aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMihai Bazon <mihai@bazon.net>2013-05-15 13:27:23 +0300
committerMihai Bazon <mihai@bazon.net>2013-05-15 13:27:23 +0300
commitca3388cf5a27e48b8d41ba41114dd329de4708ee (patch)
treed3a8e4983f23f5be0cde736d930d475ef716b054
parentcaa8896a8a9d619334c21e49964e4a6c1a1a15eb (diff)
downloadtracifyjs-ca3388cf5a27e48b8d41ba41114dd329de4708ee.tar.gz
tracifyjs-ca3388cf5a27e48b8d41ba41114dd329de4708ee.zip
Add `--expr`, an option to parse a single expression (suitable for JSON)
-rwxr-xr-xbin/uglifyjs8
-rw-r--r--lib/parse.js11
2 files changed, 14 insertions, 5 deletions
diff --git a/bin/uglifyjs b/bin/uglifyjs
index fab9c665..b30b7599 100755
--- a/bin/uglifyjs
+++ b/bin/uglifyjs
@@ -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("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("expr", "Parse a single expression, rather than a program (for parsing JSON)")
.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.")
.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("comments")
.string("wrap")
+
+ .boolean("expr")
.boolean("screw-ie8")
.boolean("export-all")
.boolean("self")
@@ -242,8 +245,9 @@ async.eachLimit(files, 1, function (file, cb) {
}
else {
TOPLEVEL = UglifyJS.parse(code, {
- filename: file,
- toplevel: TOPLEVEL
+ filename : file,
+ toplevel : TOPLEVEL,
+ expression : ARGS.expr,
});
};
});
diff --git a/lib/parse.js b/lib/parse.js
index a687495b..e561ab67 100644
--- a/lib/parse.js
+++ b/lib/parse.js
@@ -588,9 +588,10 @@ var ATOMIC_START_TOKEN = array_to_hash([ "atom", "num", "string", "regexp", "nam
function parse($TEXT, options) {
options = defaults(options, {
- strict : false,
- filename : null,
- toplevel : null
+ strict : false,
+ filename : null,
+ toplevel : null,
+ expression : false
});
var S = {
@@ -1386,6 +1387,10 @@ function parse($TEXT, options) {
return ret;
};
+ if (options.expression) {
+ return expression(true);
+ }
+
return (function(){
var start = S.token;
var body = [];