From 1a3ae96761ca634fae0914a8afe1c20e40ea5eef Mon Sep 17 00:00:00 2001 From: liujia178 Date: Fri, 9 May 2025 14:01:55 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8F=90=E4=BA=A4=E8=AF=AD=E5=8F=A5=E7=9B=B8?= =?UTF-8?q?=E5=85=B3=E7=9A=84=E6=AD=A3=E4=BA=A4=E7=94=A8=E4=BE=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: liujia178 --- .../breakStatement_classInitializer.ets | 35 +++++++++++++ .../breakStatement_finallyClause.ets | 35 +++++++++++++ .../breakStatement_initializerBlock.ets | 35 +++++++++++++ ...Statement_lambdaExpressionWithReceiver.ets | 37 +++++++++++++ .../breakStatement_namespaceDeclaration.ets | 34 ++++++++++++ .../breakStatement_switchStatement.ets | 37 +++++++++++++ .../breakStatement_tryStatement.ets | 39 ++++++++++++++ .../continueStatement_classInitializer.ets | 37 +++++++++++++ .../continueStatement_finallyClause.ets | 34 ++++++++++++ .../continueStatement_initializerBlock.ets | 34 ++++++++++++ ...Statement_lambdaExpressionWithReceiver.ets | 36 +++++++++++++ ...continueStatement_namespaceDeclaration.ets | 34 ++++++++++++ .../continueStatement_switchStatement.ets | 41 +++++++++++++++ .../continueStatement_tryStatement.ets | 37 +++++++++++++ .../finallyClause_awaitExpression.ets | 42 +++++++++++++++ .../finallyClause_classInitializer.ets | 40 ++++++++++++++ .../finallyClause_enumDeclaration.ets | 34 ++++++++++++ ...finallyClause_functionTypeWithReceiver.ets | 36 +++++++++++++ .../finallyClause_initializerBlock.ets | 38 ++++++++++++++ ...llyClause_lambdaExpressionWithReceiver.ets | 44 ++++++++++++++++ .../finallyClause_namespaceDeclaration.ets | 37 +++++++++++++ .../finallyClause_newArrayInstance.ets | 35 +++++++++++++ ...inallyClause_separateModuleDeclaration.ets | 34 ++++++++++++ .../finallyClause_topDeclaration.ets | 43 +++++++++++++++ .../finallyClause_topLevelStatements.ets | 34 ++++++++++++ .../finallyClause_trailingLambdaCall.ets | 46 ++++++++++++++++ .../forOfStatement_awaitExpression.ets | 37 +++++++++++++ .../forOfStatement_breakStatement.ets | 30 +++++++++++ .../forOfStatement_classInitializer.ets | 35 +++++++++++++ .../forOfStatement_continueStatement.ets | 32 ++++++++++++ .../forOfStatement_finallyClause.ets | 35 +++++++++++++ ...orOfStatement_functionTypeWithReceiver.ets | 32 ++++++++++++ .../forOfStatement_initializerBlock.ets | 34 ++++++++++++ ...Statement_lambdaExpressionWithReceiver.ets | 37 +++++++++++++ .../forOfStatement_namespaceDeclaration.ets | 33 ++++++++++++ .../forOfStatement_newArrayInstance.ets | 31 +++++++++++ .../forOfStatement_returnStatement.ets | 33 ++++++++++++ ...rOfStatement_separateModuleDeclaration.ets | 28 ++++++++++ .../forOfStatement_switchStatement.ets | 37 +++++++++++++ .../forOfStatement_throwStatement.ets | 31 +++++++++++ .../forOfStatement_topDeclaration.ets | 37 +++++++++++++ .../forOfStatement_topLevelStatements.ets | 28 ++++++++++ .../forOfStatement_trailingLambdaCall.ets | 42 +++++++++++++++ .../forOfStatement_tryStatement.ets | 41 +++++++++++++++ .../forStatement_awaitExpression.ets | 37 +++++++++++++ .../forStatement_breakStatement.ets | 30 +++++++++++ .../forStatement_classInitializer.ets | 35 +++++++++++++ .../forStatement_continueStatement.ets | 30 +++++++++++ .../forStatement_enumDeclaration.ets | 30 +++++++++++ .../forStatement_finallyClause.ets | 34 ++++++++++++ .../forStatement_forOfStatement.ets | 33 ++++++++++++ .../forStatement_functionTypeWithReceiver.ets | 32 ++++++++++++ .../forStatement_initializerBlock.ets | 34 ++++++++++++ ...Statement_lambdaExpressionWithReceiver.ets | 37 +++++++++++++ .../forStatement_namespaceDeclaration.ets | 33 ++++++++++++ .../forStatement_newArrayInstance.ets | 31 +++++++++++ .../forStatement_returnStatement.ets | 33 ++++++++++++ ...forStatement_separateModuleDeclaration.ets | 28 ++++++++++ .../forStatement_switchStatement.ets | 37 +++++++++++++ .../forStatement_throwStatement.ets | 31 +++++++++++ .../forStatement_topDeclaration.ets | 37 +++++++++++++ .../forStatement_topLevelStatements.ets | 28 ++++++++++ .../forStatement_trailingLambdaCall.ets | 42 +++++++++++++++ .../forStatement_tryStatement.ets | 41 +++++++++++++++ .../ifStatement_awaitExpression.ets | 38 ++++++++++++++ .../ifStatement_breakStatement.ets | 33 ++++++++++++ .../ifStatement_classInitializer.ets | 36 +++++++++++++ .../ifStatement_continueStatement.ets | 33 ++++++++++++ .../ifStatement_enumDeclaration.ets | 31 +++++++++++ .../ifStatement/ifStatement_finallyClause.ets | 35 +++++++++++++ .../ifStatement_forOfStatement.ets | 34 ++++++++++++ .../ifStatement/ifStatement_forStatement.ets | 33 ++++++++++++ .../ifStatement_functionTypeWithReceiver.ets | 33 ++++++++++++ .../ifStatement_initializerBlock.ets | 35 +++++++++++++ ...Statement_lambdaExpressionWithReceiver.ets | 38 ++++++++++++++ .../ifStatement/ifStatement_loopStatement.ets | 38 ++++++++++++++ .../ifStatement_namespaceDeclaration.ets | 34 ++++++++++++ .../ifStatement_newArrayInstance.ets | 32 ++++++++++++ .../ifStatement_returnStatement.ets | 35 +++++++++++++ .../ifStatement_separateModuleDeclaration.ets | 29 +++++++++++ .../ifStatement_switchStatement.ets | 39 ++++++++++++++ .../ifStatement_throwStatement.ets | 32 ++++++++++++ .../ifStatement_topDeclaration.ets | 38 ++++++++++++++ .../ifStatement_topLevelStatements.ets | 29 +++++++++++ .../ifStatement_trailingLambdaCall.ets | 43 +++++++++++++++ .../ifStatement/ifStatement_tryStatement.ets | 38 ++++++++++++++ .../ifStatement_whileStatement.ets | 35 +++++++++++++ .../loopStatement_awaitExpression.ets | 41 +++++++++++++++ .../loopStatement_breakStatement.ets | 36 +++++++++++++ .../loopStatement_classInitializer.ets | 39 ++++++++++++++ .../loopStatement_continueStatement.ets | 36 +++++++++++++ .../loopStatement_enumDeclaration.ets | 34 ++++++++++++ .../loopStatement_finallyClause.ets | 39 ++++++++++++++ .../loopStatement_forOfStatement.ets | 37 +++++++++++++ .../loopStatement_forStatement.ets | 36 +++++++++++++ ...loopStatement_functionTypeWithReceiver.ets | 36 +++++++++++++ .../loopStatement_initializerBlock.ets | 38 ++++++++++++++ ...Statement_lambdaExpressionWithReceiver.ets | 41 +++++++++++++++ .../loopStatement_namespaceDeclaration.ets | 37 +++++++++++++ .../loopStatement_newArrayInstance.ets | 35 +++++++++++++ .../loopStatement_returnStatement.ets | 36 +++++++++++++ ...oopStatement_separateModuleDeclaration.ets | 32 ++++++++++++ .../loopStatement_switchStatement.ets | 41 +++++++++++++++ .../loopStatement_throwStatement.ets | 35 +++++++++++++ .../loopStatement_topDeclaration.ets | 41 +++++++++++++++ .../loopStatement_topLevelStatements.ets | 32 ++++++++++++ .../loopStatement_trailingLambdaCall.ets | 46 ++++++++++++++++ .../loopStatement_tryStatement.ets | 45 ++++++++++++++++ .../loopStatement_whileStatement.ets | 38 ++++++++++++++ .../returnStatement_awaitExpression.ets | 37 +++++++++++++ .../returnStatement_classInitializer.ets | 33 ++++++++++++ .../returnStatement_initializerBlock.ets | 32 ++++++++++++ ...Statement_lambdaExpressionWithReceiver.ets | 35 +++++++++++++ .../returnStatement_namespaceDeclaration.ets | 34 ++++++++++++ .../returnStatement_newArrayInstance.ets | 30 +++++++++++ .../returnStatement_switchStatement.ets | 38 ++++++++++++++ .../returnStatement_trailingLambdaCall.ets | 42 +++++++++++++++ .../returnStatement_tryStatement.ets | 37 +++++++++++++ .../statement/statement_awaitExpression.ets | 47 +++++++++++++++++ .../statement/statement_breakStatement.ets | 42 +++++++++++++++ .../statement/statement_classInitializer.ets | 45 ++++++++++++++++ .../statement/statement_continueStatement.ets | 42 +++++++++++++++ .../statement/statement_enumDeclaration.ets | 40 ++++++++++++++ .../statement/statement_finallyClause.ets | 45 ++++++++++++++++ .../statement/statement_forOfStatement.ets | 43 +++++++++++++++ .../statement/statement_forStatement.ets | 42 +++++++++++++++ .../statement_functionTypeWithReceiver.ets | 42 +++++++++++++++ .../statement/statement_ifStatement.ets | 43 +++++++++++++++ .../statement/statement_initializerBlock.ets | 44 ++++++++++++++++ ...statement_lambdaExpressionWithReceiver.ets | 47 +++++++++++++++++ .../statement/statement_loopStatement.ets | 47 +++++++++++++++++ .../statement_namespaceDeclaration.ets | 44 ++++++++++++++++ .../statement/statement_newArrayInstance.ets | 41 +++++++++++++++ .../statement/statement_returnStatement.ets | 44 ++++++++++++++++ .../statement_separateModuleDeclaration.ets | 38 ++++++++++++++ .../statement/statement_switchStatement.ets | 48 +++++++++++++++++ .../statement/statement_throwStatement.ets | 41 +++++++++++++++ .../statement/statement_topDeclaration.ets | 47 +++++++++++++++++ .../statement_topLevelStatements.ets | 38 ++++++++++++++ .../statement_trailingLambdaCall.ets | 52 +++++++++++++++++++ .../statement/statement_tryStatement.ets | 47 +++++++++++++++++ .../statement/statement_whileStatement.ets | 44 ++++++++++++++++ .../switchStatement_awaitExpression.ets | 41 +++++++++++++++ .../switchStatement_classInitializer.ets | 38 ++++++++++++++ .../switchStatement_finallyClause.ets | 36 +++++++++++++ ...itchStatement_functionTypeWithReceiver.ets | 34 ++++++++++++ .../switchStatement_initializerBlock.ets | 37 +++++++++++++ ...Statement_lambdaExpressionWithReceiver.ets | 41 +++++++++++++++ .../switchStatement_namespaceDeclaration.ets | 36 +++++++++++++ .../switchStatement_newArrayInstance.ets | 35 +++++++++++++ ...tchStatement_separateModuleDeclaration.ets | 33 ++++++++++++ .../switchStatement_throwStatement.ets | 34 ++++++++++++ .../switchStatement_topDeclaration.ets | 42 +++++++++++++++ .../switchStatement_topLevelStatements.ets | 33 ++++++++++++ .../switchStatement_trailingLambdaCall.ets | 46 ++++++++++++++++ .../switchStatement_tryStatement.ets | 40 ++++++++++++++ .../throwStatement_classInitializer.ets | 33 ++++++++++++ .../throwStatement_finallyClause.ets | 38 ++++++++++++++ .../throwStatement_initializerBlock.ets | 32 ++++++++++++ ...Statement_lambdaExpressionWithReceiver.ets | 36 +++++++++++++ .../throwStatement_namespaceDeclaration.ets | 31 +++++++++++ ...rowStatement_separateModuleDeclaration.ets | 28 ++++++++++ .../throwStatement_topDeclaration.ets | 37 +++++++++++++ .../throwStatement_topLevelStatements.ets | 28 ++++++++++ .../throwStatement_trailingLambdaCall.ets | 40 ++++++++++++++ .../throwStatement_tryStatement.ets | 34 ++++++++++++ .../tryStatement_awaitExpression.ets | 39 ++++++++++++++ .../tryStatement_classInitializer.ets | 37 +++++++++++++ .../tryStatement_enumDeclaration.ets | 32 ++++++++++++ .../tryStatement_finallyClause.ets | 32 ++++++++++++ .../tryStatement_functionTypeWithReceiver.ets | 34 ++++++++++++ .../tryStatement_initializerBlock.ets | 36 +++++++++++++ ...Statement_lambdaExpressionWithReceiver.ets | 39 ++++++++++++++ .../tryStatement_namespaceDeclaration.ets | 35 +++++++++++++ .../tryStatement_newArrayInstance.ets | 33 ++++++++++++ ...tryStatement_separateModuleDeclaration.ets | 32 ++++++++++++ .../tryStatement_topDeclaration.ets | 41 +++++++++++++++ .../tryStatement_topLevelStatements.ets | 32 ++++++++++++ .../tryStatement_trailingLambdaCall.ets | 44 ++++++++++++++++ .../whileStatement_awaitExpression.ets | 37 +++++++++++++ .../whileStatement_breakStatement.ets | 32 ++++++++++++ .../whileStatement_classInitializer.ets | 35 +++++++++++++ .../whileStatement_continueStatement.ets | 32 ++++++++++++ .../whileStatement_enumDeclaration.ets | 30 +++++++++++ .../whileStatement_finallyClause.ets | 35 +++++++++++++ .../whileStatement_forOfStatement.ets | 33 ++++++++++++ .../whileStatement_forStatement.ets | 32 ++++++++++++ ...hileStatement_functionTypeWithReceiver.ets | 32 ++++++++++++ .../whileStatement_initializerBlock.ets | 34 ++++++++++++ ...Statement_lambdaExpressionWithReceiver.ets | 37 +++++++++++++ .../whileStatement_namespaceDeclaration.ets | 33 ++++++++++++ .../whileStatement_newArrayInstance.ets | 31 +++++++++++ .../whileStatement_returnStatement.ets | 32 ++++++++++++ ...ileStatement_separateModuleDeclaration.ets | 28 ++++++++++ .../whileStatement_switchStatement.ets | 37 +++++++++++++ .../whileStatement_throwStatement.ets | 31 +++++++++++ .../whileStatement_topDeclaration.ets | 37 +++++++++++++ .../whileStatement_topLevelStatements.ets | 28 ++++++++++ .../whileStatement_trailingLambdaCall.ets | 42 +++++++++++++++ .../whileStatement_tryStatement.ets | 41 +++++++++++++++ 200 files changed, 7295 insertions(+) create mode 100644 ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/breakStatement/breakStatement_classInitializer.ets create mode 100644 ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/breakStatement/breakStatement_finallyClause.ets create mode 100644 ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/breakStatement/breakStatement_initializerBlock.ets create mode 100644 ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/breakStatement/breakStatement_lambdaExpressionWithReceiver.ets create mode 100644 ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/breakStatement/breakStatement_namespaceDeclaration.ets create mode 100644 ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/breakStatement/breakStatement_switchStatement.ets create mode 100644 ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/breakStatement/breakStatement_tryStatement.ets create mode 100644 ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/continueStatement/continueStatement_classInitializer.ets create mode 100644 ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/continueStatement/continueStatement_finallyClause.ets create mode 100644 ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/continueStatement/continueStatement_initializerBlock.ets create mode 100644 ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/continueStatement/continueStatement_lambdaExpressionWithReceiver.ets create mode 100644 ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/continueStatement/continueStatement_namespaceDeclaration.ets create mode 100644 ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/continueStatement/continueStatement_switchStatement.ets create mode 100644 ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/continueStatement/continueStatement_tryStatement.ets create mode 100644 ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/finallyClause/finallyClause_awaitExpression.ets create mode 100644 ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/finallyClause/finallyClause_classInitializer.ets create mode 100644 ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/finallyClause/finallyClause_enumDeclaration.ets create mode 100644 ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/finallyClause/finallyClause_functionTypeWithReceiver.ets create mode 100644 ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/finallyClause/finallyClause_initializerBlock.ets create mode 100644 ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/finallyClause/finallyClause_lambdaExpressionWithReceiver.ets create mode 100644 ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/finallyClause/finallyClause_namespaceDeclaration.ets create mode 100644 ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/finallyClause/finallyClause_newArrayInstance.ets create mode 100644 ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/finallyClause/finallyClause_separateModuleDeclaration.ets create mode 100644 ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/finallyClause/finallyClause_topDeclaration.ets create mode 100644 ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/finallyClause/finallyClause_topLevelStatements.ets create mode 100644 ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/finallyClause/finallyClause_trailingLambdaCall.ets create mode 100644 ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/forOfStatement/forOfStatement_awaitExpression.ets create mode 100644 ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/forOfStatement/forOfStatement_breakStatement.ets create mode 100644 ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/forOfStatement/forOfStatement_classInitializer.ets create mode 100644 ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/forOfStatement/forOfStatement_continueStatement.ets create mode 100644 ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/forOfStatement/forOfStatement_finallyClause.ets create mode 100644 ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/forOfStatement/forOfStatement_functionTypeWithReceiver.ets create mode 100644 ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/forOfStatement/forOfStatement_initializerBlock.ets create mode 100644 ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/forOfStatement/forOfStatement_lambdaExpressionWithReceiver.ets create mode 100644 ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/forOfStatement/forOfStatement_namespaceDeclaration.ets create mode 100644 ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/forOfStatement/forOfStatement_newArrayInstance.ets create mode 100644 ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/forOfStatement/forOfStatement_returnStatement.ets create mode 100644 ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/forOfStatement/forOfStatement_separateModuleDeclaration.ets create mode 100644 ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/forOfStatement/forOfStatement_switchStatement.ets create mode 100644 ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/forOfStatement/forOfStatement_throwStatement.ets create mode 100644 ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/forOfStatement/forOfStatement_topDeclaration.ets create mode 100644 ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/forOfStatement/forOfStatement_topLevelStatements.ets create mode 100644 ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/forOfStatement/forOfStatement_trailingLambdaCall.ets create mode 100644 ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/forOfStatement/forOfStatement_tryStatement.ets create mode 100644 ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/forStatement/forStatement_awaitExpression.ets create mode 100644 ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/forStatement/forStatement_breakStatement.ets create mode 100644 ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/forStatement/forStatement_classInitializer.ets create mode 100644 ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/forStatement/forStatement_continueStatement.ets create mode 100644 ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/forStatement/forStatement_enumDeclaration.ets create mode 100644 ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/forStatement/forStatement_finallyClause.ets create mode 100644 ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/forStatement/forStatement_forOfStatement.ets create mode 100644 ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/forStatement/forStatement_functionTypeWithReceiver.ets create mode 100644 ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/forStatement/forStatement_initializerBlock.ets create mode 100644 ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/forStatement/forStatement_lambdaExpressionWithReceiver.ets create mode 100644 ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/forStatement/forStatement_namespaceDeclaration.ets create mode 100644 ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/forStatement/forStatement_newArrayInstance.ets create mode 100644 ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/forStatement/forStatement_returnStatement.ets create mode 100644 ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/forStatement/forStatement_separateModuleDeclaration.ets create mode 100644 ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/forStatement/forStatement_switchStatement.ets create mode 100644 ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/forStatement/forStatement_throwStatement.ets create mode 100644 ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/forStatement/forStatement_topDeclaration.ets create mode 100644 ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/forStatement/forStatement_topLevelStatements.ets create mode 100644 ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/forStatement/forStatement_trailingLambdaCall.ets create mode 100644 ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/forStatement/forStatement_tryStatement.ets create mode 100644 ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/ifStatement/ifStatement_awaitExpression.ets create mode 100644 ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/ifStatement/ifStatement_breakStatement.ets create mode 100644 ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/ifStatement/ifStatement_classInitializer.ets create mode 100644 ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/ifStatement/ifStatement_continueStatement.ets create mode 100644 ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/ifStatement/ifStatement_enumDeclaration.ets create mode 100644 ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/ifStatement/ifStatement_finallyClause.ets create mode 100644 ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/ifStatement/ifStatement_forOfStatement.ets create mode 100644 ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/ifStatement/ifStatement_forStatement.ets create mode 100644 ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/ifStatement/ifStatement_functionTypeWithReceiver.ets create mode 100644 ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/ifStatement/ifStatement_initializerBlock.ets create mode 100644 ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/ifStatement/ifStatement_lambdaExpressionWithReceiver.ets create mode 100644 ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/ifStatement/ifStatement_loopStatement.ets create mode 100644 ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/ifStatement/ifStatement_namespaceDeclaration.ets create mode 100644 ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/ifStatement/ifStatement_newArrayInstance.ets create mode 100644 ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/ifStatement/ifStatement_returnStatement.ets create mode 100644 ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/ifStatement/ifStatement_separateModuleDeclaration.ets create mode 100644 ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/ifStatement/ifStatement_switchStatement.ets create mode 100644 ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/ifStatement/ifStatement_throwStatement.ets create mode 100644 ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/ifStatement/ifStatement_topDeclaration.ets create mode 100644 ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/ifStatement/ifStatement_topLevelStatements.ets create mode 100644 ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/ifStatement/ifStatement_trailingLambdaCall.ets create mode 100644 ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/ifStatement/ifStatement_tryStatement.ets create mode 100644 ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/ifStatement/ifStatement_whileStatement.ets create mode 100644 ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/loopStatement/loopStatement_awaitExpression.ets create mode 100644 ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/loopStatement/loopStatement_breakStatement.ets create mode 100644 ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/loopStatement/loopStatement_classInitializer.ets create mode 100644 ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/loopStatement/loopStatement_continueStatement.ets create mode 100644 ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/loopStatement/loopStatement_enumDeclaration.ets create mode 100644 ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/loopStatement/loopStatement_finallyClause.ets create mode 100644 ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/loopStatement/loopStatement_forOfStatement.ets create mode 100644 ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/loopStatement/loopStatement_forStatement.ets create mode 100644 ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/loopStatement/loopStatement_functionTypeWithReceiver.ets create mode 100644 ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/loopStatement/loopStatement_initializerBlock.ets create mode 100644 ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/loopStatement/loopStatement_lambdaExpressionWithReceiver.ets create mode 100644 ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/loopStatement/loopStatement_namespaceDeclaration.ets create mode 100644 ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/loopStatement/loopStatement_newArrayInstance.ets create mode 100644 ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/loopStatement/loopStatement_returnStatement.ets create mode 100644 ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/loopStatement/loopStatement_separateModuleDeclaration.ets create mode 100644 ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/loopStatement/loopStatement_switchStatement.ets create mode 100644 ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/loopStatement/loopStatement_throwStatement.ets create mode 100644 ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/loopStatement/loopStatement_topDeclaration.ets create mode 100644 ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/loopStatement/loopStatement_topLevelStatements.ets create mode 100644 ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/loopStatement/loopStatement_trailingLambdaCall.ets create mode 100644 ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/loopStatement/loopStatement_tryStatement.ets create mode 100644 ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/loopStatement/loopStatement_whileStatement.ets create mode 100644 ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/returnStatement/returnStatement_awaitExpression.ets create mode 100644 ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/returnStatement/returnStatement_classInitializer.ets create mode 100644 ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/returnStatement/returnStatement_initializerBlock.ets create mode 100644 ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/returnStatement/returnStatement_lambdaExpressionWithReceiver.ets create mode 100644 ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/returnStatement/returnStatement_namespaceDeclaration.ets create mode 100644 ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/returnStatement/returnStatement_newArrayInstance.ets create mode 100644 ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/returnStatement/returnStatement_switchStatement.ets create mode 100644 ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/returnStatement/returnStatement_trailingLambdaCall.ets create mode 100644 ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/returnStatement/returnStatement_tryStatement.ets create mode 100644 ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/statement/statement_awaitExpression.ets create mode 100644 ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/statement/statement_breakStatement.ets create mode 100644 ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/statement/statement_classInitializer.ets create mode 100644 ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/statement/statement_continueStatement.ets create mode 100644 ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/statement/statement_enumDeclaration.ets create mode 100644 ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/statement/statement_finallyClause.ets create mode 100644 ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/statement/statement_forOfStatement.ets create mode 100644 ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/statement/statement_forStatement.ets create mode 100644 ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/statement/statement_functionTypeWithReceiver.ets create mode 100644 ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/statement/statement_ifStatement.ets create mode 100644 ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/statement/statement_initializerBlock.ets create mode 100644 ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/statement/statement_lambdaExpressionWithReceiver.ets create mode 100644 ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/statement/statement_loopStatement.ets create mode 100644 ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/statement/statement_namespaceDeclaration.ets create mode 100644 ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/statement/statement_newArrayInstance.ets create mode 100644 ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/statement/statement_returnStatement.ets create mode 100644 ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/statement/statement_separateModuleDeclaration.ets create mode 100644 ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/statement/statement_switchStatement.ets create mode 100644 ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/statement/statement_throwStatement.ets create mode 100644 ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/statement/statement_topDeclaration.ets create mode 100644 ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/statement/statement_topLevelStatements.ets create mode 100644 ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/statement/statement_trailingLambdaCall.ets create mode 100644 ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/statement/statement_tryStatement.ets create mode 100644 ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/statement/statement_whileStatement.ets create mode 100644 ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/switchStatement/switchStatement_awaitExpression.ets create mode 100644 ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/switchStatement/switchStatement_classInitializer.ets create mode 100644 ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/switchStatement/switchStatement_finallyClause.ets create mode 100644 ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/switchStatement/switchStatement_functionTypeWithReceiver.ets create mode 100644 ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/switchStatement/switchStatement_initializerBlock.ets create mode 100644 ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/switchStatement/switchStatement_lambdaExpressionWithReceiver.ets create mode 100644 ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/switchStatement/switchStatement_namespaceDeclaration.ets create mode 100644 ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/switchStatement/switchStatement_newArrayInstance.ets create mode 100644 ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/switchStatement/switchStatement_separateModuleDeclaration.ets create mode 100644 ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/switchStatement/switchStatement_throwStatement.ets create mode 100644 ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/switchStatement/switchStatement_topDeclaration.ets create mode 100644 ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/switchStatement/switchStatement_topLevelStatements.ets create mode 100644 ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/switchStatement/switchStatement_trailingLambdaCall.ets create mode 100644 ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/switchStatement/switchStatement_tryStatement.ets create mode 100644 ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/throwStatement/throwStatement_classInitializer.ets create mode 100644 ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/throwStatement/throwStatement_finallyClause.ets create mode 100644 ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/throwStatement/throwStatement_initializerBlock.ets create mode 100644 ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/throwStatement/throwStatement_lambdaExpressionWithReceiver.ets create mode 100644 ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/throwStatement/throwStatement_namespaceDeclaration.ets create mode 100644 ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/throwStatement/throwStatement_separateModuleDeclaration.ets create mode 100644 ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/throwStatement/throwStatement_topDeclaration.ets create mode 100644 ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/throwStatement/throwStatement_topLevelStatements.ets create mode 100644 ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/throwStatement/throwStatement_trailingLambdaCall.ets create mode 100644 ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/throwStatement/throwStatement_tryStatement.ets create mode 100644 ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/tryStatement/tryStatement_awaitExpression.ets create mode 100644 ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/tryStatement/tryStatement_classInitializer.ets create mode 100644 ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/tryStatement/tryStatement_enumDeclaration.ets create mode 100644 ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/tryStatement/tryStatement_finallyClause.ets create mode 100644 ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/tryStatement/tryStatement_functionTypeWithReceiver.ets create mode 100644 ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/tryStatement/tryStatement_initializerBlock.ets create mode 100644 ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/tryStatement/tryStatement_lambdaExpressionWithReceiver.ets create mode 100644 ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/tryStatement/tryStatement_namespaceDeclaration.ets create mode 100644 ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/tryStatement/tryStatement_newArrayInstance.ets create mode 100644 ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/tryStatement/tryStatement_separateModuleDeclaration.ets create mode 100644 ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/tryStatement/tryStatement_topDeclaration.ets create mode 100644 ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/tryStatement/tryStatement_topLevelStatements.ets create mode 100644 ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/tryStatement/tryStatement_trailingLambdaCall.ets create mode 100644 ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/whileStatement/whileStatement_awaitExpression.ets create mode 100644 ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/whileStatement/whileStatement_breakStatement.ets create mode 100644 ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/whileStatement/whileStatement_classInitializer.ets create mode 100644 ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/whileStatement/whileStatement_continueStatement.ets create mode 100644 ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/whileStatement/whileStatement_enumDeclaration.ets create mode 100644 ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/whileStatement/whileStatement_finallyClause.ets create mode 100644 ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/whileStatement/whileStatement_forOfStatement.ets create mode 100644 ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/whileStatement/whileStatement_forStatement.ets create mode 100644 ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/whileStatement/whileStatement_functionTypeWithReceiver.ets create mode 100644 ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/whileStatement/whileStatement_initializerBlock.ets create mode 100644 ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/whileStatement/whileStatement_lambdaExpressionWithReceiver.ets create mode 100644 ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/whileStatement/whileStatement_namespaceDeclaration.ets create mode 100644 ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/whileStatement/whileStatement_newArrayInstance.ets create mode 100644 ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/whileStatement/whileStatement_returnStatement.ets create mode 100644 ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/whileStatement/whileStatement_separateModuleDeclaration.ets create mode 100644 ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/whileStatement/whileStatement_switchStatement.ets create mode 100644 ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/whileStatement/whileStatement_throwStatement.ets create mode 100644 ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/whileStatement/whileStatement_topDeclaration.ets create mode 100644 ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/whileStatement/whileStatement_topLevelStatements.ets create mode 100644 ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/whileStatement/whileStatement_trailingLambdaCall.ets create mode 100644 ets2panda/test/ast/compiler/ets/spec_orthogonality/8_statements/whileStatement/whileStatement_tryStatement.ets 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 0000000000..8978de1cee --- /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 0000000000..657b181b4c --- /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 0000000000..8f9a1bcbda --- /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 0000000000..9c378fd6cf --- /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 0000000000..bbc95f26e0 --- /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 0000000000..d898086270 --- /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 0000000000..44e6ac37a6 --- /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 0000000000..350d51f53e --- /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 0000000000..8c63c7c771 --- /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 0000000000..d077565a82 --- /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 0000000000..ed2faba49a --- /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 0000000000..d4a9bdc9fa --- /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 0000000000..9aac48c811 --- /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 0000000000..aba24d8922 --- /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 0000000000..27d3a71982 --- /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 0000000000..069a63518b --- /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 0000000000..c7641f9f50 --- /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 0000000000..eaa7405697 --- /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 0000000000..2e7faaff43 --- /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 0000000000..aeb0a1b1aa --- /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 0000000000..9ad24f469d --- /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 0000000000..4cec49dbec --- /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 0000000000..de0b564cce --- /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 0000000000..759c565243 --- /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 0000000000..d55c2924f0 --- /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 0000000000..6a0b6a56cd --- /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 0000000000..59ac8e708b --- /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 0000000000..7c8707a0b9 --- /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 0000000000..ae3c223202 --- /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 0000000000..a33cbfac18 --- /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 0000000000..7f2b9f92cb --- /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 0000000000..cc26c74a61 --- /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 0000000000..3986ae110e --- /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 0000000000..e73b852358 --- /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 0000000000..f75da53839 --- /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 0000000000..b0d26da9ed --- /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 0000000000..89c92e1bef --- /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 0000000000..02540243f6 --- /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 0000000000..0ed4e38ee3 --- /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 0000000000..d5452ca190 --- /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 0000000000..0e3723b30e --- /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 0000000000..7f4e418025 --- /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 0000000000..e54d043604 --- /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 0000000000..b14b888701 --- /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 0000000000..79bb20a99d --- /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 0000000000..e67935727e --- /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 0000000000..c61d75da47 --- /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 0000000000..e20c8cafb5 --- /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 0000000000..f463c29160 --- /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 0000000000..f07cb9bd4f --- /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 0000000000..4d9262de82 --- /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 0000000000..cbb468ecf5 --- /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 0000000000..e114b870d3 --- /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 0000000000..7bcc878912 --- /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 0000000000..3692feafac --- /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 0000000000..e3ab7bc349 --- /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 0000000000..2999405cdf --- /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 0000000000..793d679820 --- /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 0000000000..f98aa87a8a --- /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 0000000000..0e5d628ec1 --- /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 0000000000..f4b5a7ad4a --- /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 0000000000..c5408306aa --- /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 0000000000..4e7333fff8 --- /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 0000000000..7f9cbc33bf --- /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 0000000000..4b546ae1f6 --- /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 0000000000..a5a25d4dcb --- /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 0000000000..1edc9d9f30 --- /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 0000000000..db10ddcb95 --- /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 0000000000..caa6d63632 --- /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 0000000000..7640bdd92b --- /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 0000000000..f500a56d25 --- /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 0000000000..489bc01d22 --- /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 0000000000..8adc562cc6 --- /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 0000000000..21849d3b3b --- /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 0000000000..d5dae35f09 --- /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 0000000000..7bc00484a3 --- /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 0000000000..8857bfe9e1 --- /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 0000000000..c47296da08 --- /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 0000000000..08bf1ec51c --- /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 0000000000..7831dce888 --- /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 0000000000..7f568bd75b --- /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 0000000000..9ee54c1a13 --- /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 0000000000..1aa87cab4f --- /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 0000000000..fea04b3b5a --- /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 0000000000..459b972659 --- /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 0000000000..dccd7e6aca --- /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 0000000000..36bd223f57 --- /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 0000000000..5a5743a425 --- /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 0000000000..97560b45b0 --- /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 0000000000..68ecb38a58 --- /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 0000000000..724d2efd89 --- /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 0000000000..98e3896648 --- /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 0000000000..72d2745e70 --- /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 0000000000..145445af83 --- /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 0000000000..c3f4eee408 --- /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 0000000000..b50d7175d8 --- /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 0000000000..07bce69035 --- /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 0000000000..e2b1872c2f --- /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 0000000000..281187a2f5 --- /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 0000000000..7b47b513ef --- /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 0000000000..b1af74844d --- /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 0000000000..590fc9f944 --- /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 0000000000..23a1143002 --- /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 0000000000..ae715c5785 --- /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 0000000000..12a293277a --- /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 0000000000..e6151e370e --- /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 0000000000..de731977b0 --- /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 0000000000..6d3c11b5ca --- /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 0000000000..e6b50144c4 --- /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 0000000000..d841c8f77e --- /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 0000000000..b046f5435b --- /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 0000000000..e826416873 --- /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 0000000000..9469ff2827 --- /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 0000000000..0bbf74c3d5 --- /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 0000000000..ad3708a244 --- /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 0000000000..373db76a56 --- /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 0000000000..d65d169f26 --- /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 0000000000..b980493ee2 --- /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 0000000000..1f604ec7de --- /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 0000000000..c75d5cf150 --- /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 0000000000..23932f71c6 --- /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 0000000000..f3d4d97765 --- /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 0000000000..dbf5f4d6e2 --- /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 0000000000..d0e9b4ba60 --- /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 0000000000..2164cc17bc --- /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 0000000000..11023a5bf6 --- /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 0000000000..18af3734ef --- /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 0000000000..ac0c72a7f8 --- /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 0000000000..dd16100b5e --- /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 0000000000..a69c501da4 --- /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 0000000000..30399bccbc --- /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 0000000000..702c12d1f8 --- /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 0000000000..87cf9bcece --- /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 0000000000..e73e285459 --- /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 0000000000..b2d0eeecc9 --- /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 0000000000..36e1e439fd --- /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 0000000000..31cabd1cc3 --- /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 0000000000..b0756dd21c --- /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 0000000000..3ea0149f50 --- /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 0000000000..7f4273c94b --- /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 0000000000..9755d99e50 --- /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 0000000000..1044ea597f --- /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 0000000000..f8cce7369d --- /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 0000000000..a727f6ee6e --- /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 0000000000..48c99dcfdc --- /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 0000000000..0efae3bf4e --- /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 0000000000..90ec799af0 --- /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 0000000000..6270fe2c6f --- /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 0000000000..ccbb07f72a --- /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 0000000000..bd45cd4931 --- /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 0000000000..c8fed7d6ca --- /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 0000000000..393b3125a7 --- /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 0000000000..0d5365e44e --- /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 0000000000..005a74f6b3 --- /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 0000000000..53155443f0 --- /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 0000000000..3f3dde1f54 --- /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 0000000000..0a065757de --- /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 0000000000..dd699319b8 --- /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 0000000000..018c8b1dd2 --- /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 0000000000..0b0239dc02 --- /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 0000000000..7aff9aec25 --- /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 0000000000..782c8ee816 --- /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 0000000000..1f29d82d9b --- /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 0000000000..7e069c2f5d --- /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 0000000000..fec75a0ce1 --- /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 0000000000..70bee953da --- /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 0000000000..a07bc5fcb5 --- /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 0000000000..29d84414a1 --- /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 0000000000..4718f75b47 --- /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 0000000000..053fd6ff12 --- /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 0000000000..90a1825536 --- /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 0000000000..9f28f09047 --- /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 0000000000..2e5694452f --- /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 0000000000..e48cefdf85 --- /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 0000000000..ad072c2ac2 --- /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 0000000000..2338f188cb --- /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 0000000000..9f4d51a4e6 --- /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 0000000000..a8f91281d1 --- /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 0000000000..287f128b75 --- /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 0000000000..d65834f9fc --- /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 0000000000..b727e68519 --- /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 0000000000..59bc8406f1 --- /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 0000000000..6a2c48883c --- /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 0000000000..fe4fac42ee --- /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 0000000000..3786b2e503 --- /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 0000000000..86ac29da58 --- /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 0000000000..c6b19e0d70 --- /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 0000000000..28db921582 --- /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 0000000000..d91a96de06 --- /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 0000000000..0f493c5702 --- /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 0000000000..8e05278a55 --- /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 0000000000..d405550c5c --- /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 0000000000..2f7df0f8ab --- /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 0000000000..fb35eacd1d --- /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 0000000000..e573a01bb1 --- /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 0000000000..aa683d4aa6 --- /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 0000000000..dfa6eba182 --- /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 0000000000..28625b5a19 --- /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 0000000000..d77c02b010 --- /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 0000000000..73911de219 --- /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; + } +} -- Gitee