Compare commits
275 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
5beb7e4797 | ||
|
|
46caaa82ba | ||
|
|
5d258259a4 | ||
|
|
14c35739dd | ||
|
|
f5ceff6e4b | ||
|
|
4d6771b9b1 | ||
|
|
d17191111a | ||
|
|
0ff607cb80 | ||
|
|
1988495d71 | ||
|
|
fdc10086da | ||
|
|
746f5f6c62 | ||
|
|
d83d3d741a | ||
|
|
99ac73a635 | ||
|
|
a2e4c2fd97 | ||
|
|
94785e8e14 | ||
|
|
4dbdac9c31 | ||
|
|
78c8efd851 | ||
|
|
af310ba2d0 | ||
|
|
2f3930d1b9 | ||
|
|
d1a78920d9 | ||
|
|
d9cd3d33c8 | ||
|
|
22b47cdd63 | ||
|
|
4cf612dc9f | ||
|
|
a19d31dd33 | ||
|
|
01d6e0f223 | ||
|
|
ab050e7a94 | ||
|
|
75aa6ef848 | ||
|
|
519a00bd8a | ||
|
|
3ff0feddee | ||
|
|
74396acc86 | ||
|
|
036bca980c | ||
|
|
18c2b1841b | ||
|
|
fe19ab7c57 | ||
|
|
9074f05129 | ||
|
|
04fbb1f949 | ||
|
|
bf7e4ca1a3 | ||
|
|
d68ddc31f9 | ||
|
|
500e31e03b | ||
|
|
bef856addb | ||
|
|
9a6faf365b | ||
|
|
e915832a36 | ||
|
|
0593892d6e | ||
|
|
b866a23671 | ||
|
|
1283d73853 | ||
|
|
1b61a81b5d | ||
|
|
5a88c30d65 | ||
|
|
168ae747ad | ||
|
|
d4b7010678 | ||
|
|
e27493f3c2 | ||
|
|
292d1de363 | ||
|
|
6768e6578f | ||
|
|
48a0f6fe41 | ||
|
|
81caadb709 | ||
|
|
d959e0b86f | ||
|
|
67278e76c8 | ||
|
|
c289ba1139 | ||
|
|
02cc4a0d03 | ||
|
|
4e06e1ca34 | ||
|
|
644f65feca | ||
|
|
8504a4ea0e | ||
|
|
10c1a78772 | ||
|
|
a6a0319f1c | ||
|
|
d1b2ecec27 | ||
|
|
552be61c4d | ||
|
|
dcfc4aca5b | ||
|
|
4027f87717 | ||
|
|
910799ca99 | ||
|
|
4bd36dc8da | ||
|
|
ab15c40770 | ||
|
|
fe65ce9658 | ||
|
|
d6fd18d0b0 | ||
|
|
0d17c5b0fa | ||
|
|
5b20bad4b3 | ||
|
|
765a06340f | ||
|
|
5045e140b1 | ||
|
|
10648c9af6 | ||
|
|
87e67ec299 | ||
|
|
61a0dad9fe | ||
|
|
3e2c51a4da | ||
|
|
0e29ad5eb9 | ||
|
|
0f2687ecfc | ||
|
|
1c0defdc03 | ||
|
|
dcbf2236c7 | ||
|
|
24bb288832 | ||
|
|
6ad8e1081f | ||
|
|
815eff1f7c | ||
|
|
1e9b576ee9 | ||
|
|
3797458365 | ||
|
|
1858c2018c | ||
|
|
ec7f071272 | ||
|
|
f1eb03f2c0 | ||
|
|
0f4cfa877a | ||
|
|
1d5c2becbd | ||
|
|
22a09ea7c5 | ||
|
|
bad664c632 | ||
|
|
8a191c0a84 | ||
|
|
83fb8b4ca1 | ||
|
|
f38e31bd1e | ||
|
|
24e8b47977 | ||
|
|
95618793a4 | ||
|
|
2f3b460212 | ||
|
|
06e135e35f | ||
|
|
ebbf3d4a51 | ||
|
|
a270ba6b59 | ||
|
|
37f35e4ac2 | ||
|
|
50a578c1f6 | ||
|
|
85237b08d4 | ||
|
|
27b159e711 | ||
|
|
82b3eed5ef | ||
|
|
0f7aa41e33 | ||
|
|
370c8e0385 | ||
|
|
4240fba9b8 | ||
|
|
267bc70d33 | ||
|
|
a53ab99378 | ||
|
|
02308a7b56 | ||
|
|
0b3705e82f | ||
|
|
da5a21b240 | ||
|
|
5bd0cf8633 | ||
|
|
9199ab5846 | ||
|
|
ca6dce43fe | ||
|
|
543dd7d3d7 | ||
|
|
6b4886c908 | ||
|
|
0201cb4b52 | ||
|
|
cd072317d0 | ||
|
|
0785a15ace | ||
|
|
b1279a46d9 | ||
|
|
b571619d31 | ||
|
|
7b5350b459 | ||
|
|
1549db70e6 | ||
|
|
8ff9a3c8fb | ||
|
|
91cae51d8f | ||
|
|
8af2f5fbcf | ||
|
|
86a8016323 | ||
|
|
009dcdae01 | ||
|
|
f86f615d83 | ||
|
|
d3d1d11926 | ||
|
|
736019b767 | ||
|
|
a39bdb5840 | ||
|
|
e8ab0a44b2 | ||
|
|
c3ca293e6b | ||
|
|
516b67a43b | ||
|
|
eba3a37bb5 | ||
|
|
6d57ca1a59 | ||
|
|
3320251b4b | ||
|
|
33c94d3bd9 | ||
|
|
b18f717b46 | ||
|
|
a0d4b648bb | ||
|
|
6db880e16d | ||
|
|
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 | ||
|
|
fdee083465 | ||
|
|
5ffc17d4aa | ||
|
|
6aa750010f | ||
|
|
76df77c08c | ||
|
|
957d5537a8 |
31
.github/workflows/ci.yml
vendored
Normal file
31
.github/workflows/ci.yml
vendored
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
name: CI
|
||||||
|
on: [ push, pull_request ]
|
||||||
|
jobs:
|
||||||
|
test:
|
||||||
|
strategy:
|
||||||
|
matrix:
|
||||||
|
os: [ ubuntu-latest, windows-latest ]
|
||||||
|
node: [ "0.10", 0.12, 4, 6, 8, 10, latest ]
|
||||||
|
script: [ compress, mocha, release/benchmark, release/jetstream ]
|
||||||
|
name: ${{ matrix.os }} ${{ matrix.node }} ${{ matrix.script }}
|
||||||
|
runs-on: ${{ matrix.os }}
|
||||||
|
env:
|
||||||
|
NODE: ${{ matrix.node }}
|
||||||
|
TYPE: ${{ matrix.script }}
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v1
|
||||||
|
- uses: actions/cache@v1
|
||||||
|
with:
|
||||||
|
path: tmp
|
||||||
|
key: tmp ${{ matrix.script }}
|
||||||
|
- name: Perform tests
|
||||||
|
shell: bash
|
||||||
|
run: |
|
||||||
|
git clone --branch v1.5.3 --depth 1 https://github.com/jasongin/nvs.git ~/.nvs
|
||||||
|
. ~/.nvs/nvs.sh --version
|
||||||
|
nvs add $NODE
|
||||||
|
nvs use $NODE
|
||||||
|
node --version
|
||||||
|
npm --version --no-update-notifier
|
||||||
|
npm install --no-audit --no-optional --no-save --no-update-notifier
|
||||||
|
node test/$TYPE
|
||||||
25
.github/workflows/ufuzz.yml
vendored
Normal file
25
.github/workflows/ufuzz.yml
vendored
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
name: Fuzzing
|
||||||
|
on:
|
||||||
|
schedule:
|
||||||
|
- cron: "*/15 * * * *"
|
||||||
|
jobs:
|
||||||
|
ufuzz:
|
||||||
|
strategy:
|
||||||
|
fail-fast: false
|
||||||
|
matrix:
|
||||||
|
os: [ ubuntu-latest, windows-latest ]
|
||||||
|
name: ${{ matrix.os }}
|
||||||
|
runs-on: ${{ matrix.os }}
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v1
|
||||||
|
- name: Perform fuzzing
|
||||||
|
shell: bash
|
||||||
|
run: |
|
||||||
|
git clone --branch v1.5.3 --depth 1 https://github.com/jasongin/nvs.git ~/.nvs
|
||||||
|
. ~/.nvs/nvs.sh --version
|
||||||
|
nvs add 10
|
||||||
|
nvs use 10
|
||||||
|
node --version
|
||||||
|
npm --version --no-update-notifier
|
||||||
|
npm install --no-audit --no-optional --no-save --no-update-notifier
|
||||||
|
node test/ufuzz/job 3600000
|
||||||
14
.travis.yml
14
.travis.yml
@@ -1,14 +0,0 @@
|
|||||||
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
|
|
||||||
2
LICENSE
2
LICENSE
@@ -1,6 +1,6 @@
|
|||||||
UglifyJS is released under the BSD license:
|
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
|
Redistribution and use in source and binary forms, with or without
|
||||||
modification, are permitted provided that the following conditions
|
modification, are permitted provided that the following conditions
|
||||||
|
|||||||
69
README.md
69
README.md
@@ -87,6 +87,7 @@ a double dash to prevent input files being used as option arguments:
|
|||||||
`wrap_iife` Wrap IIFEs in parenthesis. Note: you may
|
`wrap_iife` Wrap IIFEs in parenthesis. Note: you may
|
||||||
want to disable `negate_iife` under
|
want to disable `negate_iife` under
|
||||||
compressor options.
|
compressor options.
|
||||||
|
-O, --output-opts [options] Specify output options (`beautify` disabled by default).
|
||||||
-o, --output <file> Output file path (default STDOUT). Specify `ast` or
|
-o, --output <file> Output file path (default STDOUT). Specify `ast` or
|
||||||
`spidermonkey` to write UglifyJS or SpiderMonkey AST
|
`spidermonkey` to write UglifyJS or SpiderMonkey AST
|
||||||
as JSON to STDOUT respectively.
|
as JSON to STDOUT respectively.
|
||||||
@@ -478,42 +479,42 @@ if (result.error) throw result.error;
|
|||||||
|
|
||||||
## Minify options
|
## Minify options
|
||||||
|
|
||||||
- `warnings` (default `false`) — pass `true` to return compressor warnings
|
|
||||||
in `result.warnings`. Use the value `"verbose"` for more detailed warnings.
|
|
||||||
|
|
||||||
- `parse` (default `{}`) — pass an object if you wish to specify some
|
|
||||||
additional [parse options](#parse-options).
|
|
||||||
|
|
||||||
- `compress` (default `{}`) — pass `false` to skip compressing entirely.
|
- `compress` (default `{}`) — pass `false` to skip compressing entirely.
|
||||||
Pass an object to specify custom [compress options](#compress-options).
|
Pass an object to specify custom [compress options](#compress-options).
|
||||||
|
|
||||||
|
- `ie8` (default `false`) -- set to `true` to support IE8.
|
||||||
|
|
||||||
|
- `keep_fnames` (default: `false`) -- pass `true` to prevent discarding or mangling
|
||||||
|
of function names. Useful for code relying on `Function.prototype.name`.
|
||||||
|
|
||||||
- `mangle` (default `true`) — pass `false` to skip mangling names, or pass
|
- `mangle` (default `true`) — pass `false` to skip mangling names, or pass
|
||||||
an object to specify [mangle options](#mangle-options) (see below).
|
an object to specify [mangle options](#mangle-options) (see below).
|
||||||
|
|
||||||
- `mangle.properties` (default `false`) — a subcategory of the mangle option.
|
- `mangle.properties` (default `false`) — a subcategory of the mangle option.
|
||||||
Pass an object to specify custom [mangle property options](#mangle-properties-options).
|
Pass an object to specify custom [mangle property options](#mangle-properties-options).
|
||||||
|
|
||||||
- `output` (default `null`) — pass an object if you wish to specify
|
- `nameCache` (default `null`) -- pass an empty object `{}` or a previously
|
||||||
additional [output options](#output-options). The defaults are optimized
|
|
||||||
for best compression.
|
|
||||||
|
|
||||||
- `sourceMap` (default `false`) - pass an object if you wish to specify
|
|
||||||
[source map options](#source-map-options).
|
|
||||||
|
|
||||||
- `toplevel` (default `false`) - set to `true` if you wish to enable top level
|
|
||||||
variable and function name mangling and to drop unused variables and functions.
|
|
||||||
|
|
||||||
- `nameCache` (default `null`) - pass an empty object `{}` or a previously
|
|
||||||
used `nameCache` object if you wish to cache mangled variable and
|
used `nameCache` object if you wish to cache mangled variable and
|
||||||
property names across multiple invocations of `minify()`. Note: this is
|
property names across multiple invocations of `minify()`. Note: this is
|
||||||
a read/write property. `minify()` will read the name cache state of this
|
a read/write property. `minify()` will read the name cache state of this
|
||||||
object and update it during minification so that it may be
|
object and update it during minification so that it may be
|
||||||
reused or externally persisted by the user.
|
reused or externally persisted by the user.
|
||||||
|
|
||||||
- `ie8` (default `false`) - set to `true` to support IE8.
|
- `output` (default `null`) — pass an object if you wish to specify
|
||||||
|
additional [output options](#output-options). The defaults are optimized
|
||||||
|
for best compression.
|
||||||
|
|
||||||
- `keep_fnames` (default: `false`) - pass `true` to prevent discarding or mangling
|
- `parse` (default `{}`) — pass an object if you wish to specify some
|
||||||
of function names. Useful for code relying on `Function.prototype.name`.
|
additional [parse options](#parse-options).
|
||||||
|
|
||||||
|
- `sourceMap` (default `false`) -- pass an object if you wish to specify
|
||||||
|
[source map options](#source-map-options).
|
||||||
|
|
||||||
|
- `toplevel` (default `false`) -- set to `true` if you wish to enable top level
|
||||||
|
variable and function name mangling and to drop unused variables and functions.
|
||||||
|
|
||||||
|
- `warnings` (default `false`) — pass `true` to return compressor warnings
|
||||||
|
in `result.warnings`. Use the value `"verbose"` for more detailed warnings.
|
||||||
|
|
||||||
## Minify options structure
|
## Minify options structure
|
||||||
|
|
||||||
@@ -605,6 +606,8 @@ If you're using the `X-SourceMap` header instead, you can just omit `sourceMap.u
|
|||||||
- `arguments` (default: `true`) -- replace `arguments[index]` with function
|
- `arguments` (default: `true`) -- replace `arguments[index]` with function
|
||||||
parameter name whenever possible.
|
parameter name whenever possible.
|
||||||
|
|
||||||
|
- `assignments` (default: `true`) -- apply optimizations to assignment expressions.
|
||||||
|
|
||||||
- `booleans` (default: `true`) -- various optimizations for boolean context,
|
- `booleans` (default: `true`) -- various optimizations for boolean context,
|
||||||
for example `!!a ? b : c → a ? b : c`
|
for example `!!a ? b : c → a ? b : c`
|
||||||
|
|
||||||
@@ -620,6 +623,8 @@ If you're using the `X-SourceMap` header instead, you can just omit `sourceMap.u
|
|||||||
|
|
||||||
- `dead_code` (default: `true`) -- remove unreachable code
|
- `dead_code` (default: `true`) -- remove unreachable code
|
||||||
|
|
||||||
|
- `directives` (default: `true`) -- remove redundant or non-standard directives
|
||||||
|
|
||||||
- `drop_console` (default: `false`) -- Pass `true` to discard calls to
|
- `drop_console` (default: `false`) -- Pass `true` to discard calls to
|
||||||
`console.*` functions. If you wish to drop a specific function call
|
`console.*` functions. If you wish to drop a specific function call
|
||||||
such as `console.info` and/or retain side effects from function arguments
|
such as `console.info` and/or retain side effects from function arguments
|
||||||
@@ -627,11 +632,17 @@ If you're using the `X-SourceMap` header instead, you can just omit `sourceMap.u
|
|||||||
|
|
||||||
- `drop_debugger` (default: `true`) -- remove `debugger;` statements
|
- `drop_debugger` (default: `true`) -- remove `debugger;` statements
|
||||||
|
|
||||||
- `evaluate` (default: `true`) -- attempt to evaluate constant expressions
|
- `evaluate` (default: `true`) -- Evaluate expression for shorter constant
|
||||||
|
representation. Pass `"eager"` to always replace function calls whenever
|
||||||
|
possible, or a positive integer to specify an upper bound for each individual
|
||||||
|
evaluation in number of characters.
|
||||||
|
|
||||||
- `expression` (default: `false`) -- Pass `true` to preserve completion values
|
- `expression` (default: `false`) -- Pass `true` to preserve completion values
|
||||||
from terminal statements without `return`, e.g. in bookmarklets.
|
from terminal statements without `return`, e.g. in bookmarklets.
|
||||||
|
|
||||||
|
- `functions` (default: `true`) -- convert declarations from `var`to `function`
|
||||||
|
whenever possible.
|
||||||
|
|
||||||
- `global_defs` (default: `{}`) -- see [conditional compilation](#conditional-compilation)
|
- `global_defs` (default: `{}`) -- see [conditional compilation](#conditional-compilation)
|
||||||
|
|
||||||
- `hoist_funs` (default: `false`) -- hoist function declarations
|
- `hoist_funs` (default: `false`) -- hoist function declarations
|
||||||
@@ -657,12 +668,13 @@ If you're using the `X-SourceMap` header instead, you can just omit `sourceMap.u
|
|||||||
|
|
||||||
- `join_vars` (default: `true`) -- join consecutive `var` statements
|
- `join_vars` (default: `true`) -- join consecutive `var` statements
|
||||||
|
|
||||||
- `keep_fargs` (default: `true`) -- Prevents the compressor from discarding unused
|
- `keep_fargs` (default: `strict`) -- Discard unused function arguments. Code
|
||||||
function arguments. You need this for code which relies on `Function.length`.
|
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
|
- `keep_fnames` (default: `false`) -- Pass `true` to prevent the
|
||||||
compressor from discarding function names. Useful for code relying on
|
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
|
- `keep_infinity` (default: `false`) -- Pass `true` to prevent `Infinity` from
|
||||||
being compressed into `1/0`, which may cause performance issues on Chrome.
|
being compressed into `1/0`, which may cause performance issues on Chrome.
|
||||||
@@ -674,6 +686,8 @@ If you're using the `X-SourceMap` header instead, you can just omit `sourceMap.u
|
|||||||
where the return value is discarded, to avoid the parens that the
|
where the return value is discarded, to avoid the parens that the
|
||||||
code generator would insert.
|
code generator would insert.
|
||||||
|
|
||||||
|
- `objects` (default: `true`) -- compact duplicate keys in object literals.
|
||||||
|
|
||||||
- `passes` (default: `1`) -- The maximum number of times to run compress.
|
- `passes` (default: `1`) -- The maximum number of times to run compress.
|
||||||
In some cases more than one pass leads to further compressed code. Keep in
|
In some cases more than one pass leads to further compressed code. Keep in
|
||||||
mind more passes will take more time.
|
mind more passes will take more time.
|
||||||
@@ -760,9 +774,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
|
- `unused` (default: `true`) -- drop unreferenced functions and variables (simple
|
||||||
direct variable assignments do not count as references unless set to `"keep_assign"`)
|
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
|
## Mangle options
|
||||||
|
|
||||||
- `eval` (default `false`) -- Pass `true` to mangle names visible in scopes
|
- `eval` (default `false`) -- Pass `true` to mangle names visible in scopes
|
||||||
@@ -855,8 +866,8 @@ can pass additional arguments that control the code output:
|
|||||||
adjust for this text. Can be used to insert a comment containing
|
adjust for this text. Can be used to insert a comment containing
|
||||||
licensing information, for example.
|
licensing information, for example.
|
||||||
|
|
||||||
- `preserve_line` (default `false`) -- pass `true` to preserve lines, but it
|
- `preserve_line` (default `false`) -- pass `true` to retain line numbering on
|
||||||
only works if `beautify` is set to `false`.
|
a best effort basis.
|
||||||
|
|
||||||
- `quote_keys` (default `false`) -- pass `true` to quote all keys in literal
|
- `quote_keys` (default `false`) -- pass `true` to quote all keys in literal
|
||||||
objects
|
objects
|
||||||
|
|||||||
17
appveyor.yml
17
appveyor.yml
@@ -1,20 +1,5 @@
|
|||||||
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
|
build: off
|
||||||
cache:
|
|
||||||
- tmp
|
|
||||||
matrix:
|
matrix:
|
||||||
fast_finish: true
|
fast_finish: true
|
||||||
test_script:
|
test_script:
|
||||||
- node --version
|
- echo No longer in use
|
||||||
- npm --version
|
|
||||||
- npm test
|
|
||||||
|
|||||||
99
bin/uglifyjs
99
bin/uglifyjs
@@ -36,6 +36,7 @@ program.option("-c, --compress [options]", "Enable compressor/specify compressor
|
|||||||
program.option("-m, --mangle [options]", "Mangle names/specify mangler options.", parse_js());
|
program.option("-m, --mangle [options]", "Mangle names/specify mangler options.", parse_js());
|
||||||
program.option("--mangle-props [options]", "Mangle properties/specify mangler options.", parse_js());
|
program.option("--mangle-props [options]", "Mangle properties/specify mangler options.", parse_js());
|
||||||
program.option("-b, --beautify [options]", "Beautify output/specify output options.", parse_js());
|
program.option("-b, --beautify [options]", "Beautify output/specify output options.", parse_js());
|
||||||
|
program.option("-O, --output-opts [options]", "Output options (beautify disabled).", parse_js());
|
||||||
program.option("-o, --output <file>", "Output file (default STDOUT).");
|
program.option("-o, --output <file>", "Output file (default STDOUT).");
|
||||||
program.option("--comments [filter]", "Preserve copyright comments in the output.");
|
program.option("--comments [filter]", "Preserve copyright comments in the output.");
|
||||||
program.option("--config-file <file>", "Read minify() options from JSON file.");
|
program.option("--config-file <file>", "Read minify() options from JSON file.");
|
||||||
@@ -56,9 +57,14 @@ program.option("--wrap <name>", "Embed everything as a function with “exports
|
|||||||
program.arguments("[files...]").parseArgv(process.argv);
|
program.arguments("[files...]").parseArgv(process.argv);
|
||||||
if (program.configFile) {
|
if (program.configFile) {
|
||||||
options = JSON.parse(read_file(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
|
||||||
|
}).value;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (!program.output && program.sourceMap && program.sourceMap.url != "inline") {
|
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",
|
"compress",
|
||||||
@@ -73,12 +79,25 @@ if (!program.output && program.sourceMap && program.sourceMap.url != "inline") {
|
|||||||
options[name] = program[name];
|
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) {
|
if (program.beautify) {
|
||||||
options.output = typeof program.beautify == "object" ? program.beautify : {};
|
options.output = typeof program.beautify == "object" ? program.beautify : {};
|
||||||
if (!("beautify" in options.output)) {
|
if (!("beautify" in options.output)) {
|
||||||
options.output.beautify = true;
|
options.output.beautify = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (program.outputOpts) {
|
||||||
|
if (program.beautify) fatal("--beautify cannot be used with --output-opts");
|
||||||
|
options.output = typeof program.outputOpts == "object" ? program.outputOpts : {};
|
||||||
|
}
|
||||||
if (program.comments) {
|
if (program.comments) {
|
||||||
if (typeof options.output != "object") options.output = {};
|
if (typeof options.output != "object") options.output = {};
|
||||||
options.output.comments = typeof program.comments == "string" ? program.comments : "some";
|
options.output.comments = typeof program.comments == "string" ? program.comments : "some";
|
||||||
@@ -100,7 +119,7 @@ if (program.mangleProps) {
|
|||||||
if (typeof program.mangleProps != "object") program.mangleProps = {};
|
if (typeof program.mangleProps != "object") program.mangleProps = {};
|
||||||
if (!Array.isArray(program.mangleProps.reserved)) program.mangleProps.reserved = [];
|
if (!Array.isArray(program.mangleProps.reserved)) program.mangleProps.reserved = [];
|
||||||
require("../tools/domprops").forEach(function(name) {
|
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 = {};
|
if (typeof options.mangle != "object") options.mangle = {};
|
||||||
@@ -119,7 +138,7 @@ if (program.parse) {
|
|||||||
if (!program.parse.acorn && !program.parse.spidermonkey) {
|
if (!program.parse.acorn && !program.parse.spidermonkey) {
|
||||||
options.parse = program.parse;
|
options.parse = program.parse;
|
||||||
} else if (program.sourceMap && program.sourceMap.content == "inline") {
|
} 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")) {
|
if (~program.rawArgs.indexOf("--rename")) {
|
||||||
@@ -139,15 +158,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.self) {
|
||||||
if (program.args.length) {
|
if (program.args.length) UglifyJS.AST_Node.warn("Ignoring input files since --self was passed");
|
||||||
print_error("WARN: Ignoring input files since --self was passed");
|
|
||||||
}
|
|
||||||
if (!options.wrap) options.wrap = "UglifyJS";
|
if (!options.wrap) options.wrap = "UglifyJS";
|
||||||
simple_glob(UglifyJS.FILES).forEach(function(name) {
|
simple_glob(UglifyJS.FILES).forEach(function(name) {
|
||||||
files[convert_path(name)] = read_file(name);
|
files[convert_path(name)] = read_file(name);
|
||||||
@@ -175,12 +187,9 @@ function convert_ast(fn) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function run() {
|
function run() {
|
||||||
UglifyJS.AST_Node.warn_function = function(msg) {
|
|
||||||
print_error("WARN: " + msg);
|
|
||||||
};
|
|
||||||
var content = program.sourceMap && program.sourceMap.content;
|
var content = program.sourceMap && program.sourceMap.content;
|
||||||
if (content && content != "inline") {
|
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);
|
options.sourceMap.content = read_file(content, content);
|
||||||
}
|
}
|
||||||
if (program.timings) options.timings = true;
|
if (program.timings) options.timings = true;
|
||||||
@@ -211,24 +220,26 @@ function run() {
|
|||||||
var ex = result.error;
|
var ex = result.error;
|
||||||
if (ex.name == "SyntaxError") {
|
if (ex.name == "SyntaxError") {
|
||||||
print_error("Parse error at " + ex.filename + ":" + ex.line + "," + ex.col);
|
print_error("Parse error at " + ex.filename + ":" + ex.line + "," + ex.col);
|
||||||
var col = ex.col;
|
var file = files[ex.filename];
|
||||||
var lines = files[ex.filename].split(/\r?\n/);
|
if (file) {
|
||||||
var line = lines[ex.line - 1];
|
var col = ex.col;
|
||||||
if (!line && !col) {
|
var lines = file.split(/\r?\n/);
|
||||||
line = lines[ex.line - 2];
|
var line = lines[ex.line - 1];
|
||||||
col = line.length;
|
if (!line && !col) {
|
||||||
}
|
line = lines[ex.line - 2];
|
||||||
if (line) {
|
col = line.length;
|
||||||
var limit = 70;
|
}
|
||||||
if (col > limit) {
|
if (line) {
|
||||||
line = line.slice(col - limit);
|
var limit = 70;
|
||||||
col = limit;
|
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, " ") + "^");
|
|
||||||
}
|
}
|
||||||
}
|
} else if (ex.defs) {
|
||||||
if (ex.defs) {
|
|
||||||
print_error("Supported options:");
|
print_error("Supported options:");
|
||||||
print_error(format_object(ex.defs));
|
print_error(format_object(ex.defs));
|
||||||
}
|
}
|
||||||
@@ -288,7 +299,11 @@ function run() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function fatal(message) {
|
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);
|
print_error(message);
|
||||||
process.exit(1);
|
process.exit(1);
|
||||||
}
|
}
|
||||||
@@ -337,17 +352,9 @@ function parse_js(flag) {
|
|||||||
return function(value, options) {
|
return function(value, options) {
|
||||||
options = options || {};
|
options = options || {};
|
||||||
try {
|
try {
|
||||||
UglifyJS.minify(value, {
|
UglifyJS.parse(value, {
|
||||||
parse: {
|
expression: true
|
||||||
expression: true
|
}).walk(new UglifyJS.TreeWalker(function(node) {
|
||||||
},
|
|
||||||
compress: false,
|
|
||||||
mangle: false,
|
|
||||||
output: {
|
|
||||||
ast: true,
|
|
||||||
code: false
|
|
||||||
}
|
|
||||||
}).ast.walk(new UglifyJS.TreeWalker(function(node) {
|
|
||||||
if (node instanceof UglifyJS.AST_Assign) {
|
if (node instanceof UglifyJS.AST_Assign) {
|
||||||
var name = node.left.print_to_string();
|
var name = node.left.print_to_string();
|
||||||
var value = node.right;
|
var value = node.right;
|
||||||
@@ -368,14 +375,14 @@ function parse_js(flag) {
|
|||||||
if (!(node instanceof UglifyJS.AST_Sequence)) throw node;
|
if (!(node instanceof UglifyJS.AST_Sequence)) throw node;
|
||||||
|
|
||||||
function to_string(value) {
|
function to_string(value) {
|
||||||
return value instanceof UglifyJS.AST_Constant ? value.getValue() : value.print_to_string({
|
return value instanceof UglifyJS.AST_Constant ? value.value : value.print_to_string({
|
||||||
quote_keys: true
|
quote_keys: true
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}));
|
}));
|
||||||
} catch(ex) {
|
} catch (ex) {
|
||||||
if (flag) {
|
if (flag) {
|
||||||
fatal("Error parsing arguments for '" + flag + "': " + value);
|
fatal("cannot parse arguments for '" + flag + "': " + value);
|
||||||
} else {
|
} else {
|
||||||
options[value] = null;
|
options[value] = null;
|
||||||
}
|
}
|
||||||
|
|||||||
87
lib/ast.js
87
lib/ast.js
@@ -118,11 +118,25 @@ var AST_Node = DEFNODE("Node", "start end", {
|
|||||||
}
|
}
|
||||||
}, null);
|
}, null);
|
||||||
|
|
||||||
AST_Node.warn_function = null;
|
(AST_Node.log_function = function(fn, verbose) {
|
||||||
AST_Node.warn = function(txt, props) {
|
var printed = Object.create(null);
|
||||||
if (AST_Node.warn_function)
|
if (fn) {
|
||||||
AST_Node.warn_function(string_template(txt, props));
|
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 ]----- */
|
/* -----[ statements ]----- */
|
||||||
|
|
||||||
@@ -207,8 +221,7 @@ var AST_LabeledStatement = DEFNODE("LabeledStatement", "label", {
|
|||||||
var label = node.label;
|
var label = node.label;
|
||||||
var def = this.label;
|
var def = this.label;
|
||||||
node.walk(new TreeWalker(function(node) {
|
node.walk(new TreeWalker(function(node) {
|
||||||
if (node instanceof AST_LoopControl
|
if (node instanceof AST_LoopControl && node.label && node.label.thedef === def) {
|
||||||
&& node.label && node.label.thedef === def) {
|
|
||||||
node.label.thedef = label;
|
node.label.thedef = label;
|
||||||
label.references.push(node);
|
label.references.push(node);
|
||||||
}
|
}
|
||||||
@@ -324,18 +337,25 @@ var AST_Toplevel = DEFNODE("Toplevel", "globals", {
|
|||||||
$propdoc: {
|
$propdoc: {
|
||||||
globals: "[Object/S] a map of name -> SymbolDef for all undeclared names",
|
globals: "[Object/S] a map of name -> SymbolDef for all undeclared names",
|
||||||
},
|
},
|
||||||
wrap_commonjs: function(name) {
|
wrap: function(name) {
|
||||||
var body = this.body;
|
var body = this.body;
|
||||||
var wrapped_tl = "(function(exports){'$ORIG';})(typeof " + name + "=='undefined'?(" + name + "={}):" + name + ");";
|
return parse([
|
||||||
wrapped_tl = parse(wrapped_tl);
|
"(function(exports){'$ORIG';})(typeof ",
|
||||||
wrapped_tl = wrapped_tl.transform(new TreeTransformer(function before(node) {
|
name,
|
||||||
|
"=='undefined'?(",
|
||||||
|
name,
|
||||||
|
"={}):",
|
||||||
|
name,
|
||||||
|
");"
|
||||||
|
].join(""), {
|
||||||
|
filename: "wrap=" + JSON.stringify(name)
|
||||||
|
}).transform(new TreeTransformer(function(node) {
|
||||||
if (node instanceof AST_Directive && node.value == "$ORIG") {
|
if (node instanceof AST_Directive && node.value == "$ORIG") {
|
||||||
return MAP.splice(body);
|
return MAP.splice(body);
|
||||||
}
|
}
|
||||||
}));
|
}));
|
||||||
return wrapped_tl;
|
|
||||||
},
|
},
|
||||||
wrap_enclose: function(args_values) {
|
enclose: function(args_values) {
|
||||||
if (typeof args_values != "string") args_values = "";
|
if (typeof args_values != "string") args_values = "";
|
||||||
var index = args_values.indexOf(":");
|
var index = args_values.indexOf(":");
|
||||||
if (index < 0) index = args_values.length;
|
if (index < 0) index = args_values.length;
|
||||||
@@ -346,7 +366,9 @@ var AST_Toplevel = DEFNODE("Toplevel", "globals", {
|
|||||||
'){"$ORIG"})(',
|
'){"$ORIG"})(',
|
||||||
args_values.slice(index + 1),
|
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") {
|
if (node instanceof AST_Directive && node.value == "$ORIG") {
|
||||||
return MAP.splice(body);
|
return MAP.splice(body);
|
||||||
}
|
}
|
||||||
@@ -354,7 +376,7 @@ var AST_Toplevel = DEFNODE("Toplevel", "globals", {
|
|||||||
}
|
}
|
||||||
}, AST_Scope);
|
}, 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",
|
$documentation: "Base class for functions",
|
||||||
$propdoc: {
|
$propdoc: {
|
||||||
name: "[AST_SymbolDeclaration?] the name of this function",
|
name: "[AST_SymbolDeclaration?] the name of this function",
|
||||||
@@ -592,6 +614,18 @@ var AST_PropAccess = DEFNODE("PropAccess", "expression property", {
|
|||||||
$propdoc: {
|
$propdoc: {
|
||||||
expression: "[AST_Node] the “container” expression",
|
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"
|
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.value;
|
||||||
|
}
|
||||||
|
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);
|
}, AST_Symbol);
|
||||||
|
|
||||||
var AST_SymbolRef = DEFNODE("SymbolRef", null, {
|
var AST_SymbolRef = DEFNODE("SymbolRef", "fixed", {
|
||||||
$documentation: "Reference to some symbol (not definition/declaration)",
|
$documentation: "Reference to some symbol (not definition/declaration)",
|
||||||
}, AST_Symbol);
|
}, AST_Symbol);
|
||||||
|
|
||||||
@@ -790,9 +824,6 @@ var AST_This = DEFNODE("This", null, {
|
|||||||
|
|
||||||
var AST_Constant = DEFNODE("Constant", null, {
|
var AST_Constant = DEFNODE("Constant", null, {
|
||||||
$documentation: "Base class for all constants",
|
$documentation: "Base class for all constants",
|
||||||
getValue: function() {
|
|
||||||
return this.value;
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
var AST_String = DEFNODE("String", "value quote", {
|
var AST_String = DEFNODE("String", "value quote", {
|
||||||
@@ -803,11 +834,10 @@ var AST_String = DEFNODE("String", "value quote", {
|
|||||||
}
|
}
|
||||||
}, AST_Constant);
|
}, AST_Constant);
|
||||||
|
|
||||||
var AST_Number = DEFNODE("Number", "value literal", {
|
var AST_Number = DEFNODE("Number", "value", {
|
||||||
$documentation: "A number literal",
|
$documentation: "A number literal",
|
||||||
$propdoc: {
|
$propdoc: {
|
||||||
value: "[number] the numeric value",
|
value: "[number] the numeric value",
|
||||||
literal: "[string] numeric value as string (optional)"
|
|
||||||
}
|
}
|
||||||
}, AST_Constant);
|
}, AST_Constant);
|
||||||
|
|
||||||
@@ -934,11 +964,13 @@ TreeWalker.prototype = {
|
|||||||
in_boolean_context: function() {
|
in_boolean_context: function() {
|
||||||
var self = this.self();
|
var self = this.self();
|
||||||
for (var i = 0, p; p = this.parent(i); i++) {
|
for (var i = 0, p; p = this.parent(i); i++) {
|
||||||
if (p instanceof AST_SimpleStatement
|
if (p instanceof AST_Conditional && p.condition === self
|
||||||
|| p instanceof AST_Conditional && p.condition === self
|
|
||||||
|| p instanceof AST_DWLoop && p.condition === self
|
|| p instanceof AST_DWLoop && p.condition === self
|
||||||
|| p instanceof AST_For && p.condition === self
|
|| p instanceof AST_For && p.condition === self
|
||||||
|| p instanceof AST_If && p.condition === self
|
|| p instanceof AST_If && p.condition === self
|
||||||
|
|| p instanceof AST_Return && p.in_bool
|
||||||
|
|| p instanceof AST_Sequence && p.tail_node() !== self
|
||||||
|
|| p instanceof AST_SimpleStatement
|
||||||
|| p instanceof AST_UnaryPrefix && p.operator == "!" && p.expression === self) {
|
|| p instanceof AST_UnaryPrefix && p.operator == "!" && p.expression === self) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -946,6 +978,15 @@ TreeWalker.prototype = {
|
|||||||
|| p instanceof AST_Conditional
|
|| p instanceof AST_Conditional
|
||||||
|| p.tail_node() === self) {
|
|| p.tail_node() === self) {
|
||||||
self = p;
|
self = p;
|
||||||
|
} else if (p instanceof AST_Return) {
|
||||||
|
var fn;
|
||||||
|
do {
|
||||||
|
fn = this.parent(++i);
|
||||||
|
if (!fn) return false;
|
||||||
|
} while (!(fn instanceof AST_Lambda));
|
||||||
|
if (fn.name) return false;
|
||||||
|
self = this.parent(++i);
|
||||||
|
if (!self || self.TYPE != "Call" || self.expression !== fn) return false;
|
||||||
} else {
|
} else {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|||||||
3911
lib/compress.js
3911
lib/compress.js
File diff suppressed because it is too large
Load Diff
@@ -1,19 +1,39 @@
|
|||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
var to_ascii = typeof atob == "undefined" ? function(b64) {
|
var to_ascii, to_base64;
|
||||||
return new Buffer(b64, "base64").toString();
|
if (typeof Buffer == "undefined") {
|
||||||
} : atob;
|
to_ascii = atob;
|
||||||
var to_base64 = typeof btoa == "undefined" ? function(str) {
|
to_base64 = btoa;
|
||||||
return new Buffer(str).toString("base64");
|
} else if (typeof Buffer.alloc == "undefined") {
|
||||||
} : btoa;
|
to_ascii = function(b64) {
|
||||||
|
return new Buffer(b64, "base64").toString();
|
||||||
|
};
|
||||||
|
to_base64 = function(str) {
|
||||||
|
return new Buffer(str).toString("base64");
|
||||||
|
};
|
||||||
|
} else {
|
||||||
|
to_ascii = function(b64) {
|
||||||
|
return Buffer.from(b64, "base64").toString();
|
||||||
|
};
|
||||||
|
to_base64 = function(str) {
|
||||||
|
return Buffer.from(str).toString("base64");
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
function read_source_map(name, code) {
|
function read_source_map(name, toplevel) {
|
||||||
var match = /\n\/\/# sourceMappingURL=data:application\/json(;.*?)?;base64,(.*)/.exec(code);
|
var comments = toplevel.end.comments_after;
|
||||||
if (!match) {
|
for (var i = comments.length; --i >= 0;) {
|
||||||
AST_Node.warn("inline source map not found: " + name);
|
var comment = comments[i];
|
||||||
return null;
|
if (comment.type != "comment1") break;
|
||||||
|
var match = /^# ([^\s=]+)=(\S+)\s*$/.exec(comment.value);
|
||||||
|
if (!match) break;
|
||||||
|
if (match[1] == "sourceMappingURL") {
|
||||||
|
match = /^data:application\/json(;.*?)?;base64,(\S+)$/.exec(match[2]);
|
||||||
|
if (!match) break;
|
||||||
|
return to_ascii(match[2]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return to_ascii(match[2]);
|
AST_Node.warn("inline source map not found: " + name);
|
||||||
}
|
}
|
||||||
|
|
||||||
function parse_source_map(content) {
|
function parse_source_map(content) {
|
||||||
@@ -51,7 +71,6 @@ function to_json(cache) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function minify(files, options) {
|
function minify(files, options) {
|
||||||
var warn_function = AST_Node.warn_function;
|
|
||||||
try {
|
try {
|
||||||
options = defaults(options, {
|
options = defaults(options, {
|
||||||
compress: {},
|
compress: {},
|
||||||
@@ -78,7 +97,6 @@ function minify(files, options) {
|
|||||||
set_shorthand("ie8", options, [ "compress", "mangle", "output" ]);
|
set_shorthand("ie8", options, [ "compress", "mangle", "output" ]);
|
||||||
set_shorthand("keep_fnames", options, [ "compress", "mangle" ]);
|
set_shorthand("keep_fnames", options, [ "compress", "mangle" ]);
|
||||||
set_shorthand("toplevel", options, [ "compress", "mangle" ]);
|
set_shorthand("toplevel", options, [ "compress", "mangle" ]);
|
||||||
set_shorthand("warnings", options, [ "compress" ]);
|
|
||||||
var quoted_props;
|
var quoted_props;
|
||||||
if (options.mangle) {
|
if (options.mangle) {
|
||||||
options.mangle = defaults(options.mangle, {
|
options.mangle = defaults(options.mangle, {
|
||||||
@@ -116,11 +134,9 @@ function minify(files, options) {
|
|||||||
}, true);
|
}, true);
|
||||||
}
|
}
|
||||||
var warnings = [];
|
var warnings = [];
|
||||||
if (options.warnings && !AST_Node.warn_function) {
|
if (options.warnings) AST_Node.log_function(function(warning) {
|
||||||
AST_Node.warn_function = function(warning) {
|
warnings.push(warning);
|
||||||
warnings.push(warning);
|
}, options.warnings == "verbose");
|
||||||
};
|
|
||||||
}
|
|
||||||
if (timings) timings.parse = Date.now();
|
if (timings) timings.parse = Date.now();
|
||||||
var source_maps, toplevel;
|
var source_maps, toplevel;
|
||||||
if (files instanceof AST_Toplevel) {
|
if (files instanceof AST_Toplevel) {
|
||||||
@@ -138,10 +154,10 @@ function minify(files, options) {
|
|||||||
source_maps = source_map_content && Object.create(null);
|
source_maps = source_map_content && Object.create(null);
|
||||||
for (var name in files) if (HOP(files, name)) {
|
for (var name in files) if (HOP(files, name)) {
|
||||||
options.parse.filename = name;
|
options.parse.filename = name;
|
||||||
options.parse.toplevel = parse(files[name], options.parse);
|
options.parse.toplevel = toplevel = parse(files[name], options.parse);
|
||||||
if (source_maps) {
|
if (source_maps) {
|
||||||
if (source_map_content == "inline") {
|
if (source_map_content == "inline") {
|
||||||
var inlined_content = read_source_map(name, files[name]);
|
var inlined_content = read_source_map(name, toplevel);
|
||||||
if (inlined_content) {
|
if (inlined_content) {
|
||||||
source_maps[name] = parse_source_map(inlined_content);
|
source_maps[name] = parse_source_map(inlined_content);
|
||||||
}
|
}
|
||||||
@@ -150,17 +166,17 @@ function minify(files, options) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
toplevel = options.parse.toplevel;
|
|
||||||
}
|
}
|
||||||
if (quoted_props) {
|
if (quoted_props) {
|
||||||
reserve_quoted_keys(toplevel, quoted_props);
|
reserve_quoted_keys(toplevel, quoted_props);
|
||||||
}
|
}
|
||||||
if (options.wrap) {
|
[ "enclose", "wrap" ].forEach(function(action) {
|
||||||
toplevel = toplevel.wrap_commonjs(options.wrap);
|
var option = options[action];
|
||||||
}
|
if (!option) return;
|
||||||
if (options.enclose) {
|
var orig = toplevel.print_to_string().slice(0, -1);
|
||||||
toplevel = toplevel.wrap_enclose(options.enclose);
|
toplevel = toplevel[action](option);
|
||||||
}
|
files[toplevel.start.file] = toplevel.print_to_string().replace(orig, "");
|
||||||
|
});
|
||||||
if (timings) timings.rename = Date.now();
|
if (timings) timings.rename = Date.now();
|
||||||
if (options.rename) {
|
if (options.rename) {
|
||||||
toplevel.figure_out_scope(options.mangle);
|
toplevel.figure_out_scope(options.mangle);
|
||||||
@@ -208,10 +224,14 @@ function minify(files, options) {
|
|||||||
result.code = stream.get();
|
result.code = stream.get();
|
||||||
if (options.sourceMap) {
|
if (options.sourceMap) {
|
||||||
result.map = options.output.source_map.toString();
|
result.map = options.output.source_map.toString();
|
||||||
if (options.sourceMap.url == "inline") {
|
var url = options.sourceMap.url;
|
||||||
result.code += "\n//# sourceMappingURL=data:application/json;charset=utf-8;base64," + to_base64(result.map);
|
if (url) {
|
||||||
} else if (options.sourceMap.url) {
|
result.code = result.code.replace(/\n\/\/# sourceMappingURL=\S+\s*$/, "");
|
||||||
result.code += "\n//# sourceMappingURL=" + options.sourceMap.url;
|
if (url == "inline") {
|
||||||
|
result.code += "\n//# sourceMappingURL=data:application/json;charset=utf-8;base64," + to_base64(result.map);
|
||||||
|
} else {
|
||||||
|
result.code += "\n//# sourceMappingURL=" + url;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -232,7 +252,7 @@ function minify(files, options) {
|
|||||||
properties: 1e-3 * (timings.output - timings.properties),
|
properties: 1e-3 * (timings.output - timings.properties),
|
||||||
output: 1e-3 * (timings.end - timings.output),
|
output: 1e-3 * (timings.end - timings.output),
|
||||||
total: 1e-3 * (timings.end - timings.start)
|
total: 1e-3 * (timings.end - timings.start)
|
||||||
}
|
};
|
||||||
}
|
}
|
||||||
if (warnings.length) {
|
if (warnings.length) {
|
||||||
result.warnings = warnings;
|
result.warnings = warnings;
|
||||||
@@ -240,7 +260,5 @@ function minify(files, options) {
|
|||||||
return result;
|
return result;
|
||||||
} catch (ex) {
|
} catch (ex) {
|
||||||
return { error: ex };
|
return { error: ex };
|
||||||
} finally {
|
|
||||||
AST_Node.warn_function = warn_function;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -403,7 +403,7 @@
|
|||||||
var def = M.definition();
|
var def = M.definition();
|
||||||
return {
|
return {
|
||||||
type: "Identifier",
|
type: "Identifier",
|
||||||
name: def ? def.mangled_name || def.name : M.name
|
name: def && def.mangled_name || M.name
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
405
lib/output.js
405
lib/output.js
@@ -43,8 +43,6 @@
|
|||||||
|
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
var EXPECT_DIRECTIVE = /^$|[;{][\s\n]*$/;
|
|
||||||
|
|
||||||
function is_some_comments(comment) {
|
function is_some_comments(comment) {
|
||||||
// multiline comment
|
// multiline comment
|
||||||
return comment.type == "comment2" && /@preserve|@license|@cc_on/i.test(comment.value);
|
return comment.type == "comment2" && /@preserve|@license|@cc_on/i.test(comment.value);
|
||||||
@@ -91,13 +89,11 @@ function OutputStream(options) {
|
|||||||
comment_filter = function(comment) {
|
comment_filter = function(comment) {
|
||||||
return comment.type != "comment5" && comments.test(comment.value);
|
return comment.type != "comment5" && comments.test(comment.value);
|
||||||
};
|
};
|
||||||
}
|
} else if (typeof comments === "function") {
|
||||||
else if (typeof comments === "function") {
|
|
||||||
comment_filter = function(comment) {
|
comment_filter = function(comment) {
|
||||||
return comment.type != "comment5" && comments(this, comment);
|
return comment.type != "comment5" && comments(this, comment);
|
||||||
};
|
};
|
||||||
}
|
} else if (comments === "some") {
|
||||||
else if (comments === "some") {
|
|
||||||
comment_filter = is_some_comments;
|
comment_filter = is_some_comments;
|
||||||
} else { // NOTE includes "all" option
|
} else { // NOTE includes "all" option
|
||||||
comment_filter = return_true;
|
comment_filter = return_true;
|
||||||
@@ -123,21 +119,25 @@ function OutputStream(options) {
|
|||||||
});
|
});
|
||||||
} : function(str) {
|
} : function(str) {
|
||||||
var s = "";
|
var s = "";
|
||||||
for (var i = 0, len = str.length; i < len; i++) {
|
for (var i = 0, j = 0; i < str.length; i++) {
|
||||||
if (is_surrogate_pair_head(str[i]) && !is_surrogate_pair_tail(str[i + 1])
|
var code = str.charCodeAt(i);
|
||||||
|| is_surrogate_pair_tail(str[i]) && !is_surrogate_pair_head(str[i - 1])) {
|
if (is_surrogate_pair_head(code)) {
|
||||||
s += "\\u" + str.charCodeAt(i).toString(16);
|
if (is_surrogate_pair_tail(str.charCodeAt(i + 1))) {
|
||||||
} else {
|
i++;
|
||||||
s += str[i];
|
continue;
|
||||||
|
}
|
||||||
|
} else if (!is_surrogate_pair_tail(code)) {
|
||||||
|
continue;
|
||||||
}
|
}
|
||||||
|
s += str.slice(j, i) + "\\u" + code.toString(16);
|
||||||
|
j = i + 1;
|
||||||
}
|
}
|
||||||
return s;
|
return j == 0 ? str : s + str.slice(j);
|
||||||
};
|
};
|
||||||
|
|
||||||
function make_string(str, quote) {
|
function make_string(str, quote) {
|
||||||
var dq = 0, sq = 0;
|
var dq = 0, sq = 0;
|
||||||
str = str.replace(/[\\\b\f\n\r\v\t\x22\x27\u2028\u2029\0\ufeff]/g,
|
str = str.replace(/[\\\b\f\n\r\v\t\x22\x27\u2028\u2029\0\ufeff]/g, function(s, i) {
|
||||||
function(s, i) {
|
|
||||||
switch (s) {
|
switch (s) {
|
||||||
case '"': ++dq; return '"';
|
case '"': ++dq; return '"';
|
||||||
case "'": ++sq; return "'";
|
case "'": ++sq; return "'";
|
||||||
@@ -198,63 +198,59 @@ function OutputStream(options) {
|
|||||||
/* -----[ beautification/minification ]----- */
|
/* -----[ beautification/minification ]----- */
|
||||||
|
|
||||||
var has_parens = false;
|
var has_parens = false;
|
||||||
|
var line_end = 0;
|
||||||
|
var line_fixed = true;
|
||||||
var might_need_space = false;
|
var might_need_space = false;
|
||||||
var might_need_semicolon = false;
|
var might_need_semicolon = false;
|
||||||
var might_add_newline = 0;
|
|
||||||
var need_newline_indented = false;
|
var need_newline_indented = false;
|
||||||
var need_space = false;
|
var need_space = false;
|
||||||
var newline_insert = -1;
|
var newline_insert = -1;
|
||||||
var last = "";
|
var last = "";
|
||||||
var mapping_token, mapping_name, mappings = options.source_map && [];
|
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) {
|
mappings.forEach(function(mapping) {
|
||||||
try {
|
mapping.line += line;
|
||||||
options.source_map.add(
|
mapping.col += col;
|
||||||
mapping.token.file,
|
});
|
||||||
mapping.line, mapping.col,
|
} : noop;
|
||||||
mapping.token.line, mapping.token.col,
|
|
||||||
!mapping.name && mapping.token.type == "name" ? mapping.token.value : mapping.name
|
var flush_mappings = mappings ? function() {
|
||||||
);
|
mappings.forEach(function(mapping) {
|
||||||
} catch(ex) {
|
options.source_map.add(
|
||||||
AST_Node.warn("Couldn't figure out mapping for {file}:{line},{col} → {cline},{ccol} [{name}]", {
|
mapping.token.file,
|
||||||
file: mapping.token.file,
|
mapping.line, mapping.col,
|
||||||
line: mapping.token.line,
|
mapping.token.line, mapping.token.col,
|
||||||
col: mapping.token.col,
|
!mapping.name && mapping.token.type == "name" ? mapping.token.value : mapping.name
|
||||||
cline: mapping.line,
|
);
|
||||||
ccol: mapping.col,
|
|
||||||
name: mapping.name || ""
|
|
||||||
})
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
mappings = [];
|
mappings = [];
|
||||||
} : noop;
|
} : noop;
|
||||||
|
|
||||||
var ensure_line_len = options.max_line_len ? function() {
|
function insert_newlines(count) {
|
||||||
if (current_col > options.max_line_len) {
|
var index = OUTPUT.lastIndexOf("\n");
|
||||||
if (might_add_newline) {
|
if (line_end < index) line_end = index;
|
||||||
var left = OUTPUT.slice(0, might_add_newline);
|
var left = OUTPUT.slice(0, line_end);
|
||||||
var right = OUTPUT.slice(might_add_newline);
|
var right = OUTPUT.slice(line_end);
|
||||||
if (mappings) {
|
adjust_mappings(count, right.length - current_col);
|
||||||
var delta = right.length - current_col;
|
current_line += count;
|
||||||
mappings.forEach(function(mapping) {
|
current_pos += count;
|
||||||
mapping.line++;
|
current_col = right.length;
|
||||||
mapping.col += delta;
|
OUTPUT = left;
|
||||||
});
|
while (count--) OUTPUT += "\n";
|
||||||
}
|
OUTPUT += right;
|
||||||
OUTPUT = left + "\n" + right;
|
}
|
||||||
current_line++;
|
|
||||||
current_pos++;
|
var fix_line = options.max_line_len ? function() {
|
||||||
current_col = right.length;
|
if (line_fixed) {
|
||||||
}
|
|
||||||
if (current_col > options.max_line_len) {
|
if (current_col > options.max_line_len) {
|
||||||
AST_Node.warn("Output exceeds {max_line_len} characters", options);
|
AST_Node.warn("Output exceeds {max_line_len} characters", options);
|
||||||
}
|
}
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
if (might_add_newline) {
|
if (current_col > options.max_line_len) insert_newlines(1);
|
||||||
might_add_newline = 0;
|
line_fixed = true;
|
||||||
do_add_mapping();
|
flush_mappings();
|
||||||
}
|
|
||||||
} : noop;
|
} : noop;
|
||||||
|
|
||||||
var requireSemicolonChars = makePredicate("( [ + * / - , .");
|
var requireSemicolonChars = makePredicate("( [ + * / - , .");
|
||||||
@@ -276,7 +272,7 @@ function OutputStream(options) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
newline_insert = -1;
|
newline_insert = -1;
|
||||||
var prev = last.charAt(last.length - 1);
|
var prev = last.slice(-1);
|
||||||
if (might_need_semicolon) {
|
if (might_need_semicolon) {
|
||||||
might_need_semicolon = false;
|
might_need_semicolon = false;
|
||||||
|
|
||||||
@@ -286,7 +282,7 @@ function OutputStream(options) {
|
|||||||
current_col++;
|
current_col++;
|
||||||
current_pos++;
|
current_pos++;
|
||||||
} else {
|
} else {
|
||||||
ensure_line_len();
|
fix_line();
|
||||||
OUTPUT += "\n";
|
OUTPUT += "\n";
|
||||||
current_pos++;
|
current_pos++;
|
||||||
current_line++;
|
current_line++;
|
||||||
@@ -304,29 +300,17 @@ 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 (might_need_space) {
|
||||||
if ((is_identifier_char(prev)
|
if (is_identifier_char(prev) && (is_identifier_char(ch) || ch == "\\")
|
||||||
&& (is_identifier_char(ch) || ch == "\\"))
|
|
||||||
|| (ch == "/" && ch == prev)
|
|| (ch == "/" && ch == prev)
|
||||||
|| ((ch == "+" || ch == "-") && ch == last))
|
|| ((ch == "+" || ch == "-") && ch == last)
|
||||||
{
|
|| str == "--" && last == "!"
|
||||||
|
|| last == "--" && ch == ">") {
|
||||||
OUTPUT += " ";
|
OUTPUT += " ";
|
||||||
current_col++;
|
current_col++;
|
||||||
current_pos++;
|
current_pos++;
|
||||||
}
|
}
|
||||||
might_need_space = false;
|
if (prev != "<" || str != "!") might_need_space = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mapping_token) {
|
if (mapping_token) {
|
||||||
@@ -337,17 +321,17 @@ function OutputStream(options) {
|
|||||||
col: current_col
|
col: current_col
|
||||||
});
|
});
|
||||||
mapping_token = false;
|
mapping_token = false;
|
||||||
if (!might_add_newline) do_add_mapping();
|
if (line_fixed) flush_mappings();
|
||||||
}
|
}
|
||||||
|
|
||||||
OUTPUT += str;
|
OUTPUT += str;
|
||||||
has_parens = str[str.length - 1] == "(";
|
has_parens = str.slice(-1) == "(";
|
||||||
current_pos += str.length;
|
current_pos += str.length;
|
||||||
var a = str.split(/\r?\n/), n = a.length - 1;
|
var a = str.split(/\r?\n/), n = a.length - 1;
|
||||||
current_line += n;
|
current_line += n;
|
||||||
current_col += a[0].length;
|
current_col += a[0].length;
|
||||||
if (n > 0) {
|
if (n > 0) {
|
||||||
ensure_line_len();
|
fix_line();
|
||||||
current_col = a[n].length;
|
current_col = a[n].length;
|
||||||
}
|
}
|
||||||
last = str;
|
last = str;
|
||||||
@@ -374,9 +358,10 @@ function OutputStream(options) {
|
|||||||
return ret;
|
return ret;
|
||||||
} : function(col, cont) { return cont() };
|
} : function(col, cont) { return cont() };
|
||||||
|
|
||||||
var may_add_newline = options.max_line_len ? function() {
|
var may_add_newline = options.max_line_len || options.preserve_line ? function() {
|
||||||
ensure_line_len();
|
fix_line();
|
||||||
might_add_newline = OUTPUT.length;
|
line_end = OUTPUT.length;
|
||||||
|
line_fixed = false;
|
||||||
} : noop;
|
} : noop;
|
||||||
|
|
||||||
var newline = options.beautify ? function() {
|
var newline = options.beautify ? function() {
|
||||||
@@ -396,7 +381,7 @@ function OutputStream(options) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
function force_semicolon() {
|
function force_semicolon() {
|
||||||
might_need_semicolon = false;
|
if (might_need_semicolon) print(";");
|
||||||
print(";");
|
print(";");
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -455,9 +440,7 @@ function OutputStream(options) {
|
|||||||
} : noop;
|
} : noop;
|
||||||
|
|
||||||
function get() {
|
function get() {
|
||||||
if (might_add_newline) {
|
if (!line_fixed) fix_line();
|
||||||
ensure_line_len();
|
|
||||||
}
|
|
||||||
return OUTPUT;
|
return OUTPUT;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -468,16 +451,11 @@ function OutputStream(options) {
|
|||||||
|
|
||||||
function prepend_comments(node) {
|
function prepend_comments(node) {
|
||||||
var self = this;
|
var self = this;
|
||||||
var start = node.start;
|
var scan = node instanceof AST_Exit && node.value;
|
||||||
if (!start) return;
|
var comments = dump(node);
|
||||||
if (start.comments_before && start.comments_before._dumped === self) return;
|
if (!comments) comments = [];
|
||||||
var comments = start.comments_before;
|
|
||||||
if (!comments) {
|
|
||||||
comments = start.comments_before = [];
|
|
||||||
}
|
|
||||||
comments._dumped = self;
|
|
||||||
|
|
||||||
if (node instanceof AST_Exit && node.value) {
|
if (scan) {
|
||||||
var tw = new TreeWalker(function(node) {
|
var tw = new TreeWalker(function(node) {
|
||||||
var parent = tw.parent();
|
var parent = tw.parent();
|
||||||
if (parent instanceof AST_Exit
|
if (parent instanceof AST_Exit
|
||||||
@@ -488,11 +466,8 @@ function OutputStream(options) {
|
|||||||
|| parent instanceof AST_Sequence && parent.expressions[0] === node
|
|| parent instanceof AST_Sequence && parent.expressions[0] === node
|
||||||
|| parent instanceof AST_Sub && parent.expression === node
|
|| parent instanceof AST_Sub && parent.expression === node
|
||||||
|| parent instanceof AST_UnaryPostfix) {
|
|| parent instanceof AST_UnaryPostfix) {
|
||||||
var text = node.start.comments_before;
|
var before = dump(node);
|
||||||
if (text && text._dumped !== self) {
|
if (before) comments = comments.concat(before);
|
||||||
text._dumped = self;
|
|
||||||
comments = comments.concat(text);
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -535,13 +510,29 @@ function OutputStream(options) {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
if (!last_nlb) {
|
if (!last_nlb) {
|
||||||
if (start.nlb) {
|
if (node.start.nlb) {
|
||||||
print("\n");
|
print("\n");
|
||||||
indent();
|
indent();
|
||||||
} else {
|
} else {
|
||||||
space();
|
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) {
|
function append_comments(node, tail) {
|
||||||
@@ -597,18 +588,7 @@ function OutputStream(options) {
|
|||||||
force_semicolon : force_semicolon,
|
force_semicolon : force_semicolon,
|
||||||
to_utf8 : to_utf8,
|
to_utf8 : to_utf8,
|
||||||
print_name : function(name) { print(make_name(name)) },
|
print_name : function(name) { print(make_name(name)) },
|
||||||
print_string : function(str, quote, escape_directive) {
|
print_string : function(str, quote) { print(encode_string(str, quote)) },
|
||||||
var encoded = encode_string(str, quote);
|
|
||||||
if (escape_directive === true && encoded.indexOf("\\") === -1) {
|
|
||||||
// Insert semicolons to break directive prologue
|
|
||||||
if (!EXPECT_DIRECTIVE.test(OUTPUT)) {
|
|
||||||
force_semicolon();
|
|
||||||
}
|
|
||||||
force_semicolon();
|
|
||||||
}
|
|
||||||
print(encoded);
|
|
||||||
},
|
|
||||||
encode_string : encode_string,
|
|
||||||
next_indent : next_indent,
|
next_indent : next_indent,
|
||||||
with_indent : with_indent,
|
with_indent : with_indent,
|
||||||
with_block : with_block,
|
with_block : with_block,
|
||||||
@@ -622,7 +602,14 @@ function OutputStream(options) {
|
|||||||
col : function() { return current_col },
|
col : function() { return current_col },
|
||||||
pos : function() { return current_pos },
|
pos : function() { return current_pos },
|
||||||
push_node : function(node) { stack.push(node) },
|
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) {
|
parent : function(n) {
|
||||||
return stack[stack.length - 2 - (n || 0)];
|
return stack[stack.length - 2 - (n || 0)];
|
||||||
}
|
}
|
||||||
@@ -639,18 +626,10 @@ function OutputStream(options) {
|
|||||||
nodetype.DEFMETHOD("_codegen", generator);
|
nodetype.DEFMETHOD("_codegen", generator);
|
||||||
}
|
}
|
||||||
|
|
||||||
var in_directive = false;
|
var use_asm = false;
|
||||||
var active_scope = null;
|
|
||||||
var use_asm = null;
|
|
||||||
|
|
||||||
AST_Node.DEFMETHOD("print", function(stream, force_parens) {
|
AST_Node.DEFMETHOD("print", function(stream, force_parens) {
|
||||||
var self = this, generator = self._codegen;
|
var self = this, generator = self._codegen;
|
||||||
if (self instanceof AST_Scope) {
|
|
||||||
active_scope = self;
|
|
||||||
}
|
|
||||||
else if (!use_asm && self instanceof AST_Directive && self.value == "use asm") {
|
|
||||||
use_asm = active_scope;
|
|
||||||
}
|
|
||||||
function doit() {
|
function doit() {
|
||||||
stream.prepend_comments(self);
|
stream.prepend_comments(self);
|
||||||
self.add_source_map(stream);
|
self.add_source_map(stream);
|
||||||
@@ -664,9 +643,6 @@ function OutputStream(options) {
|
|||||||
doit();
|
doit();
|
||||||
}
|
}
|
||||||
stream.pop_node();
|
stream.pop_node();
|
||||||
if (self === use_asm) {
|
|
||||||
use_asm = null;
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
AST_Node.DEFMETHOD("_print", AST_Node.prototype.print);
|
AST_Node.DEFMETHOD("_print", AST_Node.prototype.print);
|
||||||
|
|
||||||
@@ -693,23 +669,15 @@ function OutputStream(options) {
|
|||||||
// a function expression needs parens around it when it's provably
|
// a function expression needs parens around it when it's provably
|
||||||
// the first token to appear in a statement.
|
// the first token to appear in a statement.
|
||||||
PARENS(AST_Function, function(output) {
|
PARENS(AST_Function, function(output) {
|
||||||
if (!output.has_parens() && first_in_statement(output)) {
|
if (!output.has_parens() && first_in_statement(output)) return true;
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (output.option('webkit')) {
|
if (output.option('webkit')) {
|
||||||
var p = output.parent();
|
var p = output.parent();
|
||||||
if (p instanceof AST_PropAccess && p.expression === this) {
|
if (p instanceof AST_PropAccess && p.expression === this) return true;
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (output.option('wrap_iife')) {
|
if (output.option('wrap_iife')) {
|
||||||
var p = output.parent();
|
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
|
// same goes for an object literal, because otherwise it would be
|
||||||
@@ -726,16 +694,23 @@ function OutputStream(options) {
|
|||||||
|
|
||||||
PARENS(AST_Sequence, function(output) {
|
PARENS(AST_Sequence, function(output) {
|
||||||
var p = output.parent();
|
var p = output.parent();
|
||||||
return p instanceof AST_Call // (foo, bar)() or foo(1, (2, 3), 4)
|
// (foo, bar)() or foo(1, (2, 3), 4)
|
||||||
|| p instanceof AST_Unary // !(foo, bar, baz)
|
return p instanceof AST_Call
|
||||||
|| p instanceof AST_Binary // 1 + (2, 3) + 4 ==> 8
|
// !(foo, bar, baz)
|
||||||
|| p instanceof AST_VarDef // var a = (1, 2), b = a + a; ==> b == 4
|
|| p instanceof AST_Unary
|
||||||
|| p instanceof AST_PropAccess // (1, {foo:2}).foo or (1, {foo:2})["foo"] ==> 2
|
// 1 + (2, 3) + 4 ==> 8
|
||||||
|| p instanceof AST_Array // [ 1, (2, 3), 4 ] ==> [ 1, 3, 4 ]
|
|| p instanceof AST_Binary
|
||||||
|| p instanceof AST_ObjectProperty // { foo: (1, 2) }.foo ==> 2
|
// var a = (1, 2), b = a + a; ==> b == 4
|
||||||
|| p instanceof AST_Conditional /* (false, true) ? (a = 10, b = 20) : (c = 30)
|
|| p instanceof AST_VarDef
|
||||||
* ==> 20 (side effect, set a := 10 and b := 20) */
|
// (1, {foo:2}).foo or (1, {foo:2})["foo"] ==> 2
|
||||||
;
|
|| p instanceof AST_PropAccess && p.expression === this
|
||||||
|
// [ 1, (2, 3), 4 ] ==> [ 1, 3, 4 ]
|
||||||
|
|| p instanceof AST_Array
|
||||||
|
// { foo: (1, 2) }.foo ==> 2
|
||||||
|
|| p instanceof AST_ObjectProperty
|
||||||
|
// (false, true) ? (a = 10, b = 20) : (c = 30)
|
||||||
|
// ==> 20 (side effect, set a := 10 and b := 20)
|
||||||
|
|| p instanceof AST_Conditional;
|
||||||
});
|
});
|
||||||
|
|
||||||
PARENS(AST_Binary, function(output) {
|
PARENS(AST_Binary, function(output) {
|
||||||
@@ -783,17 +758,17 @@ function OutputStream(options) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
PARENS(AST_Call, function(output) {
|
PARENS(AST_Call, function(output) {
|
||||||
var p = output.parent(), p1;
|
var p = output.parent();
|
||||||
if (p instanceof AST_New && p.expression === this)
|
if (p instanceof AST_New && p.expression === this) return true;
|
||||||
return true;
|
|
||||||
|
|
||||||
// workaround for Safari bug.
|
|
||||||
// https://bugs.webkit.org/show_bug.cgi?id=123506
|
// https://bugs.webkit.org/show_bug.cgi?id=123506
|
||||||
return this.expression instanceof AST_Function
|
if (output.option('webkit')) {
|
||||||
&& p instanceof AST_PropAccess
|
var g = output.parent(1);
|
||||||
&& p.expression === this
|
return this.expression instanceof AST_Function
|
||||||
&& (p1 = output.parent(1)) instanceof AST_Assign
|
&& p instanceof AST_PropAccess
|
||||||
&& p1.left === p;
|
&& p.expression === this
|
||||||
|
&& g instanceof AST_Assign
|
||||||
|
&& g.left === p;
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
PARENS(AST_New, function(output) {
|
PARENS(AST_New, function(output) {
|
||||||
@@ -807,7 +782,7 @@ function OutputStream(options) {
|
|||||||
PARENS(AST_Number, function(output) {
|
PARENS(AST_Number, function(output) {
|
||||||
var p = output.parent();
|
var p = output.parent();
|
||||||
if (p instanceof AST_PropAccess && p.expression === this) {
|
if (p instanceof AST_PropAccess && p.expression === this) {
|
||||||
var value = this.getValue();
|
var value = this.value;
|
||||||
if (value < 0 || /^0/.test(make_num(value))) {
|
if (value < 0 || /^0/.test(make_num(value))) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -836,7 +811,18 @@ function OutputStream(options) {
|
|||||||
/* -----[ PRINTERS ]----- */
|
/* -----[ PRINTERS ]----- */
|
||||||
|
|
||||||
DEFPRINT(AST_Directive, function(self, output) {
|
DEFPRINT(AST_Directive, function(self, output) {
|
||||||
output.print_string(self.value, self.quote);
|
var quote = self.quote;
|
||||||
|
var value = self.value;
|
||||||
|
switch (output.option("quote_style")) {
|
||||||
|
case 0:
|
||||||
|
case 2:
|
||||||
|
if (value.indexOf('"') == -1) quote = '"';
|
||||||
|
break;
|
||||||
|
case 1:
|
||||||
|
if (value.indexOf("'") == -1) quote = "'";
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
output.print(quote + value + quote);
|
||||||
output.semicolon();
|
output.semicolon();
|
||||||
});
|
});
|
||||||
DEFPRINT(AST_Debugger, function(self, output) {
|
DEFPRINT(AST_Debugger, function(self, output) {
|
||||||
@@ -848,30 +834,27 @@ function OutputStream(options) {
|
|||||||
|
|
||||||
function display_body(body, is_toplevel, output, allow_directives) {
|
function display_body(body, is_toplevel, output, allow_directives) {
|
||||||
var last = body.length - 1;
|
var last = body.length - 1;
|
||||||
in_directive = allow_directives;
|
var in_directive = allow_directives;
|
||||||
|
var was_asm = use_asm;
|
||||||
body.forEach(function(stmt, i) {
|
body.forEach(function(stmt, i) {
|
||||||
if (in_directive === true && !(stmt instanceof AST_Directive ||
|
if (in_directive) {
|
||||||
stmt instanceof AST_EmptyStatement ||
|
if (stmt instanceof AST_Directive) {
|
||||||
(stmt instanceof AST_SimpleStatement && stmt.body instanceof AST_String)
|
if (stmt.value == "use asm") use_asm = true;
|
||||||
)) {
|
} else if (!(stmt instanceof AST_EmptyStatement)) {
|
||||||
in_directive = false;
|
if (stmt instanceof AST_SimpleStatement && stmt.body instanceof AST_String) {
|
||||||
}
|
output.force_semicolon();
|
||||||
if (!(stmt instanceof AST_EmptyStatement)) {
|
}
|
||||||
output.indent();
|
in_directive = false;
|
||||||
stmt.print(output);
|
|
||||||
if (!(i == last && is_toplevel)) {
|
|
||||||
output.newline();
|
|
||||||
if (is_toplevel) output.newline();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (in_directive === true &&
|
if (stmt instanceof AST_EmptyStatement) return;
|
||||||
stmt instanceof AST_SimpleStatement &&
|
output.indent();
|
||||||
stmt.body instanceof AST_String
|
stmt.print(output);
|
||||||
) {
|
if (i == last && is_toplevel) return;
|
||||||
in_directive = false;
|
output.newline();
|
||||||
}
|
if (is_toplevel) output.newline();
|
||||||
});
|
});
|
||||||
in_directive = false;
|
use_asm = was_asm;
|
||||||
}
|
}
|
||||||
|
|
||||||
AST_StatementWithBody.DEFMETHOD("_do_print_body", function(output) {
|
AST_StatementWithBody.DEFMETHOD("_do_print_body", function(output) {
|
||||||
@@ -1055,11 +1038,9 @@ function OutputStream(options) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
b = b.alternative;
|
b = b.alternative;
|
||||||
}
|
} else if (b instanceof AST_StatementWithBody) {
|
||||||
else if (b instanceof AST_StatementWithBody) {
|
|
||||||
b = b.body;
|
b = b.body;
|
||||||
}
|
} else break;
|
||||||
else break;
|
|
||||||
}
|
}
|
||||||
force_statement(self.body, output);
|
force_statement(self.body, output);
|
||||||
}
|
}
|
||||||
@@ -1160,7 +1141,7 @@ function OutputStream(options) {
|
|||||||
def.print(output);
|
def.print(output);
|
||||||
});
|
});
|
||||||
var p = output.parent();
|
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) {
|
function parenthesize_for_noin(node, output, noin) {
|
||||||
@@ -1231,7 +1212,7 @@ function OutputStream(options) {
|
|||||||
output.print_string(prop);
|
output.print_string(prop);
|
||||||
output.print("]");
|
output.print("]");
|
||||||
} else {
|
} else {
|
||||||
if (expr instanceof AST_Number && expr.getValue() >= 0) {
|
if (expr instanceof AST_Number && expr.value >= 0) {
|
||||||
if (!/[xa-f.)]/i.test(output.last())) {
|
if (!/[xa-f.)]/i.test(output.last())) {
|
||||||
output.print(".");
|
output.print(".");
|
||||||
}
|
}
|
||||||
@@ -1264,29 +1245,10 @@ function OutputStream(options) {
|
|||||||
output.print(self.operator);
|
output.print(self.operator);
|
||||||
});
|
});
|
||||||
DEFPRINT(AST_Binary, function(self, output) {
|
DEFPRINT(AST_Binary, function(self, output) {
|
||||||
var op = self.operator;
|
|
||||||
self.left.print(output);
|
self.left.print(output);
|
||||||
if (op[0] == ">" /* ">>" ">>>" ">" ">=" */
|
output.space();
|
||||||
&& self.left instanceof AST_UnaryPostfix
|
output.print(self.operator);
|
||||||
&& self.left.operator == "--") {
|
output.space();
|
||||||
// space is mandatory to avoid outputting -->
|
|
||||||
output.print(" ");
|
|
||||||
} else {
|
|
||||||
// the space is optional depending on "beautify"
|
|
||||||
output.space();
|
|
||||||
}
|
|
||||||
output.print(op);
|
|
||||||
if ((op == "<" || op == "<<")
|
|
||||||
&& self.right instanceof AST_UnaryPrefix
|
|
||||||
&& self.right.operator == "!"
|
|
||||||
&& self.right.expression instanceof AST_UnaryPrefix
|
|
||||||
&& self.right.expression.operator == "--") {
|
|
||||||
// space is mandatory to avoid outputting <!--
|
|
||||||
output.print(" ");
|
|
||||||
} else {
|
|
||||||
// the space is optional depending on "beautify"
|
|
||||||
output.space();
|
|
||||||
}
|
|
||||||
self.right.print(output);
|
self.right.print(output);
|
||||||
});
|
});
|
||||||
DEFPRINT(AST_Conditional, function(self, output) {
|
DEFPRINT(AST_Conditional, function(self, output) {
|
||||||
@@ -1367,34 +1329,53 @@ function OutputStream(options) {
|
|||||||
});
|
});
|
||||||
DEFPRINT(AST_Symbol, function(self, output) {
|
DEFPRINT(AST_Symbol, function(self, output) {
|
||||||
var def = self.definition();
|
var def = self.definition();
|
||||||
output.print_name(def ? def.mangled_name || def.name : self.name);
|
output.print_name(def && def.mangled_name || self.name);
|
||||||
});
|
});
|
||||||
DEFPRINT(AST_Hole, noop);
|
DEFPRINT(AST_Hole, noop);
|
||||||
DEFPRINT(AST_This, function(self, output) {
|
DEFPRINT(AST_This, function(self, output) {
|
||||||
output.print("this");
|
output.print("this");
|
||||||
});
|
});
|
||||||
DEFPRINT(AST_Constant, function(self, output) {
|
DEFPRINT(AST_Constant, function(self, output) {
|
||||||
output.print(self.getValue());
|
output.print(self.value);
|
||||||
});
|
});
|
||||||
DEFPRINT(AST_String, function(self, output) {
|
DEFPRINT(AST_String, function(self, output) {
|
||||||
output.print_string(self.getValue(), self.quote, in_directive);
|
output.print_string(self.value, self.quote);
|
||||||
});
|
});
|
||||||
DEFPRINT(AST_Number, function(self, output) {
|
DEFPRINT(AST_Number, function(self, output) {
|
||||||
if (use_asm && self.start && self.start.raw != null) {
|
if (use_asm && self.start && self.start.raw != null) {
|
||||||
output.print(self.start.raw);
|
output.print(self.start.raw);
|
||||||
} else {
|
} else {
|
||||||
output.print(make_num(self.getValue()));
|
output.print(make_num(self.value));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
DEFPRINT(AST_RegExp, function(self, output) {
|
DEFPRINT(AST_RegExp, function(self, output) {
|
||||||
var regexp = self.getValue();
|
var regexp = self.value;
|
||||||
var str = regexp.toString();
|
var str = regexp.toString();
|
||||||
if (regexp.raw_source) {
|
if (regexp.raw_source) {
|
||||||
str = "/" + regexp.raw_source + str.slice(str.lastIndexOf("/"));
|
str = "/" + regexp.raw_source + str.slice(str.lastIndexOf("/"));
|
||||||
}
|
}
|
||||||
str = output.to_utf8(str);
|
output.print(output.to_utf8(str).replace(/\\(?:\0(?![0-9])|[^\0])/g, function(seq) {
|
||||||
output.print(str);
|
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();
|
var p = output.parent();
|
||||||
if (p instanceof AST_Binary && /^in/.test(p.operator) && p.left === self)
|
if (p instanceof AST_Binary && /^in/.test(p.operator) && p.left === self)
|
||||||
output.print(" ");
|
output.print(" ");
|
||||||
|
|||||||
169
lib/parse.js
169
lib/parse.js
@@ -133,14 +133,10 @@ function is_letter(code) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function is_surrogate_pair_head(code) {
|
function is_surrogate_pair_head(code) {
|
||||||
if (typeof code == "string")
|
|
||||||
code = code.charCodeAt(0);
|
|
||||||
return code >= 0xd800 && code <= 0xdbff;
|
return code >= 0xd800 && code <= 0xdbff;
|
||||||
}
|
}
|
||||||
|
|
||||||
function is_surrogate_pair_tail(code) {
|
function is_surrogate_pair_tail(code) {
|
||||||
if (typeof code == "string")
|
|
||||||
code = code.charCodeAt(0);
|
|
||||||
return code >= 0xdc00 && code <= 0xdfff;
|
return code >= 0xdc00 && code <= 0xdfff;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -164,10 +160,6 @@ function is_unicode_connector_punctuation(ch) {
|
|||||||
return UNICODE.connector_punctuation.test(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) {
|
function is_identifier_start(code) {
|
||||||
return code == 36 || code == 95 || is_letter(code);
|
return code == 36 || code == 95 || is_letter(code);
|
||||||
}
|
}
|
||||||
@@ -238,6 +230,7 @@ function tokenizer($TEXT, filename, html5_comments, shebang) {
|
|||||||
directives : {},
|
directives : {},
|
||||||
directive_stack : []
|
directive_stack : []
|
||||||
};
|
};
|
||||||
|
var prev_was_dot = false;
|
||||||
|
|
||||||
function peek() {
|
function peek() {
|
||||||
return S.text.charAt(S.pos);
|
return S.text.charAt(S.pos);
|
||||||
@@ -272,10 +265,8 @@ function tokenizer($TEXT, filename, html5_comments, shebang) {
|
|||||||
|
|
||||||
function find_eol() {
|
function find_eol() {
|
||||||
var text = S.text;
|
var text = S.text;
|
||||||
for (var i = S.pos, n = S.text.length; i < n; ++i) {
|
for (var i = S.pos; i < S.text.length; ++i) {
|
||||||
var ch = text[i];
|
if (NEWLINE_CHARS[text[i]]) return i;
|
||||||
if (NEWLINE_CHARS[ch])
|
|
||||||
return i;
|
|
||||||
}
|
}
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
@@ -292,16 +283,12 @@ function tokenizer($TEXT, filename, html5_comments, shebang) {
|
|||||||
S.tokpos = S.pos;
|
S.tokpos = S.pos;
|
||||||
}
|
}
|
||||||
|
|
||||||
var prev_was_dot = false;
|
|
||||||
function token(type, value, is_comment) {
|
function token(type, value, is_comment) {
|
||||||
S.regex_allowed = ((type == "operator" && !UNARY_POSTFIX[value]) ||
|
S.regex_allowed = type == "operator" && !UNARY_POSTFIX[value]
|
||||||
(type == "keyword" && KEYWORDS_BEFORE_EXPRESSION[value]) ||
|
|| type == "keyword" && KEYWORDS_BEFORE_EXPRESSION[value]
|
||||||
(type == "punc" && PUNC_BEFORE_EXPRESSION[value]));
|
|| type == "punc" && PUNC_BEFORE_EXPRESSION[value];
|
||||||
if (type == "punc" && value == ".") {
|
if (type == "punc" && value == ".") prev_was_dot = true;
|
||||||
prev_was_dot = true;
|
else if (!is_comment) prev_was_dot = false;
|
||||||
} else if (!is_comment) {
|
|
||||||
prev_was_dot = false;
|
|
||||||
}
|
|
||||||
var ret = {
|
var ret = {
|
||||||
type : type,
|
type : type,
|
||||||
value : value,
|
value : value,
|
||||||
@@ -364,11 +351,8 @@ function tokenizer($TEXT, filename, html5_comments, shebang) {
|
|||||||
parse_error("Legacy octal literals are not allowed in strict mode");
|
parse_error("Legacy octal literals are not allowed in strict mode");
|
||||||
}
|
}
|
||||||
var valid = parse_js_number(num);
|
var valid = parse_js_number(num);
|
||||||
if (!isNaN(valid)) {
|
if (!isNaN(valid)) return token("num", valid);
|
||||||
return token("num", valid);
|
parse_error("Invalid syntax: " + num);
|
||||||
} else {
|
|
||||||
parse_error("Invalid syntax: " + num);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function read_escaped_char(in_string) {
|
function read_escaped_char(in_string) {
|
||||||
@@ -469,8 +453,7 @@ function tokenizer($TEXT, filename, html5_comments, shebang) {
|
|||||||
if (ch == "\\") escaped = backslash = true, next();
|
if (ch == "\\") escaped = backslash = true, next();
|
||||||
else if (is_identifier_char(ch)) name += next();
|
else if (is_identifier_char(ch)) name += next();
|
||||||
else break;
|
else break;
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
if (ch != "u") parse_error("Expecting UnicodeEscapeSequence -- uXXXX");
|
if (ch != "u") parse_error("Expecting UnicodeEscapeSequence -- uXXXX");
|
||||||
ch = read_escaped_char();
|
ch = read_escaped_char();
|
||||||
if (!is_identifier_char(ch)) parse_error("Unicode char: " + ch.charCodeAt(0) + " is not valid in identifier");
|
if (!is_identifier_char(ch)) parse_error("Unicode char: " + ch.charCodeAt(0) + " is not valid in identifier");
|
||||||
@@ -510,7 +493,7 @@ function tokenizer($TEXT, filename, html5_comments, shebang) {
|
|||||||
var regexp = new RegExp(source, mods);
|
var regexp = new RegExp(source, mods);
|
||||||
regexp.raw_source = source;
|
regexp.raw_source = source;
|
||||||
return token("regexp", regexp);
|
return token("regexp", regexp);
|
||||||
} catch(e) {
|
} catch (e) {
|
||||||
parse_error(e.message);
|
parse_error(e.message);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -544,9 +527,7 @@ function tokenizer($TEXT, filename, html5_comments, shebang) {
|
|||||||
|
|
||||||
function handle_dot() {
|
function handle_dot() {
|
||||||
next();
|
next();
|
||||||
return is_digit(peek().charCodeAt(0))
|
return is_digit(peek().charCodeAt(0)) ? read_num(".") : token("punc", ".");
|
||||||
? read_num(".")
|
|
||||||
: token("punc", ".");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function read_word() {
|
function read_word() {
|
||||||
@@ -562,7 +543,7 @@ function tokenizer($TEXT, filename, html5_comments, shebang) {
|
|||||||
return function(x) {
|
return function(x) {
|
||||||
try {
|
try {
|
||||||
return cont(x);
|
return cont(x);
|
||||||
} catch(ex) {
|
} catch (ex) {
|
||||||
if (ex === EX_EOF) parse_error(eof_error);
|
if (ex === EX_EOF) parse_error(eof_error);
|
||||||
else throw ex;
|
else throw ex;
|
||||||
}
|
}
|
||||||
@@ -598,11 +579,10 @@ function tokenizer($TEXT, filename, html5_comments, shebang) {
|
|||||||
switch (code) {
|
switch (code) {
|
||||||
case 34: case 39: return read_string(ch);
|
case 34: case 39: return read_string(ch);
|
||||||
case 46: return handle_dot();
|
case 46: return handle_dot();
|
||||||
case 47: {
|
case 47:
|
||||||
var tok = handle_slash();
|
var tok = handle_slash();
|
||||||
if (tok === next_token) continue;
|
if (tok === next_token) continue;
|
||||||
return tok;
|
return tok;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if (is_digit(code)) return read_num();
|
if (is_digit(code)) return read_num();
|
||||||
if (PUNC_CHARS[ch]) return token("punc", next());
|
if (PUNC_CHARS[ch]) return token("punc", next());
|
||||||
@@ -620,12 +600,8 @@ function tokenizer($TEXT, filename, html5_comments, shebang) {
|
|||||||
|
|
||||||
next_token.add_directive = function(directive) {
|
next_token.add_directive = function(directive) {
|
||||||
S.directive_stack[S.directive_stack.length - 1].push(directive);
|
S.directive_stack[S.directive_stack.length - 1].push(directive);
|
||||||
|
if (S.directives[directive]) S.directives[directive]++;
|
||||||
if (S.directives[directive] === undefined) {
|
else S.directives[directive] = 1;
|
||||||
S.directives[directive] = 1;
|
|
||||||
} else {
|
|
||||||
S.directives[directive]++;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
next_token.push_directives_stack = function() {
|
next_token.push_directives_stack = function() {
|
||||||
@@ -633,13 +609,10 @@ function tokenizer($TEXT, filename, html5_comments, shebang) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
next_token.pop_directives_stack = function() {
|
next_token.pop_directives_stack = function() {
|
||||||
var directives = S.directive_stack[S.directive_stack.length - 1];
|
var directives = S.directive_stack.pop();
|
||||||
|
for (var i = directives.length; --i >= 0;) {
|
||||||
for (var i = 0; i < directives.length; i++) {
|
|
||||||
S.directives[directives[i]]--;
|
S.directives[directives[i]]--;
|
||||||
}
|
}
|
||||||
|
|
||||||
S.directive_stack.pop();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
next_token.has_directive = function(directive) {
|
next_token.has_directive = function(directive) {
|
||||||
@@ -651,27 +624,17 @@ function tokenizer($TEXT, filename, html5_comments, shebang) {
|
|||||||
|
|
||||||
/* -----[ Parser (constants) ]----- */
|
/* -----[ Parser (constants) ]----- */
|
||||||
|
|
||||||
var UNARY_PREFIX = makePredicate([
|
var UNARY_PREFIX = makePredicate("typeof void delete -- ++ ! ~ - +");
|
||||||
"typeof",
|
|
||||||
"void",
|
|
||||||
"delete",
|
|
||||||
"--",
|
|
||||||
"++",
|
|
||||||
"!",
|
|
||||||
"~",
|
|
||||||
"-",
|
|
||||||
"+"
|
|
||||||
]);
|
|
||||||
|
|
||||||
var UNARY_POSTFIX = makePredicate([ "--", "++" ]);
|
var UNARY_POSTFIX = makePredicate("-- ++");
|
||||||
|
|
||||||
var ASSIGNMENT = makePredicate([ "=", "+=", "-=", "/=", "*=", "%=", ">>=", "<<=", ">>>=", "|=", "^=", "&=" ]);
|
var ASSIGNMENT = makePredicate("= += -= /= *= %= >>= <<= >>>= |= ^= &=");
|
||||||
|
|
||||||
var PRECEDENCE = function(a, ret) {
|
var PRECEDENCE = function(a, ret) {
|
||||||
for (var i = 0; i < a.length; ++i) {
|
for (var i = 0; i < a.length;) {
|
||||||
var b = a[i];
|
var b = a[i++];
|
||||||
for (var j = 0; j < b.length; ++j) {
|
for (var j = 0; j < b.length; j++) {
|
||||||
ret[b[j]] = i + 1;
|
ret[b[j]] = i;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return ret;
|
return ret;
|
||||||
@@ -688,7 +651,7 @@ var PRECEDENCE = function(a, ret) {
|
|||||||
["*", "/", "%"]
|
["*", "/", "%"]
|
||||||
], {});
|
], {});
|
||||||
|
|
||||||
var ATOMIC_START_TOKEN = makePredicate([ "atom", "num", "string", "regexp", "name" ]);
|
var ATOMIC_START_TOKEN = makePredicate("atom num string regexp name");
|
||||||
|
|
||||||
/* -----[ Parser ]----- */
|
/* -----[ Parser ]----- */
|
||||||
|
|
||||||
@@ -704,10 +667,9 @@ function parse($TEXT, options) {
|
|||||||
}, true);
|
}, true);
|
||||||
|
|
||||||
var S = {
|
var S = {
|
||||||
input : (typeof $TEXT == "string"
|
input : typeof $TEXT == "string"
|
||||||
? tokenizer($TEXT, options.filename,
|
? tokenizer($TEXT, options.filename, options.html5_comments, options.shebang)
|
||||||
options.html5_comments, options.shebang)
|
: $TEXT,
|
||||||
: $TEXT),
|
|
||||||
token : null,
|
token : null,
|
||||||
prev : null,
|
prev : null,
|
||||||
peeked : null,
|
peeked : null,
|
||||||
@@ -758,17 +720,18 @@ function parse($TEXT, options) {
|
|||||||
croak(msg, token.line, token.col);
|
croak(msg, token.line, token.col);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function token_to_string(type, value) {
|
||||||
|
return type + (value === undefined ? "" : " «" + value + "»");
|
||||||
|
}
|
||||||
|
|
||||||
function unexpected(token) {
|
function unexpected(token) {
|
||||||
if (token == null)
|
if (token == null) token = S.token;
|
||||||
token = S.token;
|
token_error(token, "Unexpected token: " + token_to_string(token.type, token.value));
|
||||||
token_error(token, "Unexpected token: " + token.type + " (" + token.value + ")");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function expect_token(type, val) {
|
function expect_token(type, val) {
|
||||||
if (is(type, val)) {
|
if (is(type, val)) return next();
|
||||||
return next();
|
token_error(S.token, "Unexpected token: " + token_to_string(S.token.type, S.token.value) + ", expected: " + token_to_string(type, val));
|
||||||
}
|
|
||||||
token_error(S.token, "Unexpected token " + S.token.type + " «" + S.token.value + "»" + ", expected " + type + " «" + val + "»");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function expect(punc) {
|
function expect(punc) {
|
||||||
@@ -788,7 +751,7 @@ function parse($TEXT, options) {
|
|||||||
|
|
||||||
function semicolon(optional) {
|
function semicolon(optional) {
|
||||||
if (is("punc", ";")) next();
|
if (is("punc", ";")) next();
|
||||||
else if (!optional && !can_insert_semicolon()) unexpected();
|
else if (!optional && !can_insert_semicolon()) expect_token("punc", ";");
|
||||||
}
|
}
|
||||||
|
|
||||||
function parenthesised() {
|
function parenthesised() {
|
||||||
@@ -820,20 +783,19 @@ function parse($TEXT, options) {
|
|||||||
handle_regexp();
|
handle_regexp();
|
||||||
switch (S.token.type) {
|
switch (S.token.type) {
|
||||||
case "string":
|
case "string":
|
||||||
if (S.in_directives) {
|
var dir = S.in_directives;
|
||||||
var token = peek();
|
var body = expression(true);
|
||||||
if (S.token.raw.indexOf("\\") == -1
|
if (dir) {
|
||||||
&& (is_token(token, "punc", ";")
|
if (body instanceof AST_String) {
|
||||||
|| is_token(token, "punc", "}")
|
var value = body.start.raw.slice(1, -1);
|
||||||
|| has_newline_before(token)
|
S.input.add_directive(value);
|
||||||
|| is_token(token, "eof"))) {
|
body.value = value;
|
||||||
S.input.add_directive(S.token.value);
|
|
||||||
} else {
|
} else {
|
||||||
S.in_directives = false;
|
S.in_directives = dir = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
var dir = S.in_directives, stat = simple_statement();
|
semicolon();
|
||||||
return dir ? new AST_Directive(stat.body) : stat;
|
return dir ? new AST_Directive(body) : new AST_SimpleStatement({ body: body });
|
||||||
case "num":
|
case "num":
|
||||||
case "regexp":
|
case "regexp":
|
||||||
case "operator":
|
case "operator":
|
||||||
@@ -998,8 +960,10 @@ function parse($TEXT, options) {
|
|||||||
return new AST_LabeledStatement({ body: stat, label: label });
|
return new AST_LabeledStatement({ body: stat, label: label });
|
||||||
}
|
}
|
||||||
|
|
||||||
function simple_statement(tmp) {
|
function simple_statement() {
|
||||||
return new AST_SimpleStatement({ body: (tmp = expression(true), semicolon(), tmp) });
|
var body = expression(true);
|
||||||
|
semicolon();
|
||||||
|
return new AST_SimpleStatement({ body: body });
|
||||||
}
|
}
|
||||||
|
|
||||||
function break_cont(type) {
|
function break_cont(type) {
|
||||||
@@ -1069,7 +1033,7 @@ function parse($TEXT, options) {
|
|||||||
var in_statement = ctor === AST_Defun;
|
var in_statement = ctor === AST_Defun;
|
||||||
var name = is("name") ? as_symbol(in_statement ? AST_SymbolDefun : AST_SymbolLambda) : null;
|
var name = is("name") ? as_symbol(in_statement ? AST_SymbolDefun : AST_SymbolLambda) : null;
|
||||||
if (in_statement && !name)
|
if (in_statement && !name)
|
||||||
unexpected();
|
expect_token("name");
|
||||||
if (name && ctor !== AST_Accessor && !(name instanceof AST_SymbolDeclaration))
|
if (name && ctor !== AST_Accessor && !(name instanceof AST_SymbolDeclaration))
|
||||||
unexpected(prev());
|
unexpected(prev());
|
||||||
expect("(");
|
expect("(");
|
||||||
@@ -1119,7 +1083,7 @@ function parse($TEXT, options) {
|
|||||||
expect("{");
|
expect("{");
|
||||||
var a = [];
|
var a = [];
|
||||||
while (!is("punc", "}")) {
|
while (!is("punc", "}")) {
|
||||||
if (is("eof")) unexpected();
|
if (is("eof")) expect_token("punc", "}");
|
||||||
a.push(statement(strict_defun));
|
a.push(statement(strict_defun));
|
||||||
}
|
}
|
||||||
next();
|
next();
|
||||||
@@ -1130,7 +1094,7 @@ function parse($TEXT, options) {
|
|||||||
expect("{");
|
expect("{");
|
||||||
var a = [], cur = null, branch = null, tmp;
|
var a = [], cur = null, branch = null, tmp;
|
||||||
while (!is("punc", "}")) {
|
while (!is("punc", "}")) {
|
||||||
if (is("eof")) unexpected();
|
if (is("eof")) expect_token("punc", "}");
|
||||||
if (is("keyword", "case")) {
|
if (is("keyword", "case")) {
|
||||||
if (branch) branch.end = prev();
|
if (branch) branch.end = prev();
|
||||||
cur = [];
|
cur = [];
|
||||||
@@ -1141,8 +1105,7 @@ function parse($TEXT, options) {
|
|||||||
});
|
});
|
||||||
a.push(branch);
|
a.push(branch);
|
||||||
expect(":");
|
expect(":");
|
||||||
}
|
} else if (is("keyword", "default")) {
|
||||||
else if (is("keyword", "default")) {
|
|
||||||
if (branch) branch.end = prev();
|
if (branch) branch.end = prev();
|
||||||
cur = [];
|
cur = [];
|
||||||
branch = new AST_Default({
|
branch = new AST_Default({
|
||||||
@@ -1150,8 +1113,7 @@ function parse($TEXT, options) {
|
|||||||
body : cur
|
body : cur
|
||||||
});
|
});
|
||||||
a.push(branch);
|
a.push(branch);
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
if (!cur) unexpected();
|
if (!cur) unexpected();
|
||||||
cur.push(statement());
|
cur.push(statement());
|
||||||
}
|
}
|
||||||
@@ -1288,6 +1250,7 @@ function parse($TEXT, options) {
|
|||||||
var ex = expression(true);
|
var ex = expression(true);
|
||||||
var len = start.comments_before.length;
|
var len = start.comments_before.length;
|
||||||
[].unshift.apply(ex.start.comments_before, start.comments_before);
|
[].unshift.apply(ex.start.comments_before, start.comments_before);
|
||||||
|
start.comments_before.length = 0;
|
||||||
start.comments_before = ex.start.comments_before;
|
start.comments_before = ex.start.comments_before;
|
||||||
start.comments_before_length = len;
|
start.comments_before_length = len;
|
||||||
if (len == 0 && start.comments_before.length > 0) {
|
if (len == 0 && start.comments_before.length > 0) {
|
||||||
@@ -1303,6 +1266,7 @@ function parse($TEXT, options) {
|
|||||||
var end = prev();
|
var end = prev();
|
||||||
end.comments_before = ex.end.comments_before;
|
end.comments_before = ex.end.comments_before;
|
||||||
[].push.apply(ex.end.comments_after, end.comments_after);
|
[].push.apply(ex.end.comments_after, end.comments_after);
|
||||||
|
end.comments_after.length = 0;
|
||||||
end.comments_after = ex.end.comments_after;
|
end.comments_after = ex.end.comments_after;
|
||||||
ex.end = end;
|
ex.end = end;
|
||||||
if (ex instanceof AST_Call) mark_pure(ex);
|
if (ex instanceof AST_Call) mark_pure(ex);
|
||||||
@@ -1420,10 +1384,10 @@ function parse($TEXT, options) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function as_name() {
|
function as_name() {
|
||||||
var tmp = S.token;
|
if (!is("name")) expect_token("name");
|
||||||
if (tmp.type != "name") unexpected();
|
var name = S.token.value;
|
||||||
next();
|
next();
|
||||||
return tmp.value;
|
return name;
|
||||||
}
|
}
|
||||||
|
|
||||||
function _make_symbol(type) {
|
function _make_symbol(type) {
|
||||||
@@ -1625,6 +1589,7 @@ function parse($TEXT, options) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (options.expression) {
|
if (options.expression) {
|
||||||
|
handle_regexp();
|
||||||
return expression(true);
|
return expression(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -53,25 +53,30 @@ function find_builtins(reserved) {
|
|||||||
"-Infinity",
|
"-Infinity",
|
||||||
"undefined",
|
"undefined",
|
||||||
].forEach(add);
|
].forEach(add);
|
||||||
[ Object, Array, Function, Number,
|
[
|
||||||
String, Boolean, Error, Math,
|
Array,
|
||||||
Date, RegExp
|
Boolean,
|
||||||
|
Date,
|
||||||
|
Error,
|
||||||
|
Function,
|
||||||
|
Math,
|
||||||
|
Number,
|
||||||
|
Object,
|
||||||
|
RegExp,
|
||||||
|
String,
|
||||||
].forEach(function(ctor) {
|
].forEach(function(ctor) {
|
||||||
Object.getOwnPropertyNames(ctor).map(add);
|
Object.getOwnPropertyNames(ctor).map(add);
|
||||||
if (ctor.prototype) {
|
if (ctor.prototype) {
|
||||||
Object.getOwnPropertyNames(ctor.prototype).map(add);
|
Object.getOwnPropertyNames(ctor.prototype).map(add);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
function add(name) {
|
function add(name) {
|
||||||
push_uniq(reserved, name);
|
push_uniq(reserved, name);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function reserve_quoted_keys(ast, reserved) {
|
function reserve_quoted_keys(ast, reserved) {
|
||||||
function add(name) {
|
|
||||||
push_uniq(reserved, name);
|
|
||||||
}
|
|
||||||
|
|
||||||
ast.walk(new TreeWalker(function(node) {
|
ast.walk(new TreeWalker(function(node) {
|
||||||
if (node instanceof AST_ObjectKeyVal && node.quote) {
|
if (node instanceof AST_ObjectKeyVal && node.quote) {
|
||||||
add(node.key);
|
add(node.key);
|
||||||
@@ -79,6 +84,10 @@ function reserve_quoted_keys(ast, reserved) {
|
|||||||
addStrings(node.property, add);
|
addStrings(node.property, add);
|
||||||
}
|
}
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
function add(name) {
|
||||||
|
push_uniq(reserved, name);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function addStrings(node, add) {
|
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'
|
// note debug may be enabled as an empty string, which is falsey. Also treat passing 'true'
|
||||||
// the same as passing an empty string.
|
// the same as passing an empty string.
|
||||||
var debug = options.debug !== false;
|
var debug = options.debug !== false;
|
||||||
var debug_name_suffix;
|
var debug_suffix;
|
||||||
if (debug) {
|
if (debug) debug_suffix = options.debug === true ? "" : options.debug;
|
||||||
debug_name_suffix = (options.debug === true ? "" : options.debug);
|
|
||||||
}
|
|
||||||
|
|
||||||
var names_to_mangle = [];
|
var names_to_mangle = [];
|
||||||
var unmangleable = [];
|
var unmangleable = [];
|
||||||
@@ -139,18 +146,14 @@ function mangle_properties(ast, options) {
|
|||||||
ast.walk(new TreeWalker(function(node) {
|
ast.walk(new TreeWalker(function(node) {
|
||||||
if (node instanceof AST_ObjectKeyVal) {
|
if (node instanceof AST_ObjectKeyVal) {
|
||||||
add(node.key);
|
add(node.key);
|
||||||
}
|
} else if (node instanceof AST_ObjectProperty) {
|
||||||
else if (node instanceof AST_ObjectProperty) {
|
|
||||||
// setter or getter, since KeyVal is handled above
|
// setter or getter, since KeyVal is handled above
|
||||||
add(node.key.name);
|
add(node.key.name);
|
||||||
}
|
} else if (node instanceof AST_Dot) {
|
||||||
else if (node instanceof AST_Dot) {
|
|
||||||
add(node.property);
|
add(node.property);
|
||||||
}
|
} else if (node instanceof AST_Sub) {
|
||||||
else if (node instanceof AST_Sub) {
|
|
||||||
addStrings(node.property, add);
|
addStrings(node.property, add);
|
||||||
}
|
} else if (node instanceof AST_Call
|
||||||
else if (node instanceof AST_Call
|
|
||||||
&& node.expression.print_to_string() == "Object.defineProperty") {
|
&& node.expression.print_to_string() == "Object.defineProperty") {
|
||||||
addStrings(node.args[1], add);
|
addStrings(node.args[1], add);
|
||||||
}
|
}
|
||||||
@@ -160,18 +163,14 @@ function mangle_properties(ast, options) {
|
|||||||
return ast.transform(new TreeTransformer(function(node) {
|
return ast.transform(new TreeTransformer(function(node) {
|
||||||
if (node instanceof AST_ObjectKeyVal) {
|
if (node instanceof AST_ObjectKeyVal) {
|
||||||
node.key = mangle(node.key);
|
node.key = mangle(node.key);
|
||||||
}
|
} else if (node instanceof AST_ObjectProperty) {
|
||||||
else if (node instanceof AST_ObjectProperty) {
|
|
||||||
// setter or getter
|
// setter or getter
|
||||||
node.key.name = mangle(node.key.name);
|
node.key.name = mangle(node.key.name);
|
||||||
}
|
} else if (node instanceof AST_Dot) {
|
||||||
else if (node instanceof AST_Dot) {
|
|
||||||
node.property = mangle(node.property);
|
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);
|
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.expression.print_to_string() == "Object.defineProperty") {
|
||||||
node.args[1] = mangleStrings(node.args[1]);
|
node.args[1] = mangleStrings(node.args[1]);
|
||||||
}
|
}
|
||||||
@@ -182,9 +181,7 @@ function mangle_properties(ast, options) {
|
|||||||
function can_mangle(name) {
|
function can_mangle(name) {
|
||||||
if (unmangleable.indexOf(name) >= 0) return false;
|
if (unmangleable.indexOf(name) >= 0) return false;
|
||||||
if (reserved.indexOf(name) >= 0) return false;
|
if (reserved.indexOf(name) >= 0) return false;
|
||||||
if (options.only_cache) {
|
if (options.only_cache) return cache.has(name);
|
||||||
return cache.has(name);
|
|
||||||
}
|
|
||||||
if (/^-?[0-9]+(\.[0-9]+)?(e[+-][0-9]+)?$/.test(name)) return false;
|
if (/^-?[0-9]+(\.[0-9]+)?(e[+-][0-9]+)?$/.test(name)) return false;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -192,42 +189,29 @@ function mangle_properties(ast, options) {
|
|||||||
function should_mangle(name) {
|
function should_mangle(name) {
|
||||||
if (regex && !regex.test(name)) return false;
|
if (regex && !regex.test(name)) return false;
|
||||||
if (reserved.indexOf(name) >= 0) return false;
|
if (reserved.indexOf(name) >= 0) return false;
|
||||||
return cache.has(name)
|
return cache.has(name) || names_to_mangle.indexOf(name) >= 0;
|
||||||
|| names_to_mangle.indexOf(name) >= 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function add(name) {
|
function add(name) {
|
||||||
if (can_mangle(name))
|
if (can_mangle(name)) push_uniq(names_to_mangle, name);
|
||||||
push_uniq(names_to_mangle, name);
|
if (!should_mangle(name)) push_uniq(unmangleable, name);
|
||||||
|
|
||||||
if (!should_mangle(name)) {
|
|
||||||
push_uniq(unmangleable, name);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function mangle(name) {
|
function mangle(name) {
|
||||||
if (!should_mangle(name)) {
|
if (!should_mangle(name)) {
|
||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
|
|
||||||
var mangled = cache.get(name);
|
var mangled = cache.get(name);
|
||||||
if (!mangled) {
|
if (!mangled) {
|
||||||
if (debug) {
|
if (debug) {
|
||||||
// debug mode: use a prefix and suffix to preserve readability, e.g. o.foo -> o._$foo$NNN_.
|
// debug mode: use a prefix and suffix to preserve readability, e.g. o.foo -> o._$foo$NNN_.
|
||||||
var debug_mangled = "_$" + name + "$" + debug_name_suffix + "_";
|
var debug_mangled = "_$" + name + "$" + debug_suffix + "_";
|
||||||
|
if (can_mangle(debug_mangled)) mangled = debug_mangled;
|
||||||
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
|
// either debug mode is off, or it is on and we could not use the mangled name
|
||||||
if (!mangled) {
|
if (!mangled) do {
|
||||||
do {
|
mangled = base54(++cname);
|
||||||
mangled = base54(++cname);
|
} while (!can_mangle(mangled));
|
||||||
} while (!can_mangle(mangled));
|
|
||||||
}
|
|
||||||
|
|
||||||
cache.set(name, mangled);
|
cache.set(name, mangled);
|
||||||
}
|
}
|
||||||
return mangled;
|
return mangled;
|
||||||
@@ -238,11 +222,9 @@ function mangle_properties(ast, options) {
|
|||||||
if (node instanceof AST_Sequence) {
|
if (node instanceof AST_Sequence) {
|
||||||
var last = node.expressions.length - 1;
|
var last = node.expressions.length - 1;
|
||||||
node.expressions[last] = mangleStrings(node.expressions[last]);
|
node.expressions[last] = mangleStrings(node.expressions[last]);
|
||||||
}
|
} else if (node instanceof AST_String) {
|
||||||
else if (node instanceof AST_String) {
|
|
||||||
node.value = mangle(node.value);
|
node.value = mangle(node.value);
|
||||||
}
|
} else if (node instanceof AST_Conditional) {
|
||||||
else if (node instanceof AST_Conditional) {
|
|
||||||
node.consequent = mangleStrings(node.consequent);
|
node.consequent = mangleStrings(node.consequent);
|
||||||
node.alternative = mangleStrings(node.alternative);
|
node.alternative = mangleStrings(node.alternative);
|
||||||
}
|
}
|
||||||
|
|||||||
183
lib/scope.js
183
lib/scope.js
@@ -55,14 +55,13 @@ function SymbolDef(scope, orig, init) {
|
|||||||
this.mangled_name = null;
|
this.mangled_name = null;
|
||||||
this.undeclared = false;
|
this.undeclared = false;
|
||||||
this.id = SymbolDef.next_id++;
|
this.id = SymbolDef.next_id++;
|
||||||
|
this.lambda = orig instanceof AST_SymbolLambda;
|
||||||
}
|
}
|
||||||
|
|
||||||
SymbolDef.next_id = 1;
|
SymbolDef.next_id = 1;
|
||||||
|
|
||||||
SymbolDef.prototype = {
|
SymbolDef.prototype = {
|
||||||
unmangleable: function(options) {
|
unmangleable: function(options) {
|
||||||
if (!options) options = {};
|
|
||||||
|
|
||||||
return this.global && !options.toplevel
|
return this.global && !options.toplevel
|
||||||
|| this.undeclared
|
|| this.undeclared
|
||||||
|| !options.eval && this.scope.pinned()
|
|| !options.eval && this.scope.pinned()
|
||||||
@@ -118,11 +117,10 @@ AST_Toplevel.DEFMETHOD("figure_out_scope", function(options) {
|
|||||||
descend();
|
descend();
|
||||||
scope = save_scope;
|
scope = save_scope;
|
||||||
defun = save_defun;
|
defun = save_defun;
|
||||||
return true; // don't descend again in TreeWalker
|
return true;
|
||||||
}
|
}
|
||||||
if (node instanceof AST_With) {
|
if (node instanceof AST_With) {
|
||||||
for (var s = scope; s; s = s.parent_scope)
|
for (var s = scope; s; s = s.parent_scope) s.uses_with = true;
|
||||||
s.uses_with = true;
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (node instanceof AST_Symbol) {
|
if (node instanceof AST_Symbol) {
|
||||||
@@ -132,18 +130,14 @@ AST_Toplevel.DEFMETHOD("figure_out_scope", function(options) {
|
|||||||
node.thedef = node;
|
node.thedef = node;
|
||||||
node.references = [];
|
node.references = [];
|
||||||
}
|
}
|
||||||
if (node instanceof AST_SymbolDefun || options.ie8 && node instanceof AST_SymbolLambda) {
|
if (node instanceof AST_SymbolDefun) {
|
||||||
// Careful here, the scope where this should be defined is
|
// This should be defined in the parent scope, as we encounter the
|
||||||
// the parent scope. The reason is that we enter a new
|
// AST_Defun node before getting to its AST_Symbol.
|
||||||
// scope when we encounter the AST_Defun node (which is
|
(node.scope = defun.parent_scope.resolve()).def_function(node, defun);
|
||||||
// instanceof AST_Scope) but we get to the symbol a bit
|
} else if (node instanceof AST_SymbolLambda) {
|
||||||
// later.
|
var def = defun.def_function(node, node.name == "arguments" ? undefined : defun);
|
||||||
(node.scope = defun.parent_scope).def_function(node, defun);
|
if (options.ie8) def.defun = defun.parent_scope.resolve();
|
||||||
}
|
} else if (node instanceof AST_SymbolVar) {
|
||||||
else if (node instanceof AST_SymbolLambda) {
|
|
||||||
defun.def_function(node, node.name == "arguments" ? undefined : defun);
|
|
||||||
}
|
|
||||||
else if (node instanceof AST_SymbolVar) {
|
|
||||||
defun.def_variable(node, node.TYPE == "SymbolVar" ? null : undefined);
|
defun.def_variable(node, node.TYPE == "SymbolVar" ? null : undefined);
|
||||||
if (defun !== scope) {
|
if (defun !== scope) {
|
||||||
node.mark_enclosed(options);
|
node.mark_enclosed(options);
|
||||||
@@ -153,8 +147,7 @@ AST_Toplevel.DEFMETHOD("figure_out_scope", function(options) {
|
|||||||
}
|
}
|
||||||
node.reference(options);
|
node.reference(options);
|
||||||
}
|
}
|
||||||
}
|
} else if (node instanceof AST_SymbolCatch) {
|
||||||
else if (node instanceof AST_SymbolCatch) {
|
|
||||||
scope.def_variable(node).defun = defun;
|
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
|
// pass 2: find back references and eval
|
||||||
self.globals = new Dictionary();
|
self.globals = new Dictionary();
|
||||||
var tw = new TreeWalker(function(node, descend) {
|
var tw = new TreeWalker(function(node) {
|
||||||
if (node instanceof AST_LoopControl && node.label) {
|
if (node instanceof AST_LoopControl) {
|
||||||
node.label.thedef.references.push(node);
|
if (node.label) node.label.thedef.references.push(node);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (node instanceof AST_SymbolRef) {
|
if (node instanceof AST_SymbolRef) {
|
||||||
@@ -185,35 +178,55 @@ AST_Toplevel.DEFMETHOD("figure_out_scope", function(options) {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
// ensure mangling works if catch reuses a scope variable
|
// ensure mangling works if catch reuses a scope variable
|
||||||
var def;
|
if (node instanceof AST_SymbolCatch) {
|
||||||
if (node instanceof AST_SymbolCatch && (def = node.definition().redefined())) {
|
var def = node.definition().redefined();
|
||||||
var s = node.scope;
|
if (def) for (var s = node.scope; s; s = s.parent_scope) {
|
||||||
while (s) {
|
|
||||||
push_uniq(s.enclosed, def);
|
push_uniq(s.enclosed, def);
|
||||||
if (s === def.scope) break;
|
if (s === def.scope) break;
|
||||||
s = s.parent_scope;
|
|
||||||
}
|
}
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
self.walk(tw);
|
self.walk(tw);
|
||||||
|
|
||||||
// pass 3: fix up any scoping issue with IE8
|
// pass 3: fix up any scoping issue with IE8
|
||||||
if (options.ie8) {
|
if (options.ie8) self.walk(new TreeWalker(function(node) {
|
||||||
self.walk(new TreeWalker(function(node, descend) {
|
if (node instanceof AST_SymbolCatch) {
|
||||||
if (node instanceof AST_SymbolCatch) {
|
var scope = node.thedef.defun;
|
||||||
var name = node.name;
|
if (scope.name instanceof AST_SymbolLambda && scope.name.name == node.name) {
|
||||||
var refs = node.thedef.references;
|
scope = scope.parent_scope.resolve();
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
}));
|
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) {
|
AST_Symbol.DEFMETHOD("mark_enclosed", function(options) {
|
||||||
var def = this.definition();
|
var def = this.definition();
|
||||||
var s = this.scope;
|
for (var s = this.scope; s; s = s.parent_scope) {
|
||||||
while (s) {
|
|
||||||
push_uniq(s.enclosed, def);
|
push_uniq(s.enclosed, def);
|
||||||
if (options.keep_fnames) {
|
if (options.keep_fnames) {
|
||||||
s.functions.each(function(d) {
|
s.functions.each(function(d) {
|
||||||
@@ -261,7 +273,6 @@ AST_Symbol.DEFMETHOD("mark_enclosed", function(options) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
if (s === def.scope) break;
|
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);
|
var def = this.variables.get(symbol.name);
|
||||||
if (def) {
|
if (def) {
|
||||||
def.orig.push(symbol);
|
def.orig.push(symbol);
|
||||||
if (def.init && (def.scope !== symbol.scope || def.init instanceof AST_Function)) {
|
if (def.init instanceof AST_Function) def.init = init;
|
||||||
def.init = init;
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
def = new SymbolDef(this, symbol, init);
|
def = new SymbolDef(this, symbol, init);
|
||||||
this.variables.set(symbol.name, def);
|
this.variables.set(symbol.name, def);
|
||||||
@@ -298,13 +307,23 @@ AST_Scope.DEFMETHOD("def_variable", function(symbol, init) {
|
|||||||
return symbol.thedef = def;
|
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) {
|
function names_in_use(scope, options) {
|
||||||
var names = scope.names_in_use;
|
var names = scope.names_in_use;
|
||||||
if (!names) {
|
if (!names) {
|
||||||
scope.names_in_use = names = Object.create(scope.mangled_names || null);
|
scope.names_in_use = names = Object.create(scope.mangled_names || null);
|
||||||
scope.cname_holes = [];
|
scope.cname_holes = [];
|
||||||
|
var cache = options.cache && options.cache.props;
|
||||||
scope.enclosed.forEach(function(def) {
|
scope.enclosed.forEach(function(def) {
|
||||||
if (def.unmangleable(options)) names[def.name] = true;
|
if (def.unmangleable(options)) names[def.name] = true;
|
||||||
|
if (def.global && cache && cache.has(def.name)) {
|
||||||
|
names[cache.get(def.name)] = true;
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
return names;
|
return names;
|
||||||
@@ -314,14 +333,6 @@ function next_mangled_name(scope, options, def) {
|
|||||||
var in_use = names_in_use(scope, options);
|
var in_use = names_in_use(scope, options);
|
||||||
var holes = scope.cname_holes;
|
var holes = scope.cname_holes;
|
||||||
var names = Object.create(null);
|
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 ];
|
var scopes = [ scope ];
|
||||||
def.references.forEach(function(sym) {
|
def.references.forEach(function(sym) {
|
||||||
var scope = sym.scope;
|
var scope = sym.scope;
|
||||||
@@ -335,7 +346,7 @@ function next_mangled_name(scope, options, def) {
|
|||||||
} while (scope = scope.parent_scope);
|
} while (scope = scope.parent_scope);
|
||||||
});
|
});
|
||||||
var name;
|
var name;
|
||||||
for (var i = 0, len = holes.length; i < len; i++) {
|
for (var i = 0; i < holes.length; i++) {
|
||||||
name = base54(holes[i]);
|
name = base54(holes[i]);
|
||||||
if (names[name]) continue;
|
if (names[name]) continue;
|
||||||
holes.splice(i, 1);
|
holes.splice(i, 1);
|
||||||
@@ -344,7 +355,7 @@ function next_mangled_name(scope, options, def) {
|
|||||||
}
|
}
|
||||||
while (true) {
|
while (true) {
|
||||||
name = base54(++scope.cname);
|
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;
|
if (!names[name]) break;
|
||||||
holes.push(scope.cname);
|
holes.push(scope.cname);
|
||||||
}
|
}
|
||||||
@@ -410,40 +421,38 @@ AST_Toplevel.DEFMETHOD("mangle_names", function(options) {
|
|||||||
var save_nesting = lname;
|
var save_nesting = lname;
|
||||||
descend();
|
descend();
|
||||||
lname = save_nesting;
|
lname = save_nesting;
|
||||||
return true; // don't descend again in TreeWalker
|
return true;
|
||||||
}
|
}
|
||||||
if (node instanceof AST_Scope) {
|
if (node instanceof AST_Scope) {
|
||||||
descend();
|
descend();
|
||||||
if (options.cache && node instanceof AST_Toplevel) {
|
if (options.cache && node instanceof AST_Toplevel) {
|
||||||
node.globals.each(mangle);
|
node.globals.each(mangle);
|
||||||
}
|
}
|
||||||
node.variables.each(mangle);
|
if (node instanceof AST_Defun && tw.has_directive("use asm")) {
|
||||||
|
var sym = new AST_SymbolRef(node.name);
|
||||||
|
sym.scope = node;
|
||||||
|
sym.reference(options);
|
||||||
|
}
|
||||||
|
node.variables.each(function(def) {
|
||||||
|
if (!defer_redef(def)) mangle(def);
|
||||||
|
});
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (node instanceof AST_Label) {
|
if (node instanceof AST_Label) {
|
||||||
var name;
|
var name;
|
||||||
do name = base54(++lname); while (!is_identifier(name));
|
do {
|
||||||
|
name = base54(++lname);
|
||||||
|
} while (RESERVED_WORDS[name]);
|
||||||
node.mangled_name = name;
|
node.mangled_name = name;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (!options.ie8 && node instanceof AST_Catch) {
|
if (!options.ie8 && node instanceof AST_Catch) {
|
||||||
var def = node.argname.definition();
|
var def = node.argname.definition();
|
||||||
var redef = def.redefined();
|
var redef = defer_redef(def, node.argname);
|
||||||
if (redef) {
|
|
||||||
redefined.push(def);
|
|
||||||
reference(node.argname);
|
|
||||||
def.references.forEach(reference);
|
|
||||||
}
|
|
||||||
descend();
|
descend();
|
||||||
if (!redef) mangle(def);
|
if (!redef) mangle(def);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
function reference(sym) {
|
|
||||||
sym.thedef = redef;
|
|
||||||
sym.reference(options);
|
|
||||||
sym.thedef = def;
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
this.walk(tw);
|
this.walk(tw);
|
||||||
redefined.forEach(mangle);
|
redefined.forEach(mangle);
|
||||||
@@ -452,6 +461,21 @@ AST_Toplevel.DEFMETHOD("mangle_names", function(options) {
|
|||||||
if (options.reserved.has[def.name]) return;
|
if (options.reserved.has[def.name]) return;
|
||||||
def.mangle(options);
|
def.mangle(options);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function defer_redef(def, node) {
|
||||||
|
var redef = def.redefined();
|
||||||
|
if (!redef) return false;
|
||||||
|
redefined.push(def);
|
||||||
|
def.references.forEach(reference);
|
||||||
|
if (node) reference(node);
|
||||||
|
return true;
|
||||||
|
|
||||||
|
function reference(sym) {
|
||||||
|
sym.thedef = redef;
|
||||||
|
sym.reference(options);
|
||||||
|
sym.thedef = def;
|
||||||
|
}
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
AST_Toplevel.DEFMETHOD("find_colliding_names", function(options) {
|
AST_Toplevel.DEFMETHOD("find_colliding_names", function(options) {
|
||||||
@@ -493,7 +517,7 @@ AST_Toplevel.DEFMETHOD("expand_names", function(options) {
|
|||||||
var name;
|
var name;
|
||||||
do {
|
do {
|
||||||
name = base54(cname++);
|
name = base54(cname++);
|
||||||
} while (avoid[name] || !is_identifier(name));
|
} while (avoid[name] || RESERVED_WORDS[name]);
|
||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -501,13 +525,14 @@ AST_Toplevel.DEFMETHOD("expand_names", function(options) {
|
|||||||
if (def.global && options.cache) return;
|
if (def.global && options.cache) return;
|
||||||
if (def.unmangleable(options)) return;
|
if (def.unmangleable(options)) return;
|
||||||
if (options.reserved.has[def.name]) return;
|
if (options.reserved.has[def.name]) return;
|
||||||
var d = def.redefined();
|
var redef = def.redefined();
|
||||||
def.name = d ? d.name : next_name();
|
var name = redef ? redef.rename || redef.name : next_name();
|
||||||
|
def.rename = name;
|
||||||
def.orig.forEach(function(sym) {
|
def.orig.forEach(function(sym) {
|
||||||
sym.name = def.name;
|
sym.name = name;
|
||||||
});
|
});
|
||||||
def.references.forEach(function(sym) {
|
def.references.forEach(function(sym) {
|
||||||
sym.name = def.name;
|
sym.name = name;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -555,7 +580,7 @@ var base54 = (function() {
|
|||||||
var freq = Object.create(null);
|
var freq = Object.create(null);
|
||||||
function init(chars) {
|
function init(chars) {
|
||||||
var array = [];
|
var array = [];
|
||||||
for (var i = 0, len = chars.length; i < len; i++) {
|
for (var i = 0; i < chars.length; i++) {
|
||||||
var ch = chars[i];
|
var ch = chars[i];
|
||||||
array.push(ch);
|
array.push(ch);
|
||||||
freq[ch] = -1e-2 * i;
|
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;
|
err.name = this.name;
|
||||||
try {
|
try {
|
||||||
throw err;
|
throw err;
|
||||||
} catch(e) {
|
} catch (e) {
|
||||||
return e.stack;
|
return e.stack;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -127,8 +127,7 @@ var MAP = (function() {
|
|||||||
} else {
|
} else {
|
||||||
top.push(val);
|
top.push(val);
|
||||||
}
|
}
|
||||||
}
|
} else if (val !== skip) {
|
||||||
else if (val !== skip) {
|
|
||||||
if (val instanceof Splice) {
|
if (val instanceof Splice) {
|
||||||
ret.push.apply(ret, backwards ? val.v.slice().reverse() : val.v);
|
ret.push.apply(ret, backwards ? val.v.slice().reverse() : val.v);
|
||||||
} else {
|
} else {
|
||||||
@@ -145,8 +144,7 @@ var MAP = (function() {
|
|||||||
} else {
|
} else {
|
||||||
for (i = 0; i < a.length; ++i) if (doit()) break;
|
for (i = 0; i < a.length; ++i) if (doit()) break;
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
for (i in a) if (HOP(a, i)) if (doit()) break;
|
for (i in a) if (HOP(a, i)) if (doit()) break;
|
||||||
}
|
}
|
||||||
return top.concat(ret);
|
return top.concat(ret);
|
||||||
@@ -162,8 +160,7 @@ var MAP = (function() {
|
|||||||
})();
|
})();
|
||||||
|
|
||||||
function push_uniq(array, el) {
|
function push_uniq(array, el) {
|
||||||
if (array.indexOf(el) < 0)
|
if (array.indexOf(el) < 0) return array.push(el);
|
||||||
array.push(el);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function string_template(text, props) {
|
function string_template(text, props) {
|
||||||
@@ -173,9 +170,8 @@ function string_template(text, props) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function remove(array, el) {
|
function remove(array, el) {
|
||||||
for (var i = array.length; --i >= 0;) {
|
var index = array.indexOf(el);
|
||||||
if (array[i] === el) array.splice(i, 1);
|
if (index >= 0) array.splice(index, 1);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function makePredicate(words) {
|
function makePredicate(words) {
|
||||||
|
|||||||
10
package.json
10
package.json
@@ -3,7 +3,7 @@
|
|||||||
"description": "JavaScript parser, mangler/compressor and beautifier toolkit",
|
"description": "JavaScript parser, mangler/compressor and beautifier toolkit",
|
||||||
"author": "Mihai Bazon <mihai.bazon@gmail.com> (http://lisperator.net/)",
|
"author": "Mihai Bazon <mihai.bazon@gmail.com> (http://lisperator.net/)",
|
||||||
"license": "BSD-2-Clause",
|
"license": "BSD-2-Clause",
|
||||||
"version": "3.4.2",
|
"version": "3.7.5",
|
||||||
"engines": {
|
"engines": {
|
||||||
"node": ">=0.8.0"
|
"node": ">=0.8.0"
|
||||||
},
|
},
|
||||||
@@ -23,15 +23,15 @@
|
|||||||
"LICENSE"
|
"LICENSE"
|
||||||
],
|
],
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"commander": "~2.15.0",
|
"commander": "~2.20.3",
|
||||||
"source-map": "~0.6.1"
|
"source-map": "~0.6.1"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"acorn": "~5.5.3",
|
"acorn": "~7.1.0",
|
||||||
"semver": "~5.5.0"
|
"semver": "~6.3.0"
|
||||||
},
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"test": "node test/run-tests.js"
|
"test": "node test/compress.js && node test/mocha.js"
|
||||||
},
|
},
|
||||||
"keywords": [
|
"keywords": [
|
||||||
"cli",
|
"cli",
|
||||||
|
|||||||
@@ -13,15 +13,15 @@ if (!args.length) {
|
|||||||
}
|
}
|
||||||
args.push("--timings");
|
args.push("--timings");
|
||||||
var urls = [
|
var urls = [
|
||||||
"https://code.jquery.com/jquery-3.2.1.js",
|
"https://code.jquery.com/jquery-3.4.1.js",
|
||||||
"https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.6.4/angular.js",
|
"https://code.angularjs.org/1.7.8/angular.js",
|
||||||
"https://cdnjs.cloudflare.com/ajax/libs/mathjs/3.9.0/math.js",
|
"https://unpkg.com/mathjs@6.2.3/dist/math.js",
|
||||||
"https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.js",
|
|
||||||
"https://unpkg.com/react@15.3.2/dist/react.js",
|
"https://unpkg.com/react@15.3.2/dist/react.js",
|
||||||
"http://builds.emberjs.com/tags/v2.11.0/ember.prod.js",
|
"https://cdnjs.cloudflare.com/ajax/libs/d3/5.12.0/d3.js",
|
||||||
"https://cdn.jsdelivr.net/lodash/4.17.4/lodash.js",
|
"https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.js",
|
||||||
"https://cdnjs.cloudflare.com/ajax/libs/d3/4.5.0/d3.js",
|
"https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.15/lodash.js",
|
||||||
"https://raw.githubusercontent.com/kangax/html-minifier/v3.5.7/dist/htmlminifier.js",
|
"https://cdnjs.cloudflare.com/ajax/libs/ember.js/2.12.2/ember.prod.js",
|
||||||
|
"https://raw.githubusercontent.com/kangax/html-minifier/v4.0.0/dist/htmlminifier.js",
|
||||||
];
|
];
|
||||||
var results = {};
|
var results = {};
|
||||||
var remaining = 2 * urls.length;
|
var remaining = 2 * urls.length;
|
||||||
|
|||||||
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"
|
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"
|
||||||
|
}
|
||||||
|
|||||||
@@ -15,9 +15,9 @@ holes_and_undefined: {
|
|||||||
|
|
||||||
constant_join: {
|
constant_join: {
|
||||||
options = {
|
options = {
|
||||||
unsafe : true,
|
evaluate: true,
|
||||||
evaluate : true
|
unsafe: true,
|
||||||
};
|
}
|
||||||
input: {
|
input: {
|
||||||
var a = [ "foo", "bar", "baz" ].join("");
|
var a = [ "foo", "bar", "baz" ].join("");
|
||||||
var a1 = [ "foo", "bar", "baz" ].join();
|
var a1 = [ "foo", "bar", "baz" ].join();
|
||||||
@@ -64,9 +64,9 @@ constant_join: {
|
|||||||
|
|
||||||
constant_join_2: {
|
constant_join_2: {
|
||||||
options = {
|
options = {
|
||||||
unsafe : true,
|
evaluate: true,
|
||||||
evaluate : true
|
unsafe: true,
|
||||||
};
|
}
|
||||||
input: {
|
input: {
|
||||||
var a = [ "foo", "bar", boo(), "baz", "x", "y" ].join("");
|
var a = [ "foo", "bar", boo(), "baz", "x", "y" ].join("");
|
||||||
var b = [ "foo", "bar", boo(), "baz", "x", "y" ].join("-");
|
var b = [ "foo", "bar", boo(), "baz", "x", "y" ].join("-");
|
||||||
@@ -93,9 +93,9 @@ constant_join_2: {
|
|||||||
|
|
||||||
constant_join_3: {
|
constant_join_3: {
|
||||||
options = {
|
options = {
|
||||||
unsafe: true,
|
|
||||||
evaluate: true,
|
evaluate: true,
|
||||||
};
|
unsafe: true,
|
||||||
|
}
|
||||||
input: {
|
input: {
|
||||||
var a = [ null ].join();
|
var a = [ null ].join();
|
||||||
var b = [ , ].join();
|
var b = [ , ].join();
|
||||||
@@ -133,7 +133,7 @@ for_loop: {
|
|||||||
reduce_vars: true,
|
reduce_vars: true,
|
||||||
unsafe: true,
|
unsafe: true,
|
||||||
unused: true,
|
unused: true,
|
||||||
};
|
}
|
||||||
input: {
|
input: {
|
||||||
function f0() {
|
function f0() {
|
||||||
var a = [1, 2, 3];
|
var a = [1, 2, 3];
|
||||||
@@ -239,3 +239,113 @@ index_length: {
|
|||||||
}
|
}
|
||||||
expect_stdout: "1 2"
|
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,24 +1,25 @@
|
|||||||
asm_mixed: {
|
asm_mixed: {
|
||||||
options = {
|
options = {
|
||||||
sequences : true,
|
assignments: true,
|
||||||
properties : true,
|
booleans: true,
|
||||||
dead_code : true,
|
comparisons: true,
|
||||||
drop_debugger : true,
|
conditionals: true,
|
||||||
conditionals : true,
|
dead_code: true,
|
||||||
comparisons : true,
|
drop_debugger: true,
|
||||||
evaluate : true,
|
evaluate: true,
|
||||||
booleans : true,
|
hoist_funs: true,
|
||||||
loops : true,
|
hoist_vars: true,
|
||||||
unused : true,
|
if_return: true,
|
||||||
hoist_funs : true,
|
join_vars: true,
|
||||||
keep_fargs : true,
|
keep_fargs: true,
|
||||||
keep_fnames : false,
|
keep_fnames: false,
|
||||||
hoist_vars : true,
|
loops: true,
|
||||||
if_return : true,
|
negate_iife: true,
|
||||||
join_vars : true,
|
properties: true,
|
||||||
side_effects : true,
|
sequences: true,
|
||||||
negate_iife : true
|
side_effects: true,
|
||||||
};
|
unused: true,
|
||||||
|
}
|
||||||
input: {
|
input: {
|
||||||
// adapted from http://asmjs.org/spec/latest/
|
// adapted from http://asmjs.org/spec/latest/
|
||||||
function asm_GeometricMean(stdlib, foreign, buffer) {
|
function asm_GeometricMean(stdlib, foreign, buffer) {
|
||||||
@@ -95,7 +96,7 @@ asm_mixed: {
|
|||||||
return +sum;
|
return +sum;
|
||||||
}
|
}
|
||||||
function geometricMean(start, end) {
|
function geometricMean(start, end) {
|
||||||
return start |= 0, end |= 0, +exp(+logSum(start, end) / +(end - start | 0));
|
return start |= 0, end |= 0, +exp(logSum(start, end) / (end - start | 0));
|
||||||
}
|
}
|
||||||
var exp = stdlib.Math.exp, log = stdlib.Math.log, values = new stdlib.Float64Array(buffer);
|
var exp = stdlib.Math.exp, log = stdlib.Math.log, values = new stdlib.Float64Array(buffer);
|
||||||
return { geometricMean: geometricMean };
|
return { geometricMean: geometricMean };
|
||||||
@@ -165,3 +166,69 @@ asm_nested_functions: {
|
|||||||
}
|
}
|
||||||
expect_exact: '0;function a(){"use asm";0.0}0;function b(){0;function c(){"use asm";0.0}0;function d(){0}0}0;'
|
expect_exact: '0;function a(){"use asm";0.0}0;function b(){0;function c(){"use asm";0.0}0;function d(){0}0}0;'
|
||||||
}
|
}
|
||||||
|
|
||||||
|
issue_3636_1: {
|
||||||
|
mangle = {}
|
||||||
|
input: {
|
||||||
|
function n(stdlib, foreign, buffer) {
|
||||||
|
"use asm";
|
||||||
|
function add(x, y) {
|
||||||
|
x = x | 0;
|
||||||
|
y = y | 0;
|
||||||
|
return x + y | 0;
|
||||||
|
}
|
||||||
|
return {
|
||||||
|
add: add
|
||||||
|
};
|
||||||
|
}
|
||||||
|
console.log(new n().add("foo", 42));
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
function n(o, e, u) {
|
||||||
|
"use asm";
|
||||||
|
function d(n, o) {
|
||||||
|
n = n | 0;
|
||||||
|
o = o | 0;
|
||||||
|
return n + o | 0;
|
||||||
|
}
|
||||||
|
return {
|
||||||
|
add: d
|
||||||
|
};
|
||||||
|
}
|
||||||
|
console.log(new n().add("foo", 42));
|
||||||
|
}
|
||||||
|
expect_stdout: "42"
|
||||||
|
}
|
||||||
|
|
||||||
|
issue_3636_2: {
|
||||||
|
mangle = {}
|
||||||
|
input: {
|
||||||
|
var n = function(stdlib, foreign, buffer) {
|
||||||
|
"use asm";
|
||||||
|
function add(x, y) {
|
||||||
|
x = x | 0;
|
||||||
|
y = y | 0;
|
||||||
|
return x + y | 0;
|
||||||
|
}
|
||||||
|
return {
|
||||||
|
add: add
|
||||||
|
};
|
||||||
|
};
|
||||||
|
console.log(new n().add("foo", 42));
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
var n = function(n, o, e) {
|
||||||
|
"use asm";
|
||||||
|
function r(n, o) {
|
||||||
|
n = n | 0;
|
||||||
|
o = o | 0;
|
||||||
|
return n + o | 0;
|
||||||
|
}
|
||||||
|
return {
|
||||||
|
add: r
|
||||||
|
};
|
||||||
|
};
|
||||||
|
console.log(new n().add("foo", 42));
|
||||||
|
}
|
||||||
|
expect_stdout: "42"
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
op_equals_left_local_var: {
|
op_equals_left_local_var: {
|
||||||
options = {
|
options = {
|
||||||
|
assignments: true,
|
||||||
evaluate: true,
|
evaluate: true,
|
||||||
}
|
}
|
||||||
input: {
|
input: {
|
||||||
@@ -60,6 +61,7 @@ op_equals_left_local_var: {
|
|||||||
|
|
||||||
op_equals_right_local_var: {
|
op_equals_right_local_var: {
|
||||||
options = {
|
options = {
|
||||||
|
assignments: true,
|
||||||
evaluate: true,
|
evaluate: true,
|
||||||
}
|
}
|
||||||
input: {
|
input: {
|
||||||
@@ -123,6 +125,7 @@ op_equals_right_local_var: {
|
|||||||
}
|
}
|
||||||
op_equals_left_global_var: {
|
op_equals_left_global_var: {
|
||||||
options = {
|
options = {
|
||||||
|
assignments: true,
|
||||||
evaluate: true,
|
evaluate: true,
|
||||||
}
|
}
|
||||||
input: {
|
input: {
|
||||||
@@ -179,6 +182,7 @@ op_equals_left_global_var: {
|
|||||||
|
|
||||||
op_equals_right_global_var: {
|
op_equals_right_global_var: {
|
||||||
options = {
|
options = {
|
||||||
|
assignments: true,
|
||||||
evaluate: true,
|
evaluate: true,
|
||||||
}
|
}
|
||||||
input: {
|
input: {
|
||||||
@@ -236,3 +240,170 @@ op_equals_right_global_var: {
|
|||||||
x = g() & x;
|
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_1: {
|
||||||
|
options = {
|
||||||
|
assignments: true,
|
||||||
|
reduce_vars: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
function p(o) {
|
||||||
|
console.log(typeof o, o);
|
||||||
|
}
|
||||||
|
p(function(b) {
|
||||||
|
var a = b += 1;
|
||||||
|
--b;
|
||||||
|
return a;
|
||||||
|
}("object"));
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
function p(o) {
|
||||||
|
console.log(typeof o, o);
|
||||||
|
}
|
||||||
|
p(function(b) {
|
||||||
|
var a = b += 1;
|
||||||
|
--b;
|
||||||
|
return a;
|
||||||
|
}("object"));
|
||||||
|
}
|
||||||
|
expect_stdout: "string object1"
|
||||||
|
}
|
||||||
|
|
||||||
|
issue_3375_2: {
|
||||||
|
options = {
|
||||||
|
assignments: true,
|
||||||
|
reduce_vars: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
function p(o) {
|
||||||
|
console.log(typeof o, o);
|
||||||
|
}
|
||||||
|
p(function(b) {
|
||||||
|
var a = b -= 1;
|
||||||
|
--b;
|
||||||
|
return a;
|
||||||
|
}("object"));
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
function p(o) {
|
||||||
|
console.log(typeof o, o);
|
||||||
|
}
|
||||||
|
p(function(b) {
|
||||||
|
var a = --b;
|
||||||
|
--b;
|
||||||
|
return a;
|
||||||
|
}("object"));
|
||||||
|
}
|
||||||
|
expect_stdout: "number NaN"
|
||||||
|
}
|
||||||
|
|
||||||
|
issue_3427: {
|
||||||
|
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"
|
||||||
|
}
|
||||||
|
|||||||
133
test/compress/booleans.js
Normal file
133
test/compress/booleans.js
Normal file
@@ -0,0 +1,133 @@
|
|||||||
|
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"
|
||||||
|
}
|
||||||
|
|
||||||
|
issue_2737_2: {
|
||||||
|
options = {
|
||||||
|
booleans: true,
|
||||||
|
inline: true,
|
||||||
|
reduce_vars: true,
|
||||||
|
unused: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
(function(bar) {
|
||||||
|
for (;bar();) break;
|
||||||
|
})(function qux() {
|
||||||
|
return console.log("PASS"), qux;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
(function(bar) {
|
||||||
|
for (;bar();) break;
|
||||||
|
})(function() {
|
||||||
|
return console.log("PASS"), 1;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
expect_stdout: "PASS"
|
||||||
|
}
|
||||||
|
|
||||||
|
issue_3658: {
|
||||||
|
options = {
|
||||||
|
booleans: true,
|
||||||
|
evaluate: true,
|
||||||
|
reduce_vars: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
console.log(function f() {
|
||||||
|
console || f();
|
||||||
|
return "PASS";
|
||||||
|
}());
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
console.log(function f() {
|
||||||
|
console || f();
|
||||||
|
return "PASS";
|
||||||
|
}());
|
||||||
|
}
|
||||||
|
expect_stdout: "PASS"
|
||||||
|
}
|
||||||
File diff suppressed because it is too large
Load Diff
@@ -33,10 +33,10 @@ unsafe_comps: {
|
|||||||
}
|
}
|
||||||
expect: {
|
expect: {
|
||||||
var obj1, obj2;
|
var obj1, obj2;
|
||||||
obj2 < obj1 ? g1() : f1();
|
(obj2 < obj1 ? g1 : f1)();
|
||||||
obj1 < obj2 ? f2() : g2();
|
(obj1 < obj2 ? f2 : g2)();
|
||||||
obj1 < obj2 ? g3() : f3();
|
(obj1 < obj2 ? g3 : f3)();
|
||||||
obj2 < obj1 ? f4() : g4();
|
(obj2 < obj1 ? f4 : g4)();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -295,3 +295,148 @@ issue_2857_6: {
|
|||||||
}
|
}
|
||||||
expect_stdout: "true"
|
expect_stdout: "true"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
is_boolean_unsafe: {
|
||||||
|
options = {
|
||||||
|
comparisons: true,
|
||||||
|
unsafe: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
console.log(/foo/.test("bar") === [].isPrototypeOf({}));
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
console.log(/foo/.test("bar") == [].isPrototypeOf({}));
|
||||||
|
}
|
||||||
|
expect_stdout: "true"
|
||||||
|
}
|
||||||
|
|
||||||
|
is_number_unsafe: {
|
||||||
|
options = {
|
||||||
|
comparisons: true,
|
||||||
|
unsafe: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
console.log(Math.acos(42) !== "foo".charCodeAt(4));
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
console.log(Math.acos(42) != "foo".charCodeAt(4));
|
||||||
|
}
|
||||||
|
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"
|
||||||
|
}
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
concat_1: {
|
concat_1: {
|
||||||
options = {
|
options = {
|
||||||
evaluate: true
|
evaluate: true,
|
||||||
};
|
}
|
||||||
input: {
|
input: {
|
||||||
var a = "foo" + "bar" + x() + "moo" + "foo" + y() + "x" + "y" + "z" + q();
|
var a = "foo" + "bar" + x() + "moo" + "foo" + y() + "x" + "y" + "z" + q();
|
||||||
var b = "foo" + 1 + x() + 2 + "boo";
|
var b = "foo" + 1 + x() + 2 + "boo";
|
||||||
@@ -26,7 +26,7 @@ concat_1: {
|
|||||||
}
|
}
|
||||||
|
|
||||||
concat_2: {
|
concat_2: {
|
||||||
options = {};
|
options = {}
|
||||||
input: {
|
input: {
|
||||||
console.log(
|
console.log(
|
||||||
1 + (2 + 3),
|
1 + (2 + 3),
|
||||||
@@ -55,7 +55,7 @@ concat_2: {
|
|||||||
}
|
}
|
||||||
|
|
||||||
concat_3: {
|
concat_3: {
|
||||||
options = {};
|
options = {}
|
||||||
input: {
|
input: {
|
||||||
console.log(
|
console.log(
|
||||||
1 + 2 + (3 + 4 + 5),
|
1 + 2 + (3 + 4 + 5),
|
||||||
@@ -84,7 +84,7 @@ concat_3: {
|
|||||||
}
|
}
|
||||||
|
|
||||||
concat_4: {
|
concat_4: {
|
||||||
options = {};
|
options = {}
|
||||||
input: {
|
input: {
|
||||||
console.log(
|
console.log(
|
||||||
1 + "2" + (3 + 4 + 5),
|
1 + "2" + (3 + 4 + 5),
|
||||||
@@ -113,7 +113,7 @@ concat_4: {
|
|||||||
}
|
}
|
||||||
|
|
||||||
concat_5: {
|
concat_5: {
|
||||||
options = {};
|
options = {}
|
||||||
input: {
|
input: {
|
||||||
console.log(
|
console.log(
|
||||||
"1" + 2 + (3 + 4 + 5),
|
"1" + 2 + (3 + 4 + 5),
|
||||||
@@ -142,7 +142,7 @@ concat_5: {
|
|||||||
}
|
}
|
||||||
|
|
||||||
concat_6: {
|
concat_6: {
|
||||||
options = {};
|
options = {}
|
||||||
input: {
|
input: {
|
||||||
console.log(
|
console.log(
|
||||||
"1" + "2" + (3 + 4 + 5),
|
"1" + "2" + (3 + 4 + 5),
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
ifs_1: {
|
ifs_1: {
|
||||||
options = {
|
options = {
|
||||||
conditionals: true
|
conditionals: true,
|
||||||
};
|
}
|
||||||
input: {
|
input: {
|
||||||
if (foo) bar();
|
if (foo) bar();
|
||||||
if (!foo); else bar();
|
if (!foo); else bar();
|
||||||
@@ -18,8 +18,8 @@ ifs_1: {
|
|||||||
|
|
||||||
ifs_2: {
|
ifs_2: {
|
||||||
options = {
|
options = {
|
||||||
conditionals: true
|
conditionals: true,
|
||||||
};
|
}
|
||||||
input: {
|
input: {
|
||||||
if (foo) {
|
if (foo) {
|
||||||
x();
|
x();
|
||||||
@@ -41,18 +41,18 @@ ifs_2: {
|
|||||||
}
|
}
|
||||||
expect: {
|
expect: {
|
||||||
foo ? x() : bar ? y() : baz && z();
|
foo ? x() : bar ? y() : baz && z();
|
||||||
foo ? x() : bar ? y() : baz ? z() : t();
|
(foo ? x : bar ? y : baz ? z : t)();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ifs_3_should_warn: {
|
ifs_3_should_warn: {
|
||||||
options = {
|
options = {
|
||||||
conditionals : true,
|
booleans: true,
|
||||||
dead_code : true,
|
conditionals: true,
|
||||||
evaluate : true,
|
dead_code: true,
|
||||||
booleans : true,
|
evaluate: true,
|
||||||
side_effects : true,
|
side_effects: true,
|
||||||
};
|
}
|
||||||
input: {
|
input: {
|
||||||
var x, y;
|
var x, y;
|
||||||
if (x && !(x + "1") && y) { // 1
|
if (x && !(x + "1") && y) { // 1
|
||||||
@@ -78,8 +78,8 @@ ifs_3_should_warn: {
|
|||||||
|
|
||||||
ifs_4: {
|
ifs_4: {
|
||||||
options = {
|
options = {
|
||||||
conditionals: true
|
conditionals: true,
|
||||||
};
|
}
|
||||||
input: {
|
input: {
|
||||||
if (foo && bar) {
|
if (foo && bar) {
|
||||||
x(foo)[10].bar.baz = something();
|
x(foo)[10].bar.baz = something();
|
||||||
@@ -95,10 +95,10 @@ ifs_4: {
|
|||||||
|
|
||||||
ifs_5: {
|
ifs_5: {
|
||||||
options = {
|
options = {
|
||||||
if_return: true,
|
|
||||||
conditionals: true,
|
|
||||||
comparisons: true,
|
comparisons: true,
|
||||||
};
|
conditionals: true,
|
||||||
|
if_return: true,
|
||||||
|
}
|
||||||
input: {
|
input: {
|
||||||
function f() {
|
function f() {
|
||||||
if (foo) return;
|
if (foo) return;
|
||||||
@@ -132,9 +132,9 @@ ifs_5: {
|
|||||||
|
|
||||||
ifs_6: {
|
ifs_6: {
|
||||||
options = {
|
options = {
|
||||||
|
comparisons: true,
|
||||||
conditionals: true,
|
conditionals: true,
|
||||||
comparisons: true
|
}
|
||||||
};
|
|
||||||
input: {
|
input: {
|
||||||
var x, y;
|
var x, y;
|
||||||
if (!foo && !bar && !baz && !boo) {
|
if (!foo && !bar && !baz && !boo) {
|
||||||
@@ -161,10 +161,28 @@ ifs_6: {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ifs_7: {
|
||||||
|
options = {
|
||||||
|
conditionals: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
if (A); else;
|
||||||
|
if (A) while (B); else;
|
||||||
|
if (A); else while (C);
|
||||||
|
if (A) while (B); else while (C);
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
A;
|
||||||
|
if (A) while (B);
|
||||||
|
if (!A) while (C);
|
||||||
|
if (A) while (B); else while (C);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
cond_1: {
|
cond_1: {
|
||||||
options = {
|
options = {
|
||||||
conditionals: true
|
conditionals: true,
|
||||||
};
|
}
|
||||||
input: {
|
input: {
|
||||||
function foo(do_something, some_condition) {
|
function foo(do_something, some_condition) {
|
||||||
if (some_condition) {
|
if (some_condition) {
|
||||||
@@ -189,8 +207,8 @@ cond_1: {
|
|||||||
|
|
||||||
cond_2: {
|
cond_2: {
|
||||||
options = {
|
options = {
|
||||||
conditionals: true
|
conditionals: true,
|
||||||
};
|
}
|
||||||
input: {
|
input: {
|
||||||
function foo(x, FooBar, some_condition) {
|
function foo(x, FooBar, some_condition) {
|
||||||
if (some_condition) {
|
if (some_condition) {
|
||||||
@@ -209,8 +227,8 @@ cond_2: {
|
|||||||
|
|
||||||
cond_3: {
|
cond_3: {
|
||||||
options = {
|
options = {
|
||||||
conditionals: true
|
conditionals: true,
|
||||||
};
|
}
|
||||||
input: {
|
input: {
|
||||||
var FooBar;
|
var FooBar;
|
||||||
if (some_condition()) {
|
if (some_condition()) {
|
||||||
@@ -227,8 +245,8 @@ cond_3: {
|
|||||||
|
|
||||||
cond_4: {
|
cond_4: {
|
||||||
options = {
|
options = {
|
||||||
conditionals: true
|
conditionals: true,
|
||||||
};
|
}
|
||||||
input: {
|
input: {
|
||||||
var do_something;
|
var do_something;
|
||||||
if (some_condition()) {
|
if (some_condition()) {
|
||||||
@@ -251,8 +269,8 @@ cond_4: {
|
|||||||
|
|
||||||
cond_5: {
|
cond_5: {
|
||||||
options = {
|
options = {
|
||||||
conditionals: true
|
conditionals: true,
|
||||||
};
|
}
|
||||||
input: {
|
input: {
|
||||||
if (some_condition()) {
|
if (some_condition()) {
|
||||||
if (some_other_condition()) {
|
if (some_other_condition()) {
|
||||||
@@ -271,7 +289,7 @@ cond_5: {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
expect: {
|
expect: {
|
||||||
some_condition() && some_other_condition() ? do_something() : alternate();
|
(some_condition() && some_other_condition() ? do_something : alternate)();
|
||||||
some_condition() && some_other_condition() && do_something();
|
some_condition() && some_other_condition() && do_something();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -279,9 +297,9 @@ cond_5: {
|
|||||||
cond_7: {
|
cond_7: {
|
||||||
options = {
|
options = {
|
||||||
conditionals: true,
|
conditionals: true,
|
||||||
evaluate : true,
|
evaluate: true,
|
||||||
side_effects: true,
|
side_effects: true,
|
||||||
};
|
}
|
||||||
input: {
|
input: {
|
||||||
var x, y, z, a, b;
|
var x, y, z, a, b;
|
||||||
// compress these
|
// compress these
|
||||||
@@ -342,8 +360,8 @@ cond_7: {
|
|||||||
cond_7_1: {
|
cond_7_1: {
|
||||||
options = {
|
options = {
|
||||||
conditionals: true,
|
conditionals: true,
|
||||||
evaluate : true
|
evaluate: true,
|
||||||
};
|
}
|
||||||
input: {
|
input: {
|
||||||
var x;
|
var x;
|
||||||
// access to global should be assumed to have side effects
|
// access to global should be assumed to have side effects
|
||||||
@@ -361,10 +379,10 @@ cond_7_1: {
|
|||||||
|
|
||||||
cond_8: {
|
cond_8: {
|
||||||
options = {
|
options = {
|
||||||
|
booleans: false,
|
||||||
conditionals: true,
|
conditionals: true,
|
||||||
evaluate : true,
|
evaluate: true,
|
||||||
booleans : false
|
}
|
||||||
};
|
|
||||||
input: {
|
input: {
|
||||||
var a;
|
var a;
|
||||||
// compress these
|
// compress these
|
||||||
@@ -445,10 +463,10 @@ cond_8: {
|
|||||||
|
|
||||||
cond_8b: {
|
cond_8b: {
|
||||||
options = {
|
options = {
|
||||||
|
booleans: true,
|
||||||
conditionals: true,
|
conditionals: true,
|
||||||
evaluate : true,
|
evaluate: true,
|
||||||
booleans : true
|
}
|
||||||
};
|
|
||||||
input: {
|
input: {
|
||||||
var a;
|
var a;
|
||||||
// compress these
|
// compress these
|
||||||
@@ -528,10 +546,10 @@ cond_8b: {
|
|||||||
|
|
||||||
cond_8c: {
|
cond_8c: {
|
||||||
options = {
|
options = {
|
||||||
|
booleans: false,
|
||||||
conditionals: true,
|
conditionals: true,
|
||||||
evaluate : false,
|
evaluate: false,
|
||||||
booleans : false
|
}
|
||||||
};
|
|
||||||
input: {
|
input: {
|
||||||
var a;
|
var a;
|
||||||
// compress these
|
// compress these
|
||||||
@@ -645,11 +663,86 @@ cond_9: {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
cond_10: {
|
||||||
|
options = {
|
||||||
|
conditionals: true,
|
||||||
|
if_return: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
function f(a) {
|
||||||
|
if (1 == a) return "foo";
|
||||||
|
if (2 == a) return "foo";
|
||||||
|
if (3 == a) return "foo";
|
||||||
|
if (4 == a) return 42;
|
||||||
|
if (5 == a) return "foo";
|
||||||
|
if (6 == a) return "foo";
|
||||||
|
return "bar";
|
||||||
|
}
|
||||||
|
console.log(f(1), f(2), f(3), f(4), f(5), f(6), f(7));
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
function f(a) {
|
||||||
|
return 1 == a || 2 == a || 3 == a ? "foo" : 4 == a ? 42 : 5 == a || 6 == a ? "foo" : "bar";
|
||||||
|
}
|
||||||
|
console.log(f(1), f(2), f(3), f(4), f(5), f(6), f(7));
|
||||||
|
}
|
||||||
|
expect_stdout: "foo foo foo 42 foo foo bar"
|
||||||
|
}
|
||||||
|
|
||||||
|
cond_11: {
|
||||||
|
options = {
|
||||||
|
conditionals: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
var o = {
|
||||||
|
p: "foo",
|
||||||
|
q: function() {
|
||||||
|
return this.p;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
function f() {
|
||||||
|
return "bar";
|
||||||
|
}
|
||||||
|
function g(a) {
|
||||||
|
return a ? f() : o.q();
|
||||||
|
}
|
||||||
|
console.log(g(0), g(1));
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
var o = {
|
||||||
|
p: "foo",
|
||||||
|
q: function() {
|
||||||
|
return this.p;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
function f() {
|
||||||
|
return "bar";
|
||||||
|
}
|
||||||
|
function g(a) {
|
||||||
|
return a ? f() : o.q();
|
||||||
|
}
|
||||||
|
console.log(g(0), g(1));
|
||||||
|
}
|
||||||
|
expect_stdout: "foo bar"
|
||||||
|
}
|
||||||
|
|
||||||
ternary_boolean_consequent: {
|
ternary_boolean_consequent: {
|
||||||
options = {
|
options = {
|
||||||
collapse_vars:true, sequences:true, properties:true, dead_code:true, conditionals:true,
|
booleans: true,
|
||||||
comparisons:true, evaluate:true, booleans:true, loops:true, unused:true, hoist_funs:true,
|
collapse_vars: true,
|
||||||
keep_fargs:true, if_return:true, join_vars:true, side_effects:true
|
comparisons: true,
|
||||||
|
conditionals: true,
|
||||||
|
dead_code: true,
|
||||||
|
evaluate: true,
|
||||||
|
hoist_funs: true,
|
||||||
|
if_return: true,
|
||||||
|
join_vars: true,
|
||||||
|
keep_fargs: true,
|
||||||
|
loops: true,
|
||||||
|
properties: true,
|
||||||
|
sequences: true,
|
||||||
|
side_effects: true,
|
||||||
|
unused: true,
|
||||||
}
|
}
|
||||||
input: {
|
input: {
|
||||||
function f1() { return a == b ? true : x; }
|
function f1() { return a == b ? true : x; }
|
||||||
@@ -675,9 +768,21 @@ ternary_boolean_consequent: {
|
|||||||
|
|
||||||
ternary_boolean_alternative: {
|
ternary_boolean_alternative: {
|
||||||
options = {
|
options = {
|
||||||
collapse_vars:true, sequences:true, properties:true, dead_code:true, conditionals:true,
|
booleans: true,
|
||||||
comparisons:true, evaluate:true, booleans:true, loops:true, unused:true, hoist_funs:true,
|
collapse_vars: true,
|
||||||
keep_fargs:true, if_return:true, join_vars:true, side_effects:true
|
comparisons: true,
|
||||||
|
conditionals: true,
|
||||||
|
dead_code: true,
|
||||||
|
evaluate: true,
|
||||||
|
hoist_funs: true,
|
||||||
|
if_return: true,
|
||||||
|
join_vars: true,
|
||||||
|
keep_fargs: true,
|
||||||
|
loops: true,
|
||||||
|
properties: true,
|
||||||
|
sequences: true,
|
||||||
|
side_effects: true,
|
||||||
|
unused: true,
|
||||||
}
|
}
|
||||||
input: {
|
input: {
|
||||||
function f1() { return a == b ? x : true; }
|
function f1() { return a == b ? x : true; }
|
||||||
@@ -778,11 +883,11 @@ trivial_boolean_ternary_expressions : {
|
|||||||
|
|
||||||
issue_1154: {
|
issue_1154: {
|
||||||
options = {
|
options = {
|
||||||
|
booleans: true,
|
||||||
conditionals: true,
|
conditionals: true,
|
||||||
evaluate : true,
|
evaluate: true,
|
||||||
booleans : true,
|
|
||||||
side_effects: true,
|
side_effects: true,
|
||||||
};
|
}
|
||||||
input: {
|
input: {
|
||||||
function f1(x) { return x ? -1 : -1; }
|
function f1(x) { return x ? -1 : -1; }
|
||||||
function f2(x) { return x ? +2 : +2; }
|
function f2(x) { return x ? +2 : +2; }
|
||||||
@@ -818,7 +923,7 @@ issue_1154: {
|
|||||||
no_evaluate: {
|
no_evaluate: {
|
||||||
options = {
|
options = {
|
||||||
conditionals: true,
|
conditionals: true,
|
||||||
evaluate : false,
|
evaluate: false,
|
||||||
side_effects: true,
|
side_effects: true,
|
||||||
}
|
}
|
||||||
input: {
|
input: {
|
||||||
@@ -1268,3 +1373,239 @@ to_and_or: {
|
|||||||
}
|
}
|
||||||
expect_stdout: true
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
issue_3576: {
|
||||||
|
options = {
|
||||||
|
conditionals: true,
|
||||||
|
evaluate: true,
|
||||||
|
pure_getters: "strict",
|
||||||
|
reduce_vars: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
var c = "FAIL";
|
||||||
|
(function(a) {
|
||||||
|
(a = -1) ? (a && (a.a = 0)) : (a && (a.a = 0));
|
||||||
|
a && a[c = "PASS"]++;
|
||||||
|
})();
|
||||||
|
console.log(c);
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
var c = "FAIL";
|
||||||
|
(function(a) {
|
||||||
|
a = -1, a, a.a = 0;
|
||||||
|
a, a[c = "PASS"]++;
|
||||||
|
})();
|
||||||
|
console.log(c);
|
||||||
|
}
|
||||||
|
expect_stdout: "PASS"
|
||||||
|
}
|
||||||
|
|
||||||
|
issue_3668: {
|
||||||
|
options = {
|
||||||
|
conditionals: true,
|
||||||
|
if_return: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
function f() {
|
||||||
|
try {
|
||||||
|
var undefined = typeof f;
|
||||||
|
if (!f) return undefined;
|
||||||
|
return;
|
||||||
|
} catch (e) {
|
||||||
|
return "FAIL";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
console.log(f());
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
function f() {
|
||||||
|
try {
|
||||||
|
var undefined = typeof f;
|
||||||
|
return f ? void 0 : undefined;
|
||||||
|
} catch (e) {
|
||||||
|
return "FAIL";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
console.log(f());
|
||||||
|
}
|
||||||
|
expect_stdout: "undefined"
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
dead_code_1: {
|
dead_code_1: {
|
||||||
options = {
|
options = {
|
||||||
dead_code: true
|
dead_code: true,
|
||||||
};
|
}
|
||||||
input: {
|
input: {
|
||||||
function f() {
|
function f() {
|
||||||
a();
|
a();
|
||||||
@@ -25,8 +25,8 @@ dead_code_1: {
|
|||||||
|
|
||||||
dead_code_2_should_warn: {
|
dead_code_2_should_warn: {
|
||||||
options = {
|
options = {
|
||||||
dead_code: true
|
dead_code: true,
|
||||||
};
|
}
|
||||||
input: {
|
input: {
|
||||||
function f() {
|
function f() {
|
||||||
g();
|
g();
|
||||||
@@ -64,13 +64,13 @@ dead_code_2_should_warn: {
|
|||||||
|
|
||||||
dead_code_constant_boolean_should_warn_more: {
|
dead_code_constant_boolean_should_warn_more: {
|
||||||
options = {
|
options = {
|
||||||
dead_code : true,
|
booleans: true,
|
||||||
loops : true,
|
conditionals: true,
|
||||||
booleans : true,
|
dead_code: true,
|
||||||
conditionals : true,
|
evaluate: true,
|
||||||
evaluate : true,
|
loops: true,
|
||||||
side_effects : true,
|
side_effects: true,
|
||||||
};
|
}
|
||||||
input: {
|
input: {
|
||||||
while (!((foo && bar) || (x + "0"))) {
|
while (!((foo && bar) || (x + "0"))) {
|
||||||
console.log("unreachable");
|
console.log("unreachable");
|
||||||
@@ -141,207 +141,6 @@ try_catch_finally: {
|
|||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
accessor: {
|
|
||||||
options = {
|
|
||||||
side_effects: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
({
|
|
||||||
get a() {},
|
|
||||||
set a(v){
|
|
||||||
this.b = 2;
|
|
||||||
},
|
|
||||||
b: 1
|
|
||||||
});
|
|
||||||
}
|
|
||||||
expect: {}
|
|
||||||
}
|
|
||||||
|
|
||||||
issue_2233_1: {
|
|
||||||
options = {
|
|
||||||
pure_getters: "strict",
|
|
||||||
side_effects: true,
|
|
||||||
unsafe: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
Array.isArray;
|
|
||||||
Boolean;
|
|
||||||
console.log;
|
|
||||||
Date;
|
|
||||||
decodeURI;
|
|
||||||
decodeURIComponent;
|
|
||||||
encodeURI;
|
|
||||||
encodeURIComponent;
|
|
||||||
Error.name;
|
|
||||||
escape;
|
|
||||||
eval;
|
|
||||||
EvalError;
|
|
||||||
Function.length;
|
|
||||||
isFinite;
|
|
||||||
isNaN;
|
|
||||||
JSON;
|
|
||||||
Math.random;
|
|
||||||
Number.isNaN;
|
|
||||||
parseFloat;
|
|
||||||
parseInt;
|
|
||||||
RegExp;
|
|
||||||
Object.defineProperty;
|
|
||||||
String.fromCharCode;
|
|
||||||
RangeError;
|
|
||||||
ReferenceError;
|
|
||||||
SyntaxError;
|
|
||||||
TypeError;
|
|
||||||
unescape;
|
|
||||||
URIError;
|
|
||||||
}
|
|
||||||
expect: {}
|
|
||||||
expect_stdout: true
|
|
||||||
}
|
|
||||||
|
|
||||||
global_timeout_and_interval_symbols: {
|
|
||||||
options = {
|
|
||||||
pure_getters: "strict",
|
|
||||||
side_effects: true,
|
|
||||||
unsafe: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
// These global symbols do not exist in the test sandbox
|
|
||||||
// and must be tested separately.
|
|
||||||
clearInterval;
|
|
||||||
clearTimeout;
|
|
||||||
setInterval;
|
|
||||||
setTimeout;
|
|
||||||
}
|
|
||||||
expect: {}
|
|
||||||
}
|
|
||||||
|
|
||||||
issue_2233_2: {
|
|
||||||
options = {
|
|
||||||
pure_getters: "strict",
|
|
||||||
reduce_funcs: true,
|
|
||||||
reduce_vars: true,
|
|
||||||
side_effects: true,
|
|
||||||
unsafe: true,
|
|
||||||
unused: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
var RegExp;
|
|
||||||
Array.isArray;
|
|
||||||
RegExp;
|
|
||||||
UndeclaredGlobal;
|
|
||||||
function foo() {
|
|
||||||
var Number;
|
|
||||||
AnotherUndeclaredGlobal;
|
|
||||||
Math.sin;
|
|
||||||
Number.isNaN;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
var RegExp;
|
|
||||||
UndeclaredGlobal;
|
|
||||||
function foo() {
|
|
||||||
var Number;
|
|
||||||
AnotherUndeclaredGlobal;
|
|
||||||
Number.isNaN;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
issue_2233_3: {
|
|
||||||
options = {
|
|
||||||
pure_getters: "strict",
|
|
||||||
reduce_funcs: true,
|
|
||||||
reduce_vars: true,
|
|
||||||
side_effects: true,
|
|
||||||
toplevel: true,
|
|
||||||
unsafe: true,
|
|
||||||
unused: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
var RegExp;
|
|
||||||
Array.isArray;
|
|
||||||
RegExp;
|
|
||||||
UndeclaredGlobal;
|
|
||||||
function foo() {
|
|
||||||
var Number;
|
|
||||||
AnotherUndeclaredGlobal;
|
|
||||||
Math.sin;
|
|
||||||
Number.isNaN;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
UndeclaredGlobal;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
global_fns: {
|
|
||||||
options = {
|
|
||||||
side_effects: true,
|
|
||||||
unsafe: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
Boolean(1, 2);
|
|
||||||
decodeURI(1, 2);
|
|
||||||
decodeURIComponent(1, 2);
|
|
||||||
Date(1, 2);
|
|
||||||
encodeURI(1, 2);
|
|
||||||
encodeURIComponent(1, 2);
|
|
||||||
Error(1, 2);
|
|
||||||
escape(1, 2);
|
|
||||||
EvalError(1, 2);
|
|
||||||
isFinite(1, 2);
|
|
||||||
isNaN(1, 2);
|
|
||||||
Number(1, 2);
|
|
||||||
Object(1, 2);
|
|
||||||
parseFloat(1, 2);
|
|
||||||
parseInt(1, 2);
|
|
||||||
RangeError(1, 2);
|
|
||||||
ReferenceError(1, 2);
|
|
||||||
String(1, 2);
|
|
||||||
SyntaxError(1, 2);
|
|
||||||
TypeError(1, 2);
|
|
||||||
unescape(1, 2);
|
|
||||||
URIError(1, 2);
|
|
||||||
try {
|
|
||||||
Function(1, 2);
|
|
||||||
} catch (e) {
|
|
||||||
console.log(e.name);
|
|
||||||
}
|
|
||||||
try {
|
|
||||||
RegExp(1, 2);
|
|
||||||
} catch (e) {
|
|
||||||
console.log(e.name);
|
|
||||||
}
|
|
||||||
try {
|
|
||||||
Array(NaN);
|
|
||||||
} catch (e) {
|
|
||||||
console.log(e.name);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
try {
|
|
||||||
Function(1, 2);
|
|
||||||
} catch (e) {
|
|
||||||
console.log(e.name);
|
|
||||||
}
|
|
||||||
try {
|
|
||||||
RegExp(1, 2);
|
|
||||||
} catch (e) {
|
|
||||||
console.log(e.name);
|
|
||||||
}
|
|
||||||
try {
|
|
||||||
Array(NaN);
|
|
||||||
} catch (e) {
|
|
||||||
console.log(e.name);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
expect_stdout: [
|
|
||||||
"SyntaxError",
|
|
||||||
"SyntaxError",
|
|
||||||
"RangeError",
|
|
||||||
]
|
|
||||||
}
|
|
||||||
|
|
||||||
collapse_vars_assignment: {
|
collapse_vars_assignment: {
|
||||||
options = {
|
options = {
|
||||||
collapse_vars: true,
|
collapse_vars: true,
|
||||||
@@ -863,23 +662,6 @@ issue_2749: {
|
|||||||
expect_stdout: "PASS"
|
expect_stdout: "PASS"
|
||||||
}
|
}
|
||||||
|
|
||||||
unsafe_builtin: {
|
|
||||||
options = {
|
|
||||||
side_effects: true,
|
|
||||||
unsafe: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
(!w).constructor(x);
|
|
||||||
Math.abs(y);
|
|
||||||
[ 1, 2, z ].valueOf();
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
w, x;
|
|
||||||
y;
|
|
||||||
z;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
issue_2860_1: {
|
issue_2860_1: {
|
||||||
options = {
|
options = {
|
||||||
dead_code: true,
|
dead_code: true,
|
||||||
@@ -892,9 +674,7 @@ issue_2860_1: {
|
|||||||
}());
|
}());
|
||||||
}
|
}
|
||||||
expect: {
|
expect: {
|
||||||
console.log(function(a) {
|
console.log(1);
|
||||||
return 1 ^ a;
|
|
||||||
}());
|
|
||||||
}
|
}
|
||||||
expect_stdout: "1"
|
expect_stdout: "1"
|
||||||
}
|
}
|
||||||
@@ -942,3 +722,172 @@ issue_2929: {
|
|||||||
}
|
}
|
||||||
expect_stdout: "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"
|
||||||
|
}
|
||||||
|
|
||||||
|
unreachable_assign: {
|
||||||
|
options = {
|
||||||
|
dead_code: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
console.log(A = "P" + (A = "A" + (B = "S" + (A = B = "S"))), A, B);
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
console.log(A = "P" + "A" + (B = "S" + "S"), A, B);
|
||||||
|
}
|
||||||
|
expect_stdout: "PASS PASS SS"
|
||||||
|
}
|
||||||
|
|
||||||
|
catch_return_assign: {
|
||||||
|
options = {
|
||||||
|
dead_code: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
console.log(function() {
|
||||||
|
try {
|
||||||
|
throw "FAIL";
|
||||||
|
} catch (e) {
|
||||||
|
return e = "PASS";
|
||||||
|
}
|
||||||
|
}());
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
console.log(function() {
|
||||||
|
try {
|
||||||
|
throw "FAIL";
|
||||||
|
} catch (e) {
|
||||||
|
return "PASS";
|
||||||
|
}
|
||||||
|
}());
|
||||||
|
}
|
||||||
|
expect_stdout: "PASS"
|
||||||
|
}
|
||||||
|
|
||||||
|
issue_3578: {
|
||||||
|
options = {
|
||||||
|
dead_code: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
var a = "FAIL", b, c;
|
||||||
|
try {
|
||||||
|
b = c.p = b = 0;
|
||||||
|
} catch (e) {
|
||||||
|
b += 42;
|
||||||
|
b && (a = "PASS");
|
||||||
|
}
|
||||||
|
console.log(a);
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
var a = "FAIL", b, c;
|
||||||
|
try {
|
||||||
|
b = c.p = b = 0;
|
||||||
|
} catch (e) {
|
||||||
|
b += 42;
|
||||||
|
b && (a = "PASS");
|
||||||
|
}
|
||||||
|
console.log(a);
|
||||||
|
}
|
||||||
|
expect_stdout: "PASS"
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
keep_debugger: {
|
keep_debugger: {
|
||||||
options = {
|
options = {
|
||||||
drop_debugger: false
|
drop_debugger: false,
|
||||||
};
|
}
|
||||||
input: {
|
input: {
|
||||||
debugger;
|
debugger;
|
||||||
}
|
}
|
||||||
@@ -12,8 +12,8 @@ keep_debugger: {
|
|||||||
|
|
||||||
drop_debugger: {
|
drop_debugger: {
|
||||||
options = {
|
options = {
|
||||||
drop_debugger: true
|
drop_debugger: true,
|
||||||
};
|
}
|
||||||
input: {
|
input: {
|
||||||
debugger;
|
debugger;
|
||||||
if (foo) debugger;
|
if (foo) debugger;
|
||||||
|
|||||||
133
test/compress/directives.js
Normal file
133
test/compress/directives.js
Normal file
@@ -0,0 +1,133 @@
|
|||||||
|
simple_statement_is_not_a_directive: {
|
||||||
|
input: {
|
||||||
|
"use strict"
|
||||||
|
.split(" ")
|
||||||
|
.forEach(function(s) {
|
||||||
|
console.log(s);
|
||||||
|
});
|
||||||
|
console.log(!this); // is strict mode?
|
||||||
|
(function() {
|
||||||
|
"directive"
|
||||||
|
""
|
||||||
|
"use strict"
|
||||||
|
"hello world"
|
||||||
|
.split(" ")
|
||||||
|
.forEach(function(s) {
|
||||||
|
console.log(s);
|
||||||
|
});
|
||||||
|
console.log(!this); // is strict mode?
|
||||||
|
})();
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
"use strict".split(" ").forEach(function(s) {
|
||||||
|
console.log(s);
|
||||||
|
});
|
||||||
|
console.log(!this);
|
||||||
|
(function() {
|
||||||
|
"directive";
|
||||||
|
"";
|
||||||
|
"use strict";
|
||||||
|
"hello world".split(" ").forEach(function(s) {
|
||||||
|
console.log(s);
|
||||||
|
});
|
||||||
|
console.log(!this);
|
||||||
|
})();
|
||||||
|
}
|
||||||
|
expect_stdout: [
|
||||||
|
"use",
|
||||||
|
"strict",
|
||||||
|
"false",
|
||||||
|
"hello",
|
||||||
|
"world",
|
||||||
|
"true",
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
|
drop_lone_use_strict: {
|
||||||
|
options = {
|
||||||
|
directives: true,
|
||||||
|
side_effects: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
function f1() {
|
||||||
|
"use strict";
|
||||||
|
}
|
||||||
|
function f2() {
|
||||||
|
"use strict";
|
||||||
|
function f3() {
|
||||||
|
"use strict";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
(function f4() {
|
||||||
|
"use strict";
|
||||||
|
})();
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
function f1() {
|
||||||
|
}
|
||||||
|
function f2() {
|
||||||
|
"use strict";
|
||||||
|
function f3() {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
issue_3166: {
|
||||||
|
options = {
|
||||||
|
directives: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
"foo";
|
||||||
|
"use strict";
|
||||||
|
function f() {
|
||||||
|
"use strict";
|
||||||
|
"bar";
|
||||||
|
"use asm";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
"use strict";
|
||||||
|
function f() {
|
||||||
|
"use asm";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
valid_after_invalid_1: {
|
||||||
|
input: {
|
||||||
|
console.log(typeof function() {
|
||||||
|
"use\x20strict";
|
||||||
|
"use strict";
|
||||||
|
return this;
|
||||||
|
}());
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
console.log(typeof function() {
|
||||||
|
"use\x20strict";
|
||||||
|
"use strict";
|
||||||
|
return this;
|
||||||
|
}());
|
||||||
|
}
|
||||||
|
expect_stdout: "undefined"
|
||||||
|
}
|
||||||
|
|
||||||
|
valid_after_invalid_2: {
|
||||||
|
options = {
|
||||||
|
directives: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
console.log(typeof function() {
|
||||||
|
"use\x20strict";
|
||||||
|
"use strict";
|
||||||
|
return this;
|
||||||
|
}());
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
console.log(typeof function() {
|
||||||
|
"use strict";
|
||||||
|
return this;
|
||||||
|
}());
|
||||||
|
}
|
||||||
|
expect_stdout: "undefined"
|
||||||
|
}
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
drop_console_1: {
|
drop_console_1: {
|
||||||
options = {};
|
options = {}
|
||||||
input: {
|
input: {
|
||||||
console.log('foo');
|
console.log('foo');
|
||||||
console.log.apply(console, arguments);
|
console.log.apply(console, arguments);
|
||||||
@@ -11,7 +11,9 @@ drop_console_1: {
|
|||||||
}
|
}
|
||||||
|
|
||||||
drop_console_2: {
|
drop_console_2: {
|
||||||
options = { drop_console: true };
|
options = {
|
||||||
|
drop_console: true,
|
||||||
|
}
|
||||||
input: {
|
input: {
|
||||||
console.log('foo');
|
console.log('foo');
|
||||||
console.log.apply(console, arguments);
|
console.log.apply(console, arguments);
|
||||||
|
|||||||
@@ -1,5 +1,8 @@
|
|||||||
unused_funarg_1: {
|
unused_funarg_1: {
|
||||||
options = { unused: true, keep_fargs: false };
|
options = {
|
||||||
|
keep_fargs: false,
|
||||||
|
unused: true,
|
||||||
|
}
|
||||||
input: {
|
input: {
|
||||||
function f(a, b, c, d, e) {
|
function f(a, b, c, d, e) {
|
||||||
return a + b;
|
return a + b;
|
||||||
@@ -13,7 +16,10 @@ unused_funarg_1: {
|
|||||||
}
|
}
|
||||||
|
|
||||||
unused_funarg_2: {
|
unused_funarg_2: {
|
||||||
options = { unused: true, keep_fargs: false };
|
options = {
|
||||||
|
keep_fargs: false,
|
||||||
|
unused: true,
|
||||||
|
}
|
||||||
input: {
|
input: {
|
||||||
function f(a, b, c, d, e) {
|
function f(a, b, c, d, e) {
|
||||||
return a + c;
|
return a + c;
|
||||||
@@ -27,7 +33,9 @@ unused_funarg_2: {
|
|||||||
}
|
}
|
||||||
|
|
||||||
unused_nested_function: {
|
unused_nested_function: {
|
||||||
options = { unused: true };
|
options = {
|
||||||
|
unused: true,
|
||||||
|
}
|
||||||
input: {
|
input: {
|
||||||
function f(x, y) {
|
function f(x, y) {
|
||||||
function g() {
|
function g() {
|
||||||
@@ -44,7 +52,9 @@ unused_nested_function: {
|
|||||||
}
|
}
|
||||||
|
|
||||||
unused_circular_references_1: {
|
unused_circular_references_1: {
|
||||||
options = { unused: true };
|
options = {
|
||||||
|
unused: true,
|
||||||
|
}
|
||||||
input: {
|
input: {
|
||||||
function f(x, y) {
|
function f(x, y) {
|
||||||
// circular reference
|
// circular reference
|
||||||
@@ -65,7 +75,9 @@ unused_circular_references_1: {
|
|||||||
}
|
}
|
||||||
|
|
||||||
unused_circular_references_2: {
|
unused_circular_references_2: {
|
||||||
options = { unused: true };
|
options = {
|
||||||
|
unused: true,
|
||||||
|
}
|
||||||
input: {
|
input: {
|
||||||
function f(x, y) {
|
function f(x, y) {
|
||||||
var foo = 1, bar = baz, baz = foo + bar, qwe = moo();
|
var foo = 1, bar = baz, baz = foo + bar, qwe = moo();
|
||||||
@@ -81,7 +93,9 @@ unused_circular_references_2: {
|
|||||||
}
|
}
|
||||||
|
|
||||||
unused_circular_references_3: {
|
unused_circular_references_3: {
|
||||||
options = { unused: true };
|
options = {
|
||||||
|
unused: true,
|
||||||
|
}
|
||||||
input: {
|
input: {
|
||||||
function f(x, y) {
|
function f(x, y) {
|
||||||
var g = function() { return h() };
|
var g = function() { return h() };
|
||||||
@@ -97,7 +111,9 @@ unused_circular_references_3: {
|
|||||||
}
|
}
|
||||||
|
|
||||||
unused_keep_setter_arg: {
|
unused_keep_setter_arg: {
|
||||||
options = { unused: true };
|
options = {
|
||||||
|
unused: true,
|
||||||
|
}
|
||||||
input: {
|
input: {
|
||||||
var x = {
|
var x = {
|
||||||
_foo: null,
|
_foo: null,
|
||||||
@@ -121,12 +137,14 @@ unused_keep_setter_arg: {
|
|||||||
}
|
}
|
||||||
|
|
||||||
unused_var_in_catch: {
|
unused_var_in_catch: {
|
||||||
options = { unused: true };
|
options = {
|
||||||
|
unused: true,
|
||||||
|
}
|
||||||
input: {
|
input: {
|
||||||
function foo() {
|
function foo() {
|
||||||
try {
|
try {
|
||||||
foo();
|
foo();
|
||||||
} catch(ex) {
|
} catch (ex) {
|
||||||
var x = 10;
|
var x = 10;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -135,18 +153,20 @@ unused_var_in_catch: {
|
|||||||
function foo() {
|
function foo() {
|
||||||
try {
|
try {
|
||||||
foo();
|
foo();
|
||||||
} catch(ex) {}
|
} catch (ex) {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
used_var_in_catch: {
|
used_var_in_catch: {
|
||||||
options = { unused: true };
|
options = {
|
||||||
|
unused: true,
|
||||||
|
}
|
||||||
input: {
|
input: {
|
||||||
function foo() {
|
function foo() {
|
||||||
try {
|
try {
|
||||||
foo();
|
foo();
|
||||||
} catch(ex) {
|
} catch (ex) {
|
||||||
var x = 10;
|
var x = 10;
|
||||||
}
|
}
|
||||||
return x;
|
return x;
|
||||||
@@ -156,7 +176,7 @@ used_var_in_catch: {
|
|||||||
function foo() {
|
function foo() {
|
||||||
try {
|
try {
|
||||||
foo();
|
foo();
|
||||||
} catch(ex) {
|
} catch (ex) {
|
||||||
var x = 10;
|
var x = 10;
|
||||||
}
|
}
|
||||||
return x;
|
return x;
|
||||||
@@ -165,7 +185,11 @@ used_var_in_catch: {
|
|||||||
}
|
}
|
||||||
|
|
||||||
keep_fnames: {
|
keep_fnames: {
|
||||||
options = { unused: true, keep_fnames: true, unsafe: true };
|
options = {
|
||||||
|
keep_fnames: true,
|
||||||
|
unsafe: true,
|
||||||
|
unused: true,
|
||||||
|
}
|
||||||
input: {
|
input: {
|
||||||
function foo() {
|
function foo() {
|
||||||
return function bar(baz) {};
|
return function bar(baz) {};
|
||||||
@@ -367,7 +391,7 @@ drop_toplevel_vars_fargs: {
|
|||||||
drop_toplevel_all: {
|
drop_toplevel_all: {
|
||||||
options = {
|
options = {
|
||||||
toplevel: true,
|
toplevel: true,
|
||||||
unused: true
|
unused: true,
|
||||||
}
|
}
|
||||||
input: {
|
input: {
|
||||||
var a, b = 1, c = g;
|
var a, b = 1, c = g;
|
||||||
@@ -418,7 +442,11 @@ drop_toplevel_retain: {
|
|||||||
|
|
||||||
drop_toplevel_retain_array: {
|
drop_toplevel_retain_array: {
|
||||||
options = {
|
options = {
|
||||||
top_retain: [ "f", "a", "o" ],
|
top_retain: [
|
||||||
|
"f",
|
||||||
|
"a",
|
||||||
|
"o"
|
||||||
|
],
|
||||||
unused: true,
|
unused: true,
|
||||||
}
|
}
|
||||||
input: {
|
input: {
|
||||||
@@ -476,8 +504,8 @@ drop_toplevel_retain_regex: {
|
|||||||
|
|
||||||
drop_toplevel_all_retain: {
|
drop_toplevel_all_retain: {
|
||||||
options = {
|
options = {
|
||||||
toplevel: true,
|
|
||||||
top_retain: "f,a,o",
|
top_retain: "f,a,o",
|
||||||
|
toplevel: true,
|
||||||
unused: true,
|
unused: true,
|
||||||
}
|
}
|
||||||
input: {
|
input: {
|
||||||
@@ -506,8 +534,8 @@ drop_toplevel_all_retain: {
|
|||||||
|
|
||||||
drop_toplevel_funcs_retain: {
|
drop_toplevel_funcs_retain: {
|
||||||
options = {
|
options = {
|
||||||
toplevel: "funcs",
|
|
||||||
top_retain: "f,a,o",
|
top_retain: "f,a,o",
|
||||||
|
toplevel: "funcs",
|
||||||
unused: true,
|
unused: true,
|
||||||
}
|
}
|
||||||
input: {
|
input: {
|
||||||
@@ -537,8 +565,8 @@ drop_toplevel_funcs_retain: {
|
|||||||
|
|
||||||
drop_toplevel_vars_retain: {
|
drop_toplevel_vars_retain: {
|
||||||
options = {
|
options = {
|
||||||
toplevel: "vars",
|
|
||||||
top_retain: "f,a,o",
|
top_retain: "f,a,o",
|
||||||
|
toplevel: "vars",
|
||||||
unused: true,
|
unused: true,
|
||||||
}
|
}
|
||||||
input: {
|
input: {
|
||||||
@@ -671,18 +699,6 @@ iife: {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
drop_value: {
|
|
||||||
options = {
|
|
||||||
side_effects: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
(1, [2, foo()], 3, {a:1, b:bar()});
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
foo(), bar();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
issue_1539: {
|
issue_1539: {
|
||||||
options = {
|
options = {
|
||||||
collapse_vars: true,
|
collapse_vars: true,
|
||||||
@@ -769,6 +785,7 @@ assign_chain: {
|
|||||||
issue_1583: {
|
issue_1583: {
|
||||||
options = {
|
options = {
|
||||||
keep_fargs: true,
|
keep_fargs: true,
|
||||||
|
passes: 2,
|
||||||
reduce_funcs: true,
|
reduce_funcs: true,
|
||||||
reduce_vars: true,
|
reduce_vars: true,
|
||||||
unused: true,
|
unused: true,
|
||||||
@@ -976,7 +993,7 @@ issue_1715_4: {
|
|||||||
delete_assign_1: {
|
delete_assign_1: {
|
||||||
options = {
|
options = {
|
||||||
booleans: true,
|
booleans: true,
|
||||||
side_effects: true,
|
evaluate: true,
|
||||||
toplevel: true,
|
toplevel: true,
|
||||||
unused: true,
|
unused: true,
|
||||||
}
|
}
|
||||||
@@ -990,21 +1007,28 @@ delete_assign_1: {
|
|||||||
console.log(delete (a = 0 / 0));
|
console.log(delete (a = 0 / 0));
|
||||||
}
|
}
|
||||||
expect: {
|
expect: {
|
||||||
console.log((void 0, !0));
|
console.log(!0);
|
||||||
console.log((void 0, !0));
|
console.log(!0);
|
||||||
console.log((1 / 0, !0));
|
console.log(!0);
|
||||||
console.log((1 / 0, !0));
|
console.log(!0);
|
||||||
console.log((NaN, !0));
|
console.log(!0);
|
||||||
console.log((0 / 0, !0));
|
console.log(!0);
|
||||||
}
|
}
|
||||||
expect_stdout: true
|
expect_stdout: [
|
||||||
|
"true",
|
||||||
|
"true",
|
||||||
|
"true",
|
||||||
|
"true",
|
||||||
|
"true",
|
||||||
|
"true",
|
||||||
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
delete_assign_2: {
|
delete_assign_2: {
|
||||||
options = {
|
options = {
|
||||||
booleans: true,
|
booleans: true,
|
||||||
|
evaluate: true,
|
||||||
keep_infinity: true,
|
keep_infinity: true,
|
||||||
side_effects: true,
|
|
||||||
toplevel: true,
|
toplevel: true,
|
||||||
unused: true,
|
unused: true,
|
||||||
}
|
}
|
||||||
@@ -1018,14 +1042,21 @@ delete_assign_2: {
|
|||||||
console.log(delete (a = 0 / 0));
|
console.log(delete (a = 0 / 0));
|
||||||
}
|
}
|
||||||
expect: {
|
expect: {
|
||||||
console.log((void 0, !0));
|
console.log(!0);
|
||||||
console.log((void 0, !0));
|
console.log(!0);
|
||||||
console.log((Infinity, !0));
|
console.log(!0);
|
||||||
console.log((1 / 0, !0));
|
console.log(!0);
|
||||||
console.log((NaN, !0));
|
console.log(!0);
|
||||||
console.log((0 / 0, !0));
|
console.log(!0);
|
||||||
}
|
}
|
||||||
expect_stdout: true
|
expect_stdout: [
|
||||||
|
"true",
|
||||||
|
"true",
|
||||||
|
"true",
|
||||||
|
"true",
|
||||||
|
"true",
|
||||||
|
"true",
|
||||||
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
drop_var: {
|
drop_var: {
|
||||||
@@ -1116,6 +1147,7 @@ var_catch_toplevel: {
|
|||||||
options = {
|
options = {
|
||||||
conditionals: true,
|
conditionals: true,
|
||||||
negate_iife: true,
|
negate_iife: true,
|
||||||
|
passes: 2,
|
||||||
reduce_funcs: true,
|
reduce_funcs: true,
|
||||||
reduce_vars: true,
|
reduce_vars: true,
|
||||||
side_effects: true,
|
side_effects: true,
|
||||||
@@ -1128,7 +1160,7 @@ var_catch_toplevel: {
|
|||||||
try {
|
try {
|
||||||
a++;
|
a++;
|
||||||
x();
|
x();
|
||||||
} catch(a) {
|
} catch (a) {
|
||||||
if (a) var a;
|
if (a) var a;
|
||||||
var a = 10;
|
var a = 10;
|
||||||
}
|
}
|
||||||
@@ -1139,7 +1171,7 @@ var_catch_toplevel: {
|
|||||||
!function() {
|
!function() {
|
||||||
try {
|
try {
|
||||||
x();
|
x();
|
||||||
} catch(a) {
|
} catch (a) {
|
||||||
var a;
|
var a;
|
||||||
}
|
}
|
||||||
}();
|
}();
|
||||||
@@ -1377,9 +1409,9 @@ issue_2516_1: {
|
|||||||
issue_2516_2: {
|
issue_2516_2: {
|
||||||
options = {
|
options = {
|
||||||
collapse_vars: true,
|
collapse_vars: true,
|
||||||
|
passes: 2,
|
||||||
reduce_funcs: true,
|
reduce_funcs: true,
|
||||||
reduce_vars: true,
|
reduce_vars: true,
|
||||||
passes: 2,
|
|
||||||
unused: true,
|
unused: true,
|
||||||
}
|
}
|
||||||
input: {
|
input: {
|
||||||
@@ -1605,7 +1637,7 @@ double_assign_2: {
|
|||||||
}
|
}
|
||||||
expect: {
|
expect: {
|
||||||
for (var i = 0; i < 2; i++)
|
for (var i = 0; i < 2; i++)
|
||||||
void 0, a = {}, console.log(a);
|
a = {}, console.log(a);
|
||||||
var a;
|
var a;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1686,7 +1718,7 @@ issue_2768: {
|
|||||||
}
|
}
|
||||||
expect: {
|
expect: {
|
||||||
var a = "FAIL";
|
var a = "FAIL";
|
||||||
var c = (d = a, 0, void (d && (a = "PASS")));
|
var c = (d = a, void (d && (a = "PASS")));
|
||||||
var d;
|
var d;
|
||||||
console.log(a, typeof c);
|
console.log(a, typeof c);
|
||||||
}
|
}
|
||||||
@@ -1954,3 +1986,392 @@ issue_3192: {
|
|||||||
"foo bar",
|
"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"
|
||||||
|
}
|
||||||
|
|
||||||
|
issue_3598: {
|
||||||
|
options = {
|
||||||
|
collapse_vars: true,
|
||||||
|
reduce_vars: true,
|
||||||
|
unused: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
var a = "FAIL";
|
||||||
|
try {
|
||||||
|
(function() {
|
||||||
|
var b = void 0;
|
||||||
|
a = "PASS";
|
||||||
|
c.p = 0;
|
||||||
|
var c = b[!1];
|
||||||
|
})();
|
||||||
|
} catch (e) {}
|
||||||
|
console.log(a);
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
var a = "FAIL";
|
||||||
|
try {
|
||||||
|
(function() {
|
||||||
|
a = "PASS";
|
||||||
|
var c = (void (c.p = 0))[!1];
|
||||||
|
})();
|
||||||
|
} catch (e) {}
|
||||||
|
console.log(a);
|
||||||
|
}
|
||||||
|
expect_stdout: "PASS"
|
||||||
|
}
|
||||||
|
|
||||||
|
self_assign: {
|
||||||
|
options = {
|
||||||
|
passes: 2,
|
||||||
|
side_effects: true,
|
||||||
|
unused: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
function d(a) {
|
||||||
|
a = a;
|
||||||
|
}
|
||||||
|
function e(a, b) {
|
||||||
|
a = b;
|
||||||
|
b = a;
|
||||||
|
}
|
||||||
|
function f(a, b, c) {
|
||||||
|
a = b;
|
||||||
|
b = c;
|
||||||
|
c = a;
|
||||||
|
}
|
||||||
|
function g(a, b, c) {
|
||||||
|
a = a * b + c;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
function d(a) {}
|
||||||
|
function e(a, b) {}
|
||||||
|
function f(a, b, c) {}
|
||||||
|
function g(a, b, c) {}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function_argument_reference: {
|
||||||
|
options = {
|
||||||
|
keep_fargs: false,
|
||||||
|
side_effects: true,
|
||||||
|
unused: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
var a = 1, b = 42;
|
||||||
|
function f(a) {
|
||||||
|
b <<= a;
|
||||||
|
}
|
||||||
|
f();
|
||||||
|
console.log(a, b);
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
var a = 1, b = 42;
|
||||||
|
function f(a) {
|
||||||
|
b <<= a;
|
||||||
|
}
|
||||||
|
f();
|
||||||
|
console.log(a, b);
|
||||||
|
}
|
||||||
|
expect_stdout: "1 42"
|
||||||
|
}
|
||||||
|
|
||||||
|
function_parameter_ie8: {
|
||||||
|
options = {
|
||||||
|
ie8: true,
|
||||||
|
reduce_vars: true,
|
||||||
|
unused: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
(function() {
|
||||||
|
var a;
|
||||||
|
function f() {
|
||||||
|
console.log("PASS");
|
||||||
|
}
|
||||||
|
f(a = 1 + a);
|
||||||
|
})();
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
(function() {
|
||||||
|
(function f() {
|
||||||
|
console.log("PASS");
|
||||||
|
})(0);
|
||||||
|
})();
|
||||||
|
}
|
||||||
|
expect_stdout: "PASS"
|
||||||
|
}
|
||||||
|
|
||||||
|
issue_3664: {
|
||||||
|
options = {
|
||||||
|
pure_getters: "strict",
|
||||||
|
unused: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
console.log(function() {
|
||||||
|
var a, b = (a = (a = [ b && console.log("FAIL") ]).p = 0, 0);
|
||||||
|
return "PASS";
|
||||||
|
}());
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
console.log(function() {
|
||||||
|
var b = ([ b && console.log("FAIL") ].p = 0, 0);
|
||||||
|
return "PASS";
|
||||||
|
}());
|
||||||
|
}
|
||||||
|
expect_stdout: "PASS"
|
||||||
|
}
|
||||||
|
|
||||||
|
issue_3673: {
|
||||||
|
options = {
|
||||||
|
pure_getters: "strict",
|
||||||
|
side_effects: true,
|
||||||
|
toplevel: true,
|
||||||
|
unused: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
var a;
|
||||||
|
(a = [ a ]).p = 42;
|
||||||
|
console.log("PASS");
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
var a;
|
||||||
|
(a = [ a ]).p = 42;
|
||||||
|
console.log("PASS");
|
||||||
|
}
|
||||||
|
expect_stdout: "PASS"
|
||||||
|
}
|
||||||
|
|||||||
@@ -186,7 +186,9 @@ unary_prefix: {
|
|||||||
}
|
}
|
||||||
|
|
||||||
negative_zero: {
|
negative_zero: {
|
||||||
options = { evaluate: true }
|
options = {
|
||||||
|
evaluate: true,
|
||||||
|
}
|
||||||
input: {
|
input: {
|
||||||
console.log(
|
console.log(
|
||||||
-"",
|
-"",
|
||||||
@@ -207,7 +209,9 @@ negative_zero: {
|
|||||||
}
|
}
|
||||||
|
|
||||||
positive_zero: {
|
positive_zero: {
|
||||||
options = { evaluate: true }
|
options = {
|
||||||
|
evaluate: true,
|
||||||
|
}
|
||||||
input: {
|
input: {
|
||||||
console.log(
|
console.log(
|
||||||
+"",
|
+"",
|
||||||
@@ -229,26 +233,43 @@ positive_zero: {
|
|||||||
|
|
||||||
unsafe_constant: {
|
unsafe_constant: {
|
||||||
options = {
|
options = {
|
||||||
evaluate : true,
|
evaluate: true,
|
||||||
unsafe : true
|
unsafe: true,
|
||||||
}
|
}
|
||||||
input: {
|
input: {
|
||||||
console.log(
|
console.log(true.a, false.a);
|
||||||
true.a,
|
console.log(true.valueOf(), false.valueOf());
|
||||||
false.a,
|
try {
|
||||||
null.a,
|
console.log(null.a);
|
||||||
undefined.a
|
} catch (e) {
|
||||||
);
|
console.log("PASS");
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
console.log(undefined.a);
|
||||||
|
} catch (e) {
|
||||||
|
console.log("PASS");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
expect: {
|
expect: {
|
||||||
console.log(
|
console.log(void 0, void 0);
|
||||||
true.a,
|
console.log(true, false);
|
||||||
false.a,
|
try {
|
||||||
null.a,
|
console.log(null.a);
|
||||||
(void 0).a
|
} catch (e) {
|
||||||
);
|
console.log("PASS");
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
console.log((void 0).a);
|
||||||
|
} catch (e) {
|
||||||
|
console.log("PASS");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
expect_stdout: true
|
expect_stdout: [
|
||||||
|
"undefined undefined",
|
||||||
|
"true false",
|
||||||
|
"PASS",
|
||||||
|
"PASS",
|
||||||
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
unsafe_object: {
|
unsafe_object: {
|
||||||
@@ -274,7 +295,7 @@ unsafe_object: {
|
|||||||
o + 1,
|
o + 1,
|
||||||
2,
|
2,
|
||||||
o.b + 1,
|
o.b + 1,
|
||||||
1..b + 1
|
NaN
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
expect_stdout: true
|
expect_stdout: true
|
||||||
@@ -361,7 +382,7 @@ unsafe_object_repeated: {
|
|||||||
o + 1,
|
o + 1,
|
||||||
2,
|
2,
|
||||||
o.b + 1,
|
o.b + 1,
|
||||||
1..b + 1
|
NaN
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
expect_stdout: true
|
expect_stdout: true
|
||||||
@@ -421,8 +442,8 @@ prop_function: {
|
|||||||
|
|
||||||
unsafe_integer_key: {
|
unsafe_integer_key: {
|
||||||
options = {
|
options = {
|
||||||
evaluate : true,
|
evaluate: true,
|
||||||
unsafe : true
|
unsafe: true,
|
||||||
}
|
}
|
||||||
input: {
|
input: {
|
||||||
console.log(
|
console.log(
|
||||||
@@ -440,8 +461,8 @@ unsafe_integer_key: {
|
|||||||
2,
|
2,
|
||||||
2,
|
2,
|
||||||
({0:1})[1] + 1,
|
({0:1})[1] + 1,
|
||||||
1[1] + 1,
|
NaN,
|
||||||
1["1"] + 1
|
NaN
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
expect_stdout: true
|
expect_stdout: true
|
||||||
@@ -449,8 +470,8 @@ unsafe_integer_key: {
|
|||||||
|
|
||||||
unsafe_integer_key_complex: {
|
unsafe_integer_key_complex: {
|
||||||
options = {
|
options = {
|
||||||
evaluate : true,
|
evaluate: true,
|
||||||
unsafe : true
|
unsafe: true,
|
||||||
}
|
}
|
||||||
input: {
|
input: {
|
||||||
console.log(
|
console.log(
|
||||||
@@ -477,8 +498,8 @@ unsafe_integer_key_complex: {
|
|||||||
|
|
||||||
unsafe_float_key: {
|
unsafe_float_key: {
|
||||||
options = {
|
options = {
|
||||||
evaluate : true,
|
evaluate: true,
|
||||||
unsafe : true
|
unsafe: true,
|
||||||
}
|
}
|
||||||
input: {
|
input: {
|
||||||
console.log(
|
console.log(
|
||||||
@@ -496,8 +517,8 @@ unsafe_float_key: {
|
|||||||
2,
|
2,
|
||||||
2,
|
2,
|
||||||
({2.72:1})[3.14] + 1,
|
({2.72:1})[3.14] + 1,
|
||||||
1[3.14] + 1,
|
NaN,
|
||||||
1["3.14"] + 1
|
NaN
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
expect_stdout: true
|
expect_stdout: true
|
||||||
@@ -505,8 +526,8 @@ unsafe_float_key: {
|
|||||||
|
|
||||||
unsafe_float_key_complex: {
|
unsafe_float_key_complex: {
|
||||||
options = {
|
options = {
|
||||||
evaluate : true,
|
evaluate: true,
|
||||||
unsafe : true
|
unsafe: true,
|
||||||
}
|
}
|
||||||
input: {
|
input: {
|
||||||
console.log(
|
console.log(
|
||||||
@@ -533,8 +554,8 @@ unsafe_float_key_complex: {
|
|||||||
|
|
||||||
unsafe_array: {
|
unsafe_array: {
|
||||||
options = {
|
options = {
|
||||||
evaluate : true,
|
evaluate: true,
|
||||||
unsafe : true
|
unsafe: true,
|
||||||
}
|
}
|
||||||
input: {
|
input: {
|
||||||
console.log(
|
console.log(
|
||||||
@@ -569,8 +590,8 @@ unsafe_array: {
|
|||||||
|
|
||||||
unsafe_string: {
|
unsafe_string: {
|
||||||
options = {
|
options = {
|
||||||
evaluate : true,
|
evaluate: true,
|
||||||
unsafe : true
|
unsafe: true,
|
||||||
}
|
}
|
||||||
input: {
|
input: {
|
||||||
console.log(
|
console.log(
|
||||||
@@ -597,8 +618,8 @@ unsafe_string: {
|
|||||||
|
|
||||||
unsafe_array_bad_index: {
|
unsafe_array_bad_index: {
|
||||||
options = {
|
options = {
|
||||||
evaluate : true,
|
evaluate: true,
|
||||||
unsafe : true
|
unsafe: true,
|
||||||
}
|
}
|
||||||
input: {
|
input: {
|
||||||
console.log(
|
console.log(
|
||||||
@@ -619,8 +640,8 @@ unsafe_array_bad_index: {
|
|||||||
|
|
||||||
unsafe_string_bad_index: {
|
unsafe_string_bad_index: {
|
||||||
options = {
|
options = {
|
||||||
evaluate : true,
|
evaluate: true,
|
||||||
unsafe : true
|
unsafe: true,
|
||||||
}
|
}
|
||||||
input: {
|
input: {
|
||||||
console.log(
|
console.log(
|
||||||
@@ -631,12 +652,12 @@ unsafe_string_bad_index: {
|
|||||||
}
|
}
|
||||||
expect: {
|
expect: {
|
||||||
console.log(
|
console.log(
|
||||||
"1234".a + 1,
|
NaN,
|
||||||
"1234"["a"] + 1,
|
NaN,
|
||||||
"1234"[3.14] + 1
|
NaN
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
expect_stdout: true
|
expect_stdout: "NaN NaN NaN"
|
||||||
}
|
}
|
||||||
|
|
||||||
prototype_function: {
|
prototype_function: {
|
||||||
@@ -754,8 +775,8 @@ in_boolean_context: {
|
|||||||
|
|
||||||
unsafe_charAt: {
|
unsafe_charAt: {
|
||||||
options = {
|
options = {
|
||||||
evaluate : true,
|
evaluate: true,
|
||||||
unsafe : true
|
unsafe: true,
|
||||||
}
|
}
|
||||||
input: {
|
input: {
|
||||||
console.log(
|
console.log(
|
||||||
@@ -782,8 +803,8 @@ unsafe_charAt: {
|
|||||||
|
|
||||||
unsafe_charAt_bad_index: {
|
unsafe_charAt_bad_index: {
|
||||||
options = {
|
options = {
|
||||||
evaluate : true,
|
evaluate: true,
|
||||||
unsafe : true
|
unsafe: true,
|
||||||
}
|
}
|
||||||
input: {
|
input: {
|
||||||
console.log(
|
console.log(
|
||||||
@@ -804,8 +825,8 @@ unsafe_charAt_bad_index: {
|
|||||||
|
|
||||||
unsafe_charAt_noop: {
|
unsafe_charAt_noop: {
|
||||||
options = {
|
options = {
|
||||||
evaluate : true,
|
evaluate: true,
|
||||||
unsafe : true
|
unsafe: true,
|
||||||
}
|
}
|
||||||
input: {
|
input: {
|
||||||
console.log(
|
console.log(
|
||||||
@@ -816,8 +837,8 @@ unsafe_charAt_noop: {
|
|||||||
}
|
}
|
||||||
expect: {
|
expect: {
|
||||||
console.log(
|
console.log(
|
||||||
s.charAt(0),
|
s[0],
|
||||||
"string".charAt(x),
|
"string"[0 | x],
|
||||||
(typeof x)[0]
|
(typeof x)[0]
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -1120,14 +1141,14 @@ issue_2207_1: {
|
|||||||
console.log(Math.max(3, 6, 2, 7, 3, 4));
|
console.log(Math.max(3, 6, 2, 7, 3, 4));
|
||||||
console.log(Math.cos(1.2345));
|
console.log(Math.cos(1.2345));
|
||||||
console.log(Math.cos(1.2345) - Math.sin(4.321));
|
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: {
|
expect: {
|
||||||
console.log("A");
|
console.log("A");
|
||||||
console.log(7);
|
console.log(7);
|
||||||
console.log(Math.cos(1.2345));
|
console.log(Math.cos(1.2345));
|
||||||
console.log(1.2543732512566947);
|
console.log(1.2543732512566947);
|
||||||
console.log(1.6093984514472044);
|
console.log("1.609398451447204");
|
||||||
}
|
}
|
||||||
expect_stdout: true
|
expect_stdout: true
|
||||||
}
|
}
|
||||||
@@ -1195,7 +1216,7 @@ issue_2231_1: {
|
|||||||
}
|
}
|
||||||
expect_stdout: true
|
expect_stdout: true
|
||||||
expect_warnings: [
|
expect_warnings: [
|
||||||
"WARN: Error evaluating Object.keys(void 0) [test/compress/evaluate.js:1191,20]",
|
"WARN: Error evaluating Object.keys(void 0) [test/compress/evaluate.js:1,20]",
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1212,7 +1233,7 @@ issue_2231_2: {
|
|||||||
}
|
}
|
||||||
expect_stdout: true
|
expect_stdout: true
|
||||||
expect_warnings: [
|
expect_warnings: [
|
||||||
"WARN: Error evaluating Object.getOwnPropertyNames(null) [test/compress/evaluate.js:1208,20]",
|
"WARN: Error evaluating Object.getOwnPropertyNames(null) [test/compress/evaluate.js:1,20]",
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1241,12 +1262,12 @@ self_comparison_1: {
|
|||||||
}
|
}
|
||||||
input: {
|
input: {
|
||||||
var o = { n: NaN };
|
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: {
|
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: {
|
self_comparison_2: {
|
||||||
@@ -1261,12 +1282,12 @@ self_comparison_2: {
|
|||||||
}
|
}
|
||||||
input: {
|
input: {
|
||||||
var o = { n: NaN };
|
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: {
|
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: {
|
issue_2535_1: {
|
||||||
@@ -1350,14 +1371,14 @@ issue_2535_3: {
|
|||||||
}
|
}
|
||||||
expect_stdout: true
|
expect_stdout: true
|
||||||
expect_warnings: [
|
expect_warnings: [
|
||||||
"WARN: Dropping side-effect-free && [test/compress/evaluate.js:1336,20]",
|
"WARN: Dropping side-effect-free && [test/compress/evaluate.js:1,20]",
|
||||||
"WARN: Dropping side-effect-free && [test/compress/evaluate.js:1337,20]",
|
"WARN: Dropping side-effect-free && [test/compress/evaluate.js:2,20]",
|
||||||
"WARN: Dropping side-effect-free && [test/compress/evaluate.js:1338,20]",
|
"WARN: Dropping side-effect-free && [test/compress/evaluate.js:3,20]",
|
||||||
"WARN: Condition left of && always false [test/compress/evaluate.js:1338,20]",
|
"WARN: Condition left of && always false [test/compress/evaluate.js:3,20]",
|
||||||
"WARN: Dropping side-effect-free || [test/compress/evaluate.js:1339,20]",
|
"WARN: Dropping side-effect-free || [test/compress/evaluate.js:4,20]",
|
||||||
"WARN: Dropping side-effect-free || [test/compress/evaluate.js:1340,20]",
|
"WARN: Dropping side-effect-free || [test/compress/evaluate.js:5,20]",
|
||||||
"WARN: Dropping side-effect-free || [test/compress/evaluate.js:1341,20]",
|
"WARN: Dropping side-effect-free || [test/compress/evaluate.js:6,20]",
|
||||||
"WARN: Condition left of || always true [test/compress/evaluate.js:1341,20]",
|
"WARN: Condition left of || always true [test/compress/evaluate.js:6,20]",
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1536,7 +1557,7 @@ issue_2926_2: {
|
|||||||
expect_stdout: "function"
|
expect_stdout: "function"
|
||||||
}
|
}
|
||||||
|
|
||||||
issue_2968: {
|
issue_2968_1: {
|
||||||
options = {
|
options = {
|
||||||
collapse_vars: true,
|
collapse_vars: true,
|
||||||
evaluate: true,
|
evaluate: true,
|
||||||
@@ -1567,6 +1588,39 @@ issue_2968: {
|
|||||||
expect_stdout: "PASS"
|
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: {
|
truthy_conditionals: {
|
||||||
options = {
|
options = {
|
||||||
conditionals: true,
|
conditionals: true,
|
||||||
@@ -1606,3 +1660,504 @@ 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"
|
||||||
|
}
|
||||||
|
|
||||||
|
issue_3568: {
|
||||||
|
options = {
|
||||||
|
evaluate: true,
|
||||||
|
reduce_vars: true,
|
||||||
|
toplevel: true,
|
||||||
|
unsafe: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
var a = 0;
|
||||||
|
function f(b) {
|
||||||
|
return b && b.p;
|
||||||
|
}
|
||||||
|
console.log(f(++a + f()));
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
var a = 0;
|
||||||
|
function f(b) {
|
||||||
|
return b && b.p;
|
||||||
|
}
|
||||||
|
console.log(NaN);
|
||||||
|
}
|
||||||
|
expect_stdout: "NaN"
|
||||||
|
}
|
||||||
|
|
||||||
|
conditional_function: {
|
||||||
|
options = {
|
||||||
|
evaluate: true,
|
||||||
|
reduce_vars: true,
|
||||||
|
toplevel: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
function f(a) {
|
||||||
|
return a && "undefined" != typeof A ? A : 42;
|
||||||
|
}
|
||||||
|
console.log(f(0), f(1));
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
function f(a) {
|
||||||
|
return a && "undefined" != typeof A ? A : 42;
|
||||||
|
}
|
||||||
|
console.log(42, f(1));
|
||||||
|
}
|
||||||
|
expect_stdout: "42 42"
|
||||||
|
}
|
||||||
|
|
||||||
|
best_of_evaluate: {
|
||||||
|
options = {
|
||||||
|
evaluate: true,
|
||||||
|
reduce_vars: true,
|
||||||
|
toplevel: true,
|
||||||
|
unused: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
function d(x, y) {
|
||||||
|
return x / y;
|
||||||
|
}
|
||||||
|
console.log(0 / 3, 1 / 64, 4 / 7, 7 / 7);
|
||||||
|
console.log(d(0, 3), d(1, 64), d(4, 7), d(7, 7));
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
function d(x, y) {
|
||||||
|
return x / y;
|
||||||
|
}
|
||||||
|
console.log(0, 1 / 64, 4 / 7, 1);
|
||||||
|
console.log(0, .015625, d(4, 7), 1);
|
||||||
|
}
|
||||||
|
expect_stdout: [
|
||||||
|
"0 0.015625 0.5714285714285714 1",
|
||||||
|
"0 0.015625 0.5714285714285714 1",
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
|
eager_evaluate: {
|
||||||
|
options = {
|
||||||
|
evaluate: "eager",
|
||||||
|
reduce_vars: true,
|
||||||
|
toplevel: true,
|
||||||
|
unused: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
function d(x, y) {
|
||||||
|
return x / y;
|
||||||
|
}
|
||||||
|
console.log(0 / 3, 1 / 64, 4 / 7, 7 / 7);
|
||||||
|
console.log(d(0, 3), d(1, 64), d(4, 7), d(7, 7));
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
console.log(0, .015625, .5714285714285714, 1);
|
||||||
|
console.log(0, .015625, .5714285714285714, 1);
|
||||||
|
}
|
||||||
|
expect_stdout: [
|
||||||
|
"0 0.015625 0.5714285714285714 1",
|
||||||
|
"0 0.015625 0.5714285714285714 1",
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
|
threshold_evaluate_default: {
|
||||||
|
options = {
|
||||||
|
evaluate: true,
|
||||||
|
reduce_vars: true,
|
||||||
|
toplevel: true,
|
||||||
|
unused: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
function b(x) {
|
||||||
|
return x + x + x;
|
||||||
|
}
|
||||||
|
console.log(b("1"), b(2), b(b(b("ABCDEFGHIJK"))));
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
function b(x) {
|
||||||
|
return x + x + x;
|
||||||
|
}
|
||||||
|
console.log("111", 6, b(b(b("ABCDEFGHIJK"))));
|
||||||
|
}
|
||||||
|
expect_stdout: "111 6 ABCDEFGHIJKABCDEFGHIJKABCDEFGHIJKABCDEFGHIJKABCDEFGHIJKABCDEFGHIJKABCDEFGHIJKABCDEFGHIJKABCDEFGHIJKABCDEFGHIJKABCDEFGHIJKABCDEFGHIJKABCDEFGHIJKABCDEFGHIJKABCDEFGHIJKABCDEFGHIJKABCDEFGHIJKABCDEFGHIJKABCDEFGHIJKABCDEFGHIJKABCDEFGHIJKABCDEFGHIJKABCDEFGHIJKABCDEFGHIJKABCDEFGHIJKABCDEFGHIJKABCDEFGHIJK"
|
||||||
|
}
|
||||||
|
|
||||||
|
threshold_evaluate_30: {
|
||||||
|
options = {
|
||||||
|
evaluate: 30,
|
||||||
|
reduce_vars: true,
|
||||||
|
toplevel: true,
|
||||||
|
unused: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
function b(x) {
|
||||||
|
return x + x + x;
|
||||||
|
}
|
||||||
|
console.log(b("1"), b(2), b(b(b("ABCDEFGHIJK"))));
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
function b(x) {
|
||||||
|
return x + x + x;
|
||||||
|
}
|
||||||
|
console.log("111", 6, b(b("ABCDEFGHIJKABCDEFGHIJKABCDEFGHIJK")));
|
||||||
|
}
|
||||||
|
expect_stdout: "111 6 ABCDEFGHIJKABCDEFGHIJKABCDEFGHIJKABCDEFGHIJKABCDEFGHIJKABCDEFGHIJKABCDEFGHIJKABCDEFGHIJKABCDEFGHIJKABCDEFGHIJKABCDEFGHIJKABCDEFGHIJKABCDEFGHIJKABCDEFGHIJKABCDEFGHIJKABCDEFGHIJKABCDEFGHIJKABCDEFGHIJKABCDEFGHIJKABCDEFGHIJKABCDEFGHIJKABCDEFGHIJKABCDEFGHIJKABCDEFGHIJKABCDEFGHIJKABCDEFGHIJKABCDEFGHIJK"
|
||||||
|
}
|
||||||
|
|
||||||
|
threshold_evaluate_100: {
|
||||||
|
options = {
|
||||||
|
evaluate: 100,
|
||||||
|
reduce_vars: true,
|
||||||
|
toplevel: true,
|
||||||
|
unused: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
function b(x) {
|
||||||
|
return x + x + x;
|
||||||
|
}
|
||||||
|
console.log(b("1"), b(2), b(b(b("ABCDEFGHIJK"))));
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
function b(x) {
|
||||||
|
return x + x + x;
|
||||||
|
}
|
||||||
|
console.log("111", 6, b("ABCDEFGHIJKABCDEFGHIJKABCDEFGHIJKABCDEFGHIJKABCDEFGHIJKABCDEFGHIJKABCDEFGHIJKABCDEFGHIJKABCDEFGHIJK"));
|
||||||
|
}
|
||||||
|
expect_stdout: "111 6 ABCDEFGHIJKABCDEFGHIJKABCDEFGHIJKABCDEFGHIJKABCDEFGHIJKABCDEFGHIJKABCDEFGHIJKABCDEFGHIJKABCDEFGHIJKABCDEFGHIJKABCDEFGHIJKABCDEFGHIJKABCDEFGHIJKABCDEFGHIJKABCDEFGHIJKABCDEFGHIJKABCDEFGHIJKABCDEFGHIJKABCDEFGHIJKABCDEFGHIJKABCDEFGHIJKABCDEFGHIJKABCDEFGHIJKABCDEFGHIJKABCDEFGHIJKABCDEFGHIJKABCDEFGHIJK"
|
||||||
|
}
|
||||||
|
|
||||||
|
threshold_evaluate_999: {
|
||||||
|
options = {
|
||||||
|
evaluate: 999,
|
||||||
|
reduce_vars: true,
|
||||||
|
toplevel: true,
|
||||||
|
unused: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
function b(x) {
|
||||||
|
return x + x + x;
|
||||||
|
}
|
||||||
|
console.log(b("1"), b(2), b(b(b("ABCDEFGHIJK"))));
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
console.log("111", 6, "ABCDEFGHIJKABCDEFGHIJKABCDEFGHIJKABCDEFGHIJKABCDEFGHIJKABCDEFGHIJKABCDEFGHIJKABCDEFGHIJKABCDEFGHIJKABCDEFGHIJKABCDEFGHIJKABCDEFGHIJKABCDEFGHIJKABCDEFGHIJKABCDEFGHIJKABCDEFGHIJKABCDEFGHIJKABCDEFGHIJKABCDEFGHIJKABCDEFGHIJKABCDEFGHIJKABCDEFGHIJKABCDEFGHIJKABCDEFGHIJKABCDEFGHIJKABCDEFGHIJKABCDEFGHIJK");
|
||||||
|
}
|
||||||
|
expect_stdout: "111 6 ABCDEFGHIJKABCDEFGHIJKABCDEFGHIJKABCDEFGHIJKABCDEFGHIJKABCDEFGHIJKABCDEFGHIJKABCDEFGHIJKABCDEFGHIJKABCDEFGHIJKABCDEFGHIJKABCDEFGHIJKABCDEFGHIJKABCDEFGHIJKABCDEFGHIJKABCDEFGHIJKABCDEFGHIJKABCDEFGHIJKABCDEFGHIJKABCDEFGHIJKABCDEFGHIJKABCDEFGHIJKABCDEFGHIJKABCDEFGHIJKABCDEFGHIJKABCDEFGHIJKABCDEFGHIJK"
|
||||||
|
}
|
||||||
|
|
||||||
|
collapse_vars_regexp: {
|
||||||
|
options = {
|
||||||
|
booleans: true,
|
||||||
|
collapse_vars: true,
|
||||||
|
comparisons: true,
|
||||||
|
conditionals: true,
|
||||||
|
dead_code: true,
|
||||||
|
evaluate: true,
|
||||||
|
hoist_funs: true,
|
||||||
|
if_return: true,
|
||||||
|
join_vars: true,
|
||||||
|
keep_fargs: true,
|
||||||
|
loops: false,
|
||||||
|
reduce_funcs: true,
|
||||||
|
reduce_vars: true,
|
||||||
|
side_effects: true,
|
||||||
|
unsafe_regexp: true,
|
||||||
|
unused: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
function f1() {
|
||||||
|
var k = 9;
|
||||||
|
var rx = /[A-Z]+/;
|
||||||
|
return [rx, k];
|
||||||
|
}
|
||||||
|
function f2() {
|
||||||
|
var rx = /ab*/g;
|
||||||
|
return function(s) {
|
||||||
|
return rx.exec(s);
|
||||||
|
};
|
||||||
|
}
|
||||||
|
function f3() {
|
||||||
|
var rx = /ab*/g;
|
||||||
|
return function() {
|
||||||
|
return rx;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
(function() {
|
||||||
|
var result;
|
||||||
|
var s = "acdabcdeabbb";
|
||||||
|
var rx = /ab*/g;
|
||||||
|
while (result = rx.exec(s))
|
||||||
|
console.log(result[0]);
|
||||||
|
})();
|
||||||
|
(function() {
|
||||||
|
var result;
|
||||||
|
var s = "acdabcdeabbb";
|
||||||
|
var rx = f2();
|
||||||
|
while (result = rx(s))
|
||||||
|
console.log(result[0]);
|
||||||
|
})();
|
||||||
|
(function() {
|
||||||
|
var result;
|
||||||
|
var s = "acdabcdeabbb";
|
||||||
|
var rx = f3();
|
||||||
|
while (result = rx().exec(s))
|
||||||
|
console.log(result[0]);
|
||||||
|
})();
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
function f1() {
|
||||||
|
return [/[A-Z]+/, 9];
|
||||||
|
}
|
||||||
|
function f2() {
|
||||||
|
var rx = /ab*/g;
|
||||||
|
return function(s) {
|
||||||
|
return rx.exec(s);
|
||||||
|
};
|
||||||
|
}
|
||||||
|
function f3() {
|
||||||
|
var rx = /ab*/g;
|
||||||
|
return function() {
|
||||||
|
return rx;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
(function() {
|
||||||
|
var result, rx = /ab*/g;
|
||||||
|
while (result = rx.exec("acdabcdeabbb"))
|
||||||
|
console.log(result[0]);
|
||||||
|
})();
|
||||||
|
(function() {
|
||||||
|
var result, rx = f2();
|
||||||
|
while (result = rx("acdabcdeabbb"))
|
||||||
|
console.log(result[0]);
|
||||||
|
})();
|
||||||
|
(function() {
|
||||||
|
var result, rx = f3();
|
||||||
|
while (result = rx().exec("acdabcdeabbb"))
|
||||||
|
console.log(result[0]);
|
||||||
|
})();
|
||||||
|
}
|
||||||
|
expect_stdout: [
|
||||||
|
"a",
|
||||||
|
"ab",
|
||||||
|
"abbb",
|
||||||
|
"a",
|
||||||
|
"ab",
|
||||||
|
"abbb",
|
||||||
|
"a",
|
||||||
|
"ab",
|
||||||
|
"abbb",
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@@ -2,7 +2,7 @@ must_replace: {
|
|||||||
options = {
|
options = {
|
||||||
global_defs: {
|
global_defs: {
|
||||||
D: "foo bar",
|
D: "foo bar",
|
||||||
}
|
},
|
||||||
}
|
}
|
||||||
input: {
|
input: {
|
||||||
console.log(D);
|
console.log(D);
|
||||||
@@ -141,9 +141,8 @@ mixed: {
|
|||||||
console.log(CONFIG);
|
console.log(CONFIG);
|
||||||
}
|
}
|
||||||
expect_warnings: [
|
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:4,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:7,8]",
|
||||||
'WARN: global_defs CONFIG.VALUE redefined [test/compress/global_defs.js:130,8]',
|
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -197,3 +196,23 @@ issue_2167: {
|
|||||||
doWork();
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
issue_2377_1: {
|
issue_2377_1: {
|
||||||
options = {
|
options = {
|
||||||
evaluate: true,
|
evaluate: true,
|
||||||
inline: true,
|
|
||||||
hoist_props: true,
|
hoist_props: true,
|
||||||
|
inline: true,
|
||||||
reduce_funcs: true,
|
reduce_funcs: true,
|
||||||
reduce_vars: true,
|
reduce_vars: true,
|
||||||
toplevel: true,
|
toplevel: true,
|
||||||
@@ -33,8 +33,8 @@ issue_2377_1: {
|
|||||||
issue_2377_2: {
|
issue_2377_2: {
|
||||||
options = {
|
options = {
|
||||||
evaluate: true,
|
evaluate: true,
|
||||||
inline: true,
|
|
||||||
hoist_props: true,
|
hoist_props: true,
|
||||||
|
inline: true,
|
||||||
passes: 2,
|
passes: 2,
|
||||||
reduce_funcs: true,
|
reduce_funcs: true,
|
||||||
reduce_vars: true,
|
reduce_vars: true,
|
||||||
@@ -64,8 +64,8 @@ issue_2377_2: {
|
|||||||
issue_2377_3: {
|
issue_2377_3: {
|
||||||
options = {
|
options = {
|
||||||
evaluate: true,
|
evaluate: true,
|
||||||
inline: true,
|
|
||||||
hoist_props: true,
|
hoist_props: true,
|
||||||
|
inline: true,
|
||||||
passes: 4,
|
passes: 4,
|
||||||
reduce_funcs: true,
|
reduce_funcs: true,
|
||||||
reduce_vars: true,
|
reduce_vars: true,
|
||||||
@@ -416,7 +416,10 @@ issue_2473_1: {
|
|||||||
options = {
|
options = {
|
||||||
hoist_props: false,
|
hoist_props: false,
|
||||||
reduce_vars: true,
|
reduce_vars: true,
|
||||||
top_retain: [ "x", "y" ],
|
top_retain: [
|
||||||
|
"x",
|
||||||
|
"y"
|
||||||
|
],
|
||||||
toplevel: true,
|
toplevel: true,
|
||||||
unused: true,
|
unused: true,
|
||||||
}
|
}
|
||||||
@@ -435,7 +438,10 @@ issue_2473_2: {
|
|||||||
options = {
|
options = {
|
||||||
hoist_props: true,
|
hoist_props: true,
|
||||||
reduce_vars: true,
|
reduce_vars: true,
|
||||||
top_retain: [ "x", "y" ],
|
top_retain: [
|
||||||
|
"x",
|
||||||
|
"y"
|
||||||
|
],
|
||||||
toplevel: true,
|
toplevel: true,
|
||||||
unused: true,
|
unused: true,
|
||||||
}
|
}
|
||||||
@@ -658,7 +664,7 @@ issue_2519: {
|
|||||||
}
|
}
|
||||||
expect: {
|
expect: {
|
||||||
function testFunc() {
|
function testFunc() {
|
||||||
return 1 * ((6 + 5) / 2);
|
return +((6 + 5) / 2);
|
||||||
}
|
}
|
||||||
console.log(testFunc());
|
console.log(testFunc());
|
||||||
}
|
}
|
||||||
@@ -746,9 +752,9 @@ issue_3046: {
|
|||||||
issue_3071_1: {
|
issue_3071_1: {
|
||||||
options = {
|
options = {
|
||||||
evaluate: true,
|
evaluate: true,
|
||||||
|
hoist_props: true,
|
||||||
inline: true,
|
inline: true,
|
||||||
join_vars: true,
|
join_vars: true,
|
||||||
hoist_props: true,
|
|
||||||
passes: 3,
|
passes: 3,
|
||||||
reduce_vars: true,
|
reduce_vars: true,
|
||||||
sequences: true,
|
sequences: true,
|
||||||
@@ -773,9 +779,9 @@ issue_3071_1: {
|
|||||||
issue_3071_2: {
|
issue_3071_2: {
|
||||||
options = {
|
options = {
|
||||||
evaluate: true,
|
evaluate: true,
|
||||||
|
hoist_props: true,
|
||||||
inline: true,
|
inline: true,
|
||||||
join_vars: true,
|
join_vars: true,
|
||||||
hoist_props: true,
|
|
||||||
passes: 3,
|
passes: 3,
|
||||||
reduce_vars: true,
|
reduce_vars: true,
|
||||||
sequences: true,
|
sequences: true,
|
||||||
@@ -800,9 +806,9 @@ issue_3071_2: {
|
|||||||
issue_3071_2_toplevel: {
|
issue_3071_2_toplevel: {
|
||||||
options = {
|
options = {
|
||||||
evaluate: true,
|
evaluate: true,
|
||||||
|
hoist_props: true,
|
||||||
inline: true,
|
inline: true,
|
||||||
join_vars: true,
|
join_vars: true,
|
||||||
hoist_props: true,
|
|
||||||
passes: 3,
|
passes: 3,
|
||||||
reduce_vars: true,
|
reduce_vars: true,
|
||||||
sequences: true,
|
sequences: true,
|
||||||
@@ -856,3 +862,55 @@ issue_3071_3: {
|
|||||||
}
|
}
|
||||||
expect_stdout: "2"
|
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"
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,55 +1,107 @@
|
|||||||
html_comment_in_expression: {
|
html_comment_in_expression: {
|
||||||
input: {
|
input: {
|
||||||
function f(a, b, x, y) { return a < !--b && x-- > y; }
|
(function(a, b) {
|
||||||
|
console.log(a < !--b && a-- > b, a, b);
|
||||||
|
})(1, 2);
|
||||||
}
|
}
|
||||||
expect_exact: "function f(a,b,x,y){return a< !--b&&x-- >y}";
|
expect_exact: "(function(a,b){console.log(a<! --b&&a-- >b,a,b)})(1,2);"
|
||||||
|
expect_stdout: "false 1 1"
|
||||||
}
|
}
|
||||||
|
|
||||||
html_comment_in_less_than: {
|
html_comment_in_less_than: {
|
||||||
input: {
|
input: {
|
||||||
function f(a, b) { return a < !--b; }
|
(function(a, b, c) {
|
||||||
|
console.log(
|
||||||
|
a < !--b,
|
||||||
|
a < !--b + c,
|
||||||
|
a + b < !--c,
|
||||||
|
a, b, c
|
||||||
|
);
|
||||||
|
})(1, 2, 3);
|
||||||
}
|
}
|
||||||
expect_exact: "function f(a,b){return a< !--b}";
|
expect_exact: "(function(a,b,c){console.log(a<! --b,a<! --b+c,a+b<! --c,a,b,c)})(1,2,3);"
|
||||||
|
expect_stdout: "false true false 1 0 2"
|
||||||
}
|
}
|
||||||
|
|
||||||
html_comment_in_left_shift: {
|
html_comment_in_left_shift: {
|
||||||
input: {
|
input: {
|
||||||
function f(a, b) { return a << !--b; }
|
(function(a, b, c) {
|
||||||
|
console.log(
|
||||||
|
a << !--b,
|
||||||
|
a << !--b + c,
|
||||||
|
a + b << !--c,
|
||||||
|
a, b, c
|
||||||
|
);
|
||||||
|
})(1, 2, 3);
|
||||||
}
|
}
|
||||||
expect_exact: "function f(a,b){return a<< !--b}";
|
expect_exact: "(function(a,b,c){console.log(a<<! --b,a<<! --b+c,a+b<<! --c,a,b,c)})(1,2,3);"
|
||||||
}
|
expect_stdout: "1 16 1 1 0 2"
|
||||||
|
|
||||||
html_comment_in_right_shift: {
|
|
||||||
input: {
|
|
||||||
function f(a, b) { return a-- >> b; }
|
|
||||||
}
|
|
||||||
expect_exact: "function f(a,b){return a-- >>b}";
|
|
||||||
}
|
|
||||||
|
|
||||||
html_comment_in_zero_fill_right_shift: {
|
|
||||||
input: {
|
|
||||||
function f(a, b) { return a-- >>> b; }
|
|
||||||
}
|
|
||||||
expect_exact: "function f(a,b){return a-- >>>b}";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
html_comment_in_greater_than: {
|
html_comment_in_greater_than: {
|
||||||
input: {
|
input: {
|
||||||
function f(a, b) { return a-- > b; }
|
(function(a, b, c) {
|
||||||
|
console.log(
|
||||||
|
a-- > b,
|
||||||
|
a-- > b + c,
|
||||||
|
a + b-- > c,
|
||||||
|
a, b, c
|
||||||
|
);
|
||||||
|
})(1, 2, 3);
|
||||||
}
|
}
|
||||||
expect_exact: "function f(a,b){return a-- >b}";
|
expect_exact: "(function(a,b,c){console.log(a-- >b,a-- >b+c,a+b-- >c,a,b,c)})(1,2,3);"
|
||||||
|
expect_stdout: "false false false -1 1 3"
|
||||||
}
|
}
|
||||||
|
|
||||||
html_comment_in_greater_than_or_equal: {
|
html_comment_in_greater_than_or_equal: {
|
||||||
input: {
|
input: {
|
||||||
function f(a, b) { return a-- >= b; }
|
(function(a, b, c) {
|
||||||
|
console.log(
|
||||||
|
a-- >= b,
|
||||||
|
a-- >= b + c,
|
||||||
|
a + b-- >= c,
|
||||||
|
a, b, c
|
||||||
|
);
|
||||||
|
})(1, 2, 3);
|
||||||
}
|
}
|
||||||
expect_exact: "function f(a,b){return a-- >=b}";
|
expect_exact: "(function(a,b,c){console.log(a-- >=b,a-- >=b+c,a+b-- >=c,a,b,c)})(1,2,3);"
|
||||||
|
expect_stdout: "false false false -1 1 3"
|
||||||
|
}
|
||||||
|
|
||||||
|
html_comment_in_right_shift: {
|
||||||
|
input: {
|
||||||
|
(function(a, b, c) {
|
||||||
|
console.log(
|
||||||
|
a-- >> b,
|
||||||
|
a-- >> b + c,
|
||||||
|
a + b-- >> c,
|
||||||
|
a, b, c
|
||||||
|
);
|
||||||
|
})(1, 2, 3);
|
||||||
|
}
|
||||||
|
expect_exact: "(function(a,b,c){console.log(a-- >>b,a-- >>b+c,a+b-- >>c,a,b,c)})(1,2,3);"
|
||||||
|
expect_stdout: "0 0 0 -1 1 3"
|
||||||
|
}
|
||||||
|
|
||||||
|
html_comment_in_zero_fill_right_shift: {
|
||||||
|
input: {
|
||||||
|
(function(a, b, c) {
|
||||||
|
console.log(
|
||||||
|
a-- >>> b,
|
||||||
|
a-- >>> b + c,
|
||||||
|
a + b-- >>> c,
|
||||||
|
a, b, c
|
||||||
|
);
|
||||||
|
})(1, 2, 3);
|
||||||
|
}
|
||||||
|
expect_exact: "(function(a,b,c){console.log(a-- >>>b,a-- >>>b+c,a+b-- >>>c,a,b,c)})(1,2,3);"
|
||||||
|
expect_stdout: "0 0 0 -1 1 3"
|
||||||
}
|
}
|
||||||
|
|
||||||
html_comment_in_string_literal: {
|
html_comment_in_string_literal: {
|
||||||
input: {
|
input: {
|
||||||
function f() { return "<!--HTML-->comment in<!--string literal-->"; }
|
console.log("<!--HTML-->comment in<!--string literal-->".length);
|
||||||
}
|
}
|
||||||
expect_exact: 'function f(){return"\\x3c!--HTML--\\x3ecomment in\\x3c!--string literal--\\x3e"}';
|
expect_exact: 'console.log("\\x3c!--HTML--\\x3ecomment in\\x3c!--string literal--\\x3e".length);'
|
||||||
|
expect_stdout: "42"
|
||||||
}
|
}
|
||||||
|
|||||||
1757
test/compress/ie8.js
1757
test/compress/ie8.js
File diff suppressed because it is too large
Load Diff
@@ -1,14 +1,14 @@
|
|||||||
if_return_1: {
|
if_return_1: {
|
||||||
options = {
|
options = {
|
||||||
if_return : true,
|
booleans: true,
|
||||||
sequences : true,
|
comparisons: true,
|
||||||
conditionals : true,
|
conditionals: true,
|
||||||
comparisons : true,
|
dead_code: true,
|
||||||
evaluate : true,
|
evaluate: true,
|
||||||
booleans : true,
|
if_return: true,
|
||||||
unused : true,
|
sequences: true,
|
||||||
side_effects : true,
|
side_effects: true,
|
||||||
dead_code : true,
|
unused: true,
|
||||||
}
|
}
|
||||||
input: {
|
input: {
|
||||||
function f(x) {
|
function f(x) {
|
||||||
@@ -24,15 +24,15 @@ if_return_1: {
|
|||||||
|
|
||||||
if_return_2: {
|
if_return_2: {
|
||||||
options = {
|
options = {
|
||||||
if_return : true,
|
booleans: true,
|
||||||
sequences : true,
|
comparisons: true,
|
||||||
conditionals : true,
|
conditionals: true,
|
||||||
comparisons : true,
|
dead_code: true,
|
||||||
evaluate : true,
|
evaluate: true,
|
||||||
booleans : true,
|
if_return: true,
|
||||||
unused : true,
|
sequences: true,
|
||||||
side_effects : true,
|
side_effects: true,
|
||||||
dead_code : true,
|
unused: true,
|
||||||
}
|
}
|
||||||
input: {
|
input: {
|
||||||
function f(x, y) {
|
function f(x, y) {
|
||||||
@@ -49,15 +49,15 @@ if_return_2: {
|
|||||||
|
|
||||||
if_return_3: {
|
if_return_3: {
|
||||||
options = {
|
options = {
|
||||||
if_return : true,
|
booleans: true,
|
||||||
sequences : true,
|
comparisons: true,
|
||||||
conditionals : true,
|
conditionals: true,
|
||||||
comparisons : true,
|
dead_code: true,
|
||||||
evaluate : true,
|
evaluate: true,
|
||||||
booleans : true,
|
if_return: true,
|
||||||
unused : true,
|
sequences: true,
|
||||||
side_effects : true,
|
side_effects: true,
|
||||||
dead_code : true,
|
unused: true,
|
||||||
}
|
}
|
||||||
input: {
|
input: {
|
||||||
function f(x) {
|
function f(x) {
|
||||||
@@ -75,15 +75,15 @@ if_return_3: {
|
|||||||
|
|
||||||
if_return_4: {
|
if_return_4: {
|
||||||
options = {
|
options = {
|
||||||
if_return : true,
|
booleans: true,
|
||||||
sequences : true,
|
comparisons: true,
|
||||||
conditionals : true,
|
conditionals: true,
|
||||||
comparisons : true,
|
dead_code: true,
|
||||||
evaluate : true,
|
evaluate: true,
|
||||||
booleans : true,
|
if_return: true,
|
||||||
unused : true,
|
sequences: true,
|
||||||
side_effects : true,
|
side_effects: true,
|
||||||
dead_code : true,
|
unused: true,
|
||||||
}
|
}
|
||||||
input: {
|
input: {
|
||||||
function f(x, y) {
|
function f(x, y) {
|
||||||
@@ -100,15 +100,15 @@ if_return_4: {
|
|||||||
|
|
||||||
if_return_5: {
|
if_return_5: {
|
||||||
options = {
|
options = {
|
||||||
if_return : true,
|
booleans: true,
|
||||||
sequences : true,
|
comparisons: true,
|
||||||
conditionals : true,
|
conditionals: true,
|
||||||
comparisons : true,
|
dead_code: true,
|
||||||
evaluate : true,
|
evaluate: true,
|
||||||
booleans : true,
|
if_return: true,
|
||||||
unused : true,
|
sequences: true,
|
||||||
side_effects : true,
|
side_effects: true,
|
||||||
dead_code : true,
|
unused: true,
|
||||||
}
|
}
|
||||||
input: {
|
input: {
|
||||||
function f() {
|
function f() {
|
||||||
@@ -126,15 +126,15 @@ if_return_5: {
|
|||||||
|
|
||||||
if_return_6: {
|
if_return_6: {
|
||||||
options = {
|
options = {
|
||||||
if_return : true,
|
booleans: true,
|
||||||
sequences : true,
|
comparisons: true,
|
||||||
conditionals : true,
|
conditionals: true,
|
||||||
comparisons : true,
|
dead_code: true,
|
||||||
evaluate : true,
|
evaluate: true,
|
||||||
booleans : true,
|
if_return: true,
|
||||||
unused : true,
|
sequences: true,
|
||||||
side_effects : true,
|
side_effects: true,
|
||||||
dead_code : true,
|
unused: true,
|
||||||
}
|
}
|
||||||
input: {
|
input: {
|
||||||
function f(x) {
|
function f(x) {
|
||||||
@@ -150,15 +150,15 @@ if_return_6: {
|
|||||||
|
|
||||||
if_return_7: {
|
if_return_7: {
|
||||||
options = {
|
options = {
|
||||||
if_return : true,
|
booleans: true,
|
||||||
sequences : true,
|
comparisons: true,
|
||||||
conditionals : true,
|
conditionals: true,
|
||||||
comparisons : true,
|
dead_code: true,
|
||||||
evaluate : true,
|
evaluate: true,
|
||||||
booleans : true,
|
if_return: true,
|
||||||
unused : true,
|
sequences: true,
|
||||||
side_effects : true,
|
side_effects: true,
|
||||||
dead_code : true,
|
unused: true,
|
||||||
}
|
}
|
||||||
input: {
|
input: {
|
||||||
function f(x) {
|
function f(x) {
|
||||||
@@ -176,10 +176,10 @@ if_return_7: {
|
|||||||
|
|
||||||
if_return_8: {
|
if_return_8: {
|
||||||
options = {
|
options = {
|
||||||
if_return: true,
|
conditionals: true,
|
||||||
sequences: true,
|
if_return: true,
|
||||||
conditionals: true,
|
sequences: true,
|
||||||
side_effects : true,
|
side_effects: true,
|
||||||
}
|
}
|
||||||
input: {
|
input: {
|
||||||
function f(e) {
|
function f(e) {
|
||||||
@@ -220,15 +220,15 @@ if_return_8: {
|
|||||||
|
|
||||||
issue_1089: {
|
issue_1089: {
|
||||||
options = {
|
options = {
|
||||||
if_return : true,
|
booleans: true,
|
||||||
sequences : true,
|
comparisons: true,
|
||||||
conditionals : true,
|
conditionals: true,
|
||||||
comparisons : true,
|
dead_code: true,
|
||||||
evaluate : true,
|
evaluate: true,
|
||||||
booleans : true,
|
if_return: true,
|
||||||
unused : true,
|
sequences: true,
|
||||||
side_effects : true,
|
side_effects: true,
|
||||||
dead_code : true,
|
unused: true,
|
||||||
}
|
}
|
||||||
input: {
|
input: {
|
||||||
function x() {
|
function x() {
|
||||||
@@ -251,9 +251,9 @@ issue_1089: {
|
|||||||
|
|
||||||
issue_1437: {
|
issue_1437: {
|
||||||
options = {
|
options = {
|
||||||
if_return : true,
|
conditionals: false,
|
||||||
sequences : true,
|
if_return: true,
|
||||||
conditionals : false
|
sequences: true,
|
||||||
}
|
}
|
||||||
input: {
|
input: {
|
||||||
function x() {
|
function x() {
|
||||||
@@ -281,9 +281,9 @@ issue_1437: {
|
|||||||
|
|
||||||
issue_1437_conditionals: {
|
issue_1437_conditionals: {
|
||||||
options = {
|
options = {
|
||||||
conditionals : true,
|
conditionals: true,
|
||||||
if_return : true,
|
if_return: true,
|
||||||
sequences : true
|
sequences: true,
|
||||||
}
|
}
|
||||||
input: {
|
input: {
|
||||||
function x() {
|
function x() {
|
||||||
@@ -396,3 +396,180 @@ 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",
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
|
issue_3600: {
|
||||||
|
options = {
|
||||||
|
if_return: true,
|
||||||
|
inline: true,
|
||||||
|
side_effects: true,
|
||||||
|
unused: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
var c = 0;
|
||||||
|
(function() {
|
||||||
|
if ([ ][c++]); else return;
|
||||||
|
return void function() {
|
||||||
|
var b = --b, a = c = 42;
|
||||||
|
return c;
|
||||||
|
}();
|
||||||
|
})();
|
||||||
|
console.log(c);
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
var c = 0;
|
||||||
|
(function() {
|
||||||
|
if ([][c++]) b = --b, c = 42;
|
||||||
|
var b;
|
||||||
|
})();
|
||||||
|
console.log(c);
|
||||||
|
}
|
||||||
|
expect_stdout: "1"
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,8 +1,17 @@
|
|||||||
non_hoisted_function_after_return: {
|
non_hoisted_function_after_return: {
|
||||||
options = {
|
options = {
|
||||||
hoist_funs: false, dead_code: true, conditionals: true, comparisons: true,
|
booleans: true,
|
||||||
evaluate: true, booleans: true, loops: true, unused: true, keep_fargs: true,
|
comparisons: true,
|
||||||
if_return: true, join_vars: true, side_effects: true
|
conditionals: true,
|
||||||
|
dead_code: true,
|
||||||
|
evaluate: true,
|
||||||
|
hoist_funs: false,
|
||||||
|
if_return: true,
|
||||||
|
join_vars: true,
|
||||||
|
keep_fargs: true,
|
||||||
|
loops: true,
|
||||||
|
side_effects: true,
|
||||||
|
unused: true,
|
||||||
}
|
}
|
||||||
input: {
|
input: {
|
||||||
function foo(x) {
|
function foo(x) {
|
||||||
@@ -21,25 +30,35 @@ non_hoisted_function_after_return: {
|
|||||||
}
|
}
|
||||||
expect: {
|
expect: {
|
||||||
function foo(x) {
|
function foo(x) {
|
||||||
return x ? bar() : baz();
|
return (x ? bar : baz)();
|
||||||
function bar() { return 7 }
|
function bar() { return 7 }
|
||||||
function baz() { return 8 }
|
function baz() { return 8 }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
expect_warnings: [
|
expect_warnings: [
|
||||||
'WARN: Dropping unreachable code [test/compress/issue-1034.js:11,16]',
|
"WARN: Dropping unreachable code [test/compress/issue-1034.js:4,16]",
|
||||||
"WARN: Dropping unreachable code [test/compress/issue-1034.js:14,16]",
|
"WARN: Dropping unreachable code [test/compress/issue-1034.js:7,16]",
|
||||||
"WARN: Dropping unreachable code [test/compress/issue-1034.js:17,12]",
|
"WARN: Dropping unreachable code [test/compress/issue-1034.js:10,12]",
|
||||||
"WARN: Dropping unused function UnusedFunction [test/compress/issue-1034.js:18,21]"
|
"WARN: Dropping unused function UnusedFunction [test/compress/issue-1034.js:11,21]"
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
non_hoisted_function_after_return_2a: {
|
non_hoisted_function_after_return_2a: {
|
||||||
options = {
|
options = {
|
||||||
hoist_funs: false, dead_code: true, conditionals: true, comparisons: true,
|
booleans: true,
|
||||||
evaluate: true, booleans: true, loops: true, unused: true, keep_fargs: true,
|
collapse_vars: false,
|
||||||
if_return: true, join_vars: true, side_effects: true,
|
comparisons: true,
|
||||||
collapse_vars: false, passes: 2, warnings: "verbose"
|
conditionals: true,
|
||||||
|
dead_code: true,
|
||||||
|
evaluate: true,
|
||||||
|
hoist_funs: false,
|
||||||
|
if_return: true,
|
||||||
|
join_vars: true,
|
||||||
|
keep_fargs: true,
|
||||||
|
loops: true,
|
||||||
|
passes: 2,
|
||||||
|
side_effects: true,
|
||||||
|
unused: true,
|
||||||
}
|
}
|
||||||
input: {
|
input: {
|
||||||
function foo(x) {
|
function foo(x) {
|
||||||
@@ -65,28 +84,37 @@ non_hoisted_function_after_return_2a: {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
expect_warnings: [
|
expect_warnings: [
|
||||||
"WARN: Dropping unreachable code [test/compress/issue-1034.js:48,16]",
|
"WARN: Dropping unreachable code [test/compress/issue-1034.js:4,16]",
|
||||||
"WARN: Declarations in unreachable code! [test/compress/issue-1034.js:48,16]",
|
"WARN: Declarations in unreachable code! [test/compress/issue-1034.js:4,16]",
|
||||||
"WARN: Dropping unreachable code [test/compress/issue-1034.js:51,16]",
|
"WARN: Dropping unreachable code [test/compress/issue-1034.js:7,16]",
|
||||||
"WARN: Declarations in unreachable code! [test/compress/issue-1034.js:51,16]",
|
"WARN: Declarations in unreachable code! [test/compress/issue-1034.js:7,16]",
|
||||||
"WARN: Dropping unused variable a [test/compress/issue-1034.js:48,20]",
|
"WARN: Dropping unused variable a [test/compress/issue-1034.js:4,20]",
|
||||||
"WARN: Dropping unused function nope [test/compress/issue-1034.js:55,21]",
|
"WARN: Dropping unused function nope [test/compress/issue-1034.js:11,21]",
|
||||||
"WARN: pass 0: last_count: Infinity, count: 37",
|
"INFO: pass 0: last_count: Infinity, count: 37",
|
||||||
"WARN: Dropping unreachable code [test/compress/issue-1034.js:53,12]",
|
"WARN: Dropping unreachable code [test/compress/issue-1034.js:9,12]",
|
||||||
"WARN: Declarations in unreachable code! [test/compress/issue-1034.js:53,12]",
|
"WARN: Declarations in unreachable code! [test/compress/issue-1034.js:9,12]",
|
||||||
"WARN: Dropping unreachable code [test/compress/issue-1034.js:56,12]",
|
"WARN: Dropping unreachable code [test/compress/issue-1034.js:12,12]",
|
||||||
"WARN: Dropping unused variable b [test/compress/issue-1034.js:51,20]",
|
"INFO: Dropping unused variable b [test/compress/issue-1034.js:7,20]",
|
||||||
"WARN: Dropping unused variable c [test/compress/issue-1034.js:53,16]",
|
"INFO: Dropping unused variable c [test/compress/issue-1034.js:9,16]",
|
||||||
"WARN: pass 1: last_count: 37, count: 18",
|
"INFO: pass 1: last_count: 37, count: 18",
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
non_hoisted_function_after_return_2b: {
|
non_hoisted_function_after_return_2b: {
|
||||||
options = {
|
options = {
|
||||||
hoist_funs: false, dead_code: true, conditionals: true, comparisons: true,
|
booleans: true,
|
||||||
evaluate: true, booleans: true, loops: true, unused: true, keep_fargs: true,
|
collapse_vars: false,
|
||||||
if_return: true, join_vars: true, side_effects: true,
|
comparisons: true,
|
||||||
collapse_vars: false
|
conditionals: true,
|
||||||
|
dead_code: true,
|
||||||
|
evaluate: true,
|
||||||
|
hoist_funs: false,
|
||||||
|
if_return: true,
|
||||||
|
join_vars: true,
|
||||||
|
keep_fargs: true,
|
||||||
|
loops: true,
|
||||||
|
side_effects: true,
|
||||||
|
unused: true,
|
||||||
}
|
}
|
||||||
input: {
|
input: {
|
||||||
function foo(x) {
|
function foo(x) {
|
||||||
@@ -110,20 +138,28 @@ non_hoisted_function_after_return_2b: {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
expect_warnings: [
|
expect_warnings: [
|
||||||
// duplicate warnings no longer emitted
|
"WARN: Dropping unreachable code [test/compress/issue-1034.js:6,16]",
|
||||||
"WARN: Dropping unreachable code [test/compress/issue-1034.js:97,16]",
|
"WARN: Declarations in unreachable code! [test/compress/issue-1034.js:6,16]",
|
||||||
"WARN: Declarations in unreachable code! [test/compress/issue-1034.js:97,16]",
|
"WARN: Dropping unreachable code [test/compress/issue-1034.js:8,12]",
|
||||||
"WARN: Dropping unreachable code [test/compress/issue-1034.js:99,12]",
|
"WARN: Declarations in unreachable code! [test/compress/issue-1034.js:8,12]",
|
||||||
"WARN: Declarations in unreachable code! [test/compress/issue-1034.js:99,12]",
|
"WARN: Dropping unreachable code [test/compress/issue-1034.js:12,12]",
|
||||||
"WARN: Dropping unreachable code [test/compress/issue-1034.js:103,12]",
|
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
non_hoisted_function_after_return_strict: {
|
non_hoisted_function_after_return_strict: {
|
||||||
options = {
|
options = {
|
||||||
hoist_funs: false, dead_code: true, conditionals: true, comparisons: true,
|
booleans: true,
|
||||||
evaluate: true, booleans: true, loops: true, unused: true, keep_fargs: true,
|
comparisons: true,
|
||||||
if_return: true, join_vars: true, side_effects: true
|
conditionals: true,
|
||||||
|
dead_code: true,
|
||||||
|
evaluate: true,
|
||||||
|
hoist_funs: false,
|
||||||
|
if_return: true,
|
||||||
|
join_vars: true,
|
||||||
|
keep_fargs: true,
|
||||||
|
loops: true,
|
||||||
|
side_effects: true,
|
||||||
|
unused: true,
|
||||||
}
|
}
|
||||||
input: {
|
input: {
|
||||||
"use strict";
|
"use strict";
|
||||||
@@ -145,7 +181,7 @@ non_hoisted_function_after_return_strict: {
|
|||||||
expect: {
|
expect: {
|
||||||
"use strict";
|
"use strict";
|
||||||
function foo(x) {
|
function foo(x) {
|
||||||
return x ? bar() : baz();
|
return (x ? bar : baz)();
|
||||||
function bar() { return 7 }
|
function bar() { return 7 }
|
||||||
function baz() { return 8 }
|
function baz() { return 8 }
|
||||||
}
|
}
|
||||||
@@ -153,19 +189,29 @@ non_hoisted_function_after_return_strict: {
|
|||||||
}
|
}
|
||||||
expect_stdout: "8 7"
|
expect_stdout: "8 7"
|
||||||
expect_warnings: [
|
expect_warnings: [
|
||||||
"WARN: Dropping unreachable code [test/compress/issue-1034.js:133,16]",
|
"WARN: Dropping unreachable code [test/compress/issue-1034.js:5,16]",
|
||||||
"WARN: Dropping unreachable code [test/compress/issue-1034.js:136,16]",
|
"WARN: Dropping unreachable code [test/compress/issue-1034.js:8,16]",
|
||||||
"WARN: Dropping unreachable code [test/compress/issue-1034.js:139,12]",
|
"WARN: Dropping unreachable code [test/compress/issue-1034.js:11,12]",
|
||||||
"WARN: Dropping unused function UnusedFunction [test/compress/issue-1034.js:140,21]",
|
"WARN: Dropping unused function UnusedFunction [test/compress/issue-1034.js:12,21]",
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
non_hoisted_function_after_return_2a_strict: {
|
non_hoisted_function_after_return_2a_strict: {
|
||||||
options = {
|
options = {
|
||||||
hoist_funs: false, dead_code: true, conditionals: true, comparisons: true,
|
booleans: true,
|
||||||
evaluate: true, booleans: true, loops: true, unused: true, keep_fargs: true,
|
collapse_vars: false,
|
||||||
if_return: true, join_vars: true, side_effects: true,
|
comparisons: true,
|
||||||
collapse_vars: false, passes: 2, warnings: "verbose"
|
conditionals: true,
|
||||||
|
dead_code: true,
|
||||||
|
evaluate: true,
|
||||||
|
hoist_funs: false,
|
||||||
|
if_return: true,
|
||||||
|
join_vars: true,
|
||||||
|
keep_fargs: true,
|
||||||
|
loops: true,
|
||||||
|
passes: 2,
|
||||||
|
side_effects: true,
|
||||||
|
unused: true,
|
||||||
}
|
}
|
||||||
input: {
|
input: {
|
||||||
"use strict";
|
"use strict";
|
||||||
@@ -196,28 +242,37 @@ non_hoisted_function_after_return_2a_strict: {
|
|||||||
}
|
}
|
||||||
expect_stdout: "5 6"
|
expect_stdout: "5 6"
|
||||||
expect_warnings: [
|
expect_warnings: [
|
||||||
"WARN: Dropping unreachable code [test/compress/issue-1034.js:175,16]",
|
"WARN: Dropping unreachable code [test/compress/issue-1034.js:5,16]",
|
||||||
"WARN: Declarations in unreachable code! [test/compress/issue-1034.js:175,16]",
|
"WARN: Declarations in unreachable code! [test/compress/issue-1034.js:5,16]",
|
||||||
"WARN: Dropping unreachable code [test/compress/issue-1034.js:178,16]",
|
"WARN: Dropping unreachable code [test/compress/issue-1034.js:8,16]",
|
||||||
"WARN: Declarations in unreachable code! [test/compress/issue-1034.js:178,16]",
|
"WARN: Declarations in unreachable code! [test/compress/issue-1034.js:8,16]",
|
||||||
"WARN: Dropping unused variable a [test/compress/issue-1034.js:175,20]",
|
"WARN: Dropping unused variable a [test/compress/issue-1034.js:5,20]",
|
||||||
"WARN: Dropping unused function nope [test/compress/issue-1034.js:182,21]",
|
"WARN: Dropping unused function nope [test/compress/issue-1034.js:12,21]",
|
||||||
"WARN: pass 0: last_count: Infinity, count: 48",
|
"INFO: pass 0: last_count: Infinity, count: 48",
|
||||||
"WARN: Dropping unreachable code [test/compress/issue-1034.js:180,12]",
|
"WARN: Dropping unreachable code [test/compress/issue-1034.js:10,12]",
|
||||||
"WARN: Declarations in unreachable code! [test/compress/issue-1034.js:180,12]",
|
"WARN: Declarations in unreachable code! [test/compress/issue-1034.js:10,12]",
|
||||||
"WARN: Dropping unreachable code [test/compress/issue-1034.js:183,12]",
|
"WARN: Dropping unreachable code [test/compress/issue-1034.js:13,12]",
|
||||||
"WARN: Dropping unused variable b [test/compress/issue-1034.js:178,20]",
|
"INFO: Dropping unused variable b [test/compress/issue-1034.js:8,20]",
|
||||||
"WARN: Dropping unused variable c [test/compress/issue-1034.js:180,16]",
|
"INFO: Dropping unused variable c [test/compress/issue-1034.js:10,16]",
|
||||||
"WARN: pass 1: last_count: 48, count: 29",
|
"INFO: pass 1: last_count: 48, count: 29",
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
non_hoisted_function_after_return_2b_strict: {
|
non_hoisted_function_after_return_2b_strict: {
|
||||||
options = {
|
options = {
|
||||||
hoist_funs: false, dead_code: true, conditionals: true, comparisons: true,
|
booleans: true,
|
||||||
evaluate: true, booleans: true, loops: true, unused: true, keep_fargs: true,
|
collapse_vars: false,
|
||||||
if_return: true, join_vars: true, side_effects: true,
|
comparisons: true,
|
||||||
collapse_vars: false
|
conditionals: true,
|
||||||
|
dead_code: true,
|
||||||
|
evaluate: true,
|
||||||
|
hoist_funs: false,
|
||||||
|
if_return: true,
|
||||||
|
join_vars: true,
|
||||||
|
keep_fargs: true,
|
||||||
|
loops: true,
|
||||||
|
side_effects: true,
|
||||||
|
unused: true,
|
||||||
}
|
}
|
||||||
input: {
|
input: {
|
||||||
"use strict";
|
"use strict";
|
||||||
@@ -246,11 +301,10 @@ non_hoisted_function_after_return_2b_strict: {
|
|||||||
}
|
}
|
||||||
expect_stdout: "5 6"
|
expect_stdout: "5 6"
|
||||||
expect_warnings: [
|
expect_warnings: [
|
||||||
// duplicate warnings no longer emitted
|
"WARN: Dropping unreachable code [test/compress/issue-1034.js:7,16]",
|
||||||
"WARN: Dropping unreachable code [test/compress/issue-1034.js:229,16]",
|
"WARN: Declarations in unreachable code! [test/compress/issue-1034.js:7,16]",
|
||||||
"WARN: Declarations in unreachable code! [test/compress/issue-1034.js:229,16]",
|
"WARN: Dropping unreachable code [test/compress/issue-1034.js:9,12]",
|
||||||
"WARN: Dropping unreachable code [test/compress/issue-1034.js:231,12]",
|
"WARN: Declarations in unreachable code! [test/compress/issue-1034.js:9,12]",
|
||||||
"WARN: Declarations in unreachable code! [test/compress/issue-1034.js:231,12]",
|
"WARN: Dropping unreachable code [test/compress/issue-1034.js:13,12]",
|
||||||
"WARN: Dropping unreachable code [test/compress/issue-1034.js:235,12]",
|
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ const_pragma: {
|
|||||||
evaluate: true,
|
evaluate: true,
|
||||||
reduce_funcs: true,
|
reduce_funcs: true,
|
||||||
reduce_vars: true,
|
reduce_vars: true,
|
||||||
};
|
}
|
||||||
|
|
||||||
input: {
|
input: {
|
||||||
/** @const */ var goog = goog || {};
|
/** @const */ var goog = goog || {};
|
||||||
@@ -19,7 +19,7 @@ not_const: {
|
|||||||
evaluate: true,
|
evaluate: true,
|
||||||
reduce_funcs: true,
|
reduce_funcs: true,
|
||||||
reduce_vars: true,
|
reduce_vars: true,
|
||||||
};
|
}
|
||||||
|
|
||||||
input: {
|
input: {
|
||||||
var goog = goog || {};
|
var goog = goog || {};
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
with_in_global_scope: {
|
with_in_global_scope: {
|
||||||
options = {
|
options = {
|
||||||
unused: true
|
unused: true,
|
||||||
}
|
}
|
||||||
input: {
|
input: {
|
||||||
var o = 42;
|
var o = 42;
|
||||||
@@ -18,7 +18,7 @@ with_in_global_scope: {
|
|||||||
}
|
}
|
||||||
with_in_function_scope: {
|
with_in_function_scope: {
|
||||||
options = {
|
options = {
|
||||||
unused: true
|
unused: true,
|
||||||
}
|
}
|
||||||
input: {
|
input: {
|
||||||
function foo() {
|
function foo() {
|
||||||
@@ -40,7 +40,7 @@ with_in_function_scope: {
|
|||||||
}
|
}
|
||||||
compress_with_with_in_other_scope: {
|
compress_with_with_in_other_scope: {
|
||||||
options = {
|
options = {
|
||||||
unused: true
|
unused: true,
|
||||||
}
|
}
|
||||||
input: {
|
input: {
|
||||||
function foo() {
|
function foo() {
|
||||||
@@ -69,7 +69,7 @@ compress_with_with_in_other_scope: {
|
|||||||
}
|
}
|
||||||
with_using_existing_variable_outside_scope: {
|
with_using_existing_variable_outside_scope: {
|
||||||
options = {
|
options = {
|
||||||
unused: true
|
unused: true,
|
||||||
}
|
}
|
||||||
input: {
|
input: {
|
||||||
function f() {
|
function f() {
|
||||||
@@ -99,7 +99,7 @@ with_using_existing_variable_outside_scope: {
|
|||||||
}
|
}
|
||||||
check_drop_unused_in_peer_function: {
|
check_drop_unused_in_peer_function: {
|
||||||
options = {
|
options = {
|
||||||
unused: true
|
unused: true,
|
||||||
}
|
}
|
||||||
input: {
|
input: {
|
||||||
function outer() {
|
function outer() {
|
||||||
@@ -148,7 +148,7 @@ check_drop_unused_in_peer_function: {
|
|||||||
|
|
||||||
Infinity_not_in_with_scope: {
|
Infinity_not_in_with_scope: {
|
||||||
options = {
|
options = {
|
||||||
unused: true
|
unused: true,
|
||||||
}
|
}
|
||||||
input: {
|
input: {
|
||||||
var o = { Infinity: 'oInfinity' };
|
var o = { Infinity: 'oInfinity' };
|
||||||
@@ -164,7 +164,7 @@ Infinity_not_in_with_scope: {
|
|||||||
|
|
||||||
Infinity_in_with_scope: {
|
Infinity_in_with_scope: {
|
||||||
options = {
|
options = {
|
||||||
unused: true
|
unused: true,
|
||||||
}
|
}
|
||||||
input: {
|
input: {
|
||||||
var o = { Infinity: 'oInfinity' };
|
var o = { Infinity: 'oInfinity' };
|
||||||
@@ -180,19 +180,19 @@ Infinity_in_with_scope: {
|
|||||||
|
|
||||||
assorted_Infinity_NaN_undefined_in_with_scope: {
|
assorted_Infinity_NaN_undefined_in_with_scope: {
|
||||||
options = {
|
options = {
|
||||||
unused: true,
|
booleans: true,
|
||||||
evaluate: true,
|
comparisons: true,
|
||||||
dead_code: true,
|
conditionals: true,
|
||||||
conditionals: true,
|
dead_code: true,
|
||||||
comparisons: true,
|
evaluate: true,
|
||||||
booleans: true,
|
hoist_funs: true,
|
||||||
hoist_funs: true,
|
if_return: true,
|
||||||
keep_fargs: true,
|
join_vars: true,
|
||||||
if_return: true,
|
keep_fargs: true,
|
||||||
join_vars: true,
|
|
||||||
side_effects: true,
|
|
||||||
sequences: false,
|
|
||||||
keep_infinity: false,
|
keep_infinity: false,
|
||||||
|
sequences: false,
|
||||||
|
side_effects: true,
|
||||||
|
unused: true,
|
||||||
}
|
}
|
||||||
input: {
|
input: {
|
||||||
var f = console.log;
|
var f = console.log;
|
||||||
@@ -242,19 +242,19 @@ assorted_Infinity_NaN_undefined_in_with_scope: {
|
|||||||
|
|
||||||
assorted_Infinity_NaN_undefined_in_with_scope_keep_infinity: {
|
assorted_Infinity_NaN_undefined_in_with_scope_keep_infinity: {
|
||||||
options = {
|
options = {
|
||||||
unused: true,
|
booleans: true,
|
||||||
evaluate: true,
|
comparisons: true,
|
||||||
dead_code: true,
|
conditionals: true,
|
||||||
conditionals: true,
|
dead_code: true,
|
||||||
comparisons: true,
|
evaluate: true,
|
||||||
booleans: true,
|
hoist_funs: true,
|
||||||
hoist_funs: true,
|
if_return: true,
|
||||||
keep_fargs: true,
|
join_vars: true,
|
||||||
if_return: true,
|
keep_fargs: true,
|
||||||
join_vars: true,
|
|
||||||
side_effects: true,
|
|
||||||
sequences: false,
|
|
||||||
keep_infinity: true,
|
keep_infinity: true,
|
||||||
|
sequences: false,
|
||||||
|
side_effects: true,
|
||||||
|
unused: true,
|
||||||
}
|
}
|
||||||
input: {
|
input: {
|
||||||
var f = console.log;
|
var f = console.log;
|
||||||
|
|||||||
@@ -1,11 +1,15 @@
|
|||||||
keep_name_of_getter: {
|
keep_name_of_getter: {
|
||||||
options = { unused: true };
|
options = {
|
||||||
|
unused: true,
|
||||||
|
}
|
||||||
input: { a = { get foo () {} } }
|
input: { a = { get foo () {} } }
|
||||||
expect: { a = { get foo () {} } }
|
expect: { a = { get foo () {} } }
|
||||||
}
|
}
|
||||||
|
|
||||||
keep_name_of_setter: {
|
keep_name_of_setter: {
|
||||||
options = { unused: true };
|
options = {
|
||||||
|
unused: true,
|
||||||
|
}
|
||||||
input: { a = { set foo () {} } }
|
input: { a = { set foo () {} } }
|
||||||
expect: { a = { set foo () {} } }
|
expect: { a = { set foo () {} } }
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
mangle_keep_fnames_false: {
|
mangle_keep_fnames_false: {
|
||||||
options = {
|
options = {
|
||||||
keep_fnames : true,
|
keep_fargs: true,
|
||||||
keep_fargs : true,
|
keep_fnames: true,
|
||||||
}
|
}
|
||||||
mangle = {
|
mangle = {
|
||||||
keep_fnames : false,
|
keep_fnames : false,
|
||||||
@@ -26,8 +26,8 @@ mangle_keep_fnames_false: {
|
|||||||
|
|
||||||
mangle_keep_fnames_true: {
|
mangle_keep_fnames_true: {
|
||||||
options = {
|
options = {
|
||||||
keep_fnames : true,
|
keep_fargs: true,
|
||||||
keep_fargs : true,
|
keep_fnames: true,
|
||||||
}
|
}
|
||||||
mangle = {
|
mangle = {
|
||||||
keep_fnames : true,
|
keep_fnames : true,
|
||||||
|
|||||||
@@ -1,14 +1,14 @@
|
|||||||
pure_function_calls: {
|
pure_function_calls: {
|
||||||
options = {
|
options = {
|
||||||
evaluate : true,
|
booleans: true,
|
||||||
conditionals : true,
|
comparisons: true,
|
||||||
comparisons : true,
|
conditionals: true,
|
||||||
side_effects : true,
|
evaluate: true,
|
||||||
booleans : true,
|
if_return: true,
|
||||||
unused : true,
|
join_vars: true,
|
||||||
if_return : true,
|
negate_iife: true,
|
||||||
join_vars : true,
|
side_effects: true,
|
||||||
negate_iife : true,
|
unused: true,
|
||||||
}
|
}
|
||||||
input: {
|
input: {
|
||||||
// pure top-level IIFE will be dropped
|
// pure top-level IIFE will be dropped
|
||||||
@@ -48,28 +48,28 @@ pure_function_calls: {
|
|||||||
a.b(), f.g();
|
a.b(), f.g();
|
||||||
}
|
}
|
||||||
expect_warnings: [
|
expect_warnings: [
|
||||||
"WARN: Dropping __PURE__ call [test/compress/issue-1261.js:16,8]",
|
"WARN: Dropping __PURE__ call [test/compress/issue-1261.js:3,8]",
|
||||||
"WARN: Dropping side-effect-free statement [test/compress/issue-1261.js:16,8]",
|
"WARN: Dropping side-effect-free statement [test/compress/issue-1261.js:3,8]",
|
||||||
"WARN: Dropping __PURE__ call [test/compress/issue-1261.js:29,37]",
|
"WARN: Dropping __PURE__ call [test/compress/issue-1261.js:16,37]",
|
||||||
"WARN: Dropping unused variable iife2 [test/compress/issue-1261.js:29,16]",
|
"WARN: Dropping unused variable iife2 [test/compress/issue-1261.js:16,16]",
|
||||||
"WARN: Dropping side-effect-free statement [test/compress/issue-1261.js:27,8]",
|
"WARN: Dropping side-effect-free statement [test/compress/issue-1261.js:14,8]",
|
||||||
"WARN: Dropping __PURE__ call [test/compress/issue-1261.js:37,8]",
|
"WARN: Dropping __PURE__ call [test/compress/issue-1261.js:24,8]",
|
||||||
"WARN: Dropping __PURE__ call [test/compress/issue-1261.js:38,31]",
|
"WARN: Dropping __PURE__ call [test/compress/issue-1261.js:25,31]",
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
pure_function_calls_toplevel: {
|
pure_function_calls_toplevel: {
|
||||||
options = {
|
options = {
|
||||||
evaluate : true,
|
booleans: true,
|
||||||
conditionals : true,
|
comparisons: true,
|
||||||
comparisons : true,
|
conditionals: true,
|
||||||
side_effects : true,
|
evaluate: true,
|
||||||
booleans : true,
|
if_return: true,
|
||||||
unused : true,
|
join_vars: true,
|
||||||
if_return : true,
|
negate_iife: true,
|
||||||
join_vars : true,
|
side_effects: true,
|
||||||
negate_iife : true,
|
toplevel: true,
|
||||||
toplevel : true,
|
unused: true,
|
||||||
}
|
}
|
||||||
input: {
|
input: {
|
||||||
// pure top-level IIFE will be dropped
|
// pure top-level IIFE will be dropped
|
||||||
@@ -110,17 +110,17 @@ pure_function_calls_toplevel: {
|
|||||||
a.b(), f.g();
|
a.b(), f.g();
|
||||||
}
|
}
|
||||||
expect_warnings: [
|
expect_warnings: [
|
||||||
"WARN: Dropping __PURE__ call [test/compress/issue-1261.js:77,8]",
|
"WARN: Dropping __PURE__ call [test/compress/issue-1261.js:3,8]",
|
||||||
"WARN: Dropping side-effect-free statement [test/compress/issue-1261.js:77,8]",
|
"WARN: Dropping side-effect-free statement [test/compress/issue-1261.js:3,8]",
|
||||||
"WARN: Dropping __PURE__ call [test/compress/issue-1261.js:90,37]",
|
"WARN: Dropping __PURE__ call [test/compress/issue-1261.js:16,37]",
|
||||||
"WARN: Dropping unused variable iife2 [test/compress/issue-1261.js:90,16]",
|
"WARN: Dropping unused variable iife2 [test/compress/issue-1261.js:16,16]",
|
||||||
"WARN: Dropping side-effect-free statement [test/compress/issue-1261.js:88,8]",
|
"WARN: Dropping side-effect-free statement [test/compress/issue-1261.js:14,8]",
|
||||||
"WARN: Dropping __PURE__ call [test/compress/issue-1261.js:105,8]",
|
"WARN: Dropping __PURE__ call [test/compress/issue-1261.js:31,8]",
|
||||||
"WARN: Dropping __PURE__ call [test/compress/issue-1261.js:106,31]",
|
"WARN: Dropping __PURE__ call [test/compress/issue-1261.js:32,31]",
|
||||||
"WARN: Dropping __PURE__ call [test/compress/issue-1261.js:82,33]",
|
"WARN: Dropping __PURE__ call [test/compress/issue-1261.js:8,33]",
|
||||||
"WARN: Dropping unused variable iife1 [test/compress/issue-1261.js:82,12]",
|
"WARN: Dropping unused variable iife1 [test/compress/issue-1261.js:8,12]",
|
||||||
"WARN: Dropping __PURE__ call [test/compress/issue-1261.js:98,45]",
|
"WARN: Dropping __PURE__ call [test/compress/issue-1261.js:24,45]",
|
||||||
"WARN: Dropping unused variable MyClass [test/compress/issue-1261.js:98,12]",
|
"WARN: Dropping unused variable MyClass [test/compress/issue-1261.js:24,12]",
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -155,29 +155,29 @@ should_warn: {
|
|||||||
baz();
|
baz();
|
||||||
}
|
}
|
||||||
expect_warnings: [
|
expect_warnings: [
|
||||||
"WARN: Dropping __PURE__ call [test/compress/issue-1261.js:135,61]",
|
"WARN: Dropping __PURE__ call [test/compress/issue-1261.js:1,61]",
|
||||||
"WARN: Dropping __PURE__ call [test/compress/issue-1261.js:135,23]",
|
"WARN: Dropping __PURE__ call [test/compress/issue-1261.js:1,23]",
|
||||||
"WARN: Dropping side-effect-free statement [test/compress/issue-1261.js:135,23]",
|
"WARN: Dropping side-effect-free statement [test/compress/issue-1261.js:1,23]",
|
||||||
"WARN: Boolean || always true [test/compress/issue-1261.js:136,23]",
|
"WARN: Boolean || always true [test/compress/issue-1261.js:2,23]",
|
||||||
"WARN: Dropping __PURE__ call [test/compress/issue-1261.js:136,23]",
|
"WARN: Dropping __PURE__ call [test/compress/issue-1261.js:2,23]",
|
||||||
"WARN: Condition always true [test/compress/issue-1261.js:136,23]",
|
"WARN: Condition always true [test/compress/issue-1261.js:2,23]",
|
||||||
"WARN: Condition left of || always true [test/compress/issue-1261.js:137,8]",
|
"WARN: Condition left of || always true [test/compress/issue-1261.js:3,8]",
|
||||||
"WARN: Condition always true [test/compress/issue-1261.js:137,8]",
|
"WARN: Condition always true [test/compress/issue-1261.js:3,8]",
|
||||||
"WARN: Boolean && always false [test/compress/issue-1261.js:138,23]",
|
"WARN: Boolean && always false [test/compress/issue-1261.js:4,23]",
|
||||||
"WARN: Dropping __PURE__ call [test/compress/issue-1261.js:138,23]",
|
"WARN: Dropping __PURE__ call [test/compress/issue-1261.js:4,23]",
|
||||||
"WARN: Condition always false [test/compress/issue-1261.js:138,23]",
|
"WARN: Condition always false [test/compress/issue-1261.js:4,23]",
|
||||||
"WARN: Condition left of && always false [test/compress/issue-1261.js:139,8]",
|
"WARN: Condition left of && always false [test/compress/issue-1261.js:5,8]",
|
||||||
"WARN: Condition always false [test/compress/issue-1261.js:139,8]",
|
"WARN: Condition always false [test/compress/issue-1261.js:5,8]",
|
||||||
"WARN: + in boolean context always true [test/compress/issue-1261.js:140,23]",
|
"WARN: + in boolean context always true [test/compress/issue-1261.js:6,23]",
|
||||||
"WARN: Dropping __PURE__ call [test/compress/issue-1261.js:140,23]",
|
"WARN: Dropping __PURE__ call [test/compress/issue-1261.js:6,23]",
|
||||||
"WARN: Condition always true [test/compress/issue-1261.js:140,23]",
|
"WARN: Condition always true [test/compress/issue-1261.js:6,23]",
|
||||||
"WARN: + in boolean context always true [test/compress/issue-1261.js:141,8]",
|
"WARN: + in boolean context always true [test/compress/issue-1261.js:7,8]",
|
||||||
"WARN: Dropping __PURE__ call [test/compress/issue-1261.js:141,31]",
|
"WARN: Dropping __PURE__ call [test/compress/issue-1261.js:7,31]",
|
||||||
"WARN: Condition always true [test/compress/issue-1261.js:141,8]",
|
"WARN: Condition always true [test/compress/issue-1261.js:7,8]",
|
||||||
"WARN: Dropping __PURE__ call [test/compress/issue-1261.js:142,23]",
|
"WARN: Dropping __PURE__ call [test/compress/issue-1261.js:8,23]",
|
||||||
"WARN: Condition always true [test/compress/issue-1261.js:143,8]",
|
"WARN: Condition always true [test/compress/issue-1261.js:9,8]",
|
||||||
"WARN: Dropping __PURE__ call [test/compress/issue-1261.js:143,24]",
|
"WARN: Dropping __PURE__ call [test/compress/issue-1261.js:9,24]",
|
||||||
"WARN: Dropping __PURE__ call [test/compress/issue-1261.js:144,31]",
|
"WARN: Dropping __PURE__ call [test/compress/issue-1261.js:10,31]",
|
||||||
"WARN: Condition always false [test/compress/issue-1261.js:144,8]",
|
"WARN: Condition always false [test/compress/issue-1261.js:10,8]",
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,16 +1,16 @@
|
|||||||
string_plus_optimization: {
|
string_plus_optimization: {
|
||||||
options = {
|
options = {
|
||||||
side_effects : true,
|
booleans: true,
|
||||||
evaluate : true,
|
comparisons: true,
|
||||||
conditionals : true,
|
conditionals: true,
|
||||||
comparisons : true,
|
dead_code: true,
|
||||||
dead_code : true,
|
evaluate: true,
|
||||||
booleans : true,
|
hoist_funs: true,
|
||||||
unused : true,
|
if_return: true,
|
||||||
if_return : true,
|
join_vars: true,
|
||||||
join_vars : true,
|
side_effects: true,
|
||||||
hoist_funs : true,
|
unused: true,
|
||||||
};
|
}
|
||||||
input: {
|
input: {
|
||||||
function foo(anything) {
|
function foo(anything) {
|
||||||
function throwing_function() {
|
function throwing_function() {
|
||||||
|
|||||||
@@ -15,7 +15,7 @@
|
|||||||
tranformation_sort_order_equal: {
|
tranformation_sort_order_equal: {
|
||||||
options = {
|
options = {
|
||||||
comparisons: true,
|
comparisons: true,
|
||||||
};
|
}
|
||||||
|
|
||||||
input: { (a = parseInt('100')) == a }
|
input: { (a = parseInt('100')) == a }
|
||||||
expect: { (a = parseInt('100')) == a }
|
expect: { (a = parseInt('100')) == a }
|
||||||
@@ -24,7 +24,7 @@ tranformation_sort_order_equal: {
|
|||||||
tranformation_sort_order_unequal: {
|
tranformation_sort_order_unequal: {
|
||||||
options = {
|
options = {
|
||||||
comparisons: true,
|
comparisons: true,
|
||||||
};
|
}
|
||||||
|
|
||||||
input: { (a = parseInt('100')) != a }
|
input: { (a = parseInt('100')) != a }
|
||||||
expect: { (a = parseInt('100')) != a }
|
expect: { (a = parseInt('100')) != a }
|
||||||
@@ -33,7 +33,7 @@ tranformation_sort_order_unequal: {
|
|||||||
tranformation_sort_order_lesser_or_equal: {
|
tranformation_sort_order_lesser_or_equal: {
|
||||||
options = {
|
options = {
|
||||||
comparisons: true,
|
comparisons: true,
|
||||||
};
|
}
|
||||||
|
|
||||||
input: { (a = parseInt('100')) <= a }
|
input: { (a = parseInt('100')) <= a }
|
||||||
expect: { (a = parseInt('100')) <= a }
|
expect: { (a = parseInt('100')) <= a }
|
||||||
@@ -41,7 +41,7 @@ tranformation_sort_order_lesser_or_equal: {
|
|||||||
tranformation_sort_order_greater_or_equal: {
|
tranformation_sort_order_greater_or_equal: {
|
||||||
options = {
|
options = {
|
||||||
comparisons: true,
|
comparisons: true,
|
||||||
};
|
}
|
||||||
|
|
||||||
input: { (a = parseInt('100')) >= a }
|
input: { (a = parseInt('100')) >= a }
|
||||||
expect: { (a = parseInt('100')) >= a }
|
expect: { (a = parseInt('100')) >= a }
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
level_zero: {
|
level_zero: {
|
||||||
options = {
|
options = {
|
||||||
keep_fnames: true
|
keep_fnames: true,
|
||||||
}
|
}
|
||||||
mangle = {
|
mangle = {
|
||||||
keep_fnames: true
|
keep_fnames: true
|
||||||
@@ -29,7 +29,7 @@ level_zero: {
|
|||||||
|
|
||||||
level_one: {
|
level_one: {
|
||||||
options = {
|
options = {
|
||||||
keep_fnames: true
|
keep_fnames: true,
|
||||||
}
|
}
|
||||||
mangle = {
|
mangle = {
|
||||||
keep_fnames: true
|
keep_fnames: true
|
||||||
@@ -58,7 +58,7 @@ level_one: {
|
|||||||
|
|
||||||
level_two: {
|
level_two: {
|
||||||
options = {
|
options = {
|
||||||
keep_fnames: true
|
keep_fnames: true,
|
||||||
}
|
}
|
||||||
mangle = {
|
mangle = {
|
||||||
keep_fnames: true
|
keep_fnames: true
|
||||||
@@ -97,7 +97,7 @@ level_two: {
|
|||||||
|
|
||||||
level_three: {
|
level_three: {
|
||||||
options = {
|
options = {
|
||||||
keep_fnames: true
|
keep_fnames: true,
|
||||||
}
|
}
|
||||||
mangle = {
|
mangle = {
|
||||||
keep_fnames: true
|
keep_fnames: true
|
||||||
|
|||||||
@@ -22,17 +22,17 @@ else_with_empty_statement: {
|
|||||||
|
|
||||||
conditional_false_stray_else_in_loop: {
|
conditional_false_stray_else_in_loop: {
|
||||||
options = {
|
options = {
|
||||||
evaluate : true,
|
booleans: true,
|
||||||
comparisons : true,
|
comparisons: true,
|
||||||
booleans : true,
|
conditionals: false,
|
||||||
unused : true,
|
dead_code: true,
|
||||||
loops : true,
|
evaluate: true,
|
||||||
side_effects : true,
|
hoist_vars: true,
|
||||||
dead_code : true,
|
if_return: true,
|
||||||
hoist_vars : true,
|
join_vars: true,
|
||||||
join_vars : true,
|
loops: true,
|
||||||
if_return : true,
|
side_effects: true,
|
||||||
conditionals : false,
|
unused: true,
|
||||||
}
|
}
|
||||||
input: {
|
input: {
|
||||||
for (var i = 1; i <= 4; ++i) {
|
for (var i = 1; i <= 4; ++i) {
|
||||||
|
|||||||
@@ -52,3 +52,30 @@ chained_evaluation_2: {
|
|||||||
})();
|
})();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
chained_evaluation_3: {
|
||||||
|
options = {
|
||||||
|
collapse_vars: true,
|
||||||
|
evaluate: 10,
|
||||||
|
reduce_funcs: true,
|
||||||
|
reduce_vars: true,
|
||||||
|
unused: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
(function() {
|
||||||
|
var a = "long piece of string";
|
||||||
|
(function() {
|
||||||
|
var b = a, c;
|
||||||
|
c = f(b);
|
||||||
|
c.bar = b;
|
||||||
|
})();
|
||||||
|
})();
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
(function() {
|
||||||
|
(function() {
|
||||||
|
f("long piece of string").bar = "long piece of string";
|
||||||
|
})();
|
||||||
|
})();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
|
|
||||||
issue_1639_1: {
|
issue_1639_1: {
|
||||||
options = {
|
options = {
|
||||||
booleans: true,
|
booleans: true,
|
||||||
@@ -12,7 +11,6 @@ issue_1639_1: {
|
|||||||
}
|
}
|
||||||
input: {
|
input: {
|
||||||
var a = 100, b = 10;
|
var a = 100, b = 10;
|
||||||
|
|
||||||
var L1 = 5;
|
var L1 = 5;
|
||||||
while (--L1 > 0) {
|
while (--L1 > 0) {
|
||||||
if ((--b), false) {
|
if ((--b), false) {
|
||||||
@@ -21,7 +19,6 @@ issue_1639_1: {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log(a, b);
|
console.log(a, b);
|
||||||
}
|
}
|
||||||
expect: {
|
expect: {
|
||||||
@@ -29,7 +26,7 @@ issue_1639_1: {
|
|||||||
if (--b, 0) var ignore = 0;
|
if (--b, 0) var ignore = 0;
|
||||||
console.log(a, b);
|
console.log(a, b);
|
||||||
}
|
}
|
||||||
expect_stdout: true
|
expect_stdout: "100 6"
|
||||||
}
|
}
|
||||||
|
|
||||||
issue_1639_2: {
|
issue_1639_2: {
|
||||||
@@ -44,25 +41,23 @@ issue_1639_2: {
|
|||||||
}
|
}
|
||||||
input: {
|
input: {
|
||||||
var a = 100, b = 10;
|
var a = 100, b = 10;
|
||||||
|
|
||||||
function f19() {
|
function f19() {
|
||||||
if (++a, false)
|
if (++a, false)
|
||||||
if (a)
|
if (a)
|
||||||
if (++a);
|
if (++a);
|
||||||
}
|
}
|
||||||
f19();
|
f19();
|
||||||
|
|
||||||
console.log(a, b);
|
console.log(a, b);
|
||||||
}
|
}
|
||||||
expect: {
|
expect: {
|
||||||
var a = 100, b = 10;
|
var a = 100, b = 10;
|
||||||
function f19() {
|
function f19() {
|
||||||
++a, 0;
|
++a, 1;
|
||||||
}
|
}
|
||||||
f19(),
|
f19(),
|
||||||
console.log(a, b);
|
console.log(a, b);
|
||||||
}
|
}
|
||||||
expect_stdout: true
|
expect_stdout: "101 10"
|
||||||
}
|
}
|
||||||
|
|
||||||
issue_1639_3: {
|
issue_1639_3: {
|
||||||
@@ -84,5 +79,5 @@ issue_1639_3: {
|
|||||||
a++,
|
a++,
|
||||||
console.log(a, b);
|
console.log(a, b);
|
||||||
}
|
}
|
||||||
expect_stdout: true
|
expect_stdout: "101 10"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -366,7 +366,7 @@ mangle_catch_redef_3: {
|
|||||||
console.log(o);
|
console.log(o);
|
||||||
}
|
}
|
||||||
expect_exact: 'var o="PASS";try{throw 0}catch(o){(function(){function c(){o="FAIL"}c(),c()})()}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: {
|
mangle_catch_redef_3_toplevel: {
|
||||||
@@ -389,10 +389,10 @@ mangle_catch_redef_3_toplevel: {
|
|||||||
console.log(o);
|
console.log(o);
|
||||||
}
|
}
|
||||||
expect_exact: 'var c="PASS";try{throw 0}catch(c){(function(){function o(){c="FAIL"}o(),o()})()}console.log(c);'
|
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 = {
|
mangle = {
|
||||||
ie8: true,
|
ie8: true,
|
||||||
toplevel: false,
|
toplevel: false,
|
||||||
@@ -412,7 +412,7 @@ mangle_catch_redef_ie8_3: {
|
|||||||
console.log(o);
|
console.log(o);
|
||||||
}
|
}
|
||||||
expect_exact: 'var o="PASS";try{throw 0}catch(o){(function(){function c(){o="FAIL"}c(),c()})()}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: {
|
mangle_catch_redef_3_ie8_toplevel: {
|
||||||
@@ -435,5 +435,5 @@ mangle_catch_redef_3_ie8_toplevel: {
|
|||||||
console.log(o);
|
console.log(o);
|
||||||
}
|
}
|
||||||
expect_exact: 'var c="PASS";try{throw 0}catch(c){(function(){function o(){c="FAIL"}o(),o()})()}console.log(c);'
|
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
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -125,8 +125,8 @@ label_do: {
|
|||||||
|
|
||||||
label_while: {
|
label_while: {
|
||||||
options = {
|
options = {
|
||||||
evaluate: true,
|
|
||||||
dead_code: true,
|
dead_code: true,
|
||||||
|
evaluate: true,
|
||||||
loops: true,
|
loops: true,
|
||||||
}
|
}
|
||||||
input: {
|
input: {
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
do_not_update_lhs: {
|
do_not_update_lhs: {
|
||||||
options = {
|
options = {
|
||||||
global_defs: { DEBUG: 0 }
|
global_defs: {
|
||||||
|
DEBUG: 0,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
input: {
|
input: {
|
||||||
DEBUG++;
|
DEBUG++;
|
||||||
@@ -16,7 +18,9 @@ do_not_update_lhs: {
|
|||||||
|
|
||||||
do_update_rhs: {
|
do_update_rhs: {
|
||||||
options = {
|
options = {
|
||||||
global_defs: { DEBUG: 0 }
|
global_defs: {
|
||||||
|
DEBUG: 0,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
input: {
|
input: {
|
||||||
MY_DEBUG = DEBUG;
|
MY_DEBUG = DEBUG;
|
||||||
@@ -35,7 +39,7 @@ mixed: {
|
|||||||
DEBUG: 0,
|
DEBUG: 0,
|
||||||
ENV: 1,
|
ENV: 1,
|
||||||
FOO: 2,
|
FOO: 2,
|
||||||
}
|
},
|
||||||
}
|
}
|
||||||
input: {
|
input: {
|
||||||
var ENV = 3;
|
var ENV = 3;
|
||||||
@@ -60,11 +64,11 @@ mixed: {
|
|||||||
x = 0;
|
x = 0;
|
||||||
}
|
}
|
||||||
expect_warnings: [
|
expect_warnings: [
|
||||||
'WARN: global_defs ENV redefined [test/compress/issue-208.js:41,12]',
|
"WARN: global_defs ENV redefined [test/compress/issue-208.js:1,12]",
|
||||||
'WARN: global_defs FOO redefined [test/compress/issue-208.js:42,12]',
|
"WARN: global_defs FOO redefined [test/compress/issue-208.js:2,12]",
|
||||||
'WARN: global_defs FOO redefined [test/compress/issue-208.js:44,10]',
|
"WARN: global_defs FOO redefined [test/compress/issue-208.js:4,10]",
|
||||||
'WARN: global_defs DEBUG redefined [test/compress/issue-208.js:45,8]',
|
"WARN: global_defs DEBUG redefined [test/compress/issue-208.js:5,8]",
|
||||||
'WARN: global_defs DEBUG redefined [test/compress/issue-208.js:46,8]',
|
"WARN: global_defs DEBUG redefined [test/compress/issue-208.js:6,8]",
|
||||||
'WARN: global_defs DEBUG redefined [test/compress/issue-208.js:47,8]',
|
"WARN: global_defs DEBUG redefined [test/compress/issue-208.js:7,8]",
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
return_with_no_value_in_if_body: {
|
return_with_no_value_in_if_body: {
|
||||||
options = { conditionals: true };
|
options = {
|
||||||
|
conditionals: true,
|
||||||
|
}
|
||||||
input: {
|
input: {
|
||||||
function foo(bar) {
|
function foo(bar) {
|
||||||
if (bar) {
|
if (bar) {
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
issue_267: {
|
issue_267: {
|
||||||
options = { comparisons: true };
|
options = {
|
||||||
|
comparisons: true,
|
||||||
|
}
|
||||||
input: {
|
input: {
|
||||||
x = a % b / b * c * 2;
|
x = a % b / b * c * 2;
|
||||||
x = a % b * 2
|
x = a % b * 2
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
issue_269_1: {
|
issue_269_1: {
|
||||||
options = {unsafe: true};
|
options = {
|
||||||
|
unsafe: true,
|
||||||
|
}
|
||||||
input: {
|
input: {
|
||||||
f(
|
f(
|
||||||
String(x),
|
String(x),
|
||||||
@@ -20,7 +22,9 @@ issue_269_1: {
|
|||||||
}
|
}
|
||||||
|
|
||||||
issue_269_dangers: {
|
issue_269_dangers: {
|
||||||
options = {unsafe: true};
|
options = {
|
||||||
|
unsafe: true,
|
||||||
|
}
|
||||||
input: {
|
input: {
|
||||||
f(
|
f(
|
||||||
String(x, x),
|
String(x, x),
|
||||||
@@ -34,7 +38,9 @@ issue_269_dangers: {
|
|||||||
}
|
}
|
||||||
|
|
||||||
issue_269_in_scope: {
|
issue_269_in_scope: {
|
||||||
options = {unsafe: true};
|
options = {
|
||||||
|
unsafe: true,
|
||||||
|
}
|
||||||
input: {
|
input: {
|
||||||
var String, Number, Boolean;
|
var String, Number, Boolean;
|
||||||
f(
|
f(
|
||||||
@@ -50,7 +56,9 @@ issue_269_in_scope: {
|
|||||||
}
|
}
|
||||||
|
|
||||||
strings_concat: {
|
strings_concat: {
|
||||||
options = {unsafe: true};
|
options = {
|
||||||
|
unsafe: true,
|
||||||
|
}
|
||||||
input: {
|
input: {
|
||||||
f(
|
f(
|
||||||
String(x + 'str'),
|
String(x + 'str'),
|
||||||
@@ -67,9 +75,9 @@ strings_concat: {
|
|||||||
|
|
||||||
regexp: {
|
regexp: {
|
||||||
options = {
|
options = {
|
||||||
evaluate: true,
|
evaluate: true,
|
||||||
unsafe: true,
|
unsafe: true,
|
||||||
}
|
}
|
||||||
input: {
|
input: {
|
||||||
RegExp("foo");
|
RegExp("foo");
|
||||||
RegExp("bar", "ig");
|
RegExp("bar", "ig");
|
||||||
@@ -85,6 +93,6 @@ regexp: {
|
|||||||
RegExp("should", "fail");
|
RegExp("should", "fail");
|
||||||
}
|
}
|
||||||
expect_warnings: [
|
expect_warnings: [
|
||||||
'WARN: Error converting RegExp("should","fail") [test/compress/issue-269.js:78,2]',
|
'WARN: Error converting RegExp("should","fail") [test/compress/issue-269.js:5,2]',
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ warn: {
|
|||||||
}().length);
|
}().length);
|
||||||
}
|
}
|
||||||
expect_warnings: [
|
expect_warnings: [
|
||||||
"WARN: Function.protoype.caller not supported [test/compress/issue-2719.js:17,19]",
|
"WARN: Function.prototype.caller not supported [test/compress/issue-2719.js:5,19]",
|
||||||
"WARN: Function.protoype.arguments not supported [test/compress/issue-2719.js:17,19]",
|
"WARN: Function.prototype.arguments not supported [test/compress/issue-2719.js:5,19]",
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -186,7 +186,7 @@ negate_iife_5_off: {
|
|||||||
inline: true,
|
inline: true,
|
||||||
negate_iife: false,
|
negate_iife: false,
|
||||||
sequences: true,
|
sequences: true,
|
||||||
};
|
}
|
||||||
input: {
|
input: {
|
||||||
if ((function(){ return t })()) {
|
if ((function(){ return t })()) {
|
||||||
foo(true);
|
foo(true);
|
||||||
@@ -245,7 +245,7 @@ negate_iife_issue_1073: {
|
|||||||
reduce_vars: true,
|
reduce_vars: true,
|
||||||
sequences: true,
|
sequences: true,
|
||||||
unused: true,
|
unused: true,
|
||||||
};
|
}
|
||||||
input: {
|
input: {
|
||||||
new (function(a) {
|
new (function(a) {
|
||||||
return function Foo() {
|
return function Foo() {
|
||||||
@@ -273,7 +273,7 @@ issue_1288_side_effects: {
|
|||||||
reduce_vars: true,
|
reduce_vars: true,
|
||||||
side_effects: true,
|
side_effects: true,
|
||||||
unused: true,
|
unused: true,
|
||||||
};
|
}
|
||||||
input: {
|
input: {
|
||||||
if (w) ;
|
if (w) ;
|
||||||
else {
|
else {
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
issue_44_valid_ast_1: {
|
issue_44_valid_ast_1: {
|
||||||
options = { unused: true };
|
options = {
|
||||||
|
unused: true,
|
||||||
|
}
|
||||||
input: {
|
input: {
|
||||||
function a(b) {
|
function a(b) {
|
||||||
for (var i = 0, e = b.qoo(); ; i++) {}
|
for (var i = 0, e = b.qoo(); ; i++) {}
|
||||||
@@ -14,7 +16,9 @@ issue_44_valid_ast_1: {
|
|||||||
}
|
}
|
||||||
|
|
||||||
issue_44_valid_ast_2: {
|
issue_44_valid_ast_2: {
|
||||||
options = { unused: true };
|
options = {
|
||||||
|
unused: true,
|
||||||
|
}
|
||||||
input: {
|
input: {
|
||||||
function a(b) {
|
function a(b) {
|
||||||
if (foo) for (var i = 0, e = b.qoo(); ; i++) {}
|
if (foo) for (var i = 0, e = b.qoo(); ; i++) {}
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
keep_continue: {
|
keep_continue: {
|
||||||
options = {
|
options = {
|
||||||
dead_code: true,
|
dead_code: true,
|
||||||
evaluate: true
|
evaluate: true,
|
||||||
};
|
}
|
||||||
input: {
|
input: {
|
||||||
while (a) {
|
while (a) {
|
||||||
if (b) {
|
if (b) {
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
NaN_and_Infinity_must_have_parens: {
|
NaN_and_Infinity_must_have_parens: {
|
||||||
options = {};
|
options = {}
|
||||||
input: {
|
input: {
|
||||||
Infinity.toString();
|
Infinity.toString();
|
||||||
NaN.toString();
|
NaN.toString();
|
||||||
@@ -11,7 +11,7 @@ NaN_and_Infinity_must_have_parens: {
|
|||||||
}
|
}
|
||||||
|
|
||||||
NaN_and_Infinity_should_not_be_replaced_when_they_are_redefined: {
|
NaN_and_Infinity_should_not_be_replaced_when_they_are_redefined: {
|
||||||
options = {};
|
options = {}
|
||||||
input: {
|
input: {
|
||||||
var Infinity, NaN;
|
var Infinity, NaN;
|
||||||
Infinity.toString();
|
Infinity.toString();
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
issue_611: {
|
issue_611: {
|
||||||
options = {
|
options = {
|
||||||
sequences: true,
|
sequences: true,
|
||||||
side_effects: true
|
side_effects: true,
|
||||||
};
|
}
|
||||||
input: {
|
input: {
|
||||||
define(function() {
|
define(function() {
|
||||||
function fn() {}
|
function fn() {}
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
wrongly_optimized: {
|
wrongly_optimized: {
|
||||||
options = {
|
options = {
|
||||||
conditionals: true,
|
|
||||||
booleans: true,
|
booleans: true,
|
||||||
evaluate: true
|
conditionals: true,
|
||||||
};
|
evaluate: true,
|
||||||
|
}
|
||||||
input: {
|
input: {
|
||||||
function func() {
|
function func() {
|
||||||
foo();
|
foo();
|
||||||
|
|||||||
@@ -21,19 +21,19 @@ cond_5: {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
expect: {
|
expect: {
|
||||||
some_condition() && some_other_condition() ? do_something() : alternate();
|
(some_condition() && some_other_condition() ? do_something : alternate)();
|
||||||
if (some_condition() && some_other_condition()) do_something();
|
if (some_condition() && some_other_condition()) do_something();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
dead_code_const_annotation_regex: {
|
dead_code_const_annotation_regex: {
|
||||||
options = {
|
options = {
|
||||||
booleans : true,
|
booleans: true,
|
||||||
conditionals : true,
|
conditionals: true,
|
||||||
dead_code : true,
|
dead_code: true,
|
||||||
evaluate : true,
|
evaluate: true,
|
||||||
expression : true,
|
expression: true,
|
||||||
loops : true,
|
loops: true,
|
||||||
}
|
}
|
||||||
input: {
|
input: {
|
||||||
var unused;
|
var unused;
|
||||||
@@ -82,8 +82,8 @@ drop_value: {
|
|||||||
|
|
||||||
wrongly_optimized: {
|
wrongly_optimized: {
|
||||||
options = {
|
options = {
|
||||||
conditionals: true,
|
|
||||||
booleans: true,
|
booleans: true,
|
||||||
|
conditionals: true,
|
||||||
evaluate: true,
|
evaluate: true,
|
||||||
expression: true,
|
expression: true,
|
||||||
}
|
}
|
||||||
@@ -195,7 +195,7 @@ negate_iife_5_off: {
|
|||||||
expression: true,
|
expression: true,
|
||||||
negate_iife: false,
|
negate_iife: false,
|
||||||
sequences: true,
|
sequences: true,
|
||||||
};
|
}
|
||||||
input: {
|
input: {
|
||||||
if ((function(){ return t })()) {
|
if ((function(){ return t })()) {
|
||||||
foo(true);
|
foo(true);
|
||||||
@@ -248,7 +248,9 @@ issue_1254_negate_iife_nested: {
|
|||||||
conditional: {
|
conditional: {
|
||||||
options = {
|
options = {
|
||||||
expression: true,
|
expression: true,
|
||||||
pure_funcs: [ "pure" ],
|
pure_funcs: [
|
||||||
|
"pure"
|
||||||
|
],
|
||||||
side_effects: true,
|
side_effects: true,
|
||||||
}
|
}
|
||||||
input: {
|
input: {
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
negate_booleans_1: {
|
negate_booleans_1: {
|
||||||
options = {
|
options = {
|
||||||
comparisons: true
|
comparisons: true,
|
||||||
};
|
}
|
||||||
input: {
|
input: {
|
||||||
var a = !a || !b || !c || !d || !e || !f;
|
var a = !a || !b || !c || !d || !e || !f;
|
||||||
}
|
}
|
||||||
@@ -12,8 +12,8 @@ negate_booleans_1: {
|
|||||||
|
|
||||||
negate_booleans_2: {
|
negate_booleans_2: {
|
||||||
options = {
|
options = {
|
||||||
comparisons: true
|
comparisons: true,
|
||||||
};
|
}
|
||||||
input: {
|
input: {
|
||||||
var match = !x && // should not touch this one
|
var match = !x && // should not touch this one
|
||||||
(!z || c) &&
|
(!z || c) &&
|
||||||
|
|||||||
@@ -2,25 +2,25 @@ dont_mangle_arguments: {
|
|||||||
mangle = {
|
mangle = {
|
||||||
};
|
};
|
||||||
options = {
|
options = {
|
||||||
sequences : true,
|
booleans: true,
|
||||||
properties : true,
|
comparisons: true,
|
||||||
dead_code : true,
|
conditionals: true,
|
||||||
drop_debugger : true,
|
dead_code: true,
|
||||||
conditionals : true,
|
drop_debugger: true,
|
||||||
comparisons : true,
|
evaluate: true,
|
||||||
evaluate : true,
|
hoist_funs: true,
|
||||||
booleans : true,
|
hoist_vars: true,
|
||||||
loops : true,
|
if_return: true,
|
||||||
unused : true,
|
join_vars: true,
|
||||||
hoist_funs : true,
|
keep_fargs: true,
|
||||||
keep_fargs : true,
|
keep_fnames: false,
|
||||||
keep_fnames : false,
|
loops: true,
|
||||||
hoist_vars : true,
|
negate_iife: false,
|
||||||
if_return : true,
|
properties: true,
|
||||||
join_vars : true,
|
sequences: true,
|
||||||
side_effects : true,
|
side_effects: true,
|
||||||
negate_iife : false
|
unused: true,
|
||||||
};
|
}
|
||||||
input: {
|
input: {
|
||||||
(function(){
|
(function(){
|
||||||
var arguments = arguments, not_arguments = 9;
|
var arguments = arguments, not_arguments = 9;
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
keep_var_for_in: {
|
keep_var_for_in: {
|
||||||
options = {
|
options = {
|
||||||
hoist_vars: true,
|
hoist_vars: true,
|
||||||
unused: true
|
unused: true,
|
||||||
};
|
}
|
||||||
input: {
|
input: {
|
||||||
(function(obj){
|
(function(obj){
|
||||||
var foo = 5;
|
var foo = 5;
|
||||||
|
|||||||
@@ -72,7 +72,7 @@ this_binding_collapse_vars: {
|
|||||||
|
|
||||||
this_binding_side_effects: {
|
this_binding_side_effects: {
|
||||||
options = {
|
options = {
|
||||||
side_effects : true
|
side_effects: true,
|
||||||
}
|
}
|
||||||
input: {
|
input: {
|
||||||
(function(foo) {
|
(function(foo) {
|
||||||
|
|||||||
@@ -1,9 +1,21 @@
|
|||||||
eval_collapse_vars: {
|
eval_collapse_vars: {
|
||||||
options = {
|
options = {
|
||||||
collapse_vars:true, sequences:false, properties:true, dead_code:true, conditionals:true,
|
booleans: true,
|
||||||
comparisons:true, evaluate:true, booleans:true, loops:true, unused:true, hoist_funs:true,
|
collapse_vars: true,
|
||||||
keep_fargs:true, if_return:true, join_vars:true, side_effects:true
|
comparisons: true,
|
||||||
};
|
conditionals: true,
|
||||||
|
dead_code: true,
|
||||||
|
evaluate: true,
|
||||||
|
hoist_funs: true,
|
||||||
|
if_return: true,
|
||||||
|
join_vars: true,
|
||||||
|
keep_fargs: true,
|
||||||
|
loops: true,
|
||||||
|
properties: true,
|
||||||
|
sequences: false,
|
||||||
|
side_effects: true,
|
||||||
|
unused: true,
|
||||||
|
}
|
||||||
input: {
|
input: {
|
||||||
function f1() {
|
function f1() {
|
||||||
var e = 7;
|
var e = 7;
|
||||||
@@ -46,7 +58,10 @@ eval_collapse_vars: {
|
|||||||
}
|
}
|
||||||
|
|
||||||
eval_unused: {
|
eval_unused: {
|
||||||
options = { unused: true, keep_fargs: false };
|
options = {
|
||||||
|
keep_fargs: false,
|
||||||
|
unused: true,
|
||||||
|
}
|
||||||
input: {
|
input: {
|
||||||
function f1(a, eval, c, d, e) {
|
function f1(a, eval, c, d, e) {
|
||||||
return a('c') + eval;
|
return a('c') + eval;
|
||||||
|
|||||||
@@ -1,8 +1,19 @@
|
|||||||
issue979_reported: {
|
issue979_reported: {
|
||||||
options = {
|
options = {
|
||||||
sequences:true, properties:true, dead_code:true, conditionals:true,
|
booleans: true,
|
||||||
comparisons:true, evaluate:true, booleans:true, loops:true, unused:true, hoist_funs:true,
|
comparisons: true,
|
||||||
keep_fargs:true, if_return:true, join_vars:true, side_effects:true
|
conditionals: true,
|
||||||
|
dead_code: true,
|
||||||
|
evaluate: true,
|
||||||
|
hoist_funs: true,
|
||||||
|
if_return: true,
|
||||||
|
join_vars: true,
|
||||||
|
keep_fargs: true,
|
||||||
|
loops: true,
|
||||||
|
properties: true,
|
||||||
|
sequences: true,
|
||||||
|
side_effects: true,
|
||||||
|
unused: true,
|
||||||
}
|
}
|
||||||
input: {
|
input: {
|
||||||
function f1() {
|
function f1() {
|
||||||
@@ -30,9 +41,20 @@ issue979_reported: {
|
|||||||
|
|
||||||
issue979_test_negated_is_best: {
|
issue979_test_negated_is_best: {
|
||||||
options = {
|
options = {
|
||||||
sequences:true, properties:true, dead_code:true, conditionals:true,
|
booleans: true,
|
||||||
comparisons:true, evaluate:true, booleans:true, loops:true, unused:true, hoist_funs:true,
|
comparisons: true,
|
||||||
keep_fargs:true, if_return:true, join_vars:true, side_effects:true
|
conditionals: true,
|
||||||
|
dead_code: true,
|
||||||
|
evaluate: true,
|
||||||
|
hoist_funs: true,
|
||||||
|
if_return: true,
|
||||||
|
join_vars: true,
|
||||||
|
keep_fargs: true,
|
||||||
|
loops: true,
|
||||||
|
properties: true,
|
||||||
|
sequences: true,
|
||||||
|
side_effects: true,
|
||||||
|
unused: true,
|
||||||
}
|
}
|
||||||
input: {
|
input: {
|
||||||
function f3() {
|
function f3() {
|
||||||
|
|||||||
1457
test/compress/keep_fargs.js
Normal file
1457
test/compress/keep_fargs.js
Normal file
File diff suppressed because it is too large
Load Diff
@@ -1,5 +1,9 @@
|
|||||||
labels_1: {
|
labels_1: {
|
||||||
options = { if_return: true, conditionals: true, dead_code: true };
|
options = {
|
||||||
|
conditionals: true,
|
||||||
|
dead_code: true,
|
||||||
|
if_return: true,
|
||||||
|
}
|
||||||
input: {
|
input: {
|
||||||
out: {
|
out: {
|
||||||
if (foo) break out;
|
if (foo) break out;
|
||||||
@@ -13,7 +17,11 @@ labels_1: {
|
|||||||
}
|
}
|
||||||
|
|
||||||
labels_2: {
|
labels_2: {
|
||||||
options = { if_return: true, conditionals: true, dead_code: true };
|
options = {
|
||||||
|
conditionals: true,
|
||||||
|
dead_code: true,
|
||||||
|
if_return: true,
|
||||||
|
}
|
||||||
input: {
|
input: {
|
||||||
out: {
|
out: {
|
||||||
if (foo) print("stuff");
|
if (foo) print("stuff");
|
||||||
@@ -30,7 +38,11 @@ labels_2: {
|
|||||||
}
|
}
|
||||||
|
|
||||||
labels_3: {
|
labels_3: {
|
||||||
options = { if_return: true, conditionals: true, dead_code: true };
|
options = {
|
||||||
|
conditionals: true,
|
||||||
|
dead_code: true,
|
||||||
|
if_return: true,
|
||||||
|
}
|
||||||
input: {
|
input: {
|
||||||
for (var i = 0; i < 5; ++i) {
|
for (var i = 0; i < 5; ++i) {
|
||||||
if (i < 3) continue;
|
if (i < 3) continue;
|
||||||
@@ -45,7 +57,11 @@ labels_3: {
|
|||||||
}
|
}
|
||||||
|
|
||||||
labels_4: {
|
labels_4: {
|
||||||
options = { if_return: true, conditionals: true, dead_code: true };
|
options = {
|
||||||
|
conditionals: true,
|
||||||
|
dead_code: true,
|
||||||
|
if_return: true,
|
||||||
|
}
|
||||||
input: {
|
input: {
|
||||||
out: for (var i = 0; i < 5; ++i) {
|
out: for (var i = 0; i < 5; ++i) {
|
||||||
if (i < 3) continue out;
|
if (i < 3) continue out;
|
||||||
@@ -60,7 +76,11 @@ labels_4: {
|
|||||||
}
|
}
|
||||||
|
|
||||||
labels_5: {
|
labels_5: {
|
||||||
options = { if_return: true, conditionals: true, dead_code: true };
|
options = {
|
||||||
|
conditionals: true,
|
||||||
|
dead_code: true,
|
||||||
|
if_return: true,
|
||||||
|
}
|
||||||
// should keep the break-s in the following
|
// should keep the break-s in the following
|
||||||
input: {
|
input: {
|
||||||
while (foo) {
|
while (foo) {
|
||||||
@@ -92,7 +112,11 @@ labels_6: {
|
|||||||
}
|
}
|
||||||
|
|
||||||
labels_7: {
|
labels_7: {
|
||||||
options = { if_return: true, conditionals: true, dead_code: true };
|
options = {
|
||||||
|
conditionals: true,
|
||||||
|
dead_code: true,
|
||||||
|
if_return: true,
|
||||||
|
}
|
||||||
input: {
|
input: {
|
||||||
while (foo) {
|
while (foo) {
|
||||||
x();
|
x();
|
||||||
@@ -109,7 +133,11 @@ labels_7: {
|
|||||||
}
|
}
|
||||||
|
|
||||||
labels_8: {
|
labels_8: {
|
||||||
options = { if_return: true, conditionals: true, dead_code: true };
|
options = {
|
||||||
|
conditionals: true,
|
||||||
|
dead_code: true,
|
||||||
|
if_return: true,
|
||||||
|
}
|
||||||
input: {
|
input: {
|
||||||
while (foo) {
|
while (foo) {
|
||||||
x();
|
x();
|
||||||
@@ -127,7 +155,11 @@ labels_8: {
|
|||||||
}
|
}
|
||||||
|
|
||||||
labels_9: {
|
labels_9: {
|
||||||
options = { if_return: true, conditionals: true, dead_code: true };
|
options = {
|
||||||
|
conditionals: true,
|
||||||
|
dead_code: true,
|
||||||
|
if_return: true,
|
||||||
|
}
|
||||||
input: {
|
input: {
|
||||||
out: while (foo) {
|
out: while (foo) {
|
||||||
x();
|
x();
|
||||||
@@ -146,7 +178,11 @@ labels_9: {
|
|||||||
}
|
}
|
||||||
|
|
||||||
labels_10: {
|
labels_10: {
|
||||||
options = { if_return: true, conditionals: true, dead_code: true };
|
options = {
|
||||||
|
conditionals: true,
|
||||||
|
dead_code: true,
|
||||||
|
if_return: true,
|
||||||
|
}
|
||||||
input: {
|
input: {
|
||||||
out: while (foo) {
|
out: while (foo) {
|
||||||
x();
|
x();
|
||||||
|
|||||||
@@ -1,37 +1,45 @@
|
|||||||
while_becomes_for: {
|
while_becomes_for: {
|
||||||
options = { loops: true };
|
options = {
|
||||||
|
loops: true,
|
||||||
|
}
|
||||||
input: {
|
input: {
|
||||||
while (foo()) bar();
|
while (foo()) bar();
|
||||||
}
|
}
|
||||||
expect: {
|
expect: {
|
||||||
for (; foo(); ) bar();
|
for (;foo();) bar();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
drop_if_break_1: {
|
drop_if_break_1: {
|
||||||
options = { loops: true };
|
options = {
|
||||||
|
loops: true,
|
||||||
|
}
|
||||||
input: {
|
input: {
|
||||||
for (;;)
|
for (;;)
|
||||||
if (foo()) break;
|
if (foo()) break;
|
||||||
}
|
}
|
||||||
expect: {
|
expect: {
|
||||||
for (; !foo(););
|
for (;!foo(););
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
drop_if_break_2: {
|
drop_if_break_2: {
|
||||||
options = { loops: true };
|
options = {
|
||||||
|
loops: true,
|
||||||
|
}
|
||||||
input: {
|
input: {
|
||||||
for (;bar();)
|
for (;bar();)
|
||||||
if (foo()) break;
|
if (foo()) break;
|
||||||
}
|
}
|
||||||
expect: {
|
expect: {
|
||||||
for (; bar() && !foo(););
|
for (;bar() && !foo(););
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
drop_if_break_3: {
|
drop_if_break_3: {
|
||||||
options = { loops: true };
|
options = {
|
||||||
|
loops: true,
|
||||||
|
}
|
||||||
input: {
|
input: {
|
||||||
for (;bar();) {
|
for (;bar();) {
|
||||||
if (foo()) break;
|
if (foo()) break;
|
||||||
@@ -48,7 +56,10 @@ drop_if_break_3: {
|
|||||||
}
|
}
|
||||||
|
|
||||||
drop_if_break_4: {
|
drop_if_break_4: {
|
||||||
options = { loops: true, sequences: true };
|
options = {
|
||||||
|
loops: true,
|
||||||
|
sequences: true,
|
||||||
|
}
|
||||||
input: {
|
input: {
|
||||||
for (;bar();) {
|
for (;bar();) {
|
||||||
x();
|
x();
|
||||||
@@ -59,22 +70,26 @@ drop_if_break_4: {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
expect: {
|
expect: {
|
||||||
for (; bar() && (x(), y(), !foo());) z(), k();
|
for (;bar() && (x(), y(), !foo());) z(), k();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
drop_if_else_break_1: {
|
drop_if_else_break_1: {
|
||||||
options = { loops: true };
|
options = {
|
||||||
|
loops: true,
|
||||||
|
}
|
||||||
input: {
|
input: {
|
||||||
for (;;) if (foo()) bar(); else break;
|
for (;;) if (foo()) bar(); else break;
|
||||||
}
|
}
|
||||||
expect: {
|
expect: {
|
||||||
for (; foo(); ) bar();
|
for (;foo();) bar();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
drop_if_else_break_2: {
|
drop_if_else_break_2: {
|
||||||
options = { loops: true };
|
options = {
|
||||||
|
loops: true,
|
||||||
|
}
|
||||||
input: {
|
input: {
|
||||||
for (;bar();) {
|
for (;bar();) {
|
||||||
if (foo()) baz();
|
if (foo()) baz();
|
||||||
@@ -82,12 +97,14 @@ drop_if_else_break_2: {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
expect: {
|
expect: {
|
||||||
for (; bar() && foo();) baz();
|
for (;bar() && foo();) baz();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
drop_if_else_break_3: {
|
drop_if_else_break_3: {
|
||||||
options = { loops: true };
|
options = {
|
||||||
|
loops: true,
|
||||||
|
}
|
||||||
input: {
|
input: {
|
||||||
for (;bar();) {
|
for (;bar();) {
|
||||||
if (foo()) baz();
|
if (foo()) baz();
|
||||||
@@ -97,7 +114,7 @@ drop_if_else_break_3: {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
expect: {
|
expect: {
|
||||||
for (; bar() && foo();) {
|
for (;bar() && foo();) {
|
||||||
baz();
|
baz();
|
||||||
stuff1();
|
stuff1();
|
||||||
stuff2();
|
stuff2();
|
||||||
@@ -106,7 +123,10 @@ drop_if_else_break_3: {
|
|||||||
}
|
}
|
||||||
|
|
||||||
drop_if_else_break_4: {
|
drop_if_else_break_4: {
|
||||||
options = { loops: true, sequences: true };
|
options = {
|
||||||
|
loops: true,
|
||||||
|
sequences: true,
|
||||||
|
}
|
||||||
input: {
|
input: {
|
||||||
for (;bar();) {
|
for (;bar();) {
|
||||||
x();
|
x();
|
||||||
@@ -118,12 +138,14 @@ drop_if_else_break_4: {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
expect: {
|
expect: {
|
||||||
for (; bar() && (x(), y(), foo());) baz(), z(), k();
|
for (;bar() && (x(), y(), foo());) baz(), z(), k();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
parse_do_while_with_semicolon: {
|
parse_do_while_with_semicolon: {
|
||||||
options = { loops: false };
|
options = {
|
||||||
|
loops: false,
|
||||||
|
}
|
||||||
input: {
|
input: {
|
||||||
do {
|
do {
|
||||||
x();
|
x();
|
||||||
@@ -135,7 +157,9 @@ parse_do_while_with_semicolon: {
|
|||||||
}
|
}
|
||||||
|
|
||||||
parse_do_while_without_semicolon: {
|
parse_do_while_without_semicolon: {
|
||||||
options = { loops: false };
|
options = {
|
||||||
|
loops: false,
|
||||||
|
}
|
||||||
input: {
|
input: {
|
||||||
do {
|
do {
|
||||||
x();
|
x();
|
||||||
@@ -153,7 +177,7 @@ evaluate: {
|
|||||||
loops: true,
|
loops: true,
|
||||||
passes: 2,
|
passes: 2,
|
||||||
side_effects: true,
|
side_effects: true,
|
||||||
};
|
}
|
||||||
input: {
|
input: {
|
||||||
while (true) {
|
while (true) {
|
||||||
a();
|
a();
|
||||||
@@ -457,7 +481,7 @@ init_side_effects: {
|
|||||||
options = {
|
options = {
|
||||||
loops: true,
|
loops: true,
|
||||||
side_effects: true,
|
side_effects: true,
|
||||||
};
|
}
|
||||||
input: {
|
input: {
|
||||||
for (function() {}(), i = 0; i < 5; i++) console.log(i);
|
for (function() {}(), i = 0; i < 5; i++) console.log(i);
|
||||||
for (function() {}(); i < 10; i++) console.log(i);
|
for (function() {}(); i < 10; i++) console.log(i);
|
||||||
@@ -499,13 +523,13 @@ issue_2740_1: {
|
|||||||
loops: true,
|
loops: true,
|
||||||
}
|
}
|
||||||
input: {
|
input: {
|
||||||
for (; ; ) break;
|
for (;;) break;
|
||||||
for (a(); ; ) break;
|
for (a();;) break;
|
||||||
for (; b(); ) break;
|
for (;b();) break;
|
||||||
for (c(); d(); ) break;
|
for (c(); d();) break;
|
||||||
for (; ; e()) break;
|
for (;;e()) break;
|
||||||
for (f(); ; g()) break;
|
for (f();; g()) break;
|
||||||
for (; h(); i()) break;
|
for (;h(); i()) break;
|
||||||
for (j(); k(); l()) break;
|
for (j(); k(); l()) break;
|
||||||
}
|
}
|
||||||
expect: {
|
expect: {
|
||||||
@@ -550,9 +574,11 @@ issue_2740_3: {
|
|||||||
console.log(x, y);
|
console.log(x, y);
|
||||||
}
|
}
|
||||||
expect: {
|
expect: {
|
||||||
L1: for (var x = 0; x < 3; x++)
|
L1: for (var x = 0; x < 3; x++) {
|
||||||
for (var y = 0; y < 2; y++)
|
var y = 0;
|
||||||
|
if (y < 2)
|
||||||
break L1;
|
break L1;
|
||||||
|
}
|
||||||
console.log(x, y);
|
console.log(x, y);
|
||||||
}
|
}
|
||||||
expect_stdout: "0 0"
|
expect_stdout: "0 0"
|
||||||
@@ -622,3 +648,282 @@ issue_2904: {
|
|||||||
}
|
}
|
||||||
expect_stdout: "1"
|
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"
|
||||||
|
}
|
||||||
|
|
||||||
|
empty_for_in: {
|
||||||
|
options = {
|
||||||
|
loops: true,
|
||||||
|
toplevel: true,
|
||||||
|
unused: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
for (var a in [ 1, 2, 3 ]) {
|
||||||
|
var b = a + 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
expect: {}
|
||||||
|
expect_warnings: [
|
||||||
|
"WARN: Dropping unused variable b [test/compress/loops.js:2,16]",
|
||||||
|
"INFO: Dropping unused loop variable a [test/compress/loops.js:1,17]",
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
|
empty_for_in_used: {
|
||||||
|
options = {
|
||||||
|
loops: true,
|
||||||
|
toplevel: true,
|
||||||
|
unused: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
for (var a in [ 1, 2, 3 ]) {
|
||||||
|
var b = a + 1;
|
||||||
|
}
|
||||||
|
console.log(a);
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
for (var a in [ 1, 2, 3 ]);
|
||||||
|
console.log(a);
|
||||||
|
}
|
||||||
|
expect_stdout: "2"
|
||||||
|
expect_warnings: [
|
||||||
|
"WARN: Dropping unused variable b [test/compress/loops.js:2,16]",
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
|
empty_for_in_side_effects: {
|
||||||
|
options = {
|
||||||
|
loops: true,
|
||||||
|
toplevel: true,
|
||||||
|
unused: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
for (var a in {
|
||||||
|
foo: console.log("PASS")
|
||||||
|
}) {
|
||||||
|
var b = a + "bar";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
console.log("PASS");
|
||||||
|
}
|
||||||
|
expect_stdout: "PASS"
|
||||||
|
expect_warnings: [
|
||||||
|
"WARN: Dropping unused variable b [test/compress/loops.js:4,16]",
|
||||||
|
"INFO: Dropping unused loop variable a [test/compress/loops.js:1,17]",
|
||||||
|
"WARN: Side effects in object of for-in loop [test/compress/loops.js:1,17]",
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
|
issue_3631_1: {
|
||||||
|
options = {
|
||||||
|
dead_code: true,
|
||||||
|
evaluate: true,
|
||||||
|
loops: true,
|
||||||
|
reduce_vars: true,
|
||||||
|
toplevel: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
var c = 0;
|
||||||
|
L: do {
|
||||||
|
for (;;) continue L;
|
||||||
|
var b = 1;
|
||||||
|
} while (b && c++);
|
||||||
|
console.log(c);
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
var c = 0;
|
||||||
|
do {
|
||||||
|
var b;
|
||||||
|
} while (b && c++);
|
||||||
|
console.log(c);
|
||||||
|
}
|
||||||
|
expect_stdout: "0"
|
||||||
|
}
|
||||||
|
|
||||||
|
issue_3631_2: {
|
||||||
|
options = {
|
||||||
|
dead_code: true,
|
||||||
|
evaluate: true,
|
||||||
|
loops: true,
|
||||||
|
reduce_vars: true,
|
||||||
|
toplevel: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
L: for (var a = 1; a--; console.log(b)) {
|
||||||
|
for (;;) continue L;
|
||||||
|
var b = "FAIL";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
for (var a = 1; a--; console.log(b))
|
||||||
|
var b;
|
||||||
|
}
|
||||||
|
expect_stdout: "undefined"
|
||||||
|
}
|
||||||
|
|
||||||
|
loop_if_break: {
|
||||||
|
options = {
|
||||||
|
dead_code: true,
|
||||||
|
loops: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
function f(a, b) {
|
||||||
|
try {
|
||||||
|
while (a) {
|
||||||
|
if (b) {
|
||||||
|
break;
|
||||||
|
var c = 42;
|
||||||
|
console.log(c);
|
||||||
|
} else {
|
||||||
|
var d = false;
|
||||||
|
throw d;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
console.log("E:", e);
|
||||||
|
}
|
||||||
|
console.log(a, b, c, d);
|
||||||
|
}
|
||||||
|
f(0, 0);
|
||||||
|
f(0, 1);
|
||||||
|
f(1, 0);
|
||||||
|
f(1, 1);
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
function f(a, b) {
|
||||||
|
try {
|
||||||
|
for (;a && !b;) {
|
||||||
|
var d = false;
|
||||||
|
throw d;
|
||||||
|
var c;
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
console.log("E:", e);
|
||||||
|
}
|
||||||
|
console.log(a, b, c, d);
|
||||||
|
}
|
||||||
|
f(0, 0);
|
||||||
|
f(0, 1);
|
||||||
|
f(1, 0);
|
||||||
|
f(1, 1);
|
||||||
|
}
|
||||||
|
expect_stdout: [
|
||||||
|
"0 0 undefined undefined",
|
||||||
|
"0 1 undefined undefined",
|
||||||
|
"E: false",
|
||||||
|
"1 0 undefined false",
|
||||||
|
"1 1 undefined undefined",
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
|
loop_return: {
|
||||||
|
options = {
|
||||||
|
dead_code: true,
|
||||||
|
loops: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
function f(a) {
|
||||||
|
while (a) return 42;
|
||||||
|
return "foo";
|
||||||
|
}
|
||||||
|
console.log(f(0), f(1));
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
function f(a) {
|
||||||
|
if (a) return 42;
|
||||||
|
return "foo";
|
||||||
|
}
|
||||||
|
console.log(f(0), f(1));
|
||||||
|
}
|
||||||
|
expect_stdout: "foo 42"
|
||||||
|
}
|
||||||
|
|
||||||
|
issue_3634_1: {
|
||||||
|
options = {
|
||||||
|
loops: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
var b = 0;
|
||||||
|
L: while (++b < 2)
|
||||||
|
while (1)
|
||||||
|
if (b) break L;
|
||||||
|
console.log(b);
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
var b = 0;
|
||||||
|
L: for (;++b < 2;)
|
||||||
|
for (;1;)
|
||||||
|
if (b) break L;
|
||||||
|
console.log(b);
|
||||||
|
}
|
||||||
|
expect_stdout: "1"
|
||||||
|
}
|
||||||
|
|
||||||
|
issue_3634_2: {
|
||||||
|
options = {
|
||||||
|
loops: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
var b = 0;
|
||||||
|
L: while (++b < 2)
|
||||||
|
while (1)
|
||||||
|
if (!b)
|
||||||
|
continue L;
|
||||||
|
else
|
||||||
|
break L;
|
||||||
|
console.log(b);
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
var b = 0;
|
||||||
|
L: for (;++b < 2;)
|
||||||
|
for (;1;)
|
||||||
|
if (!b)
|
||||||
|
continue L;
|
||||||
|
else
|
||||||
|
break L;
|
||||||
|
console.log(b);
|
||||||
|
}
|
||||||
|
expect_stdout: "1"
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
negate_iife_1: {
|
negate_iife_1: {
|
||||||
options = {
|
options = {
|
||||||
negate_iife: true
|
negate_iife: true,
|
||||||
};
|
}
|
||||||
input: {
|
input: {
|
||||||
(function(){ stuff() })();
|
(function(){ stuff() })();
|
||||||
}
|
}
|
||||||
@@ -13,7 +13,7 @@ negate_iife_1: {
|
|||||||
negate_iife_1_off: {
|
negate_iife_1_off: {
|
||||||
options = {
|
options = {
|
||||||
negate_iife: false,
|
negate_iife: false,
|
||||||
};
|
}
|
||||||
input: {
|
input: {
|
||||||
(function(){ stuff() })();
|
(function(){ stuff() })();
|
||||||
}
|
}
|
||||||
@@ -24,7 +24,7 @@ negate_iife_2: {
|
|||||||
options = {
|
options = {
|
||||||
inline: true,
|
inline: true,
|
||||||
negate_iife: true,
|
negate_iife: true,
|
||||||
};
|
}
|
||||||
input: {
|
input: {
|
||||||
(function(){ return {} })().x = 10;
|
(function(){ return {} })().x = 10;
|
||||||
}
|
}
|
||||||
@@ -45,9 +45,9 @@ negate_iife_2_side_effects: {
|
|||||||
|
|
||||||
negate_iife_3: {
|
negate_iife_3: {
|
||||||
options = {
|
options = {
|
||||||
|
conditionals: true,
|
||||||
negate_iife: true,
|
negate_iife: true,
|
||||||
conditionals: true
|
}
|
||||||
};
|
|
||||||
input: {
|
input: {
|
||||||
(function(){ return t })() ? console.log(true) : console.log(false);
|
(function(){ return t })() ? console.log(true) : console.log(false);
|
||||||
}
|
}
|
||||||
@@ -88,9 +88,9 @@ negate_iife_3_side_effects: {
|
|||||||
|
|
||||||
negate_iife_3_off: {
|
negate_iife_3_off: {
|
||||||
options = {
|
options = {
|
||||||
negate_iife: false,
|
|
||||||
conditionals: true,
|
conditionals: true,
|
||||||
};
|
negate_iife: false,
|
||||||
|
}
|
||||||
input: {
|
input: {
|
||||||
(function(){ return t })() ? console.log(true) : console.log(false);
|
(function(){ return t })() ? console.log(true) : console.log(false);
|
||||||
}
|
}
|
||||||
@@ -117,10 +117,10 @@ negate_iife_3_off_evaluate: {
|
|||||||
|
|
||||||
negate_iife_4: {
|
negate_iife_4: {
|
||||||
options = {
|
options = {
|
||||||
negate_iife: true,
|
|
||||||
conditionals: true,
|
conditionals: true,
|
||||||
sequences: true
|
negate_iife: true,
|
||||||
};
|
sequences: true,
|
||||||
|
}
|
||||||
input: {
|
input: {
|
||||||
(function(){ return t })() ? console.log(true) : console.log(false);
|
(function(){ return t })() ? console.log(true) : console.log(false);
|
||||||
(function(){
|
(function(){
|
||||||
@@ -136,11 +136,11 @@ negate_iife_4: {
|
|||||||
|
|
||||||
sequence_off: {
|
sequence_off: {
|
||||||
options = {
|
options = {
|
||||||
negate_iife: false,
|
|
||||||
conditionals: true,
|
conditionals: true,
|
||||||
sequences: true,
|
negate_iife: false,
|
||||||
passes: 2,
|
passes: 2,
|
||||||
};
|
sequences: true,
|
||||||
|
}
|
||||||
input: {
|
input: {
|
||||||
function f() {
|
function f() {
|
||||||
(function(){ return t })() ? console.log(true) : console.log(false);
|
(function(){ return t })() ? console.log(true) : console.log(false);
|
||||||
@@ -171,10 +171,10 @@ sequence_off: {
|
|||||||
|
|
||||||
negate_iife_5: {
|
negate_iife_5: {
|
||||||
options = {
|
options = {
|
||||||
|
conditionals: true,
|
||||||
negate_iife: true,
|
negate_iife: true,
|
||||||
sequences: true,
|
sequences: true,
|
||||||
conditionals: true,
|
}
|
||||||
};
|
|
||||||
input: {
|
input: {
|
||||||
if ((function(){ return t })()) {
|
if ((function(){ return t })()) {
|
||||||
foo(true);
|
foo(true);
|
||||||
@@ -194,10 +194,10 @@ negate_iife_5: {
|
|||||||
|
|
||||||
negate_iife_5_off: {
|
negate_iife_5_off: {
|
||||||
options = {
|
options = {
|
||||||
|
conditionals: true,
|
||||||
negate_iife: false,
|
negate_iife: false,
|
||||||
sequences: true,
|
sequences: true,
|
||||||
conditionals: true,
|
}
|
||||||
};
|
|
||||||
input: {
|
input: {
|
||||||
if ((function(){ return t })()) {
|
if ((function(){ return t })()) {
|
||||||
foo(true);
|
foo(true);
|
||||||
@@ -217,10 +217,10 @@ negate_iife_5_off: {
|
|||||||
|
|
||||||
negate_iife_nested: {
|
negate_iife_nested: {
|
||||||
options = {
|
options = {
|
||||||
|
conditionals: true,
|
||||||
negate_iife: true,
|
negate_iife: true,
|
||||||
sequences: true,
|
sequences: true,
|
||||||
conditionals: true,
|
}
|
||||||
};
|
|
||||||
input: {
|
input: {
|
||||||
function Foo(f) {
|
function Foo(f) {
|
||||||
this.f = f;
|
this.f = f;
|
||||||
@@ -250,10 +250,10 @@ negate_iife_nested: {
|
|||||||
|
|
||||||
negate_iife_nested_off: {
|
negate_iife_nested_off: {
|
||||||
options = {
|
options = {
|
||||||
|
conditionals: true,
|
||||||
negate_iife: false,
|
negate_iife: false,
|
||||||
sequences: true,
|
sequences: true,
|
||||||
conditionals: true,
|
}
|
||||||
};
|
|
||||||
input: {
|
input: {
|
||||||
function Foo(f) {
|
function Foo(f) {
|
||||||
this.f = f;
|
this.f = f;
|
||||||
@@ -283,10 +283,10 @@ negate_iife_nested_off: {
|
|||||||
|
|
||||||
negate_iife_issue_1073: {
|
negate_iife_issue_1073: {
|
||||||
options = {
|
options = {
|
||||||
|
conditionals: true,
|
||||||
negate_iife: true,
|
negate_iife: true,
|
||||||
sequences: true,
|
sequences: true,
|
||||||
conditionals: true,
|
}
|
||||||
};
|
|
||||||
input: {
|
input: {
|
||||||
new (function(a) {
|
new (function(a) {
|
||||||
return function Foo() {
|
return function Foo() {
|
||||||
@@ -356,7 +356,7 @@ issue_1288: {
|
|||||||
conditionals: true,
|
conditionals: true,
|
||||||
negate_iife: true,
|
negate_iife: true,
|
||||||
side_effects: false,
|
side_effects: false,
|
||||||
};
|
}
|
||||||
input: {
|
input: {
|
||||||
if (w) ;
|
if (w) ;
|
||||||
else {
|
else {
|
||||||
|
|||||||
@@ -36,7 +36,9 @@ new_statements_3: {
|
|||||||
}
|
}
|
||||||
|
|
||||||
new_with_rewritten_true_value: {
|
new_with_rewritten_true_value: {
|
||||||
options = { booleans: true }
|
options = {
|
||||||
|
booleans: true,
|
||||||
|
}
|
||||||
input: {
|
input: {
|
||||||
new true;
|
new true;
|
||||||
}
|
}
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
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"
|
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"
|
||||||
|
}
|
||||||
|
|||||||
@@ -187,10 +187,10 @@ issue_2110_1: {
|
|||||||
options = {
|
options = {
|
||||||
collapse_vars: true,
|
collapse_vars: true,
|
||||||
pure_getters: "strict",
|
pure_getters: "strict",
|
||||||
sequences: true,
|
|
||||||
side_effects: true,
|
|
||||||
reduce_funcs: true,
|
reduce_funcs: true,
|
||||||
reduce_vars: true,
|
reduce_vars: true,
|
||||||
|
sequences: true,
|
||||||
|
side_effects: true,
|
||||||
unused: true,
|
unused: true,
|
||||||
}
|
}
|
||||||
input: {
|
input: {
|
||||||
@@ -1161,3 +1161,51 @@ collapse_rhs_lhs: {
|
|||||||
}
|
}
|
||||||
expect_stdout: "1 3"
|
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
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,15 +1,15 @@
|
|||||||
reduce_vars: {
|
reduce_vars: {
|
||||||
options = {
|
options = {
|
||||||
conditionals : true,
|
conditionals: true,
|
||||||
evaluate : true,
|
evaluate: true,
|
||||||
inline : true,
|
global_defs: {
|
||||||
global_defs : {
|
C: 0,
|
||||||
C : 0
|
|
||||||
},
|
},
|
||||||
reduce_funcs : true,
|
inline: true,
|
||||||
reduce_vars : true,
|
reduce_funcs: true,
|
||||||
toplevel : true,
|
reduce_vars: true,
|
||||||
unused : true
|
toplevel: true,
|
||||||
|
unused: true,
|
||||||
}
|
}
|
||||||
input: {
|
input: {
|
||||||
var A = 1;
|
var A = 1;
|
||||||
@@ -63,11 +63,11 @@ reduce_vars: {
|
|||||||
|
|
||||||
modified: {
|
modified: {
|
||||||
options = {
|
options = {
|
||||||
conditionals : true,
|
conditionals: true,
|
||||||
evaluate : true,
|
evaluate: true,
|
||||||
reduce_funcs : true,
|
reduce_funcs: true,
|
||||||
reduce_vars : true,
|
reduce_vars: true,
|
||||||
unused : true,
|
unused: true,
|
||||||
}
|
}
|
||||||
input: {
|
input: {
|
||||||
function f0() {
|
function f0() {
|
||||||
@@ -184,46 +184,43 @@ modified: {
|
|||||||
|
|
||||||
unsafe_evaluate: {
|
unsafe_evaluate: {
|
||||||
options = {
|
options = {
|
||||||
evaluate : true,
|
evaluate: true,
|
||||||
reduce_funcs : true,
|
reduce_funcs: true,
|
||||||
reduce_vars : true,
|
reduce_vars: true,
|
||||||
side_effects : true,
|
side_effects: true,
|
||||||
unsafe : true,
|
unsafe: true,
|
||||||
unused : true
|
unused: true,
|
||||||
}
|
}
|
||||||
input: {
|
input: {
|
||||||
function f0(){
|
function f0() {
|
||||||
var a = {
|
var a = { b: 1 };
|
||||||
b:1
|
|
||||||
};
|
|
||||||
console.log(a.b + 3);
|
console.log(a.b + 3);
|
||||||
}
|
}
|
||||||
|
function f1() {
|
||||||
function f1(){
|
|
||||||
var a = {
|
var a = {
|
||||||
b:{
|
b: { c: 1 },
|
||||||
c:1
|
d: 2
|
||||||
},
|
|
||||||
d:2
|
|
||||||
};
|
};
|
||||||
console.log(a.b + 3, a.d + 4, a.b.c + 5, a.d.c + 6);
|
console.log(a.b + 3, a.d + 4, a.b.c + 5, a.d.c + 6);
|
||||||
}
|
}
|
||||||
|
f0();
|
||||||
|
f1();
|
||||||
}
|
}
|
||||||
expect: {
|
expect: {
|
||||||
function f0(){
|
function f0() {
|
||||||
console.log(4);
|
console.log(4);
|
||||||
}
|
}
|
||||||
|
function f1() {
|
||||||
function f1(){
|
|
||||||
var a = {
|
var a = {
|
||||||
b:{
|
b: { c: 1 },
|
||||||
c:1
|
d: 2
|
||||||
},
|
|
||||||
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: {
|
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; }());
|
console.log(function(){ var o={p:3},a=[o]; console.log(a[0].p++); return o.p; }());
|
||||||
}
|
}
|
||||||
expect: {
|
expect: {
|
||||||
console.log(function(){ var o={p:1}; console.log(o, o.p); 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(o.p, o); 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; }());
|
console.log(function(){ var o={p:3},a=[o]; console.log(a[0].p++); return o.p; }());
|
||||||
}
|
}
|
||||||
expect_stdout: true
|
expect_stdout: true
|
||||||
@@ -344,10 +341,10 @@ unsafe_evaluate_unknown: {
|
|||||||
|
|
||||||
unsafe_evaluate_object_1: {
|
unsafe_evaluate_object_1: {
|
||||||
options = {
|
options = {
|
||||||
evaluate : true,
|
evaluate: true,
|
||||||
reduce_funcs : true,
|
reduce_funcs: true,
|
||||||
reduce_vars : true,
|
reduce_vars: true,
|
||||||
unsafe : true
|
unsafe: true,
|
||||||
}
|
}
|
||||||
input: {
|
input: {
|
||||||
function f0(){
|
function f0(){
|
||||||
@@ -463,10 +460,10 @@ unsafe_evaluate_object_3: {
|
|||||||
|
|
||||||
unsafe_evaluate_array_1: {
|
unsafe_evaluate_array_1: {
|
||||||
options = {
|
options = {
|
||||||
evaluate : true,
|
evaluate: true,
|
||||||
reduce_funcs : true,
|
reduce_funcs: true,
|
||||||
reduce_vars : true,
|
reduce_vars: true,
|
||||||
unsafe : true
|
unsafe: true,
|
||||||
}
|
}
|
||||||
input: {
|
input: {
|
||||||
function f0(){
|
function f0(){
|
||||||
@@ -642,11 +639,11 @@ unsafe_evaluate_array_5: {
|
|||||||
|
|
||||||
unsafe_evaluate_equality_1: {
|
unsafe_evaluate_equality_1: {
|
||||||
options = {
|
options = {
|
||||||
evaluate : true,
|
evaluate: true,
|
||||||
reduce_funcs : true,
|
reduce_funcs: true,
|
||||||
reduce_vars : true,
|
reduce_vars: true,
|
||||||
unsafe : true,
|
unsafe: true,
|
||||||
unused : true
|
unused: true,
|
||||||
}
|
}
|
||||||
input: {
|
input: {
|
||||||
function f0() {
|
function f0() {
|
||||||
@@ -674,12 +671,12 @@ unsafe_evaluate_equality_1: {
|
|||||||
unsafe_evaluate_equality_2: {
|
unsafe_evaluate_equality_2: {
|
||||||
options = {
|
options = {
|
||||||
collapse_vars: true,
|
collapse_vars: true,
|
||||||
evaluate : true,
|
evaluate: true,
|
||||||
passes : 2,
|
passes: 2,
|
||||||
reduce_funcs : true,
|
reduce_funcs: true,
|
||||||
reduce_vars : true,
|
reduce_vars: true,
|
||||||
unsafe : true,
|
unsafe: true,
|
||||||
unused : true
|
unused: true,
|
||||||
}
|
}
|
||||||
input: {
|
input: {
|
||||||
function f2() {
|
function f2() {
|
||||||
@@ -1130,7 +1127,7 @@ toplevel_on: {
|
|||||||
evaluate: true,
|
evaluate: true,
|
||||||
reduce_funcs: true,
|
reduce_funcs: true,
|
||||||
reduce_vars: true,
|
reduce_vars: true,
|
||||||
toplevel:true,
|
toplevel: true,
|
||||||
unused: true,
|
unused: true,
|
||||||
}
|
}
|
||||||
input: {
|
input: {
|
||||||
@@ -1148,7 +1145,7 @@ toplevel_off: {
|
|||||||
evaluate: true,
|
evaluate: true,
|
||||||
reduce_funcs: true,
|
reduce_funcs: true,
|
||||||
reduce_vars: true,
|
reduce_vars: true,
|
||||||
toplevel:false,
|
toplevel: false,
|
||||||
unused: true,
|
unused: true,
|
||||||
}
|
}
|
||||||
input: {
|
input: {
|
||||||
@@ -1168,7 +1165,7 @@ toplevel_on_loops_1: {
|
|||||||
loops: true,
|
loops: true,
|
||||||
reduce_funcs: true,
|
reduce_funcs: true,
|
||||||
reduce_vars: true,
|
reduce_vars: true,
|
||||||
toplevel:true,
|
toplevel: true,
|
||||||
unused: true,
|
unused: true,
|
||||||
}
|
}
|
||||||
input: {
|
input: {
|
||||||
@@ -1196,7 +1193,7 @@ toplevel_off_loops_1: {
|
|||||||
loops: true,
|
loops: true,
|
||||||
reduce_funcs: true,
|
reduce_funcs: true,
|
||||||
reduce_vars: true,
|
reduce_vars: true,
|
||||||
toplevel:false,
|
toplevel: false,
|
||||||
unused: true,
|
unused: true,
|
||||||
}
|
}
|
||||||
input: {
|
input: {
|
||||||
@@ -1225,7 +1222,7 @@ toplevel_on_loops_2: {
|
|||||||
reduce_funcs: true,
|
reduce_funcs: true,
|
||||||
reduce_vars: true,
|
reduce_vars: true,
|
||||||
side_effects: true,
|
side_effects: true,
|
||||||
toplevel:true,
|
toplevel: true,
|
||||||
unused: true,
|
unused: true,
|
||||||
}
|
}
|
||||||
input: {
|
input: {
|
||||||
@@ -1251,7 +1248,7 @@ toplevel_off_loops_2: {
|
|||||||
loops: true,
|
loops: true,
|
||||||
reduce_funcs: true,
|
reduce_funcs: true,
|
||||||
reduce_vars: true,
|
reduce_vars: true,
|
||||||
toplevel:false,
|
toplevel: false,
|
||||||
unused: true,
|
unused: true,
|
||||||
}
|
}
|
||||||
input: {
|
input: {
|
||||||
@@ -1278,7 +1275,7 @@ toplevel_on_loops_3: {
|
|||||||
loops: true,
|
loops: true,
|
||||||
reduce_funcs: true,
|
reduce_funcs: true,
|
||||||
reduce_vars: true,
|
reduce_vars: true,
|
||||||
toplevel:true,
|
toplevel: true,
|
||||||
unused: true,
|
unused: true,
|
||||||
}
|
}
|
||||||
input: {
|
input: {
|
||||||
@@ -1296,7 +1293,7 @@ toplevel_off_loops_3: {
|
|||||||
loops: true,
|
loops: true,
|
||||||
reduce_funcs: true,
|
reduce_funcs: true,
|
||||||
reduce_vars: true,
|
reduce_vars: true,
|
||||||
toplevel:false,
|
toplevel: false,
|
||||||
unused: true,
|
unused: true,
|
||||||
}
|
}
|
||||||
input: {
|
input: {
|
||||||
@@ -1430,13 +1427,13 @@ defun_inline_3: {
|
|||||||
|
|
||||||
defun_call: {
|
defun_call: {
|
||||||
options = {
|
options = {
|
||||||
inline: true,
|
evaluate: true,
|
||||||
reduce_funcs: true,
|
reduce_funcs: true,
|
||||||
reduce_vars: true,
|
reduce_vars: true,
|
||||||
unused: true,
|
unused: true,
|
||||||
}
|
}
|
||||||
input: {
|
input: {
|
||||||
function f() {
|
console.log(function f() {
|
||||||
return g() + h(1) - h(g(), 2, 3);
|
return g() + h(1) - h(g(), 2, 3);
|
||||||
function g() {
|
function g() {
|
||||||
return 4;
|
return 4;
|
||||||
@@ -1444,21 +1441,17 @@ defun_call: {
|
|||||||
function h(a) {
|
function h(a) {
|
||||||
return a;
|
return a;
|
||||||
}
|
}
|
||||||
}
|
}());
|
||||||
}
|
}
|
||||||
expect: {
|
expect: {
|
||||||
function f() {
|
console.log(1);
|
||||||
return 4 + h(1) - h(4);
|
|
||||||
function h(a) {
|
|
||||||
return a;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
expect_stdout: "1"
|
||||||
}
|
}
|
||||||
|
|
||||||
defun_redefine: {
|
defun_redefine: {
|
||||||
options = {
|
options = {
|
||||||
inline: true,
|
evaluate: true,
|
||||||
reduce_funcs: true,
|
reduce_funcs: true,
|
||||||
reduce_vars: true,
|
reduce_vars: true,
|
||||||
unused: true,
|
unused: true,
|
||||||
@@ -1483,7 +1476,7 @@ defun_redefine: {
|
|||||||
(function() {
|
(function() {
|
||||||
return 3;
|
return 3;
|
||||||
});
|
});
|
||||||
return 3 + 2;
|
return 5;
|
||||||
}
|
}
|
||||||
console.log(f());
|
console.log(f());
|
||||||
}
|
}
|
||||||
@@ -1520,7 +1513,7 @@ func_inline: {
|
|||||||
|
|
||||||
func_modified: {
|
func_modified: {
|
||||||
options = {
|
options = {
|
||||||
inline: true,
|
evaluate: true,
|
||||||
reduce_funcs: true,
|
reduce_funcs: true,
|
||||||
reduce_vars: true,
|
reduce_vars: true,
|
||||||
unused: true,
|
unused: true,
|
||||||
@@ -1553,13 +1546,39 @@ func_modified: {
|
|||||||
(function() {
|
(function() {
|
||||||
return 4;
|
return 4;
|
||||||
});
|
});
|
||||||
return 1 + 2 + 4;
|
return 7;
|
||||||
}
|
}
|
||||||
console.log(f());
|
console.log(f());
|
||||||
}
|
}
|
||||||
expect_stdout: "7"
|
expect_stdout: "7"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
unused_modified: {
|
||||||
|
options = {
|
||||||
|
reduce_vars: true,
|
||||||
|
unused: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
console.log(function() {
|
||||||
|
var b = 1, c = "FAIL";
|
||||||
|
if (0 || b--)
|
||||||
|
c = "PASS";
|
||||||
|
b = 1;
|
||||||
|
return c;
|
||||||
|
}());
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
console.log(function() {
|
||||||
|
var b = 1, c = "FAIL";
|
||||||
|
if (0 || b--)
|
||||||
|
c = "PASS";
|
||||||
|
b = 1;
|
||||||
|
return c;
|
||||||
|
}());
|
||||||
|
}
|
||||||
|
expect_stdout: "PASS"
|
||||||
|
}
|
||||||
|
|
||||||
defun_label: {
|
defun_label: {
|
||||||
options = {
|
options = {
|
||||||
passes: 2,
|
passes: 2,
|
||||||
@@ -1868,8 +1887,8 @@ issue_1670_1: {
|
|||||||
options = {
|
options = {
|
||||||
comparisons: true,
|
comparisons: true,
|
||||||
conditionals: true,
|
conditionals: true,
|
||||||
evaluate: true,
|
|
||||||
dead_code: true,
|
dead_code: true,
|
||||||
|
evaluate: true,
|
||||||
reduce_funcs: true,
|
reduce_funcs: true,
|
||||||
reduce_vars: true,
|
reduce_vars: true,
|
||||||
side_effects: true,
|
side_effects: true,
|
||||||
@@ -1901,8 +1920,8 @@ issue_1670_1: {
|
|||||||
issue_1670_2: {
|
issue_1670_2: {
|
||||||
options = {
|
options = {
|
||||||
conditionals: true,
|
conditionals: true,
|
||||||
evaluate: true,
|
|
||||||
dead_code: true,
|
dead_code: true,
|
||||||
|
evaluate: true,
|
||||||
passes: 2,
|
passes: 2,
|
||||||
reduce_funcs: true,
|
reduce_funcs: true,
|
||||||
reduce_vars: true,
|
reduce_vars: true,
|
||||||
@@ -1934,8 +1953,8 @@ issue_1670_3: {
|
|||||||
options = {
|
options = {
|
||||||
comparisons: true,
|
comparisons: true,
|
||||||
conditionals: true,
|
conditionals: true,
|
||||||
evaluate: true,
|
|
||||||
dead_code: true,
|
dead_code: true,
|
||||||
|
evaluate: true,
|
||||||
reduce_funcs: true,
|
reduce_funcs: true,
|
||||||
reduce_vars: true,
|
reduce_vars: true,
|
||||||
side_effects: true,
|
side_effects: true,
|
||||||
@@ -1967,8 +1986,8 @@ issue_1670_3: {
|
|||||||
issue_1670_4: {
|
issue_1670_4: {
|
||||||
options = {
|
options = {
|
||||||
conditionals: true,
|
conditionals: true,
|
||||||
evaluate: true,
|
|
||||||
dead_code: true,
|
dead_code: true,
|
||||||
|
evaluate: true,
|
||||||
passes: 2,
|
passes: 2,
|
||||||
reduce_funcs: true,
|
reduce_funcs: true,
|
||||||
reduce_vars: true,
|
reduce_vars: true,
|
||||||
@@ -2714,18 +2733,18 @@ issue_1814_2: {
|
|||||||
!function() {
|
!function() {
|
||||||
var b = a + 1;
|
var b = a + 1;
|
||||||
!function(a) {
|
!function(a) {
|
||||||
console.log(a++, b);
|
console.log(b, a++);
|
||||||
}(0);
|
}(0);
|
||||||
}();
|
}();
|
||||||
}
|
}
|
||||||
expect: {
|
expect: {
|
||||||
!function() {
|
!function() {
|
||||||
!function(a) {
|
!function(a) {
|
||||||
console.log(a++, "321");
|
console.log("321", a++);
|
||||||
}(0);
|
}(0);
|
||||||
}();
|
}();
|
||||||
}
|
}
|
||||||
expect_stdout: "0 '321'"
|
expect_stdout: "321 0"
|
||||||
}
|
}
|
||||||
|
|
||||||
try_abort: {
|
try_abort: {
|
||||||
@@ -4924,7 +4943,7 @@ defun_single_use_loop: {
|
|||||||
unused: true,
|
unused: true,
|
||||||
}
|
}
|
||||||
input: {
|
input: {
|
||||||
for (var x, i = 2; --i >= 0; ) {
|
for (var x, i = 2; --i >= 0;) {
|
||||||
var y = x;
|
var y = x;
|
||||||
x = f;
|
x = f;
|
||||||
console.log(x === y);
|
console.log(x === y);
|
||||||
@@ -4932,7 +4951,7 @@ defun_single_use_loop: {
|
|||||||
function f() {};
|
function f() {};
|
||||||
}
|
}
|
||||||
expect: {
|
expect: {
|
||||||
for (var x, i = 2; --i >= 0; ) {
|
for (var x, i = 2; --i >= 0;) {
|
||||||
var y = x;
|
var y = x;
|
||||||
x = f;
|
x = f;
|
||||||
console.log(x === y);
|
console.log(x === y);
|
||||||
@@ -5205,11 +5224,11 @@ defun_catch_4: {
|
|||||||
try {
|
try {
|
||||||
throw 42;
|
throw 42;
|
||||||
} catch (a) {
|
} catch (a) {
|
||||||
function a() {}
|
|
||||||
console.log(a);
|
console.log(a);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
expect_stdout: true
|
expect_stdout: "42"
|
||||||
|
node_version: "<=4"
|
||||||
}
|
}
|
||||||
|
|
||||||
defun_catch_5: {
|
defun_catch_5: {
|
||||||
@@ -5231,10 +5250,10 @@ defun_catch_5: {
|
|||||||
throw 42;
|
throw 42;
|
||||||
} catch (a) {
|
} catch (a) {
|
||||||
console.log(a);
|
console.log(a);
|
||||||
function a() {}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
expect_stdout: true
|
expect_stdout: "42"
|
||||||
|
node_version: "<=4"
|
||||||
}
|
}
|
||||||
|
|
||||||
defun_catch_6: {
|
defun_catch_6: {
|
||||||
@@ -5328,6 +5347,7 @@ issue_2774: {
|
|||||||
|
|
||||||
issue_2799_1: {
|
issue_2799_1: {
|
||||||
options = {
|
options = {
|
||||||
|
passes: 2,
|
||||||
reduce_funcs: true,
|
reduce_funcs: true,
|
||||||
reduce_vars: true,
|
reduce_vars: true,
|
||||||
unused: true,
|
unused: true,
|
||||||
@@ -5492,9 +5512,7 @@ issue_2860_1: {
|
|||||||
}());
|
}());
|
||||||
}
|
}
|
||||||
expect: {
|
expect: {
|
||||||
console.log(function(a) {
|
console.log(1);
|
||||||
return 1 ^ a;
|
|
||||||
}());
|
|
||||||
}
|
}
|
||||||
expect_stdout: "1"
|
expect_stdout: "1"
|
||||||
}
|
}
|
||||||
@@ -6403,3 +6421,460 @@ issue_3140_5: {
|
|||||||
}
|
}
|
||||||
expect_stdout: "1"
|
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"
|
||||||
|
}
|
||||||
|
|
||||||
|
issue_3622: {
|
||||||
|
options = {
|
||||||
|
evaluate: true,
|
||||||
|
inline: true,
|
||||||
|
keep_fargs: "strict",
|
||||||
|
reduce_vars: true,
|
||||||
|
sequences: true,
|
||||||
|
toplevel: true,
|
||||||
|
unused: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
var c = "FAIL";
|
||||||
|
!function(b, a) {
|
||||||
|
a && (c = "PASS");
|
||||||
|
}(42, this);
|
||||||
|
console.log(c);
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
var c = "FAIL";
|
||||||
|
var a;
|
||||||
|
a = this,
|
||||||
|
!void (a && (c = "PASS")),
|
||||||
|
console.log(c);
|
||||||
|
}
|
||||||
|
expect_stdout: "PASS"
|
||||||
|
}
|
||||||
|
|
||||||
|
issue_3631_1: {
|
||||||
|
options = {
|
||||||
|
evaluate: true,
|
||||||
|
reduce_vars: true,
|
||||||
|
toplevel: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
var c = 0;
|
||||||
|
L: do {
|
||||||
|
for (;;) continue L;
|
||||||
|
var b = 1;
|
||||||
|
} while (b && c++);
|
||||||
|
console.log(c);
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
var c = 0;
|
||||||
|
L: do {
|
||||||
|
for (;;) continue L;
|
||||||
|
var b = 1;
|
||||||
|
} while (b && c++);
|
||||||
|
console.log(c);
|
||||||
|
}
|
||||||
|
expect_stdout: "0"
|
||||||
|
}
|
||||||
|
|
||||||
|
issue_3631_2: {
|
||||||
|
options = {
|
||||||
|
reduce_vars: true,
|
||||||
|
toplevel: true,
|
||||||
|
unused: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
L: for (var a = 1; a--; console.log(b)) {
|
||||||
|
for (;;) continue L;
|
||||||
|
var b = "FAIL";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
L: for (var a = 1; a--; console.log(b)) {
|
||||||
|
for (;;) continue L;
|
||||||
|
var b = "FAIL";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
expect_stdout: "undefined"
|
||||||
|
}
|
||||||
|
|
||||||
|
issue_3666: {
|
||||||
|
options = {
|
||||||
|
collapse_vars: true,
|
||||||
|
passes: 2,
|
||||||
|
reduce_vars: true,
|
||||||
|
toplevel: true,
|
||||||
|
unused: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
try {
|
||||||
|
var a = "FAIL";
|
||||||
|
} finally {
|
||||||
|
for (;!a;)
|
||||||
|
var c = a++;
|
||||||
|
var a = "PASS", b = c = "PASS";
|
||||||
|
}
|
||||||
|
console.log(a, b);
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
try {
|
||||||
|
var a = "FAIL";
|
||||||
|
} finally {
|
||||||
|
for (;!a;)
|
||||||
|
a++;
|
||||||
|
var b = a = "PASS";
|
||||||
|
}
|
||||||
|
console.log(a, b);
|
||||||
|
}
|
||||||
|
expect_stdout: "PASS PASS"
|
||||||
|
}
|
||||||
|
|||||||
@@ -35,3 +35,154 @@ regexp_2: {
|
|||||||
}
|
}
|
||||||
expect_stdout: '["PASS","pass"]'
|
expect_stdout: '["PASS","pass"]'
|
||||||
}
|
}
|
||||||
|
|
||||||
|
regexp_properties: {
|
||||||
|
options = {
|
||||||
|
evaluate: true,
|
||||||
|
unsafe: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
console.log(/abc/g.source, /abc/g.global, /abc/g.ignoreCase, /abc/g.lastIndex, /abc/g.multiline);
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
console.log("abc", true, false, /abc/g.lastIndex, false);
|
||||||
|
}
|
||||||
|
expect_stdout: "abc true false 0 false"
|
||||||
|
}
|
||||||
|
|
||||||
|
issue_3434_1: {
|
||||||
|
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",
|
"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"
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,24 +1,24 @@
|
|||||||
return_undefined: {
|
return_undefined: {
|
||||||
options = {
|
options = {
|
||||||
sequences : false,
|
booleans: true,
|
||||||
if_return : true,
|
comparisons: true,
|
||||||
evaluate : true,
|
conditionals: true,
|
||||||
dead_code : true,
|
dead_code: true,
|
||||||
conditionals : true,
|
drop_debugger: true,
|
||||||
comparisons : true,
|
evaluate: true,
|
||||||
booleans : true,
|
hoist_funs: true,
|
||||||
unused : true,
|
hoist_vars: true,
|
||||||
side_effects : true,
|
if_return: true,
|
||||||
properties : true,
|
join_vars: true,
|
||||||
drop_debugger : true,
|
keep_fargs: true,
|
||||||
loops : true,
|
keep_fnames: false,
|
||||||
hoist_funs : true,
|
loops: true,
|
||||||
keep_fargs : true,
|
negate_iife: true,
|
||||||
keep_fnames : false,
|
properties: true,
|
||||||
hoist_vars : true,
|
sequences: false,
|
||||||
join_vars : true,
|
side_effects: true,
|
||||||
negate_iife : true
|
unused: true,
|
||||||
};
|
}
|
||||||
input: {
|
input: {
|
||||||
function f0() {
|
function f0() {
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,3 +12,71 @@ console_log: {
|
|||||||
"% %s",
|
"% %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]"
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
make_sequences_1: {
|
make_sequences_1: {
|
||||||
options = {
|
options = {
|
||||||
sequences: true
|
sequences: true,
|
||||||
};
|
}
|
||||||
input: {
|
input: {
|
||||||
foo();
|
foo();
|
||||||
bar();
|
bar();
|
||||||
@@ -14,8 +14,8 @@ make_sequences_1: {
|
|||||||
|
|
||||||
make_sequences_2: {
|
make_sequences_2: {
|
||||||
options = {
|
options = {
|
||||||
sequences: true
|
sequences: true,
|
||||||
};
|
}
|
||||||
input: {
|
input: {
|
||||||
if (boo) {
|
if (boo) {
|
||||||
foo();
|
foo();
|
||||||
@@ -35,8 +35,8 @@ make_sequences_2: {
|
|||||||
|
|
||||||
make_sequences_3: {
|
make_sequences_3: {
|
||||||
options = {
|
options = {
|
||||||
sequences: true
|
sequences: true,
|
||||||
};
|
}
|
||||||
input: {
|
input: {
|
||||||
function f() {
|
function f() {
|
||||||
foo();
|
foo();
|
||||||
@@ -61,8 +61,8 @@ make_sequences_3: {
|
|||||||
|
|
||||||
make_sequences_4: {
|
make_sequences_4: {
|
||||||
options = {
|
options = {
|
||||||
sequences: true
|
sequences: true,
|
||||||
};
|
}
|
||||||
input: {
|
input: {
|
||||||
x = 5;
|
x = 5;
|
||||||
if (y) z();
|
if (y) z();
|
||||||
@@ -90,7 +90,9 @@ make_sequences_4: {
|
|||||||
}
|
}
|
||||||
|
|
||||||
lift_sequences_1: {
|
lift_sequences_1: {
|
||||||
options = { sequences: true };
|
options = {
|
||||||
|
sequences: true,
|
||||||
|
}
|
||||||
input: {
|
input: {
|
||||||
var foo, x, y, bar;
|
var foo, x, y, bar;
|
||||||
foo = !(x(), y(), bar());
|
foo = !(x(), y(), bar());
|
||||||
@@ -102,7 +104,10 @@ lift_sequences_1: {
|
|||||||
}
|
}
|
||||||
|
|
||||||
lift_sequences_2: {
|
lift_sequences_2: {
|
||||||
options = { sequences: true, evaluate: true };
|
options = {
|
||||||
|
evaluate: true,
|
||||||
|
sequences: true,
|
||||||
|
}
|
||||||
input: {
|
input: {
|
||||||
var foo = 1, bar;
|
var foo = 1, bar;
|
||||||
foo.x = (foo = {}, 10);
|
foo.x = (foo = {}, 10);
|
||||||
@@ -119,7 +124,10 @@ lift_sequences_2: {
|
|||||||
}
|
}
|
||||||
|
|
||||||
lift_sequences_3: {
|
lift_sequences_3: {
|
||||||
options = { sequences: true, conditionals: true };
|
options = {
|
||||||
|
conditionals: true,
|
||||||
|
sequences: true,
|
||||||
|
}
|
||||||
input: {
|
input: {
|
||||||
var x, foo, bar, baz;
|
var x, foo, bar, baz;
|
||||||
x = (foo(), bar(), baz()) ? 10 : 20;
|
x = (foo(), bar(), baz()) ? 10 : 20;
|
||||||
@@ -131,7 +139,9 @@ lift_sequences_3: {
|
|||||||
}
|
}
|
||||||
|
|
||||||
lift_sequences_4: {
|
lift_sequences_4: {
|
||||||
options = { side_effects: true };
|
options = {
|
||||||
|
side_effects: true,
|
||||||
|
}
|
||||||
input: {
|
input: {
|
||||||
var x, foo, bar, baz;
|
var x, foo, bar, baz;
|
||||||
x = (foo, bar, baz);
|
x = (foo, bar, baz);
|
||||||
@@ -160,7 +170,9 @@ lift_sequences_5: {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for_sequences: {
|
for_sequences: {
|
||||||
options = { sequences: true };
|
options = {
|
||||||
|
sequences: true,
|
||||||
|
}
|
||||||
input: {
|
input: {
|
||||||
// 1
|
// 1
|
||||||
foo();
|
foo();
|
||||||
@@ -203,7 +215,7 @@ for_sequences: {
|
|||||||
limit_1: {
|
limit_1: {
|
||||||
options = {
|
options = {
|
||||||
sequences: 3,
|
sequences: 3,
|
||||||
};
|
}
|
||||||
input: {
|
input: {
|
||||||
a;
|
a;
|
||||||
b;
|
b;
|
||||||
@@ -228,7 +240,7 @@ limit_1: {
|
|||||||
limit_2: {
|
limit_2: {
|
||||||
options = {
|
options = {
|
||||||
sequences: 3,
|
sequences: 3,
|
||||||
};
|
}
|
||||||
input: {
|
input: {
|
||||||
a, b;
|
a, b;
|
||||||
c, d;
|
c, d;
|
||||||
@@ -246,9 +258,9 @@ limit_2: {
|
|||||||
|
|
||||||
negate_iife_for: {
|
negate_iife_for: {
|
||||||
options = {
|
options = {
|
||||||
sequences: true,
|
|
||||||
negate_iife: true,
|
negate_iife: true,
|
||||||
};
|
sequences: true,
|
||||||
|
}
|
||||||
input: {
|
input: {
|
||||||
(function() {})();
|
(function() {})();
|
||||||
for (i = 0; i < 5; i++) console.log(i);
|
for (i = 0; i < 5; i++) console.log(i);
|
||||||
@@ -265,7 +277,7 @@ negate_iife_for: {
|
|||||||
iife: {
|
iife: {
|
||||||
options = {
|
options = {
|
||||||
sequences: true,
|
sequences: true,
|
||||||
};
|
}
|
||||||
input: {
|
input: {
|
||||||
x = 42;
|
x = 42;
|
||||||
(function a() {})();
|
(function a() {})();
|
||||||
@@ -478,6 +490,7 @@ issue_1758: {
|
|||||||
delete_seq_1: {
|
delete_seq_1: {
|
||||||
options = {
|
options = {
|
||||||
booleans: true,
|
booleans: true,
|
||||||
|
evaluate: true,
|
||||||
side_effects: true,
|
side_effects: true,
|
||||||
}
|
}
|
||||||
input: {
|
input: {
|
||||||
@@ -502,6 +515,7 @@ delete_seq_1: {
|
|||||||
delete_seq_2: {
|
delete_seq_2: {
|
||||||
options = {
|
options = {
|
||||||
booleans: true,
|
booleans: true,
|
||||||
|
evaluate: true,
|
||||||
side_effects: true,
|
side_effects: true,
|
||||||
}
|
}
|
||||||
input: {
|
input: {
|
||||||
@@ -526,6 +540,7 @@ delete_seq_2: {
|
|||||||
delete_seq_3: {
|
delete_seq_3: {
|
||||||
options = {
|
options = {
|
||||||
booleans: true,
|
booleans: true,
|
||||||
|
evaluate: true,
|
||||||
keep_infinity: true,
|
keep_infinity: true,
|
||||||
side_effects: true,
|
side_effects: true,
|
||||||
}
|
}
|
||||||
@@ -551,6 +566,7 @@ delete_seq_3: {
|
|||||||
delete_seq_4: {
|
delete_seq_4: {
|
||||||
options = {
|
options = {
|
||||||
booleans: true,
|
booleans: true,
|
||||||
|
evaluate: true,
|
||||||
sequences: true,
|
sequences: true,
|
||||||
side_effects: true,
|
side_effects: true,
|
||||||
}
|
}
|
||||||
@@ -578,6 +594,7 @@ delete_seq_4: {
|
|||||||
delete_seq_5: {
|
delete_seq_5: {
|
||||||
options = {
|
options = {
|
||||||
booleans: true,
|
booleans: true,
|
||||||
|
evaluate: true,
|
||||||
keep_infinity: true,
|
keep_infinity: true,
|
||||||
sequences: true,
|
sequences: true,
|
||||||
side_effects: true,
|
side_effects: true,
|
||||||
@@ -606,6 +623,7 @@ delete_seq_5: {
|
|||||||
delete_seq_6: {
|
delete_seq_6: {
|
||||||
options = {
|
options = {
|
||||||
booleans: true,
|
booleans: true,
|
||||||
|
evaluate: true,
|
||||||
side_effects: true,
|
side_effects: true,
|
||||||
}
|
}
|
||||||
input: {
|
input: {
|
||||||
@@ -690,7 +708,7 @@ side_effects_cascade_3: {
|
|||||||
}
|
}
|
||||||
expect: {
|
expect: {
|
||||||
function f(a, b) {
|
function f(a, b) {
|
||||||
!(b += a) && ((b = a) || (b -= a, b ^= a)),
|
(b += a) || (b = a) || (b -= a, b ^= a),
|
||||||
a--;
|
a--;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -912,14 +930,14 @@ call: {
|
|||||||
b.c = function() {
|
b.c = function() {
|
||||||
console.log(this === b ? "bar" : "baz");
|
console.log(this === b ? "bar" : "baz");
|
||||||
},
|
},
|
||||||
a, b(),
|
b(),
|
||||||
(a, b.c)(),
|
(a, b.c)(),
|
||||||
a, function() {
|
function() {
|
||||||
console.log(this === a);
|
console.log(this === a);
|
||||||
}(),
|
}(),
|
||||||
a, new b(),
|
new b(),
|
||||||
a, new b.c(),
|
new b.c(),
|
||||||
a, new function() {
|
new function() {
|
||||||
console.log(this === a);
|
console.log(this === a);
|
||||||
}();
|
}();
|
||||||
}
|
}
|
||||||
@@ -932,3 +950,122 @@ call: {
|
|||||||
"false",
|
"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"
|
||||||
|
}
|
||||||
|
|||||||
277
test/compress/side_effects.js
Normal file
277
test/compress/side_effects.js
Normal file
@@ -0,0 +1,277 @@
|
|||||||
|
accessor: {
|
||||||
|
options = {
|
||||||
|
side_effects: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
({
|
||||||
|
get a() {},
|
||||||
|
set a(v){
|
||||||
|
this.b = 2;
|
||||||
|
},
|
||||||
|
b: 1
|
||||||
|
});
|
||||||
|
}
|
||||||
|
expect: {}
|
||||||
|
}
|
||||||
|
|
||||||
|
issue_2233_1: {
|
||||||
|
options = {
|
||||||
|
pure_getters: "strict",
|
||||||
|
side_effects: true,
|
||||||
|
unsafe: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
Array.isArray;
|
||||||
|
Boolean;
|
||||||
|
console.log;
|
||||||
|
Date;
|
||||||
|
decodeURI;
|
||||||
|
decodeURIComponent;
|
||||||
|
encodeURI;
|
||||||
|
encodeURIComponent;
|
||||||
|
Error.name;
|
||||||
|
escape;
|
||||||
|
eval;
|
||||||
|
EvalError;
|
||||||
|
Function.length;
|
||||||
|
isFinite;
|
||||||
|
isNaN;
|
||||||
|
JSON;
|
||||||
|
Math.random;
|
||||||
|
Number.isNaN;
|
||||||
|
parseFloat;
|
||||||
|
parseInt;
|
||||||
|
RegExp;
|
||||||
|
Object.defineProperty;
|
||||||
|
String.fromCharCode;
|
||||||
|
RangeError;
|
||||||
|
ReferenceError;
|
||||||
|
SyntaxError;
|
||||||
|
TypeError;
|
||||||
|
unescape;
|
||||||
|
URIError;
|
||||||
|
}
|
||||||
|
expect: {}
|
||||||
|
expect_stdout: true
|
||||||
|
}
|
||||||
|
|
||||||
|
global_timeout_and_interval_symbols: {
|
||||||
|
options = {
|
||||||
|
pure_getters: "strict",
|
||||||
|
side_effects: true,
|
||||||
|
unsafe: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
// These global symbols do not exist in the test sandbox
|
||||||
|
// and must be tested separately.
|
||||||
|
clearInterval;
|
||||||
|
clearTimeout;
|
||||||
|
setInterval;
|
||||||
|
setTimeout;
|
||||||
|
}
|
||||||
|
expect: {}
|
||||||
|
}
|
||||||
|
|
||||||
|
issue_2233_2: {
|
||||||
|
options = {
|
||||||
|
pure_getters: "strict",
|
||||||
|
reduce_funcs: true,
|
||||||
|
reduce_vars: true,
|
||||||
|
side_effects: true,
|
||||||
|
unsafe: true,
|
||||||
|
unused: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
var RegExp;
|
||||||
|
Array.isArray;
|
||||||
|
RegExp;
|
||||||
|
UndeclaredGlobal;
|
||||||
|
function foo() {
|
||||||
|
var Number;
|
||||||
|
AnotherUndeclaredGlobal;
|
||||||
|
Math.sin;
|
||||||
|
Number.isNaN;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
var RegExp;
|
||||||
|
UndeclaredGlobal;
|
||||||
|
function foo() {
|
||||||
|
var Number;
|
||||||
|
AnotherUndeclaredGlobal;
|
||||||
|
Number.isNaN;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
issue_2233_3: {
|
||||||
|
options = {
|
||||||
|
pure_getters: "strict",
|
||||||
|
reduce_funcs: true,
|
||||||
|
reduce_vars: true,
|
||||||
|
side_effects: true,
|
||||||
|
toplevel: true,
|
||||||
|
unsafe: true,
|
||||||
|
unused: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
var RegExp;
|
||||||
|
Array.isArray;
|
||||||
|
RegExp;
|
||||||
|
UndeclaredGlobal;
|
||||||
|
function foo() {
|
||||||
|
var Number;
|
||||||
|
AnotherUndeclaredGlobal;
|
||||||
|
Math.sin;
|
||||||
|
Number.isNaN;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
UndeclaredGlobal;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
global_fns: {
|
||||||
|
options = {
|
||||||
|
side_effects: true,
|
||||||
|
unsafe: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
Boolean(1, 2);
|
||||||
|
decodeURI(1, 2);
|
||||||
|
decodeURIComponent(1, 2);
|
||||||
|
Date(1, 2);
|
||||||
|
encodeURI(1, 2);
|
||||||
|
encodeURIComponent(1, 2);
|
||||||
|
Error(1, 2);
|
||||||
|
escape(1, 2);
|
||||||
|
EvalError(1, 2);
|
||||||
|
isFinite(1, 2);
|
||||||
|
isNaN(1, 2);
|
||||||
|
Number(1, 2);
|
||||||
|
Object(1, 2);
|
||||||
|
parseFloat(1, 2);
|
||||||
|
parseInt(1, 2);
|
||||||
|
RangeError(1, 2);
|
||||||
|
ReferenceError(1, 2);
|
||||||
|
String(1, 2);
|
||||||
|
SyntaxError(1, 2);
|
||||||
|
TypeError(1, 2);
|
||||||
|
unescape(1, 2);
|
||||||
|
URIError(1, 2);
|
||||||
|
try {
|
||||||
|
Function(1, 2);
|
||||||
|
} catch (e) {
|
||||||
|
console.log(e.name);
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
RegExp(1, 2);
|
||||||
|
} catch (e) {
|
||||||
|
console.log(e.name);
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
Array(NaN);
|
||||||
|
} catch (e) {
|
||||||
|
console.log(e.name);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
try {
|
||||||
|
Function(1, 2);
|
||||||
|
} catch (e) {
|
||||||
|
console.log(e.name);
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
RegExp(1, 2);
|
||||||
|
} catch (e) {
|
||||||
|
console.log(e.name);
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
Array(NaN);
|
||||||
|
} catch (e) {
|
||||||
|
console.log(e.name);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
expect_stdout: [
|
||||||
|
"SyntaxError",
|
||||||
|
"SyntaxError",
|
||||||
|
"RangeError",
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
|
unsafe_builtin_1: {
|
||||||
|
options = {
|
||||||
|
side_effects: true,
|
||||||
|
unsafe: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
(!w).constructor(x);
|
||||||
|
Math.abs(y);
|
||||||
|
[ 1, 2, z ].valueOf();
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
w, x;
|
||||||
|
y;
|
||||||
|
z;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
unsafe_builtin_2: {
|
||||||
|
options = {
|
||||||
|
side_effects: true,
|
||||||
|
unsafe: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
var o = {};
|
||||||
|
constructor.call(o, 42);
|
||||||
|
__defineGetter__.call(o, "foo", function() {
|
||||||
|
return o.p;
|
||||||
|
});
|
||||||
|
__defineSetter__.call(o, void 0, function(a) {
|
||||||
|
o.p = a;
|
||||||
|
});
|
||||||
|
console.log(typeof o, o.undefined = "PASS", o.foo);
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
var o = {};
|
||||||
|
constructor.call(o, 42);
|
||||||
|
__defineGetter__.call(o, "foo", function() {
|
||||||
|
return o.p;
|
||||||
|
});
|
||||||
|
__defineSetter__.call(o, void 0, function(a) {
|
||||||
|
o.p = a;
|
||||||
|
});
|
||||||
|
console.log(typeof o, o.undefined = "PASS", o.foo);
|
||||||
|
}
|
||||||
|
expect_stdout: "object PASS PASS"
|
||||||
|
}
|
||||||
|
|
||||||
|
unsafe_string_replace: {
|
||||||
|
options = {
|
||||||
|
side_effects: true,
|
||||||
|
unsafe: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
"foo".replace("f", function() {
|
||||||
|
console.log("PASS");
|
||||||
|
});
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
"foo".replace("f", function() {
|
||||||
|
console.log("PASS");
|
||||||
|
});
|
||||||
|
}
|
||||||
|
expect_stdout: "PASS"
|
||||||
|
}
|
||||||
|
|
||||||
|
drop_value: {
|
||||||
|
options = {
|
||||||
|
side_effects: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
(1, [2, foo()], 3, {a:1, b:bar()});
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
foo(), bar();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -261,13 +261,13 @@ drop_default_1: {
|
|||||||
}
|
}
|
||||||
input: {
|
input: {
|
||||||
switch (foo) {
|
switch (foo) {
|
||||||
case 'bar': baz();
|
case "bar": baz();
|
||||||
default:
|
default:
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
expect: {
|
expect: {
|
||||||
switch (foo) {
|
switch (foo) {
|
||||||
case 'bar': baz();
|
case "bar": baz();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -279,14 +279,14 @@ drop_default_2: {
|
|||||||
}
|
}
|
||||||
input: {
|
input: {
|
||||||
switch (foo) {
|
switch (foo) {
|
||||||
case 'bar': baz(); break;
|
case "bar": baz(); break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
expect: {
|
expect: {
|
||||||
switch (foo) {
|
switch (foo) {
|
||||||
case 'bar': baz();
|
case "bar": baz();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -298,7 +298,7 @@ keep_default: {
|
|||||||
}
|
}
|
||||||
input: {
|
input: {
|
||||||
switch (foo) {
|
switch (foo) {
|
||||||
case 'bar': baz();
|
case "bar": baz();
|
||||||
default:
|
default:
|
||||||
something();
|
something();
|
||||||
break;
|
break;
|
||||||
@@ -306,7 +306,7 @@ keep_default: {
|
|||||||
}
|
}
|
||||||
expect: {
|
expect: {
|
||||||
switch (foo) {
|
switch (foo) {
|
||||||
case 'bar': baz();
|
case "bar": baz();
|
||||||
default:
|
default:
|
||||||
something();
|
something();
|
||||||
}
|
}
|
||||||
@@ -347,25 +347,103 @@ issue_1663: {
|
|||||||
expect_stdout: true
|
expect_stdout: true
|
||||||
}
|
}
|
||||||
|
|
||||||
drop_case: {
|
drop_case_1: {
|
||||||
options = {
|
options = {
|
||||||
dead_code: true,
|
dead_code: true,
|
||||||
switches: true,
|
switches: true,
|
||||||
}
|
}
|
||||||
input: {
|
input: {
|
||||||
switch (foo) {
|
switch (foo) {
|
||||||
case 'bar': baz(); break;
|
case "bar": baz(); break;
|
||||||
case 'moo':
|
case "moo":
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
expect: {
|
expect: {
|
||||||
switch (foo) {
|
switch (foo) {
|
||||||
case 'bar': baz();
|
case "bar": baz();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
drop_case_2: {
|
||||||
|
options = {
|
||||||
|
dead_code: true,
|
||||||
|
switches: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
switch (foo) {
|
||||||
|
case "bar":
|
||||||
|
bar();
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
case "moo":
|
||||||
|
moo();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
switch (foo) {
|
||||||
|
case "bar":
|
||||||
|
bar();
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
moo();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
drop_case_3: {
|
||||||
|
options = {
|
||||||
|
dead_code: true,
|
||||||
|
switches: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
var c = "PASS";
|
||||||
|
switch ({}.p) {
|
||||||
|
default:
|
||||||
|
case void 0:
|
||||||
|
break;
|
||||||
|
case c = "FAIL":
|
||||||
|
}
|
||||||
|
console.log(c);
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
var c = "PASS";
|
||||||
|
switch ({}.p) {
|
||||||
|
default:
|
||||||
|
case void 0:
|
||||||
|
break;
|
||||||
|
case c = "FAIL":
|
||||||
|
}
|
||||||
|
console.log(c);
|
||||||
|
}
|
||||||
|
expect_stdout: "PASS"
|
||||||
|
}
|
||||||
|
|
||||||
|
drop_case_4: {
|
||||||
|
options = {
|
||||||
|
dead_code: true,
|
||||||
|
switches: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
switch (0) {
|
||||||
|
case [ a, typeof b ]:
|
||||||
|
default:
|
||||||
|
var a;
|
||||||
|
}
|
||||||
|
console.log("PASS");
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
switch (0) {
|
||||||
|
case [ a, typeof b ]:
|
||||||
|
var a;
|
||||||
|
}
|
||||||
|
console.log("PASS");
|
||||||
|
}
|
||||||
|
expect_stdout: "PASS"
|
||||||
|
}
|
||||||
|
|
||||||
keep_case: {
|
keep_case: {
|
||||||
options = {
|
options = {
|
||||||
dead_code: true,
|
dead_code: true,
|
||||||
@@ -373,14 +451,14 @@ keep_case: {
|
|||||||
}
|
}
|
||||||
input: {
|
input: {
|
||||||
switch (foo) {
|
switch (foo) {
|
||||||
case 'bar': baz(); break;
|
case "bar": baz(); break;
|
||||||
case moo:
|
case moo:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
expect: {
|
expect: {
|
||||||
switch (foo) {
|
switch (foo) {
|
||||||
case 'bar': baz(); break;
|
case "bar": baz(); break;
|
||||||
case moo:
|
case moo:
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -539,7 +617,7 @@ issue_1679: {
|
|||||||
f();
|
f();
|
||||||
console.log(a, b);
|
console.log(a, b);
|
||||||
}
|
}
|
||||||
expect_stdout: true
|
expect_stdout: "99 8"
|
||||||
}
|
}
|
||||||
|
|
||||||
issue_1680_1: {
|
issue_1680_1: {
|
||||||
@@ -820,8 +898,8 @@ issue_1758: {
|
|||||||
|
|
||||||
issue_2535: {
|
issue_2535: {
|
||||||
options = {
|
options = {
|
||||||
evaluate: true,
|
|
||||||
dead_code: true,
|
dead_code: true,
|
||||||
|
evaluate: true,
|
||||||
switches: true,
|
switches: true,
|
||||||
}
|
}
|
||||||
input: {
|
input: {
|
||||||
@@ -864,3 +942,89 @@ issue_1750: {
|
|||||||
}
|
}
|
||||||
expect_stdout: "0 2"
|
expect_stdout: "0 2"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
drop_switch_1: {
|
||||||
|
options = {
|
||||||
|
dead_code: true,
|
||||||
|
switches: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
switch (foo) {
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
case "bar":
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
foo;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
drop_switch_2: {
|
||||||
|
options = {
|
||||||
|
dead_code: true,
|
||||||
|
switches: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
switch (foo) {
|
||||||
|
default:
|
||||||
|
case "bar":
|
||||||
|
baz();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
foo;
|
||||||
|
baz();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
drop_switch_3: {
|
||||||
|
options = {
|
||||||
|
dead_code: true,
|
||||||
|
switches: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
console.log(function() {
|
||||||
|
switch (0) {
|
||||||
|
default:
|
||||||
|
return "PASS";
|
||||||
|
case 1:
|
||||||
|
}
|
||||||
|
}());
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
console.log(function() {
|
||||||
|
switch (0) {
|
||||||
|
default:
|
||||||
|
return "PASS";
|
||||||
|
case 1:
|
||||||
|
}
|
||||||
|
}());
|
||||||
|
}
|
||||||
|
expect_stdout: "PASS"
|
||||||
|
}
|
||||||
|
|
||||||
|
drop_switch_4: {
|
||||||
|
options = {
|
||||||
|
dead_code: true,
|
||||||
|
switches: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
var a = "FAIL";
|
||||||
|
switch (0) {
|
||||||
|
default:
|
||||||
|
case a:
|
||||||
|
var b = a = "PASS";
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
console.log(a);
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
var a = "FAIL";
|
||||||
|
0;
|
||||||
|
var b = a = "PASS";
|
||||||
|
console.log(a);
|
||||||
|
}
|
||||||
|
expect_stdout: "PASS"
|
||||||
|
}
|
||||||
|
|||||||
@@ -103,6 +103,7 @@ if_return: {
|
|||||||
booleans: true,
|
booleans: true,
|
||||||
conditionals: true,
|
conditionals: true,
|
||||||
if_return: true,
|
if_return: true,
|
||||||
|
passes: 2,
|
||||||
sequences: true,
|
sequences: true,
|
||||||
side_effects: true,
|
side_effects: true,
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ typeof_evaluation: {
|
|||||||
options = {
|
options = {
|
||||||
evaluate: true,
|
evaluate: true,
|
||||||
typeofs: true,
|
typeofs: true,
|
||||||
};
|
}
|
||||||
input: {
|
input: {
|
||||||
a = typeof 1;
|
a = typeof 1;
|
||||||
b = typeof 'test';
|
b = typeof 'test';
|
||||||
@@ -27,11 +27,11 @@ typeof_evaluation: {
|
|||||||
|
|
||||||
typeof_in_boolean_context: {
|
typeof_in_boolean_context: {
|
||||||
options = {
|
options = {
|
||||||
booleans : true,
|
booleans: true,
|
||||||
evaluate : true,
|
conditionals: true,
|
||||||
conditionals : true,
|
evaluate: true,
|
||||||
side_effects : true,
|
side_effects: true,
|
||||||
};
|
}
|
||||||
input: {
|
input: {
|
||||||
function f1(x) { return typeof x ? "yes" : "no"; }
|
function f1(x) { return typeof x ? "yes" : "no"; }
|
||||||
function f2() { return typeof g()? "Yes" : "No"; }
|
function f2() { return typeof g()? "Yes" : "No"; }
|
||||||
@@ -166,9 +166,7 @@ duplicate_lambda_arg_name: {
|
|||||||
}());
|
}());
|
||||||
}
|
}
|
||||||
expect: {
|
expect: {
|
||||||
console.log(function long_name(long_name) {
|
console.log("undefined");
|
||||||
return typeof long_name;
|
|
||||||
}());
|
|
||||||
}
|
}
|
||||||
expect_stdout: "undefined"
|
expect_stdout: "undefined"
|
||||||
}
|
}
|
||||||
@@ -295,3 +293,145 @@ issue_2728_6: {
|
|||||||
}
|
}
|
||||||
expect_stdout: "function undefined"
|
expect_stdout: "function undefined"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
typeof_defined_1: {
|
||||||
|
options = {
|
||||||
|
side_effects: true,
|
||||||
|
typeofs: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
"undefined" == typeof A && A;
|
||||||
|
"undefined" != typeof A && A;
|
||||||
|
"undefined" == typeof A || A;
|
||||||
|
"undefined" != typeof A || A;
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
"undefined" == typeof A && A;
|
||||||
|
"undefined" != typeof A || A;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
typeof_defined_2: {
|
||||||
|
options = {
|
||||||
|
side_effects: true,
|
||||||
|
typeofs: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
"function" == typeof A && A;
|
||||||
|
"function" != typeof A && A;
|
||||||
|
"function" == typeof A || A;
|
||||||
|
"function" != typeof A || A;
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
"function" != typeof A && A;
|
||||||
|
"function" == typeof A || A;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
typeof_defined_3: {
|
||||||
|
options = {
|
||||||
|
side_effects: true,
|
||||||
|
typeofs: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
"undefined" == typeof A && "undefined" == typeof B && (A, B);
|
||||||
|
"undefined" == typeof A && "undefined" != typeof B && (A, B);
|
||||||
|
"undefined" != typeof A && "undefined" == typeof B && (A, B);
|
||||||
|
"undefined" != typeof A && "undefined" != typeof B && (A, B);
|
||||||
|
"undefined" == typeof A && "undefined" == typeof B || (A, B);
|
||||||
|
"undefined" == typeof A && "undefined" != typeof B || (A, B);
|
||||||
|
"undefined" != typeof A && "undefined" == typeof B || (A, B);
|
||||||
|
"undefined" != typeof A && "undefined" != typeof B || (A, B);
|
||||||
|
"undefined" == typeof A || "undefined" == typeof B && (A, B);
|
||||||
|
"undefined" == typeof A || "undefined" != typeof B && (A, B);
|
||||||
|
"undefined" != typeof A || "undefined" == typeof B && (A, B);
|
||||||
|
"undefined" != typeof A || "undefined" != typeof B && (A, B);
|
||||||
|
"undefined" == typeof A || "undefined" == typeof B || (A, B);
|
||||||
|
"undefined" == typeof A || "undefined" != typeof B || (A, B);
|
||||||
|
"undefined" != typeof A || "undefined" == typeof B || (A, B);
|
||||||
|
"undefined" != typeof A || "undefined" != typeof B || (A, B);
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
"undefined" == typeof A && "undefined" == typeof B && (A, B);
|
||||||
|
"undefined" == typeof A && "undefined" != typeof B && A;
|
||||||
|
"undefined" != typeof A && "undefined" == typeof B && B;
|
||||||
|
"undefined" == typeof A && "undefined" == typeof B || (A, B);
|
||||||
|
"undefined" == typeof A && "undefined" != typeof B || (A, B);
|
||||||
|
"undefined" != typeof A && "undefined" == typeof B || (A, B);
|
||||||
|
"undefined" != typeof A && "undefined" != typeof B || (A, B);
|
||||||
|
"undefined" == typeof A || "undefined" == typeof B && B;
|
||||||
|
"undefined" != typeof A || "undefined" == typeof B && (A, B);
|
||||||
|
"undefined" != typeof A || "undefined" != typeof B && A;
|
||||||
|
"undefined" == typeof A || "undefined" != typeof B || B;
|
||||||
|
"undefined" != typeof A || "undefined" == typeof B || A;
|
||||||
|
"undefined" != typeof A || "undefined" != typeof B || (A, B);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
typeof_defined_4: {
|
||||||
|
options = {
|
||||||
|
side_effects: true,
|
||||||
|
typeofs: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
"object" == typeof A && "object" == typeof B && (A, B);
|
||||||
|
"object" == typeof A && "object" != typeof B && (A, B);
|
||||||
|
"object" != typeof A && "object" == typeof B && (A, B);
|
||||||
|
"object" != typeof A && "object" != typeof B && (A, B);
|
||||||
|
"object" == typeof A && "object" == typeof B || (A, B);
|
||||||
|
"object" == typeof A && "object" != typeof B || (A, B);
|
||||||
|
"object" != typeof A && "object" == typeof B || (A, B);
|
||||||
|
"object" != typeof A && "object" != typeof B || (A, B);
|
||||||
|
"object" == typeof A || "object" == typeof B && (A, B);
|
||||||
|
"object" == typeof A || "object" != typeof B && (A, B);
|
||||||
|
"object" != typeof A || "object" == typeof B && (A, B);
|
||||||
|
"object" != typeof A || "object" != typeof B && (A, B);
|
||||||
|
"object" == typeof A || "object" == typeof B || (A, B);
|
||||||
|
"object" == typeof A || "object" != typeof B || (A, B);
|
||||||
|
"object" != typeof A || "object" == typeof B || (A, B);
|
||||||
|
"object" != typeof A || "object" != typeof B || (A, B);
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
"object" == typeof A && "object" != typeof B && B;
|
||||||
|
"object" != typeof A && "object" == typeof B && A;
|
||||||
|
"object" != typeof A && "object" != typeof B && (A, B);
|
||||||
|
"object" == typeof A && "object" == typeof B || (A, B);
|
||||||
|
"object" == typeof A && "object" != typeof B || (A, B);
|
||||||
|
"object" != typeof A && "object" == typeof B || (A, B);
|
||||||
|
"object" != typeof A && "object" != typeof B || (A, B);
|
||||||
|
"object" == typeof A || "object" == typeof B && A;
|
||||||
|
"object" == typeof A || "object" != typeof B && (A, B);
|
||||||
|
"object" != typeof A || "object" != typeof B && B;
|
||||||
|
"object" == typeof A || "object" == typeof B || (A, B);
|
||||||
|
"object" == typeof A || "object" != typeof B || A;
|
||||||
|
"object" != typeof A || "object" == typeof B || B;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
emberjs_global: {
|
||||||
|
options = {
|
||||||
|
comparisons: true,
|
||||||
|
conditionals: true,
|
||||||
|
if_return: true,
|
||||||
|
passes: 2,
|
||||||
|
side_effects: true,
|
||||||
|
toplevel: true,
|
||||||
|
typeofs: true,
|
||||||
|
unused: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
var a;
|
||||||
|
if (typeof A === "object") {
|
||||||
|
a = A;
|
||||||
|
} else if (typeof B === "object") {
|
||||||
|
a = B;
|
||||||
|
} else {
|
||||||
|
throw new Error("PASS");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
if ("object" != typeof A && "object" != typeof B)
|
||||||
|
throw new Error("PASS");
|
||||||
|
}
|
||||||
|
expect_stdout: Error("PASS")
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
unicode_parse_variables: {
|
unicode_parse_variables: {
|
||||||
options = {};
|
options = {}
|
||||||
input: {
|
input: {
|
||||||
var a = {};
|
var a = {};
|
||||||
a.你好 = 456;
|
a.你好 = 456;
|
||||||
@@ -16,6 +16,81 @@ unicode_parse_variables: {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
unicode_escaped_identifier: {
|
||||||
|
input: {
|
||||||
|
var \u0061 = "\ud800\udc00";
|
||||||
|
console.log(a);
|
||||||
|
}
|
||||||
|
expect_exact: 'var a="\ud800\udc00";console.log(a);'
|
||||||
|
expect_stdout: "\ud800\udc00"
|
||||||
|
}
|
||||||
|
|
||||||
|
unicode_identifier_ascii_only: {
|
||||||
|
beautify = {
|
||||||
|
ascii_only: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
var \u0061 = "testing \udbc4\udd11";
|
||||||
|
var bar = "h\u0065llo";
|
||||||
|
console.log(a, \u0062\u0061r);
|
||||||
|
}
|
||||||
|
expect_exact: 'var a="testing \\udbc4\\udd11";var bar="hello";console.log(a,bar);'
|
||||||
|
expect_stdout: "testing \udbc4\udd11 hello"
|
||||||
|
}
|
||||||
|
|
||||||
|
unicode_string_literals: {
|
||||||
|
beautify = {
|
||||||
|
ascii_only: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
var a = "6 length unicode character: \udbc4\udd11";
|
||||||
|
console.log(\u0061);
|
||||||
|
}
|
||||||
|
expect_exact: 'var a="6 length unicode character: \\udbc4\\udd11";console.log(a);'
|
||||||
|
expect_stdout: "6 length unicode character: \udbc4\udd11"
|
||||||
|
}
|
||||||
|
|
||||||
|
check_escape_style: {
|
||||||
|
beautify = {
|
||||||
|
ascii_only: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
var a = "\x01";
|
||||||
|
var \ua0081 = "\x10"; // \u0081 only in ID_Continue
|
||||||
|
var \u0100 = "\u0100";
|
||||||
|
var \u1000 = "\u1000";
|
||||||
|
var \u1000 = "\ud800\udc00";
|
||||||
|
var \u3f80 = "\udbc0\udc00";
|
||||||
|
console.log(\u0061, \ua0081, \u0100, \u1000, \u3f80);
|
||||||
|
}
|
||||||
|
expect_exact: 'var a="\\x01";var \\ua0081="\\x10";var \\u0100="\\u0100";var \\u1000="\\u1000";var \\u1000="\\ud800\\udc00";var \\u3f80="\\udbc0\\udc00";console.log(a,\\ua0081,\\u0100,\\u1000,\\u3f80);'
|
||||||
|
expect_stdout: "\u0001 \u0010 \u0100 \ud800\udc00 \udbc0\udc00"
|
||||||
|
}
|
||||||
|
|
||||||
|
escape_non_escaped_identifier: {
|
||||||
|
beautify = {
|
||||||
|
ascii_only: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
var µþ = "µþ";
|
||||||
|
console.log(\u00b5þ);
|
||||||
|
}
|
||||||
|
expect_exact: 'var \\u00b5\\u00fe="\\xb5\\xfe";console.log(\\u00b5\\u00fe);'
|
||||||
|
expect_stdout: "µþ"
|
||||||
|
}
|
||||||
|
|
||||||
|
non_escape_2_non_escape: {
|
||||||
|
beautify = {
|
||||||
|
ascii_only: false,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
var µþ = "µþ";
|
||||||
|
console.log(\u00b5þ);
|
||||||
|
}
|
||||||
|
expect_exact: 'var µþ="µþ";console.log(µþ);'
|
||||||
|
expect_stdout: "µþ"
|
||||||
|
}
|
||||||
|
|
||||||
issue_2242_1: {
|
issue_2242_1: {
|
||||||
beautify = {
|
beautify = {
|
||||||
ascii_only: false,
|
ascii_only: false,
|
||||||
@@ -24,6 +99,7 @@ issue_2242_1: {
|
|||||||
console.log("\ud83d", "\ude00", "\ud83d\ude00", "\ud83d@\ude00");
|
console.log("\ud83d", "\ude00", "\ud83d\ude00", "\ud83d@\ude00");
|
||||||
}
|
}
|
||||||
expect_exact: 'console.log("\\ud83d","\\ude00","\ud83d\ude00","\\ud83d@\\ude00");'
|
expect_exact: 'console.log("\\ud83d","\\ude00","\ud83d\ude00","\\ud83d@\\ude00");'
|
||||||
|
expect_stdout: "\ud83d \ude00 \ud83d\ude00 \ud83d@\ude00"
|
||||||
}
|
}
|
||||||
|
|
||||||
issue_2242_2: {
|
issue_2242_2: {
|
||||||
@@ -34,6 +110,7 @@ issue_2242_2: {
|
|||||||
console.log("\ud83d", "\ude00", "\ud83d\ude00", "\ud83d@\ude00");
|
console.log("\ud83d", "\ude00", "\ud83d\ude00", "\ud83d@\ude00");
|
||||||
}
|
}
|
||||||
expect_exact: 'console.log("\\ud83d","\\ude00","\\ud83d\\ude00","\\ud83d@\\ude00");'
|
expect_exact: 'console.log("\\ud83d","\\ude00","\\ud83d\\ude00","\\ud83d@\\ude00");'
|
||||||
|
expect_stdout: "\ud83d \ude00 \ud83d\ude00 \ud83d@\ude00"
|
||||||
}
|
}
|
||||||
|
|
||||||
issue_2242_3: {
|
issue_2242_3: {
|
||||||
@@ -44,6 +121,7 @@ issue_2242_3: {
|
|||||||
console.log("\ud83d" + "\ude00", "\ud83d" + "@" + "\ude00");
|
console.log("\ud83d" + "\ude00", "\ud83d" + "@" + "\ude00");
|
||||||
}
|
}
|
||||||
expect_exact: 'console.log("\\ud83d"+"\\ude00","\\ud83d"+"@"+"\\ude00");'
|
expect_exact: 'console.log("\\ud83d"+"\\ude00","\\ud83d"+"@"+"\\ude00");'
|
||||||
|
expect_stdout: "\ud83d\ude00 \ud83d@\ude00"
|
||||||
}
|
}
|
||||||
|
|
||||||
issue_2242_4: {
|
issue_2242_4: {
|
||||||
@@ -54,6 +132,7 @@ issue_2242_4: {
|
|||||||
console.log("\ud83d" + "\ude00", "\ud83d" + "@" + "\ude00");
|
console.log("\ud83d" + "\ude00", "\ud83d" + "@" + "\ude00");
|
||||||
}
|
}
|
||||||
expect_exact: 'console.log("\ud83d\ude00","\\ud83d@\\ude00");'
|
expect_exact: 'console.log("\ud83d\ude00","\\ud83d@\\ude00");'
|
||||||
|
expect_stdout: "\ud83d\ude00 \ud83d@\ude00"
|
||||||
}
|
}
|
||||||
|
|
||||||
issue_2569: {
|
issue_2569: {
|
||||||
|
|||||||
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["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["defaults"] = defaults;
|
||||||
|
exports["JS_Parse_Error"] = JS_Parse_Error;
|
||||||
exports["mangle_properties"] = mangle_properties;
|
exports["mangle_properties"] = mangle_properties;
|
||||||
exports["minify"] = minify;
|
exports["minify"] = minify;
|
||||||
|
exports["OutputStream"] = OutputStream;
|
||||||
exports["parse"] = parse;
|
exports["parse"] = parse;
|
||||||
|
exports["push_uniq"] = push_uniq;
|
||||||
exports["reserve_quoted_keys"] = reserve_quoted_keys;
|
exports["reserve_quoted_keys"] = reserve_quoted_keys;
|
||||||
exports["string_template"] = string_template;
|
exports["string_template"] = string_template;
|
||||||
|
exports["to_ascii"] = to_ascii;
|
||||||
exports["tokenizer"] = tokenizer;
|
exports["tokenizer"] = tokenizer;
|
||||||
exports["is_identifier"] = is_identifier;
|
exports["TreeTransformer"] = TreeTransformer;
|
||||||
|
exports["TreeWalker"] = TreeWalker;
|
||||||
|
|||||||
@@ -23,10 +23,9 @@ module.exports = function(url, callback) {
|
|||||||
var options = parse(url);
|
var options = parse(url);
|
||||||
options.rejectUnauthorized = false;
|
options.rejectUnauthorized = false;
|
||||||
require(options.protocol.slice(0, -1)).get(options, function(res) {
|
require(options.protocol.slice(0, -1)).get(options, function(res) {
|
||||||
if (res.statusCode !== 200) return callback(res);
|
if (res.statusCode !== 200) return callback(res.statusCode);
|
||||||
res.pipe(fs.createWriteStream(local(url)).on("close", function() {
|
res.pipe(fs.createWriteStream(local(url)));
|
||||||
callback(null, read(url));
|
callback(null, res);
|
||||||
}));
|
|
||||||
});
|
});
|
||||||
}).on("open", function() {
|
}).on("open", function() {
|
||||||
callback(null, result);
|
callback(null, result);
|
||||||
|
|||||||
17
test/input/issue-1482/beautify.js
Normal file
17
test/input/issue-1482/beautify.js
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
if (x) foo();
|
||||||
|
|
||||||
|
if (x) foo(); else baz();
|
||||||
|
|
||||||
|
if (x) foo(); else if (y) bar(); else baz();
|
||||||
|
|
||||||
|
if (x) if (y) foo(); else bar(); else baz();
|
||||||
|
|
||||||
|
if (x) foo(); else if (y) bar(); else if (z) baz(); else moo();
|
||||||
|
|
||||||
|
function f() {
|
||||||
|
if (x) foo();
|
||||||
|
if (x) foo(); else baz();
|
||||||
|
if (x) foo(); else if (y) bar(); else baz();
|
||||||
|
if (x) if (y) foo(); else bar(); else baz();
|
||||||
|
if (x) foo(); else if (y) bar(); else if (z) baz(); else moo();
|
||||||
|
}
|
||||||
@@ -1,17 +1 @@
|
|||||||
if (x) foo();
|
if(x)foo();if(x)foo();else baz();if(x)foo();else if(y)bar();else baz();if(x)if(y)foo();else bar();else baz();if(x)foo();else if(y)bar();else if(z)baz();else moo();function f(){if(x)foo();if(x)foo();else baz();if(x)foo();else if(y)bar();else baz();if(x)if(y)foo();else bar();else baz();if(x)foo();else if(y)bar();else if(z)baz();else moo()}
|
||||||
|
|
||||||
if (x) foo(); else baz();
|
|
||||||
|
|
||||||
if (x) foo(); else if (y) bar(); else baz();
|
|
||||||
|
|
||||||
if (x) if (y) foo(); else bar(); else baz();
|
|
||||||
|
|
||||||
if (x) foo(); else if (y) bar(); else if (z) baz(); else moo();
|
|
||||||
|
|
||||||
function f() {
|
|
||||||
if (x) foo();
|
|
||||||
if (x) foo(); else baz();
|
|
||||||
if (x) foo(); else if (y) bar(); else baz();
|
|
||||||
if (x) if (y) foo(); else bar(); else baz();
|
|
||||||
if (x) foo(); else if (y) bar(); else if (z) baz(); else moo();
|
|
||||||
}
|
|
||||||
|
|||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user