diff --git a/ets2panda/checker/ETSAnalyzer.cpp b/ets2panda/checker/ETSAnalyzer.cpp index c52f3f348262fc97c954a998da416d2b77580569..5b96302007c316a77e837e4e39907c817ecfd108 100644 --- a/ets2panda/checker/ETSAnalyzer.cpp +++ b/ets2panda/checker/ETSAnalyzer.cpp @@ -2547,16 +2547,17 @@ checker::Type *ETSAnalyzer::Check(ir::TSQualifiedName *expr) const { ETSChecker *checker = GetETSChecker(); checker::Type *baseType = expr->Left()->Check(checker); - if (baseType->IsETSObjectType()) { - varbinder::Variable *prop = + varbinder::Variable *prop {}; + if (baseType->IsETSDynamicType()) { + prop = baseType->AsETSDynamicType()->GetPropertyDynamic(expr->Right()->Name(), checker); + } else if (baseType->IsETSObjectType()) { + prop = baseType->AsETSObjectType()->GetProperty(expr->Right()->Name(), checker::PropertySearchFlags::SEARCH_DECL); - - if (prop != nullptr) { - return checker->GetTypeOfVariable(prop); - } } - - checker->ThrowTypeError({"'", expr->Right()->Name(), "' type does not exist."}, expr->Right()->Start()); + if (prop == nullptr) { + checker->ThrowTypeError({"'", expr->Right()->Name(), "' type does not exist."}, expr->Right()->Start()); + } + return checker->GetTypeOfVariable(prop); } checker::Type *ETSAnalyzer::Check([[maybe_unused]] ir::TSStringKeyword *node) const diff --git a/ets2panda/checker/ETSchecker.h b/ets2panda/checker/ETSchecker.h index c512dfb6581254cad68adecaa950753e682689b4..a98b5fcbeafa366e7acc5102308d75c1b9ef2178 100644 --- a/ets2panda/checker/ETSchecker.h +++ b/ets2panda/checker/ETSchecker.h @@ -460,7 +460,7 @@ public: ir::ETSImportDeclaration *importDecl = nullptr); void SetrModuleObjectTsType(ir::Identifier *local, checker::ETSObjectType *moduleObjType); Type *GetReferencedTypeFromBase(Type *baseType, ir::Expression *name); - Type *GetReferencedTypeBase(ir::Expression *name); + Type *GetReferencedTypeBase(ir::Expression *name, bool allowDynamic); Type *GetTypeFromInterfaceReference(varbinder::Variable *var); Type *GetTypeFromTypeAliasReference(varbinder::Variable *var); Type *GetTypeFromClassReference(varbinder::Variable *var); diff --git a/ets2panda/checker/ets/helpers.cpp b/ets2panda/checker/ets/helpers.cpp index a5ee1b3bb6ff005731b7531befac3be4691473af..4072319325bb339c1a092b324364dac8bc91bc9b 100644 --- a/ets2panda/checker/ets/helpers.cpp +++ b/ets2panda/checker/ets/helpers.cpp @@ -1069,7 +1069,7 @@ Type *ETSChecker::HandleTypeAlias(ir::Expression *const name, const ir::TSTypePa if (typeParams == nullptr) { // SUPPRESS_CSA_NEXTLINE(alpha.core.AllocatorETSCheckerHint) - return GetReferencedTypeBase(name); + return GetReferencedTypeBase(name, false); } for (auto *const origTypeParam : typeParams->Params()) { @@ -1077,7 +1077,7 @@ Type *ETSChecker::HandleTypeAlias(ir::Expression *const name, const ir::TSTypePa } // SUPPRESS_CSA_NEXTLINE(alpha.core.AllocatorETSCheckerHint) - Type *const aliasType = GetReferencedTypeBase(name); + Type *const aliasType = GetReferencedTypeBase(name, false); auto *const aliasSub = NewSubstitution(); if (typeAliasNode->TypeParams()->Params().size() != typeParams->Params().size()) { @@ -1193,19 +1193,30 @@ Type *ETSChecker::GetReferencedTypeFromBase([[maybe_unused]] Type *baseType, [[m return nullptr; } -Type *ETSChecker::GetReferencedTypeBase(ir::Expression *name) +Type *ETSChecker::GetReferencedTypeBase(ir::Expression *name, bool allowDynamic) { if (name->IsTSQualifiedName()) { auto *qualified = name->AsTSQualifiedName(); return qualified->Check(this); } - ASSERT(name->IsIdentifier() && name->AsIdentifier()->Variable() != nullptr); + bool isIdentWithVar = name->IsIdentifier() && name->AsIdentifier()->Variable() != nullptr; + // NOTE: for dynamic expression identifiers have no variable yet + // if there is variable in identifier it means it is not dynamic one + ASSERT(allowDynamic || isIdentWithVar); - // NOTE: kbaladurin. forbid usage imported entities as types without declarations - auto *importData = VarBinder()->AsETSBinder()->DynamicImportDataForVar(name->AsIdentifier()->Variable()); - if (importData != nullptr && importData->import->IsPureDynamic()) { - return GlobalBuiltinDynamicType(importData->import->Language()); + if (allowDynamic && !isIdentWithVar) { + auto dynamicExprType = name->Check(this); + if (dynamicExprType->IsETSDynamicType()) { + return dynamicExprType; + } + if (name->IsIdentifier()) { + ThrowTypeError({"Cannot find type '", name->AsIdentifier()->Name(), "'."}, name->Start()); + } else { + ThrowTypeError( + {"type mismatch: dynamic type expected, got: '", util::StringView(dynamicExprType->ToString()), "'."}, + name->Start()); + } } auto *refVar = name->AsIdentifier()->Variable()->AsLocalVariable(); diff --git a/ets2panda/compiler/core/ETSCompiler.cpp b/ets2panda/compiler/core/ETSCompiler.cpp index 8b837ef3828cef376407e4077e312b0ee39f1cba..ca5026dddde4de30825987a776b0c7514176950f 100644 --- a/ets2panda/compiler/core/ETSCompiler.cpp +++ b/ets2panda/compiler/core/ETSCompiler.cpp @@ -273,7 +273,7 @@ static std::pair LoadDynamicName(compiler::ETSGen *etsg, const ir::A return {qnameStart, qnameLen}; } -static void CreateDynamicObject(const ir::AstNode *node, compiler::ETSGen *etsg, const ir::Expression *typeRef, +static void CreateDynamicObject(const ir::Expression *node, compiler::ETSGen *etsg, const ir::Expression *typeRef, checker::Signature *signature, const ArenaVector &arguments) { auto objReg = etsg->AllocReg(); @@ -287,8 +287,16 @@ static void CreateDynamicObject(const ir::AstNode *node, compiler::ETSGen *etsg, etsg->StoreAccumulator(node, objReg); - auto [qnameStart, qnameLen] = LoadDynamicName(etsg, node, callInfo.name, true); - etsg->CallDynamic(node, objReg, qnameStart, qnameLen, signature, arguments); + if (!callInfo.name.empty()) { + auto [qnameStart, qnameLen] = LoadDynamicName(etsg, node, callInfo.name, true); + etsg->CallDynamic(node, objReg, qnameStart, qnameLen, signature, arguments); + } else { + compiler::VReg dynParam2 = etsg->AllocReg(); + auto lang = node->TsType()->AsETSDynamicType()->Language(); + etsg->LoadUndefinedDynamic(node, lang); + etsg->StoreAccumulator(node, dynParam2); + etsg->CallDynamic(node, objReg, dynParam2, signature, arguments); + } } static void ConvertRestArguments(checker::ETSChecker *const checker, const ir::ETSNewClassInstanceExpression *expr) diff --git a/ets2panda/ir/ets/etsTypeReferencePart.cpp b/ets2panda/ir/ets/etsTypeReferencePart.cpp index 44c6a4ba6b5316213624bd00b33c9814e802afb1..d513f1e9924a4a0d6aebc8ee7c65ad3aa3e8febb 100644 --- a/ets2panda/ir/ets/etsTypeReferencePart.cpp +++ b/ets2panda/ir/ets/etsTypeReferencePart.cpp @@ -112,7 +112,7 @@ checker::Type *ETSTypeReferencePart::GetType(checker::ETSChecker *checker) } } - checker::Type *baseType = checker->GetReferencedTypeBase(name_); + checker::Type *baseType = checker->GetReferencedTypeBase(name_, IsDynamicTypeAllowed()); ASSERT(baseType != nullptr); if (baseType->IsETSObjectType()) { diff --git a/ets2panda/ir/ets/etsTypeReferencePart.h b/ets2panda/ir/ets/etsTypeReferencePart.h index 41b1cd2293a7af76c15515b422f87edaab52bb62..941fdb2910b92f40c482d4e32f1b7d00c9f4b087 100644 --- a/ets2panda/ir/ets/etsTypeReferencePart.h +++ b/ets2panda/ir/ets/etsTypeReferencePart.h @@ -55,6 +55,16 @@ public: return name_; } + bool IsDynamicTypeAllowed() const + { + return allowDynamicType_; + } + + void SetAllowDynamicType() + { + allowDynamicType_ = true; + } + void TransformChildren(const NodeTransformer &cb, std::string_view transformationName) override; void Iterate(const NodeTraverser &cb) const override; void Dump(ir::AstDumper *dumper) const override; @@ -76,6 +86,7 @@ private: ir::Expression *name_; ir::TSTypeParameterInstantiation *typeParams_ {}; ir::ETSTypeReferencePart *prev_ {}; + bool allowDynamicType_ {false}; }; } // namespace ark::es2panda::ir diff --git a/ets2panda/parser/ETSparser.cpp b/ets2panda/parser/ETSparser.cpp index 773822beff78d20a16f4d83923a69f8ba287c9de..4ec6acd0d3ee2238dd6719851843fbbd6c75666e 100644 --- a/ets2panda/parser/ETSparser.cpp +++ b/ets2panda/parser/ETSparser.cpp @@ -3197,7 +3197,12 @@ ir::Expression *ETSParser::ParseExpressionOrTypeAnnotation(lexer::TokenType type return typeAnnotation; } - return ParseTypeAnnotation(&options); + auto typeAnnotation = ParseTypeAnnotation(&options); + if (typeAnnotation->IsETSTypeReference()) { + typeAnnotation->AsETSTypeReference()->Part()->SetAllowDynamicType(); + } + + return typeAnnotation; } return ParseExpression(ExpressionParseFlags::DISALLOW_YIELD); @@ -3521,6 +3526,9 @@ ir::Expression *ETSParser::ParseNewExpression() auto *newExprNode = AllocNode(typeReference, std::move(arguments), classDefinition); + if (newExprNode->GetTypeRef()->IsETSTypeReference()) { + newExprNode->GetTypeRef()->AsETSTypeReference()->Part()->SetAllowDynamicType(); + } newExprNode->SetRange({start, Lexer()->GetToken().End()}); return newExprNode; diff --git a/ets2panda/test/compiler/ets/dynamicJsImport-expected.txt b/ets2panda/test/compiler/ets/dynamicJsImport-expected.txt index df48da9663acc5d7a22608e58998c567db5d1af1..dfca237afa70bdb5a3e6d14ea5f3c95f2aced793 100644 --- a/ets2panda/test/compiler/ets/dynamicJsImport-expected.txt +++ b/ets2panda/test/compiler/ets/dynamicJsImport-expected.txt @@ -335,7 +335,7 @@ "type": "ETSTypeReferencePart", "name": { "type": "Identifier", - "name": "B", + "name": "JSValue", "decorators": [], "loc": { "start": { @@ -344,7 +344,7 @@ }, "end": { "line": 24, - "column": 13 + "column": 19 } } }, @@ -355,7 +355,7 @@ }, "end": { "line": 24, - "column": 15 + "column": 21 } } }, @@ -366,7 +366,7 @@ }, "end": { "line": 24, - "column": 15 + "column": 21 } } }, @@ -395,33 +395,33 @@ "loc": { "start": { "line": 24, - "column": 20 + "column": 26 }, "end": { "line": 24, - "column": 21 + "column": 27 } } }, "loc": { "start": { "line": 24, - "column": 20 + "column": 26 }, "end": { "line": 24, - "column": 22 + "column": 28 } } }, "loc": { "start": { "line": 24, - "column": 20 + "column": 26 }, "end": { "line": 24, - "column": 22 + "column": 28 } } }, @@ -435,11 +435,11 @@ "loc": { "start": { "line": 24, - "column": 22 + "column": 28 }, "end": { "line": 24, - "column": 24 + "column": 30 } } }, @@ -450,11 +450,11 @@ "loc": { "start": { "line": 24, - "column": 25 + "column": 31 }, "end": { "line": 24, - "column": 26 + "column": 32 } } }, @@ -463,11 +463,11 @@ "loc": { "start": { "line": 24, - "column": 22 + "column": 28 }, "end": { "line": 24, - "column": 26 + "column": 32 } } }, @@ -477,11 +477,11 @@ "loc": { "start": { "line": 24, - "column": 28 + "column": 34 }, "end": { "line": 24, - "column": 29 + "column": 35 } } }, @@ -491,11 +491,11 @@ "loc": { "start": { "line": 24, - "column": 31 + "column": 37 }, "end": { "line": 24, - "column": 34 + "column": 40 } } } @@ -503,7 +503,7 @@ "loc": { "start": { "line": 24, - "column": 16 + "column": 22 }, "end": { "line": 25, diff --git a/ets2panda/test/compiler/ets/dynamicJsImport.ets b/ets2panda/test/compiler/ets/dynamicJsImport.ets index 620c3485174b0923f017638e6eef8c9abbef7f89..c65ed9182e09ae6216fcc3ba3c52317876fc46b2 100644 --- a/ets2panda/test/compiler/ets/dynamicJsImport.ets +++ b/ets2panda/test/compiler/ets/dynamicJsImport.ets @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021-2023 Huawei Device Co., Ltd. + * Copyright (c) 2021-2024 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -21,7 +21,7 @@ import { A as AA } from "dynamic_js_import_tests" import { B } from "dynamic_js_import_tests" function main(): void { - let o: B = new B(AA.x, 1, 2.0) + let o: JSValue = new B(AA.x, 1, 2.0) let r = o.foo(3.0, 4) let e = r[10] e(); diff --git a/ets2panda/test/compiler/ets/dynamicObjectLiteral-expected.txt b/ets2panda/test/compiler/ets/dynamicObjectLiteral-expected.txt index 0a23031bbad92ccb34a2e62cb12b208c3868772d..09923e83b226f21740df3f4ed61b313fe8b514ff 100644 --- a/ets2panda/test/compiler/ets/dynamicObjectLiteral-expected.txt +++ b/ets2panda/test/compiler/ets/dynamicObjectLiteral-expected.txt @@ -263,7 +263,7 @@ "type": "ETSTypeReferencePart", "name": { "type": "Identifier", - "name": "A", + "name": "JSValue", "decorators": [], "loc": { "start": { @@ -272,7 +272,7 @@ }, "end": { "line": 30, - "column": 13 + "column": 19 } } }, @@ -283,7 +283,7 @@ }, "end": { "line": 30, - "column": 15 + "column": 21 } } }, @@ -294,7 +294,7 @@ }, "end": { "line": 30, - "column": 15 + "column": 21 } } }, @@ -325,11 +325,11 @@ "loc": { "start": { "line": 30, - "column": 18 + "column": 24 }, "end": { "line": 30, - "column": 22 + "column": 28 } } }, @@ -339,11 +339,11 @@ "loc": { "start": { "line": 30, - "column": 24 + "column": 30 }, "end": { "line": 30, - "column": 32 + "column": 38 } } }, @@ -351,11 +351,11 @@ "loc": { "start": { "line": 30, - "column": 18 + "column": 24 }, "end": { "line": 30, - "column": 32 + "column": 38 } } }, @@ -371,11 +371,11 @@ "loc": { "start": { "line": 30, - "column": 34 + "column": 40 }, "end": { "line": 30, - "column": 37 + "column": 43 } } }, @@ -385,11 +385,11 @@ "loc": { "start": { "line": 30, - "column": 39 + "column": 45 }, "end": { "line": 30, - "column": 41 + "column": 47 } } }, @@ -397,11 +397,11 @@ "loc": { "start": { "line": 30, - "column": 34 + "column": 40 }, "end": { "line": 30, - "column": 41 + "column": 47 } } }, @@ -417,11 +417,11 @@ "loc": { "start": { "line": 30, - "column": 43 + "column": 49 }, "end": { "line": 30, - "column": 51 + "column": 57 } } }, @@ -431,11 +431,11 @@ "loc": { "start": { "line": 30, - "column": 53 + "column": 59 }, "end": { "line": 30, - "column": 68 + "column": 74 } } }, @@ -443,11 +443,11 @@ "loc": { "start": { "line": 30, - "column": 43 + "column": 49 }, "end": { "line": 30, - "column": 68 + "column": 74 } } } @@ -455,11 +455,11 @@ "loc": { "start": { "line": 30, - "column": 16 + "column": 22 }, "end": { "line": 30, - "column": 70 + "column": 76 } } }, @@ -470,7 +470,7 @@ }, "end": { "line": 30, - "column": 70 + "column": 76 } } } @@ -483,7 +483,7 @@ }, "end": { "line": 30, - "column": 71 + "column": 77 } } } diff --git a/ets2panda/test/compiler/ets/dynamicObjectLiteral.ets b/ets2panda/test/compiler/ets/dynamicObjectLiteral.ets index 6ef64094fb745bd08fc31c3cd367cd1716a043a9..b9d955b4c21900b6900e4460110d0f7574fa5453 100644 --- a/ets2panda/test/compiler/ets/dynamicObjectLiteral.ets +++ b/ets2panda/test/compiler/ets/dynamicObjectLiteral.ets @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021-2023 Huawei Device Co., Ltd. + * Copyright (c) 2021-2024 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -27,5 +27,5 @@ flags: [dynamic-ast] import { A } from "dynamic_js_import_tests" function main(): void { - let a: A = { name: "Edalyn", age: 30, location: "Boiling_isles" }; + let a: JSValue = { name: "Edalyn", age: 30, location: "Boiling_isles" }; } diff --git a/ets2panda/test/compiler/ets/dynamic_object_is_kinda_type-expected.txt b/ets2panda/test/compiler/ets/dynamic_object_is_kinda_type-expected.txt new file mode 100644 index 0000000000000000000000000000000000000000..9059b9a6d48f7b611901a6a065a75f54cb38d974 --- /dev/null +++ b/ets2panda/test/compiler/ets/dynamic_object_is_kinda_type-expected.txt @@ -0,0 +1,3534 @@ +{ + "type": "Program", + "statements": [ + { + "type": "ImportDeclaration", + "source": { + "type": "StringLiteral", + "value": "dynamic_js_import_tests", + "loc": { + "start": { + "line": 26, + "column": 39 + }, + "end": { + "line": 26, + "column": 64 + } + } + }, + "specifiers": [ + { + "type": "ImportSpecifier", + "local": { + "type": "Identifier", + "name": "A", + "decorators": [], + "loc": { + "start": { + "line": 26, + "column": 10 + }, + "end": { + "line": 26, + "column": 11 + } + } + }, + "imported": { + "type": "Identifier", + "name": "A", + "decorators": [], + "loc": { + "start": { + "line": 26, + "column": 10 + }, + "end": { + "line": 26, + "column": 11 + } + } + }, + "loc": { + "start": { + "line": 26, + "column": 10 + }, + "end": { + "line": 26, + "column": 11 + } + } + }, + { + "type": "ImportSpecifier", + "local": { + "type": "Identifier", + "name": "NamespaceOfClasses", + "decorators": [], + "loc": { + "start": { + "line": 26, + "column": 13 + }, + "end": { + "line": 26, + "column": 31 + } + } + }, + "imported": { + "type": "Identifier", + "name": "NamespaceOfClasses", + "decorators": [], + "loc": { + "start": { + "line": 26, + "column": 13 + }, + "end": { + "line": 26, + "column": 31 + } + } + }, + "loc": { + "start": { + "line": 26, + "column": 13 + }, + "end": { + "line": 26, + "column": 31 + } + } + } + ], + "loc": { + "start": { + "line": 26, + "column": 1 + }, + "end": { + "line": 26, + "column": 64 + } + } + }, + { + "type": "ClassDeclaration", + "definition": { + "id": { + "type": "Identifier", + "name": "ETSGLOBAL", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "superClass": null, + "implements": [], + "body": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "_$init$_", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "kind": "method", + "accessibility": "public", + "static": true, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "_$init$_", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "statements": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "main", + "decorators": [], + "loc": { + "start": { + "line": 28, + "column": 10 + }, + "end": { + "line": 28, + "column": 14 + } + } + }, + "kind": "method", + "accessibility": "public", + "static": true, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "main", + "decorators": [], + "loc": { + "start": { + "line": 28, + "column": 10 + }, + "end": { + "line": 28, + "column": 14 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "returnType": { + "type": "ETSPrimitiveType", + "loc": { + "start": { + "line": 28, + "column": 18 + }, + "end": { + "line": 28, + "column": 21 + } + } + }, + "body": { + "type": "BlockStatement", + "statements": [ + { + "type": "VariableDeclaration", + "declarations": [ + { + "type": "VariableDeclarator", + "id": { + "type": "Identifier", + "name": "a", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "JSValue", + "decorators": [], + "loc": { + "start": { + "line": 29, + "column": 12 + }, + "end": { + "line": 29, + "column": 19 + } + } + }, + "loc": { + "start": { + "line": 29, + "column": 12 + }, + "end": { + "line": 29, + "column": 21 + } + } + }, + "loc": { + "start": { + "line": 29, + "column": 12 + }, + "end": { + "line": 29, + "column": 21 + } + } + }, + "decorators": [], + "loc": { + "start": { + "line": 29, + "column": 9 + }, + "end": { + "line": 29, + "column": 10 + } + } + }, + "init": { + "type": "ETSNewClassInstanceExpression", + "typeReference": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "A", + "decorators": [], + "loc": { + "start": { + "line": 29, + "column": 26 + }, + "end": { + "line": 29, + "column": 27 + } + } + }, + "loc": { + "start": { + "line": 29, + "column": 26 + }, + "end": { + "line": 29, + "column": 28 + } + } + }, + "loc": { + "start": { + "line": 29, + "column": 26 + }, + "end": { + "line": 29, + "column": 28 + } + } + }, + "arguments": [ + { + "type": "StringLiteral", + "value": "arg", + "loc": { + "start": { + "line": 29, + "column": 28 + }, + "end": { + "line": 29, + "column": 33 + } + } + }, + { + "type": "NumberLiteral", + "value": 1, + "loc": { + "start": { + "line": 29, + "column": 35 + }, + "end": { + "line": 29, + "column": 36 + } + } + } + ], + "loc": { + "start": { + "line": 29, + "column": 22 + }, + "end": { + "line": 29, + "column": 38 + } + } + }, + "loc": { + "start": { + "line": 29, + "column": 9 + }, + "end": { + "line": 29, + "column": 38 + } + } + } + ], + "kind": "let", + "loc": { + "start": { + "line": 29, + "column": 5 + }, + "end": { + "line": 29, + "column": 38 + } + } + }, + { + "type": "IfStatement", + "test": { + "type": "UnaryExpression", + "operator": "!", + "prefix": true, + "argument": { + "type": "BinaryExpression", + "operator": "instanceof", + "left": { + "type": "Identifier", + "name": "a", + "decorators": [], + "loc": { + "start": { + "line": 30, + "column": 11 + }, + "end": { + "line": 30, + "column": 12 + } + } + }, + "right": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "A", + "decorators": [], + "loc": { + "start": { + "line": 30, + "column": 24 + }, + "end": { + "line": 30, + "column": 25 + } + } + }, + "loc": { + "start": { + "line": 30, + "column": 24 + }, + "end": { + "line": 30, + "column": 26 + } + } + }, + "loc": { + "start": { + "line": 30, + "column": 24 + }, + "end": { + "line": 30, + "column": 26 + } + } + }, + "loc": { + "start": { + "line": 30, + "column": 10 + }, + "end": { + "line": 30, + "column": 26 + } + } + }, + "loc": { + "start": { + "line": 30, + "column": 9 + }, + "end": { + "line": 30, + "column": 26 + } + } + }, + "consequent": { + "type": "BlockStatement", + "statements": [ + { + "type": "ReturnStatement", + "argument": { + "type": "NumberLiteral", + "value": 1, + "loc": { + "start": { + "line": 31, + "column": 16 + }, + "end": { + "line": 31, + "column": 17 + } + } + }, + "loc": { + "start": { + "line": 31, + "column": 9 + }, + "end": { + "line": 31, + "column": 18 + } + } + } + ], + "loc": { + "start": { + "line": 30, + "column": 28 + }, + "end": { + "line": 32, + "column": 6 + } + } + }, + "alternate": null, + "loc": { + "start": { + "line": 30, + "column": 5 + }, + "end": { + "line": 32, + "column": 6 + } + } + }, + { + "type": "VariableDeclaration", + "declarations": [ + { + "type": "VariableDeclarator", + "id": { + "type": "Identifier", + "name": "varA", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "JSValue", + "decorators": [], + "loc": { + "start": { + "line": 33, + "column": 15 + }, + "end": { + "line": 33, + "column": 22 + } + } + }, + "loc": { + "start": { + "line": 33, + "column": 15 + }, + "end": { + "line": 33, + "column": 24 + } + } + }, + "loc": { + "start": { + "line": 33, + "column": 15 + }, + "end": { + "line": 33, + "column": 24 + } + } + }, + "decorators": [], + "loc": { + "start": { + "line": 33, + "column": 9 + }, + "end": { + "line": 33, + "column": 13 + } + } + }, + "init": { + "type": "Identifier", + "name": "A", + "decorators": [], + "loc": { + "start": { + "line": 33, + "column": 25 + }, + "end": { + "line": 33, + "column": 26 + } + } + }, + "loc": { + "start": { + "line": 33, + "column": 9 + }, + "end": { + "line": 33, + "column": 26 + } + } + } + ], + "kind": "let", + "loc": { + "start": { + "line": 33, + "column": 5 + }, + "end": { + "line": 33, + "column": 27 + } + } + }, + { + "type": "VariableDeclaration", + "declarations": [ + { + "type": "VariableDeclarator", + "id": { + "type": "Identifier", + "name": "var_a", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "JSValue", + "decorators": [], + "loc": { + "start": { + "line": 34, + "column": 16 + }, + "end": { + "line": 34, + "column": 23 + } + } + }, + "loc": { + "start": { + "line": 34, + "column": 16 + }, + "end": { + "line": 34, + "column": 25 + } + } + }, + "loc": { + "start": { + "line": 34, + "column": 16 + }, + "end": { + "line": 34, + "column": 25 + } + } + }, + "decorators": [], + "loc": { + "start": { + "line": 34, + "column": 9 + }, + "end": { + "line": 34, + "column": 14 + } + } + }, + "init": { + "type": "ETSNewClassInstanceExpression", + "typeReference": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "varA", + "decorators": [], + "loc": { + "start": { + "line": 34, + "column": 30 + }, + "end": { + "line": 34, + "column": 34 + } + } + }, + "loc": { + "start": { + "line": 34, + "column": 30 + }, + "end": { + "line": 34, + "column": 35 + } + } + }, + "loc": { + "start": { + "line": 34, + "column": 30 + }, + "end": { + "line": 34, + "column": 35 + } + } + }, + "arguments": [ + { + "type": "StringLiteral", + "value": "arg", + "loc": { + "start": { + "line": 34, + "column": 35 + }, + "end": { + "line": 34, + "column": 40 + } + } + }, + { + "type": "NumberLiteral", + "value": 1, + "loc": { + "start": { + "line": 34, + "column": 42 + }, + "end": { + "line": 34, + "column": 43 + } + } + } + ], + "loc": { + "start": { + "line": 34, + "column": 26 + }, + "end": { + "line": 34, + "column": 45 + } + } + }, + "loc": { + "start": { + "line": 34, + "column": 9 + }, + "end": { + "line": 34, + "column": 45 + } + } + } + ], + "kind": "let", + "loc": { + "start": { + "line": 34, + "column": 5 + }, + "end": { + "line": 34, + "column": 45 + } + } + }, + { + "type": "IfStatement", + "test": { + "type": "UnaryExpression", + "operator": "!", + "prefix": true, + "argument": { + "type": "BinaryExpression", + "operator": "instanceof", + "left": { + "type": "Identifier", + "name": "var_a", + "decorators": [], + "loc": { + "start": { + "line": 35, + "column": 11 + }, + "end": { + "line": 35, + "column": 16 + } + } + }, + "right": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "varA", + "decorators": [], + "loc": { + "start": { + "line": 35, + "column": 28 + }, + "end": { + "line": 35, + "column": 32 + } + } + }, + "loc": { + "start": { + "line": 35, + "column": 28 + }, + "end": { + "line": 35, + "column": 33 + } + } + }, + "loc": { + "start": { + "line": 35, + "column": 28 + }, + "end": { + "line": 35, + "column": 33 + } + } + }, + "loc": { + "start": { + "line": 35, + "column": 10 + }, + "end": { + "line": 35, + "column": 33 + } + } + }, + "loc": { + "start": { + "line": 35, + "column": 9 + }, + "end": { + "line": 35, + "column": 33 + } + } + }, + "consequent": { + "type": "BlockStatement", + "statements": [ + { + "type": "ReturnStatement", + "argument": { + "type": "NumberLiteral", + "value": 1, + "loc": { + "start": { + "line": 36, + "column": 16 + }, + "end": { + "line": 36, + "column": 17 + } + } + }, + "loc": { + "start": { + "line": 36, + "column": 9 + }, + "end": { + "line": 36, + "column": 18 + } + } + } + ], + "loc": { + "start": { + "line": 35, + "column": 35 + }, + "end": { + "line": 37, + "column": 6 + } + } + }, + "alternate": null, + "loc": { + "start": { + "line": 35, + "column": 5 + }, + "end": { + "line": 37, + "column": 6 + } + } + }, + { + "type": "VariableDeclaration", + "declarations": [ + { + "type": "VariableDeclarator", + "id": { + "type": "Identifier", + "name": "fromNamespace", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "JSValue", + "decorators": [], + "loc": { + "start": { + "line": 38, + "column": 24 + }, + "end": { + "line": 38, + "column": 31 + } + } + }, + "loc": { + "start": { + "line": 38, + "column": 24 + }, + "end": { + "line": 38, + "column": 33 + } + } + }, + "loc": { + "start": { + "line": 38, + "column": 24 + }, + "end": { + "line": 38, + "column": 33 + } + } + }, + "decorators": [], + "loc": { + "start": { + "line": 38, + "column": 9 + }, + "end": { + "line": 38, + "column": 22 + } + } + }, + "init": { + "type": "ETSNewClassInstanceExpression", + "typeReference": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "TSQualifiedName", + "left": { + "type": "Identifier", + "name": "NamespaceOfClasses", + "decorators": [], + "loc": { + "start": { + "line": 38, + "column": 38 + }, + "end": { + "line": 38, + "column": 56 + } + } + }, + "right": { + "type": "Identifier", + "name": "A", + "decorators": [], + "loc": { + "start": { + "line": 38, + "column": 57 + }, + "end": { + "line": 38, + "column": 58 + } + } + }, + "loc": { + "start": { + "line": 38, + "column": 38 + }, + "end": { + "line": 38, + "column": 59 + } + } + }, + "loc": { + "start": { + "line": 38, + "column": 38 + }, + "end": { + "line": 38, + "column": 59 + } + } + }, + "loc": { + "start": { + "line": 38, + "column": 38 + }, + "end": { + "line": 38, + "column": 59 + } + } + }, + "arguments": [ + { + "type": "StringLiteral", + "value": "arg", + "loc": { + "start": { + "line": 38, + "column": 59 + }, + "end": { + "line": 38, + "column": 64 + } + } + }, + { + "type": "NumberLiteral", + "value": 1, + "loc": { + "start": { + "line": 38, + "column": 66 + }, + "end": { + "line": 38, + "column": 67 + } + } + } + ], + "loc": { + "start": { + "line": 38, + "column": 34 + }, + "end": { + "line": 38, + "column": 69 + } + } + }, + "loc": { + "start": { + "line": 38, + "column": 9 + }, + "end": { + "line": 38, + "column": 69 + } + } + } + ], + "kind": "let", + "loc": { + "start": { + "line": 38, + "column": 5 + }, + "end": { + "line": 38, + "column": 69 + } + } + }, + { + "type": "VariableDeclaration", + "declarations": [ + { + "type": "VariableDeclarator", + "id": { + "type": "Identifier", + "name": "varNameA", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "JSValue", + "decorators": [], + "loc": { + "start": { + "line": 43, + "column": 19 + }, + "end": { + "line": 43, + "column": 26 + } + } + }, + "loc": { + "start": { + "line": 43, + "column": 19 + }, + "end": { + "line": 43, + "column": 28 + } + } + }, + "loc": { + "start": { + "line": 43, + "column": 19 + }, + "end": { + "line": 43, + "column": 28 + } + } + }, + "decorators": [], + "loc": { + "start": { + "line": 43, + "column": 9 + }, + "end": { + "line": 43, + "column": 17 + } + } + }, + "init": { + "type": "MemberExpression", + "object": { + "type": "Identifier", + "name": "NamespaceOfClasses", + "decorators": [], + "loc": { + "start": { + "line": 43, + "column": 29 + }, + "end": { + "line": 43, + "column": 47 + } + } + }, + "property": { + "type": "Identifier", + "name": "A", + "decorators": [], + "loc": { + "start": { + "line": 43, + "column": 48 + }, + "end": { + "line": 43, + "column": 49 + } + } + }, + "computed": false, + "optional": false, + "loc": { + "start": { + "line": 43, + "column": 29 + }, + "end": { + "line": 43, + "column": 49 + } + } + }, + "loc": { + "start": { + "line": 43, + "column": 9 + }, + "end": { + "line": 43, + "column": 49 + } + } + } + ], + "kind": "let", + "loc": { + "start": { + "line": 43, + "column": 5 + }, + "end": { + "line": 43, + "column": 50 + } + } + }, + { + "type": "VariableDeclaration", + "declarations": [ + { + "type": "VariableDeclarator", + "id": { + "type": "Identifier", + "name": "var_name_a", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "JSValue", + "decorators": [], + "loc": { + "start": { + "line": 44, + "column": 21 + }, + "end": { + "line": 44, + "column": 28 + } + } + }, + "loc": { + "start": { + "line": 44, + "column": 21 + }, + "end": { + "line": 44, + "column": 30 + } + } + }, + "loc": { + "start": { + "line": 44, + "column": 21 + }, + "end": { + "line": 44, + "column": 30 + } + } + }, + "decorators": [], + "loc": { + "start": { + "line": 44, + "column": 9 + }, + "end": { + "line": 44, + "column": 19 + } + } + }, + "init": { + "type": "ETSNewClassInstanceExpression", + "typeReference": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "varNameA", + "decorators": [], + "loc": { + "start": { + "line": 44, + "column": 35 + }, + "end": { + "line": 44, + "column": 43 + } + } + }, + "loc": { + "start": { + "line": 44, + "column": 35 + }, + "end": { + "line": 44, + "column": 44 + } + } + }, + "loc": { + "start": { + "line": 44, + "column": 35 + }, + "end": { + "line": 44, + "column": 44 + } + } + }, + "arguments": [ + { + "type": "StringLiteral", + "value": "arg", + "loc": { + "start": { + "line": 44, + "column": 44 + }, + "end": { + "line": 44, + "column": 49 + } + } + }, + { + "type": "NumberLiteral", + "value": 1, + "loc": { + "start": { + "line": 44, + "column": 51 + }, + "end": { + "line": 44, + "column": 52 + } + } + } + ], + "loc": { + "start": { + "line": 44, + "column": 31 + }, + "end": { + "line": 44, + "column": 54 + } + } + }, + "loc": { + "start": { + "line": 44, + "column": 9 + }, + "end": { + "line": 44, + "column": 54 + } + } + } + ], + "kind": "let", + "loc": { + "start": { + "line": 44, + "column": 5 + }, + "end": { + "line": 44, + "column": 54 + } + } + }, + { + "type": "IfStatement", + "test": { + "type": "UnaryExpression", + "operator": "!", + "prefix": true, + "argument": { + "type": "BinaryExpression", + "operator": "instanceof", + "left": { + "type": "Identifier", + "name": "var_name_a", + "decorators": [], + "loc": { + "start": { + "line": 45, + "column": 11 + }, + "end": { + "line": 45, + "column": 21 + } + } + }, + "right": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "varNameA", + "decorators": [], + "loc": { + "start": { + "line": 45, + "column": 33 + }, + "end": { + "line": 45, + "column": 41 + } + } + }, + "loc": { + "start": { + "line": 45, + "column": 33 + }, + "end": { + "line": 45, + "column": 42 + } + } + }, + "loc": { + "start": { + "line": 45, + "column": 33 + }, + "end": { + "line": 45, + "column": 42 + } + } + }, + "loc": { + "start": { + "line": 45, + "column": 10 + }, + "end": { + "line": 45, + "column": 42 + } + } + }, + "loc": { + "start": { + "line": 45, + "column": 9 + }, + "end": { + "line": 45, + "column": 42 + } + } + }, + "consequent": { + "type": "BlockStatement", + "statements": [ + { + "type": "ReturnStatement", + "argument": { + "type": "NumberLiteral", + "value": 1, + "loc": { + "start": { + "line": 46, + "column": 16 + }, + "end": { + "line": 46, + "column": 17 + } + } + }, + "loc": { + "start": { + "line": 46, + "column": 9 + }, + "end": { + "line": 46, + "column": 18 + } + } + } + ], + "loc": { + "start": { + "line": 45, + "column": 44 + }, + "end": { + "line": 47, + "column": 6 + } + } + }, + "alternate": null, + "loc": { + "start": { + "line": 45, + "column": 5 + }, + "end": { + "line": 47, + "column": 6 + } + } + }, + { + "type": "VariableDeclaration", + "declarations": [ + { + "type": "VariableDeclarator", + "id": { + "type": "Identifier", + "name": "varName", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "JSValue", + "decorators": [], + "loc": { + "start": { + "line": 48, + "column": 18 + }, + "end": { + "line": 48, + "column": 25 + } + } + }, + "loc": { + "start": { + "line": 48, + "column": 18 + }, + "end": { + "line": 48, + "column": 27 + } + } + }, + "loc": { + "start": { + "line": 48, + "column": 18 + }, + "end": { + "line": 48, + "column": 27 + } + } + }, + "decorators": [], + "loc": { + "start": { + "line": 48, + "column": 9 + }, + "end": { + "line": 48, + "column": 16 + } + } + }, + "init": { + "type": "Identifier", + "name": "NamespaceOfClasses", + "decorators": [], + "loc": { + "start": { + "line": 48, + "column": 28 + }, + "end": { + "line": 48, + "column": 46 + } + } + }, + "loc": { + "start": { + "line": 48, + "column": 9 + }, + "end": { + "line": 48, + "column": 46 + } + } + } + ], + "kind": "let", + "loc": { + "start": { + "line": 48, + "column": 5 + }, + "end": { + "line": 48, + "column": 47 + } + } + }, + { + "type": "VariableDeclaration", + "declarations": [ + { + "type": "VariableDeclarator", + "id": { + "type": "Identifier", + "name": "var_var_name_a", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "JSValue", + "decorators": [], + "loc": { + "start": { + "line": 49, + "column": 25 + }, + "end": { + "line": 49, + "column": 32 + } + } + }, + "loc": { + "start": { + "line": 49, + "column": 25 + }, + "end": { + "line": 49, + "column": 34 + } + } + }, + "loc": { + "start": { + "line": 49, + "column": 25 + }, + "end": { + "line": 49, + "column": 34 + } + } + }, + "decorators": [], + "loc": { + "start": { + "line": 49, + "column": 9 + }, + "end": { + "line": 49, + "column": 23 + } + } + }, + "init": { + "type": "ETSNewClassInstanceExpression", + "typeReference": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "TSQualifiedName", + "left": { + "type": "Identifier", + "name": "varName", + "decorators": [], + "loc": { + "start": { + "line": 49, + "column": 39 + }, + "end": { + "line": 49, + "column": 46 + } + } + }, + "right": { + "type": "Identifier", + "name": "A", + "decorators": [], + "loc": { + "start": { + "line": 49, + "column": 47 + }, + "end": { + "line": 49, + "column": 48 + } + } + }, + "loc": { + "start": { + "line": 49, + "column": 39 + }, + "end": { + "line": 49, + "column": 49 + } + } + }, + "loc": { + "start": { + "line": 49, + "column": 39 + }, + "end": { + "line": 49, + "column": 49 + } + } + }, + "loc": { + "start": { + "line": 49, + "column": 39 + }, + "end": { + "line": 49, + "column": 49 + } + } + }, + "arguments": [ + { + "type": "StringLiteral", + "value": "arg", + "loc": { + "start": { + "line": 49, + "column": 49 + }, + "end": { + "line": 49, + "column": 54 + } + } + }, + { + "type": "NumberLiteral", + "value": 1, + "loc": { + "start": { + "line": 49, + "column": 56 + }, + "end": { + "line": 49, + "column": 57 + } + } + } + ], + "loc": { + "start": { + "line": 49, + "column": 35 + }, + "end": { + "line": 49, + "column": 59 + } + } + }, + "loc": { + "start": { + "line": 49, + "column": 9 + }, + "end": { + "line": 49, + "column": 59 + } + } + } + ], + "kind": "let", + "loc": { + "start": { + "line": 49, + "column": 5 + }, + "end": { + "line": 49, + "column": 59 + } + } + }, + { + "type": "ReturnStatement", + "argument": { + "type": "NumberLiteral", + "value": 0, + "loc": { + "start": { + "line": 54, + "column": 12 + }, + "end": { + "line": 54, + "column": 13 + } + } + }, + "loc": { + "start": { + "line": 54, + "column": 5 + }, + "end": { + "line": 54, + "column": 14 + } + } + } + ], + "loc": { + "start": { + "line": 28, + "column": 22 + }, + "end": { + "line": 55, + "column": 2 + } + } + }, + "loc": { + "start": { + "line": 28, + "column": 14 + }, + "end": { + "line": 55, + "column": 2 + } + } + }, + "loc": { + "start": { + "line": 28, + "column": 14 + }, + "end": { + "line": 55, + "column": 2 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 28, + "column": 1 + }, + "end": { + "line": 55, + "column": 2 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "ClassDeclaration", + "definition": { + "id": { + "type": "Identifier", + "name": "$jsnew", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "superClass": null, + "implements": [], + "body": [ + { + "type": "ClassProperty", + "key": { + "type": "Identifier", + "name": "qname_start_from", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "accessibility": "private", + "static": true, + "readonly": true, + "declare": false, + "optional": false, + "computed": false, + "typeAnnotation": { + "type": "ETSPrimitiveType", + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "definite": false, + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "ClassStaticBlock", + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "generator": false, + "async": false, + "expression": true, + "params": [], + "body": { + "type": "BlockStatement", + "statements": [ + { + "type": "ExpressionStatement", + "expression": { + "type": "CallExpression", + "callee": { + "type": "MemberExpression", + "object": { + "type": "Identifier", + "name": "JSRuntime", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "property": { + "type": "Identifier", + "name": "__initJSNewClass", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "computed": false, + "optional": false, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "arguments": [ + { + "type": "StringLiteral", + "value": "L$jsnew;", + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "optional": false, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "invoke", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "kind": "method", + "accessibility": "public", + "static": true, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "invoke", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [ + { + "type": "ETSParameterExpression", + "name": { + "type": "Identifier", + "name": "obj", + "typeAnnotation": { + "type": "OpaqueType", + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "ETSParameterExpression", + "name": { + "type": "Identifier", + "name": "qname_start", + "typeAnnotation": { + "type": "ETSPrimitiveType", + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "ETSParameterExpression", + "name": { + "type": "Identifier", + "name": "qname_len", + "typeAnnotation": { + "type": "ETSPrimitiveType", + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "ETSParameterExpression", + "name": { + "type": "Identifier", + "name": "p0", + "typeAnnotation": { + "type": "OpaqueType", + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "ETSParameterExpression", + "name": { + "type": "Identifier", + "name": "p1", + "typeAnnotation": { + "type": "OpaqueType", + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "returnType": { + "type": "OpaqueType", + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "overloads": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "invoke", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "kind": "method", + "accessibility": "public", + "static": true, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "invoke", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [ + { + "type": "ETSParameterExpression", + "name": { + "type": "Identifier", + "name": "obj", + "typeAnnotation": { + "type": "OpaqueType", + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "ETSParameterExpression", + "name": { + "type": "Identifier", + "name": "this", + "typeAnnotation": { + "type": "OpaqueType", + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "ETSParameterExpression", + "name": { + "type": "Identifier", + "name": "p0", + "typeAnnotation": { + "type": "OpaqueType", + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "ETSParameterExpression", + "name": { + "type": "Identifier", + "name": "p1", + "typeAnnotation": { + "type": "OpaqueType", + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "returnType": { + "type": "OpaqueType", + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "invoke", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "kind": "method", + "accessibility": "public", + "static": true, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "invoke", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [ + { + "type": "ETSParameterExpression", + "name": { + "type": "Identifier", + "name": "obj", + "typeAnnotation": { + "type": "OpaqueType", + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "ETSParameterExpression", + "name": { + "type": "Identifier", + "name": "this", + "typeAnnotation": { + "type": "OpaqueType", + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "ETSParameterExpression", + "name": { + "type": "Identifier", + "name": "p0", + "typeAnnotation": { + "type": "OpaqueType", + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "ETSParameterExpression", + "name": { + "type": "Identifier", + "name": "p1", + "typeAnnotation": { + "type": "OpaqueType", + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "returnType": { + "type": "OpaqueType", + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "ClassDeclaration", + "definition": { + "id": { + "type": "Identifier", + "name": "$dynmodule", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "superClass": null, + "implements": [], + "body": [ + { + "type": "ClassProperty", + "key": { + "type": "Identifier", + "name": "dynamic_js_import_tests0", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "accessibility": "public", + "static": true, + "readonly": true, + "declare": false, + "optional": false, + "computed": false, + "typeAnnotation": { + "type": "OpaqueType", + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "definite": false, + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "ClassStaticBlock", + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "generator": false, + "async": false, + "expression": true, + "params": [], + "body": { + "type": "BlockStatement", + "statements": [ + { + "type": "ExpressionStatement", + "expression": { + "type": "AssignmentExpression", + "operator": "=", + "left": { + "type": "MemberExpression", + "object": { + "type": "Identifier", + "name": "$dynmodule", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "property": { + "type": "Identifier", + "name": "dynamic_js_import_tests0", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "computed": false, + "optional": false, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "right": { + "type": "CallExpression", + "callee": { + "type": "MemberExpression", + "object": { + "type": "Identifier", + "name": "JSRuntime", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "property": { + "type": "Identifier", + "name": "loadModule", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "computed": false, + "optional": false, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "arguments": [ + { + "type": "StringLiteral", + "value": "dynamic_js_import_tests", + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "optional": false, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "init", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "kind": "method", + "accessibility": "public", + "static": true, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "init", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "statements": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 56, + "column": 1 + } + } +} diff --git a/ets2panda/test/compiler/ets/dynamic_object_is_kinda_type.ets b/ets2panda/test/compiler/ets/dynamic_object_is_kinda_type.ets new file mode 100644 index 0000000000000000000000000000000000000000..f89331860ab97e913a5dd444af1ca607acd81e09 --- /dev/null +++ b/ets2panda/test/compiler/ets/dynamic_object_is_kinda_type.ets @@ -0,0 +1,55 @@ +/* + * Copyright (c) 2021-2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/*--- +flags: [dynamic-ast] +---*/ + +// JS code: +// Class A { +// constructor(arg1, arg2) {} +// } +// exports.NamespaceOfClasses = {A} + +import { A, NamespaceOfClasses } from "dynamic_js_import_tests" + +function main(): int { + let a: JSValue = new A("arg", 1); + if (!(a instanceof A)) { + return 1; + } + let varA: JSValue = A; + let var_a: JSValue = new varA("arg", 1); + if (!(var_a instanceof varA)) { + return 1; + } + let fromNamespace: JSValue = new NamespaceOfClasses.A("arg", 1); + // NOTE(staroverovag): support member access in instanceof rhs + // if (!(fromNamespace instanceof NamespaceOfClasses.A)) { + // return 1; + // } + let varNameA: JSValue = NamespaceOfClasses.A; + let var_name_a: JSValue = new varNameA("arg", 1); + if (!(var_name_a instanceof varNameA)) { + return 1; + } + let varName: JSValue = NamespaceOfClasses; + let var_var_name_a: JSValue = new varName.A("arg", 1); + // NOTE(staroverovag): support member access in instanceof rhs + // if (!(var_var_name_a instanceof varName.A)) { + // return 1; + // } + return 0; +} diff --git a/ets2panda/test/compiler/ets/dynamic_object_is_not_a_type-expected.txt b/ets2panda/test/compiler/ets/dynamic_object_is_not_a_type-expected.txt new file mode 100644 index 0000000000000000000000000000000000000000..e2fe4abca5da4adca6fcfecee00b8f5bb04b5ac2 --- /dev/null +++ b/ets2panda/test/compiler/ets/dynamic_object_is_not_a_type-expected.txt @@ -0,0 +1 @@ +SyntaxError: Cannot find type 'A'. [dynamic_object_is_not_a_type.ets:30:12] diff --git a/ets2panda/test/compiler/ets/dynamic_object_is_not_a_type.ets b/ets2panda/test/compiler/ets/dynamic_object_is_not_a_type.ets new file mode 100644 index 0000000000000000000000000000000000000000..ff48c8d3f6340beecc60f32cd4a51906926c21b9 --- /dev/null +++ b/ets2panda/test/compiler/ets/dynamic_object_is_not_a_type.ets @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2021-2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/*--- +flags: [dynamic-ast] +---*/ + +// JS code: +// Class A { +// name, +// age, +// location +// } + +import { A } from "dynamic_js_import_tests" + +function main(): void { + let a: A = { name: "Edalyn", age: 30, location: "Boiling_isles" }; // `A` is not a type use `JSValue` explicitly +} diff --git a/ets2panda/test/parser/ets/instanceof_with_not_object_type-expected.txt b/ets2panda/test/parser/ets/instanceof_with_not_object_type-expected.txt index 423949cdb833e9a6c2fbb5d1422dc28d7e66162c..0a2351e129bbc1e1fc3464f99ae071c5bacc0269 100644 --- a/ets2panda/test/parser/ets/instanceof_with_not_object_type-expected.txt +++ b/ets2panda/test/parser/ets/instanceof_with_not_object_type-expected.txt @@ -481,4 +481,4 @@ } } } -SyntaxError: Cannot find type 'a'. [instanceof_with_not_object_type.ets:24:18] +TypeError: Cannot find type 'a'. [instanceof_with_not_object_type.ets:24:18] diff --git a/ets2panda/varbinder/ETSBinder.cpp b/ets2panda/varbinder/ETSBinder.cpp index 8fcb6880885515efaff4d468c981734510167d3c..0647d4d826006ba83a4ea764f9b769c9ddc983c6 100644 --- a/ets2panda/varbinder/ETSBinder.cpp +++ b/ets2panda/varbinder/ETSBinder.cpp @@ -93,7 +93,7 @@ void ETSBinder::LookupTypeArgumentReferences(ir::ETSTypeReference *typeRef) } } -void ETSBinder::LookupTypeReference(ir::Identifier *ident, bool allowDynamicNamespaces) +void ETSBinder::LookupTypeReference(ir::Identifier *ident, bool allowDynamic) { const auto &name = ident->Name(); if (name == compiler::Signatures::UNDEFINED || name == compiler::Signatures::NULL_LITERAL) { @@ -107,16 +107,6 @@ void ETSBinder::LookupTypeReference(ir::Identifier *ident, bool allowDynamicName break; } - if (IsDynamicModuleVariable(res.variable)) { - ident->SetVariable(res.variable); - return; - } - - if (allowDynamicNamespaces && IsDynamicNamespaceVariable(res.variable)) { - ident->SetVariable(res.variable); - return; - } - switch (res.variable->Declaration()->Node()->Type()) { case ir::AstNodeType::CLASS_DECLARATION: case ir::AstNodeType::CLASS_DEFINITION: @@ -135,6 +125,10 @@ void ETSBinder::LookupTypeReference(ir::Identifier *ident, bool allowDynamicName } } + if (allowDynamic) { + LookupIdentReference(ident); + return; + } ThrowUnresolvableType(ident->Start(), name); } @@ -753,11 +747,8 @@ void ETSBinder::HandleCustomNodes(ir::AstNode *childNode) auto *typeRef = childNode->AsETSTypeReference(); auto *baseName = typeRef->BaseName(); ASSERT(baseName->IsReference()); - // We allow to resolve following types in pure dynamic mode: - // import * as I from "@dynamic" - // let x : I.X.Y - bool allowDynamicNamespaces = typeRef->Part()->Name() != baseName; - LookupTypeReference(baseName, allowDynamicNamespaces); + bool allowDynamic = typeRef->Part()->IsDynamicTypeAllowed(); + LookupTypeReference(baseName, allowDynamic); LookupTypeArgumentReferences(typeRef); break; } diff --git a/ets2panda/varbinder/ETSBinder.h b/ets2panda/varbinder/ETSBinder.h index 128fedd7612b8aca125cfd90e0ebc7846b46ab31..8075ab340ad6467c74827cad11103af3d9b871de 100644 --- a/ets2panda/varbinder/ETSBinder.h +++ b/ets2panda/varbinder/ETSBinder.h @@ -115,7 +115,7 @@ public: bool BuildInternalName(ir::ScriptFunction *scriptFunc) override; void AddCompilableFunction(ir::ScriptFunction *func) override; - void LookupTypeReference(ir::Identifier *ident, bool allowDynamicNamespaces); + void LookupTypeReference(ir::Identifier *ident, bool allowDynamic); void LookupTypeArgumentReferences(ir::ETSTypeReference *typeRef); void BuildInterfaceDeclaration(ir::TSInterfaceDeclaration *decl); void BuildMemberExpression(ir::MemberExpression *memberExpr);