From d9401149e7b786af74df705f06c848a8a660434a Mon Sep 17 00:00:00 2001 From: hufeng Date: Fri, 31 Dec 2021 15:12:15 +0800 Subject: [PATCH] fix generating the usable json file Signed-off-by: hufeng Change-Id: I71fc17b133e8e8f3e84b4883d40c2d04e84fd4c5 --- ts2panda/src/cmdOptions.ts | 2 +- ts2panda/src/ts2panda.ts | 18 ++++++++---------- 2 files changed, 9 insertions(+), 11 deletions(-) diff --git a/ts2panda/src/cmdOptions.ts b/ts2panda/src/cmdOptions.ts index 72bd24cc4f0..e4117916096 100644 --- a/ts2panda/src/cmdOptions.ts +++ b/ts2panda/src/cmdOptions.ts @@ -24,7 +24,7 @@ import { execute } from "./base/util"; const ts2pandaOptions = [ { name: 'variant-bytecode', alias: 'r', type: Boolean, defaultValue: true, description: "emit 2nd bytecode to pandafile." }, { name: 'modules', alias: 'm', type: Boolean, defaultValue: false, description: "compile as module." }, - { name: 'debug-log', alias: 'l', type: Boolean, defaultValue: false, description: "show info debug log." }, + { name: 'debug-log', alias: 'l', type: Boolean, defaultValue: false, description: "show info debug log and generate the json file."}, { name: 'dump-assembly', alias: 'a', type: Boolean, defaultValue: false, description: "dump assembly to file." }, { name: 'debug', alias: 'd', type: Boolean, defaultValue: false, description: "compile with debug info." }, { name: 'show-statistics', alias: 's', type: String, lazyMultiple: true, defaultValue: "", description: "show compile statistics(ast, histogram, hoisting, all)." }, diff --git a/ts2panda/src/ts2panda.ts b/ts2panda/src/ts2panda.ts index af9cf1e7820..6e0d6e7cd99 100644 --- a/ts2panda/src/ts2panda.ts +++ b/ts2panda/src/ts2panda.ts @@ -129,9 +129,6 @@ export class Ts2Panda { static dumpStringsArray(ts2abc: any) { let strings_arr = Array.from(Ts2Panda.strings); - if (CmdOptions.isEnableDebugLog()) { - Ts2Panda.jsonString += escapeUnicode(JSON.stringify(strings_arr, null, 2)); - } strings_arr.forEach(function(str) { let strObject = { @@ -139,8 +136,10 @@ export class Ts2Panda { "string": str } let jsonStrUnicode = escapeUnicode(JSON.stringify(strObject, null, 2)); - Ts2Panda.jsonString += jsonStrUnicode; jsonStrUnicode = "$" + jsonStrUnicode.replace(dollarSign, '#$') + "$"; + if (CmdOptions.isEnableDebugLog()) { + Ts2Panda.jsonString += jsonStrUnicode; + } ts2abc.stdio[3].write(jsonStrUnicode + '\n'); }); } @@ -167,10 +166,6 @@ export class Ts2Panda { } } - if (CmdOptions.isEnableDebugLog()) { - Ts2Panda.jsonString += escapeUnicode(JSON.stringify(literalArrays, null, 2)); - } - literalArrays.forEach(function(literalArray) { let literalArrayObject = { "type": JsonType.literal_arr, @@ -178,6 +173,9 @@ export class Ts2Panda { } let jsonLiteralArrUnicode = escapeUnicode(JSON.stringify(literalArrayObject, null, 2)); jsonLiteralArrUnicode = "$" + jsonLiteralArrUnicode.replace(dollarSign, '#$') + "$"; + if (CmdOptions.isEnableDebugLog()) { + Ts2Panda.jsonString += jsonLiteralArrUnicode; + } ts2abc.stdio[3].write(jsonLiteralArrUnicode + '\n'); }); } @@ -192,10 +190,10 @@ export class Ts2Panda { "opt_log_level": CmdOptions.getOptLogLevel() }; let jsonOpt = JSON.stringify(options, null, 2); + jsonOpt = "$" + jsonOpt.replace(dollarSign, '#$') + "$"; if (CmdOptions.isEnableDebugLog()) { Ts2Panda.jsonString += jsonOpt; } - jsonOpt = "$" + jsonOpt.replace(dollarSign, '#$') + "$"; ts2abc.stdio[3].write(jsonOpt + '\n'); } @@ -279,10 +277,10 @@ export class Ts2Panda { "func_body": func } let jsonFuncUnicode = escapeUnicode(JSON.stringify(funcObject, null, 2)); + jsonFuncUnicode = "$" + jsonFuncUnicode.replace(dollarSign, '#$') + "$"; if (CmdOptions.isEnableDebugLog()) { Ts2Panda.jsonString += jsonFuncUnicode; } - jsonFuncUnicode = "$" + jsonFuncUnicode.replace(dollarSign, '#$') + "$"; ts2abc.stdio[3].write(jsonFuncUnicode + '\n'); } -- Gitee