Compare commits
80 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
5beb7e4797 | ||
|
|
46caaa82ba | ||
|
|
5d258259a4 | ||
|
|
14c35739dd | ||
|
|
f5ceff6e4b | ||
|
|
4d6771b9b1 | ||
|
|
d17191111a | ||
|
|
0ff607cb80 | ||
|
|
1988495d71 | ||
|
|
fdc10086da | ||
|
|
746f5f6c62 | ||
|
|
d83d3d741a | ||
|
|
99ac73a635 | ||
|
|
a2e4c2fd97 | ||
|
|
94785e8e14 | ||
|
|
4dbdac9c31 | ||
|
|
78c8efd851 | ||
|
|
af310ba2d0 | ||
|
|
2f3930d1b9 | ||
|
|
d1a78920d9 | ||
|
|
d9cd3d33c8 | ||
|
|
22b47cdd63 | ||
|
|
4cf612dc9f | ||
|
|
a19d31dd33 | ||
|
|
01d6e0f223 | ||
|
|
ab050e7a94 | ||
|
|
75aa6ef848 | ||
|
|
519a00bd8a | ||
|
|
3ff0feddee | ||
|
|
74396acc86 | ||
|
|
036bca980c | ||
|
|
18c2b1841b | ||
|
|
fe19ab7c57 | ||
|
|
9074f05129 | ||
|
|
04fbb1f949 | ||
|
|
bf7e4ca1a3 | ||
|
|
d68ddc31f9 | ||
|
|
500e31e03b | ||
|
|
bef856addb | ||
|
|
9a6faf365b | ||
|
|
e915832a36 | ||
|
|
0593892d6e | ||
|
|
b866a23671 | ||
|
|
1283d73853 | ||
|
|
1b61a81b5d | ||
|
|
5a88c30d65 | ||
|
|
168ae747ad | ||
|
|
d4b7010678 | ||
|
|
e27493f3c2 | ||
|
|
292d1de363 | ||
|
|
6768e6578f | ||
|
|
48a0f6fe41 | ||
|
|
81caadb709 | ||
|
|
d959e0b86f | ||
|
|
67278e76c8 | ||
|
|
c289ba1139 | ||
|
|
02cc4a0d03 | ||
|
|
4e06e1ca34 | ||
|
|
644f65feca | ||
|
|
8504a4ea0e | ||
|
|
10c1a78772 | ||
|
|
a6a0319f1c | ||
|
|
d1b2ecec27 | ||
|
|
552be61c4d | ||
|
|
dcfc4aca5b | ||
|
|
4027f87717 | ||
|
|
910799ca99 | ||
|
|
4bd36dc8da | ||
|
|
ab15c40770 | ||
|
|
fe65ce9658 | ||
|
|
d6fd18d0b0 | ||
|
|
0d17c5b0fa | ||
|
|
5b20bad4b3 | ||
|
|
765a06340f | ||
|
|
5045e140b1 | ||
|
|
10648c9af6 | ||
|
|
87e67ec299 | ||
|
|
61a0dad9fe | ||
|
|
3e2c51a4da | ||
|
|
0e29ad5eb9 |
16
.github/workflows/ci.yml
vendored
16
.github/workflows/ci.yml
vendored
@@ -14,13 +14,17 @@ jobs:
|
|||||||
TYPE: ${{ matrix.script }}
|
TYPE: ${{ matrix.script }}
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v1
|
- uses: actions/checkout@v1
|
||||||
- shell: bash
|
- uses: actions/cache@v1
|
||||||
|
with:
|
||||||
|
path: tmp
|
||||||
|
key: tmp ${{ matrix.script }}
|
||||||
|
- name: Perform tests
|
||||||
|
shell: bash
|
||||||
run: |
|
run: |
|
||||||
git clone --branch v1.5.2 --depth 1 https://github.com/jasongin/nvs.git ~/.nvs
|
git clone --branch v1.5.3 --depth 1 https://github.com/jasongin/nvs.git ~/.nvs
|
||||||
. ~/.nvs/nvs.sh
|
. ~/.nvs/nvs.sh --version
|
||||||
nvs --version
|
nvs add $NODE
|
||||||
nvs add node/$NODE
|
nvs use $NODE
|
||||||
nvs use node/$NODE
|
|
||||||
node --version
|
node --version
|
||||||
npm --version --no-update-notifier
|
npm --version --no-update-notifier
|
||||||
npm install --no-audit --no-optional --no-save --no-update-notifier
|
npm install --no-audit --no-optional --no-save --no-update-notifier
|
||||||
|
|||||||
12
.github/workflows/ufuzz.yml
vendored
12
.github/workflows/ufuzz.yml
vendored
@@ -12,13 +12,13 @@ jobs:
|
|||||||
runs-on: ${{ matrix.os }}
|
runs-on: ${{ matrix.os }}
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v1
|
- uses: actions/checkout@v1
|
||||||
- shell: bash
|
- name: Perform fuzzing
|
||||||
|
shell: bash
|
||||||
run: |
|
run: |
|
||||||
git clone --branch v1.5.2 --depth 1 https://github.com/jasongin/nvs.git ~/.nvs
|
git clone --branch v1.5.3 --depth 1 https://github.com/jasongin/nvs.git ~/.nvs
|
||||||
. ~/.nvs/nvs.sh
|
. ~/.nvs/nvs.sh --version
|
||||||
nvs --version
|
nvs add 10
|
||||||
nvs add node
|
nvs use 10
|
||||||
nvs use node
|
|
||||||
node --version
|
node --version
|
||||||
npm --version --no-update-notifier
|
npm --version --no-update-notifier
|
||||||
npm install --no-audit --no-optional --no-save --no-update-notifier
|
npm install --no-audit --no-optional --no-save --no-update-notifier
|
||||||
|
|||||||
46
.travis.yml
46
.travis.yml
@@ -1,46 +0,0 @@
|
|||||||
cache:
|
|
||||||
directories: tmp
|
|
||||||
language: shell
|
|
||||||
matrix:
|
|
||||||
fast_finish: true
|
|
||||||
env:
|
|
||||||
- NODE=0.10 TYPE=compress
|
|
||||||
- NODE=0.10 TYPE=mocha
|
|
||||||
- NODE=0.10 TYPE=release/benchmark
|
|
||||||
- NODE=0.10 TYPE=release/jetstream
|
|
||||||
- NODE=0.12 TYPE=compress
|
|
||||||
- NODE=0.12 TYPE=mocha
|
|
||||||
- NODE=0.12 TYPE=release/benchmark
|
|
||||||
- NODE=0.12 TYPE=release/jetstream
|
|
||||||
- NODE=4 TYPE=compress
|
|
||||||
- NODE=4 TYPE=mocha
|
|
||||||
- NODE=4 TYPE=release/benchmark
|
|
||||||
- NODE=4 TYPE=release/jetstream
|
|
||||||
- NODE=6 TYPE=compress
|
|
||||||
- NODE=6 TYPE=mocha
|
|
||||||
- NODE=6 TYPE=release/benchmark
|
|
||||||
- NODE=6 TYPE=release/jetstream
|
|
||||||
- NODE=8 TYPE=compress
|
|
||||||
- NODE=8 TYPE=mocha
|
|
||||||
- NODE=8 TYPE=release/benchmark
|
|
||||||
- NODE=8 TYPE=release/jetstream
|
|
||||||
- NODE=10 TYPE=compress
|
|
||||||
- NODE=10 TYPE=mocha
|
|
||||||
- NODE=10 TYPE=release/benchmark
|
|
||||||
- NODE=10 TYPE=release/jetstream
|
|
||||||
- NODE=latest TYPE=compress
|
|
||||||
- NODE=latest TYPE=mocha
|
|
||||||
- NODE=latest TYPE=release/benchmark
|
|
||||||
- NODE=latest TYPE=release/jetstream
|
|
||||||
before_install:
|
|
||||||
- git clone --branch v1.5.2 --depth 1 https://github.com/jasongin/nvs.git ~/.nvs
|
|
||||||
- . ~/.nvs/nvs.sh
|
|
||||||
- nvs --version
|
|
||||||
install:
|
|
||||||
- nvs add node/$NODE
|
|
||||||
- nvs use node/$NODE
|
|
||||||
- node --version
|
|
||||||
- npm --version --no-update-notifier
|
|
||||||
- npm install --no-audit --no-optional --no-save --no-update-notifier
|
|
||||||
script:
|
|
||||||
- node test/$TYPE
|
|
||||||
@@ -87,6 +87,7 @@ a double dash to prevent input files being used as option arguments:
|
|||||||
`wrap_iife` Wrap IIFEs in parenthesis. Note: you may
|
`wrap_iife` Wrap IIFEs in parenthesis. Note: you may
|
||||||
want to disable `negate_iife` under
|
want to disable `negate_iife` under
|
||||||
compressor options.
|
compressor options.
|
||||||
|
-O, --output-opts [options] Specify output options (`beautify` disabled by default).
|
||||||
-o, --output <file> Output file path (default STDOUT). Specify `ast` or
|
-o, --output <file> Output file path (default STDOUT). Specify `ast` or
|
||||||
`spidermonkey` to write UglifyJS or SpiderMonkey AST
|
`spidermonkey` to write UglifyJS or SpiderMonkey AST
|
||||||
as JSON to STDOUT respectively.
|
as JSON to STDOUT respectively.
|
||||||
@@ -631,7 +632,10 @@ If you're using the `X-SourceMap` header instead, you can just omit `sourceMap.u
|
|||||||
|
|
||||||
- `drop_debugger` (default: `true`) -- remove `debugger;` statements
|
- `drop_debugger` (default: `true`) -- remove `debugger;` statements
|
||||||
|
|
||||||
- `evaluate` (default: `true`) -- attempt to evaluate constant expressions
|
- `evaluate` (default: `true`) -- Evaluate expression for shorter constant
|
||||||
|
representation. Pass `"eager"` to always replace function calls whenever
|
||||||
|
possible, or a positive integer to specify an upper bound for each individual
|
||||||
|
evaluation in number of characters.
|
||||||
|
|
||||||
- `expression` (default: `false`) -- Pass `true` to preserve completion values
|
- `expression` (default: `false`) -- Pass `true` to preserve completion values
|
||||||
from terminal statements without `return`, e.g. in bookmarklets.
|
from terminal statements without `return`, e.g. in bookmarklets.
|
||||||
|
|||||||
71
appveyor.yml
71
appveyor.yml
@@ -1,74 +1,5 @@
|
|||||||
build: off
|
build: off
|
||||||
cache:
|
|
||||||
- tmp
|
|
||||||
matrix:
|
matrix:
|
||||||
fast_finish: true
|
fast_finish: true
|
||||||
environment:
|
|
||||||
matrix:
|
|
||||||
- NODE: 0.10
|
|
||||||
TYPE: compress
|
|
||||||
- NODE: 0.10
|
|
||||||
TYPE: mocha
|
|
||||||
- NODE: 0.10
|
|
||||||
TYPE: release/benchmark
|
|
||||||
- NODE: 0.10
|
|
||||||
TYPE: release/jetstream
|
|
||||||
- NODE: 0.12
|
|
||||||
TYPE: compress
|
|
||||||
- NODE: 0.12
|
|
||||||
TYPE: mocha
|
|
||||||
- NODE: 0.12
|
|
||||||
TYPE: release/benchmark
|
|
||||||
- NODE: 0.12
|
|
||||||
TYPE: release/jetstream
|
|
||||||
- NODE: 4
|
|
||||||
TYPE: compress
|
|
||||||
- NODE: 4
|
|
||||||
TYPE: mocha
|
|
||||||
- NODE: 4
|
|
||||||
TYPE: release/benchmark
|
|
||||||
- NODE: 4
|
|
||||||
TYPE: release/jetstream
|
|
||||||
- NODE: 6
|
|
||||||
TYPE: compress
|
|
||||||
- NODE: 6
|
|
||||||
TYPE: mocha
|
|
||||||
- NODE: 6
|
|
||||||
TYPE: release/benchmark
|
|
||||||
- NODE: 6
|
|
||||||
TYPE: release/jetstream
|
|
||||||
- NODE: 8
|
|
||||||
TYPE: compress
|
|
||||||
- NODE: 8
|
|
||||||
TYPE: mocha
|
|
||||||
- NODE: 8
|
|
||||||
TYPE: release/benchmark
|
|
||||||
- NODE: 8
|
|
||||||
TYPE: release/jetstream
|
|
||||||
- NODE: 10
|
|
||||||
TYPE: compress
|
|
||||||
- NODE: 10
|
|
||||||
TYPE: mocha
|
|
||||||
- NODE: 10
|
|
||||||
TYPE: release/benchmark
|
|
||||||
- NODE: 10
|
|
||||||
TYPE: release/jetstream
|
|
||||||
- NODE: latest
|
|
||||||
TYPE: compress
|
|
||||||
- NODE: latest
|
|
||||||
TYPE: mocha
|
|
||||||
- NODE: latest
|
|
||||||
TYPE: release/benchmark
|
|
||||||
- NODE: latest
|
|
||||||
TYPE: release/jetstream
|
|
||||||
install:
|
|
||||||
- git clone --branch v1.5.2 --depth 1 https://github.com/jasongin/nvs.git %LOCALAPPDATA%\nvs
|
|
||||||
- set PATH=%LOCALAPPDATA%\nvs;%PATH%
|
|
||||||
- nvs --version
|
|
||||||
- nvs add node/%NODE%
|
|
||||||
- nvs use node/%NODE%
|
|
||||||
- node --version
|
|
||||||
- npm --version --no-update-notifier
|
|
||||||
- npm install --no-audit --no-optional --no-save --no-update-notifier
|
|
||||||
test_script:
|
test_script:
|
||||||
- node test/%TYPE%
|
- echo No longer in use
|
||||||
|
|||||||
@@ -36,6 +36,7 @@ program.option("-c, --compress [options]", "Enable compressor/specify compressor
|
|||||||
program.option("-m, --mangle [options]", "Mangle names/specify mangler options.", parse_js());
|
program.option("-m, --mangle [options]", "Mangle names/specify mangler options.", parse_js());
|
||||||
program.option("--mangle-props [options]", "Mangle properties/specify mangler options.", parse_js());
|
program.option("--mangle-props [options]", "Mangle properties/specify mangler options.", parse_js());
|
||||||
program.option("-b, --beautify [options]", "Beautify output/specify output options.", parse_js());
|
program.option("-b, --beautify [options]", "Beautify output/specify output options.", parse_js());
|
||||||
|
program.option("-O, --output-opts [options]", "Output options (beautify disabled).", parse_js());
|
||||||
program.option("-o, --output <file>", "Output file (default STDOUT).");
|
program.option("-o, --output <file>", "Output file (default STDOUT).");
|
||||||
program.option("--comments [filter]", "Preserve copyright comments in the output.");
|
program.option("--comments [filter]", "Preserve copyright comments in the output.");
|
||||||
program.option("--config-file <file>", "Read minify() options from JSON file.");
|
program.option("--config-file <file>", "Read minify() options from JSON file.");
|
||||||
@@ -59,7 +60,7 @@ if (program.configFile) {
|
|||||||
if (options.mangle && options.mangle.properties && options.mangle.properties.regex) {
|
if (options.mangle && options.mangle.properties && options.mangle.properties.regex) {
|
||||||
options.mangle.properties.regex = UglifyJS.parse(options.mangle.properties.regex, {
|
options.mangle.properties.regex = UglifyJS.parse(options.mangle.properties.regex, {
|
||||||
expression: true
|
expression: true
|
||||||
}).getValue();
|
}).value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!program.output && program.sourceMap && program.sourceMap.url != "inline") {
|
if (!program.output && program.sourceMap && program.sourceMap.url != "inline") {
|
||||||
@@ -93,6 +94,10 @@ if (program.beautify) {
|
|||||||
options.output.beautify = true;
|
options.output.beautify = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (program.outputOpts) {
|
||||||
|
if (program.beautify) fatal("--beautify cannot be used with --output-opts");
|
||||||
|
options.output = typeof program.outputOpts == "object" ? program.outputOpts : {};
|
||||||
|
}
|
||||||
if (program.comments) {
|
if (program.comments) {
|
||||||
if (typeof options.output != "object") options.output = {};
|
if (typeof options.output != "object") options.output = {};
|
||||||
options.output.comments = typeof program.comments == "string" ? program.comments : "some";
|
options.output.comments = typeof program.comments == "string" ? program.comments : "some";
|
||||||
@@ -370,7 +375,7 @@ function parse_js(flag) {
|
|||||||
if (!(node instanceof UglifyJS.AST_Sequence)) throw node;
|
if (!(node instanceof UglifyJS.AST_Sequence)) throw node;
|
||||||
|
|
||||||
function to_string(value) {
|
function to_string(value) {
|
||||||
return value instanceof UglifyJS.AST_Constant ? value.getValue() : value.print_to_string({
|
return value instanceof UglifyJS.AST_Constant ? value.value : value.print_to_string({
|
||||||
quote_keys: true
|
quote_keys: true
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
11
lib/ast.js
11
lib/ast.js
@@ -618,7 +618,7 @@ var AST_PropAccess = DEFNODE("PropAccess", "expression property", {
|
|||||||
getProperty: function() {
|
getProperty: function() {
|
||||||
var p = this.property;
|
var p = this.property;
|
||||||
if (p instanceof AST_Constant) {
|
if (p instanceof AST_Constant) {
|
||||||
return p.getValue();
|
return p.value;
|
||||||
}
|
}
|
||||||
if (p instanceof AST_UnaryPrefix
|
if (p instanceof AST_UnaryPrefix
|
||||||
&& p.operator == "void"
|
&& p.operator == "void"
|
||||||
@@ -824,9 +824,6 @@ var AST_This = DEFNODE("This", null, {
|
|||||||
|
|
||||||
var AST_Constant = DEFNODE("Constant", null, {
|
var AST_Constant = DEFNODE("Constant", null, {
|
||||||
$documentation: "Base class for all constants",
|
$documentation: "Base class for all constants",
|
||||||
getValue: function() {
|
|
||||||
return this.value;
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
var AST_String = DEFNODE("String", "value quote", {
|
var AST_String = DEFNODE("String", "value quote", {
|
||||||
@@ -967,11 +964,13 @@ TreeWalker.prototype = {
|
|||||||
in_boolean_context: function() {
|
in_boolean_context: function() {
|
||||||
var self = this.self();
|
var self = this.self();
|
||||||
for (var i = 0, p; p = this.parent(i); i++) {
|
for (var i = 0, p; p = this.parent(i); i++) {
|
||||||
if (p instanceof AST_SimpleStatement
|
if (p instanceof AST_Conditional && p.condition === self
|
||||||
|| p instanceof AST_Conditional && p.condition === self
|
|
||||||
|| p instanceof AST_DWLoop && p.condition === self
|
|| p instanceof AST_DWLoop && p.condition === self
|
||||||
|| p instanceof AST_For && p.condition === self
|
|| p instanceof AST_For && p.condition === self
|
||||||
|| p instanceof AST_If && 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) {
|
|| p instanceof AST_UnaryPrefix && p.operator == "!" && p.expression === self) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|||||||
1247
lib/compress.js
1247
lib/compress.js
File diff suppressed because it is too large
Load Diff
@@ -252,7 +252,7 @@ function minify(files, options) {
|
|||||||
properties: 1e-3 * (timings.output - timings.properties),
|
properties: 1e-3 * (timings.output - timings.properties),
|
||||||
output: 1e-3 * (timings.end - timings.output),
|
output: 1e-3 * (timings.end - timings.output),
|
||||||
total: 1e-3 * (timings.end - timings.start)
|
total: 1e-3 * (timings.end - timings.start)
|
||||||
}
|
};
|
||||||
}
|
}
|
||||||
if (warnings.length) {
|
if (warnings.length) {
|
||||||
result.warnings = warnings;
|
result.warnings = warnings;
|
||||||
|
|||||||
163
lib/output.js
163
lib/output.js
@@ -43,8 +43,6 @@
|
|||||||
|
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
var EXPECT_DIRECTIVE = /^$|[;{][\s\n]*$/;
|
|
||||||
|
|
||||||
function is_some_comments(comment) {
|
function is_some_comments(comment) {
|
||||||
// multiline comment
|
// multiline comment
|
||||||
return comment.type == "comment2" && /@preserve|@license|@cc_on/i.test(comment.value);
|
return comment.type == "comment2" && /@preserve|@license|@cc_on/i.test(comment.value);
|
||||||
@@ -121,15 +119,20 @@ function OutputStream(options) {
|
|||||||
});
|
});
|
||||||
} : function(str) {
|
} : function(str) {
|
||||||
var s = "";
|
var s = "";
|
||||||
for (var i = 0; i < str.length; i++) {
|
for (var i = 0, j = 0; i < str.length; i++) {
|
||||||
if (is_surrogate_pair_head(str[i]) && !is_surrogate_pair_tail(str[i + 1])
|
var code = str.charCodeAt(i);
|
||||||
|| is_surrogate_pair_tail(str[i]) && !is_surrogate_pair_head(str[i - 1])) {
|
if (is_surrogate_pair_head(code)) {
|
||||||
s += "\\u" + str.charCodeAt(i).toString(16);
|
if (is_surrogate_pair_tail(str.charCodeAt(i + 1))) {
|
||||||
} else {
|
i++;
|
||||||
s += str[i];
|
continue;
|
||||||
}
|
}
|
||||||
|
} else if (!is_surrogate_pair_tail(code)) {
|
||||||
|
continue;
|
||||||
}
|
}
|
||||||
return s;
|
s += str.slice(j, i) + "\\u" + code.toString(16);
|
||||||
|
j = i + 1;
|
||||||
|
}
|
||||||
|
return j == 0 ? str : s + str.slice(j);
|
||||||
};
|
};
|
||||||
|
|
||||||
function make_string(str, quote) {
|
function make_string(str, quote) {
|
||||||
@@ -269,7 +272,7 @@ function OutputStream(options) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
newline_insert = -1;
|
newline_insert = -1;
|
||||||
var prev = last.charAt(last.length - 1);
|
var prev = last.slice(-1);
|
||||||
if (might_need_semicolon) {
|
if (might_need_semicolon) {
|
||||||
might_need_semicolon = false;
|
might_need_semicolon = false;
|
||||||
|
|
||||||
@@ -298,16 +301,16 @@ function OutputStream(options) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (might_need_space) {
|
if (might_need_space) {
|
||||||
if ((is_identifier_char(prev)
|
if (is_identifier_char(prev) && (is_identifier_char(ch) || ch == "\\")
|
||||||
&& (is_identifier_char(ch) || ch == "\\"))
|
|
||||||
|| (ch == "/" && ch == prev)
|
|| (ch == "/" && ch == prev)
|
||||||
|| ((ch == "+" || ch == "-") && ch == last))
|
|| ((ch == "+" || ch == "-") && ch == last)
|
||||||
{
|
|| str == "--" && last == "!"
|
||||||
|
|| last == "--" && ch == ">") {
|
||||||
OUTPUT += " ";
|
OUTPUT += " ";
|
||||||
current_col++;
|
current_col++;
|
||||||
current_pos++;
|
current_pos++;
|
||||||
}
|
}
|
||||||
might_need_space = false;
|
if (prev != "<" || str != "!") might_need_space = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mapping_token) {
|
if (mapping_token) {
|
||||||
@@ -322,7 +325,7 @@ function OutputStream(options) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
OUTPUT += str;
|
OUTPUT += str;
|
||||||
has_parens = str[str.length - 1] == "(";
|
has_parens = str.slice(-1) == "(";
|
||||||
current_pos += str.length;
|
current_pos += str.length;
|
||||||
var a = str.split(/\r?\n/), n = a.length - 1;
|
var a = str.split(/\r?\n/), n = a.length - 1;
|
||||||
current_line += n;
|
current_line += n;
|
||||||
@@ -378,7 +381,7 @@ function OutputStream(options) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
function force_semicolon() {
|
function force_semicolon() {
|
||||||
might_need_semicolon = false;
|
if (might_need_semicolon) print(";");
|
||||||
print(";");
|
print(";");
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -585,17 +588,7 @@ function OutputStream(options) {
|
|||||||
force_semicolon : force_semicolon,
|
force_semicolon : force_semicolon,
|
||||||
to_utf8 : to_utf8,
|
to_utf8 : to_utf8,
|
||||||
print_name : function(name) { print(make_name(name)) },
|
print_name : function(name) { print(make_name(name)) },
|
||||||
print_string : function(str, quote, escape_directive) {
|
print_string : function(str, quote) { print(encode_string(str, quote)) },
|
||||||
var encoded = encode_string(str, quote);
|
|
||||||
if (escape_directive === true && encoded.indexOf("\\") === -1) {
|
|
||||||
// Insert semicolons to break directive prologue
|
|
||||||
if (!EXPECT_DIRECTIVE.test(OUTPUT)) {
|
|
||||||
force_semicolon();
|
|
||||||
}
|
|
||||||
force_semicolon();
|
|
||||||
}
|
|
||||||
print(encoded);
|
|
||||||
},
|
|
||||||
next_indent : next_indent,
|
next_indent : next_indent,
|
||||||
with_indent : with_indent,
|
with_indent : with_indent,
|
||||||
with_block : with_block,
|
with_block : with_block,
|
||||||
@@ -633,17 +626,10 @@ function OutputStream(options) {
|
|||||||
nodetype.DEFMETHOD("_codegen", generator);
|
nodetype.DEFMETHOD("_codegen", generator);
|
||||||
}
|
}
|
||||||
|
|
||||||
var in_directive = false;
|
var use_asm = false;
|
||||||
var active_scope = null;
|
|
||||||
var use_asm = null;
|
|
||||||
|
|
||||||
AST_Node.DEFMETHOD("print", function(stream, force_parens) {
|
AST_Node.DEFMETHOD("print", function(stream, force_parens) {
|
||||||
var self = this, generator = self._codegen;
|
var self = this, generator = self._codegen;
|
||||||
if (self instanceof AST_Scope) {
|
|
||||||
active_scope = self;
|
|
||||||
} else if (!use_asm && self instanceof AST_Directive && self.value == "use asm") {
|
|
||||||
use_asm = active_scope;
|
|
||||||
}
|
|
||||||
function doit() {
|
function doit() {
|
||||||
stream.prepend_comments(self);
|
stream.prepend_comments(self);
|
||||||
self.add_source_map(stream);
|
self.add_source_map(stream);
|
||||||
@@ -657,9 +643,6 @@ function OutputStream(options) {
|
|||||||
doit();
|
doit();
|
||||||
}
|
}
|
||||||
stream.pop_node();
|
stream.pop_node();
|
||||||
if (self === use_asm) {
|
|
||||||
use_asm = null;
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
AST_Node.DEFMETHOD("_print", AST_Node.prototype.print);
|
AST_Node.DEFMETHOD("_print", AST_Node.prototype.print);
|
||||||
|
|
||||||
@@ -711,16 +694,23 @@ function OutputStream(options) {
|
|||||||
|
|
||||||
PARENS(AST_Sequence, function(output) {
|
PARENS(AST_Sequence, function(output) {
|
||||||
var p = output.parent();
|
var p = output.parent();
|
||||||
return p instanceof AST_Call // (foo, bar)() or foo(1, (2, 3), 4)
|
// (foo, bar)() or foo(1, (2, 3), 4)
|
||||||
|| p instanceof AST_Unary // !(foo, bar, baz)
|
return p instanceof AST_Call
|
||||||
|| p instanceof AST_Binary // 1 + (2, 3) + 4 ==> 8
|
// !(foo, bar, baz)
|
||||||
|| p instanceof AST_VarDef // var a = (1, 2), b = a + a; ==> b == 4
|
|| p instanceof AST_Unary
|
||||||
|| p instanceof AST_PropAccess // (1, {foo:2}).foo or (1, {foo:2})["foo"] ==> 2
|
// 1 + (2, 3) + 4 ==> 8
|
||||||
|| p instanceof AST_Array // [ 1, (2, 3), 4 ] ==> [ 1, 3, 4 ]
|
|| p instanceof AST_Binary
|
||||||
|| p instanceof AST_ObjectProperty // { foo: (1, 2) }.foo ==> 2
|
// var a = (1, 2), b = a + a; ==> b == 4
|
||||||
|| p instanceof AST_Conditional /* (false, true) ? (a = 10, b = 20) : (c = 30)
|
|| p instanceof AST_VarDef
|
||||||
* ==> 20 (side effect, set a := 10 and b := 20) */
|
// (1, {foo:2}).foo or (1, {foo:2})["foo"] ==> 2
|
||||||
;
|
|| p instanceof AST_PropAccess && p.expression === this
|
||||||
|
// [ 1, (2, 3), 4 ] ==> [ 1, 3, 4 ]
|
||||||
|
|| p instanceof AST_Array
|
||||||
|
// { foo: (1, 2) }.foo ==> 2
|
||||||
|
|| p instanceof AST_ObjectProperty
|
||||||
|
// (false, true) ? (a = 10, b = 20) : (c = 30)
|
||||||
|
// ==> 20 (side effect, set a := 10 and b := 20)
|
||||||
|
|| p instanceof AST_Conditional;
|
||||||
});
|
});
|
||||||
|
|
||||||
PARENS(AST_Binary, function(output) {
|
PARENS(AST_Binary, function(output) {
|
||||||
@@ -792,7 +782,7 @@ function OutputStream(options) {
|
|||||||
PARENS(AST_Number, function(output) {
|
PARENS(AST_Number, function(output) {
|
||||||
var p = output.parent();
|
var p = output.parent();
|
||||||
if (p instanceof AST_PropAccess && p.expression === this) {
|
if (p instanceof AST_PropAccess && p.expression === this) {
|
||||||
var value = this.getValue();
|
var value = this.value;
|
||||||
if (value < 0 || /^0/.test(make_num(value))) {
|
if (value < 0 || /^0/.test(make_num(value))) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -821,7 +811,18 @@ function OutputStream(options) {
|
|||||||
/* -----[ PRINTERS ]----- */
|
/* -----[ PRINTERS ]----- */
|
||||||
|
|
||||||
DEFPRINT(AST_Directive, function(self, output) {
|
DEFPRINT(AST_Directive, function(self, output) {
|
||||||
output.print_string(self.value, self.quote);
|
var quote = self.quote;
|
||||||
|
var value = self.value;
|
||||||
|
switch (output.option("quote_style")) {
|
||||||
|
case 0:
|
||||||
|
case 2:
|
||||||
|
if (value.indexOf('"') == -1) quote = '"';
|
||||||
|
break;
|
||||||
|
case 1:
|
||||||
|
if (value.indexOf("'") == -1) quote = "'";
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
output.print(quote + value + quote);
|
||||||
output.semicolon();
|
output.semicolon();
|
||||||
});
|
});
|
||||||
DEFPRINT(AST_Debugger, function(self, output) {
|
DEFPRINT(AST_Debugger, function(self, output) {
|
||||||
@@ -833,30 +834,27 @@ function OutputStream(options) {
|
|||||||
|
|
||||||
function display_body(body, is_toplevel, output, allow_directives) {
|
function display_body(body, is_toplevel, output, allow_directives) {
|
||||||
var last = body.length - 1;
|
var last = body.length - 1;
|
||||||
in_directive = allow_directives;
|
var in_directive = allow_directives;
|
||||||
|
var was_asm = use_asm;
|
||||||
body.forEach(function(stmt, i) {
|
body.forEach(function(stmt, i) {
|
||||||
if (in_directive === true && !(stmt instanceof AST_Directive ||
|
if (in_directive) {
|
||||||
stmt instanceof AST_EmptyStatement ||
|
if (stmt instanceof AST_Directive) {
|
||||||
(stmt instanceof AST_SimpleStatement && stmt.body instanceof AST_String)
|
if (stmt.value == "use asm") use_asm = true;
|
||||||
)) {
|
} else if (!(stmt instanceof AST_EmptyStatement)) {
|
||||||
|
if (stmt instanceof AST_SimpleStatement && stmt.body instanceof AST_String) {
|
||||||
|
output.force_semicolon();
|
||||||
|
}
|
||||||
in_directive = false;
|
in_directive = false;
|
||||||
}
|
}
|
||||||
if (!(stmt instanceof AST_EmptyStatement)) {
|
}
|
||||||
|
if (stmt instanceof AST_EmptyStatement) return;
|
||||||
output.indent();
|
output.indent();
|
||||||
stmt.print(output);
|
stmt.print(output);
|
||||||
if (!(i == last && is_toplevel)) {
|
if (i == last && is_toplevel) return;
|
||||||
output.newline();
|
output.newline();
|
||||||
if (is_toplevel) output.newline();
|
if (is_toplevel) output.newline();
|
||||||
}
|
|
||||||
}
|
|
||||||
if (in_directive === true &&
|
|
||||||
stmt instanceof AST_SimpleStatement &&
|
|
||||||
stmt.body instanceof AST_String
|
|
||||||
) {
|
|
||||||
in_directive = false;
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
in_directive = false;
|
use_asm = was_asm;
|
||||||
}
|
}
|
||||||
|
|
||||||
AST_StatementWithBody.DEFMETHOD("_do_print_body", function(output) {
|
AST_StatementWithBody.DEFMETHOD("_do_print_body", function(output) {
|
||||||
@@ -1214,7 +1212,7 @@ function OutputStream(options) {
|
|||||||
output.print_string(prop);
|
output.print_string(prop);
|
||||||
output.print("]");
|
output.print("]");
|
||||||
} else {
|
} else {
|
||||||
if (expr instanceof AST_Number && expr.getValue() >= 0) {
|
if (expr instanceof AST_Number && expr.value >= 0) {
|
||||||
if (!/[xa-f.)]/i.test(output.last())) {
|
if (!/[xa-f.)]/i.test(output.last())) {
|
||||||
output.print(".");
|
output.print(".");
|
||||||
}
|
}
|
||||||
@@ -1247,29 +1245,10 @@ function OutputStream(options) {
|
|||||||
output.print(self.operator);
|
output.print(self.operator);
|
||||||
});
|
});
|
||||||
DEFPRINT(AST_Binary, function(self, output) {
|
DEFPRINT(AST_Binary, function(self, output) {
|
||||||
var op = self.operator;
|
|
||||||
self.left.print(output);
|
self.left.print(output);
|
||||||
if (op[0] == ">" /* ">>" ">>>" ">" ">=" */
|
|
||||||
&& self.left instanceof AST_UnaryPostfix
|
|
||||||
&& self.left.operator == "--") {
|
|
||||||
// space is mandatory to avoid outputting -->
|
|
||||||
output.print(" ");
|
|
||||||
} else {
|
|
||||||
// the space is optional depending on "beautify"
|
|
||||||
output.space();
|
output.space();
|
||||||
}
|
output.print(self.operator);
|
||||||
output.print(op);
|
|
||||||
if ((op == "<" || op == "<<")
|
|
||||||
&& self.right instanceof AST_UnaryPrefix
|
|
||||||
&& self.right.operator == "!"
|
|
||||||
&& self.right.expression instanceof AST_UnaryPrefix
|
|
||||||
&& self.right.expression.operator == "--") {
|
|
||||||
// space is mandatory to avoid outputting <!--
|
|
||||||
output.print(" ");
|
|
||||||
} else {
|
|
||||||
// the space is optional depending on "beautify"
|
|
||||||
output.space();
|
output.space();
|
||||||
}
|
|
||||||
self.right.print(output);
|
self.right.print(output);
|
||||||
});
|
});
|
||||||
DEFPRINT(AST_Conditional, function(self, output) {
|
DEFPRINT(AST_Conditional, function(self, output) {
|
||||||
@@ -1357,21 +1336,21 @@ function OutputStream(options) {
|
|||||||
output.print("this");
|
output.print("this");
|
||||||
});
|
});
|
||||||
DEFPRINT(AST_Constant, function(self, output) {
|
DEFPRINT(AST_Constant, function(self, output) {
|
||||||
output.print(self.getValue());
|
output.print(self.value);
|
||||||
});
|
});
|
||||||
DEFPRINT(AST_String, function(self, output) {
|
DEFPRINT(AST_String, function(self, output) {
|
||||||
output.print_string(self.getValue(), self.quote, in_directive);
|
output.print_string(self.value, self.quote);
|
||||||
});
|
});
|
||||||
DEFPRINT(AST_Number, function(self, output) {
|
DEFPRINT(AST_Number, function(self, output) {
|
||||||
if (use_asm && self.start && self.start.raw != null) {
|
if (use_asm && self.start && self.start.raw != null) {
|
||||||
output.print(self.start.raw);
|
output.print(self.start.raw);
|
||||||
} else {
|
} else {
|
||||||
output.print(make_num(self.getValue()));
|
output.print(make_num(self.value));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
DEFPRINT(AST_RegExp, function(self, output) {
|
DEFPRINT(AST_RegExp, function(self, output) {
|
||||||
var regexp = self.getValue();
|
var regexp = self.value;
|
||||||
var str = regexp.toString();
|
var str = regexp.toString();
|
||||||
if (regexp.raw_source) {
|
if (regexp.raw_source) {
|
||||||
str = "/" + regexp.raw_source + str.slice(str.lastIndexOf("/"));
|
str = "/" + regexp.raw_source + str.slice(str.lastIndexOf("/"));
|
||||||
|
|||||||
31
lib/parse.js
31
lib/parse.js
@@ -133,14 +133,10 @@ function is_letter(code) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function is_surrogate_pair_head(code) {
|
function is_surrogate_pair_head(code) {
|
||||||
if (typeof code == "string")
|
|
||||||
code = code.charCodeAt(0);
|
|
||||||
return code >= 0xd800 && code <= 0xdbff;
|
return code >= 0xd800 && code <= 0xdbff;
|
||||||
}
|
}
|
||||||
|
|
||||||
function is_surrogate_pair_tail(code) {
|
function is_surrogate_pair_tail(code) {
|
||||||
if (typeof code == "string")
|
|
||||||
code = code.charCodeAt(0);
|
|
||||||
return code >= 0xdc00 && code <= 0xdfff;
|
return code >= 0xdc00 && code <= 0xdfff;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -787,20 +783,19 @@ function parse($TEXT, options) {
|
|||||||
handle_regexp();
|
handle_regexp();
|
||||||
switch (S.token.type) {
|
switch (S.token.type) {
|
||||||
case "string":
|
case "string":
|
||||||
if (S.in_directives) {
|
var dir = S.in_directives;
|
||||||
var token = peek();
|
var body = expression(true);
|
||||||
if (S.token.raw.indexOf("\\") == -1
|
if (dir) {
|
||||||
&& (is_token(token, "punc", ";")
|
if (body instanceof AST_String) {
|
||||||
|| is_token(token, "punc", "}")
|
var value = body.start.raw.slice(1, -1);
|
||||||
|| has_newline_before(token)
|
S.input.add_directive(value);
|
||||||
|| is_token(token, "eof"))) {
|
body.value = value;
|
||||||
S.input.add_directive(S.token.value);
|
|
||||||
} else {
|
} else {
|
||||||
S.in_directives = false;
|
S.in_directives = dir = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
var dir = S.in_directives, stat = simple_statement();
|
semicolon();
|
||||||
return dir ? new AST_Directive(stat.body) : stat;
|
return dir ? new AST_Directive(body) : new AST_SimpleStatement({ body: body });
|
||||||
case "num":
|
case "num":
|
||||||
case "regexp":
|
case "regexp":
|
||||||
case "operator":
|
case "operator":
|
||||||
@@ -965,8 +960,10 @@ function parse($TEXT, options) {
|
|||||||
return new AST_LabeledStatement({ body: stat, label: label });
|
return new AST_LabeledStatement({ body: stat, label: label });
|
||||||
}
|
}
|
||||||
|
|
||||||
function simple_statement(tmp) {
|
function simple_statement() {
|
||||||
return new AST_SimpleStatement({ body: (tmp = expression(true), semicolon(), tmp) });
|
var body = expression(true);
|
||||||
|
semicolon();
|
||||||
|
return new AST_SimpleStatement({ body: body });
|
||||||
}
|
}
|
||||||
|
|
||||||
function break_cont(type) {
|
function break_cont(type) {
|
||||||
|
|||||||
@@ -428,6 +428,11 @@ AST_Toplevel.DEFMETHOD("mangle_names", function(options) {
|
|||||||
if (options.cache && node instanceof AST_Toplevel) {
|
if (options.cache && node instanceof AST_Toplevel) {
|
||||||
node.globals.each(mangle);
|
node.globals.each(mangle);
|
||||||
}
|
}
|
||||||
|
if (node instanceof AST_Defun && tw.has_directive("use asm")) {
|
||||||
|
var sym = new AST_SymbolRef(node.name);
|
||||||
|
sym.scope = node;
|
||||||
|
sym.reference(options);
|
||||||
|
}
|
||||||
node.variables.each(function(def) {
|
node.variables.each(function(def) {
|
||||||
if (!defer_redef(def)) mangle(def);
|
if (!defer_redef(def)) mangle(def);
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
"description": "JavaScript parser, mangler/compressor and beautifier toolkit",
|
"description": "JavaScript parser, mangler/compressor and beautifier toolkit",
|
||||||
"author": "Mihai Bazon <mihai.bazon@gmail.com> (http://lisperator.net/)",
|
"author": "Mihai Bazon <mihai.bazon@gmail.com> (http://lisperator.net/)",
|
||||||
"license": "BSD-2-Clause",
|
"license": "BSD-2-Clause",
|
||||||
"version": "3.6.7",
|
"version": "3.7.5",
|
||||||
"engines": {
|
"engines": {
|
||||||
"node": ">=0.8.0"
|
"node": ">=0.8.0"
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -166,3 +166,69 @@ asm_nested_functions: {
|
|||||||
}
|
}
|
||||||
expect_exact: '0;function a(){"use asm";0.0}0;function b(){0;function c(){"use asm";0.0}0;function d(){0}0}0;'
|
expect_exact: '0;function a(){"use asm";0.0}0;function b(){0;function c(){"use asm";0.0}0;function d(){0}0}0;'
|
||||||
}
|
}
|
||||||
|
|
||||||
|
issue_3636_1: {
|
||||||
|
mangle = {}
|
||||||
|
input: {
|
||||||
|
function n(stdlib, foreign, buffer) {
|
||||||
|
"use asm";
|
||||||
|
function add(x, y) {
|
||||||
|
x = x | 0;
|
||||||
|
y = y | 0;
|
||||||
|
return x + y | 0;
|
||||||
|
}
|
||||||
|
return {
|
||||||
|
add: add
|
||||||
|
};
|
||||||
|
}
|
||||||
|
console.log(new n().add("foo", 42));
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
function n(o, e, u) {
|
||||||
|
"use asm";
|
||||||
|
function d(n, o) {
|
||||||
|
n = n | 0;
|
||||||
|
o = o | 0;
|
||||||
|
return n + o | 0;
|
||||||
|
}
|
||||||
|
return {
|
||||||
|
add: d
|
||||||
|
};
|
||||||
|
}
|
||||||
|
console.log(new n().add("foo", 42));
|
||||||
|
}
|
||||||
|
expect_stdout: "42"
|
||||||
|
}
|
||||||
|
|
||||||
|
issue_3636_2: {
|
||||||
|
mangle = {}
|
||||||
|
input: {
|
||||||
|
var n = function(stdlib, foreign, buffer) {
|
||||||
|
"use asm";
|
||||||
|
function add(x, y) {
|
||||||
|
x = x | 0;
|
||||||
|
y = y | 0;
|
||||||
|
return x + y | 0;
|
||||||
|
}
|
||||||
|
return {
|
||||||
|
add: add
|
||||||
|
};
|
||||||
|
};
|
||||||
|
console.log(new n().add("foo", 42));
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
var n = function(n, o, e) {
|
||||||
|
"use asm";
|
||||||
|
function r(n, o) {
|
||||||
|
n = n | 0;
|
||||||
|
o = o | 0;
|
||||||
|
return n + o | 0;
|
||||||
|
}
|
||||||
|
return {
|
||||||
|
add: r
|
||||||
|
};
|
||||||
|
};
|
||||||
|
console.log(new n().add("foo", 42));
|
||||||
|
}
|
||||||
|
expect_stdout: "42"
|
||||||
|
}
|
||||||
|
|||||||
@@ -290,26 +290,60 @@ increment_decrement_2: {
|
|||||||
expect_stdout: "42"
|
expect_stdout: "42"
|
||||||
}
|
}
|
||||||
|
|
||||||
issue_3375: {
|
issue_3375_1: {
|
||||||
options = {
|
options = {
|
||||||
assignments: true,
|
assignments: true,
|
||||||
reduce_vars: true,
|
reduce_vars: true,
|
||||||
}
|
}
|
||||||
input: {
|
input: {
|
||||||
console.log(typeof function(b) {
|
function p(o) {
|
||||||
|
console.log(typeof o, o);
|
||||||
|
}
|
||||||
|
p(function(b) {
|
||||||
var a = b += 1;
|
var a = b += 1;
|
||||||
--b;
|
--b;
|
||||||
return a;
|
return a;
|
||||||
}("object"));
|
}("object"));
|
||||||
}
|
}
|
||||||
expect: {
|
expect: {
|
||||||
console.log(typeof function(b) {
|
function p(o) {
|
||||||
|
console.log(typeof o, o);
|
||||||
|
}
|
||||||
|
p(function(b) {
|
||||||
var a = b += 1;
|
var a = b += 1;
|
||||||
--b;
|
--b;
|
||||||
return a;
|
return a;
|
||||||
}("object"));
|
}("object"));
|
||||||
}
|
}
|
||||||
expect_stdout: "string"
|
expect_stdout: "string object1"
|
||||||
|
}
|
||||||
|
|
||||||
|
issue_3375_2: {
|
||||||
|
options = {
|
||||||
|
assignments: true,
|
||||||
|
reduce_vars: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
function p(o) {
|
||||||
|
console.log(typeof o, o);
|
||||||
|
}
|
||||||
|
p(function(b) {
|
||||||
|
var a = b -= 1;
|
||||||
|
--b;
|
||||||
|
return a;
|
||||||
|
}("object"));
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
function p(o) {
|
||||||
|
console.log(typeof o, o);
|
||||||
|
}
|
||||||
|
p(function(b) {
|
||||||
|
var a = --b;
|
||||||
|
--b;
|
||||||
|
return a;
|
||||||
|
}("object"));
|
||||||
|
}
|
||||||
|
expect_stdout: "number NaN"
|
||||||
}
|
}
|
||||||
|
|
||||||
issue_3427: {
|
issue_3427: {
|
||||||
|
|||||||
@@ -86,3 +86,48 @@ issue_3465_3: {
|
|||||||
}
|
}
|
||||||
expect_stdout: "PASS"
|
expect_stdout: "PASS"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
issue_2737_2: {
|
||||||
|
options = {
|
||||||
|
booleans: true,
|
||||||
|
inline: true,
|
||||||
|
reduce_vars: true,
|
||||||
|
unused: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
(function(bar) {
|
||||||
|
for (;bar();) break;
|
||||||
|
})(function qux() {
|
||||||
|
return console.log("PASS"), qux;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
(function(bar) {
|
||||||
|
for (;bar();) break;
|
||||||
|
})(function() {
|
||||||
|
return console.log("PASS"), 1;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
expect_stdout: "PASS"
|
||||||
|
}
|
||||||
|
|
||||||
|
issue_3658: {
|
||||||
|
options = {
|
||||||
|
booleans: true,
|
||||||
|
evaluate: true,
|
||||||
|
reduce_vars: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
console.log(function f() {
|
||||||
|
console || f();
|
||||||
|
return "PASS";
|
||||||
|
}());
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
console.log(function f() {
|
||||||
|
console || f();
|
||||||
|
return "PASS";
|
||||||
|
}());
|
||||||
|
}
|
||||||
|
expect_stdout: "PASS"
|
||||||
|
}
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@@ -33,10 +33,10 @@ unsafe_comps: {
|
|||||||
}
|
}
|
||||||
expect: {
|
expect: {
|
||||||
var obj1, obj2;
|
var obj1, obj2;
|
||||||
obj2 < obj1 ? g1() : f1();
|
(obj2 < obj1 ? g1 : f1)();
|
||||||
obj1 < obj2 ? f2() : g2();
|
(obj1 < obj2 ? f2 : g2)();
|
||||||
obj1 < obj2 ? g3() : f3();
|
(obj1 < obj2 ? g3 : f3)();
|
||||||
obj2 < obj1 ? f4() : g4();
|
(obj2 < obj1 ? f4 : g4)();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -41,7 +41,7 @@ ifs_2: {
|
|||||||
}
|
}
|
||||||
expect: {
|
expect: {
|
||||||
foo ? x() : bar ? y() : baz && z();
|
foo ? x() : bar ? y() : baz && z();
|
||||||
foo ? x() : bar ? y() : baz ? z() : t();
|
(foo ? x : bar ? y : baz ? z : t)();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -289,7 +289,7 @@ cond_5: {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
expect: {
|
expect: {
|
||||||
some_condition() && some_other_condition() ? do_something() : alternate();
|
(some_condition() && some_other_condition() ? do_something : alternate)();
|
||||||
some_condition() && some_other_condition() && do_something();
|
some_condition() && some_other_condition() && do_something();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -663,6 +663,69 @@ cond_9: {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
cond_10: {
|
||||||
|
options = {
|
||||||
|
conditionals: true,
|
||||||
|
if_return: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
function f(a) {
|
||||||
|
if (1 == a) return "foo";
|
||||||
|
if (2 == a) return "foo";
|
||||||
|
if (3 == a) return "foo";
|
||||||
|
if (4 == a) return 42;
|
||||||
|
if (5 == a) return "foo";
|
||||||
|
if (6 == a) return "foo";
|
||||||
|
return "bar";
|
||||||
|
}
|
||||||
|
console.log(f(1), f(2), f(3), f(4), f(5), f(6), f(7));
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
function f(a) {
|
||||||
|
return 1 == a || 2 == a || 3 == a ? "foo" : 4 == a ? 42 : 5 == a || 6 == a ? "foo" : "bar";
|
||||||
|
}
|
||||||
|
console.log(f(1), f(2), f(3), f(4), f(5), f(6), f(7));
|
||||||
|
}
|
||||||
|
expect_stdout: "foo foo foo 42 foo foo bar"
|
||||||
|
}
|
||||||
|
|
||||||
|
cond_11: {
|
||||||
|
options = {
|
||||||
|
conditionals: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
var o = {
|
||||||
|
p: "foo",
|
||||||
|
q: function() {
|
||||||
|
return this.p;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
function f() {
|
||||||
|
return "bar";
|
||||||
|
}
|
||||||
|
function g(a) {
|
||||||
|
return a ? f() : o.q();
|
||||||
|
}
|
||||||
|
console.log(g(0), g(1));
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
var o = {
|
||||||
|
p: "foo",
|
||||||
|
q: function() {
|
||||||
|
return this.p;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
function f() {
|
||||||
|
return "bar";
|
||||||
|
}
|
||||||
|
function g(a) {
|
||||||
|
return a ? f() : o.q();
|
||||||
|
}
|
||||||
|
console.log(g(0), g(1));
|
||||||
|
}
|
||||||
|
expect_stdout: "foo bar"
|
||||||
|
}
|
||||||
|
|
||||||
ternary_boolean_consequent: {
|
ternary_boolean_consequent: {
|
||||||
options = {
|
options = {
|
||||||
booleans: true,
|
booleans: true,
|
||||||
@@ -1489,3 +1552,60 @@ angularjs_chain: {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
issue_3576: {
|
||||||
|
options = {
|
||||||
|
conditionals: true,
|
||||||
|
evaluate: true,
|
||||||
|
pure_getters: "strict",
|
||||||
|
reduce_vars: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
var c = "FAIL";
|
||||||
|
(function(a) {
|
||||||
|
(a = -1) ? (a && (a.a = 0)) : (a && (a.a = 0));
|
||||||
|
a && a[c = "PASS"]++;
|
||||||
|
})();
|
||||||
|
console.log(c);
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
var c = "FAIL";
|
||||||
|
(function(a) {
|
||||||
|
a = -1, a, a.a = 0;
|
||||||
|
a, a[c = "PASS"]++;
|
||||||
|
})();
|
||||||
|
console.log(c);
|
||||||
|
}
|
||||||
|
expect_stdout: "PASS"
|
||||||
|
}
|
||||||
|
|
||||||
|
issue_3668: {
|
||||||
|
options = {
|
||||||
|
conditionals: true,
|
||||||
|
if_return: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
function f() {
|
||||||
|
try {
|
||||||
|
var undefined = typeof f;
|
||||||
|
if (!f) return undefined;
|
||||||
|
return;
|
||||||
|
} catch (e) {
|
||||||
|
return "FAIL";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
console.log(f());
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
function f() {
|
||||||
|
try {
|
||||||
|
var undefined = typeof f;
|
||||||
|
return f ? void 0 : undefined;
|
||||||
|
} catch (e) {
|
||||||
|
return "FAIL";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
console.log(f());
|
||||||
|
}
|
||||||
|
expect_stdout: "undefined"
|
||||||
|
}
|
||||||
|
|||||||
@@ -141,207 +141,6 @@ try_catch_finally: {
|
|||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
accessor: {
|
|
||||||
options = {
|
|
||||||
side_effects: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
({
|
|
||||||
get a() {},
|
|
||||||
set a(v){
|
|
||||||
this.b = 2;
|
|
||||||
},
|
|
||||||
b: 1
|
|
||||||
});
|
|
||||||
}
|
|
||||||
expect: {}
|
|
||||||
}
|
|
||||||
|
|
||||||
issue_2233_1: {
|
|
||||||
options = {
|
|
||||||
pure_getters: "strict",
|
|
||||||
side_effects: true,
|
|
||||||
unsafe: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
Array.isArray;
|
|
||||||
Boolean;
|
|
||||||
console.log;
|
|
||||||
Date;
|
|
||||||
decodeURI;
|
|
||||||
decodeURIComponent;
|
|
||||||
encodeURI;
|
|
||||||
encodeURIComponent;
|
|
||||||
Error.name;
|
|
||||||
escape;
|
|
||||||
eval;
|
|
||||||
EvalError;
|
|
||||||
Function.length;
|
|
||||||
isFinite;
|
|
||||||
isNaN;
|
|
||||||
JSON;
|
|
||||||
Math.random;
|
|
||||||
Number.isNaN;
|
|
||||||
parseFloat;
|
|
||||||
parseInt;
|
|
||||||
RegExp;
|
|
||||||
Object.defineProperty;
|
|
||||||
String.fromCharCode;
|
|
||||||
RangeError;
|
|
||||||
ReferenceError;
|
|
||||||
SyntaxError;
|
|
||||||
TypeError;
|
|
||||||
unescape;
|
|
||||||
URIError;
|
|
||||||
}
|
|
||||||
expect: {}
|
|
||||||
expect_stdout: true
|
|
||||||
}
|
|
||||||
|
|
||||||
global_timeout_and_interval_symbols: {
|
|
||||||
options = {
|
|
||||||
pure_getters: "strict",
|
|
||||||
side_effects: true,
|
|
||||||
unsafe: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
// These global symbols do not exist in the test sandbox
|
|
||||||
// and must be tested separately.
|
|
||||||
clearInterval;
|
|
||||||
clearTimeout;
|
|
||||||
setInterval;
|
|
||||||
setTimeout;
|
|
||||||
}
|
|
||||||
expect: {}
|
|
||||||
}
|
|
||||||
|
|
||||||
issue_2233_2: {
|
|
||||||
options = {
|
|
||||||
pure_getters: "strict",
|
|
||||||
reduce_funcs: true,
|
|
||||||
reduce_vars: true,
|
|
||||||
side_effects: true,
|
|
||||||
unsafe: true,
|
|
||||||
unused: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
var RegExp;
|
|
||||||
Array.isArray;
|
|
||||||
RegExp;
|
|
||||||
UndeclaredGlobal;
|
|
||||||
function foo() {
|
|
||||||
var Number;
|
|
||||||
AnotherUndeclaredGlobal;
|
|
||||||
Math.sin;
|
|
||||||
Number.isNaN;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
var RegExp;
|
|
||||||
UndeclaredGlobal;
|
|
||||||
function foo() {
|
|
||||||
var Number;
|
|
||||||
AnotherUndeclaredGlobal;
|
|
||||||
Number.isNaN;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
issue_2233_3: {
|
|
||||||
options = {
|
|
||||||
pure_getters: "strict",
|
|
||||||
reduce_funcs: true,
|
|
||||||
reduce_vars: true,
|
|
||||||
side_effects: true,
|
|
||||||
toplevel: true,
|
|
||||||
unsafe: true,
|
|
||||||
unused: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
var RegExp;
|
|
||||||
Array.isArray;
|
|
||||||
RegExp;
|
|
||||||
UndeclaredGlobal;
|
|
||||||
function foo() {
|
|
||||||
var Number;
|
|
||||||
AnotherUndeclaredGlobal;
|
|
||||||
Math.sin;
|
|
||||||
Number.isNaN;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
UndeclaredGlobal;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
global_fns: {
|
|
||||||
options = {
|
|
||||||
side_effects: true,
|
|
||||||
unsafe: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
Boolean(1, 2);
|
|
||||||
decodeURI(1, 2);
|
|
||||||
decodeURIComponent(1, 2);
|
|
||||||
Date(1, 2);
|
|
||||||
encodeURI(1, 2);
|
|
||||||
encodeURIComponent(1, 2);
|
|
||||||
Error(1, 2);
|
|
||||||
escape(1, 2);
|
|
||||||
EvalError(1, 2);
|
|
||||||
isFinite(1, 2);
|
|
||||||
isNaN(1, 2);
|
|
||||||
Number(1, 2);
|
|
||||||
Object(1, 2);
|
|
||||||
parseFloat(1, 2);
|
|
||||||
parseInt(1, 2);
|
|
||||||
RangeError(1, 2);
|
|
||||||
ReferenceError(1, 2);
|
|
||||||
String(1, 2);
|
|
||||||
SyntaxError(1, 2);
|
|
||||||
TypeError(1, 2);
|
|
||||||
unescape(1, 2);
|
|
||||||
URIError(1, 2);
|
|
||||||
try {
|
|
||||||
Function(1, 2);
|
|
||||||
} catch (e) {
|
|
||||||
console.log(e.name);
|
|
||||||
}
|
|
||||||
try {
|
|
||||||
RegExp(1, 2);
|
|
||||||
} catch (e) {
|
|
||||||
console.log(e.name);
|
|
||||||
}
|
|
||||||
try {
|
|
||||||
Array(NaN);
|
|
||||||
} catch (e) {
|
|
||||||
console.log(e.name);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
try {
|
|
||||||
Function(1, 2);
|
|
||||||
} catch (e) {
|
|
||||||
console.log(e.name);
|
|
||||||
}
|
|
||||||
try {
|
|
||||||
RegExp(1, 2);
|
|
||||||
} catch (e) {
|
|
||||||
console.log(e.name);
|
|
||||||
}
|
|
||||||
try {
|
|
||||||
Array(NaN);
|
|
||||||
} catch (e) {
|
|
||||||
console.log(e.name);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
expect_stdout: [
|
|
||||||
"SyntaxError",
|
|
||||||
"SyntaxError",
|
|
||||||
"RangeError",
|
|
||||||
]
|
|
||||||
}
|
|
||||||
|
|
||||||
collapse_vars_assignment: {
|
collapse_vars_assignment: {
|
||||||
options = {
|
options = {
|
||||||
collapse_vars: true,
|
collapse_vars: true,
|
||||||
@@ -863,23 +662,6 @@ issue_2749: {
|
|||||||
expect_stdout: "PASS"
|
expect_stdout: "PASS"
|
||||||
}
|
}
|
||||||
|
|
||||||
unsafe_builtin: {
|
|
||||||
options = {
|
|
||||||
side_effects: true,
|
|
||||||
unsafe: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
(!w).constructor(x);
|
|
||||||
Math.abs(y);
|
|
||||||
[ 1, 2, z ].valueOf();
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
w, x;
|
|
||||||
y;
|
|
||||||
z;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
issue_2860_1: {
|
issue_2860_1: {
|
||||||
options = {
|
options = {
|
||||||
dead_code: true,
|
dead_code: true,
|
||||||
@@ -892,9 +674,7 @@ issue_2860_1: {
|
|||||||
}());
|
}());
|
||||||
}
|
}
|
||||||
expect: {
|
expect: {
|
||||||
console.log(function(a) {
|
console.log(1);
|
||||||
return 1 ^ a;
|
|
||||||
}());
|
|
||||||
}
|
}
|
||||||
expect_stdout: "1"
|
expect_stdout: "1"
|
||||||
}
|
}
|
||||||
@@ -943,24 +723,6 @@ issue_2929: {
|
|||||||
expect_stdout: "PASS"
|
expect_stdout: "PASS"
|
||||||
}
|
}
|
||||||
|
|
||||||
unsafe_string_replace: {
|
|
||||||
options = {
|
|
||||||
side_effects: true,
|
|
||||||
unsafe: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
"foo".replace("f", function() {
|
|
||||||
console.log("PASS");
|
|
||||||
});
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
"foo".replace("f", function() {
|
|
||||||
console.log("PASS");
|
|
||||||
});
|
|
||||||
}
|
|
||||||
expect_stdout: "PASS"
|
|
||||||
}
|
|
||||||
|
|
||||||
issue_3402: {
|
issue_3402: {
|
||||||
options = {
|
options = {
|
||||||
dead_code: true,
|
dead_code: true,
|
||||||
@@ -1064,3 +826,68 @@ issue_3552: {
|
|||||||
}
|
}
|
||||||
expect_stdout: "PASS"
|
expect_stdout: "PASS"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
unreachable_assign: {
|
||||||
|
options = {
|
||||||
|
dead_code: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
console.log(A = "P" + (A = "A" + (B = "S" + (A = B = "S"))), A, B);
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
console.log(A = "P" + "A" + (B = "S" + "S"), A, B);
|
||||||
|
}
|
||||||
|
expect_stdout: "PASS PASS SS"
|
||||||
|
}
|
||||||
|
|
||||||
|
catch_return_assign: {
|
||||||
|
options = {
|
||||||
|
dead_code: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
console.log(function() {
|
||||||
|
try {
|
||||||
|
throw "FAIL";
|
||||||
|
} catch (e) {
|
||||||
|
return e = "PASS";
|
||||||
|
}
|
||||||
|
}());
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
console.log(function() {
|
||||||
|
try {
|
||||||
|
throw "FAIL";
|
||||||
|
} catch (e) {
|
||||||
|
return "PASS";
|
||||||
|
}
|
||||||
|
}());
|
||||||
|
}
|
||||||
|
expect_stdout: "PASS"
|
||||||
|
}
|
||||||
|
|
||||||
|
issue_3578: {
|
||||||
|
options = {
|
||||||
|
dead_code: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
var a = "FAIL", b, c;
|
||||||
|
try {
|
||||||
|
b = c.p = b = 0;
|
||||||
|
} catch (e) {
|
||||||
|
b += 42;
|
||||||
|
b && (a = "PASS");
|
||||||
|
}
|
||||||
|
console.log(a);
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
var a = "FAIL", b, c;
|
||||||
|
try {
|
||||||
|
b = c.p = b = 0;
|
||||||
|
} catch (e) {
|
||||||
|
b += 42;
|
||||||
|
b && (a = "PASS");
|
||||||
|
}
|
||||||
|
console.log(a);
|
||||||
|
}
|
||||||
|
expect_stdout: "PASS"
|
||||||
|
}
|
||||||
|
|||||||
133
test/compress/directives.js
Normal file
133
test/compress/directives.js
Normal file
@@ -0,0 +1,133 @@
|
|||||||
|
simple_statement_is_not_a_directive: {
|
||||||
|
input: {
|
||||||
|
"use strict"
|
||||||
|
.split(" ")
|
||||||
|
.forEach(function(s) {
|
||||||
|
console.log(s);
|
||||||
|
});
|
||||||
|
console.log(!this); // is strict mode?
|
||||||
|
(function() {
|
||||||
|
"directive"
|
||||||
|
""
|
||||||
|
"use strict"
|
||||||
|
"hello world"
|
||||||
|
.split(" ")
|
||||||
|
.forEach(function(s) {
|
||||||
|
console.log(s);
|
||||||
|
});
|
||||||
|
console.log(!this); // is strict mode?
|
||||||
|
})();
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
"use strict".split(" ").forEach(function(s) {
|
||||||
|
console.log(s);
|
||||||
|
});
|
||||||
|
console.log(!this);
|
||||||
|
(function() {
|
||||||
|
"directive";
|
||||||
|
"";
|
||||||
|
"use strict";
|
||||||
|
"hello world".split(" ").forEach(function(s) {
|
||||||
|
console.log(s);
|
||||||
|
});
|
||||||
|
console.log(!this);
|
||||||
|
})();
|
||||||
|
}
|
||||||
|
expect_stdout: [
|
||||||
|
"use",
|
||||||
|
"strict",
|
||||||
|
"false",
|
||||||
|
"hello",
|
||||||
|
"world",
|
||||||
|
"true",
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
|
drop_lone_use_strict: {
|
||||||
|
options = {
|
||||||
|
directives: true,
|
||||||
|
side_effects: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
function f1() {
|
||||||
|
"use strict";
|
||||||
|
}
|
||||||
|
function f2() {
|
||||||
|
"use strict";
|
||||||
|
function f3() {
|
||||||
|
"use strict";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
(function f4() {
|
||||||
|
"use strict";
|
||||||
|
})();
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
function f1() {
|
||||||
|
}
|
||||||
|
function f2() {
|
||||||
|
"use strict";
|
||||||
|
function f3() {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
issue_3166: {
|
||||||
|
options = {
|
||||||
|
directives: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
"foo";
|
||||||
|
"use strict";
|
||||||
|
function f() {
|
||||||
|
"use strict";
|
||||||
|
"bar";
|
||||||
|
"use asm";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
"use strict";
|
||||||
|
function f() {
|
||||||
|
"use asm";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
valid_after_invalid_1: {
|
||||||
|
input: {
|
||||||
|
console.log(typeof function() {
|
||||||
|
"use\x20strict";
|
||||||
|
"use strict";
|
||||||
|
return this;
|
||||||
|
}());
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
console.log(typeof function() {
|
||||||
|
"use\x20strict";
|
||||||
|
"use strict";
|
||||||
|
return this;
|
||||||
|
}());
|
||||||
|
}
|
||||||
|
expect_stdout: "undefined"
|
||||||
|
}
|
||||||
|
|
||||||
|
valid_after_invalid_2: {
|
||||||
|
options = {
|
||||||
|
directives: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
console.log(typeof function() {
|
||||||
|
"use\x20strict";
|
||||||
|
"use strict";
|
||||||
|
return this;
|
||||||
|
}());
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
console.log(typeof function() {
|
||||||
|
"use strict";
|
||||||
|
return this;
|
||||||
|
}());
|
||||||
|
}
|
||||||
|
expect_stdout: "undefined"
|
||||||
|
}
|
||||||
@@ -699,18 +699,6 @@ iife: {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
drop_value: {
|
|
||||||
options = {
|
|
||||||
side_effects: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
(1, [2, foo()], 3, {a:1, b:bar()});
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
foo(), bar();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
issue_1539: {
|
issue_1539: {
|
||||||
options = {
|
options = {
|
||||||
collapse_vars: true,
|
collapse_vars: true,
|
||||||
@@ -1019,14 +1007,21 @@ delete_assign_1: {
|
|||||||
console.log(delete (a = 0 / 0));
|
console.log(delete (a = 0 / 0));
|
||||||
}
|
}
|
||||||
expect: {
|
expect: {
|
||||||
console.log((void 0, !0));
|
console.log(!0);
|
||||||
console.log((void 0, !0));
|
console.log(!0);
|
||||||
console.log((1 / 0, !0));
|
console.log(!0);
|
||||||
console.log((1 / 0, !0));
|
console.log(!0);
|
||||||
console.log((NaN, !0));
|
console.log(!0);
|
||||||
console.log((NaN, !0));
|
console.log(!0);
|
||||||
}
|
}
|
||||||
expect_stdout: true
|
expect_stdout: [
|
||||||
|
"true",
|
||||||
|
"true",
|
||||||
|
"true",
|
||||||
|
"true",
|
||||||
|
"true",
|
||||||
|
"true",
|
||||||
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
delete_assign_2: {
|
delete_assign_2: {
|
||||||
@@ -1047,14 +1042,21 @@ delete_assign_2: {
|
|||||||
console.log(delete (a = 0 / 0));
|
console.log(delete (a = 0 / 0));
|
||||||
}
|
}
|
||||||
expect: {
|
expect: {
|
||||||
console.log((void 0, !0));
|
console.log(!0);
|
||||||
console.log((void 0, !0));
|
console.log(!0);
|
||||||
console.log((Infinity, !0));
|
console.log(!0);
|
||||||
console.log((1 / 0, !0));
|
console.log(!0);
|
||||||
console.log((NaN, !0));
|
console.log(!0);
|
||||||
console.log((NaN, !0));
|
console.log(!0);
|
||||||
}
|
}
|
||||||
expect_stdout: true
|
expect_stdout: [
|
||||||
|
"true",
|
||||||
|
"true",
|
||||||
|
"true",
|
||||||
|
"true",
|
||||||
|
"true",
|
||||||
|
"true",
|
||||||
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
drop_var: {
|
drop_var: {
|
||||||
@@ -1635,7 +1637,7 @@ double_assign_2: {
|
|||||||
}
|
}
|
||||||
expect: {
|
expect: {
|
||||||
for (var i = 0; i < 2; i++)
|
for (var i = 0; i < 2; i++)
|
||||||
void 0, a = {}, console.log(a);
|
a = {}, console.log(a);
|
||||||
var a;
|
var a;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1716,7 +1718,7 @@ issue_2768: {
|
|||||||
}
|
}
|
||||||
expect: {
|
expect: {
|
||||||
var a = "FAIL";
|
var a = "FAIL";
|
||||||
var c = (d = a, 0, void (d && (a = "PASS")));
|
var c = (d = a, void (d && (a = "PASS")));
|
||||||
var d;
|
var d;
|
||||||
console.log(a, typeof c);
|
console.log(a, typeof c);
|
||||||
}
|
}
|
||||||
@@ -2221,3 +2223,155 @@ function_assign: {
|
|||||||
}
|
}
|
||||||
expect_stdout: "PASS"
|
expect_stdout: "PASS"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
issue_3598: {
|
||||||
|
options = {
|
||||||
|
collapse_vars: true,
|
||||||
|
reduce_vars: true,
|
||||||
|
unused: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
var a = "FAIL";
|
||||||
|
try {
|
||||||
|
(function() {
|
||||||
|
var b = void 0;
|
||||||
|
a = "PASS";
|
||||||
|
c.p = 0;
|
||||||
|
var c = b[!1];
|
||||||
|
})();
|
||||||
|
} catch (e) {}
|
||||||
|
console.log(a);
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
var a = "FAIL";
|
||||||
|
try {
|
||||||
|
(function() {
|
||||||
|
a = "PASS";
|
||||||
|
var c = (void (c.p = 0))[!1];
|
||||||
|
})();
|
||||||
|
} catch (e) {}
|
||||||
|
console.log(a);
|
||||||
|
}
|
||||||
|
expect_stdout: "PASS"
|
||||||
|
}
|
||||||
|
|
||||||
|
self_assign: {
|
||||||
|
options = {
|
||||||
|
passes: 2,
|
||||||
|
side_effects: true,
|
||||||
|
unused: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
function d(a) {
|
||||||
|
a = a;
|
||||||
|
}
|
||||||
|
function e(a, b) {
|
||||||
|
a = b;
|
||||||
|
b = a;
|
||||||
|
}
|
||||||
|
function f(a, b, c) {
|
||||||
|
a = b;
|
||||||
|
b = c;
|
||||||
|
c = a;
|
||||||
|
}
|
||||||
|
function g(a, b, c) {
|
||||||
|
a = a * b + c;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
function d(a) {}
|
||||||
|
function e(a, b) {}
|
||||||
|
function f(a, b, c) {}
|
||||||
|
function g(a, b, c) {}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function_argument_reference: {
|
||||||
|
options = {
|
||||||
|
keep_fargs: false,
|
||||||
|
side_effects: true,
|
||||||
|
unused: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
var a = 1, b = 42;
|
||||||
|
function f(a) {
|
||||||
|
b <<= a;
|
||||||
|
}
|
||||||
|
f();
|
||||||
|
console.log(a, b);
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
var a = 1, b = 42;
|
||||||
|
function f(a) {
|
||||||
|
b <<= a;
|
||||||
|
}
|
||||||
|
f();
|
||||||
|
console.log(a, b);
|
||||||
|
}
|
||||||
|
expect_stdout: "1 42"
|
||||||
|
}
|
||||||
|
|
||||||
|
function_parameter_ie8: {
|
||||||
|
options = {
|
||||||
|
ie8: true,
|
||||||
|
reduce_vars: true,
|
||||||
|
unused: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
(function() {
|
||||||
|
var a;
|
||||||
|
function f() {
|
||||||
|
console.log("PASS");
|
||||||
|
}
|
||||||
|
f(a = 1 + a);
|
||||||
|
})();
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
(function() {
|
||||||
|
(function f() {
|
||||||
|
console.log("PASS");
|
||||||
|
})(0);
|
||||||
|
})();
|
||||||
|
}
|
||||||
|
expect_stdout: "PASS"
|
||||||
|
}
|
||||||
|
|
||||||
|
issue_3664: {
|
||||||
|
options = {
|
||||||
|
pure_getters: "strict",
|
||||||
|
unused: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
console.log(function() {
|
||||||
|
var a, b = (a = (a = [ b && console.log("FAIL") ]).p = 0, 0);
|
||||||
|
return "PASS";
|
||||||
|
}());
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
console.log(function() {
|
||||||
|
var b = ([ b && console.log("FAIL") ].p = 0, 0);
|
||||||
|
return "PASS";
|
||||||
|
}());
|
||||||
|
}
|
||||||
|
expect_stdout: "PASS"
|
||||||
|
}
|
||||||
|
|
||||||
|
issue_3673: {
|
||||||
|
options = {
|
||||||
|
pure_getters: "strict",
|
||||||
|
side_effects: true,
|
||||||
|
toplevel: true,
|
||||||
|
unused: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
var a;
|
||||||
|
(a = [ a ]).p = 42;
|
||||||
|
console.log("PASS");
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
var a;
|
||||||
|
(a = [ a ]).p = 42;
|
||||||
|
console.log("PASS");
|
||||||
|
}
|
||||||
|
expect_stdout: "PASS"
|
||||||
|
}
|
||||||
|
|||||||
@@ -1876,3 +1876,288 @@ issue_3558: {
|
|||||||
}
|
}
|
||||||
expect_stdout: "1 0"
|
expect_stdout: "1 0"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
issue_3568: {
|
||||||
|
options = {
|
||||||
|
evaluate: true,
|
||||||
|
reduce_vars: true,
|
||||||
|
toplevel: true,
|
||||||
|
unsafe: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
var a = 0;
|
||||||
|
function f(b) {
|
||||||
|
return b && b.p;
|
||||||
|
}
|
||||||
|
console.log(f(++a + f()));
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
var a = 0;
|
||||||
|
function f(b) {
|
||||||
|
return b && b.p;
|
||||||
|
}
|
||||||
|
console.log(NaN);
|
||||||
|
}
|
||||||
|
expect_stdout: "NaN"
|
||||||
|
}
|
||||||
|
|
||||||
|
conditional_function: {
|
||||||
|
options = {
|
||||||
|
evaluate: true,
|
||||||
|
reduce_vars: true,
|
||||||
|
toplevel: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
function f(a) {
|
||||||
|
return a && "undefined" != typeof A ? A : 42;
|
||||||
|
}
|
||||||
|
console.log(f(0), f(1));
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
function f(a) {
|
||||||
|
return a && "undefined" != typeof A ? A : 42;
|
||||||
|
}
|
||||||
|
console.log(42, f(1));
|
||||||
|
}
|
||||||
|
expect_stdout: "42 42"
|
||||||
|
}
|
||||||
|
|
||||||
|
best_of_evaluate: {
|
||||||
|
options = {
|
||||||
|
evaluate: true,
|
||||||
|
reduce_vars: true,
|
||||||
|
toplevel: true,
|
||||||
|
unused: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
function d(x, y) {
|
||||||
|
return x / y;
|
||||||
|
}
|
||||||
|
console.log(0 / 3, 1 / 64, 4 / 7, 7 / 7);
|
||||||
|
console.log(d(0, 3), d(1, 64), d(4, 7), d(7, 7));
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
function d(x, y) {
|
||||||
|
return x / y;
|
||||||
|
}
|
||||||
|
console.log(0, 1 / 64, 4 / 7, 1);
|
||||||
|
console.log(0, .015625, d(4, 7), 1);
|
||||||
|
}
|
||||||
|
expect_stdout: [
|
||||||
|
"0 0.015625 0.5714285714285714 1",
|
||||||
|
"0 0.015625 0.5714285714285714 1",
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
|
eager_evaluate: {
|
||||||
|
options = {
|
||||||
|
evaluate: "eager",
|
||||||
|
reduce_vars: true,
|
||||||
|
toplevel: true,
|
||||||
|
unused: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
function d(x, y) {
|
||||||
|
return x / y;
|
||||||
|
}
|
||||||
|
console.log(0 / 3, 1 / 64, 4 / 7, 7 / 7);
|
||||||
|
console.log(d(0, 3), d(1, 64), d(4, 7), d(7, 7));
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
console.log(0, .015625, .5714285714285714, 1);
|
||||||
|
console.log(0, .015625, .5714285714285714, 1);
|
||||||
|
}
|
||||||
|
expect_stdout: [
|
||||||
|
"0 0.015625 0.5714285714285714 1",
|
||||||
|
"0 0.015625 0.5714285714285714 1",
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
|
threshold_evaluate_default: {
|
||||||
|
options = {
|
||||||
|
evaluate: true,
|
||||||
|
reduce_vars: true,
|
||||||
|
toplevel: true,
|
||||||
|
unused: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
function b(x) {
|
||||||
|
return x + x + x;
|
||||||
|
}
|
||||||
|
console.log(b("1"), b(2), b(b(b("ABCDEFGHIJK"))));
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
function b(x) {
|
||||||
|
return x + x + x;
|
||||||
|
}
|
||||||
|
console.log("111", 6, b(b(b("ABCDEFGHIJK"))));
|
||||||
|
}
|
||||||
|
expect_stdout: "111 6 ABCDEFGHIJKABCDEFGHIJKABCDEFGHIJKABCDEFGHIJKABCDEFGHIJKABCDEFGHIJKABCDEFGHIJKABCDEFGHIJKABCDEFGHIJKABCDEFGHIJKABCDEFGHIJKABCDEFGHIJKABCDEFGHIJKABCDEFGHIJKABCDEFGHIJKABCDEFGHIJKABCDEFGHIJKABCDEFGHIJKABCDEFGHIJKABCDEFGHIJKABCDEFGHIJKABCDEFGHIJKABCDEFGHIJKABCDEFGHIJKABCDEFGHIJKABCDEFGHIJKABCDEFGHIJK"
|
||||||
|
}
|
||||||
|
|
||||||
|
threshold_evaluate_30: {
|
||||||
|
options = {
|
||||||
|
evaluate: 30,
|
||||||
|
reduce_vars: true,
|
||||||
|
toplevel: true,
|
||||||
|
unused: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
function b(x) {
|
||||||
|
return x + x + x;
|
||||||
|
}
|
||||||
|
console.log(b("1"), b(2), b(b(b("ABCDEFGHIJK"))));
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
function b(x) {
|
||||||
|
return x + x + x;
|
||||||
|
}
|
||||||
|
console.log("111", 6, b(b("ABCDEFGHIJKABCDEFGHIJKABCDEFGHIJK")));
|
||||||
|
}
|
||||||
|
expect_stdout: "111 6 ABCDEFGHIJKABCDEFGHIJKABCDEFGHIJKABCDEFGHIJKABCDEFGHIJKABCDEFGHIJKABCDEFGHIJKABCDEFGHIJKABCDEFGHIJKABCDEFGHIJKABCDEFGHIJKABCDEFGHIJKABCDEFGHIJKABCDEFGHIJKABCDEFGHIJKABCDEFGHIJKABCDEFGHIJKABCDEFGHIJKABCDEFGHIJKABCDEFGHIJKABCDEFGHIJKABCDEFGHIJKABCDEFGHIJKABCDEFGHIJKABCDEFGHIJKABCDEFGHIJKABCDEFGHIJK"
|
||||||
|
}
|
||||||
|
|
||||||
|
threshold_evaluate_100: {
|
||||||
|
options = {
|
||||||
|
evaluate: 100,
|
||||||
|
reduce_vars: true,
|
||||||
|
toplevel: true,
|
||||||
|
unused: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
function b(x) {
|
||||||
|
return x + x + x;
|
||||||
|
}
|
||||||
|
console.log(b("1"), b(2), b(b(b("ABCDEFGHIJK"))));
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
function b(x) {
|
||||||
|
return x + x + x;
|
||||||
|
}
|
||||||
|
console.log("111", 6, b("ABCDEFGHIJKABCDEFGHIJKABCDEFGHIJKABCDEFGHIJKABCDEFGHIJKABCDEFGHIJKABCDEFGHIJKABCDEFGHIJKABCDEFGHIJK"));
|
||||||
|
}
|
||||||
|
expect_stdout: "111 6 ABCDEFGHIJKABCDEFGHIJKABCDEFGHIJKABCDEFGHIJKABCDEFGHIJKABCDEFGHIJKABCDEFGHIJKABCDEFGHIJKABCDEFGHIJKABCDEFGHIJKABCDEFGHIJKABCDEFGHIJKABCDEFGHIJKABCDEFGHIJKABCDEFGHIJKABCDEFGHIJKABCDEFGHIJKABCDEFGHIJKABCDEFGHIJKABCDEFGHIJKABCDEFGHIJKABCDEFGHIJKABCDEFGHIJKABCDEFGHIJKABCDEFGHIJKABCDEFGHIJKABCDEFGHIJK"
|
||||||
|
}
|
||||||
|
|
||||||
|
threshold_evaluate_999: {
|
||||||
|
options = {
|
||||||
|
evaluate: 999,
|
||||||
|
reduce_vars: true,
|
||||||
|
toplevel: true,
|
||||||
|
unused: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
function b(x) {
|
||||||
|
return x + x + x;
|
||||||
|
}
|
||||||
|
console.log(b("1"), b(2), b(b(b("ABCDEFGHIJK"))));
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
console.log("111", 6, "ABCDEFGHIJKABCDEFGHIJKABCDEFGHIJKABCDEFGHIJKABCDEFGHIJKABCDEFGHIJKABCDEFGHIJKABCDEFGHIJKABCDEFGHIJKABCDEFGHIJKABCDEFGHIJKABCDEFGHIJKABCDEFGHIJKABCDEFGHIJKABCDEFGHIJKABCDEFGHIJKABCDEFGHIJKABCDEFGHIJKABCDEFGHIJKABCDEFGHIJKABCDEFGHIJKABCDEFGHIJKABCDEFGHIJKABCDEFGHIJKABCDEFGHIJKABCDEFGHIJKABCDEFGHIJK");
|
||||||
|
}
|
||||||
|
expect_stdout: "111 6 ABCDEFGHIJKABCDEFGHIJKABCDEFGHIJKABCDEFGHIJKABCDEFGHIJKABCDEFGHIJKABCDEFGHIJKABCDEFGHIJKABCDEFGHIJKABCDEFGHIJKABCDEFGHIJKABCDEFGHIJKABCDEFGHIJKABCDEFGHIJKABCDEFGHIJKABCDEFGHIJKABCDEFGHIJKABCDEFGHIJKABCDEFGHIJKABCDEFGHIJKABCDEFGHIJKABCDEFGHIJKABCDEFGHIJKABCDEFGHIJKABCDEFGHIJKABCDEFGHIJKABCDEFGHIJK"
|
||||||
|
}
|
||||||
|
|
||||||
|
collapse_vars_regexp: {
|
||||||
|
options = {
|
||||||
|
booleans: true,
|
||||||
|
collapse_vars: true,
|
||||||
|
comparisons: true,
|
||||||
|
conditionals: true,
|
||||||
|
dead_code: true,
|
||||||
|
evaluate: true,
|
||||||
|
hoist_funs: true,
|
||||||
|
if_return: true,
|
||||||
|
join_vars: true,
|
||||||
|
keep_fargs: true,
|
||||||
|
loops: false,
|
||||||
|
reduce_funcs: true,
|
||||||
|
reduce_vars: true,
|
||||||
|
side_effects: true,
|
||||||
|
unsafe_regexp: true,
|
||||||
|
unused: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
function f1() {
|
||||||
|
var k = 9;
|
||||||
|
var rx = /[A-Z]+/;
|
||||||
|
return [rx, k];
|
||||||
|
}
|
||||||
|
function f2() {
|
||||||
|
var rx = /ab*/g;
|
||||||
|
return function(s) {
|
||||||
|
return rx.exec(s);
|
||||||
|
};
|
||||||
|
}
|
||||||
|
function f3() {
|
||||||
|
var rx = /ab*/g;
|
||||||
|
return function() {
|
||||||
|
return rx;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
(function() {
|
||||||
|
var result;
|
||||||
|
var s = "acdabcdeabbb";
|
||||||
|
var rx = /ab*/g;
|
||||||
|
while (result = rx.exec(s))
|
||||||
|
console.log(result[0]);
|
||||||
|
})();
|
||||||
|
(function() {
|
||||||
|
var result;
|
||||||
|
var s = "acdabcdeabbb";
|
||||||
|
var rx = f2();
|
||||||
|
while (result = rx(s))
|
||||||
|
console.log(result[0]);
|
||||||
|
})();
|
||||||
|
(function() {
|
||||||
|
var result;
|
||||||
|
var s = "acdabcdeabbb";
|
||||||
|
var rx = f3();
|
||||||
|
while (result = rx().exec(s))
|
||||||
|
console.log(result[0]);
|
||||||
|
})();
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
function f1() {
|
||||||
|
return [/[A-Z]+/, 9];
|
||||||
|
}
|
||||||
|
function f2() {
|
||||||
|
var rx = /ab*/g;
|
||||||
|
return function(s) {
|
||||||
|
return rx.exec(s);
|
||||||
|
};
|
||||||
|
}
|
||||||
|
function f3() {
|
||||||
|
var rx = /ab*/g;
|
||||||
|
return function() {
|
||||||
|
return rx;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
(function() {
|
||||||
|
var result, rx = /ab*/g;
|
||||||
|
while (result = rx.exec("acdabcdeabbb"))
|
||||||
|
console.log(result[0]);
|
||||||
|
})();
|
||||||
|
(function() {
|
||||||
|
var result, rx = f2();
|
||||||
|
while (result = rx("acdabcdeabbb"))
|
||||||
|
console.log(result[0]);
|
||||||
|
})();
|
||||||
|
(function() {
|
||||||
|
var result, rx = f3();
|
||||||
|
while (result = rx().exec("acdabcdeabbb"))
|
||||||
|
console.log(result[0]);
|
||||||
|
})();
|
||||||
|
}
|
||||||
|
expect_stdout: [
|
||||||
|
"a",
|
||||||
|
"ab",
|
||||||
|
"abbb",
|
||||||
|
"a",
|
||||||
|
"ab",
|
||||||
|
"abbb",
|
||||||
|
"a",
|
||||||
|
"ab",
|
||||||
|
"abbb",
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|||||||
@@ -266,12 +266,7 @@ issue_2084: {
|
|||||||
}
|
}
|
||||||
expect: {
|
expect: {
|
||||||
var c = 0;
|
var c = 0;
|
||||||
!function() {
|
23..toString(),
|
||||||
var c;
|
|
||||||
c = 1 + (c = -1),
|
|
||||||
c = 1 + (c = 0),
|
|
||||||
0 !== 23..toString() && (c = 1 + c);
|
|
||||||
}(),
|
|
||||||
console.log(c);
|
console.log(c);
|
||||||
}
|
}
|
||||||
expect_stdout: "0"
|
expect_stdout: "0"
|
||||||
@@ -2004,57 +1999,6 @@ deduplicate_parenthesis: {
|
|||||||
expect_exact: "({}).a=b;({}.a=b)();(function(){}).a=b;(function(){}.a=b)();"
|
expect_exact: "({}).a=b;({}.a=b)();(function(){}).a=b;(function(){}.a=b)();"
|
||||||
}
|
}
|
||||||
|
|
||||||
drop_lone_use_strict: {
|
|
||||||
options = {
|
|
||||||
directives: true,
|
|
||||||
side_effects: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
function f1() {
|
|
||||||
"use strict";
|
|
||||||
}
|
|
||||||
function f2() {
|
|
||||||
"use strict";
|
|
||||||
function f3() {
|
|
||||||
"use strict";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
(function f4() {
|
|
||||||
"use strict";
|
|
||||||
})();
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
function f1() {
|
|
||||||
}
|
|
||||||
function f2() {
|
|
||||||
"use strict";
|
|
||||||
function f3() {
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
issue_3166: {
|
|
||||||
options = {
|
|
||||||
directives: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
"foo";
|
|
||||||
"use strict";
|
|
||||||
function f() {
|
|
||||||
"use strict";
|
|
||||||
"bar";
|
|
||||||
"use asm";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
"use strict";
|
|
||||||
function f() {
|
|
||||||
"use asm";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
issue_3016_1: {
|
issue_3016_1: {
|
||||||
options = {
|
options = {
|
||||||
inline: true,
|
inline: true,
|
||||||
@@ -2265,7 +2209,8 @@ issue_3054: {
|
|||||||
return { a: !0 };
|
return { a: !0 };
|
||||||
}
|
}
|
||||||
console.log(function(b) {
|
console.log(function(b) {
|
||||||
return { a: !(b = !1) };
|
b = !1;
|
||||||
|
return f();
|
||||||
}().a, f.call().a);
|
}().a, f.call().a);
|
||||||
}
|
}
|
||||||
expect_stdout: "true true"
|
expect_stdout: "true true"
|
||||||
@@ -2345,7 +2290,7 @@ issue_3274: {
|
|||||||
}
|
}
|
||||||
expect: {
|
expect: {
|
||||||
(function() {
|
(function() {
|
||||||
for (var c; void 0, (c = 1..p) != c;)
|
for (var c; (c = 1..p) != c;)
|
||||||
console.log("FAIL");
|
console.log("FAIL");
|
||||||
console.log("PASS");
|
console.log("PASS");
|
||||||
})();
|
})();
|
||||||
@@ -2513,18 +2458,21 @@ issue_3297_3: {
|
|||||||
}).processBulk([1, 2, 3]);
|
}).processBulk([1, 2, 3]);
|
||||||
}
|
}
|
||||||
expect: {
|
expect: {
|
||||||
function function1(u) {
|
function function1(c) {
|
||||||
return {
|
return {
|
||||||
processBulk: function n(r) {
|
processBulk: function n(o) {
|
||||||
var o, t = u();
|
var r, t, u = c();
|
||||||
r && 0 < r.length && (o = {
|
o && 0 < o.length && (r = {
|
||||||
param1: r.shift(),
|
param1: o.shift(),
|
||||||
param2: {
|
param2: {
|
||||||
subparam1: t
|
subparam1: u
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
console.log(JSON.stringify(o)),
|
t = function() {
|
||||||
n(r));
|
n(o);
|
||||||
|
},
|
||||||
|
console.log(JSON.stringify(r)),
|
||||||
|
t());
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@@ -3096,8 +3044,7 @@ issue_3400_1: {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
expect: {
|
expect: {
|
||||||
void console.log(function() {
|
void console.log(function g() {
|
||||||
function g() {
|
|
||||||
function h(u) {
|
function h(u) {
|
||||||
var o = {
|
var o = {
|
||||||
p: u
|
p: u
|
||||||
@@ -3110,9 +3057,7 @@ issue_3400_1: {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
return e();
|
return e();
|
||||||
}
|
}()[0].p);
|
||||||
return g;
|
|
||||||
}()()[0].p);
|
|
||||||
}
|
}
|
||||||
expect_stdout: [
|
expect_stdout: [
|
||||||
"undefined",
|
"undefined",
|
||||||
@@ -3153,12 +3098,10 @@ issue_3400_2: {
|
|||||||
expect: {
|
expect: {
|
||||||
void console.log(function g() {
|
void console.log(function g() {
|
||||||
return [ 42 ].map(function(v) {
|
return [ 42 ].map(function(v) {
|
||||||
return function(u) {
|
return o = {
|
||||||
var o = {
|
p: v
|
||||||
p: u
|
}, console.log(o[g]), o;
|
||||||
};
|
var o;
|
||||||
return console.log(o[g]), o;
|
|
||||||
}(v);
|
|
||||||
});
|
});
|
||||||
}()[0].p);
|
}()[0].p);
|
||||||
}
|
}
|
||||||
@@ -3400,3 +3343,445 @@ issue_3562: {
|
|||||||
}
|
}
|
||||||
expect_stdout: "PASS"
|
expect_stdout: "PASS"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
hoisted_inline: {
|
||||||
|
options = {
|
||||||
|
inline: true,
|
||||||
|
reduce_vars: true,
|
||||||
|
toplevel: true,
|
||||||
|
unused: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
function f() {
|
||||||
|
console.log("PASS");
|
||||||
|
}
|
||||||
|
function g() {
|
||||||
|
for (var console in [ 0 ])
|
||||||
|
h();
|
||||||
|
}
|
||||||
|
function h() {
|
||||||
|
f();
|
||||||
|
}
|
||||||
|
g();
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
function f() {
|
||||||
|
console.log("PASS");
|
||||||
|
}
|
||||||
|
(function() {
|
||||||
|
for (var console in [ 0 ])
|
||||||
|
void f();
|
||||||
|
})();
|
||||||
|
}
|
||||||
|
expect_stdout: "PASS"
|
||||||
|
}
|
||||||
|
|
||||||
|
hoisted_single_use: {
|
||||||
|
options = {
|
||||||
|
reduce_funcs: true,
|
||||||
|
reduce_vars: true,
|
||||||
|
toplevel: true,
|
||||||
|
unused: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
function f(a) {
|
||||||
|
for (var r in a) g(r);
|
||||||
|
}
|
||||||
|
function g(a) {
|
||||||
|
console.log(a);
|
||||||
|
}
|
||||||
|
function h(a) {
|
||||||
|
var g = a.bar;
|
||||||
|
g();
|
||||||
|
g();
|
||||||
|
i(a);
|
||||||
|
}
|
||||||
|
function i(b) {
|
||||||
|
f(b);
|
||||||
|
}
|
||||||
|
h({
|
||||||
|
bar: function() {
|
||||||
|
console.log("foo");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
function f(a) {
|
||||||
|
for (var r in a) g(r);
|
||||||
|
}
|
||||||
|
function g(a) {
|
||||||
|
console.log(a);
|
||||||
|
}
|
||||||
|
(function(a) {
|
||||||
|
var g = a.bar;
|
||||||
|
g();
|
||||||
|
g();
|
||||||
|
(function(b) {
|
||||||
|
f(b);
|
||||||
|
})(a);
|
||||||
|
})({
|
||||||
|
bar: function() {
|
||||||
|
console.log("foo");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
expect_stdout: [
|
||||||
|
"foo",
|
||||||
|
"foo",
|
||||||
|
"bar",
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
|
pr_3592_1: {
|
||||||
|
options = {
|
||||||
|
inline: true,
|
||||||
|
reduce_funcs: false,
|
||||||
|
reduce_vars: true,
|
||||||
|
toplevel: true,
|
||||||
|
unused: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
function problem(w) {
|
||||||
|
return g.indexOf(w);
|
||||||
|
}
|
||||||
|
function unused(x) {
|
||||||
|
return problem(x);
|
||||||
|
}
|
||||||
|
function B(problem) {
|
||||||
|
return g[problem];
|
||||||
|
}
|
||||||
|
function A(y) {
|
||||||
|
return problem(y);
|
||||||
|
}
|
||||||
|
function main(z) {
|
||||||
|
return B(A(z));
|
||||||
|
}
|
||||||
|
var g = [ "PASS" ];
|
||||||
|
console.log(main("PASS"));
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
function problem(w) {
|
||||||
|
return g.indexOf(w);
|
||||||
|
}
|
||||||
|
function B(problem) {
|
||||||
|
return g[problem];
|
||||||
|
}
|
||||||
|
var g = [ "PASS" ];
|
||||||
|
console.log((z = "PASS", B((y = z, problem(y)))));
|
||||||
|
var z, y;
|
||||||
|
}
|
||||||
|
expect_stdout: "PASS"
|
||||||
|
}
|
||||||
|
|
||||||
|
pr_3592_2: {
|
||||||
|
options = {
|
||||||
|
inline: true,
|
||||||
|
reduce_funcs: true,
|
||||||
|
reduce_vars: true,
|
||||||
|
toplevel: true,
|
||||||
|
unused: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
function problem(w) {
|
||||||
|
return g.indexOf(w);
|
||||||
|
}
|
||||||
|
function unused(x) {
|
||||||
|
return problem(x);
|
||||||
|
}
|
||||||
|
function B(problem) {
|
||||||
|
return g[problem];
|
||||||
|
}
|
||||||
|
function A(y) {
|
||||||
|
return problem(y);
|
||||||
|
}
|
||||||
|
function main(z) {
|
||||||
|
return B(A(z));
|
||||||
|
}
|
||||||
|
var g = [ "PASS" ];
|
||||||
|
console.log(main("PASS"));
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
function problem(w) {
|
||||||
|
return g.indexOf(w);
|
||||||
|
}
|
||||||
|
var g = [ "PASS" ];
|
||||||
|
console.log((z = "PASS", function(problem) {
|
||||||
|
return g[problem];
|
||||||
|
}((y = z, problem(y)))));
|
||||||
|
var z, y;
|
||||||
|
}
|
||||||
|
expect_stdout: "PASS"
|
||||||
|
}
|
||||||
|
|
||||||
|
inline_use_strict: {
|
||||||
|
options = {
|
||||||
|
evaluate: true,
|
||||||
|
inline: true,
|
||||||
|
reduce_vars: true,
|
||||||
|
sequences: true,
|
||||||
|
side_effects: true,
|
||||||
|
unused: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
console.log(function() {
|
||||||
|
"use strict";
|
||||||
|
return function() {
|
||||||
|
"use strict";
|
||||||
|
var a = "foo";
|
||||||
|
a += "bar";
|
||||||
|
return a;
|
||||||
|
};
|
||||||
|
}()());
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
console.log("foobar");
|
||||||
|
}
|
||||||
|
expect_stdout: "foobar"
|
||||||
|
}
|
||||||
|
|
||||||
|
pr_3595_1: {
|
||||||
|
options = {
|
||||||
|
collapse_vars: false,
|
||||||
|
inline: true,
|
||||||
|
reduce_funcs: true,
|
||||||
|
reduce_vars: true,
|
||||||
|
toplevel: true,
|
||||||
|
unused: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
var g = [ "PASS" ];
|
||||||
|
function problem(arg) {
|
||||||
|
return g.indexOf(arg);
|
||||||
|
}
|
||||||
|
function unused(arg) {
|
||||||
|
return problem(arg);
|
||||||
|
}
|
||||||
|
function a(arg) {
|
||||||
|
return problem(arg);
|
||||||
|
}
|
||||||
|
function b(problem) {
|
||||||
|
return g[problem];
|
||||||
|
}
|
||||||
|
function c(arg) {
|
||||||
|
return b(a(arg));
|
||||||
|
}
|
||||||
|
console.log(c("PASS"));
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
var g = [ "PASS" ];
|
||||||
|
function problem(arg) {
|
||||||
|
return g.indexOf(arg);
|
||||||
|
}
|
||||||
|
console.log((arg = "PASS", function(problem) {
|
||||||
|
return g[problem];
|
||||||
|
}(function(arg) {
|
||||||
|
return problem(arg);
|
||||||
|
}(arg))));
|
||||||
|
var arg;
|
||||||
|
}
|
||||||
|
expect_stdout: "PASS"
|
||||||
|
}
|
||||||
|
|
||||||
|
pr_3595_2: {
|
||||||
|
options = {
|
||||||
|
collapse_vars: true,
|
||||||
|
inline: true,
|
||||||
|
reduce_funcs: true,
|
||||||
|
reduce_vars: true,
|
||||||
|
toplevel: true,
|
||||||
|
unused: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
var g = [ "PASS" ];
|
||||||
|
function problem(arg) {
|
||||||
|
return g.indexOf(arg);
|
||||||
|
}
|
||||||
|
function unused(arg) {
|
||||||
|
return problem(arg);
|
||||||
|
}
|
||||||
|
function a(arg) {
|
||||||
|
return problem(arg);
|
||||||
|
}
|
||||||
|
function b(problem) {
|
||||||
|
return g[problem];
|
||||||
|
}
|
||||||
|
function c(arg) {
|
||||||
|
return b(a(arg));
|
||||||
|
}
|
||||||
|
console.log(c("PASS"));
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
var g = [ "PASS" ];
|
||||||
|
function problem(arg) {
|
||||||
|
return g.indexOf(arg);
|
||||||
|
}
|
||||||
|
console.log(function(problem) {
|
||||||
|
return g[problem];
|
||||||
|
}(function(arg) {
|
||||||
|
return problem(arg);
|
||||||
|
}("PASS")));
|
||||||
|
}
|
||||||
|
expect_stdout: "PASS"
|
||||||
|
}
|
||||||
|
|
||||||
|
pr_3595_3: {
|
||||||
|
options = {
|
||||||
|
collapse_vars: true,
|
||||||
|
inline: true,
|
||||||
|
passes: 2,
|
||||||
|
reduce_funcs: true,
|
||||||
|
reduce_vars: true,
|
||||||
|
toplevel: true,
|
||||||
|
unused: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
var g = [ "PASS" ];
|
||||||
|
function problem(arg) {
|
||||||
|
return g.indexOf(arg);
|
||||||
|
}
|
||||||
|
function unused(arg) {
|
||||||
|
return problem(arg);
|
||||||
|
}
|
||||||
|
function a(arg) {
|
||||||
|
return problem(arg);
|
||||||
|
}
|
||||||
|
function b(problem) {
|
||||||
|
return g[problem];
|
||||||
|
}
|
||||||
|
function c(arg) {
|
||||||
|
return b(a(arg));
|
||||||
|
}
|
||||||
|
console.log(c("PASS"));
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
var g = [ "PASS" ];
|
||||||
|
console.log(function(problem) {
|
||||||
|
return g[problem];
|
||||||
|
}(function(arg) {
|
||||||
|
return g.indexOf(arg);
|
||||||
|
}("PASS")));
|
||||||
|
}
|
||||||
|
expect_stdout: "PASS"
|
||||||
|
}
|
||||||
|
|
||||||
|
pr_3595_4: {
|
||||||
|
options = {
|
||||||
|
collapse_vars: true,
|
||||||
|
inline: true,
|
||||||
|
passes: 3,
|
||||||
|
reduce_funcs: true,
|
||||||
|
reduce_vars: true,
|
||||||
|
toplevel: true,
|
||||||
|
unused: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
var g = [ "PASS" ];
|
||||||
|
function problem(arg) {
|
||||||
|
return g.indexOf(arg);
|
||||||
|
}
|
||||||
|
function unused(arg) {
|
||||||
|
return problem(arg);
|
||||||
|
}
|
||||||
|
function a(arg) {
|
||||||
|
return problem(arg);
|
||||||
|
}
|
||||||
|
function b(problem) {
|
||||||
|
return g[problem];
|
||||||
|
}
|
||||||
|
function c(arg) {
|
||||||
|
return b(a(arg));
|
||||||
|
}
|
||||||
|
console.log(c("PASS"));
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
var g = [ "PASS" ];
|
||||||
|
console.log((problem = g.indexOf("PASS"), g[problem]));
|
||||||
|
var problem;
|
||||||
|
}
|
||||||
|
expect_stdout: "PASS"
|
||||||
|
}
|
||||||
|
|
||||||
|
issue_3679_1: {
|
||||||
|
options = {
|
||||||
|
collapse_vars: true,
|
||||||
|
inline: true,
|
||||||
|
pure_getters: "strict",
|
||||||
|
reduce_vars: true,
|
||||||
|
side_effects: true,
|
||||||
|
unused: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
(function() {
|
||||||
|
var f = function() {};
|
||||||
|
f.g = function() {
|
||||||
|
console.log("PASS");
|
||||||
|
};
|
||||||
|
f.g();
|
||||||
|
})();
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
console.log("PASS");
|
||||||
|
}
|
||||||
|
expect_stdout: "PASS"
|
||||||
|
}
|
||||||
|
|
||||||
|
issue_3679_2: {
|
||||||
|
options = {
|
||||||
|
collapse_vars: true,
|
||||||
|
inline: true,
|
||||||
|
passes: 2,
|
||||||
|
pure_getters: "strict",
|
||||||
|
reduce_vars: true,
|
||||||
|
side_effects: true,
|
||||||
|
unused: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
(function() {
|
||||||
|
"use strict";
|
||||||
|
var f = function() {};
|
||||||
|
f.g = function() {
|
||||||
|
console.log("PASS");
|
||||||
|
};
|
||||||
|
f.g();
|
||||||
|
})();
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
(function() {
|
||||||
|
"use strict";
|
||||||
|
console.log("PASS");
|
||||||
|
})();
|
||||||
|
}
|
||||||
|
expect_stdout: "PASS"
|
||||||
|
}
|
||||||
|
|
||||||
|
issue_3679_3: {
|
||||||
|
options = {
|
||||||
|
collapse_vars: true,
|
||||||
|
inline: true,
|
||||||
|
functions: true,
|
||||||
|
pure_getters: "strict",
|
||||||
|
reduce_vars: true,
|
||||||
|
side_effects: true,
|
||||||
|
unused: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
(function() {
|
||||||
|
var f = function() {};
|
||||||
|
f.p = "PASS";
|
||||||
|
f.g = function() {
|
||||||
|
console.log(f.p);
|
||||||
|
};
|
||||||
|
f.g();
|
||||||
|
})();
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
(function() {
|
||||||
|
function f() {};
|
||||||
|
f.p = "PASS";
|
||||||
|
(f.g = function() {
|
||||||
|
console.log(f.p);
|
||||||
|
})();
|
||||||
|
})();
|
||||||
|
}
|
||||||
|
expect_stdout: "PASS"
|
||||||
|
}
|
||||||
|
|||||||
@@ -664,7 +664,7 @@ issue_2519: {
|
|||||||
}
|
}
|
||||||
expect: {
|
expect: {
|
||||||
function testFunc() {
|
function testFunc() {
|
||||||
return 1 * ((6 + 5) / 2);
|
return +((6 + 5) / 2);
|
||||||
}
|
}
|
||||||
console.log(testFunc());
|
console.log(testFunc());
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,55 +1,107 @@
|
|||||||
html_comment_in_expression: {
|
html_comment_in_expression: {
|
||||||
input: {
|
input: {
|
||||||
function f(a, b, x, y) { return a < !--b && x-- > y; }
|
(function(a, b) {
|
||||||
|
console.log(a < !--b && a-- > b, a, b);
|
||||||
|
})(1, 2);
|
||||||
}
|
}
|
||||||
expect_exact: "function f(a,b,x,y){return a< !--b&&x-- >y}";
|
expect_exact: "(function(a,b){console.log(a<! --b&&a-- >b,a,b)})(1,2);"
|
||||||
|
expect_stdout: "false 1 1"
|
||||||
}
|
}
|
||||||
|
|
||||||
html_comment_in_less_than: {
|
html_comment_in_less_than: {
|
||||||
input: {
|
input: {
|
||||||
function f(a, b) { return a < !--b; }
|
(function(a, b, c) {
|
||||||
|
console.log(
|
||||||
|
a < !--b,
|
||||||
|
a < !--b + c,
|
||||||
|
a + b < !--c,
|
||||||
|
a, b, c
|
||||||
|
);
|
||||||
|
})(1, 2, 3);
|
||||||
}
|
}
|
||||||
expect_exact: "function f(a,b){return a< !--b}";
|
expect_exact: "(function(a,b,c){console.log(a<! --b,a<! --b+c,a+b<! --c,a,b,c)})(1,2,3);"
|
||||||
|
expect_stdout: "false true false 1 0 2"
|
||||||
}
|
}
|
||||||
|
|
||||||
html_comment_in_left_shift: {
|
html_comment_in_left_shift: {
|
||||||
input: {
|
input: {
|
||||||
function f(a, b) { return a << !--b; }
|
(function(a, b, c) {
|
||||||
|
console.log(
|
||||||
|
a << !--b,
|
||||||
|
a << !--b + c,
|
||||||
|
a + b << !--c,
|
||||||
|
a, b, c
|
||||||
|
);
|
||||||
|
})(1, 2, 3);
|
||||||
}
|
}
|
||||||
expect_exact: "function f(a,b){return a<< !--b}";
|
expect_exact: "(function(a,b,c){console.log(a<<! --b,a<<! --b+c,a+b<<! --c,a,b,c)})(1,2,3);"
|
||||||
}
|
expect_stdout: "1 16 1 1 0 2"
|
||||||
|
|
||||||
html_comment_in_right_shift: {
|
|
||||||
input: {
|
|
||||||
function f(a, b) { return a-- >> b; }
|
|
||||||
}
|
|
||||||
expect_exact: "function f(a,b){return a-- >>b}";
|
|
||||||
}
|
|
||||||
|
|
||||||
html_comment_in_zero_fill_right_shift: {
|
|
||||||
input: {
|
|
||||||
function f(a, b) { return a-- >>> b; }
|
|
||||||
}
|
|
||||||
expect_exact: "function f(a,b){return a-- >>>b}";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
html_comment_in_greater_than: {
|
html_comment_in_greater_than: {
|
||||||
input: {
|
input: {
|
||||||
function f(a, b) { return a-- > b; }
|
(function(a, b, c) {
|
||||||
|
console.log(
|
||||||
|
a-- > b,
|
||||||
|
a-- > b + c,
|
||||||
|
a + b-- > c,
|
||||||
|
a, b, c
|
||||||
|
);
|
||||||
|
})(1, 2, 3);
|
||||||
}
|
}
|
||||||
expect_exact: "function f(a,b){return a-- >b}";
|
expect_exact: "(function(a,b,c){console.log(a-- >b,a-- >b+c,a+b-- >c,a,b,c)})(1,2,3);"
|
||||||
|
expect_stdout: "false false false -1 1 3"
|
||||||
}
|
}
|
||||||
|
|
||||||
html_comment_in_greater_than_or_equal: {
|
html_comment_in_greater_than_or_equal: {
|
||||||
input: {
|
input: {
|
||||||
function f(a, b) { return a-- >= b; }
|
(function(a, b, c) {
|
||||||
|
console.log(
|
||||||
|
a-- >= b,
|
||||||
|
a-- >= b + c,
|
||||||
|
a + b-- >= c,
|
||||||
|
a, b, c
|
||||||
|
);
|
||||||
|
})(1, 2, 3);
|
||||||
}
|
}
|
||||||
expect_exact: "function f(a,b){return a-- >=b}";
|
expect_exact: "(function(a,b,c){console.log(a-- >=b,a-- >=b+c,a+b-- >=c,a,b,c)})(1,2,3);"
|
||||||
|
expect_stdout: "false false false -1 1 3"
|
||||||
|
}
|
||||||
|
|
||||||
|
html_comment_in_right_shift: {
|
||||||
|
input: {
|
||||||
|
(function(a, b, c) {
|
||||||
|
console.log(
|
||||||
|
a-- >> b,
|
||||||
|
a-- >> b + c,
|
||||||
|
a + b-- >> c,
|
||||||
|
a, b, c
|
||||||
|
);
|
||||||
|
})(1, 2, 3);
|
||||||
|
}
|
||||||
|
expect_exact: "(function(a,b,c){console.log(a-- >>b,a-- >>b+c,a+b-- >>c,a,b,c)})(1,2,3);"
|
||||||
|
expect_stdout: "0 0 0 -1 1 3"
|
||||||
|
}
|
||||||
|
|
||||||
|
html_comment_in_zero_fill_right_shift: {
|
||||||
|
input: {
|
||||||
|
(function(a, b, c) {
|
||||||
|
console.log(
|
||||||
|
a-- >>> b,
|
||||||
|
a-- >>> b + c,
|
||||||
|
a + b-- >>> c,
|
||||||
|
a, b, c
|
||||||
|
);
|
||||||
|
})(1, 2, 3);
|
||||||
|
}
|
||||||
|
expect_exact: "(function(a,b,c){console.log(a-- >>>b,a-- >>>b+c,a+b-- >>>c,a,b,c)})(1,2,3);"
|
||||||
|
expect_stdout: "0 0 0 -1 1 3"
|
||||||
}
|
}
|
||||||
|
|
||||||
html_comment_in_string_literal: {
|
html_comment_in_string_literal: {
|
||||||
input: {
|
input: {
|
||||||
function f() { return "<!--HTML-->comment in<!--string literal-->"; }
|
console.log("<!--HTML-->comment in<!--string literal-->".length);
|
||||||
}
|
}
|
||||||
expect_exact: 'function f(){return"\\x3c!--HTML--\\x3ecomment in\\x3c!--string literal--\\x3e"}';
|
expect_exact: 'console.log("\\x3c!--HTML--\\x3ecomment in\\x3c!--string literal--\\x3e".length);'
|
||||||
|
expect_stdout: "42"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -544,3 +544,32 @@ if_body_return_3: {
|
|||||||
"PASS",
|
"PASS",
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
issue_3600: {
|
||||||
|
options = {
|
||||||
|
if_return: true,
|
||||||
|
inline: true,
|
||||||
|
side_effects: true,
|
||||||
|
unused: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
var c = 0;
|
||||||
|
(function() {
|
||||||
|
if ([ ][c++]); else return;
|
||||||
|
return void function() {
|
||||||
|
var b = --b, a = c = 42;
|
||||||
|
return c;
|
||||||
|
}();
|
||||||
|
})();
|
||||||
|
console.log(c);
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
var c = 0;
|
||||||
|
(function() {
|
||||||
|
if ([][c++]) b = --b, c = 42;
|
||||||
|
var b;
|
||||||
|
})();
|
||||||
|
console.log(c);
|
||||||
|
}
|
||||||
|
expect_stdout: "1"
|
||||||
|
}
|
||||||
|
|||||||
@@ -30,7 +30,7 @@ non_hoisted_function_after_return: {
|
|||||||
}
|
}
|
||||||
expect: {
|
expect: {
|
||||||
function foo(x) {
|
function foo(x) {
|
||||||
return x ? bar() : baz();
|
return (x ? bar : baz)();
|
||||||
function bar() { return 7 }
|
function bar() { return 7 }
|
||||||
function baz() { return 8 }
|
function baz() { return 8 }
|
||||||
}
|
}
|
||||||
@@ -181,7 +181,7 @@ non_hoisted_function_after_return_strict: {
|
|||||||
expect: {
|
expect: {
|
||||||
"use strict";
|
"use strict";
|
||||||
function foo(x) {
|
function foo(x) {
|
||||||
return x ? bar() : baz();
|
return (x ? bar : baz)();
|
||||||
function bar() { return 7 }
|
function bar() { return 7 }
|
||||||
function baz() { return 8 }
|
function baz() { return 8 }
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -52,3 +52,30 @@ chained_evaluation_2: {
|
|||||||
})();
|
})();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
chained_evaluation_3: {
|
||||||
|
options = {
|
||||||
|
collapse_vars: true,
|
||||||
|
evaluate: 10,
|
||||||
|
reduce_funcs: true,
|
||||||
|
reduce_vars: true,
|
||||||
|
unused: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
(function() {
|
||||||
|
var a = "long piece of string";
|
||||||
|
(function() {
|
||||||
|
var b = a, c;
|
||||||
|
c = f(b);
|
||||||
|
c.bar = b;
|
||||||
|
})();
|
||||||
|
})();
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
(function() {
|
||||||
|
(function() {
|
||||||
|
f("long piece of string").bar = "long piece of string";
|
||||||
|
})();
|
||||||
|
})();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ cond_5: {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
expect: {
|
expect: {
|
||||||
some_condition() && some_other_condition() ? do_something() : alternate();
|
(some_condition() && some_other_condition() ? do_something : alternate)();
|
||||||
if (some_condition() && some_other_condition()) do_something();
|
if (some_condition() && some_other_condition()) do_something();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -873,13 +873,13 @@ iife_func_side_effects: {
|
|||||||
function z() {
|
function z() {
|
||||||
console.log("z");
|
console.log("z");
|
||||||
}
|
}
|
||||||
(function(a, b) {
|
(function(b) {
|
||||||
return function() {
|
return function() {
|
||||||
console.log("FAIL");
|
console.log("FAIL");
|
||||||
} + b();
|
} + b();
|
||||||
})(x(), function() {
|
})((x(), function() {
|
||||||
return y();
|
return y();
|
||||||
}, z());
|
}), z());
|
||||||
}
|
}
|
||||||
expect_stdout: [
|
expect_stdout: [
|
||||||
"x",
|
"x",
|
||||||
@@ -1155,3 +1155,303 @@ issue_3423_2: {
|
|||||||
}
|
}
|
||||||
expect_stdout: "1"
|
expect_stdout: "1"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
collapse_vars_repeated: {
|
||||||
|
options = {
|
||||||
|
booleans: true,
|
||||||
|
collapse_vars: true,
|
||||||
|
comparisons: true,
|
||||||
|
conditionals: true,
|
||||||
|
dead_code: true,
|
||||||
|
evaluate: true,
|
||||||
|
hoist_funs: true,
|
||||||
|
if_return: true,
|
||||||
|
join_vars: true,
|
||||||
|
keep_fargs: "strict",
|
||||||
|
loops: true,
|
||||||
|
properties: true,
|
||||||
|
reduce_funcs: true,
|
||||||
|
reduce_vars: true,
|
||||||
|
sequences: true,
|
||||||
|
side_effects: true,
|
||||||
|
unused: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
function f1() {
|
||||||
|
var dummy = 3, a = 5, unused = 2, a = 1, a = 3;
|
||||||
|
return -a;
|
||||||
|
}
|
||||||
|
function f2(x) {
|
||||||
|
var a = 3, a = x;
|
||||||
|
return a;
|
||||||
|
}
|
||||||
|
(function(x) {
|
||||||
|
var a = "GOOD" + x, e = "BAD", k = "!", e = a;
|
||||||
|
console.log(e + k);
|
||||||
|
})("!"),
|
||||||
|
(function(x) {
|
||||||
|
var a = "GOOD" + x, e = "BAD" + x, k = "!", e = a;
|
||||||
|
console.log(e + k);
|
||||||
|
})("!");
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
function f1() {
|
||||||
|
return -3;
|
||||||
|
}
|
||||||
|
function f2(x) {
|
||||||
|
return x;
|
||||||
|
}
|
||||||
|
(function() {
|
||||||
|
console.log("GOOD!!");
|
||||||
|
})(),
|
||||||
|
(function() {
|
||||||
|
console.log("GOOD!!");
|
||||||
|
})();
|
||||||
|
}
|
||||||
|
expect_stdout: true
|
||||||
|
}
|
||||||
|
|
||||||
|
chained_3: {
|
||||||
|
options = {
|
||||||
|
collapse_vars: true,
|
||||||
|
keep_fargs: "strict",
|
||||||
|
unused: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
console.log(function(a, b) {
|
||||||
|
var c = a, c = b;
|
||||||
|
b++;
|
||||||
|
return c;
|
||||||
|
}(1, 2));
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
console.log(function(b) {
|
||||||
|
var c = 1;
|
||||||
|
c = b;
|
||||||
|
b++;
|
||||||
|
return c;
|
||||||
|
}(2));
|
||||||
|
}
|
||||||
|
expect_stdout: "2"
|
||||||
|
}
|
||||||
|
|
||||||
|
replace_all_var_scope: {
|
||||||
|
rename = true
|
||||||
|
options = {
|
||||||
|
collapse_vars: true,
|
||||||
|
keep_fargs: "strict",
|
||||||
|
unused: true,
|
||||||
|
}
|
||||||
|
mangle = {}
|
||||||
|
input: {
|
||||||
|
var a = 100, b = 10;
|
||||||
|
(function(r, a) {
|
||||||
|
switch (~a) {
|
||||||
|
case (b += a):
|
||||||
|
case a++:
|
||||||
|
}
|
||||||
|
})(--b, a);
|
||||||
|
console.log(a, b);
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
var a = 100, b = 10;
|
||||||
|
(function(c) {
|
||||||
|
switch (~a) {
|
||||||
|
case (b += a):
|
||||||
|
case c++:
|
||||||
|
}
|
||||||
|
})((--b, a));
|
||||||
|
console.log(a, b);
|
||||||
|
}
|
||||||
|
expect_stdout: "100 109"
|
||||||
|
}
|
||||||
|
|
||||||
|
issue_1583: {
|
||||||
|
options = {
|
||||||
|
keep_fargs: "strict",
|
||||||
|
passes: 2,
|
||||||
|
reduce_funcs: true,
|
||||||
|
reduce_vars: true,
|
||||||
|
unused: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
function m(t) {
|
||||||
|
(function(e) {
|
||||||
|
t = e();
|
||||||
|
})(function() {
|
||||||
|
return (function(a) {
|
||||||
|
return a;
|
||||||
|
})(function(a) {});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
function m(t) {
|
||||||
|
(function() {
|
||||||
|
(function() {
|
||||||
|
return (function() {
|
||||||
|
return function(a) {};
|
||||||
|
})();
|
||||||
|
})();
|
||||||
|
})();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
issues_3267_1: {
|
||||||
|
options = {
|
||||||
|
collapse_vars: true,
|
||||||
|
conditionals: true,
|
||||||
|
dead_code: true,
|
||||||
|
evaluate: true,
|
||||||
|
inline: true,
|
||||||
|
keep_fargs: "strict",
|
||||||
|
reduce_vars: true,
|
||||||
|
sequences: true,
|
||||||
|
side_effects: true,
|
||||||
|
unused: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
(function(x) {
|
||||||
|
x();
|
||||||
|
})(function() {
|
||||||
|
(function(i) {
|
||||||
|
if (i)
|
||||||
|
return console.log("PASS");
|
||||||
|
throw "FAIL";
|
||||||
|
})(Object());
|
||||||
|
});
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
!function() {
|
||||||
|
if (Object())
|
||||||
|
return console.log("PASS");
|
||||||
|
throw "FAIL";
|
||||||
|
}();
|
||||||
|
}
|
||||||
|
expect_stdout: "PASS"
|
||||||
|
}
|
||||||
|
|
||||||
|
trailing_argument_side_effects: {
|
||||||
|
options = {
|
||||||
|
keep_fargs: "strict",
|
||||||
|
unused: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
function f() {
|
||||||
|
return "FAIL";
|
||||||
|
}
|
||||||
|
console.log(function(a, b) {
|
||||||
|
return b || "PASS";
|
||||||
|
}(f()));
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
function f() {
|
||||||
|
return "FAIL";
|
||||||
|
}
|
||||||
|
console.log(function(b) {
|
||||||
|
return b || "PASS";
|
||||||
|
}(void f()));
|
||||||
|
}
|
||||||
|
expect_stdout: "PASS"
|
||||||
|
}
|
||||||
|
|
||||||
|
recursive_iife_1: {
|
||||||
|
options = {
|
||||||
|
keep_fargs: "strict",
|
||||||
|
reduce_vars: true,
|
||||||
|
unused: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
console.log(function f(a, b) {
|
||||||
|
return b || f("FAIL", "PASS");
|
||||||
|
}());
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
console.log(function f(a, b) {
|
||||||
|
return b || f("FAIL", "PASS");
|
||||||
|
}());
|
||||||
|
}
|
||||||
|
expect_stdout: "PASS"
|
||||||
|
}
|
||||||
|
|
||||||
|
recursive_iife_2: {
|
||||||
|
options = {
|
||||||
|
keep_fargs: "strict",
|
||||||
|
reduce_vars: true,
|
||||||
|
unused: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
console.log(function f(a, b) {
|
||||||
|
return b || f("FAIL", "PASS");
|
||||||
|
}(null, 0));
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
console.log(function f(a, b) {
|
||||||
|
return b || f("FAIL", "PASS");
|
||||||
|
}(0, 0));
|
||||||
|
}
|
||||||
|
expect_stdout: "PASS"
|
||||||
|
}
|
||||||
|
|
||||||
|
recursive_iife_3: {
|
||||||
|
options = {
|
||||||
|
keep_fargs: false,
|
||||||
|
reduce_vars: true,
|
||||||
|
unused: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
var a = 1, c = "PASS";
|
||||||
|
(function() {
|
||||||
|
function f(b, d, e) {
|
||||||
|
a-- && f(null, 42, 0);
|
||||||
|
e && (c = "FAIL");
|
||||||
|
d && d.p;
|
||||||
|
}
|
||||||
|
var a_1 = f();
|
||||||
|
})();
|
||||||
|
console.log(c);
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
var a = 1, c = "PASS";
|
||||||
|
(function() {
|
||||||
|
(function f(b, d, e) {
|
||||||
|
a-- && f(null, 42, 0);
|
||||||
|
e && (c = "FAIL");
|
||||||
|
d && d.p;
|
||||||
|
})();
|
||||||
|
})();
|
||||||
|
console.log(c);
|
||||||
|
}
|
||||||
|
expect_stdout: "PASS"
|
||||||
|
}
|
||||||
|
|
||||||
|
issue_3619: {
|
||||||
|
options = {
|
||||||
|
keep_fargs: false,
|
||||||
|
unused: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
var a = 1, b = "FAIL";
|
||||||
|
(function f(c, d) {
|
||||||
|
function g() {
|
||||||
|
d && (b = "PASS", 0 <= --a && g());
|
||||||
|
0 <= --a && f(0, "function");
|
||||||
|
}
|
||||||
|
g();
|
||||||
|
})();
|
||||||
|
console.log(b);
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
var a = 1, b = "FAIL";
|
||||||
|
(function f(c, d) {
|
||||||
|
function g() {
|
||||||
|
d && (b = "PASS", 0 <= --a && g());
|
||||||
|
0 <= --a && f(0, "function");
|
||||||
|
}
|
||||||
|
g();
|
||||||
|
})();
|
||||||
|
console.log(b);
|
||||||
|
}
|
||||||
|
expect_stdout: "PASS"
|
||||||
|
}
|
||||||
|
|||||||
@@ -574,9 +574,11 @@ issue_2740_3: {
|
|||||||
console.log(x, y);
|
console.log(x, y);
|
||||||
}
|
}
|
||||||
expect: {
|
expect: {
|
||||||
L1: for (var x = 0; x < 3; x++)
|
L1: for (var x = 0; x < 3; x++) {
|
||||||
for (var y = 0; y < 2; y++)
|
var y = 0;
|
||||||
|
if (y < 2)
|
||||||
break L1;
|
break L1;
|
||||||
|
}
|
||||||
console.log(x, y);
|
console.log(x, y);
|
||||||
}
|
}
|
||||||
expect_stdout: "0 0"
|
expect_stdout: "0 0"
|
||||||
@@ -689,3 +691,239 @@ step: {
|
|||||||
}
|
}
|
||||||
expect_stdout: "42"
|
expect_stdout: "42"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
empty_for_in: {
|
||||||
|
options = {
|
||||||
|
loops: true,
|
||||||
|
toplevel: true,
|
||||||
|
unused: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
for (var a in [ 1, 2, 3 ]) {
|
||||||
|
var b = a + 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
expect: {}
|
||||||
|
expect_warnings: [
|
||||||
|
"WARN: Dropping unused variable b [test/compress/loops.js:2,16]",
|
||||||
|
"INFO: Dropping unused loop variable a [test/compress/loops.js:1,17]",
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
|
empty_for_in_used: {
|
||||||
|
options = {
|
||||||
|
loops: true,
|
||||||
|
toplevel: true,
|
||||||
|
unused: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
for (var a in [ 1, 2, 3 ]) {
|
||||||
|
var b = a + 1;
|
||||||
|
}
|
||||||
|
console.log(a);
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
for (var a in [ 1, 2, 3 ]);
|
||||||
|
console.log(a);
|
||||||
|
}
|
||||||
|
expect_stdout: "2"
|
||||||
|
expect_warnings: [
|
||||||
|
"WARN: Dropping unused variable b [test/compress/loops.js:2,16]",
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
|
empty_for_in_side_effects: {
|
||||||
|
options = {
|
||||||
|
loops: true,
|
||||||
|
toplevel: true,
|
||||||
|
unused: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
for (var a in {
|
||||||
|
foo: console.log("PASS")
|
||||||
|
}) {
|
||||||
|
var b = a + "bar";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
console.log("PASS");
|
||||||
|
}
|
||||||
|
expect_stdout: "PASS"
|
||||||
|
expect_warnings: [
|
||||||
|
"WARN: Dropping unused variable b [test/compress/loops.js:4,16]",
|
||||||
|
"INFO: Dropping unused loop variable a [test/compress/loops.js:1,17]",
|
||||||
|
"WARN: Side effects in object of for-in loop [test/compress/loops.js:1,17]",
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
|
issue_3631_1: {
|
||||||
|
options = {
|
||||||
|
dead_code: true,
|
||||||
|
evaluate: true,
|
||||||
|
loops: true,
|
||||||
|
reduce_vars: true,
|
||||||
|
toplevel: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
var c = 0;
|
||||||
|
L: do {
|
||||||
|
for (;;) continue L;
|
||||||
|
var b = 1;
|
||||||
|
} while (b && c++);
|
||||||
|
console.log(c);
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
var c = 0;
|
||||||
|
do {
|
||||||
|
var b;
|
||||||
|
} while (b && c++);
|
||||||
|
console.log(c);
|
||||||
|
}
|
||||||
|
expect_stdout: "0"
|
||||||
|
}
|
||||||
|
|
||||||
|
issue_3631_2: {
|
||||||
|
options = {
|
||||||
|
dead_code: true,
|
||||||
|
evaluate: true,
|
||||||
|
loops: true,
|
||||||
|
reduce_vars: true,
|
||||||
|
toplevel: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
L: for (var a = 1; a--; console.log(b)) {
|
||||||
|
for (;;) continue L;
|
||||||
|
var b = "FAIL";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
for (var a = 1; a--; console.log(b))
|
||||||
|
var b;
|
||||||
|
}
|
||||||
|
expect_stdout: "undefined"
|
||||||
|
}
|
||||||
|
|
||||||
|
loop_if_break: {
|
||||||
|
options = {
|
||||||
|
dead_code: true,
|
||||||
|
loops: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
function f(a, b) {
|
||||||
|
try {
|
||||||
|
while (a) {
|
||||||
|
if (b) {
|
||||||
|
break;
|
||||||
|
var c = 42;
|
||||||
|
console.log(c);
|
||||||
|
} else {
|
||||||
|
var d = false;
|
||||||
|
throw d;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
console.log("E:", e);
|
||||||
|
}
|
||||||
|
console.log(a, b, c, d);
|
||||||
|
}
|
||||||
|
f(0, 0);
|
||||||
|
f(0, 1);
|
||||||
|
f(1, 0);
|
||||||
|
f(1, 1);
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
function f(a, b) {
|
||||||
|
try {
|
||||||
|
for (;a && !b;) {
|
||||||
|
var d = false;
|
||||||
|
throw d;
|
||||||
|
var c;
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
console.log("E:", e);
|
||||||
|
}
|
||||||
|
console.log(a, b, c, d);
|
||||||
|
}
|
||||||
|
f(0, 0);
|
||||||
|
f(0, 1);
|
||||||
|
f(1, 0);
|
||||||
|
f(1, 1);
|
||||||
|
}
|
||||||
|
expect_stdout: [
|
||||||
|
"0 0 undefined undefined",
|
||||||
|
"0 1 undefined undefined",
|
||||||
|
"E: false",
|
||||||
|
"1 0 undefined false",
|
||||||
|
"1 1 undefined undefined",
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
|
loop_return: {
|
||||||
|
options = {
|
||||||
|
dead_code: true,
|
||||||
|
loops: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
function f(a) {
|
||||||
|
while (a) return 42;
|
||||||
|
return "foo";
|
||||||
|
}
|
||||||
|
console.log(f(0), f(1));
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
function f(a) {
|
||||||
|
if (a) return 42;
|
||||||
|
return "foo";
|
||||||
|
}
|
||||||
|
console.log(f(0), f(1));
|
||||||
|
}
|
||||||
|
expect_stdout: "foo 42"
|
||||||
|
}
|
||||||
|
|
||||||
|
issue_3634_1: {
|
||||||
|
options = {
|
||||||
|
loops: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
var b = 0;
|
||||||
|
L: while (++b < 2)
|
||||||
|
while (1)
|
||||||
|
if (b) break L;
|
||||||
|
console.log(b);
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
var b = 0;
|
||||||
|
L: for (;++b < 2;)
|
||||||
|
for (;1;)
|
||||||
|
if (b) break L;
|
||||||
|
console.log(b);
|
||||||
|
}
|
||||||
|
expect_stdout: "1"
|
||||||
|
}
|
||||||
|
|
||||||
|
issue_3634_2: {
|
||||||
|
options = {
|
||||||
|
loops: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
var b = 0;
|
||||||
|
L: while (++b < 2)
|
||||||
|
while (1)
|
||||||
|
if (!b)
|
||||||
|
continue L;
|
||||||
|
else
|
||||||
|
break L;
|
||||||
|
console.log(b);
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
var b = 0;
|
||||||
|
L: for (;++b < 2;)
|
||||||
|
for (;1;)
|
||||||
|
if (!b)
|
||||||
|
continue L;
|
||||||
|
else
|
||||||
|
break L;
|
||||||
|
console.log(b);
|
||||||
|
}
|
||||||
|
expect_stdout: "1"
|
||||||
|
}
|
||||||
|
|||||||
@@ -91,7 +91,7 @@ evaluate_1: {
|
|||||||
expect: {
|
expect: {
|
||||||
console.log(
|
console.log(
|
||||||
x + 1 + 2,
|
x + 1 + 2,
|
||||||
1 * x * 2,
|
2 * x,
|
||||||
+x + 1 + 2,
|
+x + 1 + 2,
|
||||||
1 + x + 2 + 3,
|
1 + x + 2 + 3,
|
||||||
3 | x,
|
3 | x,
|
||||||
@@ -173,7 +173,7 @@ evaluate_2: {
|
|||||||
var x = "42", y = null;
|
var x = "42", y = null;
|
||||||
[
|
[
|
||||||
x + 1 + 2,
|
x + 1 + 2,
|
||||||
1 * x * 2,
|
2 * x,
|
||||||
+x + 1 + 2,
|
+x + 1 + 2,
|
||||||
1 + x + 2 + 3,
|
1 + x + 2 + 3,
|
||||||
3 | x,
|
3 | x,
|
||||||
@@ -870,7 +870,7 @@ issue_3547_3: {
|
|||||||
a + "21",
|
a + "21",
|
||||||
a + "2" - 1,
|
a + "2" - 1,
|
||||||
a - 1,
|
a - 1,
|
||||||
a - "2" - 1,
|
a - 3,
|
||||||
].forEach(function(n) {
|
].forEach(function(n) {
|
||||||
console.log(typeof n, n);
|
console.log(typeof n, n);
|
||||||
});
|
});
|
||||||
@@ -904,7 +904,7 @@ issue_3547_4: {
|
|||||||
[
|
[
|
||||||
"3" + a + 1,
|
"3" + a + 1,
|
||||||
"3" + a - 1,
|
"3" + a - 1,
|
||||||
"3" - a + 1,
|
4 - a,
|
||||||
2 - a,
|
2 - a,
|
||||||
].forEach(function(n) {
|
].forEach(function(n) {
|
||||||
console.log(typeof n, n);
|
console.log(typeof n, n);
|
||||||
@@ -917,3 +917,253 @@ issue_3547_4: {
|
|||||||
"number 0",
|
"number 0",
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
unsafe_math_rounding: {
|
||||||
|
options = {
|
||||||
|
evaluate: true,
|
||||||
|
unsafe_math: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
console.log(4 / -3 + 1 === 1 / -3);
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
console.log(false);
|
||||||
|
}
|
||||||
|
expect_stdout: "false"
|
||||||
|
}
|
||||||
|
|
||||||
|
issue_3593: {
|
||||||
|
options = {
|
||||||
|
evaluate: true,
|
||||||
|
unsafe_math: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
console.log((0 === this) - 1 - "1");
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
console.log((0 === this) - 2);
|
||||||
|
}
|
||||||
|
expect_stdout: "-2"
|
||||||
|
}
|
||||||
|
|
||||||
|
unsafe_math_swap_constant: {
|
||||||
|
options = {
|
||||||
|
evaluate: true,
|
||||||
|
unsafe_math: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
var a = 1, b = 2;
|
||||||
|
console.log(
|
||||||
|
a++ + b-- + 3,
|
||||||
|
a++ + b + 3,
|
||||||
|
a + b-- + 3,
|
||||||
|
a + b + 3,
|
||||||
|
a++ - b-- + 3,
|
||||||
|
a++ - b + 3,
|
||||||
|
a - b-- + 3,
|
||||||
|
a - b + 3
|
||||||
|
);
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
var a = 1, b = 2;
|
||||||
|
console.log(
|
||||||
|
3 + a++ + b--,
|
||||||
|
a++ + b + 3,
|
||||||
|
a + b-- + 3,
|
||||||
|
a + b + 3,
|
||||||
|
3 + a++ - b--,
|
||||||
|
3 + a++ - b,
|
||||||
|
a - b-- + 3,
|
||||||
|
a - b + 3
|
||||||
|
);
|
||||||
|
}
|
||||||
|
expect_stdout: "6 6 7 6 6 8 9 10"
|
||||||
|
}
|
||||||
|
|
||||||
|
identity_1: {
|
||||||
|
options = {
|
||||||
|
evaluate: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
0 + a;
|
||||||
|
a + 0;
|
||||||
|
0 - a;
|
||||||
|
a - 0;
|
||||||
|
1 * a;
|
||||||
|
a * 1;
|
||||||
|
1 / a;
|
||||||
|
a / 1;
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
0 + a;
|
||||||
|
a + 0;
|
||||||
|
0 - a;
|
||||||
|
+a;
|
||||||
|
+a;
|
||||||
|
+a;
|
||||||
|
1 / a;
|
||||||
|
+a;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
identity_2: {
|
||||||
|
options = {
|
||||||
|
evaluate: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
0 + !a;
|
||||||
|
!a + 0;
|
||||||
|
0 - !a;
|
||||||
|
!a - 0;
|
||||||
|
1 * !a;
|
||||||
|
!a * 1;
|
||||||
|
1 / !a;
|
||||||
|
!a / 1;
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
+!a;
|
||||||
|
+!a;
|
||||||
|
0 - !a;
|
||||||
|
+!a;
|
||||||
|
+!a;
|
||||||
|
+!a;
|
||||||
|
1 / !a;
|
||||||
|
+!a;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
identity_3: {
|
||||||
|
options = {
|
||||||
|
evaluate: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
0 + --a;
|
||||||
|
--a + 0;
|
||||||
|
0 - --a;
|
||||||
|
--a - 0;
|
||||||
|
1 * --a;
|
||||||
|
--a * 1;
|
||||||
|
1 / --a;
|
||||||
|
--a / 1;
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
--a;
|
||||||
|
--a;
|
||||||
|
0 - --a;
|
||||||
|
--a;
|
||||||
|
--a;
|
||||||
|
--a;
|
||||||
|
1 / --a;
|
||||||
|
--a;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
issue_3653: {
|
||||||
|
options = {
|
||||||
|
evaluate: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
console.log(0 - (console && 0));
|
||||||
|
console.log(0 + (0 - (console && 0)));
|
||||||
|
console.log(0 - (0 - (console && 0)));
|
||||||
|
console.log(1 * (0 - (console && 0)));
|
||||||
|
console.log(1 / (0 - (console && 0)));
|
||||||
|
console.log((0 - (console && 0)) + 0);
|
||||||
|
console.log((0 - (console && 0)) - 0);
|
||||||
|
console.log((0 - (console && 0)) * 1);
|
||||||
|
console.log((0 - (console && 0)) / 1);
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
console.log(0 - (console && 0));
|
||||||
|
console.log(0 - (console && 0) + 0);
|
||||||
|
console.log(0 - (0 - (console && 0)));
|
||||||
|
console.log(0 - (console && 0));
|
||||||
|
console.log(1 / (0 - (console && 0)));
|
||||||
|
console.log(0 - (console && 0) + 0);
|
||||||
|
console.log(0 - (console && 0));
|
||||||
|
console.log(0 - (console && 0));
|
||||||
|
console.log(0 - (console && 0));
|
||||||
|
}
|
||||||
|
expect_stdout: [
|
||||||
|
"0",
|
||||||
|
"0",
|
||||||
|
"0",
|
||||||
|
"0",
|
||||||
|
"Infinity",
|
||||||
|
"0",
|
||||||
|
"0",
|
||||||
|
"0",
|
||||||
|
"0",
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
|
issue_3655: {
|
||||||
|
options = {
|
||||||
|
evaluate: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
console.log(0 + 0 * -[].length);
|
||||||
|
console.log(0 + (0 + 0 * -[].length));
|
||||||
|
console.log(0 - (0 + 0 * -[].length));
|
||||||
|
console.log(1 * (0 + 0 * -[].length));
|
||||||
|
console.log(1 / (0 + 0 * -[].length));
|
||||||
|
console.log((0 + 0 * -[].length) + 0);
|
||||||
|
console.log((0 + 0 * -[].length) - 0);
|
||||||
|
console.log((0 + 0 * -[].length) * 1);
|
||||||
|
console.log((0 + 0 * -[].length) / 1);
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
console.log(0 + 0 * -[].length);
|
||||||
|
console.log(0 + 0 * -[].length);
|
||||||
|
console.log(0 - (0 + 0 * -[].length));
|
||||||
|
console.log(0 + 0 * -[].length);
|
||||||
|
console.log(1 / (0 + 0 * -[].length));
|
||||||
|
console.log(0 + 0 * -[].length);
|
||||||
|
console.log(0 + 0 * -[].length);
|
||||||
|
console.log(0 + 0 * -[].length);
|
||||||
|
console.log(0 + 0 * -[].length);
|
||||||
|
}
|
||||||
|
expect_stdout: [
|
||||||
|
"0",
|
||||||
|
"0",
|
||||||
|
"0",
|
||||||
|
"0",
|
||||||
|
"Infinity",
|
||||||
|
"0",
|
||||||
|
"0",
|
||||||
|
"0",
|
||||||
|
"0",
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
|
issue_3676_1: {
|
||||||
|
options = {
|
||||||
|
evaluate: true,
|
||||||
|
unsafe_math: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
var a = [];
|
||||||
|
console.log(false - (a - (a[1] = 42)));
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
var a = [];
|
||||||
|
console.log(false - (a - (a[1] = 42)));
|
||||||
|
}
|
||||||
|
expect_stdout: "NaN"
|
||||||
|
}
|
||||||
|
|
||||||
|
issue_3676_2: {
|
||||||
|
options = {
|
||||||
|
evaluate: true,
|
||||||
|
unsafe_math: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
var a;
|
||||||
|
console.log(false - ((a = []) - (a[1] = 42)));
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
var a;
|
||||||
|
console.log(false - ((a = []) - (a[1] = 42)));
|
||||||
|
}
|
||||||
|
expect_stdout: "NaN"
|
||||||
|
}
|
||||||
|
|||||||
@@ -1427,13 +1427,13 @@ defun_inline_3: {
|
|||||||
|
|
||||||
defun_call: {
|
defun_call: {
|
||||||
options = {
|
options = {
|
||||||
inline: true,
|
evaluate: true,
|
||||||
reduce_funcs: true,
|
reduce_funcs: true,
|
||||||
reduce_vars: true,
|
reduce_vars: true,
|
||||||
unused: true,
|
unused: true,
|
||||||
}
|
}
|
||||||
input: {
|
input: {
|
||||||
function f() {
|
console.log(function f() {
|
||||||
return g() + h(1) - h(g(), 2, 3);
|
return g() + h(1) - h(g(), 2, 3);
|
||||||
function g() {
|
function g() {
|
||||||
return 4;
|
return 4;
|
||||||
@@ -1441,21 +1441,17 @@ defun_call: {
|
|||||||
function h(a) {
|
function h(a) {
|
||||||
return a;
|
return a;
|
||||||
}
|
}
|
||||||
}
|
}());
|
||||||
}
|
}
|
||||||
expect: {
|
expect: {
|
||||||
function f() {
|
console.log(1);
|
||||||
return 4 + h(1) - h(4);
|
|
||||||
function h(a) {
|
|
||||||
return a;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
expect_stdout: "1"
|
||||||
}
|
}
|
||||||
|
|
||||||
defun_redefine: {
|
defun_redefine: {
|
||||||
options = {
|
options = {
|
||||||
inline: true,
|
evaluate: true,
|
||||||
reduce_funcs: true,
|
reduce_funcs: true,
|
||||||
reduce_vars: true,
|
reduce_vars: true,
|
||||||
unused: true,
|
unused: true,
|
||||||
@@ -1480,7 +1476,7 @@ defun_redefine: {
|
|||||||
(function() {
|
(function() {
|
||||||
return 3;
|
return 3;
|
||||||
});
|
});
|
||||||
return 3 + 2;
|
return 5;
|
||||||
}
|
}
|
||||||
console.log(f());
|
console.log(f());
|
||||||
}
|
}
|
||||||
@@ -1517,7 +1513,7 @@ func_inline: {
|
|||||||
|
|
||||||
func_modified: {
|
func_modified: {
|
||||||
options = {
|
options = {
|
||||||
inline: true,
|
evaluate: true,
|
||||||
reduce_funcs: true,
|
reduce_funcs: true,
|
||||||
reduce_vars: true,
|
reduce_vars: true,
|
||||||
unused: true,
|
unused: true,
|
||||||
@@ -1550,7 +1546,7 @@ func_modified: {
|
|||||||
(function() {
|
(function() {
|
||||||
return 4;
|
return 4;
|
||||||
});
|
});
|
||||||
return 1 + 2 + 4;
|
return 7;
|
||||||
}
|
}
|
||||||
console.log(f());
|
console.log(f());
|
||||||
}
|
}
|
||||||
@@ -5516,9 +5512,7 @@ issue_2860_1: {
|
|||||||
}());
|
}());
|
||||||
}
|
}
|
||||||
expect: {
|
expect: {
|
||||||
console.log(function(a) {
|
console.log(1);
|
||||||
return 1 ^ a;
|
|
||||||
}());
|
|
||||||
}
|
}
|
||||||
expect_stdout: "1"
|
expect_stdout: "1"
|
||||||
}
|
}
|
||||||
@@ -6780,3 +6774,107 @@ issue_3509: {
|
|||||||
}
|
}
|
||||||
expect_stdout: "PASS"
|
expect_stdout: "PASS"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
issue_3622: {
|
||||||
|
options = {
|
||||||
|
evaluate: true,
|
||||||
|
inline: true,
|
||||||
|
keep_fargs: "strict",
|
||||||
|
reduce_vars: true,
|
||||||
|
sequences: true,
|
||||||
|
toplevel: true,
|
||||||
|
unused: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
var c = "FAIL";
|
||||||
|
!function(b, a) {
|
||||||
|
a && (c = "PASS");
|
||||||
|
}(42, this);
|
||||||
|
console.log(c);
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
var c = "FAIL";
|
||||||
|
var a;
|
||||||
|
a = this,
|
||||||
|
!void (a && (c = "PASS")),
|
||||||
|
console.log(c);
|
||||||
|
}
|
||||||
|
expect_stdout: "PASS"
|
||||||
|
}
|
||||||
|
|
||||||
|
issue_3631_1: {
|
||||||
|
options = {
|
||||||
|
evaluate: true,
|
||||||
|
reduce_vars: true,
|
||||||
|
toplevel: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
var c = 0;
|
||||||
|
L: do {
|
||||||
|
for (;;) continue L;
|
||||||
|
var b = 1;
|
||||||
|
} while (b && c++);
|
||||||
|
console.log(c);
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
var c = 0;
|
||||||
|
L: do {
|
||||||
|
for (;;) continue L;
|
||||||
|
var b = 1;
|
||||||
|
} while (b && c++);
|
||||||
|
console.log(c);
|
||||||
|
}
|
||||||
|
expect_stdout: "0"
|
||||||
|
}
|
||||||
|
|
||||||
|
issue_3631_2: {
|
||||||
|
options = {
|
||||||
|
reduce_vars: true,
|
||||||
|
toplevel: true,
|
||||||
|
unused: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
L: for (var a = 1; a--; console.log(b)) {
|
||||||
|
for (;;) continue L;
|
||||||
|
var b = "FAIL";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
L: for (var a = 1; a--; console.log(b)) {
|
||||||
|
for (;;) continue L;
|
||||||
|
var b = "FAIL";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
expect_stdout: "undefined"
|
||||||
|
}
|
||||||
|
|
||||||
|
issue_3666: {
|
||||||
|
options = {
|
||||||
|
collapse_vars: true,
|
||||||
|
passes: 2,
|
||||||
|
reduce_vars: true,
|
||||||
|
toplevel: true,
|
||||||
|
unused: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
try {
|
||||||
|
var a = "FAIL";
|
||||||
|
} finally {
|
||||||
|
for (;!a;)
|
||||||
|
var c = a++;
|
||||||
|
var a = "PASS", b = c = "PASS";
|
||||||
|
}
|
||||||
|
console.log(a, b);
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
try {
|
||||||
|
var a = "FAIL";
|
||||||
|
} finally {
|
||||||
|
for (;!a;)
|
||||||
|
a++;
|
||||||
|
var b = a = "PASS";
|
||||||
|
}
|
||||||
|
console.log(a, b);
|
||||||
|
}
|
||||||
|
expect_stdout: "PASS PASS"
|
||||||
|
}
|
||||||
|
|||||||
277
test/compress/side_effects.js
Normal file
277
test/compress/side_effects.js
Normal file
@@ -0,0 +1,277 @@
|
|||||||
|
accessor: {
|
||||||
|
options = {
|
||||||
|
side_effects: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
({
|
||||||
|
get a() {},
|
||||||
|
set a(v){
|
||||||
|
this.b = 2;
|
||||||
|
},
|
||||||
|
b: 1
|
||||||
|
});
|
||||||
|
}
|
||||||
|
expect: {}
|
||||||
|
}
|
||||||
|
|
||||||
|
issue_2233_1: {
|
||||||
|
options = {
|
||||||
|
pure_getters: "strict",
|
||||||
|
side_effects: true,
|
||||||
|
unsafe: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
Array.isArray;
|
||||||
|
Boolean;
|
||||||
|
console.log;
|
||||||
|
Date;
|
||||||
|
decodeURI;
|
||||||
|
decodeURIComponent;
|
||||||
|
encodeURI;
|
||||||
|
encodeURIComponent;
|
||||||
|
Error.name;
|
||||||
|
escape;
|
||||||
|
eval;
|
||||||
|
EvalError;
|
||||||
|
Function.length;
|
||||||
|
isFinite;
|
||||||
|
isNaN;
|
||||||
|
JSON;
|
||||||
|
Math.random;
|
||||||
|
Number.isNaN;
|
||||||
|
parseFloat;
|
||||||
|
parseInt;
|
||||||
|
RegExp;
|
||||||
|
Object.defineProperty;
|
||||||
|
String.fromCharCode;
|
||||||
|
RangeError;
|
||||||
|
ReferenceError;
|
||||||
|
SyntaxError;
|
||||||
|
TypeError;
|
||||||
|
unescape;
|
||||||
|
URIError;
|
||||||
|
}
|
||||||
|
expect: {}
|
||||||
|
expect_stdout: true
|
||||||
|
}
|
||||||
|
|
||||||
|
global_timeout_and_interval_symbols: {
|
||||||
|
options = {
|
||||||
|
pure_getters: "strict",
|
||||||
|
side_effects: true,
|
||||||
|
unsafe: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
// These global symbols do not exist in the test sandbox
|
||||||
|
// and must be tested separately.
|
||||||
|
clearInterval;
|
||||||
|
clearTimeout;
|
||||||
|
setInterval;
|
||||||
|
setTimeout;
|
||||||
|
}
|
||||||
|
expect: {}
|
||||||
|
}
|
||||||
|
|
||||||
|
issue_2233_2: {
|
||||||
|
options = {
|
||||||
|
pure_getters: "strict",
|
||||||
|
reduce_funcs: true,
|
||||||
|
reduce_vars: true,
|
||||||
|
side_effects: true,
|
||||||
|
unsafe: true,
|
||||||
|
unused: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
var RegExp;
|
||||||
|
Array.isArray;
|
||||||
|
RegExp;
|
||||||
|
UndeclaredGlobal;
|
||||||
|
function foo() {
|
||||||
|
var Number;
|
||||||
|
AnotherUndeclaredGlobal;
|
||||||
|
Math.sin;
|
||||||
|
Number.isNaN;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
var RegExp;
|
||||||
|
UndeclaredGlobal;
|
||||||
|
function foo() {
|
||||||
|
var Number;
|
||||||
|
AnotherUndeclaredGlobal;
|
||||||
|
Number.isNaN;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
issue_2233_3: {
|
||||||
|
options = {
|
||||||
|
pure_getters: "strict",
|
||||||
|
reduce_funcs: true,
|
||||||
|
reduce_vars: true,
|
||||||
|
side_effects: true,
|
||||||
|
toplevel: true,
|
||||||
|
unsafe: true,
|
||||||
|
unused: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
var RegExp;
|
||||||
|
Array.isArray;
|
||||||
|
RegExp;
|
||||||
|
UndeclaredGlobal;
|
||||||
|
function foo() {
|
||||||
|
var Number;
|
||||||
|
AnotherUndeclaredGlobal;
|
||||||
|
Math.sin;
|
||||||
|
Number.isNaN;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
UndeclaredGlobal;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
global_fns: {
|
||||||
|
options = {
|
||||||
|
side_effects: true,
|
||||||
|
unsafe: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
Boolean(1, 2);
|
||||||
|
decodeURI(1, 2);
|
||||||
|
decodeURIComponent(1, 2);
|
||||||
|
Date(1, 2);
|
||||||
|
encodeURI(1, 2);
|
||||||
|
encodeURIComponent(1, 2);
|
||||||
|
Error(1, 2);
|
||||||
|
escape(1, 2);
|
||||||
|
EvalError(1, 2);
|
||||||
|
isFinite(1, 2);
|
||||||
|
isNaN(1, 2);
|
||||||
|
Number(1, 2);
|
||||||
|
Object(1, 2);
|
||||||
|
parseFloat(1, 2);
|
||||||
|
parseInt(1, 2);
|
||||||
|
RangeError(1, 2);
|
||||||
|
ReferenceError(1, 2);
|
||||||
|
String(1, 2);
|
||||||
|
SyntaxError(1, 2);
|
||||||
|
TypeError(1, 2);
|
||||||
|
unescape(1, 2);
|
||||||
|
URIError(1, 2);
|
||||||
|
try {
|
||||||
|
Function(1, 2);
|
||||||
|
} catch (e) {
|
||||||
|
console.log(e.name);
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
RegExp(1, 2);
|
||||||
|
} catch (e) {
|
||||||
|
console.log(e.name);
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
Array(NaN);
|
||||||
|
} catch (e) {
|
||||||
|
console.log(e.name);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
try {
|
||||||
|
Function(1, 2);
|
||||||
|
} catch (e) {
|
||||||
|
console.log(e.name);
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
RegExp(1, 2);
|
||||||
|
} catch (e) {
|
||||||
|
console.log(e.name);
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
Array(NaN);
|
||||||
|
} catch (e) {
|
||||||
|
console.log(e.name);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
expect_stdout: [
|
||||||
|
"SyntaxError",
|
||||||
|
"SyntaxError",
|
||||||
|
"RangeError",
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
|
unsafe_builtin_1: {
|
||||||
|
options = {
|
||||||
|
side_effects: true,
|
||||||
|
unsafe: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
(!w).constructor(x);
|
||||||
|
Math.abs(y);
|
||||||
|
[ 1, 2, z ].valueOf();
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
w, x;
|
||||||
|
y;
|
||||||
|
z;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
unsafe_builtin_2: {
|
||||||
|
options = {
|
||||||
|
side_effects: true,
|
||||||
|
unsafe: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
var o = {};
|
||||||
|
constructor.call(o, 42);
|
||||||
|
__defineGetter__.call(o, "foo", function() {
|
||||||
|
return o.p;
|
||||||
|
});
|
||||||
|
__defineSetter__.call(o, void 0, function(a) {
|
||||||
|
o.p = a;
|
||||||
|
});
|
||||||
|
console.log(typeof o, o.undefined = "PASS", o.foo);
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
var o = {};
|
||||||
|
constructor.call(o, 42);
|
||||||
|
__defineGetter__.call(o, "foo", function() {
|
||||||
|
return o.p;
|
||||||
|
});
|
||||||
|
__defineSetter__.call(o, void 0, function(a) {
|
||||||
|
o.p = a;
|
||||||
|
});
|
||||||
|
console.log(typeof o, o.undefined = "PASS", o.foo);
|
||||||
|
}
|
||||||
|
expect_stdout: "object PASS PASS"
|
||||||
|
}
|
||||||
|
|
||||||
|
unsafe_string_replace: {
|
||||||
|
options = {
|
||||||
|
side_effects: true,
|
||||||
|
unsafe: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
"foo".replace("f", function() {
|
||||||
|
console.log("PASS");
|
||||||
|
});
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
"foo".replace("f", function() {
|
||||||
|
console.log("PASS");
|
||||||
|
});
|
||||||
|
}
|
||||||
|
expect_stdout: "PASS"
|
||||||
|
}
|
||||||
|
|
||||||
|
drop_value: {
|
||||||
|
options = {
|
||||||
|
side_effects: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
(1, [2, foo()], 3, {a:1, b:bar()});
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
foo(), bar();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -261,13 +261,13 @@ drop_default_1: {
|
|||||||
}
|
}
|
||||||
input: {
|
input: {
|
||||||
switch (foo) {
|
switch (foo) {
|
||||||
case 'bar': baz();
|
case "bar": baz();
|
||||||
default:
|
default:
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
expect: {
|
expect: {
|
||||||
switch (foo) {
|
switch (foo) {
|
||||||
case 'bar': baz();
|
case "bar": baz();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -279,14 +279,14 @@ drop_default_2: {
|
|||||||
}
|
}
|
||||||
input: {
|
input: {
|
||||||
switch (foo) {
|
switch (foo) {
|
||||||
case 'bar': baz(); break;
|
case "bar": baz(); break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
expect: {
|
expect: {
|
||||||
switch (foo) {
|
switch (foo) {
|
||||||
case 'bar': baz();
|
case "bar": baz();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -298,7 +298,7 @@ keep_default: {
|
|||||||
}
|
}
|
||||||
input: {
|
input: {
|
||||||
switch (foo) {
|
switch (foo) {
|
||||||
case 'bar': baz();
|
case "bar": baz();
|
||||||
default:
|
default:
|
||||||
something();
|
something();
|
||||||
break;
|
break;
|
||||||
@@ -306,7 +306,7 @@ keep_default: {
|
|||||||
}
|
}
|
||||||
expect: {
|
expect: {
|
||||||
switch (foo) {
|
switch (foo) {
|
||||||
case 'bar': baz();
|
case "bar": baz();
|
||||||
default:
|
default:
|
||||||
something();
|
something();
|
||||||
}
|
}
|
||||||
@@ -347,25 +347,103 @@ issue_1663: {
|
|||||||
expect_stdout: true
|
expect_stdout: true
|
||||||
}
|
}
|
||||||
|
|
||||||
drop_case: {
|
drop_case_1: {
|
||||||
options = {
|
options = {
|
||||||
dead_code: true,
|
dead_code: true,
|
||||||
switches: true,
|
switches: true,
|
||||||
}
|
}
|
||||||
input: {
|
input: {
|
||||||
switch (foo) {
|
switch (foo) {
|
||||||
case 'bar': baz(); break;
|
case "bar": baz(); break;
|
||||||
case 'moo':
|
case "moo":
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
expect: {
|
expect: {
|
||||||
switch (foo) {
|
switch (foo) {
|
||||||
case 'bar': baz();
|
case "bar": baz();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
drop_case_2: {
|
||||||
|
options = {
|
||||||
|
dead_code: true,
|
||||||
|
switches: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
switch (foo) {
|
||||||
|
case "bar":
|
||||||
|
bar();
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
case "moo":
|
||||||
|
moo();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
switch (foo) {
|
||||||
|
case "bar":
|
||||||
|
bar();
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
moo();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
drop_case_3: {
|
||||||
|
options = {
|
||||||
|
dead_code: true,
|
||||||
|
switches: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
var c = "PASS";
|
||||||
|
switch ({}.p) {
|
||||||
|
default:
|
||||||
|
case void 0:
|
||||||
|
break;
|
||||||
|
case c = "FAIL":
|
||||||
|
}
|
||||||
|
console.log(c);
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
var c = "PASS";
|
||||||
|
switch ({}.p) {
|
||||||
|
default:
|
||||||
|
case void 0:
|
||||||
|
break;
|
||||||
|
case c = "FAIL":
|
||||||
|
}
|
||||||
|
console.log(c);
|
||||||
|
}
|
||||||
|
expect_stdout: "PASS"
|
||||||
|
}
|
||||||
|
|
||||||
|
drop_case_4: {
|
||||||
|
options = {
|
||||||
|
dead_code: true,
|
||||||
|
switches: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
switch (0) {
|
||||||
|
case [ a, typeof b ]:
|
||||||
|
default:
|
||||||
|
var a;
|
||||||
|
}
|
||||||
|
console.log("PASS");
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
switch (0) {
|
||||||
|
case [ a, typeof b ]:
|
||||||
|
var a;
|
||||||
|
}
|
||||||
|
console.log("PASS");
|
||||||
|
}
|
||||||
|
expect_stdout: "PASS"
|
||||||
|
}
|
||||||
|
|
||||||
keep_case: {
|
keep_case: {
|
||||||
options = {
|
options = {
|
||||||
dead_code: true,
|
dead_code: true,
|
||||||
@@ -373,14 +451,14 @@ keep_case: {
|
|||||||
}
|
}
|
||||||
input: {
|
input: {
|
||||||
switch (foo) {
|
switch (foo) {
|
||||||
case 'bar': baz(); break;
|
case "bar": baz(); break;
|
||||||
case moo:
|
case moo:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
expect: {
|
expect: {
|
||||||
switch (foo) {
|
switch (foo) {
|
||||||
case 'bar': baz(); break;
|
case "bar": baz(); break;
|
||||||
case moo:
|
case moo:
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -539,7 +617,7 @@ issue_1679: {
|
|||||||
f();
|
f();
|
||||||
console.log(a, b);
|
console.log(a, b);
|
||||||
}
|
}
|
||||||
expect_stdout: true
|
expect_stdout: "99 8"
|
||||||
}
|
}
|
||||||
|
|
||||||
issue_1680_1: {
|
issue_1680_1: {
|
||||||
@@ -864,3 +942,89 @@ issue_1750: {
|
|||||||
}
|
}
|
||||||
expect_stdout: "0 2"
|
expect_stdout: "0 2"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
drop_switch_1: {
|
||||||
|
options = {
|
||||||
|
dead_code: true,
|
||||||
|
switches: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
switch (foo) {
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
case "bar":
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
foo;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
drop_switch_2: {
|
||||||
|
options = {
|
||||||
|
dead_code: true,
|
||||||
|
switches: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
switch (foo) {
|
||||||
|
default:
|
||||||
|
case "bar":
|
||||||
|
baz();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
foo;
|
||||||
|
baz();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
drop_switch_3: {
|
||||||
|
options = {
|
||||||
|
dead_code: true,
|
||||||
|
switches: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
console.log(function() {
|
||||||
|
switch (0) {
|
||||||
|
default:
|
||||||
|
return "PASS";
|
||||||
|
case 1:
|
||||||
|
}
|
||||||
|
}());
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
console.log(function() {
|
||||||
|
switch (0) {
|
||||||
|
default:
|
||||||
|
return "PASS";
|
||||||
|
case 1:
|
||||||
|
}
|
||||||
|
}());
|
||||||
|
}
|
||||||
|
expect_stdout: "PASS"
|
||||||
|
}
|
||||||
|
|
||||||
|
drop_switch_4: {
|
||||||
|
options = {
|
||||||
|
dead_code: true,
|
||||||
|
switches: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
var a = "FAIL";
|
||||||
|
switch (0) {
|
||||||
|
default:
|
||||||
|
case a:
|
||||||
|
var b = a = "PASS";
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
console.log(a);
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
var a = "FAIL";
|
||||||
|
0;
|
||||||
|
var b = a = "PASS";
|
||||||
|
console.log(a);
|
||||||
|
}
|
||||||
|
expect_stdout: "PASS"
|
||||||
|
}
|
||||||
|
|||||||
@@ -103,6 +103,7 @@ if_return: {
|
|||||||
booleans: true,
|
booleans: true,
|
||||||
conditionals: true,
|
conditionals: true,
|
||||||
if_return: true,
|
if_return: true,
|
||||||
|
passes: 2,
|
||||||
sequences: true,
|
sequences: true,
|
||||||
side_effects: true,
|
side_effects: true,
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -166,9 +166,7 @@ duplicate_lambda_arg_name: {
|
|||||||
}());
|
}());
|
||||||
}
|
}
|
||||||
expect: {
|
expect: {
|
||||||
console.log(function long_name(long_name) {
|
console.log("undefined");
|
||||||
return typeof long_name;
|
|
||||||
}());
|
|
||||||
}
|
}
|
||||||
expect_stdout: "undefined"
|
expect_stdout: "undefined"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,6 +16,81 @@ unicode_parse_variables: {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
unicode_escaped_identifier: {
|
||||||
|
input: {
|
||||||
|
var \u0061 = "\ud800\udc00";
|
||||||
|
console.log(a);
|
||||||
|
}
|
||||||
|
expect_exact: 'var a="\ud800\udc00";console.log(a);'
|
||||||
|
expect_stdout: "\ud800\udc00"
|
||||||
|
}
|
||||||
|
|
||||||
|
unicode_identifier_ascii_only: {
|
||||||
|
beautify = {
|
||||||
|
ascii_only: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
var \u0061 = "testing \udbc4\udd11";
|
||||||
|
var bar = "h\u0065llo";
|
||||||
|
console.log(a, \u0062\u0061r);
|
||||||
|
}
|
||||||
|
expect_exact: 'var a="testing \\udbc4\\udd11";var bar="hello";console.log(a,bar);'
|
||||||
|
expect_stdout: "testing \udbc4\udd11 hello"
|
||||||
|
}
|
||||||
|
|
||||||
|
unicode_string_literals: {
|
||||||
|
beautify = {
|
||||||
|
ascii_only: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
var a = "6 length unicode character: \udbc4\udd11";
|
||||||
|
console.log(\u0061);
|
||||||
|
}
|
||||||
|
expect_exact: 'var a="6 length unicode character: \\udbc4\\udd11";console.log(a);'
|
||||||
|
expect_stdout: "6 length unicode character: \udbc4\udd11"
|
||||||
|
}
|
||||||
|
|
||||||
|
check_escape_style: {
|
||||||
|
beautify = {
|
||||||
|
ascii_only: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
var a = "\x01";
|
||||||
|
var \ua0081 = "\x10"; // \u0081 only in ID_Continue
|
||||||
|
var \u0100 = "\u0100";
|
||||||
|
var \u1000 = "\u1000";
|
||||||
|
var \u1000 = "\ud800\udc00";
|
||||||
|
var \u3f80 = "\udbc0\udc00";
|
||||||
|
console.log(\u0061, \ua0081, \u0100, \u1000, \u3f80);
|
||||||
|
}
|
||||||
|
expect_exact: 'var a="\\x01";var \\ua0081="\\x10";var \\u0100="\\u0100";var \\u1000="\\u1000";var \\u1000="\\ud800\\udc00";var \\u3f80="\\udbc0\\udc00";console.log(a,\\ua0081,\\u0100,\\u1000,\\u3f80);'
|
||||||
|
expect_stdout: "\u0001 \u0010 \u0100 \ud800\udc00 \udbc0\udc00"
|
||||||
|
}
|
||||||
|
|
||||||
|
escape_non_escaped_identifier: {
|
||||||
|
beautify = {
|
||||||
|
ascii_only: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
var µþ = "µþ";
|
||||||
|
console.log(\u00b5þ);
|
||||||
|
}
|
||||||
|
expect_exact: 'var \\u00b5\\u00fe="\\xb5\\xfe";console.log(\\u00b5\\u00fe);'
|
||||||
|
expect_stdout: "µþ"
|
||||||
|
}
|
||||||
|
|
||||||
|
non_escape_2_non_escape: {
|
||||||
|
beautify = {
|
||||||
|
ascii_only: false,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
var µþ = "µþ";
|
||||||
|
console.log(\u00b5þ);
|
||||||
|
}
|
||||||
|
expect_exact: 'var µþ="µþ";console.log(µþ);'
|
||||||
|
expect_stdout: "µþ"
|
||||||
|
}
|
||||||
|
|
||||||
issue_2242_1: {
|
issue_2242_1: {
|
||||||
beautify = {
|
beautify = {
|
||||||
ascii_only: false,
|
ascii_only: false,
|
||||||
@@ -24,6 +99,7 @@ issue_2242_1: {
|
|||||||
console.log("\ud83d", "\ude00", "\ud83d\ude00", "\ud83d@\ude00");
|
console.log("\ud83d", "\ude00", "\ud83d\ude00", "\ud83d@\ude00");
|
||||||
}
|
}
|
||||||
expect_exact: 'console.log("\\ud83d","\\ude00","\ud83d\ude00","\\ud83d@\\ude00");'
|
expect_exact: 'console.log("\\ud83d","\\ude00","\ud83d\ude00","\\ud83d@\\ude00");'
|
||||||
|
expect_stdout: "\ud83d \ude00 \ud83d\ude00 \ud83d@\ude00"
|
||||||
}
|
}
|
||||||
|
|
||||||
issue_2242_2: {
|
issue_2242_2: {
|
||||||
@@ -34,6 +110,7 @@ issue_2242_2: {
|
|||||||
console.log("\ud83d", "\ude00", "\ud83d\ude00", "\ud83d@\ude00");
|
console.log("\ud83d", "\ude00", "\ud83d\ude00", "\ud83d@\ude00");
|
||||||
}
|
}
|
||||||
expect_exact: 'console.log("\\ud83d","\\ude00","\\ud83d\\ude00","\\ud83d@\\ude00");'
|
expect_exact: 'console.log("\\ud83d","\\ude00","\\ud83d\\ude00","\\ud83d@\\ude00");'
|
||||||
|
expect_stdout: "\ud83d \ude00 \ud83d\ude00 \ud83d@\ude00"
|
||||||
}
|
}
|
||||||
|
|
||||||
issue_2242_3: {
|
issue_2242_3: {
|
||||||
@@ -44,6 +121,7 @@ issue_2242_3: {
|
|||||||
console.log("\ud83d" + "\ude00", "\ud83d" + "@" + "\ude00");
|
console.log("\ud83d" + "\ude00", "\ud83d" + "@" + "\ude00");
|
||||||
}
|
}
|
||||||
expect_exact: 'console.log("\\ud83d"+"\\ude00","\\ud83d"+"@"+"\\ude00");'
|
expect_exact: 'console.log("\\ud83d"+"\\ude00","\\ud83d"+"@"+"\\ude00");'
|
||||||
|
expect_stdout: "\ud83d\ude00 \ud83d@\ude00"
|
||||||
}
|
}
|
||||||
|
|
||||||
issue_2242_4: {
|
issue_2242_4: {
|
||||||
@@ -54,6 +132,7 @@ issue_2242_4: {
|
|||||||
console.log("\ud83d" + "\ude00", "\ud83d" + "@" + "\ude00");
|
console.log("\ud83d" + "\ude00", "\ud83d" + "@" + "\ude00");
|
||||||
}
|
}
|
||||||
expect_exact: 'console.log("\ud83d\ude00","\\ud83d@\\ude00");'
|
expect_exact: 'console.log("\ud83d\ude00","\\ud83d@\\ude00");'
|
||||||
|
expect_stdout: "\ud83d\ude00 \ud83d@\ude00"
|
||||||
}
|
}
|
||||||
|
|
||||||
issue_2569: {
|
issue_2569: {
|
||||||
|
|||||||
17
test/input/issue-1482/beautify.js
Normal file
17
test/input/issue-1482/beautify.js
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
if (x) foo();
|
||||||
|
|
||||||
|
if (x) foo(); else baz();
|
||||||
|
|
||||||
|
if (x) foo(); else if (y) bar(); else baz();
|
||||||
|
|
||||||
|
if (x) if (y) foo(); else bar(); else baz();
|
||||||
|
|
||||||
|
if (x) foo(); else if (y) bar(); else if (z) baz(); else moo();
|
||||||
|
|
||||||
|
function f() {
|
||||||
|
if (x) foo();
|
||||||
|
if (x) foo(); else baz();
|
||||||
|
if (x) foo(); else if (y) bar(); else baz();
|
||||||
|
if (x) if (y) foo(); else bar(); else baz();
|
||||||
|
if (x) foo(); else if (y) bar(); else if (z) baz(); else moo();
|
||||||
|
}
|
||||||
@@ -1,17 +1 @@
|
|||||||
if (x) foo();
|
if(x)foo();if(x)foo();else baz();if(x)foo();else if(y)bar();else baz();if(x)if(y)foo();else bar();else baz();if(x)foo();else if(y)bar();else if(z)baz();else moo();function f(){if(x)foo();if(x)foo();else baz();if(x)foo();else if(y)bar();else baz();if(x)if(y)foo();else bar();else baz();if(x)foo();else if(y)bar();else if(z)baz();else moo()}
|
||||||
|
|
||||||
if (x) foo(); else baz();
|
|
||||||
|
|
||||||
if (x) foo(); else if (y) bar(); else baz();
|
|
||||||
|
|
||||||
if (x) if (y) foo(); else bar(); else baz();
|
|
||||||
|
|
||||||
if (x) foo(); else if (y) bar(); else if (z) baz(); else moo();
|
|
||||||
|
|
||||||
function f() {
|
|
||||||
if (x) foo();
|
|
||||||
if (x) foo(); else baz();
|
|
||||||
if (x) foo(); else if (y) bar(); else baz();
|
|
||||||
if (x) if (y) foo(); else bar(); else baz();
|
|
||||||
if (x) foo(); else if (y) bar(); else if (z) baz(); else moo();
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
var fs = require("fs");
|
var fs = require("fs");
|
||||||
|
|
||||||
var config = {
|
var config = {
|
||||||
limit: 5000,
|
limit: 10000,
|
||||||
timeout: function(limit) {
|
timeout: function(limit) {
|
||||||
this.limit = limit;
|
this.limit = limit;
|
||||||
}
|
}
|
||||||
@@ -55,11 +55,11 @@ process.nextTick(function run() {
|
|||||||
var elapsed = Date.now();
|
var elapsed = Date.now();
|
||||||
var timer;
|
var timer;
|
||||||
var done = function() {
|
var done = function() {
|
||||||
reset();
|
|
||||||
elapsed = Date.now() - elapsed;
|
elapsed = Date.now() - elapsed;
|
||||||
if (elapsed > task.limit) {
|
if (elapsed > task.limit) {
|
||||||
throw new Error("Timed out: " + elapsed + "ms > " + task.limit + "ms");
|
throw new Error("Timed out: " + elapsed + "ms > " + task.limit + "ms");
|
||||||
}
|
}
|
||||||
|
reset();
|
||||||
log_titles(console.log, task.titles, green('\u221A '));
|
log_titles(console.log, task.titles, green('\u221A '));
|
||||||
process.nextTick(run);
|
process.nextTick(run);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -12,7 +12,9 @@ describe("bin/uglifyjs", function() {
|
|||||||
it("Should produce a functional build when using --self", function(done) {
|
it("Should produce a functional build when using --self", function(done) {
|
||||||
this.timeout(30000);
|
this.timeout(30000);
|
||||||
var command = uglifyjscmd + ' --self -cm --wrap WrappedUglifyJS';
|
var command = uglifyjscmd + ' --self -cm --wrap WrappedUglifyJS';
|
||||||
exec(command, function(err, stdout) {
|
exec(command, {
|
||||||
|
maxBuffer: 1048576
|
||||||
|
}, function(err, stdout) {
|
||||||
if (err) throw err;
|
if (err) throw err;
|
||||||
eval(stdout);
|
eval(stdout);
|
||||||
assert.strictEqual(typeof WrappedUglifyJS, "object");
|
assert.strictEqual(typeof WrappedUglifyJS, "object");
|
||||||
@@ -174,7 +176,7 @@ describe("bin/uglifyjs", function() {
|
|||||||
var command = uglifyjscmd + ' test/input/issue-1482/input.js -b';
|
var command = uglifyjscmd + ' test/input/issue-1482/input.js -b';
|
||||||
exec(command, function(err, stdout) {
|
exec(command, function(err, stdout) {
|
||||||
if (err) throw err;
|
if (err) throw err;
|
||||||
assert.strictEqual(stdout, read("test/input/issue-1482/default.js"));
|
assert.strictEqual(stdout, read("test/input/issue-1482/beautify.js"));
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@@ -186,6 +188,22 @@ describe("bin/uglifyjs", function() {
|
|||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
it("Should work with `--output-opts`", function(done) {
|
||||||
|
var command = uglifyjscmd + ' test/input/issue-1482/input.js -O';
|
||||||
|
exec(command, function(err, stdout) {
|
||||||
|
if (err) throw err;
|
||||||
|
assert.strictEqual(stdout, read("test/input/issue-1482/default.js"));
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
it("Should fail when both --beautify & --output-opts are specified", function(done) {
|
||||||
|
var command = uglifyjscmd + " test/input/issue-520/input.js -bO";
|
||||||
|
exec(command, function(err, stdout, stderr) {
|
||||||
|
assert.ok(err);
|
||||||
|
assert.strictEqual(stderr, "ERROR: --beautify cannot be used with --output-opts\n");
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
it("Should process inline source map", function(done) {
|
it("Should process inline source map", function(done) {
|
||||||
var command = [
|
var command = [
|
||||||
uglifyjscmd,
|
uglifyjscmd,
|
||||||
|
|||||||
@@ -69,19 +69,19 @@ describe("Directives", function() {
|
|||||||
],
|
],
|
||||||
[
|
[
|
||||||
'"use \\\nstrict";"use strict";',
|
'"use \\\nstrict";"use strict";',
|
||||||
[],
|
[ "use strict" ],
|
||||||
[ "use strict", "use\nstrict", "use \nstrict", "use asm" ]
|
[ "use\nstrict", "use \nstrict", "use asm" ]
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
'"\\76";',
|
'"\\76";',
|
||||||
[],
|
[ "\\76" ],
|
||||||
[ ">", "\\76" ]
|
[ ">" ]
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
// no ; or newline
|
// no ; or newline
|
||||||
'"use strict"',
|
'"use strict"',
|
||||||
[],
|
[ "use strict" ],
|
||||||
[ "use strict", "use\nstrict", "use \nstrict", "use asm" ]
|
[ "use\nstrict", "use \nstrict", "use asm" ]
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
';"use strict"',
|
';"use strict"',
|
||||||
@@ -106,18 +106,18 @@ describe("Directives", function() {
|
|||||||
],
|
],
|
||||||
[
|
[
|
||||||
'function foo() {"use \\\nstrict";"use strict";',
|
'function foo() {"use \\\nstrict";"use strict";',
|
||||||
[],
|
[ "use strict" ],
|
||||||
[ "use strict", "use\nstrict", "use \nstrict", "use asm" ]
|
[ "use\nstrict", "use \nstrict", "use asm" ]
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
'var foo = function() {"\\76";',
|
'var foo = function() {"\\76";',
|
||||||
[],
|
[ "\\76" ],
|
||||||
[ ">", "\\76" ]
|
[ ">" ]
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
'var foo = function() {"use strict"', // no ; or newline
|
'var foo = function() {"use strict"', // no ; or newline
|
||||||
[],
|
[ "use strict" ],
|
||||||
[ "use strict", "use\nstrict", "use \nstrict", "use asm" ]
|
[ "use\nstrict", "use \nstrict", "use asm" ]
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
'var foo = function() {;"use strict"',
|
'var foo = function() {;"use strict"',
|
||||||
@@ -156,21 +156,24 @@ describe("Directives", function() {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
it("Should test EXPECT_DIRECTIVE RegExp", function() {
|
it("Should print semicolon to separate strings from directives", function() {
|
||||||
[
|
[
|
||||||
[ "", true ],
|
[ "", ';"";' ],
|
||||||
[ "'test';", true ],
|
[ '"test";', '"test";;"";' ],
|
||||||
[ "'test';;", true ],
|
[ '"test";;', '"test";;"";' ],
|
||||||
[ "'tests';\n", true ],
|
[ '"tests";\n', '"tests";;"";' ],
|
||||||
[ "'tests'", false ],
|
[ '"tests"', '"tests";;"";' ],
|
||||||
[ "'tests'; \n\t", true ],
|
[ '"tests"; \n\t', '"tests";;"";' ],
|
||||||
[ "'tests';\n\n", true ],
|
[ '"tests";\n\n', '"tests";;"";' ],
|
||||||
[ "\n\n\"use strict\";\n\n", true ],
|
[ '\n\n"use strict";\n\n', '"use strict";;"";' ],
|
||||||
].forEach(function(test) {
|
].forEach(function(test) {
|
||||||
|
var ast = UglifyJS.parse(test[0]);
|
||||||
|
ast.body.push(new UglifyJS.AST_SimpleStatement({
|
||||||
|
body: new UglifyJS.AST_String({ value: "" })
|
||||||
|
}));
|
||||||
var out = UglifyJS.OutputStream();
|
var out = UglifyJS.OutputStream();
|
||||||
out.print(test[0]);
|
ast.print(out);
|
||||||
out.print_string("", null, true);
|
assert.strictEqual(out.get(), test[1], test[0]);
|
||||||
assert.strictEqual(out.get() === test[0] + ';""', test[1], test[0]);
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
it("Should only print 2 semicolons spread over 2 lines in beautify mode", function() {
|
it("Should only print 2 semicolons spread over 2 lines in beautify mode", function() {
|
||||||
@@ -178,8 +181,8 @@ describe("Directives", function() {
|
|||||||
'"use strict";',
|
'"use strict";',
|
||||||
"'use strict';",
|
"'use strict';",
|
||||||
'"use strict";',
|
'"use strict";',
|
||||||
'"use strict";;',
|
'"use strict";',
|
||||||
"'use strict';",
|
";'use strict';",
|
||||||
"console.log('use strict');"
|
"console.log('use strict');"
|
||||||
].join(""), {
|
].join(""), {
|
||||||
compress: false,
|
compress: false,
|
||||||
@@ -201,19 +204,23 @@ describe("Directives", function() {
|
|||||||
it("Should not add double semicolons in non-scoped block statements to avoid strings becoming directives", function() {
|
it("Should not add double semicolons in non-scoped block statements to avoid strings becoming directives", function() {
|
||||||
[
|
[
|
||||||
[
|
[
|
||||||
'{"use\x20strict"}',
|
'"use strict";"use\\x20strict";',
|
||||||
|
'"use strict";"use\\x20strict";'
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'{"use\\x20strict"}',
|
||||||
'{"use strict"}'
|
'{"use strict"}'
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
'function foo(){"use\x20strict";}', // Valid place for directives
|
'function foo(){"use\\x20strict";}', // Valid place for directives
|
||||||
'function foo(){"use strict"}'
|
'function foo(){"use\\x20strict"}'
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
'try{"use\x20strict"}catch(e){}finally{"use\x20strict"}',
|
'try{"use\\x20strict"}catch(e){}finally{"use\\x20strict"}',
|
||||||
'try{"use strict"}catch(e){}finally{"use strict"}'
|
'try{"use strict"}catch(e){}finally{"use strict"}'
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
'if(1){"use\x20strict"} else {"use strict"}',
|
'if(1){"use\\x20strict"} else {"use strict"}',
|
||||||
'if(1){"use strict"}else{"use strict"}'
|
'if(1){"use strict"}else{"use strict"}'
|
||||||
]
|
]
|
||||||
].forEach(function(test) {
|
].forEach(function(test) {
|
||||||
@@ -225,16 +232,6 @@ describe("Directives", function() {
|
|||||||
assert.strictEqual(result.code, test[1], test[0]);
|
assert.strictEqual(result.code, test[1], test[0]);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
it("Should add double semicolon when relying on automatic semicolon insertion", function() {
|
|
||||||
var result = UglifyJS.minify('"use strict";"use\\x20strict";', {
|
|
||||||
compress: false,
|
|
||||||
output: {
|
|
||||||
semicolons: false
|
|
||||||
}
|
|
||||||
});
|
|
||||||
if (result.error) throw result.error;
|
|
||||||
assert.strictEqual(result.code, '"use strict";;"use strict"\n');
|
|
||||||
});
|
|
||||||
it("Should check quote style of directives", function() {
|
it("Should check quote style of directives", function() {
|
||||||
[
|
[
|
||||||
// 0. Prefer double quotes, unless string contains more double quotes than single quotes
|
// 0. Prefer double quotes, unless string contains more double quotes than single quotes
|
||||||
@@ -249,9 +246,9 @@ describe("Directives", function() {
|
|||||||
'"use strict";'
|
'"use strict";'
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
'"\\\'use strict\\\'";', // Not a directive as it contains quotes
|
'"\\\'use strict\\\'";',
|
||||||
0,
|
0,
|
||||||
';"\'use strict\'";',
|
'"\\\'use strict\\\'";',
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
"'\"use strict\"';",
|
"'\"use strict\"';",
|
||||||
@@ -273,7 +270,7 @@ describe("Directives", function() {
|
|||||||
'"\'use strict\'";',
|
'"\'use strict\'";',
|
||||||
1,
|
1,
|
||||||
// Intentionally causes directive breakage at cost of less logic, usage should be rare anyway
|
// Intentionally causes directive breakage at cost of less logic, usage should be rare anyway
|
||||||
"'\\'use strict\\'';",
|
'"\'use strict\'";',
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
"'\\'use strict\\'';", // Not a valid directive
|
"'\\'use strict\\'';", // Not a valid directive
|
||||||
@@ -305,7 +302,7 @@ describe("Directives", function() {
|
|||||||
"'\"use strict\"';",
|
"'\"use strict\"';",
|
||||||
2,
|
2,
|
||||||
// Intentionally causes directive breakage at cost of less logic, usage should be rare anyway
|
// Intentionally causes directive breakage at cost of less logic, usage should be rare anyway
|
||||||
'"\\\"use strict\\\"";',
|
"'\"use strict\"';",
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
'"\\"use strict\\"";', // Not a valid directive
|
'"\\"use strict\\"";', // Not a valid directive
|
||||||
@@ -353,8 +350,7 @@ describe("Directives", function() {
|
|||||||
[
|
[
|
||||||
// Nothing gets optimised in the compressor because "use asm" is the first statement
|
// Nothing gets optimised in the compressor because "use asm" is the first statement
|
||||||
'"use asm";"use\\x20strict";1+1;',
|
'"use asm";"use\\x20strict";1+1;',
|
||||||
// Yet, the parser noticed that "use strict" wasn't a directive
|
'"use asm";"use\\x20strict";1+1;'
|
||||||
'"use asm";;"use strict";1+1;',
|
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
'function f(){ "use strict" }',
|
'function f(){ "use strict" }',
|
||||||
|
|||||||
@@ -2,10 +2,18 @@ var assert = require("assert");
|
|||||||
var UglifyJS = require("../node");
|
var UglifyJS = require("../node");
|
||||||
|
|
||||||
describe("Number literals", function() {
|
describe("Number literals", function() {
|
||||||
|
it("Should allow legacy octal literals in non-strict mode", function() {
|
||||||
|
[
|
||||||
|
"'use strict'\n.slice()\n00",
|
||||||
|
'"use strict"\n.slice()\nvar foo = 00',
|
||||||
|
].forEach(function(input) {
|
||||||
|
UglifyJS.parse(input);
|
||||||
|
});
|
||||||
|
});
|
||||||
it("Should not allow legacy octal literals in strict mode", function() {
|
it("Should not allow legacy octal literals in strict mode", function() {
|
||||||
var inputs = [
|
var inputs = [
|
||||||
'"use strict";00;',
|
'"use strict";00;',
|
||||||
'"use strict"; var foo = 00;'
|
'"use strict"; var foo = 00;',
|
||||||
];
|
];
|
||||||
var test = function(input) {
|
var test = function(input) {
|
||||||
return function() {
|
return function() {
|
||||||
|
|||||||
@@ -10,7 +10,9 @@ describe("spidermonkey export/import sanity test", function() {
|
|||||||
var command = uglifyjs + " --self -cm --wrap SpiderUglify -o spidermonkey | " +
|
var command = uglifyjs + " --self -cm --wrap SpiderUglify -o spidermonkey | " +
|
||||||
uglifyjs + " -p spidermonkey -cm";
|
uglifyjs + " -p spidermonkey -cm";
|
||||||
|
|
||||||
exec(command, function(err, stdout) {
|
exec(command, {
|
||||||
|
maxBuffer: 1048576
|
||||||
|
}, function(err, stdout) {
|
||||||
if (err) throw err;
|
if (err) throw err;
|
||||||
|
|
||||||
eval(stdout);
|
eval(stdout);
|
||||||
|
|||||||
@@ -59,13 +59,13 @@ describe("String literals", function() {
|
|||||||
|
|
||||||
it("Should not throw error outside strict mode if string contains escaped octalIntegerLiteral", function() {
|
it("Should not throw error outside strict mode if string contains escaped octalIntegerLiteral", function() {
|
||||||
var tests = [
|
var tests = [
|
||||||
['"\\76";', ';">";'],
|
[ ';"\\76";', ';">";' ],
|
||||||
['"\\0"', '"\\0";'],
|
[ ';"\\0";', ';"\\0";' ],
|
||||||
['"\\08"', '"\\x008";'],
|
[ ';"\\08"', ';"\\x008";' ],
|
||||||
['"\\008"', '"\\x008";'],
|
[ ';"\\008"', ';"\\x008";' ],
|
||||||
['"\\0008"', '"\\x008";'],
|
[ ';"\\0008"', ';"\\x008";' ],
|
||||||
|
[ ';"use\\\n strict";\n"\\07";', ';"use strict";"\07";' ],
|
||||||
[ '"use strict" === "use strict";\n"\\76";', '"use strict"==="use strict";">";' ],
|
[ '"use strict" === "use strict";\n"\\76";', '"use strict"==="use strict";">";' ],
|
||||||
['"use\\\n strict";\n"\\07";', ';"use strict";"\07";']
|
|
||||||
];
|
];
|
||||||
|
|
||||||
for (var test in tests) {
|
for (var test in tests) {
|
||||||
@@ -75,8 +75,8 @@ describe("String literals", function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it("Should not throw error when digit is 8 or 9", function() {
|
it("Should not throw error when digit is 8 or 9", function() {
|
||||||
assert.equal(UglifyJS.parse('"use strict";"\\08"').print_to_string(), '"use strict";"\\x008";');
|
assert.equal(UglifyJS.parse('"use strict";;"\\08"').print_to_string(), '"use strict";;"\\x008";');
|
||||||
assert.equal(UglifyJS.parse('"use strict";"\\09"').print_to_string(), '"use strict";"\\x009";');
|
assert.equal(UglifyJS.parse('"use strict";;"\\09"').print_to_string(), '"use strict";;"\\x009";');
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should not unescape unpaired surrogates", function() {
|
it("Should not unescape unpaired surrogates", function() {
|
||||||
@@ -93,7 +93,7 @@ describe("String literals", function() {
|
|||||||
for (; i <= 0xFFFF; i++) {
|
for (; i <= 0xFFFF; i++) {
|
||||||
code.push("\\u" + i.toString(16));
|
code.push("\\u" + i.toString(16));
|
||||||
}
|
}
|
||||||
code = '"' + code.join() + '"';
|
code = ';"' + code.join() + '"';
|
||||||
var normal = UglifyJS.minify(code, {
|
var normal = UglifyJS.minify(code, {
|
||||||
compress: false,
|
compress: false,
|
||||||
mangle: false,
|
mangle: false,
|
||||||
|
|||||||
@@ -1089,6 +1089,20 @@ function log(options) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function fuzzy_match(original, uglified) {
|
||||||
|
uglified = uglified.split(" ");
|
||||||
|
var i = uglified.length;
|
||||||
|
original = original.split(" ", i);
|
||||||
|
while (--i >= 0) {
|
||||||
|
if (original[i] === uglified[i]) continue;
|
||||||
|
var a = +original[i];
|
||||||
|
var b = +uglified[i];
|
||||||
|
if (Math.abs((b - a) / a) < 1e-10) continue;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
var fallback_options = [ JSON.stringify({
|
var fallback_options = [ JSON.stringify({
|
||||||
compress: false,
|
compress: false,
|
||||||
mangle: false
|
mangle: false
|
||||||
@@ -1111,8 +1125,12 @@ for (var round = 1; round <= num_iterations; round++) {
|
|||||||
uglify_code = uglify_code.code;
|
uglify_code = uglify_code.code;
|
||||||
uglify_result = sandbox.run_code(uglify_code, o.toplevel);
|
uglify_result = sandbox.run_code(uglify_code, o.toplevel);
|
||||||
ok = sandbox.same_stdout(original_result, uglify_result);
|
ok = sandbox.same_stdout(original_result, uglify_result);
|
||||||
if (!ok && o.compress.unsafe_math) {
|
if (!ok && typeof uglify_result == "string" && o.compress.unsafe_math) {
|
||||||
ok = sandbox.same_stdout(sandbox.run_code(original_code.replace(/( - 0\.1){3}/g, " - 0.3")), uglify_result, o.toplevel);
|
ok = fuzzy_match(original_result, uglify_result);
|
||||||
|
if (!ok) {
|
||||||
|
var fuzzy_result = sandbox.run_code(original_code.replace(/( - 0\.1){3}/g, " - 0.3"));
|
||||||
|
ok = sandbox.same_stdout(fuzzy_result, uglify_result);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
uglify_code = uglify_code.error;
|
uglify_code = uglify_code.error;
|
||||||
|
|||||||
@@ -12,17 +12,16 @@ function spawn(endTime) {
|
|||||||
], {
|
], {
|
||||||
stdio: [ "ignore", "pipe", "pipe" ]
|
stdio: [ "ignore", "pipe", "pipe" ]
|
||||||
}).on("exit", respawn);
|
}).on("exit", respawn);
|
||||||
var line = "";
|
var stdout = "";
|
||||||
child.stdout.on("data", function(data) {
|
child.stdout.on("data", function(data) {
|
||||||
line += data;
|
stdout += data;
|
||||||
});
|
});
|
||||||
child.stderr.once("data", function() {
|
var stderr = "";
|
||||||
process.exitCode = 1;
|
child.stderr.on("data", trap).pipe(process.stdout);
|
||||||
}).pipe(process.stdout);
|
|
||||||
var keepAlive = setInterval(function() {
|
var keepAlive = setInterval(function() {
|
||||||
var end = line.lastIndexOf("\r");
|
var end = stdout.lastIndexOf("\r");
|
||||||
console.log(line.slice(line.lastIndexOf("\r", end - 1) + 1, end));
|
console.log(stdout.slice(stdout.lastIndexOf("\r", end - 1) + 1, end));
|
||||||
line = line.slice(end + 1);
|
stdout = stdout.slice(end + 1);
|
||||||
}, ping);
|
}, ping);
|
||||||
var timer = setTimeout(function() {
|
var timer = setTimeout(function() {
|
||||||
clearInterval(keepAlive);
|
clearInterval(keepAlive);
|
||||||
@@ -31,9 +30,17 @@ function spawn(endTime) {
|
|||||||
}, endTime - Date.now());
|
}, endTime - Date.now());
|
||||||
|
|
||||||
function respawn() {
|
function respawn() {
|
||||||
console.log(line);
|
console.log(stdout.replace(/[^\r\n]*\r/g, ""));
|
||||||
clearInterval(keepAlive);
|
clearInterval(keepAlive);
|
||||||
clearTimeout(timer);
|
clearTimeout(timer);
|
||||||
spawn(endTime);
|
spawn(endTime);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function trap(data) {
|
||||||
|
stderr += data;
|
||||||
|
if (~stderr.indexOf("\nminify(options):\n")) {
|
||||||
|
process.exitCode = 1;
|
||||||
|
child.stderr.removeListener("data", trap);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,44 +0,0 @@
|
|||||||
"use strict";
|
|
||||||
|
|
||||||
var child_process = require("child_process");
|
|
||||||
var https = require("https");
|
|
||||||
var url = require("url");
|
|
||||||
|
|
||||||
var period = 45 * 60 * 1000;
|
|
||||||
var wait = 2 * 60 * 1000;
|
|
||||||
if (process.argv.length > 2) {
|
|
||||||
var token = process.argv[2];
|
|
||||||
var branch = process.argv[3] || "v" + require("../../package.json").version;
|
|
||||||
var repository = encodeURIComponent(process.argv[4] || "mishoo/UglifyJS2");
|
|
||||||
var concurrency = process.argv[5] || 1;
|
|
||||||
var platform = process.argv[6] || "latest";
|
|
||||||
(function request() {
|
|
||||||
setTimeout(request, (period + wait) / concurrency);
|
|
||||||
var options = url.parse("https://api.travis-ci.org/repo/" + repository + "/requests");
|
|
||||||
options.method = "POST";
|
|
||||||
options.headers = {
|
|
||||||
"Content-Type": "application/json",
|
|
||||||
"Travis-API-Version": 3,
|
|
||||||
"Authorization": "token " + token
|
|
||||||
};
|
|
||||||
https.request(options, function(res) {
|
|
||||||
console.log("HTTP", res.statusCode);
|
|
||||||
console.log(JSON.stringify(res.headers, null, 2));
|
|
||||||
console.log();
|
|
||||||
res.setEncoding("utf8");
|
|
||||||
res.on("data", console.log);
|
|
||||||
}).on("error", console.error).end(JSON.stringify({
|
|
||||||
request: {
|
|
||||||
message: "ufuzz testing",
|
|
||||||
branch: branch,
|
|
||||||
config: {
|
|
||||||
cache: false,
|
|
||||||
env: "NODE=" + platform,
|
|
||||||
script: "node test/ufuzz/job " + period
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}));
|
|
||||||
})();
|
|
||||||
} else {
|
|
||||||
console.log("Usage: test/ufuzz/travis.js <token> [branch] [repository] [concurrency] [platform]");
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user