upgrade AST<->ESTree translation (#4870)

fixes #968
This commit is contained in:
Alex Lam S.L
2021-04-26 04:23:52 +08:00
committed by GitHub
parent 80efaa2f33
commit 324587f769
8 changed files with 801 additions and 177 deletions

View File

@@ -235,7 +235,7 @@ if (options.mangle && options.mangle.properties) {
});
}
}
if (output == "ast") options.output = {
if (output == "ast" || output == "spidermonkey") options.output = {
ast: true,
code: false,
};
@@ -313,9 +313,11 @@ function run() {
if (options.parse.acorn) {
files = convert_ast(function(toplevel, name) {
return require("acorn").parse(files[name], {
ecmaVersion: "latest",
locations: true,
program: toplevel,
sourceFile: name
sourceFile: name,
sourceType: "module",
});
});
} else if (options.parse.spidermonkey) {
@@ -409,14 +411,7 @@ function run() {
return value;
}, 2));
} else if (output == "spidermonkey") {
print(JSON.stringify(UglifyJS.minify(result.code, {
compress: false,
mangle: false,
output: {
ast: true,
code: false
},
}).ast.to_mozilla_ast(), null, 2));
print(JSON.stringify(result.ast.to_mozilla_ast(), null, 2));
} else if (output) {
fs.writeFileSync(output, result.code);
if (result.map) fs.writeFileSync(output + ".map", result.map);