Compare commits
186 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
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 | ||
|
|
a82003d6ac | ||
|
|
da9f1622fc | ||
|
|
8a4c7077bb | ||
|
|
0a63f2f2b0 | ||
|
|
931ac66638 | ||
|
|
35338a100f | ||
|
|
d57b606e73 | ||
|
|
00ada04111 | ||
|
|
a31c477fea | ||
|
|
bde7418ce1 | ||
|
|
70bb304a0a | ||
|
|
9d3b1efd86 | ||
|
|
482e1baea3 | ||
|
|
e4f5ba1d29 | ||
|
|
b9053c7a25 | ||
|
|
d357a7aabc | ||
|
|
ae77ebe5a5 | ||
|
|
04439edcec | ||
|
|
a246195412 | ||
|
|
8939a36bc7 | ||
|
|
a21c348d93 | ||
|
|
1f0def10eb | ||
|
|
f87caac9d8 | ||
|
|
d538a73250 | ||
|
|
2e4fbdeb08 | ||
|
|
3bc7cc82bb | ||
|
|
45fbdbc2dc | ||
|
|
54cb678055 | ||
|
|
e88c439eac | ||
|
|
9fc8cd4076 | ||
|
|
5476cb8f05 | ||
|
|
6a30e1d6be | ||
|
|
e4881245d9 | ||
|
|
354fec8a9c | ||
|
|
11cdab745d | ||
|
|
a89d424a0b | ||
|
|
429d2b56b7 | ||
|
|
2ea96549c5 | ||
|
|
fba008e298 | ||
|
|
c37a8e927e | ||
|
|
413bbe0480 | ||
|
|
34075fc4c4 | ||
|
|
e5436ca566 | ||
|
|
cfde686eab | ||
|
|
a206964c0a | ||
|
|
c56d89f804 | ||
|
|
c215706350 | ||
|
|
d3b93ec682 | ||
|
|
6fe20dbe33 | ||
|
|
7ccdf3337b | ||
|
|
dafed54764 | ||
|
|
a84beafd1b | ||
|
|
f01cc1e413 | ||
|
|
338dd144b8 | ||
|
|
c719552317 | ||
|
|
855964a87a | ||
|
|
a438e2fca9 | ||
|
|
00833e893a | ||
|
|
f1a77e4fc0 | ||
|
|
b55a2fd531 | ||
|
|
e8a2c0b5bf | ||
|
|
21cd7e3f57 | ||
|
|
5172ba5f2a | ||
|
|
a57b069409 | ||
|
|
4454656c3b | ||
|
|
fa43768ce0 | ||
|
|
a74e600fa0 | ||
|
|
4b21526310 | ||
|
|
a7a7b1daed | ||
|
|
7436977aa5 | ||
|
|
e3c565b46f | ||
|
|
54b0b49b68 | ||
|
|
65648d84a5 | ||
|
|
fd788590f6 | ||
|
|
143f9054da | ||
|
|
f2286c33f1 | ||
|
|
b9615f7a62 | ||
|
|
c520e99eda | ||
|
|
615ae37ca3 | ||
|
|
7aa7f21872 | ||
|
|
4430a436eb | ||
|
|
9707ccdc9f | ||
|
|
cb8f3a2a31 | ||
|
|
8b3259e0c2 | ||
|
|
b66f47b8dd | ||
|
|
8d2e6f333e | ||
|
|
b3ef5e514d | ||
|
|
627f5fb41e | ||
|
|
d90777b724 | ||
|
|
e49297e5eb | ||
|
|
ebd82b3fb6 | ||
|
|
d074aa6e27 | ||
|
|
b052f62710 | ||
|
|
d4ac84b255 | ||
|
|
e250396d7e | ||
|
|
c6fa39b482 | ||
|
|
9aae4f2424 | ||
|
|
008c236137 | ||
|
|
b1c0664066 | ||
|
|
ea999b0e92 | ||
|
|
ce7e220de4 | ||
|
|
2bdaca10ae | ||
|
|
aa0029204e | ||
|
|
f352bcec3a | ||
|
|
08514030f4 | ||
|
|
694ca5d045 | ||
|
|
57fb58b263 | ||
|
|
18c1c9b38a | ||
|
|
5c1ae3662d | ||
|
|
cfebeb2f63 | ||
|
|
fc78423f1d | ||
|
|
2a5277b391 | ||
|
|
d47547dc71 | ||
|
|
304db15a20 | ||
|
|
7cf72b8d66 | ||
|
|
cea685f8d9 | ||
|
|
8d4b5344f4 | ||
|
|
34a0ab6f2c | ||
|
|
bcebacbb9e | ||
|
|
018a5a750a | ||
|
|
b468103f26 | ||
|
|
66c126ffde |
27
.github/workflows/ci.yml
vendored
Normal file
27
.github/workflows/ci.yml
vendored
Normal file
@@ -0,0 +1,27 @@
|
||||
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
|
||||
- shell: bash
|
||||
run: |
|
||||
git clone --branch v1.5.2 --depth 1 https://github.com/jasongin/nvs.git ~/.nvs
|
||||
. ~/.nvs/nvs.sh
|
||||
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
|
||||
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
|
||||
- shell: bash
|
||||
run: |
|
||||
git clone --branch v1.5.2 --depth 1 https://github.com/jasongin/nvs.git ~/.nvs
|
||||
. ~/.nvs/nvs.sh
|
||||
nvs --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
|
||||
56
.travis.yml
56
.travis.yml
@@ -1,14 +1,46 @@
|
||||
language: node_js
|
||||
node_js:
|
||||
- "0.10"
|
||||
- "0.12"
|
||||
- "4"
|
||||
- "6"
|
||||
- "8"
|
||||
env:
|
||||
- UGLIFYJS_TEST_ALL=1
|
||||
matrix:
|
||||
fast_finish: true
|
||||
sudo: false
|
||||
cache:
|
||||
directories: tmp
|
||||
language: shell
|
||||
matrix:
|
||||
fast_finish: true
|
||||
env:
|
||||
- NODE=0.10 TYPE=compress
|
||||
- NODE=0.10 TYPE=mocha
|
||||
- NODE=0.10 TYPE=release/benchmark
|
||||
- NODE=0.10 TYPE=release/jetstream
|
||||
- NODE=0.12 TYPE=compress
|
||||
- NODE=0.12 TYPE=mocha
|
||||
- NODE=0.12 TYPE=release/benchmark
|
||||
- NODE=0.12 TYPE=release/jetstream
|
||||
- NODE=4 TYPE=compress
|
||||
- NODE=4 TYPE=mocha
|
||||
- NODE=4 TYPE=release/benchmark
|
||||
- NODE=4 TYPE=release/jetstream
|
||||
- NODE=6 TYPE=compress
|
||||
- NODE=6 TYPE=mocha
|
||||
- NODE=6 TYPE=release/benchmark
|
||||
- NODE=6 TYPE=release/jetstream
|
||||
- NODE=8 TYPE=compress
|
||||
- NODE=8 TYPE=mocha
|
||||
- NODE=8 TYPE=release/benchmark
|
||||
- NODE=8 TYPE=release/jetstream
|
||||
- NODE=10 TYPE=compress
|
||||
- NODE=10 TYPE=mocha
|
||||
- NODE=10 TYPE=release/benchmark
|
||||
- NODE=10 TYPE=release/jetstream
|
||||
- NODE=latest TYPE=compress
|
||||
- NODE=latest TYPE=mocha
|
||||
- NODE=latest TYPE=release/benchmark
|
||||
- NODE=latest TYPE=release/jetstream
|
||||
before_install:
|
||||
- git clone --branch v1.5.2 --depth 1 https://github.com/jasongin/nvs.git ~/.nvs
|
||||
- . ~/.nvs/nvs.sh
|
||||
- nvs --version
|
||||
install:
|
||||
- nvs add node/$NODE
|
||||
- nvs use node/$NODE
|
||||
- node --version
|
||||
- npm --version --no-update-notifier
|
||||
- npm install --no-audit --no-optional --no-save --no-update-notifier
|
||||
script:
|
||||
- node test/$TYPE
|
||||
|
||||
2
LICENSE
2
LICENSE
@@ -1,6 +1,6 @@
|
||||
UglifyJS is released under the BSD license:
|
||||
|
||||
Copyright 2012-2018 (c) Mihai Bazon <mihai.bazon@gmail.com>
|
||||
Copyright 2012-2019 (c) Mihai Bazon <mihai.bazon@gmail.com>
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions
|
||||
|
||||
61
README.md
61
README.md
@@ -478,42 +478,42 @@ if (result.error) throw result.error;
|
||||
|
||||
## 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.
|
||||
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
|
||||
an object to specify [mangle options](#mangle-options) (see below).
|
||||
|
||||
- `mangle.properties` (default `false`) — a subcategory of the mangle option.
|
||||
Pass an object to specify custom [mangle property options](#mangle-properties-options).
|
||||
|
||||
- `output` (default `null`) — pass an object if you wish to specify
|
||||
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
|
||||
- `nameCache` (default `null`) -- pass an empty object `{}` or a previously
|
||||
used `nameCache` object if you wish to cache mangled variable and
|
||||
property names across multiple invocations of `minify()`. Note: this is
|
||||
a read/write property. `minify()` will read the name cache state of this
|
||||
object and update it during minification so that it may be
|
||||
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
|
||||
of function names. Useful for code relying on `Function.prototype.name`.
|
||||
- `parse` (default `{}`) — pass an object if you wish to specify some
|
||||
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
|
||||
|
||||
@@ -605,6 +605,8 @@ If you're using the `X-SourceMap` header instead, you can just omit `sourceMap.u
|
||||
- `arguments` (default: `true`) -- replace `arguments[index]` with function
|
||||
parameter name whenever possible.
|
||||
|
||||
- `assignments` (default: `true`) -- apply optimizations to assignment expressions.
|
||||
|
||||
- `booleans` (default: `true`) -- various optimizations for boolean context,
|
||||
for example `!!a ? b : c → a ? b : c`
|
||||
|
||||
@@ -634,6 +636,9 @@ If you're using the `X-SourceMap` header instead, you can just omit `sourceMap.u
|
||||
- `expression` (default: `false`) -- Pass `true` to preserve completion values
|
||||
from terminal statements without `return`, e.g. in bookmarklets.
|
||||
|
||||
- `functions` (default: `true`) -- convert declarations from `var`to `function`
|
||||
whenever possible.
|
||||
|
||||
- `global_defs` (default: `{}`) -- see [conditional compilation](#conditional-compilation)
|
||||
|
||||
- `hoist_funs` (default: `false`) -- hoist function declarations
|
||||
@@ -659,12 +664,13 @@ If you're using the `X-SourceMap` header instead, you can just omit `sourceMap.u
|
||||
|
||||
- `join_vars` (default: `true`) -- join consecutive `var` statements
|
||||
|
||||
- `keep_fargs` (default: `true`) -- Prevents the compressor from discarding unused
|
||||
function arguments. You need this for code which relies on `Function.length`.
|
||||
- `keep_fargs` (default: `strict`) -- Discard unused function arguments. Code
|
||||
which relies on `Function.length` will break if this is done indiscriminately,
|
||||
i.e. when passing `true`. Pass `false` to always retain function arguments.
|
||||
|
||||
- `keep_fnames` (default: `false`) -- Pass `true` to prevent the
|
||||
compressor from discarding function names. Useful for code relying on
|
||||
`Function.prototype.name`. See also: the `keep_fnames` [mangle option](#mangle).
|
||||
`Function.prototype.name`. See also: the `keep_fnames` [mangle option](#mangle-options).
|
||||
|
||||
- `keep_infinity` (default: `false`) -- Pass `true` to prevent `Infinity` from
|
||||
being compressed into `1/0`, which may cause performance issues on Chrome.
|
||||
@@ -676,6 +682,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
|
||||
code generator would insert.
|
||||
|
||||
- `objects` (default: `true`) -- compact duplicate keys in object literals.
|
||||
|
||||
- `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
|
||||
mind more passes will take more time.
|
||||
@@ -762,9 +770,6 @@ If you're using the `X-SourceMap` header instead, you can just omit `sourceMap.u
|
||||
- `unused` (default: `true`) -- drop unreferenced functions and variables (simple
|
||||
direct variable assignments do not count as references unless set to `"keep_assign"`)
|
||||
|
||||
- `warnings` (default: `false`) -- display warnings when dropping unreachable
|
||||
code or unused declarations etc.
|
||||
|
||||
## Mangle options
|
||||
|
||||
- `eval` (default `false`) -- Pass `true` to mangle names visible in scopes
|
||||
@@ -857,8 +862,8 @@ can pass additional arguments that control the code output:
|
||||
adjust for this text. Can be used to insert a comment containing
|
||||
licensing information, for example.
|
||||
|
||||
- `preserve_line` (default `false`) -- pass `true` to preserve lines, but it
|
||||
only works if `beautify` is set to `false`.
|
||||
- `preserve_line` (default `false`) -- pass `true` to retain line numbering on
|
||||
a best effort basis.
|
||||
|
||||
- `quote_keys` (default `false`) -- pass `true` to quote all keys in literal
|
||||
objects
|
||||
|
||||
82
appveyor.yml
82
appveyor.yml
@@ -1,20 +1,74 @@
|
||||
environment:
|
||||
matrix:
|
||||
- nodejs_version: "0.10"
|
||||
- nodejs_version: "0.12"
|
||||
- nodejs_version: "4"
|
||||
- nodejs_version: "6"
|
||||
- nodejs_version: "8"
|
||||
install:
|
||||
- ps: Install-Product node $env:nodejs_version
|
||||
- set UGLIFYJS_TEST_ALL=1
|
||||
- npm install
|
||||
build: off
|
||||
cache:
|
||||
- tmp
|
||||
matrix:
|
||||
fast_finish: true
|
||||
test_script:
|
||||
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
|
||||
- npm test
|
||||
- npm --version --no-update-notifier
|
||||
- npm install --no-audit --no-optional --no-save --no-update-notifier
|
||||
test_script:
|
||||
- node test/%TYPE%
|
||||
|
||||
92
bin/uglifyjs
92
bin/uglifyjs
@@ -56,9 +56,14 @@ program.option("--wrap <name>", "Embed everything as a function with “exports
|
||||
program.arguments("[files...]").parseArgv(process.argv);
|
||||
if (program.configFile) {
|
||||
options = JSON.parse(read_file(program.configFile));
|
||||
if (options.mangle && options.mangle.properties && options.mangle.properties.regex) {
|
||||
options.mangle.properties.regex = UglifyJS.parse(options.mangle.properties.regex, {
|
||||
expression: true
|
||||
}).getValue();
|
||||
}
|
||||
}
|
||||
if (!program.output && program.sourceMap && program.sourceMap.url != "inline") {
|
||||
fatal("ERROR: cannot write source map to STDOUT");
|
||||
fatal("cannot write source map to STDOUT");
|
||||
}
|
||||
[
|
||||
"compress",
|
||||
@@ -73,6 +78,15 @@ if (!program.output && program.sourceMap && program.sourceMap.url != "inline") {
|
||||
options[name] = program[name];
|
||||
}
|
||||
});
|
||||
if (program.verbose) {
|
||||
options.warnings = "verbose";
|
||||
} else if (program.warn) {
|
||||
options.warnings = true;
|
||||
}
|
||||
if (options.warnings) {
|
||||
UglifyJS.AST_Node.log_function(print_error, options.warnings == "verbose");
|
||||
delete options.warnings;
|
||||
}
|
||||
if (program.beautify) {
|
||||
options.output = typeof program.beautify == "object" ? program.beautify : {};
|
||||
if (!("beautify" in options.output)) {
|
||||
@@ -100,7 +114,7 @@ if (program.mangleProps) {
|
||||
if (typeof program.mangleProps != "object") program.mangleProps = {};
|
||||
if (!Array.isArray(program.mangleProps.reserved)) program.mangleProps.reserved = [];
|
||||
require("../tools/domprops").forEach(function(name) {
|
||||
UglifyJS._push_uniq(program.mangleProps.reserved, name);
|
||||
UglifyJS.push_uniq(program.mangleProps.reserved, name);
|
||||
});
|
||||
}
|
||||
if (typeof options.mangle != "object") options.mangle = {};
|
||||
@@ -119,7 +133,7 @@ if (program.parse) {
|
||||
if (!program.parse.acorn && !program.parse.spidermonkey) {
|
||||
options.parse = program.parse;
|
||||
} else if (program.sourceMap && program.sourceMap.content == "inline") {
|
||||
fatal("ERROR: inline source map only works with built-in parser");
|
||||
fatal("inline source map only works with built-in parser");
|
||||
}
|
||||
}
|
||||
if (~program.rawArgs.indexOf("--rename")) {
|
||||
@@ -139,15 +153,8 @@ if (typeof program.sourceMap == "object" && "base" in program.sourceMap) {
|
||||
};
|
||||
}();
|
||||
}
|
||||
if (program.verbose) {
|
||||
options.warnings = "verbose";
|
||||
} else if (program.warn) {
|
||||
options.warnings = true;
|
||||
}
|
||||
if (program.self) {
|
||||
if (program.args.length) {
|
||||
print_error("WARN: Ignoring input files since --self was passed");
|
||||
}
|
||||
if (program.args.length) UglifyJS.AST_Node.warn("Ignoring input files since --self was passed");
|
||||
if (!options.wrap) options.wrap = "UglifyJS";
|
||||
simple_glob(UglifyJS.FILES).forEach(function(name) {
|
||||
files[convert_path(name)] = read_file(name);
|
||||
@@ -175,12 +182,9 @@ function convert_ast(fn) {
|
||||
}
|
||||
|
||||
function run() {
|
||||
UglifyJS.AST_Node.warn_function = function(msg) {
|
||||
print_error("WARN: " + msg);
|
||||
};
|
||||
var content = program.sourceMap && program.sourceMap.content;
|
||||
if (content && content != "inline") {
|
||||
print_error("INFO: Using input source map: " + content);
|
||||
UglifyJS.AST_Node.info("Using input source map: " + content);
|
||||
options.sourceMap.content = read_file(content, content);
|
||||
}
|
||||
if (program.timings) options.timings = true;
|
||||
@@ -211,24 +215,26 @@ function run() {
|
||||
var ex = result.error;
|
||||
if (ex.name == "SyntaxError") {
|
||||
print_error("Parse error at " + ex.filename + ":" + ex.line + "," + ex.col);
|
||||
var col = ex.col;
|
||||
var lines = files[ex.filename].split(/\r?\n/);
|
||||
var line = lines[ex.line - 1];
|
||||
if (!line && !col) {
|
||||
line = lines[ex.line - 2];
|
||||
col = line.length;
|
||||
}
|
||||
if (line) {
|
||||
var limit = 70;
|
||||
if (col > limit) {
|
||||
line = line.slice(col - limit);
|
||||
col = limit;
|
||||
var file = files[ex.filename];
|
||||
if (file) {
|
||||
var col = ex.col;
|
||||
var lines = file.split(/\r?\n/);
|
||||
var line = lines[ex.line - 1];
|
||||
if (!line && !col) {
|
||||
line = lines[ex.line - 2];
|
||||
col = line.length;
|
||||
}
|
||||
if (line) {
|
||||
var limit = 70;
|
||||
if (col > limit) {
|
||||
line = line.slice(col - limit);
|
||||
col = limit;
|
||||
}
|
||||
print_error(line.slice(0, 80));
|
||||
print_error(line.slice(0, col).replace(/\S/g, " ") + "^");
|
||||
}
|
||||
print_error(line.slice(0, 80));
|
||||
print_error(line.slice(0, col).replace(/\S/g, " ") + "^");
|
||||
}
|
||||
}
|
||||
if (ex.defs) {
|
||||
} else if (ex.defs) {
|
||||
print_error("Supported options:");
|
||||
print_error(format_object(ex.defs));
|
||||
}
|
||||
@@ -288,7 +294,11 @@ function run() {
|
||||
}
|
||||
|
||||
function fatal(message) {
|
||||
if (message instanceof Error) message = message.stack.replace(/^\S*?Error:/, "ERROR:")
|
||||
if (message instanceof Error) {
|
||||
message = message.stack.replace(/^\S*?Error:/, "ERROR:")
|
||||
} else {
|
||||
message = "ERROR: " + message;
|
||||
}
|
||||
print_error(message);
|
||||
process.exit(1);
|
||||
}
|
||||
@@ -337,17 +347,9 @@ function parse_js(flag) {
|
||||
return function(value, options) {
|
||||
options = options || {};
|
||||
try {
|
||||
UglifyJS.minify(value, {
|
||||
parse: {
|
||||
expression: true
|
||||
},
|
||||
compress: false,
|
||||
mangle: false,
|
||||
output: {
|
||||
ast: true,
|
||||
code: false
|
||||
}
|
||||
}).ast.walk(new UglifyJS.TreeWalker(function(node) {
|
||||
UglifyJS.parse(value, {
|
||||
expression: true
|
||||
}).walk(new UglifyJS.TreeWalker(function(node) {
|
||||
if (node instanceof UglifyJS.AST_Assign) {
|
||||
var name = node.left.print_to_string();
|
||||
var value = node.right;
|
||||
@@ -373,9 +375,9 @@ function parse_js(flag) {
|
||||
});
|
||||
}
|
||||
}));
|
||||
} catch(ex) {
|
||||
} catch (ex) {
|
||||
if (flag) {
|
||||
fatal("Error parsing arguments for '" + flag + "': " + value);
|
||||
fatal("cannot parse arguments for '" + flag + "': " + value);
|
||||
} else {
|
||||
options[value] = null;
|
||||
}
|
||||
|
||||
78
lib/ast.js
78
lib/ast.js
@@ -118,11 +118,25 @@ var AST_Node = DEFNODE("Node", "start end", {
|
||||
}
|
||||
}, null);
|
||||
|
||||
AST_Node.warn_function = null;
|
||||
AST_Node.warn = function(txt, props) {
|
||||
if (AST_Node.warn_function)
|
||||
AST_Node.warn_function(string_template(txt, props));
|
||||
};
|
||||
(AST_Node.log_function = function(fn, verbose) {
|
||||
var printed = Object.create(null);
|
||||
if (fn) {
|
||||
AST_Node.info = verbose ? function(text, props) {
|
||||
log("INFO: " + string_template(text, props));
|
||||
} : noop;
|
||||
AST_Node.warn = function(text, props) {
|
||||
log("WARN: " + string_template(text, props));
|
||||
};
|
||||
} else {
|
||||
AST_Node.info = AST_Node.warn = noop;
|
||||
}
|
||||
|
||||
function log(msg) {
|
||||
if (printed[msg]) return;
|
||||
printed[msg] = true;
|
||||
fn(msg);
|
||||
}
|
||||
})();
|
||||
|
||||
/* -----[ statements ]----- */
|
||||
|
||||
@@ -207,8 +221,7 @@ var AST_LabeledStatement = DEFNODE("LabeledStatement", "label", {
|
||||
var label = node.label;
|
||||
var def = this.label;
|
||||
node.walk(new TreeWalker(function(node) {
|
||||
if (node instanceof AST_LoopControl
|
||||
&& node.label && node.label.thedef === def) {
|
||||
if (node instanceof AST_LoopControl && node.label && node.label.thedef === def) {
|
||||
node.label.thedef = label;
|
||||
label.references.push(node);
|
||||
}
|
||||
@@ -324,18 +337,25 @@ var AST_Toplevel = DEFNODE("Toplevel", "globals", {
|
||||
$propdoc: {
|
||||
globals: "[Object/S] a map of name -> SymbolDef for all undeclared names",
|
||||
},
|
||||
wrap_commonjs: function(name) {
|
||||
wrap: function(name) {
|
||||
var body = this.body;
|
||||
var wrapped_tl = "(function(exports){'$ORIG';})(typeof " + name + "=='undefined'?(" + name + "={}):" + name + ");";
|
||||
wrapped_tl = parse(wrapped_tl);
|
||||
wrapped_tl = wrapped_tl.transform(new TreeTransformer(function(node) {
|
||||
return parse([
|
||||
"(function(exports){'$ORIG';})(typeof ",
|
||||
name,
|
||||
"=='undefined'?(",
|
||||
name,
|
||||
"={}):",
|
||||
name,
|
||||
");"
|
||||
].join(""), {
|
||||
filename: "wrap=" + JSON.stringify(name)
|
||||
}).transform(new TreeTransformer(function(node) {
|
||||
if (node instanceof AST_Directive && node.value == "$ORIG") {
|
||||
return MAP.splice(body);
|
||||
}
|
||||
}));
|
||||
return wrapped_tl;
|
||||
},
|
||||
wrap_enclose: function(args_values) {
|
||||
enclose: function(args_values) {
|
||||
if (typeof args_values != "string") args_values = "";
|
||||
var index = args_values.indexOf(":");
|
||||
if (index < 0) index = args_values.length;
|
||||
@@ -346,7 +366,9 @@ var AST_Toplevel = DEFNODE("Toplevel", "globals", {
|
||||
'){"$ORIG"})(',
|
||||
args_values.slice(index + 1),
|
||||
")"
|
||||
].join("")).transform(new TreeTransformer(function(node) {
|
||||
].join(""), {
|
||||
filename: "enclose=" + JSON.stringify(args_values)
|
||||
}).transform(new TreeTransformer(function(node) {
|
||||
if (node instanceof AST_Directive && node.value == "$ORIG") {
|
||||
return MAP.splice(body);
|
||||
}
|
||||
@@ -354,7 +376,7 @@ var AST_Toplevel = DEFNODE("Toplevel", "globals", {
|
||||
}
|
||||
}, AST_Scope);
|
||||
|
||||
var AST_Lambda = DEFNODE("Lambda", "name argnames uses_arguments", {
|
||||
var AST_Lambda = DEFNODE("Lambda", "name argnames uses_arguments length_read", {
|
||||
$documentation: "Base class for functions",
|
||||
$propdoc: {
|
||||
name: "[AST_SymbolDeclaration?] the name of this function",
|
||||
@@ -592,6 +614,18 @@ var AST_PropAccess = DEFNODE("PropAccess", "expression property", {
|
||||
$propdoc: {
|
||||
expression: "[AST_Node] the “container” expression",
|
||||
property: "[AST_Node|string] the property to access. For AST_Dot this is always a plain string, while for AST_Sub it's an arbitrary AST_Node"
|
||||
},
|
||||
getProperty: function() {
|
||||
var p = this.property;
|
||||
if (p instanceof AST_Constant) {
|
||||
return p.getValue();
|
||||
}
|
||||
if (p instanceof AST_UnaryPrefix
|
||||
&& p.operator == "void"
|
||||
&& p.expression instanceof AST_Constant) {
|
||||
return;
|
||||
}
|
||||
return p;
|
||||
}
|
||||
});
|
||||
|
||||
@@ -776,7 +810,7 @@ var AST_Label = DEFNODE("Label", "references", {
|
||||
}
|
||||
}, AST_Symbol);
|
||||
|
||||
var AST_SymbolRef = DEFNODE("SymbolRef", null, {
|
||||
var AST_SymbolRef = DEFNODE("SymbolRef", "fixed", {
|
||||
$documentation: "Reference to some symbol (not definition/declaration)",
|
||||
}, AST_Symbol);
|
||||
|
||||
@@ -803,11 +837,10 @@ var AST_String = DEFNODE("String", "value quote", {
|
||||
}
|
||||
}, AST_Constant);
|
||||
|
||||
var AST_Number = DEFNODE("Number", "value literal", {
|
||||
var AST_Number = DEFNODE("Number", "value", {
|
||||
$documentation: "A number literal",
|
||||
$propdoc: {
|
||||
value: "[number] the numeric value",
|
||||
literal: "[string] numeric value as string (optional)"
|
||||
}
|
||||
}, AST_Constant);
|
||||
|
||||
@@ -946,6 +979,15 @@ TreeWalker.prototype = {
|
||||
|| p instanceof AST_Conditional
|
||||
|| p.tail_node() === self) {
|
||||
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 {
|
||||
return false;
|
||||
}
|
||||
|
||||
2445
lib/compress.js
2445
lib/compress.js
File diff suppressed because it is too large
Load Diff
@@ -1,19 +1,39 @@
|
||||
"use strict";
|
||||
|
||||
var to_ascii = typeof atob == "undefined" ? function(b64) {
|
||||
return new Buffer(b64, "base64").toString();
|
||||
} : atob;
|
||||
var to_base64 = typeof btoa == "undefined" ? function(str) {
|
||||
return new Buffer(str).toString("base64");
|
||||
} : btoa;
|
||||
var to_ascii, to_base64;
|
||||
if (typeof Buffer == "undefined") {
|
||||
to_ascii = atob;
|
||||
to_base64 = btoa;
|
||||
} else if (typeof Buffer.alloc == "undefined") {
|
||||
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) {
|
||||
var match = /\n\/\/# sourceMappingURL=data:application\/json(;.*?)?;base64,(.*)/.exec(code);
|
||||
if (!match) {
|
||||
AST_Node.warn("inline source map not found: " + name);
|
||||
return null;
|
||||
function read_source_map(name, toplevel) {
|
||||
var comments = toplevel.end.comments_after;
|
||||
for (var i = comments.length; --i >= 0;) {
|
||||
var comment = comments[i];
|
||||
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) {
|
||||
@@ -51,7 +71,6 @@ function to_json(cache) {
|
||||
}
|
||||
|
||||
function minify(files, options) {
|
||||
var warn_function = AST_Node.warn_function;
|
||||
try {
|
||||
options = defaults(options, {
|
||||
compress: {},
|
||||
@@ -78,7 +97,6 @@ function minify(files, options) {
|
||||
set_shorthand("ie8", options, [ "compress", "mangle", "output" ]);
|
||||
set_shorthand("keep_fnames", options, [ "compress", "mangle" ]);
|
||||
set_shorthand("toplevel", options, [ "compress", "mangle" ]);
|
||||
set_shorthand("warnings", options, [ "compress" ]);
|
||||
var quoted_props;
|
||||
if (options.mangle) {
|
||||
options.mangle = defaults(options.mangle, {
|
||||
@@ -116,11 +134,9 @@ function minify(files, options) {
|
||||
}, true);
|
||||
}
|
||||
var warnings = [];
|
||||
if (options.warnings && !AST_Node.warn_function) {
|
||||
AST_Node.warn_function = function(warning) {
|
||||
warnings.push(warning);
|
||||
};
|
||||
}
|
||||
if (options.warnings) AST_Node.log_function(function(warning) {
|
||||
warnings.push(warning);
|
||||
}, options.warnings == "verbose");
|
||||
if (timings) timings.parse = Date.now();
|
||||
var source_maps, toplevel;
|
||||
if (files instanceof AST_Toplevel) {
|
||||
@@ -138,10 +154,10 @@ function minify(files, options) {
|
||||
source_maps = source_map_content && Object.create(null);
|
||||
for (var name in files) if (HOP(files, 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_map_content == "inline") {
|
||||
var inlined_content = read_source_map(name, files[name]);
|
||||
var inlined_content = read_source_map(name, toplevel);
|
||||
if (inlined_content) {
|
||||
source_maps[name] = parse_source_map(inlined_content);
|
||||
}
|
||||
@@ -150,17 +166,17 @@ function minify(files, options) {
|
||||
}
|
||||
}
|
||||
}
|
||||
toplevel = options.parse.toplevel;
|
||||
}
|
||||
if (quoted_props) {
|
||||
reserve_quoted_keys(toplevel, quoted_props);
|
||||
}
|
||||
if (options.wrap) {
|
||||
toplevel = toplevel.wrap_commonjs(options.wrap);
|
||||
}
|
||||
if (options.enclose) {
|
||||
toplevel = toplevel.wrap_enclose(options.enclose);
|
||||
}
|
||||
[ "enclose", "wrap" ].forEach(function(action) {
|
||||
var option = options[action];
|
||||
if (!option) return;
|
||||
var orig = toplevel.print_to_string().slice(0, -1);
|
||||
toplevel = toplevel[action](option);
|
||||
files[toplevel.start.file] = toplevel.print_to_string().replace(orig, "");
|
||||
});
|
||||
if (timings) timings.rename = Date.now();
|
||||
if (options.rename) {
|
||||
toplevel.figure_out_scope(options.mangle);
|
||||
@@ -208,10 +224,14 @@ function minify(files, options) {
|
||||
result.code = stream.get();
|
||||
if (options.sourceMap) {
|
||||
result.map = options.output.source_map.toString();
|
||||
if (options.sourceMap.url == "inline") {
|
||||
result.code += "\n//# sourceMappingURL=data:application/json;charset=utf-8;base64," + to_base64(result.map);
|
||||
} else if (options.sourceMap.url) {
|
||||
result.code += "\n//# sourceMappingURL=" + options.sourceMap.url;
|
||||
var url = options.sourceMap.url;
|
||||
if (url) {
|
||||
result.code = result.code.replace(/\n\/\/# sourceMappingURL=\S+\s*$/, "");
|
||||
if (url == "inline") {
|
||||
result.code += "\n//# sourceMappingURL=data:application/json;charset=utf-8;base64," + to_base64(result.map);
|
||||
} else {
|
||||
result.code += "\n//# sourceMappingURL=" + url;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -240,7 +260,5 @@ function minify(files, options) {
|
||||
return result;
|
||||
} catch (ex) {
|
||||
return { error: ex };
|
||||
} finally {
|
||||
AST_Node.warn_function = warn_function;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -403,7 +403,7 @@
|
||||
var def = M.definition();
|
||||
return {
|
||||
type: "Identifier",
|
||||
name: def ? def.mangled_name || def.name : M.name
|
||||
name: def && def.mangled_name || M.name
|
||||
};
|
||||
});
|
||||
|
||||
|
||||
234
lib/output.js
234
lib/output.js
@@ -91,13 +91,11 @@ function OutputStream(options) {
|
||||
comment_filter = function(comment) {
|
||||
return comment.type != "comment5" && comments.test(comment.value);
|
||||
};
|
||||
}
|
||||
else if (typeof comments === "function") {
|
||||
} else if (typeof comments === "function") {
|
||||
comment_filter = function(comment) {
|
||||
return comment.type != "comment5" && comments(this, comment);
|
||||
};
|
||||
}
|
||||
else if (comments === "some") {
|
||||
} else if (comments === "some") {
|
||||
comment_filter = is_some_comments;
|
||||
} else { // NOTE includes "all" option
|
||||
comment_filter = return_true;
|
||||
@@ -123,7 +121,7 @@ function OutputStream(options) {
|
||||
});
|
||||
} : function(str) {
|
||||
var s = "";
|
||||
for (var i = 0, len = str.length; i < len; i++) {
|
||||
for (var i = 0; i < str.length; i++) {
|
||||
if (is_surrogate_pair_head(str[i]) && !is_surrogate_pair_tail(str[i + 1])
|
||||
|| is_surrogate_pair_tail(str[i]) && !is_surrogate_pair_head(str[i - 1])) {
|
||||
s += "\\u" + str.charCodeAt(i).toString(16);
|
||||
@@ -136,8 +134,7 @@ function OutputStream(options) {
|
||||
|
||||
function make_string(str, quote) {
|
||||
var dq = 0, sq = 0;
|
||||
str = str.replace(/[\\\b\f\n\r\v\t\x22\x27\u2028\u2029\0\ufeff]/g,
|
||||
function(s, i) {
|
||||
str = str.replace(/[\\\b\f\n\r\v\t\x22\x27\u2028\u2029\0\ufeff]/g, function(s, i) {
|
||||
switch (s) {
|
||||
case '"': ++dq; return '"';
|
||||
case "'": ++sq; return "'";
|
||||
@@ -198,63 +195,59 @@ function OutputStream(options) {
|
||||
/* -----[ beautification/minification ]----- */
|
||||
|
||||
var has_parens = false;
|
||||
var line_end = 0;
|
||||
var line_fixed = true;
|
||||
var might_need_space = false;
|
||||
var might_need_semicolon = false;
|
||||
var might_add_newline = 0;
|
||||
var need_newline_indented = false;
|
||||
var need_space = false;
|
||||
var newline_insert = -1;
|
||||
var last = "";
|
||||
var mapping_token, mapping_name, mappings = options.source_map && [];
|
||||
|
||||
var do_add_mapping = mappings ? function() {
|
||||
var adjust_mappings = mappings ? function(line, col) {
|
||||
mappings.forEach(function(mapping) {
|
||||
try {
|
||||
options.source_map.add(
|
||||
mapping.token.file,
|
||||
mapping.line, mapping.col,
|
||||
mapping.token.line, mapping.token.col,
|
||||
!mapping.name && mapping.token.type == "name" ? mapping.token.value : mapping.name
|
||||
);
|
||||
} catch(ex) {
|
||||
AST_Node.warn("Couldn't figure out mapping for {file}:{line},{col} → {cline},{ccol} [{name}]", {
|
||||
file: mapping.token.file,
|
||||
line: mapping.token.line,
|
||||
col: mapping.token.col,
|
||||
cline: mapping.line,
|
||||
ccol: mapping.col,
|
||||
name: mapping.name || ""
|
||||
})
|
||||
}
|
||||
mapping.line += line;
|
||||
mapping.col += col;
|
||||
});
|
||||
} : noop;
|
||||
|
||||
var flush_mappings = mappings ? function() {
|
||||
mappings.forEach(function(mapping) {
|
||||
options.source_map.add(
|
||||
mapping.token.file,
|
||||
mapping.line, mapping.col,
|
||||
mapping.token.line, mapping.token.col,
|
||||
!mapping.name && mapping.token.type == "name" ? mapping.token.value : mapping.name
|
||||
);
|
||||
});
|
||||
mappings = [];
|
||||
} : noop;
|
||||
|
||||
var ensure_line_len = options.max_line_len ? function() {
|
||||
if (current_col > options.max_line_len) {
|
||||
if (might_add_newline) {
|
||||
var left = OUTPUT.slice(0, might_add_newline);
|
||||
var right = OUTPUT.slice(might_add_newline);
|
||||
if (mappings) {
|
||||
var delta = right.length - current_col;
|
||||
mappings.forEach(function(mapping) {
|
||||
mapping.line++;
|
||||
mapping.col += delta;
|
||||
});
|
||||
}
|
||||
OUTPUT = left + "\n" + right;
|
||||
current_line++;
|
||||
current_pos++;
|
||||
current_col = right.length;
|
||||
}
|
||||
function insert_newlines(count) {
|
||||
var index = OUTPUT.lastIndexOf("\n");
|
||||
if (line_end < index) line_end = index;
|
||||
var left = OUTPUT.slice(0, line_end);
|
||||
var right = OUTPUT.slice(line_end);
|
||||
adjust_mappings(count, right.length - current_col);
|
||||
current_line += count;
|
||||
current_pos += count;
|
||||
current_col = right.length;
|
||||
OUTPUT = left;
|
||||
while (count--) OUTPUT += "\n";
|
||||
OUTPUT += right;
|
||||
}
|
||||
|
||||
var fix_line = options.max_line_len ? function() {
|
||||
if (line_fixed) {
|
||||
if (current_col > options.max_line_len) {
|
||||
AST_Node.warn("Output exceeds {max_line_len} characters", options);
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (might_add_newline) {
|
||||
might_add_newline = 0;
|
||||
do_add_mapping();
|
||||
}
|
||||
if (current_col > options.max_line_len) insert_newlines(1);
|
||||
line_fixed = true;
|
||||
flush_mappings();
|
||||
} : noop;
|
||||
|
||||
var requireSemicolonChars = makePredicate("( [ + * / - , .");
|
||||
@@ -286,7 +279,7 @@ function OutputStream(options) {
|
||||
current_col++;
|
||||
current_pos++;
|
||||
} else {
|
||||
ensure_line_len();
|
||||
fix_line();
|
||||
OUTPUT += "\n";
|
||||
current_pos++;
|
||||
current_line++;
|
||||
@@ -304,18 +297,6 @@ function OutputStream(options) {
|
||||
}
|
||||
}
|
||||
|
||||
if (!options.beautify && options.preserve_line && stack[stack.length - 1]) {
|
||||
var target_line = stack[stack.length - 1].start.line;
|
||||
while (current_line < target_line) {
|
||||
ensure_line_len();
|
||||
OUTPUT += "\n";
|
||||
current_pos++;
|
||||
current_line++;
|
||||
current_col = 0;
|
||||
might_need_space = false;
|
||||
}
|
||||
}
|
||||
|
||||
if (might_need_space) {
|
||||
if ((is_identifier_char(prev)
|
||||
&& (is_identifier_char(ch) || ch == "\\"))
|
||||
@@ -337,7 +318,7 @@ function OutputStream(options) {
|
||||
col: current_col
|
||||
});
|
||||
mapping_token = false;
|
||||
if (!might_add_newline) do_add_mapping();
|
||||
if (line_fixed) flush_mappings();
|
||||
}
|
||||
|
||||
OUTPUT += str;
|
||||
@@ -347,7 +328,7 @@ function OutputStream(options) {
|
||||
current_line += n;
|
||||
current_col += a[0].length;
|
||||
if (n > 0) {
|
||||
ensure_line_len();
|
||||
fix_line();
|
||||
current_col = a[n].length;
|
||||
}
|
||||
last = str;
|
||||
@@ -374,9 +355,10 @@ function OutputStream(options) {
|
||||
return ret;
|
||||
} : function(col, cont) { return cont() };
|
||||
|
||||
var may_add_newline = options.max_line_len ? function() {
|
||||
ensure_line_len();
|
||||
might_add_newline = OUTPUT.length;
|
||||
var may_add_newline = options.max_line_len || options.preserve_line ? function() {
|
||||
fix_line();
|
||||
line_end = OUTPUT.length;
|
||||
line_fixed = false;
|
||||
} : noop;
|
||||
|
||||
var newline = options.beautify ? function() {
|
||||
@@ -455,9 +437,7 @@ function OutputStream(options) {
|
||||
} : noop;
|
||||
|
||||
function get() {
|
||||
if (might_add_newline) {
|
||||
ensure_line_len();
|
||||
}
|
||||
if (!line_fixed) fix_line();
|
||||
return OUTPUT;
|
||||
}
|
||||
|
||||
@@ -468,16 +448,11 @@ function OutputStream(options) {
|
||||
|
||||
function prepend_comments(node) {
|
||||
var self = this;
|
||||
var start = node.start;
|
||||
if (!start) return;
|
||||
if (start.comments_before && start.comments_before._dumped === self) return;
|
||||
var comments = start.comments_before;
|
||||
if (!comments) {
|
||||
comments = start.comments_before = [];
|
||||
}
|
||||
comments._dumped = self;
|
||||
var scan = node instanceof AST_Exit && node.value;
|
||||
var comments = dump(node);
|
||||
if (!comments) comments = [];
|
||||
|
||||
if (node instanceof AST_Exit && node.value) {
|
||||
if (scan) {
|
||||
var tw = new TreeWalker(function(node) {
|
||||
var parent = tw.parent();
|
||||
if (parent instanceof AST_Exit
|
||||
@@ -488,11 +463,8 @@ function OutputStream(options) {
|
||||
|| parent instanceof AST_Sequence && parent.expressions[0] === node
|
||||
|| parent instanceof AST_Sub && parent.expression === node
|
||||
|| parent instanceof AST_UnaryPostfix) {
|
||||
var text = node.start.comments_before;
|
||||
if (text && text._dumped !== self) {
|
||||
text._dumped = self;
|
||||
comments = comments.concat(text);
|
||||
}
|
||||
var before = dump(node);
|
||||
if (before) comments = comments.concat(before);
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
@@ -535,13 +507,29 @@ function OutputStream(options) {
|
||||
}
|
||||
});
|
||||
if (!last_nlb) {
|
||||
if (start.nlb) {
|
||||
if (node.start.nlb) {
|
||||
print("\n");
|
||||
indent();
|
||||
} else {
|
||||
space();
|
||||
}
|
||||
}
|
||||
|
||||
function dump(node) {
|
||||
var token = node.start;
|
||||
if (!token) {
|
||||
if (!scan) return;
|
||||
node.start = token = new AST_Token();
|
||||
}
|
||||
var comments = token.comments_before;
|
||||
if (!comments) {
|
||||
if (!scan) return;
|
||||
token.comments_before = comments = [];
|
||||
}
|
||||
if (comments._dumped === self) return;
|
||||
comments._dumped = self;
|
||||
return comments;
|
||||
}
|
||||
}
|
||||
|
||||
function append_comments(node, tail) {
|
||||
@@ -608,7 +596,6 @@ function OutputStream(options) {
|
||||
}
|
||||
print(encoded);
|
||||
},
|
||||
encode_string : encode_string,
|
||||
next_indent : next_indent,
|
||||
with_indent : with_indent,
|
||||
with_block : with_block,
|
||||
@@ -622,7 +609,14 @@ function OutputStream(options) {
|
||||
col : function() { return current_col },
|
||||
pos : function() { return current_pos },
|
||||
push_node : function(node) { stack.push(node) },
|
||||
pop_node : function() { return stack.pop() },
|
||||
pop_node : options.preserve_line ? function() {
|
||||
var node = stack.pop();
|
||||
if (node.start && node.start.line > current_line) {
|
||||
insert_newlines(node.start.line - current_line);
|
||||
}
|
||||
} : function() {
|
||||
stack.pop();
|
||||
},
|
||||
parent : function(n) {
|
||||
return stack[stack.length - 2 - (n || 0)];
|
||||
}
|
||||
@@ -647,8 +641,7 @@ function OutputStream(options) {
|
||||
var self = this, generator = self._codegen;
|
||||
if (self instanceof AST_Scope) {
|
||||
active_scope = self;
|
||||
}
|
||||
else if (!use_asm && self instanceof AST_Directive && self.value == "use asm") {
|
||||
} else if (!use_asm && self instanceof AST_Directive && self.value == "use asm") {
|
||||
use_asm = active_scope;
|
||||
}
|
||||
function doit() {
|
||||
@@ -693,23 +686,15 @@ function OutputStream(options) {
|
||||
// a function expression needs parens around it when it's provably
|
||||
// the first token to appear in a statement.
|
||||
PARENS(AST_Function, function(output) {
|
||||
if (!output.has_parens() && first_in_statement(output)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!output.has_parens() && first_in_statement(output)) return true;
|
||||
if (output.option('webkit')) {
|
||||
var p = output.parent();
|
||||
if (p instanceof AST_PropAccess && p.expression === this) {
|
||||
return true;
|
||||
}
|
||||
if (p instanceof AST_PropAccess && p.expression === this) return true;
|
||||
}
|
||||
|
||||
if (output.option('wrap_iife')) {
|
||||
var p = output.parent();
|
||||
return p instanceof AST_Call && p.expression === this;
|
||||
if (p instanceof AST_Call && p.expression === this) return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
});
|
||||
|
||||
// same goes for an object literal, because otherwise it would be
|
||||
@@ -783,17 +768,17 @@ function OutputStream(options) {
|
||||
});
|
||||
|
||||
PARENS(AST_Call, function(output) {
|
||||
var p = output.parent(), p1;
|
||||
if (p instanceof AST_New && p.expression === this)
|
||||
return true;
|
||||
|
||||
// workaround for Safari bug.
|
||||
var p = output.parent();
|
||||
if (p instanceof AST_New && p.expression === this) return true;
|
||||
// https://bugs.webkit.org/show_bug.cgi?id=123506
|
||||
return this.expression instanceof AST_Function
|
||||
&& p instanceof AST_PropAccess
|
||||
&& p.expression === this
|
||||
&& (p1 = output.parent(1)) instanceof AST_Assign
|
||||
&& p1.left === p;
|
||||
if (output.option('webkit')) {
|
||||
var g = output.parent(1);
|
||||
return this.expression instanceof AST_Function
|
||||
&& p instanceof AST_PropAccess
|
||||
&& p.expression === this
|
||||
&& g instanceof AST_Assign
|
||||
&& g.left === p;
|
||||
}
|
||||
});
|
||||
|
||||
PARENS(AST_New, function(output) {
|
||||
@@ -1055,11 +1040,9 @@ function OutputStream(options) {
|
||||
return;
|
||||
}
|
||||
b = b.alternative;
|
||||
}
|
||||
else if (b instanceof AST_StatementWithBody) {
|
||||
} else if (b instanceof AST_StatementWithBody) {
|
||||
b = b.body;
|
||||
}
|
||||
else break;
|
||||
} else break;
|
||||
}
|
||||
force_statement(self.body, output);
|
||||
}
|
||||
@@ -1160,7 +1143,7 @@ function OutputStream(options) {
|
||||
def.print(output);
|
||||
});
|
||||
var p = output.parent();
|
||||
if (p.init !== self || !(p instanceof AST_For || p instanceof AST_ForIn)) output.semicolon();
|
||||
if (p && p.init !== self || !(p instanceof AST_For || p instanceof AST_ForIn)) output.semicolon();
|
||||
});
|
||||
|
||||
function parenthesize_for_noin(node, output, noin) {
|
||||
@@ -1367,7 +1350,7 @@ function OutputStream(options) {
|
||||
});
|
||||
DEFPRINT(AST_Symbol, function(self, output) {
|
||||
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_This, function(self, output) {
|
||||
@@ -1393,8 +1376,27 @@ function OutputStream(options) {
|
||||
if (regexp.raw_source) {
|
||||
str = "/" + regexp.raw_source + str.slice(str.lastIndexOf("/"));
|
||||
}
|
||||
str = output.to_utf8(str);
|
||||
output.print(str);
|
||||
output.print(output.to_utf8(str).replace(/\\(?:\0(?![0-9])|[^\0])/g, function(seq) {
|
||||
switch (seq[1]) {
|
||||
case "\n": return "\\n";
|
||||
case "\r": return "\\r";
|
||||
case "\t": return "\t";
|
||||
case "\b": return "\b";
|
||||
case "\f": return "\f";
|
||||
case "\0": return "\0";
|
||||
case "\x0B": return "\v";
|
||||
case "\u2028": return "\\u2028";
|
||||
case "\u2029": return "\\u2029";
|
||||
default: return seq;
|
||||
}
|
||||
}).replace(/[\n\r\u2028\u2029]/g, function(c) {
|
||||
switch (c) {
|
||||
case "\n": return "\\n";
|
||||
case "\r": return "\\r";
|
||||
case "\u2028": return "\\u2028";
|
||||
case "\u2029": return "\\u2029";
|
||||
}
|
||||
}));
|
||||
var p = output.parent();
|
||||
if (p instanceof AST_Binary && /^in/.test(p.operator) && p.left === self)
|
||||
output.print(" ");
|
||||
|
||||
138
lib/parse.js
138
lib/parse.js
@@ -164,10 +164,6 @@ function is_unicode_connector_punctuation(ch) {
|
||||
return UNICODE.connector_punctuation.test(ch);
|
||||
}
|
||||
|
||||
function is_identifier(name) {
|
||||
return !RESERVED_WORDS[name] && /^[a-z_$][a-z0-9_$]*$/i.test(name);
|
||||
}
|
||||
|
||||
function is_identifier_start(code) {
|
||||
return code == 36 || code == 95 || is_letter(code);
|
||||
}
|
||||
@@ -238,6 +234,7 @@ function tokenizer($TEXT, filename, html5_comments, shebang) {
|
||||
directives : {},
|
||||
directive_stack : []
|
||||
};
|
||||
var prev_was_dot = false;
|
||||
|
||||
function peek() {
|
||||
return S.text.charAt(S.pos);
|
||||
@@ -272,10 +269,8 @@ function tokenizer($TEXT, filename, html5_comments, shebang) {
|
||||
|
||||
function find_eol() {
|
||||
var text = S.text;
|
||||
for (var i = S.pos, n = S.text.length; i < n; ++i) {
|
||||
var ch = text[i];
|
||||
if (NEWLINE_CHARS[ch])
|
||||
return i;
|
||||
for (var i = S.pos; i < S.text.length; ++i) {
|
||||
if (NEWLINE_CHARS[text[i]]) return i;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
@@ -292,16 +287,12 @@ function tokenizer($TEXT, filename, html5_comments, shebang) {
|
||||
S.tokpos = S.pos;
|
||||
}
|
||||
|
||||
var prev_was_dot = false;
|
||||
function token(type, value, is_comment) {
|
||||
S.regex_allowed = ((type == "operator" && !UNARY_POSTFIX[value]) ||
|
||||
(type == "keyword" && KEYWORDS_BEFORE_EXPRESSION[value]) ||
|
||||
(type == "punc" && PUNC_BEFORE_EXPRESSION[value]));
|
||||
if (type == "punc" && value == ".") {
|
||||
prev_was_dot = true;
|
||||
} else if (!is_comment) {
|
||||
prev_was_dot = false;
|
||||
}
|
||||
S.regex_allowed = type == "operator" && !UNARY_POSTFIX[value]
|
||||
|| type == "keyword" && KEYWORDS_BEFORE_EXPRESSION[value]
|
||||
|| type == "punc" && PUNC_BEFORE_EXPRESSION[value];
|
||||
if (type == "punc" && value == ".") prev_was_dot = true;
|
||||
else if (!is_comment) prev_was_dot = false;
|
||||
var ret = {
|
||||
type : type,
|
||||
value : value,
|
||||
@@ -364,11 +355,8 @@ function tokenizer($TEXT, filename, html5_comments, shebang) {
|
||||
parse_error("Legacy octal literals are not allowed in strict mode");
|
||||
}
|
||||
var valid = parse_js_number(num);
|
||||
if (!isNaN(valid)) {
|
||||
return token("num", valid);
|
||||
} else {
|
||||
parse_error("Invalid syntax: " + num);
|
||||
}
|
||||
if (!isNaN(valid)) return token("num", valid);
|
||||
parse_error("Invalid syntax: " + num);
|
||||
}
|
||||
|
||||
function read_escaped_char(in_string) {
|
||||
@@ -469,8 +457,7 @@ function tokenizer($TEXT, filename, html5_comments, shebang) {
|
||||
if (ch == "\\") escaped = backslash = true, next();
|
||||
else if (is_identifier_char(ch)) name += next();
|
||||
else break;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
if (ch != "u") parse_error("Expecting UnicodeEscapeSequence -- uXXXX");
|
||||
ch = read_escaped_char();
|
||||
if (!is_identifier_char(ch)) parse_error("Unicode char: " + ch.charCodeAt(0) + " is not valid in identifier");
|
||||
@@ -510,7 +497,7 @@ function tokenizer($TEXT, filename, html5_comments, shebang) {
|
||||
var regexp = new RegExp(source, mods);
|
||||
regexp.raw_source = source;
|
||||
return token("regexp", regexp);
|
||||
} catch(e) {
|
||||
} catch (e) {
|
||||
parse_error(e.message);
|
||||
}
|
||||
});
|
||||
@@ -544,9 +531,7 @@ function tokenizer($TEXT, filename, html5_comments, shebang) {
|
||||
|
||||
function handle_dot() {
|
||||
next();
|
||||
return is_digit(peek().charCodeAt(0))
|
||||
? read_num(".")
|
||||
: token("punc", ".");
|
||||
return is_digit(peek().charCodeAt(0)) ? read_num(".") : token("punc", ".");
|
||||
}
|
||||
|
||||
function read_word() {
|
||||
@@ -562,7 +547,7 @@ function tokenizer($TEXT, filename, html5_comments, shebang) {
|
||||
return function(x) {
|
||||
try {
|
||||
return cont(x);
|
||||
} catch(ex) {
|
||||
} catch (ex) {
|
||||
if (ex === EX_EOF) parse_error(eof_error);
|
||||
else throw ex;
|
||||
}
|
||||
@@ -598,11 +583,10 @@ function tokenizer($TEXT, filename, html5_comments, shebang) {
|
||||
switch (code) {
|
||||
case 34: case 39: return read_string(ch);
|
||||
case 46: return handle_dot();
|
||||
case 47: {
|
||||
var tok = handle_slash();
|
||||
if (tok === next_token) continue;
|
||||
return tok;
|
||||
}
|
||||
case 47:
|
||||
var tok = handle_slash();
|
||||
if (tok === next_token) continue;
|
||||
return tok;
|
||||
}
|
||||
if (is_digit(code)) return read_num();
|
||||
if (PUNC_CHARS[ch]) return token("punc", next());
|
||||
@@ -620,12 +604,8 @@ function tokenizer($TEXT, filename, html5_comments, shebang) {
|
||||
|
||||
next_token.add_directive = function(directive) {
|
||||
S.directive_stack[S.directive_stack.length - 1].push(directive);
|
||||
|
||||
if (S.directives[directive] === undefined) {
|
||||
S.directives[directive] = 1;
|
||||
} else {
|
||||
S.directives[directive]++;
|
||||
}
|
||||
if (S.directives[directive]) S.directives[directive]++;
|
||||
else S.directives[directive] = 1;
|
||||
}
|
||||
|
||||
next_token.push_directives_stack = function() {
|
||||
@@ -633,13 +613,10 @@ function tokenizer($TEXT, filename, html5_comments, shebang) {
|
||||
}
|
||||
|
||||
next_token.pop_directives_stack = function() {
|
||||
var directives = S.directive_stack[S.directive_stack.length - 1];
|
||||
|
||||
for (var i = 0; i < directives.length; i++) {
|
||||
var directives = S.directive_stack.pop();
|
||||
for (var i = directives.length; --i >= 0;) {
|
||||
S.directives[directives[i]]--;
|
||||
}
|
||||
|
||||
S.directive_stack.pop();
|
||||
}
|
||||
|
||||
next_token.has_directive = function(directive) {
|
||||
@@ -651,27 +628,17 @@ function tokenizer($TEXT, filename, html5_comments, shebang) {
|
||||
|
||||
/* -----[ Parser (constants) ]----- */
|
||||
|
||||
var UNARY_PREFIX = makePredicate([
|
||||
"typeof",
|
||||
"void",
|
||||
"delete",
|
||||
"--",
|
||||
"++",
|
||||
"!",
|
||||
"~",
|
||||
"-",
|
||||
"+"
|
||||
]);
|
||||
var UNARY_PREFIX = makePredicate("typeof void delete -- ++ ! ~ - +");
|
||||
|
||||
var UNARY_POSTFIX = makePredicate([ "--", "++" ]);
|
||||
var UNARY_POSTFIX = makePredicate("-- ++");
|
||||
|
||||
var ASSIGNMENT = makePredicate([ "=", "+=", "-=", "/=", "*=", "%=", ">>=", "<<=", ">>>=", "|=", "^=", "&=" ]);
|
||||
var ASSIGNMENT = makePredicate("= += -= /= *= %= >>= <<= >>>= |= ^= &=");
|
||||
|
||||
var PRECEDENCE = function(a, ret) {
|
||||
for (var i = 0; i < a.length; ++i) {
|
||||
var b = a[i];
|
||||
for (var j = 0; j < b.length; ++j) {
|
||||
ret[b[j]] = i + 1;
|
||||
for (var i = 0; i < a.length;) {
|
||||
var b = a[i++];
|
||||
for (var j = 0; j < b.length; j++) {
|
||||
ret[b[j]] = i;
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
@@ -688,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 ]----- */
|
||||
|
||||
@@ -704,10 +671,9 @@ function parse($TEXT, options) {
|
||||
}, true);
|
||||
|
||||
var S = {
|
||||
input : (typeof $TEXT == "string"
|
||||
? tokenizer($TEXT, options.filename,
|
||||
options.html5_comments, options.shebang)
|
||||
: $TEXT),
|
||||
input : typeof $TEXT == "string"
|
||||
? tokenizer($TEXT, options.filename, options.html5_comments, options.shebang)
|
||||
: $TEXT,
|
||||
token : null,
|
||||
prev : null,
|
||||
peeked : null,
|
||||
@@ -758,17 +724,18 @@ function parse($TEXT, options) {
|
||||
croak(msg, token.line, token.col);
|
||||
}
|
||||
|
||||
function token_to_string(type, value) {
|
||||
return type + (value === undefined ? "" : " «" + value + "»");
|
||||
}
|
||||
|
||||
function unexpected(token) {
|
||||
if (token == null)
|
||||
token = S.token;
|
||||
token_error(token, "Unexpected token: " + token.type + " (" + token.value + ")");
|
||||
if (token == null) token = S.token;
|
||||
token_error(token, "Unexpected token: " + token_to_string(token.type, token.value));
|
||||
}
|
||||
|
||||
function expect_token(type, val) {
|
||||
if (is(type, val)) {
|
||||
return next();
|
||||
}
|
||||
token_error(S.token, "Unexpected token " + S.token.type + " «" + S.token.value + "»" + ", expected " + type + " «" + val + "»");
|
||||
if (is(type, val)) return next();
|
||||
token_error(S.token, "Unexpected token: " + token_to_string(S.token.type, S.token.value) + ", expected: " + token_to_string(type, val));
|
||||
}
|
||||
|
||||
function expect(punc) {
|
||||
@@ -788,7 +755,7 @@ function parse($TEXT, options) {
|
||||
|
||||
function semicolon(optional) {
|
||||
if (is("punc", ";")) next();
|
||||
else if (!optional && !can_insert_semicolon()) unexpected();
|
||||
else if (!optional && !can_insert_semicolon()) expect_token("punc", ";");
|
||||
}
|
||||
|
||||
function parenthesised() {
|
||||
@@ -1069,7 +1036,7 @@ function parse($TEXT, options) {
|
||||
var in_statement = ctor === AST_Defun;
|
||||
var name = is("name") ? as_symbol(in_statement ? AST_SymbolDefun : AST_SymbolLambda) : null;
|
||||
if (in_statement && !name)
|
||||
unexpected();
|
||||
expect_token("name");
|
||||
if (name && ctor !== AST_Accessor && !(name instanceof AST_SymbolDeclaration))
|
||||
unexpected(prev());
|
||||
expect("(");
|
||||
@@ -1119,7 +1086,7 @@ function parse($TEXT, options) {
|
||||
expect("{");
|
||||
var a = [];
|
||||
while (!is("punc", "}")) {
|
||||
if (is("eof")) unexpected();
|
||||
if (is("eof")) expect_token("punc", "}");
|
||||
a.push(statement(strict_defun));
|
||||
}
|
||||
next();
|
||||
@@ -1130,7 +1097,7 @@ function parse($TEXT, options) {
|
||||
expect("{");
|
||||
var a = [], cur = null, branch = null, tmp;
|
||||
while (!is("punc", "}")) {
|
||||
if (is("eof")) unexpected();
|
||||
if (is("eof")) expect_token("punc", "}");
|
||||
if (is("keyword", "case")) {
|
||||
if (branch) branch.end = prev();
|
||||
cur = [];
|
||||
@@ -1141,8 +1108,7 @@ function parse($TEXT, options) {
|
||||
});
|
||||
a.push(branch);
|
||||
expect(":");
|
||||
}
|
||||
else if (is("keyword", "default")) {
|
||||
} else if (is("keyword", "default")) {
|
||||
if (branch) branch.end = prev();
|
||||
cur = [];
|
||||
branch = new AST_Default({
|
||||
@@ -1150,8 +1116,7 @@ function parse($TEXT, options) {
|
||||
body : cur
|
||||
});
|
||||
a.push(branch);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
if (!cur) unexpected();
|
||||
cur.push(statement());
|
||||
}
|
||||
@@ -1288,6 +1253,7 @@ function parse($TEXT, options) {
|
||||
var ex = expression(true);
|
||||
var len = start.comments_before.length;
|
||||
[].unshift.apply(ex.start.comments_before, start.comments_before);
|
||||
start.comments_before.length = 0;
|
||||
start.comments_before = ex.start.comments_before;
|
||||
start.comments_before_length = len;
|
||||
if (len == 0 && start.comments_before.length > 0) {
|
||||
@@ -1303,6 +1269,7 @@ function parse($TEXT, options) {
|
||||
var end = prev();
|
||||
end.comments_before = ex.end.comments_before;
|
||||
[].push.apply(ex.end.comments_after, end.comments_after);
|
||||
end.comments_after.length = 0;
|
||||
end.comments_after = ex.end.comments_after;
|
||||
ex.end = end;
|
||||
if (ex instanceof AST_Call) mark_pure(ex);
|
||||
@@ -1420,10 +1387,10 @@ function parse($TEXT, options) {
|
||||
}
|
||||
|
||||
function as_name() {
|
||||
var tmp = S.token;
|
||||
if (tmp.type != "name") unexpected();
|
||||
if (!is("name")) expect_token("name");
|
||||
var name = S.token.value;
|
||||
next();
|
||||
return tmp.value;
|
||||
return name;
|
||||
}
|
||||
|
||||
function _make_symbol(type) {
|
||||
@@ -1625,6 +1592,7 @@ function parse($TEXT, options) {
|
||||
}
|
||||
|
||||
if (options.expression) {
|
||||
handle_regexp();
|
||||
return expression(true);
|
||||
}
|
||||
|
||||
|
||||
@@ -53,25 +53,30 @@ function find_builtins(reserved) {
|
||||
"-Infinity",
|
||||
"undefined",
|
||||
].forEach(add);
|
||||
[ Object, Array, Function, Number,
|
||||
String, Boolean, Error, Math,
|
||||
Date, RegExp
|
||||
[
|
||||
Array,
|
||||
Boolean,
|
||||
Date,
|
||||
Error,
|
||||
Function,
|
||||
Math,
|
||||
Number,
|
||||
Object,
|
||||
RegExp,
|
||||
String,
|
||||
].forEach(function(ctor) {
|
||||
Object.getOwnPropertyNames(ctor).map(add);
|
||||
if (ctor.prototype) {
|
||||
Object.getOwnPropertyNames(ctor.prototype).map(add);
|
||||
}
|
||||
});
|
||||
|
||||
function add(name) {
|
||||
push_uniq(reserved, name);
|
||||
}
|
||||
}
|
||||
|
||||
function reserve_quoted_keys(ast, reserved) {
|
||||
function add(name) {
|
||||
push_uniq(reserved, name);
|
||||
}
|
||||
|
||||
ast.walk(new TreeWalker(function(node) {
|
||||
if (node instanceof AST_ObjectKeyVal && node.quote) {
|
||||
add(node.key);
|
||||
@@ -79,6 +84,10 @@ function reserve_quoted_keys(ast, reserved) {
|
||||
addStrings(node.property, add);
|
||||
}
|
||||
}));
|
||||
|
||||
function add(name) {
|
||||
push_uniq(reserved, name);
|
||||
}
|
||||
}
|
||||
|
||||
function addStrings(node, add) {
|
||||
@@ -127,10 +136,8 @@ function mangle_properties(ast, options) {
|
||||
// note debug may be enabled as an empty string, which is falsey. Also treat passing 'true'
|
||||
// the same as passing an empty string.
|
||||
var debug = options.debug !== false;
|
||||
var debug_name_suffix;
|
||||
if (debug) {
|
||||
debug_name_suffix = (options.debug === true ? "" : options.debug);
|
||||
}
|
||||
var debug_suffix;
|
||||
if (debug) debug_suffix = options.debug === true ? "" : options.debug;
|
||||
|
||||
var names_to_mangle = [];
|
||||
var unmangleable = [];
|
||||
@@ -139,18 +146,14 @@ function mangle_properties(ast, options) {
|
||||
ast.walk(new TreeWalker(function(node) {
|
||||
if (node instanceof AST_ObjectKeyVal) {
|
||||
add(node.key);
|
||||
}
|
||||
else if (node instanceof AST_ObjectProperty) {
|
||||
} else if (node instanceof AST_ObjectProperty) {
|
||||
// setter or getter, since KeyVal is handled above
|
||||
add(node.key.name);
|
||||
}
|
||||
else if (node instanceof AST_Dot) {
|
||||
} else if (node instanceof AST_Dot) {
|
||||
add(node.property);
|
||||
}
|
||||
else if (node instanceof AST_Sub) {
|
||||
} else if (node instanceof AST_Sub) {
|
||||
addStrings(node.property, add);
|
||||
}
|
||||
else if (node instanceof AST_Call
|
||||
} else if (node instanceof AST_Call
|
||||
&& node.expression.print_to_string() == "Object.defineProperty") {
|
||||
addStrings(node.args[1], add);
|
||||
}
|
||||
@@ -160,18 +163,14 @@ function mangle_properties(ast, options) {
|
||||
return ast.transform(new TreeTransformer(function(node) {
|
||||
if (node instanceof AST_ObjectKeyVal) {
|
||||
node.key = mangle(node.key);
|
||||
}
|
||||
else if (node instanceof AST_ObjectProperty) {
|
||||
} else if (node instanceof AST_ObjectProperty) {
|
||||
// setter or getter
|
||||
node.key.name = mangle(node.key.name);
|
||||
}
|
||||
else if (node instanceof AST_Dot) {
|
||||
} else if (node instanceof AST_Dot) {
|
||||
node.property = mangle(node.property);
|
||||
}
|
||||
else if (!options.keep_quoted && node instanceof AST_Sub) {
|
||||
} else if (!options.keep_quoted && node instanceof AST_Sub) {
|
||||
node.property = mangleStrings(node.property);
|
||||
}
|
||||
else if (node instanceof AST_Call
|
||||
} else if (node instanceof AST_Call
|
||||
&& node.expression.print_to_string() == "Object.defineProperty") {
|
||||
node.args[1] = mangleStrings(node.args[1]);
|
||||
}
|
||||
@@ -182,9 +181,7 @@ function mangle_properties(ast, options) {
|
||||
function can_mangle(name) {
|
||||
if (unmangleable.indexOf(name) >= 0) return false;
|
||||
if (reserved.indexOf(name) >= 0) return false;
|
||||
if (options.only_cache) {
|
||||
return cache.has(name);
|
||||
}
|
||||
if (options.only_cache) return cache.has(name);
|
||||
if (/^-?[0-9]+(\.[0-9]+)?(e[+-][0-9]+)?$/.test(name)) return false;
|
||||
return true;
|
||||
}
|
||||
@@ -192,42 +189,29 @@ function mangle_properties(ast, options) {
|
||||
function should_mangle(name) {
|
||||
if (regex && !regex.test(name)) return false;
|
||||
if (reserved.indexOf(name) >= 0) return false;
|
||||
return cache.has(name)
|
||||
|| names_to_mangle.indexOf(name) >= 0;
|
||||
return cache.has(name) || names_to_mangle.indexOf(name) >= 0;
|
||||
}
|
||||
|
||||
function add(name) {
|
||||
if (can_mangle(name))
|
||||
push_uniq(names_to_mangle, name);
|
||||
|
||||
if (!should_mangle(name)) {
|
||||
push_uniq(unmangleable, name);
|
||||
}
|
||||
if (can_mangle(name)) push_uniq(names_to_mangle, name);
|
||||
if (!should_mangle(name)) push_uniq(unmangleable, name);
|
||||
}
|
||||
|
||||
function mangle(name) {
|
||||
if (!should_mangle(name)) {
|
||||
return name;
|
||||
}
|
||||
|
||||
var mangled = cache.get(name);
|
||||
if (!mangled) {
|
||||
if (debug) {
|
||||
// debug mode: use a prefix and suffix to preserve readability, e.g. o.foo -> o._$foo$NNN_.
|
||||
var debug_mangled = "_$" + name + "$" + debug_name_suffix + "_";
|
||||
|
||||
if (can_mangle(debug_mangled)) {
|
||||
mangled = debug_mangled;
|
||||
}
|
||||
var debug_mangled = "_$" + name + "$" + debug_suffix + "_";
|
||||
if (can_mangle(debug_mangled)) mangled = debug_mangled;
|
||||
}
|
||||
|
||||
// either debug mode is off, or it is on and we could not use the mangled name
|
||||
if (!mangled) {
|
||||
do {
|
||||
mangled = base54(++cname);
|
||||
} while (!can_mangle(mangled));
|
||||
}
|
||||
|
||||
if (!mangled) do {
|
||||
mangled = base54(++cname);
|
||||
} while (!can_mangle(mangled));
|
||||
cache.set(name, mangled);
|
||||
}
|
||||
return mangled;
|
||||
@@ -238,11 +222,9 @@ function mangle_properties(ast, options) {
|
||||
if (node instanceof AST_Sequence) {
|
||||
var last = node.expressions.length - 1;
|
||||
node.expressions[last] = mangleStrings(node.expressions[last]);
|
||||
}
|
||||
else if (node instanceof AST_String) {
|
||||
} else if (node instanceof AST_String) {
|
||||
node.value = mangle(node.value);
|
||||
}
|
||||
else if (node instanceof AST_Conditional) {
|
||||
} else if (node instanceof AST_Conditional) {
|
||||
node.consequent = mangleStrings(node.consequent);
|
||||
node.alternative = mangleStrings(node.alternative);
|
||||
}
|
||||
|
||||
178
lib/scope.js
178
lib/scope.js
@@ -55,14 +55,13 @@ function SymbolDef(scope, orig, init) {
|
||||
this.mangled_name = null;
|
||||
this.undeclared = false;
|
||||
this.id = SymbolDef.next_id++;
|
||||
this.lambda = orig instanceof AST_SymbolLambda;
|
||||
}
|
||||
|
||||
SymbolDef.next_id = 1;
|
||||
|
||||
SymbolDef.prototype = {
|
||||
unmangleable: function(options) {
|
||||
if (!options) options = {};
|
||||
|
||||
return this.global && !options.toplevel
|
||||
|| this.undeclared
|
||||
|| !options.eval && this.scope.pinned()
|
||||
@@ -118,11 +117,10 @@ AST_Toplevel.DEFMETHOD("figure_out_scope", function(options) {
|
||||
descend();
|
||||
scope = save_scope;
|
||||
defun = save_defun;
|
||||
return true; // don't descend again in TreeWalker
|
||||
return true;
|
||||
}
|
||||
if (node instanceof AST_With) {
|
||||
for (var s = scope; s; s = s.parent_scope)
|
||||
s.uses_with = true;
|
||||
for (var s = scope; s; s = s.parent_scope) s.uses_with = true;
|
||||
return;
|
||||
}
|
||||
if (node instanceof AST_Symbol) {
|
||||
@@ -132,18 +130,14 @@ AST_Toplevel.DEFMETHOD("figure_out_scope", function(options) {
|
||||
node.thedef = node;
|
||||
node.references = [];
|
||||
}
|
||||
if (node instanceof AST_SymbolDefun || options.ie8 && node instanceof AST_SymbolLambda) {
|
||||
// Careful here, the scope where this should be defined is
|
||||
// the parent scope. The reason is that we enter a new
|
||||
// scope when we encounter the AST_Defun node (which is
|
||||
// instanceof AST_Scope) but we get to the symbol a bit
|
||||
// later.
|
||||
(node.scope = defun.parent_scope).def_function(node, defun);
|
||||
}
|
||||
else if (node instanceof AST_SymbolLambda) {
|
||||
defun.def_function(node, node.name == "arguments" ? undefined : defun);
|
||||
}
|
||||
else if (node instanceof AST_SymbolVar) {
|
||||
if (node instanceof AST_SymbolDefun) {
|
||||
// This should be defined in the parent scope, as we encounter the
|
||||
// AST_Defun node before getting to its AST_Symbol.
|
||||
(node.scope = defun.parent_scope.resolve()).def_function(node, defun);
|
||||
} else if (node instanceof AST_SymbolLambda) {
|
||||
var def = defun.def_function(node, node.name == "arguments" ? undefined : defun);
|
||||
if (options.ie8) def.defun = defun.parent_scope.resolve();
|
||||
} else if (node instanceof AST_SymbolVar) {
|
||||
defun.def_variable(node, node.TYPE == "SymbolVar" ? null : undefined);
|
||||
if (defun !== scope) {
|
||||
node.mark_enclosed(options);
|
||||
@@ -153,8 +147,7 @@ AST_Toplevel.DEFMETHOD("figure_out_scope", function(options) {
|
||||
}
|
||||
node.reference(options);
|
||||
}
|
||||
}
|
||||
else if (node instanceof AST_SymbolCatch) {
|
||||
} else if (node instanceof AST_SymbolCatch) {
|
||||
scope.def_variable(node).defun = defun;
|
||||
}
|
||||
});
|
||||
@@ -162,9 +155,9 @@ AST_Toplevel.DEFMETHOD("figure_out_scope", function(options) {
|
||||
|
||||
// pass 2: find back references and eval
|
||||
self.globals = new Dictionary();
|
||||
var tw = new TreeWalker(function(node, descend) {
|
||||
if (node instanceof AST_LoopControl && node.label) {
|
||||
node.label.thedef.references.push(node);
|
||||
var tw = new TreeWalker(function(node) {
|
||||
if (node instanceof AST_LoopControl) {
|
||||
if (node.label) node.label.thedef.references.push(node);
|
||||
return true;
|
||||
}
|
||||
if (node instanceof AST_SymbolRef) {
|
||||
@@ -185,35 +178,55 @@ AST_Toplevel.DEFMETHOD("figure_out_scope", function(options) {
|
||||
return true;
|
||||
}
|
||||
// ensure mangling works if catch reuses a scope variable
|
||||
var def;
|
||||
if (node instanceof AST_SymbolCatch && (def = node.definition().redefined())) {
|
||||
var s = node.scope;
|
||||
while (s) {
|
||||
if (node instanceof AST_SymbolCatch) {
|
||||
var def = node.definition().redefined();
|
||||
if (def) for (var s = node.scope; s; s = s.parent_scope) {
|
||||
push_uniq(s.enclosed, def);
|
||||
if (s === def.scope) break;
|
||||
s = s.parent_scope;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
});
|
||||
self.walk(tw);
|
||||
|
||||
// pass 3: fix up any scoping issue with IE8
|
||||
if (options.ie8) {
|
||||
self.walk(new TreeWalker(function(node, descend) {
|
||||
if (node instanceof AST_SymbolCatch) {
|
||||
var name = node.name;
|
||||
var refs = node.thedef.references;
|
||||
var scope = node.thedef.defun;
|
||||
var def = scope.find_variable(name) || self.globals.get(name) || scope.def_variable(node);
|
||||
refs.forEach(function(ref) {
|
||||
ref.thedef = def;
|
||||
ref.reference(options);
|
||||
});
|
||||
node.thedef = def;
|
||||
node.reference(options);
|
||||
return true;
|
||||
if (options.ie8) self.walk(new TreeWalker(function(node) {
|
||||
if (node instanceof AST_SymbolCatch) {
|
||||
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;
|
||||
}
|
||||
if (node instanceof AST_SymbolLambda) {
|
||||
var def = node.thedef;
|
||||
redefine(node, node.scope.parent_scope.resolve());
|
||||
if (typeof node.thedef.init !== "undefined") {
|
||||
node.thedef.init = false;
|
||||
} else if (def.init) {
|
||||
node.thedef.init = def.init;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}));
|
||||
|
||||
function redefine(node, scope) {
|
||||
var name = node.name;
|
||||
var old_def = node.thedef;
|
||||
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) {
|
||||
node.thedef = new_def;
|
||||
node.reference(options);
|
||||
});
|
||||
if (old_def.lambda) new_def.lambda = true;
|
||||
if (new_def.undeclared) self.variables.set(name, new_def);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -252,8 +265,7 @@ AST_Lambda.DEFMETHOD("init_scope_vars", function() {
|
||||
|
||||
AST_Symbol.DEFMETHOD("mark_enclosed", function(options) {
|
||||
var def = this.definition();
|
||||
var s = this.scope;
|
||||
while (s) {
|
||||
for (var s = this.scope; s; s = s.parent_scope) {
|
||||
push_uniq(s.enclosed, def);
|
||||
if (options.keep_fnames) {
|
||||
s.functions.each(function(d) {
|
||||
@@ -261,7 +273,6 @@ AST_Symbol.DEFMETHOD("mark_enclosed", function(options) {
|
||||
});
|
||||
}
|
||||
if (s === def.scope) break;
|
||||
s = s.parent_scope;
|
||||
}
|
||||
});
|
||||
|
||||
@@ -287,9 +298,7 @@ AST_Scope.DEFMETHOD("def_variable", function(symbol, init) {
|
||||
var def = this.variables.get(symbol.name);
|
||||
if (def) {
|
||||
def.orig.push(symbol);
|
||||
if (def.init && (def.scope !== symbol.scope || def.init instanceof AST_Function)) {
|
||||
def.init = init;
|
||||
}
|
||||
if (def.init instanceof AST_Function) def.init = init;
|
||||
} else {
|
||||
def = new SymbolDef(this, symbol, init);
|
||||
this.variables.set(symbol.name, def);
|
||||
@@ -298,13 +307,23 @@ AST_Scope.DEFMETHOD("def_variable", function(symbol, init) {
|
||||
return symbol.thedef = def;
|
||||
});
|
||||
|
||||
AST_Lambda.DEFMETHOD("resolve", return_this);
|
||||
AST_Scope.DEFMETHOD("resolve", function() {
|
||||
return this.parent_scope.resolve();
|
||||
});
|
||||
AST_Toplevel.DEFMETHOD("resolve", return_this);
|
||||
|
||||
function names_in_use(scope, options) {
|
||||
var names = scope.names_in_use;
|
||||
if (!names) {
|
||||
scope.names_in_use = names = Object.create(scope.mangled_names || null);
|
||||
scope.cname_holes = [];
|
||||
var cache = options.cache && options.cache.props;
|
||||
scope.enclosed.forEach(function(def) {
|
||||
if (def.unmangleable(options)) names[def.name] = true;
|
||||
if (def.global && cache && cache.has(def.name)) {
|
||||
names[cache.get(def.name)] = true;
|
||||
}
|
||||
});
|
||||
}
|
||||
return names;
|
||||
@@ -314,14 +333,6 @@ function next_mangled_name(scope, options, def) {
|
||||
var in_use = names_in_use(scope, options);
|
||||
var holes = scope.cname_holes;
|
||||
var names = Object.create(null);
|
||||
// #179, #326
|
||||
// in Safari strict mode, something like (function x(x){...}) is a syntax error;
|
||||
// a function expression's argument cannot shadow the function expression's name
|
||||
if (scope instanceof AST_Function && scope.name && def.orig[0] instanceof AST_SymbolFunarg) {
|
||||
var tricky_def = scope.name.definition();
|
||||
// the function's mangled_name is null when keep_fnames is true
|
||||
names[tricky_def.mangled_name || tricky_def.name] = true;
|
||||
}
|
||||
var scopes = [ scope ];
|
||||
def.references.forEach(function(sym) {
|
||||
var scope = sym.scope;
|
||||
@@ -335,7 +346,7 @@ function next_mangled_name(scope, options, def) {
|
||||
} while (scope = scope.parent_scope);
|
||||
});
|
||||
var name;
|
||||
for (var i = 0, len = holes.length; i < len; i++) {
|
||||
for (var i = 0; i < holes.length; i++) {
|
||||
name = base54(holes[i]);
|
||||
if (names[name]) continue;
|
||||
holes.splice(i, 1);
|
||||
@@ -344,7 +355,7 @@ function next_mangled_name(scope, options, def) {
|
||||
}
|
||||
while (true) {
|
||||
name = base54(++scope.cname);
|
||||
if (in_use[name] || !is_identifier(name) || options.reserved.has[name]) continue;
|
||||
if (in_use[name] || RESERVED_WORDS[name] || options.reserved.has[name]) continue;
|
||||
if (!names[name]) break;
|
||||
holes.push(scope.cname);
|
||||
}
|
||||
@@ -410,40 +421,33 @@ AST_Toplevel.DEFMETHOD("mangle_names", function(options) {
|
||||
var save_nesting = lname;
|
||||
descend();
|
||||
lname = save_nesting;
|
||||
return true; // don't descend again in TreeWalker
|
||||
return true;
|
||||
}
|
||||
if (node instanceof AST_Scope) {
|
||||
descend();
|
||||
if (options.cache && node instanceof AST_Toplevel) {
|
||||
node.globals.each(mangle);
|
||||
}
|
||||
node.variables.each(mangle);
|
||||
node.variables.each(function(def) {
|
||||
if (!defer_redef(def)) mangle(def);
|
||||
});
|
||||
return true;
|
||||
}
|
||||
if (node instanceof AST_Label) {
|
||||
var name;
|
||||
do name = base54(++lname); while (!is_identifier(name));
|
||||
do {
|
||||
name = base54(++lname);
|
||||
} while (RESERVED_WORDS[name]);
|
||||
node.mangled_name = name;
|
||||
return true;
|
||||
}
|
||||
if (!options.ie8 && node instanceof AST_Catch) {
|
||||
var def = node.argname.definition();
|
||||
var redef = def.redefined();
|
||||
if (redef) {
|
||||
redefined.push(def);
|
||||
reference(node.argname);
|
||||
def.references.forEach(reference);
|
||||
}
|
||||
var redef = defer_redef(def, node.argname);
|
||||
descend();
|
||||
if (!redef) mangle(def);
|
||||
return true;
|
||||
}
|
||||
|
||||
function reference(sym) {
|
||||
sym.thedef = redef;
|
||||
sym.reference(options);
|
||||
sym.thedef = def;
|
||||
}
|
||||
});
|
||||
this.walk(tw);
|
||||
redefined.forEach(mangle);
|
||||
@@ -452,6 +456,21 @@ AST_Toplevel.DEFMETHOD("mangle_names", function(options) {
|
||||
if (options.reserved.has[def.name]) return;
|
||||
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) {
|
||||
@@ -493,7 +512,7 @@ AST_Toplevel.DEFMETHOD("expand_names", function(options) {
|
||||
var name;
|
||||
do {
|
||||
name = base54(cname++);
|
||||
} while (avoid[name] || !is_identifier(name));
|
||||
} while (avoid[name] || RESERVED_WORDS[name]);
|
||||
return name;
|
||||
}
|
||||
|
||||
@@ -501,13 +520,14 @@ AST_Toplevel.DEFMETHOD("expand_names", function(options) {
|
||||
if (def.global && options.cache) return;
|
||||
if (def.unmangleable(options)) return;
|
||||
if (options.reserved.has[def.name]) return;
|
||||
var d = def.redefined();
|
||||
def.name = d ? d.name : next_name();
|
||||
var redef = def.redefined();
|
||||
var name = redef ? redef.rename || redef.name : next_name();
|
||||
def.rename = name;
|
||||
def.orig.forEach(function(sym) {
|
||||
sym.name = def.name;
|
||||
sym.name = name;
|
||||
});
|
||||
def.references.forEach(function(sym) {
|
||||
sym.name = def.name;
|
||||
sym.name = name;
|
||||
});
|
||||
}
|
||||
});
|
||||
@@ -555,7 +575,7 @@ var base54 = (function() {
|
||||
var freq = Object.create(null);
|
||||
function init(chars) {
|
||||
var array = [];
|
||||
for (var i = 0, len = chars.length; i < len; i++) {
|
||||
for (var i = 0; i < chars.length; i++) {
|
||||
var ch = chars[i];
|
||||
array.push(ch);
|
||||
freq[ch] = -1e-2 * i;
|
||||
|
||||
16
lib/utils.js
16
lib/utils.js
@@ -70,7 +70,7 @@ function configure_error_stack(fn) {
|
||||
err.name = this.name;
|
||||
try {
|
||||
throw err;
|
||||
} catch(e) {
|
||||
} catch (e) {
|
||||
return e.stack;
|
||||
}
|
||||
}
|
||||
@@ -127,8 +127,7 @@ var MAP = (function() {
|
||||
} else {
|
||||
top.push(val);
|
||||
}
|
||||
}
|
||||
else if (val !== skip) {
|
||||
} else if (val !== skip) {
|
||||
if (val instanceof Splice) {
|
||||
ret.push.apply(ret, backwards ? val.v.slice().reverse() : val.v);
|
||||
} else {
|
||||
@@ -145,8 +144,7 @@ var MAP = (function() {
|
||||
} else {
|
||||
for (i = 0; i < a.length; ++i) if (doit()) break;
|
||||
}
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
for (i in a) if (HOP(a, i)) if (doit()) break;
|
||||
}
|
||||
return top.concat(ret);
|
||||
@@ -162,8 +160,7 @@ var MAP = (function() {
|
||||
})();
|
||||
|
||||
function push_uniq(array, el) {
|
||||
if (array.indexOf(el) < 0)
|
||||
array.push(el);
|
||||
if (array.indexOf(el) < 0) return array.push(el);
|
||||
}
|
||||
|
||||
function string_template(text, props) {
|
||||
@@ -173,9 +170,8 @@ function string_template(text, props) {
|
||||
}
|
||||
|
||||
function remove(array, el) {
|
||||
for (var i = array.length; --i >= 0;) {
|
||||
if (array[i] === el) array.splice(i, 1);
|
||||
}
|
||||
var index = array.indexOf(el);
|
||||
if (index >= 0) array.splice(index, 1);
|
||||
}
|
||||
|
||||
function makePredicate(words) {
|
||||
|
||||
10
package.json
10
package.json
@@ -3,7 +3,7 @@
|
||||
"description": "JavaScript parser, mangler/compressor and beautifier toolkit",
|
||||
"author": "Mihai Bazon <mihai.bazon@gmail.com> (http://lisperator.net/)",
|
||||
"license": "BSD-2-Clause",
|
||||
"version": "3.4.3",
|
||||
"version": "3.6.6",
|
||||
"engines": {
|
||||
"node": ">=0.8.0"
|
||||
},
|
||||
@@ -23,15 +23,15 @@
|
||||
"LICENSE"
|
||||
],
|
||||
"dependencies": {
|
||||
"commander": "~2.16.0",
|
||||
"commander": "~2.20.3",
|
||||
"source-map": "~0.6.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"acorn": "~5.7.1",
|
||||
"semver": "~5.5.0"
|
||||
"acorn": "~7.1.0",
|
||||
"semver": "~6.3.0"
|
||||
},
|
||||
"scripts": {
|
||||
"test": "node test/run-tests.js"
|
||||
"test": "node test/compress.js && node test/mocha.js"
|
||||
},
|
||||
"keywords": [
|
||||
"cli",
|
||||
|
||||
@@ -13,15 +13,15 @@ if (!args.length) {
|
||||
}
|
||||
args.push("--timings");
|
||||
var urls = [
|
||||
"https://code.jquery.com/jquery-3.2.1.js",
|
||||
"https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.6.4/angular.js",
|
||||
"https://cdnjs.cloudflare.com/ajax/libs/mathjs/3.9.0/math.js",
|
||||
"https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.js",
|
||||
"https://code.jquery.com/jquery-3.4.1.js",
|
||||
"https://code.angularjs.org/1.7.8/angular.js",
|
||||
"https://unpkg.com/mathjs@6.2.3/dist/math.js",
|
||||
"https://unpkg.com/react@15.3.2/dist/react.js",
|
||||
"http://builds.emberjs.com/tags/v2.11.0/ember.prod.js",
|
||||
"https://cdn.jsdelivr.net/lodash/4.17.4/lodash.js",
|
||||
"https://cdnjs.cloudflare.com/ajax/libs/d3/4.5.0/d3.js",
|
||||
"https://raw.githubusercontent.com/kangax/html-minifier/v3.5.7/dist/htmlminifier.js",
|
||||
"https://cdnjs.cloudflare.com/ajax/libs/d3/5.12.0/d3.js",
|
||||
"https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.js",
|
||||
"https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.15/lodash.js",
|
||||
"https://cdnjs.cloudflare.com/ajax/libs/ember.js/2.12.2/ember.prod.js",
|
||||
"https://raw.githubusercontent.com/kangax/html-minifier/v4.0.0/dist/htmlminifier.js",
|
||||
];
|
||||
var results = {};
|
||||
var remaining = 2 * urls.length;
|
||||
|
||||
454
test/compress.js
Normal file
454
test/compress.js
Normal file
@@ -0,0 +1,454 @@
|
||||
"use strict";
|
||||
|
||||
require("../tools/exit");
|
||||
|
||||
var assert = require("assert");
|
||||
var child_process = require("child_process");
|
||||
var fs = require("fs");
|
||||
var path = require("path");
|
||||
var sandbox = require("./sandbox");
|
||||
var semver = require("semver");
|
||||
var U = require("./node");
|
||||
|
||||
var file = process.argv[2];
|
||||
var dir = path.resolve(path.dirname(module.filename), "compress");
|
||||
if (file) {
|
||||
var minify_options = require("./ufuzz/options.json").map(JSON.stringify);
|
||||
log("--- {file}", { file: file });
|
||||
var tests = parse_test(path.resolve(dir, file));
|
||||
process.exit(Object.keys(tests).filter(function(name) {
|
||||
return !test_case(tests[name]);
|
||||
}).length);
|
||||
} else {
|
||||
var files = fs.readdirSync(dir).filter(function(name) {
|
||||
return /\.js$/i.test(name);
|
||||
});
|
||||
var failures = 0;
|
||||
var failed_files = Object.create(null);
|
||||
(function next() {
|
||||
var file = files.shift();
|
||||
if (file) {
|
||||
child_process.spawn(process.argv[0], [ process.argv[1], file ], {
|
||||
stdio: [ "ignore", 1, 2 ]
|
||||
}).on("exit", function(code) {
|
||||
if (code) {
|
||||
failures += code;
|
||||
failed_files[file] = code;
|
||||
}
|
||||
next();
|
||||
});
|
||||
} else if (failures) {
|
||||
console.error();
|
||||
console.error("!!! Failed " + failures + " test case(s).");
|
||||
console.error("!!! " + Object.keys(failed_files).join(", "));
|
||||
process.exit(1);
|
||||
}
|
||||
})();
|
||||
}
|
||||
|
||||
function evaluate(code) {
|
||||
if (code instanceof U.AST_Node) code = make_code(code, { beautify: true });
|
||||
return new Function("return(" + code + ")")();
|
||||
}
|
||||
|
||||
function log() {
|
||||
console.log("%s", tmpl.apply(null, arguments));
|
||||
}
|
||||
|
||||
function make_code(ast, options) {
|
||||
var stream = U.OutputStream(options);
|
||||
ast.print(stream);
|
||||
return stream.get();
|
||||
}
|
||||
|
||||
function parse_test(file) {
|
||||
var script = fs.readFileSync(file, "utf8");
|
||||
// TODO try/catch can be removed after fixing https://github.com/mishoo/UglifyJS2/issues/348
|
||||
try {
|
||||
var ast = U.parse(script, {
|
||||
filename: file
|
||||
});
|
||||
} catch (e) {
|
||||
console.error("Caught error while parsing tests in " + file);
|
||||
console.error(e);
|
||||
process.exit(1);
|
||||
}
|
||||
var tests = Object.create(null);
|
||||
var tw = new U.TreeWalker(function(node, descend) {
|
||||
if (node instanceof U.AST_LabeledStatement
|
||||
&& tw.parent() instanceof U.AST_Toplevel) {
|
||||
var name = node.label.name;
|
||||
if (name in tests) {
|
||||
throw new Error('Duplicated test name "' + name + '" in ' + file);
|
||||
}
|
||||
tests[name] = get_one_test(name, node.body);
|
||||
return true;
|
||||
}
|
||||
if (!(node instanceof U.AST_Toplevel)) croak(node);
|
||||
});
|
||||
ast.walk(tw);
|
||||
return tests;
|
||||
|
||||
function croak(node) {
|
||||
throw new Error(tmpl("Can't understand test file {file} [{line},{col}]\n{code}", {
|
||||
file: file,
|
||||
line: node.start.line,
|
||||
col: node.start.col,
|
||||
code: make_code(node, { beautify: false })
|
||||
}));
|
||||
}
|
||||
|
||||
function read_string(stat) {
|
||||
if (stat.TYPE == "SimpleStatement") {
|
||||
var body = stat.body;
|
||||
switch(body.TYPE) {
|
||||
case "String":
|
||||
return body.value;
|
||||
case "Array":
|
||||
return body.elements.map(function(element) {
|
||||
if (element.TYPE !== "String")
|
||||
throw new Error("Should be array of strings");
|
||||
return element.value;
|
||||
}).join("\n");
|
||||
}
|
||||
}
|
||||
throw new Error("Should be string or array of strings");
|
||||
}
|
||||
|
||||
function get_one_test(name, block) {
|
||||
var test = { name: name, options: {} };
|
||||
var tw = new U.TreeWalker(function(node, descend) {
|
||||
if (node instanceof U.AST_Assign) {
|
||||
if (!(node.left instanceof U.AST_SymbolRef)) {
|
||||
croak(node);
|
||||
}
|
||||
var name = node.left.name;
|
||||
test[name] = evaluate(node.right);
|
||||
return true;
|
||||
}
|
||||
if (node instanceof U.AST_LabeledStatement) {
|
||||
var label = node.label;
|
||||
assert.ok([
|
||||
"input",
|
||||
"expect",
|
||||
"expect_exact",
|
||||
"expect_warnings",
|
||||
"expect_stdout",
|
||||
"node_version",
|
||||
].indexOf(label.name) >= 0, tmpl("Unsupported label {name} [{line},{col}]", {
|
||||
name: label.name,
|
||||
line: label.start.line,
|
||||
col: label.start.col
|
||||
}));
|
||||
var stat = node.body;
|
||||
if (label.name == "expect_exact" || label.name == "node_version") {
|
||||
test[label.name] = read_string(stat);
|
||||
} else if (label.name == "expect_stdout") {
|
||||
var body = stat.body;
|
||||
if (body instanceof U.AST_Boolean) {
|
||||
test[label.name] = body.value;
|
||||
} else if (body instanceof U.AST_Call) {
|
||||
var ctor = global[body.expression.name];
|
||||
assert.ok(ctor === Error || ctor.prototype instanceof Error, tmpl("Unsupported expect_stdout format [{line},{col}]", {
|
||||
line: label.start.line,
|
||||
col: label.start.col
|
||||
}));
|
||||
test[label.name] = ctor.apply(null, body.args.map(function(node) {
|
||||
assert.ok(node instanceof U.AST_Constant, tmpl("Unsupported expect_stdout format [{line},{col}]", {
|
||||
line: label.start.line,
|
||||
col: label.start.col
|
||||
}));
|
||||
return node.value;
|
||||
}));
|
||||
} else {
|
||||
test[label.name] = read_string(stat) + "\n";
|
||||
}
|
||||
} else {
|
||||
test[label.name] = stat;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
});
|
||||
block.walk(tw);
|
||||
return test;
|
||||
}
|
||||
}
|
||||
|
||||
// Try to reminify original input with standard options
|
||||
// to see if it matches expect_stdout.
|
||||
function reminify(orig_options, input_code, input_formatted, stdout) {
|
||||
for (var i = 0; i < minify_options.length; i++) {
|
||||
var options = JSON.parse(minify_options[i]);
|
||||
if (options.compress) [
|
||||
"keep_fargs",
|
||||
"keep_fnames",
|
||||
].forEach(function(name) {
|
||||
if (name in orig_options) {
|
||||
options.compress[name] = orig_options[name];
|
||||
}
|
||||
});
|
||||
var options_formatted = JSON.stringify(options, null, 4);
|
||||
var result = U.minify(input_code, options);
|
||||
if (result.error) {
|
||||
log([
|
||||
"!!! failed input reminify",
|
||||
"---INPUT---",
|
||||
"{input}",
|
||||
"---OPTIONS---",
|
||||
"{options}",
|
||||
"--ERROR---",
|
||||
"{error}",
|
||||
"",
|
||||
"",
|
||||
].join("\n"), {
|
||||
input: input_formatted,
|
||||
options: options_formatted,
|
||||
error: result.error,
|
||||
});
|
||||
return false;
|
||||
} else {
|
||||
var expected = stdout[options.toplevel ? 1 : 0];
|
||||
var actual = run_code(result.code, options.toplevel);
|
||||
if (typeof expected != "string" && typeof actual != "string" && expected.name == actual.name) {
|
||||
actual = expected;
|
||||
}
|
||||
if (!sandbox.same_stdout(expected, actual)) {
|
||||
log([
|
||||
"!!! failed running reminified input",
|
||||
"---INPUT---",
|
||||
"{input}",
|
||||
"---OPTIONS---",
|
||||
"{options}",
|
||||
"---OUTPUT---",
|
||||
"{output}",
|
||||
"---EXPECTED {expected_type}---",
|
||||
"{expected}",
|
||||
"---ACTUAL {actual_type}---",
|
||||
"{actual}",
|
||||
"",
|
||||
"",
|
||||
].join("\n"), {
|
||||
input: input_formatted,
|
||||
options: options_formatted,
|
||||
output: result.code,
|
||||
expected_type: typeof expected == "string" ? "STDOUT" : "ERROR",
|
||||
expected: expected,
|
||||
actual_type: typeof actual == "string" ? "STDOUT" : "ERROR",
|
||||
actual: actual,
|
||||
});
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
function run_code(code, toplevel) {
|
||||
var result = sandbox.run_code(code, toplevel);
|
||||
return typeof result == "string" ? result.replace(/\u001b\[\d+m/g, "") : result;
|
||||
}
|
||||
|
||||
function test_case(test) {
|
||||
log(" Running test [{name}]", { name: test.name });
|
||||
var output_options = test.beautify || {};
|
||||
var expect;
|
||||
if (test.expect) {
|
||||
expect = make_code(to_toplevel(test.expect, test.mangle), output_options);
|
||||
} else {
|
||||
expect = test.expect_exact;
|
||||
}
|
||||
var input = to_toplevel(test.input, test.mangle);
|
||||
var input_code = make_code(input);
|
||||
var input_formatted = make_code(test.input, {
|
||||
beautify: true,
|
||||
comments: "all",
|
||||
keep_quoted_props: true,
|
||||
quote_style: 3,
|
||||
});
|
||||
try {
|
||||
U.parse(input_code);
|
||||
} catch (ex) {
|
||||
log([
|
||||
"!!! Cannot parse input",
|
||||
"---INPUT---",
|
||||
"{input}",
|
||||
"--PARSE ERROR--",
|
||||
"{error}",
|
||||
"",
|
||||
"",
|
||||
].join("\n"), {
|
||||
input: input_formatted,
|
||||
error: ex,
|
||||
});
|
||||
return false;
|
||||
}
|
||||
var warnings_emitted = [];
|
||||
if (test.expect_warnings) {
|
||||
var expected_warnings = make_code(test.expect_warnings, {
|
||||
beautify: false,
|
||||
quote_style: 2, // force double quote to match JSON
|
||||
});
|
||||
U.AST_Node.log_function(function(text) {
|
||||
warnings_emitted.push(text);
|
||||
}, /"INFO: /.test(expected_warnings));
|
||||
}
|
||||
if (test.mangle && test.mangle.properties && test.mangle.properties.keep_quoted) {
|
||||
var quoted_props = test.mangle.properties.reserved;
|
||||
if (!Array.isArray(quoted_props)) quoted_props = [];
|
||||
test.mangle.properties.reserved = quoted_props;
|
||||
U.reserve_quoted_keys(input, quoted_props);
|
||||
}
|
||||
if (test.rename) {
|
||||
input.figure_out_scope(test.mangle);
|
||||
input.expand_names(test.mangle);
|
||||
}
|
||||
var cmp = new U.Compressor(test.options, true);
|
||||
var output = cmp.compress(input);
|
||||
output.figure_out_scope(test.mangle);
|
||||
if (test.mangle) {
|
||||
output.compute_char_frequency(test.mangle);
|
||||
output.mangle_names(test.mangle);
|
||||
if (test.mangle.properties) {
|
||||
output = U.mangle_properties(output, test.mangle.properties);
|
||||
}
|
||||
}
|
||||
output = make_code(output, output_options);
|
||||
if (expect != output) {
|
||||
log([
|
||||
"!!! failed",
|
||||
"---INPUT---",
|
||||
"{input}",
|
||||
"---OUTPUT---",
|
||||
"{output}",
|
||||
"---EXPECTED---",
|
||||
"{expected}",
|
||||
"",
|
||||
"",
|
||||
].join("\n"), {
|
||||
input: input_formatted,
|
||||
output: output,
|
||||
expected: expect
|
||||
});
|
||||
return false;
|
||||
}
|
||||
// expect == output
|
||||
try {
|
||||
U.parse(output);
|
||||
} catch (ex) {
|
||||
log([
|
||||
"!!! Test matched expected result but cannot parse output",
|
||||
"---INPUT---",
|
||||
"{input}",
|
||||
"---OUTPUT---",
|
||||
"{output}",
|
||||
"--REPARSE ERROR--",
|
||||
"{error}",
|
||||
"",
|
||||
"",
|
||||
].join("\n"), {
|
||||
input: input_formatted,
|
||||
output: output,
|
||||
error: ex,
|
||||
});
|
||||
return false;
|
||||
}
|
||||
if (test.expect_warnings) {
|
||||
warnings_emitted = warnings_emitted.map(function(input) {
|
||||
return input.split(process.cwd() + path.sep).join("").split(path.sep).join("/");
|
||||
});
|
||||
var actual_warnings = JSON.stringify(warnings_emitted);
|
||||
if (expected_warnings != actual_warnings) {
|
||||
log([
|
||||
"!!! failed",
|
||||
"---INPUT---",
|
||||
"{input}",
|
||||
"---EXPECTED WARNINGS---",
|
||||
"{expected_warnings}",
|
||||
"---ACTUAL WARNINGS---",
|
||||
"{actual_warnings}",
|
||||
"",
|
||||
"",
|
||||
].join("\n"), {
|
||||
input: input_formatted,
|
||||
expected_warnings: expected_warnings,
|
||||
actual_warnings: actual_warnings,
|
||||
});
|
||||
return false;
|
||||
}
|
||||
}
|
||||
if (test.expect_stdout && (!test.node_version || semver.satisfies(process.version, test.node_version))) {
|
||||
var stdout = [ run_code(input_code), run_code(input_code, true) ];
|
||||
var toplevel = test.options.toplevel;
|
||||
var actual = stdout[toplevel ? 1 : 0];
|
||||
if (test.expect_stdout === true) {
|
||||
test.expect_stdout = actual;
|
||||
}
|
||||
if (!sandbox.same_stdout(test.expect_stdout, actual)) {
|
||||
log([
|
||||
"!!! Invalid input or expected stdout",
|
||||
"---INPUT---",
|
||||
"{input}",
|
||||
"---EXPECTED {expected_type}---",
|
||||
"{expected}",
|
||||
"---ACTUAL {actual_type}---",
|
||||
"{actual}",
|
||||
"",
|
||||
"",
|
||||
].join("\n"), {
|
||||
input: input_formatted,
|
||||
expected_type: typeof test.expect_stdout == "string" ? "STDOUT" : "ERROR",
|
||||
expected: test.expect_stdout,
|
||||
actual_type: typeof actual == "string" ? "STDOUT" : "ERROR",
|
||||
actual: actual,
|
||||
});
|
||||
return false;
|
||||
}
|
||||
actual = run_code(output, toplevel);
|
||||
if (!sandbox.same_stdout(test.expect_stdout, actual)) {
|
||||
log([
|
||||
"!!! failed",
|
||||
"---INPUT---",
|
||||
"{input}",
|
||||
"---EXPECTED {expected_type}---",
|
||||
"{expected}",
|
||||
"---ACTUAL {actual_type}---",
|
||||
"{actual}",
|
||||
"",
|
||||
"",
|
||||
].join("\n"), {
|
||||
input: input_formatted,
|
||||
expected_type: typeof test.expect_stdout == "string" ? "STDOUT" : "ERROR",
|
||||
expected: test.expect_stdout,
|
||||
actual_type: typeof actual == "string" ? "STDOUT" : "ERROR",
|
||||
actual: actual,
|
||||
});
|
||||
return false;
|
||||
}
|
||||
if (!reminify(test.options, input_code, input_formatted, stdout)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
function tmpl() {
|
||||
return U.string_template.apply(null, arguments);
|
||||
}
|
||||
|
||||
function to_toplevel(input, mangle_options) {
|
||||
if (!(input instanceof U.AST_BlockStatement)) throw new Error("Unsupported input syntax");
|
||||
var directive = true;
|
||||
var offset = input.start.line;
|
||||
var tokens = [];
|
||||
var toplevel = new U.AST_Toplevel(input.transform(new U.TreeTransformer(function(node) {
|
||||
if (U.push_uniq(tokens, node.start)) node.start.line -= offset;
|
||||
if (!directive || node === input) return;
|
||||
if (node instanceof U.AST_SimpleStatement && node.body instanceof U.AST_String) {
|
||||
return new U.AST_Directive(node.body);
|
||||
} else {
|
||||
directive = false;
|
||||
}
|
||||
})));
|
||||
toplevel.figure_out_scope(mangle_options);
|
||||
return toplevel;
|
||||
}
|
||||
@@ -237,3 +237,542 @@ duplicate_argname: {
|
||||
}
|
||||
expect_stdout: "bar 42 foo 42 bar"
|
||||
}
|
||||
|
||||
issue_3273: {
|
||||
options = {
|
||||
arguments: true,
|
||||
}
|
||||
input: {
|
||||
function f(a) {
|
||||
console.log(arguments[0], a);
|
||||
arguments[0]++;
|
||||
console.log(arguments[0], a);
|
||||
}
|
||||
f(0);
|
||||
}
|
||||
expect: {
|
||||
function f(a) {
|
||||
console.log(a, a);
|
||||
a++;
|
||||
console.log(a, a);
|
||||
}
|
||||
f(0);
|
||||
}
|
||||
expect_stdout: [
|
||||
"0 0",
|
||||
"1 1",
|
||||
]
|
||||
}
|
||||
|
||||
issue_3273_reduce_vars: {
|
||||
options = {
|
||||
arguments: true,
|
||||
reduce_vars: true,
|
||||
}
|
||||
input: {
|
||||
function f(a) {
|
||||
console.log(arguments[0], a);
|
||||
arguments[0]++;
|
||||
console.log(arguments[0], a);
|
||||
}
|
||||
f(0);
|
||||
}
|
||||
expect: {
|
||||
function f(a) {
|
||||
console.log(a, a);
|
||||
a++;
|
||||
console.log(a, a);
|
||||
}
|
||||
f(0);
|
||||
}
|
||||
expect_stdout: [
|
||||
"0 0",
|
||||
"1 1",
|
||||
]
|
||||
}
|
||||
|
||||
issue_3273_local_strict: {
|
||||
options = {
|
||||
arguments: true,
|
||||
}
|
||||
input: {
|
||||
function f(a) {
|
||||
"use strict";
|
||||
console.log(arguments[0], a);
|
||||
arguments[0]++;
|
||||
console.log(arguments[0], a);
|
||||
}
|
||||
f(0);
|
||||
}
|
||||
expect: {
|
||||
function f(a) {
|
||||
"use strict";
|
||||
console.log(arguments[0], a);
|
||||
arguments[0]++;
|
||||
console.log(arguments[0], a);
|
||||
}
|
||||
f(0);
|
||||
}
|
||||
expect_stdout: [
|
||||
"0 0",
|
||||
"1 0",
|
||||
]
|
||||
}
|
||||
|
||||
issue_3273_local_strict_reduce_vars: {
|
||||
options = {
|
||||
arguments: true,
|
||||
reduce_vars: true,
|
||||
}
|
||||
input: {
|
||||
function f(a) {
|
||||
"use strict";
|
||||
console.log(arguments[0], a);
|
||||
arguments[0]++;
|
||||
console.log(arguments[0], a);
|
||||
}
|
||||
f(0);
|
||||
}
|
||||
expect: {
|
||||
function f(a) {
|
||||
"use strict";
|
||||
console.log(arguments[0], a);
|
||||
arguments[0]++;
|
||||
console.log(arguments[0], a);
|
||||
}
|
||||
f(0);
|
||||
}
|
||||
expect_stdout: [
|
||||
"0 0",
|
||||
"1 0",
|
||||
]
|
||||
}
|
||||
|
||||
issue_3273_global_strict: {
|
||||
options = {
|
||||
arguments: true,
|
||||
}
|
||||
input: {
|
||||
"use strict";
|
||||
function f(a) {
|
||||
console.log(arguments[0], a);
|
||||
arguments[0]++;
|
||||
console.log(arguments[0], a);
|
||||
}
|
||||
f(0);
|
||||
}
|
||||
expect: {
|
||||
"use strict";
|
||||
function f(a) {
|
||||
console.log(arguments[0], a);
|
||||
arguments[0]++;
|
||||
console.log(arguments[0], a);
|
||||
}
|
||||
f(0);
|
||||
}
|
||||
expect_stdout: [
|
||||
"0 0",
|
||||
"1 0",
|
||||
]
|
||||
}
|
||||
|
||||
issue_3273_global_strict_reduce_vars: {
|
||||
options = {
|
||||
arguments: true,
|
||||
reduce_vars: true,
|
||||
}
|
||||
input: {
|
||||
"use strict";
|
||||
function f(a) {
|
||||
console.log(arguments[0], a);
|
||||
arguments[0]++;
|
||||
console.log(arguments[0], a);
|
||||
}
|
||||
f(0);
|
||||
}
|
||||
expect: {
|
||||
"use strict";
|
||||
function f(a) {
|
||||
console.log(arguments[0], a);
|
||||
arguments[0]++;
|
||||
console.log(arguments[0], a);
|
||||
}
|
||||
f(0);
|
||||
}
|
||||
expect_stdout: [
|
||||
"0 0",
|
||||
"1 0",
|
||||
]
|
||||
}
|
||||
|
||||
issue_3273_keep_fargs_false: {
|
||||
options = {
|
||||
arguments: true,
|
||||
keep_fargs: false,
|
||||
reduce_vars: true,
|
||||
}
|
||||
input: {
|
||||
(function() {
|
||||
"use strict";
|
||||
arguments[0]++;
|
||||
console.log(arguments[0]);
|
||||
})(0);
|
||||
}
|
||||
expect: {
|
||||
(function(argument_0) {
|
||||
"use strict";
|
||||
argument_0++;
|
||||
console.log(argument_0);
|
||||
})(0);
|
||||
}
|
||||
expect_stdout: "1"
|
||||
}
|
||||
|
||||
issue_3273_keep_fargs_strict: {
|
||||
options = {
|
||||
arguments: true,
|
||||
keep_fargs: "strict",
|
||||
reduce_vars: true,
|
||||
}
|
||||
input: {
|
||||
(function() {
|
||||
"use strict";
|
||||
arguments[0]++;
|
||||
console.log(arguments[0]);
|
||||
})(0);
|
||||
}
|
||||
expect: {
|
||||
(function(argument_0) {
|
||||
"use strict";
|
||||
argument_0++;
|
||||
console.log(argument_0);
|
||||
})(0);
|
||||
}
|
||||
expect_stdout: "1"
|
||||
}
|
||||
|
||||
issue_3282_1: {
|
||||
options = {
|
||||
arguments: true,
|
||||
reduce_funcs: true,
|
||||
reduce_vars: true,
|
||||
keep_fargs: false,
|
||||
unused: true,
|
||||
}
|
||||
input: {
|
||||
(function(t) {
|
||||
return function() {
|
||||
t();
|
||||
};
|
||||
})(function() {
|
||||
'use strict';
|
||||
function e() {
|
||||
return arguments[0];
|
||||
}
|
||||
e();
|
||||
e();
|
||||
})();
|
||||
}
|
||||
expect: {
|
||||
(function() {
|
||||
return function() {
|
||||
(function() {
|
||||
"use strict";
|
||||
function e() {
|
||||
return arguments[0];
|
||||
}
|
||||
e();
|
||||
e();
|
||||
})();
|
||||
};
|
||||
})()();
|
||||
}
|
||||
expect_stdout: true
|
||||
}
|
||||
|
||||
issue_3282_1_passes: {
|
||||
options = {
|
||||
arguments: true,
|
||||
passes: 2,
|
||||
reduce_funcs: true,
|
||||
reduce_vars: true,
|
||||
keep_fargs: false,
|
||||
unused: true,
|
||||
}
|
||||
input: {
|
||||
(function(t) {
|
||||
return function() {
|
||||
t();
|
||||
};
|
||||
})(function() {
|
||||
'use strict';
|
||||
function e() {
|
||||
return arguments[0];
|
||||
}
|
||||
e();
|
||||
e();
|
||||
})();
|
||||
}
|
||||
expect: {
|
||||
(function() {
|
||||
return function() {
|
||||
(function() {
|
||||
"use strict";
|
||||
function e(argument_0) {
|
||||
return argument_0;
|
||||
}
|
||||
e();
|
||||
e();
|
||||
})();
|
||||
};
|
||||
})()();
|
||||
}
|
||||
expect_stdout: true
|
||||
}
|
||||
|
||||
issue_3282_2: {
|
||||
options = {
|
||||
arguments: true,
|
||||
reduce_vars: true,
|
||||
keep_fargs: false,
|
||||
unused: true,
|
||||
}
|
||||
input: {
|
||||
(function(f) {
|
||||
f();
|
||||
})(function() {
|
||||
return (function(t) {
|
||||
return function() {
|
||||
t();
|
||||
};
|
||||
})(function() {
|
||||
'use strict';
|
||||
function e() {
|
||||
return arguments[0];
|
||||
}
|
||||
e();
|
||||
e();
|
||||
})();
|
||||
});
|
||||
}
|
||||
expect: {
|
||||
(function() {
|
||||
(function() {
|
||||
return function(t) {
|
||||
return function() {
|
||||
t();
|
||||
};
|
||||
}(function() {
|
||||
"use strict";
|
||||
function e() {
|
||||
return arguments[0];
|
||||
}
|
||||
e();
|
||||
e();
|
||||
})();
|
||||
})();
|
||||
})();
|
||||
}
|
||||
expect_stdout: true
|
||||
}
|
||||
|
||||
issue_3282_2_passes: {
|
||||
options = {
|
||||
arguments: true,
|
||||
passes: 2,
|
||||
reduce_vars: true,
|
||||
keep_fargs: false,
|
||||
unused: true,
|
||||
}
|
||||
input: {
|
||||
(function(f) {
|
||||
f();
|
||||
})(function() {
|
||||
return (function(t) {
|
||||
return function() {
|
||||
t();
|
||||
};
|
||||
})(function() {
|
||||
'use strict';
|
||||
function e() {
|
||||
return arguments[0];
|
||||
}
|
||||
e();
|
||||
e();
|
||||
})();
|
||||
});
|
||||
}
|
||||
expect: {
|
||||
(function() {
|
||||
(function() {
|
||||
return function(t) {
|
||||
return function() {
|
||||
t();
|
||||
};
|
||||
}(function() {
|
||||
"use strict";
|
||||
function e(argument_0) {
|
||||
return argument_0;
|
||||
}
|
||||
e();
|
||||
e();
|
||||
})();
|
||||
})();
|
||||
})();
|
||||
}
|
||||
expect_stdout: true
|
||||
}
|
||||
|
||||
issue_3420_1: {
|
||||
options = {
|
||||
arguments: true,
|
||||
keep_fargs: "strict",
|
||||
}
|
||||
input: {
|
||||
console.log(function() {
|
||||
return function() {
|
||||
return arguments[0];
|
||||
};
|
||||
}().length);
|
||||
}
|
||||
expect: {
|
||||
console.log(function() {
|
||||
return function() {
|
||||
return arguments[0];
|
||||
};
|
||||
}().length);
|
||||
}
|
||||
expect_stdout: "0"
|
||||
}
|
||||
|
||||
issue_3420_2: {
|
||||
options = {
|
||||
arguments: true,
|
||||
keep_fargs: "strict",
|
||||
}
|
||||
input: {
|
||||
var foo = function() {
|
||||
delete arguments[0];
|
||||
};
|
||||
foo();
|
||||
}
|
||||
expect: {
|
||||
var foo = function() {
|
||||
delete arguments[0];
|
||||
};
|
||||
foo();
|
||||
}
|
||||
expect_stdout: true
|
||||
}
|
||||
|
||||
issue_3420_3: {
|
||||
options = {
|
||||
arguments: true,
|
||||
keep_fargs: "strict",
|
||||
}
|
||||
input: {
|
||||
"use strict";
|
||||
var foo = function() {
|
||||
delete arguments[0];
|
||||
};
|
||||
foo();
|
||||
}
|
||||
expect: {
|
||||
"use strict";
|
||||
var foo = function() {
|
||||
delete arguments[0];
|
||||
};
|
||||
foo();
|
||||
}
|
||||
expect_stdout: true
|
||||
}
|
||||
|
||||
issue_3420_4: {
|
||||
options = {
|
||||
arguments: true,
|
||||
keep_fargs: "strict",
|
||||
}
|
||||
input: {
|
||||
!function() {
|
||||
console.log(arguments[0]);
|
||||
delete arguments[0];
|
||||
console.log(arguments[0]);
|
||||
}(42);
|
||||
}
|
||||
expect: {
|
||||
!function(argument_0) {
|
||||
console.log(argument_0);
|
||||
delete arguments[0];
|
||||
console.log(arguments[0]);
|
||||
}(42);
|
||||
}
|
||||
expect_stdout: [
|
||||
"42",
|
||||
"undefined",
|
||||
]
|
||||
}
|
||||
|
||||
issue_3420_5: {
|
||||
options = {
|
||||
arguments: true,
|
||||
keep_fargs: "strict",
|
||||
}
|
||||
input: {
|
||||
"use strict";
|
||||
!function() {
|
||||
console.log(arguments[0]);
|
||||
delete arguments[0];
|
||||
console.log(arguments[0]);
|
||||
}(42);
|
||||
}
|
||||
expect: {
|
||||
"use strict";
|
||||
!function(argument_0) {
|
||||
console.log(argument_0);
|
||||
delete arguments[0];
|
||||
console.log(arguments[0]);
|
||||
}(42);
|
||||
}
|
||||
expect_stdout: [
|
||||
"42",
|
||||
"undefined",
|
||||
]
|
||||
}
|
||||
|
||||
issue_3420_6: {
|
||||
options = {
|
||||
arguments: true,
|
||||
keep_fargs: "strict",
|
||||
}
|
||||
input: {
|
||||
console.log(function() {
|
||||
return delete arguments[0];
|
||||
}());
|
||||
}
|
||||
expect: {
|
||||
console.log(function() {
|
||||
return delete arguments[0];
|
||||
}());
|
||||
}
|
||||
expect_stdout: "true"
|
||||
}
|
||||
|
||||
issue_3420_7: {
|
||||
options = {
|
||||
arguments: true,
|
||||
keep_fargs: "strict",
|
||||
}
|
||||
input: {
|
||||
"use strict";
|
||||
console.log(function() {
|
||||
return delete arguments[0];
|
||||
}());
|
||||
}
|
||||
expect: {
|
||||
"use strict";
|
||||
console.log(function() {
|
||||
return delete arguments[0];
|
||||
}());
|
||||
}
|
||||
expect_stdout: "true"
|
||||
}
|
||||
|
||||
@@ -239,3 +239,113 @@ index_length: {
|
||||
}
|
||||
expect_stdout: "1 2"
|
||||
}
|
||||
|
||||
constructor_bad: {
|
||||
options = {
|
||||
unsafe: true
|
||||
}
|
||||
input: {
|
||||
try {
|
||||
Array(NaN);
|
||||
console.log("FAIL1");
|
||||
} catch (ex) {
|
||||
try {
|
||||
new Array(NaN);
|
||||
console.log("FAIL2");
|
||||
} catch (ex) {
|
||||
console.log("PASS");
|
||||
}
|
||||
}
|
||||
try {
|
||||
Array(3.14);
|
||||
console.log("FAIL1");
|
||||
} catch (ex) {
|
||||
try {
|
||||
new Array(3.14);
|
||||
console.log("FAIL2");
|
||||
} catch (ex) {
|
||||
console.log("PASS");
|
||||
}
|
||||
}
|
||||
}
|
||||
expect: {
|
||||
try {
|
||||
Array(NaN);
|
||||
console.log("FAIL1");
|
||||
} catch (ex) {
|
||||
try {
|
||||
Array(NaN);
|
||||
console.log("FAIL2");
|
||||
} catch (ex) {
|
||||
console.log("PASS");
|
||||
}
|
||||
}
|
||||
try {
|
||||
Array(3.14);
|
||||
console.log("FAIL1");
|
||||
} catch (ex) {
|
||||
try {
|
||||
Array(3.14);
|
||||
console.log("FAIL2");
|
||||
} catch (ex) {
|
||||
console.log("PASS");
|
||||
}
|
||||
}
|
||||
}
|
||||
expect_stdout: [
|
||||
"PASS",
|
||||
"PASS",
|
||||
]
|
||||
expect_warnings: [
|
||||
"WARN: Invalid array length: 3.14 [test/compress/arrays.js:13,12]",
|
||||
"WARN: Invalid array length: 3.14 [test/compress/arrays.js:17,16]",
|
||||
]
|
||||
}
|
||||
|
||||
constructor_good: {
|
||||
options = {
|
||||
unsafe: true
|
||||
}
|
||||
input: {
|
||||
console.log(Array());
|
||||
console.log(Array(0));
|
||||
console.log(Array(1));
|
||||
console.log(Array(6));
|
||||
console.log(Array(7));
|
||||
console.log(Array(1, 2));
|
||||
console.log(Array(false));
|
||||
console.log(Array("foo"));
|
||||
console.log(Array(Array));
|
||||
console.log(new Array());
|
||||
console.log(new Array(0));
|
||||
console.log(new Array(1));
|
||||
console.log(new Array(6));
|
||||
console.log(new Array(7));
|
||||
console.log(new Array(1, 2));
|
||||
console.log(new Array(false));
|
||||
console.log(new Array("foo"));
|
||||
console.log(new Array(Array));
|
||||
}
|
||||
expect: {
|
||||
console.log([]);
|
||||
console.log([]);
|
||||
console.log([,]);
|
||||
console.log([,,,,,,]);
|
||||
console.log(Array(7));
|
||||
console.log([ 1, 2 ]);
|
||||
console.log([ false ]);
|
||||
console.log([ "foo" ]);
|
||||
console.log(Array(Array));
|
||||
console.log([]);
|
||||
console.log([]);
|
||||
console.log([,]);
|
||||
console.log([,,,,,,]);
|
||||
console.log(Array(7));
|
||||
console.log([ 1, 2 ]);
|
||||
console.log([ false ]);
|
||||
console.log([ "foo" ]);
|
||||
console.log(Array(Array));
|
||||
}
|
||||
expect_stdout: true
|
||||
expect_warnings: []
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
asm_mixed: {
|
||||
options = {
|
||||
assignments: true,
|
||||
booleans: true,
|
||||
comparisons: true,
|
||||
conditionals: true,
|
||||
@@ -95,7 +96,7 @@ asm_mixed: {
|
||||
return +sum;
|
||||
}
|
||||
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);
|
||||
return { geometricMean: geometricMean };
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
op_equals_left_local_var: {
|
||||
options = {
|
||||
assignments: true,
|
||||
evaluate: true,
|
||||
}
|
||||
input: {
|
||||
@@ -60,6 +61,7 @@ op_equals_left_local_var: {
|
||||
|
||||
op_equals_right_local_var: {
|
||||
options = {
|
||||
assignments: true,
|
||||
evaluate: true,
|
||||
}
|
||||
input: {
|
||||
@@ -123,6 +125,7 @@ op_equals_right_local_var: {
|
||||
}
|
||||
op_equals_left_global_var: {
|
||||
options = {
|
||||
assignments: true,
|
||||
evaluate: true,
|
||||
}
|
||||
input: {
|
||||
@@ -179,6 +182,7 @@ op_equals_left_global_var: {
|
||||
|
||||
op_equals_right_global_var: {
|
||||
options = {
|
||||
assignments: true,
|
||||
evaluate: true,
|
||||
}
|
||||
input: {
|
||||
@@ -236,3 +240,136 @@ op_equals_right_global_var: {
|
||||
x = g() & x;
|
||||
}
|
||||
}
|
||||
|
||||
increment_decrement_1: {
|
||||
options = {
|
||||
assignments: true,
|
||||
reduce_vars: true,
|
||||
}
|
||||
input: {
|
||||
console.log(function(a) {
|
||||
a += 1;
|
||||
a -= 1;
|
||||
return a;
|
||||
}(42));
|
||||
}
|
||||
expect: {
|
||||
console.log(function(a){
|
||||
++a;
|
||||
--a;
|
||||
return a;
|
||||
}(42));
|
||||
}
|
||||
expect_stdout: "42"
|
||||
}
|
||||
|
||||
increment_decrement_2: {
|
||||
options = {
|
||||
assignments: true,
|
||||
passes: 2,
|
||||
reduce_vars: true,
|
||||
}
|
||||
input: {
|
||||
console.log(function(a) {
|
||||
a = a + 1;
|
||||
a = a - 1;
|
||||
a += 1;
|
||||
a -= 1;
|
||||
return a;
|
||||
}(42));
|
||||
}
|
||||
expect: {
|
||||
console.log(function(a){
|
||||
++a;
|
||||
--a;
|
||||
++a;
|
||||
--a;
|
||||
return a;
|
||||
}(42));
|
||||
}
|
||||
expect_stdout: "42"
|
||||
}
|
||||
|
||||
issue_3375: {
|
||||
options = {
|
||||
assignments: true,
|
||||
reduce_vars: true,
|
||||
}
|
||||
input: {
|
||||
console.log(typeof function(b) {
|
||||
var a = b += 1;
|
||||
--b;
|
||||
return a;
|
||||
}("object"));
|
||||
}
|
||||
expect: {
|
||||
console.log(typeof function(b) {
|
||||
var a = b += 1;
|
||||
--b;
|
||||
return a;
|
||||
}("object"));
|
||||
}
|
||||
expect_stdout: "string"
|
||||
}
|
||||
|
||||
issue_3427: {
|
||||
options = {
|
||||
assignments: true,
|
||||
sequences: true,
|
||||
side_effects: true,
|
||||
unused: true,
|
||||
}
|
||||
input: {
|
||||
(function() {
|
||||
var a;
|
||||
a || (a = {});
|
||||
})();
|
||||
}
|
||||
expect: {}
|
||||
}
|
||||
|
||||
issue_3429_1: {
|
||||
options = {
|
||||
assignments: true,
|
||||
side_effects: true,
|
||||
unused: true,
|
||||
}
|
||||
input: {
|
||||
var a = "PASS";
|
||||
(function(b) {
|
||||
b && (b = a = "FAIL");
|
||||
})();
|
||||
console.log(a);
|
||||
}
|
||||
expect: {
|
||||
var a = "PASS";
|
||||
(function(b) {
|
||||
b = b && (a = "FAIL");
|
||||
})();
|
||||
console.log(a);
|
||||
}
|
||||
expect_stdout: "PASS"
|
||||
}
|
||||
|
||||
issue_3429_2: {
|
||||
options = {
|
||||
assignments: true,
|
||||
side_effects: true,
|
||||
unused: true,
|
||||
}
|
||||
input: {
|
||||
var a;
|
||||
(function(b) {
|
||||
b || (b = a = "FAIL");
|
||||
})(42);
|
||||
console.log(a);
|
||||
}
|
||||
expect: {
|
||||
var a;
|
||||
(function(b) {
|
||||
b = b || (a = "FAIL");
|
||||
})(42);
|
||||
console.log(a);
|
||||
}
|
||||
expect_stdout: "undefined"
|
||||
}
|
||||
|
||||
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"
|
||||
}
|
||||
@@ -944,10 +944,10 @@ collapse_vars_misc1: {
|
||||
function f5(x) { var z = foo(); return (5 - window.x) / z }
|
||||
function f6() { return window.a * window.z && zap() }
|
||||
function f7() { var b = window.a * window.z; return b + b }
|
||||
function f8() { var b = window.a * window.z; return b + (b + 5) }
|
||||
function f8() { var b = window.a * window.z; return b + (5 + b) }
|
||||
function f9() { var b = window.a * window.z; return bar() || b }
|
||||
function f10(x) { var a = 5; return a += 3; }
|
||||
function f11(x) { var a = 5, b = 3; return a += --b; }
|
||||
function f11(x) { var a = 5; return a += 2; }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3497,10 +3497,10 @@ issue_2437_1: {
|
||||
return Object.defineProperty(XMLHttpRequest.prototype, "onreadystatechange", xhrDesc || {}),
|
||||
result;
|
||||
}
|
||||
var req, detectFunc = function(){};
|
||||
(req = new XMLHttpRequest()).onreadystatechange = detectFunc;
|
||||
result = req[SYMBOL_FAKE_ONREADYSTATECHANGE_1] === detectFunc;
|
||||
return req.onreadystatechange = null, result;
|
||||
var req = new XMLHttpRequest(), detectFunc = function(){};
|
||||
return req.onreadystatechange = detectFunc,
|
||||
result = req[SYMBOL_FAKE_ONREADYSTATECHANGE_1] === detectFunc,
|
||||
req.onreadystatechange = null, result;
|
||||
}());
|
||||
}
|
||||
}
|
||||
@@ -3511,7 +3511,7 @@ issue_2437_2: {
|
||||
conditionals: true,
|
||||
inline: true,
|
||||
join_vars: true,
|
||||
passes: 2,
|
||||
passes: 3,
|
||||
reduce_funcs: true,
|
||||
reduce_vars: true,
|
||||
sequences: true,
|
||||
@@ -3545,8 +3545,8 @@ issue_2437_2: {
|
||||
if (xhrDesc)
|
||||
return (req = new XMLHttpRequest()).onreadystatechange,
|
||||
Object.defineProperty(XMLHttpRequest.prototype, "onreadystatechange", xhrDesc || {});
|
||||
var req;
|
||||
(req = new XMLHttpRequest).onreadystatechange = function(){},
|
||||
var req = new XMLHttpRequest();
|
||||
req.onreadystatechange = function(){},
|
||||
req[SYMBOL_FAKE_ONREADYSTATECHANGE_1],
|
||||
req.onreadystatechange = null;
|
||||
}();
|
||||
@@ -3895,11 +3895,11 @@ issue_2436_10: {
|
||||
o = { b: 3 };
|
||||
return n;
|
||||
}
|
||||
console.log((c = o, [
|
||||
c.a,
|
||||
console.log([
|
||||
(c = o).a,
|
||||
f(c.b),
|
||||
c.b,
|
||||
]).join(" "));
|
||||
].join(" "));
|
||||
var c;
|
||||
}
|
||||
expect_stdout: "1 2 2"
|
||||
@@ -4194,7 +4194,7 @@ may_throw_2: {
|
||||
var a = x();
|
||||
++b;
|
||||
return b(a);
|
||||
} catch(e) {}
|
||||
} catch (e) {}
|
||||
console.log(b);
|
||||
}
|
||||
f(0);
|
||||
@@ -4204,7 +4204,7 @@ may_throw_2: {
|
||||
try {
|
||||
var a = x();
|
||||
return (++b)(a);
|
||||
} catch(e) {}
|
||||
} catch (e) {}
|
||||
console.log(b);
|
||||
}
|
||||
f(0);
|
||||
@@ -4388,7 +4388,7 @@ replace_all_var: {
|
||||
}
|
||||
|
||||
replace_all_var_scope: {
|
||||
rename = true;
|
||||
rename = true
|
||||
options = {
|
||||
collapse_vars: true,
|
||||
unused: true,
|
||||
@@ -5730,3 +5730,621 @@ issue_3096: {
|
||||
}
|
||||
expect_stdout: "ab"
|
||||
}
|
||||
|
||||
issue_3215_1: {
|
||||
options = {
|
||||
collapse_vars: true,
|
||||
evaluate: true,
|
||||
ie8: false,
|
||||
inline: true,
|
||||
passes: 2,
|
||||
side_effects: true,
|
||||
unused: true,
|
||||
}
|
||||
input: {
|
||||
console.log(function a() {
|
||||
var a = 42;
|
||||
return typeof a;
|
||||
}());
|
||||
}
|
||||
expect: {
|
||||
console.log("number");
|
||||
}
|
||||
expect_stdout: "number"
|
||||
}
|
||||
|
||||
issue_3215_2: {
|
||||
options = {
|
||||
collapse_vars: true,
|
||||
evaluate: true,
|
||||
ie8: true,
|
||||
inline: true,
|
||||
passes: 2,
|
||||
side_effects: true,
|
||||
unused: true,
|
||||
}
|
||||
input: {
|
||||
console.log(function a() {
|
||||
var a = 42;
|
||||
return typeof a;
|
||||
}());
|
||||
}
|
||||
expect: {
|
||||
console.log(function a() {
|
||||
var a = 42;
|
||||
return typeof a;
|
||||
}());
|
||||
}
|
||||
expect_stdout: "number"
|
||||
}
|
||||
|
||||
issue_3215_3: {
|
||||
options = {
|
||||
collapse_vars: true,
|
||||
evaluate: true,
|
||||
ie8: false,
|
||||
inline: true,
|
||||
passes: 2,
|
||||
side_effects: true,
|
||||
unused: true,
|
||||
}
|
||||
input: {
|
||||
console.log(function() {
|
||||
var a = 42;
|
||||
(function a() {});
|
||||
return typeof a;
|
||||
}());
|
||||
}
|
||||
expect: {
|
||||
console.log("number");
|
||||
}
|
||||
expect_stdout: "number"
|
||||
}
|
||||
|
||||
issue_3215_4: {
|
||||
options = {
|
||||
collapse_vars: true,
|
||||
evaluate: true,
|
||||
ie8: true,
|
||||
inline: true,
|
||||
passes: 2,
|
||||
side_effects: true,
|
||||
unused: true,
|
||||
}
|
||||
input: {
|
||||
console.log(function() {
|
||||
var a = 42;
|
||||
(function a() {});
|
||||
return typeof a;
|
||||
}());
|
||||
}
|
||||
expect: {
|
||||
console.log(function() {
|
||||
var a = 42;
|
||||
(function a() {});
|
||||
return typeof a;
|
||||
}());
|
||||
}
|
||||
expect_stdout: "number"
|
||||
}
|
||||
|
||||
issue_3238_1: {
|
||||
options = {
|
||||
collapse_vars: true,
|
||||
unsafe: true,
|
||||
}
|
||||
input: {
|
||||
function f(a) {
|
||||
var b, c;
|
||||
if (a) {
|
||||
b = Object.create(null);
|
||||
c = Object.create(null);
|
||||
}
|
||||
return b === c;
|
||||
}
|
||||
console.log(f(0), f(1));
|
||||
}
|
||||
expect: {
|
||||
function f(a) {
|
||||
var b, c;
|
||||
if (a) {
|
||||
b = Object.create(null);
|
||||
c = Object.create(null);
|
||||
}
|
||||
return b === c;
|
||||
}
|
||||
console.log(f(0), f(1));
|
||||
}
|
||||
expect_stdout: "true false"
|
||||
}
|
||||
|
||||
issue_3238_2: {
|
||||
options = {
|
||||
collapse_vars: true,
|
||||
unsafe: true,
|
||||
}
|
||||
input: {
|
||||
function f(a) {
|
||||
var b, c;
|
||||
if (a) {
|
||||
b = Error();
|
||||
c = Error();
|
||||
}
|
||||
return b === c;
|
||||
}
|
||||
console.log(f(0), f(1));
|
||||
}
|
||||
expect: {
|
||||
function f(a) {
|
||||
var b, c;
|
||||
if (a) {
|
||||
b = Error();
|
||||
c = Error();
|
||||
}
|
||||
return b === c;
|
||||
}
|
||||
console.log(f(0), f(1));
|
||||
}
|
||||
expect_stdout: "true false"
|
||||
}
|
||||
|
||||
issue_3238_3: {
|
||||
options = {
|
||||
collapse_vars: true,
|
||||
unsafe: true,
|
||||
}
|
||||
input: {
|
||||
function f(a) {
|
||||
var b, c;
|
||||
if (a) {
|
||||
b = new Date();
|
||||
c = new Date();
|
||||
}
|
||||
return b === c;
|
||||
}
|
||||
console.log(f(0), f(1));
|
||||
}
|
||||
expect: {
|
||||
function f(a) {
|
||||
var b, c;
|
||||
if (a) {
|
||||
b = new Date();
|
||||
c = new Date();
|
||||
}
|
||||
return b === c;
|
||||
}
|
||||
console.log(f(0), f(1));
|
||||
}
|
||||
expect_stdout: "true false"
|
||||
}
|
||||
|
||||
issue_3238_4: {
|
||||
options = {
|
||||
collapse_vars: true,
|
||||
unsafe: true,
|
||||
}
|
||||
input: {
|
||||
function f(a) {
|
||||
var b, c;
|
||||
if (a) {
|
||||
b = a && {};
|
||||
c = a && {};
|
||||
}
|
||||
return b === c;
|
||||
}
|
||||
console.log(f(0), f(1));
|
||||
}
|
||||
expect: {
|
||||
function f(a) {
|
||||
var b, c;
|
||||
if (a) {
|
||||
b = a && {};
|
||||
c = a && {};
|
||||
}
|
||||
return b === c;
|
||||
}
|
||||
console.log(f(0), f(1));
|
||||
}
|
||||
expect_stdout: "true false"
|
||||
}
|
||||
|
||||
issue_3238_5: {
|
||||
options = {
|
||||
collapse_vars: true,
|
||||
unsafe: true,
|
||||
}
|
||||
input: {
|
||||
function f(a) {
|
||||
var b, c;
|
||||
if (a) {
|
||||
b = a ? [] : 42;
|
||||
c = a ? [] : 42;
|
||||
}
|
||||
return b === c;
|
||||
}
|
||||
console.log(f(0), f(1));
|
||||
}
|
||||
expect: {
|
||||
function f(a) {
|
||||
var b, c;
|
||||
if (a) {
|
||||
b = a ? [] : 42;
|
||||
c = a ? [] : 42;
|
||||
}
|
||||
return b === c;
|
||||
}
|
||||
console.log(f(0), f(1));
|
||||
}
|
||||
expect_stdout: "true false"
|
||||
}
|
||||
|
||||
issue_3238_6: {
|
||||
options = {
|
||||
collapse_vars: true,
|
||||
unsafe: true,
|
||||
}
|
||||
input: {
|
||||
function f(a) {
|
||||
var b, c;
|
||||
if (a) {
|
||||
b = a && 0 || [];
|
||||
c = a && 0 || [];
|
||||
}
|
||||
return b === c;
|
||||
}
|
||||
console.log(f(0), f(1));
|
||||
}
|
||||
expect: {
|
||||
function f(a) {
|
||||
var b, c;
|
||||
if (a) {
|
||||
b = a && 0 || [];
|
||||
c = a && 0 || [];
|
||||
}
|
||||
return b === c;
|
||||
}
|
||||
console.log(f(0), f(1));
|
||||
}
|
||||
expect_stdout: "true false"
|
||||
}
|
||||
|
||||
issue_3247: {
|
||||
options = {
|
||||
collapse_vars: true,
|
||||
}
|
||||
input: {
|
||||
function f(o) {
|
||||
console.log(o.p);
|
||||
}
|
||||
var a;
|
||||
a = Object({ p: "PASS" });
|
||||
a.q = true;
|
||||
f(a, true);
|
||||
}
|
||||
expect: {
|
||||
function f(o) {
|
||||
console.log(o.p);
|
||||
}
|
||||
var a;
|
||||
(a = Object({ p: "PASS" })).q = true;
|
||||
f(a, true);
|
||||
}
|
||||
expect_stdout: "PASS"
|
||||
}
|
||||
|
||||
issue_3305: {
|
||||
options = {
|
||||
collapse_vars: true,
|
||||
conditionals: true,
|
||||
sequences: true,
|
||||
}
|
||||
input: {
|
||||
function calc(a) {
|
||||
var x, w;
|
||||
if (a) {
|
||||
x = a;
|
||||
w = 1;
|
||||
} else {
|
||||
x = 1;
|
||||
w = 0;
|
||||
}
|
||||
return add(x, w);
|
||||
}
|
||||
function add(x, w) {
|
||||
return x + w;
|
||||
}
|
||||
console.log(calc(41));
|
||||
}
|
||||
expect: {
|
||||
function calc(a) {
|
||||
var x, w;
|
||||
return w = a ? (x = a, 1) : (x = 1, 0), add(x, w);
|
||||
}
|
||||
function add(x, w) {
|
||||
return x + w;
|
||||
}
|
||||
console.log(calc(41));
|
||||
}
|
||||
expect_stdout: "42"
|
||||
}
|
||||
|
||||
issue_3314: {
|
||||
options = {
|
||||
collapse_vars: true,
|
||||
}
|
||||
input: {
|
||||
function test(a, b) {
|
||||
console.log(a, b);
|
||||
}
|
||||
var a = "FAIL", b;
|
||||
b = a = "PASS";
|
||||
test(a, b);
|
||||
}
|
||||
expect: {
|
||||
function test(a, b) {
|
||||
console.log(a, b);
|
||||
}
|
||||
var a = "FAIL", b;
|
||||
b = a = "PASS";
|
||||
test(a, b);
|
||||
}
|
||||
expect_stdout: "PASS PASS"
|
||||
}
|
||||
|
||||
issue_3327: {
|
||||
options = {
|
||||
collapse_vars: true,
|
||||
conditionals: true,
|
||||
sequences: true,
|
||||
}
|
||||
input: {
|
||||
var a, b, l = ["PASS", 42];
|
||||
if (l.length === 1) {
|
||||
a = l[0].a;
|
||||
b = l[0].b;
|
||||
} else {
|
||||
a = l[0];
|
||||
b = l[1];
|
||||
}
|
||||
function echo(a, b) {
|
||||
console.log(a, b);
|
||||
}
|
||||
echo(a, b);
|
||||
}
|
||||
expect: {
|
||||
var a, b, l = ["PASS", 42];
|
||||
function echo(a, b) {
|
||||
console.log(a, b);
|
||||
}
|
||||
b = 1 === l.length ? (a = l[0].a, l[0].b) : (a = l[0], l[1]),
|
||||
echo(a,b);
|
||||
}
|
||||
expect_stdout: "PASS 42"
|
||||
}
|
||||
|
||||
assign_left: {
|
||||
options = {
|
||||
collapse_vars: true,
|
||||
}
|
||||
input: {
|
||||
console.log(function(a, b) {
|
||||
(b = a, b.p).q = "PASS";
|
||||
return a.p.q;
|
||||
}({p: {}}));
|
||||
}
|
||||
expect: {
|
||||
console.log(function(a, b) {
|
||||
(b = a).p.q = "PASS";
|
||||
return a.p.q;
|
||||
}({p: {}}));
|
||||
}
|
||||
expect_stdout: "PASS"
|
||||
}
|
||||
|
||||
sub_property: {
|
||||
options = {
|
||||
collapse_vars: true,
|
||||
}
|
||||
input: {
|
||||
console.log(function(a, b) {
|
||||
return a[(b = a, b.length - 1)];
|
||||
}([ "FAIL", "PASS" ]));
|
||||
}
|
||||
expect: {
|
||||
console.log(function(a, b) {
|
||||
return a[(b = a).length - 1];
|
||||
}([ "FAIL", "PASS" ]));
|
||||
}
|
||||
expect_stdout: "PASS"
|
||||
}
|
||||
|
||||
assign_undeclared: {
|
||||
options = {
|
||||
collapse_vars: true,
|
||||
toplevel: true,
|
||||
unused: true,
|
||||
}
|
||||
input: {
|
||||
var A = (console.log(42), function() {});
|
||||
B = new A();
|
||||
console.log(typeof B);
|
||||
}
|
||||
expect: {
|
||||
B = new (console.log(42), function() {})();
|
||||
console.log(typeof B);
|
||||
}
|
||||
expect_stdout: [
|
||||
"42",
|
||||
"object",
|
||||
]
|
||||
}
|
||||
|
||||
Infinity_assignment: {
|
||||
options = {
|
||||
collapse_vars: true,
|
||||
pure_getters: "strict",
|
||||
unsafe: true,
|
||||
}
|
||||
input: {
|
||||
var Infinity;
|
||||
Infinity = 42;
|
||||
console.log(Infinity);
|
||||
}
|
||||
expect: {
|
||||
var Infinity;
|
||||
Infinity = 42;
|
||||
console.log(Infinity);
|
||||
}
|
||||
expect_stdout: true
|
||||
}
|
||||
|
||||
issue_3439_1: {
|
||||
options = {
|
||||
collapse_vars: true,
|
||||
unused: true,
|
||||
}
|
||||
input: {
|
||||
console.log(typeof function(a) {
|
||||
function a() {}
|
||||
return a;
|
||||
}(42));
|
||||
}
|
||||
expect: {
|
||||
console.log(typeof function(a) {
|
||||
function a() {}
|
||||
return a;
|
||||
}(42));
|
||||
}
|
||||
expect_stdout: "function"
|
||||
}
|
||||
|
||||
issue_3439_2: {
|
||||
options = {
|
||||
collapse_vars: true,
|
||||
unused: true,
|
||||
}
|
||||
input: {
|
||||
console.log(typeof function() {
|
||||
var a = 42;
|
||||
function a() {}
|
||||
return a;
|
||||
}());
|
||||
}
|
||||
expect: {
|
||||
console.log(typeof function() {
|
||||
return 42;
|
||||
}());
|
||||
}
|
||||
expect_stdout: "number"
|
||||
}
|
||||
|
||||
cond_sequence_return: {
|
||||
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"
|
||||
}
|
||||
|
||||
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"
|
||||
}
|
||||
|
||||
@@ -323,3 +323,120 @@ is_number_unsafe: {
|
||||
}
|
||||
expect_stdout: "true"
|
||||
}
|
||||
|
||||
is_boolean_var: {
|
||||
options = {
|
||||
comparisons: true,
|
||||
reduce_vars: true,
|
||||
}
|
||||
input: {
|
||||
console.log(function(a, b) {
|
||||
for (var i = 0, c = !b; i < a.length; i++)
|
||||
if (!a[i] === c)
|
||||
return i;
|
||||
}([ false, true ], 42));
|
||||
}
|
||||
expect: {
|
||||
console.log(function(a, b) {
|
||||
for (var i = 0, c = !b; i < a.length; i++)
|
||||
if (!a[i] == c)
|
||||
return i;
|
||||
}([ false, true ], 42));
|
||||
}
|
||||
expect_stdout: "1"
|
||||
}
|
||||
|
||||
is_defined: {
|
||||
options = {
|
||||
comparisons: true,
|
||||
}
|
||||
input: {
|
||||
console.log(function a() {
|
||||
return void 0 === a;
|
||||
}());
|
||||
}
|
||||
expect: {
|
||||
console.log(function a() {
|
||||
return a, false;
|
||||
}());
|
||||
}
|
||||
expect_stdout: "false"
|
||||
expect_warnings: [
|
||||
"WARN: Expression always defined [test/compress/comparisons.js:2,19]",
|
||||
]
|
||||
}
|
||||
|
||||
unsafe_indexOf: {
|
||||
options = {
|
||||
booleans: true,
|
||||
comparisons: true,
|
||||
unsafe: true,
|
||||
}
|
||||
input: {
|
||||
var a = Object.keys({ foo: 42 });
|
||||
if (a.indexOf("bar") < 0) console.log("PASS");
|
||||
if (0 > a.indexOf("bar")) console.log("PASS");
|
||||
if (a.indexOf("foo") >= 0) console.log("PASS");
|
||||
if (0 <= a.indexOf("foo")) console.log("PASS");
|
||||
if (a.indexOf("foo") > -1) console.log("PASS");
|
||||
if (-1 < a.indexOf("foo")) console.log("PASS");
|
||||
if (a.indexOf("bar") == -1) console.log("PASS");
|
||||
if (-1 == a.indexOf("bar")) console.log("PASS");
|
||||
if (a.indexOf("bar") === -1) console.log("PASS");
|
||||
if (-1 === a.indexOf("bar")) console.log("PASS");
|
||||
if (a.indexOf("foo") != -1) console.log("PASS");
|
||||
if (-1 != a.indexOf("foo")) console.log("PASS");
|
||||
if (a.indexOf("foo") !== -1) console.log("PASS");
|
||||
if (-1 !== a.indexOf("foo")) console.log("PASS");
|
||||
}
|
||||
expect: {
|
||||
var a = Object.keys({ foo: 42 });
|
||||
if (!~a.indexOf("bar")) console.log("PASS");
|
||||
if (!~a.indexOf("bar")) console.log("PASS");
|
||||
if (~a.indexOf("foo")) console.log("PASS");
|
||||
if (~a.indexOf("foo")) console.log("PASS");
|
||||
if (~a.indexOf("foo")) console.log("PASS");
|
||||
if (~a.indexOf("foo")) console.log("PASS");
|
||||
if (!~a.indexOf("bar")) console.log("PASS");
|
||||
if (!~a.indexOf("bar")) console.log("PASS");
|
||||
if (!~a.indexOf("bar")) console.log("PASS");
|
||||
if (!~a.indexOf("bar")) console.log("PASS");
|
||||
if (~a.indexOf("foo")) console.log("PASS");
|
||||
if (~a.indexOf("foo")) console.log("PASS");
|
||||
if (~a.indexOf("foo")) console.log("PASS");
|
||||
if (~a.indexOf("foo")) console.log("PASS");
|
||||
}
|
||||
expect_stdout: [
|
||||
"PASS",
|
||||
"PASS",
|
||||
"PASS",
|
||||
"PASS",
|
||||
"PASS",
|
||||
"PASS",
|
||||
"PASS",
|
||||
"PASS",
|
||||
"PASS",
|
||||
"PASS",
|
||||
"PASS",
|
||||
"PASS",
|
||||
"PASS",
|
||||
"PASS",
|
||||
]
|
||||
}
|
||||
|
||||
issue_3413: {
|
||||
options = {
|
||||
comparisons: true,
|
||||
evaluate: true,
|
||||
side_effects: true,
|
||||
}
|
||||
input: {
|
||||
var b;
|
||||
void 0 !== ("" < b || void 0) || console.log("PASS");
|
||||
}
|
||||
expect: {
|
||||
var b;
|
||||
void 0 !== ("" < b || void 0) || console.log("PASS");
|
||||
}
|
||||
expect_stdout: "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: {
|
||||
options = {
|
||||
conditionals: true,
|
||||
@@ -1292,3 +1310,182 @@ to_and_or: {
|
||||
}
|
||||
expect_stdout: true
|
||||
}
|
||||
|
||||
cond_seq_assign_1: {
|
||||
options = {
|
||||
conditionals: true,
|
||||
sequences: true,
|
||||
}
|
||||
input: {
|
||||
function f(a) {
|
||||
var t;
|
||||
if (a) {
|
||||
t = "foo";
|
||||
t = "bar";
|
||||
} else {
|
||||
console.log(t);
|
||||
t = 42;
|
||||
}
|
||||
console.log(t);
|
||||
}
|
||||
f(f);
|
||||
f();
|
||||
}
|
||||
expect: {
|
||||
function f(a) {
|
||||
var t;
|
||||
t = a ? (t = "foo", "bar") : (console.log(t), 42),
|
||||
console.log(t);
|
||||
}
|
||||
f(f),
|
||||
f();
|
||||
}
|
||||
expect_stdout: [
|
||||
"bar",
|
||||
"undefined",
|
||||
"42",
|
||||
]
|
||||
}
|
||||
|
||||
cond_seq_assign_2: {
|
||||
options = {
|
||||
conditionals: true,
|
||||
sequences: true,
|
||||
}
|
||||
input: {
|
||||
function f(a) {
|
||||
var t;
|
||||
if (a) {
|
||||
t = "foo";
|
||||
a = "bar";
|
||||
} else {
|
||||
console.log(t);
|
||||
t = 42;
|
||||
}
|
||||
console.log(t);
|
||||
}
|
||||
f(f);
|
||||
f();
|
||||
}
|
||||
expect: {
|
||||
function f(a) {
|
||||
var t;
|
||||
a ? (t = "foo", a = "bar") : (console.log(t), t = 42),
|
||||
console.log(t);
|
||||
}
|
||||
f(f),
|
||||
f();
|
||||
}
|
||||
expect_stdout: [
|
||||
"foo",
|
||||
"undefined",
|
||||
"42",
|
||||
]
|
||||
}
|
||||
|
||||
cond_seq_assign_3: {
|
||||
options = {
|
||||
assignments: true,
|
||||
conditionals: true,
|
||||
}
|
||||
input: {
|
||||
var c = 0;
|
||||
if (this)
|
||||
c = 1 + c, c = c + 1;
|
||||
else
|
||||
c = 1 + c, c = c + 1;
|
||||
console.log(c);
|
||||
}
|
||||
expect: {
|
||||
var c = 0;
|
||||
this, c = 1 + c, c += 1;
|
||||
console.log(c);
|
||||
}
|
||||
expect_stdout: "2"
|
||||
}
|
||||
|
||||
issue_3271: {
|
||||
options = {
|
||||
conditionals: true,
|
||||
}
|
||||
input: {
|
||||
function f(a) {
|
||||
var i = 0, b = [];
|
||||
if (a) {
|
||||
b[i++] = 4,
|
||||
b[i++] = 1;
|
||||
} else {
|
||||
b[i++] = 3,
|
||||
b[i++] = 2,
|
||||
b[i++] = 1;
|
||||
}
|
||||
return b;
|
||||
}
|
||||
console.log(f(0).pop(), f(1).pop());
|
||||
}
|
||||
expect: {
|
||||
function f(a) {
|
||||
var i = 0, b = [];
|
||||
a ? b[i++] = 4 : (b[i++] = 3, b[i++] = 2),
|
||||
b[i++] = 1;
|
||||
return b;
|
||||
}
|
||||
console.log(f(0).pop(), f(1).pop());
|
||||
}
|
||||
expect_stdout: "1 1"
|
||||
}
|
||||
|
||||
iife_condition: {
|
||||
options = {
|
||||
conditionals: true,
|
||||
side_effects: true,
|
||||
}
|
||||
input: {
|
||||
if (function() {
|
||||
return console;
|
||||
}())
|
||||
console.log("PASS");
|
||||
}
|
||||
expect: {
|
||||
!function() {
|
||||
return console;
|
||||
}() || console.log("PASS");
|
||||
}
|
||||
expect_stdout: "PASS"
|
||||
}
|
||||
|
||||
angularjs_chain: {
|
||||
options = {
|
||||
conditionals: true,
|
||||
passes: 2,
|
||||
side_effects: true,
|
||||
}
|
||||
input: {
|
||||
function nonComputedMember(left, right, context, create) {
|
||||
var lhs = left();
|
||||
if (create && create !== 1) {
|
||||
if (lhs && lhs[right] == null) {
|
||||
lhs[right] = {};
|
||||
}
|
||||
}
|
||||
var value = lhs != null ? lhs[right] : undefined;
|
||||
if (context) {
|
||||
return { context: lhs, name: right, value: value };
|
||||
} else {
|
||||
return value;
|
||||
}
|
||||
}
|
||||
}
|
||||
expect: {
|
||||
function nonComputedMember(left, right, context, create) {
|
||||
var lhs = left();
|
||||
create && 1 !== create && lhs && null == lhs[right] && (lhs[right] = {});
|
||||
var value = null != lhs ? lhs[right] : void 0;
|
||||
return context ? {
|
||||
context: lhs,
|
||||
name: right,
|
||||
value: value
|
||||
} : value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -942,3 +942,125 @@ issue_2929: {
|
||||
}
|
||||
expect_stdout: "PASS"
|
||||
}
|
||||
|
||||
unsafe_string_replace: {
|
||||
options = {
|
||||
side_effects: true,
|
||||
unsafe: true,
|
||||
}
|
||||
input: {
|
||||
"foo".replace("f", function() {
|
||||
console.log("PASS");
|
||||
});
|
||||
}
|
||||
expect: {
|
||||
"foo".replace("f", function() {
|
||||
console.log("PASS");
|
||||
});
|
||||
}
|
||||
expect_stdout: "PASS"
|
||||
}
|
||||
|
||||
issue_3402: {
|
||||
options = {
|
||||
dead_code: true,
|
||||
evaluate: true,
|
||||
functions: true,
|
||||
passes: 2,
|
||||
reduce_vars: true,
|
||||
side_effects: true,
|
||||
toplevel: true,
|
||||
typeofs: true,
|
||||
unused: true,
|
||||
}
|
||||
input: {
|
||||
var f = function f() {
|
||||
f = 42;
|
||||
console.log(typeof f);
|
||||
};
|
||||
"function" == typeof f && f();
|
||||
"function" == typeof f && f();
|
||||
console.log(typeof f);
|
||||
}
|
||||
expect: {
|
||||
function f() {
|
||||
console.log(typeof f);
|
||||
}
|
||||
f();
|
||||
f();
|
||||
console.log(typeof f);
|
||||
}
|
||||
expect_stdout: [
|
||||
"function",
|
||||
"function",
|
||||
"function",
|
||||
]
|
||||
}
|
||||
|
||||
issue_3406: {
|
||||
options = {
|
||||
dead_code: true,
|
||||
}
|
||||
input: {
|
||||
console.log(function f(a) {
|
||||
return delete (f = a);
|
||||
}());
|
||||
}
|
||||
expect: {
|
||||
console.log(function f(a) {
|
||||
return delete (0, a);
|
||||
}());
|
||||
}
|
||||
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"
|
||||
}
|
||||
|
||||
@@ -144,7 +144,7 @@ unused_var_in_catch: {
|
||||
function foo() {
|
||||
try {
|
||||
foo();
|
||||
} catch(ex) {
|
||||
} catch (ex) {
|
||||
var x = 10;
|
||||
}
|
||||
}
|
||||
@@ -153,7 +153,7 @@ unused_var_in_catch: {
|
||||
function foo() {
|
||||
try {
|
||||
foo();
|
||||
} catch(ex) {}
|
||||
} catch (ex) {}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -166,7 +166,7 @@ used_var_in_catch: {
|
||||
function foo() {
|
||||
try {
|
||||
foo();
|
||||
} catch(ex) {
|
||||
} catch (ex) {
|
||||
var x = 10;
|
||||
}
|
||||
return x;
|
||||
@@ -176,7 +176,7 @@ used_var_in_catch: {
|
||||
function foo() {
|
||||
try {
|
||||
foo();
|
||||
} catch(ex) {
|
||||
} catch (ex) {
|
||||
var x = 10;
|
||||
}
|
||||
return x;
|
||||
@@ -797,6 +797,7 @@ assign_chain: {
|
||||
issue_1583: {
|
||||
options = {
|
||||
keep_fargs: true,
|
||||
passes: 2,
|
||||
reduce_funcs: true,
|
||||
reduce_vars: true,
|
||||
unused: true,
|
||||
@@ -1004,7 +1005,7 @@ issue_1715_4: {
|
||||
delete_assign_1: {
|
||||
options = {
|
||||
booleans: true,
|
||||
side_effects: true,
|
||||
evaluate: true,
|
||||
toplevel: true,
|
||||
unused: true,
|
||||
}
|
||||
@@ -1023,7 +1024,7 @@ delete_assign_1: {
|
||||
console.log((1 / 0, !0));
|
||||
console.log((1 / 0, !0));
|
||||
console.log((NaN, !0));
|
||||
console.log((0 / 0, !0));
|
||||
console.log((NaN, !0));
|
||||
}
|
||||
expect_stdout: true
|
||||
}
|
||||
@@ -1031,8 +1032,8 @@ delete_assign_1: {
|
||||
delete_assign_2: {
|
||||
options = {
|
||||
booleans: true,
|
||||
evaluate: true,
|
||||
keep_infinity: true,
|
||||
side_effects: true,
|
||||
toplevel: true,
|
||||
unused: true,
|
||||
}
|
||||
@@ -1051,7 +1052,7 @@ delete_assign_2: {
|
||||
console.log((Infinity, !0));
|
||||
console.log((1 / 0, !0));
|
||||
console.log((NaN, !0));
|
||||
console.log((0 / 0, !0));
|
||||
console.log((NaN, !0));
|
||||
}
|
||||
expect_stdout: true
|
||||
}
|
||||
@@ -1144,6 +1145,7 @@ var_catch_toplevel: {
|
||||
options = {
|
||||
conditionals: true,
|
||||
negate_iife: true,
|
||||
passes: 2,
|
||||
reduce_funcs: true,
|
||||
reduce_vars: true,
|
||||
side_effects: true,
|
||||
@@ -1156,7 +1158,7 @@ var_catch_toplevel: {
|
||||
try {
|
||||
a++;
|
||||
x();
|
||||
} catch(a) {
|
||||
} catch (a) {
|
||||
if (a) var a;
|
||||
var a = 10;
|
||||
}
|
||||
@@ -1167,7 +1169,7 @@ var_catch_toplevel: {
|
||||
!function() {
|
||||
try {
|
||||
x();
|
||||
} catch(a) {
|
||||
} catch (a) {
|
||||
var a;
|
||||
}
|
||||
}();
|
||||
@@ -1982,3 +1984,240 @@ issue_3192: {
|
||||
"foo bar",
|
||||
]
|
||||
}
|
||||
|
||||
issue_3233: {
|
||||
options = {
|
||||
pure_getters: "strict",
|
||||
side_effects: true,
|
||||
unused: true,
|
||||
}
|
||||
input: {
|
||||
var a = function b() {
|
||||
b.c = "PASS";
|
||||
};
|
||||
a();
|
||||
console.log(a.c);
|
||||
}
|
||||
expect: {
|
||||
var a = function b() {
|
||||
b.c = "PASS";
|
||||
};
|
||||
a();
|
||||
console.log(a.c);
|
||||
}
|
||||
expect_stdout: "PASS"
|
||||
}
|
||||
|
||||
issue_3375: {
|
||||
options = {
|
||||
reduce_vars: true,
|
||||
toplevel: true,
|
||||
unused: true,
|
||||
}
|
||||
input: {
|
||||
var b = 1;
|
||||
var a = c = [], c = --b + ("function" == typeof f && f());
|
||||
var a = c && c[a];
|
||||
console.log(a, b);
|
||||
}
|
||||
expect: {
|
||||
var b = 1;
|
||||
var a = [], c = --b + ("function" == typeof f && f());
|
||||
a = c && c[a];
|
||||
console.log(a, b);
|
||||
}
|
||||
expect_stdout: "0 0"
|
||||
}
|
||||
|
||||
issue_3427_1: {
|
||||
options = {
|
||||
sequences: true,
|
||||
side_effects: true,
|
||||
unused: true,
|
||||
}
|
||||
input: {
|
||||
(function() {
|
||||
var a;
|
||||
a = a || {};
|
||||
})();
|
||||
}
|
||||
expect: {}
|
||||
}
|
||||
|
||||
issue_3427_2: {
|
||||
options = {
|
||||
unused: true,
|
||||
}
|
||||
input: {
|
||||
(function() {
|
||||
var s = "PASS";
|
||||
console.log(s = s || "FAIL");
|
||||
})();
|
||||
}
|
||||
expect: {
|
||||
(function() {
|
||||
var s = "PASS";
|
||||
console.log(s = s || "FAIL");
|
||||
})();
|
||||
}
|
||||
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"
|
||||
}
|
||||
|
||||
@@ -246,7 +246,7 @@ unsafe_constant: {
|
||||
}
|
||||
expect: {
|
||||
console.log(
|
||||
true.a,
|
||||
void 0,
|
||||
false.a,
|
||||
null.a,
|
||||
(void 0).a
|
||||
@@ -278,7 +278,7 @@ unsafe_object: {
|
||||
o + 1,
|
||||
2,
|
||||
o.b + 1,
|
||||
1..b + 1
|
||||
NaN
|
||||
);
|
||||
}
|
||||
expect_stdout: true
|
||||
@@ -365,7 +365,7 @@ unsafe_object_repeated: {
|
||||
o + 1,
|
||||
2,
|
||||
o.b + 1,
|
||||
1..b + 1
|
||||
NaN
|
||||
);
|
||||
}
|
||||
expect_stdout: true
|
||||
@@ -444,8 +444,8 @@ unsafe_integer_key: {
|
||||
2,
|
||||
2,
|
||||
({0:1})[1] + 1,
|
||||
1[1] + 1,
|
||||
1["1"] + 1
|
||||
NaN,
|
||||
NaN
|
||||
);
|
||||
}
|
||||
expect_stdout: true
|
||||
@@ -500,8 +500,8 @@ unsafe_float_key: {
|
||||
2,
|
||||
2,
|
||||
({2.72:1})[3.14] + 1,
|
||||
1[3.14] + 1,
|
||||
1["3.14"] + 1
|
||||
NaN,
|
||||
NaN
|
||||
);
|
||||
}
|
||||
expect_stdout: true
|
||||
@@ -635,12 +635,12 @@ unsafe_string_bad_index: {
|
||||
}
|
||||
expect: {
|
||||
console.log(
|
||||
"1234".a + 1,
|
||||
"1234"["a"] + 1,
|
||||
"1234"[3.14] + 1
|
||||
NaN,
|
||||
NaN,
|
||||
NaN
|
||||
);
|
||||
}
|
||||
expect_stdout: true
|
||||
expect_stdout: "NaN NaN NaN"
|
||||
}
|
||||
|
||||
prototype_function: {
|
||||
@@ -820,8 +820,8 @@ unsafe_charAt_noop: {
|
||||
}
|
||||
expect: {
|
||||
console.log(
|
||||
s.charAt(0),
|
||||
"string".charAt(x),
|
||||
s[0],
|
||||
"string"[0 | x],
|
||||
(typeof x)[0]
|
||||
);
|
||||
}
|
||||
@@ -1124,14 +1124,14 @@ issue_2207_1: {
|
||||
console.log(Math.max(3, 6, 2, 7, 3, 4));
|
||||
console.log(Math.cos(1.2345));
|
||||
console.log(Math.cos(1.2345) - Math.sin(4.321));
|
||||
console.log(Math.pow(Math.PI, Math.E - Math.LN10));
|
||||
console.log(Math.pow(Math.PI, Math.E - Math.LN10).toFixed(15));
|
||||
}
|
||||
expect: {
|
||||
console.log("A");
|
||||
console.log(7);
|
||||
console.log(Math.cos(1.2345));
|
||||
console.log(1.2543732512566947);
|
||||
console.log(1.6093984514472044);
|
||||
console.log("1.609398451447204");
|
||||
}
|
||||
expect_stdout: true
|
||||
}
|
||||
@@ -1199,7 +1199,7 @@ issue_2231_1: {
|
||||
}
|
||||
expect_stdout: true
|
||||
expect_warnings: [
|
||||
"WARN: Error evaluating Object.keys(void 0) [test/compress/evaluate.js:1195,20]",
|
||||
"WARN: Error evaluating Object.keys(void 0) [test/compress/evaluate.js:1,20]",
|
||||
]
|
||||
}
|
||||
|
||||
@@ -1216,7 +1216,7 @@ issue_2231_2: {
|
||||
}
|
||||
expect_stdout: true
|
||||
expect_warnings: [
|
||||
"WARN: Error evaluating Object.getOwnPropertyNames(null) [test/compress/evaluate.js:1212,20]",
|
||||
"WARN: Error evaluating Object.getOwnPropertyNames(null) [test/compress/evaluate.js:1,20]",
|
||||
]
|
||||
}
|
||||
|
||||
@@ -1245,12 +1245,12 @@ self_comparison_1: {
|
||||
}
|
||||
input: {
|
||||
var o = { n: NaN };
|
||||
console.log(o.n == o.n, o.n === o.n, o.n != o.n, o.n !== o.n, typeof o.n);
|
||||
console.log(typeof o.n, o.n == o.n, o.n === o.n, o.n != o.n, o.n !== o.n);
|
||||
}
|
||||
expect: {
|
||||
console.log(false, false, true, true, "number");
|
||||
console.log("number", false, false, true, true);
|
||||
}
|
||||
expect_stdout: "false false true true 'number'"
|
||||
expect_stdout: "number false false true true"
|
||||
}
|
||||
|
||||
self_comparison_2: {
|
||||
@@ -1265,12 +1265,12 @@ self_comparison_2: {
|
||||
}
|
||||
input: {
|
||||
var o = { n: NaN };
|
||||
console.log(o.n == o.n, o.n === o.n, o.n != o.n, o.n !== o.n, typeof o.n);
|
||||
console.log(typeof o.n, o.n == o.n, o.n === o.n, o.n != o.n, o.n !== o.n);
|
||||
}
|
||||
expect: {
|
||||
console.log(false, false, true, true, "number");
|
||||
console.log("number", false, false, true, true);
|
||||
}
|
||||
expect_stdout: "false false true true 'number'"
|
||||
expect_stdout: "number false false true true"
|
||||
}
|
||||
|
||||
issue_2535_1: {
|
||||
@@ -1354,14 +1354,14 @@ issue_2535_3: {
|
||||
}
|
||||
expect_stdout: true
|
||||
expect_warnings: [
|
||||
"WARN: Dropping side-effect-free && [test/compress/evaluate.js:1340,20]",
|
||||
"WARN: Dropping side-effect-free && [test/compress/evaluate.js:1341,20]",
|
||||
"WARN: Dropping side-effect-free && [test/compress/evaluate.js:1342,20]",
|
||||
"WARN: Condition left of && always false [test/compress/evaluate.js:1342,20]",
|
||||
"WARN: Dropping side-effect-free || [test/compress/evaluate.js:1343,20]",
|
||||
"WARN: Dropping side-effect-free || [test/compress/evaluate.js:1344,20]",
|
||||
"WARN: Dropping side-effect-free || [test/compress/evaluate.js:1345,20]",
|
||||
"WARN: Condition left of || always true [test/compress/evaluate.js:1345,20]",
|
||||
"WARN: Dropping side-effect-free && [test/compress/evaluate.js:1,20]",
|
||||
"WARN: Dropping side-effect-free && [test/compress/evaluate.js:2,20]",
|
||||
"WARN: Dropping side-effect-free && [test/compress/evaluate.js:3,20]",
|
||||
"WARN: Condition left of && always false [test/compress/evaluate.js:3,20]",
|
||||
"WARN: Dropping side-effect-free || [test/compress/evaluate.js:4,20]",
|
||||
"WARN: Dropping side-effect-free || [test/compress/evaluate.js:5,20]",
|
||||
"WARN: Dropping side-effect-free || [test/compress/evaluate.js:6,20]",
|
||||
"WARN: Condition left of || always true [test/compress/evaluate.js:6,20]",
|
||||
]
|
||||
}
|
||||
|
||||
@@ -1540,7 +1540,7 @@ issue_2926_2: {
|
||||
expect_stdout: "function"
|
||||
}
|
||||
|
||||
issue_2968: {
|
||||
issue_2968_1: {
|
||||
options = {
|
||||
collapse_vars: true,
|
||||
evaluate: true,
|
||||
@@ -1571,6 +1571,39 @@ issue_2968: {
|
||||
expect_stdout: "PASS"
|
||||
}
|
||||
|
||||
issue_2968_2: {
|
||||
options = {
|
||||
assignments: true,
|
||||
collapse_vars: true,
|
||||
evaluate: true,
|
||||
inline: true,
|
||||
passes: 2,
|
||||
reduce_vars: true,
|
||||
side_effects: true,
|
||||
unused: true,
|
||||
}
|
||||
input: {
|
||||
var c = "FAIL";
|
||||
(function() {
|
||||
(function(a, b) {
|
||||
a <<= 0;
|
||||
a && (a[(c = "PASS", 0 >>> (b += 1))] = 0);
|
||||
})(42, -42);
|
||||
})();
|
||||
console.log(c);
|
||||
}
|
||||
expect: {
|
||||
var c = "FAIL";
|
||||
(function() {
|
||||
a = 42,
|
||||
((a <<= 0) && (a[(c = "PASS", 0)] = 0));
|
||||
var a;
|
||||
})();
|
||||
console.log(c);
|
||||
}
|
||||
expect_stdout: "PASS"
|
||||
}
|
||||
|
||||
truthy_conditionals: {
|
||||
options = {
|
||||
conditionals: true,
|
||||
@@ -1610,3 +1643,219 @@ truthy_loops: {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if_increment: {
|
||||
options = {
|
||||
evaluate: true,
|
||||
reduce_vars: true,
|
||||
unused: true,
|
||||
}
|
||||
input: {
|
||||
console.log(function(a) {
|
||||
if (console)
|
||||
return ++a;
|
||||
}(0));
|
||||
}
|
||||
expect: {
|
||||
console.log(function(a) {
|
||||
if (console)
|
||||
return 1;
|
||||
}());
|
||||
}
|
||||
expect_stdout: "1"
|
||||
}
|
||||
|
||||
try_increment: {
|
||||
options = {
|
||||
evaluate: true,
|
||||
reduce_vars: true,
|
||||
unused: true,
|
||||
}
|
||||
input: {
|
||||
console.log(function(a) {
|
||||
try {
|
||||
return ++a;
|
||||
} catch (e) {}
|
||||
}(0));
|
||||
}
|
||||
expect: {
|
||||
console.log(function(a) {
|
||||
try {
|
||||
return 1;
|
||||
} catch (e) {}
|
||||
}());
|
||||
}
|
||||
expect_stdout: "1"
|
||||
}
|
||||
|
||||
unsafe_escaped: {
|
||||
options = {
|
||||
evaluate: true,
|
||||
inline: true,
|
||||
passes: 3,
|
||||
reduce_vars: true,
|
||||
side_effects: true,
|
||||
unsafe: true,
|
||||
unused: true,
|
||||
}
|
||||
input: {
|
||||
(function(a) {
|
||||
console.log(function(index) {
|
||||
return a[index];
|
||||
}(function(term) {
|
||||
return a.indexOf(term);
|
||||
}("PASS")));
|
||||
})([ "PASS" ]);
|
||||
}
|
||||
expect: {
|
||||
console.log("PASS");
|
||||
}
|
||||
expect_stdout: "PASS"
|
||||
}
|
||||
|
||||
unsafe_string_replace: {
|
||||
options = {
|
||||
evaluate: true,
|
||||
unsafe: true,
|
||||
}
|
||||
input: {
|
||||
"foo".replace("f", function() {
|
||||
console.log("PASS");
|
||||
});
|
||||
}
|
||||
expect: {
|
||||
"foo".replace("f", function() {
|
||||
console.log("PASS");
|
||||
});
|
||||
}
|
||||
expect_stdout: "PASS"
|
||||
}
|
||||
|
||||
issue_3387_1: {
|
||||
options = {
|
||||
evaluate: true,
|
||||
}
|
||||
input: {
|
||||
console.log(1 + (2 + "3"[4]));
|
||||
}
|
||||
expect: {
|
||||
console.log(1 + (2 + "3"[4]));
|
||||
}
|
||||
expect_stdout: "NaN"
|
||||
}
|
||||
|
||||
issue_3387_2: {
|
||||
options = {
|
||||
evaluate: true,
|
||||
unsafe: true,
|
||||
}
|
||||
input: {
|
||||
console.log(1 + (2 + "3"[4]));
|
||||
}
|
||||
expect: {
|
||||
console.log(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"
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -141,9 +141,8 @@ mixed: {
|
||||
console.log(CONFIG);
|
||||
}
|
||||
expect_warnings: [
|
||||
"WARN: global_defs CONFIG.VALUE redefined [test/compress/global_defs.js:127,22]",
|
||||
"WARN: global_defs CONFIG.VALUE redefined [test/compress/global_defs.js:128,22]",
|
||||
"WARN: global_defs CONFIG.VALUE redefined [test/compress/global_defs.js:130,8]",
|
||||
"WARN: global_defs CONFIG.VALUE redefined [test/compress/global_defs.js:4,22]",
|
||||
"WARN: global_defs CONFIG.VALUE redefined [test/compress/global_defs.js:7,8]",
|
||||
]
|
||||
}
|
||||
|
||||
@@ -197,3 +196,23 @@ issue_2167: {
|
||||
doWork();
|
||||
}
|
||||
}
|
||||
|
||||
issue_3217: {
|
||||
options = {
|
||||
collapse_vars: true,
|
||||
global_defs: {
|
||||
"@o": "{fn:function(){var a=42;console.log(a)}}",
|
||||
},
|
||||
inline: true,
|
||||
properties: true,
|
||||
reduce_vars: true,
|
||||
side_effects: true,
|
||||
unused: true,
|
||||
}
|
||||
input: {
|
||||
o.fn();
|
||||
}
|
||||
expect: {
|
||||
console.log(42);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -862,3 +862,55 @@ issue_3071_3: {
|
||||
}
|
||||
expect_stdout: "2"
|
||||
}
|
||||
|
||||
issue_3411: {
|
||||
options = {
|
||||
hoist_props: true,
|
||||
reduce_vars: true,
|
||||
}
|
||||
input: {
|
||||
var c = 1;
|
||||
!function f() {
|
||||
var o = {
|
||||
p: --c && f()
|
||||
};
|
||||
+o || console.log("PASS");
|
||||
}();
|
||||
}
|
||||
expect: {
|
||||
var c = 1;
|
||||
!function f() {
|
||||
var o_p = --c && f();
|
||||
+{} || console.log("PASS");
|
||||
}();
|
||||
}
|
||||
expect_stdout: "PASS"
|
||||
}
|
||||
|
||||
issue_3440: {
|
||||
options = {
|
||||
hoist_props: true,
|
||||
reduce_vars: true,
|
||||
unused: true,
|
||||
}
|
||||
input: {
|
||||
(function() {
|
||||
function f() {
|
||||
console.log(o.p);
|
||||
}
|
||||
var o = {
|
||||
p: "PASS",
|
||||
};
|
||||
return f;
|
||||
})()();
|
||||
}
|
||||
expect: {
|
||||
(function() {
|
||||
var o_p = "PASS";
|
||||
return function() {
|
||||
console.log(o_p);
|
||||
};
|
||||
})()();
|
||||
}
|
||||
expect_stdout: "PASS"
|
||||
}
|
||||
|
||||
1755
test/compress/ie8.js
1755
test/compress/ie8.js
File diff suppressed because it is too large
Load Diff
@@ -396,3 +396,151 @@ if_if_return_return: {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if_body_return_1: {
|
||||
options = {
|
||||
if_return: true,
|
||||
}
|
||||
input: {
|
||||
var c = "PASS";
|
||||
function f(a, b) {
|
||||
if (a) {
|
||||
if (b) throw new Error(c);
|
||||
return 42;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
console.log(f(0, 0));
|
||||
console.log(f(0, 1));
|
||||
console.log(f(1, 0));
|
||||
try {
|
||||
f(1, 1);
|
||||
console.log("FAIL");
|
||||
} catch (e) {
|
||||
console.log(e.message);
|
||||
}
|
||||
}
|
||||
expect: {
|
||||
var c = "PASS";
|
||||
function f(a, b) {
|
||||
if (a) {
|
||||
if (b) throw new Error(c);
|
||||
return 42;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
console.log(f(0, 0));
|
||||
console.log(f(0, 1));
|
||||
console.log(f(1, 0));
|
||||
try {
|
||||
f(1, 1);
|
||||
console.log("FAIL");
|
||||
} catch (e) {
|
||||
console.log(e.message);
|
||||
}
|
||||
}
|
||||
expect_stdout: [
|
||||
"true",
|
||||
"true",
|
||||
"42",
|
||||
"PASS",
|
||||
]
|
||||
}
|
||||
|
||||
if_body_return_2: {
|
||||
options = {
|
||||
if_return: true,
|
||||
}
|
||||
input: {
|
||||
var c = "PASS";
|
||||
function f(a, b) {
|
||||
if (0 + a) {
|
||||
if (b) throw new Error(c);
|
||||
return 42;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
console.log(f(0, 0));
|
||||
console.log(f(0, 1));
|
||||
console.log(f(1, 0));
|
||||
try {
|
||||
f(1, 1);
|
||||
console.log("FAIL");
|
||||
} catch (e) {
|
||||
console.log(e.message);
|
||||
}
|
||||
}
|
||||
expect: {
|
||||
var c = "PASS";
|
||||
function f(a, b) {
|
||||
if (0 + a) {
|
||||
if (b) throw new Error(c);
|
||||
return 42;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
console.log(f(0, 0));
|
||||
console.log(f(0, 1));
|
||||
console.log(f(1, 0));
|
||||
try {
|
||||
f(1, 1);
|
||||
console.log("FAIL");
|
||||
} catch (e) {
|
||||
console.log(e.message);
|
||||
}
|
||||
}
|
||||
expect_stdout: [
|
||||
"true",
|
||||
"true",
|
||||
"42",
|
||||
"PASS",
|
||||
]
|
||||
}
|
||||
|
||||
if_body_return_3: {
|
||||
options = {
|
||||
if_return: true,
|
||||
}
|
||||
input: {
|
||||
var c = "PASS";
|
||||
function f(a, b) {
|
||||
if (1 == a) {
|
||||
if (b) throw new Error(c);
|
||||
return 42;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
console.log(f(0, 0));
|
||||
console.log(f(0, 1));
|
||||
console.log(f(1, 0));
|
||||
try {
|
||||
f(1, 1);
|
||||
console.log("FAIL");
|
||||
} catch (e) {
|
||||
console.log(e.message);
|
||||
}
|
||||
}
|
||||
expect: {
|
||||
var c = "PASS";
|
||||
function f(a, b) {
|
||||
if (1 != a) return true;
|
||||
if (b) throw new Error(c);
|
||||
return 42;
|
||||
}
|
||||
console.log(f(0, 0));
|
||||
console.log(f(0, 1));
|
||||
console.log(f(1, 0));
|
||||
try {
|
||||
f(1, 1);
|
||||
console.log("FAIL");
|
||||
} catch (e) {
|
||||
console.log(e.message);
|
||||
}
|
||||
}
|
||||
expect_stdout: [
|
||||
"true",
|
||||
"true",
|
||||
"42",
|
||||
"PASS",
|
||||
]
|
||||
}
|
||||
|
||||
@@ -36,10 +36,10 @@ non_hoisted_function_after_return: {
|
||||
}
|
||||
}
|
||||
expect_warnings: [
|
||||
"WARN: Dropping unreachable code [test/compress/issue-1034.js:20,16]",
|
||||
"WARN: Dropping unreachable code [test/compress/issue-1034.js:23,16]",
|
||||
"WARN: Dropping unreachable code [test/compress/issue-1034.js:26,12]",
|
||||
"WARN: Dropping unused function UnusedFunction [test/compress/issue-1034.js:27,21]"
|
||||
"WARN: Dropping unreachable code [test/compress/issue-1034.js:4,16]",
|
||||
"WARN: Dropping unreachable code [test/compress/issue-1034.js:7,16]",
|
||||
"WARN: Dropping unreachable code [test/compress/issue-1034.js:10,12]",
|
||||
"WARN: Dropping unused function UnusedFunction [test/compress/issue-1034.js:11,21]"
|
||||
]
|
||||
}
|
||||
|
||||
@@ -59,7 +59,6 @@ non_hoisted_function_after_return_2a: {
|
||||
passes: 2,
|
||||
side_effects: true,
|
||||
unused: true,
|
||||
warnings: "verbose",
|
||||
}
|
||||
input: {
|
||||
function foo(x) {
|
||||
@@ -85,19 +84,19 @@ non_hoisted_function_after_return_2a: {
|
||||
}
|
||||
}
|
||||
expect_warnings: [
|
||||
"WARN: Dropping unreachable code [test/compress/issue-1034.js:68,16]",
|
||||
"WARN: Declarations in unreachable code! [test/compress/issue-1034.js:68,16]",
|
||||
"WARN: Dropping unreachable code [test/compress/issue-1034.js:71,16]",
|
||||
"WARN: Declarations in unreachable code! [test/compress/issue-1034.js:71,16]",
|
||||
"WARN: Dropping unused variable a [test/compress/issue-1034.js:68,20]",
|
||||
"WARN: Dropping unused function nope [test/compress/issue-1034.js:75,21]",
|
||||
"WARN: pass 0: last_count: Infinity, count: 37",
|
||||
"WARN: Dropping unreachable code [test/compress/issue-1034.js:73,12]",
|
||||
"WARN: Declarations in unreachable code! [test/compress/issue-1034.js:73,12]",
|
||||
"WARN: Dropping unreachable code [test/compress/issue-1034.js:76,12]",
|
||||
"WARN: Dropping unused variable b [test/compress/issue-1034.js:71,20]",
|
||||
"WARN: Dropping unused variable c [test/compress/issue-1034.js:73,16]",
|
||||
"WARN: pass 1: last_count: 37, count: 18",
|
||||
"WARN: Dropping unreachable code [test/compress/issue-1034.js:4,16]",
|
||||
"WARN: Declarations in unreachable code! [test/compress/issue-1034.js:4,16]",
|
||||
"WARN: Dropping unreachable code [test/compress/issue-1034.js:7,16]",
|
||||
"WARN: Declarations in unreachable code! [test/compress/issue-1034.js:7,16]",
|
||||
"WARN: Dropping unused variable a [test/compress/issue-1034.js:4,20]",
|
||||
"WARN: Dropping unused function nope [test/compress/issue-1034.js:11,21]",
|
||||
"INFO: pass 0: last_count: Infinity, count: 37",
|
||||
"WARN: Dropping unreachable code [test/compress/issue-1034.js:9,12]",
|
||||
"WARN: Declarations in unreachable code! [test/compress/issue-1034.js:9,12]",
|
||||
"WARN: Dropping unreachable code [test/compress/issue-1034.js:12,12]",
|
||||
"INFO: Dropping unused variable b [test/compress/issue-1034.js:7,20]",
|
||||
"INFO: Dropping unused variable c [test/compress/issue-1034.js:9,16]",
|
||||
"INFO: pass 1: last_count: 37, count: 18",
|
||||
]
|
||||
}
|
||||
|
||||
@@ -139,12 +138,11 @@ non_hoisted_function_after_return_2b: {
|
||||
}
|
||||
}
|
||||
expect_warnings: [
|
||||
// duplicate warnings no longer emitted
|
||||
"WARN: Dropping unreachable code [test/compress/issue-1034.js:126,16]",
|
||||
"WARN: Declarations in unreachable code! [test/compress/issue-1034.js:126,16]",
|
||||
"WARN: Dropping unreachable code [test/compress/issue-1034.js:128,12]",
|
||||
"WARN: Declarations in unreachable code! [test/compress/issue-1034.js:128,12]",
|
||||
"WARN: Dropping unreachable code [test/compress/issue-1034.js:132,12]",
|
||||
"WARN: Dropping unreachable code [test/compress/issue-1034.js:6,16]",
|
||||
"WARN: Declarations in unreachable code! [test/compress/issue-1034.js:6,16]",
|
||||
"WARN: Dropping unreachable code [test/compress/issue-1034.js:8,12]",
|
||||
"WARN: Declarations in unreachable code! [test/compress/issue-1034.js:8,12]",
|
||||
"WARN: Dropping unreachable code [test/compress/issue-1034.js:12,12]",
|
||||
]
|
||||
}
|
||||
|
||||
@@ -191,10 +189,10 @@ non_hoisted_function_after_return_strict: {
|
||||
}
|
||||
expect_stdout: "8 7"
|
||||
expect_warnings: [
|
||||
"WARN: Dropping unreachable code [test/compress/issue-1034.js:171,16]",
|
||||
"WARN: Dropping unreachable code [test/compress/issue-1034.js:174,16]",
|
||||
"WARN: Dropping unreachable code [test/compress/issue-1034.js:177,12]",
|
||||
"WARN: Dropping unused function UnusedFunction [test/compress/issue-1034.js:178,21]",
|
||||
"WARN: Dropping unreachable code [test/compress/issue-1034.js:5,16]",
|
||||
"WARN: Dropping unreachable code [test/compress/issue-1034.js:8,16]",
|
||||
"WARN: Dropping unreachable code [test/compress/issue-1034.js:11,12]",
|
||||
"WARN: Dropping unused function UnusedFunction [test/compress/issue-1034.js:12,21]",
|
||||
]
|
||||
}
|
||||
|
||||
@@ -214,7 +212,6 @@ non_hoisted_function_after_return_2a_strict: {
|
||||
passes: 2,
|
||||
side_effects: true,
|
||||
unused: true,
|
||||
warnings: "verbose",
|
||||
}
|
||||
input: {
|
||||
"use strict";
|
||||
@@ -245,19 +242,19 @@ non_hoisted_function_after_return_2a_strict: {
|
||||
}
|
||||
expect_stdout: "5 6"
|
||||
expect_warnings: [
|
||||
"WARN: Dropping unreachable code [test/compress/issue-1034.js:224,16]",
|
||||
"WARN: Declarations in unreachable code! [test/compress/issue-1034.js:224,16]",
|
||||
"WARN: Dropping unreachable code [test/compress/issue-1034.js:227,16]",
|
||||
"WARN: Declarations in unreachable code! [test/compress/issue-1034.js:227,16]",
|
||||
"WARN: Dropping unused variable a [test/compress/issue-1034.js:224,20]",
|
||||
"WARN: Dropping unused function nope [test/compress/issue-1034.js:231,21]",
|
||||
"WARN: pass 0: last_count: Infinity, count: 48",
|
||||
"WARN: Dropping unreachable code [test/compress/issue-1034.js:229,12]",
|
||||
"WARN: Declarations in unreachable code! [test/compress/issue-1034.js:229,12]",
|
||||
"WARN: Dropping unreachable code [test/compress/issue-1034.js:232,12]",
|
||||
"WARN: Dropping unused variable b [test/compress/issue-1034.js:227,20]",
|
||||
"WARN: Dropping unused variable c [test/compress/issue-1034.js:229,16]",
|
||||
"WARN: pass 1: last_count: 48, count: 29",
|
||||
"WARN: Dropping unreachable code [test/compress/issue-1034.js:5,16]",
|
||||
"WARN: Declarations in unreachable code! [test/compress/issue-1034.js:5,16]",
|
||||
"WARN: Dropping unreachable code [test/compress/issue-1034.js:8,16]",
|
||||
"WARN: Declarations in unreachable code! [test/compress/issue-1034.js:8,16]",
|
||||
"WARN: Dropping unused variable a [test/compress/issue-1034.js:5,20]",
|
||||
"WARN: Dropping unused function nope [test/compress/issue-1034.js:12,21]",
|
||||
"INFO: pass 0: last_count: Infinity, count: 48",
|
||||
"WARN: Dropping unreachable code [test/compress/issue-1034.js:10,12]",
|
||||
"WARN: Declarations in unreachable code! [test/compress/issue-1034.js:10,12]",
|
||||
"WARN: Dropping unreachable code [test/compress/issue-1034.js:13,12]",
|
||||
"INFO: Dropping unused variable b [test/compress/issue-1034.js:8,20]",
|
||||
"INFO: Dropping unused variable c [test/compress/issue-1034.js:10,16]",
|
||||
"INFO: pass 1: last_count: 48, count: 29",
|
||||
]
|
||||
}
|
||||
|
||||
@@ -304,11 +301,10 @@ non_hoisted_function_after_return_2b_strict: {
|
||||
}
|
||||
expect_stdout: "5 6"
|
||||
expect_warnings: [
|
||||
// duplicate warnings no longer emitted
|
||||
"WARN: Dropping unreachable code [test/compress/issue-1034.js:287,16]",
|
||||
"WARN: Declarations in unreachable code! [test/compress/issue-1034.js:287,16]",
|
||||
"WARN: Dropping unreachable code [test/compress/issue-1034.js:289,12]",
|
||||
"WARN: Declarations in unreachable code! [test/compress/issue-1034.js:289,12]",
|
||||
"WARN: Dropping unreachable code [test/compress/issue-1034.js:293,12]",
|
||||
"WARN: Dropping unreachable code [test/compress/issue-1034.js:7,16]",
|
||||
"WARN: Declarations in unreachable code! [test/compress/issue-1034.js:7,16]",
|
||||
"WARN: Dropping unreachable code [test/compress/issue-1034.js:9,12]",
|
||||
"WARN: Declarations in unreachable code! [test/compress/issue-1034.js:9,12]",
|
||||
"WARN: Dropping unreachable code [test/compress/issue-1034.js:13,12]",
|
||||
]
|
||||
}
|
||||
|
||||
@@ -48,13 +48,13 @@ pure_function_calls: {
|
||||
a.b(), f.g();
|
||||
}
|
||||
expect_warnings: [
|
||||
"WARN: Dropping __PURE__ call [test/compress/issue-1261.js:16,8]",
|
||||
"WARN: Dropping side-effect-free statement [test/compress/issue-1261.js:16,8]",
|
||||
"WARN: Dropping __PURE__ call [test/compress/issue-1261.js:29,37]",
|
||||
"WARN: Dropping unused variable iife2 [test/compress/issue-1261.js:29,16]",
|
||||
"WARN: Dropping side-effect-free statement [test/compress/issue-1261.js:27,8]",
|
||||
"WARN: Dropping __PURE__ call [test/compress/issue-1261.js:37,8]",
|
||||
"WARN: Dropping __PURE__ call [test/compress/issue-1261.js:38,31]",
|
||||
"WARN: Dropping __PURE__ call [test/compress/issue-1261.js:3,8]",
|
||||
"WARN: Dropping side-effect-free statement [test/compress/issue-1261.js:3,8]",
|
||||
"WARN: Dropping __PURE__ call [test/compress/issue-1261.js:16,37]",
|
||||
"WARN: Dropping unused variable iife2 [test/compress/issue-1261.js:16,16]",
|
||||
"WARN: Dropping side-effect-free statement [test/compress/issue-1261.js:14,8]",
|
||||
"WARN: Dropping __PURE__ call [test/compress/issue-1261.js:24,8]",
|
||||
"WARN: Dropping __PURE__ call [test/compress/issue-1261.js:25,31]",
|
||||
]
|
||||
}
|
||||
|
||||
@@ -110,17 +110,17 @@ pure_function_calls_toplevel: {
|
||||
a.b(), f.g();
|
||||
}
|
||||
expect_warnings: [
|
||||
"WARN: Dropping __PURE__ call [test/compress/issue-1261.js:77,8]",
|
||||
"WARN: Dropping side-effect-free statement [test/compress/issue-1261.js:77,8]",
|
||||
"WARN: Dropping __PURE__ call [test/compress/issue-1261.js:90,37]",
|
||||
"WARN: Dropping unused variable iife2 [test/compress/issue-1261.js:90,16]",
|
||||
"WARN: Dropping side-effect-free statement [test/compress/issue-1261.js:88,8]",
|
||||
"WARN: Dropping __PURE__ call [test/compress/issue-1261.js:105,8]",
|
||||
"WARN: Dropping __PURE__ call [test/compress/issue-1261.js:106,31]",
|
||||
"WARN: Dropping __PURE__ call [test/compress/issue-1261.js:82,33]",
|
||||
"WARN: Dropping unused variable iife1 [test/compress/issue-1261.js:82,12]",
|
||||
"WARN: Dropping __PURE__ call [test/compress/issue-1261.js:98,45]",
|
||||
"WARN: Dropping unused variable MyClass [test/compress/issue-1261.js:98,12]",
|
||||
"WARN: Dropping __PURE__ call [test/compress/issue-1261.js:3,8]",
|
||||
"WARN: Dropping side-effect-free statement [test/compress/issue-1261.js:3,8]",
|
||||
"WARN: Dropping __PURE__ call [test/compress/issue-1261.js:16,37]",
|
||||
"WARN: Dropping unused variable iife2 [test/compress/issue-1261.js:16,16]",
|
||||
"WARN: Dropping side-effect-free statement [test/compress/issue-1261.js:14,8]",
|
||||
"WARN: Dropping __PURE__ call [test/compress/issue-1261.js:31,8]",
|
||||
"WARN: Dropping __PURE__ call [test/compress/issue-1261.js:32,31]",
|
||||
"WARN: Dropping __PURE__ call [test/compress/issue-1261.js:8,33]",
|
||||
"WARN: Dropping unused variable iife1 [test/compress/issue-1261.js:8,12]",
|
||||
"WARN: Dropping __PURE__ call [test/compress/issue-1261.js:24,45]",
|
||||
"WARN: Dropping unused variable MyClass [test/compress/issue-1261.js:24,12]",
|
||||
]
|
||||
}
|
||||
|
||||
@@ -155,29 +155,29 @@ should_warn: {
|
||||
baz();
|
||||
}
|
||||
expect_warnings: [
|
||||
"WARN: Dropping __PURE__ call [test/compress/issue-1261.js:135,61]",
|
||||
"WARN: Dropping __PURE__ call [test/compress/issue-1261.js:135,23]",
|
||||
"WARN: Dropping side-effect-free statement [test/compress/issue-1261.js:135,23]",
|
||||
"WARN: Boolean || always true [test/compress/issue-1261.js:136,23]",
|
||||
"WARN: Dropping __PURE__ call [test/compress/issue-1261.js:136,23]",
|
||||
"WARN: Condition always true [test/compress/issue-1261.js:136,23]",
|
||||
"WARN: Condition left of || always true [test/compress/issue-1261.js:137,8]",
|
||||
"WARN: Condition always true [test/compress/issue-1261.js:137,8]",
|
||||
"WARN: Boolean && always false [test/compress/issue-1261.js:138,23]",
|
||||
"WARN: Dropping __PURE__ call [test/compress/issue-1261.js:138,23]",
|
||||
"WARN: Condition always false [test/compress/issue-1261.js:138,23]",
|
||||
"WARN: Condition left of && always false [test/compress/issue-1261.js:139,8]",
|
||||
"WARN: Condition always false [test/compress/issue-1261.js:139,8]",
|
||||
"WARN: + in boolean context always true [test/compress/issue-1261.js:140,23]",
|
||||
"WARN: Dropping __PURE__ call [test/compress/issue-1261.js:140,23]",
|
||||
"WARN: Condition always true [test/compress/issue-1261.js:140,23]",
|
||||
"WARN: + in boolean context always true [test/compress/issue-1261.js:141,8]",
|
||||
"WARN: Dropping __PURE__ call [test/compress/issue-1261.js:141,31]",
|
||||
"WARN: Condition always true [test/compress/issue-1261.js:141,8]",
|
||||
"WARN: Dropping __PURE__ call [test/compress/issue-1261.js:142,23]",
|
||||
"WARN: Condition always true [test/compress/issue-1261.js:143,8]",
|
||||
"WARN: Dropping __PURE__ call [test/compress/issue-1261.js:143,24]",
|
||||
"WARN: Dropping __PURE__ call [test/compress/issue-1261.js:144,31]",
|
||||
"WARN: Condition always false [test/compress/issue-1261.js:144,8]",
|
||||
"WARN: Dropping __PURE__ call [test/compress/issue-1261.js:1,61]",
|
||||
"WARN: Dropping __PURE__ call [test/compress/issue-1261.js:1,23]",
|
||||
"WARN: Dropping side-effect-free statement [test/compress/issue-1261.js:1,23]",
|
||||
"WARN: Boolean || always true [test/compress/issue-1261.js:2,23]",
|
||||
"WARN: Dropping __PURE__ call [test/compress/issue-1261.js:2,23]",
|
||||
"WARN: Condition always true [test/compress/issue-1261.js:2,23]",
|
||||
"WARN: Condition left of || always true [test/compress/issue-1261.js:3,8]",
|
||||
"WARN: Condition always true [test/compress/issue-1261.js:3,8]",
|
||||
"WARN: Boolean && always false [test/compress/issue-1261.js:4,23]",
|
||||
"WARN: Dropping __PURE__ call [test/compress/issue-1261.js:4,23]",
|
||||
"WARN: Condition always false [test/compress/issue-1261.js:4,23]",
|
||||
"WARN: Condition left of && always false [test/compress/issue-1261.js:5,8]",
|
||||
"WARN: Condition always false [test/compress/issue-1261.js:5,8]",
|
||||
"WARN: + in boolean context always true [test/compress/issue-1261.js:6,23]",
|
||||
"WARN: Dropping __PURE__ call [test/compress/issue-1261.js:6,23]",
|
||||
"WARN: Condition always true [test/compress/issue-1261.js:6,23]",
|
||||
"WARN: + in boolean context always true [test/compress/issue-1261.js:7,8]",
|
||||
"WARN: Dropping __PURE__ call [test/compress/issue-1261.js:7,31]",
|
||||
"WARN: Condition always true [test/compress/issue-1261.js:7,8]",
|
||||
"WARN: Dropping __PURE__ call [test/compress/issue-1261.js:8,23]",
|
||||
"WARN: Condition always true [test/compress/issue-1261.js:9,8]",
|
||||
"WARN: Dropping __PURE__ call [test/compress/issue-1261.js:9,24]",
|
||||
"WARN: Dropping __PURE__ call [test/compress/issue-1261.js:10,31]",
|
||||
"WARN: Condition always false [test/compress/issue-1261.js:10,8]",
|
||||
]
|
||||
}
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
|
||||
issue_1639_1: {
|
||||
options = {
|
||||
booleans: true,
|
||||
@@ -12,7 +11,6 @@ issue_1639_1: {
|
||||
}
|
||||
input: {
|
||||
var a = 100, b = 10;
|
||||
|
||||
var L1 = 5;
|
||||
while (--L1 > 0) {
|
||||
if ((--b), false) {
|
||||
@@ -21,7 +19,6 @@ issue_1639_1: {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
console.log(a, b);
|
||||
}
|
||||
expect: {
|
||||
@@ -29,7 +26,7 @@ issue_1639_1: {
|
||||
if (--b, 0) var ignore = 0;
|
||||
console.log(a, b);
|
||||
}
|
||||
expect_stdout: true
|
||||
expect_stdout: "100 6"
|
||||
}
|
||||
|
||||
issue_1639_2: {
|
||||
@@ -44,25 +41,23 @@ issue_1639_2: {
|
||||
}
|
||||
input: {
|
||||
var a = 100, b = 10;
|
||||
|
||||
function f19() {
|
||||
if (++a, false)
|
||||
if (a)
|
||||
if (++a);
|
||||
}
|
||||
f19();
|
||||
|
||||
console.log(a, b);
|
||||
}
|
||||
expect: {
|
||||
var a = 100, b = 10;
|
||||
function f19() {
|
||||
++a, 0;
|
||||
++a, 1;
|
||||
}
|
||||
f19(),
|
||||
console.log(a, b);
|
||||
}
|
||||
expect_stdout: true
|
||||
expect_stdout: "101 10"
|
||||
}
|
||||
|
||||
issue_1639_3: {
|
||||
@@ -84,5 +79,5 @@ issue_1639_3: {
|
||||
a++,
|
||||
console.log(a, b);
|
||||
}
|
||||
expect_stdout: true
|
||||
expect_stdout: "101 10"
|
||||
}
|
||||
|
||||
@@ -366,7 +366,7 @@ mangle_catch_redef_3: {
|
||||
console.log(o);
|
||||
}
|
||||
expect_exact: 'var o="PASS";try{throw 0}catch(o){(function(){function c(){o="FAIL"}c(),c()})()}console.log(o);'
|
||||
expect_stdout: "PASS"
|
||||
expect_stdout: true
|
||||
}
|
||||
|
||||
mangle_catch_redef_3_toplevel: {
|
||||
@@ -389,10 +389,10 @@ mangle_catch_redef_3_toplevel: {
|
||||
console.log(o);
|
||||
}
|
||||
expect_exact: 'var c="PASS";try{throw 0}catch(c){(function(){function o(){c="FAIL"}o(),o()})()}console.log(c);'
|
||||
expect_stdout: "PASS"
|
||||
expect_stdout: true
|
||||
}
|
||||
|
||||
mangle_catch_redef_ie8_3: {
|
||||
mangle_catch_redef_3_ie8: {
|
||||
mangle = {
|
||||
ie8: true,
|
||||
toplevel: false,
|
||||
@@ -412,7 +412,7 @@ mangle_catch_redef_ie8_3: {
|
||||
console.log(o);
|
||||
}
|
||||
expect_exact: 'var o="PASS";try{throw 0}catch(o){(function(){function c(){o="FAIL"}c(),c()})()}console.log(o);'
|
||||
expect_stdout: "PASS"
|
||||
expect_stdout: true
|
||||
}
|
||||
|
||||
mangle_catch_redef_3_ie8_toplevel: {
|
||||
@@ -435,5 +435,5 @@ mangle_catch_redef_3_ie8_toplevel: {
|
||||
console.log(o);
|
||||
}
|
||||
expect_exact: 'var c="PASS";try{throw 0}catch(c){(function(){function o(){c="FAIL"}o(),o()})()}console.log(c);'
|
||||
expect_stdout: "PASS"
|
||||
expect_stdout: true
|
||||
}
|
||||
|
||||
@@ -64,11 +64,11 @@ mixed: {
|
||||
x = 0;
|
||||
}
|
||||
expect_warnings: [
|
||||
"WARN: global_defs ENV redefined [test/compress/issue-208.js:45,12]",
|
||||
"WARN: global_defs FOO redefined [test/compress/issue-208.js:46,12]",
|
||||
"WARN: global_defs FOO redefined [test/compress/issue-208.js:48,10]",
|
||||
"WARN: global_defs DEBUG redefined [test/compress/issue-208.js:49,8]",
|
||||
"WARN: global_defs DEBUG redefined [test/compress/issue-208.js:50,8]",
|
||||
"WARN: global_defs DEBUG redefined [test/compress/issue-208.js:51,8]",
|
||||
"WARN: global_defs ENV redefined [test/compress/issue-208.js:1,12]",
|
||||
"WARN: global_defs FOO redefined [test/compress/issue-208.js:2,12]",
|
||||
"WARN: global_defs FOO redefined [test/compress/issue-208.js:4,10]",
|
||||
"WARN: global_defs DEBUG redefined [test/compress/issue-208.js:5,8]",
|
||||
"WARN: global_defs DEBUG redefined [test/compress/issue-208.js:6,8]",
|
||||
"WARN: global_defs DEBUG redefined [test/compress/issue-208.js:7,8]",
|
||||
]
|
||||
}
|
||||
|
||||
@@ -93,6 +93,6 @@ regexp: {
|
||||
RegExp("should", "fail");
|
||||
}
|
||||
expect_warnings: [
|
||||
'WARN: Error converting RegExp("should","fail") [test/compress/issue-269.js:86,2]',
|
||||
'WARN: Error converting RegExp("should","fail") [test/compress/issue-269.js:5,2]',
|
||||
]
|
||||
}
|
||||
|
||||
@@ -26,7 +26,7 @@ warn: {
|
||||
}().length);
|
||||
}
|
||||
expect_warnings: [
|
||||
"WARN: Function.protoype.caller not supported [test/compress/issue-2719.js:17,19]",
|
||||
"WARN: Function.protoype.arguments not supported [test/compress/issue-2719.js:17,19]",
|
||||
"WARN: Function.prototype.caller not supported [test/compress/issue-2719.js:5,19]",
|
||||
"WARN: Function.prototype.arguments not supported [test/compress/issue-2719.js:5,19]",
|
||||
]
|
||||
}
|
||||
|
||||
1157
test/compress/keep_fargs.js
Normal file
1157
test/compress/keep_fargs.js
Normal file
File diff suppressed because it is too large
Load Diff
@@ -646,3 +646,46 @@ issue_2904: {
|
||||
}
|
||||
expect_stdout: "1"
|
||||
}
|
||||
|
||||
issue_3371: {
|
||||
options = {
|
||||
functions: true,
|
||||
join_vars: true,
|
||||
loops: true,
|
||||
reduce_vars: true,
|
||||
unused: true,
|
||||
}
|
||||
input: {
|
||||
(function() {
|
||||
var a = function() {
|
||||
console.log("PASS");
|
||||
};
|
||||
while (a());
|
||||
})();
|
||||
}
|
||||
expect: {
|
||||
(function() {
|
||||
function a() {
|
||||
console.log("PASS");
|
||||
}
|
||||
for (; a(); );
|
||||
})();
|
||||
}
|
||||
expect_stdout: "PASS"
|
||||
}
|
||||
|
||||
step: {
|
||||
options = {
|
||||
loops: true,
|
||||
side_effects: true,
|
||||
}
|
||||
input: {
|
||||
for (var i = 0; i < 42; "foo", i++, "bar");
|
||||
console.log(i);
|
||||
}
|
||||
expect: {
|
||||
for (var i = 0; i < 42; i++);
|
||||
console.log(i);
|
||||
}
|
||||
expect_stdout: "42"
|
||||
}
|
||||
|
||||
@@ -51,17 +51,20 @@ comparisons: {
|
||||
comparisons: true,
|
||||
}
|
||||
input: {
|
||||
var x = "42", y = "0x30";
|
||||
console.log(
|
||||
~x === 42,
|
||||
x % n === 42
|
||||
x % y === 42
|
||||
);
|
||||
}
|
||||
expect: {
|
||||
var x = "42", y = "0x30";
|
||||
console.log(
|
||||
42 == ~x,
|
||||
x % n == 42
|
||||
x % y == 42
|
||||
);
|
||||
}
|
||||
expect_stdout: "false true"
|
||||
}
|
||||
|
||||
evaluate_1: {
|
||||
@@ -103,7 +106,7 @@ evaluate_1: {
|
||||
}
|
||||
}
|
||||
|
||||
evaluate_2: {
|
||||
evaluate_1_unsafe_math: {
|
||||
options = {
|
||||
evaluate: true,
|
||||
unsafe_math: true,
|
||||
@@ -118,6 +121,8 @@ evaluate_2: {
|
||||
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)
|
||||
);
|
||||
@@ -126,18 +131,138 @@ evaluate_2: {
|
||||
console.log(
|
||||
x + 1 + 2,
|
||||
2 * x,
|
||||
3 + +x,
|
||||
+x + 3,
|
||||
1 + x + 2 + 3,
|
||||
3 | x,
|
||||
6 + x--,
|
||||
6 + x*y,
|
||||
x*y + 6,
|
||||
1 + (2 + x + 3),
|
||||
6 + ~x,
|
||||
5 - y + ~x,
|
||||
0 & x,
|
||||
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: {
|
||||
options = {
|
||||
evaluate: true,
|
||||
@@ -148,7 +273,7 @@ evaluate_3: {
|
||||
console.log(1 + Number(x) + 2);
|
||||
}
|
||||
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: {
|
||||
options = {
|
||||
evaluate: true,
|
||||
@@ -230,3 +701,219 @@ unary_binary_parenthesis: {
|
||||
}
|
||||
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 - "2" - 1,
|
||||
].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,
|
||||
"3" - a + 1,
|
||||
2 - a,
|
||||
].forEach(function(n) {
|
||||
console.log(typeof n, n);
|
||||
});
|
||||
}
|
||||
expect_stdout: [
|
||||
"string 321",
|
||||
"number 31",
|
||||
"number 2",
|
||||
"number 0",
|
||||
]
|
||||
}
|
||||
|
||||
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",
|
||||
]
|
||||
}
|
||||
181
test/compress/preserve_line.js
Normal file
181
test/compress/preserve_line.js
Normal file
@@ -0,0 +1,181 @@
|
||||
return_1: {
|
||||
beautify = {
|
||||
beautify: false,
|
||||
preserve_line: true,
|
||||
}
|
||||
input: {
|
||||
console.log(function f() {
|
||||
return (
|
||||
f.toString() != 42
|
||||
);
|
||||
}());
|
||||
}
|
||||
expect_exact: [
|
||||
"console.log(function f(){",
|
||||
"",
|
||||
"return 42!=f.toString()}());",
|
||||
]
|
||||
expect_stdout: "true"
|
||||
}
|
||||
|
||||
return_2: {
|
||||
beautify = {
|
||||
beautify: true,
|
||||
preserve_line: true,
|
||||
}
|
||||
input: {
|
||||
console.log(function f() {
|
||||
return (
|
||||
f.toString() != 42
|
||||
);
|
||||
}());
|
||||
}
|
||||
expect_exact: [
|
||||
"console.log(function f() {",
|
||||
"",
|
||||
" return 42 != f.toString();",
|
||||
"}());",
|
||||
]
|
||||
expect_stdout: "true"
|
||||
}
|
||||
|
||||
return_3: {
|
||||
options = {}
|
||||
beautify = {
|
||||
beautify: false,
|
||||
preserve_line: true,
|
||||
}
|
||||
input: {
|
||||
console.log(function f() {
|
||||
return (
|
||||
f.toString() != 42
|
||||
);
|
||||
}());
|
||||
}
|
||||
expect_exact: [
|
||||
"console.log(function f(){",
|
||||
"",
|
||||
"return 42!=f.toString()}());",
|
||||
]
|
||||
expect_stdout: "true"
|
||||
}
|
||||
|
||||
return_4: {
|
||||
options = {}
|
||||
beautify = {
|
||||
beautify: true,
|
||||
preserve_line: true,
|
||||
}
|
||||
input: {
|
||||
console.log(function f() {
|
||||
return (
|
||||
f.toString() != 42
|
||||
);
|
||||
}());
|
||||
}
|
||||
expect_exact: [
|
||||
"console.log(function f() {",
|
||||
"",
|
||||
" return 42 != f.toString();",
|
||||
"}());",
|
||||
]
|
||||
expect_stdout: "true"
|
||||
}
|
||||
|
||||
return_5: {
|
||||
beautify = {
|
||||
beautify: false,
|
||||
preserve_line: true,
|
||||
}
|
||||
input: {
|
||||
_is_selected = function(tags, slug) {
|
||||
var ref;
|
||||
return (ref = _.find(tags, {
|
||||
slug: slug
|
||||
})) != null ? ref.selected : void 0;
|
||||
};
|
||||
}
|
||||
expect_exact: [
|
||||
"_is_selected=function(tags,slug){",
|
||||
"var ref",
|
||||
"",
|
||||
"",
|
||||
";return null!=(ref=_.find(tags,{slug:slug}))?ref.selected:void 0};",
|
||||
]
|
||||
}
|
||||
|
||||
return_6: {
|
||||
beautify = {
|
||||
beautify: true,
|
||||
preserve_line: true,
|
||||
}
|
||||
input: {
|
||||
_is_selected = function(tags, slug) {
|
||||
var ref;
|
||||
return (ref = _.find(tags, {
|
||||
slug: slug
|
||||
})) != null ? ref.selected : void 0;
|
||||
};
|
||||
}
|
||||
expect_exact: [
|
||||
"_is_selected = function(tags, slug) {",
|
||||
" var ref;",
|
||||
"",
|
||||
"",
|
||||
" return null != (ref = _.find(tags, {",
|
||||
" slug: slug",
|
||||
" })) ? ref.selected : void 0;",
|
||||
"};",
|
||||
]
|
||||
}
|
||||
|
||||
return_7: {
|
||||
options = {}
|
||||
mangle = {}
|
||||
beautify = {
|
||||
beautify: false,
|
||||
preserve_line: true,
|
||||
}
|
||||
input: {
|
||||
_is_selected = function(tags, slug) {
|
||||
var ref;
|
||||
return (ref = _.find(tags, {
|
||||
slug: slug
|
||||
})) != null ? ref.selected : void 0;
|
||||
};
|
||||
}
|
||||
expect_exact: [
|
||||
"_is_selected=function(e,l){",
|
||||
"var n",
|
||||
"",
|
||||
"",
|
||||
";return null!=(n=_.find(e,{slug:l}))?n.selected:void 0};",
|
||||
]
|
||||
}
|
||||
|
||||
return_8: {
|
||||
options = {}
|
||||
mangle = {}
|
||||
beautify = {
|
||||
beautify: true,
|
||||
preserve_line: true,
|
||||
}
|
||||
input: {
|
||||
_is_selected = function(tags, slug) {
|
||||
var ref;
|
||||
return (ref = _.find(tags, {
|
||||
slug: slug
|
||||
})) != null ? ref.selected : void 0;
|
||||
};
|
||||
}
|
||||
expect_exact: [
|
||||
"_is_selected = function(e, l) {",
|
||||
" var n;",
|
||||
"",
|
||||
"",
|
||||
" return null != (n = _.find(e, {",
|
||||
" slug: l",
|
||||
" })) ? n.selected : void 0;",
|
||||
"};",
|
||||
]
|
||||
}
|
||||
@@ -1832,3 +1832,59 @@ issue_3188_3: {
|
||||
}
|
||||
expect_stdout: "PASS"
|
||||
}
|
||||
|
||||
join_expr: {
|
||||
options = {
|
||||
evaluate: true,
|
||||
join_vars: true,
|
||||
}
|
||||
input: {
|
||||
var c = "FAIL";
|
||||
(function() {
|
||||
var a = 0;
|
||||
switch ((a = {}) && (a.b = 0)) {
|
||||
case 0:
|
||||
c = "PASS";
|
||||
}
|
||||
})();
|
||||
console.log(c);
|
||||
}
|
||||
expect: {
|
||||
var c = "FAIL";
|
||||
(function() {
|
||||
var a = 0;
|
||||
switch (a = { b: 0 }, a.b) {
|
||||
case 0:
|
||||
c = "PASS";
|
||||
}
|
||||
})();
|
||||
console.log(c);
|
||||
}
|
||||
expect_stdout: "PASS"
|
||||
}
|
||||
|
||||
issue_3389: {
|
||||
options = {
|
||||
evaluate: true,
|
||||
properties: true,
|
||||
reduce_vars: true,
|
||||
unsafe: true,
|
||||
}
|
||||
input: {
|
||||
(function() {
|
||||
var a = "PASS";
|
||||
if (delete b)
|
||||
b = a[null] = 42;
|
||||
console.log(a);
|
||||
})();
|
||||
}
|
||||
expect: {
|
||||
(function() {
|
||||
var a = "PASS";
|
||||
if (delete b)
|
||||
b = a.null = 42;
|
||||
console.log(a);
|
||||
})();
|
||||
}
|
||||
expect_stdout: "PASS"
|
||||
}
|
||||
|
||||
@@ -642,3 +642,41 @@ issue_3065_4: {
|
||||
})();
|
||||
}
|
||||
}
|
||||
|
||||
issue_3325_1: {
|
||||
options = {
|
||||
pure_funcs: "cb",
|
||||
side_effects: true,
|
||||
}
|
||||
input: {
|
||||
function cb() {
|
||||
console.log("PASS");
|
||||
}
|
||||
cb();
|
||||
}
|
||||
expect: {
|
||||
function cb() {
|
||||
console.log("PASS");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
issue_3325_2: {
|
||||
options = {
|
||||
pure_funcs: "xxxcbxxx",
|
||||
side_effects: true,
|
||||
}
|
||||
input: {
|
||||
function cb() {
|
||||
console.log("PASS");
|
||||
}
|
||||
cb();
|
||||
}
|
||||
expect: {
|
||||
function cb() {
|
||||
console.log("PASS");
|
||||
}
|
||||
cb();
|
||||
}
|
||||
expect_stdout: "PASS"
|
||||
}
|
||||
|
||||
@@ -1161,3 +1161,51 @@ collapse_rhs_lhs: {
|
||||
}
|
||||
expect_stdout: "1 3"
|
||||
}
|
||||
|
||||
drop_arguments: {
|
||||
options = {
|
||||
pure_getters: "strict",
|
||||
side_effects: true,
|
||||
}
|
||||
input: {
|
||||
(function() {
|
||||
arguments.slice = function() {
|
||||
console.log("PASS");
|
||||
};
|
||||
arguments[42];
|
||||
arguments.length;
|
||||
arguments.slice();
|
||||
})();
|
||||
}
|
||||
expect: {
|
||||
(function() {
|
||||
arguments.slice = function() {
|
||||
console.log("PASS");
|
||||
};
|
||||
arguments.slice();
|
||||
})();
|
||||
}
|
||||
expect_stdout: "PASS"
|
||||
}
|
||||
|
||||
issue_3427: {
|
||||
options = {
|
||||
assignments: true,
|
||||
collapse_vars: true,
|
||||
inline: true,
|
||||
passes: 2,
|
||||
pure_getters: "strict",
|
||||
sequences: true,
|
||||
side_effects: true,
|
||||
toplevel: true,
|
||||
unused: true,
|
||||
}
|
||||
input: {
|
||||
var a;
|
||||
(function(b) {
|
||||
b.p = 42;
|
||||
})(a || (a = {}));
|
||||
}
|
||||
expect: {}
|
||||
expect_stdout: true
|
||||
}
|
||||
|
||||
@@ -192,38 +192,35 @@ unsafe_evaluate: {
|
||||
unused: true,
|
||||
}
|
||||
input: {
|
||||
function f0(){
|
||||
var a = {
|
||||
b:1
|
||||
};
|
||||
function f0() {
|
||||
var a = { b: 1 };
|
||||
console.log(a.b + 3);
|
||||
}
|
||||
|
||||
function f1(){
|
||||
function f1() {
|
||||
var a = {
|
||||
b:{
|
||||
c:1
|
||||
},
|
||||
d:2
|
||||
b: { c: 1 },
|
||||
d: 2
|
||||
};
|
||||
console.log(a.b + 3, a.d + 4, a.b.c + 5, a.d.c + 6);
|
||||
}
|
||||
f0();
|
||||
f1();
|
||||
}
|
||||
expect: {
|
||||
function f0(){
|
||||
function f0() {
|
||||
console.log(4);
|
||||
}
|
||||
|
||||
function f1(){
|
||||
function f1() {
|
||||
var a = {
|
||||
b:{
|
||||
c:1
|
||||
},
|
||||
d:2
|
||||
b: { c: 1 },
|
||||
d: 2
|
||||
};
|
||||
console.log(a.b + 3, 6, 6, 2..c + 6);
|
||||
console.log(a.b + 3, 6, 6, NaN);
|
||||
}
|
||||
f0();
|
||||
f1();
|
||||
}
|
||||
expect_stdout: true
|
||||
}
|
||||
|
||||
unsafe_evaluate_side_effect_free_1: {
|
||||
@@ -281,8 +278,8 @@ unsafe_evaluate_escaped: {
|
||||
console.log(function(){ var o={p:3},a=[o]; console.log(a[0].p++); return o.p; }());
|
||||
}
|
||||
expect: {
|
||||
console.log(function(){ var o={p:1}; console.log(o, o.p); return o.p; }());
|
||||
console.log(function(){ var o={p:2}; console.log(o.p, o); return o.p; }());
|
||||
console.log(function(){ var o={p:1}; console.log(o, 1); return o.p; }());
|
||||
console.log(function(){ var o={p:2}; console.log(2, o); return o.p; }());
|
||||
console.log(function(){ var o={p:3},a=[o]; console.log(a[0].p++); return o.p; }());
|
||||
}
|
||||
expect_stdout: true
|
||||
@@ -2740,18 +2737,18 @@ issue_1814_2: {
|
||||
!function() {
|
||||
var b = a + 1;
|
||||
!function(a) {
|
||||
console.log(a++, b);
|
||||
console.log(b, a++);
|
||||
}(0);
|
||||
}();
|
||||
}
|
||||
expect: {
|
||||
!function() {
|
||||
!function(a) {
|
||||
console.log(a++, "321");
|
||||
console.log("321", a++);
|
||||
}(0);
|
||||
}();
|
||||
}
|
||||
expect_stdout: "0 '321'"
|
||||
expect_stdout: "321 0"
|
||||
}
|
||||
|
||||
try_abort: {
|
||||
@@ -4950,7 +4947,7 @@ defun_single_use_loop: {
|
||||
unused: true,
|
||||
}
|
||||
input: {
|
||||
for (var x, i = 2; --i >= 0; ) {
|
||||
for (var x, i = 2; --i >= 0;) {
|
||||
var y = x;
|
||||
x = f;
|
||||
console.log(x === y);
|
||||
@@ -4958,7 +4955,7 @@ defun_single_use_loop: {
|
||||
function f() {};
|
||||
}
|
||||
expect: {
|
||||
for (var x, i = 2; --i >= 0; ) {
|
||||
for (var x, i = 2; --i >= 0;) {
|
||||
var y = x;
|
||||
x = f;
|
||||
console.log(x === y);
|
||||
@@ -5231,11 +5228,11 @@ defun_catch_4: {
|
||||
try {
|
||||
throw 42;
|
||||
} catch (a) {
|
||||
function a() {}
|
||||
console.log(a);
|
||||
}
|
||||
}
|
||||
expect_stdout: true
|
||||
expect_stdout: "42"
|
||||
node_version: "<=4"
|
||||
}
|
||||
|
||||
defun_catch_5: {
|
||||
@@ -5257,10 +5254,10 @@ defun_catch_5: {
|
||||
throw 42;
|
||||
} catch (a) {
|
||||
console.log(a);
|
||||
function a() {}
|
||||
}
|
||||
}
|
||||
expect_stdout: true
|
||||
expect_stdout: "42"
|
||||
node_version: "<=4"
|
||||
}
|
||||
|
||||
defun_catch_6: {
|
||||
@@ -5354,6 +5351,7 @@ issue_2774: {
|
||||
|
||||
issue_2799_1: {
|
||||
options = {
|
||||
passes: 2,
|
||||
reduce_funcs: true,
|
||||
reduce_vars: true,
|
||||
unused: true,
|
||||
@@ -6429,3 +6427,356 @@ issue_3140_5: {
|
||||
}
|
||||
expect_stdout: "1"
|
||||
}
|
||||
|
||||
issue_3240_1: {
|
||||
options = {
|
||||
reduce_funcs: true,
|
||||
reduce_vars: true,
|
||||
unused: true,
|
||||
}
|
||||
input: {
|
||||
(function() {
|
||||
f(1);
|
||||
function f(a) {
|
||||
console.log(a);
|
||||
var g = function() {
|
||||
f(a - 1);
|
||||
};
|
||||
if (a) g();
|
||||
}
|
||||
})();
|
||||
}
|
||||
expect: {
|
||||
(function() {
|
||||
(function f(a) {
|
||||
console.log(a);
|
||||
var g = function() {
|
||||
f(a - 1);
|
||||
};
|
||||
if (a) g();
|
||||
})(1);
|
||||
})();
|
||||
}
|
||||
expect_stdout: [
|
||||
"1",
|
||||
"0",
|
||||
]
|
||||
}
|
||||
|
||||
issue_3240_2: {
|
||||
options = {
|
||||
passes: 2,
|
||||
reduce_funcs: true,
|
||||
reduce_vars: true,
|
||||
unused: true,
|
||||
}
|
||||
input: {
|
||||
(function() {
|
||||
f(1);
|
||||
function f(a) {
|
||||
console.log(a);
|
||||
var g = function() {
|
||||
f(a - 1);
|
||||
};
|
||||
if (a) g();
|
||||
}
|
||||
})();
|
||||
}
|
||||
expect: {
|
||||
(function() {
|
||||
(function f(a) {
|
||||
console.log(a);
|
||||
if (a) (function() {
|
||||
f(a - 1);
|
||||
})();
|
||||
})(1);
|
||||
})();
|
||||
}
|
||||
expect_stdout: [
|
||||
"1",
|
||||
"0",
|
||||
]
|
||||
}
|
||||
|
||||
issue_3240_3: {
|
||||
options = {
|
||||
reduce_funcs: true,
|
||||
reduce_vars: true,
|
||||
unused: true,
|
||||
}
|
||||
input: {
|
||||
(function() {
|
||||
f();
|
||||
function f(b) {
|
||||
if (!f.a) f.a = 0;
|
||||
console.log(f.a.toString());
|
||||
var g = function() {
|
||||
(b ? function() {} : function() {
|
||||
f.a++;
|
||||
f(1);
|
||||
})();
|
||||
};
|
||||
g();
|
||||
}
|
||||
})();
|
||||
}
|
||||
expect: {
|
||||
(function() {
|
||||
(function f(b) {
|
||||
if (!f.a) f.a = 0;
|
||||
console.log(f.a.toString());
|
||||
var g = function() {
|
||||
(b ? function() {} : function() {
|
||||
f.a++;
|
||||
f(1);
|
||||
})();
|
||||
};
|
||||
g();
|
||||
})();
|
||||
})();
|
||||
}
|
||||
expect_stdout: [
|
||||
"0",
|
||||
"1",
|
||||
]
|
||||
}
|
||||
|
||||
issue_3240_4: {
|
||||
options = {
|
||||
passes: 2,
|
||||
reduce_funcs: true,
|
||||
reduce_vars: true,
|
||||
unused: true,
|
||||
}
|
||||
input: {
|
||||
(function() {
|
||||
f();
|
||||
function f(b) {
|
||||
if (!f.a) f.a = 0;
|
||||
console.log(f.a.toString());
|
||||
var g = function() {
|
||||
(b ? function() {} : function() {
|
||||
f.a++;
|
||||
f(1);
|
||||
})();
|
||||
};
|
||||
g();
|
||||
}
|
||||
})();
|
||||
}
|
||||
expect: {
|
||||
(function() {
|
||||
(function f(b) {
|
||||
if (!f.a) f.a = 0;
|
||||
console.log(f.a.toString());
|
||||
(function() {
|
||||
(b ? function() {} : function() {
|
||||
f.a++;
|
||||
f(1);
|
||||
})();
|
||||
})();
|
||||
})();
|
||||
})();
|
||||
}
|
||||
expect_stdout: [
|
||||
"0",
|
||||
"1",
|
||||
]
|
||||
}
|
||||
|
||||
issues_3267_1: {
|
||||
options = {
|
||||
collapse_vars: true,
|
||||
conditionals: true,
|
||||
dead_code: true,
|
||||
evaluate: true,
|
||||
inline: true,
|
||||
reduce_vars: true,
|
||||
sequences: true,
|
||||
side_effects: true,
|
||||
unused: true,
|
||||
}
|
||||
input: {
|
||||
(function(x) {
|
||||
x();
|
||||
})(function() {
|
||||
(function(i) {
|
||||
if (i)
|
||||
return console.log("PASS");
|
||||
throw "FAIL";
|
||||
})(Object());
|
||||
});
|
||||
}
|
||||
expect: {
|
||||
!function(i) {
|
||||
if (Object())
|
||||
return console.log("PASS");
|
||||
throw "FAIL";
|
||||
}();
|
||||
}
|
||||
expect_stdout: "PASS"
|
||||
}
|
||||
|
||||
issues_3267_2: {
|
||||
options = {
|
||||
collapse_vars: true,
|
||||
conditionals: true,
|
||||
dead_code: true,
|
||||
evaluate: true,
|
||||
inline: true,
|
||||
keep_fargs: false,
|
||||
passes: 2,
|
||||
reduce_vars: true,
|
||||
sequences: true,
|
||||
side_effects: true,
|
||||
unused: true,
|
||||
}
|
||||
input: {
|
||||
(function(x) {
|
||||
x();
|
||||
})(function() {
|
||||
(function(i) {
|
||||
if (i)
|
||||
return console.log("PASS");
|
||||
throw "FAIL";
|
||||
})(Object());
|
||||
});
|
||||
}
|
||||
expect: {
|
||||
!function() {
|
||||
if (Object())
|
||||
return console.log("PASS");
|
||||
throw "FAIL";
|
||||
}();
|
||||
}
|
||||
expect_stdout: "PASS"
|
||||
}
|
||||
|
||||
issues_3267_3: {
|
||||
options = {
|
||||
collapse_vars: true,
|
||||
conditionals: true,
|
||||
dead_code: true,
|
||||
evaluate: true,
|
||||
inline: true,
|
||||
keep_fargs: false,
|
||||
passes: 2,
|
||||
reduce_vars: true,
|
||||
sequences: true,
|
||||
side_effects: true,
|
||||
unsafe: true,
|
||||
unused: true,
|
||||
}
|
||||
input: {
|
||||
(function(x) {
|
||||
x();
|
||||
})(function() {
|
||||
(function(i) {
|
||||
if (i)
|
||||
return console.log("PASS");
|
||||
throw "FAIL";
|
||||
})(Object());
|
||||
});
|
||||
}
|
||||
expect: {
|
||||
console.log("PASS");
|
||||
}
|
||||
expect_stdout: "PASS"
|
||||
}
|
||||
|
||||
issue_3297: {
|
||||
options = {
|
||||
reduce_vars: true,
|
||||
unused: true,
|
||||
}
|
||||
input: {
|
||||
(function() {
|
||||
function f() {
|
||||
var a;
|
||||
var b = function a() {
|
||||
console.log(a === b) && f();
|
||||
};
|
||||
b();
|
||||
}
|
||||
f();
|
||||
})();
|
||||
}
|
||||
expect: {
|
||||
(function() {
|
||||
(function f() {
|
||||
var b = function a() {
|
||||
console.log(a === b) && f();
|
||||
};
|
||||
b();
|
||||
})();
|
||||
})();
|
||||
}
|
||||
expect_stdout: "true"
|
||||
}
|
||||
|
||||
drop_side_effect_free: {
|
||||
options = {
|
||||
collapse_vars: true,
|
||||
evaluate: true,
|
||||
reduce_vars: true,
|
||||
side_effects: true,
|
||||
toplevel: true,
|
||||
}
|
||||
input: {
|
||||
var a = 123;
|
||||
"" + (a && (a.b = 0) || a);
|
||||
console.log(a);
|
||||
}
|
||||
expect: {
|
||||
var a = 123;
|
||||
a.b = 0;
|
||||
console.log(a);
|
||||
}
|
||||
expect_stdout: "123"
|
||||
}
|
||||
|
||||
issue_3377: {
|
||||
options = {
|
||||
reduce_vars: true,
|
||||
unused: true,
|
||||
}
|
||||
input: {
|
||||
console.log(function f() {
|
||||
return f[0], (f = 42);
|
||||
}());
|
||||
}
|
||||
expect: {
|
||||
console.log(function f() {
|
||||
return f[0], (f = 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"
|
||||
}
|
||||
|
||||
@@ -35,3 +35,140 @@ regexp_2: {
|
||||
}
|
||||
expect_stdout: '["PASS","pass"]'
|
||||
}
|
||||
|
||||
issue_3434_1: {
|
||||
options = {
|
||||
evaluate: true,
|
||||
unsafe: true,
|
||||
}
|
||||
beautify = {
|
||||
beautify: true,
|
||||
}
|
||||
input: {
|
||||
var o = {
|
||||
"\n": RegExp("\n"),
|
||||
"\r": RegExp("\r"),
|
||||
"\t": RegExp("\t"),
|
||||
"\b": RegExp("\b"),
|
||||
"\f": RegExp("\f"),
|
||||
"\0": RegExp("\0"),
|
||||
"\x0B": RegExp("\x0B"),
|
||||
"\u2028": RegExp("\u2028"),
|
||||
"\u2029": RegExp("\u2029"),
|
||||
};
|
||||
for (var c in o)
|
||||
console.log(o[c].test("\\"), o[c].test(c));
|
||||
}
|
||||
expect_exact: [
|
||||
"var o = {",
|
||||
' "\\n": /\\n/,',
|
||||
' "\\r": /\\r/,',
|
||||
' "\\t": /\t/,',
|
||||
' "\\b": /\b/,',
|
||||
' "\\f": /\f/,',
|
||||
' "\\0": /\0/,',
|
||||
' "\\v": /\v/,',
|
||||
' "\\u2028": /\\u2028/,',
|
||||
' "\\u2029": /\\u2029/',
|
||||
"};",
|
||||
"",
|
||||
'for (var c in o) console.log(o[c].test("\\\\"), o[c].test(c));',
|
||||
]
|
||||
expect_stdout: [
|
||||
"false true",
|
||||
"false true",
|
||||
"false true",
|
||||
"false true",
|
||||
"false true",
|
||||
"false true",
|
||||
"false true",
|
||||
"false true",
|
||||
"false true",
|
||||
]
|
||||
}
|
||||
|
||||
issue_3434_2: {
|
||||
options = {
|
||||
evaluate: true,
|
||||
unsafe: true,
|
||||
}
|
||||
beautify = {
|
||||
beautify: true,
|
||||
}
|
||||
input: {
|
||||
var o = {
|
||||
"\n": RegExp("\\\n"),
|
||||
"\r": RegExp("\\\r"),
|
||||
"\t": RegExp("\\\t"),
|
||||
"\b": RegExp("\\\b"),
|
||||
"\f": RegExp("\\\f"),
|
||||
"\0": RegExp("\\\0"),
|
||||
"\x0B": RegExp("\\\x0B"),
|
||||
"\u2028": RegExp("\\\u2028"),
|
||||
"\u2029": RegExp("\\\u2029"),
|
||||
};
|
||||
for (var c in o)
|
||||
console.log(o[c].test("\\"), o[c].test(c));
|
||||
}
|
||||
expect_exact: [
|
||||
"var o = {",
|
||||
' "\\n": /\\n/,',
|
||||
' "\\r": /\\r/,',
|
||||
' "\\t": /\t/,',
|
||||
' "\\b": /\b/,',
|
||||
' "\\f": /\f/,',
|
||||
' "\\0": /\0/,',
|
||||
' "\\v": /\v/,',
|
||||
' "\\u2028": /\\u2028/,',
|
||||
' "\\u2029": /\\u2029/',
|
||||
"};",
|
||||
"",
|
||||
'for (var c in o) console.log(o[c].test("\\\\"), o[c].test(c));',
|
||||
]
|
||||
expect_stdout: [
|
||||
"false true",
|
||||
"false true",
|
||||
"false true",
|
||||
"false true",
|
||||
"false true",
|
||||
"false true",
|
||||
"false true",
|
||||
"false true",
|
||||
"false true",
|
||||
]
|
||||
}
|
||||
|
||||
issue_3434_3: {
|
||||
options = {
|
||||
evaluate: true,
|
||||
unsafe: true,
|
||||
}
|
||||
input: {
|
||||
RegExp("\n");
|
||||
RegExp("\r");
|
||||
RegExp("\\n");
|
||||
RegExp("\\\n");
|
||||
RegExp("\\\\n");
|
||||
RegExp("\\\\\n");
|
||||
RegExp("\\\\\\n");
|
||||
RegExp("\\\\\\\n");
|
||||
RegExp("\u2028");
|
||||
RegExp("\u2029");
|
||||
RegExp("\n\r\u2028\u2029");
|
||||
RegExp("\\\nfo\n[\n]o\\bbb");
|
||||
}
|
||||
expect: {
|
||||
/\n/;
|
||||
/\r/;
|
||||
/\n/;
|
||||
/\n/;
|
||||
/\\n/;
|
||||
/\\\n/;
|
||||
/\\\n/;
|
||||
/\\\n/;
|
||||
/\u2028/;
|
||||
/\u2029/;
|
||||
/\n\r\u2028\u2029/;
|
||||
/\nfo\n[\n]o\bbb/;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -534,3 +534,208 @@ function_catch_catch_ie8: {
|
||||
"undefined",
|
||||
]
|
||||
}
|
||||
|
||||
function_do_catch_ie8: {
|
||||
rename = true
|
||||
options = {
|
||||
ie8: true,
|
||||
side_effects: true,
|
||||
unused: true,
|
||||
}
|
||||
mangle = {
|
||||
ie8: true,
|
||||
toplevel: true,
|
||||
}
|
||||
input: {
|
||||
var a = 1, b = 1, c = 0;
|
||||
function d(e) {
|
||||
var f, g, h, i;
|
||||
do {
|
||||
try {
|
||||
try {
|
||||
var j = function q(){}();
|
||||
} catch (r) {
|
||||
--a && w("ddddddddeeeeeeegggggggggiiiiilllllllnnnnntuuuuuuuuyyyyyyy");
|
||||
var k, l, m, n, o;
|
||||
--m;
|
||||
--n;
|
||||
--o;
|
||||
}
|
||||
try {
|
||||
i[1];
|
||||
} catch (s) {
|
||||
var p;
|
||||
switch (function t() {
|
||||
c++;
|
||||
}()) {
|
||||
case j + --p:
|
||||
}
|
||||
}
|
||||
} catch (u) {}
|
||||
} while (--i);
|
||||
b--;
|
||||
}
|
||||
d();
|
||||
console.log(b, c);
|
||||
}
|
||||
expect: {
|
||||
var u = 1, y = 1, a = 0;
|
||||
function c(c) {
|
||||
var d;
|
||||
do {
|
||||
try {
|
||||
try {
|
||||
var e = void 0;
|
||||
} catch (i) {
|
||||
--u && w("ddddddddeeeeeeegggggggggiiiiilllllllnnnnntuuuuuuuuyyyyyyy");
|
||||
0;
|
||||
0;
|
||||
0;
|
||||
}
|
||||
try {
|
||||
d[1];
|
||||
} catch (l) {
|
||||
var g;
|
||||
switch (function n() {
|
||||
a++;
|
||||
}()) {
|
||||
case e + --g:
|
||||
}
|
||||
}
|
||||
} catch (t) {}
|
||||
} while (--d);
|
||||
y--;
|
||||
}
|
||||
c();
|
||||
console.log(y, a);
|
||||
}
|
||||
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"
|
||||
}
|
||||
|
||||
@@ -12,3 +12,71 @@ console_log: {
|
||||
"% %s",
|
||||
]
|
||||
}
|
||||
|
||||
typeof_arguments: {
|
||||
options = {
|
||||
evaluate: true,
|
||||
reduce_vars: true,
|
||||
toplevel: true,
|
||||
unused: true,
|
||||
}
|
||||
input: {
|
||||
var arguments;
|
||||
console.log((typeof arguments).length);
|
||||
}
|
||||
expect: {
|
||||
var arguments;
|
||||
console.log((typeof arguments).length);
|
||||
}
|
||||
expect_stdout: "6"
|
||||
}
|
||||
|
||||
typeof_arguments_assigned: {
|
||||
options = {
|
||||
evaluate: true,
|
||||
reduce_vars: true,
|
||||
toplevel: true,
|
||||
unused: true,
|
||||
}
|
||||
input: {
|
||||
var arguments = void 0;
|
||||
console.log((typeof arguments).length);
|
||||
}
|
||||
expect: {
|
||||
console.log("undefined".length);
|
||||
}
|
||||
expect_stdout: "9"
|
||||
}
|
||||
|
||||
toplevel_Infinity_NaN_undefined: {
|
||||
options = {
|
||||
evaluate: true,
|
||||
reduce_vars: true,
|
||||
toplevel: true,
|
||||
unused: true,
|
||||
}
|
||||
input: {
|
||||
var Infinity = "foo";
|
||||
var NaN = 42;
|
||||
var undefined = null;
|
||||
console.log(Infinity, NaN, undefined);
|
||||
}
|
||||
expect: {
|
||||
console.log("foo", 42, null);
|
||||
}
|
||||
expect_stdout: "foo 42 null"
|
||||
}
|
||||
|
||||
log_global: {
|
||||
input: {
|
||||
console.log(function() {
|
||||
return this;
|
||||
}());
|
||||
}
|
||||
expect: {
|
||||
console.log(function() {
|
||||
return this;
|
||||
}());
|
||||
}
|
||||
expect_stdout: "[object global]"
|
||||
}
|
||||
|
||||
@@ -490,6 +490,7 @@ issue_1758: {
|
||||
delete_seq_1: {
|
||||
options = {
|
||||
booleans: true,
|
||||
evaluate: true,
|
||||
side_effects: true,
|
||||
}
|
||||
input: {
|
||||
@@ -514,6 +515,7 @@ delete_seq_1: {
|
||||
delete_seq_2: {
|
||||
options = {
|
||||
booleans: true,
|
||||
evaluate: true,
|
||||
side_effects: true,
|
||||
}
|
||||
input: {
|
||||
@@ -538,6 +540,7 @@ delete_seq_2: {
|
||||
delete_seq_3: {
|
||||
options = {
|
||||
booleans: true,
|
||||
evaluate: true,
|
||||
keep_infinity: true,
|
||||
side_effects: true,
|
||||
}
|
||||
@@ -563,6 +566,7 @@ delete_seq_3: {
|
||||
delete_seq_4: {
|
||||
options = {
|
||||
booleans: true,
|
||||
evaluate: true,
|
||||
sequences: true,
|
||||
side_effects: true,
|
||||
}
|
||||
@@ -590,6 +594,7 @@ delete_seq_4: {
|
||||
delete_seq_5: {
|
||||
options = {
|
||||
booleans: true,
|
||||
evaluate: true,
|
||||
keep_infinity: true,
|
||||
sequences: true,
|
||||
side_effects: true,
|
||||
@@ -618,6 +623,7 @@ delete_seq_5: {
|
||||
delete_seq_6: {
|
||||
options = {
|
||||
booleans: true,
|
||||
evaluate: true,
|
||||
side_effects: true,
|
||||
}
|
||||
input: {
|
||||
@@ -702,7 +708,7 @@ side_effects_cascade_3: {
|
||||
}
|
||||
expect: {
|
||||
function f(a, b) {
|
||||
!(b += a) && ((b = a) || (b -= a, b ^= a)),
|
||||
(b += a) || (b = a) || (b -= a, b ^= a),
|
||||
a--;
|
||||
}
|
||||
}
|
||||
@@ -924,14 +930,14 @@ call: {
|
||||
b.c = function() {
|
||||
console.log(this === b ? "bar" : "baz");
|
||||
},
|
||||
a, b(),
|
||||
b(),
|
||||
(a, b.c)(),
|
||||
a, function() {
|
||||
function() {
|
||||
console.log(this === a);
|
||||
}(),
|
||||
a, new b(),
|
||||
a, new b.c(),
|
||||
a, new function() {
|
||||
new b(),
|
||||
new b.c(),
|
||||
new function() {
|
||||
console.log(this === a);
|
||||
}();
|
||||
}
|
||||
@@ -944,3 +950,122 @@ call: {
|
||||
"false",
|
||||
]
|
||||
}
|
||||
|
||||
missing_link: {
|
||||
options = {
|
||||
conditionals: true,
|
||||
evaluate: true,
|
||||
sequences: true,
|
||||
}
|
||||
input: {
|
||||
var a = 100;
|
||||
a;
|
||||
a++ + (0 ? 2 : 1);
|
||||
console.log(a);
|
||||
}
|
||||
expect: {
|
||||
var a = 100;
|
||||
a,
|
||||
a++,
|
||||
console.log(a);
|
||||
}
|
||||
}
|
||||
|
||||
angularjs_chain: {
|
||||
options = {
|
||||
conditionals: true,
|
||||
sequences: true,
|
||||
side_effects: true,
|
||||
}
|
||||
input: {
|
||||
function nonComputedMember(left, right, context, create) {
|
||||
var lhs = left();
|
||||
if (create && create !== 1) {
|
||||
if (lhs && lhs[right] == null) {
|
||||
lhs[right] = {};
|
||||
}
|
||||
}
|
||||
var value = lhs != null ? lhs[right] : undefined;
|
||||
if (context) {
|
||||
return { context: lhs, name: right, value: value };
|
||||
} else {
|
||||
return value;
|
||||
}
|
||||
}
|
||||
}
|
||||
expect: {
|
||||
function nonComputedMember(left, right, context, create) {
|
||||
var lhs = left();
|
||||
create && 1 !== create && lhs && null == lhs[right] && (lhs[right] = {});
|
||||
var value = null != lhs ? lhs[right] : void 0;
|
||||
return context ? {
|
||||
context: lhs,
|
||||
name: right,
|
||||
value: value
|
||||
} : value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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"
|
||||
}
|
||||
|
||||
@@ -295,3 +295,145 @@ issue_2728_6: {
|
||||
}
|
||||
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")
|
||||
}
|
||||
|
||||
109
test/compress/webkit.js
Normal file
109
test/compress/webkit.js
Normal file
@@ -0,0 +1,109 @@
|
||||
lambda_call_dot_assign: {
|
||||
beautify = {
|
||||
webkit: false,
|
||||
}
|
||||
input: {
|
||||
console.log(function() {
|
||||
return {};
|
||||
}().a = 1);
|
||||
}
|
||||
expect_exact: "console.log(function(){return{}}().a=1);"
|
||||
expect_stdout: "1"
|
||||
}
|
||||
|
||||
lambda_call_dot_assign_webkit: {
|
||||
beautify = {
|
||||
webkit: true,
|
||||
}
|
||||
input: {
|
||||
console.log(function() {
|
||||
return {};
|
||||
}().a = 1);
|
||||
}
|
||||
expect_exact: "console.log((function(){return{}}()).a=1);"
|
||||
expect_stdout: "1"
|
||||
}
|
||||
|
||||
lambda_dot_assign: {
|
||||
beautify = {
|
||||
webkit: false,
|
||||
}
|
||||
input: {
|
||||
console.log(function() {
|
||||
1 + 1;
|
||||
}.a = 1);
|
||||
}
|
||||
expect_exact: "console.log(function(){1+1}.a=1);"
|
||||
expect_stdout: "1"
|
||||
}
|
||||
|
||||
lambda_dot_assign_webkit: {
|
||||
beautify = {
|
||||
webkit: true,
|
||||
}
|
||||
input: {
|
||||
console.log(function() {
|
||||
1 + 1;
|
||||
}.a = 1);
|
||||
}
|
||||
expect_exact: "console.log((function(){1+1}).a=1);"
|
||||
expect_stdout: "1"
|
||||
}
|
||||
|
||||
lambda_name_mangle: {
|
||||
mangle = {}
|
||||
input: {
|
||||
console.log(typeof function foo(bar) {});
|
||||
}
|
||||
expect_exact: "console.log(typeof function o(n){});"
|
||||
expect_stdout: "function"
|
||||
}
|
||||
|
||||
lambda_name_mangle_ie8: {
|
||||
mangle = {
|
||||
ie8: true,
|
||||
toplevel: true,
|
||||
}
|
||||
input: {
|
||||
console.log(typeof function foo(bar) {});
|
||||
}
|
||||
expect_exact: "console.log(typeof function n(o){});"
|
||||
expect_stdout: "function"
|
||||
}
|
||||
|
||||
function_name_mangle: {
|
||||
options = {
|
||||
keep_fnames: true,
|
||||
reduce_vars: true,
|
||||
unused: true,
|
||||
}
|
||||
mangle = {}
|
||||
input: {
|
||||
(function() {
|
||||
function foo(bar) {}
|
||||
console.log(typeof foo);
|
||||
})();
|
||||
}
|
||||
expect_exact: "(function(){console.log(typeof function o(n){})})();"
|
||||
expect_stdout: "function"
|
||||
}
|
||||
|
||||
function_name_mangle_ie8: {
|
||||
options = {
|
||||
keep_fnames: true,
|
||||
reduce_vars: true,
|
||||
unused: true,
|
||||
}
|
||||
mangle = {
|
||||
ie8: true,
|
||||
toplevel: true,
|
||||
}
|
||||
input: {
|
||||
(function() {
|
||||
function foo(bar) {}
|
||||
console.log(typeof foo);
|
||||
})();
|
||||
}
|
||||
expect_exact: "(function(){console.log(typeof function n(o){})})();"
|
||||
expect_stdout: "function"
|
||||
}
|
||||
@@ -1,14 +1,14 @@
|
||||
exports["Compressor"] = Compressor;
|
||||
exports["JS_Parse_Error"] = JS_Parse_Error;
|
||||
exports["OutputStream"] = OutputStream;
|
||||
exports["SourceMap"] = SourceMap;
|
||||
exports["TreeWalker"] = TreeWalker;
|
||||
exports["base54"] = base54;
|
||||
exports["defaults"] = defaults;
|
||||
exports["JS_Parse_Error"] = JS_Parse_Error;
|
||||
exports["mangle_properties"] = mangle_properties;
|
||||
exports["minify"] = minify;
|
||||
exports["OutputStream"] = OutputStream;
|
||||
exports["parse"] = parse;
|
||||
exports["push_uniq"] = push_uniq;
|
||||
exports["reserve_quoted_keys"] = reserve_quoted_keys;
|
||||
exports["string_template"] = string_template;
|
||||
exports["to_ascii"] = to_ascii;
|
||||
exports["tokenizer"] = tokenizer;
|
||||
exports["is_identifier"] = is_identifier;
|
||||
exports["TreeTransformer"] = TreeTransformer;
|
||||
exports["TreeWalker"] = TreeWalker;
|
||||
|
||||
@@ -23,10 +23,9 @@ module.exports = function(url, callback) {
|
||||
var options = parse(url);
|
||||
options.rejectUnauthorized = false;
|
||||
require(options.protocol.slice(0, -1)).get(options, function(res) {
|
||||
if (res.statusCode !== 200) return callback(res);
|
||||
res.pipe(fs.createWriteStream(local(url)).on("close", function() {
|
||||
callback(null, read(url));
|
||||
}));
|
||||
if (res.statusCode !== 200) return callback(res.statusCode);
|
||||
res.pipe(fs.createWriteStream(local(url)));
|
||||
callback(null, res);
|
||||
});
|
||||
}).on("open", function() {
|
||||
callback(null, result);
|
||||
|
||||
6
test/input/issue-3294/input.js
Normal file
6
test/input/issue-3294/input.js
Normal file
@@ -0,0 +1,6 @@
|
||||
var Foo = function Foo(){console.log(1+2);}; new Foo();
|
||||
|
||||
//# sourceMappingURL=data:application/json;charset=utf-8;base64,DeadBeef
|
||||
//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjpudWxsLCJzb3VyY2VzIjpbInN0ZGluIl0sInNvdXJjZXNDb250ZW50IjpbImNsYXNzIEZvbyB7IGNvbnN0cnVjdG9yKCl7Y29uc29sZS5sb2coMSsyKTt9IH0gbmV3IEZvbygpO1xuIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUFBLElBQU0sR0FBRyxHQUFDLEFBQUUsWUFBVyxFQUFFLENBQUMsT0FBTyxDQUFDLEdBQUcsQ0FBQyxDQUFDLENBQUMsQ0FBQyxDQUFDLENBQUMsQ0FBQyxDQUFBLEFBQUUsQ0FBQyxJQUFJLEdBQUcsRUFBRSxDQUFDOyJ9
|
||||
|
||||
|
||||
2
test/input/issue-3294/output.js
Normal file
2
test/input/issue-3294/output.js
Normal file
@@ -0,0 +1,2 @@
|
||||
new function(){console.log(3)};
|
||||
//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbInN0ZGluIl0sIm5hbWVzIjpbImNvbnNvbGUiLCJsb2ciXSwibWFwcGluZ3MiOiJBQUErQyxJQUFyQyxXQUFnQkEsUUFBUUMsSUFBSSIsInNvdXJjZXNDb250ZW50IjpbImNsYXNzIEZvbyB7IGNvbnN0cnVjdG9yKCl7Y29uc29sZS5sb2coMSsyKTt9IH0gbmV3IEZvbygpO1xuIl19
|
||||
8
test/input/issue-3315/config.json
Normal file
8
test/input/issue-3315/config.json
Normal file
@@ -0,0 +1,8 @@
|
||||
{
|
||||
"compress": false,
|
||||
"mangle": {
|
||||
"properties": {
|
||||
"regex": "/^_/"
|
||||
}
|
||||
}
|
||||
}
|
||||
8
test/input/issue-3315/input.js
Normal file
8
test/input/issue-3315/input.js
Normal file
@@ -0,0 +1,8 @@
|
||||
function f() {
|
||||
"aaaaaaaaaa";
|
||||
var o = {
|
||||
prop: 1,
|
||||
_int: 2,
|
||||
};
|
||||
return o.prop + o._int;
|
||||
}
|
||||
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
|
||||
@@ -3,7 +3,7 @@
|
||||
|
||||
"use strict";
|
||||
|
||||
var site = "https://browserbench.org/JetStream";
|
||||
var site = "https://browserbench.org/JetStream1.1";
|
||||
if (typeof phantom == "undefined") {
|
||||
require("../tools/exit");
|
||||
var args = process.argv.slice(2);
|
||||
@@ -25,30 +25,35 @@ if (typeof phantom == "undefined") {
|
||||
request.resume();
|
||||
var url = site + request.url;
|
||||
fetch(url, function(err, res) {
|
||||
if (err) throw err;
|
||||
response.writeHead(200, {
|
||||
"Content-Type": {
|
||||
css: "text/css",
|
||||
js: "application/javascript",
|
||||
png: "image/png"
|
||||
}[url.slice(url.lastIndexOf(".") + 1)] || "text/html; charset=utf-8"
|
||||
});
|
||||
if (/\.js$/.test(url)) {
|
||||
var stderr = "";
|
||||
var uglifyjs = child_process.fork("bin/uglifyjs", args, {
|
||||
silent: true
|
||||
}).on("exit", function(code) {
|
||||
console.log("uglifyjs", url.slice(site.length + 1), args.join(" "));
|
||||
console.log(stderr);
|
||||
if (code) throw new Error("uglifyjs failed with code " + code);
|
||||
});
|
||||
uglifyjs.stderr.on("data", function(data) {
|
||||
stderr += data;
|
||||
}).setEncoding("utf8");
|
||||
uglifyjs.stdout.pipe(response);
|
||||
res.pipe(uglifyjs.stdin);
|
||||
if (err) {
|
||||
if (typeof err != "number") throw err;
|
||||
response.writeHead(err);
|
||||
response.end();
|
||||
} else {
|
||||
res.pipe(response);
|
||||
response.writeHead(200, {
|
||||
"Content-Type": {
|
||||
css: "text/css",
|
||||
js: "application/javascript",
|
||||
png: "image/png"
|
||||
}[url.slice(url.lastIndexOf(".") + 1)] || "text/html; charset=utf-8"
|
||||
});
|
||||
if (/\.js$/.test(url)) {
|
||||
var stderr = "";
|
||||
var uglifyjs = child_process.fork("bin/uglifyjs", args, {
|
||||
silent: true
|
||||
}).on("exit", function(code) {
|
||||
console.log("uglifyjs", url.slice(site.length + 1), args.join(" "));
|
||||
console.log(stderr);
|
||||
if (code) throw new Error("uglifyjs failed with code " + code);
|
||||
});
|
||||
uglifyjs.stderr.on("data", function(data) {
|
||||
stderr += data;
|
||||
}).setEncoding("utf8");
|
||||
uglifyjs.stdout.pipe(response);
|
||||
res.pipe(uglifyjs.stdin);
|
||||
} else {
|
||||
res.pipe(response);
|
||||
}
|
||||
}
|
||||
});
|
||||
}).listen();
|
||||
@@ -57,8 +62,17 @@ if (typeof phantom == "undefined") {
|
||||
if (debug) {
|
||||
console.log("http://localhost:" + port + "/");
|
||||
} else {
|
||||
child_process.exec("npm install phantomjs-prebuilt@2.1.14 --no-save", function(error) {
|
||||
if (error) throw error;
|
||||
child_process.spawn(process.platform == "win32" ? "npm.cmd" : "npm", [
|
||||
"install",
|
||||
"phantomjs-prebuilt@2.1.14",
|
||||
"--no-audit",
|
||||
"--no-optional",
|
||||
"--no-save",
|
||||
"--no-update-notifier",
|
||||
], {
|
||||
stdio: [ "ignore", 1, 2 ]
|
||||
}).on("exit", function(code) {
|
||||
if (code) throw new Error("npm install failed!");
|
||||
var program = require("phantomjs-prebuilt").exec(process.argv[1], port);
|
||||
program.stdout.pipe(process.stdout);
|
||||
program.stderr.pipe(process.stderr);
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
var assert = require("assert");
|
||||
var exec = require("child_process").exec;
|
||||
var fs = require("fs");
|
||||
var run_code = require("../sandbox").run_code;
|
||||
|
||||
function read(path) {
|
||||
return fs.readFileSync(path, "utf8");
|
||||
@@ -46,7 +47,7 @@ describe("bin/uglifyjs", function() {
|
||||
});
|
||||
});
|
||||
it("Should give sensible error against invalid input source map", function(done) {
|
||||
var command = uglifyjscmd + " test/mocha.js --source-map content=blah,url=inline";
|
||||
var command = uglifyjscmd + " test/mocha.js --source-map content=blah,url=inline --verbose";
|
||||
exec(command, function(err, stdout, stderr) {
|
||||
assert.ok(err);
|
||||
assert.deepEqual(stderr.split(/\n/).slice(0, 2), [
|
||||
@@ -82,6 +83,7 @@ describe("bin/uglifyjs", function() {
|
||||
"test/input/issue-2082/sample.js",
|
||||
"--source-map", "content=test/input/issue-2082/sample.js.map",
|
||||
"--source-map", "url=inline",
|
||||
"--verbose",
|
||||
].join(" ");
|
||||
exec(command, function(err, stdout, stderr) {
|
||||
if (err) throw err;
|
||||
@@ -112,13 +114,12 @@ describe("bin/uglifyjs", function() {
|
||||
|
||||
var child = exec(command, function(err, stdout) {
|
||||
if (err) throw err;
|
||||
|
||||
assert.strictEqual(stdout, read("test/input/pr-3040/expect.js"));
|
||||
assert.strictEqual(stdout, read("test/input/issue-3040/expect.js"));
|
||||
done();
|
||||
});
|
||||
setTimeout(function() {
|
||||
fs.writeFileSync(mapFile, read("test/input/pr-3040/input.js.map"));
|
||||
child.stdin.end(read("test/input/pr-3040/input.js"));
|
||||
fs.writeFileSync(mapFile, read("test/input/issue-3040/input.js.map"));
|
||||
child.stdin.end(read("test/input/issue-3040/input.js"));
|
||||
}, 1000);
|
||||
});
|
||||
it("Should work with --keep-fnames (mangle only)", function(done) {
|
||||
@@ -201,7 +202,7 @@ describe("bin/uglifyjs", function() {
|
||||
});
|
||||
});
|
||||
it("Should warn for missing inline source map", function(done) {
|
||||
var command = uglifyjscmd + " test/input/issue-1323/sample.js --source-map content=inline,url=inline";
|
||||
var command = uglifyjscmd + " test/input/issue-1323/sample.js --source-map content=inline,url=inline --warn";
|
||||
exec(command, function(err, stdout, stderr) {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(stdout, [
|
||||
@@ -220,6 +221,7 @@ describe("bin/uglifyjs", function() {
|
||||
"test/input/issue-520/input.js",
|
||||
"test/input/issue-1323/sample.js",
|
||||
"--source-map", "content=inline,url=inline",
|
||||
"--warn",
|
||||
].join(" ");
|
||||
exec(command, function(err, stdout, stderr) {
|
||||
if (err) throw err;
|
||||
@@ -257,7 +259,7 @@ describe("bin/uglifyjs", function() {
|
||||
assert.strictEqual(lines[0], "Parse error at test/input/invalid/simple.js:1,12");
|
||||
assert.strictEqual(lines[1], "function f(a{}");
|
||||
assert.strictEqual(lines[2], " ^");
|
||||
assert.strictEqual(lines[3], "ERROR: Unexpected token punc «{», expected punc «,»");
|
||||
assert.strictEqual(lines[3], "ERROR: Unexpected token: punc «{», expected: punc «,»");
|
||||
done();
|
||||
});
|
||||
});
|
||||
@@ -281,7 +283,7 @@ describe("bin/uglifyjs", function() {
|
||||
assert.strictEqual(lines[0], "Parse error at test/input/invalid/eof.js:2,0");
|
||||
assert.strictEqual(lines[1], "foo, bar(");
|
||||
assert.strictEqual(lines[2], " ^");
|
||||
assert.strictEqual(lines[3], "ERROR: Unexpected token: eof (undefined)");
|
||||
assert.strictEqual(lines[3], "ERROR: Unexpected token: eof");
|
||||
done();
|
||||
});
|
||||
});
|
||||
@@ -293,7 +295,7 @@ describe("bin/uglifyjs", function() {
|
||||
assert.strictEqual(lines[0], "Parse error at test/input/invalid/loop-no-body.js:2,0");
|
||||
assert.strictEqual(lines[1], "for (var i = 0; i < 1; i++) ");
|
||||
assert.strictEqual(lines[2], " ^");
|
||||
assert.strictEqual(lines[3], "ERROR: Unexpected token: eof (undefined)");
|
||||
assert.strictEqual(lines[3], "ERROR: Unexpected token: eof");
|
||||
done();
|
||||
});
|
||||
});
|
||||
@@ -362,7 +364,7 @@ describe("bin/uglifyjs", function() {
|
||||
"Parse error at test/input/invalid/dot_1.js:1,2",
|
||||
"a.=",
|
||||
" ^",
|
||||
"ERROR: Unexpected token: operator (=)"
|
||||
"ERROR: Unexpected token: operator «=», expected: name"
|
||||
].join("\n"));
|
||||
done();
|
||||
});
|
||||
@@ -376,7 +378,7 @@ describe("bin/uglifyjs", function() {
|
||||
"Parse error at test/input/invalid/dot_2.js:1,0",
|
||||
"%.a;",
|
||||
"^",
|
||||
"ERROR: Unexpected token: operator (%)"
|
||||
"ERROR: Unexpected token: operator «%»"
|
||||
].join("\n"));
|
||||
done();
|
||||
});
|
||||
@@ -390,7 +392,7 @@ describe("bin/uglifyjs", function() {
|
||||
"Parse error at test/input/invalid/dot_3.js:1,2",
|
||||
"a./();",
|
||||
" ^",
|
||||
"ERROR: Unexpected token: operator (/)"
|
||||
"ERROR: Unexpected token: operator «/», expected: name"
|
||||
].join("\n"));
|
||||
done();
|
||||
});
|
||||
@@ -404,7 +406,7 @@ describe("bin/uglifyjs", function() {
|
||||
"Parse error at test/input/invalid/object.js:1,13",
|
||||
"console.log({%: 1});",
|
||||
" ^",
|
||||
"ERROR: Unexpected token: operator (%)"
|
||||
"ERROR: Unexpected token: operator «%»"
|
||||
].join("\n"));
|
||||
done();
|
||||
});
|
||||
@@ -465,7 +467,7 @@ describe("bin/uglifyjs", function() {
|
||||
done();
|
||||
});
|
||||
});
|
||||
it("Should throw syntax error (catch(eval))", function(done) {
|
||||
it("Should throw syntax error (catch (eval))", function(done) {
|
||||
var command = uglifyjscmd + ' test/input/invalid/try.js';
|
||||
exec(command, function(err, stdout, stderr) {
|
||||
assert.ok(err);
|
||||
@@ -502,7 +504,7 @@ describe("bin/uglifyjs", function() {
|
||||
"Parse error at test/input/invalid/else.js:1,7",
|
||||
"if (0) else 1;",
|
||||
" ^",
|
||||
"ERROR: Unexpected token: keyword (else)"
|
||||
"ERROR: Unexpected token: keyword «else»"
|
||||
].join("\n"));
|
||||
done();
|
||||
});
|
||||
@@ -633,12 +635,20 @@ describe("bin/uglifyjs", function() {
|
||||
done();
|
||||
});
|
||||
});
|
||||
it("Should work with mangle.properties.regex from --config-file", function(done) {
|
||||
var command = uglifyjscmd + " test/input/issue-3315/input.js --config-file test/input/issue-3315/config.json";
|
||||
exec(command, function(err, stdout) {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(stdout, 'function f(){"aaaaaaaaaa";var a={prop:1,a:2};return a.prop+a.a}\n');
|
||||
done();
|
||||
});
|
||||
});
|
||||
it("Should fail with --define a-b", function(done) {
|
||||
var command = uglifyjscmd + " test/input/issue-505/input.js --define a-b";
|
||||
exec(command, function(err, stdout, stderr) {
|
||||
assert.ok(err);
|
||||
assert.strictEqual(stdout, "");
|
||||
assert.strictEqual(stderr, "Error parsing arguments for 'define': a-b\n");
|
||||
assert.strictEqual(stderr, "ERROR: cannot parse arguments for 'define': a-b\n");
|
||||
done();
|
||||
});
|
||||
});
|
||||
@@ -651,7 +661,7 @@ describe("bin/uglifyjs", function() {
|
||||
});
|
||||
});
|
||||
it("Should work with explicit --no-rename", function(done) {
|
||||
var command = uglifyjscmd + " test/input/rename/input.js -mc --no-rename";
|
||||
var command = uglifyjscmd + " test/input/rename/input.js -mc passes=2 --no-rename";
|
||||
exec(command, function(err, stdout, stderr) {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(stdout, "function f(n){return function(n){return n}(n)}\n");
|
||||
@@ -659,7 +669,7 @@ describe("bin/uglifyjs", function() {
|
||||
});
|
||||
});
|
||||
it("Should work with implicit --rename", function(done) {
|
||||
var command = uglifyjscmd + " test/input/rename/input.js -mc";
|
||||
var command = uglifyjscmd + " test/input/rename/input.js -mc passes=2";
|
||||
exec(command, function(err, stdout, stderr) {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(stdout, "function f(n){return n}\n");
|
||||
@@ -667,7 +677,7 @@ describe("bin/uglifyjs", function() {
|
||||
});
|
||||
});
|
||||
it("Should work with implicit --no-rename", function(done) {
|
||||
var command = uglifyjscmd + " test/input/rename/input.js -c";
|
||||
var command = uglifyjscmd + " test/input/rename/input.js -c passes=2";
|
||||
exec(command, function(err, stdout, stderr) {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(stdout, "function f(x){return function(x){return x}(x)}\n");
|
||||
@@ -702,8 +712,36 @@ describe("bin/uglifyjs", function() {
|
||||
var command = uglifyjscmd + " test/input/enclose/input.js --enclose window,undefined:window --wrap exports";
|
||||
exec(command, function(err, stdout, stderr) {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(stdout, '(function(window,undefined){(function(exports){function enclose(){console.log("test enclose")}enclose()})(typeof exports=="undefined"?exports={}:exports)})(window);\n');
|
||||
assert.strictEqual(stdout, '(function(exports){(function(window,undefined){function enclose(){console.log("test enclose")}enclose()})(window)})(typeof exports=="undefined"?exports={}:exports);\n');
|
||||
done();
|
||||
});
|
||||
});
|
||||
it("Should compress swarm of unused variables with reasonable performance", function(done) {
|
||||
var code = [
|
||||
"console.log(function() {",
|
||||
];
|
||||
for (var i = 0; i < 10000; i++) {
|
||||
code.push("var obj" + i + " = {p: " + i + "};");
|
||||
}
|
||||
code.push("var map = {");
|
||||
for (var i = 0; i < 10000; i++) {
|
||||
code.push("obj" + i + ": obj" + i + ",");
|
||||
}
|
||||
code = code.concat([
|
||||
"};",
|
||||
"return obj25.p + obj121.p + obj1024.p;",
|
||||
"}());",
|
||||
]).join("\n");
|
||||
exec(uglifyjscmd + " -mc", function(err, stdout) {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(stdout, [
|
||||
"console.log(function(){",
|
||||
"var p={p:25},n={p:121},o={p:1024};",
|
||||
"return p.p+n.p+o.p",
|
||||
"}());\n",
|
||||
].join(""));
|
||||
assert.strictEqual(run_code(stdout), run_code(code));
|
||||
done();
|
||||
}).stdin.end(code);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -13,7 +13,7 @@ describe("comments", function() {
|
||||
|
||||
var fail = function(e) {
|
||||
return e instanceof UglifyJS.JS_Parse_Error
|
||||
&& e.message === "Unexpected token: operator (>)"
|
||||
&& e.message === "Unexpected token: operator «>»"
|
||||
&& e.line === 2
|
||||
&& e.col === 0;
|
||||
}
|
||||
@@ -36,7 +36,7 @@ describe("comments", function() {
|
||||
|
||||
var fail = function(e) {
|
||||
return e instanceof UglifyJS.JS_Parse_Error
|
||||
&& e.message === "Unexpected token: operator (>)"
|
||||
&& e.message === "Unexpected token: operator «>»"
|
||||
&& e.line === 5
|
||||
&& e.col === 0;
|
||||
}
|
||||
@@ -48,53 +48,84 @@ describe("comments", function() {
|
||||
}
|
||||
});
|
||||
|
||||
it("Should handle comment within return correctly", function() {
|
||||
var result = UglifyJS.minify([
|
||||
"function unequal(x, y) {",
|
||||
" return (",
|
||||
" // Either one",
|
||||
" x < y",
|
||||
" ||",
|
||||
" y < x",
|
||||
" );",
|
||||
"}",
|
||||
].join("\n"), {
|
||||
compress: false,
|
||||
mangle: false,
|
||||
output: {
|
||||
beautify: true,
|
||||
comments: "all",
|
||||
},
|
||||
describe("comment within return", function() {
|
||||
it("Should handle leading return", function() {
|
||||
var result = UglifyJS.minify([
|
||||
"function unequal(x, y) {",
|
||||
" return (",
|
||||
" // Either one",
|
||||
" x < y",
|
||||
" ||",
|
||||
" y < x",
|
||||
" );",
|
||||
"}",
|
||||
].join("\n"), {
|
||||
compress: false,
|
||||
mangle: false,
|
||||
output: {
|
||||
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() {
|
||||
var result = UglifyJS.minify([
|
||||
"function f() {",
|
||||
" /* boo */ x();",
|
||||
" return y();",
|
||||
"}",
|
||||
].join("\n"), {
|
||||
mangle: false,
|
||||
output: {
|
||||
beautify: true,
|
||||
comments: "all",
|
||||
},
|
||||
it("Should handle trailing return", function() {
|
||||
var result = UglifyJS.minify([
|
||||
"function unequal(x) {",
|
||||
" var y;",
|
||||
" return (",
|
||||
" // Either one",
|
||||
" x < y",
|
||||
" ||",
|
||||
" y < x",
|
||||
" );",
|
||||
"}",
|
||||
].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() {
|
||||
@@ -228,6 +259,30 @@ describe("comments", function() {
|
||||
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() {
|
||||
var result = UglifyJS.minify("/*a*/(/*b*/function(){/*c*/}/*d*/)/*e*/();", {
|
||||
compress: false,
|
||||
@@ -260,6 +315,60 @@ describe("comments", function() {
|
||||
].join("\n"));
|
||||
});
|
||||
|
||||
it("Should handle programmatic AST insertions gracefully", function() {
|
||||
var ast = UglifyJS.parse([
|
||||
"function f() {",
|
||||
" //foo",
|
||||
" bar;",
|
||||
" return;",
|
||||
"}",
|
||||
].join("\n"));
|
||||
ast.body[0].body[0] = new UglifyJS.AST_Throw({value: ast.body[0].body[0].body});
|
||||
ast.body[0].body[1].value = new UglifyJS.AST_Number({value: 42});
|
||||
assert.strictEqual(ast.print_to_string({comments: "all"}), [
|
||||
"function f(){",
|
||||
"//foo",
|
||||
"throw bar;return 42}",
|
||||
].join("\n"));
|
||||
});
|
||||
|
||||
it("Should not duplicate sourceMappingURL", function() {
|
||||
var code = [
|
||||
"//# sourceMappingURL=input.map",
|
||||
"print(42);",
|
||||
"//# sourceMappingURL=input.map",
|
||||
"",
|
||||
"//# sourceMappingURL=input.map",
|
||||
"//# sourceMappingURL=input.map",
|
||||
"",
|
||||
].join("\n");
|
||||
|
||||
var result = UglifyJS.minify(code, {
|
||||
output: { comments: true },
|
||||
});
|
||||
if (result.error) throw result.error;
|
||||
assert.strictEqual(result.code, [
|
||||
"//# sourceMappingURL=input.map",
|
||||
"print(42);",
|
||||
"//# sourceMappingURL=input.map",
|
||||
"//# sourceMappingURL=input.map",
|
||||
"//# sourceMappingURL=input.map",
|
||||
].join("\n"));
|
||||
|
||||
result = UglifyJS.minify(code, {
|
||||
output: { comments: true },
|
||||
sourceMap: { url: "output.map" },
|
||||
});
|
||||
if (result.error) throw result.error;
|
||||
assert.strictEqual(result.code, [
|
||||
"//# sourceMappingURL=input.map",
|
||||
"print(42);",
|
||||
"//# sourceMappingURL=input.map",
|
||||
"//# sourceMappingURL=input.map",
|
||||
"//# sourceMappingURL=output.map",
|
||||
].join("\n"));
|
||||
});
|
||||
|
||||
describe("comment before constant", function() {
|
||||
var js = 'function f() { /*c1*/ var /*c2*/ foo = /*c3*/ false; return foo; }';
|
||||
|
||||
|
||||
@@ -146,7 +146,7 @@ describe("Directives", function() {
|
||||
UglifyJS.parse(tokenizer);
|
||||
}, function(e) {
|
||||
return e instanceof UglifyJS.JS_Parse_Error
|
||||
&& e.message === "Unexpected token: punc (])"
|
||||
&& /^Unexpected token: punc «]»/.test(e.message)
|
||||
}, test[0]);
|
||||
test[1].forEach(function(directive) {
|
||||
assert.strictEqual(tokenizer.has_directive(directive), true, directive + " in " + test[0]);
|
||||
|
||||
@@ -69,7 +69,7 @@ describe("Getters and setters", function() {
|
||||
var fail = function(data) {
|
||||
return function(e) {
|
||||
return e instanceof UglifyJS.JS_Parse_Error
|
||||
&& e.message === "Unexpected token: operator (" + data.operator + ")";
|
||||
&& e.message === "Unexpected token: operator «" + data.operator + "»";
|
||||
};
|
||||
};
|
||||
var errorMessage = function(data) {
|
||||
|
||||
@@ -87,7 +87,7 @@ describe("minify", function() {
|
||||
assert.strictEqual(run_code(compressed), run_code(original));
|
||||
});
|
||||
|
||||
it("Should avoid mangled names in cache", function() {
|
||||
it("Should avoid cached names when mangling top-level variables", function() {
|
||||
var cache = {};
|
||||
var original = "";
|
||||
var compressed = "";
|
||||
@@ -116,10 +116,34 @@ describe("minify", function() {
|
||||
assert.strictEqual(run_code(compressed), run_code(original));
|
||||
});
|
||||
|
||||
it("Should avoid cached names when mangling inner-scoped variables", function() {
|
||||
var cache = {};
|
||||
var original = "";
|
||||
var compressed = "";
|
||||
[
|
||||
'var extend = function(a, b) { console.log("extend"); a(); b(); }; function A() { console.log("A"); };',
|
||||
'var B = function(A) { function B() { console.log("B") }; extend(B, A); return B; }(A);',
|
||||
].forEach(function(code) {
|
||||
var result = UglifyJS.minify(code, {
|
||||
compress: false,
|
||||
nameCache: cache,
|
||||
toplevel: true,
|
||||
});
|
||||
if (result.error) throw result.error;
|
||||
original += code;
|
||||
compressed += result.code;
|
||||
});
|
||||
assert.strictEqual(compressed, [
|
||||
'var o=function(o,n){console.log("extend");o();n()};function n(){console.log("A")}',
|
||||
'var e=function(n){function e(){console.log("B")}o(e,n);return e}(n);',
|
||||
].join(""));
|
||||
assert.strictEqual(run_code(compressed), run_code(original));
|
||||
});
|
||||
|
||||
it("Should not parse invalid use of reserved words", function() {
|
||||
assert.strictEqual(UglifyJS.minify("function enum(){}").error, undefined);
|
||||
assert.strictEqual(UglifyJS.minify("function static(){}").error, undefined);
|
||||
assert.strictEqual(UglifyJS.minify("function this(){}").error.message, "Unexpected token: name (this)");
|
||||
assert.strictEqual(UglifyJS.minify("function this(){}").error.message, "Unexpected token: name «this»");
|
||||
});
|
||||
|
||||
describe("keep_quoted_props", function() {
|
||||
@@ -214,7 +238,7 @@ describe("minify", function() {
|
||||
var result = UglifyJS.minify("function f(a{}");
|
||||
var err = result.error;
|
||||
assert.ok(err instanceof Error);
|
||||
assert.strictEqual(err.stack.split(/\n/)[0], "SyntaxError: Unexpected token punc «{», expected punc «,»");
|
||||
assert.strictEqual(err.stack.split(/\n/)[0], "SyntaxError: Unexpected token: punc «{», expected: punc «,»");
|
||||
assert.strictEqual(err.filename, "0");
|
||||
assert.strictEqual(err.line, 1);
|
||||
assert.strictEqual(err.col, 12);
|
||||
@@ -241,7 +265,7 @@ describe("minify", function() {
|
||||
});
|
||||
var err = result.error;
|
||||
assert.ok(err instanceof Error);
|
||||
assert.strictEqual(err.stack.split(/\n/)[0], "SyntaxError: Unexpected token: keyword (debugger)");
|
||||
assert.strictEqual(err.stack.split(/\n/)[0], "SyntaxError: Unexpected token: keyword «debugger»");
|
||||
});
|
||||
it("Should skip inherited properties", function() {
|
||||
var foo = Object.create({ skip: this });
|
||||
@@ -341,7 +365,7 @@ describe("minify", function() {
|
||||
wrap: 'exports',
|
||||
});
|
||||
if (result.error) throw result.error;
|
||||
assert.strictEqual(result.code, '(function(window,undefined){(function(exports){function enclose(){console.log("test enclose")}enclose()})(typeof exports=="undefined"?exports={}:exports)})(window);');
|
||||
assert.strictEqual(result.code, '(function(exports){(function(window,undefined){function enclose(){console.log("test enclose")}enclose()})(window)})(typeof exports=="undefined"?exports={}:exports);');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,50 +0,0 @@
|
||||
var assert = require("assert");
|
||||
var semver = require("semver");
|
||||
var spawn = require("child_process").spawn;
|
||||
|
||||
if (!process.env.UGLIFYJS_TEST_ALL) return;
|
||||
|
||||
function run(command, args, done) {
|
||||
spawn(command, args, {
|
||||
stdio: [ "ignore", 1, 2 ]
|
||||
}).on("exit", function(code) {
|
||||
assert.strictEqual(code, 0);
|
||||
done();
|
||||
});
|
||||
}
|
||||
|
||||
describe("test/benchmark.js", function() {
|
||||
this.timeout(10 * 60 * 1000);
|
||||
[
|
||||
"-b",
|
||||
"-b braces",
|
||||
"-m",
|
||||
"-mc passes=3",
|
||||
"-mc passes=3,toplevel",
|
||||
"-mc passes=3,unsafe",
|
||||
"-mc keep_fargs=false,passes=3",
|
||||
"-mc keep_fargs=false,passes=3,pure_getters,unsafe,unsafe_comps,unsafe_math,unsafe_proto",
|
||||
].forEach(function(options) {
|
||||
it("Should pass with options " + options, function(done) {
|
||||
var args = options.split(/ /);
|
||||
args.unshift("test/benchmark.js");
|
||||
run(process.argv[0], args, done);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
if (semver.satisfies(process.version, "0.12")) return;
|
||||
describe("test/jetstream.js", function() {
|
||||
this.timeout(20 * 60 * 1000);
|
||||
[
|
||||
"-mc",
|
||||
"-mc keep_fargs=false,passes=3,pure_getters,unsafe,unsafe_comps,unsafe_math,unsafe_proto",
|
||||
].forEach(function(options) {
|
||||
it("Should pass with options " + options, function(done) {
|
||||
var args = options.split(/ /);
|
||||
args.unshift("test/jetstream.js");
|
||||
args.push("-b", "beautify=false,webkit");
|
||||
run(process.argv[0], args, done);
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -1,7 +1,7 @@
|
||||
var assert = require("assert");
|
||||
var readFileSync = require("fs").readFileSync;
|
||||
var SourceMapConsumer = require("source-map").SourceMapConsumer;
|
||||
var UglifyJS = require("../..");
|
||||
var UglifyJS = require("../node");
|
||||
|
||||
function read(path) {
|
||||
return readFileSync(path, "utf8");
|
||||
@@ -118,51 +118,33 @@ describe("sourcemaps", function() {
|
||||
assert.strictEqual(result.code + "\n", readFileSync("test/input/issue-520/output.js", "utf8"));
|
||||
});
|
||||
it("Should warn for missing inline source map", function() {
|
||||
var warn_function = UglifyJS.AST_Node.warn_function;
|
||||
var warnings = [];
|
||||
UglifyJS.AST_Node.warn_function = function(txt) {
|
||||
warnings.push(txt);
|
||||
};
|
||||
try {
|
||||
var result = UglifyJS.minify(read("./test/input/issue-1323/sample.js"), {
|
||||
mangle: false,
|
||||
sourceMap: {
|
||||
content: "inline"
|
||||
}
|
||||
});
|
||||
assert.strictEqual(result.code, "var bar=function(bar){return bar};");
|
||||
assert.strictEqual(warnings.length, 1);
|
||||
assert.strictEqual(warnings[0], "inline source map not found: 0");
|
||||
} finally {
|
||||
UglifyJS.AST_Node.warn_function = warn_function;
|
||||
}
|
||||
var result = UglifyJS.minify(read("./test/input/issue-1323/sample.js"), {
|
||||
mangle: false,
|
||||
sourceMap: {
|
||||
content: "inline"
|
||||
},
|
||||
warnings: true,
|
||||
});
|
||||
assert.strictEqual(result.code, "var bar=function(bar){return bar};");
|
||||
assert.deepEqual(result.warnings, [ "WARN: inline source map not found: 0" ]);
|
||||
});
|
||||
it("Should handle multiple input and inline source map", function() {
|
||||
var warn_function = UglifyJS.AST_Node.warn_function;
|
||||
var warnings = [];
|
||||
UglifyJS.AST_Node.warn_function = function(txt) {
|
||||
warnings.push(txt);
|
||||
};
|
||||
try {
|
||||
var result = UglifyJS.minify([
|
||||
read("./test/input/issue-520/input.js"),
|
||||
read("./test/input/issue-1323/sample.js"),
|
||||
], {
|
||||
sourceMap: {
|
||||
content: "inline",
|
||||
url: "inline",
|
||||
}
|
||||
});
|
||||
if (result.error) throw result.error;
|
||||
assert.strictEqual(result.code, [
|
||||
"var Foo=function(){console.log(3)};new Foo;var bar=function(o){return o};",
|
||||
"//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbInN0ZGluIiwiMSJdLCJuYW1lcyI6WyJGb28iLCJjb25zb2xlIiwibG9nIiwiYmFyIl0sIm1hcHBpbmdzIjoiQUFBQSxJQUFNQSxJQUFJLFdBQWdCQyxRQUFRQyxJQUFJLElBQVMsSUFBSUYsSUNBbkQsSUFBSUcsSUFDQSxTQUFjQSxHQUNWLE9BQU9BIn0=",
|
||||
].join("\n"));
|
||||
assert.strictEqual(warnings.length, 1);
|
||||
assert.strictEqual(warnings[0], "inline source map not found: 1");
|
||||
} finally {
|
||||
UglifyJS.AST_Node.warn_function = warn_function;
|
||||
}
|
||||
var result = UglifyJS.minify([
|
||||
read("./test/input/issue-520/input.js"),
|
||||
read("./test/input/issue-1323/sample.js"),
|
||||
], {
|
||||
sourceMap: {
|
||||
content: "inline",
|
||||
url: "inline",
|
||||
},
|
||||
warnings: true,
|
||||
});
|
||||
if (result.error) throw result.error;
|
||||
assert.strictEqual(result.code, [
|
||||
"var Foo=function(){console.log(3)};new Foo;var bar=function(o){return o};",
|
||||
"//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbInN0ZGluIiwiMSJdLCJuYW1lcyI6WyJGb28iLCJjb25zb2xlIiwibG9nIiwiYmFyIl0sIm1hcHBpbmdzIjoiQUFBQSxJQUFNQSxJQUFJLFdBQWdCQyxRQUFRQyxJQUFJLElBQVMsSUFBSUYsSUNBbkQsSUFBSUcsSUFDQSxTQUFjQSxHQUNWLE9BQU9BIn0=",
|
||||
].join("\n"));
|
||||
assert.deepEqual(result.warnings, [ "WARN: inline source map not found: 1" ]);
|
||||
});
|
||||
it("Should drop source contents for includeSources=false", function() {
|
||||
var result = UglifyJS.minify(read("./test/input/issue-520/input.js"), {
|
||||
@@ -187,6 +169,30 @@ describe("sourcemaps", function() {
|
||||
map = JSON.parse(result.map);
|
||||
assert.ok(!("sourcesContent" in map));
|
||||
});
|
||||
it("Should parse the correct sourceMappingURL", function() {
|
||||
var result = UglifyJS.minify(read("./test/input/issue-3294/input.js"), {
|
||||
compress: { toplevel: true },
|
||||
sourceMap: {
|
||||
content: "inline",
|
||||
includeSources: true,
|
||||
url: "inline"
|
||||
}
|
||||
});
|
||||
if (result.error) throw result.error;
|
||||
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() {
|
||||
@@ -238,7 +244,7 @@ describe("sourcemaps", function() {
|
||||
assert.strictEqual(map.sourcesContent.length, 1);
|
||||
assert.strictEqual(map.sourcesContent[0], code);
|
||||
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[0], code);
|
||||
result = UglifyJS.minify(result.code, {
|
||||
|
||||
17
test/release/benchmark.js
Normal file
17
test/release/benchmark.js
Normal file
@@ -0,0 +1,17 @@
|
||||
setInterval(function() {
|
||||
process.stderr.write("\0");
|
||||
}, 8 * 60 * 1000).unref();
|
||||
require("./run")([
|
||||
"-b",
|
||||
"-b braces",
|
||||
"-m",
|
||||
"-mc passes=3",
|
||||
"-mc passes=3,toplevel",
|
||||
"-mc passes=3,unsafe",
|
||||
"-mc keep_fargs=false,passes=3",
|
||||
"-mc keep_fargs=false,passes=3,pure_getters,unsafe,unsafe_comps,unsafe_math,unsafe_proto",
|
||||
].map(function(options) {
|
||||
var args = options.split(/ /);
|
||||
args.unshift("test/benchmark.js");
|
||||
return args;
|
||||
}));
|
||||
9
test/release/jetstream.js
Normal file
9
test/release/jetstream.js
Normal file
@@ -0,0 +1,9 @@
|
||||
require("./run")([
|
||||
"-mc",
|
||||
"-mc keep_fargs=false,passes=3,pure_getters,unsafe,unsafe_comps,unsafe_math,unsafe_proto",
|
||||
].map(function(options) {
|
||||
var args = options.split(/ /);
|
||||
args.unshift("test/jetstream.js");
|
||||
args.push("-b", "beautify=false,webkit");
|
||||
return args;
|
||||
}));
|
||||
16
test/release/run.js
Normal file
16
test/release/run.js
Normal file
@@ -0,0 +1,16 @@
|
||||
var child_process = require("child_process");
|
||||
|
||||
module.exports = function(tasks) {
|
||||
(function next() {
|
||||
if (!tasks.length) return;
|
||||
var args = tasks.shift();
|
||||
console.log();
|
||||
console.log("\u001B[36m$> " + args.join(" ") + "\u001B[39m");
|
||||
child_process.spawn(process.argv[0], args, {
|
||||
stdio: [ "ignore", 1, 2 ]
|
||||
}).on("exit", function(code) {
|
||||
if (code) process.exit(code);
|
||||
next();
|
||||
});
|
||||
})();
|
||||
};
|
||||
@@ -1,393 +0,0 @@
|
||||
#! /usr/bin/env node
|
||||
|
||||
var U = require("./node");
|
||||
var path = require("path");
|
||||
var fs = require("fs");
|
||||
var assert = require("assert");
|
||||
var sandbox = require("./sandbox");
|
||||
var semver = require("semver");
|
||||
|
||||
var tests_dir = path.dirname(module.filename);
|
||||
var failures = 0;
|
||||
var failed_files = {};
|
||||
var minify_options = require("./ufuzz.json").map(JSON.stringify);
|
||||
|
||||
run_compress_tests();
|
||||
if (failures) {
|
||||
console.error("\n!!! Failed " + failures + " test cases.");
|
||||
console.error("!!! " + Object.keys(failed_files).join(", "));
|
||||
process.exit(1);
|
||||
}
|
||||
console.log();
|
||||
require("./mocha.js");
|
||||
|
||||
/* -----[ utils ]----- */
|
||||
|
||||
function tmpl() {
|
||||
return U.string_template.apply(this, arguments);
|
||||
}
|
||||
|
||||
function log() {
|
||||
var txt = tmpl.apply(this, arguments);
|
||||
console.log("%s", txt);
|
||||
}
|
||||
|
||||
function log_directory(dir) {
|
||||
log("*** Entering [{dir}]", { dir: dir });
|
||||
}
|
||||
|
||||
function log_start_file(file) {
|
||||
log("--- {file}", { file: file });
|
||||
}
|
||||
|
||||
function log_test(name) {
|
||||
log(" Running test [{name}]", { name: name });
|
||||
}
|
||||
|
||||
function find_test_files(dir) {
|
||||
return fs.readdirSync(dir).filter(function(name) {
|
||||
return /\.js$/i.test(name);
|
||||
});
|
||||
}
|
||||
|
||||
function test_directory(dir) {
|
||||
return path.resolve(tests_dir, dir);
|
||||
}
|
||||
|
||||
function as_toplevel(input, mangle_options) {
|
||||
if (!(input instanceof U.AST_BlockStatement))
|
||||
throw new Error("Unsupported input syntax");
|
||||
for (var i = 0; i < input.body.length; i++) {
|
||||
var stat = input.body[i];
|
||||
if (stat instanceof U.AST_SimpleStatement && stat.body instanceof U.AST_String)
|
||||
input.body[i] = new U.AST_Directive(stat.body);
|
||||
else break;
|
||||
}
|
||||
var toplevel = new U.AST_Toplevel(input);
|
||||
toplevel.figure_out_scope(mangle_options);
|
||||
return toplevel;
|
||||
}
|
||||
|
||||
function run_compress_tests() {
|
||||
var dir = test_directory("compress");
|
||||
log_directory("compress");
|
||||
var files = find_test_files(dir);
|
||||
function test_file(file) {
|
||||
log_start_file(file);
|
||||
function test_case(test) {
|
||||
log_test(test.name);
|
||||
var output_options = test.beautify || {};
|
||||
var expect;
|
||||
if (test.expect) {
|
||||
expect = make_code(as_toplevel(test.expect, test.mangle), output_options);
|
||||
} else {
|
||||
expect = test.expect_exact;
|
||||
}
|
||||
var input = as_toplevel(test.input, test.mangle);
|
||||
var input_code = make_code(input, output_options);
|
||||
var input_formatted = make_code(test.input, {
|
||||
beautify: true,
|
||||
quote_style: 3,
|
||||
keep_quoted_props: true
|
||||
});
|
||||
try {
|
||||
U.parse(input_code);
|
||||
} catch (ex) {
|
||||
log("!!! Cannot parse input\n---INPUT---\n{input}\n--PARSE ERROR--\n{error}\n\n", {
|
||||
input: input_formatted,
|
||||
error: ex,
|
||||
});
|
||||
return false;
|
||||
}
|
||||
var options = U.defaults(test.options, {
|
||||
warnings: false
|
||||
});
|
||||
var warnings_emitted = [];
|
||||
var original_warn_function = U.AST_Node.warn_function;
|
||||
if (test.expect_warnings) {
|
||||
U.AST_Node.warn_function = function(text) {
|
||||
warnings_emitted.push("WARN: " + text);
|
||||
};
|
||||
if (!options.warnings) options.warnings = true;
|
||||
}
|
||||
if (test.mangle && test.mangle.properties && test.mangle.properties.keep_quoted) {
|
||||
var quoted_props = test.mangle.properties.reserved;
|
||||
if (!Array.isArray(quoted_props)) quoted_props = [];
|
||||
test.mangle.properties.reserved = quoted_props;
|
||||
U.reserve_quoted_keys(input, quoted_props);
|
||||
}
|
||||
if (test.rename) {
|
||||
input.figure_out_scope(test.mangle);
|
||||
input.expand_names(test.mangle);
|
||||
}
|
||||
var cmp = new U.Compressor(options, true);
|
||||
var output = cmp.compress(input);
|
||||
output.figure_out_scope(test.mangle);
|
||||
if (test.mangle) {
|
||||
output.compute_char_frequency(test.mangle);
|
||||
output.mangle_names(test.mangle);
|
||||
if (test.mangle.properties) {
|
||||
output = U.mangle_properties(output, test.mangle.properties);
|
||||
}
|
||||
}
|
||||
output = make_code(output, output_options);
|
||||
if (expect != output) {
|
||||
log("!!! failed\n---INPUT---\n{input}\n---OUTPUT---\n{output}\n---EXPECTED---\n{expected}\n\n", {
|
||||
input: input_formatted,
|
||||
output: output,
|
||||
expected: expect
|
||||
});
|
||||
return false;
|
||||
}
|
||||
// expect == output
|
||||
try {
|
||||
U.parse(output);
|
||||
} catch (ex) {
|
||||
log("!!! Test matched expected result but cannot parse output\n---INPUT---\n{input}\n---OUTPUT---\n{output}\n--REPARSE ERROR--\n{error}\n\n", {
|
||||
input: input_formatted,
|
||||
output: output,
|
||||
error: ex,
|
||||
});
|
||||
return false;
|
||||
}
|
||||
if (test.expect_warnings) {
|
||||
U.AST_Node.warn_function = original_warn_function;
|
||||
var expected_warnings = make_code(test.expect_warnings, {
|
||||
beautify: false,
|
||||
quote_style: 2, // force double quote to match JSON
|
||||
});
|
||||
warnings_emitted = warnings_emitted.map(function(input) {
|
||||
return input.split(process.cwd() + path.sep).join("").split(path.sep).join("/");
|
||||
});
|
||||
var actual_warnings = JSON.stringify(warnings_emitted);
|
||||
if (expected_warnings != actual_warnings) {
|
||||
log("!!! failed\n---INPUT---\n{input}\n---EXPECTED WARNINGS---\n{expected_warnings}\n---ACTUAL WARNINGS---\n{actual_warnings}\n\n", {
|
||||
input: input_formatted,
|
||||
expected_warnings: expected_warnings,
|
||||
actual_warnings: actual_warnings,
|
||||
});
|
||||
return false;
|
||||
}
|
||||
}
|
||||
if (test.expect_stdout
|
||||
&& (!test.node_version || semver.satisfies(process.version, test.node_version))) {
|
||||
var stdout = run_code(input_code);
|
||||
if (test.expect_stdout === true) {
|
||||
test.expect_stdout = stdout;
|
||||
}
|
||||
if (!sandbox.same_stdout(test.expect_stdout, stdout)) {
|
||||
log("!!! Invalid input or expected stdout\n---INPUT---\n{input}\n---EXPECTED {expected_type}---\n{expected}\n---ACTUAL {actual_type}---\n{actual}\n\n", {
|
||||
input: input_formatted,
|
||||
expected_type: typeof test.expect_stdout == "string" ? "STDOUT" : "ERROR",
|
||||
expected: test.expect_stdout,
|
||||
actual_type: typeof stdout == "string" ? "STDOUT" : "ERROR",
|
||||
actual: stdout,
|
||||
});
|
||||
return false;
|
||||
}
|
||||
stdout = run_code(output);
|
||||
if (!sandbox.same_stdout(test.expect_stdout, stdout)) {
|
||||
log("!!! failed\n---INPUT---\n{input}\n---EXPECTED {expected_type}---\n{expected}\n---ACTUAL {actual_type}---\n{actual}\n\n", {
|
||||
input: input_formatted,
|
||||
expected_type: typeof test.expect_stdout == "string" ? "STDOUT" : "ERROR",
|
||||
expected: test.expect_stdout,
|
||||
actual_type: typeof stdout == "string" ? "STDOUT" : "ERROR",
|
||||
actual: stdout,
|
||||
});
|
||||
return false;
|
||||
}
|
||||
if (!reminify(test.options, input_code, input_formatted, test.expect_stdout)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
var tests = parse_test(path.resolve(dir, file));
|
||||
for (var i in tests) if (tests.hasOwnProperty(i)) {
|
||||
if (!test_case(tests[i])) {
|
||||
failures++;
|
||||
failed_files[file] = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
files.forEach(function(file) {
|
||||
test_file(file);
|
||||
});
|
||||
}
|
||||
|
||||
function parse_test(file) {
|
||||
var script = fs.readFileSync(file, "utf8");
|
||||
// TODO try/catch can be removed after fixing https://github.com/mishoo/UglifyJS2/issues/348
|
||||
try {
|
||||
var ast = U.parse(script, {
|
||||
filename: file
|
||||
});
|
||||
} catch (e) {
|
||||
console.log("Caught error while parsing tests in " + file + "\n");
|
||||
console.log(e);
|
||||
throw e;
|
||||
}
|
||||
var tests = {};
|
||||
var tw = new U.TreeWalker(function(node, descend) {
|
||||
if (node instanceof U.AST_LabeledStatement
|
||||
&& tw.parent() instanceof U.AST_Toplevel) {
|
||||
var name = node.label.name;
|
||||
if (name in tests) {
|
||||
throw new Error('Duplicated test name "' + name + '" in ' + file);
|
||||
}
|
||||
tests[name] = get_one_test(name, node.body);
|
||||
return true;
|
||||
}
|
||||
if (!(node instanceof U.AST_Toplevel)) croak(node);
|
||||
});
|
||||
ast.walk(tw);
|
||||
return tests;
|
||||
|
||||
function croak(node) {
|
||||
throw new Error(tmpl("Can't understand test file {file} [{line},{col}]\n{code}", {
|
||||
file: file,
|
||||
line: node.start.line,
|
||||
col: node.start.col,
|
||||
code: make_code(node, { beautify: false })
|
||||
}));
|
||||
}
|
||||
|
||||
function read_string(stat) {
|
||||
if (stat.TYPE == "SimpleStatement") {
|
||||
var body = stat.body;
|
||||
switch(body.TYPE) {
|
||||
case "String":
|
||||
return body.value;
|
||||
case "Array":
|
||||
return body.elements.map(function(element) {
|
||||
if (element.TYPE !== "String")
|
||||
throw new Error("Should be array of strings");
|
||||
return element.value;
|
||||
}).join("\n");
|
||||
}
|
||||
}
|
||||
throw new Error("Should be string or array of strings");
|
||||
}
|
||||
|
||||
function get_one_test(name, block) {
|
||||
var test = { name: name, options: {} };
|
||||
var tw = new U.TreeWalker(function(node, descend) {
|
||||
if (node instanceof U.AST_Assign) {
|
||||
if (!(node.left instanceof U.AST_SymbolRef)) {
|
||||
croak(node);
|
||||
}
|
||||
var name = node.left.name;
|
||||
test[name] = evaluate(node.right);
|
||||
return true;
|
||||
}
|
||||
if (node instanceof U.AST_LabeledStatement) {
|
||||
var label = node.label;
|
||||
assert.ok(
|
||||
[
|
||||
"input",
|
||||
"expect",
|
||||
"expect_exact",
|
||||
"expect_warnings",
|
||||
"expect_stdout",
|
||||
"node_version",
|
||||
].indexOf(label.name) >= 0,
|
||||
tmpl("Unsupported label {name} [{line},{col}]", {
|
||||
name: label.name,
|
||||
line: label.start.line,
|
||||
col: label.start.col
|
||||
})
|
||||
);
|
||||
var stat = node.body;
|
||||
if (label.name == "expect_exact" || label.name == "node_version") {
|
||||
test[label.name] = read_string(stat);
|
||||
} else if (label.name == "expect_stdout") {
|
||||
var body = stat.body;
|
||||
if (body instanceof U.AST_Boolean) {
|
||||
test[label.name] = body.value;
|
||||
} else if (body instanceof U.AST_Call) {
|
||||
var ctor = global[body.expression.name];
|
||||
assert.ok(ctor === Error || ctor.prototype instanceof Error, tmpl("Unsupported expect_stdout format [{line},{col}]", {
|
||||
line: label.start.line,
|
||||
col: label.start.col
|
||||
}));
|
||||
test[label.name] = ctor.apply(null, body.args.map(function(node) {
|
||||
assert.ok(node instanceof U.AST_Constant, tmpl("Unsupported expect_stdout format [{line},{col}]", {
|
||||
line: label.start.line,
|
||||
col: label.start.col
|
||||
}));
|
||||
return node.value;
|
||||
}));
|
||||
} else {
|
||||
test[label.name] = read_string(stat) + "\n";
|
||||
}
|
||||
} else {
|
||||
test[label.name] = stat;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
});
|
||||
block.walk(tw);
|
||||
return test;
|
||||
};
|
||||
}
|
||||
|
||||
function make_code(ast, options) {
|
||||
var stream = U.OutputStream(options);
|
||||
ast.print(stream);
|
||||
return stream.get();
|
||||
}
|
||||
|
||||
function evaluate(code) {
|
||||
if (code instanceof U.AST_Node)
|
||||
code = make_code(code, { beautify: true });
|
||||
return new Function("return(" + code + ")")();
|
||||
}
|
||||
|
||||
function run_code(code) {
|
||||
var result = sandbox.run_code(code, true);
|
||||
return typeof result == "string" ? result.replace(/\u001b\[\d+m/g, "") : result;
|
||||
}
|
||||
|
||||
// Try to reminify original input with standard options
|
||||
// to see if it matches expect_stdout.
|
||||
function reminify(orig_options, input_code, input_formatted, expect_stdout) {
|
||||
for (var i = 0; i < minify_options.length; i++) {
|
||||
var options = JSON.parse(minify_options[i]);
|
||||
if (options.compress) [
|
||||
"keep_fargs",
|
||||
"keep_fnames",
|
||||
].forEach(function(name) {
|
||||
if (name in orig_options) {
|
||||
options.compress[name] = orig_options[name];
|
||||
}
|
||||
});
|
||||
var options_formatted = JSON.stringify(options, null, 4);
|
||||
var result = U.minify(input_code, options);
|
||||
if (result.error) {
|
||||
log("!!! failed input reminify\n---INPUT---\n{input}\n---OPTIONS---\n{options}\n--ERROR---\n{error}\n\n", {
|
||||
input: input_formatted,
|
||||
options: options_formatted,
|
||||
error: result.error,
|
||||
});
|
||||
return false;
|
||||
} else {
|
||||
var stdout = run_code(result.code);
|
||||
if (typeof expect_stdout != "string" && typeof stdout != "string" && expect_stdout.name == stdout.name) {
|
||||
stdout = expect_stdout;
|
||||
}
|
||||
if (!sandbox.same_stdout(expect_stdout, stdout)) {
|
||||
log("!!! failed running reminified input\n---INPUT---\n{input}\n---OPTIONS---\n{options}\n---OUTPUT---\n{output}\n---EXPECTED {expected_type}---\n{expected}\n---ACTUAL {actual_type}---\n{actual}\n\n", {
|
||||
input: input_formatted,
|
||||
options: options_formatted,
|
||||
output: result.code,
|
||||
expected_type: typeof expect_stdout == "string" ? "STDOUT" : "ERROR",
|
||||
expected: expect_stdout,
|
||||
actual_type: typeof stdout == "string" ? "STDOUT" : "ERROR",
|
||||
actual: stdout,
|
||||
});
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@@ -1,45 +1,8 @@
|
||||
var semver = require("semver");
|
||||
var vm = require("vm");
|
||||
|
||||
function createContext() {
|
||||
return vm.createContext(Object.defineProperty({}, "console", {
|
||||
value: {
|
||||
log: function(msg) {
|
||||
if (arguments.length == 1 && typeof msg == "string") {
|
||||
return console.log("%s", msg);
|
||||
}
|
||||
return console.log.apply(console, [].map.call(arguments, function(arg) {
|
||||
return safe_log(arg, 3);
|
||||
}));
|
||||
}
|
||||
}
|
||||
}));
|
||||
}
|
||||
|
||||
function safe_log(arg, level) {
|
||||
if (arg) switch (typeof arg) {
|
||||
case "function":
|
||||
return arg.toString();
|
||||
case "object":
|
||||
if (/Error$/.test(arg.name)) return arg.toString();
|
||||
arg.constructor.toString();
|
||||
if (level--) for (var key in arg) {
|
||||
var desc = Object.getOwnPropertyDescriptor(arg, key);
|
||||
if (!desc || !desc.get) {
|
||||
arg[key] = safe_log(arg[key], level);
|
||||
}
|
||||
}
|
||||
}
|
||||
return arg;
|
||||
}
|
||||
|
||||
function strip_func_ids(text) {
|
||||
return ("" + text).replace(/F[0-9]{6}N/g, "<F<>N>");
|
||||
}
|
||||
|
||||
var context;
|
||||
var FUNC_TOSTRING = [
|
||||
"[ Array, Boolean, Error, Function, Number, Object, RegExp, String].forEach(function(f) {",
|
||||
var setupContext = new vm.Script([
|
||||
"[ Array, Boolean, Error, Function, Number, Object, RegExp, String ].forEach(function(f) {",
|
||||
" f.toString = Function.prototype.toString;",
|
||||
"});",
|
||||
"Function.prototype.toString = function() {",
|
||||
@@ -59,33 +22,58 @@ var FUNC_TOSTRING = [
|
||||
' return "function(){}";',
|
||||
" };",
|
||||
"}();",
|
||||
]).join("\n");
|
||||
exports.run_code = function(code, reuse) {
|
||||
"this;",
|
||||
]).join("\n"));
|
||||
|
||||
function createContext() {
|
||||
var ctx = vm.createContext(Object.defineProperty({}, "console", { value: { log: log } }));
|
||||
var global = setupContext.runInContext(ctx);
|
||||
return ctx;
|
||||
|
||||
function safe_log(arg, level) {
|
||||
if (arg) switch (typeof arg) {
|
||||
case "function":
|
||||
return arg.toString();
|
||||
case "object":
|
||||
if (arg === global) return "[object global]";
|
||||
if (/Error$/.test(arg.name)) return arg.toString();
|
||||
arg.constructor.toString();
|
||||
if (level--) for (var key in arg) {
|
||||
var desc = Object.getOwnPropertyDescriptor(arg, key);
|
||||
if (!desc || !desc.get) arg[key] = safe_log(arg[key], level);
|
||||
}
|
||||
}
|
||||
return arg;
|
||||
}
|
||||
|
||||
function log(msg) {
|
||||
if (arguments.length == 1 && typeof msg == "string") return console.log("%s", msg);
|
||||
return console.log.apply(console, [].map.call(arguments, function(arg) {
|
||||
return safe_log(arg, 3);
|
||||
}));
|
||||
}
|
||||
}
|
||||
|
||||
exports.run_code = function(code, toplevel) {
|
||||
var stdout = "";
|
||||
var original_write = process.stdout.write;
|
||||
process.stdout.write = function(chunk) {
|
||||
stdout += chunk;
|
||||
};
|
||||
try {
|
||||
if (!reuse || !context) context = createContext();
|
||||
vm.runInContext([
|
||||
FUNC_TOSTRING,
|
||||
"!function() {",
|
||||
code,
|
||||
"}();",
|
||||
].join("\n"), context, { timeout: 5000 });
|
||||
vm.runInContext(toplevel ? "(function(){" + code + "})()" : code, createContext(), { timeout: 5000 });
|
||||
return stdout;
|
||||
} catch (ex) {
|
||||
return ex;
|
||||
} finally {
|
||||
process.stdout.write = original_write;
|
||||
if (!reuse || code.indexOf(".prototype") >= 0) {
|
||||
context = null;
|
||||
} else for (var key in context) {
|
||||
delete context[key];
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
function strip_func_ids(text) {
|
||||
return ("" + text).replace(/F[0-9]{6}N/g, "<F<>N>");
|
||||
}
|
||||
|
||||
exports.same_stdout = semver.satisfies(process.version, "0.12") ? function(expected, actual) {
|
||||
if (typeof expected != typeof actual) return false;
|
||||
if (typeof expected != "string") {
|
||||
|
||||
@@ -1,82 +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;
|
||||
(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 (when idle)",
|
||||
branch: branch,
|
||||
config: {
|
||||
merge_mode: "replace",
|
||||
language: "node_js",
|
||||
node_js: "9",
|
||||
sudo: false,
|
||||
script: "node test/travis-ufuzz run"
|
||||
}
|
||||
}
|
||||
}));
|
||||
})();
|
||||
} else {
|
||||
console.log("Usage: test/travis-ufuzz.js <token> [branch] [repository] [concurrency]");
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
@@ -16,6 +16,7 @@
|
||||
},
|
||||
{},
|
||||
{
|
||||
"ie8": true,
|
||||
"toplevel": true
|
||||
},
|
||||
{
|
||||
44
test/ufuzz/travis.js
Normal file
44
test/ufuzz/travis.js
Normal file
@@ -0,0 +1,44 @@
|
||||
"use strict";
|
||||
|
||||
var child_process = require("child_process");
|
||||
var https = require("https");
|
||||
var url = require("url");
|
||||
|
||||
var period = 45 * 60 * 1000;
|
||||
var wait = 2 * 60 * 1000;
|
||||
if (process.argv.length > 2) {
|
||||
var token = process.argv[2];
|
||||
var branch = process.argv[3] || "v" + require("../../package.json").version;
|
||||
var repository = encodeURIComponent(process.argv[4] || "mishoo/UglifyJS2");
|
||||
var concurrency = process.argv[5] || 1;
|
||||
var platform = process.argv[6] || "latest";
|
||||
(function request() {
|
||||
setTimeout(request, (period + wait) / concurrency);
|
||||
var options = url.parse("https://api.travis-ci.org/repo/" + repository + "/requests");
|
||||
options.method = "POST";
|
||||
options.headers = {
|
||||
"Content-Type": "application/json",
|
||||
"Travis-API-Version": 3,
|
||||
"Authorization": "token " + token
|
||||
};
|
||||
https.request(options, function(res) {
|
||||
console.log("HTTP", res.statusCode);
|
||||
console.log(JSON.stringify(res.headers, null, 2));
|
||||
console.log();
|
||||
res.setEncoding("utf8");
|
||||
res.on("data", console.log);
|
||||
}).on("error", console.error).end(JSON.stringify({
|
||||
request: {
|
||||
message: "ufuzz testing",
|
||||
branch: branch,
|
||||
config: {
|
||||
cache: false,
|
||||
env: "NODE=" + platform,
|
||||
script: "node test/ufuzz/job " + period
|
||||
}
|
||||
}
|
||||
}));
|
||||
})();
|
||||
} else {
|
||||
console.log("Usage: test/ufuzz/travis.js <token> [branch] [repository] [concurrency] [platform]");
|
||||
}
|
||||
1249
tools/domprops.json
1249
tools/domprops.json
File diff suppressed because it is too large
Load Diff
@@ -1,6 +1,6 @@
|
||||
exports["Dictionary"] = Dictionary;
|
||||
exports["TreeWalker"] = TreeWalker;
|
||||
exports["TreeTransformer"] = TreeTransformer;
|
||||
exports["minify"] = minify;
|
||||
exports["parse"] = parse;
|
||||
exports["_push_uniq"] = push_uniq;
|
||||
exports["push_uniq"] = push_uniq;
|
||||
exports["TreeTransformer"] = TreeTransformer;
|
||||
exports["TreeWalker"] = TreeWalker;
|
||||
|
||||
@@ -1,21 +1,19 @@
|
||||
var fs = require("fs");
|
||||
|
||||
exports.FILES = [
|
||||
"../lib/utils.js",
|
||||
"../lib/ast.js",
|
||||
"../lib/parse.js",
|
||||
"../lib/transform.js",
|
||||
"../lib/scope.js",
|
||||
"../lib/output.js",
|
||||
"../lib/compress.js",
|
||||
"../lib/sourcemap.js",
|
||||
"../lib/mozilla-ast.js",
|
||||
"../lib/propmangle.js",
|
||||
"../lib/minify.js",
|
||||
"./exports.js",
|
||||
].map(function(file) {
|
||||
return require.resolve(file);
|
||||
});
|
||||
require.resolve("../lib/utils.js"),
|
||||
require.resolve("../lib/ast.js"),
|
||||
require.resolve("../lib/parse.js"),
|
||||
require.resolve("../lib/transform.js"),
|
||||
require.resolve("../lib/scope.js"),
|
||||
require.resolve("../lib/output.js"),
|
||||
require.resolve("../lib/compress.js"),
|
||||
require.resolve("../lib/sourcemap.js"),
|
||||
require.resolve("../lib/mozilla-ast.js"),
|
||||
require.resolve("../lib/propmangle.js"),
|
||||
require.resolve("../lib/minify.js"),
|
||||
require.resolve("./exports.js"),
|
||||
];
|
||||
|
||||
new Function("MOZ_SourceMap", "exports", function() {
|
||||
var code = exports.FILES.map(function(file) {
|
||||
@@ -48,7 +46,9 @@ function describe_ast() {
|
||||
if (ctor.SUBCLASSES.length > 0) {
|
||||
out.space();
|
||||
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();
|
||||
doitem(ctor);
|
||||
out.newline();
|
||||
|
||||
591
tools/props.html
591
tools/props.html
@@ -1,61 +1,540 @@
|
||||
<!doctype html>
|
||||
<html>
|
||||
<head>
|
||||
</head>
|
||||
<body>
|
||||
<script>(function(){
|
||||
var props = {};
|
||||
<body>
|
||||
<script>
|
||||
!function() {
|
||||
var names = [];
|
||||
var scanned = [];
|
||||
var to_scan = [];
|
||||
|
||||
function addObject(obj) {
|
||||
if (obj == null) return;
|
||||
try {
|
||||
Object.getOwnPropertyNames(obj).forEach(add);
|
||||
} catch(ex) {}
|
||||
if (obj.prototype) {
|
||||
Object.getOwnPropertyNames(obj.prototype).forEach(add);
|
||||
}
|
||||
if (typeof obj == "function") {
|
||||
try {
|
||||
Object.getOwnPropertyNames(new obj).forEach(add);
|
||||
} catch(ex) {}
|
||||
}
|
||||
}
|
||||
function scan(obj) {
|
||||
if (obj && typeof obj == "object" && !~scanned.indexOf(obj)) {
|
||||
scanned.push(obj);
|
||||
to_scan.push(obj);
|
||||
}
|
||||
}
|
||||
|
||||
function add(name) {
|
||||
props[name] = true;
|
||||
}
|
||||
scan(self);
|
||||
[
|
||||
"a",
|
||||
"abbr",
|
||||
"acronym",
|
||||
"address",
|
||||
"applet",
|
||||
"area",
|
||||
"article",
|
||||
"aside",
|
||||
"audio",
|
||||
"b",
|
||||
"base",
|
||||
"basefont",
|
||||
"bdi",
|
||||
"bdo",
|
||||
"bgsound",
|
||||
"big",
|
||||
"blink",
|
||||
"blockquote",
|
||||
"body",
|
||||
"br",
|
||||
"button",
|
||||
"canvas",
|
||||
"caption",
|
||||
"center",
|
||||
"checked",
|
||||
"cite",
|
||||
"code",
|
||||
"col",
|
||||
"colgroup",
|
||||
"command",
|
||||
"comment",
|
||||
"compact",
|
||||
"content",
|
||||
"data",
|
||||
"datalist",
|
||||
"dd",
|
||||
"declare",
|
||||
"defer",
|
||||
"del",
|
||||
"details",
|
||||
"dfn",
|
||||
"dialog",
|
||||
"dir",
|
||||
"disabled",
|
||||
"div",
|
||||
"dl",
|
||||
"dt",
|
||||
"element",
|
||||
"em",
|
||||
"embed",
|
||||
"fieldset",
|
||||
"figcaption",
|
||||
"figure",
|
||||
"font",
|
||||
"footer",
|
||||
"form",
|
||||
"frame",
|
||||
"frameset",
|
||||
"h1",
|
||||
"h2",
|
||||
"h3",
|
||||
"h4",
|
||||
"h5",
|
||||
"h6",
|
||||
"head",
|
||||
"header",
|
||||
"hgroup",
|
||||
"hr",
|
||||
"html",
|
||||
"i",
|
||||
"iframe",
|
||||
"image",
|
||||
"img",
|
||||
"input",
|
||||
"ins",
|
||||
"isindex",
|
||||
"ismap",
|
||||
"kbd",
|
||||
"keygen",
|
||||
"label",
|
||||
"legend",
|
||||
"li",
|
||||
"link",
|
||||
"listing",
|
||||
"main",
|
||||
"map",
|
||||
"mark",
|
||||
"marquee",
|
||||
"math",
|
||||
"menu",
|
||||
"menuitem",
|
||||
"meta",
|
||||
"meter",
|
||||
"multicol",
|
||||
"multiple",
|
||||
"nav",
|
||||
"nobr",
|
||||
"noembed",
|
||||
"noframes",
|
||||
"nohref",
|
||||
"noresize",
|
||||
"noscript",
|
||||
"noshade",
|
||||
"nowrap",
|
||||
"object",
|
||||
"ol",
|
||||
"optgroup",
|
||||
"option",
|
||||
"output",
|
||||
"p",
|
||||
"param",
|
||||
"picture",
|
||||
"plaintext",
|
||||
"pre",
|
||||
"progress",
|
||||
"q",
|
||||
"rb",
|
||||
"readonly",
|
||||
"rp",
|
||||
"rt",
|
||||
"rtc",
|
||||
"ruby",
|
||||
"s",
|
||||
"samp",
|
||||
"script",
|
||||
"section",
|
||||
"select",
|
||||
"selected",
|
||||
"shadow",
|
||||
"small",
|
||||
"source",
|
||||
"spacer",
|
||||
"span",
|
||||
"strike",
|
||||
"strong",
|
||||
"style",
|
||||
"sub",
|
||||
"summary",
|
||||
"sup",
|
||||
"svg",
|
||||
"table",
|
||||
"tbody",
|
||||
"td",
|
||||
"template",
|
||||
"textarea",
|
||||
"tfoot",
|
||||
"th",
|
||||
"thead",
|
||||
"time",
|
||||
"title",
|
||||
"tr",
|
||||
"track",
|
||||
"tt",
|
||||
"u",
|
||||
"ul",
|
||||
"var",
|
||||
"video",
|
||||
"wbr",
|
||||
"xmp",
|
||||
"XXX",
|
||||
].forEach(function(tag) {
|
||||
scan(document.createElement(tag));
|
||||
});
|
||||
[
|
||||
"abort",
|
||||
"absolutedeviceorientation",
|
||||
"activate",
|
||||
"active",
|
||||
"addsourcebuffer",
|
||||
"addstream",
|
||||
"addtrack",
|
||||
"afterprint",
|
||||
"afterscriptexecute",
|
||||
"afterupdate",
|
||||
"animationcancel",
|
||||
"animationend",
|
||||
"animationiteration",
|
||||
"animationstart",
|
||||
"appinstalled",
|
||||
"audioend",
|
||||
"audioprocess",
|
||||
"audiostart",
|
||||
"autocomplete",
|
||||
"autocompleteerror",
|
||||
"auxclick",
|
||||
"beforeactivate",
|
||||
"beforecopy",
|
||||
"beforecut",
|
||||
"beforedeactivate",
|
||||
"beforeeditfocus",
|
||||
"beforeinstallprompt",
|
||||
"beforepaste",
|
||||
"beforeprint",
|
||||
"beforescriptexecute",
|
||||
"beforeunload",
|
||||
"beforeupdate",
|
||||
"blocked",
|
||||
"blur",
|
||||
"bounce",
|
||||
"boundary",
|
||||
"cached",
|
||||
"cancel",
|
||||
"candidatewindowhide",
|
||||
"candidatewindowshow",
|
||||
"candidatewindowupdate",
|
||||
"canplay",
|
||||
"canplaythrough",
|
||||
"cellchange",
|
||||
"change",
|
||||
"chargingchange",
|
||||
"chargingtimechange",
|
||||
"checking",
|
||||
"click",
|
||||
"close",
|
||||
"compassneedscalibration",
|
||||
"complete",
|
||||
"connect",
|
||||
"connecting",
|
||||
"connectionstatechange",
|
||||
"contextmenu",
|
||||
"controllerchange",
|
||||
"controlselect",
|
||||
"copy",
|
||||
"cuechange",
|
||||
"cut",
|
||||
"dataavailable",
|
||||
"datachannel",
|
||||
"datasetchanged",
|
||||
"datasetcomplete",
|
||||
"dblclick",
|
||||
"deactivate",
|
||||
"devicechange",
|
||||
"devicelight",
|
||||
"devicemotion",
|
||||
"deviceorientation",
|
||||
"deviceorientationabsolute",
|
||||
"deviceproximity",
|
||||
"dischargingtimechange",
|
||||
"disconnect",
|
||||
"display",
|
||||
"downloading",
|
||||
"drag",
|
||||
"dragend",
|
||||
"dragenter",
|
||||
"dragexit",
|
||||
"dragleave",
|
||||
"dragover",
|
||||
"dragstart",
|
||||
"drop",
|
||||
"durationchange",
|
||||
"emptied",
|
||||
"encrypted",
|
||||
"end",
|
||||
"ended",
|
||||
"enter",
|
||||
"enterpictureinpicture",
|
||||
"error",
|
||||
"errorupdate",
|
||||
"exit",
|
||||
"filterchange",
|
||||
"finish",
|
||||
"focus",
|
||||
"focusin",
|
||||
"focusout",
|
||||
"freeze",
|
||||
"fullscreenchange",
|
||||
"fullscreenerror",
|
||||
"gesturechange",
|
||||
"gestureend",
|
||||
"gesturestart",
|
||||
"gotpointercapture",
|
||||
"hashchange",
|
||||
"help",
|
||||
"icecandidate",
|
||||
"iceconnectionstatechange",
|
||||
"icegatheringstatechange",
|
||||
"inactive",
|
||||
"input",
|
||||
"invalid",
|
||||
"keydown",
|
||||
"keypress",
|
||||
"keyup",
|
||||
"languagechange",
|
||||
"layoutcomplete",
|
||||
"leavepictureinpicture",
|
||||
"levelchange",
|
||||
"load",
|
||||
"loadeddata",
|
||||
"loadedmetadata",
|
||||
"loadend",
|
||||
"loading",
|
||||
"loadingdone",
|
||||
"loadingerror",
|
||||
"loadstart",
|
||||
"losecapture",
|
||||
"lostpointercapture",
|
||||
"mark",
|
||||
"message",
|
||||
"messageerror",
|
||||
"mousedown",
|
||||
"mouseenter",
|
||||
"mouseleave",
|
||||
"mousemove",
|
||||
"mouseout",
|
||||
"mouseover",
|
||||
"mouseup",
|
||||
"mousewheel",
|
||||
"move",
|
||||
"moveend",
|
||||
"movestart",
|
||||
"mozfullscreenchange",
|
||||
"mozfullscreenerror",
|
||||
"mozorientationchange",
|
||||
"mozpointerlockchange",
|
||||
"mozpointerlockerror",
|
||||
"mscontentzoom",
|
||||
"msfullscreenchange",
|
||||
"msfullscreenerror",
|
||||
"msgesturechange",
|
||||
"msgesturedoubletap",
|
||||
"msgestureend",
|
||||
"msgesturehold",
|
||||
"msgesturestart",
|
||||
"msgesturetap",
|
||||
"msgotpointercapture",
|
||||
"msinertiastart",
|
||||
"mslostpointercapture",
|
||||
"msmanipulationstatechanged",
|
||||
"msneedkey",
|
||||
"msorientationchange",
|
||||
"mspointercancel",
|
||||
"mspointerdown",
|
||||
"mspointerenter",
|
||||
"mspointerhover",
|
||||
"mspointerleave",
|
||||
"mspointermove",
|
||||
"mspointerout",
|
||||
"mspointerover",
|
||||
"mspointerup",
|
||||
"mssitemodejumplistitemremoved",
|
||||
"msthumbnailclick",
|
||||
"negotiationneeded",
|
||||
"nomatch",
|
||||
"noupdate",
|
||||
"obsolete",
|
||||
"offline",
|
||||
"online",
|
||||
"open",
|
||||
"orientationchange",
|
||||
"pagechange",
|
||||
"pagehide",
|
||||
"pageshow",
|
||||
"paste",
|
||||
"pause",
|
||||
"play",
|
||||
"playing",
|
||||
"pluginstreamstart",
|
||||
"pointercancel",
|
||||
"pointerdown",
|
||||
"pointerenter",
|
||||
"pointerleave",
|
||||
"pointerlockchange",
|
||||
"pointerlockerror",
|
||||
"pointermove",
|
||||
"pointerout",
|
||||
"pointerover",
|
||||
"pointerup",
|
||||
"popstate",
|
||||
"progress",
|
||||
"propertychange",
|
||||
"ratechange",
|
||||
"reading",
|
||||
"readystatechange",
|
||||
"rejectionhandled",
|
||||
"removesourcebuffer",
|
||||
"removestream",
|
||||
"removetrack",
|
||||
"reset",
|
||||
"resize",
|
||||
"resizeend",
|
||||
"resizestart",
|
||||
"resourcetimingbufferfull",
|
||||
"result",
|
||||
"resume",
|
||||
"rowenter",
|
||||
"rowexit",
|
||||
"rowsdelete",
|
||||
"rowsinserted",
|
||||
"scroll",
|
||||
"search",
|
||||
"seeked",
|
||||
"seeking",
|
||||
"select",
|
||||
"selectionchange",
|
||||
"selectstart",
|
||||
"show",
|
||||
"signalingstatechange",
|
||||
"soundend",
|
||||
"soundstart",
|
||||
"sourceclose",
|
||||
"sourceclosed",
|
||||
"sourceended",
|
||||
"sourceopen",
|
||||
"speechend",
|
||||
"speechstart",
|
||||
"stalled",
|
||||
"start",
|
||||
"statechange",
|
||||
"stop",
|
||||
"storage",
|
||||
"storagecommit",
|
||||
"submit",
|
||||
"success",
|
||||
"suspend",
|
||||
"textinput",
|
||||
"timeout",
|
||||
"timeupdate",
|
||||
"toggle",
|
||||
"touchcancel",
|
||||
"touchend",
|
||||
"touchmove",
|
||||
"touchstart",
|
||||
"track",
|
||||
"transitioncancel",
|
||||
"transitionend",
|
||||
"transitionrun",
|
||||
"transitionstart",
|
||||
"unhandledrejection",
|
||||
"unload",
|
||||
"updateready",
|
||||
"upgradeneeded",
|
||||
"userproximity",
|
||||
"versionchange",
|
||||
"visibilitychange",
|
||||
"voiceschanged",
|
||||
"volumechange",
|
||||
"vrdisplayactivate",
|
||||
"vrdisplayconnect",
|
||||
"vrdisplaydeactivate",
|
||||
"vrdisplaydisconnect",
|
||||
"vrdisplaypresentchange",
|
||||
"waiting",
|
||||
"waitingforkey",
|
||||
"warning",
|
||||
"webkitanimationend",
|
||||
"webkitanimationiteration",
|
||||
"webkitanimationstart",
|
||||
"webkitcurrentplaybacktargetiswirelesschanged",
|
||||
"webkitfullscreenchange",
|
||||
"webkitfullscreenerror",
|
||||
"webkitkeyadded",
|
||||
"webkitkeyerror",
|
||||
"webkitkeymessage",
|
||||
"webkitneedkey",
|
||||
"webkitorientationchange",
|
||||
"webkitplaybacktargetavailabilitychanged",
|
||||
"webkitpointerlockchange",
|
||||
"webkitpointerlockerror",
|
||||
"webkitresourcetimingbufferfull",
|
||||
"webkittransitionend",
|
||||
"wheel",
|
||||
"zoom",
|
||||
].forEach(function(type) {
|
||||
[
|
||||
"beforeunloadevent",
|
||||
"compositionevent",
|
||||
"customevent",
|
||||
"devicemotionevent",
|
||||
"deviceorientationevent",
|
||||
"dragevent",
|
||||
"event",
|
||||
"events",
|
||||
"focusevent",
|
||||
"hashchangeevent",
|
||||
"htmlevents",
|
||||
"keyboardevent",
|
||||
"messageevent",
|
||||
"mouseevent",
|
||||
"mouseevents",
|
||||
"storageevent",
|
||||
"svgevents",
|
||||
"textevent",
|
||||
"touchevent",
|
||||
"uievent",
|
||||
"uievents",
|
||||
].forEach(function(interface) {
|
||||
try {
|
||||
var event = document.createEvent(interface);
|
||||
event.initEvent(type, true, true);
|
||||
scan(event);
|
||||
} catch (e) {}
|
||||
});
|
||||
});
|
||||
|
||||
Object.getOwnPropertyNames(window).forEach(function(thing){
|
||||
addObject(window[thing]);
|
||||
});
|
||||
|
||||
try {
|
||||
addObject(new Event("click"));
|
||||
addObject(new Event("contextmenu"));
|
||||
addObject(new Event("mouseup"));
|
||||
addObject(new Event("mousedown"));
|
||||
addObject(new Event("keydown"));
|
||||
addObject(new Event("keypress"));
|
||||
addObject(new Event("keyup"));
|
||||
} catch(ex) {}
|
||||
|
||||
var ta = document.createElement("textarea");
|
||||
ta.style.width = "100%";
|
||||
ta.style.height = "20em";
|
||||
ta.style.boxSizing = "border-box";
|
||||
<!-- ta.value = Object.keys(props).sort(cmp).map(function(name){ -->
|
||||
<!-- return JSON.stringify(name); -->
|
||||
<!-- }).join(",\n"); -->
|
||||
ta.value = JSON.stringify({
|
||||
vars: [],
|
||||
props: Object.keys(props).sort(cmp)
|
||||
}, null, 2);
|
||||
document.body.appendChild(ta);
|
||||
|
||||
function cmp(a, b) {
|
||||
a = a.toLowerCase();
|
||||
b = b.toLowerCase();
|
||||
return a < b ? -1 : a > b ? 1 : 0;
|
||||
}
|
||||
})();</script>
|
||||
</body>
|
||||
var obj;
|
||||
while (obj = to_scan.shift()) {
|
||||
var proto = obj;
|
||||
do {
|
||||
Object.getOwnPropertyNames(proto).forEach(function(name) {
|
||||
var visited = ~names.indexOf(name);
|
||||
if (!visited) names.push(name);
|
||||
try {
|
||||
scan(obj[name]);
|
||||
if (visited) return;
|
||||
if (/^create/.test(name)) {
|
||||
scan(obj[name]());
|
||||
}
|
||||
if (/^[A-Z]/.test(name)) {
|
||||
scan(new obj[name]());
|
||||
}
|
||||
} catch (e) {}
|
||||
});
|
||||
} while (proto = Object.getPrototypeOf(proto));
|
||||
}
|
||||
names.sort();
|
||||
document.write('<pre>[\n "');
|
||||
document.write(names.join('",\n "'));
|
||||
document.write('"\n]</pre>');
|
||||
}();
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
Reference in New Issue
Block a user