diff --git a/es2panda/aot/options.cpp b/es2panda/aot/options.cpp index 95085c90674b020d4236b8a1e6ed23ff22511fc8..2aca4f0b9e77d29d79932d978876732d1135bfd0 100644 --- a/es2panda/aot/options.cpp +++ b/es2panda/aot/options.cpp @@ -199,6 +199,7 @@ bool Options::Parse(int argc, const char **argv) panda::PandArg opDumpTransformedAst("dump-transformed-ast", false, "Dump the parsed AST after transform"); panda::PandArg opCheckTransformedAstStructure("check-transformed-ast-structure", false, "Check the AST structure after transform"); + panda::PandArg opRecordSource("record-source", false, "Show the source code"); // type extractor panda::PandArg opTypeExtractor("type-extractor", false, "Enable type extractor for typescript"); @@ -249,6 +250,7 @@ bool Options::Parse(int argc, const char **argv) argparser_->Add(&opDumpAst); argparser_->Add(&opDumpTransformedAst); argparser_->Add(&opCheckTransformedAstStructure); + argparser_->Add(&opRecordSource); argparser_->Add(&opParseOnly); argparser_->Add(&opEnableTypeCheck); argparser_->Add(&opTypeExtractor); @@ -433,6 +435,7 @@ bool Options::Parse(int argc, const char **argv) options_ |= OptionFlags::SIZE_STAT; } + compilerOptions_.recordSource = opRecordSource.GetValue(); compilerOptions_.dumpAsm = opDumpAssembly.GetValue(); compilerOptions_.dumpAst = opDumpAst.GetValue(); compilerOptions_.dumpTransformedAst = opDumpTransformedAst.GetValue(); diff --git a/es2panda/compiler/core/compilerContext.cpp b/es2panda/compiler/core/compilerContext.cpp index 78edb8abbd9f7cfcec64daeff7d1846375945dcc..0080f85f48c6d1d26b3d4746897b316663ced3ed 100644 --- a/es2panda/compiler/core/compilerContext.cpp +++ b/es2panda/compiler/core/compilerContext.cpp @@ -31,6 +31,17 @@ CompilerContext::CompilerContext(binder::Binder *binder, bool isDebug, bool isDe { } +CompilerContext::CompilerContext(binder::Binder *binder, bool isDebug, bool isDebuggerEvaluateExpressionMode, + bool isMergeAbc, bool isTypeExtractorEnabled, bool isJsonInputFile, bool isRecordCode, + std::string sourceFile, std::string pkgName, util::StringView recordName, + util::PatchFix *patchFixHelper) + : binder_(binder), isDebug_(isDebug), isDebuggerEvaluateExpressionMode_(isDebuggerEvaluateExpressionMode), + isMergeAbc_(isMergeAbc), isTypeExtractorEnabled_(isTypeExtractorEnabled), isJsonInputFile_(isJsonInputFile), + isRecordCode_(isRecordCode), sourceFile_(sourceFile), pkgName_(pkgName), recordName_(recordName), patchFixHelper_(patchFixHelper), + emitter_(std::make_unique(this)) +{ +} + void CompilerContext::SetTypeRecorder(extractor::TypeRecorder *recorder) { ASSERT(emitter_ != nullptr); diff --git a/es2panda/compiler/core/compilerContext.h b/es2panda/compiler/core/compilerContext.h index 0581f4c2d1b6b212cdc6688d4513b3d8784963e0..f243790df3b3903e4a04068a35275fe724cc7600 100644 --- a/es2panda/compiler/core/compilerContext.h +++ b/es2panda/compiler/core/compilerContext.h @@ -46,6 +46,10 @@ public: CompilerContext(binder::Binder *binder, bool isDebug, bool isDebuggerEvaluateExpressionMode, bool isMergeAbc, bool isTypeExtractorEnabled, bool isJsonInputFile, std::string sourceFile, std::string pkgName, util::StringView recordName, util::PatchFix *patchFixHelper); + CompilerContext(binder::Binder *binder, bool isDebug, bool isDebuggerEvaluateExpressionMode, + bool isMergeAbc, bool isTypeExtractorEnabled, bool isJsonInputFile, bool isRecordCode, std::string sourceFile, + std::string pkgName, util::StringView recordName, util::PatchFix *patchFixHelper); + NO_COPY_SEMANTIC(CompilerContext); NO_MOVE_SEMANTIC(CompilerContext); ~CompilerContext() = default; @@ -134,6 +138,11 @@ public: return isJsonInputFile_; } + bool IsRecordCode() const + { + return isRecordCode_; + } + private: binder::Binder *binder_; int32_t literalBufferIdx_ {0}; @@ -145,6 +154,7 @@ private: bool isTypeExtractorEnabled_; // true when input file is json file bool isJsonInputFile_; + bool isRecordCode_; extractor::TypeRecorder *recorder_ {}; extractor::TypeExtractor *extractor_ {}; std::string sourceFile_; diff --git a/es2panda/compiler/core/compilerImpl.cpp b/es2panda/compiler/core/compilerImpl.cpp index 1d2c8bffc56730af7b2df07c0ea5ab218ffcb00b..823187f1ed9aee4c5ddbdc14425c556bc7948a0c 100644 --- a/es2panda/compiler/core/compilerImpl.cpp +++ b/es2panda/compiler/core/compilerImpl.cpp @@ -41,8 +41,8 @@ panda::pandasm::Program *CompilerImpl::Compile(parser::Program *program, const e { bool isTypeExtractorEnabled = ((program->Extension() == ScriptExtension::TS) && options.typeExtractor); CompilerContext context(program->Binder(), options.isDebug, options.isDebuggerEvaluateExpressionMode, - options.mergeAbc, isTypeExtractorEnabled, false, debugInfoSourceFile, pkgName, - program->RecordName(), patchFixHelper_); + options.mergeAbc, isTypeExtractorEnabled, false, options.recordSource, debugInfoSourceFile, + pkgName, program->RecordName(), patchFixHelper_); ArenaAllocator localAllocator(SpaceType::SPACE_TYPE_COMPILER, nullptr, true); diff --git a/es2panda/compiler/core/emitter/emitter.cpp b/es2panda/compiler/core/emitter/emitter.cpp index 6a4a4b98cfc1270cc079220a378c9bc93253fce8..053ad306f26f3f78a397c862196f491df9a6c6df 100644 --- a/es2panda/compiler/core/emitter/emitter.cpp +++ b/es2panda/compiler/core/emitter/emitter.cpp @@ -247,11 +247,11 @@ void FunctionEmitter::GenFunctionSource() return; } - if (!(static_cast(pg_->RootNode()))->ShowSource()) { + if (pg_->Context()->IsRecordCode() || (static_cast(pg_->RootNode()))->ShowSource()) { + func_->source_code = SourceCode().Mutf8(); return; } - - func_->source_code = SourceCode().Mutf8(); + } void FunctionEmitter::GenScopeVariableInfo(const binder::Scope *scope) diff --git a/es2panda/es2panda.h b/es2panda/es2panda.h index a1778653f5c8e369929059fe08b43f1989e707e6..76552a3563245e2b6aa4e5c9e608654df11e5ed5 100644 --- a/es2panda/es2panda.h +++ b/es2panda/es2panda.h @@ -84,6 +84,7 @@ struct CompilerOptions { bool mergeAbc {false}; bool typeExtractor {false}; bool typeDtsBuiltin {false}; + bool recordSource {false}; int fileThreadCount {0}; int functionThreadCount {0}; int optLevel {0};