diff --git a/es2panda/BUILD.gn b/es2panda/BUILD.gn index ed23cba1148da0c5fc285dec613bf4caf588c6ff..18dc68c07c33969c254e4cd6c60f4764b8e2749e 100644 --- a/es2panda/BUILD.gn +++ b/es2panda/BUILD.gn @@ -197,6 +197,7 @@ es2panda_src = [ "parser/parserImpl.cpp", "parser/program/program.cpp", "parser/statementParser.cpp", + "parser/transformer/transformer.cpp", "typescript/checker.cpp", "typescript/core/binaryLikeExpression.cpp", "typescript/core/destructuringContext.cpp", diff --git a/es2panda/CMakeLists.txt b/es2panda/CMakeLists.txt index 80e619467f5f4ab45c16b5e7a51456022fad7a14..d3ce0e9fb2537095d0621f6bea7ad1103f249765 100644 --- a/es2panda/CMakeLists.txt +++ b/es2panda/CMakeLists.txt @@ -243,6 +243,7 @@ set(ES2PANDA_LIB_SRC parser/parserImpl.cpp parser/program/program.cpp parser/statementParser.cpp + parser/transformer/transformer.cpp typescript/checker.cpp typescript/core/binaryLikeExpression.cpp typescript/core/destructuringContext.cpp diff --git a/es2panda/binder/binder.cpp b/es2panda/binder/binder.cpp index a094a339ee453509c84826ba16be5d8415e58c52..1a56f6cdc0bbce6209c0a9fd80bb441c54173c46 100644 --- a/es2panda/binder/binder.cpp +++ b/es2panda/binder/binder.cpp @@ -99,16 +99,21 @@ void Binder::AssignIndexToModuleVariable() program_->ModuleRecord()->AssignIndexToModuleVariable(topScope_->AsModuleScope()); } -void Binder::IdentifierAnalysis() +void Binder::IdentifierAnalysis(ResolveBindingFlags flags) { ASSERT(program_->Ast()); ASSERT(scope_ == topScope_); - BuildFunction(topScope_, MAIN_FUNC_NAME); - ResolveReferences(program_->Ast()); - AddMandatoryParams(); - if (topScope_->IsModuleScope()) { - AssignIndexToModuleVariable(); + bindingFlags_ = flags; + if (bindingFlags_ & ResolveBindingFlags::TS_BEFORE_TRANSFORM) { + ResolveReferences(program_->Ast()); + } else if (bindingFlags_ & ResolveBindingFlags::ALL) { + BuildFunction(topScope_, MAIN_FUNC_NAME); + ResolveReferences(program_->Ast()); + AddMandatoryParams(); + if (topScope_->IsModuleScope()) { + AssignIndexToModuleVariable(); + } } } @@ -229,12 +234,17 @@ void Binder::BuildFunction(FunctionScope *funcScope, util::StringView name) void Binder::BuildScriptFunction(Scope *outerScope, const ir::ScriptFunction *scriptFunc) { + if (bindingFlags_ & ResolveBindingFlags::TS_BEFORE_TRANSFORM) { + return; + } + if (scriptFunc->IsArrow()) { VariableScope *outerVarScope = outerScope->EnclosingVariableScope(); outerVarScope->AddFlag(VariableScopeFlags::INNER_ARROW); } - BuildFunction(scope_->AsFunctionScope(), util::Helpers::FunctionName(scriptFunc)); + ASSERT(scope_->IsFunctionScope() || scope_->IsTSModuleScope()); + BuildFunction(scope_->AsFunctionVariableScope(), util::Helpers::FunctionName(scriptFunc)); } void Binder::BuildVarDeclaratorId(const ir::AstNode *parent, ir::AstNode *childNode) @@ -571,11 +581,6 @@ void Binder::ResolveReference(const ir::AstNode *parent, ir::AstNode *childNode) ResolveReferences(childNode); break; } - case ir::AstNodeType::TS_MODULE_BLOCK: { - auto scopeCtx = LexicalScope::Enter(this, childNode->AsTSModuleBlock()->Scope()); - ResolveReferences(childNode); - break; - } default: { ResolveReferences(childNode); break; @@ -650,4 +655,25 @@ void Binder::AddMandatoryParams() } } } + +void Binder::AddDeclarationName(const util::StringView &name) +{ + if (extension_ != ScriptExtension::TS) { + return; + } + variableNames_.insert(name); + auto *scope = GetScope(); + while (scope != nullptr) { + if (scope->IsTSModuleScope()) { + scope->AsTSModuleScope()->AddDeclarationName(name); + } + scope = scope->Parent(); + } +} + +bool Binder::HasVariableName(const util::StringView &name) const +{ + return variableNames_.find(name) != variableNames_.end(); +} + } // namespace panda::es2panda::binder diff --git a/es2panda/binder/binder.h b/es2panda/binder/binder.h index e9213c472e5ba71165c7711659bbb279ff672a93..ebbbf6cb9289108431afdd17d9c32e21f762998b 100644 --- a/es2panda/binder/binder.h +++ b/es2panda/binder/binder.h @@ -46,9 +46,11 @@ public: explicit Binder(parser::Program *program, ScriptExtension extension) : program_(program), functionScopes_(Allocator()->Adapter()), - functionNames_(Allocator()->Adapter()) + functionNames_(Allocator()->Adapter()), + variableNames_(Allocator()->Adapter()), + extension_(extension) { - if (extension == ScriptExtension::TS) { + if (extension_ == ScriptExtension::TS) { bindingOptions_ = ResolveBindingOptions::ALL; return; } @@ -61,7 +63,7 @@ public: ~Binder() = default; void InitTopScope(); - void IdentifierAnalysis(); + void IdentifierAnalysis(ResolveBindingFlags flags = ResolveBindingFlags::ALL); template T *AddDecl(const lexer::SourcePosition &pos, Args &&... args); @@ -110,6 +112,15 @@ public: return program_; } + void SetProgram(parser::Program *program) + { + program_ = program; + } + + void AddDeclarationName(const util::StringView &name); + + bool HasVariableName(const util::StringView &name) const; + static constexpr std::string_view FUNCTION_ARGUMENTS = "arguments"; static constexpr std::string_view MANDATORY_PARAM_FUNC = "=f"; static constexpr std::string_view MANDATORY_PARAM_NEW_TARGET = "=nt"; @@ -187,7 +198,10 @@ private: ArenaVector functionScopes_; ResolveBindingOptions bindingOptions_; ArenaSet functionNames_; + ArenaSet variableNames_; size_t functionNameIndex_ {1}; + ResolveBindingFlags bindingFlags_ {ResolveBindingFlags::ALL}; + ScriptExtension extension_; }; template @@ -238,6 +252,7 @@ T *Binder::AddTsDecl(const lexer::SourcePosition &pos, Args &&... args) T *decl = Allocator()->New(std::forward(args)...); if (scope_->AddTsDecl(Allocator(), decl, program_->Extension())) { + AddDeclarationName(decl->Name()); return decl; } @@ -250,6 +265,7 @@ T *Binder::AddDecl(const lexer::SourcePosition &pos, Args &&... args) T *decl = Allocator()->New(std::forward(args)...); if (scope_->AddDecl(Allocator(), decl, program_->Extension())) { + AddDeclarationName(decl->Name()); return decl; } @@ -263,6 +279,7 @@ T *Binder::AddDecl(const lexer::SourcePosition &pos, DeclarationFlags flag, Args decl->AddFlag(flag); if (scope_->AddDecl(Allocator(), decl, program_->Extension())) { + AddDeclarationName(decl->Name()); return decl; } diff --git a/es2panda/binder/declaration.h b/es2panda/binder/declaration.h index 84053347deb8fa23943c8c27200d4ee6943ba682..c835e99e5ed2f3b1c06c231de62bb1c27a7c0a01 100644 --- a/es2panda/binder/declaration.h +++ b/es2panda/binder/declaration.h @@ -24,6 +24,7 @@ namespace panda::es2panda::ir { class AstNode; class ScriptFunction; class TSInterfaceDeclaration; +class TSModuleDeclaration; class ImportDeclaration; } // namespace panda::es2panda::ir @@ -235,9 +236,12 @@ public: } }; -class NameSpaceDecl : public Decl { +class NamespaceDecl : public MultiDecl { public: - explicit NameSpaceDecl(util::StringView name) : Decl(name) {} + explicit NamespaceDecl(ArenaAllocator *allocator, util::StringView name) + : MultiDecl(allocator, name) + { + } DeclType Type() const override { @@ -295,6 +299,16 @@ public: } }; +class ImportEqualsDecl : public Decl { +public: + explicit ImportEqualsDecl(util::StringView name) : Decl(name) {} + + DeclType Type() const override + { + return DeclType::IMPORT_EQUALS; + } +}; + } // namespace panda::es2panda::binder #endif diff --git a/es2panda/binder/scope.cpp b/es2panda/binder/scope.cpp index 634676482a8d63ea7f5b39091cba8c71b4bab17c..696521f1887da45376ff38bcfe1baf3a1ac91e21 100644 --- a/es2panda/binder/scope.cpp +++ b/es2panda/binder/scope.cpp @@ -305,6 +305,12 @@ bool FunctionScope::AddBinding(ArenaAllocator *allocator, Variable *currentVaria case DeclType::ENUM_LITERAL: { return AddTSBinding(allocator, currentVariable, newDecl, VariableFlags::ENUM_LITERAL); } + case DeclType::NAMESPACE: { + return AddTSBinding(allocator, newDecl, VariableFlags::NAMESPACE); + } + case DeclType::IMPORT_EQUALS: { + return AddTSBinding(allocator, newDecl, VariableFlags::IMPORT_EQUALS); + } case DeclType::INTERFACE: { return AddTSBinding(allocator, currentVariable, newDecl, VariableFlags::INTERFACE); } @@ -331,6 +337,12 @@ bool GlobalScope::AddBinding(ArenaAllocator *allocator, Variable *currentVariabl case DeclType::ENUM_LITERAL: { return AddTSBinding(allocator, currentVariable, newDecl, VariableFlags::ENUM_LITERAL); } + case DeclType::NAMESPACE: { + return AddTSBinding(allocator, newDecl, VariableFlags::NAMESPACE); + } + case DeclType::IMPORT_EQUALS: { + return AddTSBinding(allocator, newDecl, VariableFlags::IMPORT_EQUALS); + } case DeclType::INTERFACE: { return AddTSBinding(allocator, currentVariable, newDecl, VariableFlags::INTERFACE); } @@ -396,6 +408,12 @@ bool ModuleScope::AddBinding(ArenaAllocator *allocator, Variable *currentVariabl case DeclType::ENUM_LITERAL: { return AddTSBinding(allocator, currentVariable, newDecl, VariableFlags::ENUM_LITERAL); } + case DeclType::NAMESPACE: { + return AddTSBinding(allocator, newDecl, VariableFlags::NAMESPACE); + } + case DeclType::IMPORT_EQUALS: { + return AddTSBinding(allocator, newDecl, VariableFlags::IMPORT_EQUALS); + } case DeclType::INTERFACE: { return AddTSBinding(allocator, currentVariable, newDecl, VariableFlags::INTERFACE); } diff --git a/es2panda/binder/scope.h b/es2panda/binder/scope.h index 94b3791028e56c0f3558af5cb6b36aebd20cc862..7375e895306a4e02a8e03769fa7f79bb5cbc3806 100644 --- a/es2panda/binder/scope.h +++ b/es2panda/binder/scope.h @@ -42,6 +42,101 @@ class Variable; using VariableMap = ArenaUnorderedMap; +class TSBindings { +public: + explicit TSBindings(ArenaAllocator *allocator) : allocator_(allocator) {} + + template + bool AddTSVariable(const util::StringView &name, Variable *variable) + { + static_assert(type < TSBindingType::COUNT); + size_t index = GetIndex(type); + if (tsBindings_[index] == nullptr) { + tsBindings_[index] = allocator_->New(allocator_->Adapter()); + } + return tsBindings_[index]->insert({name, variable}).second; + } + + template + Variable *FindTSVariable(const util::StringView &name) const + { + static_assert(type < TSBindingType::COUNT); + size_t index = GetIndex(type); + if (tsBindings_[index] == nullptr) { + return nullptr; + } + auto res = tsBindings_[index]->find(name); + if (res == tsBindings_[index]->end()) { + return nullptr; + } + return res->second; + } + + bool InTSBindings(const util::StringView &name) const + { + for (size_t i = 0; i < GetIndex(TSBindingType::COUNT); i++) { + if (tsBindings_[i] && tsBindings_[i]->find(name) != tsBindings_[i]->end()) { + return true; + } + } + return false; + } + +private: + size_t GetIndex(TSBindingType type) const + { + return static_cast(type); + } + + ArenaAllocator *allocator_; + std::array(TSBindingType::COUNT)> tsBindings_ {}; +}; + +class ExportBindings { +public: + explicit ExportBindings(ArenaAllocator *allocator) + : exportBindings_(allocator->Adapter()), + exportTSBindings_(allocator) + { + } + + Variable *FindExportVariable(const util::StringView &name) const + { + auto res = exportBindings_.find(name); + if (res == exportBindings_.end()) { + return nullptr; + } + return res->second; + } + + bool AddExportVariable(const util::StringView &name, Variable *var) + { + return exportBindings_.insert({name, var}).second; + } + + bool InExportBindings(const util::StringView &name) const + { + auto res = FindExportVariable(name); + return res != nullptr || exportTSBindings_.InTSBindings(name); + } + + template + Variable *FindExportTSVariable(const util::StringView &name) const + { + return exportTSBindings_.FindTSVariable(name); + } + + template + bool AddExportTSVariable(const util::StringView &name, Variable *var) + { + return exportTSBindings_.AddTSVariable(name, var); + } + +private: + VariableMap exportBindings_; + TSBindings exportTSBindings_; +}; + class ScopeFindResult { public: ScopeFindResult() = default; @@ -216,9 +311,26 @@ public: bool HasVarDecl(const util::StringView &name) const; + template + Variable *FindLocalTSVariable(const util::StringView &name) const + { + return tsBindings_.FindTSVariable(name); + } + + template + void AddLocalTSVariable(const util::StringView &name, Variable *var) + { + tsBindings_.AddTSVariable(name, var); + } + + bool InLocalTSBindings(const util::StringView &name) const + { + return tsBindings_.InTSBindings(name); + } + protected: explicit Scope(ArenaAllocator *allocator, Scope *parent) - : parent_(parent), decls_(allocator->Adapter()), bindings_(allocator->Adapter()) + : parent_(parent), decls_(allocator->Adapter()), bindings_(allocator->Adapter()), tsBindings_(allocator) { } @@ -237,9 +349,15 @@ protected: bool AddLocal(ArenaAllocator *allocator, Variable *currentVariable, Decl *newDecl, [[maybe_unused]] ScriptExtension extension); + void SetParent(Scope *parent) + { + parent_ = parent; + } + Scope *parent_ {}; ArenaVector decls_; VariableMap bindings_; + TSBindings tsBindings_; const ir::AstNode *node_ {}; const compiler::IRNode *startIns_ {}; const compiler::IRNode *endIns_ {}; @@ -307,6 +425,9 @@ protected: template bool AddTSBinding(ArenaAllocator *allocator, Variable *currentVariable, Decl *newDecl, VariableFlags flags); + template + bool AddTSBinding(ArenaAllocator *allocator, Decl *newDecl, VariableFlags flags); + template bool AddLexical(ArenaAllocator *allocator, Variable *currentVariable, Decl *newDecl); @@ -425,6 +546,12 @@ public: return paramScope_; } + void AddBindsFromParam() + { + ASSERT(paramScope_); + this->bindings_.insert(paramScope_->Bindings().begin(), paramScope_->Bindings().end()); + } + protected: T *paramScope_; }; @@ -607,6 +734,68 @@ public: [[maybe_unused]] ScriptExtension extension) override; }; +class TSModuleScope : public FunctionScope { +public: + explicit TSModuleScope(ArenaAllocator *allocator, Scope *parent, ExportBindings *exportBindings) + : FunctionScope(allocator, nullptr), exportBindings_(exportBindings), variableNames_(allocator->Adapter()) + { + paramScope_ = allocator->New(allocator, parent); + paramScope_->BindFunctionScope(this); + SetParent(paramScope_); + } + + ScopeType Type() const override + { + return ScopeType::TSMODULE; + } + + template + Variable *FindExportTSVariable(const util::StringView &name) const + { + return exportBindings_->FindExportTSVariable(name); + } + + template + bool AddExportTSVariable(const util::StringView &name, Variable *var) + { + return exportBindings_->AddExportTSVariable(name, var); + } + + Variable *FindExportVariable(const util::StringView &name) const + { + return exportBindings_->FindExportVariable(name); + } + + bool AddExportVariable(const util::StringView &name, Variable *var) + { + return exportBindings_->AddExportVariable(name, var); + } + + bool AddExportVariable(const util::StringView &name) + { + return exportBindings_->AddExportVariable(name, FindLocal(name)); + } + + bool InExportBindings(const util::StringView &name) const + { + return exportBindings_->InExportBindings(name); + } + + void AddDeclarationName(const util::StringView &name) + { + variableNames_.insert(name); + } + + bool HasVariableName(const util::StringView &name) const + { + return variableNames_.find(name) != variableNames_.end(); + } + +private: + ExportBindings *exportBindings_; + ArenaSet variableNames_; +}; + inline VariableFlags VariableScope::DeclFlagToVariableFlag(DeclarationFlags declFlag) { VariableFlags varFlag = VariableFlags::NONE; @@ -681,10 +870,38 @@ bool VariableScope::AddTSBinding(ArenaAllocator *allocator, [[maybe_unused]] Var VariableFlags flags) { ASSERT(!currentVariable); + // TODO(xucheng): move the ts variables to tsBindings_ bindings_.insert({newDecl->Name(), allocator->New(newDecl, flags)}); return true; } +template +bool VariableScope::AddTSBinding(ArenaAllocator *allocator, Decl *newDecl, VariableFlags flags) +{ + switch (flags) { + case VariableFlags::NAMESPACE: { + return tsBindings_.AddTSVariable( + newDecl->Name(), allocator->New(newDecl, flags)); + } + case VariableFlags::ENUM_LITERAL: { + return tsBindings_.AddTSVariable( + newDecl->Name(), allocator->New(newDecl, flags)); + } + case VariableFlags::INTERFACE: { + return tsBindings_.AddTSVariable( + newDecl->Name(), allocator->New(newDecl, flags)); + } + case VariableFlags::IMPORT_EQUALS: { + return tsBindings_.AddTSVariable( + newDecl->Name(), allocator->New(newDecl, flags)); + } + default: { + break; + } + } + return false; +} + template bool VariableScope::AddLexical(ArenaAllocator *allocator, Variable *currentVariable, Decl *newDecl) { diff --git a/es2panda/binder/variable.cpp b/es2panda/binder/variable.cpp index 7407d8a5c59a48e55d4c6391d7c216e8ac85a7a4..7c82dd583c4efc94180795cbbd19b096c74ffadc 100644 --- a/es2panda/binder/variable.cpp +++ b/es2panda/binder/variable.cpp @@ -68,6 +68,8 @@ void LocalVariable::SetLexical(Scope *scope, util::Hotfix *hotfixHelper) void GlobalVariable::SetLexical([[maybe_unused]] Scope *scope, [[maybe_unused]] util::Hotfix *hotfixHelper) {} void ModuleVariable::SetLexical([[maybe_unused]] Scope *scope, [[maybe_unused]] util::Hotfix *hotfixHelper) {} void EnumVariable::SetLexical([[maybe_unused]] Scope *scope, [[maybe_unused]] util::Hotfix *hotfixHelper) {} +void NamespaceVariable::SetLexical([[maybe_unused]] Scope *scope, [[maybe_unused]] util::Hotfix *hotfixHelper) {} +void ImportEqualsVariable::SetLexical([[maybe_unused]] Scope *scope, [[maybe_unused]] util::Hotfix *hotfixHelper) {} void EnumVariable::ResetDecl(Decl *decl) { diff --git a/es2panda/binder/variable.h b/es2panda/binder/variable.h index a17b88885a19d065ed153e5c86eeee397dcdf73b..d9408beec3ad53a41f22fd6856222dd07ded7b6b 100644 --- a/es2panda/binder/variable.h +++ b/es2panda/binder/variable.h @@ -34,6 +34,7 @@ namespace panda::es2panda::binder { class Decl; class Scope; class VariableScope; +class ExportBindings; #define DECLARE_CLASSES(type, className) class className; VARIABLE_TYPES(DECLARE_CLASSES) @@ -240,5 +241,55 @@ private: bool backReference_ {}; }; +class NamespaceVariable : public Variable { +public: + explicit NamespaceVariable(Decl *decl, VariableFlags flags) : Variable(decl, flags) {} + + VariableType Type() const override + { + return VariableType::NAMESPACE; + } + + void SetLexical([[maybe_unused]] Scope *scope, [[maybe_unused]] util::Hotfix *hotfixHelper = nullptr) override; + + ExportBindings *GetExportBindings() + { + return exportBindings_; + } + + void SetExportBindings(ExportBindings *exportBindings) + { + exportBindings_ = exportBindings; + } + +private: + ExportBindings *exportBindings_ {nullptr}; +}; + +class ImportEqualsVariable : public Variable { +public: + explicit ImportEqualsVariable(Decl *decl, VariableFlags flags) : Variable(decl, flags) {} + + VariableType Type() const override + { + return VariableType::IMPORT_EQUALS; + } + + void SetLexical([[maybe_unused]] Scope *scope, [[maybe_unused]] util::Hotfix *hotfixHelper = nullptr) override; + + Scope *GetScope() + { + return scope_; + } + + void SetScope(Scope *scope) + { + scope_ = scope; + } + +private: + Scope *scope_ {nullptr}; +}; + } // namespace panda::es2panda::binder #endif diff --git a/es2panda/binder/variableFlags.h b/es2panda/binder/variableFlags.h index 3b659009702173998eded906aef61e91cfd76d94..cc60c28879ea140d791b815322c5a639aff68f81 100644 --- a/es2panda/binder/variableFlags.h +++ b/es2panda/binder/variableFlags.h @@ -16,6 +16,7 @@ #ifndef ES2PANDA_COMPILER_SCOPES_VARIABLE_FLAGS_H #define ES2PANDA_COMPILER_SCOPES_VARIABLE_FLAGS_H +#include #include namespace panda::es2panda::binder { @@ -29,13 +30,14 @@ namespace panda::es2panda::binder { _(PARAM, ParameterDecl) \ /* TS */ \ _(TYPE_ALIAS, TypeAliasDecl) \ - _(NAMESPACE, NameSpaceDecl) \ + _(NAMESPACE, NamespaceDecl) \ _(INTERFACE, InterfaceDecl) \ _(ENUM_LITERAL, EnumLiteralDecl) \ _(TYPE_PARAMETER, TypeParameterDecl) \ _(PROPERTY, PropertyDecl) \ _(METHOD, MethodDecl) \ - _(ENUM, EnumDecl) + _(ENUM, EnumDecl) \ + _(IMPORT_EQUALS, ImportEqualsDecl) enum class DeclType { NONE, @@ -55,7 +57,9 @@ enum class DeclType { _(LOOP_DECL, LoopDeclarationScope) \ _(FUNCTION, FunctionScope) \ _(GLOBAL, GlobalScope) \ - _(MODULE, ModuleScope) + _(MODULE, ModuleScope) \ + _(TSMODULE, TSModuleScope) + enum class ScopeType { #define GEN_SCOPE_TYPES(type, class_name) type, @@ -72,11 +76,20 @@ enum class ResolveBindingOptions { DEFINE_BITOPS(ResolveBindingOptions) -#define VARIABLE_TYPES(_) \ - _(LOCAL, LocalVariable) \ - _(GLOBAL, GlobalVariable) \ - _(MODULE, ModuleVariable) \ - _(ENUM, EnumVariable) +enum class ResolveBindingFlags { + ALL = 1U << 0U, + TS_BEFORE_TRANSFORM = 1U << 1U, +}; + +DEFINE_BITOPS(ResolveBindingFlags) + +#define VARIABLE_TYPES(_) \ + _(LOCAL, LocalVariable) \ + _(GLOBAL, GlobalVariable) \ + _(MODULE, ModuleVariable) \ + _(ENUM, EnumVariable) \ + _(NAMESPACE, NamespaceVariable) \ + _(IMPORT_EQUALS, ImportEqualsVariable) enum class VariableType { #define GEN_VARIABLE_TYPES(type, class_name) type, @@ -111,6 +124,8 @@ enum class VariableFlags { REST_ARG = 1 << 14, NUMERIC_NAME = 1 << 15, TYPE = 1 << 16, + NAMESPACE = 1 << 17, + IMPORT_EQUALS = 1 << 18, INDEX_LIKE = COMPUTED_INDEX | INDEX_NAME, @@ -150,6 +165,14 @@ enum class DeclarationFlags { DEFINE_BITOPS(DeclarationFlags) +enum class TSBindingType : size_t { + NAMESPACE = 0, + ENUM, + INTERFACE, + IMPORT_EQUALS, + COUNT, +}; + } // namespace panda::es2panda::binder #endif diff --git a/es2panda/compiler/base/hoisting.cpp b/es2panda/compiler/base/hoisting.cpp index 5f5b6370b65be4bfa2cc4122dbe808fd3a1a6ac8..2bf9a660b684094da30d87d2c2c73c0e2adaa92f 100644 --- a/es2panda/compiler/base/hoisting.cpp +++ b/es2panda/compiler/base/hoisting.cpp @@ -69,7 +69,8 @@ static void HoistFunction(PandaGen *pg, binder::Variable *var, const binder::Fun return; } - ASSERT(scope->IsFunctionScope() || scope->IsCatchScope() || scope->IsLocalScope() || scope->IsModuleScope()); + ASSERT(scope->IsFunctionScope() || scope->IsCatchScope() || scope->IsLocalScope() || + scope->IsModuleScope() || scope->IsTSModuleScope()); binder::ScopeFindResult result(decl->Name(), scope, 0, var); pg->DefineFunction(decl->Node(), scriptFunction, internalName); diff --git a/es2panda/compiler/core/compileQueue.cpp b/es2panda/compiler/core/compileQueue.cpp index f8709aa36dccf91705432f5920f71668ccd9f809..ea11d2bd33e33b34c914a75c9296c6559dc50e12 100644 --- a/es2panda/compiler/core/compileQueue.cpp +++ b/es2panda/compiler/core/compileQueue.cpp @@ -78,7 +78,7 @@ void CompileFunctionJob::Run() FunctionEmitter funcEmitter(&allocator, &pg); funcEmitter.Generate(context_->HotfixHelper()); - context_->GetEmitter()->AddFunction(&funcEmitter); + context_->GetEmitter()->AddFunction(&funcEmitter, context_); if (dependant_) { dependant_->Signal(); diff --git a/es2panda/compiler/core/compilerImpl.cpp b/es2panda/compiler/core/compilerImpl.cpp index 368783be9633a58dc2a8ce8f99c98582a2344101..f0e0448c2ea2d3f8c2d875a10b46089bdd7ff335 100644 --- a/es2panda/compiler/core/compilerImpl.cpp +++ b/es2panda/compiler/core/compilerImpl.cpp @@ -45,16 +45,6 @@ panda::pandasm::Program *CompilerImpl::Compile(parser::Program *program, const e context.AddHotfixHelper(hotfixHelper_); } - if (program->Extension() == ScriptExtension::TS && options.enableTypeCheck) { - ArenaAllocator localAllocator(SpaceType::SPACE_TYPE_COMPILER, nullptr, true); - auto checker = std::make_unique(&localAllocator, context.Binder()); - checker->StartChecker(); - } - - if (options.parseOnly) { - return nullptr; - } - queue_ = new CompileFuncQueue(threadCount_, &context); queue_->Schedule(); diff --git a/es2panda/compiler/core/emitter/emitter.cpp b/es2panda/compiler/core/emitter/emitter.cpp index a438ad9515aa03324004fd51a0488f8dbef0ab88..8d1b08456de1cd2dc067a6d97d5bbd245745f17c 100644 --- a/es2panda/compiler/core/emitter/emitter.cpp +++ b/es2panda/compiler/core/emitter/emitter.cpp @@ -371,7 +371,7 @@ Emitter::~Emitter() delete prog_; } -void Emitter::AddFunction(FunctionEmitter *func) +void Emitter::AddFunction(FunctionEmitter *func, CompilerContext *context) { std::lock_guard lock(m_); @@ -381,7 +381,8 @@ void Emitter::AddFunction(FunctionEmitter *func) for (auto &[idx, buf] : func->LiteralBuffers()) { auto literalArrayInstance = panda::pandasm::LiteralArray(std::move(buf)); - prog_->literalarray_table.emplace(std::to_string(idx), std::move(literalArrayInstance)); + prog_->literalarray_table.emplace(std::string(context->RecordName()) + std::to_string(idx), + std::move(literalArrayInstance)); } auto *function = func->Function(); diff --git a/es2panda/compiler/core/emitter/emitter.h b/es2panda/compiler/core/emitter/emitter.h index 3bf135f729da4656bed90d9673739d5ed3e30223..f461ece869c3362e4ae1276d874d8d8b030ceca3 100644 --- a/es2panda/compiler/core/emitter/emitter.h +++ b/es2panda/compiler/core/emitter/emitter.h @@ -102,7 +102,7 @@ public: NO_COPY_SEMANTIC(Emitter); NO_MOVE_SEMANTIC(Emitter); - void AddFunction(FunctionEmitter *func); + void AddFunction(FunctionEmitter *func, CompilerContext *context); void AddSourceTextModuleRecord(ModuleRecordEmitter *module, CompilerContext *context); static void DumpAsm(const panda::pandasm::Program *prog); panda::pandasm::Program *Finalize(bool dumpDebugInfo, util::Hotfix *hotfixHelper); diff --git a/es2panda/compiler/core/function.cpp b/es2panda/compiler/core/function.cpp index c2f0f7298e577bbe4928853c1e08e5c0ff6dcf3d..b9a4bce84f25fb5ddf8ee00fc4d97bebd9ee837a 100644 --- a/es2panda/compiler/core/function.cpp +++ b/es2panda/compiler/core/function.cpp @@ -16,7 +16,6 @@ #include "function.h" #include -#include #include #include #include @@ -27,6 +26,7 @@ #include #include #include +#include namespace panda::es2panda::compiler { @@ -185,7 +185,7 @@ static void CompileFunctionOrProgram(PandaGen *pg) } else { pg->FunctionInit(nullptr); - if (topScope->IsFunctionScope()) { + if (topScope->IsFunctionScope() || topScope->IsTSModuleScope()) { CompileFunction(pg); } else { ASSERT(topScope->IsGlobalScope() || topScope->IsModuleScope()); diff --git a/es2panda/es2panda.cpp b/es2panda/es2panda.cpp index 81d07bbdb21a68a7143ac650951183e0a23c9839..b5e978169bdcba563f215c2589461dd03268a30e 100644 --- a/es2panda/es2panda.cpp +++ b/es2panda/es2panda.cpp @@ -20,6 +20,8 @@ #include #include #include +#include +#include #include #include @@ -38,6 +40,9 @@ Compiler::Compiler(ScriptExtension ext) : Compiler(ext, DEFAULT_THREAD_COUNT) {} Compiler::Compiler(ScriptExtension ext, size_t threadCount) : parser_(new parser::ParserImpl(ext)), compiler_(new compiler::CompilerImpl(threadCount)) { + if (parser_->Extension() == ScriptExtension::TS) { + transformer_ = std::make_unique(parser_->Allocator()); + } } Compiler::~Compiler() @@ -67,11 +72,27 @@ panda::pandasm::Program *Compiler::Compile(const SourceFile &input, const Compil try { auto ast = parser_->Parse(fname, src, rname, kind); + ast.Binder()->SetProgram(&ast); if (options.dumpAst) { std::cout << ast.Dump() << std::endl; } + if (ast.Extension() == ScriptExtension::TS && options.enableTypeCheck) { + ArenaAllocator localAllocator(SpaceType::SPACE_TYPE_COMPILER, nullptr, true); + auto checker = std::make_unique(&localAllocator, ast.Binder()); + checker->StartChecker(); + } + + if (options.parseOnly) { + return nullptr; + } + + if (ast.Extension() == ScriptExtension::TS) { + transformer_->Transform(&ast); + ast.Binder()->IdentifierAnalysis(binder::ResolveBindingFlags::ALL); + } + std::string debugInfoSourceFile = options.debugInfoSourceFile.empty() ? sourcefile : options.debugInfoSourceFile; auto *prog = compiler_->Compile(&ast, options, debugInfoSourceFile); diff --git a/es2panda/es2panda.h b/es2panda/es2panda.h index 43cca7772c2388ce9f89d67da5d423c0cc51ef14..94878e743edfda2e834cf5fcb3c5821770106f45 100644 --- a/es2panda/es2panda.h +++ b/es2panda/es2panda.h @@ -31,6 +31,7 @@ struct Program; namespace panda::es2panda { namespace parser { class ParserImpl; +class Transformer; enum class ScriptKind; } // namespace parser @@ -195,6 +196,7 @@ public: private: parser::ParserImpl *parser_; compiler::CompilerImpl *compiler_; + std::unique_ptr transformer_ {nullptr}; Error error_; }; } // namespace panda::es2panda diff --git a/es2panda/ir/astNode.h b/es2panda/ir/astNode.h index bdaf842d0368bb4488f657cc6c8eb9c068301bc9..19fd7d0a72afbec85bf91e16e139f7c37c39b7cd 100644 --- a/es2panda/ir/astNode.h +++ b/es2panda/ir/astNode.h @@ -16,13 +16,14 @@ #ifndef ES2PANDA_IR_ASTNODE_H #define ES2PANDA_IR_ASTNODE_H +#include +#include + +#include +#include #include #include #include -#include - -#include -#include namespace panda::es2panda::compiler { class PandaGen; @@ -39,6 +40,9 @@ class AstNode; using NodeTraverser = std::function; +using UpdateNodes = std::variant>; +using NodeUpdater = std::function; + enum class AstNodeType { #define DECLARE_NODE_TYPES(nodeType, className) nodeType, AST_NODE_MAPPING(DECLARE_NODE_TYPES) @@ -258,6 +262,16 @@ public: parent_ = parent; } + const AstNode *Original() const + { + return original_; + } + + void SetOriginal(const AstNode *original) + { + original_ = original; + } + binder::Variable *Variable() const { return variable_; @@ -272,6 +286,7 @@ public: virtual void Dump(ir::AstDumper *dumper) const = 0; virtual void Compile([[maybe_unused]] compiler::PandaGen *pg) const = 0; virtual checker::Type *Check([[maybe_unused]] checker::Checker *checker) const = 0; + virtual void UpdateSelf([[maybe_unused]] const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) = 0; protected: void SetType(AstNodeType type) @@ -283,6 +298,7 @@ protected: lexer::SourceRange range_ {}; AstNodeType type_; binder::Variable *variable_ {nullptr}; + const AstNode *original_ {nullptr}; }; } // namespace panda::es2panda::ir diff --git a/es2panda/ir/astNodeMapping.h b/es2panda/ir/astNodeMapping.h index aa260c1c870fbc482bc8e2e6575de31fe8ab5f07..0ae3acc4294148294be526b4a74aa317e69743ce 100644 --- a/es2panda/ir/astNodeMapping.h +++ b/es2panda/ir/astNodeMapping.h @@ -128,6 +128,7 @@ _(TS_INDEX_SIGNATURE, TSIndexSignature) \ _(TS_TYPE_QUERY, TSTypeQuery) \ _(TS_AS_EXPRESSION, TSAsExpression) \ + _(TS_CLASS_IMPLEMENTS, TSClassImplements) \ _(TS_TYPE_ASSERTION, TSTypeAssertion) \ _(TAGGED_TEMPLATE_EXPRESSION, TaggedTemplateExpression) \ _(TAGGED_LITERAL, TaggedLiteral) \ diff --git a/es2panda/ir/base/catchClause.cpp b/es2panda/ir/base/catchClause.cpp index 8b1144f6d0803e1d23ce09c571978170dc192b9c..809d72eff5ced2229f49db4ab07e56868db923d1 100644 --- a/es2panda/ir/base/catchClause.cpp +++ b/es2panda/ir/base/catchClause.cpp @@ -15,6 +15,7 @@ #include "catchClause.h" +#include #include #include #include @@ -83,4 +84,15 @@ checker::Type *CatchClause::Check(checker::Checker *checker) const return nullptr; } +void CatchClause::UpdateSelf(const NodeUpdater &cb, binder::Binder *binder) +{ + if (param_) { + auto paramScopeCtx = binder::LexicalScope::Enter(binder, scope_->ParamScope()); + param_ = std::get(cb(param_))->AsExpression(); + } + + auto scopeCtx = binder::LexicalScope::Enter(binder, scope_); + body_ = std::get(cb(body_))->AsBlockStatement(); +} + } // namespace panda::es2panda::ir diff --git a/es2panda/ir/base/catchClause.h b/es2panda/ir/base/catchClause.h index 950a62e090ed04a8dd260a27e84282801002f64a..dac3dc4e66aa04cc49962a03db3730aa1196723a 100644 --- a/es2panda/ir/base/catchClause.h +++ b/es2panda/ir/base/catchClause.h @@ -72,6 +72,7 @@ public: void Dump(ir::AstDumper *dumper) const override; void Compile(compiler::PandaGen *pg) const override; checker::Type *Check(checker::Checker *checker) const override; + void UpdateSelf(const NodeUpdater &cb, binder::Binder *binder) override; protected: binder::CatchScope *scope_; diff --git a/es2panda/ir/base/classDefinition.cpp b/es2panda/ir/base/classDefinition.cpp index 2b850b83e580b2c1c047043a430369700e3980ea..ed8938dd01e0819a34a6be1ecdb061820b56a686 100644 --- a/es2panda/ir/base/classDefinition.cpp +++ b/es2panda/ir/base/classDefinition.cpp @@ -16,6 +16,7 @@ #include "classDefinition.h" #include +#include #include #include #include @@ -309,4 +310,39 @@ checker::Type *ClassDefinition::Check(checker::Checker *checker) const return checker->GlobalAnyType(); } +void ClassDefinition::UpdateSelf(const NodeUpdater &cb, binder::Binder *binder) +{ + auto scopeCtx = binder::LexicalScope::Enter(binder, scope_); + + if (ident_) { + ident_ = std::get(cb(ident_))->AsIdentifier(); + } + + if (typeParams_) { + typeParams_ = std::get(cb(typeParams_))->AsTSTypeParameterDeclaration(); + } + + if (superClass_) { + superClass_ = std::get(cb(superClass_))->AsExpression(); + } + + if (superTypeParams_) { + superTypeParams_ = std::get(cb(superTypeParams_))->AsTSTypeParameterInstantiation(); + } + + for (auto iter = implements_.begin(); iter != implements_.end(); iter++) { + *iter = std::get(cb(*iter))->AsTSClassImplements(); + } + + ctor_ = std::get(cb(ctor_))->AsMethodDefinition(); + + for (auto iter = body_.begin(); iter != body_.end(); iter++) { + *iter = std::get(cb(*iter))->AsStatement(); + } + + for (auto iter = indexSignatures_.begin(); iter != indexSignatures_.end(); iter++) { + *iter = std::get(cb(*iter))->AsTSIndexSignature(); + } +} + } // namespace panda::es2panda::ir diff --git a/es2panda/ir/base/classDefinition.h b/es2panda/ir/base/classDefinition.h index 2d58a5e1ddac96bb1af18b576f9068eb0e149966..a5210c2545bd74a402c91adefa4180b49dee1247 100644 --- a/es2panda/ir/base/classDefinition.h +++ b/es2panda/ir/base/classDefinition.h @@ -125,6 +125,7 @@ public: void Dump(ir::AstDumper *dumper) const override; void Compile(compiler::PandaGen *pg) const override; checker::Type *Check(checker::Checker *checker) const override; + void UpdateSelf(const NodeUpdater &cb, binder::Binder *binder) override; private: compiler::VReg CompileHeritageClause(compiler::PandaGen *pg) const; diff --git a/es2panda/ir/base/classProperty.cpp b/es2panda/ir/base/classProperty.cpp index b39f7f25305c09baacfd0f5477e573439174f463..0c8f44b9e91cbe361656d14e0137cea2bc93d27b 100644 --- a/es2panda/ir/base/classProperty.cpp +++ b/es2panda/ir/base/classProperty.cpp @@ -15,13 +15,16 @@ #include "classProperty.h" -#include -#include -#include - #include #include +#include "binder/binder.h" +#include "ir/astDump.h" +#include "ir/base/decorator.h" +#include "ir/base/scriptFunction.h" +#include "ir/expression.h" +#include "util/helpers.h" + namespace panda::es2panda::ir { void ClassProperty::Iterate(const NodeTraverser &cb) const @@ -65,4 +68,24 @@ checker::Type *ClassProperty::Check([[maybe_unused]] checker::Checker *checker) return nullptr; } +void ClassProperty::UpdateSelf(const NodeUpdater &cb, binder::Binder *binder) +{ + const ir::ScriptFunction *ctor = util::Helpers::GetContainingConstructor(this); + auto scopeCtx = binder::LexicalScope::Enter(binder, ctor->Scope()); + + key_ = std::get(cb(key_))->AsExpression(); + + if (value_) { + value_ = std::get(cb(value_))->AsExpression(); + } + + if (typeAnnotation_) { + typeAnnotation_ = std::get(cb(typeAnnotation_))->AsExpression(); + } + + for (auto iter = decorators_.begin(); iter != decorators_.end(); iter++) { + *iter = std::get(cb(*iter))->AsDecorator(); + } +} + } // namespace panda::es2panda::ir diff --git a/es2panda/ir/base/classProperty.h b/es2panda/ir/base/classProperty.h index e1bc499436164b6c94607e0cbc42c6925917c496..2380eea35677c8d100758fb3dccf79c225689055 100644 --- a/es2panda/ir/base/classProperty.h +++ b/es2panda/ir/base/classProperty.h @@ -85,6 +85,7 @@ public: void Dump(ir::AstDumper *dumper) const override; void Compile([[maybe_unused]] compiler::PandaGen *pg) const override; checker::Type *Check([[maybe_unused]] checker::Checker *checker) const override; + void UpdateSelf(const NodeUpdater &cb, binder::Binder *binder) override; private: Expression *key_; diff --git a/es2panda/ir/base/decorator.cpp b/es2panda/ir/base/decorator.cpp index 801230527b66ed75ff35e63f5bf4aff5c46edbfa..fefba92b4cd480b5b528901ebb1d53ea6596161e 100644 --- a/es2panda/ir/base/decorator.cpp +++ b/es2panda/ir/base/decorator.cpp @@ -37,4 +37,9 @@ checker::Type *Decorator::Check([[maybe_unused]] checker::Checker *checker) cons return nullptr; } +void Decorator::UpdateSelf(const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) +{ + expr_ = std::get(cb(expr_))->AsExpression(); +} + } // namespace panda::es2panda::ir diff --git a/es2panda/ir/base/decorator.h b/es2panda/ir/base/decorator.h index d01c7f01bf5016b64e8d251500e565383a496ac3..8ea87b4b04a88416f70a9322e1ecf513f5d76373 100644 --- a/es2panda/ir/base/decorator.h +++ b/es2panda/ir/base/decorator.h @@ -43,6 +43,7 @@ public: void Dump(ir::AstDumper *dumper) const override; void Compile([[maybe_unused]] compiler::PandaGen *pg) const override; checker::Type *Check([[maybe_unused]] checker::Checker *checker) const override; + void UpdateSelf(const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) override; private: Expression *expr_; diff --git a/es2panda/ir/base/metaProperty.cpp b/es2panda/ir/base/metaProperty.cpp index 043ba395e34204318f3502636131a37a3cd82a64..a8df61c894b9cd8c0b511d558146e12167c95322 100644 --- a/es2panda/ir/base/metaProperty.cpp +++ b/es2panda/ir/base/metaProperty.cpp @@ -63,4 +63,6 @@ checker::Type *MetaProperty::Check(checker::Checker *checker) const return checker->GlobalAnyType(); } +void MetaProperty::UpdateSelf([[maybe_unused]] const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) {} + } // namespace panda::es2panda::ir diff --git a/es2panda/ir/base/metaProperty.h b/es2panda/ir/base/metaProperty.h index 91eef27dc5acea2a2431b047b2d29b8b364cc17a..667de6e80c24d050dcc97bda0703c62ccb728081 100644 --- a/es2panda/ir/base/metaProperty.h +++ b/es2panda/ir/base/metaProperty.h @@ -44,6 +44,7 @@ public: void Dump(ir::AstDumper *dumper) const override; void Compile(compiler::PandaGen *pg) const override; checker::Type *Check(checker::Checker *checker) const override; + void UpdateSelf([[maybe_unused]] const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) override; private: MetaPropertyKind kind_; diff --git a/es2panda/ir/base/methodDefinition.cpp b/es2panda/ir/base/methodDefinition.cpp index a3798ecfba36c1c9dff5df9a485bc50d06a7e7ce..4c814e6eacc663f5e6482f76251e3890e74c5cb6 100644 --- a/es2panda/ir/base/methodDefinition.cpp +++ b/es2panda/ir/base/methodDefinition.cpp @@ -89,4 +89,18 @@ checker::Type *MethodDefinition::Check([[maybe_unused]] checker::Checker *checke return nullptr; } +void MethodDefinition::UpdateSelf(const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) +{ + key_ = std::get(cb(key_))->AsExpression(); + value_ = std::get(cb(value_))->AsFunctionExpression(); + + for (auto iter = overloads_.begin(); iter != overloads_.end(); iter++) { + *iter = std::get(cb(*iter))->AsMethodDefinition(); + } + + for (auto iter = decorators_.begin(); iter != decorators_.end(); iter++) { + *iter = std::get(cb(*iter))->AsDecorator(); + } +} + } // namespace panda::es2panda::ir diff --git a/es2panda/ir/base/methodDefinition.h b/es2panda/ir/base/methodDefinition.h index 1170e01693b500da39d45e68134bcc105aed9a82..77c5fc8c29741e9a4c69effa261d17417903f49e 100644 --- a/es2panda/ir/base/methodDefinition.h +++ b/es2panda/ir/base/methodDefinition.h @@ -116,6 +116,7 @@ public: void Dump(ir::AstDumper *dumper) const override; void Compile([[maybe_unused]] compiler::PandaGen *pg) const override; checker::Type *Check([[maybe_unused]] checker::Checker *checker) const override; + void UpdateSelf(const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) override; private: MethodDefinitionKind kind_; diff --git a/es2panda/ir/base/property.cpp b/es2panda/ir/base/property.cpp index 5802e381fac4a8a7ee44c1c8616d7938ee2003db..0bdc9c4d5d2383322f15700bf86ea2b75b5808ea 100644 --- a/es2panda/ir/base/property.cpp +++ b/es2panda/ir/base/property.cpp @@ -135,4 +135,10 @@ checker::Type *Property::Check([[maybe_unused]] checker::Checker *checker) const return nullptr; } +void Property::UpdateSelf(const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) +{ + key_ = std::get(cb(key_))->AsExpression(); + value_ = std::get(cb(value_))->AsExpression(); +} + } // namespace panda::es2panda::ir diff --git a/es2panda/ir/base/property.h b/es2panda/ir/base/property.h index f47df4b114e986183563d4bd394789c7eda03a9d..1a9b225378f0da0a430ca032673f8981eb7d54cb 100644 --- a/es2panda/ir/base/property.h +++ b/es2panda/ir/base/property.h @@ -112,6 +112,7 @@ public: void Dump(ir::AstDumper *dumper) const override; void Compile([[maybe_unused]] compiler::PandaGen *pg) const override; checker::Type *Check([[maybe_unused]] checker::Checker *checker) const override; + void UpdateSelf(const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) override; private: PropertyKind kind_; diff --git a/es2panda/ir/base/scriptFunction.cpp b/es2panda/ir/base/scriptFunction.cpp index 3e2f39e87f9fa9a9055c1661dca1d87724c92eeb..52a766ed10d2635603071a600c1fb4a8b4501181 100644 --- a/es2panda/ir/base/scriptFunction.cpp +++ b/es2panda/ir/base/scriptFunction.cpp @@ -15,6 +15,7 @@ #include "scriptFunction.h" +#include #include #include #include @@ -97,4 +98,31 @@ checker::Type *ScriptFunction::Check([[maybe_unused]] checker::Checker *checker) return nullptr; } +void ScriptFunction::UpdateSelf(const NodeUpdater &cb, binder::Binder *binder) +{ + if (id_) { + id_ = std::get(cb(id_))->AsIdentifier(); + } + + auto paramScopeCtx = binder::LexicalScope::Enter(binder, scope_->ParamScope()); + + if (typeParams_) { + typeParams_ = std::get(cb(typeParams_))->AsTSTypeParameterDeclaration(); + } + + for (auto iter = params_.begin(); iter != params_.end(); iter++) { + *iter = std::get(cb(*iter))->AsExpression(); + } + + if (returnTypeAnnotation_) { + returnTypeAnnotation_ = std::get(cb(returnTypeAnnotation_))->AsExpression(); + } + + auto scopeCtx = binder::LexicalScope::Enter(binder, scope_); + + if (body_) { + body_ = std::get(cb(body_)); + } +} + } // namespace panda::es2panda::ir diff --git a/es2panda/ir/base/scriptFunction.h b/es2panda/ir/base/scriptFunction.h index 9eb543f4d0935305ceec061f210805ac0593e45d..5a0db1202e379a1952decebbd95e10df1f5ebef1 100644 --- a/es2panda/ir/base/scriptFunction.h +++ b/es2panda/ir/base/scriptFunction.h @@ -161,6 +161,7 @@ public: void Dump(ir::AstDumper *dumper) const override; void Compile([[maybe_unused]] compiler::PandaGen *pg) const override; checker::Type *Check([[maybe_unused]] checker::Checker *checker) const override; + void UpdateSelf(const NodeUpdater &cb, binder::Binder *binder) override; private: binder::FunctionScope *scope_; diff --git a/es2panda/ir/base/spreadElement.cpp b/es2panda/ir/base/spreadElement.cpp index fec7ceadd1df2f5c1dc0541dc8ec76d8f9b8ab75..ca16f5cfd89b21271b314386dacb861e298db2df 100644 --- a/es2panda/ir/base/spreadElement.cpp +++ b/es2panda/ir/base/spreadElement.cpp @@ -102,4 +102,12 @@ checker::Type *SpreadElement::Check([[maybe_unused]] checker::Checker *checker) return nullptr; } +void SpreadElement::UpdateSelf(const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) +{ + argument_ = std::get(cb(argument_))->AsExpression(); + if (typeAnnotation_) { + typeAnnotation_ = std::get(cb(typeAnnotation_))->AsExpression(); + } +} + } // namespace panda::es2panda::ir diff --git a/es2panda/ir/base/spreadElement.h b/es2panda/ir/base/spreadElement.h index 858ef0122bac8767db0372f25baeffbb3d820c5e..ff01e3bc94f5cf7f2600589b852729a681b35741 100644 --- a/es2panda/ir/base/spreadElement.h +++ b/es2panda/ir/base/spreadElement.h @@ -57,6 +57,7 @@ public: void Dump(ir::AstDumper *dumper) const override; void Compile([[maybe_unused]] compiler::PandaGen *pg) const override; checker::Type *Check([[maybe_unused]] checker::Checker *checker) const override; + void UpdateSelf(const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) override; private: Expression *argument_; diff --git a/es2panda/ir/base/templateElement.cpp b/es2panda/ir/base/templateElement.cpp index 4013a17ddfc694df74a89c692ab5521d5d745dde..12dea11a0869a183f93643a2e79599cc13a02b29 100644 --- a/es2panda/ir/base/templateElement.cpp +++ b/es2panda/ir/base/templateElement.cpp @@ -39,4 +39,6 @@ checker::Type *TemplateElement::Check([[maybe_unused]] checker::Checker *checker return nullptr; } +void TemplateElement::UpdateSelf([[maybe_unused]] const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) {} + } // namespace panda::es2panda::ir diff --git a/es2panda/ir/base/templateElement.h b/es2panda/ir/base/templateElement.h index b0d136262e51dc020d32c180d87cbfcce30c6e31..f717c4f4e425f1812a369cf4185400095afd6770 100644 --- a/es2panda/ir/base/templateElement.h +++ b/es2panda/ir/base/templateElement.h @@ -53,6 +53,7 @@ public: void Dump(ir::AstDumper *dumper) const override; void Compile([[maybe_unused]] compiler::PandaGen *pg) const override; checker::Type *Check([[maybe_unused]] checker::Checker *checker) const override; + void UpdateSelf([[maybe_unused]] const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) override; protected: util::StringView raw_ {}; diff --git a/es2panda/ir/expressions/arrayExpression.cpp b/es2panda/ir/expressions/arrayExpression.cpp index 906912f18ef794ed1bfce2d7cb40e95704ffcb11..9df2ecbef092d94fa0e60f08c55ae45545221fcf 100644 --- a/es2panda/ir/expressions/arrayExpression.cpp +++ b/es2panda/ir/expressions/arrayExpression.cpp @@ -379,4 +379,11 @@ checker::Type *ArrayExpression::CheckPattern(checker::Checker *checker) const false); } +void ArrayExpression::UpdateSelf(const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) +{ + for (auto iter = elements_.begin(); iter != elements_.end(); iter++) { + *iter = std::get(cb(*iter))->AsExpression(); + } +} + } // namespace panda::es2panda::ir diff --git a/es2panda/ir/expressions/arrayExpression.h b/es2panda/ir/expressions/arrayExpression.h index 66ed5614cb37de958158fb88fa0f05b81d9c928b..f9bdd7f80cc46ee6d88c6f6836c4c5c6bc6e531e 100644 --- a/es2panda/ir/expressions/arrayExpression.h +++ b/es2panda/ir/expressions/arrayExpression.h @@ -86,6 +86,7 @@ public: void Compile(compiler::PandaGen *pg) const override; checker::Type *Check(checker::Checker *checker) const override; checker::Type *CheckPattern(checker::Checker *checker) const; + void UpdateSelf(const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) override; private: ArenaVector elements_; diff --git a/es2panda/ir/expressions/arrowFunctionExpression.cpp b/es2panda/ir/expressions/arrowFunctionExpression.cpp index 82e7ea038d154102be3ede8dbc37c3600fdd32b4..353ac9631ddfc63a038175b31938e76e7aaff09b 100644 --- a/es2panda/ir/expressions/arrowFunctionExpression.cpp +++ b/es2panda/ir/expressions/arrowFunctionExpression.cpp @@ -70,4 +70,9 @@ checker::Type *ArrowFunctionExpression::Check(checker::Checker *checker) const return funcType; } +void ArrowFunctionExpression::UpdateSelf(const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) +{ + func_ = std::get(cb(func_))->AsScriptFunction(); +} + } // namespace panda::es2panda::ir diff --git a/es2panda/ir/expressions/arrowFunctionExpression.h b/es2panda/ir/expressions/arrowFunctionExpression.h index 8c60759936428def9ce914489947282da5c1d6fc..d2d8d691827e6f3ee852086998acf950698114d7 100644 --- a/es2panda/ir/expressions/arrowFunctionExpression.h +++ b/es2panda/ir/expressions/arrowFunctionExpression.h @@ -52,6 +52,7 @@ public: void Dump(ir::AstDumper *dumper) const override; void Compile(compiler::PandaGen *pg) const override; checker::Type *Check(checker::Checker *checker) const override; + void UpdateSelf(const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) override; private: ScriptFunction *func_; diff --git a/es2panda/ir/expressions/assignmentExpression.cpp b/es2panda/ir/expressions/assignmentExpression.cpp index 0905c4fe2a367ffc1ca60eea09564f3bbce5611a..9e89751a4ed2e9f0fbac927886b146c30664f2ad 100644 --- a/es2panda/ir/expressions/assignmentExpression.cpp +++ b/es2panda/ir/expressions/assignmentExpression.cpp @@ -207,4 +207,10 @@ checker::Type *AssignmentExpression::Check(checker::Checker *checker) const return nullptr; } +void AssignmentExpression::UpdateSelf(const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) +{ + left_ = std::get(cb(left_))->AsExpression(); + right_ = std::get(cb(right_))->AsExpression(); +} + } // namespace panda::es2panda::ir diff --git a/es2panda/ir/expressions/assignmentExpression.h b/es2panda/ir/expressions/assignmentExpression.h index 53b240cc355d182d4a8e7d0b883132afe6cc0b72..93f92c9b31c61f13ee45e94eb25c7463372386a1 100644 --- a/es2panda/ir/expressions/assignmentExpression.h +++ b/es2panda/ir/expressions/assignmentExpression.h @@ -75,6 +75,7 @@ public: void Compile(compiler::PandaGen *pg) const override; void CompilePattern(compiler::PandaGen *pg) const; checker::Type *Check(checker::Checker *checker) const override; + void UpdateSelf(const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) override; private: Expression *left_; diff --git a/es2panda/ir/expressions/awaitExpression.cpp b/es2panda/ir/expressions/awaitExpression.cpp index 32b76645d99289b1a353851a6480cece40945a11..a4c74d986e3f3cb116ffc86c5fade65ef8224070 100644 --- a/es2panda/ir/expressions/awaitExpression.cpp +++ b/es2panda/ir/expressions/awaitExpression.cpp @@ -53,4 +53,11 @@ checker::Type *AwaitExpression::Check(checker::Checker *checker) const return checker->GlobalAnyType(); } +void AwaitExpression::UpdateSelf(const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) +{ + if (argument_) { + argument_ = std::get(cb(argument_))->AsExpression(); + } +} + } // namespace panda::es2panda::ir diff --git a/es2panda/ir/expressions/awaitExpression.h b/es2panda/ir/expressions/awaitExpression.h index 8759f5c05349b624851e0cbe0ad621e0775909ce..3386735901e5f0e7be5f447c04247679dedba28d 100644 --- a/es2panda/ir/expressions/awaitExpression.h +++ b/es2panda/ir/expressions/awaitExpression.h @@ -42,6 +42,7 @@ public: void Dump(ir::AstDumper *dumper) const override; void Compile(compiler::PandaGen *pg) const override; checker::Type *Check(checker::Checker *checker) const override; + void UpdateSelf(const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) override; private: Expression *argument_; diff --git a/es2panda/ir/expressions/binaryExpression.cpp b/es2panda/ir/expressions/binaryExpression.cpp index b34d315374d101bd1318826ee4e66f230cd3c16a..58fafd3d1a41622633100c6088c0469c3a934243 100644 --- a/es2panda/ir/expressions/binaryExpression.cpp +++ b/es2panda/ir/expressions/binaryExpression.cpp @@ -157,4 +157,10 @@ checker::Type *BinaryExpression::Check(checker::Checker *checker) const return nullptr; } +void BinaryExpression::UpdateSelf(const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) +{ + left_ = std::get(cb(left_))->AsExpression(); + right_ = std::get(cb(right_))->AsExpression(); +} + } // namespace panda::es2panda::ir diff --git a/es2panda/ir/expressions/binaryExpression.h b/es2panda/ir/expressions/binaryExpression.h index f44860fd8243c2c9831a4ccd61f0b3651509ba6b..8ac98c5c5794495f44e019b7b1f55415337d83ab 100644 --- a/es2panda/ir/expressions/binaryExpression.h +++ b/es2panda/ir/expressions/binaryExpression.h @@ -79,6 +79,7 @@ public: void Compile(compiler::PandaGen *pg) const override; void CompileLogical(compiler::PandaGen *pg) const; checker::Type *Check(checker::Checker *checker) const override; + void UpdateSelf(const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) override; private: Expression *left_; diff --git a/es2panda/ir/expressions/callExpression.cpp b/es2panda/ir/expressions/callExpression.cpp index 881b6f507822ef6fefd27d1e34779a465439d0e2..3c83bbc32eeccdc82008f5e820f11a02887b3df3 100644 --- a/es2panda/ir/expressions/callExpression.cpp +++ b/es2panda/ir/expressions/callExpression.cpp @@ -169,4 +169,17 @@ checker::Type *CallExpression::Check(checker::Checker *checker) const return nullptr; } +void CallExpression::UpdateSelf(const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) +{ + callee_ = std::get(cb(callee_))->AsExpression(); + + if (typeParams_) { + typeParams_ = std::get(cb(typeParams_))->AsTSTypeParameterInstantiation(); + } + + for (auto iter = arguments_.begin(); iter != arguments_.end(); iter++) { + *iter = std::get(cb(*iter))->AsExpression(); + } +} + } // namespace panda::es2panda::ir diff --git a/es2panda/ir/expressions/callExpression.h b/es2panda/ir/expressions/callExpression.h index 406496b71f3d881daa76c70e3ff828feab49db1e..18576bd2b956dfee038fd1864922a5426cd669b2 100644 --- a/es2panda/ir/expressions/callExpression.h +++ b/es2panda/ir/expressions/callExpression.h @@ -73,6 +73,7 @@ public: void Dump(ir::AstDumper *dumper) const override; void Compile(compiler::PandaGen *pg) const override; checker::Type *Check(checker::Checker *checker) const override; + void UpdateSelf(const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) override; private: compiler::VReg CreateSpreadArguments(compiler::PandaGen *pg) const; diff --git a/es2panda/ir/expressions/chainExpression.cpp b/es2panda/ir/expressions/chainExpression.cpp index 495cb42bea1b760001b180d33fc86a21269b13e4..d2656c05ac78ce57eadf7be05652bd865fda59c9 100644 --- a/es2panda/ir/expressions/chainExpression.cpp +++ b/es2panda/ir/expressions/chainExpression.cpp @@ -50,4 +50,9 @@ checker::Type *ChainExpression::Check(checker::Checker *checker) const return expression_->Check(checker); } +void ChainExpression::UpdateSelf(const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) +{ + expression_ = std::get(cb(expression_))->AsExpression(); +} + } // namespace panda::es2panda::ir diff --git a/es2panda/ir/expressions/chainExpression.h b/es2panda/ir/expressions/chainExpression.h index faafcdef3e0d21f7a0336acb45ed6f963df9a51a..3077fe8d0267a87fe1cff68dcc6952ef92c20da6 100644 --- a/es2panda/ir/expressions/chainExpression.h +++ b/es2panda/ir/expressions/chainExpression.h @@ -45,6 +45,7 @@ public: void Dump(ir::AstDumper *dumper) const override; void Compile(compiler::PandaGen *pg) const override; checker::Type *Check(checker::Checker *checker) const override; + void UpdateSelf(const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) override; private: Expression *expression_; diff --git a/es2panda/ir/expressions/classExpression.cpp b/es2panda/ir/expressions/classExpression.cpp index 20580662a214c06f3a4af45ca7ff7be548063337..1b9ccbf2b7b8533c9181a3d23848043245dc4304 100644 --- a/es2panda/ir/expressions/classExpression.cpp +++ b/es2panda/ir/expressions/classExpression.cpp @@ -40,4 +40,9 @@ checker::Type *ClassExpression::Check([[maybe_unused]] checker::Checker *checker return nullptr; } +void ClassExpression::UpdateSelf(const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) +{ + def_ = std::get(cb(def_))->AsClassDefinition(); +} + } // namespace panda::es2panda::ir diff --git a/es2panda/ir/expressions/classExpression.h b/es2panda/ir/expressions/classExpression.h index b478ab42297232a64347e7fda53ac2985042a53e..b4f350b3ee70e4f44126d93b81175abc4b9e1341 100644 --- a/es2panda/ir/expressions/classExpression.h +++ b/es2panda/ir/expressions/classExpression.h @@ -44,6 +44,7 @@ public: void Dump(ir::AstDumper *dumper) const override; void Compile(compiler::PandaGen *pg) const override; checker::Type *Check([[maybe_unused]] checker::Checker *checker) const override; + void UpdateSelf(const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) override; private: ClassDefinition *def_; diff --git a/es2panda/ir/expressions/conditionalExpression.cpp b/es2panda/ir/expressions/conditionalExpression.cpp index 102342f507a042c9c048c87f64c7a9836ddd333e..e1bd59e64811d509e5c48bcd9b3f9555eb5e0c52 100644 --- a/es2panda/ir/expressions/conditionalExpression.cpp +++ b/es2panda/ir/expressions/conditionalExpression.cpp @@ -61,4 +61,11 @@ checker::Type *ConditionalExpression::Check(checker::Checker *checker) const return checker->CreateUnionType({consequentType, alternateType}); } +void ConditionalExpression::UpdateSelf(const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) +{ + test_ = std::get(cb(test_))->AsExpression(); + consequent_ = std::get(cb(consequent_))->AsExpression(); + alternate_ = std::get(cb(alternate_))->AsExpression(); +} + } // namespace panda::es2panda::ir diff --git a/es2panda/ir/expressions/conditionalExpression.h b/es2panda/ir/expressions/conditionalExpression.h index 10fb8c4e95b96eb400d752921b2607f1903fa11f..ae40889e8112e9dae991bbea523b8230f66ee4af 100644 --- a/es2panda/ir/expressions/conditionalExpression.h +++ b/es2panda/ir/expressions/conditionalExpression.h @@ -65,6 +65,7 @@ public: void Dump(ir::AstDumper *dumper) const override; void Compile(compiler::PandaGen *pg) const override; checker::Type *Check(checker::Checker *checker) const override; + void UpdateSelf(const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) override; private: Expression *test_; diff --git a/es2panda/ir/expressions/functionExpression.cpp b/es2panda/ir/expressions/functionExpression.cpp index a4e5d34126187beaa24031e6f35262dad5d66f1c..4982bcd57f61bcbd08070c3a9f421819fba5a53e 100644 --- a/es2panda/ir/expressions/functionExpression.cpp +++ b/es2panda/ir/expressions/functionExpression.cpp @@ -68,4 +68,9 @@ checker::Type *FunctionExpression::Check(checker::Checker *checker) const return funcType; } +void FunctionExpression::UpdateSelf(const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) +{ + func_ = std::get(cb(func_))->AsScriptFunction(); +} + } // namespace panda::es2panda::ir diff --git a/es2panda/ir/expressions/functionExpression.h b/es2panda/ir/expressions/functionExpression.h index 23555b6416837edc626a220c23fdafeab8c306b8..3211855b980adfc96fa76f52ad833501dc2f89c0 100644 --- a/es2panda/ir/expressions/functionExpression.h +++ b/es2panda/ir/expressions/functionExpression.h @@ -44,6 +44,7 @@ public: void Dump(ir::AstDumper *dumper) const override; void Compile(compiler::PandaGen *pg) const override; checker::Type *Check(checker::Checker *checker) const override; + void UpdateSelf(const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) override; private: ScriptFunction *func_; diff --git a/es2panda/ir/expressions/identifier.cpp b/es2panda/ir/expressions/identifier.cpp index 7662a99ac0bc771a621d8ede217408ddc002cb89..26989d93db1d74d1e3aa1321e153970ce16819cb 100644 --- a/es2panda/ir/expressions/identifier.cpp +++ b/es2panda/ir/expressions/identifier.cpp @@ -99,4 +99,15 @@ checker::Type *Identifier::Check(checker::Checker *checker) const return checker->GetTypeOfVariable(Variable()); } +void Identifier::UpdateSelf(const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) +{ + if (typeAnnotation_) { + typeAnnotation_ = std::get(cb(typeAnnotation_))->AsExpression(); + } + + for (auto iter = decorators_.begin(); iter != decorators_.end(); iter++) { + *iter = std::get(cb(*iter))->AsDecorator(); + } +} + } // namespace panda::es2panda::ir diff --git a/es2panda/ir/expressions/identifier.h b/es2panda/ir/expressions/identifier.h index fce780b661feb691480d2f651d95d9138f520292..543397f6c6abdb5315f787e0c5120857159f88a4 100644 --- a/es2panda/ir/expressions/identifier.h +++ b/es2panda/ir/expressions/identifier.h @@ -126,6 +126,7 @@ public: void Dump(ir::AstDumper *dumper) const override; void Compile(compiler::PandaGen *pg) const override; checker::Type *Check(checker::Checker *checker) const override; + void UpdateSelf(const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) override; private: util::StringView name_; diff --git a/es2panda/ir/expressions/importExpression.cpp b/es2panda/ir/expressions/importExpression.cpp index ec88d45b4d142d9405a32e9419bc9ee7cd353e37..fbd4020a3b1aa6be24fb171259c9e8b5cf68c17d 100644 --- a/es2panda/ir/expressions/importExpression.cpp +++ b/es2panda/ir/expressions/importExpression.cpp @@ -41,4 +41,9 @@ checker::Type *ImportExpression::Check([[maybe_unused]] checker::Checker *checke return nullptr; } +void ImportExpression::UpdateSelf(const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) +{ + source_ = std::get(cb(source_))->AsExpression(); +} + } // namespace panda::es2panda::ir diff --git a/es2panda/ir/expressions/importExpression.h b/es2panda/ir/expressions/importExpression.h index efee65dcc47a8f09987ec0ef633b2624ae15b2a6..d3affc819a61ac39fef09a2e8fc4ea9915dd8066 100644 --- a/es2panda/ir/expressions/importExpression.h +++ b/es2panda/ir/expressions/importExpression.h @@ -37,6 +37,7 @@ public: void Dump(ir::AstDumper *dumper) const override; void Compile(compiler::PandaGen *pg) const override; checker::Type *Check([[maybe_unused]] checker::Checker *checker) const override; + void UpdateSelf(const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) override; private: Expression *source_; diff --git a/es2panda/ir/expressions/literals/bigIntLiteral.cpp b/es2panda/ir/expressions/literals/bigIntLiteral.cpp index 19290522c68df50fa8b494509ed8d2985891361f..0a274fa6a227063a2e92c215839d7d85c1282f9a 100644 --- a/es2panda/ir/expressions/literals/bigIntLiteral.cpp +++ b/es2panda/ir/expressions/literals/bigIntLiteral.cpp @@ -46,4 +46,6 @@ checker::Type *BigIntLiteral::Check(checker::Checker *checker) const return newBigintLiteralType; } +void BigIntLiteral::UpdateSelf([[maybe_unused]] const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) {} + } // namespace panda::es2panda::ir diff --git a/es2panda/ir/expressions/literals/bigIntLiteral.h b/es2panda/ir/expressions/literals/bigIntLiteral.h index 2890dbab670bfc2f62467de10e6194f563953f11..ef1aee885f5adc1992385e46f9a61c9015740e21 100644 --- a/es2panda/ir/expressions/literals/bigIntLiteral.h +++ b/es2panda/ir/expressions/literals/bigIntLiteral.h @@ -48,6 +48,7 @@ public: void Dump(ir::AstDumper *dumper) const override; void Compile(compiler::PandaGen *pg) const override; checker::Type *Check(checker::Checker *checker) const override; + void UpdateSelf([[maybe_unused]] const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) override; private: util::StringView src_; diff --git a/es2panda/ir/expressions/literals/booleanLiteral.cpp b/es2panda/ir/expressions/literals/booleanLiteral.cpp index b0dd0f4fca994a2a5f9b89886bfaf60ef1094c91..018727b42955c4ac82acf9893ae435c798d5febd 100644 --- a/es2panda/ir/expressions/literals/booleanLiteral.cpp +++ b/es2panda/ir/expressions/literals/booleanLiteral.cpp @@ -38,4 +38,6 @@ checker::Type *BooleanLiteral::Check(checker::Checker *checker) const return boolean_ ? checker->GlobalTrueType() : checker->GlobalFalseType(); } +void BooleanLiteral::UpdateSelf([[maybe_unused]] const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) {} + } // namespace panda::es2panda::ir diff --git a/es2panda/ir/expressions/literals/booleanLiteral.h b/es2panda/ir/expressions/literals/booleanLiteral.h index 384a6e36e8c153253d035bad82387423fe228a87..24bcb03114b146f1c23a0b6e8dff377623cd3fac 100644 --- a/es2panda/ir/expressions/literals/booleanLiteral.h +++ b/es2panda/ir/expressions/literals/booleanLiteral.h @@ -47,6 +47,7 @@ public: void Dump(ir::AstDumper *dumper) const override; void Compile(compiler::PandaGen *pg) const override; checker::Type *Check(checker::Checker *checker) const override; + void UpdateSelf([[maybe_unused]] const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) override; private: bool boolean_; diff --git a/es2panda/ir/expressions/literals/nullLiteral.cpp b/es2panda/ir/expressions/literals/nullLiteral.cpp index 67a65c2877b9796a69ff3bc954eb05f613f36645..b643a188012721b5d8f9e05635493b461b749cb2 100644 --- a/es2panda/ir/expressions/literals/nullLiteral.cpp +++ b/es2panda/ir/expressions/literals/nullLiteral.cpp @@ -38,4 +38,6 @@ checker::Type *NullLiteral::Check(checker::Checker *checker) const return checker->GlobalNullType(); } +void NullLiteral::UpdateSelf([[maybe_unused]] const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) {} + } // namespace panda::es2panda::ir diff --git a/es2panda/ir/expressions/literals/nullLiteral.h b/es2panda/ir/expressions/literals/nullLiteral.h index fc5a9d1da0980c457f305305a6b2755f28240992..2118fbf69eb93fff18f50b1bbdb6d12b615ced72 100644 --- a/es2panda/ir/expressions/literals/nullLiteral.h +++ b/es2panda/ir/expressions/literals/nullLiteral.h @@ -42,6 +42,7 @@ public: void Dump(ir::AstDumper *dumper) const override; void Compile(compiler::PandaGen *pg) const override; checker::Type *Check(checker::Checker *checker) const override; + void UpdateSelf([[maybe_unused]] const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) override; }; } // namespace panda::es2panda::ir diff --git a/es2panda/ir/expressions/literals/numberLiteral.cpp b/es2panda/ir/expressions/literals/numberLiteral.cpp index 11782233eeb7315f1092fb558b67f2b4dc0875c0..347f776f4b9330191d3deb5288f74cb82004b296 100644 --- a/es2panda/ir/expressions/literals/numberLiteral.cpp +++ b/es2panda/ir/expressions/literals/numberLiteral.cpp @@ -59,4 +59,6 @@ checker::Type *NumberLiteral::Check(checker::Checker *checker) const return newNumLiteralType; } +void NumberLiteral::UpdateSelf([[maybe_unused]] const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) {} + } // namespace panda::es2panda::ir diff --git a/es2panda/ir/expressions/literals/numberLiteral.h b/es2panda/ir/expressions/literals/numberLiteral.h index cd61076a815b0c60ee7061893f3aa3fed0f855d6..1aaf97960eb7e59c736352f3394c112725d69413 100644 --- a/es2panda/ir/expressions/literals/numberLiteral.h +++ b/es2panda/ir/expressions/literals/numberLiteral.h @@ -65,6 +65,7 @@ public: void Dump(ir::AstDumper *dumper) const override; void Compile(compiler::PandaGen *pg) const override; checker::Type *Check(checker::Checker *checker) const override; + void UpdateSelf([[maybe_unused]] const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) override; private: double number_; diff --git a/es2panda/ir/expressions/literals/regExpLiteral.cpp b/es2panda/ir/expressions/literals/regExpLiteral.cpp index f63d01aff1d8c65e0edff55422a278ecdfdb00d5..b87cd4ab3d171f95b18398d67872720dad7d2da0 100644 --- a/es2panda/ir/expressions/literals/regExpLiteral.cpp +++ b/es2panda/ir/expressions/literals/regExpLiteral.cpp @@ -60,4 +60,6 @@ checker::Type *RegExpLiteral::Check(checker::Checker *checker) const return checker->GlobalAnyType(); } +void RegExpLiteral::UpdateSelf([[maybe_unused]] const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) {} + } // namespace panda::es2panda::ir diff --git a/es2panda/ir/expressions/literals/regExpLiteral.h b/es2panda/ir/expressions/literals/regExpLiteral.h index 649143052aec3e223c364dffca85d0f9489bcdd1..2425403a50e02cec2e6df5ede0e9da208d7514d0 100644 --- a/es2panda/ir/expressions/literals/regExpLiteral.h +++ b/es2panda/ir/expressions/literals/regExpLiteral.h @@ -56,6 +56,7 @@ public: void Dump(ir::AstDumper *dumper) const override; void Compile(compiler::PandaGen *pg) const override; checker::Type *Check(checker::Checker *checker) const override; + void UpdateSelf([[maybe_unused]] const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) override; private: util::StringView pattern_; diff --git a/es2panda/ir/expressions/literals/stringLiteral.cpp b/es2panda/ir/expressions/literals/stringLiteral.cpp index d68d4ea58bff824eb0fe20132b7f37dd3e5c3581..08b50558c687df5dd5de7603ce6678c6558070c9 100644 --- a/es2panda/ir/expressions/literals/stringLiteral.cpp +++ b/es2panda/ir/expressions/literals/stringLiteral.cpp @@ -48,4 +48,6 @@ checker::Type *StringLiteral::Check(checker::Checker *checker) const return newStrLiteralType; } +void StringLiteral::UpdateSelf([[maybe_unused]] const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) {} + } // namespace panda::es2panda::ir diff --git a/es2panda/ir/expressions/literals/stringLiteral.h b/es2panda/ir/expressions/literals/stringLiteral.h index 4ff338957ad035fb971d443ece6fd21654f719b1..0862d86a34f6872c09cbcd3de454efb182267b9a 100644 --- a/es2panda/ir/expressions/literals/stringLiteral.h +++ b/es2panda/ir/expressions/literals/stringLiteral.h @@ -53,6 +53,7 @@ public: void Dump(ir::AstDumper *dumper) const override; void Compile(compiler::PandaGen *pg) const override; checker::Type *Check(checker::Checker *checker) const override; + void UpdateSelf([[maybe_unused]] const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) override; private: util::StringView str_; diff --git a/es2panda/ir/expressions/literals/taggedLiteral.cpp b/es2panda/ir/expressions/literals/taggedLiteral.cpp index 5c8d455345b6266b6222d8564465c388cc9cba0c..5421e1a034a00be18e3ae2451923b1a3af066b0b 100644 --- a/es2panda/ir/expressions/literals/taggedLiteral.cpp +++ b/es2panda/ir/expressions/literals/taggedLiteral.cpp @@ -36,4 +36,7 @@ checker::Type *TaggedLiteral::Check([[maybe_unused]] checker::Checker *checker) { UNREACHABLE(); } + +void TaggedLiteral::UpdateSelf([[maybe_unused]] const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) {} + } // namespace panda::es2panda::ir diff --git a/es2panda/ir/expressions/literals/taggedLiteral.h b/es2panda/ir/expressions/literals/taggedLiteral.h index c8ecd27e70eb55ca5392b6ff75ddfeb348adee47..06cd7028bd1b9e33f260e8ffd60d5110e448e163 100644 --- a/es2panda/ir/expressions/literals/taggedLiteral.h +++ b/es2panda/ir/expressions/literals/taggedLiteral.h @@ -74,6 +74,7 @@ public: void Dump(ir::AstDumper *dumper) const override; void Compile([[maybe_unused]] compiler::PandaGen *pg) const override; checker::Type *Check([[maybe_unused]] checker::Checker *checker) const override; + void UpdateSelf([[maybe_unused]] const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) override; private: uint16_t num_ {}; diff --git a/es2panda/ir/expressions/memberExpression.cpp b/es2panda/ir/expressions/memberExpression.cpp index 6754ecf67251dc7ccbc6e41988889c9755d7075b..c3bbed8a26bd1e298fad99e4b7128b41c5b79a30 100644 --- a/es2panda/ir/expressions/memberExpression.cpp +++ b/es2panda/ir/expressions/memberExpression.cpp @@ -147,4 +147,10 @@ checker::Type *MemberExpression::Check(checker::Checker *checker) const return nullptr; } +void MemberExpression::UpdateSelf(const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) +{ + object_ = std::get(cb(object_))->AsExpression(); + property_ = std::get(cb(property_))->AsExpression(); +} + } // namespace panda::es2panda::ir diff --git a/es2panda/ir/expressions/memberExpression.h b/es2panda/ir/expressions/memberExpression.h index 8fbac5d816ceb788a8be2810b49a028a8a5dafbf..a38b20dfb2d3c964402ae35e3e9f9be160780e44 100644 --- a/es2panda/ir/expressions/memberExpression.h +++ b/es2panda/ir/expressions/memberExpression.h @@ -78,6 +78,7 @@ public: void CompileObject(compiler::PandaGen *pg, compiler::VReg dest) const; compiler::Operand CompileKey(compiler::PandaGen *pg) const; checker::Type *Check(checker::Checker *checker) const override; + void UpdateSelf(const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) override; private: Expression *object_; diff --git a/es2panda/ir/expressions/newExpression.cpp b/es2panda/ir/expressions/newExpression.cpp index b7b2f253521fd134043ed36a69c931c153e2a3e2..ed02d396ae40da5529de849921d30fb4654ac056 100644 --- a/es2panda/ir/expressions/newExpression.cpp +++ b/es2panda/ir/expressions/newExpression.cpp @@ -81,4 +81,13 @@ checker::Type *NewExpression::Check(checker::Checker *checker) const return nullptr; } +void NewExpression::UpdateSelf(const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) +{ + callee_ = std::get(cb(callee_))->AsExpression(); + + for (auto iter = arguments_.begin(); iter != arguments_.end(); iter++) { + *iter = std::get(cb(*iter))->AsExpression(); + } +} + } // namespace panda::es2panda::ir diff --git a/es2panda/ir/expressions/newExpression.h b/es2panda/ir/expressions/newExpression.h index d4d88bd140203e1fc520a8838e56e31c3f5bb38f..380009c473c03a32e625963f81417ffa5ebbc36d 100644 --- a/es2panda/ir/expressions/newExpression.h +++ b/es2panda/ir/expressions/newExpression.h @@ -59,6 +59,7 @@ public: void Dump(ir::AstDumper *dumper) const override; void Compile(compiler::PandaGen *pg) const override; checker::Type *Check(checker::Checker *checker) const override; + void UpdateSelf(const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) override; private: Expression *callee_; diff --git a/es2panda/ir/expressions/objectExpression.cpp b/es2panda/ir/expressions/objectExpression.cpp index b4c365666a332c7ff37f3b8384244b9edf853d80..2e5e0e924dc28594635ce8a394a7e5a50090116a 100644 --- a/es2panda/ir/expressions/objectExpression.cpp +++ b/es2panda/ir/expressions/objectExpression.cpp @@ -743,4 +743,15 @@ checker::Type *ObjectExpression::Check(checker::Checker *checker) const return returnType; } +void ObjectExpression::UpdateSelf(const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) +{ + for (auto iter = properties_.begin(); iter != properties_.end(); iter++) { + *iter = std::get(cb(*iter))->AsExpression(); + } + + if (typeAnnotation_) { + typeAnnotation_ = std::get(cb(typeAnnotation_))->AsExpression(); + } +} + } // namespace panda::es2panda::ir diff --git a/es2panda/ir/expressions/objectExpression.h b/es2panda/ir/expressions/objectExpression.h index 16f497400514f496bf80486fb2386618e848240a..e4c7989d555fbd3d2af41e0425bf0c866cf0ec7d 100644 --- a/es2panda/ir/expressions/objectExpression.h +++ b/es2panda/ir/expressions/objectExpression.h @@ -82,6 +82,7 @@ public: void Compile(compiler::PandaGen *pg) const override; checker::Type *Check(checker::Checker *checker) const override; checker::Type *CheckPattern(checker::Checker *checker) const; + void UpdateSelf(const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) override; private: void FillInLiteralBuffer(compiler::LiteralBuffer *buf, diff --git a/es2panda/ir/expressions/omittedExpression.cpp b/es2panda/ir/expressions/omittedExpression.cpp index 05f4f3f56ba1f5914e8c22e9983fc79918502bf2..d15d28b2f5757b9730b2db7d541b0f65d7c9174d 100644 --- a/es2panda/ir/expressions/omittedExpression.cpp +++ b/es2panda/ir/expressions/omittedExpression.cpp @@ -34,4 +34,6 @@ checker::Type *OmittedExpression::Check(checker::Checker *checker) const return checker->GlobalUndefinedType(); } +void OmittedExpression::UpdateSelf([[maybe_unused]] const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) {} + } // namespace panda::es2panda::ir diff --git a/es2panda/ir/expressions/omittedExpression.h b/es2panda/ir/expressions/omittedExpression.h index f8e0ab40945a8ef2ed78314e6ed892213efec50b..c61f5198ae59b8677f86e34168b8fbfe05e71028 100644 --- a/es2panda/ir/expressions/omittedExpression.h +++ b/es2panda/ir/expressions/omittedExpression.h @@ -37,6 +37,7 @@ public: void Dump(ir::AstDumper *dumper) const override; void Compile([[maybe_unused]] compiler::PandaGen *pg) const override; checker::Type *Check(checker::Checker *checker) const override; + void UpdateSelf([[maybe_unused]] const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) override; }; } // namespace panda::es2panda::ir diff --git a/es2panda/ir/expressions/sequenceExpression.cpp b/es2panda/ir/expressions/sequenceExpression.cpp index c2f276f1f7a96c55ea2842f5d54d67978a14221b..6e842ced3a944d95d4db66f0a9c7acd2a9f3ccbd 100644 --- a/es2panda/ir/expressions/sequenceExpression.cpp +++ b/es2panda/ir/expressions/sequenceExpression.cpp @@ -45,4 +45,11 @@ checker::Type *SequenceExpression::Check(checker::Checker *checker) const return checker->GlobalAnyType(); } +void SequenceExpression::UpdateSelf(const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) +{ + for (auto iter = sequence_.begin(); iter != sequence_.end(); iter++) { + *iter = std::get(cb(*iter))->AsExpression(); + } +} + } // namespace panda::es2panda::ir diff --git a/es2panda/ir/expressions/sequenceExpression.h b/es2panda/ir/expressions/sequenceExpression.h index e2d1f2c9423977c959040223ccb1776d82ebde3c..ff751fe1c394b30b10bbe1f4a829396bad83ac6e 100644 --- a/es2panda/ir/expressions/sequenceExpression.h +++ b/es2panda/ir/expressions/sequenceExpression.h @@ -49,6 +49,7 @@ public: void Dump(ir::AstDumper *dumper) const override; void Compile(compiler::PandaGen *pg) const override; checker::Type *Check(checker::Checker *checker) const override; + void UpdateSelf(const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) override; private: ArenaVector sequence_; diff --git a/es2panda/ir/expressions/superExpression.cpp b/es2panda/ir/expressions/superExpression.cpp index 8c305d231d643684934bd0067151356685d747a2..14673a447563cf458707b8bcb8a87dbf0ee77cc3 100644 --- a/es2panda/ir/expressions/superExpression.cpp +++ b/es2panda/ir/expressions/superExpression.cpp @@ -46,4 +46,6 @@ checker::Type *SuperExpression::Check(checker::Checker *checker) const return checker->GlobalAnyType(); } +void SuperExpression::UpdateSelf([[maybe_unused]] const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) {} + } // namespace panda::es2panda::ir diff --git a/es2panda/ir/expressions/superExpression.h b/es2panda/ir/expressions/superExpression.h index d1cabbd0334aaea2697db804da12d873e75fc64c..ae162fe7a30c2b641d320454aee40ba6f4340501 100644 --- a/es2panda/ir/expressions/superExpression.h +++ b/es2panda/ir/expressions/superExpression.h @@ -37,6 +37,7 @@ public: void Dump(ir::AstDumper *dumper) const override; void Compile(compiler::PandaGen *pg) const override; checker::Type *Check(checker::Checker *checker) const override; + void UpdateSelf([[maybe_unused]] const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) override; private: }; diff --git a/es2panda/ir/expressions/taggedTemplateExpression.cpp b/es2panda/ir/expressions/taggedTemplateExpression.cpp index 156483238128f3c08159be578dea97e270952b6e..12ac2cb3f0654e066460f3425cbeedcb30f04842 100644 --- a/es2panda/ir/expressions/taggedTemplateExpression.cpp +++ b/es2panda/ir/expressions/taggedTemplateExpression.cpp @@ -89,4 +89,14 @@ checker::Type *TaggedTemplateExpression::Check(checker::Checker *checker) const return checker->GlobalAnyType(); } +void TaggedTemplateExpression::UpdateSelf(const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) +{ + if (typeParams_) { + typeParams_ = std::get(cb(typeParams_))->AsTSTypeParameterInstantiation(); + } + + tag_ = std::get(cb(tag_))->AsExpression(); + quasi_ = std::get(cb(quasi_))->AsTemplateLiteral(); +} + } // namespace panda::es2panda::ir diff --git a/es2panda/ir/expressions/taggedTemplateExpression.h b/es2panda/ir/expressions/taggedTemplateExpression.h index c2d48e52541be7340164ad87211d726b47b1bf7b..eac3dc1e14dc4efb9fb99877dc5ca3ccd485d4bc 100644 --- a/es2panda/ir/expressions/taggedTemplateExpression.h +++ b/es2panda/ir/expressions/taggedTemplateExpression.h @@ -59,6 +59,7 @@ public: void Dump(ir::AstDumper *dumper) const override; void Compile(compiler::PandaGen *pg) const override; checker::Type *Check(checker::Checker *checker) const override; + void UpdateSelf(const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) override; protected: Expression *tag_; diff --git a/es2panda/ir/expressions/templateLiteral.cpp b/es2panda/ir/expressions/templateLiteral.cpp index 6519cad1bfc32ce7fd85dc71ac0b72fecc71db9f..1a66c3b81a0b807c91c7e7681c5ec7457792f25f 100644 --- a/es2panda/ir/expressions/templateLiteral.cpp +++ b/es2panda/ir/expressions/templateLiteral.cpp @@ -85,4 +85,15 @@ checker::Type *TemplateLiteral::Check(checker::Checker *checker) const return checker->GlobalAnyType(); } +void TemplateLiteral::UpdateSelf(const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) +{ + for (auto iter = expressions_.begin(); iter != expressions_.end(); iter++) { + *iter = std::get(cb(*iter))->AsExpression(); + } + + for (auto iter = quasis_.begin(); iter != quasis_.end(); iter++) { + *iter = std::get(cb(*iter))->AsTemplateElement(); + } +} + } // namespace panda::es2panda::ir diff --git a/es2panda/ir/expressions/templateLiteral.h b/es2panda/ir/expressions/templateLiteral.h index 31bf6761d1aa45e3254c686e151d30cbcf449ffc..c68adfe56d52374ad2d63166ca65d0adec0513d6 100644 --- a/es2panda/ir/expressions/templateLiteral.h +++ b/es2panda/ir/expressions/templateLiteral.h @@ -51,6 +51,7 @@ public: void Dump(ir::AstDumper *dumper) const override; void Compile(compiler::PandaGen *pg) const override; checker::Type *Check(checker::Checker *checker) const override; + void UpdateSelf(const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) override; protected: ArenaVector quasis_; diff --git a/es2panda/ir/expressions/thisExpression.cpp b/es2panda/ir/expressions/thisExpression.cpp index 397b0bab53c3ca6331eaf1a6e26812af2fe7aef0..2bd432c7872155114e62b394021cf8bb83164ca5 100644 --- a/es2panda/ir/expressions/thisExpression.cpp +++ b/es2panda/ir/expressions/thisExpression.cpp @@ -54,4 +54,6 @@ checker::Type *ThisExpression::Check(checker::Checker *checker) const return checker->GlobalAnyType(); } +void ThisExpression::UpdateSelf([[maybe_unused]] const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) {} + } // namespace panda::es2panda::ir diff --git a/es2panda/ir/expressions/thisExpression.h b/es2panda/ir/expressions/thisExpression.h index 6e3f0e4ea27a14ac754c2efa50654105f8d0ee4d..e3cc4b94750fef76b5c5082d6f3b95ed9ee375db 100644 --- a/es2panda/ir/expressions/thisExpression.h +++ b/es2panda/ir/expressions/thisExpression.h @@ -37,6 +37,7 @@ public: void Dump(ir::AstDumper *dumper) const override; void Compile(compiler::PandaGen *pg) const override; checker::Type *Check(checker::Checker *checker) const override; + void UpdateSelf([[maybe_unused]] const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) override; private: }; diff --git a/es2panda/ir/expressions/unaryExpression.cpp b/es2panda/ir/expressions/unaryExpression.cpp index 6eb17d0c3d6421548cbb68244aad930a1cfbd6db..6f4620b9324ce7da1c141cfc9cc34b65f9e185e6 100644 --- a/es2panda/ir/expressions/unaryExpression.cpp +++ b/es2panda/ir/expressions/unaryExpression.cpp @@ -209,4 +209,9 @@ checker::Type *UnaryExpression::Check(checker::Checker *checker) const return nullptr; } +void UnaryExpression::UpdateSelf(const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) +{ + argument_ = std::get(cb(argument_))->AsExpression(); +} + } // namespace panda::es2panda::ir diff --git a/es2panda/ir/expressions/unaryExpression.h b/es2panda/ir/expressions/unaryExpression.h index 4e6c5b1d8973d4d5b7412034c41f225dc906e042..fc3714fa2b024356695f222eec5262b9d779e36c 100644 --- a/es2panda/ir/expressions/unaryExpression.h +++ b/es2panda/ir/expressions/unaryExpression.h @@ -51,6 +51,7 @@ public: void Dump(ir::AstDumper *dumper) const override; void Compile(compiler::PandaGen *pg) const override; checker::Type *Check(checker::Checker *checker) const override; + void UpdateSelf(const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) override; private: Expression *argument_; diff --git a/es2panda/ir/expressions/updateExpression.cpp b/es2panda/ir/expressions/updateExpression.cpp index 588b34f52b2f0da4eba886ea458cfe8b560f4323..77d0be0a1216d0f2e81a6a2af1668d980189294b 100644 --- a/es2panda/ir/expressions/updateExpression.cpp +++ b/es2panda/ir/expressions/updateExpression.cpp @@ -70,4 +70,9 @@ checker::Type *UpdateExpression::Check(checker::Checker *checker) const return checker->GetUnaryResultType(operandType); } +void UpdateExpression::UpdateSelf(const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) +{ + argument_ = std::get(cb(argument_))->AsExpression(); +} + } // namespace panda::es2panda::ir diff --git a/es2panda/ir/expressions/updateExpression.h b/es2panda/ir/expressions/updateExpression.h index 4344eaa28a918e00255655539b0ddbe979f79673..0641e3fe61519c8c7405207b9481fd0ec6ddbd8e 100644 --- a/es2panda/ir/expressions/updateExpression.h +++ b/es2panda/ir/expressions/updateExpression.h @@ -59,6 +59,7 @@ public: void Dump(ir::AstDumper *dumper) const override; void Compile(compiler::PandaGen *pg) const override; checker::Type *Check(checker::Checker *checker) const override; + void UpdateSelf(const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) override; private: Expression *argument_; diff --git a/es2panda/ir/expressions/yieldExpression.cpp b/es2panda/ir/expressions/yieldExpression.cpp index b47907270679674c4e7d7eda393ba24ba89980a7..5fbb5cbfe455ebb0a864f317b4ccc1996a851077 100644 --- a/es2panda/ir/expressions/yieldExpression.cpp +++ b/es2panda/ir/expressions/yieldExpression.cpp @@ -58,4 +58,11 @@ checker::Type *YieldExpression::Check(checker::Checker *checker) const return checker->GlobalAnyType(); } +void YieldExpression::UpdateSelf(const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) +{ + if (argument_) { + argument_ = std::get(cb(argument_))->AsExpression(); + } +} + } // namespace panda::es2panda::ir diff --git a/es2panda/ir/expressions/yieldExpression.h b/es2panda/ir/expressions/yieldExpression.h index af9cce60ffb773d59ab3df5dfa98522807e2c817..5129260e39d035bd0d0e2937a9943963f1d81e98 100644 --- a/es2panda/ir/expressions/yieldExpression.h +++ b/es2panda/ir/expressions/yieldExpression.h @@ -51,6 +51,7 @@ public: void Dump(ir::AstDumper *dumper) const override; void Compile(compiler::PandaGen *pg) const override; checker::Type *Check(checker::Checker *checker) const override; + void UpdateSelf(const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) override; private: Expression *argument_; diff --git a/es2panda/ir/module/exportAllDeclaration.cpp b/es2panda/ir/module/exportAllDeclaration.cpp index 0913f07b3677be009c7bab3d10b6b24e2ec7d1e4..a9562694e4154e131f78462c7241c67b7884dd86 100644 --- a/es2panda/ir/module/exportAllDeclaration.cpp +++ b/es2panda/ir/module/exportAllDeclaration.cpp @@ -42,4 +42,13 @@ checker::Type *ExportAllDeclaration::Check([[maybe_unused]] checker::Checker *ch return nullptr; } +void ExportAllDeclaration::UpdateSelf(const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) +{ + source_ = std::get(cb(source_))->AsStringLiteral(); + + if (exported_) { + exported_ = std::get(cb(exported_))->AsIdentifier(); + } +} + } // namespace panda::es2panda::ir diff --git a/es2panda/ir/module/exportAllDeclaration.h b/es2panda/ir/module/exportAllDeclaration.h index f9c94ddff74c55621ec4d6ac6cfb004be6eeca73..149dae0196767175cddd5d27259685e111df2371 100644 --- a/es2panda/ir/module/exportAllDeclaration.h +++ b/es2panda/ir/module/exportAllDeclaration.h @@ -53,6 +53,7 @@ public: void Dump(ir::AstDumper *dumper) const override; void Compile([[maybe_unused]] compiler::PandaGen *pg) const override; checker::Type *Check([[maybe_unused]] checker::Checker *checker) const override; + void UpdateSelf(const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) override; private: StringLiteral *source_; diff --git a/es2panda/ir/module/exportDefaultDeclaration.cpp b/es2panda/ir/module/exportDefaultDeclaration.cpp index 7612a55558b08951827749d3fa5456905ba7884a..1050faefd92588ec06e38fd990ca535ba6a84a7e 100644 --- a/es2panda/ir/module/exportDefaultDeclaration.cpp +++ b/es2panda/ir/module/exportDefaultDeclaration.cpp @@ -49,4 +49,9 @@ checker::Type *ExportDefaultDeclaration::Check([[maybe_unused]] checker::Checker return nullptr; } +void ExportDefaultDeclaration::UpdateSelf(const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) +{ + decl_ = std::get(cb(decl_)); +} + } // namespace panda::es2panda::ir diff --git a/es2panda/ir/module/exportDefaultDeclaration.h b/es2panda/ir/module/exportDefaultDeclaration.h index 624555363c500a5b4ae2d6ff1033c8c6539b361b..6ab246e25a41307e11c7561637ad4310e6b3aba7 100644 --- a/es2panda/ir/module/exportDefaultDeclaration.h +++ b/es2panda/ir/module/exportDefaultDeclaration.h @@ -50,6 +50,7 @@ public: void Dump(ir::AstDumper *dumper) const override; void Compile(compiler::PandaGen *pg) const override; checker::Type *Check([[maybe_unused]] checker::Checker *checker) const override; + void UpdateSelf(const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) override; private: AstNode *decl_; diff --git a/es2panda/ir/module/exportNamedDeclaration.cpp b/es2panda/ir/module/exportNamedDeclaration.cpp index 1b5f8511045324620279160db5bf25db2b8afd0c..b8a0f08ce969c8e7967e1713b5e4a47573509762 100644 --- a/es2panda/ir/module/exportNamedDeclaration.cpp +++ b/es2panda/ir/module/exportNamedDeclaration.cpp @@ -59,4 +59,19 @@ checker::Type *ExportNamedDeclaration::Check([[maybe_unused]] checker::Checker * return nullptr; } +void ExportNamedDeclaration::UpdateSelf(const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) +{ + if (decl_) { + decl_ = std::get(cb(decl_))->AsStatement(); + } else { + if (source_) { + source_ = std::get(cb(source_))->AsStringLiteral(); + } + + for (auto iter = specifiers_.begin(); iter != specifiers_.end(); iter++) { + *iter = std::get(cb(*iter))->AsExportSpecifier(); + } + } +} + } // namespace panda::es2panda::ir diff --git a/es2panda/ir/module/exportNamedDeclaration.h b/es2panda/ir/module/exportNamedDeclaration.h index 05c4089f71b8d2629576a74a696c0444f75b0ab2..d863428fe3dd64d543bec4d996a33730e1a02cb2 100644 --- a/es2panda/ir/module/exportNamedDeclaration.h +++ b/es2panda/ir/module/exportNamedDeclaration.h @@ -55,6 +55,11 @@ public: return decl_; } + Statement *Decl() + { + return decl_; + } + const StringLiteral *Source() const { return source_; @@ -69,6 +74,7 @@ public: void Dump(ir::AstDumper *dumper) const override; void Compile(compiler::PandaGen *pg) const override; checker::Type *Check([[maybe_unused]] checker::Checker *checker) const override; + void UpdateSelf(const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) override; private: StringLiteral *source_; diff --git a/es2panda/ir/module/exportSpecifier.cpp b/es2panda/ir/module/exportSpecifier.cpp index 39710daf39a1ec03459b1c62eb50520aab30d36f..4458e409dddb10009e43031b68e47868de870223 100644 --- a/es2panda/ir/module/exportSpecifier.cpp +++ b/es2panda/ir/module/exportSpecifier.cpp @@ -38,4 +38,10 @@ checker::Type *ExportSpecifier::Check([[maybe_unused]] checker::Checker *checker return nullptr; } +void ExportSpecifier::UpdateSelf(const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) +{ + local_ = std::get(cb(local_))->AsIdentifier(); + exported_ = std::get(cb(exported_))->AsIdentifier(); +} + } // namespace panda::es2panda::ir diff --git a/es2panda/ir/module/exportSpecifier.h b/es2panda/ir/module/exportSpecifier.h index d160f7087538a785d04bd1c51213f45e79d5298d..fc8aec505a47f0eebe76c736479455469e7ecc65 100644 --- a/es2panda/ir/module/exportSpecifier.h +++ b/es2panda/ir/module/exportSpecifier.h @@ -52,6 +52,7 @@ public: void Dump(ir::AstDumper *dumper) const override; void Compile([[maybe_unused]] compiler::PandaGen *pg) const override; checker::Type *Check([[maybe_unused]] checker::Checker *checker) const override; + void UpdateSelf(const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) override; private: Identifier *local_; diff --git a/es2panda/ir/module/importDeclaration.cpp b/es2panda/ir/module/importDeclaration.cpp index ad120eb007f2a16c7e1bd9c3f1356149619c6cef..b6f11650128d8f8b10693d8d466f1d5929c45393 100644 --- a/es2panda/ir/module/importDeclaration.cpp +++ b/es2panda/ir/module/importDeclaration.cpp @@ -41,4 +41,13 @@ checker::Type *ImportDeclaration::Check([[maybe_unused]] checker::Checker *check return nullptr; } +void ImportDeclaration::UpdateSelf(const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) +{ + source_ = std::get(cb(source_))->AsStringLiteral(); + + for (auto iter = specifiers_.begin(); iter != specifiers_.end(); iter++) { + *iter = std::get(cb(*iter)); + } +} + } // namespace panda::es2panda::ir diff --git a/es2panda/ir/module/importDeclaration.h b/es2panda/ir/module/importDeclaration.h index 6407fb47e4ffc257a1b250f1f22bf138cf9b3397..271f5f1c8f973c8fe02b1f4f11e0ce65071e7f74 100644 --- a/es2panda/ir/module/importDeclaration.h +++ b/es2panda/ir/module/importDeclaration.h @@ -53,6 +53,7 @@ public: void Dump(ir::AstDumper *dumper) const override; void Compile([[maybe_unused]] compiler::PandaGen *pg) const override; checker::Type *Check([[maybe_unused]] checker::Checker *checker) const override; + void UpdateSelf(const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) override; private: StringLiteral *source_; diff --git a/es2panda/ir/module/importDefaultSpecifier.cpp b/es2panda/ir/module/importDefaultSpecifier.cpp index cea1de1cbaeaf9f21ece7f7d6e89d994ffa3aaea..f8d078c654163da7a27eff15821da2760c685662 100644 --- a/es2panda/ir/module/importDefaultSpecifier.cpp +++ b/es2panda/ir/module/importDefaultSpecifier.cpp @@ -37,4 +37,9 @@ checker::Type *ImportDefaultSpecifier::Check([[maybe_unused]] checker::Checker * return nullptr; } +void ImportDefaultSpecifier::UpdateSelf(const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) +{ + local_ = std::get(cb(local_))->AsIdentifier(); +} + } // namespace panda::es2panda::ir diff --git a/es2panda/ir/module/importDefaultSpecifier.h b/es2panda/ir/module/importDefaultSpecifier.h index c38d4a55739878a8bba375422057c6db4ed5d297..87595fca33a896bb5d5e700300616e7a2a5305b8 100644 --- a/es2panda/ir/module/importDefaultSpecifier.h +++ b/es2panda/ir/module/importDefaultSpecifier.h @@ -46,6 +46,7 @@ public: void Dump(ir::AstDumper *dumper) const override; void Compile([[maybe_unused]] compiler::PandaGen *pg) const override; checker::Type *Check([[maybe_unused]] checker::Checker *checker) const override; + void UpdateSelf(const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) override; private: Identifier *local_; diff --git a/es2panda/ir/module/importNamespaceSpecifier.cpp b/es2panda/ir/module/importNamespaceSpecifier.cpp index a7ee3daa41268596e2e987b3a139a87db550b015..b13cddcac65b52109dac665b4681c361391871fa 100644 --- a/es2panda/ir/module/importNamespaceSpecifier.cpp +++ b/es2panda/ir/module/importNamespaceSpecifier.cpp @@ -37,4 +37,9 @@ checker::Type *ImportNamespaceSpecifier::Check([[maybe_unused]] checker::Checker return nullptr; } +void ImportNamespaceSpecifier::UpdateSelf(const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) +{ + local_ = std::get(cb(local_))->AsIdentifier(); +} + } // namespace panda::es2panda::ir diff --git a/es2panda/ir/module/importNamespaceSpecifier.h b/es2panda/ir/module/importNamespaceSpecifier.h index dc753f85e249cc4c6983a4a9ffd55b80864a6812..9566436f1b6cc167727064d244d1397b18442bbe 100644 --- a/es2panda/ir/module/importNamespaceSpecifier.h +++ b/es2panda/ir/module/importNamespaceSpecifier.h @@ -47,6 +47,7 @@ public: void Dump(ir::AstDumper *dumper) const override; void Compile([[maybe_unused]] compiler::PandaGen *pg) const override; checker::Type *Check([[maybe_unused]] checker::Checker *checker) const override; + void UpdateSelf(const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) override; private: Identifier *local_; diff --git a/es2panda/ir/module/importSpecifier.cpp b/es2panda/ir/module/importSpecifier.cpp index 58ec2ee587115eccad2ea88eaac633ff43636063..a790f644dc53e40a7cb60bc64223e2fa3b389638 100644 --- a/es2panda/ir/module/importSpecifier.cpp +++ b/es2panda/ir/module/importSpecifier.cpp @@ -38,4 +38,10 @@ checker::Type *ImportSpecifier::Check([[maybe_unused]] checker::Checker *checker return nullptr; } +void ImportSpecifier::UpdateSelf(const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) +{ + local_ = std::get(cb(local_))->AsIdentifier(); + imported_ = std::get(cb(imported_))->AsIdentifier(); +} + } // namespace panda::es2panda::ir diff --git a/es2panda/ir/module/importSpecifier.h b/es2panda/ir/module/importSpecifier.h index 6347067522bbaeda6474d00d0d8a4207cdfb4cab..a5ba4fc139b86bf5dc702b0818a657239dd12f2a 100644 --- a/es2panda/ir/module/importSpecifier.h +++ b/es2panda/ir/module/importSpecifier.h @@ -52,6 +52,7 @@ public: void Dump(ir::AstDumper *dumper) const override; void Compile([[maybe_unused]] compiler::PandaGen *pg) const override; checker::Type *Check([[maybe_unused]] checker::Checker *checker) const override; + void UpdateSelf(const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) override; private: Identifier *imported_; diff --git a/es2panda/ir/statements/blockStatement.cpp b/es2panda/ir/statements/blockStatement.cpp index f69f29f2c6928dfbb0dc7340a28c95a4e555690e..24abd03273c82f412db78c8051011cdb26771444 100644 --- a/es2panda/ir/statements/blockStatement.cpp +++ b/es2panda/ir/statements/blockStatement.cpp @@ -15,6 +15,7 @@ #include "blockStatement.h" +#include #include #include #include @@ -54,4 +55,31 @@ checker::Type *BlockStatement::Check(checker::Checker *checker) const return nullptr; } +void BlockStatement::UpdateSelf(const NodeUpdater &cb, binder::Binder *binder) +{ + auto scopeCtx = binder::LexicalScope::Enter(binder, scope_); + + for (auto iter = statements_.begin(); iter != statements_.end();) { + auto newStatements = cb(*iter); + if (std::holds_alternative(newStatements)) { + auto statement = std::get(newStatements); + if (statement == *iter) { + iter++; + } else if (statement == nullptr) { + iter = statements_.erase(iter); + } else { + *iter = statement->AsStatement(); + iter++; + } + } else { + auto statements = std::get>(newStatements); + for (auto *it : statements) { + iter = statements_.insert(iter, it->AsStatement()); + iter++; + } + iter = statements_.erase(iter); + } + } +} + } // namespace panda::es2panda::ir diff --git a/es2panda/ir/statements/blockStatement.h b/es2panda/ir/statements/blockStatement.h index ce567d4227a04d1ccdf9c53fde076eb379b4f8df..3769fd6862cf46d978620070f411987678305248 100644 --- a/es2panda/ir/statements/blockStatement.h +++ b/es2panda/ir/statements/blockStatement.h @@ -54,6 +54,7 @@ public: void Dump(ir::AstDumper *dumper) const override; void Compile(compiler::PandaGen *pg) const override; checker::Type *Check(checker::Checker *checker) const override; + void UpdateSelf(const NodeUpdater &cb, binder::Binder *binder) override; protected: binder::Scope *scope_; diff --git a/es2panda/ir/statements/breakStatement.cpp b/es2panda/ir/statements/breakStatement.cpp index 5ba38a1b3326657feeb83bf1b52997c49e8e99e8..dd2abc5cada186518b56214077cb0854faaf6571 100644 --- a/es2panda/ir/statements/breakStatement.cpp +++ b/es2panda/ir/statements/breakStatement.cpp @@ -44,4 +44,11 @@ checker::Type *BreakStatement::Check([[maybe_unused]] checker::Checker *checker) return nullptr; } +void BreakStatement::UpdateSelf(const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) +{ + if (ident_) { + ident_ = std::get(cb(ident_))->AsIdentifier(); + } +} + } // namespace panda::es2panda::ir diff --git a/es2panda/ir/statements/breakStatement.h b/es2panda/ir/statements/breakStatement.h index 255b8944d1ee62e3d531f011f266641c27491b61..27919c82352bf07e2e41e74ce2275ed542f5f2f6 100644 --- a/es2panda/ir/statements/breakStatement.h +++ b/es2panda/ir/statements/breakStatement.h @@ -45,6 +45,7 @@ public: void Dump(ir::AstDumper *dumper) const override; void Compile(compiler::PandaGen *pg) const override; checker::Type *Check([[maybe_unused]] checker::Checker *checker) const override; + void UpdateSelf(const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) override; protected: Identifier *ident_ {}; diff --git a/es2panda/ir/statements/classDeclaration.cpp b/es2panda/ir/statements/classDeclaration.cpp index bc46317eceff4da8dbd8d29ce33845a0330e4054..b52fe2b4847e70a76c11d9e3f88243e0deccc177 100644 --- a/es2panda/ir/statements/classDeclaration.cpp +++ b/es2panda/ir/statements/classDeclaration.cpp @@ -55,4 +55,13 @@ checker::Type *ClassDeclaration::Check([[maybe_unused]] checker::Checker *checke return nullptr; } +void ClassDeclaration::UpdateSelf(const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) +{ + def_ = std::get(cb(def_))->AsClassDefinition(); + + for (auto iter = decorators_.begin(); iter != decorators_.end(); iter++) { + *iter = std::get(cb(*iter))->AsDecorator(); + } +} + } // namespace panda::es2panda::ir diff --git a/es2panda/ir/statements/classDeclaration.h b/es2panda/ir/statements/classDeclaration.h index d983604e69ba7e26382ec87f0b3601b7f35d358c..5f2864fa1c19e3cd9ca386ff8aca6e5b62cbdff2 100644 --- a/es2panda/ir/statements/classDeclaration.h +++ b/es2panda/ir/statements/classDeclaration.h @@ -49,6 +49,7 @@ public: void Dump(ir::AstDumper *dumper) const override; void Compile(compiler::PandaGen *pg) const override; checker::Type *Check([[maybe_unused]] checker::Checker *checker) const override; + void UpdateSelf(const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) override; private: ClassDefinition *def_; diff --git a/es2panda/ir/statements/continueStatement.cpp b/es2panda/ir/statements/continueStatement.cpp index 016cdce977fd8755e216de171c9aac1097f6ed75..3613598605ec31ef4c0e18a806d4bd0c102ec518 100644 --- a/es2panda/ir/statements/continueStatement.cpp +++ b/es2panda/ir/statements/continueStatement.cpp @@ -43,4 +43,11 @@ checker::Type *ContinueStatement::Check([[maybe_unused]] checker::Checker *check return nullptr; } +void ContinueStatement::UpdateSelf(const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) +{ + if (ident_) { + ident_ = std::get(cb(ident_))->AsIdentifier(); + } +} + } // namespace panda::es2panda::ir diff --git a/es2panda/ir/statements/continueStatement.h b/es2panda/ir/statements/continueStatement.h index a4148db8380b1265dec19c1dec3aebe631cd1a2e..3b77294308e4d3ff6bab2b31ae87b3f4994210b0 100644 --- a/es2panda/ir/statements/continueStatement.h +++ b/es2panda/ir/statements/continueStatement.h @@ -44,6 +44,7 @@ public: void Dump(ir::AstDumper *dumper) const override; void Compile(compiler::PandaGen *pg) const override; checker::Type *Check([[maybe_unused]] checker::Checker *checker) const override; + void UpdateSelf(const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) override; protected: Identifier *ident_ {}; diff --git a/es2panda/ir/statements/debuggerStatement.cpp b/es2panda/ir/statements/debuggerStatement.cpp index a72d12075d4a7b3f509aa1b4c8c9bf9b8d410157..739aed9f4a7e4477ee84158170487bca3f3bbd29 100644 --- a/es2panda/ir/statements/debuggerStatement.cpp +++ b/es2panda/ir/statements/debuggerStatement.cpp @@ -33,4 +33,6 @@ checker::Type *DebuggerStatement::Check([[maybe_unused]] checker::Checker *check return nullptr; } +void DebuggerStatement::UpdateSelf([[maybe_unused]] const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) {} + } // namespace panda::es2panda::ir diff --git a/es2panda/ir/statements/debuggerStatement.h b/es2panda/ir/statements/debuggerStatement.h index 07c3352e09bfee0df88cb408289b038a12769fdb..87c4a9d011282b57fcb1c71b105f1f20d259071c 100644 --- a/es2panda/ir/statements/debuggerStatement.h +++ b/es2panda/ir/statements/debuggerStatement.h @@ -37,6 +37,7 @@ public: void Dump(ir::AstDumper *dumper) const override; void Compile([[maybe_unused]] compiler::PandaGen *pg) const override; checker::Type *Check([[maybe_unused]] checker::Checker *checker) const override; + void UpdateSelf([[maybe_unused]] const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) override; private: }; diff --git a/es2panda/ir/statements/doWhileStatement.cpp b/es2panda/ir/statements/doWhileStatement.cpp index f10c2b0db504d87b70dd023fb78f5ea26caff745..83078b77efc90c68227879d3712b58ccaafe02d0 100644 --- a/es2panda/ir/statements/doWhileStatement.cpp +++ b/es2panda/ir/statements/doWhileStatement.cpp @@ -15,6 +15,7 @@ #include "doWhileStatement.h" +#include #include #include #include @@ -67,4 +68,13 @@ checker::Type *DoWhileStatement::Check(checker::Checker *checker) const return nullptr; } +void DoWhileStatement::UpdateSelf(const NodeUpdater &cb, binder::Binder *binder) +{ + { + auto loopScopeCtx = binder::LexicalScope::Enter(binder, scope_); + body_ = std::get(cb(body_))->AsStatement(); + } + test_ = std::get(cb(test_))->AsExpression(); +} + } // namespace panda::es2panda::ir diff --git a/es2panda/ir/statements/doWhileStatement.h b/es2panda/ir/statements/doWhileStatement.h index 098f66542f9a9f637db7a679cc19d0a2f5f2cb0a..73f64a78d461ca0270da9c4b25cac4b88cf04f88 100644 --- a/es2panda/ir/statements/doWhileStatement.h +++ b/es2panda/ir/statements/doWhileStatement.h @@ -66,6 +66,7 @@ public: void Dump(ir::AstDumper *dumper) const override; void Compile(compiler::PandaGen *pg) const override; checker::Type *Check(checker::Checker *checker) const override; + void UpdateSelf(const NodeUpdater &cb, binder::Binder *binder) override; protected: Statement *body_; diff --git a/es2panda/ir/statements/emptyStatement.cpp b/es2panda/ir/statements/emptyStatement.cpp index ad7d07f66aeb9fad1c6284289431216cc6a2e89a..9c96300634c255f3551b1c1a7d7e736e6c1bce73 100644 --- a/es2panda/ir/statements/emptyStatement.cpp +++ b/es2panda/ir/statements/emptyStatement.cpp @@ -33,4 +33,6 @@ checker::Type *EmptyStatement::Check([[maybe_unused]] checker::Checker *checker) return nullptr; } +void EmptyStatement::UpdateSelf([[maybe_unused]] const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) {} + } // namespace panda::es2panda::ir diff --git a/es2panda/ir/statements/emptyStatement.h b/es2panda/ir/statements/emptyStatement.h index de5e9b90ee89c7fc2f9b3d0275a0a2adb602edfd..688d6196d98d7f38565a88b6df11e85ae130afa1 100644 --- a/es2panda/ir/statements/emptyStatement.h +++ b/es2panda/ir/statements/emptyStatement.h @@ -37,6 +37,7 @@ public: void Dump(ir::AstDumper *dumper) const override; void Compile([[maybe_unused]] compiler::PandaGen *pg) const override; checker::Type *Check([[maybe_unused]] checker::Checker *checker) const override; + void UpdateSelf([[maybe_unused]] const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) override; private: }; diff --git a/es2panda/ir/statements/expressionStatement.cpp b/es2panda/ir/statements/expressionStatement.cpp index 55e6e76ded4672630c0c547d5ef197b698a87321..2e69e05d9ed21a69797a67de2bc842ae2f96b964 100644 --- a/es2panda/ir/statements/expressionStatement.cpp +++ b/es2panda/ir/statements/expressionStatement.cpp @@ -40,4 +40,9 @@ checker::Type *ExpressionStatement::Check(checker::Checker *checker) const return expression_->Check(checker); } +void ExpressionStatement::UpdateSelf(const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) +{ + expression_ = std::get(cb(expression_))->AsExpression(); +} + } // namespace panda::es2panda::ir diff --git a/es2panda/ir/statements/expressionStatement.h b/es2panda/ir/statements/expressionStatement.h index d670b015b55f6505e99c654cdc90c02ece536bd0..36b2d2cf9da17d2207ac8db72793c214d64aa1f2 100644 --- a/es2panda/ir/statements/expressionStatement.h +++ b/es2panda/ir/statements/expressionStatement.h @@ -44,6 +44,7 @@ public: void Dump(ir::AstDumper *dumper) const override; void Compile(compiler::PandaGen *pg) const override; checker::Type *Check(checker::Checker *checker) const override; + void UpdateSelf(const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) override; private: Expression *expression_; diff --git a/es2panda/ir/statements/forInStatement.cpp b/es2panda/ir/statements/forInStatement.cpp index 22ad7f7476b3a7781104839027f08c1a9380ea97..2ccad0cb65b5ab4b604d5b7d8bebceaf453e9a21 100644 --- a/es2panda/ir/statements/forInStatement.cpp +++ b/es2panda/ir/statements/forInStatement.cpp @@ -15,6 +15,7 @@ #include "forInStatement.h" +#include #include #include #include @@ -78,4 +79,15 @@ checker::Type *ForInStatement::Check([[maybe_unused]] checker::Checker *checker) return nullptr; } +void ForInStatement::UpdateSelf(const NodeUpdater &cb, binder::Binder *binder) +{ + auto *loopScope = Scope(); + auto declScopeCtx = binder::LexicalScope::Enter(binder, loopScope->DeclScope()); + left_ = std::get(cb(left_)); + right_ = std::get(cb(right_))->AsExpression(); + + auto loopCtx = binder::LexicalScope::Enter(binder, loopScope); + body_ = std::get(cb(body_))->AsStatement(); +} + } // namespace panda::es2panda::ir diff --git a/es2panda/ir/statements/forInStatement.h b/es2panda/ir/statements/forInStatement.h index 668688a269f66610bc0221de1835af5bbcf2be46..0605b33cb095bd11d6871411de430aaa08c3d329 100644 --- a/es2panda/ir/statements/forInStatement.h +++ b/es2panda/ir/statements/forInStatement.h @@ -76,6 +76,7 @@ public: void Dump(ir::AstDumper *dumper) const override; void Compile(compiler::PandaGen *pg) const override; checker::Type *Check([[maybe_unused]] checker::Checker *checker) const override; + void UpdateSelf(const NodeUpdater &cb, binder::Binder *binder) override; private: AstNode *left_; diff --git a/es2panda/ir/statements/forOfStatement.cpp b/es2panda/ir/statements/forOfStatement.cpp index 2edd29bda0f2d1601b17b58af3a3f713557b14d1..f653ce3108ac2cc371a09d90282e7fe8e5eadf8b 100644 --- a/es2panda/ir/statements/forOfStatement.cpp +++ b/es2panda/ir/statements/forOfStatement.cpp @@ -15,6 +15,7 @@ #include "forOfStatement.h" +#include #include #include #include @@ -79,4 +80,15 @@ checker::Type *ForOfStatement::Check([[maybe_unused]] checker::Checker *checker) return nullptr; } +void ForOfStatement::UpdateSelf(const NodeUpdater &cb, binder::Binder *binder) +{ + auto *loopScope = Scope(); + auto declScopeCtx = binder::LexicalScope::Enter(binder, loopScope->DeclScope()); + left_ = std::get(cb(left_)); + right_ = std::get(cb(right_))->AsExpression(); + + auto loopCtx = binder::LexicalScope::Enter(binder, loopScope); + body_ = std::get(cb(body_))->AsStatement(); +} + } // namespace panda::es2panda::ir diff --git a/es2panda/ir/statements/forOfStatement.h b/es2panda/ir/statements/forOfStatement.h index 4e639ef2e8e2e7ebbc87e71509b44747da75048e..c28b54ecf297be4558e0ed1af1de3df5c81cba51 100644 --- a/es2panda/ir/statements/forOfStatement.h +++ b/es2panda/ir/statements/forOfStatement.h @@ -85,6 +85,7 @@ public: void Dump(ir::AstDumper *dumper) const override; void Compile(compiler::PandaGen *pg) const override; checker::Type *Check([[maybe_unused]] checker::Checker *checker) const override; + void UpdateSelf(const NodeUpdater &cb, binder::Binder *binder) override; private: AstNode *left_; diff --git a/es2panda/ir/statements/forUpdateStatement.cpp b/es2panda/ir/statements/forUpdateStatement.cpp index 780fe7f448333e89a5895d8567b55127e42d644e..d6275d9817170a63e6a7ffccbea43dc86a7f47e5 100644 --- a/es2panda/ir/statements/forUpdateStatement.cpp +++ b/es2panda/ir/statements/forUpdateStatement.cpp @@ -15,6 +15,7 @@ #include "forUpdateStatement.h" +#include #include #include #include @@ -109,4 +110,26 @@ checker::Type *ForUpdateStatement::Check(checker::Checker *checker) const return nullptr; } +void ForUpdateStatement::UpdateSelf(const NodeUpdater &cb, binder::Binder *binder) +{ + auto *loopScope = Scope(); + auto declScopeCtx = binder::LexicalScope::Enter(binder, loopScope->DeclScope()); + + if (init_) { + init_ = std::get(cb(init_)); + } + + if (test_) { + test_ = std::get(cb(test_))->AsExpression(); + } + + auto loopCtx = binder::LexicalScope::Enter(binder, loopScope); + + if (update_) { + update_ = std::get(cb(update_))->AsExpression(); + } + + body_ = std::get(cb(body_))->AsStatement(); +} + } // namespace panda::es2panda::ir diff --git a/es2panda/ir/statements/forUpdateStatement.h b/es2panda/ir/statements/forUpdateStatement.h index 923313adb6f45ead145ad15bff0c09ec87effeb7..9871daea2df7cf5d93552f00a19bc088b068c566 100644 --- a/es2panda/ir/statements/forUpdateStatement.h +++ b/es2panda/ir/statements/forUpdateStatement.h @@ -91,6 +91,7 @@ public: void Dump(ir::AstDumper *dumper) const override; void Compile(compiler::PandaGen *pg) const override; checker::Type *Check(checker::Checker *checker) const override; + void UpdateSelf(const NodeUpdater &cb, binder::Binder *binder) override; private: AstNode *init_; diff --git a/es2panda/ir/statements/functionDeclaration.cpp b/es2panda/ir/statements/functionDeclaration.cpp index f032a28d4067665a68617f9a1150016a9aac27d7..62e3401db8f560d754b4171ea595b6c1acf3cf29 100644 --- a/es2panda/ir/statements/functionDeclaration.cpp +++ b/es2panda/ir/statements/functionDeclaration.cpp @@ -57,4 +57,11 @@ checker::Type *FunctionDeclaration::Check(checker::Checker *checker) const return nullptr; } +void FunctionDeclaration::UpdateSelf(const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) +{ + if (func_) { + func_ = std::get(cb(func_))->AsScriptFunction(); + } +} + } // namespace panda::es2panda::ir diff --git a/es2panda/ir/statements/functionDeclaration.h b/es2panda/ir/statements/functionDeclaration.h index aff9ae022ea8c5f7a954289d35877df449d1d36c..9cf3df1130e302655dd402de44fdcf4530f89028 100644 --- a/es2panda/ir/statements/functionDeclaration.h +++ b/es2panda/ir/statements/functionDeclaration.h @@ -44,6 +44,7 @@ public: void Dump(ir::AstDumper *dumper) const override; void Compile([[maybe_unused]] compiler::PandaGen *pg) const override; checker::Type *Check(checker::Checker *checker) const override; + void UpdateSelf(const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) override; private: ScriptFunction *func_; diff --git a/es2panda/ir/statements/ifStatement.cpp b/es2panda/ir/statements/ifStatement.cpp index 8404cc16e60450a3dbb0aa8b030183ac67fe2a64..7f0a35b5fb8bdf5a44601c73e225e092899a04dc 100644 --- a/es2panda/ir/statements/ifStatement.cpp +++ b/es2panda/ir/statements/ifStatement.cpp @@ -75,4 +75,14 @@ checker::Type *IfStatement::Check(checker::Checker *checker) const return nullptr; } +void IfStatement::UpdateSelf(const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) +{ + test_ = std::get(cb(test_))->AsExpression(); + consequent_ = std::get(cb(consequent_))->AsStatement(); + + if (alternate_) { + alternate_ = std::get(cb(alternate_))->AsStatement(); + } +} + } // namespace panda::es2panda::ir diff --git a/es2panda/ir/statements/ifStatement.h b/es2panda/ir/statements/ifStatement.h index ac4dd2f01f6a7e0f086aa3fe5f2e843a6c18203a..7380df429b76776fd80fb8d86a38d0fb94fcdf19 100644 --- a/es2panda/ir/statements/ifStatement.h +++ b/es2panda/ir/statements/ifStatement.h @@ -56,6 +56,7 @@ public: void Dump(ir::AstDumper *dumper) const override; void Compile(compiler::PandaGen *pg) const override; checker::Type *Check(checker::Checker *checker) const override; + void UpdateSelf(const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) override; protected: Expression *test_; diff --git a/es2panda/ir/statements/labelledStatement.cpp b/es2panda/ir/statements/labelledStatement.cpp index 021c3f650b9176ba58499cb164ca621aec201e55..cdf60712e688ca84d2b81c8cb069471c55fdd291 100644 --- a/es2panda/ir/statements/labelledStatement.cpp +++ b/es2panda/ir/statements/labelledStatement.cpp @@ -44,4 +44,10 @@ checker::Type *LabelledStatement::Check([[maybe_unused]] checker::Checker *check return nullptr; } +void LabelledStatement::UpdateSelf(const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) +{ + ident_ = std::get(cb(ident_))->AsIdentifier(); + body_ = std::get(cb(body_))->AsStatement(); +} + } // namespace panda::es2panda::ir diff --git a/es2panda/ir/statements/labelledStatement.h b/es2panda/ir/statements/labelledStatement.h index 2b0d4d9a32154e2964b739ce06f120aacc93f67f..926fdcf6bc41014b8e8f43bf9044d52c7a08774f 100644 --- a/es2panda/ir/statements/labelledStatement.h +++ b/es2panda/ir/statements/labelledStatement.h @@ -53,6 +53,7 @@ public: void Dump(ir::AstDumper *dumper) const override; void Compile(compiler::PandaGen *pg) const override; checker::Type *Check([[maybe_unused]] checker::Checker *checker) const override; + void UpdateSelf(const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) override; protected: Identifier *ident_; diff --git a/es2panda/ir/statements/returnStatement.cpp b/es2panda/ir/statements/returnStatement.cpp index 5d65a90860f58332ddc04961b2ff286f272ed61d..65d1a5cf014399f5ab09bf7d2f47571452f3ac4a 100644 --- a/es2panda/ir/statements/returnStatement.cpp +++ b/es2panda/ir/statements/returnStatement.cpp @@ -93,4 +93,11 @@ checker::Type *ReturnStatement::Check(checker::Checker *checker) const return nullptr; } +void ReturnStatement::UpdateSelf(const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) +{ + if (argument_) { + argument_ = std::get(cb(argument_))->AsExpression(); + } +} + } // namespace panda::es2panda::ir diff --git a/es2panda/ir/statements/returnStatement.h b/es2panda/ir/statements/returnStatement.h index 827f8634c97dc198251b5c302388e639bb690fae..5262cbdd069e93066b0bba131883a6f40cec87e7 100644 --- a/es2panda/ir/statements/returnStatement.h +++ b/es2panda/ir/statements/returnStatement.h @@ -43,6 +43,7 @@ public: void Dump(ir::AstDumper *dumper) const override; void Compile(compiler::PandaGen *pg) const override; checker::Type *Check(checker::Checker *checker) const override; + void UpdateSelf(const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) override; protected: Expression *argument_ {}; diff --git a/es2panda/ir/statements/switchCaseStatement.cpp b/es2panda/ir/statements/switchCaseStatement.cpp index e2fd5c7866e9f41e3cca8a0adb212c6a5260a7ed..70ed91d245754b9a40e06a97e788bb4494627021 100644 --- a/es2panda/ir/statements/switchCaseStatement.cpp +++ b/es2panda/ir/statements/switchCaseStatement.cpp @@ -43,4 +43,15 @@ checker::Type *SwitchCaseStatement::Check([[maybe_unused]] checker::Checker *che return nullptr; } +void SwitchCaseStatement::UpdateSelf(const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) +{ + if (test_) { + test_ = std::get(cb(test_))->AsExpression(); + } + + for (auto iter = consequent_.begin(); iter != consequent_.end(); iter++) { + *iter = std::get(cb(*iter))->AsStatement(); + } +} + } // namespace panda::es2panda::ir diff --git a/es2panda/ir/statements/switchCaseStatement.h b/es2panda/ir/statements/switchCaseStatement.h index cb6a6f95f07d420254d589baa2468b0ad0aa88cd..54971877cf26fad99bb4e757e6b5911abee0fb18 100644 --- a/es2panda/ir/statements/switchCaseStatement.h +++ b/es2panda/ir/statements/switchCaseStatement.h @@ -52,6 +52,7 @@ public: void Dump(ir::AstDumper *dumper) const override; void Compile([[maybe_unused]] compiler::PandaGen *pg) const override; checker::Type *Check([[maybe_unused]] checker::Checker *checker) const override; + void UpdateSelf(const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) override; protected: Expression *test_; diff --git a/es2panda/ir/statements/switchStatement.cpp b/es2panda/ir/statements/switchStatement.cpp index fb9be5f8ed81f7fbc0414b6f542601cea357af26..94b97de649145b29bf47462967afdd856f4e31b1 100644 --- a/es2panda/ir/statements/switchStatement.cpp +++ b/es2panda/ir/statements/switchStatement.cpp @@ -15,6 +15,7 @@ #include "switchStatement.h" +#include #include #include #include @@ -105,4 +106,15 @@ checker::Type *SwitchStatement::Check(checker::Checker *checker) const return nullptr; } +void SwitchStatement::UpdateSelf(const NodeUpdater &cb, binder::Binder *binder) +{ + auto scopeCtx = binder::LexicalScope::Enter(binder, scope_); + + discriminant_ = std::get(cb(discriminant_))->AsExpression(); + + for (auto iter = cases_.begin(); iter != cases_.end(); iter++) { + *iter = std::get(cb(*iter))->AsSwitchCaseStatement(); + } +} + } // namespace panda::es2panda::ir diff --git a/es2panda/ir/statements/switchStatement.h b/es2panda/ir/statements/switchStatement.h index 3389f5bd0e39b27492650806f1f60bc12dcc769f..3e2148fd76c725b0736fe99247befc42c0ef5898 100644 --- a/es2panda/ir/statements/switchStatement.h +++ b/es2panda/ir/statements/switchStatement.h @@ -63,6 +63,7 @@ public: void Dump(ir::AstDumper *dumper) const override; void Compile(compiler::PandaGen *pg) const override; checker::Type *Check(checker::Checker *checker) const override; + void UpdateSelf(const NodeUpdater &cb, binder::Binder *binder) override; protected: binder::LocalScope *scope_; diff --git a/es2panda/ir/statements/throwStatement.cpp b/es2panda/ir/statements/throwStatement.cpp index a17408337e61987a33f0fc9e265564bf482049e7..8319c218348eeb57049fd8e9b99c77b1e156c824 100644 --- a/es2panda/ir/statements/throwStatement.cpp +++ b/es2panda/ir/statements/throwStatement.cpp @@ -42,4 +42,9 @@ checker::Type *ThrowStatement::Check([[maybe_unused]] checker::Checker *checker) return nullptr; } +void ThrowStatement::UpdateSelf(const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) +{ + argument_ = std::get(cb(argument_))->AsExpression(); +} + } // namespace panda::es2panda::ir diff --git a/es2panda/ir/statements/throwStatement.h b/es2panda/ir/statements/throwStatement.h index e657ecab9130b3d3ec1e48e61cf2ce462f2b53e6..274570561a63c5df268bd8df93f3f4a26f20cb29 100644 --- a/es2panda/ir/statements/throwStatement.h +++ b/es2panda/ir/statements/throwStatement.h @@ -44,6 +44,7 @@ public: void Dump(ir::AstDumper *dumper) const override; void Compile(compiler::PandaGen *pg) const override; checker::Type *Check([[maybe_unused]] checker::Checker *checker) const override; + void UpdateSelf(const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) override; protected: Expression *argument_; diff --git a/es2panda/ir/statements/tryStatement.cpp b/es2panda/ir/statements/tryStatement.cpp index 6ec2774bdb8c4f78c26085125971e37f1f20b7e4..7a1f1e5960fbf4292a4d64640c42c5e397158041 100644 --- a/es2panda/ir/statements/tryStatement.cpp +++ b/es2panda/ir/statements/tryStatement.cpp @@ -170,4 +170,17 @@ checker::Type *TryStatement::Check(checker::Checker *checker) const return nullptr; } +void TryStatement::UpdateSelf(const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) +{ + block_ = std::get(cb(block_))->AsBlockStatement(); + + if (catchClause_) { + catchClause_ = std::get(cb(catchClause_))->AsCatchClause(); + } + + if (finalizer_) { + finalizer_ = std::get(cb(finalizer_))->AsBlockStatement(); + } +} + } // namespace panda::es2panda::ir diff --git a/es2panda/ir/statements/tryStatement.h b/es2panda/ir/statements/tryStatement.h index 7cd7b3ef4a81c715080b83f3db0b7773c03ea57b..79d2a1279756ffddc7d2212d1c3e2b40bc978a70 100644 --- a/es2panda/ir/statements/tryStatement.h +++ b/es2panda/ir/statements/tryStatement.h @@ -60,6 +60,7 @@ public: void Dump(ir::AstDumper *dumper) const override; void Compile(compiler::PandaGen *pg) const override; checker::Type *Check(checker::Checker *checker) const override; + void UpdateSelf(const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) override; private: void CompileTryCatch(compiler::PandaGen *pg) const; diff --git a/es2panda/ir/statements/variableDeclaration.cpp b/es2panda/ir/statements/variableDeclaration.cpp index aab386285aa4b310577141c0b44c1c8db01cd392..bbca47e6418788e4914329967a5a4bb6bec0da2d 100644 --- a/es2panda/ir/statements/variableDeclaration.cpp +++ b/es2panda/ir/statements/variableDeclaration.cpp @@ -74,4 +74,11 @@ checker::Type *VariableDeclaration::Check(checker::Checker *checker) const return nullptr; } +void VariableDeclaration::UpdateSelf(const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) +{ + for (auto iter = declarators_.begin(); iter != declarators_.end(); iter++) { + *iter = std::get(cb(*iter))->AsVariableDeclarator(); + } +} + } // namespace panda::es2panda::ir diff --git a/es2panda/ir/statements/variableDeclaration.h b/es2panda/ir/statements/variableDeclaration.h index 42a70da3a48fc5e413f13b1250e0d05b8a6e6aba..eb38cb4ad0585060bb8425221dc099d1c4f61c89 100644 --- a/es2panda/ir/statements/variableDeclaration.h +++ b/es2panda/ir/statements/variableDeclaration.h @@ -63,6 +63,7 @@ public: void Dump(ir::AstDumper *dumper) const override; void Compile(compiler::PandaGen *pg) const override; checker::Type *Check(checker::Checker *checker) const override; + void UpdateSelf(const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) override; private: VariableDeclarationKind kind_; diff --git a/es2panda/ir/statements/variableDeclarator.cpp b/es2panda/ir/statements/variableDeclarator.cpp index 7018207f6037a78be79aa3cbbcd8c29aa5a6f3aa..ef3fb7d5bc22631e7c2ef01cc6e3f291fcf86abc 100644 --- a/es2panda/ir/statements/variableDeclarator.cpp +++ b/es2panda/ir/statements/variableDeclarator.cpp @@ -143,4 +143,13 @@ checker::Type *VariableDeclarator::Check(checker::Checker *checker) const return nullptr; } +void VariableDeclarator::UpdateSelf(const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) +{ + id_ = std::get(cb(id_))->AsExpression(); + + if (init_) { + init_ = std::get(cb(init_))->AsExpression(); + } +} + } // namespace panda::es2panda::ir diff --git a/es2panda/ir/statements/variableDeclarator.h b/es2panda/ir/statements/variableDeclarator.h index dd73f305eadcda0a2ca15680e7cf118538568528..4c695dfbf2bc30d482602eb4fbab9d544aed80b5 100644 --- a/es2panda/ir/statements/variableDeclarator.h +++ b/es2panda/ir/statements/variableDeclarator.h @@ -68,6 +68,7 @@ public: void Dump(ir::AstDumper *dumper) const override; void Compile(compiler::PandaGen *pg) const override; checker::Type *Check(checker::Checker *checker) const override; + void UpdateSelf(const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) override; private: Expression *id_; diff --git a/es2panda/ir/statements/whileStatement.cpp b/es2panda/ir/statements/whileStatement.cpp index 258cd447ffe39ea53ec22236ba336c98e01ed162..0c5a09fb3427763c6f203c29aabd11f197973d25 100644 --- a/es2panda/ir/statements/whileStatement.cpp +++ b/es2panda/ir/statements/whileStatement.cpp @@ -15,6 +15,7 @@ #include "whileStatement.h" +#include #include #include #include @@ -66,4 +67,12 @@ checker::Type *WhileStatement::Check(checker::Checker *checker) const return nullptr; } +void WhileStatement::UpdateSelf(const NodeUpdater &cb, binder::Binder *binder) +{ + test_ = std::get(cb(test_))->AsExpression(); + + auto loopScopeCtx = binder::LexicalScope::Enter(binder, scope_); + body_ = std::get(cb(body_))->AsStatement(); +} + } // namespace panda::es2panda::ir diff --git a/es2panda/ir/statements/whileStatement.h b/es2panda/ir/statements/whileStatement.h index 680389ab21bacb4a335defa6dc131a91b9df7749..e77f97a6319db2d33d271ff3e45c806147f37a98 100644 --- a/es2panda/ir/statements/whileStatement.h +++ b/es2panda/ir/statements/whileStatement.h @@ -66,6 +66,7 @@ public: void Dump(ir::AstDumper *dumper) const override; void Compile(compiler::PandaGen *pg) const override; checker::Type *Check(checker::Checker *checker) const override; + void UpdateSelf(const NodeUpdater &cb, binder::Binder *binder) override; protected: Expression *test_; diff --git a/es2panda/ir/ts/tsAnyKeyword.cpp b/es2panda/ir/ts/tsAnyKeyword.cpp index 18572a52ac3e62e91ac3ac3faf39a511a52315f0..5422a346164bf7ddd36769c5c5f1239c76d04423 100644 --- a/es2panda/ir/ts/tsAnyKeyword.cpp +++ b/es2panda/ir/ts/tsAnyKeyword.cpp @@ -39,4 +39,6 @@ checker::Type *TSAnyKeyword::GetType(checker::Checker *checker) const return checker->GlobalAnyType(); } +void TSAnyKeyword::UpdateSelf([[maybe_unused]] const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) {} + } // namespace panda::es2panda::ir diff --git a/es2panda/ir/ts/tsAnyKeyword.h b/es2panda/ir/ts/tsAnyKeyword.h index 438466758e2a5afd5433472dcb09c902a795a186..8641cbc53c7ac742b3df79c7e78f22862c8004b5 100644 --- a/es2panda/ir/ts/tsAnyKeyword.h +++ b/es2panda/ir/ts/tsAnyKeyword.h @@ -38,6 +38,7 @@ public: void Compile([[maybe_unused]] compiler::PandaGen *pg) const override; checker::Type *Check([[maybe_unused]] checker::Checker *checker) const override; checker::Type *GetType(checker::Checker *checker) const override; + void UpdateSelf([[maybe_unused]] const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) override; }; } // namespace panda::es2panda::ir diff --git a/es2panda/ir/ts/tsArrayType.cpp b/es2panda/ir/ts/tsArrayType.cpp index 7e5d86c56397edf52acb0da2115a834627274804..1040fbfde7fd0f4e61c10133a8e6b558a5e10b88 100644 --- a/es2panda/ir/ts/tsArrayType.cpp +++ b/es2panda/ir/ts/tsArrayType.cpp @@ -43,4 +43,9 @@ checker::Type *TSArrayType::GetType(checker::Checker *checker) const return checker->Allocator()->New(elementType_->AsTypeNode()->GetType(checker)); } +void TSArrayType::UpdateSelf(const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) +{ + elementType_ = std::get(cb(elementType_))->AsExpression(); +} + } // namespace panda::es2panda::ir diff --git a/es2panda/ir/ts/tsArrayType.h b/es2panda/ir/ts/tsArrayType.h index 1c6e1337dde7f607f18ead3472941b0bc7e2a877..be5a1d875af94103d0688898d937c83851d69ebc 100644 --- a/es2panda/ir/ts/tsArrayType.h +++ b/es2panda/ir/ts/tsArrayType.h @@ -43,6 +43,7 @@ public: void Compile([[maybe_unused]] compiler::PandaGen *pg) const override; checker::Type *Check(checker::Checker *checker) const override; checker::Type *GetType(checker::Checker *checker) const override; + void UpdateSelf(const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) override; private: Expression *elementType_; diff --git a/es2panda/ir/ts/tsAsExpression.cpp b/es2panda/ir/ts/tsAsExpression.cpp index a4e6e08db60e44e48ee4752ea69accde24948027..c67d15b4211c4677049471ec18233776f96d78c1 100644 --- a/es2panda/ir/ts/tsAsExpression.cpp +++ b/es2panda/ir/ts/tsAsExpression.cpp @@ -108,4 +108,10 @@ checker::Type *TSAsExpression::Check(checker::Checker *checker) const return targetType; } +void TSAsExpression::UpdateSelf(const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) +{ + expression_ = std::get(cb(expression_))->AsExpression(); + typeAnnotation_ = std::get(cb(typeAnnotation_))->AsExpression(); +} + } // namespace panda::es2panda::ir diff --git a/es2panda/ir/ts/tsAsExpression.h b/es2panda/ir/ts/tsAsExpression.h index 698a431bf8130fba7d40198142d3ab0a6229d3e8..ceb6fc2fd1481c6eda690734f4febb0731554eb4 100644 --- a/es2panda/ir/ts/tsAsExpression.h +++ b/es2panda/ir/ts/tsAsExpression.h @@ -59,6 +59,7 @@ public: void Dump(ir::AstDumper *dumper) const override; void Compile([[maybe_unused]] compiler::PandaGen *pg) const override; checker::Type *Check(checker::Checker *checker) const override; + void UpdateSelf(const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) override; private: Expression *expression_; diff --git a/es2panda/ir/ts/tsBigintKeyword.cpp b/es2panda/ir/ts/tsBigintKeyword.cpp index 53c0ee42405e9372756996df3895d63914ec239a..d5688ff2e4d97b153dbd98c10ca3cfd79c4f25d5 100644 --- a/es2panda/ir/ts/tsBigintKeyword.cpp +++ b/es2panda/ir/ts/tsBigintKeyword.cpp @@ -39,4 +39,6 @@ checker::Type *TSBigintKeyword::GetType(checker::Checker *checker) const return checker->GlobalBigintType(); } +void TSBigintKeyword::UpdateSelf([[maybe_unused]] const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) {} + } // namespace panda::es2panda::ir diff --git a/es2panda/ir/ts/tsBigintKeyword.h b/es2panda/ir/ts/tsBigintKeyword.h index 174253b416aa4f16ed2dfc61ee992e289022b0d0..0b2c2ce9efb111f820ec1456ea9dd88a76a9065d 100644 --- a/es2panda/ir/ts/tsBigintKeyword.h +++ b/es2panda/ir/ts/tsBigintKeyword.h @@ -38,6 +38,7 @@ public: void Compile([[maybe_unused]] compiler::PandaGen *pg) const override; checker::Type *Check([[maybe_unused]] checker::Checker *checker) const override; checker::Type *GetType(checker::Checker *checker) const override; + void UpdateSelf([[maybe_unused]] const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) override; }; } // namespace panda::es2panda::ir diff --git a/es2panda/ir/ts/tsBooleanKeyword.cpp b/es2panda/ir/ts/tsBooleanKeyword.cpp index 179e4e1942c150d6e665f2505a81446cbbd46746..90f59758f015939cfc46f42982e8f4edf90b4873 100644 --- a/es2panda/ir/ts/tsBooleanKeyword.cpp +++ b/es2panda/ir/ts/tsBooleanKeyword.cpp @@ -39,4 +39,6 @@ checker::Type *TSBooleanKeyword::GetType(checker::Checker *checker) const return checker->GlobalBooleanType(); } +void TSBooleanKeyword::UpdateSelf([[maybe_unused]] const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) {} + } // namespace panda::es2panda::ir diff --git a/es2panda/ir/ts/tsBooleanKeyword.h b/es2panda/ir/ts/tsBooleanKeyword.h index 4e6056d729f765518dfc844149ee5cd6d880b1bb..080a85aedc51843f4f42307d3380aa777e1d8265 100644 --- a/es2panda/ir/ts/tsBooleanKeyword.h +++ b/es2panda/ir/ts/tsBooleanKeyword.h @@ -38,6 +38,7 @@ public: void Compile([[maybe_unused]] compiler::PandaGen *pg) const override; checker::Type *Check([[maybe_unused]] checker::Checker *checker) const override; checker::Type *GetType(checker::Checker *checker) const override; + void UpdateSelf([[maybe_unused]] const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) override; }; } // namespace panda::es2panda::ir diff --git a/es2panda/ir/ts/tsClassImplements.cpp b/es2panda/ir/ts/tsClassImplements.cpp index c122178534eb8f1681d4e9196bec85466dced35f..704156143f8ea0f25b0d1e9b0911f1f0da8efe9c 100644 --- a/es2panda/ir/ts/tsClassImplements.cpp +++ b/es2panda/ir/ts/tsClassImplements.cpp @@ -44,4 +44,13 @@ checker::Type *TSClassImplements::Check([[maybe_unused]] checker::Checker *check return nullptr; } +void TSClassImplements::UpdateSelf(const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) +{ + expression_ = std::get(cb(expression_))->AsExpression(); + + if (typeParameters_) { + typeParameters_ = std::get(cb(typeParameters_))->AsTSTypeParameterInstantiation(); + } +} + } // namespace panda::es2panda::ir diff --git a/es2panda/ir/ts/tsClassImplements.h b/es2panda/ir/ts/tsClassImplements.h index 3926e09ae838532532dd2b12c18cf5c1430b35ae..cadd1d28c8b416d2bcb06bdc7276234e3b0e7c80 100644 --- a/es2panda/ir/ts/tsClassImplements.h +++ b/es2panda/ir/ts/tsClassImplements.h @@ -34,7 +34,7 @@ class TSTypeParameterInstantiation; class TSClassImplements : public Expression { public: explicit TSClassImplements(Expression *expression, TSTypeParameterInstantiation *typeParameters) - : Expression(AstNodeType::TS_AS_EXPRESSION), expression_(expression), typeParameters_(typeParameters) + : Expression(AstNodeType::TS_CLASS_IMPLEMENTS), expression_(expression), typeParameters_(typeParameters) { } @@ -52,6 +52,7 @@ public: void Dump(ir::AstDumper *dumper) const override; void Compile([[maybe_unused]] compiler::PandaGen *pg) const override; checker::Type *Check([[maybe_unused]] checker::Checker *checker) const override; + void UpdateSelf(const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) override; private: Expression *expression_; diff --git a/es2panda/ir/ts/tsConditionalType.cpp b/es2panda/ir/ts/tsConditionalType.cpp index ffe89a8fbbf94531499fe0839f7ffca2db92847d..63ece61adbbc791f9e5d031baf7d9c5d57b544d5 100644 --- a/es2panda/ir/ts/tsConditionalType.cpp +++ b/es2panda/ir/ts/tsConditionalType.cpp @@ -48,4 +48,12 @@ checker::Type *TSConditionalType::GetType([[maybe_unused]] checker::Checker *che return nullptr; } +void TSConditionalType::UpdateSelf(const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) +{ + checkType_ = std::get(cb(checkType_))->AsExpression(); + extendsType_ = std::get(cb(extendsType_))->AsExpression(); + trueType_ = std::get(cb(trueType_))->AsExpression(); + falseType_ = std::get(cb(falseType_))->AsExpression(); +} + } // namespace panda::es2panda::ir diff --git a/es2panda/ir/ts/tsConditionalType.h b/es2panda/ir/ts/tsConditionalType.h index 4689e3369119348314ed25a68d921417ccf2631b..2eb2eab7bce0ac1f631a53682673deeb89e4d830 100644 --- a/es2panda/ir/ts/tsConditionalType.h +++ b/es2panda/ir/ts/tsConditionalType.h @@ -66,6 +66,7 @@ public: void Compile([[maybe_unused]] compiler::PandaGen *pg) const override; checker::Type *Check([[maybe_unused]] checker::Checker *checker) const override; checker::Type *GetType([[maybe_unused]] checker::Checker *checker) const override; + void UpdateSelf(const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) override; private: Expression *checkType_; diff --git a/es2panda/ir/ts/tsConstructorType.cpp b/es2panda/ir/ts/tsConstructorType.cpp index 74089d8bb1eebe7cc83c0e6f59bb8c75ebba196a..e3417762315f985cb561b88668e60de31fd7c5ba 100644 --- a/es2panda/ir/ts/tsConstructorType.cpp +++ b/es2panda/ir/ts/tsConstructorType.cpp @@ -15,6 +15,7 @@ #include "tsConstructorType.h" +#include #include #include #include @@ -66,4 +67,19 @@ checker::Type *TSConstructorType::GetType(checker::Checker *checker) const return checker->CheckTypeCached(this); } +void TSConstructorType::UpdateSelf(const NodeUpdater &cb, binder::Binder *binder) +{ + auto scopeCtx = binder::LexicalScope::Enter(binder, scope_); + + if (typeParams_) { + typeParams_ = std::get(cb(typeParams_))->AsTSTypeParameterDeclaration(); + } + + for (auto iter = params_.begin(); iter != params_.end(); iter++) { + *iter = std::get(cb(*iter))->AsExpression(); + } + + returnType_ = std::get(cb(returnType_))->AsExpression(); +} + } // namespace panda::es2panda::ir diff --git a/es2panda/ir/ts/tsConstructorType.h b/es2panda/ir/ts/tsConstructorType.h index 162eb08070145451de60be7dc5549c237e21c7f4..01686e44ee7197b6a1e63314f838e1467c4b8251 100644 --- a/es2panda/ir/ts/tsConstructorType.h +++ b/es2panda/ir/ts/tsConstructorType.h @@ -78,6 +78,7 @@ public: void Compile([[maybe_unused]] compiler::PandaGen *pg) const override; checker::Type *Check(checker::Checker *checker) const override; checker::Type *GetType(checker::Checker *checker) const override; + void UpdateSelf(const NodeUpdater &cb, binder::Binder *binder) override; private: binder::Scope *scope_; diff --git a/es2panda/ir/ts/tsEnumDeclaration.cpp b/es2panda/ir/ts/tsEnumDeclaration.cpp index 304f4933eea763ac5273562b47fef559c2afec97..e75142f59748edfd4bb33f1b5bd9306b2df94ebf 100644 --- a/es2panda/ir/ts/tsEnumDeclaration.cpp +++ b/es2panda/ir/ts/tsEnumDeclaration.cpp @@ -398,4 +398,13 @@ checker::Type *TSEnumDeclaration::Check(checker::Checker *checker) const return nullptr; } +void TSEnumDeclaration::UpdateSelf(const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) +{ + key_ = std::get(cb(key_))->AsIdentifier(); + + for (auto iter = members_.begin(); iter != members_.end(); iter++) { + *iter = std::get(cb(*iter))->AsTSEnumMember(); + } +} + } // namespace panda::es2panda::ir diff --git a/es2panda/ir/ts/tsEnumDeclaration.h b/es2panda/ir/ts/tsEnumDeclaration.h index 0b04785f9d56d7ae61c832ac82e1f220463b4a27..b1920b02430882567a9d89555e5d7d0837eba1c0 100644 --- a/es2panda/ir/ts/tsEnumDeclaration.h +++ b/es2panda/ir/ts/tsEnumDeclaration.h @@ -78,6 +78,7 @@ public: void Dump(ir::AstDumper *dumper) const override; void Compile([[maybe_unused]] compiler::PandaGen *pg) const override; checker::Type *Check(checker::Checker *checker) const override; + void UpdateSelf(const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) override; private: binder::LocalScope *scope_; diff --git a/es2panda/ir/ts/tsEnumMember.cpp b/es2panda/ir/ts/tsEnumMember.cpp index 55a38d3cdcb53895e6ebae6d21e31495f4cff65c..1946bfb9264996b8ddd7f0b6fccad4972adfa7ef 100644 --- a/es2panda/ir/ts/tsEnumMember.cpp +++ b/es2panda/ir/ts/tsEnumMember.cpp @@ -41,4 +41,13 @@ checker::Type *TSEnumMember::Check([[maybe_unused]] checker::Checker *checker) c return nullptr; } +void TSEnumMember::UpdateSelf(const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) +{ + key_ = std::get(cb(key_))->AsExpression(); + + if (init_) { + init_ = std::get(cb(init_))->AsExpression(); + } +} + } // namespace panda::es2panda::ir diff --git a/es2panda/ir/ts/tsEnumMember.h b/es2panda/ir/ts/tsEnumMember.h index 8de6f9d3decc6b4268ce385c9dd321b456a71b5b..4f6d28ba5d71fe3376eec2752d625072dec33a68 100644 --- a/es2panda/ir/ts/tsEnumMember.h +++ b/es2panda/ir/ts/tsEnumMember.h @@ -51,6 +51,7 @@ public: void Dump(ir::AstDumper *dumper) const override; void Compile([[maybe_unused]] compiler::PandaGen *pg) const override; checker::Type *Check([[maybe_unused]] checker::Checker *checker) const override; + void UpdateSelf(const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) override; private: Expression *key_; diff --git a/es2panda/ir/ts/tsExternalModuleReference.cpp b/es2panda/ir/ts/tsExternalModuleReference.cpp index 67f731168db60b3bede5a721f63fdc5a246aec7a..f77c3be5bace26c134834fd49ed14aa19ed165f6 100644 --- a/es2panda/ir/ts/tsExternalModuleReference.cpp +++ b/es2panda/ir/ts/tsExternalModuleReference.cpp @@ -36,4 +36,9 @@ checker::Type *TSExternalModuleReference::Check([[maybe_unused]] checker::Checke return nullptr; } +void TSExternalModuleReference::UpdateSelf(const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) +{ + expr_ = std::get(cb(expr_))->AsExpression(); +} + } // namespace panda::es2panda::ir diff --git a/es2panda/ir/ts/tsExternalModuleReference.h b/es2panda/ir/ts/tsExternalModuleReference.h index d89233126b5fac527f494ff5d104e00aa99e864e..0b41b4d7f59220bcfc22b192b2fd100371b520d0 100644 --- a/es2panda/ir/ts/tsExternalModuleReference.h +++ b/es2panda/ir/ts/tsExternalModuleReference.h @@ -45,6 +45,7 @@ public: void Dump(ir::AstDumper *dumper) const override; void Compile([[maybe_unused]] compiler::PandaGen *pg) const override; checker::Type *Check([[maybe_unused]] checker::Checker *checker) const override; + void UpdateSelf(const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) override; private: Expression *expr_; diff --git a/es2panda/ir/ts/tsFunctionType.cpp b/es2panda/ir/ts/tsFunctionType.cpp index 7715a736cba224277385cb6fdd26012f4cd74e90..335ea72c182c5685c8b8b8063f70a931edddb275 100644 --- a/es2panda/ir/ts/tsFunctionType.cpp +++ b/es2panda/ir/ts/tsFunctionType.cpp @@ -15,6 +15,7 @@ #include "tsFunctionType.h" +#include #include #include #include @@ -65,4 +66,19 @@ checker::Type *TSFunctionType::GetType(checker::Checker *checker) const return checker->CheckTypeCached(this); } +void TSFunctionType::UpdateSelf(const NodeUpdater &cb, binder::Binder *binder) +{ + auto scopeCtx = binder::LexicalScope::Enter(binder, scope_); + + if (typeParams_) { + typeParams_ = std::get(cb(typeParams_))->AsTSTypeParameterDeclaration(); + } + + for (auto iter = params_.begin(); iter != params_.end(); iter++) { + *iter = std::get(cb(*iter))->AsExpression(); + } + + returnType_ = std::get(cb(returnType_))->AsExpression(); +} + } // namespace panda::es2panda::ir diff --git a/es2panda/ir/ts/tsFunctionType.h b/es2panda/ir/ts/tsFunctionType.h index 7cc2508df423ffced9a0819a5d482e13dcf7431c..7ce73b35f715529ee7ef880b4e2200304620e961 100644 --- a/es2panda/ir/ts/tsFunctionType.h +++ b/es2panda/ir/ts/tsFunctionType.h @@ -72,6 +72,7 @@ public: void Compile([[maybe_unused]] compiler::PandaGen *pg) const override; checker::Type *Check(checker::Checker *checker) const override; checker::Type *GetType(checker::Checker *checker) const override; + void UpdateSelf(const NodeUpdater &cb, binder::Binder *binder) override; private: binder::Scope *scope_; diff --git a/es2panda/ir/ts/tsImportEqualsDeclaration.cpp b/es2panda/ir/ts/tsImportEqualsDeclaration.cpp index 89b612bc1d711f37081f8bb70bc4010b2b8e264d..f47fb66352efb1890a095e12a42c09125c2f04ef 100644 --- a/es2panda/ir/ts/tsImportEqualsDeclaration.cpp +++ b/es2panda/ir/ts/tsImportEqualsDeclaration.cpp @@ -42,4 +42,10 @@ checker::Type *TSImportEqualsDeclaration::Check([[maybe_unused]] checker::Checke return nullptr; } +void TSImportEqualsDeclaration::UpdateSelf(const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) +{ + id_ = std::get(cb(id_))->AsIdentifier(); + moduleReference_ = std::get(cb(moduleReference_))->AsExpression(); +} + } // namespace panda::es2panda::ir diff --git a/es2panda/ir/ts/tsImportEqualsDeclaration.h b/es2panda/ir/ts/tsImportEqualsDeclaration.h index 8bcd9e65ca778243c709d6595f8738fe018edfb4..4ac96f3ba8748a86d9da7669f10cd07ac896457a 100644 --- a/es2panda/ir/ts/tsImportEqualsDeclaration.h +++ b/es2panda/ir/ts/tsImportEqualsDeclaration.h @@ -51,6 +51,11 @@ public: return moduleReference_; } + Expression *ModuleReference() + { + return moduleReference_; + } + bool IsExport() const { return isExport_; @@ -60,6 +65,7 @@ public: void Dump(ir::AstDumper *dumper) const override; void Compile([[maybe_unused]] compiler::PandaGen *pg) const override; checker::Type *Check([[maybe_unused]] checker::Checker *checker) const override; + void UpdateSelf(const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) override; private: Identifier *id_; diff --git a/es2panda/ir/ts/tsImportType.cpp b/es2panda/ir/ts/tsImportType.cpp index 89b3e32d5c2f8f736ced463d73171cf9fff41d92..3f99abf8cd98113c891ddaf3b57392b550112646 100644 --- a/es2panda/ir/ts/tsImportType.cpp +++ b/es2panda/ir/ts/tsImportType.cpp @@ -55,4 +55,17 @@ checker::Type *TSImportType::GetType([[maybe_unused]] checker::Checker *checker) return nullptr; } +void TSImportType::UpdateSelf(const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) +{ + param_ = std::get(cb(param_))->AsExpression(); + + if (typeParams_) { + typeParams_ = std::get(cb(typeParams_))->AsTSTypeParameterInstantiation(); + } + + if (qualifier_) { + qualifier_ = std::get(cb(qualifier_))->AsExpression(); + } +} + } // namespace panda::es2panda::ir diff --git a/es2panda/ir/ts/tsImportType.h b/es2panda/ir/ts/tsImportType.h index df73c96aed539744edcda46651720123c5eaae63..92d6c46bacb8d1840aaf9b6c6dcbad31a6701d08 100644 --- a/es2panda/ir/ts/tsImportType.h +++ b/es2panda/ir/ts/tsImportType.h @@ -68,6 +68,7 @@ public: void Compile([[maybe_unused]] compiler::PandaGen *pg) const override; checker::Type *Check([[maybe_unused]] checker::Checker *checker) const override; checker::Type *GetType([[maybe_unused]] checker::Checker *checker) const override; + void UpdateSelf(const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) override; private: Expression *param_; diff --git a/es2panda/ir/ts/tsIndexSignature.cpp b/es2panda/ir/ts/tsIndexSignature.cpp index 270a8aa2090bae3ef4705d2c8eb3af7d71e839db..f556086f2f530d992b271b9c382086ce1947637a 100644 --- a/es2panda/ir/ts/tsIndexSignature.cpp +++ b/es2panda/ir/ts/tsIndexSignature.cpp @@ -71,4 +71,10 @@ checker::Type *TSIndexSignature::Check(checker::Checker *checker) const return placeholder; } +void TSIndexSignature::UpdateSelf(const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) +{ + param_ = std::get(cb(param_))->AsExpression(); + typeAnnotation_ = std::get(cb(typeAnnotation_))->AsExpression(); +} + } // namespace panda::es2panda::ir diff --git a/es2panda/ir/ts/tsIndexSignature.h b/es2panda/ir/ts/tsIndexSignature.h index 170a4e7bd9529f600c591321172f82c3f5bd4bfc..07fc83ebce7fd78fde957e71739bdeefe4abfe2e 100644 --- a/es2panda/ir/ts/tsIndexSignature.h +++ b/es2panda/ir/ts/tsIndexSignature.h @@ -62,6 +62,7 @@ public: void Dump(ir::AstDumper *dumper) const override; void Compile([[maybe_unused]] compiler::PandaGen *pg) const override; checker::Type *Check(checker::Checker *checker) const override; + void UpdateSelf(const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) override; private: Expression *param_; diff --git a/es2panda/ir/ts/tsIndexedAccessType.cpp b/es2panda/ir/ts/tsIndexedAccessType.cpp index c7e479449c894e3e1107f25af6be249ad8bb17ac..ba8d8d83394cfc4a3e7b046f0ac100481e50520d 100644 --- a/es2panda/ir/ts/tsIndexedAccessType.cpp +++ b/es2panda/ir/ts/tsIndexedAccessType.cpp @@ -75,4 +75,10 @@ checker::Type *TSIndexedAccessType::GetType(checker::Checker *checker) const return resolved; } +void TSIndexedAccessType::UpdateSelf(const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) +{ + objectType_ = std::get(cb(objectType_))->AsExpression(); + indexType_ = std::get(cb(indexType_))->AsExpression(); +} + } // namespace panda::es2panda::ir diff --git a/es2panda/ir/ts/tsIndexedAccessType.h b/es2panda/ir/ts/tsIndexedAccessType.h index 9d133fdb90d430d11aadf6a3b9b2dac0feddd469..6e5be26c8c0b805cd4a764b80e2222eb6b3c9da6 100644 --- a/es2panda/ir/ts/tsIndexedAccessType.h +++ b/es2panda/ir/ts/tsIndexedAccessType.h @@ -51,6 +51,7 @@ public: void Compile([[maybe_unused]] compiler::PandaGen *pg) const override; checker::Type *Check(checker::Checker *checker) const override; checker::Type *GetType(checker::Checker *checker) const override; + void UpdateSelf(const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) override; private: Expression *objectType_; diff --git a/es2panda/ir/ts/tsInferType.cpp b/es2panda/ir/ts/tsInferType.cpp index e1787d04bd8b8d9de1e784bd9c256726887ef858..321591cddb900e852c501a5967f9f50e382a174d 100644 --- a/es2panda/ir/ts/tsInferType.cpp +++ b/es2panda/ir/ts/tsInferType.cpp @@ -42,4 +42,9 @@ checker::Type *TSInferType::GetType([[maybe_unused]] checker::Checker *checker) return nullptr; } +void TSInferType::UpdateSelf(const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) +{ + typeParam_ = std::get(cb(typeParam_))->AsTSTypeParameter(); +} + } // namespace panda::es2panda::ir diff --git a/es2panda/ir/ts/tsInferType.h b/es2panda/ir/ts/tsInferType.h index d401c76a589b4803849fe0c3f1c35dc0d0d2bdee..b0f86d34ae3d98be769382132832d9cf72c857c1 100644 --- a/es2panda/ir/ts/tsInferType.h +++ b/es2panda/ir/ts/tsInferType.h @@ -45,6 +45,7 @@ public: void Compile([[maybe_unused]] compiler::PandaGen *pg) const override; checker::Type *Check([[maybe_unused]] checker::Checker *checker) const override; checker::Type *GetType([[maybe_unused]] checker::Checker *checker) const override; + void UpdateSelf(const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) override; private: TSTypeParameter *typeParam_; diff --git a/es2panda/ir/ts/tsInterfaceBody.cpp b/es2panda/ir/ts/tsInterfaceBody.cpp index 2dc2278c714a0b30f0c8f3fe728810cf2d48d8e2..754f63f4e79480c3b887a5931c5155c790f631e3 100644 --- a/es2panda/ir/ts/tsInterfaceBody.cpp +++ b/es2panda/ir/ts/tsInterfaceBody.cpp @@ -42,4 +42,11 @@ checker::Type *TSInterfaceBody::Check(checker::Checker *checker) const return nullptr; } +void TSInterfaceBody::UpdateSelf(const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) +{ + for (auto iter = body_.begin(); iter != body_.end(); iter++) { + *iter = std::get(cb(*iter))->AsExpression(); + } +} + } // namespace panda::es2panda::ir diff --git a/es2panda/ir/ts/tsInterfaceBody.h b/es2panda/ir/ts/tsInterfaceBody.h index 62b5b52f62965b22ac7167dcef1a244f552eccdd..5792c6340c3f3ec2f8ae4998b508bcf9e1cb5048 100644 --- a/es2panda/ir/ts/tsInterfaceBody.h +++ b/es2panda/ir/ts/tsInterfaceBody.h @@ -45,6 +45,7 @@ public: void Dump(ir::AstDumper *dumper) const override; void Compile([[maybe_unused]] compiler::PandaGen *pg) const override; checker::Type *Check(checker::Checker *checker) const override; + void UpdateSelf(const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) override; private: ArenaVector body_; diff --git a/es2panda/ir/ts/tsInterfaceDeclaration.cpp b/es2panda/ir/ts/tsInterfaceDeclaration.cpp index a8e96c32591a07cc3c071399955805a380d41b1e..ef74133aa7873919bbb886be229f86134efce2a3 100644 --- a/es2panda/ir/ts/tsInterfaceDeclaration.cpp +++ b/es2panda/ir/ts/tsInterfaceDeclaration.cpp @@ -126,4 +126,19 @@ checker::Type *TSInterfaceDeclaration::Check(checker::Checker *checker) const return nullptr; } +void TSInterfaceDeclaration::UpdateSelf(const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) +{ + id_ = std::get(cb(id_))->AsIdentifier(); + + if (typeParams_) { + typeParams_ = std::get(cb(typeParams_))->AsTSTypeParameterDeclaration(); + } + + for (auto iter = extends_.begin(); iter != extends_.end(); iter++) { + *iter = std::get(cb(*iter))->AsTSInterfaceHeritage(); + } + + body_ = std::get(cb(body_))->AsTSInterfaceBody(); +} + } // namespace panda::es2panda::ir diff --git a/es2panda/ir/ts/tsInterfaceDeclaration.h b/es2panda/ir/ts/tsInterfaceDeclaration.h index a866a55d0b85152c4e194d3f6d28b3b8f3df33e2..723a92a278f4814878aef278e10ad6535074a227 100644 --- a/es2panda/ir/ts/tsInterfaceDeclaration.h +++ b/es2panda/ir/ts/tsInterfaceDeclaration.h @@ -82,6 +82,7 @@ public: void Compile([[maybe_unused]] compiler::PandaGen *pg) const override; checker::Type *Check(checker::Checker *checker) const override; checker::Type *InferType(checker::Checker *checker, binder::Variable *bindingVar) const; + void UpdateSelf(const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) override; private: binder::LocalScope *scope_; diff --git a/es2panda/ir/ts/tsInterfaceHeritage.cpp b/es2panda/ir/ts/tsInterfaceHeritage.cpp index e8801521f85b817fdd7b07a2edd0f08a10688430..32797c357de57a8f8066fdd27fbe3adce577a4f9 100644 --- a/es2panda/ir/ts/tsInterfaceHeritage.cpp +++ b/es2panda/ir/ts/tsInterfaceHeritage.cpp @@ -44,4 +44,9 @@ checker::Type *TSInterfaceHeritage::Check([[maybe_unused]] checker::Checker *che return nullptr; } +void TSInterfaceHeritage::UpdateSelf(const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) +{ + expr_ = std::get(cb(expr_))->AsExpression(); +} + } // namespace panda::es2panda::ir diff --git a/es2panda/ir/ts/tsInterfaceHeritage.h b/es2panda/ir/ts/tsInterfaceHeritage.h index 915dcf8961fe90d8b515f60268faaee55b20053e..9d6d0f18a46954ebac8f3900551cf88f00663cdf 100644 --- a/es2panda/ir/ts/tsInterfaceHeritage.h +++ b/es2panda/ir/ts/tsInterfaceHeritage.h @@ -45,6 +45,7 @@ public: void Dump(ir::AstDumper *dumper) const override; void Compile([[maybe_unused]] compiler::PandaGen *pg) const override; checker::Type *Check([[maybe_unused]] checker::Checker *checker) const override; + void UpdateSelf(const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) override; private: Expression *expr_; diff --git a/es2panda/ir/ts/tsIntersectionType.cpp b/es2panda/ir/ts/tsIntersectionType.cpp index 707f84f03486ce7a663041723ed3370ef5869619..cbffe8a516bc0311c6258906813b5624ddc7482f 100644 --- a/es2panda/ir/ts/tsIntersectionType.cpp +++ b/es2panda/ir/ts/tsIntersectionType.cpp @@ -43,4 +43,11 @@ checker::Type *TSIntersectionType::GetType([[maybe_unused]] checker::Checker *ch return nullptr; } +void TSIntersectionType::UpdateSelf(const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) +{ + for (auto iter = types_.begin(); iter != types_.end(); iter++) { + *iter = std::get(cb(*iter))->AsExpression(); + } +} + } // namespace panda::es2panda::ir diff --git a/es2panda/ir/ts/tsIntersectionType.h b/es2panda/ir/ts/tsIntersectionType.h index a31aca5863980957a04a4ef39304886649548d7b..a79ec939b51134d3a2b9ea44610a40b578320b3d 100644 --- a/es2panda/ir/ts/tsIntersectionType.h +++ b/es2panda/ir/ts/tsIntersectionType.h @@ -46,6 +46,7 @@ public: void Compile([[maybe_unused]] compiler::PandaGen *pg) const override; checker::Type *Check([[maybe_unused]] checker::Checker *checker) const override; checker::Type *GetType([[maybe_unused]] checker::Checker *checker) const override; + void UpdateSelf(const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) override; private: ArenaVector types_; diff --git a/es2panda/ir/ts/tsLiteralType.cpp b/es2panda/ir/ts/tsLiteralType.cpp index 00ebe63bbc7736df3f87796e5f75c6a093263fca..721633147ee725109b36e3c672298fc4246b6580 100644 --- a/es2panda/ir/ts/tsLiteralType.cpp +++ b/es2panda/ir/ts/tsLiteralType.cpp @@ -51,4 +51,9 @@ checker::Type *TSLiteralType::GetType(checker::Checker *checker) const return type; } +void TSLiteralType::UpdateSelf(const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) +{ + literal_ = std::get(cb(literal_))->AsExpression(); +} + } // namespace panda::es2panda::ir diff --git a/es2panda/ir/ts/tsLiteralType.h b/es2panda/ir/ts/tsLiteralType.h index 3799d9f64f490c0db8f97c12ce7bf2e2eff5b8ba..4384d9c9ecc8b05940ff937035da58835ce1cd23 100644 --- a/es2panda/ir/ts/tsLiteralType.h +++ b/es2panda/ir/ts/tsLiteralType.h @@ -43,6 +43,7 @@ public: void Compile([[maybe_unused]] compiler::PandaGen *pg) const override; checker::Type *Check(checker::Checker *checker) const override; checker::Type *GetType(checker::Checker *checker) const override; + void UpdateSelf(const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) override; private: Expression *literal_; diff --git a/es2panda/ir/ts/tsMappedType.cpp b/es2panda/ir/ts/tsMappedType.cpp index 37178340cfd5a7a0eb33c92cf57a8fcd13dda81f..e508ba89d1d9270683d454a3e2cfe6f409a3ae7f 100644 --- a/es2panda/ir/ts/tsMappedType.cpp +++ b/es2panda/ir/ts/tsMappedType.cpp @@ -55,4 +55,13 @@ checker::Type *TSMappedType::GetType([[maybe_unused]] checker::Checker *checker) return nullptr; } +void TSMappedType::UpdateSelf(const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) +{ + typeParameter_ = std::get(cb(typeParameter_))->AsTSTypeParameter(); + + if (typeAnnotation_) { + typeAnnotation_ = std::get(cb(typeAnnotation_))->AsExpression(); + } +} + } // namespace panda::es2panda::ir diff --git a/es2panda/ir/ts/tsMappedType.h b/es2panda/ir/ts/tsMappedType.h index f7d32a45749be03ea7af6e03506216bf9ec37a30..32b449638a8f548dddfd672049d29d9b34dfd6bd 100644 --- a/es2panda/ir/ts/tsMappedType.h +++ b/es2panda/ir/ts/tsMappedType.h @@ -68,6 +68,7 @@ public: void Compile([[maybe_unused]] compiler::PandaGen *pg) const override; checker::Type *Check([[maybe_unused]] checker::Checker *checker) const override; checker::Type *GetType([[maybe_unused]] checker::Checker *checker) const override; + void UpdateSelf(const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) override; private: TSTypeParameter *typeParameter_; diff --git a/es2panda/ir/ts/tsMethodSignature.cpp b/es2panda/ir/ts/tsMethodSignature.cpp index 95f0680868a33265b8394e643c934b009e5c814e..c83c09581b3e609ab7383c9c078f11dd188b6137 100644 --- a/es2panda/ir/ts/tsMethodSignature.cpp +++ b/es2panda/ir/ts/tsMethodSignature.cpp @@ -16,6 +16,7 @@ #include "tsMethodSignature.h" #include +#include #include #include #include @@ -80,4 +81,23 @@ checker::Type *TSMethodSignature::Check(checker::Checker *checker) const return nullptr; } +void TSMethodSignature::UpdateSelf(const NodeUpdater &cb, binder::Binder *binder) +{ + auto scopeCtx = binder::LexicalScope::Enter(binder, scope_); + + key_ = std::get(cb(key_))->AsExpression(); + + if (typeParams_) { + typeParams_ = std::get(cb(typeParams_))->AsTSTypeParameterDeclaration(); + } + + for (auto iter = params_.begin(); iter != params_.end(); iter++) { + *iter = std::get(cb(*iter))->AsExpression(); + } + + if (returnTypeAnnotation_) { + returnTypeAnnotation_ = std::get(cb(returnTypeAnnotation_))->AsExpression(); + } +} + } // namespace panda::es2panda::ir diff --git a/es2panda/ir/ts/tsMethodSignature.h b/es2panda/ir/ts/tsMethodSignature.h index 79f671cc8204cf77d81d6e4611db6e284550a5cd..b10488351664e4673e263b27cc3bf4368f0f8926 100644 --- a/es2panda/ir/ts/tsMethodSignature.h +++ b/es2panda/ir/ts/tsMethodSignature.h @@ -95,6 +95,7 @@ public: void Dump(ir::AstDumper *dumper) const override; void Compile([[maybe_unused]] compiler::PandaGen *pg) const override; checker::Type *Check(checker::Checker *checker) const override; + void UpdateSelf(const NodeUpdater &cb, binder::Binder *binder) override; private: binder::Scope *scope_; diff --git a/es2panda/ir/ts/tsModuleBlock.cpp b/es2panda/ir/ts/tsModuleBlock.cpp index 295d18d207903b3ca708d114eade7ead85fccad5..8955fc3b40ed3e9ea881fc1232713bbb475d02d3 100644 --- a/es2panda/ir/ts/tsModuleBlock.cpp +++ b/es2panda/ir/ts/tsModuleBlock.cpp @@ -39,4 +39,29 @@ checker::Type *TSModuleBlock::Check([[maybe_unused]] checker::Checker *checker) return nullptr; } +void TSModuleBlock::UpdateSelf(const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) +{ + for (auto iter = statements_.begin(); iter != statements_.end();) { + auto newStatements = cb(*iter); + if (std::holds_alternative(newStatements)) { + auto statement = std::get(newStatements); + if (statement == *iter) { + iter++; + } else if (statement == nullptr) { + iter = statements_.erase(iter); + } else { + *iter = statement->AsStatement(); + iter++; + } + } else { + auto statements = std::get>(newStatements); + for (auto *it : statements) { + iter = statements_.insert(iter, it->AsStatement()); + iter++; + } + iter = statements_.erase(iter); + } + } +} + } // namespace panda::es2panda::ir diff --git a/es2panda/ir/ts/tsModuleBlock.h b/es2panda/ir/ts/tsModuleBlock.h index e0c74c12d2de478624cf7802474a9d33820cbe72..f62792938f2f1fdb5161facf454e27ef1b73ae28 100644 --- a/es2panda/ir/ts/tsModuleBlock.h +++ b/es2panda/ir/ts/tsModuleBlock.h @@ -18,10 +18,6 @@ #include -namespace panda::es2panda::binder { -class LocalScope; -} // namespace panda::es2panda::binder - namespace panda::es2panda::compiler { class PandaGen; } // namespace panda::es2panda::compiler @@ -35,17 +31,17 @@ namespace panda::es2panda::ir { class TSModuleBlock : public Statement { public: - explicit TSModuleBlock(binder::LocalScope *scope, ArenaVector &&statements) - : Statement(AstNodeType::TS_MODULE_BLOCK), scope_(scope), statements_(std::move(statements)) + explicit TSModuleBlock(ArenaVector &&statements) + : Statement(AstNodeType::TS_MODULE_BLOCK), statements_(std::move(statements)) { } - binder::LocalScope *Scope() const + const ArenaVector &Statements() const { - return scope_; + return statements_; } - const ArenaVector &Statements() const + ArenaVector &Statements() { return statements_; } @@ -54,9 +50,9 @@ public: void Dump(ir::AstDumper *dumper) const override; void Compile([[maybe_unused]] compiler::PandaGen *pg) const override; checker::Type *Check([[maybe_unused]] checker::Checker *checker) const override; + void UpdateSelf(const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) override; private: - binder::LocalScope *scope_; ArenaVector statements_; }; } // namespace panda::es2panda::ir diff --git a/es2panda/ir/ts/tsModuleDeclaration.cpp b/es2panda/ir/ts/tsModuleDeclaration.cpp index 65667dd6ef996ff08c58ee2094a99bfc32e4ff8a..0cca37f7e028af1f9501c125eade2b106f58f8c8 100644 --- a/es2panda/ir/ts/tsModuleDeclaration.cpp +++ b/es2panda/ir/ts/tsModuleDeclaration.cpp @@ -15,6 +15,7 @@ #include "tsModuleDeclaration.h" +#include #include #include #include @@ -46,4 +47,14 @@ checker::Type *TSModuleDeclaration::Check([[maybe_unused]] checker::Checker *che return nullptr; } +void TSModuleDeclaration::UpdateSelf(const NodeUpdater &cb, binder::Binder *binder) +{ + name_ = std::get(cb(name_))->AsExpression(); + + if (body_) { + auto scopeCtx = binder::LexicalScope::Enter(binder, scope_); + body_ = std::get(cb(body_))->AsStatement(); + } +} + } // namespace panda::es2panda::ir diff --git a/es2panda/ir/ts/tsModuleDeclaration.h b/es2panda/ir/ts/tsModuleDeclaration.h index dc991c4d266800b4dde6b7fbc5bbce2ba4964321..82d792908054f7687b94c60d780c7fc90477508f 100644 --- a/es2panda/ir/ts/tsModuleDeclaration.h +++ b/es2panda/ir/ts/tsModuleDeclaration.h @@ -16,12 +16,9 @@ #ifndef ES2PANDA_IR_TS_MODULE_DECLARATION_H #define ES2PANDA_IR_TS_MODULE_DECLARATION_H +#include #include -namespace panda::es2panda::binder { -class LocalScope; -} // namespace panda::es2panda::binder - namespace panda::es2panda::compiler { class PandaGen; } // namespace panda::es2panda::compiler @@ -37,18 +34,19 @@ class Expression; class TSModuleDeclaration : public Statement { public: - explicit TSModuleDeclaration(binder::LocalScope *scope, Expression *name, Statement *body, bool declare, - bool global) + explicit TSModuleDeclaration(binder::TSModuleScope *scope, Expression *name, Statement *body, bool declare, + bool global, bool isInstantiated = true) : Statement(AstNodeType::TS_MODULE_DECLARATION), scope_(scope), name_(name), body_(body), declare_(declare), - global_(global) + global_(global), + isInstantiated_(isInstantiated) { } - binder::LocalScope *Scope() const + binder::TSModuleScope *Scope() const { return scope_; } @@ -63,6 +61,11 @@ public: return body_; } + Statement *Body() + { + return body_; + } + bool Declare() const { return declare_; @@ -73,17 +76,24 @@ public: return global_; } + bool IsInstantiated() const + { + return isInstantiated_; + } + void Iterate(const NodeTraverser &cb) const override; void Dump(ir::AstDumper *dumper) const override; void Compile([[maybe_unused]] compiler::PandaGen *pg) const override; checker::Type *Check([[maybe_unused]] checker::Checker *checker) const override; + void UpdateSelf(const NodeUpdater &cb, binder::Binder *binder) override; private: - binder::LocalScope *scope_; + binder::TSModuleScope *scope_; Expression *name_; Statement *body_; bool declare_; bool global_; + bool isInstantiated_; }; } // namespace panda::es2panda::ir diff --git a/es2panda/ir/ts/tsNamedTupleMember.cpp b/es2panda/ir/ts/tsNamedTupleMember.cpp index 5c76fbeef42276723b283e2dd812e2ba7bd48a56..37b95b2583b8363effff11443541130b12dd4cc7 100644 --- a/es2panda/ir/ts/tsNamedTupleMember.cpp +++ b/es2panda/ir/ts/tsNamedTupleMember.cpp @@ -42,4 +42,10 @@ checker::Type *TSNamedTupleMember::Check(checker::Checker *checker) const return nullptr; } +void TSNamedTupleMember::UpdateSelf(const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) +{ + label_ = std::get(cb(label_))->AsExpression(); + elementType_ = std::get(cb(elementType_))->AsExpression(); +} + } // namespace panda::es2panda::ir diff --git a/es2panda/ir/ts/tsNamedTupleMember.h b/es2panda/ir/ts/tsNamedTupleMember.h index 135d4ed88972ef78c3f0fe05377db81daf3ecbcc..4243a75c1e14c5c95b1650f3a98f06e876142b48 100644 --- a/es2panda/ir/ts/tsNamedTupleMember.h +++ b/es2panda/ir/ts/tsNamedTupleMember.h @@ -64,6 +64,7 @@ public: void Dump(ir::AstDumper *dumper) const override; void Compile([[maybe_unused]] compiler::PandaGen *pg) const override; checker::Type *Check(checker::Checker *checker) const override; + void UpdateSelf(const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) override; private: Expression *label_; diff --git a/es2panda/ir/ts/tsNeverKeyword.cpp b/es2panda/ir/ts/tsNeverKeyword.cpp index 4964a4a9e09ad5e1f16988d941f87410071caf48..3e2212e38a5371628259a2b7505695da6ce4c136 100644 --- a/es2panda/ir/ts/tsNeverKeyword.cpp +++ b/es2panda/ir/ts/tsNeverKeyword.cpp @@ -39,4 +39,6 @@ checker::Type *TSNeverKeyword::GetType(checker::Checker *checker) const return checker->GlobalNeverType(); } +void TSNeverKeyword::UpdateSelf([[maybe_unused]] const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) {} + } // namespace panda::es2panda::ir diff --git a/es2panda/ir/ts/tsNeverKeyword.h b/es2panda/ir/ts/tsNeverKeyword.h index 8333126ade4b42f53026da1f1bbbab24e505b5fc..5692c320dd10e72606e87d375fce24f5315330d9 100644 --- a/es2panda/ir/ts/tsNeverKeyword.h +++ b/es2panda/ir/ts/tsNeverKeyword.h @@ -38,6 +38,7 @@ public: void Compile([[maybe_unused]] compiler::PandaGen *pg) const override; checker::Type *Check([[maybe_unused]] checker::Checker *checker) const override; checker::Type *GetType(checker::Checker *checker) const override; + void UpdateSelf([[maybe_unused]] const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) override; }; } // namespace panda::es2panda::ir diff --git a/es2panda/ir/ts/tsNonNullExpression.cpp b/es2panda/ir/ts/tsNonNullExpression.cpp index 939c80a25039a013404cd751a56fe5602fccb634..06f51f77c7bbbbf4fb3265b3baeb0f409314e145 100644 --- a/es2panda/ir/ts/tsNonNullExpression.cpp +++ b/es2panda/ir/ts/tsNonNullExpression.cpp @@ -36,4 +36,9 @@ checker::Type *TSNonNullExpression::Check([[maybe_unused]] checker::Checker *che return nullptr; } +void TSNonNullExpression::UpdateSelf(const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) +{ + expr_ = std::get(cb(expr_))->AsExpression(); +} + } // namespace panda::es2panda::ir diff --git a/es2panda/ir/ts/tsNonNullExpression.h b/es2panda/ir/ts/tsNonNullExpression.h index 110a3174ef835afcc727fb1cd428c02835653bab..9f278f49f704e3919032a316d81d307bb423fb28 100644 --- a/es2panda/ir/ts/tsNonNullExpression.h +++ b/es2panda/ir/ts/tsNonNullExpression.h @@ -42,6 +42,7 @@ public: void Dump(ir::AstDumper *dumper) const override; void Compile([[maybe_unused]] compiler::PandaGen *pg) const override; checker::Type *Check([[maybe_unused]] checker::Checker *checker) const override; + void UpdateSelf(const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) override; private: Expression *expr_; diff --git a/es2panda/ir/ts/tsNullKeyword.cpp b/es2panda/ir/ts/tsNullKeyword.cpp index 0077cfc10d5d94b98f960ef2c4639daf6d6d4d8d..a8e458634527c916496effe6217991d728ccc330 100644 --- a/es2panda/ir/ts/tsNullKeyword.cpp +++ b/es2panda/ir/ts/tsNullKeyword.cpp @@ -39,4 +39,6 @@ checker::Type *TSNullKeyword::GetType(checker::Checker *checker) const return checker->GlobalNullType(); } +void TSNullKeyword::UpdateSelf([[maybe_unused]] const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) {} + } // namespace panda::es2panda::ir diff --git a/es2panda/ir/ts/tsNullKeyword.h b/es2panda/ir/ts/tsNullKeyword.h index b9bff0b967c919d8e70456523c726a399e342088..79bf0cc1cf5a0f5cd5d1a9de8c5300984048b991 100644 --- a/es2panda/ir/ts/tsNullKeyword.h +++ b/es2panda/ir/ts/tsNullKeyword.h @@ -38,6 +38,7 @@ public: void Compile([[maybe_unused]] compiler::PandaGen *pg) const override; checker::Type *Check([[maybe_unused]] checker::Checker *checker) const override; checker::Type *GetType(checker::Checker *checker) const override; + void UpdateSelf([[maybe_unused]] const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) override; }; } // namespace panda::es2panda::ir diff --git a/es2panda/ir/ts/tsNumberKeyword.cpp b/es2panda/ir/ts/tsNumberKeyword.cpp index 18d86cd934c85a3f5fe941e4069fefed59a56192..68b57f4988d638f10b662e24a4fe908872213b96 100644 --- a/es2panda/ir/ts/tsNumberKeyword.cpp +++ b/es2panda/ir/ts/tsNumberKeyword.cpp @@ -39,4 +39,6 @@ checker::Type *TSNumberKeyword::GetType(checker::Checker *checker) const return checker->GlobalNumberType(); } +void TSNumberKeyword::UpdateSelf([[maybe_unused]] const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) {} + } // namespace panda::es2panda::ir diff --git a/es2panda/ir/ts/tsNumberKeyword.h b/es2panda/ir/ts/tsNumberKeyword.h index 115936dfd957818b6ba055a349c0a55e2a5a9838..d56a49c15bb4f4669abe5483b67f49c77b264fb5 100644 --- a/es2panda/ir/ts/tsNumberKeyword.h +++ b/es2panda/ir/ts/tsNumberKeyword.h @@ -38,6 +38,7 @@ public: void Compile([[maybe_unused]] compiler::PandaGen *pg) const override; checker::Type *Check([[maybe_unused]] checker::Checker *checker) const override; checker::Type *GetType(checker::Checker *checker) const override; + void UpdateSelf([[maybe_unused]] const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) override; }; } // namespace panda::es2panda::ir diff --git a/es2panda/ir/ts/tsObjectKeyword.cpp b/es2panda/ir/ts/tsObjectKeyword.cpp index bbe29c3583668e0a85dceb407ae70c12e6bdfe30..df378afe277ca5f7fc8958dea4fbe157eccf5c09 100644 --- a/es2panda/ir/ts/tsObjectKeyword.cpp +++ b/es2panda/ir/ts/tsObjectKeyword.cpp @@ -39,4 +39,6 @@ checker::Type *TSObjectKeyword::GetType(checker::Checker *checker) const return checker->GlobalNonPrimitiveType(); } +void TSObjectKeyword::UpdateSelf([[maybe_unused]] const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) {} + } // namespace panda::es2panda::ir diff --git a/es2panda/ir/ts/tsObjectKeyword.h b/es2panda/ir/ts/tsObjectKeyword.h index 6e4fa48fdf000d631bbfe79a3dfd9b4ced274484..35d668e2191770a28b34fe0008e49c4326a36e7b 100644 --- a/es2panda/ir/ts/tsObjectKeyword.h +++ b/es2panda/ir/ts/tsObjectKeyword.h @@ -38,6 +38,7 @@ public: void Compile([[maybe_unused]] compiler::PandaGen *pg) const override; checker::Type *Check([[maybe_unused]] checker::Checker *checker) const override; checker::Type *GetType(checker::Checker *checker) const override; + void UpdateSelf([[maybe_unused]] const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) override; }; } // namespace panda::es2panda::ir diff --git a/es2panda/ir/ts/tsOptionalType.cpp b/es2panda/ir/ts/tsOptionalType.cpp index 297e6641ed2cd815248831cf9e58e41881fd914c..88dcbf14633f6c730bdc9dc5b03111a2aa93fcd4 100644 --- a/es2panda/ir/ts/tsOptionalType.cpp +++ b/es2panda/ir/ts/tsOptionalType.cpp @@ -50,4 +50,9 @@ checker::Type *TSOptionalType::GetType(checker::Checker *checker) const return type; } +void TSOptionalType::UpdateSelf(const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) +{ + type_ = std::get(cb(type_))->AsExpression(); +} + } // namespace panda::es2panda::ir diff --git a/es2panda/ir/ts/tsOptionalType.h b/es2panda/ir/ts/tsOptionalType.h index 3d9af242b0adadda008d206ea47cd65ff8cb4285..525dca1690417cb634e4108fd09e90f88e0f1e4c 100644 --- a/es2panda/ir/ts/tsOptionalType.h +++ b/es2panda/ir/ts/tsOptionalType.h @@ -31,6 +31,7 @@ public: void Compile([[maybe_unused]] compiler::PandaGen *pg) const override; checker::Type *Check([[maybe_unused]] checker::Checker *checker) const override; checker::Type *GetType(checker::Checker *checker) const override; + void UpdateSelf(const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) override; private: Expression *type_; diff --git a/es2panda/ir/ts/tsParameterProperty.cpp b/es2panda/ir/ts/tsParameterProperty.cpp index a1583d5a6a8d75887c2355684e9fd37c00ad3916..2768a1e41940dc4e6c59f54a3dfc9ff25abe4106 100644 --- a/es2panda/ir/ts/tsParameterProperty.cpp +++ b/es2panda/ir/ts/tsParameterProperty.cpp @@ -45,4 +45,10 @@ checker::Type *TSParameterProperty::Check([[maybe_unused]] checker::Checker *che { return nullptr; } + +void TSParameterProperty::UpdateSelf(const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) +{ + parameter_ = std::get(cb(parameter_))->AsExpression(); +} + } // namespace panda::es2panda::ir diff --git a/es2panda/ir/ts/tsParameterProperty.h b/es2panda/ir/ts/tsParameterProperty.h index 635ec0a45523ce68e517b17b03c473263d138584..1addbb278f17e482b8f9e311344575983be922af 100644 --- a/es2panda/ir/ts/tsParameterProperty.h +++ b/es2panda/ir/ts/tsParameterProperty.h @@ -73,6 +73,7 @@ public: void Dump(ir::AstDumper *dumper) const override; void Compile([[maybe_unused]] compiler::PandaGen *pg) const override; checker::Type *Check([[maybe_unused]] checker::Checker *checker) const override; + void UpdateSelf(const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) override; private: AccessibilityOption accessibility_; diff --git a/es2panda/ir/ts/tsParenthesizedType.cpp b/es2panda/ir/ts/tsParenthesizedType.cpp index b6dc972a033119bd31961f6e3ddd46b46892014a..25a4e89149e5a7e147422c8b9780537ef93b3ecd 100644 --- a/es2panda/ir/ts/tsParenthesizedType.cpp +++ b/es2panda/ir/ts/tsParenthesizedType.cpp @@ -51,4 +51,9 @@ checker::Type *TSParenthesizedType::GetType(checker::Checker *checker) const return type; } +void TSParenthesizedType::UpdateSelf(const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) +{ + type_ = std::get(cb(type_))->AsExpression(); +} + } // namespace panda::es2panda::ir diff --git a/es2panda/ir/ts/tsParenthesizedType.h b/es2panda/ir/ts/tsParenthesizedType.h index f40552fdf15ccd53940f066535b1dd32ea6d591c..1d2011740376f9ac38208956275c144c92486099 100644 --- a/es2panda/ir/ts/tsParenthesizedType.h +++ b/es2panda/ir/ts/tsParenthesizedType.h @@ -43,6 +43,7 @@ public: void Compile([[maybe_unused]] compiler::PandaGen *pg) const override; checker::Type *Check(checker::Checker *checker) const override; checker::Type *GetType(checker::Checker *checker) const override; + void UpdateSelf(const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) override; private: Expression *type_; diff --git a/es2panda/ir/ts/tsPrivateIdentifier.cpp b/es2panda/ir/ts/tsPrivateIdentifier.cpp index e510353450b25df865893eea233bd3f825a860c2..1ddda30c91ba72d0c7d07a9e8f667ebe763617f6 100644 --- a/es2panda/ir/ts/tsPrivateIdentifier.cpp +++ b/es2panda/ir/ts/tsPrivateIdentifier.cpp @@ -47,4 +47,17 @@ checker::Type *TSPrivateIdentifier::Check([[maybe_unused]] checker::Checker *che return nullptr; } +void TSPrivateIdentifier::UpdateSelf(const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) +{ + key_ = std::get(cb(key_))->AsExpression(); + + if (value_) { + value_ = std::get(cb(value_))->AsExpression(); + } + + if (typeAnnotation_) { + typeAnnotation_ = std::get(cb(typeAnnotation_))->AsExpression(); + } +} + } // namespace panda::es2panda::ir diff --git a/es2panda/ir/ts/tsPrivateIdentifier.h b/es2panda/ir/ts/tsPrivateIdentifier.h index e4872d5a8f204e60e4b10b25b0908693cd81dfe5..594261e2de23f946e5832665f63f00de530732cb 100644 --- a/es2panda/ir/ts/tsPrivateIdentifier.h +++ b/es2panda/ir/ts/tsPrivateIdentifier.h @@ -55,6 +55,7 @@ public: void Dump(ir::AstDumper *dumper) const override; void Compile([[maybe_unused]] compiler::PandaGen *pg) const override; checker::Type *Check([[maybe_unused]] checker::Checker *checker) const override; + void UpdateSelf(const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) override; private: Expression *key_; diff --git a/es2panda/ir/ts/tsPropertySignature.cpp b/es2panda/ir/ts/tsPropertySignature.cpp index 1905714fbccc1c11b70148a6ef6d42f7a30de7e8..2450bd47a1e99e986999434d7c21aaaf663cb0a3 100644 --- a/es2panda/ir/ts/tsPropertySignature.cpp +++ b/es2panda/ir/ts/tsPropertySignature.cpp @@ -63,4 +63,13 @@ checker::Type *TSPropertySignature::Check(checker::Checker *checker) const return nullptr; } +void TSPropertySignature::UpdateSelf(const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) +{ + key_ = std::get(cb(key_))->AsExpression(); + + if (typeAnnotation_) { + typeAnnotation_ = std::get(cb(typeAnnotation_))->AsExpression(); + } +} + } // namespace panda::es2panda::ir diff --git a/es2panda/ir/ts/tsPropertySignature.h b/es2panda/ir/ts/tsPropertySignature.h index 7adc8b2b1ad8b5dc104e83c982d65d3768a09a68..83ec0318caf634535c5c499f0f2de18fcaa4bbf5 100644 --- a/es2panda/ir/ts/tsPropertySignature.h +++ b/es2panda/ir/ts/tsPropertySignature.h @@ -76,6 +76,7 @@ public: void Dump(ir::AstDumper *dumper) const override; void Compile([[maybe_unused]] compiler::PandaGen *pg) const override; checker::Type *Check(checker::Checker *checker) const override; + void UpdateSelf(const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) override; private: Expression *key_; diff --git a/es2panda/ir/ts/tsQualifiedName.cpp b/es2panda/ir/ts/tsQualifiedName.cpp index c6088362bddc995d3a4e35842644be88685b40be..cb4acc6f7309a21b1cc24a0c7135cb5ffae68fff 100644 --- a/es2panda/ir/ts/tsQualifiedName.cpp +++ b/es2panda/ir/ts/tsQualifiedName.cpp @@ -55,4 +55,10 @@ checker::Type *TSQualifiedName::Check(checker::Checker *checker) const return nullptr; } +void TSQualifiedName::UpdateSelf(const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) +{ + left_ = std::get(cb(left_))->AsExpression(); + right_ = std::get(cb(right_))->AsIdentifier(); +} + } // namespace panda::es2panda::ir diff --git a/es2panda/ir/ts/tsQualifiedName.h b/es2panda/ir/ts/tsQualifiedName.h index 94c381a0dbeff0e720aaa72e386e74a7d9d5306d..c4e61615a97caa50996d762d3fb6281a3de09514 100644 --- a/es2panda/ir/ts/tsQualifiedName.h +++ b/es2panda/ir/ts/tsQualifiedName.h @@ -41,6 +41,11 @@ public: return left_; } + Expression *Left() + { + return left_; + } + const Identifier *Right() const { return right_; @@ -55,6 +60,7 @@ public: void Dump(ir::AstDumper *dumper) const override; void Compile([[maybe_unused]] compiler::PandaGen *pg) const override; checker::Type *Check(checker::Checker *checker) const override; + void UpdateSelf(const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) override; private: Expression *left_; diff --git a/es2panda/ir/ts/tsRestType.cpp b/es2panda/ir/ts/tsRestType.cpp index a3ec1e049c96f80bd90a86d67919d9128edb6c6d..e219fdc2ff2c37f5a18c67626020cf1b1ece0dc9 100644 --- a/es2panda/ir/ts/tsRestType.cpp +++ b/es2panda/ir/ts/tsRestType.cpp @@ -50,4 +50,9 @@ checker::Type *TSRestType::GetType(checker::Checker *checker) const return type; } +void TSRestType::UpdateSelf(const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) +{ + type_ = std::get(cb(type_))->AsExpression(); +} + } // namespace panda::es2panda::ir diff --git a/es2panda/ir/ts/tsRestType.h b/es2panda/ir/ts/tsRestType.h index 419333842fe69b0c873e4fafa3f873fbba2c9704..f9ec4a0960978a523212a11b11932bc98b9b6cf8 100644 --- a/es2panda/ir/ts/tsRestType.h +++ b/es2panda/ir/ts/tsRestType.h @@ -31,6 +31,7 @@ public: void Compile([[maybe_unused]] compiler::PandaGen *pg) const override; checker::Type *Check([[maybe_unused]] checker::Checker *checker) const override; checker::Type *GetType(checker::Checker *checker) const override; + void UpdateSelf(const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) override; private: Expression *type_; diff --git a/es2panda/ir/ts/tsSignatureDeclaration.cpp b/es2panda/ir/ts/tsSignatureDeclaration.cpp index 137bd4aa215b3c0cfc9264d4f36ad30957de0ab6..87c28ea929094f392585907799218c93d271bbea 100644 --- a/es2panda/ir/ts/tsSignatureDeclaration.cpp +++ b/es2panda/ir/ts/tsSignatureDeclaration.cpp @@ -15,12 +15,13 @@ #include "tsSignatureDeclaration.h" -#include +#include #include #include #include #include #include +#include namespace panda::es2panda::ir { @@ -94,4 +95,21 @@ checker::Type *TSSignatureDeclaration::Check(checker::Checker *checker) const return placeholderObj; } +void TSSignatureDeclaration::UpdateSelf(const NodeUpdater &cb, binder::Binder *binder) +{ + auto scopeCtx = binder::LexicalScope::Enter(binder, scope_); + + if (typeParams_) { + typeParams_ = std::get(cb(typeParams_))->AsTSTypeParameterDeclaration(); + } + + for (auto iter = params_.begin(); iter != params_.end(); iter++) { + *iter = std::get(cb(*iter))->AsExpression(); + } + + if (returnTypeAnnotation_) { + returnTypeAnnotation_ = std::get(cb(returnTypeAnnotation_))->AsExpression(); + } +} + } // namespace panda::es2panda::ir diff --git a/es2panda/ir/ts/tsSignatureDeclaration.h b/es2panda/ir/ts/tsSignatureDeclaration.h index c23f0aa31193dad828492631e59870b5b39c2710..7a2ddf2f6cd89916e80c4d4d4b2b85c1897ac0e1 100644 --- a/es2panda/ir/ts/tsSignatureDeclaration.h +++ b/es2panda/ir/ts/tsSignatureDeclaration.h @@ -79,6 +79,7 @@ public: void Dump(ir::AstDumper *dumper) const override; void Compile([[maybe_unused]] compiler::PandaGen *pg) const override; checker::Type *Check(checker::Checker *checker) const override; + void UpdateSelf(const NodeUpdater &cb, binder::Binder *binder) override; private: binder::Scope *scope_; diff --git a/es2panda/ir/ts/tsStringKeyword.cpp b/es2panda/ir/ts/tsStringKeyword.cpp index e58baba28440101c53213c6d227942334d39ad1e..faf13883cd3b52aebe9ef9deb117a147522ff83a 100644 --- a/es2panda/ir/ts/tsStringKeyword.cpp +++ b/es2panda/ir/ts/tsStringKeyword.cpp @@ -39,4 +39,6 @@ checker::Type *TSStringKeyword::GetType(checker::Checker *checker) const return checker->GlobalStringType(); } +void TSStringKeyword::UpdateSelf([[maybe_unused]] const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) {} + } // namespace panda::es2panda::ir diff --git a/es2panda/ir/ts/tsStringKeyword.h b/es2panda/ir/ts/tsStringKeyword.h index 8b626571a6ecc38ef61b6955208fec3fd4cc2272..057ecfbf8f0bceff4b4de494d92937c5d00ff81a 100644 --- a/es2panda/ir/ts/tsStringKeyword.h +++ b/es2panda/ir/ts/tsStringKeyword.h @@ -38,6 +38,7 @@ public: void Compile([[maybe_unused]] compiler::PandaGen *pg) const override; checker::Type *Check([[maybe_unused]] checker::Checker *checker) const override; checker::Type *GetType(checker::Checker *checker) const override; + void UpdateSelf([[maybe_unused]] const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) override; }; } // namespace panda::es2panda::ir diff --git a/es2panda/ir/ts/tsSymbolKeyword.cpp b/es2panda/ir/ts/tsSymbolKeyword.cpp index 7234176e4f226d871fe73878d2ddc61e77a98ccc..28ba8a6e39bd57f3ab242b7c42e022afa3c35025 100644 --- a/es2panda/ir/ts/tsSymbolKeyword.cpp +++ b/es2panda/ir/ts/tsSymbolKeyword.cpp @@ -40,4 +40,6 @@ checker::Type *TSSymbolKeyword::GetType(checker::Checker *checker) const return checker->GlobalSymbolType(); } +void TSSymbolKeyword::UpdateSelf([[maybe_unused]] const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) {} + } // namespace panda::es2panda::ir diff --git a/es2panda/ir/ts/tsSymbolKeyword.h b/es2panda/ir/ts/tsSymbolKeyword.h index 27e20304e8d6135642428b37d58ffec8bf7d4cd6..53a046cf31f6bd0f25ca90ed16d1ddca38d5be25 100644 --- a/es2panda/ir/ts/tsSymbolKeyword.h +++ b/es2panda/ir/ts/tsSymbolKeyword.h @@ -31,6 +31,7 @@ public: void Compile([[maybe_unused]] compiler::PandaGen *pg) const override; checker::Type *Check([[maybe_unused]] checker::Checker *checker) const override; checker::Type *GetType(checker::Checker *checker) const override; + void UpdateSelf([[maybe_unused]] const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) override; }; } // namespace panda::es2panda::ir diff --git a/es2panda/ir/ts/tsTemplateLiteralType.cpp b/es2panda/ir/ts/tsTemplateLiteralType.cpp index d9c300e2548c1f0ff724944c5a59b23ff3d99d84..f817c710c9d18136750dd6978a61b24c1972fa69 100644 --- a/es2panda/ir/ts/tsTemplateLiteralType.cpp +++ b/es2panda/ir/ts/tsTemplateLiteralType.cpp @@ -49,4 +49,15 @@ checker::Type *TSTemplateLiteralType::GetType(checker::Checker *checker) const return nullptr; } +void TSTemplateLiteralType::UpdateSelf(const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) +{ + for (auto iter = references_.begin(); iter != references_.end(); iter++) { + *iter = std::get(cb(*iter))->AsExpression(); + } + + for (auto iter = quasis_.begin(); iter != quasis_.end(); iter++) { + *iter = std::get(cb(*iter))->AsTemplateElement(); + } +} + } // namespace panda::es2panda::ir diff --git a/es2panda/ir/ts/tsTemplateLiteralType.h b/es2panda/ir/ts/tsTemplateLiteralType.h index 6fe63b084a1a44ad6a041f0c03f13bd9e4f62cd8..518b53c404b58aa6a33c8da6e6aee56c4d5d48ee 100644 --- a/es2panda/ir/ts/tsTemplateLiteralType.h +++ b/es2panda/ir/ts/tsTemplateLiteralType.h @@ -36,6 +36,7 @@ public: void Compile([[maybe_unused]] compiler::PandaGen *pg) const override; checker::Type *Check([[maybe_unused]] checker::Checker *checker) const override; checker::Type *GetType(checker::Checker *checker) const override; + void UpdateSelf(const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) override; private: ArenaVector quasis_; diff --git a/es2panda/ir/ts/tsThisType.cpp b/es2panda/ir/ts/tsThisType.cpp index 23573f4c4644775f928f881c58df882582a9d2bd..86a7392c01fd76092855e32f502e00d2936fc9cf 100644 --- a/es2panda/ir/ts/tsThisType.cpp +++ b/es2panda/ir/ts/tsThisType.cpp @@ -38,4 +38,6 @@ checker::Type *TSThisType::GetType([[maybe_unused]] checker::Checker *checker) c return nullptr; } +void TSThisType::UpdateSelf([[maybe_unused]] const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) {} + } // namespace panda::es2panda::ir diff --git a/es2panda/ir/ts/tsThisType.h b/es2panda/ir/ts/tsThisType.h index 826d37e38f9e9543cffe6bccced19ae68e50690e..c36a53ac7ef50942646e9f6d9de25e80d4fbc7fd 100644 --- a/es2panda/ir/ts/tsThisType.h +++ b/es2panda/ir/ts/tsThisType.h @@ -38,6 +38,7 @@ public: void Compile([[maybe_unused]] compiler::PandaGen *pg) const override; checker::Type *Check([[maybe_unused]] checker::Checker *checker) const override; checker::Type *GetType([[maybe_unused]] checker::Checker *checker) const override; + void UpdateSelf([[maybe_unused]] const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) override; }; } // namespace panda::es2panda::ir diff --git a/es2panda/ir/ts/tsTupleType.cpp b/es2panda/ir/ts/tsTupleType.cpp index 530305e70e923c0bf465c0386e22f793d7e40e14..f3fb275c9a6bb57ec9c7b3c30d135e824180bd5b 100644 --- a/es2panda/ir/ts/tsTupleType.cpp +++ b/es2panda/ir/ts/tsTupleType.cpp @@ -125,4 +125,11 @@ checker::Type *TSTupleType::Check(checker::Checker *checker) const return nullptr; } +void TSTupleType::UpdateSelf(const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) +{ + for (auto iter = elementTypes_.begin(); iter != elementTypes_.end(); iter++) { + *iter = std::get(cb(*iter))->AsExpression(); + } +} + } // namespace panda::es2panda::ir diff --git a/es2panda/ir/ts/tsTupleType.h b/es2panda/ir/ts/tsTupleType.h index e3590c8812b234540710e8204595bc94f5c64da7..3fbbd08236cdcff7f3c2275e49ded988da7daf89 100644 --- a/es2panda/ir/ts/tsTupleType.h +++ b/es2panda/ir/ts/tsTupleType.h @@ -48,6 +48,7 @@ public: void Compile([[maybe_unused]] compiler::PandaGen *pg) const override; checker::Type *Check(checker::Checker *checker) const override; checker::Type *GetType(checker::Checker *checker) const override; + void UpdateSelf(const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) override; private: ArenaVector elementTypes_; diff --git a/es2panda/ir/ts/tsTypeAliasDeclaration.cpp b/es2panda/ir/ts/tsTypeAliasDeclaration.cpp index d3061ac3d44921abe3d19aea702fc07e7b61fe54..4cb8f006ee9172f5a7c7115dd82ea8298cd7ec7a 100644 --- a/es2panda/ir/ts/tsTypeAliasDeclaration.cpp +++ b/es2panda/ir/ts/tsTypeAliasDeclaration.cpp @@ -52,4 +52,15 @@ checker::Type *TSTypeAliasDeclaration::Check(checker::Checker *checker) const return nullptr; } +void TSTypeAliasDeclaration::UpdateSelf(const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) +{ + id_ = std::get(cb(id_))->AsIdentifier(); + + if (typeParams_) { + typeParams_ = std::get(cb(typeParams_))->AsTSTypeParameterDeclaration(); + } + + typeAnnotation_ = std::get(cb(typeAnnotation_))->AsExpression(); +} + } // namespace panda::es2panda::ir diff --git a/es2panda/ir/ts/tsTypeAliasDeclaration.h b/es2panda/ir/ts/tsTypeAliasDeclaration.h index ce247e3204bf4c2efd3cc5885074220637d5a567..cab6f4beb71bdcc92b0111aad177e89d37b4bfbd 100644 --- a/es2panda/ir/ts/tsTypeAliasDeclaration.h +++ b/es2panda/ir/ts/tsTypeAliasDeclaration.h @@ -72,6 +72,7 @@ public: void Dump(ir::AstDumper *dumper) const override; void Compile([[maybe_unused]] compiler::PandaGen *pg) const override; checker::Type *Check(checker::Checker *checker) const override; + void UpdateSelf(const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) override; private: Identifier *id_; diff --git a/es2panda/ir/ts/tsTypeAssertion.cpp b/es2panda/ir/ts/tsTypeAssertion.cpp index 90ed300678e3ac304d9615a42eb94d2c4a440f2f..cc09c201032314625fce2587dfd5d3e055fba1d9 100644 --- a/es2panda/ir/ts/tsTypeAssertion.cpp +++ b/es2panda/ir/ts/tsTypeAssertion.cpp @@ -37,4 +37,10 @@ checker::Type *TSTypeAssertion::Check([[maybe_unused]] checker::Checker *checker return nullptr; } +void TSTypeAssertion::UpdateSelf(const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) +{ + typeAnnotation_ = std::get(cb(typeAnnotation_))->AsExpression(); + expression_ = std::get(cb(expression_))->AsExpression(); +} + } // namespace panda::es2panda::ir diff --git a/es2panda/ir/ts/tsTypeAssertion.h b/es2panda/ir/ts/tsTypeAssertion.h index d23ba49630adf3e0007e682d4733cdcd405898f9..afc8ced7fba8da815921bd328f080eb057d44534 100644 --- a/es2panda/ir/ts/tsTypeAssertion.h +++ b/es2panda/ir/ts/tsTypeAssertion.h @@ -50,6 +50,7 @@ public: void Dump(ir::AstDumper *dumper) const override; void Compile([[maybe_unused]] compiler::PandaGen *pg) const override; checker::Type *Check([[maybe_unused]] checker::Checker *checker) const override; + void UpdateSelf(const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) override; private: Expression *typeAnnotation_; diff --git a/es2panda/ir/ts/tsTypeLiteral.cpp b/es2panda/ir/ts/tsTypeLiteral.cpp index f5f5825e32d7d2ef778db28bea4d1c1aef7a5545..00122d78baafb127b9d8c3e30edadf8d776dcfc9 100644 --- a/es2panda/ir/ts/tsTypeLiteral.cpp +++ b/es2panda/ir/ts/tsTypeLiteral.cpp @@ -67,4 +67,12 @@ checker::Type *TSTypeLiteral::GetType(checker::Checker *checker) const return type; } + +void TSTypeLiteral::UpdateSelf(const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) +{ + for (auto iter = members_.begin(); iter != members_.end(); iter++) { + *iter = std::get(cb(*iter))->AsExpression(); + } +} + } // namespace panda::es2panda::ir diff --git a/es2panda/ir/ts/tsTypeLiteral.h b/es2panda/ir/ts/tsTypeLiteral.h index 99066fd69960c9013ed03a9a8cc5470822bd938b..d34774fa9ca12fdb220518a5f4695e0ab35805f2 100644 --- a/es2panda/ir/ts/tsTypeLiteral.h +++ b/es2panda/ir/ts/tsTypeLiteral.h @@ -46,6 +46,7 @@ public: void Compile([[maybe_unused]] compiler::PandaGen *pg) const override; checker::Type *Check(checker::Checker *checker) const override; checker::Type *GetType(checker::Checker *checker) const override; + void UpdateSelf(const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) override; private: ArenaVector members_; diff --git a/es2panda/ir/ts/tsTypeOperator.cpp b/es2panda/ir/ts/tsTypeOperator.cpp index 2d910a47e1b4a15b3e5c8d38e0aba965de543dcf..48ce1f914b82e386b06e13e6782cf86df3709b20 100644 --- a/es2panda/ir/ts/tsTypeOperator.cpp +++ b/es2panda/ir/ts/tsTypeOperator.cpp @@ -45,4 +45,9 @@ checker::Type *TSTypeOperator::GetType([[maybe_unused]] checker::Checker *checke return nullptr; } +void TSTypeOperator::UpdateSelf(const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) +{ + type_ = std::get(cb(type_))->AsExpression(); +} + } // namespace panda::es2panda::ir diff --git a/es2panda/ir/ts/tsTypeOperator.h b/es2panda/ir/ts/tsTypeOperator.h index 3f1815e9df9241b794a2a4acd600e0de8f2048e0..5883f7611cc1a10b2208107b9e87f2420a63441c 100644 --- a/es2panda/ir/ts/tsTypeOperator.h +++ b/es2panda/ir/ts/tsTypeOperator.h @@ -61,6 +61,7 @@ public: void Compile([[maybe_unused]] compiler::PandaGen *pg) const override; checker::Type *Check([[maybe_unused]] checker::Checker *checker) const override; checker::Type *GetType([[maybe_unused]] checker::Checker *checker) const override; + void UpdateSelf(const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) override; private: Expression *type_; diff --git a/es2panda/ir/ts/tsTypeParameter.cpp b/es2panda/ir/ts/tsTypeParameter.cpp index 462c53bb2e81664243f11010fbedcdca7c7dde3e..fc60a331fcc7c522460f5c6dfbd8f04730c6925e 100644 --- a/es2panda/ir/ts/tsTypeParameter.cpp +++ b/es2panda/ir/ts/tsTypeParameter.cpp @@ -50,4 +50,17 @@ checker::Type *TSTypeParameter::Check([[maybe_unused]] checker::Checker *checker return nullptr; } +void TSTypeParameter::UpdateSelf(const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) +{ + name_ = std::get(cb(name_))->AsIdentifier(); + + if (constraint_) { + constraint_ = std::get(cb(constraint_))->AsIdentifier(); + } + + if (defaultType_) { + defaultType_ = std::get(cb(defaultType_))->AsIdentifier(); + } +} + } // namespace panda::es2panda::ir diff --git a/es2panda/ir/ts/tsTypeParameter.h b/es2panda/ir/ts/tsTypeParameter.h index fb6d2c0331bb61a4a20e27721e09a1193941d520..1f6a56091869a83f9f62db3f28977879db3480bb 100644 --- a/es2panda/ir/ts/tsTypeParameter.h +++ b/es2panda/ir/ts/tsTypeParameter.h @@ -57,6 +57,7 @@ public: void Dump(ir::AstDumper *dumper) const override; void Compile([[maybe_unused]] compiler::PandaGen *pg) const override; checker::Type *Check([[maybe_unused]] checker::Checker *checker) const override; + void UpdateSelf(const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) override; private: Identifier *name_; diff --git a/es2panda/ir/ts/tsTypeParameterDeclaration.cpp b/es2panda/ir/ts/tsTypeParameterDeclaration.cpp index 7b2e868caa442f1f5c0e7aaf8343b8f463825cf3..10ed66107d01e76a900a233b3ea398dcfcb92720 100644 --- a/es2panda/ir/ts/tsTypeParameterDeclaration.cpp +++ b/es2panda/ir/ts/tsTypeParameterDeclaration.cpp @@ -40,4 +40,11 @@ checker::Type *TSTypeParameterDeclaration::Check([[maybe_unused]] checker::Check return nullptr; } +void TSTypeParameterDeclaration::UpdateSelf(const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) +{ + for (auto iter = params_.begin(); iter != params_.end(); iter++) { + *iter = std::get(cb(*iter))->AsTSTypeParameter(); + } +} + } // namespace panda::es2panda::ir diff --git a/es2panda/ir/ts/tsTypeParameterDeclaration.h b/es2panda/ir/ts/tsTypeParameterDeclaration.h index d8b09540b6bbc9e2dbcda5c76e6d883357620922..539f2aba97e9ebf0860114ba592a95123cad426e 100644 --- a/es2panda/ir/ts/tsTypeParameterDeclaration.h +++ b/es2panda/ir/ts/tsTypeParameterDeclaration.h @@ -65,6 +65,7 @@ public: void Dump(ir::AstDumper *dumper) const override; void Compile([[maybe_unused]] compiler::PandaGen *pg) const override; checker::Type *Check([[maybe_unused]] checker::Checker *checker) const override; + void UpdateSelf(const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) override; private: binder::LocalScope *scope_; diff --git a/es2panda/ir/ts/tsTypeParameterInstantiation.cpp b/es2panda/ir/ts/tsTypeParameterInstantiation.cpp index 5910cfbc0025010556464563748d00f127c977a1..332f1ba33ab9f60f4ae497af8f664d11f41eb67d 100644 --- a/es2panda/ir/ts/tsTypeParameterInstantiation.cpp +++ b/es2panda/ir/ts/tsTypeParameterInstantiation.cpp @@ -39,4 +39,11 @@ checker::Type *TSTypeParameterInstantiation::Check([[maybe_unused]] checker::Che return nullptr; } +void TSTypeParameterInstantiation::UpdateSelf(const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) +{ + for (auto iter = params_.begin(); iter != params_.end(); iter++) { + *iter = std::get(cb(*iter))->AsExpression(); + } +} + } // namespace panda::es2panda::ir diff --git a/es2panda/ir/ts/tsTypeParameterInstantiation.h b/es2panda/ir/ts/tsTypeParameterInstantiation.h index 0bedba52ffdf88b65b06ccff21e4b6270c8dddd7..318fb9f2e4ab112c2048e047406e95d57c039ee2 100644 --- a/es2panda/ir/ts/tsTypeParameterInstantiation.h +++ b/es2panda/ir/ts/tsTypeParameterInstantiation.h @@ -45,6 +45,7 @@ public: void Dump(ir::AstDumper *dumper) const override; void Compile([[maybe_unused]] compiler::PandaGen *pg) const override; checker::Type *Check([[maybe_unused]] checker::Checker *checker) const override; + void UpdateSelf(const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) override; private: ArenaVector params_; diff --git a/es2panda/ir/ts/tsTypePredicate.cpp b/es2panda/ir/ts/tsTypePredicate.cpp index 52d00c0875b3971c71b5723c8c46bd5efd19f27c..b20f29aa58abf97e07b9bd018bfbd5ad95b708cd 100644 --- a/es2panda/ir/ts/tsTypePredicate.cpp +++ b/es2panda/ir/ts/tsTypePredicate.cpp @@ -48,4 +48,13 @@ checker::Type *TSTypePredicate::GetType([[maybe_unused]] checker::Checker *check return nullptr; } +void TSTypePredicate::UpdateSelf(const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) +{ + parameterName_ = std::get(cb(parameterName_))->AsExpression(); + + if (typeAnnotation_) { + typeAnnotation_ = std::get(cb(typeAnnotation_))->AsExpression(); + } +} + } // namespace panda::es2panda::ir diff --git a/es2panda/ir/ts/tsTypePredicate.h b/es2panda/ir/ts/tsTypePredicate.h index 1c59db4bb77f86e48737435e4185c6d3245f76e2..0a5e2edca9d5bfcfa1e710f9475b94bd78288abf 100644 --- a/es2panda/ir/ts/tsTypePredicate.h +++ b/es2panda/ir/ts/tsTypePredicate.h @@ -59,6 +59,7 @@ public: void Compile([[maybe_unused]] compiler::PandaGen *pg) const override; checker::Type *Check([[maybe_unused]] checker::Checker *checker) const override; checker::Type *GetType([[maybe_unused]] checker::Checker *checker) const override; + void UpdateSelf(const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) override; private: Expression *parameterName_; diff --git a/es2panda/ir/ts/tsTypeQuery.cpp b/es2panda/ir/ts/tsTypeQuery.cpp index 0a4c50bb7f2d40794aceec05d17caee84cf51169..a9ee275d74353f9bb9109c45db93e91a98b57c83 100644 --- a/es2panda/ir/ts/tsTypeQuery.cpp +++ b/es2panda/ir/ts/tsTypeQuery.cpp @@ -53,4 +53,9 @@ checker::Type *TSTypeQuery::GetType(checker::Checker *checker) const return type; } +void TSTypeQuery::UpdateSelf(const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) +{ + exprName_ = std::get(cb(exprName_))->AsExpression(); +} + } // namespace panda::es2panda::ir diff --git a/es2panda/ir/ts/tsTypeQuery.h b/es2panda/ir/ts/tsTypeQuery.h index 5d282b8d3ed68e64555007d182f5a6b3713924ac..deab8a34c63fa6eb7b595e7abd5033003193f70a 100644 --- a/es2panda/ir/ts/tsTypeQuery.h +++ b/es2panda/ir/ts/tsTypeQuery.h @@ -43,6 +43,7 @@ public: void Compile([[maybe_unused]] compiler::PandaGen *pg) const override; checker::Type *Check(checker::Checker *checker) const override; checker::Type *GetType(checker::Checker *checker) const override; + void UpdateSelf(const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) override; private: Expression *exprName_; diff --git a/es2panda/ir/ts/tsTypeReference.cpp b/es2panda/ir/ts/tsTypeReference.cpp index 4dac7c8c79228b5e2d4dce8371f73c7c04c4e0f2..10f5002de654e8e4eae1b6fd196ff871546783f7 100644 --- a/es2panda/ir/ts/tsTypeReference.cpp +++ b/es2panda/ir/ts/tsTypeReference.cpp @@ -77,4 +77,13 @@ checker::Type *TSTypeReference::GetType(checker::Checker *checker) const return type; } +void TSTypeReference::UpdateSelf(const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) +{ + if (typeParams_) { + typeParams_ = std::get(cb(typeParams_))->AsTSTypeParameterInstantiation(); + } + + typeName_ = std::get(cb(typeName_))->AsExpression(); +} + } // namespace panda::es2panda::ir diff --git a/es2panda/ir/ts/tsTypeReference.h b/es2panda/ir/ts/tsTypeReference.h index c7af1d9d2a5b7e02501798cac4105cc49363e6ac..6f8ebe0564b2b3c3cafc73813d03e2d7cee1955e 100644 --- a/es2panda/ir/ts/tsTypeReference.h +++ b/es2panda/ir/ts/tsTypeReference.h @@ -58,6 +58,7 @@ public: void Compile([[maybe_unused]] compiler::PandaGen *pg) const override; checker::Type *Check(checker::Checker *checker) const override; checker::Type *GetType(checker::Checker *checker) const override; + void UpdateSelf(const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) override; private: Expression *typeName_; diff --git a/es2panda/ir/ts/tsUndefinedKeyword.cpp b/es2panda/ir/ts/tsUndefinedKeyword.cpp index ca431d73cf7b817832a263b276fe2a861f781f77..2b23a6fc7bc847e227a0f43b766adcf1247879b7 100644 --- a/es2panda/ir/ts/tsUndefinedKeyword.cpp +++ b/es2panda/ir/ts/tsUndefinedKeyword.cpp @@ -39,4 +39,6 @@ checker::Type *TSUndefinedKeyword::GetType(checker::Checker *checker) const return checker->GlobalUndefinedType(); } +void TSUndefinedKeyword::UpdateSelf([[maybe_unused]] const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) {} + } // namespace panda::es2panda::ir diff --git a/es2panda/ir/ts/tsUndefinedKeyword.h b/es2panda/ir/ts/tsUndefinedKeyword.h index fd7860f9d153aa7a7df11040e0f694090b024656..c3b253dbe9fc135caa32bffd66c3d1c5a7d3bd56 100644 --- a/es2panda/ir/ts/tsUndefinedKeyword.h +++ b/es2panda/ir/ts/tsUndefinedKeyword.h @@ -38,6 +38,7 @@ public: void Compile([[maybe_unused]] compiler::PandaGen *pg) const override; checker::Type *Check([[maybe_unused]] checker::Checker *checker) const override; checker::Type *GetType(checker::Checker *checker) const override; + void UpdateSelf([[maybe_unused]] const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) override; }; } // namespace panda::es2panda::ir diff --git a/es2panda/ir/ts/tsUnionType.cpp b/es2panda/ir/ts/tsUnionType.cpp index ecb98b5bbaa963d371d5040cdc204f53ea93391e..b1f1ba68e0ca478705213855396d80160043685e 100644 --- a/es2panda/ir/ts/tsUnionType.cpp +++ b/es2panda/ir/ts/tsUnionType.cpp @@ -65,4 +65,11 @@ checker::Type *TSUnionType::GetType(checker::Checker *checker) const return type; } +void TSUnionType::UpdateSelf(const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) +{ + for (auto iter = types_.begin(); iter != types_.end(); iter++) { + *iter = std::get(cb(*iter))->AsExpression(); + } +} + } // namespace panda::es2panda::ir diff --git a/es2panda/ir/ts/tsUnionType.h b/es2panda/ir/ts/tsUnionType.h index 8146f1c0526daaf7f0e6463ecd1629cd853b6d25..baf10055f8e52033cdb7cda3deb9c74c2ea0b9d6 100644 --- a/es2panda/ir/ts/tsUnionType.h +++ b/es2panda/ir/ts/tsUnionType.h @@ -46,6 +46,7 @@ public: void Compile([[maybe_unused]] compiler::PandaGen *pg) const override; checker::Type *Check(checker::Checker *checker) const override; checker::Type *GetType(checker::Checker *checker) const override; + void UpdateSelf(const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) override; private: ArenaVector types_; diff --git a/es2panda/ir/ts/tsUnknownKeyword.cpp b/es2panda/ir/ts/tsUnknownKeyword.cpp index 69f2934674a5e9508dd5040b60a051f28c48826d..d048731d69277ad349fa35361f5f7f226ea2f9d5 100644 --- a/es2panda/ir/ts/tsUnknownKeyword.cpp +++ b/es2panda/ir/ts/tsUnknownKeyword.cpp @@ -39,4 +39,6 @@ checker::Type *TSUnknownKeyword::GetType(checker::Checker *checker) const return checker->GlobalUnknownType(); } +void TSUnknownKeyword::UpdateSelf([[maybe_unused]] const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) {} + } // namespace panda::es2panda::ir diff --git a/es2panda/ir/ts/tsUnknownKeyword.h b/es2panda/ir/ts/tsUnknownKeyword.h index eacdf05ead8456ce53c051b33c45656e21be2ae2..b76ec1f652d3333b6cd3fcf5ab285710d1b53152 100644 --- a/es2panda/ir/ts/tsUnknownKeyword.h +++ b/es2panda/ir/ts/tsUnknownKeyword.h @@ -38,6 +38,7 @@ public: void Compile([[maybe_unused]] compiler::PandaGen *pg) const override; checker::Type *Check([[maybe_unused]] checker::Checker *checker) const override; checker::Type *GetType(checker::Checker *checker) const override; + void UpdateSelf([[maybe_unused]] const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) override; }; } // namespace panda::es2panda::ir diff --git a/es2panda/ir/ts/tsVoidKeyword.cpp b/es2panda/ir/ts/tsVoidKeyword.cpp index ab6febb2b2965b520459684f70a7d923a22d513c..df9998eb8b37da26d9fc6db8292263b9de0ddbba 100644 --- a/es2panda/ir/ts/tsVoidKeyword.cpp +++ b/es2panda/ir/ts/tsVoidKeyword.cpp @@ -39,4 +39,6 @@ checker::Type *TSVoidKeyword::GetType(checker::Checker *checker) const return checker->GlobalVoidType(); } +void TSVoidKeyword::UpdateSelf([[maybe_unused]] const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) {} + } // namespace panda::es2panda::ir diff --git a/es2panda/ir/ts/tsVoidKeyword.h b/es2panda/ir/ts/tsVoidKeyword.h index dbd904d6a923171632ed945d25ab2ceea1d3ee79..d898343913d7b791845e3141e1630ed630ee4227 100644 --- a/es2panda/ir/ts/tsVoidKeyword.h +++ b/es2panda/ir/ts/tsVoidKeyword.h @@ -38,6 +38,7 @@ public: void Compile([[maybe_unused]] compiler::PandaGen *pg) const override; checker::Type *Check([[maybe_unused]] checker::Checker *checker) const override; checker::Type *GetType(checker::Checker *checker) const override; + void UpdateSelf([[maybe_unused]] const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) override; }; } // namespace panda::es2panda::ir diff --git a/es2panda/parser/parserImpl.cpp b/es2panda/parser/parserImpl.cpp index 664faf665e2e91144e0734ba18d46bac27482a84..0b7012d10bb15ab2617989949d42606e02a8b35d 100644 --- a/es2panda/parser/parserImpl.cpp +++ b/es2panda/parser/parserImpl.cpp @@ -139,7 +139,11 @@ Program ParserImpl::Parse(const std::string &fileName, const std::string &source UNREACHABLE(); } } - Binder()->IdentifierAnalysis(); + binder::ResolveBindingFlags bindFlags = binder::ResolveBindingFlags::ALL; + if (Extension() == ScriptExtension::TS) { + bindFlags = binder::ResolveBindingFlags::TS_BEFORE_TRANSFORM; + } + Binder()->IdentifierAnalysis(bindFlags); return std::move(program_); } diff --git a/es2panda/parser/parserImpl.h b/es2panda/parser/parserImpl.h index ff4a6e6653321ab3128c1ae9b90af73c58ce13dd..61873d0f202ae3fbcbb603f07372126abf5cc53a 100644 --- a/es2panda/parser/parserImpl.h +++ b/es2panda/parser/parserImpl.h @@ -184,6 +184,11 @@ public: void AddHotfixHelper(util::Hotfix *hotfixHelper); + ArenaAllocator *Allocator() const + { + return program_.Allocator(); + } + private: bool IsStartOfMappedType() const; bool IsStartOfTsTypePredicate() const; @@ -418,17 +423,19 @@ private: void AddExportStarEntryItem(const lexer::SourcePosition &startLoc, const ir::StringLiteral *source, const ir::Identifier *exported); void AddExportDefaultEntryItem(const ir::AstNode *declNode); - void AddExportLocalEntryItem(const ir::Statement *declNode); + void AddExportLocalEntryItem(const ir::Statement *declNode, bool isTsModule); parser::SourceTextModuleRecord *GetSourceTextModuleRecord(); bool ParseDirective(ArenaVector *statements); void ParseDirectivePrologue(ArenaVector *statements); ArenaVector ParseStatementList(StatementParsingFlags flags = StatementParsingFlags::ALLOW_LEXICAL); ir::Statement *ParseStatement(StatementParsingFlags flags = StatementParsingFlags::NONE); - ir::TSModuleDeclaration *ParseTsModuleDeclaration(bool isDeclare); + ir::TSModuleDeclaration *ParseTsModuleDeclaration(bool isDeclare, bool isExport = false); ir::TSModuleDeclaration *ParseTsAmbientExternalModuleDeclaration(const lexer::SourcePosition &startLoc, bool isDeclare); - ir::TSModuleDeclaration *ParseTsModuleOrNamespaceDelaration(const lexer::SourcePosition &startLoc, bool isDeclare); + ir::TSModuleDeclaration *ParseTsModuleOrNamespaceDelaration(const lexer::SourcePosition &startLoc, + bool isDeclare, + bool isExport); ir::TSImportEqualsDeclaration *ParseTsImportEqualsDeclaration(const lexer::SourcePosition &startLoc, bool isExport = false); @@ -497,11 +504,6 @@ private: return internalName.View(); } - ArenaAllocator *Allocator() const - { - return program_.Allocator(); - } - binder::Binder *Binder() { return program_.Binder(); diff --git a/es2panda/parser/program/program.cpp b/es2panda/parser/program/program.cpp index 891bd46e314b1e59d13807e9b745fa21350512f7..c184046e3a2864f07346513b04acf5938ad422c3 100644 --- a/es2panda/parser/program/program.cpp +++ b/es2panda/parser/program/program.cpp @@ -35,9 +35,12 @@ Program::Program(Program &&other) ast_(other.ast_), sourceCode_(other.sourceCode_), sourceFile_(other.sourceFile_), + recordName_(other.recordName_), kind_(other.kind_), extension_(other.extension_), - lineIndex_(other.lineIndex_) + lineIndex_(other.lineIndex_), + moduleRecord_(other.moduleRecord_), + hotfixHelper_(other.hotfixHelper_) { other.binder_ = nullptr; other.ast_ = nullptr; diff --git a/es2panda/parser/statementParser.cpp b/es2panda/parser/statementParser.cpp index ffa8688480bf9dd559572bc8f493b5feca1e6889..ddb71e97f08fe740a30f1eb0856036bb3f3ab6bb 100644 --- a/es2panda/parser/statementParser.cpp +++ b/es2panda/parser/statementParser.cpp @@ -243,7 +243,7 @@ ir::Statement *ParserImpl::ParseStatement(StatementParsingFlags flags) return ParseExpressionStatement(flags); } -ir::TSModuleDeclaration *ParserImpl::ParseTsModuleDeclaration(bool isDeclare) +ir::TSModuleDeclaration *ParserImpl::ParseTsModuleDeclaration(bool isDeclare, bool isExport) { lexer::SourcePosition startLoc = lexer_->GetToken().Start(); context_.Status() |= ParserStatus::TS_MODULE; @@ -262,7 +262,7 @@ ir::TSModuleDeclaration *ParserImpl::ParseTsModuleDeclaration(bool isDeclare) } } - return ParseTsModuleOrNamespaceDelaration(startLoc, isDeclare); + return ParseTsModuleOrNamespaceDelaration(startLoc, isDeclare, isExport); } ir::TSModuleDeclaration *ParserImpl::ParseTsAmbientExternalModuleDeclaration(const lexer::SourcePosition &startLoc, @@ -288,7 +288,8 @@ ir::TSModuleDeclaration *ParserImpl::ParseTsAmbientExternalModuleDeclaration(con lexer_->NextToken(); - auto localCtx = binder::LexicalScope(Binder()); + binder::ExportBindings *exportBindings = Allocator()->New(Allocator()); + auto localCtx = binder::LexicalScope(Binder(), exportBindings); ir::Statement *body = nullptr; if (lexer_->GetToken().Type() == lexer::TokenType::PUNCTUATOR_LEFT_BRACE) { @@ -307,15 +308,32 @@ ir::TSModuleDeclaration *ParserImpl::ParseTsAmbientExternalModuleDeclaration(con } ir::TSModuleDeclaration *ParserImpl::ParseTsModuleOrNamespaceDelaration(const lexer::SourcePosition &startLoc, - bool isDeclare) + bool isDeclare, bool isExport) { if (lexer_->GetToken().Type() != lexer::TokenType::LITERAL_IDENT) { ThrowSyntaxError("Identifier expected"); } - auto *decl = Binder()->AddDecl(lexer_->GetToken().Start(), lexer_->GetToken().Ident()); + auto name = lexer_->GetToken().Ident(); + auto *parentScope = Binder()->GetScope(); + binder::Variable *res = parentScope->FindLocalTSVariable(name); + if (!res && isExport && parentScope->IsTSModuleScope()) { + res = parentScope->AsTSModuleScope()->FindExportTSVariable(name); + if (res != nullptr) { + parentScope->AddLocalTSVariable(name, res); + } + } + if (res == nullptr) { + Binder()->AddTsDecl(lexer_->GetToken().Start(), Allocator(), name); + res = parentScope->FindLocalTSVariable(name); + if (isExport && parentScope->IsTSModuleScope()) { + parentScope->AsTSModuleScope()->AddExportTSVariable(name, res); + } + res->AsNamespaceVariable()->SetExportBindings(Allocator()->New(Allocator())); + } + binder::ExportBindings *exportBindings = res->AsNamespaceVariable()->GetExportBindings(); - auto *identNode = AllocNode(lexer_->GetToken().Ident(), Allocator()); + auto *identNode = AllocNode(name, Allocator()); identNode->SetRange(lexer_->GetToken().Loc()); lexer_->NextToken(); @@ -327,22 +345,41 @@ ir::TSModuleDeclaration *ParserImpl::ParseTsModuleOrNamespaceDelaration(const le context_.Status() |= ParserStatus::IN_AMBIENT_CONTEXT; } - auto localCtx = binder::LexicalScope(Binder()); + auto localCtx = binder::LexicalScope(Binder(), exportBindings); + bool isInstantiated = false; if (lexer_->GetToken().Type() == lexer::TokenType::PUNCTUATOR_PERIOD) { lexer_->NextToken(); lexer::SourcePosition moduleStart = lexer_->GetToken().Start(); - body = ParseTsModuleOrNamespaceDelaration(moduleStart, false); + body = ParseTsModuleOrNamespaceDelaration(moduleStart, false, true); + isInstantiated = body->AsTSModuleDeclaration()->IsInstantiated(); } else { body = ParseTsModuleBlock(); + auto statements = body->AsTSModuleBlock()->Statements(); + for (auto *it : statements) { + auto statement = it; + if (statement->IsExportNamedDeclaration()) { + statement = statement->AsExportNamedDeclaration()->Decl(); + } + if (statement != nullptr && + !statement->IsTSInterfaceDeclaration() && !statement->IsTSTypeAliasDeclaration() && + (!statement->IsTSModuleDeclaration() || statement->AsTSModuleDeclaration()->IsInstantiated())) { + isInstantiated = true; + break; + } + } + } + if (isDeclare) { + isInstantiated = false; } context_.Status() = savedStatus; - auto *moduleDecl = AllocNode(localCtx.GetScope(), identNode, body, isDeclare, false); + auto *moduleDecl = AllocNode(localCtx.GetScope(), identNode, body, + isDeclare, false, isInstantiated); moduleDecl->SetRange({startLoc, lexer_->GetToken().End()}); localCtx.GetScope()->BindNode(moduleDecl); - decl->BindNode(moduleDecl); + res->Declaration()->AsNamespaceDecl()->Add(moduleDecl); return moduleDecl; } @@ -369,6 +406,21 @@ ir::TSImportEqualsDeclaration *ParserImpl::ParseTsImportEqualsDeclaration(const ThrowSyntaxError("identifier expected"); } + if (lexer_->GetToken().KeywordType() != lexer::TokenType::KEYW_REQUIRE || + lexer_->Lookahead() != LEX_CHAR_LEFT_PAREN) { + binder::DeclarationFlags declflag = binder::DeclarationFlags::NONE; + auto *decl = Binder()->AddDecl(id->Start(), declflag, id->Name()); + decl->BindNode(id); + auto *scope = Binder()->GetScope(); + auto name = id->Name(); + auto *var = scope->FindLocalTSVariable(name); + ASSERT(var != nullptr); + var->AsImportEqualsVariable()->SetScope(scope); + if (isExport && scope->IsTSModuleScope()) { + scope->AsTSModuleScope()->AddExportTSVariable(name, var); + } + } + auto *importEqualsDecl = AllocNode(id, ParseModuleReference(), isExport); importEqualsDecl->SetRange({startLoc, lexer_->GetToken().End()}); @@ -379,7 +431,6 @@ ir::TSImportEqualsDeclaration *ParserImpl::ParseTsImportEqualsDeclaration(const ir::TSModuleBlock *ParserImpl::ParseTsModuleBlock() { - auto localCtx = binder::LexicalScope(Binder()); if (lexer_->GetToken().Type() != lexer::TokenType::PUNCTUATOR_LEFT_BRACE) { ThrowSyntaxError("'{' expected."); } @@ -392,9 +443,8 @@ ir::TSModuleBlock *ParserImpl::ParseTsModuleBlock() ThrowSyntaxError("Expected a '}'"); } - auto *blockNode = AllocNode(localCtx.GetScope(), std::move(statements)); + auto *blockNode = AllocNode(std::move(statements)); blockNode->SetRange({startLoc, lexer_->GetToken().End()}); - localCtx.GetScope()->BindNode(blockNode); lexer_->NextToken(); return blockNode; @@ -2097,20 +2147,30 @@ void ParserImpl::AddExportDefaultEntryItem(const ir::AstNode *declNode) } } -void ParserImpl::AddExportLocalEntryItem(const ir::Statement *declNode) +void ParserImpl::AddExportLocalEntryItem(const ir::Statement *declNode, bool isTsModule) { ASSERT(declNode != nullptr); auto moduleRecord = GetSourceTextModuleRecord(); - ASSERT(moduleRecord != nullptr); + ASSERT(isTsModule || moduleRecord != nullptr); + binder::TSModuleScope *tsModuleScope = nullptr; + if (isTsModule) { + ASSERT(Binder()->GetScope()->IsTSModuleScope()); + tsModuleScope = Binder()->GetScope()->AsTSModuleScope(); + } if (declNode->IsVariableDeclaration()) { auto declarators = declNode->AsVariableDeclaration()->Declarators(); for (auto *decl : declarators) { std::vector bindings = util::Helpers::CollectBindingNames(decl->Id()); for (const auto *binding : bindings) { - auto *entry = moduleRecord->NewEntry( - binding->Name(), binding->Name()); - if (!moduleRecord->AddLocalExportEntry(entry)) { - ThrowSyntaxError("Duplicate export name of '" + binding->Name().Mutf8() + "'", binding->Start()); + if (isTsModule) { + tsModuleScope->AddExportVariable(binding->Name()); + } else { + auto *entry = moduleRecord->NewEntry( + binding->Name(), binding->Name()); + if (!moduleRecord->AddLocalExportEntry(entry)) { + ThrowSyntaxError("Duplicate export name of '" + binding->Name().Mutf8() + + "'", binding->Start()); + } } } } @@ -2123,9 +2183,14 @@ void ParserImpl::AddExportLocalEntryItem(const ir::Statement *declNode) ThrowSyntaxError("A class or function declaration without the default modifier mush have a name.", declNode->Start()); } - auto *entry = moduleRecord->NewEntry(name->Name(), name->Name()); - if (!moduleRecord->AddLocalExportEntry(entry)) { - ThrowSyntaxError("Duplicate export name of '" + name->Name().Mutf8() + "'", name->Start()); + if (isTsModule) { + tsModuleScope->AddExportVariable(name->Name()); + } else { + auto *entry = moduleRecord->NewEntry(name->Name(), + name->Name()); + if (!moduleRecord->AddLocalExportEntry(entry)) { + ThrowSyntaxError("Duplicate export name of '" + name->Name().Mutf8() + "'", name->Start()); + } } } } @@ -2279,6 +2344,7 @@ ir::ExportNamedDeclaration *ParserImpl::ParseNamedExportDeclaration(const lexer: ir::Statement *decl = nullptr; bool isDeclare = false; + bool isTsModule = context_.IsTsModule(); if (Extension() == ScriptExtension::TS && lexer_->GetToken().KeywordType() == lexer::TokenType::KEYW_DECLARE) { CheckDeclare(); @@ -2290,7 +2356,8 @@ ir::ExportNamedDeclaration *ParserImpl::ParseNamedExportDeclaration(const lexer: ThrowSyntaxError("Decorators are not valid here.", decorators.front()->Start()); } - VariableParsingFlags flag = VariableParsingFlags::EXPORTED; + VariableParsingFlags flag = isTsModule ? VariableParsingFlags::NO_OPTS : VariableParsingFlags::EXPORTED; + ParserStatus status = isTsModule ? ParserStatus::NO_OPTS : ParserStatus::EXPORT_REACHED; switch (lexer_->GetToken().Type()) { case lexer::TokenType::KEYW_VAR: { decl = ParseVariableDeclaration(flag | VariableParsingFlags::VAR, isDeclare); @@ -2305,11 +2372,11 @@ ir::ExportNamedDeclaration *ParserImpl::ParseNamedExportDeclaration(const lexer: break; } case lexer::TokenType::KEYW_FUNCTION: { - decl = ParseFunctionDeclaration(false, ParserStatus::EXPORT_REACHED, isDeclare); + decl = ParseFunctionDeclaration(false, status, isDeclare); break; } case lexer::TokenType::KEYW_CLASS: { - decl = ParseClassDeclaration(true, std::move(decorators), isDeclare, false, true); + decl = ParseClassDeclaration(true, std::move(decorators), isDeclare, false, !isTsModule); break; } case lexer::TokenType::LITERAL_IDENT: { @@ -2338,7 +2405,7 @@ ir::ExportNamedDeclaration *ParserImpl::ParseNamedExportDeclaration(const lexer: if (isDeclare) { context_.Status() |= ParserStatus::IN_AMBIENT_CONTEXT; } - decl = ParseTsModuleDeclaration(isDeclare); + decl = ParseTsModuleDeclaration(isDeclare, true); context_.Status() = savedStatus; break; } @@ -2360,7 +2427,7 @@ ir::ExportNamedDeclaration *ParserImpl::ParseNamedExportDeclaration(const lexer: } lexer_->NextToken(); // eat `async` keyword - decl = ParseFunctionDeclaration(false, ParserStatus::ASYNC_FUNCTION | ParserStatus::EXPORT_REACHED); + decl = ParseFunctionDeclaration(false, ParserStatus::ASYNC_FUNCTION | status); } } @@ -2368,9 +2435,7 @@ ir::ExportNamedDeclaration *ParserImpl::ParseNamedExportDeclaration(const lexer: ConsumeSemicolon(decl); } - if (Extension() != ScriptExtension::TS || !context_.IsTsModule()) { - AddExportLocalEntryItem(decl); - } + AddExportLocalEntryItem(decl, isTsModule); lexer::SourcePosition endLoc = decl->End(); ArenaVector specifiers(Allocator()->Adapter()); @@ -2383,7 +2448,7 @@ ir::ExportNamedDeclaration *ParserImpl::ParseNamedExportDeclaration(const lexer: ir::Statement *ParserImpl::ParseExportDeclaration(StatementParsingFlags flags, ArenaVector &&decorators) { - if (Extension() == ScriptExtension::JS) { + if (Extension() == ScriptExtension::JS || !context_.IsTsModule()) { if (!(flags & StatementParsingFlags::GLOBAL)) { ThrowSyntaxError("'import' and 'export' may only appear at the top level"); } @@ -2565,6 +2630,17 @@ ir::AstNode *ParserImpl::ParseImportDefaultSpecifier(ArenaVector if (lexer_->GetToken().Type() != lexer::TokenType::LITERAL_IDENT) { ThrowSyntaxError("identifier expected"); } + if (lexer_->GetToken().KeywordType() != lexer::TokenType::KEYW_REQUIRE || + lexer_->Lookahead() != LEX_CHAR_LEFT_PAREN) { + auto *decl = Binder()->AddDecl(local->Start(), + binder::DeclarationFlags::NONE, + local->Name()); + decl->BindNode(local); + auto *scope = Binder()->GetScope(); + auto *var = scope->FindLocalTSVariable(local->Name()); + ASSERT(var != nullptr); + var->AsImportEqualsVariable()->SetScope(scope); + } auto *importEqualsDecl = AllocNode(local, ParseModuleReference(), false); diff --git a/es2panda/parser/transformer/transformer.cpp b/es2panda/parser/transformer/transformer.cpp new file mode 100644 index 0000000000000000000000000000000000000000..19afc1c9fd9da78d4f923cde9a47868cb2adb3a7 --- /dev/null +++ b/es2panda/parser/transformer/transformer.cpp @@ -0,0 +1,527 @@ +/* + * 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. + */ + +#include "transformer.h" + +#include "ir/base/scriptFunction.h" +#include "ir/base/classDefinition.h" +#include "ir/expressions/assignmentExpression.h" +#include "ir/expressions/binaryExpression.h" +#include "ir/expressions/callExpression.h" +#include "ir/expressions/functionExpression.h" +#include "ir/expressions/identifier.h" +#include "ir/expressions/memberExpression.h" +#include "ir/expressions/objectExpression.h" +#include "ir/module/exportNamedDeclaration.h" +#include "ir/statements/blockStatement.h" +#include "ir/statements/classDeclaration.h" +#include "ir/statements/emptyStatement.h" +#include "ir/statements/expressionStatement.h" +#include "ir/statements/functionDeclaration.h" +#include "ir/statements/variableDeclaration.h" +#include "ir/statements/variableDeclarator.h" +#include "ir/ts/tsImportEqualsDeclaration.h" +#include "ir/ts/tsModuleBlock.h" +#include "ir/ts/tsModuleDeclaration.h" +#include "ir/ts/tsQualifiedName.h" +#include "util/helpers.h" + + +namespace panda::es2panda::parser { + +void Transformer::Transform(Program *program) +{ + program_ = program; + if (Extension() == ScriptExtension::TS) { + TransformFromTS(); + } +} + +void Transformer::TransformFromTS() +{ + ASSERT(Extension() == ScriptExtension::TS); + VisitTSNodes(program_->Ast()); +} + +ir::AstNode *Transformer::VisitTSNodes(ir::AstNode *parent) +{ + if (!parent) { + return nullptr; + } + parent->UpdateSelf([this](auto *childNode) { return VisitTSNode(childNode); }, Binder()); + return parent; +} + +binder::Scope *Transformer::FindExportVariableInTsModuleScope(util::StringView name) const +{ + bool isExport = false; + auto currentScope = Scope(); + while (currentScope != nullptr) { + binder::Variable *v = currentScope->FindLocal(name, binder::ResolveBindingOptions::ALL); + bool isTSModuleScope = currentScope->IsTSModuleScope(); + if (v != nullptr) { + if (!v->HasFlag(binder::VariableFlags::VAR)) { + break; + } + if (isTSModuleScope && currentScope->AsTSModuleScope()->FindExportVariable(name)) { + isExport = true; + } + break; + } + if (currentScope->InLocalTSBindings(name) && + !currentScope->FindLocalTSVariable(name)) { + break; + } + if (isTSModuleScope && currentScope->AsTSModuleScope()->InExportBindings(name)) { + isExport = true; + break; + } + currentScope = currentScope->Parent(); + } + if (!isExport) { + return nullptr; + } + return currentScope; +} + +ir::UpdateNodes Transformer::VisitTSNode(ir::AstNode *childNode) +{ + ASSERT(childNode != nullptr); + switch (childNode->Type()) { + case ir::AstNodeType::IDENTIFIER: { + auto *ident = childNode->AsIdentifier(); + if (!ident->IsReference() || !IsTsModule()) { + return VisitTSNodes(childNode); + } + + auto name = ident->Name(); + auto scope = FindExportVariableInTsModuleScope(name); + if (scope) { + auto moduleName = FindTSModuleNameByScope(scope); + auto *id = AllocNode(moduleName, Allocator()); + id->AsIdentifier()->SetReference(); + auto *res = AllocNode(id, AllocNode(name, Allocator()), + ir::MemberExpression::MemberExpressionKind::PROPERTY_ACCESS, false, false); + SetOriginalNode(res, childNode); + return res; + } + + return VisitTSNodes(childNode); + } + case ir::AstNodeType::TS_MODULE_DECLARATION: { + auto *node = childNode->AsTSModuleDeclaration(); + if (node->Declare() || !node->IsInstantiated()) { + return childNode; + } + auto res = VisitTsModuleDeclaration(node); + SetOriginalNode(res, childNode); + return res; + } + case ir::AstNodeType::EXPORT_NAMED_DECLARATION: { + auto *node = childNode->AsExportNamedDeclaration(); + auto *decl = node->Decl(); + if (!decl) { + return VisitTSNodes(childNode); + } + + if (decl->IsTSModuleDeclaration()) { + auto *tsModuleDeclaration = decl->AsTSModuleDeclaration(); + if (tsModuleDeclaration->Declare() || !tsModuleDeclaration->IsInstantiated()) { + return childNode; + } + auto res = VisitTsModuleDeclaration(tsModuleDeclaration, true); + SetOriginalNode(res, childNode); + return res; + } + + if (!IsTsModule()) { + return VisitTSNodes(childNode); + } + + auto res = VisitExportNamedVariable(decl); + SetOriginalNode(res, childNode); + return res; + } + case ir::AstNodeType::TS_IMPORT_EQUALS_DECLARATION: { + auto *node = childNode->AsTSImportEqualsDeclaration(); + auto *express = node->ModuleReference(); + if (express->IsTSExternalModuleReference()) { + return VisitTSNodes(childNode); + } + auto *res = VisitTsImportEqualsDeclaration(node); + SetOriginalNode(res, childNode); + return res; + } + default: { + return VisitTSNodes(childNode); + } + } +} + +ir::AstNode *Transformer::VisitTsImportEqualsDeclaration(ir::TSImportEqualsDeclaration *node) +{ + auto *express = node->ModuleReference(); + if (!IsInstantiatedTSModule(express)) { + return node; + } + auto name = node->Id()->Name(); + if (IsTsModule() && node->IsExport()) { + auto moduleName = GetCurrentTSModuleName(); + auto *id = AllocNode(moduleName, Allocator()); + id->AsIdentifier()->SetReference(); + auto *left = AllocNode(id, AllocNode(name, Allocator()), + ir::MemberExpression::MemberExpressionKind::PROPERTY_ACCESS, false, false); + ir::Expression *right = CreateMemberExpressionFromQualified(express); + auto *assignExpr = AllocNode(left, right, + lexer::TokenType::PUNCTUATOR_SUBSTITUTION); + auto *res = AllocNode(assignExpr); + return res; + } + + ir::Expression *init = CreateMemberExpressionFromQualified(express); + ir::Statement *res = CreateVariableDeclarationWithIdentify(name, VariableParsingFlags::VAR, node, + node->IsExport(), init); + if (node->IsExport()) { + ArenaVector specifiers(Allocator()->Adapter()); + res = AllocNode(res, std::move(specifiers)); + AddExportLocalEntryItem(name); + } + return res; +} + +bool Transformer::IsInstantiatedTSModule(const ir::Expression *node) const +{ + auto *var = FindTSModuleVariable(node, Scope()); + if (var == nullptr) { + return true; + } + auto *decl = var->Declaration(); + ASSERT(decl->IsNamespaceDecl()); + auto tsModules = decl->AsNamespaceDecl()->Decls(); + for (auto *it : tsModules) { + if (it->IsInstantiated()) { + return true; + } + } + return false; +} + +binder::Variable *Transformer::FindTSModuleVariable(const ir::Expression *node, binder::Scope *scope) const +{ + if (node == nullptr) { + return nullptr; + } + if (node->IsTSQualifiedName()) { + auto *tsQualifiedName = node->AsTSQualifiedName(); + auto *var = FindTSModuleVariable(tsQualifiedName->Left(), scope); + if (var == nullptr) { + return nullptr; + } + auto *exportTSBindings = var->AsNamespaceVariable()->GetExportBindings(); + auto name = tsQualifiedName->Right()->Name(); + auto *res = exportTSBindings->FindExportTSVariable(name); + if (res != nullptr) { + return res; + } + res = exportTSBindings->FindExportTSVariable(name); + if (res != nullptr) { + auto *node = res->Declaration()->Node(); + return FindTSModuleVariable(node->Parent()->AsTSImportEqualsDeclaration()->ModuleReference(), + res->AsImportEqualsVariable()->GetScope()); + } + 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); + } + if (res != nullptr) { + return res; + } + res = currentScope->FindLocalTSVariable(name); + if (res == nullptr && currentScope->IsTSModuleScope()) { + res = currentScope->AsTSModuleScope()->FindExportTSVariable(name); + } + if (res != nullptr) { + auto *node = res->Declaration()->Node(); + return FindTSModuleVariable(node->Parent()->AsTSImportEqualsDeclaration()->ModuleReference(), + res->AsImportEqualsVariable()->GetScope()); + } + currentScope = currentScope->Parent(); + } + return nullptr; +} + +std::vector Transformer::VisitExportNamedVariable(ir::Statement *decl) +{ + std::vector res; + if (decl->IsVariableDeclaration()) { + auto declarators = decl->AsVariableDeclaration()->Declarators(); + for (auto *it : declarators) { + if (it->Init()) { + auto *left = std::get(VisitTSNode(it->Id()))->AsExpression(); + auto *right = std::get(VisitTSNode(it->Init()))->AsExpression(); + auto *assignExpr = AllocNode(left, right, + lexer::TokenType::PUNCTUATOR_SUBSTITUTION); + res.push_back(AllocNode(assignExpr)); + } + } + } else if (decl->IsFunctionDeclaration() || decl->IsClassDeclaration()) { + res.push_back(VisitTSNodes(decl)); + auto name = decl->IsFunctionDeclaration() ? + decl->AsFunctionDeclaration()->Function()->Id() : + decl->AsClassDeclaration()->Definition()->Ident(); + ASSERT(name != nullptr); + res.push_back(CreateTsModuleAssignment(name->Name())); + } + return res; +} + +ir::Expression *Transformer::CreateMemberExpressionFromQualified(ir::Expression *node) +{ + if (node->IsTSQualifiedName()) { + auto *tsQualifiedName = node->AsTSQualifiedName(); + auto *left = CreateMemberExpressionFromQualified(tsQualifiedName->Left()); + auto *right = AllocNode(tsQualifiedName->Right()->Name(), Allocator()); + return AllocNode(left, right, + ir::MemberExpression::MemberExpressionKind::PROPERTY_ACCESS, false, false); + } + ASSERT(node->IsIdentifier()); + auto *id = AllocNode(node->AsIdentifier()->Name(), Allocator()); + id->AsIdentifier()->SetReference(); + return id; +} + +void Transformer::SetOriginalNode(ir::UpdateNodes res, ir::AstNode *originalNode) const +{ + if (std::holds_alternative(res)) { + auto *node = std::get(res); + if (node == nullptr || node == originalNode) { + return; + } + node->SetOriginal(originalNode); + node->SetRange(originalNode->Range()); + } else { + auto nodes = std::get>(res); + for (auto *it : nodes) { + it->SetOriginal(originalNode); + it->SetRange(originalNode->Range()); + } + } +} + +ir::ExpressionStatement *Transformer::CreateTsModuleAssignment(util::StringView name) +{ + auto moduleName = GetCurrentTSModuleName(); + auto *id = AllocNode(moduleName, Allocator()); + id->AsIdentifier()->SetReference(); + auto *left = AllocNode(id, AllocNode(name, Allocator()), + ir::MemberExpression::MemberExpressionKind::PROPERTY_ACCESS, false, false); + auto *right = AllocNode(name, Allocator()); + right->AsIdentifier()->SetReference(); + auto *assignExpr = AllocNode(left, right, lexer::TokenType::PUNCTUATOR_SUBSTITUTION); + return AllocNode(assignExpr); +} + +util::StringView Transformer::GetNameFromModuleDeclaration(ir::TSModuleDeclaration *node) const +{ + return node->Name()->AsIdentifier()->Name(); +} + +ir::VariableDeclaration *Transformer::CreateVariableDeclarationWithIdentify(util::StringView name, + VariableParsingFlags flags, + ir::AstNode *node, + bool isExport, + ir::Expression *init) +{ + auto *ident = AllocNode(name, Allocator()); + ident->AsIdentifier()->SetReference(); + auto *declarator = AllocNode(ident, init); + ArenaVector declarators(Allocator()->Adapter()); + declarators.push_back(declarator); + + binder::Decl *decl = nullptr; + binder::DeclarationFlags declflag = isExport ? + binder::DeclarationFlags::EXPORT : + binder::DeclarationFlags::NONE; + auto varKind = ir::VariableDeclaration::VariableDeclarationKind::VAR; + if (flags & VariableParsingFlags::VAR) { + decl = Binder()->AddDecl(node->Start(), declflag, name); + } else if (flags & VariableParsingFlags::LET) { + varKind = ir::VariableDeclaration::VariableDeclarationKind::LET; + decl = Binder()->AddDecl(node->Start(), declflag, name); + } else { + varKind = ir::VariableDeclaration::VariableDeclarationKind::CONST; + decl = Binder()->AddDecl(node->Start(), declflag, name); + } + + auto *declaration = AllocNode(varKind, std::move(declarators), false); + decl->BindNode(declaration); + + return declaration; +} + +util::StringView Transformer::GetParamName(ir::TSModuleDeclaration *node, util::StringView name) const +{ + auto scope = node->Scope(); + if (!scope->HasVariableName(name)) { + return name; + } + + auto pramaName = name; + uint32_t idx = 0; + do { + std::stringstream ss; + ss << name; + idx++; + ss << "_" << std::to_string(idx); + util::UString internalName(ss.str(), Allocator()); + pramaName = internalName.View(); + } while (Binder()->HasVariableName(pramaName)); + Binder()->AddDeclarationName(pramaName); + return pramaName; +} + +ir::CallExpression *Transformer::CreateCallExpressionForTsModule(ir::TSModuleDeclaration *node, + util::StringView name, + bool isExport) +{ + ir::ScriptFunction *funcNode = nullptr; + + binder::FunctionScope *funcScope = node->Scope(); + binder::FunctionParamScope *funcParamScope = funcScope->ParamScope(); + auto paramName = GetParamName(node, name); + { + auto paramScopeCtx = binder::LexicalScope::Enter(Binder(), funcParamScope); + + ArenaVector params(Allocator()->Adapter()); + auto *parameter = AllocNode(paramName, Allocator()); + parameter->AsIdentifier()->SetReference(); + Binder()->AddParamDecl(parameter); + params.push_back(parameter); + + ir::BlockStatement *blockNode = nullptr; + { + auto scopeCtx = binder::LexicalScope::Enter(Binder(), funcScope); + tsModuleList_.push_back({paramName, funcScope}); + if (node->Body()->IsTSModuleDeclaration()) { + auto *tsModule = node->Body()->AsTSModuleDeclaration(); + auto body = std::get>(VisitTsModuleDeclaration(tsModule, true)); + ArenaVector statements(Allocator()->Adapter()); + for (auto *it : body) { + statements.push_back(static_cast(it)); + } + blockNode = AllocNode(funcScope, std::move(statements)); + } else { + auto body = VisitTSNodes(node->Body()); + blockNode = AllocNode(funcScope, + std::move(body->AsTSModuleBlock()->Statements())); + } + tsModuleList_.pop_back(); + funcScope->AddBindsFromParam(); + } + + funcNode = AllocNode(funcScope, std::move(params), nullptr, blockNode, nullptr, + ir::ScriptFunctionFlags::NONE, false); + + funcScope->BindNode(funcNode); + funcParamScope->BindNode(funcNode); + } + + auto *funcExpr = AllocNode(funcNode); + + ArenaVector arguments(Allocator()->Adapter()); + ArenaVector properties(Allocator()->Adapter()); + auto *objectExpression = AllocNode(ir::AstNodeType::OBJECT_EXPRESSION, + std::move(properties), + false); + auto assignExpr = AllocNode(CreateTsModuleParam(name, isExport), + objectExpression, + lexer::TokenType::PUNCTUATOR_SUBSTITUTION); + auto argument = AllocNode(CreateTsModuleParam(name, isExport), + assignExpr, + lexer::TokenType::PUNCTUATOR_LOGICAL_OR); + if (isExport) { + auto *id = AllocNode(name, Allocator()); + id->AsIdentifier()->SetReference(); + arguments.push_back(AllocNode(id, argument, + lexer::TokenType::PUNCTUATOR_SUBSTITUTION)); + } else { + arguments.push_back(argument); + } + + auto *callExpr = AllocNode(funcExpr, std::move(arguments), nullptr, false); + + return callExpr; +} + +ir::Expression *Transformer::CreateTsModuleParam(util::StringView paramName, bool isExport) +{ + if (isExport) { + auto moduleName = GetCurrentTSModuleName(); + auto *id = AllocNode(moduleName, Allocator()); + id->AsIdentifier()->SetReference(); + return AllocNode(id, AllocNode(paramName, Allocator()), + ir::MemberExpression::MemberExpressionKind::PROPERTY_ACCESS, false, false); + } + + auto *id = AllocNode(paramName, Allocator()); + id->AsIdentifier()->SetReference(); + return id; +} + +void Transformer::AddExportLocalEntryItem(util::StringView name) +{ + auto moduleRecord = GetSourceTextModuleRecord(); + auto *entry = moduleRecord->NewEntry(name, name); + [[maybe_unused]] bool res = moduleRecord->AddLocalExportEntry(entry); + ASSERT(res); +} + +ir::UpdateNodes Transformer::VisitTsModuleDeclaration(ir::TSModuleDeclaration *node, bool isExport) +{ + std::vector res; + + util::StringView name = GetNameFromModuleDeclaration(node); + + auto findRes = Scope()->FindLocal(name, binder::ResolveBindingOptions::ALL); + if (findRes == nullptr) { + bool doExport = isExport && !IsTsModule(); + auto flag = VariableParsingFlags::VAR; + if (IsTsModule()) { + flag = VariableParsingFlags::LET; + } + auto *var = CreateVariableDeclarationWithIdentify(name, flag, node, doExport); + if (doExport) { + ArenaVector specifiers(Allocator()->Adapter()); + res.push_back(AllocNode(var, std::move(specifiers))); + AddExportLocalEntryItem(name); + } else { + res.push_back(var); + } + } + + auto *callExpr = CreateCallExpressionForTsModule(node, name, isExport && IsTsModule()); + auto *exprStatementNode = AllocNode(callExpr); + res.push_back(exprStatementNode); + + return res; +} + +} // namespace panda::es2panda::parser diff --git a/es2panda/parser/transformer/transformer.h b/es2panda/parser/transformer/transformer.h new file mode 100644 index 0000000000000000000000000000000000000000..4a444d71a12e1d2417ef9359b97d5e5ce8a1e1f2 --- /dev/null +++ b/es2panda/parser/transformer/transformer.h @@ -0,0 +1,134 @@ +/* + * 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. + */ + +#ifndef ES2PANDA_PARSER_TRANSFORMER_TRANSFORMER_H +#define ES2PANDA_PARSER_TRANSFORMER_TRANSFORMER_H + +#include + +#include "binder/binder.h" +#include "binder/scope.h" +#include "ir/astNode.h" +#include "parser/module/sourceTextModuleRecord.h" +#include "parser/parserFlags.h" +#include "parser/program/program.h" + +namespace panda::es2panda::parser { + +struct TsModuleInfo { + util::StringView name; + binder::Scope *scope; +}; + +class Transformer { +public: + explicit Transformer(panda::ArenaAllocator *allocator) + : program_(nullptr), + tsModuleList_(allocator->Adapter()) + { + } + NO_COPY_SEMANTIC(Transformer); + ~Transformer() = default; + + void Transform(Program *program); + +private: + void TransformFromTS(); + ir::AstNode *VisitTSNodes(ir::AstNode *parent); + ir::UpdateNodes VisitTSNode(ir::AstNode *childNode); + ir::UpdateNodes VisitTsModuleDeclaration(ir::TSModuleDeclaration *childNode, bool isExport = false); + std::vector VisitExportNamedVariable(ir::Statement *decl); + ir::AstNode *VisitTsImportEqualsDeclaration(ir::TSImportEqualsDeclaration *node); + ir::VariableDeclaration *CreateVariableDeclarationWithIdentify(util::StringView name, + VariableParsingFlags flags, + ir::AstNode *node, + bool isExport, + ir::Expression *init = nullptr); + ir::CallExpression *CreateCallExpressionForTsModule(ir::TSModuleDeclaration *node, + util::StringView paramName, + bool isExport = false); + ir::Expression *CreateTsModuleParam(util::StringView paramName, bool isExport); + ir::ExpressionStatement *CreateTsModuleAssignment(util::StringView name); + ir::Expression *CreateMemberExpressionFromQualified(ir::Expression *node); + util::StringView GetNameFromModuleDeclaration(ir::TSModuleDeclaration *node) const; + util::StringView GetParamName(ir::TSModuleDeclaration *node, util::StringView name) const; + binder::Scope *FindExportVariableInTsModuleScope(util::StringView name) const; + binder::Variable *FindTSModuleVariable(const ir::Expression *node, binder::Scope *scope) const; + void AddExportLocalEntryItem(util::StringView name); + bool IsInstantiatedTSModule(const ir::Expression *node) const; + void SetOriginalNode(ir::UpdateNodes res, ir::AstNode *originalNode) const; + + bool IsTsModule() const + { + return (tsModuleList_.size() != 0); + } + + template + T *AllocNode(Args &&... args) + { + auto ret = program_->Allocator()->New(std::forward(args)...); + if (ret == nullptr) { + throw Error(ErrorType::GENERIC, "Unsuccessful allocation during parsing"); + } + return ret; + } + + ArenaAllocator *Allocator() const + { + return program_->Allocator(); + } + + binder::Binder *Binder() const + { + return program_->Binder(); + } + + binder::Scope *Scope() const + { + return Binder()->GetScope(); + } + + util::StringView GetCurrentTSModuleName() const + { + return tsModuleList_.back().name; + } + + util::StringView FindTSModuleNameByScope(binder::Scope *scope) const + { + for (auto it : tsModuleList_) { + if (it.scope == scope) { + return it.name; + } + } + UNREACHABLE(); + } + + ScriptExtension Extension() const + { + return program_->Extension(); + } + + SourceTextModuleRecord *GetSourceTextModuleRecord() + { + return program_->ModuleRecord(); + } + + Program *program_; + ArenaVector tsModuleList_; +}; + +} // namespace panda::es2panda::parser + +#endif diff --git a/es2panda/test/compiler/ts/cases/compiler/test-ts-namespace-1-expected.txt b/es2panda/test/compiler/ts/cases/compiler/test-ts-namespace-1-expected.txt new file mode 100644 index 0000000000000000000000000000000000000000..52ad985cedbefc5f1de657a7906fbf3431aa1894 --- /dev/null +++ b/es2panda/test/compiler/ts/cases/compiler/test-ts-namespace-1-expected.txt @@ -0,0 +1 @@ +test-ts-namespace-1 diff --git a/es2panda/test/compiler/ts/cases/compiler/test-ts-namespace-1.ts b/es2panda/test/compiler/ts/cases/compiler/test-ts-namespace-1.ts new file mode 100644 index 0000000000000000000000000000000000000000..c3e63d1c48032aa6374ea6c613c8068288a2e7c2 --- /dev/null +++ b/es2panda/test/compiler/ts/cases/compiler/test-ts-namespace-1.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. + */ + + +namespace ns { + print("test-ts-namespace-1") +} diff --git a/es2panda/test/compiler/ts/cases/compiler/test-ts-namespace-10-expected.txt b/es2panda/test/compiler/ts/cases/compiler/test-ts-namespace-10-expected.txt new file mode 100644 index 0000000000000000000000000000000000000000..fa1afaacc0d9f72f7812e74d2e4ef5498653f9f8 --- /dev/null +++ b/es2panda/test/compiler/ts/cases/compiler/test-ts-namespace-10-expected.txt @@ -0,0 +1,4 @@ +test-ts-namespace-9 flag1 +test-ts-namespace-9 flag2 +test-ts-namespace-9 flag3 +test-ts-namespace-9 flag4 diff --git a/es2panda/test/compiler/ts/cases/compiler/test-ts-namespace-10.ts b/es2panda/test/compiler/ts/cases/compiler/test-ts-namespace-10.ts new file mode 100644 index 0000000000000000000000000000000000000000..8dfebb53b61c5396611514a1313d2f713ff88919 --- /dev/null +++ b/es2panda/test/compiler/ts/cases/compiler/test-ts-namespace-10.ts @@ -0,0 +1,40 @@ +/* + * 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.ns2 { + export namespace ns3 { + export class C { + s : string = "test-ts-namespace-9 flag1"; + f() { + print("test-ts-namespace-9 flag2"); + } + } + } + export class C { + s : string = "test-ts-namespace-9 flag3"; + f() { + print("test-ts-namespace-9 flag4"); + } + } +} + +var c : ns.ns2.ns3.C = new ns.ns2.ns3.C(); +print(c.s); +c.f(); + +var d : ns.ns2.C = new ns.ns2.C(); +print(d.s); +d.f(); diff --git a/es2panda/test/compiler/ts/cases/compiler/test-ts-namespace-11-expected.txt b/es2panda/test/compiler/ts/cases/compiler/test-ts-namespace-11-expected.txt new file mode 100644 index 0000000000000000000000000000000000000000..47e54acf1c4c8daaa765175d3e37b5e88a796d85 --- /dev/null +++ b/es2panda/test/compiler/ts/cases/compiler/test-ts-namespace-11-expected.txt @@ -0,0 +1,4 @@ +test-ts-namespace-11 flag2 +test-ts-namespace-11 flag1 +test-ts-namespace-11 flag1 +test-ts-namespace-11 flag1 diff --git a/es2panda/test/compiler/ts/cases/compiler/test-ts-namespace-11.ts b/es2panda/test/compiler/ts/cases/compiler/test-ts-namespace-11.ts new file mode 100644 index 0000000000000000000000000000000000000000..61c0acac5be774b13e5e73f7cc9c0e281404b55b --- /dev/null +++ b/es2panda/test/compiler/ts/cases/compiler/test-ts-namespace-11.ts @@ -0,0 +1,34 @@ +/* + * 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 {} + +class ns { + s : string = "test-ts-namespace-11 flag1"; +} + +var s : string = "test-ts-namespace-11 flag2"; + +namespace ns { + print(s); + export var c = new ns(); + print(c.s) +} + +print(ns.c.s) + +var d = new ns(); +print(d.s); diff --git a/es2panda/test/compiler/ts/cases/compiler/test-ts-namespace-12-expected.txt b/es2panda/test/compiler/ts/cases/compiler/test-ts-namespace-12-expected.txt new file mode 100644 index 0000000000000000000000000000000000000000..12e1d0efdbb758ad03ddee746ba19f64a7d02825 --- /dev/null +++ b/es2panda/test/compiler/ts/cases/compiler/test-ts-namespace-12-expected.txt @@ -0,0 +1,3 @@ +test-ts-namespace-12 flag3 +test-ts-namespace-12 flag1 +test-ts-namespace-12 flag2 diff --git a/es2panda/test/compiler/ts/cases/compiler/test-ts-namespace-12.ts b/es2panda/test/compiler/ts/cases/compiler/test-ts-namespace-12.ts new file mode 100644 index 0000000000000000000000000000000000000000..0022fd02afcbf011faeb26895eb5d973f3ec7769 --- /dev/null +++ b/es2panda/test/compiler/ts/cases/compiler/test-ts-namespace-12.ts @@ -0,0 +1,31 @@ +/* + * 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 {} + +function ns() { + print("test-ts-namespace-12 flag1"); +} + +namespace ns { + export function ns() { + print("test-ts-namespace-12 flag2"); + } + print("test-ts-namespace-12 flag3"); +} + +ns(); +ns.ns(); diff --git a/es2panda/test/compiler/ts/cases/compiler/test-ts-namespace-13-expected.txt b/es2panda/test/compiler/ts/cases/compiler/test-ts-namespace-13-expected.txt new file mode 100644 index 0000000000000000000000000000000000000000..acd467e6aecd04cd829ae9da3de66e2e2bf344b2 --- /dev/null +++ b/es2panda/test/compiler/ts/cases/compiler/test-ts-namespace-13-expected.txt @@ -0,0 +1,3 @@ +test-ts-namespace-13 flag1 +test-ts-namespace-13 flag2 +test-ts-namespace-13 flag3 diff --git a/es2panda/test/compiler/ts/cases/compiler/test-ts-namespace-13.ts b/es2panda/test/compiler/ts/cases/compiler/test-ts-namespace-13.ts new file mode 100644 index 0000000000000000000000000000000000000000..ed2269f7622ca03ac021b7540557164df72fd0c6 --- /dev/null +++ b/es2panda/test/compiler/ts/cases/compiler/test-ts-namespace-13.ts @@ -0,0 +1,33 @@ +/* + * 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. + */ + + +var ns1_1 : string = "test-ts-namespace-13 flag1"; +var ns2_1 : string = "test-ts-namespace-13 flag2"; +var ns3_1 : string = "test-ts-namespace-13 flag3"; + +namespace ns1 { + export namespace ns2{ + export namespace ns3{ + export var ns1 = ns1_1; + export var ns2 = ns2_1; + export var ns3 = ns3_1; + } + } +} + +print(ns1.ns2.ns3.ns1); +print(ns1.ns2.ns3.ns2); +print(ns1.ns2.ns3.ns3); diff --git a/es2panda/test/compiler/ts/cases/compiler/test-ts-namespace-14-expected.txt b/es2panda/test/compiler/ts/cases/compiler/test-ts-namespace-14-expected.txt new file mode 100644 index 0000000000000000000000000000000000000000..e4f92c18653a3b430c125b23759ecf6f441905a1 --- /dev/null +++ b/es2panda/test/compiler/ts/cases/compiler/test-ts-namespace-14-expected.txt @@ -0,0 +1,3 @@ +test-ts-namespace-13 flag2 +test-ts-namespace-13 flag3 +test-ts-namespace-13 flag2 diff --git a/es2panda/test/compiler/ts/cases/compiler/test-ts-namespace-14.ts b/es2panda/test/compiler/ts/cases/compiler/test-ts-namespace-14.ts new file mode 100644 index 0000000000000000000000000000000000000000..f377a7c382ace52647e73d4e9627d04ae9f1637f --- /dev/null +++ b/es2panda/test/compiler/ts/cases/compiler/test-ts-namespace-14.ts @@ -0,0 +1,31 @@ +/* + * 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. + */ + + +var ns2 : string = "test-ts-namespace-13 flag1"; +namespace ns { + namespace ns2 { + export var s : string = "test-ts-namespace-13 flag2"; + function f() { + var ns2 = { + s : "test-ts-namespace-13 flag3" + }; + print(s); + print(ns2.s); + } + f(); + print(ns2.s); + } +} diff --git a/es2panda/test/compiler/ts/cases/compiler/test-ts-namespace-15-expected.txt b/es2panda/test/compiler/ts/cases/compiler/test-ts-namespace-15-expected.txt new file mode 100644 index 0000000000000000000000000000000000000000..8464be06d18125b682e64c06613231b3dc557e78 --- /dev/null +++ b/es2panda/test/compiler/ts/cases/compiler/test-ts-namespace-15-expected.txt @@ -0,0 +1,2 @@ +test-ts-namespace-15 flag1 +test-ts-namespace-15 flag2 diff --git a/es2panda/test/compiler/ts/cases/compiler/test-ts-namespace-15.ts b/es2panda/test/compiler/ts/cases/compiler/test-ts-namespace-15.ts new file mode 100644 index 0000000000000000000000000000000000000000..0fc35ad791e6714dc43578915ce71cbd746f8d29 --- /dev/null +++ b/es2panda/test/compiler/ts/cases/compiler/test-ts-namespace-15.ts @@ -0,0 +1,27 @@ +/* + * 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 var a : string = "test-ts-namespace-15 flag1"; +} + +print(ns.a); + +namespace ns { + export var a : string = "test-ts-namespace-15 flag2"; +} + +print(ns.a); diff --git a/es2panda/test/compiler/ts/cases/compiler/test-ts-namespace-16-expected.txt b/es2panda/test/compiler/ts/cases/compiler/test-ts-namespace-16-expected.txt new file mode 100644 index 0000000000000000000000000000000000000000..40fd190b003dacdd2402bf4f7643f0be9e63000b --- /dev/null +++ b/es2panda/test/compiler/ts/cases/compiler/test-ts-namespace-16-expected.txt @@ -0,0 +1 @@ +test-ts-namespace-16 diff --git a/es2panda/test/compiler/ts/cases/compiler/test-ts-namespace-16.ts b/es2panda/test/compiler/ts/cases/compiler/test-ts-namespace-16.ts new file mode 100644 index 0000000000000000000000000000000000000000..9d839295c540c4df37fa3a77990ed9d3857e764c --- /dev/null +++ b/es2panda/test/compiler/ts/cases/compiler/test-ts-namespace-16.ts @@ -0,0 +1,32 @@ +/* + * 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 C = ns.ns3.ns4; + +namespace ns { + export namespace ns2 { + export namespace ns4 {} + } + export import ns3 = ns2; + var a = 1; +} + +class C { + a : string = "test-ts-namespace-16"; +} + +var c = new C(); +print(c.a); diff --git a/es2panda/test/compiler/ts/cases/compiler/test-ts-namespace-17-expected.txt b/es2panda/test/compiler/ts/cases/compiler/test-ts-namespace-17-expected.txt new file mode 100644 index 0000000000000000000000000000000000000000..62c9e811e2f8eead12bc38d5e9dd98e98d80d71e --- /dev/null +++ b/es2panda/test/compiler/ts/cases/compiler/test-ts-namespace-17-expected.txt @@ -0,0 +1,3 @@ +test-ts-namespace-17 +test-ts-namespace-17 +test-ts-namespace-17 diff --git a/es2panda/test/compiler/ts/cases/compiler/test-ts-namespace-17.ts b/es2panda/test/compiler/ts/cases/compiler/test-ts-namespace-17.ts new file mode 100644 index 0000000000000000000000000000000000000000..5c421937c59480f965cda91184b9fc52f680c9a3 --- /dev/null +++ b/es2panda/test/compiler/ts/cases/compiler/test-ts-namespace-17.ts @@ -0,0 +1,29 @@ +/* + * 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 { + namespace ns2 { + export var a : string = "test-ts-namespace-17"; + } + export import b = ns2.a; + print(b); +} + +namespace ns { + print(b); +} + +print(ns.b); \ No newline at end of file diff --git a/es2panda/test/compiler/ts/cases/compiler/test-ts-namespace-2-expected.txt b/es2panda/test/compiler/ts/cases/compiler/test-ts-namespace-2-expected.txt new file mode 100644 index 0000000000000000000000000000000000000000..72351bd590150936139f5222e1fddb2f0105cad3 --- /dev/null +++ b/es2panda/test/compiler/ts/cases/compiler/test-ts-namespace-2-expected.txt @@ -0,0 +1 @@ +test-ts-namespace-2 diff --git a/es2panda/test/compiler/ts/cases/compiler/test-ts-namespace-2.ts b/es2panda/test/compiler/ts/cases/compiler/test-ts-namespace-2.ts new file mode 100644 index 0000000000000000000000000000000000000000..fd6bdfb3f720496b9b59ca7ccd31f9f20ed86613 --- /dev/null +++ b/es2panda/test/compiler/ts/cases/compiler/test-ts-namespace-2.ts @@ -0,0 +1,21 @@ +/* + * 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.ns2 { + namespace ns3 { + print("test-ts-namespace-2") + } +} diff --git a/es2panda/test/compiler/ts/cases/compiler/test-ts-namespace-3-expected.txt b/es2panda/test/compiler/ts/cases/compiler/test-ts-namespace-3-expected.txt new file mode 100644 index 0000000000000000000000000000000000000000..16127b818037cd2a416bed04811a7f238b04e539 --- /dev/null +++ b/es2panda/test/compiler/ts/cases/compiler/test-ts-namespace-3-expected.txt @@ -0,0 +1 @@ +test-ts-namespace-3 diff --git a/es2panda/test/compiler/ts/cases/compiler/test-ts-namespace-3.ts b/es2panda/test/compiler/ts/cases/compiler/test-ts-namespace-3.ts new file mode 100644 index 0000000000000000000000000000000000000000..4ef471ef67d0479e7043433e6f9010eef9de51ca --- /dev/null +++ b/es2panda/test/compiler/ts/cases/compiler/test-ts-namespace-3.ts @@ -0,0 +1,21 @@ +/* + * 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 var ns : string = "test-ts-namespace-3"; +} + +print(ns.ns) diff --git a/es2panda/test/compiler/ts/cases/compiler/test-ts-namespace-4-expected.txt b/es2panda/test/compiler/ts/cases/compiler/test-ts-namespace-4-expected.txt new file mode 100644 index 0000000000000000000000000000000000000000..e80ae4c2dfd39216f7d9526e1dcea16494751c7b --- /dev/null +++ b/es2panda/test/compiler/ts/cases/compiler/test-ts-namespace-4-expected.txt @@ -0,0 +1 @@ +test-ts-namespace-4 diff --git a/es2panda/test/compiler/ts/cases/compiler/test-ts-namespace-4.ts b/es2panda/test/compiler/ts/cases/compiler/test-ts-namespace-4.ts new file mode 100644 index 0000000000000000000000000000000000000000..113b7235a3b7d6ad89f2ef417b2a1e98187d7ad9 --- /dev/null +++ b/es2panda/test/compiler/ts/cases/compiler/test-ts-namespace-4.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.ns2 { + export namespace ns3 { + export var ns : string = "test-ts-namespace-4"; + } +} + +print(ns.ns2.ns3.ns) diff --git a/es2panda/test/compiler/ts/cases/compiler/test-ts-namespace-5-expected.txt b/es2panda/test/compiler/ts/cases/compiler/test-ts-namespace-5-expected.txt new file mode 100644 index 0000000000000000000000000000000000000000..2a3ce4dac51b529b552b889a77235f92d5352bb3 --- /dev/null +++ b/es2panda/test/compiler/ts/cases/compiler/test-ts-namespace-5-expected.txt @@ -0,0 +1,3 @@ +test-ts-namespace-5 +test-ts-namespace-5 +test-ts-namespace-5 diff --git a/es2panda/test/compiler/ts/cases/compiler/test-ts-namespace-5.ts b/es2panda/test/compiler/ts/cases/compiler/test-ts-namespace-5.ts new file mode 100644 index 0000000000000000000000000000000000000000..9a904dd796fa1abeb352a222b5e3fda31ac80386 --- /dev/null +++ b/es2panda/test/compiler/ts/cases/compiler/test-ts-namespace-5.ts @@ -0,0 +1,32 @@ +/* + * 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 { + namespace ns2 { + export var s : string = "test-ts-namespace-5"; + } + export import ns = ns2.s; +} + +namespace ns { + print(ns) +} + +import ns3 = ns; +print(ns3.ns) + +import s = ns.ns; +print(s) diff --git a/es2panda/test/compiler/ts/cases/compiler/test-ts-namespace-6-expected.txt b/es2panda/test/compiler/ts/cases/compiler/test-ts-namespace-6-expected.txt new file mode 100644 index 0000000000000000000000000000000000000000..02948d5e0c14fce99d191e5d1e10a8330f217f2a --- /dev/null +++ b/es2panda/test/compiler/ts/cases/compiler/test-ts-namespace-6-expected.txt @@ -0,0 +1 @@ +test-ts-namespace-6 diff --git a/es2panda/test/compiler/ts/cases/compiler/test-ts-namespace-6.ts b/es2panda/test/compiler/ts/cases/compiler/test-ts-namespace-6.ts new file mode 100644 index 0000000000000000000000000000000000000000..79142da30180e076e70b5643b9d3dfb199d786fe --- /dev/null +++ b/es2panda/test/compiler/ts/cases/compiler/test-ts-namespace-6.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 var ns : string = "test-ts-namespace-6"; +} + +namespace ns { + print(ns); +} diff --git a/es2panda/test/compiler/ts/cases/compiler/test-ts-namespace-7-expected.txt b/es2panda/test/compiler/ts/cases/compiler/test-ts-namespace-7-expected.txt new file mode 100644 index 0000000000000000000000000000000000000000..0bb6191a182c9ce6cafb958fdd277f597f999034 --- /dev/null +++ b/es2panda/test/compiler/ts/cases/compiler/test-ts-namespace-7-expected.txt @@ -0,0 +1,3 @@ +test-ts-namespace-7 flag1 +test-ts-namespace-7 flag2 +test-ts-namespace-7 flag3 diff --git a/es2panda/test/compiler/ts/cases/compiler/test-ts-namespace-7.ts b/es2panda/test/compiler/ts/cases/compiler/test-ts-namespace-7.ts new file mode 100644 index 0000000000000000000000000000000000000000..c46ef2ed3ccc97aef17a31b3d264e54bbc89259a --- /dev/null +++ b/es2panda/test/compiler/ts/cases/compiler/test-ts-namespace-7.ts @@ -0,0 +1,49 @@ +/* + * 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.ns2 { + export namespace ns3{ + export var s : string = "test-ts-namespace-7 flag1"; + } +} + +var s : string = "test-ts-namespace-7 flag2"; +namespace ns.ns2 { + export namespace ns3{ + export namespace ns4{ + print(s); + } + } +} + +namespace ns.ns2 { + namespace ns3 { + export namespace ns4 { + print(s); + } + } +} + +namespace ns.ns2 { + namespace ns3 { + export var s : string = "test-ts-namespace-7 flag3"; + } + namespace ns3 { + export namespace ns4 { + print(s) + } + } +} diff --git a/es2panda/test/compiler/ts/cases/compiler/test-ts-namespace-8-expected.txt b/es2panda/test/compiler/ts/cases/compiler/test-ts-namespace-8-expected.txt new file mode 100644 index 0000000000000000000000000000000000000000..285fd0a25b5b856f2d154258dbce703f07bc06ba --- /dev/null +++ b/es2panda/test/compiler/ts/cases/compiler/test-ts-namespace-8-expected.txt @@ -0,0 +1 @@ +test-ts-namespace-8 diff --git a/es2panda/test/compiler/ts/cases/compiler/test-ts-namespace-8.ts b/es2panda/test/compiler/ts/cases/compiler/test-ts-namespace-8.ts new file mode 100644 index 0000000000000000000000000000000000000000..00a411759bdf959f582c56900a02388d11f13cd9 --- /dev/null +++ b/es2panda/test/compiler/ts/cases/compiler/test-ts-namespace-8.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.ns2 { + export var ns2 : string = "test-ts-namespace-8"; +} + +namespace ns.ns2.ns3 { + print(ns2); +} diff --git a/es2panda/test/compiler/ts/cases/compiler/test-ts-namespace-9-expected.txt b/es2panda/test/compiler/ts/cases/compiler/test-ts-namespace-9-expected.txt new file mode 100644 index 0000000000000000000000000000000000000000..549855f097427e0e5a007c51cb06684d9c1c3d5f --- /dev/null +++ b/es2panda/test/compiler/ts/cases/compiler/test-ts-namespace-9-expected.txt @@ -0,0 +1,2 @@ +test-ts-namespace-9 flag1 +test-ts-namespace-9 flag2 diff --git a/es2panda/test/compiler/ts/cases/compiler/test-ts-namespace-9.ts b/es2panda/test/compiler/ts/cases/compiler/test-ts-namespace-9.ts new file mode 100644 index 0000000000000000000000000000000000000000..3e2eb228e106f1909c1fbbb62354e7b36f94baf0 --- /dev/null +++ b/es2panda/test/compiler/ts/cases/compiler/test-ts-namespace-9.ts @@ -0,0 +1,29 @@ +/* + * 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.ns2 { + export namespace ns3 { + export function f() { + print("test-ts-namespace-9 flag1"); + } + } + export function f() { + print("test-ts-namespace-9 flag2"); + } +} + +ns.ns2.ns3.f(); +ns.ns2.f(); diff --git a/es2panda/test/test_tsc_ignore_list.txt b/es2panda/test/test_tsc_ignore_list.txt index 4d79e018a15b8c012dbaa067a97d5b998b09d877..716ca0e026f689dcceeda7c22a77f185ffb6a9b7 100644 --- a/es2panda/test/test_tsc_ignore_list.txt +++ b/es2panda/test/test_tsc_ignore_list.txt @@ -1,182 +1,125 @@ -es2panda/test/TypeScript/tests/cases/conformance/functions/functionWithUseStrictAndSimpleParameterList.ts -es2panda/test/TypeScript/tests/cases/conformance/externalModules/es6/es6modulekindWithES5Target12.ts -es2panda/test/TypeScript/tests/cases/conformance/externalModules/esnext/esnextmodulekindWithES5Target12.ts -es2panda/test/TypeScript/tests/cases/conformance/expressions/propertyAccess/propertyAccessNumericLiterals.ts -es2panda/test/TypeScript/tests/cases/conformance/expressions/typeGuards/typePredicateASI.ts -es2panda/test/TypeScript/tests/cases/conformance/expressions/typeGuards/typeGuardFunctionOfFormThis.ts -es2panda/test/TypeScript/tests/cases/conformance/expressions/nullishCoalescingOperator/nullishCoalescingOperator_es2020.ts -es2panda/test/TypeScript/tests/cases/conformance/expressions/elementAccess/letIdentifierInElementAccess01.ts -es2panda/test/TypeScript/tests/cases/conformance/internalModules/DeclarationMerging/ClassAndModuleThatMergeWithStaticVariableAndNonExportedVarThatShareAName.ts -es2panda/test/TypeScript/tests/cases/conformance/interfaces/interfaceDeclarations/asiPreventsParsingAsInterface04.ts -es2panda/test/TypeScript/tests/cases/conformance/interfaces/interfaceDeclarations/asiPreventsParsingAsInterface01.ts -es2panda/test/TypeScript/tests/cases/conformance/interfaces/interfaceDeclarations/asiPreventsParsingAsInterface03.ts +es2panda/test/TypeScript/tests/cases/compiler/ambientClassOverloadForFunction.ts +es2panda/test/TypeScript/tests/cases/compiler/arrowFunctionWithObjectLiteralBody5.ts +es2panda/test/TypeScript/tests/cases/compiler/arrowFunctionWithObjectLiteralBody6.ts +es2panda/test/TypeScript/tests/cases/compiler/assertionFunctionsCanNarrowByDiscriminant.ts +es2panda/test/TypeScript/tests/cases/compiler/bom-utf16be.ts +es2panda/test/TypeScript/tests/cases/compiler/castOfAwait.ts +es2panda/test/TypeScript/tests/cases/compiler/castTest.ts +es2panda/test/TypeScript/tests/cases/compiler/classFunctionMerging.ts +es2panda/test/TypeScript/tests/cases/compiler/collisionArgumentsInType.ts +es2panda/test/TypeScript/tests/cases/compiler/collisionArgumentsInterfaceMembers.ts +es2panda/test/TypeScript/tests/cases/compiler/computedPropertiesTransformedInOtherwiseNonTSClasses.ts +es2panda/test/TypeScript/tests/cases/compiler/constructorOverloads5.ts +es2panda/test/TypeScript/tests/cases/compiler/continueTarget3.ts +es2panda/test/TypeScript/tests/cases/compiler/controlFlowCaching.ts +es2panda/test/TypeScript/tests/cases/compiler/controlFlowManyCallExpressionStatementsPerf.ts +es2panda/test/TypeScript/tests/cases/compiler/declarationEmitDestructuringOptionalBindingParametersInOverloads.ts +es2panda/test/TypeScript/tests/cases/compiler/declareIdentifierAsBeginningOfStatementExpression01.ts +es2panda/test/TypeScript/tests/cases/compiler/discriminantsAndPrimitives.ts +es2panda/test/TypeScript/tests/cases/compiler/elidedEmbeddedStatementsReplacedWithSemicolon.ts +es2panda/test/TypeScript/tests/cases/compiler/emitBundleWithShebang1.ts +es2panda/test/TypeScript/tests/cases/compiler/emitDecoratorMetadata_restArgs.ts +es2panda/test/TypeScript/tests/cases/compiler/exportAsNamespace.d.ts +es2panda/test/TypeScript/tests/cases/compiler/exportDeclarationsInAmbientNamespaces.ts +es2panda/test/TypeScript/tests/cases/compiler/exportEqualsOfModule.ts +es2panda/test/TypeScript/tests/cases/compiler/exportRedeclarationTypeAliases.ts +es2panda/test/TypeScript/tests/cases/compiler/exportSpecifierAndExportedMemberDeclaration.ts +es2panda/test/TypeScript/tests/cases/compiler/fileWithNextLine2.ts +es2panda/test/TypeScript/tests/cases/compiler/genericRecursiveImplicitConstructorErrors2.ts +es2panda/test/TypeScript/tests/cases/compiler/getterSetterNonAccessor.ts +es2panda/test/TypeScript/tests/cases/compiler/globalIsContextualKeyword.ts +es2panda/test/TypeScript/tests/cases/compiler/implementsInClassExpression.ts +es2panda/test/TypeScript/tests/cases/compiler/inferenceErasedSignatures.ts +es2panda/test/TypeScript/tests/cases/compiler/isLiteral1.ts +es2panda/test/TypeScript/tests/cases/compiler/isLiteral2.ts +es2panda/test/TypeScript/tests/cases/compiler/letAsIdentifier2.ts +es2panda/test/TypeScript/tests/cases/compiler/letInVarDeclOfForIn_ES5.ts +es2panda/test/TypeScript/tests/cases/compiler/letInVarDeclOfForIn_ES6.ts +es2panda/test/TypeScript/tests/cases/compiler/letInVarDeclOfForOf_ES5.ts +es2panda/test/TypeScript/tests/cases/compiler/letInVarDeclOfForOf_ES6.ts +es2panda/test/TypeScript/tests/cases/compiler/mutuallyRecursiveInterfaceDeclaration.ts +es2panda/test/TypeScript/tests/cases/compiler/objectLitGetterSetter.ts +es2panda/test/TypeScript/tests/cases/compiler/overloadResolutionOverNonCTObjectLit.ts +es2panda/test/TypeScript/tests/cases/compiler/overloadedConstructorFixesInferencesAppropriately.ts +es2panda/test/TypeScript/tests/cases/compiler/parameterInitializerBeforeDestructuringEmit.ts +es2panda/test/TypeScript/tests/cases/compiler/parseArrowFunctionWithFunctionReturnType.ts +es2panda/test/TypeScript/tests/cases/compiler/parseEntityNameWithReservedWord.ts +es2panda/test/TypeScript/tests/cases/compiler/shebang.ts +es2panda/test/TypeScript/tests/cases/compiler/sigantureIsSubTypeIfTheyAreIdentical.ts +es2panda/test/TypeScript/tests/cases/compiler/sourceMap-LineBreaks.ts +es2panda/test/TypeScript/tests/cases/compiler/sourceMapValidationDecorators.ts +es2panda/test/TypeScript/tests/cases/compiler/sourceMapValidationDestructuringForArrayBindingPattern2.ts +es2panda/test/TypeScript/tests/cases/compiler/sourceMapValidationDestructuringForArrayBindingPatternDefaultValues2.ts +es2panda/test/TypeScript/tests/cases/compiler/sourceMapValidationDestructuringForObjectBindingPattern2.ts +es2panda/test/TypeScript/tests/cases/compiler/sourceMapValidationDestructuringForObjectBindingPatternDefaultValues2.ts +es2panda/test/TypeScript/tests/cases/compiler/systemNamespaceAliasEmit.ts +es2panda/test/TypeScript/tests/cases/compiler/taggedTemplateStringWithSymbolExpression01.ts +es2panda/test/TypeScript/tests/cases/compiler/unusedLocalsAndParametersOverloadSignatures.ts +es2panda/test/TypeScript/tests/cases/compiler/withStatementInternalComments.ts +es2panda/test/TypeScript/tests/cases/conformance/async/es2017/asyncAwait_es2017.ts +es2panda/test/TypeScript/tests/cases/conformance/async/es5/asyncAwait_es5.ts +es2panda/test/TypeScript/tests/cases/conformance/async/es6/asyncAwait_es6.ts +es2panda/test/TypeScript/tests/cases/conformance/async/es6/asyncWithVarShadowing_es6.ts es2panda/test/TypeScript/tests/cases/conformance/classes/members/privateNames/privateNameComputedPropertyName1.ts -es2panda/test/TypeScript/tests/cases/conformance/internalModules/DeclarationMerging/ClassAndModuleThatMergeWithStaticFunctionAndNonExportedFunctionThatShareAName.ts -es2panda/test/TypeScript/tests/cases/conformance/internalModules/importDeclarations/importAliasIdentifiers.ts -es2panda/test/TypeScript/tests/cases/conformance/internalModules/importDeclarations/exportImportAlias.ts -es2panda/test/TypeScript/tests/cases/conformance/internalModules/moduleDeclarations/asiPreventsParsingAsNamespace04.ts -es2panda/test/TypeScript/tests/cases/conformance/internalModules/moduleDeclarations/nonInstantiatedModule.ts -es2panda/test/TypeScript/tests/cases/conformance/classes/classDeclarations/mergeClassInterfaceAndModule.ts +es2panda/test/TypeScript/tests/cases/conformance/es6/arrowFunction/emitArrowFunctionWhenUsingArguments03_ES6.ts +es2panda/test/TypeScript/tests/cases/conformance/es6/arrowFunction/emitArrowFunctionWhenUsingArguments04_ES6.ts +es2panda/test/TypeScript/tests/cases/conformance/es6/arrowFunction/emitArrowFunctionWhenUsingArguments05_ES6.ts +es2panda/test/TypeScript/tests/cases/conformance/es6/arrowFunction/emitArrowFunctionWhenUsingArguments06_ES6.ts +es2panda/test/TypeScript/tests/cases/conformance/es6/arrowFunction/emitArrowFunctionWhenUsingArguments07_ES6.ts +es2panda/test/TypeScript/tests/cases/conformance/es6/arrowFunction/emitArrowFunctionWhenUsingArguments08.ts +es2panda/test/TypeScript/tests/cases/conformance/es6/arrowFunction/emitArrowFunctionWhenUsingArguments08_ES6.ts +es2panda/test/TypeScript/tests/cases/conformance/es6/arrowFunction/emitArrowFunctionWhenUsingArguments11_ES6.ts +es2panda/test/TypeScript/tests/cases/conformance/es6/arrowFunction/emitArrowFunctionWhenUsingArguments13.ts +es2panda/test/TypeScript/tests/cases/conformance/es6/arrowFunction/emitArrowFunctionWhenUsingArguments13_ES6.ts +es2panda/test/TypeScript/tests/cases/conformance/es6/arrowFunction/emitArrowFunctionWhenUsingArguments14_ES6.ts +es2panda/test/TypeScript/tests/cases/conformance/es6/arrowFunction/emitArrowFunctionWhenUsingArguments15_ES6.ts +es2panda/test/TypeScript/tests/cases/conformance/es6/arrowFunction/emitArrowFunctionWhenUsingArguments16_ES6.ts +es2panda/test/TypeScript/tests/cases/conformance/es6/arrowFunction/emitArrowFunctionWhenUsingArguments17_ES6.ts es2panda/test/TypeScript/tests/cases/conformance/es6/destructuring/declarationInAmbientContext.ts +es2panda/test/TypeScript/tests/cases/conformance/es6/for-ofStatements/for-of53.ts +es2panda/test/TypeScript/tests/cases/conformance/es6/for-ofStatements/for-of56.ts +es2panda/test/TypeScript/tests/cases/conformance/es6/functionDeclarations/FunctionDeclaration11_es6.ts +es2panda/test/TypeScript/tests/cases/conformance/es6/functionDeclarations/FunctionDeclaration2_es6.ts +es2panda/test/TypeScript/tests/cases/conformance/es6/functionDeclarations/FunctionDeclaration4_es6.ts +es2panda/test/TypeScript/tests/cases/conformance/es6/modules/defaultExportWithOverloads01.ts es2panda/test/TypeScript/tests/cases/conformance/es6/templates/taggedTemplateStringsWithTagNamedDeclare.ts -es2panda/test/TypeScript/tests/cases/conformance/es6/templates/taggedTemplateStringsWithTypedTagsES6.ts +es2panda/test/TypeScript/tests/cases/conformance/es6/templates/taggedTemplateStringsWithTagNamedDeclareES6.ts es2panda/test/TypeScript/tests/cases/conformance/es6/templates/taggedTemplateStringsWithTypedTags.ts +es2panda/test/TypeScript/tests/cases/conformance/es6/templates/taggedTemplateStringsWithTypedTagsES6.ts es2panda/test/TypeScript/tests/cases/conformance/es6/templates/templateStringControlCharacterEscapes01.ts es2panda/test/TypeScript/tests/cases/conformance/es6/templates/templateStringControlCharacterEscapes01_ES6.ts -es2panda/test/TypeScript/tests/cases/conformance/es6/templates/taggedTemplateStringsWithTagNamedDeclareES6.ts -es2panda/test/TypeScript/tests/cases/conformance/es6/functionDeclarations/FunctionDeclaration2_es6.ts -es2panda/test/TypeScript/tests/cases/conformance/es6/functionDeclarations/FunctionDeclaration4_es6.ts -es2panda/test/TypeScript/tests/cases/conformance/es6/functionDeclarations/FunctionDeclaration11_es6.ts -es2panda/test/TypeScript/tests/cases/conformance/es6/for-ofStatements/for-of53.ts -es2panda/test/TypeScript/tests/cases/conformance/es6/for-ofStatements/for-of56.ts -es2panda/test/TypeScript/tests/cases/conformance/es6/unicodeExtendedEscapes/unicodeExtendedEscapesInRegularExpressions14_ES5.ts es2panda/test/TypeScript/tests/cases/conformance/es6/unicodeExtendedEscapes/unicodeExtendedEscapesInRegularExpressions07_ES5.ts +es2panda/test/TypeScript/tests/cases/conformance/es6/unicodeExtendedEscapes/unicodeExtendedEscapesInRegularExpressions07_ES6.ts es2panda/test/TypeScript/tests/cases/conformance/es6/unicodeExtendedEscapes/unicodeExtendedEscapesInRegularExpressions12_ES5.ts -es2panda/test/TypeScript/tests/cases/conformance/es6/unicodeExtendedEscapes/unicodeExtendedEscapesInRegularExpressions17_ES6.ts -es2panda/test/TypeScript/tests/cases/conformance/es6/unicodeExtendedEscapes/unicodeExtendedEscapesInRegularExpressions19_ES6.ts es2panda/test/TypeScript/tests/cases/conformance/es6/unicodeExtendedEscapes/unicodeExtendedEscapesInRegularExpressions12_ES6.ts +es2panda/test/TypeScript/tests/cases/conformance/es6/unicodeExtendedEscapes/unicodeExtendedEscapesInRegularExpressions14_ES5.ts es2panda/test/TypeScript/tests/cases/conformance/es6/unicodeExtendedEscapes/unicodeExtendedEscapesInRegularExpressions14_ES6.ts -es2panda/test/TypeScript/tests/cases/conformance/es6/unicodeExtendedEscapes/unicodeExtendedEscapesInRegularExpressions07_ES6.ts -es2panda/test/TypeScript/tests/cases/conformance/es6/unicodeExtendedEscapes/unicodeExtendedEscapesInRegularExpressions19_ES5.ts es2panda/test/TypeScript/tests/cases/conformance/es6/unicodeExtendedEscapes/unicodeExtendedEscapesInRegularExpressions17_ES5.ts +es2panda/test/TypeScript/tests/cases/conformance/es6/unicodeExtendedEscapes/unicodeExtendedEscapesInRegularExpressions17_ES6.ts +es2panda/test/TypeScript/tests/cases/conformance/es6/unicodeExtendedEscapes/unicodeExtendedEscapesInRegularExpressions19_ES5.ts +es2panda/test/TypeScript/tests/cases/conformance/es6/unicodeExtendedEscapes/unicodeExtendedEscapesInRegularExpressions19_ES6.ts es2panda/test/TypeScript/tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck38.ts -es2panda/test/TypeScript/tests/cases/conformance/es6/arrowFunction/emitArrowFunctionWhenUsingArguments14_ES6.ts -es2panda/test/TypeScript/tests/cases/conformance/es6/arrowFunction/emitArrowFunctionWhenUsingArguments08.ts -es2panda/test/TypeScript/tests/cases/conformance/es6/arrowFunction/emitArrowFunctionWhenUsingArguments17_ES6.ts -es2panda/test/TypeScript/tests/cases/conformance/es6/arrowFunction/emitArrowFunctionWhenUsingArguments08_ES6.ts -es2panda/test/TypeScript/tests/cases/conformance/es6/arrowFunction/emitArrowFunctionWhenUsingArguments04_ES6.ts -es2panda/test/TypeScript/tests/cases/conformance/scanner/ecmascript3/scannerES3NumericLiteral2.ts -es2panda/test/TypeScript/tests/cases/conformance/es6/modules/defaultExportWithOverloads01.ts -es2panda/test/TypeScript/tests/cases/conformance/es6/arrowFunction/emitArrowFunctionWhenUsingArguments13_ES6.ts -es2panda/test/TypeScript/tests/cases/conformance/es6/arrowFunction/emitArrowFunctionWhenUsingArguments03_ES6.ts -es2panda/test/TypeScript/tests/cases/conformance/es6/arrowFunction/emitArrowFunctionWhenUsingArguments16_ES6.ts -es2panda/test/TypeScript/tests/cases/conformance/es6/arrowFunction/emitArrowFunctionWhenUsingArguments05_ES6.ts -es2panda/test/TypeScript/tests/cases/conformance/es6/arrowFunction/emitArrowFunctionWhenUsingArguments13.ts -es2panda/test/TypeScript/tests/cases/conformance/es6/arrowFunction/emitArrowFunctionWhenUsingArguments11_ES6.ts -es2panda/test/TypeScript/tests/cases/conformance/es6/arrowFunction/emitArrowFunctionWhenUsingArguments06_ES6.ts -es2panda/test/TypeScript/tests/cases/conformance/es6/arrowFunction/emitArrowFunctionWhenUsingArguments07_ES6.ts -es2panda/test/TypeScript/tests/cases/conformance/es6/arrowFunction/emitArrowFunctionWhenUsingArguments15_ES6.ts -es2panda/test/TypeScript/tests/cases/conformance/async/es6/asyncAwait_es6.ts -es2panda/test/TypeScript/tests/cases/conformance/async/es6/asyncWithVarShadowing_es6.ts -es2panda/test/TypeScript/tests/cases/conformance/async/es5/asyncAwait_es5.ts -es2panda/test/TypeScript/tests/cases/conformance/async/es2017/asyncAwait_es2017.ts -es2panda/test/TypeScript/tests/cases/conformance/types/typeParameters/typeArgumentLists/constraintSatisfactionWithEmptyObject.ts -es2panda/test/TypeScript/tests/cases/conformance/types/tuple/named/namedTupleMembers.ts -es2panda/test/TypeScript/tests/cases/conformance/types/uniqueSymbol/uniqueSymbols.ts -es2panda/test/TypeScript/tests/cases/conformance/types/uniqueSymbol/uniqueSymbolsDeclarations.ts -es2panda/test/TypeScript/tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/nullIsSubtypeOfEverythingButUndefined.ts -es2panda/test/TypeScript/tests/cases/conformance/types/typeRelationships/assignmentCompatibility/anyAssignableToEveryType2.ts -es2panda/test/TypeScript/tests/cases/conformance/types/typeRelationships/bestCommonType/heterogeneousArrayLiterals.ts -es2panda/test/TypeScript/tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/undefinedIsSubtypeOfEverything.ts -es2panda/test/TypeScript/tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfAny.ts -es2panda/test/TypeScript/tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints2.ts -es2panda/test/TypeScript/tests/cases/conformance/types/typeRelationships/assignmentCompatibility/anyAssignabilityInInheritance.ts -es2panda/test/TypeScript/tests/cases/conformance/types/stringLiteral/stringLiteralTypesAndParenthesizedExpressions01.ts -es2panda/test/TypeScript/tests/cases/conformance/types/keyof/keyofAndIndexedAccess.ts -es2panda/test/TypeScript/tests/cases/conformance/types/import/importTypeAmbient.ts -es2panda/test/TypeScript/tests/cases/conformance/types/specifyingTypes/typeQueries/typeQueryWithReservedWords.ts -es2panda/test/TypeScript/tests/cases/conformance/types/members/objectTypeWithStringNamedNumericProperty.ts -es2panda/test/TypeScript/tests/cases/conformance/types/objectTypeLiteral/callSignatures/callSignatureWithoutReturnTypeAnnotationInference.ts -es2panda/test/TypeScript/tests/cases/conformance/types/literal/literalTypesAndDestructuring.ts -es2panda/test/TypeScript/tests/cases/conformance/parser/ecmascript5/parserUnicodeWhitespaceCharacter1.ts +es2panda/test/TypeScript/tests/cases/conformance/expressions/elementAccess/letIdentifierInElementAccess01.ts +es2panda/test/TypeScript/tests/cases/conformance/expressions/nullishCoalescingOperator/nullishCoalescingOperator_es2020.ts +es2panda/test/TypeScript/tests/cases/conformance/expressions/propertyAccess/propertyAccessNumericLiterals.ts +es2panda/test/TypeScript/tests/cases/conformance/expressions/typeGuards/typeGuardFunctionOfFormThis.ts +es2panda/test/TypeScript/tests/cases/conformance/expressions/typeGuards/typePredicateASI.ts +es2panda/test/TypeScript/tests/cases/conformance/functions/functionWithUseStrictAndSimpleParameterList.ts +es2panda/test/TypeScript/tests/cases/conformance/interfaces/interfaceDeclarations/asiPreventsParsingAsInterface01.ts +es2panda/test/TypeScript/tests/cases/conformance/interfaces/interfaceDeclarations/asiPreventsParsingAsInterface03.ts +es2panda/test/TypeScript/tests/cases/conformance/interfaces/interfaceDeclarations/asiPreventsParsingAsInterface04.ts +es2panda/test/TypeScript/tests/cases/conformance/internalModules/moduleDeclarations/asiPreventsParsingAsNamespace04.ts es2panda/test/TypeScript/tests/cases/conformance/parser/ecmascript5/ArrowFunctionExpressions/parserArrowFunctionExpression6.ts es2panda/test/TypeScript/tests/cases/conformance/parser/ecmascript5/RegressionTests/parser579071.ts es2panda/test/TypeScript/tests/cases/conformance/parser/ecmascript5/Statements/ContinueStatements/parser_continueTarget3.ts -es2panda/test/TypeScript/tests/cases/compiler/multiModuleClodule1.ts -es2panda/test/TypeScript/tests/cases/compiler/discriminantsAndPrimitives.ts -es2panda/test/TypeScript/tests/cases/compiler/circularTypeofWithFunctionModule.ts -es2panda/test/TypeScript/tests/cases/compiler/collisionArgumentsInType.ts -es2panda/test/TypeScript/tests/cases/compiler/sourceMapValidationDestructuringForArrayBindingPattern2.ts -es2panda/test/TypeScript/tests/cases/compiler/ambientClassOverloadForFunction.ts -es2panda/test/TypeScript/tests/cases/compiler/doubleUnderscoreEnumEmit.ts -es2panda/test/TypeScript/tests/cases/compiler/parseArrowFunctionWithFunctionReturnType.ts -es2panda/test/TypeScript/tests/cases/compiler/augmentedTypesModules3b.ts -es2panda/test/TypeScript/tests/cases/compiler/computedPropertiesTransformedInOtherwiseNonTSClasses.ts -es2panda/test/TypeScript/tests/cases/compiler/castTest.ts -es2panda/test/TypeScript/tests/cases/compiler/constructorOverloads5.ts -es2panda/test/TypeScript/tests/cases/compiler/parameterInitializerBeforeDestructuringEmit.ts -es2panda/test/TypeScript/tests/cases/compiler/classDeclarationMergedInModuleWithContinuation.ts -es2panda/test/TypeScript/tests/cases/compiler/exportEqualsOfModule.ts -es2panda/test/TypeScript/tests/cases/compiler/arrowFunctionWithObjectLiteralBody6.ts -es2panda/test/TypeScript/tests/cases/compiler/getterSetterNonAccessor.ts -es2panda/test/TypeScript/tests/cases/compiler/systemNamespaceAliasEmit.ts -es2panda/test/TypeScript/tests/cases/compiler/sourceMapValidationDestructuringForObjectBindingPattern2.ts -es2panda/test/TypeScript/tests/cases/compiler/resolveModuleNameWithSameLetDeclarationName1.ts -es2panda/test/TypeScript/tests/cases/compiler/partiallyAmbientFundule.ts -es2panda/test/TypeScript/tests/cases/compiler/internalImportInstantiatedModuleMergedWithClassNotReferencingInstanceNoConflict.ts -es2panda/test/TypeScript/tests/cases/compiler/collisionArgumentsInterfaceMembers.ts -es2panda/test/TypeScript/tests/cases/compiler/sourceMapValidationDestructuringForObjectBindingPatternDefaultValues2.ts -es2panda/test/TypeScript/tests/cases/compiler/es5ExportEqualsDts.ts -es2panda/test/TypeScript/tests/cases/compiler/parseEntityNameWithReservedWord.ts -es2panda/test/TypeScript/tests/cases/compiler/exportDeclarationsInAmbientNamespaces.ts -es2panda/test/TypeScript/tests/cases/compiler/castOfAwait.ts -es2panda/test/TypeScript/tests/cases/compiler/objectLitGetterSetter.ts -es2panda/test/TypeScript/tests/cases/compiler/continueTarget3.ts -es2panda/test/TypeScript/tests/cases/compiler/letInVarDeclOfForIn_ES6.ts -es2panda/test/TypeScript/tests/cases/compiler/functionMergedWithModule.ts -es2panda/test/TypeScript/tests/cases/compiler/internalImportUnInstantiatedModuleMergedWithClassNotReferencingInstanceNoConflict.ts -es2panda/test/TypeScript/tests/cases/compiler/controlFlowManyCallExpressionStatementsPerf.ts -es2panda/test/TypeScript/tests/cases/compiler/declareIdentifierAsBeginningOfStatementExpression01.ts -es2panda/test/TypeScript/tests/cases/compiler/declarationEmitLocalClassHasRequiredDeclare.ts -es2panda/test/TypeScript/tests/cases/compiler/isLiteral2.ts -es2panda/test/TypeScript/tests/cases/compiler/exportImportAndClodule.ts -es2panda/test/TypeScript/tests/cases/compiler/genericCloduleInModule.ts -es2panda/test/TypeScript/tests/cases/compiler/shebang.ts -es2panda/test/TypeScript/tests/cases/compiler/arrowFunctionWithObjectLiteralBody5.ts -es2panda/test/TypeScript/tests/cases/compiler/partiallyAmbientClodule.ts -es2panda/test/TypeScript/tests/cases/compiler/overloadResolutionOverNonCTObjectLit.ts -es2panda/test/TypeScript/tests/cases/compiler/controlFlowCaching.ts -es2panda/test/TypeScript/tests/cases/compiler/overloadedConstructorFixesInferencesAppropriately.ts -es2panda/test/TypeScript/tests/cases/compiler/multiModuleFundule1.ts -es2panda/test/TypeScript/tests/cases/compiler/systemModuleDeclarationMerging.ts -es2panda/test/TypeScript/tests/cases/compiler/bom-utf16be.ts -es2panda/test/TypeScript/tests/cases/compiler/isLiteral1.ts -es2panda/test/TypeScript/tests/cases/compiler/sourceMapValidationDecorators.ts -es2panda/test/TypeScript/tests/cases/compiler/cloduleGenericOnSelfMember.ts -es2panda/test/TypeScript/tests/cases/compiler/unusedLocalsAndParametersOverloadSignatures.ts -es2panda/test/TypeScript/tests/cases/compiler/noCircularDefinitionOnExportOfPrivateInMergedNamespace.ts -es2panda/test/TypeScript/tests/cases/compiler/inferenceErasedSignatures.ts -es2panda/test/TypeScript/tests/cases/compiler/exportSpecifierAndExportedMemberDeclaration.ts -es2panda/test/TypeScript/tests/cases/compiler/elidedEmbeddedStatementsReplacedWithSemicolon.ts -es2panda/test/TypeScript/tests/cases/compiler/letInVarDeclOfForOf_ES5.ts -es2panda/test/TypeScript/tests/cases/compiler/declarationEmitDestructuringOptionalBindingParametersInOverloads.ts -es2panda/test/TypeScript/tests/cases/compiler/moduleRedifinitionErrors.ts -es2panda/test/TypeScript/tests/cases/compiler/globalIsContextualKeyword.ts -es2panda/test/TypeScript/tests/cases/compiler/exportRedeclarationTypeAliases.ts -es2panda/test/TypeScript/tests/cases/compiler/letAsIdentifier2.ts -es2panda/test/TypeScript/tests/cases/compiler/fileWithNextLine2.ts -es2panda/test/TypeScript/tests/cases/compiler/mutuallyRecursiveInterfaceDeclaration.ts -es2panda/test/TypeScript/tests/cases/compiler/funduleOfFunctionWithoutReturnTypeAnnotation.ts -es2panda/test/TypeScript/tests/cases/compiler/implementsInClassExpression.ts -es2panda/test/TypeScript/tests/cases/compiler/funduleExportedClassIsUsedBeforeDeclaration.ts -es2panda/test/TypeScript/tests/cases/compiler/genericOfACloduleType2.ts -es2panda/test/TypeScript/tests/cases/compiler/genericOfACloduleType1.ts -es2panda/test/TypeScript/tests/cases/compiler/mixingFunctionAndAmbientModule1.ts -es2panda/test/TypeScript/tests/cases/compiler/cloduleWithPriorUninstantiatedModule.ts -es2panda/test/TypeScript/tests/cases/compiler/emitDecoratorMetadata_restArgs.ts -es2panda/test/TypeScript/tests/cases/compiler/sourceMapValidationDestructuringForArrayBindingPatternDefaultValues2.ts -es2panda/test/TypeScript/tests/cases/compiler/augmentedTypesClass3.ts -es2panda/test/TypeScript/tests/cases/compiler/cloduleTest1.ts -es2panda/test/TypeScript/tests/cases/compiler/taggedTemplateStringWithSymbolExpression01.ts -es2panda/test/TypeScript/tests/cases/compiler/cloduleAndTypeParameters.ts -es2panda/test/TypeScript/tests/cases/compiler/privacyCheckExportAssignmentOnExportedGenericInterface2.ts -es2panda/test/TypeScript/tests/cases/compiler/exportAsNamespace.d.ts -es2panda/test/TypeScript/tests/cases/compiler/letInVarDeclOfForOf_ES6.ts -es2panda/test/TypeScript/tests/cases/compiler/emitBundleWithShebang1.ts -es2panda/test/TypeScript/tests/cases/compiler/recursiveCloduleReference.ts -es2panda/test/TypeScript/tests/cases/compiler/letInVarDeclOfForIn_ES5.ts -es2panda/test/TypeScript/tests/cases/compiler/mergedDeclarations1.ts -es2panda/test/TypeScript/tests/cases/compiler/augmentedTypesExternalModule1.ts -es2panda/test/TypeScript/tests/cases/compiler/sigantureIsSubTypeIfTheyAreIdentical.ts -es2panda/test/TypeScript/tests/cases/compiler/assertionFunctionsCanNarrowByDiscriminant.ts -es2panda/test/TypeScript/tests/cases/compiler/withStatementInternalComments.ts -es2panda/test/TypeScript/tests/cases/compiler/genericRecursiveImplicitConstructorErrors2.ts -es2panda/test/TypeScript/tests/cases/compiler/cloduleWithRecursiveReference.ts -es2panda/test/TypeScript/tests/cases/compiler/sourceMap-LineBreaks.ts -es2panda/test/TypeScript/tests/cases/compiler/declareExternalModuleWithExportAssignedFundule.ts -es2panda/test/TypeScript/tests/cases/compiler/classFunctionMerging.ts -es2panda/test/TypeScript/tests/cases/compiler/es5ExportDefaultFunctionDeclaration4.ts -es2panda/test/TypeScript/tests/cases/compiler/typeAliasExport.ts -es2panda/test/TypeScript/tests/cases/compiler/es5ExportDefaultClassDeclaration4.ts -es2panda/test/TypeScript/tests/cases/compiler/exportDefaultVariable.ts -es2panda/test/TypeScript/tests/cases/compiler/declarationEmitModuleWithScopeMarker.ts \ No newline at end of file +es2panda/test/TypeScript/tests/cases/conformance/parser/ecmascript5/parserUnicodeWhitespaceCharacter1.ts +es2panda/test/TypeScript/tests/cases/conformance/scanner/ecmascript3/scannerES3NumericLiteral2.ts +es2panda/test/TypeScript/tests/cases/conformance/types/keyof/keyofAndIndexedAccess.ts +es2panda/test/TypeScript/tests/cases/conformance/types/literal/literalTypesAndDestructuring.ts +es2panda/test/TypeScript/tests/cases/conformance/types/members/objectTypeWithStringNamedNumericProperty.ts +es2panda/test/TypeScript/tests/cases/conformance/types/specifyingTypes/typeQueries/typeQueryWithReservedWords.ts +es2panda/test/TypeScript/tests/cases/conformance/types/stringLiteral/stringLiteralTypesAndParenthesizedExpressions01.ts +es2panda/test/TypeScript/tests/cases/conformance/types/tuple/named/namedTupleMembers.ts +es2panda/test/TypeScript/tests/cases/conformance/types/typeParameters/typeArgumentLists/constraintSatisfactionWithEmptyObject.ts +es2panda/test/TypeScript/tests/cases/conformance/types/uniqueSymbol/uniqueSymbols.ts +es2panda/test/TypeScript/tests/cases/conformance/types/uniqueSymbol/uniqueSymbolsDeclarations.ts \ No newline at end of file