Add --expr, an option to parse a single expression (suitable for JSON)

This commit is contained in:
Mihai Bazon
2013-05-15 13:27:23 +03:00
parent caa8896a8a
commit ca3388cf5a
2 changed files with 14 additions and 5 deletions

View File

@@ -23,6 +23,7 @@ mangling you need to use `-c` and `-m`.\
.describe("source-map-url", "The path to the source map to be added in //@ sourceMappingURL. Defaults to the value passed with --source-map.") .describe("source-map-url", "The path to the source map to be added in //@ sourceMappingURL. Defaults to the value passed with --source-map.")
.describe("in-source-map", "Input source map, useful if you're compressing JS that was generated from some other original code.") .describe("in-source-map", "Input source map, useful if you're compressing JS that was generated from some other original code.")
.describe("screw-ie8", "Pass this flag if you don't care about full compliance with Internet Explorer 6-8 quirks (by default UglifyJS will try to be IE-proof).") .describe("screw-ie8", "Pass this flag if you don't care about full compliance with Internet Explorer 6-8 quirks (by default UglifyJS will try to be IE-proof).")
.describe("expr", "Parse a single expression, rather than a program (for parsing JSON)")
.describe("p", "Skip prefix for original filenames that appear in source maps. \ .describe("p", "Skip prefix for original filenames that appear in source maps. \
For example -p 3 will drop 3 directories from file names and ensure they are relative paths.") For example -p 3 will drop 3 directories from file names and ensure they are relative paths.")
.describe("o", "Output file (default STDOUT).") .describe("o", "Output file (default STDOUT).")
@@ -76,6 +77,8 @@ You need to pass an argument to this option to specify the name that your module
.string("e") .string("e")
.string("comments") .string("comments")
.string("wrap") .string("wrap")
.boolean("expr")
.boolean("screw-ie8") .boolean("screw-ie8")
.boolean("export-all") .boolean("export-all")
.boolean("self") .boolean("self")
@@ -242,8 +245,9 @@ async.eachLimit(files, 1, function (file, cb) {
} }
else { else {
TOPLEVEL = UglifyJS.parse(code, { TOPLEVEL = UglifyJS.parse(code, {
filename: file, filename : file,
toplevel: TOPLEVEL toplevel : TOPLEVEL,
expression : ARGS.expr,
}); });
}; };
}); });

View File

@@ -590,7 +590,8 @@ function parse($TEXT, options) {
options = defaults(options, { options = defaults(options, {
strict : false, strict : false,
filename : null, filename : null,
toplevel : null toplevel : null,
expression : false
}); });
var S = { var S = {
@@ -1386,6 +1387,10 @@ function parse($TEXT, options) {
return ret; return ret;
}; };
if (options.expression) {
return expression(true);
}
return (function(){ return (function(){
var start = S.token; var start = S.token;
var body = []; var body = [];