aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorkzc <zaxxon2011@gmail.com>2015-11-01 01:02:52 -0400
committerkzc <zaxxon2011@gmail.com>2015-11-01 01:02:52 -0400
commit83db98ad3bc92797df7a1cde009893af9e3dbaf3 (patch)
treecfe3eb78a3397094bee5103a1856f57f84c849cc
parentbd0ae6569fd81f9f53d66b1c696e5394a0fa2bc2 (diff)
downloadtracifyjs-83db98ad3bc92797df7a1cde009893af9e3dbaf3.tar.gz
tracifyjs-83db98ad3bc92797df7a1cde009893af9e3dbaf3.zip
Fixed RegExp literal in mozilla AST generation/output and added a --dump-spidermonkey-ast flag
-rwxr-xr-xbin/uglifyjs40
-rw-r--r--lib/mozilla-ast.js15
2 files changed, 37 insertions, 18 deletions
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);
- });
+ if (ARGS.dump_spidermonkey_ast) {
+ print(JSON.stringify(TOPLEVEL.to_mozilla_ast(), null, 2));
+ } else {
+ time_it("generate", function(){
+ TOPLEVEL.print(output);
+ });
- output = output.get();
+ 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 (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 (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))) {