Compare commits
213 Commits
harmony-v3
...
harmony-v3
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b84c99ef5c | ||
|
|
4f08c2f504 | ||
|
|
b37a68c84f | ||
|
|
c141ae6f8d | ||
|
|
97c464dbf5 | ||
|
|
ba4894af18 | ||
|
|
f1e3ef5262 | ||
|
|
3b28b915eb | ||
|
|
eb001dc1d9 | ||
|
|
aa9bdf416e | ||
|
|
bbf38dc9c0 | ||
|
|
8987780db6 | ||
|
|
30cfea2e7a | ||
|
|
3d8341a7ab | ||
|
|
f4e2fb9864 | ||
|
|
567cb0e4e3 | ||
|
|
b80062c490 | ||
|
|
227b58812d | ||
|
|
f25bd13be6 | ||
|
|
667fc4d08b | ||
|
|
6142117cdd | ||
|
|
e826973b76 | ||
|
|
ae28a24c7f | ||
|
|
ebe761cad0 | ||
|
|
fa7a7c5c5a | ||
|
|
557636f3b7 | ||
|
|
49fbe9c5ac | ||
|
|
2ac5086831 | ||
|
|
c6cfa04d10 | ||
|
|
9632f79e46 | ||
|
|
a3fbb27194 | ||
|
|
11c0b1e1f9 | ||
|
|
346fa12e0e | ||
|
|
cda27b0970 | ||
|
|
3c74047368 | ||
|
|
650d5d5c9b | ||
|
|
94525d859f | ||
|
|
1127a2caf3 | ||
|
|
246d9d4e83 | ||
|
|
4c0b0177b6 | ||
|
|
dd0a36119b | ||
|
|
94b19a9c46 | ||
|
|
bcf95ac02c | ||
|
|
e11cec1ab8 | ||
|
|
38bfb73f06 | ||
|
|
bbedbf4ea0 | ||
|
|
2cfb5aa7da | ||
|
|
6c45101870 | ||
|
|
2c2fd89e34 | ||
|
|
0c43519097 | ||
|
|
352a7de204 | ||
|
|
df9c8dfd72 | ||
|
|
f46281e2b7 | ||
|
|
25a18883f5 | ||
|
|
5b4b07e9a7 | ||
|
|
a8aa28a7a6 | ||
|
|
fe5a68f9d5 | ||
|
|
71e61153b1 | ||
|
|
c8b6f4733d | ||
|
|
29bbc41dfe | ||
|
|
a48f87abf2 | ||
|
|
d535daa2c7 | ||
|
|
0a9cdb6c73 | ||
|
|
3ae34177a6 | ||
|
|
086cb33163 | ||
|
|
2fd927a7cc | ||
|
|
8428326ea1 | ||
|
|
6371e2ee63 | ||
|
|
6ab73c7bd5 | ||
|
|
31f8209193 | ||
|
|
9b0f86f5a1 | ||
|
|
ee082ace1b | ||
|
|
ae67a49850 | ||
|
|
4178289c38 | ||
|
|
74ae16f9f8 | ||
|
|
1968203d83 | ||
|
|
2848596280 | ||
|
|
86ea38a259 | ||
|
|
8a713e449f | ||
|
|
7d9a8596a9 | ||
|
|
24aa07855b | ||
|
|
5fd723f143 | ||
|
|
516eaef50c | ||
|
|
4ae1fb3ed8 | ||
|
|
011123223b | ||
|
|
44352eb26a | ||
|
|
9f1c72ae28 | ||
|
|
c60fa67827 | ||
|
|
96439ca246 | ||
|
|
f9c57dfee0 | ||
|
|
c927cea632 | ||
|
|
9f4b98f8e4 | ||
|
|
0f2ef3367c | ||
|
|
6bf5fea008 | ||
|
|
7e5b5cac97 | ||
|
|
c1346e06b7 | ||
|
|
0d2fe8e3ef | ||
|
|
f2b9c11e2a | ||
|
|
b6a7ca292e | ||
|
|
fe647b083e | ||
|
|
a89f126db6 | ||
|
|
d8ee2de95c | ||
|
|
58a5608b66 | ||
|
|
f496ac5c85 | ||
|
|
dfe4f6c6de | ||
|
|
a09c8ad666 | ||
|
|
ec598c351b | ||
|
|
f79f737fb2 | ||
|
|
eba0f93bc0 | ||
|
|
99800d4aa9 | ||
|
|
70d56c951a | ||
|
|
b810e2f8da | ||
|
|
1abe14296e | ||
|
|
336b1add4f | ||
|
|
873755b35c | ||
|
|
744032755d | ||
|
|
4fac8076b8 | ||
|
|
6920e898d1 | ||
|
|
dd71639264 | ||
|
|
2dcc552ce0 | ||
|
|
a020d2ead3 | ||
|
|
68645b28d3 | ||
|
|
aaa8212837 | ||
|
|
bd84007cf4 | ||
|
|
55387e8fd0 | ||
|
|
1241600013 | ||
|
|
7e3e9da860 | ||
|
|
a784717fe2 | ||
|
|
00f509405b | ||
|
|
e8235657e4 | ||
|
|
c46b9f361a | ||
|
|
3b0b4d6abf | ||
|
|
d73500e8d1 | ||
|
|
aceb0af36b | ||
|
|
4f0953f7e9 | ||
|
|
182a47bfb1 | ||
|
|
d8685f528d | ||
|
|
8891495789 | ||
|
|
cd27f4ec38 | ||
|
|
8158b1bdcf | ||
|
|
aacf3edc68 | ||
|
|
8b89072190 | ||
|
|
395a17ccda | ||
|
|
3f355866cf | ||
|
|
2779a29a86 | ||
|
|
71d52f147d | ||
|
|
eb7adaa6fc | ||
|
|
e5cf7972ea | ||
|
|
067d52b6ba | ||
|
|
e0e009ace2 | ||
|
|
f81ff10a9b | ||
|
|
ae0f117da6 | ||
|
|
a5461e0adc | ||
|
|
16d40915b4 | ||
|
|
2bf8216e50 | ||
|
|
2ed3f8db44 | ||
|
|
4700c14855 | ||
|
|
e7c21e87e3 | ||
|
|
f54ab16843 | ||
|
|
69cb459c16 | ||
|
|
1eae8f2dcc | ||
|
|
c4c2ef44d0 | ||
|
|
a845897758 | ||
|
|
d600c78d7b | ||
|
|
32ea2c5530 | ||
|
|
d3df2f985d | ||
|
|
69861824b5 | ||
|
|
1e0c7d2bc5 | ||
|
|
98b850580b | ||
|
|
29011ea60a | ||
|
|
77d18be073 | ||
|
|
bc61deeca9 | ||
|
|
6a5e74b44e | ||
|
|
54446341ee | ||
|
|
91f8b57b3e | ||
|
|
3a2b737c42 | ||
|
|
4e12a6f740 | ||
|
|
b35dfc2599 | ||
|
|
9e1da9235e | ||
|
|
a5ffe2c23f | ||
|
|
9282e7b0c6 | ||
|
|
5229cb2b1b | ||
|
|
458e3e15f0 | ||
|
|
c615a1e80a | ||
|
|
10a938cb79 | ||
|
|
0f4278148d | ||
|
|
4956ad311b | ||
|
|
145874e504 | ||
|
|
f30375052b | ||
|
|
3e1a8598bf | ||
|
|
ef63de6968 | ||
|
|
2539fb8096 | ||
|
|
a556dd2dcb | ||
|
|
bd7be07c38 | ||
|
|
71ee91e716 | ||
|
|
e7334b4048 | ||
|
|
4f70d2e28c | ||
|
|
4b6ca5e742 | ||
|
|
f5c46db738 | ||
|
|
9306da3c58 | ||
|
|
1ac25fc032 | ||
|
|
fdbb1d09ef | ||
|
|
5f046c724b | ||
|
|
af0262b7e5 | ||
|
|
6b3aeff1d8 | ||
|
|
20e4f8277f | ||
|
|
f3a487a368 | ||
|
|
33ad0d258c | ||
|
|
5ea1da2d42 | ||
|
|
e77b6d525c | ||
|
|
2dde41615a | ||
|
|
8b69a3d18e | ||
|
|
d40950b741 |
11
.github/ISSUE_TEMPLATE.md
vendored
11
.github/ISSUE_TEMPLATE.md
vendored
@@ -8,7 +8,16 @@
|
|||||||
|
|
||||||
**Uglify version (`uglifyjs -V`)**
|
**Uglify version (`uglifyjs -V`)**
|
||||||
|
|
||||||
**JavaScript input** <!-- ideally as small as possible -->
|
**JavaScript input**
|
||||||
|
|
||||||
|
<!--
|
||||||
|
A complete parsable JS program exhibiting the issue with
|
||||||
|
UglifyJS alone - without third party tools or libraries.
|
||||||
|
Ideally the input should be as small as possible.
|
||||||
|
Post a link to a gist if necessary.
|
||||||
|
|
||||||
|
Issues without a reproducible test case will be closed.
|
||||||
|
-->
|
||||||
|
|
||||||
**The `uglifyjs` CLI command executed or `minify()` options used.**
|
**The `uglifyjs` CLI command executed or `minify()` options used.**
|
||||||
|
|
||||||
|
|||||||
368
README.md
368
README.md
@@ -1,7 +1,7 @@
|
|||||||
uglify-es
|
uglify-es
|
||||||
=========
|
=========
|
||||||
|
|
||||||
**uglify-es** is an ECMAScript parser, minifier, compressor and beautifier toolkit for ES6+.
|
A JavaScript parser, mangler/compressor and beautifier toolkit for ES6+.
|
||||||
|
|
||||||
#### Note:
|
#### Note:
|
||||||
- **`uglify-es` is API/CLI compatible with `uglify-js@3`.**
|
- **`uglify-es` is API/CLI compatible with `uglify-js@3`.**
|
||||||
@@ -102,11 +102,12 @@ a double dash to prevent input files being used as option arguments:
|
|||||||
sequences.
|
sequences.
|
||||||
--config-file <file> Read `minify()` options from JSON file.
|
--config-file <file> Read `minify()` options from JSON file.
|
||||||
-d, --define <expr>[=value] Global definitions.
|
-d, --define <expr>[=value] Global definitions.
|
||||||
--ecma <version> Specifiy ECMAScript release: 5, 6, 7 or 8.
|
--ecma <version> Specify ECMAScript release: 5, 6, 7 or 8.
|
||||||
--ie8 Support non-standard Internet Explorer 8.
|
--ie8 Support non-standard Internet Explorer 8.
|
||||||
Equivalent to setting `ie8: true` in `minify()`
|
Equivalent to setting `ie8: true` in `minify()`
|
||||||
for `compress`, `mangle` and `output` options.
|
for `compress`, `mangle` and `output` options.
|
||||||
By default UglifyJS will not try to be IE-proof.
|
By default UglifyJS will not try to be IE-proof.
|
||||||
|
--keep-classnames Do not mangle/drop class names.
|
||||||
--keep-fnames Do not mangle/drop function names. Useful for
|
--keep-fnames Do not mangle/drop function names. Useful for
|
||||||
code relying on Function.prototype.name.
|
code relying on Function.prototype.name.
|
||||||
--name-cache <file> File to hold mangled name mappings.
|
--name-cache <file> File to hold mangled name mappings.
|
||||||
@@ -148,19 +149,19 @@ debugging your compressed JavaScript. To get a source map, pass
|
|||||||
|
|
||||||
Additional options:
|
Additional options:
|
||||||
|
|
||||||
- `--source-map filename=<NAME>` to specify the name of the source map.
|
- `--source-map "filename='<NAME>'"` to specify the name of the source map.
|
||||||
|
|
||||||
- `--source-map root=<URL>` to pass the URL where the original files can be found.
|
- `--source-map "root='<URL>'"` to pass the URL where the original files can be found.
|
||||||
|
|
||||||
|
- `--source-map "url='<URL>'"` to specify the URL where the source map can be found.
|
||||||
Otherwise UglifyJS assumes HTTP `X-SourceMap` is being used and will omit the
|
Otherwise UglifyJS assumes HTTP `X-SourceMap` is being used and will omit the
|
||||||
`//# sourceMappingURL=` directive.
|
`//# sourceMappingURL=` directive.
|
||||||
|
|
||||||
- `--source-map url=<URL>` to specify the URL where the source map can be found.
|
|
||||||
|
|
||||||
For example:
|
For example:
|
||||||
|
|
||||||
uglifyjs js/file1.js js/file2.js \
|
uglifyjs js/file1.js js/file2.js \
|
||||||
-o foo.min.js -c -m \
|
-o foo.min.js -c -m \
|
||||||
--source-map root="http://foo.com/src",url=foo.min.js.map
|
--source-map "root='http://foo.com/src',url='foo.min.js.map'"
|
||||||
|
|
||||||
The above will compress and mangle `file1.js` and `file2.js`, will drop the
|
The above will compress and mangle `file1.js` and `file2.js`, will drop the
|
||||||
output in `foo.min.js` and the source map in `foo.min.js.map`. The source
|
output in `foo.min.js` and the source map in `foo.min.js.map`. The source
|
||||||
@@ -179,8 +180,8 @@ CoffeeScript → compiled JS, UglifyJS can generate a map from CoffeeScript →
|
|||||||
compressed JS by mapping every token in the compiled JS to its original
|
compressed JS by mapping every token in the compiled JS to its original
|
||||||
location.
|
location.
|
||||||
|
|
||||||
To use this feature pass `--source-map content="/path/to/input/source.map"`
|
To use this feature pass `--source-map "content='/path/to/input/source.map'"`
|
||||||
or `--source-map content=inline` if the source map is included inline with
|
or `--source-map "content=inline"` if the source map is included inline with
|
||||||
the sources.
|
the sources.
|
||||||
|
|
||||||
## CLI compress options
|
## CLI compress options
|
||||||
@@ -201,17 +202,15 @@ Example:
|
|||||||
To enable the mangler you need to pass `--mangle` (`-m`). The following
|
To enable the mangler you need to pass `--mangle` (`-m`). The following
|
||||||
(comma-separated) options are supported:
|
(comma-separated) options are supported:
|
||||||
|
|
||||||
- `toplevel` — mangle names declared in the top level scope (disabled by
|
- `toplevel` (default `false`) -- mangle names declared in the top level scope.
|
||||||
default).
|
|
||||||
|
|
||||||
- `eval` — mangle names visible in scopes where `eval` or `with` are used
|
- `eval` (default `false`) -- mangle names visible in scopes where `eval` or `with` are used.
|
||||||
(disabled by default).
|
|
||||||
|
|
||||||
When mangling is enabled but you want to prevent certain names from being
|
When mangling is enabled but you want to prevent certain names from being
|
||||||
mangled, you can declare those names with `--mangle reserved` — pass a
|
mangled, you can declare those names with `--mangle reserved` — pass a
|
||||||
comma-separated list of names. For example:
|
comma-separated list of names. For example:
|
||||||
|
|
||||||
uglifyjs ... -m reserved=[$,require,exports]
|
uglifyjs ... -m reserved=['$','require','exports']
|
||||||
|
|
||||||
to prevent the `require`, `exports` and `$` names from being changed.
|
to prevent the `require`, `exports` and `$` names from being changed.
|
||||||
|
|
||||||
@@ -221,7 +220,7 @@ to prevent the `require`, `exports` and `$` names from being changed.
|
|||||||
is a separate step, different from variable name mangling. Pass
|
is a separate step, different from variable name mangling. Pass
|
||||||
`--mangle-props` to enable it. It will mangle all properties in the
|
`--mangle-props` to enable it. It will mangle all properties in the
|
||||||
input code with the exception of built in DOM properties and properties
|
input code with the exception of built in DOM properties and properties
|
||||||
in core javascript classes. For example:
|
in core JavaScript classes. For example:
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
// example.js
|
// example.js
|
||||||
@@ -236,7 +235,7 @@ x.bar_ = 2;
|
|||||||
x["baz_"] = 3;
|
x["baz_"] = 3;
|
||||||
console.log(x.calc());
|
console.log(x.calc());
|
||||||
```
|
```
|
||||||
Mangle all properties (except for javascript `builtins`):
|
Mangle all properties (except for JavaScript `builtins`):
|
||||||
```bash
|
```bash
|
||||||
$ uglifyjs example.js -c -m --mangle-props
|
$ uglifyjs example.js -c -m --mangle-props
|
||||||
```
|
```
|
||||||
@@ -511,6 +510,14 @@ if (result.error) throw result.error;
|
|||||||
|
|
||||||
- `ie8` (default `false`) - set to `true` to support IE8.
|
- `ie8` (default `false`) - set to `true` to support IE8.
|
||||||
|
|
||||||
|
- `keep_classnames` (default: `undefined`) - pass `true` to prevent discarding or mangling
|
||||||
|
of class names.
|
||||||
|
|
||||||
|
- `keep_fnames` (default: `false`) - pass `true` to prevent discarding or mangling
|
||||||
|
of function names. Useful for code relying on `Function.prototype.name`. If the
|
||||||
|
top level minify option `keep_classnames` is `undefined` it will be overriden with
|
||||||
|
the value of the top level minify option `keep_fnames`.
|
||||||
|
|
||||||
## Minify options structure
|
## Minify options structure
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
@@ -537,6 +544,8 @@ if (result.error) throw result.error;
|
|||||||
ecma: 5, // specify one of: 5, 6, 7 or 8
|
ecma: 5, // specify one of: 5, 6, 7 or 8
|
||||||
nameCache: null, // or specify a name cache object
|
nameCache: null, // or specify a name cache object
|
||||||
toplevel: false,
|
toplevel: false,
|
||||||
|
keep_classnames: false,
|
||||||
|
keep_fnames: false,
|
||||||
ie8: false,
|
ie8: false,
|
||||||
warnings: false,
|
warnings: false,
|
||||||
}
|
}
|
||||||
@@ -592,114 +601,106 @@ If you're using the `X-SourceMap` header instead, you can just omit `sourceMap.u
|
|||||||
## Parse options
|
## Parse options
|
||||||
|
|
||||||
- `bare_returns` (default `false`) -- support top level `return` statements
|
- `bare_returns` (default `false`) -- support top level `return` statements
|
||||||
|
|
||||||
- `ecma` (default: `8`) -- specify one of `5`, `6`, `7` or `8`. Note: this setting
|
- `ecma` (default: `8`) -- specify one of `5`, `6`, `7` or `8`. Note: this setting
|
||||||
is not presently enforced except for ES8 optional trailing commas in function
|
is not presently enforced except for ES8 optional trailing commas in function
|
||||||
parameter lists and calls with `ecma` `8`.
|
parameter lists and calls with `ecma` `8`.
|
||||||
|
|
||||||
- `html5_comments` (default `true`)
|
- `html5_comments` (default `true`)
|
||||||
|
|
||||||
- `shebang` (default `true`) -- support `#!command` as the first line
|
- `shebang` (default `true`) -- support `#!command` as the first line
|
||||||
|
|
||||||
## Compress options
|
## Compress options
|
||||||
|
|
||||||
- `sequences` (default: true) -- join consecutive simple statements using the
|
- `arrows` (default: `true`) -- Converts `()=>{return x}` to `()=>x`. Class
|
||||||
comma operator. May be set to a positive integer to specify the maximum number
|
and object literal methods will also be converted to arrow expressions if
|
||||||
of consecutive comma sequences that will be generated. If this option is set to
|
the resultant code is shorter: `m(){return x}` becomes `m:()=>x`.
|
||||||
`true` then the default `sequences` limit is `200`. Set option to `false` or `0`
|
This transform requires that the `ecma` compress option is set to `6` or greater.
|
||||||
to disable. The smallest `sequences` length is `2`. A `sequences` value of `1`
|
|
||||||
is grandfathered to be equivalent to `true` and as such means `200`. On rare
|
|
||||||
occasions the default sequences limit leads to very slow compress times in which
|
|
||||||
case a value of `20` or less is recommended.
|
|
||||||
|
|
||||||
- `properties` -- rewrite property access using the dot notation, for
|
- `booleans` (default: `true`) -- various optimizations for boolean context,
|
||||||
example `foo["bar"] → foo.bar`
|
for example `!!a ? b : c → a ? b : c`
|
||||||
|
|
||||||
- `dead_code` -- remove unreachable code
|
- `cascade` (default: `true`) -- small optimization for sequences, transform
|
||||||
|
`x, x` into `x` and `x = something(), x` into `x = something()`
|
||||||
|
|
||||||
- `drop_debugger` -- remove `debugger;` statements
|
- `collapse_vars` (default: `true`) -- Collapse single-use non-constant variables,
|
||||||
|
side effects permitting.
|
||||||
|
|
||||||
- `unsafe` (default: false) -- apply "unsafe" transformations (discussion below)
|
- `comparisons` (default: `true`) -- apply certain optimizations to binary nodes,
|
||||||
|
e.g. `!(a <= b) → a > b` (only when `unsafe_comps`), attempts to negate binary
|
||||||
- `unsafe_comps` (default: false) -- Reverse `<` and `<=` to `>` and `>=` to
|
|
||||||
allow improved compression. This might be unsafe when an at least one of two
|
|
||||||
operands is an object with computed values due the use of methods like `get`,
|
|
||||||
or `valueOf`. This could cause change in execution order after operands in the
|
|
||||||
comparison are switching. Compression only works if both `comparisons` and
|
|
||||||
`unsafe_comps` are both set to true.
|
|
||||||
|
|
||||||
- `unsafe_Func` (default: false) -- compress and mangle `Function(args, code)`
|
|
||||||
when both `args` and `code` are string literals.
|
|
||||||
|
|
||||||
- `unsafe_math` (default: false) -- optimize numerical expressions like
|
|
||||||
`2 * x * 3` into `6 * x`, which may give imprecise floating point results.
|
|
||||||
|
|
||||||
- `unsafe_proto` (default: false) -- optimize expressions like
|
|
||||||
`Array.prototype.slice.call(a)` into `[].slice.call(a)`
|
|
||||||
|
|
||||||
- `unsafe_regexp` (default: false) -- enable substitutions of variables with
|
|
||||||
`RegExp` values the same way as if they are constants.
|
|
||||||
|
|
||||||
- `conditionals` -- apply optimizations for `if`-s and conditional
|
|
||||||
expressions
|
|
||||||
|
|
||||||
- `comparisons` -- apply certain optimizations to binary nodes, for example:
|
|
||||||
`!(a <= b) → a > b` (only when `unsafe_comps`), attempts to negate binary
|
|
||||||
nodes, e.g. `a = !b && !c && !d && !e → a=!(b||c||d||e)` etc.
|
nodes, e.g. `a = !b && !c && !d && !e → a=!(b||c||d||e)` etc.
|
||||||
|
|
||||||
- `evaluate` -- attempt to evaluate constant expressions
|
- `computed_props` (default: `true`) -- Transforms constant computed properties
|
||||||
|
into regular ones: `{["computed"]: 1}` is converted to `{computed: 1}`.
|
||||||
|
|
||||||
- `arrows` (default `true`) -- convert ES5 style anonymous function expressions
|
- `conditionals` (default: `true`) -- apply optimizations for `if`-s and conditional
|
||||||
to arrow functions if permissible by language semantics.
|
expressions
|
||||||
Note: `arrows` requires that the `ecma` compress option is set to `6` or greater.
|
|
||||||
|
|
||||||
- `booleans` -- various optimizations for boolean context, for example `!!a
|
- `dead_code` (default: `true`) -- remove unreachable code
|
||||||
? b : c → a ? b : c`
|
|
||||||
|
|
||||||
- `loops` -- optimizations for `do`, `while` and `for` loops when we can
|
- `drop_console` (default: `false`) -- Pass `true` to discard calls to
|
||||||
statically determine the condition
|
`console.*` functions. If you wish to drop a specific function call
|
||||||
|
such as `console.info` and/or retain side effects from function arguments
|
||||||
|
after dropping the function call then use `pure_funcs` instead.
|
||||||
|
|
||||||
- `unused` -- drop unreferenced functions and variables (simple direct variable
|
- `drop_debugger` (default: `true`) -- remove `debugger;` statements
|
||||||
assignments do not count as references unless set to `"keep_assign"`)
|
|
||||||
|
|
||||||
- `toplevel` -- drop unreferenced functions (`"funcs"`) and/or variables (`"vars"`)
|
- `ecma` (default: `5`) -- Pass `6` or greater to enable `compress` options that
|
||||||
in the top level scope (`false` by default, `true` to drop both unreferenced
|
will transform ES5 code into smaller ES6+ equivalent forms.
|
||||||
functions and variables)
|
|
||||||
|
|
||||||
- `top_retain` -- prevent specific toplevel functions and variables from `unused`
|
- `evaluate` (default: `true`) -- attempt to evaluate constant expressions
|
||||||
removal (can be array, comma-separated, RegExp or function. Implies `toplevel`)
|
|
||||||
|
|
||||||
- `hoist_funs` -- hoist function declarations
|
- `expression` (default: `false`) -- Pass `true` to preserve completion values
|
||||||
|
from terminal statements without `return`, e.g. in bookmarklets.
|
||||||
|
|
||||||
- `hoist_vars` (default: false) -- hoist `var` declarations (this is `false`
|
- `global_defs` (default: `{}`) -- see [conditional compilation](#conditional-compilation)
|
||||||
|
|
||||||
|
- `hoist_funs` (default: `true`) -- hoist function declarations
|
||||||
|
|
||||||
|
- `hoist_props` (default: `true`) -- hoist properties from constant object and
|
||||||
|
array literals into regular variables subject to a set of constraints. For example:
|
||||||
|
`var o={p:1, q:2}; f(o.p, o.q);` is converted to `f(1, 2);`. Note: `hoist_props`
|
||||||
|
works best with `mangle` enabled, the `compress` option `passes` set to `2` or higher,
|
||||||
|
and the `compress` option `toplevel` enabled.
|
||||||
|
|
||||||
|
- `hoist_vars` (default: `false`) -- hoist `var` declarations (this is `false`
|
||||||
by default because it seems to increase the size of the output in general)
|
by default because it seems to increase the size of the output in general)
|
||||||
|
|
||||||
- `if_return` -- optimizations for if/return and if/continue
|
- `if_return` (default: `true`) -- optimizations for if/return and if/continue
|
||||||
|
|
||||||
- `inline` -- embed simple functions
|
- `inline` (default: `true`) -- embed simple functions
|
||||||
|
|
||||||
- `join_vars` -- join consecutive `var` statements
|
- `join_vars` (default: `true`) -- join consecutive `var` statements
|
||||||
|
|
||||||
- `cascade` -- small optimization for sequences, transform `x, x` into `x`
|
- `keep_classnames` (default: `false`) -- Pass `true` to prevent the
|
||||||
and `x = something(), x` into `x = something()`
|
compressor from discarding class names. See also: the `keep_classnames`
|
||||||
|
[mangle option](#mangle).
|
||||||
|
|
||||||
- `collapse_vars` -- Collapse single-use non-constant variables - side
|
- `keep_fargs` (default: `true`) -- Prevents the compressor from discarding unused
|
||||||
effects permitting.
|
function arguments. You need this for code which relies on `Function.length`.
|
||||||
|
|
||||||
- `reduce_vars` -- Improve optimization on variables assigned with and
|
- `keep_fnames` (default: `false`) -- Pass `true` to prevent the
|
||||||
used as constant values.
|
compressor from discarding function names. Useful for code relying on
|
||||||
|
`Function.prototype.name`. See also: the `keep_fnames` [mangle option](#mangle).
|
||||||
|
|
||||||
- `warnings` -- display warnings when dropping unreachable code or unused
|
- `keep_infinity` (default: `false`) -- Pass `true` to prevent `Infinity` from
|
||||||
declarations etc.
|
being compressed into `1/0`, which may cause performance issues on Chrome.
|
||||||
|
|
||||||
- `negate_iife` -- negate "Immediately-Called Function Expressions"
|
- `loops` (default: `true`) -- optimizations for `do`, `while` and `for` loops
|
||||||
|
when we can statically determine the condition.
|
||||||
|
|
||||||
|
- `negate_iife` (default: `true`) -- negate "Immediately-Called Function Expressions"
|
||||||
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.
|
||||||
|
|
||||||
- `pure_getters` -- the default is `false`. If you pass `true` for
|
- `passes` (default: `1`) -- The maximum number of times to run compress.
|
||||||
this, UglifyJS will assume that object property access
|
In some cases more than one pass leads to further compressed code. Keep in
|
||||||
(e.g. `foo.bar` or `foo["bar"]`) doesn't have any side effects.
|
mind more passes will take more time.
|
||||||
Specify `"strict"` to treat `foo.bar` as side-effect-free only when
|
|
||||||
`foo` is certain to not throw, i.e. not `null` or `undefined`.
|
|
||||||
|
|
||||||
- `pure_funcs` -- default `null`. You can pass an array of names and
|
- `properties` (default: `true`) -- rewrite property access using the dot notation, for
|
||||||
|
example `foo["bar"] → foo.bar`
|
||||||
|
|
||||||
|
- `pure_funcs` (default: `null`) -- You can pass an array of names and
|
||||||
UglifyJS will assume that those functions do not produce side
|
UglifyJS will assume that those functions do not produce side
|
||||||
effects. DANGER: will not check if the name is redefined in scope.
|
effects. DANGER: will not check if the name is redefined in scope.
|
||||||
An example case here, for instance `var q = Math.floor(a/b)`. If
|
An example case here, for instance `var q = Math.floor(a/b)`. If
|
||||||
@@ -710,55 +711,108 @@ If you're using the `X-SourceMap` header instead, you can just omit `sourceMap.u
|
|||||||
statement would get discarded. The current implementation adds some
|
statement would get discarded. The current implementation adds some
|
||||||
overhead (compression will be slower).
|
overhead (compression will be slower).
|
||||||
|
|
||||||
- `drop_console` -- default `false`. Pass `true` to discard calls to
|
- `pure_getters` (default: `"strict"`) -- If you pass `true` for
|
||||||
`console.*` functions. If you wish to drop a specific function call
|
this, UglifyJS will assume that object property access
|
||||||
such as `console.info` and/or retain side effects from function arguments
|
(e.g. `foo.bar` or `foo["bar"]`) doesn't have any side effects.
|
||||||
after dropping the function call then use `pure_funcs` instead.
|
Specify `"strict"` to treat `foo.bar` as side-effect-free only when
|
||||||
|
`foo` is certain to not throw, i.e. not `null` or `undefined`.
|
||||||
|
|
||||||
- `expression` -- default `false`. Pass `true` to preserve completion values
|
- `reduce_funcs` (default: `true`) -- Allows single-use functions to be
|
||||||
from terminal statements without `return`, e.g. in bookmarklets.
|
inlined as function expressions when permissible allowing further
|
||||||
|
optimization. Enabled by default. Option depends on `reduce_vars`
|
||||||
|
being enabled. Some code runs faster in the Chrome V8 engine if this
|
||||||
|
option is disabled. Does not negatively impact other major browsers.
|
||||||
|
|
||||||
- `keep_fargs` -- default `true`. Prevents the
|
- `reduce_vars` (default: `true`) -- Improve optimization on variables assigned with and
|
||||||
compressor from discarding unused function arguments. You need this
|
used as constant values.
|
||||||
for code which relies on `Function.length`.
|
|
||||||
|
|
||||||
- `keep_fnames` -- default `false`. Pass `true` to prevent the
|
- `sequences` (default: `true`) -- join consecutive simple statements using the
|
||||||
compressor from discarding function names. Useful for code relying on
|
comma operator. May be set to a positive integer to specify the maximum number
|
||||||
`Function.prototype.name`. See also: the `keep_fnames` [mangle option](#mangle).
|
of consecutive comma sequences that will be generated. If this option is set to
|
||||||
|
`true` then the default `sequences` limit is `200`. Set option to `false` or `0`
|
||||||
|
to disable. The smallest `sequences` length is `2`. A `sequences` value of `1`
|
||||||
|
is grandfathered to be equivalent to `true` and as such means `200`. On rare
|
||||||
|
occasions the default sequences limit leads to very slow compress times in which
|
||||||
|
case a value of `20` or less is recommended.
|
||||||
|
|
||||||
- `passes` -- default `1`. Number of times to run compress with a maximum of 3.
|
- `side_effects` (default: `true`) -- Pass `false` to disable potentially dropping
|
||||||
In some cases more than one pass leads to further compressed code. Keep in
|
|
||||||
mind more passes will take more time.
|
|
||||||
|
|
||||||
- `keep_infinity` -- default `false`. Pass `true` to prevent `Infinity` from
|
|
||||||
being compressed into `1/0`, which may cause performance issues on Chrome.
|
|
||||||
|
|
||||||
- `side_effects` -- default `true`. Pass `false` to disable potentially dropping
|
|
||||||
functions marked as "pure". A function call is marked as "pure" if a comment
|
functions marked as "pure". A function call is marked as "pure" if a comment
|
||||||
annotation `/*@__PURE__*/` or `/*#__PURE__*/` immediately precedes the call. For
|
annotation `/*@__PURE__*/` or `/*#__PURE__*/` immediately precedes the call. For
|
||||||
example: `/*@__PURE__*/foo();`
|
example: `/*@__PURE__*/foo();`
|
||||||
|
|
||||||
- `ecma` -- default `5`. Pass `6` or greater to enable `compress` options that
|
- `switches` (default: `true`) -- de-duplicate and remove unreachable `switch` branches
|
||||||
will transform ES5 code into smaller ES6+ equivalent forms.
|
|
||||||
|
- `toplevel` (default: `false`) -- drop unreferenced functions (`"funcs"`) and/or
|
||||||
|
variables (`"vars"`) in the top level scope (`false` by default, `true` to drop
|
||||||
|
both unreferenced functions and variables)
|
||||||
|
|
||||||
|
- `top_retain` (default: `null`) -- prevent specific toplevel functions and
|
||||||
|
variables from `unused` removal (can be array, comma-separated, RegExp or
|
||||||
|
function. Implies `toplevel`)
|
||||||
|
|
||||||
|
- `typeofs` (default: `true`) -- Transforms `typeof foo == "undefined"` into
|
||||||
|
`foo === void 0`. Note: recommend to set this value to `false` for IE10 and
|
||||||
|
earlier versions due to known issues.
|
||||||
|
|
||||||
|
- `unsafe` (default: `false`) -- apply "unsafe" transformations (discussion below)
|
||||||
|
|
||||||
|
- `unsafe_arrows` (default: `false`) -- Convert ES5 style anonymous function
|
||||||
|
expressions to arrow functions if the function body does not reference `this`.
|
||||||
|
Note: it is not always safe to perform this conversion if code relies on the
|
||||||
|
the function having a `prototype`, which arrow functions lack.
|
||||||
|
This transform requires that the `ecma` compress option is set to `6` or greater.
|
||||||
|
|
||||||
|
- `unsafe_comps` (default: `false`) -- Reverse `<` and `<=` to `>` and `>=` to
|
||||||
|
allow improved compression. This might be unsafe when an at least one of two
|
||||||
|
operands is an object with computed values due the use of methods like `get`,
|
||||||
|
or `valueOf`. This could cause change in execution order after operands in the
|
||||||
|
comparison are switching. Compression only works if both `comparisons` and
|
||||||
|
`unsafe_comps` are both set to true.
|
||||||
|
|
||||||
|
- `unsafe_Func` (default: `false`) -- compress and mangle `Function(args, code)`
|
||||||
|
when both `args` and `code` are string literals.
|
||||||
|
|
||||||
|
- `unsafe_math` (default: `false`) -- optimize numerical expressions like
|
||||||
|
`2 * x * 3` into `6 * x`, which may give imprecise floating point results.
|
||||||
|
|
||||||
|
- `unsafe_methods` (default: false) -- Converts `{ m: function(){} }` to
|
||||||
|
`{ m(){} }`. `ecma` must be set to `6` or greater to enable this transform.
|
||||||
|
If `unsafe_methods` is a RegExp then key/value pairs with keys matching the
|
||||||
|
RegExp will be converted to concise methods.
|
||||||
|
Note: if enabled there is a risk of getting a "`<method name>` is not a
|
||||||
|
constructor" TypeError should any code try to `new` the former function.
|
||||||
|
|
||||||
|
- `unsafe_proto` (default: `false`) -- optimize expressions like
|
||||||
|
`Array.prototype.slice.call(a)` into `[].slice.call(a)`
|
||||||
|
|
||||||
|
- `unsafe_regexp` (default: `false`) -- enable substitutions of variables with
|
||||||
|
`RegExp` values the same way as if they are constants.
|
||||||
|
|
||||||
|
- `unused` (default: `true`) -- drop unreferenced functions and variables (simple
|
||||||
|
direct variable assignments do not count as references unless set to `"keep_assign"`)
|
||||||
|
|
||||||
|
- `warnings` (default: `false`) -- display warnings when dropping unreachable
|
||||||
|
code or unused declarations etc.
|
||||||
|
|
||||||
## Mangle options
|
## Mangle options
|
||||||
|
|
||||||
- `reserved` (default `[]`). Pass an array of identifiers that should be
|
- `eval` (default `false`) -- Pass `true` to mangle names visible in scopes
|
||||||
excluded from mangling. Example: `["foo", "bar"]`.
|
where `eval` or `with` are used.
|
||||||
|
|
||||||
- `toplevel` (default `false`). Pass `true` to mangle names declared in the
|
- `keep_classnames` (default `false`) -- Pass `true` to not mangle class names.
|
||||||
top level scope.
|
See also: the `keep_classnames` [compress option](#compress-options).
|
||||||
|
|
||||||
- `keep_classnames` (default `false`). Pass `true` to not mangle class names.
|
- `keep_fnames` (default `false`) -- Pass `true` to not mangle function names.
|
||||||
|
|
||||||
- `keep_fnames` (default `false`). Pass `true` to not mangle function names.
|
|
||||||
Useful for code relying on `Function.prototype.name`. See also: the `keep_fnames`
|
Useful for code relying on `Function.prototype.name`. See also: the `keep_fnames`
|
||||||
[compress option](#compress-options).
|
[compress option](#compress-options).
|
||||||
|
|
||||||
- `eval` (default `false`). Pass `true` to mangle names visible in scopes
|
- `reserved` (default `[]`) -- Pass an array of identifiers that should be
|
||||||
where `eval` or `with` are used.
|
excluded from mangling. Example: `["foo", "bar"]`.
|
||||||
|
|
||||||
- `safari10` (default `false`). Pass `true` to work around the Safari 10 loop
|
- `toplevel` (default `false`) -- Pass `true` to mangle names declared in the
|
||||||
|
top level scope.
|
||||||
|
|
||||||
|
- `safari10` (default `false`) -- Pass `true` to work around the Safari 10 loop
|
||||||
iterator [bug](https://bugs.webkit.org/show_bug.cgi?id=171041)
|
iterator [bug](https://bugs.webkit.org/show_bug.cgi?id=171041)
|
||||||
"Cannot declare a let variable twice".
|
"Cannot declare a let variable twice".
|
||||||
|
|
||||||
@@ -786,16 +840,20 @@ UglifyJS.minify(code, { mangle: { toplevel: true } }).code;
|
|||||||
|
|
||||||
### Mangle properties options
|
### Mangle properties options
|
||||||
|
|
||||||
- `reserved` (default: `[]`) -- Do not mangle property names listed in the
|
|
||||||
`reserved` array.
|
|
||||||
- `regex` (default: `null`) -— Pass a RegExp literal to only mangle property
|
|
||||||
names matching the regular expression.
|
|
||||||
- `keep_quoted` (default: `false`) -— Only mangle unquoted property names.
|
|
||||||
- `debug` (default: `false`) -— Mangle names with the original name still present.
|
|
||||||
Pass an empty string `""` to enable, or a non-empty string to set the debug suffix.
|
|
||||||
- `builtins` (default: `false`) -- Use `true` to allow the mangling of builtin
|
- `builtins` (default: `false`) -- Use `true` to allow the mangling of builtin
|
||||||
DOM properties. Not recommended to override this setting.
|
DOM properties. Not recommended to override this setting.
|
||||||
|
|
||||||
|
- `debug` (default: `false`) -— Mangle names with the original name still present.
|
||||||
|
Pass an empty string `""` to enable, or a non-empty string to set the debug suffix.
|
||||||
|
|
||||||
|
- `keep_quoted` (default: `false`) -— Only mangle unquoted property names.
|
||||||
|
|
||||||
|
- `regex` (default: `null`) -— Pass a RegExp literal to only mangle property
|
||||||
|
names matching the regular expression.
|
||||||
|
|
||||||
|
- `reserved` (default: `[]`) -- Do not mangle property names listed in the
|
||||||
|
`reserved` array.
|
||||||
|
|
||||||
## Output options
|
## Output options
|
||||||
|
|
||||||
The code generator tries to output shortest code possible by default. In
|
The code generator tries to output shortest code possible by default. In
|
||||||
@@ -804,37 +862,50 @@ can pass additional arguments that control the code output:
|
|||||||
|
|
||||||
- `ascii_only` (default `false`) -- escape Unicode characters in strings and
|
- `ascii_only` (default `false`) -- escape Unicode characters in strings and
|
||||||
regexps (affects directives with non-ascii characters becoming invalid)
|
regexps (affects directives with non-ascii characters becoming invalid)
|
||||||
|
|
||||||
- `beautify` (default `true`) -- whether to actually beautify the output.
|
- `beautify` (default `true`) -- whether to actually beautify the output.
|
||||||
Passing `-b` will set this to true, but you might need to pass `-b` even
|
Passing `-b` will set this to true, but you might need to pass `-b` even
|
||||||
when you want to generate minified code, in order to specify additional
|
when you want to generate minified code, in order to specify additional
|
||||||
arguments, so you can use `-b beautify=false` to override it.
|
arguments, so you can use `-b beautify=false` to override it.
|
||||||
|
|
||||||
- `bracketize` (default `false`) -- always insert brackets in `if`, `for`,
|
- `bracketize` (default `false`) -- always insert brackets in `if`, `for`,
|
||||||
`do`, `while` or `with` statements, even if their body is a single
|
`do`, `while` or `with` statements, even if their body is a single
|
||||||
statement.
|
statement.
|
||||||
|
|
||||||
- `comments` (default `false`) -- pass `true` or `"all"` to preserve all
|
- `comments` (default `false`) -- pass `true` or `"all"` to preserve all
|
||||||
comments, `"some"` to preserve some comments, a regular expression string
|
comments, `"some"` to preserve some comments, a regular expression string
|
||||||
(e.g. `/^!/`) or a function.
|
(e.g. `/^!/`) or a function.
|
||||||
|
|
||||||
- `ecma` (default `5`) -- set output printing mode. Set `ecma` to `6` or
|
- `ecma` (default `5`) -- set output printing mode. Set `ecma` to `6` or
|
||||||
greater to emit shorthand object properties - i.e.: `{a}` instead of `{a: a}`.
|
greater to emit shorthand object properties - i.e.: `{a}` instead of `{a: a}`.
|
||||||
The `ecma` option will only change the output in direct control of the
|
The `ecma` option will only change the output in direct control of the
|
||||||
beautifier. Non-compatible features in the abstract syntax tree will still
|
beautifier. Non-compatible features in the abstract syntax tree will still
|
||||||
be output as is. For example: an `ecma` setting of `5` will **not** convert
|
be output as is. For example: an `ecma` setting of `5` will **not** convert
|
||||||
ES6+ code to ES5.
|
ES6+ code to ES5.
|
||||||
- `indent_level` (default 4)
|
|
||||||
- `indent_start` (default 0) -- prefix all lines by that many spaces
|
- `indent_level` (default `4`)
|
||||||
|
|
||||||
|
- `indent_start` (default `0`) -- prefix all lines by that many spaces
|
||||||
|
|
||||||
- `inline_script` (default `false`) -- escape the slash in occurrences of
|
- `inline_script` (default `false`) -- escape the slash in occurrences of
|
||||||
`</script` in strings
|
`</script` in strings
|
||||||
|
|
||||||
- `keep_quoted_props` (default `false`) -- when turned on, prevents stripping
|
- `keep_quoted_props` (default `false`) -- when turned on, prevents stripping
|
||||||
quotes from property names in object literals.
|
quotes from property names in object literals.
|
||||||
|
|
||||||
- `max_line_len` (default `false`) -- maximum line length (for uglified code)
|
- `max_line_len` (default `false`) -- maximum line length (for uglified code)
|
||||||
|
|
||||||
- `preamble` (default `null`) -- when passed it must be a string and
|
- `preamble` (default `null`) -- when passed it must be a string and
|
||||||
it will be prepended to the output literally. The source map will
|
it will be prepended to the output literally. The source map will
|
||||||
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 preserve lines, but it
|
||||||
only works if `beautify` is set to `false`.
|
only works if `beautify` is set to `false`.
|
||||||
|
|
||||||
- `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
|
||||||
|
|
||||||
- `quote_style` (default `0`) -- preferred quote style for strings (affects
|
- `quote_style` (default `0`) -- preferred quote style for strings (affects
|
||||||
quoted property names and directives as well):
|
quoted property names and directives as well):
|
||||||
- `0` -- prefers double quotes, switches to single quotes when there are
|
- `0` -- prefers double quotes, switches to single quotes when there are
|
||||||
@@ -842,16 +913,23 @@ can pass additional arguments that control the code output:
|
|||||||
- `1` -- always use single quotes
|
- `1` -- always use single quotes
|
||||||
- `2` -- always use double quotes
|
- `2` -- always use double quotes
|
||||||
- `3` -- always use the original quotes
|
- `3` -- always use the original quotes
|
||||||
|
|
||||||
- `semicolons` (default `true`) -- separate statements with semicolons. If
|
- `semicolons` (default `true`) -- separate statements with semicolons. If
|
||||||
you pass `false` then whenever possible we will use a newline instead of a
|
you pass `false` then whenever possible we will use a newline instead of a
|
||||||
semicolon, leading to more readable output of uglified code (size before
|
semicolon, leading to more readable output of uglified code (size before
|
||||||
gzip could be smaller; size after gzip insignificantly larger).
|
gzip could be smaller; size after gzip insignificantly larger).
|
||||||
|
|
||||||
- `shebang` (default `true`) -- preserve shebang `#!` in preamble (bash scripts)
|
- `shebang` (default `true`) -- preserve shebang `#!` in preamble (bash scripts)
|
||||||
- `width` (default 80) -- only takes effect when beautification is on, this
|
|
||||||
|
- `webkit` (default `false`) -- enable workarounds for WebKit bugs.
|
||||||
|
PhantomJS users should set this option to `true`.
|
||||||
|
|
||||||
|
- `width` (default `80`) -- only takes effect when beautification is on, this
|
||||||
specifies an (orientative) line width that the beautifier will try to
|
specifies an (orientative) line width that the beautifier will try to
|
||||||
obey. It refers to the width of the line text (excluding indentation).
|
obey. It refers to the width of the line text (excluding indentation).
|
||||||
It doesn't work very well currently, but it does make the code generated
|
It doesn't work very well currently, but it does make the code generated
|
||||||
by UglifyJS more readable.
|
by UglifyJS more readable.
|
||||||
|
|
||||||
- `wrap_iife` (default `false`) -- pass `true` to wrap immediately invoked
|
- `wrap_iife` (default `false`) -- pass `true` to wrap immediately invoked
|
||||||
function expressions. See
|
function expressions. See
|
||||||
[#640](https://github.com/mishoo/UglifyJS2/issues/640) for more details.
|
[#640](https://github.com/mishoo/UglifyJS2/issues/640) for more details.
|
||||||
@@ -897,7 +975,6 @@ when this flag is on:
|
|||||||
- `new Object()` → `{}`
|
- `new Object()` → `{}`
|
||||||
- `String(exp)` or `exp.toString()` → `"" + exp`
|
- `String(exp)` or `exp.toString()` → `"" + exp`
|
||||||
- `new Object/RegExp/Function/Error/Array (...)` → we discard the `new`
|
- `new Object/RegExp/Function/Error/Array (...)` → we discard the `new`
|
||||||
- `typeof foo == "undefined"` → `foo === void 0`
|
|
||||||
- `void 0` → `undefined` (if there is a variable named "undefined" in
|
- `void 0` → `undefined` (if there is a variable named "undefined" in
|
||||||
scope; we do it because the variable name will be mangled, typically
|
scope; we do it because the variable name will be mangled, typically
|
||||||
reduced to a single character)
|
reduced to a single character)
|
||||||
@@ -1050,3 +1127,30 @@ in total it's a bit more than just using UglifyJS's own parser.
|
|||||||
|
|
||||||
[acorn]: https://github.com/ternjs/acorn
|
[acorn]: https://github.com/ternjs/acorn
|
||||||
[sm-spec]: https://docs.google.com/document/d/1U1RGAehQwRypUTovF1KRlpiOFze0b-_2gc6fAH0KY0k
|
[sm-spec]: https://docs.google.com/document/d/1U1RGAehQwRypUTovF1KRlpiOFze0b-_2gc6fAH0KY0k
|
||||||
|
|
||||||
|
### Uglify Fast Minify Mode
|
||||||
|
|
||||||
|
It's not well known, but whitespace removal and symbol mangling accounts
|
||||||
|
for 95% of the size reduction in minified code for most JavaScript - not
|
||||||
|
elaborate code transforms. One can simply disable `compress` to speed up
|
||||||
|
Uglify builds by 3 to 4 times. In this fast `mangle`-only mode Uglify has
|
||||||
|
comparable minify speeds and gzip sizes to
|
||||||
|
[`butternut`](https://www.npmjs.com/package/butternut):
|
||||||
|
|
||||||
|
| d3.js | minify size | gzip size | minify time (seconds) |
|
||||||
|
| --- | ---: | ---: | ---: |
|
||||||
|
| original | 451,131 | 108,733 | - |
|
||||||
|
| uglify-js@3.0.24 mangle=false, compress=false | 316,600 | 85,245 | 0.70 |
|
||||||
|
| uglify-js@3.0.24 mangle=true, compress=false | 220,216 | 72,730 | 1.13 |
|
||||||
|
| butternut@0.4.6 | 217,568 | 72,738 | 1.41 |
|
||||||
|
| uglify-js@3.0.24 mangle=true, compress=true | 212,511 | 71,560 | 3.36 |
|
||||||
|
| babili@0.1.4 | 210,713 | 72,140 | 12.64 |
|
||||||
|
|
||||||
|
To enable fast minify mode from the CLI use:
|
||||||
|
```
|
||||||
|
uglifyjs file.js -m
|
||||||
|
```
|
||||||
|
To enable fast minify mode with the API use:
|
||||||
|
```js
|
||||||
|
UglifyJS.minify(code, { compress: false, mangle: true });
|
||||||
|
```
|
||||||
|
|||||||
33
bin/uglifyjs
33
bin/uglifyjs
@@ -15,7 +15,7 @@ var path = require("path");
|
|||||||
var program = require("commander");
|
var program = require("commander");
|
||||||
var UglifyJS = require("../tools/node");
|
var UglifyJS = require("../tools/node");
|
||||||
|
|
||||||
var skip_keys = [ "cname", "enclosed", "parent_scope", "scope", "thedef", "uses_eval", "uses_with" ];
|
var skip_keys = [ "cname", "enclosed", "inlined", "parent_scope", "scope", "thedef", "uses_eval", "uses_with" ];
|
||||||
var files = {};
|
var files = {};
|
||||||
var options = {
|
var options = {
|
||||||
compress: false,
|
compress: false,
|
||||||
@@ -35,19 +35,21 @@ else if (process.argv.indexOf("options") >= 0) program.helpInformation = functio
|
|||||||
}
|
}
|
||||||
return text.join("\n");
|
return text.join("\n");
|
||||||
};
|
};
|
||||||
program.option("-p, --parse <options>", "Specify parser options.", parse_js("parse", true));
|
program.option("-p, --parse <options>", "Specify parser options.", parse_js());
|
||||||
program.option("-c, --compress [options]", "Enable compressor/specify compressor options.", parse_js("compress", true));
|
program.option("-c, --compress [options]", "Enable compressor/specify compressor options.", parse_js());
|
||||||
program.option("-m, --mangle [options]", "Mangle names/specify mangler options.", parse_js("mangle", true));
|
program.option("-m, --mangle [options]", "Mangle names/specify mangler options.", parse_js());
|
||||||
program.option("--mangle-props [options]", "Mangle properties/specify mangler options.", parse_js("mangle-props", true));
|
program.option("--mangle-props [options]", "Mangle properties/specify mangler options.", parse_js());
|
||||||
program.option("-b, --beautify [options]", "Beautify output/specify output options.", parse_js("beautify", true));
|
program.option("-b, --beautify [options]", "Beautify output/specify output options.", 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.");
|
||||||
program.option("-d, --define <expr>[=value]", "Global definitions.", parse_js("define"));
|
program.option("-d, --define <expr>[=value]", "Global definitions.", parse_js("define"));
|
||||||
program.option("--ecma <version>", "Specifiy ECMAScript release: 5, 6, 7 or 8.");
|
program.option("--ecma <version>", "Specify ECMAScript release: 5, 6, 7 or 8.");
|
||||||
program.option("--ie8", "Support non-standard Internet Explorer 8.");
|
program.option("--ie8", "Support non-standard Internet Explorer 8.");
|
||||||
|
program.option("--keep-classnames", "Do not mangle/drop class names.");
|
||||||
program.option("--keep-fnames", "Do not mangle/drop function names. Useful for code relying on Function.prototype.name.");
|
program.option("--keep-fnames", "Do not mangle/drop function names. Useful for code relying on Function.prototype.name.");
|
||||||
program.option("--name-cache <file>", "File to hold mangled name mappings.");
|
program.option("--name-cache <file>", "File to hold mangled name mappings.");
|
||||||
|
program.option("--no-rename", "Disable symbol expansion.");
|
||||||
program.option("--self", "Build UglifyJS as a library (implies --wrap UglifyJS)");
|
program.option("--self", "Build UglifyJS as a library (implies --wrap UglifyJS)");
|
||||||
program.option("--source-map [options]", "Enable source map/specify source map options.", parse_source_map());
|
program.option("--source-map [options]", "Enable source map/specify source map options.", parse_source_map());
|
||||||
program.option("--timings", "Display operations run time on STDERR.")
|
program.option("--timings", "Display operations run time on STDERR.")
|
||||||
@@ -66,11 +68,13 @@ if (!program.output && program.sourceMap && program.sourceMap.url != "inline") {
|
|||||||
"compress",
|
"compress",
|
||||||
"ie8",
|
"ie8",
|
||||||
"mangle",
|
"mangle",
|
||||||
|
"rename",
|
||||||
"sourceMap",
|
"sourceMap",
|
||||||
"toplevel",
|
"toplevel",
|
||||||
"wrap"
|
"wrap"
|
||||||
].forEach(function(name) {
|
].forEach(function(name) {
|
||||||
if (name in program) {
|
if (name in program) {
|
||||||
|
if (name == "rename" && program[name]) return;
|
||||||
options[name] = program[name];
|
options[name] = program[name];
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -95,6 +99,9 @@ if (program.define) {
|
|||||||
options.compress.global_defs[expr] = program.define[expr];
|
options.compress.global_defs[expr] = program.define[expr];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (program.keepClassnames) {
|
||||||
|
options.keep_classnames = true;
|
||||||
|
}
|
||||||
if (program.keepFnames) {
|
if (program.keepFnames) {
|
||||||
options.keep_fnames = true;
|
options.keep_fnames = true;
|
||||||
}
|
}
|
||||||
@@ -315,7 +322,7 @@ function read_file(path, default_value) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function parse_js(flag, constants) {
|
function parse_js(flag) {
|
||||||
return function(value, options) {
|
return function(value, options) {
|
||||||
options = options || {};
|
options = options || {};
|
||||||
try {
|
try {
|
||||||
@@ -333,7 +340,7 @@ function parse_js(flag, constants) {
|
|||||||
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;
|
||||||
if (!constants) {
|
if (flag) {
|
||||||
options[name] = value;
|
options[name] = value;
|
||||||
} else if (value instanceof UglifyJS.AST_Array) {
|
} else if (value instanceof UglifyJS.AST_Array) {
|
||||||
options[name] = value.elements.map(to_string);
|
options[name] = value.elements.map(to_string);
|
||||||
@@ -356,14 +363,18 @@ function parse_js(flag, constants) {
|
|||||||
}
|
}
|
||||||
}));
|
}));
|
||||||
} catch(ex) {
|
} catch(ex) {
|
||||||
options[value] = null;
|
if (flag) {
|
||||||
|
fatal("Error parsing arguments for '" + flag + "': " + value);
|
||||||
|
} else {
|
||||||
|
options[value] = null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return options;
|
return options;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function parse_source_map() {
|
function parse_source_map() {
|
||||||
var parse = parse_js("sourceMap", true);
|
var parse = parse_js();
|
||||||
return function(value, options) {
|
return function(value, options) {
|
||||||
var hasContent = options && "content" in options;
|
var hasContent = options && "content" in options;
|
||||||
var settings = parse(value, options);
|
var settings = parse(value, options);
|
||||||
|
|||||||
28
lib/ast.js
28
lib/ast.js
@@ -134,11 +134,10 @@ var AST_Debugger = DEFNODE("Debugger", null, {
|
|||||||
$documentation: "Represents a debugger statement",
|
$documentation: "Represents a debugger statement",
|
||||||
}, AST_Statement);
|
}, AST_Statement);
|
||||||
|
|
||||||
var AST_Directive = DEFNODE("Directive", "value scope quote", {
|
var AST_Directive = DEFNODE("Directive", "value quote", {
|
||||||
$documentation: "Represents a directive, like \"use strict\";",
|
$documentation: "Represents a directive, like \"use strict\";",
|
||||||
$propdoc: {
|
$propdoc: {
|
||||||
value: "[string] The value of this directive as a plain string (it's not an AST_String!)",
|
value: "[string] The value of this directive as a plain string (it's not an AST_String!)",
|
||||||
scope: "[AST_Scope/S] The scope that this directive affects",
|
|
||||||
quote: "[string] the original quote character"
|
quote: "[string] the original quote character"
|
||||||
},
|
},
|
||||||
}, AST_Statement);
|
}, AST_Statement);
|
||||||
@@ -303,10 +302,9 @@ var AST_With = DEFNODE("With", "expression", {
|
|||||||
|
|
||||||
/* -----[ scope and functions ]----- */
|
/* -----[ scope and functions ]----- */
|
||||||
|
|
||||||
var AST_Scope = DEFNODE("Scope", "directives variables functions uses_with uses_eval parent_scope enclosed cname", {
|
var AST_Scope = DEFNODE("Scope", "variables functions uses_with uses_eval parent_scope enclosed cname", {
|
||||||
$documentation: "Base class for all statements introducing a lexical scope",
|
$documentation: "Base class for all statements introducing a lexical scope",
|
||||||
$propdoc: {
|
$propdoc: {
|
||||||
directives: "[string*/S] an array of directives declared in this scope",
|
|
||||||
variables: "[Object/S] a map of name -> SymbolDef for all variables/functions defined in this scope",
|
variables: "[Object/S] a map of name -> SymbolDef for all variables/functions defined in this scope",
|
||||||
functions: "[Object/S] like `variables`, but only lists function declarations",
|
functions: "[Object/S] like `variables`, but only lists function declarations",
|
||||||
uses_with: "[boolean/S] tells whether this scope uses the `with` statement",
|
uses_with: "[boolean/S] tells whether this scope uses the `with` statement",
|
||||||
@@ -391,15 +389,15 @@ var AST_Accessor = DEFNODE("Accessor", null, {
|
|||||||
$documentation: "A setter/getter function. The `name` property is always null."
|
$documentation: "A setter/getter function. The `name` property is always null."
|
||||||
}, AST_Lambda);
|
}, AST_Lambda);
|
||||||
|
|
||||||
var AST_Function = DEFNODE("Function", null, {
|
var AST_Function = DEFNODE("Function", "inlined", {
|
||||||
$documentation: "A function expression"
|
$documentation: "A function expression"
|
||||||
}, AST_Lambda);
|
}, AST_Lambda);
|
||||||
|
|
||||||
var AST_Arrow = DEFNODE("Arrow", null, {
|
var AST_Arrow = DEFNODE("Arrow", "inlined", {
|
||||||
$documentation: "An ES6 Arrow function ((a) => b)"
|
$documentation: "An ES6 Arrow function ((a) => b)"
|
||||||
}, AST_Lambda);
|
}, AST_Lambda);
|
||||||
|
|
||||||
var AST_Defun = DEFNODE("Defun", null, {
|
var AST_Defun = DEFNODE("Defun", "inlined", {
|
||||||
$documentation: "A function definition"
|
$documentation: "A function definition"
|
||||||
}, AST_Lambda);
|
}, AST_Lambda);
|
||||||
|
|
||||||
@@ -450,10 +448,8 @@ var AST_TemplateString = DEFNODE("TemplateString", "segments", {
|
|||||||
},
|
},
|
||||||
_walk: function(visitor) {
|
_walk: function(visitor) {
|
||||||
return visitor._visit(this, function(){
|
return visitor._visit(this, function(){
|
||||||
this.segments.forEach(function(seg, i){
|
this.segments.forEach(function(seg){
|
||||||
if (i % 2 !== 0) {
|
seg._walk(visitor);
|
||||||
seg._walk(visitor);
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -697,7 +693,7 @@ var AST_Export = DEFNODE("Export", "exported_definition exported_value is_defaul
|
|||||||
var AST_VarDef = DEFNODE("VarDef", "name value", {
|
var AST_VarDef = DEFNODE("VarDef", "name value", {
|
||||||
$documentation: "A variable declaration; only appears in a AST_Definitions node",
|
$documentation: "A variable declaration; only appears in a AST_Definitions node",
|
||||||
$propdoc: {
|
$propdoc: {
|
||||||
name: "[AST_SymbolVar|AST_SymbolConst|AST_Destructuring] name of the variable",
|
name: "[AST_Destructuring|AST_SymbolConst|AST_SymbolLet|AST_SymbolVar] name of the variable",
|
||||||
value: "[AST_Node?] initializer, or null of there's no initializer"
|
value: "[AST_Node?] initializer, or null of there's no initializer"
|
||||||
},
|
},
|
||||||
_walk: function(visitor) {
|
_walk: function(visitor) {
|
||||||
@@ -1044,7 +1040,7 @@ var AST_This = DEFNODE("This", null, {
|
|||||||
|
|
||||||
var AST_Super = DEFNODE("Super", null, {
|
var AST_Super = DEFNODE("Super", null, {
|
||||||
$documentation: "The `super` symbol",
|
$documentation: "The `super` symbol",
|
||||||
}, AST_Symbol);
|
}, AST_This);
|
||||||
|
|
||||||
var AST_Constant = DEFNODE("Constant", null, {
|
var AST_Constant = DEFNODE("Constant", null, {
|
||||||
$documentation: "Base class for all constants",
|
$documentation: "Base class for all constants",
|
||||||
@@ -1160,7 +1156,7 @@ TreeWalker.prototype = {
|
|||||||
if (!ret && descend) {
|
if (!ret && descend) {
|
||||||
descend.call(node);
|
descend.call(node);
|
||||||
}
|
}
|
||||||
this.pop(node);
|
this.pop();
|
||||||
return ret;
|
return ret;
|
||||||
},
|
},
|
||||||
parent: function(n) {
|
parent: function(n) {
|
||||||
@@ -1179,8 +1175,8 @@ TreeWalker.prototype = {
|
|||||||
}
|
}
|
||||||
this.stack.push(node);
|
this.stack.push(node);
|
||||||
},
|
},
|
||||||
pop: function(node) {
|
pop: function() {
|
||||||
this.stack.pop();
|
var node = this.stack.pop();
|
||||||
if (node instanceof AST_Lambda || node instanceof AST_Class) {
|
if (node instanceof AST_Lambda || node instanceof AST_Class) {
|
||||||
this.directives = Object.getPrototypeOf(this.directives);
|
this.directives = Object.getPrototypeOf(this.directives);
|
||||||
}
|
}
|
||||||
|
|||||||
2082
lib/compress.js
2082
lib/compress.js
File diff suppressed because it is too large
Load Diff
@@ -51,11 +51,13 @@ function minify(files, options) {
|
|||||||
compress: {},
|
compress: {},
|
||||||
ecma: undefined,
|
ecma: undefined,
|
||||||
ie8: false,
|
ie8: false,
|
||||||
|
keep_classnames: undefined,
|
||||||
keep_fnames: false,
|
keep_fnames: false,
|
||||||
mangle: {},
|
mangle: {},
|
||||||
nameCache: null,
|
nameCache: null,
|
||||||
output: {},
|
output: {},
|
||||||
parse: {},
|
parse: {},
|
||||||
|
rename: undefined,
|
||||||
sourceMap: false,
|
sourceMap: false,
|
||||||
timings: false,
|
timings: false,
|
||||||
toplevel: false,
|
toplevel: false,
|
||||||
@@ -65,11 +67,19 @@ function minify(files, options) {
|
|||||||
var timings = options.timings && {
|
var timings = options.timings && {
|
||||||
start: Date.now()
|
start: Date.now()
|
||||||
};
|
};
|
||||||
|
if (options.keep_classnames === undefined) {
|
||||||
|
options.keep_classnames = options.keep_fnames;
|
||||||
|
}
|
||||||
|
if (options.rename === undefined) {
|
||||||
|
options.rename = options.compress && options.mangle;
|
||||||
|
}
|
||||||
set_shorthand("ecma", options, [ "parse", "compress", "output" ]);
|
set_shorthand("ecma", options, [ "parse", "compress", "output" ]);
|
||||||
set_shorthand("ie8", options, [ "compress", "mangle", "output" ]);
|
set_shorthand("ie8", options, [ "compress", "mangle", "output" ]);
|
||||||
|
set_shorthand("keep_classnames", options, [ "compress", "mangle" ]);
|
||||||
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" ]);
|
set_shorthand("warnings", options, [ "compress" ]);
|
||||||
|
var quoted_props;
|
||||||
if (options.mangle) {
|
if (options.mangle) {
|
||||||
options.mangle = defaults(options.mangle, {
|
options.mangle = defaults(options.mangle, {
|
||||||
cache: options.nameCache && (options.nameCache.vars || {}),
|
cache: options.nameCache && (options.nameCache.vars || {}),
|
||||||
@@ -82,11 +92,16 @@ function minify(files, options) {
|
|||||||
safari10: false,
|
safari10: false,
|
||||||
toplevel: false,
|
toplevel: false,
|
||||||
}, true);
|
}, true);
|
||||||
if (options.nameCache && options.mangle.properties) {
|
if (options.mangle.properties) {
|
||||||
if (typeof options.mangle.properties != "object") {
|
if (typeof options.mangle.properties != "object") {
|
||||||
options.mangle.properties = {};
|
options.mangle.properties = {};
|
||||||
}
|
}
|
||||||
if (!("cache" in options.mangle.properties)) {
|
if (options.mangle.properties.keep_quoted) {
|
||||||
|
quoted_props = options.mangle.properties.reserved;
|
||||||
|
if (!Array.isArray(quoted_props)) quoted_props = [];
|
||||||
|
options.mangle.properties.reserved = quoted_props;
|
||||||
|
}
|
||||||
|
if (options.nameCache && !("cache" in options.mangle.properties)) {
|
||||||
options.mangle.properties.cache = options.nameCache.props || {};
|
options.mangle.properties.cache = options.nameCache.props || {};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -129,14 +144,20 @@ function minify(files, options) {
|
|||||||
}
|
}
|
||||||
toplevel = options.parse.toplevel;
|
toplevel = options.parse.toplevel;
|
||||||
}
|
}
|
||||||
|
if (quoted_props) {
|
||||||
|
reserve_quoted_keys(toplevel, quoted_props);
|
||||||
|
}
|
||||||
if (options.wrap) {
|
if (options.wrap) {
|
||||||
toplevel = toplevel.wrap_commonjs(options.wrap);
|
toplevel = toplevel.wrap_commonjs(options.wrap);
|
||||||
}
|
}
|
||||||
if (timings) timings.scope1 = Date.now();
|
if (timings) timings.rename = Date.now();
|
||||||
if (options.compress) toplevel.figure_out_scope(options.mangle);
|
if (options.rename) {
|
||||||
|
toplevel.figure_out_scope(options.mangle);
|
||||||
|
toplevel.expand_names(options.mangle);
|
||||||
|
}
|
||||||
if (timings) timings.compress = Date.now();
|
if (timings) timings.compress = Date.now();
|
||||||
if (options.compress) toplevel = new Compressor(options.compress).compress(toplevel);
|
if (options.compress) toplevel = new Compressor(options.compress).compress(toplevel);
|
||||||
if (timings) timings.scope2 = Date.now();
|
if (timings) timings.scope = Date.now();
|
||||||
if (options.mangle) toplevel.figure_out_scope(options.mangle);
|
if (options.mangle) toplevel.figure_out_scope(options.mangle);
|
||||||
if (timings) timings.mangle = Date.now();
|
if (timings) timings.mangle = Date.now();
|
||||||
if (options.mangle) {
|
if (options.mangle) {
|
||||||
@@ -194,9 +215,10 @@ function minify(files, options) {
|
|||||||
if (timings) {
|
if (timings) {
|
||||||
timings.end = Date.now();
|
timings.end = Date.now();
|
||||||
result.timings = {
|
result.timings = {
|
||||||
parse: 1e-3 * (timings.scope1 - timings.parse),
|
parse: 1e-3 * (timings.rename - timings.parse),
|
||||||
scope: 1e-3 * (timings.compress - timings.scope1 + timings.mangle - timings.scope2),
|
rename: 1e-3 * (timings.compress - timings.rename),
|
||||||
compress: 1e-3 * (timings.scope2 - timings.compress),
|
compress: 1e-3 * (timings.scope - timings.compress),
|
||||||
|
scope: 1e-3 * (timings.mangle - timings.scope),
|
||||||
mangle: 1e-3 * (timings.properties - timings.mangle),
|
mangle: 1e-3 * (timings.properties - timings.mangle),
|
||||||
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),
|
||||||
|
|||||||
137
lib/output.js
137
lib/output.js
@@ -54,7 +54,6 @@ function OutputStream(options) {
|
|||||||
|
|
||||||
options = defaults(options, {
|
options = defaults(options, {
|
||||||
ascii_only : false,
|
ascii_only : false,
|
||||||
ascii_identifiers: undefined,
|
|
||||||
beautify : false,
|
beautify : false,
|
||||||
bracketize : false,
|
bracketize : false,
|
||||||
comments : false,
|
comments : false,
|
||||||
@@ -78,9 +77,6 @@ function OutputStream(options) {
|
|||||||
wrap_iife : false,
|
wrap_iife : false,
|
||||||
}, true);
|
}, true);
|
||||||
|
|
||||||
if (typeof options.ascii_identifiers === 'undefined')
|
|
||||||
options.ascii_identifiers = options.ascii_only;
|
|
||||||
|
|
||||||
if (options.shorthand === undefined)
|
if (options.shorthand === undefined)
|
||||||
options.shorthand = options.ecma > 5;
|
options.shorthand = options.ecma > 5;
|
||||||
|
|
||||||
@@ -118,20 +114,16 @@ function OutputStream(options) {
|
|||||||
var current_pos = 0;
|
var current_pos = 0;
|
||||||
var OUTPUT = "";
|
var OUTPUT = "";
|
||||||
|
|
||||||
function to_ascii(str, identifier) {
|
var to_utf8 = options.ascii_only ? function(str, identifier) {
|
||||||
return str.replace(/[\ud800-\udbff][\udc00-\udfff]|[\u0000-\u001f\u007f-\uffff]/g, function(ch) {
|
if (options.ecma >= 6) {
|
||||||
var code = get_full_char_code(ch, 0).toString(16);
|
str = str.replace(/[\ud800-\udbff][\udc00-\udfff]/g, function(ch) {
|
||||||
|
var code = get_full_char_code(ch, 0).toString(16);
|
||||||
if ((identifier && code.length === 1 && options.ecma >= 6) || code.length > 4) {
|
|
||||||
if (options.ecma < 6) {
|
|
||||||
if (identifier) {
|
|
||||||
return ch; // no \u{} support
|
|
||||||
}
|
|
||||||
return "\\u" + ch.charCodeAt(0).toString(16) + "\\u"
|
|
||||||
+ ch.charCodeAt(1).toString(16);
|
|
||||||
}
|
|
||||||
return "\\u{" + code + "}";
|
return "\\u{" + code + "}";
|
||||||
} else if (code.length <= 2 && !identifier) {
|
});
|
||||||
|
}
|
||||||
|
return str.replace(/[\u0000-\u001f\u007f-\uffff]/g, function(ch) {
|
||||||
|
var code = ch.charCodeAt(0).toString(16);
|
||||||
|
if (code.length <= 2 && !identifier) {
|
||||||
while (code.length < 2) code = "0" + code;
|
while (code.length < 2) code = "0" + code;
|
||||||
return "\\x" + code;
|
return "\\x" + code;
|
||||||
} else {
|
} else {
|
||||||
@@ -139,6 +131,12 @@ function OutputStream(options) {
|
|||||||
return "\\u" + code;
|
return "\\u" + code;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
} : function(str) {
|
||||||
|
return str.replace(/[\ud800-\udbff](?![\udc00-\udfff])/g, function(ch) {
|
||||||
|
return "\\u" + ch.charCodeAt(0).toString(16);
|
||||||
|
}).replace(/(^|[^\ud800-\udbff])([\udc00-\udfff])/g, function(match, prefix, ch) {
|
||||||
|
return prefix + "\\u" + ch.charCodeAt(0).toString(16);
|
||||||
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
function make_string(str, quote) {
|
function make_string(str, quote) {
|
||||||
@@ -159,7 +157,7 @@ function OutputStream(options) {
|
|||||||
case "\u2029": return "\\u2029";
|
case "\u2029": return "\\u2029";
|
||||||
case "\ufeff": return "\\ufeff";
|
case "\ufeff": return "\\ufeff";
|
||||||
case "\0":
|
case "\0":
|
||||||
return /[0-7]/.test(get_full_char(str, i+1)) ? "\\x00" : "\\0";
|
return /[0-9]/.test(get_full_char(str, i+1)) ? "\\x00" : "\\0";
|
||||||
}
|
}
|
||||||
return s;
|
return s;
|
||||||
});
|
});
|
||||||
@@ -172,7 +170,7 @@ function OutputStream(options) {
|
|||||||
function quote_template() {
|
function quote_template() {
|
||||||
return '`' + str.replace(/`/g, '\\`') + '`';
|
return '`' + str.replace(/`/g, '\\`') + '`';
|
||||||
}
|
}
|
||||||
if (options.ascii_only) str = to_ascii(str);
|
str = to_utf8(str);
|
||||||
if (quote === "`") return quote_template();
|
if (quote === "`") return quote_template();
|
||||||
switch (options.quote_style) {
|
switch (options.quote_style) {
|
||||||
case 1:
|
case 1:
|
||||||
@@ -198,8 +196,7 @@ function OutputStream(options) {
|
|||||||
|
|
||||||
function make_name(name) {
|
function make_name(name) {
|
||||||
name = name.toString();
|
name = name.toString();
|
||||||
if (options.ascii_identifiers)
|
name = to_utf8(name, true);
|
||||||
name = to_ascii(name, true);
|
|
||||||
return name;
|
return name;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -265,7 +262,7 @@ function OutputStream(options) {
|
|||||||
}
|
}
|
||||||
} : noop;
|
} : noop;
|
||||||
|
|
||||||
var requireSemicolonChars = makePredicate("( [ + * / - , .");
|
var requireSemicolonChars = makePredicate("( [ + * / - , . `");
|
||||||
|
|
||||||
function print(str) {
|
function print(str) {
|
||||||
str = String(str);
|
str = String(str);
|
||||||
@@ -461,7 +458,7 @@ function OutputStream(options) {
|
|||||||
last : function() { return last },
|
last : function() { return last },
|
||||||
semicolon : semicolon,
|
semicolon : semicolon,
|
||||||
force_semicolon : force_semicolon,
|
force_semicolon : force_semicolon,
|
||||||
to_ascii : to_ascii,
|
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, escape_directive) {
|
||||||
var encoded = encode_string(str, quote);
|
var encoded = encode_string(str, quote);
|
||||||
@@ -509,13 +506,17 @@ function OutputStream(options) {
|
|||||||
nodetype.DEFMETHOD("_codegen", generator);
|
nodetype.DEFMETHOD("_codegen", generator);
|
||||||
};
|
};
|
||||||
|
|
||||||
var use_asm = false;
|
|
||||||
var in_directive = false;
|
var in_directive = 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, prev_use_asm = use_asm;
|
var self = this, generator = self._codegen;
|
||||||
if (self instanceof AST_Directive && self.value == "use asm" && stream.parent() instanceof AST_Scope) {
|
if (self instanceof AST_Scope) {
|
||||||
use_asm = true;
|
active_scope = self;
|
||||||
|
}
|
||||||
|
else if (!use_asm && self instanceof AST_Directive && self.value == "use asm") {
|
||||||
|
use_asm = active_scope;
|
||||||
}
|
}
|
||||||
function doit() {
|
function doit() {
|
||||||
self.add_comments(stream);
|
self.add_comments(stream);
|
||||||
@@ -529,8 +530,8 @@ function OutputStream(options) {
|
|||||||
doit();
|
doit();
|
||||||
}
|
}
|
||||||
stream.pop_node();
|
stream.pop_node();
|
||||||
if (self instanceof AST_Scope) {
|
if (self === use_asm) {
|
||||||
use_asm = prev_use_asm;
|
use_asm = null;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
AST_Node.DEFMETHOD("_print", AST_Node.prototype.print);
|
AST_Node.DEFMETHOD("_print", AST_Node.prototype.print);
|
||||||
@@ -692,6 +693,7 @@ function OutputStream(options) {
|
|||||||
* ==> 20 (side effect, set a := 10 and b := 20) */
|
* ==> 20 (side effect, set a := 10 and b := 20) */
|
||||||
|| p instanceof AST_Arrow // x => (x, x)
|
|| p instanceof AST_Arrow // x => (x, x)
|
||||||
|| p instanceof AST_DefaultAssign // x => (x = (0, function(){}))
|
|| p instanceof AST_DefaultAssign // x => (x = (0, function(){}))
|
||||||
|
|| p instanceof AST_Expansion // [...(a, b)]
|
||||||
;
|
;
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -745,14 +747,15 @@ function OutputStream(options) {
|
|||||||
// parens around it too, otherwise the call will be
|
// parens around it too, otherwise the call will be
|
||||||
// interpreted as passing the arguments to the upper New
|
// interpreted as passing the arguments to the upper New
|
||||||
// expression.
|
// expression.
|
||||||
try {
|
var parens = false;
|
||||||
this.walk(new TreeWalker(function(node){
|
this.walk(new TreeWalker(function(node) {
|
||||||
if (node instanceof AST_Call) throw p;
|
if (parens || node instanceof AST_Scope) return true;
|
||||||
}));
|
if (node instanceof AST_Call) {
|
||||||
} catch(ex) {
|
parens = true;
|
||||||
if (ex !== p) throw ex;
|
return true;
|
||||||
return true;
|
}
|
||||||
}
|
}));
|
||||||
|
return parens;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -1358,6 +1361,7 @@ function OutputStream(options) {
|
|||||||
self.exported_value.print(output);
|
self.exported_value.print(output);
|
||||||
} else if (self.exported_definition) {
|
} else if (self.exported_definition) {
|
||||||
self.exported_definition.print(output);
|
self.exported_definition.print(output);
|
||||||
|
if (self.exported_definition instanceof AST_Definitions) return;
|
||||||
}
|
}
|
||||||
if (self.module_name) {
|
if (self.module_name) {
|
||||||
output.space();
|
output.space();
|
||||||
@@ -1369,19 +1373,17 @@ function OutputStream(options) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
function parenthesize_for_noin(node, output, noin) {
|
function parenthesize_for_noin(node, output, noin) {
|
||||||
if (!noin) node.print(output);
|
var parens = false;
|
||||||
else try {
|
// need to take some precautions here:
|
||||||
// need to take some precautions here:
|
// https://github.com/mishoo/UglifyJS2/issues/60
|
||||||
// https://github.com/mishoo/UglifyJS2/issues/60
|
if (noin) node.walk(new TreeWalker(function(node) {
|
||||||
node.walk(new TreeWalker(function(node){
|
if (parens || node instanceof AST_Scope) return true;
|
||||||
if (node instanceof AST_Binary && node.operator == "in")
|
if (node instanceof AST_Binary && node.operator == "in") {
|
||||||
throw output;
|
parens = true;
|
||||||
}));
|
return true;
|
||||||
node.print(output);
|
}
|
||||||
} catch(ex) {
|
}));
|
||||||
if (ex !== output) throw ex;
|
node.print(output, parens);
|
||||||
node.print(output, true);
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
DEFPRINT(AST_VarDef, function(self, output){
|
DEFPRINT(AST_VarDef, function(self, output){
|
||||||
@@ -1401,6 +1403,9 @@ function OutputStream(options) {
|
|||||||
self.expression.print(output);
|
self.expression.print(output);
|
||||||
if (self instanceof AST_New && !need_constructor_parens(self, output))
|
if (self instanceof AST_New && !need_constructor_parens(self, output))
|
||||||
return;
|
return;
|
||||||
|
if (self.expression instanceof AST_Call || self.expression instanceof AST_Lambda) {
|
||||||
|
output.add_mapping(self.start);
|
||||||
|
}
|
||||||
output.with_parens(function(){
|
output.with_parens(function(){
|
||||||
self.args.forEach(function(expr, i){
|
self.args.forEach(function(expr, i){
|
||||||
if (i) output.comma();
|
if (i) output.comma();
|
||||||
@@ -1440,15 +1445,23 @@ function OutputStream(options) {
|
|||||||
DEFPRINT(AST_Dot, function(self, output){
|
DEFPRINT(AST_Dot, function(self, output){
|
||||||
var expr = self.expression;
|
var expr = self.expression;
|
||||||
expr.print(output);
|
expr.print(output);
|
||||||
if (expr instanceof AST_Number && expr.getValue() >= 0) {
|
var prop = self.property;
|
||||||
if (!/[xa-f.)]/i.test(output.last())) {
|
if (output.option("ie8") && RESERVED_WORDS(prop)) {
|
||||||
output.print(".");
|
output.print("[");
|
||||||
|
output.add_mapping(self.end);
|
||||||
|
output.print_string(prop);
|
||||||
|
output.print("]");
|
||||||
|
} else {
|
||||||
|
if (expr instanceof AST_Number && expr.getValue() >= 0) {
|
||||||
|
if (!/[xa-f.)]/i.test(output.last())) {
|
||||||
|
output.print(".");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
output.print(".");
|
||||||
|
// the name after dot would be mapped about here.
|
||||||
|
output.add_mapping(self.end);
|
||||||
|
output.print_name(prop);
|
||||||
}
|
}
|
||||||
output.print(".");
|
|
||||||
// the name after dot would be mapped about here.
|
|
||||||
output.add_mapping(self.end);
|
|
||||||
output.print_name(self.property);
|
|
||||||
});
|
});
|
||||||
DEFPRINT(AST_Sub, function(self, output){
|
DEFPRINT(AST_Sub, function(self, output){
|
||||||
self.expression.print(output);
|
self.expression.print(output);
|
||||||
@@ -1611,7 +1624,8 @@ function OutputStream(options) {
|
|||||||
if (allowShortHand &&
|
if (allowShortHand &&
|
||||||
self.value instanceof AST_Symbol &&
|
self.value instanceof AST_Symbol &&
|
||||||
is_identifier_string(self.key) &&
|
is_identifier_string(self.key) &&
|
||||||
get_name(self.value) === self.key
|
get_name(self.value) === self.key &&
|
||||||
|
is_identifier(self.key)
|
||||||
) {
|
) {
|
||||||
print_property_name(self.key, self.quote, output);
|
print_property_name(self.key, self.quote, output);
|
||||||
|
|
||||||
@@ -1673,9 +1687,6 @@ function OutputStream(options) {
|
|||||||
DEFPRINT(AST_Symbol, function (self, output) {
|
DEFPRINT(AST_Symbol, function (self, output) {
|
||||||
self._do_print(output);
|
self._do_print(output);
|
||||||
});
|
});
|
||||||
DEFPRINT(AST_SymbolDeclaration, function(self, output){
|
|
||||||
self._do_print(output);
|
|
||||||
});
|
|
||||||
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");
|
||||||
@@ -1703,9 +1714,7 @@ function OutputStream(options) {
|
|||||||
if (regexp.raw_source) {
|
if (regexp.raw_source) {
|
||||||
str = "/" + regexp.raw_source + str.slice(str.lastIndexOf("/"));
|
str = "/" + regexp.raw_source + str.slice(str.lastIndexOf("/"));
|
||||||
}
|
}
|
||||||
if (output.option("ascii_only")) {
|
str = output.to_utf8(str);
|
||||||
str = output.to_ascii(str);
|
|
||||||
}
|
|
||||||
output.print(str);
|
output.print(str);
|
||||||
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)
|
||||||
|
|||||||
91
lib/parse.js
91
lib/parse.js
@@ -44,9 +44,9 @@
|
|||||||
|
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
var KEYWORDS = 'break case catch class const continue debugger default delete do else export extends finally for function if in instanceof new return switch throw try typeof var let void while with import';
|
var KEYWORDS = 'break case catch class const continue debugger default delete do else export extends finally for function if in instanceof let new return switch throw try typeof var void while with';
|
||||||
var KEYWORDS_ATOM = 'false null true';
|
var KEYWORDS_ATOM = 'false null true';
|
||||||
var RESERVED_WORDS = 'enum implements interface package private protected public static super this ' + KEYWORDS_ATOM + " " + KEYWORDS;
|
var RESERVED_WORDS = 'enum implements import interface package private protected public static super this ' + KEYWORDS_ATOM + " " + KEYWORDS;
|
||||||
var KEYWORDS_BEFORE_EXPRESSION = 'return new delete throw else case yield await';
|
var KEYWORDS_BEFORE_EXPRESSION = 'return new delete throw else case yield await';
|
||||||
|
|
||||||
KEYWORDS = makePredicate(KEYWORDS);
|
KEYWORDS = makePredicate(KEYWORDS);
|
||||||
@@ -1013,6 +1013,12 @@ function parse($TEXT, options) {
|
|||||||
next();
|
next();
|
||||||
return function_(AST_Defun, false, true);
|
return function_(AST_Defun, false, true);
|
||||||
}
|
}
|
||||||
|
if (S.token.value == "import" && !is_token(peek(), "punc", "(")) {
|
||||||
|
next();
|
||||||
|
var node = import_();
|
||||||
|
semicolon();
|
||||||
|
return node;
|
||||||
|
}
|
||||||
return is_token(peek(), "punc", ":")
|
return is_token(peek(), "punc", ":")
|
||||||
? labeled_statement()
|
? labeled_statement()
|
||||||
: simple_statement();
|
: simple_statement();
|
||||||
@@ -1149,15 +1155,11 @@ function parse($TEXT, options) {
|
|||||||
body : statement()
|
body : statement()
|
||||||
});
|
});
|
||||||
|
|
||||||
case "import":
|
|
||||||
next();
|
|
||||||
var node = import_();
|
|
||||||
semicolon();
|
|
||||||
return node;
|
|
||||||
|
|
||||||
case "export":
|
case "export":
|
||||||
next();
|
if (!is_token(peek(), "punc", "(")) {
|
||||||
return export_();
|
next();
|
||||||
|
return export_();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
unexpected();
|
unexpected();
|
||||||
@@ -1320,6 +1322,9 @@ function parse($TEXT, options) {
|
|||||||
if (in_statement && !name)
|
if (in_statement && !name)
|
||||||
unexpected();
|
unexpected();
|
||||||
|
|
||||||
|
if (name && ctor !== AST_Accessor && !(name instanceof AST_SymbolDeclaration))
|
||||||
|
unexpected(prev());
|
||||||
|
|
||||||
var args = parameters();
|
var args = parameters();
|
||||||
var body = _function_body(true, is_generator || is_generator_property, is_async, name, args);
|
var body = _function_body(true, is_generator || is_generator_property, is_async, name, args);
|
||||||
return new ctor({
|
return new ctor({
|
||||||
@@ -1522,7 +1527,7 @@ function parse($TEXT, options) {
|
|||||||
}
|
}
|
||||||
if (is_expand) {
|
if (is_expand) {
|
||||||
if (!is("punc", "]")) {
|
if (!is("punc", "]")) {
|
||||||
unexpected(); // Must be last element
|
croak("Rest element must be last element");
|
||||||
}
|
}
|
||||||
elements[elements.length - 1] = new AST_Expansion({
|
elements[elements.length - 1] = new AST_Expansion({
|
||||||
start: expand_token,
|
start: expand_token,
|
||||||
@@ -1547,18 +1552,33 @@ function parse($TEXT, options) {
|
|||||||
} else {
|
} else {
|
||||||
expect(",");
|
expect(",");
|
||||||
}
|
}
|
||||||
|
if (is("expand", "...")) {
|
||||||
|
is_expand = true;
|
||||||
|
expand_token = S.token;
|
||||||
|
used_parameters.mark_spread(S.token);
|
||||||
|
next();
|
||||||
|
}
|
||||||
if (is("name") && (is_token(peek(), "punc") || is_token(peek(), "operator")) && [",", "}", "="].indexOf(peek().value) !== -1) {
|
if (is("name") && (is_token(peek(), "punc") || is_token(peek(), "operator")) && [",", "}", "="].indexOf(peek().value) !== -1) {
|
||||||
used_parameters.add_parameter(S.token);
|
used_parameters.add_parameter(S.token);
|
||||||
elements.push(new AST_ObjectKeyVal({
|
var value = new symbol_type({
|
||||||
start: prev(),
|
start: S.token,
|
||||||
key: S.token.value,
|
name: S.token.value,
|
||||||
value: new symbol_type({
|
end: S.token,
|
||||||
start: S.token,
|
});
|
||||||
name: S.token.value,
|
if (is_expand) {
|
||||||
end: S.token
|
elements.push(new AST_Expansion({
|
||||||
}),
|
start: expand_token,
|
||||||
end: prev()
|
expression: value,
|
||||||
}));
|
end: value.end,
|
||||||
|
}));
|
||||||
|
} else {
|
||||||
|
elements.push(new AST_ObjectKeyVal({
|
||||||
|
start: prev(),
|
||||||
|
key: S.token.value,
|
||||||
|
value: value,
|
||||||
|
end: value.end,
|
||||||
|
}));
|
||||||
|
}
|
||||||
next();
|
next();
|
||||||
} else if (is("punc", "}")) {
|
} else if (is("punc", "}")) {
|
||||||
continue; // Allow trailing hole
|
continue; // Allow trailing hole
|
||||||
@@ -1589,7 +1609,12 @@ function parse($TEXT, options) {
|
|||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (is("operator", "=")) {
|
if (is_expand) {
|
||||||
|
if (!is("punc", "}")) {
|
||||||
|
croak("Rest element must be last element");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (is("operator", "=")) {
|
||||||
used_parameters.mark_default_assignment(S.token);
|
used_parameters.mark_default_assignment(S.token);
|
||||||
next();
|
next();
|
||||||
elements[elements.length - 1].value = new AST_DefaultAssign({
|
elements[elements.length - 1].value = new AST_DefaultAssign({
|
||||||
@@ -1855,7 +1880,8 @@ function parse($TEXT, options) {
|
|||||||
: !no_in && kind === "const" && S.input.has_directive("use strict")
|
: !no_in && kind === "const" && S.input.has_directive("use strict")
|
||||||
? croak("Missing initializer in const declaration") : null,
|
? croak("Missing initializer in const declaration") : null,
|
||||||
end : prev()
|
end : prev()
|
||||||
})
|
});
|
||||||
|
if (def.name.name == "import") croak("Unexpected token: import");
|
||||||
}
|
}
|
||||||
a.push(def);
|
a.push(def);
|
||||||
if (!is("punc", ","))
|
if (!is("punc", ","))
|
||||||
@@ -1974,9 +2000,6 @@ function parse($TEXT, options) {
|
|||||||
names: ex.properties.map(to_fun_args)
|
names: ex.properties.map(to_fun_args)
|
||||||
}), default_seen_above);
|
}), default_seen_above);
|
||||||
} else if (ex instanceof AST_ObjectKeyVal) {
|
} else if (ex instanceof AST_ObjectKeyVal) {
|
||||||
if (ex.key instanceof AST_SymbolRef) {
|
|
||||||
ex.key = to_fun_args(ex.key, 0, [ex.key]);
|
|
||||||
}
|
|
||||||
ex.value = to_fun_args(ex.value, 0, [ex.key]);
|
ex.value = to_fun_args(ex.value, 0, [ex.key]);
|
||||||
return insert_default(ex, default_seen_above);
|
return insert_default(ex, default_seen_above);
|
||||||
} else if (ex instanceof AST_Hole) {
|
} else if (ex instanceof AST_Hole) {
|
||||||
@@ -2084,7 +2107,8 @@ function parse($TEXT, options) {
|
|||||||
}));
|
}));
|
||||||
while (S.token.end === false) {
|
while (S.token.end === false) {
|
||||||
next();
|
next();
|
||||||
segments.push(expression());
|
handle_regexp();
|
||||||
|
segments.push(expression(true));
|
||||||
|
|
||||||
if (!is_token("template_substitution")) {
|
if (!is_token("template_substitution")) {
|
||||||
unexpected();
|
unexpected();
|
||||||
@@ -2143,7 +2167,18 @@ function parse($TEXT, options) {
|
|||||||
if (!options.strict && is("punc", "}"))
|
if (!options.strict && is("punc", "}"))
|
||||||
// allow trailing comma
|
// allow trailing comma
|
||||||
break;
|
break;
|
||||||
|
|
||||||
start = S.token;
|
start = S.token;
|
||||||
|
if (start.type == "expand") {
|
||||||
|
next();
|
||||||
|
a.push(new AST_Expansion({
|
||||||
|
start: start,
|
||||||
|
expression: expression(false),
|
||||||
|
end: prev(),
|
||||||
|
}));
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
var name = as_property_name();
|
var name = as_property_name();
|
||||||
var value;
|
var value;
|
||||||
|
|
||||||
@@ -2531,7 +2566,7 @@ function parse($TEXT, options) {
|
|||||||
unexpected(tmp);
|
unexpected(tmp);
|
||||||
}
|
}
|
||||||
case "name":
|
case "name":
|
||||||
if (tmp.value == "yield" && !is_token(peek(), "punc", ":")
|
if (tmp.value == "yield" && !is_token(peek(), "punc", ":") && !is_token(peek(), "punc", "(")
|
||||||
&& S.input.has_directive("use strict") && !is_in_generator()) {
|
&& S.input.has_directive("use strict") && !is_in_generator()) {
|
||||||
token_error(tmp, "Unexpected yield identifier inside strict mode");
|
token_error(tmp, "Unexpected yield identifier inside strict mode");
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -85,6 +85,36 @@ function find_builtins(reserved) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function reserve_quoted_keys(ast, reserved) {
|
||||||
|
function add(name) {
|
||||||
|
push_uniq(reserved, name);
|
||||||
|
}
|
||||||
|
|
||||||
|
ast.walk(new TreeWalker(function(node) {
|
||||||
|
if (node instanceof AST_ObjectKeyVal && node.quote) {
|
||||||
|
add(node.key);
|
||||||
|
} else if (node instanceof AST_ObjectProperty && node.quote) {
|
||||||
|
add(node.key.name);
|
||||||
|
} else if (node instanceof AST_Sub) {
|
||||||
|
addStrings(node.property, add);
|
||||||
|
}
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
|
||||||
|
function addStrings(node, add) {
|
||||||
|
node.walk(new TreeWalker(function(node) {
|
||||||
|
if (node instanceof AST_Sequence) {
|
||||||
|
addStrings(node.expressions[node.expressions.length - 1], add);
|
||||||
|
} else if (node instanceof AST_String) {
|
||||||
|
add(node.value);
|
||||||
|
} else if (node instanceof AST_Conditional) {
|
||||||
|
addStrings(node.consequent, add);
|
||||||
|
addStrings(node.alternative, add);
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
|
||||||
function mangle_properties(ast, options) {
|
function mangle_properties(ast, options) {
|
||||||
options = defaults(options, {
|
options = defaults(options, {
|
||||||
builtins: false,
|
builtins: false,
|
||||||
@@ -94,7 +124,7 @@ function mangle_properties(ast, options) {
|
|||||||
only_cache: false,
|
only_cache: false,
|
||||||
regex: null,
|
regex: null,
|
||||||
reserved: null,
|
reserved: null,
|
||||||
});
|
}, true);
|
||||||
|
|
||||||
var reserved = options.reserved;
|
var reserved = options.reserved;
|
||||||
if (!Array.isArray(reserved)) reserved = [];
|
if (!Array.isArray(reserved)) reserved = [];
|
||||||
@@ -109,7 +139,6 @@ function mangle_properties(ast, options) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var regex = options.regex;
|
var regex = options.regex;
|
||||||
var keep_quoted = options.keep_quoted;
|
|
||||||
|
|
||||||
// note debug is either false (disabled), or a string of the debug suffix to use (enabled).
|
// note debug is either false (disabled), or a string of the debug suffix to use (enabled).
|
||||||
// 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'
|
||||||
@@ -122,12 +151,11 @@ function mangle_properties(ast, options) {
|
|||||||
|
|
||||||
var names_to_mangle = [];
|
var names_to_mangle = [];
|
||||||
var unmangleable = [];
|
var unmangleable = [];
|
||||||
var to_keep = {};
|
|
||||||
|
|
||||||
// step 1: find candidates to mangle
|
// step 1: find candidates to mangle
|
||||||
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, keep_quoted && node.quote);
|
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
|
||||||
@@ -137,18 +165,14 @@ function mangle_properties(ast, options) {
|
|||||||
add(node.property);
|
add(node.property);
|
||||||
}
|
}
|
||||||
else if (node instanceof AST_Sub) {
|
else if (node instanceof AST_Sub) {
|
||||||
addStrings(node.property, keep_quoted);
|
addStrings(node.property, add);
|
||||||
}
|
|
||||||
else if (node instanceof AST_ConciseMethod) {
|
|
||||||
add(node.name.name);
|
|
||||||
}
|
}
|
||||||
}));
|
}));
|
||||||
|
|
||||||
// step 2: transform the tree, renaming properties
|
// step 2: transform the tree, renaming properties
|
||||||
return ast.transform(new TreeTransformer(function(node){
|
return ast.transform(new TreeTransformer(function(node){
|
||||||
if (node instanceof AST_ObjectKeyVal) {
|
if (node instanceof AST_ObjectKeyVal) {
|
||||||
if (!(keep_quoted && node.quote))
|
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
|
||||||
@@ -157,27 +181,9 @@ function mangle_properties(ast, options) {
|
|||||||
else if (node instanceof AST_Dot) {
|
else if (node instanceof AST_Dot) {
|
||||||
node.property = mangle(node.property);
|
node.property = mangle(node.property);
|
||||||
}
|
}
|
||||||
else if (node instanceof AST_Sub) {
|
else if (!options.keep_quoted && node instanceof AST_Sub) {
|
||||||
if (!keep_quoted)
|
node.property = mangleStrings(node.property);
|
||||||
node.property = mangleStrings(node.property);
|
|
||||||
}
|
}
|
||||||
else if (node instanceof AST_ConciseMethod) {
|
|
||||||
if (should_mangle(node.name.name)) {
|
|
||||||
node.name.name = mangle(node.name.name);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// else if (node instanceof AST_String) {
|
|
||||||
// if (should_mangle(node.value)) {
|
|
||||||
// AST_Node.warn(
|
|
||||||
// "Found \"{prop}\" property candidate for mangling in an arbitrary string [{file}:{line},{col}]", {
|
|
||||||
// file : node.start.file,
|
|
||||||
// line : node.start.line,
|
|
||||||
// col : node.start.col,
|
|
||||||
// prop : node.value
|
|
||||||
// }
|
|
||||||
// );
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
}));
|
}));
|
||||||
|
|
||||||
// only function declarations after this line
|
// only function declarations after this line
|
||||||
@@ -193,19 +199,13 @@ function mangle_properties(ast, options) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function should_mangle(name) {
|
function should_mangle(name) {
|
||||||
if (keep_quoted && name in to_keep) return false;
|
|
||||||
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.props.has(name)
|
return cache.props.has(name)
|
||||||
|| names_to_mangle.indexOf(name) >= 0;
|
|| names_to_mangle.indexOf(name) >= 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
function add(name, keep) {
|
function add(name) {
|
||||||
if (keep) {
|
|
||||||
to_keep[name] = true;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (can_mangle(name))
|
if (can_mangle(name))
|
||||||
push_uniq(names_to_mangle, name);
|
push_uniq(names_to_mangle, name);
|
||||||
|
|
||||||
@@ -225,19 +225,16 @@ function mangle_properties(ast, options) {
|
|||||||
// 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_name_suffix + "_";
|
||||||
|
|
||||||
if (can_mangle(debug_mangled) && !(keep_quoted && debug_mangled in to_keep)) {
|
if (can_mangle(debug_mangled)) {
|
||||||
mangled = 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) {
|
||||||
// Note: `can_mangle()` does not check if the name collides with the `to_keep` set
|
|
||||||
// (filled with quoted properties when `keep_quoted` is set). Make sure we add this
|
|
||||||
// check so we don't collide with a quoted name.
|
|
||||||
do {
|
do {
|
||||||
mangled = base54(++cache.cname);
|
mangled = base54(++cache.cname);
|
||||||
} while (!can_mangle(mangled) || keep_quoted && mangled in to_keep);
|
} while (!can_mangle(mangled));
|
||||||
}
|
}
|
||||||
|
|
||||||
cache.props.set(name, mangled);
|
cache.props.set(name, mangled);
|
||||||
@@ -245,32 +242,6 @@ function mangle_properties(ast, options) {
|
|||||||
return mangled;
|
return mangled;
|
||||||
}
|
}
|
||||||
|
|
||||||
function addStrings(node, keep) {
|
|
||||||
var out = {};
|
|
||||||
try {
|
|
||||||
(function walk(node){
|
|
||||||
node.walk(new TreeWalker(function(node){
|
|
||||||
if (node instanceof AST_Sequence) {
|
|
||||||
walk(node.expressions[node.expressions.length - 1]);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
if (node instanceof AST_String) {
|
|
||||||
add(node.value, keep);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
if (node instanceof AST_Conditional) {
|
|
||||||
walk(node.consequent);
|
|
||||||
walk(node.alternative);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
throw out;
|
|
||||||
}));
|
|
||||||
})(node);
|
|
||||||
} catch(ex) {
|
|
||||||
if (ex !== out) throw ex;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function mangleStrings(node) {
|
function mangleStrings(node) {
|
||||||
return node.transform(new TreeTransformer(function(node){
|
return node.transform(new TreeTransformer(function(node){
|
||||||
if (node instanceof AST_Sequence) {
|
if (node instanceof AST_Sequence) {
|
||||||
|
|||||||
130
lib/scope.js
130
lib/scope.js
@@ -43,16 +43,17 @@
|
|||||||
|
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
function SymbolDef(scope, index, orig) {
|
function SymbolDef(scope, orig) {
|
||||||
this.name = orig.name;
|
this.name = orig.name;
|
||||||
this.orig = [ orig ];
|
this.orig = [ orig ];
|
||||||
|
this.eliminated = 0;
|
||||||
this.scope = scope;
|
this.scope = scope;
|
||||||
this.references = [];
|
this.references = [];
|
||||||
|
this.replaced = 0;
|
||||||
this.global = false;
|
this.global = false;
|
||||||
this.export = false;
|
this.export = false;
|
||||||
this.mangled_name = null;
|
this.mangled_name = null;
|
||||||
this.undeclared = false;
|
this.undeclared = false;
|
||||||
this.index = index;
|
|
||||||
this.id = SymbolDef.next_id++;
|
this.id = SymbolDef.next_id++;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -116,7 +117,7 @@ AST_Toplevel.DEFMETHOD("figure_out_scope", function(options){
|
|||||||
var tw = new TreeWalker(function(node, descend){
|
var tw = new TreeWalker(function(node, descend){
|
||||||
if (node.is_block_scope()) {
|
if (node.is_block_scope()) {
|
||||||
var save_scope = scope;
|
var save_scope = scope;
|
||||||
scope = new AST_Scope(node);
|
node.block_scope = scope = new AST_Scope(node);
|
||||||
scope.init_scope_vars(save_scope);
|
scope.init_scope_vars(save_scope);
|
||||||
if (!(node instanceof AST_Scope)) {
|
if (!(node instanceof AST_Scope)) {
|
||||||
scope.uses_with = save_scope.uses_with;
|
scope.uses_with = save_scope.uses_with;
|
||||||
@@ -203,6 +204,21 @@ AST_Toplevel.DEFMETHOD("figure_out_scope", function(options){
|
|||||||
|| node instanceof AST_SymbolLet
|
|| node instanceof AST_SymbolLet
|
||||||
|| node instanceof AST_SymbolConst) {
|
|| node instanceof AST_SymbolConst) {
|
||||||
var def = ((node instanceof AST_SymbolBlockDeclaration) ? scope : defun).def_variable(node);
|
var def = ((node instanceof AST_SymbolBlockDeclaration) ? scope : defun).def_variable(node);
|
||||||
|
if (!all(def.orig, function(sym) {
|
||||||
|
if (sym === node) return true;
|
||||||
|
if (node instanceof AST_SymbolBlockDeclaration) {
|
||||||
|
return sym instanceof AST_SymbolLambda;
|
||||||
|
}
|
||||||
|
return !(sym instanceof AST_SymbolLet || sym instanceof AST_SymbolConst);
|
||||||
|
})) {
|
||||||
|
js_error(
|
||||||
|
node.name + " redeclared",
|
||||||
|
node.start.file,
|
||||||
|
node.start.line,
|
||||||
|
node.start.col,
|
||||||
|
node.start.pos
|
||||||
|
);
|
||||||
|
}
|
||||||
if (!(node instanceof AST_SymbolFunarg)) mark_export(def, 2);
|
if (!(node instanceof AST_SymbolFunarg)) mark_export(def, 2);
|
||||||
def.destructuring = in_destructuring;
|
def.destructuring = in_destructuring;
|
||||||
if (defun !== scope) {
|
if (defun !== scope) {
|
||||||
@@ -300,6 +316,7 @@ AST_Toplevel.DEFMETHOD("figure_out_scope", function(options){
|
|||||||
ref.reference(options);
|
ref.reference(options);
|
||||||
});
|
});
|
||||||
node.thedef = def;
|
node.thedef = def;
|
||||||
|
node.reference(options);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}));
|
}));
|
||||||
@@ -328,7 +345,7 @@ AST_Toplevel.DEFMETHOD("def_global", function(node){
|
|||||||
if (globals.has(name)) {
|
if (globals.has(name)) {
|
||||||
return globals.get(name);
|
return globals.get(name);
|
||||||
} else {
|
} else {
|
||||||
var g = new SymbolDef(this, globals.size(), node);
|
var g = new SymbolDef(this, node);
|
||||||
g.undeclared = true;
|
g.undeclared = true;
|
||||||
g.global = true;
|
g.global = true;
|
||||||
globals.set(name, g);
|
globals.set(name, g);
|
||||||
@@ -357,7 +374,7 @@ AST_IterationStatement.DEFMETHOD("is_block_scope", return_true);
|
|||||||
AST_Lambda.DEFMETHOD("init_scope_vars", function(){
|
AST_Lambda.DEFMETHOD("init_scope_vars", function(){
|
||||||
AST_Scope.prototype.init_scope_vars.apply(this, arguments);
|
AST_Scope.prototype.init_scope_vars.apply(this, arguments);
|
||||||
this.uses_arguments = false;
|
this.uses_arguments = false;
|
||||||
this.def_variable(new AST_SymbolConst({
|
this.def_variable(new AST_SymbolFunarg({
|
||||||
name: "arguments",
|
name: "arguments",
|
||||||
start: this.start,
|
start: this.start,
|
||||||
end: this.end
|
end: this.end
|
||||||
@@ -399,7 +416,7 @@ AST_Scope.DEFMETHOD("def_function", function(symbol){
|
|||||||
AST_Scope.DEFMETHOD("def_variable", function(symbol){
|
AST_Scope.DEFMETHOD("def_variable", function(symbol){
|
||||||
var def;
|
var def;
|
||||||
if (!this.variables.has(symbol.name)) {
|
if (!this.variables.has(symbol.name)) {
|
||||||
def = new SymbolDef(this, this.variables.size(), symbol);
|
def = new SymbolDef(this, symbol);
|
||||||
this.variables.set(symbol.name, def);
|
this.variables.set(symbol.name, def);
|
||||||
def.global = !this.parent_scope;
|
def.global = !this.parent_scope;
|
||||||
} else {
|
} else {
|
||||||
@@ -417,7 +434,7 @@ AST_Scope.DEFMETHOD("next_mangled", function(options){
|
|||||||
|
|
||||||
// https://github.com/mishoo/UglifyJS2/issues/242 -- do not
|
// https://github.com/mishoo/UglifyJS2/issues/242 -- do not
|
||||||
// shadow a name reserved from mangling.
|
// shadow a name reserved from mangling.
|
||||||
if (options.reserved.indexOf(m) >= 0) continue;
|
if (member(m, options.reserved)) continue;
|
||||||
|
|
||||||
// we must ensure that the mangled name does not shadow a name
|
// we must ensure that the mangled name does not shadow a name
|
||||||
// from some parent scope that is referenced in this or in
|
// from some parent scope that is referenced in this or in
|
||||||
@@ -461,14 +478,6 @@ AST_Symbol.DEFMETHOD("unreferenced", function(){
|
|||||||
&& !(this.scope.uses_eval || this.scope.uses_with);
|
&& !(this.scope.uses_eval || this.scope.uses_with);
|
||||||
});
|
});
|
||||||
|
|
||||||
AST_Symbol.DEFMETHOD("undeclared", function(){
|
|
||||||
return this.definition().undeclared;
|
|
||||||
});
|
|
||||||
|
|
||||||
AST_LabelRef.DEFMETHOD("undeclared", return_false);
|
|
||||||
|
|
||||||
AST_Label.DEFMETHOD("undeclared", return_false);
|
|
||||||
|
|
||||||
AST_Symbol.DEFMETHOD("definition", function(){
|
AST_Symbol.DEFMETHOD("definition", function(){
|
||||||
return this.thedef;
|
return this.thedef;
|
||||||
});
|
});
|
||||||
@@ -477,7 +486,7 @@ AST_Symbol.DEFMETHOD("global", function(){
|
|||||||
return this.definition().global;
|
return this.definition().global;
|
||||||
});
|
});
|
||||||
|
|
||||||
AST_Toplevel.DEFMETHOD("_default_mangler_options", function(options){
|
AST_Toplevel.DEFMETHOD("_default_mangler_options", function(options) {
|
||||||
options = defaults(options, {
|
options = defaults(options, {
|
||||||
eval : false,
|
eval : false,
|
||||||
ie8 : false,
|
ie8 : false,
|
||||||
@@ -487,15 +496,14 @@ AST_Toplevel.DEFMETHOD("_default_mangler_options", function(options){
|
|||||||
toplevel : false,
|
toplevel : false,
|
||||||
});
|
});
|
||||||
if (!Array.isArray(options.reserved)) options.reserved = [];
|
if (!Array.isArray(options.reserved)) options.reserved = [];
|
||||||
|
// Never mangle arguments
|
||||||
|
push_uniq(options.reserved, "arguments");
|
||||||
return options;
|
return options;
|
||||||
});
|
});
|
||||||
|
|
||||||
AST_Toplevel.DEFMETHOD("mangle_names", function(options){
|
AST_Toplevel.DEFMETHOD("mangle_names", function(options){
|
||||||
options = this._default_mangler_options(options);
|
options = this._default_mangler_options(options);
|
||||||
|
|
||||||
// Never mangle arguments
|
|
||||||
options.reserved.push('arguments');
|
|
||||||
|
|
||||||
// We only need to mangle declaration nodes. Special logic wired
|
// We only need to mangle declaration nodes. Special logic wired
|
||||||
// into the code generator will display the mangled name if it's
|
// into the code generator will display the mangled name if it's
|
||||||
// present (and for AST_SymbolRef-s it'll use the mangled name of
|
// present (and for AST_SymbolRef-s it'll use the mangled name of
|
||||||
@@ -504,11 +512,7 @@ AST_Toplevel.DEFMETHOD("mangle_names", function(options){
|
|||||||
var to_mangle = [];
|
var to_mangle = [];
|
||||||
|
|
||||||
if (options.cache) {
|
if (options.cache) {
|
||||||
this.globals.each(function(symbol){
|
this.globals.each(collect);
|
||||||
if (options.reserved.indexOf(symbol.name) < 0) {
|
|
||||||
to_mangle.push(symbol);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var tw = new TreeWalker(function(node, descend){
|
var tw = new TreeWalker(function(node, descend){
|
||||||
@@ -520,13 +524,7 @@ AST_Toplevel.DEFMETHOD("mangle_names", function(options){
|
|||||||
return true; // don't descend again in TreeWalker
|
return true; // don't descend again in TreeWalker
|
||||||
}
|
}
|
||||||
if (node instanceof AST_Scope) {
|
if (node instanceof AST_Scope) {
|
||||||
var p = tw.parent(), a = [];
|
node.variables.each(collect);
|
||||||
node.variables.each(function(symbol){
|
|
||||||
if (options.reserved.indexOf(symbol.name) < 0) {
|
|
||||||
a.push(symbol);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
to_mangle.push.apply(to_mangle, a);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (node instanceof AST_Label) {
|
if (node instanceof AST_Label) {
|
||||||
@@ -538,7 +536,7 @@ AST_Toplevel.DEFMETHOD("mangle_names", function(options){
|
|||||||
var mangle_with_block_scope =
|
var mangle_with_block_scope =
|
||||||
(!options.ie8 && node instanceof AST_SymbolCatch) ||
|
(!options.ie8 && node instanceof AST_SymbolCatch) ||
|
||||||
node instanceof AST_SymbolBlockDeclaration;
|
node instanceof AST_SymbolBlockDeclaration;
|
||||||
if (mangle_with_block_scope) {
|
if (mangle_with_block_scope && options.reserved.indexOf(node.name) < 0) {
|
||||||
to_mangle.push(node.definition());
|
to_mangle.push(node.definition());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -551,6 +549,74 @@ AST_Toplevel.DEFMETHOD("mangle_names", function(options){
|
|||||||
if (options.cache) {
|
if (options.cache) {
|
||||||
options.cache.cname = this.cname;
|
options.cache.cname = this.cname;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function collect(symbol) {
|
||||||
|
if (!member(symbol.name, options.reserved)) {
|
||||||
|
to_mangle.push(symbol);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
AST_Toplevel.DEFMETHOD("find_unique_prefix", function(options) {
|
||||||
|
var letters = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ$_";
|
||||||
|
var cache = options.cache && options.cache.props;
|
||||||
|
var prefixes = Object.create(null);
|
||||||
|
options.reserved.forEach(add_prefix);
|
||||||
|
this.globals.each(add_def);
|
||||||
|
this.walk(new TreeWalker(function(node) {
|
||||||
|
if (node instanceof AST_Scope) node.variables.each(add_def);
|
||||||
|
if (node instanceof AST_SymbolCatch) add_def(node.definition());
|
||||||
|
}));
|
||||||
|
var prefix, i = 0;
|
||||||
|
do {
|
||||||
|
prefix = create_name(i++);
|
||||||
|
} while (prefixes[prefix]);
|
||||||
|
return prefix;
|
||||||
|
|
||||||
|
function add_prefix(name) {
|
||||||
|
if (/[0-9]$/.test(name)) {
|
||||||
|
prefixes[name.replace(/[0-9]+$/, "")] = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function add_def(def) {
|
||||||
|
var name = def.name;
|
||||||
|
if (def.global && cache && cache.has(name)) name = cache.get(name);
|
||||||
|
else if (!def.unmangleable(options)) return;
|
||||||
|
add_prefix(name);
|
||||||
|
}
|
||||||
|
|
||||||
|
function create_name(num) {
|
||||||
|
var name = "";
|
||||||
|
do {
|
||||||
|
name += letters[num % letters.length];
|
||||||
|
num = Math.floor(num / letters.length);
|
||||||
|
} while (num);
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
AST_Toplevel.DEFMETHOD("expand_names", function(options) {
|
||||||
|
options = this._default_mangler_options(options);
|
||||||
|
var prefix = this.find_unique_prefix(options);
|
||||||
|
this.globals.each(rename);
|
||||||
|
this.walk(new TreeWalker(function(node) {
|
||||||
|
if (node instanceof AST_Scope) node.variables.each(rename);
|
||||||
|
if (node instanceof AST_SymbolCatch) rename(node.definition());
|
||||||
|
}));
|
||||||
|
|
||||||
|
function rename(def) {
|
||||||
|
if (def.global || def.unmangleable(options)) return;
|
||||||
|
if (member(def.name, options.reserved)) return;
|
||||||
|
var d = def.redefined();
|
||||||
|
def.name = d ? d.name : prefix + def.id;
|
||||||
|
def.orig.forEach(function(sym) {
|
||||||
|
sym.name = def.name;
|
||||||
|
});
|
||||||
|
def.references.forEach(function(sym) {
|
||||||
|
sym.name = def.name;
|
||||||
|
});
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
AST_Toplevel.DEFMETHOD("compute_char_frequency", function(options){
|
AST_Toplevel.DEFMETHOD("compute_char_frequency", function(options){
|
||||||
|
|||||||
@@ -70,7 +70,7 @@ TreeTransformer.prototype = new TreeWalker;
|
|||||||
if (y !== undefined) x = y;
|
if (y !== undefined) x = y;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
tw.pop(this);
|
tw.pop();
|
||||||
return x;
|
return x;
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
@@ -262,11 +262,7 @@ TreeTransformer.prototype = new TreeWalker;
|
|||||||
});
|
});
|
||||||
|
|
||||||
_(AST_TemplateString, function(self, tw) {
|
_(AST_TemplateString, function(self, tw) {
|
||||||
for (var i = 0; i < self.segments.length; i++) {
|
self.segments = do_list(self.segments, tw);
|
||||||
if (!(self.segments[i] instanceof AST_TemplateSegment)) {
|
|
||||||
self.segments[i] = self.segments[i].transform(tw);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
_(AST_PrefixedTemplateString, function(self, tw) {
|
_(AST_PrefixedTemplateString, function(self, tw) {
|
||||||
|
|||||||
25
package.json
25
package.json
@@ -1,20 +1,17 @@
|
|||||||
{
|
{
|
||||||
"name": "uglify-es",
|
"name": "uglify-es",
|
||||||
"description": "JavaScript parser, mangler/compressor and beautifier toolkit",
|
"description": "JavaScript parser, mangler/compressor and beautifier toolkit for ES6+",
|
||||||
"homepage": "https://github.com/mishoo/UglifyJS2/tree/harmony",
|
"homepage": "https://github.com/mishoo/UglifyJS2/tree/harmony",
|
||||||
"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.0.22",
|
"version": "3.2.0",
|
||||||
"engines": {
|
"engines": {
|
||||||
"node": ">=0.8.0"
|
"node": ">=0.8.0"
|
||||||
},
|
},
|
||||||
"maintainers": [
|
"maintainers": [
|
||||||
"Mihai Bazon <mihai.bazon@gmail.com> (http://lisperator.net/)"
|
"Mihai Bazon <mihai.bazon@gmail.com> (http://lisperator.net/)"
|
||||||
],
|
],
|
||||||
"repository": {
|
"repository": "git+https://github.com/mishoo/UglifyJS2.git#harmony",
|
||||||
"type": "git",
|
|
||||||
"url": "https://github.com/mishoo/UglifyJS2.git"
|
|
||||||
},
|
|
||||||
"bugs": {
|
"bugs": {
|
||||||
"url": "https://github.com/mishoo/UglifyJS2/issues"
|
"url": "https://github.com/mishoo/UglifyJS2/issues"
|
||||||
},
|
},
|
||||||
@@ -29,25 +26,29 @@
|
|||||||
"LICENSE"
|
"LICENSE"
|
||||||
],
|
],
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"commander": "~2.9.0",
|
"commander": "~2.12.1",
|
||||||
"source-map": "~0.5.1"
|
"source-map": "~0.6.1"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"acorn": "~5.0.3",
|
"acorn": "~5.2.1",
|
||||||
"mocha": "~2.3.4",
|
"mocha": "~3.5.1",
|
||||||
"semver": "~5.3.0"
|
"semver": "~5.4.1"
|
||||||
},
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"test": "node test/run-tests.js"
|
"test": "node test/run-tests.js"
|
||||||
},
|
},
|
||||||
"keywords": [
|
"keywords": [
|
||||||
"uglify",
|
"uglify",
|
||||||
"uglify-js",
|
|
||||||
"uglify-es",
|
"uglify-es",
|
||||||
|
"uglify-js",
|
||||||
"minify",
|
"minify",
|
||||||
"minifier",
|
"minifier",
|
||||||
|
"javascript",
|
||||||
|
"ecmascript",
|
||||||
"es5",
|
"es5",
|
||||||
"es6",
|
"es6",
|
||||||
|
"es7",
|
||||||
|
"es8",
|
||||||
"es2015",
|
"es2015",
|
||||||
"es2016",
|
"es2016",
|
||||||
"es2017",
|
"es2017",
|
||||||
|
|||||||
@@ -6,6 +6,7 @@
|
|||||||
var createHash = require("crypto").createHash;
|
var createHash = require("crypto").createHash;
|
||||||
var fetch = require("./fetch");
|
var fetch = require("./fetch");
|
||||||
var fork = require("child_process").fork;
|
var fork = require("child_process").fork;
|
||||||
|
var zlib = require("zlib");
|
||||||
var args = process.argv.slice(2);
|
var args = process.argv.slice(2);
|
||||||
if (!args.length) {
|
if (!args.length) {
|
||||||
args.push("-mc");
|
args.push("-mc");
|
||||||
@@ -33,6 +34,7 @@ function done() {
|
|||||||
console.log(info.log);
|
console.log(info.log);
|
||||||
console.log("Original:", info.input, "bytes");
|
console.log("Original:", info.input, "bytes");
|
||||||
console.log("Uglified:", info.output, "bytes");
|
console.log("Uglified:", info.output, "bytes");
|
||||||
|
console.log("GZipped: ", info.gzip, "bytes");
|
||||||
console.log("SHA1 sum:", info.sha1);
|
console.log("SHA1 sum:", info.sha1);
|
||||||
if (info.code) {
|
if (info.code) {
|
||||||
failures.push(url);
|
failures.push(url);
|
||||||
@@ -51,6 +53,7 @@ urls.forEach(function(url) {
|
|||||||
results[url] = {
|
results[url] = {
|
||||||
input: 0,
|
input: 0,
|
||||||
output: 0,
|
output: 0,
|
||||||
|
gzip: 0,
|
||||||
log: ""
|
log: ""
|
||||||
};
|
};
|
||||||
fetch(url, function(err, res) {
|
fetch(url, function(err, res) {
|
||||||
@@ -61,6 +64,10 @@ urls.forEach(function(url) {
|
|||||||
}).pipe(uglifyjs.stdin);
|
}).pipe(uglifyjs.stdin);
|
||||||
uglifyjs.stdout.on("data", function(data) {
|
uglifyjs.stdout.on("data", function(data) {
|
||||||
results[url].output += data.length;
|
results[url].output += data.length;
|
||||||
|
}).pipe(zlib.createGzip({
|
||||||
|
level: zlib.Z_BEST_COMPRESSION
|
||||||
|
})).on("data", function(data) {
|
||||||
|
results[url].gzip += data.length;
|
||||||
}).pipe(createHash("sha1")).on("data", function(data) {
|
}).pipe(createHash("sha1")).on("data", function(data) {
|
||||||
results[url].sha1 = data.toString("hex");
|
results[url].sha1 = data.toString("hex");
|
||||||
done();
|
done();
|
||||||
|
|||||||
@@ -203,50 +203,114 @@ constant_join_3: {
|
|||||||
|
|
||||||
for_loop: {
|
for_loop: {
|
||||||
options = {
|
options = {
|
||||||
unsafe : true,
|
evaluate: true,
|
||||||
unused : true,
|
reduce_funcs: true,
|
||||||
evaluate : true,
|
reduce_vars: true,
|
||||||
reduce_vars : true
|
unsafe: true,
|
||||||
|
unused: true,
|
||||||
};
|
};
|
||||||
input: {
|
input: {
|
||||||
function f0() {
|
function f0() {
|
||||||
var a = [1, 2, 3];
|
var a = [1, 2, 3];
|
||||||
for (var i = 0; i < a.length; i++) {
|
var b = 0;
|
||||||
console.log(a[i]);
|
for (var i = 0; i < a.length; i++)
|
||||||
}
|
b += a[i];
|
||||||
|
return b;
|
||||||
}
|
}
|
||||||
|
|
||||||
function f1() {
|
function f1() {
|
||||||
var a = [1, 2, 3];
|
var a = [1, 2, 3];
|
||||||
for (var i = 0, len = a.length; i < len; i++) {
|
var b = 0;
|
||||||
console.log(a[i]);
|
for (var i = 0, len = a.length; i < len; i++)
|
||||||
}
|
b += a[i];
|
||||||
|
return b;
|
||||||
}
|
}
|
||||||
|
|
||||||
function f2() {
|
|
||||||
var a = [1, 2, 3];
|
|
||||||
for (var i = 0; i < a.length; i++) {
|
|
||||||
a[i]++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
function f0() {
|
|
||||||
var a = [1, 2, 3];
|
|
||||||
for (var i = 0; i < 3; i++)
|
|
||||||
console.log(a[i]);
|
|
||||||
}
|
|
||||||
|
|
||||||
function f1() {
|
|
||||||
var a = [1, 2, 3];
|
|
||||||
for (var i = 0; i < 3; i++)
|
|
||||||
console.log(a[i]);
|
|
||||||
}
|
|
||||||
|
|
||||||
function f2() {
|
function f2() {
|
||||||
var a = [1, 2, 3];
|
var a = [1, 2, 3];
|
||||||
for (var i = 0; i < a.length; i++)
|
for (var i = 0; i < a.length; i++)
|
||||||
a[i]++;
|
a[i]++;
|
||||||
|
return a[2];
|
||||||
}
|
}
|
||||||
|
console.log(f0(), f1(), f2());
|
||||||
}
|
}
|
||||||
|
expect: {
|
||||||
|
function f0() {
|
||||||
|
var a = [1, 2, 3];
|
||||||
|
var b = 0;
|
||||||
|
for (var i = 0; i < 3; i++)
|
||||||
|
b += a[i];
|
||||||
|
return b;
|
||||||
|
}
|
||||||
|
function f1() {
|
||||||
|
var a = [1, 2, 3];
|
||||||
|
var b = 0;
|
||||||
|
for (var i = 0; i < 3; i++)
|
||||||
|
b += a[i];
|
||||||
|
return b;
|
||||||
|
}
|
||||||
|
function f2() {
|
||||||
|
var a = [1, 2, 3];
|
||||||
|
for (var i = 0; i < a.length; i++)
|
||||||
|
a[i]++;
|
||||||
|
return a[2];
|
||||||
|
}
|
||||||
|
console.log(f0(), f1(), f2());
|
||||||
|
}
|
||||||
|
expect_stdout: "6 6 4"
|
||||||
|
}
|
||||||
|
|
||||||
|
index: {
|
||||||
|
options = {
|
||||||
|
evaluate: true,
|
||||||
|
reduce_funcs: true,
|
||||||
|
reduce_vars: true,
|
||||||
|
toplevel: true,
|
||||||
|
unsafe: true,
|
||||||
|
unused: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
var a = [ 1, 2 ];
|
||||||
|
console.log(a[0], a[1]);
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
console.log(1, 2);
|
||||||
|
}
|
||||||
|
expect_stdout: "1 2"
|
||||||
|
}
|
||||||
|
|
||||||
|
length: {
|
||||||
|
options = {
|
||||||
|
evaluate: true,
|
||||||
|
reduce_funcs: true,
|
||||||
|
reduce_vars: true,
|
||||||
|
toplevel: true,
|
||||||
|
unsafe: true,
|
||||||
|
unused: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
var a = [ 1, 2 ];
|
||||||
|
console.log(a.length);
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
console.log(2);
|
||||||
|
}
|
||||||
|
expect_stdout: "2"
|
||||||
|
}
|
||||||
|
|
||||||
|
index_length: {
|
||||||
|
options = {
|
||||||
|
evaluate: true,
|
||||||
|
reduce_funcs: true,
|
||||||
|
reduce_vars: true,
|
||||||
|
toplevel: true,
|
||||||
|
unsafe: true,
|
||||||
|
unused: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
var a = [ 1, 2 ];
|
||||||
|
console.log(a[0], a.length);
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
console.log(1, 2);
|
||||||
|
}
|
||||||
|
expect_stdout: "1 2"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -213,7 +213,7 @@ no_leading_parentheses: {
|
|||||||
|
|
||||||
async_identifiers: {
|
async_identifiers: {
|
||||||
options = {
|
options = {
|
||||||
arrows: true,
|
unsafe_arrows: true,
|
||||||
ecma: 6,
|
ecma: 6,
|
||||||
}
|
}
|
||||||
input: {
|
input: {
|
||||||
@@ -237,7 +237,7 @@ async_identifiers: {
|
|||||||
|
|
||||||
async_function_expression: {
|
async_function_expression: {
|
||||||
options = {
|
options = {
|
||||||
arrows: true,
|
unsafe_arrows: true,
|
||||||
ecma: 6,
|
ecma: 6,
|
||||||
evaluate: true,
|
evaluate: true,
|
||||||
side_effects: true,
|
side_effects: true,
|
||||||
@@ -262,7 +262,7 @@ async_function_expression: {
|
|||||||
|
|
||||||
issue_27: {
|
issue_27: {
|
||||||
options = {
|
options = {
|
||||||
arrows: true,
|
unsafe_arrows: true,
|
||||||
collapse_vars: true,
|
collapse_vars: true,
|
||||||
ecma: 6,
|
ecma: 6,
|
||||||
unused: true,
|
unused: true,
|
||||||
@@ -283,12 +283,15 @@ issue_27: {
|
|||||||
|
|
||||||
issue_2105_1: {
|
issue_2105_1: {
|
||||||
options = {
|
options = {
|
||||||
arrows: true,
|
unsafe_arrows: true,
|
||||||
collapse_vars: true,
|
collapse_vars: true,
|
||||||
ecma: 6,
|
ecma: 6,
|
||||||
inline: true,
|
inline: true,
|
||||||
|
passes: 3,
|
||||||
|
reduce_funcs: true,
|
||||||
reduce_vars: true,
|
reduce_vars: true,
|
||||||
side_effects: true,
|
side_effects: true,
|
||||||
|
unsafe_methods: true,
|
||||||
unused: true,
|
unused: true,
|
||||||
}
|
}
|
||||||
input: {
|
input: {
|
||||||
@@ -312,17 +315,12 @@ issue_2105_1: {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
expect: {
|
expect: {
|
||||||
void (() => {
|
({
|
||||||
var quux = () => {
|
prop() {
|
||||||
|
console.log;
|
||||||
console.log("PASS");
|
console.log("PASS");
|
||||||
};
|
}
|
||||||
return {
|
}).prop();
|
||||||
prop: () => {
|
|
||||||
console.log;
|
|
||||||
quux();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
})().prop();
|
|
||||||
}
|
}
|
||||||
expect_stdout: "PASS"
|
expect_stdout: "PASS"
|
||||||
node_version: ">=4"
|
node_version: ">=4"
|
||||||
@@ -332,6 +330,8 @@ issue_2105_2: {
|
|||||||
options = {
|
options = {
|
||||||
collapse_vars: true,
|
collapse_vars: true,
|
||||||
inline: true,
|
inline: true,
|
||||||
|
passes: 2,
|
||||||
|
reduce_funcs: true,
|
||||||
reduce_vars: true,
|
reduce_vars: true,
|
||||||
side_effects: true,
|
side_effects: true,
|
||||||
unused: true,
|
unused: true,
|
||||||
@@ -357,17 +357,12 @@ issue_2105_2: {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
expect: {
|
expect: {
|
||||||
void (() => {
|
({
|
||||||
var quux = () => {
|
prop: () => {
|
||||||
|
console.log;
|
||||||
console.log("PASS");
|
console.log("PASS");
|
||||||
};
|
}
|
||||||
return {
|
}).prop();
|
||||||
prop: () => {
|
|
||||||
console.log;
|
|
||||||
quux();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
})().prop();
|
|
||||||
}
|
}
|
||||||
expect_stdout: "PASS"
|
expect_stdout: "PASS"
|
||||||
node_version: ">=6"
|
node_version: ">=6"
|
||||||
@@ -408,6 +403,7 @@ issue_2136_3: {
|
|||||||
evaluate: true,
|
evaluate: true,
|
||||||
inline: true,
|
inline: true,
|
||||||
passes: 3,
|
passes: 3,
|
||||||
|
reduce_funcs: true,
|
||||||
reduce_vars: true,
|
reduce_vars: true,
|
||||||
side_effects: true,
|
side_effects: true,
|
||||||
toplevel: true,
|
toplevel: true,
|
||||||
@@ -435,6 +431,7 @@ call_args: {
|
|||||||
ecma: 6,
|
ecma: 6,
|
||||||
evaluate: true,
|
evaluate: true,
|
||||||
inline: true,
|
inline: true,
|
||||||
|
reduce_funcs: true,
|
||||||
reduce_vars: true,
|
reduce_vars: true,
|
||||||
}
|
}
|
||||||
input: {
|
input: {
|
||||||
@@ -459,6 +456,7 @@ call_args_drop_param: {
|
|||||||
evaluate: true,
|
evaluate: true,
|
||||||
inline: true,
|
inline: true,
|
||||||
keep_fargs: false,
|
keep_fargs: false,
|
||||||
|
reduce_funcs: true,
|
||||||
reduce_vars: true,
|
reduce_vars: true,
|
||||||
unused: true,
|
unused: true,
|
||||||
}
|
}
|
||||||
@@ -499,13 +497,14 @@ issue_485_crashing_1530: {
|
|||||||
|
|
||||||
issue_2084: {
|
issue_2084: {
|
||||||
options = {
|
options = {
|
||||||
arrows: true,
|
unsafe_arrows: true,
|
||||||
collapse_vars: true,
|
collapse_vars: true,
|
||||||
conditionals: true,
|
conditionals: true,
|
||||||
ecma: 6,
|
ecma: 6,
|
||||||
evaluate: true,
|
evaluate: true,
|
||||||
inline: true,
|
inline: true,
|
||||||
passes: 2,
|
passes: 2,
|
||||||
|
reduce_funcs: true,
|
||||||
reduce_vars: true,
|
reduce_vars: true,
|
||||||
sequences: true,
|
sequences: true,
|
||||||
side_effects: true,
|
side_effects: true,
|
||||||
@@ -538,3 +537,121 @@ issue_2084: {
|
|||||||
expect_stdout: "0"
|
expect_stdout: "0"
|
||||||
node_version: ">=4"
|
node_version: ">=4"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export_default_object_expression: {
|
||||||
|
options = {
|
||||||
|
arrows: true,
|
||||||
|
evaluate: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
export default {
|
||||||
|
foo: 1 + 2,
|
||||||
|
bar() { return 4; },
|
||||||
|
get baz() { return this.foo; },
|
||||||
|
};
|
||||||
|
}
|
||||||
|
expect_exact: "export default{foo:3,bar:()=>4,get baz(){return this.foo}};"
|
||||||
|
}
|
||||||
|
|
||||||
|
concise_methods_with_computed_property2: {
|
||||||
|
options = {
|
||||||
|
arrows: true,
|
||||||
|
evaluate: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
var foo = {
|
||||||
|
[[1]](v) {
|
||||||
|
return v;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
console.log(foo[[1]]("PASS"));
|
||||||
|
}
|
||||||
|
expect_exact: 'var foo={[[1]]:v=>v};console.log(foo[[1]]("PASS"));'
|
||||||
|
expect_stdout: "PASS"
|
||||||
|
node_version: ">=4"
|
||||||
|
}
|
||||||
|
|
||||||
|
async_object_literal: {
|
||||||
|
options = {
|
||||||
|
arrows: true,
|
||||||
|
unsafe_arrows: true,
|
||||||
|
ecma: 6,
|
||||||
|
evaluate: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
var obj = {
|
||||||
|
async a() {
|
||||||
|
return await foo(1 + 0);
|
||||||
|
},
|
||||||
|
anon: async function() {
|
||||||
|
return await foo(2 + 0);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
var obj = {
|
||||||
|
a: async () => await foo(1),
|
||||||
|
anon: async () => await foo(2)
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
issue_2271: {
|
||||||
|
options = {
|
||||||
|
arrows: true,
|
||||||
|
ecma: 6,
|
||||||
|
evaluate: true,
|
||||||
|
unsafe_arrows: false,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
var Foo = function() {};
|
||||||
|
Foo.prototype.set = function(value) {
|
||||||
|
this.value = value;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
Foo.prototype.print = function() {
|
||||||
|
console.log(this.value);
|
||||||
|
}
|
||||||
|
new Foo().set("PASS").print();
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
var Foo = function() {};
|
||||||
|
Foo.prototype.set = function(value) {
|
||||||
|
this.value = value;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
Foo.prototype.print = function() {
|
||||||
|
console.log(this.value);
|
||||||
|
}
|
||||||
|
new Foo().set("PASS").print();
|
||||||
|
}
|
||||||
|
expect_stdout: "PASS"
|
||||||
|
}
|
||||||
|
|
||||||
|
concise_method_with_super: {
|
||||||
|
options = {
|
||||||
|
arrows: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
var o = {
|
||||||
|
f: "FAIL",
|
||||||
|
g() {
|
||||||
|
return super.f;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Object.setPrototypeOf(o, { f: "PASS" });
|
||||||
|
console.log(o.g());
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
var o = {
|
||||||
|
f: "FAIL",
|
||||||
|
g() {
|
||||||
|
return super.f;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Object.setPrototypeOf(o, { f: "PASS" });
|
||||||
|
console.log(o.g());
|
||||||
|
}
|
||||||
|
expect_stdout: "PASS"
|
||||||
|
node_version: ">=4"
|
||||||
|
}
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ ascii_only_true: {
|
|||||||
"\x20\x21\x22\x23 ... \x7d\x7e\x7f\x80\x81 ... \xfe\xff\u0fff\uffff";
|
"\x20\x21\x22\x23 ... \x7d\x7e\x7f\x80\x81 ... \xfe\xff\u0fff\uffff";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
expect_exact: 'function f(){return"\\x000\\x001\\x007\\08\\0"+"\\0\\x01\\x02\\x03\\x04\\x05\\x06\\x07\\b\\t\\n\\v\\f\\r\\x0e\\x0f"+"\\x10\\x11\\x12\\x13\\x14\\x15\\x16\\x17\\x18\\x19\\x1a\\x1b\\x1c\\x1d\\x1e\\x1f"+\' !"# ... }~\\x7f\\x80\\x81 ... \\xfe\\xff\\u0fff\\uffff\'}'
|
expect_exact: 'function f(){return"\\x000\\x001\\x007\\x008\\0"+"\\0\\x01\\x02\\x03\\x04\\x05\\x06\\x07\\b\\t\\n\\v\\f\\r\\x0e\\x0f"+"\\x10\\x11\\x12\\x13\\x14\\x15\\x16\\x17\\x18\\x19\\x1a\\x1b\\x1c\\x1d\\x1e\\x1f"+\' !"# ... }~\\x7f\\x80\\x81 ... \\xfe\\xff\\u0fff\\uffff\'}'
|
||||||
}
|
}
|
||||||
|
|
||||||
ascii_only_false: {
|
ascii_only_false: {
|
||||||
@@ -31,5 +31,5 @@ ascii_only_false: {
|
|||||||
"\x20\x21\x22\x23 ... \x7d\x7e\x7f\x80\x81 ... \xfe\xff\u0fff\uffff";
|
"\x20\x21\x22\x23 ... \x7d\x7e\x7f\x80\x81 ... \xfe\xff\u0fff\uffff";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
expect_exact: 'function f(){return"\\x000\\x001\\x007\\08\\0"+"\\0\x01\x02\x03\x04\x05\x06\x07\\b\\t\\n\\v\\f\\r\x0e\x0f"+"\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f"+\' !"# ... }~\x7f\x80\x81 ... \xfe\xff\u0fff\uffff\'}'
|
expect_exact: 'function f(){return"\\x000\\x001\\x007\\x008\\0"+"\\0\x01\x02\x03\x04\x05\x06\x07\\b\\t\\n\\v\\f\\r\x0e\x0f"+"\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f"+\' !"# ... }~\x7f\x80\x81 ... \xfe\xff\u0fff\uffff\'}'
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -104,3 +104,65 @@ asm_mixed: {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
asm_toplevel: {
|
||||||
|
options = {}
|
||||||
|
input: {
|
||||||
|
"use asm";
|
||||||
|
0.0;
|
||||||
|
function f() {
|
||||||
|
0.0;
|
||||||
|
(function(){
|
||||||
|
0.0;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
0.0;
|
||||||
|
}
|
||||||
|
expect_exact: '"use asm";0.0;function f(){0.0;(function(){0.0})}0.0;'
|
||||||
|
}
|
||||||
|
|
||||||
|
asm_function_expression: {
|
||||||
|
options = {}
|
||||||
|
input: {
|
||||||
|
0.0;
|
||||||
|
var a = function() {
|
||||||
|
"use asm";
|
||||||
|
0.0;
|
||||||
|
}
|
||||||
|
function f() {
|
||||||
|
0.0;
|
||||||
|
return function(){
|
||||||
|
"use asm";
|
||||||
|
0.0;
|
||||||
|
}
|
||||||
|
0.0;
|
||||||
|
}
|
||||||
|
0.0;
|
||||||
|
}
|
||||||
|
expect_exact: '0;var a=function(){"use asm";0.0};function f(){0;return function(){"use asm";0.0};0}0;'
|
||||||
|
}
|
||||||
|
|
||||||
|
asm_nested_functions: {
|
||||||
|
options = {}
|
||||||
|
input: {
|
||||||
|
0.0;
|
||||||
|
function a() {
|
||||||
|
"use asm";
|
||||||
|
0.0;
|
||||||
|
}
|
||||||
|
0.0;
|
||||||
|
function b() {
|
||||||
|
0.0;
|
||||||
|
function c(){
|
||||||
|
"use asm";
|
||||||
|
0.0;
|
||||||
|
}
|
||||||
|
0.0;
|
||||||
|
function d(){
|
||||||
|
0.0;
|
||||||
|
}
|
||||||
|
0.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;'
|
||||||
|
}
|
||||||
|
|||||||
@@ -141,6 +141,7 @@ async_inline: {
|
|||||||
evaluate: true,
|
evaluate: true,
|
||||||
inline: true,
|
inline: true,
|
||||||
negate_iife: true,
|
negate_iife: true,
|
||||||
|
reduce_funcs: true,
|
||||||
reduce_vars: true,
|
reduce_vars: true,
|
||||||
side_effects: true,
|
side_effects: true,
|
||||||
toplevel: true,
|
toplevel: true,
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@@ -73,4 +73,42 @@ dont_change_in_or_instanceof_expressions: {
|
|||||||
1 instanceof 1;
|
1 instanceof 1;
|
||||||
null instanceof null;
|
null instanceof null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
self_comparison_1: {
|
||||||
|
options = {
|
||||||
|
comparisons: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
a === a;
|
||||||
|
a !== b;
|
||||||
|
b.c === a.c;
|
||||||
|
b.c !== b.c;
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
a == a;
|
||||||
|
a !== b;
|
||||||
|
b.c === a.c;
|
||||||
|
b.c != b.c;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
self_comparison_2: {
|
||||||
|
options = {
|
||||||
|
comparisons: true,
|
||||||
|
reduce_funcs: true,
|
||||||
|
reduce_vars: true,
|
||||||
|
toplevel: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
function f() {}
|
||||||
|
var o = {};
|
||||||
|
console.log(f != f, o === o);
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
function f() {}
|
||||||
|
var o = {};
|
||||||
|
console.log(false, true);
|
||||||
|
}
|
||||||
|
expect_stdout: "false true"
|
||||||
|
}
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ concat_1: {
|
|||||||
var c = 1 + x() + 2 + "boo";
|
var c = 1 + x() + 2 + "boo";
|
||||||
var d = 1 + x() + 2 + 3 + "boo";
|
var d = 1 + x() + 2 + 3 + "boo";
|
||||||
var e = 1 + x() + 2 + "X3boo";
|
var e = 1 + x() + 2 + "X3boo";
|
||||||
var f = "\x00360\08\0";
|
var f = "\x00360\x008\0";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ issue_1191: {
|
|||||||
join_vars : true,
|
join_vars : true,
|
||||||
sequences : false,
|
sequences : false,
|
||||||
collapse_vars : false,
|
collapse_vars : false,
|
||||||
|
reduce_funcs : true,
|
||||||
reduce_vars : true,
|
reduce_vars : true,
|
||||||
}
|
}
|
||||||
input: {
|
input: {
|
||||||
@@ -44,6 +45,7 @@ issue_1194: {
|
|||||||
join_vars : true,
|
join_vars : true,
|
||||||
sequences : false,
|
sequences : false,
|
||||||
collapse_vars : false,
|
collapse_vars : false,
|
||||||
|
reduce_funcs : true,
|
||||||
reduce_vars : true,
|
reduce_vars : true,
|
||||||
}
|
}
|
||||||
input: {
|
input: {
|
||||||
@@ -72,6 +74,7 @@ issue_1396: {
|
|||||||
join_vars : true,
|
join_vars : true,
|
||||||
sequences : false,
|
sequences : false,
|
||||||
collapse_vars : false,
|
collapse_vars : false,
|
||||||
|
reduce_funcs : true,
|
||||||
reduce_vars : true,
|
reduce_vars : true,
|
||||||
}
|
}
|
||||||
input: {
|
input: {
|
||||||
@@ -143,6 +146,7 @@ regexp_literal_not_const: {
|
|||||||
join_vars : true,
|
join_vars : true,
|
||||||
sequences : false,
|
sequences : false,
|
||||||
collapse_vars : false,
|
collapse_vars : false,
|
||||||
|
reduce_funcs : true,
|
||||||
reduce_vars : true,
|
reduce_vars : true,
|
||||||
}
|
}
|
||||||
input: {
|
input: {
|
||||||
|
|||||||
@@ -202,6 +202,7 @@ dead_code_const_declaration: {
|
|||||||
booleans : true,
|
booleans : true,
|
||||||
conditionals : true,
|
conditionals : true,
|
||||||
evaluate : true,
|
evaluate : true,
|
||||||
|
reduce_funcs : true,
|
||||||
reduce_vars : true,
|
reduce_vars : true,
|
||||||
};
|
};
|
||||||
input: {
|
input: {
|
||||||
@@ -229,6 +230,7 @@ dead_code_const_annotation: {
|
|||||||
booleans : true,
|
booleans : true,
|
||||||
conditionals : true,
|
conditionals : true,
|
||||||
evaluate : true,
|
evaluate : true,
|
||||||
|
reduce_funcs : true,
|
||||||
reduce_vars : true,
|
reduce_vars : true,
|
||||||
toplevel : true,
|
toplevel : true,
|
||||||
};
|
};
|
||||||
@@ -281,6 +283,7 @@ dead_code_const_annotation_complex_scope: {
|
|||||||
booleans : true,
|
booleans : true,
|
||||||
conditionals : true,
|
conditionals : true,
|
||||||
evaluate : true,
|
evaluate : true,
|
||||||
|
reduce_funcs : true,
|
||||||
reduce_vars : true,
|
reduce_vars : true,
|
||||||
toplevel : true,
|
toplevel : true,
|
||||||
};
|
};
|
||||||
@@ -377,3 +380,249 @@ accessor: {
|
|||||||
}
|
}
|
||||||
expect: {}
|
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",
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
|
issue_2383_1: {
|
||||||
|
options = {
|
||||||
|
conditionals: true,
|
||||||
|
dead_code: true,
|
||||||
|
evaluate: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
if (0) {
|
||||||
|
var {x, y} = foo();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
var x, y;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
issue_2383_2: {
|
||||||
|
options = {
|
||||||
|
conditionals: true,
|
||||||
|
dead_code: true,
|
||||||
|
evaluate: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
if (0) {
|
||||||
|
var {
|
||||||
|
x = 0,
|
||||||
|
y: [ w, , { z, p: q = 7 } ] = [ 1, 2, { z: 3 } ]
|
||||||
|
} = {};
|
||||||
|
}
|
||||||
|
console.log(x, q, w, z);
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
var x, w, z, q;
|
||||||
|
console.log(x, q, w, z);
|
||||||
|
}
|
||||||
|
expect_stdout: "undefined undefined undefined undefined"
|
||||||
|
node_version: ">=6"
|
||||||
|
}
|
||||||
|
|
||||||
|
issue_2383_3: {
|
||||||
|
options = {
|
||||||
|
conditionals: true,
|
||||||
|
dead_code: true,
|
||||||
|
evaluate: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
var b = 7, y = 8;
|
||||||
|
if (0) {
|
||||||
|
var a = 1, [ x, y, z ] = [ 2, 3, 4 ], b = 5;
|
||||||
|
}
|
||||||
|
console.log(a, x, y, z, b);
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
var b = 7, y = 8;
|
||||||
|
var a, x, y, z, b;
|
||||||
|
console.log(a, x, y, z, b);
|
||||||
|
}
|
||||||
|
expect_stdout: "undefined undefined 8 undefined 7"
|
||||||
|
node_version: ">=6"
|
||||||
|
}
|
||||||
|
|||||||
@@ -65,10 +65,10 @@ nested_destructuring_objects: {
|
|||||||
}
|
}
|
||||||
input: {
|
input: {
|
||||||
const [{a},b] = c;
|
const [{a},b] = c;
|
||||||
let [{a},b] = c;
|
let [{d},e] = f;
|
||||||
var [{a},b] = c;
|
var [{g},h] = i;
|
||||||
}
|
}
|
||||||
expect_exact: 'const[{a},b]=c;let[{a},b]=c;var[{a},b]=c;';
|
expect_exact: 'const[{a},b]=c;let[{d},e]=f;var[{g},h]=i;';
|
||||||
}
|
}
|
||||||
|
|
||||||
destructuring_constdef_in_loops: {
|
destructuring_constdef_in_loops: {
|
||||||
@@ -262,6 +262,7 @@ destructuring_dont_evaluate_with_undefined_as_default_assignment: {
|
|||||||
|
|
||||||
reduce_vars: {
|
reduce_vars: {
|
||||||
options = {
|
options = {
|
||||||
|
reduce_funcs: true,
|
||||||
reduce_vars: true,
|
reduce_vars: true,
|
||||||
}
|
}
|
||||||
input: {
|
input: {
|
||||||
@@ -274,8 +275,8 @@ reduce_vars: {
|
|||||||
var {aa, bb: {cc, dd}} = {aa:1, bb: {cc:2, dd: 3}};
|
var {aa, bb: {cc, dd}} = {aa:1, bb: {cc:2, dd: 3}};
|
||||||
({aa, bb: {cc, dd}} = {aa:1, bb: {cc:2, dd: 3}});
|
({aa, bb: {cc, dd}} = {aa:1, bb: {cc:2, dd: 3}});
|
||||||
const [{a},b] = c;
|
const [{a},b] = c;
|
||||||
let [{a},b] = c;
|
let [{d},e] = f;
|
||||||
var [{a},b] = c;
|
var [{g},h] = i;
|
||||||
[{a},b] = c;
|
[{a},b] = c;
|
||||||
for (const [x,y] in pairs);
|
for (const [x,y] in pairs);
|
||||||
for (let [x,y] in pairs);
|
for (let [x,y] in pairs);
|
||||||
@@ -292,8 +293,8 @@ reduce_vars: {
|
|||||||
var {aa, bb: {cc, dd}} = {aa:1, bb: {cc:2, dd: 3}};
|
var {aa, bb: {cc, dd}} = {aa:1, bb: {cc:2, dd: 3}};
|
||||||
({aa, bb: {cc, dd}} = {aa:1, bb: {cc:2, dd: 3}});
|
({aa, bb: {cc, dd}} = {aa:1, bb: {cc:2, dd: 3}});
|
||||||
const [{a},b] = c;
|
const [{a},b] = c;
|
||||||
let [{a},b] = c;
|
let [{d},e] = f;
|
||||||
var [{a},b] = c;
|
var [{g},h] = i;
|
||||||
[{a},b] = c;
|
[{a},b] = c;
|
||||||
for (const [x,y] in pairs);
|
for (const [x,y] in pairs);
|
||||||
for (let [x,y] in pairs);
|
for (let [x,y] in pairs);
|
||||||
|
|||||||
@@ -733,6 +733,7 @@ drop_value: {
|
|||||||
const_assign: {
|
const_assign: {
|
||||||
options = {
|
options = {
|
||||||
evaluate: true,
|
evaluate: true,
|
||||||
|
reduce_funcs: true,
|
||||||
reduce_vars: true,
|
reduce_vars: true,
|
||||||
unused: true,
|
unused: true,
|
||||||
}
|
}
|
||||||
@@ -785,6 +786,7 @@ issue_1539: {
|
|||||||
vardef_value: {
|
vardef_value: {
|
||||||
options = {
|
options = {
|
||||||
keep_fnames: false,
|
keep_fnames: false,
|
||||||
|
reduce_funcs: true,
|
||||||
reduce_vars: true,
|
reduce_vars: true,
|
||||||
unused: true,
|
unused: true,
|
||||||
}
|
}
|
||||||
@@ -846,6 +848,7 @@ assign_chain: {
|
|||||||
issue_1583: {
|
issue_1583: {
|
||||||
options = {
|
options = {
|
||||||
keep_fargs: true,
|
keep_fargs: true,
|
||||||
|
reduce_funcs: true,
|
||||||
reduce_vars: true,
|
reduce_vars: true,
|
||||||
unused: true,
|
unused: true,
|
||||||
}
|
}
|
||||||
@@ -863,12 +866,12 @@ issue_1583: {
|
|||||||
expect: {
|
expect: {
|
||||||
function m(t) {
|
function m(t) {
|
||||||
(function(e) {
|
(function(e) {
|
||||||
t = e();
|
t = function() {
|
||||||
})(function() {
|
return (function(a) {
|
||||||
return (function(a) {
|
return function(a) {};
|
||||||
return a;
|
})();
|
||||||
})(function(a) {});
|
}();
|
||||||
});
|
})();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1200,6 +1203,7 @@ var_catch_toplevel: {
|
|||||||
options = {
|
options = {
|
||||||
conditionals: true,
|
conditionals: true,
|
||||||
negate_iife: true,
|
negate_iife: true,
|
||||||
|
reduce_funcs: true,
|
||||||
reduce_vars: true,
|
reduce_vars: true,
|
||||||
side_effects: true,
|
side_effects: true,
|
||||||
toplevel: true,
|
toplevel: true,
|
||||||
@@ -1210,6 +1214,7 @@ var_catch_toplevel: {
|
|||||||
a--;
|
a--;
|
||||||
try {
|
try {
|
||||||
a++;
|
a++;
|
||||||
|
x();
|
||||||
} catch(a) {
|
} catch(a) {
|
||||||
if (a) var a;
|
if (a) var a;
|
||||||
var a = 10;
|
var a = 10;
|
||||||
@@ -1219,9 +1224,8 @@ var_catch_toplevel: {
|
|||||||
}
|
}
|
||||||
expect: {
|
expect: {
|
||||||
!function() {
|
!function() {
|
||||||
a--;
|
|
||||||
try {
|
try {
|
||||||
a++;
|
x();
|
||||||
} catch(a) {
|
} catch(a) {
|
||||||
var a;
|
var a;
|
||||||
}
|
}
|
||||||
@@ -1291,14 +1295,15 @@ issue_2063: {
|
|||||||
}
|
}
|
||||||
expect: {
|
expect: {
|
||||||
var a;
|
var a;
|
||||||
var a;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
issue_2105: {
|
issue_2105_1: {
|
||||||
options = {
|
options = {
|
||||||
collapse_vars: true,
|
collapse_vars: true,
|
||||||
inline: true,
|
inline: true,
|
||||||
|
passes: 3,
|
||||||
|
reduce_funcs: true,
|
||||||
reduce_vars: true,
|
reduce_vars: true,
|
||||||
side_effects: true,
|
side_effects: true,
|
||||||
unused: true,
|
unused: true,
|
||||||
@@ -1324,17 +1329,51 @@ issue_2105: {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
expect: {
|
expect: {
|
||||||
!void function() {
|
({
|
||||||
var quux = function() {
|
prop: function() {
|
||||||
|
console.log;
|
||||||
console.log("PASS");
|
console.log("PASS");
|
||||||
};
|
}
|
||||||
return {
|
}).prop();
|
||||||
prop: function() {
|
}
|
||||||
console.log;
|
expect_stdout: "PASS"
|
||||||
quux();
|
}
|
||||||
|
|
||||||
|
issue_2105_2: {
|
||||||
|
options = {
|
||||||
|
collapse_vars: true,
|
||||||
|
inline: true,
|
||||||
|
passes: 3,
|
||||||
|
properties: true,
|
||||||
|
pure_getters: "strict",
|
||||||
|
reduce_funcs: true,
|
||||||
|
reduce_vars: true,
|
||||||
|
side_effects: true,
|
||||||
|
unsafe: true,
|
||||||
|
unused: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
!function(factory) {
|
||||||
|
factory();
|
||||||
|
}( function() {
|
||||||
|
return function(fn) {
|
||||||
|
fn()().prop();
|
||||||
|
}( function() {
|
||||||
|
function bar() {
|
||||||
|
var quux = function() {
|
||||||
|
console.log("PASS");
|
||||||
|
}, foo = function() {
|
||||||
|
console.log;
|
||||||
|
quux();
|
||||||
|
};
|
||||||
|
return { prop: foo };
|
||||||
}
|
}
|
||||||
};
|
return bar;
|
||||||
}().prop();
|
} );
|
||||||
|
});
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
console.log("PASS");
|
||||||
}
|
}
|
||||||
expect_stdout: "PASS"
|
expect_stdout: "PASS"
|
||||||
}
|
}
|
||||||
@@ -1389,6 +1428,7 @@ issue_2136_3: {
|
|||||||
evaluate: true,
|
evaluate: true,
|
||||||
inline: true,
|
inline: true,
|
||||||
passes: 3,
|
passes: 3,
|
||||||
|
reduce_funcs: true,
|
||||||
reduce_vars: true,
|
reduce_vars: true,
|
||||||
side_effects: true,
|
side_effects: true,
|
||||||
toplevel: true,
|
toplevel: true,
|
||||||
@@ -1426,3 +1466,209 @@ issue_2163: {
|
|||||||
b;
|
b;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
issue_2226_1: {
|
||||||
|
options = {
|
||||||
|
side_effects: true,
|
||||||
|
unused: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
function f1() {
|
||||||
|
var a = b;
|
||||||
|
a += c;
|
||||||
|
}
|
||||||
|
function f2(a) {
|
||||||
|
a <<= b;
|
||||||
|
}
|
||||||
|
function f3(a) {
|
||||||
|
--a;
|
||||||
|
}
|
||||||
|
function f4() {
|
||||||
|
var a = b;
|
||||||
|
return a *= c;
|
||||||
|
}
|
||||||
|
function f5(a) {
|
||||||
|
x(a /= b);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
function f1() {
|
||||||
|
b;
|
||||||
|
c;
|
||||||
|
}
|
||||||
|
function f2(a) {
|
||||||
|
b;
|
||||||
|
}
|
||||||
|
function f3(a) {
|
||||||
|
0;
|
||||||
|
}
|
||||||
|
function f4() {
|
||||||
|
var a = b;
|
||||||
|
return a *= c;
|
||||||
|
}
|
||||||
|
function f5(a) {
|
||||||
|
x(a /= b);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
issue_2226_2: {
|
||||||
|
options = {
|
||||||
|
cascade: true,
|
||||||
|
sequences: true,
|
||||||
|
side_effects: true,
|
||||||
|
unused: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
console.log(function(a, b) {
|
||||||
|
a += b;
|
||||||
|
return a;
|
||||||
|
}(1, 2));
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
console.log(function(a, b) {
|
||||||
|
return a += b;
|
||||||
|
}(1, 2));
|
||||||
|
}
|
||||||
|
expect_stdout: "3"
|
||||||
|
}
|
||||||
|
|
||||||
|
issue_2226_3: {
|
||||||
|
options = {
|
||||||
|
collapse_vars: true,
|
||||||
|
side_effects: true,
|
||||||
|
unused: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
console.log(function(a, b) {
|
||||||
|
a += b;
|
||||||
|
return a;
|
||||||
|
}(1, 2));
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
console.log(function(a, b) {
|
||||||
|
return a += 2;
|
||||||
|
}(1));
|
||||||
|
}
|
||||||
|
expect_stdout: "3"
|
||||||
|
}
|
||||||
|
|
||||||
|
issue_2288: {
|
||||||
|
options = {
|
||||||
|
unused: true,
|
||||||
|
}
|
||||||
|
beautify = {
|
||||||
|
beautify: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
function foo(o) {
|
||||||
|
for (var j = o.a, i = 0; i < 0; i++);
|
||||||
|
for (var i = 0; i < 0; i++);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
function foo(o) {
|
||||||
|
o.a;
|
||||||
|
for (i = 0; i < 0; i++);
|
||||||
|
for (var i = 0; i < 0; i++);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
issue_2418_1: {
|
||||||
|
options = {
|
||||||
|
unused: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
class C {}
|
||||||
|
function F() {}
|
||||||
|
(class c {});
|
||||||
|
(function f() {});
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
class C {}
|
||||||
|
function F() {}
|
||||||
|
(class {});
|
||||||
|
(function() {});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
issue_2418_2: {
|
||||||
|
options = {
|
||||||
|
keep_classnames: false,
|
||||||
|
keep_fnames: false,
|
||||||
|
unused: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
class C {}
|
||||||
|
function F() {}
|
||||||
|
(class c {});
|
||||||
|
(function f() {});
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
class C {}
|
||||||
|
function F() {}
|
||||||
|
(class {});
|
||||||
|
(function() {});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
issue_2418_3: {
|
||||||
|
options = {
|
||||||
|
keep_classnames: false,
|
||||||
|
keep_fnames: true,
|
||||||
|
unused: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
class C {}
|
||||||
|
function F() {}
|
||||||
|
(class c {});
|
||||||
|
(function f() {});
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
class C {}
|
||||||
|
function F() {}
|
||||||
|
(class {});
|
||||||
|
(function f() {});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
issue_2418_4: {
|
||||||
|
options = {
|
||||||
|
keep_classnames: true,
|
||||||
|
keep_fnames: false,
|
||||||
|
unused: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
class C {}
|
||||||
|
function F() {}
|
||||||
|
(class c {});
|
||||||
|
(function f() {});
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
class C {}
|
||||||
|
function F() {}
|
||||||
|
(class c {});
|
||||||
|
(function() {});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
issue_2418_5: {
|
||||||
|
options = {
|
||||||
|
keep_classnames: true,
|
||||||
|
keep_fnames: true,
|
||||||
|
unused: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
class C {}
|
||||||
|
function F() {}
|
||||||
|
(class c {});
|
||||||
|
(function f() {});
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
class C {}
|
||||||
|
function F() {}
|
||||||
|
(class c {});
|
||||||
|
(function f() {});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -344,22 +344,27 @@ unsafe_constant: {
|
|||||||
|
|
||||||
unsafe_object: {
|
unsafe_object: {
|
||||||
options = {
|
options = {
|
||||||
evaluate : true,
|
evaluate: true,
|
||||||
unsafe : true
|
reduce_funcs: true,
|
||||||
|
reduce_vars: true,
|
||||||
|
toplevel: true,
|
||||||
|
unsafe: true,
|
||||||
}
|
}
|
||||||
input: {
|
input: {
|
||||||
|
var o = { a: 1 };
|
||||||
console.log(
|
console.log(
|
||||||
({a:1}) + 1,
|
o + 1,
|
||||||
({a:1}).a + 1,
|
o.a + 1,
|
||||||
({a:1}).b + 1,
|
o.b + 1,
|
||||||
({a:1}).a.b + 1
|
o.a.b + 1
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
expect: {
|
expect: {
|
||||||
|
var o = { a: 1 };
|
||||||
console.log(
|
console.log(
|
||||||
({a:1}) + 1,
|
o + 1,
|
||||||
2,
|
2,
|
||||||
({a:1}).b + 1,
|
o.b + 1,
|
||||||
1..b + 1
|
1..b + 1
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -368,22 +373,27 @@ unsafe_object: {
|
|||||||
|
|
||||||
unsafe_object_nested: {
|
unsafe_object_nested: {
|
||||||
options = {
|
options = {
|
||||||
evaluate : true,
|
evaluate: true,
|
||||||
unsafe : true
|
reduce_funcs: true,
|
||||||
|
reduce_vars: true,
|
||||||
|
toplevel: true,
|
||||||
|
unsafe: true,
|
||||||
}
|
}
|
||||||
input: {
|
input: {
|
||||||
|
var o = { a: { b: 1 } };
|
||||||
console.log(
|
console.log(
|
||||||
({a:{b:1}}) + 1,
|
o + 1,
|
||||||
({a:{b:1}}).a + 1,
|
o.a + 1,
|
||||||
({a:{b:1}}).b + 1,
|
o.b + 1,
|
||||||
({a:{b:1}}).a.b + 1
|
o.a.b + 1
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
expect: {
|
expect: {
|
||||||
|
var o = { a: { b: 1 } };
|
||||||
console.log(
|
console.log(
|
||||||
({a:{b:1}}) + 1,
|
o + 1,
|
||||||
({a:{b:1}}).a + 1,
|
o.a + 1,
|
||||||
({a:{b:1}}).b + 1,
|
o.b + 1,
|
||||||
2
|
2
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -392,21 +402,26 @@ unsafe_object_nested: {
|
|||||||
|
|
||||||
unsafe_object_complex: {
|
unsafe_object_complex: {
|
||||||
options = {
|
options = {
|
||||||
evaluate : true,
|
evaluate: true,
|
||||||
unsafe : true
|
reduce_funcs: true,
|
||||||
|
reduce_vars: true,
|
||||||
|
toplevel: true,
|
||||||
|
unsafe: true,
|
||||||
}
|
}
|
||||||
input: {
|
input: {
|
||||||
|
var o = { a: { b: 1 }, b: 1 };
|
||||||
console.log(
|
console.log(
|
||||||
({a:{b:1},b:1}) + 1,
|
o + 1,
|
||||||
({a:{b:1},b:1}).a + 1,
|
o.a + 1,
|
||||||
({a:{b:1},b:1}).b + 1,
|
o.b + 1,
|
||||||
({a:{b:1},b:1}).a.b + 1
|
o.a.b + 1
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
expect: {
|
expect: {
|
||||||
|
var o = { a: { b: 1 }, b: 1 };
|
||||||
console.log(
|
console.log(
|
||||||
({a:{b:1},b:1}) + 1,
|
o + 1,
|
||||||
({a:{b:1},b:1}).a + 1,
|
o.a + 1,
|
||||||
2,
|
2,
|
||||||
2
|
2
|
||||||
);
|
);
|
||||||
@@ -416,22 +431,27 @@ unsafe_object_complex: {
|
|||||||
|
|
||||||
unsafe_object_repeated: {
|
unsafe_object_repeated: {
|
||||||
options = {
|
options = {
|
||||||
evaluate : true,
|
evaluate: true,
|
||||||
unsafe : true
|
reduce_funcs: true,
|
||||||
|
reduce_vars: true,
|
||||||
|
toplevel: true,
|
||||||
|
unsafe: true,
|
||||||
}
|
}
|
||||||
input: {
|
input: {
|
||||||
|
var o = { a: { b: 1 }, a: 1 };
|
||||||
console.log(
|
console.log(
|
||||||
({a:{b:1},a:1}) + 1,
|
o + 1,
|
||||||
({a:{b:1},a:1}).a + 1,
|
o.a + 1,
|
||||||
({a:{b:1},a:1}).b + 1,
|
o.b + 1,
|
||||||
({a:{b:1},a:1}).a.b + 1
|
o.a.b + 1
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
expect: {
|
expect: {
|
||||||
|
var o = { a: { b: 1 }, a: 1 };
|
||||||
console.log(
|
console.log(
|
||||||
({a:{b:1},a:1}) + 1,
|
o + 1,
|
||||||
2,
|
2,
|
||||||
({a:{b:1},a:1}).b + 1,
|
o.b + 1,
|
||||||
1..b + 1
|
1..b + 1
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -441,6 +461,7 @@ unsafe_object_repeated: {
|
|||||||
unsafe_object_accessor: {
|
unsafe_object_accessor: {
|
||||||
options = {
|
options = {
|
||||||
evaluate: true,
|
evaluate: true,
|
||||||
|
reduce_funcs: true,
|
||||||
reduce_vars: true,
|
reduce_vars: true,
|
||||||
unsafe: true,
|
unsafe: true,
|
||||||
}
|
}
|
||||||
@@ -464,10 +485,11 @@ unsafe_object_accessor: {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
unsafe_function: {
|
prop_function: {
|
||||||
options = {
|
options = {
|
||||||
evaluate : true,
|
evaluate: true,
|
||||||
unsafe : true
|
properties: true,
|
||||||
|
side_effects: true,
|
||||||
}
|
}
|
||||||
input: {
|
input: {
|
||||||
console.log(
|
console.log(
|
||||||
@@ -480,9 +502,9 @@ unsafe_function: {
|
|||||||
expect: {
|
expect: {
|
||||||
console.log(
|
console.log(
|
||||||
({a:{b:1},b:function(){}}) + 1,
|
({a:{b:1},b:function(){}}) + 1,
|
||||||
({a:{b:1},b:function(){}}).a + 1,
|
({b:1}) + 1,
|
||||||
({a:{b:1},b:function(){}}).b + 1,
|
function(){} + 1,
|
||||||
({a:{b:1},b:function(){}}).a.b + 1
|
2
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
expect_stdout: true
|
expect_stdout: true
|
||||||
@@ -708,10 +730,11 @@ unsafe_string_bad_index: {
|
|||||||
expect_stdout: true
|
expect_stdout: true
|
||||||
}
|
}
|
||||||
|
|
||||||
unsafe_prototype_function: {
|
prototype_function: {
|
||||||
options = {
|
options = {
|
||||||
evaluate : true,
|
evaluate: true,
|
||||||
unsafe : true
|
properties: true,
|
||||||
|
side_effects: true,
|
||||||
}
|
}
|
||||||
input: {
|
input: {
|
||||||
var a = ({valueOf: 0}) < 1;
|
var a = ({valueOf: 0}) < 1;
|
||||||
@@ -730,8 +753,8 @@ unsafe_prototype_function: {
|
|||||||
var d = ({toString: 0}) + "";
|
var d = ({toString: 0}) + "";
|
||||||
var e = (({valueOf: 0}) + "")[2];
|
var e = (({valueOf: 0}) + "")[2];
|
||||||
var f = (({toString: 0}) + "")[2];
|
var f = (({toString: 0}) + "")[2];
|
||||||
var g = ({valueOf: 0}).valueOf();
|
var g = 0();
|
||||||
var h = "" + ({toString: 0});
|
var h = 0();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -739,6 +762,7 @@ call_args: {
|
|||||||
options = {
|
options = {
|
||||||
evaluate: true,
|
evaluate: true,
|
||||||
inline: true,
|
inline: true,
|
||||||
|
reduce_funcs: true,
|
||||||
reduce_vars: true,
|
reduce_vars: true,
|
||||||
}
|
}
|
||||||
input: {
|
input: {
|
||||||
@@ -761,6 +785,7 @@ call_args_drop_param: {
|
|||||||
evaluate: true,
|
evaluate: true,
|
||||||
inline: true,
|
inline: true,
|
||||||
keep_fargs: false,
|
keep_fargs: false,
|
||||||
|
reduce_funcs: true,
|
||||||
reduce_vars: true,
|
reduce_vars: true,
|
||||||
unused: true,
|
unused: true,
|
||||||
}
|
}
|
||||||
@@ -1091,6 +1116,7 @@ Infinity_NaN_undefined_LHS: {
|
|||||||
issue_1964_1: {
|
issue_1964_1: {
|
||||||
options = {
|
options = {
|
||||||
evaluate: true,
|
evaluate: true,
|
||||||
|
reduce_funcs: true,
|
||||||
reduce_vars: true,
|
reduce_vars: true,
|
||||||
unsafe_regexp: false,
|
unsafe_regexp: false,
|
||||||
unused: true,
|
unused: true,
|
||||||
@@ -1098,6 +1124,7 @@ issue_1964_1: {
|
|||||||
input: {
|
input: {
|
||||||
function f() {
|
function f() {
|
||||||
var long_variable_name = /\s/;
|
var long_variable_name = /\s/;
|
||||||
|
console.log(long_variable_name.source);
|
||||||
return "a b c".split(long_variable_name)[1];
|
return "a b c".split(long_variable_name)[1];
|
||||||
}
|
}
|
||||||
console.log(f());
|
console.log(f());
|
||||||
@@ -1105,16 +1132,21 @@ issue_1964_1: {
|
|||||||
expect: {
|
expect: {
|
||||||
function f() {
|
function f() {
|
||||||
var long_variable_name = /\s/;
|
var long_variable_name = /\s/;
|
||||||
|
console.log(long_variable_name.source);
|
||||||
return "a b c".split(long_variable_name)[1];
|
return "a b c".split(long_variable_name)[1];
|
||||||
}
|
}
|
||||||
console.log(f());
|
console.log(f());
|
||||||
}
|
}
|
||||||
expect_stdout: "b"
|
expect_stdout: [
|
||||||
|
"\\s",
|
||||||
|
"b",
|
||||||
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
issue_1964_2: {
|
issue_1964_2: {
|
||||||
options = {
|
options = {
|
||||||
evaluate: true,
|
evaluate: true,
|
||||||
|
reduce_funcs: true,
|
||||||
reduce_vars: true,
|
reduce_vars: true,
|
||||||
unsafe_regexp: true,
|
unsafe_regexp: true,
|
||||||
unused: true,
|
unused: true,
|
||||||
@@ -1122,17 +1154,22 @@ issue_1964_2: {
|
|||||||
input: {
|
input: {
|
||||||
function f() {
|
function f() {
|
||||||
var long_variable_name = /\s/;
|
var long_variable_name = /\s/;
|
||||||
|
console.log(long_variable_name.source);
|
||||||
return "a b c".split(long_variable_name)[1];
|
return "a b c".split(long_variable_name)[1];
|
||||||
}
|
}
|
||||||
console.log(f());
|
console.log(f());
|
||||||
}
|
}
|
||||||
expect: {
|
expect: {
|
||||||
function f() {
|
function f() {
|
||||||
|
console.log(/\s/.source);
|
||||||
return "a b c".split(/\s/)[1];
|
return "a b c".split(/\s/)[1];
|
||||||
}
|
}
|
||||||
console.log(f());
|
console.log(f());
|
||||||
}
|
}
|
||||||
expect_stdout: "b"
|
expect_stdout: [
|
||||||
|
"\\s",
|
||||||
|
"b",
|
||||||
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
array_slice_index: {
|
array_slice_index: {
|
||||||
@@ -1162,3 +1199,142 @@ string_charCodeAt: {
|
|||||||
}
|
}
|
||||||
expect_stdout: "NaN"
|
expect_stdout: "NaN"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
issue_2207_1: {
|
||||||
|
options = {
|
||||||
|
evaluate: true,
|
||||||
|
unsafe: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
console.log(String.fromCharCode(65));
|
||||||
|
console.log(Math.max(3, 6, 2, 7, 3, 4));
|
||||||
|
console.log(Math.cos(1.2345));
|
||||||
|
console.log(Math.cos(1.2345) - Math.sin(4.321));
|
||||||
|
console.log(Math.pow(Math.PI, Math.E - Math.LN10));
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
console.log("A");
|
||||||
|
console.log(7);
|
||||||
|
console.log(Math.cos(1.2345));
|
||||||
|
console.log(1.2543732512566947);
|
||||||
|
console.log(1.6093984514472044);
|
||||||
|
}
|
||||||
|
expect_stdout: true
|
||||||
|
}
|
||||||
|
|
||||||
|
issue_2207_2: {
|
||||||
|
options = {
|
||||||
|
evaluate: true,
|
||||||
|
unsafe: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
console.log(Math.E);
|
||||||
|
console.log(Math.LN10);
|
||||||
|
console.log(Math.LN2);
|
||||||
|
console.log(Math.LOG2E);
|
||||||
|
console.log(Math.LOG10E);
|
||||||
|
console.log(Math.PI);
|
||||||
|
console.log(Math.SQRT1_2);
|
||||||
|
console.log(Math.SQRT2);
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
console.log(Math.E);
|
||||||
|
console.log(Math.LN10);
|
||||||
|
console.log(Math.LN2);
|
||||||
|
console.log(Math.LOG2E);
|
||||||
|
console.log(Math.LOG10E);
|
||||||
|
console.log(Math.PI);
|
||||||
|
console.log(Math.SQRT1_2);
|
||||||
|
console.log(Math.SQRT2);
|
||||||
|
}
|
||||||
|
expect_stdout: true
|
||||||
|
}
|
||||||
|
|
||||||
|
issue_2207_3: {
|
||||||
|
options = {
|
||||||
|
evaluate: true,
|
||||||
|
unsafe: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
console.log(Number.MAX_VALUE);
|
||||||
|
console.log(Number.MIN_VALUE);
|
||||||
|
console.log(Number.NaN);
|
||||||
|
console.log(Number.NEGATIVE_INFINITY);
|
||||||
|
console.log(Number.POSITIVE_INFINITY);
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
console.log(Number.MAX_VALUE);
|
||||||
|
console.log(5e-324);
|
||||||
|
console.log(NaN);
|
||||||
|
console.log(-1/0);
|
||||||
|
console.log(1/0);
|
||||||
|
}
|
||||||
|
expect_stdout: true
|
||||||
|
}
|
||||||
|
|
||||||
|
issue_2231_1: {
|
||||||
|
options = {
|
||||||
|
evaluate: true,
|
||||||
|
unsafe: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
console.log(Object.keys(void 0));
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
console.log(Object.keys(void 0));
|
||||||
|
}
|
||||||
|
expect_stdout: true
|
||||||
|
}
|
||||||
|
|
||||||
|
issue_2231_2: {
|
||||||
|
options = {
|
||||||
|
evaluate: true,
|
||||||
|
unsafe: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
console.log(Object.getOwnPropertyNames(null));
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
console.log(Object.getOwnPropertyNames(null));
|
||||||
|
}
|
||||||
|
expect_stdout: true
|
||||||
|
}
|
||||||
|
|
||||||
|
self_comparison_1: {
|
||||||
|
options = {
|
||||||
|
evaluate: true,
|
||||||
|
reduce_funcs: true,
|
||||||
|
reduce_vars: true,
|
||||||
|
toplevel: true,
|
||||||
|
unsafe: true,
|
||||||
|
unused: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
var o = { n: NaN };
|
||||||
|
console.log(o.n == o.n, o.n === o.n, o.n != o.n, o.n !== o.n, typeof o.n);
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
console.log(false, false, true, true, "number");
|
||||||
|
}
|
||||||
|
expect_stdout: "false false true true 'number'"
|
||||||
|
}
|
||||||
|
|
||||||
|
self_comparison_2: {
|
||||||
|
options = {
|
||||||
|
evaluate: true,
|
||||||
|
hoist_props: true,
|
||||||
|
passes: 2,
|
||||||
|
reduce_funcs: true,
|
||||||
|
reduce_vars: true,
|
||||||
|
toplevel: true,
|
||||||
|
unused: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
var o = { n: NaN };
|
||||||
|
console.log(o.n == o.n, o.n === o.n, o.n != o.n, o.n !== o.n, typeof o.n);
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
console.log(false, false, true, true, "number");
|
||||||
|
}
|
||||||
|
expect_stdout: "false false true true 'number'"
|
||||||
|
}
|
||||||
|
|||||||
@@ -26,3 +26,46 @@ expand_parameters: {
|
|||||||
expect_exact: "(function(a,...b){});(function(...args){});"
|
expect_exact: "(function(a,...b){});(function(...args){});"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
avoid_spread_in_ternary: {
|
||||||
|
options = {
|
||||||
|
comparisons: true,
|
||||||
|
conditionals: true,
|
||||||
|
evaluate: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
function print(...x) {
|
||||||
|
console.log(...x);
|
||||||
|
}
|
||||||
|
var a = [1, 2], b = [3, 4];
|
||||||
|
|
||||||
|
if (Math)
|
||||||
|
print(a);
|
||||||
|
else
|
||||||
|
print(b);
|
||||||
|
|
||||||
|
if (Math)
|
||||||
|
print(...a);
|
||||||
|
else
|
||||||
|
print(b);
|
||||||
|
|
||||||
|
if (Math.no_such_property)
|
||||||
|
print(a);
|
||||||
|
else
|
||||||
|
print(...b);
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
function print(...x) {
|
||||||
|
console.log(...x);
|
||||||
|
}
|
||||||
|
var a = [ 1, 2 ], b = [ 3, 4 ];
|
||||||
|
print(Math ? a : b);
|
||||||
|
Math ? print(...a) : print(b);
|
||||||
|
Math.no_such_property ? print(a) : print(...b);
|
||||||
|
}
|
||||||
|
expect_stdout: [
|
||||||
|
"[ 1, 2 ]",
|
||||||
|
"1 2",
|
||||||
|
"3 4",
|
||||||
|
]
|
||||||
|
node_version: ">=6"
|
||||||
|
}
|
||||||
|
|||||||
@@ -124,6 +124,7 @@ async_func: {
|
|||||||
issue_2134_1: {
|
issue_2134_1: {
|
||||||
options = {
|
options = {
|
||||||
keep_fargs: false,
|
keep_fargs: false,
|
||||||
|
reduce_funcs: true,
|
||||||
reduce_vars: true,
|
reduce_vars: true,
|
||||||
toplevel: true,
|
toplevel: true,
|
||||||
unused: true,
|
unused: true,
|
||||||
@@ -141,6 +142,7 @@ issue_2134_1: {
|
|||||||
issue_2134_2: {
|
issue_2134_2: {
|
||||||
options = {
|
options = {
|
||||||
keep_fargs: false,
|
keep_fargs: false,
|
||||||
|
reduce_funcs: true,
|
||||||
reduce_vars: true,
|
reduce_vars: true,
|
||||||
toplevel: true,
|
toplevel: true,
|
||||||
unused: true,
|
unused: true,
|
||||||
@@ -226,3 +228,37 @@ keyword_valid_3: {
|
|||||||
export { default as default } from "module.js";
|
export { default as default } from "module.js";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
dynamic_import: {
|
||||||
|
mangle = {
|
||||||
|
toplevel: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
import traditional from './traditional.js';
|
||||||
|
function imp(x) {
|
||||||
|
return import(x);
|
||||||
|
}
|
||||||
|
import("module_for_side_effects.js");
|
||||||
|
let dynamic = import("some/module.js");
|
||||||
|
dynamic.foo();
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
import o from "./traditional.js";
|
||||||
|
function t(o) {
|
||||||
|
return import(o);
|
||||||
|
}
|
||||||
|
import("module_for_side_effects.js");
|
||||||
|
let r = import("some/module.js");
|
||||||
|
r.foo();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
trailing_comma: {
|
||||||
|
beautify = {
|
||||||
|
beautify: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
export const a = 1;
|
||||||
|
}
|
||||||
|
expect_exact: "export const a = 1;"
|
||||||
|
}
|
||||||
|
|||||||
@@ -19,6 +19,7 @@ iifes_returning_constants_keep_fargs_true: {
|
|||||||
booleans : true,
|
booleans : true,
|
||||||
if_return : true,
|
if_return : true,
|
||||||
join_vars : true,
|
join_vars : true,
|
||||||
|
reduce_funcs : true,
|
||||||
reduce_vars : true,
|
reduce_vars : true,
|
||||||
cascade : true,
|
cascade : true,
|
||||||
inline : true,
|
inline : true,
|
||||||
@@ -55,6 +56,7 @@ iifes_returning_constants_keep_fargs_false: {
|
|||||||
booleans : true,
|
booleans : true,
|
||||||
if_return : true,
|
if_return : true,
|
||||||
join_vars : true,
|
join_vars : true,
|
||||||
|
reduce_funcs : true,
|
||||||
reduce_vars : true,
|
reduce_vars : true,
|
||||||
cascade : true,
|
cascade : true,
|
||||||
inline : true,
|
inline : true,
|
||||||
@@ -101,6 +103,7 @@ issue_1841_1: {
|
|||||||
options = {
|
options = {
|
||||||
keep_fargs: false,
|
keep_fargs: false,
|
||||||
pure_getters: "strict",
|
pure_getters: "strict",
|
||||||
|
reduce_funcs: true,
|
||||||
reduce_vars: true,
|
reduce_vars: true,
|
||||||
unused: true,
|
unused: true,
|
||||||
}
|
}
|
||||||
@@ -127,6 +130,7 @@ issue_1841_2: {
|
|||||||
options = {
|
options = {
|
||||||
keep_fargs: false,
|
keep_fargs: false,
|
||||||
pure_getters: false,
|
pure_getters: false,
|
||||||
|
reduce_funcs: true,
|
||||||
reduce_vars: true,
|
reduce_vars: true,
|
||||||
unused: true,
|
unused: true,
|
||||||
}
|
}
|
||||||
@@ -151,13 +155,14 @@ issue_1841_2: {
|
|||||||
|
|
||||||
function_returning_constant_literal: {
|
function_returning_constant_literal: {
|
||||||
options = {
|
options = {
|
||||||
reduce_vars: true,
|
|
||||||
unsafe: true,
|
|
||||||
toplevel: true,
|
|
||||||
evaluate: true,
|
|
||||||
cascade: true,
|
|
||||||
unused: true,
|
|
||||||
inline: true,
|
inline: true,
|
||||||
|
passes: 2,
|
||||||
|
properties: true,
|
||||||
|
reduce_funcs: true,
|
||||||
|
reduce_vars: true,
|
||||||
|
side_effects: true,
|
||||||
|
toplevel: true,
|
||||||
|
unused: true,
|
||||||
}
|
}
|
||||||
input: {
|
input: {
|
||||||
function greeter() {
|
function greeter() {
|
||||||
@@ -305,6 +310,7 @@ issue_2084: {
|
|||||||
evaluate: true,
|
evaluate: true,
|
||||||
inline: true,
|
inline: true,
|
||||||
passes: 2,
|
passes: 2,
|
||||||
|
reduce_funcs: true,
|
||||||
reduce_vars: true,
|
reduce_vars: true,
|
||||||
sequences: true,
|
sequences: true,
|
||||||
side_effects: true,
|
side_effects: true,
|
||||||
@@ -340,6 +346,7 @@ issue_2084: {
|
|||||||
issue_2097: {
|
issue_2097: {
|
||||||
options = {
|
options = {
|
||||||
negate_iife: true,
|
negate_iife: true,
|
||||||
|
reduce_funcs: true,
|
||||||
reduce_vars: true,
|
reduce_vars: true,
|
||||||
toplevel: true,
|
toplevel: true,
|
||||||
unused: true,
|
unused: true,
|
||||||
@@ -468,11 +475,9 @@ issue_2114_1: {
|
|||||||
}
|
}
|
||||||
expect: {
|
expect: {
|
||||||
var c = 0;
|
var c = 0;
|
||||||
!function() {
|
c = 1 + (c += 1), function() {
|
||||||
0;
|
|
||||||
}((c += 1, c = 1 + c, function() {
|
|
||||||
var b = void (b && (b.b += (c += 1, 0)));
|
var b = void (b && (b.b += (c += 1, 0)));
|
||||||
}()));
|
}();
|
||||||
console.log(c);
|
console.log(c);
|
||||||
}
|
}
|
||||||
expect_stdout: "2"
|
expect_stdout: "2"
|
||||||
@@ -510,3 +515,42 @@ issue_2114_2: {
|
|||||||
}
|
}
|
||||||
expect_stdout: "2"
|
expect_stdout: "2"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
issue_2428: {
|
||||||
|
options = {
|
||||||
|
collapse_vars: true,
|
||||||
|
inline: true,
|
||||||
|
passes: 3,
|
||||||
|
pure_getters: "strict",
|
||||||
|
reduce_funcs: true,
|
||||||
|
reduce_vars: true,
|
||||||
|
side_effects: true,
|
||||||
|
toplevel: true,
|
||||||
|
unsafe: true,
|
||||||
|
unused: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
function bar(k) {
|
||||||
|
console.log(k);
|
||||||
|
}
|
||||||
|
function foo(x) {
|
||||||
|
return bar(x);
|
||||||
|
}
|
||||||
|
function baz(a) {
|
||||||
|
foo(a);
|
||||||
|
}
|
||||||
|
baz(42);
|
||||||
|
baz("PASS");
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
function baz(a) {
|
||||||
|
console.log(a);
|
||||||
|
}
|
||||||
|
baz(42);
|
||||||
|
baz("PASS");
|
||||||
|
}
|
||||||
|
expect_stdout: [
|
||||||
|
"42",
|
||||||
|
"PASS",
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|||||||
@@ -37,6 +37,7 @@ object: {
|
|||||||
VALUE: 42,
|
VALUE: 42,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
side_effects: true,
|
||||||
unsafe: true,
|
unsafe: true,
|
||||||
}
|
}
|
||||||
input: {
|
input: {
|
||||||
@@ -140,9 +141,9 @@ mixed: {
|
|||||||
console.log(CONFIG);
|
console.log(CONFIG);
|
||||||
}
|
}
|
||||||
expect_warnings: [
|
expect_warnings: [
|
||||||
'WARN: global_defs CONFIG.VALUE redefined [test/compress/global_defs.js:126,22]',
|
|
||||||
'WARN: global_defs CONFIG.VALUE redefined [test/compress/global_defs.js:127,22]',
|
'WARN: global_defs CONFIG.VALUE redefined [test/compress/global_defs.js:127,22]',
|
||||||
'WARN: global_defs CONFIG.VALUE redefined [test/compress/global_defs.js:129,8]',
|
'WARN: global_defs CONFIG.VALUE redefined [test/compress/global_defs.js:128,22]',
|
||||||
|
'WARN: global_defs CONFIG.VALUE redefined [test/compress/global_defs.js:130,8]',
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -211,13 +211,13 @@ export_statement: {
|
|||||||
}
|
}
|
||||||
input: {
|
input: {
|
||||||
export default 1 + 2;
|
export default 1 + 2;
|
||||||
export var foo = 4;
|
export var a = 4;
|
||||||
export let foo = 6;
|
export let b = 6;
|
||||||
export const foo = 6;
|
export const c = 6;
|
||||||
export function foo() {};
|
export function d() {};
|
||||||
export class foo { };
|
export class e {};
|
||||||
}
|
}
|
||||||
expect_exact: "export default 3;export var foo=4;export let foo=6;export const foo=6;export function foo(){};export class foo{};"
|
expect_exact: "export default 3;export var a=4;export let b=6;export const c=6;export function d(){};export class e{};"
|
||||||
}
|
}
|
||||||
|
|
||||||
export_default_object_expression: {
|
export_default_object_expression: {
|
||||||
@@ -695,3 +695,460 @@ export_default_class_decl: {
|
|||||||
}
|
}
|
||||||
expect_exact: "export default class Car{};export class Cab{};"
|
expect_exact: "export default class Car{};export class Cab{};"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
object_rest_spread: {
|
||||||
|
mangle = {
|
||||||
|
toplevel: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
var { w: w1, ...V } = { w: 7, x: 1, y: 2 }; console.log(w1, V);
|
||||||
|
let { w: w2, ...L } = { w: 8, x: 3, y: 4 }; console.log(w2, L);
|
||||||
|
const { w: w3, ...C } = { w: 9, x: 5, y: 6 }; console.log(w3, C);
|
||||||
|
|
||||||
|
let b;
|
||||||
|
({ b, ...V } = { a: 1, b: 2, c: 3 }); console.log(V);
|
||||||
|
({ b, ...L } = { a: 4, b: 5, c: 6 }); console.log(L);
|
||||||
|
|
||||||
|
(function({ y, ...p }){ console.log(p); })({ x: 1, y: 2, z: 3 });
|
||||||
|
(({ y, ...p }) => { console.log(p); })({ x: 4, y: 5, z: 6 });
|
||||||
|
|
||||||
|
const T = { a: 1, b: 2 }; console.log({ ...T, w: 0, ...{}, ...L, ...{K: 9} });
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
var { w: o, ...l } = { w: 7, x: 1, y: 2 }; console.log(o, l);
|
||||||
|
let { w: c, ...n } = { w: 8, x: 3, y: 4 }; console.log(c, n);
|
||||||
|
const { w: e, ...s } = { w: 9, x: 5, y: 6 }; console.log(e, s);
|
||||||
|
|
||||||
|
let g;
|
||||||
|
({ b: g, ...l } = { a: 1, b: 2, c: 3 }); console.log(l);
|
||||||
|
({ b: g, ...n } = { a: 4, b: 5, c: 6 }); console.log(n);
|
||||||
|
|
||||||
|
(function({ y: o, ...l }) { console.log(l); })({ x: 1, y: 2, z: 3 });
|
||||||
|
(({ y: o, ...l }) => { console.log(l); })({ x: 4, y: 5, z: 6 });
|
||||||
|
|
||||||
|
const w = { a: 1, b: 2 }; console.log({ ...w, w: 0, ...{}, ...n, ...{ K: 9 } });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
object_spread_unsafe: {
|
||||||
|
options = {
|
||||||
|
collapse_vars: true,
|
||||||
|
evaluate: true,
|
||||||
|
join_vars: true,
|
||||||
|
passes: 3,
|
||||||
|
reduce_funcs: true,
|
||||||
|
reduce_vars: true,
|
||||||
|
side_effects: true,
|
||||||
|
toplevel: true,
|
||||||
|
unsafe: true,
|
||||||
|
unused: true,
|
||||||
|
}
|
||||||
|
mangle = {
|
||||||
|
toplevel: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
var o1 = { x: 1, y: 2 };
|
||||||
|
var o2 = { x: 3, z: 4 };
|
||||||
|
var cloned = { ...o1 };
|
||||||
|
var merged = { ...o1, ...o2 };
|
||||||
|
console.log(cloned, merged);
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
var o = { x: 1, y: 2 }, l = { ...o }, x = { ...o, ...{ x: 3, z: 4 } };
|
||||||
|
console.log(l, x);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
array_spread_of_sequence: {
|
||||||
|
mangle = {
|
||||||
|
toplevel: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
var a = [1];
|
||||||
|
console.log([...(a, a)]);
|
||||||
|
console.log([...a, a]);
|
||||||
|
console.log([...(a || a)]);
|
||||||
|
console.log([...a || a]);
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
var o = [1];
|
||||||
|
console.log([...(o, o)]);
|
||||||
|
console.log([...o, o]);
|
||||||
|
console.log([...o || o]);
|
||||||
|
console.log([...o || o]);
|
||||||
|
}
|
||||||
|
expect_stdout: [
|
||||||
|
"[ 1 ]",
|
||||||
|
"[ 1, [ 1 ] ]",
|
||||||
|
"[ 1 ]",
|
||||||
|
"[ 1 ]",
|
||||||
|
]
|
||||||
|
node_version: ">=6"
|
||||||
|
}
|
||||||
|
|
||||||
|
object_spread_of_sequence: {
|
||||||
|
mangle = {
|
||||||
|
toplevel: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
var a = {x: 1};
|
||||||
|
console.log({ ...(a, a) });
|
||||||
|
console.log({ ...a, a });
|
||||||
|
console.log({ ...(a || a) });
|
||||||
|
console.log({ ...a || a });
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
var o = { x: 1 };
|
||||||
|
console.log({ ...(o, o) });
|
||||||
|
console.log({ ...o, a: o });
|
||||||
|
console.log({ ...o || o });
|
||||||
|
console.log({ ...o || o });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// issue 2316
|
||||||
|
class_name_can_be_preserved_with_reserved: {
|
||||||
|
mangle = {
|
||||||
|
reserved: [ "Foo" ],
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
function x() {
|
||||||
|
class Foo {}
|
||||||
|
Foo.bar;
|
||||||
|
class Bar {}
|
||||||
|
Bar.foo;
|
||||||
|
}
|
||||||
|
function y() {
|
||||||
|
var Foo = class Foo {};
|
||||||
|
Foo.bar;
|
||||||
|
var Bar = class Bar {};
|
||||||
|
Bar.bar;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
function x() {
|
||||||
|
class Foo {}
|
||||||
|
Foo.bar;
|
||||||
|
class a {}
|
||||||
|
a.foo;
|
||||||
|
}
|
||||||
|
function y() {
|
||||||
|
var Foo = class Foo {};
|
||||||
|
Foo.bar;
|
||||||
|
var a = class a {};
|
||||||
|
a.bar;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
issue_2345: {
|
||||||
|
options = {
|
||||||
|
evaluate: true,
|
||||||
|
side_effects: true,
|
||||||
|
unsafe: true,
|
||||||
|
unused: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
console.log([...[3, 2, 1]].join("-"));
|
||||||
|
var a = [3, 2, 1];
|
||||||
|
console.log([...a].join("-"));
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
console.log([...[3, 2, 1]].join("-"));
|
||||||
|
var a = [3, 2, 1];
|
||||||
|
console.log([...a].join("-"));
|
||||||
|
}
|
||||||
|
expect_stdout: [
|
||||||
|
"3-2-1",
|
||||||
|
"3-2-1",
|
||||||
|
]
|
||||||
|
node_version: ">=6"
|
||||||
|
}
|
||||||
|
|
||||||
|
issue_2349: {
|
||||||
|
mangle = {}
|
||||||
|
input: {
|
||||||
|
function foo(boo, key) {
|
||||||
|
const value = boo.get();
|
||||||
|
return value.map(({[key]: bar}) => bar);
|
||||||
|
}
|
||||||
|
console.log(foo({
|
||||||
|
get: () => [ {
|
||||||
|
blah: 42
|
||||||
|
} ]
|
||||||
|
}, "blah"));
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
function foo(o, n) {
|
||||||
|
const t = o.get();
|
||||||
|
return t.map(({[n]: o}) => o);
|
||||||
|
}
|
||||||
|
console.log(foo({
|
||||||
|
get: () => [ {
|
||||||
|
blah: 42
|
||||||
|
} ]
|
||||||
|
}, "blah"));
|
||||||
|
}
|
||||||
|
expect_stdout: [
|
||||||
|
"[ 42 ]",
|
||||||
|
]
|
||||||
|
node_version: ">=7"
|
||||||
|
}
|
||||||
|
|
||||||
|
issue_2349b: {
|
||||||
|
options = {
|
||||||
|
arrows: true,
|
||||||
|
collapse_vars: true,
|
||||||
|
ecma: 6,
|
||||||
|
evaluate: true,
|
||||||
|
inline: true,
|
||||||
|
passes: 3,
|
||||||
|
properties: true,
|
||||||
|
reduce_funcs: true,
|
||||||
|
reduce_vars: true,
|
||||||
|
toplevel: true,
|
||||||
|
side_effects: true,
|
||||||
|
unsafe_arrows: true,
|
||||||
|
unused: true,
|
||||||
|
}
|
||||||
|
mangle = {
|
||||||
|
toplevel: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
function foo(boo, key) {
|
||||||
|
const value = boo.get();
|
||||||
|
return value.map(function({[key]: bar}){ return bar; });
|
||||||
|
}
|
||||||
|
console.log(foo({
|
||||||
|
get: function() {
|
||||||
|
return [ {
|
||||||
|
blah: 42
|
||||||
|
} ];
|
||||||
|
}
|
||||||
|
}, "blah"));
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
console.log([ {
|
||||||
|
blah: 42
|
||||||
|
} ].map(({["blah"]: l}) => l));
|
||||||
|
}
|
||||||
|
expect_stdout: [
|
||||||
|
"[ 42 ]",
|
||||||
|
]
|
||||||
|
node_version: ">=7"
|
||||||
|
}
|
||||||
|
|
||||||
|
shorthand_keywords: {
|
||||||
|
beautify = {
|
||||||
|
ecma: 6,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
var foo = 0,
|
||||||
|
async = 1,
|
||||||
|
await = 2,
|
||||||
|
implements = 3,
|
||||||
|
package = 4,
|
||||||
|
private = 5,
|
||||||
|
protected = 6,
|
||||||
|
static = 7,
|
||||||
|
yield = 8;
|
||||||
|
console.log({
|
||||||
|
foo: foo,
|
||||||
|
0: 0,
|
||||||
|
NaN: NaN,
|
||||||
|
async: async,
|
||||||
|
await: await,
|
||||||
|
false: false,
|
||||||
|
implements: implements,
|
||||||
|
null: null,
|
||||||
|
package: package,
|
||||||
|
private: private,
|
||||||
|
protected: protected,
|
||||||
|
static: static,
|
||||||
|
this: this,
|
||||||
|
true: true,
|
||||||
|
undefined: undefined,
|
||||||
|
yield: yield,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
expect_exact: "var foo=0,async=1,await=2,implements=3,package=4,private=5,protected=6,static=7,yield=8;console.log({foo,0:0,NaN:NaN,async,await,false:false,implements:implements,null:null,package:package,private:private,protected:protected,static:static,this:this,true:true,undefined:void 0,yield});"
|
||||||
|
expect_stdout: true
|
||||||
|
node_version: ">=4"
|
||||||
|
}
|
||||||
|
|
||||||
|
array_literal_with_spread_1: {
|
||||||
|
options = {
|
||||||
|
properties: true,
|
||||||
|
side_effects: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
var f = (x) => [...x][0];
|
||||||
|
console.log(f(["PASS"]));
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
var f = x => [ ...x ][0];
|
||||||
|
console.log(f([ "PASS" ]));
|
||||||
|
}
|
||||||
|
expect_stdout: "PASS"
|
||||||
|
node_version: ">=6"
|
||||||
|
}
|
||||||
|
|
||||||
|
array_literal_with_spread_2: {
|
||||||
|
options = {
|
||||||
|
properties: true,
|
||||||
|
side_effects: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
console.log([10, ...[], 20, ...[30, 40], 50]["length"]);
|
||||||
|
console.log([10, ...[], 20, ...[30, 40], 50][0]);
|
||||||
|
console.log([10, ...[], 20, ...[30, 40], 50][1]);
|
||||||
|
console.log([10, ...[], 20, ...[30, 40], 50][2]);
|
||||||
|
console.log([10, ...[], 20, ...[30, 40], 50][3]);
|
||||||
|
console.log([10, ...[], 20, ...[30, 40], 50][4]);
|
||||||
|
console.log([10, ...[], 20, ...[30, 40], 50][5]);
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
console.log([ 10, ...[], 20, ...[ 30, 40 ], 50 ]["length"]);
|
||||||
|
console.log(10);
|
||||||
|
console.log([ 10, ...[], 20, ...[ 30, 40 ], 50 ][1]);
|
||||||
|
console.log([ 10, ...[], 20, ...[ 30, 40 ], 50 ][2]);
|
||||||
|
console.log([ 10, ...[], 20, ...[ 30, 40 ], 50 ][3]);
|
||||||
|
console.log([ 10, ...[], 20, ...[ 30, 40 ], 50 ][4]);
|
||||||
|
console.log([ 10, ...[], 20, ...[ 30, 40 ], 50 ][5]);
|
||||||
|
}
|
||||||
|
expect_stdout: [
|
||||||
|
"5",
|
||||||
|
"10",
|
||||||
|
"20",
|
||||||
|
"30",
|
||||||
|
"40",
|
||||||
|
"50",
|
||||||
|
"undefined",
|
||||||
|
]
|
||||||
|
node_version: ">=6"
|
||||||
|
}
|
||||||
|
|
||||||
|
array_literal_with_spread_3: {
|
||||||
|
options = {
|
||||||
|
properties: true,
|
||||||
|
side_effects: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
console.log([10, 20][0]);
|
||||||
|
console.log([10, 20][1]);
|
||||||
|
console.log([10, 20][2]);
|
||||||
|
|
||||||
|
console.log([...[], 10, 20][0]);
|
||||||
|
console.log([...[], 10, 20][1]);
|
||||||
|
console.log([...[], 10, 20][2]);
|
||||||
|
|
||||||
|
console.log([10, ...[], 20][0]);
|
||||||
|
console.log([10, ...[], 20][1]);
|
||||||
|
console.log([10, ...[], 20][2]);
|
||||||
|
|
||||||
|
console.log([10, 20, ...[]][0]);
|
||||||
|
console.log([10, 20, ...[]][1]);
|
||||||
|
console.log([10, 20, ...[]][2]);
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
console.log(10);
|
||||||
|
console.log(20);
|
||||||
|
console.log([ 10, 20 ][2]);
|
||||||
|
|
||||||
|
console.log([...[], 10, 20][0]);
|
||||||
|
console.log([...[], 10, 20][1]);
|
||||||
|
console.log([...[], 10, 20][2]);
|
||||||
|
|
||||||
|
console.log(10);
|
||||||
|
console.log([10, ...[], 20][1]);
|
||||||
|
console.log([10, ...[], 20][2]);
|
||||||
|
|
||||||
|
console.log(10);
|
||||||
|
console.log(20);
|
||||||
|
console.log([10, 20, ...[]][2]);
|
||||||
|
}
|
||||||
|
expect_stdout: [
|
||||||
|
"10",
|
||||||
|
"20",
|
||||||
|
"undefined",
|
||||||
|
"10",
|
||||||
|
"20",
|
||||||
|
"undefined",
|
||||||
|
"10",
|
||||||
|
"20",
|
||||||
|
"undefined",
|
||||||
|
"10",
|
||||||
|
"20",
|
||||||
|
"undefined",
|
||||||
|
]
|
||||||
|
node_version: ">=6"
|
||||||
|
}
|
||||||
|
|
||||||
|
array_literal_with_spread_4: {
|
||||||
|
options = {
|
||||||
|
properties: true,
|
||||||
|
side_effects: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
function t(x) {
|
||||||
|
console.log("(" + x + ")");
|
||||||
|
return 10 * x;
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log([t(1), t(2)][0]);
|
||||||
|
console.log([t(1), t(2)][1]);
|
||||||
|
console.log([t(1), t(2)][2]);
|
||||||
|
|
||||||
|
console.log([...[], t(1), t(2)][0]);
|
||||||
|
console.log([...[], t(1), t(2)][1]);
|
||||||
|
console.log([...[], t(1), t(2)][2]);
|
||||||
|
|
||||||
|
console.log([t(1), ...[], t(2)][0]);
|
||||||
|
console.log([t(1), ...[], t(2)][1]);
|
||||||
|
console.log([t(1), ...[], t(2)][2]);
|
||||||
|
|
||||||
|
console.log([t(1), t(2), ...[]][0]);
|
||||||
|
console.log([t(1), t(2), ...[]][1]);
|
||||||
|
console.log([t(1), t(2), ...[]][2]);
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
function t(x) {
|
||||||
|
console.log("(" + x + ")");
|
||||||
|
return 10 * x;
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log([ t(1), t(2) ][0]);
|
||||||
|
console.log((t(1), t(2)));
|
||||||
|
console.log([ t(1), t(2) ][2]);
|
||||||
|
|
||||||
|
console.log([ ...[], t(1), t(2) ][0]);
|
||||||
|
console.log([ ...[], t(1), t(2) ][1]);
|
||||||
|
console.log([ ...[], t(1), t(2) ][2]);
|
||||||
|
|
||||||
|
console.log([ t(1), t(2) ][0]);
|
||||||
|
console.log([ t(1), ...[], t(2) ][1]);
|
||||||
|
console.log([ t(1), ...[], t(2) ][2]);
|
||||||
|
|
||||||
|
console.log([ t(1), t(2) ][0]);
|
||||||
|
console.log((t(1), t(2)));
|
||||||
|
console.log([ t(1), t(2), ...[] ][2]);
|
||||||
|
}
|
||||||
|
expect_stdout: [
|
||||||
|
"(1)", "(2)", "10",
|
||||||
|
"(1)", "(2)", "20",
|
||||||
|
"(1)", "(2)", "undefined",
|
||||||
|
|
||||||
|
"(1)", "(2)", "10",
|
||||||
|
"(1)", "(2)", "20",
|
||||||
|
"(1)", "(2)", "undefined",
|
||||||
|
|
||||||
|
"(1)", "(2)", "10",
|
||||||
|
"(1)", "(2)", "20",
|
||||||
|
"(1)", "(2)", "undefined",
|
||||||
|
|
||||||
|
"(1)", "(2)", "10",
|
||||||
|
"(1)", "(2)", "20",
|
||||||
|
"(1)", "(2)", "undefined",
|
||||||
|
]
|
||||||
|
node_version: ">=6"
|
||||||
|
}
|
||||||
|
|||||||
774
test/compress/hoist_props.js
Normal file
774
test/compress/hoist_props.js
Normal file
@@ -0,0 +1,774 @@
|
|||||||
|
issue_2377_1: {
|
||||||
|
options = {
|
||||||
|
evaluate: true,
|
||||||
|
inline: true,
|
||||||
|
hoist_props: true,
|
||||||
|
reduce_funcs: true,
|
||||||
|
reduce_vars: true,
|
||||||
|
toplevel: true,
|
||||||
|
unused: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
var obj = {
|
||||||
|
foo: 1,
|
||||||
|
bar: 2,
|
||||||
|
square: function(x) {
|
||||||
|
return x * x;
|
||||||
|
},
|
||||||
|
cube: function(x) {
|
||||||
|
return x * x * x;
|
||||||
|
},
|
||||||
|
};
|
||||||
|
console.log(obj.foo, obj.cube(3));
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
var obj_foo = 1, obj_cube = function(x) {
|
||||||
|
return x * x * x;
|
||||||
|
};
|
||||||
|
console.log(obj_foo, obj_cube(3));
|
||||||
|
}
|
||||||
|
expect_stdout: "1 27"
|
||||||
|
}
|
||||||
|
|
||||||
|
issue_2377_2: {
|
||||||
|
options = {
|
||||||
|
evaluate: true,
|
||||||
|
inline: true,
|
||||||
|
hoist_props: true,
|
||||||
|
passes: 2,
|
||||||
|
reduce_funcs: true,
|
||||||
|
reduce_vars: true,
|
||||||
|
toplevel: true,
|
||||||
|
unused: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
var obj = {
|
||||||
|
foo: 1,
|
||||||
|
bar: 2,
|
||||||
|
square: function(x) {
|
||||||
|
return x * x;
|
||||||
|
},
|
||||||
|
cube: function(x) {
|
||||||
|
return x * x * x;
|
||||||
|
},
|
||||||
|
};
|
||||||
|
console.log(obj.foo, obj.cube(3));
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
console.log(1, function(x) {
|
||||||
|
return x * x * x;
|
||||||
|
}(3));
|
||||||
|
}
|
||||||
|
expect_stdout: "1 27"
|
||||||
|
}
|
||||||
|
|
||||||
|
issue_2377_3: {
|
||||||
|
options = {
|
||||||
|
evaluate: true,
|
||||||
|
inline: true,
|
||||||
|
hoist_props: true,
|
||||||
|
passes: 3,
|
||||||
|
reduce_funcs: true,
|
||||||
|
reduce_vars: true,
|
||||||
|
toplevel: true,
|
||||||
|
unused: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
var obj = {
|
||||||
|
foo: 1,
|
||||||
|
bar: 2,
|
||||||
|
square: function(x) {
|
||||||
|
return x * x;
|
||||||
|
},
|
||||||
|
cube: function(x) {
|
||||||
|
return x * x * x;
|
||||||
|
},
|
||||||
|
};
|
||||||
|
console.log(obj.foo, obj.cube(3));
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
console.log(1, 27);
|
||||||
|
}
|
||||||
|
expect_stdout: "1 27"
|
||||||
|
}
|
||||||
|
|
||||||
|
direct_access_1: {
|
||||||
|
options = {
|
||||||
|
hoist_props: true,
|
||||||
|
reduce_funcs: true,
|
||||||
|
reduce_vars: true,
|
||||||
|
toplevel: true,
|
||||||
|
unused: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
var a = 0;
|
||||||
|
var obj = {
|
||||||
|
a: 1,
|
||||||
|
b: 2,
|
||||||
|
};
|
||||||
|
for (var k in obj) a++;
|
||||||
|
console.log(a, obj.a);
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
var a = 0;
|
||||||
|
var obj = {
|
||||||
|
a: 1,
|
||||||
|
b: 2,
|
||||||
|
};
|
||||||
|
for (var k in obj) a++;
|
||||||
|
console.log(a, obj.a);
|
||||||
|
}
|
||||||
|
expect_stdout: "2 1"
|
||||||
|
}
|
||||||
|
|
||||||
|
direct_access_2: {
|
||||||
|
options = {
|
||||||
|
hoist_props: true,
|
||||||
|
reduce_funcs: true,
|
||||||
|
reduce_vars: true,
|
||||||
|
toplevel: true,
|
||||||
|
unused: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
var o = { a: 1 };
|
||||||
|
var f = function(k) {
|
||||||
|
if (o[k]) return "PASS";
|
||||||
|
};
|
||||||
|
console.log(f("a"));
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
var o = { a: 1 };
|
||||||
|
console.log(function(k) {
|
||||||
|
if (o[k]) return "PASS";
|
||||||
|
}("a"));
|
||||||
|
}
|
||||||
|
expect_stdout: "PASS"
|
||||||
|
}
|
||||||
|
|
||||||
|
direct_access_3: {
|
||||||
|
options = {
|
||||||
|
hoist_props: true,
|
||||||
|
reduce_funcs: true,
|
||||||
|
reduce_vars: true,
|
||||||
|
toplevel: true,
|
||||||
|
unused: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
var o = { a: 1 };
|
||||||
|
o.b;
|
||||||
|
console.log(o.a);
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
var o = { a: 1 };
|
||||||
|
o.b;
|
||||||
|
console.log(o.a);
|
||||||
|
}
|
||||||
|
expect_stdout: "1"
|
||||||
|
}
|
||||||
|
|
||||||
|
single_use: {
|
||||||
|
options = {
|
||||||
|
hoist_props: true,
|
||||||
|
reduce_funcs: true,
|
||||||
|
reduce_vars: true,
|
||||||
|
toplevel: true,
|
||||||
|
unused: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
var obj = {
|
||||||
|
bar: function() {
|
||||||
|
return 42;
|
||||||
|
},
|
||||||
|
};
|
||||||
|
console.log(obj.bar());
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
console.log({
|
||||||
|
bar: function() {
|
||||||
|
return 42;
|
||||||
|
},
|
||||||
|
}.bar());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
name_collision_1: {
|
||||||
|
options = {
|
||||||
|
hoist_props: true,
|
||||||
|
reduce_funcs: true,
|
||||||
|
reduce_vars: true,
|
||||||
|
toplevel: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
var obj_foo = 1;
|
||||||
|
var obj_bar = 2;
|
||||||
|
function f() {
|
||||||
|
var obj = {
|
||||||
|
foo: 3,
|
||||||
|
bar: 4,
|
||||||
|
"b-r": 5,
|
||||||
|
"b+r": 6,
|
||||||
|
"b!r": 7,
|
||||||
|
};
|
||||||
|
console.log(obj_foo, obj.foo, obj.bar, obj["b-r"], obj["b+r"], obj["b!r"]);
|
||||||
|
}
|
||||||
|
f();
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
var obj_foo = 1;
|
||||||
|
var obj_bar = 2;
|
||||||
|
function f() {
|
||||||
|
var obj_foo$0 = 3,
|
||||||
|
obj_bar = 4,
|
||||||
|
obj_b_r = 5,
|
||||||
|
obj_b_r$0 = 6,
|
||||||
|
obj_b_r$1 = 7;
|
||||||
|
console.log(obj_foo, obj_foo$0, obj_bar, obj_b_r, obj_b_r$0, obj_b_r$1);
|
||||||
|
}
|
||||||
|
f();
|
||||||
|
}
|
||||||
|
expect_stdout: "1 3 4 5 6 7"
|
||||||
|
}
|
||||||
|
|
||||||
|
name_collision_2: {
|
||||||
|
options = {
|
||||||
|
hoist_props: true,
|
||||||
|
reduce_funcs: true,
|
||||||
|
reduce_vars: true,
|
||||||
|
toplevel: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
var o = {
|
||||||
|
p: 1,
|
||||||
|
0: function(x) {
|
||||||
|
return x;
|
||||||
|
},
|
||||||
|
1: function(x) {
|
||||||
|
return x + 1;
|
||||||
|
}
|
||||||
|
}, o__$0 = 2, o__$1 = 3;
|
||||||
|
console.log(o.p === o.p, o[0](4), o[1](5), o__$0, o__$1);
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
var o_p = 1,
|
||||||
|
o__ = function(x) {
|
||||||
|
return x;
|
||||||
|
},
|
||||||
|
o__$2 = function(x) {
|
||||||
|
return x + 1;
|
||||||
|
},
|
||||||
|
o__$0 = 2,
|
||||||
|
o__$1 = 3;
|
||||||
|
console.log(o_p === o_p, o__(4), o__$2(5), o__$0, o__$1);
|
||||||
|
}
|
||||||
|
expect_stdout: "true 4 6 2 3"
|
||||||
|
}
|
||||||
|
|
||||||
|
name_collision_3: {
|
||||||
|
options = {
|
||||||
|
hoist_props: true,
|
||||||
|
reduce_funcs: true,
|
||||||
|
reduce_vars: true,
|
||||||
|
toplevel: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
var o = {
|
||||||
|
p: 1,
|
||||||
|
0: function(x) {
|
||||||
|
return x;
|
||||||
|
},
|
||||||
|
1: function(x) {
|
||||||
|
return x + 1;
|
||||||
|
}
|
||||||
|
}, o__$0 = 2, o__$1 = 3;
|
||||||
|
console.log(o.p === o.p, o[0](4), o[1](5));
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
var o_p = 1,
|
||||||
|
o__ = function(x) {
|
||||||
|
return x;
|
||||||
|
},
|
||||||
|
o__$2 = function(x) {
|
||||||
|
return x + 1;
|
||||||
|
},
|
||||||
|
o__$0 = 2,
|
||||||
|
o__$1 = 3;
|
||||||
|
console.log(o_p === o_p, o__(4), o__$2(5));
|
||||||
|
}
|
||||||
|
expect_stdout: "true 4 6"
|
||||||
|
}
|
||||||
|
|
||||||
|
contains_this_1: {
|
||||||
|
options = {
|
||||||
|
evaluate: true,
|
||||||
|
hoist_props: true,
|
||||||
|
inline: true,
|
||||||
|
passes: 2,
|
||||||
|
reduce_funcs: true,
|
||||||
|
reduce_vars: true,
|
||||||
|
toplevel: true,
|
||||||
|
unused: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
var o = {
|
||||||
|
u: function() {
|
||||||
|
return this === this;
|
||||||
|
},
|
||||||
|
p: 1
|
||||||
|
};
|
||||||
|
console.log(o.p, o.p);
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
console.log(1, 1);
|
||||||
|
}
|
||||||
|
expect_stdout: "1 1"
|
||||||
|
}
|
||||||
|
|
||||||
|
contains_this_2: {
|
||||||
|
options = {
|
||||||
|
evaluate: true,
|
||||||
|
hoist_props: true,
|
||||||
|
inline: true,
|
||||||
|
passes: 2,
|
||||||
|
reduce_funcs: true,
|
||||||
|
reduce_vars: true,
|
||||||
|
toplevel: true,
|
||||||
|
unused: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
var o = {
|
||||||
|
u: function() {
|
||||||
|
return this === this;
|
||||||
|
},
|
||||||
|
p: 1
|
||||||
|
};
|
||||||
|
console.log(o.p, o.p, o.u);
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
console.log(1, 1, function() {
|
||||||
|
return this === this;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
expect_stdout: true
|
||||||
|
}
|
||||||
|
|
||||||
|
contains_this_3: {
|
||||||
|
options = {
|
||||||
|
evaluate: true,
|
||||||
|
hoist_props: true,
|
||||||
|
inline: true,
|
||||||
|
passes: 2,
|
||||||
|
reduce_funcs: true,
|
||||||
|
reduce_vars: true,
|
||||||
|
toplevel: true,
|
||||||
|
unused: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
var o = {
|
||||||
|
u: function() {
|
||||||
|
return this === this;
|
||||||
|
},
|
||||||
|
p: 1
|
||||||
|
};
|
||||||
|
console.log(o.p, o.p, o.u());
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
var o = {
|
||||||
|
u: function() {
|
||||||
|
return this === this;
|
||||||
|
},
|
||||||
|
p: 1
|
||||||
|
};
|
||||||
|
console.log(o.p, o.p, o.u());
|
||||||
|
}
|
||||||
|
expect_stdout: "1 1 true"
|
||||||
|
}
|
||||||
|
|
||||||
|
hoist_class: {
|
||||||
|
options = {
|
||||||
|
comparisons: true,
|
||||||
|
evaluate: true,
|
||||||
|
hoist_props: true,
|
||||||
|
inline: true,
|
||||||
|
keep_classnames: true,
|
||||||
|
keep_fnames: true,
|
||||||
|
passes: 2,
|
||||||
|
reduce_funcs: true,
|
||||||
|
reduce_vars: true,
|
||||||
|
toplevel: true,
|
||||||
|
unused: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
function run(c, v) {
|
||||||
|
return new c(v).value;
|
||||||
|
}
|
||||||
|
var o = {
|
||||||
|
p: class Foo {
|
||||||
|
constructor(value) {
|
||||||
|
this.value = value * 10;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
x: 1,
|
||||||
|
y: 2,
|
||||||
|
};
|
||||||
|
console.log(o.p.name, o.p === o.p, run(o.p, o.x), run(o.p, o.y));
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
function run(c, v) {
|
||||||
|
return new c(v).value;
|
||||||
|
}
|
||||||
|
var o_p = class Foo {
|
||||||
|
constructor(value) {
|
||||||
|
this.value = 10 * value;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
console.log(o_p.name, true, run(o_p, 1), run(o_p, 2));
|
||||||
|
}
|
||||||
|
node_version: ">=6"
|
||||||
|
expect_stdout: "Foo true 10 20"
|
||||||
|
}
|
||||||
|
|
||||||
|
hoist_class_with_new: {
|
||||||
|
options = {
|
||||||
|
comparisons: true,
|
||||||
|
evaluate: true,
|
||||||
|
hoist_props: true,
|
||||||
|
inline: true,
|
||||||
|
keep_classnames: true,
|
||||||
|
keep_fnames: true,
|
||||||
|
passes: 2,
|
||||||
|
reduce_funcs: true,
|
||||||
|
reduce_vars: true,
|
||||||
|
toplevel: true,
|
||||||
|
unused: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
var o = {
|
||||||
|
p: class Foo {
|
||||||
|
constructor(value) {
|
||||||
|
this.value = value * 10;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
x: 1,
|
||||||
|
y: 2,
|
||||||
|
};
|
||||||
|
console.log(o.p.name, o.p === o.p, new o.p(o.x).value, new o.p(o.y).value);
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
// FIXME: class `o.p` not hoisted due to `new`
|
||||||
|
var o = {
|
||||||
|
p: class Foo {
|
||||||
|
constructor(value) {
|
||||||
|
this.value = 10 * value;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
x: 1,
|
||||||
|
y: 2
|
||||||
|
};
|
||||||
|
console.log(o.p.name, o.p == o.p, new o.p(o.x).value, new o.p(o.y).value);
|
||||||
|
}
|
||||||
|
node_version: ">=6"
|
||||||
|
expect_stdout: "Foo true 10 20"
|
||||||
|
}
|
||||||
|
|
||||||
|
hoist_function_with_call: {
|
||||||
|
options = {
|
||||||
|
comparisons: true,
|
||||||
|
evaluate: true,
|
||||||
|
hoist_props: true,
|
||||||
|
inline: true,
|
||||||
|
keep_fnames: true,
|
||||||
|
passes: 2,
|
||||||
|
reduce_funcs: true,
|
||||||
|
reduce_vars: true,
|
||||||
|
toplevel: true,
|
||||||
|
unused: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
var o = {
|
||||||
|
p: function Foo(value) {
|
||||||
|
return 10 * value;
|
||||||
|
},
|
||||||
|
x: 1,
|
||||||
|
y: 2
|
||||||
|
};
|
||||||
|
console.log(o.p.name, o.p === o.p, o.p(o.x), o.p(o.y));
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
var o_p = function Foo(value){
|
||||||
|
return 10 * value
|
||||||
|
};
|
||||||
|
console.log(o_p.name, true, o_p(1), o_p(2));
|
||||||
|
}
|
||||||
|
expect_stdout: "Foo true 10 20"
|
||||||
|
}
|
||||||
|
|
||||||
|
new_this: {
|
||||||
|
options = {
|
||||||
|
evaluate: true,
|
||||||
|
hoist_props: true,
|
||||||
|
inline: true,
|
||||||
|
passes: 2,
|
||||||
|
reduce_funcs: true,
|
||||||
|
reduce_vars: true,
|
||||||
|
toplevel: true,
|
||||||
|
unused: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
var o = {
|
||||||
|
a: 1,
|
||||||
|
b: 2,
|
||||||
|
f: function(a) {
|
||||||
|
this.b = a;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
console.log(new o.f(o.a).b, o.b);
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
console.log(new function(a) {
|
||||||
|
this.b = a;
|
||||||
|
}(1).b, 2);
|
||||||
|
}
|
||||||
|
expect_stdout: "1 2"
|
||||||
|
}
|
||||||
|
|
||||||
|
issue_2462: {
|
||||||
|
options = {
|
||||||
|
hoist_props: true,
|
||||||
|
reduce_funcs: true,
|
||||||
|
reduce_vars: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
export const Foo = {
|
||||||
|
a: 1,
|
||||||
|
b: () => 2
|
||||||
|
};
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
export const Foo = {
|
||||||
|
a: 1,
|
||||||
|
b: () => 2
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
issue_2473_1: {
|
||||||
|
options = {
|
||||||
|
hoist_props: false,
|
||||||
|
reduce_vars: true,
|
||||||
|
top_retain: [ "x", "y" ],
|
||||||
|
toplevel: true,
|
||||||
|
unused: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
var x = {};
|
||||||
|
var y = [];
|
||||||
|
var z = {};
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
var x = {};
|
||||||
|
var y = [];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
issue_2473_2: {
|
||||||
|
options = {
|
||||||
|
hoist_props: true,
|
||||||
|
reduce_vars: true,
|
||||||
|
top_retain: [ "x", "y" ],
|
||||||
|
toplevel: true,
|
||||||
|
unused: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
var x = {};
|
||||||
|
var y = [];
|
||||||
|
var z = {};
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
var x = {};
|
||||||
|
var y = [];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
issue_2473_3: {
|
||||||
|
options = {
|
||||||
|
hoist_props: true,
|
||||||
|
reduce_vars: true,
|
||||||
|
top_retain: "o",
|
||||||
|
toplevel: true,
|
||||||
|
unused: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
var o = {
|
||||||
|
a: 1,
|
||||||
|
b: 2,
|
||||||
|
};
|
||||||
|
console.log(o.a, o.b);
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
var o = {
|
||||||
|
a: 1,
|
||||||
|
b: 2,
|
||||||
|
};
|
||||||
|
console.log(o.a, o.b);
|
||||||
|
}
|
||||||
|
expect_stdout: "1 2"
|
||||||
|
}
|
||||||
|
|
||||||
|
issue_2473_4: {
|
||||||
|
options = {
|
||||||
|
hoist_props: true,
|
||||||
|
reduce_vars: true,
|
||||||
|
top_retain: "o",
|
||||||
|
toplevel: true,
|
||||||
|
unused: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
(function() {
|
||||||
|
var o = {
|
||||||
|
a: 1,
|
||||||
|
b: 2,
|
||||||
|
};
|
||||||
|
console.log(o.a, o.b);
|
||||||
|
})();
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
(function() {
|
||||||
|
var o_a = 1, o_b = 2;
|
||||||
|
console.log(o_a, o_b);
|
||||||
|
})();
|
||||||
|
}
|
||||||
|
expect_stdout: "1 2"
|
||||||
|
}
|
||||||
|
|
||||||
|
issue_2508_1: {
|
||||||
|
options = {
|
||||||
|
collapse_vars: true,
|
||||||
|
hoist_props: true,
|
||||||
|
reduce_vars: true,
|
||||||
|
toplevel: true,
|
||||||
|
unused: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
var o = {
|
||||||
|
a: [ 1 ],
|
||||||
|
f: function(x) {
|
||||||
|
console.log(x);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
o.f(o.a);
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
(function(x) {
|
||||||
|
console.log(x);
|
||||||
|
})([ 1 ]);
|
||||||
|
}
|
||||||
|
expect_stdout: true
|
||||||
|
}
|
||||||
|
|
||||||
|
issue_2508_2: {
|
||||||
|
options = {
|
||||||
|
collapse_vars: true,
|
||||||
|
hoist_props: true,
|
||||||
|
reduce_vars: true,
|
||||||
|
toplevel: true,
|
||||||
|
unused: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
var o = {
|
||||||
|
a: { b: 2 },
|
||||||
|
f: function(x) {
|
||||||
|
console.log(x);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
o.f(o.a);
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
(function(x) {
|
||||||
|
console.log(x);
|
||||||
|
})({ b: 2 });
|
||||||
|
}
|
||||||
|
expect_stdout: true
|
||||||
|
}
|
||||||
|
|
||||||
|
issue_2508_3: {
|
||||||
|
options = {
|
||||||
|
collapse_vars: true,
|
||||||
|
hoist_props: true,
|
||||||
|
reduce_vars: true,
|
||||||
|
toplevel: true,
|
||||||
|
unused: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
var o = {
|
||||||
|
a: [ o ],
|
||||||
|
f: function(x) {
|
||||||
|
console.log(x);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
o.f(o.a);
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
var o = {
|
||||||
|
a: [ o ],
|
||||||
|
f: function(x) {
|
||||||
|
console.log(x);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
o.f(o.a);
|
||||||
|
}
|
||||||
|
expect_stdout: true
|
||||||
|
}
|
||||||
|
|
||||||
|
issue_2508_4: {
|
||||||
|
options = {
|
||||||
|
collapse_vars: true,
|
||||||
|
hoist_props: true,
|
||||||
|
reduce_vars: true,
|
||||||
|
toplevel: true,
|
||||||
|
unused: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
var o = {
|
||||||
|
a: { b: o },
|
||||||
|
f: function(x) {
|
||||||
|
console.log(x);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
o.f(o.a);
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
var o = {
|
||||||
|
a: { b: o },
|
||||||
|
f: function(x) {
|
||||||
|
console.log(x);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
o.f(o.a);
|
||||||
|
}
|
||||||
|
expect_stdout: true
|
||||||
|
}
|
||||||
|
|
||||||
|
issue_2508_5: {
|
||||||
|
options = {
|
||||||
|
collapse_vars: true,
|
||||||
|
hoist_props: true,
|
||||||
|
reduce_vars: true,
|
||||||
|
toplevel: true,
|
||||||
|
unused: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
var o = {
|
||||||
|
f: function(x) {
|
||||||
|
console.log(x);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
o.f(o.f);
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
var o_f = function(x) {
|
||||||
|
console.log(x);
|
||||||
|
};
|
||||||
|
o_f(o_f);
|
||||||
|
}
|
||||||
|
expect_stdout: true
|
||||||
|
}
|
||||||
@@ -88,3 +88,24 @@ sequences_funs: {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
issue_2295: {
|
||||||
|
options = {
|
||||||
|
collapse_vars: true,
|
||||||
|
hoist_vars: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
function foo(o) {
|
||||||
|
var a = o.a;
|
||||||
|
if (a) return a;
|
||||||
|
var a = 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
function foo(o) {
|
||||||
|
var a = o.a;
|
||||||
|
if (a) return a;
|
||||||
|
a = 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -71,11 +71,13 @@ non_hoisted_function_after_return_2a: {
|
|||||||
"WARN: Declarations in unreachable code! [test/compress/issue-1034.js:51,16]",
|
"WARN: Declarations in unreachable code! [test/compress/issue-1034.js:51,16]",
|
||||||
"WARN: Dropping unused variable a [test/compress/issue-1034.js:48,20]",
|
"WARN: Dropping unused variable a [test/compress/issue-1034.js:48,20]",
|
||||||
"WARN: Dropping unused function nope [test/compress/issue-1034.js:55,21]",
|
"WARN: Dropping unused function nope [test/compress/issue-1034.js:55,21]",
|
||||||
|
"WARN: 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:53,12]",
|
||||||
"WARN: Declarations in unreachable code! [test/compress/issue-1034.js:53,12]",
|
"WARN: Declarations in unreachable code! [test/compress/issue-1034.js:53,12]",
|
||||||
"WARN: Dropping unreachable code [test/compress/issue-1034.js:56,12]",
|
"WARN: Dropping unreachable code [test/compress/issue-1034.js:56,12]",
|
||||||
"WARN: Dropping unused variable b [test/compress/issue-1034.js:51,20]",
|
"WARN: Dropping unused variable b [test/compress/issue-1034.js:51,20]",
|
||||||
"WARN: Dropping unused variable c [test/compress/issue-1034.js:53,16]",
|
"WARN: Dropping unused variable c [test/compress/issue-1034.js:53,16]",
|
||||||
|
"WARN: pass 1: last_count: 37, count: 18",
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -109,11 +111,11 @@ non_hoisted_function_after_return_2b: {
|
|||||||
}
|
}
|
||||||
expect_warnings: [
|
expect_warnings: [
|
||||||
// duplicate warnings no longer emitted
|
// duplicate warnings no longer emitted
|
||||||
"WARN: Dropping unreachable code [test/compress/issue-1034.js:95,16]",
|
"WARN: Dropping unreachable code [test/compress/issue-1034.js:97,16]",
|
||||||
"WARN: Declarations in unreachable code! [test/compress/issue-1034.js:95,16]",
|
"WARN: Declarations in unreachable code! [test/compress/issue-1034.js:97,16]",
|
||||||
"WARN: Dropping unreachable code [test/compress/issue-1034.js:97,12]",
|
"WARN: Dropping unreachable code [test/compress/issue-1034.js:99,12]",
|
||||||
"WARN: Declarations in unreachable code! [test/compress/issue-1034.js:97,12]",
|
"WARN: Declarations in unreachable code! [test/compress/issue-1034.js:99,12]",
|
||||||
"WARN: Dropping unreachable code [test/compress/issue-1034.js:101,12]",
|
"WARN: Dropping unreachable code [test/compress/issue-1034.js:103,12]",
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -151,10 +153,10 @@ 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:131,16]',
|
"WARN: Dropping unreachable code [test/compress/issue-1034.js:133,16]",
|
||||||
"WARN: Dropping unreachable code [test/compress/issue-1034.js:134,16]",
|
"WARN: Dropping unreachable code [test/compress/issue-1034.js:136,16]",
|
||||||
"WARN: Dropping unreachable code [test/compress/issue-1034.js:137,12]",
|
"WARN: Dropping unreachable code [test/compress/issue-1034.js:139,12]",
|
||||||
"WARN: Dropping unused function UnusedFunction [test/compress/issue-1034.js:138,21]"
|
"WARN: Dropping unused function UnusedFunction [test/compress/issue-1034.js:140,21]",
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -194,17 +196,19 @@ 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:173,16]",
|
"WARN: Dropping unreachable code [test/compress/issue-1034.js:175,16]",
|
||||||
"WARN: Declarations in unreachable code! [test/compress/issue-1034.js:173,16]",
|
"WARN: Declarations in unreachable code! [test/compress/issue-1034.js:175,16]",
|
||||||
"WARN: Dropping unreachable code [test/compress/issue-1034.js:176,16]",
|
"WARN: Dropping unreachable code [test/compress/issue-1034.js:178,16]",
|
||||||
"WARN: Declarations in unreachable code! [test/compress/issue-1034.js:176,16]",
|
"WARN: Declarations in unreachable code! [test/compress/issue-1034.js:178,16]",
|
||||||
"WARN: Dropping unused variable a [test/compress/issue-1034.js:173,20]",
|
"WARN: Dropping unused variable a [test/compress/issue-1034.js:175,20]",
|
||||||
"WARN: Dropping unused function nope [test/compress/issue-1034.js:180,21]",
|
"WARN: Dropping unused function nope [test/compress/issue-1034.js:182,21]",
|
||||||
"WARN: Dropping unreachable code [test/compress/issue-1034.js:178,12]",
|
"WARN: pass 0: last_count: Infinity, count: 48",
|
||||||
"WARN: Declarations in unreachable code! [test/compress/issue-1034.js:178,12]",
|
"WARN: Dropping unreachable code [test/compress/issue-1034.js:180,12]",
|
||||||
"WARN: Dropping unreachable code [test/compress/issue-1034.js:181,12]",
|
"WARN: Declarations in unreachable code! [test/compress/issue-1034.js:180,12]",
|
||||||
"WARN: Dropping unused variable b [test/compress/issue-1034.js:176,20]",
|
"WARN: Dropping unreachable code [test/compress/issue-1034.js:183,12]",
|
||||||
"WARN: Dropping unused variable c [test/compress/issue-1034.js:178,16]",
|
"WARN: Dropping unused variable b [test/compress/issue-1034.js:178,20]",
|
||||||
|
"WARN: Dropping unused variable c [test/compress/issue-1034.js:180,16]",
|
||||||
|
"WARN: pass 1: last_count: 48, count: 29",
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -243,10 +247,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
|
// duplicate warnings no longer emitted
|
||||||
"WARN: Dropping unreachable code [test/compress/issue-1034.js:225,16]",
|
"WARN: Dropping unreachable code [test/compress/issue-1034.js:229,16]",
|
||||||
"WARN: Declarations in unreachable code! [test/compress/issue-1034.js:225,16]",
|
"WARN: Declarations in unreachable code! [test/compress/issue-1034.js:229,16]",
|
||||||
"WARN: Dropping unreachable code [test/compress/issue-1034.js:227,12]",
|
|
||||||
"WARN: Declarations in unreachable code! [test/compress/issue-1034.js:227,12]",
|
|
||||||
"WARN: Dropping unreachable code [test/compress/issue-1034.js:231,12]",
|
"WARN: Dropping unreachable code [test/compress/issue-1034.js:231,12]",
|
||||||
|
"WARN: Declarations in unreachable code! [test/compress/issue-1034.js:231,12]",
|
||||||
|
"WARN: Dropping unreachable code [test/compress/issue-1034.js:235,12]",
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ const_declaration: {
|
|||||||
const_pragma: {
|
const_pragma: {
|
||||||
options = {
|
options = {
|
||||||
evaluate: true,
|
evaluate: true,
|
||||||
|
reduce_funcs: true,
|
||||||
reduce_vars: true,
|
reduce_vars: true,
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -29,6 +30,7 @@ const_pragma: {
|
|||||||
not_const: {
|
not_const: {
|
||||||
options = {
|
options = {
|
||||||
evaluate: true,
|
evaluate: true,
|
||||||
|
reduce_funcs: true,
|
||||||
reduce_vars: true,
|
reduce_vars: true,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -96,6 +96,13 @@ pure_function_calls_toplevel: {
|
|||||||
})();
|
})();
|
||||||
})();
|
})();
|
||||||
|
|
||||||
|
// pure top-level calls will be dropped regardless of the leading comments position
|
||||||
|
var MyClass = /*#__PURE__*//*@class*/(function(){
|
||||||
|
function MyClass() {}
|
||||||
|
MyClass.prototype.method = function() {};
|
||||||
|
return MyClass;
|
||||||
|
})();
|
||||||
|
|
||||||
// comment #__PURE__ comment
|
// comment #__PURE__ comment
|
||||||
bar(), baz(), quux();
|
bar(), baz(), quux();
|
||||||
a.b(), /* @__PURE__ */ c.d.e(), f.g();
|
a.b(), /* @__PURE__ */ c.d.e(), f.g();
|
||||||
@@ -110,10 +117,12 @@ pure_function_calls_toplevel: {
|
|||||||
"WARN: Dropping __PURE__ call [test/compress/issue-1261.js:92,37]",
|
"WARN: Dropping __PURE__ call [test/compress/issue-1261.js:92,37]",
|
||||||
"WARN: Dropping unused variable iife2 [test/compress/issue-1261.js:92,16]",
|
"WARN: Dropping unused variable iife2 [test/compress/issue-1261.js:92,16]",
|
||||||
"WARN: Dropping side-effect-free statement [test/compress/issue-1261.js:90,8]",
|
"WARN: Dropping side-effect-free statement [test/compress/issue-1261.js:90,8]",
|
||||||
"WARN: Dropping __PURE__ call [test/compress/issue-1261.js:100,8]",
|
"WARN: Dropping __PURE__ call [test/compress/issue-1261.js:107,8]",
|
||||||
"WARN: Dropping __PURE__ call [test/compress/issue-1261.js:101,31]",
|
"WARN: Dropping __PURE__ call [test/compress/issue-1261.js:108,31]",
|
||||||
"WARN: Dropping __PURE__ call [test/compress/issue-1261.js:84,33]",
|
"WARN: Dropping __PURE__ call [test/compress/issue-1261.js:84,33]",
|
||||||
"WARN: Dropping unused variable iife1 [test/compress/issue-1261.js:84,12]",
|
"WARN: Dropping unused variable iife1 [test/compress/issue-1261.js:84,12]",
|
||||||
|
"WARN: Dropping __PURE__ call [test/compress/issue-1261.js:100,45]",
|
||||||
|
"WARN: Dropping unused variable MyClass [test/compress/issue-1261.js:100,12]",
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -148,29 +157,29 @@ should_warn: {
|
|||||||
baz();
|
baz();
|
||||||
}
|
}
|
||||||
expect_warnings: [
|
expect_warnings: [
|
||||||
"WARN: Dropping __PURE__ call [test/compress/issue-1261.js:128,61]",
|
"WARN: Dropping __PURE__ call [test/compress/issue-1261.js:137,61]",
|
||||||
"WARN: Dropping __PURE__ call [test/compress/issue-1261.js:128,23]",
|
"WARN: Dropping __PURE__ call [test/compress/issue-1261.js:137,23]",
|
||||||
"WARN: Dropping side-effect-free statement [test/compress/issue-1261.js:128,23]",
|
"WARN: Dropping side-effect-free statement [test/compress/issue-1261.js:137,23]",
|
||||||
"WARN: Boolean || always true [test/compress/issue-1261.js:129,23]",
|
"WARN: Boolean || always true [test/compress/issue-1261.js:138,23]",
|
||||||
"WARN: Dropping __PURE__ call [test/compress/issue-1261.js:129,23]",
|
"WARN: Dropping __PURE__ call [test/compress/issue-1261.js:138,23]",
|
||||||
"WARN: Condition always true [test/compress/issue-1261.js:129,23]",
|
"WARN: Condition always true [test/compress/issue-1261.js:138,23]",
|
||||||
"WARN: Condition left of || always true [test/compress/issue-1261.js:130,8]",
|
"WARN: Condition left of || always true [test/compress/issue-1261.js:139,8]",
|
||||||
"WARN: Condition always true [test/compress/issue-1261.js:130,8]",
|
"WARN: Condition always true [test/compress/issue-1261.js:139,8]",
|
||||||
"WARN: Boolean && always false [test/compress/issue-1261.js:131,23]",
|
"WARN: Boolean && always false [test/compress/issue-1261.js:140,23]",
|
||||||
"WARN: Dropping __PURE__ call [test/compress/issue-1261.js:131,23]",
|
"WARN: Dropping __PURE__ call [test/compress/issue-1261.js:140,23]",
|
||||||
"WARN: Condition always false [test/compress/issue-1261.js:131,23]",
|
"WARN: Condition always false [test/compress/issue-1261.js:140,23]",
|
||||||
"WARN: Condition left of && always false [test/compress/issue-1261.js:132,8]",
|
"WARN: Condition left of && always false [test/compress/issue-1261.js:141,8]",
|
||||||
"WARN: Condition always false [test/compress/issue-1261.js:132,8]",
|
"WARN: Condition always false [test/compress/issue-1261.js:141,8]",
|
||||||
"WARN: + in boolean context always true [test/compress/issue-1261.js:133,23]",
|
"WARN: + in boolean context always true [test/compress/issue-1261.js:142,23]",
|
||||||
"WARN: Dropping __PURE__ call [test/compress/issue-1261.js:133,23]",
|
"WARN: Dropping __PURE__ call [test/compress/issue-1261.js:142,23]",
|
||||||
"WARN: Condition always true [test/compress/issue-1261.js:133,23]",
|
"WARN: Condition always true [test/compress/issue-1261.js:142,23]",
|
||||||
"WARN: + in boolean context always true [test/compress/issue-1261.js:134,8]",
|
"WARN: + in boolean context always true [test/compress/issue-1261.js:143,8]",
|
||||||
"WARN: Dropping __PURE__ call [test/compress/issue-1261.js:134,31]",
|
"WARN: Dropping __PURE__ call [test/compress/issue-1261.js:143,31]",
|
||||||
"WARN: Condition always true [test/compress/issue-1261.js:134,8]",
|
"WARN: Condition always true [test/compress/issue-1261.js:143,8]",
|
||||||
"WARN: Dropping __PURE__ call [test/compress/issue-1261.js:135,23]",
|
"WARN: Dropping __PURE__ call [test/compress/issue-1261.js:144,23]",
|
||||||
"WARN: Dropping __PURE__ call [test/compress/issue-1261.js:136,24]",
|
"WARN: Dropping __PURE__ call [test/compress/issue-1261.js:145,24]",
|
||||||
"WARN: Condition always true [test/compress/issue-1261.js:136,8]",
|
"WARN: Condition always true [test/compress/issue-1261.js:145,8]",
|
||||||
"WARN: Dropping __PURE__ call [test/compress/issue-1261.js:137,31]",
|
"WARN: Dropping __PURE__ call [test/compress/issue-1261.js:146,31]",
|
||||||
"WARN: Condition always false [test/compress/issue-1261.js:137,8]",
|
"WARN: Condition always false [test/compress/issue-1261.js:146,8]",
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
issue_1321_no_debug: {
|
issue_1321_no_debug: {
|
||||||
mangle_props = {
|
mangle = {
|
||||||
keep_quoted: true
|
properties: {
|
||||||
|
keep_quoted: true,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
input: {
|
input: {
|
||||||
var x = {};
|
var x = {};
|
||||||
@@ -10,17 +12,19 @@ issue_1321_no_debug: {
|
|||||||
}
|
}
|
||||||
expect: {
|
expect: {
|
||||||
var x = {};
|
var x = {};
|
||||||
x.o = 1;
|
x.x = 1;
|
||||||
x["a"] = 2 * x.o;
|
x["a"] = 2 * x.x;
|
||||||
console.log(x.o, x["a"]);
|
console.log(x.x, x["a"]);
|
||||||
}
|
}
|
||||||
expect_stdout: true
|
expect_stdout: true
|
||||||
}
|
}
|
||||||
|
|
||||||
issue_1321_debug: {
|
issue_1321_debug: {
|
||||||
mangle_props = {
|
mangle = {
|
||||||
keep_quoted: true,
|
properties: {
|
||||||
debug: ""
|
debug: "",
|
||||||
|
keep_quoted: true,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
input: {
|
input: {
|
||||||
var x = {};
|
var x = {};
|
||||||
@@ -30,16 +34,18 @@ issue_1321_debug: {
|
|||||||
}
|
}
|
||||||
expect: {
|
expect: {
|
||||||
var x = {};
|
var x = {};
|
||||||
x.o = 1;
|
x.x = 1;
|
||||||
x["_$foo$_"] = 2 * x.o;
|
x["_$foo$_"] = 2 * x.x;
|
||||||
console.log(x.o, x["_$foo$_"]);
|
console.log(x.x, x["_$foo$_"]);
|
||||||
}
|
}
|
||||||
expect_stdout: true
|
expect_stdout: true
|
||||||
}
|
}
|
||||||
|
|
||||||
issue_1321_with_quoted: {
|
issue_1321_with_quoted: {
|
||||||
mangle_props = {
|
mangle = {
|
||||||
keep_quoted: false
|
properties: {
|
||||||
|
keep_quoted: false,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
input: {
|
input: {
|
||||||
var x = {};
|
var x = {};
|
||||||
@@ -49,9 +55,9 @@ issue_1321_with_quoted: {
|
|||||||
}
|
}
|
||||||
expect: {
|
expect: {
|
||||||
var x = {};
|
var x = {};
|
||||||
x.o = 1;
|
x.x = 1;
|
||||||
x["x"] = 2 * x.o;
|
x["o"] = 2 * x.x;
|
||||||
console.log(x.o, x["x"]);
|
console.log(x.x, x["o"]);
|
||||||
}
|
}
|
||||||
expect_stdout: true
|
expect_stdout: true
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
typeof_eq_undefined: {
|
typeof_eq_undefined: {
|
||||||
options = {
|
options = {
|
||||||
comparisons: true
|
comparisons: true,
|
||||||
|
typeofs: true,
|
||||||
}
|
}
|
||||||
input: {
|
input: {
|
||||||
var a = typeof b != "undefined";
|
var a = typeof b != "undefined";
|
||||||
@@ -24,6 +25,7 @@ typeof_eq_undefined_ie8: {
|
|||||||
options = {
|
options = {
|
||||||
comparisons: true,
|
comparisons: true,
|
||||||
ie8: true,
|
ie8: true,
|
||||||
|
typeofs: true,
|
||||||
}
|
}
|
||||||
input: {
|
input: {
|
||||||
var a = typeof b != "undefined";
|
var a = typeof b != "undefined";
|
||||||
@@ -45,7 +47,8 @@ typeof_eq_undefined_ie8: {
|
|||||||
|
|
||||||
undefined_redefined: {
|
undefined_redefined: {
|
||||||
options = {
|
options = {
|
||||||
comparisons: true
|
comparisons: true,
|
||||||
|
typeofs: true,
|
||||||
}
|
}
|
||||||
input: {
|
input: {
|
||||||
function f(undefined) {
|
function f(undefined) {
|
||||||
@@ -58,7 +61,8 @@ undefined_redefined: {
|
|||||||
|
|
||||||
undefined_redefined_mangle: {
|
undefined_redefined_mangle: {
|
||||||
options = {
|
options = {
|
||||||
comparisons: true
|
comparisons: true,
|
||||||
|
typeofs: true,
|
||||||
}
|
}
|
||||||
mangle = {}
|
mangle = {}
|
||||||
input: {
|
input: {
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ chained_evaluation_1: {
|
|||||||
options = {
|
options = {
|
||||||
collapse_vars: true,
|
collapse_vars: true,
|
||||||
evaluate: true,
|
evaluate: true,
|
||||||
|
reduce_funcs: true,
|
||||||
reduce_vars: true,
|
reduce_vars: true,
|
||||||
unused: true,
|
unused: true,
|
||||||
}
|
}
|
||||||
@@ -28,6 +29,7 @@ chained_evaluation_2: {
|
|||||||
options = {
|
options = {
|
||||||
collapse_vars: true,
|
collapse_vars: true,
|
||||||
evaluate: true,
|
evaluate: true,
|
||||||
|
reduce_funcs: true,
|
||||||
reduce_vars: true,
|
reduce_vars: true,
|
||||||
unused: true,
|
unused: true,
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ f7: {
|
|||||||
negate_iife: true,
|
negate_iife: true,
|
||||||
passes: 3,
|
passes: 3,
|
||||||
properties: true,
|
properties: true,
|
||||||
|
reduce_funcs: true,
|
||||||
reduce_vars: true,
|
reduce_vars: true,
|
||||||
sequences: true,
|
sequences: true,
|
||||||
side_effects: true,
|
side_effects: true,
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
side_effects_catch: {
|
side_effects_catch: {
|
||||||
options = {
|
options = {
|
||||||
|
reduce_funcs: true,
|
||||||
reduce_vars: true,
|
reduce_vars: true,
|
||||||
side_effects: true,
|
side_effects: true,
|
||||||
unused: true,
|
unused: true,
|
||||||
@@ -34,6 +35,7 @@ side_effects_catch: {
|
|||||||
|
|
||||||
side_effects_else: {
|
side_effects_else: {
|
||||||
options = {
|
options = {
|
||||||
|
reduce_funcs: true,
|
||||||
reduce_vars: true,
|
reduce_vars: true,
|
||||||
side_effects: true,
|
side_effects: true,
|
||||||
unused: true,
|
unused: true,
|
||||||
@@ -62,6 +64,7 @@ side_effects_else: {
|
|||||||
|
|
||||||
side_effects_finally: {
|
side_effects_finally: {
|
||||||
options = {
|
options = {
|
||||||
|
reduce_funcs: true,
|
||||||
reduce_vars: true,
|
reduce_vars: true,
|
||||||
side_effects: true,
|
side_effects: true,
|
||||||
unused: true,
|
unused: true,
|
||||||
@@ -98,6 +101,7 @@ side_effects_finally: {
|
|||||||
|
|
||||||
side_effects_label: {
|
side_effects_label: {
|
||||||
options = {
|
options = {
|
||||||
|
reduce_funcs: true,
|
||||||
reduce_vars: true,
|
reduce_vars: true,
|
||||||
side_effects: true,
|
side_effects: true,
|
||||||
unused: true,
|
unused: true,
|
||||||
@@ -130,6 +134,7 @@ side_effects_label: {
|
|||||||
|
|
||||||
side_effects_switch: {
|
side_effects_switch: {
|
||||||
options = {
|
options = {
|
||||||
|
reduce_funcs: true,
|
||||||
reduce_vars: true,
|
reduce_vars: true,
|
||||||
side_effects: true,
|
side_effects: true,
|
||||||
unused: true,
|
unused: true,
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
mangle_props: {
|
mangle_props: {
|
||||||
mangle_props = {}
|
mangle = {
|
||||||
|
properties: true,
|
||||||
|
}
|
||||||
input: {
|
input: {
|
||||||
var obj = {
|
var obj = {
|
||||||
undefined: 1,
|
undefined: 1,
|
||||||
@@ -54,10 +56,12 @@ mangle_props: {
|
|||||||
}
|
}
|
||||||
|
|
||||||
numeric_literal: {
|
numeric_literal: {
|
||||||
|
mangle = {
|
||||||
|
properties: true,
|
||||||
|
}
|
||||||
beautify = {
|
beautify = {
|
||||||
beautify: true,
|
beautify: true,
|
||||||
}
|
}
|
||||||
mangle_props = {}
|
|
||||||
input: {
|
input: {
|
||||||
var obj = {
|
var obj = {
|
||||||
0: 0,
|
0: 0,
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ unary_prefix: {
|
|||||||
options = {
|
options = {
|
||||||
evaluate: true,
|
evaluate: true,
|
||||||
inline: true,
|
inline: true,
|
||||||
|
reduce_funcs: true,
|
||||||
reduce_vars: true,
|
reduce_vars: true,
|
||||||
unused: true,
|
unused: true,
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
iife_for: {
|
iife_for: {
|
||||||
options = {
|
options = {
|
||||||
negate_iife: true,
|
negate_iife: true,
|
||||||
|
reduce_funcs: true,
|
||||||
reduce_vars: true,
|
reduce_vars: true,
|
||||||
toplevel: true,
|
toplevel: true,
|
||||||
unused: true,
|
unused: true,
|
||||||
@@ -26,6 +27,7 @@ iife_for: {
|
|||||||
iife_for_in: {
|
iife_for_in: {
|
||||||
options = {
|
options = {
|
||||||
negate_iife: true,
|
negate_iife: true,
|
||||||
|
reduce_funcs: true,
|
||||||
reduce_vars: true,
|
reduce_vars: true,
|
||||||
toplevel: true,
|
toplevel: true,
|
||||||
unused: true,
|
unused: true,
|
||||||
@@ -51,6 +53,7 @@ iife_for_in: {
|
|||||||
iife_do: {
|
iife_do: {
|
||||||
options = {
|
options = {
|
||||||
negate_iife: true,
|
negate_iife: true,
|
||||||
|
reduce_funcs: true,
|
||||||
reduce_vars: true,
|
reduce_vars: true,
|
||||||
toplevel: true,
|
toplevel: true,
|
||||||
unused: true,
|
unused: true,
|
||||||
@@ -80,6 +83,7 @@ iife_do: {
|
|||||||
iife_while: {
|
iife_while: {
|
||||||
options = {
|
options = {
|
||||||
negate_iife: true,
|
negate_iife: true,
|
||||||
|
reduce_funcs: true,
|
||||||
reduce_vars: true,
|
reduce_vars: true,
|
||||||
toplevel: true,
|
toplevel: true,
|
||||||
unused: true,
|
unused: true,
|
||||||
|
|||||||
@@ -177,6 +177,7 @@ export_mangle_2: {
|
|||||||
export_mangle_3: {
|
export_mangle_3: {
|
||||||
options = {
|
options = {
|
||||||
collapse_vars: true,
|
collapse_vars: true,
|
||||||
|
unused: true,
|
||||||
}
|
}
|
||||||
mangle = {
|
mangle = {
|
||||||
toplevel: true,
|
toplevel: true,
|
||||||
@@ -195,6 +196,7 @@ export_mangle_3: {
|
|||||||
export_mangle_4: {
|
export_mangle_4: {
|
||||||
options = {
|
options = {
|
||||||
collapse_vars: true,
|
collapse_vars: true,
|
||||||
|
unused: true,
|
||||||
}
|
}
|
||||||
mangle = {
|
mangle = {
|
||||||
toplevel: true,
|
toplevel: true,
|
||||||
|
|||||||
@@ -36,9 +36,10 @@ compress_new_function_with_destruct: {
|
|||||||
compress_new_function_with_destruct_arrows: {
|
compress_new_function_with_destruct_arrows: {
|
||||||
options = {
|
options = {
|
||||||
arrows: true,
|
arrows: true,
|
||||||
|
unsafe_arrows: true,
|
||||||
unsafe: true,
|
unsafe: true,
|
||||||
unsafe_Func: true,
|
unsafe_Func: true,
|
||||||
ecma: 6
|
ecma: 6,
|
||||||
}
|
}
|
||||||
beautify = {
|
beautify = {
|
||||||
ecma: 6
|
ecma: 6
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ collapse_vars_constants: {
|
|||||||
collapse_vars: true,
|
collapse_vars: true,
|
||||||
evaluate: true,
|
evaluate: true,
|
||||||
inline: true,
|
inline: true,
|
||||||
|
reduce_funcs: true,
|
||||||
reduce_vars: true,
|
reduce_vars: true,
|
||||||
unused: true,
|
unused: true,
|
||||||
}
|
}
|
||||||
@@ -240,6 +241,7 @@ negate_iife_issue_1073: {
|
|||||||
evaluate: true,
|
evaluate: true,
|
||||||
inline: true,
|
inline: true,
|
||||||
negate_iife: true,
|
negate_iife: true,
|
||||||
|
reduce_funcs: true,
|
||||||
reduce_vars: true,
|
reduce_vars: true,
|
||||||
sequences: true,
|
sequences: true,
|
||||||
unused: true,
|
unused: true,
|
||||||
@@ -267,6 +269,7 @@ issue_1288_side_effects: {
|
|||||||
evaluate: true,
|
evaluate: true,
|
||||||
inline: true,
|
inline: true,
|
||||||
negate_iife: true,
|
negate_iife: true,
|
||||||
|
reduce_funcs: true,
|
||||||
reduce_vars: true,
|
reduce_vars: true,
|
||||||
side_effects: true,
|
side_effects: true,
|
||||||
unused: true,
|
unused: true,
|
||||||
@@ -299,6 +302,7 @@ inner_var_for_in_1: {
|
|||||||
options = {
|
options = {
|
||||||
evaluate: true,
|
evaluate: true,
|
||||||
inline: true,
|
inline: true,
|
||||||
|
reduce_funcs: true,
|
||||||
reduce_vars: true,
|
reduce_vars: true,
|
||||||
}
|
}
|
||||||
input: {
|
input: {
|
||||||
@@ -330,6 +334,7 @@ issue_1595_3: {
|
|||||||
evaluate: true,
|
evaluate: true,
|
||||||
inline: true,
|
inline: true,
|
||||||
passes: 2,
|
passes: 2,
|
||||||
|
reduce_funcs: true,
|
||||||
reduce_vars: true,
|
reduce_vars: true,
|
||||||
unused: true,
|
unused: true,
|
||||||
}
|
}
|
||||||
@@ -419,7 +424,7 @@ wrap_iife_in_return_call: {
|
|||||||
expect_exact: '(void console.log("test"))();'
|
expect_exact: '(void console.log("test"))();'
|
||||||
}
|
}
|
||||||
|
|
||||||
pure_annotation: {
|
pure_annotation_1: {
|
||||||
options = {
|
options = {
|
||||||
inline: true,
|
inline: true,
|
||||||
side_effects: true,
|
side_effects: true,
|
||||||
@@ -432,6 +437,20 @@ pure_annotation: {
|
|||||||
expect_exact: ""
|
expect_exact: ""
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pure_annotation_2: {
|
||||||
|
options = {
|
||||||
|
collapse_vars: true,
|
||||||
|
inline: true,
|
||||||
|
side_effects: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
/*@__PURE__*/(function(n) {
|
||||||
|
console.log("hello", n);
|
||||||
|
}(42));
|
||||||
|
}
|
||||||
|
expect_exact: ""
|
||||||
|
}
|
||||||
|
|
||||||
drop_fargs: {
|
drop_fargs: {
|
||||||
options = {
|
options = {
|
||||||
cascade: true,
|
cascade: true,
|
||||||
@@ -449,9 +468,7 @@ drop_fargs: {
|
|||||||
}
|
}
|
||||||
expect: {
|
expect: {
|
||||||
var a = 1;
|
var a = 1;
|
||||||
!function() {
|
++a && a.var, a++;
|
||||||
a++;
|
|
||||||
}(++a && a.var);
|
|
||||||
console.log(a);
|
console.log(a);
|
||||||
}
|
}
|
||||||
expect_stdout: "3"
|
expect_stdout: "3"
|
||||||
@@ -474,9 +491,7 @@ keep_fargs: {
|
|||||||
}
|
}
|
||||||
expect: {
|
expect: {
|
||||||
var a = 1;
|
var a = 1;
|
||||||
!function(a_1) {
|
++a && a.var, a++;
|
||||||
a++;
|
|
||||||
}(++a && a.var);
|
|
||||||
console.log(a);
|
console.log(a);
|
||||||
}
|
}
|
||||||
expect_stdout: "3"
|
expect_stdout: "3"
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
dont_reuse_prop: {
|
dont_reuse_prop: {
|
||||||
mangle_props = {
|
mangle = {
|
||||||
regex: /asd/
|
properties: {
|
||||||
|
regex: /asd/,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
input: {
|
input: {
|
||||||
"aaaaaaaaaabbbbb";
|
"aaaaaaaaaabbbbb";
|
||||||
@@ -20,8 +22,10 @@ dont_reuse_prop: {
|
|||||||
}
|
}
|
||||||
|
|
||||||
unmangleable_props_should_always_be_reserved: {
|
unmangleable_props_should_always_be_reserved: {
|
||||||
mangle_props = {
|
mangle = {
|
||||||
regex: /asd/
|
properties: {
|
||||||
|
regex: /asd/,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
input: {
|
input: {
|
||||||
"aaaaaaaaaabbbbb";
|
"aaaaaaaaaabbbbb";
|
||||||
|
|||||||
@@ -51,6 +51,7 @@ this_binding_collapse_vars: {
|
|||||||
options = {
|
options = {
|
||||||
collapse_vars: true,
|
collapse_vars: true,
|
||||||
toplevel: true,
|
toplevel: true,
|
||||||
|
unused: true,
|
||||||
};
|
};
|
||||||
input: {
|
input: {
|
||||||
var c = a; c();
|
var c = a; c();
|
||||||
|
|||||||
@@ -480,3 +480,17 @@ do_switch: {
|
|||||||
} while (false);
|
} while (false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
in_parenthesis_1: {
|
||||||
|
input: {
|
||||||
|
for (("foo" in {});0;);
|
||||||
|
}
|
||||||
|
expect_exact: 'for(("foo"in{});0;);'
|
||||||
|
}
|
||||||
|
|
||||||
|
in_parenthesis_2: {
|
||||||
|
input: {
|
||||||
|
for ((function(){ "foo" in {}; });0;);
|
||||||
|
}
|
||||||
|
expect_exact: 'for(function(){"foo"in{}};0;);'
|
||||||
|
}
|
||||||
|
|||||||
@@ -98,3 +98,19 @@ new_with_assignement_expression: {
|
|||||||
new y([a, b] = [3, 4]);
|
new y([a, b] = [3, 4]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
dot_parenthesis_1: {
|
||||||
|
input: {
|
||||||
|
console.log(new (Math.random().constructor) instanceof Number);
|
||||||
|
}
|
||||||
|
expect_exact: "console.log(new(Math.random().constructor)instanceof Number);"
|
||||||
|
expect_stdout: "true"
|
||||||
|
}
|
||||||
|
|
||||||
|
dot_parenthesis_2: {
|
||||||
|
input: {
|
||||||
|
console.log(typeof new function(){Math.random()}.constructor);
|
||||||
|
}
|
||||||
|
expect_exact: "console.log(typeof new function(){Math.random()}.constructor);"
|
||||||
|
expect_stdout: "function"
|
||||||
|
}
|
||||||
|
|||||||
@@ -126,6 +126,67 @@ computed_property_names: {
|
|||||||
expect_exact: 'obj({["x"+"x"]:6});'
|
expect_exact: 'obj({["x"+"x"]:6});'
|
||||||
}
|
}
|
||||||
|
|
||||||
|
convert_computed_props_to_regular_ones: {
|
||||||
|
options = {
|
||||||
|
booleans: true,
|
||||||
|
computed_props: true,
|
||||||
|
evaluate: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
var o = {
|
||||||
|
["hi"]: 0,
|
||||||
|
["A" + 1]: 1,
|
||||||
|
[/B/]: 2,
|
||||||
|
[100 + 23]: 3,
|
||||||
|
[1 + .5]: 4,
|
||||||
|
[Math.PI]: 5,
|
||||||
|
[undefined]: 6,
|
||||||
|
[true]: 7,
|
||||||
|
[false]: 8,
|
||||||
|
[null]: 9,
|
||||||
|
[Infinity]: 10,
|
||||||
|
[NaN]: 11,
|
||||||
|
};
|
||||||
|
for (var k in o) {
|
||||||
|
console.log(k, o[k]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
var o = {
|
||||||
|
hi: 0,
|
||||||
|
A1: 1,
|
||||||
|
[/B/]: 2,
|
||||||
|
123: 3,
|
||||||
|
1.5: 4,
|
||||||
|
[Math.PI]: 5,
|
||||||
|
|
||||||
|
// leave these problematic cases as is
|
||||||
|
[void 0]: 6,
|
||||||
|
[!0]: 7,
|
||||||
|
[!1]: 8,
|
||||||
|
[null]: 9,
|
||||||
|
[1 / 0]: 10,
|
||||||
|
[NaN]: 11
|
||||||
|
};
|
||||||
|
for (var k in o) console.log(k, o[k]);
|
||||||
|
}
|
||||||
|
expect_stdout: [
|
||||||
|
"123 3",
|
||||||
|
"hi 0",
|
||||||
|
"A1 1",
|
||||||
|
"/B/ 2",
|
||||||
|
"1.5 4",
|
||||||
|
"3.141592653589793 5",
|
||||||
|
"undefined 6",
|
||||||
|
"true 7",
|
||||||
|
"false 8",
|
||||||
|
"null 9",
|
||||||
|
"Infinity 10",
|
||||||
|
"NaN 11",
|
||||||
|
]
|
||||||
|
node_version: ">=6"
|
||||||
|
}
|
||||||
|
|
||||||
computed_property_names_evaluated_1: {
|
computed_property_names_evaluated_1: {
|
||||||
options = {
|
options = {
|
||||||
evaluate: true
|
evaluate: true
|
||||||
@@ -284,9 +345,11 @@ concise_methods_with_various_property_names: {
|
|||||||
}
|
}
|
||||||
|
|
||||||
concise_methods_and_mangle_props: {
|
concise_methods_and_mangle_props: {
|
||||||
mangle_props = {
|
mangle = {
|
||||||
regex: /_/
|
properties: {
|
||||||
};
|
regex: /_/,
|
||||||
|
},
|
||||||
|
}
|
||||||
input: {
|
input: {
|
||||||
function x() {
|
function x() {
|
||||||
obj = {
|
obj = {
|
||||||
@@ -510,3 +573,242 @@ variable_as_computed_property: {
|
|||||||
}
|
}
|
||||||
expect_exact: "function getLine(header){return{[header]:{}}}"
|
expect_exact: "function getLine(header){return{[header]:{}}}"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
prop_func_to_concise_method: {
|
||||||
|
options = {
|
||||||
|
ecma: 6,
|
||||||
|
unsafe_methods: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
({
|
||||||
|
emit: function NamedFunctionExpression() {
|
||||||
|
console.log("PASS");
|
||||||
|
},
|
||||||
|
run: function() {
|
||||||
|
this.emit();
|
||||||
|
}
|
||||||
|
}).run();
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
({
|
||||||
|
emit: function NamedFunctionExpression() {
|
||||||
|
console.log("PASS");
|
||||||
|
},
|
||||||
|
run() {
|
||||||
|
this.emit();
|
||||||
|
}
|
||||||
|
}).run();
|
||||||
|
}
|
||||||
|
expect_stdout: "PASS"
|
||||||
|
node_version: ">=6"
|
||||||
|
}
|
||||||
|
|
||||||
|
prop_arrow_to_concise_method: {
|
||||||
|
options = {
|
||||||
|
ecma: 6,
|
||||||
|
unsafe_methods: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
({
|
||||||
|
run: () => {
|
||||||
|
console.log("PASS");
|
||||||
|
}
|
||||||
|
}).run();
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
({
|
||||||
|
run() {
|
||||||
|
console.log("PASS");
|
||||||
|
}
|
||||||
|
}).run();
|
||||||
|
}
|
||||||
|
expect_stdout: "PASS"
|
||||||
|
node_version: ">=6"
|
||||||
|
}
|
||||||
|
|
||||||
|
concise_method_to_prop_arrow: {
|
||||||
|
options = {
|
||||||
|
arrows: true,
|
||||||
|
ecma: 6,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
console.log(({ a: () => 1 }).a());
|
||||||
|
console.log(({ a: () => { return 2; } }).a());
|
||||||
|
console.log(({ a() { return 3; } }).a());
|
||||||
|
console.log(({ a() { return this.b; }, b: 4 }).a());
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
console.log({ a: () => 1 }.a());
|
||||||
|
console.log({ a: () => 2 }.a());
|
||||||
|
console.log({ a: () => 3 }.a());
|
||||||
|
console.log({ a() { return this.b; }, b: 4 }.a());
|
||||||
|
}
|
||||||
|
expect_stdout: [
|
||||||
|
"1",
|
||||||
|
"2",
|
||||||
|
"3",
|
||||||
|
"4",
|
||||||
|
]
|
||||||
|
node_version: ">=4"
|
||||||
|
}
|
||||||
|
|
||||||
|
prop_func_to_async_concise_method: {
|
||||||
|
options = {
|
||||||
|
ecma: 8,
|
||||||
|
unsafe_methods: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
({
|
||||||
|
run: async function() {
|
||||||
|
console.log("PASS");
|
||||||
|
}
|
||||||
|
}).run();
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
({
|
||||||
|
async run() {
|
||||||
|
console.log("PASS");
|
||||||
|
}
|
||||||
|
}).run();
|
||||||
|
}
|
||||||
|
expect_stdout: "PASS"
|
||||||
|
node_version: ">=8"
|
||||||
|
}
|
||||||
|
|
||||||
|
prop_func_to_concise_method_various: {
|
||||||
|
options = {
|
||||||
|
ecma: 6,
|
||||||
|
unsafe_methods: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
({
|
||||||
|
null: function(x, y){ x(y); },
|
||||||
|
123: function(x, y){ x(y); },
|
||||||
|
"A B": function(x, y){ x(y); },
|
||||||
|
p1: function(x, y){ x(y); },
|
||||||
|
p2: function*(x, y){ yield x(y); },
|
||||||
|
p3: async function(x, y){ await x(y); },
|
||||||
|
[c1]: function(x, y){ x(y); },
|
||||||
|
[c2]: function*(x, y){ yield x(y); },
|
||||||
|
[c3]: async function(x, y){ await x(y); },
|
||||||
|
});
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
({
|
||||||
|
null(x, y) { x(y); },
|
||||||
|
123(x, y) { x(y); },
|
||||||
|
"A B"(x, y) { x(y); },
|
||||||
|
p1(x, y) { x(y); },
|
||||||
|
*p2(x, y) { yield x(y); },
|
||||||
|
async p3(x, y) { await x(y); },
|
||||||
|
[c1](x, y) { x(y); },
|
||||||
|
*[c2](x, y) { yield x(y); },
|
||||||
|
async [c3](x, y) { await x(y); },
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
prop_arrows_to_concise_method_various: {
|
||||||
|
options = {
|
||||||
|
ecma: 6,
|
||||||
|
unsafe_methods: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
({
|
||||||
|
null: (x, y) => { x(y); },
|
||||||
|
123: (x, y) => { x(y); },
|
||||||
|
"A B": (x, y) => { x(y); },
|
||||||
|
p1: (x, y) => { x(y); },
|
||||||
|
p3: async (x, y) => { await x(y); },
|
||||||
|
[c1]: (x, y) => { x(y); },
|
||||||
|
[c3]: async (x, y) => { await x(y); },
|
||||||
|
});
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
({
|
||||||
|
null(x, y) { x(y); },
|
||||||
|
123(x, y) { x(y); },
|
||||||
|
"A B"(x, y) { x(y); },
|
||||||
|
p1(x, y) { x(y); },
|
||||||
|
async p3(x, y) { await x(y); },
|
||||||
|
[c1](x, y) { x(y); },
|
||||||
|
async [c3](x, y) { await x(y); },
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
prop_arrow_with_this: {
|
||||||
|
options = {
|
||||||
|
ecma: 6,
|
||||||
|
unsafe_methods: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
function run(arg) {
|
||||||
|
console.log(arg === this ? "global" : arg === foo ? "foo" : arg);
|
||||||
|
}
|
||||||
|
var foo = {
|
||||||
|
func_no_this: function() { run(); },
|
||||||
|
func_with_this: function() { run(this); },
|
||||||
|
arrow_no_this: () => { run(); },
|
||||||
|
arrow_with_this: () => { run(this); },
|
||||||
|
};
|
||||||
|
for (var key in foo) foo[key]();
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
function run(arg) {
|
||||||
|
console.log(arg === this ? "global" : arg === foo ? "foo" : arg);
|
||||||
|
}
|
||||||
|
var foo = {
|
||||||
|
func_no_this() { run(); },
|
||||||
|
func_with_this() { run(this); },
|
||||||
|
arrow_no_this() { run(); },
|
||||||
|
arrow_with_this: () => { run(this); },
|
||||||
|
};
|
||||||
|
for (var key in foo) foo[key]();
|
||||||
|
}
|
||||||
|
expect_stdout: [
|
||||||
|
"undefined",
|
||||||
|
"foo",
|
||||||
|
"undefined",
|
||||||
|
"global",
|
||||||
|
]
|
||||||
|
node_version: ">=4"
|
||||||
|
}
|
||||||
|
|
||||||
|
prop_arrow_with_nested_this: {
|
||||||
|
options = {
|
||||||
|
ecma: 6,
|
||||||
|
unsafe_methods: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
function run(arg) {
|
||||||
|
console.log(arg === this ? "global" : arg === foo ? "foo" : arg);
|
||||||
|
}
|
||||||
|
var foo = {
|
||||||
|
func_func_this: function() { (function() { run(this); })(); },
|
||||||
|
func_arrow_this: function() { (() => { run(this); })(); },
|
||||||
|
arrow_func_this: () => { (function() { run(this); })(); },
|
||||||
|
arrow_arrow_this: () => { (() => { run(this); })(); },
|
||||||
|
};
|
||||||
|
for (var key in foo) foo[key]();
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
function run(arg) {
|
||||||
|
console.log(arg === this ? "global" : arg === foo ? "foo" : arg);
|
||||||
|
}
|
||||||
|
var foo = {
|
||||||
|
func_func_this() { (function() { run(this); })(); },
|
||||||
|
func_arrow_this() { (() => { run(this); })(); },
|
||||||
|
arrow_func_this() { (function() { run(this); })(); },
|
||||||
|
arrow_arrow_this: () => { (() => { run(this); })(); },
|
||||||
|
};
|
||||||
|
for (var key in foo) foo[key]();
|
||||||
|
}
|
||||||
|
expect_stdout: [
|
||||||
|
"global",
|
||||||
|
"foo",
|
||||||
|
"global",
|
||||||
|
"global",
|
||||||
|
]
|
||||||
|
node_version: ">=4"
|
||||||
|
}
|
||||||
|
|||||||
@@ -142,11 +142,11 @@ destructuring_arguments_3: {
|
|||||||
}
|
}
|
||||||
input: {
|
input: {
|
||||||
function fn3({x: {y: {z: {} = 42}}}) {}
|
function fn3({x: {y: {z: {} = 42}}}) {}
|
||||||
const { cover = (function () {}), xCover = (0, function() {}) } = {};
|
const { a = (function () {}), b = (0, function() {}) } = {};
|
||||||
let { cover = (function () {}), xCover = (0, function() {}) } = {};
|
let { c = (function () {}), d = (0, function() {}) } = {};
|
||||||
var { cover = (function () {}), xCover = (0, function() {}) } = {};
|
var { e = (function () {}), f = (0, function() {}) } = {};
|
||||||
}
|
}
|
||||||
expect_exact: "function fn3({x:{y:{z:{}=42}}}){}const{cover=function(){},xCover=(0,function(){})}={};let{cover=function(){},xCover=(0,function(){})}={};var{cover=function(){},xCover=(0,function(){})}={};"
|
expect_exact: "function fn3({x:{y:{z:{}=42}}}){}const{a=function(){},b=(0,function(){})}={};let{c=function(){},d=(0,function(){})}={};var{e=function(){},f=(0,function(){})}={};"
|
||||||
}
|
}
|
||||||
|
|
||||||
default_arguments: {
|
default_arguments: {
|
||||||
|
|||||||
@@ -1,7 +1,8 @@
|
|||||||
keep_properties: {
|
keep_properties: {
|
||||||
options = {
|
options = {
|
||||||
properties: false
|
evaluate: true,
|
||||||
};
|
properties: false,
|
||||||
|
}
|
||||||
input: {
|
input: {
|
||||||
a["foo"] = "bar";
|
a["foo"] = "bar";
|
||||||
}
|
}
|
||||||
@@ -12,9 +13,12 @@ keep_properties: {
|
|||||||
|
|
||||||
dot_properties: {
|
dot_properties: {
|
||||||
options = {
|
options = {
|
||||||
|
evaluate: true,
|
||||||
properties: true,
|
properties: true,
|
||||||
|
}
|
||||||
|
beautify = {
|
||||||
ie8: true,
|
ie8: true,
|
||||||
};
|
}
|
||||||
input: {
|
input: {
|
||||||
a["foo"] = "bar";
|
a["foo"] = "bar";
|
||||||
a["if"] = "if";
|
a["if"] = "if";
|
||||||
@@ -35,9 +39,12 @@ dot_properties: {
|
|||||||
|
|
||||||
dot_properties_es5: {
|
dot_properties_es5: {
|
||||||
options = {
|
options = {
|
||||||
|
evaluate: true,
|
||||||
properties: true,
|
properties: true,
|
||||||
|
}
|
||||||
|
beautify = {
|
||||||
ie8: false,
|
ie8: false,
|
||||||
};
|
}
|
||||||
input: {
|
input: {
|
||||||
a["foo"] = "bar";
|
a["foo"] = "bar";
|
||||||
a["if"] = "if";
|
a["if"] = "if";
|
||||||
@@ -57,8 +64,8 @@ dot_properties_es5: {
|
|||||||
sub_properties: {
|
sub_properties: {
|
||||||
options = {
|
options = {
|
||||||
evaluate: true,
|
evaluate: true,
|
||||||
properties: true
|
properties: true,
|
||||||
};
|
}
|
||||||
input: {
|
input: {
|
||||||
a[0] = 0;
|
a[0] = 0;
|
||||||
a["0"] = 1;
|
a["0"] = 1;
|
||||||
@@ -77,18 +84,18 @@ sub_properties: {
|
|||||||
a[3.14] = 3;
|
a[3.14] = 3;
|
||||||
a.if = 4;
|
a.if = 4;
|
||||||
a["foo bar"] = 5;
|
a["foo bar"] = 5;
|
||||||
a[NaN] = 6;
|
a.NaN = 6;
|
||||||
a[null] = 7;
|
a.null = 7;
|
||||||
a[void 0] = 8;
|
a[void 0] = 8;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
evaluate_array_length: {
|
evaluate_array_length: {
|
||||||
options = {
|
options = {
|
||||||
|
evaluate: true,
|
||||||
properties: true,
|
properties: true,
|
||||||
unsafe: true,
|
unsafe: true,
|
||||||
evaluate: true
|
}
|
||||||
};
|
|
||||||
input: {
|
input: {
|
||||||
a = [1, 2, 3].length;
|
a = [1, 2, 3].length;
|
||||||
a = [1, 2, 3].join()["len" + "gth"];
|
a = [1, 2, 3].join()["len" + "gth"];
|
||||||
@@ -105,10 +112,10 @@ evaluate_array_length: {
|
|||||||
|
|
||||||
evaluate_string_length: {
|
evaluate_string_length: {
|
||||||
options = {
|
options = {
|
||||||
|
evaluate: true,
|
||||||
properties: true,
|
properties: true,
|
||||||
unsafe: true,
|
unsafe: true,
|
||||||
evaluate: true
|
}
|
||||||
};
|
|
||||||
input: {
|
input: {
|
||||||
a = "foo".length;
|
a = "foo".length;
|
||||||
a = ("foo" + "bar")["len" + "gth"];
|
a = ("foo" + "bar")["len" + "gth"];
|
||||||
@@ -124,9 +131,11 @@ evaluate_string_length: {
|
|||||||
}
|
}
|
||||||
|
|
||||||
mangle_properties: {
|
mangle_properties: {
|
||||||
mangle_props = {
|
mangle = {
|
||||||
keep_quoted: false
|
properties: {
|
||||||
};
|
keep_quoted: false,
|
||||||
|
},
|
||||||
|
}
|
||||||
input: {
|
input: {
|
||||||
a["foo"] = "bar";
|
a["foo"] = "bar";
|
||||||
a.color = "red";
|
a.color = "red";
|
||||||
@@ -135,21 +144,24 @@ mangle_properties: {
|
|||||||
a['run']({color: "blue", foo: "baz"});
|
a['run']({color: "blue", foo: "baz"});
|
||||||
}
|
}
|
||||||
expect: {
|
expect: {
|
||||||
a["o"] = "bar";
|
a["a"] = "bar";
|
||||||
a.a = "red";
|
a.b = "red";
|
||||||
x = {r: 10};
|
x = {o: 10};
|
||||||
a.b(x.r, a.o);
|
a.r(x.o, a.a);
|
||||||
a['b']({a: "blue", o: "baz"});
|
a['r']({b: "blue", a: "baz"});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
mangle_unquoted_properties: {
|
mangle_unquoted_properties: {
|
||||||
options = {
|
options = {
|
||||||
properties: false
|
evaluate: true,
|
||||||
|
properties: false,
|
||||||
}
|
}
|
||||||
mangle_props = {
|
mangle = {
|
||||||
builtins: true,
|
properties: {
|
||||||
keep_quoted: true
|
builtins: true,
|
||||||
|
keep_quoted: true,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
beautify = {
|
beautify = {
|
||||||
beautify: false,
|
beautify: false,
|
||||||
@@ -178,24 +190,26 @@ mangle_unquoted_properties: {
|
|||||||
function f1() {
|
function f1() {
|
||||||
a["foo"] = "bar";
|
a["foo"] = "bar";
|
||||||
a.color = "red";
|
a.color = "red";
|
||||||
a.o = 2;
|
a.r = 2;
|
||||||
x = {"bar": 10, f: 7};
|
x = {"bar": 10, b: 7};
|
||||||
a.f = 9;
|
a.b = 9;
|
||||||
}
|
}
|
||||||
function f2() {
|
function f2() {
|
||||||
a.foo = "bar";
|
a.foo = "bar";
|
||||||
a['color'] = "red";
|
a['color'] = "red";
|
||||||
x = {bar: 10, f: 7};
|
x = {bar: 10, b: 7};
|
||||||
a.f = 9;
|
a.b = 9;
|
||||||
a.o = 3;
|
a.r = 3;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
mangle_debug: {
|
mangle_debug: {
|
||||||
mangle_props = {
|
mangle = {
|
||||||
debug: ""
|
properties: {
|
||||||
};
|
debug: "",
|
||||||
|
},
|
||||||
|
}
|
||||||
input: {
|
input: {
|
||||||
a.foo = "bar";
|
a.foo = "bar";
|
||||||
x = { baz: "ban" };
|
x = { baz: "ban" };
|
||||||
@@ -207,9 +221,11 @@ mangle_debug: {
|
|||||||
}
|
}
|
||||||
|
|
||||||
mangle_debug_true: {
|
mangle_debug_true: {
|
||||||
mangle_props = {
|
mangle = {
|
||||||
debug: true
|
properties: {
|
||||||
};
|
debug: true,
|
||||||
|
},
|
||||||
|
}
|
||||||
input: {
|
input: {
|
||||||
a.foo = "bar";
|
a.foo = "bar";
|
||||||
x = { baz: "ban" };
|
x = { baz: "ban" };
|
||||||
@@ -221,9 +237,11 @@ mangle_debug_true: {
|
|||||||
}
|
}
|
||||||
|
|
||||||
mangle_debug_suffix: {
|
mangle_debug_suffix: {
|
||||||
mangle_props = {
|
mangle = {
|
||||||
debug: "XYZ"
|
properties: {
|
||||||
};
|
debug: "XYZ",
|
||||||
|
},
|
||||||
|
}
|
||||||
input: {
|
input: {
|
||||||
a.foo = "bar";
|
a.foo = "bar";
|
||||||
x = { baz: "ban" };
|
x = { baz: "ban" };
|
||||||
@@ -236,13 +254,16 @@ mangle_debug_suffix: {
|
|||||||
|
|
||||||
mangle_debug_suffix_keep_quoted: {
|
mangle_debug_suffix_keep_quoted: {
|
||||||
options = {
|
options = {
|
||||||
properties: false
|
evaluate: true,
|
||||||
|
properties: false,
|
||||||
}
|
}
|
||||||
mangle_props = {
|
mangle = {
|
||||||
builtins: true,
|
properties: {
|
||||||
keep_quoted: true,
|
builtins: true,
|
||||||
debug: "XYZ",
|
debug: "XYZ",
|
||||||
reserved: []
|
keep_quoted: true,
|
||||||
|
reserved: [],
|
||||||
|
},
|
||||||
}
|
}
|
||||||
beautify = {
|
beautify = {
|
||||||
beautify: false,
|
beautify: false,
|
||||||
@@ -659,3 +680,654 @@ accessor_this: {
|
|||||||
expect_exact: 'var a=1;var b={get this(){return a},set this(c){a=c}};console.log(b.this,b.this=2,b.this);'
|
expect_exact: 'var a=1;var b={get this(){return a},set this(c){a=c}};console.log(b.this,b.this=2,b.this);'
|
||||||
expect_stdout: "1 2 2"
|
expect_stdout: "1 2 2"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
issue_2208_1: {
|
||||||
|
options = {
|
||||||
|
inline: true,
|
||||||
|
properties: true,
|
||||||
|
side_effects: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
console.log({
|
||||||
|
p: function() {
|
||||||
|
return 42;
|
||||||
|
}
|
||||||
|
}.p());
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
console.log(42);
|
||||||
|
}
|
||||||
|
expect_stdout: "42"
|
||||||
|
}
|
||||||
|
|
||||||
|
issue_2208_2: {
|
||||||
|
options = {
|
||||||
|
inline: true,
|
||||||
|
properties: true,
|
||||||
|
side_effects: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
console.log({
|
||||||
|
a: 42,
|
||||||
|
p: function() {
|
||||||
|
return this.a;
|
||||||
|
}
|
||||||
|
}.p());
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
console.log({
|
||||||
|
a: 42,
|
||||||
|
p: function() {
|
||||||
|
return this.a;
|
||||||
|
}
|
||||||
|
}.p());
|
||||||
|
}
|
||||||
|
expect_stdout: "42"
|
||||||
|
}
|
||||||
|
|
||||||
|
issue_2208_3: {
|
||||||
|
options = {
|
||||||
|
inline: true,
|
||||||
|
properties: true,
|
||||||
|
side_effects: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
a = 42;
|
||||||
|
console.log({
|
||||||
|
p: function() {
|
||||||
|
return function() {
|
||||||
|
return this.a;
|
||||||
|
}();
|
||||||
|
}
|
||||||
|
}.p());
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
a = 42;
|
||||||
|
console.log(function() {
|
||||||
|
return this.a;
|
||||||
|
}());
|
||||||
|
}
|
||||||
|
expect_stdout: "42"
|
||||||
|
}
|
||||||
|
|
||||||
|
issue_2208_4: {
|
||||||
|
options = {
|
||||||
|
inline: true,
|
||||||
|
properties: true,
|
||||||
|
side_effects: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
function foo() {}
|
||||||
|
console.log({
|
||||||
|
a: foo(),
|
||||||
|
p: function() {
|
||||||
|
return 42;
|
||||||
|
}
|
||||||
|
}.p());
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
function foo() {}
|
||||||
|
console.log((foo(), function() {
|
||||||
|
return 42;
|
||||||
|
})());
|
||||||
|
}
|
||||||
|
expect_stdout: "42"
|
||||||
|
}
|
||||||
|
|
||||||
|
issue_2208_5: {
|
||||||
|
options = {
|
||||||
|
inline: true,
|
||||||
|
properties: true,
|
||||||
|
side_effects: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
console.log({
|
||||||
|
p: "FAIL",
|
||||||
|
p: function() {
|
||||||
|
return 42;
|
||||||
|
}
|
||||||
|
}.p());
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
console.log(42);
|
||||||
|
}
|
||||||
|
expect_stdout: "42"
|
||||||
|
}
|
||||||
|
|
||||||
|
issue_2208_6: {
|
||||||
|
options = {
|
||||||
|
inline: true,
|
||||||
|
properties: true,
|
||||||
|
side_effects: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
console.log({
|
||||||
|
p: () => 42
|
||||||
|
}.p());
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
console.log(42);
|
||||||
|
}
|
||||||
|
expect_stdout: "42"
|
||||||
|
node_version: ">=4"
|
||||||
|
}
|
||||||
|
|
||||||
|
issue_2208_7: {
|
||||||
|
options = {
|
||||||
|
ecma: 6,
|
||||||
|
inline: true,
|
||||||
|
properties: true,
|
||||||
|
side_effects: true,
|
||||||
|
unsafe_arrows: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
console.log({
|
||||||
|
p() {
|
||||||
|
return 42;
|
||||||
|
}
|
||||||
|
}.p());
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
console.log(42);
|
||||||
|
}
|
||||||
|
expect_stdout: "42"
|
||||||
|
node_version: ">=4"
|
||||||
|
}
|
||||||
|
|
||||||
|
issue_2208_8: {
|
||||||
|
options = {
|
||||||
|
ecma: 6,
|
||||||
|
inline: true,
|
||||||
|
properties: true,
|
||||||
|
side_effects: true,
|
||||||
|
unsafe_arrows: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
console.log({
|
||||||
|
*p() {
|
||||||
|
return x();
|
||||||
|
}
|
||||||
|
}.p());
|
||||||
|
console.log({
|
||||||
|
async p() {
|
||||||
|
return await x();
|
||||||
|
}
|
||||||
|
}.p());
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
console.log({
|
||||||
|
*p() {
|
||||||
|
return x();
|
||||||
|
}
|
||||||
|
}.p());
|
||||||
|
console.log((async () => {
|
||||||
|
return await x();
|
||||||
|
})());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
issue_2208_9: {
|
||||||
|
options = {
|
||||||
|
inline: true,
|
||||||
|
properties: true,
|
||||||
|
side_effects: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
a = 42;
|
||||||
|
console.log({
|
||||||
|
p: () => {
|
||||||
|
return function() {
|
||||||
|
return this.a;
|
||||||
|
}();
|
||||||
|
}
|
||||||
|
}.p());
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
a = 42;
|
||||||
|
console.log(function() {
|
||||||
|
return this.a;
|
||||||
|
}());
|
||||||
|
}
|
||||||
|
expect_stdout: "42"
|
||||||
|
node_version: ">=4"
|
||||||
|
}
|
||||||
|
|
||||||
|
methods_keep_quoted_true: {
|
||||||
|
options = {
|
||||||
|
arrows: true,
|
||||||
|
ecma: 6,
|
||||||
|
unsafe_methods: true,
|
||||||
|
}
|
||||||
|
mangle = {
|
||||||
|
properties: {
|
||||||
|
keep_quoted: true,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
class C { "Quoted"(){} Unquoted(){} }
|
||||||
|
f1({ "Quoted"(){}, Unquoted(){}, "Prop": 3 });
|
||||||
|
f2({ "Quoted": function(){} });
|
||||||
|
f3({ "Quoted": ()=>{} });
|
||||||
|
}
|
||||||
|
expect_exact: "class C{Quoted(){}o(){}}f1({Quoted(){},o(){},Prop:3});f2({Quoted(){}});f3({Quoted(){}});"
|
||||||
|
}
|
||||||
|
|
||||||
|
methods_keep_quoted_false: {
|
||||||
|
options = {
|
||||||
|
arrows: true,
|
||||||
|
ecma: 6,
|
||||||
|
unsafe_methods: true,
|
||||||
|
}
|
||||||
|
mangle = {
|
||||||
|
properties: {
|
||||||
|
keep_quoted: false,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
class C { "Quoted"(){} Unquoted(){} }
|
||||||
|
f1({ "Quoted"(){}, Unquoted(){}, "Prop": 3 });
|
||||||
|
f2({ "Quoted": function(){} });
|
||||||
|
f3({ "Quoted": ()=>{} });
|
||||||
|
}
|
||||||
|
expect_exact: "class C{o(){}d(){}}f1({o(){},d(){},e:3});f2({o(){}});f3({o(){}});"
|
||||||
|
}
|
||||||
|
|
||||||
|
methods_keep_quoted_from_dead_code: {
|
||||||
|
options = {
|
||||||
|
arrows: true,
|
||||||
|
booleans: true,
|
||||||
|
conditionals: true,
|
||||||
|
dead_code: true,
|
||||||
|
ecma: 6,
|
||||||
|
evaluate: true,
|
||||||
|
reduce_funcs: true,
|
||||||
|
reduce_vars: true,
|
||||||
|
side_effects: true,
|
||||||
|
unsafe_methods: true,
|
||||||
|
}
|
||||||
|
mangle = {
|
||||||
|
properties: {
|
||||||
|
keep_quoted: true,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
class C { Quoted(){} Unquoted(){} }
|
||||||
|
f1({ Quoted(){}, Unquoted(){}, "Prop": 3 });
|
||||||
|
f2({ Quoted: function(){} });
|
||||||
|
f3({ Quoted: ()=>{} });
|
||||||
|
0 && obj["Quoted"];
|
||||||
|
}
|
||||||
|
expect_exact: "class C{Quoted(){}o(){}}f1({Quoted(){},o(){},Prop:3});f2({Quoted(){}});f3({Quoted(){}});"
|
||||||
|
}
|
||||||
|
|
||||||
|
issue_2256: {
|
||||||
|
options = {
|
||||||
|
side_effects: true,
|
||||||
|
}
|
||||||
|
mangle = {
|
||||||
|
properties: {
|
||||||
|
keep_quoted: true,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
({ "keep": 1 });
|
||||||
|
g.keep = g.change;
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
g.keep = g.g;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
issue_2321: {
|
||||||
|
options = {
|
||||||
|
ecma: 6,
|
||||||
|
unsafe_methods: false,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
var f = {
|
||||||
|
foo: function(){ console.log("foo") },
|
||||||
|
bar() { console.log("bar") }
|
||||||
|
};
|
||||||
|
var foo = new f.foo();
|
||||||
|
var bar = f.bar();
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
var f = {
|
||||||
|
foo: function() {
|
||||||
|
console.log("foo");
|
||||||
|
},
|
||||||
|
bar() {
|
||||||
|
console.log("bar");
|
||||||
|
}
|
||||||
|
};
|
||||||
|
var foo = new f.foo();
|
||||||
|
var bar = f.bar();
|
||||||
|
}
|
||||||
|
expect_stdout: [
|
||||||
|
"foo",
|
||||||
|
"bar",
|
||||||
|
]
|
||||||
|
node_version: ">=6"
|
||||||
|
}
|
||||||
|
|
||||||
|
unsafe_methods_regex: {
|
||||||
|
options = {
|
||||||
|
ecma: 6,
|
||||||
|
unsafe_methods: /^[A-Z1]/,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
var f = {
|
||||||
|
123: function(){ console.log("123") },
|
||||||
|
foo: function(){ console.log("foo") },
|
||||||
|
bar() { console.log("bar") },
|
||||||
|
Baz: function(){ console.log("baz") },
|
||||||
|
BOO: function(){ console.log("boo") },
|
||||||
|
null: function(){ console.log("null") },
|
||||||
|
undefined: function(){ console.log("undefined") },
|
||||||
|
};
|
||||||
|
f[123]();
|
||||||
|
new f.foo();
|
||||||
|
f.bar();
|
||||||
|
f.Baz();
|
||||||
|
f.BOO();
|
||||||
|
new f.null();
|
||||||
|
new f.undefined();
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
var f = {
|
||||||
|
123() { console.log("123") },
|
||||||
|
foo: function(){ console.log("foo") },
|
||||||
|
bar() { console.log("bar"); },
|
||||||
|
Baz() { console.log("baz") },
|
||||||
|
BOO() { console.log("boo") },
|
||||||
|
null: function(){ console.log("null") },
|
||||||
|
undefined: function(){ console.log("undefined") },
|
||||||
|
};
|
||||||
|
f[123]();
|
||||||
|
new f.foo();
|
||||||
|
f.bar();
|
||||||
|
f.Baz();
|
||||||
|
f.BOO();
|
||||||
|
new f.null();
|
||||||
|
new f.undefined();
|
||||||
|
}
|
||||||
|
expect_stdout: [
|
||||||
|
"123",
|
||||||
|
"foo",
|
||||||
|
"bar",
|
||||||
|
"baz",
|
||||||
|
"boo",
|
||||||
|
"null",
|
||||||
|
"undefined",
|
||||||
|
]
|
||||||
|
node_version: ">=6"
|
||||||
|
}
|
||||||
|
|
||||||
|
lhs_prop_1: {
|
||||||
|
options = {
|
||||||
|
evaluate: true,
|
||||||
|
properties: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
console.log(++{
|
||||||
|
a: 1
|
||||||
|
}.a);
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
console.log(++{
|
||||||
|
a: 1
|
||||||
|
}.a);
|
||||||
|
}
|
||||||
|
expect_stdout: "2"
|
||||||
|
}
|
||||||
|
|
||||||
|
lhs_prop_2: {
|
||||||
|
options = {
|
||||||
|
evaluate: true,
|
||||||
|
inline: true,
|
||||||
|
properties: true,
|
||||||
|
reduce_funcs: true,
|
||||||
|
reduce_vars: true,
|
||||||
|
side_effects: true,
|
||||||
|
unused: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
[1][0] = 42;
|
||||||
|
(function(a) {
|
||||||
|
a.b = "g";
|
||||||
|
})("abc");
|
||||||
|
(function(a) {
|
||||||
|
a[2] = "g";
|
||||||
|
})("def");
|
||||||
|
(function(a) {
|
||||||
|
a[""] = "g";
|
||||||
|
})("ghi");
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
[1][0] = 42;
|
||||||
|
"abc".b = "g";
|
||||||
|
"def"[2] = "g";
|
||||||
|
"ghi"[""] = "g";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
literal_duplicate_key_side_effects: {
|
||||||
|
options = {
|
||||||
|
properties: true,
|
||||||
|
side_effects: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
console.log({
|
||||||
|
a: "FAIL",
|
||||||
|
a: console.log ? "PASS" : "FAIL"
|
||||||
|
}.a);
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
console.log(console.log ? "PASS" : "FAIL");
|
||||||
|
}
|
||||||
|
expect_stdout: "PASS"
|
||||||
|
}
|
||||||
|
|
||||||
|
prop_side_effects_1: {
|
||||||
|
options = {
|
||||||
|
evaluate: true,
|
||||||
|
inline: true,
|
||||||
|
properties: true,
|
||||||
|
reduce_funcs: true,
|
||||||
|
reduce_vars: true,
|
||||||
|
side_effects: true,
|
||||||
|
toplevel: true,
|
||||||
|
unused: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
var C = 1;
|
||||||
|
console.log(C);
|
||||||
|
var obj = {
|
||||||
|
bar: function() {
|
||||||
|
return C + C;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
console.log(obj.bar());
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
console.log(1);
|
||||||
|
var obj = {
|
||||||
|
bar: function() {
|
||||||
|
return 2;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
console.log(obj.bar());
|
||||||
|
}
|
||||||
|
expect_stdout: [
|
||||||
|
"1",
|
||||||
|
"2",
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
|
prop_side_effects_2: {
|
||||||
|
options = {
|
||||||
|
evaluate: true,
|
||||||
|
inline: true,
|
||||||
|
passes: 2,
|
||||||
|
properties: true,
|
||||||
|
reduce_funcs: true,
|
||||||
|
reduce_vars: true,
|
||||||
|
side_effects: true,
|
||||||
|
toplevel: true,
|
||||||
|
unused: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
var C = 1;
|
||||||
|
console.log(C);
|
||||||
|
var obj = {
|
||||||
|
"": function() {
|
||||||
|
return C + C;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
console.log(obj[""]());
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
console.log(1);
|
||||||
|
console.log(2);
|
||||||
|
}
|
||||||
|
expect_stdout: [
|
||||||
|
"1",
|
||||||
|
"2",
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
|
accessor_1: {
|
||||||
|
options = {
|
||||||
|
properties: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
console.log({
|
||||||
|
a: "FAIL",
|
||||||
|
get a() {
|
||||||
|
return "PASS";
|
||||||
|
}
|
||||||
|
}.a);
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
console.log({
|
||||||
|
a: "FAIL",
|
||||||
|
get a() {
|
||||||
|
return "PASS";
|
||||||
|
}
|
||||||
|
}.a);
|
||||||
|
}
|
||||||
|
expect_stdout: "PASS"
|
||||||
|
node_version: ">=4"
|
||||||
|
}
|
||||||
|
|
||||||
|
accessor_2: {
|
||||||
|
options = {
|
||||||
|
properties: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
console.log({
|
||||||
|
get a() {
|
||||||
|
return "PASS";
|
||||||
|
},
|
||||||
|
set a(v) {},
|
||||||
|
a: "FAIL"
|
||||||
|
}.a);
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
console.log({
|
||||||
|
get a() {
|
||||||
|
return "PASS";
|
||||||
|
},
|
||||||
|
set a(v) {},
|
||||||
|
a: "FAIL"
|
||||||
|
}.a);
|
||||||
|
}
|
||||||
|
expect_stdout: true
|
||||||
|
}
|
||||||
|
|
||||||
|
array_hole: {
|
||||||
|
options = {
|
||||||
|
properties: true,
|
||||||
|
side_effects: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
console.log(
|
||||||
|
[ 1, 2, , 3][1],
|
||||||
|
[ 1, 2, , 3][2],
|
||||||
|
[ 1, 2, , 3][3]
|
||||||
|
);
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
console.log(2, void 0, 3);
|
||||||
|
}
|
||||||
|
expect_stdout: "2 undefined 3"
|
||||||
|
}
|
||||||
|
|
||||||
|
computed_property: {
|
||||||
|
options = {
|
||||||
|
properties: true,
|
||||||
|
side_effects: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
console.log({
|
||||||
|
a: "bar",
|
||||||
|
[console.log("foo")]: 42,
|
||||||
|
}.a);
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
console.log([
|
||||||
|
"bar",
|
||||||
|
console.log("foo")
|
||||||
|
][0]);
|
||||||
|
}
|
||||||
|
expect_stdout: [
|
||||||
|
"foo",
|
||||||
|
"bar"
|
||||||
|
]
|
||||||
|
node_version: ">=4"
|
||||||
|
}
|
||||||
|
|
||||||
|
new_this: {
|
||||||
|
options = {
|
||||||
|
properties: true,
|
||||||
|
side_effects: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
new {
|
||||||
|
f: function(a) {
|
||||||
|
this.a = a;
|
||||||
|
}
|
||||||
|
}.f(42);
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
new function(a) {
|
||||||
|
this.a = a;
|
||||||
|
}(42);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
issue_2513: {
|
||||||
|
options = {
|
||||||
|
evaluate: true,
|
||||||
|
properties: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
!function(Infinity, NaN, undefined) {
|
||||||
|
console.log("a"[1/0], "b"["Infinity"]);
|
||||||
|
console.log("c"[0/0], "d"["NaN"]);
|
||||||
|
console.log("e"[void 0], "f"["undefined"]);
|
||||||
|
}(0, 0, 0);
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
!function(Infinity, NaN, undefined) {
|
||||||
|
console.log("a"[1/0], "b"[1/0]);
|
||||||
|
console.log("c".NaN, "d".NaN);
|
||||||
|
console.log("e"[void 0], "f"[void 0]);
|
||||||
|
}(0, 0, 0);
|
||||||
|
}
|
||||||
|
expect_stdout: [
|
||||||
|
"undefined undefined",
|
||||||
|
"undefined undefined",
|
||||||
|
"undefined undefined",
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
strict: {
|
strict: {
|
||||||
options = {
|
options = {
|
||||||
pure_getters: "strict",
|
pure_getters: "strict",
|
||||||
|
reduce_funcs: false,
|
||||||
reduce_vars: false,
|
reduce_vars: false,
|
||||||
side_effects: true,
|
side_effects: true,
|
||||||
toplevel: true,
|
toplevel: true,
|
||||||
@@ -30,6 +31,7 @@ strict: {
|
|||||||
strict_reduce_vars: {
|
strict_reduce_vars: {
|
||||||
options = {
|
options = {
|
||||||
pure_getters: "strict",
|
pure_getters: "strict",
|
||||||
|
reduce_funcs: true,
|
||||||
reduce_vars: true,
|
reduce_vars: true,
|
||||||
side_effects: true,
|
side_effects: true,
|
||||||
toplevel: true,
|
toplevel: true,
|
||||||
@@ -58,6 +60,7 @@ strict_reduce_vars: {
|
|||||||
unsafe: {
|
unsafe: {
|
||||||
options = {
|
options = {
|
||||||
pure_getters: true,
|
pure_getters: true,
|
||||||
|
reduce_funcs: false,
|
||||||
reduce_vars: false,
|
reduce_vars: false,
|
||||||
side_effects: true,
|
side_effects: true,
|
||||||
toplevel: true,
|
toplevel: true,
|
||||||
@@ -84,6 +87,7 @@ unsafe: {
|
|||||||
unsafe_reduce_vars: {
|
unsafe_reduce_vars: {
|
||||||
options = {
|
options = {
|
||||||
pure_getters: true,
|
pure_getters: true,
|
||||||
|
reduce_funcs: true,
|
||||||
reduce_vars: true,
|
reduce_vars: true,
|
||||||
side_effects: true,
|
side_effects: true,
|
||||||
toplevel: true,
|
toplevel: true,
|
||||||
@@ -185,6 +189,7 @@ issue_2110_1: {
|
|||||||
pure_getters: "strict",
|
pure_getters: "strict",
|
||||||
sequences: true,
|
sequences: true,
|
||||||
side_effects: true,
|
side_effects: true,
|
||||||
|
reduce_funcs: true,
|
||||||
reduce_vars: true,
|
reduce_vars: true,
|
||||||
unused: true,
|
unused: true,
|
||||||
}
|
}
|
||||||
@@ -215,6 +220,7 @@ issue_2110_2: {
|
|||||||
options = {
|
options = {
|
||||||
collapse_vars: true,
|
collapse_vars: true,
|
||||||
pure_getters: "strict",
|
pure_getters: "strict",
|
||||||
|
reduce_funcs: true,
|
||||||
reduce_vars: true,
|
reduce_vars: true,
|
||||||
unused: true,
|
unused: true,
|
||||||
}
|
}
|
||||||
@@ -247,6 +253,7 @@ set_immutable_1: {
|
|||||||
collapse_vars: true,
|
collapse_vars: true,
|
||||||
evaluate: true,
|
evaluate: true,
|
||||||
pure_getters: "strict",
|
pure_getters: "strict",
|
||||||
|
reduce_funcs: true,
|
||||||
reduce_vars: true,
|
reduce_vars: true,
|
||||||
toplevel: true,
|
toplevel: true,
|
||||||
unused: true,
|
unused: true,
|
||||||
@@ -270,6 +277,7 @@ set_immutable_2: {
|
|||||||
cascade: true,
|
cascade: true,
|
||||||
conditionals: true,
|
conditionals: true,
|
||||||
pure_getters: "strict",
|
pure_getters: "strict",
|
||||||
|
reduce_funcs: true,
|
||||||
reduce_vars: true,
|
reduce_vars: true,
|
||||||
sequences: true,
|
sequences: true,
|
||||||
side_effects: true,
|
side_effects: true,
|
||||||
@@ -293,6 +301,7 @@ set_immutable_3: {
|
|||||||
collapse_vars: true,
|
collapse_vars: true,
|
||||||
evaluate: true,
|
evaluate: true,
|
||||||
pure_getters: "strict",
|
pure_getters: "strict",
|
||||||
|
reduce_funcs: true,
|
||||||
reduce_vars: true,
|
reduce_vars: true,
|
||||||
toplevel: true,
|
toplevel: true,
|
||||||
unused: true,
|
unused: true,
|
||||||
@@ -318,6 +327,7 @@ set_immutable_4: {
|
|||||||
cascade: true,
|
cascade: true,
|
||||||
conditionals: true,
|
conditionals: true,
|
||||||
pure_getters: "strict",
|
pure_getters: "strict",
|
||||||
|
reduce_funcs: true,
|
||||||
reduce_vars: true,
|
reduce_vars: true,
|
||||||
sequences: true,
|
sequences: true,
|
||||||
side_effects: true,
|
side_effects: true,
|
||||||
@@ -343,6 +353,7 @@ set_mutable_1: {
|
|||||||
collapse_vars: true,
|
collapse_vars: true,
|
||||||
evaluate: true,
|
evaluate: true,
|
||||||
pure_getters: "strict",
|
pure_getters: "strict",
|
||||||
|
reduce_funcs: true,
|
||||||
reduce_vars: true,
|
reduce_vars: true,
|
||||||
unused: true,
|
unused: true,
|
||||||
}
|
}
|
||||||
@@ -367,6 +378,7 @@ set_mutable_2: {
|
|||||||
cascade: true,
|
cascade: true,
|
||||||
conditionals: true,
|
conditionals: true,
|
||||||
pure_getters: "strict",
|
pure_getters: "strict",
|
||||||
|
reduce_funcs: true,
|
||||||
reduce_vars: true,
|
reduce_vars: true,
|
||||||
sequences: true,
|
sequences: true,
|
||||||
side_effects: true,
|
side_effects: true,
|
||||||
@@ -385,3 +397,341 @@ set_mutable_2: {
|
|||||||
}
|
}
|
||||||
expect_stdout: "PASS"
|
expect_stdout: "PASS"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
issue_2265_1: {
|
||||||
|
options = {
|
||||||
|
pure_getters: "strict",
|
||||||
|
side_effects: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
({ ...{} }).p;
|
||||||
|
({ ...g }).p;
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
({ ...g }).p;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
issue_2265_2: {
|
||||||
|
options = {
|
||||||
|
pure_getters: "strict",
|
||||||
|
reduce_funcs: true,
|
||||||
|
reduce_vars: true,
|
||||||
|
side_effects: true,
|
||||||
|
toplevel: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
var a = {
|
||||||
|
get b() {
|
||||||
|
throw 0;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
({...a}).b;
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
var a = {
|
||||||
|
get b() {
|
||||||
|
throw 0;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
({...a}).b;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
issue_2265_3: {
|
||||||
|
options = {
|
||||||
|
pure_getters: "strict",
|
||||||
|
reduce_funcs: true,
|
||||||
|
reduce_vars: true,
|
||||||
|
side_effects: true,
|
||||||
|
toplevel: true,
|
||||||
|
unused: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
var a = {
|
||||||
|
set b() {
|
||||||
|
throw 0;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
({...a}).b;
|
||||||
|
}
|
||||||
|
expect: {}
|
||||||
|
}
|
||||||
|
|
||||||
|
issue_2265_4: {
|
||||||
|
options = {
|
||||||
|
pure_getters: "strict",
|
||||||
|
reduce_funcs: true,
|
||||||
|
reduce_vars: true,
|
||||||
|
side_effects: true,
|
||||||
|
toplevel: true,
|
||||||
|
unused: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
var a = { b: 1 };
|
||||||
|
({...a}).b;
|
||||||
|
}
|
||||||
|
expect: {}
|
||||||
|
}
|
||||||
|
|
||||||
|
issue_2313_1: {
|
||||||
|
options = {
|
||||||
|
cascade: true,
|
||||||
|
conditionals: true,
|
||||||
|
pure_getters: "strict",
|
||||||
|
sequences: true,
|
||||||
|
side_effects: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
function x() {
|
||||||
|
console.log(1);
|
||||||
|
return {
|
||||||
|
y: function() {
|
||||||
|
console.log(2);
|
||||||
|
return {
|
||||||
|
z: 0
|
||||||
|
};
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
x().y().z++;
|
||||||
|
if (x().y().z) {
|
||||||
|
console.log(3);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
function x() {
|
||||||
|
return console.log(1), {
|
||||||
|
y: function() {
|
||||||
|
return console.log(2), {
|
||||||
|
z: 0
|
||||||
|
};
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
x().y().z++,
|
||||||
|
x().y().z && console.log(3);
|
||||||
|
}
|
||||||
|
expect_stdout: [
|
||||||
|
"1",
|
||||||
|
"2",
|
||||||
|
"1",
|
||||||
|
"2",
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
|
issue_2313_2: {
|
||||||
|
options = {
|
||||||
|
cascade: true,
|
||||||
|
conditionals: true,
|
||||||
|
pure_getters: true,
|
||||||
|
sequences: true,
|
||||||
|
side_effects: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
function x() {
|
||||||
|
console.log(1);
|
||||||
|
return {
|
||||||
|
y: function() {
|
||||||
|
console.log(2);
|
||||||
|
return {
|
||||||
|
z: 0
|
||||||
|
};
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
x().y().z++;
|
||||||
|
if (x().y().z) {
|
||||||
|
console.log(3);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
function x() {
|
||||||
|
return console.log(1), {
|
||||||
|
y: function() {
|
||||||
|
return console.log(2), {
|
||||||
|
z: 0
|
||||||
|
};
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
x().y().z++,
|
||||||
|
x().y().z && console.log(3);
|
||||||
|
}
|
||||||
|
expect_stdout: [
|
||||||
|
"1",
|
||||||
|
"2",
|
||||||
|
"1",
|
||||||
|
"2",
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
|
issue_2313_3: {
|
||||||
|
options = {
|
||||||
|
collapse_vars: true,
|
||||||
|
conditionals: true,
|
||||||
|
pure_getters: "strict",
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
function x() {
|
||||||
|
console.log(1);
|
||||||
|
return {
|
||||||
|
y: function() {
|
||||||
|
console.log(2);
|
||||||
|
return {
|
||||||
|
z: 0
|
||||||
|
};
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
x().y().z++;
|
||||||
|
if (x().y().z) {
|
||||||
|
console.log(3);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
function x() {
|
||||||
|
console.log(1);
|
||||||
|
return {
|
||||||
|
y: function() {
|
||||||
|
console.log(2);
|
||||||
|
return {
|
||||||
|
z: 0
|
||||||
|
};
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
x().y().z++;
|
||||||
|
x().y().z && console.log(3);
|
||||||
|
}
|
||||||
|
expect_stdout: [
|
||||||
|
"1",
|
||||||
|
"2",
|
||||||
|
"1",
|
||||||
|
"2",
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
|
issue_2313_4: {
|
||||||
|
options = {
|
||||||
|
collapse_vars: true,
|
||||||
|
conditionals: true,
|
||||||
|
pure_getters: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
function x() {
|
||||||
|
console.log(1);
|
||||||
|
return {
|
||||||
|
y: function() {
|
||||||
|
console.log(2);
|
||||||
|
return {
|
||||||
|
z: 0
|
||||||
|
};
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
x().y().z++;
|
||||||
|
if (x().y().z) {
|
||||||
|
console.log(3);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
function x() {
|
||||||
|
console.log(1);
|
||||||
|
return {
|
||||||
|
y: function() {
|
||||||
|
console.log(2);
|
||||||
|
return {
|
||||||
|
z: 0
|
||||||
|
};
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
x().y().z++;
|
||||||
|
x().y().z && console.log(3);
|
||||||
|
}
|
||||||
|
expect_stdout: [
|
||||||
|
"1",
|
||||||
|
"2",
|
||||||
|
"1",
|
||||||
|
"2",
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
|
issue_2313_5: {
|
||||||
|
options = {
|
||||||
|
pure_getters: "strict",
|
||||||
|
side_effects: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
x().y++;
|
||||||
|
x().y;
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
x().y++;
|
||||||
|
x().y;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
issue_2313_6: {
|
||||||
|
options = {
|
||||||
|
pure_getters: true,
|
||||||
|
side_effects: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
x().y++;
|
||||||
|
x().y;
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
x().y++;
|
||||||
|
x();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
issue_2313_7: {
|
||||||
|
options = {
|
||||||
|
collapse_vars: true,
|
||||||
|
conditionals: true,
|
||||||
|
pure_getters: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
var a = 0, b = 0;
|
||||||
|
class foo {
|
||||||
|
get c() {
|
||||||
|
a++;
|
||||||
|
return 42;
|
||||||
|
}
|
||||||
|
set c(c) {
|
||||||
|
b++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
class bar extends foo {
|
||||||
|
d() {
|
||||||
|
super.c++;
|
||||||
|
if (super.c) console.log(a, b);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
new bar().d();
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
var a = 0, b = 0;
|
||||||
|
class foo {
|
||||||
|
get c() {
|
||||||
|
a++;
|
||||||
|
return 42;
|
||||||
|
}
|
||||||
|
set c(c) {
|
||||||
|
b++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
class bar extends foo {
|
||||||
|
d() {
|
||||||
|
super.c++;
|
||||||
|
super.c && console.log(a, b);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
new bar().d();
|
||||||
|
}
|
||||||
|
expect_stdout: "2 1"
|
||||||
|
node_version: ">=6"
|
||||||
|
}
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
536
test/compress/rename.js
Normal file
536
test/compress/rename.js
Normal file
@@ -0,0 +1,536 @@
|
|||||||
|
mangle_catch: {
|
||||||
|
rename = true
|
||||||
|
options = {
|
||||||
|
ie8: false,
|
||||||
|
toplevel: false,
|
||||||
|
}
|
||||||
|
mangle = {
|
||||||
|
ie8: false,
|
||||||
|
toplevel: false,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
var a = "FAIL";
|
||||||
|
try {
|
||||||
|
throw 1;
|
||||||
|
} catch (args) {
|
||||||
|
a = "PASS";
|
||||||
|
}
|
||||||
|
console.log(a);
|
||||||
|
}
|
||||||
|
expect_exact: 'var a="FAIL";try{throw 1}catch(o){a="PASS"}console.log(a);'
|
||||||
|
expect_stdout: "PASS"
|
||||||
|
}
|
||||||
|
|
||||||
|
mangle_catch_ie8: {
|
||||||
|
rename = true
|
||||||
|
options = {
|
||||||
|
ie8: true,
|
||||||
|
toplevel: false,
|
||||||
|
}
|
||||||
|
mangle = {
|
||||||
|
ie8: true,
|
||||||
|
toplevel: false,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
var a = "FAIL";
|
||||||
|
try {
|
||||||
|
throw 1;
|
||||||
|
} catch (args) {
|
||||||
|
a = "PASS";
|
||||||
|
}
|
||||||
|
console.log(a);
|
||||||
|
}
|
||||||
|
expect_exact: 'var a="FAIL";try{throw 1}catch(args){a="PASS"}console.log(a);'
|
||||||
|
expect_stdout: "PASS"
|
||||||
|
}
|
||||||
|
|
||||||
|
mangle_catch_var: {
|
||||||
|
rename = true
|
||||||
|
options = {
|
||||||
|
ie8: false,
|
||||||
|
toplevel: false,
|
||||||
|
}
|
||||||
|
mangle = {
|
||||||
|
ie8: false,
|
||||||
|
toplevel: false,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
var a = "FAIL";
|
||||||
|
try {
|
||||||
|
throw 1;
|
||||||
|
} catch (args) {
|
||||||
|
var a = "PASS";
|
||||||
|
}
|
||||||
|
console.log(a);
|
||||||
|
}
|
||||||
|
expect_exact: 'var a="FAIL";try{throw 1}catch(o){var a="PASS"}console.log(a);'
|
||||||
|
expect_stdout: "PASS"
|
||||||
|
}
|
||||||
|
|
||||||
|
mangle_catch_var_ie8: {
|
||||||
|
rename = true
|
||||||
|
options = {
|
||||||
|
ie8: true,
|
||||||
|
toplevel: false,
|
||||||
|
}
|
||||||
|
mangle = {
|
||||||
|
ie8: true,
|
||||||
|
toplevel: false,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
var a = "FAIL";
|
||||||
|
try {
|
||||||
|
throw 1;
|
||||||
|
} catch (args) {
|
||||||
|
var a = "PASS";
|
||||||
|
}
|
||||||
|
console.log(a);
|
||||||
|
}
|
||||||
|
expect_exact: 'var a="FAIL";try{throw 1}catch(args){var a="PASS"}console.log(a);'
|
||||||
|
expect_stdout: "PASS"
|
||||||
|
}
|
||||||
|
|
||||||
|
mangle_catch_toplevel: {
|
||||||
|
rename = true
|
||||||
|
options = {
|
||||||
|
ie8: false,
|
||||||
|
toplevel: true,
|
||||||
|
}
|
||||||
|
mangle = {
|
||||||
|
ie8: false,
|
||||||
|
toplevel: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
var a = "FAIL";
|
||||||
|
try {
|
||||||
|
throw 1;
|
||||||
|
} catch (args) {
|
||||||
|
a = "PASS";
|
||||||
|
}
|
||||||
|
console.log(a);
|
||||||
|
}
|
||||||
|
expect_exact: 'var o="FAIL";try{throw 1}catch(c){o="PASS"}console.log(o);'
|
||||||
|
expect_stdout: "PASS"
|
||||||
|
}
|
||||||
|
|
||||||
|
mangle_catch_ie8_toplevel: {
|
||||||
|
rename = true
|
||||||
|
options = {
|
||||||
|
ie8: true,
|
||||||
|
toplevel: true,
|
||||||
|
}
|
||||||
|
mangle = {
|
||||||
|
ie8: true,
|
||||||
|
toplevel: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
var a = "FAIL";
|
||||||
|
try {
|
||||||
|
throw 1;
|
||||||
|
} catch (args) {
|
||||||
|
a = "PASS";
|
||||||
|
}
|
||||||
|
console.log(a);
|
||||||
|
}
|
||||||
|
expect_exact: 'var o="FAIL";try{throw 1}catch(c){o="PASS"}console.log(o);'
|
||||||
|
expect_stdout: "PASS"
|
||||||
|
}
|
||||||
|
|
||||||
|
mangle_catch_var_toplevel: {
|
||||||
|
rename = true
|
||||||
|
options = {
|
||||||
|
ie8: false,
|
||||||
|
toplevel: true,
|
||||||
|
}
|
||||||
|
mangle = {
|
||||||
|
ie8: false,
|
||||||
|
toplevel: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
var a = "FAIL";
|
||||||
|
try {
|
||||||
|
throw 1;
|
||||||
|
} catch (args) {
|
||||||
|
var a = "PASS";
|
||||||
|
}
|
||||||
|
console.log(a);
|
||||||
|
}
|
||||||
|
expect_exact: 'var o="FAIL";try{throw 1}catch(r){var o="PASS"}console.log(o);'
|
||||||
|
expect_stdout: "PASS"
|
||||||
|
}
|
||||||
|
|
||||||
|
mangle_catch_var_ie8_toplevel: {
|
||||||
|
rename = true
|
||||||
|
options = {
|
||||||
|
ie8: true,
|
||||||
|
toplevel: true,
|
||||||
|
}
|
||||||
|
mangle = {
|
||||||
|
ie8: true,
|
||||||
|
toplevel: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
var a = "FAIL";
|
||||||
|
try {
|
||||||
|
throw 1;
|
||||||
|
} catch (args) {
|
||||||
|
var a = "PASS";
|
||||||
|
}
|
||||||
|
console.log(a);
|
||||||
|
}
|
||||||
|
expect_exact: 'var o="FAIL";try{throw 1}catch(r){var o="PASS"}console.log(o);'
|
||||||
|
expect_stdout: "PASS"
|
||||||
|
}
|
||||||
|
|
||||||
|
mangle_catch_redef_1: {
|
||||||
|
rename = true
|
||||||
|
options = {
|
||||||
|
ie8: false,
|
||||||
|
toplevel: false,
|
||||||
|
}
|
||||||
|
mangle = {
|
||||||
|
ie8: false,
|
||||||
|
toplevel: false,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
var a = "PASS";
|
||||||
|
try {
|
||||||
|
throw "FAIL1";
|
||||||
|
} catch (a) {
|
||||||
|
var a = "FAIL2";
|
||||||
|
}
|
||||||
|
console.log(a);
|
||||||
|
}
|
||||||
|
expect_exact: 'var a="PASS";try{throw"FAIL1"}catch(a){var a="FAIL2"}console.log(a);'
|
||||||
|
expect_stdout: "PASS"
|
||||||
|
}
|
||||||
|
|
||||||
|
mangle_catch_redef_1_ie8: {
|
||||||
|
rename = true
|
||||||
|
options = {
|
||||||
|
ie8: true,
|
||||||
|
toplevel: false,
|
||||||
|
}
|
||||||
|
mangle = {
|
||||||
|
ie8: true,
|
||||||
|
toplevel: false,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
var a = "PASS";
|
||||||
|
try {
|
||||||
|
throw "FAIL1";
|
||||||
|
} catch (a) {
|
||||||
|
var a = "FAIL2";
|
||||||
|
}
|
||||||
|
console.log(a);
|
||||||
|
}
|
||||||
|
expect_exact: 'var a="PASS";try{throw"FAIL1"}catch(a){var a="FAIL2"}console.log(a);'
|
||||||
|
expect_stdout: "PASS"
|
||||||
|
}
|
||||||
|
|
||||||
|
mangle_catch_redef_1_toplevel: {
|
||||||
|
rename = true
|
||||||
|
options = {
|
||||||
|
ie8: false,
|
||||||
|
toplevel: true,
|
||||||
|
}
|
||||||
|
mangle = {
|
||||||
|
ie8: false,
|
||||||
|
toplevel: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
var a = "PASS";
|
||||||
|
try {
|
||||||
|
throw "FAIL1";
|
||||||
|
} catch (a) {
|
||||||
|
var a = "FAIL2";
|
||||||
|
}
|
||||||
|
console.log(a);
|
||||||
|
}
|
||||||
|
expect_exact: 'var o="PASS";try{throw"FAIL1"}catch(o){var o="FAIL2"}console.log(o);'
|
||||||
|
expect_stdout: "PASS"
|
||||||
|
}
|
||||||
|
|
||||||
|
mangle_catch_redef_1_ie8_toplevel: {
|
||||||
|
rename = true
|
||||||
|
options = {
|
||||||
|
ie8: true,
|
||||||
|
toplevel: true,
|
||||||
|
}
|
||||||
|
mangle = {
|
||||||
|
ie8: true,
|
||||||
|
toplevel: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
var a = "PASS";
|
||||||
|
try {
|
||||||
|
throw "FAIL1";
|
||||||
|
} catch (a) {
|
||||||
|
var a = "FAIL2";
|
||||||
|
}
|
||||||
|
console.log(a);
|
||||||
|
}
|
||||||
|
expect_exact: 'var o="PASS";try{throw"FAIL1"}catch(o){var o="FAIL2"}console.log(o);'
|
||||||
|
expect_stdout: "PASS"
|
||||||
|
}
|
||||||
|
|
||||||
|
mangle_catch_redef_2: {
|
||||||
|
rename = true
|
||||||
|
options = {
|
||||||
|
ie8: false,
|
||||||
|
toplevel: false,
|
||||||
|
}
|
||||||
|
mangle = {
|
||||||
|
ie8: false,
|
||||||
|
toplevel: false,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
try {
|
||||||
|
throw "FAIL1";
|
||||||
|
} catch (a) {
|
||||||
|
var a = "FAIL2";
|
||||||
|
}
|
||||||
|
console.log(a);
|
||||||
|
}
|
||||||
|
expect_exact: 'try{throw"FAIL1"}catch(a){var a="FAIL2"}console.log(a);'
|
||||||
|
expect_stdout: "undefined"
|
||||||
|
}
|
||||||
|
|
||||||
|
mangle_catch_redef_2_ie8: {
|
||||||
|
rename = true
|
||||||
|
options = {
|
||||||
|
ie8: true,
|
||||||
|
toplevel: false,
|
||||||
|
}
|
||||||
|
mangle = {
|
||||||
|
ie8: true,
|
||||||
|
toplevel: false,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
try {
|
||||||
|
throw "FAIL1";
|
||||||
|
} catch (a) {
|
||||||
|
var a = "FAIL2";
|
||||||
|
}
|
||||||
|
console.log(a);
|
||||||
|
}
|
||||||
|
expect_exact: 'try{throw"FAIL1"}catch(a){var a="FAIL2"}console.log(a);'
|
||||||
|
expect_stdout: "undefined"
|
||||||
|
}
|
||||||
|
|
||||||
|
mangle_catch_redef_2_toplevel: {
|
||||||
|
rename = true
|
||||||
|
options = {
|
||||||
|
ie8: false,
|
||||||
|
toplevel: true,
|
||||||
|
}
|
||||||
|
mangle = {
|
||||||
|
ie8: false,
|
||||||
|
toplevel: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
try {
|
||||||
|
throw "FAIL1";
|
||||||
|
} catch (a) {
|
||||||
|
var a = "FAIL2";
|
||||||
|
}
|
||||||
|
console.log(a);
|
||||||
|
}
|
||||||
|
expect_exact: 'try{throw"FAIL1"}catch(o){var o="FAIL2"}console.log(o);'
|
||||||
|
expect_stdout: "undefined"
|
||||||
|
}
|
||||||
|
|
||||||
|
mangle_catch_redef_2_ie8_toplevel: {
|
||||||
|
rename = true
|
||||||
|
options = {
|
||||||
|
ie8: true,
|
||||||
|
toplevel: true,
|
||||||
|
}
|
||||||
|
mangle = {
|
||||||
|
ie8: true,
|
||||||
|
toplevel: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
try {
|
||||||
|
throw "FAIL1";
|
||||||
|
} catch (a) {
|
||||||
|
var a = "FAIL2";
|
||||||
|
}
|
||||||
|
console.log(a);
|
||||||
|
}
|
||||||
|
expect_exact: 'try{throw"FAIL1"}catch(o){var o="FAIL2"}console.log(o);'
|
||||||
|
expect_stdout: "undefined"
|
||||||
|
}
|
||||||
|
|
||||||
|
issue_2120_1: {
|
||||||
|
rename = true
|
||||||
|
mangle = {
|
||||||
|
ie8: false,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
"aaaaaaaa";
|
||||||
|
var a = 1, b = "FAIL";
|
||||||
|
try {
|
||||||
|
throw 1;
|
||||||
|
} catch (c) {
|
||||||
|
try {
|
||||||
|
throw 0;
|
||||||
|
} catch (a) {
|
||||||
|
if (c) b = "PASS";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
console.log(b);
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
"aaaaaaaa";
|
||||||
|
var a = 1, b = "FAIL";
|
||||||
|
try {
|
||||||
|
throw 1;
|
||||||
|
} catch (t) {
|
||||||
|
try {
|
||||||
|
throw 0;
|
||||||
|
} catch (a) {
|
||||||
|
if (t) b = "PASS";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
console.log(b);
|
||||||
|
}
|
||||||
|
expect_stdout: "PASS"
|
||||||
|
}
|
||||||
|
|
||||||
|
issue_2120_2: {
|
||||||
|
rename = true
|
||||||
|
mangle = {
|
||||||
|
ie8: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
"aaaaaaaa";
|
||||||
|
var a = 1, b = "FAIL";
|
||||||
|
try {
|
||||||
|
throw 1;
|
||||||
|
} catch (c) {
|
||||||
|
try {
|
||||||
|
throw 0;
|
||||||
|
} catch (a) {
|
||||||
|
if (c) b = "PASS";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
console.log(b);
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
"aaaaaaaa";
|
||||||
|
var a = 1, b = "FAIL";
|
||||||
|
try {
|
||||||
|
throw 1;
|
||||||
|
} catch (c) {
|
||||||
|
try {
|
||||||
|
throw 0;
|
||||||
|
} catch (a) {
|
||||||
|
if (c) b = "PASS";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
console.log(b);
|
||||||
|
}
|
||||||
|
expect_stdout: "PASS"
|
||||||
|
}
|
||||||
|
function_iife_catch: {
|
||||||
|
rename = true
|
||||||
|
mangle = {
|
||||||
|
ie8: false,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
function f(n) {
|
||||||
|
!function() {
|
||||||
|
try {
|
||||||
|
throw 0;
|
||||||
|
} catch (n) {
|
||||||
|
var a = 1;
|
||||||
|
console.log(n, a);
|
||||||
|
}
|
||||||
|
}();
|
||||||
|
}
|
||||||
|
f();
|
||||||
|
}
|
||||||
|
expect_exact: "function f(o){!function(){try{throw 0}catch(c){var o=1;console.log(c,o)}}()}f();"
|
||||||
|
expect_stdout: "0 1"
|
||||||
|
}
|
||||||
|
|
||||||
|
function_iife_catch_ie8: {
|
||||||
|
rename = true
|
||||||
|
mangle = {
|
||||||
|
ie8: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
function f(n) {
|
||||||
|
!function() {
|
||||||
|
try {
|
||||||
|
throw 0;
|
||||||
|
} catch (n) {
|
||||||
|
var a = 1;
|
||||||
|
console.log(n, a);
|
||||||
|
}
|
||||||
|
}();
|
||||||
|
}
|
||||||
|
f();
|
||||||
|
}
|
||||||
|
expect_exact: "function f(o){!function(){try{throw 0}catch(o){var c=1;console.log(o,c)}}()}f();"
|
||||||
|
expect_stdout: "0 1"
|
||||||
|
}
|
||||||
|
|
||||||
|
function_catch_catch: {
|
||||||
|
rename = true
|
||||||
|
mangle = {
|
||||||
|
ie8: false,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
var o = 0;
|
||||||
|
function f() {
|
||||||
|
try {
|
||||||
|
throw 1;
|
||||||
|
} catch (c) {
|
||||||
|
try {
|
||||||
|
throw 2;
|
||||||
|
} catch (o) {
|
||||||
|
var o = 3;
|
||||||
|
console.log(o);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
console.log(o);
|
||||||
|
}
|
||||||
|
f();
|
||||||
|
}
|
||||||
|
expect_exact: "var o=0;function f(){try{throw 1}catch(c){try{throw 2}catch(o){var o=3;console.log(o)}}console.log(o)}f();"
|
||||||
|
expect_stdout: [
|
||||||
|
"3",
|
||||||
|
"undefined",
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
|
function_catch_catch_ie8: {
|
||||||
|
rename = true
|
||||||
|
mangle = {
|
||||||
|
ie8: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
var o = 0;
|
||||||
|
function f() {
|
||||||
|
try {
|
||||||
|
throw 1;
|
||||||
|
} catch (c) {
|
||||||
|
try {
|
||||||
|
throw 2;
|
||||||
|
} catch (o) {
|
||||||
|
var o = 3;
|
||||||
|
console.log(o);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
console.log(o);
|
||||||
|
}
|
||||||
|
f();
|
||||||
|
}
|
||||||
|
expect_exact: "var o=0;function f(){try{throw 1}catch(c){try{throw 2}catch(o){var o=3;console.log(o)}}console.log(o)}f();"
|
||||||
|
expect_stdout: [
|
||||||
|
"3",
|
||||||
|
"undefined",
|
||||||
|
]
|
||||||
|
}
|
||||||
@@ -187,6 +187,7 @@ dont_screw_try_catch_undefined: {
|
|||||||
reduce_vars: {
|
reduce_vars: {
|
||||||
options = {
|
options = {
|
||||||
evaluate: true,
|
evaluate: true,
|
||||||
|
reduce_funcs: true,
|
||||||
reduce_vars: true,
|
reduce_vars: true,
|
||||||
ie8: true,
|
ie8: true,
|
||||||
unused: true,
|
unused: true,
|
||||||
@@ -325,3 +326,69 @@ issue_2120_2: {
|
|||||||
}
|
}
|
||||||
expect_stdout: "PASS"
|
expect_stdout: "PASS"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
issue_2254_1: {
|
||||||
|
mangle = {
|
||||||
|
ie8: false,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
"eeeeee";
|
||||||
|
try {
|
||||||
|
console.log(f("PASS"));
|
||||||
|
} catch (e) {}
|
||||||
|
function f(s) {
|
||||||
|
try {
|
||||||
|
throw "FAIL";
|
||||||
|
} catch (e) {
|
||||||
|
return s;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
"eeeeee";
|
||||||
|
try {
|
||||||
|
console.log(f("PASS"));
|
||||||
|
} catch (e) {}
|
||||||
|
function f(e) {
|
||||||
|
try {
|
||||||
|
throw "FAIL";
|
||||||
|
} catch (t) {
|
||||||
|
return e;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
expect_stdout: "PASS"
|
||||||
|
}
|
||||||
|
|
||||||
|
issue_2254_2: {
|
||||||
|
mangle = {
|
||||||
|
ie8: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
"eeeeee";
|
||||||
|
try {
|
||||||
|
console.log(f("PASS"));
|
||||||
|
} catch (e) {}
|
||||||
|
function f(s) {
|
||||||
|
try {
|
||||||
|
throw "FAIL";
|
||||||
|
} catch (e) {
|
||||||
|
return s;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
"eeeeee";
|
||||||
|
try {
|
||||||
|
console.log(f("PASS"));
|
||||||
|
} catch (e) {}
|
||||||
|
function f(t) {
|
||||||
|
try {
|
||||||
|
throw "FAIL";
|
||||||
|
} catch (e) {
|
||||||
|
return t;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
expect_stdout: "PASS"
|
||||||
|
}
|
||||||
|
|||||||
@@ -176,6 +176,11 @@ for_sequences: {
|
|||||||
// 4
|
// 4
|
||||||
x = (foo in bar);
|
x = (foo in bar);
|
||||||
for (y = 5; false;);
|
for (y = 5; false;);
|
||||||
|
// 5
|
||||||
|
x = function() {
|
||||||
|
foo in bar;
|
||||||
|
};
|
||||||
|
for (y = 5; false;);
|
||||||
}
|
}
|
||||||
expect: {
|
expect: {
|
||||||
// 1
|
// 1
|
||||||
@@ -188,6 +193,10 @@ for_sequences: {
|
|||||||
// 4
|
// 4
|
||||||
x = (foo in bar);
|
x = (foo in bar);
|
||||||
for (y = 5; false;);
|
for (y = 5; false;);
|
||||||
|
// 5
|
||||||
|
for (x = function() {
|
||||||
|
foo in bar;
|
||||||
|
}, y = 5; false;);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -754,3 +763,44 @@ issue_2062: {
|
|||||||
}
|
}
|
||||||
expect_stdout: "1"
|
expect_stdout: "1"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
issue_2313: {
|
||||||
|
options = {
|
||||||
|
cascade: true,
|
||||||
|
sequences: true,
|
||||||
|
side_effects: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
var a = 0, b = 0;
|
||||||
|
var foo = {
|
||||||
|
get c() {
|
||||||
|
a++;
|
||||||
|
return 42;
|
||||||
|
},
|
||||||
|
set c(c) {
|
||||||
|
b++;
|
||||||
|
},
|
||||||
|
d: function() {
|
||||||
|
this.c++;
|
||||||
|
if (this.c) console.log(a, b);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
foo.d();
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
var a = 0, b = 0;
|
||||||
|
var foo = {
|
||||||
|
get c() {
|
||||||
|
return a++, 42;
|
||||||
|
},
|
||||||
|
set c(c) {
|
||||||
|
b++;
|
||||||
|
},
|
||||||
|
d: function() {
|
||||||
|
if (this.c++, this.c) console.log(a, b);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
foo.d();
|
||||||
|
}
|
||||||
|
expect_stdout: "2 1"
|
||||||
|
}
|
||||||
|
|||||||
@@ -714,6 +714,7 @@ issue_1705_2: {
|
|||||||
options = {
|
options = {
|
||||||
dead_code: true,
|
dead_code: true,
|
||||||
evaluate: true,
|
evaluate: true,
|
||||||
|
reduce_funcs: true,
|
||||||
reduce_vars: true,
|
reduce_vars: true,
|
||||||
sequences: true,
|
sequences: true,
|
||||||
side_effects: true,
|
side_effects: true,
|
||||||
|
|||||||
@@ -59,7 +59,7 @@ template_string_with_constant_expression: {
|
|||||||
var foo = `${4 + 4} equals 4 + 4`;
|
var foo = `${4 + 4} equals 4 + 4`;
|
||||||
}
|
}
|
||||||
expect: {
|
expect: {
|
||||||
var foo = `8 equals 4 + 4`;
|
var foo = "8 equals 4 + 4";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -89,21 +89,21 @@ template_string_with_predefined_constants: {
|
|||||||
var c = `${4**14}`; // 8 in template vs 9 chars - 268435456
|
var c = `${4**14}`; // 8 in template vs 9 chars - 268435456
|
||||||
}
|
}
|
||||||
expect: {
|
expect: {
|
||||||
var foo = `This is undefined`;
|
var foo = "This is undefined";
|
||||||
var bar = `This is NaN`;
|
var bar = "This is NaN";
|
||||||
var baz = `This is null`;
|
var baz = "This is null";
|
||||||
var foofoo = `This is ${1/0}`;
|
var foofoo = `This is ${1/0}`;
|
||||||
var foobar = "This is ${1/0}";
|
var foobar = "This is ${1/0}";
|
||||||
var foobaz = 'This is ${1/0}';
|
var foobaz = 'This is ${1/0}';
|
||||||
var barfoo = "This is ${NaN}";
|
var barfoo = "This is ${NaN}";
|
||||||
var bazfoo = "This is ${null}";
|
var bazfoo = "This is ${null}";
|
||||||
var bazbaz = `This is ${1/0}`;
|
var bazbaz = `This is ${1/0}`;
|
||||||
var barbar = `This is NaN`;
|
var barbar = "This is NaN";
|
||||||
var barbar = "This is ${0/0}";
|
var barbar = "This is ${0/0}";
|
||||||
var barber = 'This is ${0/0}';
|
var barber = 'This is ${0/0}';
|
||||||
|
|
||||||
var a = `4194304`;
|
var a = "4194304";
|
||||||
var b = `16777216`; // Potential for further concatentation
|
var b = "16777216"; // Potential for further concatentation
|
||||||
var c = `${4**14}`; // Not worth converting
|
var c = `${4**14}`; // Not worth converting
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -123,7 +123,7 @@ template_string_evaluate_with_many_segments: {
|
|||||||
}
|
}
|
||||||
expect: {
|
expect: {
|
||||||
var foo = `Hello ${guest()}, welcome to ${location()}.`;
|
var foo = `Hello ${guest()}, welcome to ${location()}.`;
|
||||||
var bar = `1234567890`;
|
var bar = "1234567890";
|
||||||
var baz = `${foobar()}${foobar()}${foobar()}${foobar()}`;
|
var baz = `${foobar()}${foobar()}${foobar()}${foobar()}`;
|
||||||
var buzz = `1${foobar()}2${foobar()}3${foobar()}`;
|
var buzz = `1${foobar()}2${foobar()}3${foobar()}`;
|
||||||
}
|
}
|
||||||
@@ -159,7 +159,7 @@ template_string_to_normal_string: {
|
|||||||
var bar = "Decimals " + `${1}${2}${3}${4}${5}${6}${7}${8}${9}${0}`;
|
var bar = "Decimals " + `${1}${2}${3}${4}${5}${6}${7}${8}${9}${0}`;
|
||||||
}
|
}
|
||||||
expect: {
|
expect: {
|
||||||
var foo = `This is undefined`;
|
var foo = "This is undefined";
|
||||||
var bar = "Decimals 1234567890";
|
var bar = "Decimals 1234567890";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -192,7 +192,7 @@ evaluate_nested_templates: {
|
|||||||
var baz = `${`${`${`foo`}`}`}`;
|
var baz = `${`${`${`foo`}`}`}`;
|
||||||
}
|
}
|
||||||
expect: {
|
expect: {
|
||||||
var baz = `foo`;
|
var baz = "foo";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -241,8 +241,8 @@ enforce_double_quotes_and_evaluate: {
|
|||||||
var baz = `Hello ${world()}`;
|
var baz = `Hello ${world()}`;
|
||||||
}
|
}
|
||||||
expect: {
|
expect: {
|
||||||
var foo = `Hello world`;
|
var foo = "Hello world";
|
||||||
var bar = `Hello world`;
|
var bar = "Hello world";
|
||||||
var baz = `Hello ${world()}`;
|
var baz = `Hello ${world()}`;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -260,8 +260,8 @@ enforce_single_quotes_and_evaluate: {
|
|||||||
var baz = `Hello ${world()}`;
|
var baz = `Hello ${world()}`;
|
||||||
}
|
}
|
||||||
expect: {
|
expect: {
|
||||||
var foo = `Hello world`;
|
var foo = "Hello world";
|
||||||
var bar = `Hello world`;
|
var bar = "Hello world";
|
||||||
var baz = `Hello ${world()}`;
|
var baz = `Hello ${world()}`;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -339,7 +339,7 @@ escape_dollar_curly: {
|
|||||||
console.log(`${1-0}\${2-0}$\{3-0}${4-0}`)
|
console.log(`${1-0}\${2-0}$\{3-0}${4-0}`)
|
||||||
console.log(`$${""}{not an expression}`)
|
console.log(`$${""}{not an expression}`)
|
||||||
}
|
}
|
||||||
expect_exact: "console.log(`\\${ beep }`);console.log(`1\\${2-0}\\${3-0}4`);console.log(`\\${not an expression}`);"
|
expect_exact: 'console.log("${ beep }");console.log("1${2-0}${3-0}4");console.log("${not an expression}");'
|
||||||
}
|
}
|
||||||
|
|
||||||
template_starting_with_newline: {
|
template_starting_with_newline: {
|
||||||
@@ -400,3 +400,109 @@ issue_1856_ascii_only: {
|
|||||||
}
|
}
|
||||||
expect_exact: "console.log(`\\\\n\\\\r\\\\u2028\\\\u2029\\n\\r\\u2028\\u2029`);"
|
expect_exact: "console.log(`\\\\n\\\\r\\\\u2028\\\\u2029\\n\\r\\u2028\\u2029`);"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
side_effects: {
|
||||||
|
options = {
|
||||||
|
evaluate: true,
|
||||||
|
side_effects: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
`t1`;
|
||||||
|
tag`t2`;
|
||||||
|
`t${3}`;
|
||||||
|
tag`t${4}`;
|
||||||
|
console.log(`
|
||||||
|
t${5}`);
|
||||||
|
function f(a) {
|
||||||
|
`t6${a}`;
|
||||||
|
a = `t7${a}` & a;
|
||||||
|
a = `t8${b}` | a;
|
||||||
|
a = f`t9${a}` ^ a;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
tag`t2`;
|
||||||
|
tag`t${4}`;
|
||||||
|
console.log("\nt5");
|
||||||
|
function f(a) {
|
||||||
|
a &= `t7${a}`;
|
||||||
|
a = `t8${b}` | a;
|
||||||
|
a = f`t9${a}` ^ a;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
simple_string: {
|
||||||
|
options = {
|
||||||
|
computed_props: true,
|
||||||
|
evaluate: true,
|
||||||
|
properties: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
console.log({[`foo`]: 1}[`foo`], `hi` == "hi", `world`);
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
console.log([ 1 ][0], true, "world");
|
||||||
|
}
|
||||||
|
expect_stdout: "1 true 'world'"
|
||||||
|
node_version: ">=4"
|
||||||
|
}
|
||||||
|
|
||||||
|
semicolons: {
|
||||||
|
beautify = {
|
||||||
|
semicolons: false,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
foo;
|
||||||
|
`bar`;
|
||||||
|
}
|
||||||
|
expect_exact: "foo;`bar`\n"
|
||||||
|
}
|
||||||
|
|
||||||
|
regex_1: {
|
||||||
|
input: {
|
||||||
|
console.log(`${/a/} ${6/2} ${/b/.test("b")} ${1?/c/:/d/}`);
|
||||||
|
}
|
||||||
|
expect_exact: 'console.log(`${/a/} ${6/2} ${/b/.test("b")} ${1?/c/:/d/}`);'
|
||||||
|
expect_stdout: "/a/ 3 true /c/"
|
||||||
|
node_version: ">=4"
|
||||||
|
}
|
||||||
|
|
||||||
|
regex_2: {
|
||||||
|
options = {
|
||||||
|
evaluate: true,
|
||||||
|
unsafe: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
console.log(`${/a/} ${6/2} ${/b/.test("b")} ${1?/c/:/d/}`);
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
console.log("/a/ 3 true /c/");
|
||||||
|
}
|
||||||
|
expect_stdout: "/a/ 3 true /c/"
|
||||||
|
node_version: ">=4"
|
||||||
|
}
|
||||||
|
|
||||||
|
sequence_1: {
|
||||||
|
input: {
|
||||||
|
console.log(`${1,2} ${/a/,/b/}`);
|
||||||
|
}
|
||||||
|
expect_exact: 'console.log(`${1,2} ${/a/,/b/}`);'
|
||||||
|
expect_stdout: "2 /b/"
|
||||||
|
node_version: ">=4"
|
||||||
|
}
|
||||||
|
|
||||||
|
sequence_2: {
|
||||||
|
options = {
|
||||||
|
evaluate: true,
|
||||||
|
side_effects: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
console.log(`${1,2} ${/a/,/b/}`);
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
console.log("2 /b/");
|
||||||
|
}
|
||||||
|
expect_stdout: "2 /b/"
|
||||||
|
node_version: ">=4"
|
||||||
|
}
|
||||||
|
|||||||
@@ -43,15 +43,6 @@ unicode_string_literals: {
|
|||||||
expect_exact: 'var a="6 length unicode character: \\u{101111}";'
|
expect_exact: 'var a="6 length unicode character: \\u{101111}";'
|
||||||
}
|
}
|
||||||
|
|
||||||
// Don't escape identifiers below es6 (or in this case double escaped in expect_exact)
|
|
||||||
unicode_output_es5_surrogates: {
|
|
||||||
beautify = {ascii_only: true, ecma: 5}
|
|
||||||
input: {
|
|
||||||
var \u{10000} = "6 length unicode character: \u{10FFFF}";
|
|
||||||
}
|
|
||||||
expect_exact: 'var \u{10000}="6 length unicode character: \\udbff\\udfff";'
|
|
||||||
}
|
|
||||||
|
|
||||||
check_escape_style: {
|
check_escape_style: {
|
||||||
beautify = {ascii_only: true, ecma: 6}
|
beautify = {ascii_only: true, ecma: 6}
|
||||||
input: {
|
input: {
|
||||||
@@ -65,20 +56,6 @@ check_escape_style: {
|
|||||||
expect_exact: 'var a="\\x01";var \\ua0081="\\x10";var \\u0100="\\u0100";var \\u1000="\\u1000";var \\u{10000}="\\u{10000}";var \\u{2f800}="\\u{100000}";'
|
expect_exact: 'var a="\\x01";var \\ua0081="\\x10";var \\u0100="\\u0100";var \\u1000="\\u1000";var \\u{10000}="\\u{10000}";var \\u{2f800}="\\u{100000}";'
|
||||||
}
|
}
|
||||||
|
|
||||||
// Don't escape identifiers below es6, no escaped identifiers support and no \u{} syntax
|
|
||||||
check_escape_style_es5: {
|
|
||||||
beautify = {ascii_only: true, ecma: 5}
|
|
||||||
input: {
|
|
||||||
var a = "\x01";
|
|
||||||
var \ua0081 = "\x10"; // \u0081 only in ID_Continue
|
|
||||||
var \u0100 = "\u0100";
|
|
||||||
var \u1000 = "\u1000";
|
|
||||||
var \u{10000} = "\u{10000}"; // Identifier won't be escaped in es 5.1
|
|
||||||
var \u{2f800} = "\u{100000}"; // Same
|
|
||||||
}
|
|
||||||
expect_exact: 'var a="\\x01";var \\ua0081="\\x10";var \\u0100="\\u0100";var \\u1000="\\u1000";var \ud800\udc00="\\ud800\\udc00";var \ud87e\udc00="\\udbc0\\udc00";'
|
|
||||||
}
|
|
||||||
|
|
||||||
ID_continue_with_surrogate_pair: {
|
ID_continue_with_surrogate_pair: {
|
||||||
beautify = {ascii_only: true, ecma: 6}
|
beautify = {ascii_only: true, ecma: 6}
|
||||||
input: {
|
input: {
|
||||||
@@ -103,18 +80,42 @@ non_escape_2_non_escape: {
|
|||||||
expect_exact: 'var µþ="µþ";'
|
expect_exact: 'var µþ="µþ";'
|
||||||
}
|
}
|
||||||
|
|
||||||
non_escape_2_half_escape1: {
|
issue_2242_1: {
|
||||||
beautify = {ascii_only: false, ascii_identifiers: true, ecma: 6}
|
beautify = {
|
||||||
input: {
|
ascii_only: false,
|
||||||
var µþ = "µþ";
|
|
||||||
}
|
}
|
||||||
expect_exact: 'var \\u00b5\\u00fe="µþ";'
|
input: {
|
||||||
|
console.log("\ud83d", "\ude00", "\ud83d\ude00", "\ud83d@\ude00");
|
||||||
|
}
|
||||||
|
expect_exact: 'console.log("\\ud83d","\\ude00","\ud83d\ude00","\\ud83d@\\ude00");'
|
||||||
}
|
}
|
||||||
|
|
||||||
non_escape_2_half_escape2: {
|
issue_2242_2: {
|
||||||
beautify = {ascii_only: true, ascii_identifiers: false, ecma: 6}
|
beautify = {
|
||||||
input: {
|
ascii_only: true,
|
||||||
var µþ = "µþ";
|
|
||||||
}
|
}
|
||||||
expect_exact: 'var µþ="\\xb5\\xfe";'
|
input: {
|
||||||
}
|
console.log("\ud83d", "\ude00", "\ud83d\ude00", "\ud83d@\ude00");
|
||||||
|
}
|
||||||
|
expect_exact: 'console.log("\\ud83d","\\ude00","\\ud83d\\ude00","\\ud83d@\\ude00");'
|
||||||
|
}
|
||||||
|
|
||||||
|
issue_2242_3: {
|
||||||
|
options = {
|
||||||
|
evaluate: false,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
console.log("\ud83d" + "\ude00", "\ud83d" + "@" + "\ude00");
|
||||||
|
}
|
||||||
|
expect_exact: 'console.log("\\ud83d"+"\\ude00","\\ud83d"+"@"+"\\ude00");'
|
||||||
|
}
|
||||||
|
|
||||||
|
issue_2242_4: {
|
||||||
|
options = {
|
||||||
|
evaluate: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
console.log("\ud83d" + "\ude00", "\ud83d" + "@" + "\ude00");
|
||||||
|
}
|
||||||
|
expect_exact: 'console.log("\ud83d\ude00","\\ud83d@\\ude00");'
|
||||||
|
}
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ exports["defaults"] = defaults;
|
|||||||
exports["mangle_properties"] = mangle_properties;
|
exports["mangle_properties"] = mangle_properties;
|
||||||
exports["minify"] = minify;
|
exports["minify"] = minify;
|
||||||
exports["parse"] = parse;
|
exports["parse"] = parse;
|
||||||
|
exports["reserve_quoted_keys"] = reserve_quoted_keys;
|
||||||
exports["string_template"] = string_template;
|
exports["string_template"] = string_template;
|
||||||
exports["tokenizer"] = tokenizer;
|
exports["tokenizer"] = tokenizer;
|
||||||
exports["is_identifier"] = is_identifier;
|
exports["is_identifier"] = is_identifier;
|
||||||
|
|||||||
10
test/input/issue-2310/input.js
Normal file
10
test/input/issue-2310/input.js
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
function foo() {
|
||||||
|
return function() {
|
||||||
|
console.log("PASS");
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
(function() {
|
||||||
|
var f = foo();
|
||||||
|
f();
|
||||||
|
})();
|
||||||
@@ -10,7 +10,7 @@ function read(path) {
|
|||||||
describe("bin/uglifyjs", function () {
|
describe("bin/uglifyjs", function () {
|
||||||
var uglifyjscmd = '"' + process.argv[0] + '" bin/uglifyjs';
|
var uglifyjscmd = '"' + process.argv[0] + '" bin/uglifyjs';
|
||||||
it("should produce a functional build when using --self", function (done) {
|
it("should produce a functional build when using --self", function (done) {
|
||||||
this.timeout(60000);
|
this.timeout(120000);
|
||||||
|
|
||||||
var command = uglifyjscmd + ' --self -mc ecma=';
|
var command = uglifyjscmd + ' --self -mc ecma=';
|
||||||
command += semver.satisfies(process.version, ">=4") ? "6" : "5";
|
command += semver.satisfies(process.version, ">=4") ? "6" : "5";
|
||||||
@@ -66,7 +66,7 @@ describe("bin/uglifyjs", function () {
|
|||||||
if (err) throw err;
|
if (err) throw err;
|
||||||
|
|
||||||
assert.strictEqual(stdout, "var bar=function(){function foo(bar){return bar}return foo}();\n" +
|
assert.strictEqual(stdout, "var bar=function(){function foo(bar){return bar}return foo}();\n" +
|
||||||
"//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbInRlc3QvaW5wdXQvaXNzdWUtMTMyMy9zYW1wbGUuanMiXSwibmFtZXMiOlsiYmFyIiwiZm9vIl0sIm1hcHBpbmdzIjoiQUFBQSxJQUFJQSxJQUFNLFdBQ04sU0FBU0MsSUFBS0QsS0FDVixPQUFPQSxJQUdYLE9BQU9DIn0=\n");
|
"//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbInRlc3QvaW5wdXQvaXNzdWUtMTMyMy9zYW1wbGUuanMiXSwibmFtZXMiOlsiYmFyIiwiZm9vIl0sIm1hcHBpbmdzIjoiQUFBQSxJQUFJQSxJQUFNLFdBQ04sU0FBU0MsSUFBS0QsS0FDVixPQUFPQSxJQUdYLE9BQU9DLElBTEQifQ==\n");
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@@ -195,7 +195,7 @@ describe("bin/uglifyjs", function () {
|
|||||||
|
|
||||||
assert.strictEqual(stdout, [
|
assert.strictEqual(stdout, [
|
||||||
"var bar=function(){function foo(bar){return bar}return foo}();",
|
"var bar=function(){function foo(bar){return bar}return foo}();",
|
||||||
"//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbInRlc3QvaW5wdXQvaXNzdWUtMTMyMy9zYW1wbGUuanMiXSwibmFtZXMiOlsiYmFyIiwiZm9vIl0sIm1hcHBpbmdzIjoiQUFBQSxJQUFJQSxJQUFNLFdBQ04sU0FBU0MsSUFBS0QsS0FDVixPQUFPQSxJQUdYLE9BQU9DIn0=",
|
"//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbInRlc3QvaW5wdXQvaXNzdWUtMTMyMy9zYW1wbGUuanMiXSwibmFtZXMiOlsiYmFyIiwiZm9vIl0sIm1hcHBpbmdzIjoiQUFBQSxJQUFJQSxJQUFNLFdBQ04sU0FBU0MsSUFBS0QsS0FDVixPQUFPQSxJQUdYLE9BQU9DLElBTEQifQ==",
|
||||||
"",
|
"",
|
||||||
].join("\n"));
|
].join("\n"));
|
||||||
assert.strictEqual(stderr, "WARN: inline source map not found\n");
|
assert.strictEqual(stderr, "WARN: inline source map not found\n");
|
||||||
@@ -666,6 +666,25 @@ describe("bin/uglifyjs", function () {
|
|||||||
return JSON.stringify(map).replace(/"/g, '\\"');
|
return JSON.stringify(map).replace(/"/g, '\\"');
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
it("Should include function calls in source map", function(done) {
|
||||||
|
var command = [
|
||||||
|
uglifyjscmd,
|
||||||
|
"test/input/issue-2310/input.js",
|
||||||
|
"-c",
|
||||||
|
"--source-map", "url=inline",
|
||||||
|
].join(" ");
|
||||||
|
|
||||||
|
exec(command, function(err, stdout, stderr) {
|
||||||
|
if (err) throw err;
|
||||||
|
|
||||||
|
assert.strictEqual(stdout, [
|
||||||
|
'function foo(){return function(){console.log("PASS")}}foo()();',
|
||||||
|
"//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbInRlc3QvaW5wdXQvaXNzdWUtMjMxMC9pbnB1dC5qcyJdLCJuYW1lcyI6WyJmb28iLCJjb25zb2xlIiwibG9nIiwiZiJdLCJtYXBwaW5ncyI6IkFBQUEsU0FBU0EsTUFDTCxPQUFPLFdBQ0hDLFFBQVFDLElBQUksU0FLUkYsS0FDUkcifQ==",
|
||||||
|
""
|
||||||
|
].join("\n"));
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
it("Should dump AST as JSON", function(done) {
|
it("Should dump AST as JSON", function(done) {
|
||||||
var command = uglifyjscmd + " test/input/global_defs/simple.js -mco ast";
|
var command = uglifyjscmd + " test/input/global_defs/simple.js -mco ast";
|
||||||
exec(command, function (err, stdout) {
|
exec(command, function (err, stdout) {
|
||||||
@@ -686,8 +705,8 @@ describe("bin/uglifyjs", function () {
|
|||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
it("Should work with --mangle reserved=[]", function (done) {
|
it("Should work with --mangle reserved=[]", function(done) {
|
||||||
var command = uglifyjscmd + ' test/input/issue-505/input.js -m reserved=[callback]';
|
var command = uglifyjscmd + " test/input/issue-505/input.js -m reserved=[callback]";
|
||||||
|
|
||||||
exec(command, function (err, stdout) {
|
exec(command, function (err, stdout) {
|
||||||
if (err) throw err;
|
if (err) throw err;
|
||||||
@@ -696,8 +715,8 @@ describe("bin/uglifyjs", function () {
|
|||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
it("Should work with --mangle reserved=false", function (done) {
|
it("Should work with --mangle reserved=false", function(done) {
|
||||||
var command = uglifyjscmd + ' test/input/issue-505/input.js -m reserved=false';
|
var command = uglifyjscmd + " test/input/issue-505/input.js -m reserved=false";
|
||||||
|
|
||||||
exec(command, function (err, stdout) {
|
exec(command, function (err, stdout) {
|
||||||
if (err) throw err;
|
if (err) throw err;
|
||||||
@@ -706,4 +725,22 @@ describe("bin/uglifyjs", function () {
|
|||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
it("Should fail with --mangle-props reserved=[in]", function(done) {
|
||||||
|
var command = uglifyjscmd + " test/input/issue-505/input.js --mangle-props reserved=[in]";
|
||||||
|
exec(command, function (err, stdout, stderr) {
|
||||||
|
assert.ok(err);
|
||||||
|
assert.strictEqual(stdout, "");
|
||||||
|
assert.ok(/^Supported options:\n[\s\S]*?\nERROR: `reserved=\[in]` is not a supported option/.test(stderr), stderr);
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
it("Should fail with --define a-b", function(done) {
|
||||||
|
var command = uglifyjscmd + " test/input/issue-505/input.js --define a-b";
|
||||||
|
exec(command, function (err, stdout, stderr) {
|
||||||
|
assert.ok(err);
|
||||||
|
assert.strictEqual(stdout, "");
|
||||||
|
assert.strictEqual(stderr, "Error parsing arguments for 'define': a-b\n");
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
var assert = require("assert");
|
var assert = require("assert");
|
||||||
var uglify = require("../node");
|
var uglify = require("../node");
|
||||||
|
|
||||||
describe("Export", function() {
|
describe("Export/Import", function() {
|
||||||
it("Should parse export directives", function() {
|
it("Should parse export directives", function() {
|
||||||
var inputs = [
|
var inputs = [
|
||||||
['export * from "a.js"', ['*'], "a.js"],
|
['export * from "a.js"', ['*'], "a.js"],
|
||||||
@@ -36,4 +36,22 @@ describe("Export", function() {
|
|||||||
assert.equal(st.module_name.value, filename);
|
assert.equal(st.module_name.value, filename);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("Should not parse invalid uses of export", function() {
|
||||||
|
assert.equal(uglify.minify("export").error.message, "Unexpected token: eof (undefined)");
|
||||||
|
assert.equal(uglify.minify("export;").error.message, "Unexpected token: punc (;)");
|
||||||
|
assert.equal(uglify.minify("export();").error.message, "Unexpected token: keyword (export)");
|
||||||
|
assert.equal(uglify.minify("export(1);").error.message, "Unexpected token: keyword (export)");
|
||||||
|
assert.equal(uglify.minify("var export;").error.message, "Name expected");
|
||||||
|
assert.equal(uglify.minify("var export = 1;").error.message, "Name expected");
|
||||||
|
assert.equal(uglify.minify("function f(export){}").error.message, "Invalid function parameter");
|
||||||
|
});
|
||||||
|
|
||||||
|
it("Should not parse invalid uses of import", function() {
|
||||||
|
assert.equal(uglify.minify("import").error.message, "Unexpected token: eof (undefined)");
|
||||||
|
assert.equal(uglify.minify("import;").error.message, "Unexpected token: punc (;)");
|
||||||
|
assert.equal(uglify.minify("var import;").error.message, "Unexpected token: import");
|
||||||
|
assert.equal(uglify.minify("var import = 1;").error.message, "Unexpected token: import");
|
||||||
|
assert.equal(uglify.minify("function f(import){}").error.message, "Unexpected token: name (import)");
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -26,12 +26,12 @@ describe("bin/uglifyjs with input file globs", function() {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
it("bin/uglifyjs with multiple input file globs.", function(done) {
|
it("bin/uglifyjs with multiple input file globs.", function(done) {
|
||||||
var command = uglifyjscmd + ' "test/input/issue-1242/???.es5" "test/input/issue-1242/*.js" -mc toplevel';
|
var command = uglifyjscmd + ' "test/input/issue-1242/???.es5" "test/input/issue-1242/*.js" -mc toplevel,passes=2';
|
||||||
|
|
||||||
exec(command, function(err, stdout) {
|
exec(command, function(err, stdout) {
|
||||||
if (err) throw err;
|
if (err) throw err;
|
||||||
|
|
||||||
assert.strictEqual(stdout, 'var print=console.log.bind(console);print("qux",9,6),print("Foo:",2*11);\n');
|
assert.strictEqual(stdout, 'var print=console.log.bind(console);print("qux",9,6),print("Foo:",22);\n');
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -2,16 +2,17 @@ var Uglify = require('../../');
|
|||||||
var assert = require("assert");
|
var assert = require("assert");
|
||||||
|
|
||||||
describe("let", function() {
|
describe("let", function() {
|
||||||
it("Should not produce reserved keywords as variable name in mangle", function(done) {
|
this.timeout(30000);
|
||||||
this.timeout(10000);
|
it("Should not produce reserved keywords as variable name in mangle", function() {
|
||||||
|
|
||||||
// Produce a lot of variables in a function and run it through mangle.
|
// Produce a lot of variables in a function and run it through mangle.
|
||||||
var s = '"dddddeeeeelllllooooottttt"; function foo() {';
|
var s = '"dddddeeeeelllllooooottttt"; function foo() {';
|
||||||
for (var i = 0; i < 18000; i++) {
|
for (var i = 0; i < 18000; i++) {
|
||||||
s += "var v" + i + "=0;";
|
s += "var v" + i + "=0;";
|
||||||
}
|
}
|
||||||
s += '}';
|
s += '}';
|
||||||
var result = Uglify.minify(s, {compress: false});
|
var result = Uglify.minify(s, {
|
||||||
|
compress: false
|
||||||
|
}).code;
|
||||||
|
|
||||||
// Verify that select keywords and reserved keywords not produced
|
// Verify that select keywords and reserved keywords not produced
|
||||||
[
|
[
|
||||||
@@ -19,7 +20,7 @@ describe("let", function() {
|
|||||||
"let",
|
"let",
|
||||||
"var",
|
"var",
|
||||||
].forEach(function(name) {
|
].forEach(function(name) {
|
||||||
assert.strictEqual(result.code.indexOf("var " + name + "="), -1);
|
assert.strictEqual(result.indexOf("var " + name + "="), -1);
|
||||||
});
|
});
|
||||||
|
|
||||||
// Verify that the variable names that appeared immediately before
|
// Verify that the variable names that appeared immediately before
|
||||||
@@ -30,9 +31,27 @@ describe("let", function() {
|
|||||||
"eet", "fet",
|
"eet", "fet",
|
||||||
"rar", "oar",
|
"rar", "oar",
|
||||||
].forEach(function(name) {
|
].forEach(function(name) {
|
||||||
assert.ok(result.code.indexOf("var " + name + "=") >= 0);
|
assert.notStrictEqual(result.indexOf("var " + name + "="), -1);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
it("Should quote mangled properties that are reserved keywords", function() {
|
||||||
|
var s = '"rrrrrnnnnniiiiiaaaaa";';
|
||||||
|
for (var i = 0; i < 18000; i++) {
|
||||||
|
s += "v.b" + i + ";";
|
||||||
|
}
|
||||||
|
var result = Uglify.minify(s, {
|
||||||
|
compress: false,
|
||||||
|
ie8: true,
|
||||||
|
mangle: {
|
||||||
|
properties: true,
|
||||||
|
}
|
||||||
|
}).code;
|
||||||
|
[
|
||||||
|
"in",
|
||||||
|
"var",
|
||||||
|
].forEach(function(name) {
|
||||||
|
assert.notStrictEqual(result.indexOf(name), -1);
|
||||||
|
assert.notStrictEqual(result.indexOf('v["' + name + '"]'), -1);
|
||||||
});
|
});
|
||||||
|
|
||||||
done();
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -253,13 +253,19 @@ describe("Left-hand side expressions", function () {
|
|||||||
// Multiple spreads are not allowed in destructuring array
|
// Multiple spreads are not allowed in destructuring array
|
||||||
expect("[...a, ...b] = [1, 2, 3, 4]", "Spread must the be last element in destructuring array");
|
expect("[...a, ...b] = [1, 2, 3, 4]", "Spread must the be last element in destructuring array");
|
||||||
|
|
||||||
// Spread in obvious object pattern
|
// Array spread must be last in destructuring declaration
|
||||||
expect("({...a} = foo)", "Unexpected token: expand (...)");
|
expect("let [ ...x, a ] = o;", "Rest element must be last element");
|
||||||
|
|
||||||
|
// Only one spread per destructuring array declaration
|
||||||
|
expect("let [ a, ...x, ...y ] = o;", "Rest element must be last element");
|
||||||
|
|
||||||
// Spread in block should not be allowed
|
// Spread in block should not be allowed
|
||||||
expect("{...a} = foo", "Unexpected token: expand (...)");
|
expect("{...a} = foo", "Unexpected token: expand (...)");
|
||||||
|
|
||||||
// Not in standard yet
|
// Object spread must be last in destructuring declaration
|
||||||
expect("let foo = {bar: 42}, bar; bar = {...foo}", "Unexpected token: expand (...)");
|
expect("let { ...x, a } = o;", "Rest element must be last element");
|
||||||
|
|
||||||
|
// Only one spread per destructuring declaration
|
||||||
|
expect("let { a, ...x, ...y } = o;", "Rest element must be last element");
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -73,6 +73,13 @@ describe("minify", function() {
|
|||||||
assert.strictEqual(run_code(compressed), run_code(original));
|
assert.strictEqual(run_code(compressed), run_code(original));
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("should not parse invalid use of reserved words", function() {
|
||||||
|
assert.strictEqual(Uglify.minify("function enum(){}").error, undefined);
|
||||||
|
assert.strictEqual(Uglify.minify("function static(){}").error, undefined);
|
||||||
|
assert.strictEqual(Uglify.minify("function super(){}").error.message, "Unexpected token: name (super)");
|
||||||
|
assert.strictEqual(Uglify.minify("function this(){}").error.message, "Unexpected token: name (this)");
|
||||||
|
});
|
||||||
|
|
||||||
describe("keep_quoted_props", function() {
|
describe("keep_quoted_props", function() {
|
||||||
it("Should preserve quotes in object literals", function() {
|
it("Should preserve quotes in object literals", function() {
|
||||||
var js = 'var foo = {"x": 1, y: 2, \'z\': 3};';
|
var js = 'var foo = {"x": 1, y: 2, \'z\': 3};';
|
||||||
@@ -124,6 +131,17 @@ describe("minify", function() {
|
|||||||
assert.strictEqual(result.code,
|
assert.strictEqual(result.code,
|
||||||
'a["foo"]="bar",a.a="red",x={"bar":10};');
|
'a["foo"]="bar",a.a="red",x={"bar":10};');
|
||||||
});
|
});
|
||||||
|
it("Should not mangle quoted property within dead code", function() {
|
||||||
|
var result = Uglify.minify('({ "keep": 1 }); g.keep = g.change;', {
|
||||||
|
mangle: {
|
||||||
|
properties: {
|
||||||
|
keep_quoted: true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
if (result.error) throw result.error;
|
||||||
|
assert.strictEqual(result.code, "g.keep=g.g;");
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("inSourceMap", function() {
|
describe("inSourceMap", function() {
|
||||||
@@ -280,4 +298,67 @@ describe("minify", function() {
|
|||||||
assert.strictEqual(result.code, "alert({bar:42});");
|
assert.strictEqual(result.code, "alert({bar:42});");
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe("duplicated block-scoped declarations", function() {
|
||||||
|
[
|
||||||
|
"let a=1;let a=2;",
|
||||||
|
"let a=1;var a=2;",
|
||||||
|
"var a=1;let a=2;",
|
||||||
|
"let[a]=[1];var a=2;",
|
||||||
|
"let a=1;var[a]=[2];",
|
||||||
|
"let[a]=[1];var[a]=[2];",
|
||||||
|
"const a=1;const a=2;",
|
||||||
|
"const a=1;var a=2;",
|
||||||
|
"var a=1;const a=2;",
|
||||||
|
"const[a]=[1];var a=2;",
|
||||||
|
"const a=1;var[a]=[2];",
|
||||||
|
"const[a]=[1];var[a]=[2];",
|
||||||
|
].forEach(function(code) {
|
||||||
|
it(code, function() {
|
||||||
|
var result = Uglify.minify(code, {
|
||||||
|
compress: false,
|
||||||
|
mangle: false
|
||||||
|
});
|
||||||
|
assert.strictEqual(result.error, undefined);
|
||||||
|
assert.strictEqual(result.code, code);
|
||||||
|
result = Uglify.minify(code);
|
||||||
|
var err = result.error;
|
||||||
|
assert.ok(err instanceof Error);
|
||||||
|
assert.strictEqual(err.stack.split(/\n/)[0], "SyntaxError: a redeclared");
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe("collapse_vars", function() {
|
||||||
|
it("Should not produce invalid AST", function() {
|
||||||
|
var code = [
|
||||||
|
"function f(a) {",
|
||||||
|
" a = x();",
|
||||||
|
" return a;",
|
||||||
|
"}",
|
||||||
|
"f();",
|
||||||
|
].join("\n");
|
||||||
|
var ast = Uglify.minify(code, {
|
||||||
|
compress: false,
|
||||||
|
mangle: false,
|
||||||
|
output: {
|
||||||
|
ast: true
|
||||||
|
},
|
||||||
|
}).ast;
|
||||||
|
assert.strictEqual(ast.TYPE, "Toplevel");
|
||||||
|
assert.strictEqual(ast.body.length, 2);
|
||||||
|
assert.strictEqual(ast.body[0].TYPE, "Defun");
|
||||||
|
assert.strictEqual(ast.body[0].body.length, 2);
|
||||||
|
assert.strictEqual(ast.body[0].body[0].TYPE, "SimpleStatement");
|
||||||
|
var stat = ast.body[0].body[0];
|
||||||
|
Uglify.minify(ast, {
|
||||||
|
compress: {
|
||||||
|
sequences: false
|
||||||
|
},
|
||||||
|
mangle: false
|
||||||
|
});
|
||||||
|
assert.ok(stat.body);
|
||||||
|
assert.strictEqual(stat.print_to_string(), "a=x()");
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -4,7 +4,11 @@ var assert = require("assert");
|
|||||||
describe("Object", function() {
|
describe("Object", function() {
|
||||||
it("Should allow objects to have a methodDefinition as property", function() {
|
it("Should allow objects to have a methodDefinition as property", function() {
|
||||||
var code = "var a = {test() {return true;}}";
|
var code = "var a = {test() {return true;}}";
|
||||||
assert.equal(Uglify.minify(code).code, "var a={test(){return!0}};");
|
assert.equal(Uglify.minify(code, {
|
||||||
|
compress: {
|
||||||
|
arrows: false
|
||||||
|
}
|
||||||
|
}).code, "var a={test(){return!0}};");
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should not allow objects to use static keywords like in classes", function() {
|
it("Should not allow objects to use static keywords like in classes", function() {
|
||||||
|
|||||||
@@ -61,9 +61,9 @@ describe("String literals", function() {
|
|||||||
var tests = [
|
var tests = [
|
||||||
['"\\76";', ';">";'],
|
['"\\76";', ';">";'],
|
||||||
['"\\0"', '"\\0";'],
|
['"\\0"', '"\\0";'],
|
||||||
['"\\08"', '"\\08";'],
|
['"\\08"', '"\\x008";'],
|
||||||
['"\\008"', '"\\08";'],
|
['"\\008"', '"\\x008";'],
|
||||||
['"\\0008"', '"\\08";'],
|
['"\\0008"', '"\\x008";'],
|
||||||
['"use strict" === "use strict";\n"\\76";', '"use strict"==="use strict";">";'],
|
['"use strict" === "use strict";\n"\\76";', '"use strict"==="use strict";">";'],
|
||||||
['"use\\\n strict";\n"\\07";', ';"use strict";"\07";']
|
['"use\\\n strict";\n"\\07";', ';"use strict";"\07";']
|
||||||
];
|
];
|
||||||
@@ -75,7 +75,44 @@ describe("String literals", function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it("Should not throw error when digit is 8 or 9", function() {
|
it("Should not throw error when digit is 8 or 9", function() {
|
||||||
assert.equal(UglifyJS.parse('"use strict";"\\08"').print_to_string(), '"use strict";"\\08";');
|
assert.equal(UglifyJS.parse('"use strict";"\\08"').print_to_string(), '"use strict";"\\x008";');
|
||||||
assert.equal(UglifyJS.parse('"use strict";"\\09"').print_to_string(), '"use strict";"\\09";');
|
assert.equal(UglifyJS.parse('"use strict";"\\09"').print_to_string(), '"use strict";"\\x009";');
|
||||||
|
});
|
||||||
|
|
||||||
|
it("Should not unescape unpaired surrogates", function() {
|
||||||
|
var code = [];
|
||||||
|
for (var i = 0; i <= 0xF; i++) {
|
||||||
|
code.push("\\u000" + i.toString(16));
|
||||||
|
}
|
||||||
|
for (;i <= 0xFF; i++) {
|
||||||
|
code.push("\\u00" + i.toString(16));
|
||||||
|
}
|
||||||
|
for (;i <= 0xFFF; i++) {
|
||||||
|
code.push("\\u0" + i.toString(16));
|
||||||
|
}
|
||||||
|
for (; i <= 0xFFFF; i++) {
|
||||||
|
code.push("\\u" + i.toString(16));
|
||||||
|
}
|
||||||
|
code = '"' + code.join() + '"';
|
||||||
|
var normal = UglifyJS.minify(code, {
|
||||||
|
compress: false,
|
||||||
|
mangle: false,
|
||||||
|
output: {
|
||||||
|
ascii_only: false
|
||||||
|
}
|
||||||
|
});
|
||||||
|
if (normal.error) throw normal.error;
|
||||||
|
assert.ok(code.length > normal.code.length);
|
||||||
|
assert.strictEqual(eval(code), eval(normal.code));
|
||||||
|
var ascii = UglifyJS.minify(code, {
|
||||||
|
compress: false,
|
||||||
|
mangle: false,
|
||||||
|
output: {
|
||||||
|
ascii_only: false
|
||||||
|
}
|
||||||
|
});
|
||||||
|
if (ascii.error) throw ascii.error;
|
||||||
|
assert.ok(code.length > ascii.code.length);
|
||||||
|
assert.strictEqual(eval(code), eval(ascii.code));
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
var assert = require("assert");
|
var assert = require("assert");
|
||||||
|
var semver = require("semver");
|
||||||
var uglify = require("../node");
|
var uglify = require("../node");
|
||||||
|
|
||||||
describe("Unicode", function() {
|
describe("Unicode", function() {
|
||||||
@@ -138,8 +139,34 @@ describe("Unicode", function() {
|
|||||||
|
|
||||||
it("Should parse raw characters correctly", function() {
|
it("Should parse raw characters correctly", function() {
|
||||||
var ast = uglify.parse('console.log("\\udbff");');
|
var ast = uglify.parse('console.log("\\udbff");');
|
||||||
assert.strictEqual(ast.print_to_string(), 'console.log("\udbff");');
|
assert.strictEqual(ast.print_to_string(), 'console.log("\\udbff");');
|
||||||
ast = uglify.parse(ast.print_to_string());
|
ast = uglify.parse(ast.print_to_string());
|
||||||
assert.strictEqual(ast.print_to_string(), 'console.log("\udbff");');
|
assert.strictEqual(ast.print_to_string(), 'console.log("\\udbff");');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
if (semver.satisfies(process.version, ">=4")) {
|
||||||
|
it("Should not unescape unpaired surrogates", function() {
|
||||||
|
this.timeout(5000);
|
||||||
|
var code = [];
|
||||||
|
for (var i = 0; i <= 0x20001; i++) {
|
||||||
|
code.push("\\u{" + i.toString(16) + "}");
|
||||||
|
}
|
||||||
|
code = '"' + code.join() + '"';
|
||||||
|
[true, false].forEach(function(ascii_only) {
|
||||||
|
[5, 6].forEach(function(ecma) {
|
||||||
|
var result = uglify.minify(code, {
|
||||||
|
compress: false,
|
||||||
|
mangle: false,
|
||||||
|
output: {
|
||||||
|
ascii_only: ascii_only
|
||||||
|
},
|
||||||
|
ecma: ecma
|
||||||
|
});
|
||||||
|
if (result.error) throw result.error;
|
||||||
|
if (ecma > 5) assert.ok(code.length > result.code.length);
|
||||||
|
assert.strictEqual(eval(code), eval(result.code));
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -102,4 +102,15 @@ describe("Yield", function() {
|
|||||||
assert.throws(test(tests[i]), fail, tests[i]);
|
assert.throws(test(tests[i]), fail, tests[i]);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("Should allow yield to be used as class/object property name", function() {
|
||||||
|
var input = [
|
||||||
|
'"use strict";',
|
||||||
|
"({yield:42});",
|
||||||
|
"({yield(){}});",
|
||||||
|
"(class{yield(){}});",
|
||||||
|
"class C{yield(){}}",
|
||||||
|
].join("");
|
||||||
|
assert.strictEqual(UglifyJS.minify(input, { compress: false }).code, input);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -111,18 +111,26 @@ function run_compress_tests() {
|
|||||||
};
|
};
|
||||||
if (!options.warnings) options.warnings = true;
|
if (!options.warnings) options.warnings = true;
|
||||||
}
|
}
|
||||||
|
if (test.mangle && test.mangle.properties && test.mangle.properties.keep_quoted) {
|
||||||
|
var quoted_props = test.mangle.properties.reserved;
|
||||||
|
if (!Array.isArray(quoted_props)) quoted_props = [];
|
||||||
|
test.mangle.properties.reserved = quoted_props;
|
||||||
|
U.reserve_quoted_keys(input, quoted_props);
|
||||||
|
}
|
||||||
|
if (test.rename) {
|
||||||
|
input.figure_out_scope(test.mangle);
|
||||||
|
input.expand_names(test.mangle);
|
||||||
|
}
|
||||||
var cmp = new U.Compressor(options, true);
|
var cmp = new U.Compressor(options, true);
|
||||||
var output = cmp.compress(input);
|
var output = cmp.compress(input);
|
||||||
output.figure_out_scope(test.mangle);
|
output.figure_out_scope(test.mangle);
|
||||||
if (test.mangle || test.mangle_props) {
|
if (test.mangle) {
|
||||||
U.base54.reset();
|
U.base54.reset();
|
||||||
output.compute_char_frequency(test.mangle);
|
output.compute_char_frequency(test.mangle);
|
||||||
}
|
|
||||||
if (test.mangle) {
|
|
||||||
output.mangle_names(test.mangle);
|
output.mangle_names(test.mangle);
|
||||||
}
|
if (test.mangle.properties) {
|
||||||
if (test.mangle_props) {
|
output = U.mangle_properties(output, test.mangle.properties);
|
||||||
output = U.mangle_properties(output, test.mangle_props);
|
}
|
||||||
}
|
}
|
||||||
output = make_code(output, output_options);
|
output = make_code(output, output_options);
|
||||||
if (expect != output) {
|
if (expect != output) {
|
||||||
|
|||||||
@@ -162,6 +162,7 @@ var VALUES = [
|
|||||||
'"object"',
|
'"object"',
|
||||||
'"number"',
|
'"number"',
|
||||||
'"function"',
|
'"function"',
|
||||||
|
'this',
|
||||||
];
|
];
|
||||||
|
|
||||||
var BINARY_OPS_NO_COMMA = [
|
var BINARY_OPS_NO_COMMA = [
|
||||||
@@ -349,10 +350,10 @@ function createParams() {
|
|||||||
return params.join(', ');
|
return params.join(', ');
|
||||||
}
|
}
|
||||||
|
|
||||||
function createArgs() {
|
function createArgs(recurmax, stmtDepth, canThrow) {
|
||||||
var args = [];
|
var args = [];
|
||||||
for (var n = rng(4); --n >= 0;) {
|
for (var n = rng(4); --n >= 0;) {
|
||||||
args.push(createValue());
|
args.push(rng(2) ? createValue() : createExpression(recurmax - 1, COMMA_OK, stmtDepth, canThrow));
|
||||||
}
|
}
|
||||||
return args.join(', ');
|
return args.join(', ');
|
||||||
}
|
}
|
||||||
@@ -390,9 +391,10 @@ function createFunction(recurmax, inGlobal, noDecl, canThrow, stmtDepth) {
|
|||||||
|
|
||||||
VAR_NAMES.length = namesLenBefore;
|
VAR_NAMES.length = namesLenBefore;
|
||||||
|
|
||||||
if (noDecl) s = 'var ' + createVarName(MANDATORY) + ' = ' + s + '(' + createExpression(recurmax, COMMA_OK, stmtDepth, canThrow) + ');';
|
if (noDecl) s = 'var ' + createVarName(MANDATORY) + ' = ' + s;
|
||||||
// avoid "function statements" (decl inside statements)
|
// avoid "function statements" (decl inside statements)
|
||||||
else if (inGlobal || rng(10) > 0) s += 'var ' + createVarName(MANDATORY) + ' = ' + name + '(' + createArgs() + ');';
|
else if (inGlobal || rng(10) > 0) s += 'var ' + createVarName(MANDATORY) + ' = ' + name;
|
||||||
|
s += '(' + createArgs(recurmax, stmtDepth, canThrow) + ');';
|
||||||
|
|
||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
@@ -626,6 +628,9 @@ function _createExpression(recurmax, noComma, stmtDepth, canThrow) {
|
|||||||
case p++:
|
case p++:
|
||||||
case p++:
|
case p++:
|
||||||
return createValue();
|
return createValue();
|
||||||
|
case p++:
|
||||||
|
case p++:
|
||||||
|
return getVarName();
|
||||||
case p++:
|
case p++:
|
||||||
return createExpression(recurmax, COMMA_OK, stmtDepth, canThrow);
|
return createExpression(recurmax, COMMA_OK, stmtDepth, canThrow);
|
||||||
case p++:
|
case p++:
|
||||||
|
|||||||
@@ -16,11 +16,9 @@
|
|||||||
{},
|
{},
|
||||||
{
|
{
|
||||||
"compress": {
|
"compress": {
|
||||||
"toplevel": true
|
"hoist_props": true
|
||||||
},
|
},
|
||||||
"mangle": {
|
"toplevel": true
|
||||||
"toplevel": true
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"compress": {
|
"compress": {
|
||||||
|
|||||||
Reference in New Issue
Block a user