From: Alex Lam S.L Date: Sat, 3 Oct 2020 14:53:06 +0000 (+0100) Subject: support JSON dump beyond `AST_Toplevel` (#4173) X-Git-Url: https://git.ndcode.org/public/gitweb.cgi?a=commitdiff_plain;h=04017215cc0bd9a19492cd8792dac556a0912043;p=UglifyJS.git support JSON dump beyond `AST_Toplevel` (#4173) --- 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":