diff --git a/bin/uglifyjs b/bin/uglifyjs index ca75f159..8d4fe4d9 100755 --- a/bin/uglifyjs +++ b/bin/uglifyjs @@ -73,6 +73,7 @@ You need to pass an argument to this option to specify the name that your module .describe("mangle-regex", "Only mangle property names matching the regex") .describe("name-cache", "File to hold mangled names mappings") .describe("pure-funcs", "List of functions that can be safely removed if their return value is not used") + .describe("dump-spidermonkey-ast", "Dump SpiderMonkey AST to stdout.") .alias("p", "prefix") .alias("o", "output") @@ -117,6 +118,7 @@ You need to pass an argument to this option to specify the name that your module .boolean("stats") .boolean("acorn") .boolean("spidermonkey") + .boolean("dump-spidermonkey-ast") .boolean("lint") .boolean("V") .boolean("version") @@ -444,26 +446,30 @@ async.eachLimit(files, 1, function (file, cb) { } } - time_it("generate", function(){ - TOPLEVEL.print(output); - }); - - output = output.get(); - - if (SOURCE_MAP) { - fs.writeFileSync(ARGS.source_map, SOURCE_MAP, "utf8"); - var source_map_url = ARGS.source_map_url || ( - P_RELATIVE - ? path.relative(path.dirname(OUTPUT_FILE), ARGS.source_map) - : ARGS.source_map - ); - output += "\n//# sourceMappingURL=" + source_map_url; - } - - if (OUTPUT_FILE) { - fs.writeFileSync(OUTPUT_FILE, output, "utf8"); + if (ARGS.dump_spidermonkey_ast) { + print(JSON.stringify(TOPLEVEL.to_mozilla_ast(), null, 2)); } else { - print(output); + time_it("generate", function(){ + TOPLEVEL.print(output); + }); + + output = output.get(); + + if (SOURCE_MAP) { + fs.writeFileSync(ARGS.source_map, SOURCE_MAP, "utf8"); + var source_map_url = ARGS.source_map_url || ( + P_RELATIVE + ? path.relative(path.dirname(OUTPUT_FILE), ARGS.source_map) + : ARGS.source_map + ); + output += "\n//# sourceMappingURL=" + source_map_url; + } + + if (OUTPUT_FILE) { + fs.writeFileSync(OUTPUT_FILE, output, "utf8"); + } else { + print(output); + } } if (ARGS.stats) { diff --git a/lib/mozilla-ast.js b/lib/mozilla-ast.js index ac53ca27..0a439a59 100644 --- a/lib/mozilla-ast.js +++ b/lib/mozilla-ast.js @@ -146,7 +146,7 @@ case "boolean": return new (val ? AST_True : AST_False)(args); default: - args.value = val; + args.value = M.regex && M.raw ? M.raw : val; return new AST_RegExp(args); } }, @@ -334,6 +334,19 @@ }; }); + def_to_moz(AST_RegExp, function To_Moz_Literal(M) { + var value = M.value; + return { + type: "Literal", + value: value, + raw: value.toString(), + regex: { + pattern: value.source, + flags: value.toString().match(/[gimuy]*$/)[0] + } + }; + }); + def_to_moz(AST_Constant, function To_Moz_Literal(M) { var value = M.value; if (typeof value === 'number' && (value < 0 || (value === 0 && 1 / value < 0))) {