From f61cddf3e2ab28c4f79bc5b5fa5b47afaa0c62e9 Mon Sep 17 00:00:00 2001 From: Tamas Toth Date: Wed, 20 Dec 2023 10:59:35 +0100 Subject: [PATCH] Fix import with alias can be used with re-export Fixes #14862 internal issue Signed-off-by: Tamas Toth Change-Id: I152f17867dd8e63ff63440ad0de8e31a38401d03 --- ets2panda/checker/ETSAnalyzer.cpp | 62 +- ets2panda/checker/ETSchecker.h | 13 +- ets2panda/checker/ets/helpers.cpp | 143 ++++- ets2panda/checker/ets/object.cpp | 18 +- ets2panda/checker/types/ets/etsObjectType.cpp | 43 ++ ets2panda/checker/types/ets/etsObjectType.h | 28 +- .../ets/re_export/diamond/A-expected.txt | 287 +++++++++ .../test/parser/ets/re_export/diamond/A.ets | 16 + .../ets/re_export/diamond/B-expected.txt | 238 +++++++ .../test/parser/ets/re_export/diamond/B.ets | 16 + .../ets/re_export/diamond/B2-expected.txt | 238 +++++++ .../test/parser/ets/re_export/diamond/B2.ets | 16 + .../ets/re_export/diamond/C-expected.txt | 238 +++++++ .../test/parser/ets/re_export/diamond/C.ets | 16 + .../ets/re_export/diamond/C2-expected.txt | 238 +++++++ .../test/parser/ets/re_export/diamond/C2.ets | 16 + .../ets/re_export/diamond/D-expected.txt | 600 ++++++++++++++++++ .../test/parser/ets/re_export/diamond/D.ets | 28 + .../ets/re_export/diamond/D2-expected.txt | 600 ++++++++++++++++++ .../test/parser/ets/re_export/diamond/D2.ets | 30 + .../ets/re_export/import_13-expected.txt | 391 ++++++++++++ .../test/parser/ets/re_export/import_13.ets | 21 + .../ets/re_export/import_14-expected.txt | 391 ++++++++++++ .../test/parser/ets/re_export/import_14.ets | 21 + .../ets/re_export/import_15-expected.txt | 391 ++++++++++++ .../test/parser/ets/re_export/import_15.ets | 21 + .../ets/re_export/import_7-expected.txt | 1 - .../ets/re_export/re_export_10-expected.txt | 223 +++++++ .../parser/ets/re_export/re_export_10.ets | 17 + .../ets/re_export/re_export_8-expected.txt | 238 +++++++ .../test/parser/ets/re_export/re_export_8.ets | 17 + .../ets/re_export/re_export_9-expected.txt | 238 +++++++ .../test/parser/ets/re_export/re_export_9.ets | 17 + ets2panda/varbinder/ETSBinder.cpp | 10 +- 34 files changed, 4798 insertions(+), 83 deletions(-) create mode 100644 ets2panda/test/parser/ets/re_export/diamond/A-expected.txt create mode 100644 ets2panda/test/parser/ets/re_export/diamond/A.ets create mode 100644 ets2panda/test/parser/ets/re_export/diamond/B-expected.txt create mode 100644 ets2panda/test/parser/ets/re_export/diamond/B.ets create mode 100644 ets2panda/test/parser/ets/re_export/diamond/B2-expected.txt create mode 100644 ets2panda/test/parser/ets/re_export/diamond/B2.ets create mode 100644 ets2panda/test/parser/ets/re_export/diamond/C-expected.txt create mode 100644 ets2panda/test/parser/ets/re_export/diamond/C.ets create mode 100644 ets2panda/test/parser/ets/re_export/diamond/C2-expected.txt create mode 100644 ets2panda/test/parser/ets/re_export/diamond/C2.ets create mode 100644 ets2panda/test/parser/ets/re_export/diamond/D-expected.txt create mode 100644 ets2panda/test/parser/ets/re_export/diamond/D.ets create mode 100644 ets2panda/test/parser/ets/re_export/diamond/D2-expected.txt create mode 100644 ets2panda/test/parser/ets/re_export/diamond/D2.ets create mode 100644 ets2panda/test/parser/ets/re_export/import_13-expected.txt create mode 100644 ets2panda/test/parser/ets/re_export/import_13.ets create mode 100644 ets2panda/test/parser/ets/re_export/import_14-expected.txt create mode 100644 ets2panda/test/parser/ets/re_export/import_14.ets create mode 100644 ets2panda/test/parser/ets/re_export/import_15-expected.txt create mode 100644 ets2panda/test/parser/ets/re_export/import_15.ets create mode 100644 ets2panda/test/parser/ets/re_export/re_export_10-expected.txt create mode 100644 ets2panda/test/parser/ets/re_export/re_export_10.ets create mode 100644 ets2panda/test/parser/ets/re_export/re_export_8-expected.txt create mode 100644 ets2panda/test/parser/ets/re_export/re_export_8.ets create mode 100644 ets2panda/test/parser/ets/re_export/re_export_9-expected.txt create mode 100644 ets2panda/test/parser/ets/re_export/re_export_9.ets diff --git a/ets2panda/checker/ETSAnalyzer.cpp b/ets2panda/checker/ETSAnalyzer.cpp index bf7b78c0db..4bddc0ce7b 100644 --- a/ets2panda/checker/ETSAnalyzer.cpp +++ b/ets2panda/checker/ETSAnalyzer.cpp @@ -1105,6 +1105,21 @@ checker::Type *ETSAnalyzer::SetAndAdjustType(ETSChecker *checker, ir::MemberExpr return expr->AdjustType(checker, resType); } +std::pair SearchReExportsType(Type *baseType, ir::MemberExpression *expr, + util::StringView aliasName) +{ + for (auto item : baseType->AsETSObjectType()->ReExports()) { + auto name = item->AsETSObjectType()->GetReExportAliasValue(aliasName); + if (item->GetProperty(name, PropertySearchFlags::SEARCH_ALL) != nullptr) { + return std::make_pair(item, name); + } + if (auto reExportType = SearchReExportsType(item, expr, name); reExportType.first != nullptr) { + return reExportType; + } + } + return std::make_pair(nullptr, util::StringView()); +} + checker::Type *ETSAnalyzer::Check(ir::MemberExpression *expr) const { if (expr->TsType() != nullptr) { @@ -1119,6 +1134,18 @@ checker::Type *ETSAnalyzer::Check(ir::MemberExpression *expr) const if (baseType->DefinitelyETSNullish() && expr->Object()->IsIdentifier()) { baseType = expr->Object()->AsIdentifier()->Variable()->TsType(); } + + if (baseType->IsETSObjectType() && !baseType->AsETSObjectType()->ReExports().empty() && + baseType->AsETSObjectType()->GetProperty(expr->Property()->AsIdentifier()->Name(), + PropertySearchFlags::SEARCH_ALL) == nullptr) { + if (auto reExportType = SearchReExportsType(baseType, expr, expr->Property()->AsIdentifier()->Name()); + reExportType.first != nullptr) { + baseType = reExportType.first; + expr->object_->AsIdentifier()->SetTsType(baseType); + expr->property_->AsIdentifier()->SetName(reExportType.second); + } + } + checker->CheckNonNullish(expr->Object()); if (expr->IsComputed()) { @@ -1635,7 +1662,6 @@ checker::Type *ETSAnalyzer::Check(ir::ImportNamespaceSpecifier *st) const } auto *importDecl = st->Parent()->AsETSImportDeclaration(); - auto importPath = importDecl->ResolvedSource()->Str(); if (importDecl->IsPureDynamic()) { auto *type = checker->GlobalBuiltinDynamicType(importDecl->Language()); @@ -1643,39 +1669,7 @@ checker::Type *ETSAnalyzer::Check(ir::ImportNamespaceSpecifier *st) const return type; } - auto [moduleName, isPackageModule] = checker->VarBinder()->AsETSBinder()->GetModuleInfo(importPath); - - std::vector syntheticNames = checker->GetNameForSynteticObjectType(moduleName); - - ASSERT(!syntheticNames.empty()); - - auto assemblerName = syntheticNames[0]; - if (!isPackageModule) { - assemblerName = util::UString(assemblerName.Mutf8().append(".").append(compiler::Signatures::ETS_GLOBAL), - checker->Allocator()) - .View(); - } - - auto *moduleObjectType = checker->Allocator()->New( - checker->Allocator(), syntheticNames[0], assemblerName, st->Local()->AsIdentifier(), - checker::ETSObjectFlags::CLASS, checker->Relation()); - - auto *rootDecl = checker->Allocator()->New(syntheticNames[0]); - varbinder::LocalVariable *rootVar = - checker->Allocator()->New(rootDecl, varbinder::VariableFlags::NONE); - rootVar->SetTsType(moduleObjectType); - - syntheticNames.erase(syntheticNames.begin()); - checker::ETSObjectType *lastObjectType(moduleObjectType); - - for (const auto &syntheticName : syntheticNames) { - lastObjectType = CreateSyntheticType(checker, syntheticName, lastObjectType, st->Local()->AsIdentifier()); - } - - checker->SetPropertiesForModuleObject(lastObjectType, importPath); - checker->SetrModuleObjectTsType(st->Local(), lastObjectType); - - return moduleObjectType; + return checker->GetImportSpecifierObjectType(importDecl, st->Local()->AsIdentifier()); } checker::Type *ETSAnalyzer::Check([[maybe_unused]] ir::ImportSpecifier *st) const diff --git a/ets2panda/checker/ETSchecker.h b/ets2panda/checker/ETSchecker.h index a7e1743da9..f936d5f251 100644 --- a/ets2panda/checker/ETSchecker.h +++ b/ets2panda/checker/ETSchecker.h @@ -443,7 +443,11 @@ public: static std::string GetAsyncImplName(const util::StringView &name); static std::string GetAsyncImplName(ir::MethodDefinition *asyncMethod); std::vector GetNameForSynteticObjectType(const util::StringView &source); - void SetPropertiesForModuleObject(checker::ETSObjectType *moduleObjType, const util::StringView &importPath); + template + void BindingsModuleObjectAddProperty(checker::ETSObjectType *moduleObjType, ir::ETSImportDeclaration *importDecl, + const varbinder::Scope::VariableMap &bindings); + void SetPropertiesForModuleObject(checker::ETSObjectType *moduleObjType, const util::StringView &importPath, + ir::ETSImportDeclaration *importDecl = nullptr); void SetrModuleObjectTsType(ir::Identifier *local, checker::ETSObjectType *moduleObjType); Type *GetReferencedTypeFromBase(Type *baseType, ir::Expression *name); Type *GetReferencedTypeBase(ir::Expression *name); @@ -572,6 +576,11 @@ public: ir::ClassProperty *field, varbinder::ClassScope *scope, bool isSetter, ETSChecker *checker); void GenerateGetterSetterPropertyAndMethod(ir::ClassProperty *originalProp, ETSObjectType *classType); + ETSObjectType *GetImportSpecifierObjectType(ir::ETSImportDeclaration *importDecl, ir::Identifier *ident); + void ImportNamespaceObjectTypeAddReExportType(ir::ETSImportDeclaration *importDecl, + checker::ETSObjectType *lastObjectType, ir::Identifier *ident); + checker::ETSObjectType *CreateSyntheticType(util::StringView const &syntheticName, + checker::ETSObjectType *lastObjectType, ir::Identifier *id); // Smart cast support [[nodiscard]] checker::Type *ResolveSmartType(checker::Type *sourceType, checker::Type *targetType); @@ -680,6 +689,8 @@ private: void ValidateGetterSetter(const ir::MemberExpression *memberExpr, const varbinder::LocalVariable *prop, PropertySearchFlags searchFlag); void ValidateVarDeclaratorOrClassProperty(const ir::MemberExpression *memberExpr, varbinder::LocalVariable *prop); + void ResolveMemberReferenceValidate(varbinder::LocalVariable *prop, PropertySearchFlags searchFlag, + const ir::MemberExpression *const memberExpr); std::tuple IsResolvedAndValue(const ir::Expression *expr, Type *type) const; PropertySearchFlags GetSearchFlags(const ir::MemberExpression *memberExpr, const varbinder::Variable *targetRef); PropertySearchFlags GetInitialSearchFlags(const ir::MemberExpression *memberExpr); diff --git a/ets2panda/checker/ets/helpers.cpp b/ets2panda/checker/ets/helpers.cpp index 55b410391c..5d6bc301a6 100644 --- a/ets2panda/checker/ets/helpers.cpp +++ b/ets2panda/checker/ets/helpers.cpp @@ -1092,7 +1092,43 @@ std::vector ETSChecker::GetNameForSynteticObjectType(const uti return syntheticName; } -void ETSChecker::SetPropertiesForModuleObject(checker::ETSObjectType *moduleObjType, const util::StringView &importPath) +std::pair FindSpecifierForModuleObject(ir::ETSImportDeclaration *importDecl, + util::StringView const &name) +{ + if (importDecl == nullptr) { + return std::make_pair(true, util::StringView()); + } + + for (auto item : importDecl->Specifiers()) { + if (item->IsImportSpecifier() && item->AsImportSpecifier()->Imported()->Name().Is(name.Mutf8())) { + if (!item->AsImportSpecifier()->Imported()->Name().Is(item->AsImportSpecifier()->Local()->Name().Mutf8())) { + return std::make_pair(true, item->AsImportSpecifier()->Local()->Name()); + } + return std::make_pair(true, util::StringView()); + } + } + return std::make_pair(false, util::StringView()); +} + +template +void ETSChecker::BindingsModuleObjectAddProperty(checker::ETSObjectType *moduleObjType, + ir::ETSImportDeclaration *importDecl, + const varbinder::Scope::VariableMap &bindings) +{ + for (auto [_, var] : bindings) { + (void)_; + auto [found, aliasedName] = FindSpecifierForModuleObject(importDecl, var->AsLocalVariable()->Name()); + if (var->AsLocalVariable()->Declaration()->Node()->IsExported() && found) { + if (!aliasedName.Empty()) { + moduleObjType->AddReExportAlias(var->Declaration()->Name(), aliasedName); + } + moduleObjType->AddProperty(var->AsLocalVariable()); + } + } +} + +void ETSChecker::SetPropertiesForModuleObject(checker::ETSObjectType *moduleObjType, const util::StringView &importPath, + ir::ETSImportDeclaration *importDecl) { auto *etsBinder = static_cast(VarBinder()); @@ -1104,33 +1140,17 @@ void ETSChecker::SetPropertiesForModuleObject(checker::ETSObjectType *moduleObjT // Check imported properties before assigning them to module object res->second.front()->Ast()->Check(this); - for (auto [_, var] : res->second.front()->GlobalClassScope()->StaticFieldScope()->Bindings()) { - (void)_; - if (var->AsLocalVariable()->Declaration()->Node()->IsExported()) { - moduleObjType->AddProperty(var->AsLocalVariable()); - } - } + BindingsModuleObjectAddProperty( + moduleObjType, importDecl, res->second.front()->GlobalClassScope()->StaticFieldScope()->Bindings()); - for (auto [_, var] : res->second.front()->GlobalClassScope()->StaticMethodScope()->Bindings()) { - (void)_; - if (var->AsLocalVariable()->Declaration()->Node()->IsExported()) { - moduleObjType->AddProperty(var->AsLocalVariable()); - } - } + BindingsModuleObjectAddProperty( + moduleObjType, importDecl, res->second.front()->GlobalClassScope()->StaticMethodScope()->Bindings()); - for (auto [_, var] : res->second.front()->GlobalClassScope()->InstanceDeclScope()->Bindings()) { - (void)_; - if (var->AsLocalVariable()->Declaration()->Node()->IsExported()) { - moduleObjType->AddProperty(var->AsLocalVariable()); - } - } + BindingsModuleObjectAddProperty( + moduleObjType, importDecl, res->second.front()->GlobalClassScope()->InstanceDeclScope()->Bindings()); - for (auto [_, var] : res->second.front()->GlobalClassScope()->TypeAliasScope()->Bindings()) { - (void)_; - if (var->AsLocalVariable()->Declaration()->Node()->IsExported()) { - moduleObjType->AddProperty(var->AsLocalVariable()); - } - } + BindingsModuleObjectAddProperty( + moduleObjType, importDecl, res->second.front()->GlobalClassScope()->TypeAliasScope()->Bindings()); } void ETSChecker::SetrModuleObjectTsType(ir::Identifier *local, checker::ETSObjectType *moduleObjType) @@ -2263,4 +2283,77 @@ bool ETSChecker::TryTransformingToStaticInvoke(ir::Identifier *const ident, cons return true; } + +checker::ETSObjectType *ETSChecker::CreateSyntheticType(util::StringView const &syntheticName, + checker::ETSObjectType *lastObjectType, ir::Identifier *id) +{ + auto *syntheticObjType = Allocator()->New(Allocator(), syntheticName, syntheticName, id, + checker::ETSObjectFlags::NO_OPTS); + + auto *classDecl = Allocator()->New(syntheticName); + varbinder::LocalVariable *var = + Allocator()->New(classDecl, varbinder::VariableFlags::CLASS); + var->SetTsType(syntheticObjType); + lastObjectType->AddProperty(var); + syntheticObjType->SetEnclosingType(lastObjectType); + return syntheticObjType; +} + +void ETSChecker::ImportNamespaceObjectTypeAddReExportType(ir::ETSImportDeclaration *importDecl, + checker::ETSObjectType *lastObjectType, ir::Identifier *ident) +{ + for (auto item : VarBinder()->AsETSBinder()->ReExportImports()) { + if (!importDecl->ResolvedSource()->Str().Is(item->GetProgramPath().Mutf8())) { + continue; + } + auto *reExportType = GetImportSpecifierObjectType(item->GetETSImportDeclarations(), ident); + lastObjectType->AddReExports(reExportType); + for (auto node : importDecl->Specifiers()) { + if (node->IsImportSpecifier()) { + auto specifier = node->AsImportSpecifier(); + lastObjectType->AddReExportAlias(specifier->Imported()->Name(), specifier->Local()->Name()); + } + } + } +} + +ETSObjectType *ETSChecker::GetImportSpecifierObjectType(ir::ETSImportDeclaration *importDecl, ir::Identifier *ident) +{ + auto importPath = importDecl->ResolvedSource()->Str(); + + auto [moduleName, isPackageModule] = VarBinder()->AsETSBinder()->GetModuleInfo(importPath); + + std::vector syntheticNames = GetNameForSynteticObjectType(moduleName); + + ASSERT(!syntheticNames.empty()); + + auto assemblerName = syntheticNames[0]; + if (!isPackageModule) { + assemblerName = + util::UString(assemblerName.Mutf8().append(".").append(compiler::Signatures::ETS_GLOBAL), Allocator()) + .View(); + } + + auto *moduleObjectType = Allocator()->New( + Allocator(), syntheticNames[0], assemblerName, ident, checker::ETSObjectFlags::CLASS, Relation()); + + auto *rootDecl = Allocator()->New(syntheticNames[0]); + varbinder::LocalVariable *rootVar = + Allocator()->New(rootDecl, varbinder::VariableFlags::NONE); + rootVar->SetTsType(moduleObjectType); + + syntheticNames.erase(syntheticNames.begin()); + checker::ETSObjectType *lastObjectType(moduleObjectType); + + for (const auto &syntheticName : syntheticNames) { + lastObjectType = CreateSyntheticType(syntheticName, lastObjectType, ident); + } + + ImportNamespaceObjectTypeAddReExportType(importDecl, lastObjectType, ident); + SetPropertiesForModuleObject(lastObjectType, importPath, + importDecl->Specifiers()[0]->IsImportNamespaceSpecifier() ? nullptr : importDecl); + SetrModuleObjectTsType(ident, lastObjectType); + + return moduleObjectType; +} } // namespace ark::es2panda::checker diff --git a/ets2panda/checker/ets/object.cpp b/ets2panda/checker/ets/object.cpp index 35e6db8440..dd960f2a44 100644 --- a/ets2panda/checker/ets/object.cpp +++ b/ets2panda/checker/ets/object.cpp @@ -1434,7 +1434,12 @@ std::vector ETSChecker::ResolveMemberReference(const ir::Member searchFlag |= PropertySearchFlags::SEARCH_ALL; } - auto *const prop = target->GetProperty(memberExpr->Property()->AsIdentifier()->Name(), searchFlag); + auto searchName = target->GetReExportAliasValue(memberExpr->Property()->AsIdentifier()->Name()); + auto *const prop = target->GetProperty(searchName, searchFlag); + + if (memberExpr->Parent()->IsCallExpression() && memberExpr->Parent()->AsCallExpression()->Callee() == memberExpr) { + globalFunctionVar = ResolveInstanceExtension(memberExpr); + } if (globalFunctionVar == nullptr || (targetRef != nullptr && targetRef->HasFlag(varbinder::VariableFlags::CLASS_OR_INTERFACE))) { @@ -1464,6 +1469,15 @@ std::vector ETSChecker::ResolveMemberReference(const ir::Member resolveRes.emplace_back(Allocator()->New(prop, ResolvedKind::PROPERTY)); + ResolveMemberReferenceValidate(prop, searchFlag, memberExpr); + + return resolveRes; +} + +void ETSChecker::ResolveMemberReferenceValidate(varbinder::LocalVariable *const prop, + PropertySearchFlags const searchFlag, + const ir::MemberExpression *const memberExpr) +{ if (prop->HasFlag(varbinder::VariableFlags::METHOD) && !IsVariableGetterSetter(prop) && (searchFlag & PropertySearchFlags::IS_FUNCTIONAL) == 0) { ThrowTypeError("Method used in wrong context", memberExpr->Property()->Start()); @@ -1479,8 +1493,6 @@ std::vector ETSChecker::ResolveMemberReference(const ir::Member if (memberExpr->Parent()->IsVariableDeclarator() || memberExpr->Parent()->IsClassProperty()) { ValidateVarDeclaratorOrClassProperty(memberExpr, prop); } - - return resolveRes; } void ETSChecker::CheckValidInheritance(ETSObjectType *classType, ir::ClassDefinition *classDef) diff --git a/ets2panda/checker/types/ets/etsObjectType.cpp b/ets2panda/checker/types/ets/etsObjectType.cpp index 3fcdf820d0..213a398333 100644 --- a/ets2panda/checker/types/ets/etsObjectType.cpp +++ b/ets2panda/checker/types/ets/etsObjectType.cpp @@ -970,4 +970,47 @@ std::uint32_t ETSObjectType::GetPrecedence(ETSObjectType const *type) noexcept } return 0U; } +void ETSObjectType::AddReExports(ETSObjectType *reExport) +{ + if (std::find(reExports_.begin(), reExports_.end(), reExport) == reExports_.end()) { + reExports_.push_back(reExport); + } +} + +void ETSObjectType::AddReExportAlias(util::StringView const &value, util::StringView const &key) +{ + reExportAlias_.insert({key, value}); +} + +util::StringView ETSObjectType::GetReExportAliasValue(util::StringView const &key) const +{ + auto ret = reExportAlias_.find(key); + if (reExportAlias_.end() == ret) { + return key; + } + return ret->second; +} + +const ArenaVector &ETSObjectType::ReExports() const +{ + return reExports_; +} + +void ETSObjectType::ToAssemblerType([[maybe_unused]] std::stringstream &ss) const +{ + ss << assemblerName_; +} + +void ETSObjectType::ToDebugInfoType(std::stringstream &ss) const +{ + DebugInfoTypeFromName(ss, assemblerName_); +} + +void ETSObjectType::ToDebugInfoSignatureType(std::stringstream &ss) const +{ + ss << compiler::Signatures::GENERIC_BEGIN; + ss << assemblerName_; + ss << compiler::Signatures::GENERIC_END; +} + } // namespace ark::es2panda::checker diff --git a/ets2panda/checker/types/ets/etsObjectType.h b/ets2panda/checker/types/ets/etsObjectType.h index 42fa39e9bc..aa2c7f54ce 100644 --- a/ets2panda/checker/types/ets/etsObjectType.h +++ b/ets2panda/checker/types/ets/etsObjectType.h @@ -379,25 +379,15 @@ public: bool DefaultObjectTypeChecks(const ETSChecker *etsChecker, TypeRelation *relation, Type *source); void IsSupertypeOf(TypeRelation *relation, Type *source) override; Type *AsSuper(Checker *checker, varbinder::Variable *sourceVar) override; - - void ToAssemblerType([[maybe_unused]] std::stringstream &ss) const override - { - ss << assemblerName_; - } - + void ToAssemblerType([[maybe_unused]] std::stringstream &ss) const override; static void DebugInfoTypeFromName(std::stringstream &ss, util::StringView asmName); + void ToDebugInfoType(std::stringstream &ss) const override; + void ToDebugInfoSignatureType(std::stringstream &ss) const; - void ToDebugInfoType(std::stringstream &ss) const override - { - DebugInfoTypeFromName(ss, assemblerName_); - } - - void ToDebugInfoSignatureType(std::stringstream &ss) const - { - ss << compiler::Signatures::GENERIC_BEGIN; - ss << assemblerName_; - ss << compiler::Signatures::GENERIC_END; - } + void AddReExports(ETSObjectType *reExport); + void AddReExportAlias(util::StringView const &value, util::StringView const &key); + util::StringView GetReExportAliasValue(util::StringView const &key) const; + const ArenaVector &ReExports() const; ArenaAllocator *Allocator() const { @@ -430,6 +420,8 @@ private: assemblerName_(assemblerName), declNode_(declNode), interfaces_(allocator->Adapter()), + reExports_(allocator->Adapter()), + reExportAlias_(allocator->Adapter()), flags_(flags), instantiationMap_(allocator->Adapter()), typeArguments_(allocator->Adapter()), @@ -475,6 +467,8 @@ private: util::StringView assemblerName_; ir::AstNode *declNode_; ArenaVector interfaces_; + ArenaVector reExports_; + ArenaMap reExportAlias_; ETSObjectFlags flags_; InstantiationMap instantiationMap_; ArenaVector typeArguments_; diff --git a/ets2panda/test/parser/ets/re_export/diamond/A-expected.txt b/ets2panda/test/parser/ets/re_export/diamond/A-expected.txt new file mode 100644 index 0000000000..5c1d2aa74e --- /dev/null +++ b/ets2panda/test/parser/ets/re_export/diamond/A-expected.txt @@ -0,0 +1,287 @@ +{ + "type": "Program", + "statements": [ + { + "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": [ + { + "type": "ExpressionStatement", + "expression": { + "type": "AssignmentExpression", + "operator": "=", + "left": { + "type": "Identifier", + "name": "foo", + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 12 + }, + "end": { + "line": 16, + "column": 15 + } + } + }, + "right": { + "type": "StringLiteral", + "value": "AAA", + "loc": { + "start": { + "line": 16, + "column": 26 + }, + "end": { + "line": 16, + "column": 31 + } + } + }, + "loc": { + "start": { + "line": 16, + "column": 12 + }, + "end": { + "line": 16, + "column": 31 + } + } + }, + "loc": { + "start": { + "line": 16, + "column": 12 + }, + "end": { + "line": 16, + "column": 31 + } + } + } + ], + "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": "ClassProperty", + "key": { + "type": "Identifier", + "name": "foo", + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 12 + }, + "end": { + "line": 16, + "column": 15 + } + } + }, + "accessibility": "public", + "static": true, + "readonly": false, + "declare": false, + "optional": false, + "computed": false, + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "string", + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 17 + }, + "end": { + "line": 16, + "column": 23 + } + } + }, + "loc": { + "start": { + "line": 16, + "column": 17 + }, + "end": { + "line": 16, + "column": 25 + } + } + }, + "loc": { + "start": { + "line": 16, + "column": 17 + }, + "end": { + "line": 16, + "column": 25 + } + } + }, + "definite": false, + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 12 + }, + "end": { + "line": 16, + "column": 31 + } + } + } + ], + "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": 17, + "column": 1 + } + } +} diff --git a/ets2panda/test/parser/ets/re_export/diamond/A.ets b/ets2panda/test/parser/ets/re_export/diamond/A.ets new file mode 100644 index 0000000000..eb3c9b7243 --- /dev/null +++ b/ets2panda/test/parser/ets/re_export/diamond/A.ets @@ -0,0 +1,16 @@ +/* + * Copyright (c) 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. + */ + +export let foo: string = "AAA" diff --git a/ets2panda/test/parser/ets/re_export/diamond/B-expected.txt b/ets2panda/test/parser/ets/re_export/diamond/B-expected.txt new file mode 100644 index 0000000000..75bfb3625e --- /dev/null +++ b/ets2panda/test/parser/ets/re_export/diamond/B-expected.txt @@ -0,0 +1,238 @@ +{ + "type": "Program", + "statements": [ + { + "type": "ETSReExportDeclaration", + "ets_import_declarations": { + "type": "ImportDeclaration", + "source": { + "type": "StringLiteral", + "value": "./A", + "loc": { + "start": { + "line": 16, + "column": 26 + }, + "end": { + "line": 16, + "column": 31 + } + } + }, + "specifiers": [ + { + "type": "ImportSpecifier", + "local": { + "type": "Identifier", + "name": "boo", + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 16 + }, + "end": { + "line": 16, + "column": 19 + } + } + }, + "imported": { + "type": "Identifier", + "name": "foo", + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 9 + }, + "end": { + "line": 16, + "column": 12 + } + } + }, + "loc": { + "start": { + "line": 16, + "column": 9 + }, + "end": { + "line": 16, + "column": 19 + } + } + } + ], + "loc": { + "start": { + "line": 16, + "column": 8 + }, + "end": { + "line": 16, + "column": 31 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "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 + } + } + } + ], + "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": 17, + "column": 1 + } + } +} diff --git a/ets2panda/test/parser/ets/re_export/diamond/B.ets b/ets2panda/test/parser/ets/re_export/diamond/B.ets new file mode 100644 index 0000000000..4ca9b2e2a6 --- /dev/null +++ b/ets2panda/test/parser/ets/re_export/diamond/B.ets @@ -0,0 +1,16 @@ +/* + * Copyright (c) 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. + */ + +export {foo as boo} from "./A" diff --git a/ets2panda/test/parser/ets/re_export/diamond/B2-expected.txt b/ets2panda/test/parser/ets/re_export/diamond/B2-expected.txt new file mode 100644 index 0000000000..12883a6851 --- /dev/null +++ b/ets2panda/test/parser/ets/re_export/diamond/B2-expected.txt @@ -0,0 +1,238 @@ +{ + "type": "Program", + "statements": [ + { + "type": "ETSReExportDeclaration", + "ets_import_declarations": { + "type": "ImportDeclaration", + "source": { + "type": "StringLiteral", + "value": "./B", + "loc": { + "start": { + "line": 16, + "column": 26 + }, + "end": { + "line": 16, + "column": 31 + } + } + }, + "specifiers": [ + { + "type": "ImportSpecifier", + "local": { + "type": "Identifier", + "name": "BOO", + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 16 + }, + "end": { + "line": 16, + "column": 19 + } + } + }, + "imported": { + "type": "Identifier", + "name": "boo", + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 9 + }, + "end": { + "line": 16, + "column": 12 + } + } + }, + "loc": { + "start": { + "line": 16, + "column": 9 + }, + "end": { + "line": 16, + "column": 19 + } + } + } + ], + "loc": { + "start": { + "line": 16, + "column": 8 + }, + "end": { + "line": 16, + "column": 31 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "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 + } + } + } + ], + "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": 17, + "column": 1 + } + } +} diff --git a/ets2panda/test/parser/ets/re_export/diamond/B2.ets b/ets2panda/test/parser/ets/re_export/diamond/B2.ets new file mode 100644 index 0000000000..6b9860e9ce --- /dev/null +++ b/ets2panda/test/parser/ets/re_export/diamond/B2.ets @@ -0,0 +1,16 @@ +/* + * Copyright (c) 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. + */ + +export {boo as BOO} from "./B" diff --git a/ets2panda/test/parser/ets/re_export/diamond/C-expected.txt b/ets2panda/test/parser/ets/re_export/diamond/C-expected.txt new file mode 100644 index 0000000000..730c5bba5f --- /dev/null +++ b/ets2panda/test/parser/ets/re_export/diamond/C-expected.txt @@ -0,0 +1,238 @@ +{ + "type": "Program", + "statements": [ + { + "type": "ETSReExportDeclaration", + "ets_import_declarations": { + "type": "ImportDeclaration", + "source": { + "type": "StringLiteral", + "value": "./A", + "loc": { + "start": { + "line": 16, + "column": 26 + }, + "end": { + "line": 16, + "column": 31 + } + } + }, + "specifiers": [ + { + "type": "ImportSpecifier", + "local": { + "type": "Identifier", + "name": "coo", + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 16 + }, + "end": { + "line": 16, + "column": 19 + } + } + }, + "imported": { + "type": "Identifier", + "name": "foo", + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 9 + }, + "end": { + "line": 16, + "column": 12 + } + } + }, + "loc": { + "start": { + "line": 16, + "column": 9 + }, + "end": { + "line": 16, + "column": 19 + } + } + } + ], + "loc": { + "start": { + "line": 16, + "column": 8 + }, + "end": { + "line": 16, + "column": 31 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "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 + } + } + } + ], + "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": 17, + "column": 1 + } + } +} diff --git a/ets2panda/test/parser/ets/re_export/diamond/C.ets b/ets2panda/test/parser/ets/re_export/diamond/C.ets new file mode 100644 index 0000000000..fccf01e30c --- /dev/null +++ b/ets2panda/test/parser/ets/re_export/diamond/C.ets @@ -0,0 +1,16 @@ +/* + * Copyright (c) 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. + */ + +export {foo as coo} from "./A" diff --git a/ets2panda/test/parser/ets/re_export/diamond/C2-expected.txt b/ets2panda/test/parser/ets/re_export/diamond/C2-expected.txt new file mode 100644 index 0000000000..11dda3ff2a --- /dev/null +++ b/ets2panda/test/parser/ets/re_export/diamond/C2-expected.txt @@ -0,0 +1,238 @@ +{ + "type": "Program", + "statements": [ + { + "type": "ETSReExportDeclaration", + "ets_import_declarations": { + "type": "ImportDeclaration", + "source": { + "type": "StringLiteral", + "value": "./C", + "loc": { + "start": { + "line": 16, + "column": 26 + }, + "end": { + "line": 16, + "column": 31 + } + } + }, + "specifiers": [ + { + "type": "ImportSpecifier", + "local": { + "type": "Identifier", + "name": "COO", + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 16 + }, + "end": { + "line": 16, + "column": 19 + } + } + }, + "imported": { + "type": "Identifier", + "name": "coo", + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 9 + }, + "end": { + "line": 16, + "column": 12 + } + } + }, + "loc": { + "start": { + "line": 16, + "column": 9 + }, + "end": { + "line": 16, + "column": 19 + } + } + } + ], + "loc": { + "start": { + "line": 16, + "column": 8 + }, + "end": { + "line": 16, + "column": 31 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "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 + } + } + } + ], + "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": 17, + "column": 1 + } + } +} diff --git a/ets2panda/test/parser/ets/re_export/diamond/C2.ets b/ets2panda/test/parser/ets/re_export/diamond/C2.ets new file mode 100644 index 0000000000..8a1afee54f --- /dev/null +++ b/ets2panda/test/parser/ets/re_export/diamond/C2.ets @@ -0,0 +1,16 @@ +/* + * Copyright (c) 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. + */ + +export {coo as COO} from "./C" diff --git a/ets2panda/test/parser/ets/re_export/diamond/D-expected.txt b/ets2panda/test/parser/ets/re_export/diamond/D-expected.txt new file mode 100644 index 0000000000..e50334a106 --- /dev/null +++ b/ets2panda/test/parser/ets/re_export/diamond/D-expected.txt @@ -0,0 +1,600 @@ +{ + "type": "Program", + "statements": [ + { + "type": "ImportDeclaration", + "source": { + "type": "StringLiteral", + "value": "./B", + "loc": { + "start": { + "line": 22, + "column": 21 + }, + "end": { + "line": 22, + "column": 26 + } + } + }, + "specifiers": [ + { + "type": "ImportNamespaceSpecifier", + "local": { + "type": "Identifier", + "name": "BB", + "decorators": [], + "loc": { + "start": { + "line": 22, + "column": 13 + }, + "end": { + "line": 22, + "column": 15 + } + } + }, + "loc": { + "start": { + "line": 22, + "column": 8 + }, + "end": { + "line": 22, + "column": 15 + } + } + } + ], + "loc": { + "start": { + "line": 22, + "column": 1 + }, + "end": { + "line": 22, + "column": 26 + } + } + }, + { + "type": "ImportDeclaration", + "source": { + "type": "StringLiteral", + "value": "./C", + "loc": { + "start": { + "line": 23, + "column": 21 + }, + "end": { + "line": 23, + "column": 26 + } + } + }, + "specifiers": [ + { + "type": "ImportNamespaceSpecifier", + "local": { + "type": "Identifier", + "name": "CC", + "decorators": [], + "loc": { + "start": { + "line": 23, + "column": 13 + }, + "end": { + "line": 23, + "column": 15 + } + } + }, + "loc": { + "start": { + "line": 23, + "column": 8 + }, + "end": { + "line": 23, + "column": 15 + } + } + } + ], + "loc": { + "start": { + "line": 23, + "column": 1 + }, + "end": { + "line": 23, + "column": 26 + } + } + }, + { + "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": 25, + "column": 10 + }, + "end": { + "line": 25, + "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": 25, + "column": 10 + }, + "end": { + "line": 25, + "column": 14 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "statements": [ + { + "type": "ExpressionStatement", + "expression": { + "type": "CallExpression", + "callee": { + "type": "MemberExpression", + "object": { + "type": "Identifier", + "name": "console", + "decorators": [], + "loc": { + "start": { + "line": 26, + "column": 3 + }, + "end": { + "line": 26, + "column": 10 + } + } + }, + "property": { + "type": "Identifier", + "name": "log", + "decorators": [], + "loc": { + "start": { + "line": 26, + "column": 11 + }, + "end": { + "line": 26, + "column": 14 + } + } + }, + "computed": false, + "optional": false, + "loc": { + "start": { + "line": 26, + "column": 3 + }, + "end": { + "line": 26, + "column": 14 + } + } + }, + "arguments": [ + { + "type": "MemberExpression", + "object": { + "type": "Identifier", + "name": "CC", + "decorators": [], + "loc": { + "start": { + "line": 26, + "column": 15 + }, + "end": { + "line": 26, + "column": 17 + } + } + }, + "property": { + "type": "Identifier", + "name": "coo", + "decorators": [], + "loc": { + "start": { + "line": 26, + "column": 18 + }, + "end": { + "line": 26, + "column": 21 + } + } + }, + "computed": false, + "optional": false, + "loc": { + "start": { + "line": 26, + "column": 15 + }, + "end": { + "line": 26, + "column": 21 + } + } + } + ], + "optional": false, + "loc": { + "start": { + "line": 26, + "column": 3 + }, + "end": { + "line": 26, + "column": 22 + } + } + }, + "loc": { + "start": { + "line": 26, + "column": 3 + }, + "end": { + "line": 26, + "column": 23 + } + } + }, + { + "type": "ExpressionStatement", + "expression": { + "type": "CallExpression", + "callee": { + "type": "MemberExpression", + "object": { + "type": "Identifier", + "name": "console", + "decorators": [], + "loc": { + "start": { + "line": 27, + "column": 3 + }, + "end": { + "line": 27, + "column": 10 + } + } + }, + "property": { + "type": "Identifier", + "name": "log", + "decorators": [], + "loc": { + "start": { + "line": 27, + "column": 11 + }, + "end": { + "line": 27, + "column": 14 + } + } + }, + "computed": false, + "optional": false, + "loc": { + "start": { + "line": 27, + "column": 3 + }, + "end": { + "line": 27, + "column": 14 + } + } + }, + "arguments": [ + { + "type": "MemberExpression", + "object": { + "type": "Identifier", + "name": "BB", + "decorators": [], + "loc": { + "start": { + "line": 27, + "column": 15 + }, + "end": { + "line": 27, + "column": 17 + } + } + }, + "property": { + "type": "Identifier", + "name": "boo", + "decorators": [], + "loc": { + "start": { + "line": 27, + "column": 18 + }, + "end": { + "line": 27, + "column": 21 + } + } + }, + "computed": false, + "optional": false, + "loc": { + "start": { + "line": 27, + "column": 15 + }, + "end": { + "line": 27, + "column": 21 + } + } + } + ], + "optional": false, + "loc": { + "start": { + "line": 27, + "column": 3 + }, + "end": { + "line": 27, + "column": 22 + } + } + }, + "loc": { + "start": { + "line": 27, + "column": 3 + }, + "end": { + "line": 27, + "column": 23 + } + } + } + ], + "loc": { + "start": { + "line": 25, + "column": 17 + }, + "end": { + "line": 28, + "column": 2 + } + } + }, + "loc": { + "start": { + "line": 25, + "column": 14 + }, + "end": { + "line": 28, + "column": 2 + } + } + }, + "loc": { + "start": { + "line": 25, + "column": 14 + }, + "end": { + "line": 28, + "column": 2 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 25, + "column": 1 + }, + "end": { + "line": 28, + "column": 2 + } + } + } + ], + "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": 29, + "column": 1 + } + } +} diff --git a/ets2panda/test/parser/ets/re_export/diamond/D.ets b/ets2panda/test/parser/ets/re_export/diamond/D.ets new file mode 100644 index 0000000000..e9f2897d28 --- /dev/null +++ b/ets2panda/test/parser/ets/re_export/diamond/D.ets @@ -0,0 +1,28 @@ +/* + * Copyright (c) 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. + */ + +/* A + / \ + B C + \ / + D */ + +import * as BB from "./B" +import * as CC from "./C" + +function main() { + console.log(CC.coo); + console.log(BB.boo); +} diff --git a/ets2panda/test/parser/ets/re_export/diamond/D2-expected.txt b/ets2panda/test/parser/ets/re_export/diamond/D2-expected.txt new file mode 100644 index 0000000000..d7aa2fa443 --- /dev/null +++ b/ets2panda/test/parser/ets/re_export/diamond/D2-expected.txt @@ -0,0 +1,600 @@ +{ + "type": "Program", + "statements": [ + { + "type": "ImportDeclaration", + "source": { + "type": "StringLiteral", + "value": "./B2", + "loc": { + "start": { + "line": 24, + "column": 21 + }, + "end": { + "line": 24, + "column": 27 + } + } + }, + "specifiers": [ + { + "type": "ImportNamespaceSpecifier", + "local": { + "type": "Identifier", + "name": "BB", + "decorators": [], + "loc": { + "start": { + "line": 24, + "column": 13 + }, + "end": { + "line": 24, + "column": 15 + } + } + }, + "loc": { + "start": { + "line": 24, + "column": 8 + }, + "end": { + "line": 24, + "column": 15 + } + } + } + ], + "loc": { + "start": { + "line": 24, + "column": 1 + }, + "end": { + "line": 24, + "column": 27 + } + } + }, + { + "type": "ImportDeclaration", + "source": { + "type": "StringLiteral", + "value": "./C2", + "loc": { + "start": { + "line": 25, + "column": 21 + }, + "end": { + "line": 25, + "column": 27 + } + } + }, + "specifiers": [ + { + "type": "ImportNamespaceSpecifier", + "local": { + "type": "Identifier", + "name": "CC", + "decorators": [], + "loc": { + "start": { + "line": 25, + "column": 13 + }, + "end": { + "line": 25, + "column": 15 + } + } + }, + "loc": { + "start": { + "line": 25, + "column": 8 + }, + "end": { + "line": 25, + "column": 15 + } + } + } + ], + "loc": { + "start": { + "line": 25, + "column": 1 + }, + "end": { + "line": 25, + "column": 27 + } + } + }, + { + "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": 27, + "column": 10 + }, + "end": { + "line": 27, + "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": 27, + "column": 10 + }, + "end": { + "line": 27, + "column": 14 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "statements": [ + { + "type": "ExpressionStatement", + "expression": { + "type": "CallExpression", + "callee": { + "type": "MemberExpression", + "object": { + "type": "Identifier", + "name": "console", + "decorators": [], + "loc": { + "start": { + "line": 28, + "column": 3 + }, + "end": { + "line": 28, + "column": 10 + } + } + }, + "property": { + "type": "Identifier", + "name": "log", + "decorators": [], + "loc": { + "start": { + "line": 28, + "column": 11 + }, + "end": { + "line": 28, + "column": 14 + } + } + }, + "computed": false, + "optional": false, + "loc": { + "start": { + "line": 28, + "column": 3 + }, + "end": { + "line": 28, + "column": 14 + } + } + }, + "arguments": [ + { + "type": "MemberExpression", + "object": { + "type": "Identifier", + "name": "CC", + "decorators": [], + "loc": { + "start": { + "line": 28, + "column": 15 + }, + "end": { + "line": 28, + "column": 17 + } + } + }, + "property": { + "type": "Identifier", + "name": "COO", + "decorators": [], + "loc": { + "start": { + "line": 28, + "column": 18 + }, + "end": { + "line": 28, + "column": 21 + } + } + }, + "computed": false, + "optional": false, + "loc": { + "start": { + "line": 28, + "column": 15 + }, + "end": { + "line": 28, + "column": 21 + } + } + } + ], + "optional": false, + "loc": { + "start": { + "line": 28, + "column": 3 + }, + "end": { + "line": 28, + "column": 22 + } + } + }, + "loc": { + "start": { + "line": 28, + "column": 3 + }, + "end": { + "line": 28, + "column": 23 + } + } + }, + { + "type": "ExpressionStatement", + "expression": { + "type": "CallExpression", + "callee": { + "type": "MemberExpression", + "object": { + "type": "Identifier", + "name": "console", + "decorators": [], + "loc": { + "start": { + "line": 29, + "column": 3 + }, + "end": { + "line": 29, + "column": 10 + } + } + }, + "property": { + "type": "Identifier", + "name": "log", + "decorators": [], + "loc": { + "start": { + "line": 29, + "column": 11 + }, + "end": { + "line": 29, + "column": 14 + } + } + }, + "computed": false, + "optional": false, + "loc": { + "start": { + "line": 29, + "column": 3 + }, + "end": { + "line": 29, + "column": 14 + } + } + }, + "arguments": [ + { + "type": "MemberExpression", + "object": { + "type": "Identifier", + "name": "BB", + "decorators": [], + "loc": { + "start": { + "line": 29, + "column": 15 + }, + "end": { + "line": 29, + "column": 17 + } + } + }, + "property": { + "type": "Identifier", + "name": "BOO", + "decorators": [], + "loc": { + "start": { + "line": 29, + "column": 18 + }, + "end": { + "line": 29, + "column": 21 + } + } + }, + "computed": false, + "optional": false, + "loc": { + "start": { + "line": 29, + "column": 15 + }, + "end": { + "line": 29, + "column": 21 + } + } + } + ], + "optional": false, + "loc": { + "start": { + "line": 29, + "column": 3 + }, + "end": { + "line": 29, + "column": 22 + } + } + }, + "loc": { + "start": { + "line": 29, + "column": 3 + }, + "end": { + "line": 29, + "column": 23 + } + } + } + ], + "loc": { + "start": { + "line": 27, + "column": 17 + }, + "end": { + "line": 30, + "column": 2 + } + } + }, + "loc": { + "start": { + "line": 27, + "column": 14 + }, + "end": { + "line": 30, + "column": 2 + } + } + }, + "loc": { + "start": { + "line": 27, + "column": 14 + }, + "end": { + "line": 30, + "column": 2 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 27, + "column": 1 + }, + "end": { + "line": 30, + "column": 2 + } + } + } + ], + "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": 31, + "column": 1 + } + } +} diff --git a/ets2panda/test/parser/ets/re_export/diamond/D2.ets b/ets2panda/test/parser/ets/re_export/diamond/D2.ets new file mode 100644 index 0000000000..b2f16bb816 --- /dev/null +++ b/ets2panda/test/parser/ets/re_export/diamond/D2.ets @@ -0,0 +1,30 @@ +/* + * Copyright (c) 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. + */ + +/* A + / \ + B C + | | + B2 C2 + \ / + D2 */ + +import * as BB from "./B2" +import * as CC from "./C2" + +function main() { + console.log(CC.COO); + console.log(BB.BOO); +} diff --git a/ets2panda/test/parser/ets/re_export/import_13-expected.txt b/ets2panda/test/parser/ets/re_export/import_13-expected.txt new file mode 100644 index 0000000000..93b4d5684d --- /dev/null +++ b/ets2panda/test/parser/ets/re_export/import_13-expected.txt @@ -0,0 +1,391 @@ +{ + "type": "Program", + "statements": [ + { + "type": "ImportDeclaration", + "source": { + "type": "StringLiteral", + "value": "./re_export_8", + "loc": { + "start": { + "line": 16, + "column": 20 + }, + "end": { + "line": 16, + "column": 35 + } + } + }, + "specifiers": [ + { + "type": "ImportNamespaceSpecifier", + "local": { + "type": "Identifier", + "name": "A", + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 13 + }, + "end": { + "line": 16, + "column": 14 + } + } + }, + "loc": { + "start": { + "line": 16, + "column": 8 + }, + "end": { + "line": 16, + "column": 14 + } + } + } + ], + "loc": { + "start": { + "line": 16, + "column": 1 + }, + "end": { + "line": 16, + "column": 35 + } + } + }, + { + "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": 18, + "column": 10 + }, + "end": { + "line": 18, + "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": 18, + "column": 10 + }, + "end": { + "line": 18, + "column": 14 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "returnType": { + "type": "ETSPrimitiveType", + "loc": { + "start": { + "line": 18, + "column": 19 + }, + "end": { + "line": 18, + "column": 23 + } + } + }, + "body": { + "type": "BlockStatement", + "statements": [ + { + "type": "ExpressionStatement", + "expression": { + "type": "CallExpression", + "callee": { + "type": "MemberExpression", + "object": { + "type": "Identifier", + "name": "A", + "decorators": [], + "loc": { + "start": { + "line": 20, + "column": 5 + }, + "end": { + "line": 20, + "column": 6 + } + } + }, + "property": { + "type": "Identifier", + "name": "foo", + "decorators": [], + "loc": { + "start": { + "line": 20, + "column": 7 + }, + "end": { + "line": 20, + "column": 10 + } + } + }, + "computed": false, + "optional": false, + "loc": { + "start": { + "line": 20, + "column": 5 + }, + "end": { + "line": 20, + "column": 10 + } + } + }, + "arguments": [], + "optional": false, + "loc": { + "start": { + "line": 20, + "column": 5 + }, + "end": { + "line": 20, + "column": 12 + } + } + }, + "loc": { + "start": { + "line": 20, + "column": 5 + }, + "end": { + "line": 20, + "column": 13 + } + } + } + ], + "loc": { + "start": { + "line": 19, + "column": 1 + }, + "end": { + "line": 21, + "column": 2 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 14 + }, + "end": { + "line": 21, + "column": 2 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 14 + }, + "end": { + "line": 21, + "column": 2 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 18, + "column": 1 + }, + "end": { + "line": 21, + "column": 2 + } + } + } + ], + "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": 22, + "column": 1 + } + } +} diff --git a/ets2panda/test/parser/ets/re_export/import_13.ets b/ets2panda/test/parser/ets/re_export/import_13.ets new file mode 100644 index 0000000000..9b7fc3dcfb --- /dev/null +++ b/ets2panda/test/parser/ets/re_export/import_13.ets @@ -0,0 +1,21 @@ +/* + * Copyright (c) 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. + */ + +import * as A from "./re_export_8" + +function main() : void +{ + A.foo(); +} diff --git a/ets2panda/test/parser/ets/re_export/import_14-expected.txt b/ets2panda/test/parser/ets/re_export/import_14-expected.txt new file mode 100644 index 0000000000..0626011c04 --- /dev/null +++ b/ets2panda/test/parser/ets/re_export/import_14-expected.txt @@ -0,0 +1,391 @@ +{ + "type": "Program", + "statements": [ + { + "type": "ImportDeclaration", + "source": { + "type": "StringLiteral", + "value": "./re_export_9", + "loc": { + "start": { + "line": 16, + "column": 20 + }, + "end": { + "line": 16, + "column": 35 + } + } + }, + "specifiers": [ + { + "type": "ImportNamespaceSpecifier", + "local": { + "type": "Identifier", + "name": "A", + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 13 + }, + "end": { + "line": 16, + "column": 14 + } + } + }, + "loc": { + "start": { + "line": 16, + "column": 8 + }, + "end": { + "line": 16, + "column": 14 + } + } + } + ], + "loc": { + "start": { + "line": 16, + "column": 1 + }, + "end": { + "line": 16, + "column": 35 + } + } + }, + { + "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": 18, + "column": 10 + }, + "end": { + "line": 18, + "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": 18, + "column": 10 + }, + "end": { + "line": 18, + "column": 14 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "returnType": { + "type": "ETSPrimitiveType", + "loc": { + "start": { + "line": 18, + "column": 19 + }, + "end": { + "line": 18, + "column": 23 + } + } + }, + "body": { + "type": "BlockStatement", + "statements": [ + { + "type": "ExpressionStatement", + "expression": { + "type": "CallExpression", + "callee": { + "type": "MemberExpression", + "object": { + "type": "Identifier", + "name": "A", + "decorators": [], + "loc": { + "start": { + "line": 20, + "column": 5 + }, + "end": { + "line": 20, + "column": 6 + } + } + }, + "property": { + "type": "Identifier", + "name": "fooAlias", + "decorators": [], + "loc": { + "start": { + "line": 20, + "column": 7 + }, + "end": { + "line": 20, + "column": 15 + } + } + }, + "computed": false, + "optional": false, + "loc": { + "start": { + "line": 20, + "column": 5 + }, + "end": { + "line": 20, + "column": 15 + } + } + }, + "arguments": [], + "optional": false, + "loc": { + "start": { + "line": 20, + "column": 5 + }, + "end": { + "line": 20, + "column": 17 + } + } + }, + "loc": { + "start": { + "line": 20, + "column": 5 + }, + "end": { + "line": 20, + "column": 18 + } + } + } + ], + "loc": { + "start": { + "line": 19, + "column": 1 + }, + "end": { + "line": 21, + "column": 2 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 14 + }, + "end": { + "line": 21, + "column": 2 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 14 + }, + "end": { + "line": 21, + "column": 2 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 18, + "column": 1 + }, + "end": { + "line": 21, + "column": 2 + } + } + } + ], + "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": 22, + "column": 1 + } + } +} diff --git a/ets2panda/test/parser/ets/re_export/import_14.ets b/ets2panda/test/parser/ets/re_export/import_14.ets new file mode 100644 index 0000000000..2748599756 --- /dev/null +++ b/ets2panda/test/parser/ets/re_export/import_14.ets @@ -0,0 +1,21 @@ +/* + * Copyright (c) 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. + */ + +import * as A from "./re_export_9" + +function main() : void +{ + A.fooAlias(); +} diff --git a/ets2panda/test/parser/ets/re_export/import_15-expected.txt b/ets2panda/test/parser/ets/re_export/import_15-expected.txt new file mode 100644 index 0000000000..236d597b09 --- /dev/null +++ b/ets2panda/test/parser/ets/re_export/import_15-expected.txt @@ -0,0 +1,391 @@ +{ + "type": "Program", + "statements": [ + { + "type": "ImportDeclaration", + "source": { + "type": "StringLiteral", + "value": "./re_export_10", + "loc": { + "start": { + "line": 16, + "column": 20 + }, + "end": { + "line": 16, + "column": 36 + } + } + }, + "specifiers": [ + { + "type": "ImportNamespaceSpecifier", + "local": { + "type": "Identifier", + "name": "A", + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 13 + }, + "end": { + "line": 16, + "column": 14 + } + } + }, + "loc": { + "start": { + "line": 16, + "column": 8 + }, + "end": { + "line": 16, + "column": 14 + } + } + } + ], + "loc": { + "start": { + "line": 16, + "column": 1 + }, + "end": { + "line": 16, + "column": 36 + } + } + }, + { + "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": 18, + "column": 10 + }, + "end": { + "line": 18, + "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": 18, + "column": 10 + }, + "end": { + "line": 18, + "column": 14 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "returnType": { + "type": "ETSPrimitiveType", + "loc": { + "start": { + "line": 18, + "column": 19 + }, + "end": { + "line": 18, + "column": 23 + } + } + }, + "body": { + "type": "BlockStatement", + "statements": [ + { + "type": "ExpressionStatement", + "expression": { + "type": "CallExpression", + "callee": { + "type": "MemberExpression", + "object": { + "type": "Identifier", + "name": "A", + "decorators": [], + "loc": { + "start": { + "line": 20, + "column": 5 + }, + "end": { + "line": 20, + "column": 6 + } + } + }, + "property": { + "type": "Identifier", + "name": "foo", + "decorators": [], + "loc": { + "start": { + "line": 20, + "column": 7 + }, + "end": { + "line": 20, + "column": 10 + } + } + }, + "computed": false, + "optional": false, + "loc": { + "start": { + "line": 20, + "column": 5 + }, + "end": { + "line": 20, + "column": 10 + } + } + }, + "arguments": [], + "optional": false, + "loc": { + "start": { + "line": 20, + "column": 5 + }, + "end": { + "line": 20, + "column": 12 + } + } + }, + "loc": { + "start": { + "line": 20, + "column": 5 + }, + "end": { + "line": 20, + "column": 13 + } + } + } + ], + "loc": { + "start": { + "line": 19, + "column": 1 + }, + "end": { + "line": 21, + "column": 2 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 14 + }, + "end": { + "line": 21, + "column": 2 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 14 + }, + "end": { + "line": 21, + "column": 2 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 18, + "column": 1 + }, + "end": { + "line": 21, + "column": 2 + } + } + } + ], + "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": 22, + "column": 1 + } + } +} diff --git a/ets2panda/test/parser/ets/re_export/import_15.ets b/ets2panda/test/parser/ets/re_export/import_15.ets new file mode 100644 index 0000000000..91d3c71f02 --- /dev/null +++ b/ets2panda/test/parser/ets/re_export/import_15.ets @@ -0,0 +1,21 @@ +/* + * Copyright (c) 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. + */ + +import * as A from "./re_export_10" + +function main() : void +{ + A.foo(); +} diff --git a/ets2panda/test/parser/ets/re_export/import_7-expected.txt b/ets2panda/test/parser/ets/re_export/import_7-expected.txt index 06508df534..2cb3020a50 100644 --- a/ets2panda/test/parser/ets/re_export/import_7-expected.txt +++ b/ets2panda/test/parser/ets/re_export/import_7-expected.txt @@ -389,4 +389,3 @@ } } } -TypeError: Property 'foo' does not exist on type 're_export' [import_7.ets:20:7] diff --git a/ets2panda/test/parser/ets/re_export/re_export_10-expected.txt b/ets2panda/test/parser/ets/re_export/re_export_10-expected.txt new file mode 100644 index 0000000000..748856996c --- /dev/null +++ b/ets2panda/test/parser/ets/re_export/re_export_10-expected.txt @@ -0,0 +1,223 @@ +{ + "type": "Program", + "statements": [ + { + "type": "ETSReExportDeclaration", + "ets_import_declarations": { + "type": "ImportDeclaration", + "source": { + "type": "StringLiteral", + "value": "./re_export", + "loc": { + "start": { + "line": 16, + "column": 15 + }, + "end": { + "line": 16, + "column": 28 + } + } + }, + "specifiers": [ + { + "type": "ImportNamespaceSpecifier", + "local": { + "type": "Identifier", + "name": "", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 16, + "column": 8 + }, + "end": { + "line": 16, + "column": 14 + } + } + } + ], + "loc": { + "start": { + "line": 16, + "column": 8 + }, + "end": { + "line": 16, + "column": 28 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "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 + } + } + } + ], + "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": 18, + "column": 1 + } + } +} diff --git a/ets2panda/test/parser/ets/re_export/re_export_10.ets b/ets2panda/test/parser/ets/re_export/re_export_10.ets new file mode 100644 index 0000000000..15868fdd7b --- /dev/null +++ b/ets2panda/test/parser/ets/re_export/re_export_10.ets @@ -0,0 +1,17 @@ +/* + * Copyright (c) 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. + */ + +export * from "./re_export" + diff --git a/ets2panda/test/parser/ets/re_export/re_export_8-expected.txt b/ets2panda/test/parser/ets/re_export/re_export_8-expected.txt new file mode 100644 index 0000000000..18e18255ef --- /dev/null +++ b/ets2panda/test/parser/ets/re_export/re_export_8-expected.txt @@ -0,0 +1,238 @@ +{ + "type": "Program", + "statements": [ + { + "type": "ETSReExportDeclaration", + "ets_import_declarations": { + "type": "ImportDeclaration", + "source": { + "type": "StringLiteral", + "value": "./export", + "loc": { + "start": { + "line": 16, + "column": 19 + }, + "end": { + "line": 16, + "column": 29 + } + } + }, + "specifiers": [ + { + "type": "ImportSpecifier", + "local": { + "type": "Identifier", + "name": "foo", + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 9 + }, + "end": { + "line": 16, + "column": 12 + } + } + }, + "imported": { + "type": "Identifier", + "name": "foo", + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 9 + }, + "end": { + "line": 16, + "column": 12 + } + } + }, + "loc": { + "start": { + "line": 16, + "column": 9 + }, + "end": { + "line": 16, + "column": 12 + } + } + } + ], + "loc": { + "start": { + "line": 16, + "column": 8 + }, + "end": { + "line": 16, + "column": 29 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "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 + } + } + } + ], + "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": 18, + "column": 1 + } + } +} diff --git a/ets2panda/test/parser/ets/re_export/re_export_8.ets b/ets2panda/test/parser/ets/re_export/re_export_8.ets new file mode 100644 index 0000000000..60011e734e --- /dev/null +++ b/ets2panda/test/parser/ets/re_export/re_export_8.ets @@ -0,0 +1,17 @@ +/* + * Copyright (c) 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. + */ + +export {foo} from "./export" + diff --git a/ets2panda/test/parser/ets/re_export/re_export_9-expected.txt b/ets2panda/test/parser/ets/re_export/re_export_9-expected.txt new file mode 100644 index 0000000000..addfea23e0 --- /dev/null +++ b/ets2panda/test/parser/ets/re_export/re_export_9-expected.txt @@ -0,0 +1,238 @@ +{ + "type": "Program", + "statements": [ + { + "type": "ETSReExportDeclaration", + "ets_import_declarations": { + "type": "ImportDeclaration", + "source": { + "type": "StringLiteral", + "value": "./export", + "loc": { + "start": { + "line": 16, + "column": 31 + }, + "end": { + "line": 16, + "column": 41 + } + } + }, + "specifiers": [ + { + "type": "ImportSpecifier", + "local": { + "type": "Identifier", + "name": "fooAlias", + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 16 + }, + "end": { + "line": 16, + "column": 24 + } + } + }, + "imported": { + "type": "Identifier", + "name": "foo", + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 9 + }, + "end": { + "line": 16, + "column": 12 + } + } + }, + "loc": { + "start": { + "line": 16, + "column": 9 + }, + "end": { + "line": 16, + "column": 24 + } + } + } + ], + "loc": { + "start": { + "line": 16, + "column": 8 + }, + "end": { + "line": 16, + "column": 41 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "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 + } + } + } + ], + "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": 18, + "column": 1 + } + } +} diff --git a/ets2panda/test/parser/ets/re_export/re_export_9.ets b/ets2panda/test/parser/ets/re_export/re_export_9.ets new file mode 100644 index 0000000000..2ca1a91495 --- /dev/null +++ b/ets2panda/test/parser/ets/re_export/re_export_9.ets @@ -0,0 +1,17 @@ +/* + * Copyright (c) 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. + */ + +export {foo as fooAlias} from "./export" + diff --git a/ets2panda/varbinder/ETSBinder.cpp b/ets2panda/varbinder/ETSBinder.cpp index 36ef4f1eec..a1b9caea88 100644 --- a/ets2panda/varbinder/ETSBinder.cpp +++ b/ets2panda/varbinder/ETSBinder.cpp @@ -516,7 +516,6 @@ bool ETSBinder::AddImportNamespaceSpecifiersToTopBindings(ir::AstNode *const spe for (auto it : item->GetETSImportDeclarations()->Specifiers()) { if (it->IsImportNamespaceSpecifier() && !specifier->AsImportNamespaceSpecifier()->Local()->Name().Empty()) { - std::cerr << "Warning: import with alias cannot be used with re-export\n"; continue; } @@ -622,7 +621,14 @@ bool ETSBinder::AddImportSpecifiersToTopBindings(ir::AstNode *const specifier, return true; } - const auto &imported = importSpecifier->Imported()->AsIdentifier()->Name(); + auto imported = importSpecifier->Imported()->Name(); + + for (auto const item : import->Specifiers()) { + if (item->IsImportSpecifier() && item->AsImportSpecifier()->Local()->Name().Is(imported.Mutf8()) && + !item->AsImportSpecifier()->Local()->Name().Is(item->AsImportSpecifier()->Imported()->Name().Mutf8())) { + imported = item->AsImportSpecifier()->Imported()->Name(); + } + } auto *const var = FindImportSpecifiersVariable(imported, globalBindings, recordRes); -- Gitee