aboutsummaryrefslogtreecommitdiff
path: root/bin/uglifyjs
diff options
context:
space:
mode:
authorAlex Lam S.L <alexlamsl@gmail.com>2017-05-08 02:11:45 +0800
committerGitHub <noreply@github.com>2017-05-08 02:11:45 +0800
commite54748365cba0509c82c089cdc2ef6a8bb1a724b (patch)
tree8c251cb9dae341483a5fa4eea8491bf25f0a72ec /bin/uglifyjs
parent2d99d06601013ab996d574d122b31df400055302 (diff)
downloadtracifyjs-e54748365cba0509c82c089cdc2ef6a8bb1a724b.tar.gz
tracifyjs-e54748365cba0509c82c089cdc2ef6a8bb1a724b.zip
support `minify()` output as AST (#1878)
- `options.output.ast` (default `false`) - `options.output.code` (default `true`)
Diffstat (limited to 'bin/uglifyjs')
-rwxr-xr-xbin/uglifyjs23
1 files changed, 19 insertions, 4 deletions
diff --git a/bin/uglifyjs b/bin/uglifyjs
index 57e33d9b..c4f9dc5d 100755
--- a/bin/uglifyjs
+++ b/bin/uglifyjs
@@ -212,7 +212,14 @@ function run() {
fatal("ERROR: " + ex.message);
}
if (program.output == "spidermonkey") {
- console.log(JSON.stringify(UglifyJS.parse(result.code).to_mozilla_ast(), null, 2));
+ console.log(JSON.stringify(UglifyJS.minify(result.code, {
+ compress: false,
+ mangle: false,
+ output: {
+ ast: true,
+ code: false
+ }
+ }).ast.to_mozilla_ast(), null, 2));
} else if (program.output) {
fs.writeFileSync(program.output, result.code);
if (result.map) {
@@ -278,9 +285,17 @@ function parse_js(flag, constants) {
return function(value, options) {
options = options || {};
try {
- UglifyJS.parse(value, {
- expression: true
- }).walk(new UglifyJS.TreeWalker(function(node) {
+ UglifyJS.minify(value, {
+ parse: {
+ expression: true
+ },
+ compress: false,
+ mangle: false,
+ output: {
+ ast: true,
+ code: false
+ }
+ }).ast.walk(new UglifyJS.TreeWalker(function(node) {
if (node instanceof UglifyJS.AST_Assign) {
var name = node.left.print_to_string();
var value = node.right;