diff --git a/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/breakStatement/breakStatement_classInitializer.ets b/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/breakStatement/breakStatement_classInitializer.ets new file mode 100644 index 0000000000000000000000000000000000000000..8978de1cee72ff254ba7ad5b07200dc26bb6e77f --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/breakStatement/breakStatement_classInitializer.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 8.10 + * breakStatement: + * 'break' identifier? + * ; + * + * CHAPTER 9.8 + * classInitializer: + * initializerBlock + * ; + */ + +class X { + static initialized = false; + static initializerBlock() { + for (let x of [1, 2, 3]) { + break; + } + } +} diff --git a/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/breakStatement/breakStatement_finallyClause.ets b/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/breakStatement/breakStatement_finallyClause.ets new file mode 100644 index 0000000000000000000000000000000000000000..657b181b4c8d014fc39434c3f75db78c62a4816a --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/breakStatement/breakStatement_finallyClause.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 8.10 + * breakStatement: + * 'break' identifier? + * ; + * + * CHAPTER 8.15.2 + * finallyClause: + * 'finally' block + * ; + */ + +try { +} catch (error) { +} finally { + for (let x = 1; x < 2; x++) { + let a = 1; + break; + } +} diff --git a/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/breakStatement/breakStatement_initializerBlock.ets b/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/breakStatement/breakStatement_initializerBlock.ets new file mode 100644 index 0000000000000000000000000000000000000000..8f9a1bcbda38763072675add616eaa813c1d3e24 --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/breakStatement/breakStatement_initializerBlock.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 8.10 + * breakStatement: + * 'break' identifier? + * ; + * + * CHAPTER 15.10 + * initializerBlock: + * 'static' block + * ; + */ + +class Test { + static { + for (let x = 1; x < 2; x++) { + let a = 1; + break; + } + } +} diff --git a/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/breakStatement/breakStatement_lambdaExpressionWithReceiver.ets b/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/breakStatement/breakStatement_lambdaExpressionWithReceiver.ets new file mode 100644 index 0000000000000000000000000000000000000000..9c378fd6cff33141cf17af94e863d9144dc38968 --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/breakStatement/breakStatement_lambdaExpressionWithReceiver.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 8.10 + * breakStatement: + * 'break' identifier? + * ; + * + * CHAPTER 17.12.5 + * lambdaExpressionWithReceiver: + * annotationUsage? typeParameters? + * '(' receiverParameter (',' lambdaParameterList)? ')' + * returnType? throwMark? '=>' lambdaBody + * ; + */ + +class A {} + +let result = (this: A) => { + for (let x = 1; x < 2; x++) { + let a = 1; + break; + } +}; diff --git a/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/breakStatement/breakStatement_namespaceDeclaration.ets b/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/breakStatement/breakStatement_namespaceDeclaration.ets new file mode 100644 index 0000000000000000000000000000000000000000..bbc95f26e0a3afe9c5ab96374d6e303a59b92e20 --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/breakStatement/breakStatement_namespaceDeclaration.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. + */ + +/** + * CHAPTER 8.10 + * breakStatement: + * 'break' identifier? + * ; + * + * CHAPTER 13.8 + * namespaceDeclaration: + * 'namespace' qualifiedName + * '{' topDeclaration* initializerBlock? topDeclaration* '}' + * ; + */ + +namespace A { + for (let x = 1; x < 2; x++) { + let a = 1; + break; + } +} diff --git a/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/breakStatement/breakStatement_switchStatement.ets b/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/breakStatement/breakStatement_switchStatement.ets new file mode 100644 index 0000000000000000000000000000000000000000..d898086270458950e2b74c76b40cad89fe50fb0e --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/breakStatement/breakStatement_switchStatement.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 8.10 + * breakStatement: + * 'break' identifier? + * ; + * + * CHAPTER 8.13 + * switchStatement: + * (identifier ':')? 'switch' '(' expression ')' switchBlock + * ; + */ + +let x = 1; +switch (x) { + case 1: + for (let x of [1, 2, 3]) { + break; + } + break; + default: + break; +} diff --git a/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/breakStatement/breakStatement_tryStatement.ets b/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/breakStatement/breakStatement_tryStatement.ets new file mode 100644 index 0000000000000000000000000000000000000000..44e6ac37a640e9dce904d07e3eb37424117bb7fc --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/breakStatement/breakStatement_tryStatement.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 8.10 + * breakStatement: + * 'break' identifier? + * ; + * + * CHAPTER 8.15 + * tryStatement: + * 'try' block catchClauses finallyClause? + * ; + */ + +function processOne(a: number): number { + try { + let counter = 0; + for (let x = 1; x < 2; x++) { + let a = 1; + break; + } + return 0; + } catch (error) { + return -1; + } +} diff --git a/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/continueStatement/continueStatement_classInitializer.ets b/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/continueStatement/continueStatement_classInitializer.ets new file mode 100644 index 0000000000000000000000000000000000000000..350d51f53ebc60cb194a6d5dabdd52abed354b86 --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/continueStatement/continueStatement_classInitializer.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 8.11 + * continueStatement: + * 'continue' identifier? + * ; + * + * CHAPTER 9.8 + * classInitializer: + * initializerBlock + * ; + */ + +class X { + static initialized = false; + static initializerBlock() { + for (let i = 0; i < 10; i++) { + if (!X.initialized) { + continue; + } + } + } +} diff --git a/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/continueStatement/continueStatement_finallyClause.ets b/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/continueStatement/continueStatement_finallyClause.ets new file mode 100644 index 0000000000000000000000000000000000000000..8c63c7c77111b2482bf8ea8b9bb0b29b5d2d0904 --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/continueStatement/continueStatement_finallyClause.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. + */ + +/** + * CHAPTER 8.11 + * continueStatement: + * 'continue' identifier? + * ; + * + * CHAPTER 8.15.2 + * finallyClause: + * 'finally' block + * ; + */ + +try { +} catch (error) { +} finally { + for (let x = 1; x < 2; x++) { + continue; + } +} diff --git a/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/continueStatement/continueStatement_initializerBlock.ets b/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/continueStatement/continueStatement_initializerBlock.ets new file mode 100644 index 0000000000000000000000000000000000000000..d077565a82ea5e396d3be05231b09df115f553bb --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/continueStatement/continueStatement_initializerBlock.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. + */ + +/** + * CHAPTER 8.11 + * continueStatement: + * 'continue' identifier? + * ; + * + * CHAPTER 15.10 + * initializerBlock: + * 'static' block + * ; + */ + +class Test { + static { + for (let x = 1; x < 2; x++) { + continue; + } + } +} diff --git a/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/continueStatement/continueStatement_lambdaExpressionWithReceiver.ets b/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/continueStatement/continueStatement_lambdaExpressionWithReceiver.ets new file mode 100644 index 0000000000000000000000000000000000000000..ed2faba49ac20bec85a843a80387baf0bc0637b7 --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/continueStatement/continueStatement_lambdaExpressionWithReceiver.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 8.11 + * continueStatement: + * 'continue' identifier? + * ; + * + * CHAPTER 17.12.5 + * lambdaExpressionWithReceiver: + * annotationUsage? typeParameters? + * '(' receiverParameter (',' lambdaParameterList)? ')' + * returnType? throwMark? '=>' lambdaBody + * ; + */ + +class A {} + +let result = (this: A) => { + for (let x = 1; x < 2; x++) { + continue; + } +}; diff --git a/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/continueStatement/continueStatement_namespaceDeclaration.ets b/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/continueStatement/continueStatement_namespaceDeclaration.ets new file mode 100644 index 0000000000000000000000000000000000000000..d4a9bdc9faa884d5705b3ba8c8fb8490f3dc97d9 --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/continueStatement/continueStatement_namespaceDeclaration.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. + */ + +/** + * CHAPTER 8.11 + * continueStatement: + * 'continue' identifier? + * ; + * + * CHAPTER 13.8 + * namespaceDeclaration: + * 'namespace' qualifiedName + * '{' topDeclaration* initializerBlock? topDeclaration* '}' + * ; + */ + + +namespace A { + for (let x = 1; x < 2; x++) { + continue; + } +} diff --git a/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/continueStatement/continueStatement_switchStatement.ets b/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/continueStatement/continueStatement_switchStatement.ets new file mode 100644 index 0000000000000000000000000000000000000000..9aac48c8113b5522aaac2715ea06fff4ca5582a8 --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/continueStatement/continueStatement_switchStatement.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 8.11 + * continueStatement: + * 'continue' identifier? + * ; + * + * CHAPTER 8.13 + * switchStatement: + * (identifier ':')? 'switch' '(' expression ')' switchBlock + * ; + */ + +let x = 1; +switch (x) { + case 1: + if (true) { + for (let x of [1, 2, 3]) { + continue; + } + break; + } else { + break; + } + default: + break; +} diff --git a/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/continueStatement/continueStatement_tryStatement.ets b/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/continueStatement/continueStatement_tryStatement.ets new file mode 100644 index 0000000000000000000000000000000000000000..aba24d8922ae03977721c70c348d8ba37d2972bd --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/continueStatement/continueStatement_tryStatement.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 8.11 + * continueStatement: + * 'continue' identifier? + * ; + * + * CHAPTER 8.15 + * tryStatement: + * 'try' block catchClauses finallyClause? + * ; + */ + +function processTwo(a: number): number { + try { + for (let x = 1; x < 2; x++) { + continue; + } + return 0; + } catch (error) { + return -1; + } +} diff --git a/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/finallyClause/finallyClause_awaitExpression.ets b/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/finallyClause/finallyClause_awaitExpression.ets new file mode 100644 index 0000000000000000000000000000000000000000..27d3a71982c77c217e6f81394c23fd9ed0427390 --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/finallyClause/finallyClause_awaitExpression.ets @@ -0,0 +1,42 @@ +/* + * 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 8.15.2 + * finallyClause: + * 'finally' block + * ; + * + * CHAPTER 17.16.2 + * awaitExpression: + * 'await' expression + * ; + */ + +async function foo(): Promise { + return 42.0; +} + +async function main() { + let x = foo(); + try { + let result = await x; + } catch (error) { + console.log(`Error occurred: ${error}`); + } finally { + await x; + console.log("Execution completed, cleanup code goes here"); + } +} diff --git a/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/finallyClause/finallyClause_classInitializer.ets b/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/finallyClause/finallyClause_classInitializer.ets new file mode 100644 index 0000000000000000000000000000000000000000..069a63518bc93039d809e8a6ef286d3cce7807c9 --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/finallyClause/finallyClause_classInitializer.ets @@ -0,0 +1,40 @@ +/* + * 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 8.15.2 + * finallyClause: + * 'finally' block + * ; + * + * CHAPTER 9.8 + * classInitializer: + * initializerBlock + * ; + */ + +class X { + static initialized = false; + static initializerBlock() { + try { + X.initialized = true; + } catch (error) { + console.log(`Error occurred: ${error}`); + } finally { + X.initialized = true; + console.log("Execution completed, cleanup code goes here"); + } + } +} diff --git a/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/finallyClause/finallyClause_enumDeclaration.ets b/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/finallyClause/finallyClause_enumDeclaration.ets new file mode 100644 index 0000000000000000000000000000000000000000..c7641f9f50b649626909bf8ef6ec824fdf6a023d --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/finallyClause/finallyClause_enumDeclaration.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. + */ + +/** + * CHAPTER 8.15.2 + * finallyClause: + * 'finally' block + * ; + * + * CHAPTER 11 + * enumDeclaration: + * 'const'? 'enum' identifier '{' enumConstantList '}' + * ; + */ + +try { + const enum x { Red = 1, Green = 2, Blue = 3 }; +} catch (error) { + console.log(`Error occurred: ${error}`); +} finally { + const enum X { Red = 1, Green = 2, Blue = 3 }; +} diff --git a/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/finallyClause/finallyClause_functionTypeWithReceiver.ets b/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/finallyClause/finallyClause_functionTypeWithReceiver.ets new file mode 100644 index 0000000000000000000000000000000000000000..eaa740569752aaba1c2b0430e4732ca5239cedd1 --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/finallyClause/finallyClause_functionTypeWithReceiver.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 8.15.2 + * finallyClause: + * 'finally' block + * ; + * + * CHAPTER 17.12.4 + * functionTypeWithReceiver: + * '(' receiverParameter (',' ftParameterList)? ')' ftReturnType + * ; + */ + +class A {} + +try { + type FA = (this: A) => boolean; +} catch (error) { + console.log(`Error occurred: ${error}`); +} finally { + type FA1 = (this: A) => boolean; +} diff --git a/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/finallyClause/finallyClause_initializerBlock.ets b/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/finallyClause/finallyClause_initializerBlock.ets new file mode 100644 index 0000000000000000000000000000000000000000..2e7faaff43e7e78cfb78b74fbc6e9316b8cf1272 --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/finallyClause/finallyClause_initializerBlock.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 8.15.2 + * finallyClause: + * 'finally' block + * ; + * + * CHAPTER 15.10 + * initializerBlock: + * 'static' block + * ; + */ + +class Test { + static { + try { + console.log("try"); + } catch (error) { + console.log(`Error occurred: ${error}`); + } finally { + console.log("Execution completed, cleanup code goes here"); + } + } +} diff --git a/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/finallyClause/finallyClause_lambdaExpressionWithReceiver.ets b/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/finallyClause/finallyClause_lambdaExpressionWithReceiver.ets new file mode 100644 index 0000000000000000000000000000000000000000..aeb0a1b1aa4be1cd8714efe41c71531d324fc07b --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/finallyClause/finallyClause_lambdaExpressionWithReceiver.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 8.15.2 + * finallyClause: + * 'finally' block + * ; + * + * CHAPTER 17.12.5 + * lambdaExpressionWithReceiver: + * annotationUsage? typeParameters? + * '(' receiverParameter (',' lambdaParameterList)? ')' + * returnType? throwMark? '=>' lambdaBody + * ; + */ + +class A {} + +try { + let result = (this: A) => { + let b = 2; + return b; + } +} catch (error) { + console.log(`Error occurred: ${error}`); +} finally { + let result1 = (this: A) => { + let b1 = 2; + return b1; + } +} diff --git a/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/finallyClause/finallyClause_namespaceDeclaration.ets b/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/finallyClause/finallyClause_namespaceDeclaration.ets new file mode 100644 index 0000000000000000000000000000000000000000..9ad24f469d54e797bd2109f0d459ded7e4d1f211 --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/finallyClause/finallyClause_namespaceDeclaration.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 8.15.2 + * finallyClause: + * 'finally' block + * ; + * + * CHAPTER 13.8 + * namespaceDeclaration: + * 'namespace' qualifiedName + * '{' topDeclaration* initializerBlock? topDeclaration* '}' + * ; + */ + +namespace A { + try { + console.log("try"); + } catch (error) { + console.log(`Error occurred: ${error}`); + } finally { + console.log("Execution completed, cleanup code goes here"); + } +} diff --git a/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/finallyClause/finallyClause_newArrayInstance.ets b/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/finallyClause/finallyClause_newArrayInstance.ets new file mode 100644 index 0000000000000000000000000000000000000000..4cec49dbec05b81ab3be623916ea0de99379b5de --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/finallyClause/finallyClause_newArrayInstance.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 8.15.2 + * finallyClause: + * 'finally' block + * ; + * + * CHAPTER 17.3 + * newArrayInstance: + * 'new' arrayElementType dimensionExpression+ (arrayElement)? + * ; + */ + +try { + let y = 1; +} catch (error) { + console.log(`Error occurred: ${error}`); +} finally { + let x = 1; + let a = new string[x]; +} diff --git a/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/finallyClause/finallyClause_separateModuleDeclaration.ets b/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/finallyClause/finallyClause_separateModuleDeclaration.ets new file mode 100644 index 0000000000000000000000000000000000000000..de0b564cce66a370a7a9f47e1d8392fb78d78d20 --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/finallyClause/finallyClause_separateModuleDeclaration.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. + */ + +/** + * CHAPTER 8.15.2 + * finallyClause: + * 'finally' block + * ; + * + * CHAPTER 13.1 + * separateModuleDeclaration: + * importDirective* (topDeclaration | topLevelStatements | exportDirective)* + * ; + */ + +try { + console.log("try"); +} catch (error) { + console.log(`Error occurred: ${error}`); +} finally { + console.log("Execution completed, cleanup code goes here"); +} diff --git a/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/finallyClause/finallyClause_topDeclaration.ets b/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/finallyClause/finallyClause_topDeclaration.ets new file mode 100644 index 0000000000000000000000000000000000000000..759c565243d2b80c78304f20c9c348c0e83ed5d2 --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/finallyClause/finallyClause_topDeclaration.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 8.15.2 + * finallyClause: + * 'finally' block + * ; + * + * CHAPTER 13.7 + * topDeclaration: + * ('export' 'default'?)? + * annotationUsage? + * ( typeDeclaration + * | variableDeclarations + * | constantDeclarations + * | functionDeclaration + * | functionWithReceiverDeclaration + * | accessorWithReceiverDeclaration + * | namespaceDeclaration + * ) + * ; + */ + +try { + console.log("try"); +} catch (error) { + console.log(`Error occurred: ${error}`); +} finally { + console.log("Execution completed, cleanup code goes here"); +} diff --git a/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/finallyClause/finallyClause_topLevelStatements.ets b/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/finallyClause/finallyClause_topLevelStatements.ets new file mode 100644 index 0000000000000000000000000000000000000000..d55c2924f08a04c851e4cdc051f81169fd4e0dc9 --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/finallyClause/finallyClause_topLevelStatements.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. + */ + +/** + * CHAPTER 8.15.2 + * finallyClause: + * 'finally' block + * ; + * + * CHAPTER 13.10 + * topLevelStatements: + * statement* + * ; + */ + +try { + console.log("try"); +} catch (error) { + console.log(`Error occurred: ${error}`); +} finally { + console.log("Execution completed, cleanup code goes here"); +} diff --git a/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/finallyClause/finallyClause_trailingLambdaCall.ets b/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/finallyClause/finallyClause_trailingLambdaCall.ets new file mode 100644 index 0000000000000000000000000000000000000000..6a0b6a56cdc267daeac1d63032bc43ac01cb658f --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/finallyClause/finallyClause_trailingLambdaCall.ets @@ -0,0 +1,46 @@ +/* + * 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 8.15.2 + * finallyClause: + * 'finally' block + * ; + * + * CHAPTER 17.13 + * trailingLambdaCall: + * ( objectReference '.' identifier typeArguments? + * | expression ('?.' | typeArguments)? + * ) + * arguments block + * ; + */ + +class A { + x(arg: T, callback: (result: T) => void): number { + const result = arg; + callback(result); + return 0; + } +} + +let a = new A(); +try { + let test = a.x("Hi") {} +} catch (error) { + console.log(`Error occurred: ${error}`); +} finally { + let test1 = a.x("Hi") {} +} diff --git a/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/forOfStatement/forOfStatement_awaitExpression.ets b/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/forOfStatement/forOfStatement_awaitExpression.ets new file mode 100644 index 0000000000000000000000000000000000000000..59ac8e708be10e793961dce1041f8943fb338ed5 --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/forOfStatement/forOfStatement_awaitExpression.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 8.9 + * forOfStatement: + * 'for' '(' forVariable 'of' expression ')' statement + * ; + * + * CHAPTER 17.16.2 + * awaitExpression: + * 'await' expression + * ; + */ + +async function foo(): Promise { + return 42.0; +} + +async function main() { + for (let a of [1, 2, 3]) { + let x = foo(); + let result = await x; + } +} diff --git a/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/forOfStatement/forOfStatement_breakStatement.ets b/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/forOfStatement/forOfStatement_breakStatement.ets new file mode 100644 index 0000000000000000000000000000000000000000..7c8707a0b92ef3d4bffc80d57616ca8e32fb65a9 --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/forOfStatement/forOfStatement_breakStatement.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 8.9 + * forOfStatement: + * 'for' '(' forVariable 'of' expression ')' statement + * ; + * + * CHAPTER 8.10 + * breakStatement: + * 'break' identifier? + * ; + */ + +for (let x of [1, 2, 3]) { + break; +} diff --git a/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/forOfStatement/forOfStatement_classInitializer.ets b/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/forOfStatement/forOfStatement_classInitializer.ets new file mode 100644 index 0000000000000000000000000000000000000000..ae3c22320215d66afd16495ff58304c132496543 --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/forOfStatement/forOfStatement_classInitializer.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 8.9 + * forOfStatement: + * 'for' '(' forVariable 'of' expression ')' statement + * ; + * + * CHAPTER 9.8 + * classInitializer: + * initializerBlock + * ; + */ + +class X { + static initialized = false; + static initializerBlock() { + for (let x of [1, 2, 3]) { + X.initialized = true; + } + } +} diff --git a/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/forOfStatement/forOfStatement_continueStatement.ets b/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/forOfStatement/forOfStatement_continueStatement.ets new file mode 100644 index 0000000000000000000000000000000000000000..a33cbfac18d56c107a8267309dbcc87817bef9b1 --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/forOfStatement/forOfStatement_continueStatement.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 8.9 + * forOfStatement: + * 'for' '(' forVariable 'of' expression ')' statement + * ; + * + * CHAPTER 8.11 + * continueStatement: + * 'continue' identifier? + * ; + */ + +for (let a of [1, 2, 3]) { + if (a === 2) { + continue; + } +} diff --git a/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/forOfStatement/forOfStatement_finallyClause.ets b/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/forOfStatement/forOfStatement_finallyClause.ets new file mode 100644 index 0000000000000000000000000000000000000000..7f2b9f92cb84e4e510297dfcc63a193fd5cce4dc --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/forOfStatement/forOfStatement_finallyClause.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 8.9 + * forOfStatement: + * 'for' '(' forVariable 'of' expression ')' statement + * ; + * + * CHAPTER 8.15.2 + * finallyClause: + * 'finally' block + * ; + */ + +for (let x of [1, 2, 3]) { + try { + } catch (error) { + } finally { + let x = 1; + } +} + diff --git a/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/forOfStatement/forOfStatement_functionTypeWithReceiver.ets b/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/forOfStatement/forOfStatement_functionTypeWithReceiver.ets new file mode 100644 index 0000000000000000000000000000000000000000..cc26c74a61c764d018b606553b9e998d7c17dec2 --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/forOfStatement/forOfStatement_functionTypeWithReceiver.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 8.9 + * forOfStatement: + * 'for' '(' forVariable 'of' expression ')' statement + * ; + * + * CHAPTER 17.12.4 + * functionTypeWithReceiver: + * '(' receiverParameter (',' ftParameterList)? ')' ftReturnType + * ; + */ + +class A {} + +for (let x of [1, 2, 3]) { + type FA = (this: A) => boolean; +} diff --git a/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/forOfStatement/forOfStatement_initializerBlock.ets b/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/forOfStatement/forOfStatement_initializerBlock.ets new file mode 100644 index 0000000000000000000000000000000000000000..3986ae110ee4857dca606610bd141d49fc50c0e1 --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/forOfStatement/forOfStatement_initializerBlock.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. + */ + +/** + * CHAPTER 8.9 + * forOfStatement: + * 'for' '(' forVariable 'of' expression ')' statement + * ; + * + * CHAPTER 15.10 + * initializerBlock: + * 'static' block + * ; + */ + +class Test { + static { + for (let a of [1, 2, 3]) { + let x = 0; + } + } +} diff --git a/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/forOfStatement/forOfStatement_lambdaExpressionWithReceiver.ets b/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/forOfStatement/forOfStatement_lambdaExpressionWithReceiver.ets new file mode 100644 index 0000000000000000000000000000000000000000..e73b852358fe924b1426ec79d8e68d95cd8e46e9 --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/forOfStatement/forOfStatement_lambdaExpressionWithReceiver.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 8.9 + * forOfStatement: + * 'for' '(' forVariable 'of' expression ')' statement + * ; + * + * CHAPTER 17.12.5 + * lambdaExpressionWithReceiver: + * annotationUsage? typeParameters? + * '(' receiverParameter (',' lambdaParameterList)? ')' + * returnType? throwMark? '=>' lambdaBody + * ; + */ + +class A {} + +for (let x of [1, 2, 3]) { + let result = (this: A) => { + let b = 2; + return b; + }; +} diff --git a/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/forOfStatement/forOfStatement_namespaceDeclaration.ets b/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/forOfStatement/forOfStatement_namespaceDeclaration.ets new file mode 100644 index 0000000000000000000000000000000000000000..f75da538391d3ae99c4931ef359033da5021c284 --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/forOfStatement/forOfStatement_namespaceDeclaration.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 8.9 + * forOfStatement: + * 'for' '(' forVariable 'of' expression ')' statement + * ; + * + * CHAPTER 13.8 + * namespaceDeclaration: + * 'namespace' qualifiedName + * '{' topDeclaration* initializerBlock? topDeclaration* '}' + * ; + */ + +namespace A { + for (let x of [1, 2, 3]) { + let a: number = 1; + } +} diff --git a/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/forOfStatement/forOfStatement_newArrayInstance.ets b/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/forOfStatement/forOfStatement_newArrayInstance.ets new file mode 100644 index 0000000000000000000000000000000000000000..b0d26da9edf2c787893c2a0fa4b22bda81ace218 --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/forOfStatement/forOfStatement_newArrayInstance.ets @@ -0,0 +1,31 @@ +/* + * 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 8.9 + * forOfStatement: + * 'for' '(' forVariable 'of' expression ')' statement + * ; + * + * CHAPTER 17.3 + * newArrayInstance: + * 'new' arrayElementType dimensionExpression+ (arrayElement)? + * ; + */ + +for (let i of [1, 2, 3]) { + let x = 1; + let a = new string[x]; +} diff --git a/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/forOfStatement/forOfStatement_returnStatement.ets b/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/forOfStatement/forOfStatement_returnStatement.ets new file mode 100644 index 0000000000000000000000000000000000000000..89c92e1befa25ba0c57f6671aafa345a2e93ca9f --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/forOfStatement/forOfStatement_returnStatement.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 8.9 + * forOfStatement: + * 'for' '(' forVariable 'of' expression ')' statement + * ; + * + * CHAPTER 8.12 + * returnStatement: + * 'return' expression? + * ; + */ + +function add(x1: number, x2: number): number { + for (let x of [1, 2, 3]) { + return 1; + } + return 0; +} diff --git a/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/forOfStatement/forOfStatement_separateModuleDeclaration.ets b/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/forOfStatement/forOfStatement_separateModuleDeclaration.ets new file mode 100644 index 0000000000000000000000000000000000000000..02540243f6aa5a32d64db2ea47757eaa75e42763 --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/forOfStatement/forOfStatement_separateModuleDeclaration.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 8.9 + * forOfStatement: + * 'for' '(' forVariable 'of' expression ')' statement + * ; + * + * CHAPTER 13.1 + * separateModuleDeclaration: + * importDirective* (topDeclaration | topLevelStatements | exportDirective)* + * ; + */ + +for (let x of [1, 2, 3]) {} diff --git a/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/forOfStatement/forOfStatement_switchStatement.ets b/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/forOfStatement/forOfStatement_switchStatement.ets new file mode 100644 index 0000000000000000000000000000000000000000..0ed4e38ee35d01a4bd235409e5b7aeacd95915df --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/forOfStatement/forOfStatement_switchStatement.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 8.9 + * forOfStatement: + * 'for' '(' forVariable 'of' expression ')' statement + * ; + * + * CHAPTER 8.13 + * switchStatement: + * (identifier ':')? 'switch' '(' expression ')' switchBlock + * ; + */ + +let x = 1; +switch (x) { + case 1: + for (let x of [1, 2, 3]) { + break; + } + break; + default: + break; +} diff --git a/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/forOfStatement/forOfStatement_throwStatement.ets b/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/forOfStatement/forOfStatement_throwStatement.ets new file mode 100644 index 0000000000000000000000000000000000000000..d5452ca190d5b3456698daba2b025cca37d2f326 --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/forOfStatement/forOfStatement_throwStatement.ets @@ -0,0 +1,31 @@ +/* + * 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 8.9 + * forOfStatement: + * 'for' '(' forVariable 'of' expression ')' statement + * ; + * + * CHAPTER 8.14 + * throwStatement: + * 'throw' expression + * ; + */ + +let x = new Error("1"); +for (let a of [1, 2, 3]) { + throw (x = new Error("2")); +} diff --git a/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/forOfStatement/forOfStatement_topDeclaration.ets b/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/forOfStatement/forOfStatement_topDeclaration.ets new file mode 100644 index 0000000000000000000000000000000000000000..0e3723b30e9a5506c6b806013033dc31bb265fd0 --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/forOfStatement/forOfStatement_topDeclaration.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 8.9 + * forOfStatement: + * 'for' '(' forVariable 'of' expression ')' statement + * ; + * + * CHAPTER 13.7 + * topDeclaration: + * ('export' 'default'?)? + * annotationUsage? + * ( typeDeclaration + * | variableDeclarations + * | constantDeclarations + * | functionDeclaration + * | functionWithReceiverDeclaration + * | accessorWithReceiverDeclaration + * | namespaceDeclaration + * ) + * ; + */ + +for (let x of [1, 2, 3]) {} diff --git a/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/forOfStatement/forOfStatement_topLevelStatements.ets b/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/forOfStatement/forOfStatement_topLevelStatements.ets new file mode 100644 index 0000000000000000000000000000000000000000..7f4e418025a2099150f9f1b862d2d0ba1b4cb496 --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/forOfStatement/forOfStatement_topLevelStatements.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 8.9 + * forOfStatement: + * 'for' '(' forVariable 'of' expression ')' statement + * ; + * + * CHAPTER 13.10 + * topLevelStatements: + * statement* + * ; + */ + +for (let x of [1, 2, 3]) {} diff --git a/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/forOfStatement/forOfStatement_trailingLambdaCall.ets b/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/forOfStatement/forOfStatement_trailingLambdaCall.ets new file mode 100644 index 0000000000000000000000000000000000000000..e54d043604ca2a0f6e3ea4473caa6d78d37b4722 --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/forOfStatement/forOfStatement_trailingLambdaCall.ets @@ -0,0 +1,42 @@ +/* + * 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 8.9 + * forOfStatement: + * 'for' '(' forVariable 'of' expression ')' statement + * ; + * + * CHAPTER 17.13 + * trailingLambdaCall: + * ( objectReference '.' identifier typeArguments? + * | expression ('?.' | typeArguments)? + * ) + * arguments block + * ; + */ + +class A { + x(arg: T, callback: (result: T) => void): number { + const result = arg; + callback(result); + return 0; + } +} + +let a = new A(); +for (let x of [1, 2, 3]) { + let test = a.x("Hi") {} +} diff --git a/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/forOfStatement/forOfStatement_tryStatement.ets b/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/forOfStatement/forOfStatement_tryStatement.ets new file mode 100644 index 0000000000000000000000000000000000000000..b14b8887018634745d52ef6ad248a4d14763a8c4 --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/forOfStatement/forOfStatement_tryStatement.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 8.9 + * forOfStatement: + * 'for' '(' forVariable 'of' expression ')' statement + * ; + * + * CHAPTER 8.15 + * tryStatement: + * 'try' block catchClauses finallyClause? + * ; + */ + +function processOne(a: number): number { + try { + let counter = 0; + for (let x of [1, 2, 3]) { + counter++; + if (counter === 5) { + throw new Error("Counter reached 5"); + } + } + return 0; + } catch (error) { + return -1; + } +} diff --git a/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/forStatement/forStatement_awaitExpression.ets b/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/forStatement/forStatement_awaitExpression.ets new file mode 100644 index 0000000000000000000000000000000000000000..79bb20a99daaedf11a3b373b6705ad4bb19a6b26 --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/forStatement/forStatement_awaitExpression.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 8.8 + * forStatement: + * 'for' '(' forInit? ';' forContinue? ';' forUpdate? ')' statement + * ; + * + * CHAPTER 17.16.2 + * awaitExpression: + * 'await' expression + * ; + */ + +async function foo(): Promise { + return 42.0; +} + +async function main() { + let x = foo(); + for (let i = 1; i < 10; i++) { + let result = await x; + } +} diff --git a/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/forStatement/forStatement_breakStatement.ets b/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/forStatement/forStatement_breakStatement.ets new file mode 100644 index 0000000000000000000000000000000000000000..e67935727e7a5b7182dec9ef13573a2b69761018 --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/forStatement/forStatement_breakStatement.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 8.8 + * forStatement: + * 'for' '(' forInit? ';' forContinue? ';' forUpdate? ')' statement + * ; + * + * CHAPTER 8.10 + * breakStatement: + * 'break' identifier? + * ; + */ + +for (let x = 0; x < 5; x++) { + break; +} diff --git a/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/forStatement/forStatement_classInitializer.ets b/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/forStatement/forStatement_classInitializer.ets new file mode 100644 index 0000000000000000000000000000000000000000..c61d75da47ad10bd3f2ae4e3934ad1d6fe89fa5c --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/forStatement/forStatement_classInitializer.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 8.8 + * forStatement: + * 'for' '(' forInit? ';' forContinue? ';' forUpdate? ')' statement + * ; + * + * CHAPTER 9.8 + * classInitializer: + * initializerBlock + * ; + */ + +class X { + static initialized = false; + static initializerBlock() { + for (let i = 1; i < 10; i++) { + X.initialized = true; + } + } +} diff --git a/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/forStatement/forStatement_continueStatement.ets b/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/forStatement/forStatement_continueStatement.ets new file mode 100644 index 0000000000000000000000000000000000000000..e20c8cafb5e602d20faccaf49426df853ef4150b --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/forStatement/forStatement_continueStatement.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 8.8 + * forStatement: + * 'for' '(' forInit? ';' forContinue? ';' forUpdate? ')' statement + * ; + * + * CHAPTER 8.11 + * continueStatement: + * 'continue' identifier? + * ; + */ + +x: for (let i = 0; i < 3; i++) { + continue x; +} diff --git a/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/forStatement/forStatement_enumDeclaration.ets b/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/forStatement/forStatement_enumDeclaration.ets new file mode 100644 index 0000000000000000000000000000000000000000..f463c2916092dca8195fbb6c547299855d0c3c04 --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/forStatement/forStatement_enumDeclaration.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 8.8 + * forStatement: + * 'for' '(' forInit? ';' forContinue? ';' forUpdate? ')' statement + * ; + * + * CHAPTER 11 + * enumDeclaration: + * 'const'? 'enum' identifier '{' enumConstantList '}' + * ; + */ + +for (let i = 1; i < 10; i++) { + const enum x { Red = 1, Green = 2, Blue = 3 } +} diff --git a/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/forStatement/forStatement_finallyClause.ets b/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/forStatement/forStatement_finallyClause.ets new file mode 100644 index 0000000000000000000000000000000000000000..f07cb9bd4f2b2852c2d025e80ade82b3123ae56e --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/forStatement/forStatement_finallyClause.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. + */ + +/** + * CHAPTER 8.8 + * forStatement: + * 'for' '(' forInit? ';' forContinue? ';' forUpdate? ')' statement + * ; + * + * CHAPTER 8.15.2 + * finallyClause: + * 'finally' block + * ; + */ + +for (let i = 1; i < 10; i++) { + try { + } catch (error) { + } finally { + let x = 1; + } +} diff --git a/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/forStatement/forStatement_forOfStatement.ets b/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/forStatement/forStatement_forOfStatement.ets new file mode 100644 index 0000000000000000000000000000000000000000..4d9262de826ebe599fc9c1e4eb3a0930b7e06b12 --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/forStatement/forStatement_forOfStatement.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 8.8 + * forStatement: + * 'for' '(' forInit? ';' forContinue? ';' forUpdate? ')' statement + * ; + * + * CHAPTER 8.9 + * forOfStatement: + * 'for' '(' forVariable 'of' expression ')' statement + * ; + */ + +let arr = [1, 2, 3]; +for (let x of arr = [0]) { + for (let i = 1; i < 10; i++) { + break; + } +} diff --git a/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/forStatement/forStatement_functionTypeWithReceiver.ets b/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/forStatement/forStatement_functionTypeWithReceiver.ets new file mode 100644 index 0000000000000000000000000000000000000000..cbb468ecf5b7d4ad1ec0fbd4daa431a4feeab47b --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/forStatement/forStatement_functionTypeWithReceiver.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 8.8 + * forStatement: + * 'for' '(' forInit? ';' forContinue? ';' forUpdate? ')' statement + * ; + * + * CHAPTER 17.12.4 + * functionTypeWithReceiver: + * '(' receiverParameter (',' ftParameterList)? ')' ftReturnType + * ; + */ + +class A {} + +for (let i = 1; i < 10; i++) { + type FA = (this: A) => boolean; +} diff --git a/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/forStatement/forStatement_initializerBlock.ets b/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/forStatement/forStatement_initializerBlock.ets new file mode 100644 index 0000000000000000000000000000000000000000..e114b870d336a079d13ab9d25c7fea90960f1489 --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/forStatement/forStatement_initializerBlock.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. + */ + +/** + * CHAPTER 8.8 + * forStatement: + * 'for' '(' forInit? ';' forContinue? ';' forUpdate? ')' statement + * ; + * + * CHAPTER 15.10 + * initializerBlock: + * 'static' block + * ; + */ + +class Test { + static { + for (let i = 1; i < 10; i++) { + let x = 0; + } + } +} diff --git a/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/forStatement/forStatement_lambdaExpressionWithReceiver.ets b/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/forStatement/forStatement_lambdaExpressionWithReceiver.ets new file mode 100644 index 0000000000000000000000000000000000000000..7bcc878912b1ec83ab5c2b549f20d64766f235fd --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/forStatement/forStatement_lambdaExpressionWithReceiver.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 8.8 + * forStatement: + * 'for' '(' forInit? ';' forContinue? ';' forUpdate? ')' statement + * ; + * + * CHAPTER 17.12.5 + * lambdaExpressionWithReceiver: + * annotationUsage? typeParameters? + * '(' receiverParameter (',' lambdaParameterList)? ')' + * returnType? throwMark? '=>' lambdaBody + * ; + */ + +class A {} + +for (let i = 1; i < 10; i++) { + let result = (this: A) => { + let b = 2; + return b; + } +} diff --git a/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/forStatement/forStatement_namespaceDeclaration.ets b/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/forStatement/forStatement_namespaceDeclaration.ets new file mode 100644 index 0000000000000000000000000000000000000000..3692feafacda6c557a47ba861c1c4874c2f30a64 --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/forStatement/forStatement_namespaceDeclaration.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 8.8 + * forStatement: + * 'for' '(' forInit? ';' forContinue? ';' forUpdate? ')' statement + * ; + * + * CHAPTER 13.8 + * namespaceDeclaration: + * 'namespace' qualifiedName + * '{' topDeclaration* initializerBlock? topDeclaration* '}' + * ; + */ + +namespace A { + for (let i = 1; i < 10; i++) { + let a: number = 1; + } +} diff --git a/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/forStatement/forStatement_newArrayInstance.ets b/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/forStatement/forStatement_newArrayInstance.ets new file mode 100644 index 0000000000000000000000000000000000000000..e3ab7bc349b519e49046f73668e51fdd847a73c6 --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/forStatement/forStatement_newArrayInstance.ets @@ -0,0 +1,31 @@ +/* + * 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 8.8 + * forStatement: + * 'for' '(' forInit? ';' forContinue? ';' forUpdate? ')' statement + * ; + * + * CHAPTER 17.3 + * newArrayInstance: + * 'new' arrayElementType dimensionExpression+ (arrayElement)? + * ; + */ + +for (let i = 1; i < 10; i++) { + let x = 1; + let a = new string[x]; +} diff --git a/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/forStatement/forStatement_returnStatement.ets b/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/forStatement/forStatement_returnStatement.ets new file mode 100644 index 0000000000000000000000000000000000000000..2999405cdf7433b01e0303dd1c13c0e8d0188afe --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/forStatement/forStatement_returnStatement.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 8.8 + * forStatement: + * 'for' '(' forInit? ';' forContinue? ';' forUpdate? ')' statement + * ; + * + * CHAPTER 8.12 + * returnStatement: + * 'return' expression? + * ; + */ + +function add(x1: number, x2: number): number { + for (let i = 1; i < 10; i++) { + return 1; + } + return 0; +} diff --git a/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/forStatement/forStatement_separateModuleDeclaration.ets b/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/forStatement/forStatement_separateModuleDeclaration.ets new file mode 100644 index 0000000000000000000000000000000000000000..793d6798202c90d3d94fb50f5f19cf69f12537ca --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/forStatement/forStatement_separateModuleDeclaration.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 8.8 + * forStatement: + * 'for' '(' forInit? ';' forContinue? ';' forUpdate? ')' statement + * ; + * + * CHAPTER 13.1 + * separateModuleDeclaration: + * importDirective* (topDeclaration | topLevelStatements | exportDirective)* + * ; + */ + +for (let i = 1; i < 10; i++) {} diff --git a/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/forStatement/forStatement_switchStatement.ets b/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/forStatement/forStatement_switchStatement.ets new file mode 100644 index 0000000000000000000000000000000000000000..f98aa87a8a9eb8a6dee0c5bda662438e6e6662f5 --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/forStatement/forStatement_switchStatement.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 8.8 + * forStatement: + * 'for' '(' forInit? ';' forContinue? ';' forUpdate? ')' statement + * ; + * + * CHAPTER 8.13 + * switchStatement: + * (identifier ':')? 'switch' '(' expression ')' switchBlock + * ; + */ + +let x = 1; +switch (x) { + case 1: + for (let i = 1; i < 10; i++) { + break; + } + break; + default: + break; +} diff --git a/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/forStatement/forStatement_throwStatement.ets b/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/forStatement/forStatement_throwStatement.ets new file mode 100644 index 0000000000000000000000000000000000000000..0e5d628ec1a7f66d4e7466b4ada735b60bfa880a --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/forStatement/forStatement_throwStatement.ets @@ -0,0 +1,31 @@ +/* + * 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 8.8 + * forStatement: + * 'for' '(' forInit? ';' forContinue? ';' forUpdate? ')' statement + * ; + * + * CHAPTER 8.14 + * throwStatement: + * 'throw' expression + * ; + */ + +let x = new Error("1"); +for (let i = 1; i < 10; i++) { + throw (x = new Error("2")); +} diff --git a/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/forStatement/forStatement_topDeclaration.ets b/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/forStatement/forStatement_topDeclaration.ets new file mode 100644 index 0000000000000000000000000000000000000000..f4b5a7ad4aead6197297bc0bb22c55bfa6ae9045 --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/forStatement/forStatement_topDeclaration.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 8.8 + * forStatement: + * 'for' '(' forInit? ';' forContinue? ';' forUpdate? ')' statement + * ; + * + * CHAPTER 13.7 + * topDeclaration: + * ('export' 'default'?)? + * annotationUsage? + * ( typeDeclaration + * | variableDeclarations + * | constantDeclarations + * | functionDeclaration + * | functionWithReceiverDeclaration + * | accessorWithReceiverDeclaration + * | namespaceDeclaration + * ) + * ; + */ + +for (let i = 1; i < 10; i++) {} diff --git a/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/forStatement/forStatement_topLevelStatements.ets b/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/forStatement/forStatement_topLevelStatements.ets new file mode 100644 index 0000000000000000000000000000000000000000..c5408306aad253589fbf4e403b3be34602a45b3f --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/forStatement/forStatement_topLevelStatements.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 8.8 + * forStatement: + * 'for' '(' forInit? ';' forContinue? ';' forUpdate? ')' statement + * ; + * + * CHAPTER 13.10 + * topLevelStatements: + * statement* + * ; + */ + +for (let i = 1; i < 10; i++) {} diff --git a/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/forStatement/forStatement_trailingLambdaCall.ets b/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/forStatement/forStatement_trailingLambdaCall.ets new file mode 100644 index 0000000000000000000000000000000000000000..4e7333fff8d96cba44ac9417e59fb27a1c07ec99 --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/forStatement/forStatement_trailingLambdaCall.ets @@ -0,0 +1,42 @@ +/* + * 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 8.8 + * forStatement: + * 'for' '(' forInit? ';' forContinue? ';' forUpdate? ')' statement + * ; + * + * CHAPTER 17.13 + * trailingLambdaCall: + * ( objectReference '.' identifier typeArguments? + * | expression ('?.' | typeArguments)? + * ) + * arguments block + * ; + */ + +class A { + x(arg: T, callback: (result: T) => void): number { + const result = arg; + callback(result); + return 0; + } +} + +let a = new A(); +for (let i = 1; i < 10; i++) { + let test = a.x("Hi") {} +} diff --git a/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/forStatement/forStatement_tryStatement.ets b/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/forStatement/forStatement_tryStatement.ets new file mode 100644 index 0000000000000000000000000000000000000000..7f9cbc33bffe69ab0d5426f82af71820c4bc2a06 --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/forStatement/forStatement_tryStatement.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 8.8 + * forStatement: + * 'for' '(' forInit? ';' forContinue? ';' forUpdate? ')' statement + * ; + * + * CHAPTER 8.15 + * tryStatement: + * 'try' block catchClauses finallyClause? + * ; + */ + +function processOne(a: number): number { + try { + let counter = 0; + for (let i = 1; i < 10; i++) { + counter++; + if (counter === 5) { + throw new Error("Counter reached 5"); + } + } + return 0; + } catch (error) { + return -1; + } +} diff --git a/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/ifStatement/ifStatement_awaitExpression.ets b/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/ifStatement/ifStatement_awaitExpression.ets new file mode 100644 index 0000000000000000000000000000000000000000..4b546ae1f663781bec373063bdc64d0ad41112cd --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/ifStatement/ifStatement_awaitExpression.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 8.5 + * ifStatement: + * 'if' '(' expression ')' thenStatement + * ('else' elseStatement)? + * ; + * + * CHAPTER 17.16.2 + * awaitExpression: + * 'await' expression + * ; + */ + +async function foo(): Promise { + return 42.0; +} + +async function main() { + let x = foo(); + if (true) { + let result = await x; + } +} diff --git a/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/ifStatement/ifStatement_breakStatement.ets b/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/ifStatement/ifStatement_breakStatement.ets new file mode 100644 index 0000000000000000000000000000000000000000..a5a25d4dcb6d2a725cb91a64b4b309fd1f9afe27 --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/ifStatement/ifStatement_breakStatement.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 8.5 + * ifStatement: + * 'if' '(' expression ')' thenStatement + * ('else' elseStatement)? + * ; + * + * CHAPTER 8.10 + * breakStatement: + * 'break' identifier? + * ; + */ + +for (let x = 0; x < 5; x++) { + if (x === 2) { + break; + } +} diff --git a/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/ifStatement/ifStatement_classInitializer.ets b/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/ifStatement/ifStatement_classInitializer.ets new file mode 100644 index 0000000000000000000000000000000000000000..1edc9d9f3043abbe5e4664a9f551db2afb90fab7 --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/ifStatement/ifStatement_classInitializer.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 8.5 + * ifStatement: + * 'if' '(' expression ')' thenStatement + * ('else' elseStatement)? + * ; + * + * CHAPTER 9.8 + * classInitializer: + * initializerBlock + * ; + */ + +class X { + static initialized = false; + static initializerBlock() { + if (!X.initialized) { + X.initialized = true; + } + } +} diff --git a/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/ifStatement/ifStatement_continueStatement.ets b/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/ifStatement/ifStatement_continueStatement.ets new file mode 100644 index 0000000000000000000000000000000000000000..db10ddcb954dc24ed5900c01d007a4c8aec2e69b --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/ifStatement/ifStatement_continueStatement.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 8.5 + * ifStatement: + * 'if' '(' expression ')' thenStatement + * ('else' elseStatement)? + * ; + * + * CHAPTER 8.11 + * continueStatement: + * 'continue' identifier? + * ; + */ + +x: for (let i = 0; i < 3; i++) { + if (i === 1) { + continue x; + } +} diff --git a/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/ifStatement/ifStatement_enumDeclaration.ets b/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/ifStatement/ifStatement_enumDeclaration.ets new file mode 100644 index 0000000000000000000000000000000000000000..caa6d636323b8e20ebcf3e84f5d9a7cc82f942bb --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/ifStatement/ifStatement_enumDeclaration.ets @@ -0,0 +1,31 @@ +/* + * 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 8.5 + * ifStatement: + * 'if' '(' expression ')' thenStatement + * ('else' elseStatement)? + * ; + * + * CHAPTER 11 + * enumDeclaration: + * 'const'? 'enum' identifier '{' enumConstantList '}' + * ; + */ + +if (true) { + const enum x { Red = 1, Green = 2, Blue = 3 } +} diff --git a/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/ifStatement/ifStatement_finallyClause.ets b/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/ifStatement/ifStatement_finallyClause.ets new file mode 100644 index 0000000000000000000000000000000000000000..7640bdd92b7f4d25c55e35aafb7a2ab9248035ec --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/ifStatement/ifStatement_finallyClause.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 8.5 + * ifStatement: + * 'if' '(' expression ')' thenStatement + * ('else' elseStatement)? + * ; + * + * CHAPTER 8.15.2 + * finallyClause: + * 'finally' block + * ; + */ + +if (true) { + try { + } catch (error) { + } finally { + let x = 1; + } +} diff --git a/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/ifStatement/ifStatement_forOfStatement.ets b/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/ifStatement/ifStatement_forOfStatement.ets new file mode 100644 index 0000000000000000000000000000000000000000..f500a56d257f8f54f258f7be95a56f26b1eb6db0 --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/ifStatement/ifStatement_forOfStatement.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. + */ + +/** + * CHAPTER 8.5 + * ifStatement: + * 'if' '(' expression ')' thenStatement + * ('else' elseStatement)? + * ; + * + * CHAPTER 8.9 + * forOfStatement: + * 'for' '(' forVariable 'of' expression ')' statement + * ; + */ + +let arr = [1, 2, 3]; +for (let x of arr = [0]) { + if (true) { + break; + } +} diff --git a/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/ifStatement/ifStatement_forStatement.ets b/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/ifStatement/ifStatement_forStatement.ets new file mode 100644 index 0000000000000000000000000000000000000000..489bc01d222aabe6e1e009e39ff57a931dd002d4 --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/ifStatement/ifStatement_forStatement.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 8.5 + * ifStatement: + * 'if' '(' expression ')' thenStatement + * ('else' elseStatement)? + * ; + * + * CHAPTER 8.8 + * forStatement: + * 'for' '(' forInit? ';' forContinue? ';' forUpdate? ')' statement + * ; + */ + +for (let x = 1; x < 10; x++) { + if (true) { + break; + } +} diff --git a/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/ifStatement/ifStatement_functionTypeWithReceiver.ets b/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/ifStatement/ifStatement_functionTypeWithReceiver.ets new file mode 100644 index 0000000000000000000000000000000000000000..8adc562cc68b3bea1d6e4bce579a1a99c146f069 --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/ifStatement/ifStatement_functionTypeWithReceiver.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 8.5 + * ifStatement: + * 'if' '(' expression ')' thenStatement + * ('else' elseStatement)? + * ; + * + * CHAPTER 17.12.4 + * functionTypeWithReceiver: + * '(' receiverParameter (',' ftParameterList)? ')' ftReturnType + * ; + */ + +class A {} + +if (true) { + type FA = (this: A) => boolean; +} diff --git a/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/ifStatement/ifStatement_initializerBlock.ets b/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/ifStatement/ifStatement_initializerBlock.ets new file mode 100644 index 0000000000000000000000000000000000000000..21849d3b3bbfd3449760acdda352d195d57e7189 --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/ifStatement/ifStatement_initializerBlock.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 8.5 + * ifStatement: + * 'if' '(' expression ')' thenStatement + * ('else' elseStatement)? + * ; + * + * CHAPTER 15.10 + * initializerBlock: + * 'static' block + * ; + */ + +class Test { + static { + if (true) { + let x = 0; + } + } +} diff --git a/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/ifStatement/ifStatement_lambdaExpressionWithReceiver.ets b/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/ifStatement/ifStatement_lambdaExpressionWithReceiver.ets new file mode 100644 index 0000000000000000000000000000000000000000..d5dae35f09ee73cda6b817c67909385789a1af6d --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/ifStatement/ifStatement_lambdaExpressionWithReceiver.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 8.5 + * ifStatement: + * 'if' '(' expression ')' thenStatement + * ('else' elseStatement)? + * ; + * + * CHAPTER 17.12.5 + * lambdaExpressionWithReceiver: + * annotationUsage? typeParameters? + * '(' receiverParameter (',' lambdaParameterList)? ')' + * returnType? throwMark? '=>' lambdaBody + * ; + */ + +class A {} + +if (true) { + let result = (this: A) => { + let b = 2; + return b; + }; +} diff --git a/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/ifStatement/ifStatement_loopStatement.ets b/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/ifStatement/ifStatement_loopStatement.ets new file mode 100644 index 0000000000000000000000000000000000000000..7bc00484a3a858b88f06df615d424ea991422f80 --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/ifStatement/ifStatement_loopStatement.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 8.5 + * ifStatement: + * 'if' '(' expression ')' thenStatement + * ('else' elseStatement)? + * ; + * + * CHAPTER 8.6 + * loopStatement: + * (identifier ':')? + * whileStatement + * | doStatement + * | forStatement + * | forOfStatement + * ; + */ + +while(true) { + if (true) { + let x = 1; + } + break; +} diff --git a/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/ifStatement/ifStatement_namespaceDeclaration.ets b/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/ifStatement/ifStatement_namespaceDeclaration.ets new file mode 100644 index 0000000000000000000000000000000000000000..8857bfe9e16340133e90a0f47f5e0a6aef0df0f1 --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/ifStatement/ifStatement_namespaceDeclaration.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. + */ + +/** + * CHAPTER 8.5 + * ifStatement: + * 'if' '(' expression ')' thenStatement + * ('else' elseStatement)? + * ; + * + * CHAPTER 13.8 + * namespaceDeclaration: + * 'namespace' qualifiedName + * '{' topDeclaration* initializerBlock? topDeclaration* '}' + * ; + */ + +namespace A { + if (true) { + let a: number = 1; + } +} diff --git a/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/ifStatement/ifStatement_newArrayInstance.ets b/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/ifStatement/ifStatement_newArrayInstance.ets new file mode 100644 index 0000000000000000000000000000000000000000..c47296da08684f2ebdfeed43a7952de0f262582a --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/ifStatement/ifStatement_newArrayInstance.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 8.5 + * ifStatement: + * 'if' '(' expression ')' thenStatement + * ('else' elseStatement)? + * ; + * + * CHAPTER 17.3 + * newArrayInstance: + * 'new' arrayElementType dimensionExpression+ (arrayElement)? + * ; + */ + +if (true) { + let x = 1; + let a = new string[x]; +} diff --git a/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/ifStatement/ifStatement_returnStatement.ets b/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/ifStatement/ifStatement_returnStatement.ets new file mode 100644 index 0000000000000000000000000000000000000000..08bf1ec51cb0a8ad4f8eea24e4b52db349561490 --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/ifStatement/ifStatement_returnStatement.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 8.5 + * ifStatement: + * 'if' '(' expression ')' thenStatement + * ('else' elseStatement)? + * ; + * + * CHAPTER 8.12 + * returnStatement: + * 'return' expression? + * ; + */ + +function add(x1: number, x2: number): number { + if (true) { + return 1; + } else { + return x1 + x2; + } +} diff --git a/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/ifStatement/ifStatement_separateModuleDeclaration.ets b/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/ifStatement/ifStatement_separateModuleDeclaration.ets new file mode 100644 index 0000000000000000000000000000000000000000..7831dce888d717ea74e360fa1c36deaea2a71b1a --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/ifStatement/ifStatement_separateModuleDeclaration.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 8.5 + * ifStatement: + * 'if' '(' expression ')' thenStatement + * ('else' elseStatement)? + * ; + * + * CHAPTER 13.1 + * separateModuleDeclaration: + * importDirective* (topDeclaration | topLevelStatements | exportDirective)* + * ; + */ + +if (true) {}; diff --git a/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/ifStatement/ifStatement_switchStatement.ets b/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/ifStatement/ifStatement_switchStatement.ets new file mode 100644 index 0000000000000000000000000000000000000000..7f568bd75b9cc2475e9e272b0076f708e6a2aaa2 --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/ifStatement/ifStatement_switchStatement.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 8.5 + * ifStatement: + * 'if' '(' expression ')' thenStatement + * ('else' elseStatement)? + * ; + * + * CHAPTER 8.13 + * switchStatement: + * (identifier ':')? 'switch' '(' expression ')' switchBlock + * ; + */ + +let x = 1; +switch (x) { + case 1: + if (true) { + break; + } else { + break; + } + default: + break; +} diff --git a/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/ifStatement/ifStatement_throwStatement.ets b/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/ifStatement/ifStatement_throwStatement.ets new file mode 100644 index 0000000000000000000000000000000000000000..9ee54c1a1327af1b5e341678826029fc36265774 --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/ifStatement/ifStatement_throwStatement.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 8.5 + * ifStatement: + * 'if' '(' expression ')' thenStatement + * ('else' elseStatement)? + * ; + * + * CHAPTER 8.14 + * throwStatement: + * 'throw' expression + * ; + */ + +let x = new Error("1"); +if (true) { + throw (x = new Error("2")); +} diff --git a/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/ifStatement/ifStatement_topDeclaration.ets b/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/ifStatement/ifStatement_topDeclaration.ets new file mode 100644 index 0000000000000000000000000000000000000000..1aa87cab4f53405fe79097d01e483489fd8a03ca --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/ifStatement/ifStatement_topDeclaration.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 8.5 + * ifStatement: + * 'if' '(' expression ')' thenStatement + * ('else' elseStatement)? + * ; + * + * CHAPTER 13.7 + * topDeclaration: + * ('export' 'default'?)? + * annotationUsage? + * ( typeDeclaration + * | variableDeclarations + * | constantDeclarations + * | functionDeclaration + * | functionWithReceiverDeclaration + * | accessorWithReceiverDeclaration + * | namespaceDeclaration + * ) + * ; + */ + +if (true) {}; diff --git a/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/ifStatement/ifStatement_topLevelStatements.ets b/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/ifStatement/ifStatement_topLevelStatements.ets new file mode 100644 index 0000000000000000000000000000000000000000..fea04b3b5a976a172ad158217a66112c139c62db --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/ifStatement/ifStatement_topLevelStatements.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 8.5 + * ifStatement: + * 'if' '(' expression ')' thenStatement + * ('else' elseStatement)? + * ; + * + * CHAPTER 13.10 + * topLevelStatements: + * statement* + * ; + */ + +if (true) {}; diff --git a/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/ifStatement/ifStatement_trailingLambdaCall.ets b/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/ifStatement/ifStatement_trailingLambdaCall.ets new file mode 100644 index 0000000000000000000000000000000000000000..459b972659d4a8867f17d47896a3cff2e8c8c366 --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/ifStatement/ifStatement_trailingLambdaCall.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 8.5 + * ifStatement: + * 'if' '(' expression ')' thenStatement + * ('else' elseStatement)? + * ; + * + * CHAPTER 17.13 + * trailingLambdaCall: + * ( objectReference '.' identifier typeArguments? + * | expression ('?.' | typeArguments)? + * ) + * arguments block + * ; + */ + +class A { + x(arg: T, callback: (result: T) => void): number { + const result = arg; + callback(result); + return 0; + } +} + +let a = new A(); +if (true) { + let test = a.x("Hi") {} +} diff --git a/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/ifStatement/ifStatement_tryStatement.ets b/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/ifStatement/ifStatement_tryStatement.ets new file mode 100644 index 0000000000000000000000000000000000000000..dccd7e6aca53e030fe31afb63e6c1df4590dbf37 --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/ifStatement/ifStatement_tryStatement.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 8.5 + * ifStatement: + * 'if' '(' expression ')' thenStatement + * ('else' elseStatement)? + * ; + * + * CHAPTER 8.15 + * tryStatement: + * 'try' block catchClauses finallyClause? + * ; + */ + +function processTwo(a: number): number { + try { + if (true) { + const x = 1; + } + return 0; + } catch (error) { + return -1; + } +} diff --git a/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/ifStatement/ifStatement_whileStatement.ets b/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/ifStatement/ifStatement_whileStatement.ets new file mode 100644 index 0000000000000000000000000000000000000000..36bd223f571ed449af96fa3cec63b1091ba193e6 --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/ifStatement/ifStatement_whileStatement.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 8.5 + * ifStatement: + * 'if' '(' expression ')' thenStatement + * ('else' elseStatement)? + * ; + * + * CHAPTER 8.7 + * whileStatement: + * 'while' '(' expression ')' statement + * ; + */ + +let x = 5; +let n = 3; +while (x &= n) { + if (x > n) { + console.log("x is greater than n"); + } +} diff --git a/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/loopStatement/loopStatement_awaitExpression.ets b/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/loopStatement/loopStatement_awaitExpression.ets new file mode 100644 index 0000000000000000000000000000000000000000..5a5743a425861a74c9aef20b0d19afada3f2e2c7 --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/loopStatement/loopStatement_awaitExpression.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 8.6 + * loopStatement: + * (identifier ':')? + * whileStatement + * | doStatement + * | forStatement + * | forOfStatement + * ; + * + * CHAPTER 17.16.2 + * awaitExpression: + * 'await' expression + * ; + */ + +async function foo(): Promise { + return 42.0; +} + +async function main() { + let x = foo(); + while (true) { + let result = await x; + } +} diff --git a/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/loopStatement/loopStatement_breakStatement.ets b/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/loopStatement/loopStatement_breakStatement.ets new file mode 100644 index 0000000000000000000000000000000000000000..97560b45b017a7dd0c8e6dfa121f153e6c6eab78 --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/loopStatement/loopStatement_breakStatement.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 8.6 + * loopStatement: + * (identifier ':')? + * whileStatement + * | doStatement + * | forStatement + * | forOfStatement + * ; + * + * CHAPTER 8.10 + * breakStatement: + * 'break' identifier? + * ; + */ + +for (let x = 0; x < 5; x++) { + while (x === 2) { + break; + } +} diff --git a/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/loopStatement/loopStatement_classInitializer.ets b/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/loopStatement/loopStatement_classInitializer.ets new file mode 100644 index 0000000000000000000000000000000000000000..68ecb38a58c981f198b23288e9a2ce430070e72a --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/loopStatement/loopStatement_classInitializer.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 8.6 + * loopStatement: + * (identifier ':')? + * whileStatement + * | doStatement + * | forStatement + * | forOfStatement + * ; + * + * CHAPTER 9.8 + * classInitializer: + * initializerBlock + * ; + */ + +class X { + static initialized = false; + static initializerBlock() { + while (!X.initialized) { + X.initialized = true; + } + } +} diff --git a/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/loopStatement/loopStatement_continueStatement.ets b/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/loopStatement/loopStatement_continueStatement.ets new file mode 100644 index 0000000000000000000000000000000000000000..724d2efd89e8de7e5c187eae862af2a716255849 --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/loopStatement/loopStatement_continueStatement.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 8.6 + * loopStatement: + * (identifier ':')? + * whileStatement + * | doStatement + * | forStatement + * | forOfStatement + * ; + * + * CHAPTER 8.11 + * continueStatement: + * 'continue' identifier? + * ; + */ + +x: for (let i = 0; i < 3; i++) { + while (i === 1) { + continue x; + } +} diff --git a/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/loopStatement/loopStatement_enumDeclaration.ets b/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/loopStatement/loopStatement_enumDeclaration.ets new file mode 100644 index 0000000000000000000000000000000000000000..98e38966482fa495cd0c6d21a3713483b16d2c72 --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/loopStatement/loopStatement_enumDeclaration.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. + */ + +/** + * CHAPTER 8.6 + * loopStatement: + * (identifier ':')? + * whileStatement + * | doStatement + * | forStatement + * | forOfStatement + * ; + * + * CHAPTER 11 + * enumDeclaration: + * 'const'? 'enum' identifier '{' enumConstantList '}' + * ; + */ + +while (true) { + const enum x { Red = 1, Green = 2, Blue = 3 } +} diff --git a/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/loopStatement/loopStatement_finallyClause.ets b/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/loopStatement/loopStatement_finallyClause.ets new file mode 100644 index 0000000000000000000000000000000000000000..72d2745e704c953169be46d878c89c7960845ad3 --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/loopStatement/loopStatement_finallyClause.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 8.6 + * loopStatement: + * (identifier ':')? + * whileStatement + * | doStatement + * | forStatement + * | forOfStatement + * ; + * + * CHAPTER 8.15.2 + * finallyClause: + * 'finally' block + * ; + */ + +while (true) { + try { + } catch (error) { + } finally { + let x = 1; + } +} + diff --git a/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/loopStatement/loopStatement_forOfStatement.ets b/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/loopStatement/loopStatement_forOfStatement.ets new file mode 100644 index 0000000000000000000000000000000000000000..145445af837e29e63269443415edb446a54f81f9 --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/loopStatement/loopStatement_forOfStatement.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 8.6 + * loopStatement: + * (identifier ':')? + * whileStatement + * | doStatement + * | forStatement + * | forOfStatement + * ; + * + * CHAPTER 8.9 + * forOfStatement: + * 'for' '(' forVariable 'of' expression ')' statement + * ; + */ + +let arr = [1, 2, 3]; +for (let x of arr = [0]) { + while (true) { + break; + } +} diff --git a/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/loopStatement/loopStatement_forStatement.ets b/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/loopStatement/loopStatement_forStatement.ets new file mode 100644 index 0000000000000000000000000000000000000000..c3f4eee408062cdaefa41b217387ce2dc825c3d8 --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/loopStatement/loopStatement_forStatement.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 8.6 + * loopStatement: + * (identifier ':')? + * whileStatement + * | doStatement + * | forStatement + * | forOfStatement + * ; + * + * CHAPTER 8.8 + * forStatement: + * 'for' '(' forInit? ';' forContinue? ';' forUpdate? ')' statement + * ; + */ + +for (let x = 1; x < 10; x++) { + while (true) { + break; + } +} diff --git a/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/loopStatement/loopStatement_functionTypeWithReceiver.ets b/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/loopStatement/loopStatement_functionTypeWithReceiver.ets new file mode 100644 index 0000000000000000000000000000000000000000..b50d7175d8b623575f8b2a0ecd71e83224e5277d --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/loopStatement/loopStatement_functionTypeWithReceiver.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 8.6 + * loopStatement: + * (identifier ':')? + * whileStatement + * | doStatement + * | forStatement + * | forOfStatement + * ; + * + * CHAPTER 17.12.4 + * functionTypeWithReceiver: + * '(' receiverParameter (',' ftParameterList)? ')' ftReturnType + * ; + */ + +class A {} + +while (true) { + type FA = (this: A) => boolean; +} diff --git a/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/loopStatement/loopStatement_initializerBlock.ets b/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/loopStatement/loopStatement_initializerBlock.ets new file mode 100644 index 0000000000000000000000000000000000000000..07bce690359a15d031436fc8a11364ff9d96faa2 --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/loopStatement/loopStatement_initializerBlock.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 8.6 + * loopStatement: + * (identifier ':')? + * whileStatement + * | doStatement + * | forStatement + * | forOfStatement + * ; + * + * CHAPTER 15.10 + * initializerBlock: + * 'static' block + * ; + */ + +class Test { + static { + while (true) { + let x = 0; + } + } +} diff --git a/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/loopStatement/loopStatement_lambdaExpressionWithReceiver.ets b/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/loopStatement/loopStatement_lambdaExpressionWithReceiver.ets new file mode 100644 index 0000000000000000000000000000000000000000..e2b1872c2f832278d245fab9592c5bdf76459c11 --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/loopStatement/loopStatement_lambdaExpressionWithReceiver.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 8.6 + * loopStatement: + * (identifier ':')? + * whileStatement + * | doStatement + * | forStatement + * | forOfStatement + * ; + * + * CHAPTER 17.12.5 + * lambdaExpressionWithReceiver: + * annotationUsage? typeParameters? + * '(' receiverParameter (',' lambdaParameterList)? ')' + * returnType? throwMark? '=>' lambdaBody + * ; + */ + +class A {} + +while (true) { + let result = (this: A) => { + let b = 2; + return b; + }; +} diff --git a/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/loopStatement/loopStatement_namespaceDeclaration.ets b/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/loopStatement/loopStatement_namespaceDeclaration.ets new file mode 100644 index 0000000000000000000000000000000000000000..281187a2f553ace07105373fb4373ec9b256aca6 --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/loopStatement/loopStatement_namespaceDeclaration.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 8.6 + * loopStatement: + * (identifier ':')? + * whileStatement + * | doStatement + * | forStatement + * | forOfStatement + * ; + * + * CHAPTER 13.8 + * namespaceDeclaration: + * 'namespace' qualifiedName + * '{' topDeclaration* initializerBlock? topDeclaration* '}' + * ; + */ + +namespace A { + while (true) { + let a: number = 1; + } +} diff --git a/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/loopStatement/loopStatement_newArrayInstance.ets b/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/loopStatement/loopStatement_newArrayInstance.ets new file mode 100644 index 0000000000000000000000000000000000000000..7b47b513ef51659ec930594dddda48e2127b3c49 --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/loopStatement/loopStatement_newArrayInstance.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 8.6 + * loopStatement: + * (identifier ':')? + * whileStatement + * | doStatement + * | forStatement + * | forOfStatement + * ; + * + * CHAPTER 17.3 + * newArrayInstance: + * 'new' arrayElementType dimensionExpression+ (arrayElement)? + * ; + */ + +while (true) { + let x = 1; + let a = new string[x]; +} diff --git a/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/loopStatement/loopStatement_returnStatement.ets b/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/loopStatement/loopStatement_returnStatement.ets new file mode 100644 index 0000000000000000000000000000000000000000..b1af74844dd9ea577296df9356c7e3ddaada3966 --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/loopStatement/loopStatement_returnStatement.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 8.6 + * loopStatement: + * (identifier ':')? + * whileStatement + * | doStatement + * | forStatement + * | forOfStatement + * ; + * + * CHAPTER 8.12 + * returnStatement: + * 'return' expression? + * ; + */ + +function add(x1: number, x2: number): number { + while (true) { + return 1; + } +} diff --git a/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/loopStatement/loopStatement_separateModuleDeclaration.ets b/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/loopStatement/loopStatement_separateModuleDeclaration.ets new file mode 100644 index 0000000000000000000000000000000000000000..590fc9f9440ef05851008ded543eaf037a1b1c64 --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/loopStatement/loopStatement_separateModuleDeclaration.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 8.6 + * loopStatement: + * (identifier ':')? + * whileStatement + * | doStatement + * | forStatement + * | forOfStatement + * ; + * + * CHAPTER 13.1 + * separateModuleDeclaration: + * importDirective* (topDeclaration | topLevelStatements | exportDirective)* + * ; + */ + +while (true) {}; diff --git a/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/loopStatement/loopStatement_switchStatement.ets b/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/loopStatement/loopStatement_switchStatement.ets new file mode 100644 index 0000000000000000000000000000000000000000..23a11430021fc3d5ec399f308ae9043c29601217 --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/loopStatement/loopStatement_switchStatement.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 8.6 + * loopStatement: + * (identifier ':')? + * whileStatement + * | doStatement + * | forStatement + * | forOfStatement + * ; + * + * CHAPTER 8.13 + * switchStatement: + * (identifier ':')? 'switch' '(' expression ')' switchBlock + * ; + */ + +let x = 1; +switch (x) { + case 1: + while (true) { + break; + } + break; + default: + break; +} diff --git a/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/loopStatement/loopStatement_throwStatement.ets b/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/loopStatement/loopStatement_throwStatement.ets new file mode 100644 index 0000000000000000000000000000000000000000..ae715c5785c989f6b2f3abcd91c016c04e53b219 --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/loopStatement/loopStatement_throwStatement.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 8.6 + * loopStatement: + * (identifier ':')? + * whileStatement + * | doStatement + * | forStatement + * | forOfStatement + * ; + * + * CHAPTER 8.14 + * throwStatement: + * 'throw' expression + * ; + */ + +let x = new Error("1"); +while (true) { + throw (x = new Error("2")); +} diff --git a/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/loopStatement/loopStatement_topDeclaration.ets b/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/loopStatement/loopStatement_topDeclaration.ets new file mode 100644 index 0000000000000000000000000000000000000000..12a293277ab2f9faedd307ba433ee94fa8b52766 --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/loopStatement/loopStatement_topDeclaration.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 8.6 + * loopStatement: + * (identifier ':')? + * whileStatement + * | doStatement + * | forStatement + * | forOfStatement + * ; + * + * CHAPTER 13.7 + * topDeclaration: + * ('export' 'default'?)? + * annotationUsage? + * ( typeDeclaration + * | variableDeclarations + * | constantDeclarations + * | functionDeclaration + * | functionWithReceiverDeclaration + * | accessorWithReceiverDeclaration + * | namespaceDeclaration + * ) + * ; + */ + +while (true) {}; diff --git a/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/loopStatement/loopStatement_topLevelStatements.ets b/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/loopStatement/loopStatement_topLevelStatements.ets new file mode 100644 index 0000000000000000000000000000000000000000..e6151e370edf140b06015aaa7cb94ecba5abb8a5 --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/loopStatement/loopStatement_topLevelStatements.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 8.6 + * loopStatement: + * (identifier ':')? + * whileStatement + * | doStatement + * | forStatement + * | forOfStatement + * ; + * + * CHAPTER 13.10 + * topLevelStatements: + * statement* + * ; + */ + +while (true) {}; diff --git a/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/loopStatement/loopStatement_trailingLambdaCall.ets b/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/loopStatement/loopStatement_trailingLambdaCall.ets new file mode 100644 index 0000000000000000000000000000000000000000..de731977b0d235b0c3c6d82b3c62e55eee863084 --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/loopStatement/loopStatement_trailingLambdaCall.ets @@ -0,0 +1,46 @@ +/* + * 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 8.6 + * loopStatement: + * (identifier ':')? + * whileStatement + * | doStatement + * | forStatement + * | forOfStatement + * ; + * + * CHAPTER 17.13 + * trailingLambdaCall: + * ( objectReference '.' identifier typeArguments? + * | expression ('?.' | typeArguments)? + * ) + * arguments block + * ; + */ + +class A { + x(arg: T, callback: (result: T) => void): number { + const result = arg; + callback(result); + return 0; + } +} + +let a = new A(); +while (true) { + let test = a.x("Hi") {} +} diff --git a/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/loopStatement/loopStatement_tryStatement.ets b/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/loopStatement/loopStatement_tryStatement.ets new file mode 100644 index 0000000000000000000000000000000000000000..6d3c11b5ca3a9eaa0a941acc0749201844f6238d --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/loopStatement/loopStatement_tryStatement.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 8.6 + * loopStatement: + * (identifier ':')? + * whileStatement + * | doStatement + * | forStatement + * | forOfStatement + * ; + * + * CHAPTER 8.15 + * tryStatement: + * 'try' block catchClauses finallyClause? + * ; + */ + +function processOne(a: number): number { + try { + let counter = 0; + while (counter < 10) { + counter++; + if (counter === 5) { + throw new Error("Counter reached 5"); + } + } + return 0; + } catch (error) { + return -1; + } +} diff --git a/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/loopStatement/loopStatement_whileStatement.ets b/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/loopStatement/loopStatement_whileStatement.ets new file mode 100644 index 0000000000000000000000000000000000000000..e6b50144c44a316b04505dd398838687aa2107b2 --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/loopStatement/loopStatement_whileStatement.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 8.6 + * loopStatement: + * (identifier ':')? + * whileStatement + * | doStatement + * | forStatement + * | forOfStatement + * ; + * + * CHAPTER 8.7 + * whileStatement: + * 'while' '(' expression ')' statement + * ; + */ + +let x = 5; +let n = 3; +while (x &= n) { + while (x > n) { + console.log("x is greater than n"); + } +} diff --git a/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/returnStatement/returnStatement_awaitExpression.ets b/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/returnStatement/returnStatement_awaitExpression.ets new file mode 100644 index 0000000000000000000000000000000000000000..d841c8f77e81aa0a5577dfb18329509eb79b54c9 --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/returnStatement/returnStatement_awaitExpression.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 8.12 + * returnStatement: + * 'return' expression? + * ; + * + * CHAPTER 17.16.2 + * awaitExpression: + * 'await' expression + * ; + */ + +async function foo(): Promise { + return 42.0; +} + +async function main() { + let x = foo(); + if (true) { + return await x; + } +} diff --git a/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/returnStatement/returnStatement_classInitializer.ets b/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/returnStatement/returnStatement_classInitializer.ets new file mode 100644 index 0000000000000000000000000000000000000000..b046f5435b8fc263b942fb3de57f154c169f6263 --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/returnStatement/returnStatement_classInitializer.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 8.12 + * returnStatement: + * 'return' expression? + * ; + * + * CHAPTER 9.8 + * classInitializer: + * initializerBlock + * ; + */ + +class X { + static initialized = false; + static initializerBlock() { + return; + } +} diff --git a/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/returnStatement/returnStatement_initializerBlock.ets b/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/returnStatement/returnStatement_initializerBlock.ets new file mode 100644 index 0000000000000000000000000000000000000000..e826416873dfbc29fb10ef243f0afb2cb57c360a --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/returnStatement/returnStatement_initializerBlock.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 8.12 + * returnStatement: + * 'return' expression? + * ; + * + * CHAPTER 15.10 + * initializerBlock: + * 'static' block + * ; + */ + +class Test { + static { + return; + } +} diff --git a/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/returnStatement/returnStatement_lambdaExpressionWithReceiver.ets b/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/returnStatement/returnStatement_lambdaExpressionWithReceiver.ets new file mode 100644 index 0000000000000000000000000000000000000000..9469ff28273fa2bf9b7c9755d647d0aa9badae42 --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/returnStatement/returnStatement_lambdaExpressionWithReceiver.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 8.12 + * returnStatement: + * 'return' expression? + * ; + * + * CHAPTER 17.12.5 + * lambdaExpressionWithReceiver: + * annotationUsage? typeParameters? + * '(' receiverParameter (',' lambdaParameterList)? ')' + * returnType? throwMark? '=>' lambdaBody + * ; + */ + +class A {} + +let result = (this: A) => { + let b = 2; + return b; +}; diff --git a/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/returnStatement/returnStatement_namespaceDeclaration.ets b/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/returnStatement/returnStatement_namespaceDeclaration.ets new file mode 100644 index 0000000000000000000000000000000000000000..0bbf74c3d5dbfb746c52e223d19cae8bbc9f9682 --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/returnStatement/returnStatement_namespaceDeclaration.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. + */ + +/** + * CHAPTER 8.12 + * returnStatement: + * 'return' expression? + * ; + * + * CHAPTER 13.8 + * namespaceDeclaration: + * 'namespace' qualifiedName + * '{' topDeclaration* initializerBlock? topDeclaration* '}' + * ; + */ + + +namespace A { + function add(a: number, b: number): number { + return a + b; + } +} diff --git a/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/returnStatement/returnStatement_newArrayInstance.ets b/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/returnStatement/returnStatement_newArrayInstance.ets new file mode 100644 index 0000000000000000000000000000000000000000..ad3708a24492a47fd72879c1f75f7129f79b5c14 --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/returnStatement/returnStatement_newArrayInstance.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 8.12 + * returnStatement: + * 'return' expression? + * ; + * + * CHAPTER 17.3 + * newArrayInstance: + * 'new' arrayElementType dimensionExpression+ (arrayElement)? + * ; + */ + +function add(a: number, b: number): string[] { + return new Array(1); +} diff --git a/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/returnStatement/returnStatement_switchStatement.ets b/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/returnStatement/returnStatement_switchStatement.ets new file mode 100644 index 0000000000000000000000000000000000000000..373db76a5689cc65eb383db259475070da9c4edb --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/returnStatement/returnStatement_switchStatement.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 8.12 + * returnStatement: + * 'return' expression? + * ; + * + * CHAPTER 8.13 + * switchStatement: + * (identifier ':')? 'switch' '(' expression ')' switchBlock + * ; + */ + +function processValue(a: number): number { + let x = 1; + switch (x) { + case 1: + return 1; + case 2: + return 2; + default: + return 0; + } +} diff --git a/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/returnStatement/returnStatement_trailingLambdaCall.ets b/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/returnStatement/returnStatement_trailingLambdaCall.ets new file mode 100644 index 0000000000000000000000000000000000000000..d65d169f260805c17fa096cbb92997cdbc351a05 --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/returnStatement/returnStatement_trailingLambdaCall.ets @@ -0,0 +1,42 @@ +/* + * 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 8.12 + * returnStatement: + * 'return' expression? + * ; + * + * CHAPTER 17.13 + * trailingLambdaCall: + * ( objectReference '.' identifier typeArguments? + * | expression ('?.' | typeArguments)? + * ) + * arguments block + * ; + */ + +class A { + x(arg: T, callback: (result: T) => void): number { + const result = arg; + callback(result); + return 0; + } +} + +let a = new A(); +function processValue(b: number): number { + return a.x("Hi") {} +} diff --git a/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/returnStatement/returnStatement_tryStatement.ets b/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/returnStatement/returnStatement_tryStatement.ets new file mode 100644 index 0000000000000000000000000000000000000000..b980493ee2605ecde0c3b8bf99b49f8c5644a7fc --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/returnStatement/returnStatement_tryStatement.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 8.12 + * returnStatement: + * 'return' expression? + * ; + * + * CHAPTER 8.15 + * tryStatement: + * 'try' block catchClauses finallyClause? + * ; + */ + +function processTwo(a: number): number { + try { + if (true) { + const x = 1; + } + return 0; + } catch (error) { + return -1; + } +} diff --git a/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/statement/statement_awaitExpression.ets b/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/statement/statement_awaitExpression.ets new file mode 100644 index 0000000000000000000000000000000000000000..1f604ec7de4faa98cf57f9c903cac4bb039fa368 --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/statement/statement_awaitExpression.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 8 + * statement: + * expressionStatement + * | block + * | localDeclaration + * | ifStatement + * | loopStatement + * | breakStatement + * | continueStatement + * | returnStatement + * | switchStatement + * | throwStatement + * | tryStatement + * ; + * + * CHAPTER 17.16.2 + * awaitExpression: + * 'await' expression + * ; + */ + +async function foo(): Promise { + return 42.0; +} + +async function main() { + let x = foo(); + if (true) { + let result = await x; + } +} diff --git a/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/statement/statement_breakStatement.ets b/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/statement/statement_breakStatement.ets new file mode 100644 index 0000000000000000000000000000000000000000..c75d5cf15080a30d492320407d8b15a3f17a5ef6 --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/statement/statement_breakStatement.ets @@ -0,0 +1,42 @@ +/* + * 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 8 + * statement: + * expressionStatement + * | block + * | localDeclaration + * | ifStatement + * | loopStatement + * | breakStatement + * | continueStatement + * | returnStatement + * | switchStatement + * | throwStatement + * | tryStatement + * ; + * + * CHAPTER 8.10 + * breakStatement: + * 'break' identifier? + * ; + */ + +for (let x = 0; x < 5; x++) { + if (x === 2) { + break; + } +} diff --git a/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/statement/statement_classInitializer.ets b/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/statement/statement_classInitializer.ets new file mode 100644 index 0000000000000000000000000000000000000000..23932f71c6d13cb1e7bbdab16ef9899a91138f87 --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/statement/statement_classInitializer.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 8 + * statement: + * expressionStatement + * | block + * | localDeclaration + * | ifStatement + * | loopStatement + * | breakStatement + * | continueStatement + * | returnStatement + * | switchStatement + * | throwStatement + * | tryStatement + * ; + * + * CHAPTER 9.8 + * classInitializer: + * initializerBlock + * ; + */ + +class X { + static initialized = false; + static initializerBlock() { + if (!X.initialized) { + X.initialized = true; + } + } +} diff --git a/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/statement/statement_continueStatement.ets b/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/statement/statement_continueStatement.ets new file mode 100644 index 0000000000000000000000000000000000000000..f3d4d9776507d18753c9d274e7c36390204f3ebe --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/statement/statement_continueStatement.ets @@ -0,0 +1,42 @@ +/* + * 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 8 + * statement: + * expressionStatement + * | block + * | localDeclaration + * | ifStatement + * | loopStatement + * | breakStatement + * | continueStatement + * | returnStatement + * | switchStatement + * | throwStatement + * | tryStatement + * ; + * + * CHAPTER 8.11 + * continueStatement: + * 'continue' identifier? + * ; + */ + +x: for (let i = 0; i < 3; i++) { + if (i === 1) { + continue x; + } +} diff --git a/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/statement/statement_enumDeclaration.ets b/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/statement/statement_enumDeclaration.ets new file mode 100644 index 0000000000000000000000000000000000000000..dbf5f4d6e2c9f9e724de4a26f6f45675729d95ea --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/statement/statement_enumDeclaration.ets @@ -0,0 +1,40 @@ +/* + * 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 8 + * statement: + * expressionStatement + * | block + * | localDeclaration + * | ifStatement + * | loopStatement + * | breakStatement + * | continueStatement + * | returnStatement + * | switchStatement + * | throwStatement + * | tryStatement + * ; + * + * CHAPTER 11 + * enumDeclaration: + * 'const'? 'enum' identifier '{' enumConstantList '}' + * ; + */ + +if (true) { + const enum x { Red = 1, Green = 2, Blue = 3 } +} diff --git a/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/statement/statement_finallyClause.ets b/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/statement/statement_finallyClause.ets new file mode 100644 index 0000000000000000000000000000000000000000..d0e9b4ba60602e23433b6213d27a6b4da2bbbf44 --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/statement/statement_finallyClause.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 8 + * statement: + * expressionStatement + * | block + * | localDeclaration + * | ifStatement + * | loopStatement + * | breakStatement + * | continueStatement + * | returnStatement + * | switchStatement + * | throwStatement + * | tryStatement + * ; + * + * CHAPTER 8.15.2 + * finallyClause: + * 'finally' block + * ; + */ + +if (true) { + try { + } catch (error) { + } finally { + let x = 1; + } +} + diff --git a/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/statement/statement_forOfStatement.ets b/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/statement/statement_forOfStatement.ets new file mode 100644 index 0000000000000000000000000000000000000000..2164cc17bcb4c0eaa47ba471a87d1e5c1ac52ac9 --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/statement/statement_forOfStatement.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 8 + * statement: + * expressionStatement + * | block + * | localDeclaration + * | ifStatement + * | loopStatement + * | breakStatement + * | continueStatement + * | returnStatement + * | switchStatement + * | throwStatement + * | tryStatement + * ; + * + * CHAPTER 8.9 + * forOfStatement: + * 'for' '(' forVariable 'of' expression ')' statement + * ; + */ + +let arr = [1, 2, 3]; +for (let x of arr = [0]) { + if (true) { + break; + } +} diff --git a/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/statement/statement_forStatement.ets b/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/statement/statement_forStatement.ets new file mode 100644 index 0000000000000000000000000000000000000000..11023a5bf60d55b053c76caa69a618a42c3ced07 --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/statement/statement_forStatement.ets @@ -0,0 +1,42 @@ +/* + * 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 8 + * statement: + * expressionStatement + * | block + * | localDeclaration + * | ifStatement + * | loopStatement + * | breakStatement + * | continueStatement + * | returnStatement + * | switchStatement + * | throwStatement + * | tryStatement + * ; + * + * CHAPTER 8.8 + * forStatement: + * 'for' '(' forInit? ';' forContinue? ';' forUpdate? ')' statement + * ; + */ + +for (let x = 1; x < 10; x++) { + if (true) { + break; + } +} diff --git a/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/statement/statement_functionTypeWithReceiver.ets b/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/statement/statement_functionTypeWithReceiver.ets new file mode 100644 index 0000000000000000000000000000000000000000..18af3734ef06758ea2a40154d02eea5766ca6835 --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/statement/statement_functionTypeWithReceiver.ets @@ -0,0 +1,42 @@ +/* + * 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 8 + * statement: + * expressionStatement + * | block + * | localDeclaration + * | ifStatement + * | loopStatement + * | breakStatement + * | continueStatement + * | returnStatement + * | switchStatement + * | throwStatement + * | tryStatement + * ; + * + * CHAPTER 17.12.4 + * functionTypeWithReceiver: + * '(' receiverParameter (',' ftParameterList)? ')' ftReturnType + * ; + */ + +class A {} + +if (true) { + type FA = (this: A) => boolean; +} diff --git a/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/statement/statement_ifStatement.ets b/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/statement/statement_ifStatement.ets new file mode 100644 index 0000000000000000000000000000000000000000..ac0c72a7f886f9815f1de4b25055b4805449804a --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/statement/statement_ifStatement.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 8 + * statement: + * expressionStatement + * | block + * | localDeclaration + * | ifStatement + * | loopStatement + * | breakStatement + * | continueStatement + * | returnStatement + * | switchStatement + * | throwStatement + * | tryStatement + * ; + * + * CHAPTER 8.5 + * ifStatement: + * 'if' '(' expression ')' thenStatement + * ('else' elseStatement)? + * ; + */ + +if (true) { + if (false) { + console.log('Condition is false'); + } +} diff --git a/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/statement/statement_initializerBlock.ets b/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/statement/statement_initializerBlock.ets new file mode 100644 index 0000000000000000000000000000000000000000..dd16100b5e42ac959bc5f1e4ea08ee9a2271cb11 --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/statement/statement_initializerBlock.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 8 + * statement: + * expressionStatement + * | block + * | localDeclaration + * | ifStatement + * | loopStatement + * | breakStatement + * | continueStatement + * | returnStatement + * | switchStatement + * | throwStatement + * | tryStatement + * ; + * + * CHAPTER 15.10 + * initializerBlock: + * 'static' block + * ; + */ + +class Test { + static { + if (true) { + let x = 0; + } + } +} diff --git a/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/statement/statement_lambdaExpressionWithReceiver.ets b/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/statement/statement_lambdaExpressionWithReceiver.ets new file mode 100644 index 0000000000000000000000000000000000000000..a69c501da421db0dbbb1b68b180ca07b8c1c1972 --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/statement/statement_lambdaExpressionWithReceiver.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 8 + * statement: + * expressionStatement + * | block + * | localDeclaration + * | ifStatement + * | loopStatement + * | breakStatement + * | continueStatement + * | returnStatement + * | switchStatement + * | throwStatement + * | tryStatement + * ; + * + * CHAPTER 17.12.5 + * lambdaExpressionWithReceiver: + * annotationUsage? typeParameters? + * '(' receiverParameter (',' lambdaParameterList)? ')' + * returnType? throwMark? '=>' lambdaBody + * ; + */ + +class A {} + +if (true) { + let result = (this: A) => { + let b = 2; + return b; + }; +} diff --git a/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/statement/statement_loopStatement.ets b/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/statement/statement_loopStatement.ets new file mode 100644 index 0000000000000000000000000000000000000000..30399bccbcb9a851ba9246284369101121242bb3 --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/statement/statement_loopStatement.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 8 + * statement: + * expressionStatement + * | block + * | localDeclaration + * | ifStatement + * | loopStatement + * | breakStatement + * | continueStatement + * | returnStatement + * | switchStatement + * | throwStatement + * | tryStatement + * ; + * + * CHAPTER 8.6 + * loopStatement: + * (identifier ':')? + * whileStatement + * | doStatement + * | forStatement + * | forOfStatement + * ; + */ + +while(true) { + if (true) { + let x = 1; + } + break; +} diff --git a/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/statement/statement_namespaceDeclaration.ets b/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/statement/statement_namespaceDeclaration.ets new file mode 100644 index 0000000000000000000000000000000000000000..702c12d1f86373a6f1168f37672a0365b61af97c --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/statement/statement_namespaceDeclaration.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 8 + * statement: + * expressionStatement + * | block + * | localDeclaration + * | ifStatement + * | loopStatement + * | breakStatement + * | continueStatement + * | returnStatement + * | switchStatement + * | throwStatement + * | tryStatement + * ; + * + * CHAPTER 13.8 + * namespaceDeclaration: + * 'namespace' qualifiedName + * '{' topDeclaration* initializerBlock? topDeclaration* '}' + * ; + */ + + +namespace A { + if (true) { + let a: number = 1; + } +} diff --git a/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/statement/statement_newArrayInstance.ets b/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/statement/statement_newArrayInstance.ets new file mode 100644 index 0000000000000000000000000000000000000000..87cf9bcece8429a852b6b6674163db854f997ce6 --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/statement/statement_newArrayInstance.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 8 + * statement: + * expressionStatement + * | block + * | localDeclaration + * | ifStatement + * | loopStatement + * | breakStatement + * | continueStatement + * | returnStatement + * | switchStatement + * | throwStatement + * | tryStatement + * ; + * + * CHAPTER 17.3 + * newArrayInstance: + * 'new' arrayElementType dimensionExpression+ (arrayElement)? + * ; + */ + +if (true) { + let x = 1; + let a = new string[x]; +} diff --git a/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/statement/statement_returnStatement.ets b/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/statement/statement_returnStatement.ets new file mode 100644 index 0000000000000000000000000000000000000000..e73e2854590c380a2700684f5967314b71d92b88 --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/statement/statement_returnStatement.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 8 + * statement: + * expressionStatement + * | block + * | localDeclaration + * | ifStatement + * | loopStatement + * | breakStatement + * | continueStatement + * | returnStatement + * | switchStatement + * | throwStatement + * | tryStatement + * ; + * + * CHAPTER 8.12 + * returnStatement: + * 'return' expression? + * ; + */ + +function add(x1: number, x2: number): number { + if (true) { + return 1; + } else { + return x1 + x2; + } +} diff --git a/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/statement/statement_separateModuleDeclaration.ets b/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/statement/statement_separateModuleDeclaration.ets new file mode 100644 index 0000000000000000000000000000000000000000..b2d0eeecc96c087a15158095e7a73fb3fdeb7878 --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/statement/statement_separateModuleDeclaration.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 8 + * statement: + * expressionStatement + * | block + * | localDeclaration + * | ifStatement + * | loopStatement + * | breakStatement + * | continueStatement + * | returnStatement + * | switchStatement + * | throwStatement + * | tryStatement + * ; + * + * CHAPTER 13.1 + * separateModuleDeclaration: + * importDirective* (topDeclaration | topLevelStatements | exportDirective)* + * ; + */ + +if (true) {}; diff --git a/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/statement/statement_switchStatement.ets b/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/statement/statement_switchStatement.ets new file mode 100644 index 0000000000000000000000000000000000000000..36e1e439fd2fd2abbca694838cea4990a8527682 --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/statement/statement_switchStatement.ets @@ -0,0 +1,48 @@ +/* + * 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 8 + * statement: + * expressionStatement + * | block + * | localDeclaration + * | ifStatement + * | loopStatement + * | breakStatement + * | continueStatement + * | returnStatement + * | switchStatement + * | throwStatement + * | tryStatement + * ; + * + * CHAPTER 8.13 + * switchStatement: + * (identifier ':')? 'switch' '(' expression ')' switchBlock + * ; + */ + +let x = 1; +switch (x) { + case 1: + if (true) { + break; + } else { + break; + } + default: + break; +} diff --git a/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/statement/statement_throwStatement.ets b/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/statement/statement_throwStatement.ets new file mode 100644 index 0000000000000000000000000000000000000000..31cabd1cc3cbb1f5c9e33e56eec49aa1e168a694 --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/statement/statement_throwStatement.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 8 + * statement: + * expressionStatement + * | block + * | localDeclaration + * | ifStatement + * | loopStatement + * | breakStatement + * | continueStatement + * | returnStatement + * | switchStatement + * | throwStatement + * | tryStatement + * ; + * + * CHAPTER 8.14 + * throwStatement: + * 'throw' expression + * ; + */ + +let x = new Error("1"); +if (true) { + throw (x = new Error("2")); +} diff --git a/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/statement/statement_topDeclaration.ets b/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/statement/statement_topDeclaration.ets new file mode 100644 index 0000000000000000000000000000000000000000..b0756dd21c65a261720d4f5de710fcdf68a2ddc6 --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/statement/statement_topDeclaration.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 8 + * statement: + * expressionStatement + * | block + * | localDeclaration + * | ifStatement + * | loopStatement + * | breakStatement + * | continueStatement + * | returnStatement + * | switchStatement + * | throwStatement + * | tryStatement + * ; + * + * CHAPTER 13.7 + * topDeclaration: + * ('export' 'default'?)? + * annotationUsage? + * ( typeDeclaration + * | variableDeclarations + * | constantDeclarations + * | functionDeclaration + * | functionWithReceiverDeclaration + * | accessorWithReceiverDeclaration + * | namespaceDeclaration + * ) + * ; + */ + +if (true) {} diff --git a/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/statement/statement_topLevelStatements.ets b/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/statement/statement_topLevelStatements.ets new file mode 100644 index 0000000000000000000000000000000000000000..3ea0149f50a0166eec68ff48128025aa2892166c --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/statement/statement_topLevelStatements.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 8 + * statement: + * expressionStatement + * | block + * | localDeclaration + * | ifStatement + * | loopStatement + * | breakStatement + * | continueStatement + * | returnStatement + * | switchStatement + * | throwStatement + * | tryStatement + * ; + * + * CHAPTER 13.10 + * topLevelStatements: + * statement* + * ; + */ + +if (true) {} diff --git a/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/statement/statement_trailingLambdaCall.ets b/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/statement/statement_trailingLambdaCall.ets new file mode 100644 index 0000000000000000000000000000000000000000..7f4273c94b6dbb1b116b62f5a80bb48852f17b29 --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/statement/statement_trailingLambdaCall.ets @@ -0,0 +1,52 @@ +/* + * 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 8 + * statement: + * expressionStatement + * | block + * | localDeclaration + * | ifStatement + * | loopStatement + * | breakStatement + * | continueStatement + * | returnStatement + * | switchStatement + * | throwStatement + * | tryStatement + * ; + * + * CHAPTER 17.13 + * trailingLambdaCall: + * ( objectReference '.' identifier typeArguments? + * | expression ('?.' | typeArguments)? + * ) + * arguments block + * ; + */ + +class A { + x(arg: T, callback: (result: T) => void): number { + const result = arg; + callback(result); + return 0; + } +} + +let a = new A(); +if (true) { + let test = a.x("Hi") {} +} diff --git a/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/statement/statement_tryStatement.ets b/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/statement/statement_tryStatement.ets new file mode 100644 index 0000000000000000000000000000000000000000..9755d99e5022d8a9c00776fb35c22fce30821f52 --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/statement/statement_tryStatement.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 8 + * statement: + * expressionStatement + * | block + * | localDeclaration + * | ifStatement + * | loopStatement + * | breakStatement + * | continueStatement + * | returnStatement + * | switchStatement + * | throwStatement + * | tryStatement + * ; + * + * CHAPTER 8.15 + * tryStatement: + * 'try' block catchClauses finallyClause? + * ; + */ + +function processTwo(a: number): number { + try { + if (true) { + const x = 1; + } + return 0; + } catch (error) { + return -1; + } +} diff --git a/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/statement/statement_whileStatement.ets b/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/statement/statement_whileStatement.ets new file mode 100644 index 0000000000000000000000000000000000000000..1044ea597fafcf18db362099589ecbeecde9e7fb --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/statement/statement_whileStatement.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 8 + * statement: + * expressionStatement + * | block + * | localDeclaration + * | ifStatement + * | loopStatement + * | breakStatement + * | continueStatement + * | returnStatement + * | switchStatement + * | throwStatement + * | tryStatement + * ; + * + * CHAPTER 8.7 + * whileStatement: + * 'while' '(' expression ')' statement + * ; + */ + +let x = 5; +let n = 3; +while (x &= n) { + if (x > n) { + console.log("x is greater than n"); + } +} diff --git a/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/switchStatement/switchStatement_awaitExpression.ets b/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/switchStatement/switchStatement_awaitExpression.ets new file mode 100644 index 0000000000000000000000000000000000000000..f8cce7369d3eecb5f5ddea79518fa383e5a6d5a1 --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/switchStatement/switchStatement_awaitExpression.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 8.13 + * switchStatement: + * (identifier ':')? 'switch' '(' expression ')' switchBlock + * ; + * + * CHAPTER 17.16.2 + * awaitExpression: + * 'await' expression + * ; + */ + +async function foo(): Promise { + return 42.0; +} + +async function main() { + let x = foo(); + switch (1) { + case 42: + let result = await x; + break; + default: + break; + } +} diff --git a/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/switchStatement/switchStatement_classInitializer.ets b/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/switchStatement/switchStatement_classInitializer.ets new file mode 100644 index 0000000000000000000000000000000000000000..a727f6ee6e81e7d42f69d27d3436e2ba1b181304 --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/switchStatement/switchStatement_classInitializer.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 8.13 + * switchStatement: + * (identifier ':')? 'switch' '(' expression ')' switchBlock + * ; + * + * CHAPTER 9.8 + * classInitializer: + * initializerBlock + * ; + */ + +class X { + static initialized = false; + static initializerBlock() { + switch (1) { + case 1: + break; + default: + break; + } + } +} diff --git a/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/switchStatement/switchStatement_finallyClause.ets b/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/switchStatement/switchStatement_finallyClause.ets new file mode 100644 index 0000000000000000000000000000000000000000..48c99dcfdc02358b06db88d3760f8469cbea41da --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/switchStatement/switchStatement_finallyClause.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 8.13 + * switchStatement: + * (identifier ':')? 'switch' '(' expression ')' switchBlock + * ; + * + * CHAPTER 8.15.2 + * finallyClause: + * 'finally' block + * ; + */ + +switch (1) { + case 1: + try { + } catch (error) { + } finally { + let x = 1; + } + break; +} diff --git a/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/switchStatement/switchStatement_functionTypeWithReceiver.ets b/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/switchStatement/switchStatement_functionTypeWithReceiver.ets new file mode 100644 index 0000000000000000000000000000000000000000..0efae3bf4eac3f39c21fc20239a1be4de6714056 --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/switchStatement/switchStatement_functionTypeWithReceiver.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. + */ + +/** + * CHAPTER 8.13 + * switchStatement: + * (identifier ':')? 'switch' '(' expression ')' switchBlock + * ; + * + * CHAPTER 17.12.4 + * functionTypeWithReceiver: + * '(' receiverParameter (',' ftParameterList)? ')' ftReturnType + * ; + */ + +class A {} + +switch (1) { + case 1: + type FA = (this: A) => boolean; + break; +} diff --git a/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/switchStatement/switchStatement_initializerBlock.ets b/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/switchStatement/switchStatement_initializerBlock.ets new file mode 100644 index 0000000000000000000000000000000000000000..90ec799af0f116d715fb0947adf71fd4fc764373 --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/switchStatement/switchStatement_initializerBlock.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 8.13 + * switchStatement: + * (identifier ':')? 'switch' '(' expression ')' switchBlock + * ; + * + * CHAPTER 15.10 + * initializerBlock: + * 'static' block + * ; + */ + +class Test { + static { + switch (1) { + case 1: + break; + default: + break; + } + } +} diff --git a/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/switchStatement/switchStatement_lambdaExpressionWithReceiver.ets b/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/switchStatement/switchStatement_lambdaExpressionWithReceiver.ets new file mode 100644 index 0000000000000000000000000000000000000000..6270fe2c6f76ad60b7ee7c841c12cf0f259f7790 --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/switchStatement/switchStatement_lambdaExpressionWithReceiver.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 8.13 + * switchStatement: + * (identifier ':')? 'switch' '(' expression ')' switchBlock + * ; + * + * CHAPTER 17.12.5 + * lambdaExpressionWithReceiver: + * annotationUsage? typeParameters? + * '(' receiverParameter (',' lambdaParameterList)? ')' + * returnType? throwMark? '=>' lambdaBody + * ; + */ + +class A {} + +switch (1) { + case 1: + let result = (this: A) => { + let b = 2; + return b; + }; + break; + default: + break; +} diff --git a/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/switchStatement/switchStatement_namespaceDeclaration.ets b/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/switchStatement/switchStatement_namespaceDeclaration.ets new file mode 100644 index 0000000000000000000000000000000000000000..ccbb07f72a2c6c084d77b51f6abf8c2c75cfcdec --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/switchStatement/switchStatement_namespaceDeclaration.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 8.13 + * switchStatement: + * (identifier ':')? 'switch' '(' expression ')' switchBlock + * ; + * + * CHAPTER 13.8 + * namespaceDeclaration: + * 'namespace' qualifiedName + * '{' topDeclaration* initializerBlock? topDeclaration* '}' + * ; + */ + +namespace A { + switch (1) { + case 1: + break; + default: + break; + } +} diff --git a/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/switchStatement/switchStatement_newArrayInstance.ets b/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/switchStatement/switchStatement_newArrayInstance.ets new file mode 100644 index 0000000000000000000000000000000000000000..bd45cd49314744f16d4874a86ac1047726a99135 --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/switchStatement/switchStatement_newArrayInstance.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 8.13 + * switchStatement: + * (identifier ':')? 'switch' '(' expression ')' switchBlock + * ; + * + * CHAPTER 17.3 + * newArrayInstance: + * 'new' arrayElementType dimensionExpression+ (arrayElement)? + * ; + */ + +switch (1) { + case 1: + let x = 1; + let a = new string[x]; + break; + default: + break; +} diff --git a/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/switchStatement/switchStatement_separateModuleDeclaration.ets b/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/switchStatement/switchStatement_separateModuleDeclaration.ets new file mode 100644 index 0000000000000000000000000000000000000000..c8fed7d6caa47dd1d180fb4a634b831fb49fa9f7 --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/switchStatement/switchStatement_separateModuleDeclaration.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 8.13 + * switchStatement: + * (identifier ':')? 'switch' '(' expression ')' switchBlock + * ; + * + * CHAPTER 13.1 + * separateModuleDeclaration: + * importDirective* (topDeclaration | topLevelStatements | exportDirective)* + * ; + */ + +switch (1) { + case 1: + break; + default: + break; +} diff --git a/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/switchStatement/switchStatement_throwStatement.ets b/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/switchStatement/switchStatement_throwStatement.ets new file mode 100644 index 0000000000000000000000000000000000000000..393b3125a743d8ff94356ddea8b97f9f037727cd --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/switchStatement/switchStatement_throwStatement.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. + */ + +/** + * CHAPTER 8.13 + * switchStatement: + * (identifier ':')? 'switch' '(' expression ')' switchBlock + * ; + * + * CHAPTER 8.14 + * throwStatement: + * 'throw' expression + * ; + */ + +let x = new Error("1"); +switch (1) { + case 1: + throw (x = new Error("2")); + default: + break; +} diff --git a/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/switchStatement/switchStatement_topDeclaration.ets b/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/switchStatement/switchStatement_topDeclaration.ets new file mode 100644 index 0000000000000000000000000000000000000000..0d5365e44e485fa9548e4488a1224bfa02a1a77f --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/switchStatement/switchStatement_topDeclaration.ets @@ -0,0 +1,42 @@ +/* + * 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 8.13 + * switchStatement: + * (identifier ':')? 'switch' '(' expression ')' switchBlock + * ; + * + * CHAPTER 13.7 + * topDeclaration: + * ('export' 'default'?)? + * annotationUsage? + * ( typeDeclaration + * | variableDeclarations + * | constantDeclarations + * | functionDeclaration + * | functionWithReceiverDeclaration + * | accessorWithReceiverDeclaration + * | namespaceDeclaration + * ) + * ; + */ + +switch (1) { + case 1: + break; + default: + break; +} diff --git a/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/switchStatement/switchStatement_topLevelStatements.ets b/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/switchStatement/switchStatement_topLevelStatements.ets new file mode 100644 index 0000000000000000000000000000000000000000..005a74f6b3597bb2e6216aab993d15c1e2f4be37 --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/switchStatement/switchStatement_topLevelStatements.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 8.13 + * switchStatement: + * (identifier ':')? 'switch' '(' expression ')' switchBlock + * ; + * + * CHAPTER 13.10 + * topLevelStatements: + * statement* + * ; + */ + +switch (1) { + case 1: + break; + default: + break; +} diff --git a/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/switchStatement/switchStatement_trailingLambdaCall.ets b/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/switchStatement/switchStatement_trailingLambdaCall.ets new file mode 100644 index 0000000000000000000000000000000000000000..53155443f0ba423bff50cf035599f9423fd91f1c --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/switchStatement/switchStatement_trailingLambdaCall.ets @@ -0,0 +1,46 @@ +/* + * 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 8.13 + * switchStatement: + * (identifier ':')? 'switch' '(' expression ')' switchBlock + * ; + * + * CHAPTER 17.13 + * trailingLambdaCall: + * ( objectReference '.' identifier typeArguments? + * | expression ('?.' | typeArguments)? + * ) + * arguments block + * ; + */ + +class A { + x(arg: T, callback: (result: T) => void): number { + const result = arg; + callback(result); + return 0; + } +} + +let a = new A(); +switch (1) { + case 1: + let test = a.x("Hi") {} + break; + default: + break; +} diff --git a/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/switchStatement/switchStatement_tryStatement.ets b/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/switchStatement/switchStatement_tryStatement.ets new file mode 100644 index 0000000000000000000000000000000000000000..3f3dde1f541de18aba1755e9c00c1f086de4dd40 --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/switchStatement/switchStatement_tryStatement.ets @@ -0,0 +1,40 @@ +/* + * 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 8.13 + * switchStatement: + * (identifier ':')? 'switch' '(' expression ')' switchBlock + * ; + * + * CHAPTER 8.15 + * tryStatement: + * 'try' block catchClauses finallyClause? + * ; + */ + +function processTwo(a: number): number { + try { + switch (1) { + case 1: + break; + default: + break; + } + return 0; + } catch (error) { + return -1; + } +} diff --git a/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/throwStatement/throwStatement_classInitializer.ets b/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/throwStatement/throwStatement_classInitializer.ets new file mode 100644 index 0000000000000000000000000000000000000000..0a065757def5628bb239c5ac8f29bcdb56478398 --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/throwStatement/throwStatement_classInitializer.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 8.14 + * throwStatement: + * 'throw' expression + * ; + * + * CHAPTER 9.8 + * classInitializer: + * initializerBlock + * ; + */ + +class X { + static initialized = false; + static initializerBlock() { + throw new Error("An error occurred"); + } +} diff --git a/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/throwStatement/throwStatement_finallyClause.ets b/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/throwStatement/throwStatement_finallyClause.ets new file mode 100644 index 0000000000000000000000000000000000000000..dd699319b8fda41463505402db220e6096536cea --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/throwStatement/throwStatement_finallyClause.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 8.14 + * throwStatement: + * 'throw' expression + * ; + * + * CHAPTER 8.15.2 + * finallyClause: + * 'finally' block + * ; + */ + +let shouldThrowError = false; +try { + if (Math.random() > 0.5) { + shouldThrowError = true; + } +} catch (error) { +} finally { + if (shouldThrowError) { + throw new Error("An error occurred"); + } +} diff --git a/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/throwStatement/throwStatement_initializerBlock.ets b/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/throwStatement/throwStatement_initializerBlock.ets new file mode 100644 index 0000000000000000000000000000000000000000..018c8b1dd2be5a1ff41b0858b39f9f5a8467d68a --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/throwStatement/throwStatement_initializerBlock.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 8.14 + * throwStatement: + * 'throw' expression + * ; + * + * CHAPTER 15.10 + * initializerBlock: + * 'static' block + * ; + */ + +class Test { + static { + throw new Error("An error occurred"); + } +} diff --git a/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/throwStatement/throwStatement_lambdaExpressionWithReceiver.ets b/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/throwStatement/throwStatement_lambdaExpressionWithReceiver.ets new file mode 100644 index 0000000000000000000000000000000000000000..0b0239dc0285fcbcaea399eb6d22073fd1581276 --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/throwStatement/throwStatement_lambdaExpressionWithReceiver.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 8.14 + * throwStatement: + * 'throw' expression + * ; + * + * CHAPTER 17.12.5 + * lambdaExpressionWithReceiver: + * annotationUsage? typeParameters? + * '(' receiverParameter (',' lambdaParameterList)? ')' + * returnType? throwMark? '=>' lambdaBody + * ; + */ + +class A {} + +let result = (this: A) => { + throw new Error("An error occurred"); + let b = 2; + return b; +}; diff --git a/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/throwStatement/throwStatement_namespaceDeclaration.ets b/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/throwStatement/throwStatement_namespaceDeclaration.ets new file mode 100644 index 0000000000000000000000000000000000000000..7aff9aec256ec55645196cb5f6f341af152de3d2 --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/throwStatement/throwStatement_namespaceDeclaration.ets @@ -0,0 +1,31 @@ +/* + * 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 8.14 + * throwStatement: + * 'throw' expression + * ; + * + * CHAPTER 13.8 + * namespaceDeclaration: + * 'namespace' qualifiedName + * '{' topDeclaration* initializerBlock? topDeclaration* '}' + * ; + */ + +namespace A { + throw new Error("An error occurred"); +} diff --git a/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/throwStatement/throwStatement_separateModuleDeclaration.ets b/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/throwStatement/throwStatement_separateModuleDeclaration.ets new file mode 100644 index 0000000000000000000000000000000000000000..782c8ee816bfa3e19a2e37cff3fff22fb6b62ab8 --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/throwStatement/throwStatement_separateModuleDeclaration.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 8.14 + * throwStatement: + * 'throw' expression + * ; + * + * CHAPTER 13.1 + * separateModuleDeclaration: + * importDirective* (topDeclaration | topLevelStatements | exportDirective)* + * ; + */ + +throw new Error("An error occurred"); diff --git a/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/throwStatement/throwStatement_topDeclaration.ets b/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/throwStatement/throwStatement_topDeclaration.ets new file mode 100644 index 0000000000000000000000000000000000000000..1f29d82d9b1786ca2b376ef116d841c2a6813817 --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/throwStatement/throwStatement_topDeclaration.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 8.14 + * throwStatement: + * 'throw' expression + * ; + * + * CHAPTER 13.7 + * topDeclaration: + * ('export' 'default'?)? + * annotationUsage? + * ( typeDeclaration + * | variableDeclarations + * | constantDeclarations + * | functionDeclaration + * | functionWithReceiverDeclaration + * | accessorWithReceiverDeclaration + * | namespaceDeclaration + * ) + * ; + */ + +throw new Error("An error occurred"); diff --git a/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/throwStatement/throwStatement_topLevelStatements.ets b/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/throwStatement/throwStatement_topLevelStatements.ets new file mode 100644 index 0000000000000000000000000000000000000000..7e069c2f5d0898a0a85658dc7c1f8128188f25da --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/throwStatement/throwStatement_topLevelStatements.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 8.14 + * throwStatement: + * 'throw' expression + * ; + * + * CHAPTER 13.10 + * topLevelStatements: + * statement* + * ; + */ + +throw new Error("An error occurred"); diff --git a/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/throwStatement/throwStatement_trailingLambdaCall.ets b/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/throwStatement/throwStatement_trailingLambdaCall.ets new file mode 100644 index 0000000000000000000000000000000000000000..fec75a0ce10c67dd10131ccbc0b5172fdcfdb0d4 --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/throwStatement/throwStatement_trailingLambdaCall.ets @@ -0,0 +1,40 @@ +/* + * 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 8.14 + * throwStatement: + * 'throw' expression + * ; + * + * CHAPTER 17.13 + * trailingLambdaCall: + * ( objectReference '.' identifier typeArguments? + * | expression ('?.' | typeArguments)? + * ) + * arguments block + * ; + */ + +class A { + x(arg: T, callback: (result: T) => void): string { + const result = arg; + callback(result); + return "0"; + } +} + +let a = new A(); +throw new Error(a.x("Hi") {}); diff --git a/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/throwStatement/throwStatement_tryStatement.ets b/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/throwStatement/throwStatement_tryStatement.ets new file mode 100644 index 0000000000000000000000000000000000000000..70bee953da34bd7fa9928a32da26805046a51312 --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/throwStatement/throwStatement_tryStatement.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. + */ + +/** + * CHAPTER 8.14 + * throwStatement: + * 'throw' expression + * ; + * + * CHAPTER 8.15 + * tryStatement: + * 'try' block catchClauses finallyClause? + * ; + */ + +function processTwo(a: number): number { + try { + throw new Error("An error occurred"); + } catch (error) { + return -1; + } +} diff --git a/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/tryStatement/tryStatement_awaitExpression.ets b/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/tryStatement/tryStatement_awaitExpression.ets new file mode 100644 index 0000000000000000000000000000000000000000..a07bc5fcb5700f0e7bb2e2490cf8507a57d25a7f --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/tryStatement/tryStatement_awaitExpression.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 8.15 + * tryStatement: + * 'try' block catchClauses? finallyClause? + * ; + * + * CHAPTER 17.16.2 + * awaitExpression: + * 'await' expression + * ; + */ + +async function foo(): Promise { + return 42.0; +} + +async function main() { + let x = foo(); + try { + let result = await x; + } catch (error) { + console.log(`Error occurred: ${error}`); + } +} diff --git a/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/tryStatement/tryStatement_classInitializer.ets b/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/tryStatement/tryStatement_classInitializer.ets new file mode 100644 index 0000000000000000000000000000000000000000..29d84414a1d4a5b0643e1d1b2a7d694b3288e4f8 --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/tryStatement/tryStatement_classInitializer.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 8.15 + * tryStatement: + * 'try' block catchClauses? finallyClause? + * ; + * + * CHAPTER 9.8 + * classInitializer: + * initializerBlock + * ; + */ + +class X { + static initialized = false; + static initializerBlock() { + try { + X.initialized = true; + } catch (error) { + console.log(`Error occurred: ${error}`); + } + } +} diff --git a/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/tryStatement/tryStatement_enumDeclaration.ets b/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/tryStatement/tryStatement_enumDeclaration.ets new file mode 100644 index 0000000000000000000000000000000000000000..4718f75b475535d7e8bdb79250a7e46ac9cb42b1 --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/tryStatement/tryStatement_enumDeclaration.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 8.15 + * tryStatement: + * 'try' block catchClauses? finallyClause? + * ; + * + * CHAPTER 11 + * enumDeclaration: + * 'const'? 'enum' identifier '{' enumConstantList '}' + * ; + */ + +try { + const enum x { Red = 1, Green = 2, Blue = 3 } +} catch (error) { + console.log(`Error occurred: ${error}`); +} diff --git a/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/tryStatement/tryStatement_finallyClause.ets b/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/tryStatement/tryStatement_finallyClause.ets new file mode 100644 index 0000000000000000000000000000000000000000..053fd6ff122297728bb95ed20616b44410555b0b --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/tryStatement/tryStatement_finallyClause.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 8.15 + * tryStatement: + * 'try' block catchClauses? finallyClause? + * ; + * + * CHAPTER 8.15.2 + * finallyClause: + * 'finally' block + * ; + */ + +try { +} catch (error) { +} finally { + let x = 1; +} diff --git a/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/tryStatement/tryStatement_functionTypeWithReceiver.ets b/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/tryStatement/tryStatement_functionTypeWithReceiver.ets new file mode 100644 index 0000000000000000000000000000000000000000..90a18255366fa4b9911f472741240f38e523a16b --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/tryStatement/tryStatement_functionTypeWithReceiver.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. + */ + +/** + * CHAPTER 8.15 + * tryStatement: + * 'try' block catchClauses? finallyClause? + * ; + * + * CHAPTER 17.12.4 + * functionTypeWithReceiver: + * '(' receiverParameter (',' ftParameterList)? ')' ftReturnType + * ; + */ + +class A {} + +try { + type FA = (this: A) => boolean; +} catch (error) { + console.log(`Error occurred: ${error}`); +} diff --git a/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/tryStatement/tryStatement_initializerBlock.ets b/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/tryStatement/tryStatement_initializerBlock.ets new file mode 100644 index 0000000000000000000000000000000000000000..9f28f09047fb6122b0ecba675228d3e276a5dc1a --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/tryStatement/tryStatement_initializerBlock.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 8.15 + * tryStatement: + * 'try' block catchClauses? finallyClause? + * ; + * + * CHAPTER 15.10 + * initializerBlock: + * 'static' block + * ; + */ + +class Test { + static { + try { + console.log("try"); + } catch (error) { + console.log(`Error occurred: ${error}`); + } + } +} diff --git a/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/tryStatement/tryStatement_lambdaExpressionWithReceiver.ets b/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/tryStatement/tryStatement_lambdaExpressionWithReceiver.ets new file mode 100644 index 0000000000000000000000000000000000000000..2e5694452f1a36ed09670c8ce6076ed1c42e2368 --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/tryStatement/tryStatement_lambdaExpressionWithReceiver.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 8.15 + * tryStatement: + * 'try' block catchClauses? finallyClause? + * ; + * + * CHAPTER 17.12.5 + * lambdaExpressionWithReceiver: + * annotationUsage? typeParameters? + * '(' receiverParameter (',' lambdaParameterList)? ')' + * returnType? throwMark? '=>' lambdaBody + * ; + */ + +class A {} + +try { + let result = (this: A) => { + let b = 2; + return b; + } +} catch (error) { + console.log(`Error occurred: ${error}`); +} diff --git a/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/tryStatement/tryStatement_namespaceDeclaration.ets b/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/tryStatement/tryStatement_namespaceDeclaration.ets new file mode 100644 index 0000000000000000000000000000000000000000..e48cefdf858bf647a4e8239cbbc5efa2f6a848bb --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/tryStatement/tryStatement_namespaceDeclaration.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 8.15 + * tryStatement: + * 'try' block catchClauses? finallyClause? + * ; + * + * CHAPTER 13.8 + * namespaceDeclaration: + * 'namespace' qualifiedName + * '{' topDeclaration* initializerBlock? topDeclaration* '}' + * ; + */ + +namespace A { + try { + console.log("try"); + } catch (error) { + console.log(`Error occurred: ${error}`); + } +} diff --git a/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/tryStatement/tryStatement_newArrayInstance.ets b/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/tryStatement/tryStatement_newArrayInstance.ets new file mode 100644 index 0000000000000000000000000000000000000000..ad072c2ac29b492ecc2529b217d32ebf44230551 --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/tryStatement/tryStatement_newArrayInstance.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 8.15 + * tryStatement: + * 'try' block catchClauses? finallyClause? + * ; + * + * CHAPTER 17.3 + * newArrayInstance: + * 'new' arrayElementType dimensionExpression+ (arrayElement)? + * ; + */ + +try { + let x = 1; + let a = new string[x]; +} catch (error) { + console.log(`Error occurred: ${error}`); +} diff --git a/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/tryStatement/tryStatement_separateModuleDeclaration.ets b/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/tryStatement/tryStatement_separateModuleDeclaration.ets new file mode 100644 index 0000000000000000000000000000000000000000..2338f188cb3d79781074666fe3d702e149d11d4b --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/tryStatement/tryStatement_separateModuleDeclaration.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 8.15 + * tryStatement: + * 'try' block catchClauses? finallyClause? + * ; + * + * CHAPTER 13.1 + * separateModuleDeclaration: + * importDirective* (topDeclaration | topLevelStatements | exportDirective)* + * ; + */ + +try { + console.log("try"); +} catch (error) { + console.log(`Error occurred: ${error}`); +} diff --git a/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/tryStatement/tryStatement_topDeclaration.ets b/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/tryStatement/tryStatement_topDeclaration.ets new file mode 100644 index 0000000000000000000000000000000000000000..9f4d51a4e6e24c9179e2983f601986cc9efc2aa4 --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/tryStatement/tryStatement_topDeclaration.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 8.15 + * tryStatement: + * 'try' block catchClauses? finallyClause? + * ; + * + * CHAPTER 13.7 + * topDeclaration: + * ('export' 'default'?)? + * annotationUsage? + * ( typeDeclaration + * | variableDeclarations + * | constantDeclarations + * | functionDeclaration + * | functionWithReceiverDeclaration + * | accessorWithReceiverDeclaration + * | namespaceDeclaration + * ) + * ; + */ + +try { + console.log("try"); +} catch (error) { + console.log(`Error occurred: ${error}`); +} diff --git a/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/tryStatement/tryStatement_topLevelStatements.ets b/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/tryStatement/tryStatement_topLevelStatements.ets new file mode 100644 index 0000000000000000000000000000000000000000..a8f91281d1ab698e1e0e57172e148b9f6d41a114 --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/tryStatement/tryStatement_topLevelStatements.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 8.15 + * tryStatement: + * 'try' block catchClauses? finallyClause? + * ; + * + * CHAPTER 13.10 + * topLevelStatements: + * statement* + * ; + */ + +try { + console.log("try"); +} catch (error) { + console.log(`Error occurred: ${error}`); +} diff --git a/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/tryStatement/tryStatement_trailingLambdaCall.ets b/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/tryStatement/tryStatement_trailingLambdaCall.ets new file mode 100644 index 0000000000000000000000000000000000000000..287f128b752d184375f6449d0bcd0dd5fdf978ec --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/tryStatement/tryStatement_trailingLambdaCall.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 8.15 + * tryStatement: + * 'try' block catchClauses? finallyClause? + * ; + * + * CHAPTER 17.13 + * trailingLambdaCall: + * ( objectReference '.' identifier typeArguments? + * | expression ('?.' | typeArguments)? + * ) + * arguments block + * ; + */ + +class A { + x(arg: T, callback: (result: T) => void): number { + const result = arg; + callback(result); + return 0; + } +} + +let a = new A(); +try { + let test = a.x("Hi") {} +} catch (error) { + console.log(`Error occurred: ${error}`); +} diff --git a/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/whileStatement/whileStatement_awaitExpression.ets b/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/whileStatement/whileStatement_awaitExpression.ets new file mode 100644 index 0000000000000000000000000000000000000000..d65834f9fcb050d1d30e43afe016864ed895dc5d --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/whileStatement/whileStatement_awaitExpression.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 8.7 + * whileStatement: + * 'while' '(' expression ')' statement + * ; + * + * CHAPTER 17.16.2 + * awaitExpression: + * 'await' expression + * ; + */ + +async function foo(): Promise { + return 42.0; +} + +async function main() { + let x = foo(); + while (true) { + let result = await x; + } +} diff --git a/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/whileStatement/whileStatement_breakStatement.ets b/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/whileStatement/whileStatement_breakStatement.ets new file mode 100644 index 0000000000000000000000000000000000000000..b727e68519c3ea9afab1a7306ef3969e3c1576d0 --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/whileStatement/whileStatement_breakStatement.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 8.7 + * whileStatement: + * 'while' '(' expression ')' statement + * ; + * + * CHAPTER 8.10 + * breakStatement: + * 'break' identifier? + * ; + */ + +for (let x = 0; x < 5; x++) { + while (x === 2) { + break; + } +} diff --git a/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/whileStatement/whileStatement_classInitializer.ets b/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/whileStatement/whileStatement_classInitializer.ets new file mode 100644 index 0000000000000000000000000000000000000000..59bc8406f17ce18b537cedcd3eaa9d30e4429b55 --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/whileStatement/whileStatement_classInitializer.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 8.7 + * whileStatement: + * 'while' '(' expression ')' statement + * ; + * + * CHAPTER 9.8 + * classInitializer: + * initializerBlock + * ; + */ + +class X { + static initialized = false; + static initializerBlock() { + while (!X.initialized) { + X.initialized = true; + } + } +} diff --git a/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/whileStatement/whileStatement_continueStatement.ets b/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/whileStatement/whileStatement_continueStatement.ets new file mode 100644 index 0000000000000000000000000000000000000000..6a2c48883c5009a93a338006dc2d48fc0daca83b --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/whileStatement/whileStatement_continueStatement.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 8.7 + * whileStatement: + * 'while' '(' expression ')' statement + * ; + * + * CHAPTER 8.11 + * continueStatement: + * 'continue' identifier? + * ; + */ + +x: for (let i = 0; i < 3; i++) { + while (i === 1) { + continue x; + } +} diff --git a/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/whileStatement/whileStatement_enumDeclaration.ets b/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/whileStatement/whileStatement_enumDeclaration.ets new file mode 100644 index 0000000000000000000000000000000000000000..fe4fac42eed179c402d551155f1620e6e73619c8 --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/whileStatement/whileStatement_enumDeclaration.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 8.7 + * whileStatement: + * 'while' '(' expression ')' statement + * ; + * + * CHAPTER 11 + * enumDeclaration: + * 'const'? 'enum' identifier '{' enumConstantList '}' + * ; + */ + +while (true) { + const enum x { Red = 1, Green = 2, Blue = 3 } +} diff --git a/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/whileStatement/whileStatement_finallyClause.ets b/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/whileStatement/whileStatement_finallyClause.ets new file mode 100644 index 0000000000000000000000000000000000000000..3786b2e503209a512ac4889b6cca9e2c7d7511ac --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/whileStatement/whileStatement_finallyClause.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 8.7 + * whileStatement: + * 'while' '(' expression ')' statement + * ; + * + * CHAPTER 8.15.2 + * finallyClause: + * 'finally' block + * ; + */ + +while (true) { + try { + } catch (error) { + } finally { + let x = 1; + } +} + diff --git a/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/whileStatement/whileStatement_forOfStatement.ets b/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/whileStatement/whileStatement_forOfStatement.ets new file mode 100644 index 0000000000000000000000000000000000000000..86ac29da5878f6ba5aefb7ec76be64a5596593a4 --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/whileStatement/whileStatement_forOfStatement.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 8.7 + * whileStatement: + * 'while' '(' expression ')' statement + * ; + * + * CHAPTER 8.9 + * forOfStatement: + * 'for' '(' forVariable 'of' expression ')' statement + * ; + */ + +let arr = [1, 2, 3]; +for (let x of arr = [0]) { + while (true) { + break; + } +} diff --git a/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/whileStatement/whileStatement_forStatement.ets b/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/whileStatement/whileStatement_forStatement.ets new file mode 100644 index 0000000000000000000000000000000000000000..c6b19e0d70b9d00ac05de69864b8068120a908b2 --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/whileStatement/whileStatement_forStatement.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 8.7 + * whileStatement: + * 'while' '(' expression ')' statement + * ; + * + * CHAPTER 8.8 + * forStatement: + * 'for' '(' forInit? ';' forContinue? ';' forUpdate? ')' statement + * ; + */ + +for (let x = 1; x < 10; x++) { + while (true) { + break; + } +} diff --git a/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/whileStatement/whileStatement_functionTypeWithReceiver.ets b/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/whileStatement/whileStatement_functionTypeWithReceiver.ets new file mode 100644 index 0000000000000000000000000000000000000000..28db921582c1c8d4ae40b98066845a2525f643bc --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/whileStatement/whileStatement_functionTypeWithReceiver.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 8.7 + * whileStatement: + * 'while' '(' expression ')' statement + * ; + * + * CHAPTER 17.12.4 + * functionTypeWithReceiver: + * '(' receiverParameter (',' ftParameterList)? ')' ftReturnType + * ; + */ + +class A {} + +while (true) { + type FA = (this: A) => boolean; +} diff --git a/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/whileStatement/whileStatement_initializerBlock.ets b/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/whileStatement/whileStatement_initializerBlock.ets new file mode 100644 index 0000000000000000000000000000000000000000..d91a96de06afb04438d5c5ebb025c3dcacb2be8c --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/whileStatement/whileStatement_initializerBlock.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. + */ + +/** + * CHAPTER 8.7 + * whileStatement: + * 'while' '(' expression ')' statement + * ; + * + * CHAPTER 15.10 + * initializerBlock: + * 'static' block + * ; + */ + +class Test { + static { + while (true) { + let x = 0; + } + } +} diff --git a/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/whileStatement/whileStatement_lambdaExpressionWithReceiver.ets b/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/whileStatement/whileStatement_lambdaExpressionWithReceiver.ets new file mode 100644 index 0000000000000000000000000000000000000000..0f493c57021839c633f437c79ae97f1e5948eda6 --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/whileStatement/whileStatement_lambdaExpressionWithReceiver.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 8.7 + * whileStatement: + * 'while' '(' expression ')' statement + * ; + * + * CHAPTER 17.12.5 + * lambdaExpressionWithReceiver: + * annotationUsage? typeParameters? + * '(' receiverParameter (',' lambdaParameterList)? ')' + * returnType? throwMark? '=>' lambdaBody + * ; + */ + +class A {} + +while (true) { + let result = (this: A) => { + let b = 2; + return b; + }; +} diff --git a/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/whileStatement/whileStatement_namespaceDeclaration.ets b/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/whileStatement/whileStatement_namespaceDeclaration.ets new file mode 100644 index 0000000000000000000000000000000000000000..8e05278a5547c7edd7132fbbe4c9747c4a4202ba --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/whileStatement/whileStatement_namespaceDeclaration.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 8.7 + * whileStatement: + * 'while' '(' expression ')' statement + * ; + * + * CHAPTER 13.8 + * namespaceDeclaration: + * 'namespace' qualifiedName + * '{' topDeclaration* initializerBlock? topDeclaration* '}' + * ; + */ + +namespace A { + while (true) { + let a: number = 1; + } +} diff --git a/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/whileStatement/whileStatement_newArrayInstance.ets b/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/whileStatement/whileStatement_newArrayInstance.ets new file mode 100644 index 0000000000000000000000000000000000000000..d405550c5c9e0bb7687eab3c8dd532fbb43c6808 --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/whileStatement/whileStatement_newArrayInstance.ets @@ -0,0 +1,31 @@ +/* + * 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 8.7 + * whileStatement: + * 'while' '(' expression ')' statement + * ; + * + * CHAPTER 17.3 + * newArrayInstance: + * 'new' arrayElementType dimensionExpression+ (arrayElement)? + * ; + */ + +while (true) { + let x = 1; + let a = new string[x]; +} diff --git a/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/whileStatement/whileStatement_returnStatement.ets b/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/whileStatement/whileStatement_returnStatement.ets new file mode 100644 index 0000000000000000000000000000000000000000..2f7df0f8ab4e09dac8006db5f565aa6a256fd366 --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/whileStatement/whileStatement_returnStatement.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 8.7 + * whileStatement: + * 'while' '(' expression ')' statement + * ; + * + * CHAPTER 8.12 + * returnStatement: + * 'return' expression? + * ; + */ + +function add(x1: number, x2: number): number { + while (true) { + return 1; + } +} diff --git a/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/whileStatement/whileStatement_separateModuleDeclaration.ets b/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/whileStatement/whileStatement_separateModuleDeclaration.ets new file mode 100644 index 0000000000000000000000000000000000000000..fb35eacd1d0bf88f6a347ae3c9986ae4ee2217e1 --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/whileStatement/whileStatement_separateModuleDeclaration.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 8.7 + * whileStatement: + * 'while' '(' expression ')' statement + * ; + * + * CHAPTER 13.1 + * separateModuleDeclaration: + * importDirective* (topDeclaration | topLevelStatements | exportDirective)* + * ; + */ + +while (true) {}; diff --git a/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/whileStatement/whileStatement_switchStatement.ets b/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/whileStatement/whileStatement_switchStatement.ets new file mode 100644 index 0000000000000000000000000000000000000000..e573a01bb11d97c8840f6b07977fd2b1e61231ab --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/whileStatement/whileStatement_switchStatement.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 8.7 + * whileStatement: + * 'while' '(' expression ')' statement + * ; + * + * CHAPTER 8.13 + * switchStatement: + * (identifier ':')? 'switch' '(' expression ')' switchBlock + * ; + */ + +let x = 1; +switch (x) { + case 1: + while (true) { + break; + } + break; + default: + break; +} diff --git a/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/whileStatement/whileStatement_throwStatement.ets b/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/whileStatement/whileStatement_throwStatement.ets new file mode 100644 index 0000000000000000000000000000000000000000..aa683d4aa68693e9577bef5fcb842768e0c0223f --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/whileStatement/whileStatement_throwStatement.ets @@ -0,0 +1,31 @@ +/* + * 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 8.7 + * whileStatement: + * 'while' '(' expression ')' statement + * ; + * + * CHAPTER 8.14 + * throwStatement: + * 'throw' expression + * ; + */ + +let x = new Error("1"); +while (true) { + throw (x = new Error("2")); +} diff --git a/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/whileStatement/whileStatement_topDeclaration.ets b/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/whileStatement/whileStatement_topDeclaration.ets new file mode 100644 index 0000000000000000000000000000000000000000..dfa6eba182041ea15105a5f06986502909529756 --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/whileStatement/whileStatement_topDeclaration.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 8.7 + * whileStatement: + * 'while' '(' expression ')' statement + * ; + * + * CHAPTER 13.7 + * topDeclaration: + * ('export' 'default'?)? + * annotationUsage? + * ( typeDeclaration + * | variableDeclarations + * | constantDeclarations + * | functionDeclaration + * | functionWithReceiverDeclaration + * | accessorWithReceiverDeclaration + * | namespaceDeclaration + * ) + * ; + */ + +while (true) {} diff --git a/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/whileStatement/whileStatement_topLevelStatements.ets b/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/whileStatement/whileStatement_topLevelStatements.ets new file mode 100644 index 0000000000000000000000000000000000000000..28625b5a193b32577cb2bf81d8a2cb03a81f73f6 --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/whileStatement/whileStatement_topLevelStatements.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 8.7 + * whileStatement: + * 'while' '(' expression ')' statement + * ; + * + * CHAPTER 13.10 + * topLevelStatements: + * statement* + * ; + */ + +while (true) {} diff --git a/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/whileStatement/whileStatement_trailingLambdaCall.ets b/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/whileStatement/whileStatement_trailingLambdaCall.ets new file mode 100644 index 0000000000000000000000000000000000000000..d77c02b010044163b6df3406541e3797b4cfa099 --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/whileStatement/whileStatement_trailingLambdaCall.ets @@ -0,0 +1,42 @@ +/* + * 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 8.7 + * whileStatement: + * 'while' '(' expression ')' statement + * ; + * + * CHAPTER 17.13 + * trailingLambdaCall: + * ( objectReference '.' identifier typeArguments? + * | expression ('?.' | typeArguments)? + * ) + * arguments block + * ; + */ + +class A { + x(arg: T, callback: (result: T) => void): number { + const result = arg; + callback(result); + return 0; + } +} + +let a = new A(); +while (true) { + let test = a.x("Hi") {} +} diff --git a/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/whileStatement/whileStatement_tryStatement.ets b/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/whileStatement/whileStatement_tryStatement.ets new file mode 100644 index 0000000000000000000000000000000000000000..73911de219b27a4e208d64e94e1851cb0a732724 --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/whileStatement/whileStatement_tryStatement.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 8.7 + * whileStatement: + * 'while' '(' expression ')' statement + * ; + * + * CHAPTER 8.15 + * tryStatement: + * 'try' block catchClauses finallyClause? + * ; + */ + +function processOne(a: number): number { + try { + let counter = 0; + while (counter < 10) { + counter++; + if (counter === 5) { + throw new Error("Counter reached 5"); + } + } + return 0; + } catch (error) { + return -1; + } +}