support JSON dump beyond AST_Toplevel (#4173)

This commit is contained in:
Alex Lam S.L 2020-10-03 15:53:06 +01:00 committed by GitHub
parent 142bd1bd1a
commit 04017215cc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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":