1/** 2 * Copyright (c) 2021-2024 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'use strict'; 16 17function standaloneFunctionJs() { 18 return 1; 19} 20 21class ClassWithMethodJs { 22 methodInClassJs() { 23 return 1; 24 } 25} 26 27class InterfaceWithMethodImpl { 28 methodInInterface() { 29 return 1; 30 } 31} 32 33function newInterfaceWithMethod() { 34 let implInterfaceWithMethod = new InterfaceWithMethodImpl(); 35 return implInterfaceWithMethod; 36 /* above is transpiled from the following TS code: 37 interface InterfaceWithMethod { 38 methodInInterface(): int; 39 } 40 41 class InterfaceWithMethodImpl implements InterfaceWithMethod { 42 methodInInterface(): int { 43 return 1; 44 } 45 } 46 47 function newInterfaceWithMethod(): InterfaceWithMethod { 48 let implInterfaceWithMethod: InterfaceWithMethod = new InterfaceWithMethodImpl(); 49 return implInterfaceWithMethod; 50 } 51 */ 52} 53 54class ClassWithGetterSetter { 55 _value = 1; 56 57 get value() { 58 return this._value; 59 } 60 61 set value(theValue) { 62 this._value = theValue; 63 } 64} 65 66let lambdaFunction = () => { 67 return 1; 68}; 69 70function genericFunction(arg) { 71 return arg; 72} 73 74class ClassToExtend { 75 value() { 76 return 1; 77 } 78} 79 80// NOTE(oignatenko) return and arg types any, unknown, undefined need real TS because transpiling cuts off 81// important details. Have a look at declgen_ets2ts 82function functionArgTypeAny(arg) { 83 return arg; // transpiled from Typescript code: functionArgTypeAny(arg: any) 84} 85 86function functionArgTypeUnknown(arg) { 87 return arg; // transpiled from Typescript code: functionArgTypeUnknown(arg: unknown) 88} 89 90function functionArgTypeUndefined(arg) { 91 return arg; // transpiled from Typescript code: functionArgTypeUndefined(arg: undefined) 92} 93 94function functionArgTypeTuple(arg) { 95 return arg[0]; // transpiled from Typescript code: functionArgTypeTuple(arg: [number, string]): number 96} 97 98function functionReturnTypeAny() { 99 let value = 1; 100 return value; // transpiled from Typescript code:functionReturnTypeAny(): any 101} 102 103function functionReturnTypeUnknown() { 104 let value = 1; 105 return value; // transpiled from Typescript code: functionReturnTypeUnknown(): unknown 106} 107 108function functionReturnTypeUndefined() { 109 let value = 1; 110 return value; // transpiled from Typescript code: functionReturnTypeUndefined(): undefined 111} 112 113function functionArgTypeCallable(functionToCall) { 114 return functionToCall(); 115 // transpiled from Typescript code: unctionArgTypeCallable(functionToCall: () => number): number 116} 117 118exports.standaloneFunctionJs = standaloneFunctionJs; 119exports.ClassWithMethodJs = ClassWithMethodJs; 120exports.newInterfaceWithMethod = newInterfaceWithMethod; 121exports.ClassWithGetterSetter = ClassWithGetterSetter; 122exports.lambdaFunction = lambdaFunction; 123exports.genericFunction = genericFunction; 124exports.ClassToExtend = ClassToExtend; 125exports.functionArgTypeAny = functionArgTypeAny; 126exports.functionArgTypeUnknown = functionArgTypeUnknown; 127exports.functionArgTypeUndefined = functionArgTypeUndefined; 128exports.functionArgTypeTuple = functionArgTypeTuple; 129exports.functionReturnTypeAny = functionReturnTypeAny; 130exports.functionReturnTypeUnknown = functionReturnTypeUnknown; 131exports.functionReturnTypeUndefined = functionReturnTypeUndefined; 132exports.functionArgTypeCallable = functionArgTypeCallable; 133