From 04017215cc0bd9a19492cd8792dac556a0912043 Mon Sep 17 00:00:00 2001 From: "Alex Lam S.L" Date: Sat, 3 Oct 2020 15:53:06 +0100 Subject: [PATCH] support JSON dump beyond `AST_Toplevel` (#4173) --- bin/uglifyjs | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) 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": -- 2.34.1