Compare commits
156 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
fc7678c115 | ||
|
|
b371dc2d1e | ||
|
|
56e9454f1f | ||
|
|
d67daa8314 | ||
|
|
f0120e90b6 | ||
|
|
ec4558be29 | ||
|
|
685ab357cc | ||
|
|
5792f30175 | ||
|
|
24443b6764 | ||
|
|
154edf0427 | ||
|
|
4778cf88e2 | ||
|
|
38bd4f65d0 | ||
|
|
0b808f6428 | ||
|
|
b2bc2e1173 | ||
|
|
80787ff7ef | ||
|
|
b92a89f325 | ||
|
|
902292f776 | ||
|
|
3dcf098468 | ||
|
|
d89f0965aa | ||
|
|
c8d98f4787 | ||
|
|
0207b46d70 | ||
|
|
aa2a9fbedb | ||
|
|
3596b4feda | ||
|
|
51deeff72e | ||
|
|
4c227cc6bd | ||
|
|
2426657daa | ||
|
|
e1b03d0235 | ||
|
|
f1b3e9df1e | ||
|
|
fcc87edb71 | ||
|
|
8b464331ba | ||
|
|
9f57920566 | ||
|
|
933ca9ddd8 | ||
|
|
74e36e4456 | ||
|
|
4382bfe848 | ||
|
|
b6f250f5c9 | ||
|
|
5d69545299 | ||
|
|
139fad0c05 | ||
|
|
99946a3993 | ||
|
|
053cb27fe3 | ||
|
|
25017978e7 | ||
|
|
f749863cb2 | ||
|
|
123f9cf987 | ||
|
|
a758b40e3f | ||
|
|
44e5e99aae | ||
|
|
be53c4838b | ||
|
|
0c7b016fa7 | ||
|
|
00665766da | ||
|
|
88b4283200 | ||
|
|
d2bd0d1c1c | ||
|
|
25441d44f6 | ||
|
|
a025392a30 | ||
|
|
ad5f5ef2a3 | ||
|
|
40e669eacb | ||
|
|
ad3a331ca3 | ||
|
|
3c9e1693d5 | ||
|
|
8bc03dc6c4 | ||
|
|
2152f00de2 | ||
|
|
94aae05d45 | ||
|
|
0dbf2b1d3c | ||
|
|
59b23b8c13 | ||
|
|
5979b195fe | ||
|
|
a1cff23377 | ||
|
|
c82fc1ef71 | ||
|
|
740f93f5a9 | ||
|
|
d4caa97b88 | ||
|
|
c2ca7b7659 | ||
|
|
59edda6ca5 | ||
|
|
1668bc33c3 | ||
|
|
01f1e3fef8 | ||
|
|
27aa85f84b | ||
|
|
33c9c48318 | ||
|
|
63f16e4616 | ||
|
|
cb6dd34b98 | ||
|
|
27727e6926 | ||
|
|
a968ddc78c | ||
|
|
f70462aeb2 | ||
|
|
3aa92c76cc | ||
|
|
fc6a66836a | ||
|
|
31167da1a9 | ||
|
|
7db2ada880 | ||
|
|
e31bbe329a | ||
|
|
8946c87011 | ||
|
|
a9ef659bcb | ||
|
|
35c2149dbd | ||
|
|
89a35f9fcd | ||
|
|
1a4e99dc2d | ||
|
|
cb870f6fd6 | ||
|
|
a0c0c294c5 | ||
|
|
fbdb7eeda3 | ||
|
|
1bc0fccc8c | ||
|
|
20252c6483 | ||
|
|
e396912ea2 | ||
|
|
5ebfa78f56 | ||
|
|
950609f578 | ||
|
|
4a44d95f09 | ||
|
|
36718948be | ||
|
|
21bd4c4a9d | ||
|
|
998c9792da | ||
|
|
ccd77d70db | ||
|
|
d75a946707 | ||
|
|
696a20f10d | ||
|
|
224c91b6c1 | ||
|
|
8065e27a7d | ||
|
|
584e253f33 | ||
|
|
fb5e08e4ec | ||
|
|
e3d328f741 | ||
|
|
8922f08fbf | ||
|
|
15a4074d1a | ||
|
|
c624b43739 | ||
|
|
a8e040b133 | ||
|
|
5e30f3a48b | ||
|
|
46570a4eb6 | ||
|
|
01b84074d7 | ||
|
|
7aba2dc5f2 | ||
|
|
12a6728c4e | ||
|
|
042c228c7b | ||
|
|
e2b00814a8 | ||
|
|
104d385ba9 | ||
|
|
fdbbef2991 | ||
|
|
f8edf05c3c | ||
|
|
a9d0ddea9d | ||
|
|
313e4974a4 | ||
|
|
dd3b81dec6 | ||
|
|
d5afe16bc8 | ||
|
|
212ce4608e | ||
|
|
fbc5ecf75a | ||
|
|
a7d06167a0 | ||
|
|
9686379884 | ||
|
|
82e8ebd77d | ||
|
|
0b50880b4f | ||
|
|
316245ee12 | ||
|
|
63b92ead4e | ||
|
|
a14555a39e | ||
|
|
6d0bb58d68 | ||
|
|
33c163f648 | ||
|
|
b6c72c84d4 | ||
|
|
327e94a759 | ||
|
|
6fb7de7787 | ||
|
|
d338e45033 | ||
|
|
b106cd9476 | ||
|
|
9a91a7a4dc | ||
|
|
fa30960b8b | ||
|
|
8ceb4b0492 | ||
|
|
aad5d6e122 | ||
|
|
77552d9e69 | ||
|
|
93105f1a6d | ||
|
|
d7eb80b050 | ||
|
|
0a5a1f3687 | ||
|
|
e7d6dd2ea2 | ||
|
|
28943bcebb | ||
|
|
18f00457f6 | ||
|
|
e4a91a89e0 | ||
|
|
3693bde2dd | ||
|
|
67438f3ff9 | ||
|
|
371d25944d | ||
|
|
5c863b74d7 |
6
.github/workflows/ufuzz.yml
vendored
6
.github/workflows/ufuzz.yml
vendored
@@ -17,13 +17,13 @@ jobs:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
include:
|
||||
- node: latest
|
||||
- node: '16'
|
||||
os: macos-latest
|
||||
- node: '8'
|
||||
- node: '12'
|
||||
os: ubuntu-latest
|
||||
- node: '8'
|
||||
os: ubuntu-latest
|
||||
- node: '8'
|
||||
- node: '12'
|
||||
os: windows-latest
|
||||
- node: '8'
|
||||
os: windows-latest
|
||||
|
||||
101
README.md
101
README.md
@@ -118,6 +118,7 @@ a double dash to prevent input files being used as option arguments:
|
||||
--keep-fargs Do not mangle/drop function arguments.
|
||||
--keep-fnames Do not mangle/drop function names. Useful for
|
||||
code relying on Function.prototype.name.
|
||||
--module Process input as ES module (implies --toplevel)
|
||||
--name-cache <file> File to hold mangled name mappings.
|
||||
--self Build UglifyJS as a library (implies --wrap UglifyJS)
|
||||
--source-map [options] Enable source map/specify source map options:
|
||||
@@ -146,7 +147,7 @@ a double dash to prevent input files being used as option arguments:
|
||||
--warn Print warning messages.
|
||||
--webkit Support non-standard Safari/Webkit.
|
||||
Equivalent to setting `webkit: true` in `minify()`
|
||||
for `mangle` and `output` options.
|
||||
for `compress`, `mangle` and `output` options.
|
||||
By default UglifyJS will not try to be Safari-proof.
|
||||
--wrap <name> Embed everything in a big function, making the
|
||||
“exports” and “global” variables available. You
|
||||
@@ -517,6 +518,10 @@ if (result.error) throw result.error;
|
||||
- `mangle.properties` (default: `false`) — a subcategory of the mangle option.
|
||||
Pass an object to specify custom [mangle property options](#mangle-properties-options).
|
||||
|
||||
- `module` (default: `false`) — set to `true` if you wish to process input as
|
||||
ES module, i.e. implicit `"use strict";` and support for top-level `await`,
|
||||
alongside with `toplevel` enabled.
|
||||
|
||||
- `nameCache` (default: `null`) — pass an empty object `{}` or a previously
|
||||
used `nameCache` object if you wish to cache mangled variable and
|
||||
property names across multiple invocations of `minify()`. Note: this is
|
||||
@@ -628,7 +633,13 @@ to be `false` and all symbol names will be omitted.
|
||||
|
||||
- `bare_returns` (default: `false`) — support top level `return` statements
|
||||
|
||||
- `html5_comments` (default: `true`)
|
||||
- `expression` (default: `false`) — parse as a single expression, e.g. JSON
|
||||
|
||||
- `html5_comments` (default: `true`) — process HTML comment as workaround for
|
||||
browsers which do not recognise `<script>` tags
|
||||
|
||||
- `module` (default: `false`) — set to `true` if you wish to process input as
|
||||
ES module, i.e. implicit `"use strict";` and support for top-level `await`.
|
||||
|
||||
- `shebang` (default: `true`) — support `#!command` as the first line
|
||||
|
||||
@@ -728,6 +739,9 @@ to be `false` and all symbol names will be omitted.
|
||||
|
||||
- `merge_vars` (default: `true`) — combine and reuse variables.
|
||||
|
||||
- `module` (default: `false`) — set to `true` if you wish to process input as
|
||||
ES module, i.e. implicit `"use strict";` alongside with `toplevel` enabled.
|
||||
|
||||
- `negate_iife` (default: `true`) — negate "Immediately-Called Function Expressions"
|
||||
where the return value is discarded, to avoid the parens that the
|
||||
code generator would insert.
|
||||
@@ -804,8 +818,9 @@ to be `false` and all symbol names will be omitted.
|
||||
|
||||
- `unsafe` (default: `false`) — apply "unsafe" transformations (discussion below)
|
||||
|
||||
- `unsafe_comps` (default: `false`) — compress expressions like `a <= b` assuming
|
||||
none of the operands can be (coerced to) `NaN`.
|
||||
- `unsafe_comps` (default: `false`) — assume operands cannot be (coerced to) `NaN`
|
||||
in numeric comparisons, e.g. `a <= b`. In addition, expressions involving `in`
|
||||
or `instanceof` would never throw.
|
||||
|
||||
- `unsafe_Function` (default: `false`) — compress and mangle `Function(args, code)`
|
||||
when both `args` and `code` are string literals.
|
||||
@@ -917,9 +932,11 @@ can pass additional arguments that control the code output:
|
||||
|
||||
- `galio` (default: `false`) — enable workarounds for ANT Galio bugs
|
||||
|
||||
- `indent_level` (default: `4`)
|
||||
- `indent_level` (default: `4`) — indent by specified number of spaces or the
|
||||
exact whitespace sequence supplied, e.g. `"\t"`.
|
||||
|
||||
- `indent_start` (default: `0`) — prefix all lines by that many spaces
|
||||
- `indent_start` (default: `0`) — prefix all lines by whitespace sequence
|
||||
specified in the same format as `indent_level`.
|
||||
|
||||
- `inline_script` (default: `true`) — escape HTML comments and the slash in
|
||||
occurrences of `</script>` in strings
|
||||
@@ -1329,10 +1346,8 @@ To allow for better optimizations, the compiler makes various assumptions:
|
||||
- Later versions of JavaScript will throw `SyntaxError` with the following:
|
||||
```javascript
|
||||
var await;
|
||||
async function f() {
|
||||
class A {
|
||||
static p = await;
|
||||
}
|
||||
class A {
|
||||
static p = await;
|
||||
}
|
||||
// SyntaxError: Unexpected reserved word
|
||||
```
|
||||
@@ -1344,7 +1359,7 @@ To allow for better optimizations, the compiler makes various assumptions:
|
||||
// SyntaxError: The left-hand side of a for-of loop may not be 'async'.
|
||||
```
|
||||
UglifyJS may modify the input which in turn may suppress those errors.
|
||||
- Later versions of Chrome and Node.js will give incorrect results with the
|
||||
- Some versions of Chrome and Node.js will give incorrect results with the
|
||||
following:
|
||||
```javascript
|
||||
console.log({
|
||||
@@ -1353,9 +1368,15 @@ To allow for better optimizations, the compiler makes various assumptions:
|
||||
return "FAIL";
|
||||
},
|
||||
[42]: "PASS",
|
||||
}[42], {
|
||||
...console,
|
||||
get 42() {
|
||||
return "FAIL";
|
||||
},
|
||||
42: "PASS",
|
||||
}[42]);
|
||||
// Expected: "PASS"
|
||||
// Actual: "FAIL"
|
||||
// Expected: "PASS PASS"
|
||||
// Actual: "PASS FAIL"
|
||||
```
|
||||
UglifyJS may modify the input which in turn may suppress those errors.
|
||||
- Earlier versions of JavaScript will throw `TypeError` with the following:
|
||||
@@ -1371,3 +1392,57 @@ To allow for better optimizations, the compiler makes various assumptions:
|
||||
// TypeError: const 'a' has already been declared
|
||||
```
|
||||
UglifyJS may modify the input which in turn may suppress those errors.
|
||||
- Later versions of Chrome and Node.js will give incorrect results with the
|
||||
following:
|
||||
```javascript
|
||||
try {
|
||||
class A {
|
||||
static 42;
|
||||
static get 42() {}
|
||||
}
|
||||
console.log("PASS");
|
||||
} catch (e) {
|
||||
console.log("FAIL");
|
||||
}
|
||||
// Expected: "PASS"
|
||||
// Actual: "FAIL"
|
||||
```
|
||||
UglifyJS may modify the input which in turn may suppress those errors.
|
||||
- Some versions of Chrome and Node.js will give incorrect results with the
|
||||
following:
|
||||
```javascript
|
||||
(async function(a) {
|
||||
(function() {
|
||||
var b = await => console.log("PASS");
|
||||
b();
|
||||
})();
|
||||
})().catch(console.error);
|
||||
// Expected: "PASS"
|
||||
// Actual: SyntaxError: Unexpected reserved word
|
||||
```
|
||||
UglifyJS may modify the input which in turn may suppress those errors.
|
||||
- Later versions of Chrome and Node.js will give incorrect results with the
|
||||
following:
|
||||
```javascript
|
||||
try {
|
||||
f();
|
||||
function f() {
|
||||
throw 42;
|
||||
}
|
||||
} catch (e) {
|
||||
console.log(typeof f, e);
|
||||
}
|
||||
// Expected: "function 42"
|
||||
// Actual: "undefined 42"
|
||||
```
|
||||
UglifyJS may modify the input which in turn may suppress those errors.
|
||||
- Later versions of JavaScript will throw `SyntaxError` with the following:
|
||||
```javascript
|
||||
"use strict";
|
||||
console.log(function f() {
|
||||
return f = "PASS";
|
||||
}());
|
||||
// Expected: "PASS"
|
||||
// Actual: TypeError: invalid assignment to const 'f'
|
||||
```
|
||||
UglifyJS may modify the input which in turn may suppress those errors.
|
||||
|
||||
@@ -107,6 +107,7 @@ function process_option(name, no_value) {
|
||||
" --ie Support non-standard Internet Explorer.",
|
||||
" --keep-fargs Do not mangle/drop function arguments.",
|
||||
" --keep-fnames Do not mangle/drop function names. Useful for code relying on Function.prototype.name.",
|
||||
" --module Process input as ES module (implies --toplevel)",
|
||||
" --name-cache <file> File to hold mangled name mappings.",
|
||||
" --rename Force symbol expansion.",
|
||||
" --no-rename Disable symbol expansion.",
|
||||
@@ -152,6 +153,7 @@ function process_option(name, no_value) {
|
||||
case "annotations":
|
||||
case "ie":
|
||||
case "ie8":
|
||||
case "module":
|
||||
case "timings":
|
||||
case "toplevel":
|
||||
case "v8":
|
||||
|
||||
365
lib/ast.js
365
lib/ast.js
@@ -109,6 +109,9 @@ var AST_Node = DEFNODE("Node", "start end", {
|
||||
start: "[AST_Token] The first token of this node",
|
||||
end: "[AST_Token] The last token of this node"
|
||||
},
|
||||
equals: function(node) {
|
||||
return this.TYPE == node.TYPE && this._equals(node);
|
||||
},
|
||||
walk: function(visitor) {
|
||||
visitor.visit(this);
|
||||
},
|
||||
@@ -138,6 +141,7 @@ var AST_Node = DEFNODE("Node", "start end", {
|
||||
}, null);
|
||||
|
||||
DEF_BITPROPS(AST_Node, [
|
||||
// AST_Node
|
||||
"_optimized",
|
||||
"_squeezed",
|
||||
// AST_Call
|
||||
@@ -172,6 +176,8 @@ DEF_BITPROPS(AST_Node, [
|
||||
"pure",
|
||||
// AST_Assign
|
||||
"redundant",
|
||||
// AST_Node
|
||||
"single_use",
|
||||
// AST_ClassProperty
|
||||
"static",
|
||||
// AST_Call
|
||||
@@ -231,6 +237,24 @@ AST_Node.disable_validation = function() {
|
||||
while (restore = restore_transforms.pop()) restore();
|
||||
};
|
||||
|
||||
function all_equals(k, l) {
|
||||
return k.length == l.length && all(k, function(m, i) {
|
||||
return m.equals(l[i]);
|
||||
});
|
||||
}
|
||||
|
||||
function list_equals(s, t) {
|
||||
return s.length == t.length && all(s, function(u, i) {
|
||||
return u == t[i];
|
||||
});
|
||||
}
|
||||
|
||||
function prop_equals(u, v) {
|
||||
if (u === v) return true;
|
||||
if (u == null) return v == null;
|
||||
return u instanceof AST_Node && v instanceof AST_Node && u.equals(v);
|
||||
}
|
||||
|
||||
/* -----[ statements ]----- */
|
||||
|
||||
var AST_Statement = DEFNODE("Statement", null, {
|
||||
@@ -242,6 +266,7 @@ var AST_Statement = DEFNODE("Statement", null, {
|
||||
|
||||
var AST_Debugger = DEFNODE("Debugger", null, {
|
||||
$documentation: "Represents a debugger statement",
|
||||
_equals: return_true,
|
||||
}, AST_Statement);
|
||||
|
||||
var AST_Directive = DEFNODE("Directive", "quote value", {
|
||||
@@ -250,6 +275,9 @@ var AST_Directive = DEFNODE("Directive", "quote value", {
|
||||
quote: "[string?] the original quote character",
|
||||
value: "[string] The value of this directive as a plain string (it's not an AST_String!)",
|
||||
},
|
||||
_equals: function(node) {
|
||||
return this.value == node.value;
|
||||
},
|
||||
_validate: function() {
|
||||
if (this.quote != null) {
|
||||
if (typeof this.quote != "string") throw new Error("quote must be string");
|
||||
@@ -260,7 +288,8 @@ var AST_Directive = DEFNODE("Directive", "quote value", {
|
||||
}, AST_Statement);
|
||||
|
||||
var AST_EmptyStatement = DEFNODE("EmptyStatement", null, {
|
||||
$documentation: "The empty statement (empty block or simply a semicolon)"
|
||||
$documentation: "The empty statement (empty block or simply a semicolon)",
|
||||
_equals: return_true,
|
||||
}, AST_Statement);
|
||||
|
||||
function is_statement(node) {
|
||||
@@ -291,6 +320,9 @@ var AST_SimpleStatement = DEFNODE("SimpleStatement", "body", {
|
||||
$propdoc: {
|
||||
body: "[AST_Node] an expression node (should not be instanceof AST_Statement)",
|
||||
},
|
||||
_equals: function(node) {
|
||||
return this.body.equals(node.body);
|
||||
},
|
||||
walk: function(visitor) {
|
||||
var node = this;
|
||||
visitor.visit(node, function() {
|
||||
@@ -342,6 +374,9 @@ var AST_Block = DEFNODE("Block", "body", {
|
||||
$propdoc: {
|
||||
body: "[AST_Statement*] an array of statements"
|
||||
},
|
||||
_equals: function(node) {
|
||||
return all_equals(this.body, node.body);
|
||||
},
|
||||
walk: function(visitor) {
|
||||
var node = this;
|
||||
visitor.visit(node, function() {
|
||||
@@ -376,6 +411,10 @@ var AST_LabeledStatement = DEFNODE("LabeledStatement", "label", {
|
||||
$propdoc: {
|
||||
label: "[AST_Label] a label definition"
|
||||
},
|
||||
_equals: function(node) {
|
||||
return this.label.equals(node.label)
|
||||
&& this.body.equals(node.body);
|
||||
},
|
||||
walk: function(visitor) {
|
||||
var node = this;
|
||||
visitor.visit(node, function() {
|
||||
@@ -417,6 +456,10 @@ var AST_DWLoop = DEFNODE("DWLoop", "condition", {
|
||||
$propdoc: {
|
||||
condition: "[AST_Node] the loop condition. Should not be instanceof AST_Statement"
|
||||
},
|
||||
_equals: function(node) {
|
||||
return this.body.equals(node.body)
|
||||
&& this.condition.equals(node.condition);
|
||||
},
|
||||
_validate: function() {
|
||||
if (this.TYPE == "DWLoop") throw new Error("should not instantiate AST_DWLoop");
|
||||
must_be_expression(this, "condition");
|
||||
@@ -431,7 +474,7 @@ var AST_Do = DEFNODE("Do", null, {
|
||||
node.body.walk(visitor);
|
||||
node.condition.walk(visitor);
|
||||
});
|
||||
}
|
||||
},
|
||||
}, AST_DWLoop);
|
||||
|
||||
var AST_While = DEFNODE("While", null, {
|
||||
@@ -442,7 +485,7 @@ var AST_While = DEFNODE("While", null, {
|
||||
node.condition.walk(visitor);
|
||||
node.body.walk(visitor);
|
||||
});
|
||||
}
|
||||
},
|
||||
}, AST_DWLoop);
|
||||
|
||||
var AST_For = DEFNODE("For", "init condition step", {
|
||||
@@ -452,6 +495,12 @@ var AST_For = DEFNODE("For", "init condition step", {
|
||||
condition: "[AST_Node?] the `for` termination clause, or null if empty",
|
||||
step: "[AST_Node?] the `for` update clause, or null if empty"
|
||||
},
|
||||
_equals: function(node) {
|
||||
return prop_equals(this.init, node.init)
|
||||
&& prop_equals(this.condition, node.condition)
|
||||
&& prop_equals(this.step, node.step)
|
||||
&& this.body.equals(node.body);
|
||||
},
|
||||
walk: function(visitor) {
|
||||
var node = this;
|
||||
visitor.visit(node, function() {
|
||||
@@ -479,6 +528,11 @@ var AST_ForEnumeration = DEFNODE("ForEnumeration", "init object", {
|
||||
init: "[AST_Node] the assignment target during iteration",
|
||||
object: "[AST_Node] the object to iterate over"
|
||||
},
|
||||
_equals: function(node) {
|
||||
return this.init.equals(node.init)
|
||||
&& this.object.equals(node.object)
|
||||
&& this.body.equals(node.body);
|
||||
},
|
||||
walk: function(visitor) {
|
||||
var node = this;
|
||||
visitor.visit(node, function() {
|
||||
@@ -519,6 +573,10 @@ var AST_With = DEFNODE("With", "expression", {
|
||||
$propdoc: {
|
||||
expression: "[AST_Node] the `with` expression"
|
||||
},
|
||||
_equals: function(node) {
|
||||
return this.expression.equals(node.expression)
|
||||
&& this.body.equals(node.body);
|
||||
},
|
||||
walk: function(visitor) {
|
||||
var node = this;
|
||||
visitor.visit(node, function() {
|
||||
@@ -534,7 +592,7 @@ var AST_With = DEFNODE("With", "expression", {
|
||||
/* -----[ scope and functions ]----- */
|
||||
|
||||
var AST_Scope = DEFNODE("Scope", "fn_defs may_call_this uses_eval uses_with", {
|
||||
$documentation: "Base class for all statements introducing a lexical scope",
|
||||
$documentation: "Base class for all statements introducing a lambda scope",
|
||||
$propdoc: {
|
||||
uses_eval: "[boolean/S] tells whether this scope contains a direct call to the global `eval`",
|
||||
uses_with: "[boolean/S] tells whether this scope uses the `with` statement",
|
||||
@@ -592,6 +650,10 @@ var AST_Toplevel = DEFNODE("Toplevel", "globals", {
|
||||
}
|
||||
}, AST_Scope);
|
||||
|
||||
var AST_ClassInitBlock = DEFNODE("ClassInitBlock", null, {
|
||||
$documentation: "Value for `class` static initialization blocks",
|
||||
}, AST_Scope);
|
||||
|
||||
var AST_Lambda = DEFNODE("Lambda", "argnames length_read rest safe_ids uses_arguments", {
|
||||
$documentation: "Base class for functions",
|
||||
$propdoc: {
|
||||
@@ -617,6 +679,13 @@ var AST_Lambda = DEFNODE("Lambda", "argnames length_read rest safe_ids uses_argu
|
||||
});
|
||||
if (this.rest) this.rest.walk(tw);
|
||||
},
|
||||
_equals: function(node) {
|
||||
return prop_equals(this.rest, node.rest)
|
||||
&& prop_equals(this.name, node.name)
|
||||
&& prop_equals(this.value, node.value)
|
||||
&& all_equals(this.argnames, node.argnames)
|
||||
&& all_equals(this.body, node.body);
|
||||
},
|
||||
walk: function(visitor) {
|
||||
var node = this;
|
||||
visitor.visit(node, function() {
|
||||
@@ -827,6 +896,14 @@ var AST_Class = DEFNODE("Class", "extends name properties", {
|
||||
extends: "[AST_Node?] the super class, or null if not specified",
|
||||
properties: "[AST_ClassProperty*] array of class properties",
|
||||
},
|
||||
_equals: function(node) {
|
||||
return prop_equals(this.name, node.name)
|
||||
&& prop_equals(this.extends, node.extends)
|
||||
&& all_equals(this.properties, node.properties);
|
||||
},
|
||||
resolve: function(def_class) {
|
||||
return def_class ? this : this.parent_scope.resolve();
|
||||
},
|
||||
walk: function(visitor) {
|
||||
var node = this;
|
||||
visitor.visit(node, function() {
|
||||
@@ -871,11 +948,17 @@ var AST_ClassExpression = DEFNODE("ClassExpression", null, {
|
||||
var AST_ClassProperty = DEFNODE("ClassProperty", "key private static value", {
|
||||
$documentation: "Base class for `class` properties",
|
||||
$propdoc: {
|
||||
key: "[string|AST_Node] property name (AST_Node for computed property)",
|
||||
key: "[string|AST_Node?] property name (AST_Node for computed property, null for initialization block)",
|
||||
private: "[boolean] whether this is a private property",
|
||||
static: "[boolean] whether this is a static property",
|
||||
value: "[AST_Node?] property value (AST_Accessor for getters/setters, AST_LambdaExpression for methods, null if not specified for fields)",
|
||||
},
|
||||
_equals: function(node) {
|
||||
return !this.private == !node.private
|
||||
&& !this.static == !node.static
|
||||
&& prop_equals(this.key, node.key)
|
||||
&& prop_equals(this.value, node.value);
|
||||
},
|
||||
walk: function(visitor) {
|
||||
var node = this;
|
||||
visitor.visit(node, function() {
|
||||
@@ -885,7 +968,9 @@ var AST_ClassProperty = DEFNODE("ClassProperty", "key private static value", {
|
||||
},
|
||||
_validate: function() {
|
||||
if (this.TYPE == "ClassProperty") throw new Error("should not instantiate AST_ClassProperty");
|
||||
if (typeof this.key != "string") {
|
||||
if (this instanceof AST_ClassInit) {
|
||||
if (this.key != null) throw new Error("key must be null");
|
||||
} else if (typeof this.key != "string") {
|
||||
if (!(this.key instanceof AST_Node)) throw new Error("key must be string or AST_Node");
|
||||
must_be_expression(this, "key");
|
||||
}
|
||||
@@ -925,6 +1010,17 @@ var AST_ClassMethod = DEFNODE("ClassMethod", null, {
|
||||
},
|
||||
}, AST_ClassProperty);
|
||||
|
||||
var AST_ClassInit = DEFNODE("ClassInit", null, {
|
||||
$documentation: "A `class` static initialization block",
|
||||
_validate: function() {
|
||||
if (!this.static) throw new Error("static must be true");
|
||||
if (!(this.value instanceof AST_ClassInitBlock)) throw new Error("value must be AST_ClassInitBlock");
|
||||
},
|
||||
initialize: function() {
|
||||
this.static = true;
|
||||
},
|
||||
}, AST_ClassProperty);
|
||||
|
||||
/* -----[ JUMPS ]----- */
|
||||
|
||||
var AST_Jump = DEFNODE("Jump", null, {
|
||||
@@ -939,6 +1035,9 @@ var AST_Exit = DEFNODE("Exit", "value", {
|
||||
$propdoc: {
|
||||
value: "[AST_Node?] the value returned or thrown by this statement; could be null for AST_Return"
|
||||
},
|
||||
_equals: function(node) {
|
||||
return prop_equals(this.value, node.value);
|
||||
},
|
||||
walk: function(visitor) {
|
||||
var node = this;
|
||||
visitor.visit(node, function() {
|
||||
@@ -969,6 +1068,9 @@ var AST_LoopControl = DEFNODE("LoopControl", "label", {
|
||||
$propdoc: {
|
||||
label: "[AST_LabelRef?] the label, or null if none",
|
||||
},
|
||||
_equals: function(node) {
|
||||
return prop_equals(this.label, node.label);
|
||||
},
|
||||
walk: function(visitor) {
|
||||
var node = this;
|
||||
visitor.visit(node, function() {
|
||||
@@ -999,6 +1101,11 @@ var AST_If = DEFNODE("If", "condition alternative", {
|
||||
condition: "[AST_Node] the `if` condition",
|
||||
alternative: "[AST_Statement?] the `else` part, or null if not present"
|
||||
},
|
||||
_equals: function(node) {
|
||||
return this.body.equals(node.body)
|
||||
&& this.condition.equals(node.condition)
|
||||
&& prop_equals(this.alternative, node.alternative);
|
||||
},
|
||||
walk: function(visitor) {
|
||||
var node = this;
|
||||
visitor.visit(node, function() {
|
||||
@@ -1022,6 +1129,10 @@ var AST_Switch = DEFNODE("Switch", "expression", {
|
||||
$propdoc: {
|
||||
expression: "[AST_Node] the `switch` “discriminant”"
|
||||
},
|
||||
_equals: function(node) {
|
||||
return this.expression.equals(node.expression)
|
||||
&& all_equals(this.body, node.body);
|
||||
},
|
||||
walk: function(visitor) {
|
||||
var node = this;
|
||||
visitor.visit(node, function() {
|
||||
@@ -1053,6 +1164,10 @@ var AST_Case = DEFNODE("Case", "expression", {
|
||||
$propdoc: {
|
||||
expression: "[AST_Node] the `case` expression"
|
||||
},
|
||||
_equals: function(node) {
|
||||
return this.expression.equals(node.expression)
|
||||
&& all_equals(this.body, node.body);
|
||||
},
|
||||
walk: function(visitor) {
|
||||
var node = this;
|
||||
visitor.visit(node, function() {
|
||||
@@ -1073,6 +1188,11 @@ var AST_Try = DEFNODE("Try", "bcatch bfinally", {
|
||||
bcatch: "[AST_Catch?] the catch block, or null if not present",
|
||||
bfinally: "[AST_Finally?] the finally block, or null if not present"
|
||||
},
|
||||
_equals: function(node) {
|
||||
return all_equals(this.body, node.body)
|
||||
&& prop_equals(this.bcatch, node.bcatch)
|
||||
&& prop_equals(this.bfinally, node.bfinally);
|
||||
},
|
||||
walk: function(visitor) {
|
||||
var node = this;
|
||||
visitor.visit(node, function() {
|
||||
@@ -1096,6 +1216,10 @@ var AST_Catch = DEFNODE("Catch", "argname", {
|
||||
$propdoc: {
|
||||
argname: "[(AST_Destructured|AST_SymbolCatch)?] symbol for the exception, or null if not present",
|
||||
},
|
||||
_equals: function(node) {
|
||||
return prop_equals(this.argname, node.argname)
|
||||
&& all_equals(this.body, node.body);
|
||||
},
|
||||
walk: function(visitor) {
|
||||
var node = this;
|
||||
visitor.visit(node, function() {
|
||||
@@ -1121,6 +1245,9 @@ var AST_Definitions = DEFNODE("Definitions", "definitions", {
|
||||
$propdoc: {
|
||||
definitions: "[AST_VarDef*] array of variable definitions"
|
||||
},
|
||||
_equals: function(node) {
|
||||
return all_equals(this.definitions, node.definitions);
|
||||
},
|
||||
walk: function(visitor) {
|
||||
var node = this;
|
||||
visitor.visit(node, function() {
|
||||
@@ -1177,6 +1304,10 @@ var AST_VarDef = DEFNODE("VarDef", "name value", {
|
||||
name: "[AST_Destructured|AST_SymbolVar] name of the variable",
|
||||
value: "[AST_Node?] initializer, or null of there's no initializer",
|
||||
},
|
||||
_equals: function(node) {
|
||||
return this.name.equals(node.name)
|
||||
&& prop_equals(this.value, node.value);
|
||||
},
|
||||
walk: function(visitor) {
|
||||
var node = this;
|
||||
visitor.visit(node, function() {
|
||||
@@ -1196,6 +1327,9 @@ var AST_ExportDeclaration = DEFNODE("ExportDeclaration", "body", {
|
||||
$propdoc: {
|
||||
body: "[AST_DefClass|AST_Definitions|AST_LambdaDefinition] the statement to export",
|
||||
},
|
||||
_equals: function(node) {
|
||||
return this.body.equals(node.body);
|
||||
},
|
||||
walk: function(visitor) {
|
||||
var node = this;
|
||||
visitor.visit(node, function() {
|
||||
@@ -1216,6 +1350,9 @@ var AST_ExportDefault = DEFNODE("ExportDefault", "body", {
|
||||
$propdoc: {
|
||||
body: "[AST_Node] the default export",
|
||||
},
|
||||
_equals: function(node) {
|
||||
return this.body.equals(node.body);
|
||||
},
|
||||
walk: function(visitor) {
|
||||
var node = this;
|
||||
visitor.visit(node, function() {
|
||||
@@ -1229,29 +1366,29 @@ var AST_ExportDefault = DEFNODE("ExportDefault", "body", {
|
||||
},
|
||||
}, AST_Statement);
|
||||
|
||||
var AST_ExportForeign = DEFNODE("ExportForeign", "aliases keys path quote", {
|
||||
var AST_ExportForeign = DEFNODE("ExportForeign", "aliases keys path", {
|
||||
$documentation: "An `export ... from '...'` statement",
|
||||
$propdoc: {
|
||||
aliases: "[string*] array of aliases to export",
|
||||
keys: "[string*] array of keys to import",
|
||||
path: "[string] the path to import module",
|
||||
quote: "[string?] the original quote character",
|
||||
aliases: "[AST_String*] array of aliases to export",
|
||||
keys: "[AST_String*] array of keys to import",
|
||||
path: "[AST_String] the path to import module",
|
||||
},
|
||||
_equals: function(node) {
|
||||
return this.path.equals(node.path)
|
||||
&& all_equals(this.aliases, node.aliases)
|
||||
&& all_equals(this.keys, node.keys);
|
||||
},
|
||||
_validate: function() {
|
||||
if (this.aliases.length != this.keys.length) {
|
||||
throw new Error("aliases:key length mismatch: " + this.aliases.length + " != " + this.keys.length);
|
||||
}
|
||||
this.aliases.forEach(function(name) {
|
||||
if (typeof name != "string") throw new Error("aliases must contain string");
|
||||
if (!(name instanceof AST_String)) throw new Error("aliases must contain AST_String");
|
||||
});
|
||||
this.keys.forEach(function(name) {
|
||||
if (typeof name != "string") throw new Error("keys must contain string");
|
||||
if (!(name instanceof AST_String)) throw new Error("keys must contain AST_String");
|
||||
});
|
||||
if (typeof this.path != "string") throw new Error("path must be string");
|
||||
if (this.quote != null) {
|
||||
if (typeof this.quote != "string") throw new Error("quote must be string");
|
||||
if (!/^["']$/.test(this.quote)) throw new Error("invalid quote: " + this.quote);
|
||||
}
|
||||
if (!(this.path instanceof AST_String)) throw new Error("path must be AST_String");
|
||||
},
|
||||
}, AST_Statement);
|
||||
|
||||
@@ -1260,6 +1397,9 @@ var AST_ExportReferences = DEFNODE("ExportReferences", "properties", {
|
||||
$propdoc: {
|
||||
properties: "[AST_SymbolExport*] array of aliases to export",
|
||||
},
|
||||
_equals: function(node) {
|
||||
return all_equals(this.properties, node.properties);
|
||||
},
|
||||
walk: function(visitor) {
|
||||
var node = this;
|
||||
visitor.visit(node, function() {
|
||||
@@ -1275,14 +1415,20 @@ var AST_ExportReferences = DEFNODE("ExportReferences", "properties", {
|
||||
},
|
||||
}, AST_Statement);
|
||||
|
||||
var AST_Import = DEFNODE("Import", "all default path properties quote", {
|
||||
var AST_Import = DEFNODE("Import", "all default path properties", {
|
||||
$documentation: "An `import` statement",
|
||||
$propdoc: {
|
||||
all: "[AST_SymbolImport?] the imported namespace, or null if not specified",
|
||||
default: "[AST_SymbolImport?] the alias for default `export`, or null if not specified",
|
||||
path: "[string] the path to import module",
|
||||
path: "[AST_String] the path to import module",
|
||||
properties: "[(AST_SymbolImport*)?] array of aliases, or null if not specified",
|
||||
quote: "[string?] the original quote character",
|
||||
},
|
||||
_equals: function(node) {
|
||||
return this.path.equals(node.path)
|
||||
&& prop_equals(this.all, node.all)
|
||||
&& prop_equals(this.default, node.default)
|
||||
&& !this.properties == !node.properties
|
||||
&& (!this.properties || all_equals(this.properties, node.properties));
|
||||
},
|
||||
walk: function(visitor) {
|
||||
var node = this;
|
||||
@@ -1301,16 +1447,12 @@ var AST_Import = DEFNODE("Import", "all default path properties quote", {
|
||||
}
|
||||
if (this.default != null) {
|
||||
if (!(this.default instanceof AST_SymbolImport)) throw new Error("default must be AST_SymbolImport");
|
||||
if (this.default.key !== "") throw new Error("invalid default key: " + this.default.key);
|
||||
if (this.default.key.value !== "") throw new Error("invalid default key: " + this.default.key.value);
|
||||
}
|
||||
if (typeof this.path != "string") throw new Error("path must be string");
|
||||
if (!(this.path instanceof AST_String)) throw new Error("path must be AST_String");
|
||||
if (this.properties != null) this.properties.forEach(function(node) {
|
||||
if (!(node instanceof AST_SymbolImport)) throw new Error("properties must contain AST_SymbolImport");
|
||||
});
|
||||
if (this.quote != null) {
|
||||
if (typeof this.quote != "string") throw new Error("quote must be string");
|
||||
if (!/^["']$/.test(this.quote)) throw new Error("invalid quote: " + this.quote);
|
||||
}
|
||||
},
|
||||
}, AST_Statement);
|
||||
|
||||
@@ -1320,6 +1462,10 @@ var AST_DefaultValue = DEFNODE("DefaultValue", "name value", {
|
||||
name: "[AST_Destructured|AST_SymbolDeclaration] name of the variable",
|
||||
value: "[AST_Node] value to assign if variable is `undefined`",
|
||||
},
|
||||
_equals: function(node) {
|
||||
return this.name.equals(node.name)
|
||||
&& this.value.equals(node.value);
|
||||
},
|
||||
walk: function(visitor) {
|
||||
var node = this;
|
||||
visitor.visit(node, function() {
|
||||
@@ -1347,6 +1493,11 @@ var AST_Call = DEFNODE("Call", "args expression optional pure terminal", {
|
||||
pure: "[boolean/S] marker for side-effect-free call expression",
|
||||
terminal: "[boolean] whether the chain has ended",
|
||||
},
|
||||
_equals: function(node) {
|
||||
return !this.optional == !node.optional
|
||||
&& this.expression.equals(node.expression)
|
||||
&& all_equals(this.args, node.args);
|
||||
},
|
||||
walk: function(visitor) {
|
||||
var node = this;
|
||||
visitor.visit(node, function() {
|
||||
@@ -1375,6 +1526,9 @@ var AST_Sequence = DEFNODE("Sequence", "expressions", {
|
||||
$propdoc: {
|
||||
expressions: "[AST_Node*] array of expressions (at least two)"
|
||||
},
|
||||
_equals: function(node) {
|
||||
return all_equals(this.expressions, node.expressions);
|
||||
},
|
||||
walk: function(visitor) {
|
||||
var node = this;
|
||||
visitor.visit(node, function() {
|
||||
@@ -1402,6 +1556,11 @@ var AST_PropAccess = DEFNODE("PropAccess", "expression optional property termina
|
||||
property: "[AST_Node|string] the property to access. For AST_Dot this is always a plain string, while for AST_Sub it's an arbitrary AST_Node",
|
||||
terminal: "[boolean] whether the chain has ended",
|
||||
},
|
||||
_equals: function(node) {
|
||||
return !this.optional == !node.optional
|
||||
&& prop_equals(this.property, node.property)
|
||||
&& this.expression.equals(node.expression);
|
||||
},
|
||||
get_property: function() {
|
||||
var p = this.property;
|
||||
if (p instanceof AST_Constant) return p.value;
|
||||
@@ -1446,6 +1605,9 @@ var AST_Spread = DEFNODE("Spread", "expression", {
|
||||
$propdoc: {
|
||||
expression: "[AST_Node] expression to be expanded",
|
||||
},
|
||||
_equals: function(node) {
|
||||
return this.expression.equals(node.expression);
|
||||
},
|
||||
walk: function(visitor) {
|
||||
var node = this;
|
||||
visitor.visit(node, function() {
|
||||
@@ -1463,6 +1625,10 @@ var AST_Unary = DEFNODE("Unary", "operator expression", {
|
||||
operator: "[string] the operator",
|
||||
expression: "[AST_Node] expression that this unary operator applies to"
|
||||
},
|
||||
_equals: function(node) {
|
||||
return this.operator == node.operator
|
||||
&& this.expression.equals(node.expression);
|
||||
},
|
||||
walk: function(visitor) {
|
||||
var node = this;
|
||||
visitor.visit(node, function() {
|
||||
@@ -1491,6 +1657,11 @@ var AST_Binary = DEFNODE("Binary", "operator left right", {
|
||||
operator: "[string] the operator",
|
||||
right: "[AST_Node] right-hand side expression"
|
||||
},
|
||||
_equals: function(node) {
|
||||
return this.operator == node.operator
|
||||
&& this.left.equals(node.left)
|
||||
&& this.right.equals(node.right);
|
||||
},
|
||||
walk: function(visitor) {
|
||||
var node = this;
|
||||
visitor.visit(node, function() {
|
||||
@@ -1512,6 +1683,11 @@ var AST_Conditional = DEFNODE("Conditional", "condition consequent alternative",
|
||||
consequent: "[AST_Node]",
|
||||
alternative: "[AST_Node]"
|
||||
},
|
||||
_equals: function(node) {
|
||||
return this.condition.equals(node.condition)
|
||||
&& this.consequent.equals(node.consequent)
|
||||
&& this.alternative.equals(node.alternative);
|
||||
},
|
||||
walk: function(visitor) {
|
||||
var node = this;
|
||||
visitor.visit(node, function() {
|
||||
@@ -1553,6 +1729,9 @@ var AST_Await = DEFNODE("Await", "expression", {
|
||||
$propdoc: {
|
||||
expression: "[AST_Node] expression with Promise to resolve on",
|
||||
},
|
||||
_equals: function(node) {
|
||||
return this.expression.equals(node.expression);
|
||||
},
|
||||
walk: function(visitor) {
|
||||
var node = this;
|
||||
visitor.visit(node, function() {
|
||||
@@ -1570,6 +1749,10 @@ var AST_Yield = DEFNODE("Yield", "expression nested", {
|
||||
expression: "[AST_Node?] return value for iterator, or null if undefined",
|
||||
nested: "[boolean] whether to iterate over expression as generator",
|
||||
},
|
||||
_equals: function(node) {
|
||||
return !this.nested == !node.nested
|
||||
&& prop_equals(this.expression, node.expression);
|
||||
},
|
||||
walk: function(visitor) {
|
||||
var node = this;
|
||||
visitor.visit(node, function() {
|
||||
@@ -1592,6 +1775,9 @@ var AST_Array = DEFNODE("Array", "elements", {
|
||||
$propdoc: {
|
||||
elements: "[AST_Node*] array of elements"
|
||||
},
|
||||
_equals: function(node) {
|
||||
return all_equals(this.elements, node.elements);
|
||||
},
|
||||
walk: function(visitor) {
|
||||
var node = this;
|
||||
visitor.visit(node, function() {
|
||||
@@ -1634,6 +1820,10 @@ var AST_DestructuredArray = DEFNODE("DestructuredArray", "elements", {
|
||||
$propdoc: {
|
||||
elements: "[(AST_DefaultValue|AST_Destructured|AST_SymbolDeclaration|AST_SymbolRef)*] array of elements",
|
||||
},
|
||||
_equals: function(node) {
|
||||
return prop_equals(this.rest, node.rest)
|
||||
&& all_equals(this.elements, node.elements);
|
||||
},
|
||||
walk: function(visitor) {
|
||||
var node = this;
|
||||
visitor.visit(node, function() {
|
||||
@@ -1651,6 +1841,10 @@ var AST_DestructuredKeyVal = DEFNODE("DestructuredKeyVal", "key value", {
|
||||
key: "[string|AST_Node] property name. For computed property this is an AST_Node.",
|
||||
value: "[AST_DefaultValue|AST_Destructured|AST_SymbolDeclaration|AST_SymbolRef] property value",
|
||||
},
|
||||
_equals: function(node) {
|
||||
return prop_equals(this.key, node.key)
|
||||
&& this.value.equals(node.value);
|
||||
},
|
||||
walk: function(visitor) {
|
||||
var node = this;
|
||||
visitor.visit(node, function() {
|
||||
@@ -1672,6 +1866,10 @@ var AST_DestructuredObject = DEFNODE("DestructuredObject", "properties", {
|
||||
$propdoc: {
|
||||
properties: "[AST_DestructuredKeyVal*] array of properties",
|
||||
},
|
||||
_equals: function(node) {
|
||||
return prop_equals(this.rest, node.rest)
|
||||
&& all_equals(this.properties, node.properties);
|
||||
},
|
||||
walk: function(visitor) {
|
||||
var node = this;
|
||||
visitor.visit(node, function() {
|
||||
@@ -1693,6 +1891,9 @@ var AST_Object = DEFNODE("Object", "properties", {
|
||||
$propdoc: {
|
||||
properties: "[(AST_ObjectProperty|AST_Spread)*] array of properties"
|
||||
},
|
||||
_equals: function(node) {
|
||||
return all_equals(this.properties, node.properties);
|
||||
},
|
||||
walk: function(visitor) {
|
||||
var node = this;
|
||||
visitor.visit(node, function() {
|
||||
@@ -1716,6 +1917,10 @@ var AST_ObjectProperty = DEFNODE("ObjectProperty", "key value", {
|
||||
key: "[string|AST_Node] property name. For computed property this is an AST_Node.",
|
||||
value: "[AST_Node] property value. For getters and setters this is an AST_Accessor.",
|
||||
},
|
||||
_equals: function(node) {
|
||||
return prop_equals(this.key, node.key)
|
||||
&& this.value.equals(node.value);
|
||||
},
|
||||
walk: function(visitor) {
|
||||
var node = this;
|
||||
visitor.visit(node, function() {
|
||||
@@ -1770,6 +1975,9 @@ var AST_Symbol = DEFNODE("Symbol", "scope name thedef", {
|
||||
scope: "[AST_Scope/S] the current scope (not necessarily the definition scope)",
|
||||
thedef: "[SymbolDef/S] the definition of this symbol"
|
||||
},
|
||||
_equals: function(node) {
|
||||
return this.thedef ? this.thedef === node.thedef : this.name == node.name;
|
||||
},
|
||||
_validate: function() {
|
||||
if (this.TYPE == "Symbol") throw new Error("should not instantiate AST_Symbol");
|
||||
if (typeof this.name != "string") throw new Error("name must be string");
|
||||
@@ -1787,10 +1995,14 @@ var AST_SymbolConst = DEFNODE("SymbolConst", null, {
|
||||
var AST_SymbolImport = DEFNODE("SymbolImport", "key", {
|
||||
$documentation: "Symbol defined by an `import` statement",
|
||||
$propdoc: {
|
||||
key: "[string] the original `export` name",
|
||||
key: "[AST_String] the original `export` name",
|
||||
},
|
||||
_equals: function(node) {
|
||||
return this.name == node.name
|
||||
&& this.key.equals(node.key);
|
||||
},
|
||||
_validate: function() {
|
||||
if (typeof this.key != "string") throw new Error("key must be string");
|
||||
if (!(this.key instanceof AST_String)) throw new Error("key must be AST_String");
|
||||
},
|
||||
}, AST_SymbolConst);
|
||||
|
||||
@@ -1834,7 +2046,7 @@ var AST_Label = DEFNODE("Label", "references", {
|
||||
initialize: function() {
|
||||
this.references = [];
|
||||
this.thedef = this;
|
||||
}
|
||||
},
|
||||
}, AST_Symbol);
|
||||
|
||||
var AST_SymbolRef = DEFNODE("SymbolRef", "fixed in_arg redef", {
|
||||
@@ -1844,10 +2056,14 @@ var AST_SymbolRef = DEFNODE("SymbolRef", "fixed in_arg redef", {
|
||||
var AST_SymbolExport = DEFNODE("SymbolExport", "alias", {
|
||||
$documentation: "Reference in an `export` statement",
|
||||
$propdoc: {
|
||||
alias: "[string] the `export` alias",
|
||||
alias: "[AST_String] the `export` alias",
|
||||
},
|
||||
_equals: function(node) {
|
||||
return this.name == node.name
|
||||
&& this.alias.equals(node.alias);
|
||||
},
|
||||
_validate: function() {
|
||||
if (typeof this.alias != "string") throw new Error("alias must be string");
|
||||
if (!(this.alias instanceof AST_String)) throw new Error("alias must be AST_String");
|
||||
},
|
||||
}, AST_SymbolRef);
|
||||
|
||||
@@ -1857,6 +2073,7 @@ var AST_LabelRef = DEFNODE("LabelRef", null, {
|
||||
|
||||
var AST_ObjectIdentity = DEFNODE("ObjectIdentity", null, {
|
||||
$documentation: "Base class for `super` & `this`",
|
||||
_equals: return_true,
|
||||
_validate: function() {
|
||||
if (this.TYPE == "ObjectIdentity") throw new Error("should not instantiate AST_ObjectIdentity");
|
||||
},
|
||||
@@ -1891,7 +2108,12 @@ var AST_Template = DEFNODE("Template", "expressions strings tag", {
|
||||
$propdoc: {
|
||||
expressions: "[AST_Node*] the placeholder expressions",
|
||||
strings: "[string*] the raw text segments",
|
||||
tag: "[AST_Node] tag function, or null if absent",
|
||||
tag: "[AST_Node?] tag function, or null if absent",
|
||||
},
|
||||
_equals: function(node) {
|
||||
return prop_equals(this.tag, node.tag)
|
||||
&& list_equals(this.strings, node.strings)
|
||||
&& all_equals(this.expressions, node.expressions);
|
||||
},
|
||||
walk: function(visitor) {
|
||||
var node = this;
|
||||
@@ -1916,6 +2138,9 @@ var AST_Template = DEFNODE("Template", "expressions strings tag", {
|
||||
|
||||
var AST_Constant = DEFNODE("Constant", null, {
|
||||
$documentation: "Base class for all constants",
|
||||
_equals: function(node) {
|
||||
return this.value === node.value;
|
||||
},
|
||||
_validate: function() {
|
||||
if (this.TYPE == "Constant") throw new Error("should not instantiate AST_Constant");
|
||||
},
|
||||
@@ -1964,6 +2189,9 @@ var AST_RegExp = DEFNODE("RegExp", "value", {
|
||||
$propdoc: {
|
||||
value: "[RegExp] the actual regexp"
|
||||
},
|
||||
_equals: function(node) {
|
||||
return "" + this.value == "" + node.value;
|
||||
},
|
||||
_validate: function() {
|
||||
if (!(this.value instanceof RegExp)) throw new Error("value must be RegExp");
|
||||
},
|
||||
@@ -1971,6 +2199,7 @@ var AST_RegExp = DEFNODE("RegExp", "value", {
|
||||
|
||||
var AST_Atom = DEFNODE("Atom", null, {
|
||||
$documentation: "Base class for atoms",
|
||||
_equals: return_true,
|
||||
_validate: function() {
|
||||
if (this.TYPE == "Atom") throw new Error("should not instantiate AST_Atom");
|
||||
},
|
||||
@@ -2036,16 +2265,21 @@ TreeWalker.prototype = {
|
||||
return this.stack[this.stack.length - 2 - (n || 0)];
|
||||
},
|
||||
push: function(node) {
|
||||
if (node instanceof AST_Lambda) {
|
||||
var value;
|
||||
if (node instanceof AST_Class) {
|
||||
this.directives = Object.create(this.directives);
|
||||
value = "use strict";
|
||||
} else if (node instanceof AST_Directive) {
|
||||
value = node.value;
|
||||
} else if (node instanceof AST_Lambda) {
|
||||
this.directives = Object.create(this.directives);
|
||||
} else if (node instanceof AST_Directive && !this.directives[node.value]) {
|
||||
this.directives[node.value] = node;
|
||||
}
|
||||
if (value && !this.directives[value]) this.directives[value] = node;
|
||||
this.stack.push(node);
|
||||
},
|
||||
pop: function() {
|
||||
var node = this.stack.pop();
|
||||
if (node instanceof AST_Lambda) {
|
||||
if (node instanceof AST_Class || node instanceof AST_Lambda) {
|
||||
this.directives = Object.getPrototypeOf(this.directives);
|
||||
}
|
||||
},
|
||||
@@ -2085,33 +2319,40 @@ TreeWalker.prototype = {
|
||||
}
|
||||
},
|
||||
in_boolean_context: function() {
|
||||
var self = this.self();
|
||||
for (var i = 0, p; p = this.parent(i); i++) {
|
||||
if (p instanceof AST_Conditional && p.condition === self
|
||||
|| p instanceof AST_DWLoop && p.condition === self
|
||||
|| p instanceof AST_For && p.condition === self
|
||||
|| p instanceof AST_If && p.condition === self
|
||||
|| p instanceof AST_Return && p.in_bool
|
||||
|| p instanceof AST_Sequence && p.tail_node() !== self
|
||||
|| p instanceof AST_SimpleStatement
|
||||
|| p instanceof AST_UnaryPrefix && p.operator == "!" && p.expression === self) {
|
||||
return true;
|
||||
}
|
||||
if (p instanceof AST_Binary && (p.operator == "&&" || p.operator == "||")
|
||||
|| p instanceof AST_Conditional
|
||||
|| p.tail_node() === self) {
|
||||
self = p;
|
||||
} else if (p instanceof AST_Return) {
|
||||
for (var call, fn = p; call = this.parent(++i); fn = call) {
|
||||
if (call.TYPE == "Call") {
|
||||
if (!(fn instanceof AST_Lambda) || fn.name) return false;
|
||||
} else if (fn instanceof AST_Lambda) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
for (var drop = true, level = 0, parent, self = this.self(); parent = this.parent(level++); self = parent) {
|
||||
if (parent instanceof AST_Binary) switch (parent.operator) {
|
||||
case "&&":
|
||||
case "||":
|
||||
if (parent.left === self) drop = false;
|
||||
continue;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
if (parent instanceof AST_Conditional) {
|
||||
if (parent.condition === self) return true;
|
||||
continue;
|
||||
}
|
||||
if (parent instanceof AST_DWLoop) return parent.condition === self;
|
||||
if (parent instanceof AST_For) return parent.condition === self;
|
||||
if (parent instanceof AST_If) return parent.condition === self;
|
||||
if (parent instanceof AST_Return) {
|
||||
if (parent.in_bool) return true;
|
||||
while (parent = this.parent(level++)) {
|
||||
if (parent instanceof AST_Lambda) {
|
||||
if (parent.name) return false;
|
||||
parent = this.parent(level++);
|
||||
if (parent.TYPE != "Call") return false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (parent instanceof AST_Sequence) {
|
||||
if (parent.tail_node() === self) continue;
|
||||
return drop ? "d" : true;
|
||||
}
|
||||
if (parent instanceof AST_SimpleStatement) return drop ? "d" : true;
|
||||
if (parent instanceof AST_UnaryPrefix) return parent.operator == "!";
|
||||
return false;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
2632
lib/compress.js
2632
lib/compress.js
File diff suppressed because it is too large
Load Diff
@@ -81,13 +81,14 @@ function minify(files, options) {
|
||||
keep_fargs: false,
|
||||
keep_fnames: false,
|
||||
mangle: {},
|
||||
module: false,
|
||||
nameCache: null,
|
||||
output: {},
|
||||
parse: {},
|
||||
rename: undefined,
|
||||
sourceMap: false,
|
||||
timings: false,
|
||||
toplevel: false,
|
||||
toplevel: !!(options && options["module"]),
|
||||
v8: false,
|
||||
validate: false,
|
||||
warnings: false,
|
||||
@@ -96,15 +97,15 @@ function minify(files, options) {
|
||||
}, true);
|
||||
if (options.validate) AST_Node.enable_validation();
|
||||
var timings = options.timings && { start: Date.now() };
|
||||
if (options.rename === undefined) options.rename = options.compress && options.mangle;
|
||||
if (options.annotations !== undefined) set_shorthand("annotations", options, [ "compress", "output" ]);
|
||||
if (options.ie8) options.ie = options.ie || options.ie8;
|
||||
if (options.ie) set_shorthand("ie", options, [ "compress", "mangle", "output" ]);
|
||||
if (options.keep_fargs) set_shorthand("keep_fargs", options, [ "compress", "mangle" ]);
|
||||
if (options.keep_fnames) set_shorthand("keep_fnames", options, [ "compress", "mangle" ]);
|
||||
if (options.toplevel) set_shorthand("toplevel", options, [ "compress", "mangle" ]);
|
||||
if (options.v8) set_shorthand("v8", options, [ "mangle", "output" ]);
|
||||
if (options.webkit) set_shorthand("webkit", options, [ "compress", "mangle", "output" ]);
|
||||
if (options.ie) set_shorthand("ie", options, [ "compress", "mangle", "output", "rename" ]);
|
||||
if (options.keep_fargs) set_shorthand("keep_fargs", options, [ "compress", "mangle", "rename" ]);
|
||||
if (options.keep_fnames) set_shorthand("keep_fnames", options, [ "compress", "mangle", "rename" ]);
|
||||
if (options.module) set_shorthand("module", options, [ "compress", "parse" ]);
|
||||
if (options.toplevel) set_shorthand("toplevel", options, [ "compress", "mangle", "rename" ]);
|
||||
if (options.v8) set_shorthand("v8", options, [ "mangle", "output", "rename" ]);
|
||||
if (options.webkit) set_shorthand("webkit", options, [ "compress", "mangle", "output", "rename" ]);
|
||||
var quoted_props;
|
||||
if (options.mangle) {
|
||||
options.mangle = defaults(options.mangle, {
|
||||
@@ -135,6 +136,7 @@ function minify(files, options) {
|
||||
init_cache(options.mangle.cache);
|
||||
init_cache(options.mangle.properties.cache);
|
||||
}
|
||||
if (options.rename === undefined) options.rename = options.compress && options.mangle;
|
||||
if (options.sourceMap) {
|
||||
options.sourceMap = defaults(options.sourceMap, {
|
||||
content: null,
|
||||
@@ -190,8 +192,8 @@ function minify(files, options) {
|
||||
if (options.validate) toplevel.validate_ast();
|
||||
if (timings) timings.rename = Date.now();
|
||||
if (options.rename) {
|
||||
toplevel.figure_out_scope(options.mangle);
|
||||
toplevel.expand_names(options.mangle);
|
||||
toplevel.figure_out_scope(options.rename);
|
||||
toplevel.expand_names(options.rename);
|
||||
}
|
||||
if (timings) timings.compress = Date.now();
|
||||
if (options.compress) {
|
||||
|
||||
@@ -192,6 +192,19 @@
|
||||
value: from_moz(M.value),
|
||||
});
|
||||
},
|
||||
StaticBlock: function(M) {
|
||||
var start = my_start_token(M);
|
||||
var end = my_end_token(M);
|
||||
return new AST_ClassInit({
|
||||
start: start,
|
||||
end: end,
|
||||
value: new AST_ClassInitBlock({
|
||||
start: start,
|
||||
end: end,
|
||||
body: normalize_directives(M.body.map(from_moz)),
|
||||
}),
|
||||
});
|
||||
},
|
||||
ForOfStatement: function(M) {
|
||||
return new (M.await ? AST_ForAwaitOf : AST_ForOf)({
|
||||
start: my_start_token(M),
|
||||
@@ -303,13 +316,22 @@
|
||||
});
|
||||
},
|
||||
ExportAllDeclaration: function(M) {
|
||||
var alias = M.exported ? read_name(M.exported) : "*";
|
||||
var start = my_start_token(M);
|
||||
var end = my_end_token(M);
|
||||
return new AST_ExportForeign({
|
||||
start: my_start_token(M),
|
||||
end: my_end_token(M),
|
||||
aliases: [ alias ],
|
||||
keys: [ "*" ],
|
||||
path: M.source.value,
|
||||
start: start,
|
||||
end: end,
|
||||
aliases: [ M.exported ? from_moz_alias(M.exported) : new AST_String({
|
||||
start: start,
|
||||
value: "*",
|
||||
end: end,
|
||||
}) ],
|
||||
keys: [ new AST_String({
|
||||
start: start,
|
||||
value: "*",
|
||||
end: end,
|
||||
}) ],
|
||||
path: from_moz(M.source),
|
||||
});
|
||||
},
|
||||
ExportDefaultDeclaration: function(M) {
|
||||
@@ -346,15 +368,15 @@
|
||||
if (M.source) {
|
||||
var aliases = [], keys = [];
|
||||
M.specifiers.forEach(function(prop) {
|
||||
aliases.push(read_name(prop.exported));
|
||||
keys.push(read_name(prop.local));
|
||||
aliases.push(from_moz_alias(prop.exported));
|
||||
keys.push(from_moz_alias(prop.local));
|
||||
});
|
||||
return new AST_ExportForeign({
|
||||
start: my_start_token(M),
|
||||
end: my_end_token(M),
|
||||
aliases: aliases,
|
||||
keys: keys,
|
||||
path: M.source.value,
|
||||
path: from_moz(M.source),
|
||||
});
|
||||
}
|
||||
return new AST_ExportReferences({
|
||||
@@ -362,38 +384,48 @@
|
||||
end: my_end_token(M),
|
||||
properties: M.specifiers.map(function(prop) {
|
||||
var sym = new AST_SymbolExport(from_moz(prop.local));
|
||||
sym.alias = read_name(prop.exported);
|
||||
sym.alias = from_moz_alias(prop.exported);
|
||||
return sym;
|
||||
}),
|
||||
});
|
||||
},
|
||||
ImportDeclaration: function(M) {
|
||||
var start = my_start_token(M);
|
||||
var end = my_end_token(M);
|
||||
var all = null, def = null, props = null;
|
||||
M.specifiers.forEach(function(prop) {
|
||||
var sym = new AST_SymbolImport(from_moz(prop.local));
|
||||
switch (prop.type) {
|
||||
case "ImportDefaultSpecifier":
|
||||
def = sym;
|
||||
def.key = "";
|
||||
def.key = new AST_String({
|
||||
start: start,
|
||||
value: "",
|
||||
end: end,
|
||||
});
|
||||
break;
|
||||
case "ImportNamespaceSpecifier":
|
||||
all = sym;
|
||||
all.key = "*";
|
||||
all.key = new AST_String({
|
||||
start: start,
|
||||
value: "*",
|
||||
end: end,
|
||||
});
|
||||
break;
|
||||
default:
|
||||
sym.key = prop.imported.name || syn.name;
|
||||
sym.key = from_moz_alias(prop.imported);
|
||||
if (!props) props = [];
|
||||
props.push(sym);
|
||||
break;
|
||||
}
|
||||
});
|
||||
return new AST_Import({
|
||||
start: my_start_token(M),
|
||||
end: my_end_token(M),
|
||||
start: start,
|
||||
end: end,
|
||||
all: all,
|
||||
default: def,
|
||||
properties: props,
|
||||
path: M.source.value,
|
||||
path: from_moz(M.source),
|
||||
});
|
||||
},
|
||||
ImportExpression: function(M) {
|
||||
@@ -714,6 +746,10 @@
|
||||
};
|
||||
});
|
||||
|
||||
def_to_moz(AST_ClassInit, function To_Moz_StaticBlock(M) {
|
||||
return to_moz_scope("StaticBlock", M.value);
|
||||
});
|
||||
|
||||
function To_Moz_ForOfStatement(is_await) {
|
||||
return function(M) {
|
||||
return {
|
||||
@@ -780,38 +816,26 @@
|
||||
});
|
||||
|
||||
def_to_moz(AST_ExportForeign, function To_Moz_ExportAllDeclaration_ExportNamedDeclaration(M) {
|
||||
if (M.keys[0] == "*") return {
|
||||
if (M.keys[0].value == "*") return {
|
||||
type: "ExportAllDeclaration",
|
||||
exported: M.aliases[0] == "*" ? null : {
|
||||
type: "Identifier",
|
||||
name: M.aliases[0],
|
||||
},
|
||||
source: {
|
||||
type: "Literal",
|
||||
value: M.path,
|
||||
},
|
||||
exported: M.aliases[0].value == "*" ? null : to_moz_alias(M.aliases[0]),
|
||||
source: to_moz(M.path),
|
||||
};
|
||||
var specifiers = [];
|
||||
for (var i = 0; i < M.aliases.length; i++) {
|
||||
specifiers.push({
|
||||
specifiers.push(set_moz_loc({
|
||||
start: M.keys[i].start,
|
||||
end: M.aliases[i].end,
|
||||
}, {
|
||||
type: "ExportSpecifier",
|
||||
exported: {
|
||||
type: "Identifier",
|
||||
name: M.aliases[i],
|
||||
},
|
||||
local: {
|
||||
type: "Identifier",
|
||||
name: M.keys[i],
|
||||
},
|
||||
});
|
||||
local: to_moz_alias(M.keys[i]),
|
||||
exported: to_moz_alias(M.aliases[i]),
|
||||
}));
|
||||
}
|
||||
return {
|
||||
type: "ExportNamedDeclaration",
|
||||
specifiers: specifiers,
|
||||
source: {
|
||||
type: "Literal",
|
||||
value: M.path,
|
||||
},
|
||||
source: to_moz(M.path),
|
||||
};
|
||||
});
|
||||
|
||||
@@ -819,44 +843,41 @@
|
||||
return {
|
||||
type: "ExportNamedDeclaration",
|
||||
specifiers: M.properties.map(function(prop) {
|
||||
return {
|
||||
return set_moz_loc({
|
||||
start: prop.start,
|
||||
end: prop.alias.end,
|
||||
}, {
|
||||
type: "ExportSpecifier",
|
||||
local: to_moz(prop),
|
||||
exported: {
|
||||
type: "Identifier",
|
||||
name: prop.alias,
|
||||
},
|
||||
};
|
||||
exported: to_moz_alias(prop.alias),
|
||||
});
|
||||
}),
|
||||
};
|
||||
});
|
||||
|
||||
def_to_moz(AST_Import, function To_Moz_ImportDeclaration(M) {
|
||||
var specifiers = M.properties ? M.properties.map(function(prop) {
|
||||
return {
|
||||
return set_moz_loc({
|
||||
start: prop.key.start,
|
||||
end: prop.end,
|
||||
}, {
|
||||
type: "ImportSpecifier",
|
||||
local: to_moz(prop),
|
||||
imported: {
|
||||
type: "Identifier",
|
||||
name: prop.key,
|
||||
},
|
||||
};
|
||||
imported: to_moz_alias(prop.key),
|
||||
});
|
||||
}) : [];
|
||||
if (M.all) specifiers.unshift({
|
||||
if (M.all) specifiers.unshift(set_moz_loc(M.all, {
|
||||
type: "ImportNamespaceSpecifier",
|
||||
local: to_moz(M.all),
|
||||
});
|
||||
if (M.default) specifiers.unshift({
|
||||
}));
|
||||
if (M.default) specifiers.unshift(set_moz_loc(M.default, {
|
||||
type: "ImportDefaultSpecifier",
|
||||
local: to_moz(M.default),
|
||||
});
|
||||
}));
|
||||
return {
|
||||
type: "ImportDeclaration",
|
||||
specifiers: specifiers,
|
||||
source: {
|
||||
type: "Literal",
|
||||
value: M.path,
|
||||
},
|
||||
source: to_moz(M.path),
|
||||
};
|
||||
});
|
||||
|
||||
@@ -1203,6 +1224,14 @@
|
||||
return node;
|
||||
}
|
||||
|
||||
function from_moz_alias(moz) {
|
||||
return new AST_String({
|
||||
start: my_start_token(moz),
|
||||
value: read_name(moz),
|
||||
end: my_end_token(moz),
|
||||
});
|
||||
}
|
||||
|
||||
AST_Node.from_mozilla_ast = function(node) {
|
||||
var save_stack = FROM_MOZ_STACK;
|
||||
FROM_MOZ_STACK = [];
|
||||
@@ -1254,6 +1283,13 @@
|
||||
return node != null ? node.to_mozilla_ast() : null;
|
||||
}
|
||||
|
||||
function to_moz_alias(alias) {
|
||||
return is_identifier_string(alias.value) ? set_moz_loc(alias, {
|
||||
type: "Identifier",
|
||||
name: alias.value,
|
||||
}) : to_moz(alias);
|
||||
}
|
||||
|
||||
function to_moz_block(node) {
|
||||
return {
|
||||
type: "BlockStatement",
|
||||
|
||||
189
lib/output.js
189
lib/output.js
@@ -101,10 +101,18 @@ function OutputStream(options) {
|
||||
}
|
||||
}
|
||||
|
||||
function make_indent(value) {
|
||||
if (typeof value == "number") return new Array(value + 1).join(" ");
|
||||
if (!value) return "";
|
||||
if (!/^\s*$/.test(value)) throw new Error("unsupported indentation: " + JSON.stringify("" + value));
|
||||
return value;
|
||||
}
|
||||
|
||||
var current_col = 0;
|
||||
var current_line = 1;
|
||||
var current_pos = 0;
|
||||
var indentation = options.indent_start;
|
||||
var current_indent = make_indent(options.indent_start);
|
||||
var full_indent = make_indent(options.indent_level);
|
||||
var half_indent = full_indent.length + 1 >> 1;
|
||||
var last;
|
||||
var line_end = 0;
|
||||
var line_fixed = true;
|
||||
@@ -115,17 +123,17 @@ function OutputStream(options) {
|
||||
var might_need_semicolon;
|
||||
var need_newline_indented = false;
|
||||
var need_space = false;
|
||||
var newline_insert = -1;
|
||||
var output;
|
||||
var stack;
|
||||
var OUTPUT;
|
||||
var stored = "";
|
||||
|
||||
function reset() {
|
||||
last = "";
|
||||
might_need_space = false;
|
||||
might_need_semicolon = false;
|
||||
stack = [];
|
||||
var str = OUTPUT;
|
||||
OUTPUT = "";
|
||||
var str = output;
|
||||
output = "";
|
||||
return str;
|
||||
}
|
||||
|
||||
@@ -227,32 +235,39 @@ function OutputStream(options) {
|
||||
} : noop;
|
||||
|
||||
function insert_newlines(count) {
|
||||
var index = OUTPUT.lastIndexOf("\n");
|
||||
if (line_end < index) line_end = index;
|
||||
var left = OUTPUT.slice(0, line_end);
|
||||
var right = OUTPUT.slice(line_end);
|
||||
adjust_mappings(count, right.length - current_col);
|
||||
stored += output.slice(0, line_end);
|
||||
output = output.slice(line_end);
|
||||
var new_col = output.length;
|
||||
adjust_mappings(count, new_col - current_col);
|
||||
current_line += count;
|
||||
current_pos += count;
|
||||
current_col = right.length;
|
||||
OUTPUT = left;
|
||||
while (count--) OUTPUT += "\n";
|
||||
OUTPUT += right;
|
||||
current_col = new_col;
|
||||
while (count--) stored += "\n";
|
||||
}
|
||||
|
||||
var fix_line = options.max_line_len ? function() {
|
||||
var fix_line = options.max_line_len ? function(flush) {
|
||||
if (line_fixed) {
|
||||
if (current_col > options.max_line_len) {
|
||||
AST_Node.warn("Output exceeds {max_line_len} characters", options);
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (current_col > options.max_line_len) insert_newlines(1);
|
||||
line_fixed = true;
|
||||
flush_mappings();
|
||||
if (current_col > options.max_line_len) {
|
||||
insert_newlines(1);
|
||||
line_fixed = true;
|
||||
}
|
||||
if (line_fixed || flush) flush_mappings();
|
||||
} : noop;
|
||||
|
||||
var requireSemicolonChars = makePredicate("( [ + * / - , .");
|
||||
var require_semicolon = makePredicate("( [ + * / - , .");
|
||||
|
||||
function require_space(prev, ch, str) {
|
||||
return is_identifier_char(prev) && (is_identifier_char(ch) || ch == "\\")
|
||||
|| (ch == "/" && ch == prev)
|
||||
|| ((ch == "+" || ch == "-") && ch == last)
|
||||
|| last == "--" && ch == ">"
|
||||
|| last == "!" && str == "--"
|
||||
|| prev == "/" && (str == "in" || str == "instanceof");
|
||||
}
|
||||
|
||||
var print = options.beautify
|
||||
|| options.comments
|
||||
@@ -276,45 +291,39 @@ function OutputStream(options) {
|
||||
space();
|
||||
}
|
||||
}
|
||||
newline_insert = -1;
|
||||
var prev = last.slice(-1);
|
||||
if (might_need_semicolon) {
|
||||
might_need_semicolon = false;
|
||||
|
||||
if (prev == ":" && ch == "}" || (!ch || ";}".indexOf(ch) < 0) && prev != ";") {
|
||||
if (options.semicolons || requireSemicolonChars[ch]) {
|
||||
OUTPUT += ";";
|
||||
if (prev == ":" && ch == "}" || prev != ";" && (!ch || ";}".indexOf(ch) < 0)) {
|
||||
var need_semicolon = require_semicolon[ch];
|
||||
if (need_semicolon || options.semicolons) {
|
||||
output += ";";
|
||||
current_col++;
|
||||
current_pos++;
|
||||
if (!line_fixed) {
|
||||
fix_line();
|
||||
if (line_fixed && !need_semicolon && output == ";") {
|
||||
output = "";
|
||||
current_col = 0;
|
||||
}
|
||||
}
|
||||
if (line_end == output.length - 1) line_end++;
|
||||
} else {
|
||||
fix_line();
|
||||
OUTPUT += "\n";
|
||||
current_pos++;
|
||||
output += "\n";
|
||||
current_line++;
|
||||
current_col = 0;
|
||||
|
||||
if (/^\s+$/.test(str)) {
|
||||
// reset the semicolon flag, since we didn't print one
|
||||
// now and might still have to later
|
||||
might_need_semicolon = true;
|
||||
}
|
||||
// reset the semicolon flag, since we didn't print one
|
||||
// now and might still have to later
|
||||
if (/^\s+$/.test(str)) might_need_semicolon = true;
|
||||
}
|
||||
|
||||
if (!options.beautify)
|
||||
might_need_space = false;
|
||||
if (!options.beautify) might_need_space = false;
|
||||
}
|
||||
}
|
||||
|
||||
if (might_need_space) {
|
||||
if (is_identifier_char(prev) && (is_identifier_char(ch) || ch == "\\")
|
||||
|| (ch == "/" && ch == prev)
|
||||
|| ((ch == "+" || ch == "-") && ch == last)
|
||||
|| str == "--" && last == "!"
|
||||
|| str == "in" && prev == "/"
|
||||
|| last == "--" && ch == ">") {
|
||||
OUTPUT += " ";
|
||||
if (require_space(prev, ch, str)) {
|
||||
output += " ";
|
||||
current_col++;
|
||||
current_pos++;
|
||||
}
|
||||
if (prev != "<" || str != "!") might_need_space = false;
|
||||
}
|
||||
@@ -324,14 +333,13 @@ function OutputStream(options) {
|
||||
token: mapping_token,
|
||||
name: mapping_name,
|
||||
line: current_line,
|
||||
col: current_col
|
||||
col: current_col,
|
||||
});
|
||||
mapping_token = false;
|
||||
if (line_fixed) flush_mappings();
|
||||
}
|
||||
|
||||
OUTPUT += str;
|
||||
current_pos += str.length;
|
||||
output += str;
|
||||
var a = str.split(/\r?\n/), n = a.length - 1;
|
||||
current_line += n;
|
||||
current_col += a[0].length;
|
||||
@@ -346,22 +354,15 @@ function OutputStream(options) {
|
||||
if (might_need_semicolon) {
|
||||
might_need_semicolon = false;
|
||||
if (prev == ":" && ch == "}" || (!ch || ";}".indexOf(ch) < 0) && prev != ";") {
|
||||
OUTPUT += ";";
|
||||
output += ";";
|
||||
might_need_space = false;
|
||||
}
|
||||
}
|
||||
if (might_need_space) {
|
||||
if (is_identifier_char(prev) && (is_identifier_char(ch) || ch == "\\")
|
||||
|| (ch == "/" && ch == prev)
|
||||
|| ((ch == "+" || ch == "-") && ch == last)
|
||||
|| str == "--" && last == "!"
|
||||
|| str == "in" && prev == "/"
|
||||
|| last == "--" && ch == ">") {
|
||||
OUTPUT += " ";
|
||||
}
|
||||
if (require_space(prev, ch, str)) output += " ";
|
||||
if (prev != "<" || str != "!") might_need_space = false;
|
||||
}
|
||||
OUTPUT += str;
|
||||
output += str;
|
||||
last = str;
|
||||
};
|
||||
|
||||
@@ -373,30 +374,25 @@ function OutputStream(options) {
|
||||
|
||||
var indent = options.beautify ? function(half) {
|
||||
if (need_newline_indented) print("\n");
|
||||
print(repeat_string(" ", half ? indentation - (options.indent_level >> 1) : indentation));
|
||||
print(half ? current_indent.slice(0, -half_indent) : current_indent);
|
||||
} : noop;
|
||||
|
||||
var with_indent = options.beautify ? function(cont) {
|
||||
var save_indentation = indentation;
|
||||
indentation += options.indent_level;
|
||||
var save_indentation = current_indent;
|
||||
current_indent += full_indent;
|
||||
cont();
|
||||
indentation = save_indentation;
|
||||
current_indent = save_indentation;
|
||||
} : function(cont) { cont() };
|
||||
|
||||
var may_add_newline = options.max_line_len || options.preserve_line ? function() {
|
||||
fix_line();
|
||||
line_end = OUTPUT.length;
|
||||
line_end = output.length;
|
||||
line_fixed = false;
|
||||
} : noop;
|
||||
|
||||
var newline = options.beautify ? function() {
|
||||
if (newline_insert < 0) return print("\n");
|
||||
if (OUTPUT[newline_insert] != "\n") {
|
||||
OUTPUT = OUTPUT.slice(0, newline_insert) + "\n" + OUTPUT.slice(newline_insert);
|
||||
current_pos++;
|
||||
current_line++;
|
||||
}
|
||||
newline_insert++;
|
||||
print("\n");
|
||||
line_end = output.length;
|
||||
} : may_add_newline;
|
||||
|
||||
var semicolon = options.beautify ? function() {
|
||||
@@ -452,13 +448,12 @@ function OutputStream(options) {
|
||||
} : noop;
|
||||
|
||||
function get() {
|
||||
if (!line_fixed) fix_line();
|
||||
return OUTPUT;
|
||||
if (!line_fixed) fix_line(true);
|
||||
return stored + output;
|
||||
}
|
||||
|
||||
function has_nlb() {
|
||||
var index = OUTPUT.lastIndexOf("\n");
|
||||
return /^ *$/.test(OUTPUT.slice(index + 1));
|
||||
return /(^|\n) *$/.test(output);
|
||||
}
|
||||
|
||||
function pad_comment(token, force) {
|
||||
@@ -515,7 +510,7 @@ function OutputStream(options) {
|
||||
scan.walk(tw);
|
||||
}
|
||||
|
||||
if (current_pos == 0) {
|
||||
if (current_line == 1 && current_col == 0) {
|
||||
if (comments.length > 0 && options.shebang && comments[0].type == "comment5") {
|
||||
print("#!" + comments.shift().value + "\n");
|
||||
indent();
|
||||
@@ -559,20 +554,18 @@ function OutputStream(options) {
|
||||
return !/comment[134]/.test(c.type);
|
||||
}))) return;
|
||||
comments._dumped = self;
|
||||
var insert = OUTPUT.length;
|
||||
comments.filter(comment_filter, node).forEach(function(comment, index) {
|
||||
pad_comment(comment, index || !tail);
|
||||
print_comment(comment);
|
||||
});
|
||||
if (OUTPUT.length > insert) newline_insert = insert;
|
||||
}
|
||||
|
||||
return {
|
||||
get : get,
|
||||
reset : reset,
|
||||
indent : indent,
|
||||
should_break : options.width ? function() {
|
||||
return current_col - indentation >= options.width;
|
||||
should_break : options.beautify && options.width ? function() {
|
||||
return current_col >= options.width;
|
||||
} : return_false,
|
||||
has_parens : function() { return last.slice(-1) == "(" },
|
||||
newline : newline,
|
||||
@@ -1068,6 +1061,14 @@ function OutputStream(options) {
|
||||
}
|
||||
output.semicolon();
|
||||
});
|
||||
function print_alias(alias, output) {
|
||||
var value = alias.value;
|
||||
if (value == "*" || is_identifier_string(value)) {
|
||||
output.print_name(value);
|
||||
} else {
|
||||
output.print_string(value, alias.quote);
|
||||
}
|
||||
}
|
||||
DEFPRINT(AST_ExportForeign, function(output) {
|
||||
var self = this;
|
||||
output.print("export");
|
||||
@@ -1075,7 +1076,7 @@ function OutputStream(options) {
|
||||
var len = self.keys.length;
|
||||
if (len == 0) {
|
||||
print_braced_empty(self, output);
|
||||
} else if (self.keys[0] == "*") {
|
||||
} else if (self.keys[0].value == "*") {
|
||||
print_entry(0);
|
||||
} else output.with_block(function() {
|
||||
output.indent();
|
||||
@@ -1091,18 +1092,18 @@ function OutputStream(options) {
|
||||
output.space();
|
||||
output.print("from");
|
||||
output.space();
|
||||
output.print_string(self.path, self.quote);
|
||||
self.path.print(output);
|
||||
output.semicolon();
|
||||
|
||||
function print_entry(index) {
|
||||
var alias = self.aliases[index];
|
||||
var key = self.keys[index];
|
||||
output.print_name(key);
|
||||
if (alias != key) {
|
||||
print_alias(key, output);
|
||||
if (alias.value != key.value) {
|
||||
output.space();
|
||||
output.print("as");
|
||||
output.space();
|
||||
output.print_name(alias);
|
||||
print_alias(alias, output);
|
||||
}
|
||||
}
|
||||
});
|
||||
@@ -1131,7 +1132,7 @@ function OutputStream(options) {
|
||||
output.print("from");
|
||||
output.space();
|
||||
}
|
||||
output.print_string(self.path, self.quote);
|
||||
self.path.print(output);
|
||||
output.semicolon();
|
||||
});
|
||||
|
||||
@@ -1261,6 +1262,11 @@ function OutputStream(options) {
|
||||
}
|
||||
print_method(self, output);
|
||||
});
|
||||
DEFPRINT(AST_ClassInit, function(output) {
|
||||
output.print("static");
|
||||
output.space();
|
||||
print_braced(this.value, output);
|
||||
});
|
||||
|
||||
/* -----[ jumps ]----- */
|
||||
function print_jump(kind, prop) {
|
||||
@@ -1736,19 +1742,19 @@ function OutputStream(options) {
|
||||
var name = get_symbol_name(self);
|
||||
output.print_name(name);
|
||||
var alias = self.alias;
|
||||
if (alias != name) {
|
||||
if (alias.value != name) {
|
||||
output.space();
|
||||
output.print("as");
|
||||
output.space();
|
||||
output.print_name(alias);
|
||||
print_alias(alias, output);
|
||||
}
|
||||
});
|
||||
DEFPRINT(AST_SymbolImport, function(output) {
|
||||
var self = this;
|
||||
var name = get_symbol_name(self);
|
||||
var key = self.key;
|
||||
if (key && key != name) {
|
||||
output.print_name(key);
|
||||
if (key.value && key.value != name) {
|
||||
print_alias(key, output);
|
||||
output.space();
|
||||
output.print("as");
|
||||
output.space();
|
||||
@@ -1818,9 +1824,6 @@ function OutputStream(options) {
|
||||
case "\u2029": return "\\u2029";
|
||||
}
|
||||
}));
|
||||
var p = output.parent();
|
||||
if (p instanceof AST_Binary && /^in/.test(p.operator) && p.left === this)
|
||||
output.print(" ");
|
||||
});
|
||||
|
||||
function force_statement(stat, output) {
|
||||
|
||||
154
lib/parse.js
154
lib/parse.js
@@ -237,8 +237,7 @@ function tokenizer($TEXT, filename, html5_comments, shebang) {
|
||||
newline_before : false,
|
||||
regex_allowed : false,
|
||||
comments_before : [],
|
||||
directives : {},
|
||||
directive_stack : [],
|
||||
directives : Object.create(null),
|
||||
read_template : with_eof_error("Unterminated template literal", function(strings) {
|
||||
var s = "";
|
||||
for (;;) {
|
||||
@@ -553,16 +552,8 @@ function tokenizer($TEXT, filename, html5_comments, shebang) {
|
||||
|
||||
function handle_dot() {
|
||||
next();
|
||||
var ch = peek();
|
||||
if (ch == ".") {
|
||||
var op = ".";
|
||||
do {
|
||||
op += ".";
|
||||
next();
|
||||
} while (peek() == ".");
|
||||
return token("operator", op);
|
||||
}
|
||||
return is_digit(ch.charCodeAt(0)) ? read_num(".") : token("punc", ".");
|
||||
if (looking_at("..")) return token("operator", "." + next() + next());
|
||||
return is_digit(peek().charCodeAt(0)) ? read_num(".") : token("punc", ".");
|
||||
}
|
||||
|
||||
function read_word() {
|
||||
@@ -635,24 +626,19 @@ function tokenizer($TEXT, filename, html5_comments, shebang) {
|
||||
};
|
||||
|
||||
next_token.add_directive = function(directive) {
|
||||
S.directive_stack[S.directive_stack.length - 1].push(directive);
|
||||
if (S.directives[directive]) S.directives[directive]++;
|
||||
else S.directives[directive] = 1;
|
||||
S.directives[directive] = true;
|
||||
}
|
||||
|
||||
next_token.push_directives_stack = function() {
|
||||
S.directive_stack.push([]);
|
||||
S.directives = Object.create(S.directives);
|
||||
}
|
||||
|
||||
next_token.pop_directives_stack = function() {
|
||||
var directives = S.directive_stack.pop();
|
||||
for (var i = directives.length; --i >= 0;) {
|
||||
S.directives[directives[i]]--;
|
||||
}
|
||||
S.directives = Object.getPrototypeOf(S.directives);
|
||||
}
|
||||
|
||||
next_token.has_directive = function(directive) {
|
||||
return S.directives[directive] > 0;
|
||||
return !!S.directives[directive];
|
||||
}
|
||||
|
||||
return next_token;
|
||||
@@ -699,6 +685,7 @@ function parse($TEXT, options) {
|
||||
expression : false,
|
||||
filename : null,
|
||||
html5_comments : true,
|
||||
module : false,
|
||||
shebang : true,
|
||||
strict : false,
|
||||
toplevel : null,
|
||||
@@ -820,7 +807,7 @@ function parse($TEXT, options) {
|
||||
}
|
||||
}
|
||||
|
||||
var statement = embed_tokens(function() {
|
||||
var statement = embed_tokens(function(toplevel) {
|
||||
handle_regexp();
|
||||
switch (S.token.type) {
|
||||
case "string":
|
||||
@@ -859,15 +846,15 @@ function parse($TEXT, options) {
|
||||
if (S.in_async) return simple_statement();
|
||||
break;
|
||||
case "export":
|
||||
if (!toplevel && options.module !== "") unexpected();
|
||||
next();
|
||||
return export_();
|
||||
case "import":
|
||||
var token = peek();
|
||||
if (!(token.type == "punc" && /^[(.]$/.test(token.value))) {
|
||||
next();
|
||||
return import_();
|
||||
}
|
||||
break;
|
||||
if (token.type == "punc" && /^[(.]$/.test(token.value)) break;
|
||||
if (!toplevel && options.module !== "") unexpected();
|
||||
next();
|
||||
return import_();
|
||||
case "let":
|
||||
if (is_vardefs()) {
|
||||
next();
|
||||
@@ -1124,6 +1111,18 @@ function parse($TEXT, options) {
|
||||
}));
|
||||
continue;
|
||||
}
|
||||
if (fixed && is("punc", "{")) {
|
||||
props.push(new AST_ClassInit({
|
||||
start: start,
|
||||
value: new AST_ClassInitBlock({
|
||||
start: start,
|
||||
body: block_(),
|
||||
end: prev(),
|
||||
}),
|
||||
end: prev(),
|
||||
}));
|
||||
continue;
|
||||
}
|
||||
var internal = is("name") && /^#/.test(S.token.value);
|
||||
var key = as_property_key();
|
||||
if (is("punc", "(")) {
|
||||
@@ -1194,10 +1193,10 @@ function parse($TEXT, options) {
|
||||
}
|
||||
|
||||
function for_() {
|
||||
var await = is("name", "await") && next();
|
||||
var await_token = is("name", "await") && next();
|
||||
expect("(");
|
||||
var init = null;
|
||||
if (await || !is("punc", ";")) {
|
||||
if (await_token || !is("punc", ";")) {
|
||||
init = is("keyword", "const")
|
||||
? (next(), const_(true))
|
||||
: is("name", "let") && is_vardefs()
|
||||
@@ -1206,7 +1205,7 @@ function parse($TEXT, options) {
|
||||
? (next(), var_(true))
|
||||
: expression(true);
|
||||
var ctor;
|
||||
if (await) {
|
||||
if (await_token) {
|
||||
expect_token("name", "of");
|
||||
ctor = AST_ForAwaitOf;
|
||||
} else if (is("operator", "in")) {
|
||||
@@ -1340,11 +1339,11 @@ function parse($TEXT, options) {
|
||||
var loop = S.in_loop;
|
||||
var labels = S.labels;
|
||||
++S.in_function;
|
||||
S.in_directives = true;
|
||||
S.input.push_directives_stack();
|
||||
S.in_loop = 0;
|
||||
S.labels = [];
|
||||
if (is("punc", "{")) {
|
||||
S.in_directives = true;
|
||||
body = block_();
|
||||
value = null;
|
||||
} else {
|
||||
@@ -1412,7 +1411,7 @@ function parse($TEXT, options) {
|
||||
name: name,
|
||||
argnames: argnames,
|
||||
rest: argnames.rest || null,
|
||||
body: body
|
||||
body: body,
|
||||
});
|
||||
if (is_strict) {
|
||||
if (name) strict_verify_symbol(name);
|
||||
@@ -1435,28 +1434,41 @@ function parse($TEXT, options) {
|
||||
}
|
||||
|
||||
function is_alias() {
|
||||
return is("name") || is_identifier_string(S.token.value);
|
||||
return is("name") || is("string") || is_identifier_string(S.token.value);
|
||||
}
|
||||
|
||||
function make_string(token) {
|
||||
return new AST_String({
|
||||
start: token,
|
||||
quote: token.quote,
|
||||
value: token.value,
|
||||
end: token,
|
||||
});
|
||||
}
|
||||
|
||||
function as_path() {
|
||||
var path = S.token;
|
||||
expect_token("string");
|
||||
semicolon();
|
||||
return make_string(path);
|
||||
}
|
||||
|
||||
function export_() {
|
||||
if (is("operator", "*")) {
|
||||
var key = S.token;
|
||||
var alias = key;
|
||||
next();
|
||||
var alias = "*";
|
||||
if (is("name", "as")) {
|
||||
next();
|
||||
if (!is_alias()) expect_token("name");
|
||||
alias = S.token.value;
|
||||
alias = S.token;
|
||||
next();
|
||||
}
|
||||
expect_token("name", "from");
|
||||
var path = S.token;
|
||||
expect_token("string");
|
||||
semicolon();
|
||||
return new AST_ExportForeign({
|
||||
aliases: [ alias ],
|
||||
keys: [ "*" ],
|
||||
path: path.value,
|
||||
quote: path.quote,
|
||||
aliases: [ make_string(alias) ],
|
||||
keys: [ make_string(key) ],
|
||||
path: as_path(),
|
||||
});
|
||||
}
|
||||
if (is("punc", "{")) {
|
||||
@@ -1470,26 +1482,20 @@ function parse($TEXT, options) {
|
||||
if (is("name", "as")) {
|
||||
next();
|
||||
if (!is_alias()) expect_token("name");
|
||||
aliases.push(S.token.value);
|
||||
aliases.push(S.token);
|
||||
next();
|
||||
} else {
|
||||
aliases.push(key.value);
|
||||
aliases.push(key);
|
||||
}
|
||||
if (!is("punc", "}")) expect(",");
|
||||
}
|
||||
expect("}");
|
||||
if (is("name", "from")) {
|
||||
next();
|
||||
var path = S.token;
|
||||
expect_token("string");
|
||||
semicolon();
|
||||
return new AST_ExportForeign({
|
||||
aliases: aliases,
|
||||
keys: keys.map(function(token) {
|
||||
return token.value;
|
||||
}),
|
||||
path: path.value,
|
||||
quote: path.quote,
|
||||
aliases: aliases.map(make_string),
|
||||
keys: keys.map(make_string),
|
||||
path: as_path(),
|
||||
});
|
||||
}
|
||||
semicolon();
|
||||
@@ -1497,7 +1503,7 @@ function parse($TEXT, options) {
|
||||
properties: keys.map(function(token, index) {
|
||||
if (!is_token(token, "name")) token_error(token, "Name expected");
|
||||
var sym = _make_symbol(AST_SymbolExport, token);
|
||||
sym.alias = aliases[index];
|
||||
sym.alias = make_string(aliases[index]);
|
||||
return sym;
|
||||
}),
|
||||
});
|
||||
@@ -1587,26 +1593,42 @@ function parse($TEXT, options) {
|
||||
var all = null;
|
||||
var def = as_symbol(AST_SymbolImport, true);
|
||||
var props = null;
|
||||
if (def ? (def.key = "", is("punc", ",") && next()) : !is("string")) {
|
||||
var cont;
|
||||
if (def) {
|
||||
def.key = new AST_String({
|
||||
start: def.start,
|
||||
value: "",
|
||||
end: def.end,
|
||||
});
|
||||
if (cont = is("punc", ",")) next();
|
||||
} else {
|
||||
cont = !is("string");
|
||||
}
|
||||
if (cont) {
|
||||
if (is("operator", "*")) {
|
||||
var key = S.token;
|
||||
next();
|
||||
expect_token("name", "as");
|
||||
all = as_symbol(AST_SymbolImport);
|
||||
all.key = "*";
|
||||
all.key = make_string(key);
|
||||
} else {
|
||||
expect("{");
|
||||
props = [];
|
||||
while (is_alias()) {
|
||||
var alias;
|
||||
if (is_token(peek(), "name", "as")) {
|
||||
var key = S.token.value;
|
||||
var key = S.token;
|
||||
next();
|
||||
next();
|
||||
alias = as_symbol(AST_SymbolImport);
|
||||
alias.key = key;
|
||||
alias.key = make_string(key);
|
||||
} else {
|
||||
alias = as_symbol(AST_SymbolImport);
|
||||
alias.key = alias.name;
|
||||
alias.key = new AST_String({
|
||||
start: alias.start,
|
||||
value: alias.name,
|
||||
end: alias.end,
|
||||
});
|
||||
}
|
||||
props.push(alias);
|
||||
if (!is("punc", "}")) expect(",");
|
||||
@@ -1615,15 +1637,11 @@ function parse($TEXT, options) {
|
||||
}
|
||||
}
|
||||
if (all || def || props) expect_token("name", "from");
|
||||
var path = S.token;
|
||||
expect_token("string");
|
||||
semicolon();
|
||||
return new AST_Import({
|
||||
all: all,
|
||||
default: def,
|
||||
path: path.value,
|
||||
path: as_path(),
|
||||
properties: props,
|
||||
quote: path.quote,
|
||||
});
|
||||
}
|
||||
|
||||
@@ -1801,7 +1819,7 @@ function parse($TEXT, options) {
|
||||
ret = new AST_BigInt({ value: value });
|
||||
break;
|
||||
case "string":
|
||||
ret = new AST_String({ value : value, quote : tok.quote });
|
||||
ret = new AST_String({ value: value, quote: tok.quote });
|
||||
break;
|
||||
case "regexp":
|
||||
ret = new AST_RegExp({ value: value });
|
||||
@@ -2550,9 +2568,13 @@ function parse($TEXT, options) {
|
||||
return function() {
|
||||
var start = S.token;
|
||||
var body = [];
|
||||
if (options.module) {
|
||||
S.in_async = true;
|
||||
S.input.add_directive("use strict");
|
||||
}
|
||||
S.input.push_directives_stack();
|
||||
while (!is("eof"))
|
||||
body.push(statement());
|
||||
body.push(statement(true));
|
||||
S.input.pop_directives_stack();
|
||||
var end = prev() || start;
|
||||
var toplevel = options.toplevel;
|
||||
|
||||
29
lib/scope.js
29
lib/scope.js
@@ -64,19 +64,20 @@ SymbolDef.prototype = {
|
||||
this.references.forEach(fn);
|
||||
},
|
||||
mangle: function(options) {
|
||||
var cache = options.cache && options.cache.props;
|
||||
if (this.global && cache && cache.has(this.name)) {
|
||||
if (this.mangled_name) return;
|
||||
var cache = this.global && options.cache && options.cache.props;
|
||||
if (cache && cache.has(this.name)) {
|
||||
this.mangled_name = cache.get(this.name);
|
||||
} else if (!this.mangled_name && !this.unmangleable(options)) {
|
||||
} else if (this.unmangleable(options)) {
|
||||
names_in_use(this.scope, options).set(this.name, true);
|
||||
} else {
|
||||
var def = this.redefined();
|
||||
if (def) {
|
||||
this.mangled_name = def.mangled_name || def.name;
|
||||
} else {
|
||||
this.mangled_name = next_mangled_name(this, options);
|
||||
}
|
||||
if (this.global && cache) {
|
||||
cache.set(this.name, this.mangled_name);
|
||||
}
|
||||
if (cache) cache.set(this.name, this.mangled_name);
|
||||
}
|
||||
},
|
||||
redefined: function() {
|
||||
@@ -226,7 +227,7 @@ AST_Toplevel.DEFMETHOD("figure_out_scope", function(options) {
|
||||
defun.def_variable(node);
|
||||
} else if (node instanceof AST_SymbolLambda) {
|
||||
var def = defun.def_function(node, node.name == "arguments" ? undefined : defun);
|
||||
if (options.ie) def.defun = defun.parent_scope.resolve();
|
||||
if (options.ie && node.name != "arguments") def.defun = defun.parent_scope.resolve();
|
||||
} else if (node instanceof AST_SymbolLet) {
|
||||
var def = scope.def_variable(node);
|
||||
if (exported) def.exported = true;
|
||||
@@ -469,6 +470,7 @@ AST_Lambda.DEFMETHOD("init_vars", function(parent_scope) {
|
||||
this.uses_arguments = false;
|
||||
this.def_variable(new AST_SymbolFunarg({
|
||||
name: "arguments",
|
||||
scope: this,
|
||||
start: this.start,
|
||||
end: this.end,
|
||||
}));
|
||||
@@ -616,18 +618,14 @@ AST_Toplevel.DEFMETHOD("mangle_names", function(options) {
|
||||
mangled_names.set(mangled_name, true);
|
||||
});
|
||||
}
|
||||
var cutoff = 10;
|
||||
var cutoff = 36;
|
||||
var lname = -1;
|
||||
var redefined = [];
|
||||
var tw = new TreeWalker(function(node, descend) {
|
||||
if (node instanceof AST_LabeledStatement) {
|
||||
// `lname` is incremented when we get to the `AST_Label`
|
||||
var save_nesting = lname;
|
||||
descend();
|
||||
if (!options.v8 || !in_label(tw)) lname = save_nesting;
|
||||
return true;
|
||||
}
|
||||
var save_nesting;
|
||||
if (node instanceof AST_BlockScope) {
|
||||
// `lname` is incremented when we get to the `AST_Label`
|
||||
if (node instanceof AST_LabeledStatement) save_nesting = lname;
|
||||
if (options.webkit && node instanceof AST_IterationStatement && node.init instanceof AST_Let) {
|
||||
node.init.definitions.forEach(function(defn) {
|
||||
defn.name.match_symbol(function(sym) {
|
||||
@@ -673,6 +671,7 @@ AST_Toplevel.DEFMETHOD("mangle_names", function(options) {
|
||||
}));
|
||||
}
|
||||
to_mangle.forEach(mangle);
|
||||
if (node instanceof AST_LabeledStatement && !(options.v8 && in_label(tw))) lname = save_nesting;
|
||||
return true;
|
||||
}
|
||||
if (node instanceof AST_Label) {
|
||||
|
||||
@@ -55,14 +55,6 @@ function find_if(func, array) {
|
||||
for (var i = array.length; --i >= 0;) if (func(array[i])) return array[i];
|
||||
}
|
||||
|
||||
function repeat_string(str, i) {
|
||||
if (i <= 0) return "";
|
||||
if (i == 1) return str;
|
||||
var d = repeat_string(str, i >> 1);
|
||||
d += d;
|
||||
return i & 1 ? d + str : d;
|
||||
}
|
||||
|
||||
function configure_error_stack(fn) {
|
||||
Object.defineProperty(fn.prototype, "stack", {
|
||||
get: function() {
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
"description": "JavaScript parser, mangler/compressor and beautifier toolkit",
|
||||
"author": "Mihai Bazon <mihai.bazon@gmail.com> (http://lisperator.net/)",
|
||||
"license": "BSD-2-Clause",
|
||||
"version": "3.15.0",
|
||||
"version": "3.16.3",
|
||||
"engines": {
|
||||
"node": ">=0.8.0"
|
||||
},
|
||||
@@ -23,7 +23,7 @@
|
||||
"LICENSE"
|
||||
],
|
||||
"devDependencies": {
|
||||
"acorn": "~8.2.1",
|
||||
"acorn": "~8.7.1",
|
||||
"semver": "~6.3.0"
|
||||
},
|
||||
"scripts": {
|
||||
|
||||
@@ -17,6 +17,7 @@ var urls = [
|
||||
"https://unpkg.com/mathjs@6.2.3/dist/math.js",
|
||||
"https://unpkg.com/react@15.3.2/dist/react.js",
|
||||
"https://cdnjs.cloudflare.com/ajax/libs/d3/6.7.0/d3.js",
|
||||
"https://cdnjs.cloudflare.com/ajax/libs/antd/4.18.7/antd.js",
|
||||
"https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.js",
|
||||
"https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.15/lodash.js",
|
||||
"https://cdnjs.cloudflare.com/ajax/libs/ember.js/2.12.2/ember.prod.js",
|
||||
|
||||
@@ -69,9 +69,7 @@ function make_code(ast, options) {
|
||||
function parse_test(file) {
|
||||
var script = fs.readFileSync(file, "utf8");
|
||||
try {
|
||||
var ast = U.parse(script, {
|
||||
filename: file
|
||||
});
|
||||
var ast = U.parse(script, { filename: file, module: "" });
|
||||
} catch (e) {
|
||||
console.error("Caught error while parsing tests in " + file);
|
||||
console.error(e);
|
||||
@@ -98,14 +96,14 @@ function parse_test(file) {
|
||||
file: file,
|
||||
line: node.start.line,
|
||||
col: node.start.col,
|
||||
code: make_code(node, { beautify: false })
|
||||
code: make_code(node, { beautify: false }),
|
||||
}));
|
||||
}
|
||||
|
||||
function read_string(stat) {
|
||||
if (stat.TYPE == "SimpleStatement") {
|
||||
var body = stat.body;
|
||||
switch(body.TYPE) {
|
||||
switch (body.TYPE) {
|
||||
case "String":
|
||||
return body.value;
|
||||
case "Array":
|
||||
@@ -142,7 +140,7 @@ function parse_test(file) {
|
||||
].indexOf(label.name) >= 0, tmpl("Unsupported label {name} [{line},{col}]", {
|
||||
name: label.name,
|
||||
line: label.start.line,
|
||||
col: label.start.col
|
||||
col: label.start.col,
|
||||
}));
|
||||
var stat = node.body;
|
||||
if (label.name == "expect_exact" || label.name == "node_version") {
|
||||
@@ -155,12 +153,12 @@ function parse_test(file) {
|
||||
var ctor = global[body.expression.name];
|
||||
assert.ok(ctor === Error || ctor.prototype instanceof Error, tmpl("Unsupported expect_stdout format [{line},{col}]", {
|
||||
line: label.start.line,
|
||||
col: label.start.col
|
||||
col: label.start.col,
|
||||
}));
|
||||
test[label.name] = ctor.apply(null, body.args.map(function(node) {
|
||||
assert.ok(node instanceof U.AST_Constant, tmpl("Unsupported expect_stdout format [{line},{col}]", {
|
||||
line: label.start.line,
|
||||
col: label.start.col
|
||||
col: label.start.col,
|
||||
}));
|
||||
return node.value;
|
||||
}));
|
||||
@@ -183,13 +181,11 @@ function parse_test(file) {
|
||||
function reminify(orig_options, input_code, input_formatted, stdout) {
|
||||
for (var i = 0; i < minify_options.length; i++) {
|
||||
var options = JSON.parse(minify_options[i]);
|
||||
if (options.compress) [
|
||||
[
|
||||
"keep_fargs",
|
||||
"keep_fnames",
|
||||
].forEach(function(name) {
|
||||
if (name in orig_options) {
|
||||
options.compress[name] = orig_options[name];
|
||||
}
|
||||
if (name in orig_options) options[name] = orig_options[name];
|
||||
});
|
||||
var options_formatted = JSON.stringify(options, null, 4);
|
||||
options.validate = true;
|
||||
|
||||
@@ -927,3 +927,288 @@ issue_5251: {
|
||||
expect_stdout: true
|
||||
node_version: ">=4"
|
||||
}
|
||||
|
||||
issue_5342_1: {
|
||||
options = {
|
||||
dead_code: true,
|
||||
inline: true,
|
||||
toplevel: true,
|
||||
unused: true,
|
||||
}
|
||||
input: {
|
||||
for (var a in 0) {
|
||||
(() => {
|
||||
while (1);
|
||||
})(new function(NaN) {
|
||||
a.p;
|
||||
}());
|
||||
}
|
||||
console.log(function() {
|
||||
return b;
|
||||
try {
|
||||
b;
|
||||
} catch (e) {
|
||||
var b;
|
||||
}
|
||||
}());
|
||||
}
|
||||
expect: {
|
||||
for (var a in 0) {
|
||||
(function(NaN) {
|
||||
a.p;
|
||||
})();
|
||||
while (1);
|
||||
}
|
||||
console.log(b);
|
||||
var b;
|
||||
}
|
||||
expect_stdout: "undefined"
|
||||
node_version: ">=4"
|
||||
}
|
||||
|
||||
issue_5342_2: {
|
||||
rename = true
|
||||
options = {
|
||||
dead_code: true,
|
||||
inline: true,
|
||||
toplevel: true,
|
||||
unused: true,
|
||||
}
|
||||
input: {
|
||||
for (var a in 0) {
|
||||
(() => {
|
||||
while (1);
|
||||
})(new function(NaN) {
|
||||
a.p;
|
||||
}());
|
||||
}
|
||||
console.log(function() {
|
||||
return b;
|
||||
try {
|
||||
b;
|
||||
} catch (e) {
|
||||
var b;
|
||||
}
|
||||
}());
|
||||
}
|
||||
expect: {
|
||||
for (var a in 0) {
|
||||
a.p;
|
||||
while (1);
|
||||
}
|
||||
console.log(c);
|
||||
var c;
|
||||
}
|
||||
expect_stdout: "undefined"
|
||||
node_version: ">=4"
|
||||
}
|
||||
|
||||
issue_5356: {
|
||||
options = {
|
||||
evaluate: true,
|
||||
reduce_vars: true,
|
||||
unused: true,
|
||||
}
|
||||
input: {
|
||||
console.log((a => a++)(console));
|
||||
}
|
||||
expect: {
|
||||
console.log((a => +a)(console));
|
||||
}
|
||||
expect_stdout: "NaN"
|
||||
node_version: ">=4"
|
||||
}
|
||||
|
||||
issue_5414_1: {
|
||||
options = {
|
||||
arrows: true,
|
||||
if_return: true,
|
||||
inline: true,
|
||||
toplevel: true,
|
||||
}
|
||||
input: {
|
||||
(() => {
|
||||
(() => {
|
||||
if (!console)
|
||||
var arguments = 42;
|
||||
while (console.log(arguments));
|
||||
})();
|
||||
})();
|
||||
}
|
||||
expect: {
|
||||
(() => {
|
||||
if (!console)
|
||||
var arguments = 42;
|
||||
while (console.log(arguments));
|
||||
})();
|
||||
}
|
||||
expect_stdout: true
|
||||
node_version: ">=4"
|
||||
}
|
||||
|
||||
issue_5414_2: {
|
||||
options = {
|
||||
arrows: true,
|
||||
inline: true,
|
||||
side_effects: true,
|
||||
toplevel: true,
|
||||
}
|
||||
input: {
|
||||
(() => {
|
||||
(() => {
|
||||
if (!console)
|
||||
var arguments = 42;
|
||||
while (console.log(arguments));
|
||||
})();
|
||||
})();
|
||||
}
|
||||
expect: {
|
||||
(() => {
|
||||
if (!console)
|
||||
var arguments = 42;
|
||||
while (console.log(arguments));
|
||||
})();
|
||||
}
|
||||
expect_stdout: true
|
||||
node_version: ">=4"
|
||||
}
|
||||
|
||||
issue_5416_1: {
|
||||
options = {
|
||||
dead_code: true,
|
||||
evaluate: true,
|
||||
inline: true,
|
||||
loops: true,
|
||||
unused: true,
|
||||
}
|
||||
input: {
|
||||
var f = () => {
|
||||
while ((() => {
|
||||
console;
|
||||
var a = function g(arguments) {
|
||||
console.log(arguments);
|
||||
}();
|
||||
})());
|
||||
};
|
||||
f();
|
||||
}
|
||||
expect: {
|
||||
var f = () => {
|
||||
{
|
||||
console;
|
||||
arguments = void 0,
|
||||
console.log(arguments);
|
||||
var arguments;
|
||||
return;
|
||||
}
|
||||
};
|
||||
f();
|
||||
}
|
||||
expect_stdout: "undefined"
|
||||
node_version: ">=4"
|
||||
}
|
||||
|
||||
issue_5416_2: {
|
||||
options = {
|
||||
dead_code: true,
|
||||
evaluate: true,
|
||||
inline: true,
|
||||
loops: true,
|
||||
unused: true,
|
||||
}
|
||||
input: {
|
||||
var f = () => {
|
||||
while ((() => {
|
||||
console;
|
||||
var a = function g(arguments) {
|
||||
while (console.log(arguments));
|
||||
}();
|
||||
})());
|
||||
};
|
||||
f();
|
||||
}
|
||||
expect: {
|
||||
var f = () => {
|
||||
{
|
||||
console;
|
||||
var arguments = void 0;
|
||||
for (; console.log(arguments););
|
||||
return;
|
||||
}
|
||||
};
|
||||
f();
|
||||
}
|
||||
expect_stdout: "undefined"
|
||||
node_version: ">=4"
|
||||
}
|
||||
|
||||
issue_5416_3: {
|
||||
options = {
|
||||
inline: true,
|
||||
side_effects: true,
|
||||
unused: true,
|
||||
}
|
||||
input: {
|
||||
var f = () => {
|
||||
(() => {
|
||||
var a = function g(arguments) {
|
||||
console.log(arguments);
|
||||
}();
|
||||
})();
|
||||
};
|
||||
f();
|
||||
}
|
||||
expect: {
|
||||
var f = () => {
|
||||
arguments = void 0,
|
||||
console.log(arguments);
|
||||
var arguments;
|
||||
};
|
||||
f();
|
||||
}
|
||||
expect_stdout: "undefined"
|
||||
node_version: ">=4"
|
||||
}
|
||||
|
||||
issue_5416_4: {
|
||||
options = {
|
||||
arrows: true,
|
||||
inline: true,
|
||||
side_effects: true,
|
||||
unused: true,
|
||||
}
|
||||
input: {
|
||||
var f = () => {
|
||||
(() => {
|
||||
var a = function g(arguments) {
|
||||
while (console.log(arguments));
|
||||
}();
|
||||
})();
|
||||
};
|
||||
f();
|
||||
}
|
||||
expect: {
|
||||
var f = () => {
|
||||
var arguments = void 0;
|
||||
while (console.log(arguments));
|
||||
return;
|
||||
};
|
||||
f();
|
||||
}
|
||||
expect_stdout: "undefined"
|
||||
node_version: ">=4"
|
||||
}
|
||||
|
||||
issue_5495: {
|
||||
input: {
|
||||
console.log((() => {
|
||||
"use strict";
|
||||
return function() {
|
||||
return this;
|
||||
}();
|
||||
})());
|
||||
}
|
||||
expect_exact: 'console.log((()=>{"use strict";return function(){return this}()})());'
|
||||
expect_stdout: "undefined"
|
||||
node_version: ">=4"
|
||||
}
|
||||
|
||||
@@ -673,8 +673,7 @@ issue_4827_1: {
|
||||
c &&= b = a, console.log(b);
|
||||
}
|
||||
expect: {
|
||||
A = "FAIL";
|
||||
var a = A, b = "PASS", c;
|
||||
var a = A = "FAIL", b = "PASS", c;
|
||||
c &&= b = a, console.log(b);
|
||||
}
|
||||
expect_stdout: "PASS"
|
||||
|
||||
@@ -1046,6 +1046,60 @@ collapse_vars_3: {
|
||||
node_version: ">=8"
|
||||
}
|
||||
|
||||
collapse_funarg_1: {
|
||||
options = {
|
||||
collapse_vars: true,
|
||||
unused: true,
|
||||
}
|
||||
input: {
|
||||
A = "FAIL";
|
||||
var a = "PASS";
|
||||
(async function({}, b) {
|
||||
return b;
|
||||
})(null, A = a);
|
||||
console.log(A);
|
||||
}
|
||||
expect: {
|
||||
A = "FAIL";
|
||||
var a = "PASS";
|
||||
(async function({}, b) {
|
||||
return b;
|
||||
})(null, A = a);
|
||||
console.log(A);
|
||||
}
|
||||
expect_stdout: "PASS"
|
||||
node_version: ">=8"
|
||||
}
|
||||
|
||||
collapse_funarg_2: {
|
||||
options = {
|
||||
collapse_vars: true,
|
||||
unused: true,
|
||||
}
|
||||
input: {
|
||||
A = "FAIL";
|
||||
B = "PASS";
|
||||
(async function() {
|
||||
console.log(function({}, a) {
|
||||
return a;
|
||||
}(null, A = B));
|
||||
})();
|
||||
console.log(A);
|
||||
}
|
||||
expect: {
|
||||
A = "FAIL";
|
||||
B = "PASS";
|
||||
(async function() {
|
||||
console.log(function({}, a) {
|
||||
return a;
|
||||
}(null, A = B));
|
||||
})();
|
||||
console.log(A);
|
||||
}
|
||||
expect_stdout: "PASS"
|
||||
node_version: ">=8"
|
||||
}
|
||||
|
||||
collapse_property_lambda: {
|
||||
options = {
|
||||
collapse_vars: true,
|
||||
@@ -1293,6 +1347,21 @@ functions_inner_var: {
|
||||
node_version: ">=8"
|
||||
}
|
||||
|
||||
instanceof_lambda: {
|
||||
options = {
|
||||
evaluate: true,
|
||||
side_effects: true,
|
||||
}
|
||||
input: {
|
||||
console.log(42 instanceof async function() {});
|
||||
}
|
||||
expect: {
|
||||
console.log(false);
|
||||
}
|
||||
expect_stdout: "false"
|
||||
node_version: ">=8"
|
||||
}
|
||||
|
||||
issue_4335_1: {
|
||||
options = {
|
||||
inline: true,
|
||||
@@ -1748,8 +1817,8 @@ issue_4454_2: {
|
||||
expect: {
|
||||
function f(a) {
|
||||
(async function(c = console.log(a)) {})();
|
||||
var a = 42..toString();
|
||||
console.log(a);
|
||||
var b = 42..toString();
|
||||
console.log(b);
|
||||
}
|
||||
f("PASS");
|
||||
}
|
||||
@@ -2427,80 +2496,6 @@ issue_5023_2: {
|
||||
node_version: ">=8"
|
||||
}
|
||||
|
||||
issue_5032_normal: {
|
||||
options = {
|
||||
merge_vars: true,
|
||||
webkit: false,
|
||||
}
|
||||
input: {
|
||||
function log(value) {
|
||||
console.log(value);
|
||||
return value;
|
||||
}
|
||||
async function f(a) {
|
||||
var b = log(a), c = b;
|
||||
log(b);
|
||||
log(c);
|
||||
}
|
||||
f("PASS");
|
||||
}
|
||||
expect: {
|
||||
function log(value) {
|
||||
console.log(value);
|
||||
return value;
|
||||
}
|
||||
async function f(a) {
|
||||
var a = log(a), c = a;
|
||||
log(a);
|
||||
log(c);
|
||||
}
|
||||
f("PASS");
|
||||
}
|
||||
expect_stdout: [
|
||||
"PASS",
|
||||
"PASS",
|
||||
"PASS",
|
||||
]
|
||||
node_version: ">=8"
|
||||
}
|
||||
|
||||
issue_5032_webkit: {
|
||||
options = {
|
||||
merge_vars: true,
|
||||
webkit: true,
|
||||
}
|
||||
input: {
|
||||
function log(value) {
|
||||
console.log(value);
|
||||
return value;
|
||||
}
|
||||
async function f(a) {
|
||||
var b = log(a), c = b;
|
||||
log(b);
|
||||
log(c);
|
||||
}
|
||||
f("PASS");
|
||||
}
|
||||
expect: {
|
||||
function log(value) {
|
||||
console.log(value);
|
||||
return value;
|
||||
}
|
||||
async function f(a) {
|
||||
var b = log(a), c = b;
|
||||
log(b);
|
||||
log(c);
|
||||
}
|
||||
f("PASS");
|
||||
}
|
||||
expect_stdout: [
|
||||
"PASS",
|
||||
"PASS",
|
||||
"PASS",
|
||||
]
|
||||
node_version: ">=8"
|
||||
}
|
||||
|
||||
issue_5034: {
|
||||
options = {
|
||||
functions: true,
|
||||
@@ -2959,3 +2954,278 @@ issue_5305_3: {
|
||||
expect_stdout: "PASS"
|
||||
node_version: ">=8"
|
||||
}
|
||||
|
||||
issue_5456: {
|
||||
options = {
|
||||
inline: true,
|
||||
merge_vars: true,
|
||||
}
|
||||
input: {
|
||||
var a = true;
|
||||
(function() {
|
||||
(function(b, c) {
|
||||
var d = async function() {
|
||||
c = await null;
|
||||
}();
|
||||
var e = function() {
|
||||
if (c)
|
||||
console.log(typeof d);
|
||||
while (b);
|
||||
}();
|
||||
})(function(i) {
|
||||
return console.log("foo") && i;
|
||||
}(a));
|
||||
})();
|
||||
}
|
||||
expect: {
|
||||
var a = true;
|
||||
(function() {
|
||||
b = (i = a, console.log("foo") && i),
|
||||
d = async function() {
|
||||
c = await null;
|
||||
}(),
|
||||
e = function() {
|
||||
if (c) console.log(typeof d);
|
||||
while (b);
|
||||
}(),
|
||||
void 0;
|
||||
var b, c, d, e;
|
||||
var i;
|
||||
})();
|
||||
}
|
||||
expect_stdout: "foo"
|
||||
node_version: ">=8"
|
||||
}
|
||||
|
||||
issue_5478: {
|
||||
options = {
|
||||
side_effects: true,
|
||||
}
|
||||
input: {
|
||||
A = {
|
||||
get then() {
|
||||
a = "FAIL";
|
||||
},
|
||||
};
|
||||
var a = "PASS";
|
||||
(async function() {
|
||||
for (var b in "foo")
|
||||
return void A;
|
||||
})();
|
||||
console.log(a);
|
||||
}
|
||||
expect: {
|
||||
A = {
|
||||
get then() {
|
||||
a = "FAIL";
|
||||
},
|
||||
};
|
||||
var a = "PASS";
|
||||
(async function() {
|
||||
for (var b in "foo")
|
||||
return !A;
|
||||
})();
|
||||
console.log(a);
|
||||
}
|
||||
expect_stdout: "PASS"
|
||||
node_version: ">=8"
|
||||
}
|
||||
|
||||
issue_5493: {
|
||||
options = {
|
||||
collapse_vars: true,
|
||||
reduce_vars: true,
|
||||
}
|
||||
input: {
|
||||
(async function(a) {
|
||||
var b = await [ 42 || b, a = b ];
|
||||
console.log(a);
|
||||
})();
|
||||
}
|
||||
expect: {
|
||||
(async function(a) {
|
||||
var b = await [ 42 || b, a = b ];
|
||||
console.log(a);
|
||||
})();
|
||||
}
|
||||
expect_stdout: "undefined"
|
||||
node_version: ">=8"
|
||||
}
|
||||
|
||||
issue_5506: {
|
||||
options = {
|
||||
dead_code: true,
|
||||
}
|
||||
input: {
|
||||
console.log(function(a) {
|
||||
(async function() {
|
||||
a = null in (a = "PASS");
|
||||
})();
|
||||
return a;
|
||||
}("FAIL"));
|
||||
}
|
||||
expect: {
|
||||
console.log(function(a) {
|
||||
(async function() {
|
||||
a = null in (a = "PASS");
|
||||
})();
|
||||
return a;
|
||||
}("FAIL"));
|
||||
}
|
||||
expect_stdout: "PASS"
|
||||
node_version: ">=8"
|
||||
}
|
||||
|
||||
issue_5528_1: {
|
||||
options = {
|
||||
inline: true,
|
||||
}
|
||||
input: {
|
||||
(async function() {
|
||||
await function() {
|
||||
try {
|
||||
return;
|
||||
} finally {
|
||||
console.log("foo");
|
||||
}
|
||||
}();
|
||||
})();
|
||||
console.log("bar");
|
||||
}
|
||||
expect: {
|
||||
(async function() {
|
||||
await function() {
|
||||
try {
|
||||
return;
|
||||
} finally {
|
||||
console.log("foo");
|
||||
}
|
||||
}();
|
||||
})();
|
||||
console.log("bar");
|
||||
}
|
||||
expect_stdout: [
|
||||
"foo",
|
||||
"bar",
|
||||
]
|
||||
node_version: ">=8"
|
||||
}
|
||||
|
||||
issue_5528_2: {
|
||||
options = {
|
||||
inline: true,
|
||||
}
|
||||
input: {
|
||||
(async function() {
|
||||
await function() {
|
||||
try {
|
||||
return 42;
|
||||
} finally {
|
||||
console.log("foo");
|
||||
}
|
||||
}();
|
||||
})();
|
||||
console.log("bar");
|
||||
}
|
||||
expect: {
|
||||
(async function() {
|
||||
await function() {
|
||||
try {
|
||||
return 42;
|
||||
} finally {
|
||||
console.log("foo");
|
||||
}
|
||||
}();
|
||||
})();
|
||||
console.log("bar");
|
||||
}
|
||||
expect_stdout: [
|
||||
"foo",
|
||||
"bar",
|
||||
]
|
||||
node_version: ">=8"
|
||||
}
|
||||
|
||||
issue_5528_3: {
|
||||
options = {
|
||||
inline: true,
|
||||
}
|
||||
input: {
|
||||
(async function() {
|
||||
await function() {
|
||||
try {
|
||||
FAIL;
|
||||
} catch (e) {
|
||||
return console.log("foo");
|
||||
} finally {
|
||||
console.log("bar");
|
||||
}
|
||||
}();
|
||||
})();
|
||||
console.log("baz");
|
||||
}
|
||||
expect: {
|
||||
(async function() {
|
||||
await function() {
|
||||
try {
|
||||
FAIL;
|
||||
} catch (e) {
|
||||
return console.log("foo");
|
||||
} finally {
|
||||
console.log("bar");
|
||||
}
|
||||
}();
|
||||
})();
|
||||
console.log("baz");
|
||||
}
|
||||
expect_stdout: [
|
||||
"foo",
|
||||
"bar",
|
||||
"baz",
|
||||
]
|
||||
node_version: ">=8"
|
||||
}
|
||||
|
||||
issue_5528_4: {
|
||||
options = {
|
||||
inline: true,
|
||||
}
|
||||
input: {
|
||||
(async function() {
|
||||
await function() {
|
||||
try {
|
||||
return {
|
||||
then() {
|
||||
console.log("foo");
|
||||
},
|
||||
};
|
||||
} finally {
|
||||
console.log("bar");
|
||||
}
|
||||
}();
|
||||
})();
|
||||
console.log("baz");
|
||||
}
|
||||
expect: {
|
||||
(async function() {
|
||||
await function() {
|
||||
try {
|
||||
return {
|
||||
then() {
|
||||
console.log("foo");
|
||||
},
|
||||
};
|
||||
} finally {
|
||||
console.log("bar");
|
||||
}
|
||||
}();
|
||||
})();
|
||||
console.log("baz");
|
||||
}
|
||||
expect_stdout: [
|
||||
"bar",
|
||||
"baz",
|
||||
"foo",
|
||||
]
|
||||
node_version: ">=8"
|
||||
}
|
||||
|
||||
@@ -427,6 +427,44 @@ negated_if: {
|
||||
expect_stdout: "PASS"
|
||||
}
|
||||
|
||||
concat_truthy: {
|
||||
options = {
|
||||
booleans: true,
|
||||
evaluate: true,
|
||||
}
|
||||
input: {
|
||||
console.log("foo") + (console.log("bar"), "baz") || console.log("moo");
|
||||
}
|
||||
expect: {
|
||||
console.log("foo") + (console.log("bar"), "baz");
|
||||
}
|
||||
expect_stdout: [
|
||||
"foo",
|
||||
"bar",
|
||||
]
|
||||
expect_warnings: [
|
||||
"WARN: + in boolean context always true [test/compress/booleans.js:1,8]",
|
||||
"WARN: Condition left of || always true [test/compress/booleans.js:1,8]",
|
||||
]
|
||||
}
|
||||
|
||||
process_returns: {
|
||||
options = {
|
||||
booleans: true,
|
||||
}
|
||||
input: {
|
||||
(function() {
|
||||
return 42;
|
||||
})() && console.log("PASS");
|
||||
}
|
||||
expect: {
|
||||
(function() {
|
||||
return 42;
|
||||
})() && console.log("PASS");
|
||||
}
|
||||
expect_stdout: "PASS"
|
||||
}
|
||||
|
||||
issue_3465_1: {
|
||||
options = {
|
||||
booleans: true,
|
||||
@@ -724,3 +762,27 @@ issue_5228: {
|
||||
}
|
||||
expect_stdout: "true"
|
||||
}
|
||||
|
||||
issue_5469: {
|
||||
options = {
|
||||
assignments: true,
|
||||
booleans: true,
|
||||
conditionals: true,
|
||||
dead_code: true,
|
||||
evaluate: true,
|
||||
pure_getters: "strict",
|
||||
side_effects: true,
|
||||
}
|
||||
input: {
|
||||
console.log(function f(a) {
|
||||
a && 42[a = A && null];
|
||||
}());
|
||||
}
|
||||
expect: {
|
||||
console.log(function f(a) {
|
||||
a && A,
|
||||
0;
|
||||
}());
|
||||
}
|
||||
expect_stdout: "undefined"
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -2579,7 +2579,7 @@ side_effects_property: {
|
||||
expect_stdout: true
|
||||
}
|
||||
|
||||
undeclared: {
|
||||
undeclared_1: {
|
||||
options = {
|
||||
collapse_vars: true,
|
||||
unused: true,
|
||||
@@ -2594,8 +2594,68 @@ undeclared: {
|
||||
}
|
||||
expect: {
|
||||
function f(x, y) {
|
||||
return (b = y) + x;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
undeclared_2: {
|
||||
options = {
|
||||
collapse_vars: true,
|
||||
unused: true,
|
||||
}
|
||||
input: {
|
||||
function f(x, y) {
|
||||
var a;
|
||||
a = x;
|
||||
b = y;
|
||||
return b + x;
|
||||
return a + b;
|
||||
}
|
||||
}
|
||||
expect: {
|
||||
function f(x, y) {
|
||||
return x + (b = y);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
undeclared_3: {
|
||||
options = {
|
||||
collapse_vars: true,
|
||||
unused: true,
|
||||
}
|
||||
input: {
|
||||
function f(x, y) {
|
||||
var a;
|
||||
a = x;
|
||||
b = y;
|
||||
return b + a();
|
||||
}
|
||||
}
|
||||
expect: {
|
||||
function f(x, y) {
|
||||
return (b = y) + x();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
undeclared_4: {
|
||||
options = {
|
||||
collapse_vars: true,
|
||||
unused: true,
|
||||
}
|
||||
input: {
|
||||
function f(x, y) {
|
||||
var a;
|
||||
a = x;
|
||||
b = y;
|
||||
return a() + b;
|
||||
}
|
||||
}
|
||||
expect: {
|
||||
function f(x, y) {
|
||||
b = y;
|
||||
return x() + b;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2987,9 +3047,8 @@ compound_assignment_4: {
|
||||
console.log(a);
|
||||
}
|
||||
expect: {
|
||||
A = "PASS";
|
||||
var a = "";
|
||||
(a += (a = "FAIL", A)).p;
|
||||
(a += (a = "FAIL", A = "PASS")).p;
|
||||
console.log(a);
|
||||
}
|
||||
expect_stdout: "PASS"
|
||||
@@ -8955,6 +9014,27 @@ collapse_and_assign: {
|
||||
expect_stdout: "PASS"
|
||||
}
|
||||
|
||||
collapse_and_assign_property: {
|
||||
options = {
|
||||
collapse_vars: true,
|
||||
pure_getters: "strict",
|
||||
reduce_vars: true,
|
||||
unused: true,
|
||||
}
|
||||
input: {
|
||||
console.log(function f() {
|
||||
f && (f.p = "PASS");
|
||||
return f.p;
|
||||
}());
|
||||
}
|
||||
expect: {
|
||||
console.log(function f() {
|
||||
return f.p = f ? "PASS" : f.p;
|
||||
}());
|
||||
}
|
||||
expect_stdout: "PASS"
|
||||
}
|
||||
|
||||
collapse_or_assign: {
|
||||
options = {
|
||||
collapse_vars: true,
|
||||
@@ -8972,7 +9052,7 @@ collapse_or_assign: {
|
||||
var a = {
|
||||
p: "PASS",
|
||||
};
|
||||
log(a = !a.q ? a.p : a);
|
||||
log(a = a.q ? a: a.p);
|
||||
}
|
||||
expect_stdout: "PASS"
|
||||
}
|
||||
@@ -9845,3 +9925,79 @@ issue_5309_2: {
|
||||
}
|
||||
expect_stdout: "PASS"
|
||||
}
|
||||
|
||||
issue_5394: {
|
||||
options = {
|
||||
collapse_vars: true,
|
||||
evaluate: true,
|
||||
}
|
||||
input: {
|
||||
try {
|
||||
throw A.p = (console.log("FAIL"), []), !1;
|
||||
} catch (e) {
|
||||
console.log(typeof e);
|
||||
}
|
||||
}
|
||||
expect: {
|
||||
try {
|
||||
throw !(A.p = (console.log("FAIL"), []));
|
||||
} catch (e) {
|
||||
console.log(typeof e);
|
||||
}
|
||||
}
|
||||
expect_stdout: "object"
|
||||
}
|
||||
|
||||
issue_5396: {
|
||||
options = {
|
||||
collapse_vars: true,
|
||||
merge_vars: true,
|
||||
reduce_vars: true,
|
||||
side_effects: true,
|
||||
unused: true,
|
||||
}
|
||||
input: {
|
||||
var a, b;
|
||||
function f() {}
|
||||
b = 0;
|
||||
new function g(c) {
|
||||
var d = a && g(e), e = ++d, i = [ 42 ];
|
||||
for (var j in i)
|
||||
console.log("PASS"),
|
||||
i;
|
||||
}();
|
||||
}
|
||||
expect: {
|
||||
var a, b;
|
||||
function f() {}
|
||||
b = 0;
|
||||
(function g(c) {
|
||||
a && g();
|
||||
for (var j in [ 42 ])
|
||||
console.log("PASS");
|
||||
})();
|
||||
}
|
||||
expect_stdout: "PASS"
|
||||
}
|
||||
|
||||
issue_5568: {
|
||||
options = {
|
||||
collapse_vars: true,
|
||||
evaluate: true,
|
||||
reduce_vars: true,
|
||||
toplevel: true,
|
||||
unused: true,
|
||||
}
|
||||
input: {
|
||||
A = "FAIL";
|
||||
var a = (A = "PASS", !1);
|
||||
for (var b in a);
|
||||
console.log(A);
|
||||
}
|
||||
expect: {
|
||||
A = "FAIL";
|
||||
for (var b in !(A = "PASS"));
|
||||
console.log(A);
|
||||
}
|
||||
expect_stdout: "PASS"
|
||||
}
|
||||
|
||||
@@ -40,6 +40,22 @@ unsafe_comps: {
|
||||
}
|
||||
}
|
||||
|
||||
unsafe_in_instanceof: {
|
||||
options = {
|
||||
side_effects: true,
|
||||
unsafe_comps: true,
|
||||
}
|
||||
input: {
|
||||
var a;
|
||||
42 in a;
|
||||
f() instanceof "foo";
|
||||
}
|
||||
expect: {
|
||||
var a;
|
||||
f();
|
||||
}
|
||||
}
|
||||
|
||||
dont_change_in_or_instanceof_expressions: {
|
||||
input: {
|
||||
1 in 1;
|
||||
@@ -489,7 +505,36 @@ issue_3413: {
|
||||
}
|
||||
expect: {
|
||||
var b;
|
||||
void 0 !== ("" < b || void 0) || console.log("PASS");
|
||||
void 0 === ("" < b || void 0) && console.log("PASS");
|
||||
}
|
||||
expect_stdout: "PASS"
|
||||
}
|
||||
|
||||
nullish_assign: {
|
||||
options = {
|
||||
comparisons: true,
|
||||
}
|
||||
input: {
|
||||
var a;
|
||||
void 0 !== (a = "PASS".split("")) && null !== a && console.log(a.join("-"));
|
||||
}
|
||||
expect: {
|
||||
var a;
|
||||
null != (a = "PASS".split("")) && console.log(a.join("-"));
|
||||
}
|
||||
expect_stdout: "P-A-S-S"
|
||||
}
|
||||
|
||||
nullish_chain: {
|
||||
options = {
|
||||
comparisons: true,
|
||||
}
|
||||
input: {
|
||||
var a;
|
||||
A || B || void 0 === a || null === a || C;
|
||||
}
|
||||
expect: {
|
||||
var a;
|
||||
A || B || null == a || C;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -82,14 +82,14 @@ ifs_3_should_warn: {
|
||||
"WARN: Boolean && always false [test/compress/conditionals.js:3,12]",
|
||||
"WARN: Condition left of && always false [test/compress/conditionals.js:3,12]",
|
||||
"WARN: Condition always false [test/compress/conditionals.js:3,12]",
|
||||
"WARN: Dropping side-effect-free statement [test/compress/conditionals.js:3,12]",
|
||||
"WARN: Dropping unreachable code [test/compress/conditionals.js:3,34]",
|
||||
"WARN: + in boolean context always true [test/compress/conditionals.js:10,19]",
|
||||
"WARN: Boolean || always true [test/compress/conditionals.js:10,12]",
|
||||
"WARN: Condition left of || always true [test/compress/conditionals.js:10,12]",
|
||||
"WARN: Condition always true [test/compress/conditionals.js:10,12]",
|
||||
"WARN: Dropping unreachable code [test/compress/conditionals.js:12,15]",
|
||||
"WARN: Dropping side-effect-free statement [test/compress/conditionals.js:3,12]",
|
||||
"WARN: Dropping side-effect-free statement [test/compress/conditionals.js:10,12]",
|
||||
"WARN: Dropping unreachable code [test/compress/conditionals.js:12,15]",
|
||||
]
|
||||
}
|
||||
|
||||
@@ -196,6 +196,88 @@ ifs_7: {
|
||||
}
|
||||
}
|
||||
|
||||
merge_tail_1: {
|
||||
options = {
|
||||
conditionals: true,
|
||||
}
|
||||
input: {
|
||||
function f(a) {
|
||||
var b = "foo";
|
||||
if (a) {
|
||||
while (console.log("bar"));
|
||||
console.log(b);
|
||||
} else {
|
||||
while (console.log("baz"));
|
||||
console.log(b);
|
||||
}
|
||||
}
|
||||
f();
|
||||
f(42);
|
||||
}
|
||||
expect: {
|
||||
function f(a) {
|
||||
var b = "foo";
|
||||
if (a)
|
||||
while (console.log("bar"));
|
||||
else
|
||||
while (console.log("baz"));
|
||||
console.log(b);
|
||||
}
|
||||
f();
|
||||
f(42);
|
||||
}
|
||||
expect_stdout: [
|
||||
"baz",
|
||||
"foo",
|
||||
"bar",
|
||||
"foo",
|
||||
]
|
||||
}
|
||||
|
||||
merge_tail_2: {
|
||||
options = {
|
||||
conditionals: true,
|
||||
}
|
||||
input: {
|
||||
function f(a) {
|
||||
var b = "foo";
|
||||
if (a) {
|
||||
while (console.log("bar"));
|
||||
console.log(b);
|
||||
} else {
|
||||
c = "baz";
|
||||
while (console.log(c));
|
||||
while (console.log("bar"));
|
||||
console.log(b);
|
||||
var c;
|
||||
}
|
||||
}
|
||||
f();
|
||||
f(42);
|
||||
}
|
||||
expect: {
|
||||
function f(a) {
|
||||
var b = "foo";
|
||||
if (!a) {
|
||||
c = "baz";
|
||||
while (console.log(c));
|
||||
var c;
|
||||
}
|
||||
while (console.log("bar"));
|
||||
console.log(b);
|
||||
}
|
||||
f();
|
||||
f(42);
|
||||
}
|
||||
expect_stdout: [
|
||||
"baz",
|
||||
"bar",
|
||||
"foo",
|
||||
"bar",
|
||||
"foo",
|
||||
]
|
||||
}
|
||||
|
||||
cond_1: {
|
||||
options = {
|
||||
conditionals: true,
|
||||
@@ -1731,7 +1813,7 @@ issue_3576: {
|
||||
expect_stdout: "PASS"
|
||||
}
|
||||
|
||||
issue_3668: {
|
||||
issue_3668_1: {
|
||||
options = {
|
||||
conditionals: true,
|
||||
if_return: true,
|
||||
@@ -1748,6 +1830,38 @@ issue_3668: {
|
||||
}
|
||||
console.log(f());
|
||||
}
|
||||
expect: {
|
||||
function f() {
|
||||
try {
|
||||
var undefined = typeof f;
|
||||
if (!f) return undefined;
|
||||
} catch (e) {
|
||||
return "FAIL";
|
||||
}
|
||||
}
|
||||
console.log(f());
|
||||
}
|
||||
expect_stdout: "undefined"
|
||||
}
|
||||
|
||||
issue_3668_2: {
|
||||
options = {
|
||||
conditionals: true,
|
||||
if_return: true,
|
||||
}
|
||||
input: {
|
||||
function f() {
|
||||
try {
|
||||
var undefined = typeof f;
|
||||
if (!f) return undefined;
|
||||
return;
|
||||
} catch (e) {
|
||||
return "FAIL";
|
||||
}
|
||||
FAIL;
|
||||
}
|
||||
console.log(f());
|
||||
}
|
||||
expect: {
|
||||
function f() {
|
||||
try {
|
||||
@@ -1756,6 +1870,7 @@ issue_3668: {
|
||||
} catch (e) {
|
||||
return "FAIL";
|
||||
}
|
||||
FAIL;
|
||||
}
|
||||
console.log(f());
|
||||
}
|
||||
@@ -2007,3 +2122,231 @@ issue_5232_3: {
|
||||
"undefined",
|
||||
]
|
||||
}
|
||||
|
||||
issue_5334_1: {
|
||||
options = {
|
||||
conditionals: true,
|
||||
hoist_props: true,
|
||||
reduce_vars: true,
|
||||
side_effects: true,
|
||||
toplevel: true,
|
||||
unused: true,
|
||||
}
|
||||
input: {
|
||||
function f() {
|
||||
if (console.log("PASS"))
|
||||
var o = true, o = {
|
||||
p: o += console.log("FAIL"),
|
||||
};
|
||||
}
|
||||
f();
|
||||
}
|
||||
expect: {
|
||||
(function() {
|
||||
var o;
|
||||
console.log("PASS") && (o = true, o = {
|
||||
p: o += console.log("FAIL"),
|
||||
});
|
||||
})();
|
||||
}
|
||||
expect_stdout: "PASS"
|
||||
}
|
||||
|
||||
issue_5334_2: {
|
||||
options = {
|
||||
conditionals: true,
|
||||
hoist_props: true,
|
||||
inline: true,
|
||||
passes: 3,
|
||||
reduce_vars: true,
|
||||
side_effects: true,
|
||||
toplevel: true,
|
||||
unused: true,
|
||||
}
|
||||
input: {
|
||||
function f() {
|
||||
if (console.log("PASS"))
|
||||
var o = true, o = {
|
||||
p: o += console.log("FAIL"),
|
||||
};
|
||||
}
|
||||
f();
|
||||
}
|
||||
expect: {
|
||||
console.log("PASS") && console.log("FAIL");
|
||||
}
|
||||
expect_stdout: "PASS"
|
||||
}
|
||||
|
||||
issue_5544_1: {
|
||||
options = {
|
||||
conditionals: true,
|
||||
}
|
||||
input: {
|
||||
var a;
|
||||
if (a)
|
||||
switch (42) {
|
||||
case console.log("FAIL"):
|
||||
case console:
|
||||
}
|
||||
else
|
||||
switch (false) {
|
||||
case console.log("PASS"):
|
||||
case console:
|
||||
}
|
||||
}
|
||||
expect: {
|
||||
var a;
|
||||
if (a)
|
||||
switch (42) {
|
||||
case console.log("FAIL"):
|
||||
case console:
|
||||
}
|
||||
else
|
||||
switch (false) {
|
||||
case console.log("PASS"):
|
||||
case console:
|
||||
}
|
||||
}
|
||||
expect_stdout: "PASS"
|
||||
}
|
||||
|
||||
issue_5544_2: {
|
||||
options = {
|
||||
conditionals: true,
|
||||
}
|
||||
input: {
|
||||
var a;
|
||||
if (a)
|
||||
switch (42) {
|
||||
case console.log("FAIL"):
|
||||
case console:
|
||||
}
|
||||
else
|
||||
switch (42) {
|
||||
case console.log("PASS"):
|
||||
case console:
|
||||
}
|
||||
}
|
||||
expect: {
|
||||
var a;
|
||||
if (a)
|
||||
switch (42) {
|
||||
case console.log("FAIL"):
|
||||
case console:
|
||||
}
|
||||
else
|
||||
switch (42) {
|
||||
case console.log("PASS"):
|
||||
case console:
|
||||
}
|
||||
}
|
||||
expect_stdout: "PASS"
|
||||
}
|
||||
|
||||
issue_5546_1: {
|
||||
options = {
|
||||
conditionals: true,
|
||||
}
|
||||
input: {
|
||||
var a;
|
||||
if (a)
|
||||
try {
|
||||
console;
|
||||
} finally {
|
||||
console.log("FAIL");
|
||||
}
|
||||
else
|
||||
try {
|
||||
console;
|
||||
} finally {
|
||||
console.log("PASS");
|
||||
}
|
||||
}
|
||||
expect: {
|
||||
var a;
|
||||
if (a)
|
||||
try {
|
||||
console;
|
||||
} finally {
|
||||
console.log("FAIL");
|
||||
}
|
||||
else
|
||||
try {
|
||||
console;
|
||||
} finally {
|
||||
console.log("PASS");
|
||||
}
|
||||
}
|
||||
expect_stdout: "PASS"
|
||||
}
|
||||
|
||||
issue_5546_2: {
|
||||
options = {
|
||||
conditionals: true,
|
||||
}
|
||||
input: {
|
||||
var a;
|
||||
if (a)
|
||||
try {
|
||||
console;
|
||||
} catch (e) {}
|
||||
else
|
||||
try {
|
||||
console;
|
||||
} finally {
|
||||
console.log("PASS");
|
||||
}
|
||||
}
|
||||
expect: {
|
||||
var a;
|
||||
if (a)
|
||||
try {
|
||||
console;
|
||||
} catch (e) {}
|
||||
else
|
||||
try {
|
||||
console;
|
||||
} finally {
|
||||
console.log("PASS");
|
||||
}
|
||||
}
|
||||
expect_stdout: "PASS"
|
||||
}
|
||||
|
||||
issue_5546_3: {
|
||||
options = {
|
||||
conditionals: true,
|
||||
}
|
||||
input: {
|
||||
var a;
|
||||
if (a)
|
||||
try {
|
||||
FAIL;
|
||||
} catch (e) {
|
||||
console.log("FAIL");
|
||||
}
|
||||
else
|
||||
try {
|
||||
FAIL;
|
||||
} catch (e) {
|
||||
console.log("PASS");
|
||||
}
|
||||
}
|
||||
expect: {
|
||||
var a;
|
||||
if (a)
|
||||
try {
|
||||
FAIL;
|
||||
} catch (e) {
|
||||
console.log("FAIL");
|
||||
}
|
||||
else
|
||||
try {
|
||||
FAIL;
|
||||
} catch (e) {
|
||||
console.log("PASS");
|
||||
}
|
||||
}
|
||||
expect_stdout: "PASS"
|
||||
}
|
||||
|
||||
@@ -142,6 +142,80 @@ if_dead_branch: {
|
||||
expect_stdout: "undefined"
|
||||
}
|
||||
|
||||
retain_tail_1: {
|
||||
options = {
|
||||
conditionals: true,
|
||||
}
|
||||
input: {
|
||||
function f(a) {
|
||||
var b = "foo";
|
||||
if (a) {
|
||||
const b = "bar";
|
||||
while (console.log("baz"));
|
||||
console.log(b);
|
||||
} else {
|
||||
while (console.log("moo"));
|
||||
console.log(b);
|
||||
}
|
||||
}
|
||||
f();
|
||||
f(42);
|
||||
}
|
||||
expect: {
|
||||
function f(a) {
|
||||
var b = "foo";
|
||||
if (a) {
|
||||
const b = "bar";
|
||||
while (console.log("baz"));
|
||||
console.log(b);
|
||||
} else {
|
||||
while (console.log("moo"));
|
||||
console.log(b);
|
||||
}
|
||||
}
|
||||
f();
|
||||
f(42);
|
||||
}
|
||||
expect_stdout: true
|
||||
}
|
||||
|
||||
retain_tail_2: {
|
||||
options = {
|
||||
conditionals: true,
|
||||
}
|
||||
input: {
|
||||
function f(a) {
|
||||
var b = "foo";
|
||||
if (a) {
|
||||
while (console.log("bar"));
|
||||
console.log(b);
|
||||
} else {
|
||||
const b = "baz";
|
||||
while (console.log("moo"));
|
||||
console.log(b);
|
||||
}
|
||||
}
|
||||
f();
|
||||
f(42);
|
||||
}
|
||||
expect: {
|
||||
function f(a) {
|
||||
var b = "foo";
|
||||
if (a) {
|
||||
while (console.log("bar"));
|
||||
console.log(b);
|
||||
} else {
|
||||
const b = "baz";
|
||||
while (console.log("moo"));
|
||||
console.log(b);
|
||||
}
|
||||
}
|
||||
f();
|
||||
f(42);
|
||||
}
|
||||
expect_stdout: true
|
||||
}
|
||||
|
||||
merge_vars_1: {
|
||||
options = {
|
||||
merge_vars: true,
|
||||
@@ -579,6 +653,37 @@ dead_block_after_return: {
|
||||
expect_stdout: true
|
||||
}
|
||||
|
||||
if_return_3: {
|
||||
options = {
|
||||
if_return: true,
|
||||
}
|
||||
input: {
|
||||
var a = "PASS";
|
||||
function f(b) {
|
||||
if (console) {
|
||||
const b = a;
|
||||
return b;
|
||||
} else
|
||||
while (console.log("FAIL 1"));
|
||||
return b;
|
||||
}
|
||||
console.log(f("FAIL 2"));
|
||||
}
|
||||
expect: {
|
||||
var a = "PASS";
|
||||
function f(b) {
|
||||
if (console) {
|
||||
const b = a;
|
||||
return b;
|
||||
} else
|
||||
while (console.log("FAIL 1"));
|
||||
return b;
|
||||
}
|
||||
console.log(f("FAIL 2"));
|
||||
}
|
||||
expect_stdout: true
|
||||
}
|
||||
|
||||
do_if_continue_1: {
|
||||
options = {
|
||||
if_return: true,
|
||||
@@ -597,8 +702,7 @@ do_if_continue_1: {
|
||||
}
|
||||
expect: {
|
||||
do {
|
||||
if (!console);
|
||||
else {
|
||||
if (console) {
|
||||
console.log("PASS");
|
||||
{
|
||||
const a = 0;
|
||||
@@ -628,8 +732,7 @@ do_if_continue_2: {
|
||||
}
|
||||
expect: {
|
||||
do {
|
||||
if (!console);
|
||||
else {
|
||||
if (console) {
|
||||
console.log("PASS");
|
||||
{
|
||||
const a = 0;
|
||||
@@ -1518,6 +1621,7 @@ issue_4689: {
|
||||
|
||||
issue_4691: {
|
||||
options = {
|
||||
conditionals: true,
|
||||
if_return: true,
|
||||
toplevel: true,
|
||||
}
|
||||
@@ -1813,3 +1917,97 @@ issue_5260: {
|
||||
]
|
||||
node_version: ">=4"
|
||||
}
|
||||
|
||||
issue_5319: {
|
||||
options = {
|
||||
collapse_vars: true,
|
||||
merge_vars: true,
|
||||
}
|
||||
input: {
|
||||
(function(a, c) {
|
||||
var b = a, c = b;
|
||||
{
|
||||
const a = c;
|
||||
console.log(c());
|
||||
}
|
||||
})(function() {
|
||||
return "PASS";
|
||||
});
|
||||
}
|
||||
expect: {
|
||||
(function(a, c) {
|
||||
var b = a, c;
|
||||
{
|
||||
const a = c = b;
|
||||
console.log(c());
|
||||
}
|
||||
})(function() {
|
||||
return "PASS";
|
||||
});
|
||||
}
|
||||
expect_stdout: true
|
||||
}
|
||||
|
||||
issue_5338: {
|
||||
options = {
|
||||
unused: true,
|
||||
}
|
||||
input: {
|
||||
const a = a;
|
||||
}
|
||||
expect: {
|
||||
const a = a;
|
||||
}
|
||||
expect_stdout: true
|
||||
}
|
||||
|
||||
issue_5476: {
|
||||
mangle = {
|
||||
keep_fargs: true,
|
||||
}
|
||||
input: {
|
||||
console.log(function(n) {
|
||||
const a = 42;
|
||||
}());
|
||||
}
|
||||
expect: {
|
||||
console.log(function(n) {
|
||||
const o = 42;
|
||||
}());
|
||||
}
|
||||
expect_stdout: "undefined"
|
||||
}
|
||||
|
||||
issue_5516: {
|
||||
options = {
|
||||
inline: true,
|
||||
reduce_funcs: true,
|
||||
reduce_vars: true,
|
||||
unused: true,
|
||||
}
|
||||
input: {
|
||||
console.log(typeof function() {
|
||||
try {} catch (a) {
|
||||
(function f() {
|
||||
a;
|
||||
})();
|
||||
}
|
||||
{
|
||||
const a = function() {};
|
||||
return a;
|
||||
}
|
||||
}());
|
||||
}
|
||||
expect: {
|
||||
console.log(typeof function() {
|
||||
try {} catch (a) {
|
||||
void a;
|
||||
}
|
||||
{
|
||||
const a = function() {};
|
||||
return a;
|
||||
}
|
||||
}());
|
||||
}
|
||||
expect_stdout: "function"
|
||||
}
|
||||
|
||||
@@ -1669,3 +1669,41 @@ issue_5106_2: {
|
||||
}
|
||||
expect_stdout: "PASS"
|
||||
}
|
||||
|
||||
issue_5506: {
|
||||
options = {
|
||||
dead_code: true,
|
||||
}
|
||||
input: {
|
||||
try {
|
||||
(function(a) {
|
||||
var b = 1;
|
||||
(function f() {
|
||||
try {
|
||||
b-- && f();
|
||||
} catch (c) {}
|
||||
console.log(a);
|
||||
a = 42 in (a = "bar");
|
||||
})();
|
||||
})("foo");
|
||||
} catch (e) {}
|
||||
}
|
||||
expect: {
|
||||
try {
|
||||
(function(a) {
|
||||
var b = 1;
|
||||
(function f() {
|
||||
try {
|
||||
b-- && f();
|
||||
} catch (c) {}
|
||||
console.log(a);
|
||||
a = 42 in (a = "bar");
|
||||
})();
|
||||
})("foo");
|
||||
} catch (e) {}
|
||||
}
|
||||
expect_stdout: [
|
||||
"foo",
|
||||
"bar",
|
||||
]
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -472,6 +472,93 @@ funarg_collapse_vars_3: {
|
||||
node_version: ">=6"
|
||||
}
|
||||
|
||||
funarg_collapse_vars_4: {
|
||||
options = {
|
||||
collapse_vars: true,
|
||||
unused: true,
|
||||
}
|
||||
input: {
|
||||
var a = "PASS";
|
||||
(function(b, { log: c }) {
|
||||
c(b);
|
||||
})(a, console);
|
||||
}
|
||||
expect: {
|
||||
var a = "PASS";
|
||||
(function(b, { log: c }) {
|
||||
c(a);
|
||||
})(0, console);
|
||||
}
|
||||
expect_stdout: "PASS"
|
||||
node_version: ">=6"
|
||||
}
|
||||
|
||||
funarg_collapse_vars_5: {
|
||||
options = {
|
||||
collapse_vars: true,
|
||||
unused: true,
|
||||
}
|
||||
input: {
|
||||
A = "FAIL";
|
||||
B = "PASS";
|
||||
try {
|
||||
console.log(function({}, a) {
|
||||
return a;
|
||||
}(null, A = B));
|
||||
} catch (e) {}
|
||||
console.log(A);
|
||||
}
|
||||
expect: {
|
||||
A = "FAIL";
|
||||
B = "PASS";
|
||||
try {
|
||||
console.log(function({}, a) {
|
||||
return a;
|
||||
}(null, A = B));
|
||||
} catch (e) {}
|
||||
console.log(A);
|
||||
}
|
||||
expect_stdout: "PASS"
|
||||
node_version: ">=6"
|
||||
}
|
||||
|
||||
funarg_collapse_vars_6: {
|
||||
options = {
|
||||
collapse_vars: true,
|
||||
unused: true,
|
||||
}
|
||||
input: {
|
||||
A = "FAIL";
|
||||
B = "PASS";
|
||||
function f() {
|
||||
console.log(function({}, a) {
|
||||
return a;
|
||||
}(null, A = B));
|
||||
}
|
||||
try {
|
||||
f();
|
||||
} catch (e) {
|
||||
console.log(A);
|
||||
}
|
||||
}
|
||||
expect: {
|
||||
A = "FAIL";
|
||||
B = "PASS";
|
||||
function f() {
|
||||
console.log(function({}, a) {
|
||||
return a;
|
||||
}(null, A = B));
|
||||
}
|
||||
try {
|
||||
f();
|
||||
} catch (e) {
|
||||
console.log(A);
|
||||
}
|
||||
}
|
||||
expect_stdout: "PASS"
|
||||
node_version: ">=6"
|
||||
}
|
||||
|
||||
funarg_reduce_vars_1: {
|
||||
options = {
|
||||
reduce_vars: true,
|
||||
@@ -692,7 +779,7 @@ funarg_inline: {
|
||||
node_version: ">=6"
|
||||
}
|
||||
|
||||
process_boolean_returns: {
|
||||
process_returns: {
|
||||
options = {
|
||||
booleans: true,
|
||||
}
|
||||
@@ -706,9 +793,7 @@ process_boolean_returns: {
|
||||
expect: {
|
||||
console.log(function({ length }) {
|
||||
return length ? "FAIL" : "PASS";
|
||||
}(function() {
|
||||
return 42;
|
||||
}));
|
||||
}(function() {}));
|
||||
}
|
||||
expect_stdout: "PASS"
|
||||
node_version: ">=6"
|
||||
@@ -1130,7 +1215,7 @@ drop_unused_2: {
|
||||
}
|
||||
f();
|
||||
}
|
||||
expect:{
|
||||
expect: {
|
||||
(function(a) {
|
||||
console.log("PASS");
|
||||
})();
|
||||
@@ -1850,8 +1935,8 @@ issue_4294: {
|
||||
}) {}({
|
||||
[a]: 0,
|
||||
});
|
||||
var a = A;
|
||||
console.log(a);
|
||||
var b = A;
|
||||
console.log(b);
|
||||
})();
|
||||
}
|
||||
expect_stdout: "PASS"
|
||||
@@ -3022,6 +3107,7 @@ issue_5074_method_pure_getters: {
|
||||
issue_5085_1: {
|
||||
options = {
|
||||
evaluate: true,
|
||||
passes: 2,
|
||||
reduce_vars: true,
|
||||
toplevel: true,
|
||||
unsafe: true,
|
||||
@@ -3034,8 +3120,7 @@ issue_5085_1: {
|
||||
}
|
||||
expect: {
|
||||
var a = "PASS";
|
||||
var b = [ 42 ][0];
|
||||
b;
|
||||
42;
|
||||
console.log(a);
|
||||
}
|
||||
expect_stdout: "PASS"
|
||||
@@ -3045,6 +3130,7 @@ issue_5085_1: {
|
||||
issue_5085_2: {
|
||||
options = {
|
||||
evaluate: true,
|
||||
passes: 2,
|
||||
reduce_vars: true,
|
||||
side_effects: true,
|
||||
unsafe: true,
|
||||
@@ -3061,7 +3147,7 @@ issue_5085_2: {
|
||||
expect: {
|
||||
var a = "PASS";
|
||||
(function(b) {
|
||||
b = [ 42 ][0];
|
||||
0;
|
||||
})();
|
||||
console.log(a);
|
||||
}
|
||||
@@ -3402,10 +3488,11 @@ issue_5222: {
|
||||
node_version: ">=6"
|
||||
}
|
||||
|
||||
issue_5288: {
|
||||
issue_5288_1: {
|
||||
options = {
|
||||
conditionals: true,
|
||||
inline: true,
|
||||
keep_fargs: false,
|
||||
reduce_vars: true,
|
||||
toplevel: true,
|
||||
unused: true,
|
||||
@@ -3421,8 +3508,339 @@ issue_5288: {
|
||||
}() ]));
|
||||
}
|
||||
expect: {
|
||||
while ([ [ console ? console.log("PASS") : 0 ] ], void 0);
|
||||
while (function() {
|
||||
if (console)
|
||||
console.log("PASS");
|
||||
}(), void 0);
|
||||
}
|
||||
expect_stdout: "PASS"
|
||||
node_version: ">=6"
|
||||
}
|
||||
|
||||
issue_5288_2: {
|
||||
options = {
|
||||
conditionals: true,
|
||||
inline: true,
|
||||
keep_fargs: false,
|
||||
passes: 2,
|
||||
reduce_vars: true,
|
||||
toplevel: true,
|
||||
unused: true,
|
||||
varify: true,
|
||||
}
|
||||
input: {
|
||||
while (function([]) {}([ function f() {
|
||||
if (console)
|
||||
return console.log("PASS");
|
||||
else {
|
||||
let a = 0;
|
||||
}
|
||||
}() ]));
|
||||
}
|
||||
expect: {
|
||||
while (console && console.log("PASS"), void 0);
|
||||
}
|
||||
expect_stdout: "PASS"
|
||||
node_version: ">=6"
|
||||
}
|
||||
|
||||
issue_5314_1: {
|
||||
options = {
|
||||
side_effects: true,
|
||||
}
|
||||
input: {
|
||||
A = this;
|
||||
new function() {
|
||||
(function({
|
||||
[console.log(this === A ? "PASS" : "FAIL")]: a,
|
||||
}) {})(42);
|
||||
}();
|
||||
}
|
||||
expect: {
|
||||
A = this;
|
||||
(function() {
|
||||
(function({
|
||||
[console.log(this === A ? "PASS" : "FAIL")]: a,
|
||||
}) {})(42);
|
||||
})();
|
||||
}
|
||||
expect_stdout: "PASS"
|
||||
node_version: ">=6"
|
||||
}
|
||||
|
||||
issue_5314_2: {
|
||||
options = {
|
||||
side_effects: true,
|
||||
}
|
||||
input: {
|
||||
A = this;
|
||||
new function() {
|
||||
(({
|
||||
[console.log(this === A ? "FAIL" : "PASS")]: a,
|
||||
}) => {})(42);
|
||||
}();
|
||||
}
|
||||
expect: {
|
||||
A = this;
|
||||
new function() {
|
||||
[ {
|
||||
[console.log(this === A ? "FAIL" : "PASS")]: [][0],
|
||||
} ] = [ 42 ];
|
||||
}();
|
||||
}
|
||||
expect_stdout: "PASS"
|
||||
node_version: ">=6"
|
||||
}
|
||||
|
||||
issue_5370: {
|
||||
options = {
|
||||
dead_code: true,
|
||||
ie: true,
|
||||
unused: true,
|
||||
}
|
||||
input: {
|
||||
console.log(function arguments({}) {
|
||||
return arguments;
|
||||
try {} catch (e) {
|
||||
var arguments;
|
||||
}
|
||||
}(42));
|
||||
}
|
||||
expect: {
|
||||
console.log(function arguments({}) {
|
||||
return arguments;
|
||||
var arguments;
|
||||
}(42));
|
||||
}
|
||||
expect_stdout: true
|
||||
node_version: ">=6"
|
||||
}
|
||||
|
||||
issue_5405_1: {
|
||||
options = {
|
||||
evaluate: true,
|
||||
reduce_vars: true,
|
||||
toplevel: true,
|
||||
unsafe: true,
|
||||
}
|
||||
input: {
|
||||
var [ a ] = [ {} ];
|
||||
console.log(a === a ? "PASS" : "FAIL");
|
||||
}
|
||||
expect: {
|
||||
var [ a ] = [ {} ];
|
||||
console.log(true ? "PASS" : "FAIL");
|
||||
}
|
||||
expect_stdout: "PASS"
|
||||
node_version: ">=6"
|
||||
}
|
||||
|
||||
issue_5405_2: {
|
||||
options = {
|
||||
evaluate: true,
|
||||
reduce_vars: true,
|
||||
toplevel: true,
|
||||
unsafe: true,
|
||||
}
|
||||
input: {
|
||||
var { p: a } = { p: [] };
|
||||
console.log(a === a ? "PASS" : "FAIL");
|
||||
}
|
||||
expect: {
|
||||
var { p: a } = { p: [] };
|
||||
console.log(true ? "PASS" : "FAIL");
|
||||
}
|
||||
expect_stdout: "PASS"
|
||||
node_version: ">=6"
|
||||
}
|
||||
|
||||
issue_5423: {
|
||||
options = {
|
||||
merge_vars: true,
|
||||
toplevel: true,
|
||||
}
|
||||
input: {
|
||||
var a, b;
|
||||
function f({
|
||||
[function() {
|
||||
if (++a)
|
||||
return 42;
|
||||
}()]: c
|
||||
}) {}
|
||||
f(b = f);
|
||||
console.log(typeof b);
|
||||
}
|
||||
expect: {
|
||||
var a, b;
|
||||
function f({
|
||||
[function() {
|
||||
if (++a)
|
||||
return 42;
|
||||
}()]: c
|
||||
}) {}
|
||||
f(b = f);
|
||||
console.log(typeof b);
|
||||
}
|
||||
expect_stdout: "function"
|
||||
node_version: ">=6"
|
||||
}
|
||||
|
||||
issue_5454: {
|
||||
options = {
|
||||
hoist_props: true,
|
||||
reduce_vars: true,
|
||||
side_effects: true,
|
||||
toplevel: true,
|
||||
unused: true,
|
||||
}
|
||||
input: {
|
||||
function f(a) {
|
||||
var a = 42, a = {
|
||||
p: [ a ] = [],
|
||||
};
|
||||
return "PASS";
|
||||
}
|
||||
console.log(f());
|
||||
}
|
||||
expect: {
|
||||
console.log(function(a) {
|
||||
a = 42, a = {
|
||||
p: [ a ] = [],
|
||||
};
|
||||
return "PASS";
|
||||
}());
|
||||
}
|
||||
expect_stdout: "PASS"
|
||||
node_version: ">=6"
|
||||
}
|
||||
|
||||
issue_5485: {
|
||||
options = {
|
||||
comparisons: true,
|
||||
}
|
||||
input: {
|
||||
(function f({
|
||||
p: f,
|
||||
[console.log(void 0 === f ? "PASS" : "FAIL")]: a,
|
||||
}) {})(42);
|
||||
}
|
||||
expect: {
|
||||
(function f({
|
||||
p: f,
|
||||
[console.log(void 0 === f ? "PASS" : "FAIL")]: a,
|
||||
}) {})(42);
|
||||
}
|
||||
expect_stdout: "PASS"
|
||||
node_version: ">=6"
|
||||
}
|
||||
|
||||
issue_5533_keep_fargs: {
|
||||
options = {
|
||||
evaluate: true,
|
||||
inline: true,
|
||||
join_vars: true,
|
||||
keep_fargs: true,
|
||||
loops: true,
|
||||
side_effects: true,
|
||||
unused: true,
|
||||
}
|
||||
input: {
|
||||
"use strict";
|
||||
try {
|
||||
(function() {
|
||||
var a;
|
||||
for (; 1;)
|
||||
a = function() {
|
||||
(function f([ b ]) {
|
||||
b;
|
||||
throw "PASS";
|
||||
})([]);
|
||||
}();
|
||||
})();
|
||||
} catch (e) {
|
||||
console.log(e);
|
||||
}
|
||||
}
|
||||
expect: {
|
||||
"use strict";
|
||||
try {
|
||||
(function() {
|
||||
for (;;)
|
||||
throw "PASS";
|
||||
})();
|
||||
} catch (e) {
|
||||
console.log(e);
|
||||
}
|
||||
}
|
||||
expect_stdout: "PASS"
|
||||
node_version: ">=6"
|
||||
}
|
||||
|
||||
issue_5533_drop_fargs: {
|
||||
options = {
|
||||
evaluate: true,
|
||||
inline: true,
|
||||
join_vars: true,
|
||||
keep_fargs: false,
|
||||
loops: true,
|
||||
side_effects: true,
|
||||
unused: true,
|
||||
}
|
||||
input: {
|
||||
"use strict";
|
||||
try {
|
||||
(function() {
|
||||
var a;
|
||||
for (; 1;)
|
||||
a = function() {
|
||||
(function f([ b ]) {
|
||||
b;
|
||||
throw "PASS";
|
||||
})([]);
|
||||
}();
|
||||
})();
|
||||
} catch (e) {
|
||||
console.log(e);
|
||||
}
|
||||
}
|
||||
expect: {
|
||||
"use strict";
|
||||
try {
|
||||
(function() {
|
||||
for (;;)
|
||||
throw "PASS";
|
||||
})();
|
||||
} catch (e) {
|
||||
console.log(e);
|
||||
}
|
||||
}
|
||||
expect_stdout: "PASS"
|
||||
node_version: ">=6"
|
||||
}
|
||||
|
||||
issue_5573: {
|
||||
options = {
|
||||
collapse_vars: true,
|
||||
}
|
||||
input: {
|
||||
var log = console.log;
|
||||
var a = "FAIL";
|
||||
(function([ { [log(a)]: b } ]) {
|
||||
A = 42;
|
||||
})((a = "PASS", [ {} ]));
|
||||
log(a, A);
|
||||
}
|
||||
expect: {
|
||||
var log = console.log;
|
||||
var a = "FAIL";
|
||||
(function([ { [log(a)]: b } ]) {
|
||||
A = 42;
|
||||
})((a = "PASS", [ {} ]));
|
||||
log(a, A);
|
||||
}
|
||||
expect_stdout: [
|
||||
"PASS",
|
||||
"PASS 42",
|
||||
]
|
||||
node_version: ">=6"
|
||||
}
|
||||
|
||||
@@ -129,3 +129,32 @@ valid_after_invalid_2: {
|
||||
}
|
||||
expect_stdout: "undefined"
|
||||
}
|
||||
|
||||
issue_5368_1: {
|
||||
options = {
|
||||
directives: true,
|
||||
expression: true,
|
||||
}
|
||||
input: {
|
||||
"foo";
|
||||
}
|
||||
expect: {
|
||||
"foo";
|
||||
}
|
||||
}
|
||||
|
||||
issue_5368_2: {
|
||||
options = {
|
||||
directives: true,
|
||||
expression: true,
|
||||
}
|
||||
input: {
|
||||
"foo";
|
||||
(function() {
|
||||
"bar";
|
||||
})();
|
||||
}
|
||||
expect: {
|
||||
(function() {})();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -671,6 +671,76 @@ iife: {
|
||||
}
|
||||
}
|
||||
|
||||
drop_instanceof: {
|
||||
options = {
|
||||
booleans: true,
|
||||
toplevel: true,
|
||||
unused: true,
|
||||
}
|
||||
input: {
|
||||
function f() {}
|
||||
console.log({} instanceof f, Math instanceof f);
|
||||
}
|
||||
expect: {
|
||||
console.log(!1, (Math, !1));
|
||||
}
|
||||
expect_stdout: "false false"
|
||||
}
|
||||
|
||||
keep_instanceof_1: {
|
||||
options = {
|
||||
toplevel: true,
|
||||
unused: true,
|
||||
}
|
||||
input: {
|
||||
function f() {}
|
||||
var f;
|
||||
console.log({} instanceof f, Math instanceof f);
|
||||
}
|
||||
expect: {
|
||||
function f() {}
|
||||
var f;
|
||||
console.log({} instanceof f, Math instanceof f);
|
||||
}
|
||||
expect_stdout: "false false"
|
||||
}
|
||||
|
||||
keep_instanceof_2: {
|
||||
options = {
|
||||
toplevel: true,
|
||||
unused: true,
|
||||
}
|
||||
input: {
|
||||
function f() {}
|
||||
var f = Object;
|
||||
console.log({} instanceof f, Math instanceof f);
|
||||
}
|
||||
expect: {
|
||||
function f() {}
|
||||
var f = Object;
|
||||
console.log({} instanceof f, Math instanceof f);
|
||||
}
|
||||
expect_stdout: "true true"
|
||||
}
|
||||
|
||||
keep_instanceof_3: {
|
||||
options = {
|
||||
toplevel: true,
|
||||
unused: true,
|
||||
}
|
||||
input: {
|
||||
f = Object;
|
||||
function f() {}
|
||||
console.log({} instanceof f, Math instanceof f);
|
||||
}
|
||||
expect: {
|
||||
f = Object;
|
||||
function f() {}
|
||||
console.log({} instanceof f, Math instanceof f);
|
||||
}
|
||||
expect_stdout: "true true"
|
||||
}
|
||||
|
||||
issue_1539: {
|
||||
options = {
|
||||
collapse_vars: true,
|
||||
@@ -2656,7 +2726,7 @@ issue_3956: {
|
||||
collapse_vars: true,
|
||||
evaluate: true,
|
||||
inline: true,
|
||||
passes: 2,
|
||||
passes: 3,
|
||||
reduce_vars: true,
|
||||
sequences: true,
|
||||
side_effects: true,
|
||||
@@ -2787,7 +2857,7 @@ issue_3986: {
|
||||
expect_stdout: "0"
|
||||
}
|
||||
|
||||
issue_4017: {
|
||||
issue_4017_1: {
|
||||
options = {
|
||||
pure_getters: "strict",
|
||||
reduce_vars: true,
|
||||
@@ -2805,7 +2875,31 @@ issue_4017: {
|
||||
var a = 0;
|
||||
console.log(function() {
|
||||
c &= 0;
|
||||
var c;
|
||||
var c = a++ + (A = a);
|
||||
}());
|
||||
}
|
||||
expect_stdout: "undefined"
|
||||
}
|
||||
|
||||
issue_4017_2: {
|
||||
options = {
|
||||
passes: 2,
|
||||
pure_getters: "strict",
|
||||
reduce_vars: true,
|
||||
unused: true,
|
||||
}
|
||||
input: {
|
||||
var a = 0;
|
||||
console.log(function f() {
|
||||
var b = c &= 0;
|
||||
var c = a++ + (A = a);
|
||||
var d = c && c[f];
|
||||
}());
|
||||
}
|
||||
expect: {
|
||||
var a = 0;
|
||||
console.log(function() {
|
||||
0;
|
||||
a++,
|
||||
A = a;
|
||||
}());
|
||||
@@ -3248,7 +3342,7 @@ issue_4558_1: {
|
||||
expect: {
|
||||
var a = 0;
|
||||
var b = c >>>= a;
|
||||
var c;
|
||||
var c = 0;
|
||||
b && a++,
|
||||
console.log(a);
|
||||
}
|
||||
@@ -3334,6 +3428,7 @@ issue_4806_1: {
|
||||
issue_4806_2: {
|
||||
options = {
|
||||
sequences: true,
|
||||
side_effects: true,
|
||||
toplevel: true,
|
||||
unused: true,
|
||||
}
|
||||
@@ -3590,3 +3685,85 @@ issue_5271: {
|
||||
}
|
||||
expect_stdout: "42"
|
||||
}
|
||||
|
||||
issue_5533_keep_fargs: {
|
||||
options = {
|
||||
evaluate: true,
|
||||
inline: true,
|
||||
join_vars: true,
|
||||
keep_fargs: true,
|
||||
loops: true,
|
||||
side_effects: true,
|
||||
unused: true,
|
||||
}
|
||||
input: {
|
||||
"use strict";
|
||||
try {
|
||||
(function() {
|
||||
var a;
|
||||
for (; 1;)
|
||||
a = function() {
|
||||
(function f(b) {
|
||||
b;
|
||||
throw "PASS";
|
||||
})();
|
||||
}();
|
||||
})();
|
||||
} catch (e) {
|
||||
console.log(e);
|
||||
}
|
||||
}
|
||||
expect: {
|
||||
"use strict";
|
||||
try {
|
||||
(function() {
|
||||
for (;;)
|
||||
throw "PASS";
|
||||
})();
|
||||
} catch (e) {
|
||||
console.log(e);
|
||||
}
|
||||
}
|
||||
expect_stdout: "PASS"
|
||||
}
|
||||
|
||||
issue_5533_drop_fargs: {
|
||||
options = {
|
||||
evaluate: true,
|
||||
inline: true,
|
||||
join_vars: true,
|
||||
keep_fargs: false,
|
||||
loops: true,
|
||||
side_effects: true,
|
||||
unused: true,
|
||||
}
|
||||
input: {
|
||||
"use strict";
|
||||
try {
|
||||
(function() {
|
||||
var a;
|
||||
for (; 1;)
|
||||
a = function() {
|
||||
(function f(b) {
|
||||
b;
|
||||
throw "PASS";
|
||||
})();
|
||||
}();
|
||||
})();
|
||||
} catch (e) {
|
||||
console.log(e);
|
||||
}
|
||||
}
|
||||
expect: {
|
||||
"use strict";
|
||||
try {
|
||||
(function() {
|
||||
for (;;)
|
||||
throw "PASS";
|
||||
})();
|
||||
} catch (e) {
|
||||
console.log(e);
|
||||
}
|
||||
}
|
||||
expect_stdout: "PASS"
|
||||
}
|
||||
|
||||
@@ -745,7 +745,7 @@ call_args: {
|
||||
expect: {
|
||||
var a = 1;
|
||||
console.log(1);
|
||||
+(1, 1);
|
||||
1, 1;
|
||||
}
|
||||
expect_stdout: true
|
||||
}
|
||||
@@ -769,7 +769,7 @@ call_args_drop_param: {
|
||||
}
|
||||
expect: {
|
||||
console.log(1);
|
||||
+(b, 1);
|
||||
b, 1;
|
||||
}
|
||||
expect_stdout: true
|
||||
}
|
||||
@@ -888,6 +888,39 @@ unsafe_charAt_noop: {
|
||||
expect_stdout: "f n"
|
||||
}
|
||||
|
||||
chained_side_effects: {
|
||||
options = {
|
||||
evaluate: true,
|
||||
}
|
||||
input: {
|
||||
console.log("foo") || (console.log("bar"), "baz") || console.log("moo");
|
||||
}
|
||||
expect: {
|
||||
console.log("foo") || (console.log("bar"), "baz");
|
||||
}
|
||||
expect_stdout: [
|
||||
"foo",
|
||||
"bar",
|
||||
]
|
||||
expect_warnings: [
|
||||
"WARN: Condition left of || always true [test/compress/evaluate.js:1,8]",
|
||||
]
|
||||
}
|
||||
|
||||
instanceof_lambda: {
|
||||
options = {
|
||||
evaluate: true,
|
||||
side_effects: true,
|
||||
}
|
||||
input: {
|
||||
console.log(42 instanceof function() {});
|
||||
}
|
||||
expect: {
|
||||
console.log(false);
|
||||
}
|
||||
expect_stdout: "false"
|
||||
}
|
||||
|
||||
issue_1649: {
|
||||
options = {
|
||||
evaluate: true,
|
||||
@@ -3241,3 +3274,145 @@ issue_4886_2: {
|
||||
}
|
||||
expect_stdout: "true"
|
||||
}
|
||||
|
||||
issue_5354: {
|
||||
options = {
|
||||
evaluate: true,
|
||||
unsafe: true,
|
||||
}
|
||||
input: {
|
||||
function f(a) {
|
||||
return +a.toExponential(1);
|
||||
}
|
||||
function g(b) {
|
||||
return 0 + b.toFixed(2);
|
||||
}
|
||||
function h(c) {
|
||||
return 1 * c.toPrecision(3);
|
||||
}
|
||||
console.log(typeof f(45), typeof g(67), typeof h(89));
|
||||
}
|
||||
expect: {
|
||||
function f(a) {
|
||||
return +a.toExponential(1);
|
||||
}
|
||||
function g(b) {
|
||||
return 0 + b.toFixed(2);
|
||||
}
|
||||
function h(c) {
|
||||
return +c.toPrecision(3);
|
||||
}
|
||||
console.log(typeof f(45), typeof g(67), typeof h(89));
|
||||
}
|
||||
expect_stdout: "number string number"
|
||||
}
|
||||
|
||||
issue_5356: {
|
||||
options = {
|
||||
evaluate: true,
|
||||
inline: true,
|
||||
reduce_vars: true,
|
||||
toplevel: true,
|
||||
unused: true,
|
||||
}
|
||||
input: {
|
||||
console.log(function() {
|
||||
return a++;
|
||||
var a = a;
|
||||
}());
|
||||
}
|
||||
expect: {
|
||||
console.log(+a);
|
||||
var a;
|
||||
}
|
||||
expect_stdout: "NaN"
|
||||
}
|
||||
|
||||
issue_5362_1: {
|
||||
options = {
|
||||
evaluate: true,
|
||||
reduce_vars: true,
|
||||
toplevel: true,
|
||||
}
|
||||
input: {
|
||||
var a = -console;
|
||||
console.log(delete +a);
|
||||
}
|
||||
expect: {
|
||||
var a = -console;
|
||||
console.log((+a, true));
|
||||
}
|
||||
expect_stdout: "true"
|
||||
}
|
||||
|
||||
issue_5362_2: {
|
||||
options = {
|
||||
evaluate: true,
|
||||
reduce_vars: true,
|
||||
side_effects: true,
|
||||
toplevel: true,
|
||||
unsafe: true,
|
||||
unused: true,
|
||||
}
|
||||
input: {
|
||||
var a = -console;
|
||||
console.log(delete +a);
|
||||
}
|
||||
expect: {
|
||||
console.log(true);
|
||||
}
|
||||
expect_stdout: "true"
|
||||
}
|
||||
|
||||
issue_5380: {
|
||||
options = {
|
||||
evaluate: true,
|
||||
keep_fnames: true,
|
||||
reduce_vars: true,
|
||||
toplevel: true,
|
||||
unused: true,
|
||||
}
|
||||
input: {
|
||||
var a = function f(b) {
|
||||
return function g() {
|
||||
for (b in { PASS: 42 });
|
||||
}(), b;
|
||||
}("FAIL");
|
||||
console.log(a);
|
||||
}
|
||||
expect: {
|
||||
var a = function f(b) {
|
||||
return function g() {
|
||||
for (b in { PASS: 42 });
|
||||
}(), b;
|
||||
}("FAIL");
|
||||
console.log(a);
|
||||
}
|
||||
expect_stdout: "PASS"
|
||||
}
|
||||
|
||||
issue_5558: {
|
||||
options = {
|
||||
collapse_vars: true,
|
||||
evaluate: true,
|
||||
reduce_vars: true,
|
||||
sequences: true,
|
||||
toplevel: true,
|
||||
}
|
||||
input: {
|
||||
var a = 99, b = 0;
|
||||
a++;
|
||||
b++;
|
||||
b += a;
|
||||
b *= a;
|
||||
b += a;
|
||||
console.log(a);
|
||||
}
|
||||
expect: {
|
||||
var a = 99, b = 0;
|
||||
b++,
|
||||
b = (b += ++a) * a + a,
|
||||
console.log(a);
|
||||
}
|
||||
expect_stdout: "100"
|
||||
}
|
||||
|
||||
@@ -109,6 +109,17 @@ foreign: {
|
||||
expect_exact: 'export*from"foo";export{}from"bar";export*as a from"baz";export{default}from"moo";export{b,c as case,default as delete,d}from"moz";'
|
||||
}
|
||||
|
||||
non_identifiers: {
|
||||
beautify = {
|
||||
quote_style: 3,
|
||||
}
|
||||
input: {
|
||||
export * as "42" from 'foo';
|
||||
export { '42', "delete" as 'foo' } from "bar";
|
||||
}
|
||||
expect_exact: "export*as\"42\"from'foo';export{'42',delete as foo}from\"bar\";"
|
||||
}
|
||||
|
||||
same_quotes: {
|
||||
beautify = {
|
||||
beautify: true,
|
||||
@@ -417,6 +428,46 @@ hoist_funs: {
|
||||
expect_exact: "export function f(){}export default async function*g(){}"
|
||||
}
|
||||
|
||||
instanceof_default_class: {
|
||||
options = {
|
||||
toplevel: true,
|
||||
unused: true,
|
||||
}
|
||||
input: {
|
||||
export default class A {
|
||||
f(a) {
|
||||
return a instanceof A;
|
||||
}
|
||||
}
|
||||
}
|
||||
expect: {
|
||||
export default class A {
|
||||
f(a) {
|
||||
return a instanceof A;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
instanceof_default_function: {
|
||||
options = {
|
||||
toplevel: true,
|
||||
unused: true,
|
||||
}
|
||||
input: {
|
||||
export default function f() {
|
||||
if (!(this instanceof f))
|
||||
throw new Error("must instantiate");
|
||||
}
|
||||
}
|
||||
expect: {
|
||||
export default function f() {
|
||||
if (!(this instanceof f))
|
||||
throw new Error("must instantiate");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
issue_4742_join_vars_1: {
|
||||
options = {
|
||||
join_vars: true,
|
||||
@@ -496,3 +547,16 @@ issue_4766: {
|
||||
export var a = "bar";
|
||||
}
|
||||
}
|
||||
|
||||
issue_5444: {
|
||||
options = {
|
||||
unused: true,
|
||||
}
|
||||
input: {
|
||||
export var a = (console, console);
|
||||
}
|
||||
expect: {
|
||||
console;
|
||||
export var a = console;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -629,7 +629,7 @@ inline_binary_and: {
|
||||
return void "moo";
|
||||
return;
|
||||
} else
|
||||
return;
|
||||
return void 0;
|
||||
}());
|
||||
}
|
||||
expect_stdout: [
|
||||
@@ -1508,6 +1508,48 @@ unsafe_call_3: {
|
||||
expect_stdout: "3"
|
||||
}
|
||||
|
||||
inline_eval_inner: {
|
||||
options = {
|
||||
inline: true,
|
||||
}
|
||||
input: {
|
||||
(function() {
|
||||
console.log(typeof eval("arguments"));
|
||||
})();
|
||||
}
|
||||
expect: {
|
||||
(function() {
|
||||
console.log(typeof eval("arguments"));
|
||||
})();
|
||||
}
|
||||
expect_stdout: "object"
|
||||
}
|
||||
|
||||
inline_eval_outer: {
|
||||
options = {
|
||||
inline: true,
|
||||
toplevel: true,
|
||||
}
|
||||
input: {
|
||||
A = 42;
|
||||
(function(a) {
|
||||
console.log(a);
|
||||
})(A);
|
||||
console.log(eval("typeof a"));
|
||||
}
|
||||
expect: {
|
||||
A = 42;
|
||||
(function(a) {
|
||||
console.log(a);
|
||||
})(A);
|
||||
console.log(eval("typeof a"));
|
||||
}
|
||||
expect_stdout: [
|
||||
"42",
|
||||
"undefined",
|
||||
]
|
||||
}
|
||||
|
||||
issue_2616: {
|
||||
options = {
|
||||
evaluate: true,
|
||||
@@ -1713,16 +1755,14 @@ issue_2620_5: {
|
||||
}
|
||||
expect: {
|
||||
var c = "FAIL";
|
||||
(function() {
|
||||
var a = 0/0;
|
||||
var NaN = void 0;
|
||||
!function(a, NaN) {
|
||||
switch (a) {
|
||||
case a:
|
||||
break;
|
||||
case c = "PASS", NaN:
|
||||
break;
|
||||
}
|
||||
})();
|
||||
}(NaN);
|
||||
console.log(c);
|
||||
}
|
||||
expect_stdout: "PASS"
|
||||
@@ -3517,6 +3557,27 @@ functions_inner_var: {
|
||||
expect_stdout: "undefined undefined"
|
||||
}
|
||||
|
||||
functions_keep_fnames: {
|
||||
options = {
|
||||
functions: true,
|
||||
keep_fnames: true,
|
||||
reduce_vars: true,
|
||||
toplevel: true,
|
||||
unused: true,
|
||||
}
|
||||
input: {
|
||||
var FAIL = function PASS() {};
|
||||
FAIL.p = 42;
|
||||
console.log(FAIL.name, FAIL.p);
|
||||
}
|
||||
expect: {
|
||||
var FAIL = function PASS() {};
|
||||
FAIL.p = 42;
|
||||
console.log(FAIL.name, FAIL.p);
|
||||
}
|
||||
expect_stdout: "PASS 42"
|
||||
}
|
||||
|
||||
issue_2437: {
|
||||
options = {
|
||||
collapse_vars: true,
|
||||
@@ -5521,7 +5582,7 @@ issue_3835: {
|
||||
return f();
|
||||
})();
|
||||
}
|
||||
expect_stdout: true
|
||||
expect_stdout: RangeError("Maximum call stack size exceeded")
|
||||
}
|
||||
|
||||
issue_3836_1: {
|
||||
@@ -6137,6 +6198,7 @@ issue_4265: {
|
||||
dead_code: true,
|
||||
inline: true,
|
||||
sequences: true,
|
||||
side_effects: true,
|
||||
}
|
||||
input: {
|
||||
function f() {
|
||||
@@ -6342,7 +6404,7 @@ issue_4612_4: {
|
||||
expect: {
|
||||
console.log(function() {
|
||||
function f() {
|
||||
return h();
|
||||
h();
|
||||
}
|
||||
function g() {
|
||||
return h();
|
||||
@@ -7635,9 +7697,10 @@ issue_5237: {
|
||||
}
|
||||
expect: {
|
||||
function f() {
|
||||
while (console.log(0/0));
|
||||
var NaN = console && console.log(NaN);
|
||||
return;
|
||||
while (console.log(NaN));
|
||||
(function() {
|
||||
var NaN = console && console.log(NaN);
|
||||
})();
|
||||
}
|
||||
f();
|
||||
}
|
||||
@@ -7772,7 +7835,7 @@ issue_5249_1: {
|
||||
while (console.log("FAIL 2"));
|
||||
return;
|
||||
} else
|
||||
return;
|
||||
return void 0;
|
||||
throw "FAIL 3";
|
||||
}());
|
||||
}
|
||||
@@ -7981,6 +8044,7 @@ issue_5264_2: {
|
||||
|
||||
issue_5283: {
|
||||
options = {
|
||||
conditionals: true,
|
||||
if_return: true,
|
||||
inline: true,
|
||||
pure_getters: "strict",
|
||||
@@ -8005,11 +8069,10 @@ issue_5283: {
|
||||
var a = "FAIL 1";
|
||||
(function() {
|
||||
a = "PASS";
|
||||
if (!console)
|
||||
(function(a) {
|
||||
console.log("FAIL 2");
|
||||
a.p;
|
||||
})();
|
||||
console || function(a) {
|
||||
console.log("FAIL 2");
|
||||
a.p;
|
||||
}();
|
||||
})();
|
||||
console.log(a);
|
||||
}
|
||||
@@ -8084,3 +8147,502 @@ issue_5296: {
|
||||
}
|
||||
expect_stdout: "PASS"
|
||||
}
|
||||
|
||||
issue_5316_1: {
|
||||
options = {
|
||||
collapse_vars: true,
|
||||
evaluate: true,
|
||||
inline: true,
|
||||
reduce_vars: true,
|
||||
toplevel: true,
|
||||
}
|
||||
input: {
|
||||
do {
|
||||
console.log("PASS");
|
||||
} while (function() {
|
||||
var a, b = 42 && (console[a = b] = a++);
|
||||
}());
|
||||
}
|
||||
expect: {
|
||||
do {
|
||||
console.log("PASS");
|
||||
} while (b = a = void 0, b = (42, console[a = a] = a++), void 0);
|
||||
var a, b;
|
||||
}
|
||||
expect_stdout: "PASS"
|
||||
}
|
||||
|
||||
issue_5316_2: {
|
||||
options = {
|
||||
collapse_vars: true,
|
||||
evaluate: true,
|
||||
inline: true,
|
||||
reduce_vars: true,
|
||||
toplevel: true,
|
||||
}
|
||||
input: {
|
||||
do {
|
||||
(function() {
|
||||
var a, b = 42 && (console[a = b] = a++);
|
||||
while (console.log("PASS"));
|
||||
})();
|
||||
} while (!console);
|
||||
}
|
||||
expect: {
|
||||
do {
|
||||
a = void 0;
|
||||
var a, b = (42, console[a = b = void 0] = a++);
|
||||
while (console.log("PASS"));
|
||||
} while (!console);
|
||||
}
|
||||
expect_stdout: "PASS"
|
||||
}
|
||||
|
||||
issue_5328: {
|
||||
options = {
|
||||
inline: true,
|
||||
}
|
||||
input: {
|
||||
(function(arguments) {
|
||||
console.log(Object.keys(arguments).join());
|
||||
})(this);
|
||||
}
|
||||
expect: {
|
||||
(function(arguments) {
|
||||
console.log(Object.keys(arguments).join());
|
||||
})(this);
|
||||
}
|
||||
expect_stdout: ""
|
||||
}
|
||||
|
||||
issue_5332_1: {
|
||||
options = {
|
||||
inline: true,
|
||||
merge_vars: true,
|
||||
reduce_vars: true,
|
||||
side_effects: true,
|
||||
toplevel: true,
|
||||
unused: true,
|
||||
}
|
||||
input: {
|
||||
do {
|
||||
var a = {};
|
||||
for (A in a)
|
||||
a;
|
||||
} while (function() {
|
||||
console.log(b);
|
||||
var b = b;
|
||||
}());
|
||||
}
|
||||
expect: {
|
||||
do {
|
||||
var a = {};
|
||||
for (A in a);
|
||||
} while (a = void 0, void console.log(a));
|
||||
}
|
||||
expect_stdout: "undefined"
|
||||
}
|
||||
|
||||
issue_5332_2: {
|
||||
options = {
|
||||
inline: true,
|
||||
merge_vars: true,
|
||||
reduce_vars: true,
|
||||
side_effects: true,
|
||||
toplevel: true,
|
||||
unused: true,
|
||||
}
|
||||
input: {
|
||||
do {
|
||||
var a = 42 in [];
|
||||
for (A in a)
|
||||
a;
|
||||
} while (function() {
|
||||
console.log(++b);
|
||||
var b = b;
|
||||
}());
|
||||
}
|
||||
expect: {
|
||||
do {
|
||||
var a = 42 in [];
|
||||
for (A in a);
|
||||
} while (a = void 0, void console.log(++a));
|
||||
}
|
||||
expect_stdout: "NaN"
|
||||
}
|
||||
|
||||
issue_5366: {
|
||||
options = {
|
||||
inline: true,
|
||||
}
|
||||
input: {
|
||||
for (console.log("foo") || function() {
|
||||
while (console.log("bar"));
|
||||
}(); console.log("baz") ;);
|
||||
}
|
||||
expect: {
|
||||
if (!console.log("foo"))
|
||||
while (console.log("bar"));
|
||||
for (;console.log("baz"););
|
||||
}
|
||||
expect_stdout: [
|
||||
"foo",
|
||||
"bar",
|
||||
"baz",
|
||||
]
|
||||
}
|
||||
|
||||
issue_5376_1: {
|
||||
options = {
|
||||
evaluate: true,
|
||||
inline: true,
|
||||
join_vars: true,
|
||||
loops: true,
|
||||
reduce_vars: true,
|
||||
toplevel: true,
|
||||
unused: true,
|
||||
}
|
||||
input: {
|
||||
"use strict";
|
||||
var a;
|
||||
for (;42;)
|
||||
var b = function() {
|
||||
var c;
|
||||
throw new Error(c++);
|
||||
}();
|
||||
}
|
||||
expect: {
|
||||
"use strict";
|
||||
for (;;) {
|
||||
42;
|
||||
throw new Error(NaN);
|
||||
}
|
||||
}
|
||||
expect_stdout: Error("NaN")
|
||||
}
|
||||
|
||||
issue_5376_2: {
|
||||
options = {
|
||||
evaluate: true,
|
||||
inline: true,
|
||||
join_vars: true,
|
||||
loops: true,
|
||||
side_effects: true,
|
||||
toplevel: true,
|
||||
unused: true,
|
||||
}
|
||||
input: {
|
||||
"use strict";
|
||||
var a;
|
||||
for (;42;)
|
||||
var b = function() {
|
||||
var c;
|
||||
c++;
|
||||
throw new Error("PASS");
|
||||
}();
|
||||
}
|
||||
expect: {
|
||||
"use strict";
|
||||
for (;;) {
|
||||
0;
|
||||
throw new Error("PASS");
|
||||
}
|
||||
}
|
||||
expect_stdout: Error("PASS")
|
||||
}
|
||||
|
||||
issue_5401: {
|
||||
options = {
|
||||
inline: true,
|
||||
}
|
||||
input: {
|
||||
L: for (var a in function() {
|
||||
while (console.log("PASS"));
|
||||
}(), a) do {
|
||||
continue L;
|
||||
} while (console.log("FAIL"));
|
||||
}
|
||||
expect: {
|
||||
while (console.log("PASS"));
|
||||
L: for (var a in a) do {
|
||||
continue L;
|
||||
} while (console.log("FAIL"));
|
||||
}
|
||||
expect_stdout: "PASS"
|
||||
}
|
||||
|
||||
issue_5409: {
|
||||
options = {
|
||||
inline: true,
|
||||
merge_vars: true,
|
||||
reduce_vars: true,
|
||||
unused: true,
|
||||
}
|
||||
input: {
|
||||
(function(a) {
|
||||
(a = console) || FAIL(a);
|
||||
(function(b) {
|
||||
console.log(b && b);
|
||||
while (!console);
|
||||
})();
|
||||
})();
|
||||
}
|
||||
expect: {
|
||||
(function(a) {
|
||||
(a = console) || FAIL(a);
|
||||
a = void 0;
|
||||
console.log(a && a);
|
||||
while (!console);
|
||||
return;
|
||||
})();
|
||||
}
|
||||
expect_stdout: "undefined"
|
||||
}
|
||||
|
||||
mixed_mode_inline_1: {
|
||||
options = {
|
||||
directives: true,
|
||||
inline: true,
|
||||
reduce_funcs: true,
|
||||
reduce_vars: true,
|
||||
toplevel: true,
|
||||
unused: true,
|
||||
}
|
||||
input: {
|
||||
function f() {
|
||||
return this;
|
||||
}
|
||||
console.log(function() {
|
||||
return f();
|
||||
}() ? "PASS" : "FAIL");
|
||||
}
|
||||
expect: {
|
||||
console.log(function() {
|
||||
return this;
|
||||
}() ? "PASS" : "FAIL");
|
||||
}
|
||||
expect_stdout: "PASS"
|
||||
}
|
||||
|
||||
mixed_mode_inline_1_strict: {
|
||||
options = {
|
||||
directives: true,
|
||||
inline: true,
|
||||
reduce_funcs: true,
|
||||
reduce_vars: true,
|
||||
toplevel: true,
|
||||
unused: true,
|
||||
}
|
||||
input: {
|
||||
"use strict";
|
||||
function f() {
|
||||
return this;
|
||||
}
|
||||
console.log(function() {
|
||||
return f();
|
||||
}() ? "FAIL" : "PASS");
|
||||
}
|
||||
expect: {
|
||||
"use strict";
|
||||
console.log(function() {
|
||||
return this;
|
||||
}() ? "FAIL" : "PASS");
|
||||
}
|
||||
expect_stdout: "PASS"
|
||||
}
|
||||
|
||||
mixed_mode_inline_2: {
|
||||
options = {
|
||||
directives: true,
|
||||
inline: true,
|
||||
reduce_funcs: true,
|
||||
reduce_vars: true,
|
||||
toplevel: true,
|
||||
unused: true,
|
||||
}
|
||||
input: {
|
||||
function f() {
|
||||
"use strict";
|
||||
return this;
|
||||
}
|
||||
console.log(function() {
|
||||
return f();
|
||||
}() ? "FAIL" : "PASS");
|
||||
}
|
||||
expect: {
|
||||
console.log(function() {
|
||||
"use strict";
|
||||
return this;
|
||||
}() ? "FAIL" : "PASS");
|
||||
}
|
||||
expect_stdout: "PASS"
|
||||
}
|
||||
|
||||
mixed_mode_inline_2_strict: {
|
||||
options = {
|
||||
directives: true,
|
||||
inline: true,
|
||||
reduce_funcs: true,
|
||||
reduce_vars: true,
|
||||
toplevel: true,
|
||||
unused: true,
|
||||
}
|
||||
input: {
|
||||
"use strict";
|
||||
function f() {
|
||||
"use strict";
|
||||
return this;
|
||||
}
|
||||
console.log(function() {
|
||||
return f();
|
||||
}() ? "FAIL" : "PASS");
|
||||
}
|
||||
expect: {
|
||||
"use strict";
|
||||
console.log(function() {
|
||||
return this;
|
||||
}() ? "FAIL" : "PASS");
|
||||
}
|
||||
expect_stdout: "PASS"
|
||||
}
|
||||
|
||||
mixed_mode_inline_3: {
|
||||
options = {
|
||||
directives: true,
|
||||
inline: true,
|
||||
reduce_funcs: true,
|
||||
reduce_vars: true,
|
||||
toplevel: true,
|
||||
unused: true,
|
||||
}
|
||||
input: {
|
||||
function f() {
|
||||
return this;
|
||||
}
|
||||
console.log(function() {
|
||||
"use strict";
|
||||
return f();
|
||||
}() ? "PASS" : "FAIL");
|
||||
}
|
||||
expect: {
|
||||
function f() {
|
||||
return this;
|
||||
}
|
||||
console.log(function() {
|
||||
"use strict";
|
||||
return f();
|
||||
}() ? "PASS" : "FAIL");
|
||||
}
|
||||
expect_stdout: "PASS"
|
||||
}
|
||||
|
||||
mixed_mode_inline_3_strict: {
|
||||
options = {
|
||||
directives: true,
|
||||
inline: true,
|
||||
reduce_funcs: true,
|
||||
reduce_vars: true,
|
||||
toplevel: true,
|
||||
unused: true,
|
||||
}
|
||||
input: {
|
||||
"use strict";
|
||||
function f() {
|
||||
return this;
|
||||
}
|
||||
console.log(function() {
|
||||
"use strict";
|
||||
return f();
|
||||
}() ? "FAIL" : "PASS");
|
||||
}
|
||||
expect: {
|
||||
"use strict";
|
||||
console.log(function() {
|
||||
return this;
|
||||
}() ? "FAIL" : "PASS");
|
||||
}
|
||||
expect_stdout: "PASS"
|
||||
}
|
||||
|
||||
mixed_mode_inline_4: {
|
||||
options = {
|
||||
directives: true,
|
||||
inline: true,
|
||||
reduce_funcs: true,
|
||||
reduce_vars: true,
|
||||
toplevel: true,
|
||||
unused: true,
|
||||
}
|
||||
input: {
|
||||
function f() {
|
||||
"use strict";
|
||||
return this;
|
||||
}
|
||||
console.log(function() {
|
||||
"use strict";
|
||||
return f();
|
||||
}() ? "FAIL" : "PASS");
|
||||
}
|
||||
expect: {
|
||||
console.log(function() {
|
||||
"use strict";
|
||||
return function() {
|
||||
"use strict";
|
||||
return this;
|
||||
}();
|
||||
}() ? "FAIL" : "PASS");
|
||||
}
|
||||
expect_stdout: "PASS"
|
||||
}
|
||||
|
||||
mixed_mode_inline_4_strict: {
|
||||
options = {
|
||||
directives: true,
|
||||
inline: true,
|
||||
reduce_funcs: true,
|
||||
reduce_vars: true,
|
||||
toplevel: true,
|
||||
unused: true,
|
||||
}
|
||||
input: {
|
||||
"use strict";
|
||||
function f() {
|
||||
"use strict";
|
||||
return this;
|
||||
}
|
||||
console.log(function() {
|
||||
"use strict";
|
||||
return f();
|
||||
}() ? "FAIL" : "PASS");
|
||||
}
|
||||
expect: {
|
||||
"use strict";
|
||||
console.log(function() {
|
||||
return this;
|
||||
}() ? "FAIL" : "PASS");
|
||||
}
|
||||
expect_stdout: "PASS"
|
||||
}
|
||||
|
||||
module_inline: {
|
||||
options = {
|
||||
inline: true,
|
||||
module: true,
|
||||
reduce_vars: true,
|
||||
}
|
||||
input: {
|
||||
var a = f;
|
||||
function f() {
|
||||
return a;
|
||||
}
|
||||
console.log(f() === a);
|
||||
}
|
||||
expect: {
|
||||
var a = f;
|
||||
function f() {
|
||||
return a;
|
||||
}
|
||||
console.log(a === a);
|
||||
}
|
||||
expect_stdout: "true"
|
||||
}
|
||||
|
||||
@@ -1176,3 +1176,51 @@ issue_5182: {
|
||||
"42",
|
||||
]
|
||||
}
|
||||
|
||||
issue_5441: {
|
||||
options = {
|
||||
hoist_props: true,
|
||||
passes: 2,
|
||||
reduce_vars: true,
|
||||
side_effects: true,
|
||||
}
|
||||
input: {
|
||||
console.log(function(a) {
|
||||
(function() {
|
||||
a = { p: this };
|
||||
})();
|
||||
return typeof a;
|
||||
}());
|
||||
}
|
||||
expect: {
|
||||
console.log(function(a) {
|
||||
(function() {
|
||||
a_p = this;
|
||||
})();
|
||||
var a_p;
|
||||
return typeof {};
|
||||
}());
|
||||
}
|
||||
expect_stdout: "object"
|
||||
}
|
||||
|
||||
issue_5498: {
|
||||
options = {
|
||||
hoist_props: true,
|
||||
reduce_vars: true,
|
||||
toplevel: true,
|
||||
}
|
||||
input: {
|
||||
var o = {
|
||||
__proto__: 42,
|
||||
};
|
||||
while (console.log(typeof o.__proto__));
|
||||
}
|
||||
expect: {
|
||||
var o = {
|
||||
__proto__: 42,
|
||||
};
|
||||
while (console.log(typeof o.__proto__));
|
||||
}
|
||||
expect_stdout: "object"
|
||||
}
|
||||
|
||||
@@ -224,8 +224,7 @@ issue_4489: {
|
||||
console.log(k);
|
||||
}
|
||||
expect: {
|
||||
!(A = 0);
|
||||
for (var k in true);
|
||||
for (var k in !(A = 0));
|
||||
console.log(k);
|
||||
}
|
||||
expect_stdout: "undefined"
|
||||
@@ -250,8 +249,7 @@ issue_4517: {
|
||||
expect: {
|
||||
console.log(function() {
|
||||
var a = 2;
|
||||
A = a;
|
||||
return A + typeof !1;
|
||||
return (A = a) + typeof !1;
|
||||
}());
|
||||
}
|
||||
expect_stdout: "2boolean"
|
||||
@@ -408,9 +406,9 @@ issue_4893_2: {
|
||||
expect: {
|
||||
try{
|
||||
(function() {
|
||||
var b;
|
||||
b = null;
|
||||
b.p += 42;
|
||||
var a;
|
||||
a = null;
|
||||
a.p += 42;
|
||||
})();
|
||||
} catch (e) {
|
||||
console.log("PASS");
|
||||
@@ -500,3 +498,108 @@ issue_5195: {
|
||||
}
|
||||
expect_stdout: "[object Object]"
|
||||
}
|
||||
|
||||
issue_5378: {
|
||||
options = {
|
||||
hoist_vars: true,
|
||||
inline: true,
|
||||
toplevel: true,
|
||||
}
|
||||
input: {
|
||||
var a = 2;
|
||||
while (a--)
|
||||
(function() {
|
||||
var b;
|
||||
var c;
|
||||
while (console.log(b));
|
||||
--b;
|
||||
})();
|
||||
}
|
||||
expect: {
|
||||
var a = 2;
|
||||
while (a--) {
|
||||
b = void 0;
|
||||
var b, c;
|
||||
while (console.log(b));
|
||||
--b;
|
||||
}
|
||||
}
|
||||
expect_stdout: [
|
||||
"undefined",
|
||||
"undefined",
|
||||
]
|
||||
}
|
||||
|
||||
issue_5411_1: {
|
||||
options = {
|
||||
collapse_vars: true,
|
||||
dead_code: true,
|
||||
hoist_vars: true,
|
||||
reduce_vars: true,
|
||||
side_effects: true,
|
||||
toplevel: true,
|
||||
}
|
||||
input: {
|
||||
var a = "PASS";
|
||||
b++;
|
||||
b = a;
|
||||
var b = b, c = c && c[b];
|
||||
console.log(b);
|
||||
}
|
||||
expect: {
|
||||
var b, c, a = "PASS";
|
||||
b++;
|
||||
b = a;
|
||||
c = c && c[b];
|
||||
console.log(b);
|
||||
}
|
||||
expect_stdout: "PASS"
|
||||
}
|
||||
|
||||
issue_5411_2: {
|
||||
options = {
|
||||
collapse_vars: true,
|
||||
dead_code: true,
|
||||
evaluate: true,
|
||||
hoist_vars: true,
|
||||
reduce_vars: true,
|
||||
toplevel: true,
|
||||
unused: true,
|
||||
}
|
||||
input: {
|
||||
var a = "PASS";
|
||||
b++;
|
||||
b = a;
|
||||
var b = b, c = c && c[b];
|
||||
console.log(b);
|
||||
}
|
||||
expect: {
|
||||
var b, c;
|
||||
b++;
|
||||
b = "PASS",
|
||||
c = c && c[b];
|
||||
console.log(b);
|
||||
}
|
||||
expect_stdout: "PASS"
|
||||
}
|
||||
|
||||
issue_5411_3: {
|
||||
options = {
|
||||
collapse_vars: true,
|
||||
hoist_vars: true,
|
||||
reduce_vars: true,
|
||||
toplevel: true,
|
||||
}
|
||||
input: {
|
||||
var a = console;
|
||||
a++;
|
||||
var a = A = a;
|
||||
console.log(A);
|
||||
}
|
||||
expect: {
|
||||
var a = console;
|
||||
a = A = ++a;
|
||||
console.log(A);
|
||||
}
|
||||
expect_stdout: "NaN"
|
||||
}
|
||||
|
||||
@@ -2631,13 +2631,14 @@ issue_3999: {
|
||||
]
|
||||
}
|
||||
|
||||
issue_4001: {
|
||||
issue_4001_1: {
|
||||
options = {
|
||||
collapse_vars: true,
|
||||
ie: true,
|
||||
inline: true,
|
||||
reduce_vars: true,
|
||||
sequences: true,
|
||||
side_effects: false,
|
||||
toplevel: true,
|
||||
unused: true,
|
||||
}
|
||||
@@ -2660,7 +2661,42 @@ issue_4001: {
|
||||
return a;
|
||||
}
|
||||
var a;
|
||||
console.log((a = 42, void f()[42], void function a() {}));
|
||||
console.log((a = 42, f()[42], void f, void function a() {}));
|
||||
}
|
||||
expect_stdout: "undefined"
|
||||
}
|
||||
|
||||
issue_4001_2: {
|
||||
options = {
|
||||
collapse_vars: true,
|
||||
ie: true,
|
||||
inline: true,
|
||||
reduce_vars: true,
|
||||
sequences: true,
|
||||
side_effects: true,
|
||||
toplevel: true,
|
||||
unused: true,
|
||||
}
|
||||
input: {
|
||||
console.log(function(a) {
|
||||
function f() {
|
||||
return a;
|
||||
var b;
|
||||
}
|
||||
var c = f();
|
||||
(function g() {
|
||||
c[42];
|
||||
f;
|
||||
})();
|
||||
(function a() {});
|
||||
}(42));
|
||||
}
|
||||
expect: {
|
||||
function f() {
|
||||
return a;
|
||||
}
|
||||
var a;
|
||||
console.log((a = 42, void f()[42]));
|
||||
}
|
||||
expect_stdout: "undefined"
|
||||
}
|
||||
@@ -3408,3 +3444,33 @@ issue_5269_3_ie: {
|
||||
"bar",
|
||||
]
|
||||
}
|
||||
|
||||
issue_5350: {
|
||||
options = {
|
||||
ie: false,
|
||||
properties: true,
|
||||
side_effects: true,
|
||||
}
|
||||
input: {
|
||||
console.log(typeof f, [ 42, function f() {} ][0]);
|
||||
}
|
||||
expect: {
|
||||
console.log(typeof f, 42);
|
||||
}
|
||||
expect_stdout: "undefined 42"
|
||||
}
|
||||
|
||||
issue_5350_ie: {
|
||||
options = {
|
||||
ie: true,
|
||||
properties: true,
|
||||
side_effects: true,
|
||||
}
|
||||
input: {
|
||||
console.log(typeof f, [ 42, function f() {} ][0]);
|
||||
}
|
||||
expect: {
|
||||
console.log(typeof f, (function f() {}, 42));
|
||||
}
|
||||
expect_stdout: "undefined 42"
|
||||
}
|
||||
|
||||
@@ -327,7 +327,7 @@ issue_512: {
|
||||
}
|
||||
}
|
||||
|
||||
if_var_return: {
|
||||
if_var_return_1: {
|
||||
options = {
|
||||
conditionals: true,
|
||||
if_return: true,
|
||||
@@ -373,6 +373,76 @@ if_var_return: {
|
||||
}
|
||||
}
|
||||
|
||||
if_var_return_2: {
|
||||
options = {
|
||||
conditionals: true,
|
||||
if_return: true,
|
||||
sequences: true,
|
||||
}
|
||||
input: {
|
||||
(function() {
|
||||
var a = w();
|
||||
if (x())
|
||||
return y();
|
||||
z();
|
||||
})();
|
||||
}
|
||||
expect: {
|
||||
(function() {
|
||||
var a = w();
|
||||
return x() ? y() : (z(), void 0);
|
||||
})();
|
||||
}
|
||||
}
|
||||
|
||||
if_var_retrn_3: {
|
||||
options = {
|
||||
conditionals: true,
|
||||
if_return: true,
|
||||
sequences: true,
|
||||
}
|
||||
input: {
|
||||
f(function() {
|
||||
var a = w();
|
||||
if (x())
|
||||
return y(a);
|
||||
z();
|
||||
});
|
||||
}
|
||||
expect: {
|
||||
f(function() {
|
||||
var a = w();
|
||||
if (x())
|
||||
return y(a);
|
||||
z();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
if_var_return_4: {
|
||||
options = {
|
||||
conditionals: true,
|
||||
if_return: true,
|
||||
sequences: true,
|
||||
}
|
||||
input: {
|
||||
function f() {
|
||||
if (u())
|
||||
return v();
|
||||
var a = w();
|
||||
if (x())
|
||||
return y();
|
||||
z();
|
||||
}
|
||||
}
|
||||
expect: {
|
||||
function f() {
|
||||
return u() ? v() : (a = w(), x() ? y() : (z(), void 0));
|
||||
var a;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if_if_return_return: {
|
||||
options = {
|
||||
conditionals: true,
|
||||
@@ -628,7 +698,9 @@ iife_if_return_simple: {
|
||||
|
||||
nested_if_break: {
|
||||
options = {
|
||||
conditionals: true,
|
||||
if_return: true,
|
||||
side_effects: true,
|
||||
}
|
||||
input: {
|
||||
for (var i = 0; i < 3; i++)
|
||||
@@ -639,8 +711,7 @@ nested_if_break: {
|
||||
}
|
||||
expect: {
|
||||
for (var i = 0; i < 3; i++)
|
||||
L1: if ("number" == typeof i)
|
||||
if (0 !== i) console.log(i);
|
||||
L1: "number" == typeof i && 0 !== i && console.log(i);
|
||||
}
|
||||
expect_stdout: [
|
||||
"1",
|
||||
@@ -679,11 +750,11 @@ nested_if_continue: {
|
||||
function f(n) {
|
||||
for (var i = 0;
|
||||
"number" == typeof n
|
||||
&& (0 !== n
|
||||
? 1 !== n
|
||||
? i++
|
||||
: console.log("odd", i)
|
||||
: console.log("even", i)),
|
||||
&& (0 === n
|
||||
? console.log("even", i)
|
||||
: 1 === n
|
||||
? console.log("odd", i)
|
||||
: i++),
|
||||
0 <= (n -= 2););
|
||||
}
|
||||
f(37);
|
||||
@@ -779,3 +850,546 @@ issue_866_2: {
|
||||
})();
|
||||
}
|
||||
}
|
||||
|
||||
identical_returns_1: {
|
||||
options = {
|
||||
conditionals: true,
|
||||
if_return: true,
|
||||
}
|
||||
input: {
|
||||
console.log(function() {
|
||||
if (console.log("foo"))
|
||||
return 42;
|
||||
else
|
||||
while (console.log("bar"));
|
||||
return 42;
|
||||
}());
|
||||
}
|
||||
expect: {
|
||||
console.log(function() {
|
||||
if (!console.log("foo"))
|
||||
while (console.log("bar"));
|
||||
return 42;
|
||||
}());
|
||||
}
|
||||
expect_stdout: [
|
||||
"foo",
|
||||
"bar",
|
||||
"42",
|
||||
]
|
||||
}
|
||||
|
||||
identical_returns_2: {
|
||||
options = {
|
||||
conditionals: true,
|
||||
if_return: true,
|
||||
}
|
||||
input: {
|
||||
console.log(function() {
|
||||
if (console.log("foo"))
|
||||
while (console.log("FAIL"));
|
||||
else
|
||||
return "bar";
|
||||
return "bar";
|
||||
}());
|
||||
}
|
||||
expect: {
|
||||
console.log(function() {
|
||||
if (console.log("foo"))
|
||||
while (console.log("FAIL"));
|
||||
return "bar";
|
||||
}());
|
||||
}
|
||||
expect_stdout: [
|
||||
"foo",
|
||||
"bar",
|
||||
]
|
||||
}
|
||||
|
||||
identical_returns_3: {
|
||||
options = {
|
||||
if_return: true,
|
||||
}
|
||||
input: {
|
||||
function f(a) {
|
||||
if (a)
|
||||
return 42;
|
||||
if (a)
|
||||
return;
|
||||
return 42;
|
||||
}
|
||||
if (f(console))
|
||||
console.log("PASS");
|
||||
}
|
||||
expect: {
|
||||
function f(a) {
|
||||
if (a)
|
||||
return 42;
|
||||
if (a)
|
||||
;
|
||||
else
|
||||
return 42;
|
||||
}
|
||||
if (f(console))
|
||||
console.log("PASS");
|
||||
}
|
||||
expect_stdout: "PASS"
|
||||
}
|
||||
|
||||
issue_4374: {
|
||||
options = {
|
||||
booleans: true,
|
||||
conditionals: true,
|
||||
if_return: true,
|
||||
reduce_vars: true,
|
||||
unused: true,
|
||||
}
|
||||
input: {
|
||||
(function() {
|
||||
console.log(f(console));
|
||||
function f(a) {
|
||||
if (console) return 0;
|
||||
if (a) return 1;
|
||||
return 0;
|
||||
}
|
||||
})();
|
||||
}
|
||||
expect: {
|
||||
(function() {
|
||||
console.log(function(a) {
|
||||
return !console && a ? 1 : 0;
|
||||
}(console));
|
||||
})();
|
||||
}
|
||||
expect_stdout: "0"
|
||||
}
|
||||
|
||||
issue_5521: {
|
||||
options = {
|
||||
if_return: true,
|
||||
}
|
||||
input: {
|
||||
console.log(function() {
|
||||
if (console)
|
||||
try {
|
||||
return "FAIL";
|
||||
} finally {
|
||||
return;
|
||||
}
|
||||
}());
|
||||
}
|
||||
expect: {
|
||||
console.log(function() {
|
||||
if (console)
|
||||
try {
|
||||
return "FAIL";
|
||||
} finally {
|
||||
return;
|
||||
}
|
||||
}());
|
||||
}
|
||||
expect_stdout: "undefined"
|
||||
}
|
||||
|
||||
issue_5523: {
|
||||
options = {
|
||||
if_return: true,
|
||||
}
|
||||
input: {
|
||||
console.log(function() {
|
||||
if (console)
|
||||
try {
|
||||
FAIL;
|
||||
} finally {
|
||||
return;
|
||||
}
|
||||
}());
|
||||
}
|
||||
expect: {
|
||||
console.log(function() {
|
||||
if (console)
|
||||
try {
|
||||
FAIL;
|
||||
} finally {
|
||||
return;
|
||||
}
|
||||
}());
|
||||
}
|
||||
expect_stdout: "undefined"
|
||||
}
|
||||
|
||||
drop_catch: {
|
||||
options = {
|
||||
if_return: true,
|
||||
}
|
||||
input: {
|
||||
function f() {
|
||||
try {
|
||||
throw 42;
|
||||
} catch (e) {
|
||||
return console.log("foo"), "bar";
|
||||
} finally {
|
||||
console.log("baz");
|
||||
}
|
||||
return "bar";
|
||||
}
|
||||
console.log(f());
|
||||
}
|
||||
expect: {
|
||||
function f() {
|
||||
try {
|
||||
throw 42;
|
||||
} catch (e) {
|
||||
console.log("foo");
|
||||
} finally {
|
||||
console.log("baz");
|
||||
}
|
||||
return "bar";
|
||||
}
|
||||
console.log(f());
|
||||
}
|
||||
expect_stdout: [
|
||||
"foo",
|
||||
"baz",
|
||||
"bar",
|
||||
]
|
||||
}
|
||||
|
||||
retain_catch: {
|
||||
options = {
|
||||
if_return: true,
|
||||
}
|
||||
input: {
|
||||
function f() {
|
||||
try {
|
||||
throw 42;
|
||||
} catch (e) {
|
||||
return console.log("foo");
|
||||
} finally {
|
||||
console.log("bar");
|
||||
}
|
||||
return console.log("foo");
|
||||
}
|
||||
f();
|
||||
}
|
||||
expect: {
|
||||
function f() {
|
||||
try {
|
||||
throw 42;
|
||||
} catch (e) {
|
||||
return console.log("foo");
|
||||
} finally {
|
||||
console.log("bar");
|
||||
}
|
||||
return console.log("foo");
|
||||
}
|
||||
f();
|
||||
}
|
||||
expect_stdout: [
|
||||
"foo",
|
||||
"bar",
|
||||
]
|
||||
}
|
||||
|
||||
retain_finally: {
|
||||
options = {
|
||||
if_return: true,
|
||||
}
|
||||
input: {
|
||||
function f() {
|
||||
try {
|
||||
return console.log("foo"), FAIL;
|
||||
} catch (e) {
|
||||
return console.log("bar"), "FAIL";
|
||||
} finally {
|
||||
return console.log("baz"), console.log("moo");
|
||||
}
|
||||
return console.log("moo");
|
||||
}
|
||||
console.log(f());
|
||||
}
|
||||
expect: {
|
||||
function f() {
|
||||
try {
|
||||
return console.log("foo"), FAIL;
|
||||
} catch (e) {
|
||||
return console.log("bar"), "FAIL";
|
||||
} finally {
|
||||
return console.log("baz"), console.log("moo");
|
||||
}
|
||||
return console.log("moo");
|
||||
}
|
||||
console.log(f());
|
||||
}
|
||||
expect_stdout: [
|
||||
"foo",
|
||||
"bar",
|
||||
"baz",
|
||||
"moo",
|
||||
"undefined",
|
||||
]
|
||||
}
|
||||
|
||||
drop_try: {
|
||||
options = {
|
||||
if_return: true,
|
||||
}
|
||||
input: {
|
||||
function f() {
|
||||
try {
|
||||
return console.log("foo"), "bar";
|
||||
} finally {
|
||||
console.log("baz");
|
||||
}
|
||||
return "bar";
|
||||
}
|
||||
console.log(f());
|
||||
}
|
||||
expect: {
|
||||
function f() {
|
||||
try {
|
||||
console.log("foo");
|
||||
} finally {
|
||||
console.log("baz");
|
||||
}
|
||||
return "bar";
|
||||
}
|
||||
console.log(f());
|
||||
}
|
||||
expect_stdout: [
|
||||
"foo",
|
||||
"baz",
|
||||
"bar",
|
||||
]
|
||||
}
|
||||
|
||||
retain_try: {
|
||||
options = {
|
||||
if_return: true,
|
||||
}
|
||||
input: {
|
||||
function f() {
|
||||
try {
|
||||
return console.log("foo");
|
||||
} finally {
|
||||
console.log("bar");
|
||||
}
|
||||
return console.log("foo");
|
||||
}
|
||||
f();
|
||||
}
|
||||
expect: {
|
||||
function f() {
|
||||
try {
|
||||
return console.log("foo");
|
||||
} finally {
|
||||
console.log("bar");
|
||||
}
|
||||
return console.log("foo");
|
||||
}
|
||||
f();
|
||||
}
|
||||
expect_stdout: [
|
||||
"foo",
|
||||
"bar",
|
||||
]
|
||||
}
|
||||
|
||||
drop_try_catch: {
|
||||
options = {
|
||||
if_return: true,
|
||||
}
|
||||
input: {
|
||||
function f(a) {
|
||||
try {
|
||||
if (a())
|
||||
return console.log("foo"), console.log("baz");
|
||||
} catch (e) {
|
||||
return console.log("bar"), console.log("baz");
|
||||
}
|
||||
return console.log("baz");
|
||||
}
|
||||
f(function() {
|
||||
return 42;
|
||||
});
|
||||
f(function() {});
|
||||
f();
|
||||
}
|
||||
expect: {
|
||||
function f(a) {
|
||||
try {
|
||||
if (a())
|
||||
console.log("foo");
|
||||
} catch (e) {
|
||||
console.log("bar");
|
||||
}
|
||||
return console.log("baz");
|
||||
}
|
||||
f(function() {
|
||||
return 42;
|
||||
});
|
||||
f(function() {});
|
||||
f();
|
||||
}
|
||||
expect_stdout: [
|
||||
"foo",
|
||||
"baz",
|
||||
"baz",
|
||||
"bar",
|
||||
"baz",
|
||||
]
|
||||
}
|
||||
|
||||
empty_try: {
|
||||
options = {
|
||||
if_return: true,
|
||||
reduce_vars: true,
|
||||
unused: true,
|
||||
}
|
||||
input: {
|
||||
console.log(function() {
|
||||
return f;
|
||||
function f() {
|
||||
try {} finally {}
|
||||
return "PASS";
|
||||
}
|
||||
}()());
|
||||
}
|
||||
expect: {
|
||||
console.log(function() {
|
||||
return function() {
|
||||
try {} finally {}
|
||||
return "PASS";
|
||||
};
|
||||
}()());
|
||||
}
|
||||
expect_stdout: "PASS"
|
||||
}
|
||||
|
||||
sequence_void_1: {
|
||||
options = {
|
||||
if_return: true,
|
||||
}
|
||||
input: {
|
||||
function f() {
|
||||
{
|
||||
if (console)
|
||||
return console, void console.log("PASS");
|
||||
return;
|
||||
}
|
||||
}
|
||||
f();
|
||||
}
|
||||
expect: {
|
||||
function f() {
|
||||
if (console)
|
||||
console, void console.log("PASS");
|
||||
}
|
||||
f();
|
||||
}
|
||||
expect_stdout: "PASS"
|
||||
}
|
||||
|
||||
sequence_void_2: {
|
||||
options = {
|
||||
if_return: true,
|
||||
}
|
||||
input: {
|
||||
function f() {
|
||||
{
|
||||
if (console)
|
||||
return console, void console.log("PASS");
|
||||
return;
|
||||
}
|
||||
FAIL;
|
||||
}
|
||||
f();
|
||||
}
|
||||
expect: {
|
||||
function f() {
|
||||
if (console)
|
||||
console, void console.log("PASS");
|
||||
else {
|
||||
return;
|
||||
FAIL;
|
||||
}
|
||||
}
|
||||
f();
|
||||
}
|
||||
expect_stdout: "PASS"
|
||||
}
|
||||
|
||||
tail_match: {
|
||||
options = {
|
||||
if_return: true,
|
||||
}
|
||||
input: {
|
||||
function f(a) {
|
||||
if (a) {
|
||||
console.log("foo");
|
||||
return console.log("bar");
|
||||
}
|
||||
while (console.log("baz"));
|
||||
return console.log("moo"), console.log("bar");
|
||||
}
|
||||
f();
|
||||
f(42);
|
||||
}
|
||||
expect: {
|
||||
function f(a) {
|
||||
if (a)
|
||||
console.log("foo");
|
||||
else {
|
||||
while (console.log("baz"));
|
||||
console.log("moo");
|
||||
}
|
||||
return console.log("bar");
|
||||
}
|
||||
f();
|
||||
f(42);
|
||||
}
|
||||
expect_stdout: [
|
||||
"baz",
|
||||
"moo",
|
||||
"bar",
|
||||
"foo",
|
||||
"bar",
|
||||
]
|
||||
}
|
||||
|
||||
void_match: {
|
||||
options = {
|
||||
if_return: true,
|
||||
}
|
||||
input: {
|
||||
function f(a) {
|
||||
if (a) {
|
||||
console.log("foo");
|
||||
return;
|
||||
}
|
||||
while (console.log("bar"));
|
||||
return console.log("baz"), void console.log("moo");
|
||||
}
|
||||
f();
|
||||
f(42);
|
||||
}
|
||||
expect: {
|
||||
function f(a) {
|
||||
if (a)
|
||||
console.log("foo");
|
||||
else {
|
||||
while (console.log("bar"));
|
||||
console.log("baz"),
|
||||
console.log("moo");
|
||||
}
|
||||
}
|
||||
f();
|
||||
f(42);
|
||||
}
|
||||
expect_stdout: [
|
||||
"bar",
|
||||
"baz",
|
||||
"moo",
|
||||
"foo",
|
||||
]
|
||||
}
|
||||
|
||||
@@ -40,6 +40,17 @@ default_keys: {
|
||||
expect_exact: 'import foo,{bar}from"baz";'
|
||||
}
|
||||
|
||||
non_identifiers: {
|
||||
beautify = {
|
||||
quote_style: 3,
|
||||
}
|
||||
input: {
|
||||
import { '42' as foo } from "bar";
|
||||
import { "foo" as bar } from 'baz';
|
||||
}
|
||||
expect_exact: "import{'42'as foo}from\"bar\";import{foo as bar}from'baz';"
|
||||
}
|
||||
|
||||
dynamic: {
|
||||
input: {
|
||||
(async a => await import(a))("foo").then(bar);
|
||||
@@ -227,3 +238,33 @@ issue_4708_2: {
|
||||
import a from "foo";
|
||||
}
|
||||
}
|
||||
|
||||
pr_5550_1: {
|
||||
input: {
|
||||
if (console)
|
||||
import("foo");
|
||||
else
|
||||
import.meta.url.replace(/bar/g, console.log);
|
||||
}
|
||||
expect: {
|
||||
if (console)
|
||||
import("foo");
|
||||
else
|
||||
import.meta.url.replace(/bar/g, console.log);
|
||||
}
|
||||
}
|
||||
|
||||
pr_5550_2: {
|
||||
input: {
|
||||
L: {
|
||||
import("foo");
|
||||
import.meta.url.replace(/bar/g, console.log);
|
||||
}
|
||||
}
|
||||
expect: {
|
||||
L: {
|
||||
import("foo");
|
||||
import.meta.url.replace(/bar/g, console.log);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
100
test/compress/indentation.js
Normal file
100
test/compress/indentation.js
Normal file
@@ -0,0 +1,100 @@
|
||||
numeric: {
|
||||
beautify = {
|
||||
beautify: true,
|
||||
indent_start: 1,
|
||||
indent_level: 3,
|
||||
}
|
||||
input: {
|
||||
switch (42) {
|
||||
case null:
|
||||
console.log("FAIL");
|
||||
}
|
||||
console.log("PASS");
|
||||
}
|
||||
expect_exact: [
|
||||
" switch (42) {",
|
||||
" case null:",
|
||||
' console.log("FAIL");',
|
||||
" }",
|
||||
"",
|
||||
' console.log("PASS");',
|
||||
]
|
||||
expect_stdout: "PASS"
|
||||
}
|
||||
|
||||
spaces: {
|
||||
beautify = {
|
||||
beautify: true,
|
||||
indent_start: " ",
|
||||
indent_level: " ",
|
||||
}
|
||||
input: {
|
||||
switch (42) {
|
||||
case null:
|
||||
console.log("FAIL");
|
||||
}
|
||||
console.log("PASS");
|
||||
}
|
||||
expect_exact: [
|
||||
" switch (42) {",
|
||||
" case null:",
|
||||
' console.log("FAIL");',
|
||||
" }",
|
||||
"",
|
||||
' console.log("PASS");',
|
||||
]
|
||||
expect_stdout: "PASS"
|
||||
}
|
||||
|
||||
tabs: {
|
||||
beautify = {
|
||||
beautify: true,
|
||||
indent_start: "\t",
|
||||
indent_level: "\t",
|
||||
}
|
||||
input: {
|
||||
switch (42) {
|
||||
case null:
|
||||
console.log("FAIL");
|
||||
}
|
||||
console.log("PASS");
|
||||
}
|
||||
expect_exact: [
|
||||
"\tswitch (42) {",
|
||||
"\tcase null:",
|
||||
'\t\tconsole.log("FAIL");',
|
||||
"\t}",
|
||||
"",
|
||||
'\tconsole.log("PASS");',
|
||||
]
|
||||
expect_stdout: "PASS"
|
||||
}
|
||||
|
||||
mixed: {
|
||||
beautify = {
|
||||
beautify: true,
|
||||
indent_start: "\n",
|
||||
indent_level: " \t",
|
||||
}
|
||||
input: {
|
||||
switch (42) {
|
||||
case null:
|
||||
console.log("FAIL");
|
||||
}
|
||||
console.log("PASS");
|
||||
}
|
||||
expect_exact: [
|
||||
"",
|
||||
"switch (42) {",
|
||||
"",
|
||||
" case null:",
|
||||
"",
|
||||
' \tconsole.log("FAIL");',
|
||||
"",
|
||||
"}",
|
||||
"",
|
||||
"",
|
||||
'console.log("PASS");',
|
||||
]
|
||||
expect_stdout: "PASS"
|
||||
}
|
||||
@@ -4,22 +4,21 @@ multiple_functions: {
|
||||
if_return: true,
|
||||
}
|
||||
input: {
|
||||
( function() {
|
||||
if ( !window ) {
|
||||
(function() {
|
||||
if (!window)
|
||||
return;
|
||||
}
|
||||
function f() {}
|
||||
function g() {}
|
||||
} )();
|
||||
})();
|
||||
}
|
||||
expect: {
|
||||
( function() {
|
||||
(function() {
|
||||
// NOTE: other compression steps will reduce this
|
||||
// down to just `window`.
|
||||
if ( !window );
|
||||
if (!window);
|
||||
function f() {}
|
||||
function g() {}
|
||||
} )();
|
||||
})();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -29,18 +28,17 @@ single_function: {
|
||||
if_return: true,
|
||||
}
|
||||
input: {
|
||||
( function() {
|
||||
if ( !window ) {
|
||||
(function() {
|
||||
if (!window)
|
||||
return;
|
||||
}
|
||||
function f() {}
|
||||
} )();
|
||||
})();
|
||||
}
|
||||
expect: {
|
||||
( function() {
|
||||
if ( !window );
|
||||
(function() {
|
||||
if (!window);
|
||||
function f() {}
|
||||
} )();
|
||||
})();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -50,28 +48,26 @@ deeply_nested: {
|
||||
if_return: true,
|
||||
}
|
||||
input: {
|
||||
( function() {
|
||||
if ( !window ) {
|
||||
(function() {
|
||||
if (!window)
|
||||
return;
|
||||
}
|
||||
function f() {}
|
||||
function g() {}
|
||||
if ( !document ) {
|
||||
if (!document)
|
||||
return;
|
||||
}
|
||||
function h() {}
|
||||
} )();
|
||||
})();
|
||||
}
|
||||
expect: {
|
||||
( function() {
|
||||
(function() {
|
||||
// NOTE: other compression steps will reduce this
|
||||
// down to just `window`.
|
||||
if ( window )
|
||||
if ( !document );
|
||||
if (!window);
|
||||
else if (!document);
|
||||
function f() {}
|
||||
function g() {}
|
||||
function h() {}
|
||||
} )();
|
||||
})();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -81,18 +77,18 @@ not_hoisted_when_already_nested: {
|
||||
if_return: true,
|
||||
}
|
||||
input: {
|
||||
( function() {
|
||||
if ( !window ) {
|
||||
(function() {
|
||||
if (!window)
|
||||
return;
|
||||
}
|
||||
if ( foo ) function f() {}
|
||||
} )();
|
||||
if (foo) function f() {}
|
||||
})();
|
||||
}
|
||||
expect: {
|
||||
( function() {
|
||||
if ( window )
|
||||
if ( foo ) function f() {}
|
||||
} )();
|
||||
(function() {
|
||||
if (!window);
|
||||
else if (foo)
|
||||
function f() {}
|
||||
})();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -104,15 +100,19 @@ defun_if_return: {
|
||||
input: {
|
||||
function e() {
|
||||
function f() {}
|
||||
if (!window) return;
|
||||
else function g() {}
|
||||
if (!window)
|
||||
return;
|
||||
else
|
||||
function g() {}
|
||||
function h() {}
|
||||
}
|
||||
}
|
||||
expect: {
|
||||
function e() {
|
||||
function f() {}
|
||||
if (window) function g() {}
|
||||
if (!window);
|
||||
else
|
||||
function g() {}
|
||||
function h() {}
|
||||
}
|
||||
}
|
||||
@@ -126,8 +126,10 @@ defun_hoist_funs: {
|
||||
input: {
|
||||
function e() {
|
||||
function f() {}
|
||||
if (!window) return;
|
||||
else function g() {}
|
||||
if (!window)
|
||||
return;
|
||||
else
|
||||
function g() {}
|
||||
function h() {}
|
||||
}
|
||||
}
|
||||
@@ -136,7 +138,7 @@ defun_hoist_funs: {
|
||||
function f() {}
|
||||
function g() {}
|
||||
function h() {}
|
||||
if (window);
|
||||
if (!window);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -149,15 +151,18 @@ defun_else_if_return: {
|
||||
input: {
|
||||
function e() {
|
||||
function f() {}
|
||||
if (window) function g() {}
|
||||
else return;
|
||||
if (window)
|
||||
function g() {}
|
||||
else
|
||||
return;
|
||||
function h() {}
|
||||
}
|
||||
}
|
||||
expect: {
|
||||
function e() {
|
||||
function f() {}
|
||||
if (window) function g() {}
|
||||
if (window)
|
||||
function g() {}
|
||||
function h() {}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -40,6 +40,9 @@ conditional_false_stray_else_in_loop: {
|
||||
console.log(i);
|
||||
}
|
||||
}
|
||||
expect_exact: "for(var i=1;i<=4;++i)if(!(i<=2))console.log(i);"
|
||||
expect_stdout: true
|
||||
expect_exact: "for(var i=1;i<=4;++i)if(i<=2);else console.log(i);"
|
||||
expect_stdout: [
|
||||
"3",
|
||||
"4",
|
||||
]
|
||||
}
|
||||
|
||||
@@ -317,7 +317,35 @@ iife: {
|
||||
typeof function g() {}();
|
||||
}
|
||||
expect: {
|
||||
x = 42, function a() {}(), function b() {}(), function c() {}(),
|
||||
function d() {}(), function e() {}(), function f() {}(), typeof function g() {}();
|
||||
x = 42,
|
||||
function a() {}(),
|
||||
!function b() {}(),
|
||||
~function c() {}(),
|
||||
+function d() {}(),
|
||||
-function e() {}(),
|
||||
void function f() {}(),
|
||||
typeof function g() {}();
|
||||
}
|
||||
}
|
||||
|
||||
iife_drop_side_effect_free: {
|
||||
options = {
|
||||
expression: true,
|
||||
sequences: true,
|
||||
side_effects: true,
|
||||
}
|
||||
input: {
|
||||
x = 42;
|
||||
(function a() {})();
|
||||
!function b() {}();
|
||||
~function c() {}();
|
||||
+function d() {}();
|
||||
-function e() {}();
|
||||
void function f() {}();
|
||||
typeof function g() {}();
|
||||
}
|
||||
expect: {
|
||||
x = 42,
|
||||
typeof void 0;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
issue979_reported: {
|
||||
reported: {
|
||||
options = {
|
||||
booleans: true,
|
||||
comparisons: true,
|
||||
@@ -17,29 +17,26 @@ issue979_reported: {
|
||||
}
|
||||
input: {
|
||||
function f1() {
|
||||
if (a == 1 || b == 2) {
|
||||
if (a == 1 || b == 2)
|
||||
foo();
|
||||
}
|
||||
}
|
||||
function f2() {
|
||||
if (!(a == 1 || b == 2)) {
|
||||
}
|
||||
else {
|
||||
if (!(a == 1 || b == 2));
|
||||
else
|
||||
foo();
|
||||
}
|
||||
}
|
||||
}
|
||||
expect: {
|
||||
function f1() {
|
||||
1!=a&&2!=b||foo();
|
||||
1 != a && 2 != b || foo();
|
||||
}
|
||||
function f2() {
|
||||
1!=a&&2!=b||foo();
|
||||
1 != a && 2 != b || foo();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
issue979_test_negated_is_best: {
|
||||
test_negated_is_best: {
|
||||
options = {
|
||||
booleans: true,
|
||||
comparisons: true,
|
||||
@@ -58,53 +55,47 @@ issue979_test_negated_is_best: {
|
||||
}
|
||||
input: {
|
||||
function f3() {
|
||||
if (a == 1 | b == 2) {
|
||||
if (a == 1 | b == 2)
|
||||
foo();
|
||||
}
|
||||
}
|
||||
function f4() {
|
||||
if (!(a == 1 | b == 2)) {
|
||||
}
|
||||
else {
|
||||
if (!(a == 1 | b == 2));
|
||||
else
|
||||
foo();
|
||||
}
|
||||
}
|
||||
function f5() {
|
||||
if (a == 1 && b == 2) {
|
||||
if (a == 1 && b == 2)
|
||||
foo();
|
||||
}
|
||||
}
|
||||
function f6() {
|
||||
if (!(a == 1 && b == 2)) {
|
||||
}
|
||||
else {
|
||||
if (!(a == 1 && b == 2));
|
||||
else
|
||||
foo();
|
||||
}
|
||||
}
|
||||
function f7() {
|
||||
if (a == 1 || b == 2) {
|
||||
if (a == 1 || b == 2)
|
||||
foo();
|
||||
}
|
||||
else {
|
||||
else
|
||||
return bar();
|
||||
}
|
||||
}
|
||||
}
|
||||
expect: {
|
||||
function f3() {
|
||||
1==a|2==b&&foo();
|
||||
1 == a | 2 == b && foo();
|
||||
}
|
||||
function f4() {
|
||||
1==a|2==b&&foo();
|
||||
1 == a | 2 == b && foo();
|
||||
}
|
||||
function f5() {
|
||||
1==a&&2==b&&foo();
|
||||
1 == a && 2 == b && foo();
|
||||
}
|
||||
function f6() {
|
||||
1!=a||2!=b||foo();
|
||||
1 == a && 2 == b && foo();
|
||||
}
|
||||
function f7() {
|
||||
if(1!=a&&2!=b)return bar();foo()
|
||||
if (1 != a && 2 != b)
|
||||
return bar();
|
||||
foo();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1144,7 +1144,7 @@ conditional_assignments_3: {
|
||||
expect_stdout: "PASS"
|
||||
}
|
||||
|
||||
issue_3856: {
|
||||
issue_3856_1: {
|
||||
options = {
|
||||
booleans: true,
|
||||
conditionals: true,
|
||||
@@ -1169,9 +1169,46 @@ issue_3856: {
|
||||
console.log(function() {
|
||||
(function() {
|
||||
var a, b;
|
||||
if (a) return a, 1;
|
||||
for (a = 0; !console;);
|
||||
return 0;
|
||||
if (a) a;
|
||||
else {
|
||||
a = 0;
|
||||
for (; !console;);
|
||||
}
|
||||
})();
|
||||
}());
|
||||
}
|
||||
expect_stdout: "undefined"
|
||||
}
|
||||
|
||||
issue_3856_2: {
|
||||
options = {
|
||||
booleans: true,
|
||||
conditionals: true,
|
||||
if_return: true,
|
||||
join_vars: true,
|
||||
passes: 2,
|
||||
sequences: true,
|
||||
side_effects: true,
|
||||
}
|
||||
input: {
|
||||
console.log(function() {
|
||||
(function() {
|
||||
var a;
|
||||
if (!a) {
|
||||
a = 0;
|
||||
for (var b; !console;);
|
||||
return 0;
|
||||
}
|
||||
if (a) return 1;
|
||||
})();
|
||||
}());
|
||||
}
|
||||
expect: {
|
||||
console.log(function() {
|
||||
(function() {
|
||||
var a, b;
|
||||
if (!a)
|
||||
for (a = 0; !console;);
|
||||
})();
|
||||
}());
|
||||
}
|
||||
|
||||
@@ -1258,8 +1258,7 @@ issues_3267_1: {
|
||||
}
|
||||
expect: {
|
||||
!function() {
|
||||
var i = Object();
|
||||
if (i)
|
||||
if (Object())
|
||||
return console.log("PASS");
|
||||
throw "FAIL";
|
||||
}();
|
||||
|
||||
@@ -111,6 +111,7 @@ labels_5: {
|
||||
labels_6: {
|
||||
options = {
|
||||
dead_code: true,
|
||||
unused: true,
|
||||
}
|
||||
input: {
|
||||
out: break out;
|
||||
@@ -208,6 +209,59 @@ labels_10: {
|
||||
expect_stdout: "PASS"
|
||||
}
|
||||
|
||||
labels_11: {
|
||||
options = {
|
||||
conditionals: true,
|
||||
if_return: true,
|
||||
unused: true,
|
||||
}
|
||||
input: {
|
||||
L: if (console.log("PASS"))
|
||||
break L;
|
||||
}
|
||||
expect: {
|
||||
console.log("PASS");
|
||||
}
|
||||
expect_stdout: "PASS"
|
||||
}
|
||||
|
||||
labels_12: {
|
||||
options = {
|
||||
conditionals: true,
|
||||
dead_code: true,
|
||||
if_return: true,
|
||||
}
|
||||
input: {
|
||||
L: try {
|
||||
if (console.log("foo"))
|
||||
break L;
|
||||
throw "bar";
|
||||
} catch (e) {
|
||||
console.log(e);
|
||||
break L;
|
||||
} finally {
|
||||
if (console.log("baz"))
|
||||
break L;
|
||||
}
|
||||
}
|
||||
expect: {
|
||||
L: try {
|
||||
if (!console.log("foo"))
|
||||
throw "bar";
|
||||
} catch (e) {
|
||||
console.log(e);
|
||||
} finally {
|
||||
if (console.log("baz"))
|
||||
break L;
|
||||
}
|
||||
}
|
||||
expect_stdout: [
|
||||
"foo",
|
||||
"bar",
|
||||
"baz",
|
||||
]
|
||||
}
|
||||
|
||||
issue_4466_1: {
|
||||
mangle = {
|
||||
v8: false,
|
||||
@@ -327,3 +381,53 @@ issue_4466_2_toplevel_v8: {
|
||||
}
|
||||
expect_stdout: "PASS"
|
||||
}
|
||||
|
||||
issue_5522: {
|
||||
options = {
|
||||
dead_code: true,
|
||||
}
|
||||
input: {
|
||||
console.log(function() {
|
||||
L: try {
|
||||
return "FAIL";
|
||||
} finally {
|
||||
break L;
|
||||
}
|
||||
return "PASS";
|
||||
}());
|
||||
}
|
||||
expect: {
|
||||
console.log(function() {
|
||||
L: try {
|
||||
return "FAIL";
|
||||
} finally {
|
||||
break L;
|
||||
}
|
||||
return "PASS";
|
||||
}());
|
||||
}
|
||||
expect_stdout: "PASS"
|
||||
}
|
||||
|
||||
issue_5524: {
|
||||
options = {
|
||||
dead_code: true,
|
||||
}
|
||||
input: {
|
||||
L: try {
|
||||
FAIL;
|
||||
} finally {
|
||||
break L;
|
||||
}
|
||||
console.log("PASS");
|
||||
}
|
||||
expect: {
|
||||
L: try {
|
||||
FAIL;
|
||||
} finally {
|
||||
break L;
|
||||
}
|
||||
console.log("PASS");
|
||||
}
|
||||
expect_stdout: "PASS"
|
||||
}
|
||||
|
||||
@@ -190,6 +190,96 @@ if_dead_branch: {
|
||||
node_version: ">=4"
|
||||
}
|
||||
|
||||
retain_tail_1: {
|
||||
options = {
|
||||
conditionals: true,
|
||||
}
|
||||
input: {
|
||||
"use strict";
|
||||
function f(a) {
|
||||
var b = "foo";
|
||||
if (a) {
|
||||
let b = "bar";
|
||||
while (console.log("baz"));
|
||||
console.log(b);
|
||||
} else {
|
||||
while (console.log("moo"));
|
||||
console.log(b);
|
||||
}
|
||||
}
|
||||
f();
|
||||
f(42);
|
||||
}
|
||||
expect: {
|
||||
"use strict";
|
||||
function f(a) {
|
||||
var b = "foo";
|
||||
if (a) {
|
||||
let b = "bar";
|
||||
while (console.log("baz"));
|
||||
console.log(b);
|
||||
} else {
|
||||
while (console.log("moo"));
|
||||
console.log(b);
|
||||
}
|
||||
}
|
||||
f();
|
||||
f(42);
|
||||
}
|
||||
expect_stdout: [
|
||||
"moo",
|
||||
"foo",
|
||||
"baz",
|
||||
"bar",
|
||||
]
|
||||
node_version: ">=4"
|
||||
}
|
||||
|
||||
retain_tail_2: {
|
||||
options = {
|
||||
conditionals: true,
|
||||
}
|
||||
input: {
|
||||
"use strict";
|
||||
function f(a) {
|
||||
var b = "foo";
|
||||
if (a) {
|
||||
while (console.log("bar"));
|
||||
console.log(b);
|
||||
} else {
|
||||
let b = "baz";
|
||||
while (console.log("moo"));
|
||||
console.log(b);
|
||||
}
|
||||
}
|
||||
f();
|
||||
f(42);
|
||||
}
|
||||
expect: {
|
||||
"use strict";
|
||||
function f(a) {
|
||||
var b = "foo";
|
||||
if (a) {
|
||||
while (console.log("bar"));
|
||||
console.log(b);
|
||||
} else {
|
||||
let b = "baz";
|
||||
while (console.log("moo"));
|
||||
console.log(b);
|
||||
}
|
||||
}
|
||||
f();
|
||||
f(42);
|
||||
}
|
||||
expect_stdout: [
|
||||
"moo",
|
||||
"baz",
|
||||
"bar",
|
||||
"foo",
|
||||
]
|
||||
node_version: ">=4"
|
||||
}
|
||||
|
||||
merge_vars_1: {
|
||||
options = {
|
||||
merge_vars: true,
|
||||
@@ -892,6 +982,40 @@ if_return_2: {
|
||||
node_version: ">=4"
|
||||
}
|
||||
|
||||
if_return_3: {
|
||||
options = {
|
||||
if_return: true,
|
||||
}
|
||||
input: {
|
||||
"use strict";
|
||||
var a = "PASS";
|
||||
function f(b) {
|
||||
if (console) {
|
||||
let b = a;
|
||||
return b;
|
||||
} else
|
||||
while (console.log("FAIL 1"));
|
||||
return b;
|
||||
}
|
||||
console.log(f("FAIL 2"));
|
||||
}
|
||||
expect: {
|
||||
"use strict";
|
||||
var a = "PASS";
|
||||
function f(b) {
|
||||
if (console) {
|
||||
let b = a;
|
||||
return b;
|
||||
} else
|
||||
while (console.log("FAIL 1"));
|
||||
return b;
|
||||
}
|
||||
console.log(f("FAIL 2"));
|
||||
}
|
||||
expect_stdout: "PASS"
|
||||
node_version: ">=4"
|
||||
}
|
||||
|
||||
do_if_continue_1: {
|
||||
options = {
|
||||
if_return: true,
|
||||
@@ -912,8 +1036,7 @@ do_if_continue_1: {
|
||||
expect: {
|
||||
"use strict";
|
||||
do {
|
||||
if (!console);
|
||||
else {
|
||||
if (console) {
|
||||
console.log("PASS");
|
||||
{
|
||||
let a = 0;
|
||||
@@ -946,8 +1069,7 @@ do_if_continue_2: {
|
||||
expect: {
|
||||
"use strict";
|
||||
do {
|
||||
if (!console);
|
||||
else {
|
||||
if (console) {
|
||||
console.log("FAIL");
|
||||
{
|
||||
let a = 0;
|
||||
@@ -1606,48 +1728,6 @@ issue_4305_2: {
|
||||
node_version: ">=4"
|
||||
}
|
||||
|
||||
issue_1753: {
|
||||
mangle = {
|
||||
toplevel: false,
|
||||
webkit: true,
|
||||
}
|
||||
input: {
|
||||
"use strict";
|
||||
let l = null;
|
||||
for (let i = 0; i < 1; i++)
|
||||
console.log(i);
|
||||
}
|
||||
expect: {
|
||||
"use strict";
|
||||
let l = null;
|
||||
for (let i = 0; i < 1; i++)
|
||||
console.log(i);
|
||||
}
|
||||
expect_stdout: "0"
|
||||
node_version: ">=4"
|
||||
}
|
||||
|
||||
issue_1753_toplevel: {
|
||||
mangle = {
|
||||
toplevel: true,
|
||||
webkit: true,
|
||||
}
|
||||
input: {
|
||||
"use strict";
|
||||
let l = null;
|
||||
for (let i = 0; i < 1; i++)
|
||||
console.log(i);
|
||||
}
|
||||
expect: {
|
||||
"use strict";
|
||||
let l = null;
|
||||
for (let e = 0; e < 1; e++)
|
||||
console.log(e);
|
||||
}
|
||||
expect_stdout: "0"
|
||||
node_version: ">=4"
|
||||
}
|
||||
|
||||
issue_4438: {
|
||||
options = {
|
||||
if_return: true,
|
||||
@@ -1667,11 +1747,9 @@ issue_4438: {
|
||||
expect: {
|
||||
"use strict";
|
||||
function f() {
|
||||
if (!console)
|
||||
;
|
||||
else {
|
||||
if (console) {
|
||||
let a = console.log;
|
||||
void a("PASS");
|
||||
a("PASS");
|
||||
}
|
||||
}
|
||||
f();
|
||||
@@ -1757,6 +1835,7 @@ issue_4689: {
|
||||
|
||||
issue_4691: {
|
||||
options = {
|
||||
conditionals: true,
|
||||
if_return: true,
|
||||
toplevel: true,
|
||||
}
|
||||
@@ -1973,3 +2052,73 @@ issue_5260: {
|
||||
]
|
||||
node_version: ">=4"
|
||||
}
|
||||
|
||||
issue_5319: {
|
||||
options = {
|
||||
collapse_vars: true,
|
||||
merge_vars: true,
|
||||
}
|
||||
input: {
|
||||
"use strict";
|
||||
(function(a, c) {
|
||||
var b = a, c = b;
|
||||
{
|
||||
let a = c;
|
||||
console.log(c());
|
||||
}
|
||||
})(function() {
|
||||
return "PASS";
|
||||
});
|
||||
}
|
||||
expect: {
|
||||
"use strict";
|
||||
(function(a, c) {
|
||||
var b = a, c;
|
||||
{
|
||||
let a = c = b;
|
||||
console.log(c());
|
||||
}
|
||||
})(function() {
|
||||
return "PASS";
|
||||
});
|
||||
}
|
||||
expect_stdout: "PASS"
|
||||
node_version: ">=4"
|
||||
}
|
||||
|
||||
issue_5338: {
|
||||
options = {
|
||||
unused: true,
|
||||
}
|
||||
input: {
|
||||
"use strict";
|
||||
let a = a;
|
||||
}
|
||||
expect: {
|
||||
"use strict";
|
||||
a;
|
||||
let a;
|
||||
}
|
||||
expect_stdout: ReferenceError("a is not defined")
|
||||
node_version: ">=4"
|
||||
}
|
||||
|
||||
issue_5476: {
|
||||
mangle = {
|
||||
keep_fargs: true,
|
||||
}
|
||||
input: {
|
||||
"use strict";
|
||||
console.log(function(n) {
|
||||
let a;
|
||||
}());
|
||||
}
|
||||
expect: {
|
||||
"use strict";
|
||||
console.log(function(n) {
|
||||
let o;
|
||||
}());
|
||||
}
|
||||
expect_stdout: "undefined"
|
||||
node_version: ">=4"
|
||||
}
|
||||
|
||||
@@ -37,6 +37,51 @@ just_enough: {
|
||||
expect_warnings: []
|
||||
}
|
||||
|
||||
drop_semicolon: {
|
||||
beautify = {
|
||||
max_line_len: 5,
|
||||
semicolons: true,
|
||||
}
|
||||
input: {
|
||||
var a;
|
||||
console.log(a || 42);
|
||||
}
|
||||
expect_exact: [
|
||||
"var a",
|
||||
"console.log(",
|
||||
"a||42",
|
||||
");",
|
||||
]
|
||||
expect_stdout: "42"
|
||||
expect_warnings: [
|
||||
"WARN: Output exceeds 5 characters",
|
||||
]
|
||||
}
|
||||
|
||||
template_newline: {
|
||||
beautify = {
|
||||
max_line_len: 2,
|
||||
}
|
||||
input: {
|
||||
console.log(`foo
|
||||
bar`);
|
||||
}
|
||||
expect_exact: [
|
||||
"console.log(",
|
||||
"`foo",
|
||||
"bar`",
|
||||
");",
|
||||
]
|
||||
expect_stdout: [
|
||||
"foo",
|
||||
"bar",
|
||||
]
|
||||
expect_warnings: [
|
||||
"WARN: Output exceeds 2 characters",
|
||||
]
|
||||
node_version: ">=4"
|
||||
}
|
||||
|
||||
issue_304: {
|
||||
beautify = {
|
||||
max_line_len: 10,
|
||||
|
||||
@@ -169,6 +169,158 @@ conditional_branch: {
|
||||
expect_stdout: "PASS"
|
||||
}
|
||||
|
||||
conditional_chain_1: {
|
||||
options = {
|
||||
merge_vars: true,
|
||||
}
|
||||
input: {
|
||||
function f(a, b) {
|
||||
var c, d;
|
||||
if (a && (c = a))
|
||||
console.log(c);
|
||||
else
|
||||
b || (d = b) ? console.log("foo") : console.log(d);
|
||||
}
|
||||
f("", null);
|
||||
f("", true);
|
||||
f(42, null);
|
||||
f(42, true);
|
||||
}
|
||||
expect: {
|
||||
function f(a, b) {
|
||||
var a, a;
|
||||
if (a && (a = a))
|
||||
console.log(a);
|
||||
else
|
||||
b || (a = b) ? console.log("foo") : console.log(a);
|
||||
}
|
||||
f("", null);
|
||||
f("", true);
|
||||
f(42, null);
|
||||
f(42, true);
|
||||
}
|
||||
expect_stdout: [
|
||||
"null",
|
||||
"foo",
|
||||
"42",
|
||||
"42",
|
||||
]
|
||||
}
|
||||
|
||||
conditional_chain_2: {
|
||||
options = {
|
||||
merge_vars: true,
|
||||
}
|
||||
input: {
|
||||
function f(a, b) {
|
||||
var c, d;
|
||||
if (a && (c = a))
|
||||
console.log(c);
|
||||
else
|
||||
b || (d = b) ? console.log(c) : console.log(d);
|
||||
}
|
||||
f("", null);
|
||||
f("", true);
|
||||
f(42, null);
|
||||
f(42, true);
|
||||
}
|
||||
expect: {
|
||||
function f(a, b) {
|
||||
var c, a;
|
||||
if (a && (c = a))
|
||||
console.log(c);
|
||||
else
|
||||
b || (a = b) ? console.log(c) : console.log(a);
|
||||
}
|
||||
f("", null);
|
||||
f("", true);
|
||||
f(42, null);
|
||||
f(42, true);
|
||||
}
|
||||
expect_stdout: [
|
||||
"null",
|
||||
"undefined",
|
||||
"42",
|
||||
"42",
|
||||
]
|
||||
}
|
||||
|
||||
conditional_chain_3: {
|
||||
options = {
|
||||
merge_vars: true,
|
||||
}
|
||||
input: {
|
||||
function f(a, b) {
|
||||
var c, d;
|
||||
if (a && (c = a) || b || (d = b))
|
||||
console.log(c);
|
||||
else
|
||||
console.log(d);
|
||||
}
|
||||
f("", null);
|
||||
f("", true);
|
||||
f(42, null);
|
||||
f(42, true);
|
||||
}
|
||||
expect: {
|
||||
function f(a, b) {
|
||||
var c, a;
|
||||
if (a && (c = a) || b || (a = b))
|
||||
console.log(c);
|
||||
else
|
||||
console.log(a);
|
||||
}
|
||||
f("", null);
|
||||
f("", true);
|
||||
f(42, null);
|
||||
f(42, true);
|
||||
}
|
||||
expect_stdout: [
|
||||
"null",
|
||||
"undefined",
|
||||
"42",
|
||||
"42",
|
||||
]
|
||||
}
|
||||
|
||||
conditional_chain_4: {
|
||||
options = {
|
||||
merge_vars: true,
|
||||
}
|
||||
input: {
|
||||
function f(a, b) {
|
||||
var c, d;
|
||||
if (a && b ? c = a : d = b)
|
||||
console.log(c);
|
||||
else
|
||||
console.log(d);
|
||||
}
|
||||
f("", null);
|
||||
f("", true);
|
||||
f(42, null);
|
||||
f(42, true);
|
||||
}
|
||||
expect: {
|
||||
function f(a, b) {
|
||||
var c, d;
|
||||
if (a && b ? c = a : d = b)
|
||||
console.log(c);
|
||||
else
|
||||
console.log(d);
|
||||
}
|
||||
f("", null);
|
||||
f("", true);
|
||||
f(42, null);
|
||||
f(42, true);
|
||||
}
|
||||
expect_stdout: [
|
||||
"null",
|
||||
"undefined",
|
||||
"null",
|
||||
"42",
|
||||
]
|
||||
}
|
||||
|
||||
if_branch: {
|
||||
options = {
|
||||
merge_vars: true,
|
||||
@@ -253,6 +405,7 @@ read_before_assign_1: {
|
||||
inline: true,
|
||||
merge_vars: true,
|
||||
sequences: true,
|
||||
side_effects: true,
|
||||
toplevel: true,
|
||||
}
|
||||
input: {
|
||||
@@ -3549,3 +3702,146 @@ issue_5182: {
|
||||
]
|
||||
node_version: ">=4"
|
||||
}
|
||||
|
||||
issue_5420: {
|
||||
options = {
|
||||
merge_vars: true,
|
||||
toplevel: true,
|
||||
}
|
||||
input: {
|
||||
do {
|
||||
var a = "FAIL 1";
|
||||
a && a.p;
|
||||
a = "FAIL 2";
|
||||
try {
|
||||
continue;
|
||||
} catch (e) {}
|
||||
var b = "FAIL 3";
|
||||
} while (console.log(b || "PASS"));
|
||||
}
|
||||
expect: {
|
||||
do {
|
||||
var a = "FAIL 1";
|
||||
a && a.p;
|
||||
a = "FAIL 2";
|
||||
try {
|
||||
continue;
|
||||
} catch (e) {}
|
||||
var b = "FAIL 3";
|
||||
} while (console.log(b || "PASS"));
|
||||
}
|
||||
expect_stdout: "PASS"
|
||||
}
|
||||
|
||||
issue_5451: {
|
||||
options = {
|
||||
merge_vars: true,
|
||||
toplevel: true,
|
||||
}
|
||||
input: {
|
||||
A = 1;
|
||||
var a = 1, b;
|
||||
console.log(function f() {
|
||||
return a-- && f(b = A, b);
|
||||
}());
|
||||
}
|
||||
expect: {
|
||||
A = 1;
|
||||
var a = 1, b;
|
||||
console.log(function f() {
|
||||
return a-- && f(b = A, b);
|
||||
}());
|
||||
}
|
||||
expect_stdout: "0"
|
||||
}
|
||||
|
||||
issue_5471_1: {
|
||||
options = {
|
||||
conditionals: true,
|
||||
inline: true,
|
||||
merge_vars: true,
|
||||
reduce_vars: true,
|
||||
sequences: true,
|
||||
side_effects: true,
|
||||
toplevel: true,
|
||||
unused: true,
|
||||
}
|
||||
input: {
|
||||
var a = "FAIL 1";
|
||||
function f(b, c) {
|
||||
function g() {
|
||||
if (console)
|
||||
return 42;
|
||||
else
|
||||
c = "FAIL 2";
|
||||
}
|
||||
var d = g();
|
||||
console.log(c || "PASS");
|
||||
var e = function h() {
|
||||
while (b && e);
|
||||
}();
|
||||
}
|
||||
f(a++) && a;
|
||||
}
|
||||
expect: {
|
||||
var a = "FAIL 1";
|
||||
var b, c, e;
|
||||
b = +a,
|
||||
function() {
|
||||
if (console)
|
||||
return;
|
||||
c = "FAIL 2";
|
||||
}(),
|
||||
console.log(c || "PASS"),
|
||||
e = function() {
|
||||
while (b && e);
|
||||
}();
|
||||
}
|
||||
expect_stdout: "PASS"
|
||||
}
|
||||
|
||||
issue_5471_2: {
|
||||
options = {
|
||||
conditionals: true,
|
||||
evaluate: true,
|
||||
inline: true,
|
||||
merge_vars: true,
|
||||
reduce_vars: true,
|
||||
sequences: true,
|
||||
toplevel: true,
|
||||
unused: true,
|
||||
}
|
||||
input: {
|
||||
var a = "FAIL 1";
|
||||
function f(b, c) {
|
||||
function g() {
|
||||
if (console)
|
||||
return 42;
|
||||
else
|
||||
c = "FAIL 2";
|
||||
}
|
||||
var d = g();
|
||||
console.log(c || "PASS");
|
||||
var e = function h() {
|
||||
while (b && e);
|
||||
}();
|
||||
}
|
||||
f(a++) && a;
|
||||
}
|
||||
expect: {
|
||||
var a = "FAIL 1";
|
||||
var b, c, e;
|
||||
b = +a,
|
||||
function() {
|
||||
if (console)
|
||||
return;
|
||||
c = "FAIL 2";
|
||||
}(),
|
||||
console.log(c || "PASS"),
|
||||
e = function() {
|
||||
while (b && e);
|
||||
}(),
|
||||
void 0;
|
||||
}
|
||||
expect_stdout: "PASS"
|
||||
}
|
||||
|
||||
@@ -122,13 +122,41 @@ negate_iife_4: {
|
||||
sequences: true,
|
||||
}
|
||||
input: {
|
||||
(function(){ return t })() ? console.log(true) : console.log(false);
|
||||
(function(){
|
||||
(function() {
|
||||
return t;
|
||||
})() ? console.log(true) : console.log(false);
|
||||
(function() {
|
||||
console.log("something");
|
||||
})();
|
||||
}
|
||||
expect: {
|
||||
!function(){ return t }() ? console.log(false) : console.log(true), function(){
|
||||
!function() {
|
||||
return t;
|
||||
}() ? console.log(false) : console.log(true), !function() {
|
||||
console.log("something");
|
||||
}();
|
||||
}
|
||||
}
|
||||
|
||||
negate_iife_4_drop_side_effect_free: {
|
||||
options = {
|
||||
conditionals: true,
|
||||
negate_iife: true,
|
||||
sequences: true,
|
||||
side_effects: true,
|
||||
}
|
||||
input: {
|
||||
(function() {
|
||||
return t;
|
||||
})() ? console.log(true) : console.log(false);
|
||||
(function() {
|
||||
console.log("something");
|
||||
})();
|
||||
}
|
||||
expect: {
|
||||
!function() {
|
||||
return t;
|
||||
}() ? console.log(false) : console.log(true), function() {
|
||||
console.log("something");
|
||||
}();
|
||||
}
|
||||
@@ -176,17 +204,49 @@ negate_iife_5: {
|
||||
sequences: true,
|
||||
}
|
||||
input: {
|
||||
if ((function(){ return t })()) {
|
||||
if (function() {
|
||||
return t;
|
||||
}()) {
|
||||
foo(true);
|
||||
} else {
|
||||
bar(false);
|
||||
}
|
||||
(function(){
|
||||
(function() {
|
||||
console.log("something");
|
||||
})();
|
||||
}
|
||||
expect: {
|
||||
!function(){ return t }() ? bar(false) : foo(true), function(){
|
||||
!function() {
|
||||
return t;
|
||||
}() ? bar(false) : foo(true), !function() {
|
||||
console.log("something");
|
||||
}();
|
||||
}
|
||||
}
|
||||
|
||||
negate_iife_5_drop_side_effect_free: {
|
||||
options = {
|
||||
conditionals: true,
|
||||
negate_iife: true,
|
||||
sequences: true,
|
||||
side_effects: true,
|
||||
}
|
||||
input: {
|
||||
if (function() {
|
||||
return t;
|
||||
}()) {
|
||||
foo(true);
|
||||
} else {
|
||||
bar(false);
|
||||
}
|
||||
(function() {
|
||||
console.log("something");
|
||||
})();
|
||||
}
|
||||
expect: {
|
||||
!function() {
|
||||
return t;
|
||||
}() ? bar(false) : foo(true), function() {
|
||||
console.log("something");
|
||||
}();
|
||||
}
|
||||
|
||||
@@ -308,6 +308,7 @@ issue_4679: {
|
||||
issue_5266: {
|
||||
options = {
|
||||
inline: true,
|
||||
side_effects: true,
|
||||
}
|
||||
input: {
|
||||
[
|
||||
|
||||
@@ -842,9 +842,9 @@ unary_binary_parentheses: {
|
||||
v.forEach(function(x) {
|
||||
v.forEach(function(y) {
|
||||
console.log(
|
||||
+x*y,
|
||||
+x/y,
|
||||
+x%y,
|
||||
x*y,
|
||||
x/y,
|
||||
x%y,
|
||||
-x*y,
|
||||
-x/y,
|
||||
-x%y
|
||||
@@ -1397,7 +1397,7 @@ issue_3695: {
|
||||
}
|
||||
expect: {
|
||||
var a = [];
|
||||
console.log(+(a * (a[0] = false)));
|
||||
console.log(a * (a[0] = false));
|
||||
}
|
||||
expect_stdout: "NaN"
|
||||
}
|
||||
|
||||
@@ -97,10 +97,10 @@ return_5: {
|
||||
}
|
||||
expect_exact: [
|
||||
"_is_selected=function(tags,slug){",
|
||||
"var ref",
|
||||
"var ref;",
|
||||
"",
|
||||
"",
|
||||
";return null!=(ref=_.find(tags,{slug:slug}))?ref.selected:void 0};",
|
||||
"return null!=(ref=_.find(tags,{slug:slug}))?ref.selected:void 0};",
|
||||
]
|
||||
}
|
||||
|
||||
@@ -146,10 +146,10 @@ return_7: {
|
||||
}
|
||||
expect_exact: [
|
||||
"_is_selected=function(e,l){",
|
||||
"var n",
|
||||
"var n;",
|
||||
"",
|
||||
"",
|
||||
";return null!=(n=_.find(e,{slug:l}))?n.selected:void 0};",
|
||||
"return null!=(n=_.find(e,{slug:l}))?n.selected:void 0};",
|
||||
]
|
||||
}
|
||||
|
||||
|
||||
@@ -147,7 +147,7 @@ relational: {
|
||||
"bar" >= "bar";
|
||||
}
|
||||
expect: {
|
||||
bar();
|
||||
0 instanceof bar();
|
||||
bar();
|
||||
bar(), bar();
|
||||
bar();
|
||||
|
||||
@@ -1289,6 +1289,7 @@ issue_2878: {
|
||||
collapse_vars: true,
|
||||
pure_getters: true,
|
||||
sequences: true,
|
||||
side_effects: true,
|
||||
}
|
||||
input: {
|
||||
var c = 0;
|
||||
|
||||
@@ -6,6 +6,7 @@ reduce_vars: {
|
||||
C: 0,
|
||||
},
|
||||
inline: true,
|
||||
passes: 2,
|
||||
reduce_funcs: true,
|
||||
reduce_vars: true,
|
||||
toplevel: true,
|
||||
@@ -6688,8 +6689,7 @@ issues_3267_1: {
|
||||
}
|
||||
expect: {
|
||||
!function(x) {
|
||||
var i = Object();
|
||||
if (i)
|
||||
if (Object())
|
||||
return console.log("PASS");
|
||||
throw "FAIL";
|
||||
}();
|
||||
@@ -7832,3 +7832,67 @@ issue_5055_2: {
|
||||
}
|
||||
expect_stdout: "PASS"
|
||||
}
|
||||
|
||||
issue_5324: {
|
||||
options = {
|
||||
inline: true,
|
||||
merge_vars: true,
|
||||
reduce_vars: true,
|
||||
toplevel: true,
|
||||
unused: true,
|
||||
}
|
||||
input: {
|
||||
A = 0;
|
||||
do {
|
||||
var a, b = A;
|
||||
for (a in b)
|
||||
var c = b;
|
||||
} while (function() {
|
||||
var d;
|
||||
console.log(d *= A);
|
||||
}());
|
||||
}
|
||||
expect: {
|
||||
A = 0;
|
||||
do {
|
||||
var a, b = A;
|
||||
for (a in b);
|
||||
} while (b = void 0, void console.log(b *= A));
|
||||
}
|
||||
expect_stdout: "NaN"
|
||||
}
|
||||
|
||||
issue_5434: {
|
||||
options = {
|
||||
evaluate: true,
|
||||
reduce_vars: true,
|
||||
unused: true,
|
||||
}
|
||||
input: {
|
||||
console.log(function(a) {
|
||||
for (var i = 0; i < 2; i++) {
|
||||
var b = "FAIL";
|
||||
f && f();
|
||||
a = b;
|
||||
var f = function() {
|
||||
b = "PASS";
|
||||
};
|
||||
}
|
||||
return a;
|
||||
}());
|
||||
}
|
||||
expect: {
|
||||
console.log(function(a) {
|
||||
for (var i = 0; i < 2; i++) {
|
||||
var b = "FAIL";
|
||||
f && f();
|
||||
a = b;
|
||||
var f = function() {
|
||||
b = "PASS";
|
||||
};
|
||||
}
|
||||
return a;
|
||||
}());
|
||||
}
|
||||
expect_stdout: "PASS"
|
||||
}
|
||||
|
||||
@@ -50,6 +50,22 @@ regexp_properties: {
|
||||
expect_stdout: "abc true false 0 false"
|
||||
}
|
||||
|
||||
instanceof_1: {
|
||||
input: {
|
||||
console.log(/foo/ instanceof RegExp);
|
||||
}
|
||||
expect_exact: "console.log(/foo/ instanceof RegExp);"
|
||||
expect_stdout: "true"
|
||||
}
|
||||
|
||||
instanceof_2: {
|
||||
input: {
|
||||
console.log(42 + /foo/ instanceof Object);
|
||||
}
|
||||
expect_exact: "console.log(42+/foo/ instanceof Object);"
|
||||
expect_stdout: "false"
|
||||
}
|
||||
|
||||
issue_3434_1: {
|
||||
options = {
|
||||
evaluate: true,
|
||||
|
||||
@@ -349,6 +349,7 @@ retain_funarg_destructured_object_1: {
|
||||
|
||||
retain_funarg_destructured_object_2: {
|
||||
options = {
|
||||
keep_fargs: false,
|
||||
unused: true,
|
||||
}
|
||||
input: {
|
||||
@@ -647,7 +648,7 @@ drop_new_function: {
|
||||
}
|
||||
expect: {
|
||||
void ([ ... {
|
||||
[console.log("PASS")]: [].e,
|
||||
[console.log("PASS")]: [][0],
|
||||
}] = []);
|
||||
}
|
||||
expect_stdout: "PASS"
|
||||
@@ -1048,7 +1049,9 @@ issue_5100_1: {
|
||||
p: {},
|
||||
...a
|
||||
} = [ {
|
||||
p: [ a = 42["q"] ],
|
||||
p: {
|
||||
q: a,
|
||||
} = 42,
|
||||
r: "PASS",
|
||||
} ][0]);
|
||||
console.log(a.r);
|
||||
@@ -1081,7 +1084,9 @@ issue_5100_2: {
|
||||
p: {},
|
||||
...a
|
||||
} = [ {
|
||||
p: [ console.log("PASS"), a = 42["q"] ],
|
||||
p: (console.log("PASS"), {
|
||||
q: a,
|
||||
} = 42),
|
||||
} ][0]);
|
||||
}
|
||||
expect_stdout: "PASS"
|
||||
@@ -1091,6 +1096,7 @@ issue_5100_2: {
|
||||
issue_5108: {
|
||||
options = {
|
||||
evaluate: true,
|
||||
keep_fargs: false,
|
||||
reduce_vars: true,
|
||||
rests: true,
|
||||
unsafe: true,
|
||||
@@ -1102,9 +1108,7 @@ issue_5108: {
|
||||
}([ "PASS", "FAIL" ]));
|
||||
}
|
||||
expect: {
|
||||
console.log(function([]) {
|
||||
return "PASS";
|
||||
}([]));
|
||||
console.log("PASS");
|
||||
}
|
||||
expect_stdout: "PASS"
|
||||
node_version: ">=6"
|
||||
@@ -1208,6 +1212,7 @@ issue_5165_2: {
|
||||
|
||||
issue_5246_1: {
|
||||
options = {
|
||||
keep_fargs: false,
|
||||
reduce_vars: true,
|
||||
rests: true,
|
||||
unused: true,
|
||||
@@ -1218,9 +1223,9 @@ issue_5246_1: {
|
||||
}([ , function(){} ])[0]);
|
||||
}
|
||||
expect: {
|
||||
console.log(typeof function([]) {
|
||||
console.log(typeof function() {
|
||||
return this && [ function(){} ];
|
||||
}([])[0]);
|
||||
}()[0]);
|
||||
}
|
||||
expect_stdout: "function"
|
||||
node_version: ">=6"
|
||||
@@ -1228,6 +1233,7 @@ issue_5246_1: {
|
||||
|
||||
issue_5246_2: {
|
||||
options = {
|
||||
keep_fargs: false,
|
||||
reduce_vars: true,
|
||||
rests: true,
|
||||
toplevel: true,
|
||||
@@ -1249,6 +1255,7 @@ issue_5246_2: {
|
||||
|
||||
issue_5246_3: {
|
||||
options = {
|
||||
keep_fargs: false,
|
||||
unused: true,
|
||||
}
|
||||
input: {
|
||||
@@ -1264,3 +1271,356 @@ issue_5246_3: {
|
||||
expect_stdout: "PASS"
|
||||
node_version: ">=6"
|
||||
}
|
||||
|
||||
issue_5360: {
|
||||
options = {
|
||||
keep_fargs: false,
|
||||
pure_getters: "strict",
|
||||
unused: true,
|
||||
}
|
||||
input: {
|
||||
var a;
|
||||
console.log(function({ p: {}, ...b }) {
|
||||
return b.q;
|
||||
}({
|
||||
p: ~a && ([ a ] = []),
|
||||
q: "PASS",
|
||||
}));
|
||||
}
|
||||
expect: {
|
||||
var a;
|
||||
console.log(function({ p: {}, ...b }) {
|
||||
return b.q;
|
||||
}({
|
||||
p: ~a && ([ a ] = []),
|
||||
q: "PASS",
|
||||
}));
|
||||
}
|
||||
expect_stdout: "PASS"
|
||||
node_version: ">=8.3.0"
|
||||
}
|
||||
|
||||
issue_5370: {
|
||||
options = {
|
||||
dead_code: true,
|
||||
ie: true,
|
||||
unused: true,
|
||||
}
|
||||
input: {
|
||||
console.log(function arguments(...a) {
|
||||
return arguments;
|
||||
try {} catch (e) {
|
||||
var arguments;
|
||||
}
|
||||
}());
|
||||
}
|
||||
expect: {
|
||||
console.log(function arguments(...a) {
|
||||
return arguments;
|
||||
var arguments;
|
||||
}());
|
||||
}
|
||||
expect_stdout: true
|
||||
node_version: ">=6"
|
||||
}
|
||||
|
||||
issue_5391: {
|
||||
options = {
|
||||
evaluate: true,
|
||||
keep_fargs: false,
|
||||
objects: true,
|
||||
pure_getters: "strict",
|
||||
reduce_vars: true,
|
||||
side_effects: true,
|
||||
toplevel: true,
|
||||
unused: true,
|
||||
}
|
||||
input: {
|
||||
var a, b = function f({
|
||||
p: {},
|
||||
...c
|
||||
}) {
|
||||
while (c.q);
|
||||
}({
|
||||
p: {
|
||||
r: a++,
|
||||
r: 0,
|
||||
}
|
||||
});
|
||||
console.log(a);
|
||||
}
|
||||
expect: {
|
||||
(function({
|
||||
p: {},
|
||||
...c
|
||||
}) {
|
||||
while (c.q);
|
||||
})({
|
||||
p: 0,
|
||||
});
|
||||
console.log(NaN);
|
||||
}
|
||||
expect_stdout: "NaN"
|
||||
node_version: ">=8.3.0"
|
||||
}
|
||||
|
||||
issue_5533_1_keep_fargs: {
|
||||
options = {
|
||||
evaluate: true,
|
||||
inline: true,
|
||||
join_vars: true,
|
||||
keep_fargs: true,
|
||||
loops: true,
|
||||
side_effects: true,
|
||||
unused: true,
|
||||
}
|
||||
input: {
|
||||
"use strict";
|
||||
try {
|
||||
(function() {
|
||||
var a;
|
||||
for (; 1;)
|
||||
a = function() {
|
||||
(function f(...b) {
|
||||
b;
|
||||
throw "PASS";
|
||||
})();
|
||||
}();
|
||||
})();
|
||||
} catch (e) {
|
||||
console.log(e);
|
||||
}
|
||||
}
|
||||
expect: {
|
||||
"use strict";
|
||||
try {
|
||||
(function() {
|
||||
for (;;)
|
||||
throw "PASS";
|
||||
})();
|
||||
} catch (e) {
|
||||
console.log(e);
|
||||
}
|
||||
}
|
||||
expect_stdout: "PASS"
|
||||
node_version: ">=6"
|
||||
}
|
||||
|
||||
issue_5533_1_drop_fargs: {
|
||||
options = {
|
||||
evaluate: true,
|
||||
inline: true,
|
||||
join_vars: true,
|
||||
keep_fargs: false,
|
||||
loops: true,
|
||||
side_effects: true,
|
||||
unused: true,
|
||||
}
|
||||
input: {
|
||||
"use strict";
|
||||
try {
|
||||
(function() {
|
||||
var a;
|
||||
for (; 1;)
|
||||
a = function() {
|
||||
(function f(...b) {
|
||||
b;
|
||||
throw "PASS";
|
||||
})();
|
||||
}();
|
||||
})();
|
||||
} catch (e) {
|
||||
console.log(e);
|
||||
}
|
||||
}
|
||||
expect: {
|
||||
"use strict";
|
||||
try {
|
||||
(function() {
|
||||
for (;;)
|
||||
throw "PASS";
|
||||
})();
|
||||
} catch (e) {
|
||||
console.log(e);
|
||||
}
|
||||
}
|
||||
expect_stdout: "PASS"
|
||||
node_version: ">=6"
|
||||
}
|
||||
|
||||
issue_5533_2_keep_fargs: {
|
||||
options = {
|
||||
evaluate: true,
|
||||
inline: true,
|
||||
join_vars: true,
|
||||
keep_fargs: true,
|
||||
loops: true,
|
||||
side_effects: true,
|
||||
unused: true,
|
||||
}
|
||||
input: {
|
||||
"use strict";
|
||||
try {
|
||||
(function() {
|
||||
var a;
|
||||
for (; 1;)
|
||||
a = function() {
|
||||
(function f(...[ b ]) {
|
||||
b;
|
||||
throw "PASS";
|
||||
})();
|
||||
}();
|
||||
})();
|
||||
} catch (e) {
|
||||
console.log(e);
|
||||
}
|
||||
}
|
||||
expect: {
|
||||
"use strict";
|
||||
try {
|
||||
(function() {
|
||||
for (;;)
|
||||
throw "PASS";
|
||||
})();
|
||||
} catch (e) {
|
||||
console.log(e);
|
||||
}
|
||||
}
|
||||
expect_stdout: "PASS"
|
||||
node_version: ">=6"
|
||||
}
|
||||
|
||||
issue_5533_2_drop_fargs: {
|
||||
options = {
|
||||
evaluate: true,
|
||||
inline: true,
|
||||
join_vars: true,
|
||||
keep_fargs: false,
|
||||
loops: true,
|
||||
side_effects: true,
|
||||
unused: true,
|
||||
}
|
||||
input: {
|
||||
"use strict";
|
||||
try {
|
||||
(function() {
|
||||
var a;
|
||||
for (; 1;)
|
||||
a = function() {
|
||||
(function f(...[ b ]) {
|
||||
b;
|
||||
throw "PASS";
|
||||
})();
|
||||
}();
|
||||
})();
|
||||
} catch (e) {
|
||||
console.log(e);
|
||||
}
|
||||
}
|
||||
expect: {
|
||||
"use strict";
|
||||
try {
|
||||
(function() {
|
||||
for (;;)
|
||||
throw "PASS";
|
||||
})();
|
||||
} catch (e) {
|
||||
console.log(e);
|
||||
}
|
||||
}
|
||||
expect_stdout: "PASS"
|
||||
node_version: ">=6"
|
||||
}
|
||||
|
||||
issue_5552_1: {
|
||||
options = {
|
||||
collapse_vars: true,
|
||||
reduce_vars: true,
|
||||
toplevel: true,
|
||||
}
|
||||
input: {
|
||||
var log = console.log;
|
||||
var a = f, b = log();
|
||||
function f(...[ c = a = "PASS" ]) {}
|
||||
f((a = "FAIL", b));
|
||||
log(a);
|
||||
}
|
||||
expect: {
|
||||
var log = console.log;
|
||||
var a = f, b = log();
|
||||
function f(...[ c = a = "PASS" ]) {}
|
||||
f((a = "FAIL", b));
|
||||
log(a);
|
||||
}
|
||||
expect_stdout: [
|
||||
"",
|
||||
"PASS",
|
||||
]
|
||||
node_version: ">=6"
|
||||
}
|
||||
|
||||
issue_5552_2: {
|
||||
options = {
|
||||
collapse_vars: true,
|
||||
reduce_vars: true,
|
||||
toplevel: true,
|
||||
}
|
||||
input: {
|
||||
var log = console.log;
|
||||
var a = f;
|
||||
function f(...{ [a = "PASS"]: b }) {}
|
||||
f((a = "FAIL", 42));
|
||||
log(a);
|
||||
}
|
||||
expect: {
|
||||
var log = console.log;
|
||||
var a = f;
|
||||
function f(...{ [a = "PASS"]: b }) {}
|
||||
f((a = "FAIL", 42));
|
||||
log(a);
|
||||
}
|
||||
expect_stdout: "PASS"
|
||||
node_version: ">=6"
|
||||
}
|
||||
|
||||
issue_5552_3: {
|
||||
options = {
|
||||
collapse_vars: true,
|
||||
unused: true,
|
||||
}
|
||||
input: {
|
||||
var a = [ "FAIL", "PASS" ];
|
||||
console.log(function(b, ...[ c = a.pop() ]) {
|
||||
return b;
|
||||
}(a.pop()));
|
||||
}
|
||||
expect: {
|
||||
var a = [ "FAIL", "PASS" ];
|
||||
console.log(function(b, ...[ c = a.pop() ]) {
|
||||
return b;
|
||||
}(a.pop()));
|
||||
}
|
||||
expect_stdout: "PASS"
|
||||
node_version: ">=6"
|
||||
}
|
||||
|
||||
issue_5552_4: {
|
||||
options = {
|
||||
collapse_vars: true,
|
||||
unused: true,
|
||||
}
|
||||
input: {
|
||||
var a = [ "FAIL", "PASS" ];
|
||||
console.log(function(b, ...{ [a.pop()]: c }) {
|
||||
return b;
|
||||
}(a.pop()));
|
||||
}
|
||||
expect: {
|
||||
var a = [ "FAIL", "PASS" ];
|
||||
console.log(function(b, ...{ [a.pop()]: c }) {
|
||||
return b;
|
||||
}(a.pop()));
|
||||
}
|
||||
expect_stdout: "PASS"
|
||||
node_version: ">=6"
|
||||
}
|
||||
|
||||
@@ -289,8 +289,34 @@ iife: {
|
||||
typeof function g() {}();
|
||||
}
|
||||
expect: {
|
||||
x = 42, function a() {}(), function b() {}(), function c() {}(),
|
||||
function d() {}(), function e() {}(), function f() {}(), function g() {}();
|
||||
x = 42,
|
||||
function a() {}(),
|
||||
!function b() {}(),
|
||||
~function c() {}(),
|
||||
+function d() {}(),
|
||||
-function e() {}(),
|
||||
void function f() {}(),
|
||||
typeof function g() {}();
|
||||
}
|
||||
}
|
||||
|
||||
iife_drop_side_effect_free: {
|
||||
options = {
|
||||
sequences: true,
|
||||
side_effects: true,
|
||||
}
|
||||
input: {
|
||||
x = 42;
|
||||
(function a() {})();
|
||||
!function b() {}();
|
||||
~function c() {}();
|
||||
+function d() {}();
|
||||
-function e() {}();
|
||||
void function f() {}();
|
||||
typeof function g() {}();
|
||||
}
|
||||
expect: {
|
||||
x = 42;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1045,11 +1071,102 @@ call: {
|
||||
b.c = function() {
|
||||
console.log(this === b ? "bar" : "baz");
|
||||
},
|
||||
a,
|
||||
b(),
|
||||
a,
|
||||
b.c(),
|
||||
(a, b.c)(),
|
||||
a,
|
||||
b["c"](),
|
||||
(a, b["c"])(),
|
||||
a,
|
||||
function() {
|
||||
console.log(this === a);
|
||||
}(),
|
||||
a,
|
||||
new b(),
|
||||
a,
|
||||
new b.c(),
|
||||
a,
|
||||
new b.c(),
|
||||
a,
|
||||
new b["c"](),
|
||||
a,
|
||||
new b["c"](),
|
||||
a,
|
||||
new function() {
|
||||
console.log(this === a);
|
||||
}(),
|
||||
console.log((a, typeof b.c)),
|
||||
console.log((a, typeof b["c"]));
|
||||
}
|
||||
expect_stdout: [
|
||||
"foo",
|
||||
"bar",
|
||||
"baz",
|
||||
"bar",
|
||||
"baz",
|
||||
"true",
|
||||
"foo",
|
||||
"baz",
|
||||
"baz",
|
||||
"baz",
|
||||
"baz",
|
||||
"false",
|
||||
"function",
|
||||
"function",
|
||||
]
|
||||
}
|
||||
|
||||
call_drop_side_effect_free: {
|
||||
options = {
|
||||
sequences: true,
|
||||
side_effects: true,
|
||||
}
|
||||
input: {
|
||||
var a = function() {
|
||||
return this;
|
||||
}();
|
||||
function b() {
|
||||
console.log("foo");
|
||||
}
|
||||
b.c = function() {
|
||||
console.log(this === b ? "bar" : "baz");
|
||||
};
|
||||
(a, b)();
|
||||
(a, b).c();
|
||||
(a, b.c)();
|
||||
(a, b)["c"]();
|
||||
(a, b["c"])();
|
||||
(a, function() {
|
||||
console.log(this === a);
|
||||
})();
|
||||
new (a, b)();
|
||||
new (a, b).c();
|
||||
new (a, b.c)();
|
||||
new (a, b)["c"]();
|
||||
new (a, b["c"])();
|
||||
new (a, function() {
|
||||
console.log(this === a);
|
||||
})();
|
||||
console.log(typeof (a, b).c);
|
||||
console.log(typeof (a, b)["c"]);
|
||||
}
|
||||
expect: {
|
||||
var a = function() {
|
||||
return this;
|
||||
}();
|
||||
function b() {
|
||||
console.log("foo");
|
||||
}
|
||||
b.c = function() {
|
||||
console.log(this === b ? "bar" : "baz");
|
||||
},
|
||||
b(),
|
||||
b.c(),
|
||||
(0, b.c)(),
|
||||
b["c"](),
|
||||
(0, b["c"])(),
|
||||
function() {
|
||||
console.log(this === a);
|
||||
}(),
|
||||
@@ -1061,8 +1178,8 @@ call: {
|
||||
new function() {
|
||||
console.log(this === a);
|
||||
}(),
|
||||
console.log((a, typeof b.c)),
|
||||
console.log((a, typeof b["c"]));
|
||||
console.log(typeof b.c),
|
||||
console.log(typeof b["c"]);
|
||||
}
|
||||
expect_stdout: [
|
||||
"foo",
|
||||
@@ -1097,6 +1214,26 @@ missing_link: {
|
||||
expect: {
|
||||
var a = 100;
|
||||
a,
|
||||
a++ + (0, 1),
|
||||
console.log(a);
|
||||
}
|
||||
}
|
||||
|
||||
missing_link_drop_side_effect_free: {
|
||||
options = {
|
||||
conditionals: true,
|
||||
evaluate: true,
|
||||
sequences: true,
|
||||
side_effects: true,
|
||||
}
|
||||
input: {
|
||||
var a = 100;
|
||||
a;
|
||||
a++ + (0 ? 2 : 1);
|
||||
console.log(a);
|
||||
}
|
||||
expect: {
|
||||
var a = 100;
|
||||
a++,
|
||||
console.log(a);
|
||||
}
|
||||
@@ -1192,7 +1329,7 @@ issue_3490_2: {
|
||||
expect: {
|
||||
var b = 42, c = "FAIL";
|
||||
var a;
|
||||
for (c = "PASS", b; "" == typeof d;);
|
||||
for (c = "PASS"; "" == typeof d;);
|
||||
console.log(c, b);
|
||||
}
|
||||
expect_stdout: "PASS 42"
|
||||
|
||||
@@ -617,7 +617,7 @@ issue_4730_2: {
|
||||
}
|
||||
expect: {
|
||||
var a;
|
||||
!console.log("PASS") || a && a[a.p];
|
||||
console.log("PASS") && a && a[a.p];
|
||||
}
|
||||
expect_stdout: "PASS"
|
||||
}
|
||||
@@ -645,3 +645,56 @@ issue_4751: {
|
||||
}
|
||||
expect_stdout: "PASS"
|
||||
}
|
||||
|
||||
drop_instanceof: {
|
||||
options = {
|
||||
side_effects: true,
|
||||
}
|
||||
input: {
|
||||
42 instanceof function() {};
|
||||
console.log("PASS");
|
||||
}
|
||||
expect: {
|
||||
console.log("PASS");
|
||||
}
|
||||
expect_stdout: "PASS"
|
||||
}
|
||||
|
||||
drop_instanceof_reference: {
|
||||
options = {
|
||||
reduce_vars: true,
|
||||
side_effects: true,
|
||||
toplevel: true,
|
||||
}
|
||||
input: {
|
||||
function f() {}
|
||||
42 instanceof f;
|
||||
console.log("PASS");
|
||||
}
|
||||
expect: {
|
||||
function f() {}
|
||||
console.log("PASS");
|
||||
}
|
||||
expect_stdout: "PASS"
|
||||
}
|
||||
|
||||
retain_instanceof: {
|
||||
options = {
|
||||
side_effects: true,
|
||||
}
|
||||
input: {
|
||||
try {
|
||||
42 instanceof "foo";
|
||||
} catch (e) {
|
||||
console.log("PASS");
|
||||
}
|
||||
}
|
||||
expect: {
|
||||
try {
|
||||
0 instanceof "foo";
|
||||
} catch (e) {
|
||||
console.log("PASS");
|
||||
}
|
||||
}
|
||||
expect_stdout: "PASS"
|
||||
}
|
||||
|
||||
@@ -1,3 +1,12 @@
|
||||
decimal: {
|
||||
input: {
|
||||
console.log({... 0.42});
|
||||
}
|
||||
expect_exact: "console.log({....42});"
|
||||
expect_stdout: "{}"
|
||||
node_version: ">=8.3.0"
|
||||
}
|
||||
|
||||
collapse_vars_1: {
|
||||
options = {
|
||||
collapse_vars: true,
|
||||
@@ -1166,3 +1175,31 @@ issue_5006: {
|
||||
expect_stdout: "PASS"
|
||||
node_version: ">=6"
|
||||
}
|
||||
|
||||
issue_5382: {
|
||||
options = {
|
||||
side_effects: true,
|
||||
}
|
||||
input: {
|
||||
({
|
||||
f() {
|
||||
({ ...this });
|
||||
},
|
||||
get p() {
|
||||
console.log("PASS");
|
||||
},
|
||||
}).f();
|
||||
}
|
||||
expect: {
|
||||
({
|
||||
f() {
|
||||
({ ...this });
|
||||
},
|
||||
get p() {
|
||||
console.log("PASS");
|
||||
},
|
||||
}).f();
|
||||
}
|
||||
expect_stdout: "PASS"
|
||||
node_version: ">=8.3.0"
|
||||
}
|
||||
|
||||
@@ -1608,3 +1608,83 @@ issue_5012: {
|
||||
}
|
||||
expect_stdout: "PASS"
|
||||
}
|
||||
|
||||
issue_5543_1: {
|
||||
options = {
|
||||
dead_code: true,
|
||||
switches: true,
|
||||
}
|
||||
input: {
|
||||
var a;
|
||||
switch (a) {
|
||||
default:
|
||||
switch (42) {
|
||||
case a:
|
||||
case console.log("PASS"):
|
||||
}
|
||||
break;
|
||||
case null:
|
||||
switch (false) {
|
||||
case a:
|
||||
case console.log("FAIL"):
|
||||
}
|
||||
}
|
||||
}
|
||||
expect: {
|
||||
var a;
|
||||
switch (a) {
|
||||
default:
|
||||
switch (42) {
|
||||
case a:
|
||||
case console.log("PASS"):
|
||||
}
|
||||
break;
|
||||
case null:
|
||||
switch (false) {
|
||||
case a:
|
||||
case console.log("FAIL"):
|
||||
}
|
||||
}
|
||||
}
|
||||
expect_stdout: "PASS"
|
||||
}
|
||||
|
||||
issue_5543_2: {
|
||||
options = {
|
||||
dead_code: true,
|
||||
switches: true,
|
||||
}
|
||||
input: {
|
||||
var a;
|
||||
switch (a) {
|
||||
default:
|
||||
switch (42) {
|
||||
case a:
|
||||
case console.log("PASS"):
|
||||
}
|
||||
break;
|
||||
case null:
|
||||
switch (42) {
|
||||
case a:
|
||||
case console.log("FAIL"):
|
||||
}
|
||||
}
|
||||
}
|
||||
expect: {
|
||||
var a;
|
||||
switch (a) {
|
||||
default:
|
||||
switch (42) {
|
||||
case a:
|
||||
case console.log("PASS"):
|
||||
}
|
||||
break;
|
||||
case null:
|
||||
switch (42) {
|
||||
case a:
|
||||
case console.log("FAIL"):
|
||||
}
|
||||
}
|
||||
}
|
||||
expect_stdout: "PASS"
|
||||
}
|
||||
|
||||
@@ -127,7 +127,7 @@ if_return: {
|
||||
if (w) {
|
||||
if (y) return;
|
||||
} else if (z) return;
|
||||
return x == y || (x && w(), y && z()), !0;
|
||||
return x != y && (x && w(), y && z()), !0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -307,7 +307,7 @@ typeof_defined_1: {
|
||||
}
|
||||
expect: {
|
||||
"undefined" == typeof A && A;
|
||||
"undefined" != typeof A || A;
|
||||
"undefined" == typeof A && A;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -324,7 +324,7 @@ typeof_defined_2: {
|
||||
}
|
||||
expect: {
|
||||
"function" != typeof A && A;
|
||||
"function" == typeof A || A;
|
||||
"function" != typeof A && A;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -355,16 +355,19 @@ typeof_defined_3: {
|
||||
"undefined" == typeof A && "undefined" == typeof B && (A, B);
|
||||
"undefined" == typeof A && "undefined" != typeof B && A;
|
||||
"undefined" != typeof A && "undefined" == typeof B && B;
|
||||
// dropped
|
||||
"undefined" == typeof A && "undefined" == typeof B || (A, B);
|
||||
"undefined" == typeof A && "undefined" != typeof B || (A, B);
|
||||
"undefined" != typeof A && "undefined" == typeof B || (A, B);
|
||||
"undefined" != typeof A && "undefined" != typeof B || (A, B);
|
||||
"undefined" == typeof A || "undefined" == typeof B && B;
|
||||
"undefined" != typeof A || "undefined" == typeof B && (A, B);
|
||||
"undefined" != typeof A || "undefined" != typeof B && A;
|
||||
"undefined" == typeof A || "undefined" != typeof B || B;
|
||||
"undefined" != typeof A || "undefined" == typeof B || A;
|
||||
"undefined" != typeof A || "undefined" != typeof B || (A, B);
|
||||
"undefined" != typeof A && "undefined" == typeof B && B;
|
||||
// dropped
|
||||
"undefined" == typeof A && "undefined" == typeof B && (A, B);
|
||||
"undefined" == typeof A && "undefined" != typeof B && A;
|
||||
// dropped
|
||||
"undefined" != typeof A && "undefined" == typeof B && B;
|
||||
"undefined" == typeof A && "undefined" != typeof B && A;
|
||||
"undefined" == typeof A && "undefined" == typeof B && (A, B);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -392,6 +395,7 @@ typeof_defined_4: {
|
||||
"object" != typeof A || "object" != typeof B || (A, B);
|
||||
}
|
||||
expect: {
|
||||
// dropped
|
||||
"object" == typeof A && "object" != typeof B && B;
|
||||
"object" != typeof A && "object" == typeof B && A;
|
||||
"object" != typeof A && "object" != typeof B && (A, B);
|
||||
@@ -399,12 +403,14 @@ typeof_defined_4: {
|
||||
"object" == typeof A && "object" != typeof B || (A, B);
|
||||
"object" != typeof A && "object" == typeof B || (A, B);
|
||||
"object" != typeof A && "object" != typeof B || (A, B);
|
||||
"object" == typeof A || "object" == typeof B && A;
|
||||
"object" == typeof A || "object" != typeof B && (A, B);
|
||||
"object" != typeof A || "object" != typeof B && B;
|
||||
"object" == typeof A || "object" == typeof B || (A, B);
|
||||
"object" == typeof A || "object" != typeof B || A;
|
||||
"object" != typeof A || "object" == typeof B || B;
|
||||
"object" != typeof A && "object" == typeof B && A;
|
||||
"object" != typeof A && "object" != typeof B && (A, B);
|
||||
// dropped
|
||||
"object" == typeof A && "object" != typeof B && B;
|
||||
"object" != typeof A && "object" != typeof B && (A, B);
|
||||
"object" != typeof A && "object" == typeof B && A;
|
||||
"object" == typeof A && "object" != typeof B && B;
|
||||
// dropped
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -111,7 +111,7 @@ hoist_props_const: {
|
||||
}
|
||||
}
|
||||
expect: {
|
||||
var o = 0, o_p = "PASS";
|
||||
var o, o_p = "PASS";
|
||||
console.log(o_p);
|
||||
}
|
||||
expect_stdout: "PASS"
|
||||
@@ -613,3 +613,35 @@ issue_4954: {
|
||||
]
|
||||
node_version: ">=4"
|
||||
}
|
||||
|
||||
issue_5516: {
|
||||
options = {
|
||||
reduce_funcs: true,
|
||||
reduce_vars: true,
|
||||
unused: true,
|
||||
varify: true,
|
||||
}
|
||||
input: {
|
||||
"use strict";
|
||||
console.log(typeof function() {
|
||||
{
|
||||
let a;
|
||||
}
|
||||
{
|
||||
const a = function() {};
|
||||
return a;
|
||||
}
|
||||
}());
|
||||
}
|
||||
expect: {
|
||||
"use strict";
|
||||
console.log(typeof function() {
|
||||
{
|
||||
const a = function() {};
|
||||
return a;
|
||||
}
|
||||
}());
|
||||
}
|
||||
expect_stdout: "function"
|
||||
node_version: ">=4"
|
||||
}
|
||||
|
||||
@@ -107,3 +107,209 @@ function_name_mangle_ie8: {
|
||||
expect_exact: "(function(){console.log(typeof function n(o){})})();"
|
||||
expect_stdout: "function"
|
||||
}
|
||||
|
||||
issue_1753: {
|
||||
mangle = {
|
||||
toplevel: false,
|
||||
webkit: true,
|
||||
}
|
||||
input: {
|
||||
"use strict";
|
||||
let l = null;
|
||||
for (let i = 0; i < 1; i++)
|
||||
console.log(i);
|
||||
}
|
||||
expect: {
|
||||
"use strict";
|
||||
let l = null;
|
||||
for (let i = 0; i < 1; i++)
|
||||
console.log(i);
|
||||
}
|
||||
expect_stdout: "0"
|
||||
node_version: ">=4"
|
||||
}
|
||||
|
||||
issue_1753_toplevel: {
|
||||
mangle = {
|
||||
toplevel: true,
|
||||
webkit: true,
|
||||
}
|
||||
input: {
|
||||
"use strict";
|
||||
let l = null;
|
||||
for (let i = 0; i < 1; i++)
|
||||
console.log(i);
|
||||
}
|
||||
expect: {
|
||||
"use strict";
|
||||
let l = null;
|
||||
for (let e = 0; e < 1; e++)
|
||||
console.log(e);
|
||||
}
|
||||
expect_stdout: "0"
|
||||
node_version: ">=4"
|
||||
}
|
||||
|
||||
issue_5032_await: {
|
||||
options = {
|
||||
merge_vars: true,
|
||||
webkit: false,
|
||||
}
|
||||
input: {
|
||||
function log(value) {
|
||||
console.log(value);
|
||||
return value;
|
||||
}
|
||||
async function f(a) {
|
||||
var b = log(a), c = b;
|
||||
log(b);
|
||||
log(c);
|
||||
}
|
||||
f("PASS");
|
||||
}
|
||||
expect: {
|
||||
function log(value) {
|
||||
console.log(value);
|
||||
return value;
|
||||
}
|
||||
async function f(a) {
|
||||
var a = log(a), c = a;
|
||||
log(a);
|
||||
log(c);
|
||||
}
|
||||
f("PASS");
|
||||
}
|
||||
expect_stdout: [
|
||||
"PASS",
|
||||
"PASS",
|
||||
"PASS",
|
||||
]
|
||||
node_version: ">=8"
|
||||
}
|
||||
|
||||
issue_5032_await_webkit: {
|
||||
options = {
|
||||
merge_vars: true,
|
||||
webkit: true,
|
||||
}
|
||||
input: {
|
||||
function log(value) {
|
||||
console.log(value);
|
||||
return value;
|
||||
}
|
||||
async function f(a) {
|
||||
var b = log(a), c = b;
|
||||
log(b);
|
||||
log(c);
|
||||
}
|
||||
f("PASS");
|
||||
}
|
||||
expect: {
|
||||
function log(value) {
|
||||
console.log(value);
|
||||
return value;
|
||||
}
|
||||
async function f(a) {
|
||||
var b = log(a), c = b;
|
||||
log(b);
|
||||
log(c);
|
||||
}
|
||||
f("PASS");
|
||||
}
|
||||
expect_stdout: [
|
||||
"PASS",
|
||||
"PASS",
|
||||
"PASS",
|
||||
]
|
||||
node_version: ">=8"
|
||||
}
|
||||
|
||||
issue_5032_yield: {
|
||||
options = {
|
||||
merge_vars: true,
|
||||
webkit: false,
|
||||
}
|
||||
input: {
|
||||
function log(value) {
|
||||
console.log(value);
|
||||
return value;
|
||||
}
|
||||
function *f(a) {
|
||||
var b = log(a), c = b;
|
||||
log(b);
|
||||
log(c);
|
||||
}
|
||||
f("PASS").next();
|
||||
}
|
||||
expect: {
|
||||
function log(value) {
|
||||
console.log(value);
|
||||
return value;
|
||||
}
|
||||
function *f(a) {
|
||||
var a = log(a), c = a;
|
||||
log(a);
|
||||
log(c);
|
||||
}
|
||||
f("PASS").next();
|
||||
}
|
||||
expect_stdout: [
|
||||
"PASS",
|
||||
"PASS",
|
||||
"PASS",
|
||||
]
|
||||
node_version: ">=4"
|
||||
}
|
||||
|
||||
issue_5032_yield_webkit: {
|
||||
options = {
|
||||
merge_vars: true,
|
||||
webkit: true,
|
||||
}
|
||||
input: {
|
||||
function log(value) {
|
||||
console.log(value);
|
||||
return value;
|
||||
}
|
||||
function *f(a) {
|
||||
var b = log(a), c = b;
|
||||
log(b);
|
||||
log(c);
|
||||
}
|
||||
f("PASS").next();
|
||||
}
|
||||
expect: {
|
||||
function log(value) {
|
||||
console.log(value);
|
||||
return value;
|
||||
}
|
||||
function *f(a) {
|
||||
var b = log(a), c = b;
|
||||
log(b);
|
||||
log(c);
|
||||
}
|
||||
f("PASS").next();
|
||||
}
|
||||
expect_stdout: [
|
||||
"PASS",
|
||||
"PASS",
|
||||
"PASS",
|
||||
]
|
||||
node_version: ">=4"
|
||||
}
|
||||
|
||||
issue_5480: {
|
||||
mangle = {
|
||||
webkit: true,
|
||||
}
|
||||
input: {
|
||||
"use strict";
|
||||
L: for (let a in console.log("PASS"));
|
||||
}
|
||||
expect: {
|
||||
"use strict";
|
||||
o: for (let o in console.log("PASS"));
|
||||
}
|
||||
expect_stdout: "PASS"
|
||||
node_version: ">=4"
|
||||
}
|
||||
|
||||
@@ -907,7 +907,7 @@ drop_body: {
|
||||
})([ console.log("baz") ]);
|
||||
}
|
||||
expect: {
|
||||
[ [ , [].e = console.log("foo") ] ] = [ [ console.log("baz") ] ];
|
||||
[ [ , [][0] = console.log("foo") ] ] = [ [ console.log("baz") ] ];
|
||||
}
|
||||
expect_stdout: [
|
||||
"baz",
|
||||
@@ -934,6 +934,21 @@ drop_unused_call: {
|
||||
node_version: ">=4"
|
||||
}
|
||||
|
||||
instanceof_lambda: {
|
||||
options = {
|
||||
evaluate: true,
|
||||
side_effects: true,
|
||||
}
|
||||
input: {
|
||||
console.log(42 instanceof function*() {});
|
||||
}
|
||||
expect: {
|
||||
console.log(false);
|
||||
}
|
||||
expect_stdout: "false"
|
||||
node_version: ">=4"
|
||||
}
|
||||
|
||||
issue_4454_1: {
|
||||
rename = false
|
||||
options = {
|
||||
@@ -978,8 +993,8 @@ issue_4454_2: {
|
||||
expect: {
|
||||
function f(a) {
|
||||
(function*(c = console.log(a)) {})();
|
||||
var a = 42..toString();
|
||||
console.log(a);
|
||||
var b = 42..toString();
|
||||
console.log(b);
|
||||
}
|
||||
f("PASS");
|
||||
}
|
||||
@@ -1168,6 +1183,35 @@ issue_4641_2: {
|
||||
node_version: ">=10"
|
||||
}
|
||||
|
||||
issue_4641_3: {
|
||||
options = {
|
||||
if_return: true,
|
||||
}
|
||||
input: {
|
||||
console.log(typeof async function*() {
|
||||
try {
|
||||
return void "FAIL";
|
||||
} finally {
|
||||
console.log("PASS");
|
||||
}
|
||||
}().next().then);
|
||||
}
|
||||
expect: {
|
||||
console.log(typeof async function*() {
|
||||
try {
|
||||
return void "FAIL";
|
||||
} finally {
|
||||
console.log("PASS");
|
||||
}
|
||||
}().next().then);
|
||||
}
|
||||
expect_stdout: [
|
||||
"function",
|
||||
"PASS",
|
||||
]
|
||||
node_version: ">=10"
|
||||
}
|
||||
|
||||
issue_4769_1: {
|
||||
options = {
|
||||
side_effects: true,
|
||||
@@ -1267,80 +1311,6 @@ issue_5019_2: {
|
||||
node_version: ">=4"
|
||||
}
|
||||
|
||||
issue_5032_normal: {
|
||||
options = {
|
||||
merge_vars: true,
|
||||
webkit: false,
|
||||
}
|
||||
input: {
|
||||
function log(value) {
|
||||
console.log(value);
|
||||
return value;
|
||||
}
|
||||
function *f(a) {
|
||||
var b = log(a), c = b;
|
||||
log(b);
|
||||
log(c);
|
||||
}
|
||||
f("PASS").next();
|
||||
}
|
||||
expect: {
|
||||
function log(value) {
|
||||
console.log(value);
|
||||
return value;
|
||||
}
|
||||
function *f(a) {
|
||||
var a = log(a), c = a;
|
||||
log(a);
|
||||
log(c);
|
||||
}
|
||||
f("PASS").next();
|
||||
}
|
||||
expect_stdout: [
|
||||
"PASS",
|
||||
"PASS",
|
||||
"PASS",
|
||||
]
|
||||
node_version: ">=4"
|
||||
}
|
||||
|
||||
issue_5032_webkit: {
|
||||
options = {
|
||||
merge_vars: true,
|
||||
webkit: true,
|
||||
}
|
||||
input: {
|
||||
function log(value) {
|
||||
console.log(value);
|
||||
return value;
|
||||
}
|
||||
function *f(a) {
|
||||
var b = log(a), c = b;
|
||||
log(b);
|
||||
log(c);
|
||||
}
|
||||
f("PASS").next();
|
||||
}
|
||||
expect: {
|
||||
function log(value) {
|
||||
console.log(value);
|
||||
return value;
|
||||
}
|
||||
function *f(a) {
|
||||
var b = log(a), c = b;
|
||||
log(b);
|
||||
log(c);
|
||||
}
|
||||
f("PASS").next();
|
||||
}
|
||||
expect_stdout: [
|
||||
"PASS",
|
||||
"PASS",
|
||||
"PASS",
|
||||
]
|
||||
node_version: ">=4"
|
||||
}
|
||||
|
||||
issue_5034: {
|
||||
options = {
|
||||
functions: true,
|
||||
@@ -1375,6 +1345,7 @@ issue_5076_1: {
|
||||
options = {
|
||||
evaluate: true,
|
||||
hoist_vars: true,
|
||||
keep_fargs: false,
|
||||
pure_getters: "strict",
|
||||
sequences: true,
|
||||
side_effects: true,
|
||||
@@ -1404,6 +1375,7 @@ issue_5076_2: {
|
||||
options = {
|
||||
evaluate: true,
|
||||
hoist_vars: true,
|
||||
keep_fargs: false,
|
||||
passes: 2,
|
||||
pure_getters: "strict",
|
||||
sequences: true,
|
||||
@@ -1449,3 +1421,283 @@ issue_5177: {
|
||||
expect_stdout: "function"
|
||||
node_version: ">=4"
|
||||
}
|
||||
|
||||
issue_5385_1: {
|
||||
options = {
|
||||
inline: true,
|
||||
}
|
||||
input: {
|
||||
(async function*() {
|
||||
(function() {
|
||||
try {
|
||||
return console.log("foo");
|
||||
} finally {
|
||||
return console.log("bar");
|
||||
}
|
||||
console.log("baz");
|
||||
})();
|
||||
})().next();
|
||||
console.log("moo");
|
||||
}
|
||||
expect: {
|
||||
(async function*() {
|
||||
(function() {
|
||||
try {
|
||||
return console.log("foo");
|
||||
} finally {
|
||||
return console.log("bar");
|
||||
}
|
||||
console.log("baz");
|
||||
})();
|
||||
})().next();
|
||||
console.log("moo");
|
||||
}
|
||||
expect_stdout: [
|
||||
"foo",
|
||||
"bar",
|
||||
"moo",
|
||||
]
|
||||
node_version: ">=10"
|
||||
}
|
||||
|
||||
issue_5385_2: {
|
||||
options = {
|
||||
inline: true,
|
||||
}
|
||||
input: {
|
||||
(async function*() {
|
||||
return function() {
|
||||
try {
|
||||
return console.log("foo");
|
||||
} finally {
|
||||
return console.log("bar");
|
||||
}
|
||||
}();
|
||||
})().next();
|
||||
console.log("moo");
|
||||
}
|
||||
expect: {
|
||||
(async function*() {
|
||||
return function() {
|
||||
try {
|
||||
return console.log("foo");
|
||||
} finally {
|
||||
return console.log("bar");
|
||||
}
|
||||
}();
|
||||
})().next();
|
||||
console.log("moo");
|
||||
}
|
||||
expect_stdout: [
|
||||
"foo",
|
||||
"bar",
|
||||
"moo",
|
||||
]
|
||||
node_version: ">=10"
|
||||
}
|
||||
|
||||
issue_5385_3: {
|
||||
options = {
|
||||
inline: true,
|
||||
}
|
||||
input: {
|
||||
(async function*() {
|
||||
return function() {
|
||||
try {
|
||||
throw console.log("foo");
|
||||
} catch (e) {
|
||||
return console.log("bar");
|
||||
}
|
||||
}();
|
||||
})().next();
|
||||
console.log("moo");
|
||||
}
|
||||
expect: {
|
||||
(async function*() {
|
||||
try {
|
||||
throw console.log("foo");
|
||||
} catch (e) {
|
||||
return console.log("bar");
|
||||
}
|
||||
return void 0;
|
||||
})().next();
|
||||
console.log("moo");
|
||||
}
|
||||
expect_stdout: [
|
||||
"foo",
|
||||
"bar",
|
||||
"moo",
|
||||
]
|
||||
node_version: ">=10"
|
||||
}
|
||||
|
||||
issue_5385_4: {
|
||||
options = {
|
||||
awaits: true,
|
||||
inline: true,
|
||||
}
|
||||
input: {
|
||||
(async function*() {
|
||||
return async function() {
|
||||
try {
|
||||
return {
|
||||
then(resolve) {
|
||||
resolve(console.log("FAIL"));
|
||||
},
|
||||
};
|
||||
} finally {
|
||||
return "PASS";
|
||||
}
|
||||
}();
|
||||
})().next().then(o => console.log(o.value, o.done));
|
||||
}
|
||||
expect: {
|
||||
(async function*() {
|
||||
return async function() {
|
||||
try {
|
||||
return {
|
||||
then(resolve) {
|
||||
resolve(console.log("FAIL"));
|
||||
},
|
||||
};
|
||||
} finally {
|
||||
return "PASS";
|
||||
}
|
||||
}();
|
||||
})().next().then(o => console.log(o.value, o.done));
|
||||
}
|
||||
expect_stdout: "PASS true"
|
||||
node_version: ">=10"
|
||||
}
|
||||
|
||||
issue_5425: {
|
||||
options = {
|
||||
assignments: true,
|
||||
ie: true,
|
||||
toplevel: true,
|
||||
unused: true,
|
||||
yields: true,
|
||||
}
|
||||
input: {
|
||||
var a = "FAIL";
|
||||
var b = function* f() {}(a ? a = "PASS" : 42);
|
||||
console.log(a, typeof f);
|
||||
}
|
||||
expect: {
|
||||
var a = "FAIL";
|
||||
(function* f() {})(a && (a = "PASS"));
|
||||
console.log(a, typeof f);
|
||||
}
|
||||
expect_stdout: "PASS undefined"
|
||||
node_version: ">=4"
|
||||
}
|
||||
|
||||
issue_5456: {
|
||||
options = {
|
||||
inline: true,
|
||||
merge_vars: true,
|
||||
}
|
||||
input: {
|
||||
var a = true;
|
||||
(function() {
|
||||
(function(b, c) {
|
||||
var d = function*() {
|
||||
c = null;
|
||||
}();
|
||||
var e = function() {
|
||||
if (c)
|
||||
console.log(typeof d);
|
||||
while (b);
|
||||
}();
|
||||
})(function(i) {
|
||||
return console.log("foo") && i;
|
||||
}(a));
|
||||
})();
|
||||
}
|
||||
expect: {
|
||||
var a = true;
|
||||
(function() {
|
||||
b = (i = a, console.log("foo") && i),
|
||||
d = function*() {
|
||||
c = null;
|
||||
}(),
|
||||
e = function() {
|
||||
if (c) console.log(typeof d);
|
||||
while (b);
|
||||
}(),
|
||||
void 0;
|
||||
var b, c, d, e;
|
||||
var i;
|
||||
})();
|
||||
}
|
||||
expect_stdout: "foo"
|
||||
node_version: ">=4"
|
||||
}
|
||||
|
||||
issue_5506: {
|
||||
options = {
|
||||
dead_code: true,
|
||||
}
|
||||
input: {
|
||||
console.log(function(a) {
|
||||
var b = function*() {
|
||||
a = null in (a = "PASS");
|
||||
}();
|
||||
try {
|
||||
b.next();
|
||||
} catch (e) {
|
||||
return a;
|
||||
}
|
||||
}("FAIL"));
|
||||
}
|
||||
expect: {
|
||||
console.log(function(a) {
|
||||
var b = function*() {
|
||||
a = null in (a = "PASS");
|
||||
}();
|
||||
try {
|
||||
b.next();
|
||||
} catch (e) {
|
||||
return a;
|
||||
}
|
||||
}("FAIL"));
|
||||
}
|
||||
expect_stdout: "PASS"
|
||||
node_version: ">=4"
|
||||
}
|
||||
|
||||
issue_5526: {
|
||||
options = {
|
||||
inline: true,
|
||||
side_effects: true,
|
||||
}
|
||||
input: {
|
||||
(async function*() {
|
||||
try {
|
||||
return function() {
|
||||
while (console.log("foo"));
|
||||
}();
|
||||
} finally {
|
||||
console.log("bar");
|
||||
}
|
||||
})().next();
|
||||
console.log("baz");
|
||||
}
|
||||
expect: {
|
||||
(async function*() {
|
||||
try {
|
||||
while (console.log("foo"));
|
||||
return void 0;
|
||||
} finally {
|
||||
console.log("bar");
|
||||
}
|
||||
})().next();
|
||||
console.log("baz");
|
||||
}
|
||||
expect_stdout: [
|
||||
"foo",
|
||||
"baz",
|
||||
"bar",
|
||||
]
|
||||
node_version: ">=10"
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
function test(a){
|
||||
"aaaaaaaaaaaaaaaa"
|
||||
;a(err,data),a(err,
|
||||
"aaaaaaaaaaaaaaaa";
|
||||
a(err,data),a(err,
|
||||
data)}
|
||||
//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIjAiXSwibmFtZXMiOlsidGVzdCIsImNhbGxiYWNrIiwiZXJyIiwiZGF0YSJdLCJtYXBwaW5ncyI6IkFBQUEsU0FBU0EsS0FBS0M7O0NBRVZBLEVBQVNDLElBQUtDLE1BQ2RGLEVBQVNDO0FBQUtDIn0=
|
||||
//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIjAiXSwibmFtZXMiOlsidGVzdCIsImNhbGxiYWNrIiwiZXJyIiwiZGF0YSJdLCJtYXBwaW5ncyI6IkFBQUEsU0FBU0E7SEFBS0M7QUFFVkE7aEJBQVNDLElBQUtDLE1BQ2RGLEVBQVNDLElBQUtDIn0=
|
||||
1
test/input/module/expect.js
Normal file
1
test/input/module/expect.js
Normal file
@@ -0,0 +1 @@
|
||||
function n(){return this||arguments[0]+arguments[1]}function o(){return this||arguments[0]+arguments[1]}console.log(n(n(1,3),5)),console.log(o(o(2,4),6));
|
||||
13
test/input/module/input.js
Normal file
13
test/input/module/input.js
Normal file
@@ -0,0 +1,13 @@
|
||||
console.log(function() {
|
||||
function sum(...params) {
|
||||
return this || arguments[0] + arguments[1];
|
||||
}
|
||||
return sum(sum(1, 3), 5);
|
||||
}());
|
||||
console.log(function() {
|
||||
"use strict";
|
||||
function sum(...params) {
|
||||
return this || arguments[0] + arguments[1];
|
||||
}
|
||||
return sum(sum(2, 4), 6);
|
||||
}());
|
||||
17
test/input/reduce/export_default.js
Normal file
17
test/input/reduce/export_default.js
Normal file
@@ -0,0 +1,17 @@
|
||||
var unused;
|
||||
export default class {
|
||||
____11111() {
|
||||
a, b, c, d, e;
|
||||
f, g, h, i, j;
|
||||
k, l, m, n, o;
|
||||
p, q, r, s, t;
|
||||
u, v, w, x, y, z;
|
||||
A, B, C, D, E;
|
||||
F, G, H, I, J;
|
||||
K, L, M, N, O;
|
||||
P, Q, R, S, T;
|
||||
U, V, W, X, Y, Z;
|
||||
$, _;
|
||||
unused;
|
||||
}
|
||||
}
|
||||
@@ -7,7 +7,7 @@ describe("async", function() {
|
||||
"function await() {}",
|
||||
"function(await) {}",
|
||||
"function() { await; }",
|
||||
"function() { await:{} }",
|
||||
"function() { await: {} }",
|
||||
"function() { var await; }",
|
||||
"function() { function await() {} }",
|
||||
"function() { try {} catch (await) {} }",
|
||||
|
||||
@@ -928,6 +928,14 @@ describe("bin/uglifyjs", function() {
|
||||
done();
|
||||
});
|
||||
});
|
||||
it("Should work with --module", function(done) {
|
||||
var command = uglifyjscmd + " test/input/module/input.js --module -mc";
|
||||
exec(command, function(err, stdout, stderr) {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(stdout, read("test/input/module/expect.js"));
|
||||
done();
|
||||
});
|
||||
});
|
||||
it("Should compress swarm of unused variables with reasonable performance", function(done) {
|
||||
var code = [
|
||||
"console.log(function() {",
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
var acorn = require("acorn");
|
||||
var assert = require("assert");
|
||||
var UglifyJS = require("../node");
|
||||
|
||||
@@ -25,6 +26,7 @@ describe("export", function() {
|
||||
"export { * };",
|
||||
"export { * as A };",
|
||||
"export { 42 as A };",
|
||||
"export { 'A' as B };",
|
||||
"export { A as B-C };",
|
||||
"export { default as A };",
|
||||
].forEach(function(code) {
|
||||
@@ -51,8 +53,11 @@ describe("export", function() {
|
||||
it("Should reject invalid `export ... from ...` statement syntax", function() {
|
||||
[
|
||||
"export from 'path';",
|
||||
"export A from 'path';",
|
||||
"export * from `path`;",
|
||||
"export 'A' from 'path';",
|
||||
"export A as B from 'path';",
|
||||
"export 'A' as B from 'path';",
|
||||
"export default from 'path';",
|
||||
"export { A }, B from 'path';",
|
||||
"export * as A, B from 'path';",
|
||||
@@ -68,4 +73,109 @@ describe("export", function() {
|
||||
}, code);
|
||||
});
|
||||
});
|
||||
it("Should reject `export` statement not under top-level scope", function() {
|
||||
[
|
||||
"{ export {}; }",
|
||||
"if (0) export var A;",
|
||||
"function f() { export default 42; }",
|
||||
].forEach(function(code) {
|
||||
assert.throws(function() {
|
||||
UglifyJS.parse(code);
|
||||
}, function(e) {
|
||||
return e instanceof UglifyJS.JS_Parse_Error;
|
||||
}, code);
|
||||
});
|
||||
});
|
||||
it("Should compare `export` statements correctly", function() {
|
||||
var stats = {
|
||||
Declaration: [
|
||||
"export let A;",
|
||||
"export const A = 42;",
|
||||
"export var { A, B: [] } = C;",
|
||||
"export function A() { return B(A); }",
|
||||
"export async function* A({}, ...[]) { return B(A); }",
|
||||
],
|
||||
Default: [
|
||||
"export default 42;",
|
||||
"export default A => A(B);",
|
||||
"export default class A extends B {}",
|
||||
"export default (class A extends B {});",
|
||||
"export default class A { static C = 42; }",
|
||||
"export default class A extends B { static C = 42; }",
|
||||
],
|
||||
Foreign: [
|
||||
"export * from 'path';",
|
||||
"export {} from 'path';",
|
||||
"export * as A from 'path';",
|
||||
"export { default } from 'path';",
|
||||
"export { A, B as C } from 'path';",
|
||||
"export { A, default as C } from 'path';",
|
||||
],
|
||||
References: [
|
||||
"export {};",
|
||||
"export { A };",
|
||||
"export { A as B };",
|
||||
"export { A, B as C };",
|
||||
"export { A as default };",
|
||||
],
|
||||
};
|
||||
for (var k in stats) stats[k].forEach(function(c, i) {
|
||||
var s = UglifyJS.parse(c);
|
||||
assert.ok(s instanceof UglifyJS.AST_Toplevel, c);
|
||||
assert.strictEqual(s.body.length, 1, c);
|
||||
assert.strictEqual(s.body[0].TYPE, "Export" + k, c);
|
||||
for (var l in stats) stats[l].forEach(function(d, j) {
|
||||
var t = UglifyJS.parse(d);
|
||||
assert.ok(t instanceof UglifyJS.AST_Toplevel, d);
|
||||
assert.strictEqual(t.body.length, 1, d);
|
||||
assert.strictEqual(t.body[0].TYPE, "Export" + l, d);
|
||||
assert.strictEqual(s.equals(t), k === l && i === j, c + "\n" + d);
|
||||
});
|
||||
});
|
||||
});
|
||||
it("Should interoperate with ESTree correctly", function() {
|
||||
[
|
||||
"export var A = 42;",
|
||||
"export default (class A {});",
|
||||
"var A; export { A as '42' };",
|
||||
"export { '42' } from 'path';",
|
||||
"export * as '42' from 'path';",
|
||||
].forEach(function(code) {
|
||||
var ast = UglifyJS.parse(code);
|
||||
try {
|
||||
var spidermonkey = ast.to_mozilla_ast();
|
||||
} catch (ex) {
|
||||
assert.fail("[to_mozilla_ast] " + ex.stack);
|
||||
}
|
||||
try {
|
||||
var ast2 = UglifyJS.AST_Node.from_mozilla_ast(spidermonkey);
|
||||
} catch (ex) {
|
||||
assert.fail("[from_mozilla_ast] " + ex.stack);
|
||||
}
|
||||
assert.strictEqual(ast2.print_to_string(), ast.print_to_string(), [
|
||||
"spidermonkey:",
|
||||
ast.print_to_string(),
|
||||
ast2.print_to_string(),
|
||||
].join("\n"));
|
||||
try {
|
||||
var acorn_est = acorn.parse(code, {
|
||||
ecmaVersion: "latest",
|
||||
locations: true,
|
||||
sourceType: "module",
|
||||
});
|
||||
} catch (ex) {
|
||||
assert.fail("[acorn.parse] " + ex.stack);
|
||||
}
|
||||
try {
|
||||
var ast3 = UglifyJS.AST_Node.from_mozilla_ast(acorn_est);
|
||||
} catch (ex) {
|
||||
assert.fail("[from_acorn] " + ex.stack);
|
||||
}
|
||||
assert.strictEqual(ast3.print_to_string(), ast.print_to_string(), [
|
||||
"acorn:",
|
||||
ast.print_to_string(),
|
||||
ast3.print_to_string(),
|
||||
].join("\n"));
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
var acorn = require("acorn");
|
||||
var assert = require("assert");
|
||||
var UglifyJS = require("../node");
|
||||
|
||||
@@ -8,15 +9,25 @@ describe("import", function() {
|
||||
"import A;",
|
||||
"import {};",
|
||||
"import `path`;",
|
||||
"{ import 'path'; }",
|
||||
"import from 'path';",
|
||||
"if (0) import 'path';",
|
||||
"import * from 'path';",
|
||||
"import 'A' from 'path';",
|
||||
"import A-B from 'path';",
|
||||
"import A as B from 'path';",
|
||||
"import { A }, B from 'path';",
|
||||
"import * as 'A' from 'path';",
|
||||
"import * as A-B from 'path';",
|
||||
"import * as A, B from 'path';",
|
||||
"import * as A, {} from 'path';",
|
||||
"import { * as A } from 'path';",
|
||||
"import { * as 'A' } from 'path';",
|
||||
"import { * as A-B } from 'path';",
|
||||
"function f() { import 'path'; }",
|
||||
"import { 42 as A } from 'path';",
|
||||
"import { A-B as C } from 'path';",
|
||||
"import { 'A' as 'B' } from 'path';",
|
||||
].forEach(function(code) {
|
||||
assert.throws(function() {
|
||||
UglifyJS.parse(code);
|
||||
@@ -25,4 +36,74 @@ describe("import", function() {
|
||||
}, code);
|
||||
});
|
||||
});
|
||||
it("Should compare `import` statements correctly", function() {
|
||||
[
|
||||
"import 'foo';",
|
||||
"import 'path';",
|
||||
"import A from 'path';",
|
||||
"import { A } from 'path';",
|
||||
"import * as A from 'path';",
|
||||
"import A, { B } from 'path';",
|
||||
"import A, * as B from 'path';",
|
||||
"import { A as B } from 'path';",
|
||||
"import A, { B, C as D } from 'path';",
|
||||
].forEach(function(c, i, stats) {
|
||||
var s = UglifyJS.parse(c);
|
||||
assert.ok(s instanceof UglifyJS.AST_Toplevel, c);
|
||||
assert.strictEqual(s.body.length, 1, c);
|
||||
assert.ok(s.body[0] instanceof UglifyJS.AST_Import, c);
|
||||
stats.forEach(function(d, j) {
|
||||
var t = UglifyJS.parse(d);
|
||||
assert.ok(t instanceof UglifyJS.AST_Toplevel, d);
|
||||
assert.strictEqual(t.body.length, 1, d);
|
||||
assert.ok(t.body[0] instanceof UglifyJS.AST_Import, d);
|
||||
assert.strictEqual(s.equals(t), i === j, c + "\n" + d);
|
||||
});
|
||||
});
|
||||
});
|
||||
it("Should interoperate with ESTree correctly", function() {
|
||||
[
|
||||
"import A from 'path';",
|
||||
"import * as A from 'path';",
|
||||
"import A, * as B from 'path';",
|
||||
"import { '42' as A, B } from 'path';",
|
||||
"import A, { '42' as B } from 'path';",
|
||||
].forEach(function(code) {
|
||||
var ast = UglifyJS.parse(code);
|
||||
try {
|
||||
var spidermonkey = ast.to_mozilla_ast();
|
||||
} catch (ex) {
|
||||
assert.fail("[to_mozilla_ast] " + ex.stack);
|
||||
}
|
||||
try {
|
||||
var ast2 = UglifyJS.AST_Node.from_mozilla_ast(spidermonkey);
|
||||
} catch (ex) {
|
||||
assert.fail("[from_mozilla_ast] " + ex.stack);
|
||||
}
|
||||
assert.strictEqual(ast2.print_to_string(), ast.print_to_string(), [
|
||||
"spidermonkey:",
|
||||
ast.print_to_string(),
|
||||
ast2.print_to_string(),
|
||||
].join("\n"));
|
||||
try {
|
||||
var acorn_est = acorn.parse(code, {
|
||||
ecmaVersion: "latest",
|
||||
locations: true,
|
||||
sourceType: "module",
|
||||
});
|
||||
} catch (ex) {
|
||||
assert.fail("[acorn.parse] " + ex.stack);
|
||||
}
|
||||
try {
|
||||
var ast3 = UglifyJS.AST_Node.from_mozilla_ast(acorn_est);
|
||||
} catch (ex) {
|
||||
assert.fail("[from_acorn] " + ex.stack);
|
||||
}
|
||||
assert.strictEqual(ast3.print_to_string(), ast.print_to_string(), [
|
||||
"acorn:",
|
||||
ast.print_to_string(),
|
||||
ast3.print_to_string(),
|
||||
].join("\n"));
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
var assert = require("assert");
|
||||
var readFileSync = require("fs").readFileSync;
|
||||
var run_code = require("../sandbox").run_code;
|
||||
var semver = require("semver");
|
||||
var UglifyJS = require("../..");
|
||||
|
||||
function read(path) {
|
||||
@@ -320,6 +321,24 @@ describe("minify", function() {
|
||||
});
|
||||
});
|
||||
|
||||
describe("module", function() {
|
||||
it("Should not inline `await` variables", function() {
|
||||
if (semver.satisfies(process.version, "<8")) return;
|
||||
var code = [
|
||||
"console.log(function() {",
|
||||
" return typeof await;",
|
||||
"}());",
|
||||
].join("\n");
|
||||
assert.strictEqual(run_code("(async function(){" + code + "})();"), "undefined\n");
|
||||
var result = UglifyJS.minify(code, {
|
||||
module: true,
|
||||
});
|
||||
if (result.error) throw result.error;
|
||||
assert.strictEqual(result.code, "console.log(function(){return typeof await}());");
|
||||
assert.strictEqual(run_code("(async function(){" + result.code + "})();"), "undefined\n");
|
||||
});
|
||||
});
|
||||
|
||||
describe("rename", function() {
|
||||
it("Should be repeatable", function() {
|
||||
var code = "!function(x){return x(x)}(y);";
|
||||
|
||||
@@ -434,4 +434,55 @@ describe("test/reduce.js", function() {
|
||||
"// }",
|
||||
].join("\n"));
|
||||
});
|
||||
it("Should transform `export default class` correctly", function() {
|
||||
var result = reduce_test(read("test/input/reduce/export_default.js"), {
|
||||
compress: false,
|
||||
toplevel: true,
|
||||
});
|
||||
if (result.error) throw result.error;
|
||||
assert.strictEqual(result.code, [
|
||||
"// Can't reproduce test failure",
|
||||
"// minify options: {",
|
||||
'// "compress": false,',
|
||||
'// "toplevel": true',
|
||||
"// }",
|
||||
].join("\n"));
|
||||
});
|
||||
it("Should transform `export default function` correctly", function() {
|
||||
var code = [
|
||||
"for (var k in this)",
|
||||
" console.log(k);",
|
||||
"export default (function f() {});",
|
||||
"console.log(k);",
|
||||
].join("\n");
|
||||
var result = reduce_test(code, {
|
||||
mangle: false,
|
||||
});
|
||||
if (result.error) throw result.error;
|
||||
assert.strictEqual(result.code, [
|
||||
"// Can't reproduce test failure",
|
||||
"// minify options: {",
|
||||
'// "mangle": false',
|
||||
"// }",
|
||||
].join("\n"));
|
||||
});
|
||||
it("Should transform `export default (42)` correctly", function() {
|
||||
var code = [
|
||||
"export default (42);",
|
||||
"for (var k in this)",
|
||||
" console.log(k);",
|
||||
].join("\n");
|
||||
var result = reduce_test(code, {
|
||||
compress: false,
|
||||
mangle: false,
|
||||
});
|
||||
if (result.error) throw result.error;
|
||||
assert.strictEqual(result.code, [
|
||||
"// Can't reproduce test failure",
|
||||
"// minify options: {",
|
||||
'// "compress": false,',
|
||||
'// "mangle": false',
|
||||
"// }",
|
||||
].join("\n"));
|
||||
});
|
||||
});
|
||||
|
||||
@@ -6,7 +6,7 @@ describe("generator", function() {
|
||||
[
|
||||
"function yield() {}",
|
||||
"function(yield) {}",
|
||||
"function() { yield:{} }",
|
||||
"function() { yield: {} }",
|
||||
"function() { var yield; }",
|
||||
"function() { function yield() {} }",
|
||||
"function() { try {} catch (yield) {} }",
|
||||
|
||||
@@ -9,19 +9,22 @@ function beautify(ast) {
|
||||
var beautified = UglifyJS.minify(ast, {
|
||||
compress: false,
|
||||
mangle: false,
|
||||
module: ufuzz.module,
|
||||
output: {
|
||||
ast: true,
|
||||
beautify: true,
|
||||
braces: true,
|
||||
},
|
||||
});
|
||||
if (beautified.error) return beautified;
|
||||
return UglifyJS.minify(beautified.code, {
|
||||
compress: false,
|
||||
mangle: false,
|
||||
output: {
|
||||
ast: true,
|
||||
},
|
||||
});
|
||||
if (!beautified.error) {
|
||||
var verify = UglifyJS.minify(beautified.code, {
|
||||
compress: false,
|
||||
mangle: false,
|
||||
module: ufuzz.module,
|
||||
});
|
||||
if (verify.error) return verify;
|
||||
}
|
||||
return beautified;
|
||||
}
|
||||
|
||||
function validate(ast) {
|
||||
@@ -35,6 +38,7 @@ function validate(ast) {
|
||||
return UglifyJS.minify(ast, {
|
||||
compress: false,
|
||||
mangle: false,
|
||||
module: ufuzz.module,
|
||||
output: {
|
||||
ast: true,
|
||||
},
|
||||
@@ -57,12 +61,12 @@ function test(input, to_moz, description, skip_on_error, beautified) {
|
||||
var ast = UglifyJS.AST_Node.from_mozilla_ast(to_moz(input));
|
||||
} catch (e) {
|
||||
if (skip_on_error) return true;
|
||||
console.log("//=============================================================");
|
||||
console.log("//", description, "failed... round", round);
|
||||
console.log(e);
|
||||
console.log("// original code");
|
||||
if (beautified === true) console.log("// (beautified)");
|
||||
console.log(input.code);
|
||||
console.error("//=============================================================");
|
||||
console.error("//", description, "failed... round", round);
|
||||
console.error(e);
|
||||
console.error("// original code");
|
||||
if (beautified === true) console.error("// (beautified)");
|
||||
console.error(input.code);
|
||||
return false;
|
||||
}
|
||||
var transformed = validate(ast);
|
||||
@@ -74,34 +78,34 @@ function test(input, to_moz, description, skip_on_error, beautified) {
|
||||
if (!test(beautified, to_moz, description, skip_on_error, true)) return false;
|
||||
}
|
||||
}
|
||||
console.log("//=============================================================");
|
||||
console.log("// !!!!!! Failed... round", round);
|
||||
console.log("// original code");
|
||||
console.error("//=============================================================");
|
||||
console.error("// !!!!!! Failed... round", round);
|
||||
console.error("// original code");
|
||||
if (beautified.error) {
|
||||
console.log("// !!! beautify failed !!!");
|
||||
console.log(beautified.error.stack);
|
||||
console.error("// !!! beautify failed !!!");
|
||||
console.error(beautified.error.stack);
|
||||
} else if (beautified === true) {
|
||||
console.log("// (beautified)");
|
||||
console.error("// (beautified)");
|
||||
}
|
||||
console.log(input.raw);
|
||||
console.log();
|
||||
console.log();
|
||||
console.log("//-------------------------------------------------------------");
|
||||
console.log("//", description);
|
||||
console.error(input.raw);
|
||||
console.error();
|
||||
console.error();
|
||||
console.error("//-------------------------------------------------------------");
|
||||
console.error("//", description);
|
||||
if (transformed.error) {
|
||||
console.log(transformed.error.stack);
|
||||
console.error(transformed.error.stack);
|
||||
} else {
|
||||
beautified = beautify(transformed.ast);
|
||||
if (beautified.error) {
|
||||
console.log("// !!! beautify failed !!!");
|
||||
console.log(beautified.error.stack);
|
||||
console.log(transformed.code);
|
||||
console.error("// !!! beautify failed !!!");
|
||||
console.error(beautified.error.stack);
|
||||
console.error(transformed.code);
|
||||
} else {
|
||||
console.log("// (beautified)");
|
||||
console.log(beautified.code);
|
||||
console.error("// (beautified)");
|
||||
console.error(beautified.code);
|
||||
}
|
||||
}
|
||||
console.log("!!!!!! Failed... round", round);
|
||||
console.error("!!!!!! Failed... round", round);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
@@ -115,9 +119,29 @@ for (var round = 1; round <= num_iterations; round++) {
|
||||
var code = ufuzz.createTopLevelCode();
|
||||
minify_options.forEach(function(options) {
|
||||
var ok = true;
|
||||
var input = UglifyJS.minify(options ? UglifyJS.minify(code, JSON.parse(options)).code : code, {
|
||||
var minified;
|
||||
if (options) {
|
||||
var o = JSON.parse(options);
|
||||
o.module = ufuzz.module;
|
||||
minified = UglifyJS.minify(code, o);
|
||||
if (minified.error) {
|
||||
console.log("//=============================================================");
|
||||
console.log("// minify() failed... round", round);
|
||||
console.log("// original code");
|
||||
console.log(code);
|
||||
console.log();
|
||||
console.log();
|
||||
console.log("//-------------------------------------------------------------");
|
||||
console.log("minify(options):");
|
||||
console.log(JSON.stringify(o, null, 2));
|
||||
return;
|
||||
}
|
||||
minified = minified.code;
|
||||
}
|
||||
var input = UglifyJS.minify(minified || code, {
|
||||
compress: false,
|
||||
mangle: false,
|
||||
module: ufuzz.module,
|
||||
output: {
|
||||
ast: true,
|
||||
},
|
||||
@@ -125,11 +149,27 @@ for (var round = 1; round <= num_iterations; round++) {
|
||||
input.raw = options ? input.code : code;
|
||||
if (input.error) {
|
||||
ok = false;
|
||||
console.log("//=============================================================");
|
||||
console.log("// minify() failed... round", round);
|
||||
console.log(input.error);
|
||||
console.log("// original code");
|
||||
console.log(code);
|
||||
console.error("//=============================================================");
|
||||
console.error("// parse() failed... round", round);
|
||||
console.error("// original code");
|
||||
console.error(code);
|
||||
console.error();
|
||||
console.error();
|
||||
if (options) {
|
||||
console.error("//-------------------------------------------------------------");
|
||||
console.error("// minified code");
|
||||
console.error(minified);
|
||||
console.error();
|
||||
console.error();
|
||||
console.error("//-------------------------------------------------------------");
|
||||
console.error("minify(options):");
|
||||
console.error(JSON.stringify(o, null, 2));
|
||||
console.error();
|
||||
console.error();
|
||||
}
|
||||
console.error("//-------------------------------------------------------------");
|
||||
console.error("// parse() error");
|
||||
console.error(input.error);
|
||||
}
|
||||
if (ok) ok = test(input, function(input) {
|
||||
return input.ast.to_mozilla_ast();
|
||||
@@ -141,7 +181,10 @@ for (var round = 1; round <= num_iterations; round++) {
|
||||
sourceType: "module",
|
||||
});
|
||||
}, "acorn.parse()", !ufuzz.verbose);
|
||||
if (!ok) process.exit(1);
|
||||
if (!ok && isFinite(num_iterations)) {
|
||||
console.log();
|
||||
process.exit(1);
|
||||
}
|
||||
});
|
||||
}
|
||||
console.log();
|
||||
|
||||
1133
test/reduce.js
1133
test/reduce.js
File diff suppressed because it is too large
Load Diff
@@ -54,7 +54,7 @@ ERR=$?; if [ "$ERR" != "0" ]; then echo "Error: $ERR"; exit $ERR; fi
|
||||
minify_in_situ "src" \
|
||||
&& minify_in_situ "third_party" \
|
||||
&& rm -rf node_modules \
|
||||
&& npm_install \
|
||||
&& npm_install --package-lock \
|
||||
&& rm -rf build/* \
|
||||
&& npm run build:terser-bundled \
|
||||
&& npm run build:uglify-js-bundled \
|
||||
|
||||
@@ -52,11 +52,19 @@ exports.same_stdout = semver.satisfies(process.version, "0.12") ? function(expec
|
||||
return typeof expected == typeof actual && strip_func_ids(expected) == strip_func_ids(actual);
|
||||
};
|
||||
exports.patch_module_statements = function(code) {
|
||||
var count = 0, imports = [];
|
||||
code = code.replace(/\bexport(?:\s*\{[^{}]*}\s*?(?:$|\n|;)|\s+default\b(?:\s*(\(|\{|class\s*\{|class\s+(?=extends\b)|(?:async\s+)?function\s*(?:\*\s*)?\())?|\b)/g, function(match, header) {
|
||||
var count = 0, has_default = "", imports = [], strict_mode = "";
|
||||
code = code.replace(/^\s*("|')use strict\1\s*;?/, function(match) {
|
||||
strict_mode = match;
|
||||
return "";
|
||||
}).replace(/\bexport(?:\s*\{[^{}]*}\s*?(?:$|\n|;)|\s+default\b(?:\s*(\(|\{|class\s*\{|class\s+(?=extends\b)|(?:async\s+)?function\s*(?:\*\s*)?\())?|\b)/g, function(match, header) {
|
||||
if (/^export\s+default/.test(match)) has_default = "var _uglify_export_default_;";
|
||||
if (!header) return "";
|
||||
if (header.length == 1) return "0, " + header;
|
||||
return header.slice(0, -1) + " _" + ++count + header.slice(-1);
|
||||
var name = "_uglify_export_default_";
|
||||
if (/^class\b/.test(header)) do {
|
||||
name = "_uglify_export_default_" + ++count;
|
||||
} while (code.indexOf(name) >= 0);
|
||||
return header.slice(0, -1) + " " + name + header.slice(-1);
|
||||
}).replace(/\bimport\.meta\b/g, function() {
|
||||
return '({ url: "https://example.com/path/index.html" })';
|
||||
}).replace(/\bimport\b(?:\s*([^\s('"][^('"]*)\bfrom\b)?\s*(['"]).*?\2(?:$|\n|;)/g, function(match, symbols) {
|
||||
@@ -73,7 +81,7 @@ exports.patch_module_statements = function(code) {
|
||||
return "";
|
||||
});
|
||||
imports.push("");
|
||||
return imports.join("\n") + code;
|
||||
return strict_mode + has_default + imports.join("\n") + code;
|
||||
};
|
||||
|
||||
function is_error(result) {
|
||||
|
||||
@@ -128,7 +128,7 @@ for (var i = 2; i < process.argv.length; ++i) {
|
||||
|
||||
var SUPPORT = function(matrix) {
|
||||
for (var name in matrix) {
|
||||
matrix[name] = typeof sandbox.run_code(matrix[name]) == "string";
|
||||
matrix[name] = !sandbox.is_error(sandbox.run_code(matrix[name]));
|
||||
}
|
||||
return matrix;
|
||||
}({
|
||||
@@ -140,6 +140,7 @@ var SUPPORT = function(matrix) {
|
||||
class: "class C { f() {} }",
|
||||
class_field: "class C { p = 0; }",
|
||||
class_private: "class C { #f() {} }",
|
||||
class_static_init: "class C { static {} }",
|
||||
computed_key: "({[0]: 0});",
|
||||
const_block: "var a; { const a = 0; }",
|
||||
default_value: "[ a = 0 ] = [];",
|
||||
@@ -252,7 +253,7 @@ BINARY_OPS = BINARY_OPS.concat(BINARY_OPS);
|
||||
if (SUPPORT.exponentiation) BINARY_OPS.push("**");
|
||||
BINARY_OPS = BINARY_OPS.concat(BINARY_OPS);
|
||||
BINARY_OPS = BINARY_OPS.concat(BINARY_OPS);
|
||||
BINARY_OPS.push(" in ");
|
||||
BINARY_OPS.push(" in ", " instanceof ");
|
||||
|
||||
var ASSIGNMENTS = [ "=" ];
|
||||
ASSIGNMENTS = ASSIGNMENTS.concat(ASSIGNMENTS);
|
||||
@@ -405,7 +406,7 @@ function createTopLevelCode() {
|
||||
unique_vars.length = 0;
|
||||
classes.length = 0;
|
||||
allow_this = true;
|
||||
async = false;
|
||||
async = SUPPORT.async && rng(200) == 0;
|
||||
has_await = false;
|
||||
export_default = false;
|
||||
generator = false;
|
||||
@@ -413,7 +414,7 @@ function createTopLevelCode() {
|
||||
funcs = 0;
|
||||
clazz = 0;
|
||||
imports = 0;
|
||||
in_class = 0;
|
||||
in_class = async;
|
||||
called = Object.create(null);
|
||||
var s = [
|
||||
strictMode(),
|
||||
@@ -1181,7 +1182,11 @@ function createStatement(recurmax, canThrow, canBreak, canContinue, cannotReturn
|
||||
unique_vars.length = unique_len;
|
||||
});
|
||||
}
|
||||
if (n !== 0) s += " finally { " + createStatements(3, recurmax, canThrow, canBreak, canContinue, cannotReturn, stmtDepth) + " }";
|
||||
if (n !== 0) s += [
|
||||
" finally { ",
|
||||
createStatements(rng(5) + 1, recurmax, canThrow, canBreak, canContinue, cannotReturn, stmtDepth),
|
||||
" }",
|
||||
].join("");
|
||||
return s;
|
||||
case STMT_C:
|
||||
return "c = c + 1;";
|
||||
@@ -1805,7 +1810,7 @@ function createClassLiteral(recurmax, stmtDepth, canThrow, name) {
|
||||
if (canThrow && rng(20) == 0) {
|
||||
s += p;
|
||||
} else {
|
||||
s += "(" + p + " && " + p + ".constructor === Function ? " + p + " : function() {})";
|
||||
s += "(typeof " + p + ' == "function" && typeof ' + p + '.prototype == "object" && ' + p + ".constructor === Function ? " + p + " : function() {})";
|
||||
}
|
||||
}
|
||||
s += " {\n";
|
||||
@@ -1824,15 +1829,31 @@ function createClassLiteral(recurmax, stmtDepth, canThrow, name) {
|
||||
declared.push(internal);
|
||||
}
|
||||
if (SUPPORT.class_field && rng(2)) {
|
||||
s += internal || createObjectKey(recurmax, stmtDepth, canThrow);
|
||||
if (internal) {
|
||||
s += internal;
|
||||
} else if (fixed && bug_class_static_nontrivial) {
|
||||
s += getDotKey();
|
||||
} else {
|
||||
s += createObjectKey(recurmax, stmtDepth, canThrow);
|
||||
}
|
||||
if (rng(5)) {
|
||||
async = bug_async_class_await && fixed && 0;
|
||||
async = false;
|
||||
generator = false;
|
||||
s += " = " + createExpression(recurmax, NO_COMMA, stmtDepth, fixed ? canThrow : CANNOT_THROW);
|
||||
generator = save_generator;
|
||||
async = save_async;
|
||||
}
|
||||
s += ";\n";
|
||||
} else if (SUPPORT.class_static_init && fixed && !internal && rng(10) == 0) {
|
||||
async = false;
|
||||
generator = false;
|
||||
s += [
|
||||
"{ ",
|
||||
createStatements(rng(5) + 1, recurmax, canThrow, CANNOT_BREAK, CANNOT_CONTINUE, CANNOT_RETURN, stmtDepth),
|
||||
" }\n",
|
||||
].join("");
|
||||
generator = save_generator;
|
||||
async = save_async;
|
||||
} else {
|
||||
if (!fixed && !internal && constructor && rng(10) == 0) {
|
||||
internal = constructor;
|
||||
@@ -1988,7 +2009,7 @@ function createBinaryOp(noComma, canThrow) {
|
||||
var op;
|
||||
do {
|
||||
op = BINARY_OPS[rng(BINARY_OPS.length)];
|
||||
} while (noComma && op == "," || !canThrow && op == " in ");
|
||||
} while (noComma && op == "," || !canThrow && /^ in/.test(op));
|
||||
return op;
|
||||
}
|
||||
|
||||
@@ -2031,7 +2052,7 @@ function isBannedKeyword(name) {
|
||||
case "let":
|
||||
return in_class;
|
||||
case "await":
|
||||
return async !== false;
|
||||
return async || in_class && bug_class_static_await;
|
||||
case "yield":
|
||||
return generator || in_class;
|
||||
}
|
||||
@@ -2074,13 +2095,23 @@ function createVarName(maybe, dontStore) {
|
||||
}
|
||||
|
||||
if (require.main !== module) {
|
||||
exports.createTopLevelCode = createTopLevelCode;
|
||||
exports.createTopLevelCode = function() {
|
||||
var code = createTopLevelCode();
|
||||
exports.module = async && has_await;
|
||||
return code;
|
||||
};
|
||||
exports.num_iterations = num_iterations;
|
||||
exports.verbose = verbose;
|
||||
return;
|
||||
}
|
||||
|
||||
function run_code(code, toplevel, timeout) {
|
||||
if (async && has_await) code = [
|
||||
'"use strict";',
|
||||
"(async()=>{",
|
||||
code,
|
||||
'})().catch(e=>process.on("exit",()=>{throw e}));',
|
||||
].join("\n");
|
||||
return sandbox.run_code(sandbox.patch_module_statements(code), toplevel, timeout);
|
||||
}
|
||||
|
||||
@@ -2100,7 +2131,9 @@ function errorln(msg) {
|
||||
}
|
||||
|
||||
function try_beautify(code, toplevel, result, printfn, options) {
|
||||
var beautified = UglifyJS.minify(code, JSON.parse(beautify_options));
|
||||
var o = JSON.parse(beautify_options);
|
||||
if (async && has_await) o.module = true;
|
||||
var beautified = UglifyJS.minify(code, o);
|
||||
if (beautified.error) {
|
||||
printfn("// !!! beautify failed !!!");
|
||||
printfn(beautified.error);
|
||||
@@ -2110,7 +2143,7 @@ function try_beautify(code, toplevel, result, printfn, options) {
|
||||
} else if (options) {
|
||||
var uglified = UglifyJS.minify(beautified.code, JSON.parse(options));
|
||||
var expected, actual;
|
||||
if (typeof uglify_code != "string" || uglified.error) {
|
||||
if (sandbox.is_error(uglify_code) || uglified.error) {
|
||||
expected = uglify_code;
|
||||
actual = uglified.error;
|
||||
} else {
|
||||
@@ -2139,7 +2172,7 @@ function log_suspects(minify_options, component) {
|
||||
var defs = default_options[component];
|
||||
var toplevel = sandbox.has_toplevel(minify_options);
|
||||
var suspects = Object.keys(defs).filter(function(name) {
|
||||
var flip = name == "keep_fargs";
|
||||
var flip = component == "compress" && name == "keep_fargs";
|
||||
if (flip !== (name in options ? options : defs)[name]) {
|
||||
var m = JSON.parse(JSON.stringify(minify_options));
|
||||
var o = JSON.parse(JSON.stringify(options));
|
||||
@@ -2147,7 +2180,7 @@ function log_suspects(minify_options, component) {
|
||||
m[component] = o;
|
||||
m.validate = true;
|
||||
var result = UglifyJS.minify(original_code, m);
|
||||
if (typeof uglify_code != "string") {
|
||||
if (sandbox.is_error(uglify_code)) {
|
||||
return !sandbox.same_stdout(uglify_code, result.error);
|
||||
} else if (result.error) {
|
||||
errorln("Error testing options." + component + "." + name);
|
||||
@@ -2175,7 +2208,7 @@ function log_suspects_global(options, toplevel) {
|
||||
m[component] = false;
|
||||
m.validate = true;
|
||||
var result = UglifyJS.minify(original_code, m);
|
||||
if (typeof uglify_code != "string") {
|
||||
if (sandbox.is_error(uglify_code)) {
|
||||
return !sandbox.same_stdout(uglify_code, result.error);
|
||||
} else if (result.error) {
|
||||
errorln("Error testing options." + component);
|
||||
@@ -2204,7 +2237,16 @@ function log(options) {
|
||||
errorln();
|
||||
errorln();
|
||||
errorln("//-------------------------------------------------------------");
|
||||
if (typeof uglify_code == "string") {
|
||||
if (sandbox.is_error(uglify_code)) {
|
||||
errorln("// !!! uglify failed !!!");
|
||||
errorln(uglify_code);
|
||||
if (original_erred) {
|
||||
errorln();
|
||||
errorln();
|
||||
errorln("original stacktrace:");
|
||||
errorln(original_result);
|
||||
}
|
||||
} else {
|
||||
errorln("// uglified code");
|
||||
try_beautify(uglify_code, toplevel, uglify_result, errorln);
|
||||
errorln();
|
||||
@@ -2213,15 +2255,6 @@ function log(options) {
|
||||
errorln(original_result);
|
||||
errorln("uglified result:");
|
||||
errorln(uglify_result);
|
||||
} else {
|
||||
errorln("// !!! uglify failed !!!");
|
||||
errorln(uglify_code);
|
||||
if (errored) {
|
||||
errorln();
|
||||
errorln();
|
||||
errorln("original stacktrace:");
|
||||
errorln(original_result);
|
||||
}
|
||||
}
|
||||
errorln("//-------------------------------------------------------------");
|
||||
if (!ok) {
|
||||
@@ -2253,12 +2286,27 @@ function log(options) {
|
||||
}
|
||||
|
||||
function sort_globals(code) {
|
||||
var globals = run_code("throw Object.keys(this).sort(" + function(global) {
|
||||
var injected = "throw Object.keys(this).sort(" + function(global) {
|
||||
return function(m, n) {
|
||||
return (typeof global[n] == "function") - (typeof global[m] == "function")
|
||||
|| (m < n ? -1 : m > n ? 1 : 0);
|
||||
};
|
||||
} + "(this));\n" + code);
|
||||
} + "(this));";
|
||||
var save_async = async;
|
||||
if (async && has_await) {
|
||||
async = false;
|
||||
injected = [
|
||||
'"use strict";',
|
||||
injected,
|
||||
"(async function(){",
|
||||
code,
|
||||
"})();"
|
||||
].join("\n");
|
||||
} else {
|
||||
injected += "\n" + code;
|
||||
}
|
||||
var globals = run_code(injected);
|
||||
async = save_async;
|
||||
if (!Array.isArray(globals)) {
|
||||
errorln();
|
||||
errorln();
|
||||
@@ -2318,20 +2366,28 @@ function is_error_in(ex) {
|
||||
return ex.name == "TypeError" && /'in'/.test(ex.message);
|
||||
}
|
||||
|
||||
function is_error_tdz(ex) {
|
||||
return ex.name == "ReferenceError";
|
||||
}
|
||||
|
||||
function is_error_spread(ex) {
|
||||
return ex.name == "TypeError" && /Found non-callable @@iterator| is not iterable| not a function/.test(ex.message);
|
||||
return ex.name == "TypeError" && /Found non-callable @@iterator| is not iterable| not a function|Symbol\(Symbol\.iterator\)/.test(ex.message);
|
||||
}
|
||||
|
||||
function is_error_recursion(ex) {
|
||||
return ex.name == "RangeError" && /Invalid string length|Maximum call stack size exceeded/.test(ex.message);
|
||||
}
|
||||
|
||||
function is_error_set_property(ex) {
|
||||
return ex.name == "TypeError" && /^Cannot set propert[\s\S]+? of (null|undefined)/.test(ex.message);
|
||||
}
|
||||
|
||||
function is_error_redeclaration(ex) {
|
||||
return ex.name == "SyntaxError" && /already been declared|redeclaration/.test(ex.message);
|
||||
}
|
||||
|
||||
function is_error_destructuring(ex) {
|
||||
return ex.name == "TypeError" && /^Cannot destructure /.test(ex.message);
|
||||
return ex.name == "TypeError" && /^Cannot (destructure|read propert)/.test(ex.message);
|
||||
}
|
||||
|
||||
function is_error_class_constructor(ex) {
|
||||
@@ -2345,6 +2401,8 @@ function is_error_getter_only_property(ex) {
|
||||
}
|
||||
|
||||
function patch_try_catch(orig, toplevel) {
|
||||
var patched = Object.create(null);
|
||||
var patches = [];
|
||||
var stack = [ {
|
||||
code: orig,
|
||||
index: 0,
|
||||
@@ -2382,7 +2440,7 @@ function patch_try_catch(orig, toplevel) {
|
||||
"throw " + match[1] + ";",
|
||||
].join("\n");
|
||||
}
|
||||
var new_code = code.slice(0, index) + insert + code.slice(index) + tail_throw;
|
||||
var new_code = code.slice(0, index) + insert + code.slice(index) + tail_throw + "var UFUZZ_ERROR;";
|
||||
var result = run_code(new_code, toplevel);
|
||||
if (!sandbox.is_error(result)) {
|
||||
if (!stack.filled && match[1]) stack.push({
|
||||
@@ -2394,27 +2452,35 @@ function patch_try_catch(orig, toplevel) {
|
||||
offset += insert.length;
|
||||
code = new_code;
|
||||
} else if (is_error_in(result)) {
|
||||
index = result.ufuzz_catch;
|
||||
return orig.slice(0, index) + result.ufuzz_var + ' = new Error("invalid `in`");' + orig.slice(index);
|
||||
patch(result.ufuzz_catch, result.ufuzz_var + ' = new Error("invalid `in`");');
|
||||
} else if (is_error_tdz(result)) {
|
||||
patch(result.ufuzz_catch, result.ufuzz_var + ' = new Error("TDZ");');
|
||||
} else if (is_error_spread(result)) {
|
||||
index = result.ufuzz_catch;
|
||||
return orig.slice(0, index) + result.ufuzz_var + ' = new Error("spread not iterable");' + orig.slice(index);
|
||||
patch(result.ufuzz_catch, result.ufuzz_var + ' = new Error("spread not iterable");');
|
||||
} else if (is_error_recursion(result)) {
|
||||
index = result.ufuzz_try;
|
||||
return orig.slice(0, index) + 'throw new Error("skipping infinite recursion");' + orig.slice(index);
|
||||
patch(result.ufuzz_try, 'throw new Error("skipping infinite recursion");');
|
||||
} else if (is_error_set_property(result)) {
|
||||
patch(result.ufuzz_catch, result.ufuzz_var + ' = new Error("cannot set property");');
|
||||
} else if (is_error_destructuring(result)) {
|
||||
index = result.ufuzz_catch;
|
||||
return orig.slice(0, index) + result.ufuzz_var + ' = new Error("cannot destructure");' + orig.slice(index);
|
||||
patch(result.ufuzz_catch, result.ufuzz_var + ' = new Error("cannot destructure");');
|
||||
} else if (is_error_class_constructor(result)) {
|
||||
index = result.ufuzz_catch;
|
||||
return orig.slice(0, index) + result.ufuzz_var + ' = new Error("missing new for class");' + orig.slice(index);
|
||||
patch(result.ufuzz_catch, result.ufuzz_var + ' = new Error("missing new for class");');
|
||||
} else if (is_error_getter_only_property(result)) {
|
||||
index = result.ufuzz_catch;
|
||||
return orig.slice(0, index) + result.ufuzz_var + ' = new Error("setting getter-only property");' + orig.slice(index);
|
||||
patch(result.ufuzz_catch, result.ufuzz_var + ' = new Error("setting getter-only property");');
|
||||
}
|
||||
}
|
||||
stack.filled = true;
|
||||
}
|
||||
if (patches.length) return patches.reduce(function(code, patch) {
|
||||
var index = patch[0];
|
||||
return code.slice(0, index) + patch[1] + code.slice(index);
|
||||
}, orig);
|
||||
|
||||
function patch(index, code) {
|
||||
if (patched[index]) return;
|
||||
patched[index] = true;
|
||||
patches.unshift([ index, code ]);
|
||||
}
|
||||
}
|
||||
|
||||
var beautify_options = {
|
||||
@@ -2426,22 +2492,26 @@ var beautify_options = {
|
||||
},
|
||||
};
|
||||
var minify_options = require("./options.json");
|
||||
if (typeof sandbox.run_code("A:if (0) B:; else B:;") != "string") {
|
||||
if (sandbox.is_error(sandbox.run_code("A:if (0) B:; else B:;"))) {
|
||||
minify_options.forEach(function(o) {
|
||||
if (!("mangle" in o)) o.mangle = {};
|
||||
if (o.mangle) o.mangle.v8 = true;
|
||||
});
|
||||
}
|
||||
var bug_async_arrow_rest = function() {};
|
||||
if (SUPPORT.arrow && SUPPORT.async && SUPPORT.rest && typeof sandbox.run_code("async (a = f(...[], b)) => 0;") != "string") {
|
||||
if (SUPPORT.arrow && SUPPORT.async && SUPPORT.rest && sandbox.is_error(sandbox.run_code("async (a = f(...[], b)) => 0;"))) {
|
||||
bug_async_arrow_rest = function(ex) {
|
||||
return ex.name == "SyntaxError" && ex.message == "Rest parameter must be last formal parameter";
|
||||
};
|
||||
}
|
||||
var bug_async_class_await = SUPPORT.async && SUPPORT.class_field && typeof sandbox.run_code("var await; async function f() { class A { static p = await; } }") != "string";
|
||||
var bug_for_of_async = SUPPORT.for_await_of && typeof sandbox.run_code("var async; for (async of []);") != "string";
|
||||
var bug_for_of_var = SUPPORT.for_of && SUPPORT.let && typeof sandbox.run_code("try {} catch (e) { for (var e of []); }") != "string";
|
||||
if (SUPPORT.destructuring && typeof sandbox.run_code("console.log([ 1 ], {} = 2);") != "string") {
|
||||
var bug_class_static_await = SUPPORT.async && SUPPORT.class_field && sandbox.is_error(sandbox.run_code("var await; class A { static p = await; }"));
|
||||
var bug_class_static_nontrivial = SUPPORT.class_field && sandbox.is_error(sandbox.run_code("class A { static 42; static get 42() {} }"));
|
||||
var bug_for_of_async = SUPPORT.for_await_of && sandbox.is_error(sandbox.run_code("var async; for (async of []);"));
|
||||
var bug_for_of_var = SUPPORT.for_of && SUPPORT.let && sandbox.is_error(sandbox.run_code("try {} catch (e) { for (var e of []); }"));
|
||||
var bug_proto_stream = function(ex) {
|
||||
return ex.name == "TypeError" && ex.message == "callback is not a function";
|
||||
}
|
||||
if (SUPPORT.destructuring && sandbox.is_error(sandbox.run_code("console.log([ 1 ], {} = 2);"))) {
|
||||
beautify_options.output.v8 = true;
|
||||
minify_options.forEach(function(o) {
|
||||
if (!("output" in o)) o.output = {};
|
||||
@@ -2450,7 +2520,7 @@ if (SUPPORT.destructuring && typeof sandbox.run_code("console.log([ 1 ], {} = 2)
|
||||
}
|
||||
beautify_options = JSON.stringify(beautify_options);
|
||||
minify_options = minify_options.map(JSON.stringify);
|
||||
var original_code, original_result, errored;
|
||||
var original_code, original_result, original_erred;
|
||||
var uglify_code, uglify_result, ok;
|
||||
for (var round = 1; round <= num_iterations; round++) {
|
||||
process.stdout.write(round + " of " + num_iterations + "\r");
|
||||
@@ -2458,7 +2528,7 @@ for (var round = 1; round <= num_iterations; round++) {
|
||||
original_code = createTopLevelCode();
|
||||
var orig_result = [ run_code(original_code), run_code(original_code, true) ];
|
||||
if (orig_result.some(function(result, toplevel) {
|
||||
if (typeof result == "string") return;
|
||||
if (!sandbox.is_error(result)) return;
|
||||
println();
|
||||
println();
|
||||
println("//=============================================================");
|
||||
@@ -2471,44 +2541,61 @@ for (var round = 1; round <= num_iterations; round++) {
|
||||
println();
|
||||
// ignore v8 parser bug
|
||||
return bug_async_arrow_rest(result)
|
||||
// ignore Node.js `__proto__` quirks
|
||||
|| bug_proto_stream(result)
|
||||
// ignore runtime platform bugs
|
||||
|| result.message == "Script execution aborted.";
|
||||
})) continue;
|
||||
minify_options.forEach(function(options) {
|
||||
var o = JSON.parse(options);
|
||||
if (async && has_await) {
|
||||
o.module = true;
|
||||
options = JSON.stringify(o);
|
||||
}
|
||||
var toplevel = sandbox.has_toplevel(o);
|
||||
o.validate = true;
|
||||
uglify_code = UglifyJS.minify(original_code, o);
|
||||
original_result = orig_result[toplevel ? 1 : 0];
|
||||
errored = typeof original_result != "string";
|
||||
original_erred = sandbox.is_error(original_result);
|
||||
if (!uglify_code.error) {
|
||||
uglify_code = uglify_code.code;
|
||||
uglify_result = run_code(uglify_code, toplevel);
|
||||
ok = sandbox.same_stdout(original_result, uglify_result);
|
||||
var uglify_erred = sandbox.is_error(uglify_result);
|
||||
// ignore v8 parser bug
|
||||
if (!ok && bug_async_arrow_rest(uglify_result)) ok = true;
|
||||
if (!ok && uglify_erred && bug_async_arrow_rest(uglify_result)) ok = true;
|
||||
// ignore Node.js `__proto__` quirks
|
||||
if (!ok && uglify_erred && bug_proto_stream(uglify_result)) ok = true;
|
||||
// ignore runtime platform bugs
|
||||
if (!ok && uglify_result.message == "Script execution aborted.") ok = true;
|
||||
if (!ok && uglify_erred && uglify_result.message == "Script execution aborted.") ok = true;
|
||||
// handle difference caused by time-outs
|
||||
if (!ok && errored && is_error_timeout(original_result)) {
|
||||
if (is_error_timeout(uglify_result)) {
|
||||
// ignore difference in error message
|
||||
ok = true;
|
||||
} else {
|
||||
if (!ok) {
|
||||
if (original_erred && is_error_timeout(original_result)) {
|
||||
if (uglify_erred && is_error_timeout(uglify_result)) {
|
||||
// ignore difference in error message
|
||||
ok = true;
|
||||
} else {
|
||||
// ignore spurious time-outs
|
||||
if (!orig_result[toplevel ? 3 : 2]) orig_result[toplevel ? 3 : 2] = run_code(original_code, toplevel, 10000);
|
||||
ok = sandbox.same_stdout(orig_result[toplevel ? 3 : 2], uglify_result);
|
||||
}
|
||||
} else if (uglify_erred && is_error_timeout(uglify_result)) {
|
||||
// ignore spurious time-outs
|
||||
if (!orig_result[toplevel ? 3 : 2]) orig_result[toplevel ? 3 : 2] = run_code(original_code, toplevel, 10000);
|
||||
ok = sandbox.same_stdout(orig_result[toplevel ? 3 : 2], uglify_result);
|
||||
var waited_result = run_code(uglify_code, toplevel, 10000);
|
||||
ok = sandbox.same_stdout(original_result, waited_result);
|
||||
}
|
||||
}
|
||||
// ignore declaration order of global variables
|
||||
if (!ok && !toplevel && uglify_result.name != "SyntaxError" && original_result.name != "SyntaxError") {
|
||||
ok = sandbox.same_stdout(run_code(sort_globals(original_code)), run_code(sort_globals(uglify_code)));
|
||||
if (!ok && !toplevel) {
|
||||
if (!(original_erred && original_result.name == "SyntaxError") && !(uglify_erred && uglify_result.name == "SyntaxError")) {
|
||||
ok = sandbox.same_stdout(run_code(sort_globals(original_code)), run_code(sort_globals(uglify_code)));
|
||||
}
|
||||
}
|
||||
// ignore numerical imprecision caused by `unsafe_math`
|
||||
if (!ok && o.compress && o.compress.unsafe_math && typeof original_result == typeof uglify_result) {
|
||||
if (typeof original_result == "string") {
|
||||
if (!ok && o.compress && o.compress.unsafe_math) {
|
||||
if (typeof original_result == "string" && typeof uglify_result == "string") {
|
||||
ok = fuzzy_match(original_result, uglify_result);
|
||||
} else if (sandbox.is_error(original_result)) {
|
||||
} else if (original_erred && uglify_erred) {
|
||||
ok = original_result.name == uglify_result.name && fuzzy_match(original_result.message, uglify_result.message);
|
||||
}
|
||||
if (!ok) {
|
||||
@@ -2516,46 +2603,33 @@ for (var round = 1; round <= num_iterations; round++) {
|
||||
ok = sandbox.same_stdout(fuzzy_result, uglify_result);
|
||||
}
|
||||
}
|
||||
// ignore difference in error message caused by Temporal Dead Zone
|
||||
if (!ok && errored && uglify_result.name == "ReferenceError" && original_result.name == "ReferenceError") ok = true;
|
||||
// ignore difference due to implicit strict-mode in `class`
|
||||
if (!ok && /\bclass\b/.test(original_code)) {
|
||||
var original_strict = run_code('"use strict";\n' + original_code, toplevel);
|
||||
if (/^(Syntax|Type)Error$/.test(uglify_result.name)) {
|
||||
ok = typeof original_strict != "string";
|
||||
} else {
|
||||
ok = sandbox.same_stdout(original_strict, uglify_result);
|
||||
}
|
||||
}
|
||||
// ignore difference in error message caused by `import` symbol redeclaration
|
||||
if (!ok && errored && /\bimport\b/.test(original_code)) {
|
||||
if (is_error_redeclaration(uglify_result) && is_error_redeclaration(original_result)) ok = true;
|
||||
}
|
||||
if (!ok && original_erred && uglify_erred && (
|
||||
// ignore difference in error message caused by `in`
|
||||
is_error_in(original_result) && is_error_in(uglify_result)
|
||||
// ignore difference in error message caused by Temporal Dead Zone
|
||||
|| is_error_tdz(original_result) && is_error_tdz(uglify_result)
|
||||
// ignore difference in error message caused by spread syntax
|
||||
|| is_error_spread(original_result) && is_error_spread(uglify_result)
|
||||
// ignore difference in error message caused by destructuring assignment
|
||||
|| is_error_set_property(original_result) && is_error_set_property(uglify_result)
|
||||
// ignore difference in error message caused by `import` symbol redeclaration
|
||||
|| /\bimport\b/.test(original_code) && is_error_redeclaration(original_result) && is_error_redeclaration(uglify_result)
|
||||
// ignore difference in error message caused by destructuring
|
||||
|| is_error_destructuring(original_result) && is_error_destructuring(uglify_result)
|
||||
// ignore difference in error message caused by call on class
|
||||
|| is_error_class_constructor(original_result) && is_error_class_constructor(uglify_result)
|
||||
// ignore difference in error message caused by setting getter-only property
|
||||
|| is_error_getter_only_property(original_result) && is_error_getter_only_property(uglify_result)
|
||||
)) ok = true;
|
||||
// ignore difference due to `__proto__` assignment
|
||||
if (!ok && /\b__proto__\b/.test(original_code)) {
|
||||
var original_proto = run_code("(" + patch_proto + ")();\n" + original_code, toplevel);
|
||||
var uglify_proto = run_code("(" + patch_proto + ")();\n" + uglify_code, toplevel);
|
||||
ok = sandbox.same_stdout(original_proto, uglify_proto);
|
||||
}
|
||||
// ignore difference in error message caused by `in`
|
||||
if (!ok && errored && is_error_in(uglify_result) && is_error_in(original_result)) ok = true;
|
||||
// ignore difference in error message caused by spread syntax
|
||||
if (!ok && errored && is_error_spread(uglify_result) && is_error_spread(original_result)) ok = true;
|
||||
// ignore difference in depth of termination caused by infinite recursion
|
||||
if (!ok && errored && is_error_recursion(original_result)) {
|
||||
if (is_error_recursion(uglify_result) || typeof uglify_result == "string") ok = true;
|
||||
}
|
||||
// ignore difference in error message caused by destructuring
|
||||
if (!ok && errored && is_error_destructuring(uglify_result) && is_error_destructuring(original_result)) {
|
||||
ok = true;
|
||||
}
|
||||
// ignore difference in error message caused by call on class
|
||||
if (!ok && errored && is_error_class_constructor(uglify_result) && is_error_class_constructor(original_result)) {
|
||||
ok = true;
|
||||
}
|
||||
// ignore difference in error message caused by setting getter-only property
|
||||
if (!ok && errored && is_error_getter_only_property(uglify_result) && is_error_getter_only_property(original_result)) {
|
||||
ok = true;
|
||||
if (!ok && original_erred && is_error_recursion(original_result)) {
|
||||
if (!uglify_erred || is_error_recursion(uglify_result)) ok = true;
|
||||
}
|
||||
// ignore errors above when caught by try-catch
|
||||
if (!ok) {
|
||||
@@ -2567,7 +2641,7 @@ for (var round = 1; round <= num_iterations; round++) {
|
||||
}
|
||||
} else {
|
||||
uglify_code = uglify_code.error;
|
||||
ok = errored && uglify_code.name == original_result.name;
|
||||
ok = original_erred && uglify_code.name == original_result.name;
|
||||
}
|
||||
if (verbose || (verbose_interval && !(round % INTERVAL_COUNT)) || !ok) log(options);
|
||||
if (!ok && isFinite(num_iterations)) {
|
||||
|
||||
Reference in New Issue
Block a user