diff --git a/es2panda/binder/binder.cpp b/es2panda/binder/binder.cpp index 63f359f987bc7885c95bc2abe78ef452a0073608..aec814482d0e7e6ebb68f86d88d3a45edef57efe 100644 --- a/es2panda/binder/binder.cpp +++ b/es2panda/binder/binder.cpp @@ -461,7 +461,7 @@ void Binder::ResolveReference(const ir::AstNode *parent, ir::AstNode *childNode) ResolveReference(scriptFunc, scriptFunc->ReturnTypeAnnotation()); } - if (scriptFunc->IsOverload()) { + if (scriptFunc->IsOverload() || scriptFunc->Declare()) { break; } } diff --git a/es2panda/compiler/core/pandagen.cpp b/es2panda/compiler/core/pandagen.cpp index 6103be37a8e58ec4a8e4304eaae661fb494bec29..ac9b02f19b9f5ca39fae4de0e0e903139aac2fae 100644 --- a/es2panda/compiler/core/pandagen.cpp +++ b/es2panda/compiler/core/pandagen.cpp @@ -1091,6 +1091,10 @@ void PandaGen::LoadHomeObject(const ir::AstNode *node) void PandaGen::DefineFunction(const ir::AstNode *node, const ir::ScriptFunction *realNode, const util::StringView &name) { + if (realNode->IsOverload() || realNode->Declare()) { + return; + } + auto formalParamCnt = realNode->FormalParamsLength(); if (realNode->IsMethod()) { ra_.Emit(node, name, static_cast(formalParamCnt), LexEnv()); diff --git a/es2panda/ir/base/classDefinition.cpp b/es2panda/ir/base/classDefinition.cpp index e947b8f01c70bf7d38b7fc90d7ef519cb2c5dd50..bda274c4ac7d7ef7e522149daeb9038222f44b18 100644 --- a/es2panda/ir/base/classDefinition.cpp +++ b/es2panda/ir/base/classDefinition.cpp @@ -281,6 +281,10 @@ void ClassDefinition::CompileMissingProperties(compiler::PandaGen *pg, const uti void ClassDefinition::Compile(compiler::PandaGen *pg) const { + if (declare_) { + return; + } + compiler::RegScope rs(pg); compiler::VReg classReg = pg->AllocReg(); compiler::VReg lexenv = pg->LexEnv(); diff --git a/es2panda/parser/parserImpl.cpp b/es2panda/parser/parserImpl.cpp index d6bfecb3bff298ac7bf8c16f9ba7f810ad0b806c..b1bab0217344448daac1456e09e0d85c95f4899f 100644 --- a/es2panda/parser/parserImpl.cpp +++ b/es2panda/parser/parserImpl.cpp @@ -2398,7 +2398,7 @@ static bool IsConstructor(ir::Statement *stmt) return def->Kind() == ir::MethodDefinitionKind::CONSTRUCTOR; } -ir::MethodDefinition *ParserImpl::CreateImplicitConstructor(bool hasSuperClass) +ir::MethodDefinition *ParserImpl::CreateImplicitConstructor(bool hasSuperClass, bool isDeclare) { ArenaVector params(Allocator()->Adapter()); ArenaVector statements(Allocator()->Adapter()); @@ -2423,7 +2423,7 @@ ir::MethodDefinition *ParserImpl::CreateImplicitConstructor(bool hasSuperClass) auto *body = AllocNode(scope, std::move(statements)); auto *func = AllocNode(scope, std::move(params), nullptr, body, nullptr, - ir::ScriptFunctionFlags::CONSTRUCTOR, false); + ir::ScriptFunctionFlags::CONSTRUCTOR, isDeclare); scope->BindNode(func); paramScope->BindNode(func); scope->BindParamScope(paramScope); @@ -2657,7 +2657,7 @@ ir::ClassDefinition *ParserImpl::ParseClassDefinition(bool isDeclaration, bool i lexer::SourcePosition classBodyEndLoc = lexer_->GetToken().End(); if (ctor == nullptr) { - ctor = CreateImplicitConstructor(hasSuperClass); + ctor = CreateImplicitConstructor(hasSuperClass, isDeclare); ctor->SetRange({startLoc, classBodyEndLoc}); } lexer_->NextToken(); diff --git a/es2panda/parser/parserImpl.h b/es2panda/parser/parserImpl.h index 0a70e8e116daf8c91de2a07f63af8088febd089b..7c8297a72608fd1ff1d72abbe09ddac2b52ca18c 100644 --- a/es2panda/parser/parserImpl.h +++ b/es2panda/parser/parserImpl.h @@ -286,7 +286,7 @@ private: ir::Statement *ParseClassElement(const ArenaVector &properties, ArenaVector *indexSignatures, bool hasSuperClass, bool isDeclare, bool isAbstractClass); - ir::MethodDefinition *CreateImplicitConstructor(bool hasSuperClass); + ir::MethodDefinition *CreateImplicitConstructor(bool hasSuperClass, bool isDeclare = false); ir::MethodDefinition *CheckClassMethodOverload(ir::Statement *property, ir::MethodDefinition **ctor, bool isDeclare, lexer::SourcePosition errorInfo, ir::MethodDefinition *lastOverload, bool implExists, bool isAbstract = false);