• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2 * Copyright (c) 2022 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
16declare function print(str:any):string;
17class Obj1 {
18    value:number;
19    constructor(value:number) {
20        this.value = value;
21    }
22    fun(s:number):number {
23        return 1 + this.value + s;
24    }
25}
26
27class Obj2 {
28    fun():void {
29        print("Hello World");
30    }
31}
32
33var obj1 = new Obj1(1);
34print(obj1.value);
35print(obj1.fun(2));
36var obj2 = new Obj2();
37obj2.fun();
38
39print(obj1 instanceof Object);
40
41// The following test case once exposed a bug: The abstract methods were not ignored when generating phc using ts types,
42// resulting in the inconsistency between the properties key and class litreal at runtime.
43abstract class C {
44    constructor() {}
45
46    abstract foo(): void;
47
48    bar(): string {
49       return "bar"
50    }
51}
52
53print(C.prototype.bar());
54