diff --git a/es2panda/aot/options.cpp b/es2panda/aot/options.cpp index 6fd8a714695d3bfe737383710568f9cbda404615..fbf1f16049e6374338c56ea9a59719fa315a00b9 100644 --- a/es2panda/aot/options.cpp +++ b/es2panda/aot/options.cpp @@ -334,6 +334,7 @@ bool Options::Parse(int argc, const char **argv) } if (opModule.GetValue()) { + opMergeAbc = opModule.GetValue(); scriptKind_ = es2panda::parser::ScriptKind::MODULE; } else if (opCommonjs.GetValue()) { scriptKind_ = es2panda::parser::ScriptKind::COMMONJS; diff --git a/es2panda/binder/variable.h b/es2panda/binder/variable.h index 34bbc94bd2d1f9997e9d78fd0dd00a11f0dc5cb6..c43173b11621c9a8c836cbb7ae0a67c349265a1f 100644 --- a/es2panda/binder/variable.h +++ b/es2panda/binder/variable.h @@ -115,6 +115,11 @@ public: return HasFlag(VariableFlags::LEXICAL_BOUND); } + bool IsHoistVar() const + { + return flags_ == VariableFlags::HOIST_VAR; + } + const util::StringView &Name() const; virtual void SetLexical(Scope *scope, util::PatchFix *patchFixHelper = nullptr) = 0; diff --git a/es2panda/compiler/core/emitter/emitter.cpp b/es2panda/compiler/core/emitter/emitter.cpp index b3e2062dfced56dca39dab0c5e83bc50121afc4c..81c50993c89d6a9c47c552369823758cf03c2cdc 100644 --- a/es2panda/compiler/core/emitter/emitter.cpp +++ b/es2panda/compiler/core/emitter/emitter.cpp @@ -250,7 +250,20 @@ void FunctionEmitter::GenFunctionSource() if (pg_->Context()->IsRecordSource() || (static_cast(pg_->RootNode()))->ShowSource()) { func_->source_code = SourceCode().Mutf8(); } - +} + +bool FunctionEmitter::NotHoistAndDecl(const IRNode *ins, const binder::Variable *variable) +{ + if (variable->IsHoistVar()) { + return false; + } else { + if (ins->Node() == nullptr || variable->Declaration() == nullptr || + variable->Declaration()->Node() == nullptr) { + return false; + } else { + return ins->Node() == variable->Declaration()->Node(); + } + } } void FunctionEmitter::GenScopeVariableInfo(const binder::Scope *scope) @@ -258,33 +271,34 @@ void FunctionEmitter::GenScopeVariableInfo(const binder::Scope *scope) const auto *startIns = scope->ScopeStart(); const auto *endIns = scope->ScopeEnd(); - uint32_t start = 0; - uint32_t count = 0; - - for (const auto *it : pg_->Insns()) { - if (startIns == it) { - start = count; - } else if (endIns == it) { - auto varsLength = static_cast(count - start + 1); - - for (const auto &[name, variable] : scope->Bindings()) { - if (!variable->IsLocalVariable() || variable->LexicalBound()) { - continue; - } - - auto &variableDebug = func_->local_variable_debug.emplace_back(); - variableDebug.name = name.Mutf8(); - variableDebug.signature = "any"; - variableDebug.signature_type = "any"; - variableDebug.reg = static_cast(variable->AsLocalVariable()->Vreg()); + for (const auto &[name, variable] : scope->Bindings()) { + if (!variable->IsLocalVariable() || variable->LexicalBound()) { + continue; + } + + auto &variableDebug = func_->local_variable_debug.emplace_back(); + variableDebug.name = name.Mutf8(); + variableDebug.signature = "any"; + variableDebug.signature_type = "any"; + variableDebug.reg = static_cast(variable->AsLocalVariable()->Vreg()); + + uint32_t start = 0; + uint32_t count = 0; + for (const auto *it : pg_->Insns()) { + if (startIns == it) { + start = count; + } + if (NotHoistAndDecl(it,variable)) { + start = count; + } + if (endIns == it) { + auto varsLength = static_cast(count - start + 1); variableDebug.start = start; variableDebug.length = static_cast(varsLength); + break; } - - break; + count++; } - - count++; } } diff --git a/es2panda/compiler/core/emitter/emitter.h b/es2panda/compiler/core/emitter/emitter.h index 411f34656fbf4e219fc4ba4c962f38a4d20de151..cc593ce33ca3cc91b0a028b46128cb5e81c2ce59 100644 --- a/es2panda/compiler/core/emitter/emitter.h +++ b/es2panda/compiler/core/emitter/emitter.h @@ -92,6 +92,7 @@ private: void GenLiteralBuffers(); void GenBufferLiterals(const LiteralBuffer *buff); void GenFunctionSource(); + bool NotHoistAndDecl(const IRNode *ins, const binder::Variable *variable); const PandaGen *pg_; panda::pandasm::Function *func_ {};