• 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
16function ccc(): string {
17    return "function ccc"
18}
19
20let foo: () => string = () => { return "lambda foo" }
21
22interface AAAOp {
23    aa?: () => string
24}
25
26class A {
27    _aa?: () => string
28    get aa(): () => string {
29        return this._aa!;
30    }
31    set aa(value: () => string) {
32        this._aa = value;
33    }
34    _init1(it?: AAAOp) {
35        this._aa = it?.aa ?? ccc;
36    }
37    _init2(it?: AAAOp) {
38        this.aa = it?.aa ?? ccc;
39    }
40    _init3() {
41        this._aa = foo ?? ccc;
42    }
43    _init4() {
44        this.aa = ccc ?? foo;
45    }
46    _init5(it?: AAAOp) {
47        this._aa = it == undefined ? ccc:it.aa;
48    }
49    _init6(it?: AAAOp) {
50        this._aa = it?.aa || ccc;
51    }
52}
53
54function main(){
55    let a = new A();
56    a._init1()
57    assertEQ(a.aa(),"function ccc")
58    a._init2()
59    assertEQ(a.aa(),"function ccc")
60    a._init3()
61    assertEQ(a.aa(),"lambda foo")
62    a._init4()
63    assertEQ(a.aa(),"function ccc")
64    a._init5()
65    assertEQ(a.aa(),"function ccc")
66    a._init6()
67    assertEQ(a.aa(),"function ccc")
68}
69