diff options
author | Alex Lam S.L <alexlamsl@gmail.com> | 2020-10-03 15:53:06 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-10-03 22:53:06 +0800 |
commit | 04017215cc0bd9a19492cd8792dac556a0912043 (patch) | |
tree | 2daf7b98adfb5bbd55dc220a932c3731f0c2c7d9 | |
parent | 142bd1bd1a77c0893e7b88268ef1a4d4f1be13d0 (diff) | |
download | tracifyjs-04017215cc0bd9a19492cd8792dac556a0912043.tar.gz tracifyjs-04017215cc0bd9a19492cd8792dac556a0912043.zip |
support JSON dump beyond `AST_Toplevel` (#4173)
-rwxr-xr-x | bin/uglifyjs | 13 |
1 files changed, 12 insertions, 1 deletions
diff --git a/bin/uglifyjs b/bin/uglifyjs index da2528d6..c6062657 100755 --- a/bin/uglifyjs +++ b/bin/uglifyjs @@ -342,7 +342,18 @@ function run() { } fatal(ex); } else if (output == "ast") { - if (!options.compress && !options.mangle) result.ast.figure_out_scope({}); + if (!options.compress && !options.mangle) { + var toplevel = result.ast; + if (!(toplevel instanceof UglifyJS.AST_Toplevel)) { + if (!(toplevel instanceof UglifyJS.AST_Statement)) toplevel = new UglifyJS.AST_SimpleStatement({ + body: toplevel, + }); + toplevel = new UglifyJS.AST_Toplevel({ + body: [ toplevel ], + }); + } + toplevel.figure_out_scope({}); + } print(JSON.stringify(result.ast, function(key, value) { if (value) switch (key) { case "thedef": |