parent
4f8ca4626e
commit
21f4a6aea1
|
|
@ -95,8 +95,9 @@ The available options are:
|
||||||
`wrap_iife` Wrap IIFEs in parenthesis. Note: you may
|
`wrap_iife` Wrap IIFEs in parenthesis. Note: you may
|
||||||
want to disable `negate_iife` under
|
want to disable `negate_iife` under
|
||||||
compressor options.
|
compressor options.
|
||||||
-o, --output <file> Output file (default STDOUT). Specify "spidermonkey"
|
-o, --output <file> Output file path (default STDOUT). Specify `ast` or
|
||||||
to dump SpiderMonkey AST format (as JSON) to STDOUT.
|
`spidermonkey` to write UglifyJS or SpiderMonkey AST
|
||||||
|
as JSON to STDOUT respectively.
|
||||||
--comments [filter] Preserve copyright comments in the output. By
|
--comments [filter] Preserve copyright comments in the output. By
|
||||||
default this works like Google Closure, keeping
|
default this works like Google Closure, keeping
|
||||||
JSDoc-style comments that contain "@license" or
|
JSDoc-style comments that contain "@license" or
|
||||||
|
|
|
||||||
37
bin/uglifyjs
37
bin/uglifyjs
|
|
@ -107,6 +107,12 @@ if (program.nameCache) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (program.output == "ast") {
|
||||||
|
options.output = {
|
||||||
|
ast: true,
|
||||||
|
code: false
|
||||||
|
};
|
||||||
|
}
|
||||||
if (program.parse) {
|
if (program.parse) {
|
||||||
if (program.parse.acorn || program.parse.spidermonkey) {
|
if (program.parse.acorn || program.parse.spidermonkey) {
|
||||||
if (program.sourceMap) fatal("ERROR: inline source map only works with built-in parser");
|
if (program.sourceMap) fatal("ERROR: inline source map only works with built-in parser");
|
||||||
|
|
@ -211,7 +217,23 @@ function run() {
|
||||||
}
|
}
|
||||||
fatal("ERROR: " + ex.message);
|
fatal("ERROR: " + ex.message);
|
||||||
}
|
}
|
||||||
if (program.output == "spidermonkey") {
|
if (program.output == "ast") {
|
||||||
|
console.log(JSON.stringify(result.ast, function(key, value) {
|
||||||
|
if (skip_key(key)) return;
|
||||||
|
if (value instanceof UglifyJS.AST_Token) return;
|
||||||
|
if (value instanceof UglifyJS.Dictionary) return;
|
||||||
|
if (value instanceof UglifyJS.AST_Node) {
|
||||||
|
var result = {
|
||||||
|
_class: "AST_" + value.TYPE
|
||||||
|
};
|
||||||
|
value.CTOR.PROPS.forEach(function(prop) {
|
||||||
|
result[prop] = value[prop];
|
||||||
|
});
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
return value;
|
||||||
|
}, 2));
|
||||||
|
} else if (program.output == "spidermonkey") {
|
||||||
console.log(JSON.stringify(UglifyJS.minify(result.code, {
|
console.log(JSON.stringify(UglifyJS.minify(result.code, {
|
||||||
compress: false,
|
compress: false,
|
||||||
mangle: false,
|
mangle: false,
|
||||||
|
|
@ -352,3 +374,16 @@ function to_cache(key) {
|
||||||
}
|
}
|
||||||
return cache[key];
|
return cache[key];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function skip_key(key) {
|
||||||
|
switch (key) {
|
||||||
|
case "cname":
|
||||||
|
case "enclosed":
|
||||||
|
case "parent_scope":
|
||||||
|
case "scope":
|
||||||
|
case "thedef":
|
||||||
|
case "uses_eval":
|
||||||
|
case "uses_with":
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user