Fixed RegExp literal in mozilla AST generation/output and added a --dump-spidermonkey-ast flag

This commit is contained in:
kzc
2015-11-01 01:02:52 -04:00
parent bd0ae6569f
commit 83db98ad3b
2 changed files with 39 additions and 20 deletions

View File

@@ -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,6 +446,9 @@ async.eachLimit(files, 1, function (file, cb) {
}
}
if (ARGS.dump_spidermonkey_ast) {
print(JSON.stringify(TOPLEVEL.to_mozilla_ast(), null, 2));
} else {
time_it("generate", function(){
TOPLEVEL.print(output);
});
@@ -465,6 +470,7 @@ async.eachLimit(files, 1, function (file, cb) {
} else {
print(output);
}
}
if (ARGS.stats) {
print_error(UglifyJS.string_template("Timing information (compressed {count} files):", {

View File

@@ -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))) {