From 0a3b929b22dc1198843ebf4532100e8c6008bf49 Mon Sep 17 00:00:00 2001 From: oh-rgx Date: Sat, 29 Mar 2025 18:11:27 +0800 Subject: [PATCH] Correct CTS Tests Issue: #IBX96K Signed-off-by: oh-rgx --- ets2panda/checker/TSAnalyzer.cpp | 4 +- ets2panda/checker/ets/aliveAnalyzer.cpp | 4 +- ets2panda/checker/ets/assignAnalyzer.cpp | 10 +- ets2panda/compiler/core/CFG.cpp | 5 +- ets2panda/compiler/core/switchBuilder.h | 4 +- .../ir/statements/switchCaseStatement.cpp | 38 +- ets2panda/ir/statements/switchCaseStatement.h | 15 +- ets2panda/parser/statementParser.cpp | 3 +- .../ets/switchStatementBoxing-expected.txt | 62 +- ...tchStatementCorrectConversion-expected.txt | 315 +++++--- .../compiler/ts/switch_statement-expected.txt | 153 ++-- .../ets/labeledSwitchStatement-expected.txt | 728 ++++++++++-------- .../parser/ets/localTypeAlias-expected.txt | 507 ++++++------ ets2panda/test/parser/ets/switch-expected.txt | 352 +++++---- .../test/parser/ets/switch2-expected.txt | 352 +++++---- .../parser/ets/switch_alive_1-expected.txt | 165 ++-- .../parser/ets/switch_alive_4-expected.txt | 90 ++- .../ets/switch_char_compare_num-expected.txt | 90 ++- .../ets/switch_enum_string_case-expected.txt | 299 ++++--- .../ets/switch_num_compare_char-expected.txt | 90 ++- .../ets/switch_readonly_member-expected.txt | 135 ++-- ..._readonly_member_compare_char-expected.txt | 180 +++-- ...eadonly_member_compare_char_2-expected.txt | 180 +++-- .../test/unit/public/ast_builder_test.cpp | 5 +- .../ast-builders/switchCaseStatementBuilder.h | 14 +- 25 files changed, 2295 insertions(+), 1505 deletions(-) diff --git a/ets2panda/checker/TSAnalyzer.cpp b/ets2panda/checker/TSAnalyzer.cpp index 25a4cf6789..f67470219a 100644 --- a/ets2panda/checker/TSAnalyzer.cpp +++ b/ets2panda/checker/TSAnalyzer.cpp @@ -1287,9 +1287,7 @@ checker::Type *TSAnalyzer::Check(ir::SwitchStatement *st) const } } - for (auto *caseStmt : it->Consequent()) { - caseStmt->Check(checker); - } + it->Body()->Check(checker); } return nullptr; diff --git a/ets2panda/checker/ets/aliveAnalyzer.cpp b/ets2panda/checker/ets/aliveAnalyzer.cpp index 65da4bccb7..498ee79c4c 100644 --- a/ets2panda/checker/ets/aliveAnalyzer.cpp +++ b/ets2panda/checker/ets/aliveAnalyzer.cpp @@ -402,9 +402,9 @@ void AliveAnalyzer::AnalyzeSwitch(const ir::SwitchStatement *switchStmt) AnalyzeNode(caseClause->Test()); } - AnalyzeStats(caseClause->Consequent()); + AnalyzeStats(caseClause->Body()->Statements()); - if (status_ == LivenessStatus::ALIVE && !caseClause->Consequent().empty() && i < size - 1) { + if (status_ == LivenessStatus::ALIVE && !caseClause->Body()->Statements().empty() && i < size - 1) { // NOTE(user) Add lint categories and option to enable/disable compiler warnings checker_->Warning("Possible fall-through into case", caseClause->Start()); } diff --git a/ets2panda/checker/ets/assignAnalyzer.cpp b/ets2panda/checker/ets/assignAnalyzer.cpp index f0e115a8ea..8b033f4ae3 100644 --- a/ets2panda/checker/ets/assignAnalyzer.cpp +++ b/ets2panda/checker/ets/assignAnalyzer.cpp @@ -845,13 +845,11 @@ void AssignAnalyzer::AnalyzeSwitch(const ir::SwitchStatement *switchStmt) uninits_ = uninits_.AndSet(uninitsSwitch); } - AnalyzeStats(caseClause->Consequent()); + AnalyzeBlock(caseClause->Body()); - for (const auto stmt : caseClause->Consequent()) { - if (!stmt->IsVariableDeclaration()) { - continue; - } - for (auto *var : stmt->AsVariableDeclaration()->Declarators()) { + auto *blockStatement = caseClause->Body(); + if (blockStatement->IsVariableDeclaration()) { + for (auto *var : blockStatement->AsVariableDeclaration()->Declarators()) { NodeId adr = GetNodeId(var); ES2PANDA_ASSERT(adr >= 0); initsSwitch.Excl(adr); diff --git a/ets2panda/compiler/core/CFG.cpp b/ets2panda/compiler/core/CFG.cpp index 20c5f58b7f..8943f2a703 100644 --- a/ets2panda/compiler/core/CFG.cpp +++ b/ets2panda/compiler/core/CFG.cpp @@ -558,9 +558,8 @@ CFG::BasicBlock *CFG::Build(ir::SwitchStatement *switchStatementNode, BasicBlock } auto caseBB = CreateNewBB({bb, fallThrough}, {switchCase->Test()}); - for (auto consStatement : switchCase->Consequent()) { - caseBB = Build(consStatement, caseBB); - } + auto *body = switchCase->Body(); + caseBB = Build(body, caseBB); fallThrough = caseBB; } diff --git a/ets2panda/compiler/core/switchBuilder.h b/ets2panda/compiler/core/switchBuilder.h index 02983de277..e1d7595cbc 100644 --- a/ets2panda/compiler/core/switchBuilder.h +++ b/ets2panda/compiler/core/switchBuilder.h @@ -65,9 +65,7 @@ public: void CompileCaseStatements(uint32_t index) { - for (const auto *stmt : stmt_->Cases()[index]->Consequent()) { - stmt->Compile(cg_); - } + stmt_->Cases()[index]->Body()->Compile(cg_); } void JumpIfCase(const VReg tag, const uint32_t index) diff --git a/ets2panda/ir/statements/switchCaseStatement.cpp b/ets2panda/ir/statements/switchCaseStatement.cpp index eec65df177..7e1f022e9a 100644 --- a/ets2panda/ir/statements/switchCaseStatement.cpp +++ b/ets2panda/ir/statements/switchCaseStatement.cpp @@ -32,11 +32,9 @@ void SwitchCaseStatement::TransformChildren(const NodeTransformer &cb, std::stri } } - for (auto *&it : VectorIterationGuard(consequent_)) { - if (auto *transformedNode = cb(it); it != transformedNode) { - it->SetTransformedNode(transformationName, transformedNode); - it = transformedNode->AsStatement(); - } + if (auto *transformedNode = cb(body_); body_ != transformedNode) { + body_->SetTransformedNode(transformationName, transformedNode); + body_ = transformedNode->AsBlockStatement(); } } @@ -46,14 +44,14 @@ void SwitchCaseStatement::Iterate(const NodeTraverser &cb) const cb(test_); } - for (auto *it : VectorIterationGuard(consequent_)) { - cb(it); + if (body_ != nullptr) { + cb(body_); } } void SwitchCaseStatement::Dump(ir::AstDumper *dumper) const { - dumper->Add({{"type", "SwitchCase"}, {"test", AstDumper::Nullish(test_)}, {"consequent", consequent_}}); + dumper->Add({{"type", "SwitchCase"}, {"test", AstDumper::Nullish(test_)}, {"body", body_}}); } void SwitchCaseStatement::Dump(ir::SrcDumper *dumper) const @@ -65,16 +63,8 @@ void SwitchCaseStatement::Dump(ir::SrcDumper *dumper) const } else { dumper->Add("default:"); } - if (!consequent_.empty()) { - dumper->IncrIndent(); - dumper->Endl(); - for (auto cs : consequent_) { - cs->Dump(dumper); - if (!cs->IsBlockStatement() && cs != consequent_.back()) { - dumper->Endl(); - } - } - dumper->DecrIndent(); + if (body_ != nullptr) { + body_->Dump(dumper); } } @@ -133,21 +123,13 @@ void SwitchCaseStatement::CheckAndTestCase(checker::ETSChecker *checker, checker isDefaultCase = true; } - for (auto *caseStmt : consequent_) { - caseStmt->Check(checker); - } + body_->Check(checker); } SwitchCaseStatement *SwitchCaseStatement::Clone(ArenaAllocator *const allocator, AstNode *const parent) { auto *const test = test_->Clone(allocator, nullptr)->AsExpression(); - ArenaVector consequent(allocator->Adapter()); - - for (auto *statement : consequent_) { - consequent.push_back(statement->Clone(allocator, nullptr)->AsStatement()); - } - - auto clone = util::NodeAllocator::ForceSetParent(allocator, test, std::move(consequent)); + auto clone = util::NodeAllocator::ForceSetParent(allocator, test, body_); clone->SetParent(parent); clone->SetRange(Range()); diff --git a/ets2panda/ir/statements/switchCaseStatement.h b/ets2panda/ir/statements/switchCaseStatement.h index 15dc89d788..624fd6a5c8 100644 --- a/ets2panda/ir/statements/switchCaseStatement.h +++ b/ets2panda/ir/statements/switchCaseStatement.h @@ -30,8 +30,8 @@ public: NO_COPY_SEMANTIC(SwitchCaseStatement); NO_MOVE_SEMANTIC(SwitchCaseStatement); - explicit SwitchCaseStatement(Expression *test, ArenaVector &&consequent) - : Statement(AstNodeType::SWITCH_CASE_STATEMENT), test_(test), consequent_(std::move(consequent)) + explicit SwitchCaseStatement(Expression *test, BlockStatement *body) + : Statement(AstNodeType::SWITCH_CASE_STATEMENT), test_(test), body_(body) { } @@ -53,9 +53,14 @@ public: test_ = test; } - [[nodiscard]] const ArenaVector &Consequent() const noexcept + [[nodiscard]] const BlockStatement *Body() const noexcept { - return consequent_; + return body_; + } + + [[nodiscard]] BlockStatement *Body() noexcept + { + return body_; } void TransformChildren(const NodeTransformer &cb, std::string_view transformationName) override; @@ -80,7 +85,7 @@ public: private: Expression *test_; - ArenaVector consequent_; + BlockStatement *body_; }; } // namespace ark::es2panda::ir diff --git a/ets2panda/parser/statementParser.cpp b/ets2panda/parser/statementParser.cpp index b0a687a823..fe629f6f74 100644 --- a/ets2panda/parser/statementParser.cpp +++ b/ets2panda/parser/statementParser.cpp @@ -1178,7 +1178,8 @@ ir::SwitchCaseStatement *ParserImpl::ParseSwitchCaseStatement(bool *seenDefault) consequents.push_back(consequent); } - auto *caseNode = AllocNode(testExpr, std::move(consequents)); + auto *blockStatementNode = AllocNode(Allocator(), std::move(consequents)); + auto *caseNode = AllocNode(testExpr, blockStatementNode); caseNode->SetRange({caseStartLoc, caseEndLoc}); return caseNode; } diff --git a/ets2panda/test/compiler/ets/switchStatementBoxing-expected.txt b/ets2panda/test/compiler/ets/switchStatementBoxing-expected.txt index 516f90ed32..8ae9531c8c 100644 --- a/ets2panda/test/compiler/ets/switchStatementBoxing-expected.txt +++ b/ets2panda/test/compiler/ets/switchStatementBoxing-expected.txt @@ -324,24 +324,39 @@ } } }, - "consequent": [ - { - "type": "BreakStatement", - "label": null, - "loc": { - "start": { - "line": 22, - "column": 17, - "program": "switchStatementBoxing.ets" - }, - "end": { - "line": 22, - "column": 23, - "program": "switchStatementBoxing.ets" + "body": { + "type": "BlockStatement", + "statements": [ + { + "type": "BreakStatement", + "label": null, + "loc": { + "start": { + "line": 22, + "column": 17, + "program": "switchStatementBoxing.ets" + }, + "end": { + "line": 22, + "column": 23, + "program": "switchStatementBoxing.ets" + } } } + ], + "loc": { + "start": { + "line": 1, + "column": 1, + "program": null + }, + "end": { + "line": 1, + "column": 1, + "program": null + } } - ], + }, "loc": { "start": { "line": 21, @@ -373,7 +388,22 @@ } } }, - "consequent": [], + "body": { + "type": "BlockStatement", + "statements": [], + "loc": { + "start": { + "line": 1, + "column": 1, + "program": null + }, + "end": { + "line": 1, + "column": 1, + "program": null + } + } + }, "loc": { "start": { "line": 23, diff --git a/ets2panda/test/compiler/ets/switchStatementCorrectConversion-expected.txt b/ets2panda/test/compiler/ets/switchStatementCorrectConversion-expected.txt index d0694d6504..9dd2075b4e 100644 --- a/ets2panda/test/compiler/ets/switchStatementCorrectConversion-expected.txt +++ b/ets2panda/test/compiler/ets/switchStatementCorrectConversion-expected.txt @@ -210,24 +210,39 @@ } } }, - "consequent": [ - { - "type": "BreakStatement", - "label": null, - "loc": { - "start": { - "line": 21, - "column": 17, - "program": "switchStatementCorrectConversion.ets" - }, - "end": { - "line": 21, - "column": 23, - "program": "switchStatementCorrectConversion.ets" + "body": { + "type": "BlockStatement", + "statements": [ + { + "type": "BreakStatement", + "label": null, + "loc": { + "start": { + "line": 21, + "column": 17, + "program": "switchStatementCorrectConversion.ets" + }, + "end": { + "line": 21, + "column": 23, + "program": "switchStatementCorrectConversion.ets" + } } } + ], + "loc": { + "start": { + "line": 1, + "column": 1, + "program": null + }, + "end": { + "line": 1, + "column": 1, + "program": null + } } - ], + }, "loc": { "start": { "line": 20, @@ -259,24 +274,39 @@ } } }, - "consequent": [ - { - "type": "BreakStatement", - "label": null, - "loc": { - "start": { - "line": 23, - "column": 17, - "program": "switchStatementCorrectConversion.ets" - }, - "end": { - "line": 23, - "column": 23, - "program": "switchStatementCorrectConversion.ets" + "body": { + "type": "BlockStatement", + "statements": [ + { + "type": "BreakStatement", + "label": null, + "loc": { + "start": { + "line": 23, + "column": 17, + "program": "switchStatementCorrectConversion.ets" + }, + "end": { + "line": 23, + "column": 23, + "program": "switchStatementCorrectConversion.ets" + } } } + ], + "loc": { + "start": { + "line": 1, + "column": 1, + "program": null + }, + "end": { + "line": 1, + "column": 1, + "program": null + } } - ], + }, "loc": { "start": { "line": 22, @@ -308,24 +338,39 @@ } } }, - "consequent": [ - { - "type": "BreakStatement", - "label": null, - "loc": { - "start": { - "line": 25, - "column": 17, - "program": "switchStatementCorrectConversion.ets" - }, - "end": { - "line": 25, - "column": 23, - "program": "switchStatementCorrectConversion.ets" + "body": { + "type": "BlockStatement", + "statements": [ + { + "type": "BreakStatement", + "label": null, + "loc": { + "start": { + "line": 25, + "column": 17, + "program": "switchStatementCorrectConversion.ets" + }, + "end": { + "line": 25, + "column": 23, + "program": "switchStatementCorrectConversion.ets" + } } } + ], + "loc": { + "start": { + "line": 1, + "column": 1, + "program": null + }, + "end": { + "line": 1, + "column": 1, + "program": null + } } - ], + }, "loc": { "start": { "line": 24, @@ -357,24 +402,39 @@ } } }, - "consequent": [ - { - "type": "BreakStatement", - "label": null, - "loc": { - "start": { - "line": 27, - "column": 17, - "program": "switchStatementCorrectConversion.ets" - }, - "end": { - "line": 27, - "column": 23, - "program": "switchStatementCorrectConversion.ets" + "body": { + "type": "BlockStatement", + "statements": [ + { + "type": "BreakStatement", + "label": null, + "loc": { + "start": { + "line": 27, + "column": 17, + "program": "switchStatementCorrectConversion.ets" + }, + "end": { + "line": 27, + "column": 23, + "program": "switchStatementCorrectConversion.ets" + } } } + ], + "loc": { + "start": { + "line": 1, + "column": 1, + "program": null + }, + "end": { + "line": 1, + "column": 1, + "program": null + } } - ], + }, "loc": { "start": { "line": 26, @@ -406,24 +466,39 @@ } } }, - "consequent": [ - { - "type": "BreakStatement", - "label": null, - "loc": { - "start": { - "line": 29, - "column": 17, - "program": "switchStatementCorrectConversion.ets" - }, - "end": { - "line": 29, - "column": 23, - "program": "switchStatementCorrectConversion.ets" + "body": { + "type": "BlockStatement", + "statements": [ + { + "type": "BreakStatement", + "label": null, + "loc": { + "start": { + "line": 29, + "column": 17, + "program": "switchStatementCorrectConversion.ets" + }, + "end": { + "line": 29, + "column": 23, + "program": "switchStatementCorrectConversion.ets" + } } } + ], + "loc": { + "start": { + "line": 1, + "column": 1, + "program": null + }, + "end": { + "line": 1, + "column": 1, + "program": null + } } - ], + }, "loc": { "start": { "line": 28, @@ -683,24 +758,39 @@ } } }, - "consequent": [ - { - "type": "BreakStatement", - "label": null, - "loc": { - "start": { - "line": 36, - "column": 17, - "program": "switchStatementCorrectConversion.ets" - }, - "end": { - "line": 36, - "column": 23, - "program": "switchStatementCorrectConversion.ets" + "body": { + "type": "BlockStatement", + "statements": [ + { + "type": "BreakStatement", + "label": null, + "loc": { + "start": { + "line": 36, + "column": 17, + "program": "switchStatementCorrectConversion.ets" + }, + "end": { + "line": 36, + "column": 23, + "program": "switchStatementCorrectConversion.ets" + } } } + ], + "loc": { + "start": { + "line": 1, + "column": 1, + "program": null + }, + "end": { + "line": 1, + "column": 1, + "program": null + } } - ], + }, "loc": { "start": { "line": 35, @@ -733,24 +823,39 @@ } } }, - "consequent": [ - { - "type": "BreakStatement", - "label": null, - "loc": { - "start": { - "line": 38, - "column": 17, - "program": "switchStatementCorrectConversion.ets" - }, - "end": { - "line": 38, - "column": 23, - "program": "switchStatementCorrectConversion.ets" + "body": { + "type": "BlockStatement", + "statements": [ + { + "type": "BreakStatement", + "label": null, + "loc": { + "start": { + "line": 38, + "column": 17, + "program": "switchStatementCorrectConversion.ets" + }, + "end": { + "line": 38, + "column": 23, + "program": "switchStatementCorrectConversion.ets" + } } } + ], + "loc": { + "start": { + "line": 1, + "column": 1, + "program": null + }, + "end": { + "line": 1, + "column": 1, + "program": null + } } - ], + }, "loc": { "start": { "line": 37, diff --git a/ets2panda/test/compiler/ts/switch_statement-expected.txt b/ets2panda/test/compiler/ts/switch_statement-expected.txt index eec925e087..fce153c67b 100644 --- a/ets2panda/test/compiler/ts/switch_statement-expected.txt +++ b/ets2panda/test/compiler/ts/switch_statement-expected.txt @@ -122,7 +122,22 @@ } } }, - "consequent": [], + "body": { + "type": "BlockStatement", + "statements": [], + "loc": { + "start": { + "line": 1, + "column": 1, + "program": null + }, + "end": { + "line": 1, + "column": 1, + "program": null + } + } + }, "loc": { "start": { "line": 18, @@ -154,7 +169,22 @@ } } }, - "consequent": [], + "body": { + "type": "BlockStatement", + "statements": [], + "loc": { + "start": { + "line": 1, + "column": 1, + "program": null + }, + "end": { + "line": 1, + "column": 1, + "program": null + } + } + }, "loc": { "start": { "line": 19, @@ -171,36 +201,51 @@ { "type": "SwitchCase", "test": null, - "consequent": [ - { - "type": "ExpressionStatement", - "expression": { - "type": "AssignmentExpression", - "operator": "=", - "left": { - "type": "Identifier", - "name": "arg", - "decorators": [], - "loc": { - "start": { - "line": 21, - "column": 4, - "program": "switch_statement.ts" - }, - "end": { - "line": 21, - "column": 7, - "program": "switch_statement.ts" + "body": { + "type": "BlockStatement", + "statements": [ + { + "type": "ExpressionStatement", + "expression": { + "type": "AssignmentExpression", + "operator": "=", + "left": { + "type": "Identifier", + "name": "arg", + "decorators": [], + "loc": { + "start": { + "line": 21, + "column": 4, + "program": "switch_statement.ts" + }, + "end": { + "line": 21, + "column": 7, + "program": "switch_statement.ts" + } } - } - }, - "right": { - "type": "NumberLiteral", - "value": 1, + }, + "right": { + "type": "NumberLiteral", + "value": 1, + "loc": { + "start": { + "line": 21, + "column": 8, + "program": "switch_statement.ts" + }, + "end": { + "line": 21, + "column": 9, + "program": "switch_statement.ts" + } + } + }, "loc": { "start": { "line": 21, - "column": 8, + "column": 4, "program": "switch_statement.ts" }, "end": { @@ -223,36 +268,36 @@ } } }, - "loc": { - "start": { - "line": 21, - "column": 4, - "program": "switch_statement.ts" - }, - "end": { - "line": 21, - "column": 9, - "program": "switch_statement.ts" + { + "type": "BreakStatement", + "label": null, + "loc": { + "start": { + "line": 22, + "column": 4, + "program": "switch_statement.ts" + }, + "end": { + "line": 22, + "column": 10, + "program": "switch_statement.ts" + } } } - }, - { - "type": "BreakStatement", - "label": null, - "loc": { - "start": { - "line": 22, - "column": 4, - "program": "switch_statement.ts" - }, - "end": { - "line": 22, - "column": 10, - "program": "switch_statement.ts" - } + ], + "loc": { + "start": { + "line": 1, + "column": 1, + "program": null + }, + "end": { + "line": 1, + "column": 1, + "program": null } } - ], + }, "loc": { "start": { "line": 20, diff --git a/ets2panda/test/parser/ets/labeledSwitchStatement-expected.txt b/ets2panda/test/parser/ets/labeledSwitchStatement-expected.txt index a79f02caeb..c170e6c01c 100644 --- a/ets2panda/test/parser/ets/labeledSwitchStatement-expected.txt +++ b/ets2panda/test/parser/ets/labeledSwitchStatement-expected.txt @@ -695,7 +695,22 @@ } } }, - "consequent": [], + "body": { + "type": "BlockStatement", + "statements": [], + "loc": { + "start": { + "line": 1, + "column": 1, + "program": null + }, + "end": { + "line": 1, + "column": 1, + "program": null + } + } + }, "loc": { "start": { "line": 23, @@ -727,36 +742,51 @@ } } }, - "consequent": [ - { - "type": "ExpressionStatement", - "expression": { - "type": "AssignmentExpression", - "operator": "=", - "left": { - "type": "Identifier", - "name": "result", - "decorators": [], - "loc": { - "start": { - "line": 25, - "column": 17, - "program": "labeledSwitchStatement.ets" - }, - "end": { - "line": 25, - "column": 23, - "program": "labeledSwitchStatement.ets" + "body": { + "type": "BlockStatement", + "statements": [ + { + "type": "ExpressionStatement", + "expression": { + "type": "AssignmentExpression", + "operator": "=", + "left": { + "type": "Identifier", + "name": "result", + "decorators": [], + "loc": { + "start": { + "line": 25, + "column": 17, + "program": "labeledSwitchStatement.ets" + }, + "end": { + "line": 25, + "column": 23, + "program": "labeledSwitchStatement.ets" + } } - } - }, - "right": { - "type": "NumberLiteral", - "value": 1, + }, + "right": { + "type": "NumberLiteral", + "value": 1, + "loc": { + "start": { + "line": 25, + "column": 26, + "program": "labeledSwitchStatement.ets" + }, + "end": { + "line": 25, + "column": 27, + "program": "labeledSwitchStatement.ets" + } + } + }, "loc": { "start": { "line": 25, - "column": 26, + "column": 17, "program": "labeledSwitchStatement.ets" }, "end": { @@ -774,41 +804,41 @@ }, "end": { "line": 25, - "column": 27, + "column": 28, "program": "labeledSwitchStatement.ets" } } }, - "loc": { - "start": { - "line": 25, - "column": 17, - "program": "labeledSwitchStatement.ets" - }, - "end": { - "line": 25, - "column": 28, - "program": "labeledSwitchStatement.ets" + { + "type": "BreakStatement", + "label": null, + "loc": { + "start": { + "line": 26, + "column": 17, + "program": "labeledSwitchStatement.ets" + }, + "end": { + "line": 26, + "column": 23, + "program": "labeledSwitchStatement.ets" + } } } - }, - { - "type": "BreakStatement", - "label": null, - "loc": { - "start": { - "line": 26, - "column": 17, - "program": "labeledSwitchStatement.ets" - }, - "end": { - "line": 26, - "column": 23, - "program": "labeledSwitchStatement.ets" - } + ], + "loc": { + "start": { + "line": 1, + "column": 1, + "program": null + }, + "end": { + "line": 1, + "column": 1, + "program": null } } - ], + }, "loc": { "start": { "line": 24, @@ -840,36 +870,51 @@ } } }, - "consequent": [ - { - "type": "ExpressionStatement", - "expression": { - "type": "AssignmentExpression", - "operator": "=", - "left": { - "type": "Identifier", - "name": "result", - "decorators": [], - "loc": { - "start": { - "line": 28, - "column": 17, - "program": "labeledSwitchStatement.ets" - }, - "end": { - "line": 28, - "column": 23, - "program": "labeledSwitchStatement.ets" + "body": { + "type": "BlockStatement", + "statements": [ + { + "type": "ExpressionStatement", + "expression": { + "type": "AssignmentExpression", + "operator": "=", + "left": { + "type": "Identifier", + "name": "result", + "decorators": [], + "loc": { + "start": { + "line": 28, + "column": 17, + "program": "labeledSwitchStatement.ets" + }, + "end": { + "line": 28, + "column": 23, + "program": "labeledSwitchStatement.ets" + } } - } - }, - "right": { - "type": "NumberLiteral", - "value": 2, + }, + "right": { + "type": "NumberLiteral", + "value": 2, + "loc": { + "start": { + "line": 28, + "column": 26, + "program": "labeledSwitchStatement.ets" + }, + "end": { + "line": 28, + "column": 27, + "program": "labeledSwitchStatement.ets" + } + } + }, "loc": { "start": { "line": 28, - "column": 26, + "column": 17, "program": "labeledSwitchStatement.ets" }, "end": { @@ -887,57 +932,57 @@ }, "end": { "line": 28, - "column": 27, + "column": 28, "program": "labeledSwitchStatement.ets" } } }, - "loc": { - "start": { - "line": 28, - "column": 17, - "program": "labeledSwitchStatement.ets" + { + "type": "ContinueStatement", + "label": { + "type": "Identifier", + "name": "label1", + "decorators": [], + "loc": { + "start": { + "line": 29, + "column": 26, + "program": "labeledSwitchStatement.ets" + }, + "end": { + "line": 29, + "column": 32, + "program": "labeledSwitchStatement.ets" + } + } }, - "end": { - "line": 28, - "column": 28, - "program": "labeledSwitchStatement.ets" - } - } - }, - { - "type": "ContinueStatement", - "label": { - "type": "Identifier", - "name": "label1", - "decorators": [], "loc": { "start": { "line": 29, - "column": 26, + "column": 17, "program": "labeledSwitchStatement.ets" }, "end": { "line": 29, - "column": 32, + "column": 33, "program": "labeledSwitchStatement.ets" } } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1, + "program": null }, - "loc": { - "start": { - "line": 29, - "column": 17, - "program": "labeledSwitchStatement.ets" - }, - "end": { - "line": 29, - "column": 33, - "program": "labeledSwitchStatement.ets" - } + "end": { + "line": 1, + "column": 1, + "program": null } } - ], + }, "loc": { "start": { "line": 27, @@ -954,36 +999,51 @@ { "type": "SwitchCase", "test": null, - "consequent": [ - { - "type": "ExpressionStatement", - "expression": { - "type": "AssignmentExpression", - "operator": "=", - "left": { - "type": "Identifier", - "name": "result", - "decorators": [], - "loc": { - "start": { - "line": 31, - "column": 17, - "program": "labeledSwitchStatement.ets" - }, - "end": { - "line": 31, - "column": 23, - "program": "labeledSwitchStatement.ets" + "body": { + "type": "BlockStatement", + "statements": [ + { + "type": "ExpressionStatement", + "expression": { + "type": "AssignmentExpression", + "operator": "=", + "left": { + "type": "Identifier", + "name": "result", + "decorators": [], + "loc": { + "start": { + "line": 31, + "column": 17, + "program": "labeledSwitchStatement.ets" + }, + "end": { + "line": 31, + "column": 23, + "program": "labeledSwitchStatement.ets" + } } - } - }, - "right": { - "type": "NumberLiteral", - "value": 3400, + }, + "right": { + "type": "NumberLiteral", + "value": 3400, + "loc": { + "start": { + "line": 31, + "column": 26, + "program": "labeledSwitchStatement.ets" + }, + "end": { + "line": 31, + "column": 30, + "program": "labeledSwitchStatement.ets" + } + } + }, "loc": { "start": { "line": 31, - "column": 26, + "column": 17, "program": "labeledSwitchStatement.ets" }, "end": { @@ -1001,25 +1061,25 @@ }, "end": { "line": 31, - "column": 30, + "column": 31, "program": "labeledSwitchStatement.ets" } } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1, + "program": null }, - "loc": { - "start": { - "line": 31, - "column": 17, - "program": "labeledSwitchStatement.ets" - }, - "end": { - "line": 31, - "column": 31, - "program": "labeledSwitchStatement.ets" - } + "end": { + "line": 1, + "column": 1, + "program": null } } - ], + }, "loc": { "start": { "line": 30, @@ -1567,7 +1627,22 @@ } } }, - "consequent": [], + "body": { + "type": "BlockStatement", + "statements": [], + "loc": { + "start": { + "line": 1, + "column": 1, + "program": null + }, + "end": { + "line": 1, + "column": 1, + "program": null + } + } + }, "loc": { "start": { "line": 43, @@ -1599,36 +1674,51 @@ } } }, - "consequent": [ - { - "type": "ExpressionStatement", - "expression": { - "type": "AssignmentExpression", - "operator": "=", - "left": { - "type": "Identifier", - "name": "result", - "decorators": [], - "loc": { - "start": { - "line": 45, - "column": 17, - "program": "labeledSwitchStatement.ets" - }, - "end": { - "line": 45, - "column": 23, - "program": "labeledSwitchStatement.ets" + "body": { + "type": "BlockStatement", + "statements": [ + { + "type": "ExpressionStatement", + "expression": { + "type": "AssignmentExpression", + "operator": "=", + "left": { + "type": "Identifier", + "name": "result", + "decorators": [], + "loc": { + "start": { + "line": 45, + "column": 17, + "program": "labeledSwitchStatement.ets" + }, + "end": { + "line": 45, + "column": 23, + "program": "labeledSwitchStatement.ets" + } } - } - }, - "right": { - "type": "NumberLiteral", - "value": 1, + }, + "right": { + "type": "NumberLiteral", + "value": 1, + "loc": { + "start": { + "line": 45, + "column": 26, + "program": "labeledSwitchStatement.ets" + }, + "end": { + "line": 45, + "column": 27, + "program": "labeledSwitchStatement.ets" + } + } + }, "loc": { "start": { "line": 45, - "column": 26, + "column": 17, "program": "labeledSwitchStatement.ets" }, "end": { @@ -1646,41 +1736,41 @@ }, "end": { "line": 45, - "column": 27, + "column": 28, "program": "labeledSwitchStatement.ets" } } }, - "loc": { - "start": { - "line": 45, - "column": 17, - "program": "labeledSwitchStatement.ets" - }, - "end": { - "line": 45, - "column": 28, - "program": "labeledSwitchStatement.ets" + { + "type": "BreakStatement", + "label": null, + "loc": { + "start": { + "line": 46, + "column": 17, + "program": "labeledSwitchStatement.ets" + }, + "end": { + "line": 46, + "column": 23, + "program": "labeledSwitchStatement.ets" + } } } - }, - { - "type": "BreakStatement", - "label": null, - "loc": { - "start": { - "line": 46, - "column": 17, - "program": "labeledSwitchStatement.ets" - }, - "end": { - "line": 46, - "column": 23, - "program": "labeledSwitchStatement.ets" - } + ], + "loc": { + "start": { + "line": 1, + "column": 1, + "program": null + }, + "end": { + "line": 1, + "column": 1, + "program": null } } - ], + }, "loc": { "start": { "line": 44, @@ -1712,36 +1802,51 @@ } } }, - "consequent": [ - { - "type": "ExpressionStatement", - "expression": { - "type": "AssignmentExpression", - "operator": "=", - "left": { - "type": "Identifier", - "name": "result", - "decorators": [], - "loc": { - "start": { - "line": 48, - "column": 17, - "program": "labeledSwitchStatement.ets" - }, - "end": { - "line": 48, - "column": 23, - "program": "labeledSwitchStatement.ets" + "body": { + "type": "BlockStatement", + "statements": [ + { + "type": "ExpressionStatement", + "expression": { + "type": "AssignmentExpression", + "operator": "=", + "left": { + "type": "Identifier", + "name": "result", + "decorators": [], + "loc": { + "start": { + "line": 48, + "column": 17, + "program": "labeledSwitchStatement.ets" + }, + "end": { + "line": 48, + "column": 23, + "program": "labeledSwitchStatement.ets" + } } - } - }, - "right": { - "type": "NumberLiteral", - "value": 2, + }, + "right": { + "type": "NumberLiteral", + "value": 2, + "loc": { + "start": { + "line": 48, + "column": 26, + "program": "labeledSwitchStatement.ets" + }, + "end": { + "line": 48, + "column": 27, + "program": "labeledSwitchStatement.ets" + } + } + }, "loc": { "start": { "line": 48, - "column": 26, + "column": 17, "program": "labeledSwitchStatement.ets" }, "end": { @@ -1759,57 +1864,57 @@ }, "end": { "line": 48, - "column": 27, + "column": 28, "program": "labeledSwitchStatement.ets" } } }, - "loc": { - "start": { - "line": 48, - "column": 17, - "program": "labeledSwitchStatement.ets" + { + "type": "BreakStatement", + "label": { + "type": "Identifier", + "name": "label1", + "decorators": [], + "loc": { + "start": { + "line": 49, + "column": 23, + "program": "labeledSwitchStatement.ets" + }, + "end": { + "line": 49, + "column": 29, + "program": "labeledSwitchStatement.ets" + } + } }, - "end": { - "line": 48, - "column": 28, - "program": "labeledSwitchStatement.ets" - } - } - }, - { - "type": "BreakStatement", - "label": { - "type": "Identifier", - "name": "label1", - "decorators": [], "loc": { "start": { "line": 49, - "column": 23, + "column": 17, "program": "labeledSwitchStatement.ets" }, "end": { "line": 49, - "column": 29, + "column": 30, "program": "labeledSwitchStatement.ets" } } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1, + "program": null }, - "loc": { - "start": { - "line": 49, - "column": 17, - "program": "labeledSwitchStatement.ets" - }, - "end": { - "line": 49, - "column": 30, - "program": "labeledSwitchStatement.ets" - } + "end": { + "line": 1, + "column": 1, + "program": null } } - ], + }, "loc": { "start": { "line": 47, @@ -1826,36 +1931,51 @@ { "type": "SwitchCase", "test": null, - "consequent": [ - { - "type": "ExpressionStatement", - "expression": { - "type": "AssignmentExpression", - "operator": "=", - "left": { - "type": "Identifier", - "name": "result", - "decorators": [], - "loc": { - "start": { - "line": 51, - "column": 17, - "program": "labeledSwitchStatement.ets" - }, - "end": { - "line": 51, - "column": 23, - "program": "labeledSwitchStatement.ets" + "body": { + "type": "BlockStatement", + "statements": [ + { + "type": "ExpressionStatement", + "expression": { + "type": "AssignmentExpression", + "operator": "=", + "left": { + "type": "Identifier", + "name": "result", + "decorators": [], + "loc": { + "start": { + "line": 51, + "column": 17, + "program": "labeledSwitchStatement.ets" + }, + "end": { + "line": 51, + "column": 23, + "program": "labeledSwitchStatement.ets" + } } - } - }, - "right": { - "type": "NumberLiteral", - "value": 3400, + }, + "right": { + "type": "NumberLiteral", + "value": 3400, + "loc": { + "start": { + "line": 51, + "column": 26, + "program": "labeledSwitchStatement.ets" + }, + "end": { + "line": 51, + "column": 30, + "program": "labeledSwitchStatement.ets" + } + } + }, "loc": { "start": { "line": 51, - "column": 26, + "column": 17, "program": "labeledSwitchStatement.ets" }, "end": { @@ -1873,25 +1993,25 @@ }, "end": { "line": 51, - "column": 30, + "column": 31, "program": "labeledSwitchStatement.ets" } } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1, + "program": null }, - "loc": { - "start": { - "line": 51, - "column": 17, - "program": "labeledSwitchStatement.ets" - }, - "end": { - "line": 51, - "column": 31, - "program": "labeledSwitchStatement.ets" - } + "end": { + "line": 1, + "column": 1, + "program": null } } - ], + }, "loc": { "start": { "line": 50, diff --git a/ets2panda/test/parser/ets/localTypeAlias-expected.txt b/ets2panda/test/parser/ets/localTypeAlias-expected.txt index 17a49eaa60..4882da1160 100644 --- a/ets2panda/test/parser/ets/localTypeAlias-expected.txt +++ b/ets2panda/test/parser/ets/localTypeAlias-expected.txt @@ -729,34 +729,49 @@ } } }, - "consequent": [ - { - "type": "TSTypeAliasDeclaration", - "id": { - "type": "Identifier", - "name": "dsa", - "decorators": [], - "loc": { - "start": { - "line": 30, - "column": 18, - "program": "localTypeAlias.ets" - }, - "end": { - "line": 30, - "column": 21, - "program": "localTypeAlias.ets" + "body": { + "type": "BlockStatement", + "statements": [ + { + "type": "TSTypeAliasDeclaration", + "id": { + "type": "Identifier", + "name": "dsa", + "decorators": [], + "loc": { + "start": { + "line": 30, + "column": 18, + "program": "localTypeAlias.ets" + }, + "end": { + "line": 30, + "column": 21, + "program": "localTypeAlias.ets" + } } - } - }, - "typeAnnotation": { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "Double", - "decorators": [], + }, + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Double", + "decorators": [], + "loc": { + "start": { + "line": 30, + "column": 24, + "program": "localTypeAlias.ets" + }, + "end": { + "line": 30, + "column": 30, + "program": "localTypeAlias.ets" + } + } + }, "loc": { "start": { "line": 30, @@ -765,7 +780,7 @@ }, "end": { "line": 30, - "column": 30, + "column": 31, "program": "localTypeAlias.ets" } } @@ -786,7 +801,7 @@ "loc": { "start": { "line": 30, - "column": 24, + "column": 13, "program": "localTypeAlias.ets" }, "end": { @@ -796,50 +811,50 @@ } } }, - "loc": { - "start": { - "line": 30, - "column": 13, - "program": "localTypeAlias.ets" - }, - "end": { - "line": 30, - "column": 31, - "program": "localTypeAlias.ets" - } - } - }, - { - "type": "EmptyStatement", - "loc": { - "start": { - "line": 30, - "column": 30, - "program": "localTypeAlias.ets" - }, - "end": { - "line": 30, - "column": 31, - "program": "localTypeAlias.ets" + { + "type": "EmptyStatement", + "loc": { + "start": { + "line": 30, + "column": 30, + "program": "localTypeAlias.ets" + }, + "end": { + "line": 30, + "column": 31, + "program": "localTypeAlias.ets" + } } - } - }, - { - "type": "VariableDeclaration", - "declarations": [ - { - "type": "VariableDeclarator", - "id": { - "type": "Identifier", - "name": "dsa", - "typeAnnotation": { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "dsa", - "decorators": [], + }, + { + "type": "VariableDeclaration", + "declarations": [ + { + "type": "VariableDeclarator", + "id": { + "type": "Identifier", + "name": "dsa", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "dsa", + "decorators": [], + "loc": { + "start": { + "line": 31, + "column": 23, + "program": "localTypeAlias.ets" + }, + "end": { + "line": 31, + "column": 26, + "program": "localTypeAlias.ets" + } + } + }, "loc": { "start": { "line": 31, @@ -848,7 +863,7 @@ }, "end": { "line": 31, - "column": 26, + "column": 27, "program": "localTypeAlias.ets" } } @@ -866,20 +881,21 @@ } } }, + "decorators": [], "loc": { "start": { "line": 31, - "column": 23, + "column": 17, "program": "localTypeAlias.ets" }, "end": { "line": 31, - "column": 27, + "column": 20, "program": "localTypeAlias.ets" } } }, - "decorators": [], + "init": null, "loc": { "start": { "line": 31, @@ -892,53 +908,52 @@ "program": "localTypeAlias.ets" } } + } + ], + "kind": "let", + "loc": { + "start": { + "line": 31, + "column": 13, + "program": "localTypeAlias.ets" }, - "init": null, - "loc": { - "start": { - "line": 31, - "column": 17, - "program": "localTypeAlias.ets" - }, - "end": { - "line": 31, - "column": 20, - "program": "localTypeAlias.ets" - } + "end": { + "line": 31, + "column": 27, + "program": "localTypeAlias.ets" } } - ], - "kind": "let", - "loc": { - "start": { - "line": 31, - "column": 13, - "program": "localTypeAlias.ets" - }, - "end": { - "line": 31, - "column": 27, - "program": "localTypeAlias.ets" + }, + { + "type": "BreakStatement", + "label": null, + "loc": { + "start": { + "line": 32, + "column": 13, + "program": "localTypeAlias.ets" + }, + "end": { + "line": 33, + "column": 13, + "program": "localTypeAlias.ets" + } } } - }, - { - "type": "BreakStatement", - "label": null, - "loc": { - "start": { - "line": 32, - "column": 13, - "program": "localTypeAlias.ets" - }, - "end": { - "line": 33, - "column": 13, - "program": "localTypeAlias.ets" - } + ], + "loc": { + "start": { + "line": 1, + "column": 1, + "program": null + }, + "end": { + "line": 1, + "column": 1, + "program": null } } - ], + }, "loc": { "start": { "line": 29, @@ -970,23 +985,38 @@ } } }, - "consequent": [ - { - "type": "VariableDeclaration", - "declarations": [ - { - "type": "VariableDeclarator", - "id": { - "type": "Identifier", - "name": "asd", - "typeAnnotation": { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "asd", - "decorators": [], + "body": { + "type": "BlockStatement", + "statements": [ + { + "type": "VariableDeclaration", + "declarations": [ + { + "type": "VariableDeclarator", + "id": { + "type": "Identifier", + "name": "asd", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "asd", + "decorators": [], + "loc": { + "start": { + "line": 34, + "column": 22, + "program": "localTypeAlias.ets" + }, + "end": { + "line": 34, + "column": 25, + "program": "localTypeAlias.ets" + } + } + }, "loc": { "start": { "line": 34, @@ -995,7 +1025,7 @@ }, "end": { "line": 34, - "column": 25, + "column": 26, "program": "localTypeAlias.ets" } } @@ -1013,20 +1043,21 @@ } } }, + "decorators": [], "loc": { "start": { "line": 34, - "column": 22, + "column": 17, "program": "localTypeAlias.ets" }, "end": { "line": 34, - "column": 26, + "column": 20, "program": "localTypeAlias.ets" } } }, - "decorators": [], + "init": null, "loc": { "start": { "line": 34, @@ -1039,53 +1070,52 @@ "program": "localTypeAlias.ets" } } + } + ], + "kind": "let", + "loc": { + "start": { + "line": 34, + "column": 13, + "program": "localTypeAlias.ets" }, - "init": null, - "loc": { - "start": { - "line": 34, - "column": 17, - "program": "localTypeAlias.ets" - }, - "end": { - "line": 34, - "column": 20, - "program": "localTypeAlias.ets" - } + "end": { + "line": 34, + "column": 26, + "program": "localTypeAlias.ets" } } - ], - "kind": "let", - "loc": { - "start": { - "line": 34, - "column": 13, - "program": "localTypeAlias.ets" - }, - "end": { - "line": 34, - "column": 26, - "program": "localTypeAlias.ets" + }, + { + "type": "BreakStatement", + "label": null, + "loc": { + "start": { + "line": 35, + "column": 13, + "program": "localTypeAlias.ets" + }, + "end": { + "line": 36, + "column": 16, + "program": "localTypeAlias.ets" + } } } - }, - { - "type": "BreakStatement", - "label": null, - "loc": { - "start": { - "line": 35, - "column": 13, - "program": "localTypeAlias.ets" - }, - "end": { - "line": 36, - "column": 16, - "program": "localTypeAlias.ets" - } + ], + "loc": { + "start": { + "line": 1, + "column": 1, + "program": null + }, + "end": { + "line": 1, + "column": 1, + "program": null } } - ], + }, "loc": { "start": { "line": 33, @@ -1102,34 +1132,49 @@ { "type": "SwitchCase", "test": null, - "consequent": [ - { - "type": "TSTypeAliasDeclaration", - "id": { - "type": "Identifier", - "name": "asd", - "decorators": [], - "loc": { - "start": { - "line": 37, - "column": 18, - "program": "localTypeAlias.ets" - }, - "end": { - "line": 37, - "column": 21, - "program": "localTypeAlias.ets" + "body": { + "type": "BlockStatement", + "statements": [ + { + "type": "TSTypeAliasDeclaration", + "id": { + "type": "Identifier", + "name": "asd", + "decorators": [], + "loc": { + "start": { + "line": 37, + "column": 18, + "program": "localTypeAlias.ets" + }, + "end": { + "line": 37, + "column": 21, + "program": "localTypeAlias.ets" + } } - } - }, - "typeAnnotation": { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "number", - "decorators": [], + }, + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "number", + "decorators": [], + "loc": { + "start": { + "line": 37, + "column": 24, + "program": "localTypeAlias.ets" + }, + "end": { + "line": 37, + "column": 30, + "program": "localTypeAlias.ets" + } + } + }, "loc": { "start": { "line": 37, @@ -1138,7 +1183,7 @@ }, "end": { "line": 37, - "column": 30, + "column": 31, "program": "localTypeAlias.ets" } } @@ -1159,7 +1204,7 @@ "loc": { "start": { "line": 37, - "column": 24, + "column": 13, "program": "localTypeAlias.ets" }, "end": { @@ -1169,35 +1214,35 @@ } } }, - "loc": { - "start": { - "line": 37, - "column": 13, - "program": "localTypeAlias.ets" - }, - "end": { - "line": 37, - "column": 31, - "program": "localTypeAlias.ets" + { + "type": "EmptyStatement", + "loc": { + "start": { + "line": 37, + "column": 30, + "program": "localTypeAlias.ets" + }, + "end": { + "line": 37, + "column": 31, + "program": "localTypeAlias.ets" + } } } - }, - { - "type": "EmptyStatement", - "loc": { - "start": { - "line": 37, - "column": 30, - "program": "localTypeAlias.ets" - }, - "end": { - "line": 37, - "column": 31, - "program": "localTypeAlias.ets" - } + ], + "loc": { + "start": { + "line": 1, + "column": 1, + "program": null + }, + "end": { + "line": 1, + "column": 1, + "program": null } } - ], + }, "loc": { "start": { "line": 36, diff --git a/ets2panda/test/parser/ets/switch-expected.txt b/ets2panda/test/parser/ets/switch-expected.txt index 507a6441f8..8304e747b4 100644 --- a/ets2panda/test/parser/ets/switch-expected.txt +++ b/ets2panda/test/parser/ets/switch-expected.txt @@ -480,7 +480,22 @@ } } }, - "consequent": [], + "body": { + "type": "BlockStatement", + "statements": [], + "loc": { + "start": { + "line": 1, + "column": 1, + "program": null + }, + "end": { + "line": 1, + "column": 1, + "program": null + } + } + }, "loc": { "start": { "line": 21, @@ -512,36 +527,51 @@ } } }, - "consequent": [ - { - "type": "ExpressionStatement", - "expression": { - "type": "AssignmentExpression", - "operator": "=", - "left": { - "type": "Identifier", - "name": "result", - "decorators": [], - "loc": { - "start": { - "line": 23, - "column": 4, - "program": "switch.ets" - }, - "end": { - "line": 23, - "column": 10, - "program": "switch.ets" + "body": { + "type": "BlockStatement", + "statements": [ + { + "type": "ExpressionStatement", + "expression": { + "type": "AssignmentExpression", + "operator": "=", + "left": { + "type": "Identifier", + "name": "result", + "decorators": [], + "loc": { + "start": { + "line": 23, + "column": 4, + "program": "switch.ets" + }, + "end": { + "line": 23, + "column": 10, + "program": "switch.ets" + } } - } - }, - "right": { - "type": "StringLiteral", - "value": "One or zero", + }, + "right": { + "type": "StringLiteral", + "value": "One or zero", + "loc": { + "start": { + "line": 23, + "column": 13, + "program": "switch.ets" + }, + "end": { + "line": 23, + "column": 26, + "program": "switch.ets" + } + } + }, "loc": { "start": { "line": 23, - "column": 13, + "column": 4, "program": "switch.ets" }, "end": { @@ -559,41 +589,41 @@ }, "end": { "line": 23, - "column": 26, + "column": 27, "program": "switch.ets" } } }, - "loc": { - "start": { - "line": 23, - "column": 4, - "program": "switch.ets" - }, - "end": { - "line": 23, - "column": 27, - "program": "switch.ets" + { + "type": "BreakStatement", + "label": null, + "loc": { + "start": { + "line": 24, + "column": 4, + "program": "switch.ets" + }, + "end": { + "line": 24, + "column": 10, + "program": "switch.ets" + } } } - }, - { - "type": "BreakStatement", - "label": null, - "loc": { - "start": { - "line": 24, - "column": 4, - "program": "switch.ets" - }, - "end": { - "line": 24, - "column": 10, - "program": "switch.ets" - } + ], + "loc": { + "start": { + "line": 1, + "column": 1, + "program": null + }, + "end": { + "line": 1, + "column": 1, + "program": null } } - ], + }, "loc": { "start": { "line": 22, @@ -625,36 +655,51 @@ } } }, - "consequent": [ - { - "type": "ExpressionStatement", - "expression": { - "type": "AssignmentExpression", - "operator": "=", - "left": { - "type": "Identifier", - "name": "result", - "decorators": [], - "loc": { - "start": { - "line": 26, - "column": 4, - "program": "switch.ets" - }, - "end": { - "line": 26, - "column": 10, - "program": "switch.ets" + "body": { + "type": "BlockStatement", + "statements": [ + { + "type": "ExpressionStatement", + "expression": { + "type": "AssignmentExpression", + "operator": "=", + "left": { + "type": "Identifier", + "name": "result", + "decorators": [], + "loc": { + "start": { + "line": 26, + "column": 4, + "program": "switch.ets" + }, + "end": { + "line": 26, + "column": 10, + "program": "switch.ets" + } } - } - }, - "right": { - "type": "StringLiteral", - "value": "Two", + }, + "right": { + "type": "StringLiteral", + "value": "Two", + "loc": { + "start": { + "line": 26, + "column": 13, + "program": "switch.ets" + }, + "end": { + "line": 26, + "column": 18, + "program": "switch.ets" + } + } + }, "loc": { "start": { "line": 26, - "column": 13, + "column": 4, "program": "switch.ets" }, "end": { @@ -672,41 +717,41 @@ }, "end": { "line": 26, - "column": 18, + "column": 19, "program": "switch.ets" } } }, - "loc": { - "start": { - "line": 26, - "column": 4, - "program": "switch.ets" - }, - "end": { - "line": 26, - "column": 19, - "program": "switch.ets" + { + "type": "BreakStatement", + "label": null, + "loc": { + "start": { + "line": 27, + "column": 4, + "program": "switch.ets" + }, + "end": { + "line": 27, + "column": 10, + "program": "switch.ets" + } } } - }, - { - "type": "BreakStatement", - "label": null, - "loc": { - "start": { - "line": 27, - "column": 4, - "program": "switch.ets" - }, - "end": { - "line": 27, - "column": 10, - "program": "switch.ets" - } + ], + "loc": { + "start": { + "line": 1, + "column": 1, + "program": null + }, + "end": { + "line": 1, + "column": 1, + "program": null } } - ], + }, "loc": { "start": { "line": 25, @@ -723,36 +768,51 @@ { "type": "SwitchCase", "test": null, - "consequent": [ - { - "type": "ExpressionStatement", - "expression": { - "type": "AssignmentExpression", - "operator": "=", - "left": { - "type": "Identifier", - "name": "result", - "decorators": [], - "loc": { - "start": { - "line": 29, - "column": 4, - "program": "switch.ets" - }, - "end": { - "line": 29, - "column": 10, - "program": "switch.ets" + "body": { + "type": "BlockStatement", + "statements": [ + { + "type": "ExpressionStatement", + "expression": { + "type": "AssignmentExpression", + "operator": "=", + "left": { + "type": "Identifier", + "name": "result", + "decorators": [], + "loc": { + "start": { + "line": 29, + "column": 4, + "program": "switch.ets" + }, + "end": { + "line": 29, + "column": 10, + "program": "switch.ets" + } } - } - }, - "right": { - "type": "StringLiteral", - "value": "An unknown value", + }, + "right": { + "type": "StringLiteral", + "value": "An unknown value", + "loc": { + "start": { + "line": 29, + "column": 13, + "program": "switch.ets" + }, + "end": { + "line": 29, + "column": 31, + "program": "switch.ets" + } + } + }, "loc": { "start": { "line": 29, - "column": 13, + "column": 4, "program": "switch.ets" }, "end": { @@ -770,25 +830,25 @@ }, "end": { "line": 29, - "column": 31, + "column": 32, "program": "switch.ets" } } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1, + "program": null }, - "loc": { - "start": { - "line": 29, - "column": 4, - "program": "switch.ets" - }, - "end": { - "line": 29, - "column": 32, - "program": "switch.ets" - } + "end": { + "line": 1, + "column": 1, + "program": null } } - ], + }, "loc": { "start": { "line": 28, diff --git a/ets2panda/test/parser/ets/switch2-expected.txt b/ets2panda/test/parser/ets/switch2-expected.txt index b58d4bc7a1..348bbec27a 100644 --- a/ets2panda/test/parser/ets/switch2-expected.txt +++ b/ets2panda/test/parser/ets/switch2-expected.txt @@ -431,7 +431,22 @@ } } }, - "consequent": [], + "body": { + "type": "BlockStatement", + "statements": [], + "loc": { + "start": { + "line": 1, + "column": 1, + "program": null + }, + "end": { + "line": 1, + "column": 1, + "program": null + } + } + }, "loc": { "start": { "line": 21, @@ -463,36 +478,51 @@ } } }, - "consequent": [ - { - "type": "ExpressionStatement", - "expression": { - "type": "AssignmentExpression", - "operator": "=", - "left": { - "type": "Identifier", - "name": "result", - "decorators": [], - "loc": { - "start": { - "line": 23, - "column": 4, - "program": "switch2.ets" - }, - "end": { - "line": 23, - "column": 10, - "program": "switch2.ets" + "body": { + "type": "BlockStatement", + "statements": [ + { + "type": "ExpressionStatement", + "expression": { + "type": "AssignmentExpression", + "operator": "=", + "left": { + "type": "Identifier", + "name": "result", + "decorators": [], + "loc": { + "start": { + "line": 23, + "column": 4, + "program": "switch2.ets" + }, + "end": { + "line": 23, + "column": 10, + "program": "switch2.ets" + } } - } - }, - "right": { - "type": "NumberLiteral", - "value": 1, + }, + "right": { + "type": "NumberLiteral", + "value": 1, + "loc": { + "start": { + "line": 23, + "column": 13, + "program": "switch2.ets" + }, + "end": { + "line": 23, + "column": 14, + "program": "switch2.ets" + } + } + }, "loc": { "start": { "line": 23, - "column": 13, + "column": 4, "program": "switch2.ets" }, "end": { @@ -510,41 +540,41 @@ }, "end": { "line": 23, - "column": 14, + "column": 15, "program": "switch2.ets" } } }, - "loc": { - "start": { - "line": 23, - "column": 4, - "program": "switch2.ets" - }, - "end": { - "line": 23, - "column": 15, - "program": "switch2.ets" + { + "type": "BreakStatement", + "label": null, + "loc": { + "start": { + "line": 24, + "column": 4, + "program": "switch2.ets" + }, + "end": { + "line": 24, + "column": 10, + "program": "switch2.ets" + } } } - }, - { - "type": "BreakStatement", - "label": null, - "loc": { - "start": { - "line": 24, - "column": 4, - "program": "switch2.ets" - }, - "end": { - "line": 24, - "column": 10, - "program": "switch2.ets" - } + ], + "loc": { + "start": { + "line": 1, + "column": 1, + "program": null + }, + "end": { + "line": 1, + "column": 1, + "program": null } } - ], + }, "loc": { "start": { "line": 22, @@ -576,36 +606,51 @@ } } }, - "consequent": [ - { - "type": "ExpressionStatement", - "expression": { - "type": "AssignmentExpression", - "operator": "=", - "left": { - "type": "Identifier", - "name": "result", - "decorators": [], - "loc": { - "start": { - "line": 26, - "column": 4, - "program": "switch2.ets" - }, - "end": { - "line": 26, - "column": 10, - "program": "switch2.ets" + "body": { + "type": "BlockStatement", + "statements": [ + { + "type": "ExpressionStatement", + "expression": { + "type": "AssignmentExpression", + "operator": "=", + "left": { + "type": "Identifier", + "name": "result", + "decorators": [], + "loc": { + "start": { + "line": 26, + "column": 4, + "program": "switch2.ets" + }, + "end": { + "line": 26, + "column": 10, + "program": "switch2.ets" + } } - } - }, - "right": { - "type": "NumberLiteral", - "value": 2, + }, + "right": { + "type": "NumberLiteral", + "value": 2, + "loc": { + "start": { + "line": 26, + "column": 13, + "program": "switch2.ets" + }, + "end": { + "line": 26, + "column": 14, + "program": "switch2.ets" + } + } + }, "loc": { "start": { "line": 26, - "column": 13, + "column": 4, "program": "switch2.ets" }, "end": { @@ -623,41 +668,41 @@ }, "end": { "line": 26, - "column": 14, + "column": 15, "program": "switch2.ets" } } }, - "loc": { - "start": { - "line": 26, - "column": 4, - "program": "switch2.ets" - }, - "end": { - "line": 26, - "column": 15, - "program": "switch2.ets" + { + "type": "BreakStatement", + "label": null, + "loc": { + "start": { + "line": 27, + "column": 4, + "program": "switch2.ets" + }, + "end": { + "line": 27, + "column": 10, + "program": "switch2.ets" + } } } - }, - { - "type": "BreakStatement", - "label": null, - "loc": { - "start": { - "line": 27, - "column": 4, - "program": "switch2.ets" - }, - "end": { - "line": 27, - "column": 10, - "program": "switch2.ets" - } + ], + "loc": { + "start": { + "line": 1, + "column": 1, + "program": null + }, + "end": { + "line": 1, + "column": 1, + "program": null } } - ], + }, "loc": { "start": { "line": 25, @@ -674,36 +719,51 @@ { "type": "SwitchCase", "test": null, - "consequent": [ - { - "type": "ExpressionStatement", - "expression": { - "type": "AssignmentExpression", - "operator": "=", - "left": { - "type": "Identifier", - "name": "result", - "decorators": [], - "loc": { - "start": { - "line": 29, - "column": 4, - "program": "switch2.ets" - }, - "end": { - "line": 29, - "column": 10, - "program": "switch2.ets" + "body": { + "type": "BlockStatement", + "statements": [ + { + "type": "ExpressionStatement", + "expression": { + "type": "AssignmentExpression", + "operator": "=", + "left": { + "type": "Identifier", + "name": "result", + "decorators": [], + "loc": { + "start": { + "line": 29, + "column": 4, + "program": "switch2.ets" + }, + "end": { + "line": 29, + "column": 10, + "program": "switch2.ets" + } } - } - }, - "right": { - "type": "NumberLiteral", - "value": -1, + }, + "right": { + "type": "NumberLiteral", + "value": -1, + "loc": { + "start": { + "line": 29, + "column": 13, + "program": "switch2.ets" + }, + "end": { + "line": 29, + "column": 15, + "program": "switch2.ets" + } + } + }, "loc": { "start": { "line": 29, - "column": 13, + "column": 4, "program": "switch2.ets" }, "end": { @@ -721,25 +781,25 @@ }, "end": { "line": 29, - "column": 15, + "column": 16, "program": "switch2.ets" } } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1, + "program": null }, - "loc": { - "start": { - "line": 29, - "column": 4, - "program": "switch2.ets" - }, - "end": { - "line": 29, - "column": 16, - "program": "switch2.ets" - } + "end": { + "line": 1, + "column": 1, + "program": null } } - ], + }, "loc": { "start": { "line": 28, diff --git a/ets2panda/test/parser/ets/switch_alive_1-expected.txt b/ets2panda/test/parser/ets/switch_alive_1-expected.txt index f3b50bed3f..54e45a2b16 100644 --- a/ets2panda/test/parser/ets/switch_alive_1-expected.txt +++ b/ets2panda/test/parser/ets/switch_alive_1-expected.txt @@ -350,39 +350,54 @@ } } }, - "consequent": [ - { - "type": "ReturnStatement", - "argument": { - "type": "NumberLiteral", - "value": 1, + "body": { + "type": "BlockStatement", + "statements": [ + { + "type": "ReturnStatement", + "argument": { + "type": "NumberLiteral", + "value": 1, + "loc": { + "start": { + "line": 20, + "column": 11, + "program": "switch_alive_1.ets" + }, + "end": { + "line": 20, + "column": 12, + "program": "switch_alive_1.ets" + } + } + }, "loc": { "start": { "line": 20, - "column": 11, + "column": 4, "program": "switch_alive_1.ets" }, "end": { "line": 20, - "column": 12, + "column": 13, "program": "switch_alive_1.ets" } } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1, + "program": null }, - "loc": { - "start": { - "line": 20, - "column": 4, - "program": "switch_alive_1.ets" - }, - "end": { - "line": 20, - "column": 13, - "program": "switch_alive_1.ets" - } + "end": { + "line": 1, + "column": 1, + "program": null } } - ], + }, "loc": { "start": { "line": 19, @@ -414,39 +429,54 @@ } } }, - "consequent": [ - { - "type": "ReturnStatement", - "argument": { - "type": "NumberLiteral", - "value": 2, + "body": { + "type": "BlockStatement", + "statements": [ + { + "type": "ReturnStatement", + "argument": { + "type": "NumberLiteral", + "value": 2, + "loc": { + "start": { + "line": 22, + "column": 11, + "program": "switch_alive_1.ets" + }, + "end": { + "line": 22, + "column": 12, + "program": "switch_alive_1.ets" + } + } + }, "loc": { "start": { "line": 22, - "column": 11, + "column": 4, "program": "switch_alive_1.ets" }, "end": { "line": 22, - "column": 12, + "column": 13, "program": "switch_alive_1.ets" } } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1, + "program": null }, - "loc": { - "start": { - "line": 22, - "column": 4, - "program": "switch_alive_1.ets" - }, - "end": { - "line": 22, - "column": 13, - "program": "switch_alive_1.ets" - } + "end": { + "line": 1, + "column": 1, + "program": null } } - ], + }, "loc": { "start": { "line": 21, @@ -463,39 +493,54 @@ { "type": "SwitchCase", "test": null, - "consequent": [ - { - "type": "ReturnStatement", - "argument": { - "type": "NumberLiteral", - "value": 255, + "body": { + "type": "BlockStatement", + "statements": [ + { + "type": "ReturnStatement", + "argument": { + "type": "NumberLiteral", + "value": 255, + "loc": { + "start": { + "line": 24, + "column": 11, + "program": "switch_alive_1.ets" + }, + "end": { + "line": 24, + "column": 14, + "program": "switch_alive_1.ets" + } + } + }, "loc": { "start": { "line": 24, - "column": 11, + "column": 4, "program": "switch_alive_1.ets" }, "end": { "line": 24, - "column": 14, + "column": 15, "program": "switch_alive_1.ets" } } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1, + "program": null }, - "loc": { - "start": { - "line": 24, - "column": 4, - "program": "switch_alive_1.ets" - }, - "end": { - "line": 24, - "column": 15, - "program": "switch_alive_1.ets" - } + "end": { + "line": 1, + "column": 1, + "program": null } } - ], + }, "loc": { "start": { "line": 23, diff --git a/ets2panda/test/parser/ets/switch_alive_4-expected.txt b/ets2panda/test/parser/ets/switch_alive_4-expected.txt index 41471abb22..75c2c9a93c 100644 --- a/ets2panda/test/parser/ets/switch_alive_4-expected.txt +++ b/ets2panda/test/parser/ets/switch_alive_4-expected.txt @@ -423,24 +423,39 @@ } } }, - "consequent": [ - { - "type": "BreakStatement", - "label": null, - "loc": { - "start": { - "line": 19, - "column": 4, - "program": "switch_alive_4.ets" - }, - "end": { - "line": 20, - "column": 7, - "program": "switch_alive_4.ets" + "body": { + "type": "BlockStatement", + "statements": [ + { + "type": "BreakStatement", + "label": null, + "loc": { + "start": { + "line": 19, + "column": 4, + "program": "switch_alive_4.ets" + }, + "end": { + "line": 20, + "column": 7, + "program": "switch_alive_4.ets" + } } } + ], + "loc": { + "start": { + "line": 1, + "column": 1, + "program": null + }, + "end": { + "line": 1, + "column": 1, + "program": null + } } - ], + }, "loc": { "start": { "line": 18, @@ -472,24 +487,39 @@ } } }, - "consequent": [ - { - "type": "BreakStatement", - "label": null, - "loc": { - "start": { - "line": 21, - "column": 4, - "program": "switch_alive_4.ets" - }, - "end": { - "line": 22, - "column": 3, - "program": "switch_alive_4.ets" + "body": { + "type": "BlockStatement", + "statements": [ + { + "type": "BreakStatement", + "label": null, + "loc": { + "start": { + "line": 21, + "column": 4, + "program": "switch_alive_4.ets" + }, + "end": { + "line": 22, + "column": 3, + "program": "switch_alive_4.ets" + } } } + ], + "loc": { + "start": { + "line": 1, + "column": 1, + "program": null + }, + "end": { + "line": 1, + "column": 1, + "program": null + } } - ], + }, "loc": { "start": { "line": 20, diff --git a/ets2panda/test/parser/ets/switch_char_compare_num-expected.txt b/ets2panda/test/parser/ets/switch_char_compare_num-expected.txt index 8d5e872d0c..b2bb055145 100644 --- a/ets2panda/test/parser/ets/switch_char_compare_num-expected.txt +++ b/ets2panda/test/parser/ets/switch_char_compare_num-expected.txt @@ -320,24 +320,39 @@ } } }, - "consequent": [ - { - "type": "BreakStatement", - "label": null, - "loc": { - "start": { - "line": 20, - "column": 13, - "program": "switch_char_compare_num.ets" - }, - "end": { - "line": 20, - "column": 19, - "program": "switch_char_compare_num.ets" + "body": { + "type": "BlockStatement", + "statements": [ + { + "type": "BreakStatement", + "label": null, + "loc": { + "start": { + "line": 20, + "column": 13, + "program": "switch_char_compare_num.ets" + }, + "end": { + "line": 20, + "column": 19, + "program": "switch_char_compare_num.ets" + } } } + ], + "loc": { + "start": { + "line": 1, + "column": 1, + "program": null + }, + "end": { + "line": 1, + "column": 1, + "program": null + } } - ], + }, "loc": { "start": { "line": 19, @@ -369,24 +384,39 @@ } } }, - "consequent": [ - { - "type": "BreakStatement", - "label": null, - "loc": { - "start": { - "line": 22, - "column": 13, - "program": "switch_char_compare_num.ets" - }, - "end": { - "line": 22, - "column": 19, - "program": "switch_char_compare_num.ets" + "body": { + "type": "BlockStatement", + "statements": [ + { + "type": "BreakStatement", + "label": null, + "loc": { + "start": { + "line": 22, + "column": 13, + "program": "switch_char_compare_num.ets" + }, + "end": { + "line": 22, + "column": 19, + "program": "switch_char_compare_num.ets" + } } } + ], + "loc": { + "start": { + "line": 1, + "column": 1, + "program": null + }, + "end": { + "line": 1, + "column": 1, + "program": null + } } - ], + }, "loc": { "start": { "line": 21, diff --git a/ets2panda/test/parser/ets/switch_enum_string_case-expected.txt b/ets2panda/test/parser/ets/switch_enum_string_case-expected.txt index 6c09ac3917..e5d3c76367 100644 --- a/ets2panda/test/parser/ets/switch_enum_string_case-expected.txt +++ b/ets2panda/test/parser/ets/switch_enum_string_case-expected.txt @@ -5218,15 +5218,49 @@ } } }, - "consequent": [ - { - "type": "ExpressionStatement", - "expression": { - "type": "CallExpression", - "callee": { - "type": "Identifier", - "name": "assertTrue", - "decorators": [], + "body": { + "type": "BlockStatement", + "statements": [ + { + "type": "ExpressionStatement", + "expression": { + "type": "CallExpression", + "callee": { + "type": "Identifier", + "name": "assertTrue", + "decorators": [], + "loc": { + "start": { + "line": 25, + "column": 19, + "program": "switch_enum_string_case.ets" + }, + "end": { + "line": 25, + "column": 29, + "program": "switch_enum_string_case.ets" + } + } + }, + "arguments": [ + { + "type": "BooleanLiteral", + "value": false, + "loc": { + "start": { + "line": 25, + "column": 30, + "program": "switch_enum_string_case.ets" + }, + "end": { + "line": 25, + "column": 35, + "program": "switch_enum_string_case.ets" + } + } + } + ], + "optional": false, "loc": { "start": { "line": 25, @@ -5235,30 +5269,11 @@ }, "end": { "line": 25, - "column": 29, + "column": 36, "program": "switch_enum_string_case.ets" } } }, - "arguments": [ - { - "type": "BooleanLiteral", - "value": false, - "loc": { - "start": { - "line": 25, - "column": 30, - "program": "switch_enum_string_case.ets" - }, - "end": { - "line": 25, - "column": 35, - "program": "switch_enum_string_case.ets" - } - } - } - ], - "optional": false, "loc": { "start": { "line": 25, @@ -5267,41 +5282,41 @@ }, "end": { "line": 25, - "column": 36, + "column": 37, "program": "switch_enum_string_case.ets" } } }, - "loc": { - "start": { - "line": 25, - "column": 19, - "program": "switch_enum_string_case.ets" - }, - "end": { - "line": 25, - "column": 37, - "program": "switch_enum_string_case.ets" + { + "type": "BreakStatement", + "label": null, + "loc": { + "start": { + "line": 25, + "column": 38, + "program": "switch_enum_string_case.ets" + }, + "end": { + "line": 25, + "column": 44, + "program": "switch_enum_string_case.ets" + } } } - }, - { - "type": "BreakStatement", - "label": null, - "loc": { - "start": { - "line": 25, - "column": 38, - "program": "switch_enum_string_case.ets" - }, - "end": { - "line": 25, - "column": 44, - "program": "switch_enum_string_case.ets" - } + ], + "loc": { + "start": { + "line": 1, + "column": 1, + "program": null + }, + "end": { + "line": 1, + "column": 1, + "program": null } } - ], + }, "loc": { "start": { "line": 25, @@ -5368,15 +5383,49 @@ } } }, - "consequent": [ - { - "type": "ExpressionStatement", - "expression": { - "type": "CallExpression", - "callee": { - "type": "Identifier", - "name": "assertTrue", - "decorators": [], + "body": { + "type": "BlockStatement", + "statements": [ + { + "type": "ExpressionStatement", + "expression": { + "type": "CallExpression", + "callee": { + "type": "Identifier", + "name": "assertTrue", + "decorators": [], + "loc": { + "start": { + "line": 26, + "column": 19, + "program": "switch_enum_string_case.ets" + }, + "end": { + "line": 26, + "column": 29, + "program": "switch_enum_string_case.ets" + } + } + }, + "arguments": [ + { + "type": "BooleanLiteral", + "value": false, + "loc": { + "start": { + "line": 26, + "column": 30, + "program": "switch_enum_string_case.ets" + }, + "end": { + "line": 26, + "column": 35, + "program": "switch_enum_string_case.ets" + } + } + } + ], + "optional": false, "loc": { "start": { "line": 26, @@ -5385,30 +5434,11 @@ }, "end": { "line": 26, - "column": 29, + "column": 36, "program": "switch_enum_string_case.ets" } } }, - "arguments": [ - { - "type": "BooleanLiteral", - "value": false, - "loc": { - "start": { - "line": 26, - "column": 30, - "program": "switch_enum_string_case.ets" - }, - "end": { - "line": 26, - "column": 35, - "program": "switch_enum_string_case.ets" - } - } - } - ], - "optional": false, "loc": { "start": { "line": 26, @@ -5417,41 +5447,41 @@ }, "end": { "line": 26, - "column": 36, + "column": 37, "program": "switch_enum_string_case.ets" } } }, - "loc": { - "start": { - "line": 26, - "column": 19, - "program": "switch_enum_string_case.ets" - }, - "end": { - "line": 26, - "column": 37, - "program": "switch_enum_string_case.ets" + { + "type": "BreakStatement", + "label": null, + "loc": { + "start": { + "line": 26, + "column": 38, + "program": "switch_enum_string_case.ets" + }, + "end": { + "line": 26, + "column": 44, + "program": "switch_enum_string_case.ets" + } } } - }, - { - "type": "BreakStatement", - "label": null, - "loc": { - "start": { - "line": 26, - "column": 38, - "program": "switch_enum_string_case.ets" - }, - "end": { - "line": 26, - "column": 44, - "program": "switch_enum_string_case.ets" - } + ], + "loc": { + "start": { + "line": 1, + "column": 1, + "program": null + }, + "end": { + "line": 1, + "column": 1, + "program": null } } - ], + }, "loc": { "start": { "line": 26, @@ -5518,24 +5548,39 @@ } } }, - "consequent": [ - { - "type": "BreakStatement", - "label": null, - "loc": { - "start": { - "line": 27, - "column": 20, - "program": "switch_enum_string_case.ets" - }, - "end": { - "line": 27, - "column": 26, - "program": "switch_enum_string_case.ets" + "body": { + "type": "BlockStatement", + "statements": [ + { + "type": "BreakStatement", + "label": null, + "loc": { + "start": { + "line": 27, + "column": 20, + "program": "switch_enum_string_case.ets" + }, + "end": { + "line": 27, + "column": 26, + "program": "switch_enum_string_case.ets" + } } } + ], + "loc": { + "start": { + "line": 1, + "column": 1, + "program": null + }, + "end": { + "line": 1, + "column": 1, + "program": null + } } - ], + }, "loc": { "start": { "line": 27, diff --git a/ets2panda/test/parser/ets/switch_num_compare_char-expected.txt b/ets2panda/test/parser/ets/switch_num_compare_char-expected.txt index 405f139eb6..de75ec0d00 100644 --- a/ets2panda/test/parser/ets/switch_num_compare_char-expected.txt +++ b/ets2panda/test/parser/ets/switch_num_compare_char-expected.txt @@ -320,24 +320,39 @@ } } }, - "consequent": [ - { - "type": "BreakStatement", - "label": null, - "loc": { - "start": { - "line": 20, - "column": 13, - "program": "switch_num_compare_char.ets" - }, - "end": { - "line": 20, - "column": 19, - "program": "switch_num_compare_char.ets" + "body": { + "type": "BlockStatement", + "statements": [ + { + "type": "BreakStatement", + "label": null, + "loc": { + "start": { + "line": 20, + "column": 13, + "program": "switch_num_compare_char.ets" + }, + "end": { + "line": 20, + "column": 19, + "program": "switch_num_compare_char.ets" + } } } + ], + "loc": { + "start": { + "line": 1, + "column": 1, + "program": null + }, + "end": { + "line": 1, + "column": 1, + "program": null + } } - ], + }, "loc": { "start": { "line": 19, @@ -369,24 +384,39 @@ } } }, - "consequent": [ - { - "type": "BreakStatement", - "label": null, - "loc": { - "start": { - "line": 22, - "column": 13, - "program": "switch_num_compare_char.ets" - }, - "end": { - "line": 22, - "column": 19, - "program": "switch_num_compare_char.ets" + "body": { + "type": "BlockStatement", + "statements": [ + { + "type": "BreakStatement", + "label": null, + "loc": { + "start": { + "line": 22, + "column": 13, + "program": "switch_num_compare_char.ets" + }, + "end": { + "line": 22, + "column": 19, + "program": "switch_num_compare_char.ets" + } } } + ], + "loc": { + "start": { + "line": 1, + "column": 1, + "program": null + }, + "end": { + "line": 1, + "column": 1, + "program": null + } } - ], + }, "loc": { "start": { "line": 21, diff --git a/ets2panda/test/parser/ets/switch_readonly_member-expected.txt b/ets2panda/test/parser/ets/switch_readonly_member-expected.txt index 6172839605..f07441efbb 100644 --- a/ets2panda/test/parser/ets/switch_readonly_member-expected.txt +++ b/ets2panda/test/parser/ets/switch_readonly_member-expected.txt @@ -777,24 +777,39 @@ } } }, - "consequent": [ - { - "type": "BreakStatement", - "label": null, - "loc": { - "start": { - "line": 28, - "column": 10, - "program": "switch_readonly_member.ets" - }, - "end": { - "line": 28, - "column": 16, - "program": "switch_readonly_member.ets" + "body": { + "type": "BlockStatement", + "statements": [ + { + "type": "BreakStatement", + "label": null, + "loc": { + "start": { + "line": 28, + "column": 10, + "program": "switch_readonly_member.ets" + }, + "end": { + "line": 28, + "column": 16, + "program": "switch_readonly_member.ets" + } } } + ], + "loc": { + "start": { + "line": 1, + "column": 1, + "program": null + }, + "end": { + "line": 1, + "column": 1, + "program": null + } } - ], + }, "loc": { "start": { "line": 27, @@ -861,24 +876,39 @@ } } }, - "consequent": [ - { - "type": "BreakStatement", - "label": null, - "loc": { - "start": { - "line": 30, - "column": 9, - "program": "switch_readonly_member.ets" - }, - "end": { - "line": 30, - "column": 15, - "program": "switch_readonly_member.ets" + "body": { + "type": "BlockStatement", + "statements": [ + { + "type": "BreakStatement", + "label": null, + "loc": { + "start": { + "line": 30, + "column": 9, + "program": "switch_readonly_member.ets" + }, + "end": { + "line": 30, + "column": 15, + "program": "switch_readonly_member.ets" + } } } + ], + "loc": { + "start": { + "line": 1, + "column": 1, + "program": null + }, + "end": { + "line": 1, + "column": 1, + "program": null + } } - ], + }, "loc": { "start": { "line": 29, @@ -895,24 +925,39 @@ { "type": "SwitchCase", "test": null, - "consequent": [ - { - "type": "BreakStatement", - "label": null, - "loc": { - "start": { - "line": 31, - "column": 18, - "program": "switch_readonly_member.ets" - }, - "end": { - "line": 31, - "column": 24, - "program": "switch_readonly_member.ets" + "body": { + "type": "BlockStatement", + "statements": [ + { + "type": "BreakStatement", + "label": null, + "loc": { + "start": { + "line": 31, + "column": 18, + "program": "switch_readonly_member.ets" + }, + "end": { + "line": 31, + "column": 24, + "program": "switch_readonly_member.ets" + } } } + ], + "loc": { + "start": { + "line": 1, + "column": 1, + "program": null + }, + "end": { + "line": 1, + "column": 1, + "program": null + } } - ], + }, "loc": { "start": { "line": 31, diff --git a/ets2panda/test/parser/ets/switch_readonly_member_compare_char-expected.txt b/ets2panda/test/parser/ets/switch_readonly_member_compare_char-expected.txt index 21a80a6b99..2a017d2c42 100644 --- a/ets2panda/test/parser/ets/switch_readonly_member_compare_char-expected.txt +++ b/ets2panda/test/parser/ets/switch_readonly_member_compare_char-expected.txt @@ -777,24 +777,39 @@ } } }, - "consequent": [ - { - "type": "BreakStatement", - "label": null, - "loc": { - "start": { - "line": 28, - "column": 13, - "program": "switch_readonly_member_compare_char.ets" - }, - "end": { - "line": 28, - "column": 19, - "program": "switch_readonly_member_compare_char.ets" + "body": { + "type": "BlockStatement", + "statements": [ + { + "type": "BreakStatement", + "label": null, + "loc": { + "start": { + "line": 28, + "column": 13, + "program": "switch_readonly_member_compare_char.ets" + }, + "end": { + "line": 28, + "column": 19, + "program": "switch_readonly_member_compare_char.ets" + } } } + ], + "loc": { + "start": { + "line": 1, + "column": 1, + "program": null + }, + "end": { + "line": 1, + "column": 1, + "program": null + } } - ], + }, "loc": { "start": { "line": 27, @@ -861,24 +876,39 @@ } } }, - "consequent": [ - { - "type": "BreakStatement", - "label": null, - "loc": { - "start": { - "line": 30, - "column": 13, - "program": "switch_readonly_member_compare_char.ets" - }, - "end": { - "line": 30, - "column": 19, - "program": "switch_readonly_member_compare_char.ets" + "body": { + "type": "BlockStatement", + "statements": [ + { + "type": "BreakStatement", + "label": null, + "loc": { + "start": { + "line": 30, + "column": 13, + "program": "switch_readonly_member_compare_char.ets" + }, + "end": { + "line": 30, + "column": 19, + "program": "switch_readonly_member_compare_char.ets" + } } } + ], + "loc": { + "start": { + "line": 1, + "column": 1, + "program": null + }, + "end": { + "line": 1, + "column": 1, + "program": null + } } - ], + }, "loc": { "start": { "line": 29, @@ -910,24 +940,39 @@ } } }, - "consequent": [ - { - "type": "BreakStatement", - "label": null, - "loc": { - "start": { - "line": 32, - "column": 13, - "program": "switch_readonly_member_compare_char.ets" - }, - "end": { - "line": 32, - "column": 19, - "program": "switch_readonly_member_compare_char.ets" + "body": { + "type": "BlockStatement", + "statements": [ + { + "type": "BreakStatement", + "label": null, + "loc": { + "start": { + "line": 32, + "column": 13, + "program": "switch_readonly_member_compare_char.ets" + }, + "end": { + "line": 32, + "column": 19, + "program": "switch_readonly_member_compare_char.ets" + } } } + ], + "loc": { + "start": { + "line": 1, + "column": 1, + "program": null + }, + "end": { + "line": 1, + "column": 1, + "program": null + } } - ], + }, "loc": { "start": { "line": 31, @@ -944,24 +989,39 @@ { "type": "SwitchCase", "test": null, - "consequent": [ - { - "type": "BreakStatement", - "label": null, - "loc": { - "start": { - "line": 33, - "column": 18, - "program": "switch_readonly_member_compare_char.ets" - }, - "end": { - "line": 33, - "column": 24, - "program": "switch_readonly_member_compare_char.ets" + "body": { + "type": "BlockStatement", + "statements": [ + { + "type": "BreakStatement", + "label": null, + "loc": { + "start": { + "line": 33, + "column": 18, + "program": "switch_readonly_member_compare_char.ets" + }, + "end": { + "line": 33, + "column": 24, + "program": "switch_readonly_member_compare_char.ets" + } } } + ], + "loc": { + "start": { + "line": 1, + "column": 1, + "program": null + }, + "end": { + "line": 1, + "column": 1, + "program": null + } } - ], + }, "loc": { "start": { "line": 33, diff --git a/ets2panda/test/parser/ets/switch_readonly_member_compare_char_2-expected.txt b/ets2panda/test/parser/ets/switch_readonly_member_compare_char_2-expected.txt index 697100275d..c657b44c4c 100644 --- a/ets2panda/test/parser/ets/switch_readonly_member_compare_char_2-expected.txt +++ b/ets2panda/test/parser/ets/switch_readonly_member_compare_char_2-expected.txt @@ -742,24 +742,39 @@ } } }, - "consequent": [ - { - "type": "BreakStatement", - "label": null, - "loc": { - "start": { - "line": 28, - "column": 13, - "program": "switch_readonly_member_compare_char_2.ets" - }, - "end": { - "line": 28, - "column": 19, - "program": "switch_readonly_member_compare_char_2.ets" + "body": { + "type": "BlockStatement", + "statements": [ + { + "type": "BreakStatement", + "label": null, + "loc": { + "start": { + "line": 28, + "column": 13, + "program": "switch_readonly_member_compare_char_2.ets" + }, + "end": { + "line": 28, + "column": 19, + "program": "switch_readonly_member_compare_char_2.ets" + } } } + ], + "loc": { + "start": { + "line": 1, + "column": 1, + "program": null + }, + "end": { + "line": 1, + "column": 1, + "program": null + } } - ], + }, "loc": { "start": { "line": 27, @@ -826,24 +841,39 @@ } } }, - "consequent": [ - { - "type": "BreakStatement", - "label": null, - "loc": { - "start": { - "line": 30, - "column": 13, - "program": "switch_readonly_member_compare_char_2.ets" - }, - "end": { - "line": 30, - "column": 19, - "program": "switch_readonly_member_compare_char_2.ets" + "body": { + "type": "BlockStatement", + "statements": [ + { + "type": "BreakStatement", + "label": null, + "loc": { + "start": { + "line": 30, + "column": 13, + "program": "switch_readonly_member_compare_char_2.ets" + }, + "end": { + "line": 30, + "column": 19, + "program": "switch_readonly_member_compare_char_2.ets" + } } } + ], + "loc": { + "start": { + "line": 1, + "column": 1, + "program": null + }, + "end": { + "line": 1, + "column": 1, + "program": null + } } - ], + }, "loc": { "start": { "line": 29, @@ -910,24 +940,39 @@ } } }, - "consequent": [ - { - "type": "BreakStatement", - "label": null, - "loc": { - "start": { - "line": 32, - "column": 13, - "program": "switch_readonly_member_compare_char_2.ets" - }, - "end": { - "line": 32, - "column": 19, - "program": "switch_readonly_member_compare_char_2.ets" + "body": { + "type": "BlockStatement", + "statements": [ + { + "type": "BreakStatement", + "label": null, + "loc": { + "start": { + "line": 32, + "column": 13, + "program": "switch_readonly_member_compare_char_2.ets" + }, + "end": { + "line": 32, + "column": 19, + "program": "switch_readonly_member_compare_char_2.ets" + } } } + ], + "loc": { + "start": { + "line": 1, + "column": 1, + "program": null + }, + "end": { + "line": 1, + "column": 1, + "program": null + } } - ], + }, "loc": { "start": { "line": 31, @@ -944,24 +989,39 @@ { "type": "SwitchCase", "test": null, - "consequent": [ - { - "type": "BreakStatement", - "label": null, - "loc": { - "start": { - "line": 33, - "column": 18, - "program": "switch_readonly_member_compare_char_2.ets" - }, - "end": { - "line": 33, - "column": 24, - "program": "switch_readonly_member_compare_char_2.ets" + "body": { + "type": "BlockStatement", + "statements": [ + { + "type": "BreakStatement", + "label": null, + "loc": { + "start": { + "line": 33, + "column": 18, + "program": "switch_readonly_member_compare_char_2.ets" + }, + "end": { + "line": 33, + "column": 24, + "program": "switch_readonly_member_compare_char_2.ets" + } } } + ], + "loc": { + "start": { + "line": 1, + "column": 1, + "program": null + }, + "end": { + "line": 1, + "column": 1, + "program": null + } } - ], + }, "loc": { "start": { "line": 33, diff --git a/ets2panda/test/unit/public/ast_builder_test.cpp b/ets2panda/test/unit/public/ast_builder_test.cpp index 9ef6b96540..e0fdc95e78 100644 --- a/ets2panda/test/unit/public/ast_builder_test.cpp +++ b/ets2panda/test/unit/public/ast_builder_test.cpp @@ -334,9 +334,8 @@ TEST_F(ASTVerifierTest, switchStatementBuild) auto thisExpr = ThisExpressionBuilder(Allocator()).Build(); ark::ArenaVector cases(Allocator()->Adapter()); - ark::ArenaVector conseq(Allocator()->Adapter()); - conseq.push_back(consStmnt); - auto switchCase = SwitchCaseStatementBuilder(Allocator()).SetTest(binaryExpr).SetConsequent(conseq).Build(); + auto body = BlockStatementBuilder(Allocator()).AddStatement(consStmnt).Build(); + auto switchCase = SwitchCaseStatementBuilder(Allocator(), body).SetTest(binaryExpr).Build(); cases.push_back(switchCase); auto switchStmnt = SwitchStatementBuilder(Allocator()).SetCases(cases).SetDiscriminant(thisExpr).Build(); ASSERT_TRUE(switchStmnt->IsSwitchStatement()); diff --git a/ets2panda/util/ast-builders/switchCaseStatementBuilder.h b/ets2panda/util/ast-builders/switchCaseStatementBuilder.h index b378b05879..4cd30eb092 100644 --- a/ets2panda/util/ast-builders/switchCaseStatementBuilder.h +++ b/ets2panda/util/ast-builders/switchCaseStatementBuilder.h @@ -1,5 +1,5 @@ /** - * Copyright (c) 2024 Huawei Device Co., Ltd. + * Copyright (c) 2025 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -24,8 +24,8 @@ namespace ark::es2panda::ir { class SwitchCaseStatementBuilder : public AstBuilder { public: - explicit SwitchCaseStatementBuilder(ark::ArenaAllocator *allocator) - : AstBuilder(allocator), consequent_(allocator->Adapter()) + explicit SwitchCaseStatementBuilder(ark::ArenaAllocator *allocator, BlockStatement *body) + : AstBuilder(allocator), body_(body) { } @@ -35,21 +35,21 @@ public: return *this; } - SwitchCaseStatementBuilder &SetConsequent(ArenaVector consequent) + SwitchCaseStatementBuilder &SetBody(BlockStatement *body) { - consequent_ = std::move(consequent); + body_ = body; return *this; } SwitchCaseStatement *Build() { - auto node = AllocNode(test_, std::move(consequent_)); + auto node = AllocNode(test_, body_); return node; } private: Expression *test_ {}; - ark::ArenaVector consequent_; + BlockStatement *body_; }; } // namespace ark::es2panda::ir -- Gitee