Compare commits
92 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
02cc4a0d03 | ||
|
|
4e06e1ca34 | ||
|
|
644f65feca | ||
|
|
8504a4ea0e | ||
|
|
10c1a78772 | ||
|
|
a6a0319f1c | ||
|
|
d1b2ecec27 | ||
|
|
552be61c4d | ||
|
|
dcfc4aca5b | ||
|
|
4027f87717 | ||
|
|
910799ca99 | ||
|
|
4bd36dc8da | ||
|
|
ab15c40770 | ||
|
|
fe65ce9658 | ||
|
|
d6fd18d0b0 | ||
|
|
0d17c5b0fa | ||
|
|
5b20bad4b3 | ||
|
|
765a06340f | ||
|
|
5045e140b1 | ||
|
|
10648c9af6 | ||
|
|
87e67ec299 | ||
|
|
61a0dad9fe | ||
|
|
3e2c51a4da | ||
|
|
0e29ad5eb9 | ||
|
|
0f2687ecfc | ||
|
|
1c0defdc03 | ||
|
|
dcbf2236c7 | ||
|
|
24bb288832 | ||
|
|
6ad8e1081f | ||
|
|
815eff1f7c | ||
|
|
1e9b576ee9 | ||
|
|
3797458365 | ||
|
|
1858c2018c | ||
|
|
ec7f071272 | ||
|
|
f1eb03f2c0 | ||
|
|
0f4cfa877a | ||
|
|
1d5c2becbd | ||
|
|
22a09ea7c5 | ||
|
|
bad664c632 | ||
|
|
8a191c0a84 | ||
|
|
83fb8b4ca1 | ||
|
|
f38e31bd1e | ||
|
|
24e8b47977 | ||
|
|
95618793a4 | ||
|
|
2f3b460212 | ||
|
|
06e135e35f | ||
|
|
ebbf3d4a51 | ||
|
|
a270ba6b59 | ||
|
|
37f35e4ac2 | ||
|
|
50a578c1f6 | ||
|
|
85237b08d4 | ||
|
|
27b159e711 | ||
|
|
82b3eed5ef | ||
|
|
0f7aa41e33 | ||
|
|
370c8e0385 | ||
|
|
4240fba9b8 | ||
|
|
267bc70d33 | ||
|
|
a53ab99378 | ||
|
|
02308a7b56 | ||
|
|
0b3705e82f | ||
|
|
da5a21b240 | ||
|
|
5bd0cf8633 | ||
|
|
9199ab5846 | ||
|
|
ca6dce43fe | ||
|
|
543dd7d3d7 | ||
|
|
6b4886c908 | ||
|
|
0201cb4b52 | ||
|
|
cd072317d0 | ||
|
|
0785a15ace | ||
|
|
b1279a46d9 | ||
|
|
b571619d31 | ||
|
|
7b5350b459 | ||
|
|
1549db70e6 | ||
|
|
8ff9a3c8fb | ||
|
|
91cae51d8f | ||
|
|
8af2f5fbcf | ||
|
|
86a8016323 | ||
|
|
009dcdae01 | ||
|
|
f86f615d83 | ||
|
|
d3d1d11926 | ||
|
|
736019b767 | ||
|
|
a39bdb5840 | ||
|
|
e8ab0a44b2 | ||
|
|
c3ca293e6b | ||
|
|
516b67a43b | ||
|
|
eba3a37bb5 | ||
|
|
6d57ca1a59 | ||
|
|
3320251b4b | ||
|
|
33c94d3bd9 | ||
|
|
b18f717b46 | ||
|
|
a0d4b648bb | ||
|
|
6db880e16d |
31
.github/workflows/ci.yml
vendored
Normal file
31
.github/workflows/ci.yml
vendored
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
name: CI
|
||||||
|
on: [ push, pull_request ]
|
||||||
|
jobs:
|
||||||
|
test:
|
||||||
|
strategy:
|
||||||
|
matrix:
|
||||||
|
os: [ ubuntu-latest, windows-latest ]
|
||||||
|
node: [ "0.10", 0.12, 4, 6, 8, 10, latest ]
|
||||||
|
script: [ compress, mocha, release/benchmark, release/jetstream ]
|
||||||
|
name: ${{ matrix.os }} ${{ matrix.node }} ${{ matrix.script }}
|
||||||
|
runs-on: ${{ matrix.os }}
|
||||||
|
env:
|
||||||
|
NODE: ${{ matrix.node }}
|
||||||
|
TYPE: ${{ matrix.script }}
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v1
|
||||||
|
- uses: actions/cache@v1
|
||||||
|
with:
|
||||||
|
path: tmp
|
||||||
|
key: tmp ${{ matrix.script }}
|
||||||
|
- name: Perform tests
|
||||||
|
shell: bash
|
||||||
|
run: |
|
||||||
|
git clone --branch v1.5.3 --depth 1 https://github.com/jasongin/nvs.git ~/.nvs
|
||||||
|
. ~/.nvs/nvs.sh --version
|
||||||
|
nvs add $NODE
|
||||||
|
nvs use $NODE
|
||||||
|
node --version
|
||||||
|
npm --version --no-update-notifier
|
||||||
|
npm install --no-audit --no-optional --no-save --no-update-notifier
|
||||||
|
node test/$TYPE
|
||||||
25
.github/workflows/ufuzz.yml
vendored
Normal file
25
.github/workflows/ufuzz.yml
vendored
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
name: Fuzzing
|
||||||
|
on:
|
||||||
|
schedule:
|
||||||
|
- cron: "*/15 * * * *"
|
||||||
|
jobs:
|
||||||
|
ufuzz:
|
||||||
|
strategy:
|
||||||
|
fail-fast: false
|
||||||
|
matrix:
|
||||||
|
os: [ ubuntu-latest, windows-latest ]
|
||||||
|
name: ${{ matrix.os }}
|
||||||
|
runs-on: ${{ matrix.os }}
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v1
|
||||||
|
- name: Perform fuzzing
|
||||||
|
shell: bash
|
||||||
|
run: |
|
||||||
|
git clone --branch v1.5.3 --depth 1 https://github.com/jasongin/nvs.git ~/.nvs
|
||||||
|
. ~/.nvs/nvs.sh --version
|
||||||
|
nvs add node
|
||||||
|
nvs use node
|
||||||
|
node --version
|
||||||
|
npm --version --no-update-notifier
|
||||||
|
npm install --no-audit --no-optional --no-save --no-update-notifier
|
||||||
|
node test/ufuzz/job 3600000
|
||||||
46
.travis.yml
46
.travis.yml
@@ -1,46 +0,0 @@
|
|||||||
cache:
|
|
||||||
directories: tmp
|
|
||||||
language: generic
|
|
||||||
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
|
|
||||||
47
README.md
47
README.md
@@ -478,42 +478,42 @@ if (result.error) throw result.error;
|
|||||||
|
|
||||||
## Minify options
|
## Minify options
|
||||||
|
|
||||||
- `warnings` (default `false`) — pass `true` to return compressor warnings
|
|
||||||
in `result.warnings`. Use the value `"verbose"` for more detailed warnings.
|
|
||||||
|
|
||||||
- `parse` (default `{}`) — pass an object if you wish to specify some
|
|
||||||
additional [parse options](#parse-options).
|
|
||||||
|
|
||||||
- `compress` (default `{}`) — pass `false` to skip compressing entirely.
|
- `compress` (default `{}`) — pass `false` to skip compressing entirely.
|
||||||
Pass an object to specify custom [compress options](#compress-options).
|
Pass an object to specify custom [compress options](#compress-options).
|
||||||
|
|
||||||
|
- `ie8` (default `false`) -- set to `true` to support IE8.
|
||||||
|
|
||||||
|
- `keep_fnames` (default: `false`) -- pass `true` to prevent discarding or mangling
|
||||||
|
of function names. Useful for code relying on `Function.prototype.name`.
|
||||||
|
|
||||||
- `mangle` (default `true`) — pass `false` to skip mangling names, or pass
|
- `mangle` (default `true`) — pass `false` to skip mangling names, or pass
|
||||||
an object to specify [mangle options](#mangle-options) (see below).
|
an object to specify [mangle options](#mangle-options) (see below).
|
||||||
|
|
||||||
- `mangle.properties` (default `false`) — a subcategory of the mangle option.
|
- `mangle.properties` (default `false`) — a subcategory of the mangle option.
|
||||||
Pass an object to specify custom [mangle property options](#mangle-properties-options).
|
Pass an object to specify custom [mangle property options](#mangle-properties-options).
|
||||||
|
|
||||||
- `output` (default `null`) — pass an object if you wish to specify
|
- `nameCache` (default `null`) -- pass an empty object `{}` or a previously
|
||||||
additional [output options](#output-options). The defaults are optimized
|
|
||||||
for best compression.
|
|
||||||
|
|
||||||
- `sourceMap` (default `false`) - pass an object if you wish to specify
|
|
||||||
[source map options](#source-map-options).
|
|
||||||
|
|
||||||
- `toplevel` (default `false`) - set to `true` if you wish to enable top level
|
|
||||||
variable and function name mangling and to drop unused variables and functions.
|
|
||||||
|
|
||||||
- `nameCache` (default `null`) - pass an empty object `{}` or a previously
|
|
||||||
used `nameCache` object if you wish to cache mangled variable and
|
used `nameCache` object if you wish to cache mangled variable and
|
||||||
property names across multiple invocations of `minify()`. Note: this is
|
property names across multiple invocations of `minify()`. Note: this is
|
||||||
a read/write property. `minify()` will read the name cache state of this
|
a read/write property. `minify()` will read the name cache state of this
|
||||||
object and update it during minification so that it may be
|
object and update it during minification so that it may be
|
||||||
reused or externally persisted by the user.
|
reused or externally persisted by the user.
|
||||||
|
|
||||||
- `ie8` (default `false`) - set to `true` to support IE8.
|
- `output` (default `null`) — pass an object if you wish to specify
|
||||||
|
additional [output options](#output-options). The defaults are optimized
|
||||||
|
for best compression.
|
||||||
|
|
||||||
- `keep_fnames` (default: `false`) - pass `true` to prevent discarding or mangling
|
- `parse` (default `{}`) — pass an object if you wish to specify some
|
||||||
of function names. Useful for code relying on `Function.prototype.name`.
|
additional [parse options](#parse-options).
|
||||||
|
|
||||||
|
- `sourceMap` (default `false`) -- pass an object if you wish to specify
|
||||||
|
[source map options](#source-map-options).
|
||||||
|
|
||||||
|
- `toplevel` (default `false`) -- set to `true` if you wish to enable top level
|
||||||
|
variable and function name mangling and to drop unused variables and functions.
|
||||||
|
|
||||||
|
- `warnings` (default `false`) — pass `true` to return compressor warnings
|
||||||
|
in `result.warnings`. Use the value `"verbose"` for more detailed warnings.
|
||||||
|
|
||||||
## Minify options structure
|
## Minify options structure
|
||||||
|
|
||||||
@@ -631,7 +631,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.
|
||||||
@@ -682,6 +685,8 @@ If you're using the `X-SourceMap` header instead, you can just omit `sourceMap.u
|
|||||||
where the return value is discarded, to avoid the parens that the
|
where the return value is discarded, to avoid the parens that the
|
||||||
code generator would insert.
|
code generator would insert.
|
||||||
|
|
||||||
|
- `objects` (default: `true`) -- compact duplicate keys in object literals.
|
||||||
|
|
||||||
- `passes` (default: `1`) -- The maximum number of times to run compress.
|
- `passes` (default: `1`) -- The maximum number of times to run compress.
|
||||||
In some cases more than one pass leads to further compressed code. Keep in
|
In some cases more than one pass leads to further compressed code. Keep in
|
||||||
mind more passes will take more time.
|
mind more passes will take more time.
|
||||||
|
|||||||
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
|
||||||
|
|||||||
12
lib/ast.js
12
lib/ast.js
@@ -837,11 +837,10 @@ var AST_String = DEFNODE("String", "value quote", {
|
|||||||
}
|
}
|
||||||
}, AST_Constant);
|
}, AST_Constant);
|
||||||
|
|
||||||
var AST_Number = DEFNODE("Number", "value literal", {
|
var AST_Number = DEFNODE("Number", "value", {
|
||||||
$documentation: "A number literal",
|
$documentation: "A number literal",
|
||||||
$propdoc: {
|
$propdoc: {
|
||||||
value: "[number] the numeric value",
|
value: "[number] the numeric value",
|
||||||
literal: "[string] numeric value as string (optional)"
|
|
||||||
}
|
}
|
||||||
}, AST_Constant);
|
}, AST_Constant);
|
||||||
|
|
||||||
@@ -980,6 +979,15 @@ TreeWalker.prototype = {
|
|||||||
|| p instanceof AST_Conditional
|
|| p instanceof AST_Conditional
|
||||||
|| p.tail_node() === self) {
|
|| p.tail_node() === self) {
|
||||||
self = p;
|
self = p;
|
||||||
|
} else if (p instanceof AST_Return) {
|
||||||
|
var fn;
|
||||||
|
do {
|
||||||
|
fn = this.parent(++i);
|
||||||
|
if (!fn) return false;
|
||||||
|
} while (!(fn instanceof AST_Lambda));
|
||||||
|
if (fn.name) return false;
|
||||||
|
self = this.parent(++i);
|
||||||
|
if (!self || self.TYPE != "Call" || self.expression !== fn) return false;
|
||||||
} else {
|
} else {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|||||||
992
lib/compress.js
992
lib/compress.js
File diff suppressed because it is too large
Load Diff
@@ -1,19 +1,39 @@
|
|||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
var to_ascii = typeof atob == "undefined" ? function(b64) {
|
var to_ascii, to_base64;
|
||||||
return new Buffer(b64, "base64").toString();
|
if (typeof Buffer == "undefined") {
|
||||||
} : atob;
|
to_ascii = atob;
|
||||||
var to_base64 = typeof btoa == "undefined" ? function(str) {
|
to_base64 = btoa;
|
||||||
return new Buffer(str).toString("base64");
|
} else if (typeof Buffer.alloc == "undefined") {
|
||||||
} : btoa;
|
to_ascii = function(b64) {
|
||||||
|
return new Buffer(b64, "base64").toString();
|
||||||
|
};
|
||||||
|
to_base64 = function(str) {
|
||||||
|
return new Buffer(str).toString("base64");
|
||||||
|
};
|
||||||
|
} else {
|
||||||
|
to_ascii = function(b64) {
|
||||||
|
return Buffer.from(b64, "base64").toString();
|
||||||
|
};
|
||||||
|
to_base64 = function(str) {
|
||||||
|
return Buffer.from(str).toString("base64");
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
function read_source_map(name, code) {
|
function read_source_map(name, toplevel) {
|
||||||
var match = /\n\/\/# sourceMappingURL=data:application\/json(;.*?)?;base64,(\S+)\s*$/.exec(code);
|
var comments = toplevel.end.comments_after;
|
||||||
if (!match) {
|
for (var i = comments.length; --i >= 0;) {
|
||||||
AST_Node.warn("inline source map not found: " + name);
|
var comment = comments[i];
|
||||||
return null;
|
if (comment.type != "comment1") break;
|
||||||
|
var match = /^# ([^\s=]+)=(\S+)\s*$/.exec(comment.value);
|
||||||
|
if (!match) break;
|
||||||
|
if (match[1] == "sourceMappingURL") {
|
||||||
|
match = /^data:application\/json(;.*?)?;base64,(\S+)$/.exec(match[2]);
|
||||||
|
if (!match) break;
|
||||||
|
return to_ascii(match[2]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return to_ascii(match[2]);
|
AST_Node.warn("inline source map not found: " + name);
|
||||||
}
|
}
|
||||||
|
|
||||||
function parse_source_map(content) {
|
function parse_source_map(content) {
|
||||||
@@ -134,10 +154,10 @@ function minify(files, options) {
|
|||||||
source_maps = source_map_content && Object.create(null);
|
source_maps = source_map_content && Object.create(null);
|
||||||
for (var name in files) if (HOP(files, name)) {
|
for (var name in files) if (HOP(files, name)) {
|
||||||
options.parse.filename = name;
|
options.parse.filename = name;
|
||||||
options.parse.toplevel = parse(files[name], options.parse);
|
options.parse.toplevel = toplevel = parse(files[name], options.parse);
|
||||||
if (source_maps) {
|
if (source_maps) {
|
||||||
if (source_map_content == "inline") {
|
if (source_map_content == "inline") {
|
||||||
var inlined_content = read_source_map(name, files[name]);
|
var inlined_content = read_source_map(name, toplevel);
|
||||||
if (inlined_content) {
|
if (inlined_content) {
|
||||||
source_maps[name] = parse_source_map(inlined_content);
|
source_maps[name] = parse_source_map(inlined_content);
|
||||||
}
|
}
|
||||||
@@ -146,7 +166,6 @@ function minify(files, options) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
toplevel = options.parse.toplevel;
|
|
||||||
}
|
}
|
||||||
if (quoted_props) {
|
if (quoted_props) {
|
||||||
reserve_quoted_keys(toplevel, quoted_props);
|
reserve_quoted_keys(toplevel, quoted_props);
|
||||||
@@ -233,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;
|
||||||
|
|||||||
@@ -403,7 +403,7 @@
|
|||||||
var def = M.definition();
|
var def = M.definition();
|
||||||
return {
|
return {
|
||||||
type: "Identifier",
|
type: "Identifier",
|
||||||
name: def ? def.mangled_name || def.name : M.name
|
name: def && def.mangled_name || M.name
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -91,13 +91,11 @@ function OutputStream(options) {
|
|||||||
comment_filter = function(comment) {
|
comment_filter = function(comment) {
|
||||||
return comment.type != "comment5" && comments.test(comment.value);
|
return comment.type != "comment5" && comments.test(comment.value);
|
||||||
};
|
};
|
||||||
}
|
} else if (typeof comments === "function") {
|
||||||
else if (typeof comments === "function") {
|
|
||||||
comment_filter = function(comment) {
|
comment_filter = function(comment) {
|
||||||
return comment.type != "comment5" && comments(this, comment);
|
return comment.type != "comment5" && comments(this, comment);
|
||||||
};
|
};
|
||||||
}
|
} else if (comments === "some") {
|
||||||
else if (comments === "some") {
|
|
||||||
comment_filter = is_some_comments;
|
comment_filter = is_some_comments;
|
||||||
} else { // NOTE includes "all" option
|
} else { // NOTE includes "all" option
|
||||||
comment_filter = return_true;
|
comment_filter = return_true;
|
||||||
@@ -452,7 +450,7 @@ function OutputStream(options) {
|
|||||||
var self = this;
|
var self = this;
|
||||||
var scan = node instanceof AST_Exit && node.value;
|
var scan = node instanceof AST_Exit && node.value;
|
||||||
var comments = dump(node);
|
var comments = dump(node);
|
||||||
if (!comments) return;
|
if (!comments) comments = [];
|
||||||
|
|
||||||
if (scan) {
|
if (scan) {
|
||||||
var tw = new TreeWalker(function(node) {
|
var tw = new TreeWalker(function(node) {
|
||||||
@@ -643,8 +641,7 @@ function OutputStream(options) {
|
|||||||
var self = this, generator = self._codegen;
|
var self = this, generator = self._codegen;
|
||||||
if (self instanceof AST_Scope) {
|
if (self instanceof AST_Scope) {
|
||||||
active_scope = self;
|
active_scope = self;
|
||||||
}
|
} else if (!use_asm && self instanceof AST_Directive && self.value == "use asm") {
|
||||||
else if (!use_asm && self instanceof AST_Directive && self.value == "use asm") {
|
|
||||||
use_asm = active_scope;
|
use_asm = active_scope;
|
||||||
}
|
}
|
||||||
function doit() {
|
function doit() {
|
||||||
@@ -1043,11 +1040,9 @@ function OutputStream(options) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
b = b.alternative;
|
b = b.alternative;
|
||||||
}
|
} else if (b instanceof AST_StatementWithBody) {
|
||||||
else if (b instanceof AST_StatementWithBody) {
|
|
||||||
b = b.body;
|
b = b.body;
|
||||||
}
|
} else break;
|
||||||
else break;
|
|
||||||
}
|
}
|
||||||
force_statement(self.body, output);
|
force_statement(self.body, output);
|
||||||
}
|
}
|
||||||
@@ -1355,7 +1350,7 @@ function OutputStream(options) {
|
|||||||
});
|
});
|
||||||
DEFPRINT(AST_Symbol, function(self, output) {
|
DEFPRINT(AST_Symbol, function(self, output) {
|
||||||
var def = self.definition();
|
var def = self.definition();
|
||||||
output.print_name(def ? def.mangled_name || def.name : self.name);
|
output.print_name(def && def.mangled_name || self.name);
|
||||||
});
|
});
|
||||||
DEFPRINT(AST_Hole, noop);
|
DEFPRINT(AST_Hole, noop);
|
||||||
DEFPRINT(AST_This, function(self, output) {
|
DEFPRINT(AST_This, function(self, output) {
|
||||||
|
|||||||
95
lib/parse.js
95
lib/parse.js
@@ -234,6 +234,7 @@ function tokenizer($TEXT, filename, html5_comments, shebang) {
|
|||||||
directives : {},
|
directives : {},
|
||||||
directive_stack : []
|
directive_stack : []
|
||||||
};
|
};
|
||||||
|
var prev_was_dot = false;
|
||||||
|
|
||||||
function peek() {
|
function peek() {
|
||||||
return S.text.charAt(S.pos);
|
return S.text.charAt(S.pos);
|
||||||
@@ -286,16 +287,12 @@ function tokenizer($TEXT, filename, html5_comments, shebang) {
|
|||||||
S.tokpos = S.pos;
|
S.tokpos = S.pos;
|
||||||
}
|
}
|
||||||
|
|
||||||
var prev_was_dot = false;
|
|
||||||
function token(type, value, is_comment) {
|
function token(type, value, is_comment) {
|
||||||
S.regex_allowed = ((type == "operator" && !UNARY_POSTFIX[value]) ||
|
S.regex_allowed = type == "operator" && !UNARY_POSTFIX[value]
|
||||||
(type == "keyword" && KEYWORDS_BEFORE_EXPRESSION[value]) ||
|
|| type == "keyword" && KEYWORDS_BEFORE_EXPRESSION[value]
|
||||||
(type == "punc" && PUNC_BEFORE_EXPRESSION[value]));
|
|| type == "punc" && PUNC_BEFORE_EXPRESSION[value];
|
||||||
if (type == "punc" && value == ".") {
|
if (type == "punc" && value == ".") prev_was_dot = true;
|
||||||
prev_was_dot = true;
|
else if (!is_comment) prev_was_dot = false;
|
||||||
} else if (!is_comment) {
|
|
||||||
prev_was_dot = false;
|
|
||||||
}
|
|
||||||
var ret = {
|
var ret = {
|
||||||
type : type,
|
type : type,
|
||||||
value : value,
|
value : value,
|
||||||
@@ -358,11 +355,8 @@ function tokenizer($TEXT, filename, html5_comments, shebang) {
|
|||||||
parse_error("Legacy octal literals are not allowed in strict mode");
|
parse_error("Legacy octal literals are not allowed in strict mode");
|
||||||
}
|
}
|
||||||
var valid = parse_js_number(num);
|
var valid = parse_js_number(num);
|
||||||
if (!isNaN(valid)) {
|
if (!isNaN(valid)) return token("num", valid);
|
||||||
return token("num", valid);
|
parse_error("Invalid syntax: " + num);
|
||||||
} else {
|
|
||||||
parse_error("Invalid syntax: " + num);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function read_escaped_char(in_string) {
|
function read_escaped_char(in_string) {
|
||||||
@@ -463,8 +457,7 @@ function tokenizer($TEXT, filename, html5_comments, shebang) {
|
|||||||
if (ch == "\\") escaped = backslash = true, next();
|
if (ch == "\\") escaped = backslash = true, next();
|
||||||
else if (is_identifier_char(ch)) name += next();
|
else if (is_identifier_char(ch)) name += next();
|
||||||
else break;
|
else break;
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
if (ch != "u") parse_error("Expecting UnicodeEscapeSequence -- uXXXX");
|
if (ch != "u") parse_error("Expecting UnicodeEscapeSequence -- uXXXX");
|
||||||
ch = read_escaped_char();
|
ch = read_escaped_char();
|
||||||
if (!is_identifier_char(ch)) parse_error("Unicode char: " + ch.charCodeAt(0) + " is not valid in identifier");
|
if (!is_identifier_char(ch)) parse_error("Unicode char: " + ch.charCodeAt(0) + " is not valid in identifier");
|
||||||
@@ -538,9 +531,7 @@ function tokenizer($TEXT, filename, html5_comments, shebang) {
|
|||||||
|
|
||||||
function handle_dot() {
|
function handle_dot() {
|
||||||
next();
|
next();
|
||||||
return is_digit(peek().charCodeAt(0))
|
return is_digit(peek().charCodeAt(0)) ? read_num(".") : token("punc", ".");
|
||||||
? read_num(".")
|
|
||||||
: token("punc", ".");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function read_word() {
|
function read_word() {
|
||||||
@@ -592,11 +583,10 @@ function tokenizer($TEXT, filename, html5_comments, shebang) {
|
|||||||
switch (code) {
|
switch (code) {
|
||||||
case 34: case 39: return read_string(ch);
|
case 34: case 39: return read_string(ch);
|
||||||
case 46: return handle_dot();
|
case 46: return handle_dot();
|
||||||
case 47: {
|
case 47:
|
||||||
var tok = handle_slash();
|
var tok = handle_slash();
|
||||||
if (tok === next_token) continue;
|
if (tok === next_token) continue;
|
||||||
return tok;
|
return tok;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if (is_digit(code)) return read_num();
|
if (is_digit(code)) return read_num();
|
||||||
if (PUNC_CHARS[ch]) return token("punc", next());
|
if (PUNC_CHARS[ch]) return token("punc", next());
|
||||||
@@ -614,12 +604,8 @@ function tokenizer($TEXT, filename, html5_comments, shebang) {
|
|||||||
|
|
||||||
next_token.add_directive = function(directive) {
|
next_token.add_directive = function(directive) {
|
||||||
S.directive_stack[S.directive_stack.length - 1].push(directive);
|
S.directive_stack[S.directive_stack.length - 1].push(directive);
|
||||||
|
if (S.directives[directive]) S.directives[directive]++;
|
||||||
if (S.directives[directive] === undefined) {
|
else S.directives[directive] = 1;
|
||||||
S.directives[directive] = 1;
|
|
||||||
} else {
|
|
||||||
S.directives[directive]++;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
next_token.push_directives_stack = function() {
|
next_token.push_directives_stack = function() {
|
||||||
@@ -627,13 +613,10 @@ function tokenizer($TEXT, filename, html5_comments, shebang) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
next_token.pop_directives_stack = function() {
|
next_token.pop_directives_stack = function() {
|
||||||
var directives = S.directive_stack[S.directive_stack.length - 1];
|
var directives = S.directive_stack.pop();
|
||||||
|
for (var i = directives.length; --i >= 0;) {
|
||||||
for (var i = 0; i < directives.length; i++) {
|
|
||||||
S.directives[directives[i]]--;
|
S.directives[directives[i]]--;
|
||||||
}
|
}
|
||||||
|
|
||||||
S.directive_stack.pop();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
next_token.has_directive = function(directive) {
|
next_token.has_directive = function(directive) {
|
||||||
@@ -645,27 +628,17 @@ function tokenizer($TEXT, filename, html5_comments, shebang) {
|
|||||||
|
|
||||||
/* -----[ Parser (constants) ]----- */
|
/* -----[ Parser (constants) ]----- */
|
||||||
|
|
||||||
var UNARY_PREFIX = makePredicate([
|
var UNARY_PREFIX = makePredicate("typeof void delete -- ++ ! ~ - +");
|
||||||
"typeof",
|
|
||||||
"void",
|
|
||||||
"delete",
|
|
||||||
"--",
|
|
||||||
"++",
|
|
||||||
"!",
|
|
||||||
"~",
|
|
||||||
"-",
|
|
||||||
"+"
|
|
||||||
]);
|
|
||||||
|
|
||||||
var UNARY_POSTFIX = makePredicate([ "--", "++" ]);
|
var UNARY_POSTFIX = makePredicate("-- ++");
|
||||||
|
|
||||||
var ASSIGNMENT = makePredicate([ "=", "+=", "-=", "/=", "*=", "%=", ">>=", "<<=", ">>>=", "|=", "^=", "&=" ]);
|
var ASSIGNMENT = makePredicate("= += -= /= *= %= >>= <<= >>>= |= ^= &=");
|
||||||
|
|
||||||
var PRECEDENCE = function(a, ret) {
|
var PRECEDENCE = function(a, ret) {
|
||||||
for (var i = 0; i < a.length; ++i) {
|
for (var i = 0; i < a.length;) {
|
||||||
var b = a[i];
|
var b = a[i++];
|
||||||
for (var j = 0; j < b.length; ++j) {
|
for (var j = 0; j < b.length; j++) {
|
||||||
ret[b[j]] = i + 1;
|
ret[b[j]] = i;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return ret;
|
return ret;
|
||||||
@@ -682,7 +655,7 @@ var PRECEDENCE = function(a, ret) {
|
|||||||
["*", "/", "%"]
|
["*", "/", "%"]
|
||||||
], {});
|
], {});
|
||||||
|
|
||||||
var ATOMIC_START_TOKEN = makePredicate([ "atom", "num", "string", "regexp", "name" ]);
|
var ATOMIC_START_TOKEN = makePredicate("atom num string regexp name");
|
||||||
|
|
||||||
/* -----[ Parser ]----- */
|
/* -----[ Parser ]----- */
|
||||||
|
|
||||||
@@ -698,10 +671,9 @@ function parse($TEXT, options) {
|
|||||||
}, true);
|
}, true);
|
||||||
|
|
||||||
var S = {
|
var S = {
|
||||||
input : (typeof $TEXT == "string"
|
input : typeof $TEXT == "string"
|
||||||
? tokenizer($TEXT, options.filename,
|
? tokenizer($TEXT, options.filename, options.html5_comments, options.shebang)
|
||||||
options.html5_comments, options.shebang)
|
: $TEXT,
|
||||||
: $TEXT),
|
|
||||||
token : null,
|
token : null,
|
||||||
prev : null,
|
prev : null,
|
||||||
peeked : null,
|
peeked : null,
|
||||||
@@ -757,15 +729,12 @@ function parse($TEXT, options) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function unexpected(token) {
|
function unexpected(token) {
|
||||||
if (token == null)
|
if (token == null) token = S.token;
|
||||||
token = S.token;
|
|
||||||
token_error(token, "Unexpected token: " + token_to_string(token.type, token.value));
|
token_error(token, "Unexpected token: " + token_to_string(token.type, token.value));
|
||||||
}
|
}
|
||||||
|
|
||||||
function expect_token(type, val) {
|
function expect_token(type, val) {
|
||||||
if (is(type, val)) {
|
if (is(type, val)) return next();
|
||||||
return next();
|
|
||||||
}
|
|
||||||
token_error(S.token, "Unexpected token: " + token_to_string(S.token.type, S.token.value) + ", expected: " + token_to_string(type, val));
|
token_error(S.token, "Unexpected token: " + token_to_string(S.token.type, S.token.value) + ", expected: " + token_to_string(type, val));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1284,6 +1253,7 @@ function parse($TEXT, options) {
|
|||||||
var ex = expression(true);
|
var ex = expression(true);
|
||||||
var len = start.comments_before.length;
|
var len = start.comments_before.length;
|
||||||
[].unshift.apply(ex.start.comments_before, start.comments_before);
|
[].unshift.apply(ex.start.comments_before, start.comments_before);
|
||||||
|
start.comments_before.length = 0;
|
||||||
start.comments_before = ex.start.comments_before;
|
start.comments_before = ex.start.comments_before;
|
||||||
start.comments_before_length = len;
|
start.comments_before_length = len;
|
||||||
if (len == 0 && start.comments_before.length > 0) {
|
if (len == 0 && start.comments_before.length > 0) {
|
||||||
@@ -1299,6 +1269,7 @@ function parse($TEXT, options) {
|
|||||||
var end = prev();
|
var end = prev();
|
||||||
end.comments_before = ex.end.comments_before;
|
end.comments_before = ex.end.comments_before;
|
||||||
[].push.apply(ex.end.comments_after, end.comments_after);
|
[].push.apply(ex.end.comments_after, end.comments_after);
|
||||||
|
end.comments_after.length = 0;
|
||||||
end.comments_after = ex.end.comments_after;
|
end.comments_after = ex.end.comments_after;
|
||||||
ex.end = end;
|
ex.end = end;
|
||||||
if (ex instanceof AST_Call) mark_pure(ex);
|
if (ex instanceof AST_Call) mark_pure(ex);
|
||||||
|
|||||||
70
lib/scope.js
70
lib/scope.js
@@ -55,6 +55,7 @@ function SymbolDef(scope, orig, init) {
|
|||||||
this.mangled_name = null;
|
this.mangled_name = null;
|
||||||
this.undeclared = false;
|
this.undeclared = false;
|
||||||
this.id = SymbolDef.next_id++;
|
this.id = SymbolDef.next_id++;
|
||||||
|
this.lambda = orig instanceof AST_SymbolLambda;
|
||||||
}
|
}
|
||||||
|
|
||||||
SymbolDef.next_id = 1;
|
SymbolDef.next_id = 1;
|
||||||
@@ -191,13 +192,21 @@ AST_Toplevel.DEFMETHOD("figure_out_scope", function(options) {
|
|||||||
// pass 3: fix up any scoping issue with IE8
|
// pass 3: fix up any scoping issue with IE8
|
||||||
if (options.ie8) self.walk(new TreeWalker(function(node) {
|
if (options.ie8) self.walk(new TreeWalker(function(node) {
|
||||||
if (node instanceof AST_SymbolCatch) {
|
if (node instanceof AST_SymbolCatch) {
|
||||||
redefine(node, node.thedef.defun);
|
var scope = node.thedef.defun;
|
||||||
|
if (scope.name instanceof AST_SymbolLambda && scope.name.name == node.name) {
|
||||||
|
scope = scope.parent_scope.resolve();
|
||||||
|
}
|
||||||
|
redefine(node, scope);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (node instanceof AST_SymbolLambda) {
|
if (node instanceof AST_SymbolLambda) {
|
||||||
var def = node.thedef;
|
var def = node.thedef;
|
||||||
redefine(node, node.scope.parent_scope);
|
redefine(node, node.scope.parent_scope.resolve());
|
||||||
node.thedef.init = def.init;
|
if (typeof node.thedef.init !== "undefined") {
|
||||||
|
node.thedef.init = false;
|
||||||
|
} else if (def.init) {
|
||||||
|
node.thedef.init = def.init;
|
||||||
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}));
|
}));
|
||||||
@@ -205,11 +214,19 @@ AST_Toplevel.DEFMETHOD("figure_out_scope", function(options) {
|
|||||||
function redefine(node, scope) {
|
function redefine(node, scope) {
|
||||||
var name = node.name;
|
var name = node.name;
|
||||||
var old_def = node.thedef;
|
var old_def = node.thedef;
|
||||||
var new_def = scope.find_variable(name) || self.globals.get(name) || scope.def_variable(node);
|
var new_def = scope.find_variable(name);
|
||||||
|
if (new_def) {
|
||||||
|
var redef;
|
||||||
|
while (redef = new_def.redefined()) new_def = redef;
|
||||||
|
} else {
|
||||||
|
new_def = self.globals.get(name) || scope.def_variable(node);
|
||||||
|
}
|
||||||
old_def.orig.concat(old_def.references).forEach(function(node) {
|
old_def.orig.concat(old_def.references).forEach(function(node) {
|
||||||
node.thedef = new_def;
|
node.thedef = new_def;
|
||||||
node.reference(options);
|
node.reference(options);
|
||||||
});
|
});
|
||||||
|
if (old_def.lambda) new_def.lambda = true;
|
||||||
|
if (new_def.undeclared) self.variables.set(name, new_def);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -281,9 +298,7 @@ AST_Scope.DEFMETHOD("def_variable", function(symbol, init) {
|
|||||||
var def = this.variables.get(symbol.name);
|
var def = this.variables.get(symbol.name);
|
||||||
if (def) {
|
if (def) {
|
||||||
def.orig.push(symbol);
|
def.orig.push(symbol);
|
||||||
if (def.init && (def.scope !== symbol.scope || def.init instanceof AST_Function)) {
|
if (def.init instanceof AST_Function) def.init = init;
|
||||||
def.init = init;
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
def = new SymbolDef(this, symbol, init);
|
def = new SymbolDef(this, symbol, init);
|
||||||
this.variables.set(symbol.name, def);
|
this.variables.set(symbol.name, def);
|
||||||
@@ -413,7 +428,9 @@ 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);
|
||||||
}
|
}
|
||||||
node.variables.each(mangle);
|
node.variables.each(function(def) {
|
||||||
|
if (!defer_redef(def)) mangle(def);
|
||||||
|
});
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (node instanceof AST_Label) {
|
if (node instanceof AST_Label) {
|
||||||
@@ -426,22 +443,11 @@ AST_Toplevel.DEFMETHOD("mangle_names", function(options) {
|
|||||||
}
|
}
|
||||||
if (!options.ie8 && node instanceof AST_Catch) {
|
if (!options.ie8 && node instanceof AST_Catch) {
|
||||||
var def = node.argname.definition();
|
var def = node.argname.definition();
|
||||||
var redef = def.redefined();
|
var redef = defer_redef(def, node.argname);
|
||||||
if (redef) {
|
|
||||||
redefined.push(def);
|
|
||||||
reference(node.argname);
|
|
||||||
def.references.forEach(reference);
|
|
||||||
}
|
|
||||||
descend();
|
descend();
|
||||||
if (!redef) mangle(def);
|
if (!redef) mangle(def);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
function reference(sym) {
|
|
||||||
sym.thedef = redef;
|
|
||||||
sym.reference(options);
|
|
||||||
sym.thedef = def;
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
this.walk(tw);
|
this.walk(tw);
|
||||||
redefined.forEach(mangle);
|
redefined.forEach(mangle);
|
||||||
@@ -450,6 +456,21 @@ AST_Toplevel.DEFMETHOD("mangle_names", function(options) {
|
|||||||
if (options.reserved.has[def.name]) return;
|
if (options.reserved.has[def.name]) return;
|
||||||
def.mangle(options);
|
def.mangle(options);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function defer_redef(def, node) {
|
||||||
|
var redef = def.redefined();
|
||||||
|
if (!redef) return false;
|
||||||
|
redefined.push(def);
|
||||||
|
def.references.forEach(reference);
|
||||||
|
if (node) reference(node);
|
||||||
|
return true;
|
||||||
|
|
||||||
|
function reference(sym) {
|
||||||
|
sym.thedef = redef;
|
||||||
|
sym.reference(options);
|
||||||
|
sym.thedef = def;
|
||||||
|
}
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
AST_Toplevel.DEFMETHOD("find_colliding_names", function(options) {
|
AST_Toplevel.DEFMETHOD("find_colliding_names", function(options) {
|
||||||
@@ -499,13 +520,14 @@ AST_Toplevel.DEFMETHOD("expand_names", function(options) {
|
|||||||
if (def.global && options.cache) return;
|
if (def.global && options.cache) return;
|
||||||
if (def.unmangleable(options)) return;
|
if (def.unmangleable(options)) return;
|
||||||
if (options.reserved.has[def.name]) return;
|
if (options.reserved.has[def.name]) return;
|
||||||
var d = def.redefined();
|
var redef = def.redefined();
|
||||||
def.name = d ? d.name : next_name();
|
var name = redef ? redef.rename || redef.name : next_name();
|
||||||
|
def.rename = name;
|
||||||
def.orig.forEach(function(sym) {
|
def.orig.forEach(function(sym) {
|
||||||
sym.name = def.name;
|
sym.name = name;
|
||||||
});
|
});
|
||||||
def.references.forEach(function(sym) {
|
def.references.forEach(function(sym) {
|
||||||
sym.name = def.name;
|
sym.name = name;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -127,8 +127,7 @@ var MAP = (function() {
|
|||||||
} else {
|
} else {
|
||||||
top.push(val);
|
top.push(val);
|
||||||
}
|
}
|
||||||
}
|
} else if (val !== skip) {
|
||||||
else if (val !== skip) {
|
|
||||||
if (val instanceof Splice) {
|
if (val instanceof Splice) {
|
||||||
ret.push.apply(ret, backwards ? val.v.slice().reverse() : val.v);
|
ret.push.apply(ret, backwards ? val.v.slice().reverse() : val.v);
|
||||||
} else {
|
} else {
|
||||||
@@ -145,8 +144,7 @@ var MAP = (function() {
|
|||||||
} else {
|
} else {
|
||||||
for (i = 0; i < a.length; ++i) if (doit()) break;
|
for (i = 0; i < a.length; ++i) if (doit()) break;
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
for (i in a) if (HOP(a, i)) if (doit()) break;
|
for (i in a) if (HOP(a, i)) if (doit()) break;
|
||||||
}
|
}
|
||||||
return top.concat(ret);
|
return top.concat(ret);
|
||||||
|
|||||||
@@ -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.1",
|
"version": "3.7.0",
|
||||||
"engines": {
|
"engines": {
|
||||||
"node": ">=0.8.0"
|
"node": ">=0.8.0"
|
||||||
},
|
},
|
||||||
@@ -23,7 +23,7 @@
|
|||||||
"LICENSE"
|
"LICENSE"
|
||||||
],
|
],
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"commander": "2.20.0",
|
"commander": "~2.20.3",
|
||||||
"source-map": "~0.6.1"
|
"source-map": "~0.6.1"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
|
|||||||
@@ -13,15 +13,15 @@ if (!args.length) {
|
|||||||
}
|
}
|
||||||
args.push("--timings");
|
args.push("--timings");
|
||||||
var urls = [
|
var urls = [
|
||||||
"https://code.jquery.com/jquery-3.2.1.js",
|
"https://code.jquery.com/jquery-3.4.1.js",
|
||||||
"https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.6.4/angular.js",
|
"https://code.angularjs.org/1.7.8/angular.js",
|
||||||
"https://cdnjs.cloudflare.com/ajax/libs/mathjs/3.9.0/math.js",
|
"https://unpkg.com/mathjs@6.2.3/dist/math.js",
|
||||||
"https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.js",
|
|
||||||
"https://unpkg.com/react@15.3.2/dist/react.js",
|
"https://unpkg.com/react@15.3.2/dist/react.js",
|
||||||
"http://builds.emberjs.com/tags/v2.11.0/ember.prod.js",
|
"https://cdnjs.cloudflare.com/ajax/libs/d3/5.12.0/d3.js",
|
||||||
"https://cdn.jsdelivr.net/lodash/4.17.4/lodash.js",
|
"https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.js",
|
||||||
"https://cdnjs.cloudflare.com/ajax/libs/d3/4.5.0/d3.js",
|
"https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.15/lodash.js",
|
||||||
"https://raw.githubusercontent.com/kangax/html-minifier/v3.5.7/dist/htmlminifier.js",
|
"https://cdnjs.cloudflare.com/ajax/libs/ember.js/2.12.2/ember.prod.js",
|
||||||
|
"https://raw.githubusercontent.com/kangax/html-minifier/v4.0.0/dist/htmlminifier.js",
|
||||||
];
|
];
|
||||||
var results = {};
|
var results = {};
|
||||||
var remaining = 2 * urls.length;
|
var remaining = 2 * urls.length;
|
||||||
|
|||||||
@@ -1,3 +1,7 @@
|
|||||||
|
"use strict";
|
||||||
|
|
||||||
|
require("../tools/exit");
|
||||||
|
|
||||||
var assert = require("assert");
|
var assert = require("assert");
|
||||||
var child_process = require("child_process");
|
var child_process = require("child_process");
|
||||||
var fs = require("fs");
|
var fs = require("fs");
|
||||||
@@ -9,7 +13,7 @@ var U = require("./node");
|
|||||||
var file = process.argv[2];
|
var file = process.argv[2];
|
||||||
var dir = path.resolve(path.dirname(module.filename), "compress");
|
var dir = path.resolve(path.dirname(module.filename), "compress");
|
||||||
if (file) {
|
if (file) {
|
||||||
var minify_options = require("./ufuzz.json").map(JSON.stringify);
|
var minify_options = require("./ufuzz/options.json").map(JSON.stringify);
|
||||||
log("--- {file}", { file: file });
|
log("--- {file}", { file: file });
|
||||||
var tests = parse_test(path.resolve(dir, file));
|
var tests = parse_test(path.resolve(dir, file));
|
||||||
process.exit(Object.keys(tests).filter(function(name) {
|
process.exit(Object.keys(tests).filter(function(name) {
|
||||||
|
|||||||
@@ -96,7 +96,7 @@ asm_mixed: {
|
|||||||
return +sum;
|
return +sum;
|
||||||
}
|
}
|
||||||
function geometricMean(start, end) {
|
function geometricMean(start, end) {
|
||||||
return start |= 0, end |= 0, +exp(+logSum(start, end) / +(end - start | 0));
|
return start |= 0, end |= 0, +exp(logSum(start, end) / (end - start | 0));
|
||||||
}
|
}
|
||||||
var exp = stdlib.Math.exp, log = stdlib.Math.log, values = new stdlib.Float64Array(buffer);
|
var exp = stdlib.Math.exp, log = stdlib.Math.log, values = new stdlib.Float64Array(buffer);
|
||||||
return { geometricMean: geometricMean };
|
return { geometricMean: geometricMean };
|
||||||
|
|||||||
88
test/compress/booleans.js
Normal file
88
test/compress/booleans.js
Normal file
@@ -0,0 +1,88 @@
|
|||||||
|
iife_boolean_context: {
|
||||||
|
options = {
|
||||||
|
booleans: true,
|
||||||
|
evaluate: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
console.log(function() {
|
||||||
|
return Object(1) || false;
|
||||||
|
}() ? "PASS" : "FAIL");
|
||||||
|
console.log(function() {
|
||||||
|
return [].length || true;
|
||||||
|
}() ? "PASS" : "FAIL");
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
console.log(function() {
|
||||||
|
return Object(1);
|
||||||
|
}() ? "PASS" : "FAIL");
|
||||||
|
console.log(function() {
|
||||||
|
return [].length, 1;
|
||||||
|
}() ? "PASS" : "FAIL");
|
||||||
|
}
|
||||||
|
expect_stdout: [
|
||||||
|
"PASS",
|
||||||
|
"PASS",
|
||||||
|
]
|
||||||
|
expect_warnings: [
|
||||||
|
"WARN: Dropping side-effect-free || [test/compress/booleans.js:2,19]",
|
||||||
|
"WARN: Boolean || always true [test/compress/booleans.js:5,19]",
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
|
issue_3465_1: {
|
||||||
|
options = {
|
||||||
|
booleans: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
console.log(function(a) {
|
||||||
|
return typeof a;
|
||||||
|
}() ? "PASS" : "FAIL");
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
console.log(function(a) {
|
||||||
|
return 1;
|
||||||
|
}() ? "PASS" : "FAIL");
|
||||||
|
}
|
||||||
|
expect_stdout: "PASS"
|
||||||
|
}
|
||||||
|
|
||||||
|
issue_3465_2: {
|
||||||
|
options = {
|
||||||
|
booleans: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
console.log(function f(a) {
|
||||||
|
if (!a) console.log(f(42));
|
||||||
|
return typeof a;
|
||||||
|
}() ? "PASS" : "FAIL");
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
console.log(function f(a) {
|
||||||
|
if (!a) console.log(f(42));
|
||||||
|
return typeof a;
|
||||||
|
}() ? "PASS" : "FAIL");
|
||||||
|
}
|
||||||
|
expect_stdout: [
|
||||||
|
"number",
|
||||||
|
"PASS",
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
|
issue_3465_3: {
|
||||||
|
options = {
|
||||||
|
booleans: true,
|
||||||
|
passes: 2,
|
||||||
|
unused: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
console.log(function f(a) {
|
||||||
|
return typeof a;
|
||||||
|
}() ? "PASS" : "FAIL");
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
console.log(function(a) {
|
||||||
|
return 1;
|
||||||
|
}() ? "PASS" : "FAIL");
|
||||||
|
}
|
||||||
|
expect_stdout: "PASS"
|
||||||
|
}
|
||||||
@@ -1458,7 +1458,7 @@ collapse_vars_constants: {
|
|||||||
function f3(x) {
|
function f3(x) {
|
||||||
var b = x.prop;
|
var b = x.prop;
|
||||||
sideeffect1();
|
sideeffect1();
|
||||||
return b + (function() { return -9; })();
|
return b + -9;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -3511,7 +3511,7 @@ issue_2437_2: {
|
|||||||
conditionals: true,
|
conditionals: true,
|
||||||
inline: true,
|
inline: true,
|
||||||
join_vars: true,
|
join_vars: true,
|
||||||
passes: 2,
|
passes: 3,
|
||||||
reduce_funcs: true,
|
reduce_funcs: true,
|
||||||
reduce_vars: true,
|
reduce_vars: true,
|
||||||
sequences: true,
|
sequences: true,
|
||||||
@@ -4388,7 +4388,7 @@ replace_all_var: {
|
|||||||
}
|
}
|
||||||
|
|
||||||
replace_all_var_scope: {
|
replace_all_var_scope: {
|
||||||
rename = true;
|
rename = true
|
||||||
options = {
|
options = {
|
||||||
collapse_vars: true,
|
collapse_vars: true,
|
||||||
unused: true,
|
unused: true,
|
||||||
@@ -5748,7 +5748,7 @@ issue_3215_1: {
|
|||||||
}());
|
}());
|
||||||
}
|
}
|
||||||
expect: {
|
expect: {
|
||||||
console.log("number");
|
console.log(typeof 42);
|
||||||
}
|
}
|
||||||
expect_stdout: "number"
|
expect_stdout: "number"
|
||||||
}
|
}
|
||||||
@@ -6237,3 +6237,315 @@ issue_3439_2: {
|
|||||||
}
|
}
|
||||||
expect_stdout: "number"
|
expect_stdout: "number"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
cond_sequence_return_1: {
|
||||||
|
options = {
|
||||||
|
collapse_vars: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
console.log(function(n) {
|
||||||
|
var c = 0;
|
||||||
|
for (var k in [0, 1])
|
||||||
|
if (c++, k == n) return c;
|
||||||
|
}(1));
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
console.log(function(n) {
|
||||||
|
var c = 0;
|
||||||
|
for (var k in [0, 1])
|
||||||
|
if (c++, k == n) return c;
|
||||||
|
}(1));
|
||||||
|
}
|
||||||
|
expect_stdout: "2"
|
||||||
|
}
|
||||||
|
|
||||||
|
cond_sequence_return_2: {
|
||||||
|
options = {
|
||||||
|
collapse_vars: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
console.log(function(n) {
|
||||||
|
var c = 0;
|
||||||
|
for (var k in [0, 1])
|
||||||
|
if (c += 1, k == n) return c;
|
||||||
|
}(1));
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
console.log(function(n) {
|
||||||
|
var c = 0;
|
||||||
|
for (var k in [0, 1])
|
||||||
|
if (c += 1, k == n) return c;
|
||||||
|
}(1));
|
||||||
|
}
|
||||||
|
expect_stdout: "2"
|
||||||
|
}
|
||||||
|
|
||||||
|
issue_3520: {
|
||||||
|
options = {
|
||||||
|
collapse_vars: true,
|
||||||
|
reduce_vars: true,
|
||||||
|
unused: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
var a = 0;
|
||||||
|
var b = function(c) {
|
||||||
|
for (var i = 2; --i >= 0;) {
|
||||||
|
(function f() {
|
||||||
|
c = 0;
|
||||||
|
var i = void 0;
|
||||||
|
var f = f && f[i];
|
||||||
|
})();
|
||||||
|
a += b;
|
||||||
|
c && b++;
|
||||||
|
}
|
||||||
|
}(b = 1);
|
||||||
|
console.log(a);
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
var a = 0;
|
||||||
|
var b = function(c) {
|
||||||
|
for (var i = 2; --i >= 0;) {
|
||||||
|
(function() {
|
||||||
|
c = 0;
|
||||||
|
var f = f && f[void 0];
|
||||||
|
})();
|
||||||
|
a += b;
|
||||||
|
c && b++;
|
||||||
|
}
|
||||||
|
}(b = 1);
|
||||||
|
console.log(a);
|
||||||
|
}
|
||||||
|
expect_stdout: "2"
|
||||||
|
}
|
||||||
|
|
||||||
|
issue_3526_1: {
|
||||||
|
options = {
|
||||||
|
collapse_vars: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
var b = function() {
|
||||||
|
this.a = "FAIL";
|
||||||
|
}();
|
||||||
|
var a = "PASS";
|
||||||
|
var b;
|
||||||
|
var c = b;
|
||||||
|
console.log(a);
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
var b = function() {
|
||||||
|
this.a = "FAIL";
|
||||||
|
}();
|
||||||
|
var a = "PASS";
|
||||||
|
var b;
|
||||||
|
var c = b;
|
||||||
|
console.log(a);
|
||||||
|
}
|
||||||
|
expect_stdout: "PASS"
|
||||||
|
}
|
||||||
|
|
||||||
|
issue_3526_2: {
|
||||||
|
options = {
|
||||||
|
collapse_vars: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
function f() {
|
||||||
|
this.a = "FAIL";
|
||||||
|
}
|
||||||
|
var b = f();
|
||||||
|
var a = "PASS";
|
||||||
|
var b;
|
||||||
|
var c = b;
|
||||||
|
console.log(a);
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
function f() {
|
||||||
|
this.a = "FAIL";
|
||||||
|
}
|
||||||
|
var b = f();
|
||||||
|
var a = "PASS";
|
||||||
|
var b;
|
||||||
|
var c = b;
|
||||||
|
console.log(a);
|
||||||
|
}
|
||||||
|
expect_stdout: "PASS"
|
||||||
|
}
|
||||||
|
|
||||||
|
issue_3562: {
|
||||||
|
options = {
|
||||||
|
collapse_vars: true,
|
||||||
|
conditionals: true,
|
||||||
|
sequences: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
function f(a) {
|
||||||
|
console.log("PASS", a);
|
||||||
|
}
|
||||||
|
function g(b) {
|
||||||
|
console.log("FAIL", b);
|
||||||
|
}
|
||||||
|
var h;
|
||||||
|
var c;
|
||||||
|
if (console) {
|
||||||
|
h = f;
|
||||||
|
c = "PASS";
|
||||||
|
} else {
|
||||||
|
h = g;
|
||||||
|
c = "FAIL";
|
||||||
|
}
|
||||||
|
h(c);
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
function f(a) {
|
||||||
|
console.log("PASS", a);
|
||||||
|
}
|
||||||
|
function g(b) {
|
||||||
|
console.log("FAIL", b);
|
||||||
|
}
|
||||||
|
var h;
|
||||||
|
var c;
|
||||||
|
c = console ? (h = f, "PASS") : (h = g, "FAIL"),
|
||||||
|
h(c);
|
||||||
|
}
|
||||||
|
expect_stdout: "PASS PASS"
|
||||||
|
}
|
||||||
|
|
||||||
|
dot_throw_assign_sequence: {
|
||||||
|
options = {
|
||||||
|
collapse_vars: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
var a = "FAIL";
|
||||||
|
try {
|
||||||
|
var b;
|
||||||
|
b[0] = (a = "PASS", 0);
|
||||||
|
a = 1 + a;
|
||||||
|
} catch (c) {
|
||||||
|
}
|
||||||
|
console.log(a);
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
var a = "FAIL";
|
||||||
|
try {
|
||||||
|
var b;
|
||||||
|
b[0] = (a = "PASS", 0);
|
||||||
|
a = 1 + a;
|
||||||
|
} catch (c) {
|
||||||
|
}
|
||||||
|
console.log(a);
|
||||||
|
}
|
||||||
|
expect_stdout: "PASS"
|
||||||
|
}
|
||||||
|
|
||||||
|
call_assign_order: {
|
||||||
|
options = {
|
||||||
|
collapse_vars: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
var a, b = 1, c = 0, log = console.log;
|
||||||
|
(function() {
|
||||||
|
a = b = "PASS";
|
||||||
|
})((b = "FAIL", c++));
|
||||||
|
log(a, b);
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
var a, b = 1, c = 0, log = console.log;
|
||||||
|
(function() {
|
||||||
|
a = b = "PASS";
|
||||||
|
})((b = "FAIL", c++));
|
||||||
|
log(a, b);
|
||||||
|
}
|
||||||
|
expect_stdout: "PASS PASS"
|
||||||
|
}
|
||||||
|
|
||||||
|
issue_3573: {
|
||||||
|
options = {
|
||||||
|
collapse_vars: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
var c = 0;
|
||||||
|
(function(b) {
|
||||||
|
while (--b) {
|
||||||
|
b = NaN;
|
||||||
|
switch (0 / this < 0) {
|
||||||
|
case c++, false:
|
||||||
|
case c++, NaN:
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})(3);
|
||||||
|
console.log(c);
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
var c = 0;
|
||||||
|
(function(b) {
|
||||||
|
while (--b) {
|
||||||
|
b = NaN;
|
||||||
|
switch (0 / this < 0) {
|
||||||
|
case c++, false:
|
||||||
|
case c++, NaN:
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})(3);
|
||||||
|
console.log(c);
|
||||||
|
}
|
||||||
|
expect_stdout: "1"
|
||||||
|
}
|
||||||
|
|
||||||
|
issue_3581_1: {
|
||||||
|
options = {
|
||||||
|
collapse_vars: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
var a = "PASS", b = "FAIL";
|
||||||
|
try {
|
||||||
|
b = "PASS";
|
||||||
|
if (a) throw 0;
|
||||||
|
b = 1 + b;
|
||||||
|
a = "FAIL";
|
||||||
|
} catch (e) {}
|
||||||
|
console.log(a, b);
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
var a = "PASS", b = "FAIL";
|
||||||
|
try {
|
||||||
|
b = "PASS";
|
||||||
|
if (a) throw 0;
|
||||||
|
b = 1 + b;
|
||||||
|
a = "FAIL";
|
||||||
|
} catch (e) {}
|
||||||
|
console.log(a, b);
|
||||||
|
}
|
||||||
|
expect_stdout: "PASS PASS"
|
||||||
|
}
|
||||||
|
|
||||||
|
issue_3581_2: {
|
||||||
|
options = {
|
||||||
|
collapse_vars: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
(function() {
|
||||||
|
var a = "PASS", b = "FAIL";
|
||||||
|
try {
|
||||||
|
b = "PASS";
|
||||||
|
if (a) return;
|
||||||
|
b = 1 + b;
|
||||||
|
a = "FAIL";
|
||||||
|
} finally {
|
||||||
|
console.log(a, b);
|
||||||
|
}
|
||||||
|
})();
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
(function() {
|
||||||
|
var a = "PASS", b = "FAIL";
|
||||||
|
try {
|
||||||
|
b = "PASS";
|
||||||
|
if (a) return;
|
||||||
|
b = 1 + b;
|
||||||
|
a = "FAIL";
|
||||||
|
} finally {
|
||||||
|
console.log(a, b);
|
||||||
|
}
|
||||||
|
})();
|
||||||
|
}
|
||||||
|
expect_stdout: "PASS PASS"
|
||||||
|
}
|
||||||
|
|||||||
@@ -161,6 +161,24 @@ ifs_6: {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ifs_7: {
|
||||||
|
options = {
|
||||||
|
conditionals: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
if (A); else;
|
||||||
|
if (A) while (B); else;
|
||||||
|
if (A); else while (C);
|
||||||
|
if (A) while (B); else while (C);
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
A;
|
||||||
|
if (A) while (B);
|
||||||
|
if (!A) while (C);
|
||||||
|
if (A) while (B); else while (C);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
cond_1: {
|
cond_1: {
|
||||||
options = {
|
options = {
|
||||||
conditionals: true,
|
conditionals: true,
|
||||||
@@ -1471,3 +1489,29 @@ 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"
|
||||||
|
}
|
||||||
|
|||||||
@@ -892,9 +892,7 @@ issue_2860_1: {
|
|||||||
}());
|
}());
|
||||||
}
|
}
|
||||||
expect: {
|
expect: {
|
||||||
console.log(function(a) {
|
console.log(1);
|
||||||
return 1 ^ a;
|
|
||||||
}());
|
|
||||||
}
|
}
|
||||||
expect_stdout: "1"
|
expect_stdout: "1"
|
||||||
}
|
}
|
||||||
@@ -1013,3 +1011,119 @@ issue_3406: {
|
|||||||
}
|
}
|
||||||
expect_stdout: "true"
|
expect_stdout: "true"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function_assign: {
|
||||||
|
options = {
|
||||||
|
dead_code: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
console.log(function() {
|
||||||
|
var a = "PASS";
|
||||||
|
function h(c) {
|
||||||
|
return c;
|
||||||
|
}
|
||||||
|
h.p = function(b) {
|
||||||
|
return b;
|
||||||
|
}.p = a;
|
||||||
|
return h;
|
||||||
|
}().p);
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
console.log(function() {
|
||||||
|
var a = "PASS";
|
||||||
|
function h(c) {
|
||||||
|
return c;
|
||||||
|
}
|
||||||
|
h.p = a;
|
||||||
|
return h;
|
||||||
|
}().p);
|
||||||
|
}
|
||||||
|
expect_stdout: "PASS"
|
||||||
|
}
|
||||||
|
|
||||||
|
issue_3552: {
|
||||||
|
options = {
|
||||||
|
dead_code: true,
|
||||||
|
pure_getters: "strict",
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
var a = "PASS";
|
||||||
|
(function() {
|
||||||
|
(1..p += 42) && (a = "FAIL");
|
||||||
|
})();
|
||||||
|
console.log(a);
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
var a = "PASS";
|
||||||
|
(function() {
|
||||||
|
(1..p += 42) && (a = "FAIL");
|
||||||
|
})();
|
||||||
|
console.log(a);
|
||||||
|
}
|
||||||
|
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"
|
||||||
|
}
|
||||||
|
|||||||
@@ -1019,14 +1019,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 +1054,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 +1649,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 +1730,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);
|
||||||
}
|
}
|
||||||
@@ -2062,3 +2076,162 @@ issue_3427_2: {
|
|||||||
}
|
}
|
||||||
expect_stdout: "PASS"
|
expect_stdout: "PASS"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
issue_3495: {
|
||||||
|
options = {
|
||||||
|
dead_code: true,
|
||||||
|
pure_getters: "strict",
|
||||||
|
side_effects: true,
|
||||||
|
unused: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
console.log(function f() {
|
||||||
|
f = 0;
|
||||||
|
var a = f.p;
|
||||||
|
}());
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
console.log(void 0);
|
||||||
|
}
|
||||||
|
expect_stdout: "undefined"
|
||||||
|
}
|
||||||
|
|
||||||
|
issue_3497: {
|
||||||
|
options = {
|
||||||
|
pure_getters: "strict",
|
||||||
|
side_effects: true,
|
||||||
|
unused: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
var a;
|
||||||
|
console.log(function(b) {
|
||||||
|
(b += a).p = 0;
|
||||||
|
}());
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
var a;
|
||||||
|
console.log(function(b) {
|
||||||
|
(b += a).p = 0;
|
||||||
|
}());
|
||||||
|
}
|
||||||
|
expect_stdout: "undefined"
|
||||||
|
}
|
||||||
|
|
||||||
|
issue_3515_1: {
|
||||||
|
options = {
|
||||||
|
collapse_vars: true,
|
||||||
|
reduce_vars: true,
|
||||||
|
unused: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
var c = 0;
|
||||||
|
(function() {
|
||||||
|
this[c++] = 0;
|
||||||
|
var expr20 = !0;
|
||||||
|
for (var key20 in expr20);
|
||||||
|
})();
|
||||||
|
console.log(c);
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
var c = 0;
|
||||||
|
(function() {
|
||||||
|
this[c++] = 0;
|
||||||
|
for (var key20 in !0);
|
||||||
|
})();
|
||||||
|
console.log(c);
|
||||||
|
}
|
||||||
|
expect_stdout: "1"
|
||||||
|
}
|
||||||
|
|
||||||
|
issue_3515_2: {
|
||||||
|
options = {
|
||||||
|
side_effects: true,
|
||||||
|
toplevel: true,
|
||||||
|
unused: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
var a = "FAIL";
|
||||||
|
function f() {
|
||||||
|
typeof b === "number";
|
||||||
|
delete a;
|
||||||
|
}
|
||||||
|
var b = f(a = "PASS");
|
||||||
|
console.log(a);
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
var a = "FAIL";
|
||||||
|
function f() {
|
||||||
|
delete a;
|
||||||
|
}
|
||||||
|
f(a = "PASS");
|
||||||
|
console.log(a);
|
||||||
|
}
|
||||||
|
expect_stdout: "PASS"
|
||||||
|
}
|
||||||
|
|
||||||
|
issue_3515_3: {
|
||||||
|
options = {
|
||||||
|
collapse_vars: true,
|
||||||
|
unused: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
var c = "FAIL";
|
||||||
|
(function() {
|
||||||
|
function f() {
|
||||||
|
c = "PASS";
|
||||||
|
}
|
||||||
|
var a = f();
|
||||||
|
var a = function g(b) {
|
||||||
|
b && (b.p = this);
|
||||||
|
}(a);
|
||||||
|
})();
|
||||||
|
console.log(c);
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
var c = "FAIL";
|
||||||
|
(function() {
|
||||||
|
function f() {
|
||||||
|
c = "PASS";
|
||||||
|
}
|
||||||
|
(function(b) {
|
||||||
|
b && (b.p = this);
|
||||||
|
})(f());
|
||||||
|
})();
|
||||||
|
console.log(c);
|
||||||
|
}
|
||||||
|
expect_stdout: "PASS"
|
||||||
|
}
|
||||||
|
|
||||||
|
function_assign: {
|
||||||
|
options = {
|
||||||
|
pure_getters: "strict",
|
||||||
|
reduce_vars: true,
|
||||||
|
side_effects: true,
|
||||||
|
unused: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
console.log(function() {
|
||||||
|
var a = "PASS";
|
||||||
|
function g(b) {
|
||||||
|
return b;
|
||||||
|
}
|
||||||
|
g.p = a;
|
||||||
|
function h(c) {
|
||||||
|
return c;
|
||||||
|
}
|
||||||
|
h.p = a;
|
||||||
|
return h;
|
||||||
|
}().p);
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
console.log(function() {
|
||||||
|
var a = "PASS";
|
||||||
|
function h(c) {
|
||||||
|
return c;
|
||||||
|
}
|
||||||
|
h.p = a;
|
||||||
|
return h;
|
||||||
|
}().p);
|
||||||
|
}
|
||||||
|
expect_stdout: "PASS"
|
||||||
|
}
|
||||||
|
|||||||
@@ -237,22 +237,39 @@ unsafe_constant: {
|
|||||||
unsafe: true,
|
unsafe: true,
|
||||||
}
|
}
|
||||||
input: {
|
input: {
|
||||||
console.log(
|
console.log(true.a, false.a);
|
||||||
true.a,
|
console.log(true.valueOf(), false.valueOf());
|
||||||
false.a,
|
try {
|
||||||
null.a,
|
console.log(null.a);
|
||||||
undefined.a
|
} catch (e) {
|
||||||
);
|
console.log("PASS");
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
console.log(undefined.a);
|
||||||
|
} catch (e) {
|
||||||
|
console.log("PASS");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
expect: {
|
expect: {
|
||||||
console.log(
|
console.log(void 0, void 0);
|
||||||
void 0,
|
console.log(true, false);
|
||||||
false.a,
|
try {
|
||||||
null.a,
|
console.log(null.a);
|
||||||
(void 0).a
|
} catch (e) {
|
||||||
);
|
console.log("PASS");
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
console.log((void 0).a);
|
||||||
|
} catch (e) {
|
||||||
|
console.log("PASS");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
expect_stdout: true
|
expect_stdout: [
|
||||||
|
"undefined undefined",
|
||||||
|
"true false",
|
||||||
|
"PASS",
|
||||||
|
"PASS",
|
||||||
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
unsafe_object: {
|
unsafe_object: {
|
||||||
@@ -1757,3 +1774,286 @@ issue_3387_2: {
|
|||||||
}
|
}
|
||||||
expect_stdout: "NaN"
|
expect_stdout: "NaN"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
simple_function_1: {
|
||||||
|
options = {
|
||||||
|
evaluate: true,
|
||||||
|
reduce_vars: true,
|
||||||
|
toplevel: true,
|
||||||
|
unused: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
function sum(a, b) {
|
||||||
|
return a + b;
|
||||||
|
}
|
||||||
|
console.log(sum(1, 2) * sum(3, 4));
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
console.log(21);
|
||||||
|
}
|
||||||
|
expect_stdout: "21"
|
||||||
|
}
|
||||||
|
|
||||||
|
simple_function_2: {
|
||||||
|
options = {
|
||||||
|
evaluate: true,
|
||||||
|
reduce_vars: true,
|
||||||
|
toplevel: true,
|
||||||
|
unused: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
var sum = function(a, b) {
|
||||||
|
return a + b;
|
||||||
|
}
|
||||||
|
console.log(sum(1, 2) * sum(3, 4));
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
console.log(21);
|
||||||
|
}
|
||||||
|
expect_stdout: "21"
|
||||||
|
}
|
||||||
|
|
||||||
|
recursive_function_1: {
|
||||||
|
options = {
|
||||||
|
evaluate: true,
|
||||||
|
reduce_vars: true,
|
||||||
|
toplevel: true,
|
||||||
|
unused: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
function factorial(a) {
|
||||||
|
return a > 0 ? a * factorial(a - 1) : 1;
|
||||||
|
}
|
||||||
|
console.log(factorial(5));
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
console.log(function factorial(a) {
|
||||||
|
return a > 0 ? a * factorial(a - 1) : 1;
|
||||||
|
}(5));
|
||||||
|
}
|
||||||
|
expect_stdout: "120"
|
||||||
|
}
|
||||||
|
|
||||||
|
recursive_function_2: {
|
||||||
|
options = {
|
||||||
|
evaluate: true,
|
||||||
|
reduce_vars: true,
|
||||||
|
toplevel: true,
|
||||||
|
unused: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
var factorial = function(a) {
|
||||||
|
return a > 0 ? a * factorial(a - 1) : 1;
|
||||||
|
}
|
||||||
|
console.log(factorial(5));
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
var factorial = function(a) {
|
||||||
|
return a > 0 ? a * factorial(a - 1) : 1;
|
||||||
|
}
|
||||||
|
console.log(factorial(5));
|
||||||
|
}
|
||||||
|
expect_stdout: "120"
|
||||||
|
}
|
||||||
|
|
||||||
|
issue_3558: {
|
||||||
|
options = {
|
||||||
|
evaluate: true,
|
||||||
|
reduce_vars: true,
|
||||||
|
toplevel: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
function f(a) {
|
||||||
|
return 1 + --a;
|
||||||
|
}
|
||||||
|
console.log(f(true), f(false));
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
function f(a) {
|
||||||
|
return 1 + --a;
|
||||||
|
}
|
||||||
|
console.log(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"
|
||||||
|
}
|
||||||
|
|||||||
@@ -1150,7 +1150,7 @@ issue_2620_3: {
|
|||||||
}
|
}
|
||||||
|
|
||||||
issue_2620_4: {
|
issue_2620_4: {
|
||||||
rename = true,
|
rename = true
|
||||||
options = {
|
options = {
|
||||||
dead_code: true,
|
dead_code: true,
|
||||||
evaluate: true,
|
evaluate: true,
|
||||||
@@ -2265,7 +2265,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 +2346,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");
|
||||||
})();
|
})();
|
||||||
@@ -2415,7 +2416,7 @@ issue_3297_2: {
|
|||||||
doProcessOne({
|
doProcessOne({
|
||||||
param1: param1,
|
param1: param1,
|
||||||
param2: param2,
|
param2: param2,
|
||||||
}, function () {
|
}, function() {
|
||||||
processBulk(bulk);
|
processBulk(bulk);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
@@ -2496,7 +2497,7 @@ issue_3297_3: {
|
|||||||
doProcessOne({
|
doProcessOne({
|
||||||
param1: param1,
|
param1: param1,
|
||||||
param2: param2,
|
param2: param2,
|
||||||
}, function () {
|
}, function() {
|
||||||
processBulk(bulk);
|
processBulk(bulk);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
@@ -2513,18 +2514,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());
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@@ -3066,7 +3070,7 @@ class_iife: {
|
|||||||
expect_stdout: "PASS"
|
expect_stdout: "PASS"
|
||||||
}
|
}
|
||||||
|
|
||||||
issue_3400: {
|
issue_3400_1: {
|
||||||
options = {
|
options = {
|
||||||
collapse_vars: true,
|
collapse_vars: true,
|
||||||
inline: true,
|
inline: true,
|
||||||
@@ -3097,12 +3101,15 @@ issue_3400: {
|
|||||||
}
|
}
|
||||||
expect: {
|
expect: {
|
||||||
void console.log(function g() {
|
void console.log(function g() {
|
||||||
|
function h(u) {
|
||||||
|
var o = {
|
||||||
|
p: u
|
||||||
|
};
|
||||||
|
return console.log(o[g]), o;
|
||||||
|
}
|
||||||
function e() {
|
function e() {
|
||||||
return [42].map(function(v) {
|
return [ 42 ].map(function(v) {
|
||||||
return o = {
|
return h(v);
|
||||||
p: v
|
|
||||||
}, console.log(o[g]) , o;
|
|
||||||
var o;
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
return e();
|
return e();
|
||||||
@@ -3114,6 +3121,52 @@ issue_3400: {
|
|||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
issue_3400_2: {
|
||||||
|
options = {
|
||||||
|
collapse_vars: true,
|
||||||
|
inline: true,
|
||||||
|
passes: 2,
|
||||||
|
reduce_funcs: true,
|
||||||
|
reduce_vars: true,
|
||||||
|
unused: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
(function(f) {
|
||||||
|
console.log(f()()[0].p);
|
||||||
|
})(function() {
|
||||||
|
function g() {
|
||||||
|
function h(u) {
|
||||||
|
var o = {
|
||||||
|
p: u
|
||||||
|
};
|
||||||
|
return console.log(o[g]), o;
|
||||||
|
}
|
||||||
|
function e() {
|
||||||
|
return [ 42 ].map(function(v) {
|
||||||
|
return h(v);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
return e();
|
||||||
|
}
|
||||||
|
return g;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
void console.log(function g() {
|
||||||
|
return [ 42 ].map(function(v) {
|
||||||
|
return o = {
|
||||||
|
p: v
|
||||||
|
}, console.log(o[g]), o;
|
||||||
|
var o;
|
||||||
|
});
|
||||||
|
}()[0].p);
|
||||||
|
}
|
||||||
|
expect_stdout: [
|
||||||
|
"undefined",
|
||||||
|
"42",
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
issue_3402: {
|
issue_3402: {
|
||||||
options = {
|
options = {
|
||||||
evaluate: true,
|
evaluate: true,
|
||||||
@@ -3196,3 +3249,322 @@ issue_3444: {
|
|||||||
}
|
}
|
||||||
expect_stdout: "PASS"
|
expect_stdout: "PASS"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
issue_3506_1: {
|
||||||
|
options = {
|
||||||
|
collapse_vars: true,
|
||||||
|
evaluate: true,
|
||||||
|
inline: true,
|
||||||
|
reduce_vars: true,
|
||||||
|
side_effects: true,
|
||||||
|
unused: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
var a = "FAIL";
|
||||||
|
(function(b) {
|
||||||
|
(function(b) {
|
||||||
|
b && (a = "PASS");
|
||||||
|
})(b);
|
||||||
|
})(a);
|
||||||
|
console.log(a);
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
var a = "FAIL";
|
||||||
|
!function(b) {
|
||||||
|
b && (a = "PASS");
|
||||||
|
}(a);
|
||||||
|
console.log(a);
|
||||||
|
}
|
||||||
|
expect_stdout: "PASS"
|
||||||
|
}
|
||||||
|
|
||||||
|
issue_3506_2: {
|
||||||
|
options = {
|
||||||
|
collapse_vars: true,
|
||||||
|
evaluate: true,
|
||||||
|
inline: true,
|
||||||
|
reduce_vars: true,
|
||||||
|
side_effects: true,
|
||||||
|
unused: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
var a = "FAIL";
|
||||||
|
(function(b) {
|
||||||
|
(function(c) {
|
||||||
|
var d = 1;
|
||||||
|
for (;c && (a = "PASS") && 0 < --d;);
|
||||||
|
})(b);
|
||||||
|
})(a);
|
||||||
|
console.log(a);
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
var a = "FAIL";
|
||||||
|
!function(c) {
|
||||||
|
var d = 1;
|
||||||
|
for (;c && (a = "PASS") && 0 < --d;);
|
||||||
|
}(a);
|
||||||
|
console.log(a);
|
||||||
|
}
|
||||||
|
expect_stdout: "PASS"
|
||||||
|
}
|
||||||
|
|
||||||
|
issue_3506_3: {
|
||||||
|
options = {
|
||||||
|
collapse_vars: true,
|
||||||
|
dead_code: true,
|
||||||
|
evaluate: true,
|
||||||
|
inline: true,
|
||||||
|
loops: true,
|
||||||
|
reduce_vars: true,
|
||||||
|
side_effects: true,
|
||||||
|
unused: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
var a = "FAIL";
|
||||||
|
(function(b) {
|
||||||
|
(function(c) {
|
||||||
|
var d = 1;
|
||||||
|
for (;c && (a = "PASS") && 0 < --d;);
|
||||||
|
})(b);
|
||||||
|
})(a);
|
||||||
|
console.log(a);
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
var a = "FAIL";
|
||||||
|
!function(c) {
|
||||||
|
var d = 1;
|
||||||
|
for (;c && (a = "PASS") && 0 < --d;);
|
||||||
|
}(a);
|
||||||
|
console.log(a);
|
||||||
|
}
|
||||||
|
expect_stdout: "PASS"
|
||||||
|
}
|
||||||
|
|
||||||
|
issue_3512: {
|
||||||
|
options = {
|
||||||
|
collapse_vars: true,
|
||||||
|
pure_getters: "strict",
|
||||||
|
sequences: true,
|
||||||
|
side_effects: true,
|
||||||
|
unused: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
var a = "PASS";
|
||||||
|
(function(b) {
|
||||||
|
(function() {
|
||||||
|
b <<= this || 1;
|
||||||
|
b.a = "FAIL";
|
||||||
|
})();
|
||||||
|
})();
|
||||||
|
console.log(a);
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
var a = "PASS";
|
||||||
|
(function(b) {
|
||||||
|
(function() {
|
||||||
|
(b <<= this || 1).a = "FAIL";
|
||||||
|
})();
|
||||||
|
})(),
|
||||||
|
console.log(a);
|
||||||
|
}
|
||||||
|
expect_stdout: "PASS"
|
||||||
|
}
|
||||||
|
|
||||||
|
issue_3562: {
|
||||||
|
options = {
|
||||||
|
collapse_vars: true,
|
||||||
|
reduce_vars: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
var a = "PASS";
|
||||||
|
function f(b) {
|
||||||
|
f = function() {
|
||||||
|
console.log(b);
|
||||||
|
};
|
||||||
|
return "FAIL";
|
||||||
|
}
|
||||||
|
a = f(a);
|
||||||
|
f(a);
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
var a = "PASS";
|
||||||
|
function f(b) {
|
||||||
|
f = function() {
|
||||||
|
console.log(b);
|
||||||
|
};
|
||||||
|
return "FAIL";
|
||||||
|
}
|
||||||
|
a = f(a);
|
||||||
|
f(a);
|
||||||
|
}
|
||||||
|
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"
|
||||||
|
}
|
||||||
|
|||||||
1432
test/compress/ie8.js
1432
test/compress/ie8.js
File diff suppressed because it is too large
Load Diff
@@ -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";
|
||||||
|
})();
|
||||||
|
})();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -689,3 +689,67 @@ 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]",
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|||||||
@@ -51,17 +51,20 @@ comparisons: {
|
|||||||
comparisons: true,
|
comparisons: true,
|
||||||
}
|
}
|
||||||
input: {
|
input: {
|
||||||
|
var x = "42", y = "0x30";
|
||||||
console.log(
|
console.log(
|
||||||
~x === 42,
|
~x === 42,
|
||||||
x % n === 42
|
x % y === 42
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
expect: {
|
expect: {
|
||||||
|
var x = "42", y = "0x30";
|
||||||
console.log(
|
console.log(
|
||||||
42 == ~x,
|
42 == ~x,
|
||||||
x % n == 42
|
x % y == 42
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
expect_stdout: "false true"
|
||||||
}
|
}
|
||||||
|
|
||||||
evaluate_1: {
|
evaluate_1: {
|
||||||
@@ -103,7 +106,7 @@ evaluate_1: {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
evaluate_2: {
|
evaluate_1_unsafe_math: {
|
||||||
options = {
|
options = {
|
||||||
evaluate: true,
|
evaluate: true,
|
||||||
unsafe_math: true,
|
unsafe_math: true,
|
||||||
@@ -118,6 +121,8 @@ evaluate_2: {
|
|||||||
1 + x-- + 2 + 3,
|
1 + x-- + 2 + 3,
|
||||||
1 + (x*y + 2) + 3,
|
1 + (x*y + 2) + 3,
|
||||||
1 + (2 + x + 3),
|
1 + (2 + x + 3),
|
||||||
|
1 + (2 + ~x + 3),
|
||||||
|
-y + (2 + ~x + 3),
|
||||||
1 & (2 & x & 3),
|
1 & (2 & x & 3),
|
||||||
1 + (2 + (x |= 0) + 3)
|
1 + (2 + (x |= 0) + 3)
|
||||||
);
|
);
|
||||||
@@ -126,18 +131,138 @@ evaluate_2: {
|
|||||||
console.log(
|
console.log(
|
||||||
x + 1 + 2,
|
x + 1 + 2,
|
||||||
2 * x,
|
2 * x,
|
||||||
3 + +x,
|
+x + 3,
|
||||||
1 + x + 2 + 3,
|
1 + x + 2 + 3,
|
||||||
3 | x,
|
3 | x,
|
||||||
6 + x--,
|
6 + x--,
|
||||||
6 + x*y,
|
x*y + 6,
|
||||||
1 + (2 + x + 3),
|
1 + (2 + x + 3),
|
||||||
|
6 + ~x,
|
||||||
|
5 - y + ~x,
|
||||||
0 & x,
|
0 & x,
|
||||||
6 + (x |= 0)
|
6 + (x |= 0)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
evaluate_2: {
|
||||||
|
options = {
|
||||||
|
evaluate: true,
|
||||||
|
unsafe_math: false,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
var x = "42", y = null;
|
||||||
|
[
|
||||||
|
x + 1 + 2,
|
||||||
|
x * 1 * 2,
|
||||||
|
+x + 1 + 2,
|
||||||
|
1 + x + 2 + 3,
|
||||||
|
1 | x | 2 | 3,
|
||||||
|
1 + x-- + 2 + 3,
|
||||||
|
1 + (x*y + 2) + 3,
|
||||||
|
1 + (2 + x + 3),
|
||||||
|
1 + (2 + ~x + 3),
|
||||||
|
-y + (2 + ~x + 3),
|
||||||
|
1 & (2 & x & 3),
|
||||||
|
1 + (2 + (x |= 0) + 3),
|
||||||
|
].forEach(function(n) {
|
||||||
|
console.log(typeof n, n);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
var x = "42", y = null;
|
||||||
|
[
|
||||||
|
x + 1 + 2,
|
||||||
|
1 * x * 2,
|
||||||
|
+x + 1 + 2,
|
||||||
|
1 + x + 2 + 3,
|
||||||
|
3 | x,
|
||||||
|
1 + x-- + 2 + 3,
|
||||||
|
x*y + 2 + 1 + 3,
|
||||||
|
1 + (2 + x + 3),
|
||||||
|
2 + ~x + 3 + 1,
|
||||||
|
2 + ~x + 3 - y,
|
||||||
|
0 & x,
|
||||||
|
2 + (x |= 0) + 3 + 1,
|
||||||
|
].forEach(function(n) {
|
||||||
|
console.log(typeof n, n);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
expect_stdout: [
|
||||||
|
"string 4212",
|
||||||
|
"number 84",
|
||||||
|
"number 45",
|
||||||
|
"string 14223",
|
||||||
|
"number 43",
|
||||||
|
"number 48",
|
||||||
|
"number 6",
|
||||||
|
"number 47",
|
||||||
|
"number -36",
|
||||||
|
"number -37",
|
||||||
|
"number 0",
|
||||||
|
"number 47",
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
|
evaluate_2_unsafe_math: {
|
||||||
|
options = {
|
||||||
|
evaluate: true,
|
||||||
|
unsafe_math: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
var x = "42", y = null;
|
||||||
|
[
|
||||||
|
x + 1 + 2,
|
||||||
|
x * 1 * 2,
|
||||||
|
+x + 1 + 2,
|
||||||
|
1 + x + 2 + 3,
|
||||||
|
1 | x | 2 | 3,
|
||||||
|
1 + x-- + 2 + 3,
|
||||||
|
1 + (x*y + 2) + 3,
|
||||||
|
1 + (2 + x + 3),
|
||||||
|
1 + (2 + ~x + 3),
|
||||||
|
-y + (2 + ~x + 3),
|
||||||
|
1 & (2 & x & 3),
|
||||||
|
1 + (2 + (x |= 0) + 3),
|
||||||
|
].forEach(function(n) {
|
||||||
|
console.log(typeof n, n);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
var x = "42", y = null;
|
||||||
|
[
|
||||||
|
x + 1 + 2,
|
||||||
|
2 * x,
|
||||||
|
+x + 3,
|
||||||
|
1 + x + 2 + 3,
|
||||||
|
3 | x,
|
||||||
|
6 + x--,
|
||||||
|
x*y + 6,
|
||||||
|
1 + (2 + x + 3),
|
||||||
|
6 + ~x,
|
||||||
|
5 + ~x - y,
|
||||||
|
0 & x,
|
||||||
|
6 + (x |= 0),
|
||||||
|
].forEach(function(n) {
|
||||||
|
console.log(typeof n, n);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
expect_stdout: [
|
||||||
|
"string 4212",
|
||||||
|
"number 84",
|
||||||
|
"number 45",
|
||||||
|
"string 14223",
|
||||||
|
"number 43",
|
||||||
|
"number 48",
|
||||||
|
"number 6",
|
||||||
|
"number 47",
|
||||||
|
"number -36",
|
||||||
|
"number -37",
|
||||||
|
"number 0",
|
||||||
|
"number 47",
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
evaluate_3: {
|
evaluate_3: {
|
||||||
options = {
|
options = {
|
||||||
evaluate: true,
|
evaluate: true,
|
||||||
@@ -148,7 +273,7 @@ evaluate_3: {
|
|||||||
console.log(1 + Number(x) + 2);
|
console.log(1 + Number(x) + 2);
|
||||||
}
|
}
|
||||||
expect: {
|
expect: {
|
||||||
console.log(3 + +x);
|
console.log(+x + 3);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -182,6 +307,352 @@ evaluate_4: {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
evaluate_5: {
|
||||||
|
options = {
|
||||||
|
evaluate: true,
|
||||||
|
unsafe_math: false,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
var a = "1";
|
||||||
|
[
|
||||||
|
+a + 2 + 3,
|
||||||
|
+a + 2 - 3,
|
||||||
|
+a - 2 + 3,
|
||||||
|
+a - 2 - 3,
|
||||||
|
2 + +a + 3,
|
||||||
|
2 + +a - 3,
|
||||||
|
2 - +a + 3,
|
||||||
|
2 - +a - 3,
|
||||||
|
2 + 3 + +a,
|
||||||
|
2 + 3 - +a,
|
||||||
|
2 - 3 + +a,
|
||||||
|
2 - 3 - +a,
|
||||||
|
].forEach(function(n) {
|
||||||
|
console.log(typeof n, n);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
var a = "1";
|
||||||
|
[
|
||||||
|
+a + 2 + 3,
|
||||||
|
+a + 2 - 3,
|
||||||
|
a - 2 + 3,
|
||||||
|
a - 2 - 3,
|
||||||
|
+a + 2 + 3,
|
||||||
|
+a + 2 - 3,
|
||||||
|
2 - a + 3,
|
||||||
|
2 - a - 3,
|
||||||
|
+a + 5,
|
||||||
|
5 - a,
|
||||||
|
+a - 1,
|
||||||
|
-1 - a,
|
||||||
|
].forEach(function(n) {
|
||||||
|
console.log(typeof n, n);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
expect_stdout: [
|
||||||
|
"number 6",
|
||||||
|
"number 0",
|
||||||
|
"number 2",
|
||||||
|
"number -4",
|
||||||
|
"number 6",
|
||||||
|
"number 0",
|
||||||
|
"number 4",
|
||||||
|
"number -2",
|
||||||
|
"number 6",
|
||||||
|
"number 4",
|
||||||
|
"number 0",
|
||||||
|
"number -2",
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
|
evaluate_5_unsafe_math: {
|
||||||
|
options = {
|
||||||
|
evaluate: true,
|
||||||
|
unsafe_math: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
var a = "1";
|
||||||
|
[
|
||||||
|
+a + 2 + 3,
|
||||||
|
+a + 2 - 3,
|
||||||
|
+a - 2 + 3,
|
||||||
|
+a - 2 - 3,
|
||||||
|
2 + +a + 3,
|
||||||
|
2 + +a - 3,
|
||||||
|
2 - +a + 3,
|
||||||
|
2 - +a - 3,
|
||||||
|
2 + 3 + +a,
|
||||||
|
2 + 3 - +a,
|
||||||
|
2 - 3 + +a,
|
||||||
|
2 - 3 - +a,
|
||||||
|
].forEach(function(n) {
|
||||||
|
console.log(typeof n, n);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
var a = "1";
|
||||||
|
[
|
||||||
|
+a + 5,
|
||||||
|
+a + -1,
|
||||||
|
a - -1,
|
||||||
|
a - 5,
|
||||||
|
+a + 5,
|
||||||
|
+a + -1,
|
||||||
|
5 - a,
|
||||||
|
-1 - a,
|
||||||
|
+a + 5,
|
||||||
|
5 - a,
|
||||||
|
+a - 1,
|
||||||
|
-1 - a,
|
||||||
|
].forEach(function(n) {
|
||||||
|
console.log(typeof n, n);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
expect_stdout: [
|
||||||
|
"number 6",
|
||||||
|
"number 0",
|
||||||
|
"number 2",
|
||||||
|
"number -4",
|
||||||
|
"number 6",
|
||||||
|
"number 0",
|
||||||
|
"number 4",
|
||||||
|
"number -2",
|
||||||
|
"number 6",
|
||||||
|
"number 4",
|
||||||
|
"number 0",
|
||||||
|
"number -2",
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
|
evaluate_6: {
|
||||||
|
options = {
|
||||||
|
evaluate: true,
|
||||||
|
unsafe_math: false,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
var a = "1";
|
||||||
|
[
|
||||||
|
-a + 2 + 3,
|
||||||
|
-a + 2 - 3,
|
||||||
|
-a - 2 + 3,
|
||||||
|
-a - 2 - 3,
|
||||||
|
2 + -a + 3,
|
||||||
|
2 + -a - 3,
|
||||||
|
2 - -a + 3,
|
||||||
|
2 - -a - 3,
|
||||||
|
2 + 3 + -a,
|
||||||
|
2 + 3 - -a,
|
||||||
|
2 - 3 + -a,
|
||||||
|
2 - 3 - -a,
|
||||||
|
].forEach(function(n) {
|
||||||
|
console.log(typeof n, n);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
var a = "1";
|
||||||
|
[
|
||||||
|
2 - a + 3,
|
||||||
|
2 - a - 3,
|
||||||
|
-a - 2 + 3,
|
||||||
|
-a - 2 - 3,
|
||||||
|
2 - a + 3,
|
||||||
|
2 - a - 3,
|
||||||
|
2 - -a + 3,
|
||||||
|
2 - -a - 3,
|
||||||
|
5 - a,
|
||||||
|
5 - -a,
|
||||||
|
-1 - a,
|
||||||
|
-1 - -a,
|
||||||
|
].forEach(function(n) {
|
||||||
|
console.log(typeof n, n);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
expect_stdout: [
|
||||||
|
"number 4",
|
||||||
|
"number -2",
|
||||||
|
"number 0",
|
||||||
|
"number -6",
|
||||||
|
"number 4",
|
||||||
|
"number -2",
|
||||||
|
"number 6",
|
||||||
|
"number 0",
|
||||||
|
"number 4",
|
||||||
|
"number 6",
|
||||||
|
"number -2",
|
||||||
|
"number 0",
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
|
evaluate_6_unsafe_math: {
|
||||||
|
options = {
|
||||||
|
evaluate: true,
|
||||||
|
unsafe_math: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
var a = "1";
|
||||||
|
[
|
||||||
|
-a + 2 + 3,
|
||||||
|
-a + 2 - 3,
|
||||||
|
-a - 2 + 3,
|
||||||
|
-a - 2 - 3,
|
||||||
|
2 + -a + 3,
|
||||||
|
2 + -a - 3,
|
||||||
|
2 - -a + 3,
|
||||||
|
2 - -a - 3,
|
||||||
|
2 + 3 + -a,
|
||||||
|
2 + 3 - -a,
|
||||||
|
2 - 3 + -a,
|
||||||
|
2 - 3 - -a,
|
||||||
|
].forEach(function(n) {
|
||||||
|
console.log(typeof n, n);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
var a = "1";
|
||||||
|
[
|
||||||
|
5 - a,
|
||||||
|
-1 - a,
|
||||||
|
-a - -1,
|
||||||
|
-a - 5,
|
||||||
|
5 - a,
|
||||||
|
-1 - a,
|
||||||
|
5 - -a,
|
||||||
|
-1 - -a,
|
||||||
|
5 - a,
|
||||||
|
5 - -a,
|
||||||
|
-1 - a,
|
||||||
|
-1 - -a,
|
||||||
|
].forEach(function(n) {
|
||||||
|
console.log(typeof n, n);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
expect_stdout: [
|
||||||
|
"number 4",
|
||||||
|
"number -2",
|
||||||
|
"number 0",
|
||||||
|
"number -6",
|
||||||
|
"number 4",
|
||||||
|
"number -2",
|
||||||
|
"number 6",
|
||||||
|
"number 0",
|
||||||
|
"number 4",
|
||||||
|
"number 6",
|
||||||
|
"number -2",
|
||||||
|
"number 0",
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
|
evaluate_7: {
|
||||||
|
options = {
|
||||||
|
evaluate: true,
|
||||||
|
unsafe_math: false,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
var x = "42", y;
|
||||||
|
[
|
||||||
|
+x + 2 + (3 + !y),
|
||||||
|
+x + 2 + (3 - !y),
|
||||||
|
+x + 2 - (3 + !y),
|
||||||
|
+x + 2 - (3 - !y),
|
||||||
|
+x - 2 + (3 + !y),
|
||||||
|
+x - 2 + (3 - !y),
|
||||||
|
+x - 2 - (3 + !y),
|
||||||
|
+x - 2 - (3 - !y),
|
||||||
|
].forEach(function(n) {
|
||||||
|
console.log(typeof n, n);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
var x = "42", y;
|
||||||
|
[
|
||||||
|
+x + 2 + (3 + !y),
|
||||||
|
+x + 2 + (3 - !y),
|
||||||
|
+x + 2 - (3 + !y),
|
||||||
|
+x + 2 - (3 - !y),
|
||||||
|
x - 2 + (3 + !y),
|
||||||
|
x - 2 + (3 - !y),
|
||||||
|
x - 2 - (3 + !y),
|
||||||
|
x - 2 - (3 - !y),
|
||||||
|
].forEach(function(n) {
|
||||||
|
console.log(typeof n, n);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
expect_stdout: [
|
||||||
|
"number 48",
|
||||||
|
"number 46",
|
||||||
|
"number 40",
|
||||||
|
"number 42",
|
||||||
|
"number 44",
|
||||||
|
"number 42",
|
||||||
|
"number 36",
|
||||||
|
"number 38",
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
|
evaluate_7_unsafe_math: {
|
||||||
|
options = {
|
||||||
|
evaluate: true,
|
||||||
|
unsafe_math: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
var x = "42", y;
|
||||||
|
[
|
||||||
|
+x + 2 + (3 + !y),
|
||||||
|
+x + 2 + (3 - !y),
|
||||||
|
+x + 2 - (3 + !y),
|
||||||
|
+x + 2 - (3 - !y),
|
||||||
|
+x - 2 + (3 + !y),
|
||||||
|
+x - 2 + (3 - !y),
|
||||||
|
+x - 2 - (3 + !y),
|
||||||
|
+x - 2 - (3 - !y),
|
||||||
|
].forEach(function(n) {
|
||||||
|
console.log(typeof n, n);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
var x = "42", y;
|
||||||
|
[
|
||||||
|
+x + 5 + !y,
|
||||||
|
+x + 5 - !y,
|
||||||
|
+x + -1 - !y,
|
||||||
|
+x + -1 + !y,
|
||||||
|
x - -1 + !y,
|
||||||
|
x - -1 - !y,
|
||||||
|
x - 5 - !y,
|
||||||
|
x - 5 + !y,
|
||||||
|
].forEach(function(n) {
|
||||||
|
console.log(typeof n, n);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
expect_stdout: [
|
||||||
|
"number 48",
|
||||||
|
"number 46",
|
||||||
|
"number 40",
|
||||||
|
"number 42",
|
||||||
|
"number 44",
|
||||||
|
"number 42",
|
||||||
|
"number 36",
|
||||||
|
"number 38",
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
|
NaN_redefined: {
|
||||||
|
options = {
|
||||||
|
evaluate: true,
|
||||||
|
unsafe_math: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
var NaN;
|
||||||
|
console.log(1 / (0 / 0));
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
var NaN;
|
||||||
|
console.log(0 / 0);
|
||||||
|
}
|
||||||
|
expect_stdout: "NaN"
|
||||||
|
}
|
||||||
|
|
||||||
issue_1710: {
|
issue_1710: {
|
||||||
options = {
|
options = {
|
||||||
evaluate: true,
|
evaluate: true,
|
||||||
@@ -230,3 +701,247 @@ unary_binary_parenthesis: {
|
|||||||
}
|
}
|
||||||
expect_stdout: true
|
expect_stdout: true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
issue_3531_1: {
|
||||||
|
options = {
|
||||||
|
evaluate: true,
|
||||||
|
unsafe_math: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
var a = "1";
|
||||||
|
console.log(typeof (a + 1 - .1 - .1 - .1));
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
var a = "1";
|
||||||
|
console.log(typeof (a + 1 - .3));
|
||||||
|
}
|
||||||
|
expect_stdout: "number"
|
||||||
|
}
|
||||||
|
|
||||||
|
issue_3531_2: {
|
||||||
|
options = {
|
||||||
|
evaluate: true,
|
||||||
|
unsafe_math: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
console.log(1 - (2 - {}));
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
console.log(-1 + +{});
|
||||||
|
}
|
||||||
|
expect_stdout: "NaN"
|
||||||
|
}
|
||||||
|
|
||||||
|
issue_3531_3: {
|
||||||
|
options = {
|
||||||
|
evaluate: true,
|
||||||
|
unsafe_math: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
var a = "3";
|
||||||
|
console.log(1 - (2 + a));
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
var a = "3";
|
||||||
|
console.log(1 - (2 + a));
|
||||||
|
}
|
||||||
|
expect_stdout: "-22"
|
||||||
|
}
|
||||||
|
|
||||||
|
issue_3536: {
|
||||||
|
options = {
|
||||||
|
evaluate: true,
|
||||||
|
unsafe_math: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
var a = 100, b = 10;
|
||||||
|
var c = --a + ("23" - (b++, 1));
|
||||||
|
console.log(typeof c, a, b, c);
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
var a = 100, b = 10;
|
||||||
|
var c = --a + ("23" - (b++, 1));
|
||||||
|
console.log(typeof c, a, b, c);
|
||||||
|
}
|
||||||
|
expect_stdout: "number 99 11 121"
|
||||||
|
}
|
||||||
|
|
||||||
|
issue_3539: {
|
||||||
|
options = {
|
||||||
|
evaluate: true,
|
||||||
|
unsafe_math: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
var a = -0 + -"";
|
||||||
|
console.log(0/a, 1/a, -1/a);
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
var a = -0;
|
||||||
|
console.log(0/a, 1/a, -1/a);
|
||||||
|
}
|
||||||
|
expect_stdout: "NaN -Infinity Infinity"
|
||||||
|
}
|
||||||
|
|
||||||
|
issue_3547_1: {
|
||||||
|
options = {
|
||||||
|
evaluate: true,
|
||||||
|
unsafe_math: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
[
|
||||||
|
1/0 + "1" + 0,
|
||||||
|
1/0 + "1" - 0,
|
||||||
|
1/0 - "1" + 0,
|
||||||
|
1/0 - "1" - 0,
|
||||||
|
].forEach(function(n) {
|
||||||
|
console.log(typeof n, n);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
[
|
||||||
|
1/0 + "10",
|
||||||
|
NaN,
|
||||||
|
1/0,
|
||||||
|
1/0,
|
||||||
|
].forEach(function(n) {
|
||||||
|
console.log(typeof n, n);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
expect_stdout: [
|
||||||
|
"string Infinity10",
|
||||||
|
"number NaN",
|
||||||
|
"number Infinity",
|
||||||
|
"number Infinity",
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
|
issue_3547_2: {
|
||||||
|
options = {
|
||||||
|
evaluate: true,
|
||||||
|
unsafe_math: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
[
|
||||||
|
"1" + 1/0 + 0,
|
||||||
|
"1" + 1/0 - 0,
|
||||||
|
"1" - 1/0 + 0,
|
||||||
|
"1" - 1/0 - 0,
|
||||||
|
].forEach(function(n) {
|
||||||
|
console.log(typeof n, n);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
[
|
||||||
|
"1" + 1/0 + 0,
|
||||||
|
NaN,
|
||||||
|
-1/0,
|
||||||
|
-1/0,
|
||||||
|
].forEach(function(n) {
|
||||||
|
console.log(typeof n, n);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
expect_stdout: [
|
||||||
|
"string 1Infinity0",
|
||||||
|
"number NaN",
|
||||||
|
"number -Infinity",
|
||||||
|
"number -Infinity",
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
|
issue_3547_3: {
|
||||||
|
options = {
|
||||||
|
evaluate: true,
|
||||||
|
unsafe_math: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
var a = "3";
|
||||||
|
[
|
||||||
|
a + "2" + 1,
|
||||||
|
a + "2" - 1,
|
||||||
|
a - "2" + 1,
|
||||||
|
a - "2" - 1,
|
||||||
|
].forEach(function(n) {
|
||||||
|
console.log(typeof n, n);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
var a = "3";
|
||||||
|
[
|
||||||
|
a + "21",
|
||||||
|
a + "2" - 1,
|
||||||
|
a - 1,
|
||||||
|
a - 3,
|
||||||
|
].forEach(function(n) {
|
||||||
|
console.log(typeof n, n);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
expect_stdout: [
|
||||||
|
"string 321",
|
||||||
|
"number 31",
|
||||||
|
"number 2",
|
||||||
|
"number 0",
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
|
issue_3547_4: {
|
||||||
|
options = {
|
||||||
|
evaluate: true,
|
||||||
|
unsafe_math: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
var a = "2";
|
||||||
|
[
|
||||||
|
"3" + a + 1,
|
||||||
|
"3" + a - 1,
|
||||||
|
"3" - a + 1,
|
||||||
|
"3" - a - 1,
|
||||||
|
].forEach(function(n) {
|
||||||
|
console.log(typeof n, n);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
var a = "2";
|
||||||
|
[
|
||||||
|
"3" + a + 1,
|
||||||
|
"3" + a - 1,
|
||||||
|
4 - a,
|
||||||
|
2 - a,
|
||||||
|
].forEach(function(n) {
|
||||||
|
console.log(typeof n, n);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
expect_stdout: [
|
||||||
|
"string 321",
|
||||||
|
"number 31",
|
||||||
|
"number 2",
|
||||||
|
"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"
|
||||||
|
}
|
||||||
|
|||||||
223
test/compress/objects.js
Normal file
223
test/compress/objects.js
Normal file
@@ -0,0 +1,223 @@
|
|||||||
|
duplicate_key: {
|
||||||
|
options = {
|
||||||
|
objects: true,
|
||||||
|
side_effects: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
var o = {
|
||||||
|
a: 1,
|
||||||
|
b: 2,
|
||||||
|
a: 3,
|
||||||
|
};
|
||||||
|
for (var k in o)
|
||||||
|
console.log(k, o[k]);
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
var o = {
|
||||||
|
a: 3,
|
||||||
|
b: 2,
|
||||||
|
};
|
||||||
|
for (var k in o)
|
||||||
|
console.log(k, o[k]);
|
||||||
|
}
|
||||||
|
expect_stdout: [
|
||||||
|
"a 3",
|
||||||
|
"b 2",
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
|
duplicate_key_strict: {
|
||||||
|
options = {
|
||||||
|
objects: true,
|
||||||
|
side_effects: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
"use strict";
|
||||||
|
var o = {
|
||||||
|
a: 1,
|
||||||
|
b: 2,
|
||||||
|
a: 3,
|
||||||
|
};
|
||||||
|
for (var k in o)
|
||||||
|
console.log(k, o[k]);
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
"use strict";
|
||||||
|
var o = {
|
||||||
|
a: 1,
|
||||||
|
b: 2,
|
||||||
|
a: 3,
|
||||||
|
};
|
||||||
|
for (var k in o)
|
||||||
|
console.log(k, o[k]);
|
||||||
|
}
|
||||||
|
expect_stdout: true
|
||||||
|
}
|
||||||
|
|
||||||
|
duplicate_key_side_effect: {
|
||||||
|
options = {
|
||||||
|
objects: true,
|
||||||
|
side_effects: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
var o = {
|
||||||
|
a: 1,
|
||||||
|
b: o = 2,
|
||||||
|
a: 3,
|
||||||
|
};
|
||||||
|
for (var k in o)
|
||||||
|
console.log(k, o[k]);
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
var o = {
|
||||||
|
a: 1,
|
||||||
|
b: o = 2,
|
||||||
|
a: 3,
|
||||||
|
};
|
||||||
|
for (var k in o)
|
||||||
|
console.log(k, o[k]);
|
||||||
|
}
|
||||||
|
expect_stdout: [
|
||||||
|
"a 3",
|
||||||
|
"b 2",
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
|
duplicate_key_with_accessor: {
|
||||||
|
options = {
|
||||||
|
objects: true,
|
||||||
|
side_effects: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
[
|
||||||
|
{
|
||||||
|
a: 0,
|
||||||
|
b: 1,
|
||||||
|
a: 2,
|
||||||
|
set b(v) {},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
a: 3,
|
||||||
|
b: 4,
|
||||||
|
get a() {
|
||||||
|
return 5;
|
||||||
|
},
|
||||||
|
a: 6,
|
||||||
|
b: 7,
|
||||||
|
a: 8,
|
||||||
|
b: 9,
|
||||||
|
},
|
||||||
|
].forEach(function(o) {
|
||||||
|
for (var k in o)
|
||||||
|
console.log(k, o[k]);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
[
|
||||||
|
{
|
||||||
|
a: 2,
|
||||||
|
b: 1,
|
||||||
|
set b(v) {},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
a: 3,
|
||||||
|
b: 4,
|
||||||
|
get a() {
|
||||||
|
return 5;
|
||||||
|
},
|
||||||
|
a: 8,
|
||||||
|
b: 9,
|
||||||
|
},
|
||||||
|
].forEach(function(o) {
|
||||||
|
for (var k in o)
|
||||||
|
console.log(k, o[k]);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
expect_stdout: true
|
||||||
|
}
|
||||||
|
|
||||||
|
unsafe_object_repeated: {
|
||||||
|
options = {
|
||||||
|
evaluate: true,
|
||||||
|
objects: true,
|
||||||
|
reduce_funcs: true,
|
||||||
|
reduce_vars: true,
|
||||||
|
side_effects: true,
|
||||||
|
toplevel: true,
|
||||||
|
unsafe: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
var o = { a: { b: 1 }, a: 1 };
|
||||||
|
console.log(
|
||||||
|
o + 1,
|
||||||
|
o.a + 1,
|
||||||
|
o.b + 1,
|
||||||
|
o.a.b + 1
|
||||||
|
);
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
var o = { a: 1 };
|
||||||
|
console.log(
|
||||||
|
o + 1,
|
||||||
|
2,
|
||||||
|
o.b + 1,
|
||||||
|
NaN
|
||||||
|
);
|
||||||
|
}
|
||||||
|
expect_stdout: true
|
||||||
|
}
|
||||||
|
|
||||||
|
numeric_literal: {
|
||||||
|
options = {
|
||||||
|
objects: true,
|
||||||
|
side_effects: true,
|
||||||
|
}
|
||||||
|
mangle = {
|
||||||
|
properties: true,
|
||||||
|
}
|
||||||
|
beautify = {
|
||||||
|
beautify: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
var obj = {
|
||||||
|
0: 0,
|
||||||
|
"-0": 1,
|
||||||
|
42: 2,
|
||||||
|
"42": 3,
|
||||||
|
0x25: 4,
|
||||||
|
"0x25": 5,
|
||||||
|
1E42: 6,
|
||||||
|
"1E42": 7,
|
||||||
|
"1e+42": 8,
|
||||||
|
};
|
||||||
|
console.log(obj[-0], obj[-""], obj["-0"]);
|
||||||
|
console.log(obj[42], obj["42"]);
|
||||||
|
console.log(obj[0x25], obj["0x25"], obj[37], obj["37"]);
|
||||||
|
console.log(obj[1E42], obj["1E42"], obj["1e+42"]);
|
||||||
|
}
|
||||||
|
expect_exact: [
|
||||||
|
'var obj = {',
|
||||||
|
' 0: 0,',
|
||||||
|
' "-0": 1,',
|
||||||
|
' 42: 3,',
|
||||||
|
' 37: 4,',
|
||||||
|
' o: 5,',
|
||||||
|
' 1e42: 8,',
|
||||||
|
' b: 7',
|
||||||
|
'};',
|
||||||
|
'',
|
||||||
|
'console.log(obj[-0], obj[-""], obj["-0"]);',
|
||||||
|
'',
|
||||||
|
'console.log(obj[42], obj["42"]);',
|
||||||
|
'',
|
||||||
|
'console.log(obj[37], obj["o"], obj[37], obj["37"]);',
|
||||||
|
'',
|
||||||
|
'console.log(obj[1e42], obj["b"], obj["1e+42"]);',
|
||||||
|
]
|
||||||
|
expect_stdout: [
|
||||||
|
"0 0 1",
|
||||||
|
"3 3",
|
||||||
|
"4 5 4 4",
|
||||||
|
"8 7 8",
|
||||||
|
]
|
||||||
|
}
|
||||||
@@ -1193,6 +1193,7 @@ issue_3427: {
|
|||||||
assignments: true,
|
assignments: true,
|
||||||
collapse_vars: true,
|
collapse_vars: true,
|
||||||
inline: true,
|
inline: true,
|
||||||
|
passes: 2,
|
||||||
pure_getters: "strict",
|
pure_getters: "strict",
|
||||||
sequences: true,
|
sequences: true,
|
||||||
side_effects: true,
|
side_effects: true,
|
||||||
@@ -1206,4 +1207,5 @@ issue_3427: {
|
|||||||
})(a || (a = {}));
|
})(a || (a = {}));
|
||||||
}
|
}
|
||||||
expect: {}
|
expect: {}
|
||||||
|
expect_stdout: true
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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());
|
||||||
}
|
}
|
||||||
@@ -4947,7 +4943,7 @@ defun_single_use_loop: {
|
|||||||
unused: true,
|
unused: true,
|
||||||
}
|
}
|
||||||
input: {
|
input: {
|
||||||
for (var x, i = 2; --i >= 0; ) {
|
for (var x, i = 2; --i >= 0;) {
|
||||||
var y = x;
|
var y = x;
|
||||||
x = f;
|
x = f;
|
||||||
console.log(x === y);
|
console.log(x === y);
|
||||||
@@ -4955,7 +4951,7 @@ defun_single_use_loop: {
|
|||||||
function f() {};
|
function f() {};
|
||||||
}
|
}
|
||||||
expect: {
|
expect: {
|
||||||
for (var x, i = 2; --i >= 0; ) {
|
for (var x, i = 2; --i >= 0;) {
|
||||||
var y = x;
|
var y = x;
|
||||||
x = f;
|
x = f;
|
||||||
console.log(x === y);
|
console.log(x === y);
|
||||||
@@ -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"
|
||||||
}
|
}
|
||||||
@@ -6609,10 +6603,10 @@ issues_3267_1: {
|
|||||||
}
|
}
|
||||||
expect: {
|
expect: {
|
||||||
!function(i) {
|
!function(i) {
|
||||||
if (i)
|
if (Object())
|
||||||
return console.log("PASS");
|
return console.log("PASS");
|
||||||
throw "FAIL";
|
throw "FAIL";
|
||||||
}(Object());
|
}();
|
||||||
}
|
}
|
||||||
expect_stdout: "PASS"
|
expect_stdout: "PASS"
|
||||||
}
|
}
|
||||||
@@ -6752,3 +6746,31 @@ issue_3377: {
|
|||||||
}
|
}
|
||||||
expect_stdout: "42"
|
expect_stdout: "42"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
issue_3509: {
|
||||||
|
options = {
|
||||||
|
reduce_vars: true,
|
||||||
|
toplevel: true,
|
||||||
|
unused: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
function a() {
|
||||||
|
console.log("PASS");
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
} catch (a) {
|
||||||
|
var a;
|
||||||
|
}
|
||||||
|
a();
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
try {
|
||||||
|
} catch (a) {
|
||||||
|
var a;
|
||||||
|
}
|
||||||
|
(function() {
|
||||||
|
console.log("PASS");
|
||||||
|
})();
|
||||||
|
}
|
||||||
|
expect_stdout: "PASS"
|
||||||
|
}
|
||||||
|
|||||||
@@ -36,6 +36,20 @@ regexp_2: {
|
|||||||
expect_stdout: '["PASS","pass"]'
|
expect_stdout: '["PASS","pass"]'
|
||||||
}
|
}
|
||||||
|
|
||||||
|
regexp_properties: {
|
||||||
|
options = {
|
||||||
|
evaluate: true,
|
||||||
|
unsafe: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
console.log(/abc/g.source, /abc/g.global, /abc/g.ignoreCase, /abc/g.lastIndex, /abc/g.multiline);
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
console.log("abc", true, false, /abc/g.lastIndex, false);
|
||||||
|
}
|
||||||
|
expect_stdout: "abc true false 0 false"
|
||||||
|
}
|
||||||
|
|
||||||
issue_3434_1: {
|
issue_3434_1: {
|
||||||
options = {
|
options = {
|
||||||
evaluate: true,
|
evaluate: true,
|
||||||
|
|||||||
@@ -579,7 +579,7 @@ function_do_catch_ie8: {
|
|||||||
console.log(b, c);
|
console.log(b, c);
|
||||||
}
|
}
|
||||||
expect: {
|
expect: {
|
||||||
var t = 1, u = 1, y = 0;
|
var u = 1, y = 1, a = 0;
|
||||||
function c(c) {
|
function c(c) {
|
||||||
var d;
|
var d;
|
||||||
do {
|
do {
|
||||||
@@ -587,7 +587,7 @@ function_do_catch_ie8: {
|
|||||||
try {
|
try {
|
||||||
var e = void 0;
|
var e = void 0;
|
||||||
} catch (i) {
|
} catch (i) {
|
||||||
--t && w("ddddddddeeeeeeegggggggggiiiiilllllllnnnnntuuuuuuuuyyyyyyy");
|
--u && w("ddddddddeeeeeeegggggggggiiiiilllllllnnnnntuuuuuuuuyyyyyyy");
|
||||||
0;
|
0;
|
||||||
0;
|
0;
|
||||||
0;
|
0;
|
||||||
@@ -596,18 +596,146 @@ function_do_catch_ie8: {
|
|||||||
d[1];
|
d[1];
|
||||||
} catch (l) {
|
} catch (l) {
|
||||||
var g;
|
var g;
|
||||||
switch(function x() {
|
switch (function n() {
|
||||||
y++;
|
a++;
|
||||||
}()) {
|
}()) {
|
||||||
case e + --g:
|
case e + --g:
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (n) {}
|
} catch (t) {}
|
||||||
} while (--d);
|
} while (--d);
|
||||||
u--;
|
y--;
|
||||||
}
|
}
|
||||||
c();
|
c();
|
||||||
console.log(u, y);
|
console.log(y, a);
|
||||||
}
|
}
|
||||||
expect_stdout: "0 1"
|
expect_stdout: "0 1"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
issue_3480: {
|
||||||
|
rename = true,
|
||||||
|
mangle = {
|
||||||
|
ie8: false,
|
||||||
|
toplevel: false,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
var d, a, b, c = "FAIL";
|
||||||
|
(function b() {
|
||||||
|
(function() {
|
||||||
|
try {
|
||||||
|
c = "PASS";
|
||||||
|
} catch (b) {
|
||||||
|
}
|
||||||
|
})();
|
||||||
|
})();
|
||||||
|
console.log(c);
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
var d, a, b, c = "FAIL";
|
||||||
|
(function n() {
|
||||||
|
(function() {
|
||||||
|
try {
|
||||||
|
c = "PASS";
|
||||||
|
} catch (c) {}
|
||||||
|
})();
|
||||||
|
})();
|
||||||
|
console.log(c);
|
||||||
|
}
|
||||||
|
expect_stdout: "PASS"
|
||||||
|
}
|
||||||
|
|
||||||
|
issue_3480_ie8: {
|
||||||
|
rename = true,
|
||||||
|
mangle = {
|
||||||
|
ie8: true,
|
||||||
|
toplevel: false,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
var d, a, b, c = "FAIL";
|
||||||
|
(function b() {
|
||||||
|
(function() {
|
||||||
|
try {
|
||||||
|
c = "PASS";
|
||||||
|
} catch (b) {
|
||||||
|
}
|
||||||
|
})();
|
||||||
|
})();
|
||||||
|
console.log(c);
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
var d, a, b, c = "FAIL";
|
||||||
|
(function b() {
|
||||||
|
(function() {
|
||||||
|
try {
|
||||||
|
c = "PASS";
|
||||||
|
} catch (b) {}
|
||||||
|
})();
|
||||||
|
})();
|
||||||
|
console.log(c);
|
||||||
|
}
|
||||||
|
expect_stdout: "PASS"
|
||||||
|
}
|
||||||
|
|
||||||
|
issue_3480_toplevel: {
|
||||||
|
rename = true,
|
||||||
|
mangle = {
|
||||||
|
ie8: false,
|
||||||
|
toplevel: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
var d, a, b, c = "FAIL";
|
||||||
|
(function b() {
|
||||||
|
(function() {
|
||||||
|
try {
|
||||||
|
c = "PASS";
|
||||||
|
} catch (b) {
|
||||||
|
}
|
||||||
|
})();
|
||||||
|
})();
|
||||||
|
console.log(c);
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
var c, n, o, t = "FAIL";
|
||||||
|
(function c() {
|
||||||
|
(function() {
|
||||||
|
try {
|
||||||
|
t = "PASS";
|
||||||
|
} catch (c) {}
|
||||||
|
})();
|
||||||
|
})();
|
||||||
|
console.log(t);
|
||||||
|
}
|
||||||
|
expect_stdout: "PASS"
|
||||||
|
}
|
||||||
|
|
||||||
|
issue_3480_ie8_toplevel: {
|
||||||
|
rename = true,
|
||||||
|
mangle = {
|
||||||
|
ie8: true,
|
||||||
|
toplevel: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
var d, a, b, c = "FAIL";
|
||||||
|
(function b() {
|
||||||
|
(function() {
|
||||||
|
try {
|
||||||
|
c = "PASS";
|
||||||
|
} catch (b) {
|
||||||
|
}
|
||||||
|
})();
|
||||||
|
})();
|
||||||
|
console.log(c);
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
var c, n, o, t = "FAIL";
|
||||||
|
(function o() {
|
||||||
|
(function() {
|
||||||
|
try {
|
||||||
|
t = "PASS";
|
||||||
|
} catch (o) {}
|
||||||
|
})();
|
||||||
|
})();
|
||||||
|
console.log(t);
|
||||||
|
}
|
||||||
|
expect_stdout: "PASS"
|
||||||
|
}
|
||||||
|
|||||||
@@ -1006,3 +1006,66 @@ angularjs_chain: {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
issue_3490_1: {
|
||||||
|
options = {
|
||||||
|
conditionals: true,
|
||||||
|
dead_code: true,
|
||||||
|
inline: true,
|
||||||
|
sequences: true,
|
||||||
|
side_effects: true,
|
||||||
|
toplevel: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
var b = 42, c = "FAIL";
|
||||||
|
if ({
|
||||||
|
3: function() {
|
||||||
|
var a;
|
||||||
|
return (a && a.p) < this;
|
||||||
|
}(),
|
||||||
|
}) c = "PASS";
|
||||||
|
if (b) while ("" == typeof d);
|
||||||
|
console.log(c, b);
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
var b = 42, c = "FAIL";
|
||||||
|
if (function() {
|
||||||
|
var a;
|
||||||
|
a && a.p;
|
||||||
|
}(), c = "PASS", b) while ("" == typeof d);
|
||||||
|
console.log(c, b);
|
||||||
|
}
|
||||||
|
expect_stdout: "PASS 42"
|
||||||
|
}
|
||||||
|
|
||||||
|
issue_3490_2: {
|
||||||
|
options = {
|
||||||
|
conditionals: true,
|
||||||
|
dead_code: true,
|
||||||
|
evaluate: true,
|
||||||
|
inline: true,
|
||||||
|
reduce_vars: true,
|
||||||
|
sequences: true,
|
||||||
|
side_effects: true,
|
||||||
|
toplevel: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
var b = 42, c = "FAIL";
|
||||||
|
if ({
|
||||||
|
3: function() {
|
||||||
|
var a;
|
||||||
|
return (a && a.p) < this;
|
||||||
|
}(),
|
||||||
|
}) c = "PASS";
|
||||||
|
if (b) for (; "" == typeof d;);
|
||||||
|
console.log(c, b);
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
var b = 42, c = "FAIL";
|
||||||
|
for (function() {
|
||||||
|
var a;
|
||||||
|
}(), c = "PASS", b; "" == typeof d;);
|
||||||
|
console.log(c, b);
|
||||||
|
}
|
||||||
|
expect_stdout: "PASS 42"
|
||||||
|
}
|
||||||
|
|||||||
@@ -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"
|
||||||
|
}
|
||||||
|
|||||||
@@ -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"
|
||||||
}
|
}
|
||||||
@@ -295,3 +293,145 @@ issue_2728_6: {
|
|||||||
}
|
}
|
||||||
expect_stdout: "function undefined"
|
expect_stdout: "function undefined"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
typeof_defined_1: {
|
||||||
|
options = {
|
||||||
|
side_effects: true,
|
||||||
|
typeofs: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
"undefined" == typeof A && A;
|
||||||
|
"undefined" != typeof A && A;
|
||||||
|
"undefined" == typeof A || A;
|
||||||
|
"undefined" != typeof A || A;
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
"undefined" == typeof A && A;
|
||||||
|
"undefined" != typeof A || A;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
typeof_defined_2: {
|
||||||
|
options = {
|
||||||
|
side_effects: true,
|
||||||
|
typeofs: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
"function" == typeof A && A;
|
||||||
|
"function" != typeof A && A;
|
||||||
|
"function" == typeof A || A;
|
||||||
|
"function" != typeof A || A;
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
"function" != typeof A && A;
|
||||||
|
"function" == typeof A || A;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
typeof_defined_3: {
|
||||||
|
options = {
|
||||||
|
side_effects: true,
|
||||||
|
typeofs: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
"undefined" == typeof A && "undefined" == typeof B && (A, B);
|
||||||
|
"undefined" == typeof A && "undefined" != typeof B && (A, B);
|
||||||
|
"undefined" != typeof A && "undefined" == typeof B && (A, B);
|
||||||
|
"undefined" != typeof A && "undefined" != typeof B && (A, B);
|
||||||
|
"undefined" == typeof A && "undefined" == typeof B || (A, B);
|
||||||
|
"undefined" == typeof A && "undefined" != typeof B || (A, B);
|
||||||
|
"undefined" != typeof A && "undefined" == typeof B || (A, B);
|
||||||
|
"undefined" != typeof A && "undefined" != typeof B || (A, B);
|
||||||
|
"undefined" == typeof A || "undefined" == typeof B && (A, B);
|
||||||
|
"undefined" == typeof A || "undefined" != typeof B && (A, B);
|
||||||
|
"undefined" != typeof A || "undefined" == typeof B && (A, B);
|
||||||
|
"undefined" != typeof A || "undefined" != typeof B && (A, B);
|
||||||
|
"undefined" == typeof A || "undefined" == typeof B || (A, B);
|
||||||
|
"undefined" == typeof A || "undefined" != typeof B || (A, B);
|
||||||
|
"undefined" != typeof A || "undefined" == typeof B || (A, B);
|
||||||
|
"undefined" != typeof A || "undefined" != typeof B || (A, B);
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
"undefined" == typeof A && "undefined" == typeof B && (A, B);
|
||||||
|
"undefined" == typeof A && "undefined" != typeof B && A;
|
||||||
|
"undefined" != typeof A && "undefined" == typeof B && B;
|
||||||
|
"undefined" == typeof A && "undefined" == typeof B || (A, B);
|
||||||
|
"undefined" == typeof A && "undefined" != typeof B || (A, B);
|
||||||
|
"undefined" != typeof A && "undefined" == typeof B || (A, B);
|
||||||
|
"undefined" != typeof A && "undefined" != typeof B || (A, B);
|
||||||
|
"undefined" == typeof A || "undefined" == typeof B && B;
|
||||||
|
"undefined" != typeof A || "undefined" == typeof B && (A, B);
|
||||||
|
"undefined" != typeof A || "undefined" != typeof B && A;
|
||||||
|
"undefined" == typeof A || "undefined" != typeof B || B;
|
||||||
|
"undefined" != typeof A || "undefined" == typeof B || A;
|
||||||
|
"undefined" != typeof A || "undefined" != typeof B || (A, B);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
typeof_defined_4: {
|
||||||
|
options = {
|
||||||
|
side_effects: true,
|
||||||
|
typeofs: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
"object" == typeof A && "object" == typeof B && (A, B);
|
||||||
|
"object" == typeof A && "object" != typeof B && (A, B);
|
||||||
|
"object" != typeof A && "object" == typeof B && (A, B);
|
||||||
|
"object" != typeof A && "object" != typeof B && (A, B);
|
||||||
|
"object" == typeof A && "object" == typeof B || (A, B);
|
||||||
|
"object" == typeof A && "object" != typeof B || (A, B);
|
||||||
|
"object" != typeof A && "object" == typeof B || (A, B);
|
||||||
|
"object" != typeof A && "object" != typeof B || (A, B);
|
||||||
|
"object" == typeof A || "object" == typeof B && (A, B);
|
||||||
|
"object" == typeof A || "object" != typeof B && (A, B);
|
||||||
|
"object" != typeof A || "object" == typeof B && (A, B);
|
||||||
|
"object" != typeof A || "object" != typeof B && (A, B);
|
||||||
|
"object" == typeof A || "object" == typeof B || (A, B);
|
||||||
|
"object" == typeof A || "object" != typeof B || (A, B);
|
||||||
|
"object" != typeof A || "object" == typeof B || (A, B);
|
||||||
|
"object" != typeof A || "object" != typeof B || (A, B);
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
"object" == typeof A && "object" != typeof B && B;
|
||||||
|
"object" != typeof A && "object" == typeof B && A;
|
||||||
|
"object" != typeof A && "object" != typeof B && (A, B);
|
||||||
|
"object" == typeof A && "object" == typeof B || (A, B);
|
||||||
|
"object" == typeof A && "object" != typeof B || (A, B);
|
||||||
|
"object" != typeof A && "object" == typeof B || (A, B);
|
||||||
|
"object" != typeof A && "object" != typeof B || (A, B);
|
||||||
|
"object" == typeof A || "object" == typeof B && A;
|
||||||
|
"object" == typeof A || "object" != typeof B && (A, B);
|
||||||
|
"object" != typeof A || "object" != typeof B && B;
|
||||||
|
"object" == typeof A || "object" == typeof B || (A, B);
|
||||||
|
"object" == typeof A || "object" != typeof B || A;
|
||||||
|
"object" != typeof A || "object" == typeof B || B;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
emberjs_global: {
|
||||||
|
options = {
|
||||||
|
comparisons: true,
|
||||||
|
conditionals: true,
|
||||||
|
if_return: true,
|
||||||
|
passes: 2,
|
||||||
|
side_effects: true,
|
||||||
|
toplevel: true,
|
||||||
|
typeofs: true,
|
||||||
|
unused: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
var a;
|
||||||
|
if (typeof A === "object") {
|
||||||
|
a = A;
|
||||||
|
} else if (typeof B === "object") {
|
||||||
|
a = B;
|
||||||
|
} else {
|
||||||
|
throw new Error("PASS");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
if ("object" != typeof A && "object" != typeof B)
|
||||||
|
throw new Error("PASS");
|
||||||
|
}
|
||||||
|
expect_stdout: Error("PASS")
|
||||||
|
}
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ exports["parse"] = parse;
|
|||||||
exports["push_uniq"] = push_uniq;
|
exports["push_uniq"] = push_uniq;
|
||||||
exports["reserve_quoted_keys"] = reserve_quoted_keys;
|
exports["reserve_quoted_keys"] = reserve_quoted_keys;
|
||||||
exports["string_template"] = string_template;
|
exports["string_template"] = string_template;
|
||||||
|
exports["to_ascii"] = to_ascii;
|
||||||
exports["tokenizer"] = tokenizer;
|
exports["tokenizer"] = tokenizer;
|
||||||
exports["TreeTransformer"] = TreeTransformer;
|
exports["TreeTransformer"] = TreeTransformer;
|
||||||
exports["TreeWalker"] = TreeWalker;
|
exports["TreeWalker"] = TreeWalker;
|
||||||
|
|||||||
8
test/input/issue-3441/input.js
Normal file
8
test/input/issue-3441/input.js
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
// Generated by CoffeeScript 2.4.1
|
||||||
|
(function() {
|
||||||
|
console.log('hello');
|
||||||
|
|
||||||
|
}).call(this);
|
||||||
|
|
||||||
|
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoibWFpbi5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIm1haW4uY29mZmVlIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7QUFBQTtFQUFBLE9BQU8sQ0FBQyxHQUFSLENBQVksT0FBWjtBQUFBIiwic291cmNlc0NvbnRlbnQiOlsiY29uc29sZS5sb2cgJ2hlbGxvJ1xuIl19
|
||||||
|
//# sourceURL=/Users/mohamed/Downloads/main.coffee
|
||||||
@@ -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");
|
||||||
|
|||||||
@@ -48,53 +48,84 @@ describe("comments", function() {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should handle comment within return correctly", function() {
|
describe("comment within return", function() {
|
||||||
var result = UglifyJS.minify([
|
it("Should handle leading return", function() {
|
||||||
"function unequal(x, y) {",
|
var result = UglifyJS.minify([
|
||||||
" return (",
|
"function unequal(x, y) {",
|
||||||
" // Either one",
|
" return (",
|
||||||
" x < y",
|
" // Either one",
|
||||||
" ||",
|
" x < y",
|
||||||
" y < x",
|
" ||",
|
||||||
" );",
|
" y < x",
|
||||||
"}",
|
" );",
|
||||||
].join("\n"), {
|
"}",
|
||||||
compress: false,
|
].join("\n"), {
|
||||||
mangle: false,
|
compress: false,
|
||||||
output: {
|
mangle: false,
|
||||||
beautify: true,
|
output: {
|
||||||
comments: "all",
|
beautify: true,
|
||||||
},
|
comments: "all",
|
||||||
|
},
|
||||||
|
});
|
||||||
|
if (result.error) throw result.error;
|
||||||
|
assert.strictEqual(result.code, [
|
||||||
|
"function unequal(x, y) {",
|
||||||
|
" // Either one",
|
||||||
|
" return x < y || y < x;",
|
||||||
|
"}",
|
||||||
|
].join("\n"));
|
||||||
});
|
});
|
||||||
if (result.error) throw result.error;
|
|
||||||
assert.strictEqual(result.code, [
|
|
||||||
"function unequal(x, y) {",
|
|
||||||
" // Either one",
|
|
||||||
" return x < y || y < x;",
|
|
||||||
"}",
|
|
||||||
].join("\n"));
|
|
||||||
});
|
|
||||||
|
|
||||||
it("Should handle comment folded into return correctly", function() {
|
it("Should handle trailing return", function() {
|
||||||
var result = UglifyJS.minify([
|
var result = UglifyJS.minify([
|
||||||
"function f() {",
|
"function unequal(x) {",
|
||||||
" /* boo */ x();",
|
" var y;",
|
||||||
" return y();",
|
" return (",
|
||||||
"}",
|
" // Either one",
|
||||||
].join("\n"), {
|
" x < y",
|
||||||
mangle: false,
|
" ||",
|
||||||
output: {
|
" y < x",
|
||||||
beautify: true,
|
" );",
|
||||||
comments: "all",
|
"}",
|
||||||
},
|
].join("\n"), {
|
||||||
|
compress: false,
|
||||||
|
mangle: false,
|
||||||
|
output: {
|
||||||
|
beautify: true,
|
||||||
|
comments: "all",
|
||||||
|
},
|
||||||
|
});
|
||||||
|
if (result.error) throw result.error;
|
||||||
|
assert.strictEqual(result.code, [
|
||||||
|
"function unequal(x) {",
|
||||||
|
" var y;",
|
||||||
|
" // Either one",
|
||||||
|
" return x < y || y < x;",
|
||||||
|
"}",
|
||||||
|
].join("\n"));
|
||||||
|
});
|
||||||
|
|
||||||
|
it("Should handle comment folded into return", function() {
|
||||||
|
var result = UglifyJS.minify([
|
||||||
|
"function f() {",
|
||||||
|
" /* boo */ x();",
|
||||||
|
" return y();",
|
||||||
|
"}",
|
||||||
|
].join("\n"), {
|
||||||
|
mangle: false,
|
||||||
|
output: {
|
||||||
|
beautify: true,
|
||||||
|
comments: "all",
|
||||||
|
},
|
||||||
|
});
|
||||||
|
if (result.error) throw result.error;
|
||||||
|
assert.strictEqual(result.code, [
|
||||||
|
"function f() {",
|
||||||
|
" /* boo */",
|
||||||
|
" return x(), y();",
|
||||||
|
"}",
|
||||||
|
].join("\n"));
|
||||||
});
|
});
|
||||||
if (result.error) throw result.error;
|
|
||||||
assert.strictEqual(result.code, [
|
|
||||||
"function f() {",
|
|
||||||
" /* boo */",
|
|
||||||
" return x(), y();",
|
|
||||||
"}",
|
|
||||||
].join("\n"));
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should not drop comments after first OutputStream", function() {
|
it("Should not drop comments after first OutputStream", function() {
|
||||||
@@ -228,6 +259,30 @@ describe("comments", function() {
|
|||||||
assert.strictEqual(result.code, code);
|
assert.strictEqual(result.code, code);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("Should handle comments around parenthesis correctly", function() {
|
||||||
|
var code = [
|
||||||
|
"a();",
|
||||||
|
"/* foo */",
|
||||||
|
"(b())",
|
||||||
|
"/* bar */",
|
||||||
|
"c();",
|
||||||
|
].join("\n");
|
||||||
|
var result = UglifyJS.minify(code, {
|
||||||
|
compress: false,
|
||||||
|
mangle: false,
|
||||||
|
output: {
|
||||||
|
comments: "all",
|
||||||
|
},
|
||||||
|
});
|
||||||
|
if (result.error) throw result.error;
|
||||||
|
assert.strictEqual(result.code, [
|
||||||
|
"a();",
|
||||||
|
"/* foo */",
|
||||||
|
"b()",
|
||||||
|
"/* bar */;c();",
|
||||||
|
].join("\n"));
|
||||||
|
});
|
||||||
|
|
||||||
it("Should preserve comments around IIFE", function() {
|
it("Should preserve comments around IIFE", function() {
|
||||||
var result = UglifyJS.minify("/*a*/(/*b*/function(){/*c*/}/*d*/)/*e*/();", {
|
var result = UglifyJS.minify("/*a*/(/*b*/function(){/*c*/}/*d*/)/*e*/();", {
|
||||||
compress: false,
|
compress: false,
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
var assert = require("assert");
|
var assert = require("assert");
|
||||||
var readFileSync = require("fs").readFileSync;
|
var readFileSync = require("fs").readFileSync;
|
||||||
var SourceMapConsumer = require("source-map").SourceMapConsumer;
|
var SourceMapConsumer = require("source-map").SourceMapConsumer;
|
||||||
var UglifyJS = require("../..");
|
var UglifyJS = require("../node");
|
||||||
|
|
||||||
function read(path) {
|
function read(path) {
|
||||||
return readFileSync(path, "utf8");
|
return readFileSync(path, "utf8");
|
||||||
@@ -181,6 +181,18 @@ describe("sourcemaps", function() {
|
|||||||
if (result.error) throw result.error;
|
if (result.error) throw result.error;
|
||||||
assert.strictEqual(result.code + "\n", readFileSync("test/input/issue-3294/output.js", "utf8"));
|
assert.strictEqual(result.code + "\n", readFileSync("test/input/issue-3294/output.js", "utf8"));
|
||||||
});
|
});
|
||||||
|
it("Should work in presence of unrecognised annotations", function() {
|
||||||
|
var result = UglifyJS.minify(read("./test/input/issue-3441/input.js"), {
|
||||||
|
compress: false,
|
||||||
|
mangle: false,
|
||||||
|
sourceMap: {
|
||||||
|
content: "inline",
|
||||||
|
},
|
||||||
|
});
|
||||||
|
if (result.error) throw result.error;
|
||||||
|
assert.strictEqual(result.code, '(function(){console.log("hello")}).call(this);');
|
||||||
|
assert.strictEqual(result.map, '{"version":3,"sources":["main.coffee"],"names":["console","log"],"mappings":"CAAA,WAAAA,QAAQC,IAAI"}');
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("sourceMapInline", function() {
|
describe("sourceMapInline", function() {
|
||||||
@@ -232,7 +244,7 @@ describe("sourcemaps", function() {
|
|||||||
assert.strictEqual(map.sourcesContent.length, 1);
|
assert.strictEqual(map.sourcesContent.length, 1);
|
||||||
assert.strictEqual(map.sourcesContent[0], code);
|
assert.strictEqual(map.sourcesContent[0], code);
|
||||||
var encoded = result.code.slice(result.code.lastIndexOf(",") + 1);
|
var encoded = result.code.slice(result.code.lastIndexOf(",") + 1);
|
||||||
map = JSON.parse(new Buffer(encoded, "base64").toString());
|
map = JSON.parse(UglifyJS.to_ascii(encoded));
|
||||||
assert.strictEqual(map.sourcesContent.length, 1);
|
assert.strictEqual(map.sourcesContent.length, 1);
|
||||||
assert.strictEqual(map.sourcesContent[0], code);
|
assert.strictEqual(map.sourcesContent[0], code);
|
||||||
result = UglifyJS.minify(result.code, {
|
result = UglifyJS.minify(result.code, {
|
||||||
|
|||||||
@@ -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);
|
||||||
|
|||||||
@@ -1,3 +1,6 @@
|
|||||||
|
setInterval(function() {
|
||||||
|
process.stderr.write("\0");
|
||||||
|
}, 8 * 60 * 1000).unref();
|
||||||
require("./run")([
|
require("./run")([
|
||||||
"-b",
|
"-b",
|
||||||
"-b braces",
|
"-b braces",
|
||||||
|
|||||||
@@ -1,81 +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;
|
|
||||||
var ping = 5 * 60 * 1000;
|
|
||||||
if (process.argv[2] == "run") {
|
|
||||||
var endTime = Date.now() + period;
|
|
||||||
for (var i = 0; i < 2; i++) spawn(endTime);
|
|
||||||
} else 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] || "node/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: "NODEJS_VER=" + platform,
|
|
||||||
script: "node test/travis-ufuzz run"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}));
|
|
||||||
})();
|
|
||||||
} else {
|
|
||||||
console.log("Usage: test/travis-ufuzz.js <token> [branch] [repository] [concurrency] [platform]");
|
|
||||||
}
|
|
||||||
|
|
||||||
function spawn(endTime) {
|
|
||||||
var child = child_process.spawn("node", [
|
|
||||||
"--max-old-space-size=2048",
|
|
||||||
"test/ufuzz"
|
|
||||||
], {
|
|
||||||
stdio: [ "ignore", "pipe", "pipe" ]
|
|
||||||
}).on("exit", respawn);
|
|
||||||
var line = "";
|
|
||||||
child.stdout.on("data", function(data) {
|
|
||||||
line += data;
|
|
||||||
});
|
|
||||||
child.stderr.on("data", function() {
|
|
||||||
process.exitCode = 1;
|
|
||||||
}).pipe(process.stdout);
|
|
||||||
var keepAlive = setInterval(function() {
|
|
||||||
var end = line.lastIndexOf("\r");
|
|
||||||
console.log(line.slice(line.lastIndexOf("\r", end - 1) + 1, end));
|
|
||||||
line = line.slice(end + 1);
|
|
||||||
}, ping);
|
|
||||||
var timer = setTimeout(function() {
|
|
||||||
clearInterval(keepAlive);
|
|
||||||
child.removeListener("exit", respawn);
|
|
||||||
child.kill();
|
|
||||||
}, endTime - Date.now());
|
|
||||||
|
|
||||||
function respawn() {
|
|
||||||
console.log(line);
|
|
||||||
clearInterval(keepAlive);
|
|
||||||
clearTimeout(timer);
|
|
||||||
spawn(endTime);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
File diff suppressed because it is too large
Load Diff
39
test/ufuzz/job.js
Normal file
39
test/ufuzz/job.js
Normal file
@@ -0,0 +1,39 @@
|
|||||||
|
var child_process = require("child_process");
|
||||||
|
|
||||||
|
var ping = 5 * 60 * 1000;
|
||||||
|
var period = +process.argv[2];
|
||||||
|
var endTime = Date.now() + period;
|
||||||
|
for (var i = 0; i < 2; i++) spawn(endTime);
|
||||||
|
|
||||||
|
function spawn(endTime) {
|
||||||
|
var child = child_process.spawn("node", [
|
||||||
|
"--max-old-space-size=2048",
|
||||||
|
"test/ufuzz"
|
||||||
|
], {
|
||||||
|
stdio: [ "ignore", "pipe", "pipe" ]
|
||||||
|
}).on("exit", respawn);
|
||||||
|
var line = "";
|
||||||
|
child.stdout.on("data", function(data) {
|
||||||
|
line += data;
|
||||||
|
});
|
||||||
|
child.stderr.once("data", function() {
|
||||||
|
process.exitCode = 1;
|
||||||
|
}).pipe(process.stdout);
|
||||||
|
var keepAlive = setInterval(function() {
|
||||||
|
var end = line.lastIndexOf("\r");
|
||||||
|
console.log(line.slice(line.lastIndexOf("\r", end - 1) + 1, end));
|
||||||
|
line = line.slice(end + 1);
|
||||||
|
}, ping);
|
||||||
|
var timer = setTimeout(function() {
|
||||||
|
clearInterval(keepAlive);
|
||||||
|
child.removeListener("exit", respawn);
|
||||||
|
child.kill();
|
||||||
|
}, endTime - Date.now());
|
||||||
|
|
||||||
|
function respawn() {
|
||||||
|
console.log(line);
|
||||||
|
clearInterval(keepAlive);
|
||||||
|
clearTimeout(timer);
|
||||||
|
spawn(endTime);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -2702,8 +2702,10 @@
|
|||||||
"attrChange",
|
"attrChange",
|
||||||
"attrName",
|
"attrName",
|
||||||
"attributeChangedCallback",
|
"attributeChangedCallback",
|
||||||
|
"attributeFilter",
|
||||||
"attributeName",
|
"attributeName",
|
||||||
"attributeNamespace",
|
"attributeNamespace",
|
||||||
|
"attributeOldValue",
|
||||||
"attributeStyleMap",
|
"attributeStyleMap",
|
||||||
"attributes",
|
"attributes",
|
||||||
"audioTracks",
|
"audioTracks",
|
||||||
@@ -3025,6 +3027,8 @@
|
|||||||
"charCode",
|
"charCode",
|
||||||
"charCodeAt",
|
"charCodeAt",
|
||||||
"charIndex",
|
"charIndex",
|
||||||
|
"characterData",
|
||||||
|
"characterDataOldValue",
|
||||||
"characterSet",
|
"characterSet",
|
||||||
"charging",
|
"charging",
|
||||||
"chargingTime",
|
"chargingTime",
|
||||||
@@ -3036,6 +3040,7 @@
|
|||||||
"checkValidity",
|
"checkValidity",
|
||||||
"checked",
|
"checked",
|
||||||
"childElementCount",
|
"childElementCount",
|
||||||
|
"childList",
|
||||||
"childNodes",
|
"childNodes",
|
||||||
"children",
|
"children",
|
||||||
"chrome",
|
"chrome",
|
||||||
@@ -6150,6 +6155,7 @@
|
|||||||
"substring",
|
"substring",
|
||||||
"substringData",
|
"substringData",
|
||||||
"subtle",
|
"subtle",
|
||||||
|
"subtree",
|
||||||
"suffix",
|
"suffix",
|
||||||
"suffixes",
|
"suffixes",
|
||||||
"summary",
|
"summary",
|
||||||
|
|||||||
@@ -46,7 +46,9 @@ function describe_ast() {
|
|||||||
if (ctor.SUBCLASSES.length > 0) {
|
if (ctor.SUBCLASSES.length > 0) {
|
||||||
out.space();
|
out.space();
|
||||||
out.with_block(function() {
|
out.with_block(function() {
|
||||||
ctor.SUBCLASSES.forEach(function(ctor, i) {
|
ctor.SUBCLASSES.sort(function(a, b) {
|
||||||
|
return a.TYPE < b.TYPE ? -1 : 1;
|
||||||
|
}).forEach(function(ctor, i) {
|
||||||
out.indent();
|
out.indent();
|
||||||
doitem(ctor);
|
doitem(ctor);
|
||||||
out.newline();
|
out.newline();
|
||||||
|
|||||||
Reference in New Issue
Block a user