diff --git a/es2panda/test/ts_extra_tests/test_ts_cases/4.0/class_property_Inference_from_constructors/class_property_Inference_from_constructors_1.ts b/es2panda/test/ts_extra_tests/test_ts_cases/4.0/class_property_Inference_from_constructors/class_property_Inference_from_constructors_1.ts new file mode 100644 index 0000000000000000000000000000000000000000..d245de2941d577bfa46c2f13534420f2ffe417cb --- /dev/null +++ b/es2panda/test/ts_extra_tests/test_ts_cases/4.0/class_property_Inference_from_constructors/class_property_Inference_from_constructors_1.ts @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/**--- + description: > + TypeScript 4.0 can now use control flow analysis to determine the types of properties in classes when noImplicitAny is enabled. + module: ESNext + isCurrent: true + ---*/ + + +import { Assert } from '../../../suite/assert.js' + +class NA { + name; + + constructor(name: string) { + this.name = name; + } +} +const W = new NA("tom"); +Assert.equal(W.name, 'tom'); diff --git a/es2panda/test/ts_extra_tests/test_ts_cases/4.0/labeled_tuple_elements/labeled_tuple_elements_1.ts b/es2panda/test/ts_extra_tests/test_ts_cases/4.0/labeled_tuple_elements/labeled_tuple_elements_1.ts new file mode 100644 index 0000000000000000000000000000000000000000..0f4f2ad48b43b89289eb8e76f871af0767ecf957 --- /dev/null +++ b/es2panda/test/ts_extra_tests/test_ts_cases/4.0/labeled_tuple_elements/labeled_tuple_elements_1.ts @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/**--- + description: > + To deepen the connection between parameter lists and tuple types, + the syntax for rest elements and optional elements mirrors the syntax for parameter lists. + module: ESNext + isCurrent: true + ---*/ + + +import { Assert } from '../../../suite/assert.js' + +type Weapon = [Damage: number, DamageType?: string, ...rest: any[]]; +function getWeaponJSON(weapon: Weapon): string { + let len: number = weapon.length; + let obj: { [key: string ]: any } = { 'Damage': 0 }; + for (let i = 0; i < len; i++) { + if (i == 0) { + obj['Damage'] = weapon[i]; + } else if (i == 1) { + obj['DamageType'] = weapon[i]; + } + } + return JSON.stringify(obj); +} +let weapon1: Weapon = [1024, 'XO']; +let weapon2: Weapon = [100]; +Assert.equal(getWeaponJSON(weapon1), '{"Damage":1024,"DamageType":"XO"}'); +Assert.equal(getWeaponJSON(weapon2), '{"Damage":100}'); diff --git a/es2panda/test/ts_extra_tests/test_ts_cases/4.0/labeled_tuple_elements/labeled_tuple_elements_2.ts b/es2panda/test/ts_extra_tests/test_ts_cases/4.0/labeled_tuple_elements/labeled_tuple_elements_2.ts new file mode 100644 index 0000000000000000000000000000000000000000..59b2dc0951fe3b8a6f36f0d103eea32f0a01e967 --- /dev/null +++ b/es2panda/test/ts_extra_tests/test_ts_cases/4.0/labeled_tuple_elements/labeled_tuple_elements_2.ts @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/**--- + description: > + There are a few rules when using labeled tuples. + For one, when labeling a tuple element, all other elements in the tuple must also be labeled. + module: ESNext + isCurrent: true + ---*/ + + +import { Assert } from '../../../suite/assert.js' + +type A01 = [name: string, age: number]; +type A02 = [name?: string, age?: number]; + +let a1: A01 = ['NARC', 0]; +let a2_1: A02 = []; +let a2_2: A02 = ['ACDC']; +Assert.equal(JSON.stringify(a1), '["NARC",0]'); +Assert.equal(JSON.stringify(a2_1), '[]'); +Assert.equal(JSON.stringify(a2_2), '["ACDC"]'); \ No newline at end of file diff --git a/es2panda/test/ts_extra_tests/test_ts_cases/4.0/labeled_tuple_elements/labeled_tuple_elements_3.ts b/es2panda/test/ts_extra_tests/test_ts_cases/4.0/labeled_tuple_elements/labeled_tuple_elements_3.ts new file mode 100644 index 0000000000000000000000000000000000000000..44a74e138ce7fe34bd2bf355dbf39dad43d659c0 --- /dev/null +++ b/es2panda/test/ts_extra_tests/test_ts_cases/4.0/labeled_tuple_elements/labeled_tuple_elements_3.ts @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/**--- + description: > + It’s worth noting - labels don’t require us to name our variables differently when destructuring. + They’re purely there for documentation and tooling. + module: ESNext + isCurrent: true + ---*/ + + +import { Assert } from '../../../suite/assert.js' + +function funLTE01(x: [first: string, second: number]) { + const [a, b] = x; + Assert.equal(a, "hello"); + Assert.equal(b, 42); +} +funLTE01(["hello", 42]); diff --git a/es2panda/test/ts_extra_tests/test_ts_cases/4.0/short_circuiting_assignment_operators/short_circuiting_assignment_operators_1.ts b/es2panda/test/ts_extra_tests/test_ts_cases/4.0/short_circuiting_assignment_operators/short_circuiting_assignment_operators_1.ts new file mode 100644 index 0000000000000000000000000000000000000000..42d5761db68b7eff745791f33dc2517b47ce689d --- /dev/null +++ b/es2panda/test/ts_extra_tests/test_ts_cases/4.0/short_circuiting_assignment_operators/short_circuiting_assignment_operators_1.ts @@ -0,0 +1,76 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/**--- + description: > + JavaScript, and a lot of other languages, support a set of operators called compound assignment operators. + Compound assignment operators apply an operator to two arguments, + and then assign the result to the left side. You may have seen these before: + module: ESNext + isCurrent: true + ---*/ + + +import { Assert } from '../../../suite/assert.js' + +let a: number = 1; +let b: number = 2; +a += b; +Assert.equal(a, 3); + +let c: number = 4; +let d: number = 3; +c -= d; +Assert.equal(c, 1); + +let e: number = 5; +let f: number = 6; +e *= f; +Assert.equal(e, 30); + +let g: number = 7; +let h: number = 8; +g /= h; +Assert.equal(g, 0.875); + +let j: number = 2; +let k: number = 3; +j **= k; +Assert.equal(j, 8); + +let m: number = 20; +let n: number = 30; +m <<= n; +Assert.equal(m, 0); + +let o: number = 4; +let p: number = 5; +let o1 = o && p; +o &&= p; +Assert.equal(o, 5); +Assert.equal(o1, 5); + +let s: number = 7; +let t: number = 8; +let s1 = s || t; +s ||= t; +Assert.equal(s, 7); +Assert.equal(s1, 7); + +let u: number = 10; +let v: number = 20; +let u1 = u ?? v; +u ??= v; +Assert.equal(u1, 10); +Assert.equal(u, 10); diff --git a/es2panda/test/ts_extra_tests/test_ts_cases/4.0/short_circuiting_assignment_operators/short_circuiting_assignment_operators_2.ts b/es2panda/test/ts_extra_tests/test_ts_cases/4.0/short_circuiting_assignment_operators/short_circuiting_assignment_operators_2.ts new file mode 100644 index 0000000000000000000000000000000000000000..4c7bad2308cddb87e0080d17fad2f2b5d051c267 --- /dev/null +++ b/es2panda/test/ts_extra_tests/test_ts_cases/4.0/short_circuiting_assignment_operators/short_circuiting_assignment_operators_2.ts @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/**--- + description: > + There are even some patterns we’ve seen (or, uh, written ourselves) to lazily initialize values, only if they’ll be needed. + module: ESNext + isCurrent: true + ---*/ + + +import { Assert } from '../../../suite/assert.js' + +let arrStr: string[]; + +(arrStr ??= []).push("hello"); +(arrStr ??= []).push("world"); + +Assert.equal(arrStr[0], "hello"); +Assert.equal(arrStr[1], "world"); diff --git a/es2panda/test/ts_extra_tests/test_ts_cases/4.0/short_circuiting_assignment_operators/short_circuiting_assignment_operators_3.ts b/es2panda/test/ts_extra_tests/test_ts_cases/4.0/short_circuiting_assignment_operators/short_circuiting_assignment_operators_3.ts new file mode 100644 index 0000000000000000000000000000000000000000..431a93f8c11003b605e33fbe898e0f4027054936 --- /dev/null +++ b/es2panda/test/ts_extra_tests/test_ts_cases/4.0/short_circuiting_assignment_operators/short_circuiting_assignment_operators_3.ts @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/**--- + description: > + On the rare case that you use getters or setters with side-effects, it’s worth noting that these operators only perform assignments if necessary. + In that sense, not only is the right side of the operator “short-circuited” - the assignment itself is too. + module: ESNext + isCurrent: true + ---*/ + + +import { Assert } from '../../../suite/assert.js' + +const obj = { + get prop() { + return true; + }, + set prop(_val: boolean) { }, +}; +function test01() { + return true; +} +obj.prop = obj.prop || test01(); +Assert.equal(obj.prop, true); diff --git a/es2panda/test/ts_extra_tests/test_ts_cases/4.0/unknow_on_catch_clause_bindings/unknow_on_catch_clause_bindings_1.ts b/es2panda/test/ts_extra_tests/test_ts_cases/4.0/unknow_on_catch_clause_bindings/unknow_on_catch_clause_bindings_1.ts new file mode 100644 index 0000000000000000000000000000000000000000..a698a64af228fea38f1e67b9dfbf04623cf54c04 --- /dev/null +++ b/es2panda/test/ts_extra_tests/test_ts_cases/4.0/unknow_on_catch_clause_bindings/unknow_on_catch_clause_bindings_1.ts @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/**--- + description: > + Since the beginning days of TypeScript, catch clause variables have always been typed as any. + This meant that TypeScript allowed you to do anything you wanted with them. + module: ESNext + isCurrent: true + ---*/ + + +import { Assert } from '../../../suite/assert.js' + +function getErrorMessage(): never { + throw new Error("An error occurred"); +} +try { + getErrorMessage(); +} catch (error: any) { + Assert.equal(error.message, "An error occurred"); +}; diff --git a/es2panda/test/ts_extra_tests/test_ts_cases/4.0/unknow_on_catch_clause_bindings/unknow_on_catch_clause_bindings_2.ts b/es2panda/test/ts_extra_tests/test_ts_cases/4.0/unknow_on_catch_clause_bindings/unknow_on_catch_clause_bindings_2.ts new file mode 100644 index 0000000000000000000000000000000000000000..ef8a9f770c2acaa96bc52b25d84b7de0df2c4c33 --- /dev/null +++ b/es2panda/test/ts_extra_tests/test_ts_cases/4.0/unknow_on_catch_clause_bindings/unknow_on_catch_clause_bindings_2.ts @@ -0,0 +1,56 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/**--- + description: > + The above has some undesirable behavior if we’re trying to prevent more errors from happening in our error-handling code! + Because these variables have the type any by default, they lack any type-safety which could have errored on invalid operations. + That’s why TypeScript 4.0 now lets you specify the type of catch clause variables as unknown instead. + unknown is safer than any because it reminds us that we need to perform some sorts of type-checks before operating on our values. + module: ESNext + isCurrent: true + ---*/ + + +import { Assert } from '../../../suite/assert.js' + +let flag: boolean = false; + +function getErrorMessage(): never { + throw new Error("An error occurred"); +} +function getUnknown(): never { + let err: unknown; + throw err; +} +function getFlag(fun: Function) { + try { + fun(); + } catch (error: unknown) { + if (error instanceof Error) { + flag = true; + Assert.equal(error.message, "An error occurred"); + return error.message; + } else { + flag = false; + let errString = "An unknow error occurred"; + return errString; + } + } +} +getFlag(getErrorMessage); +Assert.isTrue(flag); +let errString = getFlag(getUnknown); +Assert.equal(errString, "An unknow error occurred"); +Assert.isFalse(flag); \ No newline at end of file diff --git a/es2panda/test/ts_extra_tests/test_ts_cases/4.0/variadic_tuple_types/variadic_tuple_types_1.ts b/es2panda/test/ts_extra_tests/test_ts_cases/4.0/variadic_tuple_types/variadic_tuple_types_1.ts new file mode 100644 index 0000000000000000000000000000000000000000..b6ca4a49be77fe7dbda78077431c3cb769aa60b4 --- /dev/null +++ b/es2panda/test/ts_extra_tests/test_ts_cases/4.0/variadic_tuple_types/variadic_tuple_types_1.ts @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/**--- + description: > + The first change is that spreads in tuple type syntax can now be generic. + This means that we can represent higher-order operations on tuples and arrays even when we don’t know the actual types we’re operating over. + When generic spreads are instantiated (or, replaced with a real type) in these tuple types, they can produce other sets of array and tuple types. + module: ESNext + isCurrent: true + ---*/ + + +import { Assert } from '../../../suite/assert.js' + +function dropFrist(arr1: T[], arr2: U[]): Array { + const [first, ...others] = [...arr1, ...arr2]; + return others; +} +let num123: number[] = [1, 2, 3]; +let abc: string[] = ['a', 'b', 'c']; +let arr = dropFrist(num123, abc); +Assert.equal(JSON.stringify(arr), '[2,3,"a","b","c"]'); diff --git a/es2panda/test/ts_extra_tests/test_ts_cases/4.0/variadic_tuple_types/variadic_tuple_types_2.ts b/es2panda/test/ts_extra_tests/test_ts_cases/4.0/variadic_tuple_types/variadic_tuple_types_2.ts new file mode 100644 index 0000000000000000000000000000000000000000..8ff840a023376aff91632b1409b439cfa8effde1 --- /dev/null +++ b/es2panda/test/ts_extra_tests/test_ts_cases/4.0/variadic_tuple_types/variadic_tuple_types_2.ts @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/**--- + description: > + The second change is that rest elements can occur anywhere in a tuple - not just at the end! + Note that in cases when we spread in a type without a known length, the resulting type becomes unbounded as well, and all the following elements factor into the resulting rest element type. + module: ESNext + isCurrent: true + ---*/ + + +import { Assert } from "../../../suite/assert.js" + +type N = [number, number, number]; +type S = [string, string, string]; +type NBSB = [...N, boolean, ...S, boolean] +function mergedArray1(nbsb: NBSB): string { + return JSON.stringify(nbsb); +} +let a: NBSB = [1, 2, 3, true, 'A', 'B', 'C', false]; +let s = mergedArray1(a); +Assert.equal(s, '[1,2,3,true,"A","B","C",false]'); diff --git a/es2panda/test/ts_extra_tests/test_ts_cases/4.0/variadic_tuple_types/variadic_tuple_types_3.ts b/es2panda/test/ts_extra_tests/test_ts_cases/4.0/variadic_tuple_types/variadic_tuple_types_3.ts new file mode 100644 index 0000000000000000000000000000000000000000..9f38c529756477b1cc289b889b432723209b72ef --- /dev/null +++ b/es2panda/test/ts_extra_tests/test_ts_cases/4.0/variadic_tuple_types/variadic_tuple_types_3.ts @@ -0,0 +1,48 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/**--- + description: > + TypeScript 4.0 improves the inference process for rest parameters and rest tuple elements so that we can type this and have it “just work”. + module: ESNext + isCurrent: true + ---*/ + + +import { Assert } from '../../../suite/assert.js' + +type UnknownArray = readonly unknown[]; + +function lockType(f: (...list: [...T, ...U]) => R, ...listA: T) { + return (...listB: U) => f(...listA, ...listB); +} +function exp(num: number, str: string, bool: boolean): string { + let obj = { num: num, str: str, bool: bool }; + return JSON.stringify(obj); +} +const f1 = lockType(exp); +let f1str = f1(1, "A", true); +Assert.equal(f1str, '{"num":1,"str":"A","bool":true}'); + +const f2 = lockType(exp, 100); +let f2str = f2("B", false); +Assert.equal(f2str, '{"num":100,"str":"B","bool":false}'); + +const f3 = lockType(exp, 1024, "XO"); +let f3str = f3(true); +Assert.equal(f3str, '{"num":1024,"str":"XO","bool":true}'); + +const f4 = lockType(exp, 1408, "EXP", false); +let f4str = f4(); +Assert.equal(f4str, '{"num":1408,"str":"EXP","bool":false}'); \ No newline at end of file diff --git a/es2panda/test/ts_extra_tests/test_ts_cases/4.1/Checked_Indexed_Accesses/Checked_Indexed_Accesses.ts b/es2panda/test/ts_extra_tests/test_ts_cases/4.1/Checked_Indexed_Accesses/Checked_Indexed_Accesses.ts new file mode 100644 index 0000000000000000000000000000000000000000..4bf3596b59853a86ee2e1fd8d8ffedfe98a7348c --- /dev/null +++ b/es2panda/test/ts_extra_tests/test_ts_cases/4.1/Checked_Indexed_Accesses/Checked_Indexed_Accesses.ts @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/**--- + description: > + TypeScript has a way to describe objects which have unknown keys but known values on an object, via index signatures. + module: ESNext + isCurrent: true + ---*/ + + +import { Assert } from '../../../suite/assert.js' + +interface I1 { + name: string; + age: number; + [pName: string]: string | number; +} +let env: I1 = { + name: "lll", + age: 22, +}; +function fun(op?: I1): I1 | undefined { + if (op) { + Assert.isString(op.name); + Assert.isNumber(op.age); + }; + return op; +}; +let env2 = fun(env); +Assert.equal(env2!.name, "lll"); +Assert.equal(env2!.age, 22); \ No newline at end of file diff --git a/es2panda/test/ts_extra_tests/test_ts_cases/4.1/Checked_Indexed_Accesses/for_each_index.ts b/es2panda/test/ts_extra_tests/test_ts_cases/4.1/Checked_Indexed_Accesses/for_each_index.ts new file mode 100644 index 0000000000000000000000000000000000000000..c06681cff9fe0e75ec71a2051a57586bc951bff5 --- /dev/null +++ b/es2panda/test/ts_extra_tests/test_ts_cases/4.1/Checked_Indexed_Accesses/for_each_index.ts @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/**--- + description: > + You can using a forEach call. + module: ESNext + isCurrent: true + ---*/ + + +import { Assert } from '../../../suite/assert.js' + +let x: string[] = ["3", "4"]; +function fun(y: string[]) { + y.forEach((str: string) => { + if (str == "3") { + Assert.equal(str, "3"); + } else { + Assert.equal(str, "4") + } + }) +} +fun(x); \ No newline at end of file diff --git a/es2panda/test/ts_extra_tests/test_ts_cases/4.1/Checked_Indexed_Accesses/for_of_index.ts b/es2panda/test/ts_extra_tests/test_ts_cases/4.1/Checked_Indexed_Accesses/for_of_index.ts new file mode 100644 index 0000000000000000000000000000000000000000..b476b18586c17e8e1bf7aaea2ce6dd6c11bd7395 --- /dev/null +++ b/es2panda/test/ts_extra_tests/test_ts_cases/4.1/Checked_Indexed_Accesses/for_of_index.ts @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/**--- + description: > + You can using a for-of loop. + module: ESNext + isCurrent: true + ---*/ + + +import { Assert } from '../../../suite/assert.js' + +let x: string[] = ["1", "2"]; +function fun(strs: string[]) { + for (let str of strs) { + if (str == "1") { + Assert.equal(str, "1"); + } else { + Assert.equal(str, "2") + } + } +} +fun(x); \ No newline at end of file diff --git a/es2panda/test/ts_extra_tests/test_ts_cases/4.1/Checked_Indexed_Accesses/for_traversal_index.ts b/es2panda/test/ts_extra_tests/test_ts_cases/4.1/Checked_Indexed_Accesses/for_traversal_index.ts new file mode 100644 index 0000000000000000000000000000000000000000..4124efd187954e0caa1ceb42d486a48acbd3ff23 --- /dev/null +++ b/es2panda/test/ts_extra_tests/test_ts_cases/4.1/Checked_Indexed_Accesses/for_traversal_index.ts @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/**--- + description: > + You can traverse the fun. + module: ESNext + isCurrent: true + ---*/ + + +import { Assert } from '../../../suite/assert.js' + +let x: string[] = ["1", "2"]; +function fun(strs: string[]) { + for (let i: number = 0; i < strs.length; i++) { + if (i < 1) { + Assert.equal(strs[i], "1"); + } else { + Assert.equal(strs[i], "2"); + } + } +} +fun(x); \ No newline at end of file diff --git a/es2panda/test/ts_extra_tests/test_ts_cases/4.1/abstract_members_can_not_be_marked_async/abstract_members_can_not_be_marked_async.ts b/es2panda/test/ts_extra_tests/test_ts_cases/4.1/abstract_members_can_not_be_marked_async/abstract_members_can_not_be_marked_async.ts new file mode 100644 index 0000000000000000000000000000000000000000..2b2d5d5d6befeec3f43cf4580f3bc6aa57a475d3 --- /dev/null +++ b/es2panda/test/ts_extra_tests/test_ts_cases/4.1/abstract_members_can_not_be_marked_async/abstract_members_can_not_be_marked_async.ts @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/**--- + description: > + Members marked as abstract can no longer be marked as async. + module: ESNext + isCurrent: true + ---*/ + + +import { Assert } from '../../../suite/assert.js' + +abstract class Animal { + abstract name: string; + abstract eat(): number; + run(): void { } +} +class Dog extends Animal { + name: string = "dog"; + gender: string; + constructor(gender: string) { + super(); + this.gender = gender; + } + eat(): number { + return 1; + } +} +let dog = new Dog("male"); +Assert.equal(dog.eat(), 1); +Assert.equal(dog.name, "dog"); diff --git a/es2panda/test/ts_extra_tests/test_ts_cases/4.1/any_or_unknown_are_propagated_in_falsy_positions/any_or_unknown_are_propagated_in_falsy_positions.ts b/es2panda/test/ts_extra_tests/test_ts_cases/4.1/any_or_unknown_are_propagated_in_falsy_positions/any_or_unknown_are_propagated_in_falsy_positions.ts new file mode 100644 index 0000000000000000000000000000000000000000..b78c76608600053878b62e0412e9ae2e9e17be97 --- /dev/null +++ b/es2panda/test/ts_extra_tests/test_ts_cases/4.1/any_or_unknown_are_propagated_in_falsy_positions/any_or_unknown_are_propagated_in_falsy_positions.ts @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/**--- + description: > + Since nothing is known about the type on the left side of the &&, + we propagate any and unknown outward instead of the type on the right side. + module: ESNext + isCurrent: true + ---*/ + + +import { Assert } from '../../../suite/assert.js' + +let x: unknown; +declare let obj: { str: string }; +let y = x && obj; +function fun(x: any): boolean { + return x && typeof x === "object" && x.blah === "foo"; +} +let z = fun(y); +Assert.isUndefined(z); diff --git a/es2panda/test/ts_extra_tests/test_ts_cases/4.1/conditional_spreads_create_optional_properties/conditional_spreads_create_optional_properties_1.ts b/es2panda/test/ts_extra_tests/test_ts_cases/4.1/conditional_spreads_create_optional_properties/conditional_spreads_create_optional_properties_1.ts new file mode 100644 index 0000000000000000000000000000000000000000..462ce5b402df5c3236225ed426444af8aeaf1845 --- /dev/null +++ b/es2panda/test/ts_extra_tests/test_ts_cases/4.1/conditional_spreads_create_optional_properties/conditional_spreads_create_optional_properties_1.ts @@ -0,0 +1,52 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/**--- + description: > + the returned type sometimes uses all-optional properties. + module: ESNext + isCurrent: true + ---*/ + + +import { Assert } from '../../../suite/assert.js' + +interface I1 { + x: string; + y: number; + z: string; +} +interface I2 { + x: string; + owner: I1; +} +function fun(other?: I2) { + return { + ...(other && other.owner), + otherStuff: 123, + }; +} +let pet: I2 = { + x: "qiqi", + owner: { + x: "owner", + y: 11, + z: "qingdao", + }, +}; +let pet2 = fun(pet); +Assert.equal(pet2.y, 11); +Assert.equal(pet2.x, "owner"); +Assert.equal(pet2.z, "qingdao"); +Assert.equal(pet2.otherStuff, 123); \ No newline at end of file diff --git a/es2panda/test/ts_extra_tests/test_ts_cases/4.1/key_remapping_in_mapped_types/key_remapping_in_mapped_types_1.ts b/es2panda/test/ts_extra_tests/test_ts_cases/4.1/key_remapping_in_mapped_types/key_remapping_in_mapped_types_1.ts new file mode 100644 index 0000000000000000000000000000000000000000..41c7efa8a40f32baa599311f13e7c1147183915c --- /dev/null +++ b/es2panda/test/ts_extra_tests/test_ts_cases/4.1/key_remapping_in_mapped_types/key_remapping_in_mapped_types_1.ts @@ -0,0 +1,47 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/**--- + description: > + allows you to re-map keys in mapped types with a new as clause. + module: ESNext + isCurrent: true + ---*/ + + +import { Assert } from '../../../suite/assert.js' + +type G = { + [K in keyof T as `get${Capitalize}`]: () => T[K]; +}; +interface I1 { + a: string; + b: number; + c: string; +} +type I1Type = G; +let k1: I1Type = { + getA() { + return "honny"; + }, + getB() { + return 2; + }, + getC() { + return "qingdao"; + }, +}; +Assert.equal(k1.getA(), "honny"); +Assert.equal(k1.getB(), 2); +Assert.equal(k1.getC(), "qingdao"); \ No newline at end of file diff --git a/es2panda/test/ts_extra_tests/test_ts_cases/4.1/key_remapping_in_mapped_types/key_remapping_in_mapped_types_2.ts b/es2panda/test/ts_extra_tests/test_ts_cases/4.1/key_remapping_in_mapped_types/key_remapping_in_mapped_types_2.ts new file mode 100644 index 0000000000000000000000000000000000000000..67d448fbc46d163e322ba1499dcb868353549eb2 --- /dev/null +++ b/es2panda/test/ts_extra_tests/test_ts_cases/4.1/key_remapping_in_mapped_types/key_remapping_in_mapped_types_2.ts @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/**--- + description: > + you can even filter out keys by producing never + module: ESNext + isCurrent: true + ---*/ + + +import { Assert } from '../../../suite/assert.js' + +type TYPE1 = { + [K in keyof T as Exclude]: T[K]; +}; +interface I1 { + name: "ww"; + id: number; +} +type TYPE2 = TYPE1; +let k: TYPE2 = { id: 10 }; +Assert.equal(k.id, 10); \ No newline at end of file diff --git a/es2panda/test/ts_extra_tests/test_ts_cases/4.1/recursive_conditional_types/recursive_conditional_types.ts b/es2panda/test/ts_extra_tests/test_ts_cases/4.1/recursive_conditional_types/recursive_conditional_types.ts new file mode 100644 index 0000000000000000000000000000000000000000..44909b82820f26666130bd7f2984263969069449 --- /dev/null +++ b/es2panda/test/ts_extra_tests/test_ts_cases/4.1/recursive_conditional_types/recursive_conditional_types.ts @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/**--- + description: > + conditional types can now immediately reference themselves within their branches + module: ESNext + isCurrent: true + ---*/ + + +import { Assert } from '../../../suite/assert.js' + +type TYPE1 = T extends ReadonlyArray ? TYPE1 : T; + +function fun1(x: T): TYPE1[] { + return []; +} +let d1 = fun1([1, 2, 3]); +type typeofx = typeof d1; +let nx1: typeofx = [1, 2, 3]; +Assert.isNumber(nx1[0]); +let d2 = fun1([[1], [2, 3]]); +type typeofx2 = typeof d2; +let nx2: typeofx2 = [4, 5, 6]; +Assert.isNumber(nx2[0]); +let d3 = fun1([[1], [[2]], [[[3]]]]); +type typeofx3 = typeof d3; +let nx3: typeofx3 = [7, 8, 9]; +Assert.isNumber(nx3[0]); \ No newline at end of file diff --git a/es2panda/test/ts_extra_tests/test_ts_cases/4.1/resolvers_parameters_are_no_longer_optional_in_promises/resolves_parameters_are_no_longer_optional_in_promises.ts b/es2panda/test/ts_extra_tests/test_ts_cases/4.1/resolvers_parameters_are_no_longer_optional_in_promises/resolves_parameters_are_no_longer_optional_in_promises.ts new file mode 100644 index 0000000000000000000000000000000000000000..4dab20ad9d9fb22fe8b947e80df8d33c74dc4bd8 --- /dev/null +++ b/es2panda/test/ts_extra_tests/test_ts_cases/4.1/resolvers_parameters_are_no_longer_optional_in_promises/resolves_parameters_are_no_longer_optional_in_promises.ts @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/**--- + description: > + resolve’s Parameters Are No Longer Optional in Promises + module: ESNext + isCurrent: true + ---*/ + + +import { Assert } from '../../../suite/assert.js' + +var count: number = 1; +Assert.equal(count, 1); +let a: number = 10; +setTimeout(function () { + a = 1; +}, 0); +Promise.resolve().then(function () { + a = 2; +}); +Assert.equal(a, 10); +const p = Promise.resolve(1); +p.then(function (s) { + a = a + s; +}); +Assert.equal(a, 10); \ No newline at end of file diff --git a/es2panda/test/ts_extra_tests/test_ts_cases/4.1/template_literal_types/template_literal_types_1.ts b/es2panda/test/ts_extra_tests/test_ts_cases/4.1/template_literal_types/template_literal_types_1.ts new file mode 100644 index 0000000000000000000000000000000000000000..091f4882eb5e11315a265fc6f859e43a713691f8 --- /dev/null +++ b/es2panda/test/ts_extra_tests/test_ts_cases/4.1/template_literal_types/template_literal_types_1.ts @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/**--- + description: > + String literal types in TypeScript allow us to model functions and APIs that expect a set of specific strings. + module: ESNext + isCurrent: true + ---*/ + + +import { Assert } from '../../../suite/assert.js' + +function getnum(x: "a" | "b" | "c") { + if (x == "a") return 1; + else if (x == "b") return 2; + else if (x == "c") return 3; +} +let num1 = getnum("a"); +let num2 = getnum("b"); +let num3 = getnum("c"); +Assert.equal(num1, 1); +Assert.equal(num2, 2); +Assert.equal(num3, 3); diff --git a/es2panda/test/ts_extra_tests/test_ts_cases/4.1/template_literal_types/template_literal_types_2.ts b/es2panda/test/ts_extra_tests/test_ts_cases/4.1/template_literal_types/template_literal_types_2.ts new file mode 100644 index 0000000000000000000000000000000000000000..44529217d349e007b9a9866decfe34e759091267 --- /dev/null +++ b/es2panda/test/ts_extra_tests/test_ts_cases/4.1/template_literal_types/template_literal_types_2.ts @@ -0,0 +1,52 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/**--- + description: > + template literal string type has the same syntax as template literal strings in JavaScript, but is used in type positions. + When you use it with concrete literal types, it produces a new string literal type by concatenating the contents. + module: ESNext + isCurrent: true + ---*/ + + +import { Assert } from '../../../suite/assert.js' + +type Go = "go"; +type Dong = `just ${Go}`; +function fun(w: Go | Dong) { + if (w == "go") return 1; + else if (w == "just go") return 2; +} +let saying1 = fun("go"); +Assert.equal(saying1, 1); +let saying2 = fun("just go"); +Assert.equal(saying2, 2); +type Size = "small" | "big"; +type Num = "one" | "two"; +type Food = `${Num | Size} food`; +function getfish(food: Food) { + if (food == "one food") return 1; + else if (food == "two food") return 2; + else if (food == "small food") return "small"; + else if (food == "big food") return "big"; +} +let x1 = getfish("one food"); +Assert.equal(x1, 1); +let x2 = getfish("two food"); +Assert.equal(x2, 2); +let x3 = getfish("small food"); +Assert.equal(x3, "small"); +let x4 = getfish("big food"); +Assert.equal(x4, "big"); diff --git a/es2panda/test/ts_extra_tests/test_ts_cases/4.1/template_literal_types/template_literal_types_3.ts b/es2panda/test/ts_extra_tests/test_ts_cases/4.1/template_literal_types/template_literal_types_3.ts new file mode 100644 index 0000000000000000000000000000000000000000..f71571fefc36a16ee857c018a22c89a632137870 --- /dev/null +++ b/es2panda/test/ts_extra_tests/test_ts_cases/4.1/template_literal_types/template_literal_types_3.ts @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/**--- + description: > + The new type aliases are Uppercase, Lowercase, Capitalize and Uncapitalize. + module: ESNext + isCurrent: true + ---*/ + + +import { Assert } from '../../../suite/assert.js' + +type UpperHello = `${Uppercase}`; +type LowerHello = `${Lowercase}`; +type CapHello = `${Capitalize}`; +type UncapHello = `${Uncapitalize}`; +type HELLO = UpperHello<"hello">; +type hello = LowerHello<"HEllO">; +type Hello = CapHello<"hello">; +type hELLO = UncapHello<"HELLO">; +function gethello(hi: HELLO | hello | Hello | hELLO) { + if (hi == "HELLO") return 1; + else if (hi == "hello") return 2; + else if (hi == "Hello") return 3; + else if (hi == "hELLO") return 4; +} +let hi1 = gethello("HELLO"); +Assert.equal(hi1, 1); +let hi2 = gethello("hello"); +Assert.equal(hi2, 2); +let hi3 = gethello("Hello"); +Assert.equal(hi3, 3); +let hi4 = gethello("hELLO"); +Assert.equal(hi4, 4); diff --git a/es2panda/test/ts_extra_tests/test_ts_cases/4.2/Reverting_Template_Literal_Inference/Reverting_Template_Literal_Inference.ts b/es2panda/test/ts_extra_tests/test_ts_cases/4.2/Reverting_Template_Literal_Inference/Reverting_Template_Literal_Inference.ts new file mode 100644 index 0000000000000000000000000000000000000000..c50fadb28c9b030e016d05497a3266dec2d98408 --- /dev/null +++ b/es2panda/test/ts_extra_tests/test_ts_cases/4.2/Reverting_Template_Literal_Inference/Reverting_Template_Literal_Inference.ts @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/**--- + description: > + template string literals would either be given template string types or simplify to multiple string literal types. + These types would then widen to string when assigning to mutable variables. + module: ESNext + isCurrent: true + ---*/ + + +import { Assert } from '../../../suite/assert.js' + +const logo: "just do it" = "just do it"; +const str1: string = `go ${logo}`; +let str2: string = `hello ${logo}`; +let str3: "luckily dog just do it" = `luckily dog ${logo}` as const; +function check(op?: string){ + if (op){ + Assert.isString(op); + } +} +check(str1 + str2 + str3); +Assert.equal(str1, "go just do it"); +Assert.equal(str2, "hello just do it"); \ No newline at end of file diff --git a/es2panda/test/ts_extra_tests/test_ts_cases/4.2/abstract_construct_signatures/abstract_construct_signatures.ts b/es2panda/test/ts_extra_tests/test_ts_cases/4.2/abstract_construct_signatures/abstract_construct_signatures.ts new file mode 100644 index 0000000000000000000000000000000000000000..866275dfa2b22a7c59d5c14b2aaf2c28ba5f0809 --- /dev/null +++ b/es2panda/test/ts_extra_tests/test_ts_cases/4.2/abstract_construct_signatures/abstract_construct_signatures.ts @@ -0,0 +1,53 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/**--- + description: > + TypeScript allows us to mark a class as abstract. This tells TypeScript that the class is only meant to be extended from, and that certain members need to be filled in by any subclass to actually create an instance. + module: ESNext + isCurrent: true +---*/ + + +import { Assert } from '../../../suite/assert.js' + +abstract class Color { + abstract red: number; + abstract green: number; + abstract blue: number; + protected abstract rgb: [number, number, number]; + + abstract getRGB(): [number, number, number]; +} + +class ColorCopy extends Color { + red: number = 0; + green: number = 0; + blue: number = 0; + protected rgb: [number, number, number] = [0, 0, 0]; + getRGB(): [number, number, number] { + this.rgb = [this.red, this.green, this.blue] + return this.rgb; + } + constructor(r: number, g: number, b: number) { + super(); + this.red = r; + this.green = g; + this.blue = b; + this.getRGB(); + } +} + +let color: ColorCopy = new ColorCopy(255, 0, 0); +Assert.equal(JSON.stringify(color.getRGB()), '[255,0,0]'); \ No newline at end of file diff --git a/es2panda/test/ts_extra_tests/test_ts_cases/4.2/abstract_construct_signatures/abstract_construct_signatures_1.ts b/es2panda/test/ts_extra_tests/test_ts_cases/4.2/abstract_construct_signatures/abstract_construct_signatures_1.ts new file mode 100644 index 0000000000000000000000000000000000000000..e3fecca28252812c8578c84d0572834a89d2e435 --- /dev/null +++ b/es2panda/test/ts_extra_tests/test_ts_cases/4.2/abstract_construct_signatures/abstract_construct_signatures_1.ts @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/**--- + description: > + Assign an abstract class to anything that expects a construct signature is the right thing in case we intend to run code. + module: ESNext + isCurrent: true +---*/ + + +import { Assert } from '../../../suite/assert.js' + +abstract class myClass { + abstract getMy(): number; +} +interface myInter { + getMy(): number; +} + +function func(myCode: new () => myInter) { + let test = new myCode(); + return test.getMy(); +} + +class my_C extends myClass { + getMy(): number { + return 10; + } +} + +Assert.equal(func(my_C), 10); \ No newline at end of file diff --git a/es2panda/test/ts_extra_tests/test_ts_cases/4.2/abstract_construct_signatures/abstract_construct_signatures_2.ts b/es2panda/test/ts_extra_tests/test_ts_cases/4.2/abstract_construct_signatures/abstract_construct_signatures_2.ts new file mode 100644 index 0000000000000000000000000000000000000000..b00228cffbf9e749acae8eff82315c50f75e682a --- /dev/null +++ b/es2panda/test/ts_extra_tests/test_ts_cases/4.2/abstract_construct_signatures/abstract_construct_signatures_2.ts @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/**--- + description: > + TypeScript 4.2 allows you to specify an abstract modifier on constructor signatures. + module: ESNext + isCurrent: true + ---*/ + + +import { Assert } from '../../../suite/assert.js' + +abstract class myClass { + abstract getMy(): number; +} +interface myInter { + getMy(): number; +} + +let myTest: abstract new () => myInter = myClass; +Assert.equal(myTest.toString(), 'class myClass {\n}'); \ No newline at end of file diff --git a/es2panda/test/ts_extra_tests/test_ts_cases/4.2/abstract_construct_signatures/abstract_construct_signatures_3.ts b/es2panda/test/ts_extra_tests/test_ts_cases/4.2/abstract_construct_signatures/abstract_construct_signatures_3.ts new file mode 100644 index 0000000000000000000000000000000000000000..1ee46162c26d4180c98bf72dc41dd8a91da8ad50 --- /dev/null +++ b/es2panda/test/ts_extra_tests/test_ts_cases/4.2/abstract_construct_signatures/abstract_construct_signatures_3.ts @@ -0,0 +1,64 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/**--- + description: > + The feature allows us to write mixin factories in a way that supports abstract classes. + module: ESNext + isCurrent: true +---*/ + + +import { Assert } from '../../../suite/assert.js' + +abstract class Point { + abstract a: number; + abstract b: number; + abstract getPoint(): [number, number]; +} + +type MIX = abstract new (...args: any[]) => T + +function mixClass>(Ctor: T) { + abstract class CPColor extends Ctor { + abstract red: number; + abstract green: number; + abstract blue: number; + abstract getColor(): [number, number, number]; + } + return CPColor; +} + +class ColorPoint extends mixClass(Point) { + red: number = 0; + green: number = 0; + blue: number = 0; + a: number = 0; + b: number = 0; + getColor(): [number, number, number] { + return [this.red, this.green, this.blue]; + } + getPoint(): [number, number] { + return [this.a, this.b]; + } + constructor(red: number = 0, green: number = 0, blue: number = 0, a: number = 0, b: number = 0) { + super(); + this.a = a; this.b = b; + this.red = red; this.green = green; this.blue = blue; + } +} + +let cp = new ColorPoint(0, 255, 0, 25, 25); +Assert.equal(JSON.stringify(cp.getColor()), '[0,255,0]'); +Assert.equal(JSON.stringify(cp.getPoint()), '[25,25]'); \ No newline at end of file diff --git a/es2panda/test/ts_extra_tests/test_ts_cases/4.2/leading_middle_rest_elements_in_tuple_types/leading_middle_rest_elements_in_tuple_types1.ts b/es2panda/test/ts_extra_tests/test_ts_cases/4.2/leading_middle_rest_elements_in_tuple_types/leading_middle_rest_elements_in_tuple_types1.ts new file mode 100644 index 0000000000000000000000000000000000000000..6883648348e8c760760bb5a4ef52e5a77addad3c --- /dev/null +++ b/es2panda/test/ts_extra_tests/test_ts_cases/4.2/leading_middle_rest_elements_in_tuple_types/leading_middle_rest_elements_in_tuple_types1.ts @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/**--- + description: > + In TypeScript, tuple types are meant to model arrays with specific lengths and element types. + module: ESNext + isCurrent: true +---*/ + + +import { Assert } from '../../../suite/assert.js' + +type myType = Function | object; + +let tup: [myType, string, boolean] = [() => { }, 'a', true]; +Assert.isFunction(tup[0]); +Assert.isString(tup[1]); +Assert.isBoolean(tup[2]); + +tup = [{ o: 'obj' }, 'b', false]; +Assert.isObject(tup[0]); +Assert.isString(tup[1]); +Assert.isBoolean(tup[2]); \ No newline at end of file diff --git a/es2panda/test/ts_extra_tests/test_ts_cases/4.2/leading_middle_rest_elements_in_tuple_types/leading_middle_rest_elements_in_tuple_types2.ts b/es2panda/test/ts_extra_tests/test_ts_cases/4.2/leading_middle_rest_elements_in_tuple_types/leading_middle_rest_elements_in_tuple_types2.ts new file mode 100644 index 0000000000000000000000000000000000000000..95db41ca9952655e46bf5682b1a0bc528b7a6801 --- /dev/null +++ b/es2panda/test/ts_extra_tests/test_ts_cases/4.2/leading_middle_rest_elements_in_tuple_types/leading_middle_rest_elements_in_tuple_types2.ts @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/**--- + description: > + they can have optional elements and rest elements, and can even have labels for tooling and readability. + module: ESNext + isCurrent: true + ---*/ + + +import { Assert } from '../../../suite/assert.js' + +type myType = Function | object; + +let tup1: [myType, string?] = [() => { }]; +tup1 = [{ o: "obj" }, "a"]; + +let tup2: [arg1: myType, arg2?: string] = [() => { }]; +tup2 = [{ o: "obj" }, "a"]; + +let tup3: [myType, string, ...unknown[]]; + +tup3 = [() => { }, "world"]; +tup3 = [{ o: "obj" }, "world", false]; +tup3 = [{ o: "obj" }, "world", true, 2]; + +Assert.equal(JSON.stringify(tup1), "[{\"o\":\"obj\"},\"a\"]"); +Assert.equal(JSON.stringify(tup2), "[{\"o\":\"obj\"},\"a\"]"); +Assert.equal(JSON.stringify(tup3), "[{\"o\":\"obj\"},\"world\",true,2]"); \ No newline at end of file diff --git a/es2panda/test/ts_extra_tests/test_ts_cases/4.2/leading_middle_rest_elements_in_tuple_types/leading_middle_rest_elements_in_tuple_types3.ts b/es2panda/test/ts_extra_tests/test_ts_cases/4.2/leading_middle_rest_elements_in_tuple_types/leading_middle_rest_elements_in_tuple_types3.ts new file mode 100644 index 0000000000000000000000000000000000000000..7327dd22581df89df8b4ad77ed565c2445d08ed5 --- /dev/null +++ b/es2panda/test/ts_extra_tests/test_ts_cases/4.2/leading_middle_rest_elements_in_tuple_types/leading_middle_rest_elements_in_tuple_types3.ts @@ -0,0 +1,51 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/**--- + description: > + In prior versions, TypeScript only allowed '...rest' elements at the very last position of a tuple type. + However, now rest elements can occur anywhere within a tuple. + module: ESNext + isCurrent: true +---*/ + + +import { Assert } from '../../../suite/assert.js' + +interface h_i{ + num: number; +} +interface h_f{ + str: string; +} +type myType = h_i | h_f; + +let tup1: [...myType[], boolean]; +tup1 = [true]; +tup1 = [{ num: 10 }, true]; +tup1 = [{ num: 10 }, { str: 'string' }, true]; + +let tup2: [string, ...myType[], boolean]; +tup2 = ['a', false]; +tup2 = ['a', { num: 10 }, false]; +tup2 = ['a', { num: 10 }, { str: 'string' }, false]; + +let tup3: [string, boolean, ...myType[]]; +tup3 = ['a', false]; +tup3 = ['a', false, { num: 10 }]; +tup3 = ['a', false, { num: 10 }, { str: 'string' }]; + +Assert.equal(JSON.stringify(tup1), "[{\"num\":10},{\"str\":\"string\"},true]"); +Assert.equal(JSON.stringify(tup2), "[\"a\",{\"num\":10},{\"str\":\"string\"},false]"); +Assert.equal(JSON.stringify(tup3), "[\"a\",false,{\"num\":10},{\"str\":\"string\"}]"); diff --git a/es2panda/test/ts_extra_tests/test_ts_cases/4.2/leading_middle_rest_elements_in_tuple_types/leading_middle_rest_elements_in_tuple_types4.ts b/es2panda/test/ts_extra_tests/test_ts_cases/4.2/leading_middle_rest_elements_in_tuple_types/leading_middle_rest_elements_in_tuple_types4.ts new file mode 100644 index 0000000000000000000000000000000000000000..7166f270574b422f356c791fa1e7e3a20b9903d4 --- /dev/null +++ b/es2panda/test/ts_extra_tests/test_ts_cases/4.2/leading_middle_rest_elements_in_tuple_types/leading_middle_rest_elements_in_tuple_types4.ts @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/**--- + description: > + These non-trailing rest elements can be used to model functions that take any number of leading arguments, + followed by a few fixed ones. + module: ESNext + isCurrent: true +---*/ + + +import { Assert } from '../../../suite/assert.js' + +function func1(...arg: [...arr: unknown[], num: number]) { + return { ...arg }; +} +let result1 = func1(10); +Assert.equal(JSON.stringify(result1), '{"0":10}'); +let result2 = func1(5, 's', true, 10); +Assert.equal(JSON.stringify(result2), '{"0":5,"1":"s","2":true,"3":10}'); + +function func2(...arg: [str:string, ...arr: unknown[], num: number]) { + return { ...arg }; +} +let result3 = func2('a', 10); +Assert.equal(JSON.stringify(result3), '{"0":"a","1":10}'); +let result4 = func2('s', true, 10); +Assert.equal(JSON.stringify(result4), '{"0":"s","1":true,"2":10}'); \ No newline at end of file diff --git a/es2panda/test/ts_extra_tests/test_ts_cases/4.2/relaxed_rules_between_optional_properties_and_string_index_signatures/relaxed_rules.ts b/es2panda/test/ts_extra_tests/test_ts_cases/4.2/relaxed_rules_between_optional_properties_and_string_index_signatures/relaxed_rules.ts new file mode 100644 index 0000000000000000000000000000000000000000..655eba66710767f46a227caa9d97bd86b93c68e9 --- /dev/null +++ b/es2panda/test/ts_extra_tests/test_ts_cases/4.2/relaxed_rules_between_optional_properties_and_string_index_signatures/relaxed_rules.ts @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/**--- + description: > + Previous versions of TypeScript treated optional object properties as + unassignable to otherwise compatible index signatures, due to the presence of undefined. + TypeScript 4.2 allows this assignment. + module: ESNext + isCurrent: true +---*/ + + +import { Assert } from '../../../suite/assert.js' + +interface I{ + [key: string]: number; +} + +type myType = { + 'a'?: number; + 'b'?: number; + 'c'?: number; +} +const eg: myType = { 'a': 10 }; +const i: I = eg; +Assert.isObject(i); + +const obj: { [key: string]: number } = eg; +Assert.isObject(obj); diff --git a/es2panda/test/ts_extra_tests/test_ts_cases/4.2/smarter_type_alias_preservation/smarter_type_alias_preservation1.ts b/es2panda/test/ts_extra_tests/test_ts_cases/4.2/smarter_type_alias_preservation/smarter_type_alias_preservation1.ts new file mode 100644 index 0000000000000000000000000000000000000000..9ccb67a31630411cb425516de959610309475aef --- /dev/null +++ b/es2panda/test/ts_extra_tests/test_ts_cases/4.2/smarter_type_alias_preservation/smarter_type_alias_preservation1.ts @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/**--- + description: > + TypeScript has always used a set of rules and guesses for when to reuse type aliases when printing out types. + module: ESNext + isCurrent: true +---*/ + + +import { Assert } from '../../../suite/assert.js' + +type T = number | string | boolean; +function func(value: T): T { + return value; +} +let arr = [1, "hello", false]; +Assert.equal(typeof func(arr[0]), "number"); + +class C{ + mem: T; + constructor(mem: T) { + this.mem = mem; + } +} +let c = new C(10); +Assert.isNumber(c.mem); +c.mem = 'a'; +Assert.isString(c.mem); +c.mem = true; +Assert.isBoolean(c.mem); \ No newline at end of file diff --git a/es2panda/test/ts_extra_tests/test_ts_cases/4.2/smarter_type_alias_preservation/smarter_type_alias_preservation2.ts b/es2panda/test/ts_extra_tests/test_ts_cases/4.2/smarter_type_alias_preservation/smarter_type_alias_preservation2.ts new file mode 100644 index 0000000000000000000000000000000000000000..e6cd3461baf57a5e7011e29b1797ff4691099ba6 --- /dev/null +++ b/es2panda/test/ts_extra_tests/test_ts_cases/4.2/smarter_type_alias_preservation/smarter_type_alias_preservation2.ts @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/**--- + description: > + If we hover our mouse over value in an editor like Visual Studio, Visual Studio Code, or the TypeScript Playground, we’ll get a quick info panel that shows the type BasicPrimitive. Likewise, if we get the declaration file output (.d.ts output) for this file, TypeScript will say that doStuff returns BasicPrimitive. + module: ESNext + isCurrent: true +---*/ + + +import { Assert } from '../../../suite/assert.js' + +type T = number | string | boolean; +function func(arg: T) { + return arg; +} + +let arr = [10, "hello", false]; +Assert.equal(typeof func(arr[0]), "number"); \ No newline at end of file diff --git a/es2panda/test/ts_extra_tests/test_ts_cases/4.3/always-truthy_promise_checks/always-truthy_promise_checks.ts b/es2panda/test/ts_extra_tests/test_ts_cases/4.3/always-truthy_promise_checks/always-truthy_promise_checks.ts new file mode 100644 index 0000000000000000000000000000000000000000..ee1719ad8cebf1d56e8a6c9591ec3d01bc60cef7 --- /dev/null +++ b/es2panda/test/ts_extra_tests/test_ts_cases/4.3/always-truthy_promise_checks/always-truthy_promise_checks.ts @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/**--- + description: > + Under strictNullChecks, checking whether a Promise is 'truthy' in a conditional will trigger an error. + options: + lib: es2015 + module: ESNext + isCurrent: true + ---*/ + + +import { Assert } from '../../../suite/assert.js' + +async function getFalse(): Promise { + return false; +} + +async function funPromise(): Promise { + if (!getFalse()) { + return 'false'; + } + return 'true'; +} + +var b = funPromise(); +Assert.equal(b, '[object Promise]'); \ No newline at end of file diff --git a/es2panda/test/ts_extra_tests/test_ts_cases/4.3/constructorParameters_works_on_abstract_class/constructorParameters_works_on_abstract_class.ts b/es2panda/test/ts_extra_tests/test_ts_cases/4.3/constructorParameters_works_on_abstract_class/constructorParameters_works_on_abstract_class.ts new file mode 100644 index 0000000000000000000000000000000000000000..a3618c6e84ba66cab7674695032fb6344389f843 --- /dev/null +++ b/es2panda/test/ts_extra_tests/test_ts_cases/4.3/constructorParameters_works_on_abstract_class/constructorParameters_works_on_abstract_class.ts @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/**--- + description: > + The ConstructorParameters type helper now works on abstract classes. + module: ESNext + isCurrent: true + ---*/ + + +import { Assert } from "../../../suite/assert.js" + +abstract class CPC { + a: string; + b: number; + constructor(a: string, b: number) { + this.a = a; + this.b = b; + } +} + +type TypeC = ConstructorParameters; +var c: TypeC = ["s", 10]; +Assert.equal(JSON.stringify(c), '["s",10]'); diff --git a/es2panda/test/ts_extra_tests/test_ts_cases/4.3/contextual_narrowing_for_generic/contextual_narrowing_for_generics.ts b/es2panda/test/ts_extra_tests/test_ts_cases/4.3/contextual_narrowing_for_generic/contextual_narrowing_for_generics.ts new file mode 100644 index 0000000000000000000000000000000000000000..a1ee16262d97923b3fdbeca0bbe2bede88dc0d69 --- /dev/null +++ b/es2panda/test/ts_extra_tests/test_ts_cases/4.3/contextual_narrowing_for_generic/contextual_narrowing_for_generics.ts @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/**--- + description: > + TypeScript 4.3 now includes some slightly smarter type-narrowing logic on generic values. + This allows TypeScript to accept more patterns, and sometimes even catch mistakes. + module: ESNext + isCurrent: true + ---*/ + + +import { Assert } from "../../../suite/assert.js" + +function funSetorArray | T[]>(collection: C): C { + if (collection instanceof Set) { + return collection; + } + return collection; +} + +let num: number[] = [1, 3, 2, 2, 4]; +let n = funSetorArray(num); +Assert.equal(JSON.stringify(funSetorArray(num)), "[1,3,2,2,4]"); + +let ss = new Set(); +ss.add("NARC"); +ss.add("TypeScript"); +let ts = funSetorArray(ss); +Assert.isTrue(ts.has("NARC")); +Assert.isTrue(ts.has("TypeScript")); \ No newline at end of file diff --git a/es2panda/test/ts_extra_tests/test_ts_cases/4.3/ecmascript_private_class_elements/ecmascript_private_calss_elements.ts b/es2panda/test/ts_extra_tests/test_ts_cases/4.3/ecmascript_private_class_elements/ecmascript_private_calss_elements.ts new file mode 100644 index 0000000000000000000000000000000000000000..16ee873e22bf45e7aed8136db234cde9f4c315cf --- /dev/null +++ b/es2panda/test/ts_extra_tests/test_ts_cases/4.3/ecmascript_private_class_elements/ecmascript_private_calss_elements.ts @@ -0,0 +1,54 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/**--- + description: > + TypeScript 4.3 expands which elements in a class can be given #private #names to make them truly private at run-time. + In addition to properties, methods and accessors can also be given private names. + Even more broadly, static members can now also have private names. + options: + target: es2015 + module: ESNext + isCurrent: true + ---*/ + + +import { Assert } from "../../../suite/assert.js" + +class ClassP { + #FUN() { + return 1; + } + F1() { + return this.#FUN(); + } + static #something(num: number) { + return num; + } + F2() { + return ClassP.#something(10); + } + get #V() { + return 100; + } + mFUN() { + this.#FUN(); + return this.#V; + } +} + +let c = new ClassP(); +Assert.equal(c.F1(), 1); +Assert.equal(c.F2(), 10); +Assert.equal(c.mFUN(), 100); diff --git a/es2panda/test/ts_extra_tests/test_ts_cases/4.3/override_and_the_noImplicitOverride_Flag/override_and_the_noImplicitOverride_Flag.ts b/es2panda/test/ts_extra_tests/test_ts_cases/4.3/override_and_the_noImplicitOverride_Flag/override_and_the_noImplicitOverride_Flag.ts new file mode 100644 index 0000000000000000000000000000000000000000..99a9b6f11ff4c861e9a66d167d4564d3c42aa4e3 --- /dev/null +++ b/es2panda/test/ts_extra_tests/test_ts_cases/4.3/override_and_the_noImplicitOverride_Flag/override_and_the_noImplicitOverride_Flag.ts @@ -0,0 +1,50 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/**--- + description: > + adds the override keyword.provides a new noImplicitOverride flag.When this option is turned on, it becomes an error to override any method from a superclass unless you explicitly use an override keyword. + In that last example, TypeScript would error under noImplicitOverride, and give us a clue that we probably need to rename our method inside of Derived. + And index signatures can now be declared as static. + module: ESNext + isCurrent: true + ---*/ + + +import { Assert } from "../../../suite/assert.js" + +class Boss { + run(person?: string): string { + return person + " go" + } +} +class Manage extends Boss { + run(person?: string): string { + return super.run(person); + } +} +class Staff extends Boss { + override run(person?: string): string { + super.run(); + return person + " run"; + } +} +let boss = new Boss(); +Assert.equal(boss.run("boss"), "boss go"); + +let manage = new Manage(); +Assert.equal(manage.run("manage"), "manage go"); + +let staff = new Staff(); +Assert.equal(staff.run("staff"), "staff run"); diff --git a/es2panda/test/ts_extra_tests/test_ts_cases/4.3/separate_write_types_on_properties/separate_write_types_on_properties_1.ts b/es2panda/test/ts_extra_tests/test_ts_cases/4.3/separate_write_types_on_properties/separate_write_types_on_properties_1.ts new file mode 100644 index 0000000000000000000000000000000000000000..a925554105efb1099721244b9f688a062a9248b7 --- /dev/null +++ b/es2panda/test/ts_extra_tests/test_ts_cases/4.3/separate_write_types_on_properties/separate_write_types_on_properties_1.ts @@ -0,0 +1,65 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/**--- + description: > + TypeScript 4.3 allows to specify types for reading and writing to properties. + When considering how two properties with the same name relate to each other, TypeScript will only use the "reading" type. + "Writing" types are only considered when directly writing to a property. + options: + target: es2015 + lib: es2015 + module: ESNext + isCurrent: true + ---*/ + + +import { Assert } from "../../../suite/assert.js" + +class SWTC1 { + #data = 0; + get data(): number { + return this.#data; + } + set data(val: string | number | boolean) { + if (val === undefined || val === null) { + this.#data = NaN; + } else if (typeof val === "number") { + this.#data = val; + } else if (typeof val === "string") { + this.#data = val.length; + } else if (typeof val === "boolean") { + if (val === false) { + this.#data = 0; + } else if (val === true) { + this.#data = 1; + } + } + } +} + +let c = new SWTC1(); +let n: number = 0; + +c.data = "hello"; +n = c.data; +Assert.equal(n, 5); + +c.data = 42; +n = c.data; +Assert.equal(n, 42); + +c.data = true; +n = c.data; +Assert.equal(n, 1); diff --git a/es2panda/test/ts_extra_tests/test_ts_cases/4.3/separate_write_types_on_properties/separate_write_types_on_properties_2.ts b/es2panda/test/ts_extra_tests/test_ts_cases/4.3/separate_write_types_on_properties/separate_write_types_on_properties_2.ts new file mode 100644 index 0000000000000000000000000000000000000000..c765ea1462e29fa33ba3611e5551e96fc67923c2 --- /dev/null +++ b/es2panda/test/ts_extra_tests/test_ts_cases/4.3/separate_write_types_on_properties/separate_write_types_on_properties_2.ts @@ -0,0 +1,64 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/**--- + description: > + Be able to write getters and setters with different types in object literals. + options: + lib: es2015 + module: ESNext + isCurrent: true + ---*/ + + +import { Assert } from "../../../suite/assert.js" + +interface SWTC2 { + get data(): number; + set data(val: number | string | boolean); +} + +function funSW(): SWTC2 { + let data = 0; + return { + get data(): number { + return data; + }, + set data(val: string | number | boolean) { + if (val === undefined || val === null) { + data = NaN; + } else if (typeof val === "number") { + data = val; + } else if (typeof val === "string") { + data = val.length; + } else if (typeof val === "boolean") { + if (val === false) { + data = 0; + } else if (val === true) { + data = 1; + } + } + }, + }; +} + +let t = funSW(); +t.data = "NARC"; +Assert.equal(t.data, 4); + +t.data = true; +Assert.equal(t.data, 1); + +t.data = 1024; +Assert.equal(t.data, 1024); diff --git a/es2panda/test/ts_extra_tests/test_ts_cases/4.3/static_index_signatures/static_index_signatures.ts b/es2panda/test/ts_extra_tests/test_ts_cases/4.3/static_index_signatures/static_index_signatures.ts new file mode 100644 index 0000000000000000000000000000000000000000..99f3ab95448efba2d92135be9df6d551c297a466 --- /dev/null +++ b/es2panda/test/ts_extra_tests/test_ts_cases/4.3/static_index_signatures/static_index_signatures.ts @@ -0,0 +1,59 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/**--- + description: > + Index signatures allow us set more properties on a value than a type explicitly declares, + And index signatures can now be declared as static. + module: ESNext + isCurrent: true + ---*/ + + +import { Assert } from "../../../suite/assert.js" + +class SIS { + hello = "hello"; + world = "1213"; + [propName: string]: string | number | undefined; +} + +let sis = new SIS(); +sis["Yes!Yes!Yes!"] = 42; +Assert.equal(sis["Yes!Yes!Yes!"], 42); + +let x = sis["No!No!No!"]; +x = undefined; +Assert.isUndefined(x); +x = 20; +Assert.equal(x, 20); +x = "x"; +Assert.equal(x, "x"); + +class B { + static hello = "hello"; + static world = 1342; + static [propName: string]: string | number | undefined; +} + +B["Yes!Yes!Yes!"] = 42; +Assert.equal(B["Yes!Yes!Yes!"], 42); + +let y = B["No!No!No!"]; +y = "y"; +Assert.equal(y, "y"); +y = 10; +Assert.equal(y, 10); +y = undefined; +Assert.isUndefined(y); diff --git a/es2panda/test/ts_extra_tests/test_ts_cases/4.3/template_string_type_improvements/template_string_type_improvements_1.ts b/es2panda/test/ts_extra_tests/test_ts_cases/4.3/template_string_type_improvements/template_string_type_improvements_1.ts new file mode 100644 index 0000000000000000000000000000000000000000..ff93498ef3fe73b1dafbf9b39407732c18d2b29e --- /dev/null +++ b/es2panda/test/ts_extra_tests/test_ts_cases/4.3/template_string_type_improvements/template_string_type_improvements_1.ts @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/**--- + description: > + Template string types are types that either construct new string-like types by concatenating, + or match patterns of other string-like types. + module: ESNext + isCurrent: true + ---*/ + + +import { Assert } from "../../../suite/assert.js" + +type Figure = "three-colour" | "pure color"; +type Num = "one" | "two"; + +type Cat1 = `${Num | Figure} cat`; +type Cat2 = "one cat" | "two cat" | "three-colour cat" | "pure color cat"; +var cat1: Cat1 = "pure color cat"; +var cat2: Cat2 = cat1; +cat1 = "one cat"; +cat2 = cat1; +cat1 = "three-colour cat"; +cat2 = cat1; +cat1 = "two cat"; +cat2 = cat1; + +let s1: `${number}-${number}-${number}`; +let s2: `1-2-3` = `1-2-3`; +s1 = s2; +Assert.equal(s1, "1-2-3"); diff --git a/es2panda/test/ts_extra_tests/test_ts_cases/4.3/template_string_type_improvements/template_string_type_improvements_2.ts b/es2panda/test/ts_extra_tests/test_ts_cases/4.3/template_string_type_improvements/template_string_type_improvements_2.ts new file mode 100644 index 0000000000000000000000000000000000000000..d957eb3f4f2118638f9db569340849b180801946 --- /dev/null +++ b/es2panda/test/ts_extra_tests/test_ts_cases/4.3/template_string_type_improvements/template_string_type_improvements_2.ts @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/**--- + description: > + When a template string is contextually typed by a string-literal-like type it will try to give that expression a template type. + This also kicks in when inferring types, and the type parameter extends string. + module: ESNext + isCurrent: true + ---*/ + + +import { Assert } from "../../../suite/assert.js" + +function funStr(s: string): `hello ${string}` { + return `hello ${s}`; +} +var b = funStr("s"); +Assert.equal(b, "hello s"); + +let s: string = "s"; +function f(x: T): T { + return x; +} +let x: `hello ${string}` = f(`hello ${s}`); +Assert.equal(x, "hello s"); diff --git a/es2panda/test/ts_extra_tests/test_ts_cases/4.3/template_string_type_improvements/template_string_type_improvements_3.ts b/es2panda/test/ts_extra_tests/test_ts_cases/4.3/template_string_type_improvements/template_string_type_improvements_3.ts new file mode 100644 index 0000000000000000000000000000000000000000..87d00e6a13eb9cd14f5c6e6d3b392a9c77de1e8f --- /dev/null +++ b/es2panda/test/ts_extra_tests/test_ts_cases/4.3/template_string_type_improvements/template_string_type_improvements_3.ts @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/**--- + description: > + TypeScript can now better-relate, and infer between, different template string types. + module: ESNext + isCurrent: true + ---*/ + + +import { Assert } from "../../../suite/assert.js" + +let sn1: `${number}-${number}-${number}`; +let sn2: `1-2-3` = `1-2-3`; +let sn3: `${number}-2-3` = `${4}-2-3`; +let sn4: `1-${number}-3` = `1-${5}-3`; +let sn5: `1-2-${number}` = `1-2-${6}`; +let sn6: `${number}-2-${number}` = `${7}-2-${8}`; + +sn1 = sn2; +Assert.equal(sn1, "1-2-3"); +sn1 = sn3; +Assert.equal(sn1, "4-2-3"); +sn1 = sn4; +Assert.equal(sn1, "1-5-3"); +sn1 = sn5; +Assert.equal(sn1, "1-2-6"); +sn1 = sn6; +Assert.equal(sn1, "7-2-8"); diff --git a/es2panda/test/ts_extra_tests/test_ts_cases/4.3/template_string_type_improvements/template_string_type_improvements_4.ts b/es2panda/test/ts_extra_tests/test_ts_cases/4.3/template_string_type_improvements/template_string_type_improvements_4.ts new file mode 100644 index 0000000000000000000000000000000000000000..71d4db250fe93f744314e4a0a0b0f4ed44f69e7c --- /dev/null +++ b/es2panda/test/ts_extra_tests/test_ts_cases/4.3/template_string_type_improvements/template_string_type_improvements_4.ts @@ -0,0 +1,51 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/**--- + description: > + TypeScript add better inference capabilities + module: ESNext + isCurrent: true + ---*/ + + +import { Assert } from "../../../suite/assert.js" + +function funStr01(arg: `*${V}*`): `*${V}*` { + return arg; +} +function funStr02(s: string, n: number, b: boolean, t: T) { + let x1 = funStr01("*hello*"); + Assert.equal(x1, "*hello*"); + + let x2 = funStr01("**hello**"); + Assert.equal(x2, "**hello**"); + + let x3 = funStr01(`*${s}*` as const); + Assert.equal(x3, "*s*"); + + let x4 = funStr01(`*${n}*` as const); + Assert.equal(x4, "*5*"); + + let x5 = funStr01(`*${b}*` as const); + Assert.equal(x5, "*true*"); + + let x6 = funStr01(`*${t}*` as const); + Assert.equal(x6, "*t*"); + + let x7 = funStr01(`**${s}**` as const); + Assert.equal(x7, "**s**"); +} + +funStr02("s", 5, true, "t"); diff --git a/es2panda/test/ts_extra_tests/test_ts_cases/4.3/union_enums_cannot_be_compared_to_arbitrary_numbers/union_enums_cannot_be_compared_to_arbitrary_numbers.ts b/es2panda/test/ts_extra_tests/test_ts_cases/4.3/union_enums_cannot_be_compared_to_arbitrary_numbers/union_enums_cannot_be_compared_to_arbitrary_numbers.ts new file mode 100644 index 0000000000000000000000000000000000000000..1ff166bc825d1f420b82786b5f95bd3a051f349b --- /dev/null +++ b/es2panda/test/ts_extra_tests/test_ts_cases/4.3/union_enums_cannot_be_compared_to_arbitrary_numbers/union_enums_cannot_be_compared_to_arbitrary_numbers.ts @@ -0,0 +1,63 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/**--- + description: > + If a value with a union enum type is compared with a numeric literal that it could never be equal to, + then the type-checker will issue an error. + As a workaround, you can re-write an annotation to include the appropriate literal type. + You can also use a type-assertion on the value. + Alternatively, you can re-declare your enum to have a non-trivial initializer so that any number is both assignable and comparable to that enum. + module: ESNext + isCurrent: true + ---*/ + + +import { Assert } from "../../../suite/assert.js" + +enum AB { + A = 0, + B = 1, +} + +function eFun01(x: AB | -1) { + if (x === -1) { + return -1; + } + return 1; +} +Assert.equal(eFun01(-1), -1); +Assert.equal(eFun01(AB.A), 1); + +function eFun02(x: AB) { + if ((x as number) === -1) { + return x; + } + return x + 1; +} +Assert.equal(eFun02(AB.A), 1); + +enum ab { + A = +0, + B = 1, +} +function eFun03(x: ab) { + if (x === 1) { + return x; + } + return x + 2; +} + +Assert.equal(eFun03(ab.A), 2); +Assert.equal(eFun03(ab.B), 1); diff --git a/es2panda/test/ts_extra_tests/test_ts_cases/4.4/control_flow_analysis_of_aliased_conditions_and_discriminants/control_flow_analysis_of_aliased_conditions_and_discriminants_1.ts b/es2panda/test/ts_extra_tests/test_ts_cases/4.4/control_flow_analysis_of_aliased_conditions_and_discriminants/control_flow_analysis_of_aliased_conditions_and_discriminants_1.ts new file mode 100644 index 0000000000000000000000000000000000000000..bfe2bf2e4ec5543e17ab7c0bc3a399c4f3f291e0 --- /dev/null +++ b/es2panda/test/ts_extra_tests/test_ts_cases/4.4/control_flow_analysis_of_aliased_conditions_and_discriminants/control_flow_analysis_of_aliased_conditions_and_discriminants_1.ts @@ -0,0 +1,85 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/**--- + description: > + When TypeScript sees that we are testing a constant value, it will do a little bit of extra work to see if it contains a type guard. + If that type guard operates on a const, a readonly property, or an un-modified parameter, + then TypeScript is able to narrow that value appropriately. + module: ESNext + isCurrent: true + ---*/ + + +import { Assert } from '../../../suite/assert.js' + +function fun01(a: unknown) { + if (typeof a === "string") { + Assert.equal(a[0], "c"); + } + if (typeof a === "number") { + Assert.equal(a, 11); + } + if (typeof a === "boolean") { + Assert.equal(a, true); + } + if (typeof a === "undefined") { + Assert.isUndefined(a); + } + if (typeof a === "function") { + Assert.isFunction(a); + } + if (typeof a === "object") { + Assert.isObject(a); + } + if (typeof a === "symbol") { + Assert.isSymbol(a); + } +} +fun01("c"); +fun01(11); +fun01(true); +let x: undefined; +fun01(x); +let f = (a: number) => { a = 0; return a; }; +fun01(f); +let obj: object = { + x: 1 +} +fun01(obj); +let sym: symbol = Symbol('a'); +fun01(sym); +interface I { + readonly name: "caihua"; +} +function fun02() { + let tt: I = { name: "caihua" }; + let res = tt.name === "caihua"; + if (res) { + Assert.isNumber(tt.name.length); + Assert.equal(tt.name[0], "c"); + } +} +fun02(); +function fun03(a: number, b = "function" as const) { + let cc = typeof b === "function"; + if (cc) { + Assert.isNumber(b.length); + Assert.equal(b[0], "f"); + Assert.equal(cc, true); + } else { + Assert.equal(cc, false); + } +} +fun03(12); \ No newline at end of file diff --git a/es2panda/test/ts_extra_tests/test_ts_cases/4.4/control_flow_analysis_of_aliased_conditions_and_discriminants/control_flow_analysis_of_aliased_conditions_and_discriminants_2.ts b/es2panda/test/ts_extra_tests/test_ts_cases/4.4/control_flow_analysis_of_aliased_conditions_and_discriminants/control_flow_analysis_of_aliased_conditions_and_discriminants_2.ts new file mode 100644 index 0000000000000000000000000000000000000000..6327ee0e6c45cac06319d015dcc4b934a7ef3e7b --- /dev/null +++ b/es2panda/test/ts_extra_tests/test_ts_cases/4.4/control_flow_analysis_of_aliased_conditions_and_discriminants/control_flow_analysis_of_aliased_conditions_and_discriminants_2.ts @@ -0,0 +1,48 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/**--- + description: Different sorts of type guard conditions are preserved. For example, checks on discriminated unions + module: ESNext + isCurrent: true + ---*/ + + +import { Assert } from '../../../suite/assert.js' + +type T1 = { name: "x1"; size: number }; +type T2 = { name: "x2"; sideLength: number }; +type T3 = T1 | T2; +let c: T1 = { name: "x1", size: 2 }; +let s: T2 = { name: "x2", sideLength: 2 }; +function fun01(shape: T3): number { + const isx1 = shape.name === "x1"; + if (isx1) { + return Math.PI * shape.size ** 2; + } else { + return shape.sideLength ** 2; + } +} +Assert.equal(Math.round(fun01(c)), 13); +Assert.equal(fun01(s), 4); +function fun02(shape: T3): number { + const { name } = shape; + if (name === "x1") { + return Math.PI * shape.size ** 2; + } else { + return shape.sideLength ** 2; + } +} +Assert.equal(Math.round(fun02(c)), 13); +Assert.equal(fun02(s), 4); \ No newline at end of file diff --git a/es2panda/test/ts_extra_tests/test_ts_cases/4.4/control_flow_analysis_of_aliased_conditions_and_discriminants/control_flow_analysis_of_aliased_conditions_and_discriminants_3.ts b/es2panda/test/ts_extra_tests/test_ts_cases/4.4/control_flow_analysis_of_aliased_conditions_and_discriminants/control_flow_analysis_of_aliased_conditions_and_discriminants_3.ts new file mode 100644 index 0000000000000000000000000000000000000000..1fd1125523bb505f258a1b05bfb592001a196676 --- /dev/null +++ b/es2panda/test/ts_extra_tests/test_ts_cases/4.4/control_flow_analysis_of_aliased_conditions_and_discriminants/control_flow_analysis_of_aliased_conditions_and_discriminants_3.ts @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/**--- + description: > + Different sorts of type guard conditions are preserved. + As another example, here’s a function that checks whether two of its inputs have contents. + module: ESNext + isCurrent: true + ---*/ + + +import { Assert } from '../../../suite/assert.js' + +function fun01(a: string | undefined, b: number | undefined, c: boolean) { + const res = a && b && c; + if (res) { + Assert.equal(a.toLowerCase(), "abc"); + Assert.equal(b, 1); + Assert.equal(c, true); + return 1; + } else { + return 0; + } +} +Assert.equal(fun01("abc", 1, true), 1); +Assert.equal(fun01("abc", undefined, true), 0); \ No newline at end of file diff --git a/es2panda/test/ts_extra_tests/test_ts_cases/4.4/control_flow_analysis_of_aliased_conditions_and_discriminants/control_flow_analysis_of_aliased_conditions_and_discriminants_4.ts b/es2panda/test/ts_extra_tests/test_ts_cases/4.4/control_flow_analysis_of_aliased_conditions_and_discriminants/control_flow_analysis_of_aliased_conditions_and_discriminants_4.ts new file mode 100644 index 0000000000000000000000000000000000000000..197743bae24adfba21f3029e71ebbef36ffae54d --- /dev/null +++ b/es2panda/test/ts_extra_tests/test_ts_cases/4.4/control_flow_analysis_of_aliased_conditions_and_discriminants/control_flow_analysis_of_aliased_conditions_and_discriminants_4.ts @@ -0,0 +1,69 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/**--- + description: > + One neat feature here is that this analysis works transitively. + TypeScript will hop through constants to understand what sorts of checks you’ve already performed. + module: ESNext + isCurrent: true + ---*/ + + +import { Assert } from '../../../suite/assert.js' + +function isBool(a: unknown) { + if (typeof a === "string") { + Assert.equal(a[0], "f"); + } + if (typeof a === "number") { + Assert.equal(a, 12); + } + if (typeof a === "boolean") { + Assert.isBoolean(a); + } + if (typeof a === "undefined") { + Assert.isUndefined(a); + } + if (typeof a === "function") { + Assert.isFunction(a); + } + if (typeof a === "object") { + Assert.isObject(a); + } + if (typeof a === "symbol") { + Assert.isSymbol(a); + } + const x = typeof a === "string"; + const y = typeof a === "number"; + const z = x || y; + if (z) { + return 0; + } else { + return 1; + } +} +Assert.equal(isBool(false), 1); +Assert.equal(isBool("false"), 0); +Assert.equal(isBool(12), 0); +let x: undefined; +Assert.equal(isBool(x), 1); +let f = (a: number) => { a = 0; return a; }; +Assert.equal(isBool(f), 1); +let obj: object = { + x: 1 +} +Assert.equal(isBool(obj), 1); +let sym: symbol = Symbol('a'); +Assert.equal(isBool(sym), 1); \ No newline at end of file diff --git a/es2panda/test/ts_extra_tests/test_ts_cases/4.4/defaulting_to_the_unknown_type_in_catch_variables/defaulting_to_the_unknown_type_in_catch_variables_1.ts b/es2panda/test/ts_extra_tests/test_ts_cases/4.4/defaulting_to_the_unknown_type_in_catch_variables/defaulting_to_the_unknown_type_in_catch_variables_1.ts new file mode 100644 index 0000000000000000000000000000000000000000..1b32668a96ad37d66cfe8997f9666458569d4f9d --- /dev/null +++ b/es2panda/test/ts_extra_tests/test_ts_cases/4.4/defaulting_to_the_unknown_type_in_catch_variables/defaulting_to_the_unknown_type_in_catch_variables_1.ts @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/**--- + description: > + TypeScript 4.4 introduces a new flag called useUnknownInCatchVariables. + This flag changes the default type of catch clause variables from any to unknown. + module: ESNext + isCurrent: true + ---*/ + + +import { Assert } from '../../../suite/assert.js' + +function fun(a: any) { + if (typeof a === "number") { + } else { + throw new Error("type error"); + } +} + +try { + fun("string"); +} catch (err) { + Assert.equal(err instanceof Error, true); + if (err instanceof Error) { + Assert.equal(err.message, "type error"); + } +}; diff --git a/es2panda/test/ts_extra_tests/test_ts_cases/4.4/defaulting_to_the_unknown_type_in_catch_variables/defaulting_to_the_unknown_type_in_catch_variables_2.ts b/es2panda/test/ts_extra_tests/test_ts_cases/4.4/defaulting_to_the_unknown_type_in_catch_variables/defaulting_to_the_unknown_type_in_catch_variables_2.ts new file mode 100644 index 0000000000000000000000000000000000000000..47e6410eaab9487278afd159d001ec1699016b77 --- /dev/null +++ b/es2panda/test/ts_extra_tests/test_ts_cases/4.4/defaulting_to_the_unknown_type_in_catch_variables/defaulting_to_the_unknown_type_in_catch_variables_2.ts @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/**--- + description: > + useUnknownInCatchVariables flag is enabled under the strict family of options. + That means that if you check your code using strict, this option will automatically be turned on + module: ESNext + isCurrent: true + ---*/ + + +import { Assert } from '../../../suite/assert.js' + +function fun(a: any) { + if (typeof a === "number") { + } else { + throw new Error("type error"); + } +} + +try { + fun("string"); +} catch (err) { + Assert.equal(err instanceof Error, true); + if (err instanceof Error) { + Assert.equal(err.message, "type error"); + } +}; diff --git a/es2panda/test/ts_extra_tests/test_ts_cases/4.4/defaulting_to_the_unknown_type_in_catch_variables/defaulting_to_the_unknown_type_in_catch_variables_3.ts b/es2panda/test/ts_extra_tests/test_ts_cases/4.4/defaulting_to_the_unknown_type_in_catch_variables/defaulting_to_the_unknown_type_in_catch_variables_3.ts new file mode 100644 index 0000000000000000000000000000000000000000..7820b475cdded63794e663fabbd449eca878f4df --- /dev/null +++ b/es2panda/test/ts_extra_tests/test_ts_cases/4.4/defaulting_to_the_unknown_type_in_catch_variables/defaulting_to_the_unknown_type_in_catch_variables_3.ts @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/**--- + description: > + In cases where we don’t want to deal with an unknown variable in a catch clause, + we can always add an explicit : any annotation so that we can opt out of stricter types. + module: ESNext + isCurrent: true + ---*/ + + +import { Assert } from '../../../suite/assert.js' + +function fun(a: any) { + if (typeof a === "number") { + } else { + throw new Error("type error"); + } +} + +try { + fun("string"); +} catch (err: any) { + Assert.equal(err instanceof Error, true); + Assert.equal(err.message, "type error"); +}; diff --git a/es2panda/test/ts_extra_tests/test_ts_cases/4.4/exact_optional_property_types/exact_optional_property_types_1.ts b/es2panda/test/ts_extra_tests/test_ts_cases/4.4/exact_optional_property_types/exact_optional_property_types_1.ts new file mode 100644 index 0000000000000000000000000000000000000000..3ec83281b80f91a70c049a1e582aff0c01587f7f --- /dev/null +++ b/es2panda/test/ts_extra_tests/test_ts_cases/4.4/exact_optional_property_types/exact_optional_property_types_1.ts @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/**--- + description: > + In TypeScript 4.4, the new flag exactOptionalPropertyTypes specifies that optional property types + should be interpreted exactly as written, meaning that | undefined is not added to the type + This flag needs to be turned on explicitly. It also requires strictNullChecks to be enabled as well. + module: ESNext + isCurrent: true + ---*/ + + +import { Assert } from '../../../suite/assert.js' + +interface I { + x: string; + y?: number; +} +const p: I = { + x: "aaaa", +}; +const keys = Object.keys(p); +Assert.equal(keys.indexOf("y"), -1); +Assert.equal(typeof p.y, "undefined"); +Assert.notEqual(typeof p.y, "number"); +p.y = 12; +Assert.equal(typeof p.y, "number"); +Assert.notEqual(typeof p.y, "undefined"); \ No newline at end of file diff --git a/es2panda/test/ts_extra_tests/test_ts_cases/4.4/static_blocks_in_classe/static_blocks_in_classes1.ts b/es2panda/test/ts_extra_tests/test_ts_cases/4.4/static_blocks_in_classe/static_blocks_in_classes1.ts new file mode 100644 index 0000000000000000000000000000000000000000..40f59e3ee24721937986de38bb0326bb3522d959 --- /dev/null +++ b/es2panda/test/ts_extra_tests/test_ts_cases/4.4/static_blocks_in_classe/static_blocks_in_classes1.ts @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/**--- + description: > + These static blocks allow you to write a sequence of statements with their own scope + that can access private fields within the containing class. + we can write initialization code with all the capabilities of writing statements, no leakage of variables, and full access to our class’s internals. + options: + target: es2015 + module: ESNext + isCurrent: true + ---*/ + + +import { Assert } from '../../../suite/assert.js' + +class C { + static #aa = 0; + + get aaValue() { + return C.#aa; + } + + static { + C.#aa++; + } +} +let x = new C(); +Assert.equal(x.aaValue, 1); diff --git a/es2panda/test/ts_extra_tests/test_ts_cases/4.4/static_blocks_in_classe/static_blocks_in_classes2.ts b/es2panda/test/ts_extra_tests/test_ts_cases/4.4/static_blocks_in_classe/static_blocks_in_classes2.ts new file mode 100644 index 0000000000000000000000000000000000000000..40a0eaa36d3d7efc456eefcfeecbd6d281fa3f8b --- /dev/null +++ b/es2panda/test/ts_extra_tests/test_ts_cases/4.4/static_blocks_in_classe/static_blocks_in_classes2.ts @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/**--- + description: a class can have multiple static blocks, and they’re run in the same order in which they’re written. + module: ESNext + isCurrent: true + ---*/ + + +import { Assert } from '../../../suite/assert.js' + +class C { + static aa = 0; + + get aaValue() { + return C.aa; + } + static { + C.aa++; + Assert.equal(C.aa, 1); + } + static { + C.aa++; + Assert.equal(C.aa, 2); + } + static { + C.aa++; + Assert.equal(C.aa, 3); + } +} +new C(); +Assert.equal(C.aa, 3); \ No newline at end of file diff --git a/es2panda/test/ts_extra_tests/test_ts_cases/4.4/symbol_and_templates_string_pattern_index_signatures/symbol_and_templates_string_pattern_index_signatures_1.ts b/es2panda/test/ts_extra_tests/test_ts_cases/4.4/symbol_and_templates_string_pattern_index_signatures/symbol_and_templates_string_pattern_index_signatures_1.ts new file mode 100644 index 0000000000000000000000000000000000000000..8c3e13e57a3bf86aed4c7b18f1ada45e95be97e4 --- /dev/null +++ b/es2panda/test/ts_extra_tests/test_ts_cases/4.4/symbol_and_templates_string_pattern_index_signatures/symbol_and_templates_string_pattern_index_signatures_1.ts @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/**--- + description: > + TypeScript lets us describe objects where every property has to have a certain type using index signatures. + This allows us to use these objects as dictionary-like types, where we can use string keys to index into them with square brackets. + module: ESNext + isCurrent: true + ---*/ + + +import { Assert } from '../../../suite/assert.js' + +interface I { + [key: string]: any; +} +let t: I = {}; +t["1"] = 1; +t["2"] = "1"; +const keys = Object.keys(t); +keys.forEach((item) => { + Assert.isString(item); +}); diff --git a/es2panda/test/ts_extra_tests/test_ts_cases/4.4/symbol_and_templates_string_pattern_index_signatures/symbol_and_templates_string_pattern_index_signatures_2.ts b/es2panda/test/ts_extra_tests/test_ts_cases/4.4/symbol_and_templates_string_pattern_index_signatures/symbol_and_templates_string_pattern_index_signatures_2.ts new file mode 100644 index 0000000000000000000000000000000000000000..856247e66a0de44dd11803f5e52a8d2204fa8f6b --- /dev/null +++ b/es2panda/test/ts_extra_tests/test_ts_cases/4.4/symbol_and_templates_string_pattern_index_signatures/symbol_and_templates_string_pattern_index_signatures_2.ts @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/**--- + description: Array already defines a number index signature that lets us insert/retrieve values of type T + module: ESNext + isCurrent: true + ---*/ + + +import { Assert } from '../../../suite/assert.js' + +let x: Array = []; +x[0] = "a"; +Assert.equal(x[0], "a"); +Assert.isString(x[0]); +x[1] = 12; +Assert.equal(x[1], 12); +Assert.isNumber(x[1]); diff --git a/es2panda/test/ts_extra_tests/test_ts_cases/4.4/symbol_and_templates_string_pattern_index_signatures/symbol_and_templates_string_pattern_index_signatures_3.ts b/es2panda/test/ts_extra_tests/test_ts_cases/4.4/symbol_and_templates_string_pattern_index_signatures/symbol_and_templates_string_pattern_index_signatures_3.ts new file mode 100644 index 0000000000000000000000000000000000000000..4943f196de66dee6fdc7916b86ffcd3fece0ab7a --- /dev/null +++ b/es2panda/test/ts_extra_tests/test_ts_cases/4.4/symbol_and_templates_string_pattern_index_signatures/symbol_and_templates_string_pattern_index_signatures_3.ts @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/**--- + description: TypeScript 4.4 allows index signatures for symbols and template string patterns. + options: + lib:es2015 + module: ESNext + isCurrent: true + ---*/ + + +import { Assert } from '../../../suite/assert.js' + +interface I { + [keys: number | string]: any; +} +const x: any = Symbol("x"); +const y: any = Symbol("y"); +const z: any = Symbol("z"); +let c: I = {}; +c[x] = 0xff0000; +c[y] = 0x00ff00; +c[z] = 0x0000ff; +Assert.isNumber(c[x]); \ No newline at end of file diff --git a/es2panda/test/ts_extra_tests/test_ts_cases/4.4/symbol_and_templates_string_pattern_index_signatures/symbol_and_templates_string_pattern_index_signatures_4.ts b/es2panda/test/ts_extra_tests/test_ts_cases/4.4/symbol_and_templates_string_pattern_index_signatures/symbol_and_templates_string_pattern_index_signatures_4.ts new file mode 100644 index 0000000000000000000000000000000000000000..c169e0dcb606a674ec9f1e8efe8bd9b3b4ec2b42 --- /dev/null +++ b/es2panda/test/ts_extra_tests/test_ts_cases/4.4/symbol_and_templates_string_pattern_index_signatures/symbol_and_templates_string_pattern_index_signatures_4.ts @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/**--- + description: we can write an index signature with template string pattern type + module: ESNext + isCurrent: true + ---*/ + + +import { Assert } from '../../../suite/assert.js' + +interface I { + name: string; + age: number; +} +interface I2 extends I { + [optName: number]: any; +} +let a: I2 = { + name: "wangcai", + age: 20 +}; +Assert.isString(a.name); +Assert.isNumber(a.age); \ No newline at end of file diff --git a/es2panda/test/ts_extra_tests/test_ts_cases/4.4/symbol_and_templates_string_pattern_index_signatures/symbol_and_templates_string_pattern_index_signatures_5.ts b/es2panda/test/ts_extra_tests/test_ts_cases/4.4/symbol_and_templates_string_pattern_index_signatures/symbol_and_templates_string_pattern_index_signatures_5.ts new file mode 100644 index 0000000000000000000000000000000000000000..fd4ef12cf0cd7aa6271aee0d092d7f2f9c309b66 --- /dev/null +++ b/es2panda/test/ts_extra_tests/test_ts_cases/4.4/symbol_and_templates_string_pattern_index_signatures/symbol_and_templates_string_pattern_index_signatures_5.ts @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/**--- + description: > + index signatures now permit union types,as long as they’re a union of infinite-domain primitive types + specifically:string,number,symbol,template string patterns + An index signature whose argument is a union of these types will de-sugar into several different index signatures. + options: + lib:es2015 + module: ESNext + isCurrent: true + ---*/ + + +import { Assert } from '../../../suite/assert.js' + +interface I1 { + [key: number]: any; +} +interface I2 { + + [key: number]: any; +} +interface I3 extends I2 { + [key: number]: any; +} +const one: 1 = 1; +let a: I1 = {}; +let b: I3 = {}; +b[one] = 1; +a = b; +Assert.equal(a[one], 1); \ No newline at end of file diff --git a/es2panda/test/ts_extra_tests/test_ts_cases/4.5/disabling_import_elision/disabling_import_elision_1.ts b/es2panda/test/ts_extra_tests/test_ts_cases/4.5/disabling_import_elision/disabling_import_elision_1.ts new file mode 100644 index 0000000000000000000000000000000000000000..de587ac3daeee7af966e5f76d87600f4cd6eb8a9 --- /dev/null +++ b/es2panda/test/ts_extra_tests/test_ts_cases/4.5/disabling_import_elision/disabling_import_elision_1.ts @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/**--- + description: > + TypeScript 4.5, you can enable a new flag called preserveValueImports to prevent TypeScript + from stripping out any imported values from your JavaScript outputs. + module: ESNext + isCurrent: true +---*/ + + +import { Assert } from "../../../suite/assert.js"; +import { human } from "./human.js"; + +Assert.isFunction(human); \ No newline at end of file diff --git a/es2panda/test/ts_extra_tests/test_ts_cases/4.5/disabling_import_elision/human.ts b/es2panda/test/ts_extra_tests/test_ts_cases/4.5/disabling_import_elision/human.ts new file mode 100644 index 0000000000000000000000000000000000000000..53918940d0c6d9c96a0bbc207800be0e65eec3ef --- /dev/null +++ b/es2panda/test/ts_extra_tests/test_ts_cases/4.5/disabling_import_elision/human.ts @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + +export class Human { + name: string; + age: number; + gender: string; + constructor(name: string, age: number, gender: string) { + this.name = name; + this.age = age; + this.gender = gender; + } +} + +export { Human as human }; \ No newline at end of file diff --git a/es2panda/test/ts_extra_tests/test_ts_cases/4.5/private_field_presence_checks/private_field_presence_checks_1.ts b/es2panda/test/ts_extra_tests/test_ts_cases/4.5/private_field_presence_checks/private_field_presence_checks_1.ts new file mode 100644 index 0000000000000000000000000000000000000000..3d042696a57d343541f086b32bc2587b593a912d --- /dev/null +++ b/es2panda/test/ts_extra_tests/test_ts_cases/4.5/private_field_presence_checks/private_field_presence_checks_1.ts @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/**--- + description: > + You can now write a class with a #private field member and see whether another object has the same field by using the in operator. + module: ESNext + isCurrent: true +---*/ + + +import { Assert } from '../../../suite/assert.js' + +class RunP { + #type: string; + constructor(type: string) { + this.#type = type; + } + + combine(additional: any) { + return additional && + typeof additional === "object" && + #type in additional&& + this.#type === additional.#type; + } +} + +const men = new RunP('jack'); +const women = new RunP('marry'); +Assert.equal(women.combine(men), false); \ No newline at end of file diff --git a/es2panda/test/ts_extra_tests/test_ts_cases/4.5/tail_recursion_elimination_on_conditional_types/tail_recursion_elimination_on_conditional_types1.ts b/es2panda/test/ts_extra_tests/test_ts_cases/4.5/tail_recursion_elimination_on_conditional_types/tail_recursion_elimination_on_conditional_types1.ts new file mode 100644 index 0000000000000000000000000000000000000000..e893954d60b8d5ad14ddb9d253f3a87a5d6da635 --- /dev/null +++ b/es2panda/test/ts_extra_tests/test_ts_cases/4.5/tail_recursion_elimination_on_conditional_types/tail_recursion_elimination_on_conditional_types1.ts @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/**--- + description: > + As long as one branch of a conditional type is simply another conditional type, TypeScript can avoid intermediate instantiations. + module: ESNext + isCurrent: true +---*/ + + +import { Assert } from "../../../suite/assert.js" + +type project = T extends ` ${infer push}` ? project : T; + +type example = project<" tool">; +var t: example = "tool"; +Assert.equal(t, "tool"); diff --git a/es2panda/test/ts_extra_tests/test_ts_cases/4.5/tail_recursion_elimination_on_conditional_types/tail_recursion_elimination_on_conditional_types2.ts b/es2panda/test/ts_extra_tests/test_ts_cases/4.5/tail_recursion_elimination_on_conditional_types/tail_recursion_elimination_on_conditional_types2.ts new file mode 100644 index 0000000000000000000000000000000000000000..c8756ae053819800da7134a9701d6443069ddde0 --- /dev/null +++ b/es2panda/test/ts_extra_tests/test_ts_cases/4.5/tail_recursion_elimination_on_conditional_types/tail_recursion_elimination_on_conditional_types2.ts @@ -0,0 +1,50 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/**--- + description: > + The following type won't be optimized, since it uses the result of a conditional type by adding it to a union. + You can introduce a helper that takes an "accumulator" type parameter to make it tail-recursive + module: ESNext + isCurrent: true +---*/ + + +import { Assert } from "../../../suite/assert.js" + +type RunObtain = S extends `${infer Char}${infer Rest}` + ? Char | RunObtain + : never; +type gc = RunObtain<" getChar">; +var g1: gc = "e"; +Assert.isString(g1); + +type RunObtain1 = RunObtainHelper; +type RunObtainHelper = S extends `${infer Char}${infer Rest}` + ? RunObtainHelper + : Acc; + +type gch = RunObtainHelper; +var g2: gch = 10; +Assert.isNumber(g2); + +let g3: RunObtain1<' NEW'> = ' '; +Assert.equal(g3, ' '); +g3 = 'E'; +Assert.equal(g3, 'E'); + +let g4: RunObtainHelper<' NARC ', 'ACC'> = 'ACC'; +Assert.equal(g4, 'ACC'); +g4 = 'N'; +Assert.equal(g4, 'N'); \ No newline at end of file diff --git a/es2panda/test/ts_extra_tests/test_ts_cases/4.5/template_string_types_as_discriminants/template_string_types_as_discriminants_1.ts b/es2panda/test/ts_extra_tests/test_ts_cases/4.5/template_string_types_as_discriminants/template_string_types_as_discriminants_1.ts new file mode 100644 index 0000000000000000000000000000000000000000..26938121c1fac39ae257d12f89a29a87cdc14d90 --- /dev/null +++ b/es2panda/test/ts_extra_tests/test_ts_cases/4.5/template_string_types_as_discriminants/template_string_types_as_discriminants_1.ts @@ -0,0 +1,60 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/**--- +description: > + TypeScript 4.5 now can narrow values that have template string types, and also recognizes template string types as discriminants. +module: ESNext +isCurrent: true +---*/ + + +import { Assert } from "../../../suite/assert.js" + +interface Message { + pattern: string; + location: string; +} + +interface SMessage { + pattern: `${string}SMessage`; + location: string; +} + +interface EMessage { + pattern: `${string}EMessage`; + message: string; +} + +function RunTest(r: SMessage | EMessage |Message) { + if (r.pattern === "WinSMessage") { + let token = r.pattern; + Assert.equal(token, "WinSMessage"); + } else { + Assert.equal(r.pattern, "LostEMessage"); + } +} + +const successMessage: SMessage = { + pattern: "WinSMessage", + location: "request SMessage" +} + +const errorMessage: EMessage = { + pattern: "LostEMessage", + message: "100-continue" +} + +RunTest(successMessage); +RunTest(errorMessage); \ No newline at end of file diff --git a/es2panda/test/ts_extra_tests/test_ts_cases/4.5/the_awaited_type_and_promise_improvements/the_awaited_type_and_promise_improvements_1.ts b/es2panda/test/ts_extra_tests/test_ts_cases/4.5/the_awaited_type_and_promise_improvements/the_awaited_type_and_promise_improvements_1.ts new file mode 100644 index 0000000000000000000000000000000000000000..bab72306a085e50433aa6c205652fe99365e2b02 --- /dev/null +++ b/es2panda/test/ts_extra_tests/test_ts_cases/4.5/the_awaited_type_and_promise_improvements/the_awaited_type_and_promise_improvements_1.ts @@ -0,0 +1,47 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/**--- + description: > + TypeScript 4.5 introduces a new utility type called the Awaited type. + This type is meant to model operations like await in async functions, + or the .then() method on Promises - specifically, the way that they recursively unwrap Promises; + some of the problems around inference with Promise.all served as motivations for Awaited. + module: ESNext + isCurrent: true +---*/ + + +import { Assert } from "../../../suite/assert.js" + + +function ToP(value: number): number | Promise | PromiseLike { + return new Promise((resolve, reject) => { + resolve(Math.random()); + }); +} + +async function operate(): Promise<[number, number]> { + const result = await Promise.all([ToP(100), ToP(200)]); + return result; +} + +let D = operate().then(res => { + Assert.isObject(res, "object"); +}); + +type E = Awaited>; + +let e: E; +Assert.equal(e, undefined); \ No newline at end of file diff --git a/es2panda/test/ts_extra_tests/test_ts_cases/4.5/type_modifiers_on_import_names/some-module.ts b/es2panda/test/ts_extra_tests/test_ts_cases/4.5/type_modifiers_on_import_names/some-module.ts new file mode 100644 index 0000000000000000000000000000000000000000..3c939175fcba0b827ad03d0704a1fdb999664085 --- /dev/null +++ b/es2panda/test/ts_extra_tests/test_ts_cases/4.5/type_modifiers_on_import_names/some-module.ts @@ -0,0 +1,22 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + +let num = 5; +export let privateF = function () { + return 10 + num; +}; + +export class PrivateType { }; diff --git a/es2panda/test/ts_extra_tests/test_ts_cases/4.5/type_modifiers_on_import_names/type_modifiers_on_import_names_1.ts b/es2panda/test/ts_extra_tests/test_ts_cases/4.5/type_modifiers_on_import_names/type_modifiers_on_import_names_1.ts new file mode 100644 index 0000000000000000000000000000000000000000..6f5d5337cd5638856d6c87f688e1266cdc897ab3 --- /dev/null +++ b/es2panda/test/ts_extra_tests/test_ts_cases/4.5/type_modifiers_on_import_names/type_modifiers_on_import_names_1.ts @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/**--- +description: > + That’s part of why TypeScript 4.5 allows a type modifier on individual named imports. + BaseType is always guaranteed to be erased and someFunc will be preserved under preserveValueImports. +module: ESNext +isCurrent: true +---*/ + + +import { Assert } from "../../../suite/assert.js" +import type { PrivateType } from "./some-module.js" +import { privateF } from "./some-module.js" + + +export class Type implements PrivateType { + func() { + return privateF(); + } +} + +const type = new Type(); +Assert.isFunction(Type); +Assert.equal(type.func(), 15); \ No newline at end of file diff --git a/es2panda/test/ts_extra_tests/test_ts_cases/4.6/1_allowing_code_in_constructors.ts b/es2panda/test/ts_extra_tests/test_ts_cases/4.6/1_allowing_code_in_constructors.ts new file mode 100644 index 0000000000000000000000000000000000000000..1ce1356b83e099a9f028997863d223146ff1b544 --- /dev/null +++ b/es2panda/test/ts_extra_tests/test_ts_cases/4.6/1_allowing_code_in_constructors.ts @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/**--- + description: TypeScript 4.6 is now much more lenient in that check and permits other code to run before super()., all while still ensuring that super() occurs at the top-level before any references to this. + module: ESNext + isCurrent: true +---*/ + + +import { Assert } from '../../suite/assert.js' + +class C { + a: number = 1; +} +class C2 extends C { + bool = true; + constructor() { + let x = 1; + Assert.equal(x, 1); + super(); + this.bool = false; + } + getBool(): boolean { + return this.bool; + } +} +let d = new C2(); +Assert.equal(d.getBool(), false); \ No newline at end of file diff --git a/es2panda/test/ts_extra_tests/test_ts_cases/4.6/2_control_flow_analysis.ts b/es2panda/test/ts_extra_tests/test_ts_cases/4.6/2_control_flow_analysis.ts new file mode 100644 index 0000000000000000000000000000000000000000..6632cb62013f911d3eebea3b5b0e3569ed9fa9e0 --- /dev/null +++ b/es2panda/test/ts_extra_tests/test_ts_cases/4.6/2_control_flow_analysis.ts @@ -0,0 +1,68 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/**--- + description: TypeScript is able to narrow types based on what’s called a discriminant property. For example, in the following code snippet, TypeScript is able to narrow the type of action based on every time we check against the value of name. + module: ESNext + isCurrent: true +---*/ + + +import { Assert } from '../../suite/assert.js' + +type T = + | { name: "Name"; size: number } + | { name: "Name2"; size: string }; +function fun1(action: T) { + if (action.name === "Name") { + let num = action.size * 2; + return num; + } else if (action.name === "Name2") { + const str = action.size.trim(); + return str; + } +} +let action1: T = { + name: "Name", + size: 1 +} +let action2: T = { + name: "Name2", + size: " 1234 " +} +Assert.equal(2, fun1(action1)); +Assert.equal("1234", fun1(action2)); +type Action2 = + | { name: "Name"; size: number } + | { name: "Name2"; size: string }; +function fun2(action: Action2) { + const { name, size } = action; + if (name === "Name") { + let num = size * 2; + return num; + } else if (name === "Name2") { + const str = size.trim(); + return str; + } +} +let action3: T = { + name: "Name", + size: 2 +} +let action4: T = { + name: "Name2", + size: " 5678 " +} +Assert.equal(fun2(action3), 4); +Assert.equal(fun2(action4), "5678"); \ No newline at end of file diff --git a/es2panda/test/ts_extra_tests/test_ts_cases/4.6/3_improved_recursion_depth_checks.ts b/es2panda/test/ts_extra_tests/test_ts_cases/4.6/3_improved_recursion_depth_checks.ts new file mode 100644 index 0000000000000000000000000000000000000000..cd07f1243464e40904da14edfcb9ce1bea34cb18 --- /dev/null +++ b/es2panda/test/ts_extra_tests/test_ts_cases/4.6/3_improved_recursion_depth_checks.ts @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/**--- + description: Improved Recursion Depth Checks + module: ESNext + isCurrent: true +---*/ + + +import { Assert } from '../../suite/assert.js' + +interface I3 { + prop: T; +} +let x: I3>>>>>; +let y: I3>>>>; +y = { prop: { prop: { prop: { prop: { prop: "prop" } } } } } +x = { prop: y }; +Assert.notEqual(JSON.stringify(x), JSON.stringify(y)); \ No newline at end of file diff --git a/es2panda/test/ts_extra_tests/test_ts_cases/4.6/4_indexed_access_inference_improvements.ts b/es2panda/test/ts_extra_tests/test_ts_cases/4.6/4_indexed_access_inference_improvements.ts new file mode 100644 index 0000000000000000000000000000000000000000..80cc93cdaa2f2177416d2485e80ac47cec410140 --- /dev/null +++ b/es2panda/test/ts_extra_tests/test_ts_cases/4.6/4_indexed_access_inference_improvements.ts @@ -0,0 +1,67 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/**--- + description: TypeScript now can correctly infer to indexed access types which immediately index into a mapped object type. + module: ESNext + isCurrent: true +---*/ + + +import { Assert } from '../../suite/assert.js' + +interface I { + a: number; + b: string; + c: boolean; + d: object; +} +type T

= { + [K in P]: { + nameI: K; + v: I[K]; + f: (p: I[K]) => void; + }; +}[P]; +function fun(x: T) { + x.f(x.v); +} +fun({ + nameI: "a", + v: 11, + f: (x) => { + Assert.isNumber(x); + }, +}); +fun({ + nameI: "b", + v: "b", + f: (x) => { + Assert.isString(x); + }, +}); +fun({ + nameI: "c", + v: true, + f: (x) => { + Assert.isBoolean(x); + }, +}); +fun({ + nameI: "d", + v: {}, + f: (x) => { + Assert.isObject(x); + }, +}); \ No newline at end of file diff --git a/es2panda/test/ts_extra_tests/test_ts_cases/4.6/5_control_flow_analysis_for_dependent_parameters.ts b/es2panda/test/ts_extra_tests/test_ts_cases/4.6/5_control_flow_analysis_for_dependent_parameters.ts new file mode 100644 index 0000000000000000000000000000000000000000..8e83d913471beaeaddec92d1e3a823a15a03d95d --- /dev/null +++ b/es2panda/test/ts_extra_tests/test_ts_cases/4.6/5_control_flow_analysis_for_dependent_parameters.ts @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/**--- + description: A signature can be declared with a rest parameter whose type is a discriminated union of tuples. + module: ESNext + isCurrent: true +---*/ + + +import { Assert } from '../../suite/assert.js' + +type T = (...args: [1, number] | [true, string] | ["a", boolean]) => void; +const fun: T = (x: true | 1 | "a", y: string | number | boolean) => { + if (x === 1) { + Assert.equal(10, y); + } + if (x === true) { + Assert.equal("hello", y); + } + if (x === "a") { + Assert.isBoolean(y); + } + +}; +fun(1, 10); +fun(true, "hello"); +fun("a", true); \ No newline at end of file diff --git a/es2panda/test/ts_extra_tests/test_ts_cases/4.7/control-flow_analysis_for_bracketed_element_access/control-flow_analysis_for_bracketed_element_access.ts b/es2panda/test/ts_extra_tests/test_ts_cases/4.7/control-flow_analysis_for_bracketed_element_access/control-flow_analysis_for_bracketed_element_access.ts new file mode 100644 index 0000000000000000000000000000000000000000..c3295e44ae8e4f1451037a6cc8fce4f05c844181 --- /dev/null +++ b/es2panda/test/ts_extra_tests/test_ts_cases/4.7/control-flow_analysis_for_bracketed_element_access/control-flow_analysis_for_bracketed_element_access.ts @@ -0,0 +1,53 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/**--- + description: > + TypeScript 4.7 now narrows the types of element accesses when the indexed key is unique symbols. + module: ESNext + isCurrent: true + ---*/ + + +import { Assert } from "../../../suite/assert.js" + +let sym = Symbol(); +let func = function () { + return 5; +}; +let o = { + obj: "obejct" +}; + +let x = Math.random(); +let y = Math.random(); +const fo = x > y ? func() : o; + +const key = { + [sym]: fo +}; + +if (typeof key[sym] === "object") { + o.obj = 'Object'; +} else { + func = function () { + return 10; + } +} + +if (x < y) { + Assert.equal(o.obj, 'Object'); +} else { + Assert.equal(JSON.stringify(func), undefined); +}; \ No newline at end of file diff --git a/es2panda/test/ts_extra_tests/test_ts_cases/4.7/control-flow_analysis_for_bracketed_element_access/control-flow_analysis_for_bracketed_element_access_1.ts b/es2panda/test/ts_extra_tests/test_ts_cases/4.7/control-flow_analysis_for_bracketed_element_access/control-flow_analysis_for_bracketed_element_access_1.ts new file mode 100644 index 0000000000000000000000000000000000000000..c401307150620d62026ad279a207c9831e1cf43e --- /dev/null +++ b/es2panda/test/ts_extra_tests/test_ts_cases/4.7/control-flow_analysis_for_bracketed_element_access/control-flow_analysis_for_bracketed_element_access_1.ts @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/**--- + description: > + TypeScript 4.7 now narrows the types of element accesses when the indexed key is literal types. + module: ESNext + isCurrent: true + ---*/ + + +import { Assert } from "../../../suite/assert.js" + +type myType = "a" | 3 | "b"; +if (Math.random() > 0.8) { + var arg1: myType = "a"; +} else if (Math.random() < 0.3) { + var arg1: myType = "b"; +} else { + var arg1: myType = 3; +} + +const arg2 = Math.random() > 0.5 ? 15 : 'rand'; + +const o = { + [arg1]: arg2 +} +if (typeof o[arg1] === 'string') { + Assert.equal(arg2, 'rand'); +} else { + Assert.equal(arg2, 15); +}; diff --git a/es2panda/test/ts_extra_tests/test_ts_cases/4.7/extends_constraints_on_infer_type_variables/extends_constraints_on_infer_type_variables.ts b/es2panda/test/ts_extra_tests/test_ts_cases/4.7/extends_constraints_on_infer_type_variables/extends_constraints_on_infer_type_variables.ts new file mode 100644 index 0000000000000000000000000000000000000000..3d2071969e917614488a50d149b4a0d2238e2224 --- /dev/null +++ b/es2panda/test/ts_extra_tests/test_ts_cases/4.7/extends_constraints_on_infer_type_variables/extends_constraints_on_infer_type_variables.ts @@ -0,0 +1,48 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/**--- + description: > + Conditional types are a bit of a power-user feature. + They allow us to match and infer against the shape of types, and make decisions based on them. + TypeScript 4.7 now allows to place a constraint on any infer type. + module: ESNext + isCurrent: true + ---*/ + + +import { Assert } from "../../../suite/assert.js" + +type myType1 = T extends (...arg: infer R) => number ? R : boolean; + +const Add = (a: number, b: number) => a + b; +type add = typeof Add; +type t1 = myType1; +const arr: t1 = [1, 2]; +Assert.isObject(arr); + +type fs = Function | string; +type myType2 = T extends [infer S extends fs, ...any[]] ? S : boolean; + +const Min = (a: number, b: number)=>{ + if (a > b) { + return b; + } else { + return a; + } +} +type min = typeof Min; +type t2 = myType2<[min, number, string]>; +const func: t2 = Min; +Assert.isFunction(func); \ No newline at end of file diff --git a/es2panda/test/ts_extra_tests/test_ts_cases/4.7/improved_function_inference_in_objects_and_methods/improved_function_inference_in_objects_and_methods.ts b/es2panda/test/ts_extra_tests/test_ts_cases/4.7/improved_function_inference_in_objects_and_methods/improved_function_inference_in_objects_and_methods.ts new file mode 100644 index 0000000000000000000000000000000000000000..3669f0076b8d8dd29f5f76479afabad4fb19a594 --- /dev/null +++ b/es2panda/test/ts_extra_tests/test_ts_cases/4.7/improved_function_inference_in_objects_and_methods/improved_function_inference_in_objects_and_methods.ts @@ -0,0 +1,95 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/**--- + description: > + TypeScript 4.7 can now perform more granular inferences from functions within objects and arrays. + This allows the types of these functions to consistently flow in a left-to-right manner just like for plain arguments. + module: ESNext + isCurrent: true + ---*/ + + +import { Assert } from "../../../suite/assert.js" + +function func1(arg: T): T{ + return arg; +} +var f1 = func1(5); +Assert.isNumber(f1); +var f2 = func1('a'); +Assert.isString(f2); +var f3 = func1(true); +Assert.isBoolean(f3); +var f4 = func1({ num: 5 }); +Assert.isObject(f4); +var f5 = func1(() => { return; }); +Assert.isFunction(f5); + +function func2(arg: { member: (str: string) => T }) { + return arg; +} +var f6 = func2({ member: str => { return str; } }); +var result = f6.member('a'); +Assert.isString(result); + +function f(arg: { + arg1: (n: string) => T; + arg2: (x: T) => void; +}) { + arg.arg2 = function (x:T) { + Assert.equal(typeof x, "String"); + } + arg.arg2; +} +f({ + arg1: ():string => "string", + arg2: (x:string) => x.toLowerCase(), +}); +f({ + arg1: n => n, + arg2: (x:string) => x.toLowerCase(), +}); + + +class C{ + arg: { + mem: (str: string) => T; + t: T; + } + constructor(arg: { + mem: (str: string) => T; + t: T; + }) { + this.arg = arg; + this.arg.t = arg.t; + } +} +var c1 = new C({ + mem: function () { return 'a' }, + t: 't' +}) +Assert.isString(c1.arg.t); +var c2 = new C({ + mem() { return 'a' }, + t: 't' +}) +Assert.isString(c2.arg.t); +var c3 = new C({ + mem: str => str, + t: 't' +}) +Assert.isString(c3.arg.t); + + diff --git a/es2panda/test/ts_extra_tests/test_ts_cases/4.7/instantiation_expressions/instantiation_expressions.ts b/es2panda/test/ts_extra_tests/test_ts_cases/4.7/instantiation_expressions/instantiation_expressions.ts new file mode 100644 index 0000000000000000000000000000000000000000..0d230b89cbfe0a61e980c3e18b02f5a1aa86601f --- /dev/null +++ b/es2panda/test/ts_extra_tests/test_ts_cases/4.7/instantiation_expressions/instantiation_expressions.ts @@ -0,0 +1,73 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/**--- + description: > + TypeScript 4.7 allows exactly that we can now take functions and constructors and feed them type arguments directly. + module: ESNext + isCurrent: true + ---*/ + + +import { Assert } from "../../../suite/assert.js" + +const Data:any = Map; + +const data = new Data(); + +data.set("name",new Error("TS error")) + +Assert.equal(data.get("name").name, 'Error'); + + +interface I1 { + name: string; +} +interface I2 { + use: string; +} +function fc(value: T) { + return value; +} +let obj1 = fc({ name: 'xiao' }); +let obj2 = fc({ use: 'play' }); +Assert.equal(JSON.stringify(obj1), '{"name":"xiao"}'); +Assert.equal(JSON.stringify(obj2), '{"use":"play"}'); + +type myType1 = number | string; +type myType2 = { str: string } | (() => number); +function func(arg: T) { + return arg; +} + +var f1 = func(5); +Assert.isNumber(f1); +var f2 = func('a'); +Assert.isString(f2); +var f3 = func({str: 'str'}); +Assert.isObject(f3); +var f4 = func(() => { + return 10; +}); +Assert.isFunction(f4); + +let map = Map; +let map_instantiation = new map(); +map_instantiation.set('num', 8); +Assert.isNumber(map_instantiation.get('num')); + +let set = new Set([2]); +for (let arg of set) { + Assert.isNumber(arg); +}; diff --git a/es2panda/test/ts_extra_tests/test_ts_cases/4.7/optional_variance_annotations_for_type_parameters/optional_variance_annotations_for_type_parameters.ts b/es2panda/test/ts_extra_tests/test_ts_cases/4.7/optional_variance_annotations_for_type_parameters/optional_variance_annotations_for_type_parameters.ts new file mode 100644 index 0000000000000000000000000000000000000000..1efefdf64d875b6f8aed4b3a21527dc29aa395fb --- /dev/null +++ b/es2panda/test/ts_extra_tests/test_ts_cases/4.7/optional_variance_annotations_for_type_parameters/optional_variance_annotations_for_type_parameters.ts @@ -0,0 +1,52 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/**--- + description: > + With TypeScript 4.7, we're now able to explicitly specify variance on type parameters. + module: ESNext + isCurrent: true + ---*/ + + +import { Assert } from "../../../suite/assert.js" + +interface P{ + num: number; +} +interface C extends P{ + str: string; +} + +type myType1 = Array

; +type myType2 = Array; + +var m_ins1: myType1 = [{ num: 5 }]; +var m_ins2: myType2 = [{ num: 10, str: 'a' }]; + +m_ins1 = m_ins2; +Assert.equal(m_ins1, m_ins2); + + +interface h_C{ + name: string; + age: number; +} + +type myType3 = () => T; +type myType4 = () => T; +var m_ins3: myType3 = () => { return { name: 'xiao', age: 18 } }; +var m_ins4: myType4 = () => { return { name: 'xi', age: 18, height: 18 } }; +m_ins3 = m_ins4; +Assert.equal(m_ins3, m_ins4); \ No newline at end of file diff --git a/es2panda/test/ts_extra_tests/test_ts_cases/4.7/readonly_tuples_have_a_readonly_length_property/readonly_tuples_have_a_readonly_length_property.ts b/es2panda/test/ts_extra_tests/test_ts_cases/4.7/readonly_tuples_have_a_readonly_length_property/readonly_tuples_have_a_readonly_length_property.ts new file mode 100644 index 0000000000000000000000000000000000000000..a3c17f788b11adba96a2736df48d824ed94d2548 --- /dev/null +++ b/es2panda/test/ts_extra_tests/test_ts_cases/4.7/readonly_tuples_have_a_readonly_length_property/readonly_tuples_have_a_readonly_length_property.ts @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/**--- + description: > + A readonly tuple will now treat its length property as readonly. + module: ESNext + isCurrent: true + ---*/ + + +import { Assert } from '../../../suite/assert.js' + +class C{ + readonly arr: [number, string, boolean]; + constructor(arr: [number, string, boolean]) { + this.arr = arr; + } +} +let c = new C([10, 'a', true]); +Assert.equal(c.arr.length, 3); \ No newline at end of file diff --git a/es2panda/test/ts_extra_tests/test_ts_cases/4.8/Improved_Intersection_Reduction_Union_Compatibility,_and_Narrowing/Improved_Intersection_Reduction_Union_Compatibility,_and_Narrowing.ts b/es2panda/test/ts_extra_tests/test_ts_cases/4.8/Improved_Intersection_Reduction_Union_Compatibility,_and_Narrowing/Improved_Intersection_Reduction_Union_Compatibility,_and_Narrowing.ts new file mode 100644 index 0000000000000000000000000000000000000000..627516216b984f81141a977233e87325dee0b059 --- /dev/null +++ b/es2panda/test/ts_extra_tests/test_ts_cases/4.8/Improved_Intersection_Reduction_Union_Compatibility,_and_Narrowing/Improved_Intersection_Reduction_Union_Compatibility,_and_Narrowing.ts @@ -0,0 +1,68 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/**--- + description: > + consistency improvements under --strictNullChecks. + These changes affect how intersection and union types work, and are leveraged in how TypeScript narrows types. + Another change is that {} intersected with any other object type simplifies right down to that object type. + module: ESNext + isCurrent: true + strictNullChecks: false + ---*/ + + +import { Assert } from '../../../suite/assert.js' + +type T1 = {} & string; +let a: T1 = "sss"; +Assert.equal(a, "sss"); + +type T2 = {} & unknown; +let b: T2 = 2; +Assert.equal(b,2) + +let x: unknown = 1; +function f1(x: unknown) { + let y: null | undefined | {}; + y = x; + if (x) { + Assert.equal(y, 1); + } +} +f1(x); + +let z: T1 = "string"; +function f2(x: T, y?: T) { + y = x; + if (x) { + Assert.equal(y, "string"); + } +} +f2(z, undefined); + +let bar: unknown = 555; +function f3(x: unknown, y?: {} | null | undefined) { + y = x; + Assert.equal(y, 555); +} +f3(bar, null); + +function ensureNotNull(x: T) { + if (x != null){ + Assert.isNumber(x); + } +} +let run: unknown = 111; +ensureNotNull(run); diff --git a/es2panda/test/ts_extra_tests/test_ts_cases/4.8/improved_inference_for_infer_types_in_template_string_types/improved_inference_for_infer_types_in_template_string_types.ts b/es2panda/test/ts_extra_tests/test_ts_cases/4.8/improved_inference_for_infer_types_in_template_string_types/improved_inference_for_infer_types_in_template_string_types.ts new file mode 100644 index 0000000000000000000000000000000000000000..f47743cc54d95a5cc594a5b0007571e0c7d8bff2 --- /dev/null +++ b/es2panda/test/ts_extra_tests/test_ts_cases/4.8/improved_inference_for_infer_types_in_template_string_types/improved_inference_for_infer_types_in_template_string_types.ts @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/**--- + description: > + typescript recently introduced a way to add extends constraints to infer type variables in conditional types. + if these infer types appear in a template string type and are constrained to a primitive type, TypeScript will now try to parse out a literal type. + this can now better convey what a library will do at runtime, and give more precise types. + module: ESNext + isCurrent: true + ---*/ + + +import { Assert } from '../../../suite/assert.js' + +type myType = T extends [infer U extends V, ...unknown[]] ? U : false; +function func(arr: any[], x: myType<[T, ...any], V>) { + arr[0] = x; + return arr; +} +let arr = ["A", "B", "C"]; +let first = func(arr, 65); +Assert.equal(JSON.stringify(first), "[65,\"B\",\"C\"]"); + +type S = "string" extends `${infer T extends string}` ? T : false; +let s: S = "string"; +Assert.equal(s, "string"); \ No newline at end of file diff --git a/es2panda/test/ts_extra_tests/test_ts_cases/4.9/auto_accessors_in_classes/auto_accessors_in_classes.ts b/es2panda/test/ts_extra_tests/test_ts_cases/4.9/auto_accessors_in_classes/auto_accessors_in_classes.ts new file mode 100644 index 0000000000000000000000000000000000000000..48ab4e76df7b14fb84a21a6c06ac35ff9b186b10 --- /dev/null +++ b/es2panda/test/ts_extra_tests/test_ts_cases/4.9/auto_accessors_in_classes/auto_accessors_in_classes.ts @@ -0,0 +1,51 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/**--- + description: > + TypeScript 4.9 supports an upcoming feature in ECMAScript called auto-accessors. + options: + target: es2015 + module: ESNext + isCurrent: true + ---*/ + + +import { Assert } from "../../../suite/assert.js" + +class NormalClass { + #str: string; + constructor(str: string) { + this.#str = str; + } + get Str(): string { + return this.#str; + } + set Str(str: string) { + this.#str = str; + } +} +class AutoClass { + str: string; + constructor(str: string) { + this.str = str; + } +} + +let c1 = new NormalClass("0"); +let c2 = new AutoClass("0"); +c1.Str = "NormalClass"; +Assert.equal(c1.Str, "NormalClass"); +c2.str = "AutoClass"; +Assert.equal(c2.str, "AutoClass"); diff --git a/es2panda/test/ts_extra_tests/test_ts_cases/4.9/checks_for_equality_on_NaN/checks_for_equality_on_NaN.ts b/es2panda/test/ts_extra_tests/test_ts_cases/4.9/checks_for_equality_on_NaN/checks_for_equality_on_NaN.ts new file mode 100644 index 0000000000000000000000000000000000000000..1793962aa0cb3f009d56d0b45cd10983ed78eec8 --- /dev/null +++ b/es2panda/test/ts_extra_tests/test_ts_cases/4.9/checks_for_equality_on_NaN/checks_for_equality_on_NaN.ts @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/**--- + description: > + typescript now errors on direct comparisons against NaN, and will suggest using some variation of Number.isNaN instead. + options: + lib: es2015 + module: ESNext + isCurrent: true + ---*/ + + +import { Assert } from '../../../suite/assert.js' + +function notNaN(x: number) { + return !Number.isNaN(x); +} +Assert.isFalse(notNaN(NaN)); +Assert.isTrue(notNaN(0)); diff --git a/es2panda/test/ts_extra_tests/test_ts_cases/4.9/the_satisfies_operator/the_satisfies_operator.ts b/es2panda/test/ts_extra_tests/test_ts_cases/4.9/the_satisfies_operator/the_satisfies_operator.ts new file mode 100644 index 0000000000000000000000000000000000000000..84846a9a5a77733fcf7e0b07ce422613776e3c0e --- /dev/null +++ b/es2panda/test/ts_extra_tests/test_ts_cases/4.9/the_satisfies_operator/the_satisfies_operator.ts @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/**--- + description: > + the new satisfies operator lets us validate that the type of an expression matches some type, without changing the resulting type of that expression. + module: es2020 + isCurrent: true + ---*/ + + +import { Assert } from '../../../suite/assert.js' + +const day = { + Mon: 'monday', + Wedn: "wednesday", + Fri: 'friday' +}; + +const hobby = { + "Mon": false, + "Wedn": false, + "Fri": true +}; + +const long = day.Mon.length; +const w = day.Wedn.toUpperCase(); +const g = hobby.Wedn; + +Assert.equal(long, 6); +Assert.equal(w, "WEDNESDAY"); +Assert.isFalse(g); diff --git a/es2panda/test/ts_extra_tests/test_ts_cases/4.9/unlisted_property_narrowing_with_the_in_operator/unlisted_property_narrowing_with_the_in_operator.ts b/es2panda/test/ts_extra_tests/test_ts_cases/4.9/unlisted_property_narrowing_with_the_in_operator/unlisted_property_narrowing_with_the_in_operator.ts new file mode 100644 index 0000000000000000000000000000000000000000..6aaac94c01e7ecc2b40192a93b3c1f6f887434e6 --- /dev/null +++ b/es2panda/test/ts_extra_tests/test_ts_cases/4.9/unlisted_property_narrowing_with_the_in_operator/unlisted_property_narrowing_with_the_in_operator.ts @@ -0,0 +1,58 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/**--- + description: > + typescript 4.9 makes the in operator a little bit more powerful when narrowing types that don’t list the property at all. + module: ESNext + isCurrent: true + ---*/ + + +import { Assert } from '../../../suite/assert.js' + +type T1 = { num: number }; +type T2 = { str: string }; +function func(arg: T1 | T2) { + if ("num" in arg && "str" in arg) { + return "T1 | T2"; + } else if ("num" in arg) { + return "T1"; + } else if ("str" in arg) { + return "T2"; + } +} +let x: T1 = { num: 10 }; +let y: T2 = { str: 'a' }; +let z: T1 | T2 = { num: 10, str: 'a' }; +Assert.equal(func(x), "T1"); +Assert.equal(func(y), "T2"); +Assert.equal(func(z), "T1 | T2"); + +interface I{ + mem: any; +} +function check(arg: I) { + let mem = arg.mem; + if (mem && typeof mem === "object") { + if ("num" in mem && typeof mem.num === 'number') { + return mem.num; + } + } + return null; +} +let a: I = { mem: 10 }; +let b: I = { mem: { num: 10 } }; +Assert.isTrue(check(a) === null); +Assert.isNumber(check(b)); \ No newline at end of file diff --git a/es2panda/test/ts_extra_tests/test_ts_cases/spec/basic_concepts/declarations/declarations_1.ts b/es2panda/test/ts_extra_tests/test_ts_cases/spec/basic_concepts/declarations/declarations_1.ts new file mode 100644 index 0000000000000000000000000000000000000000..bc0c2bd827107d73aae57806612bfcc92f213f0f --- /dev/null +++ b/es2panda/test/ts_extra_tests/test_ts_cases/spec/basic_concepts/declarations/declarations_1.ts @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/**--- + description: > + A name that denotes a value has an associated type and can be referenced in expressions. + A name that denotes a type can be used by itself in a type reference or on the right hand side of a dot in a type reference. + A name that denotes a namespace can be used on the left hand side of a dot in a type reference. + module: ESNext + isCurrent: true + ---*/ + + +import { Assert } from '../../../../suite/assert.js' + +let Rog: string = "a is string"; +Assert.equal("a is string1", Rog + "1"); +type Rog = String; +let newOne: Rog = "xx"; +Assert.equal("xx", newOne); +namespace Rog { + export type b = string; +} +let yoo: Rog.b = "ystr"; +Assert.equal("ystr", yoo); \ No newline at end of file diff --git a/es2panda/test/ts_extra_tests/test_ts_cases/spec/basic_concepts/declarations/declarations_2.ts b/es2panda/test/ts_extra_tests/test_ts_cases/spec/basic_concepts/declarations/declarations_2.ts new file mode 100644 index 0000000000000000000000000000000000000000..b67f8f3601198d5a6467fdb3224799785bdc6d54 --- /dev/null +++ b/es2panda/test/ts_extra_tests/test_ts_cases/spec/basic_concepts/declarations/declarations_2.ts @@ -0,0 +1,56 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/**--- + description: > + Declarations introduce the following meanings for the name they declare: + A variable, parameter, function, generator, member variable, member function, member accessor, or enum member declaration introduces a value meaning. + An interface, type alias, or type parameter declaration introduces a type meaning. + A class declaration introduces a value meaning (the constructor function) and a type meaning (the class type). + An enum declaration introduces a value meaning (the enum instance) and a type meaning (the enum type). + A namespace declaration introduces a namespace meaning (the type and namespace container) and, if the namespace is instantiated, a value meaning (the namespace instance). + An import or export declaration introduces the meaning(s) of the imported or exported entity. + module: ESNext + isCurrent: true + ---*/ + + +import { Assert } from '../../../../suite/assert.js' + +class Myclass { + a: string; + constructor(a: string) { + this.a = a; + } + static a :number = 33; +} +var c: Myclass = new Myclass("x"); +Assert.equal(c.a, "x"); +Assert.equal(Myclass.a,33); +enum WeekDay { + MON = 1, + TUE, + WEN, + THU, + FRI, + SAT, + SUN +} +type a = WeekDay; +var mon: a = WeekDay.MON; +Assert.equal(mon, 1); +namespace X { + export let x: string = "x"; +} +Assert.equal(X.x, "x"); \ No newline at end of file diff --git a/es2panda/test/ts_extra_tests/test_ts_cases/spec/basic_concepts/names/computed_property_names/computed_property_names_1.ts b/es2panda/test/ts_extra_tests/test_ts_cases/spec/basic_concepts/names/computed_property_names/computed_property_names_1.ts new file mode 100644 index 0000000000000000000000000000000000000000..48d8ce5ddec031e9c0ac440035bd4c7f705fb46a --- /dev/null +++ b/es2panda/test/ts_extra_tests/test_ts_cases/spec/basic_concepts/names/computed_property_names/computed_property_names_1.ts @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/**--- + description: > + ECMAScript 2015 permits object literals and classes to declare members with computed property names. + A computed property name specifies an expression that computes the actual property name at run-time. + options: + lib: es6 + module: ESNext + isCurrent: true + ---*/ + + +import { Assert } from '../../../../../suite/assert.js' + +class ComputedName { + aa: 1 | undefined; + ["address"]: string; + constructor(x: string, y: 1) { + this.address = x; + if (y === 1) { + this.aa = y; + } else { + this.aa = undefined; + } + } +} +var c: ComputedName = new ComputedName("address No1", 1); +Assert.equal(1, c.aa); +Assert.equal("address No1", c.address); +var objectliteral = { ["xx" + "123".length]: 22, name: "string" }; +Assert.equal(22, objectliteral.xx3); \ No newline at end of file diff --git a/es2panda/test/ts_extra_tests/test_ts_cases/spec/basic_concepts/names/computed_property_names/computed_property_names_2.ts b/es2panda/test/ts_extra_tests/test_ts_cases/spec/basic_concepts/names/computed_property_names/computed_property_names_2.ts new file mode 100644 index 0000000000000000000000000000000000000000..44fc8ca4a0ad8b8a73707fb41f8aa445060bb7a5 --- /dev/null +++ b/es2panda/test/ts_extra_tests/test_ts_cases/spec/basic_concepts/names/computed_property_names/computed_property_names_2.ts @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/**--- + description: > + In a well-known symbol, the identifier to the right of the dot must denote a property of the primitive type symbol in the type of the global variable 'Symbol', or otherwise an error occurs. + options: + lib: es6 + module: ESNext + isCurrent: true + ---*/ + + +import { Assert } from '../../../../../suite/assert.js' + +type SymI = { + [Symbol.match]?: boolean; +} +let a: SymI = {}; +a[Symbol.match] = true; + +Assert.isTrue(a[Symbol.match]); diff --git a/es2panda/test/ts_extra_tests/test_ts_cases/spec/basic_concepts/names/property_names/property_names_1.ts b/es2panda/test/ts_extra_tests/test_ts_cases/spec/basic_concepts/names/property_names/property_names_1.ts new file mode 100644 index 0000000000000000000000000000000000000000..a4eb9cc08106e40a932dad0f1e3a6204b8719172 --- /dev/null +++ b/es2panda/test/ts_extra_tests/test_ts_cases/spec/basic_concepts/names/property_names/property_names_1.ts @@ -0,0 +1,59 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/**--- + description: > + A property name can be any identifier (including a reserved word), a string literal, a numeric literal, + or a computed property name. String literals may be used to give properties names that are not valid identifiers, + such as names containing blanks. Numeric literal property names are equivalent to string literal property names + with the string representation of the numeric literal, as defined in the ECMAScript specification. + module: ESNext + isCurrent: true + ---*/ + + +import { Assert } from '../../../../../suite/assert.js' + +class Property { + [key: string]: number | string | boolean; + [Symbol.match]: symbol = Symbol.match; + break: string; + let: string; + any: string; + as: string; + "with blank": number; + 1: boolean; + constructor() { + this.break = "break"; + this["with blank"] = 12; + this[1] = true; + this.any = "any"; + this.let = "let"; + this.as = "as"; + } +} +var p: Property = new Property(); +p['NARC'] = "NARC"; +p['0x10'] = 0x10; +p['F'] = false; +Assert.equal("break", p.break); +Assert.equal(12, p["with blank"]); +Assert.equal(true, p[1]); +Assert.equal("any", p.any); +Assert.equal("let", p.let); +Assert.equal("as", p.as); +Assert.equal(p['NARC'], 'NARC'); +Assert.equal(p['0x10'], 0x10); +Assert.equal(p['F'], false); +Assert.equal(p[Symbol.match], Symbol.match); \ No newline at end of file diff --git a/es2panda/test/ts_extra_tests/test_ts_cases/spec/basic_concepts/names/reserved_words/cannot_be_type_name/any_cannot_be_type_name_1.ts b/es2panda/test/ts_extra_tests/test_ts_cases/spec/basic_concepts/names/reserved_words/cannot_be_type_name/any_cannot_be_type_name_1.ts new file mode 100644 index 0000000000000000000000000000000000000000..6661d96beb64bc824af6b91d50a5faea97c8c9a0 --- /dev/null +++ b/es2panda/test/ts_extra_tests/test_ts_cases/spec/basic_concepts/names/reserved_words/cannot_be_type_name/any_cannot_be_type_name_1.ts @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/**--- + description: any cannot be type name, but are otherwise not restricted. + module: ESNext + isCurrent: true + ---*/ + + +import { Assert } from '../../../../../../suite/assert.js' + +function any(): string { + return "any"; +}; +Assert.isFunction(any); +Assert.equal(any(), "any"); \ No newline at end of file diff --git a/es2panda/test/ts_extra_tests/test_ts_cases/spec/basic_concepts/names/reserved_words/cannot_be_type_name/any_cannot_be_type_name_2.ts b/es2panda/test/ts_extra_tests/test_ts_cases/spec/basic_concepts/names/reserved_words/cannot_be_type_name/any_cannot_be_type_name_2.ts new file mode 100644 index 0000000000000000000000000000000000000000..0af022ed9d9e697466b6daff57a35fe1c5293172 --- /dev/null +++ b/es2panda/test/ts_extra_tests/test_ts_cases/spec/basic_concepts/names/reserved_words/cannot_be_type_name/any_cannot_be_type_name_2.ts @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/**--- + description: any cannot be type name, but are otherwise not restricted. + module: ESNext + isCurrent: true + ---*/ + + +import { Assert } from '../../../../../../suite/assert.js' + +var any: string = "any"; +Assert.equal(any, "any"); \ No newline at end of file diff --git a/es2panda/test/ts_extra_tests/test_ts_cases/spec/basic_concepts/names/reserved_words/cannot_be_type_name/boolean_cannot_be_type_name_1.ts b/es2panda/test/ts_extra_tests/test_ts_cases/spec/basic_concepts/names/reserved_words/cannot_be_type_name/boolean_cannot_be_type_name_1.ts new file mode 100644 index 0000000000000000000000000000000000000000..ff57ecbf01abb46266efe4fb89ee3e896f7ada71 --- /dev/null +++ b/es2panda/test/ts_extra_tests/test_ts_cases/spec/basic_concepts/names/reserved_words/cannot_be_type_name/boolean_cannot_be_type_name_1.ts @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/**--- + description: boolean cannot be type name, but are otherwise not restricted. + module: ESNext + isCurrent: true + ---*/ + + +import { Assert } from '../../../../../../suite/assert.js' + +function boolean(): number { + return 0; +} +Assert.isFunction(boolean); +Assert.equal(boolean(), 0); \ No newline at end of file diff --git a/es2panda/test/ts_extra_tests/test_ts_cases/spec/basic_concepts/names/reserved_words/cannot_be_type_name/boolean_cannot_be_type_name_2.ts b/es2panda/test/ts_extra_tests/test_ts_cases/spec/basic_concepts/names/reserved_words/cannot_be_type_name/boolean_cannot_be_type_name_2.ts new file mode 100644 index 0000000000000000000000000000000000000000..9743e8b5f393e64bf21cb05b0a2541c50f04882f --- /dev/null +++ b/es2panda/test/ts_extra_tests/test_ts_cases/spec/basic_concepts/names/reserved_words/cannot_be_type_name/boolean_cannot_be_type_name_2.ts @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/**--- + description: boolean cannot be type name, but are otherwise not restricted. + module: ESNext + isCurrent: true + ---*/ + + +import { Assert } from '../../../../../../suite/assert.js' + +var boolean: number = 0; +Assert.equal(boolean, 0); \ No newline at end of file diff --git a/es2panda/test/ts_extra_tests/test_ts_cases/spec/basic_concepts/names/reserved_words/cannot_be_type_name/number_cannot_be_type_name_1.ts b/es2panda/test/ts_extra_tests/test_ts_cases/spec/basic_concepts/names/reserved_words/cannot_be_type_name/number_cannot_be_type_name_1.ts new file mode 100644 index 0000000000000000000000000000000000000000..7dbc611da4f2e1a69885dff7d52ce2f1f35a2cd6 --- /dev/null +++ b/es2panda/test/ts_extra_tests/test_ts_cases/spec/basic_concepts/names/reserved_words/cannot_be_type_name/number_cannot_be_type_name_1.ts @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/**--- + description: number cannot be type name, but are otherwise not restricted. + module: ESNext + isCurrent: true + ---*/ + + +import { Assert } from '../../../../../../suite/assert.js' + +function number(): string { + return "number"; +} +Assert.isFunction(number); +Assert.equal(number(), "number"); \ No newline at end of file diff --git a/es2panda/test/ts_extra_tests/test_ts_cases/spec/basic_concepts/names/reserved_words/cannot_be_type_name/number_cannot_be_type_name_2.ts b/es2panda/test/ts_extra_tests/test_ts_cases/spec/basic_concepts/names/reserved_words/cannot_be_type_name/number_cannot_be_type_name_2.ts new file mode 100644 index 0000000000000000000000000000000000000000..6de94bd7c0431d107e2de305ebbf4b92f0e83a76 --- /dev/null +++ b/es2panda/test/ts_extra_tests/test_ts_cases/spec/basic_concepts/names/reserved_words/cannot_be_type_name/number_cannot_be_type_name_2.ts @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/**--- + description: number cannot be type name, but are otherwise not restricted. + module: ESNext + isCurrent: true + ---*/ + + +import { Assert } from '../../../../../../suite/assert.js' + +var number: string = "number"; +Assert.equal(number, "number"); \ No newline at end of file diff --git a/es2panda/test/ts_extra_tests/test_ts_cases/spec/basic_concepts/names/reserved_words/cannot_be_type_name/string_cannot_be_type_name_1.ts b/es2panda/test/ts_extra_tests/test_ts_cases/spec/basic_concepts/names/reserved_words/cannot_be_type_name/string_cannot_be_type_name_1.ts new file mode 100644 index 0000000000000000000000000000000000000000..d21a11ece2c81340822cd026037944ef91d3523e --- /dev/null +++ b/es2panda/test/ts_extra_tests/test_ts_cases/spec/basic_concepts/names/reserved_words/cannot_be_type_name/string_cannot_be_type_name_1.ts @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/**--- + description: string cannot be type name, but are otherwise not restricted. + module: ESNext + isCurrent: true + ---*/ + + +import { Assert } from '../../../../../../suite/assert.js' + +function string(): number { + return 10; +} +Assert.equal(string(), 10); \ No newline at end of file diff --git a/es2panda/test/ts_extra_tests/test_ts_cases/spec/basic_concepts/names/reserved_words/cannot_be_type_name/string_cannot_be_type_name_2.ts b/es2panda/test/ts_extra_tests/test_ts_cases/spec/basic_concepts/names/reserved_words/cannot_be_type_name/string_cannot_be_type_name_2.ts new file mode 100644 index 0000000000000000000000000000000000000000..f45a26812eeb662cf4b7375c3fe38972421ec0d8 --- /dev/null +++ b/es2panda/test/ts_extra_tests/test_ts_cases/spec/basic_concepts/names/reserved_words/cannot_be_type_name/string_cannot_be_type_name_2.ts @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/**--- + description: string cannot be type name, but are otherwise not restricted. + module: ESNext + isCurrent: true + ---*/ + + +import { Assert } from '../../../../../../suite/assert.js' + +var string: number = 10; +Assert.equal(string, 10); \ No newline at end of file diff --git a/es2panda/test/ts_extra_tests/test_ts_cases/spec/basic_concepts/names/reserved_words/cannot_be_type_name/symbol_cannot_be_type_name_1.ts b/es2panda/test/ts_extra_tests/test_ts_cases/spec/basic_concepts/names/reserved_words/cannot_be_type_name/symbol_cannot_be_type_name_1.ts new file mode 100644 index 0000000000000000000000000000000000000000..c99b03bda842c9e0a8c6ceac5e0314455d976ff4 --- /dev/null +++ b/es2panda/test/ts_extra_tests/test_ts_cases/spec/basic_concepts/names/reserved_words/cannot_be_type_name/symbol_cannot_be_type_name_1.ts @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/**--- + description: symbol cannot be type name, but are otherwise not restricted. + module: ESNext + isCurrent: true + ---*/ + + +import { Assert } from '../../../../../../suite/assert.js' + +function symbol(): string { + return "symbol" +} +Assert.equal(symbol(), "symbol"); \ No newline at end of file diff --git a/es2panda/test/ts_extra_tests/test_ts_cases/spec/basic_concepts/names/reserved_words/cannot_be_type_name/symbol_cannot_be_type_name_2.ts b/es2panda/test/ts_extra_tests/test_ts_cases/spec/basic_concepts/names/reserved_words/cannot_be_type_name/symbol_cannot_be_type_name_2.ts new file mode 100644 index 0000000000000000000000000000000000000000..280713ec745394e7d3dac85496ff3a3c63fd377f --- /dev/null +++ b/es2panda/test/ts_extra_tests/test_ts_cases/spec/basic_concepts/names/reserved_words/cannot_be_type_name/symbol_cannot_be_type_name_2.ts @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/**--- + description: symbol cannot be type name, but are otherwise not restricted. + module: ESNext + isCurrent: true + ---*/ + + +import { Assert } from '../../../../../../suite/assert.js' + +var symbol: string = "any"; +Assert.equal(symbol, "any"); \ No newline at end of file diff --git a/es2panda/test/ts_extra_tests/test_ts_cases/spec/basic_concepts/names/reserved_words/special_mean_but_valid_identifier/abstract_is_valid_identifier_1.ts b/es2panda/test/ts_extra_tests/test_ts_cases/spec/basic_concepts/names/reserved_words/special_mean_but_valid_identifier/abstract_is_valid_identifier_1.ts new file mode 100644 index 0000000000000000000000000000000000000000..f2245aa4c4358dd77219df859e62b6aa9ef2df1b --- /dev/null +++ b/es2panda/test/ts_extra_tests/test_ts_cases/spec/basic_concepts/names/reserved_words/special_mean_but_valid_identifier/abstract_is_valid_identifier_1.ts @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/**--- + description: abstract is valid identifier + module: ESNext + isCurrent: true + ---*/ + + +import { Assert } from '../../../../../../suite/assert.js' + +var abstract: string = "abstract"; +Assert.equal(abstract, "abstract"); \ No newline at end of file diff --git a/es2panda/test/ts_extra_tests/test_ts_cases/spec/basic_concepts/names/reserved_words/special_mean_but_valid_identifier/abstract_is_valid_identifier_2.ts b/es2panda/test/ts_extra_tests/test_ts_cases/spec/basic_concepts/names/reserved_words/special_mean_but_valid_identifier/abstract_is_valid_identifier_2.ts new file mode 100644 index 0000000000000000000000000000000000000000..2b22fef99744c447c332e78ee442dc4c00b38060 --- /dev/null +++ b/es2panda/test/ts_extra_tests/test_ts_cases/spec/basic_concepts/names/reserved_words/special_mean_but_valid_identifier/abstract_is_valid_identifier_2.ts @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/**--- + description: abstract is valid identifier + module: ESNext + isCurrent: true + ---*/ + + +import { Assert } from '../../../../../../suite/assert.js' + +function abstract(): string { + return "abstract"; +} +Assert.equal(abstract(), "abstract"); \ No newline at end of file diff --git a/es2panda/test/ts_extra_tests/test_ts_cases/spec/basic_concepts/names/reserved_words/special_mean_but_valid_identifier/abstract_is_valid_identifier_3.ts b/es2panda/test/ts_extra_tests/test_ts_cases/spec/basic_concepts/names/reserved_words/special_mean_but_valid_identifier/abstract_is_valid_identifier_3.ts new file mode 100644 index 0000000000000000000000000000000000000000..7ce5b7d5801cbadae3e8919031a87d8a702f7933 --- /dev/null +++ b/es2panda/test/ts_extra_tests/test_ts_cases/spec/basic_concepts/names/reserved_words/special_mean_but_valid_identifier/abstract_is_valid_identifier_3.ts @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/**--- + description: abstract is valid identifier + module: ESNext + isCurrent: true + ---*/ + + +import { Assert } from '../../../../../../suite/assert.js' + +class abstract { + name: string; + constructor(name: string) { + this.name = name; + } + getName(): string { + return this.name; + } +} +var newobj = new abstract("abstract"); +Assert.equal(newobj.getName(), "abstract"); \ No newline at end of file diff --git a/es2panda/test/ts_extra_tests/test_ts_cases/spec/basic_concepts/names/reserved_words/special_mean_but_valid_identifier/abstract_is_valid_identifier_4.ts b/es2panda/test/ts_extra_tests/test_ts_cases/spec/basic_concepts/names/reserved_words/special_mean_but_valid_identifier/abstract_is_valid_identifier_4.ts new file mode 100644 index 0000000000000000000000000000000000000000..a06c5abb677b80203b60ebfde255ae5fd70f3559 --- /dev/null +++ b/es2panda/test/ts_extra_tests/test_ts_cases/spec/basic_concepts/names/reserved_words/special_mean_but_valid_identifier/abstract_is_valid_identifier_4.ts @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/**--- + description: abstract is valid identifier + module: ESNext + isCurrent: true + ---*/ + + +import { Assert } from '../../../../../../suite/assert.js' + +interface abstruct { + name: string, + getName: () => string +} +var customer: abstruct = { + name: "abstruct", + getName(): string { + return this.name; + } +} +Assert.equal(customer.name, "abstruct"); \ No newline at end of file diff --git a/es2panda/test/ts_extra_tests/test_ts_cases/spec/basic_concepts/names/reserved_words/special_mean_but_valid_identifier/as_is_valid_identifier_1.ts b/es2panda/test/ts_extra_tests/test_ts_cases/spec/basic_concepts/names/reserved_words/special_mean_but_valid_identifier/as_is_valid_identifier_1.ts new file mode 100644 index 0000000000000000000000000000000000000000..4a0cf23f27084d91efa7ae3c82d3ddb9bcafbf21 --- /dev/null +++ b/es2panda/test/ts_extra_tests/test_ts_cases/spec/basic_concepts/names/reserved_words/special_mean_but_valid_identifier/as_is_valid_identifier_1.ts @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/**--- + description: as is valid identifier + module: ESNext + isCurrent: true + ---*/ + + +import { Assert } from '../../../../../../suite/assert.js' + +var as: string = "as"; +Assert.equal(as, "as"); \ No newline at end of file diff --git a/es2panda/test/ts_extra_tests/test_ts_cases/spec/basic_concepts/names/reserved_words/special_mean_but_valid_identifier/as_is_valid_identifier_2.ts b/es2panda/test/ts_extra_tests/test_ts_cases/spec/basic_concepts/names/reserved_words/special_mean_but_valid_identifier/as_is_valid_identifier_2.ts new file mode 100644 index 0000000000000000000000000000000000000000..ec61e3aa214f6d4d17d1b88a8838f658a85d73d9 --- /dev/null +++ b/es2panda/test/ts_extra_tests/test_ts_cases/spec/basic_concepts/names/reserved_words/special_mean_but_valid_identifier/as_is_valid_identifier_2.ts @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/**--- + description: as is valid identifier + module: ESNext + isCurrent: true + ---*/ + + +import { Assert } from '../../../../../../suite/assert.js' + +function as(): string { + return "as"; +} +Assert.equal(as(), "as"); \ No newline at end of file diff --git a/es2panda/test/ts_extra_tests/test_ts_cases/spec/basic_concepts/names/reserved_words/special_mean_but_valid_identifier/as_is_valid_identifier_3.ts b/es2panda/test/ts_extra_tests/test_ts_cases/spec/basic_concepts/names/reserved_words/special_mean_but_valid_identifier/as_is_valid_identifier_3.ts new file mode 100644 index 0000000000000000000000000000000000000000..b42a1fdd7d812513ac40f13df07244897172e5d1 --- /dev/null +++ b/es2panda/test/ts_extra_tests/test_ts_cases/spec/basic_concepts/names/reserved_words/special_mean_but_valid_identifier/as_is_valid_identifier_3.ts @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/**--- + description: as is valid identifier + module: ESNext + isCurrent: true + ---*/ + + +import { Assert } from '../../../../../../suite/assert.js' + +class as { + name: string; + constructor(name: string) { + this.name = name; + } + getName(): string { + return this.name; + } +} +var newobj = new as("as"); +Assert.equal(newobj.getName(), "as"); \ No newline at end of file diff --git a/es2panda/test/ts_extra_tests/test_ts_cases/spec/basic_concepts/names/reserved_words/special_mean_but_valid_identifier/as_is_valid_identifier_4.ts b/es2panda/test/ts_extra_tests/test_ts_cases/spec/basic_concepts/names/reserved_words/special_mean_but_valid_identifier/as_is_valid_identifier_4.ts new file mode 100644 index 0000000000000000000000000000000000000000..1eb01c1d3b016b8754343cb2ed9a72fdd2794cb0 --- /dev/null +++ b/es2panda/test/ts_extra_tests/test_ts_cases/spec/basic_concepts/names/reserved_words/special_mean_but_valid_identifier/as_is_valid_identifier_4.ts @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/**--- + description: as is valid identifier + module: ESNext + isCurrent: true + ---*/ + + +import { Assert } from '../../../../../../suite/assert.js' + +interface as { + name: string, + getName: () => string +} +var customer: as = { + name: "as", + getName(): string { + return this.name; + } +} +Assert.equal(customer.name, "as"); \ No newline at end of file diff --git a/es2panda/test/ts_extra_tests/test_ts_cases/spec/basic_concepts/names/reserved_words/special_mean_but_valid_identifier/async_is_valid_identifier_1.ts b/es2panda/test/ts_extra_tests/test_ts_cases/spec/basic_concepts/names/reserved_words/special_mean_but_valid_identifier/async_is_valid_identifier_1.ts new file mode 100644 index 0000000000000000000000000000000000000000..04f2a5cae0c2cbed06aca9cdc1ef4cabaaf817d8 --- /dev/null +++ b/es2panda/test/ts_extra_tests/test_ts_cases/spec/basic_concepts/names/reserved_words/special_mean_but_valid_identifier/async_is_valid_identifier_1.ts @@ -0,0 +1,26 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/**--- + description: async is valid identifier + module: ESNext + isCurrent: true + ---*/ + + +import { Assert } from '../../../../../../suite/assert.js' + +var async: string = "async"; +Assert.equal(async, "async"); + diff --git a/es2panda/test/ts_extra_tests/test_ts_cases/spec/basic_concepts/names/reserved_words/special_mean_but_valid_identifier/async_is_valid_identifier_2.ts b/es2panda/test/ts_extra_tests/test_ts_cases/spec/basic_concepts/names/reserved_words/special_mean_but_valid_identifier/async_is_valid_identifier_2.ts new file mode 100644 index 0000000000000000000000000000000000000000..618f40ba83c2c64dd5219b0175a90008fd57a41d --- /dev/null +++ b/es2panda/test/ts_extra_tests/test_ts_cases/spec/basic_concepts/names/reserved_words/special_mean_but_valid_identifier/async_is_valid_identifier_2.ts @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/**--- + description: async is valid identifier + module: ESNext + isCurrent: true + ---*/ + + +import { Assert } from '../../../../../../suite/assert.js' + +function async(): string { + return "async"; +} +Assert.equal(async(), "async"); + diff --git a/es2panda/test/ts_extra_tests/test_ts_cases/spec/basic_concepts/names/reserved_words/special_mean_but_valid_identifier/async_is_valid_identifier_3.ts b/es2panda/test/ts_extra_tests/test_ts_cases/spec/basic_concepts/names/reserved_words/special_mean_but_valid_identifier/async_is_valid_identifier_3.ts new file mode 100644 index 0000000000000000000000000000000000000000..fdb6480948ada47faaaec53554f247e67b59d741 --- /dev/null +++ b/es2panda/test/ts_extra_tests/test_ts_cases/spec/basic_concepts/names/reserved_words/special_mean_but_valid_identifier/async_is_valid_identifier_3.ts @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/**--- + description: async is valid identifier + module: ESNext + isCurrent: true + ---*/ + + +import { Assert } from '../../../../../../suite/assert.js' + +class async { + name: string; + constructor(name: string) { + this.name = name; + } + getName(): string { + return this.name; + } +} +var newobj = new async("async"); +Assert.equal(newobj.getName(), "async"); \ No newline at end of file diff --git a/es2panda/test/ts_extra_tests/test_ts_cases/spec/basic_concepts/names/reserved_words/special_mean_but_valid_identifier/async_is_valid_identifier_4.ts b/es2panda/test/ts_extra_tests/test_ts_cases/spec/basic_concepts/names/reserved_words/special_mean_but_valid_identifier/async_is_valid_identifier_4.ts new file mode 100644 index 0000000000000000000000000000000000000000..6c20af07d1b535f9deeb4c2345786405f1ecddca --- /dev/null +++ b/es2panda/test/ts_extra_tests/test_ts_cases/spec/basic_concepts/names/reserved_words/special_mean_but_valid_identifier/async_is_valid_identifier_4.ts @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/**--- + description: async is valid identifier + module: ESNext + isCurrent: true + ---*/ + + +import { Assert } from '../../../../../../suite/assert.js' + +interface async { + name: string, + getName: () => string +} +var customer: async = { + name: "async", + getName(): string { + return this.name; + } +} +Assert.equal(customer.name, "async"); \ No newline at end of file diff --git a/es2panda/test/ts_extra_tests/test_ts_cases/spec/basic_concepts/names/reserved_words/special_mean_but_valid_identifier/await_is_valid_identifier_1.ts b/es2panda/test/ts_extra_tests/test_ts_cases/spec/basic_concepts/names/reserved_words/special_mean_but_valid_identifier/await_is_valid_identifier_1.ts new file mode 100644 index 0000000000000000000000000000000000000000..1d5b0a3e1ec9c03705c28d57cb68862d578a94ff --- /dev/null +++ b/es2panda/test/ts_extra_tests/test_ts_cases/spec/basic_concepts/names/reserved_words/special_mean_but_valid_identifier/await_is_valid_identifier_1.ts @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/**--- + description: await is valid identifier + module: ESNext + isCurrent: true + ---*/ + + +import { Assert } from '../../../../../../suite/assert.js' + +var await: string = "await"; +Assert.equal(await , "await"); \ No newline at end of file diff --git a/es2panda/test/ts_extra_tests/test_ts_cases/spec/basic_concepts/names/reserved_words/special_mean_but_valid_identifier/await_is_valid_identifier_2.ts b/es2panda/test/ts_extra_tests/test_ts_cases/spec/basic_concepts/names/reserved_words/special_mean_but_valid_identifier/await_is_valid_identifier_2.ts new file mode 100644 index 0000000000000000000000000000000000000000..7f0c7af7d2610eeeba289853f30d01daca2e132b --- /dev/null +++ b/es2panda/test/ts_extra_tests/test_ts_cases/spec/basic_concepts/names/reserved_words/special_mean_but_valid_identifier/await_is_valid_identifier_2.ts @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/**--- + description: await is valid identifier + module: ESNext + isCurrent: true + ---*/ + + +import { Assert } from '../../../../../../suite/assert.js' + +function await(): string { + return "await"; +} +Assert.equal(await(), "await"); \ No newline at end of file diff --git a/es2panda/test/ts_extra_tests/test_ts_cases/spec/basic_concepts/names/reserved_words/special_mean_but_valid_identifier/await_is_valid_identifier_3.ts b/es2panda/test/ts_extra_tests/test_ts_cases/spec/basic_concepts/names/reserved_words/special_mean_but_valid_identifier/await_is_valid_identifier_3.ts new file mode 100644 index 0000000000000000000000000000000000000000..77efa004775c11aef785dcfe3954cc2d7568ff44 --- /dev/null +++ b/es2panda/test/ts_extra_tests/test_ts_cases/spec/basic_concepts/names/reserved_words/special_mean_but_valid_identifier/await_is_valid_identifier_3.ts @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/**--- + description: await is valid identifier + module: ESNext + isCurrent: true + ---*/ + + +import { Assert } from '../../../../../../suite/assert.js' + +class await { + name: string; + constructor(name: string) { + this.name = name; + } + getName(): string { + return this.name; + } +} +var newobj = new await("await"); +Assert.equal(newobj.getName(), "await"); \ No newline at end of file diff --git a/es2panda/test/ts_extra_tests/test_ts_cases/spec/basic_concepts/names/reserved_words/special_mean_but_valid_identifier/await_is_valid_identifier_4.ts b/es2panda/test/ts_extra_tests/test_ts_cases/spec/basic_concepts/names/reserved_words/special_mean_but_valid_identifier/await_is_valid_identifier_4.ts new file mode 100644 index 0000000000000000000000000000000000000000..77f5130dbafbd69f94b4eac6e25198a03b69deb6 --- /dev/null +++ b/es2panda/test/ts_extra_tests/test_ts_cases/spec/basic_concepts/names/reserved_words/special_mean_but_valid_identifier/await_is_valid_identifier_4.ts @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/**--- + description: async is valid identifier + module: ESNext + isCurrent: true + ---*/ + + +import { Assert } from '../../../../../../suite/assert.js' + +interface await { + name: string, + getName: () => string +} +var customer: await = { + name: "await", + getName(): string { + return this.name; + } +} +Assert.equal(customer.name, "await"); \ No newline at end of file diff --git a/es2panda/test/ts_extra_tests/test_ts_cases/spec/basic_concepts/names/reserved_words/special_mean_but_valid_identifier/constructor_is_valid_identifier_1.ts b/es2panda/test/ts_extra_tests/test_ts_cases/spec/basic_concepts/names/reserved_words/special_mean_but_valid_identifier/constructor_is_valid_identifier_1.ts new file mode 100644 index 0000000000000000000000000000000000000000..34de3bf84bb91375c3eebc3c45c55119ec0dec89 --- /dev/null +++ b/es2panda/test/ts_extra_tests/test_ts_cases/spec/basic_concepts/names/reserved_words/special_mean_but_valid_identifier/constructor_is_valid_identifier_1.ts @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/**--- + description: The keywords 'constructor' has special meaning in certain contexts, but is valid identifier. + module: ESNext + isCurrent: true + ---*/ + + +import { Assert } from '../../../../../../suite/assert.js' + +var constructor: string = "constructor"; +Assert.equal(constructor, "constructor"); \ No newline at end of file diff --git a/es2panda/test/ts_extra_tests/test_ts_cases/spec/basic_concepts/names/reserved_words/special_mean_but_valid_identifier/constructor_is_valid_identifier_2.ts b/es2panda/test/ts_extra_tests/test_ts_cases/spec/basic_concepts/names/reserved_words/special_mean_but_valid_identifier/constructor_is_valid_identifier_2.ts new file mode 100644 index 0000000000000000000000000000000000000000..17c7cc39a77b780de014ac917282792b64ce71c2 --- /dev/null +++ b/es2panda/test/ts_extra_tests/test_ts_cases/spec/basic_concepts/names/reserved_words/special_mean_but_valid_identifier/constructor_is_valid_identifier_2.ts @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/**--- + description: The keywords 'constructor' has special meaning in certain contexts, but is valid identifier. + module: ESNext + isCurrent: true + ---*/ + + +import { Assert } from '../../../../../../suite/assert.js' + +function constructor(): string { + return "constructor"; +} +Assert.equal(constructor(), "constructor"); \ No newline at end of file diff --git a/es2panda/test/ts_extra_tests/test_ts_cases/spec/basic_concepts/names/reserved_words/special_mean_but_valid_identifier/constructor_is_valid_identifier_3.ts b/es2panda/test/ts_extra_tests/test_ts_cases/spec/basic_concepts/names/reserved_words/special_mean_but_valid_identifier/constructor_is_valid_identifier_3.ts new file mode 100644 index 0000000000000000000000000000000000000000..711349b149ff8cb8e46b52397ec15a2576421ccf --- /dev/null +++ b/es2panda/test/ts_extra_tests/test_ts_cases/spec/basic_concepts/names/reserved_words/special_mean_but_valid_identifier/constructor_is_valid_identifier_3.ts @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/**--- + description: The keywords 'constructor' has special meaning in certain contexts, but is valid identifier. + module: ESNext + isCurrent: true + ---*/ + + +import { Assert } from '../../../../../../suite/assert.js' + +class constructor { + name: string; + constructor(name: string) { + this.name = name; + } + getName(): string { + return this.name; + } +} +var newobj = new constructor("constructor"); +Assert.equal(newobj.getName(), "constructor"); \ No newline at end of file diff --git a/es2panda/test/ts_extra_tests/test_ts_cases/spec/basic_concepts/names/reserved_words/special_mean_but_valid_identifier/constructor_is_valid_identifier_4.ts b/es2panda/test/ts_extra_tests/test_ts_cases/spec/basic_concepts/names/reserved_words/special_mean_but_valid_identifier/constructor_is_valid_identifier_4.ts new file mode 100644 index 0000000000000000000000000000000000000000..a0e571e0aa3db7f6e49c01073e11f3af416e6efa --- /dev/null +++ b/es2panda/test/ts_extra_tests/test_ts_cases/spec/basic_concepts/names/reserved_words/special_mean_but_valid_identifier/constructor_is_valid_identifier_4.ts @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/**--- + description: The keywords 'constructor' has special meaning in certain contexts, but is valid identifier. + module: ESNext + isCurrent: true + ---*/ + + +import { Assert } from '../../../../../../suite/assert.js' + +interface constructor { + name: string, + getName: () => string +} +var customer: constructor = { + name: "constructor", + getName(): string { + return this.name; + } +} +Assert.equal(customer.name, "constructor"); \ No newline at end of file diff --git a/es2panda/test/ts_extra_tests/test_ts_cases/spec/basic_concepts/names/reserved_words/special_mean_but_valid_identifier/declare_is_valid_identifier_1.ts b/es2panda/test/ts_extra_tests/test_ts_cases/spec/basic_concepts/names/reserved_words/special_mean_but_valid_identifier/declare_is_valid_identifier_1.ts new file mode 100644 index 0000000000000000000000000000000000000000..aac04f3d37005eff94072baad0077bde94a2313a --- /dev/null +++ b/es2panda/test/ts_extra_tests/test_ts_cases/spec/basic_concepts/names/reserved_words/special_mean_but_valid_identifier/declare_is_valid_identifier_1.ts @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/**--- + description: The keywords 'declare' has special meaning in certain contexts, but is valid identifier. + module: ESNext + isCurrent: true + ---*/ + + +import { Assert } from '../../../../../../suite/assert.js' + +var declare: string = "declare"; +Assert.equal(declare, "declare"); \ No newline at end of file diff --git a/es2panda/test/ts_extra_tests/test_ts_cases/spec/basic_concepts/names/reserved_words/special_mean_but_valid_identifier/declare_is_valid_identifier_2.ts b/es2panda/test/ts_extra_tests/test_ts_cases/spec/basic_concepts/names/reserved_words/special_mean_but_valid_identifier/declare_is_valid_identifier_2.ts new file mode 100644 index 0000000000000000000000000000000000000000..bb41f4d113ad6661ba09854771fc0e362fdbdf68 --- /dev/null +++ b/es2panda/test/ts_extra_tests/test_ts_cases/spec/basic_concepts/names/reserved_words/special_mean_but_valid_identifier/declare_is_valid_identifier_2.ts @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/**--- + description: The keywords 'declare' has special meaning in certain contexts, but is valid identifier. + module: ESNext + isCurrent: true + ---*/ + + +import { Assert } from '../../../../../../suite/assert.js' + +function declare(): string { + return "declare"; +} +Assert.equal(declare(), "declare"); \ No newline at end of file diff --git a/es2panda/test/ts_extra_tests/test_ts_cases/spec/basic_concepts/names/reserved_words/special_mean_but_valid_identifier/declare_is_valid_identifier_3.ts b/es2panda/test/ts_extra_tests/test_ts_cases/spec/basic_concepts/names/reserved_words/special_mean_but_valid_identifier/declare_is_valid_identifier_3.ts new file mode 100644 index 0000000000000000000000000000000000000000..b81f44896d742f60c33ec4b52b1ece2a8736be36 --- /dev/null +++ b/es2panda/test/ts_extra_tests/test_ts_cases/spec/basic_concepts/names/reserved_words/special_mean_but_valid_identifier/declare_is_valid_identifier_3.ts @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/**--- + description: The keywords 'declare' has special meaning in certain contexts, but is valid identifier. + module: ESNext + isCurrent: true + ---*/ + + +import { Assert } from '../../../../../../suite/assert.js' + +class declare { + name: string; + constructor(name: string) { + this.name = name; + } + getName(): string { + return this.name; + } +} +var newobj = new declare("declare"); +Assert.equal(newobj.getName(), "declare"); \ No newline at end of file diff --git a/es2panda/test/ts_extra_tests/test_ts_cases/spec/basic_concepts/names/reserved_words/special_mean_but_valid_identifier/declare_is_valid_identifier_4.ts b/es2panda/test/ts_extra_tests/test_ts_cases/spec/basic_concepts/names/reserved_words/special_mean_but_valid_identifier/declare_is_valid_identifier_4.ts new file mode 100644 index 0000000000000000000000000000000000000000..f315768977f23cafbc5a4bc0d7d7a108b541870c --- /dev/null +++ b/es2panda/test/ts_extra_tests/test_ts_cases/spec/basic_concepts/names/reserved_words/special_mean_but_valid_identifier/declare_is_valid_identifier_4.ts @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/**--- + description: The keywords 'declare' has special meaning in certain contexts, but is valid identifier. + module: ESNext + isCurrent: true + ---*/ + + +import { Assert } from '../../../../../../suite/assert.js' + +interface declare { + name: string, + getName: () => string +} +var customer: declare = { + name: "declare", + getName(): string { + return this.name; + } +} +Assert.equal(customer.name, "declare"); \ No newline at end of file diff --git a/es2panda/test/ts_extra_tests/test_ts_cases/spec/basic_concepts/names/reserved_words/special_mean_but_valid_identifier/from_is_valid_identifier_1.ts b/es2panda/test/ts_extra_tests/test_ts_cases/spec/basic_concepts/names/reserved_words/special_mean_but_valid_identifier/from_is_valid_identifier_1.ts new file mode 100644 index 0000000000000000000000000000000000000000..f7c3ea544e2158edc2e68bbca787a2652e74aee5 --- /dev/null +++ b/es2panda/test/ts_extra_tests/test_ts_cases/spec/basic_concepts/names/reserved_words/special_mean_but_valid_identifier/from_is_valid_identifier_1.ts @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/**--- + description: The keywords 'from' has special meaning in certain contexts, but is valid identifier. + module: ESNext + isCurrent: true + ---*/ + + +import { Assert } from '../../../../../../suite/assert.js' + +var from: string = "from"; +Assert.equal(from, "from"); \ No newline at end of file diff --git a/es2panda/test/ts_extra_tests/test_ts_cases/spec/basic_concepts/names/reserved_words/special_mean_but_valid_identifier/from_is_valid_identifier_2.ts b/es2panda/test/ts_extra_tests/test_ts_cases/spec/basic_concepts/names/reserved_words/special_mean_but_valid_identifier/from_is_valid_identifier_2.ts new file mode 100644 index 0000000000000000000000000000000000000000..1900fe5d1b3c7224c0e3443ddade723952bc7f50 --- /dev/null +++ b/es2panda/test/ts_extra_tests/test_ts_cases/spec/basic_concepts/names/reserved_words/special_mean_but_valid_identifier/from_is_valid_identifier_2.ts @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/**--- + description: The keywords 'from' has special meaning in certain contexts, but is valid identifier. + module: ESNext + isCurrent: true + ---*/ + + +import { Assert } from '../../../../../../suite/assert.js' + +function from(): string { + return "from"; +} +Assert.equal(from(), "from"); \ No newline at end of file diff --git a/es2panda/test/ts_extra_tests/test_ts_cases/spec/basic_concepts/names/reserved_words/special_mean_but_valid_identifier/from_is_valid_identifier_3.ts b/es2panda/test/ts_extra_tests/test_ts_cases/spec/basic_concepts/names/reserved_words/special_mean_but_valid_identifier/from_is_valid_identifier_3.ts new file mode 100644 index 0000000000000000000000000000000000000000..c1c86b2b497d19aeee3edcb76a7e6b81a4a12d07 --- /dev/null +++ b/es2panda/test/ts_extra_tests/test_ts_cases/spec/basic_concepts/names/reserved_words/special_mean_but_valid_identifier/from_is_valid_identifier_3.ts @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/**--- + description: The keywords 'from' has special meaning in certain contexts, but is valid identifier. + module: ESNext + isCurrent: true + ---*/ + + +import { Assert } from '../../../../../../suite/assert.js' + +class from { + name: string; + constructor(name: string) { + this.name = name; + } + getName(): string { + return this.name; + } +} +var newobj = new from("from"); +Assert.equal(newobj.getName(), "from"); \ No newline at end of file diff --git a/es2panda/test/ts_extra_tests/test_ts_cases/spec/basic_concepts/names/reserved_words/special_mean_but_valid_identifier/from_is_valid_identifier_4.ts b/es2panda/test/ts_extra_tests/test_ts_cases/spec/basic_concepts/names/reserved_words/special_mean_but_valid_identifier/from_is_valid_identifier_4.ts new file mode 100644 index 0000000000000000000000000000000000000000..9862bfc8e5c95ac6b7822204a2ae8c5c8f932560 --- /dev/null +++ b/es2panda/test/ts_extra_tests/test_ts_cases/spec/basic_concepts/names/reserved_words/special_mean_but_valid_identifier/from_is_valid_identifier_4.ts @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/**--- + description: The keywords 'from' has special meaning in certain contexts, but is valid identifier. + module: ESNext + isCurrent: true + ---*/ + + +import { Assert } from '../../../../../../suite/assert.js' + +interface from { + name: string, + getName: () => string +} +var customer: from = { + name: "from", + getName(): string { + return this.name; + } +} +Assert.equal(customer.name, "from"); \ No newline at end of file diff --git a/es2panda/test/ts_extra_tests/test_ts_cases/spec/basic_concepts/names/reserved_words/special_mean_but_valid_identifier/get_is_valid_identifier_1.ts b/es2panda/test/ts_extra_tests/test_ts_cases/spec/basic_concepts/names/reserved_words/special_mean_but_valid_identifier/get_is_valid_identifier_1.ts new file mode 100644 index 0000000000000000000000000000000000000000..299b54e6cc9159e5cbd7dc8770b117fb9971baef --- /dev/null +++ b/es2panda/test/ts_extra_tests/test_ts_cases/spec/basic_concepts/names/reserved_words/special_mean_but_valid_identifier/get_is_valid_identifier_1.ts @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/**--- + description: The keywords 'get' has special meaning in certain contexts, but is valid identifier. + module: ESNext + isCurrent: true + ---*/ + + +import { Assert } from '../../../../../../suite/assert.js' + +var get: string = "get"; +Assert.equal(get, "get"); \ No newline at end of file diff --git a/es2panda/test/ts_extra_tests/test_ts_cases/spec/basic_concepts/names/reserved_words/special_mean_but_valid_identifier/get_is_valid_identifier_2.ts b/es2panda/test/ts_extra_tests/test_ts_cases/spec/basic_concepts/names/reserved_words/special_mean_but_valid_identifier/get_is_valid_identifier_2.ts new file mode 100644 index 0000000000000000000000000000000000000000..1ed9abdd415da5d4ffc5823c9e6c797c542bf100 --- /dev/null +++ b/es2panda/test/ts_extra_tests/test_ts_cases/spec/basic_concepts/names/reserved_words/special_mean_but_valid_identifier/get_is_valid_identifier_2.ts @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/**--- + description: The keywords 'get' has special meaning in certain contexts, but is valid identifier. + module: ESNext + isCurrent: true + ---*/ + + +import { Assert } from '../../../../../../suite/assert.js' + +function get(): string { + return "get"; +} +Assert.equal(get(), "get"); \ No newline at end of file diff --git a/es2panda/test/ts_extra_tests/test_ts_cases/spec/basic_concepts/names/reserved_words/special_mean_but_valid_identifier/get_is_valid_identifier_3.ts b/es2panda/test/ts_extra_tests/test_ts_cases/spec/basic_concepts/names/reserved_words/special_mean_but_valid_identifier/get_is_valid_identifier_3.ts new file mode 100644 index 0000000000000000000000000000000000000000..48ade41aea8e19a3cb642e36febc7e19e360d9c0 --- /dev/null +++ b/es2panda/test/ts_extra_tests/test_ts_cases/spec/basic_concepts/names/reserved_words/special_mean_but_valid_identifier/get_is_valid_identifier_3.ts @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/**--- + description: The keywords 'get' has special meaning in certain contexts, but is valid identifier. + module: ESNext + isCurrent: true + ---*/ + + +import { Assert } from '../../../../../../suite/assert.js' + +class get { + name: string; + constructor(name: string) { + this.name = name; + } + getName(): string { + return this.name; + } +} +var newobj = new get("get"); +Assert.equal(newobj.getName(), "get"); \ No newline at end of file diff --git a/es2panda/test/ts_extra_tests/test_ts_cases/spec/basic_concepts/names/reserved_words/special_mean_but_valid_identifier/get_is_valid_identifier_4.ts b/es2panda/test/ts_extra_tests/test_ts_cases/spec/basic_concepts/names/reserved_words/special_mean_but_valid_identifier/get_is_valid_identifier_4.ts new file mode 100644 index 0000000000000000000000000000000000000000..7aeffc88a842731d9e21910aef9f57f727d64b28 --- /dev/null +++ b/es2panda/test/ts_extra_tests/test_ts_cases/spec/basic_concepts/names/reserved_words/special_mean_but_valid_identifier/get_is_valid_identifier_4.ts @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/**--- + description: The keywords 'get' has special meaning in certain contexts, but is valid identifier. + module: ESNext + isCurrent: true + ---*/ + + +import { Assert } from '../../../../../../suite/assert.js' + +interface get { + name: string, + getName: () => string +} +var customer: get = { + name: "get", + getName(): string { + return this.name; + } +} +Assert.equal(customer.name, "get"); \ No newline at end of file diff --git a/es2panda/test/ts_extra_tests/test_ts_cases/spec/basic_concepts/names/reserved_words/special_mean_but_valid_identifier/is_is_valid_identifier_1.ts b/es2panda/test/ts_extra_tests/test_ts_cases/spec/basic_concepts/names/reserved_words/special_mean_but_valid_identifier/is_is_valid_identifier_1.ts new file mode 100644 index 0000000000000000000000000000000000000000..1fe4f7ea784590c299d0a760a03e207532a2eb2d --- /dev/null +++ b/es2panda/test/ts_extra_tests/test_ts_cases/spec/basic_concepts/names/reserved_words/special_mean_but_valid_identifier/is_is_valid_identifier_1.ts @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/**--- + description: The keywords 'is' has special meaning in certain contexts, but is valid identifier. + module: ESNext + isCurrent: true + ---*/ + + +import { Assert } from '../../../../../../suite/assert.js' + +var is: string = "is"; +Assert.equal(is, "is"); \ No newline at end of file diff --git a/es2panda/test/ts_extra_tests/test_ts_cases/spec/basic_concepts/names/reserved_words/special_mean_but_valid_identifier/is_is_valid_identifier_2.ts b/es2panda/test/ts_extra_tests/test_ts_cases/spec/basic_concepts/names/reserved_words/special_mean_but_valid_identifier/is_is_valid_identifier_2.ts new file mode 100644 index 0000000000000000000000000000000000000000..bd17391c7295f11018ce68305285d9111494fbd1 --- /dev/null +++ b/es2panda/test/ts_extra_tests/test_ts_cases/spec/basic_concepts/names/reserved_words/special_mean_but_valid_identifier/is_is_valid_identifier_2.ts @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/**--- + description: The keywords 'is' has special meaning in certain contexts, but is valid identifier. + module: ESNext + isCurrent: true + ---*/ + + +import { Assert } from '../../../../../../suite/assert.js' + +function is(): string { + return "is"; +} +Assert.equal(is(), "is"); \ No newline at end of file diff --git a/es2panda/test/ts_extra_tests/test_ts_cases/spec/basic_concepts/names/reserved_words/special_mean_but_valid_identifier/is_is_valid_identifier_3.ts b/es2panda/test/ts_extra_tests/test_ts_cases/spec/basic_concepts/names/reserved_words/special_mean_but_valid_identifier/is_is_valid_identifier_3.ts new file mode 100644 index 0000000000000000000000000000000000000000..ae9fdb3c57f5f36876ce2d6edeff5de57e6b051b --- /dev/null +++ b/es2panda/test/ts_extra_tests/test_ts_cases/spec/basic_concepts/names/reserved_words/special_mean_but_valid_identifier/is_is_valid_identifier_3.ts @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/**--- + description: The keywords 'is' has special meaning in certain contexts, but is valid identifier. + module: ESNext + isCurrent: true + ---*/ + + +import { Assert } from '../../../../../../suite/assert.js' + +class is { + name: string; + constructor(name: string) { + this.name = name; + } + getName(): string { + return this.name; + } +} +var newobj = new is("is"); +Assert.equal(newobj.getName(), "is"); \ No newline at end of file diff --git a/es2panda/test/ts_extra_tests/test_ts_cases/spec/basic_concepts/names/reserved_words/special_mean_but_valid_identifier/is_is_valid_identifier_4.ts b/es2panda/test/ts_extra_tests/test_ts_cases/spec/basic_concepts/names/reserved_words/special_mean_but_valid_identifier/is_is_valid_identifier_4.ts new file mode 100644 index 0000000000000000000000000000000000000000..21d321bf4f426d21acbcd5f94061eb5c2d1231de --- /dev/null +++ b/es2panda/test/ts_extra_tests/test_ts_cases/spec/basic_concepts/names/reserved_words/special_mean_but_valid_identifier/is_is_valid_identifier_4.ts @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/**--- + description: The keywords 'is' has special meaning in certain contexts, but is valid identifier. + module: ESNext + isCurrent: true + ---*/ + + +import { Assert } from '../../../../../../suite/assert.js' + +interface is { + name: string, + getName: () => string +} +var customer: is = { + name: "is", + getName(): string { + return this.name; + } +} +Assert.equal(customer.name, "is"); \ No newline at end of file diff --git a/es2panda/test/ts_extra_tests/test_ts_cases/spec/basic_concepts/names/reserved_words/special_mean_but_valid_identifier/module_is_valid_identifier_1.ts b/es2panda/test/ts_extra_tests/test_ts_cases/spec/basic_concepts/names/reserved_words/special_mean_but_valid_identifier/module_is_valid_identifier_1.ts new file mode 100644 index 0000000000000000000000000000000000000000..a8439b34c17162a2ffdfd68921cbc3dea28c799d --- /dev/null +++ b/es2panda/test/ts_extra_tests/test_ts_cases/spec/basic_concepts/names/reserved_words/special_mean_but_valid_identifier/module_is_valid_identifier_1.ts @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/**--- + description: The keywords 'module' has special meaning in certain contexts, but is valid identifier. + module: ESNext + isCurrent: true + ---*/ + + +import { Assert } from '../../../../../../suite/assert.js' + +var module2: string = "module"; +Assert.equal(module2, "module"); \ No newline at end of file diff --git a/es2panda/test/ts_extra_tests/test_ts_cases/spec/basic_concepts/names/reserved_words/special_mean_but_valid_identifier/module_is_valid_identifier_2.ts b/es2panda/test/ts_extra_tests/test_ts_cases/spec/basic_concepts/names/reserved_words/special_mean_but_valid_identifier/module_is_valid_identifier_2.ts new file mode 100644 index 0000000000000000000000000000000000000000..7cae555f3371196f64a826f91cbc295bebe434fd --- /dev/null +++ b/es2panda/test/ts_extra_tests/test_ts_cases/spec/basic_concepts/names/reserved_words/special_mean_but_valid_identifier/module_is_valid_identifier_2.ts @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/**--- + description: The keywords 'module' has special meaning in certain contexts, but is valid identifier. + module: ESNext + isCurrent: true + ---*/ + + +import { Assert } from '../../../../../../suite/assert.js' + +function module1(): string { + return "module"; +} +Assert.equal(module1(), "module"); \ No newline at end of file diff --git a/es2panda/test/ts_extra_tests/test_ts_cases/spec/basic_concepts/names/reserved_words/special_mean_but_valid_identifier/module_is_valid_identifier_3.ts b/es2panda/test/ts_extra_tests/test_ts_cases/spec/basic_concepts/names/reserved_words/special_mean_but_valid_identifier/module_is_valid_identifier_3.ts new file mode 100644 index 0000000000000000000000000000000000000000..0782ed97f8479dcff524fafa08aa6c1bb559a87a --- /dev/null +++ b/es2panda/test/ts_extra_tests/test_ts_cases/spec/basic_concepts/names/reserved_words/special_mean_but_valid_identifier/module_is_valid_identifier_3.ts @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/**--- + description: The keywords 'module' has special meaning in certain contexts, but is valid identifier. + module: ESNext + isCurrent: true + ---*/ + + +import { Assert } from '../../../../../../suite/assert.js' + +{ + class module { + name: string; + + constructor(name: string) { + this.name = name; + } + + getName(): string { + return this.name; + } + } + + var newobj = new module("module"); + Assert.equal(newobj.getName(), "module"); +}; \ No newline at end of file diff --git a/es2panda/test/ts_extra_tests/test_ts_cases/spec/basic_concepts/names/reserved_words/special_mean_but_valid_identifier/module_is_valid_identifier_4.ts b/es2panda/test/ts_extra_tests/test_ts_cases/spec/basic_concepts/names/reserved_words/special_mean_but_valid_identifier/module_is_valid_identifier_4.ts new file mode 100644 index 0000000000000000000000000000000000000000..fe0503373631807daed86408edf447882a43e95f --- /dev/null +++ b/es2panda/test/ts_extra_tests/test_ts_cases/spec/basic_concepts/names/reserved_words/special_mean_but_valid_identifier/module_is_valid_identifier_4.ts @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/**--- + description: The keywords 'module' has special meaning in certain contexts, but is valid identifier. + module: ESNext + isCurrent: true + ---*/ + + +import { Assert } from '../../../../../../suite/assert.js' + +interface module { + name: string, + getName: () => string +} +var customer: module = { + name: "module", + getName(): string { + return this.name; + } +} +Assert.equal(customer.name, "module"); \ No newline at end of file diff --git a/es2panda/test/ts_extra_tests/test_ts_cases/spec/basic_concepts/names/reserved_words/special_mean_but_valid_identifier/namespace_is_valid_identifier_1.ts b/es2panda/test/ts_extra_tests/test_ts_cases/spec/basic_concepts/names/reserved_words/special_mean_but_valid_identifier/namespace_is_valid_identifier_1.ts new file mode 100644 index 0000000000000000000000000000000000000000..bceffbe7268be165a96afd60c71c277109d73cf4 --- /dev/null +++ b/es2panda/test/ts_extra_tests/test_ts_cases/spec/basic_concepts/names/reserved_words/special_mean_but_valid_identifier/namespace_is_valid_identifier_1.ts @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/**--- + description: The keywords 'namespace' has special meaning in certain contexts, but is valid identifier. + module: ESNext + isCurrent: true + ---*/ + + +import { Assert } from '../../../../../../suite/assert.js' + +var namespace: string = "namespace"; +Assert.equal(namespace, "namespace"); \ No newline at end of file diff --git a/es2panda/test/ts_extra_tests/test_ts_cases/spec/basic_concepts/names/reserved_words/special_mean_but_valid_identifier/namespace_is_valid_identifier_2.ts b/es2panda/test/ts_extra_tests/test_ts_cases/spec/basic_concepts/names/reserved_words/special_mean_but_valid_identifier/namespace_is_valid_identifier_2.ts new file mode 100644 index 0000000000000000000000000000000000000000..13b73f89b748d37bf6118da59c2d365fb9063615 --- /dev/null +++ b/es2panda/test/ts_extra_tests/test_ts_cases/spec/basic_concepts/names/reserved_words/special_mean_but_valid_identifier/namespace_is_valid_identifier_2.ts @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/**--- + description: The keywords 'namespace' has special meaning in certain contexts, but is valid identifier. + module: ESNext + isCurrent: true + ---*/ + + +import { Assert } from '../../../../../../suite/assert.js' + +function namespace(): string { + return "namespace"; +} +Assert.equal(namespace(), "namespace"); \ No newline at end of file diff --git a/es2panda/test/ts_extra_tests/test_ts_cases/spec/basic_concepts/names/reserved_words/special_mean_but_valid_identifier/namespace_is_valid_identifier_3.ts b/es2panda/test/ts_extra_tests/test_ts_cases/spec/basic_concepts/names/reserved_words/special_mean_but_valid_identifier/namespace_is_valid_identifier_3.ts new file mode 100644 index 0000000000000000000000000000000000000000..fa58b1e6c113f5a4fe0012a64d66f266871fd82e --- /dev/null +++ b/es2panda/test/ts_extra_tests/test_ts_cases/spec/basic_concepts/names/reserved_words/special_mean_but_valid_identifier/namespace_is_valid_identifier_3.ts @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/**--- + description: The keywords 'namespace' has special meaning in certain contexts, but is valid identifier. + module: ESNext + isCurrent: true + ---*/ + + +import { Assert } from '../../../../../../suite/assert.js' + +class namespace { + name: string; + constructor(name: string) { + this.name = name; + } + getName(): string { + return this.name; + } +} +var newobj = new namespace("namespace"); +Assert.equal(newobj.getName(), "namespace"); \ No newline at end of file diff --git a/es2panda/test/ts_extra_tests/test_ts_cases/spec/basic_concepts/names/reserved_words/special_mean_but_valid_identifier/namespace_is_valid_identifier_4.ts b/es2panda/test/ts_extra_tests/test_ts_cases/spec/basic_concepts/names/reserved_words/special_mean_but_valid_identifier/namespace_is_valid_identifier_4.ts new file mode 100644 index 0000000000000000000000000000000000000000..3be352641183f0a02f131af1b5859042efd30ad7 --- /dev/null +++ b/es2panda/test/ts_extra_tests/test_ts_cases/spec/basic_concepts/names/reserved_words/special_mean_but_valid_identifier/namespace_is_valid_identifier_4.ts @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/**--- + description: The keywords 'namespace' has special meaning in certain contexts, but is valid identifier. + module: ESNext + isCurrent: true + ---*/ + + +import { Assert } from '../../../../../../suite/assert.js' + +interface namespace { + name: string, + getName: () => string +} +var customer: namespace = { + name: "namespace", + getName(): string { + return this.name; + } +} +Assert.equal(customer.name, "namespace"); \ No newline at end of file diff --git a/es2panda/test/ts_extra_tests/test_ts_cases/spec/basic_concepts/names/reserved_words/special_mean_but_valid_identifier/of_is_valid_identifier_1.ts b/es2panda/test/ts_extra_tests/test_ts_cases/spec/basic_concepts/names/reserved_words/special_mean_but_valid_identifier/of_is_valid_identifier_1.ts new file mode 100644 index 0000000000000000000000000000000000000000..d50c317607afcad1c6017ac42483612a6d746cb5 --- /dev/null +++ b/es2panda/test/ts_extra_tests/test_ts_cases/spec/basic_concepts/names/reserved_words/special_mean_but_valid_identifier/of_is_valid_identifier_1.ts @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/**--- + description: The keywords 'of' has special meaning in certain contexts, but is valid identifier. + module: ESNext + isCurrent: true + ---*/ + + +import { Assert } from '../../../../../../suite/assert.js' + +var of: string = "of"; +Assert.equal(of, "of"); \ No newline at end of file diff --git a/es2panda/test/ts_extra_tests/test_ts_cases/spec/basic_concepts/names/reserved_words/special_mean_but_valid_identifier/of_is_valid_identifier_2.ts b/es2panda/test/ts_extra_tests/test_ts_cases/spec/basic_concepts/names/reserved_words/special_mean_but_valid_identifier/of_is_valid_identifier_2.ts new file mode 100644 index 0000000000000000000000000000000000000000..08ffa6cddfcff3a90c93381304080420a15d2291 --- /dev/null +++ b/es2panda/test/ts_extra_tests/test_ts_cases/spec/basic_concepts/names/reserved_words/special_mean_but_valid_identifier/of_is_valid_identifier_2.ts @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/**--- + description: The keywords 'of' has special meaning in certain contexts, but is valid identifier. + module: ESNext + isCurrent: true + ---*/ + + +import { Assert } from '../../../../../../suite/assert.js' + +function of(): string { + return "of"; +} +Assert.equal(of(), "of"); \ No newline at end of file diff --git a/es2panda/test/ts_extra_tests/test_ts_cases/spec/basic_concepts/names/reserved_words/special_mean_but_valid_identifier/of_is_valid_identifier_3.ts b/es2panda/test/ts_extra_tests/test_ts_cases/spec/basic_concepts/names/reserved_words/special_mean_but_valid_identifier/of_is_valid_identifier_3.ts new file mode 100644 index 0000000000000000000000000000000000000000..47d4f7a37f2294bba3b2a7e6bf075c12cf969d8b --- /dev/null +++ b/es2panda/test/ts_extra_tests/test_ts_cases/spec/basic_concepts/names/reserved_words/special_mean_but_valid_identifier/of_is_valid_identifier_3.ts @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/**--- + description: The keywords 'of' has special meaning in certain contexts, but is valid identifier. + module: ESNext + isCurrent: true + ---*/ + + +import { Assert } from '../../../../../../suite/assert.js' + +class of { + name: string; + constructor(name: string) { + this.name = name; + } + getName(): string { + return this.name; + } +} +var newobj = new of("of"); +Assert.equal(newobj.getName(), "of"); \ No newline at end of file diff --git a/es2panda/test/ts_extra_tests/test_ts_cases/spec/basic_concepts/names/reserved_words/special_mean_but_valid_identifier/of_is_valid_identifier_4.ts b/es2panda/test/ts_extra_tests/test_ts_cases/spec/basic_concepts/names/reserved_words/special_mean_but_valid_identifier/of_is_valid_identifier_4.ts new file mode 100644 index 0000000000000000000000000000000000000000..8f31d65c4f94b6f532bec8598e028d6cf79a15f2 --- /dev/null +++ b/es2panda/test/ts_extra_tests/test_ts_cases/spec/basic_concepts/names/reserved_words/special_mean_but_valid_identifier/of_is_valid_identifier_4.ts @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/**--- + description: The keywords 'of' has special meaning in certain contexts, but is valid identifier. + module: ESNext + isCurrent: true + ---*/ + + +import { Assert } from '../../../../../../suite/assert.js' + +interface of { + name: string, + getName: () => string +} +var customer: of = { + name: "of", + getName(): string { + return this.name; + } +} +Assert.equal(customer.name, "of"); \ No newline at end of file diff --git a/es2panda/test/ts_extra_tests/test_ts_cases/spec/basic_concepts/names/reserved_words/special_mean_but_valid_identifier/require_is_valid_identifier_1.ts b/es2panda/test/ts_extra_tests/test_ts_cases/spec/basic_concepts/names/reserved_words/special_mean_but_valid_identifier/require_is_valid_identifier_1.ts new file mode 100644 index 0000000000000000000000000000000000000000..b2076508c13ade6d15b076dbc1136fc8dd5d5d9c --- /dev/null +++ b/es2panda/test/ts_extra_tests/test_ts_cases/spec/basic_concepts/names/reserved_words/special_mean_but_valid_identifier/require_is_valid_identifier_1.ts @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/**--- + description: The keywords 'require' has special meaning in certain contexts, but is valid identifier. + module: ESNext + isCurrent: true + ---*/ + + +import { Assert } from '../../../../../../suite/assert.js' + +let require: string = 'require'; +Assert.equal(require, "require"); \ No newline at end of file diff --git a/es2panda/test/ts_extra_tests/test_ts_cases/spec/basic_concepts/names/reserved_words/special_mean_but_valid_identifier/require_is_valid_identifier_2.ts b/es2panda/test/ts_extra_tests/test_ts_cases/spec/basic_concepts/names/reserved_words/special_mean_but_valid_identifier/require_is_valid_identifier_2.ts new file mode 100644 index 0000000000000000000000000000000000000000..f874238fe4429a35f01794b3d046451424159499 --- /dev/null +++ b/es2panda/test/ts_extra_tests/test_ts_cases/spec/basic_concepts/names/reserved_words/special_mean_but_valid_identifier/require_is_valid_identifier_2.ts @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/**--- + description: The keywords 'require' has special meaning in certain contexts, but is valid identifier. + module: ESNext + isCurrent: true + ---*/ + + +import { Assert } from '../../../../../../suite/assert.js' + +function require(): string { + return 'require' +}; +Assert.equal(require(), "require"); \ No newline at end of file diff --git a/es2panda/test/ts_extra_tests/test_ts_cases/spec/basic_concepts/names/reserved_words/special_mean_but_valid_identifier/require_is_valid_identifier_3.ts b/es2panda/test/ts_extra_tests/test_ts_cases/spec/basic_concepts/names/reserved_words/special_mean_but_valid_identifier/require_is_valid_identifier_3.ts new file mode 100644 index 0000000000000000000000000000000000000000..5ec941565345a4b5ab701fbe1b27794d105a9f32 --- /dev/null +++ b/es2panda/test/ts_extra_tests/test_ts_cases/spec/basic_concepts/names/reserved_words/special_mean_but_valid_identifier/require_is_valid_identifier_3.ts @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/**--- + description: The keywords 'require' has special meaning in certain contexts, but is valid identifier. + module: ESNext + isCurrent: true + ---*/ + + +import { Assert } from '../../../../../../suite/assert.js' + +class require { + name: string; + constructor(name: string) { + this.name = name; + } + getName(): string { + return this.name; + } +} +var newobj = new require("require"); +Assert.equal(newobj.getName(), "require"); \ No newline at end of file diff --git a/es2panda/test/ts_extra_tests/test_ts_cases/spec/basic_concepts/names/reserved_words/special_mean_but_valid_identifier/require_is_valid_identifier_4.ts b/es2panda/test/ts_extra_tests/test_ts_cases/spec/basic_concepts/names/reserved_words/special_mean_but_valid_identifier/require_is_valid_identifier_4.ts new file mode 100644 index 0000000000000000000000000000000000000000..d5908d19d83bbbab2a0b717ecb54e3af02ef1023 --- /dev/null +++ b/es2panda/test/ts_extra_tests/test_ts_cases/spec/basic_concepts/names/reserved_words/special_mean_but_valid_identifier/require_is_valid_identifier_4.ts @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/**--- + description: The keywords 'require' has special meaning in certain contexts, but is valid identifier. + module: ESNext + isCurrent: true + ---*/ + + +import { Assert } from '../../../../../../suite/assert.js' + +interface require { + name: string, + getName: () => string +} +var customer: require = { + name: "require", + getName(): string { + return this.name; + } +} +Assert.equal(customer.name, "require"); \ No newline at end of file diff --git a/es2panda/test/ts_extra_tests/test_ts_cases/spec/basic_concepts/names/reserved_words/special_mean_but_valid_identifier/set_is_valid_identifier_1.ts b/es2panda/test/ts_extra_tests/test_ts_cases/spec/basic_concepts/names/reserved_words/special_mean_but_valid_identifier/set_is_valid_identifier_1.ts new file mode 100644 index 0000000000000000000000000000000000000000..e0b5607cf1a28d8803417ee6e23e17398f10b188 --- /dev/null +++ b/es2panda/test/ts_extra_tests/test_ts_cases/spec/basic_concepts/names/reserved_words/special_mean_but_valid_identifier/set_is_valid_identifier_1.ts @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/**--- + description: The keywords 'set' has special meaning in certain contexts, but is valid identifier. + module: ESNext + isCurrent: true + ---*/ + + +import { Assert } from '../../../../../../suite/assert.js' + +var set: string = "set"; +Assert.equal(set, "set"); \ No newline at end of file diff --git a/es2panda/test/ts_extra_tests/test_ts_cases/spec/basic_concepts/names/reserved_words/special_mean_but_valid_identifier/set_is_valid_identifier_2.ts b/es2panda/test/ts_extra_tests/test_ts_cases/spec/basic_concepts/names/reserved_words/special_mean_but_valid_identifier/set_is_valid_identifier_2.ts new file mode 100644 index 0000000000000000000000000000000000000000..65a32d4ed12888ea8845d5c7a17593018d1afe0c --- /dev/null +++ b/es2panda/test/ts_extra_tests/test_ts_cases/spec/basic_concepts/names/reserved_words/special_mean_but_valid_identifier/set_is_valid_identifier_2.ts @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/**--- + description: The keywords 'set' has special meaning in certain contexts, but is valid identifier. + module: ESNext + isCurrent: true + ---*/ + + +import { Assert } from '../../../../../../suite/assert.js' + +function set(): string { + return "set"; +} +Assert.equal(set(), "set"); \ No newline at end of file diff --git a/es2panda/test/ts_extra_tests/test_ts_cases/spec/basic_concepts/names/reserved_words/special_mean_but_valid_identifier/set_is_valid_identifier_3.ts b/es2panda/test/ts_extra_tests/test_ts_cases/spec/basic_concepts/names/reserved_words/special_mean_but_valid_identifier/set_is_valid_identifier_3.ts new file mode 100644 index 0000000000000000000000000000000000000000..0ce429bfbbaaeac78e7fde029719a8b2490c3b7b --- /dev/null +++ b/es2panda/test/ts_extra_tests/test_ts_cases/spec/basic_concepts/names/reserved_words/special_mean_but_valid_identifier/set_is_valid_identifier_3.ts @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/**--- + description: The keywords 'set' has special meaning in certain contexts, but is valid identifier. + module: ESNext + isCurrent: true + ---*/ + + +import { Assert } from '../../../../../../suite/assert.js' + +class set { + name: string; + constructor(name: string) { + this.name = name; + } + getName(): string { + return this.name; + } +} +var newobj = new set("set"); +Assert.equal(newobj.getName(), "set"); \ No newline at end of file diff --git a/es2panda/test/ts_extra_tests/test_ts_cases/spec/basic_concepts/names/reserved_words/special_mean_but_valid_identifier/set_is_valid_identifier_4.ts b/es2panda/test/ts_extra_tests/test_ts_cases/spec/basic_concepts/names/reserved_words/special_mean_but_valid_identifier/set_is_valid_identifier_4.ts new file mode 100644 index 0000000000000000000000000000000000000000..b0279a2228627b0ec3a0ebb6843db506f228a85f --- /dev/null +++ b/es2panda/test/ts_extra_tests/test_ts_cases/spec/basic_concepts/names/reserved_words/special_mean_but_valid_identifier/set_is_valid_identifier_4.ts @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/**--- + description: The keywords 'set' has special meaning in certain contexts, but is valid identifier. + module: ESNext + isCurrent: true + ---*/ + + +import { Assert } from '../../../../../../suite/assert.js' + +interface set { + name: string, + getName: () => string +} +var customer: set = { + name: "set", + getName(): string { + return this.name; + } +} +Assert.equal(customer.name, "set"); \ No newline at end of file diff --git a/es2panda/test/ts_extra_tests/test_ts_cases/spec/basic_concepts/names/reserved_words/special_mean_but_valid_identifier/type_is_valid_identifier_1.ts b/es2panda/test/ts_extra_tests/test_ts_cases/spec/basic_concepts/names/reserved_words/special_mean_but_valid_identifier/type_is_valid_identifier_1.ts new file mode 100644 index 0000000000000000000000000000000000000000..3bec40eb37322072d2f2ded8362fe1dfc092e1e1 --- /dev/null +++ b/es2panda/test/ts_extra_tests/test_ts_cases/spec/basic_concepts/names/reserved_words/special_mean_but_valid_identifier/type_is_valid_identifier_1.ts @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/**--- + description: The keywords 'type' has special meaning in certain contexts, but is valid identifier. + module: ESNext + isCurrent: true + ---*/ + + +import { Assert } from '../../../../../../suite/assert.js' + +var type: string = "type"; +Assert.equal(type, "type"); \ No newline at end of file diff --git a/es2panda/test/ts_extra_tests/test_ts_cases/spec/basic_concepts/names/reserved_words/special_mean_but_valid_identifier/type_is_valid_identifier_2.ts b/es2panda/test/ts_extra_tests/test_ts_cases/spec/basic_concepts/names/reserved_words/special_mean_but_valid_identifier/type_is_valid_identifier_2.ts new file mode 100644 index 0000000000000000000000000000000000000000..4c9e57cc56d322facb6fd9a26e0ddfb7bc36d869 --- /dev/null +++ b/es2panda/test/ts_extra_tests/test_ts_cases/spec/basic_concepts/names/reserved_words/special_mean_but_valid_identifier/type_is_valid_identifier_2.ts @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/**--- + description: The keywords 'type' has special meaning in certain contexts, but is valid identifier. + module: ESNext + isCurrent: true + ---*/ + + +import { Assert } from '../../../../../../suite/assert.js' + +function type(): string { + return "type"; +} +Assert.equal(type(), "type"); \ No newline at end of file diff --git a/es2panda/test/ts_extra_tests/test_ts_cases/spec/basic_concepts/names/reserved_words/special_mean_but_valid_identifier/type_is_valid_identifier_3.ts b/es2panda/test/ts_extra_tests/test_ts_cases/spec/basic_concepts/names/reserved_words/special_mean_but_valid_identifier/type_is_valid_identifier_3.ts new file mode 100644 index 0000000000000000000000000000000000000000..d7ef4051957fce47f55c14799f084b0cdb7fc738 --- /dev/null +++ b/es2panda/test/ts_extra_tests/test_ts_cases/spec/basic_concepts/names/reserved_words/special_mean_but_valid_identifier/type_is_valid_identifier_3.ts @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/**--- + description: The keywords 'type' has special meaning in certain contexts, but is valid identifier. + module: ESNext + isCurrent: true + ---*/ + + +import { Assert } from '../../../../../../suite/assert.js' + +class type { + name: string; + constructor(name: string) { + this.name = name; + } + getName(): string { + return this.name; + } +} +var newobj = new type("type"); +Assert.equal(newobj.getName(), "type"); \ No newline at end of file diff --git a/es2panda/test/ts_extra_tests/test_ts_cases/spec/basic_concepts/names/reserved_words/special_mean_but_valid_identifier/type_is_valid_identifier_4.ts b/es2panda/test/ts_extra_tests/test_ts_cases/spec/basic_concepts/names/reserved_words/special_mean_but_valid_identifier/type_is_valid_identifier_4.ts new file mode 100644 index 0000000000000000000000000000000000000000..995036f95a9039ba2aaa41681bfa723a6f887cf5 --- /dev/null +++ b/es2panda/test/ts_extra_tests/test_ts_cases/spec/basic_concepts/names/reserved_words/special_mean_but_valid_identifier/type_is_valid_identifier_4.ts @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/**--- + description: The keywords 'type' has special meaning in certain contexts, but is valid identifier. + module: ESNext + isCurrent: true + ---*/ + + +import { Assert } from '../../../../../../suite/assert.js' + +interface type { + name: string, + getName: () => string +} +var customer: type = { + name: "type", + getName(): string { + return this.name; + } +} +Assert.equal(customer.name, "type"); \ No newline at end of file diff --git a/es2panda/test/ts_extra_tests/test_ts_cases/spec/basic_concepts/scopes/let_scope.ts b/es2panda/test/ts_extra_tests/test_ts_cases/spec/basic_concepts/scopes/let_scope.ts new file mode 100644 index 0000000000000000000000000000000000000000..83064a87ad34f7f96285eb0c9731beb3e2623073 --- /dev/null +++ b/es2panda/test/ts_extra_tests/test_ts_cases/spec/basic_concepts/scopes/let_scope.ts @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/**--- + description: > + The scope of a local let declared immediately within a statement block is the body of that statement block. + The scope of a local let declaration declared immediately within the body of a function-like declaration is the body of that function-like declaration. + module: ESNext + isCurrent: true + ---*/ + + +import { Assert } from '../../../../suite/assert.js' + +let GlobalScope = 1; +function someFunc() { + let FunctionScope = 2; + if (true) { + let BlockScope = 3; + Assert.equal(FunctionScope, 2); + Assert.equal(BlockScope, 3); + } + Assert.equal(GlobalScope, 1); +} +someFunc(); \ No newline at end of file diff --git a/es2panda/test/ts_extra_tests/test_ts_cases/spec/basic_concepts/scopes/scopes_1.ts b/es2panda/test/ts_extra_tests/test_ts_cases/spec/basic_concepts/scopes/scopes_1.ts new file mode 100644 index 0000000000000000000000000000000000000000..15310bd065cb41035af18b97a1067205402b473d --- /dev/null +++ b/es2panda/test/ts_extra_tests/test_ts_cases/spec/basic_concepts/scopes/scopes_1.ts @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/**--- + description: > + The scope of a name declared in the global namespace is the entire program text. + module: ESNext + isCurrent: true + ---*/ + + +import { Assert } from "../../../../suite/assert.js"; + +var a: number = 1024; +let b: string = 'NARC'; +Assert.equal(a, 1024); +Assert.equal(b, 'NARC'); +function add() { + return a + b; +} +Assert.equal(add(), '1024NARC'); +class OUT { + out: string; + constructor() { + this.out = b + a; + } +} +let out = new OUT(); +Assert.equal(out.out, 'NARC1024'); \ No newline at end of file diff --git a/es2panda/test/ts_extra_tests/test_ts_cases/spec/basic_concepts/scopes/scopes_10.ts b/es2panda/test/ts_extra_tests/test_ts_cases/spec/basic_concepts/scopes/scopes_10.ts new file mode 100644 index 0000000000000000000000000000000000000000..065f551a2fdf2d6e218a1d6e4d61f54b5ca002fe --- /dev/null +++ b/es2panda/test/ts_extra_tests/test_ts_cases/spec/basic_concepts/scopes/scopes_10.ts @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/**--- + description: > + The scope of a local let, const, class, interface, type alias, or enum declaration declared immediately within the body of a function-like declaration is the body of that function-like declaration. + module: ESNext + isCurrent: true + ---*/ + + +import { Assert } from "../../../../suite/assert.js"; + +function sfun() { + let s = 1024; + Assert.equal(s, 1024); + const n = 'NARC' + Assert.equal(n, 'NARC'); + class C { + c: number; + constructor(c: number) { + this.c = c; + } + } + let cc = new C(5); + Assert.equal(cc.c, 5); + + type S = keyof C | keyof number & keyof string; + let ss: S = "valueOf"; + Assert.equal(ss, "valueOf"); +} +sfun(); \ No newline at end of file diff --git a/es2panda/test/ts_extra_tests/test_ts_cases/spec/basic_concepts/scopes/scopes_11.ts b/es2panda/test/ts_extra_tests/test_ts_cases/spec/basic_concepts/scopes/scopes_11.ts new file mode 100644 index 0000000000000000000000000000000000000000..bbcae824b704068a18f586f3059d26cb9f808083 --- /dev/null +++ b/es2panda/test/ts_extra_tests/test_ts_cases/spec/basic_concepts/scopes/scopes_11.ts @@ -0,0 +1,50 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/**--- + description: > + The scope of a local let, const, class, interface, type alias, or enum declaration declared immediately within a statement block is the body of that statement block. + module: ESNext + isCurrent: true + ---*/ + + +import { Assert } from "../../../../suite/assert.js"; + +{ + var v: number = 999; + Assert.equal(v, 999); + let l: number = 333; + Assert.equal(l, 333); + const con: "NARC" = 'NARC'; + Assert.equal(con, "NARC"); + class cla { + c: number = 1024; + } + let cl = new cla(); + Assert.equal(cl.c, 1024); + + interface I { + color: [number, number, number]; + } + let i: I = { color: [255, 0, 0] }; + Assert.equal(i.color[0], 255); + + type CV = keyof I | keyof string & keyof number; + let cv: CV = "color"; + Assert.equal(cv, "color"); +} +{ + Assert.equal(v / 9, 111); +} \ No newline at end of file diff --git a/es2panda/test/ts_extra_tests/test_ts_cases/spec/basic_concepts/scopes/scopes_12.ts b/es2panda/test/ts_extra_tests/test_ts_cases/spec/basic_concepts/scopes/scopes_12.ts new file mode 100644 index 0000000000000000000000000000000000000000..b7861c07e443969e6e2b8155221683f105084064 --- /dev/null +++ b/es2panda/test/ts_extra_tests/test_ts_cases/spec/basic_concepts/scopes/scopes_12.ts @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/**--- + description: > + Scopes may overlap, for example through nesting of namespaces and functions. When the scopes of two names overlap, + the name with the innermost declaration takes precedence and access to the outer name is either not possible or only possible by qualification. + module: ESNext + isCurrent: true + ---*/ + + +import { Assert } from "../../../../suite/assert.js"; + +var x: number = -1; + +namespace X { + export var x: number = 1024; + export function X() { + var x: string = 'NARC'; + Assert.equal(x, 'NARC'); + return x; + } + Assert.equal(x, 1024); + Assert.equal(X(), 'NARC'); +} +Assert.equal(x, -1); +Assert.equal(X.x, 1024); +Assert.equal(X.X(), 'NARC'); \ No newline at end of file diff --git a/es2panda/test/ts_extra_tests/test_ts_cases/spec/basic_concepts/scopes/scopes_13_1.ts b/es2panda/test/ts_extra_tests/test_ts_cases/spec/basic_concepts/scopes/scopes_13_1.ts new file mode 100644 index 0000000000000000000000000000000000000000..4fd14b6b002b94f971aa3630b7fdfe7e0cd89ef0 --- /dev/null +++ b/es2panda/test/ts_extra_tests/test_ts_cases/spec/basic_concepts/scopes/scopes_13_1.ts @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/**--- + description: > + When an identifier is resolved as a PrimaryExpression, only names in scope with a value meaning are considered and other names are ignored. + module: ESNext + isCurrent: true + ---*/ + + +import { Assert } from "../../../../suite/assert.js"; + +var v: number = 333; +interface v { + v: string; +} +Assert.equal(v, 333); + +let v0: v = { v: "v" }; +Assert.equal(v0.v, "v"); \ No newline at end of file diff --git a/es2panda/test/ts_extra_tests/test_ts_cases/spec/basic_concepts/scopes/scopes_13_2.ts b/es2panda/test/ts_extra_tests/test_ts_cases/spec/basic_concepts/scopes/scopes_13_2.ts new file mode 100644 index 0000000000000000000000000000000000000000..91dd3be53dcc75eb376d99b42718f40791cec2fb --- /dev/null +++ b/es2panda/test/ts_extra_tests/test_ts_cases/spec/basic_concepts/scopes/scopes_13_2.ts @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/**--- + description: > + When an identifier is resolved as a TypeName, only names in scope with a type meaning are considered and other names are ignored. + module: ESNext + isCurrent: true + ---*/ + + +import { Assert } from "../../../../suite/assert.js"; + +var s: string = "TypeScript"; +type s = Number; +Assert.equal(s, "TypeScript"); + +let s0: s = 1408; +Assert.equal(s0, 1408); \ No newline at end of file diff --git a/es2panda/test/ts_extra_tests/test_ts_cases/spec/basic_concepts/scopes/scopes_13_3.ts b/es2panda/test/ts_extra_tests/test_ts_cases/spec/basic_concepts/scopes/scopes_13_3.ts new file mode 100644 index 0000000000000000000000000000000000000000..0d15c523ccf532da23d1cbd428314cb54b236cca --- /dev/null +++ b/es2panda/test/ts_extra_tests/test_ts_cases/spec/basic_concepts/scopes/scopes_13_3.ts @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/**--- + description: > + When an identifier is resolved as a NamespaceName, only names in scope with a namespace meaning are considered and other names are ignored. + module: ESNext + isCurrent: true + ---*/ + + +import { Assert } from "../../../../suite/assert.js"; + +var f: boolean = false; +namespace f { + export interface f { + f: boolean; + } +} +Assert.equal(f, false); + +let f0: f.f = { f: true }; +Assert.equal(f0.f, true); + +type e = String; +namespace e { + export var e: number = -1; +} +let e0: e = 'NARC'; +Assert.equal(e0, 'NARC'); + +Assert.equal(e.e, -1); \ No newline at end of file diff --git a/es2panda/test/ts_extra_tests/test_ts_cases/spec/basic_concepts/scopes/scopes_14.ts b/es2panda/test/ts_extra_tests/test_ts_cases/spec/basic_concepts/scopes/scopes_14.ts new file mode 100644 index 0000000000000000000000000000000000000000..56e85d91abdfbd3beb0d088df6b68189bb1b45cc --- /dev/null +++ b/es2panda/test/ts_extra_tests/test_ts_cases/spec/basic_concepts/scopes/scopes_14.ts @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/**--- + description: > + locally declared entities in a namespace are closer in scope than exported entities declared in other namespace declarations for the same namespace. + isCurrent: true + ---*/ + + +import { Assert } from "../../../../suite/assert.js"; + +var i: number = -1; +namespace I { + export var i: number = 0; + Assert.equal(i, 0); +} +namespace I { + Assert.equal(i, 0); +} +namespace I { + var i: number = 1; + Assert.equal(i, 1); +} +Assert.equal(i, -1); +Assert.equal(I.i, 0); \ No newline at end of file diff --git a/es2panda/test/ts_extra_tests/test_ts_cases/spec/basic_concepts/scopes/scopes_2.ts b/es2panda/test/ts_extra_tests/test_ts_cases/spec/basic_concepts/scopes/scopes_2.ts new file mode 100644 index 0000000000000000000000000000000000000000..e265a38f587519bcaaee87411844e19e6e60f17e --- /dev/null +++ b/es2panda/test/ts_extra_tests/test_ts_cases/spec/basic_concepts/scopes/scopes_2.ts @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/**--- + description: > + The scope of a name declared in a module is the source file of that module. + module: ESNext + isCurrent: true + ---*/ + + +import { Assert } from "../../../../suite/assert.js"; + +import * as m from "./scopes_2_m.js"; +Assert.equal(m.m3, 1970); +Assert.equal(m.m4, 'EXP'); \ No newline at end of file diff --git a/es2panda/test/ts_extra_tests/test_ts_cases/spec/basic_concepts/scopes/scopes_2_m.ts b/es2panda/test/ts_extra_tests/test_ts_cases/spec/basic_concepts/scopes/scopes_2_m.ts new file mode 100644 index 0000000000000000000000000000000000000000..5f0e91b86d14d5b55c908d6ed2ddd654c286d651 --- /dev/null +++ b/es2panda/test/ts_extra_tests/test_ts_cases/spec/basic_concepts/scopes/scopes_2_m.ts @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/**--- + description: > + The scope of a name declared in a module is the source file of that module. + module: ESNext + isCurrent: true + ---*/ + + +import { Assert } from "../../../../suite/assert.js"; + +let m1 = 1969; +var m2 = 'XO'; +Assert.equal(m1, 1969); +Assert.equal(m2, 'XO'); +export let m3 = 1970; +export var m4 = 'EXP'; +Assert.equal(m3, 1970); +Assert.equal(m4, 'EXP'); \ No newline at end of file diff --git a/es2panda/test/ts_extra_tests/test_ts_cases/spec/basic_concepts/scopes/scopes_3.ts b/es2panda/test/ts_extra_tests/test_ts_cases/spec/basic_concepts/scopes/scopes_3.ts new file mode 100644 index 0000000000000000000000000000000000000000..bb2304400760eff641f290d3b6c48ff98f5f2b93 --- /dev/null +++ b/es2panda/test/ts_extra_tests/test_ts_cases/spec/basic_concepts/scopes/scopes_3.ts @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/**--- + description: > + The scope of an exported name declared within a namespace declaration is the body of that namespace declaration and every namespace declaration with the same root and the same qualified name relative to that root. + module: ESNext + isCurrent: true + ---*/ + + +import { Assert } from "../../../../suite/assert.js"; + +namespace X { + export var a: string = '404NotFound'; + export let b: number = 119; + export namespace Y { + export function pak() { + return { a, b }; + } + } +} +Assert.equal(X.a, '404NotFound'); +Assert.equal(X.b, 119); +Assert.equal(X.Y.pak().a, '404NotFound'); +Assert.equal(X.Y.pak().b, 119); \ No newline at end of file diff --git a/es2panda/test/ts_extra_tests/test_ts_cases/spec/basic_concepts/scopes/scopes_4.ts b/es2panda/test/ts_extra_tests/test_ts_cases/spec/basic_concepts/scopes/scopes_4.ts new file mode 100644 index 0000000000000000000000000000000000000000..4fdb88caf31242b8c66e8409a22923c733698283 --- /dev/null +++ b/es2panda/test/ts_extra_tests/test_ts_cases/spec/basic_concepts/scopes/scopes_4.ts @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/**--- + description: > + The scope of a non-exported name declared within a namespace declaration is the body of that namespace declaration. + module: ESNext + isCurrent: true + ---*/ + + +import { Assert } from "../../../../suite/assert.js"; + +namespace X { + var a: string = 'TypeScript'; + let b: number = 110; + export function assert() { + Assert.equal(a, 'TypeScript'); + Assert.equal(b, 110); + } +} +X.assert(); \ No newline at end of file diff --git a/es2panda/test/ts_extra_tests/test_ts_cases/spec/basic_concepts/scopes/scopes_5.ts b/es2panda/test/ts_extra_tests/test_ts_cases/spec/basic_concepts/scopes/scopes_5.ts new file mode 100644 index 0000000000000000000000000000000000000000..cfc5708d18f788d48cb9d15c2742190fa758b455 --- /dev/null +++ b/es2panda/test/ts_extra_tests/test_ts_cases/spec/basic_concepts/scopes/scopes_5.ts @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/**--- + description: > + The scope of a type parameter name declared in a class or interface declaration is that entire declaration, + including constraints, extends clause, implements clause, and declaration body, but not including static member declarations. + module: ESNext + isCurrent: true + ---*/ + + +import { Assert } from "../../../../suite/assert.js"; + +class C { + str: string = 'NAME'; + num: number = 333; + static flag: boolean = false; + fun() { + return [this.str, this.num, C.flag]; + } +} +let c = new C(); +Assert.equal(c.str, "NAME"); +Assert.equal(c.num, 333); +Assert.equal(C.flag, false); +interface I { + s: string; + n: number; +} +let i: I = { s: 'STR', n: 999 }; +Assert.equal(i.s, "STR"); +Assert.equal(i.n, 999); \ No newline at end of file diff --git a/es2panda/test/ts_extra_tests/test_ts_cases/spec/basic_concepts/scopes/scopes_6.ts b/es2panda/test/ts_extra_tests/test_ts_cases/spec/basic_concepts/scopes/scopes_6.ts new file mode 100644 index 0000000000000000000000000000000000000000..b59a10026932ec43b8b31045c43d18571d429b3c --- /dev/null +++ b/es2panda/test/ts_extra_tests/test_ts_cases/spec/basic_concepts/scopes/scopes_6.ts @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/**--- + description: > + The scope of a type parameter name declared in a type alias declaration is that entire type alias declaration. + module: ESNext + isCurrent: true + ---*/ + + +import { Assert } from "../../../../suite/assert.js"; + +type Tp = keyof T & keyof U; +let k: Tp = "toString"; +Assert.equal(k, "toString"); \ No newline at end of file diff --git a/es2panda/test/ts_extra_tests/test_ts_cases/spec/basic_concepts/scopes/scopes_7.ts b/es2panda/test/ts_extra_tests/test_ts_cases/spec/basic_concepts/scopes/scopes_7.ts new file mode 100644 index 0000000000000000000000000000000000000000..acb7c4447df47f06452d1c856dc265bef749f07d --- /dev/null +++ b/es2panda/test/ts_extra_tests/test_ts_cases/spec/basic_concepts/scopes/scopes_7.ts @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/**--- + description: > + The scope of a member name declared in an enum declaration is the body of that declaration and every enum declaration with the same root and the same qualified name relative to that root. + module: ESNext + isCurrent: true + ---*/ + + +import { Assert } from "../../../../suite/assert.js"; + +enum E1 { + a, b, c, +} +enum E2 { + a, b, c, +} +enum E1 { + d = 0, +} +Assert.equal(E1.a, 0); +Assert.equal(E2.a, 0); +Assert.equal(E1.d, 0); \ No newline at end of file diff --git a/es2panda/test/ts_extra_tests/test_ts_cases/spec/basic_concepts/scopes/scopes_8.ts b/es2panda/test/ts_extra_tests/test_ts_cases/spec/basic_concepts/scopes/scopes_8.ts new file mode 100644 index 0000000000000000000000000000000000000000..28cb75dab5324d44ba52b48a90ab0bcae0a6cb49 --- /dev/null +++ b/es2panda/test/ts_extra_tests/test_ts_cases/spec/basic_concepts/scopes/scopes_8.ts @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/**--- + description: > + The scope of a parameter name declared in a call or construct signature is the remainder of the signature declaration. + If the signature is part of a function-like declaration with a body (including a function declaration, constructor declaration, member function declaration, member accessor declaration, function expression, or arrow function), + the scope includes the body of that function-like declaration. + module: ESNext + isCurrent: true + ---*/ + + +import { Assert } from "../../../../suite/assert.js"; + +class CC { + a: number; b: number; + constructor(a: number, b: number) { + let c1: number = a + b; + let c2: number = a * b; + Assert.isNumber(c1); + Assert.isNumber(c2); + this.a = c1 + c2; + this.b = c2 - c1; + } +} +let cc = new CC(3, 5); +Assert.equal(cc.a, 23); +Assert.equal(cc.b, 7); \ No newline at end of file diff --git a/es2panda/test/ts_extra_tests/test_ts_cases/spec/basic_concepts/scopes/scopes_9.ts b/es2panda/test/ts_extra_tests/test_ts_cases/spec/basic_concepts/scopes/scopes_9.ts new file mode 100644 index 0000000000000000000000000000000000000000..2b736f6a3173f6845b7b70b440d682658d3762b5 --- /dev/null +++ b/es2panda/test/ts_extra_tests/test_ts_cases/spec/basic_concepts/scopes/scopes_9.ts @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/**--- + description: > + The scope of a local var or function name declared anywhere in the body of a function-like declaration is the body of that function-like declaration. + module: ESNext + isCurrent: true + ---*/ + + +import { Assert } from "../../../../suite/assert.js"; + +function sfun(x: number, y: number): number { + var a: number = x + y; + let b: number = x - y; + function subfun() { + return a * b; + } + return subfun(); +} +Assert.equal(sfun(3, 5), -16); \ No newline at end of file diff --git a/es2panda/test/ts_extra_tests/test_ts_cases/spec/basic_concepts/scopes/var_scope.ts b/es2panda/test/ts_extra_tests/test_ts_cases/spec/basic_concepts/scopes/var_scope.ts new file mode 100644 index 0000000000000000000000000000000000000000..ea58de6d9afeb5e92cbc625c800db0e49d55c2e2 --- /dev/null +++ b/es2panda/test/ts_extra_tests/test_ts_cases/spec/basic_concepts/scopes/var_scope.ts @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/**--- + description: The scope of a local var name declared anywhere in the body of a function-like declaration is the body of that function-like declaration. + module: ESNext + isCurrent: true + ---*/ + + +import { Assert } from '../../../../suite/assert.js' + +var GlobalScope = 1; +function someFunc() { + var FunctionScope = 2; + if (true) { + var BlockScope = 3; + } + Assert.equal(FunctionScope, 2); + Assert.equal(BlockScope, 3); +} +Assert.equal(GlobalScope, 1); +someFunc(); \ No newline at end of file