diff --git a/es2panda/binder/binder.cpp b/es2panda/binder/binder.cpp index e203801cb3ea4aa822012f5d1be8651d09e02bd6..c9a82aaca52af7acdc41c4b47d184c6c5ef75055 100644 --- a/es2panda/binder/binder.cpp +++ b/es2panda/binder/binder.cpp @@ -373,7 +373,7 @@ void Binder::BuildVarDeclaratorId(const ir::AstNode *parent, ir::AstNode *childN break; } - auto *variable = scope_->FindLocal(name); + auto *variable = scope_->FindLocal(name, ResolveBindingOptions::BINDINGS); if (Program()->Extension() == ScriptExtension::TS) { ident->SetVariable(variable); diff --git a/es2panda/binder/binder.h b/es2panda/binder/binder.h index 3d3bfe8f287dc03a933cfc311bd7c8a3dd6f766d..6391ed9bb1a874308096bddb98929f326af4f29e 100644 --- a/es2panda/binder/binder.h +++ b/es2panda/binder/binder.h @@ -75,6 +75,9 @@ public: template T *AddTsDecl(const lexer::SourcePosition &pos, bool isDeclare, Args &&... args); + template + T *AddTsDecl(const lexer::SourcePosition &pos, DeclarationFlags flag, bool isDeclare, Args &&... args); + ParameterDecl *AddParamDecl(const ir::AstNode *param); Scope *GetScope() const @@ -274,6 +277,21 @@ T *Binder::AddTsDecl(const lexer::SourcePosition &pos, bool isDeclare, Args &&.. ThrowRedeclaration(pos, decl->Name()); } +template +T *Binder::AddTsDecl(const lexer::SourcePosition &pos, DeclarationFlags flag, bool isDeclare, Args &&... args) +{ + T *decl = Allocator()->New(std::forward(args)...); + decl->AddFlag(flag); + decl->SetDeclare(isDeclare); + + if (scope_->AddTsDecl(Allocator(), decl, program_->Extension())) { + AddDeclarationName(decl->Name()); + return decl; + } + + ThrowRedeclaration(pos, decl->Name()); +} + template T *Binder::AddDecl(const lexer::SourcePosition &pos, bool isDeclare, Args &&... args) { diff --git a/es2panda/binder/declaration.cpp b/es2panda/binder/declaration.cpp index 0af567336506887c4beb0d376507d1762615de4b..215aac3046197b596243b3384e979508140029d1 100644 --- a/es2panda/binder/declaration.cpp +++ b/es2panda/binder/declaration.cpp @@ -15,6 +15,19 @@ #include "declaration.h" +#include "ir/ts/tsModuleDeclaration.h" + namespace panda::es2panda::binder { +bool NamespaceDecl::IsInstantiated() const +{ + auto tsModules = Decls(); + for (auto *it : tsModules) { + if (it->IsInstantiated()) { + return true; + } + } + return false; +} + } // namespace panda::es2panda::binder diff --git a/es2panda/binder/declaration.h b/es2panda/binder/declaration.h index 611241d570414b73d04305da3ce7824f5e86391f..757eb2e7f598946e7bf3c47825d51fd0b78fc3cc 100644 --- a/es2panda/binder/declaration.h +++ b/es2panda/binder/declaration.h @@ -258,6 +258,8 @@ public: { return DeclType::NAMESPACE; } + + bool IsInstantiated() const; }; class VarDecl : public Decl { diff --git a/es2panda/ir/module/exportDefaultDeclaration.cpp b/es2panda/ir/module/exportDefaultDeclaration.cpp index 1050faefd92588ec06e38fd990ca535ba6a84a7e..f84ef2f525c03dd83178b6936b3905d7be46c659 100644 --- a/es2panda/ir/module/exportDefaultDeclaration.cpp +++ b/es2panda/ir/module/exportDefaultDeclaration.cpp @@ -33,6 +33,9 @@ void ExportDefaultDeclaration::Dump(ir::AstDumper *dumper) const void ExportDefaultDeclaration::Compile(compiler::PandaGen *pg) const { + if (!decl_) { + return; + } decl_->Compile(pg); if (decl_->IsExpression()) { // export default [AssignmentExpression] diff --git a/es2panda/parser/module/sourceTextModuleRecord.cpp b/es2panda/parser/module/sourceTextModuleRecord.cpp index a6b213ed4a6bfe714aefb19d142f467c7e6de022..c0caa6d2b9053bc5cdae267f440282332b9dfbd2 100644 --- a/es2panda/parser/module/sourceTextModuleRecord.cpp +++ b/es2panda/parser/module/sourceTextModuleRecord.cpp @@ -187,4 +187,10 @@ namespace panda::es2panda::parser { (*index)++; } } + + void SourceTextModuleRecord::RemoveDefaultLocalExportEntry() + { + util::StringView localName = parser::SourceTextModuleRecord::DEFAULT_LOCAL_NAME; + localExportEntries_.erase(localName); + } } // namespace panda::es2panda::parser diff --git a/es2panda/parser/module/sourceTextModuleRecord.h b/es2panda/parser/module/sourceTextModuleRecord.h index 7e08fbe0f40fbcf700b0a646c6cdaebe3fa93c1b..d9851a24f3f4a615d0d854b17d3d1cc0f89aa9b7 100644 --- a/es2panda/parser/module/sourceTextModuleRecord.h +++ b/es2panda/parser/module/sourceTextModuleRecord.h @@ -91,6 +91,7 @@ public: void AddImportEntry(ImportEntry *entry); void AddStarImportEntry(ImportEntry *entry); bool AddLocalExportEntry(ExportEntry *entry); + void RemoveDefaultLocalExportEntry(); bool AddIndirectExportEntry(ExportEntry *entry); void AddStarExportEntry(ExportEntry *entry); diff --git a/es2panda/parser/parserImpl.h b/es2panda/parser/parserImpl.h index cf4e71e6c64a866df64448de409159b517eb806d..87652a2bd80492e518eb60a9c898ce3171b805bb 100644 --- a/es2panda/parser/parserImpl.h +++ b/es2panda/parser/parserImpl.h @@ -399,14 +399,18 @@ private: ir::Expression *ParseImportExpression(); ir::FunctionExpression *ParseFunctionExpression(ParserStatus newStatus = ParserStatus::NO_OPTS); ir::Expression *ParseOptionalChain(ir::Expression *leftSideExpr); - void ParseNameSpaceImport(ArenaVector *specifiers); + void ParseNameSpaceImport(ArenaVector *specifiers, bool isType); ir::Identifier *ParseNamedImport(const lexer::Token &importedToken); + binder::Decl *AddImportDecl(bool isType, + util::StringView name, + lexer::SourcePosition startPos, + binder::DeclarationFlags flag); ir::StringLiteral *ParseFromClause(bool requireFrom = true); - void ParseNamedImportSpecifiers(ArenaVector *specifiers); + void ParseNamedImportSpecifiers(ArenaVector *specifiers, bool isType); ir::Expression *ParseModuleReference(); - ir::AstNode *ParseImportDefaultSpecifier(ArenaVector *specifiers); - ir::AstNode *ParseImportSpecifiers(ArenaVector *specifiers); + ir::AstNode *ParseImportDefaultSpecifier(ArenaVector *specifiers, bool isType); + ir::AstNode *ParseImportSpecifiers(ArenaVector *specifiers, bool isType); void ValidateAssignmentTarget(ExpressionParseFlags flags, ir::Expression *node); void ValidateLvalueAssignmentTarget(ir::Expression *node) const; void ValidateArrowParameterBindings(const ir::Expression *node); diff --git a/es2panda/parser/statementParser.cpp b/es2panda/parser/statementParser.cpp index f4e09509064d55b4396d78f237c9fb3a94c6d0f4..f1082d18c81444b698b99fd09e691d0d6d9bab68 100644 --- a/es2panda/parser/statementParser.cpp +++ b/es2panda/parser/statementParser.cpp @@ -2711,7 +2711,7 @@ ir::Statement *ParserImpl::ParseExportDeclaration(StatementParsingFlags flags, } } -void ParserImpl::ParseNameSpaceImport(ArenaVector *specifiers) +void ParserImpl::ParseNameSpaceImport(ArenaVector *specifiers, bool isType) { lexer::SourcePosition namespaceStart = lexer_->GetToken().Start(); lexer_->NextToken(); // eat `*` character @@ -2728,13 +2728,25 @@ void ParserImpl::ParseNameSpaceImport(ArenaVector *specifiers) specifier->SetRange({namespaceStart, lexer_->GetToken().End()}); specifiers->push_back(specifier); - auto *decl = Binder()->AddDecl(namespaceStart, binder::DeclarationFlags::NAMESPACE_IMPORT, - false, local->Name()); + binder::Decl *decl = AddImportDecl(isType, local->Name(), namespaceStart, + binder::DeclarationFlags::NAMESPACE_IMPORT); decl->BindNode(specifier); lexer_->NextToken(); // eat local name } +binder::Decl *ParserImpl::AddImportDecl(bool isType, + util::StringView name, + lexer::SourcePosition startPos, + binder::DeclarationFlags flag) +{ + if (isType) { + binder::TSBinding tsBinding(Allocator(), name); + return Binder()->AddTsDecl(startPos, flag, false, tsBinding.View()); + } + return Binder()->AddDecl(startPos, flag, false, name); +} + ir::Identifier *ParserImpl::ParseNamedImport(const lexer::Token &importedToken) { if (importedToken.Type() != lexer::TokenType::LITERAL_IDENT) { @@ -2759,7 +2771,7 @@ ir::Identifier *ParserImpl::ParseNamedImport(const lexer::Token &importedToken) return local; } -void ParserImpl::ParseNamedImportSpecifiers(ArenaVector *specifiers) +void ParserImpl::ParseNamedImportSpecifiers(ArenaVector *specifiers, bool isType) { lexer_->NextToken(lexer::LexerNextTokenFlags::KEYWORD_TO_IDENT); // eat `{` character @@ -2787,8 +2799,7 @@ void ParserImpl::ParseNamedImportSpecifiers(ArenaVector *specifie specifier->SetRange({imported->Start(), local->End()}); specifiers->push_back(specifier); - auto *decl = Binder()->AddDecl(local->Start(), binder::DeclarationFlags::IMPORT, - false, local->Name()); + binder::Decl *decl = AddImportDecl(isType, local->Name(), local->Start(), binder::DeclarationFlags::IMPORT); decl->BindNode(specifier); if (lexer_->GetToken().Type() == lexer::TokenType::PUNCTUATOR_COMMA) { @@ -2838,7 +2849,7 @@ ir::Expression *ParserImpl::ParseModuleReference() return result; } -ir::AstNode *ParserImpl::ParseImportDefaultSpecifier(ArenaVector *specifiers) +ir::AstNode *ParserImpl::ParseImportDefaultSpecifier(ArenaVector *specifiers, bool isType) { ir::Identifier *local = ParseNamedImport(lexer_->GetToken()); lexer_->NextToken(); // eat local name @@ -2868,8 +2879,7 @@ ir::AstNode *ParserImpl::ParseImportDefaultSpecifier(ArenaVector specifier->SetRange(specifier->Local()->Range()); specifiers->push_back(specifier); - auto *decl = Binder()->AddDecl(local->Start(), binder::DeclarationFlags::IMPORT, - false, local->Name()); + binder::Decl *decl = AddImportDecl(isType, local->Name(), local->Start(), binder::DeclarationFlags::IMPORT); decl->BindNode(specifier); if (lexer_->GetToken().Type() == lexer::TokenType::PUNCTUATOR_COMMA) { @@ -2903,22 +2913,22 @@ ir::StringLiteral *ParserImpl::ParseFromClause(bool requireFrom) return source; } -ir::AstNode *ParserImpl::ParseImportSpecifiers(ArenaVector *specifiers) +ir::AstNode *ParserImpl::ParseImportSpecifiers(ArenaVector *specifiers, bool isType) { ASSERT(specifiers->empty()); // import [default] from 'source' if (lexer_->GetToken().Type() == lexer::TokenType::LITERAL_IDENT) { - ir::AstNode *astNode = ParseImportDefaultSpecifier(specifiers); + ir::AstNode *astNode = ParseImportDefaultSpecifier(specifiers, isType); if (astNode != nullptr) { return astNode; } } if (lexer_->GetToken().Type() == lexer::TokenType::PUNCTUATOR_MULTIPLY) { - ParseNameSpaceImport(specifiers); + ParseNameSpaceImport(specifiers, isType); } else if (lexer_->GetToken().Type() == lexer::TokenType::PUNCTUATOR_LEFT_BRACE) { - ParseNamedImportSpecifiers(specifiers); + ParseNamedImportSpecifiers(specifiers, isType); } return nullptr; } @@ -2964,7 +2974,7 @@ ir::Statement *ParserImpl::ParseImportDeclaration(StatementParsingFlags flags) ir::StringLiteral *source = nullptr; if (lexer_->GetToken().Type() != lexer::TokenType::LITERAL_STRING) { - ir::AstNode *astNode = ParseImportSpecifiers(&specifiers); + ir::AstNode *astNode = ParseImportSpecifiers(&specifiers, isType); if (astNode != nullptr) { ASSERT(astNode->IsTSImportEqualsDeclaration()); astNode->SetRange({startLoc, lexer_->GetToken().End()}); diff --git a/es2panda/parser/transformer/transformer.cpp b/es2panda/parser/transformer/transformer.cpp index d1b20892a856f290482b60a92c5a9b7b7fdc1ca1..f381314e962cb0a0dcead6dbb99c9fbae1ba7dc1 100644 --- a/es2panda/parser/transformer/transformer.cpp +++ b/es2panda/parser/transformer/transformer.cpp @@ -277,10 +277,17 @@ ir::UpdateNodes Transformer::VisitTSNode(ir::AstNode *childNode) case ir::AstNodeType::EXPORT_DEFAULT_DECLARATION: { auto *node = childNode->AsExportDefaultDeclaration(); auto *decl = node->Decl(); - if (!decl || !decl->IsClassDeclaration()) { - return VisitTSNodes(childNode); + ASSERT(decl != nullptr); + if (decl->IsClassDeclaration()) { + return VisitExportClassDeclaration(node); + } + // When we export default an identify 'a', a maybe a interface or type. So we should check here. + // if decl is not an identifier, it's won't be a type. + if (decl->IsIdentifier() && !IsValueReference(decl->AsIdentifier())) { + RemoveDefaultLocalExportEntry(); + return nullptr; } - return VisitExportClassDeclaration(node); + return VisitTSNodes(childNode); } case ir::AstNodeType::TS_IMPORT_EQUALS_DECLARATION: { auto *node = childNode->AsTSImportEqualsDeclaration(); @@ -1018,10 +1025,10 @@ std::vector Transformer::CreateClassDecorators(ir::ClassDeclarati ir::AstNode *Transformer::VisitTsImportEqualsDeclaration(ir::TSImportEqualsDeclaration *node) { - auto *express = node->ModuleReference(); - if (!IsInstantiatedTSModule(express, Scope())) { + if (!IsInstantiatedImportEquals(node, Scope())) { return node; } + auto *express = node->ModuleReference(); auto name = node->Id()->Name(); if (IsTsModule() && node->IsExport()) { auto moduleName = GetCurrentTSModuleName(); @@ -1046,37 +1053,39 @@ ir::AstNode *Transformer::VisitTsImportEqualsDeclaration(ir::TSImportEqualsDecla return res; } -bool Transformer::IsInstantiatedTSModule(const ir::Expression *node, binder::Scope *scope) const +bool Transformer::IsInstantiatedImportEquals(const ir::TSImportEqualsDeclaration *node, binder::Scope *scope) const { - auto *var = FindTSModuleVariable(node, scope); + if (!node) { + return false; + } + bool isType = true; + auto *var = FindTSModuleVariable(node->ModuleReference(), scope, &isType); if (var == nullptr) { - return true; + return !isType; } auto *decl = var->Declaration(); ASSERT(decl->IsNamespaceDecl()); - auto tsModules = decl->AsNamespaceDecl()->Decls(); - for (auto *it : tsModules) { - if (it->IsInstantiated()) { - return true; - } - } + return decl->AsNamespaceDecl()->IsInstantiated(); return false; } -binder::Variable *Transformer::FindTSModuleVariable(const ir::Expression *node, binder::Scope *scope) const +binder::Variable *Transformer::FindTSModuleVariable(const ir::Expression *node, + const binder::Scope *scope, + bool *isType) const { - if (node == nullptr) { + if (node == nullptr || !(node->IsTSQualifiedName() || node->IsIdentifier())) { return nullptr; } if (node->IsTSQualifiedName()) { auto *tsQualifiedName = node->AsTSQualifiedName(); - auto *var = FindTSModuleVariable(tsQualifiedName->Left(), scope); + auto *var = FindTSModuleVariable(tsQualifiedName->Left(), scope, isType); if (var == nullptr) { + // If it's not a namespace, we would set isType flag before. So we don't set isType here. return nullptr; } auto *exportTSBindings = var->AsNamespaceVariable()->GetExportBindings(); auto name = tsQualifiedName->Right()->Name(); - auto *res = exportTSBindings->FindExportTSVariable(name); + binder::Variable *res = exportTSBindings->FindExportTSVariable(name); if (res != nullptr) { return res; } @@ -1084,35 +1093,60 @@ binder::Variable *Transformer::FindTSModuleVariable(const ir::Expression *node, if (res != nullptr) { auto *node = res->Declaration()->Node(); return FindTSModuleVariable(node->Parent()->AsTSImportEqualsDeclaration()->ModuleReference(), - res->AsImportEqualsVariable()->GetScope()); + res->AsImportEqualsVariable()->GetScope(), isType); } + + // We process namespace and import equals before. So it should be a type, if it's not a js value or enum. + // And const enum was processed as enum in es2abc, so we don't thought it as type here. + // We should process const enum as type, if we change const enum to literal in es2abc later. + *isType = exportTSBindings->FindExportVariable(name) == nullptr && + exportTSBindings->FindExportTSVariable(name) == nullptr; + return nullptr; } - ASSERT(node->IsIdentifier()); + auto name = node->AsIdentifier()->Name(); auto *currentScope = scope; while (currentScope != nullptr) { - auto *res = currentScope->FindLocalTSVariable(name); - if (res == nullptr && currentScope->IsTSModuleScope()) { - res = currentScope->AsTSModuleScope()->FindExportTSVariable(name); - } + auto *res = FindTSVariable(currentScope, name); if (res != nullptr) { return res; } - res = currentScope->FindLocalTSVariable(name); - if (res == nullptr && currentScope->IsTSModuleScope()) { - res = currentScope->AsTSModuleScope()->FindExportTSVariable(name); - } + + res = FindTSVariable(currentScope, name); if (res != nullptr) { auto *node = res->Declaration()->Node(); return FindTSModuleVariable(node->Parent()->AsTSImportEqualsDeclaration()->ModuleReference(), - res->AsImportEqualsVariable()->GetScope()); + res->AsImportEqualsVariable()->GetScope(), isType); + } + + // Enum is not a module, so we return null here. + // Const enum was processed as enum in es2abc, so we don't process it as type here. + res = FindTSVariable(currentScope, name); + if (res != nullptr) { + *isType = false; + return nullptr; } + + // we don't process js variable here because it can't be used in import equals. currentScope = currentScope->Parent(); } + + // It should be an imported variable, so it won't be a type here. + *isType = false; return nullptr; } +template +binder::Variable *Transformer::FindTSVariable(const binder::Scope *scope, const util::StringView &name) const +{ + binder::Variable *res = scope->FindLocalTSVariable(name); + if (res == nullptr && scope->IsTSModuleScope()) { + res = scope->AsTSModuleScope()->FindExportTSVariable(name); + } + return res; +} + std::vector Transformer::VisitExportNamedVariable(ir::Statement *decl) { std::vector res; @@ -1753,8 +1787,8 @@ void Transformer::FindLocalTSVariables(binder::Scope *scope, const util::StringV case binder::TSBindingType::IMPORT_EQUALS: { v = scope->FindLocalTSVariable(name); if (v != nullptr && - !IsInstantiatedTSModule(v->AsImportEqualsVariable()->Declaration()->Node()-> - Parent()->AsTSImportEqualsDeclaration()->ModuleReference(), scope)) { + !IsInstantiatedImportEquals(v->AsImportEqualsVariable()->Declaration()->Node()-> + Parent()->AsTSImportEqualsDeclaration(), scope)) { v = nullptr; } break; @@ -1789,8 +1823,8 @@ void Transformer::FindExportTSVariables(binder::Scope *scope, const util::String case binder::TSBindingType::IMPORT_EQUALS: { v = scope->AsTSModuleScope()->FindExportTSVariable(name); if (v != nullptr && - !IsInstantiatedTSModule(v->AsImportEqualsVariable()->Declaration()->Node()-> - Parent()->AsTSImportEqualsDeclaration()->ModuleReference(), scope)) { + !IsInstantiatedImportEquals(v->AsImportEqualsVariable()->Declaration()->Node()-> + Parent()->AsTSImportEqualsDeclaration(), scope)) { v = nullptr; } break; @@ -2109,4 +2143,39 @@ void Transformer::ResetParentScopeForAstNode(ir::AstNode *childNode) const } } +bool Transformer::IsValueReference(ir::Identifier *node) +{ + auto scope = Scope(); + ASSERT(scope != nullptr); + auto name = node->Name(); + // If it's js value or enum, it won't be a type. + // Const enum was processed as enum in es2abc, so we don't process it as type here. + if (scope->FindLocal(name, binder::ResolveBindingOptions::BINDINGS) != nullptr || + scope->FindLocalTSVariable(name) != nullptr) { + return true; + } + + binder::Variable *var = nullptr; + + var = scope->FindLocalTSVariable(name); + if (var != nullptr) { + auto *decl = var->Declaration()->AsNamespaceDecl(); + return decl->IsInstantiated(); + } + + var = scope->FindLocalTSVariable(name); + if (var != nullptr) { + auto *node = var->Declaration()->Node()->AsTSImportEqualsDeclaration(); + return IsInstantiatedImportEquals(node, scope); + } + + return false; +} + +void Transformer::RemoveDefaultLocalExportEntry() +{ + auto *moduleRecord = GetSourceTextModuleRecord(); + moduleRecord->RemoveDefaultLocalExportEntry(); +} + } // namespace panda::es2panda::parser diff --git a/es2panda/parser/transformer/transformer.h b/es2panda/parser/transformer/transformer.h index 856ae31ec82e259723a1b5f8aee30a2c7e6f5098..80b6ae1907c37586ac954a0f76c401efdc6e0725 100644 --- a/es2panda/parser/transformer/transformer.h +++ b/es2panda/parser/transformer/transformer.h @@ -149,10 +149,11 @@ private: ir::Expression *GetClassMemberName(ir::Expression *key, bool isComputed, ir::Statement *node, bool inDecorator = true); binder::Scope *FindExportVariableInTsModuleScope(util::StringView name) const; - binder::Variable *FindTSModuleVariable(const ir::Expression *node, binder::Scope *scope) const; + binder::Variable *FindTSModuleVariable(const ir::Expression *node, const binder::Scope *scope, bool *isType) const; util::StringView FindPrivatePropertyBindName(util::StringView name); void AddExportLocalEntryItem(util::StringView name, const ir::Identifier *identifier); - bool IsInstantiatedTSModule(const ir::Expression *node, binder::Scope *scope) const; + void RemoveDefaultLocalExportEntry(); + bool IsInstantiatedImportEquals(const ir::TSImportEqualsDeclaration *node, binder::Scope *scope) const; void SetOriginalNode(ir::UpdateNodes res, ir::AstNode *originalNode) const; ir::UpdateNodes VisitTsEnumDeclaration(ir::TSEnumDeclaration *node, bool isExport = false); @@ -199,6 +200,11 @@ private: template ir::UpdateNodes VisitExportClassDeclaration(T *node); + template + binder::Variable *FindTSVariable(const binder::Scope *scope, const util::StringView &name) const; + + bool IsValueReference(ir::Identifier *node); + bool IsTsModule() const { return (tsModuleList_.size() != 0); diff --git a/es2panda/test/compiler/ts/cases/compiler/test-ts-namespace-19-expected.txt b/es2panda/test/compiler/ts/cases/compiler/test-ts-namespace-19-expected.txt new file mode 100644 index 0000000000000000000000000000000000000000..d00491fd7e5bb6fa28c517a0bb32b8b506539d4d --- /dev/null +++ b/es2panda/test/compiler/ts/cases/compiler/test-ts-namespace-19-expected.txt @@ -0,0 +1 @@ +1 diff --git a/es2panda/test/compiler/ts/cases/compiler/test-ts-namespace-19.ts b/es2panda/test/compiler/ts/cases/compiler/test-ts-namespace-19.ts new file mode 100644 index 0000000000000000000000000000000000000000..a8a6b5a0508f0253e4dc5866b04fee17ee20b52c --- /dev/null +++ b/es2panda/test/compiler/ts/cases/compiler/test-ts-namespace-19.ts @@ -0,0 +1,23 @@ +/* + * Copyright (c) 2022 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. + */ + + +namespace ns { + export interface I{} +} +import a = ns.I; +var a = 1; +print(a); + diff --git a/es2panda/test/compiler/ts/cases/conformance/types/test-ts-types-1-expected.txt b/es2panda/test/compiler/ts/cases/conformance/types/test-ts-types-1-expected.txt new file mode 100644 index 0000000000000000000000000000000000000000..d00491fd7e5bb6fa28c517a0bb32b8b506539d4d --- /dev/null +++ b/es2panda/test/compiler/ts/cases/conformance/types/test-ts-types-1-expected.txt @@ -0,0 +1 @@ +1 diff --git a/es2panda/test/compiler/ts/cases/conformance/types/test-ts-types-1.ts b/es2panda/test/compiler/ts/cases/conformance/types/test-ts-types-1.ts new file mode 100644 index 0000000000000000000000000000000000000000..b543f9f3d24b59210ecec17088e399b339012469 --- /dev/null +++ b/es2panda/test/compiler/ts/cases/conformance/types/test-ts-types-1.ts @@ -0,0 +1,19 @@ +/* + * Copyright (c) 2023 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. + */ + + +type a = number; +var a = 1; +print(a); diff --git a/es2panda/test/compiler/ts/projects/ts_import_type_project_3/test-ts-export-type.ts b/es2panda/test/compiler/ts/projects/ts_import_type_project_3/test-ts-export-type.ts new file mode 100644 index 0000000000000000000000000000000000000000..3e7cd6bc5a02ff503c2381827b4ef74bbe0bf696 --- /dev/null +++ b/es2panda/test/compiler/ts/projects/ts_import_type_project_3/test-ts-export-type.ts @@ -0,0 +1,19 @@ +/* + * Copyright (c) 2022 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. + */ + + +interface I {}; + +export default I; diff --git a/es2panda/test/compiler/ts/projects/ts_import_type_project_3/test-ts-import-type-exec-expected.txt b/es2panda/test/compiler/ts/projects/ts_import_type_project_3/test-ts-import-type-exec-expected.txt new file mode 100644 index 0000000000000000000000000000000000000000..d00491fd7e5bb6fa28c517a0bb32b8b506539d4d --- /dev/null +++ b/es2panda/test/compiler/ts/projects/ts_import_type_project_3/test-ts-import-type-exec-expected.txt @@ -0,0 +1 @@ +1 diff --git a/es2panda/test/compiler/ts/projects/ts_import_type_project_3/test-ts-import-type-exec.ts b/es2panda/test/compiler/ts/projects/ts_import_type_project_3/test-ts-import-type-exec.ts new file mode 100644 index 0000000000000000000000000000000000000000..6a5185a501af15d5790f6c294b74078442743c11 --- /dev/null +++ b/es2panda/test/compiler/ts/projects/ts_import_type_project_3/test-ts-import-type-exec.ts @@ -0,0 +1,19 @@ +/* + * Copyright (c) 2022 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 type I from './test-ts-export-type'; +var I = 1; +print(I); diff --git a/ts2panda/package-lock.json b/ts2panda/package-lock.json index 3acd9711c8b844755bb2983d3e197ac4468a856d..f7a8f41060f4516e5bd211f430f8b7cf6d47020b 100644 --- a/ts2panda/package-lock.json +++ b/ts2panda/package-lock.json @@ -4470,7 +4470,7 @@ }, "typescript": { "version": "file:deps/ohos-typescript-4.2.3-r2.tgz", - "integrity": "sha512-qabbDjNMHJD/ZLr9+GD+Emea1zA1FpbqPBgcDdJF4hZFc1mTfArp2A3tdOhcEPNdzaJpwgDtBGdkGO3pJdiOsA==", + "integrity": "sha512-EHgN7P6eAHEbBFXKMudrtbqwI4t9lhJQQLD9DcVplmbyORoDyar56cPD7pzVpDXsBuuteSHZaYYzo8QcNt2JpQ==", "dev": true }, "typical": {