diff --git a/ets2panda/test/ast/compiler/ets/spec/14_ambient_declarations/ambientAccessModifier.ets b/ets2panda/test/ast/compiler/ets/spec/14_ambient_declarations/ambientAccessModifier.ets new file mode 100644 index 0000000000000000000000000000000000000000..03414fe4fc8f231452bff46702062f89fe60c0b5 --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/spec/14_ambient_declarations/ambientAccessModifier.ets @@ -0,0 +1,26 @@ +/* + * Copyright (c) 2025 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. + */ + +/** + * CHAPTER 14.3 + * ambientAccessModifier: + * 'public'|'protected' + * ; + */ + +declare class AmbientClass { + public static name: string; + protected static age: number; +} diff --git a/ets2panda/test/ast/compiler/ets/spec/14_ambient_declarations/ambientAccessorDeclaration.ets b/ets2panda/test/ast/compiler/ets/spec/14_ambient_declarations/ambientAccessorDeclaration.ets new file mode 100644 index 0000000000000000000000000000000000000000..90684675988e654392f46f656d62614dc9193af8 --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/spec/14_ambient_declarations/ambientAccessorDeclaration.ets @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2025 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. + */ + +/** + * CHAPTER 14.3 + * ambientAccessorDeclaration: + * ambientMethodModifier* + * ('get' identifier'('')'returnType + * |'set' identifier'('parameter')' + * ) + * ; + * + * ambientMethodModifier: + * 'static' + * ; + * + * identifier: Identifier; + * + * returnType: + * ':' type + * ; + */ + +declare class AmbientClass { + get name(): string; + set name(name: string); + static get age(): number; + static set age(age: number); +} diff --git a/ets2panda/test/ast/compiler/ets/spec/14_ambient_declarations/ambientClassBodyDeclaration.ets b/ets2panda/test/ast/compiler/ets/spec/14_ambient_declarations/ambientClassBodyDeclaration.ets new file mode 100644 index 0000000000000000000000000000000000000000..2b65dd3cea33feec28161777aa0c97f95dc39aa6 --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/spec/14_ambient_declarations/ambientClassBodyDeclaration.ets @@ -0,0 +1,105 @@ +/* + * Copyright (c) 2025 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. + */ + +/** + * CHAPTER 14.3 + * ambientClassBodyDeclaration: + * ambientAccessModifier? + * ( ambientFieldDeclaration + * | ambientConstructorDeclaration + * | ambientMethodDeclaration + * | ambientAccessorDeclaration + * | ambientIndexerDeclaration + * | ambientCallSignatureDeclaration + * | ambientIterableDeclaration + * ) + * ; + * + * ambientAccessModifier: + * 'public'|'protected' + * ; + * + * ambientFieldDeclaration: + * ambientFieldModifier* identifier':' type + * ; + * + * ambientConstructorDeclaration: + * 'constructor' parameters throwMark? + * ; + * + * ambientMethodDeclaration: + * ambientMethodModifier* identifier signature + * ; + * + * ambientAccessorDeclaration: + * ambientMethodModifier* + * ('get' identifier'('')'returnType + * |'set' identifier'('parameter')' + * ) + * ; + * + * ambientIndexerDeclaration: + * 'readonly'? '[' identifier ':' indexType ']' returnType + * ; + * + * ambientCallSignatureDeclaration: + * signature + * ; + * + * ambientIterableDeclaration: + * '[Symbol.iterator]' '(' ')' returnType + * ; + */ + +class CIterator implements Iterator { + index = 0 + base: AmbientClass1 + constructor(base: AmbientClass1) { + this.base = base + } + next(): IteratorResult { + return { + done: true, + value: undefined + } + } +} + +declare class AmbientClass1 { + public static name: string; + public constructor(); + public getName(): string; + public get name(): string; + public [index: number]: number; + public $_invoke(a: number): number; + public $_iterator(): CIterator; + + static age: number; + constructor(age: number); + getAge(): number; + get age(): number; +} + +declare class AmbientClass2 { + [index: number]: number; +} + +declare class AmbientClass3 { + $_invoke(a: number): number; +} + +declare class AmbientClass4 { + $_iterator(): CIterator; +} diff --git a/ets2panda/test/ast/compiler/ets/spec/14_ambient_declarations/ambientClassDeclaration.ets b/ets2panda/test/ast/compiler/ets/spec/14_ambient_declarations/ambientClassDeclaration.ets new file mode 100644 index 0000000000000000000000000000000000000000..4a44be54af69e0ddcb403889b6c2d409556dd7dd --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/spec/14_ambient_declarations/ambientClassDeclaration.ets @@ -0,0 +1,115 @@ +/* + * Copyright (c) 2025 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. + */ + +/** + * CHAPTER 14.3 + * ambientClassDeclaration: + * 'class' identifier typeParameters? + * classExtendsClause? implementsClause? + * '{' ambientClassBodyDeclaration* '}' + * ; + * + * identifier: Identifier; + * + * typeParameters: + * '<' typeParameterList '>' + * ; + * + * classExtendsClause: + * 'extends' typeReference + * ; + * + * implementsClause: + * 'implements' interfaceTypeList + * ; + * + * ambientClassBodyDeclaration: + * ambientAccessModifier? + * ( ambientFieldDeclaration + * | ambientConstructorDeclaration + * | ambientMethodDeclaration + * | ambientAccessorDeclaration + * | ambientIndexerDeclaration + * | ambientCallSignatureDeclaration + * | ambientIterableDeclaration + * ) + * ; + */ + +interface I1 { foo() {} } + +declare class AmbientClass1 { + static name: string; + readonly age: number; + static gender: string; +} + +declare class AmbientClass2 implements I1 { + static name: string; + readonly age: number; + static gender: string; +} + +declare class AmbientClass3 extends AmbientClass1 { + static name: string; + readonly age: number; + static gender: string; +} + +declare class AmbientClass4 extends AmbientClass2 implements I1 { + static name: string; + readonly age: number; + static gender: string; +} + +declare class AmbientClass5 { + static name: string; + readonly age: number; + static gender: T; +} + +declare class AmbientClass6 implements I1 { + static name: string; + readonly age: number; + static gender: T; +} + +declare class AmbientClass7 extends AmbientClass3 { + static name: string; + readonly age: number; + static gender: T; +} + +declare class AmbientClass8 extends AmbientClass1 implements I1 { + static name: string; + readonly age: number; + static gender: string; +} + +declare class AmbientClass9 {} + +declare class AmbientClass10 implements I1 {} + +declare class AmbientClass11 extends AmbientClass9 {} + +declare class AmbientClass12 extends AmbientClass10 implements I1 {} + +declare class AmbientClass13 {} + +declare class AmbientClass14 implements I1 {} + +declare class AmbientClass15 extends AmbientClass11 {} + +declare class AmbientClass16 extends AmbientClass9 implements I1 {} diff --git a/ets2panda/test/ast/compiler/ets/spec/14_ambient_declarations/ambientConstructorDeclaration.ets b/ets2panda/test/ast/compiler/ets/spec/14_ambient_declarations/ambientConstructorDeclaration.ets new file mode 100644 index 0000000000000000000000000000000000000000..ff461526c879e216367ae189bb8d579b05625d7e --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/spec/14_ambient_declarations/ambientConstructorDeclaration.ets @@ -0,0 +1,26 @@ +/* + * Copyright (c) 2025 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. + */ + +/** + * CHAPTER 14.3 + * ambientConstructorDeclaration: + * 'constructor' parameters throwMark? + * ; + */ + +declare class AmbientClass1 { + constructor(name: string); + constructor() throws; +} diff --git a/ets2panda/test/ast/compiler/ets/spec/14_ambient_declarations/ambientFieldDeclaration.ets b/ets2panda/test/ast/compiler/ets/spec/14_ambient_declarations/ambientFieldDeclaration.ets new file mode 100644 index 0000000000000000000000000000000000000000..408345505a6aafadbad2cb7a43d484ebf8b8e81c --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/spec/14_ambient_declarations/ambientFieldDeclaration.ets @@ -0,0 +1,51 @@ +/* + * Copyright (c) 2025 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. + */ + +/** + * CHAPTER 14.3 + * ambientFieldDeclaration: + * ambientFieldModifier* identifier':' type + * ; + * + * ambientFieldModifier: + * 'static'|'readonly' + * ; + * + * ambientMethodDeclaration: + * ambientMethodModifier* identifier signature + * ; + * + * identifier: Identifier; + * + * type: + * annotationUsage? + * ( typeReference + * |'readonly'? arrayType + * |'readonly'? tupleType + * | functionType + * | functionTypeWithReceiver + * | unionType + * | StringLiteral + * ) + * |'('type')' + * ; + */ + +declare class AmbientClass { + static name: string; + readonly age: number; + gender: string; + static readonly home: string; +} diff --git a/ets2panda/test/ast/compiler/ets/spec/14_ambient_declarations/ambientIndexerDeclaration.ets b/ets2panda/test/ast/compiler/ets/spec/14_ambient_declarations/ambientIndexerDeclaration.ets new file mode 100644 index 0000000000000000000000000000000000000000..e88e5e859538bf4274784767498cdfc031a65864 --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/spec/14_ambient_declarations/ambientIndexerDeclaration.ets @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2025 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. + */ + +/** + * CHAPTER 14.3.1 + * ambientIndexerDeclaration: + * 'readonly'? '[' identifier ':' indexType ']' returnType + * ; + * + * identifier: Identifier; + * + * indexType:'number'; + * + * returnType: + * ':' type + * ; + */ + +declare class AmbientClass1 { + [index: number]: number; +} + +declare class AmbientClass2 { + readonly [index: number]: number; +} diff --git a/ets2panda/test/ast/compiler/ets/spec/14_ambient_declarations/ambientInterfaceDeclaration.ets b/ets2panda/test/ast/compiler/ets/spec/14_ambient_declarations/ambientInterfaceDeclaration.ets new file mode 100644 index 0000000000000000000000000000000000000000..a79c99a669ea387966139aca7925b6e5299d4fa7 --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/spec/14_ambient_declarations/ambientInterfaceDeclaration.ets @@ -0,0 +1,67 @@ +/* + * Copyright (c) 2025 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. + */ + +/** + * CHAPTER 14.4 + * ambientInterfaceDeclaration: + * 'interface' identifier typeParameters? + * interfaceExtendsClause? + * '{' ambientInterfaceMember* '}' + * ; + * + * identifier: Identifier; + * + * typeParameters: + * '<' typeParameterList '>' + * ; + * + * interfaceExtendsClause: + * 'extends' interfaceTypeList + * ; + * + * ambientInterfaceMember + * : interfaceProperty + * | interfaceMethodDeclaration + * | ambientIndexerDeclaration + * | ambientCallSignatureDeclaration + * | ambientIterableDeclaration + * ; + */ + +interface InterfaceExample { foo() {} } + +declare interface AmbientInterface1 extends InterfaceExample { + method(param: T): void; +} + +declare interface AmbientInterface2 extends InterfaceExample { + method(param: string): void; +} + +declare interface AmbientInterface3 { + method(param: T): void; +} + +declare interface AmbientInterface4 { + method(param: string): void; +} + +declare interface AmbientInterface5 extends InterfaceExample {} + +declare interface AmbientInterface6 extends InterfaceExample {} + +declare interface AmbientInterface7 {} + +declare interface AmbientInterface8 {} diff --git a/ets2panda/test/ast/compiler/ets/spec/14_ambient_declarations/ambientInterfaceMember.ets b/ets2panda/test/ast/compiler/ets/spec/14_ambient_declarations/ambientInterfaceMember.ets new file mode 100644 index 0000000000000000000000000000000000000000..ad44729532885ceb2b0b6aaf588197cbbbb24088 --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/spec/14_ambient_declarations/ambientInterfaceMember.ets @@ -0,0 +1,56 @@ +/* + * Copyright (c) 2025 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. + */ + +/** + * CHAPTER 14.4 + * ambientInterfaceMember + * : interfaceProperty + * | interfaceMethodDeclaration + * | ambientIndexerDeclaration + * | ambientCallSignatureDeclaration + * | ambientIterableDeclaration + * ; + * + * interfaceProperty: + * 'readonly'? identifier '?'? ':' type + * | 'get' identifier '(' ')' returnType + * | 'set' identifier '(' parameter ')' + * ; + * + * interfaceMethodDeclaration: + * identifier signature + * | interfaceDefaultMethodDeclaration + * ; + * + * ambientIndexerDeclaration: + * 'readonly'? '[' identifier ':' indexType ']' returnType + * ; + * + * ambientCallSignatureDeclaration: + * signature + * ; + * + * ambientIterableDeclaration: + * '[Symbol.iterator]' '(' ')' returnType + * ; + */ + +interface CIterator { foo() {} } + +declare interface AmbientInterface { + name: string; + getName(): string; + $_invoke(a: number): number; +} diff --git a/ets2panda/test/ast/compiler/ets/spec/14_ambient_declarations/ambientMethodDeclaration.ets b/ets2panda/test/ast/compiler/ets/spec/14_ambient_declarations/ambientMethodDeclaration.ets new file mode 100644 index 0000000000000000000000000000000000000000..acfa1ba86dc516845bb6d24e9bc28840be85cc71 --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/spec/14_ambient_declarations/ambientMethodDeclaration.ets @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2025 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. + */ + +/** + * CHAPTER 14.3 + * ambientMethodDeclaration: + * ambientMethodModifier* identifier signature + * ; + * + * ambientMethodModifier: + * 'static' + * ; + * + * identifier: Identifier; + * + * signature: + * '(' parameterList? ')' returnType? + * ; + */ + +declare class AmbientClass { + getName(): number; + static getAge(): number; +} diff --git a/ets2panda/test/ast/compiler/ets/spec/14_ambient_declarations/ambientNamespaceDeclaration.ets b/ets2panda/test/ast/compiler/ets/spec/14_ambient_declarations/ambientNamespaceDeclaration.ets new file mode 100644 index 0000000000000000000000000000000000000000..dbe171bf9418502a96f283286b17400f78de35e5 --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/spec/14_ambient_declarations/ambientNamespaceDeclaration.ets @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2025 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. + */ + +/** + * CHAPTER 14.5 + * ambientNamespaceDeclaration: + * 'namespace' identifier'{'ambientNamespaceElement* '}' + * ; + * + * identifier: Identifier; + * + * ambientNamespaceElement: + * ambientNamespaceElementDeclaration | selectiveExportDirective + * ; + */ + +declare namespace MyNamespace1 {} + +declare namespace MyNamespace2 { + const namespaceElem1: number; + function namespaceElem2(x:number): void; + class namespaceElem3 {} +} diff --git a/ets2panda/test/ast/compiler/ets/spec/14_ambient_declarations/ambientNamespaceElement.ets b/ets2panda/test/ast/compiler/ets/spec/14_ambient_declarations/ambientNamespaceElement.ets new file mode 100644 index 0000000000000000000000000000000000000000..30ca45b0935e716926c64ffcdb651eec317034bd --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/spec/14_ambient_declarations/ambientNamespaceElement.ets @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2025 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. + */ + +/** + * CHAPTER 14.5 + * ambientNamespaceElement: + * ambientNamespaceElementDeclaration | selectiveExportDirective + * ; + * + * ambientNamespaceElementDeclaration: + * 'export'? + * ( ambientConstantDeclaration + * | ambientFunctionDeclaration + * | ambientClassDeclaration + * | ambientInterfaceDeclaration + * | ambientNamespaceDeclaration + * |'const'?enumDeclaration + * | typeAlias + * ) + * ; + * + * selectiveExportDirective: + * 'export' selectiveBindings + * ; + */ + +declare namespace MyNamespace { + interface namespaceElem1 {} + namespace namespaceElem2 {} + export {namespaceElem1, namespaceElem2} +} diff --git a/ets2panda/test/ast/compiler/ets/spec/14_ambient_declarations/ambientNamespaceElementDeclaration.ets b/ets2panda/test/ast/compiler/ets/spec/14_ambient_declarations/ambientNamespaceElementDeclaration.ets new file mode 100644 index 0000000000000000000000000000000000000000..c3fd83b53d59045ee969de3e064edb6c1d91b4c5 --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/spec/14_ambient_declarations/ambientNamespaceElementDeclaration.ets @@ -0,0 +1,82 @@ +/* + * Copyright (c) 2025 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. + */ + +/** + * CHAPTER 14.5 + * ambientNamespaceElementDeclaration: + * 'export'? + * ( ambientConstantDeclaration + * | ambientFunctionDeclaration + * | ambientClassDeclaration + * | ambientInterfaceDeclaration + * | ambientNamespaceDeclaration + * |'const'?enumDeclaration + * | typeAlias + * ) + * ; + * + * ambientConstantDeclaration: + * 'const' ambientConstList';' + * ; + * + * ambientFunctionDeclaration: + * 'function'identifier + * typeParameters?signature + * ; + * + * ambientClassDeclaration: + * 'class' identifier typeParameters? + * classExtendsClause? implementsClause? + * '{' ambientClassBodyDeclaration* '}' + * ; + * + * ambientInterfaceDeclaration: + * 'interface' identifier typeParameters? + * interfaceExtendsClause? + * '{' ambientInterfaceMember* '}' + * ; + * + * ambientNamespaceDeclaration: + * 'namespace' identifier'{'ambientNamespaceElement* '}' + * ; + * + * enumDeclaration: + * 'const'? 'enum' identifier '{' enumConstantList '}' + * ; + * + * typeAlias: + * 'type' identifier typeParameters?'='type + * ; + */ + +declare namespace MyNamespace { + const namespaceElem1: number; + function namespaceElem2(x:number): void; + class namespaceElem3 {} + interface namespaceElem4 {} + namespace namespaceElem5 {} + enum namespaceElem6 { Red, Green, Blue } + const enum namespaceElem7 { Mon, Tue, Wed } + type namespaceElem8 = number; + + export const namespaceElem9: number; + export function namespaceElem10(x:number): void; + export class namespaceElem11 {} + export interface namespaceElem12 {} + export namespace namespaceElem13 {} + export enum namespaceElem14 { Red, Green, Blue } + export const enum namespaceElem15 { Mon, Tue, Wed } + export type namespaceElem16 = number; +} diff --git a/ets2panda/test/ast/compiler/ets/spec/17_experimental_features/AwaitExpression.ets b/ets2panda/test/ast/compiler/ets/spec/17_experimental_features/AwaitExpression.ets new file mode 100644 index 0000000000000000000000000000000000000000..abc89d7dd747998075937cc45277d44c57ff38ea --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/spec/17_experimental_features/AwaitExpression.ets @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2025 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. + */ + +/** + * CHAPTER 17.16.2 + * awaitExpression: + * 'await' expression + * ; + */ + +function foo() {} +let promise = launch foo(); +await promise; diff --git a/ets2panda/test/ast/compiler/ets/spec/17_experimental_features/FunctionTypeWithReceiver.ets b/ets2panda/test/ast/compiler/ets/spec/17_experimental_features/FunctionTypeWithReceiver.ets new file mode 100644 index 0000000000000000000000000000000000000000..b22fb7252cf2813cb5a88e23667afbe46d5752b3 --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/spec/17_experimental_features/FunctionTypeWithReceiver.ets @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2025 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. + */ + +/** + * CHAPTER 17.12.4 + * functionTypeWithReceiver: + * '(' receiverParameter(','ftParameterList)?')'ftReturnType + * ; + * + * CHAPTER 3.19 + * ftParameterList: + * ftParameter (',' ftParameter)* (',' ftRestParameter)? + * | ftRestParameter + * ; + * + * CHAPTER 3.19 + * ftReturnType: + * '=>'type + * ; + */ + +class A {} + +type FA = (this: A) => boolean; + +type FN = (this: A, max: number) => number; diff --git a/ets2panda/test/ast/compiler/ets/spec/17_experimental_features/FunctionWithReceiverDeclaration.ets b/ets2panda/test/ast/compiler/ets/spec/17_experimental_features/FunctionWithReceiverDeclaration.ets new file mode 100644 index 0000000000000000000000000000000000000000..27a7ccc15eb1fd557df9d3f06fa06a90cefe59a6 --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/spec/17_experimental_features/FunctionWithReceiverDeclaration.ets @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2025 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. + */ + +/** + * CHAPTER 17.12.1 + * functionWithReceiverDeclaration: + * 'function' identifier typeParameters? signatureWithReceiver block + * ; + * + * signatureWithReceiver: + * '(' receiverParameter (', ' parameterList)? ')' returnType? throwMark? + * ; + * + * receiverParameter: + * annotationUsage? 'this' ':' type + * ; + */ + +class A {} + +function fooOne(this: A) {} + +function fooTwo(this: A) {} diff --git a/ets2panda/test/ast/compiler/ets/spec/17_experimental_features/LambdaExpressionWithReceiver.ets b/ets2panda/test/ast/compiler/ets/spec/17_experimental_features/LambdaExpressionWithReceiver.ets new file mode 100644 index 0000000000000000000000000000000000000000..264e17464a47acde2c84385c900ce1ee222ce75a --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/spec/17_experimental_features/LambdaExpressionWithReceiver.ets @@ -0,0 +1,75 @@ +/* + * Copyright (c) 2025 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. + */ + +/** + * CHAPTER 17.12.5 + * lambdaExpressionWithReceiver: + * annotationUsage? typeParameters? + * '(' receiverParameter(','lambdaParameterList)?')' + * returnType? throwMark?'=>' lambdaBody + * ; + * + * CHAPTER 17.12.1 + * receiverParameter: + * annotationUsage? 'this' ':' type + * ; + * + * CHAPTER 7.32 + * lambdaParameterList: + * lambdaParameter(','lambdaParameter)* (','restParameter)?','? + * | restParameter','? + * ; + * + * lambdaBody: + * expression | block + * ; + */ + +class A {} + +@Retention("SOURCE") +@interface MyAnnotation {} + +let result1 = (this: A) => {}; + +let result2 = @MyAnnotation (this: A) => {}; + +let result3 = (this: A, x: number) => {}; + +let result4 = (this: A): number => { return 0; }; + +let result5 = (this: A) throws => {}; + +let result6 = @MyAnnotation (this: A, x: number) => {}; + +let result7 = @MyAnnotation (this: A): number => { return 0; }; + +let result8 = @MyAnnotation (this: A) throws => {}; + +let result9 = (this: A, x: number): number => { return 0; }; + +let result10 = (this: A, x: number) throws => {}; + +let result11 = (this: A): number throws => { return 0; }; + +let result12 = @MyAnnotation (this: A, x: number): number => { return 0; }; + +let result13 = @MyAnnotation (this: A, x: number) throws => {}; + +let result14 = @MyAnnotation (this: A): number throws => { return 0; }; + +let result15 = (this: A, x: number): number throws => { return 0; }; + +let result16 = @MyAnnotation (this: A, x: number): number throws => { return 0; }; diff --git a/ets2panda/test/ast/compiler/ets/spec/17_experimental_features/PackageModuleDeclaration/ImportDirective.ets b/ets2panda/test/ast/compiler/ets/spec/17_experimental_features/PackageModuleDeclaration/ImportDirective.ets new file mode 100644 index 0000000000000000000000000000000000000000..d5c0c667ddf3fa43141e80d66f39a3b68ba3f986 --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/spec/17_experimental_features/PackageModuleDeclaration/ImportDirective.ets @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2025 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. + */ + +/** + * CHAPTER 17.19 + * packageModuleDeclaration: + * importDirective* packageTopDeclaration* + * ; + * + * packageTopDeclaration: + * topDeclaration | initializerBlock + * ; + * + * packageModule: + * packageHeader packageModuleDeclaration + * ; + */ + +package myPackage; + +import { A } from "../PrepareForImportDirective"; +import { B } from "../PrepareForImportDirective"; +import { fooOne } from "../PrepareForImportDirective"; diff --git a/ets2panda/test/ast/compiler/ets/spec/17_experimental_features/PackageModuleDeclaration/ImportDirectivePackageTopDeclaration.ets b/ets2panda/test/ast/compiler/ets/spec/17_experimental_features/PackageModuleDeclaration/ImportDirectivePackageTopDeclaration.ets new file mode 100644 index 0000000000000000000000000000000000000000..f26e372925b46220ec5aacaec2b374528c503c51 --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/spec/17_experimental_features/PackageModuleDeclaration/ImportDirectivePackageTopDeclaration.ets @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2025 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. + */ + +/** + * CHAPTER 17.19 + * packageModuleDeclaration: + * importDirective* packageTopDeclaration* + * ; + * + * packageTopDeclaration: + * topDeclaration | initializerBlock + * ; + * + * packageModule: + * packageHeader packageModuleDeclaration + * ; + */ + +package myPackage; + +import { fooTwo } from "../PrepareForImportDirective"; +import { fooThree } from "../PrepareForImportDirective"; +import { C } from "../PrepareForImportDirective"; + +let a = 1; +let b = 2; +let c = 3; diff --git a/ets2panda/test/ast/compiler/ets/spec/17_experimental_features/PackageModuleDeclaration/PackageTopDeclaration.ets b/ets2panda/test/ast/compiler/ets/spec/17_experimental_features/PackageModuleDeclaration/PackageTopDeclaration.ets new file mode 100644 index 0000000000000000000000000000000000000000..45063a05d19781b6207effaf8348c2c59c9bdb5d --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/spec/17_experimental_features/PackageModuleDeclaration/PackageTopDeclaration.ets @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2025 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. + */ + +/** + * CHAPTER 17.19 + * packageModuleDeclaration: + * importDirective* packageTopDeclaration* + * ; + * + * packageTopDeclaration: + * topDeclaration | initializerBlock + * ; + * + * packageModule: + * packageHeader packageModuleDeclaration + * ; + */ + +package myPackage; + +let example1 = 13; +let example2 = 22; +let example3 = 35; +let example4 = 40; diff --git a/ets2panda/test/ast/compiler/ets/spec/17_experimental_features/PackageTopDeclaration.ets b/ets2panda/test/ast/compiler/ets/spec/17_experimental_features/PackageTopDeclaration.ets new file mode 100644 index 0000000000000000000000000000000000000000..0b4ab75ee683bebcfed38378cecc9ed8db8b066f --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/spec/17_experimental_features/PackageTopDeclaration.ets @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2025 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. + */ + +/** + * CHAPTER 17.19 + * packageTopDeclaration: + * topDeclaration | initializerBlock + * ; + * + * packageModuleDeclaration: + * importDirective* packageTopDeclaration* + * ; + */ + +package myPackage; + +let a = 1; + +class ExampleClass { + static initialized = false; + static initializerBlock() { + if (!ExampleClass.initialized) { + ExampleClass.initialized = true; + } + } +} diff --git a/ets2panda/test/ast/compiler/ets/spec/17_experimental_features/PrepareForImportDirective.ets b/ets2panda/test/ast/compiler/ets/spec/17_experimental_features/PrepareForImportDirective.ets new file mode 100644 index 0000000000000000000000000000000000000000..812953d36323a7654ea75f593d7ff94cb3165874 --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/spec/17_experimental_features/PrepareForImportDirective.ets @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2025 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. + */ + +/** + * This file provides the relevant export files + * for the ImportDirective file in the PackageModuleDeclaration folder + */ + +class A {} +class B {} +class C {} + +function fooOne(this: A) {} +function fooTwo(this: A) {} +function fooThree(this: A) {} + +export A; +export B; +export C; +export fooOne; +export fooTwo; +export fooThree; diff --git a/ets2panda/test/ast/compiler/ets/spec/17_experimental_features/ReceiverParameter.ets b/ets2panda/test/ast/compiler/ets/spec/17_experimental_features/ReceiverParameter.ets new file mode 100644 index 0000000000000000000000000000000000000000..2cfeae501e394e31797ff378f5af1d7d30c018b9 --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/spec/17_experimental_features/ReceiverParameter.ets @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2025 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. + */ + +/** + * CHAPTER 17.12.1 + * receiverParameter: + * annotationUsage? 'this' ':' type + * ; + * + * signatureWithReceiver: + * '(' receiverParameter (', ' parameterList)? ')' returnType? throwMark? + * ; + * + * functionWithReceiverDeclaration: + * 'function' identifier typeParameters? signatureWithReceiver block + * ; + */ + +@interface ClassPreamble { + revision: number; +} + +class A {} + +function fooOne(@ClassPreamble({ revision: 2 }) this: A) {} + +function fooTwo(this: A) {} diff --git a/ets2panda/test/ast/compiler/ets/spec/17_experimental_features/SignatureWithReceiver.ets b/ets2panda/test/ast/compiler/ets/spec/17_experimental_features/SignatureWithReceiver.ets new file mode 100644 index 0000000000000000000000000000000000000000..c1624f6af2dfad1dfe741d05de7fbc57b0c27e73 --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/spec/17_experimental_features/SignatureWithReceiver.ets @@ -0,0 +1,47 @@ +/* + * Copyright (c) 2025 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. + */ + +/** + * CHAPTER 17.12.1 + * signatureWithReceiver: + * '(' receiverParameter (', ' parameterList)? ')' returnType? throwMark? + * ; + * + * functionWithReceiverDeclaration: + * 'function' identifier typeParameters? signatureWithReceiver block + * ; + * + * receiverParameter: + * annotationUsage? 'this' ':' type + * ; + */ + +class A {} + +function fooOne(this: A) {} + +function fooTwo(this: A, n: number) {} + +function fooThree(this: A): void {} + +function fooFour(this: A) throws {} + +function fooFive(this: A, n: number): void {} + +function fooSix(this: A, n: number) throws {} + +function fooSeven(this: A): void throws {} + +function fooEight(this: A, n: number): void throws {} diff --git a/ets2panda/test/ast/compiler/ets/spec/17_experimental_features/SingleQuoteCharacterError.ets b/ets2panda/test/ast/compiler/ets/spec/17_experimental_features/SingleQuoteCharacterError.ets new file mode 100644 index 0000000000000000000000000000000000000000..82f45e31feeb1669c15ad2aa3b79abf4a4a27929 --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/spec/17_experimental_features/SingleQuoteCharacterError.ets @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2025 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. + */ + +/** +* CHAPTER 17.1.1 +* SingleQuoteCharacter: +* ~['\\\r\n] +* | '\\' EscapeSequence +* ; +* +* CharLiteral: +* 'c\'' SingleQuoteCharacter '\'' +* ; +* +*/ + +c'\''; +c'\\'; +c'\r'; +c'\n' diff --git a/ets2panda/test/ast/compiler/ets/spec/17_experimental_features/TrailingLambdaCall.ets b/ets2panda/test/ast/compiler/ets/spec/17_experimental_features/TrailingLambdaCall.ets new file mode 100644 index 0000000000000000000000000000000000000000..0edf6b7bf780da8bae8d395d967c0f83fb5257a3 --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/spec/17_experimental_features/TrailingLambdaCall.ets @@ -0,0 +1,69 @@ +/* + * Copyright (c) 2025 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. + */ + +/** + * CHAPTER 17.13 + * trailingLambdaCall: + * ( objectReference '.' identifier typeArguments? + * | expression ('?.' | typeArguments)? + * ) + * arguments block + * ; + * + * CHAPTER 6.5.14 + * objectReference: + * typeReference + * |'super' + * | primaryExpression + * ; + * + * CHAPTER 5.2.1 + * typeArguments: + * '<' type(','type)* '>' + * ; + */ + +class A { + methodOne(callback: () => void): void { + callback(); + } + methodTwo(arg: T, callback: (result: T) => void): void { + const result = arg; + callback(result); + } +} + +let a = new A(); + +a.methodOne() {} + +a.methodTwo("Hi") {} + +function add(x: number, y: number, callback: (result: number) => void) { + const result = x + y; + callback(result); + return result; +} + +function put(x: string, callback: (result: string) => void): void { + const result = x; + callback(result); +} + +add(1, 2) {} + +a?.methodOne() {} + +put("Hello") {} diff --git a/ets2panda/test/ast/compiler/ets/spec/17_experimental_features/arrayElementType.ets b/ets2panda/test/ast/compiler/ets/spec/17_experimental_features/arrayElementType.ets new file mode 100644 index 0000000000000000000000000000000000000000..61971b0fc94865765a00d78b758a121b18d5f9ab --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/spec/17_experimental_features/arrayElementType.ets @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2025 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. + */ + +/** + * CHAPTER 17.3 + * arrayElementType: + * typeReference + * | '(' type ')' + * ; + */ + +let a = new string[1]; + +type STR = string; +let b = new (STR)[2][2]; diff --git a/ets2panda/test/ast/compiler/ets/spec/17_experimental_features/characterLiterals.ets b/ets2panda/test/ast/compiler/ets/spec/17_experimental_features/characterLiterals.ets new file mode 100644 index 0000000000000000000000000000000000000000..30210783c2c59305b2c69a906eae94634ae3694f --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/spec/17_experimental_features/characterLiterals.ets @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2025 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. + */ + +/** + * CHAPTER 17.1.1 + * CharLiteral: + * 'c\'' SingleQuoteCharacter '\'' + * ; + * + * SingleQuoteCharacter: + * ~['\\\r\n] + * | '\\' EscapeSequence + * ; + */ + +c'a' +c'\n' diff --git a/ets2panda/test/ast/compiler/ets/spec/17_experimental_features/interfaceDefaultMethodDeclaration.ets b/ets2panda/test/ast/compiler/ets/spec/17_experimental_features/interfaceDefaultMethodDeclaration.ets new file mode 100644 index 0000000000000000000000000000000000000000..ded8ee719946a56750e56716bc7bbfe566cfe860 --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/spec/17_experimental_features/interfaceDefaultMethodDeclaration.ets @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2025 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. + */ + +/** + * CHAPTER 17.11 + * interfaceDefaultMethodDeclaration: + * 'private'? identifier signature block + * ; + */ + +interface fool { + private priMethod(): void {} + + pubMethod(): void {} +} diff --git a/ets2panda/test/ast/compiler/ets/spec/17_experimental_features/newArrayInstance.ets b/ets2panda/test/ast/compiler/ets/spec/17_experimental_features/newArrayInstance.ets new file mode 100644 index 0000000000000000000000000000000000000000..2c66a79c11890f1217deed3b027763afb651846e --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/spec/17_experimental_features/newArrayInstance.ets @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2025 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. + */ + +/** + * CHAPTER 17.3 + * newArrayInstance: + * 'new' arrayElementType dimensionExpression+ (arrayElement)? + * ; + * + * arrayElementType: + * typeReference + * | '(' type ')' + * ; + * + * dimensionExpression: + * '[' expression ']' + * ; + * + * arrayElement: + * '(' expression ')' + * ; + */ + +let a = new string[1]; +a[0] = "a"; + +let b = new number[2][2]; +b[0][0] = 1; + +let c = new string[1]; + +let d = new number[2][2]; diff --git a/ets2panda/test/ast/compiler/ets/spec/18_annotations/AmbientAnnotationDeclaration.ets b/ets2panda/test/ast/compiler/ets/spec/18_annotations/AmbientAnnotationDeclaration.ets new file mode 100644 index 0000000000000000000000000000000000000000..e3a36b86fd5662f74e97b61d5d7c70f0eb36834a --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/spec/18_annotations/AmbientAnnotationDeclaration.ets @@ -0,0 +1,23 @@ +/* + * Copyright (c) 2025 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. + */ + +/** + * CHAPTER 18.4 + * ambientAnnotationDeclaration: + * 'declare' annotationDeclaration + * ; + */ + +export declare @interface NameAnno { name: string = "" }; diff --git a/ets2panda/test/ast/compiler/ets/spec/18_annotations/AnnotationDeclaration.ets b/ets2panda/test/ast/compiler/ets/spec/18_annotations/AnnotationDeclaration.ets new file mode 100644 index 0000000000000000000000000000000000000000..5e0c1285def2086fa8387f75a85a397abb30f9fc --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/spec/18_annotations/AnnotationDeclaration.ets @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2025 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. + */ + +/** + * CHAPTER 18.1 + * annotationDeclaration: + * '@interface' identifier '{' annotationField* '}' + * ; + */ + +@interface MyAnnotation { + name: string; + value: number = 10; +}; + +@interface MyAnnotation1 {}; diff --git a/ets2panda/test/ast/compiler/ets/spec/18_annotations/AnnotationField.ets b/ets2panda/test/ast/compiler/ets/spec/18_annotations/AnnotationField.ets new file mode 100644 index 0000000000000000000000000000000000000000..65fe90a06cd1242a28d90f96bd253417c53f4a38 --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/spec/18_annotations/AnnotationField.ets @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2025 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. + */ + +/** + * CHAPTER 18.1 + * annotationField: + * identifier ':' type constInitializer? + * ; + * + * constInitializer: + * '=' constantExpression + * ; + */ + +@interface MyAnnotation2 { + fieldWithoutDefault: string; +}; + +@interface MyAnnotation3 { + fieldWithDefault: number = 42; +}; diff --git a/ets2panda/test/ast/compiler/ets/spec/18_annotations/AnnotationUsage.ets b/ets2panda/test/ast/compiler/ets/spec/18_annotations/AnnotationUsage.ets new file mode 100644 index 0000000000000000000000000000000000000000..4f8fe04a922c726acd60cb5ed791ae6ddfc361d5 --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/spec/18_annotations/AnnotationUsage.ets @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2025 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. + */ + +/** + * CHAPTER 18.2 + * annotationUsage: + * '@' qualifiedName annotationValues? + * ; + */ + +@interface SimpleAnnotation {} +@SimpleAnnotation +class MyClass {}; + +@interface DetailedAnnotation { + authorName: string; + creationDate: string; +} +@DetailedAnnotation({ + authorName: "张三", + creationDate: "2025-03-19" +}) +class DocumentedClass {}; diff --git a/ets2panda/test/ast/compiler/ets/spec/18_annotations/AnnotationValues.ets b/ets2panda/test/ast/compiler/ets/spec/18_annotations/AnnotationValues.ets new file mode 100644 index 0000000000000000000000000000000000000000..12ca6cff49f907c9f3dbc5251988b0c5398653ad --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/spec/18_annotations/AnnotationValues.ets @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2025 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. + */ + +/** + * CHAPTER 18.2 + * annotationValues: + * '(' (objectLiteral | constantExpression)? ')' + * ; + */ + +@interface AuthorInfo { + name: string; + email: string; +} +@AuthorInfo({ + name: "李四", + email: "lisi@example.com" +}) +class Book {}; + +@interface Version { + versionNumber: number; +} +@Version(1) +class Software {}; + +@interface Deprecated {} +@Deprecated() +class OldClass {}; diff --git a/ets2panda/test/ast/compiler/ets/spec/2_lexical_elements/BacktickCharacterError.ets b/ets2panda/test/ast/compiler/ets/spec/2_lexical_elements/BacktickCharacterError.ets new file mode 100644 index 0000000000000000000000000000000000000000..bb76998b9d9f8e5a89b56b12b38b3ee9b6d735f0 --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/spec/2_lexical_elements/BacktickCharacterError.ets @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2025 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. + */ + +/** + * CHAPTER 2.9.7 + * BacktickCharacter: + * ~['\\\r\n] + * | '\\' EscapeSequence + * | LineContinuation + * ; + */ + +`\` + +/* @@? 28:1 Error SyntaxError: Unexpected token, expected '`' */ +/* @@? 28:1 Error SyntaxError: Unterminated string */ +/* @@? 28:1 Error SyntaxError: Unexpected token, expected '${' or '`' */ +/* @@? 28:1 Error SyntaxError: Unexpected token, expected '`' */ diff --git a/ets2panda/test/ast/compiler/ets/spec/2_lexical_elements/DoubleQuoteCharacterError.ets b/ets2panda/test/ast/compiler/ets/spec/2_lexical_elements/DoubleQuoteCharacterError.ets new file mode 100644 index 0000000000000000000000000000000000000000..bd82623129ece4110b483ee91ac950a00b08a580 --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/spec/2_lexical_elements/DoubleQuoteCharacterError.ets @@ -0,0 +1,26 @@ +/* + * Copyright (c) 2025 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. + */ + +/** + * CHAPTER 2.9.6 + * DoubleQuoteCharacter: + * ~["\\\r\n] + * | '\\' EscapeSequence + * ; + */ + +"\"/* @@ label */ + +/* @@@ label Error SyntaxError: Newline is not allowed in strings */ diff --git a/ets2panda/test/ast/compiler/ets/spec/2_lexical_elements/EscapeSequenceError.ets b/ets2panda/test/ast/compiler/ets/spec/2_lexical_elements/EscapeSequenceError.ets new file mode 100644 index 0000000000000000000000000000000000000000..0efb3f83437642e8512c1c42832ab2cafbf5ec32 --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/spec/2_lexical_elements/EscapeSequenceError.ets @@ -0,0 +1,73 @@ +/* + * Copyright (c) 2025 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. + */ + +/** + * CHAPTER 2.9.6 + * EscapeSequence: + * ['"bfnrtv0\\] + * | 'x' HexDigit HexDigit + * | 'u' HexDigit HexDigit HexDigit HexDigit + * | 'u' '{' HexDigit+ '}' + * | ~[1-9xu\r\n] + * ; + */ + +"\/* @@ label */1"; +"\/* @@ label1 */2"; +"\/* @@ label2 */3"; +"\/* @@ label3 */4"; +"\/* @@ label4 */5"; +"\/* @@ label5 */6"; +"\/* @@ label6 */7"; +"\/* @@ label7 */8"; +"\/* @@ label8 */9"; +"\x"/* @@ label9 */;/* @@ label10 */ +"\u"; +"\\n";/* @@ label11 */ +"\\r";/* @@ label12 */ +'\1';/* @@ label13 */ +'\2';/* @@ label14 */ +'\3';/* @@ label15 */ +'\4';/* @@ label16 */ +'\5';/* @@ label17 */ +'\6';/* @@ label18 */ +'\7';/* @@ label19 */ +'\8'; +'\9'; +'\x'; +'\u'; +'\\n'; +'\\r'; + +/* @@@ label Error SyntaxError: Invalid character escape sequence */ +/* @@@ label1 Error SyntaxError: Invalid character escape sequence */ +/* @@@ label2 Error SyntaxError: Invalid character escape sequence */ +/* @@@ label3 Error SyntaxError: Invalid character escape sequence */ +/* @@@ label4 Error SyntaxError: Invalid character escape sequence */ +/* @@@ label5 Error SyntaxError: Invalid character escape sequence */ +/* @@@ label6 Error SyntaxError: Invalid character escape sequence */ +/* @@@ label7 Error SyntaxError: Invalid character escape sequence */ +/* @@@ label8 Error SyntaxError: Invalid character escape sequence */ +/* @@@ label9 Error SyntaxError: Invalid unicode escape sequence */ +/* @@@ label10 Error SyntaxError: Newline is not allowed in strings */ +/* @@@ label1 Error SyntaxError: Invalid character escape sequence */ +/* @@@ label2 Error SyntaxError: Invalid character escape sequence */ +/* @@@ label3 Error SyntaxError: Invalid character escape sequence */ +/* @@@ label4 Error SyntaxError: Invalid character escape sequence */ +/* @@@ label5 Error SyntaxError: Invalid character escape sequence */ +/* @@@ label6 Error SyntaxError: Invalid character escape sequence */ +/* @@@ label7 Error SyntaxError: Invalid character escape sequence */ +/* @@@ label8 Error SyntaxError: Invalid character escape sequence */ +/* @@@ label9 Error SyntaxError: Invalid character escape sequence */ diff --git a/ets2panda/test/ast/compiler/ets/spec/2_lexical_elements/SingleQuoteCharacterError.ets b/ets2panda/test/ast/compiler/ets/spec/2_lexical_elements/SingleQuoteCharacterError.ets new file mode 100644 index 0000000000000000000000000000000000000000..66a1269457bf103bd67d7871a05ed7aee72509fb --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/spec/2_lexical_elements/SingleQuoteCharacterError.ets @@ -0,0 +1,26 @@ +/* + * Copyright (c) 2025 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. + */ + +/** + * CHAPTER 2.9.6 + * SingleQuoteCharacter: + * ~['\\\r\n] + * | '\\' EscapeSequence + * ; + */ + +'\'/* @@ label */ + +/* @@@ label Error SyntaxError: Newline is not allowed in strings */ diff --git a/ets2panda/test/ast/compiler/ets/spec/7_expressions/ArrayLiteral.ets b/ets2panda/test/ast/compiler/ets/spec/7_expressions/ArrayLiteral.ets new file mode 100644 index 0000000000000000000000000000000000000000..9253653bd508574c4a6fc13e066a1b8dc8d88c3e --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/spec/7_expressions/ArrayLiteral.ets @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2025 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. + */ + +/** + * CHAPTER 7.4 + * arrayLiteral: + * '[' expressionSequence? ']' + * ; + */ + +let x1 = [1, 2, 3]; + +let x2 = []; diff --git a/ets2panda/test/ast/compiler/ets/spec/7_expressions/ExpressionSequence.ets b/ets2panda/test/ast/compiler/ets/spec/7_expressions/ExpressionSequence.ets new file mode 100644 index 0000000000000000000000000000000000000000..baba105b732080f598c9d4ca5afc0a2d024c5dd6 --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/spec/7_expressions/ExpressionSequence.ets @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2025 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. + */ + +/** + * CHAPTER 7.4 + * expressionSequence: + * expression (',' expression)* ','? + * ; + */ + +let y1 = [1, 2, 3]; + +let y2 = [1, 2, 3,]; + +let y3 = [1]; + +let y4 = [1,]; diff --git a/ets2panda/test/ast/compiler/ets/spec/7_expressions/FieldAccessExpression.ets b/ets2panda/test/ast/compiler/ets/spec/7_expressions/FieldAccessExpression.ets new file mode 100644 index 0000000000000000000000000000000000000000..a77a97030c72e134bb390382eec1ad4aace6747d --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/spec/7_expressions/FieldAccessExpression.ets @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2025 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. + */ + +/** + * CHAPTER 7.9 + * fieldAccessExpression: + * objectReference ('.' | '?.') identifier + * ; + */ + +class Person { + name: string = "Unknown"; +} +let person = new Person(); +person.name = "Alice"; + +let person1: Person | null = null; +person1?.name; diff --git a/ets2panda/test/ast/compiler/ets/spec/7_expressions/FunctionCallExpression.ets b/ets2panda/test/ast/compiler/ets/spec/7_expressions/FunctionCallExpression.ets new file mode 100644 index 0000000000000000000000000000000000000000..8e00ae1cdd209d1d37bd7523d83be5dccbbabbde --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/spec/7_expressions/FunctionCallExpression.ets @@ -0,0 +1,63 @@ +/* + * Copyright (c) 2025 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. + */ + +/** + * CHAPTER 7.11 + * functionCallExpression: + * expression ( '?.' | typeArguments)? arguments block? + * ; + */ + +class Person { + sayHello() {} +} +let person1 = new Person(); +person1.sayHello(); + +class MyClass1 { + static identity(arg: T): T { + return arg; + } +} +let result = MyClass1.identity("Hello, World!"); + +class MyClass2 { + execute(callback: () => T): T { + return callback(); + } +} +let myInstance1 = new MyClass2(); +myInstance1.execute(() => { + return "Block executed"; +}); + +let person2: Person | null = null; +person2?.sayHello(); + +class MyClass3 { + execute(callback: () => void) { + callback?.(); + } +} +let myInstance2: MyClass3 | null = null; +myInstance2?.execute(() => {}); + +class MyClass4 { + execute(callback: () => void): void { + callback(); + } +} +let myInstance3 = new MyClass4(); +myInstance3.execute(() => {}); diff --git a/ets2panda/test/ast/compiler/ets/spec/7_expressions/IndexingExpression.ets b/ets2panda/test/ast/compiler/ets/spec/7_expressions/IndexingExpression.ets new file mode 100644 index 0000000000000000000000000000000000000000..1455d6808ea208d7324740005d205e23eca780f6 --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/spec/7_expressions/IndexingExpression.ets @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2025 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. + */ + +/** + * CHAPTER 7.12 + * indexingExpression: + * expression ('?.')? '[' expression ']' + * ; + */ + +const maybeArray: number[] | null = null; +maybeArray?.[0]; + +const numbers = [1, 2, 3]; +numbers[0]; diff --git a/ets2panda/test/ast/compiler/ets/spec/7_expressions/KeyValueSequence.ets b/ets2panda/test/ast/compiler/ets/spec/7_expressions/KeyValueSequence.ets new file mode 100644 index 0000000000000000000000000000000000000000..df5114cca41b8bb41675cec5487bc047e77844e6 --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/spec/7_expressions/KeyValueSequence.ets @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2025 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. + */ + +/** + * CHAPTER 7.5.3 + * keyValueSequence: + * keyValue (',' keyValue)* ','? + * ; + * + * keyValue: + * expression ':' expression + * ; + */ + +let map1: Record = { + "John": 25, + "Mary": 21 +}; + +let map2: Record = { + "John": 25, + "Mary": 21, +}; + +let map3: Record = { + "John": 25 +}; + +let map4: Record = { + "John": 25, +}; diff --git a/ets2panda/test/ast/compiler/ets/spec/7_expressions/MethodCallExpression.ets b/ets2panda/test/ast/compiler/ets/spec/7_expressions/MethodCallExpression.ets new file mode 100644 index 0000000000000000000000000000000000000000..f28260bd7ef0e40d2c7393aa774991821c249cca --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/spec/7_expressions/MethodCallExpression.ets @@ -0,0 +1,45 @@ +/* + * Copyright (c) 2025 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. + */ + +/** + * CHAPTER 7.10 + * methodCallExpression: + * objectReference ('.' | '?.') identifier typeArguments? arguments block? + * ; + */ + +class MyClass { + sayHello(a: number) {} + sayHello1(a: number) {} + execute(action: () => void) {} + execute1(action: () => void) {} +} +let obj = new MyClass(); +obj.sayHello(1); + +obj.sayHello1(1); + +obj.execute(() => { console.log("Action executed"); }); + +obj.execute1(() => { console.log("Action executed"); }); + +let obj1: MyClass | null = null; +obj1?.sayHello(1); + +obj1?.sayHello1(1); + +obj1?.execute(() => { console.log("Action executed"); }); + +obj1?.execute1(() => { console.log("Action executed"); }); diff --git a/ets2panda/test/ast/compiler/ets/spec/7_expressions/NamedReference.ets b/ets2panda/test/ast/compiler/ets/spec/7_expressions/NamedReference.ets new file mode 100644 index 0000000000000000000000000000000000000000..ceca17ad4e2dcf1c45de90eceac6555c5dfa5cec --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/spec/7_expressions/NamedReference.ets @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2025 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. + */ + +/** + * CHAPTER 7.3 + * namedReference: + * qualifiedName typeArguments? + * ; + */ + +function generic_function() {} +generic_function(); + +function generic_function1() {} +generic_function1(); diff --git a/ets2panda/test/ast/compiler/ets/spec/7_expressions/NewClassInstance.ets b/ets2panda/test/ast/compiler/ets/spec/7_expressions/NewClassInstance.ets new file mode 100644 index 0000000000000000000000000000000000000000..39f303787f54ac304811b35bea4893d5b181adb9 --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/spec/7_expressions/NewClassInstance.ets @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2025 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. + */ + +/** + * CHAPTER 7.14 + * newClassInstance: + * 'new' typeArguments? typeReference arguments? + * ; + */ + +class GenericClass { + constructor(p: number) {} +} +let instance1 = new GenericClass(5); + +class GenericClass1 {} +let instance2 = new GenericClass1(); + +class GenericClass2 { + constructor(p: number) {} +} +let instance3 = new GenericClass2(5); + +class GenericClass3 {} +let instance4 = new GenericClass3(); diff --git a/ets2panda/test/ast/compiler/ets/spec/7_expressions/NewExpression.ets b/ets2panda/test/ast/compiler/ets/spec/7_expressions/NewExpression.ets new file mode 100644 index 0000000000000000000000000000000000000000..4b96031569ae52f19ca61cc3c541bc7d302943ea --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/spec/7_expressions/NewExpression.ets @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2025 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. + */ + +/** + * CHAPTER 7.14 + * newExpression: + * newClassInstance + * | newArrayInstance + * ; + */ + +class MyClass { + constructor(p: number) {} +} +let instance = new MyClass(5); + +let numbers = new Array(3); diff --git a/ets2panda/test/ast/compiler/ets/spec/7_expressions/ObjectLiteral.ets b/ets2panda/test/ast/compiler/ets/spec/7_expressions/ObjectLiteral.ets new file mode 100644 index 0000000000000000000000000000000000000000..3d8ec1bcd8ea2ef8264384616317fa38991af1dd --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/spec/7_expressions/ObjectLiteral.ets @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2025 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. + */ + +/** + * CHAPTER 7.5 + * objectLiteral: + * '{' valueSequence? '}' + * ; + */ + +class Person { + name: string = ""; + age: number = 0; +} +let emptyObject: Person = {}; + +let p1: Person = { name: "Alice" }; diff --git a/ets2panda/test/ast/compiler/ets/spec/7_expressions/ParenthesizedExpression.ets b/ets2panda/test/ast/compiler/ets/spec/7_expressions/ParenthesizedExpression.ets new file mode 100644 index 0000000000000000000000000000000000000000..1f9e83f7898542d81b750609dd0ed1d85a47abf1 --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/spec/7_expressions/ParenthesizedExpression.ets @@ -0,0 +1,23 @@ +/* + * Copyright (c) 2025 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. + */ + +/** + * CHAPTER 7.7 + * parenthesizedExpression: + * '(' expression ')' + * ; + */ + +let c = (5 + 10) * 2; diff --git a/ets2panda/test/ast/compiler/ets/spec/7_expressions/RecordLiteral.ets b/ets2panda/test/ast/compiler/ets/spec/7_expressions/RecordLiteral.ets new file mode 100644 index 0000000000000000000000000000000000000000..a5a4853c1f4203bcad2f715410fb696e150ff781 --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/spec/7_expressions/RecordLiteral.ets @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2025 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. + */ + +/** + * CHAPTER 7.5.3 + * recordLiteral: + * '{' keyValueSequence? '}' + * ; + */ + +let map: Record = { + "John": 25, + "Mary": 21, +}; + +let map1: Record = {}; diff --git a/ets2panda/test/ast/compiler/ets/spec/7_expressions/SpreadExpression.ets b/ets2panda/test/ast/compiler/ets/spec/7_expressions/SpreadExpression.ets new file mode 100644 index 0000000000000000000000000000000000000000..5e20ec07ac97a677cc8c64e5c1badf8744c1ef61 --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/spec/7_expressions/SpreadExpression.ets @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2025 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. + */ + +/** + * CHAPTER 7.6 + * spreadExpression: + * '...' expression + * ; + */ + +let first = [1, 2]; +let second = [3, 4]; +let combined = [...first, ...second]; diff --git a/ets2panda/test/ast/compiler/ets/spec/7_expressions/ThisExpression.ets b/ets2panda/test/ast/compiler/ets/spec/7_expressions/ThisExpression.ets new file mode 100644 index 0000000000000000000000000000000000000000..6d7c836ec6493a04a3536ef4054a8f6f78a26ee1 --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/spec/7_expressions/ThisExpression.ets @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2025 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. + */ + +/** + * CHAPTER 7.8 + * thisExpression: + * 'this' + * ; + */ + +class Person { + name: string; + constructor(name: string) { + this.name = name; + } +} +let person = new Person("Alice"); diff --git a/ets2panda/test/ast/compiler/ets/spec/7_expressions/ValueSequence.ets b/ets2panda/test/ast/compiler/ets/spec/7_expressions/ValueSequence.ets new file mode 100644 index 0000000000000000000000000000000000000000..8367b3aca5b084937b1f78361c72ec2da80e2d56 --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/spec/7_expressions/ValueSequence.ets @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2025 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. + */ + +/** + * CHAPTER 7.5 + * valueSequence: + * nameValue (',' nameValue)* ','? + * ; + * + * nameValue: + * identifier ':' expression + * ; + */ + +class Person { + name: string = ""; + age: number = 0; +} +let p1: Person = { name: "Alice", age: 25 }; + +let p2: Person = { name: "Alice", age: 25, }; + +let p3: Person = { name: "Alice" }; + +let p4: Person = { name: "Alice", }; diff --git a/ets2panda/test/test-lists/astchecker/astchecker-ets-ignored.txt b/ets2panda/test/test-lists/astchecker/astchecker-ets-ignored.txt index 303bff6cd20d4f5577e84212a168342d08e65e23..8b6d69b90bd9a04c72f492c0dd2cc22d39000744 100644 --- a/ets2panda/test/test-lists/astchecker/astchecker-ets-ignored.txt +++ b/ets2panda/test/test-lists/astchecker/astchecker-ets-ignored.txt @@ -15,6 +15,13 @@ ast/parser/ets/lexer001.ets ast/parser/ets/lexer002.ets ast/parser/ets/TypeInferFunc.ets +# Issue: #IBWNGZ +ast/compiler/ets/spec/2_lexical_elements/BacktickCharacterError.ets +ast/compiler/ets/spec/2_lexical_elements/EscapeSequenceError.ets +ast/compiler/ets/spec/2_lexical_elements/DoubleQuoteCharacterError.ets +ast/compiler/ets/spec/2_lexical_elements/SingleQuoteCharacterError.ets +ast/compiler/ets/spec/17_experimental_features/SingleQuoteCharacterError.ets + # Issue: #20639 ast/parser/ets/extension_function_tests/extension_function_array1.ets ast/parser/ets/extension_function_tests/extension_function_array1_primitive.ets diff --git a/ets2panda/test/test-lists/srcdumper/srcdumper-ets-ignored.txt b/ets2panda/test/test-lists/srcdumper/srcdumper-ets-ignored.txt index 47504eb9510fca0b29fcd1a769683f9400c7574a..c932a0f571d1a1f96c8622661c51b5045c14af74 100644 --- a/ets2panda/test/test-lists/srcdumper/srcdumper-ets-ignored.txt +++ b/ets2panda/test/test-lists/srcdumper/srcdumper-ets-ignored.txt @@ -160,6 +160,23 @@ ast/compiler/ets/import_type_without_export.ets ast/compiler/ets/type_binding_01.ets ast/compiler/ets/type_binding_02.ets +# FailKind.SRC_DUMPER_FAIL (Issue: #IBWNGZ) +ast/compiler/ets/spec/14_ambient_declarations/ambientClassBodyDeclaration.ets +ast/compiler/ets/spec/14_ambient_declarations/ambientIndexerDeclaration.ets +ast/compiler/ets/spec/14_ambient_declarations/ambientNamespaceDeclaration.ets +ast/compiler/ets/spec/14_ambient_declarations/ambientNamespaceElement.ets +ast/compiler/ets/spec/14_ambient_declarations/ambientNamespaceElementDeclaration.ets +ast/compiler/ets/spec/17_experimental_features/PackageModuleDeclaration/ImportDirective.ets +ast/compiler/ets/spec/17_experimental_features/PackageModuleDeclaration/ImportDirectivePackageTopDeclaration.ets +ast/compiler/ets/spec/17_experimental_features/PackageModuleDeclaration/PackageTopDeclaration.ets +ast/compiler/ets/spec/17_experimental_features/SingleQuoteCharacterError.ets +ast/compiler/ets/spec/17_experimental_features/TrailingLambdaCall.ets +ast/compiler/ets/spec/17_experimental_features/PackageTopDeclaration.ets +ast/compiler/ets/spec/7_expressions/FieldAccessExpression.ets +ast/compiler/ets/spec/7_expressions/FunctionCallExpression.ets +ast/compiler/ets/spec/7_expressions/IndexingExpression.ets +ast/compiler/ets/spec/7_expressions/MethodCallExpression.ets + # FailKind.ES2PANDA_FAIL runtime/ets/StringFasta.ets runtime/ets/struct-identifier.ets