Compare commits
122 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ae740b933f | ||
|
|
ec7f37f314 | ||
|
|
eb48a035e7 | ||
|
|
6ab3224c0d | ||
|
|
c909ffb715 | ||
|
|
f71f4905b0 | ||
|
|
fb177a6312 | ||
|
|
65da9acce6 | ||
|
|
67d0237f73 | ||
|
|
984a21704e | ||
|
|
aa3f647656 | ||
|
|
c526da59a1 | ||
|
|
581630e0a7 | ||
|
|
f5952933a0 | ||
|
|
f001e4cb9d | ||
|
|
57ce5bd9e0 | ||
|
|
861a79ac9f | ||
|
|
00996afd2c | ||
|
|
e76fb354eb | ||
|
|
3276740779 | ||
|
|
5509e51098 | ||
|
|
94f84727ce | ||
|
|
8a4f86528f | ||
|
|
adb0e882e9 | ||
|
|
f83d370f57 | ||
|
|
b19aa58cff | ||
|
|
0a65de89b9 | ||
|
|
6e86ee950d | ||
|
|
8ca2401ebe | ||
|
|
491f16c766 | ||
|
|
a30092e20f | ||
|
|
b1abe92e1a | ||
|
|
b454ce667e | ||
|
|
32283a0def | ||
|
|
ac51d4c5a0 | ||
|
|
0432a7abb9 | ||
|
|
f3a1694a41 | ||
|
|
2e0dc97003 | ||
|
|
701035621d | ||
|
|
79334dda10 | ||
|
|
e918748d88 | ||
|
|
6b2f34769a | ||
|
|
48ffbef51d | ||
|
|
c0f3feae9f | ||
|
|
a00040dd93 | ||
|
|
ee95c1b38b | ||
|
|
4bceb85cbf | ||
|
|
30a75049f5 | ||
|
|
a3cc3a9b87 | ||
|
|
96f8befdd7 | ||
|
|
cd58635dcc | ||
|
|
274331d0ea | ||
|
|
0489d6de64 | ||
|
|
fb092839c2 | ||
|
|
b7c112eefe | ||
|
|
b2b8a0d386 | ||
|
|
ac40301813 | ||
|
|
3563d8c09e | ||
|
|
5ae04b3545 | ||
|
|
a80b228d8b | ||
|
|
cf4bf4ceb1 | ||
|
|
8223b2e0db | ||
|
|
381bd3836e | ||
|
|
919d5e3482 | ||
|
|
e3a3db73ae | ||
|
|
d9344f30b8 | ||
|
|
be80f7e706 | ||
|
|
cf45e2f79b | ||
|
|
8354758f30 | ||
|
|
9e6b128374 | ||
|
|
93cdb194f4 | ||
|
|
b633706ce4 | ||
|
|
e9920f7ca1 | ||
|
|
7e465d4a01 | ||
|
|
aa80ee349d | ||
|
|
80e81765cf | ||
|
|
711f88dcb4 | ||
|
|
344d11d591 | ||
|
|
c7cdcf06a6 | ||
|
|
3ee55748d4 | ||
|
|
dedbeeff15 | ||
|
|
bd6dee52ab | ||
|
|
144052ca49 | ||
|
|
65c848cc6f | ||
|
|
8a8a94a596 | ||
|
|
8153b7bd8a | ||
|
|
d787d70127 | ||
|
|
3ac2421932 | ||
|
|
a9fc9ddc33 | ||
|
|
a5d62a3fc6 | ||
|
|
067e5a5762 | ||
|
|
33b5f31984 | ||
|
|
35a849dc48 | ||
|
|
b70591be1a | ||
|
|
b33e7f88e6 | ||
|
|
1f0333e9f1 | ||
|
|
eb98a7f2f3 | ||
|
|
78d1bb92d4 | ||
|
|
ea9ab9fb0e | ||
|
|
ce54c9ccee | ||
|
|
07accd2fbb | ||
|
|
18059cc94f | ||
|
|
b5e0e8c203 | ||
|
|
e5cb9275df | ||
|
|
17b81350d4 | ||
|
|
4d63d4f5b3 | ||
|
|
70d72ad806 | ||
|
|
fe9227a41b | ||
|
|
b49e142a26 | ||
|
|
ee3b39b909 | ||
|
|
9699ffb1af | ||
|
|
fdc9b9413b | ||
|
|
40ceddb48a | ||
|
|
7aa69117e1 | ||
|
|
bff7ad67bb | ||
|
|
c2334baa48 | ||
|
|
fb2b6c7c6f | ||
|
|
f5cbe19b75 | ||
|
|
b34fa11a13 | ||
|
|
320984c5f5 | ||
|
|
4365a51237 | ||
|
|
858e6c78a4 |
9
.github/ISSUE_TEMPLATE.md
vendored
Normal file
9
.github/ISSUE_TEMPLATE.md
vendored
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
- Bug report or feature request? <!-- Note: sub-optimal but correct code is not a bug -->
|
||||||
|
- `uglify-js` version (`uglifyjs -V`)
|
||||||
|
- JavaScript input - ideally as small as possible.
|
||||||
|
- The `uglifyjs` CLI command executed or `minify()` options used.
|
||||||
|
- An example of JavaScript output produced and/or the error or warning.
|
||||||
|
<!--
|
||||||
|
Note: the release version of uglify-js only supports ES5. Those wishing
|
||||||
|
to minify ES6 should use the experimental harmony branch.
|
||||||
|
-->
|
||||||
@@ -1,10 +1,12 @@
|
|||||||
language: node_js
|
language: node_js
|
||||||
before_install: "npm install -g npm"
|
before_install: "npm install -g npm"
|
||||||
node_js:
|
node_js:
|
||||||
- "0.12"
|
|
||||||
- "0.10"
|
- "0.10"
|
||||||
|
- "0.12"
|
||||||
- "4"
|
- "4"
|
||||||
- "6"
|
- "6"
|
||||||
|
env:
|
||||||
|
- UGLIFYJS_TEST_ALL=1
|
||||||
matrix:
|
matrix:
|
||||||
fast_finish: true
|
fast_finish: true
|
||||||
sudo: false
|
sudo: false
|
||||||
|
|||||||
34
README.md
34
README.md
@@ -10,8 +10,10 @@ There's also an
|
|||||||
[in-browser online demo](http://lisperator.net/uglifyjs/#demo) (for Firefox,
|
[in-browser online demo](http://lisperator.net/uglifyjs/#demo) (for Firefox,
|
||||||
Chrome and probably Safari).
|
Chrome and probably Safari).
|
||||||
|
|
||||||
Note: release versions of `uglify-js` only support ECMAScript 5 (ES5). If you wish to minify
|
#### Note:
|
||||||
|
- release versions of `uglify-js` only support ECMAScript 5 (ES5). If you wish to minify
|
||||||
ES2015+ (ES6+) code then please use the [harmony](#harmony) development branch.
|
ES2015+ (ES6+) code then please use the [harmony](#harmony) development branch.
|
||||||
|
- Node 7 has a known performance regression and runs `uglify-js` twice as slow.
|
||||||
|
|
||||||
Install
|
Install
|
||||||
-------
|
-------
|
||||||
@@ -68,15 +70,14 @@ The available options are:
|
|||||||
--source-map-inline Write base64-encoded source map to the end of js output.
|
--source-map-inline Write base64-encoded source map to the end of js output.
|
||||||
--in-source-map Input source map, useful if you're compressing
|
--in-source-map Input source map, useful if you're compressing
|
||||||
JS that was generated from some other original
|
JS that was generated from some other original
|
||||||
code.
|
code. Specify "inline" if the source map is included
|
||||||
|
inline with the sources.
|
||||||
--screw-ie8 Use this flag if you don't wish to support
|
--screw-ie8 Use this flag if you don't wish to support
|
||||||
Internet Explorer 6/7/8.
|
Internet Explorer 6/7/8.
|
||||||
By default UglifyJS will not try to be IE-proof.
|
By default UglifyJS will not try to be IE-proof.
|
||||||
--support-ie8 Use this flag to support Internet Explorer 6/7/8.
|
--support-ie8 Use this flag to support Internet Explorer 6/7/8.
|
||||||
Equivalent to setting `screw_ie8: false` in `minify()`
|
Equivalent to setting `screw_ie8: false` in `minify()`
|
||||||
for `compress`, `mangle` and `output` options.
|
for `compress`, `mangle` and `output` options.
|
||||||
Note: `--support-ie8` may generate incorrect code
|
|
||||||
for `try`/`catch` in ES5 compliant browsers.
|
|
||||||
--expr Parse a single expression, rather than a
|
--expr Parse a single expression, rather than a
|
||||||
program (for parsing JSON)
|
program (for parsing JSON)
|
||||||
-p, --prefix Skip prefix for original filenames that appear
|
-p, --prefix Skip prefix for original filenames that appear
|
||||||
@@ -202,9 +203,10 @@ compressed JS by mapping every token in the compiled JS to its original
|
|||||||
location.
|
location.
|
||||||
|
|
||||||
To use this feature you need to pass `--in-source-map
|
To use this feature you need to pass `--in-source-map
|
||||||
/path/to/input/source.map`. Normally the input source map should also point
|
/path/to/input/source.map` or `--in-source-map inline` if the source map is
|
||||||
to the file containing the generated JS, so if that's correct you can omit
|
included inline with the sources. Normally the input source map should also
|
||||||
input files from the command line.
|
point to the file containing the generated JS, so if that's correct you can
|
||||||
|
omit input files from the command line.
|
||||||
|
|
||||||
## Mangler options
|
## Mangler options
|
||||||
|
|
||||||
@@ -350,6 +352,9 @@ to set `true`; it's effectively a shortcut for `foo=true`).
|
|||||||
comparison are switching. Compression only works if both `comparisons` and
|
comparison are switching. Compression only works if both `comparisons` and
|
||||||
`unsafe_comps` are both set to true.
|
`unsafe_comps` are both set to true.
|
||||||
|
|
||||||
|
- `unsafe_math` (default: false) -- optimize numerical expressions like
|
||||||
|
`2 * x * 3` into `6 * x`, which may give imprecise floating point results.
|
||||||
|
|
||||||
- `unsafe_proto` (default: false) -- optimize expressions like
|
- `unsafe_proto` (default: false) -- optimize expressions like
|
||||||
`Array.prototype.slice.call(a)` into `[].slice.call(a)`
|
`Array.prototype.slice.call(a)` into `[].slice.call(a)`
|
||||||
|
|
||||||
@@ -390,11 +395,11 @@ to set `true`; it's effectively a shortcut for `foo=true`).
|
|||||||
- `cascade` -- small optimization for sequences, transform `x, x` into `x`
|
- `cascade` -- small optimization for sequences, transform `x, x` into `x`
|
||||||
and `x = something(), x` into `x = something()`
|
and `x = something(), x` into `x = something()`
|
||||||
|
|
||||||
- `collapse_vars` -- default `false`. Collapse single-use `var` and `const`
|
- `collapse_vars` -- Collapse single-use `var` and `const` definitions
|
||||||
definitions when possible.
|
when possible.
|
||||||
|
|
||||||
- `reduce_vars` -- default `false`. Improve optimization on variables assigned
|
- `reduce_vars` -- Improve optimization on variables assigned with and
|
||||||
with and used as constant values.
|
used as constant values.
|
||||||
|
|
||||||
- `warnings` -- display warnings when dropping unreachable code or unused
|
- `warnings` -- display warnings when dropping unreachable code or unused
|
||||||
declarations etc.
|
declarations etc.
|
||||||
@@ -423,6 +428,9 @@ to set `true`; it's effectively a shortcut for `foo=true`).
|
|||||||
such as `console.info` and/or retain side effects from function arguments
|
such as `console.info` and/or retain side effects from function arguments
|
||||||
after dropping the function call then use `pure_funcs` instead.
|
after dropping the function call then use `pure_funcs` instead.
|
||||||
|
|
||||||
|
- `expression` -- default `false`. Pass `true` to preserve completion values
|
||||||
|
from terminal statements without `return`, e.g. in bookmarklets.
|
||||||
|
|
||||||
- `keep_fargs` -- default `true`. Prevents the
|
- `keep_fargs` -- default `true`. Prevents the
|
||||||
compressor from discarding unused function arguments. You need this
|
compressor from discarding unused function arguments. You need this
|
||||||
for code which relies on `Function.length`.
|
for code which relies on `Function.length`.
|
||||||
@@ -621,7 +629,7 @@ function uglify(ast, options, mangle) {
|
|||||||
|
|
||||||
// Compression
|
// Compression
|
||||||
uAST.figure_out_scope();
|
uAST.figure_out_scope();
|
||||||
uAST = uAST.transform(UglifyJS.Compressor(options));
|
uAST = UglifyJS.Compressor(options).compress(uAST);
|
||||||
|
|
||||||
// Mangling (optional)
|
// Mangling (optional)
|
||||||
if (mangle) {
|
if (mangle) {
|
||||||
@@ -865,7 +873,7 @@ toplevel.figure_out_scope()
|
|||||||
Like this:
|
Like this:
|
||||||
```javascript
|
```javascript
|
||||||
var compressor = UglifyJS.Compressor(options);
|
var compressor = UglifyJS.Compressor(options);
|
||||||
var compressed_ast = toplevel.transform(compressor);
|
var compressed_ast = compressor.compress(toplevel);
|
||||||
```
|
```
|
||||||
|
|
||||||
The `options` can be missing. Available options are discussed above in
|
The `options` can be missing. Available options are discussed above in
|
||||||
|
|||||||
16
bin/uglifyjs
16
bin/uglifyjs
@@ -8,7 +8,6 @@ var sys = require("util");
|
|||||||
var yargs = require("yargs");
|
var yargs = require("yargs");
|
||||||
var fs = require("fs");
|
var fs = require("fs");
|
||||||
var path = require("path");
|
var path = require("path");
|
||||||
var async = require("async");
|
|
||||||
var acorn;
|
var acorn;
|
||||||
var screw_ie8 = true;
|
var screw_ie8 = true;
|
||||||
var ARGS = yargs
|
var ARGS = yargs
|
||||||
@@ -27,7 +26,7 @@ mangling you need to use `-c` and `-m`.\
|
|||||||
.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("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", "Do not support Internet Explorer 6/7/8. This flag is enabled by default.")
|
.describe("screw-ie8", "Do not support Internet Explorer 6/7/8. This flag is enabled by default.")
|
||||||
.describe("support-ie8", "Support non-standard Internet Explorer 6/7/8 javascript. Note: may generate incorrect code for try/catch in ES5 compliant browsers.")
|
.describe("support-ie8", "Support non-standard Internet Explorer 6/7/8 javascript.")
|
||||||
.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)")
|
||||||
.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. \
|
||||||
@@ -319,8 +318,11 @@ var STATS = {};
|
|||||||
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 SOURCES_CONTENT = {};
|
||||||
|
var index = 0;
|
||||||
|
|
||||||
async.eachLimit(files, 1, function (file, cb) {
|
!function cb() {
|
||||||
|
if (index == files.length) return done();
|
||||||
|
var file = files[index++];
|
||||||
read_whole_file(file, function (err, code) {
|
read_whole_file(file, function (err, code) {
|
||||||
if (err) {
|
if (err) {
|
||||||
print_error("ERROR: can't read file: " + file);
|
print_error("ERROR: can't read file: " + file);
|
||||||
@@ -388,7 +390,9 @@ async.eachLimit(files, 1, function (file, cb) {
|
|||||||
});
|
});
|
||||||
cb();
|
cb();
|
||||||
});
|
});
|
||||||
}, function () {
|
}();
|
||||||
|
|
||||||
|
function done() {
|
||||||
var OUTPUT_FILE = ARGS.o;
|
var OUTPUT_FILE = ARGS.o;
|
||||||
|
|
||||||
var SOURCE_MAP = (ARGS.source_map || ARGS.source_map_inline) ? UglifyJS.SourceMap({
|
var SOURCE_MAP = (ARGS.source_map || ARGS.source_map_inline) ? UglifyJS.SourceMap({
|
||||||
@@ -537,7 +541,7 @@ async.eachLimit(files, 1, function (file, cb) {
|
|||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
}
|
||||||
|
|
||||||
/* -----[ functions ]----- */
|
/* -----[ functions ]----- */
|
||||||
|
|
||||||
@@ -557,7 +561,7 @@ function getOptions(flag, constants) {
|
|||||||
|
|
||||||
var ast;
|
var ast;
|
||||||
try {
|
try {
|
||||||
ast = UglifyJS.parse(x, { expression: true });
|
ast = UglifyJS.parse(x, { cli: true, expression: true });
|
||||||
} catch(ex) {
|
} catch(ex) {
|
||||||
if (ex instanceof UglifyJS.JS_Parse_Error) {
|
if (ex instanceof UglifyJS.JS_Parse_Error) {
|
||||||
print_error("Error parsing arguments for flag `" + flag + "': " + x);
|
print_error("Error parsing arguments for flag `" + flag + "': " + x);
|
||||||
|
|||||||
36
lib/ast.js
36
lib/ast.js
@@ -91,9 +91,20 @@ var AST_Token = DEFNODE("Token", "type value line col pos endline endcol endpos
|
|||||||
}, null);
|
}, null);
|
||||||
|
|
||||||
var AST_Node = DEFNODE("Node", "start end", {
|
var AST_Node = DEFNODE("Node", "start end", {
|
||||||
clone: function() {
|
_clone: function(deep) {
|
||||||
|
if (deep) {
|
||||||
|
var self = this.clone();
|
||||||
|
return self.transform(new TreeTransformer(function(node) {
|
||||||
|
if (node !== self) {
|
||||||
|
return node.clone(true);
|
||||||
|
}
|
||||||
|
}));
|
||||||
|
}
|
||||||
return new this.CTOR(this);
|
return new this.CTOR(this);
|
||||||
},
|
},
|
||||||
|
clone: function(deep) {
|
||||||
|
return this._clone(deep);
|
||||||
|
},
|
||||||
$documentation: "Base class of all AST nodes",
|
$documentation: "Base class of all AST nodes",
|
||||||
$propdoc: {
|
$propdoc: {
|
||||||
start: "[AST_Token] The first token of this node",
|
start: "[AST_Token] The first token of this node",
|
||||||
@@ -199,6 +210,20 @@ var AST_LabeledStatement = DEFNODE("LabeledStatement", "label", {
|
|||||||
this.label._walk(visitor);
|
this.label._walk(visitor);
|
||||||
this.body._walk(visitor);
|
this.body._walk(visitor);
|
||||||
});
|
});
|
||||||
|
},
|
||||||
|
clone: function(deep) {
|
||||||
|
var node = this._clone(deep);
|
||||||
|
if (deep) {
|
||||||
|
var refs = node.label.references;
|
||||||
|
var label = this.label;
|
||||||
|
node.walk(new TreeWalker(function(node) {
|
||||||
|
if (node instanceof AST_LoopControl
|
||||||
|
&& node.label && node.label.thedef === label) {
|
||||||
|
refs.push(node);
|
||||||
|
}
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
return node;
|
||||||
}
|
}
|
||||||
}, AST_StatementWithBody);
|
}, AST_StatementWithBody);
|
||||||
|
|
||||||
@@ -812,9 +837,6 @@ var AST_SymbolAccessor = DEFNODE("SymbolAccessor", null, {
|
|||||||
|
|
||||||
var AST_SymbolDeclaration = DEFNODE("SymbolDeclaration", "init", {
|
var AST_SymbolDeclaration = DEFNODE("SymbolDeclaration", "init", {
|
||||||
$documentation: "A declaration symbol (symbol in var/const, function name or argument, symbol in catch)",
|
$documentation: "A declaration symbol (symbol in var/const, function name or argument, symbol in catch)",
|
||||||
$propdoc: {
|
|
||||||
init: "[AST_Node*/S] array of initializers for this declaration."
|
|
||||||
}
|
|
||||||
}, AST_Symbol);
|
}, AST_Symbol);
|
||||||
|
|
||||||
var AST_SymbolVar = DEFNODE("SymbolVar", null, {
|
var AST_SymbolVar = DEFNODE("SymbolVar", null, {
|
||||||
@@ -962,8 +984,8 @@ TreeWalker.prototype = {
|
|||||||
push: function (node) {
|
push: function (node) {
|
||||||
if (node instanceof AST_Lambda) {
|
if (node instanceof AST_Lambda) {
|
||||||
this.directives = Object.create(this.directives);
|
this.directives = Object.create(this.directives);
|
||||||
} else if (node instanceof AST_Directive) {
|
} else if (node instanceof AST_Directive && !this.directives[node.value]) {
|
||||||
this.directives[node.value] = this.directives[node.value] ? "up" : true;
|
this.directives[node.value] = node;
|
||||||
}
|
}
|
||||||
this.stack.push(node);
|
this.stack.push(node);
|
||||||
},
|
},
|
||||||
@@ -991,7 +1013,7 @@ TreeWalker.prototype = {
|
|||||||
for (var i = 0; i < node.body.length; ++i) {
|
for (var i = 0; i < node.body.length; ++i) {
|
||||||
var st = node.body[i];
|
var st = node.body[i];
|
||||||
if (!(st instanceof AST_Directive)) break;
|
if (!(st instanceof AST_Directive)) break;
|
||||||
if (st.value == type) return true;
|
if (st.value == type) return st;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|||||||
1502
lib/compress.js
1502
lib/compress.js
File diff suppressed because it is too large
Load Diff
@@ -46,17 +46,8 @@
|
|||||||
var EXPECT_DIRECTIVE = /^$|[;{][\s\n]*$/;
|
var EXPECT_DIRECTIVE = /^$|[;{][\s\n]*$/;
|
||||||
|
|
||||||
function is_some_comments(comment) {
|
function is_some_comments(comment) {
|
||||||
var text = comment.value;
|
// multiline comment
|
||||||
var type = comment.type;
|
return comment.type == "comment2" && /@preserve|@license|@cc_on/i.test(comment.value);
|
||||||
if (type == "comment2") {
|
|
||||||
// multiline comment
|
|
||||||
return /@preserve|@license|@cc_on/i.test(text);
|
|
||||||
}
|
|
||||||
return type == "comment5";
|
|
||||||
}
|
|
||||||
|
|
||||||
function is_comment5(comment) {
|
|
||||||
return comment.type == "comment5";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function OutputStream(options) {
|
function OutputStream(options) {
|
||||||
@@ -86,7 +77,7 @@ function OutputStream(options) {
|
|||||||
}, true);
|
}, true);
|
||||||
|
|
||||||
// Convert comment option to RegExp if neccessary and set up comments filter
|
// Convert comment option to RegExp if neccessary and set up comments filter
|
||||||
var comment_filter = options.shebang ? is_comment5 : return_false; // Default case, throw all comments away except shebangs
|
var comment_filter = return_false; // Default case, throw all comments away
|
||||||
if (options.comments) {
|
if (options.comments) {
|
||||||
var comments = options.comments;
|
var comments = options.comments;
|
||||||
if (typeof options.comments === "string" && /^\/.*\/[a-zA-Z]*$/.test(options.comments)) {
|
if (typeof options.comments === "string" && /^\/.*\/[a-zA-Z]*$/.test(options.comments)) {
|
||||||
@@ -98,12 +89,12 @@ function OutputStream(options) {
|
|||||||
}
|
}
|
||||||
if (comments instanceof RegExp) {
|
if (comments instanceof RegExp) {
|
||||||
comment_filter = function(comment) {
|
comment_filter = function(comment) {
|
||||||
return comment.type == "comment5" || comments.test(comment.value);
|
return comment.type != "comment5" && comments.test(comment.value);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
else if (typeof comments === "function") {
|
else if (typeof comments === "function") {
|
||||||
comment_filter = function(comment) {
|
comment_filter = function(comment) {
|
||||||
return comment.type == "comment5" || comments(this, comment);
|
return comment.type != "comment5" && comments(this, comment);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
else if (comments === "some") {
|
else if (comments === "some") {
|
||||||
@@ -400,10 +391,6 @@ 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,
|
||||||
@@ -523,6 +510,17 @@ function OutputStream(options) {
|
|||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (comments.length > 0 && output.pos() == 0) {
|
||||||
|
if (output.option("shebang") && comments[0].type == "comment5") {
|
||||||
|
output.print("#!" + comments.shift().value + "\n");
|
||||||
|
output.indent();
|
||||||
|
}
|
||||||
|
var preamble = output.option("preamble");
|
||||||
|
if (preamble) {
|
||||||
|
output.print(preamble.replace(/\r\n?|[\n\u2028\u2029]|\s*$/g, "\n"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
comments = comments.filter(output.comment_filter, self);
|
comments = comments.filter(output.comment_filter, self);
|
||||||
|
|
||||||
// Keep single line comments after nlb, after nlb
|
// Keep single line comments after nlb, after nlb
|
||||||
@@ -547,10 +545,6 @@ function OutputStream(options) {
|
|||||||
output.space();
|
output.space();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (output.pos() === 0 && c.type == "comment5" && output.option("shebang")) {
|
|
||||||
output.print("#!" + c.value + "\n");
|
|
||||||
output.indent();
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -783,7 +777,7 @@ function OutputStream(options) {
|
|||||||
DEFPRINT(AST_Do, function(self, output){
|
DEFPRINT(AST_Do, function(self, output){
|
||||||
output.print("do");
|
output.print("do");
|
||||||
output.space();
|
output.space();
|
||||||
self._do_print_body(output);
|
make_block(self.body, output);
|
||||||
output.space();
|
output.space();
|
||||||
output.print("while");
|
output.print("while");
|
||||||
output.space();
|
output.space();
|
||||||
@@ -805,7 +799,7 @@ function OutputStream(options) {
|
|||||||
output.print("for");
|
output.print("for");
|
||||||
output.space();
|
output.space();
|
||||||
output.with_parens(function(){
|
output.with_parens(function(){
|
||||||
if (self.init && !(self.init instanceof AST_EmptyStatement)) {
|
if (self.init) {
|
||||||
if (self.init instanceof AST_Definitions) {
|
if (self.init instanceof AST_Definitions) {
|
||||||
self.init.print(output);
|
self.init.print(output);
|
||||||
} else {
|
} else {
|
||||||
@@ -910,10 +904,10 @@ function OutputStream(options) {
|
|||||||
|
|
||||||
/* -----[ if ]----- */
|
/* -----[ if ]----- */
|
||||||
function make_then(self, output) {
|
function make_then(self, output) {
|
||||||
if (output.option("bracketize")) {
|
var b = self.body;
|
||||||
make_block(self.body, output);
|
if (output.option("bracketize")
|
||||||
return;
|
|| !output.option("screw_ie8") && b instanceof AST_Do)
|
||||||
}
|
return make_block(b, output);
|
||||||
// The squeezer replaces "block"-s that contain only a single
|
// The squeezer replaces "block"-s that contain only a single
|
||||||
// statement with the statement itself; technically, the AST
|
// statement with the statement itself; technically, the AST
|
||||||
// is correct, but this can create problems when we output an
|
// is correct, but this can create problems when we output an
|
||||||
@@ -921,18 +915,7 @@ function OutputStream(options) {
|
|||||||
// IF *without* an ELSE block (then the outer ELSE would refer
|
// IF *without* an ELSE block (then the outer ELSE would refer
|
||||||
// to the inner IF). This function checks for this case and
|
// to the inner IF). This function checks for this case and
|
||||||
// adds the block brackets if needed.
|
// adds the block brackets if needed.
|
||||||
if (!self.body)
|
if (!b) return output.force_semicolon();
|
||||||
return output.force_semicolon();
|
|
||||||
if (self.body instanceof AST_Do) {
|
|
||||||
// Unconditionally use the if/do-while workaround for all browsers.
|
|
||||||
// https://github.com/mishoo/UglifyJS/issues/#issue/57 IE
|
|
||||||
// croaks with "syntax error" on code like this: if (foo)
|
|
||||||
// do ... while(cond); else ... we need block brackets
|
|
||||||
// around do/while
|
|
||||||
make_block(self.body, output);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
var b = self.body;
|
|
||||||
while (true) {
|
while (true) {
|
||||||
if (b instanceof AST_If) {
|
if (b instanceof AST_If) {
|
||||||
if (!b.alternative) {
|
if (!b.alternative) {
|
||||||
@@ -1341,15 +1324,7 @@ function OutputStream(options) {
|
|||||||
|
|
||||||
function force_statement(stat, output) {
|
function force_statement(stat, output) {
|
||||||
if (output.option("bracketize")) {
|
if (output.option("bracketize")) {
|
||||||
if (!stat || stat instanceof AST_EmptyStatement)
|
make_block(stat, output);
|
||||||
output.print("{}");
|
|
||||||
else if (stat instanceof AST_BlockStatement)
|
|
||||||
stat.print(output);
|
|
||||||
else output.with_block(function(){
|
|
||||||
output.indent();
|
|
||||||
stat.print(output);
|
|
||||||
output.newline();
|
|
||||||
});
|
|
||||||
} else {
|
} else {
|
||||||
if (!stat || stat instanceof AST_EmptyStatement)
|
if (!stat || stat instanceof AST_EmptyStatement)
|
||||||
output.force_semicolon();
|
output.force_semicolon();
|
||||||
@@ -1398,11 +1373,11 @@ function OutputStream(options) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
function make_block(stmt, output) {
|
function make_block(stmt, output) {
|
||||||
if (stmt instanceof AST_BlockStatement) {
|
if (!stmt || stmt instanceof AST_EmptyStatement)
|
||||||
|
output.print("{}");
|
||||||
|
else if (stmt instanceof AST_BlockStatement)
|
||||||
stmt.print(output);
|
stmt.print(output);
|
||||||
return;
|
else output.with_block(function(){
|
||||||
}
|
|
||||||
output.with_block(function(){
|
|
||||||
output.indent();
|
output.indent();
|
||||||
stmt.print(output);
|
stmt.print(output);
|
||||||
output.newline();
|
output.newline();
|
||||||
|
|||||||
24
lib/parse.js
24
lib/parse.js
@@ -558,6 +558,11 @@ function tokenizer($TEXT, filename, html5_comments, shebang) {
|
|||||||
function next_token(force_regexp) {
|
function next_token(force_regexp) {
|
||||||
if (force_regexp != null)
|
if (force_regexp != null)
|
||||||
return read_regexp(force_regexp);
|
return read_regexp(force_regexp);
|
||||||
|
if (shebang && S.pos == 0 && looking_at("#!")) {
|
||||||
|
start_token();
|
||||||
|
forward(2);
|
||||||
|
skip_line_comment("comment5");
|
||||||
|
}
|
||||||
for (;;) {
|
for (;;) {
|
||||||
skip_whitespace();
|
skip_whitespace();
|
||||||
start_token();
|
start_token();
|
||||||
@@ -589,13 +594,6 @@ function tokenizer($TEXT, filename, html5_comments, shebang) {
|
|||||||
if (PUNC_CHARS(ch)) return token("punc", next());
|
if (PUNC_CHARS(ch)) return token("punc", next());
|
||||||
if (OPERATOR_CHARS(ch)) return read_operator();
|
if (OPERATOR_CHARS(ch)) return read_operator();
|
||||||
if (code == 92 || is_identifier_start(code)) return read_word();
|
if (code == 92 || is_identifier_start(code)) return read_word();
|
||||||
if (shebang) {
|
|
||||||
if (S.pos == 0 && looking_at("#!")) {
|
|
||||||
forward(2);
|
|
||||||
skip_line_comment("comment5");
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
parse_error("Unexpected character '" + ch + "'");
|
parse_error("Unexpected character '" + ch + "'");
|
||||||
@@ -697,6 +695,7 @@ function parse($TEXT, options) {
|
|||||||
html5_comments : true,
|
html5_comments : true,
|
||||||
bare_returns : false,
|
bare_returns : false,
|
||||||
shebang : true,
|
shebang : true,
|
||||||
|
cli : false,
|
||||||
});
|
});
|
||||||
|
|
||||||
var S = {
|
var S = {
|
||||||
@@ -930,11 +929,9 @@ function parse($TEXT, options) {
|
|||||||
expression : parenthesised(),
|
expression : parenthesised(),
|
||||||
body : statement()
|
body : statement()
|
||||||
});
|
});
|
||||||
|
|
||||||
default:
|
|
||||||
unexpected();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
unexpected();
|
||||||
});
|
});
|
||||||
|
|
||||||
function labeled_statement() {
|
function labeled_statement() {
|
||||||
@@ -1460,7 +1457,7 @@ function parse($TEXT, options) {
|
|||||||
|
|
||||||
function make_unary(ctor, op, expr) {
|
function make_unary(ctor, op, expr) {
|
||||||
if ((op == "++" || op == "--") && !is_assignable(expr))
|
if ((op == "++" || op == "--") && !is_assignable(expr))
|
||||||
croak("Invalid use of " + op + " operator");
|
croak("Invalid use of " + op + " operator", null, ctor === AST_UnaryPrefix ? expr.start.col - 1 : null);
|
||||||
return new ctor({ operator: op, expression: expr });
|
return new ctor({ operator: op, expression: expr });
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -1505,9 +1502,8 @@ function parse($TEXT, options) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
function is_assignable(expr) {
|
function is_assignable(expr) {
|
||||||
if (!options.strict) return true;
|
if (options.cli) return true;
|
||||||
if (expr instanceof AST_This) return false;
|
return expr instanceof AST_PropAccess || expr instanceof AST_SymbolRef;
|
||||||
return (expr instanceof AST_PropAccess || expr instanceof AST_Symbol);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
var maybe_assign = function(no_in) {
|
var maybe_assign = function(no_in) {
|
||||||
|
|||||||
87
lib/scope.js
87
lib/scope.js
@@ -75,9 +75,16 @@ SymbolDef.prototype = {
|
|||||||
}
|
}
|
||||||
else if (!this.mangled_name && !this.unmangleable(options)) {
|
else if (!this.mangled_name && !this.unmangleable(options)) {
|
||||||
var s = this.scope;
|
var s = this.scope;
|
||||||
if (!options.screw_ie8 && this.orig[0] instanceof AST_SymbolLambda)
|
var sym = this.orig[0];
|
||||||
|
if (!options.screw_ie8 && sym instanceof AST_SymbolLambda)
|
||||||
s = s.parent_scope;
|
s = s.parent_scope;
|
||||||
this.mangled_name = s.next_mangled(options, this);
|
var def;
|
||||||
|
if (options.screw_ie8
|
||||||
|
&& sym instanceof AST_SymbolCatch
|
||||||
|
&& (def = s.parent_scope.find_variable(sym))) {
|
||||||
|
this.mangled_name = def.mangled_name || def.name;
|
||||||
|
} else
|
||||||
|
this.mangled_name = s.next_mangled(options, this);
|
||||||
if (this.global && cache) {
|
if (this.global && cache) {
|
||||||
cache.set(this.name, this.mangled_name);
|
cache.set(this.name, this.mangled_name);
|
||||||
}
|
}
|
||||||
@@ -97,18 +104,17 @@ AST_Toplevel.DEFMETHOD("figure_out_scope", function(options){
|
|||||||
var labels = new Dictionary();
|
var labels = new Dictionary();
|
||||||
var defun = null;
|
var defun = null;
|
||||||
var tw = new TreeWalker(function(node, descend){
|
var tw = new TreeWalker(function(node, descend){
|
||||||
if (options.screw_ie8 && node instanceof AST_Catch) {
|
if (node instanceof AST_Catch) {
|
||||||
var save_scope = scope;
|
var save_scope = scope;
|
||||||
scope = new AST_Scope(node);
|
scope = new AST_Scope(node);
|
||||||
scope.init_scope_vars();
|
scope.init_scope_vars(save_scope);
|
||||||
scope.parent_scope = save_scope;
|
|
||||||
descend();
|
descend();
|
||||||
scope = save_scope;
|
scope = save_scope;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (node instanceof AST_Scope) {
|
if (node instanceof AST_Scope) {
|
||||||
node.init_scope_vars();
|
node.init_scope_vars(scope);
|
||||||
var save_scope = node.parent_scope = scope;
|
var save_scope = scope;
|
||||||
var save_defun = defun;
|
var save_defun = defun;
|
||||||
var save_labels = labels;
|
var save_labels = labels;
|
||||||
defun = scope = node;
|
defun = scope = node;
|
||||||
@@ -153,13 +159,19 @@ AST_Toplevel.DEFMETHOD("figure_out_scope", function(options){
|
|||||||
(node.scope = defun.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 = defun.def_variable(node);
|
defun.def_variable(node);
|
||||||
def.init = tw.parent().value;
|
if (defun !== scope) {
|
||||||
|
node.mark_enclosed(options);
|
||||||
|
var def = scope.find_variable(node);
|
||||||
|
if (node.thedef !== def) {
|
||||||
|
node.thedef = def;
|
||||||
|
node.reference(options);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else if (node instanceof AST_SymbolCatch) {
|
else if (node instanceof AST_SymbolCatch) {
|
||||||
(options.screw_ie8 ? scope : defun)
|
scope.def_variable(node);
|
||||||
.def_variable(node);
|
|
||||||
}
|
}
|
||||||
else if (node instanceof AST_LabelRef) {
|
else if (node instanceof AST_LabelRef) {
|
||||||
var sym = labels.get(node.name);
|
var sym = labels.get(node.name);
|
||||||
@@ -209,6 +221,24 @@ AST_Toplevel.DEFMETHOD("figure_out_scope", function(options){
|
|||||||
});
|
});
|
||||||
self.walk(tw);
|
self.walk(tw);
|
||||||
|
|
||||||
|
// pass 3: fix up any scoping issue with IE8
|
||||||
|
if (!options.screw_ie8) {
|
||||||
|
self.walk(new TreeWalker(function(node, descend) {
|
||||||
|
if (node instanceof AST_SymbolCatch) {
|
||||||
|
var name = node.name;
|
||||||
|
var refs = node.thedef.references;
|
||||||
|
var scope = node.thedef.scope.parent_scope;
|
||||||
|
var def = scope.find_variable(name) || self.globals.get(name) || scope.def_variable(node);
|
||||||
|
refs.forEach(function(ref) {
|
||||||
|
ref.thedef = def;
|
||||||
|
ref.reference(options);
|
||||||
|
});
|
||||||
|
node.thedef = def;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
|
||||||
if (options.cache) {
|
if (options.cache) {
|
||||||
this.cname = options.cache.cname;
|
this.cname = options.cache.cname;
|
||||||
}
|
}
|
||||||
@@ -227,28 +257,28 @@ AST_Toplevel.DEFMETHOD("def_global", function(node){
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
AST_Scope.DEFMETHOD("init_scope_vars", function(){
|
AST_Scope.DEFMETHOD("init_scope_vars", function(parent_scope){
|
||||||
this.variables = new Dictionary(); // map name to AST_SymbolVar (variables defined in this scope; includes functions)
|
this.variables = new Dictionary(); // map name to AST_SymbolVar (variables defined in this scope; includes functions)
|
||||||
this.functions = new Dictionary(); // map name to AST_SymbolDefun (functions defined in this scope)
|
this.functions = new Dictionary(); // map name to AST_SymbolDefun (functions defined in this scope)
|
||||||
this.uses_with = false; // will be set to true if this or some nested scope uses the `with` statement
|
this.uses_with = false; // will be set to true if this or some nested scope uses the `with` statement
|
||||||
this.uses_eval = false; // will be set to true if this or nested scope uses the global `eval`
|
this.uses_eval = false; // will be set to true if this or nested scope uses the global `eval`
|
||||||
this.parent_scope = null; // the parent scope
|
this.parent_scope = parent_scope; // the parent scope
|
||||||
this.enclosed = []; // a list of variables from this or outer scope(s) that are referenced from this or inner scopes
|
this.enclosed = []; // a list of variables from this or outer scope(s) that are referenced from this or inner scopes
|
||||||
this.cname = -1; // the current index for mangling functions/variables
|
this.cname = -1; // the current index for mangling functions/variables
|
||||||
});
|
});
|
||||||
|
|
||||||
AST_Lambda.DEFMETHOD("init_scope_vars", function(){
|
AST_Lambda.DEFMETHOD("init_scope_vars", function(){
|
||||||
AST_Scope.prototype.init_scope_vars.apply(this, arguments);
|
AST_Scope.prototype.init_scope_vars.apply(this, arguments);
|
||||||
this.uses_arguments = false;
|
this.uses_arguments = false;
|
||||||
|
this.def_variable(new AST_SymbolVar({
|
||||||
var symbol = new AST_VarDef({ name: "arguments", start: this.start, end: this.end });
|
name: "arguments",
|
||||||
var def = new SymbolDef(this, this.variables.size(), symbol);
|
start: this.start,
|
||||||
this.variables.set(symbol.name, def);
|
end: this.end
|
||||||
|
}));
|
||||||
});
|
});
|
||||||
|
|
||||||
AST_SymbolRef.DEFMETHOD("reference", function(options) {
|
AST_Symbol.DEFMETHOD("mark_enclosed", function(options) {
|
||||||
var def = this.definition();
|
var def = this.definition();
|
||||||
def.references.push(this);
|
|
||||||
var s = this.scope;
|
var s = this.scope;
|
||||||
while (s) {
|
while (s) {
|
||||||
push_uniq(s.enclosed, def);
|
push_uniq(s.enclosed, def);
|
||||||
@@ -262,6 +292,11 @@ AST_SymbolRef.DEFMETHOD("reference", function(options) {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
AST_Symbol.DEFMETHOD("reference", function(options) {
|
||||||
|
this.definition().references.push(this);
|
||||||
|
this.mark_enclosed(options);
|
||||||
|
});
|
||||||
|
|
||||||
AST_Scope.DEFMETHOD("find_variable", function(name){
|
AST_Scope.DEFMETHOD("find_variable", function(name){
|
||||||
if (name instanceof AST_Symbol) name = name.name;
|
if (name instanceof AST_Symbol) name = name.name;
|
||||||
return this.variables.get(name)
|
return this.variables.get(name)
|
||||||
|
|||||||
@@ -126,9 +126,11 @@ function merge(obj, ext) {
|
|||||||
return count;
|
return count;
|
||||||
};
|
};
|
||||||
|
|
||||||
function noop() {};
|
function noop() {}
|
||||||
function return_false() { return false; }
|
function return_false() { return false; }
|
||||||
function return_true() { return true; }
|
function return_true() { return true; }
|
||||||
|
function return_this() { return this; }
|
||||||
|
function return_null() { return null; }
|
||||||
|
|
||||||
var MAP = (function(){
|
var MAP = (function(){
|
||||||
function MAP(a, f, backwards) {
|
function MAP(a, f, backwards) {
|
||||||
@@ -185,7 +187,7 @@ function push_uniq(array, el) {
|
|||||||
|
|
||||||
function string_template(text, props) {
|
function string_template(text, props) {
|
||||||
return text.replace(/\{(.+?)\}/g, function(str, p){
|
return text.replace(/\{(.+?)\}/g, function(str, p){
|
||||||
return props[p];
|
return props && props[p];
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -4,7 +4,7 @@
|
|||||||
"homepage": "http://lisperator.net/uglifyjs",
|
"homepage": "http://lisperator.net/uglifyjs",
|
||||||
"author": "Mihai Bazon <mihai.bazon@gmail.com> (http://lisperator.net/)",
|
"author": "Mihai Bazon <mihai.bazon@gmail.com> (http://lisperator.net/)",
|
||||||
"license": "BSD-2-Clause",
|
"license": "BSD-2-Clause",
|
||||||
"version": "2.8.0",
|
"version": "2.8.18",
|
||||||
"engines": {
|
"engines": {
|
||||||
"node": ">=0.8.0"
|
"node": ">=0.8.0"
|
||||||
},
|
},
|
||||||
@@ -29,9 +29,7 @@
|
|||||||
"LICENSE"
|
"LICENSE"
|
||||||
],
|
],
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"async": "~0.2.6",
|
|
||||||
"source-map": "~0.5.1",
|
"source-map": "~0.5.1",
|
||||||
"uglify-to-browserify": "~1.0.0",
|
|
||||||
"yargs": "~3.10.0"
|
"yargs": "~3.10.0"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
@@ -41,13 +39,15 @@
|
|||||||
"estraverse": "~1.5.1",
|
"estraverse": "~1.5.1",
|
||||||
"mocha": "~2.3.4"
|
"mocha": "~2.3.4"
|
||||||
},
|
},
|
||||||
|
"optionalDependencies": {
|
||||||
|
"uglify-to-browserify": "~1.0.0"
|
||||||
|
},
|
||||||
"browserify": {
|
"browserify": {
|
||||||
"transform": [
|
"transform": [
|
||||||
"uglify-to-browserify"
|
"uglify-to-browserify"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"shrinkwrap": "rm ./npm-shrinkwrap.json; rm -rf ./node_modules; npm i && npm shrinkwrap && npm outdated",
|
|
||||||
"test": "node test/run-tests.js"
|
"test": "node test/run-tests.js"
|
||||||
},
|
},
|
||||||
"keywords": ["uglify", "uglify-js", "minify", "minifier"]
|
"keywords": ["uglify", "uglify-js", "minify", "minifier"]
|
||||||
|
|||||||
@@ -24,26 +24,57 @@ var results = {};
|
|||||||
var remaining = 2 * urls.length;
|
var remaining = 2 * urls.length;
|
||||||
function done() {
|
function done() {
|
||||||
if (!--remaining) {
|
if (!--remaining) {
|
||||||
|
var failures = [];
|
||||||
urls.forEach(function(url) {
|
urls.forEach(function(url) {
|
||||||
|
var info = results[url];
|
||||||
console.log();
|
console.log();
|
||||||
console.log(url);
|
console.log(url);
|
||||||
console.log(results[url].time);
|
console.log(info.log);
|
||||||
console.log("SHA1:", results[url].sha1);
|
var elapsed = 0;
|
||||||
|
info.log.replace(/: ([0-9]+\.[0-9]{3})s/g, function(match, time) {
|
||||||
|
elapsed += parseFloat(time);
|
||||||
|
});
|
||||||
|
console.log("Run-time:", elapsed.toFixed(3), "s");
|
||||||
|
console.log("Original:", info.input, "bytes");
|
||||||
|
console.log("Uglified:", info.output, "bytes");
|
||||||
|
console.log("SHA1 sum:", info.sha1);
|
||||||
|
if (info.code) {
|
||||||
|
failures.push(url);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
if (failures.length) {
|
||||||
|
console.error("Benchmark failed:");
|
||||||
|
failures.forEach(function(url) {
|
||||||
|
console.error(url);
|
||||||
|
});
|
||||||
|
process.exit(1);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
urls.forEach(function(url) {
|
urls.forEach(function(url) {
|
||||||
results[url] = { time: "" };
|
results[url] = {
|
||||||
|
input: 0,
|
||||||
|
output: 0,
|
||||||
|
log: ""
|
||||||
|
};
|
||||||
require(url.slice(0, url.indexOf(":"))).get(url, function(res) {
|
require(url.slice(0, url.indexOf(":"))).get(url, function(res) {
|
||||||
var uglifyjs = fork("bin/uglifyjs", args, { silent: true });
|
var uglifyjs = fork("bin/uglifyjs", args, { silent: true });
|
||||||
res.pipe(uglifyjs.stdin);
|
res.on("data", function(data) {
|
||||||
uglifyjs.stdout.pipe(createHash("sha1")).on("data", function(data) {
|
results[url].input += data.length;
|
||||||
|
}).pipe(uglifyjs.stdin);
|
||||||
|
uglifyjs.stdout.on("data", function(data) {
|
||||||
|
results[url].output += data.length;
|
||||||
|
}).pipe(createHash("sha1")).on("data", function(data) {
|
||||||
results[url].sha1 = data.toString("hex");
|
results[url].sha1 = data.toString("hex");
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
uglifyjs.stderr.setEncoding("utf8");
|
uglifyjs.stderr.setEncoding("utf8");
|
||||||
uglifyjs.stderr.on("data", function(data) {
|
uglifyjs.stderr.on("data", function(data) {
|
||||||
results[url].time += data;
|
results[url].log += data;
|
||||||
}).on("end", done)
|
});
|
||||||
|
uglifyjs.on("exit", function(code) {
|
||||||
|
results[url].code = code;
|
||||||
|
done();
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -43,6 +43,7 @@ collapse_vars_side_effects_1: {
|
|||||||
z = i += 4;
|
z = i += 4;
|
||||||
log(x, z, y, i);
|
log(x, z, y, i);
|
||||||
}
|
}
|
||||||
|
f1(), f2(), f3(), f4();
|
||||||
}
|
}
|
||||||
expect: {
|
expect: {
|
||||||
function f1() {
|
function f1() {
|
||||||
@@ -73,7 +74,9 @@ collapse_vars_side_effects_1: {
|
|||||||
y = i += 3;
|
y = i += 3;
|
||||||
log(x, i += 4, y, i);
|
log(x, i += 4, y, i);
|
||||||
}
|
}
|
||||||
|
f1(), f2(), f3(), f4();
|
||||||
}
|
}
|
||||||
|
expect_stdout: true
|
||||||
}
|
}
|
||||||
|
|
||||||
collapse_vars_side_effects_2: {
|
collapse_vars_side_effects_2: {
|
||||||
@@ -344,9 +347,9 @@ collapse_vars_do_while: {
|
|||||||
}
|
}
|
||||||
input: {
|
input: {
|
||||||
function f1(y) {
|
function f1(y) {
|
||||||
// The constant do-while condition `c` will be replaced.
|
// The constant do-while condition `c` will not be replaced.
|
||||||
var c = 9;
|
var c = 9;
|
||||||
do { } while (c === 77);
|
do {} while (c === 77);
|
||||||
}
|
}
|
||||||
function f2(y) {
|
function f2(y) {
|
||||||
// The non-constant do-while condition `c` will not be replaced.
|
// The non-constant do-while condition `c` will not be replaced.
|
||||||
@@ -381,7 +384,8 @@ collapse_vars_do_while: {
|
|||||||
}
|
}
|
||||||
expect: {
|
expect: {
|
||||||
function f1(y) {
|
function f1(y) {
|
||||||
do ; while (false);
|
var c = 9;
|
||||||
|
do ; while (77 === c);
|
||||||
}
|
}
|
||||||
function f2(y) {
|
function f2(y) {
|
||||||
var c = 5 - y;
|
var c = 5 - y;
|
||||||
@@ -418,9 +422,9 @@ collapse_vars_do_while_drop_assign: {
|
|||||||
}
|
}
|
||||||
input: {
|
input: {
|
||||||
function f1(y) {
|
function f1(y) {
|
||||||
// The constant do-while condition `c` will be replaced.
|
// The constant do-while condition `c` will be not replaced.
|
||||||
var c = 9;
|
var c = 9;
|
||||||
do { } while (c === 77);
|
do {} while (c === 77);
|
||||||
}
|
}
|
||||||
function f2(y) {
|
function f2(y) {
|
||||||
// The non-constant do-while condition `c` will not be replaced.
|
// The non-constant do-while condition `c` will not be replaced.
|
||||||
@@ -455,7 +459,8 @@ collapse_vars_do_while_drop_assign: {
|
|||||||
}
|
}
|
||||||
expect: {
|
expect: {
|
||||||
function f1(y) {
|
function f1(y) {
|
||||||
do ; while (false);
|
var c = 9;
|
||||||
|
do ; while (77 === c);
|
||||||
}
|
}
|
||||||
function f2(y) {
|
function f2(y) {
|
||||||
var c = 5 - y;
|
var c = 5 - y;
|
||||||
@@ -821,6 +826,7 @@ collapse_vars_repeated: {
|
|||||||
console.log(e + "!");
|
console.log(e + "!");
|
||||||
})("!");
|
})("!");
|
||||||
}
|
}
|
||||||
|
expect_stdout: true
|
||||||
}
|
}
|
||||||
|
|
||||||
collapse_vars_closures: {
|
collapse_vars_closures: {
|
||||||
@@ -888,7 +894,8 @@ collapse_vars_unary: {
|
|||||||
}
|
}
|
||||||
expect: {
|
expect: {
|
||||||
function f0(o, p) {
|
function f0(o, p) {
|
||||||
delete o[p];
|
var x = o[p];
|
||||||
|
delete x;
|
||||||
}
|
}
|
||||||
function f1(n) {
|
function f1(n) {
|
||||||
return n > +!!n
|
return n > +!!n
|
||||||
@@ -1107,6 +1114,7 @@ collapse_vars_eval_and_with: {
|
|||||||
return function() { with (o) console.log(a) };
|
return function() { with (o) console.log(a) };
|
||||||
})()();
|
})()();
|
||||||
}
|
}
|
||||||
|
expect_stdout: true
|
||||||
}
|
}
|
||||||
|
|
||||||
collapse_vars_constants: {
|
collapse_vars_constants: {
|
||||||
@@ -1141,7 +1149,7 @@ collapse_vars_constants: {
|
|||||||
function f3(x) {
|
function f3(x) {
|
||||||
var b = x.prop;
|
var b = x.prop;
|
||||||
sideeffect1();
|
sideeffect1();
|
||||||
return b + (function() { return -9; })();
|
return b + -9;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1150,7 +1158,8 @@ collapse_vars_arguments: {
|
|||||||
options = {
|
options = {
|
||||||
collapse_vars:true, sequences:true, properties:true, dead_code:true, conditionals:true,
|
collapse_vars:true, sequences:true, properties:true, dead_code:true, conditionals:true,
|
||||||
comparisons:true, evaluate:true, booleans:true, loops:true, unused:true, hoist_funs:true,
|
comparisons:true, evaluate:true, booleans:true, loops:true, unused:true, hoist_funs:true,
|
||||||
keep_fargs:true, if_return:true, join_vars:true, cascade:true, side_effects:true
|
keep_fargs:true, if_return:true, join_vars:true, cascade:true, side_effects:true,
|
||||||
|
toplevel:true
|
||||||
}
|
}
|
||||||
input: {
|
input: {
|
||||||
var outer = function() {
|
var outer = function() {
|
||||||
@@ -1165,6 +1174,7 @@ collapse_vars_arguments: {
|
|||||||
(function(){console.log(arguments);})(7, 1);
|
(function(){console.log(arguments);})(7, 1);
|
||||||
})();
|
})();
|
||||||
}
|
}
|
||||||
|
expect_stdout: true
|
||||||
}
|
}
|
||||||
|
|
||||||
collapse_vars_short_circuit: {
|
collapse_vars_short_circuit: {
|
||||||
@@ -1309,9 +1319,275 @@ collapse_vars_regexp: {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
(function(){
|
(function(){
|
||||||
var result, rx = /ab*/g;
|
var result, s = "acdabcdeabbb", rx = /ab*/g;
|
||||||
while (result = rx.exec('acdabcdeabbb'))
|
while (result = rx.exec(s))
|
||||||
console.log(result[0]);
|
console.log(result[0]);
|
||||||
})();
|
})();
|
||||||
}
|
}
|
||||||
|
expect_stdout: true
|
||||||
|
}
|
||||||
|
|
||||||
|
issue_1537: {
|
||||||
|
options = {
|
||||||
|
collapse_vars: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
var k = '';
|
||||||
|
for (k in {prop: 'val'}){}
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
var k = '';
|
||||||
|
for (k in {prop: 'val'});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
issue_1562: {
|
||||||
|
options = {
|
||||||
|
collapse_vars: true,
|
||||||
|
toplevel: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
var v = 1, B = 2;
|
||||||
|
for (v in objs) f(B);
|
||||||
|
|
||||||
|
var x = 3, C = 10;
|
||||||
|
while(x + 2) bar(C);
|
||||||
|
|
||||||
|
var y = 4, D = 20;
|
||||||
|
do bar(D); while(y + 2);
|
||||||
|
|
||||||
|
var z = 5, E = 30;
|
||||||
|
for (; f(z + 2) ;) bar(E);
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
var v = 1;
|
||||||
|
for (v in objs) f(2);
|
||||||
|
|
||||||
|
var x = 3;
|
||||||
|
while(x + 2) bar(10);
|
||||||
|
|
||||||
|
var y = 4;
|
||||||
|
do bar(20); while(y + 2);
|
||||||
|
|
||||||
|
var z = 5;
|
||||||
|
for (; f(z + 2) ;) bar(30);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
issue_1605_1: {
|
||||||
|
options = {
|
||||||
|
collapse_vars: true,
|
||||||
|
toplevel: false,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
function foo(x) {
|
||||||
|
var y = x;
|
||||||
|
return y;
|
||||||
|
}
|
||||||
|
var o = new Object;
|
||||||
|
o.p = 1;
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
function foo(x) {
|
||||||
|
return x;
|
||||||
|
}
|
||||||
|
var o = new Object;
|
||||||
|
o.p = 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
issue_1605_2: {
|
||||||
|
options = {
|
||||||
|
collapse_vars: true,
|
||||||
|
toplevel: "vars",
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
function foo(x) {
|
||||||
|
var y = x;
|
||||||
|
return y;
|
||||||
|
}
|
||||||
|
var o = new Object;
|
||||||
|
o.p = 1;
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
function foo(x) {
|
||||||
|
return x;
|
||||||
|
}
|
||||||
|
(new Object).p = 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
issue_1631_1: {
|
||||||
|
options = {
|
||||||
|
cascade: true,
|
||||||
|
collapse_vars: true,
|
||||||
|
hoist_funs: true,
|
||||||
|
join_vars: true,
|
||||||
|
sequences: true,
|
||||||
|
side_effects: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
var pc = 0;
|
||||||
|
function f(x) {
|
||||||
|
pc = 200;
|
||||||
|
return 100;
|
||||||
|
}
|
||||||
|
function x() {
|
||||||
|
var t = f();
|
||||||
|
pc += t;
|
||||||
|
return pc;
|
||||||
|
}
|
||||||
|
console.log(x());
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
function f(x) {
|
||||||
|
return pc = 200, 100;
|
||||||
|
}
|
||||||
|
function x() {
|
||||||
|
var t = f();
|
||||||
|
return pc += t;
|
||||||
|
}
|
||||||
|
var pc = 0;
|
||||||
|
console.log(x());
|
||||||
|
}
|
||||||
|
expect_stdout: "300"
|
||||||
|
}
|
||||||
|
|
||||||
|
issue_1631_2: {
|
||||||
|
options = {
|
||||||
|
cascade: true,
|
||||||
|
collapse_vars: true,
|
||||||
|
hoist_funs: true,
|
||||||
|
join_vars: true,
|
||||||
|
sequences: true,
|
||||||
|
side_effects: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
var a = 0, b = 1;
|
||||||
|
function f() {
|
||||||
|
a = 2;
|
||||||
|
return 4;
|
||||||
|
}
|
||||||
|
function g() {
|
||||||
|
var t = f();
|
||||||
|
b = a + t;
|
||||||
|
return b;
|
||||||
|
}
|
||||||
|
console.log(g());
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
function f() {
|
||||||
|
return a = 2, 4;
|
||||||
|
}
|
||||||
|
function g() {
|
||||||
|
var t = f();
|
||||||
|
return b = a + t;
|
||||||
|
}
|
||||||
|
var a = 0, b = 1;
|
||||||
|
console.log(g());
|
||||||
|
}
|
||||||
|
expect_stdout: "6"
|
||||||
|
}
|
||||||
|
|
||||||
|
issue_1631_3: {
|
||||||
|
options = {
|
||||||
|
cascade: true,
|
||||||
|
collapse_vars: true,
|
||||||
|
hoist_funs: true,
|
||||||
|
join_vars: true,
|
||||||
|
sequences: true,
|
||||||
|
side_effects: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
function g() {
|
||||||
|
var a = 0, b = 1;
|
||||||
|
function f() {
|
||||||
|
a = 2;
|
||||||
|
return 4;
|
||||||
|
}
|
||||||
|
var t = f();
|
||||||
|
b = a + t;
|
||||||
|
return b;
|
||||||
|
}
|
||||||
|
console.log(g());
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
function g() {
|
||||||
|
function f() {
|
||||||
|
return a = 2, 4;
|
||||||
|
}
|
||||||
|
var a = 0, b = 1, t = f();
|
||||||
|
return b = a + t;
|
||||||
|
}
|
||||||
|
console.log(g());
|
||||||
|
}
|
||||||
|
expect_stdout: "6"
|
||||||
|
}
|
||||||
|
|
||||||
|
var_side_effects_1: {
|
||||||
|
options = {
|
||||||
|
collapse_vars: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
var print = console.log.bind(console);
|
||||||
|
function foo(x) {
|
||||||
|
var twice = x * 2;
|
||||||
|
print('Foo:', twice);
|
||||||
|
}
|
||||||
|
foo(10);
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
var print = console.log.bind(console);
|
||||||
|
function foo(x) {
|
||||||
|
print('Foo:', 2 * x);
|
||||||
|
}
|
||||||
|
foo(10);
|
||||||
|
}
|
||||||
|
expect_stdout: true
|
||||||
|
}
|
||||||
|
|
||||||
|
var_side_effects_2: {
|
||||||
|
options = {
|
||||||
|
collapse_vars: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
var print = console.log.bind(console);
|
||||||
|
function foo(x) {
|
||||||
|
var twice = x.y * 2;
|
||||||
|
print('Foo:', twice);
|
||||||
|
}
|
||||||
|
foo({ y: 10 });
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
var print = console.log.bind(console);
|
||||||
|
function foo(x) {
|
||||||
|
var twice = 2 * x.y;
|
||||||
|
print('Foo:', twice);
|
||||||
|
}
|
||||||
|
foo({ y: 10 });
|
||||||
|
}
|
||||||
|
expect_stdout: true
|
||||||
|
}
|
||||||
|
|
||||||
|
var_side_effects_3: {
|
||||||
|
options = {
|
||||||
|
collapse_vars: true,
|
||||||
|
pure_getters: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
var print = console.log.bind(console);
|
||||||
|
function foo(x) {
|
||||||
|
var twice = x.y * 2;
|
||||||
|
print('Foo:', twice);
|
||||||
|
}
|
||||||
|
foo({ y: 10 });
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
var print = console.log.bind(console);
|
||||||
|
function foo(x) {
|
||||||
|
print('Foo:', 2 * x.y);
|
||||||
|
}
|
||||||
|
foo({ y: 10 });
|
||||||
|
}
|
||||||
|
expect_stdout: true
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -51,6 +51,7 @@ concat_2: {
|
|||||||
"1" + "2" + "3"
|
"1" + "2" + "3"
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
expect_stdout: true
|
||||||
}
|
}
|
||||||
|
|
||||||
concat_3: {
|
concat_3: {
|
||||||
@@ -79,6 +80,7 @@ concat_3: {
|
|||||||
1 + 2 + "3" + "4" + "5"
|
1 + 2 + "3" + "4" + "5"
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
expect_stdout: true
|
||||||
}
|
}
|
||||||
|
|
||||||
concat_4: {
|
concat_4: {
|
||||||
@@ -107,6 +109,7 @@ concat_4: {
|
|||||||
1 + "2" + "3" + "4" + "5"
|
1 + "2" + "3" + "4" + "5"
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
expect_stdout: true
|
||||||
}
|
}
|
||||||
|
|
||||||
concat_5: {
|
concat_5: {
|
||||||
@@ -135,6 +138,7 @@ concat_5: {
|
|||||||
"1" + 2 + "3" + "4" + "5"
|
"1" + 2 + "3" + "4" + "5"
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
expect_stdout: true
|
||||||
}
|
}
|
||||||
|
|
||||||
concat_6: {
|
concat_6: {
|
||||||
@@ -163,4 +167,57 @@ concat_6: {
|
|||||||
"1" + "2" + "3" + "4" + "5"
|
"1" + "2" + "3" + "4" + "5"
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
expect_stdout: true
|
||||||
|
}
|
||||||
|
|
||||||
|
concat_7: {
|
||||||
|
input: {
|
||||||
|
console.log(
|
||||||
|
"" + 1,
|
||||||
|
"" + "1",
|
||||||
|
"" + 1 + 2,
|
||||||
|
"" + 1 + "2",
|
||||||
|
"" + "1" + 2,
|
||||||
|
"" + "1" + "2",
|
||||||
|
"" + (x += "foo")
|
||||||
|
);
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
console.log(
|
||||||
|
"" + 1,
|
||||||
|
"1",
|
||||||
|
"" + 1 + 2,
|
||||||
|
1 + "2",
|
||||||
|
"1" + 2,
|
||||||
|
"1" + "2",
|
||||||
|
x += "foo"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
expect_stdout: true
|
||||||
|
}
|
||||||
|
|
||||||
|
concat_8: {
|
||||||
|
input: {
|
||||||
|
console.log(
|
||||||
|
1 + "",
|
||||||
|
"1" + "",
|
||||||
|
1 + 2 + "",
|
||||||
|
1 + "2" + "",
|
||||||
|
"1" + 2 + "",
|
||||||
|
"1" + "2" + "",
|
||||||
|
(x += "foo") + ""
|
||||||
|
);
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
console.log(
|
||||||
|
1 + "",
|
||||||
|
"1",
|
||||||
|
1 + 2 + "",
|
||||||
|
1 + "2",
|
||||||
|
"1" + 2,
|
||||||
|
"1" + "2",
|
||||||
|
x += "foo"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
expect_stdout: true
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -50,7 +50,8 @@ ifs_3_should_warn: {
|
|||||||
conditionals : true,
|
conditionals : true,
|
||||||
dead_code : true,
|
dead_code : true,
|
||||||
evaluate : true,
|
evaluate : true,
|
||||||
booleans : true
|
booleans : true,
|
||||||
|
side_effects : true,
|
||||||
};
|
};
|
||||||
input: {
|
input: {
|
||||||
var x, y;
|
var x, y;
|
||||||
@@ -135,16 +136,28 @@ ifs_6: {
|
|||||||
comparisons: true
|
comparisons: true
|
||||||
};
|
};
|
||||||
input: {
|
input: {
|
||||||
var x;
|
var x, y;
|
||||||
if (!foo && !bar && !baz && !boo) {
|
if (!foo && !bar && !baz && !boo) {
|
||||||
x = 10;
|
x = 10;
|
||||||
} else {
|
} else {
|
||||||
x = 20;
|
x = 20;
|
||||||
}
|
}
|
||||||
|
if (y) {
|
||||||
|
x[foo] = 10;
|
||||||
|
} else {
|
||||||
|
x[foo] = 20;
|
||||||
|
}
|
||||||
|
if (foo) {
|
||||||
|
x[bar] = 10;
|
||||||
|
} else {
|
||||||
|
x[bar] = 20;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
expect: {
|
expect: {
|
||||||
var x;
|
var x, y;
|
||||||
x = foo || bar || baz || boo ? 20 : 10;
|
x = foo || bar || baz || boo ? 20 : 10;
|
||||||
|
x[foo] = y ? 10 : 20;
|
||||||
|
foo ? x[bar] = 10 : x[bar] = 20;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -159,10 +172,16 @@ cond_1: {
|
|||||||
} else {
|
} else {
|
||||||
do_something(y);
|
do_something(y);
|
||||||
}
|
}
|
||||||
|
if (some_condition()) {
|
||||||
|
side_effects(x);
|
||||||
|
} else {
|
||||||
|
side_effects(y);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
expect: {
|
expect: {
|
||||||
var do_something;
|
var do_something;
|
||||||
do_something(some_condition() ? x : y);
|
do_something(some_condition() ? x : y);
|
||||||
|
some_condition() ? side_effects(x) : side_effects(y);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -213,10 +232,16 @@ cond_4: {
|
|||||||
} else {
|
} else {
|
||||||
do_something();
|
do_something();
|
||||||
}
|
}
|
||||||
|
if (some_condition()) {
|
||||||
|
side_effects();
|
||||||
|
} else {
|
||||||
|
side_effects();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
expect: {
|
expect: {
|
||||||
var do_something;
|
var do_something;
|
||||||
some_condition(), do_something();
|
some_condition(), do_something();
|
||||||
|
some_condition(), side_effects();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -250,7 +275,8 @@ cond_5: {
|
|||||||
cond_7: {
|
cond_7: {
|
||||||
options = {
|
options = {
|
||||||
conditionals: true,
|
conditionals: true,
|
||||||
evaluate : true
|
evaluate : true,
|
||||||
|
side_effects: true,
|
||||||
};
|
};
|
||||||
input: {
|
input: {
|
||||||
var x, y, z, a, b;
|
var x, y, z, a, b;
|
||||||
@@ -714,6 +740,7 @@ issue_1154: {
|
|||||||
conditionals: true,
|
conditionals: true,
|
||||||
evaluate : true,
|
evaluate : true,
|
||||||
booleans : true,
|
booleans : true,
|
||||||
|
side_effects: true,
|
||||||
};
|
};
|
||||||
input: {
|
input: {
|
||||||
function f1(x) { return x ? -1 : -1; }
|
function f1(x) { return x ? -1 : -1; }
|
||||||
@@ -742,7 +769,7 @@ issue_1154: {
|
|||||||
function g2() { return g(), 2; }
|
function g2() { return g(), 2; }
|
||||||
function g3() { return g(), -4; }
|
function g3() { return g(), -4; }
|
||||||
function g4() { return g(), !1; }
|
function g4() { return g(), !1; }
|
||||||
function g5() { return g(), void 0; }
|
function g5() { return void g(); }
|
||||||
function g6() { return g(), "number"; }
|
function g6() { return g(), "number"; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -750,7 +777,8 @@ issue_1154: {
|
|||||||
no_evaluate: {
|
no_evaluate: {
|
||||||
options = {
|
options = {
|
||||||
conditionals: true,
|
conditionals: true,
|
||||||
evaluate : false
|
evaluate : false,
|
||||||
|
side_effects: true,
|
||||||
}
|
}
|
||||||
input: {
|
input: {
|
||||||
function f(b) {
|
function f(b) {
|
||||||
@@ -769,3 +797,168 @@ no_evaluate: {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
equality_conditionals_false: {
|
||||||
|
options = {
|
||||||
|
conditionals: false,
|
||||||
|
sequences: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
function f(a, b, c) {
|
||||||
|
console.log(
|
||||||
|
a == (b ? a : a),
|
||||||
|
a == (b ? a : c),
|
||||||
|
a != (b ? a : a),
|
||||||
|
a != (b ? a : c),
|
||||||
|
a === (b ? a : a),
|
||||||
|
a === (b ? a : c),
|
||||||
|
a !== (b ? a : a),
|
||||||
|
a !== (b ? a : c)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
f(0, 0, 0);
|
||||||
|
f(0, true, 0);
|
||||||
|
f(1, 2, 3);
|
||||||
|
f(1, null, 3);
|
||||||
|
f(NaN);
|
||||||
|
f(NaN, "foo");
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
function f(a, b, c) {
|
||||||
|
console.log(
|
||||||
|
a == (b ? a : a),
|
||||||
|
a == (b ? a : c),
|
||||||
|
a != (b ? a : a),
|
||||||
|
a != (b ? a : c),
|
||||||
|
a === (b ? a : a),
|
||||||
|
a === (b ? a : c),
|
||||||
|
a !== (b ? a : a),
|
||||||
|
a !== (b ? a : c)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
f(0, 0, 0),
|
||||||
|
f(0, true, 0),
|
||||||
|
f(1, 2, 3),
|
||||||
|
f(1, null, 3),
|
||||||
|
f(NaN),
|
||||||
|
f(NaN, "foo");
|
||||||
|
}
|
||||||
|
expect_stdout: true
|
||||||
|
}
|
||||||
|
|
||||||
|
equality_conditionals_true: {
|
||||||
|
options = {
|
||||||
|
conditionals: true,
|
||||||
|
sequences: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
function f(a, b, c) {
|
||||||
|
console.log(
|
||||||
|
a == (b ? a : a),
|
||||||
|
a == (b ? a : c),
|
||||||
|
a != (b ? a : a),
|
||||||
|
a != (b ? a : c),
|
||||||
|
a === (b ? a : a),
|
||||||
|
a === (b ? a : c),
|
||||||
|
a !== (b ? a : a),
|
||||||
|
a !== (b ? a : c)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
f(0, 0, 0);
|
||||||
|
f(0, true, 0);
|
||||||
|
f(1, 2, 3);
|
||||||
|
f(1, null, 3);
|
||||||
|
f(NaN);
|
||||||
|
f(NaN, "foo");
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
function f(a, b, c) {
|
||||||
|
console.log(
|
||||||
|
(b, a == a),
|
||||||
|
a == (b ? a : c),
|
||||||
|
(b, a != a),
|
||||||
|
a != (b ? a : c),
|
||||||
|
(b, a === a),
|
||||||
|
a === (b ? a : c),
|
||||||
|
(b, a !== a),
|
||||||
|
a !== (b ? a : c)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
f(0, 0, 0),
|
||||||
|
f(0, true, 0),
|
||||||
|
f(1, 2, 3),
|
||||||
|
f(1, null, 3),
|
||||||
|
f(NaN),
|
||||||
|
f(NaN, "foo");
|
||||||
|
}
|
||||||
|
expect_stdout: true
|
||||||
|
}
|
||||||
|
|
||||||
|
issue_1645_1: {
|
||||||
|
options = {
|
||||||
|
conditionals: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
var a = 100, b = 10;
|
||||||
|
(b = a) ? a++ + (b += a) ? b += a : b += a : b ^= a;
|
||||||
|
console.log(a, b);
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
var a = 100, b = 10;
|
||||||
|
(b = a) ? (a++ + (b += a), b += a) : b ^= a;
|
||||||
|
console.log(a,b);
|
||||||
|
}
|
||||||
|
expect_stdout: true
|
||||||
|
}
|
||||||
|
|
||||||
|
issue_1645_2: {
|
||||||
|
options = {
|
||||||
|
conditionals: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
var a = 0;
|
||||||
|
function f() {
|
||||||
|
return a++;
|
||||||
|
}
|
||||||
|
f() ? a += 2 : a += 4;
|
||||||
|
console.log(a);
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
var a = 0;
|
||||||
|
function f(){
|
||||||
|
return a++;
|
||||||
|
}
|
||||||
|
f() ? a += 2 : a += 4;
|
||||||
|
console.log(a);
|
||||||
|
}
|
||||||
|
expect_stdout: true
|
||||||
|
}
|
||||||
|
|
||||||
|
condition_symbol_matches_consequent: {
|
||||||
|
options = {
|
||||||
|
conditionals: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
function foo(x, y) {
|
||||||
|
return x ? x : y;
|
||||||
|
}
|
||||||
|
function bar() {
|
||||||
|
return g ? g : h;
|
||||||
|
}
|
||||||
|
var g = 4;
|
||||||
|
var h = 5;
|
||||||
|
console.log(foo(3, null), foo(0, 7), foo(true, false), bar());
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
function foo(x, y) {
|
||||||
|
return x || y;
|
||||||
|
}
|
||||||
|
function bar() {
|
||||||
|
return g || h;
|
||||||
|
}
|
||||||
|
var g = 4;
|
||||||
|
var h = 5;
|
||||||
|
console.log(foo(3, null), foo(0, 7), foo(true, false), bar());
|
||||||
|
}
|
||||||
|
expect_stdout: "3 7 true 4"
|
||||||
|
}
|
||||||
|
|||||||
@@ -162,4 +162,5 @@ regexp_literal_not_const: {
|
|||||||
while (result = REGEXP_LITERAL.exec("acdabcdeabbb")) console.log(result[0]);
|
while (result = REGEXP_LITERAL.exec("acdabcdeabbb")) console.log(result[0]);
|
||||||
})();
|
})();
|
||||||
}
|
}
|
||||||
|
expect_stdout: true
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -64,7 +64,8 @@ dead_code_constant_boolean_should_warn_more: {
|
|||||||
loops : true,
|
loops : true,
|
||||||
booleans : true,
|
booleans : true,
|
||||||
conditionals : true,
|
conditionals : true,
|
||||||
evaluate : true
|
evaluate : true,
|
||||||
|
side_effects : true,
|
||||||
};
|
};
|
||||||
input: {
|
input: {
|
||||||
while (!((foo && bar) || (x + "0"))) {
|
while (!((foo && bar) || (x + "0"))) {
|
||||||
@@ -86,6 +87,7 @@ dead_code_constant_boolean_should_warn_more: {
|
|||||||
var x = 10, y;
|
var x = 10, y;
|
||||||
var moo;
|
var moo;
|
||||||
}
|
}
|
||||||
|
expect_stdout: true
|
||||||
}
|
}
|
||||||
|
|
||||||
dead_code_const_declaration: {
|
dead_code_const_declaration: {
|
||||||
@@ -112,6 +114,7 @@ dead_code_const_declaration: {
|
|||||||
var moo;
|
var moo;
|
||||||
function bar() {}
|
function bar() {}
|
||||||
}
|
}
|
||||||
|
expect_stdout: true
|
||||||
}
|
}
|
||||||
|
|
||||||
dead_code_const_annotation: {
|
dead_code_const_annotation: {
|
||||||
@@ -122,6 +125,7 @@ dead_code_const_annotation: {
|
|||||||
conditionals : true,
|
conditionals : true,
|
||||||
evaluate : true,
|
evaluate : true,
|
||||||
reduce_vars : true,
|
reduce_vars : true,
|
||||||
|
toplevel : true,
|
||||||
};
|
};
|
||||||
input: {
|
input: {
|
||||||
var unused;
|
var unused;
|
||||||
@@ -138,6 +142,7 @@ dead_code_const_annotation: {
|
|||||||
var moo;
|
var moo;
|
||||||
function bar() {}
|
function bar() {}
|
||||||
}
|
}
|
||||||
|
expect_stdout: true
|
||||||
}
|
}
|
||||||
|
|
||||||
dead_code_const_annotation_regex: {
|
dead_code_const_annotation_regex: {
|
||||||
@@ -161,6 +166,7 @@ dead_code_const_annotation_regex: {
|
|||||||
var CONST_FOO_ANN = !1;
|
var CONST_FOO_ANN = !1;
|
||||||
CONST_FOO_ANN && console.log('reachable');
|
CONST_FOO_ANN && console.log('reachable');
|
||||||
}
|
}
|
||||||
|
expect_stdout: true
|
||||||
}
|
}
|
||||||
|
|
||||||
dead_code_const_annotation_complex_scope: {
|
dead_code_const_annotation_complex_scope: {
|
||||||
@@ -171,6 +177,7 @@ dead_code_const_annotation_complex_scope: {
|
|||||||
conditionals : true,
|
conditionals : true,
|
||||||
evaluate : true,
|
evaluate : true,
|
||||||
reduce_vars : true,
|
reduce_vars : true,
|
||||||
|
toplevel : true,
|
||||||
};
|
};
|
||||||
input: {
|
input: {
|
||||||
var unused_var;
|
var unused_var;
|
||||||
@@ -205,4 +212,5 @@ dead_code_const_annotation_complex_scope: {
|
|||||||
var meat = 'beef';
|
var meat = 'beef';
|
||||||
var pork = 'bad';
|
var pork = 'bad';
|
||||||
}
|
}
|
||||||
|
expect_stdout: true
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -632,7 +632,7 @@ iife: {
|
|||||||
}
|
}
|
||||||
expect: {
|
expect: {
|
||||||
function f() {
|
function f() {
|
||||||
~function() {}(b);
|
b;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -679,3 +679,282 @@ const_assign: {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
issue_1539: {
|
||||||
|
options = {
|
||||||
|
cascade: true,
|
||||||
|
sequences: true,
|
||||||
|
side_effects: true,
|
||||||
|
unused: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
function f() {
|
||||||
|
var a, b;
|
||||||
|
a = b = 42;
|
||||||
|
return a;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
function f() {
|
||||||
|
return 42;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
vardef_value: {
|
||||||
|
options = {
|
||||||
|
keep_fnames: false,
|
||||||
|
reduce_vars: true,
|
||||||
|
unused: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
function f() {
|
||||||
|
function g(){
|
||||||
|
return x();
|
||||||
|
}
|
||||||
|
var a = g();
|
||||||
|
return a(42);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
function f() {
|
||||||
|
var a = function(){
|
||||||
|
return x();
|
||||||
|
}();
|
||||||
|
return a(42);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
assign_binding: {
|
||||||
|
options = {
|
||||||
|
cascade: true,
|
||||||
|
side_effects: true,
|
||||||
|
unused: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
function f() {
|
||||||
|
var a;
|
||||||
|
a = f.g, a();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
function f() {
|
||||||
|
(0, f.g)();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
assign_chain: {
|
||||||
|
options = {
|
||||||
|
unused: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
function f() {
|
||||||
|
var a, b;
|
||||||
|
x = a = y = b = 42;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
function f() {
|
||||||
|
x = y = 42;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
issue_1583: {
|
||||||
|
options = {
|
||||||
|
keep_fargs: true,
|
||||||
|
reduce_vars: true,
|
||||||
|
unused: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
function m(t) {
|
||||||
|
(function(e) {
|
||||||
|
t = e();
|
||||||
|
})(function() {
|
||||||
|
return (function(a) {
|
||||||
|
return a;
|
||||||
|
})(function(a) {});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
function m(t) {
|
||||||
|
(function(e) {
|
||||||
|
t = (function() {
|
||||||
|
return (function(a) {
|
||||||
|
return a;
|
||||||
|
})(function(a) {});
|
||||||
|
})();
|
||||||
|
})();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
issue_1656: {
|
||||||
|
options = {
|
||||||
|
toplevel: true,
|
||||||
|
unused: true,
|
||||||
|
}
|
||||||
|
beautify = {
|
||||||
|
beautify: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
for(var a=0;;);
|
||||||
|
}
|
||||||
|
expect_exact: "for (;;) ;"
|
||||||
|
}
|
||||||
|
|
||||||
|
issue_1709: {
|
||||||
|
options = {
|
||||||
|
unused: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
console.log(
|
||||||
|
function x() {
|
||||||
|
var x = 1;
|
||||||
|
return x;
|
||||||
|
}(),
|
||||||
|
function y() {
|
||||||
|
const y = 2;
|
||||||
|
return y;
|
||||||
|
}(),
|
||||||
|
function z() {
|
||||||
|
function z() {}
|
||||||
|
return z;
|
||||||
|
}()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
console.log(
|
||||||
|
function() {
|
||||||
|
var x = 1;
|
||||||
|
return x;
|
||||||
|
}(),
|
||||||
|
function() {
|
||||||
|
const y = 2;
|
||||||
|
return y;
|
||||||
|
}(),
|
||||||
|
function() {
|
||||||
|
function z() {}
|
||||||
|
return z;
|
||||||
|
}()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
expect_stdout: true
|
||||||
|
}
|
||||||
|
|
||||||
|
issue_1715_1: {
|
||||||
|
options = {
|
||||||
|
unused: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
var a = 1;
|
||||||
|
function f() {
|
||||||
|
a++;
|
||||||
|
try {} catch (a) {
|
||||||
|
var a;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
f();
|
||||||
|
console.log(a);
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
var a = 1;
|
||||||
|
function f() {
|
||||||
|
a++;
|
||||||
|
try {} catch (a) {
|
||||||
|
var a;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
f();
|
||||||
|
console.log(a);
|
||||||
|
}
|
||||||
|
expect_stdout: "1"
|
||||||
|
}
|
||||||
|
|
||||||
|
issue_1715_2: {
|
||||||
|
options = {
|
||||||
|
unused: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
var a = 1;
|
||||||
|
function f() {
|
||||||
|
a++;
|
||||||
|
try {} catch (a) {
|
||||||
|
var a = 2;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
f();
|
||||||
|
console.log(a);
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
var a = 1;
|
||||||
|
function f() {
|
||||||
|
a++;
|
||||||
|
try {} catch (a) {
|
||||||
|
var a;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
f();
|
||||||
|
console.log(a);
|
||||||
|
}
|
||||||
|
expect_stdout: "1"
|
||||||
|
}
|
||||||
|
|
||||||
|
issue_1715_3: {
|
||||||
|
options = {
|
||||||
|
unused: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
var a = 1;
|
||||||
|
function f() {
|
||||||
|
a++;
|
||||||
|
try {} catch (a) {
|
||||||
|
var a = 2 + x();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
f();
|
||||||
|
console.log(a);
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
var a = 1;
|
||||||
|
function f() {
|
||||||
|
a++;
|
||||||
|
try {} catch (a) {
|
||||||
|
var a = x();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
f();
|
||||||
|
console.log(a);
|
||||||
|
}
|
||||||
|
expect_stdout: "1"
|
||||||
|
}
|
||||||
|
|
||||||
|
issue_1715_4: {
|
||||||
|
options = {
|
||||||
|
unused: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
var a = 1;
|
||||||
|
!function a() {
|
||||||
|
a++;
|
||||||
|
try {} catch (a) {
|
||||||
|
var a;
|
||||||
|
}
|
||||||
|
}();
|
||||||
|
console.log(a);
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
var a = 1;
|
||||||
|
!function() {
|
||||||
|
a++;
|
||||||
|
try {} catch (a) {
|
||||||
|
var a;
|
||||||
|
}
|
||||||
|
}();
|
||||||
|
console.log(a);
|
||||||
|
}
|
||||||
|
expect_stdout: "1"
|
||||||
|
}
|
||||||
|
|||||||
@@ -200,6 +200,7 @@ negative_zero: {
|
|||||||
1 / (-0)
|
1 / (-0)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
expect_stdout: true
|
||||||
}
|
}
|
||||||
|
|
||||||
positive_zero: {
|
positive_zero: {
|
||||||
@@ -220,6 +221,7 @@ positive_zero: {
|
|||||||
1 / (0)
|
1 / (0)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
expect_stdout: true
|
||||||
}
|
}
|
||||||
|
|
||||||
unsafe_constant: {
|
unsafe_constant: {
|
||||||
@@ -243,6 +245,7 @@ unsafe_constant: {
|
|||||||
(void 0).a
|
(void 0).a
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
expect_stdout: true
|
||||||
}
|
}
|
||||||
|
|
||||||
unsafe_object: {
|
unsafe_object: {
|
||||||
@@ -266,6 +269,7 @@ unsafe_object: {
|
|||||||
1..b + 1
|
1..b + 1
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
expect_stdout: true
|
||||||
}
|
}
|
||||||
|
|
||||||
unsafe_object_nested: {
|
unsafe_object_nested: {
|
||||||
@@ -289,6 +293,7 @@ unsafe_object_nested: {
|
|||||||
2
|
2
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
expect_stdout: true
|
||||||
}
|
}
|
||||||
|
|
||||||
unsafe_object_complex: {
|
unsafe_object_complex: {
|
||||||
@@ -312,6 +317,7 @@ unsafe_object_complex: {
|
|||||||
2
|
2
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
expect_stdout: true
|
||||||
}
|
}
|
||||||
|
|
||||||
unsafe_object_repeated: {
|
unsafe_object_repeated: {
|
||||||
@@ -335,6 +341,33 @@ unsafe_object_repeated: {
|
|||||||
1..b + 1
|
1..b + 1
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
expect_stdout: true
|
||||||
|
}
|
||||||
|
|
||||||
|
unsafe_object_accessor: {
|
||||||
|
options = {
|
||||||
|
evaluate: true,
|
||||||
|
reduce_vars: true,
|
||||||
|
unsafe: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
function f() {
|
||||||
|
var a = {
|
||||||
|
get b() {},
|
||||||
|
set b() {}
|
||||||
|
};
|
||||||
|
return {a:a};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
function f() {
|
||||||
|
var a = {
|
||||||
|
get b() {},
|
||||||
|
set b() {}
|
||||||
|
};
|
||||||
|
return {a:a};
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
unsafe_function: {
|
unsafe_function: {
|
||||||
@@ -358,6 +391,7 @@ unsafe_function: {
|
|||||||
({a:{b:1},b:function(){}}).a.b + 1
|
({a:{b:1},b:function(){}}).a.b + 1
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
expect_stdout: true
|
||||||
}
|
}
|
||||||
|
|
||||||
unsafe_integer_key: {
|
unsafe_integer_key: {
|
||||||
@@ -385,6 +419,7 @@ unsafe_integer_key: {
|
|||||||
1["1"] + 1
|
1["1"] + 1
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
expect_stdout: true
|
||||||
}
|
}
|
||||||
|
|
||||||
unsafe_integer_key_complex: {
|
unsafe_integer_key_complex: {
|
||||||
@@ -412,6 +447,7 @@ unsafe_integer_key_complex: {
|
|||||||
2
|
2
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
expect_stdout: true
|
||||||
}
|
}
|
||||||
|
|
||||||
unsafe_float_key: {
|
unsafe_float_key: {
|
||||||
@@ -439,6 +475,7 @@ unsafe_float_key: {
|
|||||||
1["3.14"] + 1
|
1["3.14"] + 1
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
expect_stdout: true
|
||||||
}
|
}
|
||||||
|
|
||||||
unsafe_float_key_complex: {
|
unsafe_float_key_complex: {
|
||||||
@@ -466,6 +503,7 @@ unsafe_float_key_complex: {
|
|||||||
2
|
2
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
expect_stdout: true
|
||||||
}
|
}
|
||||||
|
|
||||||
unsafe_array: {
|
unsafe_array: {
|
||||||
@@ -501,6 +539,7 @@ unsafe_array: {
|
|||||||
(void 0)[1] + 1
|
(void 0)[1] + 1
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
expect_stdout: true
|
||||||
}
|
}
|
||||||
|
|
||||||
unsafe_string: {
|
unsafe_string: {
|
||||||
@@ -528,6 +567,7 @@ unsafe_string: {
|
|||||||
"11"
|
"11"
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
expect_stdout: true
|
||||||
}
|
}
|
||||||
|
|
||||||
unsafe_array_bad_index: {
|
unsafe_array_bad_index: {
|
||||||
@@ -549,6 +589,7 @@ unsafe_array_bad_index: {
|
|||||||
[1, 2, 3, 4][3.14] + 1
|
[1, 2, 3, 4][3.14] + 1
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
expect_stdout: true
|
||||||
}
|
}
|
||||||
|
|
||||||
unsafe_string_bad_index: {
|
unsafe_string_bad_index: {
|
||||||
@@ -570,6 +611,7 @@ unsafe_string_bad_index: {
|
|||||||
"1234"[3.14] + 1
|
"1234"[3.14] + 1
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
expect_stdout: true
|
||||||
}
|
}
|
||||||
|
|
||||||
unsafe_prototype_function: {
|
unsafe_prototype_function: {
|
||||||
@@ -614,35 +656,149 @@ call_args: {
|
|||||||
expect: {
|
expect: {
|
||||||
const a = 1;
|
const a = 1;
|
||||||
console.log(1);
|
console.log(1);
|
||||||
+function(a) {
|
+(1, 1);
|
||||||
return 1;
|
|
||||||
}(1);
|
|
||||||
}
|
}
|
||||||
|
expect_stdout: true
|
||||||
|
}
|
||||||
|
|
||||||
|
call_args_drop_param: {
|
||||||
|
options = {
|
||||||
|
evaluate: true,
|
||||||
|
keep_fargs: false,
|
||||||
|
reduce_vars: true,
|
||||||
|
unused: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
const a = 1;
|
||||||
|
console.log(a);
|
||||||
|
+function(a) {
|
||||||
|
return a;
|
||||||
|
}(a, b);
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
const a = 1;
|
||||||
|
console.log(1);
|
||||||
|
+(b, 1);
|
||||||
|
}
|
||||||
|
expect_stdout: true
|
||||||
}
|
}
|
||||||
|
|
||||||
in_boolean_context: {
|
in_boolean_context: {
|
||||||
options = {
|
options = {
|
||||||
booleans: true,
|
booleans: true,
|
||||||
evaluate: true,
|
evaluate: true,
|
||||||
|
sequences: true,
|
||||||
|
side_effects: true,
|
||||||
}
|
}
|
||||||
input: {
|
input: {
|
||||||
!42;
|
console.log(
|
||||||
!"foo";
|
!42,
|
||||||
![1, 2];
|
!"foo",
|
||||||
!/foo/;
|
![1, 2],
|
||||||
!b(42);
|
!/foo/,
|
||||||
!b("foo");
|
!b(42),
|
||||||
!b([1, 2]);
|
!b("foo"),
|
||||||
!b(/foo/);
|
!b([1, 2]),
|
||||||
|
!b(/foo/),
|
||||||
|
![1, foo()],
|
||||||
|
![1, foo(), 2]
|
||||||
|
);
|
||||||
}
|
}
|
||||||
expect: {
|
expect: {
|
||||||
!1;
|
console.log(
|
||||||
!1;
|
!1,
|
||||||
!1;
|
!1,
|
||||||
!1;
|
!1,
|
||||||
!b(42);
|
!1,
|
||||||
!b("foo");
|
!b(42),
|
||||||
!b([1, 2]);
|
!b("foo"),
|
||||||
!b(/foo/);
|
!b([1, 2]),
|
||||||
|
!b(/foo/),
|
||||||
|
![1, foo()],
|
||||||
|
(foo(), !1)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
expect_stdout: true
|
||||||
|
}
|
||||||
|
|
||||||
|
unsafe_charAt: {
|
||||||
|
options = {
|
||||||
|
evaluate : true,
|
||||||
|
unsafe : true
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
console.log(
|
||||||
|
"1234" + 1,
|
||||||
|
"1234".charAt(0) + 1,
|
||||||
|
"1234".charAt(6 - 5) + 1,
|
||||||
|
("12" + "34").charAt(0) + 1,
|
||||||
|
("12" + "34").charAt(6 - 5) + 1,
|
||||||
|
[1, 2, 3, 4].join("").charAt(0) + 1
|
||||||
|
);
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
console.log(
|
||||||
|
"12341",
|
||||||
|
"11",
|
||||||
|
"21",
|
||||||
|
"11",
|
||||||
|
"21",
|
||||||
|
"11"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
expect_stdout: true
|
||||||
|
}
|
||||||
|
|
||||||
|
unsafe_charAt_bad_index: {
|
||||||
|
options = {
|
||||||
|
evaluate : true,
|
||||||
|
unsafe : true
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
console.log(
|
||||||
|
"1234".charAt() + 1,
|
||||||
|
"1234".charAt("a") + 1,
|
||||||
|
"1234".charAt(3.14) + 1
|
||||||
|
);
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
console.log(
|
||||||
|
"11",
|
||||||
|
"11",
|
||||||
|
"41"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
expect_stdout: true
|
||||||
|
}
|
||||||
|
|
||||||
|
unsafe_charAt_noop: {
|
||||||
|
options = {
|
||||||
|
evaluate : true,
|
||||||
|
unsafe : true
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
console.log(
|
||||||
|
s.charAt(0),
|
||||||
|
"string".charAt(x)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
console.log(
|
||||||
|
s.charAt(0),
|
||||||
|
"string".charAt(x)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
issue_1649: {
|
||||||
|
options = {
|
||||||
|
evaluate: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
console.log(-1 + -1);
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
console.log(-2);
|
||||||
|
}
|
||||||
|
expect_stdout: "-2";
|
||||||
|
}
|
||||||
|
|||||||
@@ -6,3 +6,90 @@ non_ascii_function_identifier_name: {
|
|||||||
}
|
}
|
||||||
expect_exact: "function fooλ(δλ){}function λ(δλ){}(function λ(δλ){})();"
|
expect_exact: "function fooλ(δλ){}function λ(δλ){}(function λ(δλ){})();"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
iifes_returning_constants_keep_fargs_true: {
|
||||||
|
options = {
|
||||||
|
keep_fargs : true,
|
||||||
|
side_effects : true,
|
||||||
|
evaluate : true,
|
||||||
|
unused : true,
|
||||||
|
dead_code : true,
|
||||||
|
conditionals : true,
|
||||||
|
comparisons : true,
|
||||||
|
booleans : true,
|
||||||
|
if_return : true,
|
||||||
|
join_vars : true,
|
||||||
|
reduce_vars : true,
|
||||||
|
cascade : true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
(function(){ return -1.23; }());
|
||||||
|
console.log( function foo(){ return "okay"; }() );
|
||||||
|
console.log( function foo(x, y, z){ return 123; }() );
|
||||||
|
console.log( function(x, y, z){ return z; }() );
|
||||||
|
console.log( function(x, y, z){ if (x) return y; return z; }(1, 2, 3) );
|
||||||
|
console.log( function(x, y){ return x * y; }(2, 3) );
|
||||||
|
console.log( function(x, y){ return x * y; }(2, 3, a(), b()) );
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
console.log("okay");
|
||||||
|
console.log(123);
|
||||||
|
console.log(void 0);
|
||||||
|
console.log(2);
|
||||||
|
console.log(6);
|
||||||
|
console.log((a(), b(), 6));
|
||||||
|
}
|
||||||
|
expect_stdout: true
|
||||||
|
}
|
||||||
|
|
||||||
|
iifes_returning_constants_keep_fargs_false: {
|
||||||
|
options = {
|
||||||
|
keep_fargs : false,
|
||||||
|
side_effects : true,
|
||||||
|
evaluate : true,
|
||||||
|
unused : true,
|
||||||
|
dead_code : true,
|
||||||
|
conditionals : true,
|
||||||
|
comparisons : true,
|
||||||
|
booleans : true,
|
||||||
|
if_return : true,
|
||||||
|
join_vars : true,
|
||||||
|
reduce_vars : true,
|
||||||
|
cascade : true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
(function(){ return -1.23; }());
|
||||||
|
console.log( function foo(){ return "okay"; }() );
|
||||||
|
console.log( function foo(x, y, z){ return 123; }() );
|
||||||
|
console.log( function(x, y, z){ return z; }() );
|
||||||
|
console.log( function(x, y, z){ if (x) return y; return z; }(1, 2, 3) );
|
||||||
|
console.log( function(x, y){ return x * y; }(2, 3) );
|
||||||
|
console.log( function(x, y){ return x * y; }(2, 3, a(), b()) );
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
console.log("okay");
|
||||||
|
console.log(123);
|
||||||
|
console.log(void 0);
|
||||||
|
console.log(2);
|
||||||
|
console.log(6);
|
||||||
|
console.log((a(), b(), 6));
|
||||||
|
}
|
||||||
|
expect_stdout: true
|
||||||
|
}
|
||||||
|
|
||||||
|
issue_485_crashing_1530: {
|
||||||
|
options = {
|
||||||
|
conditionals: true,
|
||||||
|
dead_code: true,
|
||||||
|
evaluate: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
(function(a) {
|
||||||
|
if (true) return;
|
||||||
|
var b = 42;
|
||||||
|
})(this);
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
this, void 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -47,22 +47,6 @@ html_comment_in_greater_than_or_equal: {
|
|||||||
expect_exact: "function f(a,b){return a-- >=b}";
|
expect_exact: "function f(a,b){return a-- >=b}";
|
||||||
}
|
}
|
||||||
|
|
||||||
html_comment_in_right_shift_assign: {
|
|
||||||
input: {
|
|
||||||
// Note: illegal javascript
|
|
||||||
function f(a, b) { return a-- >>= b; }
|
|
||||||
}
|
|
||||||
expect_exact: "function f(a,b){return a-- >>=b}";
|
|
||||||
}
|
|
||||||
|
|
||||||
html_comment_in_zero_fill_right_shift_assign: {
|
|
||||||
input: {
|
|
||||||
// Note: illegal javascript
|
|
||||||
function f(a, b) { return a-- >>>= b; }
|
|
||||||
}
|
|
||||||
expect_exact: "function f(a,b){return a-- >>>=b}";
|
|
||||||
}
|
|
||||||
|
|
||||||
html_comment_in_string_literal: {
|
html_comment_in_string_literal: {
|
||||||
input: {
|
input: {
|
||||||
function f() { return "<!--HTML-->comment in<!--string literal-->"; }
|
function f() { return "<!--HTML-->comment in<!--string literal-->"; }
|
||||||
|
|||||||
@@ -39,7 +39,7 @@ non_hoisted_function_after_return_2a: {
|
|||||||
hoist_funs: false, dead_code: true, conditionals: true, comparisons: true,
|
hoist_funs: false, dead_code: true, conditionals: true, comparisons: true,
|
||||||
evaluate: true, booleans: true, loops: true, unused: true, keep_fargs: true,
|
evaluate: true, booleans: true, loops: true, unused: true, keep_fargs: true,
|
||||||
if_return: true, join_vars: true, cascade: true, side_effects: true,
|
if_return: true, join_vars: true, cascade: true, side_effects: true,
|
||||||
collapse_vars: false, passes: 2
|
collapse_vars: false, passes: 2, warnings: "verbose"
|
||||||
}
|
}
|
||||||
input: {
|
input: {
|
||||||
function foo(x) {
|
function foo(x) {
|
||||||
@@ -75,7 +75,7 @@ non_hoisted_function_after_return_2a: {
|
|||||||
"WARN: Declarations in unreachable code! [test/compress/issue-1034.js:53,12]",
|
"WARN: Declarations in unreachable code! [test/compress/issue-1034.js:53,12]",
|
||||||
"WARN: Dropping unreachable code [test/compress/issue-1034.js:56,12]",
|
"WARN: Dropping unreachable code [test/compress/issue-1034.js:56,12]",
|
||||||
"WARN: Dropping unused variable b [test/compress/issue-1034.js:51,20]",
|
"WARN: Dropping unused variable b [test/compress/issue-1034.js:51,20]",
|
||||||
"WARN: Dropping unused variable c [test/compress/issue-1034.js:53,16]"
|
"WARN: Dropping unused variable c [test/compress/issue-1034.js:53,16]",
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -114,8 +114,5 @@ non_hoisted_function_after_return_2b: {
|
|||||||
"WARN: Dropping unreachable code [test/compress/issue-1034.js:97,12]",
|
"WARN: Dropping unreachable code [test/compress/issue-1034.js:97,12]",
|
||||||
"WARN: Declarations in unreachable code! [test/compress/issue-1034.js:97,12]",
|
"WARN: Declarations in unreachable code! [test/compress/issue-1034.js:97,12]",
|
||||||
"WARN: Dropping unreachable code [test/compress/issue-1034.js:101,12]",
|
"WARN: Dropping unreachable code [test/compress/issue-1034.js:101,12]",
|
||||||
"WARN: Dropping unused variable b [test/compress/issue-1034.js:95,20]",
|
|
||||||
"WARN: Dropping unused variable c [test/compress/issue-1034.js:97,16]"
|
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -49,4 +49,3 @@ mangle_keep_fnames_true: {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -116,3 +116,61 @@ pure_function_calls_toplevel: {
|
|||||||
"WARN: Dropping unused variable iife1 [test/compress/issue-1261.js:84,12]",
|
"WARN: Dropping unused variable iife1 [test/compress/issue-1261.js:84,12]",
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
should_warn: {
|
||||||
|
options = {
|
||||||
|
booleans: true,
|
||||||
|
conditionals: true,
|
||||||
|
evaluate: true,
|
||||||
|
side_effects: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
/* @__PURE__ */(function(){x})(), void/* @__PURE__ */(function(){y})();
|
||||||
|
/* @__PURE__ */(function(){x})() || true ? foo() : bar();
|
||||||
|
true || /* @__PURE__ */(function(){y})() ? foo() : bar();
|
||||||
|
/* @__PURE__ */(function(){x})() && false ? foo() : bar();
|
||||||
|
false && /* @__PURE__ */(function(){y})() ? foo() : bar();
|
||||||
|
/* @__PURE__ */(function(){x})() + "foo" ? bar() : baz();
|
||||||
|
"foo" + /* @__PURE__ */(function(){y})() ? bar() : baz();
|
||||||
|
/* @__PURE__ */(function(){x})() ? foo() : foo();
|
||||||
|
[/* @__PURE__ */(function(){x})()] ? foo() : bar();
|
||||||
|
!{ foo: /* @__PURE__ */(function(){x})() } ? bar() : baz();
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
foo();
|
||||||
|
foo();
|
||||||
|
bar();
|
||||||
|
bar();
|
||||||
|
bar();
|
||||||
|
bar();
|
||||||
|
foo();
|
||||||
|
foo();
|
||||||
|
baz();
|
||||||
|
}
|
||||||
|
expect_warnings: [
|
||||||
|
"WARN: Dropping __PURE__ call [test/compress/issue-1261.js:128,61]",
|
||||||
|
"WARN: Dropping __PURE__ call [test/compress/issue-1261.js:128,23]",
|
||||||
|
"WARN: Dropping side-effect-free statement [test/compress/issue-1261.js:128,23]",
|
||||||
|
"WARN: Boolean || always true [test/compress/issue-1261.js:129,23]",
|
||||||
|
"WARN: Dropping __PURE__ call [test/compress/issue-1261.js:129,23]",
|
||||||
|
"WARN: Condition always true [test/compress/issue-1261.js:129,23]",
|
||||||
|
"WARN: Boolean || always true [test/compress/issue-1261.js:130,8]",
|
||||||
|
"WARN: Condition always true [test/compress/issue-1261.js:130,8]",
|
||||||
|
"WARN: Boolean && always false [test/compress/issue-1261.js:131,23]",
|
||||||
|
"WARN: Dropping __PURE__ call [test/compress/issue-1261.js:131,23]",
|
||||||
|
"WARN: Condition always false [test/compress/issue-1261.js:131,23]",
|
||||||
|
"WARN: Boolean && always false [test/compress/issue-1261.js:132,8]",
|
||||||
|
"WARN: Condition always false [test/compress/issue-1261.js:132,8]",
|
||||||
|
"WARN: + in boolean context always true [test/compress/issue-1261.js:133,23]",
|
||||||
|
"WARN: Dropping __PURE__ call [test/compress/issue-1261.js:133,23]",
|
||||||
|
"WARN: Condition always true [test/compress/issue-1261.js:133,23]",
|
||||||
|
"WARN: + in boolean context always true [test/compress/issue-1261.js:134,8]",
|
||||||
|
"WARN: Dropping __PURE__ call [test/compress/issue-1261.js:134,31]",
|
||||||
|
"WARN: Condition always true [test/compress/issue-1261.js:134,8]",
|
||||||
|
"WARN: Dropping __PURE__ call [test/compress/issue-1261.js:135,23]",
|
||||||
|
"WARN: Dropping __PURE__ call [test/compress/issue-1261.js:136,24]",
|
||||||
|
"WARN: Condition always true [test/compress/issue-1261.js:136,8]",
|
||||||
|
"WARN: Dropping __PURE__ call [test/compress/issue-1261.js:137,31]",
|
||||||
|
"WARN: Condition always false [test/compress/issue-1261.js:137,8]",
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|||||||
@@ -35,7 +35,7 @@ string_plus_optimization: {
|
|||||||
throw "nope";
|
throw "nope";
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
console.log('0' + throwing_function() ? "yes" : "no");
|
console.log((throwing_function(), "yes"));
|
||||||
} catch (ex) {
|
} catch (ex) {
|
||||||
console.log(ex);
|
console.log(ex);
|
||||||
}
|
}
|
||||||
@@ -46,4 +46,5 @@ string_plus_optimization: {
|
|||||||
}
|
}
|
||||||
foo();
|
foo();
|
||||||
}
|
}
|
||||||
|
expect_stdout: true
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ issue_1321_no_debug: {
|
|||||||
x["a"] = 2 * x.b;
|
x["a"] = 2 * x.b;
|
||||||
console.log(x.b, x["a"]);
|
console.log(x.b, x["a"]);
|
||||||
}
|
}
|
||||||
|
expect_stdout: true
|
||||||
}
|
}
|
||||||
|
|
||||||
issue_1321_debug: {
|
issue_1321_debug: {
|
||||||
@@ -33,6 +34,7 @@ issue_1321_debug: {
|
|||||||
x["_$foo$_"] = 2 * x.a;
|
x["_$foo$_"] = 2 * x.a;
|
||||||
console.log(x.a, x["_$foo$_"]);
|
console.log(x.a, x["_$foo$_"]);
|
||||||
}
|
}
|
||||||
|
expect_stdout: true
|
||||||
}
|
}
|
||||||
|
|
||||||
issue_1321_with_quoted: {
|
issue_1321_with_quoted: {
|
||||||
@@ -51,4 +53,5 @@ issue_1321_with_quoted: {
|
|||||||
x["b"] = 2 * x.a;
|
x["b"] = 2 * x.a;
|
||||||
console.log(x.a, x["b"]);
|
console.log(x.a, x["b"]);
|
||||||
}
|
}
|
||||||
|
expect_stdout: true
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
unsafe_undefined: {
|
unsafe_undefined: {
|
||||||
options = {
|
options = {
|
||||||
|
conditionals: true,
|
||||||
if_return: true,
|
if_return: true,
|
||||||
unsafe: true
|
unsafe: true
|
||||||
}
|
}
|
||||||
@@ -19,12 +20,7 @@ unsafe_undefined: {
|
|||||||
expect: {
|
expect: {
|
||||||
function f(n) {
|
function f(n) {
|
||||||
return function() {
|
return function() {
|
||||||
if (a)
|
return a ? b : c ? d : n;
|
||||||
return b;
|
|
||||||
if (c)
|
|
||||||
return d;
|
|
||||||
else
|
|
||||||
return n;
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -32,6 +28,7 @@ unsafe_undefined: {
|
|||||||
|
|
||||||
keep_fnames: {
|
keep_fnames: {
|
||||||
options = {
|
options = {
|
||||||
|
conditionals: true,
|
||||||
if_return: true,
|
if_return: true,
|
||||||
unsafe: true
|
unsafe: true
|
||||||
}
|
}
|
||||||
@@ -57,12 +54,7 @@ keep_fnames: {
|
|||||||
function n(n) {
|
function n(n) {
|
||||||
return n * n;
|
return n * n;
|
||||||
}
|
}
|
||||||
if (a)
|
return a ? b : c ? d : r;
|
||||||
return b;
|
|
||||||
if (c)
|
|
||||||
return d;
|
|
||||||
else
|
|
||||||
return r;
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -42,4 +42,5 @@ conditional_false_stray_else_in_loop: {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
expect_exact: "for(var i=1;i<=4;++i)if(!(i<=2))console.log(i);"
|
expect_exact: "for(var i=1;i<=4;++i)if(!(i<=2))console.log(i);"
|
||||||
|
expect_stdout: true
|
||||||
}
|
}
|
||||||
|
|||||||
19
test/compress/issue-1569.js
Normal file
19
test/compress/issue-1569.js
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
inner_reference: {
|
||||||
|
options = {
|
||||||
|
side_effects: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
!function f(a) {
|
||||||
|
return a && f(a - 1) + a;
|
||||||
|
}(42);
|
||||||
|
!function g(a) {
|
||||||
|
return a;
|
||||||
|
}(42);
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
!function f(a) {
|
||||||
|
return a && f(a - 1) + a;
|
||||||
|
}(42);
|
||||||
|
!void 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
99
test/compress/issue-1588.js
Normal file
99
test/compress/issue-1588.js
Normal file
@@ -0,0 +1,99 @@
|
|||||||
|
screw_ie8: {
|
||||||
|
options = {
|
||||||
|
screw_ie8: true,
|
||||||
|
}
|
||||||
|
mangle = {
|
||||||
|
screw_ie8: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
try { throw "foo"; } catch (x) { console.log(x); }
|
||||||
|
}
|
||||||
|
expect_exact: 'try{throw"foo"}catch(o){console.log(o)}'
|
||||||
|
expect_stdout: [
|
||||||
|
"foo"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
|
support_ie8: {
|
||||||
|
options = {
|
||||||
|
screw_ie8: false,
|
||||||
|
}
|
||||||
|
mangle = {
|
||||||
|
screw_ie8: false,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
try { throw "foo"; } catch (x) { console.log(x); }
|
||||||
|
}
|
||||||
|
expect_exact: 'try{throw"foo"}catch(x){console.log(x)}'
|
||||||
|
expect_stdout: "foo"
|
||||||
|
}
|
||||||
|
|
||||||
|
safe_undefined: {
|
||||||
|
options = {
|
||||||
|
conditionals: true,
|
||||||
|
if_return: true,
|
||||||
|
unsafe: false,
|
||||||
|
}
|
||||||
|
mangle = {}
|
||||||
|
input: {
|
||||||
|
var a, c;
|
||||||
|
console.log(function(undefined) {
|
||||||
|
return function() {
|
||||||
|
if (a)
|
||||||
|
return b;
|
||||||
|
if (c)
|
||||||
|
return d;
|
||||||
|
};
|
||||||
|
}(1)());
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
var a, c;
|
||||||
|
console.log(function(n) {
|
||||||
|
return function() {
|
||||||
|
return a ? b : c ? d : void 0;
|
||||||
|
};
|
||||||
|
}(1)());
|
||||||
|
}
|
||||||
|
expect_stdout: true
|
||||||
|
}
|
||||||
|
|
||||||
|
unsafe_undefined: {
|
||||||
|
options = {
|
||||||
|
conditionals: true,
|
||||||
|
if_return: true,
|
||||||
|
unsafe: true,
|
||||||
|
}
|
||||||
|
mangle = {}
|
||||||
|
input: {
|
||||||
|
var a, c;
|
||||||
|
console.log(function(undefined) {
|
||||||
|
return function() {
|
||||||
|
if (a)
|
||||||
|
return b;
|
||||||
|
if (c)
|
||||||
|
return d;
|
||||||
|
};
|
||||||
|
}()());
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
var a, c;
|
||||||
|
console.log(function(n) {
|
||||||
|
return function() {
|
||||||
|
return a ? b : c ? d : n;
|
||||||
|
};
|
||||||
|
}()());
|
||||||
|
}
|
||||||
|
expect_stdout: true
|
||||||
|
}
|
||||||
|
|
||||||
|
runtime_error: {
|
||||||
|
input: {
|
||||||
|
const a = 1;
|
||||||
|
console.log(a++);
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
const a = 1;
|
||||||
|
console.log(a++);
|
||||||
|
}
|
||||||
|
expect_stdout: true
|
||||||
|
}
|
||||||
56
test/compress/issue-1609.js
Normal file
56
test/compress/issue-1609.js
Normal file
@@ -0,0 +1,56 @@
|
|||||||
|
chained_evaluation_1: {
|
||||||
|
options = {
|
||||||
|
collapse_vars: true,
|
||||||
|
evaluate: true,
|
||||||
|
reduce_vars: true,
|
||||||
|
unused: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
(function() {
|
||||||
|
var a = 1;
|
||||||
|
(function() {
|
||||||
|
var b = a, c;
|
||||||
|
c = f(b);
|
||||||
|
c.bar = b;
|
||||||
|
})();
|
||||||
|
})();
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
(function() {
|
||||||
|
(function() {
|
||||||
|
var c;
|
||||||
|
c = f(1);
|
||||||
|
c.bar = 1;
|
||||||
|
})();
|
||||||
|
})();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
chained_evaluation_2: {
|
||||||
|
options = {
|
||||||
|
collapse_vars: true,
|
||||||
|
evaluate: true,
|
||||||
|
reduce_vars: true,
|
||||||
|
unused: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
(function() {
|
||||||
|
var a = "long piece of string";
|
||||||
|
(function() {
|
||||||
|
var b = a, c;
|
||||||
|
c = f(b);
|
||||||
|
c.bar = b;
|
||||||
|
})();
|
||||||
|
})();
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
(function() {
|
||||||
|
var a = "long piece of string";
|
||||||
|
(function() {
|
||||||
|
var c;
|
||||||
|
c = f(a);
|
||||||
|
c.bar = a;
|
||||||
|
})();
|
||||||
|
})();
|
||||||
|
}
|
||||||
|
}
|
||||||
88
test/compress/issue-1639.js
Normal file
88
test/compress/issue-1639.js
Normal file
@@ -0,0 +1,88 @@
|
|||||||
|
|
||||||
|
issue_1639_1: {
|
||||||
|
options = {
|
||||||
|
booleans: true,
|
||||||
|
cascade: true,
|
||||||
|
conditionals: true,
|
||||||
|
evaluate: true,
|
||||||
|
join_vars: true,
|
||||||
|
loops: true,
|
||||||
|
sequences: true,
|
||||||
|
side_effects: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
var a = 100, b = 10;
|
||||||
|
|
||||||
|
var L1 = 5;
|
||||||
|
while (--L1 > 0) {
|
||||||
|
if ((--b), false) {
|
||||||
|
if (b) {
|
||||||
|
var ignore = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log(a, b);
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
for (var a = 100, b = 10, L1 = 5; --L1 > 0;)
|
||||||
|
if (--b, !1) var ignore = 0;
|
||||||
|
console.log(a, b);
|
||||||
|
}
|
||||||
|
expect_stdout: true
|
||||||
|
}
|
||||||
|
|
||||||
|
issue_1639_2: {
|
||||||
|
options = {
|
||||||
|
booleans: true,
|
||||||
|
cascade: true,
|
||||||
|
conditionals: true,
|
||||||
|
evaluate: true,
|
||||||
|
join_vars: true,
|
||||||
|
sequences: true,
|
||||||
|
side_effects: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
var a = 100, b = 10;
|
||||||
|
|
||||||
|
function f19() {
|
||||||
|
if (++a, false)
|
||||||
|
if (a)
|
||||||
|
if (++a);
|
||||||
|
}
|
||||||
|
f19();
|
||||||
|
|
||||||
|
console.log(a, b);
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
var a = 100, b = 10;
|
||||||
|
function f19() {
|
||||||
|
++a, 1;
|
||||||
|
}
|
||||||
|
f19(),
|
||||||
|
console.log(a, b);
|
||||||
|
}
|
||||||
|
expect_stdout: true
|
||||||
|
}
|
||||||
|
|
||||||
|
issue_1639_3: {
|
||||||
|
options = {
|
||||||
|
booleans: true,
|
||||||
|
cascade: true,
|
||||||
|
conditionals: true,
|
||||||
|
evaluate: true,
|
||||||
|
sequences: true,
|
||||||
|
side_effects: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
var a = 100, b = 10;
|
||||||
|
a++ && false && a ? 0 : 0;
|
||||||
|
console.log(a, b);
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
var a = 100, b = 10;
|
||||||
|
a++,
|
||||||
|
console.log(a, b);
|
||||||
|
}
|
||||||
|
expect_stdout: true
|
||||||
|
}
|
||||||
45
test/compress/issue-1656.js
Normal file
45
test/compress/issue-1656.js
Normal file
@@ -0,0 +1,45 @@
|
|||||||
|
f7: {
|
||||||
|
options = {
|
||||||
|
booleans: true,
|
||||||
|
cascade: true,
|
||||||
|
collapse_vars: true,
|
||||||
|
comparisons: true,
|
||||||
|
conditionals: true,
|
||||||
|
dead_code: true,
|
||||||
|
drop_debugger: true,
|
||||||
|
evaluate: true,
|
||||||
|
hoist_funs: true,
|
||||||
|
if_return: true,
|
||||||
|
join_vars: true,
|
||||||
|
loops: true,
|
||||||
|
negate_iife: true,
|
||||||
|
passes: 3,
|
||||||
|
properties: true,
|
||||||
|
reduce_vars: true,
|
||||||
|
sequences: true,
|
||||||
|
side_effects: true,
|
||||||
|
toplevel: true,
|
||||||
|
unused: true,
|
||||||
|
}
|
||||||
|
beautify = {
|
||||||
|
beautify: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
var a = 100, b = 10;
|
||||||
|
function f22464() {
|
||||||
|
var brake146670 = 5;
|
||||||
|
while (((b = a) ? !a : ~a ? null : b += a) && --brake146670 > 0) {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
f22464();
|
||||||
|
console.log(a, b);
|
||||||
|
}
|
||||||
|
expect_exact: [
|
||||||
|
"var a = 100, b = 10;",
|
||||||
|
"",
|
||||||
|
"!function() {",
|
||||||
|
" for (;b = a, !1; ) ;",
|
||||||
|
"}(), console.log(a, b);",
|
||||||
|
]
|
||||||
|
expect_stdout: true
|
||||||
|
}
|
||||||
159
test/compress/issue-1673.js
Normal file
159
test/compress/issue-1673.js
Normal file
@@ -0,0 +1,159 @@
|
|||||||
|
side_effects_catch: {
|
||||||
|
options = {
|
||||||
|
reduce_vars: true,
|
||||||
|
side_effects: true,
|
||||||
|
unused: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
function f() {
|
||||||
|
function g() {
|
||||||
|
try {
|
||||||
|
throw 0;
|
||||||
|
} catch (e) {
|
||||||
|
console.log("PASS");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
g();
|
||||||
|
}
|
||||||
|
f();
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
function f() {
|
||||||
|
(function() {
|
||||||
|
try {
|
||||||
|
throw 0;
|
||||||
|
} catch (e) {
|
||||||
|
console.log("PASS");
|
||||||
|
}
|
||||||
|
})();
|
||||||
|
}
|
||||||
|
f();
|
||||||
|
}
|
||||||
|
expect_stdout: "PASS"
|
||||||
|
}
|
||||||
|
|
||||||
|
side_effects_else: {
|
||||||
|
options = {
|
||||||
|
reduce_vars: true,
|
||||||
|
side_effects: true,
|
||||||
|
unused: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
function f(x) {
|
||||||
|
function g() {
|
||||||
|
if (x);
|
||||||
|
else console.log("PASS");
|
||||||
|
}
|
||||||
|
g();
|
||||||
|
}
|
||||||
|
f(0);
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
function f(x) {
|
||||||
|
(function() {
|
||||||
|
if (x);
|
||||||
|
else console.log("PASS");
|
||||||
|
})();
|
||||||
|
}
|
||||||
|
f(0);
|
||||||
|
}
|
||||||
|
expect_stdout: "PASS"
|
||||||
|
}
|
||||||
|
|
||||||
|
side_effects_finally: {
|
||||||
|
options = {
|
||||||
|
reduce_vars: true,
|
||||||
|
side_effects: true,
|
||||||
|
unused: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
function f() {
|
||||||
|
function g() {
|
||||||
|
try {
|
||||||
|
} catch (e) {
|
||||||
|
} finally {
|
||||||
|
console.log("PASS");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
g();
|
||||||
|
}
|
||||||
|
f();
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
function f() {
|
||||||
|
(function() {
|
||||||
|
try {
|
||||||
|
} catch (e) {
|
||||||
|
} finally {
|
||||||
|
console.log("PASS");
|
||||||
|
}
|
||||||
|
})();
|
||||||
|
}
|
||||||
|
f();
|
||||||
|
}
|
||||||
|
expect_stdout: "PASS"
|
||||||
|
}
|
||||||
|
|
||||||
|
side_effects_label: {
|
||||||
|
options = {
|
||||||
|
reduce_vars: true,
|
||||||
|
side_effects: true,
|
||||||
|
unused: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
function f(x) {
|
||||||
|
function g() {
|
||||||
|
L: {
|
||||||
|
console.log("PASS");
|
||||||
|
break L;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
g();
|
||||||
|
}
|
||||||
|
f(0);
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
function f(x) {
|
||||||
|
(function() {
|
||||||
|
L: {
|
||||||
|
console.log("PASS");
|
||||||
|
break L;
|
||||||
|
}
|
||||||
|
})();
|
||||||
|
}
|
||||||
|
f(0);
|
||||||
|
}
|
||||||
|
expect_stdout: "PASS"
|
||||||
|
}
|
||||||
|
|
||||||
|
side_effects_switch: {
|
||||||
|
options = {
|
||||||
|
reduce_vars: true,
|
||||||
|
side_effects: true,
|
||||||
|
unused: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
function f() {
|
||||||
|
function g() {
|
||||||
|
switch (0) {
|
||||||
|
default:
|
||||||
|
case console.log("PASS"):
|
||||||
|
}
|
||||||
|
}
|
||||||
|
g();
|
||||||
|
}
|
||||||
|
f();
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
function f() {
|
||||||
|
(function() {
|
||||||
|
switch (0) {
|
||||||
|
default:
|
||||||
|
case console.log("PASS"):
|
||||||
|
}
|
||||||
|
})();
|
||||||
|
}
|
||||||
|
f();
|
||||||
|
}
|
||||||
|
expect_stdout: "PASS"
|
||||||
|
}
|
||||||
347
test/compress/issue-1704.js
Normal file
347
test/compress/issue-1704.js
Normal file
@@ -0,0 +1,347 @@
|
|||||||
|
mangle_catch: {
|
||||||
|
options = {
|
||||||
|
screw_ie8: true,
|
||||||
|
toplevel: false,
|
||||||
|
}
|
||||||
|
mangle = {
|
||||||
|
screw_ie8: true,
|
||||||
|
toplevel: false,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
var a = "FAIL";
|
||||||
|
try {
|
||||||
|
throw 1;
|
||||||
|
} catch (args) {
|
||||||
|
a = "PASS";
|
||||||
|
}
|
||||||
|
console.log(a);
|
||||||
|
}
|
||||||
|
expect_exact: 'var a="FAIL";try{throw 1}catch(o){a="PASS"}console.log(a);'
|
||||||
|
expect_stdout: "PASS"
|
||||||
|
}
|
||||||
|
|
||||||
|
mangle_catch_ie8: {
|
||||||
|
options = {
|
||||||
|
screw_ie8: false,
|
||||||
|
toplevel: false,
|
||||||
|
}
|
||||||
|
mangle = {
|
||||||
|
screw_ie8: false,
|
||||||
|
toplevel: false,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
var a = "FAIL";
|
||||||
|
try {
|
||||||
|
throw 1;
|
||||||
|
} catch (args) {
|
||||||
|
a = "PASS";
|
||||||
|
}
|
||||||
|
console.log(a);
|
||||||
|
}
|
||||||
|
expect_exact: 'var a="FAIL";try{throw 1}catch(args){a="PASS"}console.log(a);'
|
||||||
|
expect_stdout: "PASS"
|
||||||
|
}
|
||||||
|
|
||||||
|
mangle_catch_var: {
|
||||||
|
options = {
|
||||||
|
screw_ie8: true,
|
||||||
|
toplevel: false,
|
||||||
|
}
|
||||||
|
mangle = {
|
||||||
|
screw_ie8: true,
|
||||||
|
toplevel: false,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
var a = "FAIL";
|
||||||
|
try {
|
||||||
|
throw 1;
|
||||||
|
} catch (args) {
|
||||||
|
var a = "PASS";
|
||||||
|
}
|
||||||
|
console.log(a);
|
||||||
|
}
|
||||||
|
expect_exact: 'var a="FAIL";try{throw 1}catch(o){var a="PASS"}console.log(a);'
|
||||||
|
expect_stdout: "PASS"
|
||||||
|
}
|
||||||
|
|
||||||
|
mangle_catch_var_ie8: {
|
||||||
|
options = {
|
||||||
|
screw_ie8: false,
|
||||||
|
toplevel: false,
|
||||||
|
}
|
||||||
|
mangle = {
|
||||||
|
screw_ie8: false,
|
||||||
|
toplevel: false,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
var a = "FAIL";
|
||||||
|
try {
|
||||||
|
throw 1;
|
||||||
|
} catch (args) {
|
||||||
|
var a = "PASS";
|
||||||
|
}
|
||||||
|
console.log(a);
|
||||||
|
}
|
||||||
|
expect_exact: 'var a="FAIL";try{throw 1}catch(args){var a="PASS"}console.log(a);'
|
||||||
|
expect_stdout: "PASS"
|
||||||
|
}
|
||||||
|
|
||||||
|
mangle_catch_toplevel: {
|
||||||
|
options = {
|
||||||
|
screw_ie8: true,
|
||||||
|
toplevel: true,
|
||||||
|
}
|
||||||
|
mangle = {
|
||||||
|
screw_ie8: true,
|
||||||
|
toplevel: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
var a = "FAIL";
|
||||||
|
try {
|
||||||
|
throw 1;
|
||||||
|
} catch (args) {
|
||||||
|
a = "PASS";
|
||||||
|
}
|
||||||
|
console.log(a);
|
||||||
|
}
|
||||||
|
expect_exact: 'var o="FAIL";try{throw 1}catch(c){o="PASS"}console.log(o);'
|
||||||
|
expect_stdout: "PASS"
|
||||||
|
}
|
||||||
|
|
||||||
|
mangle_catch_ie8_toplevel: {
|
||||||
|
options = {
|
||||||
|
screw_ie8: false,
|
||||||
|
toplevel: true,
|
||||||
|
}
|
||||||
|
mangle = {
|
||||||
|
screw_ie8: false,
|
||||||
|
toplevel: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
var a = "FAIL";
|
||||||
|
try {
|
||||||
|
throw 1;
|
||||||
|
} catch (args) {
|
||||||
|
a = "PASS";
|
||||||
|
}
|
||||||
|
console.log(a);
|
||||||
|
}
|
||||||
|
expect_exact: 'var o="FAIL";try{throw 1}catch(c){o="PASS"}console.log(o);'
|
||||||
|
expect_stdout: "PASS"
|
||||||
|
}
|
||||||
|
|
||||||
|
mangle_catch_var_toplevel: {
|
||||||
|
options = {
|
||||||
|
screw_ie8: true,
|
||||||
|
toplevel: true,
|
||||||
|
}
|
||||||
|
mangle = {
|
||||||
|
screw_ie8: true,
|
||||||
|
toplevel: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
var a = "FAIL";
|
||||||
|
try {
|
||||||
|
throw 1;
|
||||||
|
} catch (args) {
|
||||||
|
var a = "PASS";
|
||||||
|
}
|
||||||
|
console.log(a);
|
||||||
|
}
|
||||||
|
expect_exact: 'var o="FAIL";try{throw 1}catch(r){var o="PASS"}console.log(o);'
|
||||||
|
expect_stdout: "PASS"
|
||||||
|
}
|
||||||
|
|
||||||
|
mangle_catch_var_ie8_toplevel: {
|
||||||
|
options = {
|
||||||
|
screw_ie8: false,
|
||||||
|
toplevel: true,
|
||||||
|
}
|
||||||
|
mangle = {
|
||||||
|
screw_ie8: false,
|
||||||
|
toplevel: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
var a = "FAIL";
|
||||||
|
try {
|
||||||
|
throw 1;
|
||||||
|
} catch (args) {
|
||||||
|
var a = "PASS";
|
||||||
|
}
|
||||||
|
console.log(a);
|
||||||
|
}
|
||||||
|
expect_exact: 'var o="FAIL";try{throw 1}catch(r){var o="PASS"}console.log(o);'
|
||||||
|
expect_stdout: "PASS"
|
||||||
|
}
|
||||||
|
|
||||||
|
mangle_catch_redef_1: {
|
||||||
|
options = {
|
||||||
|
screw_ie8: true,
|
||||||
|
toplevel: false,
|
||||||
|
}
|
||||||
|
mangle = {
|
||||||
|
screw_ie8: true,
|
||||||
|
toplevel: false,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
var a = "PASS";
|
||||||
|
try {
|
||||||
|
throw "FAIL1";
|
||||||
|
} catch (a) {
|
||||||
|
var a = "FAIL2";
|
||||||
|
}
|
||||||
|
console.log(a);
|
||||||
|
}
|
||||||
|
expect_exact: 'var a="PASS";try{throw"FAIL1"}catch(a){var a="FAIL2"}console.log(a);'
|
||||||
|
expect_stdout: "PASS"
|
||||||
|
}
|
||||||
|
|
||||||
|
mangle_catch_redef_1_ie8: {
|
||||||
|
options = {
|
||||||
|
screw_ie8: false,
|
||||||
|
toplevel: false,
|
||||||
|
}
|
||||||
|
mangle = {
|
||||||
|
screw_ie8: false,
|
||||||
|
toplevel: false,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
var a = "PASS";
|
||||||
|
try {
|
||||||
|
throw "FAIL1";
|
||||||
|
} catch (a) {
|
||||||
|
var a = "FAIL2";
|
||||||
|
}
|
||||||
|
console.log(a);
|
||||||
|
}
|
||||||
|
expect_exact: 'var a="PASS";try{throw"FAIL1"}catch(a){var a="FAIL2"}console.log(a);'
|
||||||
|
expect_stdout: "PASS"
|
||||||
|
}
|
||||||
|
|
||||||
|
mangle_catch_redef_1_toplevel: {
|
||||||
|
options = {
|
||||||
|
screw_ie8: true,
|
||||||
|
toplevel: true,
|
||||||
|
}
|
||||||
|
mangle = {
|
||||||
|
screw_ie8: true,
|
||||||
|
toplevel: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
var a = "PASS";
|
||||||
|
try {
|
||||||
|
throw "FAIL1";
|
||||||
|
} catch (a) {
|
||||||
|
var a = "FAIL2";
|
||||||
|
}
|
||||||
|
console.log(a);
|
||||||
|
}
|
||||||
|
expect_exact: 'var o="PASS";try{throw"FAIL1"}catch(o){var o="FAIL2"}console.log(o);'
|
||||||
|
expect_stdout: "PASS"
|
||||||
|
}
|
||||||
|
|
||||||
|
mangle_catch_redef_1_ie8_toplevel: {
|
||||||
|
options = {
|
||||||
|
screw_ie8: false,
|
||||||
|
toplevel: true,
|
||||||
|
}
|
||||||
|
mangle = {
|
||||||
|
screw_ie8: false,
|
||||||
|
toplevel: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
var a = "PASS";
|
||||||
|
try {
|
||||||
|
throw "FAIL1";
|
||||||
|
} catch (a) {
|
||||||
|
var a = "FAIL2";
|
||||||
|
}
|
||||||
|
console.log(a);
|
||||||
|
}
|
||||||
|
expect_exact: 'var o="PASS";try{throw"FAIL1"}catch(o){var o="FAIL2"}console.log(o);'
|
||||||
|
expect_stdout: "PASS"
|
||||||
|
}
|
||||||
|
|
||||||
|
mangle_catch_redef_2: {
|
||||||
|
options = {
|
||||||
|
screw_ie8: true,
|
||||||
|
toplevel: false,
|
||||||
|
}
|
||||||
|
mangle = {
|
||||||
|
screw_ie8: true,
|
||||||
|
toplevel: false,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
try {
|
||||||
|
throw "FAIL1";
|
||||||
|
} catch (a) {
|
||||||
|
var a = "FAIL2";
|
||||||
|
}
|
||||||
|
console.log(a);
|
||||||
|
}
|
||||||
|
expect_exact: 'try{throw"FAIL1"}catch(a){var a="FAIL2"}console.log(a);'
|
||||||
|
expect_stdout: "undefined"
|
||||||
|
}
|
||||||
|
|
||||||
|
mangle_catch_redef_2_ie8: {
|
||||||
|
options = {
|
||||||
|
screw_ie8: false,
|
||||||
|
toplevel: false,
|
||||||
|
}
|
||||||
|
mangle = {
|
||||||
|
screw_ie8: false,
|
||||||
|
toplevel: false,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
try {
|
||||||
|
throw "FAIL1";
|
||||||
|
} catch (a) {
|
||||||
|
var a = "FAIL2";
|
||||||
|
}
|
||||||
|
console.log(a);
|
||||||
|
}
|
||||||
|
expect_exact: 'try{throw"FAIL1"}catch(a){var a="FAIL2"}console.log(a);'
|
||||||
|
expect_stdout: "undefined"
|
||||||
|
}
|
||||||
|
|
||||||
|
mangle_catch_redef_2_toplevel: {
|
||||||
|
options = {
|
||||||
|
screw_ie8: true,
|
||||||
|
toplevel: true,
|
||||||
|
}
|
||||||
|
mangle = {
|
||||||
|
screw_ie8: true,
|
||||||
|
toplevel: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
try {
|
||||||
|
throw "FAIL1";
|
||||||
|
} catch (a) {
|
||||||
|
var a = "FAIL2";
|
||||||
|
}
|
||||||
|
console.log(a);
|
||||||
|
}
|
||||||
|
expect_exact: 'try{throw"FAIL1"}catch(o){var o="FAIL2"}console.log(o);'
|
||||||
|
expect_stdout: "undefined"
|
||||||
|
}
|
||||||
|
|
||||||
|
mangle_catch_redef_2_ie8_toplevel: {
|
||||||
|
options = {
|
||||||
|
screw_ie8: false,
|
||||||
|
toplevel: true,
|
||||||
|
}
|
||||||
|
mangle = {
|
||||||
|
screw_ie8: false,
|
||||||
|
toplevel: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
try {
|
||||||
|
throw "FAIL1";
|
||||||
|
} catch (a) {
|
||||||
|
var a = "FAIL2";
|
||||||
|
}
|
||||||
|
console.log(a);
|
||||||
|
}
|
||||||
|
expect_exact: 'try{throw"FAIL1"}catch(o){var o="FAIL2"}console.log(o);'
|
||||||
|
expect_stdout: "undefined"
|
||||||
|
}
|
||||||
55
test/compress/issue-368.js
Normal file
55
test/compress/issue-368.js
Normal file
@@ -0,0 +1,55 @@
|
|||||||
|
collapse: {
|
||||||
|
options = {
|
||||||
|
cascade: true,
|
||||||
|
sequences: true,
|
||||||
|
side_effects: true,
|
||||||
|
unused: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
function f1() {
|
||||||
|
var a;
|
||||||
|
a = typeof b === 'function' ? b() : b;
|
||||||
|
return a !== undefined && c();
|
||||||
|
}
|
||||||
|
function f2(b) {
|
||||||
|
var a;
|
||||||
|
b = c();
|
||||||
|
a = typeof b === 'function' ? b() : b;
|
||||||
|
return 'stirng' == typeof a && d();
|
||||||
|
}
|
||||||
|
function f3(c) {
|
||||||
|
var a;
|
||||||
|
a = b(a / 2);
|
||||||
|
if (a < 0) {
|
||||||
|
a++;
|
||||||
|
++c;
|
||||||
|
return c / 2;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
function f4(c) {
|
||||||
|
var a;
|
||||||
|
a = b(a / 2);
|
||||||
|
if (a < 0) {
|
||||||
|
a++;
|
||||||
|
c++;
|
||||||
|
return c / 2;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
function f1() {
|
||||||
|
return void 0 !== ('function' === typeof b ? b() : b) && c();
|
||||||
|
}
|
||||||
|
function f2(b) {
|
||||||
|
return b = c(), 'stirng' == typeof ('function' === typeof b ? b() : b) && d();
|
||||||
|
}
|
||||||
|
function f3(c) {
|
||||||
|
var a;
|
||||||
|
if ((a = b(a / 2)) < 0) return a++, ++c / 2;
|
||||||
|
}
|
||||||
|
function f4(c) {
|
||||||
|
var a;
|
||||||
|
if ((a = b(a / 2)) < 0) return a++, ++c / 2;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
320
test/compress/issue-640.js
Normal file
320
test/compress/issue-640.js
Normal file
@@ -0,0 +1,320 @@
|
|||||||
|
cond_5: {
|
||||||
|
options = {
|
||||||
|
conditionals: true,
|
||||||
|
expression: 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();
|
||||||
|
if (some_condition() && some_other_condition()) do_something();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
dead_code_const_annotation_regex: {
|
||||||
|
options = {
|
||||||
|
booleans : true,
|
||||||
|
conditionals : true,
|
||||||
|
dead_code : true,
|
||||||
|
evaluate : true,
|
||||||
|
expression : true,
|
||||||
|
loops : true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
var unused;
|
||||||
|
// @constraint this shouldn't be a constant
|
||||||
|
var CONST_FOO_ANN = false;
|
||||||
|
if (CONST_FOO_ANN) {
|
||||||
|
console.log("reachable");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
var unused;
|
||||||
|
var CONST_FOO_ANN = !1;
|
||||||
|
if (CONST_FOO_ANN) console.log('reachable');
|
||||||
|
}
|
||||||
|
expect_stdout: true
|
||||||
|
}
|
||||||
|
|
||||||
|
drop_console_2: {
|
||||||
|
options = {
|
||||||
|
drop_console: true,
|
||||||
|
expression: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
console.log('foo');
|
||||||
|
console.log.apply(console, arguments);
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
// with regular compression these will be stripped out as well
|
||||||
|
void 0;
|
||||||
|
void 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
drop_value: {
|
||||||
|
options = {
|
||||||
|
expression: true,
|
||||||
|
side_effects: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
(1, [2, foo()], 3, {a:1, b:bar()});
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
foo(), {a:1, b:bar()};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
wrongly_optimized: {
|
||||||
|
options = {
|
||||||
|
conditionals: true,
|
||||||
|
booleans: true,
|
||||||
|
evaluate: true,
|
||||||
|
expression: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
function func() {
|
||||||
|
foo();
|
||||||
|
}
|
||||||
|
if (func() || true) {
|
||||||
|
bar();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
function func() {
|
||||||
|
foo();
|
||||||
|
}
|
||||||
|
// TODO: optimize to `func(), bar()`
|
||||||
|
if (func(), !0) bar();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
negate_iife_1: {
|
||||||
|
options = {
|
||||||
|
expression: true,
|
||||||
|
negate_iife: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
(function(){ stuff() })();
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
(function(){ stuff() })();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
negate_iife_3: {
|
||||||
|
options = {
|
||||||
|
conditionals: true,
|
||||||
|
expression: true,
|
||||||
|
negate_iife: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
(function(){ return t })() ? console.log(true) : console.log(false);
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
(function(){ return t })() ? console.log(true) : console.log(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
negate_iife_3_off: {
|
||||||
|
options = {
|
||||||
|
conditionals: true,
|
||||||
|
expression: true,
|
||||||
|
negate_iife: false,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
(function(){ return t })() ? console.log(true) : console.log(false);
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
(function(){ return t })() ? console.log(true) : console.log(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
negate_iife_4: {
|
||||||
|
options = {
|
||||||
|
conditionals: true,
|
||||||
|
expression: true,
|
||||||
|
negate_iife: true,
|
||||||
|
sequences: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
(function(){ return t })() ? console.log(true) : console.log(false);
|
||||||
|
(function(){
|
||||||
|
console.log("something");
|
||||||
|
})();
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
(function(){ return t })() ? console.log(true) : console.log(false), function(){
|
||||||
|
console.log("something");
|
||||||
|
}();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
negate_iife_5: {
|
||||||
|
options = {
|
||||||
|
conditionals: true,
|
||||||
|
expression: true,
|
||||||
|
negate_iife: true,
|
||||||
|
sequences: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
if ((function(){ return t })()) {
|
||||||
|
foo(true);
|
||||||
|
} else {
|
||||||
|
bar(false);
|
||||||
|
}
|
||||||
|
(function(){
|
||||||
|
console.log("something");
|
||||||
|
})();
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
(function(){ return t })() ? foo(true) : bar(false), function(){
|
||||||
|
console.log("something");
|
||||||
|
}();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
negate_iife_5_off: {
|
||||||
|
options = {
|
||||||
|
conditionals: true,
|
||||||
|
expression: true,
|
||||||
|
negate_iife: false,
|
||||||
|
sequences: true,
|
||||||
|
};
|
||||||
|
input: {
|
||||||
|
if ((function(){ return t })()) {
|
||||||
|
foo(true);
|
||||||
|
} else {
|
||||||
|
bar(false);
|
||||||
|
}
|
||||||
|
(function(){
|
||||||
|
console.log("something");
|
||||||
|
})();
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
(function(){ return t })() ? foo(true) : bar(false), function(){
|
||||||
|
console.log("something");
|
||||||
|
}();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
issue_1254_negate_iife_true: {
|
||||||
|
options = {
|
||||||
|
expression: true,
|
||||||
|
negate_iife: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
(function() {
|
||||||
|
return function() {
|
||||||
|
console.log('test')
|
||||||
|
};
|
||||||
|
})()();
|
||||||
|
}
|
||||||
|
expect_exact: '(function(){return function(){console.log("test")}})()();'
|
||||||
|
expect_stdout: true
|
||||||
|
}
|
||||||
|
|
||||||
|
issue_1254_negate_iife_nested: {
|
||||||
|
options = {
|
||||||
|
expression: true,
|
||||||
|
negate_iife: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
(function() {
|
||||||
|
return function() {
|
||||||
|
console.log('test')
|
||||||
|
};
|
||||||
|
})()()()()();
|
||||||
|
}
|
||||||
|
expect_exact: '(function(){return function(){console.log("test")}})()()()()();'
|
||||||
|
expect_stdout: true
|
||||||
|
}
|
||||||
|
|
||||||
|
conditional: {
|
||||||
|
options = {
|
||||||
|
expression: true,
|
||||||
|
pure_funcs: [ "pure" ],
|
||||||
|
side_effects: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
pure(1 | a() ? 2 & b() : 7 ^ c());
|
||||||
|
pure(1 | a() ? 2 & b() : 5);
|
||||||
|
pure(1 | a() ? 4 : 7 ^ c());
|
||||||
|
pure(1 | a() ? 4 : 5);
|
||||||
|
pure(3 ? 2 & b() : 7 ^ c());
|
||||||
|
pure(3 ? 2 & b() : 5);
|
||||||
|
pure(3 ? 4 : 7 ^ c());
|
||||||
|
pure(3 ? 4 : 5);
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
1 | a() ? b() : c();
|
||||||
|
1 | a() && b();
|
||||||
|
1 | a() || c();
|
||||||
|
a();
|
||||||
|
3 ? b() : c();
|
||||||
|
3 && b();
|
||||||
|
3 || c();
|
||||||
|
pure(3 ? 4 : 5);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
limit_1: {
|
||||||
|
options = {
|
||||||
|
expression: true,
|
||||||
|
sequences: 3,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
a;
|
||||||
|
b;
|
||||||
|
c;
|
||||||
|
d;
|
||||||
|
e;
|
||||||
|
f;
|
||||||
|
g;
|
||||||
|
h;
|
||||||
|
i;
|
||||||
|
j;
|
||||||
|
k;
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
// Turned into a single return statement
|
||||||
|
// so it can no longer be split into lines
|
||||||
|
a,b,c,d,e,f,g,h,i,j,k;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
iife: {
|
||||||
|
options = {
|
||||||
|
expression: true,
|
||||||
|
sequences: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
x = 42;
|
||||||
|
(function a() {})();
|
||||||
|
!function b() {}();
|
||||||
|
~function c() {}();
|
||||||
|
+function d() {}();
|
||||||
|
-function e() {}();
|
||||||
|
void function f() {}();
|
||||||
|
typeof function g() {}();
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
x = 42, function a() {}(), function b() {}(), function c() {}(),
|
||||||
|
function d() {}(), function e() {}(), function f() {}(), typeof function g() {}();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -29,4 +29,5 @@ dont_mangle_arguments: {
|
|||||||
})(5,6,7);
|
})(5,6,7);
|
||||||
}
|
}
|
||||||
expect_exact: "(function(){var arguments=arguments,o=9;console.log(o,arguments)})(5,6,7);"
|
expect_exact: "(function(){var arguments=arguments,o=9;console.log(o,arguments)})(5,6,7);"
|
||||||
|
expect_stdout: true
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -50,6 +50,7 @@ this_binding_conditionals: {
|
|||||||
this_binding_collapse_vars: {
|
this_binding_collapse_vars: {
|
||||||
options = {
|
options = {
|
||||||
collapse_vars: true,
|
collapse_vars: true,
|
||||||
|
toplevel: true,
|
||||||
};
|
};
|
||||||
input: {
|
input: {
|
||||||
var c = a; c();
|
var c = a; c();
|
||||||
|
|||||||
@@ -42,6 +42,7 @@ eval_collapse_vars: {
|
|||||||
eval("console.log(a);");
|
eval("console.log(a);");
|
||||||
})(eval);
|
})(eval);
|
||||||
}
|
}
|
||||||
|
expect_stdout: true
|
||||||
}
|
}
|
||||||
|
|
||||||
eval_unused: {
|
eval_unused: {
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ labels_1: {
|
|||||||
expect: {
|
expect: {
|
||||||
foo || console.log("bar");
|
foo || console.log("bar");
|
||||||
}
|
}
|
||||||
|
expect_stdout: true
|
||||||
}
|
}
|
||||||
|
|
||||||
labels_2: {
|
labels_2: {
|
||||||
@@ -40,6 +41,7 @@ labels_3: {
|
|||||||
for (var i = 0; i < 5; ++i)
|
for (var i = 0; i < 5; ++i)
|
||||||
i < 3 || console.log(i);
|
i < 3 || console.log(i);
|
||||||
}
|
}
|
||||||
|
expect_stdout: true
|
||||||
}
|
}
|
||||||
|
|
||||||
labels_4: {
|
labels_4: {
|
||||||
@@ -54,6 +56,7 @@ labels_4: {
|
|||||||
for (var i = 0; i < 5; ++i)
|
for (var i = 0; i < 5; ++i)
|
||||||
i < 3 || console.log(i);
|
i < 3 || console.log(i);
|
||||||
}
|
}
|
||||||
|
expect_stdout: true
|
||||||
}
|
}
|
||||||
|
|
||||||
labels_5: {
|
labels_5: {
|
||||||
|
|||||||
@@ -166,6 +166,7 @@ keep_collapse_const_in_own_block_scope: {
|
|||||||
console.log(i);
|
console.log(i);
|
||||||
console.log(c);
|
console.log(c);
|
||||||
}
|
}
|
||||||
|
expect_stdout: true
|
||||||
}
|
}
|
||||||
|
|
||||||
keep_collapse_const_in_own_block_scope_2: {
|
keep_collapse_const_in_own_block_scope_2: {
|
||||||
@@ -186,6 +187,7 @@ keep_collapse_const_in_own_block_scope_2: {
|
|||||||
console.log(i);
|
console.log(i);
|
||||||
console.log(c);
|
console.log(c);
|
||||||
}
|
}
|
||||||
|
expect_stdout: true
|
||||||
}
|
}
|
||||||
|
|
||||||
evaluate: {
|
evaluate: {
|
||||||
@@ -213,6 +215,246 @@ evaluate: {
|
|||||||
a();
|
a();
|
||||||
for(;;)
|
for(;;)
|
||||||
c();
|
c();
|
||||||
d();
|
// rule disabled due to issue_1532
|
||||||
|
do d(); while (false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
issue_1532: {
|
||||||
|
options = {
|
||||||
|
evaluate: true,
|
||||||
|
loops: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
function f(x, y) {
|
||||||
|
do {
|
||||||
|
if (x) break;
|
||||||
|
foo();
|
||||||
|
} while (false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
function f(x, y) {
|
||||||
|
do {
|
||||||
|
if (x) break;
|
||||||
|
foo();
|
||||||
|
} while (false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
issue_186: {
|
||||||
|
beautify = {
|
||||||
|
beautify: false,
|
||||||
|
screw_ie8: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
var x = 3;
|
||||||
|
if (foo())
|
||||||
|
do
|
||||||
|
do
|
||||||
|
alert(x);
|
||||||
|
while (--x);
|
||||||
|
while (x);
|
||||||
|
else
|
||||||
|
bar();
|
||||||
|
}
|
||||||
|
expect_exact: 'var x=3;if(foo())do{do{alert(x)}while(--x)}while(x);else bar();'
|
||||||
|
}
|
||||||
|
|
||||||
|
issue_186_ie8: {
|
||||||
|
beautify = {
|
||||||
|
beautify: false,
|
||||||
|
screw_ie8: false,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
var x = 3;
|
||||||
|
if (foo())
|
||||||
|
do
|
||||||
|
do
|
||||||
|
alert(x);
|
||||||
|
while (--x);
|
||||||
|
while (x);
|
||||||
|
else
|
||||||
|
bar();
|
||||||
|
}
|
||||||
|
expect_exact: 'var x=3;if(foo()){do{do{alert(x)}while(--x)}while(x)}else bar();'
|
||||||
|
}
|
||||||
|
|
||||||
|
issue_186_beautify: {
|
||||||
|
beautify = {
|
||||||
|
beautify: true,
|
||||||
|
screw_ie8: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
var x = 3;
|
||||||
|
if (foo())
|
||||||
|
do
|
||||||
|
do
|
||||||
|
alert(x);
|
||||||
|
while (--x);
|
||||||
|
while (x);
|
||||||
|
else
|
||||||
|
bar();
|
||||||
|
}
|
||||||
|
expect_exact: [
|
||||||
|
'var x = 3;',
|
||||||
|
'',
|
||||||
|
'if (foo()) do {',
|
||||||
|
' do {',
|
||||||
|
' alert(x);',
|
||||||
|
' } while (--x);',
|
||||||
|
'} while (x); else bar();',
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
|
issue_186_beautify_ie8: {
|
||||||
|
beautify = {
|
||||||
|
beautify: true,
|
||||||
|
screw_ie8: false,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
var x = 3;
|
||||||
|
if (foo())
|
||||||
|
do
|
||||||
|
do
|
||||||
|
alert(x);
|
||||||
|
while (--x);
|
||||||
|
while (x);
|
||||||
|
else
|
||||||
|
bar();
|
||||||
|
}
|
||||||
|
expect_exact: [
|
||||||
|
'var x = 3;',
|
||||||
|
'',
|
||||||
|
'if (foo()) {',
|
||||||
|
' do {',
|
||||||
|
' do {',
|
||||||
|
' alert(x);',
|
||||||
|
' } while (--x);',
|
||||||
|
' } while (x);',
|
||||||
|
'} else bar();',
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
|
issue_186_bracketize: {
|
||||||
|
beautify = {
|
||||||
|
beautify: false,
|
||||||
|
bracketize: true,
|
||||||
|
screw_ie8: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
var x = 3;
|
||||||
|
if (foo())
|
||||||
|
do
|
||||||
|
do
|
||||||
|
alert(x);
|
||||||
|
while (--x);
|
||||||
|
while (x);
|
||||||
|
else
|
||||||
|
bar();
|
||||||
|
}
|
||||||
|
expect_exact: 'var x=3;if(foo()){do{do{alert(x)}while(--x)}while(x)}else{bar()}'
|
||||||
|
}
|
||||||
|
|
||||||
|
issue_186_bracketize_ie8: {
|
||||||
|
beautify = {
|
||||||
|
beautify: false,
|
||||||
|
bracketize: true,
|
||||||
|
screw_ie8: false,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
var x = 3;
|
||||||
|
if (foo())
|
||||||
|
do
|
||||||
|
do
|
||||||
|
alert(x);
|
||||||
|
while (--x);
|
||||||
|
while (x);
|
||||||
|
else
|
||||||
|
bar();
|
||||||
|
}
|
||||||
|
expect_exact: 'var x=3;if(foo()){do{do{alert(x)}while(--x)}while(x)}else{bar()}'
|
||||||
|
}
|
||||||
|
|
||||||
|
issue_186_beautify_bracketize: {
|
||||||
|
beautify = {
|
||||||
|
beautify: true,
|
||||||
|
bracketize: true,
|
||||||
|
screw_ie8: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
var x = 3;
|
||||||
|
if (foo())
|
||||||
|
do
|
||||||
|
do
|
||||||
|
alert(x);
|
||||||
|
while (--x);
|
||||||
|
while (x);
|
||||||
|
else
|
||||||
|
bar();
|
||||||
|
}
|
||||||
|
expect_exact: [
|
||||||
|
'var x = 3;',
|
||||||
|
'',
|
||||||
|
'if (foo()) {',
|
||||||
|
' do {',
|
||||||
|
' do {',
|
||||||
|
' alert(x);',
|
||||||
|
' } while (--x);',
|
||||||
|
' } while (x);',
|
||||||
|
'} else {',
|
||||||
|
' bar();',
|
||||||
|
'}',
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
|
issue_186_beautify_bracketize_ie8: {
|
||||||
|
beautify = {
|
||||||
|
beautify: true,
|
||||||
|
bracketize: true,
|
||||||
|
screw_ie8: false,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
var x = 3;
|
||||||
|
if (foo())
|
||||||
|
do
|
||||||
|
do
|
||||||
|
alert(x);
|
||||||
|
while (--x);
|
||||||
|
while (x);
|
||||||
|
else
|
||||||
|
bar();
|
||||||
|
}
|
||||||
|
expect_exact: [
|
||||||
|
'var x = 3;',
|
||||||
|
'',
|
||||||
|
'if (foo()) {',
|
||||||
|
' do {',
|
||||||
|
' do {',
|
||||||
|
' alert(x);',
|
||||||
|
' } while (--x);',
|
||||||
|
' } while (x);',
|
||||||
|
'} else {',
|
||||||
|
' bar();',
|
||||||
|
'}',
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
|
issue_1648: {
|
||||||
|
options = {
|
||||||
|
join_vars: true,
|
||||||
|
loops: true,
|
||||||
|
passes: 2,
|
||||||
|
sequences: true,
|
||||||
|
unused: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
function f() {
|
||||||
|
x();
|
||||||
|
var b = 1;
|
||||||
|
while (1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
expect_exact: "function f(){for(x();1;);}"
|
||||||
|
}
|
||||||
|
|||||||
@@ -7,7 +7,13 @@ too_short: {
|
|||||||
return { c: 42, d: a(), e: "foo"};
|
return { c: 42, d: a(), e: "foo"};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
expect_exact: 'function f(a){\nreturn{\nc:42,\nd:a(),\ne:"foo"}}'
|
expect_exact: [
|
||||||
|
'function f(a){',
|
||||||
|
'return{',
|
||||||
|
'c:42,',
|
||||||
|
'd:a(),',
|
||||||
|
'e:"foo"}}',
|
||||||
|
]
|
||||||
expect_warnings: [
|
expect_warnings: [
|
||||||
"WARN: Output exceeds 10 characters"
|
"WARN: Output exceeds 10 characters"
|
||||||
]
|
]
|
||||||
@@ -22,7 +28,12 @@ just_enough: {
|
|||||||
return { c: 42, d: a(), e: "foo"};
|
return { c: 42, d: a(), e: "foo"};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
expect_exact: 'function f(a){\nreturn{c:42,\nd:a(),e:"foo"}\n}'
|
expect_exact: [
|
||||||
|
'function f(a){',
|
||||||
|
'return{c:42,',
|
||||||
|
'd:a(),e:"foo"}',
|
||||||
|
'}',
|
||||||
|
]
|
||||||
expect_warnings: [
|
expect_warnings: [
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -32,16 +32,58 @@ negate_iife_2: {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
negate_iife_2_side_effects: {
|
||||||
|
options = {
|
||||||
|
negate_iife: true,
|
||||||
|
side_effects: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
(function(){ return {} })().x = 10; // should not transform this one
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
(function(){ return {} })().x = 10;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
negate_iife_3: {
|
negate_iife_3: {
|
||||||
options = {
|
options = {
|
||||||
negate_iife: true,
|
negate_iife: true,
|
||||||
conditionals: true
|
conditionals: true
|
||||||
};
|
};
|
||||||
|
input: {
|
||||||
|
(function(){ return t })() ? console.log(true) : console.log(false);
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
!function(){ return t }() ? console.log(false) : console.log(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
negate_iife_3_evaluate: {
|
||||||
|
options = {
|
||||||
|
conditionals: true,
|
||||||
|
evaluate: true,
|
||||||
|
negate_iife: true,
|
||||||
|
}
|
||||||
input: {
|
input: {
|
||||||
(function(){ return true })() ? console.log(true) : console.log(false);
|
(function(){ return true })() ? console.log(true) : console.log(false);
|
||||||
}
|
}
|
||||||
expect: {
|
expect: {
|
||||||
!function(){ return true }() ? console.log(false) : console.log(true);
|
console.log(true);
|
||||||
|
}
|
||||||
|
expect_stdout: true
|
||||||
|
}
|
||||||
|
|
||||||
|
negate_iife_3_side_effects: {
|
||||||
|
options = {
|
||||||
|
conditionals: true,
|
||||||
|
negate_iife: true,
|
||||||
|
side_effects: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
(function(){ return t })() ? console.log(true) : console.log(false);
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
!function(){ return t }() ? console.log(false) : console.log(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -50,12 +92,27 @@ negate_iife_3_off: {
|
|||||||
negate_iife: false,
|
negate_iife: false,
|
||||||
conditionals: true,
|
conditionals: true,
|
||||||
};
|
};
|
||||||
|
input: {
|
||||||
|
(function(){ return t })() ? console.log(true) : console.log(false);
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
!function(){ return t }() ? console.log(false) : console.log(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
negate_iife_3_off_evaluate: {
|
||||||
|
options = {
|
||||||
|
conditionals: true,
|
||||||
|
evaluate: true,
|
||||||
|
negate_iife: false,
|
||||||
|
}
|
||||||
input: {
|
input: {
|
||||||
(function(){ return true })() ? console.log(true) : console.log(false);
|
(function(){ return true })() ? console.log(true) : console.log(false);
|
||||||
}
|
}
|
||||||
expect: {
|
expect: {
|
||||||
!function(){ return true }() ? console.log(false) : console.log(true);
|
console.log(true);
|
||||||
}
|
}
|
||||||
|
expect_stdout: true
|
||||||
}
|
}
|
||||||
|
|
||||||
negate_iife_4: {
|
negate_iife_4: {
|
||||||
@@ -65,13 +122,13 @@ negate_iife_4: {
|
|||||||
sequences: true
|
sequences: true
|
||||||
};
|
};
|
||||||
input: {
|
input: {
|
||||||
(function(){ return true })() ? console.log(true) : console.log(false);
|
(function(){ return t })() ? console.log(true) : console.log(false);
|
||||||
(function(){
|
(function(){
|
||||||
console.log("something");
|
console.log("something");
|
||||||
})();
|
})();
|
||||||
}
|
}
|
||||||
expect: {
|
expect: {
|
||||||
!function(){ return true }() ? console.log(false) : console.log(true), function(){
|
!function(){ return t }() ? console.log(false) : console.log(true), function(){
|
||||||
console.log("something");
|
console.log("something");
|
||||||
}();
|
}();
|
||||||
}
|
}
|
||||||
@@ -86,7 +143,7 @@ sequence_off: {
|
|||||||
};
|
};
|
||||||
input: {
|
input: {
|
||||||
function f() {
|
function f() {
|
||||||
(function(){ return true })() ? console.log(true) : console.log(false);
|
(function(){ return t })() ? console.log(true) : console.log(false);
|
||||||
(function(){
|
(function(){
|
||||||
console.log("something");
|
console.log("something");
|
||||||
})();
|
})();
|
||||||
@@ -95,19 +152,19 @@ sequence_off: {
|
|||||||
(function(){
|
(function(){
|
||||||
console.log("something");
|
console.log("something");
|
||||||
})();
|
})();
|
||||||
(function(){ return true })() ? console.log(true) : console.log(false);
|
(function(){ return t })() ? console.log(true) : console.log(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
expect: {
|
expect: {
|
||||||
function f() {
|
function f() {
|
||||||
!function(){ return true }() ? console.log(false) : console.log(true), function(){
|
!function(){ return t }() ? console.log(false) : console.log(true), function(){
|
||||||
console.log("something");
|
console.log("something");
|
||||||
}();
|
}();
|
||||||
}
|
}
|
||||||
function g() {
|
function g() {
|
||||||
(function(){
|
(function(){
|
||||||
console.log("something");
|
console.log("something");
|
||||||
})(), function(){ return true }() ? console.log(true) : console.log(false);
|
})(), function(){ return t }() ? console.log(true) : console.log(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -119,7 +176,7 @@ negate_iife_5: {
|
|||||||
conditionals: true,
|
conditionals: true,
|
||||||
};
|
};
|
||||||
input: {
|
input: {
|
||||||
if ((function(){ return true })()) {
|
if ((function(){ return t })()) {
|
||||||
foo(true);
|
foo(true);
|
||||||
} else {
|
} else {
|
||||||
bar(false);
|
bar(false);
|
||||||
@@ -129,7 +186,7 @@ negate_iife_5: {
|
|||||||
})();
|
})();
|
||||||
}
|
}
|
||||||
expect: {
|
expect: {
|
||||||
!function(){ return true }() ? bar(false) : foo(true), function(){
|
!function(){ return t }() ? bar(false) : foo(true), function(){
|
||||||
console.log("something");
|
console.log("something");
|
||||||
}();
|
}();
|
||||||
}
|
}
|
||||||
@@ -142,7 +199,7 @@ negate_iife_5_off: {
|
|||||||
conditionals: true,
|
conditionals: true,
|
||||||
};
|
};
|
||||||
input: {
|
input: {
|
||||||
if ((function(){ return true })()) {
|
if ((function(){ return t })()) {
|
||||||
foo(true);
|
foo(true);
|
||||||
} else {
|
} else {
|
||||||
bar(false);
|
bar(false);
|
||||||
@@ -152,7 +209,7 @@ negate_iife_5_off: {
|
|||||||
})();
|
})();
|
||||||
}
|
}
|
||||||
expect: {
|
expect: {
|
||||||
!function(){ return true }() ? bar(false) : foo(true), function(){
|
!function(){ return t }() ? bar(false) : foo(true), function(){
|
||||||
console.log("something");
|
console.log("something");
|
||||||
}();
|
}();
|
||||||
}
|
}
|
||||||
@@ -188,6 +245,7 @@ negate_iife_nested: {
|
|||||||
}(7);
|
}(7);
|
||||||
}).f();
|
}).f();
|
||||||
}
|
}
|
||||||
|
expect_stdout: true
|
||||||
}
|
}
|
||||||
|
|
||||||
negate_iife_nested_off: {
|
negate_iife_nested_off: {
|
||||||
@@ -220,6 +278,7 @@ negate_iife_nested_off: {
|
|||||||
})(7);
|
})(7);
|
||||||
}).f();
|
}).f();
|
||||||
}
|
}
|
||||||
|
expect_stdout: true
|
||||||
}
|
}
|
||||||
|
|
||||||
negate_iife_issue_1073: {
|
negate_iife_issue_1073: {
|
||||||
@@ -244,6 +303,7 @@ negate_iife_issue_1073: {
|
|||||||
};
|
};
|
||||||
}(7))();
|
}(7))();
|
||||||
}
|
}
|
||||||
|
expect_stdout: true
|
||||||
}
|
}
|
||||||
|
|
||||||
issue_1254_negate_iife_false: {
|
issue_1254_negate_iife_false: {
|
||||||
@@ -258,6 +318,7 @@ issue_1254_negate_iife_false: {
|
|||||||
})()();
|
})()();
|
||||||
}
|
}
|
||||||
expect_exact: '(function(){return function(){console.log("test")}})()();'
|
expect_exact: '(function(){return function(){console.log("test")}})()();'
|
||||||
|
expect_stdout: true
|
||||||
}
|
}
|
||||||
|
|
||||||
issue_1254_negate_iife_true: {
|
issue_1254_negate_iife_true: {
|
||||||
@@ -272,6 +333,7 @@ issue_1254_negate_iife_true: {
|
|||||||
})()();
|
})()();
|
||||||
}
|
}
|
||||||
expect_exact: '!function(){return function(){console.log("test")}}()();'
|
expect_exact: '!function(){return function(){console.log("test")}}()();'
|
||||||
|
expect_stdout: true
|
||||||
}
|
}
|
||||||
|
|
||||||
issue_1254_negate_iife_nested: {
|
issue_1254_negate_iife_nested: {
|
||||||
@@ -286,12 +348,14 @@ issue_1254_negate_iife_nested: {
|
|||||||
})()()()()();
|
})()()()()();
|
||||||
}
|
}
|
||||||
expect_exact: '!function(){return function(){console.log("test")}}()()()()();'
|
expect_exact: '!function(){return function(){console.log("test")}}()()()()();'
|
||||||
|
expect_stdout: true
|
||||||
}
|
}
|
||||||
|
|
||||||
issue_1288: {
|
issue_1288: {
|
||||||
options = {
|
options = {
|
||||||
negate_iife: true,
|
|
||||||
conditionals: true,
|
conditionals: true,
|
||||||
|
negate_iife: true,
|
||||||
|
side_effects: false,
|
||||||
};
|
};
|
||||||
input: {
|
input: {
|
||||||
if (w) ;
|
if (w) ;
|
||||||
@@ -311,12 +375,44 @@ issue_1288: {
|
|||||||
})(0);
|
})(0);
|
||||||
}
|
}
|
||||||
expect: {
|
expect: {
|
||||||
w || function f() {}();
|
w || !function f() {}();
|
||||||
x || function() {
|
x || !function() {
|
||||||
x = {};
|
x = {};
|
||||||
}();
|
}();
|
||||||
y ? function() {}() : function(z) {
|
y ? !function() {}() : !function(z) {
|
||||||
return z;
|
return z;
|
||||||
}(0);
|
}(0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
issue_1288_side_effects: {
|
||||||
|
options = {
|
||||||
|
conditionals: true,
|
||||||
|
negate_iife: true,
|
||||||
|
side_effects: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
if (w) ;
|
||||||
|
else {
|
||||||
|
(function f() {})();
|
||||||
|
}
|
||||||
|
if (!x) {
|
||||||
|
(function() {
|
||||||
|
x = {};
|
||||||
|
})();
|
||||||
|
}
|
||||||
|
if (y)
|
||||||
|
(function() {})();
|
||||||
|
else
|
||||||
|
(function(z) {
|
||||||
|
return z;
|
||||||
|
})(0);
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
w;
|
||||||
|
x || function() {
|
||||||
|
x = {};
|
||||||
|
}();
|
||||||
|
y;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -17,3 +17,154 @@ hex_numbers_in_parentheses_for_prototype_functions: {
|
|||||||
}
|
}
|
||||||
expect_exact: "-2;(-2).toFixed(0);2;2..toFixed(0);.2;.2.toFixed(0);2e-8;2e-8.toFixed(0);0xde0b6b3a7640080;(0xde0b6b3a7640080).toFixed(0);"
|
expect_exact: "-2;(-2).toFixed(0);2;2..toFixed(0);.2;.2.toFixed(0);2e-8;2e-8.toFixed(0);0xde0b6b3a7640080;(0xde0b6b3a7640080).toFixed(0);"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
comparisons: {
|
||||||
|
options = {
|
||||||
|
comparisons: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
console.log(
|
||||||
|
~x === 42,
|
||||||
|
x % n === 42
|
||||||
|
);
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
console.log(
|
||||||
|
42 == ~x,
|
||||||
|
x % n == 42
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
evaluate_1: {
|
||||||
|
options = {
|
||||||
|
evaluate: true,
|
||||||
|
unsafe_math: false,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
console.log(
|
||||||
|
x + 1 + 2,
|
||||||
|
x * 1 * 2,
|
||||||
|
+x + 1 + 2,
|
||||||
|
1 + x + 2 + 3,
|
||||||
|
1 | x | 2 | 3,
|
||||||
|
1 + x-- + 2 + 3,
|
||||||
|
1 + (x*y + 2) + 3,
|
||||||
|
1 + (2 + x + 3),
|
||||||
|
1 + (2 + ~x + 3),
|
||||||
|
-y + (2 + ~x + 3),
|
||||||
|
1 & (2 & x & 3),
|
||||||
|
1 + (2 + (x |= 0) + 3)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
console.log(
|
||||||
|
x + 1 + 2,
|
||||||
|
1 * x * 2,
|
||||||
|
+x + 1 + 2,
|
||||||
|
1 + x + 2 + 3,
|
||||||
|
3 | x,
|
||||||
|
1 + x-- + 2 + 3,
|
||||||
|
x*y + 2 + 1 + 3,
|
||||||
|
1 + (2 + x + 3),
|
||||||
|
2 + ~x + 3 + 1,
|
||||||
|
-y + (2 + ~x + 3),
|
||||||
|
0 & x,
|
||||||
|
2 + (x |= 0) + 3 + 1
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
evaluate_2: {
|
||||||
|
options = {
|
||||||
|
evaluate: true,
|
||||||
|
unsafe_math: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
console.log(
|
||||||
|
x + 1 + 2,
|
||||||
|
x * 1 * 2,
|
||||||
|
+x + 1 + 2,
|
||||||
|
1 + x + 2 + 3,
|
||||||
|
1 | x | 2 | 3,
|
||||||
|
1 + x-- + 2 + 3,
|
||||||
|
1 + (x*y + 2) + 3,
|
||||||
|
1 + (2 + x + 3),
|
||||||
|
1 & (2 & x & 3),
|
||||||
|
1 + (2 + (x |= 0) + 3)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
console.log(
|
||||||
|
x + 1 + 2,
|
||||||
|
2 * x,
|
||||||
|
3 + +x,
|
||||||
|
1 + x + 2 + 3,
|
||||||
|
3 | x,
|
||||||
|
6 + x--,
|
||||||
|
6 + x*y,
|
||||||
|
1 + (2 + x + 3),
|
||||||
|
0 & x,
|
||||||
|
6 + (x |= 0)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
evaluate_3: {
|
||||||
|
options = {
|
||||||
|
evaluate: true,
|
||||||
|
unsafe: true,
|
||||||
|
unsafe_math: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
console.log(1 + Number(x) + 2);
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
console.log(3 + +x);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
evaluate_4: {
|
||||||
|
options = {
|
||||||
|
evaluate: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
console.log(
|
||||||
|
1+ +a,
|
||||||
|
+a+1,
|
||||||
|
1+-a,
|
||||||
|
-a+1,
|
||||||
|
+a+ +b,
|
||||||
|
+a+-b,
|
||||||
|
-a+ +b,
|
||||||
|
-a+-b
|
||||||
|
);
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
console.log(
|
||||||
|
+a+1,
|
||||||
|
+a+1,
|
||||||
|
1-a,
|
||||||
|
1-a,
|
||||||
|
+a+ +b,
|
||||||
|
+a-b,
|
||||||
|
-a+ +b,
|
||||||
|
-a-b
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
issue_1710: {
|
||||||
|
options = {
|
||||||
|
evaluate: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
var x = {};
|
||||||
|
console.log((x += 1) + -x);
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
var x = {};
|
||||||
|
console.log((x += 1) + -x);
|
||||||
|
}
|
||||||
|
expect_stdout: true
|
||||||
|
}
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@@ -1,20 +1,49 @@
|
|||||||
do_screw: {
|
do_screw: {
|
||||||
options = { screw_ie8: true };
|
options = {
|
||||||
|
screw_ie8: true,
|
||||||
|
}
|
||||||
beautify = {
|
beautify = {
|
||||||
screw_ie8: true,
|
screw_ie8: true,
|
||||||
ascii_only: true
|
ascii_only: true,
|
||||||
};
|
}
|
||||||
|
input: {
|
||||||
input: f("\v");
|
f("\v");
|
||||||
expect_exact: 'f("\\v");';
|
}
|
||||||
|
expect_exact: 'f("\\v");'
|
||||||
}
|
}
|
||||||
|
|
||||||
dont_screw: {
|
dont_screw: {
|
||||||
options = { screw_ie8: false };
|
options = {
|
||||||
beautify = { screw_ie8: false, ascii_only: true };
|
screw_ie8: false,
|
||||||
|
}
|
||||||
|
beautify = {
|
||||||
|
screw_ie8: false,
|
||||||
|
ascii_only: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
f("\v");
|
||||||
|
}
|
||||||
|
expect_exact: 'f("\\x0B");'
|
||||||
|
}
|
||||||
|
|
||||||
input: f("\v");
|
do_screw_constants: {
|
||||||
expect_exact: 'f("\\x0B");';
|
options = {
|
||||||
|
screw_ie8: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
f(undefined, Infinity);
|
||||||
|
}
|
||||||
|
expect_exact: "f(void 0,1/0);"
|
||||||
|
}
|
||||||
|
|
||||||
|
dont_screw_constants: {
|
||||||
|
options = {
|
||||||
|
screw_ie8: false,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
f(undefined, Infinity);
|
||||||
|
}
|
||||||
|
expect_exact: "f(undefined,Infinity);"
|
||||||
}
|
}
|
||||||
|
|
||||||
do_screw_try_catch: {
|
do_screw_try_catch: {
|
||||||
@@ -46,8 +75,6 @@ do_screw_try_catch: {
|
|||||||
}
|
}
|
||||||
|
|
||||||
dont_screw_try_catch: {
|
dont_screw_try_catch: {
|
||||||
// This test is known to generate incorrect code for screw_ie8=false.
|
|
||||||
// Update expected result in the event this bug is ever fixed.
|
|
||||||
options = { screw_ie8: false };
|
options = { screw_ie8: false };
|
||||||
mangle = { screw_ie8: false };
|
mangle = { screw_ie8: false };
|
||||||
beautify = { screw_ie8: false };
|
beautify = { screw_ie8: false };
|
||||||
@@ -64,11 +91,11 @@ dont_screw_try_catch: {
|
|||||||
}
|
}
|
||||||
expect: {
|
expect: {
|
||||||
bad = function(n){
|
bad = function(n){
|
||||||
return function(n){
|
return function(t){
|
||||||
try{
|
try{
|
||||||
t()
|
n()
|
||||||
} catch(t) {
|
} catch(n) {
|
||||||
n(t)
|
t(n)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@@ -101,11 +128,10 @@ do_screw_try_catch_undefined: {
|
|||||||
return void 0===o
|
return void 0===o
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
expect_stdout: true
|
||||||
}
|
}
|
||||||
|
|
||||||
dont_screw_try_catch_undefined: {
|
dont_screw_try_catch_undefined: {
|
||||||
// This test is known to generate incorrect code for screw_ie8=false.
|
|
||||||
// Update expected result in the event this bug is ever fixed.
|
|
||||||
options = { screw_ie8: false };
|
options = { screw_ie8: false };
|
||||||
mangle = { screw_ie8: false };
|
mangle = { screw_ie8: false };
|
||||||
beautify = { screw_ie8: false };
|
beautify = { screw_ie8: false };
|
||||||
@@ -121,14 +147,87 @@ dont_screw_try_catch_undefined: {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
expect: {
|
expect: {
|
||||||
function a(o){
|
function a(n){
|
||||||
try{
|
try{
|
||||||
throw "Stuff"
|
throw "Stuff"
|
||||||
} catch (n) {
|
} catch (undefined) {
|
||||||
console.log("caught: "+n)
|
console.log("caught: " + undefined)
|
||||||
}
|
}
|
||||||
console.log("undefined is " + n);
|
console.log("undefined is " + undefined);
|
||||||
return o === n
|
return n === undefined
|
||||||
|
}
|
||||||
|
}
|
||||||
|
expect_stdout: true
|
||||||
|
}
|
||||||
|
|
||||||
|
reduce_vars: {
|
||||||
|
options = {
|
||||||
|
evaluate: true,
|
||||||
|
reduce_vars: true,
|
||||||
|
screw_ie8: false,
|
||||||
|
unused: true,
|
||||||
|
}
|
||||||
|
mangle = {
|
||||||
|
screw_ie8: false,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
function f() {
|
||||||
|
var a;
|
||||||
|
try {
|
||||||
|
x();
|
||||||
|
} catch (a) {
|
||||||
|
y();
|
||||||
|
}
|
||||||
|
alert(a);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
function f() {
|
||||||
|
var t;
|
||||||
|
try {
|
||||||
|
x();
|
||||||
|
} catch (t) {
|
||||||
|
y();
|
||||||
|
}
|
||||||
|
alert(t);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
issue_1586_1: {
|
||||||
|
options = {
|
||||||
|
screw_ie8: false,
|
||||||
|
}
|
||||||
|
mangle = {
|
||||||
|
screw_ie8: false,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
function f() {
|
||||||
|
try {
|
||||||
|
} catch (err) {
|
||||||
|
console.log(err.message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
expect_exact: "function f(){try{}catch(c){console.log(c.message)}}"
|
||||||
|
expect_stdout: true
|
||||||
|
}
|
||||||
|
|
||||||
|
issue_1586_2: {
|
||||||
|
options = {
|
||||||
|
screw_ie8: true,
|
||||||
|
}
|
||||||
|
mangle = {
|
||||||
|
screw_ie8: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
function f() {
|
||||||
|
try {
|
||||||
|
} catch (err) {
|
||||||
|
console.log(err.message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
expect_exact: "function f(){try{}catch(c){console.log(c.message)}}"
|
||||||
|
expect_stdout: true
|
||||||
|
}
|
||||||
|
|||||||
@@ -86,6 +86,7 @@ make_sequences_4: {
|
|||||||
switch (x = 5, y) {}
|
switch (x = 5, y) {}
|
||||||
with (x = 5, obj);
|
with (x = 5, obj);
|
||||||
}
|
}
|
||||||
|
expect_stdout: true
|
||||||
}
|
}
|
||||||
|
|
||||||
lift_sequences_1: {
|
lift_sequences_1: {
|
||||||
@@ -103,15 +104,18 @@ lift_sequences_1: {
|
|||||||
lift_sequences_2: {
|
lift_sequences_2: {
|
||||||
options = { sequences: true, evaluate: true };
|
options = { sequences: true, evaluate: true };
|
||||||
input: {
|
input: {
|
||||||
var foo, bar;
|
var foo = 1, bar;
|
||||||
foo.x = (foo = {}, 10);
|
foo.x = (foo = {}, 10);
|
||||||
bar = (bar = {}, 10);
|
bar = (bar = {}, 10);
|
||||||
|
console.log(foo, bar);
|
||||||
}
|
}
|
||||||
expect: {
|
expect: {
|
||||||
var foo, bar;
|
var foo = 1, bar;
|
||||||
foo.x = (foo = {}, 10),
|
foo.x = (foo = {}, 10),
|
||||||
bar = {}, bar = 10;
|
bar = {}, bar = 10,
|
||||||
|
console.log(foo, bar);
|
||||||
}
|
}
|
||||||
|
expect_stdout: true
|
||||||
}
|
}
|
||||||
|
|
||||||
lift_sequences_3: {
|
lift_sequences_3: {
|
||||||
@@ -138,6 +142,23 @@ lift_sequences_4: {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
lift_sequences_5: {
|
||||||
|
options = {
|
||||||
|
sequences: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
var a = 2, b;
|
||||||
|
a *= (b, a = 4, 3);
|
||||||
|
console.log(a);
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
var a = 2, b;
|
||||||
|
b, a *= (a = 4, 3),
|
||||||
|
console.log(a);
|
||||||
|
}
|
||||||
|
expect_stdout: "6"
|
||||||
|
}
|
||||||
|
|
||||||
for_sequences: {
|
for_sequences: {
|
||||||
options = { sequences: true };
|
options = { sequences: true };
|
||||||
input: {
|
input: {
|
||||||
@@ -230,6 +251,7 @@ negate_iife_for: {
|
|||||||
for (!function() {}(), i = 0; i < 5; i++) console.log(i);
|
for (!function() {}(), i = 0; i < 5; i++) console.log(i);
|
||||||
for (function() {}(); i < 5; i++) console.log(i);
|
for (function() {}(); i < 5; i++) console.log(i);
|
||||||
}
|
}
|
||||||
|
expect_stdout: true
|
||||||
}
|
}
|
||||||
|
|
||||||
iife: {
|
iife: {
|
||||||
@@ -248,6 +270,173 @@ iife: {
|
|||||||
}
|
}
|
||||||
expect: {
|
expect: {
|
||||||
x = 42, function a() {}(), function b() {}(), function c() {}(),
|
x = 42, function a() {}(), function b() {}(), function c() {}(),
|
||||||
function d() {}(), function e() {}(), function f() {}(), function g() {}()
|
function d() {}(), function e() {}(), function f() {}(), function g() {}();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
unsafe_undefined: {
|
||||||
|
options = {
|
||||||
|
conditionals: true,
|
||||||
|
if_return: true,
|
||||||
|
sequences: true,
|
||||||
|
side_effects: true,
|
||||||
|
unsafe: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
function f(undefined) {
|
||||||
|
if (a)
|
||||||
|
return b;
|
||||||
|
if (c)
|
||||||
|
return d;
|
||||||
|
}
|
||||||
|
function g(undefined) {
|
||||||
|
if (a)
|
||||||
|
return b;
|
||||||
|
if (c)
|
||||||
|
return d;
|
||||||
|
e();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
function f(undefined) {
|
||||||
|
return a ? b : c ? d : undefined;
|
||||||
|
}
|
||||||
|
function g(undefined) {
|
||||||
|
return a ? b : c ? d : void e();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
issue_1685: {
|
||||||
|
options = {
|
||||||
|
cascade: true,
|
||||||
|
side_effects: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
var a = 100, b = 10;
|
||||||
|
function f() {
|
||||||
|
var a = (a--, delete a && --b);
|
||||||
|
}
|
||||||
|
f();
|
||||||
|
console.log(a, b);
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
var a = 100, b = 10;
|
||||||
|
function f() {
|
||||||
|
var a = (a--, delete a && --b);
|
||||||
|
}
|
||||||
|
f();
|
||||||
|
console.log(a, b);
|
||||||
|
}
|
||||||
|
expect_stdout: true
|
||||||
|
}
|
||||||
|
|
||||||
|
func_def_1: {
|
||||||
|
options = {
|
||||||
|
cascade: true,
|
||||||
|
side_effects: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
function f() {
|
||||||
|
return f = 0, !!f;
|
||||||
|
}
|
||||||
|
console.log(f());
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
function f() {
|
||||||
|
return !!(f = 0);
|
||||||
|
}
|
||||||
|
console.log(f());
|
||||||
|
}
|
||||||
|
expect_stdout: "false"
|
||||||
|
}
|
||||||
|
|
||||||
|
func_def_2: {
|
||||||
|
options = {
|
||||||
|
cascade: true,
|
||||||
|
side_effects: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
console.log(function f() {
|
||||||
|
return f = 0, !!f;
|
||||||
|
}());
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
console.log(function f() {
|
||||||
|
return f = 0, !!f;
|
||||||
|
}());
|
||||||
|
}
|
||||||
|
expect_stdout: "true"
|
||||||
|
}
|
||||||
|
|
||||||
|
func_def_3: {
|
||||||
|
options = {
|
||||||
|
cascade: true,
|
||||||
|
side_effects: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
function f() {
|
||||||
|
function g() {}
|
||||||
|
return g = 0, !!g;
|
||||||
|
}
|
||||||
|
console.log(f());
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
function f() {
|
||||||
|
function g() {}
|
||||||
|
return !!(g = 0);
|
||||||
|
}
|
||||||
|
console.log(f());
|
||||||
|
}
|
||||||
|
expect_stdout: "false"
|
||||||
|
}
|
||||||
|
|
||||||
|
func_def_4: {
|
||||||
|
options = {
|
||||||
|
cascade: true,
|
||||||
|
side_effects: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
function f() {
|
||||||
|
function g() {
|
||||||
|
return g = 0, !!g;
|
||||||
|
}
|
||||||
|
return g();
|
||||||
|
}
|
||||||
|
console.log(f());
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
function f() {
|
||||||
|
function g() {
|
||||||
|
return !!(g = 0);
|
||||||
|
}
|
||||||
|
return g();
|
||||||
|
}
|
||||||
|
console.log(f());
|
||||||
|
}
|
||||||
|
expect_stdout: "false"
|
||||||
|
}
|
||||||
|
|
||||||
|
func_def_5: {
|
||||||
|
options = {
|
||||||
|
cascade: true,
|
||||||
|
side_effects: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
function f() {
|
||||||
|
return function g(){
|
||||||
|
return g = 0, !!g;
|
||||||
|
}();
|
||||||
|
}
|
||||||
|
console.log(f());
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
function f() {
|
||||||
|
return function g(){
|
||||||
|
return g = 0, !!g;
|
||||||
|
}();
|
||||||
|
}
|
||||||
|
console.log(f());
|
||||||
|
}
|
||||||
|
expect_stdout: "true"
|
||||||
|
}
|
||||||
|
|||||||
@@ -258,3 +258,425 @@ keep_default: {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
issue_1663: {
|
||||||
|
options = {
|
||||||
|
dead_code: true,
|
||||||
|
evaluate: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
var a = 100, b = 10;
|
||||||
|
function f() {
|
||||||
|
switch (1) {
|
||||||
|
case 1:
|
||||||
|
b = a++;
|
||||||
|
return ++b;
|
||||||
|
default:
|
||||||
|
var b;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
f();
|
||||||
|
console.log(a, b);
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
var a = 100, b = 10;
|
||||||
|
function f() {
|
||||||
|
var b;
|
||||||
|
b = a++;
|
||||||
|
return ++b;
|
||||||
|
}
|
||||||
|
f();
|
||||||
|
console.log(a, b);
|
||||||
|
}
|
||||||
|
expect_stdout: true
|
||||||
|
}
|
||||||
|
|
||||||
|
drop_case: {
|
||||||
|
options = {
|
||||||
|
dead_code: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
switch (foo) {
|
||||||
|
case 'bar': baz(); break;
|
||||||
|
case 'moo':
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
switch (foo) {
|
||||||
|
case 'bar': baz();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
keep_case: {
|
||||||
|
options = {
|
||||||
|
dead_code: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
switch (foo) {
|
||||||
|
case 'bar': baz(); break;
|
||||||
|
case moo:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
switch (foo) {
|
||||||
|
case 'bar': baz(); break;
|
||||||
|
case moo:
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
issue_376: {
|
||||||
|
options = {
|
||||||
|
dead_code: true,
|
||||||
|
evaluate: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
switch (true) {
|
||||||
|
case boolCondition:
|
||||||
|
console.log(1);
|
||||||
|
break;
|
||||||
|
case false:
|
||||||
|
console.log(2);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
switch (true) {
|
||||||
|
case boolCondition:
|
||||||
|
console.log(1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
issue_441_1: {
|
||||||
|
options = {
|
||||||
|
dead_code: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
switch (foo) {
|
||||||
|
case bar:
|
||||||
|
qux();
|
||||||
|
break;
|
||||||
|
case baz:
|
||||||
|
qux();
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
qux();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
switch (foo) {
|
||||||
|
case bar:
|
||||||
|
case baz:
|
||||||
|
default:
|
||||||
|
qux();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
issue_441_2: {
|
||||||
|
options = {
|
||||||
|
dead_code: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
switch (foo) {
|
||||||
|
case bar:
|
||||||
|
// TODO: Fold into the case below
|
||||||
|
qux();
|
||||||
|
break;
|
||||||
|
case fall:
|
||||||
|
case baz:
|
||||||
|
qux();
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
qux();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
switch (foo) {
|
||||||
|
case bar:
|
||||||
|
qux();
|
||||||
|
break;
|
||||||
|
case fall:
|
||||||
|
case baz:
|
||||||
|
default:
|
||||||
|
qux();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
issue_1674: {
|
||||||
|
options = {
|
||||||
|
dead_code: true,
|
||||||
|
evaluate: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
switch (0) {
|
||||||
|
default:
|
||||||
|
console.log("FAIL");
|
||||||
|
break;
|
||||||
|
case 0:
|
||||||
|
console.log("PASS");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
console.log("PASS");
|
||||||
|
}
|
||||||
|
expect_stdout: "PASS"
|
||||||
|
}
|
||||||
|
|
||||||
|
issue_1679: {
|
||||||
|
options = {
|
||||||
|
dead_code: true,
|
||||||
|
evaluate: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
var a = 100, b = 10;
|
||||||
|
function f() {
|
||||||
|
switch (--b) {
|
||||||
|
default:
|
||||||
|
case !function x() {}:
|
||||||
|
break;
|
||||||
|
case b--:
|
||||||
|
switch (0) {
|
||||||
|
default:
|
||||||
|
case a--:
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case (a++):
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
f();
|
||||||
|
console.log(a, b);
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
var a = 100, b = 10;
|
||||||
|
function f() {
|
||||||
|
switch (--b) {
|
||||||
|
default:
|
||||||
|
case !function x() {}:
|
||||||
|
break;
|
||||||
|
case b--:
|
||||||
|
switch (0) {
|
||||||
|
default:
|
||||||
|
case a--:
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case (a++):
|
||||||
|
}
|
||||||
|
}
|
||||||
|
f();
|
||||||
|
console.log(a, b);
|
||||||
|
}
|
||||||
|
expect_stdout: true
|
||||||
|
}
|
||||||
|
|
||||||
|
issue_1680_1: {
|
||||||
|
options = {
|
||||||
|
dead_code: true,
|
||||||
|
evaluate: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
function f(x) {
|
||||||
|
console.log(x);
|
||||||
|
return x + 1;
|
||||||
|
}
|
||||||
|
switch (2) {
|
||||||
|
case f(0):
|
||||||
|
case f(1):
|
||||||
|
f(2);
|
||||||
|
case 2:
|
||||||
|
case f(3):
|
||||||
|
case f(4):
|
||||||
|
f(5);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
function f(x) {
|
||||||
|
console.log(x);
|
||||||
|
return x + 1;
|
||||||
|
}
|
||||||
|
switch (2) {
|
||||||
|
case f(0):
|
||||||
|
case f(1):
|
||||||
|
f(2);
|
||||||
|
case 2:
|
||||||
|
f(5);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
expect_stdout: [
|
||||||
|
"0",
|
||||||
|
"1",
|
||||||
|
"2",
|
||||||
|
"5",
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
|
issue_1680_2: {
|
||||||
|
options = {
|
||||||
|
dead_code: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
var a = 100, b = 10;
|
||||||
|
switch (b) {
|
||||||
|
case a--:
|
||||||
|
break;
|
||||||
|
case b:
|
||||||
|
var c;
|
||||||
|
break;
|
||||||
|
case a:
|
||||||
|
break;
|
||||||
|
case a--:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
console.log(a, b);
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
var a = 100, b = 10;
|
||||||
|
switch (b) {
|
||||||
|
case a--:
|
||||||
|
break;
|
||||||
|
case b:
|
||||||
|
var c;
|
||||||
|
break;
|
||||||
|
case a:
|
||||||
|
case a--:
|
||||||
|
}
|
||||||
|
console.log(a, b);
|
||||||
|
}
|
||||||
|
expect_stdout: true
|
||||||
|
}
|
||||||
|
|
||||||
|
issue_1690_1: {
|
||||||
|
options = {
|
||||||
|
dead_code: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
switch (console.log("PASS")) {}
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
console.log("PASS");
|
||||||
|
}
|
||||||
|
expect_stdout: "PASS"
|
||||||
|
}
|
||||||
|
|
||||||
|
issue_1690_2: {
|
||||||
|
options = {
|
||||||
|
dead_code: false,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
switch (console.log("PASS")) {}
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
switch (console.log("PASS")) {}
|
||||||
|
}
|
||||||
|
expect_stdout: "PASS"
|
||||||
|
}
|
||||||
|
|
||||||
|
if_switch_typeof: {
|
||||||
|
options = {
|
||||||
|
conditionals: true,
|
||||||
|
dead_code: true,
|
||||||
|
side_effects: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
if (a) switch(typeof b) {}
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
a;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
issue_1698: {
|
||||||
|
options = {
|
||||||
|
side_effects: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
var a = 1;
|
||||||
|
!function() {
|
||||||
|
switch (a++) {}
|
||||||
|
}();
|
||||||
|
console.log(a);
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
var a = 1;
|
||||||
|
!function() {
|
||||||
|
switch (a++) {}
|
||||||
|
}();
|
||||||
|
console.log(a);
|
||||||
|
}
|
||||||
|
expect_stdout: "2"
|
||||||
|
}
|
||||||
|
|
||||||
|
issue_1705_1: {
|
||||||
|
options = {
|
||||||
|
dead_code: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
var a = 0;
|
||||||
|
switch (a) {
|
||||||
|
default:
|
||||||
|
console.log("FAIL");
|
||||||
|
case 0:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
var a = 0;
|
||||||
|
switch (a) {
|
||||||
|
default:
|
||||||
|
console.log("FAIL");
|
||||||
|
case 0:
|
||||||
|
}
|
||||||
|
}
|
||||||
|
expect_stdout: true
|
||||||
|
}
|
||||||
|
|
||||||
|
issue_1705_2: {
|
||||||
|
options = {
|
||||||
|
dead_code: true,
|
||||||
|
evaluate: true,
|
||||||
|
reduce_vars: true,
|
||||||
|
sequences: true,
|
||||||
|
side_effects: true,
|
||||||
|
toplevel: true,
|
||||||
|
unused: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
var a = 0;
|
||||||
|
switch (a) {
|
||||||
|
default:
|
||||||
|
console.log("FAIL");
|
||||||
|
case 0:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
}
|
||||||
|
expect_stdout: true
|
||||||
|
}
|
||||||
|
|
||||||
|
issue_1705_3: {
|
||||||
|
options = {
|
||||||
|
dead_code: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
switch (a) {
|
||||||
|
case 0:
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
a;
|
||||||
|
}
|
||||||
|
expect_stdout: true
|
||||||
|
}
|
||||||
|
|||||||
130
test/compress/transform.js
Normal file
130
test/compress/transform.js
Normal file
@@ -0,0 +1,130 @@
|
|||||||
|
booleans_evaluate: {
|
||||||
|
options = {
|
||||||
|
booleans: true,
|
||||||
|
evaluate: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
console.log(typeof void 0 != "undefined");
|
||||||
|
console.log(1 == 1, 1 === 1)
|
||||||
|
console.log(1 != 1, 1 !== 1)
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
console.log(!1);
|
||||||
|
console.log(!0, !0);
|
||||||
|
console.log(!1, !1);
|
||||||
|
}
|
||||||
|
expect_stdout: true
|
||||||
|
}
|
||||||
|
|
||||||
|
booleans_global_defs: {
|
||||||
|
options = {
|
||||||
|
booleans: true,
|
||||||
|
evaluate: true,
|
||||||
|
global_defs: {
|
||||||
|
A: true,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
console.log(A == 1);
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
console.log(!0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
condition_evaluate: {
|
||||||
|
options = {
|
||||||
|
booleans: true,
|
||||||
|
dead_code: false,
|
||||||
|
evaluate: true,
|
||||||
|
loops: false,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
while (1 === 2);
|
||||||
|
for (; 1 == true;);
|
||||||
|
if (void 0 == null);
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
while (!1);
|
||||||
|
for (; !0;);
|
||||||
|
if (!0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if_else_empty: {
|
||||||
|
options = {
|
||||||
|
conditionals: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
if ({} ? a : b); else {}
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
!{} ? b : a;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
label_if_break: {
|
||||||
|
options = {
|
||||||
|
conditionals: true,
|
||||||
|
dead_code: true,
|
||||||
|
evaluate: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
L: if (true) {
|
||||||
|
a;
|
||||||
|
break L;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
a;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
while_if_break: {
|
||||||
|
options = {
|
||||||
|
conditionals: true,
|
||||||
|
loops: true,
|
||||||
|
sequences: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
while (a) {
|
||||||
|
if (b) if(c) d;
|
||||||
|
if (e) break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
for(; a && (b && c && d, !e););
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if_return: {
|
||||||
|
options = {
|
||||||
|
booleans: true,
|
||||||
|
conditionals: true,
|
||||||
|
if_return: true,
|
||||||
|
sequences: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
function f(w, x, y, z) {
|
||||||
|
if (x) return;
|
||||||
|
if (w) {
|
||||||
|
if (y) return;
|
||||||
|
} else if (z) return;
|
||||||
|
if (x == y) return true;
|
||||||
|
|
||||||
|
if (x) w();
|
||||||
|
if (y) z();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
function f(w, x, y, z) {
|
||||||
|
if (!x) {
|
||||||
|
if (w) {
|
||||||
|
if (y) return;
|
||||||
|
} else if (z) return;
|
||||||
|
return x == y || (x && w(), y && z(), !0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -29,6 +29,7 @@ typeof_in_boolean_context: {
|
|||||||
booleans : true,
|
booleans : true,
|
||||||
evaluate : true,
|
evaluate : true,
|
||||||
conditionals : true,
|
conditionals : true,
|
||||||
|
side_effects : true,
|
||||||
};
|
};
|
||||||
input: {
|
input: {
|
||||||
function f1(x) { return typeof x ? "yes" : "no"; }
|
function f1(x) { return typeof x ? "yes" : "no"; }
|
||||||
@@ -36,12 +37,26 @@ typeof_in_boolean_context: {
|
|||||||
typeof 0 ? foo() : bar();
|
typeof 0 ? foo() : bar();
|
||||||
!typeof console.log(1);
|
!typeof console.log(1);
|
||||||
var a = !typeof console.log(2);
|
var a = !typeof console.log(2);
|
||||||
|
if (typeof (1 + foo()));
|
||||||
}
|
}
|
||||||
expect: {
|
expect: {
|
||||||
function f1(x) { return "yes"; }
|
function f1(x) { return "yes"; }
|
||||||
function f2() { return g(), "Yes"; }
|
function f2() { return g(), "Yes"; }
|
||||||
foo();
|
foo();
|
||||||
!(console.log(1), !0);
|
console.log(1);
|
||||||
var a = !(console.log(2), !0);
|
var a = !(console.log(2), !0);
|
||||||
|
foo();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
issue_1668: {
|
||||||
|
options = {
|
||||||
|
booleans: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
if (typeof bar);
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
if (!0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
1
test/input/invalid/assign_1.js
Normal file
1
test/input/invalid/assign_1.js
Normal file
@@ -0,0 +1 @@
|
|||||||
|
console.log(1 || 5--);
|
||||||
1
test/input/invalid/assign_2.js
Normal file
1
test/input/invalid/assign_2.js
Normal file
@@ -0,0 +1 @@
|
|||||||
|
console.log(2 || (Math.random() /= 2));
|
||||||
1
test/input/invalid/assign_3.js
Normal file
1
test/input/invalid/assign_3.js
Normal file
@@ -0,0 +1 @@
|
|||||||
|
console.log(3 || ++this);
|
||||||
1
test/input/invalid/loop-no-body.js
Normal file
1
test/input/invalid/loop-no-body.js
Normal file
@@ -0,0 +1 @@
|
|||||||
|
for (var i = 0; i < 1; i++)
|
||||||
1
test/input/issue-1632/^{foo}[bar](baz)+$.js
Normal file
1
test/input/issue-1632/^{foo}[bar](baz)+$.js
Normal file
@@ -0,0 +1 @@
|
|||||||
|
console.log(x);
|
||||||
@@ -82,7 +82,7 @@ describe("bin/uglifyjs", function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
it("Should work with --keep-fnames (mangle & compress)", function (done) {
|
it("Should work with --keep-fnames (mangle & compress)", function (done) {
|
||||||
var command = uglifyjscmd + ' test/input/issue-1431/sample.js --keep-fnames -m -c';
|
var command = uglifyjscmd + ' test/input/issue-1431/sample.js --keep-fnames -m -c unused=false';
|
||||||
|
|
||||||
exec(command, function (err, stdout) {
|
exec(command, function (err, stdout) {
|
||||||
if (err) throw err;
|
if (err) throw err;
|
||||||
@@ -152,7 +152,7 @@ describe("bin/uglifyjs", function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
it("Should process inline source map", function(done) {
|
it("Should process inline source map", function(done) {
|
||||||
var command = uglifyjscmd + ' test/input/issue-520/input.js -cm toplevel --in-source-map inline --source-map-inline';
|
var command = uglifyjscmd + ' test/input/issue-520/input.js -mc toplevel --in-source-map inline --source-map-inline';
|
||||||
|
|
||||||
exec(command, function (err, stdout) {
|
exec(command, function (err, stdout) {
|
||||||
if (err) throw err;
|
if (err) throw err;
|
||||||
@@ -238,4 +238,72 @@ describe("bin/uglifyjs", function () {
|
|||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
it("Should fail with a missing loop body", function(done) {
|
||||||
|
var command = uglifyjscmd + ' test/input/invalid/loop-no-body.js';
|
||||||
|
|
||||||
|
exec(command, function (err, stdout, stderr) {
|
||||||
|
assert.ok(err);
|
||||||
|
var lines = stderr.split(/\n/);
|
||||||
|
assert.strictEqual(lines[0], "Parse error at test/input/invalid/loop-no-body.js:2,0");
|
||||||
|
assert.strictEqual(lines[1], "for (var i = 0; i < 1; i++) ");
|
||||||
|
assert.strictEqual(lines[2], " ^");
|
||||||
|
assert.strictEqual(lines[3], "SyntaxError: Unexpected token: eof (undefined)");
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
it("Should support hyphen as shorthand", function(done) {
|
||||||
|
var command = uglifyjscmd + ' test/input/issue-1431/sample.js -m keep-fnames=true';
|
||||||
|
|
||||||
|
exec(command, function (err, stdout) {
|
||||||
|
if (err) throw err;
|
||||||
|
|
||||||
|
assert.strictEqual(stdout, "function f(r){return function(){function n(n){return n*n}return r(n)}}function g(n){return n(1)+n(2)}console.log(f(g)()==5);\n");
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
it("Should throw syntax error (5--)", function(done) {
|
||||||
|
var command = uglifyjscmd + ' test/input/invalid/assign_1.js';
|
||||||
|
|
||||||
|
exec(command, function (err, stdout, stderr) {
|
||||||
|
assert.ok(err);
|
||||||
|
assert.strictEqual(stdout, "");
|
||||||
|
assert.strictEqual(stderr.split(/\n/).slice(0, 4).join("\n"), [
|
||||||
|
"Parse error at test/input/invalid/assign_1.js:1,18",
|
||||||
|
"console.log(1 || 5--);",
|
||||||
|
" ^",
|
||||||
|
"SyntaxError: Invalid use of -- operator"
|
||||||
|
].join("\n"));
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
it("Should throw syntax error (Math.random() /= 2)", function(done) {
|
||||||
|
var command = uglifyjscmd + ' test/input/invalid/assign_2.js';
|
||||||
|
|
||||||
|
exec(command, function (err, stdout, stderr) {
|
||||||
|
assert.ok(err);
|
||||||
|
assert.strictEqual(stdout, "");
|
||||||
|
assert.strictEqual(stderr.split(/\n/).slice(0, 4).join("\n"), [
|
||||||
|
"Parse error at test/input/invalid/assign_2.js:1,32",
|
||||||
|
"console.log(2 || (Math.random() /= 2));",
|
||||||
|
" ^",
|
||||||
|
"SyntaxError: Invalid assignment"
|
||||||
|
].join("\n"));
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
it("Should throw syntax error (++this)", function(done) {
|
||||||
|
var command = uglifyjscmd + ' test/input/invalid/assign_3.js';
|
||||||
|
|
||||||
|
exec(command, function (err, stdout, stderr) {
|
||||||
|
assert.ok(err);
|
||||||
|
assert.strictEqual(stdout, "");
|
||||||
|
assert.strictEqual(stderr.split(/\n/).slice(0, 4).join("\n"), [
|
||||||
|
"Parse error at test/input/invalid/assign_3.js:1,18",
|
||||||
|
"console.log(3 || ++this);",
|
||||||
|
" ^",
|
||||||
|
"SyntaxError: Invalid use of ++ operator"
|
||||||
|
].join("\n"));
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -72,4 +72,12 @@ describe("comment filters", function() {
|
|||||||
assert.strictEqual(UglifyJS.parse("/* ok */ function a(){}").print_to_string(options), "/* ok */function a(){}");
|
assert.strictEqual(UglifyJS.parse("/* ok */ function a(){}").print_to_string(options), "/* ok */function a(){}");
|
||||||
assert.strictEqual(UglifyJS.parse("/* ok */ function a(){}").print_to_string(options), "/* ok */function a(){}");
|
assert.strictEqual(UglifyJS.parse("/* ok */ function a(){}").print_to_string(options), "/* ok */function a(){}");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("Should handle shebang and preamble correctly", function() {
|
||||||
|
var code = UglifyJS.minify("#!/usr/bin/node\nvar x = 10;", {
|
||||||
|
fromString: true,
|
||||||
|
output: { preamble: "/* Build */" }
|
||||||
|
}).code;
|
||||||
|
assert.strictEqual(code, "#!/usr/bin/node\n/* Build */\nvar x=10;");
|
||||||
|
})
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -176,7 +176,7 @@ describe("Directives", function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it("Should test EXPECT_DIRECTIVE RegExp", function() {
|
it("Should test EXPECT_DIRECTIVE RegExp", function() {
|
||||||
var tests = [
|
[
|
||||||
["", true],
|
["", true],
|
||||||
["'test';", true],
|
["'test';", true],
|
||||||
["'test';;", true],
|
["'test';;", true],
|
||||||
@@ -185,11 +185,12 @@ describe("Directives", function() {
|
|||||||
["'tests'; \n\t", true],
|
["'tests'; \n\t", true],
|
||||||
["'tests';\n\n", true],
|
["'tests';\n\n", true],
|
||||||
["\n\n\"use strict\";\n\n", true]
|
["\n\n\"use strict\";\n\n", true]
|
||||||
];
|
].forEach(function(test) {
|
||||||
|
var out = uglify.OutputStream();
|
||||||
for (var i = 0; i < tests.length; i++) {
|
out.print(test[0]);
|
||||||
assert.strictEqual(uglify.EXPECT_DIRECTIVE.test(tests[i][0]), tests[i][1], tests[i][0]);
|
out.print_string("", null, true);
|
||||||
}
|
assert.strictEqual(out.get() === test[0] + ';""', test[1], test[0]);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should only print 2 semicolons spread over 2 lines in beautify mode", function() {
|
it("Should only print 2 semicolons spread over 2 lines in beautify mode", function() {
|
||||||
|
|||||||
@@ -1,19 +1,16 @@
|
|||||||
var Uglify = require('../../');
|
var Uglify = require('../../');
|
||||||
var assert = require("assert");
|
var assert = require("assert");
|
||||||
|
var path = require("path");
|
||||||
|
|
||||||
describe("minify() with input file globs", function() {
|
describe("minify() with input file globs", function() {
|
||||||
it("minify() with one input file glob string.", function() {
|
it("minify() with one input file glob string.", function() {
|
||||||
var result = Uglify.minify("test/input/issue-1242/foo.*", {
|
var result = Uglify.minify("test/input/issue-1242/foo.*");
|
||||||
compress: { collapse_vars: true }
|
|
||||||
});
|
|
||||||
assert.strictEqual(result.code, 'function foo(o){print("Foo:",2*o)}var print=console.log.bind(console);');
|
assert.strictEqual(result.code, 'function foo(o){print("Foo:",2*o)}var print=console.log.bind(console);');
|
||||||
});
|
});
|
||||||
it("minify() with an array of one input file glob.", function() {
|
it("minify() with an array of one input file glob.", function() {
|
||||||
var result = Uglify.minify([
|
var result = Uglify.minify([
|
||||||
"test/input/issue-1242/b*.es5",
|
"test/input/issue-1242/b*.es5",
|
||||||
], {
|
]);
|
||||||
compress: { collapse_vars: true }
|
|
||||||
});
|
|
||||||
assert.strictEqual(result.code, 'function bar(n){return 3*n}function baz(n){return n/2}');
|
assert.strictEqual(result.code, 'function bar(n){return 3*n}function baz(n){return n/2}');
|
||||||
});
|
});
|
||||||
it("minify() with an array of multiple input file globs.", function() {
|
it("minify() with an array of multiple input file globs.", function() {
|
||||||
@@ -21,8 +18,41 @@ describe("minify() with input file globs", function() {
|
|||||||
"test/input/issue-1242/???.es5",
|
"test/input/issue-1242/???.es5",
|
||||||
"test/input/issue-1242/*.js",
|
"test/input/issue-1242/*.js",
|
||||||
], {
|
], {
|
||||||
compress: { collapse_vars: true }
|
compress: { toplevel: true }
|
||||||
});
|
});
|
||||||
assert.strictEqual(result.code, 'function bar(n){return 3*n}function baz(n){return n/2}function foo(n){print("Foo:",2*n)}var print=console.log.bind(console);print("qux",bar(3),baz(12)),foo(11);');
|
assert.strictEqual(result.code, 'var print=console.log.bind(console),a=function(n){return 3*n}(3),b=function(n){return n/2}(12);print("qux",a,b),function(n){print("Foo:",2*n)}(11);');
|
||||||
|
});
|
||||||
|
it("should throw with non-matching glob string", function() {
|
||||||
|
var glob = "test/input/issue-1242/blah.*";
|
||||||
|
assert.strictEqual(Uglify.simple_glob(glob).length, 1);
|
||||||
|
assert.strictEqual(Uglify.simple_glob(glob)[0], glob);
|
||||||
|
assert.throws(function() {
|
||||||
|
Uglify.minify(glob);
|
||||||
|
}, "should throw file not found");
|
||||||
|
});
|
||||||
|
it('"?" in glob string should not match "/"', function() {
|
||||||
|
var glob = "test/input?issue-1242/foo.*";
|
||||||
|
assert.strictEqual(Uglify.simple_glob(glob).length, 1);
|
||||||
|
assert.strictEqual(Uglify.simple_glob(glob)[0], glob);
|
||||||
|
assert.throws(function() {
|
||||||
|
Uglify.minify(glob);
|
||||||
|
}, "should throw file not found");
|
||||||
|
});
|
||||||
|
it("should handle special characters in glob string", function() {
|
||||||
|
var result = Uglify.minify("test/input/issue-1632/^{*}[???](*)+$.??");
|
||||||
|
assert.strictEqual(result.code, "console.log(x);");
|
||||||
|
});
|
||||||
|
it("should handle array of glob strings - matching and otherwise", function() {
|
||||||
|
var dir = "test/input/issue-1242";
|
||||||
|
var matches = Uglify.simple_glob([
|
||||||
|
path.join(dir, "b*.es5"),
|
||||||
|
path.join(dir, "z*.es5"),
|
||||||
|
path.join(dir, "*.js"),
|
||||||
|
]);
|
||||||
|
assert.strictEqual(matches.length, 4);
|
||||||
|
assert.strictEqual(matches[0], path.join(dir, "bar.es5"));
|
||||||
|
assert.strictEqual(matches[1], path.join(dir, "baz.es5"));
|
||||||
|
assert.strictEqual(matches[2], path.join(dir, "z*.es5"));
|
||||||
|
assert.strictEqual(matches[3], path.join(dir, "qux.js"));
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -78,6 +78,7 @@ describe("minify", function() {
|
|||||||
});
|
});
|
||||||
it("Should process inline source map", function() {
|
it("Should process inline source map", function() {
|
||||||
var code = Uglify.minify("./test/input/issue-520/input.js", {
|
var code = Uglify.minify("./test/input/issue-520/input.js", {
|
||||||
|
compress: { toplevel: true },
|
||||||
inSourceMap: "inline",
|
inSourceMap: "inline",
|
||||||
sourceMapInline: true
|
sourceMapInline: true
|
||||||
}).code + "\n";
|
}).code + "\n";
|
||||||
@@ -154,6 +155,17 @@ describe("minify", function() {
|
|||||||
var code = result.code;
|
var code = result.code;
|
||||||
assert.strictEqual(code, "// comment1 comment2\nbar();");
|
assert.strictEqual(code, "// comment1 comment2\nbar();");
|
||||||
});
|
});
|
||||||
|
it("should not drop #__PURE__ hint if function is retained", function() {
|
||||||
|
var result = Uglify.minify("var a = /*#__PURE__*/(function(){ foo(); })();", {
|
||||||
|
fromString: true,
|
||||||
|
output: {
|
||||||
|
comments: "all",
|
||||||
|
beautify: false,
|
||||||
|
}
|
||||||
|
});
|
||||||
|
var code = result.code;
|
||||||
|
assert.strictEqual(code, "var a=/*#__PURE__*/function(){foo()}();");
|
||||||
|
})
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("JS_Parse_Error", function() {
|
describe("JS_Parse_Error", function() {
|
||||||
@@ -171,4 +183,13 @@ describe("minify", function() {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe("Compressor", function() {
|
||||||
|
it("should be backward compatible with ast.transform(compressor)", function() {
|
||||||
|
var ast = Uglify.parse("function f(a){for(var i=0;i<a;i++)console.log(i)}");
|
||||||
|
ast.figure_out_scope();
|
||||||
|
ast = ast.transform(Uglify.Compressor());
|
||||||
|
assert.strictEqual(ast.print_to_string(), "function f(a){for(var i=0;i<a;i++)console.log(i)}");
|
||||||
|
});
|
||||||
|
})
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|||||||
54
test/mocha/release.js
Normal file
54
test/mocha/release.js
Normal file
@@ -0,0 +1,54 @@
|
|||||||
|
var assert = require("assert");
|
||||||
|
var spawn = require("child_process").spawn;
|
||||||
|
|
||||||
|
if (!process.env.UGLIFYJS_TEST_ALL) return;
|
||||||
|
|
||||||
|
function run(command, args, done) {
|
||||||
|
var id = setInterval(function() {
|
||||||
|
process.stdout.write("\0");
|
||||||
|
}, 5 * 60 * 1000);
|
||||||
|
spawn(command, args, {
|
||||||
|
stdio: "ignore"
|
||||||
|
}).on("exit", function(code) {
|
||||||
|
clearInterval(id);
|
||||||
|
assert.strictEqual(code, 0);
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
describe("test/benchmark.js", function() {
|
||||||
|
this.timeout(5 * 60 * 1000);
|
||||||
|
[
|
||||||
|
"-b",
|
||||||
|
"-b bracketize",
|
||||||
|
"-m",
|
||||||
|
"-mc passes=3",
|
||||||
|
"-mc passes=3,toplevel",
|
||||||
|
"-mc passes=3,unsafe",
|
||||||
|
"-mc keep_fargs=false,passes=3",
|
||||||
|
"-mc keep_fargs=false,passes=3,pure_getters,unsafe,unsafe_comps,unsafe_math,unsafe_proto",
|
||||||
|
].forEach(function(options) {
|
||||||
|
it("Should pass with options " + options, function(done) {
|
||||||
|
var args = options.split(/ /);
|
||||||
|
args.unshift("test/benchmark.js");
|
||||||
|
run(process.argv[0], args, done);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe("test/jetstream.js", function() {
|
||||||
|
this.timeout(20 * 60 * 1000);
|
||||||
|
it("Should install phantomjs-prebuilt", function(done) {
|
||||||
|
run("npm", ["install", "phantomjs-prebuilt@2.1.14"], done);
|
||||||
|
});
|
||||||
|
[
|
||||||
|
"-mc warnings=false",
|
||||||
|
"-mc keep_fargs=false,passes=3,pure_getters,unsafe,unsafe_comps,unsafe_math,unsafe_proto,warnings=false",
|
||||||
|
].forEach(function(options) {
|
||||||
|
it("Should pass with options " + options, function(done) {
|
||||||
|
var args = options.split(/ /);
|
||||||
|
args.unshift("test/jetstream.js");
|
||||||
|
run(process.argv[0], args, done);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -5,7 +5,7 @@ var UglifyJS = require(".."),
|
|||||||
escodegen = require("escodegen"),
|
escodegen = require("escodegen"),
|
||||||
esfuzz = require("esfuzz"),
|
esfuzz = require("esfuzz"),
|
||||||
estraverse = require("estraverse"),
|
estraverse = require("estraverse"),
|
||||||
prefix = Array(20).join("\b") + " ";
|
prefix = "\r ";
|
||||||
|
|
||||||
// Normalizes input AST for UglifyJS in order to get correct comparison.
|
// Normalizes input AST for UglifyJS in order to get correct comparison.
|
||||||
|
|
||||||
|
|||||||
@@ -1,15 +1,25 @@
|
|||||||
#! /usr/bin/env node
|
#! /usr/bin/env node
|
||||||
|
|
||||||
global.UGLIFY_DEBUG = true;
|
|
||||||
|
|
||||||
var U = require("../tools/node");
|
var U = require("../tools/node");
|
||||||
var path = require("path");
|
var path = require("path");
|
||||||
var fs = require("fs");
|
var fs = require("fs");
|
||||||
var assert = require("assert");
|
var assert = require("assert");
|
||||||
|
var vm = require("vm");
|
||||||
|
|
||||||
var tests_dir = path.dirname(module.filename);
|
var tests_dir = path.dirname(module.filename);
|
||||||
var failures = 0;
|
var failures = 0;
|
||||||
var failed_files = {};
|
var failed_files = {};
|
||||||
|
var same_stdout = ~process.version.lastIndexOf("v0.12.", 0) ? function(expected, actual) {
|
||||||
|
if (typeof expected != typeof actual) return false;
|
||||||
|
if (typeof expected != "string") {
|
||||||
|
if (expected.name != actual.name) return false;
|
||||||
|
expected = expected.message.slice(expected.message.lastIndexOf("\n") + 1);
|
||||||
|
actual = actual.message.slice(actual.message.lastIndexOf("\n") + 1);
|
||||||
|
}
|
||||||
|
return expected == actual;
|
||||||
|
} : function(expected, actual) {
|
||||||
|
return typeof expected == typeof actual && expected.toString() == actual.toString();
|
||||||
|
};
|
||||||
|
|
||||||
run_compress_tests();
|
run_compress_tests();
|
||||||
if (failures) {
|
if (failures) {
|
||||||
@@ -71,10 +81,15 @@ function test_directory(dir) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function as_toplevel(input, mangle_options) {
|
function as_toplevel(input, mangle_options) {
|
||||||
if (input instanceof U.AST_BlockStatement) input = input.body;
|
if (!(input instanceof U.AST_BlockStatement))
|
||||||
else if (input instanceof U.AST_Statement) input = [ input ];
|
throw new Error("Unsupported input syntax");
|
||||||
else throw new Error("Unsupported input syntax");
|
for (var i = 0; i < input.body.length; i++) {
|
||||||
var toplevel = new U.AST_Toplevel({ body: input });
|
var stat = input.body[i];
|
||||||
|
if (stat instanceof U.AST_SimpleStatement && stat.body instanceof U.AST_String)
|
||||||
|
input.body[i] = new U.AST_Directive(stat.body);
|
||||||
|
else break;
|
||||||
|
}
|
||||||
|
var toplevel = new U.AST_Toplevel(input);
|
||||||
toplevel.figure_out_scope(mangle_options);
|
toplevel.figure_out_scope(mangle_options);
|
||||||
return toplevel;
|
return toplevel;
|
||||||
}
|
}
|
||||||
@@ -88,6 +103,23 @@ function run_compress_tests() {
|
|||||||
function test_case(test) {
|
function test_case(test) {
|
||||||
log_test(test.name);
|
log_test(test.name);
|
||||||
U.base54.reset();
|
U.base54.reset();
|
||||||
|
var output_options = test.beautify || {};
|
||||||
|
var expect;
|
||||||
|
if (test.expect) {
|
||||||
|
expect = make_code(as_toplevel(test.expect, test.mangle), output_options);
|
||||||
|
} else {
|
||||||
|
expect = test.expect_exact;
|
||||||
|
}
|
||||||
|
var input = as_toplevel(test.input, test.mangle);
|
||||||
|
var input_code = make_code(input, output_options);
|
||||||
|
var input_formatted = make_code(test.input, {
|
||||||
|
beautify: true,
|
||||||
|
quote_style: 3,
|
||||||
|
keep_quoted_props: true
|
||||||
|
});
|
||||||
|
if (test.mangle_props) {
|
||||||
|
input = U.mangle_properties(input, test.mangle_props);
|
||||||
|
}
|
||||||
var options = U.defaults(test.options, {
|
var options = U.defaults(test.options, {
|
||||||
warnings: false
|
warnings: false
|
||||||
});
|
});
|
||||||
@@ -97,25 +129,9 @@ function run_compress_tests() {
|
|||||||
U.AST_Node.warn_function = function(text) {
|
U.AST_Node.warn_function = function(text) {
|
||||||
warnings_emitted.push("WARN: " + text);
|
warnings_emitted.push("WARN: " + text);
|
||||||
};
|
};
|
||||||
options.warnings = true;
|
if (!options.warnings) options.warnings = true;
|
||||||
}
|
}
|
||||||
var cmp = new U.Compressor(options, true);
|
var cmp = new U.Compressor(options, true);
|
||||||
var output_options = test.beautify || {};
|
|
||||||
var expect;
|
|
||||||
if (test.expect) {
|
|
||||||
expect = make_code(as_toplevel(test.expect, test.mangle), output_options);
|
|
||||||
} else {
|
|
||||||
expect = test.expect_exact;
|
|
||||||
}
|
|
||||||
var input = as_toplevel(test.input, test.mangle);
|
|
||||||
var input_code = make_code(test.input, {
|
|
||||||
beautify: true,
|
|
||||||
quote_style: 3,
|
|
||||||
keep_quoted_props: true
|
|
||||||
});
|
|
||||||
if (test.mangle_props) {
|
|
||||||
input = U.mangle_properties(input, test.mangle_props);
|
|
||||||
}
|
|
||||||
var output = cmp.compress(input);
|
var output = cmp.compress(input);
|
||||||
output.figure_out_scope(test.mangle);
|
output.figure_out_scope(test.mangle);
|
||||||
if (test.mangle) {
|
if (test.mangle) {
|
||||||
@@ -125,7 +141,7 @@ function run_compress_tests() {
|
|||||||
output = make_code(output, output_options);
|
output = make_code(output, output_options);
|
||||||
if (expect != output) {
|
if (expect != output) {
|
||||||
log("!!! failed\n---INPUT---\n{input}\n---OUTPUT---\n{output}\n---EXPECTED---\n{expected}\n\n", {
|
log("!!! failed\n---INPUT---\n{input}\n---OUTPUT---\n{output}\n---EXPECTED---\n{expected}\n\n", {
|
||||||
input: input_code,
|
input: input_formatted,
|
||||||
output: output,
|
output: output,
|
||||||
expected: expect
|
expected: expect
|
||||||
});
|
});
|
||||||
@@ -138,7 +154,7 @@ function run_compress_tests() {
|
|||||||
var reparsed_ast = U.parse(output);
|
var reparsed_ast = U.parse(output);
|
||||||
} catch (ex) {
|
} catch (ex) {
|
||||||
log("!!! Test matched expected result but cannot parse output\n---INPUT---\n{input}\n---OUTPUT---\n{output}\n--REPARSE ERROR--\n{error}\n\n", {
|
log("!!! Test matched expected result but cannot parse output\n---INPUT---\n{input}\n---OUTPUT---\n{output}\n--REPARSE ERROR--\n{error}\n\n", {
|
||||||
input: input_code,
|
input: input_formatted,
|
||||||
output: output,
|
output: output,
|
||||||
error: ex.toString(),
|
error: ex.toString(),
|
||||||
});
|
});
|
||||||
@@ -157,7 +173,7 @@ function run_compress_tests() {
|
|||||||
var actual_warnings = JSON.stringify(warnings_emitted);
|
var actual_warnings = JSON.stringify(warnings_emitted);
|
||||||
if (expected_warnings != actual_warnings) {
|
if (expected_warnings != actual_warnings) {
|
||||||
log("!!! failed\n---INPUT---\n{input}\n---EXPECTED WARNINGS---\n{expected_warnings}\n---ACTUAL WARNINGS---\n{actual_warnings}\n\n", {
|
log("!!! failed\n---INPUT---\n{input}\n---EXPECTED WARNINGS---\n{expected_warnings}\n---ACTUAL WARNINGS---\n{actual_warnings}\n\n", {
|
||||||
input: input_code,
|
input: input_formatted,
|
||||||
expected_warnings: expected_warnings,
|
expected_warnings: expected_warnings,
|
||||||
actual_warnings: actual_warnings,
|
actual_warnings: actual_warnings,
|
||||||
});
|
});
|
||||||
@@ -165,6 +181,36 @@ function run_compress_tests() {
|
|||||||
failed_files[file] = 1;
|
failed_files[file] = 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (test.expect_stdout) {
|
||||||
|
var stdout = run_code(input_code);
|
||||||
|
if (test.expect_stdout === true) {
|
||||||
|
test.expect_stdout = stdout;
|
||||||
|
}
|
||||||
|
if (!same_stdout(test.expect_stdout, stdout)) {
|
||||||
|
log("!!! Invalid input or expected stdout\n---INPUT---\n{input}\n---EXPECTED {expected_type}---\n{expected}\n---ACTUAL {actual_type}---\n{actual}\n\n", {
|
||||||
|
input: input_formatted,
|
||||||
|
expected_type: typeof test.expect_stdout == "string" ? "STDOUT" : "ERROR",
|
||||||
|
expected: test.expect_stdout,
|
||||||
|
actual_type: typeof stdout == "string" ? "STDOUT" : "ERROR",
|
||||||
|
actual: stdout,
|
||||||
|
});
|
||||||
|
failures++;
|
||||||
|
failed_files[file] = 1;
|
||||||
|
} else {
|
||||||
|
stdout = run_code(output);
|
||||||
|
if (!same_stdout(test.expect_stdout, stdout)) {
|
||||||
|
log("!!! failed\n---INPUT---\n{input}\n---EXPECTED {expected_type}---\n{expected}\n---ACTUAL {actual_type}---\n{actual}\n\n", {
|
||||||
|
input: input_formatted,
|
||||||
|
expected_type: typeof test.expect_stdout == "string" ? "STDOUT" : "ERROR",
|
||||||
|
expected: test.expect_stdout,
|
||||||
|
actual_type: typeof stdout == "string" ? "STDOUT" : "ERROR",
|
||||||
|
actual: stdout,
|
||||||
|
});
|
||||||
|
failures++;
|
||||||
|
failed_files[file] = 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
var tests = parse_test(path.resolve(dir, file));
|
var tests = parse_test(path.resolve(dir, file));
|
||||||
@@ -214,6 +260,23 @@ function parse_test(file) {
|
|||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function read_string(stat) {
|
||||||
|
if (stat.TYPE == "SimpleStatement") {
|
||||||
|
var body = stat.body;
|
||||||
|
switch(body.TYPE) {
|
||||||
|
case "String":
|
||||||
|
return body.value;
|
||||||
|
case "Array":
|
||||||
|
return body.elements.map(function(element) {
|
||||||
|
if (element.TYPE !== "String")
|
||||||
|
throw new Error("Should be array of strings");
|
||||||
|
return element.value;
|
||||||
|
}).join("\n");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
throw new Error("Should be string or array of strings");
|
||||||
|
}
|
||||||
|
|
||||||
function get_one_test(name, block) {
|
function get_one_test(name, block) {
|
||||||
var test = { name: name, options: {} };
|
var test = { name: name, options: {} };
|
||||||
var tw = new U.TreeWalker(function(node, descend){
|
var tw = new U.TreeWalker(function(node, descend){
|
||||||
@@ -226,28 +289,26 @@ function parse_test(file) {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (node instanceof U.AST_LabeledStatement) {
|
if (node instanceof U.AST_LabeledStatement) {
|
||||||
|
var label = node.label;
|
||||||
assert.ok(
|
assert.ok(
|
||||||
["input", "expect", "expect_exact", "expect_warnings"].indexOf(node.label.name) >= 0,
|
["input", "expect", "expect_exact", "expect_warnings", "expect_stdout"].indexOf(label.name) >= 0,
|
||||||
tmpl("Unsupported label {name} [{line},{col}]", {
|
tmpl("Unsupported label {name} [{line},{col}]", {
|
||||||
name: node.label.name,
|
name: label.name,
|
||||||
line: node.label.start.line,
|
line: label.start.line,
|
||||||
col: node.label.start.col
|
col: label.start.col
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
var stat = node.body;
|
var stat = node.body;
|
||||||
if (stat instanceof U.AST_BlockStatement) {
|
if (label.name == "expect_exact") {
|
||||||
if (stat.body.length == 1) stat = stat.body[0];
|
test[label.name] = read_string(stat);
|
||||||
else if (stat.body.length == 0) stat = new U.AST_EmptyStatement();
|
} else if (label.name == "expect_stdout") {
|
||||||
}
|
if (stat.TYPE == "SimpleStatement" && stat.body instanceof U.AST_Boolean) {
|
||||||
if (node.label.name === "expect_exact") {
|
test[label.name] = stat.body.value;
|
||||||
if (!(stat.TYPE === "SimpleStatement" && stat.body.TYPE === "String")) {
|
} else {
|
||||||
throw new Error(
|
test[label.name] = read_string(stat) + "\n";
|
||||||
"The value of the expect_exact clause should be a string, " +
|
|
||||||
"like `expect_exact: \"some.exact.javascript;\"`");
|
|
||||||
}
|
}
|
||||||
test[node.label.name] = stat.body.start.value
|
|
||||||
} else {
|
} else {
|
||||||
test[node.label.name] = stat;
|
test[label.name] = stat;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -269,3 +330,19 @@ function evaluate(code) {
|
|||||||
code = make_code(code, { beautify: true });
|
code = make_code(code, { beautify: true });
|
||||||
return new Function("return(" + code + ")")();
|
return new Function("return(" + code + ")")();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function run_code(code) {
|
||||||
|
var stdout = "";
|
||||||
|
var original_write = process.stdout.write;
|
||||||
|
process.stdout.write = function(chunk) {
|
||||||
|
stdout += chunk;
|
||||||
|
};
|
||||||
|
try {
|
||||||
|
new vm.Script(code).runInNewContext({ console: console }, { timeout: 5000 });
|
||||||
|
return stdout;
|
||||||
|
} catch (ex) {
|
||||||
|
return ex;
|
||||||
|
} finally {
|
||||||
|
process.stdout.write = original_write;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
477
test/ufuzz.js
Normal file
477
test/ufuzz.js
Normal file
@@ -0,0 +1,477 @@
|
|||||||
|
// ufuzz.js
|
||||||
|
// derived from https://github.com/qfox/uglyfuzzer by Peter van der Zee
|
||||||
|
"use strict";
|
||||||
|
|
||||||
|
// workaround for tty output truncation upon process.exit()
|
||||||
|
[process.stdout, process.stderr].forEach(function(stream){
|
||||||
|
if (stream._handle && stream._handle.setBlocking)
|
||||||
|
stream._handle.setBlocking(true);
|
||||||
|
});
|
||||||
|
|
||||||
|
var vm = require("vm");
|
||||||
|
var minify = require("..").minify;
|
||||||
|
|
||||||
|
var MAX_GENERATED_FUNCTIONS_PER_RUN = 1;
|
||||||
|
var MAX_GENERATION_RECURSION_DEPTH = 15;
|
||||||
|
var INTERVAL_COUNT = 100;
|
||||||
|
|
||||||
|
var VALUES = [
|
||||||
|
'true',
|
||||||
|
'false',
|
||||||
|
'22',
|
||||||
|
'0',
|
||||||
|
'-0', // 0/-0 !== 0
|
||||||
|
'23..toString()',
|
||||||
|
'24 .toString()',
|
||||||
|
'25. ',
|
||||||
|
'0x26.toString()',
|
||||||
|
'(-1)',
|
||||||
|
'NaN',
|
||||||
|
'undefined',
|
||||||
|
'Infinity',
|
||||||
|
'null',
|
||||||
|
'[]',
|
||||||
|
'[,0][1]', // an array with elisions... but this is always false
|
||||||
|
'([,0].length === 2)', // an array with elisions... this is always true
|
||||||
|
'({})', // wrapped the object causes too many syntax errors in statements
|
||||||
|
'"foo"',
|
||||||
|
'"bar"' ];
|
||||||
|
|
||||||
|
var BINARY_OPS_NO_COMMA = [
|
||||||
|
' + ', // spaces needed to disambiguate with ++ cases (could otherwise cause syntax errors)
|
||||||
|
' - ',
|
||||||
|
'/',
|
||||||
|
'*',
|
||||||
|
'&',
|
||||||
|
'|',
|
||||||
|
'^',
|
||||||
|
'<<',
|
||||||
|
'>>',
|
||||||
|
'>>>',
|
||||||
|
'%',
|
||||||
|
'&&',
|
||||||
|
'||',
|
||||||
|
'^' ];
|
||||||
|
|
||||||
|
var BINARY_OPS = [','].concat(BINARY_OPS_NO_COMMA);
|
||||||
|
|
||||||
|
var ASSIGNMENTS = [
|
||||||
|
'=',
|
||||||
|
'=',
|
||||||
|
'=',
|
||||||
|
'=',
|
||||||
|
'=',
|
||||||
|
'=',
|
||||||
|
|
||||||
|
'==',
|
||||||
|
'!=',
|
||||||
|
'===',
|
||||||
|
'!==',
|
||||||
|
'+=',
|
||||||
|
'-=',
|
||||||
|
'*=',
|
||||||
|
'/=',
|
||||||
|
'&=',
|
||||||
|
'|=',
|
||||||
|
'^=',
|
||||||
|
'<<=',
|
||||||
|
'>>=',
|
||||||
|
'>>>=',
|
||||||
|
'%=' ];
|
||||||
|
|
||||||
|
var UNARY_OPS = [
|
||||||
|
'--',
|
||||||
|
'++',
|
||||||
|
'~',
|
||||||
|
'!',
|
||||||
|
'void ',
|
||||||
|
'delete ', // should be safe, even `delete foo` and `delete f()` shouldn't crash
|
||||||
|
' - ',
|
||||||
|
' + ' ];
|
||||||
|
|
||||||
|
var NO_COMMA = true;
|
||||||
|
var MAYBE = true;
|
||||||
|
var NESTED = true;
|
||||||
|
var CAN_THROW = true;
|
||||||
|
var CANNOT_THROW = false;
|
||||||
|
var CAN_BREAK = true;
|
||||||
|
var CAN_CONTINUE = true;
|
||||||
|
|
||||||
|
var VAR_NAMES = [
|
||||||
|
'foo',
|
||||||
|
'bar',
|
||||||
|
'a',
|
||||||
|
'b',
|
||||||
|
'undefined', // fun!
|
||||||
|
'eval', // mmmm, ok, also fun!
|
||||||
|
'NaN', // mmmm, ok, also fun!
|
||||||
|
'Infinity', // the fun never ends!
|
||||||
|
'arguments', // this one is just creepy
|
||||||
|
'Math', // since Math is assumed to be a non-constructor/function it may trip certain cases
|
||||||
|
'let' ]; // maybe omit this, it's more a parser problem than minifier
|
||||||
|
|
||||||
|
var TYPEOF_OUTCOMES = [
|
||||||
|
'undefined',
|
||||||
|
'string',
|
||||||
|
'number',
|
||||||
|
'object',
|
||||||
|
'boolean',
|
||||||
|
'special',
|
||||||
|
'unknown',
|
||||||
|
'symbol',
|
||||||
|
'crap' ];
|
||||||
|
|
||||||
|
var FUNC_TOSTRING = [
|
||||||
|
"Function.prototype.toString = function() {",
|
||||||
|
" var ids = [];",
|
||||||
|
" return function() {",
|
||||||
|
" var i = ids.indexOf(this);",
|
||||||
|
" if (i < 0) {",
|
||||||
|
" i = ids.length;",
|
||||||
|
" ids.push(this);",
|
||||||
|
" }",
|
||||||
|
' return "[Function: __func_" + i + "__]";',
|
||||||
|
" }",
|
||||||
|
"}();",
|
||||||
|
""
|
||||||
|
].join("\n");
|
||||||
|
|
||||||
|
function run_code(code) {
|
||||||
|
var stdout = "";
|
||||||
|
var original_write = process.stdout.write;
|
||||||
|
process.stdout.write = function(chunk) {
|
||||||
|
stdout += chunk;
|
||||||
|
};
|
||||||
|
try {
|
||||||
|
new vm.Script(FUNC_TOSTRING + code).runInNewContext({
|
||||||
|
console: {
|
||||||
|
log: function() {
|
||||||
|
return console.log.apply(console, [].map.call(arguments, function(arg) {
|
||||||
|
return typeof arg == "function" ? "[Function]" : arg;
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}, { timeout: 5000 });
|
||||||
|
return stdout;
|
||||||
|
} catch (ex) {
|
||||||
|
return ex;
|
||||||
|
} finally {
|
||||||
|
process.stdout.write = original_write;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function rng(max) {
|
||||||
|
return Math.floor(max * Math.random());
|
||||||
|
}
|
||||||
|
|
||||||
|
function createFunctionDecls(n, recurmax, nested) {
|
||||||
|
if (--recurmax < 0) { return ';'; }
|
||||||
|
var s = '';
|
||||||
|
while (n-- > 0) {
|
||||||
|
s += createFunctionDecl(recurmax, nested) + '\n';
|
||||||
|
}
|
||||||
|
return s;
|
||||||
|
}
|
||||||
|
|
||||||
|
var funcs = 0;
|
||||||
|
function createFunctionDecl(recurmax, nested) {
|
||||||
|
if (--recurmax < 0) { return ';'; }
|
||||||
|
var func = funcs++;
|
||||||
|
var name = rng(5) > 0 ? 'f' + func : createVarName();
|
||||||
|
if (name === 'a' || name === 'b') name = 'f' + func; // quick hack to prevent assignment to func names of being called
|
||||||
|
if (!nested && name === 'undefined' || name === 'NaN' || name === 'Infinity') name = 'f' + func; // cant redefine these in global space
|
||||||
|
var s = '';
|
||||||
|
if (rng(5) === 1) {
|
||||||
|
// functions with functions. lower the recursion to prevent a mess.
|
||||||
|
s = 'function ' + name + '(){' + createFunctionDecls(rng(5) + 1, Math.ceil(recurmax / 2), NESTED) + '}\n';
|
||||||
|
} else {
|
||||||
|
// functions with statements
|
||||||
|
s = 'function ' + name + '(){' + createStatements(3, recurmax) + '}\n';
|
||||||
|
}
|
||||||
|
|
||||||
|
if (nested) s = '!' + nested; // avoid "function statements" (decl inside statements)
|
||||||
|
else s += name + '();'
|
||||||
|
|
||||||
|
return s;
|
||||||
|
}
|
||||||
|
|
||||||
|
function createStatements(n, recurmax, canThrow, canBreak, canContinue) {
|
||||||
|
if (--recurmax < 0) { return ';'; }
|
||||||
|
var s = '';
|
||||||
|
while (--n > 0) {
|
||||||
|
s += createStatement(recurmax, canThrow, canBreak, canContinue);
|
||||||
|
}
|
||||||
|
return s;
|
||||||
|
}
|
||||||
|
|
||||||
|
var loops = 0;
|
||||||
|
function createStatement(recurmax, canThrow, canBreak, canContinue) {
|
||||||
|
var loop = ++loops;
|
||||||
|
if (--recurmax < 0) { return ';'; }
|
||||||
|
switch (rng(16)) {
|
||||||
|
case 0:
|
||||||
|
return '{' + createStatements(rng(5) + 1, recurmax, canThrow, canBreak, canContinue) + '}';
|
||||||
|
case 1:
|
||||||
|
return 'if (' + createExpression(recurmax) + ')' + createStatement(recurmax, canThrow, canBreak, canContinue) + (rng(2) === 1 ? ' else ' + createStatement(recurmax, canThrow, canBreak, canContinue) : '');
|
||||||
|
case 2:
|
||||||
|
return '{var brake' + loop + ' = 5; do {' + createStatement(recurmax, canThrow, CAN_BREAK, CAN_CONTINUE) + '} while ((' + createExpression(recurmax) + ') && --brake' + loop + ' > 0);}';
|
||||||
|
case 3:
|
||||||
|
return '{var brake' + loop + ' = 5; while ((' + createExpression(recurmax) + ') && --brake' + loop + ' > 0)' + createStatement(recurmax, canThrow, CAN_BREAK, CAN_CONTINUE) + '}';
|
||||||
|
case 4:
|
||||||
|
return 'for (var brake' + loop + ' = 5; (' + createExpression(recurmax) + ') && brake' + loop + ' > 0; --brake' + loop + ')' + createStatement(recurmax, canThrow, CAN_BREAK, CAN_CONTINUE);
|
||||||
|
case 5:
|
||||||
|
return ';';
|
||||||
|
case 6:
|
||||||
|
return createExpression(recurmax) + ';';
|
||||||
|
case 7:
|
||||||
|
// note: case args are actual expressions
|
||||||
|
// note: default does not _need_ to be last
|
||||||
|
return 'switch (' + createExpression(recurmax) + ') { ' + createSwitchParts(recurmax, 4) + '}';
|
||||||
|
case 8:
|
||||||
|
return 'var ' + createVarName() + ';';
|
||||||
|
case 9:
|
||||||
|
// initializer can only have one expression
|
||||||
|
return 'var ' + createVarName() + ' = ' + createExpression(recurmax, NO_COMMA) + ';';
|
||||||
|
case 10:
|
||||||
|
// initializer can only have one expression
|
||||||
|
return 'var ' + createVarName() + ' = ' + createExpression(recurmax, NO_COMMA) + ', ' + createVarName() + ' = ' + createExpression(recurmax, NO_COMMA) + ';';
|
||||||
|
case 11:
|
||||||
|
if (canBreak && rng(5) === 0) return 'break;';
|
||||||
|
if (canContinue && rng(5) === 0) return 'continue;';
|
||||||
|
return 'return;';
|
||||||
|
case 12:
|
||||||
|
// must wrap in curlies to prevent orphaned `else` statement
|
||||||
|
if (canThrow && rng(5) === 0) return '{ throw ' + createExpression(recurmax) + '}';
|
||||||
|
return '{ return ' + createExpression(recurmax) + '}';
|
||||||
|
case 13:
|
||||||
|
// this is actually more like a parser test, but perhaps it hits some dead code elimination traps
|
||||||
|
// must wrap in curlies to prevent orphaned `else` statement
|
||||||
|
if (canThrow && rng(5) === 0) return '{ throw\n' + createExpression(recurmax) + '}';
|
||||||
|
return '{ return\n' + createExpression(recurmax) + '}';
|
||||||
|
case 14:
|
||||||
|
// "In non-strict mode code, functions can only be declared at top level, inside a block, or ..."
|
||||||
|
// (dont both with func decls in `if`; it's only a parser thing because you cant call them without a block)
|
||||||
|
return '{' + createFunctionDecl(recurmax, NESTED) + '}';
|
||||||
|
case 15:
|
||||||
|
return ';';
|
||||||
|
// catch var could cause some problems
|
||||||
|
// note: the "blocks" are syntactically mandatory for try/catch/finally
|
||||||
|
var s = 'try {' + createStatement(recurmax, CAN_THROW, canBreak, canContinue) + ' }';
|
||||||
|
var n = rng(3); // 0=only catch, 1=only finally, 2=catch+finally
|
||||||
|
if (n !== 1) s += ' catch (' + createVarName() + ') { ' + createStatements(3, recurmax, canBreak, canContinue) + ' }';
|
||||||
|
if (n !== 0) s += ' finally { ' + createStatements(3, recurmax, canBreak, canContinue) + ' }';
|
||||||
|
return s;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function createSwitchParts(recurmax, n) {
|
||||||
|
var hadDefault = false;
|
||||||
|
var s = '';
|
||||||
|
while (n-- > 0) {
|
||||||
|
hadDefault = n > 0;
|
||||||
|
if (hadDefault || rng(4) > 0) {
|
||||||
|
s += '' +
|
||||||
|
'case ' + createExpression(recurmax) + ':\n' +
|
||||||
|
createStatements(rng(3) + 1, recurmax, CANNOT_THROW, CAN_BREAK) +
|
||||||
|
'\n' +
|
||||||
|
(rng(10) > 0 ? ' break;' : '/* fall-through */') +
|
||||||
|
'\n';
|
||||||
|
} else {
|
||||||
|
hadDefault = true;
|
||||||
|
s += '' +
|
||||||
|
'default:\n' +
|
||||||
|
createStatements(rng(3) + 1, recurmax, CANNOT_THROW, CAN_BREAK) +
|
||||||
|
'\n';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return s;
|
||||||
|
}
|
||||||
|
|
||||||
|
function createExpression(recurmax, noComma) {
|
||||||
|
if (--recurmax < 0) {
|
||||||
|
return createValue(); // note: should return a simple non-recursing expression value!
|
||||||
|
}
|
||||||
|
switch (rng(12)) {
|
||||||
|
case 0:
|
||||||
|
return '(' + createUnaryOp() + (rng(2) === 1 ? 'a' : 'b') + ')';
|
||||||
|
case 1:
|
||||||
|
return '(a' + (rng(2) == 1 ? '++' : '--') + ')';
|
||||||
|
case 2:
|
||||||
|
return '(b ' + createAssignment() + ' a)';
|
||||||
|
case 3:
|
||||||
|
return '(' + rng(2) + ' === 1 ? a : b)';
|
||||||
|
case 4:
|
||||||
|
return createExpression(recurmax, noComma) + createBinaryOp(noComma) + createExpression(recurmax, noComma);
|
||||||
|
case 5:
|
||||||
|
return createValue();
|
||||||
|
case 6:
|
||||||
|
return '(' + createExpression(recurmax) + ')';
|
||||||
|
case 7:
|
||||||
|
return createExpression(recurmax, noComma) + '?(' + createExpression(recurmax) + '):(' + createExpression(recurmax) + ')';
|
||||||
|
case 8:
|
||||||
|
switch(rng(4)) {
|
||||||
|
case 0:
|
||||||
|
return '(function ' + createVarName(MAYBE) + '(){' + createStatements(rng(5) + 1, recurmax) + '})()';
|
||||||
|
case 1:
|
||||||
|
return '+function ' + createVarName(MAYBE) + '(){' + createStatements(rng(5) + 1, recurmax) + '}';
|
||||||
|
case 2:
|
||||||
|
return '!function ' + createVarName(MAYBE) + '(){' + createStatements(rng(5) + 1, recurmax) + '}';
|
||||||
|
case 3:
|
||||||
|
return 'void function ' + createVarName(MAYBE) + '(){' + createStatements(rng(5) + 1, recurmax) + '}';
|
||||||
|
default:
|
||||||
|
return 'void function ' + createVarName(MAYBE) + '(){' + createStatements(rng(5) + 1, recurmax) + '}';
|
||||||
|
}
|
||||||
|
case 9:
|
||||||
|
return createTypeofExpr(recurmax);
|
||||||
|
case 10:
|
||||||
|
// you could statically infer that this is just `Math`, regardless of the other expression
|
||||||
|
// I don't think Uglify does this at this time...
|
||||||
|
return ''+
|
||||||
|
'new function(){ \n' +
|
||||||
|
(rng(2) === 1 ? createExpression(recurmax) + '\n' : '') +
|
||||||
|
'return Math;\n' +
|
||||||
|
'}';
|
||||||
|
case 11:
|
||||||
|
// more like a parser test but perhaps comment nodes mess up the analysis?
|
||||||
|
switch (rng(5)) {
|
||||||
|
case 0:
|
||||||
|
return '(a/* ignore */++)';
|
||||||
|
case 1:
|
||||||
|
return '(b/* ignore */--)';
|
||||||
|
case 2:
|
||||||
|
return '(++/* ignore */a)';
|
||||||
|
case 3:
|
||||||
|
return '(--/* ignore */b)';
|
||||||
|
case 4:
|
||||||
|
// only groups that wrap a single variable return a "Reference", so this is still valid.
|
||||||
|
// may just be a parser edge case that is invisible to uglify...
|
||||||
|
return '(--(b))';
|
||||||
|
default:
|
||||||
|
return '(--/* ignore */b)';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function createTypeofExpr(recurmax) {
|
||||||
|
if (--recurmax < 0) {
|
||||||
|
return 'typeof undefined === "undefined"';
|
||||||
|
}
|
||||||
|
|
||||||
|
switch (rng(5)) {
|
||||||
|
case 0:
|
||||||
|
return '(typeof ' + createVarName() + ' === "' + TYPEOF_OUTCOMES[rng(TYPEOF_OUTCOMES.length)] + '")';
|
||||||
|
case 1:
|
||||||
|
return '(typeof ' + createVarName() + ' !== "' + TYPEOF_OUTCOMES[rng(TYPEOF_OUTCOMES.length)] + '")';
|
||||||
|
case 2:
|
||||||
|
return '(typeof ' + createVarName() + ' == "' + TYPEOF_OUTCOMES[rng(TYPEOF_OUTCOMES.length)] + '")';
|
||||||
|
case 3:
|
||||||
|
return '(typeof ' + createVarName() + ' != "' + TYPEOF_OUTCOMES[rng(TYPEOF_OUTCOMES.length)] + '")';
|
||||||
|
case 4:
|
||||||
|
return '(typeof ' + createVarName() + ')';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function createValue() {
|
||||||
|
return VALUES[rng(VALUES.length)];
|
||||||
|
}
|
||||||
|
|
||||||
|
function createBinaryOp(noComma) {
|
||||||
|
if (noComma) return BINARY_OPS_NO_COMMA[rng(BINARY_OPS_NO_COMMA.length)];
|
||||||
|
return BINARY_OPS[rng(BINARY_OPS.length)];
|
||||||
|
}
|
||||||
|
|
||||||
|
function createAssignment() {
|
||||||
|
return ASSIGNMENTS[rng(ASSIGNMENTS.length)];
|
||||||
|
}
|
||||||
|
|
||||||
|
function createUnaryOp() {
|
||||||
|
return UNARY_OPS[rng(UNARY_OPS.length)];
|
||||||
|
}
|
||||||
|
|
||||||
|
function createVarName(maybe) {
|
||||||
|
if (!maybe || rng(2) === 1) {
|
||||||
|
return VAR_NAMES[rng(VAR_NAMES.length)] + (rng(5) > 0 ? ++loops : '');
|
||||||
|
}
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
|
||||||
|
function log(ok) {
|
||||||
|
console.log("//=============================================================");
|
||||||
|
if (!ok) console.log("// !!!!!! Failed...");
|
||||||
|
console.log("// original code");
|
||||||
|
console.log("//");
|
||||||
|
console.log(original_code);
|
||||||
|
console.log();
|
||||||
|
console.log();
|
||||||
|
console.log("//-------------------------------------------------------------");
|
||||||
|
console.log("// original code (beautify'd)");
|
||||||
|
console.log("//");
|
||||||
|
console.log(beautify_code);
|
||||||
|
console.log();
|
||||||
|
console.log();
|
||||||
|
console.log("//-------------------------------------------------------------");
|
||||||
|
console.log("// uglified code");
|
||||||
|
console.log("//");
|
||||||
|
console.log(uglify_code);
|
||||||
|
console.log();
|
||||||
|
console.log();
|
||||||
|
console.log("original result:");
|
||||||
|
console.log(original_result);
|
||||||
|
console.log("beautified result:");
|
||||||
|
console.log(beautify_result);
|
||||||
|
console.log("uglified result:");
|
||||||
|
console.log(uglify_result);
|
||||||
|
if (!ok) console.log("!!!!!! Failed...");
|
||||||
|
}
|
||||||
|
|
||||||
|
var num_iterations = +process.argv[2] || 1/0;
|
||||||
|
var verbose = process.argv[3] === 'v' || process.argv[2] === 'v';
|
||||||
|
var verbose_interval = process.argv[3] === 'V' || process.argv[2] === 'V';
|
||||||
|
for (var round = 0; round < num_iterations; round++) {
|
||||||
|
var parse_error = false;
|
||||||
|
process.stdout.write(round + " of " + num_iterations + "\r");
|
||||||
|
var original_code = [
|
||||||
|
"var a = 100, b = 10;",
|
||||||
|
createFunctionDecls(rng(MAX_GENERATED_FUNCTIONS_PER_RUN) + 1, MAX_GENERATION_RECURSION_DEPTH),
|
||||||
|
"console.log(a, b);"
|
||||||
|
].join("\n");
|
||||||
|
var original_result = run_code(original_code);
|
||||||
|
|
||||||
|
try {
|
||||||
|
var beautify_code = minify(original_code, {
|
||||||
|
fromString: true,
|
||||||
|
mangle: false,
|
||||||
|
compress: false,
|
||||||
|
output: {
|
||||||
|
beautify: true,
|
||||||
|
bracketize: true,
|
||||||
|
},
|
||||||
|
}).code;
|
||||||
|
} catch(e) {
|
||||||
|
parse_error = 1;
|
||||||
|
}
|
||||||
|
var beautify_result = run_code(beautify_code);
|
||||||
|
|
||||||
|
try {
|
||||||
|
var uglify_code = minify(beautify_code, {
|
||||||
|
fromString: true,
|
||||||
|
mangle: true,
|
||||||
|
compress: {
|
||||||
|
passes: 3,
|
||||||
|
},
|
||||||
|
output: {
|
||||||
|
//beautify: true,
|
||||||
|
//bracketize: true,
|
||||||
|
},
|
||||||
|
}).code;
|
||||||
|
} catch(e) {
|
||||||
|
parse_error = 2;
|
||||||
|
}
|
||||||
|
var uglify_result = run_code(uglify_code);
|
||||||
|
|
||||||
|
var ok = !parse_error && original_result == beautify_result && original_result == uglify_result;
|
||||||
|
if (verbose || (verbose_interval && !(round % INTERVAL_COUNT)) || !ok) log(ok);
|
||||||
|
if (parse_error === 1) console.log('Parse error while beautifying');
|
||||||
|
if (parse_error === 2) console.log('Parse error while uglifying');
|
||||||
|
if (!ok) break;
|
||||||
|
}
|
||||||
@@ -17,7 +17,3 @@ exports["string_template"] = string_template;
|
|||||||
exports["tokenizer"] = tokenizer;
|
exports["tokenizer"] = tokenizer;
|
||||||
exports["is_identifier"] = is_identifier;
|
exports["is_identifier"] = is_identifier;
|
||||||
exports["SymbolDef"] = SymbolDef;
|
exports["SymbolDef"] = SymbolDef;
|
||||||
|
|
||||||
if (typeof DEBUG !== "undefined" && DEBUG) {
|
|
||||||
exports["EXPECT_DIRECTIVE"] = EXPECT_DIRECTIVE;
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -7,7 +7,8 @@
|
|||||||
var path = require("path");
|
var path = require("path");
|
||||||
var fs = require("fs");
|
var fs = require("fs");
|
||||||
|
|
||||||
var FILES = exports.FILES = [
|
var UglifyJS = exports;
|
||||||
|
var FILES = UglifyJS.FILES = [
|
||||||
"../lib/utils.js",
|
"../lib/utils.js",
|
||||||
"../lib/ast.js",
|
"../lib/ast.js",
|
||||||
"../lib/parse.js",
|
"../lib/parse.js",
|
||||||
@@ -20,17 +21,14 @@ var FILES = exports.FILES = [
|
|||||||
"../lib/propmangle.js",
|
"../lib/propmangle.js",
|
||||||
"./exports.js",
|
"./exports.js",
|
||||||
].map(function(file){
|
].map(function(file){
|
||||||
return fs.realpathSync(path.join(path.dirname(__filename), file));
|
return require.resolve(file);
|
||||||
});
|
});
|
||||||
|
|
||||||
var UglifyJS = exports;
|
new Function("MOZ_SourceMap", "exports", FILES.map(function(file){
|
||||||
|
|
||||||
new Function("MOZ_SourceMap", "exports", "DEBUG", FILES.map(function(file){
|
|
||||||
return fs.readFileSync(file, "utf8");
|
return fs.readFileSync(file, "utf8");
|
||||||
}).join("\n\n"))(
|
}).join("\n\n"))(
|
||||||
require("source-map"),
|
require("source-map"),
|
||||||
UglifyJS,
|
UglifyJS
|
||||||
!!global.UGLIFY_DEBUG
|
|
||||||
);
|
);
|
||||||
|
|
||||||
UglifyJS.AST_Node.warn_function = function(txt) {
|
UglifyJS.AST_Node.warn_function = function(txt) {
|
||||||
@@ -46,7 +44,7 @@ function read_source_map(code) {
|
|||||||
return JSON.parse(new Buffer(match[2], "base64"));
|
return JSON.parse(new Buffer(match[2], "base64"));
|
||||||
}
|
}
|
||||||
|
|
||||||
exports.minify = function(files, options) {
|
UglifyJS.minify = function(files, options) {
|
||||||
options = UglifyJS.defaults(options, {
|
options = UglifyJS.defaults(options, {
|
||||||
spidermonkey : false,
|
spidermonkey : false,
|
||||||
outSourceMap : null,
|
outSourceMap : null,
|
||||||
@@ -181,7 +179,7 @@ exports.minify = function(files, options) {
|
|||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
// exports.describe_ast = function() {
|
// UglifyJS.describe_ast = function() {
|
||||||
// function doitem(ctor) {
|
// function doitem(ctor) {
|
||||||
// var sub = {};
|
// var sub = {};
|
||||||
// ctor.SUBCLASSES.forEach(function(ctor){
|
// ctor.SUBCLASSES.forEach(function(ctor){
|
||||||
@@ -195,7 +193,7 @@ exports.minify = function(files, options) {
|
|||||||
// return doitem(UglifyJS.AST_Node).sub;
|
// return doitem(UglifyJS.AST_Node).sub;
|
||||||
// }
|
// }
|
||||||
|
|
||||||
exports.describe_ast = function() {
|
UglifyJS.describe_ast = function() {
|
||||||
var out = UglifyJS.OutputStream({ beautify: true });
|
var out = UglifyJS.OutputStream({ beautify: true });
|
||||||
function doitem(ctor) {
|
function doitem(ctor) {
|
||||||
out.print("AST_" + ctor.TYPE);
|
out.print("AST_" + ctor.TYPE);
|
||||||
@@ -249,13 +247,13 @@ function readReservedFile(filename, reserved) {
|
|||||||
return reserved;
|
return reserved;
|
||||||
}
|
}
|
||||||
|
|
||||||
exports.readReservedFile = readReservedFile;
|
UglifyJS.readReservedFile = readReservedFile;
|
||||||
|
|
||||||
exports.readDefaultReservedFile = function(reserved) {
|
UglifyJS.readDefaultReservedFile = function(reserved) {
|
||||||
return readReservedFile(path.join(__dirname, "domprops.json"), reserved);
|
return readReservedFile(require.resolve("./domprops.json"), reserved);
|
||||||
};
|
};
|
||||||
|
|
||||||
exports.readNameCache = function(filename, key) {
|
UglifyJS.readNameCache = function(filename, key) {
|
||||||
var cache = null;
|
var cache = null;
|
||||||
if (filename) {
|
if (filename) {
|
||||||
try {
|
try {
|
||||||
@@ -273,7 +271,7 @@ exports.readNameCache = function(filename, key) {
|
|||||||
return cache;
|
return cache;
|
||||||
};
|
};
|
||||||
|
|
||||||
exports.writeNameCache = function(filename, key, cache) {
|
UglifyJS.writeNameCache = function(filename, key, cache) {
|
||||||
if (filename) {
|
if (filename) {
|
||||||
var data;
|
var data;
|
||||||
try {
|
try {
|
||||||
@@ -294,13 +292,9 @@ exports.writeNameCache = function(filename, key, cache) {
|
|||||||
// Example: "foo/bar/*baz??.*.js"
|
// Example: "foo/bar/*baz??.*.js"
|
||||||
// Argument `glob` may be a string or an array of strings.
|
// Argument `glob` may be a string or an array of strings.
|
||||||
// Returns an array of strings. Garbage in, garbage out.
|
// Returns an array of strings. Garbage in, garbage out.
|
||||||
exports.simple_glob = function simple_glob(glob) {
|
UglifyJS.simple_glob = function simple_glob(glob) {
|
||||||
var results = [];
|
|
||||||
if (Array.isArray(glob)) {
|
if (Array.isArray(glob)) {
|
||||||
glob.forEach(function(elem) {
|
return [].concat.apply([], glob.map(simple_glob));
|
||||||
results = results.concat(simple_glob(elem));
|
|
||||||
});
|
|
||||||
return results;
|
|
||||||
}
|
}
|
||||||
if (glob.match(/\*|\?/)) {
|
if (glob.match(/\*|\?/)) {
|
||||||
var dir = path.dirname(glob);
|
var dir = path.dirname(glob);
|
||||||
@@ -308,28 +302,19 @@ exports.simple_glob = function simple_glob(glob) {
|
|||||||
var entries = fs.readdirSync(dir);
|
var entries = fs.readdirSync(dir);
|
||||||
} catch (ex) {}
|
} catch (ex) {}
|
||||||
if (entries) {
|
if (entries) {
|
||||||
var pattern = "^" + (path.basename(glob)
|
var pattern = "^" + path.basename(glob)
|
||||||
.replace(/\(/g, "\\(")
|
.replace(/[.+^$[\]\\(){}]/g, "\\$&")
|
||||||
.replace(/\)/g, "\\)")
|
|
||||||
.replace(/\{/g, "\\{")
|
|
||||||
.replace(/\}/g, "\\}")
|
|
||||||
.replace(/\[/g, "\\[")
|
|
||||||
.replace(/\]/g, "\\]")
|
|
||||||
.replace(/\+/g, "\\+")
|
|
||||||
.replace(/\^/g, "\\^")
|
|
||||||
.replace(/\$/g, "\\$")
|
|
||||||
.replace(/\*/g, "[^/\\\\]*")
|
.replace(/\*/g, "[^/\\\\]*")
|
||||||
.replace(/\./g, "\\.")
|
.replace(/\?/g, "[^/\\\\]") + "$";
|
||||||
.replace(/\?/g, ".")) + "$";
|
|
||||||
var mod = process.platform === "win32" ? "i" : "";
|
var mod = process.platform === "win32" ? "i" : "";
|
||||||
var rx = new RegExp(pattern, mod);
|
var rx = new RegExp(pattern, mod);
|
||||||
for (var i in entries) {
|
var results = entries.filter(function(name) {
|
||||||
if (rx.test(entries[i]))
|
return rx.test(name);
|
||||||
results.push(dir + "/" + entries[i]);
|
}).map(function(name) {
|
||||||
}
|
return path.join(dir, name);
|
||||||
|
});
|
||||||
|
if (results.length) return results;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (results.length === 0)
|
return [ glob ];
|
||||||
results = [ glob ];
|
|
||||||
return results;
|
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user