From ba354ed969b12fd4e2ab38e9fd27108e9b4c8695 Mon Sep 17 00:00:00 2001 From: tengtengh Date: Mon, 26 May 2025 21:19:21 +0800 Subject: [PATCH] Fix top level init order Issue: https://gitee.com/openharmony/arkcompiler_ets_frontend/issues/IC5WYQ Signed-off-by: tengtengh --- ets2panda/compiler/core/ETSfunction.cpp | 11 +- .../ets/constantExpressionLowering.cpp | 3 +- .../topLevelStmts/globalDeclTransformer.cpp | 7 +- .../ir/statements/switchCaseStatement.cpp | 2 +- ets2panda/lsp/src/api.cpp | 2 + ets2panda/lsp/src/completions.cpp | 2 +- .../annotationUsage_as_type09.ets | 1 + ...ionUsage_duplicate_on_extension_lambda.ets | 3 +- .../compiler/ets/circular_variable_init.ets | 2 +- .../namespace_tests/namespace_as_type09.ets | 1 + .../annotationUsage_parser_bad_token04.ets | 1 + .../lambda_infer_type_scope-expected.txt | 12 +- .../ets/loopWithinLambda-expected.txt | 983 ++++++++++- .../compiler/ets/tuple_types_13-expected.txt | 133 +- .../FunctionalTypeAsTypeArgument-expected.txt | 246 ++- ets2panda/test/parser/ets/assign-expected.txt | 64 + .../test/parser/ets/boolean-expected.txt | 64 + ets2panda/test/parser/ets/const-expected.txt | 131 +- .../test/parser/ets/decl_infer-expected.txt | 320 ++++ .../test/parser/ets/exports-expected.txt | 64 + .../ets/global_const_vars3-expected.txt | 178 +- .../imported_module_1-expected.txt | 64 + .../imported_module_2-expected.txt | 64 + .../packages/package_module_1-expected.txt | 131 +- .../packages/package_module_2-expected.txt | 131 +- .../launch_with_call_expression-expected.txt | 12 +- .../test/parser/ets/literals-expected.txt | 1494 ++++++++++++++++- .../test/parser/ets/null_valid-expected.txt | 64 + .../ets/tupleIndexWithNumbers-expected.txt | 131 +- .../parser/ets/type_variance1-expected.txt | 242 ++- .../test/parser/ets/unary_op-expected.txt | 64 + .../ets/lambda_inner_call_static_method.ets | 2 +- .../ets/topLevelInitOrder/topLevelInit1.ets | 30 + .../ets/topLevelInitOrder/topLevelInit2.ets | 35 + .../topLevelInitOrder/topLevelInit_Lambda.ets | 23 + ets2panda/test/unit/lsp/get_diagnostics.cpp | 45 +- ets2panda/test/unit/lsp/inlay_hints_test.cpp | 12 +- .../test/unit/lsp/isolated_declaration.cpp | 2 +- ets2panda/util/diagnosticEngine.cpp | 9 + ets2panda/util/diagnosticEngine.h | 2 + 40 files changed, 4707 insertions(+), 80 deletions(-) mode change 100755 => 100644 ets2panda/test/parser/ets/import_tests/packages/package_module_1-expected.txt mode change 100755 => 100644 ets2panda/test/parser/ets/import_tests/packages/package_module_2-expected.txt create mode 100644 ets2panda/test/runtime/ets/topLevelInitOrder/topLevelInit1.ets create mode 100644 ets2panda/test/runtime/ets/topLevelInitOrder/topLevelInit2.ets create mode 100644 ets2panda/test/runtime/ets/topLevelInitOrder/topLevelInit_Lambda.ets diff --git a/ets2panda/compiler/core/ETSfunction.cpp b/ets2panda/compiler/core/ETSfunction.cpp index 4edd9d31b2..000f70b105 100644 --- a/ets2panda/compiler/core/ETSfunction.cpp +++ b/ets2panda/compiler/core/ETSfunction.cpp @@ -123,6 +123,9 @@ void ETSFunction::CompileAsStaticBlock(ETSGen *etsg) // Check if it is the Global class static constructor and the special '_$init$_" method exists bool const compileInitializer = classDef->IsGlobal() ? checkInitializer(classDef->Body()) : true; + if (!compileInitializer) { + return; + } for (const auto *prop : classDef->Body()) { if (!prop->IsClassProperty() || !prop->IsStatic()) { @@ -131,10 +134,12 @@ void ETSFunction::CompileAsStaticBlock(ETSGen *etsg) // Don't compile variable initializers if they present in '_$init$_" method auto *const item = prop->AsClassProperty(); - if (item->Value() != nullptr && - (compileInitializer || item->IsConst() || item->Value()->IsArrowFunctionExpression())) { - item->Compile(etsg); + + if (item->Value() == nullptr) { + continue; } + + item->Compile(etsg); } } diff --git a/ets2panda/compiler/lowering/ets/constantExpressionLowering.cpp b/ets2panda/compiler/lowering/ets/constantExpressionLowering.cpp index de86a2313a..cffbbc6adf 100644 --- a/ets2panda/compiler/lowering/ets/constantExpressionLowering.cpp +++ b/ets2panda/compiler/lowering/ets/constantExpressionLowering.cpp @@ -847,7 +847,8 @@ ir::AstNode *ConstantExpressionLowering::UnfoldConstIdentifier(ir::AstNode *node { ir::AstNode *resNode = nullptr; if (node->IsClassProperty()) { - auto prop = node->AsClassElement(); + auto prop = node->AsClassProperty(); + ES2PANDA_ASSERT(prop->Value() != nullptr); resNode = prop->Value()->Clone(context_->allocator, originNode->Parent()); resNode->SetRange(originNode->Range()); } diff --git a/ets2panda/compiler/lowering/ets/topLevelStmts/globalDeclTransformer.cpp b/ets2panda/compiler/lowering/ets/topLevelStmts/globalDeclTransformer.cpp index dc8869fffa..9bbde8cc56 100644 --- a/ets2panda/compiler/lowering/ets/topLevelStmts/globalDeclTransformer.cpp +++ b/ets2panda/compiler/lowering/ets/topLevelStmts/globalDeclTransformer.cpp @@ -14,6 +14,7 @@ */ #include "compiler/lowering/ets/topLevelStmts/globalDeclTransformer.h" +#include "compiler/lowering/util.h" namespace ark::es2panda::compiler { @@ -153,7 +154,7 @@ ir::Identifier *GlobalDeclTransformer::RefIdent(const util::StringView &name) ir::ExpressionStatement *GlobalDeclTransformer::InitTopLevelProperty(ir::ClassProperty *classProperty) { const auto initializer = classProperty->Value(); - if (classProperty->IsConst() || initializer == nullptr) { + if (initializer == nullptr) { classProperty->SetStart(classProperty->Id()->Start()); return nullptr; } @@ -172,11 +173,13 @@ ir::ExpressionStatement *GlobalDeclTransformer::InitTopLevelProperty(ir::ClassPr classProperty->SetRange({ident->Start(), initializer->End()}); - if (classProperty->TypeAnnotation() != nullptr) { + if (classProperty->TypeAnnotation() != nullptr && !classProperty->IsConst()) { classProperty->SetValue(nullptr); } else { // Code will be ignored, but checker is going to deduce the type. classProperty->SetValue(initializer->Clone(allocator_, classProperty)->AsExpression()); + RefineSourceRanges(classProperty->Value()); + assignmentExpression->SetIgnoreConstAssign(); } return expressionStatement; } diff --git a/ets2panda/ir/statements/switchCaseStatement.cpp b/ets2panda/ir/statements/switchCaseStatement.cpp index 1585c3b5bc..be0ff2741f 100644 --- a/ets2panda/ir/statements/switchCaseStatement.cpp +++ b/ets2panda/ir/statements/switchCaseStatement.cpp @@ -146,7 +146,7 @@ void SwitchCaseStatement::CheckAndTestCase(checker::ETSChecker *checker, checker SwitchCaseStatement *SwitchCaseStatement::Clone(ArenaAllocator *const allocator, AstNode *const parent) { - auto *const test = test_->Clone(allocator, nullptr)->AsExpression(); + auto *const test = test_ == nullptr ? nullptr : test_->Clone(allocator, nullptr)->AsExpression(); ArenaVector consequent(allocator->Adapter()); for (auto *statement : consequent_) { diff --git a/ets2panda/lsp/src/api.cpp b/ets2panda/lsp/src/api.cpp index 9c9b217952..7d92576743 100644 --- a/ets2panda/lsp/src/api.cpp +++ b/ets2panda/lsp/src/api.cpp @@ -174,6 +174,7 @@ DiagnosticReferences GetSemanticDiagnostics(es2panda_Context *context) { DiagnosticReferences result {}; auto ctx = reinterpret_cast(context); + ctx->diagnosticEngine->CleanDuplicateLog(util::DiagnosticType::SEMANTIC); const auto &diagnostics = ctx->diagnosticEngine->GetDiagnosticStorage(util::DiagnosticType::SEMANTIC); for (const auto &diagnostic : diagnostics) { result.diagnostic.push_back(CreateDiagnosticForError(context, *diagnostic)); @@ -185,6 +186,7 @@ DiagnosticReferences GetSyntacticDiagnostics(es2panda_Context *context) { DiagnosticReferences result {}; auto ctx = reinterpret_cast(context); + ctx->diagnosticEngine->CleanDuplicateLog(util::DiagnosticType::SYNTAX); const auto &diagnostics = ctx->diagnosticEngine->GetDiagnosticStorage(util::DiagnosticType::SYNTAX); for (const auto &diagnostic : diagnostics) { result.diagnostic.push_back(CreateDiagnosticForError(context, *diagnostic)); diff --git a/ets2panda/lsp/src/completions.cpp b/ets2panda/lsp/src/completions.cpp index fc0e486bf6..3aab5ee26f 100644 --- a/ets2panda/lsp/src/completions.cpp +++ b/ets2panda/lsp/src/completions.cpp @@ -704,7 +704,7 @@ CompletionEntry InitEntry(const ir::AstNode *decl) return child->IsAssignmentExpression() && child->AsAssignmentExpression()->Left()->IsIdentifier() && child->AsAssignmentExpression()->Left()->AsIdentifier()->ToString() == name; }); - if (found != nullptr) { + if (found != nullptr && !decl->AsClassProperty()->IsConst()) { // let variable in global definition need to be assigned in _$init$_ method kind = CompletionEntryKind::VARIABLE; } else { diff --git a/ets2panda/test/ast/compiler/ets/annotation_tests/annotationUsage_as_type09.ets b/ets2panda/test/ast/compiler/ets/annotation_tests/annotationUsage_as_type09.ets index 0aaa1cd95c..d4241e233d 100644 --- a/ets2panda/test/ast/compiler/ets/annotation_tests/annotationUsage_as_type09.ets +++ b/ets2panda/test/ast/compiler/ets/annotation_tests/annotationUsage_as_type09.ets @@ -18,4 +18,5 @@ let a = 1 as MyAnno +/* @@? 19:9 Error TypeError: Annotations cannot be used as a type. */ /* @@? 19:14 Error TypeError: Annotations cannot be used as a type. */ diff --git a/ets2panda/test/ast/compiler/ets/annotation_tests/annotationUsage_duplicate_on_extension_lambda.ets b/ets2panda/test/ast/compiler/ets/annotation_tests/annotationUsage_duplicate_on_extension_lambda.ets index 025b88d8e8..6c300bd306 100644 --- a/ets2panda/test/ast/compiler/ets/annotation_tests/annotationUsage_duplicate_on_extension_lambda.ets +++ b/ets2panda/test/ast/compiler/ets/annotation_tests/annotationUsage_duplicate_on_extension_lambda.ets @@ -18,7 +18,8 @@ class A { name = "Bob" } let a = new A(); -let show = @Anno()@/* @@ label */Anno(this: A): string => { +let show = @Anno()@/* @@ label */Anno/*@@ label2 */(this: A): string => { return "Hello," + this.name; } /* @@@ label Error TypeError: Duplicate annotations are not allowed. The annotation 'Anno' has already been applied to this element. */ +/* @@@ label2 Error TypeError: Duplicate annotations are not allowed. The annotation 'Anno' has already been applied to this element. */ diff --git a/ets2panda/test/ast/compiler/ets/circular_variable_init.ets b/ets2panda/test/ast/compiler/ets/circular_variable_init.ets index af59760eb5..fc6881da7f 100644 --- a/ets2panda/test/ast/compiler/ets/circular_variable_init.ets +++ b/ets2panda/test/ast/compiler/ets/circular_variable_init.ets @@ -47,7 +47,7 @@ function main() { /* @@? 23:19 Error TypeError: Circular dependency detected for identifier: b */ /* @@? 31:15 Error TypeError: Unresolved reference globalb */ /* @@? 33:5 Error TypeError: Circular dependency detected for identifier: globalc */ -/* @@? 37:7 Error TypeError: Circular dependency detected for identifier: constb */ +/* @@? 36:7 Error TypeError: Circular dependency detected for identifier: consta */ /* @@? 40:17 Error TypeError: Unresolved reference mainb */ /* @@? 42:17 Error TypeError: Variable 'maind' is accessed before it's initialization. */ /* @@? 43:9 Error TypeError: Circular dependency detected for identifier: maind */ diff --git a/ets2panda/test/ast/compiler/ets/namespace_tests/namespace_as_type09.ets b/ets2panda/test/ast/compiler/ets/namespace_tests/namespace_as_type09.ets index 34b0e476d3..5b1dfbb4d5 100644 --- a/ets2panda/test/ast/compiler/ets/namespace_tests/namespace_as_type09.ets +++ b/ets2panda/test/ast/compiler/ets/namespace_tests/namespace_as_type09.ets @@ -18,4 +18,5 @@ namespace MySpace { let a = 1 as MySpace +/* @@? 19:9 Error TypeError: Namespace 'MySpace' cannot be used as a type. */ /* @@? 19:14 Error TypeError: Namespace 'MySpace' cannot be used as a type. */ diff --git a/ets2panda/test/ast/parser/ets/annotations_tests/annotationUsage_parser_bad_token04.ets b/ets2panda/test/ast/parser/ets/annotations_tests/annotationUsage_parser_bad_token04.ets index 44730b44be..c3d7a882b0 100644 --- a/ets2panda/test/ast/parser/ets/annotations_tests/annotationUsage_parser_bad_token04.ets +++ b/ets2panda/test/ast/parser/ets/annotations_tests/annotationUsage_parser_bad_token04.ets @@ -20,5 +20,6 @@ const invalidUsage1 = @Log("value")) ()=>{} /* @@? 19:24 Error TypeError: Annotations without 'SOURCE' cannot be used on lambda expressions, local declarations, or types. */ /* @@? 19:36 Error SyntaxError: Unexpected token ')'. */ +/* @@? 19:36 Error TypeError: Annotations without 'SOURCE' cannot be used on lambda expressions, local declarations, or types. */ /* @@? 19:40 Error SyntaxError: Unexpected token '=>'. */ /* @@? 19:40 Error SyntaxError: Unexpected token. */ diff --git a/ets2panda/test/compiler/ets/lambda_infer_type/lambda_infer_type_scope-expected.txt b/ets2panda/test/compiler/ets/lambda_infer_type/lambda_infer_type_scope-expected.txt index cf65a444be..3622381651 100644 --- a/ets2panda/test/compiler/ets/lambda_infer_type/lambda_infer_type_scope-expected.txt +++ b/ets2panda/test/compiler/ets/lambda_infer_type/lambda_infer_type_scope-expected.txt @@ -624,14 +624,14 @@ }, "loc": { "start": { - "line": 1, - "column": 1, - "program": null + "line": 17, + "column": 9, + "program": "lambda_infer_type_scope.ets" }, "end": { - "line": 1, - "column": 1, - "program": null + "line": 17, + "column": 29, + "program": "lambda_infer_type_scope.ets" } } }, diff --git a/ets2panda/test/compiler/ets/loopWithinLambda-expected.txt b/ets2panda/test/compiler/ets/loopWithinLambda-expected.txt index 2dffdc1e5b..812505c756 100644 --- a/ets2panda/test/compiler/ets/loopWithinLambda-expected.txt +++ b/ets2panda/test/compiler/ets/loopWithinLambda-expected.txt @@ -519,7 +519,956 @@ "params": [], "body": { "type": "BlockStatement", - "statements": [], + "statements": [ + { + "type": "ExpressionStatement", + "expression": { + "type": "AssignmentExpression", + "operator": "=", + "left": { + "type": "Identifier", + "name": "F1", + "decorators": [], + "loc": { + "start": { + "line": 20, + "column": 7, + "program": "loopWithinLambda.ets" + }, + "end": { + "line": 20, + "column": 9, + "program": "loopWithinLambda.ets" + } + } + }, + "right": { + "type": "ArrowFunctionExpression", + "function": { + "type": "ScriptFunction", + "id": null, + "generator": false, + "async": false, + "expression": false, + "params": [ + { + "type": "ETSParameterExpression", + "name": { + "type": "Identifier", + "name": "counter", + "typeAnnotation": { + "type": "ETSPrimitiveType", + "loc": { + "start": { + "line": 20, + "column": 27, + "program": "loopWithinLambda.ets" + }, + "end": { + "line": 20, + "column": 30, + "program": "loopWithinLambda.ets" + } + } + }, + "decorators": [], + "loc": { + "start": { + "line": 20, + "column": 18, + "program": "loopWithinLambda.ets" + }, + "end": { + "line": 20, + "column": 30, + "program": "loopWithinLambda.ets" + } + } + }, + "loc": { + "start": { + "line": 20, + "column": 18, + "program": "loopWithinLambda.ets" + }, + "end": { + "line": 20, + "column": 30, + "program": "loopWithinLambda.ets" + } + } + } + ], + "body": { + "type": "BlockStatement", + "statements": [ + { + "type": "VariableDeclaration", + "declarations": [ + { + "type": "VariableDeclarator", + "id": { + "type": "Identifier", + "name": "funcWithLambda", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "T1", + "decorators": [], + "loc": { + "start": { + "line": 21, + "column": 25, + "program": "loopWithinLambda.ets" + }, + "end": { + "line": 21, + "column": 27, + "program": "loopWithinLambda.ets" + } + } + }, + "loc": { + "start": { + "line": 21, + "column": 25, + "program": "loopWithinLambda.ets" + }, + "end": { + "line": 21, + "column": 29, + "program": "loopWithinLambda.ets" + } + } + }, + "loc": { + "start": { + "line": 21, + "column": 25, + "program": "loopWithinLambda.ets" + }, + "end": { + "line": 21, + "column": 29, + "program": "loopWithinLambda.ets" + } + } + }, + "decorators": [], + "loc": { + "start": { + "line": 21, + "column": 9, + "program": "loopWithinLambda.ets" + }, + "end": { + "line": 21, + "column": 23, + "program": "loopWithinLambda.ets" + } + } + }, + "init": { + "type": "ArrowFunctionExpression", + "function": { + "type": "ScriptFunction", + "id": null, + "generator": false, + "async": false, + "expression": false, + "params": [ + { + "type": "ETSParameterExpression", + "name": { + "type": "Identifier", + "name": "lambda", + "typeAnnotation": { + "type": "ETSFunctionType", + "params": [ + { + "type": "ETSParameterExpression", + "name": { + "type": "Identifier", + "name": "arg", + "typeAnnotation": { + "type": "ETSPrimitiveType", + "loc": { + "start": { + "line": 21, + "column": 45, + "program": "loopWithinLambda.ets" + }, + "end": { + "line": 21, + "column": 48, + "program": "loopWithinLambda.ets" + } + } + }, + "decorators": [], + "loc": { + "start": { + "line": 21, + "column": 40, + "program": "loopWithinLambda.ets" + }, + "end": { + "line": 21, + "column": 48, + "program": "loopWithinLambda.ets" + } + } + }, + "loc": { + "start": { + "line": 21, + "column": 40, + "program": "loopWithinLambda.ets" + }, + "end": { + "line": 21, + "column": 48, + "program": "loopWithinLambda.ets" + } + } + } + ], + "returnType": { + "type": "ETSPrimitiveType", + "loc": { + "start": { + "line": 21, + "column": 53, + "program": "loopWithinLambda.ets" + }, + "end": { + "line": 21, + "column": 56, + "program": "loopWithinLambda.ets" + } + } + }, + "loc": { + "start": { + "line": 21, + "column": 39, + "program": "loopWithinLambda.ets" + }, + "end": { + "line": 21, + "column": 56, + "program": "loopWithinLambda.ets" + } + } + }, + "decorators": [], + "loc": { + "start": { + "line": 21, + "column": 31, + "program": "loopWithinLambda.ets" + }, + "end": { + "line": 21, + "column": 56, + "program": "loopWithinLambda.ets" + } + } + }, + "loc": { + "start": { + "line": 21, + "column": 31, + "program": "loopWithinLambda.ets" + }, + "end": { + "line": 21, + "column": 56, + "program": "loopWithinLambda.ets" + } + } + }, + { + "type": "ETSParameterExpression", + "name": { + "type": "Identifier", + "name": "arg", + "typeAnnotation": { + "type": "ETSPrimitiveType", + "loc": { + "start": { + "line": 21, + "column": 63, + "program": "loopWithinLambda.ets" + }, + "end": { + "line": 21, + "column": 66, + "program": "loopWithinLambda.ets" + } + } + }, + "decorators": [], + "loc": { + "start": { + "line": 21, + "column": 58, + "program": "loopWithinLambda.ets" + }, + "end": { + "line": 21, + "column": 66, + "program": "loopWithinLambda.ets" + } + } + }, + "loc": { + "start": { + "line": 21, + "column": 58, + "program": "loopWithinLambda.ets" + }, + "end": { + "line": 21, + "column": 66, + "program": "loopWithinLambda.ets" + } + } + } + ], + "body": { + "type": "BlockStatement", + "statements": [ + { + "type": "ReturnStatement", + "argument": { + "type": "CallExpression", + "callee": { + "type": "Identifier", + "name": "lambda", + "decorators": [], + "loc": { + "start": { + "line": 21, + "column": 80, + "program": "loopWithinLambda.ets" + }, + "end": { + "line": 21, + "column": 86, + "program": "loopWithinLambda.ets" + } + } + }, + "arguments": [ + { + "type": "Identifier", + "name": "arg", + "decorators": [], + "loc": { + "start": { + "line": 21, + "column": 87, + "program": "loopWithinLambda.ets" + }, + "end": { + "line": 21, + "column": 90, + "program": "loopWithinLambda.ets" + } + } + } + ], + "optional": false, + "loc": { + "start": { + "line": 21, + "column": 80, + "program": "loopWithinLambda.ets" + }, + "end": { + "line": 21, + "column": 91, + "program": "loopWithinLambda.ets" + } + } + }, + "loc": { + "start": { + "line": 21, + "column": 73, + "program": "loopWithinLambda.ets" + }, + "end": { + "line": 21, + "column": 91, + "program": "loopWithinLambda.ets" + } + } + } + ], + "loc": { + "start": { + "line": 21, + "column": 71, + "program": "loopWithinLambda.ets" + }, + "end": { + "line": 21, + "column": 93, + "program": "loopWithinLambda.ets" + } + } + }, + "loc": { + "start": { + "line": 21, + "column": 30, + "program": "loopWithinLambda.ets" + }, + "end": { + "line": 21, + "column": 93, + "program": "loopWithinLambda.ets" + } + } + }, + "loc": { + "start": { + "line": 21, + "column": 30, + "program": "loopWithinLambda.ets" + }, + "end": { + "line": 21, + "column": 93, + "program": "loopWithinLambda.ets" + } + } + }, + "loc": { + "start": { + "line": 21, + "column": 9, + "program": "loopWithinLambda.ets" + }, + "end": { + "line": 21, + "column": 93, + "program": "loopWithinLambda.ets" + } + } + } + ], + "kind": "let", + "loc": { + "start": { + "line": 21, + "column": 5, + "program": "loopWithinLambda.ets" + }, + "end": { + "line": 21, + "column": 93, + "program": "loopWithinLambda.ets" + } + } + }, + { + "type": "VariableDeclaration", + "declarations": [ + { + "type": "VariableDeclarator", + "id": { + "type": "Identifier", + "name": "it", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "T2", + "decorators": [], + "loc": { + "start": { + "line": 22, + "column": 13, + "program": "loopWithinLambda.ets" + }, + "end": { + "line": 22, + "column": 15, + "program": "loopWithinLambda.ets" + } + } + }, + "loc": { + "start": { + "line": 22, + "column": 13, + "program": "loopWithinLambda.ets" + }, + "end": { + "line": 22, + "column": 17, + "program": "loopWithinLambda.ets" + } + } + }, + "loc": { + "start": { + "line": 22, + "column": 13, + "program": "loopWithinLambda.ets" + }, + "end": { + "line": 22, + "column": 17, + "program": "loopWithinLambda.ets" + } + } + }, + "decorators": [], + "loc": { + "start": { + "line": 22, + "column": 9, + "program": "loopWithinLambda.ets" + }, + "end": { + "line": 22, + "column": 11, + "program": "loopWithinLambda.ets" + } + } + }, + "init": { + "type": "ArrowFunctionExpression", + "function": { + "type": "ScriptFunction", + "id": null, + "generator": false, + "async": false, + "expression": false, + "params": [ + { + "type": "ETSParameterExpression", + "name": { + "type": "Identifier", + "name": "c", + "typeAnnotation": { + "type": "ETSPrimitiveType", + "loc": { + "start": { + "line": 22, + "column": 22, + "program": "loopWithinLambda.ets" + }, + "end": { + "line": 22, + "column": 25, + "program": "loopWithinLambda.ets" + } + } + }, + "decorators": [], + "loc": { + "start": { + "line": 22, + "column": 19, + "program": "loopWithinLambda.ets" + }, + "end": { + "line": 22, + "column": 25, + "program": "loopWithinLambda.ets" + } + } + }, + "loc": { + "start": { + "line": 22, + "column": 19, + "program": "loopWithinLambda.ets" + }, + "end": { + "line": 22, + "column": 25, + "program": "loopWithinLambda.ets" + } + } + } + ], + "returnType": { + "type": "ETSPrimitiveType", + "loc": { + "start": { + "line": 22, + "column": 28, + "program": "loopWithinLambda.ets" + }, + "end": { + "line": 22, + "column": 31, + "program": "loopWithinLambda.ets" + } + } + }, + "body": { + "type": "BlockStatement", + "statements": [ + { + "type": "ReturnStatement", + "argument": { + "type": "Identifier", + "name": "c", + "decorators": [], + "loc": { + "start": { + "line": 22, + "column": 43, + "program": "loopWithinLambda.ets" + }, + "end": { + "line": 22, + "column": 44, + "program": "loopWithinLambda.ets" + } + } + }, + "loc": { + "start": { + "line": 22, + "column": 36, + "program": "loopWithinLambda.ets" + }, + "end": { + "line": 22, + "column": 44, + "program": "loopWithinLambda.ets" + } + } + } + ], + "loc": { + "start": { + "line": 22, + "column": 35, + "program": "loopWithinLambda.ets" + }, + "end": { + "line": 22, + "column": 45, + "program": "loopWithinLambda.ets" + } + } + }, + "loc": { + "start": { + "line": 22, + "column": 18, + "program": "loopWithinLambda.ets" + }, + "end": { + "line": 22, + "column": 45, + "program": "loopWithinLambda.ets" + } + } + }, + "loc": { + "start": { + "line": 22, + "column": 18, + "program": "loopWithinLambda.ets" + }, + "end": { + "line": 22, + "column": 45, + "program": "loopWithinLambda.ets" + } + } + }, + "loc": { + "start": { + "line": 22, + "column": 9, + "program": "loopWithinLambda.ets" + }, + "end": { + "line": 22, + "column": 45, + "program": "loopWithinLambda.ets" + } + } + } + ], + "kind": "let", + "loc": { + "start": { + "line": 22, + "column": 5, + "program": "loopWithinLambda.ets" + }, + "end": { + "line": 22, + "column": 45, + "program": "loopWithinLambda.ets" + } + } + }, + { + "type": "WhileStatement", + "test": { + "type": "BinaryExpression", + "operator": ">", + "left": { + "type": "Identifier", + "name": "counter", + "decorators": [], + "loc": { + "start": { + "line": 24, + "column": 12, + "program": "loopWithinLambda.ets" + }, + "end": { + "line": 24, + "column": 19, + "program": "loopWithinLambda.ets" + } + } + }, + "right": { + "type": "NumberLiteral", + "value": 0, + "loc": { + "start": { + "line": 24, + "column": 22, + "program": "loopWithinLambda.ets" + }, + "end": { + "line": 24, + "column": 23, + "program": "loopWithinLambda.ets" + } + } + }, + "loc": { + "start": { + "line": 24, + "column": 12, + "program": "loopWithinLambda.ets" + }, + "end": { + "line": 24, + "column": 23, + "program": "loopWithinLambda.ets" + } + } + }, + "body": { + "type": "ExpressionStatement", + "expression": { + "type": "AssignmentExpression", + "operator": "=", + "left": { + "type": "Identifier", + "name": "counter", + "decorators": [], + "loc": { + "start": { + "line": 24, + "column": 25, + "program": "loopWithinLambda.ets" + }, + "end": { + "line": 24, + "column": 32, + "program": "loopWithinLambda.ets" + } + } + }, + "right": { + "type": "CallExpression", + "callee": { + "type": "Identifier", + "name": "funcWithLambda", + "decorators": [], + "loc": { + "start": { + "line": 24, + "column": 35, + "program": "loopWithinLambda.ets" + }, + "end": { + "line": 24, + "column": 49, + "program": "loopWithinLambda.ets" + } + } + }, + "arguments": [ + { + "type": "Identifier", + "name": "it", + "decorators": [], + "loc": { + "start": { + "line": 24, + "column": 50, + "program": "loopWithinLambda.ets" + }, + "end": { + "line": 24, + "column": 52, + "program": "loopWithinLambda.ets" + } + } + }, + { + "type": "Identifier", + "name": "counter", + "decorators": [], + "loc": { + "start": { + "line": 24, + "column": 54, + "program": "loopWithinLambda.ets" + }, + "end": { + "line": 24, + "column": 61, + "program": "loopWithinLambda.ets" + } + } + } + ], + "optional": false, + "loc": { + "start": { + "line": 24, + "column": 35, + "program": "loopWithinLambda.ets" + }, + "end": { + "line": 24, + "column": 62, + "program": "loopWithinLambda.ets" + } + } + }, + "loc": { + "start": { + "line": 24, + "column": 25, + "program": "loopWithinLambda.ets" + }, + "end": { + "line": 24, + "column": 62, + "program": "loopWithinLambda.ets" + } + } + }, + "loc": { + "start": { + "line": 24, + "column": 25, + "program": "loopWithinLambda.ets" + }, + "end": { + "line": 24, + "column": 62, + "program": "loopWithinLambda.ets" + } + } + }, + "loc": { + "start": { + "line": 24, + "column": 5, + "program": "loopWithinLambda.ets" + }, + "end": { + "line": 24, + "column": 62, + "program": "loopWithinLambda.ets" + } + } + } + ], + "loc": { + "start": { + "line": 20, + "column": 35, + "program": "loopWithinLambda.ets" + }, + "end": { + "line": 25, + "column": 2, + "program": "loopWithinLambda.ets" + } + } + }, + "loc": { + "start": { + "line": 20, + "column": 17, + "program": "loopWithinLambda.ets" + }, + "end": { + "line": 25, + "column": 2, + "program": "loopWithinLambda.ets" + } + } + }, + "loc": { + "start": { + "line": 20, + "column": 17, + "program": "loopWithinLambda.ets" + }, + "end": { + "line": 25, + "column": 2, + "program": "loopWithinLambda.ets" + } + } + }, + "loc": { + "start": { + "line": 20, + "column": 7, + "program": "loopWithinLambda.ets" + }, + "end": { + "line": 25, + "column": 2, + "program": "loopWithinLambda.ets" + } + } + }, + "loc": { + "start": { + "line": 20, + "column": 7, + "program": "loopWithinLambda.ets" + }, + "end": { + "line": 25, + "column": 2, + "program": "loopWithinLambda.ets" + } + } + } + ], "loc": { "start": { "line": 1, @@ -672,12 +1621,12 @@ "loc": { "start": { "line": 21, - "column": 25, + "column": 9, "program": "loopWithinLambda.ets" }, "end": { "line": 21, - "column": 27, + "column": 23, "program": "loopWithinLambda.ets" } } @@ -685,12 +1634,12 @@ "loc": { "start": { "line": 21, - "column": 25, + "column": 9, "program": "loopWithinLambda.ets" }, "end": { "line": 21, - "column": 29, + "column": 23, "program": "loopWithinLambda.ets" } } @@ -698,12 +1647,12 @@ "loc": { "start": { "line": 21, - "column": 25, + "column": 9, "program": "loopWithinLambda.ets" }, "end": { "line": 21, - "column": 29, + "column": 23, "program": "loopWithinLambda.ets" } } @@ -805,7 +1754,7 @@ "loc": { "start": { "line": 21, - "column": 39, + "column": 31, "program": "loopWithinLambda.ets" }, "end": { @@ -964,7 +1913,7 @@ "loc": { "start": { "line": 21, - "column": 71, + "column": 30, "program": "loopWithinLambda.ets" }, "end": { @@ -1047,12 +1996,12 @@ "loc": { "start": { "line": 22, - "column": 13, + "column": 9, "program": "loopWithinLambda.ets" }, "end": { "line": 22, - "column": 15, + "column": 11, "program": "loopWithinLambda.ets" } } @@ -1060,12 +2009,12 @@ "loc": { "start": { "line": 22, - "column": 13, + "column": 9, "program": "loopWithinLambda.ets" }, "end": { "line": 22, - "column": 17, + "column": 11, "program": "loopWithinLambda.ets" } } @@ -1073,12 +2022,12 @@ "loc": { "start": { "line": 22, - "column": 13, + "column": 9, "program": "loopWithinLambda.ets" }, "end": { "line": 22, - "column": 17, + "column": 11, "program": "loopWithinLambda.ets" } } @@ -1208,7 +2157,7 @@ "loc": { "start": { "line": 22, - "column": 35, + "column": 18, "program": "loopWithinLambda.ets" }, "end": { @@ -1457,7 +2406,7 @@ "loc": { "start": { "line": 20, - "column": 35, + "column": 17, "program": "loopWithinLambda.ets" }, "end": { diff --git a/ets2panda/test/compiler/ets/tuple_types_13-expected.txt b/ets2panda/test/compiler/ets/tuple_types_13-expected.txt index 014a482298..72526f212a 100644 --- a/ets2panda/test/compiler/ets/tuple_types_13-expected.txt +++ b/ets2panda/test/compiler/ets/tuple_types_13-expected.txt @@ -371,7 +371,138 @@ "params": [], "body": { "type": "BlockStatement", - "statements": [], + "statements": [ + { + "type": "ExpressionStatement", + "expression": { + "type": "AssignmentExpression", + "operator": "=", + "left": { + "type": "Identifier", + "name": "tup_2", + "decorators": [], + "loc": { + "start": { + "line": 19, + "column": 7, + "program": "tuple_types_13.ets" + }, + "end": { + "line": 19, + "column": 12, + "program": "tuple_types_13.ets" + } + } + }, + "right": { + "type": "ArrayExpression", + "elements": [ + { + "type": "ArrayExpression", + "elements": [ + { + "type": "NumberLiteral", + "value": 13, + "loc": { + "start": { + "line": 20, + "column": 6, + "program": "tuple_types_13.ets" + }, + "end": { + "line": 20, + "column": 8, + "program": "tuple_types_13.ets" + } + } + }, + { + "type": "StringLiteral", + "value": "A", + "loc": { + "start": { + "line": 20, + "column": 10, + "program": "tuple_types_13.ets" + }, + "end": { + "line": 20, + "column": 13, + "program": "tuple_types_13.ets" + } + } + }, + { + "type": "StringLiteral", + "value": "D", + "loc": { + "start": { + "line": 20, + "column": 15, + "program": "tuple_types_13.ets" + }, + "end": { + "line": 20, + "column": 18, + "program": "tuple_types_13.ets" + } + } + } + ], + "loc": { + "start": { + "line": 20, + "column": 5, + "program": "tuple_types_13.ets" + }, + "end": { + "line": 20, + "column": 19, + "program": "tuple_types_13.ets" + } + } + } + ], + "loc": { + "start": { + "line": 19, + "column": 30, + "program": "tuple_types_13.ets" + }, + "end": { + "line": 21, + "column": 2, + "program": "tuple_types_13.ets" + } + } + }, + "loc": { + "start": { + "line": 19, + "column": 7, + "program": "tuple_types_13.ets" + }, + "end": { + "line": 21, + "column": 2, + "program": "tuple_types_13.ets" + } + } + }, + "loc": { + "start": { + "line": 19, + "column": 7, + "program": "tuple_types_13.ets" + }, + "end": { + "line": 21, + "column": 2, + "program": "tuple_types_13.ets" + } + } + } + ], "loc": { "start": { "line": 1, diff --git a/ets2panda/test/parser/ets/FunctionalTypeAsTypeArgument-expected.txt b/ets2panda/test/parser/ets/FunctionalTypeAsTypeArgument-expected.txt index d2da9e851f..e730cd38e2 100644 --- a/ets2panda/test/parser/ets/FunctionalTypeAsTypeArgument-expected.txt +++ b/ets2panda/test/parser/ets/FunctionalTypeAsTypeArgument-expected.txt @@ -181,7 +181,247 @@ "params": [], "body": { "type": "BlockStatement", - "statements": [], + "statements": [ + { + "type": "ExpressionStatement", + "expression": { + "type": "AssignmentExpression", + "operator": "=", + "left": { + "type": "Identifier", + "name": "alma", + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 7, + "program": "FunctionalTypeAsTypeArgument.ets" + }, + "end": { + "line": 16, + "column": 11, + "program": "FunctionalTypeAsTypeArgument.ets" + } + } + }, + "right": { + "type": "ETSNewClassInstanceExpression", + "typeReference": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Array", + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 18, + "program": "FunctionalTypeAsTypeArgument.ets" + }, + "end": { + "line": 16, + "column": 23, + "program": "FunctionalTypeAsTypeArgument.ets" + } + } + }, + "typeParams": { + "type": "TSTypeParameterInstantiation", + "params": [ + { + "type": "ETSFunctionType", + "params": [ + { + "type": "ETSParameterExpression", + "name": { + "type": "Identifier", + "name": "args", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Object", + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 31, + "program": "FunctionalTypeAsTypeArgument.ets" + }, + "end": { + "line": 16, + "column": 37, + "program": "FunctionalTypeAsTypeArgument.ets" + } + } + }, + "loc": { + "start": { + "line": 16, + "column": 31, + "program": "FunctionalTypeAsTypeArgument.ets" + }, + "end": { + "line": 16, + "column": 38, + "program": "FunctionalTypeAsTypeArgument.ets" + } + } + }, + "loc": { + "start": { + "line": 16, + "column": 31, + "program": "FunctionalTypeAsTypeArgument.ets" + }, + "end": { + "line": 16, + "column": 38, + "program": "FunctionalTypeAsTypeArgument.ets" + } + } + }, + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 25, + "program": "FunctionalTypeAsTypeArgument.ets" + }, + "end": { + "line": 16, + "column": 38, + "program": "FunctionalTypeAsTypeArgument.ets" + } + } + }, + "loc": { + "start": { + "line": 16, + "column": 25, + "program": "FunctionalTypeAsTypeArgument.ets" + }, + "end": { + "line": 16, + "column": 38, + "program": "FunctionalTypeAsTypeArgument.ets" + } + } + } + ], + "returnType": { + "type": "ETSPrimitiveType", + "loc": { + "start": { + "line": 16, + "column": 42, + "program": "FunctionalTypeAsTypeArgument.ets" + }, + "end": { + "line": 16, + "column": 46, + "program": "FunctionalTypeAsTypeArgument.ets" + } + } + }, + "loc": { + "start": { + "line": 16, + "column": 24, + "program": "FunctionalTypeAsTypeArgument.ets" + }, + "end": { + "line": 16, + "column": 46, + "program": "FunctionalTypeAsTypeArgument.ets" + } + } + } + ], + "loc": { + "start": { + "line": 16, + "column": 23, + "program": "FunctionalTypeAsTypeArgument.ets" + }, + "end": { + "line": 16, + "column": 47, + "program": "FunctionalTypeAsTypeArgument.ets" + } + } + }, + "loc": { + "start": { + "line": 16, + "column": 18, + "program": "FunctionalTypeAsTypeArgument.ets" + }, + "end": { + "line": 16, + "column": 48, + "program": "FunctionalTypeAsTypeArgument.ets" + } + } + }, + "loc": { + "start": { + "line": 16, + "column": 18, + "program": "FunctionalTypeAsTypeArgument.ets" + }, + "end": { + "line": 16, + "column": 48, + "program": "FunctionalTypeAsTypeArgument.ets" + } + } + }, + "arguments": [], + "loc": { + "start": { + "line": 16, + "column": 14, + "program": "FunctionalTypeAsTypeArgument.ets" + }, + "end": { + "line": 17, + "column": 1, + "program": "FunctionalTypeAsTypeArgument.ets" + } + } + }, + "loc": { + "start": { + "line": 16, + "column": 7, + "program": "FunctionalTypeAsTypeArgument.ets" + }, + "end": { + "line": 17, + "column": 1, + "program": "FunctionalTypeAsTypeArgument.ets" + } + } + }, + "loc": { + "start": { + "line": 16, + "column": 7, + "program": "FunctionalTypeAsTypeArgument.ets" + }, + "end": { + "line": 17, + "column": 1, + "program": "FunctionalTypeAsTypeArgument.ets" + } + } + } + ], "loc": { "start": { "line": 1, @@ -382,12 +622,12 @@ "loc": { "start": { "line": 16, - "column": 24, + "column": 23, "program": "FunctionalTypeAsTypeArgument.ets" }, "end": { "line": 16, - "column": 46, + "column": 47, "program": "FunctionalTypeAsTypeArgument.ets" } } diff --git a/ets2panda/test/parser/ets/assign-expected.txt b/ets2panda/test/parser/ets/assign-expected.txt index b6142a4897..ecca7cc481 100644 --- a/ets2panda/test/parser/ets/assign-expected.txt +++ b/ets2panda/test/parser/ets/assign-expected.txt @@ -139,6 +139,70 @@ "program": "assign.ets" } } + }, + { + "type": "ExpressionStatement", + "expression": { + "type": "AssignmentExpression", + "operator": "=", + "left": { + "type": "Identifier", + "name": "b", + "decorators": [], + "loc": { + "start": { + "line": 17, + "column": 7, + "program": "assign.ets" + }, + "end": { + "line": 17, + "column": 8, + "program": "assign.ets" + } + } + }, + "right": { + "type": "NumberLiteral", + "value": 1, + "loc": { + "start": { + "line": 17, + "column": 11, + "program": "assign.ets" + }, + "end": { + "line": 17, + "column": 12, + "program": "assign.ets" + } + } + }, + "loc": { + "start": { + "line": 17, + "column": 7, + "program": "assign.ets" + }, + "end": { + "line": 17, + "column": 12, + "program": "assign.ets" + } + } + }, + "loc": { + "start": { + "line": 17, + "column": 7, + "program": "assign.ets" + }, + "end": { + "line": 17, + "column": 12, + "program": "assign.ets" + } + } } ], "loc": { diff --git a/ets2panda/test/parser/ets/boolean-expected.txt b/ets2panda/test/parser/ets/boolean-expected.txt index 152eb7b11c..7ada77b321 100644 --- a/ets2panda/test/parser/ets/boolean-expected.txt +++ b/ets2panda/test/parser/ets/boolean-expected.txt @@ -245,6 +245,70 @@ "program": "boolean.ets" } } + }, + { + "type": "ExpressionStatement", + "expression": { + "type": "AssignmentExpression", + "operator": "=", + "left": { + "type": "Identifier", + "name": "f", + "decorators": [], + "loc": { + "start": { + "line": 17, + "column": 7, + "program": "boolean.ets" + }, + "end": { + "line": 17, + "column": 8, + "program": "boolean.ets" + } + } + }, + "right": { + "type": "BooleanLiteral", + "value": false, + "loc": { + "start": { + "line": 17, + "column": 11, + "program": "boolean.ets" + }, + "end": { + "line": 17, + "column": 16, + "program": "boolean.ets" + } + } + }, + "loc": { + "start": { + "line": 17, + "column": 7, + "program": "boolean.ets" + }, + "end": { + "line": 17, + "column": 16, + "program": "boolean.ets" + } + } + }, + "loc": { + "start": { + "line": 17, + "column": 7, + "program": "boolean.ets" + }, + "end": { + "line": 17, + "column": 16, + "program": "boolean.ets" + } + } } ], "loc": { diff --git a/ets2panda/test/parser/ets/const-expected.txt b/ets2panda/test/parser/ets/const-expected.txt index d4eb5c420c..5a4d86846c 100644 --- a/ets2panda/test/parser/ets/const-expected.txt +++ b/ets2panda/test/parser/ets/const-expected.txt @@ -181,7 +181,136 @@ "params": [], "body": { "type": "BlockStatement", - "statements": [], + "statements": [ + { + "type": "ExpressionStatement", + "expression": { + "type": "AssignmentExpression", + "operator": "=", + "left": { + "type": "Identifier", + "name": "x", + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 7, + "program": "const.ets" + }, + "end": { + "line": 16, + "column": 8, + "program": "const.ets" + } + } + }, + "right": { + "type": "NumberLiteral", + "value": 1, + "loc": { + "start": { + "line": 16, + "column": 11, + "program": "const.ets" + }, + "end": { + "line": 16, + "column": 12, + "program": "const.ets" + } + } + }, + "loc": { + "start": { + "line": 16, + "column": 7, + "program": "const.ets" + }, + "end": { + "line": 16, + "column": 12, + "program": "const.ets" + } + } + }, + "loc": { + "start": { + "line": 16, + "column": 7, + "program": "const.ets" + }, + "end": { + "line": 16, + "column": 12, + "program": "const.ets" + } + } + }, + { + "type": "ExpressionStatement", + "expression": { + "type": "AssignmentExpression", + "operator": "=", + "left": { + "type": "Identifier", + "name": "y", + "decorators": [], + "loc": { + "start": { + "line": 17, + "column": 7, + "program": "const.ets" + }, + "end": { + "line": 17, + "column": 8, + "program": "const.ets" + } + } + }, + "right": { + "type": "StringLiteral", + "value": "Hello", + "loc": { + "start": { + "line": 17, + "column": 19, + "program": "const.ets" + }, + "end": { + "line": 17, + "column": 26, + "program": "const.ets" + } + } + }, + "loc": { + "start": { + "line": 17, + "column": 7, + "program": "const.ets" + }, + "end": { + "line": 17, + "column": 26, + "program": "const.ets" + } + } + }, + "loc": { + "start": { + "line": 17, + "column": 7, + "program": "const.ets" + }, + "end": { + "line": 17, + "column": 26, + "program": "const.ets" + } + } + } + ], "loc": { "start": { "line": 1, diff --git a/ets2panda/test/parser/ets/decl_infer-expected.txt b/ets2panda/test/parser/ets/decl_infer-expected.txt index d019542239..157edcb8fb 100644 --- a/ets2panda/test/parser/ets/decl_infer-expected.txt +++ b/ets2panda/test/parser/ets/decl_infer-expected.txt @@ -501,6 +501,326 @@ "program": "decl_infer.ets" } } + }, + { + "type": "ExpressionStatement", + "expression": { + "type": "AssignmentExpression", + "operator": "=", + "left": { + "type": "Identifier", + "name": "ci", + "decorators": [], + "loc": { + "start": { + "line": 22, + "column": 7, + "program": "decl_infer.ets" + }, + "end": { + "line": 22, + "column": 9, + "program": "decl_infer.ets" + } + } + }, + "right": { + "type": "NumberLiteral", + "value": 0, + "loc": { + "start": { + "line": 22, + "column": 12, + "program": "decl_infer.ets" + }, + "end": { + "line": 22, + "column": 13, + "program": "decl_infer.ets" + } + } + }, + "loc": { + "start": { + "line": 22, + "column": 7, + "program": "decl_infer.ets" + }, + "end": { + "line": 22, + "column": 13, + "program": "decl_infer.ets" + } + } + }, + "loc": { + "start": { + "line": 22, + "column": 7, + "program": "decl_infer.ets" + }, + "end": { + "line": 22, + "column": 13, + "program": "decl_infer.ets" + } + } + }, + { + "type": "ExpressionStatement", + "expression": { + "type": "AssignmentExpression", + "operator": "=", + "left": { + "type": "Identifier", + "name": "cd", + "decorators": [], + "loc": { + "start": { + "line": 23, + "column": 7, + "program": "decl_infer.ets" + }, + "end": { + "line": 23, + "column": 9, + "program": "decl_infer.ets" + } + } + }, + "right": { + "type": "NumberLiteral", + "value": 0, + "loc": { + "start": { + "line": 23, + "column": 12, + "program": "decl_infer.ets" + }, + "end": { + "line": 23, + "column": 15, + "program": "decl_infer.ets" + } + } + }, + "loc": { + "start": { + "line": 23, + "column": 7, + "program": "decl_infer.ets" + }, + "end": { + "line": 23, + "column": 15, + "program": "decl_infer.ets" + } + } + }, + "loc": { + "start": { + "line": 23, + "column": 7, + "program": "decl_infer.ets" + }, + "end": { + "line": 23, + "column": 15, + "program": "decl_infer.ets" + } + } + }, + { + "type": "ExpressionStatement", + "expression": { + "type": "AssignmentExpression", + "operator": "=", + "left": { + "type": "Identifier", + "name": "cc", + "decorators": [], + "loc": { + "start": { + "line": 24, + "column": 7, + "program": "decl_infer.ets" + }, + "end": { + "line": 24, + "column": 9, + "program": "decl_infer.ets" + } + } + }, + "right": { + "type": "CharLiteral", + "value": "a", + "loc": { + "start": { + "line": 24, + "column": 12, + "program": "decl_infer.ets" + }, + "end": { + "line": 24, + "column": 16, + "program": "decl_infer.ets" + } + } + }, + "loc": { + "start": { + "line": 24, + "column": 7, + "program": "decl_infer.ets" + }, + "end": { + "line": 24, + "column": 16, + "program": "decl_infer.ets" + } + } + }, + "loc": { + "start": { + "line": 24, + "column": 7, + "program": "decl_infer.ets" + }, + "end": { + "line": 24, + "column": 16, + "program": "decl_infer.ets" + } + } + }, + { + "type": "ExpressionStatement", + "expression": { + "type": "AssignmentExpression", + "operator": "=", + "left": { + "type": "Identifier", + "name": "cs", + "decorators": [], + "loc": { + "start": { + "line": 25, + "column": 7, + "program": "decl_infer.ets" + }, + "end": { + "line": 25, + "column": 9, + "program": "decl_infer.ets" + } + } + }, + "right": { + "type": "StringLiteral", + "value": "11", + "loc": { + "start": { + "line": 25, + "column": 12, + "program": "decl_infer.ets" + }, + "end": { + "line": 25, + "column": 16, + "program": "decl_infer.ets" + } + } + }, + "loc": { + "start": { + "line": 25, + "column": 7, + "program": "decl_infer.ets" + }, + "end": { + "line": 25, + "column": 16, + "program": "decl_infer.ets" + } + } + }, + "loc": { + "start": { + "line": 25, + "column": 7, + "program": "decl_infer.ets" + }, + "end": { + "line": 25, + "column": 16, + "program": "decl_infer.ets" + } + } + }, + { + "type": "ExpressionStatement", + "expression": { + "type": "AssignmentExpression", + "operator": "=", + "left": { + "type": "Identifier", + "name": "cb", + "decorators": [], + "loc": { + "start": { + "line": 26, + "column": 7, + "program": "decl_infer.ets" + }, + "end": { + "line": 26, + "column": 9, + "program": "decl_infer.ets" + } + } + }, + "right": { + "type": "BooleanLiteral", + "value": false, + "loc": { + "start": { + "line": 26, + "column": 12, + "program": "decl_infer.ets" + }, + "end": { + "line": 26, + "column": 17, + "program": "decl_infer.ets" + } + } + }, + "loc": { + "start": { + "line": 26, + "column": 7, + "program": "decl_infer.ets" + }, + "end": { + "line": 26, + "column": 17, + "program": "decl_infer.ets" + } + } + }, + "loc": { + "start": { + "line": 26, + "column": 7, + "program": "decl_infer.ets" + }, + "end": { + "line": 26, + "column": 17, + "program": "decl_infer.ets" + } + } } ], "loc": { diff --git a/ets2panda/test/parser/ets/exports-expected.txt b/ets2panda/test/parser/ets/exports-expected.txt index 774017d3bb..442f2b93db 100644 --- a/ets2panda/test/parser/ets/exports-expected.txt +++ b/ets2panda/test/parser/ets/exports-expected.txt @@ -496,6 +496,70 @@ "program": "exports.ets" } } + }, + { + "type": "ExpressionStatement", + "expression": { + "type": "AssignmentExpression", + "operator": "=", + "left": { + "type": "Identifier", + "name": "b", + "decorators": [], + "loc": { + "start": { + "line": 17, + "column": 14, + "program": "exports.ets" + }, + "end": { + "line": 17, + "column": 15, + "program": "exports.ets" + } + } + }, + "right": { + "type": "NumberLiteral", + "value": 12, + "loc": { + "start": { + "line": 17, + "column": 18, + "program": "exports.ets" + }, + "end": { + "line": 17, + "column": 20, + "program": "exports.ets" + } + } + }, + "loc": { + "start": { + "line": 17, + "column": 14, + "program": "exports.ets" + }, + "end": { + "line": 17, + "column": 20, + "program": "exports.ets" + } + } + }, + "loc": { + "start": { + "line": 17, + "column": 14, + "program": "exports.ets" + }, + "end": { + "line": 17, + "column": 20, + "program": "exports.ets" + } + } } ], "loc": { diff --git a/ets2panda/test/parser/ets/global_const_vars3-expected.txt b/ets2panda/test/parser/ets/global_const_vars3-expected.txt index 0353208900..93edc541b8 100644 --- a/ets2panda/test/parser/ets/global_const_vars3-expected.txt +++ b/ets2panda/test/parser/ets/global_const_vars3-expected.txt @@ -689,7 +689,183 @@ "params": [], "body": { "type": "BlockStatement", - "statements": [], + "statements": [ + { + "type": "ExpressionStatement", + "expression": { + "type": "AssignmentExpression", + "operator": "=", + "left": { + "type": "Identifier", + "name": "a", + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 7, + "program": "global_const_vars3.ets" + }, + "end": { + "line": 16, + "column": 8, + "program": "global_const_vars3.ets" + } + } + }, + "right": { + "type": "NumberLiteral", + "value": 2, + "loc": { + "start": { + "line": 16, + "column": 16, + "program": "global_const_vars3.ets" + }, + "end": { + "line": 16, + "column": 17, + "program": "global_const_vars3.ets" + } + } + }, + "loc": { + "start": { + "line": 16, + "column": 7, + "program": "global_const_vars3.ets" + }, + "end": { + "line": 16, + "column": 17, + "program": "global_const_vars3.ets" + } + } + }, + "loc": { + "start": { + "line": 16, + "column": 7, + "program": "global_const_vars3.ets" + }, + "end": { + "line": 16, + "column": 17, + "program": "global_const_vars3.ets" + } + } + }, + { + "type": "ExpressionStatement", + "expression": { + "type": "AssignmentExpression", + "operator": "=", + "left": { + "type": "Identifier", + "name": "dae", + "decorators": [], + "loc": { + "start": { + "line": 17, + "column": 7, + "program": "global_const_vars3.ets" + }, + "end": { + "line": 17, + "column": 10, + "program": "global_const_vars3.ets" + } + } + }, + "right": { + "type": "ETSNewClassInstanceExpression", + "typeReference": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Date", + "decorators": [], + "loc": { + "start": { + "line": 17, + "column": 23, + "program": "global_const_vars3.ets" + }, + "end": { + "line": 17, + "column": 27, + "program": "global_const_vars3.ets" + } + } + }, + "loc": { + "start": { + "line": 17, + "column": 23, + "program": "global_const_vars3.ets" + }, + "end": { + "line": 17, + "column": 28, + "program": "global_const_vars3.ets" + } + } + }, + "loc": { + "start": { + "line": 17, + "column": 23, + "program": "global_const_vars3.ets" + }, + "end": { + "line": 17, + "column": 28, + "program": "global_const_vars3.ets" + } + } + }, + "arguments": [], + "loc": { + "start": { + "line": 17, + "column": 19, + "program": "global_const_vars3.ets" + }, + "end": { + "line": 17, + "column": 30, + "program": "global_const_vars3.ets" + } + } + }, + "loc": { + "start": { + "line": 17, + "column": 7, + "program": "global_const_vars3.ets" + }, + "end": { + "line": 17, + "column": 30, + "program": "global_const_vars3.ets" + } + } + }, + "loc": { + "start": { + "line": 17, + "column": 7, + "program": "global_const_vars3.ets" + }, + "end": { + "line": 17, + "column": 30, + "program": "global_const_vars3.ets" + } + } + } + ], "loc": { "start": { "line": 1, diff --git a/ets2panda/test/parser/ets/import_tests/import_name_conflicts/imported_module_1-expected.txt b/ets2panda/test/parser/ets/import_tests/import_name_conflicts/imported_module_1-expected.txt index 2e79b56dc3..7110030c74 100644 --- a/ets2panda/test/parser/ets/import_tests/import_name_conflicts/imported_module_1-expected.txt +++ b/ets2panda/test/parser/ets/import_tests/import_name_conflicts/imported_module_1-expected.txt @@ -547,6 +547,70 @@ "body": { "type": "BlockStatement", "statements": [ + { + "type": "ExpressionStatement", + "expression": { + "type": "AssignmentExpression", + "operator": "=", + "left": { + "type": "Identifier", + "name": "dbl", + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 14, + "program": "imported_module_1.ets" + }, + "end": { + "line": 16, + "column": 17, + "program": "imported_module_1.ets" + } + } + }, + "right": { + "type": "NumberLiteral", + "value": 1.23457, + "loc": { + "start": { + "line": 16, + "column": 28, + "program": "imported_module_1.ets" + }, + "end": { + "line": 16, + "column": 38, + "program": "imported_module_1.ets" + } + } + }, + "loc": { + "start": { + "line": 16, + "column": 14, + "program": "imported_module_1.ets" + }, + "end": { + "line": 16, + "column": 38, + "program": "imported_module_1.ets" + } + } + }, + "loc": { + "start": { + "line": 16, + "column": 14, + "program": "imported_module_1.ets" + }, + "end": { + "line": 16, + "column": 38, + "program": "imported_module_1.ets" + } + } + }, { "type": "ExpressionStatement", "expression": { diff --git a/ets2panda/test/parser/ets/import_tests/import_name_conflicts/imported_module_2-expected.txt b/ets2panda/test/parser/ets/import_tests/import_name_conflicts/imported_module_2-expected.txt index 0f0b798931..e782f6cf9d 100644 --- a/ets2panda/test/parser/ets/import_tests/import_name_conflicts/imported_module_2-expected.txt +++ b/ets2panda/test/parser/ets/import_tests/import_name_conflicts/imported_module_2-expected.txt @@ -547,6 +547,70 @@ "body": { "type": "BlockStatement", "statements": [ + { + "type": "ExpressionStatement", + "expression": { + "type": "AssignmentExpression", + "operator": "=", + "left": { + "type": "Identifier", + "name": "flt", + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 14, + "program": "imported_module_2.ets" + }, + "end": { + "line": 16, + "column": 17, + "program": "imported_module_2.ets" + } + } + }, + "right": { + "type": "NumberLiteral", + "value": 2.345, + "loc": { + "start": { + "line": 16, + "column": 27, + "program": "imported_module_2.ets" + }, + "end": { + "line": 16, + "column": 32, + "program": "imported_module_2.ets" + } + } + }, + "loc": { + "start": { + "line": 16, + "column": 14, + "program": "imported_module_2.ets" + }, + "end": { + "line": 16, + "column": 32, + "program": "imported_module_2.ets" + } + } + }, + "loc": { + "start": { + "line": 16, + "column": 14, + "program": "imported_module_2.ets" + }, + "end": { + "line": 16, + "column": 32, + "program": "imported_module_2.ets" + } + } + }, { "type": "ExpressionStatement", "expression": { diff --git a/ets2panda/test/parser/ets/import_tests/packages/package_module_1-expected.txt b/ets2panda/test/parser/ets/import_tests/packages/package_module_1-expected.txt old mode 100755 new mode 100644 index b200321200..2d5c4ca9b4 --- a/ets2panda/test/parser/ets/import_tests/packages/package_module_1-expected.txt +++ b/ets2panda/test/parser/ets/import_tests/packages/package_module_1-expected.txt @@ -139,7 +139,136 @@ "params": [], "body": { "type": "BlockStatement", - "statements": [], + "statements": [ + { + "type": "ExpressionStatement", + "expression": { + "type": "AssignmentExpression", + "operator": "=", + "left": { + "type": "Identifier", + "name": "dbl", + "decorators": [], + "loc": { + "start": { + "line": 18, + "column": 14, + "program": "package_module_1.ets" + }, + "end": { + "line": 18, + "column": 17, + "program": "package_module_1.ets" + } + } + }, + "right": { + "type": "NumberLiteral", + "value": 1.23457, + "loc": { + "start": { + "line": 18, + "column": 28, + "program": "package_module_1.ets" + }, + "end": { + "line": 18, + "column": 38, + "program": "package_module_1.ets" + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 14, + "program": "package_module_1.ets" + }, + "end": { + "line": 18, + "column": 38, + "program": "package_module_1.ets" + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 14, + "program": "package_module_1.ets" + }, + "end": { + "line": 18, + "column": 38, + "program": "package_module_1.ets" + } + } + }, + { + "type": "ExpressionStatement", + "expression": { + "type": "AssignmentExpression", + "operator": "=", + "left": { + "type": "Identifier", + "name": "flt", + "decorators": [], + "loc": { + "start": { + "line": 18, + "column": 14, + "program": "package_module_2.ets" + }, + "end": { + "line": 18, + "column": 17, + "program": "package_module_2.ets" + } + } + }, + "right": { + "type": "NumberLiteral", + "value": 1.2345, + "loc": { + "start": { + "line": 18, + "column": 27, + "program": "package_module_2.ets" + }, + "end": { + "line": 18, + "column": 33, + "program": "package_module_2.ets" + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 14, + "program": "package_module_2.ets" + }, + "end": { + "line": 18, + "column": 33, + "program": "package_module_2.ets" + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 14, + "program": "package_module_2.ets" + }, + "end": { + "line": 18, + "column": 33, + "program": "package_module_2.ets" + } + } + } + ], "loc": { "start": { "line": 1, diff --git a/ets2panda/test/parser/ets/import_tests/packages/package_module_2-expected.txt b/ets2panda/test/parser/ets/import_tests/packages/package_module_2-expected.txt old mode 100755 new mode 100644 index b1d61276d9..f4d8519548 --- a/ets2panda/test/parser/ets/import_tests/packages/package_module_2-expected.txt +++ b/ets2panda/test/parser/ets/import_tests/packages/package_module_2-expected.txt @@ -139,7 +139,136 @@ "params": [], "body": { "type": "BlockStatement", - "statements": [], + "statements": [ + { + "type": "ExpressionStatement", + "expression": { + "type": "AssignmentExpression", + "operator": "=", + "left": { + "type": "Identifier", + "name": "flt", + "decorators": [], + "loc": { + "start": { + "line": 18, + "column": 14, + "program": "package_module_2.ets" + }, + "end": { + "line": 18, + "column": 17, + "program": "package_module_2.ets" + } + } + }, + "right": { + "type": "NumberLiteral", + "value": 1.2345, + "loc": { + "start": { + "line": 18, + "column": 27, + "program": "package_module_2.ets" + }, + "end": { + "line": 18, + "column": 33, + "program": "package_module_2.ets" + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 14, + "program": "package_module_2.ets" + }, + "end": { + "line": 18, + "column": 33, + "program": "package_module_2.ets" + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 14, + "program": "package_module_2.ets" + }, + "end": { + "line": 18, + "column": 33, + "program": "package_module_2.ets" + } + } + }, + { + "type": "ExpressionStatement", + "expression": { + "type": "AssignmentExpression", + "operator": "=", + "left": { + "type": "Identifier", + "name": "dbl", + "decorators": [], + "loc": { + "start": { + "line": 18, + "column": 14, + "program": "package_module_1.ets" + }, + "end": { + "line": 18, + "column": 17, + "program": "package_module_1.ets" + } + } + }, + "right": { + "type": "NumberLiteral", + "value": 1.23457, + "loc": { + "start": { + "line": 18, + "column": 28, + "program": "package_module_1.ets" + }, + "end": { + "line": 18, + "column": 34, + "program": "package_module_1.ets" + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 14, + "program": "package_module_1.ets" + }, + "end": { + "line": 18, + "column": 34, + "program": "package_module_1.ets" + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 14, + "program": "package_module_1.ets" + }, + "end": { + "line": 18, + "column": 34, + "program": "package_module_1.ets" + } + } + } + ], "loc": { "start": { "line": 1, diff --git a/ets2panda/test/parser/ets/launch_with_call_expression-expected.txt b/ets2panda/test/parser/ets/launch_with_call_expression-expected.txt index d242fffc6c..d1b22a7214 100644 --- a/ets2panda/test/parser/ets/launch_with_call_expression-expected.txt +++ b/ets2panda/test/parser/ets/launch_with_call_expression-expected.txt @@ -825,14 +825,14 @@ }, "loc": { "start": { - "line": 1, - "column": 1, - "program": null + "line": 21, + "column": 17, + "program": "launch_with_call_expression.ets" }, "end": { - "line": 1, - "column": 1, - "program": null + "line": 21, + "column": 35, + "program": "launch_with_call_expression.ets" } } } diff --git a/ets2panda/test/parser/ets/literals-expected.txt b/ets2panda/test/parser/ets/literals-expected.txt index 5dffbbbbf6..0b5923cbd2 100644 --- a/ets2panda/test/parser/ets/literals-expected.txt +++ b/ets2panda/test/parser/ets/literals-expected.txt @@ -181,7 +181,1499 @@ "params": [], "body": { "type": "BlockStatement", - "statements": [], + "statements": [ + { + "type": "ExpressionStatement", + "expression": { + "type": "AssignmentExpression", + "operator": "=", + "left": { + "type": "Identifier", + "name": "lit00", + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 7, + "program": "literals.ets" + }, + "end": { + "line": 16, + "column": 12, + "program": "literals.ets" + } + } + }, + "right": { + "type": "NumberLiteral", + "value": 0, + "loc": { + "start": { + "line": 16, + "column": 15, + "program": "literals.ets" + }, + "end": { + "line": 16, + "column": 16, + "program": "literals.ets" + } + } + }, + "loc": { + "start": { + "line": 16, + "column": 7, + "program": "literals.ets" + }, + "end": { + "line": 16, + "column": 16, + "program": "literals.ets" + } + } + }, + "loc": { + "start": { + "line": 16, + "column": 7, + "program": "literals.ets" + }, + "end": { + "line": 16, + "column": 16, + "program": "literals.ets" + } + } + }, + { + "type": "ExpressionStatement", + "expression": { + "type": "AssignmentExpression", + "operator": "=", + "left": { + "type": "Identifier", + "name": "lit01", + "decorators": [], + "loc": { + "start": { + "line": 17, + "column": 7, + "program": "literals.ets" + }, + "end": { + "line": 17, + "column": 12, + "program": "literals.ets" + } + } + }, + "right": { + "type": "NumberLiteral", + "value": 0, + "loc": { + "start": { + "line": 17, + "column": 15, + "program": "literals.ets" + }, + "end": { + "line": 17, + "column": 18, + "program": "literals.ets" + } + } + }, + "loc": { + "start": { + "line": 17, + "column": 7, + "program": "literals.ets" + }, + "end": { + "line": 17, + "column": 18, + "program": "literals.ets" + } + } + }, + "loc": { + "start": { + "line": 17, + "column": 7, + "program": "literals.ets" + }, + "end": { + "line": 17, + "column": 18, + "program": "literals.ets" + } + } + }, + { + "type": "ExpressionStatement", + "expression": { + "type": "AssignmentExpression", + "operator": "=", + "left": { + "type": "Identifier", + "name": "lit03", + "decorators": [], + "loc": { + "start": { + "line": 20, + "column": 7, + "program": "literals.ets" + }, + "end": { + "line": 20, + "column": 12, + "program": "literals.ets" + } + } + }, + "right": { + "type": "StringLiteral", + "value": "string", + "loc": { + "start": { + "line": 20, + "column": 15, + "program": "literals.ets" + }, + "end": { + "line": 20, + "column": 23, + "program": "literals.ets" + } + } + }, + "loc": { + "start": { + "line": 20, + "column": 7, + "program": "literals.ets" + }, + "end": { + "line": 20, + "column": 23, + "program": "literals.ets" + } + } + }, + "loc": { + "start": { + "line": 20, + "column": 7, + "program": "literals.ets" + }, + "end": { + "line": 20, + "column": 23, + "program": "literals.ets" + } + } + }, + { + "type": "ExpressionStatement", + "expression": { + "type": "AssignmentExpression", + "operator": "=", + "left": { + "type": "Identifier", + "name": "lit04", + "decorators": [], + "loc": { + "start": { + "line": 21, + "column": 7, + "program": "literals.ets" + }, + "end": { + "line": 21, + "column": 12, + "program": "literals.ets" + } + } + }, + "right": { + "type": "NumberLiteral", + "value": 11, + "loc": { + "start": { + "line": 21, + "column": 15, + "program": "literals.ets" + }, + "end": { + "line": 21, + "column": 21, + "program": "literals.ets" + } + } + }, + "loc": { + "start": { + "line": 21, + "column": 7, + "program": "literals.ets" + }, + "end": { + "line": 21, + "column": 21, + "program": "literals.ets" + } + } + }, + "loc": { + "start": { + "line": 21, + "column": 7, + "program": "literals.ets" + }, + "end": { + "line": 21, + "column": 21, + "program": "literals.ets" + } + } + }, + { + "type": "ExpressionStatement", + "expression": { + "type": "AssignmentExpression", + "operator": "=", + "left": { + "type": "Identifier", + "name": "lit05", + "decorators": [], + "loc": { + "start": { + "line": 22, + "column": 7, + "program": "literals.ets" + }, + "end": { + "line": 22, + "column": 12, + "program": "literals.ets" + } + } + }, + "right": { + "type": "NumberLiteral", + "value": 3.14159, + "loc": { + "start": { + "line": 22, + "column": 15, + "program": "literals.ets" + }, + "end": { + "line": 22, + "column": 24, + "program": "literals.ets" + } + } + }, + "loc": { + "start": { + "line": 22, + "column": 7, + "program": "literals.ets" + }, + "end": { + "line": 22, + "column": 24, + "program": "literals.ets" + } + } + }, + "loc": { + "start": { + "line": 22, + "column": 7, + "program": "literals.ets" + }, + "end": { + "line": 22, + "column": 24, + "program": "literals.ets" + } + } + }, + { + "type": "ExpressionStatement", + "expression": { + "type": "AssignmentExpression", + "operator": "=", + "left": { + "type": "Identifier", + "name": "lit06", + "decorators": [], + "loc": { + "start": { + "line": 23, + "column": 7, + "program": "literals.ets" + }, + "end": { + "line": 23, + "column": 12, + "program": "literals.ets" + } + } + }, + "right": { + "type": "NumberLiteral", + "value": 1e-06, + "loc": { + "start": { + "line": 23, + "column": 15, + "program": "literals.ets" + }, + "end": { + "line": 23, + "column": 21, + "program": "literals.ets" + } + } + }, + "loc": { + "start": { + "line": 23, + "column": 7, + "program": "literals.ets" + }, + "end": { + "line": 23, + "column": 21, + "program": "literals.ets" + } + } + }, + "loc": { + "start": { + "line": 23, + "column": 7, + "program": "literals.ets" + }, + "end": { + "line": 23, + "column": 21, + "program": "literals.ets" + } + } + }, + { + "type": "ExpressionStatement", + "expression": { + "type": "AssignmentExpression", + "operator": "=", + "left": { + "type": "Identifier", + "name": "lit07", + "decorators": [], + "loc": { + "start": { + "line": 24, + "column": 7, + "program": "literals.ets" + }, + "end": { + "line": 24, + "column": 12, + "program": "literals.ets" + } + } + }, + "right": { + "type": "NumberLiteral", + "value": 1e-06, + "loc": { + "start": { + "line": 24, + "column": 15, + "program": "literals.ets" + }, + "end": { + "line": 24, + "column": 21, + "program": "literals.ets" + } + } + }, + "loc": { + "start": { + "line": 24, + "column": 7, + "program": "literals.ets" + }, + "end": { + "line": 24, + "column": 21, + "program": "literals.ets" + } + } + }, + "loc": { + "start": { + "line": 24, + "column": 7, + "program": "literals.ets" + }, + "end": { + "line": 24, + "column": 21, + "program": "literals.ets" + } + } + }, + { + "type": "ExpressionStatement", + "expression": { + "type": "AssignmentExpression", + "operator": "=", + "left": { + "type": "Identifier", + "name": "lit08", + "decorators": [], + "loc": { + "start": { + "line": 25, + "column": 7, + "program": "literals.ets" + }, + "end": { + "line": 25, + "column": 12, + "program": "literals.ets" + } + } + }, + "right": { + "type": "NumberLiteral", + "value": -1e-06, + "loc": { + "start": { + "line": 25, + "column": 15, + "program": "literals.ets" + }, + "end": { + "line": 25, + "column": 22, + "program": "literals.ets" + } + } + }, + "loc": { + "start": { + "line": 25, + "column": 7, + "program": "literals.ets" + }, + "end": { + "line": 25, + "column": 22, + "program": "literals.ets" + } + } + }, + "loc": { + "start": { + "line": 25, + "column": 7, + "program": "literals.ets" + }, + "end": { + "line": 25, + "column": 22, + "program": "literals.ets" + } + } + }, + { + "type": "ExpressionStatement", + "expression": { + "type": "AssignmentExpression", + "operator": "=", + "left": { + "type": "Identifier", + "name": "lit09", + "decorators": [], + "loc": { + "start": { + "line": 26, + "column": 7, + "program": "literals.ets" + }, + "end": { + "line": 26, + "column": 12, + "program": "literals.ets" + } + } + }, + "right": { + "type": "CharLiteral", + "value": "a", + "loc": { + "start": { + "line": 26, + "column": 15, + "program": "literals.ets" + }, + "end": { + "line": 26, + "column": 19, + "program": "literals.ets" + } + } + }, + "loc": { + "start": { + "line": 26, + "column": 7, + "program": "literals.ets" + }, + "end": { + "line": 26, + "column": 19, + "program": "literals.ets" + } + } + }, + "loc": { + "start": { + "line": 26, + "column": 7, + "program": "literals.ets" + }, + "end": { + "line": 26, + "column": 19, + "program": "literals.ets" + } + } + }, + { + "type": "ExpressionStatement", + "expression": { + "type": "AssignmentExpression", + "operator": "=", + "left": { + "type": "Identifier", + "name": "lit10", + "decorators": [], + "loc": { + "start": { + "line": 27, + "column": 7, + "program": "literals.ets" + }, + "end": { + "line": 27, + "column": 12, + "program": "literals.ets" + } + } + }, + "right": { + "type": "CharLiteral", + "value": "a", + "loc": { + "start": { + "line": 27, + "column": 15, + "program": "literals.ets" + }, + "end": { + "line": 27, + "column": 24, + "program": "literals.ets" + } + } + }, + "loc": { + "start": { + "line": 27, + "column": 7, + "program": "literals.ets" + }, + "end": { + "line": 27, + "column": 24, + "program": "literals.ets" + } + } + }, + "loc": { + "start": { + "line": 27, + "column": 7, + "program": "literals.ets" + }, + "end": { + "line": 27, + "column": 24, + "program": "literals.ets" + } + } + }, + { + "type": "ExpressionStatement", + "expression": { + "type": "AssignmentExpression", + "operator": "=", + "left": { + "type": "Identifier", + "name": "lit11", + "decorators": [], + "loc": { + "start": { + "line": 28, + "column": 7, + "program": "literals.ets" + }, + "end": { + "line": 28, + "column": 12, + "program": "literals.ets" + } + } + }, + "right": { + "type": "BooleanLiteral", + "value": true, + "loc": { + "start": { + "line": 28, + "column": 15, + "program": "literals.ets" + }, + "end": { + "line": 28, + "column": 19, + "program": "literals.ets" + } + } + }, + "loc": { + "start": { + "line": 28, + "column": 7, + "program": "literals.ets" + }, + "end": { + "line": 28, + "column": 19, + "program": "literals.ets" + } + } + }, + "loc": { + "start": { + "line": 28, + "column": 7, + "program": "literals.ets" + }, + "end": { + "line": 28, + "column": 19, + "program": "literals.ets" + } + } + }, + { + "type": "ExpressionStatement", + "expression": { + "type": "AssignmentExpression", + "operator": "=", + "left": { + "type": "Identifier", + "name": "lit12", + "decorators": [], + "loc": { + "start": { + "line": 29, + "column": 7, + "program": "literals.ets" + }, + "end": { + "line": 29, + "column": 12, + "program": "literals.ets" + } + } + }, + "right": { + "type": "BooleanLiteral", + "value": false, + "loc": { + "start": { + "line": 29, + "column": 15, + "program": "literals.ets" + }, + "end": { + "line": 29, + "column": 20, + "program": "literals.ets" + } + } + }, + "loc": { + "start": { + "line": 29, + "column": 7, + "program": "literals.ets" + }, + "end": { + "line": 29, + "column": 20, + "program": "literals.ets" + } + } + }, + "loc": { + "start": { + "line": 29, + "column": 7, + "program": "literals.ets" + }, + "end": { + "line": 29, + "column": 20, + "program": "literals.ets" + } + } + }, + { + "type": "ExpressionStatement", + "expression": { + "type": "AssignmentExpression", + "operator": "=", + "left": { + "type": "Identifier", + "name": "lit13", + "decorators": [], + "loc": { + "start": { + "line": 30, + "column": 7, + "program": "literals.ets" + }, + "end": { + "line": 30, + "column": 12, + "program": "literals.ets" + } + } + }, + "right": { + "type": "NullLiteral", + "value": null, + "loc": { + "start": { + "line": 30, + "column": 15, + "program": "literals.ets" + }, + "end": { + "line": 30, + "column": 19, + "program": "literals.ets" + } + } + }, + "loc": { + "start": { + "line": 30, + "column": 7, + "program": "literals.ets" + }, + "end": { + "line": 30, + "column": 19, + "program": "literals.ets" + } + } + }, + "loc": { + "start": { + "line": 30, + "column": 7, + "program": "literals.ets" + }, + "end": { + "line": 30, + "column": 19, + "program": "literals.ets" + } + } + }, + { + "type": "ExpressionStatement", + "expression": { + "type": "AssignmentExpression", + "operator": "=", + "left": { + "type": "Identifier", + "name": "lit14", + "decorators": [], + "loc": { + "start": { + "line": 31, + "column": 7, + "program": "literals.ets" + }, + "end": { + "line": 31, + "column": 12, + "program": "literals.ets" + } + } + }, + "right": { + "type": "NumberLiteral", + "value": 123.45, + "loc": { + "start": { + "line": 31, + "column": 15, + "program": "literals.ets" + }, + "end": { + "line": 31, + "column": 22, + "program": "literals.ets" + } + } + }, + "loc": { + "start": { + "line": 31, + "column": 7, + "program": "literals.ets" + }, + "end": { + "line": 31, + "column": 22, + "program": "literals.ets" + } + } + }, + "loc": { + "start": { + "line": 31, + "column": 7, + "program": "literals.ets" + }, + "end": { + "line": 31, + "column": 22, + "program": "literals.ets" + } + } + }, + { + "type": "ExpressionStatement", + "expression": { + "type": "AssignmentExpression", + "operator": "=", + "left": { + "type": "Identifier", + "name": "lit15", + "decorators": [], + "loc": { + "start": { + "line": 32, + "column": 7, + "program": "literals.ets" + }, + "end": { + "line": 32, + "column": 12, + "program": "literals.ets" + } + } + }, + "right": { + "type": "NumberLiteral", + "value": 1.2345e+12, + "loc": { + "start": { + "line": 32, + "column": 15, + "program": "literals.ets" + }, + "end": { + "line": 32, + "column": 25, + "program": "literals.ets" + } + } + }, + "loc": { + "start": { + "line": 32, + "column": 7, + "program": "literals.ets" + }, + "end": { + "line": 32, + "column": 25, + "program": "literals.ets" + } + } + }, + "loc": { + "start": { + "line": 32, + "column": 7, + "program": "literals.ets" + }, + "end": { + "line": 32, + "column": 25, + "program": "literals.ets" + } + } + }, + { + "type": "ExpressionStatement", + "expression": { + "type": "AssignmentExpression", + "operator": "=", + "left": { + "type": "Identifier", + "name": "lit16", + "decorators": [], + "loc": { + "start": { + "line": 33, + "column": 7, + "program": "literals.ets" + }, + "end": { + "line": 33, + "column": 12, + "program": "literals.ets" + } + } + }, + "right": { + "type": "NumberLiteral", + "value": -123.45, + "loc": { + "start": { + "line": 33, + "column": 15, + "program": "literals.ets" + }, + "end": { + "line": 33, + "column": 23, + "program": "literals.ets" + } + } + }, + "loc": { + "start": { + "line": 33, + "column": 7, + "program": "literals.ets" + }, + "end": { + "line": 33, + "column": 23, + "program": "literals.ets" + } + } + }, + "loc": { + "start": { + "line": 33, + "column": 7, + "program": "literals.ets" + }, + "end": { + "line": 33, + "column": 23, + "program": "literals.ets" + } + } + }, + { + "type": "ExpressionStatement", + "expression": { + "type": "AssignmentExpression", + "operator": "=", + "left": { + "type": "Identifier", + "name": "lit17", + "decorators": [], + "loc": { + "start": { + "line": 34, + "column": 7, + "program": "literals.ets" + }, + "end": { + "line": 34, + "column": 12, + "program": "literals.ets" + } + } + }, + "right": { + "type": "NumberLiteral", + "value": -1.2345e+12, + "loc": { + "start": { + "line": 34, + "column": 15, + "program": "literals.ets" + }, + "end": { + "line": 34, + "column": 26, + "program": "literals.ets" + } + } + }, + "loc": { + "start": { + "line": 34, + "column": 7, + "program": "literals.ets" + }, + "end": { + "line": 34, + "column": 26, + "program": "literals.ets" + } + } + }, + "loc": { + "start": { + "line": 34, + "column": 7, + "program": "literals.ets" + }, + "end": { + "line": 34, + "column": 26, + "program": "literals.ets" + } + } + }, + { + "type": "ExpressionStatement", + "expression": { + "type": "AssignmentExpression", + "operator": "=", + "left": { + "type": "Identifier", + "name": "lit18", + "decorators": [], + "loc": { + "start": { + "line": 35, + "column": 7, + "program": "literals.ets" + }, + "end": { + "line": 35, + "column": 12, + "program": "literals.ets" + } + } + }, + "right": { + "type": "ArrayExpression", + "elements": [], + "loc": { + "start": { + "line": 35, + "column": 15, + "program": "literals.ets" + }, + "end": { + "line": 35, + "column": 17, + "program": "literals.ets" + } + } + }, + "loc": { + "start": { + "line": 35, + "column": 7, + "program": "literals.ets" + }, + "end": { + "line": 35, + "column": 17, + "program": "literals.ets" + } + } + }, + "loc": { + "start": { + "line": 35, + "column": 7, + "program": "literals.ets" + }, + "end": { + "line": 35, + "column": 17, + "program": "literals.ets" + } + } + }, + { + "type": "ExpressionStatement", + "expression": { + "type": "AssignmentExpression", + "operator": "=", + "left": { + "type": "Identifier", + "name": "lit19", + "decorators": [], + "loc": { + "start": { + "line": 36, + "column": 7, + "program": "literals.ets" + }, + "end": { + "line": 36, + "column": 12, + "program": "literals.ets" + } + } + }, + "right": { + "type": "ArrayExpression", + "elements": [ + { + "type": "NumberLiteral", + "value": 1, + "loc": { + "start": { + "line": 36, + "column": 16, + "program": "literals.ets" + }, + "end": { + "line": 36, + "column": 17, + "program": "literals.ets" + } + } + }, + { + "type": "NumberLiteral", + "value": 2, + "loc": { + "start": { + "line": 36, + "column": 18, + "program": "literals.ets" + }, + "end": { + "line": 36, + "column": 19, + "program": "literals.ets" + } + } + }, + { + "type": "NumberLiteral", + "value": 3, + "loc": { + "start": { + "line": 36, + "column": 20, + "program": "literals.ets" + }, + "end": { + "line": 36, + "column": 21, + "program": "literals.ets" + } + } + } + ], + "loc": { + "start": { + "line": 36, + "column": 15, + "program": "literals.ets" + }, + "end": { + "line": 36, + "column": 22, + "program": "literals.ets" + } + } + }, + "loc": { + "start": { + "line": 36, + "column": 7, + "program": "literals.ets" + }, + "end": { + "line": 36, + "column": 22, + "program": "literals.ets" + } + } + }, + "loc": { + "start": { + "line": 36, + "column": 7, + "program": "literals.ets" + }, + "end": { + "line": 36, + "column": 22, + "program": "literals.ets" + } + } + }, + { + "type": "ExpressionStatement", + "expression": { + "type": "AssignmentExpression", + "operator": "=", + "left": { + "type": "Identifier", + "name": "lit20", + "decorators": [], + "loc": { + "start": { + "line": 37, + "column": 7, + "program": "literals.ets" + }, + "end": { + "line": 37, + "column": 12, + "program": "literals.ets" + } + } + }, + "right": { + "type": "ArrayExpression", + "elements": [ + { + "type": "StringLiteral", + "value": "1", + "loc": { + "start": { + "line": 37, + "column": 16, + "program": "literals.ets" + }, + "end": { + "line": 37, + "column": 19, + "program": "literals.ets" + } + } + }, + { + "type": "StringLiteral", + "value": "2", + "loc": { + "start": { + "line": 37, + "column": 20, + "program": "literals.ets" + }, + "end": { + "line": 37, + "column": 23, + "program": "literals.ets" + } + } + }, + { + "type": "StringLiteral", + "value": "3", + "loc": { + "start": { + "line": 37, + "column": 24, + "program": "literals.ets" + }, + "end": { + "line": 37, + "column": 27, + "program": "literals.ets" + } + } + } + ], + "loc": { + "start": { + "line": 37, + "column": 15, + "program": "literals.ets" + }, + "end": { + "line": 37, + "column": 28, + "program": "literals.ets" + } + } + }, + "loc": { + "start": { + "line": 37, + "column": 7, + "program": "literals.ets" + }, + "end": { + "line": 37, + "column": 28, + "program": "literals.ets" + } + } + }, + "loc": { + "start": { + "line": 37, + "column": 7, + "program": "literals.ets" + }, + "end": { + "line": 37, + "column": 28, + "program": "literals.ets" + } + } + }, + { + "type": "ExpressionStatement", + "expression": { + "type": "AssignmentExpression", + "operator": "=", + "left": { + "type": "Identifier", + "name": "lit21", + "decorators": [], + "loc": { + "start": { + "line": 38, + "column": 7, + "program": "literals.ets" + }, + "end": { + "line": 38, + "column": 12, + "program": "literals.ets" + } + } + }, + "right": { + "type": "ArrayExpression", + "elements": [ + { + "type": "NumberLiteral", + "value": 1, + "loc": { + "start": { + "line": 38, + "column": 16, + "program": "literals.ets" + }, + "end": { + "line": 38, + "column": 19, + "program": "literals.ets" + } + } + }, + { + "type": "NumberLiteral", + "value": 2, + "loc": { + "start": { + "line": 38, + "column": 20, + "program": "literals.ets" + }, + "end": { + "line": 38, + "column": 23, + "program": "literals.ets" + } + } + }, + { + "type": "NumberLiteral", + "value": 3, + "loc": { + "start": { + "line": 38, + "column": 24, + "program": "literals.ets" + }, + "end": { + "line": 38, + "column": 27, + "program": "literals.ets" + } + } + } + ], + "loc": { + "start": { + "line": 38, + "column": 15, + "program": "literals.ets" + }, + "end": { + "line": 38, + "column": 28, + "program": "literals.ets" + } + } + }, + "loc": { + "start": { + "line": 38, + "column": 7, + "program": "literals.ets" + }, + "end": { + "line": 38, + "column": 28, + "program": "literals.ets" + } + } + }, + "loc": { + "start": { + "line": 38, + "column": 7, + "program": "literals.ets" + }, + "end": { + "line": 38, + "column": 28, + "program": "literals.ets" + } + } + } + ], "loc": { "start": { "line": 1, diff --git a/ets2panda/test/parser/ets/null_valid-expected.txt b/ets2panda/test/parser/ets/null_valid-expected.txt index f4d0b80cdb..54574e7bad 100644 --- a/ets2panda/test/parser/ets/null_valid-expected.txt +++ b/ets2panda/test/parser/ets/null_valid-expected.txt @@ -182,6 +182,70 @@ "body": { "type": "BlockStatement", "statements": [ + { + "type": "ExpressionStatement", + "expression": { + "type": "AssignmentExpression", + "operator": "=", + "left": { + "type": "Identifier", + "name": "n", + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 7, + "program": "null_valid.ets" + }, + "end": { + "line": 16, + "column": 8, + "program": "null_valid.ets" + } + } + }, + "right": { + "type": "NullLiteral", + "value": null, + "loc": { + "start": { + "line": 16, + "column": 11, + "program": "null_valid.ets" + }, + "end": { + "line": 16, + "column": 15, + "program": "null_valid.ets" + } + } + }, + "loc": { + "start": { + "line": 16, + "column": 7, + "program": "null_valid.ets" + }, + "end": { + "line": 16, + "column": 15, + "program": "null_valid.ets" + } + } + }, + "loc": { + "start": { + "line": 16, + "column": 7, + "program": "null_valid.ets" + }, + "end": { + "line": 16, + "column": 15, + "program": "null_valid.ets" + } + } + }, { "type": "ExpressionStatement", "expression": { diff --git a/ets2panda/test/parser/ets/tupleIndexWithNumbers-expected.txt b/ets2panda/test/parser/ets/tupleIndexWithNumbers-expected.txt index f72997ce91..b060c514ff 100644 --- a/ets2panda/test/parser/ets/tupleIndexWithNumbers-expected.txt +++ b/ets2panda/test/parser/ets/tupleIndexWithNumbers-expected.txt @@ -75,7 +75,136 @@ "params": [], "body": { "type": "BlockStatement", - "statements": [], + "statements": [ + { + "type": "ExpressionStatement", + "expression": { + "type": "AssignmentExpression", + "operator": "=", + "left": { + "type": "Identifier", + "name": "index1", + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 7, + "program": "tupleIndexWithNumbers.ets" + }, + "end": { + "line": 16, + "column": 13, + "program": "tupleIndexWithNumbers.ets" + } + } + }, + "right": { + "type": "NumberLiteral", + "value": 1, + "loc": { + "start": { + "line": 16, + "column": 21, + "program": "tupleIndexWithNumbers.ets" + }, + "end": { + "line": 16, + "column": 22, + "program": "tupleIndexWithNumbers.ets" + } + } + }, + "loc": { + "start": { + "line": 16, + "column": 7, + "program": "tupleIndexWithNumbers.ets" + }, + "end": { + "line": 16, + "column": 22, + "program": "tupleIndexWithNumbers.ets" + } + } + }, + "loc": { + "start": { + "line": 16, + "column": 7, + "program": "tupleIndexWithNumbers.ets" + }, + "end": { + "line": 16, + "column": 22, + "program": "tupleIndexWithNumbers.ets" + } + } + }, + { + "type": "ExpressionStatement", + "expression": { + "type": "AssignmentExpression", + "operator": "=", + "left": { + "type": "Identifier", + "name": "index2", + "decorators": [], + "loc": { + "start": { + "line": 17, + "column": 7, + "program": "tupleIndexWithNumbers.ets" + }, + "end": { + "line": 17, + "column": 13, + "program": "tupleIndexWithNumbers.ets" + } + } + }, + "right": { + "type": "NumberLiteral", + "value": 1, + "loc": { + "start": { + "line": 17, + "column": 22, + "program": "tupleIndexWithNumbers.ets" + }, + "end": { + "line": 17, + "column": 23, + "program": "tupleIndexWithNumbers.ets" + } + } + }, + "loc": { + "start": { + "line": 17, + "column": 7, + "program": "tupleIndexWithNumbers.ets" + }, + "end": { + "line": 17, + "column": 23, + "program": "tupleIndexWithNumbers.ets" + } + } + }, + "loc": { + "start": { + "line": 17, + "column": 7, + "program": "tupleIndexWithNumbers.ets" + }, + "end": { + "line": 17, + "column": 23, + "program": "tupleIndexWithNumbers.ets" + } + } + } + ], "loc": { "start": { "line": 1, diff --git a/ets2panda/test/parser/ets/type_variance1-expected.txt b/ets2panda/test/parser/ets/type_variance1-expected.txt index d129a48009..1079702a49 100644 --- a/ets2panda/test/parser/ets/type_variance1-expected.txt +++ b/ets2panda/test/parser/ets/type_variance1-expected.txt @@ -2163,7 +2163,247 @@ "params": [], "body": { "type": "BlockStatement", - "statements": [], + "statements": [ + { + "type": "ExpressionStatement", + "expression": { + "type": "AssignmentExpression", + "operator": "=", + "left": { + "type": "Identifier", + "name": "C_GLOBAL", + "decorators": [], + "loc": { + "start": { + "line": 20, + "column": 7, + "program": "type_variance1.ets" + }, + "end": { + "line": 20, + "column": 15, + "program": "type_variance1.ets" + } + } + }, + "right": { + "type": "ETSNewClassInstanceExpression", + "typeReference": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "C", + "decorators": [], + "loc": { + "start": { + "line": 20, + "column": 35, + "program": "type_variance1.ets" + }, + "end": { + "line": 20, + "column": 36, + "program": "type_variance1.ets" + } + } + }, + "typeParams": { + "type": "TSTypeParameterInstantiation", + "params": [ + { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Array", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1, + "program": "type_variance1.ets" + }, + "end": { + "line": 1, + "column": 3, + "program": "type_variance1.ets" + } + } + }, + "typeParams": { + "type": "TSTypeParameterInstantiation", + "params": [ + { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Object", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 3, + "program": "type_variance1.ets" + }, + "end": { + "line": 1, + "column": 3, + "program": "type_variance1.ets" + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 3, + "program": "type_variance1.ets" + }, + "end": { + "line": 1, + "column": 3, + "program": "type_variance1.ets" + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 3, + "program": "type_variance1.ets" + }, + "end": { + "line": 1, + "column": 3, + "program": "type_variance1.ets" + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 3, + "program": "type_variance1.ets" + }, + "end": { + "line": 1, + "column": 3, + "program": "type_variance1.ets" + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1, + "program": "type_variance1.ets" + }, + "end": { + "line": 1, + "column": 3, + "program": "type_variance1.ets" + } + } + }, + "loc": { + "start": { + "line": 20, + "column": 43, + "program": "type_variance1.ets" + }, + "end": { + "line": 20, + "column": 45, + "program": "type_variance1.ets" + } + } + } + ], + "loc": { + "start": { + "line": 20, + "column": 36, + "program": "type_variance1.ets" + }, + "end": { + "line": 20, + "column": 46, + "program": "type_variance1.ets" + } + } + }, + "loc": { + "start": { + "line": 20, + "column": 35, + "program": "type_variance1.ets" + }, + "end": { + "line": 20, + "column": 47, + "program": "type_variance1.ets" + } + } + }, + "loc": { + "start": { + "line": 20, + "column": 35, + "program": "type_variance1.ets" + }, + "end": { + "line": 20, + "column": 47, + "program": "type_variance1.ets" + } + } + }, + "arguments": [], + "loc": { + "start": { + "line": 20, + "column": 31, + "program": "type_variance1.ets" + }, + "end": { + "line": 20, + "column": 49, + "program": "type_variance1.ets" + } + } + }, + "loc": { + "start": { + "line": 20, + "column": 7, + "program": "type_variance1.ets" + }, + "end": { + "line": 20, + "column": 49, + "program": "type_variance1.ets" + } + } + }, + "loc": { + "start": { + "line": 20, + "column": 7, + "program": "type_variance1.ets" + }, + "end": { + "line": 20, + "column": 49, + "program": "type_variance1.ets" + } + } + } + ], "loc": { "start": { "line": 1, diff --git a/ets2panda/test/parser/ets/unary_op-expected.txt b/ets2panda/test/parser/ets/unary_op-expected.txt index 10516d0b64..66a9fa021c 100644 --- a/ets2panda/test/parser/ets/unary_op-expected.txt +++ b/ets2panda/test/parser/ets/unary_op-expected.txt @@ -801,6 +801,70 @@ } } }, + { + "type": "ExpressionStatement", + "expression": { + "type": "AssignmentExpression", + "operator": "=", + "left": { + "type": "Identifier", + "name": "i", + "decorators": [], + "loc": { + "start": { + "line": 24, + "column": 7, + "program": "unary_op.ets" + }, + "end": { + "line": 24, + "column": 8, + "program": "unary_op.ets" + } + } + }, + "right": { + "type": "BooleanLiteral", + "value": true, + "loc": { + "start": { + "line": 24, + "column": 11, + "program": "unary_op.ets" + }, + "end": { + "line": 24, + "column": 15, + "program": "unary_op.ets" + } + } + }, + "loc": { + "start": { + "line": 24, + "column": 7, + "program": "unary_op.ets" + }, + "end": { + "line": 24, + "column": 15, + "program": "unary_op.ets" + } + } + }, + "loc": { + "start": { + "line": 24, + "column": 7, + "program": "unary_op.ets" + }, + "end": { + "line": 24, + "column": 15, + "program": "unary_op.ets" + } + } + }, { "type": "ExpressionStatement", "expression": { diff --git a/ets2panda/test/runtime/ets/lambda_inner_call_static_method.ets b/ets2panda/test/runtime/ets/lambda_inner_call_static_method.ets index 5214be0372..b3c0a605e2 100644 --- a/ets2panda/test/runtime/ets/lambda_inner_call_static_method.ets +++ b/ets2panda/test/runtime/ets/lambda_inner_call_static_method.ets @@ -15,7 +15,7 @@ function foo(callback: () => string) { } -const bar = (): string => { +const bar: () => string = (): string => { return A.fob(); } diff --git a/ets2panda/test/runtime/ets/topLevelInitOrder/topLevelInit1.ets b/ets2panda/test/runtime/ets/topLevelInitOrder/topLevelInit1.ets new file mode 100644 index 0000000000..dcce7c3868 --- /dev/null +++ b/ets2panda/test/runtime/ets/topLevelInitOrder/topLevelInit1.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. + */ + +class A { } + +class B { } + +let a: A = new A() + +let b: B = new B() + +const c: [A, B] = [a, b]; + +function main() { + assertEQ(c[0], a) + assertEQ(c[1], b) +} + diff --git a/ets2panda/test/runtime/ets/topLevelInitOrder/topLevelInit2.ets b/ets2panda/test/runtime/ets/topLevelInitOrder/topLevelInit2.ets new file mode 100644 index 0000000000..35ed39814b --- /dev/null +++ b/ets2panda/test/runtime/ets/topLevelInitOrder/topLevelInit2.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. + */ + +class A { } + +class B { } + +let a: A = new A() + +let b: B = new B() + +const c: [Object, Object] = [a, b]; + +let d = c; + +function main() { + assertEQ(c[0], a) + assertEQ(c[1], b) + + assertEQ(d[0], a) + assertEQ(d[1], b) +} + diff --git a/ets2panda/test/runtime/ets/topLevelInitOrder/topLevelInit_Lambda.ets b/ets2panda/test/runtime/ets/topLevelInitOrder/topLevelInit_Lambda.ets new file mode 100644 index 0000000000..fb1cae5f8d --- /dev/null +++ b/ets2panda/test/runtime/ets/topLevelInitOrder/topLevelInit_Lambda.ets @@ -0,0 +1,23 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + +let x = (s: string)=>{ + return s; +} + +function main() { + assertEQ(x("hello"), "hello"); +} diff --git a/ets2panda/test/unit/lsp/get_diagnostics.cpp b/ets2panda/test/unit/lsp/get_diagnostics.cpp index bfb46178f1..0c9b1d6815 100644 --- a/ets2panda/test/unit/lsp/get_diagnostics.cpp +++ b/ets2panda/test/unit/lsp/get_diagnostics.cpp @@ -51,31 +51,32 @@ add("1", 2);)"); initializer.DestroyContext(ctx); auto const expectedErrorCount = 3; ASSERT_EQ(result.diagnostic.size(), expectedErrorCount); - auto const thirdIndex = 2; + auto const firstIndex = 0; auto const expectedFirstStartLine = 1; auto const expectedFirstStartCharacter = 19; auto const expectedFirstEndLine = 1; auto const expectedFirstEndCharacter = 26; - ASSERT_EQ(result.diagnostic[thirdIndex].range_.start.line_, expectedFirstStartLine); - ASSERT_EQ(result.diagnostic[thirdIndex].range_.start.character_, expectedFirstStartCharacter); - ASSERT_EQ(result.diagnostic[thirdIndex].range_.end.line_, expectedFirstEndLine); - ASSERT_EQ(result.diagnostic[thirdIndex].range_.end.character_, expectedFirstEndCharacter); - ASSERT_EQ(result.diagnostic[thirdIndex].severity_, DiagnosticSeverity::Error); - ASSERT_EQ(std::get(result.diagnostic[thirdIndex].code_), 1); - ASSERT_EQ(result.diagnostic[thirdIndex].message_, R"(Type '"hello"' cannot be assigned to type 'double')"); - ASSERT_EQ(result.diagnostic[thirdIndex].codeDescription_.href_, "test code description"); + ASSERT_EQ(result.diagnostic[firstIndex].range_.start.line_, expectedFirstStartLine); + ASSERT_EQ(result.diagnostic[firstIndex].range_.start.character_, expectedFirstStartCharacter); + ASSERT_EQ(result.diagnostic[firstIndex].range_.end.line_, expectedFirstEndLine); + ASSERT_EQ(result.diagnostic[firstIndex].range_.end.character_, expectedFirstEndCharacter); + ASSERT_EQ(result.diagnostic[firstIndex].severity_, DiagnosticSeverity::Error); + ASSERT_EQ(std::get(result.diagnostic[firstIndex].code_), 1); + ASSERT_EQ(result.diagnostic[firstIndex].message_, R"(Type '"hello"' cannot be assigned to type 'double')"); + ASSERT_EQ(result.diagnostic[firstIndex].codeDescription_.href_, "test code description"); + auto const thirdIndex = 2; auto const expectedSecondStartLine = 5; auto const expectedSecondStartCharacter = 5; auto const expectedSecondEndLine = 5; auto const expectedSecondEndCharacter = 8; - ASSERT_EQ(result.diagnostic[0].range_.start.line_, expectedSecondStartLine); - ASSERT_EQ(result.diagnostic[0].range_.start.character_, expectedSecondStartCharacter); - ASSERT_EQ(result.diagnostic[0].range_.end.line_, expectedSecondEndLine); - ASSERT_EQ(result.diagnostic[0].range_.end.character_, expectedSecondEndCharacter); - ASSERT_EQ(result.diagnostic[0].severity_, DiagnosticSeverity::Error); - ASSERT_EQ(std::get(result.diagnostic[0].code_), 1); - ASSERT_EQ(result.diagnostic[0].message_, R"(Type '"1"' is not compatible with type 'double' at index 1)"); - ASSERT_EQ(result.diagnostic[0].codeDescription_.href_, "test code description"); + ASSERT_EQ(result.diagnostic[thirdIndex].range_.start.line_, expectedSecondStartLine); + ASSERT_EQ(result.diagnostic[thirdIndex].range_.start.character_, expectedSecondStartCharacter); + ASSERT_EQ(result.diagnostic[thirdIndex].range_.end.line_, expectedSecondEndLine); + ASSERT_EQ(result.diagnostic[thirdIndex].range_.end.character_, expectedSecondEndCharacter); + ASSERT_EQ(result.diagnostic[thirdIndex].severity_, DiagnosticSeverity::Error); + ASSERT_EQ(std::get(result.diagnostic[thirdIndex].code_), 1); + ASSERT_EQ(result.diagnostic[thirdIndex].message_, R"(Type '"1"' is not compatible with type 'double' at index 1)"); + ASSERT_EQ(result.diagnostic[thirdIndex].codeDescription_.href_, "test code description"); } TEST_F(LspDiagnosticsTests, GetSyntacticDiagnostics1) @@ -105,7 +106,7 @@ let res = add(n, n);)"); LSPAPI const *lspApi = GetImpl(); auto result = lspApi->getSyntacticDiagnostics(ctx); initializer.DestroyContext(ctx); - auto const expectedErrorCount = 13; + auto const expectedErrorCount = 10; ASSERT_EQ(result.diagnostic.size(), expectedErrorCount); auto const expectedFirstStartLine = 1; auto const expectedFirstStartCharacter = 9; @@ -153,7 +154,7 @@ let res = add(n, n);)"); LSPAPI const *lspApi = GetImpl(); auto result = lspApi->getSyntacticDiagnostics(ctx); initializer.DestroyContext(ctx); - auto const forthIndex = 5; + auto const forthIndex = 4; auto const expectedForthStartLine = 1; auto const expectedForthStartCharacter = 22; auto const expectedForthEndLine = 1; @@ -166,7 +167,7 @@ let res = add(n, n);)"); ASSERT_EQ(std::get(result.diagnostic[forthIndex].code_), 1); ASSERT_EQ(result.diagnostic[forthIndex].message_, R"(Unexpected token ','.)"); ASSERT_EQ(result.diagnostic[forthIndex].codeDescription_.href_, "test code description"); - auto const fifthIndex = 8; + auto const fifthIndex = 6; auto const expectedFifththStartLine = 1; auto const expectedFifthStartCharacter = 27; auto const expectedFifthEndLine = 1; @@ -193,7 +194,7 @@ let res = add(n, n);)"); LSPAPI const *lspApi = GetImpl(); auto result = lspApi->getSyntacticDiagnostics(ctx); initializer.DestroyContext(ctx); - auto const sixthIndex = 9; + auto const sixthIndex = 7; auto const expectedSixthStartLine = 1; auto const expectedSixthStartCharacter = 33; auto const expectedSixthEndLine = 1; @@ -206,7 +207,7 @@ let res = add(n, n);)"); ASSERT_EQ(std::get(result.diagnostic[sixthIndex].code_), 1); ASSERT_EQ(result.diagnostic[sixthIndex].message_, R"(Unexpected token ')'.)"); ASSERT_EQ(result.diagnostic[sixthIndex].codeDescription_.href_, "test code description"); - auto const sevenIndex = 12; + auto const sevenIndex = 9; auto const expectedSeventhStartLine = 2; auto const expectedSeventhStartCharacter = 5; auto const expectedSeventhEndLine = 2; diff --git a/ets2panda/test/unit/lsp/inlay_hints_test.cpp b/ets2panda/test/unit/lsp/inlay_hints_test.cpp index 91d7532bef..3e33e384f0 100644 --- a/ets2panda/test/unit/lsp/inlay_hints_test.cpp +++ b/ets2panda/test/unit/lsp/inlay_hints_test.cpp @@ -213,8 +213,8 @@ TEST_F(LSPInlayHintsTests, VisitFunctionDeclarationLikeForReturnTypeTest1) )"}; const std::string doubleString = "double"; - const size_t addIndex = 89; - const size_t multiplyIndex = 186; + const size_t addIndex = 186; + const size_t multiplyIndex = 89; const size_t i0 = 0; const size_t i1 = 1; const size_t i2 = 2; @@ -257,8 +257,8 @@ TEST_F(LSPInlayHintsTests, VisitFunctionDeclarationLikeForReturnTypeTest2) const std::string voidString = "void"; const std::string stdString = "String"; - const size_t greetIndex = 95; - const size_t sayHelloIndex = 179; + const size_t greetIndex = 179; + const size_t sayHelloIndex = 95; const size_t i0 = 0; const size_t i1 = 1; const size_t i2 = 2; @@ -280,9 +280,9 @@ TEST_F(LSPInlayHintsTests, VisitFunctionDeclarationLikeForReturnTypeTest2) } return false; }); - ASSERT_EQ(result.hints[i2].text, stdString); + ASSERT_EQ(result.hints[i2].text, voidString); ASSERT_EQ(result.hints[i2].number, greetIndex); - ASSERT_EQ(result.hints[i3].text, voidString); + ASSERT_EQ(result.hints[i3].text, stdString); ASSERT_EQ(result.hints[i3].number, sayHelloIndex); initializer.DestroyContext(ctx); } diff --git a/ets2panda/test/unit/lsp/isolated_declaration.cpp b/ets2panda/test/unit/lsp/isolated_declaration.cpp index 5a0f1c776b..290072080a 100644 --- a/ets2panda/test/unit/lsp/isolated_declaration.cpp +++ b/ets2panda/test/unit/lsp/isolated_declaration.cpp @@ -137,7 +137,7 @@ export const foo = () => { return childNode->IsIdentifier() && childNode->AsIdentifier()->Name() == "foo"; }); auto textChange = ark::es2panda::lsp::ProcessIdentifier(id->AsIdentifier(), checker, ctx->parserProgram); - const size_t expectedStart = 70; + const size_t expectedStart = 67; ASSERT_EQ(textChange.has_value(), true); ASSERT_EQ(textChange.value().newText, ": number | string"); ASSERT_EQ(textChange.value().span.start, expectedStart); diff --git a/ets2panda/util/diagnosticEngine.cpp b/ets2panda/util/diagnosticEngine.cpp index 9660f1f160..5d4f66e12d 100644 --- a/ets2panda/util/diagnosticEngine.cpp +++ b/ets2panda/util/diagnosticEngine.cpp @@ -32,6 +32,15 @@ void CLIDiagnosticPrinter::Print(const DiagnosticBase &diagnostic) const std::cout << std::endl; } +void DiagnosticEngine::CleanDuplicateLog(DiagnosticType type) +{ + DiagnosticStorage &log = diagnostics_[type]; + std::sort(log.begin(), log.end(), [](const auto &lhs, const auto &rhs) { return *lhs < *rhs; }); + auto last = + std::unique(log.begin(), log.end(), [&](const auto &rhs, const auto &lhs) -> bool { return *rhs == *lhs; }); + log.resize(std::distance(log.begin(), last)); +} + const DiagnosticStorage &DiagnosticEngine::GetDiagnosticStorage(DiagnosticType type) { return diagnostics_[type]; diff --git a/ets2panda/util/diagnosticEngine.h b/ets2panda/util/diagnosticEngine.h index a013fc7a71..d2ad68446a 100644 --- a/ets2panda/util/diagnosticEngine.h +++ b/ets2panda/util/diagnosticEngine.h @@ -131,6 +131,8 @@ public: wError_ = wError; } + void CleanDuplicateLog(DiagnosticType type); + const DiagnosticStorage &GetDiagnosticStorage(DiagnosticType type); static void InitializeSignalHandlers(); -- Gitee