• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2 * Copyright (c) 2025 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16class A {
17    public data: string;
18    public constructor(d: string) {
19        this.data = d;
20    }
21}
22namespace NS1{
23  export function foo():number {return 2}
24  export let data:number;
25  export let a: A;
26  export let b: string;
27  export let c: string = "immediate Initializer First!";
28  static {
29    a = new A("hello initializer block!");
30    b = "hi initializer block";
31    c = c + " initializer Block Second!";
32    data = foo()
33  }
34}
35
36assertEQ(NS1.data, 2);
37assertEQ(NS1.a.data, "hello initializer block!");
38assertEQ(NS1.b, "hi initializer block");
39assertEQ(NS1.c, "immediate Initializer First! initializer Block Second!");
40
41namespace NS2{
42  export function foo():number {return 1}
43  export let b: number;
44  export let a: A;
45  static {
46     b = 1;
47     a = new A("hello initializer block!")
48  }
49
50  export namespace NS3 {
51      export let bb:number;
52      export let aa: A;
53      static {
54        bb = 2;
55        aa = new A("hello sub initializer block!")
56    }
57  }
58}
59
60assertEQ(NS2.b, 1);
61assertEQ(NS2.a.data, "hello initializer block!");
62assertEQ(NS2.NS3.bb, 2);
63assertEQ(NS2.NS3.aa.data, "hello sub initializer block!");