diff --git a/ts2panda/src/cmdOptions.ts b/ts2panda/src/cmdOptions.ts index da02f18c62adaa64c66f7ed03a39b82854d2e62c..bf19d72cd51dce6f019b031fb97c0b04d61618c4 100644 --- a/ts2panda/src/cmdOptions.ts +++ b/ts2panda/src/cmdOptions.ts @@ -50,6 +50,7 @@ const ts2pandaOptions = [ { name: 'function-sourcecode', type: Boolean, defaultValue: false, description: "Record functions' sourceCode to support the feature of [function].toString()" }, { name: 'expression-watch-toolchain', type: String, defaultValue: "es2panda", description: "Specify the tool chain used to transform the expression" }, { name: 'source-file', type: String, defaultValue: "", description: "specify the file path info recorded in generated abc" }, + { name: 'generate-tmp-file', type: Boolean, defaultValue: false, description: "whether to generate intermediate temporary files"}, ] @@ -307,6 +308,13 @@ export class CmdOptions { return this.options["source-file"]; } + static needGenerateTmpFile(): boolean { + if (!this.options) { + return false; + } + return this.options["generate-tmp-file"]; + } + // @ts-ignore static parseUserCmd(args: string[]): ts.ParsedCommandLine | undefined { this.options = commandLineArgs(ts2pandaOptions, { partial: true }); diff --git a/ts2panda/src/index.ts b/ts2panda/src/index.ts index c7f898b58231185349dfb3efaac29dd90d735cc1..e243c78b0d2e4615206e0435985e8a5be7ff6307 100644 --- a/ts2panda/src/index.ts +++ b/ts2panda/src/index.ts @@ -52,7 +52,11 @@ function generateDTs(node: ts.SourceFile, options: ts.CompilerOptions) { } function main(fileNames: string[], options: ts.CompilerOptions) { - let program = ts.createProgram(fileNames, options); + const host = ts.createCompilerHost(options); + if (!CmdOptions.needGenerateTmpFile()) { + host.writeFile = () => {}; + } + let program = ts.createProgram(fileNames, options, host); let typeChecker = TypeChecker.getInstance(); typeChecker.setTypeChecker(program.getTypeChecker());