Compare commits
105 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e3342a3cf6 | ||
|
|
7bf59b5bcd | ||
|
|
025f3e9596 | ||
|
|
8258edd8a5 | ||
|
|
8669ca219b | ||
|
|
71652690b6 | ||
|
|
37693d2812 | ||
|
|
8fbe200012 | ||
|
|
1a34a13e33 | ||
|
|
ef772b0049 | ||
|
|
6fcabbde08 | ||
|
|
14f290f8ab | ||
|
|
e2e09d5754 | ||
|
|
448a8d3845 | ||
|
|
514936beb8 | ||
|
|
f5c09d0bbf | ||
|
|
014f655c5f | ||
|
|
bf30dc3038 | ||
|
|
ef2ef07cbd | ||
|
|
1a4440080d | ||
|
|
ac0086a745 | ||
|
|
2494daaf68 | ||
|
|
9b404f9de6 | ||
|
|
5344b7dab8 | ||
|
|
0007a53b9c | ||
|
|
1dd05f44eb | ||
|
|
bf7b122ab2 | ||
|
|
e29048b54a | ||
|
|
2eeb640eca | ||
|
|
ceb200fe81 | ||
|
|
f5f8239057 | ||
|
|
6f9d051784 | ||
|
|
931862e97f | ||
|
|
1d0127de21 | ||
|
|
2d8fc61677 | ||
|
|
1e31011874 | ||
|
|
75cdbf19aa | ||
|
|
4339bd5cfa | ||
|
|
1ab2fdaa10 | ||
|
|
eda540f6ec | ||
|
|
90a330da16 | ||
|
|
cad1f9cbd1 | ||
|
|
f6203bd5a8 | ||
|
|
03cf94ebe8 | ||
|
|
c3087dd179 | ||
|
|
2c305af478 | ||
|
|
72e6f64ca8 | ||
|
|
b9fac687ff | ||
|
|
2c88eb6fbe | ||
|
|
a67e3bfdd3 | ||
|
|
27142df4f5 | ||
|
|
5e4c7f4245 | ||
|
|
b521b4b926 | ||
|
|
aa9de76370 | ||
|
|
5a083a938d | ||
|
|
7a30d826b8 | ||
|
|
be55a09edf | ||
|
|
15a148ff6d | ||
|
|
428e19fed2 | ||
|
|
f65e55dff4 | ||
|
|
b634018618 | ||
|
|
fa3300f314 | ||
|
|
bd0886a2c0 | ||
|
|
248f304f02 | ||
|
|
dc5f70eab5 | ||
|
|
df8c5623af | ||
|
|
a790c09c91 | ||
|
|
8f35a363d9 | ||
|
|
d2190c2bf3 | ||
|
|
ea10642572 | ||
|
|
547561a568 | ||
|
|
c16d538ce7 | ||
|
|
73d082df2e | ||
|
|
50b8d7272c | ||
|
|
7d11b96f48 | ||
|
|
eab99a1c3d | ||
|
|
19e2fb134d | ||
|
|
f4919e3a25 | ||
|
|
bb700daa4c | ||
|
|
263577d5eb | ||
|
|
63287c0e68 | ||
|
|
c5ed2292bf | ||
|
|
b70670b69f | ||
|
|
9dd97605bc | ||
|
|
e4c5302406 | ||
|
|
bea3d90771 | ||
|
|
785c6064cc | ||
|
|
b214d3786f | ||
|
|
7cf79c302b | ||
|
|
a14c6b6574 | ||
|
|
f1b7094a57 | ||
|
|
0358e376f0 | ||
|
|
b47f7b76b9 | ||
|
|
582cc55cff | ||
|
|
8979579e55 | ||
|
|
0d6e08c541 | ||
|
|
e2daee9a65 | ||
|
|
9cd118ca3d | ||
|
|
cfd5c6155c | ||
|
|
1a5a4bd631 | ||
|
|
63e1a8e1fd | ||
|
|
7055af8221 | ||
|
|
aafe2e1db3 | ||
|
|
118105db43 | ||
|
|
dfa395f6ff |
@@ -1,7 +1,6 @@
|
|||||||
language: node_js
|
language: node_js
|
||||||
node_js:
|
node_js:
|
||||||
- "0.4"
|
- "0.4"
|
||||||
- "0.6"
|
|
||||||
- "0.8"
|
- "0.8"
|
||||||
- "0.10"
|
- "0.10"
|
||||||
- "0.11"
|
- "0.11"
|
||||||
|
|||||||
21
README.md
21
README.md
@@ -54,6 +54,10 @@ The available options are:
|
|||||||
--source-map-url The path to the source map to be added in //#
|
--source-map-url The path to the source map to be added in //#
|
||||||
sourceMappingURL. Defaults to the value passed with
|
sourceMappingURL. Defaults to the value passed with
|
||||||
--source-map. [string]
|
--source-map. [string]
|
||||||
|
--source-map-include-sources
|
||||||
|
Pass this flag if you want to include the content of
|
||||||
|
source files in the source map as sourcesContent
|
||||||
|
property. [boolean]
|
||||||
--in-source-map Input source map, useful if you're compressing JS that was
|
--in-source-map Input source map, useful if you're compressing JS that was
|
||||||
generated from some other original code.
|
generated from some other original code.
|
||||||
--screw-ie8 Pass this flag if you don't care about full compliance
|
--screw-ie8 Pass this flag if you don't care about full compliance
|
||||||
@@ -87,6 +91,10 @@ The available options are:
|
|||||||
Note that currently not *all* comments can be kept when
|
Note that currently not *all* comments can be kept when
|
||||||
compression is on, because of dead code removal or
|
compression is on, because of dead code removal or
|
||||||
cascading statements into sequences. [string]
|
cascading statements into sequences. [string]
|
||||||
|
--preamble Preamble to prepend to the output. You can use this to
|
||||||
|
insert a comment, for example for licensing information.
|
||||||
|
This will not be parsed, but the source map will adjust
|
||||||
|
for its presence.
|
||||||
--stats Display operations run time on STDERR. [boolean]
|
--stats Display operations run time on STDERR. [boolean]
|
||||||
--acorn Use Acorn for parsing. [boolean]
|
--acorn Use Acorn for parsing. [boolean]
|
||||||
--spidermonkey Assume input files are SpiderMonkey AST format (as JSON).
|
--spidermonkey Assume input files are SpiderMonkey AST format (as JSON).
|
||||||
@@ -165,7 +173,7 @@ To enable the mangler you need to pass `--mangle` (`-m`). The following
|
|||||||
- `toplevel` — mangle names declared in the toplevel scope (disabled by
|
- `toplevel` — mangle names declared in the toplevel scope (disabled by
|
||||||
default).
|
default).
|
||||||
|
|
||||||
- `eval` — mangle names visible in scopes where `eval` or `when` are used
|
- `eval` — mangle names visible in scopes where `eval` or `with` are used
|
||||||
(disabled by default).
|
(disabled by default).
|
||||||
|
|
||||||
When mangling is enabled but you want to prevent certain names from being
|
When mangling is enabled but you want to prevent certain names from being
|
||||||
@@ -245,6 +253,9 @@ to set `true`; it's effectively a shortcut for `foo=true`).
|
|||||||
statement would get discarded. The current implementation adds some
|
statement would get discarded. The current implementation adds some
|
||||||
overhead (compression will be slower).
|
overhead (compression will be slower).
|
||||||
|
|
||||||
|
- `drop_console` -- default `false`. Pass `true` to discard calls to
|
||||||
|
`console.*` functions.
|
||||||
|
|
||||||
### The `unsafe` option
|
### The `unsafe` option
|
||||||
|
|
||||||
It enables some transformations that *might* break code logic in certain
|
It enables some transformations that *might* break code logic in certain
|
||||||
@@ -257,7 +268,7 @@ when this flag is on:
|
|||||||
- `String(exp)` or `exp.toString()` → `"" + exp`
|
- `String(exp)` or `exp.toString()` → `"" + exp`
|
||||||
- `new Object/RegExp/Function/Error/Array (...)` → we discard the `new`
|
- `new Object/RegExp/Function/Error/Array (...)` → we discard the `new`
|
||||||
- `typeof foo == "undefined"` → `foo === void 0`
|
- `typeof foo == "undefined"` → `foo === void 0`
|
||||||
- `void 0` → `"undefined"` (if there is a variable named "undefined" in
|
- `void 0` → `undefined` (if there is a variable named "undefined" in
|
||||||
scope; we do it because the variable name will be mangled, typically
|
scope; we do it because the variable name will be mangled, typically
|
||||||
reduced to a single character).
|
reduced to a single character).
|
||||||
|
|
||||||
@@ -328,6 +339,10 @@ can pass additional arguments that control the code output:
|
|||||||
you pass `false` then whenever possible we will use a newline instead of a
|
you pass `false` then whenever possible we will use a newline instead of a
|
||||||
semicolon, leading to more readable output of uglified code (size before
|
semicolon, leading to more readable output of uglified code (size before
|
||||||
gzip could be smaller; size after gzip insignificantly larger).
|
gzip could be smaller; size after gzip insignificantly larger).
|
||||||
|
- `preamble` (default `null`) -- when passed it must be a string and
|
||||||
|
it will be prepended to the output literally. The source map will
|
||||||
|
adjust for this text. Can be used to insert a comment containing
|
||||||
|
licensing information, for example.
|
||||||
|
|
||||||
### Keeping copyright notices or other comments
|
### Keeping copyright notices or other comments
|
||||||
|
|
||||||
@@ -494,7 +509,7 @@ something like this:
|
|||||||
```javascript
|
```javascript
|
||||||
var toplevel = null;
|
var toplevel = null;
|
||||||
files.forEach(function(file){
|
files.forEach(function(file){
|
||||||
var code = fs.readFileSync(file);
|
var code = fs.readFileSync(file, "utf8");
|
||||||
toplevel = UglifyJS.parse(code, {
|
toplevel = UglifyJS.parse(code, {
|
||||||
filename: file,
|
filename: file,
|
||||||
toplevel: toplevel
|
toplevel: toplevel
|
||||||
|
|||||||
39
bin/uglifyjs
39
bin/uglifyjs
@@ -22,6 +22,7 @@ mangling you need to use `-c` and `-m`.\
|
|||||||
.describe("source-map", "Specify an output file where to generate source map.")
|
.describe("source-map", "Specify an output file where to generate source map.")
|
||||||
.describe("source-map-root", "The path to the original source to be included in the source map.")
|
.describe("source-map-root", "The path to the original source to be included in the 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("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-include-sources", "Pass this flag if you want to include the content of source files in the source map as sourcesContent property.")
|
||||||
.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("expr", "Parse a single expression, rather than a program (for parsing JSON)")
|
||||||
@@ -48,6 +49,10 @@ You can optionally pass one of the following arguments to this flag:\n\
|
|||||||
Note that currently not *all* comments can be kept when compression is on, \
|
Note that currently not *all* comments can be kept when compression is on, \
|
||||||
because of dead code removal or cascading statements into sequences.")
|
because of dead code removal or cascading statements into sequences.")
|
||||||
|
|
||||||
|
.describe("preamble", "Preamble to prepend to the output. You can use this to insert a \
|
||||||
|
comment, for example for licensing information. This will not be \
|
||||||
|
parsed, but the source map will adjust for its presence.")
|
||||||
|
|
||||||
.describe("stats", "Display operations run time on STDERR.")
|
.describe("stats", "Display operations run time on STDERR.")
|
||||||
.describe("acorn", "Use Acorn for parsing.")
|
.describe("acorn", "Use Acorn for parsing.")
|
||||||
.describe("spidermonkey", "Assume input files are SpiderMonkey AST format (as JSON).")
|
.describe("spidermonkey", "Assume input files are SpiderMonkey AST format (as JSON).")
|
||||||
@@ -58,6 +63,7 @@ You need to pass an argument to this option to specify the name that your module
|
|||||||
.describe("lint", "Display some scope warnings")
|
.describe("lint", "Display some scope warnings")
|
||||||
.describe("v", "Verbose")
|
.describe("v", "Verbose")
|
||||||
.describe("V", "Print version number and exit.")
|
.describe("V", "Print version number and exit.")
|
||||||
|
.describe("noerr", "Don't throw an error for unknown options in -c, -b or -m.")
|
||||||
|
|
||||||
.alias("p", "prefix")
|
.alias("p", "prefix")
|
||||||
.alias("o", "output")
|
.alias("o", "output")
|
||||||
@@ -83,6 +89,7 @@ You need to pass an argument to this option to specify the name that your module
|
|||||||
.string("p")
|
.string("p")
|
||||||
|
|
||||||
.boolean("expr")
|
.boolean("expr")
|
||||||
|
.boolean("source-map-include-sources")
|
||||||
.boolean("screw-ie8")
|
.boolean("screw-ie8")
|
||||||
.boolean("export-all")
|
.boolean("export-all")
|
||||||
.boolean("self")
|
.boolean("self")
|
||||||
@@ -92,6 +99,7 @@ You need to pass an argument to this option to specify the name that your module
|
|||||||
.boolean("spidermonkey")
|
.boolean("spidermonkey")
|
||||||
.boolean("lint")
|
.boolean("lint")
|
||||||
.boolean("V")
|
.boolean("V")
|
||||||
|
.boolean("noerr")
|
||||||
|
|
||||||
.wrap(80)
|
.wrap(80)
|
||||||
|
|
||||||
@@ -100,6 +108,12 @@ You need to pass an argument to this option to specify the name that your module
|
|||||||
|
|
||||||
normalize(ARGS);
|
normalize(ARGS);
|
||||||
|
|
||||||
|
if (ARGS.noerr) {
|
||||||
|
UglifyJS.DefaultsError.croak = function(msg, defs) {
|
||||||
|
sys.error("WARN: " + msg);
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
if (ARGS.version || ARGS.V) {
|
if (ARGS.version || ARGS.V) {
|
||||||
var json = require("../package.json");
|
var json = require("../package.json");
|
||||||
sys.puts(json.name + ' ' + json.version);
|
sys.puts(json.name + ' ' + json.version);
|
||||||
@@ -134,7 +148,8 @@ if (ARGS.r) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var OUTPUT_OPTIONS = {
|
var OUTPUT_OPTIONS = {
|
||||||
beautify: BEAUTIFY ? true : false
|
beautify: BEAUTIFY ? true : false,
|
||||||
|
preamble: ARGS.preamble || null,
|
||||||
};
|
};
|
||||||
|
|
||||||
if (ARGS.screw_ie8) {
|
if (ARGS.screw_ie8) {
|
||||||
@@ -205,6 +220,7 @@ var STATS = {};
|
|||||||
var OUTPUT_FILE = ARGS.o;
|
var OUTPUT_FILE = ARGS.o;
|
||||||
var TOPLEVEL = null;
|
var TOPLEVEL = null;
|
||||||
var P_RELATIVE = ARGS.p && ARGS.p == "relative";
|
var P_RELATIVE = ARGS.p && ARGS.p == "relative";
|
||||||
|
var SOURCES_CONTENT = {};
|
||||||
|
|
||||||
var SOURCE_MAP = ARGS.source_map ? UglifyJS.SourceMap({
|
var SOURCE_MAP = ARGS.source_map ? UglifyJS.SourceMap({
|
||||||
file: P_RELATIVE ? path.relative(path.dirname(ARGS.source_map), OUTPUT_FILE) : OUTPUT_FILE,
|
file: P_RELATIVE ? path.relative(path.dirname(ARGS.source_map), OUTPUT_FILE) : OUTPUT_FILE,
|
||||||
@@ -242,6 +258,7 @@ async.eachLimit(files, 1, function (file, cb) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
SOURCES_CONTENT[file] = code;
|
||||||
time_it("parse", function(){
|
time_it("parse", function(){
|
||||||
if (ARGS.spidermonkey) {
|
if (ARGS.spidermonkey) {
|
||||||
var program = JSON.parse(code);
|
var program = JSON.parse(code);
|
||||||
@@ -251,7 +268,6 @@ async.eachLimit(files, 1, function (file, cb) {
|
|||||||
else if (ARGS.acorn) {
|
else if (ARGS.acorn) {
|
||||||
TOPLEVEL = acorn.parse(code, {
|
TOPLEVEL = acorn.parse(code, {
|
||||||
locations : true,
|
locations : true,
|
||||||
trackComments : true,
|
|
||||||
sourceFile : file,
|
sourceFile : file,
|
||||||
program : TOPLEVEL
|
program : TOPLEVEL
|
||||||
});
|
});
|
||||||
@@ -325,6 +341,15 @@ async.eachLimit(files, 1, function (file, cb) {
|
|||||||
if (MANGLE) time_it("mangle", function(){
|
if (MANGLE) time_it("mangle", function(){
|
||||||
TOPLEVEL.mangle_names(MANGLE);
|
TOPLEVEL.mangle_names(MANGLE);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
if (ARGS.source_map_include_sources) {
|
||||||
|
for (var file in SOURCES_CONTENT) {
|
||||||
|
if (SOURCES_CONTENT.hasOwnProperty(file)) {
|
||||||
|
SOURCE_MAP.get().setSourceContent(file, SOURCES_CONTENT[file]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
time_it("generate", function(){
|
time_it("generate", function(){
|
||||||
TOPLEVEL.print(output);
|
TOPLEVEL.print(output);
|
||||||
});
|
});
|
||||||
@@ -345,7 +370,6 @@ async.eachLimit(files, 1, function (file, cb) {
|
|||||||
fs.writeFileSync(OUTPUT_FILE, output, "utf8");
|
fs.writeFileSync(OUTPUT_FILE, output, "utf8");
|
||||||
} else {
|
} else {
|
||||||
sys.print(output);
|
sys.print(output);
|
||||||
sys.error("\n");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ARGS.stats) {
|
if (ARGS.stats) {
|
||||||
@@ -377,7 +401,7 @@ function getOptions(x, constants) {
|
|||||||
if (x !== true) {
|
if (x !== true) {
|
||||||
var ast;
|
var ast;
|
||||||
try {
|
try {
|
||||||
ast = UglifyJS.parse(x);
|
ast = UglifyJS.parse(x, { expression: true });
|
||||||
} catch(ex) {
|
} catch(ex) {
|
||||||
if (ex instanceof UglifyJS.JS_Parse_Error) {
|
if (ex instanceof UglifyJS.JS_Parse_Error) {
|
||||||
sys.error("Error parsing arguments in: " + x);
|
sys.error("Error parsing arguments in: " + x);
|
||||||
@@ -385,8 +409,6 @@ function getOptions(x, constants) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
ast.walk(new UglifyJS.TreeWalker(function(node){
|
ast.walk(new UglifyJS.TreeWalker(function(node){
|
||||||
if (node instanceof UglifyJS.AST_Toplevel) return; // descend
|
|
||||||
if (node instanceof UglifyJS.AST_SimpleStatement) return; // descend
|
|
||||||
if (node instanceof UglifyJS.AST_Seq) return; // descend
|
if (node instanceof UglifyJS.AST_Seq) return; // descend
|
||||||
if (node instanceof UglifyJS.AST_Assign) {
|
if (node instanceof UglifyJS.AST_Assign) {
|
||||||
var name = node.left.print_to_string({ beautify: false }).replace(/-/g, "_");
|
var name = node.left.print_to_string({ beautify: false }).replace(/-/g, "_");
|
||||||
@@ -396,6 +418,11 @@ function getOptions(x, constants) {
|
|||||||
ret[name] = value;
|
ret[name] = value;
|
||||||
return true; // no descend
|
return true; // no descend
|
||||||
}
|
}
|
||||||
|
if (node instanceof UglifyJS.AST_Symbol || node instanceof UglifyJS.AST_Binary) {
|
||||||
|
var name = node.print_to_string({ beautify: false }).replace(/-/g, "_");
|
||||||
|
ret[name] = true;
|
||||||
|
return true; // no descend
|
||||||
|
}
|
||||||
sys.error(node.TYPE)
|
sys.error(node.TYPE)
|
||||||
sys.error("Error parsing arguments in: " + x);
|
sys.error("Error parsing arguments in: " + x);
|
||||||
process.exit(1);
|
process.exit(1);
|
||||||
|
|||||||
16
lib/ast.js
16
lib/ast.js
@@ -295,10 +295,10 @@ var AST_Toplevel = DEFNODE("Toplevel", "globals", {
|
|||||||
var parameters = [];
|
var parameters = [];
|
||||||
|
|
||||||
arg_parameter_pairs.forEach(function(pair) {
|
arg_parameter_pairs.forEach(function(pair) {
|
||||||
var split = pair.split(":");
|
var splitAt = pair.lastIndexOf(":");
|
||||||
|
|
||||||
args.push(split[0]);
|
args.push(pair.substr(0, splitAt));
|
||||||
parameters.push(split[1]);
|
parameters.push(pair.substr(splitAt + 1));
|
||||||
});
|
});
|
||||||
|
|
||||||
var wrapped_tl = "(function(" + parameters.join(",") + "){ '$ORIG'; })(" + args.join(",") + ")";
|
var wrapped_tl = "(function(" + parameters.join(",") + "){ '$ORIG'; })(" + args.join(",") + ")";
|
||||||
@@ -371,7 +371,7 @@ var AST_Lambda = DEFNODE("Lambda", "name argnames uses_arguments", {
|
|||||||
}, AST_Scope);
|
}, AST_Scope);
|
||||||
|
|
||||||
var AST_Accessor = DEFNODE("Accessor", null, {
|
var AST_Accessor = DEFNODE("Accessor", null, {
|
||||||
$documentation: "A setter/getter function"
|
$documentation: "A setter/getter function. The `name` property is always null."
|
||||||
}, AST_Lambda);
|
}, AST_Lambda);
|
||||||
|
|
||||||
var AST_Function = DEFNODE("Function", null, {
|
var AST_Function = DEFNODE("Function", null, {
|
||||||
@@ -498,12 +498,6 @@ var AST_Try = DEFNODE("Try", "bcatch bfinally", {
|
|||||||
}
|
}
|
||||||
}, AST_Block);
|
}, AST_Block);
|
||||||
|
|
||||||
// XXX: this is wrong according to ECMA-262 (12.4). the catch block
|
|
||||||
// should introduce another scope, as the argname should be visible
|
|
||||||
// only inside the catch block. However, doing it this way because of
|
|
||||||
// IE which simply introduces the name in the surrounding scope. If
|
|
||||||
// we ever want to fix this then AST_Catch should inherit from
|
|
||||||
// AST_Scope.
|
|
||||||
var AST_Catch = DEFNODE("Catch", "argname", {
|
var AST_Catch = DEFNODE("Catch", "argname", {
|
||||||
$documentation: "A `catch` node; only makes sense as part of a `try` statement",
|
$documentation: "A `catch` node; only makes sense as part of a `try` statement",
|
||||||
$propdoc: {
|
$propdoc: {
|
||||||
@@ -756,7 +750,7 @@ var AST_Object = DEFNODE("Object", "properties", {
|
|||||||
var AST_ObjectProperty = DEFNODE("ObjectProperty", "key value", {
|
var AST_ObjectProperty = DEFNODE("ObjectProperty", "key value", {
|
||||||
$documentation: "Base class for literal object properties",
|
$documentation: "Base class for literal object properties",
|
||||||
$propdoc: {
|
$propdoc: {
|
||||||
key: "[string] the property name; it's always a plain string in our AST, no matter if it was a string, number or identifier in original code",
|
key: "[string] the property name converted to a string for ObjectKeyVal. For setters and getters this is an arbitrary AST_Node.",
|
||||||
value: "[AST_Node] property value. For setters and getters this is an AST_Function."
|
value: "[AST_Node] property value. For setters and getters this is an AST_Function."
|
||||||
},
|
},
|
||||||
_walk: function(visitor) {
|
_walk: function(visitor) {
|
||||||
|
|||||||
196
lib/compress.js
196
lib/compress.js
@@ -61,6 +61,7 @@ function Compressor(options, false_by_default) {
|
|||||||
loops : !false_by_default,
|
loops : !false_by_default,
|
||||||
unused : !false_by_default,
|
unused : !false_by_default,
|
||||||
hoist_funs : !false_by_default,
|
hoist_funs : !false_by_default,
|
||||||
|
keep_fargs : false,
|
||||||
hoist_vars : false,
|
hoist_vars : false,
|
||||||
if_return : !false_by_default,
|
if_return : !false_by_default,
|
||||||
join_vars : !false_by_default,
|
join_vars : !false_by_default,
|
||||||
@@ -70,6 +71,8 @@ function Compressor(options, false_by_default) {
|
|||||||
pure_funcs : null,
|
pure_funcs : null,
|
||||||
negate_iife : !false_by_default,
|
negate_iife : !false_by_default,
|
||||||
screw_ie8 : false,
|
screw_ie8 : false,
|
||||||
|
drop_console : false,
|
||||||
|
angular : false,
|
||||||
|
|
||||||
warnings : true,
|
warnings : true,
|
||||||
global_defs : {}
|
global_defs : {}
|
||||||
@@ -85,14 +88,16 @@ merge(Compressor.prototype, {
|
|||||||
},
|
},
|
||||||
before: function(node, descend, in_list) {
|
before: function(node, descend, in_list) {
|
||||||
if (node._squeezed) return node;
|
if (node._squeezed) return node;
|
||||||
|
var was_scope = false;
|
||||||
if (node instanceof AST_Scope) {
|
if (node instanceof AST_Scope) {
|
||||||
node.drop_unused(this);
|
|
||||||
node = node.hoist_declarations(this);
|
node = node.hoist_declarations(this);
|
||||||
|
was_scope = true;
|
||||||
}
|
}
|
||||||
descend(node, this);
|
descend(node, this);
|
||||||
node = node.optimize(this);
|
node = node.optimize(this);
|
||||||
if (node instanceof AST_Scope) {
|
if (was_scope && node instanceof AST_Scope) {
|
||||||
node.drop_unused(this);
|
node.drop_unused(this);
|
||||||
|
descend(node, this);
|
||||||
}
|
}
|
||||||
node._squeezed = true;
|
node._squeezed = true;
|
||||||
return node;
|
return node;
|
||||||
@@ -195,6 +200,9 @@ merge(Compressor.prototype, {
|
|||||||
var CHANGED;
|
var CHANGED;
|
||||||
do {
|
do {
|
||||||
CHANGED = false;
|
CHANGED = false;
|
||||||
|
if (compressor.option("angular")) {
|
||||||
|
statements = process_for_angular(statements);
|
||||||
|
}
|
||||||
statements = eliminate_spurious_blocks(statements);
|
statements = eliminate_spurious_blocks(statements);
|
||||||
if (compressor.option("dead_code")) {
|
if (compressor.option("dead_code")) {
|
||||||
statements = eliminate_dead_code(statements, compressor);
|
statements = eliminate_dead_code(statements, compressor);
|
||||||
@@ -216,6 +224,50 @@ merge(Compressor.prototype, {
|
|||||||
|
|
||||||
return statements;
|
return statements;
|
||||||
|
|
||||||
|
function process_for_angular(statements) {
|
||||||
|
function make_injector(func, name) {
|
||||||
|
return make_node(AST_SimpleStatement, func, {
|
||||||
|
body: make_node(AST_Assign, func, {
|
||||||
|
operator: "=",
|
||||||
|
left: make_node(AST_Dot, name, {
|
||||||
|
expression: make_node(AST_SymbolRef, name, name),
|
||||||
|
property: "$inject"
|
||||||
|
}),
|
||||||
|
right: make_node(AST_Array, func, {
|
||||||
|
elements: func.argnames.map(function(sym){
|
||||||
|
return make_node(AST_String, sym, { value: sym.name });
|
||||||
|
})
|
||||||
|
})
|
||||||
|
})
|
||||||
|
});
|
||||||
|
}
|
||||||
|
return statements.reduce(function(a, stat){
|
||||||
|
a.push(stat);
|
||||||
|
var token = stat.start;
|
||||||
|
var comments = token.comments_before;
|
||||||
|
if (comments && comments.length > 0) {
|
||||||
|
var last = comments.pop();
|
||||||
|
if (/@ngInject/.test(last.value)) {
|
||||||
|
// case 1: defun
|
||||||
|
if (stat instanceof AST_Defun) {
|
||||||
|
a.push(make_injector(stat, stat.name));
|
||||||
|
}
|
||||||
|
else if (stat instanceof AST_Definitions) {
|
||||||
|
stat.definitions.forEach(function(def){
|
||||||
|
if (def.value && def.value instanceof AST_Lambda) {
|
||||||
|
a.push(make_injector(def.value, def.name));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
compressor.warn("Unknown statement marked with @ngInject [{file}:{line},{col}]", token);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return a;
|
||||||
|
}, []);
|
||||||
|
}
|
||||||
|
|
||||||
function eliminate_spurious_blocks(statements) {
|
function eliminate_spurious_blocks(statements) {
|
||||||
var seen_dirs = [];
|
var seen_dirs = [];
|
||||||
return statements.reduce(function(a, stat){
|
return statements.reduce(function(a, stat){
|
||||||
@@ -325,7 +377,7 @@ merge(Compressor.prototype, {
|
|||||||
stat = stat.clone();
|
stat = stat.clone();
|
||||||
stat.condition = stat.condition.negate(compressor);
|
stat.condition = stat.condition.negate(compressor);
|
||||||
stat.body = make_node(AST_BlockStatement, stat, {
|
stat.body = make_node(AST_BlockStatement, stat, {
|
||||||
body: ret
|
body: as_statement_array(stat.alternative).concat(ret)
|
||||||
});
|
});
|
||||||
stat.alternative = make_node(AST_BlockStatement, stat, {
|
stat.alternative = make_node(AST_BlockStatement, stat, {
|
||||||
body: body
|
body: body
|
||||||
@@ -993,6 +1045,7 @@ merge(Compressor.prototype, {
|
|||||||
var tt = new TreeTransformer(
|
var tt = new TreeTransformer(
|
||||||
function before(node, descend, in_list) {
|
function before(node, descend, in_list) {
|
||||||
if (node instanceof AST_Lambda && !(node instanceof AST_Accessor)) {
|
if (node instanceof AST_Lambda && !(node instanceof AST_Accessor)) {
|
||||||
|
if (!compressor.option("keep_fargs")) {
|
||||||
for (var a = node.argnames, i = a.length; --i >= 0;) {
|
for (var a = node.argnames, i = a.length; --i >= 0;) {
|
||||||
var sym = a[i];
|
var sym = a[i];
|
||||||
if (sym.unreferenced()) {
|
if (sym.unreferenced()) {
|
||||||
@@ -1007,6 +1060,7 @@ merge(Compressor.prototype, {
|
|||||||
else break;
|
else break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
if (node instanceof AST_Defun && node !== self) {
|
if (node instanceof AST_Defun && node !== self) {
|
||||||
if (!member(node.name.definition(), in_use)) {
|
if (!member(node.name.definition(), in_use)) {
|
||||||
compressor.warn("Dropping unused function {name} [{file}:{line},{col}]", {
|
compressor.warn("Dropping unused function {name} [{file}:{line},{col}]", {
|
||||||
@@ -1082,19 +1136,24 @@ merge(Compressor.prototype, {
|
|||||||
}
|
}
|
||||||
return node;
|
return node;
|
||||||
}
|
}
|
||||||
if (node instanceof AST_For && node.init instanceof AST_BlockStatement) {
|
if (node instanceof AST_For) {
|
||||||
descend(node, this);
|
descend(node, this);
|
||||||
|
|
||||||
|
if (node.init instanceof AST_BlockStatement) {
|
||||||
// certain combination of unused name + side effect leads to:
|
// certain combination of unused name + side effect leads to:
|
||||||
// https://github.com/mishoo/UglifyJS2/issues/44
|
// https://github.com/mishoo/UglifyJS2/issues/44
|
||||||
// that's an invalid AST.
|
// that's an invalid AST.
|
||||||
// We fix it at this stage by moving the `var` outside the `for`.
|
// We fix it at this stage by moving the `var` outside the `for`.
|
||||||
|
|
||||||
var body = node.init.body.slice(0, -1);
|
var body = node.init.body.slice(0, -1);
|
||||||
node.init = node.init.body.slice(-1)[0].body;
|
node.init = node.init.body.slice(-1)[0].body;
|
||||||
body.push(node);
|
body.push(node);
|
||||||
|
|
||||||
return in_list ? MAP.splice(body) : make_node(AST_BlockStatement, node, {
|
return in_list ? MAP.splice(body) : make_node(AST_BlockStatement, node, {
|
||||||
body: body
|
body: body
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
}
|
||||||
if (node instanceof AST_Scope && node !== self)
|
if (node instanceof AST_Scope && node !== self)
|
||||||
return node;
|
return node;
|
||||||
}
|
}
|
||||||
@@ -1614,7 +1673,7 @@ merge(Compressor.prototype, {
|
|||||||
if (self.args.length != 1) {
|
if (self.args.length != 1) {
|
||||||
return make_node(AST_Array, self, {
|
return make_node(AST_Array, self, {
|
||||||
elements: self.args
|
elements: self.args
|
||||||
});
|
}).transform(compressor);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case "Object":
|
case "Object":
|
||||||
@@ -1628,11 +1687,30 @@ merge(Compressor.prototype, {
|
|||||||
if (self.args.length == 0) return make_node(AST_String, self, {
|
if (self.args.length == 0) return make_node(AST_String, self, {
|
||||||
value: ""
|
value: ""
|
||||||
});
|
});
|
||||||
return make_node(AST_Binary, self, {
|
if (self.args.length <= 1) return make_node(AST_Binary, self, {
|
||||||
left: self.args[0],
|
left: self.args[0],
|
||||||
operator: "+",
|
operator: "+",
|
||||||
right: make_node(AST_String, self, { value: "" })
|
right: make_node(AST_String, self, { value: "" })
|
||||||
|
}).transform(compressor);
|
||||||
|
break;
|
||||||
|
case "Number":
|
||||||
|
if (self.args.length == 0) return make_node(AST_Number, self, {
|
||||||
|
value: 0
|
||||||
});
|
});
|
||||||
|
if (self.args.length == 1) return make_node(AST_UnaryPrefix, self, {
|
||||||
|
expression: self.args[0],
|
||||||
|
operator: "+"
|
||||||
|
}).transform(compressor);
|
||||||
|
case "Boolean":
|
||||||
|
if (self.args.length == 0) return make_node(AST_False, self);
|
||||||
|
if (self.args.length == 1) return make_node(AST_UnaryPrefix, self, {
|
||||||
|
expression: make_node(AST_UnaryPrefix, null, {
|
||||||
|
expression: self.args[0],
|
||||||
|
operator: "!"
|
||||||
|
}),
|
||||||
|
operator: "!"
|
||||||
|
}).transform(compressor);
|
||||||
|
break;
|
||||||
case "Function":
|
case "Function":
|
||||||
if (all(self.args, function(x){ return x instanceof AST_String })) {
|
if (all(self.args, function(x){ return x instanceof AST_String })) {
|
||||||
// quite a corner-case, but we can handle it:
|
// quite a corner-case, but we can handle it:
|
||||||
@@ -1643,10 +1721,10 @@ merge(Compressor.prototype, {
|
|||||||
return arg.value;
|
return arg.value;
|
||||||
}).join(",") + "){" + self.args[self.args.length - 1].value + "})()";
|
}).join(",") + "){" + self.args[self.args.length - 1].value + "})()";
|
||||||
var ast = parse(code);
|
var ast = parse(code);
|
||||||
ast.figure_out_scope();
|
ast.figure_out_scope({ screw_ie8: compressor.option("screw_ie8") });
|
||||||
var comp = new Compressor(compressor.options);
|
var comp = new Compressor(compressor.options);
|
||||||
ast = ast.transform(comp);
|
ast = ast.transform(comp);
|
||||||
ast.figure_out_scope();
|
ast.figure_out_scope({ screw_ie8: compressor.option("screw_ie8") });
|
||||||
ast.mangle_names();
|
ast.mangle_names();
|
||||||
var fun;
|
var fun;
|
||||||
try {
|
try {
|
||||||
@@ -1747,6 +1825,14 @@ merge(Compressor.prototype, {
|
|||||||
return make_node(AST_Undefined, self).transform(compressor);
|
return make_node(AST_Undefined, self).transform(compressor);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (compressor.option("drop_console")) {
|
||||||
|
if (self.expression instanceof AST_PropAccess &&
|
||||||
|
self.expression.expression instanceof AST_SymbolRef &&
|
||||||
|
self.expression.expression.name == "console" &&
|
||||||
|
self.expression.expression.undeclared()) {
|
||||||
|
return make_node(AST_Undefined, self).transform(compressor);
|
||||||
|
}
|
||||||
|
}
|
||||||
return self.evaluate(compressor)[0];
|
return self.evaluate(compressor)[0];
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -1785,16 +1871,34 @@ merge(Compressor.prototype, {
|
|||||||
}
|
}
|
||||||
if (compressor.option("cascade")) {
|
if (compressor.option("cascade")) {
|
||||||
if (self.car instanceof AST_Assign
|
if (self.car instanceof AST_Assign
|
||||||
&& !self.car.left.has_side_effects(compressor)
|
&& !self.car.left.has_side_effects(compressor)) {
|
||||||
&& self.car.left.equivalent_to(self.cdr)) {
|
if (self.car.left.equivalent_to(self.cdr)) {
|
||||||
return self.car;
|
return self.car;
|
||||||
}
|
}
|
||||||
|
if (self.cdr instanceof AST_Call
|
||||||
|
&& self.cdr.expression.equivalent_to(self.car.left)) {
|
||||||
|
self.cdr.expression = self.car;
|
||||||
|
return self.cdr;
|
||||||
|
}
|
||||||
|
}
|
||||||
if (!self.car.has_side_effects(compressor)
|
if (!self.car.has_side_effects(compressor)
|
||||||
&& !self.cdr.has_side_effects(compressor)
|
&& !self.cdr.has_side_effects(compressor)
|
||||||
&& self.car.equivalent_to(self.cdr)) {
|
&& self.car.equivalent_to(self.cdr)) {
|
||||||
return self.car;
|
return self.car;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (self.cdr instanceof AST_UnaryPrefix
|
||||||
|
&& self.cdr.operator == "void"
|
||||||
|
&& !self.cdr.expression.has_side_effects(compressor)) {
|
||||||
|
self.cdr.operator = self.car;
|
||||||
|
return self.cdr;
|
||||||
|
}
|
||||||
|
if (self.cdr instanceof AST_Undefined) {
|
||||||
|
return make_node(AST_UnaryPrefix, self, {
|
||||||
|
operator : "void",
|
||||||
|
expression : self.car
|
||||||
|
});
|
||||||
|
}
|
||||||
return self;
|
return self;
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -1840,6 +1944,14 @@ merge(Compressor.prototype, {
|
|||||||
return self.evaluate(compressor)[0];
|
return self.evaluate(compressor)[0];
|
||||||
});
|
});
|
||||||
|
|
||||||
|
function has_side_effects_or_prop_access(node, compressor) {
|
||||||
|
var save_pure_getters = compressor.option("pure_getters");
|
||||||
|
compressor.options.pure_getters = false;
|
||||||
|
var ret = node.has_side_effects(compressor);
|
||||||
|
compressor.options.pure_getters = save_pure_getters;
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
AST_Binary.DEFMETHOD("lift_sequences", function(compressor){
|
AST_Binary.DEFMETHOD("lift_sequences", function(compressor){
|
||||||
if (compressor.option("sequences")) {
|
if (compressor.option("sequences")) {
|
||||||
if (this.left instanceof AST_Seq) {
|
if (this.left instanceof AST_Seq) {
|
||||||
@@ -1851,8 +1963,8 @@ merge(Compressor.prototype, {
|
|||||||
return seq;
|
return seq;
|
||||||
}
|
}
|
||||||
if (this.right instanceof AST_Seq
|
if (this.right instanceof AST_Seq
|
||||||
&& !(this.operator == "||" || this.operator == "&&")
|
&& this instanceof AST_Assign
|
||||||
&& !this.left.has_side_effects(compressor)) {
|
&& !has_side_effects_or_prop_access(this.left, compressor)) {
|
||||||
var seq = this.right;
|
var seq = this.right;
|
||||||
var x = seq.to_array();
|
var x = seq.to_array();
|
||||||
this.right = x.pop();
|
this.right = x.pop();
|
||||||
@@ -1882,8 +1994,12 @@ merge(Compressor.prototype, {
|
|||||||
// if right is a constant, whatever side effects the
|
// if right is a constant, whatever side effects the
|
||||||
// left side might have could not influence the
|
// left side might have could not influence the
|
||||||
// result. hence, force switch.
|
// result. hence, force switch.
|
||||||
|
|
||||||
|
if (!(self.left instanceof AST_Binary
|
||||||
|
&& PRECEDENCE[self.left.operator] >= PRECEDENCE[self.operator])) {
|
||||||
reverse(null, true);
|
reverse(null, true);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
if (/^[!=]==?$/.test(self.operator)) {
|
if (/^[!=]==?$/.test(self.operator)) {
|
||||||
if (self.left instanceof AST_SymbolRef && self.right instanceof AST_Conditional) {
|
if (self.left instanceof AST_SymbolRef && self.right instanceof AST_Conditional) {
|
||||||
if (self.right.consequent instanceof AST_SymbolRef
|
if (self.right.consequent instanceof AST_SymbolRef
|
||||||
@@ -2032,7 +2148,8 @@ merge(Compressor.prototype, {
|
|||||||
&& self.left.right instanceof AST_Constant
|
&& self.left.right instanceof AST_Constant
|
||||||
&& self.right instanceof AST_Binary
|
&& self.right instanceof AST_Binary
|
||||||
&& self.right.operator == "+"
|
&& self.right.operator == "+"
|
||||||
&& self.right.left instanceof AST_Constant) {
|
&& self.right.left instanceof AST_Constant
|
||||||
|
&& self.right.is_string(compressor)) {
|
||||||
self = make_node(AST_Binary, self, {
|
self = make_node(AST_Binary, self, {
|
||||||
operator: "+",
|
operator: "+",
|
||||||
left: make_node(AST_Binary, self.left, {
|
left: make_node(AST_Binary, self.left, {
|
||||||
@@ -2049,6 +2166,19 @@ merge(Compressor.prototype, {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// x * (y * z) ==> x * y * z
|
||||||
|
if (self.right instanceof AST_Binary
|
||||||
|
&& self.right.operator == self.operator
|
||||||
|
&& (self.operator == "*" || self.operator == "&&" || self.operator == "||"))
|
||||||
|
{
|
||||||
|
self.left = make_node(AST_Binary, self.left, {
|
||||||
|
operator : self.operator,
|
||||||
|
left : self.left,
|
||||||
|
right : self.right.left
|
||||||
|
});
|
||||||
|
self.right = self.right.right;
|
||||||
|
return self.transform(compressor);
|
||||||
|
}
|
||||||
return self.evaluate(compressor)[0];
|
return self.evaluate(compressor)[0];
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -2140,7 +2270,7 @@ merge(Compressor.prototype, {
|
|||||||
* ==>
|
* ==>
|
||||||
* exp = foo ? something : something_else;
|
* exp = foo ? something : something_else;
|
||||||
*/
|
*/
|
||||||
self = make_node(AST_Assign, self, {
|
return make_node(AST_Assign, self, {
|
||||||
operator: consequent.operator,
|
operator: consequent.operator,
|
||||||
left: consequent.left,
|
left: consequent.left,
|
||||||
right: make_node(AST_Conditional, self, {
|
right: make_node(AST_Conditional, self, {
|
||||||
@@ -2150,6 +2280,38 @@ merge(Compressor.prototype, {
|
|||||||
})
|
})
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
if (consequent instanceof AST_Call
|
||||||
|
&& alternative.TYPE === consequent.TYPE
|
||||||
|
&& consequent.args.length == alternative.args.length
|
||||||
|
&& consequent.expression.equivalent_to(alternative.expression)) {
|
||||||
|
if (consequent.args.length == 0) {
|
||||||
|
return make_node(AST_Seq, self, {
|
||||||
|
car: self.condition,
|
||||||
|
cdr: consequent
|
||||||
|
});
|
||||||
|
}
|
||||||
|
if (consequent.args.length == 1) {
|
||||||
|
consequent.args[0] = make_node(AST_Conditional, self, {
|
||||||
|
condition: self.condition,
|
||||||
|
consequent: consequent.args[0],
|
||||||
|
alternative: alternative.args[0]
|
||||||
|
});
|
||||||
|
return consequent;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// x?y?z:a:a --> x&&y?z:a
|
||||||
|
if (consequent instanceof AST_Conditional
|
||||||
|
&& consequent.alternative.equivalent_to(alternative)) {
|
||||||
|
return make_node(AST_Conditional, self, {
|
||||||
|
condition: make_node(AST_Binary, self, {
|
||||||
|
left: self.condition,
|
||||||
|
operator: "&&",
|
||||||
|
right: consequent.condition
|
||||||
|
}),
|
||||||
|
consequent: consequent.consequent,
|
||||||
|
alternative: alternative
|
||||||
|
});
|
||||||
|
}
|
||||||
return self;
|
return self;
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -2189,6 +2351,12 @@ merge(Compressor.prototype, {
|
|||||||
property : prop
|
property : prop
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
var v = parseFloat(prop);
|
||||||
|
if (!isNaN(v) && v.toString() == prop) {
|
||||||
|
self.property = make_node(AST_Number, self.property, {
|
||||||
|
value: v
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return self;
|
return self;
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -51,7 +51,7 @@
|
|||||||
start : my_start_token(M),
|
start : my_start_token(M),
|
||||||
end : my_end_token(M),
|
end : my_end_token(M),
|
||||||
body : from_moz(M.block).body,
|
body : from_moz(M.block).body,
|
||||||
bcatch : from_moz(M.handlers[0]),
|
bcatch : from_moz(M.handlers ? M.handlers[0] : M.handler),
|
||||||
bfinally : M.finalizer ? new AST_Finally(from_moz(M.finalizer)) : null
|
bfinally : M.finalizer ? new AST_Finally(from_moz(M.finalizer)) : null
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -51,6 +51,7 @@ function OutputStream(options) {
|
|||||||
quote_keys : false,
|
quote_keys : false,
|
||||||
space_colon : true,
|
space_colon : true,
|
||||||
ascii_only : false,
|
ascii_only : false,
|
||||||
|
unescape_regexps : false,
|
||||||
inline_script : false,
|
inline_script : false,
|
||||||
width : 80,
|
width : 80,
|
||||||
max_line_len : 32000,
|
max_line_len : 32000,
|
||||||
@@ -61,6 +62,7 @@ function OutputStream(options) {
|
|||||||
comments : false,
|
comments : false,
|
||||||
preserve_line : false,
|
preserve_line : false,
|
||||||
screw_ie8 : false,
|
screw_ie8 : false,
|
||||||
|
preamble : null,
|
||||||
}, true);
|
}, true);
|
||||||
|
|
||||||
var indentation = 0;
|
var indentation = 0;
|
||||||
@@ -299,6 +301,10 @@ function OutputStream(options) {
|
|||||||
return OUTPUT;
|
return OUTPUT;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
if (options.preamble) {
|
||||||
|
print(options.preamble.replace(/\r\n?|[\n\u2028\u2029]|\s*$/g, "\n"));
|
||||||
|
}
|
||||||
|
|
||||||
var stack = [];
|
var stack = [];
|
||||||
return {
|
return {
|
||||||
get : get,
|
get : get,
|
||||||
@@ -378,15 +384,23 @@ function OutputStream(options) {
|
|||||||
var start = self.start;
|
var start = self.start;
|
||||||
if (start && !start._comments_dumped) {
|
if (start && !start._comments_dumped) {
|
||||||
start._comments_dumped = true;
|
start._comments_dumped = true;
|
||||||
var comments = start.comments_before;
|
var comments = start.comments_before || [];
|
||||||
|
|
||||||
// XXX: ugly fix for https://github.com/mishoo/UglifyJS2/issues/112
|
// XXX: ugly fix for https://github.com/mishoo/UglifyJS2/issues/112
|
||||||
// if this node is `return` or `throw`, we cannot allow comments before
|
// and https://github.com/mishoo/UglifyJS2/issues/372
|
||||||
// the returned or thrown value.
|
if (self instanceof AST_Exit && self.value) {
|
||||||
if (self instanceof AST_Exit &&
|
self.value.walk(new TreeWalker(function(node){
|
||||||
self.value && self.value.start.comments_before.length > 0) {
|
if (node.start && node.start.comments_before) {
|
||||||
comments = (comments || []).concat(self.value.start.comments_before);
|
comments = comments.concat(node.start.comments_before);
|
||||||
self.value.start.comments_before = [];
|
node.start.comments_before = [];
|
||||||
|
}
|
||||||
|
if (node instanceof AST_Function ||
|
||||||
|
node instanceof AST_Array ||
|
||||||
|
node instanceof AST_Object)
|
||||||
|
{
|
||||||
|
return true; // don't go inside.
|
||||||
|
}
|
||||||
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (c.test) {
|
if (c.test) {
|
||||||
@@ -450,7 +464,7 @@ function OutputStream(options) {
|
|||||||
|| p instanceof AST_Unary // !(foo, bar, baz)
|
|| p instanceof AST_Unary // !(foo, bar, baz)
|
||||||
|| p instanceof AST_Binary // 1 + (2, 3) + 4 ==> 8
|
|| p instanceof AST_Binary // 1 + (2, 3) + 4 ==> 8
|
||||||
|| p instanceof AST_VarDef // var a = (1, 2), b = a + a; ==> b == 4
|
|| p instanceof AST_VarDef // var a = (1, 2), b = a + a; ==> b == 4
|
||||||
|| p instanceof AST_Dot // (1, {foo:2}).foo ==> 2
|
|| p instanceof AST_PropAccess // (1, {foo:2}).foo or (1, {foo:2})["foo"] ==> 2
|
||||||
|| p instanceof AST_Array // [ 1, (2, 3), 4 ] ==> [ 1, 3, 4 ]
|
|| p instanceof AST_Array // [ 1, (2, 3), 4 ] ==> [ 1, 3, 4 ]
|
||||||
|| p instanceof AST_ObjectProperty // { foo: (1, 2) }.foo ==> 2
|
|| p instanceof AST_ObjectProperty // { foo: (1, 2) }.foo ==> 2
|
||||||
|| p instanceof AST_Conditional /* (false, true) ? (a = 10, b = 20) : (c = 30)
|
|| p instanceof AST_Conditional /* (false, true) ? (a = 10, b = 20) : (c = 30)
|
||||||
@@ -475,11 +489,7 @@ function OutputStream(options) {
|
|||||||
var so = this.operator, sp = PRECEDENCE[so];
|
var so = this.operator, sp = PRECEDENCE[so];
|
||||||
if (pp > sp
|
if (pp > sp
|
||||||
|| (pp == sp
|
|| (pp == sp
|
||||||
&& this === p.right
|
&& this === p.right)) {
|
||||||
&& !(so == po &&
|
|
||||||
(so == "*" ||
|
|
||||||
so == "&&" ||
|
|
||||||
so == "||")))) {
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -506,8 +516,17 @@ function OutputStream(options) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
PARENS(AST_Call, function(output){
|
PARENS(AST_Call, function(output){
|
||||||
var p = output.parent();
|
var p = output.parent(), p1;
|
||||||
return p instanceof AST_New && p.expression === this;
|
if (p instanceof AST_New && p.expression === this)
|
||||||
|
return true;
|
||||||
|
|
||||||
|
// workaround for Safari bug.
|
||||||
|
// https://bugs.webkit.org/show_bug.cgi?id=123506
|
||||||
|
return this.expression instanceof AST_Function
|
||||||
|
&& p instanceof AST_PropAccess
|
||||||
|
&& p.expression === this
|
||||||
|
&& (p1 = output.parent(1)) instanceof AST_Assign
|
||||||
|
&& p1.left === p;
|
||||||
});
|
});
|
||||||
|
|
||||||
PARENS(AST_New, function(output){
|
PARENS(AST_New, function(output){
|
||||||
@@ -977,8 +996,12 @@ function OutputStream(options) {
|
|||||||
DEFPRINT(AST_UnaryPrefix, function(self, output){
|
DEFPRINT(AST_UnaryPrefix, function(self, output){
|
||||||
var op = self.operator;
|
var op = self.operator;
|
||||||
output.print(op);
|
output.print(op);
|
||||||
if (/^[a-z]/i.test(op))
|
if (/^[a-z]/i.test(op)
|
||||||
|
|| (/[+-]$/.test(op)
|
||||||
|
&& self.expression instanceof AST_UnaryPrefix
|
||||||
|
&& /^[+-]/.test(self.expression.operator))) {
|
||||||
output.space();
|
output.space();
|
||||||
|
}
|
||||||
self.expression.print(output);
|
self.expression.print(output);
|
||||||
});
|
});
|
||||||
DEFPRINT(AST_UnaryPostfix, function(self, output){
|
DEFPRINT(AST_UnaryPostfix, function(self, output){
|
||||||
@@ -1064,10 +1087,14 @@ function OutputStream(options) {
|
|||||||
});
|
});
|
||||||
DEFPRINT(AST_ObjectSetter, function(self, output){
|
DEFPRINT(AST_ObjectSetter, function(self, output){
|
||||||
output.print("set");
|
output.print("set");
|
||||||
|
output.space();
|
||||||
|
self.key.print(output);
|
||||||
self.value._do_print(output, true);
|
self.value._do_print(output, true);
|
||||||
});
|
});
|
||||||
DEFPRINT(AST_ObjectGetter, function(self, output){
|
DEFPRINT(AST_ObjectGetter, function(self, output){
|
||||||
output.print("get");
|
output.print("get");
|
||||||
|
output.space();
|
||||||
|
self.key.print(output);
|
||||||
self.value._do_print(output, true);
|
self.value._do_print(output, true);
|
||||||
});
|
});
|
||||||
DEFPRINT(AST_Symbol, function(self, output){
|
DEFPRINT(AST_Symbol, function(self, output){
|
||||||
@@ -1096,10 +1123,47 @@ function OutputStream(options) {
|
|||||||
DEFPRINT(AST_Number, function(self, output){
|
DEFPRINT(AST_Number, function(self, output){
|
||||||
output.print(make_num(self.getValue()));
|
output.print(make_num(self.getValue()));
|
||||||
});
|
});
|
||||||
|
|
||||||
|
function regexp_safe_literal(code) {
|
||||||
|
return [
|
||||||
|
0x5c , // \
|
||||||
|
0x2f , // /
|
||||||
|
0x2e , // .
|
||||||
|
0x2b , // +
|
||||||
|
0x2a , // *
|
||||||
|
0x3f , // ?
|
||||||
|
0x28 , // (
|
||||||
|
0x29 , // )
|
||||||
|
0x5b , // [
|
||||||
|
0x5d , // ]
|
||||||
|
0x7b , // {
|
||||||
|
0x7d , // }
|
||||||
|
0x24 , // $
|
||||||
|
0x5e , // ^
|
||||||
|
0x3a , // :
|
||||||
|
0x7c , // |
|
||||||
|
0x21 , // !
|
||||||
|
0x0a , // \n
|
||||||
|
0x0d , // \r
|
||||||
|
0x00 , // \0
|
||||||
|
0xfeff , // Unicode BOM
|
||||||
|
0x2028 , // unicode "line separator"
|
||||||
|
0x2029 , // unicode "paragraph separator"
|
||||||
|
].indexOf(code) < 0;
|
||||||
|
};
|
||||||
|
|
||||||
DEFPRINT(AST_RegExp, function(self, output){
|
DEFPRINT(AST_RegExp, function(self, output){
|
||||||
var str = self.getValue().toString();
|
var str = self.getValue().toString();
|
||||||
if (output.option("ascii_only"))
|
if (output.option("ascii_only")) {
|
||||||
str = output.to_ascii(str);
|
str = output.to_ascii(str);
|
||||||
|
} else if (output.option("unescape_regexps")) {
|
||||||
|
str = str.split("\\\\").map(function(str){
|
||||||
|
return str.replace(/\\u[0-9a-fA-F]{4}|\\x[0-9a-fA-F]{2}/g, function(s){
|
||||||
|
var code = parseInt(s.substr(2), 16);
|
||||||
|
return regexp_safe_literal(code) ? String.fromCharCode(code) : s;
|
||||||
|
});
|
||||||
|
}).join("\\\\");
|
||||||
|
}
|
||||||
output.print(str);
|
output.print(str);
|
||||||
var p = output.parent();
|
var p = output.parent();
|
||||||
if (p instanceof AST_Binary && /^in/.test(p.operator) && p.left === self)
|
if (p instanceof AST_Binary && /^in/.test(p.operator) && p.left === self)
|
||||||
|
|||||||
62
lib/parse.js
62
lib/parse.js
@@ -46,7 +46,7 @@
|
|||||||
|
|
||||||
var KEYWORDS = 'break case catch const continue debugger default delete do else finally for function if in instanceof new return switch throw try typeof var void while with';
|
var KEYWORDS = 'break case catch const continue debugger default delete do else finally for function if in instanceof new return switch throw try typeof var void while with';
|
||||||
var KEYWORDS_ATOM = 'false null true';
|
var KEYWORDS_ATOM = 'false null true';
|
||||||
var RESERVED_WORDS = 'abstract boolean byte char class double enum export extends final float goto implements import int interface long native package private protected public short static super synchronized this throws transient volatile'
|
var RESERVED_WORDS = 'abstract boolean byte char class double enum export extends final float goto implements import int interface long native package private protected public short static super synchronized this throws transient volatile yield'
|
||||||
+ " " + KEYWORDS_ATOM + " " + KEYWORDS;
|
+ " " + KEYWORDS_ATOM + " " + KEYWORDS;
|
||||||
var KEYWORDS_BEFORE_EXPRESSION = 'return new delete throw else case';
|
var KEYWORDS_BEFORE_EXPRESSION = 'return new delete throw else case';
|
||||||
|
|
||||||
@@ -168,14 +168,7 @@ function is_identifier_char(ch) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
function is_identifier_string(str){
|
function is_identifier_string(str){
|
||||||
var i = str.length;
|
return /^[a-z_$][a-z0-9_$]*$/i.test(str);
|
||||||
if (i == 0) return false;
|
|
||||||
if (!is_identifier_start(str.charCodeAt(0))) return false;
|
|
||||||
while (--i >= 0) {
|
|
||||||
if (!is_identifier_char(str.charAt(i)))
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
function parse_js_number(num) {
|
function parse_js_number(num) {
|
||||||
@@ -579,10 +572,10 @@ var UNARY_POSTFIX = makePredicate([ "--", "++" ]);
|
|||||||
var ASSIGNMENT = makePredicate([ "=", "+=", "-=", "/=", "*=", "%=", ">>=", "<<=", ">>>=", "|=", "^=", "&=" ]);
|
var ASSIGNMENT = makePredicate([ "=", "+=", "-=", "/=", "*=", "%=", ">>=", "<<=", ">>>=", "|=", "^=", "&=" ]);
|
||||||
|
|
||||||
var PRECEDENCE = (function(a, ret){
|
var PRECEDENCE = (function(a, ret){
|
||||||
for (var i = 0, n = 1; i < a.length; ++i, ++n) {
|
for (var i = 0; i < a.length; ++i) {
|
||||||
var b = a[i];
|
var b = a[i];
|
||||||
for (var j = 0; j < b.length; ++j) {
|
for (var j = 0; j < b.length; ++j) {
|
||||||
ret[b[j]] = n;
|
ret[b[j]] = i + 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return ret;
|
return ret;
|
||||||
@@ -789,7 +782,7 @@ function parse($TEXT, options) {
|
|||||||
return for_();
|
return for_();
|
||||||
|
|
||||||
case "function":
|
case "function":
|
||||||
return function_(true);
|
return function_(AST_Defun);
|
||||||
|
|
||||||
case "if":
|
case "if":
|
||||||
return if_();
|
return if_();
|
||||||
@@ -933,19 +926,12 @@ function parse($TEXT, options) {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
var function_ = function(in_statement, ctor) {
|
var function_ = function(ctor) {
|
||||||
var is_accessor = ctor === AST_Accessor;
|
var in_statement = ctor === AST_Defun;
|
||||||
var name = (is("name") ? as_symbol(in_statement
|
var name = is("name") ? as_symbol(in_statement ? AST_SymbolDefun : AST_SymbolLambda) : null;
|
||||||
? AST_SymbolDefun
|
|
||||||
: is_accessor
|
|
||||||
? AST_SymbolAccessor
|
|
||||||
: AST_SymbolLambda)
|
|
||||||
: is_accessor && (is("string") || is("num")) ? as_atom_node()
|
|
||||||
: null);
|
|
||||||
if (in_statement && !name)
|
if (in_statement && !name)
|
||||||
unexpected();
|
unexpected();
|
||||||
expect("(");
|
expect("(");
|
||||||
if (!ctor) ctor = in_statement ? AST_Defun : AST_Function;
|
|
||||||
return new ctor({
|
return new ctor({
|
||||||
name: name,
|
name: name,
|
||||||
argnames: (function(first, a){
|
argnames: (function(first, a){
|
||||||
@@ -1116,7 +1102,9 @@ function parse($TEXT, options) {
|
|||||||
var tok = S.token, ret;
|
var tok = S.token, ret;
|
||||||
switch (tok.type) {
|
switch (tok.type) {
|
||||||
case "name":
|
case "name":
|
||||||
return as_symbol(AST_SymbolRef);
|
case "keyword":
|
||||||
|
ret = _make_symbol(AST_SymbolRef);
|
||||||
|
break;
|
||||||
case "num":
|
case "num":
|
||||||
ret = new AST_Number({ start: tok, end: tok, value: tok.value });
|
ret = new AST_Number({ start: tok, end: tok, value: tok.value });
|
||||||
break;
|
break;
|
||||||
@@ -1167,7 +1155,7 @@ function parse($TEXT, options) {
|
|||||||
}
|
}
|
||||||
if (is("keyword", "function")) {
|
if (is("keyword", "function")) {
|
||||||
next();
|
next();
|
||||||
var func = function_(false);
|
var func = function_(AST_Function);
|
||||||
func.start = start;
|
func.start = start;
|
||||||
func.end = prev();
|
func.end = prev();
|
||||||
return subscripts(func, allow_calls);
|
return subscripts(func, allow_calls);
|
||||||
@@ -1215,8 +1203,8 @@ function parse($TEXT, options) {
|
|||||||
if (name == "get") {
|
if (name == "get") {
|
||||||
a.push(new AST_ObjectGetter({
|
a.push(new AST_ObjectGetter({
|
||||||
start : start,
|
start : start,
|
||||||
key : name,
|
key : as_atom_node(),
|
||||||
value : function_(false, AST_Accessor),
|
value : function_(AST_Accessor),
|
||||||
end : prev()
|
end : prev()
|
||||||
}));
|
}));
|
||||||
continue;
|
continue;
|
||||||
@@ -1224,8 +1212,8 @@ function parse($TEXT, options) {
|
|||||||
if (name == "set") {
|
if (name == "set") {
|
||||||
a.push(new AST_ObjectSetter({
|
a.push(new AST_ObjectSetter({
|
||||||
start : start,
|
start : start,
|
||||||
key : name,
|
key : as_atom_node(),
|
||||||
value : function_(false, AST_Accessor),
|
value : function_(AST_Accessor),
|
||||||
end : prev()
|
end : prev()
|
||||||
}));
|
}));
|
||||||
continue;
|
continue;
|
||||||
@@ -1273,17 +1261,21 @@ function parse($TEXT, options) {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
function _make_symbol(type) {
|
||||||
|
var name = S.token.value;
|
||||||
|
return new (name == "this" ? AST_This : type)({
|
||||||
|
name : String(name),
|
||||||
|
start : S.token,
|
||||||
|
end : S.token
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
function as_symbol(type, noerror) {
|
function as_symbol(type, noerror) {
|
||||||
if (!is("name")) {
|
if (!is("name")) {
|
||||||
if (!noerror) croak("Name expected");
|
if (!noerror) croak("Name expected");
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
var name = S.token.value;
|
var sym = _make_symbol(type);
|
||||||
var sym = new (name == "this" ? AST_This : type)({
|
|
||||||
name : String(S.token.value),
|
|
||||||
start : S.token,
|
|
||||||
end : S.token
|
|
||||||
});
|
|
||||||
next();
|
next();
|
||||||
return sym;
|
return sym;
|
||||||
};
|
};
|
||||||
@@ -1382,7 +1374,7 @@ function parse($TEXT, options) {
|
|||||||
condition : expr,
|
condition : expr,
|
||||||
consequent : yes,
|
consequent : yes,
|
||||||
alternative : expression(false, no_in),
|
alternative : expression(false, no_in),
|
||||||
end : peek()
|
end : prev()
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
return expr;
|
return expr;
|
||||||
|
|||||||
70
lib/scope.js
70
lib/scope.js
@@ -64,34 +64,41 @@ SymbolDef.prototype = {
|
|||||||
mangle: function(options) {
|
mangle: function(options) {
|
||||||
if (!this.mangled_name && !this.unmangleable(options)) {
|
if (!this.mangled_name && !this.unmangleable(options)) {
|
||||||
var s = this.scope;
|
var s = this.scope;
|
||||||
if (this.orig[0] instanceof AST_SymbolLambda && !options.screw_ie8)
|
if (!options.screw_ie8 && this.orig[0] instanceof AST_SymbolLambda)
|
||||||
s = s.parent_scope;
|
s = s.parent_scope;
|
||||||
this.mangled_name = s.next_mangled(options);
|
this.mangled_name = s.next_mangled(options, this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
AST_Toplevel.DEFMETHOD("figure_out_scope", function(){
|
AST_Toplevel.DEFMETHOD("figure_out_scope", function(options){
|
||||||
// This does what ast_add_scope did in UglifyJS v1.
|
options = defaults(options, {
|
||||||
//
|
screw_ie8: false
|
||||||
// Part of it could be done at parse time, but it would complicate
|
});
|
||||||
// the parser (and it's already kinda complex). It's also worth
|
|
||||||
// having it separated because we might need to call it multiple
|
|
||||||
// times on the same tree.
|
|
||||||
|
|
||||||
// pass 1: setup scope chaining and handle definitions
|
// pass 1: setup scope chaining and handle definitions
|
||||||
var self = this;
|
var self = this;
|
||||||
var scope = self.parent_scope = null;
|
var scope = self.parent_scope = null;
|
||||||
|
var defun = null;
|
||||||
var nesting = 0;
|
var nesting = 0;
|
||||||
var tw = new TreeWalker(function(node, descend){
|
var tw = new TreeWalker(function(node, descend){
|
||||||
|
if (options.screw_ie8 && node instanceof AST_Catch) {
|
||||||
|
var save_scope = scope;
|
||||||
|
scope = new AST_Scope(node);
|
||||||
|
scope.init_scope_vars(nesting);
|
||||||
|
scope.parent_scope = save_scope;
|
||||||
|
descend();
|
||||||
|
scope = save_scope;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
if (node instanceof AST_Scope) {
|
if (node instanceof AST_Scope) {
|
||||||
node.init_scope_vars(nesting);
|
node.init_scope_vars(nesting);
|
||||||
var save_scope = node.parent_scope = scope;
|
var save_scope = node.parent_scope = scope;
|
||||||
++nesting;
|
var save_defun = defun;
|
||||||
scope = node;
|
defun = scope = node;
|
||||||
descend();
|
++nesting; descend(); --nesting;
|
||||||
scope = save_scope;
|
scope = save_scope;
|
||||||
--nesting;
|
defun = save_defun;
|
||||||
return true; // don't descend again in TreeWalker
|
return true; // don't descend again in TreeWalker
|
||||||
}
|
}
|
||||||
if (node instanceof AST_Directive) {
|
if (node instanceof AST_Directive) {
|
||||||
@@ -108,7 +115,7 @@ AST_Toplevel.DEFMETHOD("figure_out_scope", function(){
|
|||||||
node.scope = scope;
|
node.scope = scope;
|
||||||
}
|
}
|
||||||
if (node instanceof AST_SymbolLambda) {
|
if (node instanceof AST_SymbolLambda) {
|
||||||
scope.def_function(node);
|
defun.def_function(node);
|
||||||
}
|
}
|
||||||
else if (node instanceof AST_SymbolDefun) {
|
else if (node instanceof AST_SymbolDefun) {
|
||||||
// Careful here, the scope where this should be defined is
|
// Careful here, the scope where this should be defined is
|
||||||
@@ -116,22 +123,17 @@ AST_Toplevel.DEFMETHOD("figure_out_scope", function(){
|
|||||||
// scope when we encounter the AST_Defun node (which is
|
// scope when we encounter the AST_Defun node (which is
|
||||||
// instanceof AST_Scope) but we get to the symbol a bit
|
// instanceof AST_Scope) but we get to the symbol a bit
|
||||||
// later.
|
// later.
|
||||||
(node.scope = scope.parent_scope).def_function(node);
|
(node.scope = defun.parent_scope).def_function(node);
|
||||||
}
|
}
|
||||||
else if (node instanceof AST_SymbolVar
|
else if (node instanceof AST_SymbolVar
|
||||||
|| node instanceof AST_SymbolConst) {
|
|| node instanceof AST_SymbolConst) {
|
||||||
var def = scope.def_variable(node);
|
var def = defun.def_variable(node);
|
||||||
def.constant = node instanceof AST_SymbolConst;
|
def.constant = node instanceof AST_SymbolConst;
|
||||||
def.init = tw.parent().value;
|
def.init = tw.parent().value;
|
||||||
}
|
}
|
||||||
else if (node instanceof AST_SymbolCatch) {
|
else if (node instanceof AST_SymbolCatch) {
|
||||||
// XXX: this is wrong according to ECMA-262 (12.4). the
|
(options.screw_ie8 ? scope : defun)
|
||||||
// `catch` argument name should be visible only inside the
|
.def_variable(node);
|
||||||
// catch block. For a quick fix AST_Catch should inherit
|
|
||||||
// from AST_Scope. Keeping it this way because of IE,
|
|
||||||
// which doesn't obey the standard. (it introduces the
|
|
||||||
// identifier in the enclosing scope)
|
|
||||||
scope.def_variable(node);
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
self.walk(tw);
|
self.walk(tw);
|
||||||
@@ -244,6 +246,11 @@ AST_Scope.DEFMETHOD("next_mangled", function(options){
|
|||||||
out: while (true) {
|
out: while (true) {
|
||||||
var m = base54(++this.cname);
|
var m = base54(++this.cname);
|
||||||
if (!is_identifier(m)) continue; // skip over "do"
|
if (!is_identifier(m)) continue; // skip over "do"
|
||||||
|
|
||||||
|
// https://github.com/mishoo/UglifyJS2/issues/242 -- do not
|
||||||
|
// shadow a name excepted from mangling.
|
||||||
|
if (options.except.indexOf(m) >= 0) continue;
|
||||||
|
|
||||||
// we must ensure that the mangled name does not shadow a name
|
// we must ensure that the mangled name does not shadow a name
|
||||||
// from some parent scope that is referenced in this or in
|
// from some parent scope that is referenced in this or in
|
||||||
// inner scopes.
|
// inner scopes.
|
||||||
@@ -256,6 +263,19 @@ AST_Scope.DEFMETHOD("next_mangled", function(options){
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
AST_Function.DEFMETHOD("next_mangled", function(options, def){
|
||||||
|
// #179, #326
|
||||||
|
// in Safari strict mode, something like (function x(x){...}) is a syntax error;
|
||||||
|
// a function expression's argument cannot shadow the function expression's name
|
||||||
|
|
||||||
|
var tricky_def = def.orig[0] instanceof AST_SymbolFunarg && this.name && this.name.definition();
|
||||||
|
while (true) {
|
||||||
|
var name = AST_Lambda.prototype.next_mangled.call(this, options, def);
|
||||||
|
if (!(tricky_def && tricky_def.mangled_name == name))
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
AST_Scope.DEFMETHOD("references", function(sym){
|
AST_Scope.DEFMETHOD("references", function(sym){
|
||||||
if (sym instanceof AST_Symbol) sym = sym.definition();
|
if (sym instanceof AST_Symbol) sym = sym.definition();
|
||||||
return this.enclosed.indexOf(sym) < 0 ? null : sym;
|
return this.enclosed.indexOf(sym) < 0 ? null : sym;
|
||||||
@@ -345,6 +365,10 @@ AST_Toplevel.DEFMETHOD("mangle_names", function(options){
|
|||||||
node.mangled_name = name;
|
node.mangled_name = name;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
if (options.screw_ie8 && node instanceof AST_SymbolCatch) {
|
||||||
|
to_mangle.push(node.definition());
|
||||||
|
return;
|
||||||
|
}
|
||||||
});
|
});
|
||||||
this.walk(tw);
|
this.walk(tw);
|
||||||
to_mangle.forEach(function(def){ def.mangle(options) });
|
to_mangle.forEach(function(def){ def.mangle(options) });
|
||||||
|
|||||||
@@ -49,6 +49,9 @@ function SourceMap(options) {
|
|||||||
file : null,
|
file : null,
|
||||||
root : null,
|
root : null,
|
||||||
orig : null,
|
orig : null,
|
||||||
|
|
||||||
|
orig_line_diff : 0,
|
||||||
|
dest_line_diff : 0,
|
||||||
});
|
});
|
||||||
var generator = new MOZ_SourceMap.SourceMapGenerator({
|
var generator = new MOZ_SourceMap.SourceMapGenerator({
|
||||||
file : options.file,
|
file : options.file,
|
||||||
@@ -61,14 +64,17 @@ function SourceMap(options) {
|
|||||||
line: orig_line,
|
line: orig_line,
|
||||||
column: orig_col
|
column: orig_col
|
||||||
});
|
});
|
||||||
|
if (info.source === null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
source = info.source;
|
source = info.source;
|
||||||
orig_line = info.line;
|
orig_line = info.line;
|
||||||
orig_col = info.column;
|
orig_col = info.column;
|
||||||
name = info.name;
|
name = info.name;
|
||||||
}
|
}
|
||||||
generator.addMapping({
|
generator.addMapping({
|
||||||
generated : { line: gen_line, column: gen_col },
|
generated : { line: gen_line + options.dest_line_diff, column: gen_col },
|
||||||
original : { line: orig_line, column: orig_col },
|
original : { line: orig_line + options.orig_line_diff, column: orig_col },
|
||||||
source : source,
|
source : source,
|
||||||
name : name
|
name : name
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -82,16 +82,23 @@ function repeat_string(str, i) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
function DefaultsError(msg, defs) {
|
function DefaultsError(msg, defs) {
|
||||||
|
Error.call(this, msg);
|
||||||
this.msg = msg;
|
this.msg = msg;
|
||||||
this.defs = defs;
|
this.defs = defs;
|
||||||
};
|
};
|
||||||
|
DefaultsError.prototype = Object.create(Error.prototype);
|
||||||
|
DefaultsError.prototype.constructor = DefaultsError;
|
||||||
|
|
||||||
|
DefaultsError.croak = function(msg, defs) {
|
||||||
|
throw new DefaultsError(msg, defs);
|
||||||
|
};
|
||||||
|
|
||||||
function defaults(args, defs, croak) {
|
function defaults(args, defs, croak) {
|
||||||
if (args === true)
|
if (args === true)
|
||||||
args = {};
|
args = {};
|
||||||
var ret = args || {};
|
var ret = args || {};
|
||||||
if (croak) for (var i in ret) if (ret.hasOwnProperty(i) && !defs.hasOwnProperty(i))
|
if (croak) for (var i in ret) if (ret.hasOwnProperty(i) && !defs.hasOwnProperty(i))
|
||||||
throw new DefaultsError("`" + i + "` is not a supported option", defs);
|
DefaultsError.croak("`" + i + "` is not a supported option", defs);
|
||||||
for (var i in defs) if (defs.hasOwnProperty(i)) {
|
for (var i in defs) if (defs.hasOwnProperty(i)) {
|
||||||
ret[i] = (args && args.hasOwnProperty(i)) ? args[i] : defs[i];
|
ret[i] = (args && args.hasOwnProperty(i)) ? args[i] : defs[i];
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
"description": "JavaScript parser, mangler/compressor and beautifier toolkit",
|
"description": "JavaScript parser, mangler/compressor and beautifier toolkit",
|
||||||
"homepage": "http://lisperator.net/uglifyjs",
|
"homepage": "http://lisperator.net/uglifyjs",
|
||||||
"main": "tools/node.js",
|
"main": "tools/node.js",
|
||||||
"version": "2.4.1",
|
"version": "2.4.14",
|
||||||
"engines": { "node" : ">=0.4.0" },
|
"engines": { "node" : ">=0.4.0" },
|
||||||
"maintainers": [{
|
"maintainers": [{
|
||||||
"name": "Mihai Bazon",
|
"name": "Mihai Bazon",
|
||||||
@@ -16,7 +16,7 @@
|
|||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"async" : "~0.2.6",
|
"async" : "~0.2.6",
|
||||||
"source-map" : "~0.1.7",
|
"source-map" : "~0.1.33",
|
||||||
"optimist" : "~0.3.5",
|
"optimist" : "~0.3.5",
|
||||||
"uglify-to-browserify": "~1.0.0"
|
"uglify-to-browserify": "~1.0.0"
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -141,3 +141,94 @@ ifs_6: {
|
|||||||
x = foo || bar || baz || boo ? 20 : 10;
|
x = foo || bar || baz || boo ? 20 : 10;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
cond_1: {
|
||||||
|
options = {
|
||||||
|
conditionals: true
|
||||||
|
};
|
||||||
|
input: {
|
||||||
|
if (some_condition()) {
|
||||||
|
do_something(x);
|
||||||
|
} else {
|
||||||
|
do_something(y);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
do_something(some_condition() ? x : y);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
cond_2: {
|
||||||
|
options = {
|
||||||
|
conditionals: true
|
||||||
|
};
|
||||||
|
input: {
|
||||||
|
if (some_condition()) {
|
||||||
|
x = new FooBar(1);
|
||||||
|
} else {
|
||||||
|
x = new FooBar(2);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
x = new FooBar(some_condition() ? 1 : 2);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
cond_3: {
|
||||||
|
options = {
|
||||||
|
conditionals: true
|
||||||
|
};
|
||||||
|
input: {
|
||||||
|
if (some_condition()) {
|
||||||
|
new FooBar(1);
|
||||||
|
} else {
|
||||||
|
FooBar(2);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
some_condition() ? new FooBar(1) : FooBar(2);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
cond_4: {
|
||||||
|
options = {
|
||||||
|
conditionals: true
|
||||||
|
};
|
||||||
|
input: {
|
||||||
|
if (some_condition()) {
|
||||||
|
do_something();
|
||||||
|
} else {
|
||||||
|
do_something();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
some_condition(), do_something();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
cond_5: {
|
||||||
|
options = {
|
||||||
|
conditionals: true
|
||||||
|
};
|
||||||
|
input: {
|
||||||
|
if (some_condition()) {
|
||||||
|
if (some_other_condition()) {
|
||||||
|
do_something();
|
||||||
|
} else {
|
||||||
|
alternate();
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
alternate();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (some_condition()) {
|
||||||
|
if (some_other_condition()) {
|
||||||
|
do_something();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
some_condition() && some_other_condition() ? do_something() : alternate();
|
||||||
|
some_condition() && some_other_condition() && do_something();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -119,3 +119,47 @@ unused_keep_setter_arg: {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
unused_var_in_catch: {
|
||||||
|
options = { unused: true };
|
||||||
|
input: {
|
||||||
|
function foo() {
|
||||||
|
try {
|
||||||
|
foo();
|
||||||
|
} catch(ex) {
|
||||||
|
var x = 10;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
function foo() {
|
||||||
|
try {
|
||||||
|
foo();
|
||||||
|
} catch(ex) {}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
used_var_in_catch: {
|
||||||
|
options = { unused: true };
|
||||||
|
input: {
|
||||||
|
function foo() {
|
||||||
|
try {
|
||||||
|
foo();
|
||||||
|
} catch(ex) {
|
||||||
|
var x = 10;
|
||||||
|
}
|
||||||
|
return x;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
function foo() {
|
||||||
|
try {
|
||||||
|
foo();
|
||||||
|
} catch(ex) {
|
||||||
|
var x = 10;
|
||||||
|
}
|
||||||
|
return x;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ concatenate_rhs_strings: {
|
|||||||
foo(bar() + 123 + "Hello" + "World" + ("Foo" + "Bar"));
|
foo(bar() + 123 + "Hello" + "World" + ("Foo" + "Bar"));
|
||||||
foo("Foo" + "Bar" + bar() + 123 + "Hello" + "World" + ("Foo" + "Bar"));
|
foo("Foo" + "Bar" + bar() + 123 + "Hello" + "World" + ("Foo" + "Bar"));
|
||||||
foo("Hello" + bar() + 123 + "World");
|
foo("Hello" + bar() + 123 + "World");
|
||||||
|
foo(bar() + 'Foo' + (10 + parseInt('10')));
|
||||||
}
|
}
|
||||||
expect: {
|
expect: {
|
||||||
foo(bar() + 123 + "HelloWorld");
|
foo(bar() + 123 + "HelloWorld");
|
||||||
@@ -18,5 +19,6 @@ concatenate_rhs_strings: {
|
|||||||
foo(bar() + 123 + "HelloWorldFooBar");
|
foo(bar() + 123 + "HelloWorldFooBar");
|
||||||
foo("FooBar" + bar() + "123HelloWorldFooBar");
|
foo("FooBar" + bar() + "123HelloWorldFooBar");
|
||||||
foo("Hello" + bar() + "123World");
|
foo("Hello" + bar() + "123World");
|
||||||
|
foo(bar() + 'Foo' + (10 + parseInt('10')));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
11
test/compress/issue-267.js
Normal file
11
test/compress/issue-267.js
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
issue_267: {
|
||||||
|
options = { comparisons: true };
|
||||||
|
input: {
|
||||||
|
x = a % b / b * c * 2;
|
||||||
|
x = a % b * 2
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
x = a % b / b * c * 2;
|
||||||
|
x = a % b * 2;
|
||||||
|
}
|
||||||
|
}
|
||||||
66
test/compress/issue-269.js
Normal file
66
test/compress/issue-269.js
Normal file
@@ -0,0 +1,66 @@
|
|||||||
|
issue_269_1: {
|
||||||
|
options = {unsafe: true};
|
||||||
|
input: {
|
||||||
|
f(
|
||||||
|
String(x),
|
||||||
|
Number(x),
|
||||||
|
Boolean(x),
|
||||||
|
|
||||||
|
String(),
|
||||||
|
Number(),
|
||||||
|
Boolean()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
f(
|
||||||
|
x + '', +x, !!x,
|
||||||
|
'', 0, false
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
issue_269_dangers: {
|
||||||
|
options = {unsafe: true};
|
||||||
|
input: {
|
||||||
|
f(
|
||||||
|
String(x, x),
|
||||||
|
Number(x, x),
|
||||||
|
Boolean(x, x)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
f(String(x, x), Number(x, x), Boolean(x, x));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
issue_269_in_scope: {
|
||||||
|
options = {unsafe: true};
|
||||||
|
input: {
|
||||||
|
var String, Number, Boolean;
|
||||||
|
f(
|
||||||
|
String(x),
|
||||||
|
Number(x, x),
|
||||||
|
Boolean(x)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
var String, Number, Boolean;
|
||||||
|
f(String(x), Number(x, x), Boolean(x));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
strings_concat: {
|
||||||
|
options = {unsafe: true};
|
||||||
|
input: {
|
||||||
|
f(
|
||||||
|
String(x + 'str'),
|
||||||
|
String('str' + x)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
f(
|
||||||
|
x + 'str',
|
||||||
|
'str' + x
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -60,16 +60,16 @@ negate_iife_4: {
|
|||||||
};
|
};
|
||||||
input: {
|
input: {
|
||||||
if ((function(){ return true })()) {
|
if ((function(){ return true })()) {
|
||||||
console.log(true);
|
foo(true);
|
||||||
} else {
|
} else {
|
||||||
console.log(false);
|
bar(false);
|
||||||
}
|
}
|
||||||
(function(){
|
(function(){
|
||||||
console.log("something");
|
console.log("something");
|
||||||
})();
|
})();
|
||||||
}
|
}
|
||||||
expect: {
|
expect: {
|
||||||
!function(){ return true }() ? console.log(false) : console.log(true), function(){
|
!function(){ return true }() ? bar(false) : foo(true), function(){
|
||||||
console.log("something");
|
console.log("something");
|
||||||
}();
|
}();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ dot_properties: {
|
|||||||
a.foo = "bar";
|
a.foo = "bar";
|
||||||
a["if"] = "if";
|
a["if"] = "if";
|
||||||
a["*"] = "asterisk";
|
a["*"] = "asterisk";
|
||||||
a.\u0EB3 = "unicode";
|
a["\u0EB3"] = "unicode";
|
||||||
a[""] = "whitespace";
|
a[""] = "whitespace";
|
||||||
a["1_1"] = "foo";
|
a["1_1"] = "foo";
|
||||||
}
|
}
|
||||||
@@ -48,7 +48,7 @@ dot_properties_es5: {
|
|||||||
a.foo = "bar";
|
a.foo = "bar";
|
||||||
a.if = "if";
|
a.if = "if";
|
||||||
a["*"] = "asterisk";
|
a["*"] = "asterisk";
|
||||||
a.\u0EB3 = "unicode";
|
a["\u0EB3"] = "unicode";
|
||||||
a[""] = "whitespace";
|
a[""] = "whitespace";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -101,10 +101,12 @@ lift_sequences_1: {
|
|||||||
lift_sequences_2: {
|
lift_sequences_2: {
|
||||||
options = { sequences: true, evaluate: true };
|
options = { sequences: true, evaluate: true };
|
||||||
input: {
|
input: {
|
||||||
q = 1 + (foo(), bar(), 5) + 7 * (5 / (3 - (a(), (QW=ER), c(), 2))) - (x(), y(), 5);
|
foo.x = (foo = {}, 10);
|
||||||
|
bar = (bar = {}, 10);
|
||||||
}
|
}
|
||||||
expect: {
|
expect: {
|
||||||
foo(), bar(), a(), QW = ER, c(), x(), y(), q = 36
|
foo.x = (foo = {}, 10),
|
||||||
|
bar = {}, bar = 10;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -7,8 +7,15 @@ var assert = require("assert");
|
|||||||
var sys = require("util");
|
var sys = require("util");
|
||||||
|
|
||||||
var tests_dir = path.dirname(module.filename);
|
var tests_dir = path.dirname(module.filename);
|
||||||
|
var failures = 0;
|
||||||
|
var failed_files = {};
|
||||||
|
|
||||||
run_compress_tests();
|
run_compress_tests();
|
||||||
|
if (failures) {
|
||||||
|
sys.error("\n!!! Failed " + failures + " test cases.");
|
||||||
|
sys.error("!!! " + Object.keys(failed_files).join(", "));
|
||||||
|
process.exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
/* -----[ utils ]----- */
|
/* -----[ utils ]----- */
|
||||||
|
|
||||||
@@ -83,6 +90,8 @@ function run_compress_tests() {
|
|||||||
output: output,
|
output: output,
|
||||||
expected: expect
|
expected: expect
|
||||||
});
|
});
|
||||||
|
failures++;
|
||||||
|
failed_files[file] = 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
var tests = parse_test(path.resolve(dir, file));
|
var tests = parse_test(path.resolve(dir, file));
|
||||||
|
|||||||
@@ -51,6 +51,7 @@ for (var i in UglifyJS) {
|
|||||||
|
|
||||||
exports.minify = function(files, options) {
|
exports.minify = function(files, options) {
|
||||||
options = UglifyJS.defaults(options, {
|
options = UglifyJS.defaults(options, {
|
||||||
|
spidermonkey : false,
|
||||||
outSourceMap : null,
|
outSourceMap : null,
|
||||||
sourceRoot : null,
|
sourceRoot : null,
|
||||||
inSourceMap : null,
|
inSourceMap : null,
|
||||||
@@ -60,22 +61,28 @@ exports.minify = function(files, options) {
|
|||||||
output : null,
|
output : null,
|
||||||
compress : {}
|
compress : {}
|
||||||
});
|
});
|
||||||
if (typeof files == "string")
|
|
||||||
files = [ files ];
|
|
||||||
|
|
||||||
UglifyJS.base54.reset();
|
UglifyJS.base54.reset();
|
||||||
|
|
||||||
// 1. parse
|
// 1. parse
|
||||||
var toplevel = null;
|
var toplevel = null,
|
||||||
|
sourcesContent = {};
|
||||||
|
|
||||||
|
if (options.spidermonkey) {
|
||||||
|
toplevel = UglifyJS.AST_Node.from_mozilla_ast(files);
|
||||||
|
} else {
|
||||||
|
if (typeof files == "string")
|
||||||
|
files = [ files ];
|
||||||
files.forEach(function(file){
|
files.forEach(function(file){
|
||||||
var code = options.fromString
|
var code = options.fromString
|
||||||
? file
|
? file
|
||||||
: fs.readFileSync(file, "utf8");
|
: fs.readFileSync(file, "utf8");
|
||||||
|
sourcesContent[file] = code;
|
||||||
toplevel = UglifyJS.parse(code, {
|
toplevel = UglifyJS.parse(code, {
|
||||||
filename: options.fromString ? "?" : file,
|
filename: options.fromString ? "?" : file,
|
||||||
toplevel: toplevel
|
toplevel: toplevel
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
|
||||||
// 2. compress
|
// 2. compress
|
||||||
if (options.compress) {
|
if (options.compress) {
|
||||||
@@ -105,12 +112,25 @@ exports.minify = function(files, options) {
|
|||||||
orig: inMap,
|
orig: inMap,
|
||||||
root: options.sourceRoot
|
root: options.sourceRoot
|
||||||
});
|
});
|
||||||
|
if (options.sourceMapIncludeSources) {
|
||||||
|
for (var file in sourcesContent) {
|
||||||
|
if (sourcesContent.hasOwnProperty(file)) {
|
||||||
|
output.source_map.get().setSourceContent(file, sourcesContent[file]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
if (options.output) {
|
if (options.output) {
|
||||||
UglifyJS.merge(output, options.output);
|
UglifyJS.merge(output, options.output);
|
||||||
}
|
}
|
||||||
var stream = UglifyJS.OutputStream(output);
|
var stream = UglifyJS.OutputStream(output);
|
||||||
toplevel.print(stream);
|
toplevel.print(stream);
|
||||||
|
|
||||||
|
if(options.outSourceMap){
|
||||||
|
stream += "\n//# sourceMappingURL=" + options.outSourceMap;
|
||||||
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
code : stream + "",
|
code : stream + "",
|
||||||
map : output.source_map + ""
|
map : output.source_map + ""
|
||||||
|
|||||||
Reference in New Issue
Block a user