Skip to content

Commit

Permalink
upgrade AST<->ESTree translation (#4870)
Browse files Browse the repository at this point in the history
fixes #968
  • Loading branch information
alexlamsl committed Apr 25, 2021
1 parent 80efaa2 commit 324587f
Show file tree
Hide file tree
Showing 8 changed files with 796 additions and 172 deletions.
15 changes: 5 additions & 10 deletions bin/uglifyjs
Expand Up @@ -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,
};
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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);
Expand Down
4 changes: 4 additions & 0 deletions lib/compress.js
Expand Up @@ -6562,6 +6562,10 @@ merge(Compressor.prototype, {
}
return insert_statements(body, node, in_list);
}
if (node instanceof AST_Import) {
if (node.properties && node.properties == 0) node.properties = null;
return node;
}
if (node instanceof AST_Sequence) {
if (node.expressions.length > 1) return;
return maintain_this_binding(compressor, tt.parent(), node, node.expressions[0]);
Expand Down

0 comments on commit 324587f

Please sign in to comment.