• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/**
2 * Copyright (c) 2021-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
16export function evaluateNumber(v0, v1): number {
17	return v0 + v1;
18}
19
20export function doNothing(): void {
21	print('Hello from empty function');
22}
23
24export function evaluateObject(obj): ExampleClass {
25	return new ExampleClass(obj.v0 + obj.v1, obj.v0 + obj.v1);
26}
27
28export function evaluateArray(arr, size): number[] {
29	let result = [];
30	for (let i = 0; i < size; i++) {
31		result[i] = arr[i] + i * i;
32	}
33	return result;
34}
35
36export class ExampleClass {
37	constructor(v0, v1) {
38		this.v0 = v0;
39		this.v1 = v1;
40	}
41
42	static evaluateNumber(v2, v3): number {
43		return v2 + v3;
44	}
45
46	static evaluateArray(arr, size): number[] {
47		let result = [];
48		for (let i = 0; i < size; i++) {
49			result[i] = arr[i] + i * i;
50		}
51		return result;
52	}
53
54	instanceEvaluateNumber(): number {
55		// without 'this' also not working
56		return this.v0 + this.v1;
57	}
58
59	evaluateObject(obj): ExampleClass {
60		return new ExampleClass(obj.v0 + this.v1, this.v0 + obj.v1);
61	}
62
63	getV0(): number {
64		return this.v0;
65	}
66
67	getV1(): number {
68		return this.v1;
69	}
70
71	static emptyMethod(): void {
72		print('Hello from empty method');
73	}
74}
75
76export class ClassWithEmptyConstructor {
77	constructor() {
78		this.v0 = 42;
79		this.v1 = 42;
80	}
81
82	verifyProperties(v0Expected, v1Expected): number {
83		if (this.v0 === v0Expected && this.v1 === v1Expected) {
84			return 0;
85		} else {
86			return 1;
87		}
88	}
89
90	getV0(): number {
91		return this.v0;
92	}
93
94	getV1(): number {
95		return this.v1;
96	}
97}
98
99export namespace MyNamespace {
100    export class Kitten {
101        id: number;
102        name: string;
103
104        constructor(id: number, name: string) {
105            this.id = id;
106            this.name = name;
107        }
108    }
109
110    export function createKitten(id: number, name: string): Kitten {
111        return new Kitten(id, name);
112    }
113}
114