diff --git a/es2panda/aot/main.cpp b/es2panda/aot/main.cpp index ecb6860511592287dc95f7c440c779c4b0558519..1b0587e9a0be6b4bb5b6e0d669c7bbf1c9b4b93c 100644 --- a/es2panda/aot/main.cpp +++ b/es2panda/aot/main.cpp @@ -176,6 +176,7 @@ int Run(int argc, const char **argv) std::cerr << options->ErrorMsg() << std::endl; return 1; } + CompilerOptions::staticShowSource = options->RecordSource(); if (options->CompilerOptions().bcVersion || options->CompilerOptions().bcMinVersion) { std::string version = options->CompilerOptions().bcVersion ? diff --git a/es2panda/aot/options.cpp b/es2panda/aot/options.cpp index 95085c90674b020d4236b8a1e6ed23ff22511fc8..89cc07bb4d41c300b2f340929eb77788d0d01c39 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; } + recordSource_ = opRecordSource.GetValue(); compilerOptions_.dumpAsm = opDumpAssembly.GetValue(); compilerOptions_.dumpAst = opDumpAst.GetValue(); compilerOptions_.dumpTransformedAst = opDumpTransformedAst.GetValue(); diff --git a/es2panda/aot/options.h b/es2panda/aot/options.h index 00a2b7cf99dababad808859fec6b9f7ede398e16..1e4da262e5aebbf4c233296e588fceb61ea97b12 100644 --- a/es2panda/aot/options.h +++ b/es2panda/aot/options.h @@ -131,6 +131,11 @@ public: bool CollectInputFilesFromFileDirectory(const std::string &input, const std::string &extension); void ParseCacheFileOption(const std::string &cacheInput); + bool RecordSource() const + { + return recordSource_; + } + private: es2panda::CompilerOptions compilerOptions_ {}; es2panda::parser::ScriptKind scriptKind_ {es2panda::parser::ScriptKind::SCRIPT}; @@ -143,6 +148,7 @@ private: std::string recordName_; std::string errorMsg_; std::string compilerProtoOutput_; + bool recordSource_; int optLevel_ {0}; int functionThreadCount_ {0}; int fileThreadCount_ {0}; diff --git a/es2panda/compiler/core/emitter/emitter.cpp b/es2panda/compiler/core/emitter/emitter.cpp index 6a4a4b98cfc1270cc079220a378c9bc93253fce8..af661db77476b7bce9015dd48bc92e87d940740b 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 (panda::es2panda::CompilerOptions::staticShowSource || (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.cpp b/es2panda/es2panda.cpp index 13bde8798416ab7b8bf121cdf0a798289df6e496..e90f136d3615194baac1b426d7c1473afd89e0d4 100644 --- a/es2panda/es2panda.cpp +++ b/es2panda/es2panda.cpp @@ -31,6 +31,7 @@ namespace panda::es2panda { // Compiler constexpr size_t DEFAULT_THREAD_COUNT = 2; +bool CompilerOptions::staticShowSource = false; Compiler::Compiler(ScriptExtension ext) : Compiler(ext, DEFAULT_THREAD_COUNT) {} diff --git a/es2panda/es2panda.h b/es2panda/es2panda.h index a1778653f5c8e369929059fe08b43f1989e707e6..0795c1dd6dfb4405791f949c825a7a896dfdfe12 100644 --- a/es2panda/es2panda.h +++ b/es2panda/es2panda.h @@ -94,6 +94,7 @@ struct CompilerOptions { bool bcVersion {false}; bool bcMinVersion {false}; std::unordered_map cacheFiles; + static bool staticShowSource; }; enum class ErrorType {