From a179dc7eaeb4195afe2cc5905648476319814836 Mon Sep 17 00:00:00 2001 From: hufeng Date: Thu, 8 Sep 2022 16:16:16 +0800 Subject: [PATCH] Adapt to merge sourceMaps Issue: https://gitee.com/openharmony/developtools_ace-ets2bundle/issues/I5QAA2?from=project-issue Signed-off-by: hufeng Change-Id: If78d39cfc898af9f5c337b6750c4df84c4c15806 --- es2panda/aot/options.cpp | 4 +++- es2panda/compiler/core/emitter/emitter.cpp | 6 +++--- es2panda/es2panda.cpp | 4 +++- es2panda/es2panda.h | 1 + 4 files changed, 10 insertions(+), 5 deletions(-) diff --git a/es2panda/aot/options.cpp b/es2panda/aot/options.cpp index 7d56cfb73c..d3acf5dcf4 100644 --- a/es2panda/aot/options.cpp +++ b/es2panda/aot/options.cpp @@ -71,7 +71,7 @@ bool Options::CollectInputFilesFromFileList(const std::string &input) return false; } - constexpr size_t ITEM_COUNT = 3; + constexpr size_t ITEM_COUNT = 4; while (std::getline(ifs, line)) { const std::string seperator = ";"; std::vector itemList = GetStringItems(line, seperator); @@ -79,6 +79,7 @@ bool Options::CollectInputFilesFromFileList(const std::string &input) std::cerr << "Failed to parse input file" << std::endl; return false; } + // itemList: [filePath, recordName, moduleKind, sourceFile] std::string fileName = itemList[0]; std::string recordName = FormatRecordName(itemList[1]); parser::ScriptKind scriptKind; @@ -91,6 +92,7 @@ bool Options::CollectInputFilesFromFileList(const std::string &input) } es2panda::SourceFile src(fileName, recordName, scriptKind); + src.sourcefile = itemList[3]; sourceFiles_.push_back(src); } return true; diff --git a/es2panda/compiler/core/emitter/emitter.cpp b/es2panda/compiler/core/emitter/emitter.cpp index 53064fdc1d..7006d4478e 100644 --- a/es2panda/compiler/core/emitter/emitter.cpp +++ b/es2panda/compiler/core/emitter/emitter.cpp @@ -274,10 +274,10 @@ void FunctionEmitter::GenLiteralBuffers() void FunctionEmitter::GenSourceFileDebugInfo() { - if (pg_->SourceFile().size() > 0) { - func_->source_file = pg_->SourceFile(); - } else { + if (pg_->SourceFile().empty()) { func_->source_file = std::string {pg_->Binder()->Program()->SourceFile()}; + } else { + func_->source_file = pg_->SourceFile(); } if (!pg_->IsDebug()) { diff --git a/es2panda/es2panda.cpp b/es2panda/es2panda.cpp index fcb7f8208a..a87da3ed75 100644 --- a/es2panda/es2panda.cpp +++ b/es2panda/es2panda.cpp @@ -53,6 +53,7 @@ panda::pandasm::Program *Compiler::Compile(const SourceFile &input, const Compil std::string fname(input.fileName); std::string src(input.source); std::string rname(input.recordName); + std::string sourcefile(input.sourcefile); parser::ScriptKind kind(input.scriptKind); bool needDumpSymbolFile = !options.hotfixOptions.dumpSymbolTable.empty(); @@ -71,7 +72,8 @@ panda::pandasm::Program *Compiler::Compile(const SourceFile &input, const Compil std::cout << ast.Dump() << std::endl; } - std::string debugInfoSourceFile = options.debugInfoSourceFile.empty() ? fname : options.debugInfoSourceFile; + std::string debugInfoSourceFile = options.debugInfoSourceFile.empty() ? + sourcefile : options.debugInfoSourceFile; auto *prog = compiler_->Compile(&ast, options, debugInfoSourceFile); if (hotfixHelper) { diff --git a/es2panda/es2panda.h b/es2panda/es2panda.h index dc0e9480ee..72b7c4394a 100644 --- a/es2panda/es2panda.h +++ b/es2panda/es2panda.h @@ -54,6 +54,7 @@ struct SourceFile { std::string recordName {}; std::string_view source {}; parser::ScriptKind scriptKind {}; + std::string sourcefile {}; uint32_t hash {0}; }; -- Gitee