Compare commits
168 Commits
harmony-v3
...
v3.3.10
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
0cfbd79aa1 | ||
|
|
d66d86f20b | ||
|
|
905325d3e2 | ||
|
|
dea0cc0662 | ||
|
|
d69d8007d6 | ||
|
|
c0b8f2a16d | ||
|
|
cb0257dbbf | ||
|
|
9637f51b68 | ||
|
|
3026bd8975 | ||
|
|
78a44d5ab0 | ||
|
|
7e13c0db40 | ||
|
|
e6a2e9e4d0 | ||
|
|
e773f03927 | ||
|
|
b16380d669 | ||
|
|
334b07a3db | ||
|
|
3cc1527f00 | ||
|
|
525a61fb55 | ||
|
|
c3a002ff97 | ||
|
|
fad6766a90 | ||
|
|
aa664dea0a | ||
|
|
102f994b9d | ||
|
|
2a4c68be4f | ||
|
|
541e6011af | ||
|
|
6fa3fbeae8 | ||
|
|
4eb4cb656c | ||
|
|
193612ac67 | ||
|
|
95cfce68ea | ||
|
|
ec4202590d | ||
|
|
5e2cd07d6f | ||
|
|
06166df999 | ||
|
|
e2dc9cf091 | ||
|
|
069df27bf1 | ||
|
|
3e7873217c | ||
|
|
e21bab7ce6 | ||
|
|
ac9a168fba | ||
|
|
81b64549ce | ||
|
|
082e004b87 | ||
|
|
983e69128b | ||
|
|
b335912e86 | ||
|
|
cc07f3b806 | ||
|
|
07e4b64f3a | ||
|
|
d3ce2bc9e7 | ||
|
|
cff3bf4914 | ||
|
|
79cfac77bd | ||
|
|
224c14d49d | ||
|
|
7857354d85 | ||
|
|
b4aef753e7 | ||
|
|
424173d311 | ||
|
|
ec7cd1dcf7 | ||
|
|
7def684730 | ||
|
|
10f961c27b | ||
|
|
b483678ca7 | ||
|
|
cbbe6fad60 | ||
|
|
f96929c031 | ||
|
|
2b6657e967 | ||
|
|
7c0c92943f | ||
|
|
62a66dfff4 | ||
|
|
2cab348341 | ||
|
|
460218a3f8 | ||
|
|
e49416e4aa | ||
|
|
d4d7d99b70 | ||
|
|
6a696d0a7b | ||
|
|
1c9e13f47d | ||
|
|
b757450cd8 | ||
|
|
23ec484806 | ||
|
|
f1e1bb419a | ||
|
|
6a0af85c8b | ||
|
|
09269be974 | ||
|
|
bf832cde16 | ||
|
|
2972d58dbb | ||
|
|
2e22d38a02 | ||
|
|
ce27bcd69a | ||
|
|
9336cc8247 | ||
|
|
9809567dfc | ||
|
|
1ee8be8d91 | ||
|
|
8430c2f9f8 | ||
|
|
659c8a7632 | ||
|
|
3564b4f20d | ||
|
|
3505a3604a | ||
|
|
9b1bc6c014 | ||
|
|
9f23185f2b | ||
|
|
b82feb9302 | ||
|
|
7f2a591c7e | ||
|
|
afbcebddf6 | ||
|
|
484e484571 | ||
|
|
6f3f21233f | ||
|
|
a6873a3859 | ||
|
|
7a6d452b54 | ||
|
|
9b58b54e2d | ||
|
|
c598a12af9 | ||
|
|
cfe3a98ce5 | ||
|
|
14778e049b | ||
|
|
446fb0198b | ||
|
|
7d3cddf9d6 | ||
|
|
6dead95eb3 | ||
|
|
cc931b3ad8 | ||
|
|
d838b4b52e | ||
|
|
2f3bddbaca | ||
|
|
673b071637 | ||
|
|
da82fa59a7 | ||
|
|
333792352e | ||
|
|
e2ec270b04 | ||
|
|
ed7a0a454e | ||
|
|
d819559a01 | ||
|
|
8ca49155a8 | ||
|
|
b95e3338d9 | ||
|
|
e40a0ee9c6 | ||
|
|
cb62bd98d3 | ||
|
|
f30790b11b | ||
|
|
5205dbcbf4 | ||
|
|
3ff625de7e | ||
|
|
4832bc5d88 | ||
|
|
7f342cb3e3 | ||
|
|
05e7d34ed4 | ||
|
|
86607156e3 | ||
|
|
0fe259e9c5 | ||
|
|
8701a99a15 | ||
|
|
1476c78b53 | ||
|
|
cb6a92892f | ||
|
|
f1556cb945 | ||
|
|
efffb81735 | ||
|
|
202f90ef8f | ||
|
|
c07ea17c01 | ||
|
|
edb4e3bd52 | ||
|
|
4113609dd4 | ||
|
|
7ac7b0872f | ||
|
|
86ae5881b7 | ||
|
|
fac003c64f | ||
|
|
2273655c17 | ||
|
|
01057cf76d | ||
|
|
032f096b7f | ||
|
|
4b334edf49 | ||
|
|
8ddcbc39e6 | ||
|
|
0b0eac1d5d | ||
|
|
b29fc8b27c | ||
|
|
5de369fa67 | ||
|
|
7918a50d52 | ||
|
|
21794c9b8d | ||
|
|
6c686ce593 | ||
|
|
db902af4c6 | ||
|
|
7d6907cb99 | ||
|
|
092d9affb8 | ||
|
|
8f681b1d17 | ||
|
|
90313875f7 | ||
|
|
3f18a61532 | ||
|
|
02a6ce07eb | ||
|
|
738fd52bc4 | ||
|
|
d18979bb23 | ||
|
|
8266993c6e | ||
|
|
9a137e8613 | ||
|
|
ef618332ea | ||
|
|
7f418978c9 | ||
|
|
04cc395c35 | ||
|
|
e008dc1bde | ||
|
|
ddf96cfda2 | ||
|
|
ebfd5c5c74 | ||
|
|
f2ad542679 | ||
|
|
c43118be4f | ||
|
|
93f3b2b114 | ||
|
|
bf000beae7 | ||
|
|
0e16d92786 | ||
|
|
2441827408 | ||
|
|
0aff037a35 | ||
|
|
74a2f53683 | ||
|
|
e20935c3f2 | ||
|
|
3e34f62a1c | ||
|
|
d21cb84696 | ||
|
|
3dd495ecdd |
61
CONTRIBUTING.md
Normal file
61
CONTRIBUTING.md
Normal file
@@ -0,0 +1,61 @@
|
|||||||
|
Contributing
|
||||||
|
============
|
||||||
|
|
||||||
|
## Documentation
|
||||||
|
|
||||||
|
Every new feature and API change should be accompanied by a README additon.
|
||||||
|
|
||||||
|
## Testing
|
||||||
|
|
||||||
|
All features and bugs should have tests that verify the fix. You can run all
|
||||||
|
tests using `npm test`.
|
||||||
|
|
||||||
|
The most common type of test are tests that verify input and output of the
|
||||||
|
Uglify transforms. These tests exist in `test/compress`. New tests can be added
|
||||||
|
either to an existing file or in a new file `issue-xxx.js`.
|
||||||
|
|
||||||
|
Tests that cannot be expressed as a simple AST can be found in `test/mocha`.
|
||||||
|
|
||||||
|
## Code style
|
||||||
|
|
||||||
|
- File encoding must be `UTF-8`.
|
||||||
|
- `LF` is always used as a line ending.
|
||||||
|
- Statements end with semicolons.
|
||||||
|
- Indentation uses 4 spaces, switch `case` 2 spaces.
|
||||||
|
- Identifiers use `snake_case`.
|
||||||
|
- Strings use double quotes (`"`).
|
||||||
|
- Use a trailing comma for multiline array and object literals to minimize diffs.
|
||||||
|
- The Uglify code only uses ES5, even in the `harmony` branch.
|
||||||
|
- Line length should be at most 80 cols, except when it is easier to read a
|
||||||
|
longer line.
|
||||||
|
- If both sides of a comparison are of the same type, `==` and `!=` are used.
|
||||||
|
- Multiline conditions place `&&` and `||` first on the line.
|
||||||
|
|
||||||
|
**Example feature**
|
||||||
|
|
||||||
|
```js
|
||||||
|
OPT(AST_Debugger, function(self, compressor) {
|
||||||
|
if (compressor.option("drop_debugger"))
|
||||||
|
return make_node(AST_EmptyStatement, self);
|
||||||
|
return self;
|
||||||
|
});
|
||||||
|
```
|
||||||
|
|
||||||
|
**Example test case**
|
||||||
|
|
||||||
|
```js
|
||||||
|
drop_debugger: {
|
||||||
|
options = {
|
||||||
|
drop_debugger: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
debugger;
|
||||||
|
if (foo) debugger;
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
if (foo);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
2
LICENSE
2
LICENSE
@@ -1,6 +1,6 @@
|
|||||||
UglifyJS is released under the BSD license:
|
UglifyJS is released under the BSD license:
|
||||||
|
|
||||||
Copyright 2012-2013 (c) Mihai Bazon <mihai.bazon@gmail.com>
|
Copyright 2012-2018 (c) Mihai Bazon <mihai.bazon@gmail.com>
|
||||||
|
|
||||||
Redistribution and use in source and binary forms, with or without
|
Redistribution and use in source and binary forms, with or without
|
||||||
modification, are permitted provided that the following conditions
|
modification, are permitted provided that the following conditions
|
||||||
|
|||||||
145
README.md
145
README.md
@@ -1,11 +1,14 @@
|
|||||||
uglify-es
|
UglifyJS 3
|
||||||
=========
|
==========
|
||||||
|
|
||||||
A JavaScript parser, mangler/compressor and beautifier toolkit for ES6+.
|
UglifyJS is a JavaScript parser, minifier, compressor and beautifier toolkit.
|
||||||
|
|
||||||
#### Note:
|
#### Note:
|
||||||
- **`uglify-es` is API/CLI compatible with `uglify-js@3`.**
|
- **`uglify-js@3` has a simplified [API](#api-reference) and [CLI](#command-line-usage) that is not backwards compatible with [`uglify-js@2`](https://github.com/mishoo/UglifyJS2/tree/v2.x)**.
|
||||||
- **`uglify-es` is not backwards compatible with `uglify-js@2`.**
|
- **Documentation for UglifyJS `2.x` releases can be found [here](https://github.com/mishoo/UglifyJS2/tree/v2.x)**.
|
||||||
|
- `uglify-js` only supports ECMAScript 5 (ES5).
|
||||||
|
- Those wishing to minify
|
||||||
|
ES2015+ (ES6+) should use the `npm` package [**uglify-es**](https://github.com/mishoo/UglifyJS2/tree/harmony).
|
||||||
|
|
||||||
Install
|
Install
|
||||||
-------
|
-------
|
||||||
@@ -15,11 +18,11 @@ First make sure you have installed the latest version of [node.js](http://nodejs
|
|||||||
|
|
||||||
From NPM for use as a command line app:
|
From NPM for use as a command line app:
|
||||||
|
|
||||||
npm install uglify-es -g
|
npm install uglify-js -g
|
||||||
|
|
||||||
From NPM for programmatic use:
|
From NPM for programmatic use:
|
||||||
|
|
||||||
npm install uglify-es
|
npm install uglify-js
|
||||||
|
|
||||||
# Command line usage
|
# Command line usage
|
||||||
|
|
||||||
@@ -67,7 +70,7 @@ a double dash to prevent input files being used as option arguments:
|
|||||||
`debug` Add debug prefix and suffix.
|
`debug` Add debug prefix and suffix.
|
||||||
`domprops` Mangle property names that overlaps
|
`domprops` Mangle property names that overlaps
|
||||||
with DOM properties.
|
with DOM properties.
|
||||||
`keep_quoted` Only mangle unquoted properies.
|
`keep_quoted` Only mangle unquoted properties.
|
||||||
`regex` Only mangle matched property names.
|
`regex` Only mangle matched property names.
|
||||||
`reserved` List of names that should not be mangled.
|
`reserved` List of names that should not be mangled.
|
||||||
-b, --beautify [options] Beautify output/specify output options:
|
-b, --beautify [options] Beautify output/specify output options:
|
||||||
@@ -102,20 +105,13 @@ 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> 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.
|
||||||
--safari10 Support non-standard Safari 10/11.
|
|
||||||
Equivalent to setting `safari10: true` in `minify()`
|
|
||||||
for `mangle` and `output` options.
|
|
||||||
By default `uglify-es` will not work around
|
|
||||||
Safari 10/11 bugs.
|
|
||||||
--self Build UglifyJS as a library (implies --wrap UglifyJS)
|
--self Build UglifyJS as a library (implies --wrap UglifyJS)
|
||||||
--source-map [options] Enable source map/specify source map options:
|
--source-map [options] Enable source map/specify source map options:
|
||||||
`base` Path to compute relative paths from input files.
|
`base` Path to compute relative paths from input files.
|
||||||
@@ -349,7 +345,7 @@ identify mistakes like writing mangled keys to storage.
|
|||||||
Assuming installation via NPM, you can load UglifyJS in your application
|
Assuming installation via NPM, you can load UglifyJS in your application
|
||||||
like this:
|
like this:
|
||||||
```javascript
|
```javascript
|
||||||
var UglifyJS = require("uglify-es");
|
var UglifyJS = require("uglify-js");
|
||||||
```
|
```
|
||||||
|
|
||||||
There is a single high level function, **`minify(code, options)`**,
|
There is a single high level function, **`minify(code, options)`**,
|
||||||
@@ -478,9 +474,6 @@ if (result.error) throw result.error;
|
|||||||
|
|
||||||
## Minify options
|
## Minify options
|
||||||
|
|
||||||
- `ecma` (default `undefined`) - pass `5`, `6`, `7` or `8` to override `parse`,
|
|
||||||
`compress` and `output` options.
|
|
||||||
|
|
||||||
- `warnings` (default `false`) — pass `true` to return compressor warnings
|
- `warnings` (default `false`) — pass `true` to return compressor warnings
|
||||||
in `result.warnings`. Use the value `"verbose"` for more detailed warnings.
|
in `result.warnings`. Use the value `"verbose"` for more detailed warnings.
|
||||||
|
|
||||||
@@ -515,17 +508,8 @@ 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
|
- `keep_fnames` (default: `false`) - pass `true` to prevent discarding or mangling
|
||||||
of function names. Useful for code relying on `Function.prototype.name`. If the
|
of function names. Useful for code relying on `Function.prototype.name`.
|
||||||
top level minify option `keep_classnames` is `undefined` it will be overriden with
|
|
||||||
the value of the top level minify option `keep_fnames`.
|
|
||||||
|
|
||||||
- `safari10` (default: `false`) - pass `true` to work around Safari 10/11 bugs in
|
|
||||||
loop scoping and `await`. See `safari10` options in [`mangle`](#mangle-options)
|
|
||||||
and [`output`](#output-options) for details.
|
|
||||||
|
|
||||||
## Minify options structure
|
## Minify options structure
|
||||||
|
|
||||||
@@ -550,13 +534,9 @@ if (result.error) throw result.error;
|
|||||||
sourceMap: {
|
sourceMap: {
|
||||||
// source map options
|
// source map options
|
||||||
},
|
},
|
||||||
ecma: 5, // specify one of: 5, 6, 7 or 8
|
|
||||||
keep_classnames: false,
|
|
||||||
keep_fnames: false,
|
|
||||||
ie8: false,
|
|
||||||
nameCache: null, // or specify a name cache object
|
nameCache: null, // or specify a name cache object
|
||||||
safari10: false,
|
|
||||||
toplevel: false,
|
toplevel: false,
|
||||||
|
ie8: false,
|
||||||
warnings: false,
|
warnings: false,
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
@@ -612,27 +592,15 @@ If you're using the `X-SourceMap` header instead, you can just omit `sourceMap.u
|
|||||||
|
|
||||||
- `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
|
|
||||||
is not presently enforced except for ES8 optional trailing commas in function
|
|
||||||
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
|
||||||
|
|
||||||
- `arrows` (default: `true`) -- Converts `()=>{return x}` to `()=>x`. Class
|
|
||||||
and object literal methods will also be converted to arrow expressions if
|
|
||||||
the resultant code is shorter: `m(){return x}` becomes `m:()=>x`.
|
|
||||||
This transform requires that the `ecma` compress option is set to `6` or greater.
|
|
||||||
|
|
||||||
- `booleans` (default: `true`) -- various optimizations for boolean context,
|
- `booleans` (default: `true`) -- various optimizations for boolean context,
|
||||||
for example `!!a ? b : c → a ? b : c`
|
for example `!!a ? b : c → a ? b : c`
|
||||||
|
|
||||||
- `cascade` (default: `true`) -- small optimization for sequences, transform
|
|
||||||
`x, x` into `x` and `x = something(), x` into `x = something()`
|
|
||||||
|
|
||||||
- `collapse_vars` (default: `true`) -- Collapse single-use non-constant variables,
|
- `collapse_vars` (default: `true`) -- Collapse single-use non-constant variables,
|
||||||
side effects permitting.
|
side effects permitting.
|
||||||
|
|
||||||
@@ -640,9 +608,6 @@ If you're using the `X-SourceMap` header instead, you can just omit `sourceMap.u
|
|||||||
e.g. `!(a <= b) → a > b` (only when `unsafe_comps`), attempts to negate binary
|
e.g. `!(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.
|
||||||
|
|
||||||
- `computed_props` (default: `true`) -- Transforms constant computed properties
|
|
||||||
into regular ones: `{["computed"]: 1}` is converted to `{computed: 1}`.
|
|
||||||
|
|
||||||
- `conditionals` (default: `true`) -- apply optimizations for `if`-s and conditional
|
- `conditionals` (default: `true`) -- apply optimizations for `if`-s and conditional
|
||||||
expressions
|
expressions
|
||||||
|
|
||||||
@@ -655,9 +620,6 @@ If you're using the `X-SourceMap` header instead, you can just omit `sourceMap.u
|
|||||||
|
|
||||||
- `drop_debugger` (default: `true`) -- remove `debugger;` statements
|
- `drop_debugger` (default: `true`) -- remove `debugger;` statements
|
||||||
|
|
||||||
- `ecma` (default: `5`) -- Pass `6` or greater to enable `compress` options that
|
|
||||||
will transform ES5 code into smaller ES6+ equivalent forms.
|
|
||||||
|
|
||||||
- `evaluate` (default: `true`) -- attempt to evaluate constant expressions
|
- `evaluate` (default: `true`) -- attempt to evaluate constant expressions
|
||||||
|
|
||||||
- `expression` (default: `false`) -- Pass `true` to preserve completion values
|
- `expression` (default: `false`) -- Pass `true` to preserve completion values
|
||||||
@@ -665,7 +627,7 @@ If you're using the `X-SourceMap` header instead, you can just omit `sourceMap.u
|
|||||||
|
|
||||||
- `global_defs` (default: `{}`) -- see [conditional compilation](#conditional-compilation)
|
- `global_defs` (default: `{}`) -- see [conditional compilation](#conditional-compilation)
|
||||||
|
|
||||||
- `hoist_funs` (default: `true`) -- hoist function declarations
|
- `hoist_funs` (default: `false`) -- hoist function declarations
|
||||||
|
|
||||||
- `hoist_props` (default: `true`) -- hoist properties from constant object and
|
- `hoist_props` (default: `true`) -- hoist properties from constant object and
|
||||||
array literals into regular variables subject to a set of constraints. For example:
|
array literals into regular variables subject to a set of constraints. For example:
|
||||||
@@ -678,14 +640,16 @@ If you're using the `X-SourceMap` header instead, you can just omit `sourceMap.u
|
|||||||
|
|
||||||
- `if_return` (default: `true`) -- optimizations for if/return and if/continue
|
- `if_return` (default: `true`) -- optimizations for if/return and if/continue
|
||||||
|
|
||||||
- `inline` (default: `true`) -- embed simple functions
|
- `inline` (default: `true`) -- inline calls to function with simple/`return` statement:
|
||||||
|
- `false` -- same as `0`
|
||||||
|
- `0` -- disabled inlining
|
||||||
|
- `1` -- inline simple functions
|
||||||
|
- `2` -- inline functions with arguments
|
||||||
|
- `3` -- inline functions with arguments and variables
|
||||||
|
- `true` -- same as `3`
|
||||||
|
|
||||||
- `join_vars` (default: `true`) -- join consecutive `var` statements
|
- `join_vars` (default: `true`) -- join consecutive `var` statements
|
||||||
|
|
||||||
- `keep_classnames` (default: `false`) -- Pass `true` to prevent the
|
|
||||||
compressor from discarding class names. See also: the `keep_classnames`
|
|
||||||
[mangle option](#mangle).
|
|
||||||
|
|
||||||
- `keep_fargs` (default: `true`) -- Prevents the compressor from discarding unused
|
- `keep_fargs` (default: `true`) -- Prevents the compressor from discarding unused
|
||||||
function arguments. You need this for code which relies on `Function.length`.
|
function arguments. You need this for code which relies on `Function.length`.
|
||||||
|
|
||||||
@@ -766,12 +730,6 @@ If you're using the `X-SourceMap` header instead, you can just omit `sourceMap.u
|
|||||||
|
|
||||||
- `unsafe` (default: `false`) -- apply "unsafe" transformations (discussion below)
|
- `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
|
- `unsafe_comps` (default: `false`) -- Reverse `<` and `<=` to `>` and `>=` to
|
||||||
allow improved compression. This might be unsafe when an at least one of two
|
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`,
|
operands is an object with computed values due the use of methods like `get`,
|
||||||
@@ -779,25 +737,22 @@ If you're using the `X-SourceMap` header instead, you can just omit `sourceMap.u
|
|||||||
comparison are switching. Compression only works if both `comparisons` and
|
comparison are switching. Compression only works if both `comparisons` and
|
||||||
`unsafe_comps` are both set to true.
|
`unsafe_comps` are both set to true.
|
||||||
|
|
||||||
- `unsafe_Func` (default: `false`) -- compress and mangle `Function(args, code)`
|
- `unsafe_Function` (default: `false`) -- compress and mangle `Function(args, code)`
|
||||||
when both `args` and `code` are string literals.
|
when both `args` and `code` are string literals.
|
||||||
|
|
||||||
- `unsafe_math` (default: `false`) -- optimize numerical expressions like
|
- `unsafe_math` (default: `false`) -- optimize numerical expressions like
|
||||||
`2 * x * 3` into `6 * x`, which may give imprecise floating point results.
|
`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
|
- `unsafe_proto` (default: `false`) -- optimize expressions like
|
||||||
`Array.prototype.slice.call(a)` into `[].slice.call(a)`
|
`Array.prototype.slice.call(a)` into `[].slice.call(a)`
|
||||||
|
|
||||||
- `unsafe_regexp` (default: `false`) -- enable substitutions of variables with
|
- `unsafe_regexp` (default: `false`) -- enable substitutions of variables with
|
||||||
`RegExp` values the same way as if they are constants.
|
`RegExp` values the same way as if they are constants.
|
||||||
|
|
||||||
|
- `unsafe_undefined` (default: `false`) -- substitute `void 0` if there is a
|
||||||
|
variable named `undefined` in scope (variable name will be mangled, typically
|
||||||
|
reduced to a single character)
|
||||||
|
|
||||||
- `unused` (default: `true`) -- drop unreferenced functions and variables (simple
|
- `unused` (default: `true`) -- drop unreferenced functions and variables (simple
|
||||||
direct variable assignments do not count as references unless set to `"keep_assign"`)
|
direct variable assignments do not count as references unless set to `"keep_assign"`)
|
||||||
|
|
||||||
@@ -809,9 +764,6 @@ If you're using the `X-SourceMap` header instead, you can just omit `sourceMap.u
|
|||||||
- `eval` (default `false`) -- Pass `true` to mangle names visible in scopes
|
- `eval` (default `false`) -- Pass `true` to mangle names visible in scopes
|
||||||
where `eval` or `with` are used.
|
where `eval` or `with` are used.
|
||||||
|
|
||||||
- `keep_classnames` (default `false`) -- Pass `true` to not mangle class names.
|
|
||||||
See also: the `keep_classnames` [compress option](#compress-options).
|
|
||||||
|
|
||||||
- `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).
|
||||||
@@ -822,11 +774,6 @@ If you're using the `X-SourceMap` header instead, you can just omit `sourceMap.u
|
|||||||
- `toplevel` (default `false`) -- Pass `true` to mangle names declared in the
|
- `toplevel` (default `false`) -- Pass `true` to mangle names declared in the
|
||||||
top level scope.
|
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)
|
|
||||||
"Cannot declare a let variable twice".
|
|
||||||
See also: the `safari10` [output option](#output-options).
|
|
||||||
|
|
||||||
Examples:
|
Examples:
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
@@ -887,13 +834,6 @@ can pass additional arguments that control the code output:
|
|||||||
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
|
|
||||||
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
|
|
||||||
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
|
|
||||||
ES6+ code to ES5.
|
|
||||||
|
|
||||||
- `indent_level` (default `4`)
|
- `indent_level` (default `4`)
|
||||||
|
|
||||||
- `indent_start` (default `0`) -- prefix all lines by that many spaces
|
- `indent_start` (default `0`) -- prefix all lines by that many spaces
|
||||||
@@ -925,10 +865,6 @@ can pass additional arguments that control the code output:
|
|||||||
- `2` -- always use double quotes
|
- `2` -- always use double quotes
|
||||||
- `3` -- always use the original quotes
|
- `3` -- always use the original quotes
|
||||||
|
|
||||||
- `safari10` (default `false`) -- set this option to `true` to work around
|
|
||||||
the [Safari 10/11 await bug](https://bugs.webkit.org/show_bug.cgi?id=176685).
|
|
||||||
See also: the `safari10` [mangle option](#mangle-options).
|
|
||||||
|
|
||||||
- `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
|
||||||
@@ -990,9 +926,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`
|
||||||
- `void 0` → `undefined` (if there is a variable named "undefined" in
|
|
||||||
scope; we do it because the variable name will be mangled, typically
|
|
||||||
reduced to a single character)
|
|
||||||
|
|
||||||
### Conditional compilation
|
### Conditional compilation
|
||||||
|
|
||||||
@@ -1169,3 +1102,27 @@ To enable fast minify mode with the API use:
|
|||||||
```js
|
```js
|
||||||
UglifyJS.minify(code, { compress: false, mangle: true });
|
UglifyJS.minify(code, { compress: false, mangle: true });
|
||||||
```
|
```
|
||||||
|
|
||||||
|
#### Source maps and debugging
|
||||||
|
|
||||||
|
Various `compress` transforms that simplify, rearrange, inline and remove code
|
||||||
|
are known to have an adverse effect on debugging with source maps. This is
|
||||||
|
expected as code is optimized and mappings are often simply not possible as
|
||||||
|
some code no longer exists. For highest fidelity in source map debugging
|
||||||
|
disable the Uglify `compress` option and just use `mangle`.
|
||||||
|
|
||||||
|
### Compiler assumptions
|
||||||
|
|
||||||
|
To allow for better optimizations, the compiler makes various assumptions:
|
||||||
|
|
||||||
|
- `.toString()` and `.valueOf()` don't have side effects, and for built-in
|
||||||
|
objects they have not been overridden.
|
||||||
|
- `undefined`, `NaN` and `Infinity` have not been externally redefined.
|
||||||
|
- `arguments.callee`, `arguments.caller` and `Function.prototype.caller` are not used.
|
||||||
|
- The code doesn't expect the contents of `Function.prototype.toString()` or
|
||||||
|
`Error.prototype.stack` to be anything in particular.
|
||||||
|
- Getting and setting properties on a plain object does not cause other side effects
|
||||||
|
(using `.watch()` or `Proxy`).
|
||||||
|
- Object properties can be added, removed and modified (not prevented with
|
||||||
|
`Object.defineProperty()`, `Object.defineProperties()`, `Object.freeze()`,
|
||||||
|
`Object.preventExtensions()` or `Object.seal()`).
|
||||||
|
|||||||
28
appveyor.yml
28
appveyor.yml
@@ -1,24 +1,20 @@
|
|||||||
environment:
|
environment:
|
||||||
matrix:
|
matrix:
|
||||||
- nodejs_version: "0.10"
|
- nodejs_version: "0.10"
|
||||||
- nodejs_version: "0.12"
|
- nodejs_version: "0.12"
|
||||||
- nodejs_version: "4.0"
|
- nodejs_version: "4"
|
||||||
- nodejs_version: "6.0"
|
- nodejs_version: "6"
|
||||||
|
- nodejs_version: "8"
|
||||||
|
install:
|
||||||
|
- ps: Install-Product node $env:nodejs_version
|
||||||
|
- set UGLIFYJS_TEST_ALL=1
|
||||||
|
- npm install
|
||||||
|
build: off
|
||||||
|
cache:
|
||||||
|
- tmp
|
||||||
matrix:
|
matrix:
|
||||||
fast_finish: true
|
fast_finish: true
|
||||||
|
|
||||||
platform:
|
|
||||||
- x86
|
|
||||||
- x64
|
|
||||||
|
|
||||||
install:
|
|
||||||
- ps: Install-Product node $env:nodejs_version $env:platform
|
|
||||||
- npm install
|
|
||||||
|
|
||||||
test_script:
|
test_script:
|
||||||
- node --version
|
- node --version
|
||||||
- npm --version
|
- npm --version
|
||||||
- npm test
|
- npm test
|
||||||
|
|
||||||
build: off
|
|
||||||
|
|||||||
46
bin/uglifyjs
46
bin/uglifyjs
@@ -3,11 +3,7 @@
|
|||||||
|
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
// workaround for tty output truncation upon process.exit()
|
require("../tools/exit");
|
||||||
[process.stdout, process.stderr].forEach(function(stream){
|
|
||||||
if (stream._handle && stream._handle.setBlocking)
|
|
||||||
stream._handle.setBlocking(true);
|
|
||||||
});
|
|
||||||
|
|
||||||
var fs = require("fs");
|
var fs = require("fs");
|
||||||
var info = require("../package.json");
|
var info = require("../package.json");
|
||||||
@@ -15,7 +11,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", "inlined", "parent_scope", "scope", "thedef", "uses_eval", "uses_with" ];
|
var skip_keys = [ "cname", "inlined", "parent_scope", "scope", "uses_eval", "uses_with" ];
|
||||||
var files = {};
|
var files = {};
|
||||||
var options = {
|
var options = {
|
||||||
compress: false,
|
compress: false,
|
||||||
@@ -44,13 +40,11 @@ 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>", "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("--rename", "Force symbol expansion.");
|
||||||
program.option("--no-rename", "Disable symbol expansion.");
|
program.option("--no-rename", "Disable symbol expansion.");
|
||||||
program.option("--safari10", "Support non-standard Safari 10.");
|
|
||||||
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.")
|
||||||
@@ -69,21 +63,14 @@ if (!program.output && program.sourceMap && program.sourceMap.url != "inline") {
|
|||||||
"compress",
|
"compress",
|
||||||
"ie8",
|
"ie8",
|
||||||
"mangle",
|
"mangle",
|
||||||
"rename",
|
|
||||||
"safari10",
|
|
||||||
"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];
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
if ("ecma" in program) {
|
|
||||||
if (program.ecma != (program.ecma | 0)) fatal("ERROR: ecma must be an integer");
|
|
||||||
options.ecma = program.ecma | 0;
|
|
||||||
}
|
|
||||||
if (program.beautify) {
|
if (program.beautify) {
|
||||||
options.output = typeof program.beautify == "object" ? program.beautify : {};
|
options.output = typeof program.beautify == "object" ? program.beautify : {};
|
||||||
if (!("beautify" in options.output)) {
|
if (!("beautify" in options.output)) {
|
||||||
@@ -101,9 +88,6 @@ 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;
|
||||||
}
|
}
|
||||||
@@ -136,6 +120,11 @@ if (program.parse) {
|
|||||||
fatal("ERROR: inline source map only works with built-in parser");
|
fatal("ERROR: inline source map only works with built-in parser");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (~program.rawArgs.indexOf("--rename")) {
|
||||||
|
options.rename = true;
|
||||||
|
} else if (!program.rename) {
|
||||||
|
options.rename = false;
|
||||||
|
}
|
||||||
var convert_path = function(name) {
|
var convert_path = function(name) {
|
||||||
return name;
|
return name;
|
||||||
};
|
};
|
||||||
@@ -238,7 +227,20 @@ function run() {
|
|||||||
}
|
}
|
||||||
fatal(ex);
|
fatal(ex);
|
||||||
} else if (program.output == "ast") {
|
} else if (program.output == "ast") {
|
||||||
|
if (!options.compress && !options.mangle) {
|
||||||
|
result.ast.figure_out_scope({});
|
||||||
|
}
|
||||||
print(JSON.stringify(result.ast, function(key, value) {
|
print(JSON.stringify(result.ast, function(key, value) {
|
||||||
|
if (value) switch (key) {
|
||||||
|
case "thedef":
|
||||||
|
return symdef(value);
|
||||||
|
case "enclosed":
|
||||||
|
return value.length ? value.map(symdef) : undefined;
|
||||||
|
case "variables":
|
||||||
|
case "functions":
|
||||||
|
case "globals":
|
||||||
|
return value.size() ? value.map(symdef) : undefined;
|
||||||
|
}
|
||||||
if (skip_key(key)) return;
|
if (skip_key(key)) return;
|
||||||
if (value instanceof UglifyJS.AST_Token) return;
|
if (value instanceof UglifyJS.AST_Token) return;
|
||||||
if (value instanceof UglifyJS.Dictionary) return;
|
if (value instanceof UglifyJS.Dictionary) return;
|
||||||
@@ -392,6 +394,12 @@ function skip_key(key) {
|
|||||||
return skip_keys.indexOf(key) >= 0;
|
return skip_keys.indexOf(key) >= 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function symdef(def) {
|
||||||
|
var ret = (1e6 + def.id) + " " + def.name;
|
||||||
|
if (def.mangled_name) ret += " " + def.mangled_name;
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
function format_object(obj) {
|
function format_object(obj) {
|
||||||
var lines = [];
|
var lines = [];
|
||||||
var padding = "";
|
var padding = "";
|
||||||
|
|||||||
355
lib/ast.js
355
lib/ast.js
@@ -87,7 +87,7 @@ function DEFNODE(type, props, methods, base) {
|
|||||||
return ctor;
|
return ctor;
|
||||||
};
|
};
|
||||||
|
|
||||||
var AST_Token = DEFNODE("Token", "type value line col pos endline endcol endpos nlb comments_before file raw", {
|
var AST_Token = DEFNODE("Token", "type value line col pos endline endcol endpos nlb comments_before comments_after file raw", {
|
||||||
}, null);
|
}, null);
|
||||||
|
|
||||||
var AST_Node = DEFNODE("Node", "start end", {
|
var AST_Node = DEFNODE("Node", "start end", {
|
||||||
@@ -156,7 +156,7 @@ var AST_SimpleStatement = DEFNODE("SimpleStatement", "body", {
|
|||||||
|
|
||||||
function walk_body(node, visitor) {
|
function walk_body(node, visitor) {
|
||||||
var body = node.body;
|
var body = node.body;
|
||||||
if (body instanceof AST_Node) {
|
if (body instanceof AST_Statement) {
|
||||||
body._walk(visitor);
|
body._walk(visitor);
|
||||||
}
|
}
|
||||||
else for (var i = 0, len = body.length; i < len; i++) {
|
else for (var i = 0, len = body.length; i < len; i++) {
|
||||||
@@ -267,11 +267,10 @@ var AST_For = DEFNODE("For", "init condition step", {
|
|||||||
}
|
}
|
||||||
}, AST_IterationStatement);
|
}, AST_IterationStatement);
|
||||||
|
|
||||||
var AST_ForIn = DEFNODE("ForIn", "init name object", {
|
var AST_ForIn = DEFNODE("ForIn", "init object", {
|
||||||
$documentation: "A `for ... in` statement",
|
$documentation: "A `for ... in` statement",
|
||||||
$propdoc: {
|
$propdoc: {
|
||||||
init: "[AST_Node] the `for/in` initialization code",
|
init: "[AST_Node] the `for/in` initialization code",
|
||||||
name: "[AST_SymbolRef?] the loop variable, only if `init` is AST_Var",
|
|
||||||
object: "[AST_Node] the object that we're looping through"
|
object: "[AST_Node] the object that we're looping through"
|
||||||
},
|
},
|
||||||
_walk: function(visitor) {
|
_walk: function(visitor) {
|
||||||
@@ -283,10 +282,6 @@ var AST_ForIn = DEFNODE("ForIn", "init name object", {
|
|||||||
}
|
}
|
||||||
}, AST_IterationStatement);
|
}, AST_IterationStatement);
|
||||||
|
|
||||||
var AST_ForOf = DEFNODE("ForOf", null, {
|
|
||||||
$documentation: "A `for ... of` statement",
|
|
||||||
}, AST_ForIn);
|
|
||||||
|
|
||||||
var AST_With = DEFNODE("With", "expression", {
|
var AST_With = DEFNODE("With", "expression", {
|
||||||
$documentation: "A `with` statement",
|
$documentation: "A `with` statement",
|
||||||
$propdoc: {
|
$propdoc: {
|
||||||
@@ -313,12 +308,12 @@ var AST_Scope = DEFNODE("Scope", "variables functions uses_with uses_eval parent
|
|||||||
enclosed: "[SymbolDef*/S] a list of all symbol definitions that are accessed from this scope or any subscopes",
|
enclosed: "[SymbolDef*/S] a list of all symbol definitions that are accessed from this scope or any subscopes",
|
||||||
cname: "[integer/S] current index for mangling variables (used internally by the mangler)",
|
cname: "[integer/S] current index for mangling variables (used internally by the mangler)",
|
||||||
},
|
},
|
||||||
get_defun_scope: function() {
|
clone: function(deep) {
|
||||||
var self = this;
|
var node = this._clone(deep);
|
||||||
while (self.is_block_scope()) {
|
if (this.variables) node.variables = this.variables.clone();
|
||||||
self = self.parent_scope;
|
if (this.functions) node.functions = this.functions.clone();
|
||||||
}
|
if (this.enclosed) node.enclosed = this.enclosed.slice();
|
||||||
return self;
|
return node;
|
||||||
}
|
}
|
||||||
}, AST_Block);
|
}, AST_Block);
|
||||||
|
|
||||||
@@ -340,38 +335,12 @@ var AST_Toplevel = DEFNODE("Toplevel", "globals", {
|
|||||||
}
|
}
|
||||||
}, AST_Scope);
|
}, AST_Scope);
|
||||||
|
|
||||||
var AST_Expansion = DEFNODE("Expansion", "expression", {
|
var AST_Lambda = DEFNODE("Lambda", "name argnames uses_arguments", {
|
||||||
$documentation: "An expandible argument, such as ...rest, a splat, such as [1,2,...all], or an expansion in a variable declaration, such as var [first, ...rest] = list",
|
|
||||||
$propdoc: {
|
|
||||||
expression: "[AST_Node] the thing to be expanded"
|
|
||||||
},
|
|
||||||
_walk: function(visitor) {
|
|
||||||
var self = this;
|
|
||||||
return visitor._visit(this, function(){
|
|
||||||
self.expression.walk(visitor);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
var AST_Lambda = DEFNODE("Lambda", "name argnames uses_arguments is_generator async", {
|
|
||||||
$documentation: "Base class for functions",
|
$documentation: "Base class for functions",
|
||||||
$propdoc: {
|
$propdoc: {
|
||||||
name: "[AST_SymbolDeclaration?] the name of this function",
|
name: "[AST_SymbolDeclaration?] the name of this function",
|
||||||
argnames: "[AST_SymbolFunarg|AST_Destructuring|AST_Expansion|AST_DefaultAssign*] array of function arguments, destructurings, or expanding arguments",
|
argnames: "[AST_SymbolFunarg*] array of function arguments",
|
||||||
uses_arguments: "[boolean/S] tells whether this function accesses the arguments array",
|
uses_arguments: "[boolean/S] tells whether this function accesses the arguments array"
|
||||||
is_generator: "[boolean] is this a generator method",
|
|
||||||
async: "[boolean] is this method async",
|
|
||||||
},
|
|
||||||
args_as_names: function () {
|
|
||||||
var out = [];
|
|
||||||
for (var i = 0; i < this.argnames.length; i++) {
|
|
||||||
if (this.argnames[i] instanceof AST_Destructuring) {
|
|
||||||
out = out.concat(this.argnames[i].all_symbols());
|
|
||||||
} else {
|
|
||||||
out.push(this.argnames[i]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return out;
|
|
||||||
},
|
},
|
||||||
_walk: function(visitor) {
|
_walk: function(visitor) {
|
||||||
return visitor._visit(this, function(){
|
return visitor._visit(this, function(){
|
||||||
@@ -393,76 +362,10 @@ var AST_Function = DEFNODE("Function", "inlined", {
|
|||||||
$documentation: "A function expression"
|
$documentation: "A function expression"
|
||||||
}, AST_Lambda);
|
}, AST_Lambda);
|
||||||
|
|
||||||
var AST_Arrow = DEFNODE("Arrow", "inlined", {
|
|
||||||
$documentation: "An ES6 Arrow function ((a) => b)"
|
|
||||||
}, AST_Lambda);
|
|
||||||
|
|
||||||
var AST_Defun = DEFNODE("Defun", "inlined", {
|
var AST_Defun = DEFNODE("Defun", "inlined", {
|
||||||
$documentation: "A function definition"
|
$documentation: "A function definition"
|
||||||
}, AST_Lambda);
|
}, AST_Lambda);
|
||||||
|
|
||||||
/* -----[ DESTRUCTURING ]----- */
|
|
||||||
var AST_Destructuring = DEFNODE("Destructuring", "names is_array", {
|
|
||||||
$documentation: "A destructuring of several names. Used in destructuring assignment and with destructuring function argument names",
|
|
||||||
$propdoc: {
|
|
||||||
"names": "[AST_Node*] Array of properties or elements",
|
|
||||||
"is_array": "[Boolean] Whether the destructuring represents an object or array"
|
|
||||||
},
|
|
||||||
_walk: function(visitor) {
|
|
||||||
return visitor._visit(this, function(){
|
|
||||||
this.names.forEach(function(name){
|
|
||||||
name._walk(visitor);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
},
|
|
||||||
all_symbols: function() {
|
|
||||||
var out = [];
|
|
||||||
this.walk(new TreeWalker(function (node) {
|
|
||||||
if (node instanceof AST_Symbol) {
|
|
||||||
out.push(node);
|
|
||||||
}
|
|
||||||
if (node instanceof AST_Expansion) {
|
|
||||||
out.push(node.expression);
|
|
||||||
}
|
|
||||||
}));
|
|
||||||
return out;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
var AST_PrefixedTemplateString = DEFNODE("PrefixedTemplateString", "template_string prefix", {
|
|
||||||
$documentation: "A templatestring with a prefix, such as String.raw`foobarbaz`",
|
|
||||||
$propdoc: {
|
|
||||||
template_string: "[AST_TemplateString] The template string",
|
|
||||||
prefix: "[AST_SymbolRef|AST_PropAccess] The prefix, which can be a symbol such as `foo` or a dotted expression such as `String.raw`."
|
|
||||||
},
|
|
||||||
_walk: function(visitor) {
|
|
||||||
this.prefix._walk(visitor);
|
|
||||||
this.template_string._walk(visitor);
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
var AST_TemplateString = DEFNODE("TemplateString", "segments", {
|
|
||||||
$documentation: "A template string literal",
|
|
||||||
$propdoc: {
|
|
||||||
segments: "[AST_Node*] One or more segments, starting with AST_TemplateSegment. AST_Node may follow AST_TemplateSegment, but each AST_Node must be followed by AST_TemplateSegment."
|
|
||||||
},
|
|
||||||
_walk: function(visitor) {
|
|
||||||
return visitor._visit(this, function(){
|
|
||||||
this.segments.forEach(function(seg){
|
|
||||||
seg._walk(visitor);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
var AST_TemplateSegment = DEFNODE("TemplateSegment", "value raw", {
|
|
||||||
$documentation: "A segment of a template string literal",
|
|
||||||
$propdoc: {
|
|
||||||
value: "Content of the segment",
|
|
||||||
raw: "Raw content of the segment"
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
/* -----[ JUMPS ]----- */
|
/* -----[ JUMPS ]----- */
|
||||||
|
|
||||||
var AST_Jump = DEFNODE("Jump", null, {
|
var AST_Jump = DEFNODE("Jump", null, {
|
||||||
@@ -582,7 +485,7 @@ var AST_Try = DEFNODE("Try", "bcatch bfinally", {
|
|||||||
var AST_Catch = DEFNODE("Catch", "argname", {
|
var AST_Catch = DEFNODE("Catch", "argname", {
|
||||||
$documentation: "A `catch` node; only makes sense as part of a `try` statement",
|
$documentation: "A `catch` node; only makes sense as part of a `try` statement",
|
||||||
$propdoc: {
|
$propdoc: {
|
||||||
argname: "[AST_SymbolCatch|AST_Destructuring|AST_Expansion|AST_DefaultAssign] symbol for the exception"
|
argname: "[AST_SymbolCatch] symbol for the exception"
|
||||||
},
|
},
|
||||||
_walk: function(visitor) {
|
_walk: function(visitor) {
|
||||||
return visitor._visit(this, function(){
|
return visitor._visit(this, function(){
|
||||||
@@ -596,10 +499,10 @@ var AST_Finally = DEFNODE("Finally", null, {
|
|||||||
$documentation: "A `finally` node; only makes sense as part of a `try` statement"
|
$documentation: "A `finally` node; only makes sense as part of a `try` statement"
|
||||||
}, AST_Block);
|
}, AST_Block);
|
||||||
|
|
||||||
/* -----[ VAR/CONST ]----- */
|
/* -----[ VAR ]----- */
|
||||||
|
|
||||||
var AST_Definitions = DEFNODE("Definitions", "definitions", {
|
var AST_Definitions = DEFNODE("Definitions", "definitions", {
|
||||||
$documentation: "Base class for `var` or `const` nodes (variable declarations/initializations)",
|
$documentation: "Base class for `var` nodes (variable declarations/initializations)",
|
||||||
$propdoc: {
|
$propdoc: {
|
||||||
definitions: "[AST_VarDef*] array of variable definitions"
|
definitions: "[AST_VarDef*] array of variable definitions"
|
||||||
},
|
},
|
||||||
@@ -617,83 +520,10 @@ var AST_Var = DEFNODE("Var", null, {
|
|||||||
$documentation: "A `var` statement"
|
$documentation: "A `var` statement"
|
||||||
}, AST_Definitions);
|
}, AST_Definitions);
|
||||||
|
|
||||||
var AST_Let = DEFNODE("Let", null, {
|
|
||||||
$documentation: "A `let` statement"
|
|
||||||
}, AST_Definitions);
|
|
||||||
|
|
||||||
var AST_Const = DEFNODE("Const", null, {
|
|
||||||
$documentation: "A `const` statement"
|
|
||||||
}, AST_Definitions);
|
|
||||||
|
|
||||||
var AST_NameMapping = DEFNODE("NameMapping", "foreign_name name", {
|
|
||||||
$documentation: "The part of the export/import statement that declare names from a module.",
|
|
||||||
$propdoc: {
|
|
||||||
foreign_name: "[AST_SymbolExportForeign|AST_SymbolImportForeign] The name being exported/imported (as specified in the module)",
|
|
||||||
name: "[AST_SymbolExport|AST_SymbolImport] The name as it is visible to this module."
|
|
||||||
},
|
|
||||||
_walk: function (visitor) {
|
|
||||||
return visitor._visit(this, function() {
|
|
||||||
this.foreign_name._walk(visitor);
|
|
||||||
this.name._walk(visitor);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
var AST_Import = DEFNODE("Import", "imported_name imported_names module_name", {
|
|
||||||
$documentation: "An `import` statement",
|
|
||||||
$propdoc: {
|
|
||||||
imported_name: "[AST_SymbolImport] The name of the variable holding the module's default export.",
|
|
||||||
imported_names: "[AST_NameMapping*] The names of non-default imported variables",
|
|
||||||
module_name: "[AST_String] String literal describing where this module came from",
|
|
||||||
},
|
|
||||||
_walk: function(visitor) {
|
|
||||||
return visitor._visit(this, function() {
|
|
||||||
if (this.imported_name) {
|
|
||||||
this.imported_name._walk(visitor);
|
|
||||||
}
|
|
||||||
if (this.imported_names) {
|
|
||||||
this.imported_names.forEach(function(name_import) {
|
|
||||||
name_import._walk(visitor);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
this.module_name._walk(visitor);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
var AST_Export = DEFNODE("Export", "exported_definition exported_value is_default exported_names module_name", {
|
|
||||||
$documentation: "An `export` statement",
|
|
||||||
$propdoc: {
|
|
||||||
exported_definition: "[AST_Defun|AST_Definitions|AST_DefClass?] An exported definition",
|
|
||||||
exported_value: "[AST_Node?] An exported value",
|
|
||||||
exported_names: "[AST_NameMapping*?] List of exported names",
|
|
||||||
module_name: "[AST_String?] Name of the file to load exports from",
|
|
||||||
is_default: "[Boolean] Whether this is the default exported value of this module"
|
|
||||||
},
|
|
||||||
_walk: function (visitor) {
|
|
||||||
visitor._visit(this, function () {
|
|
||||||
if (this.exported_definition) {
|
|
||||||
this.exported_definition._walk(visitor);
|
|
||||||
}
|
|
||||||
if (this.exported_value) {
|
|
||||||
this.exported_value._walk(visitor);
|
|
||||||
}
|
|
||||||
if (this.exported_names) {
|
|
||||||
this.exported_names.forEach(function(name_export) {
|
|
||||||
name_export._walk(visitor);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
if (this.module_name) {
|
|
||||||
this.module_name._walk(visitor);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}, AST_Statement);
|
|
||||||
|
|
||||||
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_Destructuring|AST_SymbolConst|AST_SymbolLet|AST_SymbolVar] name of the variable",
|
name: "[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) {
|
||||||
@@ -824,10 +654,6 @@ var AST_Assign = DEFNODE("Assign", null, {
|
|||||||
$documentation: "An assignment expression — `a = b + 5`",
|
$documentation: "An assignment expression — `a = b + 5`",
|
||||||
}, AST_Binary);
|
}, AST_Binary);
|
||||||
|
|
||||||
var AST_DefaultAssign = DEFNODE("DefaultAssign", null, {
|
|
||||||
$documentation: "A default assignment expression like in `(a = 3) => a`"
|
|
||||||
}, AST_Binary);
|
|
||||||
|
|
||||||
/* -----[ LITERALS ]----- */
|
/* -----[ LITERALS ]----- */
|
||||||
|
|
||||||
var AST_Array = DEFNODE("Array", "elements", {
|
var AST_Array = DEFNODE("Array", "elements", {
|
||||||
@@ -863,13 +689,11 @@ var AST_Object = DEFNODE("Object", "properties", {
|
|||||||
var AST_ObjectProperty = DEFNODE("ObjectProperty", "key value", {
|
var AST_ObjectProperty = DEFNODE("ObjectProperty", "key value", {
|
||||||
$documentation: "Base class for literal object properties",
|
$documentation: "Base class for literal object properties",
|
||||||
$propdoc: {
|
$propdoc: {
|
||||||
key: "[string|AST_Node] the property name converted to a string for ObjectKeyVal. For setters, getters and computed property this is an arbitrary AST_Node",
|
key: "[string|AST_SymbolAccessor] property name. For ObjectKeyVal this is a string. For getters and setters this is an AST_SymbolAccessor.",
|
||||||
value: "[AST_Node] property value. For setters and getters this is an AST_Accessor."
|
value: "[AST_Node] property value. For getters and setters this is an AST_Accessor."
|
||||||
},
|
},
|
||||||
_walk: function(visitor) {
|
_walk: function(visitor) {
|
||||||
return visitor._visit(this, function(){
|
return visitor._visit(this, function(){
|
||||||
if (this.key instanceof AST_Node)
|
|
||||||
this.key._walk(visitor);
|
|
||||||
this.value._walk(visitor);
|
this.value._walk(visitor);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -882,95 +706,35 @@ var AST_ObjectKeyVal = DEFNODE("ObjectKeyVal", "quote", {
|
|||||||
}
|
}
|
||||||
}, AST_ObjectProperty);
|
}, AST_ObjectProperty);
|
||||||
|
|
||||||
var AST_ObjectSetter = DEFNODE("ObjectSetter", "quote static", {
|
var AST_ObjectSetter = DEFNODE("ObjectSetter", null, {
|
||||||
$propdoc: {
|
|
||||||
quote: "[string|undefined] the original quote character, if any",
|
|
||||||
static: "[boolean] whether this is a static setter (classes only)"
|
|
||||||
},
|
|
||||||
$documentation: "An object setter property",
|
$documentation: "An object setter property",
|
||||||
}, AST_ObjectProperty);
|
}, AST_ObjectProperty);
|
||||||
|
|
||||||
var AST_ObjectGetter = DEFNODE("ObjectGetter", "quote static", {
|
var AST_ObjectGetter = DEFNODE("ObjectGetter", null, {
|
||||||
$propdoc: {
|
|
||||||
quote: "[string|undefined] the original quote character, if any",
|
|
||||||
static: "[boolean] whether this is a static getter (classes only)"
|
|
||||||
},
|
|
||||||
$documentation: "An object getter property",
|
$documentation: "An object getter property",
|
||||||
}, AST_ObjectProperty);
|
}, AST_ObjectProperty);
|
||||||
|
|
||||||
var AST_ConciseMethod = DEFNODE("ConciseMethod", "quote static is_generator async", {
|
|
||||||
$propdoc: {
|
|
||||||
quote: "[string|undefined] the original quote character, if any",
|
|
||||||
static: "[boolean] is this method static (classes only)",
|
|
||||||
is_generator: "[boolean] is this a generator method",
|
|
||||||
async: "[boolean] is this method async",
|
|
||||||
},
|
|
||||||
$documentation: "An ES6 concise method inside an object or class"
|
|
||||||
}, AST_ObjectProperty);
|
|
||||||
|
|
||||||
var AST_Class = DEFNODE("Class", "name extends properties inlined", {
|
|
||||||
$propdoc: {
|
|
||||||
name: "[AST_SymbolClass|AST_SymbolDefClass?] optional class name.",
|
|
||||||
extends: "[AST_Node]? optional parent class",
|
|
||||||
properties: "[AST_ObjectProperty*] array of properties"
|
|
||||||
},
|
|
||||||
$documentation: "An ES6 class",
|
|
||||||
_walk: function(visitor) {
|
|
||||||
return visitor._visit(this, function(){
|
|
||||||
if (this.name) {
|
|
||||||
this.name._walk(visitor);
|
|
||||||
}
|
|
||||||
if (this.extends) {
|
|
||||||
this.extends._walk(visitor);
|
|
||||||
}
|
|
||||||
this.properties.forEach(function(prop){
|
|
||||||
prop._walk(visitor);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
},
|
|
||||||
}, AST_Scope);
|
|
||||||
|
|
||||||
var AST_DefClass = DEFNODE("DefClass", null, {
|
|
||||||
$documentation: "A class definition",
|
|
||||||
}, AST_Class);
|
|
||||||
|
|
||||||
var AST_ClassExpression = DEFNODE("ClassExpression", null, {
|
|
||||||
$documentation: "A class expression."
|
|
||||||
}, AST_Class);
|
|
||||||
|
|
||||||
var AST_Symbol = DEFNODE("Symbol", "scope name thedef", {
|
var AST_Symbol = DEFNODE("Symbol", "scope name thedef", {
|
||||||
$propdoc: {
|
$propdoc: {
|
||||||
name: "[string] name of this symbol",
|
name: "[string] name of this symbol",
|
||||||
scope: "[AST_Scope/S] the current scope (not necessarily the definition scope)",
|
scope: "[AST_Scope/S] the current scope (not necessarily the definition scope)",
|
||||||
thedef: "[SymbolDef/S] the definition of this symbol"
|
thedef: "[SymbolDef/S] the definition of this symbol"
|
||||||
},
|
},
|
||||||
$documentation: "Base class for all symbols"
|
$documentation: "Base class for all symbols",
|
||||||
});
|
});
|
||||||
|
|
||||||
var AST_NewTarget = DEFNODE("NewTarget", null, {
|
var AST_SymbolAccessor = DEFNODE("SymbolAccessor", null, {
|
||||||
$documentation: "A reference to new.target"
|
$documentation: "The name of a property accessor (setter/getter function)"
|
||||||
});
|
}, AST_Symbol);
|
||||||
|
|
||||||
var AST_SymbolDeclaration = DEFNODE("SymbolDeclaration", "init", {
|
var AST_SymbolDeclaration = DEFNODE("SymbolDeclaration", "init", {
|
||||||
$documentation: "A declaration symbol (symbol in var/const, function name or argument, symbol in catch)",
|
$documentation: "A declaration symbol (symbol in var, function name or argument, symbol in catch)",
|
||||||
}, AST_Symbol);
|
}, AST_Symbol);
|
||||||
|
|
||||||
var AST_SymbolVar = DEFNODE("SymbolVar", null, {
|
var AST_SymbolVar = DEFNODE("SymbolVar", null, {
|
||||||
$documentation: "Symbol defining a variable",
|
$documentation: "Symbol defining a variable",
|
||||||
}, AST_SymbolDeclaration);
|
}, AST_SymbolDeclaration);
|
||||||
|
|
||||||
var AST_SymbolBlockDeclaration = DEFNODE("SymbolBlockDeclaration", null, {
|
|
||||||
$documentation: "Base class for block-scoped declaration symbols"
|
|
||||||
}, AST_SymbolDeclaration);
|
|
||||||
|
|
||||||
var AST_SymbolConst = DEFNODE("SymbolConst", null, {
|
|
||||||
$documentation: "A constant declaration"
|
|
||||||
}, AST_SymbolBlockDeclaration);
|
|
||||||
|
|
||||||
var AST_SymbolLet = DEFNODE("SymbolLet", null, {
|
|
||||||
$documentation: "A block-scoped `let` declaration"
|
|
||||||
}, AST_SymbolBlockDeclaration);
|
|
||||||
|
|
||||||
var AST_SymbolFunarg = DEFNODE("SymbolFunarg", null, {
|
var AST_SymbolFunarg = DEFNODE("SymbolFunarg", null, {
|
||||||
$documentation: "Symbol naming a function argument",
|
$documentation: "Symbol naming a function argument",
|
||||||
}, AST_SymbolVar);
|
}, AST_SymbolVar);
|
||||||
@@ -979,33 +743,13 @@ var AST_SymbolDefun = DEFNODE("SymbolDefun", null, {
|
|||||||
$documentation: "Symbol defining a function",
|
$documentation: "Symbol defining a function",
|
||||||
}, AST_SymbolDeclaration);
|
}, AST_SymbolDeclaration);
|
||||||
|
|
||||||
var AST_SymbolMethod = DEFNODE("SymbolMethod", null, {
|
|
||||||
$documentation: "Symbol in an object defining a method",
|
|
||||||
}, AST_Symbol);
|
|
||||||
|
|
||||||
var AST_SymbolLambda = DEFNODE("SymbolLambda", null, {
|
var AST_SymbolLambda = DEFNODE("SymbolLambda", null, {
|
||||||
$documentation: "Symbol naming a function expression",
|
$documentation: "Symbol naming a function expression",
|
||||||
}, AST_SymbolDeclaration);
|
}, AST_SymbolDeclaration);
|
||||||
|
|
||||||
var AST_SymbolDefClass = DEFNODE("SymbolDefClass", null, {
|
|
||||||
$documentation: "Symbol naming a class's name in a class declaration. Lexically scoped to its containing scope, and accessible within the class."
|
|
||||||
}, AST_SymbolBlockDeclaration);
|
|
||||||
|
|
||||||
var AST_SymbolClass = DEFNODE("SymbolClass", null, {
|
|
||||||
$documentation: "Symbol naming a class's name. Lexically scoped to the class."
|
|
||||||
}, AST_SymbolDeclaration);
|
|
||||||
|
|
||||||
var AST_SymbolCatch = DEFNODE("SymbolCatch", null, {
|
var AST_SymbolCatch = DEFNODE("SymbolCatch", null, {
|
||||||
$documentation: "Symbol naming the exception in catch",
|
$documentation: "Symbol naming the exception in catch",
|
||||||
}, AST_SymbolBlockDeclaration);
|
}, AST_SymbolDeclaration);
|
||||||
|
|
||||||
var AST_SymbolImport = DEFNODE("SymbolImport", null, {
|
|
||||||
$documentation: "Symbol referring to an imported name",
|
|
||||||
}, AST_SymbolBlockDeclaration);
|
|
||||||
|
|
||||||
var AST_SymbolImportForeign = DEFNODE("SymbolImportForeign", null, {
|
|
||||||
$documentation: "A symbol imported from a module, but it is defined in the other module, and its real name is irrelevant for this module's purposes",
|
|
||||||
}, AST_Symbol);
|
|
||||||
|
|
||||||
var AST_Label = DEFNODE("Label", "references", {
|
var AST_Label = DEFNODE("Label", "references", {
|
||||||
$documentation: "Symbol naming a label (declaration)",
|
$documentation: "Symbol naming a label (declaration)",
|
||||||
@@ -1022,14 +766,6 @@ var AST_SymbolRef = DEFNODE("SymbolRef", null, {
|
|||||||
$documentation: "Reference to some symbol (not definition/declaration)",
|
$documentation: "Reference to some symbol (not definition/declaration)",
|
||||||
}, AST_Symbol);
|
}, AST_Symbol);
|
||||||
|
|
||||||
var AST_SymbolExport = DEFNODE("SymbolExport", null, {
|
|
||||||
$documentation: "Symbol referring to a name to export",
|
|
||||||
}, AST_SymbolRef);
|
|
||||||
|
|
||||||
var AST_SymbolExportForeign = DEFNODE("SymbolExportForeign", null, {
|
|
||||||
$documentation: "A symbol exported from this module, but it is used in the other module, and its real name is irrelevant for this module's purposes",
|
|
||||||
}, AST_Symbol);
|
|
||||||
|
|
||||||
var AST_LabelRef = DEFNODE("LabelRef", null, {
|
var AST_LabelRef = DEFNODE("LabelRef", null, {
|
||||||
$documentation: "Reference to a label symbol",
|
$documentation: "Reference to a label symbol",
|
||||||
}, AST_Symbol);
|
}, AST_Symbol);
|
||||||
@@ -1038,10 +774,6 @@ var AST_This = DEFNODE("This", null, {
|
|||||||
$documentation: "The `this` symbol",
|
$documentation: "The `this` symbol",
|
||||||
}, AST_Symbol);
|
}, AST_Symbol);
|
||||||
|
|
||||||
var AST_Super = DEFNODE("Super", null, {
|
|
||||||
$documentation: "The `super` 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",
|
||||||
getValue: function() {
|
getValue: function() {
|
||||||
@@ -1115,31 +847,6 @@ var AST_True = DEFNODE("True", null, {
|
|||||||
value: true
|
value: true
|
||||||
}, AST_Boolean);
|
}, AST_Boolean);
|
||||||
|
|
||||||
var AST_Await = DEFNODE("Await", "expression", {
|
|
||||||
$documentation: "An `await` statement",
|
|
||||||
$propdoc: {
|
|
||||||
expression: "[AST_Node] the mandatory expression being awaited",
|
|
||||||
},
|
|
||||||
_walk: function(visitor) {
|
|
||||||
return visitor._visit(this, function(){
|
|
||||||
this.expression._walk(visitor);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
var AST_Yield = DEFNODE("Yield", "expression is_star", {
|
|
||||||
$documentation: "A `yield` statement",
|
|
||||||
$propdoc: {
|
|
||||||
expression: "[AST_Node?] the value returned or thrown by this statement; could be null (representing undefined) but only when is_star is set to false",
|
|
||||||
is_star: "[Boolean] Whether this is a yield or yield* statement"
|
|
||||||
},
|
|
||||||
_walk: function(visitor) {
|
|
||||||
return visitor._visit(this, this.expression && function(){
|
|
||||||
this.expression._walk(visitor);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
/* -----[ TreeWalker ]----- */
|
/* -----[ TreeWalker ]----- */
|
||||||
|
|
||||||
function TreeWalker(callback) {
|
function TreeWalker(callback) {
|
||||||
@@ -1167,17 +874,11 @@ TreeWalker.prototype = {
|
|||||||
this.directives = Object.create(this.directives);
|
this.directives = Object.create(this.directives);
|
||||||
} else if (node instanceof AST_Directive && !this.directives[node.value]) {
|
} else if (node instanceof AST_Directive && !this.directives[node.value]) {
|
||||||
this.directives[node.value] = node;
|
this.directives[node.value] = node;
|
||||||
} else if (node instanceof AST_Class) {
|
|
||||||
this.directives = Object.create(this.directives);
|
|
||||||
if (!this.directives["use strict"]) {
|
|
||||||
this.directives["use strict"] = node;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
this.stack.push(node);
|
this.stack.push(node);
|
||||||
},
|
},
|
||||||
pop: function() {
|
pop: function() {
|
||||||
var node = this.stack.pop();
|
if (this.stack.pop() instanceof AST_Lambda) {
|
||||||
if (node instanceof AST_Lambda || node instanceof AST_Class) {
|
|
||||||
this.directives = Object.getPrototypeOf(this.directives);
|
this.directives = Object.getPrototypeOf(this.directives);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@@ -1195,7 +896,7 @@ TreeWalker.prototype = {
|
|||||||
var dir = this.directives[type];
|
var dir = this.directives[type];
|
||||||
if (dir) return dir;
|
if (dir) return dir;
|
||||||
var node = this.stack[this.stack.length - 1];
|
var node = this.stack[this.stack.length - 1];
|
||||||
if (node instanceof AST_Scope && node.body) {
|
if (node instanceof AST_Scope) {
|
||||||
for (var i = 0; i < node.body.length; ++i) {
|
for (var i = 0; i < node.body.length; ++i) {
|
||||||
var st = node.body[i];
|
var st = node.body[i];
|
||||||
if (!(st instanceof AST_Directive)) break;
|
if (!(st instanceof AST_Directive)) break;
|
||||||
|
|||||||
3076
lib/compress.js
3076
lib/compress.js
File diff suppressed because it is too large
Load Diff
@@ -29,7 +29,6 @@ function set_shorthand(name, options, keys) {
|
|||||||
|
|
||||||
function init_cache(cache) {
|
function init_cache(cache) {
|
||||||
if (!cache) return;
|
if (!cache) return;
|
||||||
if (!("cname" in cache)) cache.cname = -1;
|
|
||||||
if (!("props" in cache)) {
|
if (!("props" in cache)) {
|
||||||
cache.props = new Dictionary();
|
cache.props = new Dictionary();
|
||||||
} else if (!(cache.props instanceof Dictionary)) {
|
} else if (!(cache.props instanceof Dictionary)) {
|
||||||
@@ -39,7 +38,6 @@ function init_cache(cache) {
|
|||||||
|
|
||||||
function to_json(cache) {
|
function to_json(cache) {
|
||||||
return {
|
return {
|
||||||
cname: cache.cname,
|
|
||||||
props: cache.props.toObject()
|
props: cache.props.toObject()
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@@ -49,16 +47,13 @@ function minify(files, options) {
|
|||||||
try {
|
try {
|
||||||
options = defaults(options, {
|
options = defaults(options, {
|
||||||
compress: {},
|
compress: {},
|
||||||
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,
|
rename: undefined,
|
||||||
safari10: false,
|
|
||||||
sourceMap: false,
|
sourceMap: false,
|
||||||
timings: false,
|
timings: false,
|
||||||
toplevel: false,
|
toplevel: false,
|
||||||
@@ -68,17 +63,11 @@ 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) {
|
if (options.rename === undefined) {
|
||||||
options.rename = options.compress && options.mangle;
|
options.rename = options.compress && options.mangle;
|
||||||
}
|
}
|
||||||
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("safari10", options, [ "mangle", "output" ]);
|
|
||||||
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;
|
var quoted_props;
|
||||||
@@ -87,11 +76,9 @@ function minify(files, options) {
|
|||||||
cache: options.nameCache && (options.nameCache.vars || {}),
|
cache: options.nameCache && (options.nameCache.vars || {}),
|
||||||
eval: false,
|
eval: false,
|
||||||
ie8: false,
|
ie8: false,
|
||||||
keep_classnames: false,
|
|
||||||
keep_fnames: false,
|
keep_fnames: false,
|
||||||
properties: false,
|
properties: false,
|
||||||
reserved: [],
|
reserved: [],
|
||||||
safari10: false,
|
|
||||||
toplevel: false,
|
toplevel: false,
|
||||||
}, true);
|
}, true);
|
||||||
if (options.mangle.properties) {
|
if (options.mangle.properties) {
|
||||||
|
|||||||
@@ -118,7 +118,7 @@
|
|||||||
value : from_moz(M.value)
|
value : from_moz(M.value)
|
||||||
};
|
};
|
||||||
if (M.kind == "init") return new AST_ObjectKeyVal(args);
|
if (M.kind == "init") return new AST_ObjectKeyVal(args);
|
||||||
args.key = new AST_SymbolMethod({
|
args.key = new AST_SymbolAccessor({
|
||||||
name: args.key
|
name: args.key
|
||||||
});
|
});
|
||||||
args.value = new AST_Accessor(args.value);
|
args.value = new AST_Accessor(args.value);
|
||||||
@@ -168,7 +168,7 @@
|
|||||||
});
|
});
|
||||||
},
|
},
|
||||||
VariableDeclaration: function(M) {
|
VariableDeclaration: function(M) {
|
||||||
return new (M.kind === "const" ? AST_Const : AST_Var)({
|
return new AST_Var({
|
||||||
start : my_start_token(M),
|
start : my_start_token(M),
|
||||||
end : my_end_token(M),
|
end : my_end_token(M),
|
||||||
definitions : M.declarations.map(from_moz)
|
definitions : M.declarations.map(from_moz)
|
||||||
@@ -204,7 +204,7 @@
|
|||||||
Identifier: function(M) {
|
Identifier: function(M) {
|
||||||
var p = FROM_MOZ_STACK[FROM_MOZ_STACK.length - 2];
|
var p = FROM_MOZ_STACK[FROM_MOZ_STACK.length - 2];
|
||||||
return new ( p.type == "LabeledStatement" ? AST_Label
|
return new ( p.type == "LabeledStatement" ? AST_Label
|
||||||
: p.type == "VariableDeclarator" && p.id === M ? (p.kind == "const" ? AST_SymbolConst : AST_SymbolVar)
|
: p.type == "VariableDeclarator" && p.id === M ? AST_SymbolVar
|
||||||
: p.type == "FunctionExpression" ? (p.id === M ? AST_SymbolLambda : AST_SymbolFunarg)
|
: p.type == "FunctionExpression" ? (p.id === M ? AST_SymbolLambda : AST_SymbolFunarg)
|
||||||
: p.type == "FunctionDeclaration" ? (p.id === M ? AST_SymbolDefun : AST_SymbolFunarg)
|
: p.type == "FunctionDeclaration" ? (p.id === M ? AST_SymbolDefun : AST_SymbolFunarg)
|
||||||
: p.type == "CatchClause" ? AST_SymbolCatch
|
: p.type == "CatchClause" ? AST_SymbolCatch
|
||||||
@@ -324,7 +324,7 @@
|
|||||||
def_to_moz(AST_Definitions, function To_Moz_VariableDeclaration(M) {
|
def_to_moz(AST_Definitions, function To_Moz_VariableDeclaration(M) {
|
||||||
return {
|
return {
|
||||||
type: "VariableDeclaration",
|
type: "VariableDeclaration",
|
||||||
kind: M instanceof AST_Const ? "const" : "var",
|
kind: "var",
|
||||||
declarations: M.definitions.map(to_moz)
|
declarations: M.definitions.map(to_moz)
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
@@ -381,7 +381,7 @@
|
|||||||
def_to_moz(AST_ObjectProperty, function To_Moz_Property(M) {
|
def_to_moz(AST_ObjectProperty, function To_Moz_Property(M) {
|
||||||
var key = {
|
var key = {
|
||||||
type: "Literal",
|
type: "Literal",
|
||||||
value: M.key instanceof AST_SymbolMethod ? M.key.name : M.key
|
value: M.key instanceof AST_SymbolAccessor ? M.key.name : M.key
|
||||||
};
|
};
|
||||||
var kind;
|
var kind;
|
||||||
if (M instanceof AST_ObjectKeyVal) {
|
if (M instanceof AST_ObjectKeyVal) {
|
||||||
|
|||||||
716
lib/output.js
716
lib/output.js
@@ -52,12 +52,12 @@ function is_some_comments(comment) {
|
|||||||
|
|
||||||
function OutputStream(options) {
|
function OutputStream(options) {
|
||||||
|
|
||||||
|
var readonly = !options;
|
||||||
options = defaults(options, {
|
options = defaults(options, {
|
||||||
ascii_only : false,
|
ascii_only : false,
|
||||||
beautify : false,
|
beautify : false,
|
||||||
bracketize : false,
|
bracketize : false,
|
||||||
comments : false,
|
comments : false,
|
||||||
ecma : 5,
|
|
||||||
ie8 : false,
|
ie8 : false,
|
||||||
indent_level : 4,
|
indent_level : 4,
|
||||||
indent_start : 0,
|
indent_start : 0,
|
||||||
@@ -68,19 +68,14 @@ function OutputStream(options) {
|
|||||||
preserve_line : false,
|
preserve_line : false,
|
||||||
quote_keys : false,
|
quote_keys : false,
|
||||||
quote_style : 0,
|
quote_style : 0,
|
||||||
safari10 : false,
|
|
||||||
semicolons : true,
|
semicolons : true,
|
||||||
shebang : true,
|
shebang : true,
|
||||||
shorthand : undefined,
|
|
||||||
source_map : null,
|
source_map : null,
|
||||||
webkit : false,
|
webkit : false,
|
||||||
width : 80,
|
width : 80,
|
||||||
wrap_iife : false,
|
wrap_iife : false,
|
||||||
}, true);
|
}, true);
|
||||||
|
|
||||||
if (options.shorthand === undefined)
|
|
||||||
options.shorthand = options.ecma > 5;
|
|
||||||
|
|
||||||
// Convert comment option to RegExp if neccessary and set up comments filter
|
// Convert comment option to RegExp if neccessary and set up comments filter
|
||||||
var comment_filter = return_false; // Default case, throw all comments away
|
var comment_filter = return_false; // Default case, throw all comments away
|
||||||
if (options.comments) {
|
if (options.comments) {
|
||||||
@@ -116,12 +111,6 @@ function OutputStream(options) {
|
|||||||
var OUTPUT = "";
|
var OUTPUT = "";
|
||||||
|
|
||||||
var to_utf8 = options.ascii_only ? function(str, identifier) {
|
var to_utf8 = options.ascii_only ? function(str, identifier) {
|
||||||
if (options.ecma >= 6) {
|
|
||||||
str = str.replace(/[\ud800-\udbff][\udc00-\udfff]/g, function(ch) {
|
|
||||||
var code = get_full_char_code(ch, 0).toString(16);
|
|
||||||
return "\\u{" + code + "}";
|
|
||||||
});
|
|
||||||
}
|
|
||||||
return str.replace(/[\u0000-\u001f\u007f-\uffff]/g, function(ch) {
|
return str.replace(/[\u0000-\u001f\u007f-\uffff]/g, function(ch) {
|
||||||
var code = ch.charCodeAt(0).toString(16);
|
var code = ch.charCodeAt(0).toString(16);
|
||||||
if (code.length <= 2 && !identifier) {
|
if (code.length <= 2 && !identifier) {
|
||||||
@@ -133,11 +122,16 @@ function OutputStream(options) {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
} : function(str) {
|
} : function(str) {
|
||||||
return str.replace(/[\ud800-\udbff](?![\udc00-\udfff])/g, function(ch) {
|
var s = "";
|
||||||
return "\\u" + ch.charCodeAt(0).toString(16);
|
for (var i = 0, len = str.length; i < len; i++) {
|
||||||
}).replace(/(^|[^\ud800-\udbff])([\udc00-\udfff])/g, function(match, prefix, ch) {
|
if (is_surrogate_pair_head(str[i]) && !is_surrogate_pair_tail(str[i + 1])
|
||||||
return prefix + "\\u" + ch.charCodeAt(0).toString(16);
|
|| is_surrogate_pair_tail(str[i]) && !is_surrogate_pair_head(str[i - 1])) {
|
||||||
});
|
s += "\\u" + str.charCodeAt(i).toString(16);
|
||||||
|
} else {
|
||||||
|
s += str[i];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return s;
|
||||||
};
|
};
|
||||||
|
|
||||||
function make_string(str, quote) {
|
function make_string(str, quote) {
|
||||||
@@ -158,7 +152,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-9]/.test(get_full_char(str, i+1)) ? "\\x00" : "\\0";
|
return /[0-9]/.test(str.charAt(i+1)) ? "\\x00" : "\\0";
|
||||||
}
|
}
|
||||||
return s;
|
return s;
|
||||||
});
|
});
|
||||||
@@ -168,11 +162,7 @@ function OutputStream(options) {
|
|||||||
function quote_double() {
|
function quote_double() {
|
||||||
return '"' + str.replace(/\x22/g, '\\"') + '"';
|
return '"' + str.replace(/\x22/g, '\\"') + '"';
|
||||||
}
|
}
|
||||||
function quote_template() {
|
|
||||||
return '`' + str.replace(/`/g, '\\`') + '`';
|
|
||||||
}
|
|
||||||
str = to_utf8(str);
|
str = to_utf8(str);
|
||||||
if (quote === "`") return quote_template();
|
|
||||||
switch (options.quote_style) {
|
switch (options.quote_style) {
|
||||||
case 1:
|
case 1:
|
||||||
return quote_single();
|
return quote_single();
|
||||||
@@ -210,6 +200,9 @@ function OutputStream(options) {
|
|||||||
var might_need_space = false;
|
var might_need_space = false;
|
||||||
var might_need_semicolon = false;
|
var might_need_semicolon = false;
|
||||||
var might_add_newline = 0;
|
var might_add_newline = 0;
|
||||||
|
var need_newline_indented = false;
|
||||||
|
var need_space = false;
|
||||||
|
var newline_insert = -1;
|
||||||
var last = "";
|
var last = "";
|
||||||
var mapping_token, mapping_name, mappings = options.source_map && [];
|
var mapping_token, mapping_name, mappings = options.source_map && [];
|
||||||
|
|
||||||
@@ -263,12 +256,26 @@ function OutputStream(options) {
|
|||||||
}
|
}
|
||||||
} : noop;
|
} : noop;
|
||||||
|
|
||||||
var requireSemicolonChars = makePredicate("( [ + * / - , . `");
|
var requireSemicolonChars = makePredicate("( [ + * / - , .");
|
||||||
|
|
||||||
function print(str) {
|
function print(str) {
|
||||||
str = String(str);
|
str = String(str);
|
||||||
var ch = get_full_char(str, 0);
|
var ch = str.charAt(0);
|
||||||
var prev = get_full_char(last, last.length - 1);
|
if (need_newline_indented && ch) {
|
||||||
|
need_newline_indented = false;
|
||||||
|
if (ch != "\n") {
|
||||||
|
print("\n");
|
||||||
|
indent();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (need_space && ch) {
|
||||||
|
need_space = false;
|
||||||
|
if (!/[\s;})]/.test(ch)) {
|
||||||
|
space();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
newline_insert = -1;
|
||||||
|
var prev = last.charAt(last.length - 1);
|
||||||
if (might_need_semicolon) {
|
if (might_need_semicolon) {
|
||||||
might_need_semicolon = false;
|
might_need_semicolon = false;
|
||||||
|
|
||||||
@@ -344,10 +351,6 @@ function OutputStream(options) {
|
|||||||
last = str;
|
last = str;
|
||||||
};
|
};
|
||||||
|
|
||||||
var star = function(){
|
|
||||||
print("*");
|
|
||||||
}
|
|
||||||
|
|
||||||
var space = options.beautify ? function() {
|
var space = options.beautify ? function() {
|
||||||
print(" ");
|
print(" ");
|
||||||
} : function() {
|
} : function() {
|
||||||
@@ -370,7 +373,13 @@ function OutputStream(options) {
|
|||||||
} : function(col, cont) { return cont() };
|
} : function(col, cont) { return cont() };
|
||||||
|
|
||||||
var newline = options.beautify ? function() {
|
var newline = options.beautify ? function() {
|
||||||
print("\n");
|
if (newline_insert < 0) return print("\n");
|
||||||
|
if (OUTPUT[newline_insert] != "\n") {
|
||||||
|
OUTPUT = OUTPUT.slice(0, newline_insert) + "\n" + OUTPUT.slice(newline_insert);
|
||||||
|
current_pos++;
|
||||||
|
current_line++;
|
||||||
|
}
|
||||||
|
newline_insert++;
|
||||||
} : options.max_line_len ? function() {
|
} : options.max_line_len ? function() {
|
||||||
ensure_line_len();
|
ensure_line_len();
|
||||||
might_add_newline = OUTPUT.length;
|
might_add_newline = OUTPUT.length;
|
||||||
@@ -442,6 +451,123 @@ function OutputStream(options) {
|
|||||||
return OUTPUT;
|
return OUTPUT;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
function has_nlb() {
|
||||||
|
var index = OUTPUT.lastIndexOf("\n");
|
||||||
|
return /^ *$/.test(OUTPUT.slice(index + 1));
|
||||||
|
}
|
||||||
|
|
||||||
|
function prepend_comments(node) {
|
||||||
|
var self = this;
|
||||||
|
var start = node.start;
|
||||||
|
if (!start) return;
|
||||||
|
if (start.comments_before && start.comments_before._dumped === self) return;
|
||||||
|
var comments = start.comments_before;
|
||||||
|
if (!comments) {
|
||||||
|
comments = start.comments_before = [];
|
||||||
|
}
|
||||||
|
comments._dumped = self;
|
||||||
|
|
||||||
|
if (node instanceof AST_Exit && node.value) {
|
||||||
|
var tw = new TreeWalker(function(node) {
|
||||||
|
var parent = tw.parent();
|
||||||
|
if (parent instanceof AST_Exit
|
||||||
|
|| parent instanceof AST_Binary && parent.left === node
|
||||||
|
|| parent.TYPE == "Call" && parent.expression === node
|
||||||
|
|| parent instanceof AST_Conditional && parent.condition === node
|
||||||
|
|| parent instanceof AST_Dot && parent.expression === node
|
||||||
|
|| parent instanceof AST_Sequence && parent.expressions[0] === node
|
||||||
|
|| parent instanceof AST_Sub && parent.expression === node
|
||||||
|
|| parent instanceof AST_UnaryPostfix) {
|
||||||
|
var text = node.start.comments_before;
|
||||||
|
if (text && text._dumped !== self) {
|
||||||
|
text._dumped = self;
|
||||||
|
comments = comments.concat(text);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
tw.push(node);
|
||||||
|
node.value.walk(tw);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (current_pos == 0) {
|
||||||
|
if (comments.length > 0 && options.shebang && comments[0].type == "comment5") {
|
||||||
|
print("#!" + comments.shift().value + "\n");
|
||||||
|
indent();
|
||||||
|
}
|
||||||
|
var preamble = options.preamble;
|
||||||
|
if (preamble) {
|
||||||
|
print(preamble.replace(/\r\n?|[\n\u2028\u2029]|\s*$/g, "\n"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
comments = comments.filter(comment_filter, node);
|
||||||
|
if (comments.length == 0) return;
|
||||||
|
var last_nlb = has_nlb();
|
||||||
|
comments.forEach(function(c, i) {
|
||||||
|
if (!last_nlb) {
|
||||||
|
if (c.nlb) {
|
||||||
|
print("\n");
|
||||||
|
indent();
|
||||||
|
last_nlb = true;
|
||||||
|
} else if (i > 0) {
|
||||||
|
space();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (/comment[134]/.test(c.type)) {
|
||||||
|
print("//" + c.value.replace(/[@#]__PURE__/g, ' ') + "\n");
|
||||||
|
indent();
|
||||||
|
last_nlb = true;
|
||||||
|
} else if (c.type == "comment2") {
|
||||||
|
print("/*" + c.value.replace(/[@#]__PURE__/g, ' ') + "*/");
|
||||||
|
last_nlb = false;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
if (!last_nlb) {
|
||||||
|
if (start.nlb) {
|
||||||
|
print("\n");
|
||||||
|
indent();
|
||||||
|
} else {
|
||||||
|
space();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function append_comments(node, tail) {
|
||||||
|
var self = this;
|
||||||
|
var token = node.end;
|
||||||
|
if (!token) return;
|
||||||
|
var comments = token[tail ? "comments_before" : "comments_after"];
|
||||||
|
if (!comments || comments._dumped === self) return;
|
||||||
|
if (!(node instanceof AST_Statement || all(comments, function(c) {
|
||||||
|
return !/comment[134]/.test(c.type);
|
||||||
|
}))) return;
|
||||||
|
comments._dumped = self;
|
||||||
|
var insert = OUTPUT.length;
|
||||||
|
comments.filter(comment_filter, node).forEach(function(c, i) {
|
||||||
|
need_space = false;
|
||||||
|
if (need_newline_indented) {
|
||||||
|
print("\n");
|
||||||
|
indent();
|
||||||
|
need_newline_indented = false;
|
||||||
|
} else if (c.nlb && (i > 0 || !has_nlb())) {
|
||||||
|
print("\n");
|
||||||
|
indent();
|
||||||
|
} else if (i > 0 || !tail) {
|
||||||
|
space();
|
||||||
|
}
|
||||||
|
if (/comment[134]/.test(c.type)) {
|
||||||
|
print("//" + c.value.replace(/[@#]__PURE__/g, ' '));
|
||||||
|
need_newline_indented = true;
|
||||||
|
} else if (c.type == "comment2") {
|
||||||
|
print("/*" + c.value.replace(/[@#]__PURE__/g, ' ') + "*/");
|
||||||
|
need_space = true;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
if (OUTPUT.length > insert) newline_insert = insert;
|
||||||
|
}
|
||||||
|
|
||||||
var stack = [];
|
var stack = [];
|
||||||
return {
|
return {
|
||||||
get : get,
|
get : get,
|
||||||
@@ -452,7 +578,6 @@ function OutputStream(options) {
|
|||||||
should_break : function() { return options.width && this.current_width() >= options.width },
|
should_break : function() { return options.width && this.current_width() >= options.width },
|
||||||
newline : newline,
|
newline : newline,
|
||||||
print : print,
|
print : print,
|
||||||
star : star,
|
|
||||||
space : space,
|
space : space,
|
||||||
comma : comma,
|
comma : comma,
|
||||||
colon : colon,
|
colon : colon,
|
||||||
@@ -472,10 +597,6 @@ function OutputStream(options) {
|
|||||||
}
|
}
|
||||||
print(encoded);
|
print(encoded);
|
||||||
},
|
},
|
||||||
print_template_string_chars: function(str) {
|
|
||||||
var encoded = encode_string(str, '`').replace(/\${/g, "\\${");
|
|
||||||
return print(encoded.substr(1, encoded.length - 2));
|
|
||||||
},
|
|
||||||
encode_string : encode_string,
|
encode_string : encode_string,
|
||||||
next_indent : next_indent,
|
next_indent : next_indent,
|
||||||
with_indent : with_indent,
|
with_indent : with_indent,
|
||||||
@@ -484,7 +605,8 @@ function OutputStream(options) {
|
|||||||
with_square : with_square,
|
with_square : with_square,
|
||||||
add_mapping : add_mapping,
|
add_mapping : add_mapping,
|
||||||
option : function(opt) { return options[opt] },
|
option : function(opt) { return options[opt] },
|
||||||
comment_filter : comment_filter,
|
prepend_comments: readonly ? noop : prepend_comments,
|
||||||
|
append_comments : readonly || comment_filter === return_false ? noop : append_comments,
|
||||||
line : function() { return current_line },
|
line : function() { return current_line },
|
||||||
col : function() { return current_col },
|
col : function() { return current_col },
|
||||||
pos : function() { return current_pos },
|
pos : function() { return current_pos },
|
||||||
@@ -520,9 +642,10 @@ function OutputStream(options) {
|
|||||||
use_asm = active_scope;
|
use_asm = active_scope;
|
||||||
}
|
}
|
||||||
function doit() {
|
function doit() {
|
||||||
self.add_comments(stream);
|
stream.prepend_comments(self);
|
||||||
self.add_source_map(stream);
|
self.add_source_map(stream);
|
||||||
generator(self, stream);
|
generator(self, stream);
|
||||||
|
stream.append_comments(self);
|
||||||
}
|
}
|
||||||
stream.push_node(self);
|
stream.push_node(self);
|
||||||
if (force_parens || self.needs_parens(stream)) {
|
if (force_parens || self.needs_parens(stream)) {
|
||||||
@@ -539,77 +662,10 @@ function OutputStream(options) {
|
|||||||
|
|
||||||
AST_Node.DEFMETHOD("print_to_string", function(options){
|
AST_Node.DEFMETHOD("print_to_string", function(options){
|
||||||
var s = OutputStream(options);
|
var s = OutputStream(options);
|
||||||
if (!options) s._readonly = true;
|
|
||||||
this.print(s);
|
this.print(s);
|
||||||
return s.get();
|
return s.get();
|
||||||
});
|
});
|
||||||
|
|
||||||
/* -----[ comments ]----- */
|
|
||||||
|
|
||||||
AST_Node.DEFMETHOD("add_comments", function(output){
|
|
||||||
if (output._readonly) return;
|
|
||||||
var self = this;
|
|
||||||
var start = self.start;
|
|
||||||
if (start && !start._comments_dumped) {
|
|
||||||
start._comments_dumped = true;
|
|
||||||
var comments = start.comments_before || [];
|
|
||||||
|
|
||||||
// XXX: ugly fix for https://github.com/mishoo/UglifyJS2/issues/112
|
|
||||||
// and https://github.com/mishoo/UglifyJS2/issues/372
|
|
||||||
if (self instanceof AST_Exit && self.value) {
|
|
||||||
self.value.walk(new TreeWalker(function(node){
|
|
||||||
if (node.start && node.start.comments_before) {
|
|
||||||
comments = comments.concat(node.start.comments_before);
|
|
||||||
node.start.comments_before = [];
|
|
||||||
}
|
|
||||||
if (node instanceof AST_Function ||
|
|
||||||
node instanceof AST_Array ||
|
|
||||||
node instanceof AST_Object)
|
|
||||||
{
|
|
||||||
return true; // don't go inside.
|
|
||||||
}
|
|
||||||
}));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (output.pos() == 0) {
|
|
||||||
if (comments.length > 0 && output.option("shebang") && comments[0].type == "comment5") {
|
|
||||||
output.print("#!" + comments.shift().value + "\n");
|
|
||||||
output.indent();
|
|
||||||
}
|
|
||||||
var preamble = output.option("preamble");
|
|
||||||
if (preamble) {
|
|
||||||
output.print(preamble.replace(/\r\n?|[\n\u2028\u2029]|\s*$/g, "\n"));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
comments = comments.filter(output.comment_filter, self);
|
|
||||||
|
|
||||||
// Keep single line comments after nlb, after nlb
|
|
||||||
if (!output.option("beautify") && comments.length > 0 &&
|
|
||||||
/comment[134]/.test(comments[0].type) &&
|
|
||||||
output.col() !== 0 && comments[0].nlb)
|
|
||||||
{
|
|
||||||
output.print("\n");
|
|
||||||
}
|
|
||||||
|
|
||||||
comments.forEach(function(c){
|
|
||||||
if (/comment[134]/.test(c.type)) {
|
|
||||||
output.print("//" + c.value + "\n");
|
|
||||||
output.indent();
|
|
||||||
}
|
|
||||||
else if (c.type == "comment2") {
|
|
||||||
output.print("/*" + c.value + "*/");
|
|
||||||
if (start.nlb) {
|
|
||||||
output.print("\n");
|
|
||||||
output.indent();
|
|
||||||
} else {
|
|
||||||
output.space();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
/* -----[ PARENTHESES ]----- */
|
/* -----[ PARENTHESES ]----- */
|
||||||
|
|
||||||
function PARENS(nodetype, func) {
|
function PARENS(nodetype, func) {
|
||||||
@@ -622,9 +678,7 @@ function OutputStream(options) {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
PARENS(AST_Node, function(){
|
PARENS(AST_Node, return_false);
|
||||||
return false;
|
|
||||||
});
|
|
||||||
|
|
||||||
// a function expression needs parens around it when it's provably
|
// a function expression needs parens around it when it's provably
|
||||||
// the first token to appear in a statement.
|
// the first token to appear in a statement.
|
||||||
@@ -648,54 +702,27 @@ function OutputStream(options) {
|
|||||||
return false;
|
return false;
|
||||||
});
|
});
|
||||||
|
|
||||||
PARENS(AST_Arrow, function(output){
|
|
||||||
var p = output.parent();
|
|
||||||
return p instanceof AST_PropAccess && p.expression === this;
|
|
||||||
});
|
|
||||||
|
|
||||||
PARENS(AST_ClassExpression, function(output){
|
|
||||||
return output.parent() instanceof AST_SimpleStatement;
|
|
||||||
});
|
|
||||||
|
|
||||||
// same goes for an object literal, because otherwise it would be
|
// same goes for an object literal, because otherwise it would be
|
||||||
// interpreted as a block of code.
|
// interpreted as a block of code.
|
||||||
PARENS(AST_Object, function(output){
|
PARENS(AST_Object, first_in_statement);
|
||||||
return first_in_statement(output);
|
|
||||||
});
|
|
||||||
|
|
||||||
PARENS(AST_Unary, function(output){
|
PARENS(AST_Unary, function(output){
|
||||||
var p = output.parent();
|
var p = output.parent();
|
||||||
return p instanceof AST_PropAccess && p.expression === this
|
return p instanceof AST_PropAccess && p.expression === this
|
||||||
|| p instanceof AST_Call && p.expression === this
|
|| p instanceof AST_Call && p.expression === this;
|
||||||
|| p instanceof AST_Binary
|
|
||||||
&& p.operator === "**"
|
|
||||||
&& this instanceof AST_UnaryPrefix
|
|
||||||
&& p.left === this
|
|
||||||
&& this.operator !== "++"
|
|
||||||
&& this.operator !== "--";
|
|
||||||
});
|
|
||||||
|
|
||||||
PARENS(AST_Await, function(output){
|
|
||||||
var p = output.parent();
|
|
||||||
return p instanceof AST_PropAccess && p.expression === this
|
|
||||||
|| p instanceof AST_Call && p.expression === this
|
|
||||||
|| output.option("safari10") && p instanceof AST_UnaryPrefix;
|
|
||||||
});
|
});
|
||||||
|
|
||||||
PARENS(AST_Sequence, function(output){
|
PARENS(AST_Sequence, function(output){
|
||||||
var p = output.parent();
|
var p = output.parent();
|
||||||
return p instanceof AST_Call // (foo, bar)() or foo(1, (2, 3), 4)
|
return p instanceof AST_Call // (foo, bar)() or foo(1, (2, 3), 4)
|
||||||
|| p instanceof AST_Unary // !(foo, bar, baz)
|
|| p instanceof AST_Unary // !(foo, bar, baz)
|
||||||
|| p instanceof AST_Binary // 1 + (2, 3) + 4 ==> 8
|
|| p instanceof AST_Binary // 1 + (2, 3) + 4 ==> 8
|
||||||
|| p instanceof AST_VarDef // var a = (1, 2), b = a + a; ==> b == 4
|
|| p instanceof AST_VarDef // var a = (1, 2), b = a + a; ==> b == 4
|
||||||
|| p instanceof AST_PropAccess // (1, {foo:2}).foo or (1, {foo:2})["foo"] ==> 2
|
|| p instanceof AST_PropAccess // (1, {foo:2}).foo or (1, {foo:2})["foo"] ==> 2
|
||||||
|| p instanceof AST_Array // [ 1, (2, 3), 4 ] ==> [ 1, 3, 4 ]
|
|| p instanceof AST_Array // [ 1, (2, 3), 4 ] ==> [ 1, 3, 4 ]
|
||||||
|| p instanceof AST_ObjectProperty // { foo: (1, 2) }.foo ==> 2
|
|| p instanceof AST_ObjectProperty // { foo: (1, 2) }.foo ==> 2
|
||||||
|| p instanceof AST_Conditional /* (false, true) ? (a = 10, b = 20) : (c = 30)
|
|| p instanceof AST_Conditional /* (false, true) ? (a = 10, b = 20) : (c = 30)
|
||||||
* ==> 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_DefaultAssign // x => (x = (0, function(){}))
|
|
||||||
|| p instanceof AST_Expansion // [...(a, b)]
|
|
||||||
;
|
;
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -722,24 +749,6 @@ function OutputStream(options) {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
PARENS(AST_Yield, function(output){
|
|
||||||
var p = output.parent();
|
|
||||||
// (yield 1) + (yield 2)
|
|
||||||
// a = yield 3
|
|
||||||
if (p instanceof AST_Binary && p.operator !== "=")
|
|
||||||
return true;
|
|
||||||
// (yield 1) ? yield 2 : yield 3
|
|
||||||
if (p instanceof AST_Conditional && p.condition === this)
|
|
||||||
return true;
|
|
||||||
// -(yield 4)
|
|
||||||
if (p instanceof AST_Unary)
|
|
||||||
return true;
|
|
||||||
// (yield x).foo
|
|
||||||
// (yield x)['foo']
|
|
||||||
if (p instanceof AST_PropAccess && p.expression === this)
|
|
||||||
return true;
|
|
||||||
});
|
|
||||||
|
|
||||||
PARENS(AST_PropAccess, function(output){
|
PARENS(AST_PropAccess, function(output){
|
||||||
var p = output.parent();
|
var p = output.parent();
|
||||||
if (p instanceof AST_New && p.expression === this) {
|
if (p instanceof AST_New && p.expression === this) {
|
||||||
@@ -810,9 +819,6 @@ function OutputStream(options) {
|
|||||||
// (a = foo)["prop"] —or— (a = foo).prop
|
// (a = foo)["prop"] —or— (a = foo).prop
|
||||||
if (p instanceof AST_PropAccess && p.expression === this)
|
if (p instanceof AST_PropAccess && p.expression === this)
|
||||||
return true;
|
return true;
|
||||||
// ({a, b} = {a: 1, b: 2}), a destructuring assignment
|
|
||||||
if (this instanceof AST_Assign && this.left instanceof AST_Destructuring && this.left.is_array === false)
|
|
||||||
return true;
|
|
||||||
});
|
});
|
||||||
|
|
||||||
/* -----[ PRINTERS ]----- */
|
/* -----[ PRINTERS ]----- */
|
||||||
@@ -821,26 +827,6 @@ function OutputStream(options) {
|
|||||||
output.print_string(self.value, self.quote);
|
output.print_string(self.value, self.quote);
|
||||||
output.semicolon();
|
output.semicolon();
|
||||||
});
|
});
|
||||||
|
|
||||||
DEFPRINT(AST_Expansion, function (self, output) {
|
|
||||||
output.print('...');
|
|
||||||
self.expression.print(output);
|
|
||||||
});
|
|
||||||
|
|
||||||
DEFPRINT(AST_Destructuring, function (self, output) {
|
|
||||||
output.print(self.is_array ? "[" : "{");
|
|
||||||
var len = self.names.length;
|
|
||||||
self.names.forEach(function (name, i) {
|
|
||||||
if (i > 0) output.comma();
|
|
||||||
name.print(output);
|
|
||||||
// If the final element is a hole, we need to make sure it
|
|
||||||
// doesn't look like a trailing comma, by inserting an actual
|
|
||||||
// trailing comma.
|
|
||||||
if (i == len - 1 && name instanceof AST_Hole) output.comma();
|
|
||||||
});
|
|
||||||
output.print(self.is_array ? "]" : "}");
|
|
||||||
});
|
|
||||||
|
|
||||||
DEFPRINT(AST_Debugger, function(self, output){
|
DEFPRINT(AST_Debugger, function(self, output){
|
||||||
output.print("debugger");
|
output.print("debugger");
|
||||||
output.semicolon();
|
output.semicolon();
|
||||||
@@ -897,14 +883,21 @@ function OutputStream(options) {
|
|||||||
self.body.print(output);
|
self.body.print(output);
|
||||||
output.semicolon();
|
output.semicolon();
|
||||||
});
|
});
|
||||||
function print_bracketed(body, output, allow_directives) {
|
function print_bracketed(self, output, allow_directives) {
|
||||||
if (body.length > 0) output.with_block(function(){
|
if (self.body.length > 0) {
|
||||||
display_body(body, false, output, allow_directives);
|
output.with_block(function() {
|
||||||
});
|
display_body(self.body, false, output, allow_directives);
|
||||||
else output.print("{}");
|
});
|
||||||
|
} else {
|
||||||
|
output.print("{");
|
||||||
|
output.with_indent(output.next_indent(), function() {
|
||||||
|
output.append_comments(self, true);
|
||||||
|
});
|
||||||
|
output.print("}");
|
||||||
|
}
|
||||||
};
|
};
|
||||||
DEFPRINT(AST_BlockStatement, function(self, output){
|
DEFPRINT(AST_BlockStatement, function(self, output){
|
||||||
print_bracketed(self.body, output);
|
print_bracketed(self, output);
|
||||||
});
|
});
|
||||||
DEFPRINT(AST_EmptyStatement, function(self, output){
|
DEFPRINT(AST_EmptyStatement, function(self, output){
|
||||||
output.semicolon();
|
output.semicolon();
|
||||||
@@ -965,11 +958,7 @@ function OutputStream(options) {
|
|||||||
output.with_parens(function(){
|
output.with_parens(function(){
|
||||||
self.init.print(output);
|
self.init.print(output);
|
||||||
output.space();
|
output.space();
|
||||||
if (self instanceof AST_ForOf) {
|
output.print("in");
|
||||||
output.print("of");
|
|
||||||
} else {
|
|
||||||
output.print("in");
|
|
||||||
}
|
|
||||||
output.space();
|
output.space();
|
||||||
self.object.print(output);
|
self.object.print(output);
|
||||||
});
|
});
|
||||||
@@ -990,24 +979,11 @@ function OutputStream(options) {
|
|||||||
AST_Lambda.DEFMETHOD("_do_print", function(output, nokeyword){
|
AST_Lambda.DEFMETHOD("_do_print", function(output, nokeyword){
|
||||||
var self = this;
|
var self = this;
|
||||||
if (!nokeyword) {
|
if (!nokeyword) {
|
||||||
if (self.async) {
|
|
||||||
output.print("async");
|
|
||||||
output.space();
|
|
||||||
}
|
|
||||||
output.print("function");
|
output.print("function");
|
||||||
if (self.is_generator) {
|
|
||||||
output.star();
|
|
||||||
}
|
|
||||||
if (self.name) {
|
|
||||||
output.space();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if (self.name instanceof AST_Symbol) {
|
if (self.name) {
|
||||||
|
output.space();
|
||||||
self.name.print(output);
|
self.name.print(output);
|
||||||
} else if (nokeyword && self.name instanceof AST_Node) {
|
|
||||||
output.with_square(function() {
|
|
||||||
self.name.print(output); // Computed method name
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
output.with_parens(function(){
|
output.with_parens(function(){
|
||||||
self.argnames.forEach(function(arg, i){
|
self.argnames.forEach(function(arg, i){
|
||||||
@@ -1016,66 +992,12 @@ function OutputStream(options) {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
output.space();
|
output.space();
|
||||||
print_bracketed(self.body, output, true);
|
print_bracketed(self, output, true);
|
||||||
});
|
});
|
||||||
DEFPRINT(AST_Lambda, function(self, output){
|
DEFPRINT(AST_Lambda, function(self, output){
|
||||||
self._do_print(output);
|
self._do_print(output);
|
||||||
});
|
});
|
||||||
|
|
||||||
DEFPRINT(AST_PrefixedTemplateString, function(self, output) {
|
|
||||||
self.prefix.print(output);
|
|
||||||
self.template_string.print(output);
|
|
||||||
});
|
|
||||||
DEFPRINT(AST_TemplateString, function(self, output) {
|
|
||||||
var is_tagged = output.parent() instanceof AST_PrefixedTemplateString;
|
|
||||||
|
|
||||||
output.print("`");
|
|
||||||
for (var i = 0; i < self.segments.length; i++) {
|
|
||||||
if (!(self.segments[i] instanceof AST_TemplateSegment)) {
|
|
||||||
output.print("${");
|
|
||||||
self.segments[i].print(output);
|
|
||||||
output.print("}");
|
|
||||||
} else if (is_tagged) {
|
|
||||||
output.print(self.segments[i].raw);
|
|
||||||
} else {
|
|
||||||
output.print_template_string_chars(self.segments[i].value);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
output.print("`");
|
|
||||||
});
|
|
||||||
|
|
||||||
AST_Arrow.DEFMETHOD("_do_print", function(output){
|
|
||||||
var self = this;
|
|
||||||
var parent = output.parent();
|
|
||||||
var needs_parens = parent instanceof AST_Binary ||
|
|
||||||
parent instanceof AST_Unary ||
|
|
||||||
(parent instanceof AST_Call && self === parent.expression);
|
|
||||||
if (needs_parens) { output.print("(") }
|
|
||||||
if (self.async) {
|
|
||||||
output.print("async");
|
|
||||||
output.space();
|
|
||||||
}
|
|
||||||
if (self.argnames.length === 1 && self.argnames[0] instanceof AST_Symbol) {
|
|
||||||
self.argnames[0].print(output);
|
|
||||||
} else {
|
|
||||||
output.with_parens(function(){
|
|
||||||
self.argnames.forEach(function(arg, i){
|
|
||||||
if (i) output.comma();
|
|
||||||
arg.print(output);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
|
||||||
output.space();
|
|
||||||
output.print('=>');
|
|
||||||
output.space();
|
|
||||||
if (self.body instanceof AST_Node) {
|
|
||||||
self.body.print(output);
|
|
||||||
} else {
|
|
||||||
print_bracketed(self.body, output);
|
|
||||||
}
|
|
||||||
if (needs_parens) { output.print(")") }
|
|
||||||
});
|
|
||||||
|
|
||||||
/* -----[ exits ]----- */
|
/* -----[ exits ]----- */
|
||||||
AST_Exit.DEFMETHOD("_do_print", function(output, kind){
|
AST_Exit.DEFMETHOD("_do_print", function(output, kind){
|
||||||
output.print(kind);
|
output.print(kind);
|
||||||
@@ -1092,33 +1014,6 @@ function OutputStream(options) {
|
|||||||
self._do_print(output, "throw");
|
self._do_print(output, "throw");
|
||||||
});
|
});
|
||||||
|
|
||||||
/* -----[ yield ]----- */
|
|
||||||
|
|
||||||
DEFPRINT(AST_Yield, function(self, output){
|
|
||||||
var star = self.is_star ? "*" : "";
|
|
||||||
output.print("yield" + star);
|
|
||||||
if (self.expression) {
|
|
||||||
output.space();
|
|
||||||
self.expression.print(output);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
DEFPRINT(AST_Await, function(self, output){
|
|
||||||
output.print("await");
|
|
||||||
output.space();
|
|
||||||
var e = self.expression;
|
|
||||||
var parens = !(
|
|
||||||
e instanceof AST_Call
|
|
||||||
|| e instanceof AST_SymbolRef
|
|
||||||
|| e instanceof AST_PropAccess
|
|
||||||
|| e instanceof AST_Unary
|
|
||||||
|| e instanceof AST_Constant
|
|
||||||
);
|
|
||||||
if (parens) output.print("(");
|
|
||||||
self.expression.print(output);
|
|
||||||
if (parens) output.print(")");
|
|
||||||
});
|
|
||||||
|
|
||||||
/* -----[ loop control ]----- */
|
/* -----[ loop control ]----- */
|
||||||
AST_LoopControl.DEFMETHOD("_do_print", function(output, kind){
|
AST_LoopControl.DEFMETHOD("_do_print", function(output, kind){
|
||||||
output.print(kind);
|
output.print(kind);
|
||||||
@@ -1228,7 +1123,7 @@ function OutputStream(options) {
|
|||||||
DEFPRINT(AST_Try, function(self, output){
|
DEFPRINT(AST_Try, function(self, output){
|
||||||
output.print("try");
|
output.print("try");
|
||||||
output.space();
|
output.space();
|
||||||
print_bracketed(self.body, output);
|
print_bracketed(self, output);
|
||||||
if (self.bcatch) {
|
if (self.bcatch) {
|
||||||
output.space();
|
output.space();
|
||||||
self.bcatch.print(output);
|
self.bcatch.print(output);
|
||||||
@@ -1245,12 +1140,12 @@ function OutputStream(options) {
|
|||||||
self.argname.print(output);
|
self.argname.print(output);
|
||||||
});
|
});
|
||||||
output.space();
|
output.space();
|
||||||
print_bracketed(self.body, output);
|
print_bracketed(self, output);
|
||||||
});
|
});
|
||||||
DEFPRINT(AST_Finally, function(self, output){
|
DEFPRINT(AST_Finally, function(self, output){
|
||||||
output.print("finally");
|
output.print("finally");
|
||||||
output.space();
|
output.space();
|
||||||
print_bracketed(self.body, output);
|
print_bracketed(self, output);
|
||||||
});
|
});
|
||||||
|
|
||||||
/* -----[ var/const ]----- */
|
/* -----[ var/const ]----- */
|
||||||
@@ -1267,112 +1162,9 @@ function OutputStream(options) {
|
|||||||
if (!avoid_semicolon)
|
if (!avoid_semicolon)
|
||||||
output.semicolon();
|
output.semicolon();
|
||||||
});
|
});
|
||||||
DEFPRINT(AST_Let, function(self, output){
|
|
||||||
self._do_print(output, "let");
|
|
||||||
});
|
|
||||||
DEFPRINT(AST_Var, function(self, output){
|
DEFPRINT(AST_Var, function(self, output){
|
||||||
self._do_print(output, "var");
|
self._do_print(output, "var");
|
||||||
});
|
});
|
||||||
DEFPRINT(AST_Const, function(self, output){
|
|
||||||
self._do_print(output, "const");
|
|
||||||
});
|
|
||||||
DEFPRINT(AST_Import, function(self, output) {
|
|
||||||
output.print("import");
|
|
||||||
output.space();
|
|
||||||
if (self.imported_name) {
|
|
||||||
self.imported_name.print(output);
|
|
||||||
}
|
|
||||||
if (self.imported_name && self.imported_names) {
|
|
||||||
output.print(",");
|
|
||||||
output.space();
|
|
||||||
}
|
|
||||||
if (self.imported_names) {
|
|
||||||
if (self.imported_names.length === 1 && self.imported_names[0].foreign_name.name === "*") {
|
|
||||||
self.imported_names[0].print(output);
|
|
||||||
} else {
|
|
||||||
output.print("{");
|
|
||||||
self.imported_names.forEach(function (name_import, i) {
|
|
||||||
output.space();
|
|
||||||
name_import.print(output);
|
|
||||||
if (i < self.imported_names.length - 1) {
|
|
||||||
output.print(",");
|
|
||||||
}
|
|
||||||
});
|
|
||||||
output.space();
|
|
||||||
output.print("}");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (self.imported_name || self.imported_names) {
|
|
||||||
output.space();
|
|
||||||
output.print("from")
|
|
||||||
output.space();
|
|
||||||
}
|
|
||||||
self.module_name.print(output);
|
|
||||||
output.semicolon();
|
|
||||||
});
|
|
||||||
|
|
||||||
DEFPRINT(AST_NameMapping, function(self, output) {
|
|
||||||
var is_import = output.parent() instanceof AST_Import;
|
|
||||||
var definition = self.name.definition();
|
|
||||||
var names_are_different =
|
|
||||||
(definition && definition.mangled_name || self.name.name) !==
|
|
||||||
self.foreign_name.name;
|
|
||||||
if (names_are_different) {
|
|
||||||
if (is_import) {
|
|
||||||
output.print(self.foreign_name.name);
|
|
||||||
} else {
|
|
||||||
self.name.print(output);
|
|
||||||
}
|
|
||||||
output.space();
|
|
||||||
output.print("as");
|
|
||||||
output.space();
|
|
||||||
if (is_import) {
|
|
||||||
self.name.print(output);
|
|
||||||
} else {
|
|
||||||
output.print(self.foreign_name.name);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
self.name.print(output);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
DEFPRINT(AST_Export, function(self, output) {
|
|
||||||
output.print("export");
|
|
||||||
output.space();
|
|
||||||
if (self.is_default) {
|
|
||||||
output.print("default");
|
|
||||||
output.space();
|
|
||||||
}
|
|
||||||
if (self.exported_names) {
|
|
||||||
if (self.exported_names.length === 1 && self.exported_names[0].name.name === "*") {
|
|
||||||
self.exported_names[0].print(output);
|
|
||||||
} else {
|
|
||||||
output.print("{");
|
|
||||||
self.exported_names.forEach(function(name_export, i) {
|
|
||||||
output.space();
|
|
||||||
name_export.print(output);
|
|
||||||
if (i < self.exported_names.length - 1) {
|
|
||||||
output.print(",");
|
|
||||||
}
|
|
||||||
});
|
|
||||||
output.space();
|
|
||||||
output.print("}");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if (self.exported_value) {
|
|
||||||
self.exported_value.print(output);
|
|
||||||
} else if (self.exported_definition) {
|
|
||||||
self.exported_definition.print(output);
|
|
||||||
if (self.exported_definition instanceof AST_Definitions) return;
|
|
||||||
}
|
|
||||||
if (self.module_name) {
|
|
||||||
output.space();
|
|
||||||
output.print("from");
|
|
||||||
output.space();
|
|
||||||
self.module_name.print(output);
|
|
||||||
}
|
|
||||||
output.semicolon();
|
|
||||||
});
|
|
||||||
|
|
||||||
function parenthesize_for_noin(node, output, noin) {
|
function parenthesize_for_noin(node, output, noin) {
|
||||||
var parens = false;
|
var parens = false;
|
||||||
@@ -1554,56 +1346,11 @@ function OutputStream(options) {
|
|||||||
});
|
});
|
||||||
else output.print("{}");
|
else output.print("{}");
|
||||||
});
|
});
|
||||||
DEFPRINT(AST_Class, function(self, output){
|
|
||||||
output.print("class");
|
|
||||||
output.space();
|
|
||||||
if (self.name) {
|
|
||||||
self.name.print(output);
|
|
||||||
output.space();
|
|
||||||
}
|
|
||||||
if (self.extends) {
|
|
||||||
var parens = (
|
|
||||||
!(self.extends instanceof AST_SymbolRef)
|
|
||||||
&& !(self.extends instanceof AST_PropAccess)
|
|
||||||
&& !(self.extends instanceof AST_ClassExpression)
|
|
||||||
&& !(self.extends instanceof AST_Function)
|
|
||||||
);
|
|
||||||
output.print("extends");
|
|
||||||
if (parens) {
|
|
||||||
output.print("(");
|
|
||||||
} else {
|
|
||||||
output.space();
|
|
||||||
}
|
|
||||||
self.extends.print(output);
|
|
||||||
if (parens) {
|
|
||||||
output.print(")");
|
|
||||||
} else {
|
|
||||||
output.space();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (self.properties.length > 0) output.with_block(function(){
|
|
||||||
self.properties.forEach(function(prop, i){
|
|
||||||
if (i) {
|
|
||||||
output.newline();
|
|
||||||
}
|
|
||||||
output.indent();
|
|
||||||
prop.print(output);
|
|
||||||
});
|
|
||||||
output.newline();
|
|
||||||
});
|
|
||||||
else output.print("{}");
|
|
||||||
});
|
|
||||||
DEFPRINT(AST_NewTarget, function(self, output) {
|
|
||||||
output.print("new.target");
|
|
||||||
});
|
|
||||||
|
|
||||||
function print_property_name(key, quote, output) {
|
function print_property_name(key, quote, output) {
|
||||||
if (output.option("quote_keys")) {
|
if (output.option("quote_keys")) {
|
||||||
output.print_string(key + "");
|
output.print_string(key);
|
||||||
} else if ((typeof key == "number"
|
} else if ("" + +key == key && key >= 0) {
|
||||||
|| !output.option("beautify")
|
|
||||||
&& +key + "" == key)
|
|
||||||
&& parseFloat(key) >= 0) {
|
|
||||||
output.print(make_num(key));
|
output.print(make_num(key));
|
||||||
} else if (RESERVED_WORDS(key) ? !output.option("ie8") : is_identifier_string(key)) {
|
} else if (RESERVED_WORDS(key) ? !output.option("ie8") : is_identifier_string(key)) {
|
||||||
if (quote && output.option("keep_quoted_props")) {
|
if (quote && output.option("keep_quoted_props")) {
|
||||||
@@ -1617,61 +1364,15 @@ function OutputStream(options) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
DEFPRINT(AST_ObjectKeyVal, function(self, output){
|
DEFPRINT(AST_ObjectKeyVal, function(self, output){
|
||||||
function get_name(self) {
|
print_property_name(self.key, self.quote, output);
|
||||||
var def = self.definition();
|
output.colon();
|
||||||
return def ? def.mangled_name || def.name : self.name;
|
self.value.print(output);
|
||||||
}
|
|
||||||
|
|
||||||
var allowShortHand = output.option("shorthand");
|
|
||||||
if (allowShortHand &&
|
|
||||||
self.value instanceof AST_Symbol &&
|
|
||||||
is_identifier_string(self.key) &&
|
|
||||||
get_name(self.value) === self.key &&
|
|
||||||
is_identifier(self.key)
|
|
||||||
) {
|
|
||||||
print_property_name(self.key, self.quote, output);
|
|
||||||
|
|
||||||
} else if (allowShortHand &&
|
|
||||||
self.value instanceof AST_DefaultAssign &&
|
|
||||||
self.value.left instanceof AST_Symbol &&
|
|
||||||
is_identifier_string(self.key) &&
|
|
||||||
get_name(self.value.left) === self.key
|
|
||||||
) {
|
|
||||||
print_property_name(self.key, self.quote, output);
|
|
||||||
output.space();
|
|
||||||
output.print("=");
|
|
||||||
output.space();
|
|
||||||
self.value.right.print(output);
|
|
||||||
} else {
|
|
||||||
if (!(self.key instanceof AST_Node)) {
|
|
||||||
print_property_name(self.key, self.quote, output);
|
|
||||||
} else {
|
|
||||||
output.with_square(function() {
|
|
||||||
self.key.print(output);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
output.colon();
|
|
||||||
self.value.print(output);
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
AST_ObjectProperty.DEFMETHOD("_print_getter_setter", function(type, output) {
|
AST_ObjectProperty.DEFMETHOD("_print_getter_setter", function(type, output) {
|
||||||
var self = this;
|
output.print(type);
|
||||||
if (self.static) {
|
output.space();
|
||||||
output.print("static");
|
print_property_name(this.key.name, this.quote, output);
|
||||||
output.space();
|
this.value._do_print(output, true);
|
||||||
}
|
|
||||||
if (type) {
|
|
||||||
output.print(type);
|
|
||||||
output.space();
|
|
||||||
}
|
|
||||||
if (self.key instanceof AST_SymbolMethod) {
|
|
||||||
print_property_name(self.key.name, self.quote, output);
|
|
||||||
} else {
|
|
||||||
output.with_square(function() {
|
|
||||||
self.key.print(output);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
self.value._do_print(output, true);
|
|
||||||
});
|
});
|
||||||
DEFPRINT(AST_ObjectSetter, function(self, output){
|
DEFPRINT(AST_ObjectSetter, function(self, output){
|
||||||
self._print_getter_setter("set", output);
|
self._print_getter_setter("set", output);
|
||||||
@@ -1679,23 +1380,14 @@ function OutputStream(options) {
|
|||||||
DEFPRINT(AST_ObjectGetter, function(self, output){
|
DEFPRINT(AST_ObjectGetter, function(self, output){
|
||||||
self._print_getter_setter("get", output);
|
self._print_getter_setter("get", output);
|
||||||
});
|
});
|
||||||
DEFPRINT(AST_ConciseMethod, function(self, output){
|
DEFPRINT(AST_Symbol, function(self, output){
|
||||||
self._print_getter_setter(self.is_generator && "*" || self.async && "async", output);
|
var def = self.definition();
|
||||||
});
|
output.print_name(def ? def.mangled_name || def.name : self.name);
|
||||||
AST_Symbol.DEFMETHOD("_do_print", function(output){
|
|
||||||
var def = this.definition();
|
|
||||||
output.print_name(def ? def.mangled_name || def.name : this.name);
|
|
||||||
});
|
|
||||||
DEFPRINT(AST_Symbol, 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");
|
||||||
});
|
});
|
||||||
DEFPRINT(AST_Super, function(self, output){
|
|
||||||
output.print("super");
|
|
||||||
});
|
|
||||||
DEFPRINT(AST_Constant, function(self, output){
|
DEFPRINT(AST_Constant, function(self, output){
|
||||||
output.print(self.getValue());
|
output.print(self.getValue());
|
||||||
});
|
});
|
||||||
|
|||||||
1691
lib/parse.js
1691
lib/parse.js
File diff suppressed because one or more lines are too long
@@ -44,16 +44,6 @@
|
|||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
function find_builtins(reserved) {
|
function find_builtins(reserved) {
|
||||||
|
|
||||||
// Compatibility fix for some standard defined globals not defined on every js environment
|
|
||||||
var new_globals = ["Symbol", "Map", "Promise", "Proxy", "Reflect", "Set", "WeakMap", "WeakSet"];
|
|
||||||
var objects = {};
|
|
||||||
var global_ref = typeof global === "object" ? global : self;
|
|
||||||
|
|
||||||
new_globals.forEach(function (new_global) {
|
|
||||||
objects[new_global] = global_ref[new_global] || new Function();
|
|
||||||
});
|
|
||||||
|
|
||||||
// NaN will be included due to Number.NaN
|
// NaN will be included due to Number.NaN
|
||||||
[
|
[
|
||||||
"null",
|
"null",
|
||||||
@@ -65,15 +55,7 @@ function find_builtins(reserved) {
|
|||||||
].forEach(add);
|
].forEach(add);
|
||||||
[ Object, Array, Function, Number,
|
[ Object, Array, Function, Number,
|
||||||
String, Boolean, Error, Math,
|
String, Boolean, Error, Math,
|
||||||
Date, RegExp, objects.Symbol, ArrayBuffer,
|
Date, RegExp
|
||||||
DataView, decodeURI, decodeURIComponent,
|
|
||||||
encodeURI, encodeURIComponent, eval, EvalError,
|
|
||||||
Float32Array, Float64Array, Int8Array, Int16Array,
|
|
||||||
Int32Array, isFinite, isNaN, JSON, objects.Map, parseFloat,
|
|
||||||
parseInt, objects.Promise, objects.Proxy, RangeError, ReferenceError,
|
|
||||||
objects.Reflect, objects.Set, SyntaxError, TypeError, Uint8Array,
|
|
||||||
Uint8ClampedArray, Uint16Array, Uint32Array, URIError,
|
|
||||||
objects.WeakMap, objects.WeakSet
|
|
||||||
].forEach(function(ctor){
|
].forEach(function(ctor){
|
||||||
Object.getOwnPropertyNames(ctor).map(add);
|
Object.getOwnPropertyNames(ctor).map(add);
|
||||||
if (ctor.prototype) {
|
if (ctor.prototype) {
|
||||||
@@ -93,8 +75,6 @@ function reserve_quoted_keys(ast, reserved) {
|
|||||||
ast.walk(new TreeWalker(function(node) {
|
ast.walk(new TreeWalker(function(node) {
|
||||||
if (node instanceof AST_ObjectKeyVal && node.quote) {
|
if (node instanceof AST_ObjectKeyVal && node.quote) {
|
||||||
add(node.key);
|
add(node.key);
|
||||||
} else if (node instanceof AST_ObjectProperty && node.quote) {
|
|
||||||
add(node.key.name);
|
|
||||||
} else if (node instanceof AST_Sub) {
|
} else if (node instanceof AST_Sub) {
|
||||||
addStrings(node.property, add);
|
addStrings(node.property, add);
|
||||||
}
|
}
|
||||||
@@ -130,12 +110,15 @@ function mangle_properties(ast, options) {
|
|||||||
if (!Array.isArray(reserved)) reserved = [];
|
if (!Array.isArray(reserved)) reserved = [];
|
||||||
if (!options.builtins) find_builtins(reserved);
|
if (!options.builtins) find_builtins(reserved);
|
||||||
|
|
||||||
var cache = options.cache;
|
var cname = -1;
|
||||||
if (cache == null) {
|
var cache;
|
||||||
cache = {
|
if (options.cache) {
|
||||||
cname: -1,
|
cache = options.cache.props;
|
||||||
props: new Dictionary()
|
cache.each(function(mangled_name) {
|
||||||
};
|
push_uniq(reserved, mangled_name);
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
cache = new Dictionary();
|
||||||
}
|
}
|
||||||
|
|
||||||
var regex = options.regex;
|
var regex = options.regex;
|
||||||
@@ -192,7 +175,7 @@ function mangle_properties(ast, options) {
|
|||||||
if (unmangleable.indexOf(name) >= 0) return false;
|
if (unmangleable.indexOf(name) >= 0) return false;
|
||||||
if (reserved.indexOf(name) >= 0) return false;
|
if (reserved.indexOf(name) >= 0) return false;
|
||||||
if (options.only_cache) {
|
if (options.only_cache) {
|
||||||
return cache.props.has(name);
|
return cache.has(name);
|
||||||
}
|
}
|
||||||
if (/^-?[0-9]+(\.[0-9]+)?(e[+-][0-9]+)?$/.test(name)) return false;
|
if (/^-?[0-9]+(\.[0-9]+)?(e[+-][0-9]+)?$/.test(name)) return false;
|
||||||
return true;
|
return true;
|
||||||
@@ -201,7 +184,7 @@ function mangle_properties(ast, options) {
|
|||||||
function should_mangle(name) {
|
function should_mangle(name) {
|
||||||
if (regex && !regex.test(name)) return false;
|
if (regex && !regex.test(name)) return false;
|
||||||
if (reserved.indexOf(name) >= 0) return false;
|
if (reserved.indexOf(name) >= 0) return false;
|
||||||
return cache.props.has(name)
|
return cache.has(name)
|
||||||
|| names_to_mangle.indexOf(name) >= 0;
|
|| names_to_mangle.indexOf(name) >= 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -219,7 +202,7 @@ function mangle_properties(ast, options) {
|
|||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
|
|
||||||
var mangled = cache.props.get(name);
|
var mangled = cache.get(name);
|
||||||
if (!mangled) {
|
if (!mangled) {
|
||||||
if (debug) {
|
if (debug) {
|
||||||
// debug mode: use a prefix and suffix to preserve readability, e.g. o.foo -> o._$foo$NNN_.
|
// debug mode: use a prefix and suffix to preserve readability, e.g. o.foo -> o._$foo$NNN_.
|
||||||
@@ -233,11 +216,11 @@ function mangle_properties(ast, options) {
|
|||||||
// either debug mode is off, or it is on and we could not use the mangled name
|
// either debug mode is off, or it is on and we could not use the mangled name
|
||||||
if (!mangled) {
|
if (!mangled) {
|
||||||
do {
|
do {
|
||||||
mangled = base54(++cache.cname);
|
mangled = base54(++cname);
|
||||||
} while (!can_mangle(mangled));
|
} while (!can_mangle(mangled));
|
||||||
}
|
}
|
||||||
|
|
||||||
cache.props.set(name, mangled);
|
cache.set(name, mangled);
|
||||||
}
|
}
|
||||||
return mangled;
|
return mangled;
|
||||||
}
|
}
|
||||||
|
|||||||
231
lib/scope.js
231
lib/scope.js
@@ -43,15 +43,15 @@
|
|||||||
|
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
function SymbolDef(scope, orig) {
|
function SymbolDef(scope, orig, init) {
|
||||||
this.name = orig.name;
|
this.name = orig.name;
|
||||||
this.orig = [ orig ];
|
this.orig = [ orig ];
|
||||||
|
this.init = init;
|
||||||
this.eliminated = 0;
|
this.eliminated = 0;
|
||||||
this.scope = scope;
|
this.scope = scope;
|
||||||
this.references = [];
|
this.references = [];
|
||||||
this.replaced = 0;
|
this.replaced = 0;
|
||||||
this.global = false;
|
this.global = false;
|
||||||
this.export = false;
|
|
||||||
this.mangled_name = null;
|
this.mangled_name = null;
|
||||||
this.undeclared = false;
|
this.undeclared = false;
|
||||||
this.id = SymbolDef.next_id++;
|
this.id = SymbolDef.next_id++;
|
||||||
@@ -64,16 +64,11 @@ SymbolDef.prototype = {
|
|||||||
if (!options) options = {};
|
if (!options) options = {};
|
||||||
|
|
||||||
return (this.global && !options.toplevel)
|
return (this.global && !options.toplevel)
|
||||||
|| this.export
|
|
||||||
|| this.undeclared
|
|| this.undeclared
|
||||||
|| (!options.eval && (this.scope.uses_eval || this.scope.uses_with))
|
|| (!options.eval && (this.scope.uses_eval || this.scope.uses_with))
|
||||||
|| (options.keep_fnames
|
|| (options.keep_fnames
|
||||||
&& (this.orig[0] instanceof AST_SymbolLambda
|
&& (this.orig[0] instanceof AST_SymbolLambda
|
||||||
|| this.orig[0] instanceof AST_SymbolDefun))
|
|| this.orig[0] instanceof AST_SymbolDefun));
|
||||||
|| this.orig[0] instanceof AST_SymbolMethod
|
|
||||||
|| (options.keep_classnames
|
|
||||||
&& (this.orig[0] instanceof AST_SymbolClass
|
|
||||||
|| this.orig[0] instanceof AST_SymbolDefClass));
|
|
||||||
},
|
},
|
||||||
mangle: function(options) {
|
mangle: function(options) {
|
||||||
var cache = options.cache && options.cache.props;
|
var cache = options.cache && options.cache.props;
|
||||||
@@ -104,7 +99,6 @@ AST_Toplevel.DEFMETHOD("figure_out_scope", function(options){
|
|||||||
options = defaults(options, {
|
options = defaults(options, {
|
||||||
cache: null,
|
cache: null,
|
||||||
ie8: false,
|
ie8: false,
|
||||||
safari10: false,
|
|
||||||
});
|
});
|
||||||
|
|
||||||
// pass 1: setup scope chaining and handle definitions
|
// pass 1: setup scope chaining and handle definitions
|
||||||
@@ -112,33 +106,15 @@ AST_Toplevel.DEFMETHOD("figure_out_scope", function(options){
|
|||||||
var scope = self.parent_scope = null;
|
var scope = self.parent_scope = null;
|
||||||
var labels = new Dictionary();
|
var labels = new Dictionary();
|
||||||
var defun = null;
|
var defun = null;
|
||||||
var in_destructuring = null;
|
|
||||||
var for_scopes = [];
|
|
||||||
var tw = new TreeWalker(function(node, descend){
|
var tw = new TreeWalker(function(node, descend){
|
||||||
if (node.is_block_scope()) {
|
if (node instanceof AST_Catch) {
|
||||||
var save_scope = scope;
|
var save_scope = scope;
|
||||||
node.block_scope = scope = new AST_Scope(node);
|
scope = new AST_Scope(node);
|
||||||
scope.init_scope_vars(save_scope);
|
scope.init_scope_vars(save_scope);
|
||||||
if (!(node instanceof AST_Scope)) {
|
|
||||||
scope.uses_with = save_scope.uses_with;
|
|
||||||
scope.uses_eval = save_scope.uses_eval;
|
|
||||||
scope.directives = save_scope.directives;
|
|
||||||
}
|
|
||||||
if (options.safari10) {
|
|
||||||
if (node instanceof AST_For || node instanceof AST_ForIn) {
|
|
||||||
for_scopes.push(scope);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
descend();
|
descend();
|
||||||
scope = save_scope;
|
scope = save_scope;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (node instanceof AST_Destructuring) {
|
|
||||||
in_destructuring = node; // These don't nest
|
|
||||||
descend();
|
|
||||||
in_destructuring = null;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
if (node instanceof AST_Scope) {
|
if (node instanceof AST_Scope) {
|
||||||
node.init_scope_vars(scope);
|
node.init_scope_vars(scope);
|
||||||
var save_scope = scope;
|
var save_scope = scope;
|
||||||
@@ -175,7 +151,7 @@ AST_Toplevel.DEFMETHOD("figure_out_scope", function(options){
|
|||||||
node.references = [];
|
node.references = [];
|
||||||
}
|
}
|
||||||
if (node instanceof AST_SymbolLambda) {
|
if (node instanceof AST_SymbolLambda) {
|
||||||
defun.def_function(node);
|
defun.def_function(node, node.name == "arguments" ? undefined : defun);
|
||||||
}
|
}
|
||||||
else if (node instanceof AST_SymbolDefun) {
|
else if (node instanceof AST_SymbolDefun) {
|
||||||
// Careful here, the scope where this should be defined is
|
// Careful here, the scope where this should be defined is
|
||||||
@@ -183,40 +159,10 @@ AST_Toplevel.DEFMETHOD("figure_out_scope", function(options){
|
|||||||
// scope when we encounter the AST_Defun node (which is
|
// scope when we encounter the AST_Defun node (which is
|
||||||
// instanceof AST_Scope) but we get to the symbol a bit
|
// instanceof AST_Scope) but we get to the symbol a bit
|
||||||
// later.
|
// later.
|
||||||
mark_export((node.scope = defun.parent_scope.get_defun_scope()).def_function(node), 1);
|
(node.scope = defun.parent_scope).def_function(node, defun);
|
||||||
}
|
}
|
||||||
else if (node instanceof AST_SymbolClass) {
|
else if (node instanceof AST_SymbolVar) {
|
||||||
mark_export(defun.def_variable(node), 1);
|
defun.def_variable(node, node.TYPE == "SymbolVar" ? null : undefined);
|
||||||
}
|
|
||||||
else if (node instanceof AST_SymbolImport) {
|
|
||||||
scope.def_variable(node);
|
|
||||||
}
|
|
||||||
else if (node instanceof AST_SymbolDefClass) {
|
|
||||||
// This deals with the name of the class being available
|
|
||||||
// inside the class.
|
|
||||||
mark_export((node.scope = defun.parent_scope).def_function(node), 1);
|
|
||||||
}
|
|
||||||
else if (node instanceof AST_SymbolVar
|
|
||||||
|| node instanceof AST_SymbolLet
|
|
||||||
|| node instanceof AST_SymbolConst) {
|
|
||||||
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);
|
|
||||||
def.destructuring = in_destructuring;
|
|
||||||
if (defun !== scope) {
|
if (defun !== scope) {
|
||||||
node.mark_enclosed(options);
|
node.mark_enclosed(options);
|
||||||
var def = scope.find_variable(node);
|
var def = scope.find_variable(node);
|
||||||
@@ -238,26 +184,6 @@ AST_Toplevel.DEFMETHOD("figure_out_scope", function(options){
|
|||||||
}));
|
}));
|
||||||
node.thedef = sym;
|
node.thedef = sym;
|
||||||
}
|
}
|
||||||
if (!(scope instanceof AST_Toplevel) && (node instanceof AST_Export || node instanceof AST_Import)) {
|
|
||||||
js_error(
|
|
||||||
node.TYPE + " statement may only appear at top level",
|
|
||||||
node.start.file,
|
|
||||||
node.start.line,
|
|
||||||
node.start.col,
|
|
||||||
node.start.pos
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
function mark_export(def, level) {
|
|
||||||
if (in_destructuring) {
|
|
||||||
var i = 0;
|
|
||||||
do {
|
|
||||||
level++;
|
|
||||||
} while (tw.parent(i++) !== in_destructuring);
|
|
||||||
}
|
|
||||||
var node = tw.parent(level);
|
|
||||||
def.export = node instanceof AST_Export;
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
self.walk(tw);
|
self.walk(tw);
|
||||||
|
|
||||||
@@ -275,9 +201,8 @@ AST_Toplevel.DEFMETHOD("figure_out_scope", function(options){
|
|||||||
s.uses_eval = true;
|
s.uses_eval = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
var sym;
|
var sym = node.scope.find_variable(name);
|
||||||
if (tw.parent() instanceof AST_NameMapping && tw.parent(1).module_name
|
if (!sym) {
|
||||||
|| !(sym = node.scope.find_variable(name))) {
|
|
||||||
sym = self.def_global(node);
|
sym = self.def_global(node);
|
||||||
} else if (sym.scope instanceof AST_Lambda && name == "arguments") {
|
} else if (sym.scope instanceof AST_Lambda && name == "arguments") {
|
||||||
sym.scope.uses_arguments = true;
|
sym.scope.uses_arguments = true;
|
||||||
@@ -317,23 +242,6 @@ AST_Toplevel.DEFMETHOD("figure_out_scope", function(options){
|
|||||||
}
|
}
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
// pass 4: add symbol definitions to loop scopes
|
|
||||||
// Safari/Webkit bug workaround - loop init let variable shadowing argument.
|
|
||||||
// https://github.com/mishoo/UglifyJS2/issues/1753
|
|
||||||
// https://bugs.webkit.org/show_bug.cgi?id=171041
|
|
||||||
if (options.safari10) {
|
|
||||||
for (var i = 0; i < for_scopes.length; i++) {
|
|
||||||
var scope = for_scopes[i];
|
|
||||||
scope.parent_scope.variables.each(function(def) {
|
|
||||||
push_uniq(scope.enclosed, def);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (options.cache) {
|
|
||||||
this.cname = options.cache.cname;
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
AST_Toplevel.DEFMETHOD("def_global", function(node){
|
AST_Toplevel.DEFMETHOD("def_global", function(node){
|
||||||
@@ -359,14 +267,6 @@ AST_Scope.DEFMETHOD("init_scope_vars", function(parent_scope){
|
|||||||
this.cname = -1; // the current index for mangling functions/variables
|
this.cname = -1; // the current index for mangling functions/variables
|
||||||
});
|
});
|
||||||
|
|
||||||
AST_Node.DEFMETHOD("is_block_scope", return_false);
|
|
||||||
AST_Class.DEFMETHOD("is_block_scope", return_false);
|
|
||||||
AST_Lambda.DEFMETHOD("is_block_scope", return_false);
|
|
||||||
AST_Toplevel.DEFMETHOD("is_block_scope", return_false);
|
|
||||||
AST_SwitchBranch.DEFMETHOD("is_block_scope", return_false);
|
|
||||||
AST_Block.DEFMETHOD("is_block_scope", return_true);
|
|
||||||
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;
|
||||||
@@ -403,29 +303,32 @@ AST_Scope.DEFMETHOD("find_variable", function(name){
|
|||||||
|| (this.parent_scope && this.parent_scope.find_variable(name));
|
|| (this.parent_scope && this.parent_scope.find_variable(name));
|
||||||
});
|
});
|
||||||
|
|
||||||
AST_Scope.DEFMETHOD("def_function", function(symbol){
|
AST_Scope.DEFMETHOD("def_function", function(symbol, init){
|
||||||
var def = this.def_variable(symbol);
|
var def = this.def_variable(symbol, init);
|
||||||
|
if (!def.init || def.init instanceof AST_Defun) def.init = init;
|
||||||
this.functions.set(symbol.name, def);
|
this.functions.set(symbol.name, def);
|
||||||
return def;
|
return def;
|
||||||
});
|
});
|
||||||
|
|
||||||
AST_Scope.DEFMETHOD("def_variable", function(symbol){
|
AST_Scope.DEFMETHOD("def_variable", function(symbol, init){
|
||||||
var def;
|
var def = this.variables.get(symbol.name);
|
||||||
if (!this.variables.has(symbol.name)) {
|
if (def) {
|
||||||
def = new SymbolDef(this, symbol);
|
def.orig.push(symbol);
|
||||||
|
if (def.init && (def.scope !== symbol.scope || def.init instanceof AST_Function)) {
|
||||||
|
def.init = init;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
def = new SymbolDef(this, symbol, init);
|
||||||
this.variables.set(symbol.name, def);
|
this.variables.set(symbol.name, def);
|
||||||
def.global = !this.parent_scope;
|
def.global = !this.parent_scope;
|
||||||
} else {
|
|
||||||
def = this.variables.get(symbol.name);
|
|
||||||
def.orig.push(symbol);
|
|
||||||
}
|
}
|
||||||
return symbol.thedef = def;
|
return symbol.thedef = def;
|
||||||
});
|
});
|
||||||
|
|
||||||
AST_Scope.DEFMETHOD("next_mangled", function(options){
|
function next_mangled(scope, options) {
|
||||||
var ext = this.enclosed;
|
var ext = scope.enclosed;
|
||||||
out: while (true) {
|
out: while (true) {
|
||||||
var m = base54(++this.cname);
|
var m = base54(++scope.cname);
|
||||||
if (!is_identifier(m)) continue; // skip over "do"
|
if (!is_identifier(m)) continue; // skip over "do"
|
||||||
|
|
||||||
// https://github.com/mishoo/UglifyJS2/issues/242 -- do not
|
// https://github.com/mishoo/UglifyJS2/issues/242 -- do not
|
||||||
@@ -442,6 +345,18 @@ AST_Scope.DEFMETHOD("next_mangled", function(options){
|
|||||||
}
|
}
|
||||||
return m;
|
return m;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
AST_Scope.DEFMETHOD("next_mangled", function(options){
|
||||||
|
return next_mangled(this, options);
|
||||||
|
});
|
||||||
|
|
||||||
|
AST_Toplevel.DEFMETHOD("next_mangled", function(options){
|
||||||
|
var name;
|
||||||
|
do {
|
||||||
|
name = next_mangled(this, options);
|
||||||
|
} while (member(name, this.mangled_names));
|
||||||
|
return name;
|
||||||
});
|
});
|
||||||
|
|
||||||
AST_Function.DEFMETHOD("next_mangled", function(options, def){
|
AST_Function.DEFMETHOD("next_mangled", function(options, def){
|
||||||
@@ -455,7 +370,7 @@ AST_Function.DEFMETHOD("next_mangled", function(options, def){
|
|||||||
var tricky_name = tricky_def ? tricky_def.mangled_name || tricky_def.name : null;
|
var tricky_name = tricky_def ? tricky_def.mangled_name || tricky_def.name : null;
|
||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
var name = AST_Lambda.prototype.next_mangled.call(this, options, def);
|
var name = next_mangled(this, options);
|
||||||
if (!tricky_name || tricky_name != name)
|
if (!tricky_name || tricky_name != name)
|
||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
@@ -486,7 +401,6 @@ AST_Toplevel.DEFMETHOD("_default_mangler_options", function(options) {
|
|||||||
options = defaults(options, {
|
options = defaults(options, {
|
||||||
eval : false,
|
eval : false,
|
||||||
ie8 : false,
|
ie8 : false,
|
||||||
keep_classnames: false,
|
|
||||||
keep_fnames : false,
|
keep_fnames : false,
|
||||||
reserved : [],
|
reserved : [],
|
||||||
toplevel : false,
|
toplevel : false,
|
||||||
@@ -507,8 +421,14 @@ AST_Toplevel.DEFMETHOD("mangle_names", function(options){
|
|||||||
var lname = -1;
|
var lname = -1;
|
||||||
var to_mangle = [];
|
var to_mangle = [];
|
||||||
|
|
||||||
|
var mangled_names = this.mangled_names = [];
|
||||||
if (options.cache) {
|
if (options.cache) {
|
||||||
this.globals.each(collect);
|
this.globals.each(collect);
|
||||||
|
if (options.cache.props) {
|
||||||
|
options.cache.props.each(function(mangled_name) {
|
||||||
|
push_uniq(mangled_names, mangled_name);
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var tw = new TreeWalker(function(node, descend){
|
var tw = new TreeWalker(function(node, descend){
|
||||||
@@ -529,22 +449,13 @@ AST_Toplevel.DEFMETHOD("mangle_names", function(options){
|
|||||||
node.mangled_name = name;
|
node.mangled_name = name;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
var mangle_with_block_scope =
|
if (!options.ie8 && node instanceof AST_SymbolCatch) {
|
||||||
(!options.ie8 && node instanceof AST_SymbolCatch) ||
|
|
||||||
node instanceof AST_SymbolBlockDeclaration;
|
|
||||||
if (mangle_with_block_scope && options.reserved.indexOf(node.name) < 0) {
|
|
||||||
to_mangle.push(node.definition());
|
to_mangle.push(node.definition());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
this.walk(tw);
|
this.walk(tw);
|
||||||
to_mangle.forEach(function(def){
|
to_mangle.forEach(function(def){ def.mangle(options) });
|
||||||
def.mangle(options);
|
|
||||||
});
|
|
||||||
|
|
||||||
if (options.cache) {
|
|
||||||
options.cache.cname = this.cname;
|
|
||||||
}
|
|
||||||
|
|
||||||
function collect(symbol) {
|
function collect(symbol) {
|
||||||
if (!member(symbol.name, options.reserved)) {
|
if (!member(symbol.name, options.reserved)) {
|
||||||
@@ -553,59 +464,55 @@ AST_Toplevel.DEFMETHOD("mangle_names", function(options){
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
AST_Toplevel.DEFMETHOD("find_unique_prefix", function(options) {
|
AST_Toplevel.DEFMETHOD("find_colliding_names", function(options) {
|
||||||
var letters = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ$_";
|
|
||||||
var cache = options.cache && options.cache.props;
|
var cache = options.cache && options.cache.props;
|
||||||
var prefixes = Object.create(null);
|
var avoid = Object.create(null);
|
||||||
options.reserved.forEach(add_prefix);
|
options.reserved.forEach(to_avoid);
|
||||||
this.globals.each(add_def);
|
this.globals.each(add_def);
|
||||||
this.walk(new TreeWalker(function(node) {
|
this.walk(new TreeWalker(function(node) {
|
||||||
if (node instanceof AST_Scope) node.variables.each(add_def);
|
if (node instanceof AST_Scope) node.variables.each(add_def);
|
||||||
if (node instanceof AST_SymbolCatch) add_def(node.definition());
|
if (node instanceof AST_SymbolCatch) add_def(node.definition());
|
||||||
}));
|
}));
|
||||||
var prefix, i = 0;
|
return avoid;
|
||||||
do {
|
|
||||||
prefix = create_name(i++);
|
|
||||||
} while (prefixes[prefix]);
|
|
||||||
return prefix;
|
|
||||||
|
|
||||||
function add_prefix(name) {
|
function to_avoid(name) {
|
||||||
if (/[0-9]$/.test(name)) {
|
avoid[name] = true;
|
||||||
prefixes[name.replace(/[0-9]+$/, "")] = true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function add_def(def) {
|
function add_def(def) {
|
||||||
var name = def.name;
|
var name = def.name;
|
||||||
if (def.global && cache && cache.has(name)) name = cache.get(name);
|
if (def.global && cache && cache.has(name)) name = cache.get(name);
|
||||||
else if (!def.unmangleable(options)) return;
|
else if (!def.unmangleable(options)) return;
|
||||||
add_prefix(name);
|
to_avoid(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) {
|
AST_Toplevel.DEFMETHOD("expand_names", function(options) {
|
||||||
|
base54.reset();
|
||||||
|
base54.sort();
|
||||||
options = this._default_mangler_options(options);
|
options = this._default_mangler_options(options);
|
||||||
var prefix = this.find_unique_prefix(options);
|
var avoid = this.find_colliding_names(options);
|
||||||
|
var cname = 0;
|
||||||
this.globals.each(rename);
|
this.globals.each(rename);
|
||||||
this.walk(new TreeWalker(function(node) {
|
this.walk(new TreeWalker(function(node) {
|
||||||
if (node instanceof AST_Scope) node.variables.each(rename);
|
if (node instanceof AST_Scope) node.variables.each(rename);
|
||||||
if (node instanceof AST_SymbolCatch) rename(node.definition());
|
if (node instanceof AST_SymbolCatch) rename(node.definition());
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
function next_name() {
|
||||||
|
var name;
|
||||||
|
do {
|
||||||
|
name = base54(cname++);
|
||||||
|
} while (avoid[name] || !is_identifier(name));
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
function rename(def) {
|
function rename(def) {
|
||||||
if (def.global || def.unmangleable(options)) return;
|
if (def.global && options.cache) return;
|
||||||
|
if (def.unmangleable(options)) return;
|
||||||
if (member(def.name, options.reserved)) return;
|
if (member(def.name, options.reserved)) return;
|
||||||
var d = def.redefined();
|
var d = def.redefined();
|
||||||
def.name = d ? d.name : prefix + def.id;
|
def.name = d ? d.name : next_name();
|
||||||
def.orig.forEach(function(sym) {
|
def.orig.forEach(function(sym) {
|
||||||
sym.name = def.name;
|
sym.name = def.name;
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -60,12 +60,9 @@ TreeTransformer.prototype = new TreeWalker;
|
|||||||
tw.push(this);
|
tw.push(this);
|
||||||
if (tw.before) x = tw.before(this, descend, in_list);
|
if (tw.before) x = tw.before(this, descend, in_list);
|
||||||
if (x === undefined) {
|
if (x === undefined) {
|
||||||
if (!tw.after) {
|
x = this;
|
||||||
x = this;
|
descend(x, tw);
|
||||||
descend(x, tw);
|
if (tw.after) {
|
||||||
} else {
|
|
||||||
tw.stack[tw.stack.length - 1] = x = this;
|
|
||||||
descend(x, tw);
|
|
||||||
y = tw.after(x, in_list);
|
y = tw.after(x, in_list);
|
||||||
if (y !== undefined) x = y;
|
if (y !== undefined) x = y;
|
||||||
}
|
}
|
||||||
@@ -163,18 +160,10 @@ TreeTransformer.prototype = new TreeWalker;
|
|||||||
if (self.value) self.value = self.value.transform(tw);
|
if (self.value) self.value = self.value.transform(tw);
|
||||||
});
|
});
|
||||||
|
|
||||||
_(AST_Destructuring, function(self, tw) {
|
|
||||||
self.names = do_list(self.names, tw);
|
|
||||||
});
|
|
||||||
|
|
||||||
_(AST_Lambda, function(self, tw){
|
_(AST_Lambda, function(self, tw){
|
||||||
if (self.name) self.name = self.name.transform(tw);
|
if (self.name) self.name = self.name.transform(tw);
|
||||||
self.argnames = do_list(self.argnames, tw);
|
self.argnames = do_list(self.argnames, tw);
|
||||||
if (self.body instanceof AST_Node) {
|
self.body = do_list(self.body, tw);
|
||||||
self.body = self.body.transform(tw);
|
|
||||||
} else {
|
|
||||||
self.body = do_list(self.body, tw);
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
_(AST_Call, function(self, tw){
|
_(AST_Call, function(self, tw){
|
||||||
@@ -195,14 +184,6 @@ TreeTransformer.prototype = new TreeWalker;
|
|||||||
self.property = self.property.transform(tw);
|
self.property = self.property.transform(tw);
|
||||||
});
|
});
|
||||||
|
|
||||||
_(AST_Yield, function(self, tw){
|
|
||||||
if (self.expression) self.expression = self.expression.transform(tw);
|
|
||||||
});
|
|
||||||
|
|
||||||
_(AST_Await, function(self, tw){
|
|
||||||
self.expression = self.expression.transform(tw);
|
|
||||||
});
|
|
||||||
|
|
||||||
_(AST_Unary, function(self, tw){
|
_(AST_Unary, function(self, tw){
|
||||||
self.expression = self.expression.transform(tw);
|
self.expression = self.expression.transform(tw);
|
||||||
});
|
});
|
||||||
@@ -227,46 +208,7 @@ TreeTransformer.prototype = new TreeWalker;
|
|||||||
});
|
});
|
||||||
|
|
||||||
_(AST_ObjectProperty, function(self, tw){
|
_(AST_ObjectProperty, function(self, tw){
|
||||||
if (self.key instanceof AST_Node) {
|
|
||||||
self.key = self.key.transform(tw);
|
|
||||||
}
|
|
||||||
self.value = self.value.transform(tw);
|
self.value = self.value.transform(tw);
|
||||||
});
|
});
|
||||||
|
|
||||||
_(AST_Class, function(self, tw){
|
|
||||||
if (self.name) self.name = self.name.transform(tw);
|
|
||||||
if (self.extends) self.extends = self.extends.transform(tw);
|
|
||||||
self.properties = do_list(self.properties, tw);
|
|
||||||
});
|
|
||||||
|
|
||||||
_(AST_Expansion, function(self, tw){
|
|
||||||
self.expression = self.expression.transform(tw);
|
|
||||||
});
|
|
||||||
|
|
||||||
_(AST_NameMapping, function(self, tw) {
|
|
||||||
self.foreign_name = self.foreign_name.transform(tw);
|
|
||||||
self.name = self.name.transform(tw);
|
|
||||||
});
|
|
||||||
|
|
||||||
_(AST_Import, function(self, tw) {
|
|
||||||
if (self.imported_name) self.imported_name = self.imported_name.transform(tw);
|
|
||||||
if (self.imported_names) do_list(self.imported_names, tw);
|
|
||||||
self.module_name = self.module_name.transform(tw);
|
|
||||||
});
|
|
||||||
|
|
||||||
_(AST_Export, function(self, tw) {
|
|
||||||
if (self.exported_definition) self.exported_definition = self.exported_definition.transform(tw);
|
|
||||||
if (self.exported_value) self.exported_value = self.exported_value.transform(tw);
|
|
||||||
if (self.exported_names) do_list(self.exported_names, tw);
|
|
||||||
if (self.module_name) self.module_name = self.module_name.transform(tw);
|
|
||||||
});
|
|
||||||
|
|
||||||
_(AST_TemplateString, function(self, tw) {
|
|
||||||
self.segments = do_list(self.segments, tw);
|
|
||||||
});
|
|
||||||
|
|
||||||
_(AST_PrefixedTemplateString, function(self, tw) {
|
|
||||||
self.template_string = self.template_string.transform(tw);
|
|
||||||
});
|
|
||||||
|
|
||||||
})();
|
})();
|
||||||
|
|||||||
25
lib/utils.js
25
lib/utils.js
@@ -43,10 +43,6 @@
|
|||||||
|
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
function slice(a, start) {
|
|
||||||
return Array.prototype.slice.call(a, start || 0);
|
|
||||||
};
|
|
||||||
|
|
||||||
function characters(str) {
|
function characters(str) {
|
||||||
return str.split("");
|
return str.split("");
|
||||||
};
|
};
|
||||||
@@ -214,18 +210,6 @@ function mergeSort(array, cmp) {
|
|||||||
return _ms(array);
|
return _ms(array);
|
||||||
};
|
};
|
||||||
|
|
||||||
function set_difference(a, b) {
|
|
||||||
return a.filter(function(el){
|
|
||||||
return b.indexOf(el) < 0;
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
function set_intersection(a, b) {
|
|
||||||
return a.filter(function(el){
|
|
||||||
return b.indexOf(el) >= 0;
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
// this function is taken from Acorn [1], written by Marijn Haverbeke
|
// this function is taken from Acorn [1], written by Marijn Haverbeke
|
||||||
// [1] https://github.com/marijnh/acorn
|
// [1] https://github.com/marijnh/acorn
|
||||||
function makePredicate(words) {
|
function makePredicate(words) {
|
||||||
@@ -319,6 +303,13 @@ Dictionary.prototype = {
|
|||||||
ret.push(f(this._values[i], i.substr(1)));
|
ret.push(f(this._values[i], i.substr(1)));
|
||||||
return ret;
|
return ret;
|
||||||
},
|
},
|
||||||
|
clone: function() {
|
||||||
|
var ret = new Dictionary();
|
||||||
|
for (var i in this._values)
|
||||||
|
ret._values[i] = this._values[i];
|
||||||
|
ret._size = this._size;
|
||||||
|
return ret;
|
||||||
|
},
|
||||||
toObject: function() { return this._values }
|
toObject: function() { return this._values }
|
||||||
};
|
};
|
||||||
Dictionary.fromObject = function(obj) {
|
Dictionary.fromObject = function(obj) {
|
||||||
@@ -340,7 +331,7 @@ function first_in_statement(stack) {
|
|||||||
if (p instanceof AST_Statement && p.body === node)
|
if (p instanceof AST_Statement && p.body === node)
|
||||||
return true;
|
return true;
|
||||||
if ((p instanceof AST_Sequence && p.expressions[0] === node) ||
|
if ((p instanceof AST_Sequence && p.expressions[0] === node) ||
|
||||||
(p instanceof AST_Call && p.expression === node && !(p instanceof AST_New) ) ||
|
(p.TYPE == "Call" && p.expression === node ) ||
|
||||||
(p instanceof AST_Dot && p.expression === node ) ||
|
(p instanceof AST_Dot && p.expression === node ) ||
|
||||||
(p instanceof AST_Sub && p.expression === node ) ||
|
(p instanceof AST_Sub && p.expression === node ) ||
|
||||||
(p instanceof AST_Conditional && p.condition === node ) ||
|
(p instanceof AST_Conditional && p.condition === node ) ||
|
||||||
|
|||||||
39
package.json
39
package.json
@@ -1,20 +1,18 @@
|
|||||||
{
|
{
|
||||||
"name": "uglify-es",
|
"name": "uglify-js",
|
||||||
"description": "JavaScript parser, mangler/compressor and beautifier toolkit for ES6+",
|
"description": "JavaScript parser, mangler/compressor and beautifier toolkit",
|
||||||
"homepage": "https://github.com/mishoo/UglifyJS2/tree/harmony",
|
"homepage": "http://lisperator.net/uglifyjs",
|
||||||
"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.2.1",
|
"version": "3.3.10",
|
||||||
"engines": {
|
"engines": {
|
||||||
"node": ">=0.8.0"
|
"node": ">=0.8.0"
|
||||||
},
|
},
|
||||||
"maintainers": [
|
"maintainers": [
|
||||||
|
"Alex Lam <alexlamsl@gmail.com>",
|
||||||
"Mihai Bazon <mihai.bazon@gmail.com> (http://lisperator.net/)"
|
"Mihai Bazon <mihai.bazon@gmail.com> (http://lisperator.net/)"
|
||||||
],
|
],
|
||||||
"repository": "git+https://github.com/mishoo/UglifyJS2.git#harmony",
|
"repository": "mishoo/UglifyJS2",
|
||||||
"bugs": {
|
|
||||||
"url": "https://github.com/mishoo/UglifyJS2/issues"
|
|
||||||
},
|
|
||||||
"main": "tools/node.js",
|
"main": "tools/node.js",
|
||||||
"bin": {
|
"bin": {
|
||||||
"uglifyjs": "bin/uglifyjs"
|
"uglifyjs": "bin/uglifyjs"
|
||||||
@@ -26,33 +24,16 @@
|
|||||||
"LICENSE"
|
"LICENSE"
|
||||||
],
|
],
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"commander": "~2.12.1",
|
"commander": "~2.14.1",
|
||||||
"source-map": "~0.6.1"
|
"source-map": "~0.6.1"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"acorn": "~5.2.1",
|
"acorn": "~5.4.1",
|
||||||
"mocha": "~3.5.1",
|
"mocha": "~3.5.1",
|
||||||
"semver": "~5.4.1"
|
"semver": "~5.5.0"
|
||||||
},
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"test": "node test/run-tests.js"
|
"test": "node test/run-tests.js"
|
||||||
},
|
},
|
||||||
"keywords": [
|
"keywords": ["uglify", "uglify-js", "minify", "minifier", "es5"]
|
||||||
"uglify",
|
|
||||||
"uglify-es",
|
|
||||||
"uglify-js",
|
|
||||||
"minify",
|
|
||||||
"minifier",
|
|
||||||
"javascript",
|
|
||||||
"ecmascript",
|
|
||||||
"es5",
|
|
||||||
"es6",
|
|
||||||
"es7",
|
|
||||||
"es8",
|
|
||||||
"es2015",
|
|
||||||
"es2016",
|
|
||||||
"es2017",
|
|
||||||
"async",
|
|
||||||
"await"
|
|
||||||
]
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,6 +21,7 @@ var urls = [
|
|||||||
"http://builds.emberjs.com/tags/v2.11.0/ember.prod.js",
|
"http://builds.emberjs.com/tags/v2.11.0/ember.prod.js",
|
||||||
"https://cdn.jsdelivr.net/lodash/4.17.4/lodash.js",
|
"https://cdn.jsdelivr.net/lodash/4.17.4/lodash.js",
|
||||||
"https://cdnjs.cloudflare.com/ajax/libs/d3/4.5.0/d3.js",
|
"https://cdnjs.cloudflare.com/ajax/libs/d3/4.5.0/d3.js",
|
||||||
|
"https://raw.githubusercontent.com/kangax/html-minifier/v3.5.7/dist/htmlminifier.js",
|
||||||
];
|
];
|
||||||
var results = {};
|
var results = {};
|
||||||
var remaining = 2 * urls.length;
|
var remaining = 2 * urls.length;
|
||||||
|
|||||||
@@ -1,5 +1,3 @@
|
|||||||
// NOTE trailing comma doesn't contribute to length of an array
|
|
||||||
// That also means the array changes length if previous element is a hole too and got cut off
|
|
||||||
holes_and_undefined: {
|
holes_and_undefined: {
|
||||||
input: {
|
input: {
|
||||||
w = [1,,];
|
w = [1,,];
|
||||||
@@ -93,79 +91,6 @@ constant_join_2: {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
spread_with_variable_as_last_element: {
|
|
||||||
input: {
|
|
||||||
var values = [4, 5, 6];
|
|
||||||
var a = [1, 2, 3, ...values];
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
var values = [4, 5, 6];
|
|
||||||
var a = [1, 2, 3, ...values];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
spread_with_variable_in_middle: {
|
|
||||||
input: {
|
|
||||||
var values = [4, 5, 6];
|
|
||||||
var a = [1, 2, 3, ...values, 7,,,];
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
var values = [4, 5, 6];
|
|
||||||
var a = [1, 2, 3, ...values, 7,,,];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
spread_with_variable_at_front: {
|
|
||||||
input: {
|
|
||||||
var values = [1, 2, 3];
|
|
||||||
var a = [...values, 4, 5, 6];
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
var values = [1, 2, 3];
|
|
||||||
var a = [...values, 4, 5, 6];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
spread_with_variable_at_front_after_elisions: {
|
|
||||||
input: {
|
|
||||||
var values = [1, 2, 3];
|
|
||||||
var a = [,,,...values, 4, 5, 6];
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
var values = [1, 2, 3];
|
|
||||||
var a = [,,,...values, 4, 5, 6];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
spread_with_array_at_end: {
|
|
||||||
input: {
|
|
||||||
var a = [1, 2, ...[4, 5, 6]];
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
var a = [1, 2, ...[4, 5, 6]];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
spread_with_logical_expression_at_end: {
|
|
||||||
options = { evaluate: true }
|
|
||||||
input: {
|
|
||||||
var a = [1, 2, 3, ...[2+2]]
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
var a = [1, 2, 3, ...[4]]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
spread_with_logical_expression_at_middle: {
|
|
||||||
options = { evaluate: true }
|
|
||||||
input: {
|
|
||||||
var a = [1, 1, ...[1+1, 1+2, 2+3], 8]
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
var a = [1, 1, ...[2, 3, 5], 8]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
constant_join_3: {
|
constant_join_3: {
|
||||||
options = {
|
options = {
|
||||||
unsafe: true,
|
unsafe: true,
|
||||||
|
|||||||
@@ -1,656 +0,0 @@
|
|||||||
arrow_functions_without_body: {
|
|
||||||
input: {
|
|
||||||
var a1 = () => 42;
|
|
||||||
var a2 = (p) => p;
|
|
||||||
var a3 = p => p;
|
|
||||||
var a4 = (...p) => p;
|
|
||||||
var a5 = (b, c) => b + c;
|
|
||||||
var a6 = (b, ...c) => b + c[0];
|
|
||||||
var a7 = (...b) => b.join();
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
var a1 = () => 42;
|
|
||||||
var a2 = (p) => p;
|
|
||||||
var a3 = p => p;
|
|
||||||
var a4 = (...p) => p;
|
|
||||||
var a5 = (b, c) => b + c;
|
|
||||||
var a6 = (b, ...c) => b + c[0];
|
|
||||||
var a7 = (...b) => b.join();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
arrow_functions_with_body: {
|
|
||||||
input: {
|
|
||||||
var a1 = () => {
|
|
||||||
var a = 42 * Math.random();
|
|
||||||
return a;
|
|
||||||
};
|
|
||||||
var a2 = (p) => {
|
|
||||||
var a = Math.random() * p;
|
|
||||||
return a;
|
|
||||||
};
|
|
||||||
var a3 = p => {
|
|
||||||
var a = Math.random() * p;
|
|
||||||
return a;
|
|
||||||
};
|
|
||||||
var a4 = (...p) => {
|
|
||||||
var a = Math.random() * p;
|
|
||||||
return a;
|
|
||||||
};
|
|
||||||
var a5 = (b, c) => {
|
|
||||||
var result = b * c + b / c;
|
|
||||||
return result
|
|
||||||
};
|
|
||||||
var a6 = (b, ...c) => {
|
|
||||||
var result = b;
|
|
||||||
for (var i = 0; i < c.length; i++)
|
|
||||||
result += c[i];
|
|
||||||
return result
|
|
||||||
};
|
|
||||||
var a7 = (...b) => {
|
|
||||||
b.join();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
var a1 = () => {
|
|
||||||
var a = 42 * Math.random();
|
|
||||||
return a;
|
|
||||||
};
|
|
||||||
var a2 = (p) => {
|
|
||||||
var a = Math.random() * p;
|
|
||||||
return a;
|
|
||||||
};
|
|
||||||
var a3 = p => {
|
|
||||||
var a = Math.random() * p;
|
|
||||||
return a;
|
|
||||||
};
|
|
||||||
var a4 = (...p) => {
|
|
||||||
var a = Math.random() * p;
|
|
||||||
return a;
|
|
||||||
};
|
|
||||||
var a5 = (b, c) => {
|
|
||||||
var result = b * c + b / c;
|
|
||||||
return result
|
|
||||||
};
|
|
||||||
var a6 = (b, ...c) => {
|
|
||||||
var result = b;
|
|
||||||
for (var i = 0; i < c.length; i++)
|
|
||||||
result += c[i];
|
|
||||||
return result
|
|
||||||
};
|
|
||||||
var a7 = (...b) => {
|
|
||||||
b.join();
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
arrow_function_with_single_parameter_with_default: {
|
|
||||||
input: {
|
|
||||||
var foo = (a = 0) => doSomething(a);
|
|
||||||
}
|
|
||||||
expect_exact: "var foo=(a=0)=>doSomething(a);"
|
|
||||||
}
|
|
||||||
|
|
||||||
arrow_binding_pattern: {
|
|
||||||
input: {
|
|
||||||
var foo = ([]) => "foo";
|
|
||||||
var bar = ({}) => "bar";
|
|
||||||
var with_default = (foo = "default") => foo;
|
|
||||||
var object_with_default = ({foo = "default", bar: baz = "default"}) => foo;
|
|
||||||
var array_after_spread = (...[foo]) => foo;
|
|
||||||
var array_after_spread = (...{foo}) => foo;
|
|
||||||
var computed = ({ [compute()]: x }) => {};
|
|
||||||
var array_hole = ([, , ...x] = [1, 2]) => {};
|
|
||||||
var object_trailing_elision = ({foo,}) => {};
|
|
||||||
var spread_empty_array = (...[]) => "foo";
|
|
||||||
var spread_empty_object = (...{}) => "foo";
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
var foo = ([]) => "foo";
|
|
||||||
var bar = ({}) => "bar";
|
|
||||||
var with_default = (foo = "default") => foo;
|
|
||||||
var object_with_default = ({foo = "default", bar: baz = "default"}) => foo;
|
|
||||||
var array_after_spread = (...[foo]) => foo;
|
|
||||||
var array_after_spread = (...{foo}) => foo;
|
|
||||||
var computed = ({ [compute()]: x }) => {};
|
|
||||||
var array_hole = ([, , ...x] = [1, 2]) => {};
|
|
||||||
var object_trailing_elision = ({foo,}) => {};
|
|
||||||
var spread_empty_array = (...[]) => "foo";
|
|
||||||
var spread_empty_object = (...{}) => "foo";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
arrow_binding_pattern_strict: {
|
|
||||||
input: {
|
|
||||||
var foo = ([,]) => "foo";
|
|
||||||
}
|
|
||||||
expect_exact: 'var foo=([,])=>"foo";'
|
|
||||||
}
|
|
||||||
|
|
||||||
arrow_with_regexp: {
|
|
||||||
input: {
|
|
||||||
num => /\d{11,14}/.test( num )
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
num => /\d{11,14}/.test( num )
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
arrow_unused: {
|
|
||||||
options = {
|
|
||||||
toplevel: false,
|
|
||||||
side_effects: true,
|
|
||||||
unused: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
top => dog;
|
|
||||||
let fn = a => { console.log(a * a); };
|
|
||||||
let u = (x, y) => x - y + g;
|
|
||||||
(() => { console.log("0"); })();
|
|
||||||
!function(x) {
|
|
||||||
(() => { console.log("1"); })();
|
|
||||||
let unused = x => { console.log(x); };
|
|
||||||
let baz = e => e + e;
|
|
||||||
console.log(baz(x));
|
|
||||||
}(1);
|
|
||||||
fn(3);
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
let fn = a => { console.log(a * a); };
|
|
||||||
let u = (x, y) => x - y + g;
|
|
||||||
(() => { console.log("0"); })();
|
|
||||||
!function(x) {
|
|
||||||
(() => { console.log("1"); })();
|
|
||||||
let baz = e => e + e;
|
|
||||||
console.log(baz(x));
|
|
||||||
}(1);
|
|
||||||
fn(3);
|
|
||||||
}
|
|
||||||
expect_stdout: [ "0", "1", "2", "9" ]
|
|
||||||
node_version: ">=6"
|
|
||||||
}
|
|
||||||
|
|
||||||
arrow_unused_toplevel: {
|
|
||||||
options = {
|
|
||||||
toplevel: true,
|
|
||||||
side_effects: true,
|
|
||||||
unused: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
top => dog;
|
|
||||||
let fn = a => { console.log(a * a); };
|
|
||||||
let u = (x, y) => x - y + g;
|
|
||||||
(() => { console.log("0"); })();
|
|
||||||
!function(x) {
|
|
||||||
(() => { console.log("1"); })();
|
|
||||||
let unused = x => { console.log(x); };
|
|
||||||
let baz = e => e + e;
|
|
||||||
console.log(baz(x));
|
|
||||||
}(1);
|
|
||||||
fn(3);
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
let fn = a => { console.log(a * a); };
|
|
||||||
(() => { console.log("0"); })();
|
|
||||||
!function(x) {
|
|
||||||
(() => { console.log("1"); })();
|
|
||||||
let baz = e => e + e;
|
|
||||||
console.log(baz(x));
|
|
||||||
}(1);
|
|
||||||
fn(3);
|
|
||||||
}
|
|
||||||
expect_stdout: [ "0", "1", "2", "9" ]
|
|
||||||
node_version: ">=6"
|
|
||||||
}
|
|
||||||
|
|
||||||
no_leading_parentheses: {
|
|
||||||
input: {
|
|
||||||
(x,y) => x(y);
|
|
||||||
async (x,y) => await x(y);
|
|
||||||
}
|
|
||||||
expect_exact: "(x,y)=>x(y);async(x,y)=>await x(y);"
|
|
||||||
}
|
|
||||||
|
|
||||||
async_identifiers: {
|
|
||||||
options = {
|
|
||||||
unsafe_arrows: true,
|
|
||||||
ecma: 6,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
var async = function(x){ console.log("async", x); };
|
|
||||||
var await = function(x){ console.log("await", x); };
|
|
||||||
async(1);
|
|
||||||
await(2);
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
var async = x => { console.log("async", x); };
|
|
||||||
var await = x => { console.log("await", x); };
|
|
||||||
async(1);
|
|
||||||
await(2);
|
|
||||||
}
|
|
||||||
expect_stdout: [
|
|
||||||
"async 1",
|
|
||||||
"await 2",
|
|
||||||
]
|
|
||||||
node_version: ">=4"
|
|
||||||
}
|
|
||||||
|
|
||||||
async_function_expression: {
|
|
||||||
options = {
|
|
||||||
unsafe_arrows: true,
|
|
||||||
ecma: 6,
|
|
||||||
evaluate: true,
|
|
||||||
side_effects: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
var named = async function foo() {
|
|
||||||
await bar(1 + 0) + (2 + 0);
|
|
||||||
}
|
|
||||||
var anon = async function() {
|
|
||||||
await (1 + 0) + bar(2 + 0);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
var named = async function foo() {
|
|
||||||
await bar(1);
|
|
||||||
};
|
|
||||||
var anon = async () => {
|
|
||||||
await 1, bar(2);
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
issue_27: {
|
|
||||||
options = {
|
|
||||||
unsafe_arrows: true,
|
|
||||||
collapse_vars: true,
|
|
||||||
ecma: 6,
|
|
||||||
unused: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
(function(jQuery) {
|
|
||||||
var $;
|
|
||||||
$ = jQuery;
|
|
||||||
$("body").addClass("foo");
|
|
||||||
})(jQuery);
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
(jQuery => {
|
|
||||||
jQuery("body").addClass("foo");
|
|
||||||
})(jQuery);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
issue_2105_1: {
|
|
||||||
options = {
|
|
||||||
unsafe_arrows: true,
|
|
||||||
collapse_vars: true,
|
|
||||||
ecma: 6,
|
|
||||||
inline: true,
|
|
||||||
passes: 3,
|
|
||||||
reduce_funcs: true,
|
|
||||||
reduce_vars: true,
|
|
||||||
side_effects: true,
|
|
||||||
unsafe_methods: 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;
|
|
||||||
} );
|
|
||||||
});
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
({
|
|
||||||
prop() {
|
|
||||||
console.log;
|
|
||||||
console.log("PASS");
|
|
||||||
}
|
|
||||||
}).prop();
|
|
||||||
}
|
|
||||||
expect_stdout: "PASS"
|
|
||||||
node_version: ">=4"
|
|
||||||
}
|
|
||||||
|
|
||||||
issue_2105_2: {
|
|
||||||
options = {
|
|
||||||
collapse_vars: true,
|
|
||||||
inline: true,
|
|
||||||
passes: 2,
|
|
||||||
reduce_funcs: true,
|
|
||||||
reduce_vars: true,
|
|
||||||
side_effects: true,
|
|
||||||
unused: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
((factory) => {
|
|
||||||
factory();
|
|
||||||
})( () => {
|
|
||||||
return ((fn) => {
|
|
||||||
fn()().prop();
|
|
||||||
})( () => {
|
|
||||||
let bar = () => {
|
|
||||||
var quux = () => {
|
|
||||||
console.log("PASS");
|
|
||||||
}, foo = () => {
|
|
||||||
console.log;
|
|
||||||
quux();
|
|
||||||
};
|
|
||||||
return { prop: foo };
|
|
||||||
};
|
|
||||||
return bar;
|
|
||||||
} );
|
|
||||||
});
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
({
|
|
||||||
prop: () => {
|
|
||||||
console.log;
|
|
||||||
console.log("PASS");
|
|
||||||
}
|
|
||||||
}).prop();
|
|
||||||
}
|
|
||||||
expect_stdout: "PASS"
|
|
||||||
node_version: ">=6"
|
|
||||||
}
|
|
||||||
|
|
||||||
issue_2136_2: {
|
|
||||||
options = {
|
|
||||||
arrows: true,
|
|
||||||
collapse_vars: true,
|
|
||||||
ecma: 6,
|
|
||||||
inline: true,
|
|
||||||
side_effects: true,
|
|
||||||
unused: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
function f(x) {
|
|
||||||
console.log(x);
|
|
||||||
}
|
|
||||||
!function(a, ...b) {
|
|
||||||
f(b[0]);
|
|
||||||
}(1, 2, 3);
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
function f(x) {
|
|
||||||
console.log(x);
|
|
||||||
}
|
|
||||||
f([2,3][0]);
|
|
||||||
}
|
|
||||||
expect_stdout: "2"
|
|
||||||
node_version: ">=6"
|
|
||||||
}
|
|
||||||
|
|
||||||
issue_2136_3: {
|
|
||||||
options = {
|
|
||||||
arrows: true,
|
|
||||||
collapse_vars: true,
|
|
||||||
ecma: 6,
|
|
||||||
evaluate: true,
|
|
||||||
inline: true,
|
|
||||||
passes: 3,
|
|
||||||
reduce_funcs: true,
|
|
||||||
reduce_vars: true,
|
|
||||||
side_effects: true,
|
|
||||||
toplevel: true,
|
|
||||||
unsafe: true,
|
|
||||||
unused: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
function f(x) {
|
|
||||||
console.log(x);
|
|
||||||
}
|
|
||||||
!function(a, ...b) {
|
|
||||||
f(b[0]);
|
|
||||||
}(1, 2, 3);
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
console.log(2);
|
|
||||||
}
|
|
||||||
expect_stdout: "2"
|
|
||||||
node_version: ">=6"
|
|
||||||
}
|
|
||||||
|
|
||||||
call_args: {
|
|
||||||
options = {
|
|
||||||
arrows: true,
|
|
||||||
ecma: 6,
|
|
||||||
evaluate: true,
|
|
||||||
inline: true,
|
|
||||||
reduce_funcs: true,
|
|
||||||
reduce_vars: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
const a = 1;
|
|
||||||
console.log(a);
|
|
||||||
+function(a) {
|
|
||||||
return a;
|
|
||||||
}(a);
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
const a = 1;
|
|
||||||
console.log(1);
|
|
||||||
+(1, 1);
|
|
||||||
}
|
|
||||||
expect_stdout: true
|
|
||||||
}
|
|
||||||
|
|
||||||
call_args_drop_param: {
|
|
||||||
options = {
|
|
||||||
arrows: true,
|
|
||||||
ecma: 6,
|
|
||||||
evaluate: true,
|
|
||||||
inline: true,
|
|
||||||
keep_fargs: false,
|
|
||||||
reduce_funcs: true,
|
|
||||||
reduce_vars: true,
|
|
||||||
unused: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
const a = 1;
|
|
||||||
console.log(a);
|
|
||||||
+function(a) {
|
|
||||||
return a;
|
|
||||||
}(a, b);
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
const a = 1;
|
|
||||||
console.log(1);
|
|
||||||
+(b, 1);
|
|
||||||
}
|
|
||||||
expect_stdout: true
|
|
||||||
}
|
|
||||||
|
|
||||||
issue_485_crashing_1530: {
|
|
||||||
options = {
|
|
||||||
arrows: true,
|
|
||||||
conditionals: true,
|
|
||||||
dead_code: true,
|
|
||||||
ecma: 6,
|
|
||||||
evaluate: true,
|
|
||||||
inline: true,
|
|
||||||
side_effects: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
(function(a) {
|
|
||||||
if (true) return;
|
|
||||||
var b = 42;
|
|
||||||
})(this);
|
|
||||||
}
|
|
||||||
expect: {}
|
|
||||||
}
|
|
||||||
|
|
||||||
issue_2084: {
|
|
||||||
options = {
|
|
||||||
unsafe_arrows: true,
|
|
||||||
collapse_vars: true,
|
|
||||||
conditionals: true,
|
|
||||||
ecma: 6,
|
|
||||||
evaluate: true,
|
|
||||||
inline: true,
|
|
||||||
passes: 2,
|
|
||||||
reduce_funcs: true,
|
|
||||||
reduce_vars: true,
|
|
||||||
sequences: true,
|
|
||||||
side_effects: true,
|
|
||||||
unused: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
var c = 0;
|
|
||||||
!function() {
|
|
||||||
!function(c) {
|
|
||||||
c = 1 + c;
|
|
||||||
var c = 0;
|
|
||||||
function f14(a_1) {
|
|
||||||
if (c = 1 + c, 0 !== 23..toString())
|
|
||||||
c = 1 + c, a_1 && (a_1[0] = 0);
|
|
||||||
}
|
|
||||||
f14();
|
|
||||||
}(-1);
|
|
||||||
}();
|
|
||||||
console.log(c);
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
var c = 0;
|
|
||||||
((c) => {
|
|
||||||
c = 1 + c,
|
|
||||||
c = 1 + (c = 0),
|
|
||||||
0 !== 23..toString() && (c = 1 + c);
|
|
||||||
})(-1),
|
|
||||||
console.log(c);
|
|
||||||
}
|
|
||||||
expect_stdout: "0"
|
|
||||||
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"
|
|
||||||
}
|
|
||||||
@@ -16,7 +16,6 @@ asm_mixed: {
|
|||||||
hoist_vars : true,
|
hoist_vars : true,
|
||||||
if_return : true,
|
if_return : true,
|
||||||
join_vars : true,
|
join_vars : true,
|
||||||
cascade : true,
|
|
||||||
side_effects : true,
|
side_effects : true,
|
||||||
negate_iife : true
|
negate_iife : true
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,323 +0,0 @@
|
|||||||
await_precedence: {
|
|
||||||
input: {
|
|
||||||
async function f1() { await x + y; }
|
|
||||||
async function f2() { await (x + y); }
|
|
||||||
}
|
|
||||||
expect_exact: "async function f1(){await x+y}async function f2(){await(x+y)}"
|
|
||||||
}
|
|
||||||
|
|
||||||
await_precedence_prop: {
|
|
||||||
input: {
|
|
||||||
async function f1(){ return (await foo()).bar; }
|
|
||||||
async function f2(){ return (await foo().bar); }
|
|
||||||
}
|
|
||||||
expect_exact: "async function f1(){return(await foo()).bar}async function f2(){return await foo().bar}"
|
|
||||||
}
|
|
||||||
|
|
||||||
await_precedence_call: {
|
|
||||||
input: {
|
|
||||||
async function f3(){ return (await foo())(); }
|
|
||||||
async function f4(){ return await (foo()()); }
|
|
||||||
}
|
|
||||||
expect_exact: "async function f3(){return(await foo())()}async function f4(){return await foo()()}"
|
|
||||||
}
|
|
||||||
|
|
||||||
async_function_declaration: {
|
|
||||||
options = {
|
|
||||||
side_effects: true,
|
|
||||||
unused: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
async function f0() {}
|
|
||||||
async function f1() { await x + y; }
|
|
||||||
async function f2() { await (x + y); }
|
|
||||||
async function f3() { await x + await y; }
|
|
||||||
async function f4() { await (x + await y); }
|
|
||||||
async function f5() { await x; await y; }
|
|
||||||
async function f6() { await x, await y; }
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
async function f0() {}
|
|
||||||
async function f1() { await x, y; }
|
|
||||||
async function f2() { await (x + y); }
|
|
||||||
async function f3() { await x, await y; }
|
|
||||||
async function f4() { await (x + await y); }
|
|
||||||
async function f5() { await x; await y; }
|
|
||||||
async function f6() { await x, await y; }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
async_function_expression: {
|
|
||||||
options = {
|
|
||||||
evaluate: true,
|
|
||||||
side_effects: true,
|
|
||||||
unused: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
var named = async function foo() {
|
|
||||||
await bar(1 + 0) + (2 + 0);
|
|
||||||
}
|
|
||||||
var anon = async function() {
|
|
||||||
await (1 + 0) + bar(2 + 0);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
var named = async function() {
|
|
||||||
await bar(1);
|
|
||||||
};
|
|
||||||
var anon = async function() {
|
|
||||||
await 1, bar(2);
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
async_class: {
|
|
||||||
options = {
|
|
||||||
evaluate: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
class Foo {
|
|
||||||
async m1() {
|
|
||||||
return await foo(1 + 2);
|
|
||||||
}
|
|
||||||
static async m2() {
|
|
||||||
return await foo(3 + 4);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
class Foo {
|
|
||||||
async m1() {
|
|
||||||
return await foo(3);
|
|
||||||
}
|
|
||||||
static async m2() {
|
|
||||||
return await foo(7);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
async_object_literal: {
|
|
||||||
options = {
|
|
||||||
evaluate: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
var obj = {
|
|
||||||
async a() {
|
|
||||||
await foo(1 + 0);
|
|
||||||
},
|
|
||||||
anon: async function(){
|
|
||||||
await foo(2 + 0);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
var obj = {
|
|
||||||
async a() {
|
|
||||||
await foo(1);
|
|
||||||
},
|
|
||||||
anon: async function() {
|
|
||||||
await foo(2);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
async_export: {
|
|
||||||
input: {
|
|
||||||
export async function run() {};
|
|
||||||
export default async function def() {};
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
export async function run() {};
|
|
||||||
export default async function def() {};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
async_inline: {
|
|
||||||
options = {
|
|
||||||
collapse_vars: true,
|
|
||||||
conditionals: true,
|
|
||||||
evaluate: true,
|
|
||||||
inline: true,
|
|
||||||
negate_iife: true,
|
|
||||||
reduce_funcs: true,
|
|
||||||
reduce_vars: true,
|
|
||||||
side_effects: true,
|
|
||||||
toplevel: true,
|
|
||||||
unused: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
(async function(){ return await 3; })();
|
|
||||||
(async function(x){ await console.log(x); })(4);
|
|
||||||
|
|
||||||
function echo(x) { return x; }
|
|
||||||
echo( async function(){ return await 1; }() );
|
|
||||||
echo( async function(x){ await console.log(x); }(2) );
|
|
||||||
|
|
||||||
function top() { console.log("top"); }
|
|
||||||
top();
|
|
||||||
|
|
||||||
async function async_top() { console.log("async_top"); }
|
|
||||||
async_top();
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
!async function(){await 3}();
|
|
||||||
!async function(x){await console.log(4)}();
|
|
||||||
|
|
||||||
function echo(x){return x}
|
|
||||||
echo(async function(){return await 1}());
|
|
||||||
echo(async function(x){await console.log(2)}());
|
|
||||||
|
|
||||||
console.log("top");
|
|
||||||
|
|
||||||
!async function(){console.log("async_top")}();
|
|
||||||
}
|
|
||||||
expect_stdout: [
|
|
||||||
"4",
|
|
||||||
"2",
|
|
||||||
"top",
|
|
||||||
"async_top",
|
|
||||||
]
|
|
||||||
node_version: ">=8"
|
|
||||||
}
|
|
||||||
|
|
||||||
async_identifiers: {
|
|
||||||
input: {
|
|
||||||
var async = function(x){ console.log("async", x); };
|
|
||||||
var await = function(x){ console.log("await", x); };
|
|
||||||
async(1);
|
|
||||||
await(2);
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
var async = function(x){ console.log("async", x); };
|
|
||||||
var await = function(x){ console.log("await", x); };
|
|
||||||
async(1);
|
|
||||||
await(2);
|
|
||||||
}
|
|
||||||
expect_stdout: [
|
|
||||||
"async 1",
|
|
||||||
"await 2",
|
|
||||||
]
|
|
||||||
}
|
|
||||||
|
|
||||||
async_shorthand_property: {
|
|
||||||
mangle = {
|
|
||||||
toplevel: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
function print(o) { console.log(o.async + " " + o.await); }
|
|
||||||
var async = "Async", await = "Await";
|
|
||||||
|
|
||||||
print({ async });
|
|
||||||
print({ await });
|
|
||||||
print({ async, await });
|
|
||||||
print({ await, async });
|
|
||||||
|
|
||||||
print({ async: async });
|
|
||||||
print({ await: await });
|
|
||||||
print({ async: async, await: await });
|
|
||||||
print({ await: await, async: async });
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
function a(a) { console.log(a.async + " " + a.await); }
|
|
||||||
var n = "Async", c = "Await";
|
|
||||||
|
|
||||||
a({ async: n });
|
|
||||||
a({ await: c });
|
|
||||||
a({ async: n, await: c });
|
|
||||||
a({ await: c, async: n });
|
|
||||||
|
|
||||||
a({ async: n });
|
|
||||||
a({ await: c });
|
|
||||||
a({ async: n, await: c });
|
|
||||||
a({ await: c, async: n });
|
|
||||||
}
|
|
||||||
expect_stdout: [
|
|
||||||
"Async undefined",
|
|
||||||
"undefined Await",
|
|
||||||
"Async Await",
|
|
||||||
"Async Await",
|
|
||||||
"Async undefined",
|
|
||||||
"undefined Await",
|
|
||||||
"Async Await",
|
|
||||||
"Async Await",
|
|
||||||
]
|
|
||||||
node_version: ">=4"
|
|
||||||
}
|
|
||||||
|
|
||||||
async_arrow: {
|
|
||||||
input: {
|
|
||||||
let a1 = async x => await foo(x);
|
|
||||||
let a2 = async () => await bar();
|
|
||||||
let a3 = async (x) => await baz(x);
|
|
||||||
let a4 = async (x, y) => { await far(x, y); }
|
|
||||||
let a5 = async ({x = [1], y: z = 2}) => { await wow(x, z); }
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
let a1 = async x => await foo(x);
|
|
||||||
let a2 = async () => await bar();
|
|
||||||
let a3 = async (x) => await baz(x);
|
|
||||||
let a4 = async (x, y) => { await far(x, y); }
|
|
||||||
let a5 = async ({x = [1], y: z = 2}) => { await wow(x, z); }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
async_arrow_wait: {
|
|
||||||
input: {
|
|
||||||
var a = async (x, y) => await x(y);
|
|
||||||
}
|
|
||||||
expect_exact: "var a=async(x,y)=>await x(y);"
|
|
||||||
}
|
|
||||||
|
|
||||||
async_arrow_iife: {
|
|
||||||
input: {
|
|
||||||
(async () => {
|
|
||||||
await fetch({});
|
|
||||||
})();
|
|
||||||
}
|
|
||||||
expect_exact: "(async()=>{await fetch({})})();"
|
|
||||||
}
|
|
||||||
|
|
||||||
async_arrow_iife_negate_iife: {
|
|
||||||
options = {
|
|
||||||
negate_iife: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
(async () => {
|
|
||||||
await fetch();
|
|
||||||
})();
|
|
||||||
(() => {
|
|
||||||
plain();
|
|
||||||
})();
|
|
||||||
}
|
|
||||||
expect_exact: "(async()=>{await fetch()})();(()=>{plain()})();"
|
|
||||||
}
|
|
||||||
|
|
||||||
issue_2344_1: {
|
|
||||||
beautify = {
|
|
||||||
safari10: false,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
async () => {
|
|
||||||
+await x;
|
|
||||||
await y;
|
|
||||||
return await z;
|
|
||||||
};
|
|
||||||
}
|
|
||||||
expect_exact: "async()=>{+await x;await y;return await z};"
|
|
||||||
}
|
|
||||||
|
|
||||||
issue_2344_2: {
|
|
||||||
beautify = {
|
|
||||||
safari10: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
async () => {
|
|
||||||
+await x;
|
|
||||||
await y;
|
|
||||||
return await z;
|
|
||||||
};
|
|
||||||
}
|
|
||||||
expect_exact: "async()=>{+(await x);await y;return await z};"
|
|
||||||
}
|
|
||||||
@@ -1,191 +0,0 @@
|
|||||||
|
|
||||||
let_statement: {
|
|
||||||
input: {
|
|
||||||
let x = 6;
|
|
||||||
}
|
|
||||||
expect_exact: "let x=6;"
|
|
||||||
}
|
|
||||||
|
|
||||||
do_not_hoist_let: {
|
|
||||||
options = {
|
|
||||||
hoist_vars: true,
|
|
||||||
};
|
|
||||||
input: {
|
|
||||||
function x() {
|
|
||||||
if (FOO) {
|
|
||||||
let let1;
|
|
||||||
let let2;
|
|
||||||
var var1;
|
|
||||||
var var2;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
function x() {
|
|
||||||
var var1, var2;
|
|
||||||
if (FOO) {
|
|
||||||
let let1;
|
|
||||||
let let2;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
do_not_remove_anon_blocks_if_they_have_decls: {
|
|
||||||
input: {
|
|
||||||
function x() {
|
|
||||||
{
|
|
||||||
let x;
|
|
||||||
}
|
|
||||||
{
|
|
||||||
var x;
|
|
||||||
}
|
|
||||||
{
|
|
||||||
const y;
|
|
||||||
class Zee {};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
{
|
|
||||||
let y;
|
|
||||||
}
|
|
||||||
{
|
|
||||||
var y;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
function x(){
|
|
||||||
{
|
|
||||||
let x
|
|
||||||
}
|
|
||||||
var x;
|
|
||||||
{
|
|
||||||
const y;
|
|
||||||
class Zee {}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
{
|
|
||||||
let y
|
|
||||||
}
|
|
||||||
var y;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
remove_unused_in_global_block: {
|
|
||||||
options = {
|
|
||||||
unused: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
{
|
|
||||||
let x;
|
|
||||||
const y;
|
|
||||||
class Zee {};
|
|
||||||
var w;
|
|
||||||
}
|
|
||||||
let ex;
|
|
||||||
const why;
|
|
||||||
class Zed {};
|
|
||||||
var wut;
|
|
||||||
console.log(x, y, Zee);
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
var w;
|
|
||||||
let ex;
|
|
||||||
const why;
|
|
||||||
class Zed {};
|
|
||||||
var wut;
|
|
||||||
console.log(x, y, Zee);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
regression_block_scope_resolves: {
|
|
||||||
mangle = { };
|
|
||||||
options = {
|
|
||||||
dead_code: false
|
|
||||||
};
|
|
||||||
input: {
|
|
||||||
(function () {
|
|
||||||
if (1) {
|
|
||||||
let x;
|
|
||||||
const y = 1;
|
|
||||||
class Zee {};
|
|
||||||
}
|
|
||||||
if (1) {
|
|
||||||
let ex;
|
|
||||||
const why = 2;
|
|
||||||
class Zi {};
|
|
||||||
}
|
|
||||||
console.log(typeof x, typeof y, typeof Zee, typeof ex, typeof why, typeof Zi);
|
|
||||||
}());
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
(function () {
|
|
||||||
if (1) {
|
|
||||||
let e;
|
|
||||||
const o = 1;
|
|
||||||
class t {};
|
|
||||||
}
|
|
||||||
if (1) {
|
|
||||||
let e;
|
|
||||||
const o = 2;
|
|
||||||
class t {};
|
|
||||||
}
|
|
||||||
console.log(typeof x, typeof y, typeof Zee, typeof ex, typeof why, typeof Zi);
|
|
||||||
}());
|
|
||||||
}
|
|
||||||
expect_stdout: "undefined undefined undefined undefined undefined undefined"
|
|
||||||
node_version: ">=6"
|
|
||||||
}
|
|
||||||
|
|
||||||
switch_block_scope_mangler: {
|
|
||||||
mangle = {}
|
|
||||||
input: {
|
|
||||||
var fn = function(code) {
|
|
||||||
switch (code) {
|
|
||||||
case 1:
|
|
||||||
let apple = code + 1;
|
|
||||||
let dog = code + 4;
|
|
||||||
console.log(apple, dog);
|
|
||||||
break;
|
|
||||||
case 2:
|
|
||||||
let banana = code + 2;
|
|
||||||
console.log(banana);
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
let cat = code + 3;
|
|
||||||
console.log(cat);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
fn(1);
|
|
||||||
fn(2);
|
|
||||||
fn(3);
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
var fn = function(e) {
|
|
||||||
switch (e) {
|
|
||||||
case 1:
|
|
||||||
let l = e + 1
|
|
||||||
let o = e + 4;
|
|
||||||
console.log(l, o);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 2:
|
|
||||||
let n = e + 2;
|
|
||||||
console.log(n);
|
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
|
||||||
let c = e + 3;
|
|
||||||
console.log(c);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
fn(1);
|
|
||||||
fn(2);
|
|
||||||
fn(3);
|
|
||||||
}
|
|
||||||
expect_stdout: [
|
|
||||||
"2 5",
|
|
||||||
"4",
|
|
||||||
"6",
|
|
||||||
]
|
|
||||||
node_version: ">=6"
|
|
||||||
}
|
|
||||||
@@ -47,142 +47,3 @@ keep_some_blocks: {
|
|||||||
} else stuff();
|
} else stuff();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
issue_1664: {
|
|
||||||
input: {
|
|
||||||
var a = 1;
|
|
||||||
function f() {
|
|
||||||
if (undefined) a = 2;
|
|
||||||
{
|
|
||||||
function undefined() {}
|
|
||||||
undefined();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
f();
|
|
||||||
console.log(a);
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
var a = 1;
|
|
||||||
function f() {
|
|
||||||
if (undefined) a = 2;
|
|
||||||
{
|
|
||||||
function undefined() {}
|
|
||||||
undefined();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
f();
|
|
||||||
console.log(a);
|
|
||||||
}
|
|
||||||
expect_stdout: "1"
|
|
||||||
node_version: ">=6"
|
|
||||||
}
|
|
||||||
|
|
||||||
issue_1672_for: {
|
|
||||||
input: {
|
|
||||||
switch (function() {
|
|
||||||
return xxx;
|
|
||||||
}) {
|
|
||||||
case xxx:
|
|
||||||
for (; console.log("FAIL");) {
|
|
||||||
function xxx() {}
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
switch (function() {
|
|
||||||
return xxx;
|
|
||||||
}) {
|
|
||||||
case xxx:
|
|
||||||
for (; console.log("FAIL");) {
|
|
||||||
function xxx() {}
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
expect_stdout: true
|
|
||||||
node_version: ">=6"
|
|
||||||
}
|
|
||||||
|
|
||||||
issue_1672_for_strict: {
|
|
||||||
input: {
|
|
||||||
"use strict";
|
|
||||||
switch (function() {
|
|
||||||
return xxx;
|
|
||||||
}) {
|
|
||||||
case xxx:
|
|
||||||
for (; console.log("FAIL");) {
|
|
||||||
function xxx() {}
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
"use strict";
|
|
||||||
switch (function() {
|
|
||||||
return xxx;
|
|
||||||
}) {
|
|
||||||
case xxx:
|
|
||||||
for (; console.log("FAIL");) {
|
|
||||||
function xxx() {}
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
expect_stdout: true
|
|
||||||
node_version: ">=6"
|
|
||||||
}
|
|
||||||
|
|
||||||
issue_1672_if: {
|
|
||||||
input: {
|
|
||||||
switch (function() {
|
|
||||||
return xxx;
|
|
||||||
}) {
|
|
||||||
case xxx:
|
|
||||||
if (console.log("FAIL")) {
|
|
||||||
function xxx() {}
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
switch (function() {
|
|
||||||
return xxx;
|
|
||||||
}) {
|
|
||||||
case xxx:
|
|
||||||
if (console.log("FAIL")) function xxx() {}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
expect_stdout: true
|
|
||||||
node_version: ">=6"
|
|
||||||
}
|
|
||||||
|
|
||||||
issue_1672_if_strict: {
|
|
||||||
input: {
|
|
||||||
"use strict";
|
|
||||||
switch (function() {
|
|
||||||
return xxx;
|
|
||||||
}) {
|
|
||||||
case xxx:
|
|
||||||
if (console.log("FAIL")) {
|
|
||||||
function xxx() {}
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
"use strict";
|
|
||||||
switch (function() {
|
|
||||||
return xxx;
|
|
||||||
}) {
|
|
||||||
case xxx:
|
|
||||||
if (console.log("FAIL")) {
|
|
||||||
function xxx() {}
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
expect_stdout: true
|
|
||||||
node_version: ">=6"
|
|
||||||
}
|
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@@ -112,3 +112,206 @@ self_comparison_2: {
|
|||||||
}
|
}
|
||||||
expect_stdout: "false true"
|
expect_stdout: "false true"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
issue_2857_1: {
|
||||||
|
options = {
|
||||||
|
comparisons: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
function f1(a) {
|
||||||
|
a === undefined || a === null;
|
||||||
|
a === undefined || a !== null;
|
||||||
|
a !== undefined || a === null;
|
||||||
|
a !== undefined || a !== null;
|
||||||
|
a === undefined && a === null;
|
||||||
|
a === undefined && a !== null;
|
||||||
|
a !== undefined && a === null;
|
||||||
|
a !== undefined && a !== null;
|
||||||
|
}
|
||||||
|
function f2(a) {
|
||||||
|
a === null || a === undefined;
|
||||||
|
a === null || a !== undefined;
|
||||||
|
a !== null || a === undefined;
|
||||||
|
a !== null || a !== undefined;
|
||||||
|
a === null && a === undefined;
|
||||||
|
a === null && a !== undefined;
|
||||||
|
a !== null && a === undefined;
|
||||||
|
a !== null && a !== undefined;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
function f1(a) {
|
||||||
|
null == a;
|
||||||
|
void 0 === a || null !== a;
|
||||||
|
void 0 !== a || null === a;
|
||||||
|
void 0 !== a || null !== a;
|
||||||
|
void 0 === a && null === a;
|
||||||
|
void 0 === a && null !== a;
|
||||||
|
void 0 !== a && null === a;
|
||||||
|
null != a;
|
||||||
|
}
|
||||||
|
function f2(a) {
|
||||||
|
null == a;
|
||||||
|
null === a || void 0 !== a;
|
||||||
|
null !== a || void 0 === a;
|
||||||
|
null !== a || void 0 !== a;
|
||||||
|
null === a && void 0 === a;
|
||||||
|
null === a && void 0 !== a;
|
||||||
|
null !== a && void 0 === a;
|
||||||
|
null != a;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
issue_2857_2: {
|
||||||
|
options = {
|
||||||
|
comparisons: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
function f(a, p) {
|
||||||
|
a === undefined || a === null || p;
|
||||||
|
a === undefined || a !== null || p;
|
||||||
|
a !== undefined || a === null || p;
|
||||||
|
a !== undefined || a !== null || p;
|
||||||
|
a === undefined && a === null || p;
|
||||||
|
a === undefined && a !== null || p;
|
||||||
|
a !== undefined && a === null || p;
|
||||||
|
a !== undefined && a !== null || p;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
function f(a, p) {
|
||||||
|
null == a || p;
|
||||||
|
void 0 === a || null !== a || p;
|
||||||
|
void 0 !== a || null === a || p;
|
||||||
|
void 0 !== a || null !== a || p;
|
||||||
|
void 0 === a && null === a || p;
|
||||||
|
void 0 === a && null !== a || p;
|
||||||
|
void 0 !== a && null === a || p;
|
||||||
|
null != a || p;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
issue_2857_3: {
|
||||||
|
options = {
|
||||||
|
comparisons: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
function f(a, p) {
|
||||||
|
a === undefined || a === null && p;
|
||||||
|
a === undefined || a !== null && p;
|
||||||
|
a !== undefined || a === null && p;
|
||||||
|
a !== undefined || a !== null && p;
|
||||||
|
a === undefined && a === null && p;
|
||||||
|
a === undefined && a !== null && p;
|
||||||
|
a !== undefined && a === null && p;
|
||||||
|
a !== undefined && a !== null && p;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
function f(a, p) {
|
||||||
|
void 0 === a || null === a && p;
|
||||||
|
void 0 === a || null !== a && p;
|
||||||
|
void 0 !== a || null === a && p;
|
||||||
|
void 0 !== a || null !== a && p;
|
||||||
|
void 0 === a && null === a && p;
|
||||||
|
void 0 === a && null !== a && p;
|
||||||
|
void 0 !== a && null === a && p;
|
||||||
|
null != a && p;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
issue_2857_4: {
|
||||||
|
options = {
|
||||||
|
comparisons: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
function f(a, p) {
|
||||||
|
p || a === undefined || a === null;
|
||||||
|
p || a === undefined || a !== null;
|
||||||
|
p || a !== undefined || a === null;
|
||||||
|
p || a !== undefined || a !== null;
|
||||||
|
p || a === undefined && a === null;
|
||||||
|
p || a === undefined && a !== null;
|
||||||
|
p || a !== undefined && a === null;
|
||||||
|
p || a !== undefined && a !== null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
function f(a, p) {
|
||||||
|
p || null == a;
|
||||||
|
p || void 0 === a || null !== a;
|
||||||
|
p || void 0 !== a || null === a;
|
||||||
|
p || void 0 !== a || null !== a;
|
||||||
|
p || void 0 === a && null === a;
|
||||||
|
p || void 0 === a && null !== a;
|
||||||
|
p || void 0 !== a && null === a;
|
||||||
|
p || null != a;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
issue_2857_5: {
|
||||||
|
options = {
|
||||||
|
comparisons: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
function f(a, p) {
|
||||||
|
p && a === undefined || a === null;
|
||||||
|
p && a === undefined || a !== null;
|
||||||
|
p && a !== undefined || a === null;
|
||||||
|
p && a !== undefined || a !== null;
|
||||||
|
p && a === undefined && a === null;
|
||||||
|
p && a === undefined && a !== null;
|
||||||
|
p && a !== undefined && a === null;
|
||||||
|
p && a !== undefined && a !== null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
function f(a, p) {
|
||||||
|
p && void 0 === a || null === a;
|
||||||
|
p && void 0 === a || null !== a;
|
||||||
|
p && void 0 !== a || null === a;
|
||||||
|
p && void 0 !== a || null !== a;
|
||||||
|
p && void 0 === a && null === a;
|
||||||
|
p && void 0 === a && null !== a;
|
||||||
|
p && void 0 !== a && null === a;
|
||||||
|
p && null != a;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
issue_2857_6: {
|
||||||
|
options = {
|
||||||
|
comparisons: true,
|
||||||
|
pure_getters: "strict",
|
||||||
|
reduce_vars: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
function f(a) {
|
||||||
|
if (({}).b === undefined || {}.b === null)
|
||||||
|
return a.b !== undefined && a.b !== null;
|
||||||
|
}
|
||||||
|
console.log(f({
|
||||||
|
a: [ null ],
|
||||||
|
get b() {
|
||||||
|
return this.a.shift();
|
||||||
|
}
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
function f(a) {
|
||||||
|
if (null == {}.b)
|
||||||
|
return void 0 !== a.b && null !== a.b;
|
||||||
|
}
|
||||||
|
console.log(f({
|
||||||
|
a: [ null ],
|
||||||
|
get b() {
|
||||||
|
return this.a.shift();
|
||||||
|
}
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
expect_stdout: "true"
|
||||||
|
}
|
||||||
|
|||||||
@@ -166,22 +166,24 @@ cond_1: {
|
|||||||
conditionals: true
|
conditionals: true
|
||||||
};
|
};
|
||||||
input: {
|
input: {
|
||||||
var do_something; // if undeclared it's assumed to have side-effects
|
function foo(do_something, some_condition) {
|
||||||
if (some_condition()) {
|
if (some_condition) {
|
||||||
do_something(x);
|
do_something(x);
|
||||||
} else {
|
} else {
|
||||||
do_something(y);
|
do_something(y);
|
||||||
}
|
}
|
||||||
if (some_condition()) {
|
if (some_condition) {
|
||||||
side_effects(x);
|
side_effects(x);
|
||||||
} else {
|
} else {
|
||||||
side_effects(y);
|
side_effects(y);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
expect: {
|
expect: {
|
||||||
var do_something;
|
function foo(do_something, some_condition) {
|
||||||
do_something(some_condition() ? x : y);
|
do_something(some_condition ? x : y);
|
||||||
some_condition() ? side_effects(x) : side_effects(y);
|
some_condition ? side_effects(x) : side_effects(y);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -190,16 +192,18 @@ cond_2: {
|
|||||||
conditionals: true
|
conditionals: true
|
||||||
};
|
};
|
||||||
input: {
|
input: {
|
||||||
var x, FooBar;
|
function foo(x, FooBar, some_condition) {
|
||||||
if (some_condition()) {
|
if (some_condition) {
|
||||||
x = new FooBar(1);
|
x = new FooBar(1);
|
||||||
} else {
|
} else {
|
||||||
x = new FooBar(2);
|
x = new FooBar(2);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
expect: {
|
expect: {
|
||||||
var x, FooBar;
|
function foo(x, FooBar, some_condition) {
|
||||||
x = new FooBar(some_condition() ? 1 : 2);
|
x = new FooBar(some_condition ? 1 : 2);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -605,11 +609,47 @@ cond_8c: {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
cond_9: {
|
||||||
|
options = {
|
||||||
|
conditionals: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
function f(x, y) {
|
||||||
|
g() ? x(1) : x(2);
|
||||||
|
x ? (y || x)() : (y || x)();
|
||||||
|
x ? y(a, b) : y(d, b, c);
|
||||||
|
x ? y(a, b, c) : y(a, b, c);
|
||||||
|
x ? y(a, b, c) : y(a, b, f);
|
||||||
|
x ? y(a, b, c) : y(a, e, c);
|
||||||
|
x ? y(a, b, c) : y(a, e, f);
|
||||||
|
x ? y(a, b, c) : y(d, b, c);
|
||||||
|
x ? y(a, b, c) : y(d, b, f);
|
||||||
|
x ? y(a, b, c) : y(d, e, c);
|
||||||
|
x ? y(a, b, c) : y(d, e, f);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
function f(x, y) {
|
||||||
|
g() ? x(1) : x(2);
|
||||||
|
x, (y || x)();
|
||||||
|
x ? y(a, b) : y(d, b, c);
|
||||||
|
x, y(a, b, c);
|
||||||
|
y(a, b, x ? c : f);
|
||||||
|
y(a, x ? b : e, c);
|
||||||
|
x ? y(a, b, c) : y(a, e, f);
|
||||||
|
y(x ? a : d, b, c);
|
||||||
|
x ? y(a, b, c) : y(d, b, f);
|
||||||
|
x ? y(a, b, c) : y(d, e, c);
|
||||||
|
x ? y(a, b, c) : y(d, e, f);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
ternary_boolean_consequent: {
|
ternary_boolean_consequent: {
|
||||||
options = {
|
options = {
|
||||||
collapse_vars:true, sequences:true, properties:true, dead_code:true, conditionals:true,
|
collapse_vars:true, sequences:true, properties:true, dead_code:true, conditionals:true,
|
||||||
comparisons:true, evaluate:true, booleans:true, loops:true, unused:true, hoist_funs:true,
|
comparisons:true, evaluate:true, booleans:true, loops:true, unused:true, hoist_funs:true,
|
||||||
keep_fargs:true, if_return:true, join_vars:true, cascade:true, side_effects:true
|
keep_fargs:true, if_return:true, join_vars:true, side_effects:true
|
||||||
}
|
}
|
||||||
input: {
|
input: {
|
||||||
function f1() { return a == b ? true : x; }
|
function f1() { return a == b ? true : x; }
|
||||||
@@ -637,7 +677,7 @@ ternary_boolean_alternative: {
|
|||||||
options = {
|
options = {
|
||||||
collapse_vars:true, sequences:true, properties:true, dead_code:true, conditionals:true,
|
collapse_vars:true, sequences:true, properties:true, dead_code:true, conditionals:true,
|
||||||
comparisons:true, evaluate:true, booleans:true, loops:true, unused:true, hoist_funs:true,
|
comparisons:true, evaluate:true, booleans:true, loops:true, unused:true, hoist_funs:true,
|
||||||
keep_fargs:true, if_return:true, join_vars:true, cascade:true, side_effects:true
|
keep_fargs:true, if_return:true, join_vars:true, side_effects:true
|
||||||
}
|
}
|
||||||
input: {
|
input: {
|
||||||
function f1() { return a == b ? x : true; }
|
function f1() { return a == b ? x : true; }
|
||||||
@@ -1115,3 +1155,115 @@ issue_2535_2: {
|
|||||||
"false",
|
"false",
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
issue_2560: {
|
||||||
|
options = {
|
||||||
|
conditionals: true,
|
||||||
|
inline: true,
|
||||||
|
reduce_funcs: true,
|
||||||
|
reduce_vars: true,
|
||||||
|
toplevel: true,
|
||||||
|
unused: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
function log(x) {
|
||||||
|
console.log(x);
|
||||||
|
}
|
||||||
|
function foo() {
|
||||||
|
return log;
|
||||||
|
}
|
||||||
|
function bar() {
|
||||||
|
if (x !== (x = foo())) {
|
||||||
|
x(1);
|
||||||
|
} else {
|
||||||
|
x(2);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
var x = function() {
|
||||||
|
console.log("init");
|
||||||
|
};
|
||||||
|
bar();
|
||||||
|
bar();
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
function log(x) {
|
||||||
|
console.log(x);
|
||||||
|
}
|
||||||
|
function bar() {
|
||||||
|
x !== (x = log) ? x(1) : x(2);
|
||||||
|
}
|
||||||
|
var x = function() {
|
||||||
|
console.log("init");
|
||||||
|
};
|
||||||
|
bar();
|
||||||
|
bar();
|
||||||
|
}
|
||||||
|
expect_stdout: [
|
||||||
|
"1",
|
||||||
|
"2",
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
|
hoist_decl: {
|
||||||
|
options = {
|
||||||
|
conditionals: true,
|
||||||
|
join_vars: true,
|
||||||
|
sequences: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
if (x()) {
|
||||||
|
var a;
|
||||||
|
y();
|
||||||
|
} else {
|
||||||
|
z();
|
||||||
|
var b;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
var a, b;
|
||||||
|
x() ? y() : z();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
to_and_or: {
|
||||||
|
options = {
|
||||||
|
conditionals: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
var values = [
|
||||||
|
0,
|
||||||
|
null,
|
||||||
|
true,
|
||||||
|
"foo",
|
||||||
|
false,
|
||||||
|
-1 / 0,
|
||||||
|
void 0,
|
||||||
|
];
|
||||||
|
values.forEach(function(x) {
|
||||||
|
values.forEach(function(y) {
|
||||||
|
values.forEach(function(z) {
|
||||||
|
console.log(x ? y || z : z);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
var values = [
|
||||||
|
0,
|
||||||
|
null,
|
||||||
|
true,
|
||||||
|
"foo",
|
||||||
|
false,
|
||||||
|
-1 / 0,
|
||||||
|
void 0,
|
||||||
|
];
|
||||||
|
values.forEach(function(x) {
|
||||||
|
values.forEach(function(y) {
|
||||||
|
values.forEach(function(z) {
|
||||||
|
console.log(x && y || z);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
expect_stdout: true
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,170 +0,0 @@
|
|||||||
issue_1191: {
|
|
||||||
options = {
|
|
||||||
evaluate : true,
|
|
||||||
booleans : true,
|
|
||||||
comparisons : true,
|
|
||||||
dead_code : true,
|
|
||||||
conditionals : true,
|
|
||||||
side_effects : true,
|
|
||||||
unused : true,
|
|
||||||
hoist_funs : true,
|
|
||||||
if_return : true,
|
|
||||||
join_vars : true,
|
|
||||||
sequences : false,
|
|
||||||
collapse_vars : false,
|
|
||||||
reduce_funcs : true,
|
|
||||||
reduce_vars : true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
function foo(rot) {
|
|
||||||
const rotTol = 5;
|
|
||||||
if (rot < -rotTol || rot > rotTol)
|
|
||||||
bar();
|
|
||||||
baz();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
function foo(rot) {
|
|
||||||
(rot < -5 || rot > 5) && bar();
|
|
||||||
baz();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
issue_1194: {
|
|
||||||
options = {
|
|
||||||
evaluate : true,
|
|
||||||
booleans : true,
|
|
||||||
comparisons : true,
|
|
||||||
dead_code : true,
|
|
||||||
conditionals : true,
|
|
||||||
side_effects : true,
|
|
||||||
unused : true,
|
|
||||||
hoist_funs : true,
|
|
||||||
if_return : true,
|
|
||||||
join_vars : true,
|
|
||||||
sequences : false,
|
|
||||||
collapse_vars : false,
|
|
||||||
reduce_funcs : true,
|
|
||||||
reduce_vars : true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
function f1() {const a = "X"; return a + a;}
|
|
||||||
function f2() {const aa = "X"; return aa + aa;}
|
|
||||||
function f3() {const aaa = "X"; return aaa + aaa;}
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
function f1(){return"XX"}
|
|
||||||
function f2(){return"XX"}
|
|
||||||
function f3(){return"XX"}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
issue_1396: {
|
|
||||||
options = {
|
|
||||||
evaluate : true,
|
|
||||||
booleans : true,
|
|
||||||
comparisons : true,
|
|
||||||
dead_code : true,
|
|
||||||
conditionals : true,
|
|
||||||
side_effects : true,
|
|
||||||
unused : true,
|
|
||||||
hoist_funs : true,
|
|
||||||
if_return : true,
|
|
||||||
join_vars : true,
|
|
||||||
sequences : false,
|
|
||||||
collapse_vars : false,
|
|
||||||
reduce_funcs : true,
|
|
||||||
reduce_vars : true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
function foo(a) {
|
|
||||||
const VALUE = 1;
|
|
||||||
console.log(2 | VALUE);
|
|
||||||
console.log(VALUE + 1);
|
|
||||||
console.log(VALUE);
|
|
||||||
console.log(a & VALUE);
|
|
||||||
}
|
|
||||||
function bar() {
|
|
||||||
const s = "01234567890123456789";
|
|
||||||
console.log(s + s + s + s + s);
|
|
||||||
|
|
||||||
const CONSTANT = "abc";
|
|
||||||
console.log(CONSTANT + CONSTANT + CONSTANT + CONSTANT + CONSTANT);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
function foo(a) {
|
|
||||||
console.log(3);
|
|
||||||
console.log(2);
|
|
||||||
console.log(1);
|
|
||||||
console.log(1 & a);
|
|
||||||
}
|
|
||||||
function bar() {
|
|
||||||
const s = "01234567890123456789";
|
|
||||||
console.log(s + s + s + s + s);
|
|
||||||
|
|
||||||
console.log("abcabcabcabcabc");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
unused_regexp_literal: {
|
|
||||||
options = {
|
|
||||||
evaluate : true,
|
|
||||||
booleans : true,
|
|
||||||
comparisons : true,
|
|
||||||
dead_code : true,
|
|
||||||
conditionals : true,
|
|
||||||
side_effects : true,
|
|
||||||
unused : true,
|
|
||||||
hoist_funs : true,
|
|
||||||
if_return : true,
|
|
||||||
join_vars : true,
|
|
||||||
sequences : false,
|
|
||||||
collapse_vars : false,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
function f(){ var a = /b/; }
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
function f(){}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
regexp_literal_not_const: {
|
|
||||||
options = {
|
|
||||||
evaluate : true,
|
|
||||||
booleans : true,
|
|
||||||
comparisons : true,
|
|
||||||
dead_code : true,
|
|
||||||
conditionals : true,
|
|
||||||
side_effects : true,
|
|
||||||
unused : true,
|
|
||||||
hoist_funs : true,
|
|
||||||
if_return : true,
|
|
||||||
join_vars : true,
|
|
||||||
sequences : false,
|
|
||||||
collapse_vars : false,
|
|
||||||
reduce_funcs : true,
|
|
||||||
reduce_vars : true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
(function(){
|
|
||||||
var result;
|
|
||||||
const s = 'acdabcdeabbb';
|
|
||||||
const REGEXP_LITERAL = /ab*/g;
|
|
||||||
while (result = REGEXP_LITERAL.exec(s)) {
|
|
||||||
console.log(result[0]);
|
|
||||||
}
|
|
||||||
})();
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
(function() {
|
|
||||||
var result;
|
|
||||||
const REGEXP_LITERAL = /ab*/g;
|
|
||||||
while (result = REGEXP_LITERAL.exec("acdabcdeabbb")) console.log(result[0]);
|
|
||||||
})();
|
|
||||||
}
|
|
||||||
expect_stdout: true
|
|
||||||
}
|
|
||||||
@@ -54,52 +54,12 @@ dead_code_2_should_warn: {
|
|||||||
x = 10;
|
x = 10;
|
||||||
throw new Error("foo");
|
throw new Error("foo");
|
||||||
var x;
|
var x;
|
||||||
var g;
|
function g(){};
|
||||||
}
|
}
|
||||||
f();
|
f();
|
||||||
}
|
}
|
||||||
expect_stdout: true
|
expect_stdout: true
|
||||||
node_version: ">=6"
|
node_version: "<=4"
|
||||||
}
|
|
||||||
|
|
||||||
dead_code_2_should_warn_strict: {
|
|
||||||
options = {
|
|
||||||
dead_code: true
|
|
||||||
};
|
|
||||||
input: {
|
|
||||||
"use strict";
|
|
||||||
function f() {
|
|
||||||
g();
|
|
||||||
x = 10;
|
|
||||||
throw new Error("foo");
|
|
||||||
// completely discarding the `if` would introduce some
|
|
||||||
// bugs. UglifyJS v1 doesn't deal with this issue; in v2
|
|
||||||
// we copy any declarations to the upper scope.
|
|
||||||
if (x) {
|
|
||||||
y();
|
|
||||||
var x;
|
|
||||||
function g(){};
|
|
||||||
// but nested declarations should not be kept.
|
|
||||||
(function(){
|
|
||||||
var q;
|
|
||||||
function y(){};
|
|
||||||
})();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
f();
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
"use strict";
|
|
||||||
function f() {
|
|
||||||
g();
|
|
||||||
x = 10;
|
|
||||||
throw new Error("foo");
|
|
||||||
var x;
|
|
||||||
}
|
|
||||||
f();
|
|
||||||
}
|
|
||||||
expect_stdout: true
|
|
||||||
node_version: ">=4"
|
|
||||||
}
|
}
|
||||||
|
|
||||||
dead_code_constant_boolean_should_warn_more: {
|
dead_code_constant_boolean_should_warn_more: {
|
||||||
@@ -126,7 +86,7 @@ dead_code_constant_boolean_should_warn_more: {
|
|||||||
}
|
}
|
||||||
expect: {
|
expect: {
|
||||||
var foo;
|
var foo;
|
||||||
var bar;
|
function bar() {}
|
||||||
// nothing for the while
|
// nothing for the while
|
||||||
// as for the for, it should keep:
|
// as for the for, it should keep:
|
||||||
var moo;
|
var moo;
|
||||||
@@ -134,198 +94,7 @@ dead_code_constant_boolean_should_warn_more: {
|
|||||||
bar();
|
bar();
|
||||||
}
|
}
|
||||||
expect_stdout: true
|
expect_stdout: true
|
||||||
node_version: ">=6"
|
node_version: "<=4"
|
||||||
}
|
|
||||||
|
|
||||||
dead_code_constant_boolean_should_warn_more_strict: {
|
|
||||||
options = {
|
|
||||||
dead_code : true,
|
|
||||||
loops : true,
|
|
||||||
booleans : true,
|
|
||||||
conditionals : true,
|
|
||||||
evaluate : true,
|
|
||||||
side_effects : true,
|
|
||||||
};
|
|
||||||
input: {
|
|
||||||
"use strict";
|
|
||||||
while (!((foo && bar) || (x + "0"))) {
|
|
||||||
console.log("unreachable");
|
|
||||||
var foo;
|
|
||||||
function bar() {}
|
|
||||||
}
|
|
||||||
for (var x = 10, y; x && (y || x) && (!typeof x); ++x) {
|
|
||||||
asdf();
|
|
||||||
foo();
|
|
||||||
var moo;
|
|
||||||
}
|
|
||||||
bar();
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
"use strict";
|
|
||||||
var foo;
|
|
||||||
// nothing for the while
|
|
||||||
// as for the for, it should keep:
|
|
||||||
var moo;
|
|
||||||
var x = 10, y;
|
|
||||||
bar();
|
|
||||||
}
|
|
||||||
expect_stdout: true
|
|
||||||
node_version: ">=4"
|
|
||||||
}
|
|
||||||
|
|
||||||
dead_code_block_decls_die: {
|
|
||||||
options = {
|
|
||||||
booleans: true,
|
|
||||||
conditionals: true,
|
|
||||||
dead_code: true,
|
|
||||||
evaluate: true,
|
|
||||||
side_effects: true,
|
|
||||||
};
|
|
||||||
input: {
|
|
||||||
if (0) {
|
|
||||||
let foo = 6;
|
|
||||||
const bar = 12;
|
|
||||||
class Baz {};
|
|
||||||
var qux;
|
|
||||||
}
|
|
||||||
console.log(foo, bar, Baz);
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
var qux;
|
|
||||||
console.log(foo, bar, Baz);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
dead_code_const_declaration: {
|
|
||||||
options = {
|
|
||||||
booleans: true,
|
|
||||||
conditionals: true,
|
|
||||||
dead_code: true,
|
|
||||||
evaluate: true,
|
|
||||||
loops: true,
|
|
||||||
reduce_funcs: true,
|
|
||||||
reduce_vars: true,
|
|
||||||
side_effects: true,
|
|
||||||
};
|
|
||||||
input: {
|
|
||||||
var unused;
|
|
||||||
const CONST_FOO = false;
|
|
||||||
if (CONST_FOO) {
|
|
||||||
console.log("unreachable");
|
|
||||||
var moo;
|
|
||||||
function bar() {}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
var unused;
|
|
||||||
const CONST_FOO = !1;
|
|
||||||
var moo;
|
|
||||||
var bar;
|
|
||||||
}
|
|
||||||
expect_stdout: true
|
|
||||||
}
|
|
||||||
|
|
||||||
dead_code_const_annotation: {
|
|
||||||
options = {
|
|
||||||
booleans: true,
|
|
||||||
conditionals: true,
|
|
||||||
dead_code: true,
|
|
||||||
evaluate: true,
|
|
||||||
loops: true,
|
|
||||||
reduce_funcs: true,
|
|
||||||
reduce_vars: true,
|
|
||||||
side_effects: true,
|
|
||||||
toplevel: true,
|
|
||||||
};
|
|
||||||
input: {
|
|
||||||
var unused;
|
|
||||||
/** @const */ var CONST_FOO_ANN = false;
|
|
||||||
if (CONST_FOO_ANN) {
|
|
||||||
console.log("unreachable");
|
|
||||||
var moo;
|
|
||||||
function bar() {}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
var unused;
|
|
||||||
var CONST_FOO_ANN = !1;
|
|
||||||
var moo;
|
|
||||||
var bar;
|
|
||||||
}
|
|
||||||
expect_stdout: true
|
|
||||||
}
|
|
||||||
|
|
||||||
dead_code_const_annotation_regex: {
|
|
||||||
options = {
|
|
||||||
dead_code : true,
|
|
||||||
loops : true,
|
|
||||||
booleans : true,
|
|
||||||
conditionals : true,
|
|
||||||
evaluate : true
|
|
||||||
};
|
|
||||||
input: {
|
|
||||||
var unused;
|
|
||||||
// @constraint this shouldn't be a constant
|
|
||||||
var CONST_FOO_ANN = false;
|
|
||||||
if (CONST_FOO_ANN) {
|
|
||||||
console.log("reachable");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
var unused;
|
|
||||||
var CONST_FOO_ANN = !1;
|
|
||||||
CONST_FOO_ANN && console.log('reachable');
|
|
||||||
}
|
|
||||||
expect_stdout: true
|
|
||||||
}
|
|
||||||
|
|
||||||
dead_code_const_annotation_complex_scope: {
|
|
||||||
options = {
|
|
||||||
booleans: true,
|
|
||||||
conditionals: true,
|
|
||||||
dead_code: true,
|
|
||||||
evaluate: true,
|
|
||||||
loops: true,
|
|
||||||
reduce_funcs: true,
|
|
||||||
reduce_vars: true,
|
|
||||||
sequences: true,
|
|
||||||
side_effects: true,
|
|
||||||
toplevel: true,
|
|
||||||
};
|
|
||||||
input: {
|
|
||||||
var unused_var;
|
|
||||||
/** @const */ var test = 'test';
|
|
||||||
// @const
|
|
||||||
var CONST_FOO_ANN = false;
|
|
||||||
var unused_var_2;
|
|
||||||
if (CONST_FOO_ANN) {
|
|
||||||
console.log("unreachable");
|
|
||||||
var moo;
|
|
||||||
function bar() {}
|
|
||||||
}
|
|
||||||
if (test === 'test') {
|
|
||||||
var beef = 'good';
|
|
||||||
/** @const */ var meat = 'beef';
|
|
||||||
var pork = 'bad';
|
|
||||||
if (meat === 'pork') {
|
|
||||||
console.log('also unreachable');
|
|
||||||
} else if (pork === 'good') {
|
|
||||||
console.log('reached, not const');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
var unused_var;
|
|
||||||
var test = 'test';
|
|
||||||
var CONST_FOO_ANN = !1;
|
|
||||||
var unused_var_2;
|
|
||||||
var moo;
|
|
||||||
var bar;
|
|
||||||
var beef = 'good';
|
|
||||||
var meat = 'beef';
|
|
||||||
var pork = 'bad';
|
|
||||||
}
|
|
||||||
expect_stdout: true
|
|
||||||
}
|
}
|
||||||
|
|
||||||
try_catch_finally: {
|
try_catch_finally: {
|
||||||
@@ -573,66 +342,578 @@ global_fns: {
|
|||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
issue_2383_1: {
|
collapse_vars_assignment: {
|
||||||
options = {
|
options = {
|
||||||
conditionals: true,
|
collapse_vars: true,
|
||||||
dead_code: true,
|
dead_code: true,
|
||||||
evaluate: true,
|
passes: 2,
|
||||||
side_effects: true,
|
unused: true,
|
||||||
}
|
}
|
||||||
input: {
|
input: {
|
||||||
if (0) {
|
function f0(c) {
|
||||||
var {x, y} = foo();
|
var a = 3 / c;
|
||||||
|
return a = a;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
expect: {
|
expect: {
|
||||||
var x, y;
|
function f0(c) {
|
||||||
|
return 3 / c;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
issue_2383_2: {
|
collapse_vars_lvalues_drop_assign: {
|
||||||
options = {
|
options = {
|
||||||
conditionals: true,
|
collapse_vars: true,
|
||||||
dead_code: true,
|
dead_code: true,
|
||||||
evaluate: true,
|
unused: true,
|
||||||
side_effects: true,
|
|
||||||
}
|
}
|
||||||
input: {
|
input: {
|
||||||
if (0) {
|
function f0(x) { var i = ++x; return x += i; }
|
||||||
var {
|
function f1(x) { var a = (x -= 3); return x += a; }
|
||||||
x = 0,
|
function f2(x) { var z = x, a = ++z; return z += a; }
|
||||||
y: [ w, , { z, p: q = 7 } ] = [ 1, 2, { z: 3 } ]
|
|
||||||
} = {};
|
|
||||||
}
|
|
||||||
console.log(x, q, w, z);
|
|
||||||
}
|
}
|
||||||
expect: {
|
expect: {
|
||||||
var x, w, z, q;
|
function f0(x) { var i = ++x; return x + i; }
|
||||||
console.log(x, q, w, z);
|
function f1(x) { var a = (x -= 3); return x + a; }
|
||||||
|
function f2(x) { var z = x, a = ++z; return z + a; }
|
||||||
}
|
}
|
||||||
expect_stdout: "undefined undefined undefined undefined"
|
|
||||||
node_version: ">=6"
|
|
||||||
}
|
}
|
||||||
|
|
||||||
issue_2383_3: {
|
collapse_vars_misc1: {
|
||||||
options = {
|
options = {
|
||||||
conditionals: true,
|
collapse_vars: true,
|
||||||
dead_code: true,
|
dead_code: true,
|
||||||
evaluate: true,
|
unused: true,
|
||||||
side_effects: true,
|
|
||||||
}
|
}
|
||||||
input: {
|
input: {
|
||||||
var b = 7, y = 8;
|
function f10(x) { var a = 5, b = 3; return a += b; }
|
||||||
if (0) {
|
function f11(x) { var a = 5, b = 3; return a += --b; }
|
||||||
var a = 1, [ x, y, z ] = [ 2, 3, 4 ], b = 5;
|
|
||||||
}
|
|
||||||
console.log(a, x, y, z, b);
|
|
||||||
}
|
}
|
||||||
expect: {
|
expect: {
|
||||||
var b = 7, y = 8;
|
function f10(x) { return 5 + 3; }
|
||||||
var a, x, y, z, b;
|
function f11(x) { var b = 3; return 5 + --b; }
|
||||||
console.log(a, x, y, z, b);
|
|
||||||
}
|
}
|
||||||
expect_stdout: "undefined undefined 8 undefined 7"
|
}
|
||||||
node_version: ">=6"
|
|
||||||
|
return_assignment: {
|
||||||
|
options = {
|
||||||
|
dead_code: true,
|
||||||
|
unused: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
function f1(a, b, c) {
|
||||||
|
return a = x(), b = y(), b = a && (c >>= 5);
|
||||||
|
}
|
||||||
|
function f2() {
|
||||||
|
return e = x();
|
||||||
|
}
|
||||||
|
function f3(e) {
|
||||||
|
return e = x();
|
||||||
|
}
|
||||||
|
function f4() {
|
||||||
|
var e;
|
||||||
|
return e = x();
|
||||||
|
}
|
||||||
|
function f5(a) {
|
||||||
|
try {
|
||||||
|
return a = x();
|
||||||
|
} catch (b) {
|
||||||
|
console.log(a);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
function f6(a) {
|
||||||
|
try {
|
||||||
|
return a = x();
|
||||||
|
} finally {
|
||||||
|
console.log(a);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
function y() {
|
||||||
|
console.log("y");
|
||||||
|
}
|
||||||
|
function test(inc) {
|
||||||
|
var counter = 0;
|
||||||
|
x = function() {
|
||||||
|
counter += inc;
|
||||||
|
if (inc < 0) throw counter;
|
||||||
|
return counter;
|
||||||
|
};
|
||||||
|
[ f1, f2, f3, f4, f5, f6 ].forEach(function(f, i) {
|
||||||
|
e = null;
|
||||||
|
try {
|
||||||
|
i += 1;
|
||||||
|
console.log("result " + f(10 * i, 100 * i, 1000 * i));
|
||||||
|
} catch (x) {
|
||||||
|
console.log("caught " + x);
|
||||||
|
}
|
||||||
|
if (null !== e) console.log("e: " + e);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
var x, e;
|
||||||
|
test(1);
|
||||||
|
test(-1);
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
function f1(a, b, c) {
|
||||||
|
return a = x(), y(), a && (c >> 5);
|
||||||
|
}
|
||||||
|
function f2() {
|
||||||
|
return e = x();
|
||||||
|
}
|
||||||
|
function f3(e) {
|
||||||
|
return x();
|
||||||
|
}
|
||||||
|
function f4() {
|
||||||
|
return x();
|
||||||
|
}
|
||||||
|
function f5(a) {
|
||||||
|
try {
|
||||||
|
return x();
|
||||||
|
} catch (b) {
|
||||||
|
console.log(a);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
function f6(a) {
|
||||||
|
try {
|
||||||
|
return a = x();
|
||||||
|
} finally {
|
||||||
|
console.log(a);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
function y() {
|
||||||
|
console.log("y");
|
||||||
|
}
|
||||||
|
function test(inc) {
|
||||||
|
var counter = 0;
|
||||||
|
x = function() {
|
||||||
|
counter += inc;
|
||||||
|
if (inc < 0) throw counter;
|
||||||
|
return counter;
|
||||||
|
};
|
||||||
|
[ f1, f2, f3, f4, f5, f6 ].forEach(function(f, i) {
|
||||||
|
e = null;
|
||||||
|
try {
|
||||||
|
i += 1;
|
||||||
|
console.log("result " + f(10 * i, 100 * i, 1000 * i));
|
||||||
|
} catch (x) {
|
||||||
|
console.log("caught " + x);
|
||||||
|
}
|
||||||
|
if (null !== e) console.log("e: " + e);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
var x, e;
|
||||||
|
test(1);
|
||||||
|
test(-1);
|
||||||
|
}
|
||||||
|
expect_stdout: [
|
||||||
|
"y",
|
||||||
|
"result 31",
|
||||||
|
"result 2",
|
||||||
|
"e: 2",
|
||||||
|
"result 3",
|
||||||
|
"result 4",
|
||||||
|
"result 5",
|
||||||
|
"6",
|
||||||
|
"result 6",
|
||||||
|
"caught -1",
|
||||||
|
"caught -2",
|
||||||
|
"caught -3",
|
||||||
|
"caught -4",
|
||||||
|
"50",
|
||||||
|
"result undefined",
|
||||||
|
"60",
|
||||||
|
"caught -6",
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
|
throw_assignment: {
|
||||||
|
options = {
|
||||||
|
dead_code: true,
|
||||||
|
unused: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
function f1() {
|
||||||
|
throw a = x();
|
||||||
|
}
|
||||||
|
function f2(a) {
|
||||||
|
throw a = x();
|
||||||
|
}
|
||||||
|
function f3() {
|
||||||
|
var a;
|
||||||
|
throw a = x();
|
||||||
|
}
|
||||||
|
function f4() {
|
||||||
|
try {
|
||||||
|
throw a = x();
|
||||||
|
} catch (b) {
|
||||||
|
console.log(a);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
function f5(a) {
|
||||||
|
try {
|
||||||
|
throw a = x();
|
||||||
|
} catch (b) {
|
||||||
|
console.log(a);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
function f6() {
|
||||||
|
var a;
|
||||||
|
try {
|
||||||
|
throw a = x();
|
||||||
|
} catch (b) {
|
||||||
|
console.log(a);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
function f7() {
|
||||||
|
try {
|
||||||
|
throw a = x();
|
||||||
|
} finally {
|
||||||
|
console.log(a);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
function f8(a) {
|
||||||
|
try {
|
||||||
|
throw a = x();
|
||||||
|
} finally {
|
||||||
|
console.log(a);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
function f9() {
|
||||||
|
var a;
|
||||||
|
try {
|
||||||
|
throw a = x();
|
||||||
|
} finally {
|
||||||
|
console.log(a);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
function test(inc) {
|
||||||
|
var counter = 0;
|
||||||
|
x = function() {
|
||||||
|
counter += inc;
|
||||||
|
if (inc < 0) throw counter;
|
||||||
|
return counter;
|
||||||
|
};
|
||||||
|
[ f1, f2, f3, f4, f5, f6, f7, f8, f9 ].forEach(function(f, i) {
|
||||||
|
a = null;
|
||||||
|
try {
|
||||||
|
f(10 * (1 + i));
|
||||||
|
} catch (x) {
|
||||||
|
console.log("caught " + x);
|
||||||
|
}
|
||||||
|
if (null !== a) console.log("a: " + a);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
var x, a;
|
||||||
|
test(1);
|
||||||
|
test(-1);
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
function f1() {
|
||||||
|
throw a = x();
|
||||||
|
}
|
||||||
|
function f2(a) {
|
||||||
|
throw x();
|
||||||
|
}
|
||||||
|
function f3() {
|
||||||
|
throw x();
|
||||||
|
}
|
||||||
|
function f4() {
|
||||||
|
try {
|
||||||
|
throw a = x();
|
||||||
|
} catch (b) {
|
||||||
|
console.log(a);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
function f5(a) {
|
||||||
|
try {
|
||||||
|
throw a = x();
|
||||||
|
} catch (b) {
|
||||||
|
console.log(a);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
function f6() {
|
||||||
|
var a;
|
||||||
|
try {
|
||||||
|
throw a = x();
|
||||||
|
} catch (b) {
|
||||||
|
console.log(a);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
function f7() {
|
||||||
|
try {
|
||||||
|
throw a = x();
|
||||||
|
} finally {
|
||||||
|
console.log(a);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
function f8(a) {
|
||||||
|
try {
|
||||||
|
throw a = x();
|
||||||
|
} finally {
|
||||||
|
console.log(a);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
function f9() {
|
||||||
|
var a;
|
||||||
|
try {
|
||||||
|
throw a = x();
|
||||||
|
} finally {
|
||||||
|
console.log(a);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
function test(inc) {
|
||||||
|
var counter = 0;
|
||||||
|
x = function() {
|
||||||
|
counter += inc;
|
||||||
|
if (inc < 0) throw counter;
|
||||||
|
return counter;
|
||||||
|
};
|
||||||
|
[ f1, f2, f3, f4, f5, f6, f7, f8, f9 ].forEach(function(f, i) {
|
||||||
|
a = null;
|
||||||
|
try {
|
||||||
|
f(10 * (1 + i));
|
||||||
|
} catch (x) {
|
||||||
|
console.log("caught " + x);
|
||||||
|
}
|
||||||
|
if (null !== a) console.log("a: " + a);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
var x, a;
|
||||||
|
test(1);
|
||||||
|
test(-1);
|
||||||
|
}
|
||||||
|
expect_stdout: [
|
||||||
|
"caught 1",
|
||||||
|
"a: 1",
|
||||||
|
"caught 2",
|
||||||
|
"caught 3",
|
||||||
|
"4",
|
||||||
|
"a: 4",
|
||||||
|
"5",
|
||||||
|
"6",
|
||||||
|
"7",
|
||||||
|
"caught 7",
|
||||||
|
"a: 7",
|
||||||
|
"8",
|
||||||
|
"caught 8",
|
||||||
|
"9",
|
||||||
|
"caught 9",
|
||||||
|
"caught -1",
|
||||||
|
"caught -2",
|
||||||
|
"caught -3",
|
||||||
|
"null",
|
||||||
|
"50",
|
||||||
|
"undefined",
|
||||||
|
"null",
|
||||||
|
"caught -7",
|
||||||
|
"80",
|
||||||
|
"caught -8",
|
||||||
|
"undefined",
|
||||||
|
"caught -9",
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
|
issue_2597: {
|
||||||
|
options = {
|
||||||
|
dead_code: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
function f(b) {
|
||||||
|
try {
|
||||||
|
try {
|
||||||
|
throw "foo";
|
||||||
|
} catch (e) {
|
||||||
|
return b = true;
|
||||||
|
}
|
||||||
|
} finally {
|
||||||
|
b && (a = "PASS");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
var a = "FAIL";
|
||||||
|
f();
|
||||||
|
console.log(a);
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
function f(b) {
|
||||||
|
try {
|
||||||
|
try {
|
||||||
|
throw "foo";
|
||||||
|
} catch (e) {
|
||||||
|
return b = true;
|
||||||
|
}
|
||||||
|
} finally {
|
||||||
|
b && (a = "PASS");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
var a = "FAIL";
|
||||||
|
f();
|
||||||
|
console.log(a);
|
||||||
|
}
|
||||||
|
expect_stdout: "PASS"
|
||||||
|
}
|
||||||
|
|
||||||
|
issue_2666: {
|
||||||
|
options = {
|
||||||
|
dead_code: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
function f(a) {
|
||||||
|
return a = {
|
||||||
|
p: function() {
|
||||||
|
return a;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
console.log(typeof f().p());
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
function f(a) {
|
||||||
|
return a = {
|
||||||
|
p: function() {
|
||||||
|
return a;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
console.log(typeof f().p());
|
||||||
|
}
|
||||||
|
expect_stdout: "object"
|
||||||
|
}
|
||||||
|
|
||||||
|
issue_2692: {
|
||||||
|
options = {
|
||||||
|
dead_code: true,
|
||||||
|
reduce_vars: false,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
function f(a) {
|
||||||
|
return a = g;
|
||||||
|
function g() {
|
||||||
|
return a;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
console.log(typeof f()());
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
function f(a) {
|
||||||
|
return a = g;
|
||||||
|
function g() {
|
||||||
|
return a;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
console.log(typeof f()());
|
||||||
|
}
|
||||||
|
expect_stdout: "function"
|
||||||
|
}
|
||||||
|
|
||||||
|
issue_2701: {
|
||||||
|
options = {
|
||||||
|
dead_code: true,
|
||||||
|
inline: false,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
function f(a) {
|
||||||
|
return a = function() {
|
||||||
|
return function() {
|
||||||
|
return a;
|
||||||
|
};
|
||||||
|
}();
|
||||||
|
}
|
||||||
|
console.log(typeof f()());
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
function f(a) {
|
||||||
|
return a = function() {
|
||||||
|
return function() {
|
||||||
|
return a;
|
||||||
|
};
|
||||||
|
}();
|
||||||
|
}
|
||||||
|
console.log(typeof f()());
|
||||||
|
}
|
||||||
|
expect_stdout: "function"
|
||||||
|
}
|
||||||
|
|
||||||
|
issue_2749: {
|
||||||
|
options = {
|
||||||
|
dead_code: true,
|
||||||
|
inline: true,
|
||||||
|
toplevel: true,
|
||||||
|
unused: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
var a = 2, c = "PASS";
|
||||||
|
while (a--)
|
||||||
|
(function() {
|
||||||
|
return b ? c = "FAIL" : b = 1;
|
||||||
|
try {
|
||||||
|
} catch (b) {
|
||||||
|
var b;
|
||||||
|
}
|
||||||
|
})();
|
||||||
|
console.log(c);
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
var a = 2, c = "PASS";
|
||||||
|
while (a--)
|
||||||
|
b = void 0, b ? c = "FAIL" : b = 1;
|
||||||
|
var b;
|
||||||
|
console.log(c);
|
||||||
|
}
|
||||||
|
expect_stdout: "PASS"
|
||||||
|
}
|
||||||
|
|
||||||
|
unsafe_builtin: {
|
||||||
|
options = {
|
||||||
|
side_effects: true,
|
||||||
|
unsafe: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
(!w).constructor(x);
|
||||||
|
Math.abs(y);
|
||||||
|
[ 1, 2, z ].valueOf();
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
w, x;
|
||||||
|
y;
|
||||||
|
z;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
issue_2860_1: {
|
||||||
|
options = {
|
||||||
|
dead_code: true,
|
||||||
|
evaluate: true,
|
||||||
|
reduce_vars: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
console.log(function(a) {
|
||||||
|
return a ^= 1;
|
||||||
|
}());
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
console.log(function(a) {
|
||||||
|
return 1 ^ a;
|
||||||
|
}());
|
||||||
|
}
|
||||||
|
expect_stdout: "1"
|
||||||
|
}
|
||||||
|
|
||||||
|
issue_2860_2: {
|
||||||
|
options = {
|
||||||
|
dead_code: true,
|
||||||
|
evaluate: true,
|
||||||
|
inline: true,
|
||||||
|
passes: 2,
|
||||||
|
reduce_vars: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
console.log(function(a) {
|
||||||
|
return a ^= 1;
|
||||||
|
}());
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
console.log(1);
|
||||||
|
}
|
||||||
|
expect_stdout: "1"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,662 +0,0 @@
|
|||||||
destructuring_arrays: {
|
|
||||||
input: {
|
|
||||||
{const [aa, bb] = cc;}
|
|
||||||
{const [aa, [bb, cc]] = dd;}
|
|
||||||
{let [aa, bb] = cc;}
|
|
||||||
{let [aa, [bb, cc]] = dd;}
|
|
||||||
var [aa, bb] = cc;
|
|
||||||
var [aa, [bb, cc]] = dd;
|
|
||||||
var [,[,,,,,],,,zz,] = xx; // Trailing comma
|
|
||||||
var [,,zzz,,] = xxx; // Trailing comma after hole
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
{const [aa, bb] = cc;}
|
|
||||||
{const [aa, [bb, cc]] = dd;}
|
|
||||||
{let [aa, bb] = cc;}
|
|
||||||
{let [aa, [bb, cc]] = dd;}
|
|
||||||
var [aa, bb] = cc;
|
|
||||||
var [aa, [bb, cc]] = dd;
|
|
||||||
var [,[,,,,,],,,zz] = xx;
|
|
||||||
var [,,zzz,,] = xxx;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
destructuring_arrays_holes: {
|
|
||||||
input: {
|
|
||||||
var [,,,,] = a;
|
|
||||||
var [,,b,] = c;
|
|
||||||
var [d,,] = e;
|
|
||||||
}
|
|
||||||
expect_exact: "var[,,,,]=a;var[,,b]=c;var[d,,]=e;"
|
|
||||||
}
|
|
||||||
|
|
||||||
destructuring_objects: {
|
|
||||||
input: {
|
|
||||||
{const {aa, bb} = {aa:1, bb:2};}
|
|
||||||
{const {aa, bb: {cc, dd}} = {aa:1, bb: {cc:2, dd: 3}};}
|
|
||||||
{let {aa, bb} = {aa:1, bb:2};}
|
|
||||||
{let {aa, bb: {cc, dd}} = {aa:1, bb: {cc:2, dd: 3}};}
|
|
||||||
var {aa, bb} = {aa:1, bb:2};
|
|
||||||
var {aa, bb: {cc, dd}} = {aa:1, bb: {cc:2, dd: 3}};
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
{const {aa, bb} = {aa:1, bb:2};}
|
|
||||||
{const {aa, bb: {cc, dd}} = {aa:1, bb: {cc:2, dd: 3}};}
|
|
||||||
{let {aa, bb} = {aa:1, bb:2};}
|
|
||||||
{let {aa, bb: {cc, dd}} = {aa:1, bb: {cc:2, dd: 3}};}
|
|
||||||
var {aa, bb} = {aa:1, bb:2};
|
|
||||||
var {aa, bb: {cc, dd}} = {aa:1, bb: {cc:2, dd: 3}};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
destructuring_objects_trailing_elision: {
|
|
||||||
beautify = {
|
|
||||||
ecma: 6
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
var {cc,} = foo;
|
|
||||||
}
|
|
||||||
expect_exact: "var{cc}=foo;"
|
|
||||||
}
|
|
||||||
|
|
||||||
nested_destructuring_objects: {
|
|
||||||
beautify = {
|
|
||||||
ecma: 6
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
const [{a},b] = c;
|
|
||||||
let [{d},e] = f;
|
|
||||||
var [{g},h] = i;
|
|
||||||
}
|
|
||||||
expect_exact: 'const[{a},b]=c;let[{d},e]=f;var[{g},h]=i;';
|
|
||||||
}
|
|
||||||
|
|
||||||
destructuring_constdef_in_loops: {
|
|
||||||
beautify = {
|
|
||||||
ecma: 6
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
for (const [x,y] in pairs);
|
|
||||||
for (const [a] = 0;;);
|
|
||||||
for (const {c} of cees);
|
|
||||||
}
|
|
||||||
expect_exact: "for(const[x,y]in pairs);for(const[a]=0;;);for(const{c}of cees);"
|
|
||||||
}
|
|
||||||
|
|
||||||
destructuring_letdef_in_loops: {
|
|
||||||
beautify = {
|
|
||||||
ecma: 6
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
for (let [x,y] in pairs);
|
|
||||||
for (let [a] = 0;;);
|
|
||||||
for (let {c} of cees);
|
|
||||||
}
|
|
||||||
expect_exact: "for(let[x,y]in pairs);for(let[a]=0;;);for(let{c}of cees);"
|
|
||||||
}
|
|
||||||
|
|
||||||
destructuring_vardef_in_loops: {
|
|
||||||
beautify = {
|
|
||||||
ecma: 6
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
for (var [x,y] in pairs);
|
|
||||||
for (var [a] = 0;;);
|
|
||||||
for (var {c} of cees);
|
|
||||||
}
|
|
||||||
expect_exact: "for(var[x,y]in pairs);for(var[a]=0;;);for(var{c}of cees);"
|
|
||||||
}
|
|
||||||
|
|
||||||
destructuring_expressions: {
|
|
||||||
beautify = {
|
|
||||||
ecma: 6
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
({a, b});
|
|
||||||
[{a}];
|
|
||||||
f({x});
|
|
||||||
}
|
|
||||||
expect_exact: "({a,b});[{a}];f({x});"
|
|
||||||
}
|
|
||||||
|
|
||||||
destructuring_remove_unused_1: {
|
|
||||||
options = {
|
|
||||||
unused: true
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
function a() {
|
|
||||||
var unused = "foo";
|
|
||||||
var a = [1];
|
|
||||||
var [b] = a;
|
|
||||||
f(b);
|
|
||||||
}
|
|
||||||
function b() {
|
|
||||||
var unused = "foo";
|
|
||||||
var a = {b: 1};
|
|
||||||
var {b} = a;
|
|
||||||
f(b);
|
|
||||||
}
|
|
||||||
function c() {
|
|
||||||
var unused = "foo";
|
|
||||||
var a = [[1]];
|
|
||||||
var [[b]] = a;
|
|
||||||
f(b);
|
|
||||||
}
|
|
||||||
function d() {
|
|
||||||
var unused = "foo";
|
|
||||||
var a = {b: {b:1}};
|
|
||||||
var {b:{b}} = a;
|
|
||||||
f(b);
|
|
||||||
}
|
|
||||||
function e() {
|
|
||||||
var unused = "foo";
|
|
||||||
var a = [1, 2, 3, 4, 5];
|
|
||||||
var x = [[1, 2, 3]];
|
|
||||||
var y = {h: 1};
|
|
||||||
var [b, ...c] = a;
|
|
||||||
var [...[e, f]] = x;
|
|
||||||
var [...{g: h}] = y;
|
|
||||||
f(b, c, e, f, g);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
function a() {
|
|
||||||
var a = [1];
|
|
||||||
var [b] = a;
|
|
||||||
f(b);
|
|
||||||
}
|
|
||||||
function b() {
|
|
||||||
var a = {b: 1};
|
|
||||||
var {b} = a;
|
|
||||||
f(b);
|
|
||||||
}
|
|
||||||
function c() {
|
|
||||||
var a = [[1]];
|
|
||||||
var [[b]] = a;
|
|
||||||
f(b);
|
|
||||||
}
|
|
||||||
function d() {
|
|
||||||
var a = {b: {b:1}};
|
|
||||||
var {b:{b}} = a;
|
|
||||||
f(b);
|
|
||||||
}
|
|
||||||
function e() {
|
|
||||||
var a = [1, 2, 3, 4, 5];
|
|
||||||
var x = [[1, 2, 3]];
|
|
||||||
var y = {h: 1};
|
|
||||||
var [b, ...c] = a;
|
|
||||||
var [...[e, f]] = x;
|
|
||||||
var [...{g: h}] = y;
|
|
||||||
f(b, c, e, f, g);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
destructuring_remove_unused_2: {
|
|
||||||
options = {
|
|
||||||
unused: true
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
function a() {
|
|
||||||
var unused = "foo";
|
|
||||||
var a = [,,1];
|
|
||||||
var [b] = a;
|
|
||||||
f(b);
|
|
||||||
}
|
|
||||||
function b() {
|
|
||||||
var unused = "foo";
|
|
||||||
var a = [{a: [1]}];
|
|
||||||
var [{b: a}] = a;
|
|
||||||
f(b);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
function a() {
|
|
||||||
var a = [,,1];
|
|
||||||
var [b] = a;
|
|
||||||
f(b);
|
|
||||||
}
|
|
||||||
function b() {
|
|
||||||
var a = [{a: [1]}];
|
|
||||||
var [{b: a}] = a;
|
|
||||||
f(b);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
object_destructuring_may_need_parentheses: {
|
|
||||||
beautify = {
|
|
||||||
ecma: 6
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
({a, b} = {a: 1, b: 2});
|
|
||||||
}
|
|
||||||
expect_exact: "({a,b}={a:1,b:2});"
|
|
||||||
}
|
|
||||||
|
|
||||||
destructuring_with_undefined_as_default_assignment: {
|
|
||||||
options = {
|
|
||||||
evaluate: true
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
[foo = undefined] = bar;
|
|
||||||
[foo = void 0] = bar;
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
[foo] = bar;
|
|
||||||
[foo] = bar;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
destructuring_dont_evaluate_with_undefined_as_default_assignment: {
|
|
||||||
options = {
|
|
||||||
evaluate: false
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
[foo = undefined] = bar;
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
[foo = void 0] = bar;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
reduce_vars: {
|
|
||||||
options = {
|
|
||||||
reduce_funcs: true,
|
|
||||||
reduce_vars: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
{const [aa, [bb, cc]] = dd;}
|
|
||||||
{let [aa, [bb, cc]] = dd;}
|
|
||||||
var [aa, [bb, cc]] = dd;
|
|
||||||
[aa, [bb, cc]] = dd;
|
|
||||||
{const {aa, bb: {cc, dd}} = {aa:1, bb: {cc:2, dd: 3}};}
|
|
||||||
{let {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}});
|
|
||||||
const [{a},b] = c;
|
|
||||||
let [{d},e] = f;
|
|
||||||
var [{g},h] = i;
|
|
||||||
[{a},b] = c;
|
|
||||||
for (const [x,y] in pairs);
|
|
||||||
for (let [x,y] in pairs);
|
|
||||||
for (var [x,y] in pairs);
|
|
||||||
for ([x,y] in pairs);
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
{const [aa, [bb, cc]] = dd;}
|
|
||||||
{let [aa, [bb, cc]] = dd;}
|
|
||||||
var [aa, [bb, cc]] = dd;
|
|
||||||
[aa, [bb, cc]] = dd;
|
|
||||||
{const {aa, bb: {cc, dd}} = {aa:1, bb: {cc:2, dd: 3}};}
|
|
||||||
{let {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}});
|
|
||||||
const [{a},b] = c;
|
|
||||||
let [{d},e] = f;
|
|
||||||
var [{g},h] = i;
|
|
||||||
[{a},b] = c;
|
|
||||||
for (const [x,y] in pairs);
|
|
||||||
for (let [x,y] in pairs);
|
|
||||||
for (var [x,y] in pairs);
|
|
||||||
for ([x,y] in pairs);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
unused: {
|
|
||||||
options = {
|
|
||||||
unused: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
let { foo: [, , ...a] } = { foo: [1, 2, 3, 4], bar: 5 };
|
|
||||||
console.log(a);
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
let { foo: [, , ...a] } = { foo: [1, 2, 3, 4], bar: 5 };
|
|
||||||
console.log(a);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
issue_1886: {
|
|
||||||
options = {
|
|
||||||
collapse_vars: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
let [a] = [1];
|
|
||||||
console.log(a);
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
let [a] = [1];
|
|
||||||
console.log(a);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
destructuring_decl_of_numeric_key: {
|
|
||||||
options = {
|
|
||||||
evaluate: true,
|
|
||||||
unused: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
let { 3: x } = { [1 + 2]: 42 };
|
|
||||||
console.log(x);
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
let { 3: x } = { [3]: 42 };
|
|
||||||
console.log(x);
|
|
||||||
}
|
|
||||||
expect_stdout: "42"
|
|
||||||
node_version: ">=6"
|
|
||||||
}
|
|
||||||
|
|
||||||
destructuring_decl_of_computed_key: {
|
|
||||||
options = {
|
|
||||||
evaluate: true,
|
|
||||||
unused: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
let four = 4;
|
|
||||||
let { [7 - four]: x } = { [1 + 2]: 42 };
|
|
||||||
console.log(x);
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
let four = 4;
|
|
||||||
let { [7 - four]: x } = { [3]: 42 };
|
|
||||||
console.log(x);
|
|
||||||
}
|
|
||||||
expect_stdout: "42"
|
|
||||||
node_version: ">=6"
|
|
||||||
}
|
|
||||||
|
|
||||||
destructuring_assign_of_numeric_key: {
|
|
||||||
options = {
|
|
||||||
evaluate: true,
|
|
||||||
unused: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
let x;
|
|
||||||
({ 3: x } = { [1 + 2]: 42 });
|
|
||||||
console.log(x);
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
let x;
|
|
||||||
({ 3: x } = { [3]: 42 });
|
|
||||||
console.log(x);
|
|
||||||
}
|
|
||||||
expect_stdout: "42"
|
|
||||||
node_version: ">=6"
|
|
||||||
}
|
|
||||||
|
|
||||||
destructuring_assign_of_computed_key: {
|
|
||||||
options = {
|
|
||||||
evaluate: true,
|
|
||||||
unused: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
let x;
|
|
||||||
let four = 4;
|
|
||||||
({ [(5 + 2) - four]: x } = { [1 + 2]: 42 });
|
|
||||||
console.log(x);
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
let x;
|
|
||||||
let four = 4;
|
|
||||||
({ [7 - four]: x } = { [3]: 42 });
|
|
||||||
console.log(x);
|
|
||||||
}
|
|
||||||
expect_stdout: "42"
|
|
||||||
node_version: ">=6"
|
|
||||||
}
|
|
||||||
|
|
||||||
mangle_destructuring_decl: {
|
|
||||||
options = {
|
|
||||||
evaluate: true,
|
|
||||||
unused: true,
|
|
||||||
}
|
|
||||||
mangle = {
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
function test(opts) {
|
|
||||||
let a = opts.a || { e: 7, n: 8 };
|
|
||||||
let { t, e, n, s = 5 + 4, o, r } = a;
|
|
||||||
console.log(t, e, n, s, o, r);
|
|
||||||
}
|
|
||||||
test({a: { t: 1, e: 2, n: 3, s: 4, o: 5, r: 6 }});
|
|
||||||
test({});
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
function test(t) {
|
|
||||||
let e = t.a || { e: 7, n: 8 };
|
|
||||||
let {t: n, e: o, n: s, s: l = 9, o: a, r: c} = e;
|
|
||||||
console.log(n, o, s, l, a, c);
|
|
||||||
}
|
|
||||||
test({ a: { t: 1, e: 2, n: 3, s: 4, o: 5, r: 6 } });
|
|
||||||
test({});
|
|
||||||
}
|
|
||||||
expect_stdout: [
|
|
||||||
"1 2 3 4 5 6",
|
|
||||||
"undefined 7 8 9 undefined undefined",
|
|
||||||
]
|
|
||||||
node_version: ">=6"
|
|
||||||
}
|
|
||||||
|
|
||||||
mangle_destructuring_assign_toplevel_true: {
|
|
||||||
options = {
|
|
||||||
toplevel: true,
|
|
||||||
evaluate: true,
|
|
||||||
unused: true,
|
|
||||||
}
|
|
||||||
mangle = {
|
|
||||||
toplevel: true,
|
|
||||||
}
|
|
||||||
beautify = {
|
|
||||||
ecma: 6
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
function test(opts) {
|
|
||||||
let s, o, r;
|
|
||||||
let a = opts.a || { e: 7, n: 8 };
|
|
||||||
({ t, e, n, s = 5 + 4, o, r } = a);
|
|
||||||
console.log(t, e, n, s, o, r);
|
|
||||||
}
|
|
||||||
let t, e, n;
|
|
||||||
test({a: { t: 1, e: 2, n: 3, s: 4, o: 5, r: 6 }});
|
|
||||||
test({});
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
function e(e) {
|
|
||||||
let l, s, a;
|
|
||||||
let c = e.a || { e: 7, n: 8 };
|
|
||||||
({t: n, e: o, n: t, s: l = 9, o: s, r: a} = c);
|
|
||||||
console.log(n, o, t, l, s, a);
|
|
||||||
}
|
|
||||||
let n, o, t;
|
|
||||||
e({ a: { t: 1, e: 2, n: 3, s: 4, o: 5, r: 6 } });
|
|
||||||
e({});
|
|
||||||
}
|
|
||||||
expect_stdout: [
|
|
||||||
"1 2 3 4 5 6",
|
|
||||||
"undefined 7 8 9 undefined undefined",
|
|
||||||
]
|
|
||||||
node_version: ">=6"
|
|
||||||
}
|
|
||||||
|
|
||||||
mangle_destructuring_assign_toplevel_false: {
|
|
||||||
options = {
|
|
||||||
toplevel: false,
|
|
||||||
evaluate: true,
|
|
||||||
unused: true,
|
|
||||||
}
|
|
||||||
mangle = {
|
|
||||||
toplevel: false,
|
|
||||||
}
|
|
||||||
beautify = {
|
|
||||||
ecma: 6
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
function test(opts) {
|
|
||||||
let s, o, r;
|
|
||||||
let a = opts.a || { e: 7, n: 8 };
|
|
||||||
({ t, e, n, s = 9, o, r } = a);
|
|
||||||
console.log(t, e, n, s, o, r);
|
|
||||||
}
|
|
||||||
let t, e, n;
|
|
||||||
test({a: { t: 1, e: 2, n: 3, s: 4, o: 5, r: 6 }});
|
|
||||||
test({});
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
function test(o) {
|
|
||||||
let s, l, a;
|
|
||||||
let c = o.a || { e: 7, n: 8 };
|
|
||||||
({t, e, n, s = 9, o: l, r: a} = c);
|
|
||||||
console.log(t, e, n, s, l, a);
|
|
||||||
}
|
|
||||||
let t, e, n;
|
|
||||||
test({ a: { t: 1, e: 2, n: 3, s: 4, o: 5, r: 6 } });
|
|
||||||
test({});
|
|
||||||
}
|
|
||||||
expect_stdout: [
|
|
||||||
"1 2 3 4 5 6",
|
|
||||||
"undefined 7 8 9 undefined undefined",
|
|
||||||
]
|
|
||||||
node_version: ">=6"
|
|
||||||
}
|
|
||||||
|
|
||||||
mangle_destructuring_decl_array: {
|
|
||||||
options = {
|
|
||||||
evaluate: true,
|
|
||||||
unused: true,
|
|
||||||
toplevel: true,
|
|
||||||
}
|
|
||||||
mangle = {
|
|
||||||
toplevel: true,
|
|
||||||
}
|
|
||||||
beautify = {
|
|
||||||
ecma: 6
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
var [, t, e, n, s, o = 2, r = [ 1 + 2 ]] = [ 9, 8, 7, 6 ];
|
|
||||||
console.log(t, e, n, s, o, r);
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
var [, o, l, a, c, e = 2, g = [ 3 ]] = [ 9, 8, 7, 6 ];
|
|
||||||
console.log(o, l, a, c, e, g);
|
|
||||||
}
|
|
||||||
expect_stdout: "8 7 6 undefined 2 [ 3 ]"
|
|
||||||
node_version: ">=6"
|
|
||||||
}
|
|
||||||
|
|
||||||
anon_func_with_destructuring_args: {
|
|
||||||
options = {
|
|
||||||
evaluate: true,
|
|
||||||
unused: true,
|
|
||||||
toplevel: true,
|
|
||||||
}
|
|
||||||
mangle = {
|
|
||||||
toplevel: true,
|
|
||||||
}
|
|
||||||
beautify = {
|
|
||||||
ecma: 5,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
(function({foo = 1 + 0, bar = 2}, [car = 3, far = 4]) {
|
|
||||||
console.log(foo, bar, car, far);
|
|
||||||
})({bar: 5 - 0}, [, 6]);
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
(function({foo: o = 1, bar: n = 2}, [a = 3, b = 4]) {
|
|
||||||
console.log(o, n, a, b);
|
|
||||||
})({bar: 5}, [, 6]);
|
|
||||||
}
|
|
||||||
expect_stdout: "1 5 3 6"
|
|
||||||
node_version: ">=6"
|
|
||||||
}
|
|
||||||
|
|
||||||
arrow_func_with_destructuring_args: {
|
|
||||||
options = {
|
|
||||||
evaluate: true,
|
|
||||||
unused: true,
|
|
||||||
toplevel: true,
|
|
||||||
}
|
|
||||||
mangle = {
|
|
||||||
toplevel: true,
|
|
||||||
}
|
|
||||||
beautify = {
|
|
||||||
ecma: 5,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
(({foo = 1 + 0, bar = 2}, [car = 3, far = 4]) => {
|
|
||||||
console.log(foo, bar, car, far);
|
|
||||||
})({bar: 5 - 0}, [, 6]);
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
(({foo: o = 1, bar: a = 2}, [b = 3, l = 4]) => {
|
|
||||||
console.log(o, a, b, l);
|
|
||||||
})({bar: 5}, [, 6]);
|
|
||||||
}
|
|
||||||
expect_stdout: "1 5 3 6"
|
|
||||||
node_version: ">=6"
|
|
||||||
}
|
|
||||||
|
|
||||||
issue_2044_ecma_5: {
|
|
||||||
beautify = {
|
|
||||||
beautify: false,
|
|
||||||
ecma: 5,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
({x : a = 1, y = 2 + b, z = 3 - c} = obj);
|
|
||||||
}
|
|
||||||
expect_exact: "({x:a=1,y:y=2+b,z:z=3-c}=obj);"
|
|
||||||
}
|
|
||||||
|
|
||||||
issue_2044_ecma_6: {
|
|
||||||
beautify = {
|
|
||||||
beautify: false,
|
|
||||||
ecma: 6,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
({x : a = 1, y = 2 + b, z = 3 - c} = obj);
|
|
||||||
}
|
|
||||||
expect_exact: "({x:a=1,y=2+b,z=3-c}=obj);"
|
|
||||||
}
|
|
||||||
|
|
||||||
issue_2044_ecma_5_beautify: {
|
|
||||||
beautify = {
|
|
||||||
beautify: true,
|
|
||||||
ecma: 5,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
({x : a = 1, y = 2 + b, z = 3 - c} = obj);
|
|
||||||
}
|
|
||||||
expect_exact: "({x: a = 1, y: y = 2 + b, z: z = 3 - c} = obj);"
|
|
||||||
}
|
|
||||||
|
|
||||||
issue_2044_ecma_6_beautify: {
|
|
||||||
beautify = {
|
|
||||||
beautify: true,
|
|
||||||
ecma: 6,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
({x : a = 1, y = 2 + b, z = 3 - c} = obj);
|
|
||||||
}
|
|
||||||
expect_exact: "({x: a = 1, y = 2 + b, z = 3 - c} = obj);"
|
|
||||||
}
|
|
||||||
|
|
||||||
issue_2140: {
|
|
||||||
options = {
|
|
||||||
unused: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
!function() {
|
|
||||||
var t = {};
|
|
||||||
console.log(([t.a] = [42])[0]);
|
|
||||||
}();
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
!function() {
|
|
||||||
var t = {};
|
|
||||||
console.log(([t.a] = [42])[0]);
|
|
||||||
}();
|
|
||||||
}
|
|
||||||
expect_stdout: "42"
|
|
||||||
node_version: ">=6"
|
|
||||||
}
|
|
||||||
@@ -1,10 +0,0 @@
|
|||||||
class_directives_compression: {
|
|
||||||
input: {
|
|
||||||
class foo {
|
|
||||||
foo() {
|
|
||||||
"use strict";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
expect_exact: "class foo{foo(){}}"
|
|
||||||
}
|
|
||||||
File diff suppressed because it is too large
Load Diff
@@ -227,100 +227,6 @@ positive_zero: {
|
|||||||
expect_stdout: true
|
expect_stdout: true
|
||||||
}
|
}
|
||||||
|
|
||||||
pow: {
|
|
||||||
options = { evaluate: true }
|
|
||||||
input: {
|
|
||||||
var a = 5 ** 3;
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
var a = 125;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pow_sequence: {
|
|
||||||
options = {
|
|
||||||
evaluate: true
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
var a = 2 ** 3 ** 2;
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
var a = 512;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pow_mixed: {
|
|
||||||
options = {
|
|
||||||
evaluate: true
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
var a = 5 + 2 ** 3 + 5;
|
|
||||||
var b = 5 * 3 ** 2;
|
|
||||||
var c = 5 ** 3 * 2;
|
|
||||||
var d = 5 ** +3;
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
var a = 18;
|
|
||||||
var b = 45;
|
|
||||||
var c = 250;
|
|
||||||
var d = 125;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pow_with_right_side_evaluating_to_unary: {
|
|
||||||
options = {
|
|
||||||
evaluate: true
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
var a = (4 - 7) ** foo;
|
|
||||||
var b = ++bar ** 3;
|
|
||||||
var c = --baz ** 2;
|
|
||||||
}
|
|
||||||
expect_exact: "var a=(-3)**foo;var b=++bar**3;var c=--baz**2;"
|
|
||||||
}
|
|
||||||
|
|
||||||
pow_with_number_constants: {
|
|
||||||
options = {
|
|
||||||
evaluate: true
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
var a = 5 ** NaN;
|
|
||||||
/* NaN exponent results to NaN */
|
|
||||||
var b = 42 ** +0;
|
|
||||||
/* +0 exponent results to NaN */
|
|
||||||
var c = 42 ** -0;
|
|
||||||
/* -0 exponent results to NaN */
|
|
||||||
var d = NaN ** 1;
|
|
||||||
/* NaN with non-zero exponent is NaN */
|
|
||||||
var e = 2 ** Infinity;
|
|
||||||
/* abs(base) > 1 with Infinity as exponent is Infinity */
|
|
||||||
var f = 2 ** -Infinity;
|
|
||||||
/* abs(base) > 1 with -Infinity as exponent is +0 */
|
|
||||||
var g = (-7) ** (0.5);
|
|
||||||
var h = 2324334 ** 34343443;
|
|
||||||
var i = (-2324334) ** 34343443;
|
|
||||||
var j = 2 ** (-3);
|
|
||||||
var k = 2.0 ** -3;
|
|
||||||
var l = 2.0 ** (5 - 7);
|
|
||||||
var m = 3 ** -10; // Result will be 0.000016935087808430286, which is too long
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
var a = NaN;
|
|
||||||
var b = 1;
|
|
||||||
var c = 1;
|
|
||||||
var d = NaN;
|
|
||||||
var e = 1/0;
|
|
||||||
var f = 0;
|
|
||||||
var g = NaN;
|
|
||||||
var h = 1/0;
|
|
||||||
var i = -1/0;
|
|
||||||
var j = .125;
|
|
||||||
var k = .125;
|
|
||||||
var l = .25;
|
|
||||||
var m = 3 ** -10;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
unsafe_constant: {
|
unsafe_constant: {
|
||||||
options = {
|
options = {
|
||||||
evaluate : true,
|
evaluate : true,
|
||||||
@@ -767,16 +673,17 @@ call_args: {
|
|||||||
inline: true,
|
inline: true,
|
||||||
reduce_funcs: true,
|
reduce_funcs: true,
|
||||||
reduce_vars: true,
|
reduce_vars: true,
|
||||||
|
toplevel: true,
|
||||||
}
|
}
|
||||||
input: {
|
input: {
|
||||||
const a = 1;
|
var a = 1;
|
||||||
console.log(a);
|
console.log(a);
|
||||||
+function(a) {
|
+function(a) {
|
||||||
return a;
|
return a;
|
||||||
}(a);
|
}(a);
|
||||||
}
|
}
|
||||||
expect: {
|
expect: {
|
||||||
const a = 1;
|
var a = 1;
|
||||||
console.log(1);
|
console.log(1);
|
||||||
+(1, 1);
|
+(1, 1);
|
||||||
}
|
}
|
||||||
@@ -790,17 +697,17 @@ call_args_drop_param: {
|
|||||||
keep_fargs: false,
|
keep_fargs: false,
|
||||||
reduce_funcs: true,
|
reduce_funcs: true,
|
||||||
reduce_vars: true,
|
reduce_vars: true,
|
||||||
|
toplevel: true,
|
||||||
unused: true,
|
unused: true,
|
||||||
}
|
}
|
||||||
input: {
|
input: {
|
||||||
const a = 1;
|
var a = 1;
|
||||||
console.log(a);
|
console.log(a);
|
||||||
+function(a) {
|
+function(a) {
|
||||||
return a;
|
return a;
|
||||||
}(a, b);
|
}(a, b);
|
||||||
}
|
}
|
||||||
expect: {
|
expect: {
|
||||||
const a = 1;
|
|
||||||
console.log(1);
|
console.log(1);
|
||||||
+(b, 1);
|
+(b, 1);
|
||||||
}
|
}
|
||||||
@@ -1287,6 +1194,9 @@ issue_2231_1: {
|
|||||||
console.log(Object.keys(void 0));
|
console.log(Object.keys(void 0));
|
||||||
}
|
}
|
||||||
expect_stdout: true
|
expect_stdout: true
|
||||||
|
expect_warnings: [
|
||||||
|
"WARN: Error evaluating Object.keys(void 0) [test/compress/evaluate.js:1191,20]",
|
||||||
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
issue_2231_2: {
|
issue_2231_2: {
|
||||||
@@ -1301,6 +1211,23 @@ issue_2231_2: {
|
|||||||
console.log(Object.getOwnPropertyNames(null));
|
console.log(Object.getOwnPropertyNames(null));
|
||||||
}
|
}
|
||||||
expect_stdout: true
|
expect_stdout: true
|
||||||
|
expect_warnings: [
|
||||||
|
"WARN: Error evaluating Object.getOwnPropertyNames(null) [test/compress/evaluate.js:1208,20]",
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
|
issue_2231_3: {
|
||||||
|
options = {
|
||||||
|
evaluate: true,
|
||||||
|
unsafe: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
console.log(Object.keys({ foo: "bar" })[0]);
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
console.log("foo");
|
||||||
|
}
|
||||||
|
expect_stdout: "foo"
|
||||||
}
|
}
|
||||||
|
|
||||||
self_comparison_1: {
|
self_comparison_1: {
|
||||||
@@ -1423,13 +1350,82 @@ issue_2535_3: {
|
|||||||
}
|
}
|
||||||
expect_stdout: true
|
expect_stdout: true
|
||||||
expect_warnings: [
|
expect_warnings: [
|
||||||
"WARN: Dropping side-effect-free && [test/compress/evaluate.js:1409,20]",
|
"WARN: Dropping side-effect-free && [test/compress/evaluate.js:1336,20]",
|
||||||
"WARN: Dropping side-effect-free && [test/compress/evaluate.js:1410,20]",
|
"WARN: Dropping side-effect-free && [test/compress/evaluate.js:1337,20]",
|
||||||
"WARN: Dropping side-effect-free && [test/compress/evaluate.js:1411,20]",
|
"WARN: Dropping side-effect-free && [test/compress/evaluate.js:1338,20]",
|
||||||
"WARN: Condition left of && always false [test/compress/evaluate.js:1411,20]",
|
"WARN: Condition left of && always false [test/compress/evaluate.js:1338,20]",
|
||||||
"WARN: Dropping side-effect-free || [test/compress/evaluate.js:1412,20]",
|
"WARN: Dropping side-effect-free || [test/compress/evaluate.js:1339,20]",
|
||||||
"WARN: Dropping side-effect-free || [test/compress/evaluate.js:1413,20]",
|
"WARN: Dropping side-effect-free || [test/compress/evaluate.js:1340,20]",
|
||||||
"WARN: Dropping side-effect-free || [test/compress/evaluate.js:1414,20]",
|
"WARN: Dropping side-effect-free || [test/compress/evaluate.js:1341,20]",
|
||||||
"WARN: Condition left of || always true [test/compress/evaluate.js:1414,20]",
|
"WARN: Condition left of || always true [test/compress/evaluate.js:1341,20]",
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
|
issue_2822: {
|
||||||
|
options = {
|
||||||
|
evaluate: true,
|
||||||
|
unsafe: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
console.log([ function() {}, "PASS", "FAIL" ][1]);
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
console.log("PASS");
|
||||||
|
}
|
||||||
|
expect_stdout: "PASS"
|
||||||
|
}
|
||||||
|
|
||||||
|
string_case: {
|
||||||
|
options = {
|
||||||
|
evaluate: true,
|
||||||
|
unsafe: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
console.log("İ".toLowerCase().charCodeAt(0));
|
||||||
|
console.log("I".toLowerCase().charCodeAt(0));
|
||||||
|
console.log("Ş".toLowerCase().charCodeAt(0));
|
||||||
|
console.log("Ğ".toLowerCase().charCodeAt(0));
|
||||||
|
console.log("Ü".toLowerCase().charCodeAt(0));
|
||||||
|
console.log("Ö".toLowerCase().charCodeAt(0));
|
||||||
|
console.log("Ç".toLowerCase().charCodeAt(0));
|
||||||
|
console.log("i".toUpperCase().charCodeAt(0));
|
||||||
|
console.log("ı".toUpperCase().charCodeAt(0));
|
||||||
|
console.log("ş".toUpperCase().charCodeAt(0));
|
||||||
|
console.log("ğ".toUpperCase().charCodeAt(0));
|
||||||
|
console.log("ü".toUpperCase().charCodeAt(0));
|
||||||
|
console.log("ö".toUpperCase().charCodeAt(0));
|
||||||
|
console.log("ç".toUpperCase().charCodeAt(0));
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
console.log(105);
|
||||||
|
console.log(105);
|
||||||
|
console.log(351);
|
||||||
|
console.log(287);
|
||||||
|
console.log(252);
|
||||||
|
console.log(246);
|
||||||
|
console.log(231);
|
||||||
|
console.log(73);
|
||||||
|
console.log(73);
|
||||||
|
console.log(350);
|
||||||
|
console.log(286);
|
||||||
|
console.log(220);
|
||||||
|
console.log(214);
|
||||||
|
console.log(199);
|
||||||
|
}
|
||||||
|
expect_stdout: [
|
||||||
|
"105",
|
||||||
|
"105",
|
||||||
|
"351",
|
||||||
|
"287",
|
||||||
|
"252",
|
||||||
|
"246",
|
||||||
|
"231",
|
||||||
|
"73",
|
||||||
|
"73",
|
||||||
|
"350",
|
||||||
|
"286",
|
||||||
|
"220",
|
||||||
|
"214",
|
||||||
|
"199",
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,71 +0,0 @@
|
|||||||
|
|
||||||
expand_arguments: {
|
|
||||||
input: {
|
|
||||||
func(a, ...rest);
|
|
||||||
func(...all);
|
|
||||||
}
|
|
||||||
expect_exact: "func(a,...rest);func(...all);"
|
|
||||||
}
|
|
||||||
|
|
||||||
expand_expression_arguments: {
|
|
||||||
input: {
|
|
||||||
f(...a.b);
|
|
||||||
f(...a.b());
|
|
||||||
f(...(a));
|
|
||||||
f(...(a.b));
|
|
||||||
f(...a[i]);
|
|
||||||
}
|
|
||||||
expect_exact: "f(...a.b);f(...a.b());f(...a);f(...a.b);f(...a[i]);"
|
|
||||||
}
|
|
||||||
|
|
||||||
expand_parameters: {
|
|
||||||
input: {
|
|
||||||
(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"
|
|
||||||
}
|
|
||||||
@@ -1,264 +0,0 @@
|
|||||||
issue_2038_1: {
|
|
||||||
options = {
|
|
||||||
toplevel: true,
|
|
||||||
unused: true,
|
|
||||||
}
|
|
||||||
mangle = {
|
|
||||||
toplevel: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
export var V = 1;
|
|
||||||
export let L = 2;
|
|
||||||
export const C = 3;
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
export var V = 1;
|
|
||||||
export let L = 2;
|
|
||||||
export const C = 3;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
issue_2038_2: {
|
|
||||||
options = {
|
|
||||||
toplevel: true,
|
|
||||||
unused: true,
|
|
||||||
}
|
|
||||||
mangle = {
|
|
||||||
toplevel: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
let LET = 1;
|
|
||||||
const CONST = 2;
|
|
||||||
var VAR = 3;
|
|
||||||
export { LET, CONST, VAR };
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
let t = 1;
|
|
||||||
const e = 2;
|
|
||||||
var o = 3;
|
|
||||||
export { t as LET, e as CONST, o as VAR };
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
issue_2126: {
|
|
||||||
mangle = {
|
|
||||||
toplevel: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
import { foo as bar, cat as dog } from "stuff";
|
|
||||||
console.log(bar, dog);
|
|
||||||
export { bar as qux };
|
|
||||||
export { dog };
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
import { foo as o, cat as s } from "stuff";
|
|
||||||
console.log(o, s);
|
|
||||||
export { o as qux };
|
|
||||||
export { s as dog };
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
beautify: {
|
|
||||||
beautify = {
|
|
||||||
beautify: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
export { A as B, C as D };
|
|
||||||
}
|
|
||||||
expect_exact: "export { A as B, C as D };"
|
|
||||||
}
|
|
||||||
|
|
||||||
issue_2131: {
|
|
||||||
options = {
|
|
||||||
toplevel: true,
|
|
||||||
unused: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
function no() {
|
|
||||||
console.log(42);
|
|
||||||
}
|
|
||||||
function go() {
|
|
||||||
console.log(42);
|
|
||||||
}
|
|
||||||
var X = 1, Y = 2;
|
|
||||||
export function main() {
|
|
||||||
go(X);
|
|
||||||
};
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
function go() {
|
|
||||||
console.log(42);
|
|
||||||
}
|
|
||||||
var X = 1;
|
|
||||||
export function main() {
|
|
||||||
go(X);
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
issue_2129: {
|
|
||||||
mangle = {
|
|
||||||
toplevel: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
export const { keys } = Object;
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
export const { keys } = Object;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
async_func: {
|
|
||||||
options = {
|
|
||||||
keep_fargs: false,
|
|
||||||
unused: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
export async function Foo(x){};
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
export async function Foo(){};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
issue_2134_1: {
|
|
||||||
options = {
|
|
||||||
keep_fargs: false,
|
|
||||||
reduce_funcs: true,
|
|
||||||
reduce_vars: true,
|
|
||||||
toplevel: true,
|
|
||||||
unused: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
export function Foo(x){};
|
|
||||||
Foo.prototype = {};
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
export function Foo(){};
|
|
||||||
Foo.prototype = {};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
issue_2134_2: {
|
|
||||||
options = {
|
|
||||||
keep_fargs: false,
|
|
||||||
reduce_funcs: true,
|
|
||||||
reduce_vars: true,
|
|
||||||
toplevel: true,
|
|
||||||
unused: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
export async function Foo(x){};
|
|
||||||
Foo.prototype = {};
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
export async function Foo(){};
|
|
||||||
Foo.prototype = {};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
redirection: {
|
|
||||||
mangle = {
|
|
||||||
toplevel: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
let foo = 1, bar = 2;
|
|
||||||
export { foo as delete };
|
|
||||||
export { bar as default };
|
|
||||||
export { foo as var } from "module.js";
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
let e = 1, o = 2;
|
|
||||||
export { e as delete };
|
|
||||||
export { o as default };
|
|
||||||
export { foo as var } from "module.js";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
keyword_invalid_1: {
|
|
||||||
input: {
|
|
||||||
export { default };
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
export { default };
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
keyword_invalid_2: {
|
|
||||||
input: {
|
|
||||||
export { default as Alias };
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
export { default as Alias };
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
keyword_invalid_3: {
|
|
||||||
input: {
|
|
||||||
export { default as default };
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
export { default as default };
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
keyword_valid_1: {
|
|
||||||
input: {
|
|
||||||
export { default } from "module.js";
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
export { default } from "module.js";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
keyword_valid_2: {
|
|
||||||
input: {
|
|
||||||
export { default as Alias } from "module.js";
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
export { default as Alias } from "module.js";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
keyword_valid_3: {
|
|
||||||
input: {
|
|
||||||
export { default as default } from "module.js";
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
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;"
|
|
||||||
}
|
|
||||||
@@ -1,52 +0,0 @@
|
|||||||
pow: {
|
|
||||||
input: {
|
|
||||||
var a = 2 ** 7;
|
|
||||||
var b = 3;
|
|
||||||
b **= 2;
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
var a = 2 ** 7;
|
|
||||||
var b = 3;
|
|
||||||
b **= 2;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pow_with_number_constants: {
|
|
||||||
input: {
|
|
||||||
var a = 5 ** NaN;
|
|
||||||
var b = 42 ** +0;
|
|
||||||
var c = 42 ** -0;
|
|
||||||
var d = NaN ** 1;
|
|
||||||
var e = 2 ** Infinity;
|
|
||||||
var f = 2 ** -Infinity;
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
var a = 5 ** NaN;
|
|
||||||
var b = 42 ** +0;
|
|
||||||
var c = 42 ** -0;
|
|
||||||
var d = NaN ** 1;
|
|
||||||
var e = 2 ** (1/0);
|
|
||||||
var f = 2 ** (-1/0);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pow_with_parentheses: {
|
|
||||||
input: {
|
|
||||||
var g = (-7) ** (0.5);
|
|
||||||
var h = 2324334 ** 34343443;
|
|
||||||
var i = (-2324334) ** 34343443;
|
|
||||||
var j = 2 ** (-3);
|
|
||||||
var k = 2.0 ** -3;
|
|
||||||
var l = 2.0 ** (5 - 7);
|
|
||||||
}
|
|
||||||
expect_exact: "var g=(-7)**.5;var h=2324334**34343443;var i=(-2324334)**34343443;var j=2**-3;var k=2**-3;var l=2**(5-7);"
|
|
||||||
}
|
|
||||||
|
|
||||||
pow_with_unary_between_brackets: {
|
|
||||||
input: {
|
|
||||||
var a = (-(+5)) ** 3;
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
var a = (-+5)**3;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
File diff suppressed because it is too large
Load Diff
@@ -121,7 +121,7 @@ mixed: {
|
|||||||
properties: true,
|
properties: true,
|
||||||
}
|
}
|
||||||
input: {
|
input: {
|
||||||
const FOO = { BAR: 0 };
|
var FOO = { BAR: 0 };
|
||||||
console.log(FOO.BAR);
|
console.log(FOO.BAR);
|
||||||
console.log(++CONFIG.DEBUG);
|
console.log(++CONFIG.DEBUG);
|
||||||
console.log(++CONFIG.VALUE);
|
console.log(++CONFIG.VALUE);
|
||||||
@@ -131,7 +131,7 @@ mixed: {
|
|||||||
console.log(CONFIG);
|
console.log(CONFIG);
|
||||||
}
|
}
|
||||||
expect: {
|
expect: {
|
||||||
const FOO = { BAR: 0 };
|
var FOO = { BAR: 0 };
|
||||||
console.log("moo");
|
console.log("moo");
|
||||||
console.log(++CONFIG.DEBUG);
|
console.log(++CONFIG.DEBUG);
|
||||||
console.log(++CONFIG.VALUE);
|
console.log(++CONFIG.VALUE);
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@@ -1,85 +0,0 @@
|
|||||||
|
|
||||||
hoist_vars: {
|
|
||||||
options = {
|
|
||||||
hoist_vars: true
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
function a() {
|
|
||||||
bar();
|
|
||||||
var var1;
|
|
||||||
var var2;
|
|
||||||
}
|
|
||||||
function b(anArg) {
|
|
||||||
bar();
|
|
||||||
var var1;
|
|
||||||
var anArg;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
function a() {
|
|
||||||
var var1, var2; // Vars go up and are joined
|
|
||||||
bar();
|
|
||||||
}
|
|
||||||
function b(anArg) {
|
|
||||||
var var1;
|
|
||||||
bar();
|
|
||||||
// But vars named like arguments go away!
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
hoist_funs: {
|
|
||||||
options = {
|
|
||||||
hoist_funs: true
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
function a() {
|
|
||||||
bar();
|
|
||||||
function foo() {}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
function a() {
|
|
||||||
function foo() {} // Funs go up
|
|
||||||
bar();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
hoist_no_destructurings: {
|
|
||||||
options = {
|
|
||||||
hoist_vars: true,
|
|
||||||
hoist_funs: true
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
function a([anArg]) {
|
|
||||||
bar();
|
|
||||||
var var1;
|
|
||||||
var anArg; // Because anArg is already declared, this goes away!
|
|
||||||
}
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
function a([anArg]) {
|
|
||||||
var var1;
|
|
||||||
bar();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
dont_hoist_var_destructurings: {
|
|
||||||
options = {
|
|
||||||
hoist_vars: true,
|
|
||||||
hoist_funs: true
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
function x() {
|
|
||||||
// If foo is null or undefined, this should be an exception
|
|
||||||
var {x,y} = foo;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
function x() {
|
|
||||||
var {x,y} = foo;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -55,9 +55,8 @@ issue_2377_2: {
|
|||||||
console.log(obj.foo, obj.cube(3));
|
console.log(obj.foo, obj.cube(3));
|
||||||
}
|
}
|
||||||
expect: {
|
expect: {
|
||||||
console.log(1, function(x) {
|
console.log(1, (x = 3, x * x * x));
|
||||||
return x * x * x;
|
var x;
|
||||||
}(3));
|
|
||||||
}
|
}
|
||||||
expect_stdout: "1 27"
|
expect_stdout: "1 27"
|
||||||
}
|
}
|
||||||
@@ -67,9 +66,10 @@ issue_2377_3: {
|
|||||||
evaluate: true,
|
evaluate: true,
|
||||||
inline: true,
|
inline: true,
|
||||||
hoist_props: true,
|
hoist_props: true,
|
||||||
passes: 3,
|
passes: 4,
|
||||||
reduce_funcs: true,
|
reduce_funcs: true,
|
||||||
reduce_vars: true,
|
reduce_vars: true,
|
||||||
|
side_effects: true,
|
||||||
toplevel: true,
|
toplevel: true,
|
||||||
unused: true,
|
unused: true,
|
||||||
}
|
}
|
||||||
@@ -383,120 +383,6 @@ contains_this_3: {
|
|||||||
expect_stdout: "1 1 true"
|
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: {
|
|
||||||
var o_p = class Foo {
|
|
||||||
constructor(value) {
|
|
||||||
this.value = 10 * value;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
console.log(o_p.name, true, new o_p(1).value, new o_p(2).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: {
|
new_this: {
|
||||||
options = {
|
options = {
|
||||||
evaluate: true,
|
evaluate: true,
|
||||||
@@ -526,26 +412,6 @@ new_this: {
|
|||||||
expect_stdout: "1 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: {
|
issue_2473_1: {
|
||||||
options = {
|
options = {
|
||||||
hoist_props: false,
|
hoist_props: false,
|
||||||
@@ -768,31 +634,6 @@ issue_2508_5: {
|
|||||||
expect_stdout: true
|
expect_stdout: true
|
||||||
}
|
}
|
||||||
|
|
||||||
issue_2508_6: {
|
|
||||||
options = {
|
|
||||||
collapse_vars: true,
|
|
||||||
hoist_props: true,
|
|
||||||
reduce_vars: true,
|
|
||||||
toplevel: true,
|
|
||||||
unused: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
var o = {
|
|
||||||
f: x => {
|
|
||||||
console.log(x);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
o.f(o.f);
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
var o_f = x => {
|
|
||||||
console.log(x);
|
|
||||||
};
|
|
||||||
o_f(o_f);
|
|
||||||
}
|
|
||||||
expect_stdout: true
|
|
||||||
}
|
|
||||||
|
|
||||||
issue_2519: {
|
issue_2519: {
|
||||||
options = {
|
options = {
|
||||||
collapse_vars: true,
|
collapse_vars: true,
|
||||||
@@ -823,3 +664,25 @@ issue_2519: {
|
|||||||
}
|
}
|
||||||
expect_stdout: "5.5"
|
expect_stdout: "5.5"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
undefined_key: {
|
||||||
|
options = {
|
||||||
|
evaluate: true,
|
||||||
|
hoist_props: true,
|
||||||
|
join_vars: true,
|
||||||
|
passes: 4,
|
||||||
|
reduce_vars: true,
|
||||||
|
toplevel: true,
|
||||||
|
unused: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
var a, o = {};
|
||||||
|
o[a] = 1;
|
||||||
|
o.b = 2;
|
||||||
|
console.log(o[a] + o.b);
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
console.log(3);
|
||||||
|
}
|
||||||
|
expect_stdout: "3"
|
||||||
|
}
|
||||||
|
|||||||
@@ -53,12 +53,3 @@ html_comment_in_string_literal: {
|
|||||||
}
|
}
|
||||||
expect_exact: 'function f(){return"\\x3c!--HTML--\\x3ecomment in\\x3c!--string literal--\\x3e"}';
|
expect_exact: 'function f(){return"\\x3c!--HTML--\\x3ecomment in\\x3c!--string literal--\\x3e"}';
|
||||||
}
|
}
|
||||||
|
|
||||||
html_comment_after_multiline_comment: {
|
|
||||||
input: {
|
|
||||||
var foo; /*
|
|
||||||
*/--> var bar;
|
|
||||||
var foobar;
|
|
||||||
}
|
|
||||||
expect_exact: "var foo;var foobar;"
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -327,60 +327,72 @@ issue_512: {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
issue_1317: {
|
if_var_return: {
|
||||||
options = {
|
options = {
|
||||||
|
conditionals: true,
|
||||||
if_return: true,
|
if_return: true,
|
||||||
|
join_vars: true,
|
||||||
|
sequences: true,
|
||||||
}
|
}
|
||||||
input: {
|
input: {
|
||||||
!function(a) {
|
function f() {
|
||||||
if (a) return;
|
var a;
|
||||||
let b = 1;
|
return;
|
||||||
function g() {
|
var b;
|
||||||
return b;
|
}
|
||||||
|
function g() {
|
||||||
|
var a;
|
||||||
|
if (u()) {
|
||||||
|
var b;
|
||||||
|
return v();
|
||||||
|
var c;
|
||||||
}
|
}
|
||||||
console.log(g());
|
var d;
|
||||||
}();
|
if (w()) {
|
||||||
|
var e;
|
||||||
|
return x();
|
||||||
|
var f;
|
||||||
|
} else {
|
||||||
|
var g;
|
||||||
|
y();
|
||||||
|
var h;
|
||||||
|
}
|
||||||
|
var i;
|
||||||
|
z();
|
||||||
|
var j;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
expect: {
|
expect: {
|
||||||
!function(a) {
|
function f() {
|
||||||
if (a) return;
|
var a, b;
|
||||||
let b = 1;
|
}
|
||||||
function g() {
|
function g() {
|
||||||
return b;
|
var a, b, c, d, e, f, g, h, i, j;
|
||||||
}
|
return u() ? v() : w() ? x() : (y(), z(), void 0);
|
||||||
console.log(g());
|
}
|
||||||
}();
|
|
||||||
}
|
}
|
||||||
expect_stdout: "1"
|
|
||||||
node_version: ">=6"
|
|
||||||
}
|
}
|
||||||
|
|
||||||
issue_1317_strict: {
|
if_if_return_return: {
|
||||||
options = {
|
options = {
|
||||||
|
conditionals: true,
|
||||||
if_return: true,
|
if_return: true,
|
||||||
}
|
}
|
||||||
input: {
|
input: {
|
||||||
"use strict";
|
function f(a, b) {
|
||||||
!function(a) {
|
if (a) {
|
||||||
if (a) return;
|
if (b)
|
||||||
let b = 1;
|
return b;
|
||||||
function g() {
|
return;
|
||||||
return b;
|
|
||||||
}
|
}
|
||||||
console.log(g());
|
g();
|
||||||
}();
|
}
|
||||||
}
|
}
|
||||||
expect: {
|
expect: {
|
||||||
"use strict";
|
function f(a, b) {
|
||||||
!function(a) {
|
if (a)
|
||||||
if (a) return;
|
return b || void 0;
|
||||||
let b = 1;
|
g();
|
||||||
function g() {
|
}
|
||||||
return b;
|
|
||||||
}
|
|
||||||
console.log(g());
|
|
||||||
}();
|
|
||||||
}
|
}
|
||||||
expect_stdout: "1"
|
|
||||||
node_version: ">=4"
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,8 +0,0 @@
|
|||||||
parenthesis_strings_in_parenthesis: {
|
|
||||||
input: {
|
|
||||||
var foo = ('(');
|
|
||||||
a(')');
|
|
||||||
|
|
||||||
}
|
|
||||||
expect_exact: 'var foo="(";a(")");'
|
|
||||||
}
|
|
||||||
@@ -2,7 +2,7 @@ non_hoisted_function_after_return: {
|
|||||||
options = {
|
options = {
|
||||||
hoist_funs: false, dead_code: true, conditionals: true, comparisons: true,
|
hoist_funs: false, dead_code: true, conditionals: true, comparisons: true,
|
||||||
evaluate: true, booleans: true, loops: true, unused: true, keep_fargs: true,
|
evaluate: true, booleans: true, loops: true, unused: true, keep_fargs: true,
|
||||||
if_return: true, join_vars: true, cascade: true, side_effects: true
|
if_return: true, join_vars: true, side_effects: true
|
||||||
}
|
}
|
||||||
input: {
|
input: {
|
||||||
function foo(x) {
|
function foo(x) {
|
||||||
@@ -38,7 +38,7 @@ non_hoisted_function_after_return_2a: {
|
|||||||
options = {
|
options = {
|
||||||
hoist_funs: false, dead_code: true, conditionals: true, comparisons: true,
|
hoist_funs: false, dead_code: true, conditionals: true, comparisons: true,
|
||||||
evaluate: true, booleans: true, loops: true, unused: true, keep_fargs: true,
|
evaluate: true, booleans: true, loops: true, unused: true, keep_fargs: true,
|
||||||
if_return: true, join_vars: true, cascade: true, side_effects: true,
|
if_return: true, join_vars: true, side_effects: true,
|
||||||
collapse_vars: false, passes: 2, warnings: "verbose"
|
collapse_vars: false, passes: 2, warnings: "verbose"
|
||||||
}
|
}
|
||||||
input: {
|
input: {
|
||||||
@@ -85,7 +85,7 @@ non_hoisted_function_after_return_2b: {
|
|||||||
options = {
|
options = {
|
||||||
hoist_funs: false, dead_code: true, conditionals: true, comparisons: true,
|
hoist_funs: false, dead_code: true, conditionals: true, comparisons: true,
|
||||||
evaluate: true, booleans: true, loops: true, unused: true, keep_fargs: true,
|
evaluate: true, booleans: true, loops: true, unused: true, keep_fargs: true,
|
||||||
if_return: true, join_vars: true, cascade: true, side_effects: true,
|
if_return: true, join_vars: true, side_effects: true,
|
||||||
collapse_vars: false
|
collapse_vars: false
|
||||||
}
|
}
|
||||||
input: {
|
input: {
|
||||||
@@ -123,7 +123,7 @@ non_hoisted_function_after_return_strict: {
|
|||||||
options = {
|
options = {
|
||||||
hoist_funs: false, dead_code: true, conditionals: true, comparisons: true,
|
hoist_funs: false, dead_code: true, conditionals: true, comparisons: true,
|
||||||
evaluate: true, booleans: true, loops: true, unused: true, keep_fargs: true,
|
evaluate: true, booleans: true, loops: true, unused: true, keep_fargs: true,
|
||||||
if_return: true, join_vars: true, cascade: true, side_effects: true
|
if_return: true, join_vars: true, side_effects: true
|
||||||
}
|
}
|
||||||
input: {
|
input: {
|
||||||
"use strict";
|
"use strict";
|
||||||
@@ -164,7 +164,7 @@ non_hoisted_function_after_return_2a_strict: {
|
|||||||
options = {
|
options = {
|
||||||
hoist_funs: false, dead_code: true, conditionals: true, comparisons: true,
|
hoist_funs: false, dead_code: true, conditionals: true, comparisons: true,
|
||||||
evaluate: true, booleans: true, loops: true, unused: true, keep_fargs: true,
|
evaluate: true, booleans: true, loops: true, unused: true, keep_fargs: true,
|
||||||
if_return: true, join_vars: true, cascade: true, side_effects: true,
|
if_return: true, join_vars: true, side_effects: true,
|
||||||
collapse_vars: false, passes: 2, warnings: "verbose"
|
collapse_vars: false, passes: 2, warnings: "verbose"
|
||||||
}
|
}
|
||||||
input: {
|
input: {
|
||||||
@@ -216,7 +216,7 @@ non_hoisted_function_after_return_2b_strict: {
|
|||||||
options = {
|
options = {
|
||||||
hoist_funs: false, dead_code: true, conditionals: true, comparisons: true,
|
hoist_funs: false, dead_code: true, conditionals: true, comparisons: true,
|
||||||
evaluate: true, booleans: true, loops: true, unused: true, keep_fargs: true,
|
evaluate: true, booleans: true, loops: true, unused: true, keep_fargs: true,
|
||||||
if_return: true, join_vars: true, cascade: true, side_effects: true,
|
if_return: true, join_vars: true, side_effects: true,
|
||||||
collapse_vars: false
|
collapse_vars: false
|
||||||
}
|
}
|
||||||
input: {
|
input: {
|
||||||
|
|||||||
@@ -1,16 +1,3 @@
|
|||||||
const_declaration: {
|
|
||||||
options = {
|
|
||||||
evaluate: true
|
|
||||||
};
|
|
||||||
|
|
||||||
input: {
|
|
||||||
const goog = goog || {};
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
const goog = goog || {};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const_pragma: {
|
const_pragma: {
|
||||||
options = {
|
options = {
|
||||||
evaluate: true,
|
evaluate: true,
|
||||||
|
|||||||
@@ -1,30 +0,0 @@
|
|||||||
issue_1043: {
|
|
||||||
options = {
|
|
||||||
side_effects: true
|
|
||||||
};
|
|
||||||
|
|
||||||
input: {
|
|
||||||
function* range(start = 0, end = null, step = 1) {
|
|
||||||
if (end == null) {
|
|
||||||
end = start;
|
|
||||||
start = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (let i = start; i < end; i += step) {
|
|
||||||
yield i;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
expect: {
|
|
||||||
function* range(start = 0, end = null, step = 1) {
|
|
||||||
if (null == end) {
|
|
||||||
end = start;
|
|
||||||
start = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (let i = start; i < end; i += step)
|
|
||||||
yield i;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,9 +0,0 @@
|
|||||||
issue_1044: {
|
|
||||||
options = { evaluate: true, conditionals: true };
|
|
||||||
input: {
|
|
||||||
const mixed = Base ? class extends Base {} : class {}
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
const mixed = Base ? class extends Base {} : class {}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -134,8 +134,9 @@ defun_hoist_funs: {
|
|||||||
expect: {
|
expect: {
|
||||||
function e() {
|
function e() {
|
||||||
function f() {}
|
function f() {}
|
||||||
|
function g() {}
|
||||||
function h() {}
|
function h() {}
|
||||||
if (window) function g() {}
|
if (window);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -190,7 +190,6 @@ assorted_Infinity_NaN_undefined_in_with_scope: {
|
|||||||
keep_fargs: true,
|
keep_fargs: true,
|
||||||
if_return: true,
|
if_return: true,
|
||||||
join_vars: true,
|
join_vars: true,
|
||||||
cascade: true,
|
|
||||||
side_effects: true,
|
side_effects: true,
|
||||||
sequences: false,
|
sequences: false,
|
||||||
keep_infinity: false,
|
keep_infinity: false,
|
||||||
@@ -253,7 +252,6 @@ assorted_Infinity_NaN_undefined_in_with_scope_keep_infinity: {
|
|||||||
keep_fargs: true,
|
keep_fargs: true,
|
||||||
if_return: true,
|
if_return: true,
|
||||||
join_vars: true,
|
join_vars: true,
|
||||||
cascade: true,
|
|
||||||
side_effects: true,
|
side_effects: true,
|
||||||
sequences: false,
|
sequences: false,
|
||||||
keep_infinity: true,
|
keep_infinity: true,
|
||||||
|
|||||||
@@ -1,76 +0,0 @@
|
|||||||
issue_1212_debug_false: {
|
|
||||||
options = {
|
|
||||||
global_defs : { DEBUG: false },
|
|
||||||
sequences : true,
|
|
||||||
properties : true,
|
|
||||||
dead_code : true,
|
|
||||||
conditionals : true,
|
|
||||||
comparisons : true,
|
|
||||||
evaluate : true,
|
|
||||||
booleans : true,
|
|
||||||
loops : true,
|
|
||||||
unused : true,
|
|
||||||
hoist_funs : true,
|
|
||||||
keep_fargs : true,
|
|
||||||
if_return : true,
|
|
||||||
join_vars : true,
|
|
||||||
cascade : true,
|
|
||||||
side_effects : true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
class foo {
|
|
||||||
bar() {
|
|
||||||
if (DEBUG)
|
|
||||||
console.log("DEV");
|
|
||||||
else
|
|
||||||
console.log("PROD");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
new foo().bar();
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
class foo{
|
|
||||||
bar() { console.log("PROD") }
|
|
||||||
}
|
|
||||||
(new foo).bar();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
issue_1212_debug_true: {
|
|
||||||
options = {
|
|
||||||
global_defs : { DEBUG: true },
|
|
||||||
sequences : true,
|
|
||||||
properties : true,
|
|
||||||
dead_code : true,
|
|
||||||
conditionals : true,
|
|
||||||
comparisons : true,
|
|
||||||
evaluate : true,
|
|
||||||
booleans : true,
|
|
||||||
loops : true,
|
|
||||||
unused : true,
|
|
||||||
hoist_funs : true,
|
|
||||||
keep_fargs : true,
|
|
||||||
if_return : true,
|
|
||||||
join_vars : true,
|
|
||||||
cascade : true,
|
|
||||||
side_effects : true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
class foo {
|
|
||||||
bar() {
|
|
||||||
if (DEBUG)
|
|
||||||
console.log("DEV");
|
|
||||||
else
|
|
||||||
console.log("PROD");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
new foo().bar();
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
class foo{
|
|
||||||
bar() { console.log("DEV") }
|
|
||||||
}
|
|
||||||
(new foo).bar();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@@ -8,7 +8,6 @@ pure_function_calls: {
|
|||||||
unused : true,
|
unused : true,
|
||||||
if_return : true,
|
if_return : true,
|
||||||
join_vars : true,
|
join_vars : true,
|
||||||
cascade : true,
|
|
||||||
negate_iife : true,
|
negate_iife : true,
|
||||||
}
|
}
|
||||||
input: {
|
input: {
|
||||||
@@ -49,13 +48,13 @@ pure_function_calls: {
|
|||||||
a.b(), f.g();
|
a.b(), f.g();
|
||||||
}
|
}
|
||||||
expect_warnings: [
|
expect_warnings: [
|
||||||
"WARN: Dropping __PURE__ call [test/compress/issue-1261.js:17,8]",
|
"WARN: Dropping __PURE__ call [test/compress/issue-1261.js:16,8]",
|
||||||
"WARN: Dropping side-effect-free statement [test/compress/issue-1261.js:17,8]",
|
"WARN: Dropping side-effect-free statement [test/compress/issue-1261.js:16,8]",
|
||||||
"WARN: Dropping __PURE__ call [test/compress/issue-1261.js:30,37]",
|
"WARN: Dropping __PURE__ call [test/compress/issue-1261.js:29,37]",
|
||||||
"WARN: Dropping unused variable iife2 [test/compress/issue-1261.js:30,16]",
|
"WARN: Dropping unused variable iife2 [test/compress/issue-1261.js:29,16]",
|
||||||
"WARN: Dropping side-effect-free statement [test/compress/issue-1261.js:28,8]",
|
"WARN: Dropping side-effect-free statement [test/compress/issue-1261.js:27,8]",
|
||||||
"WARN: Dropping __PURE__ call [test/compress/issue-1261.js:38,8]",
|
"WARN: Dropping __PURE__ call [test/compress/issue-1261.js:37,8]",
|
||||||
"WARN: Dropping __PURE__ call [test/compress/issue-1261.js:39,31]",
|
"WARN: Dropping __PURE__ call [test/compress/issue-1261.js:38,31]",
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -69,7 +68,6 @@ pure_function_calls_toplevel: {
|
|||||||
unused : true,
|
unused : true,
|
||||||
if_return : true,
|
if_return : true,
|
||||||
join_vars : true,
|
join_vars : true,
|
||||||
cascade : true,
|
|
||||||
negate_iife : true,
|
negate_iife : true,
|
||||||
toplevel : true,
|
toplevel : true,
|
||||||
}
|
}
|
||||||
@@ -112,17 +110,17 @@ pure_function_calls_toplevel: {
|
|||||||
a.b(), f.g();
|
a.b(), f.g();
|
||||||
}
|
}
|
||||||
expect_warnings: [
|
expect_warnings: [
|
||||||
"WARN: Dropping __PURE__ call [test/compress/issue-1261.js:79,8]",
|
"WARN: Dropping __PURE__ call [test/compress/issue-1261.js:77,8]",
|
||||||
"WARN: Dropping side-effect-free statement [test/compress/issue-1261.js:79,8]",
|
"WARN: Dropping side-effect-free statement [test/compress/issue-1261.js:77,8]",
|
||||||
"WARN: Dropping __PURE__ call [test/compress/issue-1261.js:92,37]",
|
"WARN: Dropping __PURE__ call [test/compress/issue-1261.js:90,37]",
|
||||||
"WARN: Dropping unused variable iife2 [test/compress/issue-1261.js:92,16]",
|
"WARN: Dropping unused variable iife2 [test/compress/issue-1261.js:90,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:88,8]",
|
||||||
"WARN: Dropping __PURE__ call [test/compress/issue-1261.js:107,8]",
|
"WARN: Dropping __PURE__ call [test/compress/issue-1261.js:105,8]",
|
||||||
"WARN: Dropping __PURE__ call [test/compress/issue-1261.js:108,31]",
|
"WARN: Dropping __PURE__ call [test/compress/issue-1261.js:106,31]",
|
||||||
"WARN: Dropping __PURE__ call [test/compress/issue-1261.js:84,33]",
|
"WARN: Dropping __PURE__ call [test/compress/issue-1261.js:82,33]",
|
||||||
"WARN: Dropping unused variable iife1 [test/compress/issue-1261.js:84,12]",
|
"WARN: Dropping unused variable iife1 [test/compress/issue-1261.js:82,12]",
|
||||||
"WARN: Dropping __PURE__ call [test/compress/issue-1261.js:100,45]",
|
"WARN: Dropping __PURE__ call [test/compress/issue-1261.js:98,45]",
|
||||||
"WARN: Dropping unused variable MyClass [test/compress/issue-1261.js:100,12]",
|
"WARN: Dropping unused variable MyClass [test/compress/issue-1261.js:98,12]",
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -157,29 +155,29 @@ should_warn: {
|
|||||||
baz();
|
baz();
|
||||||
}
|
}
|
||||||
expect_warnings: [
|
expect_warnings: [
|
||||||
"WARN: Dropping __PURE__ call [test/compress/issue-1261.js:137,61]",
|
"WARN: Dropping __PURE__ call [test/compress/issue-1261.js:135,61]",
|
||||||
"WARN: Dropping __PURE__ call [test/compress/issue-1261.js:137,23]",
|
"WARN: Dropping __PURE__ call [test/compress/issue-1261.js:135,23]",
|
||||||
"WARN: Dropping side-effect-free statement [test/compress/issue-1261.js:137,23]",
|
"WARN: Dropping side-effect-free statement [test/compress/issue-1261.js:135,23]",
|
||||||
"WARN: Boolean || always true [test/compress/issue-1261.js:138,23]",
|
"WARN: Boolean || always true [test/compress/issue-1261.js:136,23]",
|
||||||
|
"WARN: Dropping __PURE__ call [test/compress/issue-1261.js:136,23]",
|
||||||
|
"WARN: Condition always true [test/compress/issue-1261.js:136,23]",
|
||||||
|
"WARN: Condition left of || always true [test/compress/issue-1261.js:137,8]",
|
||||||
|
"WARN: Condition always true [test/compress/issue-1261.js:137,8]",
|
||||||
|
"WARN: Boolean && always false [test/compress/issue-1261.js:138,23]",
|
||||||
"WARN: Dropping __PURE__ call [test/compress/issue-1261.js:138,23]",
|
"WARN: Dropping __PURE__ call [test/compress/issue-1261.js:138,23]",
|
||||||
"WARN: Condition always true [test/compress/issue-1261.js:138,23]",
|
"WARN: Condition always false [test/compress/issue-1261.js:138,23]",
|
||||||
"WARN: Condition left of || always true [test/compress/issue-1261.js:139,8]",
|
"WARN: Condition left of && always false [test/compress/issue-1261.js:139,8]",
|
||||||
"WARN: Condition always true [test/compress/issue-1261.js:139,8]",
|
"WARN: Condition always false [test/compress/issue-1261.js:139,8]",
|
||||||
"WARN: Boolean && always false [test/compress/issue-1261.js:140,23]",
|
"WARN: + in boolean context always true [test/compress/issue-1261.js:140,23]",
|
||||||
"WARN: Dropping __PURE__ call [test/compress/issue-1261.js:140,23]",
|
"WARN: Dropping __PURE__ call [test/compress/issue-1261.js:140,23]",
|
||||||
"WARN: Condition always false [test/compress/issue-1261.js:140,23]",
|
"WARN: Condition always true [test/compress/issue-1261.js:140,23]",
|
||||||
"WARN: Condition left of && always false [test/compress/issue-1261.js:141,8]",
|
"WARN: + in boolean context always true [test/compress/issue-1261.js:141,8]",
|
||||||
"WARN: Condition always false [test/compress/issue-1261.js:141,8]",
|
"WARN: Dropping __PURE__ call [test/compress/issue-1261.js:141,31]",
|
||||||
"WARN: + in boolean context always true [test/compress/issue-1261.js:142,23]",
|
"WARN: Condition always true [test/compress/issue-1261.js:141,8]",
|
||||||
"WARN: Dropping __PURE__ call [test/compress/issue-1261.js:142,23]",
|
"WARN: Dropping __PURE__ call [test/compress/issue-1261.js:142,23]",
|
||||||
"WARN: Condition always true [test/compress/issue-1261.js:142,23]",
|
"WARN: Dropping __PURE__ call [test/compress/issue-1261.js:143,24]",
|
||||||
"WARN: + in boolean context always true [test/compress/issue-1261.js:143,8]",
|
|
||||||
"WARN: Dropping __PURE__ call [test/compress/issue-1261.js:143,31]",
|
|
||||||
"WARN: Condition always true [test/compress/issue-1261.js:143,8]",
|
"WARN: Condition always true [test/compress/issue-1261.js:143,8]",
|
||||||
"WARN: Dropping __PURE__ call [test/compress/issue-1261.js:144,23]",
|
"WARN: Dropping __PURE__ call [test/compress/issue-1261.js:144,31]",
|
||||||
"WARN: Dropping __PURE__ call [test/compress/issue-1261.js:145,24]",
|
"WARN: Condition always false [test/compress/issue-1261.js:144,8]",
|
||||||
"WARN: Condition always true [test/compress/issue-1261.js:145,8]",
|
|
||||||
"WARN: Dropping __PURE__ call [test/compress/issue-1261.js:146,31]",
|
|
||||||
"WARN: Condition always false [test/compress/issue-1261.js:146,8]",
|
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,7 +9,6 @@ string_plus_optimization: {
|
|||||||
unused : true,
|
unused : true,
|
||||||
if_return : true,
|
if_return : true,
|
||||||
join_vars : true,
|
join_vars : true,
|
||||||
cascade : true,
|
|
||||||
hoist_funs : true,
|
hoist_funs : true,
|
||||||
};
|
};
|
||||||
input: {
|
input: {
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ unsafe_undefined: {
|
|||||||
options = {
|
options = {
|
||||||
conditionals: true,
|
conditionals: true,
|
||||||
if_return: true,
|
if_return: true,
|
||||||
unsafe: true
|
unsafe_undefined: true,
|
||||||
}
|
}
|
||||||
mangle = {}
|
mangle = {}
|
||||||
input: {
|
input: {
|
||||||
@@ -30,7 +30,7 @@ keep_fnames: {
|
|||||||
options = {
|
options = {
|
||||||
conditionals: true,
|
conditionals: true,
|
||||||
if_return: true,
|
if_return: true,
|
||||||
unsafe: true
|
unsafe_undefined: true,
|
||||||
}
|
}
|
||||||
mangle = {
|
mangle = {
|
||||||
keep_fnames: true
|
keep_fnames: true
|
||||||
|
|||||||
@@ -32,7 +32,6 @@ conditional_false_stray_else_in_loop: {
|
|||||||
hoist_vars : true,
|
hoist_vars : true,
|
||||||
join_vars : true,
|
join_vars : true,
|
||||||
if_return : true,
|
if_return : true,
|
||||||
cascade : true,
|
|
||||||
conditionals : false,
|
conditionals : false,
|
||||||
}
|
}
|
||||||
input: {
|
input: {
|
||||||
|
|||||||
@@ -1,291 +0,0 @@
|
|||||||
same_variable_in_multiple_for_loop: {
|
|
||||||
options = {
|
|
||||||
hoist_funs: true,
|
|
||||||
dead_code: true,
|
|
||||||
conditionals: true,
|
|
||||||
comparisons: true,
|
|
||||||
evaluate: true,
|
|
||||||
booleans: true,
|
|
||||||
loops: true,
|
|
||||||
unused: true,
|
|
||||||
keep_fargs: true,
|
|
||||||
if_return: true,
|
|
||||||
join_vars: true,
|
|
||||||
cascade: true,
|
|
||||||
side_effects: true,
|
|
||||||
collapse_vars: true,
|
|
||||||
}
|
|
||||||
mangle = {}
|
|
||||||
input: {
|
|
||||||
for (let i = 0; i < 3; i++) {
|
|
||||||
let a = 100;
|
|
||||||
console.log(i, a);
|
|
||||||
for (let i = 0; i < 2; i++) {
|
|
||||||
console.log(i, a);
|
|
||||||
let c = 2;
|
|
||||||
console.log(c);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
for (let o = 0; o < 3; o++) {
|
|
||||||
let l = 100;
|
|
||||||
console.log(o, l);
|
|
||||||
for (let o = 0; o < 2; o++) {
|
|
||||||
console.log(o, l);
|
|
||||||
let e = 2;
|
|
||||||
console.log(e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
expect_stdout: true
|
|
||||||
}
|
|
||||||
|
|
||||||
same_variable_in_multiple_forOf: {
|
|
||||||
options = {
|
|
||||||
hoist_funs: true,
|
|
||||||
dead_code: true,
|
|
||||||
conditionals: true,
|
|
||||||
comparisons: true,
|
|
||||||
evaluate: true,
|
|
||||||
booleans: true,
|
|
||||||
loops: true,
|
|
||||||
unused: true,
|
|
||||||
keep_fargs: true,
|
|
||||||
if_return: true,
|
|
||||||
join_vars: true,
|
|
||||||
cascade: true,
|
|
||||||
side_effects: true,
|
|
||||||
collapse_vars: true,
|
|
||||||
}
|
|
||||||
mangle = {}
|
|
||||||
input: {
|
|
||||||
var test = [ "a", "b", "c" ];
|
|
||||||
for (let tmp of test) {
|
|
||||||
console.log(tmp);
|
|
||||||
let dd;
|
|
||||||
dd = [ "e", "f", "g" ];
|
|
||||||
for (let tmp of dd) {
|
|
||||||
console.log(tmp);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
var test = [ "a", "b", "c" ];
|
|
||||||
for (let o of test) {
|
|
||||||
console.log(o);
|
|
||||||
let e;
|
|
||||||
e = [ "e", "f", "g" ];
|
|
||||||
for (let o of e)
|
|
||||||
console.log(o);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
expect_stdout: true
|
|
||||||
}
|
|
||||||
|
|
||||||
same_variable_in_multiple_forIn: {
|
|
||||||
options = {
|
|
||||||
hoist_funs: true,
|
|
||||||
dead_code: true,
|
|
||||||
conditionals: true,
|
|
||||||
comparisons: true,
|
|
||||||
evaluate: true,
|
|
||||||
booleans: true,
|
|
||||||
loops: true,
|
|
||||||
unused: false,
|
|
||||||
keep_fargs: true,
|
|
||||||
if_return: true,
|
|
||||||
join_vars: true,
|
|
||||||
cascade: true,
|
|
||||||
side_effects: true,
|
|
||||||
collapse_vars: true,
|
|
||||||
}
|
|
||||||
mangle = {}
|
|
||||||
input: {
|
|
||||||
var test = [ "a", "b", "c" ];
|
|
||||||
for (let tmp in test) {
|
|
||||||
console.log(tmp);
|
|
||||||
let dd;
|
|
||||||
dd = [ "e", "f", "g" ];
|
|
||||||
for (let tmp in test) {
|
|
||||||
console.log(tmp);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
var test = [ "a", "b", "c" ];
|
|
||||||
for (let e in test) {
|
|
||||||
console.log(e);
|
|
||||||
let t;
|
|
||||||
t = [ "e", "f", "g" ];
|
|
||||||
for (let e in test)
|
|
||||||
console.log(e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
expect_stdout: true
|
|
||||||
}
|
|
||||||
|
|
||||||
different_variable_in_multiple_for_loop: {
|
|
||||||
options = {
|
|
||||||
hoist_funs: true,
|
|
||||||
dead_code: true,
|
|
||||||
conditionals: true,
|
|
||||||
comparisons: true,
|
|
||||||
evaluate: true,
|
|
||||||
booleans: true,
|
|
||||||
loops: true,
|
|
||||||
unused: true,
|
|
||||||
keep_fargs: true,
|
|
||||||
if_return: true,
|
|
||||||
join_vars: true,
|
|
||||||
cascade: true,
|
|
||||||
side_effects: true,
|
|
||||||
collapse_vars: true,
|
|
||||||
}
|
|
||||||
mangle = {}
|
|
||||||
input: {
|
|
||||||
for (let i = 0; i < 3; i++) {
|
|
||||||
let a = 100;
|
|
||||||
console.log(i, a);
|
|
||||||
for (let j = 0; j < 2; j++) {
|
|
||||||
console.log(j, a);
|
|
||||||
let c = 2;
|
|
||||||
console.log(c);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
for (let o = 0; o < 3; o++) {
|
|
||||||
let l = 100;
|
|
||||||
console.log(o, l);
|
|
||||||
for (let o = 0; o < 2; o++) {
|
|
||||||
console.log(o, l);
|
|
||||||
let e = 2;
|
|
||||||
console.log(e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
expect_stdout: true
|
|
||||||
}
|
|
||||||
|
|
||||||
different_variable_in_multiple_forOf: {
|
|
||||||
options = {
|
|
||||||
hoist_funs: true,
|
|
||||||
dead_code: true,
|
|
||||||
conditionals: true,
|
|
||||||
comparisons: true,
|
|
||||||
evaluate: true,
|
|
||||||
booleans: true,
|
|
||||||
loops: true,
|
|
||||||
unused: true,
|
|
||||||
keep_fargs: true,
|
|
||||||
if_return: true,
|
|
||||||
join_vars: true,
|
|
||||||
cascade: true,
|
|
||||||
side_effects: true,
|
|
||||||
collapse_vars: true,
|
|
||||||
}
|
|
||||||
mangle = {}
|
|
||||||
input: {
|
|
||||||
var test = [ "a", "b", "c" ];
|
|
||||||
for (let tmp of test) {
|
|
||||||
console.log(tmp);
|
|
||||||
let dd;
|
|
||||||
dd = [ "e", "f", "g" ];
|
|
||||||
for (let t of dd) {
|
|
||||||
console.log(t);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
var test = [ "a", "b", "c" ];
|
|
||||||
for (let o of test) {
|
|
||||||
console.log(o);
|
|
||||||
let e;
|
|
||||||
e = [ "e", "f", "g" ];
|
|
||||||
for (let o of e)
|
|
||||||
console.log(o);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
expect_stdout: true
|
|
||||||
}
|
|
||||||
|
|
||||||
different_variable_in_multiple_forIn: {
|
|
||||||
options = {
|
|
||||||
hoist_funs: true,
|
|
||||||
dead_code: true,
|
|
||||||
conditionals: true,
|
|
||||||
comparisons: true,
|
|
||||||
evaluate: true,
|
|
||||||
booleans: true,
|
|
||||||
loops: true,
|
|
||||||
unused: false,
|
|
||||||
keep_fargs: true,
|
|
||||||
if_return: true,
|
|
||||||
join_vars: true,
|
|
||||||
cascade: true,
|
|
||||||
side_effects: true,
|
|
||||||
collapse_vars: true,
|
|
||||||
}
|
|
||||||
mangle = {}
|
|
||||||
input: {
|
|
||||||
var test = [ "a", "b", "c" ];
|
|
||||||
for (let tmp in test) {
|
|
||||||
console.log(tmp);
|
|
||||||
let dd;
|
|
||||||
dd = [ "e", "f", "g" ];
|
|
||||||
for (let t in test) {
|
|
||||||
console.log(t);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
var test = [ "a", "b", "c" ];
|
|
||||||
for (let e in test) {
|
|
||||||
console.log(e);
|
|
||||||
let t;
|
|
||||||
t = [ "e", "f", "g" ];
|
|
||||||
for (let e in test)
|
|
||||||
console.log(e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
expect_stdout: true
|
|
||||||
}
|
|
||||||
|
|
||||||
more_variable_in_multiple_for: {
|
|
||||||
options = {
|
|
||||||
hoist_funs: true,
|
|
||||||
dead_code: true,
|
|
||||||
conditionals: true,
|
|
||||||
comparisons: true,
|
|
||||||
evaluate: true,
|
|
||||||
booleans: true,
|
|
||||||
loops: true,
|
|
||||||
unused: false,
|
|
||||||
keep_fargs: true,
|
|
||||||
if_return: true,
|
|
||||||
join_vars: true,
|
|
||||||
cascade: true,
|
|
||||||
side_effects: true,
|
|
||||||
collapse_vars: true,
|
|
||||||
}
|
|
||||||
mangle = {}
|
|
||||||
input: {
|
|
||||||
for (let a = 9, i = 0; i < 20; i += a) {
|
|
||||||
let b = a++ + i;
|
|
||||||
console.log(a, b, i);
|
|
||||||
for (let k = b, m = b*b, i = 0; i < 10; i++) {
|
|
||||||
console.log(a, b, m, k, i);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
for (let o = 9, l = 0; l < 20; l += o) {
|
|
||||||
let e = o++ + l;
|
|
||||||
console.log(o, e, l);
|
|
||||||
for (let l = e, t = e * e, c = 0; c < 10; c++)
|
|
||||||
console.log(o, e, t, l, c);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
expect_stdout: true
|
|
||||||
}
|
|
||||||
@@ -61,7 +61,7 @@ unsafe_undefined: {
|
|||||||
options = {
|
options = {
|
||||||
conditionals: true,
|
conditionals: true,
|
||||||
if_return: true,
|
if_return: true,
|
||||||
unsafe: true,
|
unsafe_undefined: true,
|
||||||
}
|
}
|
||||||
mangle = {}
|
mangle = {}
|
||||||
input: {
|
input: {
|
||||||
@@ -85,15 +85,3 @@ unsafe_undefined: {
|
|||||||
}
|
}
|
||||||
expect_stdout: true
|
expect_stdout: true
|
||||||
}
|
}
|
||||||
|
|
||||||
runtime_error: {
|
|
||||||
input: {
|
|
||||||
const a = 1;
|
|
||||||
console.log(a++);
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
const a = 1;
|
|
||||||
console.log(a++);
|
|
||||||
}
|
|
||||||
expect_stdout: true
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
issue_1639_1: {
|
issue_1639_1: {
|
||||||
options = {
|
options = {
|
||||||
booleans: true,
|
booleans: true,
|
||||||
cascade: true,
|
collapse_vars: true,
|
||||||
conditionals: true,
|
conditionals: true,
|
||||||
evaluate: true,
|
evaluate: true,
|
||||||
join_vars: true,
|
join_vars: true,
|
||||||
@@ -35,7 +35,7 @@ issue_1639_1: {
|
|||||||
issue_1639_2: {
|
issue_1639_2: {
|
||||||
options = {
|
options = {
|
||||||
booleans: true,
|
booleans: true,
|
||||||
cascade: true,
|
collapse_vars: true,
|
||||||
conditionals: true,
|
conditionals: true,
|
||||||
evaluate: true,
|
evaluate: true,
|
||||||
join_vars: true,
|
join_vars: true,
|
||||||
@@ -68,7 +68,7 @@ issue_1639_2: {
|
|||||||
issue_1639_3: {
|
issue_1639_3: {
|
||||||
options = {
|
options = {
|
||||||
booleans: true,
|
booleans: true,
|
||||||
cascade: true,
|
collapse_vars: true,
|
||||||
conditionals: true,
|
conditionals: true,
|
||||||
evaluate: true,
|
evaluate: true,
|
||||||
sequences: true,
|
sequences: true,
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
f7: {
|
f7: {
|
||||||
options = {
|
options = {
|
||||||
booleans: true,
|
booleans: true,
|
||||||
cascade: true,
|
|
||||||
collapse_vars: true,
|
collapse_vars: true,
|
||||||
comparisons: true,
|
comparisons: true,
|
||||||
conditionals: true,
|
conditionals: true,
|
||||||
|
|||||||
@@ -84,12 +84,12 @@ numeric_literal: {
|
|||||||
' 0: 0,',
|
' 0: 0,',
|
||||||
' "-0": 1,',
|
' "-0": 1,',
|
||||||
' 42: 2,',
|
' 42: 2,',
|
||||||
' "42": 3,',
|
' 42: 3,',
|
||||||
' 37: 4,',
|
' 37: 4,',
|
||||||
' o: 5,',
|
' o: 5,',
|
||||||
' 1e42: 6,',
|
' 1e42: 6,',
|
||||||
' b: 7,',
|
' b: 7,',
|
||||||
' "1e+42": 8',
|
' 1e42: 8',
|
||||||
'};',
|
'};',
|
||||||
'',
|
'',
|
||||||
'console.log(obj[-0], obj[-""], obj["-0"]);',
|
'console.log(obj[-0], obj[-""], obj["-0"]);',
|
||||||
@@ -107,3 +107,139 @@ numeric_literal: {
|
|||||||
"8 7 8",
|
"8 7 8",
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
identifier: {
|
||||||
|
mangle = {
|
||||||
|
properties: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
var obj = {
|
||||||
|
abstract: 1,
|
||||||
|
boolean: 2,
|
||||||
|
byte: 3,
|
||||||
|
char: 4,
|
||||||
|
class: 5,
|
||||||
|
double: 6,
|
||||||
|
enum: 7,
|
||||||
|
export: 8,
|
||||||
|
extends: 9,
|
||||||
|
final: 10,
|
||||||
|
float: 11,
|
||||||
|
goto: 12,
|
||||||
|
implements: 13,
|
||||||
|
import: 14,
|
||||||
|
int: 15,
|
||||||
|
interface: 16,
|
||||||
|
let: 17,
|
||||||
|
long: 18,
|
||||||
|
native: 19,
|
||||||
|
package: 20,
|
||||||
|
private: 21,
|
||||||
|
protected: 22,
|
||||||
|
public: 23,
|
||||||
|
short: 24,
|
||||||
|
static: 25,
|
||||||
|
super: 26,
|
||||||
|
synchronized: 27,
|
||||||
|
this: 28,
|
||||||
|
throws: 29,
|
||||||
|
transient: 30,
|
||||||
|
volatile: 31,
|
||||||
|
yield: 32,
|
||||||
|
false: 33,
|
||||||
|
null: 34,
|
||||||
|
true: 35,
|
||||||
|
break: 36,
|
||||||
|
case: 37,
|
||||||
|
catch: 38,
|
||||||
|
const: 39,
|
||||||
|
continue: 40,
|
||||||
|
debugger: 41,
|
||||||
|
default: 42,
|
||||||
|
delete: 43,
|
||||||
|
do: 44,
|
||||||
|
else: 45,
|
||||||
|
finally: 46,
|
||||||
|
for: 47,
|
||||||
|
function: 48,
|
||||||
|
if: 49,
|
||||||
|
in: 50,
|
||||||
|
instanceof: 51,
|
||||||
|
new: 52,
|
||||||
|
return: 53,
|
||||||
|
switch: 54,
|
||||||
|
throw: 55,
|
||||||
|
try: 56,
|
||||||
|
typeof: 57,
|
||||||
|
var: 58,
|
||||||
|
void: 59,
|
||||||
|
while: 60,
|
||||||
|
with: 61,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
var obj = {
|
||||||
|
e: 1,
|
||||||
|
t: 2,
|
||||||
|
n: 3,
|
||||||
|
a: 4,
|
||||||
|
i: 5,
|
||||||
|
o: 6,
|
||||||
|
r: 7,
|
||||||
|
l: 8,
|
||||||
|
s: 9,
|
||||||
|
c: 10,
|
||||||
|
f: 11,
|
||||||
|
u: 12,
|
||||||
|
d: 13,
|
||||||
|
h: 14,
|
||||||
|
p: 15,
|
||||||
|
b: 16,
|
||||||
|
v: 17,
|
||||||
|
w: 18,
|
||||||
|
y: 19,
|
||||||
|
g: 20,
|
||||||
|
m: 21,
|
||||||
|
k: 22,
|
||||||
|
x: 23,
|
||||||
|
j: 24,
|
||||||
|
z: 25,
|
||||||
|
q: 26,
|
||||||
|
A: 27,
|
||||||
|
B: 28,
|
||||||
|
C: 29,
|
||||||
|
D: 30,
|
||||||
|
F: 31,
|
||||||
|
G: 32,
|
||||||
|
false: 33,
|
||||||
|
null: 34,
|
||||||
|
true: 35,
|
||||||
|
H: 36,
|
||||||
|
I: 37,
|
||||||
|
J: 38,
|
||||||
|
K: 39,
|
||||||
|
L: 40,
|
||||||
|
M: 41,
|
||||||
|
N: 42,
|
||||||
|
O: 43,
|
||||||
|
P: 44,
|
||||||
|
Q: 45,
|
||||||
|
R: 46,
|
||||||
|
S: 47,
|
||||||
|
T: 48,
|
||||||
|
U: 49,
|
||||||
|
V: 50,
|
||||||
|
W: 51,
|
||||||
|
X: 52,
|
||||||
|
Y: 53,
|
||||||
|
Z: 54,
|
||||||
|
$: 55,
|
||||||
|
_: 56,
|
||||||
|
ee: 57,
|
||||||
|
te: 58,
|
||||||
|
ne: 59,
|
||||||
|
ae: 60,
|
||||||
|
ie: 61,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,283 +0,0 @@
|
|||||||
export_func_1: {
|
|
||||||
options = {
|
|
||||||
hoist_funs: true,
|
|
||||||
toplevel: true,
|
|
||||||
unused: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
export function f(){};
|
|
||||||
}
|
|
||||||
expect_exact: "export function f(){};"
|
|
||||||
}
|
|
||||||
|
|
||||||
export_func_2: {
|
|
||||||
options = {
|
|
||||||
hoist_funs: true,
|
|
||||||
side_effects: false,
|
|
||||||
toplevel: true,
|
|
||||||
unused: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
export function f(){}(1);
|
|
||||||
}
|
|
||||||
expect_exact: "export function f(){};1;"
|
|
||||||
}
|
|
||||||
|
|
||||||
export_func_3: {
|
|
||||||
options = {
|
|
||||||
hoist_funs: true,
|
|
||||||
side_effects: true,
|
|
||||||
toplevel: true,
|
|
||||||
unused: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
export function f(){}(1);
|
|
||||||
}
|
|
||||||
expect_exact: "export function f(){};"
|
|
||||||
}
|
|
||||||
|
|
||||||
export_default_func_1: {
|
|
||||||
options = {
|
|
||||||
hoist_funs: true,
|
|
||||||
toplevel: true,
|
|
||||||
unused: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
export default function f(){};
|
|
||||||
}
|
|
||||||
expect_exact: "export default function f(){};"
|
|
||||||
}
|
|
||||||
|
|
||||||
export_default_func_2: {
|
|
||||||
options = {
|
|
||||||
hoist_funs: true,
|
|
||||||
side_effects: false,
|
|
||||||
toplevel: true,
|
|
||||||
unused: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
export default function f(){}(1);
|
|
||||||
}
|
|
||||||
expect_exact: "export default function f(){};1;"
|
|
||||||
}
|
|
||||||
|
|
||||||
export_default_func_3: {
|
|
||||||
options = {
|
|
||||||
hoist_funs: true,
|
|
||||||
side_effects: true,
|
|
||||||
toplevel: true,
|
|
||||||
unused: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
export default function f(){}(1);
|
|
||||||
}
|
|
||||||
expect_exact: "export default function f(){};"
|
|
||||||
}
|
|
||||||
|
|
||||||
export_class_1: {
|
|
||||||
options = {
|
|
||||||
hoist_funs: true,
|
|
||||||
toplevel: true,
|
|
||||||
unused: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
export class C {};
|
|
||||||
}
|
|
||||||
expect_exact: "export class C{};"
|
|
||||||
}
|
|
||||||
|
|
||||||
export_class_2: {
|
|
||||||
options = {
|
|
||||||
hoist_funs: true,
|
|
||||||
side_effects: false,
|
|
||||||
toplevel: true,
|
|
||||||
unused: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
export class C {}(1);
|
|
||||||
}
|
|
||||||
expect_exact: "export class C{};1;"
|
|
||||||
}
|
|
||||||
|
|
||||||
export_class_3: {
|
|
||||||
options = {
|
|
||||||
hoist_funs: true,
|
|
||||||
side_effects: true,
|
|
||||||
toplevel: true,
|
|
||||||
unused: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
export class C {}(1);
|
|
||||||
}
|
|
||||||
expect_exact: "export class C{};"
|
|
||||||
}
|
|
||||||
|
|
||||||
export_default_class_1: {
|
|
||||||
options = {
|
|
||||||
hoist_funs: true,
|
|
||||||
toplevel: true,
|
|
||||||
unused: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
export default class C {};
|
|
||||||
}
|
|
||||||
expect_exact: "export default class C{};"
|
|
||||||
}
|
|
||||||
|
|
||||||
export_default_class_2: {
|
|
||||||
options = {
|
|
||||||
hoist_funs: true,
|
|
||||||
side_effects: false,
|
|
||||||
toplevel: true,
|
|
||||||
unused: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
export default class C {}(1);
|
|
||||||
}
|
|
||||||
expect_exact: "export default class C{};1;"
|
|
||||||
}
|
|
||||||
|
|
||||||
export_default_class_3: {
|
|
||||||
options = {
|
|
||||||
hoist_funs: true,
|
|
||||||
side_effects: true,
|
|
||||||
toplevel: true,
|
|
||||||
unused: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
export default class C {}(1);
|
|
||||||
}
|
|
||||||
expect_exact: "export default class C{};"
|
|
||||||
}
|
|
||||||
|
|
||||||
export_mangle_1: {
|
|
||||||
mangle = {
|
|
||||||
toplevel: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
export function foo(one, two) {
|
|
||||||
return one - two;
|
|
||||||
};
|
|
||||||
}
|
|
||||||
expect_exact: "export function foo(o,n){return o-n};"
|
|
||||||
}
|
|
||||||
|
|
||||||
export_mangle_2: {
|
|
||||||
mangle = {
|
|
||||||
toplevel: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
export default function foo(one, two) {
|
|
||||||
return one - two;
|
|
||||||
};
|
|
||||||
}
|
|
||||||
expect_exact: "export default function foo(o,t){return o-t};"
|
|
||||||
}
|
|
||||||
|
|
||||||
export_mangle_3: {
|
|
||||||
options = {
|
|
||||||
collapse_vars: true,
|
|
||||||
unused: true,
|
|
||||||
}
|
|
||||||
mangle = {
|
|
||||||
toplevel: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
export class C {
|
|
||||||
go(one, two) {
|
|
||||||
var z = one;
|
|
||||||
return one - two + z;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
expect_exact: "export class C{go(r,e){return r-e+r}};"
|
|
||||||
}
|
|
||||||
|
|
||||||
export_mangle_4: {
|
|
||||||
options = {
|
|
||||||
collapse_vars: true,
|
|
||||||
unused: true,
|
|
||||||
}
|
|
||||||
mangle = {
|
|
||||||
toplevel: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
export default class C {
|
|
||||||
go(one, two) {
|
|
||||||
var z = one;
|
|
||||||
return one - two + z;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
expect_exact: "export default class C{go(e,r){return e-r+e}};"
|
|
||||||
}
|
|
||||||
|
|
||||||
export_mangle_5: {
|
|
||||||
mangle = {
|
|
||||||
toplevel: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
export default {
|
|
||||||
prop: function(one, two) {
|
|
||||||
return one - two;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
expect_exact: "export default{prop:function(r,t){return r-t}};"
|
|
||||||
}
|
|
||||||
|
|
||||||
export_mangle_6: {
|
|
||||||
mangle = {
|
|
||||||
toplevel: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
var baz = 2;
|
|
||||||
export let foo = 1, bar = baz;
|
|
||||||
}
|
|
||||||
expect_exact: "var o=2;export let foo=1,bar=o;"
|
|
||||||
}
|
|
||||||
|
|
||||||
export_toplevel_1: {
|
|
||||||
options = {
|
|
||||||
toplevel: true,
|
|
||||||
unused: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
function f(){}
|
|
||||||
export function g(){};
|
|
||||||
export default function h(){};
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
export function g(){};
|
|
||||||
export default function h(){};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export_toplevel_2: {
|
|
||||||
options = {
|
|
||||||
toplevel: true,
|
|
||||||
unused: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
class A {}
|
|
||||||
export class B {};
|
|
||||||
export default class C {};
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
export class B {};
|
|
||||||
export default class C {};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export_default_func_ref: {
|
|
||||||
options = {
|
|
||||||
hoist_funs: true,
|
|
||||||
toplevel: true,
|
|
||||||
unused: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
export default function f(){};
|
|
||||||
f();
|
|
||||||
}
|
|
||||||
expect_exact: "export default function f(){};f();"
|
|
||||||
}
|
|
||||||
@@ -1,57 +0,0 @@
|
|||||||
|
|
||||||
compress_new_function: {
|
|
||||||
options = {
|
|
||||||
unsafe: true,
|
|
||||||
unsafe_Func: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
new Function("aa, bb", 'return aa;');
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
Function("n,r", "return n");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
compress_new_function_with_destruct: {
|
|
||||||
options = {
|
|
||||||
unsafe: true,
|
|
||||||
unsafe_Func: true,
|
|
||||||
ecma: 6
|
|
||||||
}
|
|
||||||
beautify = {
|
|
||||||
ecma: 6
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
new Function("aa, [bb]", 'return aa;');
|
|
||||||
new Function("aa, {bb}", 'return aa;');
|
|
||||||
new Function("[[aa]], [{bb}]", 'return aa;');
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
Function("n,[r]", "return n");
|
|
||||||
Function("n,{bb:b}", "return n");
|
|
||||||
Function("[[n]],[{bb:b}]", "return n");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
compress_new_function_with_destruct_arrows: {
|
|
||||||
options = {
|
|
||||||
arrows: true,
|
|
||||||
unsafe_arrows: true,
|
|
||||||
unsafe: true,
|
|
||||||
unsafe_Func: true,
|
|
||||||
ecma: 6,
|
|
||||||
}
|
|
||||||
beautify = {
|
|
||||||
ecma: 6
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
new Function("aa, [bb]", 'return aa;');
|
|
||||||
new Function("aa, {bb}", 'return aa;');
|
|
||||||
new Function("[[aa]], [{bb}]", 'return aa;');
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
Function("n,[a]", "return n");
|
|
||||||
Function("b,{bb:n}", "return b");
|
|
||||||
Function("[[b]],[{bb:n}]", "return b");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -38,7 +38,7 @@ mixed: {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
input: {
|
input: {
|
||||||
const ENV = 3;
|
var ENV = 3;
|
||||||
var FOO = 4;
|
var FOO = 4;
|
||||||
f(ENV * 10);
|
f(ENV * 10);
|
||||||
--FOO;
|
--FOO;
|
||||||
@@ -49,7 +49,7 @@ mixed: {
|
|||||||
x = DEBUG;
|
x = DEBUG;
|
||||||
}
|
}
|
||||||
expect: {
|
expect: {
|
||||||
const ENV = 3;
|
var ENV = 3;
|
||||||
var FOO = 4;
|
var FOO = 4;
|
||||||
f(10);
|
f(10);
|
||||||
--FOO;
|
--FOO;
|
||||||
@@ -60,7 +60,7 @@ mixed: {
|
|||||||
x = 0;
|
x = 0;
|
||||||
}
|
}
|
||||||
expect_warnings: [
|
expect_warnings: [
|
||||||
'WARN: global_defs ENV redefined [test/compress/issue-208.js:41,14]',
|
'WARN: global_defs ENV redefined [test/compress/issue-208.js:41,12]',
|
||||||
'WARN: global_defs FOO redefined [test/compress/issue-208.js:42,12]',
|
'WARN: global_defs FOO redefined [test/compress/issue-208.js:42,12]',
|
||||||
'WARN: global_defs FOO redefined [test/compress/issue-208.js:44,10]',
|
'WARN: global_defs FOO redefined [test/compress/issue-208.js:44,10]',
|
||||||
'WARN: global_defs DEBUG redefined [test/compress/issue-208.js:45,8]',
|
'WARN: global_defs DEBUG redefined [test/compress/issue-208.js:45,8]',
|
||||||
|
|||||||
33
test/compress/issue-2652.js
Normal file
33
test/compress/issue-2652.js
Normal file
@@ -0,0 +1,33 @@
|
|||||||
|
insert_semicolon: {
|
||||||
|
beautify = {
|
||||||
|
beautify: true,
|
||||||
|
comments: "all",
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
var a
|
||||||
|
/* foo */ var b
|
||||||
|
}
|
||||||
|
expect_exact: [
|
||||||
|
"var a",
|
||||||
|
"/* foo */;",
|
||||||
|
"",
|
||||||
|
"var b;",
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
|
unary_postfix: {
|
||||||
|
beautify = {
|
||||||
|
beautify: true,
|
||||||
|
comments: "all",
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
a
|
||||||
|
/* foo */++b
|
||||||
|
}
|
||||||
|
expect_exact: [
|
||||||
|
"a",
|
||||||
|
"/* foo */;",
|
||||||
|
"",
|
||||||
|
"++b;",
|
||||||
|
]
|
||||||
|
}
|
||||||
@@ -64,3 +64,27 @@ strings_concat: {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
regexp: {
|
||||||
|
options = {
|
||||||
|
evaluate: true,
|
||||||
|
unsafe: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
RegExp("foo");
|
||||||
|
RegExp("bar", "ig");
|
||||||
|
RegExp(foo);
|
||||||
|
RegExp("bar", ig);
|
||||||
|
RegExp("should", "fail");
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
/foo/;
|
||||||
|
/bar/ig;
|
||||||
|
RegExp(foo);
|
||||||
|
RegExp("bar", ig);
|
||||||
|
RegExp("should", "fail");
|
||||||
|
}
|
||||||
|
expect_warnings: [
|
||||||
|
'WARN: Error converting RegExp("should","fail") [test/compress/issue-269.js:78,2]',
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|||||||
32
test/compress/issue-2719.js
Normal file
32
test/compress/issue-2719.js
Normal file
@@ -0,0 +1,32 @@
|
|||||||
|
warn: {
|
||||||
|
options = {
|
||||||
|
evaluate: true,
|
||||||
|
inline: true,
|
||||||
|
passes: 2,
|
||||||
|
properties: true,
|
||||||
|
reduce_funcs: true,
|
||||||
|
reduce_vars: true,
|
||||||
|
toplevel: true,
|
||||||
|
unused: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
function f() {
|
||||||
|
return g();
|
||||||
|
}
|
||||||
|
function g() {
|
||||||
|
return g["call" + "er"].arguments;
|
||||||
|
}
|
||||||
|
// 3
|
||||||
|
console.log(f(1, 2, 3).length);
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
// TypeError: Cannot read property 'arguments' of null
|
||||||
|
console.log(function g() {
|
||||||
|
return g.caller.arguments;
|
||||||
|
}().length);
|
||||||
|
}
|
||||||
|
expect_warnings: [
|
||||||
|
"WARN: Function.protoype.caller not supported [test/compress/issue-2719.js:17,19]",
|
||||||
|
"WARN: Function.protoype.arguments not supported [test/compress/issue-2719.js:17,19]",
|
||||||
|
]
|
||||||
|
}
|
||||||
@@ -453,7 +453,7 @@ pure_annotation_2: {
|
|||||||
|
|
||||||
drop_fargs: {
|
drop_fargs: {
|
||||||
options = {
|
options = {
|
||||||
cascade: true,
|
collapse_vars: true,
|
||||||
inline: true,
|
inline: true,
|
||||||
keep_fargs: false,
|
keep_fargs: false,
|
||||||
side_effects: true,
|
side_effects: true,
|
||||||
@@ -476,7 +476,7 @@ drop_fargs: {
|
|||||||
|
|
||||||
keep_fargs: {
|
keep_fargs: {
|
||||||
options = {
|
options = {
|
||||||
cascade: true,
|
collapse_vars: true,
|
||||||
inline: true,
|
inline: true,
|
||||||
keep_fargs: true,
|
keep_fargs: true,
|
||||||
side_effects: true,
|
side_effects: true,
|
||||||
|
|||||||
37
test/compress/issue-2871.js
Normal file
37
test/compress/issue-2871.js
Normal file
@@ -0,0 +1,37 @@
|
|||||||
|
comparison_with_undefined: {
|
||||||
|
options = {
|
||||||
|
comparisons: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
a == undefined;
|
||||||
|
a != undefined;
|
||||||
|
a === undefined;
|
||||||
|
a !== undefined;
|
||||||
|
|
||||||
|
undefined == a;
|
||||||
|
undefined != a;
|
||||||
|
undefined === a;
|
||||||
|
undefined !== a;
|
||||||
|
|
||||||
|
void 0 == a;
|
||||||
|
void 0 != a;
|
||||||
|
void 0 === a;
|
||||||
|
void 0 !== a;
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
null == a;
|
||||||
|
null != a;
|
||||||
|
void 0 === a;
|
||||||
|
void 0 !== a;
|
||||||
|
|
||||||
|
null == a;
|
||||||
|
null != a;
|
||||||
|
void 0 === a;
|
||||||
|
void 0 !== a;
|
||||||
|
|
||||||
|
null == a;
|
||||||
|
null != a;
|
||||||
|
void 0 === a;
|
||||||
|
void 0 !== a;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
collapse: {
|
collapse: {
|
||||||
options = {
|
options = {
|
||||||
cascade: true,
|
collapse_vars: true,
|
||||||
sequences: true,
|
sequences: true,
|
||||||
side_effects: true,
|
side_effects: true,
|
||||||
unused: true,
|
unused: true,
|
||||||
@@ -41,7 +41,7 @@ collapse: {
|
|||||||
return void 0 !== ('function' === typeof b ? b() : b) && c();
|
return void 0 !== ('function' === typeof b ? b() : b) && c();
|
||||||
}
|
}
|
||||||
function f2(b) {
|
function f2(b) {
|
||||||
return b = c(), 'stirng' == typeof ('function' === typeof b ? b() : b) && d();
|
return 'stirng' == typeof ('function' === typeof (b = c()) ? b() : b) && d();
|
||||||
}
|
}
|
||||||
function f3(c) {
|
function f3(c) {
|
||||||
var a;
|
var a;
|
||||||
|
|||||||
@@ -18,7 +18,6 @@ dont_mangle_arguments: {
|
|||||||
hoist_vars : true,
|
hoist_vars : true,
|
||||||
if_return : true,
|
if_return : true,
|
||||||
join_vars : true,
|
join_vars : true,
|
||||||
cascade : true,
|
|
||||||
side_effects : true,
|
side_effects : true,
|
||||||
negate_iife : false
|
negate_iife : false
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,9 +0,0 @@
|
|||||||
template_strings: {
|
|
||||||
input: {
|
|
||||||
foo(
|
|
||||||
`<span>${contents}</span>`,
|
|
||||||
`<a href="${url}">${text}</a>`
|
|
||||||
);
|
|
||||||
}
|
|
||||||
expect_exact: "foo(`<span>${contents}</span>`,`<a href=\"${url}\">${text}</a>`);"
|
|
||||||
}
|
|
||||||
@@ -2,7 +2,7 @@ eval_collapse_vars: {
|
|||||||
options = {
|
options = {
|
||||||
collapse_vars:true, sequences:false, properties:true, dead_code:true, conditionals:true,
|
collapse_vars:true, sequences:false, properties:true, dead_code:true, conditionals:true,
|
||||||
comparisons:true, evaluate:true, booleans:true, loops:true, unused:true, hoist_funs:true,
|
comparisons:true, evaluate:true, booleans:true, loops:true, unused:true, hoist_funs:true,
|
||||||
keep_fargs:true, if_return:true, join_vars:true, cascade:true, side_effects:true
|
keep_fargs:true, if_return:true, join_vars:true, side_effects:true
|
||||||
};
|
};
|
||||||
input: {
|
input: {
|
||||||
function f1() {
|
function f1() {
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ issue979_reported: {
|
|||||||
options = {
|
options = {
|
||||||
sequences:true, properties:true, dead_code:true, conditionals:true,
|
sequences:true, properties:true, dead_code:true, conditionals:true,
|
||||||
comparisons:true, evaluate:true, booleans:true, loops:true, unused:true, hoist_funs:true,
|
comparisons:true, evaluate:true, booleans:true, loops:true, unused:true, hoist_funs:true,
|
||||||
keep_fargs:true, if_return:true, join_vars:true, cascade:true, side_effects:true
|
keep_fargs:true, if_return:true, join_vars:true, side_effects:true
|
||||||
}
|
}
|
||||||
input: {
|
input: {
|
||||||
function f1() {
|
function f1() {
|
||||||
@@ -32,7 +32,7 @@ issue979_test_negated_is_best: {
|
|||||||
options = {
|
options = {
|
||||||
sequences:true, properties:true, dead_code:true, conditionals:true,
|
sequences:true, properties:true, dead_code:true, conditionals:true,
|
||||||
comparisons:true, evaluate:true, booleans:true, loops:true, unused:true, hoist_funs:true,
|
comparisons:true, evaluate:true, booleans:true, loops:true, unused:true, hoist_funs:true,
|
||||||
keep_fargs:true, if_return:true, join_vars:true, cascade:true, side_effects:true
|
keep_fargs:true, if_return:true, join_vars:true, side_effects:true
|
||||||
}
|
}
|
||||||
input: {
|
input: {
|
||||||
function f3() {
|
function f3() {
|
||||||
|
|||||||
@@ -1,40 +0,0 @@
|
|||||||
only_vars: {
|
|
||||||
options = { join_vars: true };
|
|
||||||
input: {
|
|
||||||
let netmaskBinary = '';
|
|
||||||
for (let i = 0; i < netmaskBits; ++i) {
|
|
||||||
netmaskBinary += '1';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
let netmaskBinary = '';
|
|
||||||
for (let i = 0; i < netmaskBits; ++i) netmaskBinary += '1';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
issue_1079_with_vars: {
|
|
||||||
options = { join_vars: true };
|
|
||||||
input: {
|
|
||||||
var netmaskBinary = '';
|
|
||||||
for (var i = 0; i < netmaskBits; ++i) {
|
|
||||||
netmaskBinary += '1';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
for (var netmaskBinary = '', i = 0; i < netmaskBits; ++i) netmaskBinary += '1';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
issue_1079_with_mixed: {
|
|
||||||
options = { join_vars: true };
|
|
||||||
input: {
|
|
||||||
var netmaskBinary = '';
|
|
||||||
for (let i = 0; i < netmaskBits; ++i) {
|
|
||||||
netmaskBinary += '1';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
var netmaskBinary = ''
|
|
||||||
for (let i = 0; i < netmaskBits; ++i) netmaskBinary += '1';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -146,50 +146,6 @@ parse_do_while_without_semicolon: {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
keep_collapse_const_in_own_block_scope: {
|
|
||||||
options = {
|
|
||||||
join_vars: true,
|
|
||||||
loops: true
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
var i=2;
|
|
||||||
const c=5;
|
|
||||||
while(i--)
|
|
||||||
console.log(i);
|
|
||||||
console.log(c);
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
var i=2;
|
|
||||||
const c=5;
|
|
||||||
for(;i--;)
|
|
||||||
console.log(i);
|
|
||||||
console.log(c);
|
|
||||||
}
|
|
||||||
expect_stdout: true
|
|
||||||
}
|
|
||||||
|
|
||||||
keep_collapse_const_in_own_block_scope_2: {
|
|
||||||
options = {
|
|
||||||
join_vars: true,
|
|
||||||
loops: true
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
const c=5;
|
|
||||||
var i=2; // Moves to loop, while it did not in previous test
|
|
||||||
while(i--)
|
|
||||||
console.log(i);
|
|
||||||
console.log(c);
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
const c=5;
|
|
||||||
for(var i=2;i--;)
|
|
||||||
console.log(i);
|
|
||||||
console.log(c);
|
|
||||||
}
|
|
||||||
expect_stdout: true
|
|
||||||
}
|
|
||||||
|
|
||||||
evaluate: {
|
evaluate: {
|
||||||
options = {
|
options = {
|
||||||
dead_code: true,
|
dead_code: true,
|
||||||
@@ -536,3 +492,116 @@ dead_code_condition: {
|
|||||||
}
|
}
|
||||||
expect_stdout: "1"
|
expect_stdout: "1"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
issue_2740_1: {
|
||||||
|
options = {
|
||||||
|
dead_code: true,
|
||||||
|
loops: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
for (; ; ) break;
|
||||||
|
for (a(); ; ) break;
|
||||||
|
for (; b(); ) break;
|
||||||
|
for (c(); d(); ) break;
|
||||||
|
for (; ; e()) break;
|
||||||
|
for (f(); ; g()) break;
|
||||||
|
for (; h(); i()) break;
|
||||||
|
for (j(); k(); l()) break;
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
a();
|
||||||
|
b();
|
||||||
|
c();
|
||||||
|
d();
|
||||||
|
f();
|
||||||
|
h();
|
||||||
|
j();
|
||||||
|
k();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
issue_2740_2: {
|
||||||
|
options = {
|
||||||
|
dead_code: true,
|
||||||
|
loops: true,
|
||||||
|
passes: 2,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
L1: while (x()) {
|
||||||
|
break L1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
x();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
issue_2740_3: {
|
||||||
|
options = {
|
||||||
|
dead_code: true,
|
||||||
|
loops: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
L1: for (var x = 0; x < 3; x++) {
|
||||||
|
L2: for (var y = 0; y < 2; y++) {
|
||||||
|
break L1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
console.log(x, y);
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
L1: for (var x = 0; x < 3; x++)
|
||||||
|
for (var y = 0; y < 2; y++)
|
||||||
|
break L1;
|
||||||
|
console.log(x, y);
|
||||||
|
}
|
||||||
|
expect_stdout: "0 0"
|
||||||
|
}
|
||||||
|
|
||||||
|
issue_2740_4: {
|
||||||
|
options = {
|
||||||
|
dead_code: true,
|
||||||
|
loops: true,
|
||||||
|
passes: 2,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
L1: for (var x = 0; x < 3; x++) {
|
||||||
|
L2: for (var y = 0; y < 2; y++) {
|
||||||
|
break L2;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
console.log(x, y);
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
for (var x = 0; x < 3; x++) {
|
||||||
|
var y = 0;
|
||||||
|
y < 2;
|
||||||
|
}
|
||||||
|
console.log(x, y);
|
||||||
|
}
|
||||||
|
expect_stdout: "3 0"
|
||||||
|
}
|
||||||
|
|
||||||
|
issue_2740_5: {
|
||||||
|
options = {
|
||||||
|
dead_code: true,
|
||||||
|
loops: true,
|
||||||
|
passes: 2,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
L1: for (var x = 0; x < 3; x++) {
|
||||||
|
break L1;
|
||||||
|
L2: for (var y = 0; y < 2; y++) {
|
||||||
|
break L2;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
console.log(x, y);
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
var x = 0;
|
||||||
|
x < 3;
|
||||||
|
var y;
|
||||||
|
console.log(x,y);
|
||||||
|
}
|
||||||
|
expect_stdout: "0 undefined"
|
||||||
|
}
|
||||||
|
|||||||
@@ -83,22 +83,6 @@ new_with_unary_prefix: {
|
|||||||
expect_exact: 'var bar=(+new Date).toString(32);';
|
expect_exact: 'var bar=(+new Date).toString(32);';
|
||||||
}
|
}
|
||||||
|
|
||||||
new_with_assignement_expression: {
|
|
||||||
options = {
|
|
||||||
evaluate: true
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
var a;
|
|
||||||
new x(a = 5 * 2, b = [1, 2, 3], c = {a: "a", b: "b", cd: "c" + "d"});
|
|
||||||
new y([a, b] = [3, 4]);
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
var a;
|
|
||||||
new x(a = 10, b = [1, 2, 3], c = {a: "a", b: "b", cd: "cd"});
|
|
||||||
new y([a, b] = [3, 4]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
dot_parenthesis_1: {
|
dot_parenthesis_1: {
|
||||||
input: {
|
input: {
|
||||||
console.log(new (Math.random().constructor) instanceof Number);
|
console.log(new (Math.random().constructor) instanceof Number);
|
||||||
|
|||||||
@@ -1,814 +0,0 @@
|
|||||||
getter_setter: {
|
|
||||||
input: {
|
|
||||||
var get = "bar";
|
|
||||||
var a = {
|
|
||||||
get,
|
|
||||||
set: "foo",
|
|
||||||
get bar() {
|
|
||||||
return this.get;
|
|
||||||
},
|
|
||||||
get 5() {
|
|
||||||
return "five";
|
|
||||||
},
|
|
||||||
get 0xf55() {
|
|
||||||
return "f five five";
|
|
||||||
},
|
|
||||||
get "five"() {
|
|
||||||
return 5;
|
|
||||||
},
|
|
||||||
set one(value) {
|
|
||||||
this._one = value;
|
|
||||||
},
|
|
||||||
set 9(value) {
|
|
||||||
this._nine = value;
|
|
||||||
},
|
|
||||||
set 0b1010(value) {
|
|
||||||
this._ten = value;
|
|
||||||
},
|
|
||||||
set "eleven"(value) {
|
|
||||||
this._eleven = value;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
var b = {
|
|
||||||
get() { return "gift"; },
|
|
||||||
set: function(code) { return "Storing code " + code; }
|
|
||||||
};
|
|
||||||
var c = {
|
|
||||||
["get"]: "foo",
|
|
||||||
["set"]: "bar"
|
|
||||||
};
|
|
||||||
var d = {
|
|
||||||
get: "foo",
|
|
||||||
set: "bar"
|
|
||||||
};
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
var get = "bar";
|
|
||||||
var a = {
|
|
||||||
get,
|
|
||||||
set: "foo",
|
|
||||||
get bar() {
|
|
||||||
return this.get;
|
|
||||||
},
|
|
||||||
get 5() {
|
|
||||||
return "five";
|
|
||||||
},
|
|
||||||
get 0xf55() {
|
|
||||||
return "f five five";
|
|
||||||
},
|
|
||||||
get "five"() {
|
|
||||||
return 5;
|
|
||||||
},
|
|
||||||
set one(value) {
|
|
||||||
this._one = value;
|
|
||||||
},
|
|
||||||
set 9(value) {
|
|
||||||
this._nine = value;
|
|
||||||
},
|
|
||||||
set 0b1010(value) {
|
|
||||||
this._ten = value;
|
|
||||||
},
|
|
||||||
set "eleven"(value) {
|
|
||||||
this._eleven = value;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
var b = {
|
|
||||||
get() { return "gift"; },
|
|
||||||
set: function(code) { return "Storing code " + code; }
|
|
||||||
};
|
|
||||||
var c = {
|
|
||||||
["get"]: "foo",
|
|
||||||
["set"]: "bar"
|
|
||||||
};
|
|
||||||
var d = {
|
|
||||||
get: "foo",
|
|
||||||
set: "bar"
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
getter_setter_mangler: {
|
|
||||||
mangle = {}
|
|
||||||
beautify = {
|
|
||||||
ecma: 6
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
function f(get,set) {
|
|
||||||
return {
|
|
||||||
get,
|
|
||||||
set,
|
|
||||||
get g(){},
|
|
||||||
set s(n){},
|
|
||||||
c,
|
|
||||||
a:1,
|
|
||||||
m(){}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
expect_exact: "function f(t,e){return{get:t,set:e,get g(){},set s(t){},c,a:1,m(){}}}"
|
|
||||||
}
|
|
||||||
|
|
||||||
use_shorthand_opportunity: {
|
|
||||||
beautify = {
|
|
||||||
ecma: 6
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
var foo = 123;
|
|
||||||
var obj = {foo: foo};
|
|
||||||
}
|
|
||||||
expect_exact: "var foo=123;var obj={foo};"
|
|
||||||
}
|
|
||||||
|
|
||||||
computed_property_names: {
|
|
||||||
input: {
|
|
||||||
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: {
|
|
||||||
options = {
|
|
||||||
evaluate: true
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
obj({
|
|
||||||
[1 + 1]: 2,
|
|
||||||
["x" + "x"]: 6
|
|
||||||
});
|
|
||||||
}
|
|
||||||
expect_exact: 'obj({[2]:2,["xx"]:6});'
|
|
||||||
}
|
|
||||||
|
|
||||||
computed_property_names_evaluated_2: {
|
|
||||||
options = {
|
|
||||||
evaluate: true
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
var foo = something();
|
|
||||||
|
|
||||||
var obj = {
|
|
||||||
[foo]() {
|
|
||||||
return "blah";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
expect_exact: 'var foo=something();var obj={[foo](){return"blah"}};'
|
|
||||||
}
|
|
||||||
|
|
||||||
shorthand_properties: {
|
|
||||||
mangle = true;
|
|
||||||
input: {
|
|
||||||
(function() {
|
|
||||||
var prop = 1;
|
|
||||||
const value = {prop};
|
|
||||||
return value;
|
|
||||||
})();
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
(function() {
|
|
||||||
var n = 1;
|
|
||||||
const r = {prop:n};
|
|
||||||
return r;
|
|
||||||
})();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
concise_methods: {
|
|
||||||
beautify = {
|
|
||||||
ecma: 6
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
x = {
|
|
||||||
foo(a, b) {
|
|
||||||
return x;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
y = {
|
|
||||||
foo([{a}]) {
|
|
||||||
return a;
|
|
||||||
},
|
|
||||||
bar(){}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
expect_exact: "x={foo(a,b){return x}};y={foo([{a}]){return a},bar(){}};"
|
|
||||||
}
|
|
||||||
|
|
||||||
concise_methods_with_computed_property: {
|
|
||||||
options = {
|
|
||||||
evaluate: true
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
var foo = {
|
|
||||||
[Symbol.iterator]() {
|
|
||||||
return { /* stuff */ }
|
|
||||||
},
|
|
||||||
[1 + 2]() {
|
|
||||||
return 3;
|
|
||||||
},
|
|
||||||
["1" + "4"]() {
|
|
||||||
return 14;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
var foo = {
|
|
||||||
[Symbol.iterator]() {
|
|
||||||
return { /* stuff */ }
|
|
||||||
},
|
|
||||||
[3]() {
|
|
||||||
return 3;
|
|
||||||
},
|
|
||||||
["14"]() {
|
|
||||||
return 14;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
concise_methods_with_computed_property2: {
|
|
||||||
options = {
|
|
||||||
evaluate: true
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
var foo = {
|
|
||||||
[[1]](){
|
|
||||||
return "success";
|
|
||||||
}
|
|
||||||
};
|
|
||||||
doSomething(foo[[1]]());
|
|
||||||
}
|
|
||||||
expect_exact: 'var foo={[[1]](){return"success"}};doSomething(foo[[1]]());'
|
|
||||||
}
|
|
||||||
|
|
||||||
concise_methods_with_various_property_names: {
|
|
||||||
input: {
|
|
||||||
var get = "bar";
|
|
||||||
var a = {
|
|
||||||
bar() {
|
|
||||||
return this.get;
|
|
||||||
},
|
|
||||||
5() {
|
|
||||||
return "five";
|
|
||||||
},
|
|
||||||
0xf55() {
|
|
||||||
return "f five five";
|
|
||||||
},
|
|
||||||
"five"() {
|
|
||||||
return 5;
|
|
||||||
},
|
|
||||||
0b1010(value) {
|
|
||||||
this._ten = value;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
var get = "bar";
|
|
||||||
var a = {
|
|
||||||
bar() {
|
|
||||||
return this.get;
|
|
||||||
},
|
|
||||||
5() {
|
|
||||||
return "five";
|
|
||||||
},
|
|
||||||
0xf55() {
|
|
||||||
return "f five five";
|
|
||||||
},
|
|
||||||
"five"() {
|
|
||||||
return 5;
|
|
||||||
},
|
|
||||||
0b1010(value) {
|
|
||||||
this._ten = value;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
concise_methods_and_mangle_props: {
|
|
||||||
mangle = {
|
|
||||||
properties: {
|
|
||||||
regex: /_/,
|
|
||||||
},
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
function x() {
|
|
||||||
obj = {
|
|
||||||
_foo() { return 1; }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
function x() {
|
|
||||||
obj = {
|
|
||||||
o() { return 1; }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
concise_generators: {
|
|
||||||
beautify = {
|
|
||||||
ecma: 6
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
x = {
|
|
||||||
*foo(a, b) {
|
|
||||||
return x;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
y = {
|
|
||||||
*foo([{a}]) {
|
|
||||||
yield a;
|
|
||||||
},
|
|
||||||
bar(){}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
expect_exact: "x={*foo(a,b){return x}};y={*foo([{a}]){yield a},bar(){}};"
|
|
||||||
}
|
|
||||||
|
|
||||||
concise_methods_and_keyword_names: {
|
|
||||||
input: {
|
|
||||||
x = {
|
|
||||||
catch() {},
|
|
||||||
throw() {}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
x={catch(){},throw(){}};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
getter_setter_with_computed_value: {
|
|
||||||
input: {
|
|
||||||
class C {
|
|
||||||
get ['a']() {
|
|
||||||
return 'A';
|
|
||||||
}
|
|
||||||
set ['a'](value) {
|
|
||||||
do_something(a);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
var x = {
|
|
||||||
get [a.b]() {
|
|
||||||
return 42;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
class MyArray extends Array {
|
|
||||||
get [Symbol.species]() {
|
|
||||||
return Array;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
expect_exact: 'class C{get["a"](){return"A"}set["a"](value){do_something(a)}}var x={get[a.b](){return 42}};class MyArray extends Array{get[Symbol.species](){return Array}}'
|
|
||||||
}
|
|
||||||
|
|
||||||
property_with_operator_value: {
|
|
||||||
input: {
|
|
||||||
var foo = {
|
|
||||||
"*": 1,
|
|
||||||
get "*"() {
|
|
||||||
return 2;
|
|
||||||
},
|
|
||||||
*"*"() {
|
|
||||||
return 3;
|
|
||||||
},
|
|
||||||
"%": 1,
|
|
||||||
get "%"() {
|
|
||||||
return 2;
|
|
||||||
},
|
|
||||||
*"%"() {
|
|
||||||
return 3;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
class bar {
|
|
||||||
get "*"() {
|
|
||||||
return 1
|
|
||||||
}
|
|
||||||
*"*"() {
|
|
||||||
return 2;
|
|
||||||
}
|
|
||||||
get "%"() {
|
|
||||||
return 1
|
|
||||||
}
|
|
||||||
*"%"() {
|
|
||||||
return 2;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
expect_exact: 'var foo={"*":1,get"*"(){return 2},*"*"(){return 3},"%":1,get"%"(){return 2},*"%"(){return 3}};class bar{get"*"(){return 1}*"*"(){return 2}get"%"(){return 1}*"%"(){return 2}}'
|
|
||||||
}
|
|
||||||
|
|
||||||
property_with_unprintable: {
|
|
||||||
input: {
|
|
||||||
var foo = {
|
|
||||||
"\x00\x01": "foo",
|
|
||||||
get "\x00\x01"() {
|
|
||||||
return "bar";
|
|
||||||
},
|
|
||||||
set "\x00\x01"(foo) {
|
|
||||||
save(foo);
|
|
||||||
},
|
|
||||||
*"\x00\x01"() {
|
|
||||||
return "foobar";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
class bar {
|
|
||||||
get "\x00\x01"() {
|
|
||||||
return "bar"
|
|
||||||
}
|
|
||||||
set "\x00\x01"(foo) {
|
|
||||||
save(foo);
|
|
||||||
}
|
|
||||||
*"\x00\x01"() {
|
|
||||||
return "foobar";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
expect_exact: 'var foo={"\\0\x01":"foo",get"\\0\x01"(){return"bar"},set"\\0\x01"(foo){save(foo)},*"\\0\x01"(){return"foobar"}};class bar{get"\\0\x01"(){return"bar"}set"\\0\x01"(foo){save(foo)}*"\\0\x01"(){return"foobar"}}'
|
|
||||||
}
|
|
||||||
|
|
||||||
property_with_unprintable_ascii_only: {
|
|
||||||
beautify = {
|
|
||||||
ascii_only: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
var foo = {
|
|
||||||
"\x00\x01": "foo",
|
|
||||||
get "\x00\x01"() {
|
|
||||||
return "bar";
|
|
||||||
},
|
|
||||||
set "\x00\x01"(foo) {
|
|
||||||
save(foo);
|
|
||||||
},
|
|
||||||
*"\x00\x01"() {
|
|
||||||
return "foobar";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
class bar {
|
|
||||||
get "\x00\x01"() {
|
|
||||||
return "bar"
|
|
||||||
}
|
|
||||||
set "\x00\x01"(foo) {
|
|
||||||
save(foo);
|
|
||||||
}
|
|
||||||
*"\x00\x01"() {
|
|
||||||
return "foobar";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
expect_exact: 'var foo={"\\0\\x01":"foo",get"\\0\\x01"(){return"bar"},set"\\0\\x01"(foo){save(foo)},*"\\0\\x01"(){return"foobar"}};class bar{get"\\0\\x01"(){return"bar"}set"\\0\\x01"(foo){save(foo)}*"\\0\\x01"(){return"foobar"}}'
|
|
||||||
}
|
|
||||||
|
|
||||||
property_with_unprintable_ascii_only_static: {
|
|
||||||
beautify = {
|
|
||||||
ascii_only: true
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
class foo {
|
|
||||||
static get "\x02\x03"() {
|
|
||||||
return "bar";
|
|
||||||
}
|
|
||||||
static set "\x04\x05"(foo) {
|
|
||||||
save(foo);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
expect_exact: 'class foo{static get"\\x02\\x03"(){return"bar"}static set"\\x04\\x05"(foo){save(foo)}}'
|
|
||||||
}
|
|
||||||
|
|
||||||
methods_and_getters_with_keep_quoted_props_enabled: {
|
|
||||||
beautify = {
|
|
||||||
quote_style: 3,
|
|
||||||
keep_quoted_props: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
var obj = {
|
|
||||||
a() {},
|
|
||||||
"b"() {},
|
|
||||||
get c() { return "c"},
|
|
||||||
get "d"() { return "d"},
|
|
||||||
set e(a) { doSomething(a); },
|
|
||||||
set f(a) { doSomething(b); }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
expect_exact: 'var obj={a(){},"b"(){},get c(){return"c"},get"d"(){return"d"},set e(a){doSomething(a)},set f(a){doSomething(b)}};'
|
|
||||||
}
|
|
||||||
|
|
||||||
allow_assignments_to_property_values: {
|
|
||||||
input: {
|
|
||||||
var foo = {123: foo = 123} = {foo: "456"};
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
var foo = {123: foo = 123} = {foo: "456"};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
variable_as_computed_property: {
|
|
||||||
input: {
|
|
||||||
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"
|
|
||||||
}
|
|
||||||
@@ -1,186 +0,0 @@
|
|||||||
arrow_functions: {
|
|
||||||
options = {
|
|
||||||
arrows: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
(a) => b; // 1 args
|
|
||||||
(a, b) => c; // n args
|
|
||||||
() => b; // 0 args
|
|
||||||
(a) => (b) => c; // func returns func returns func
|
|
||||||
(a) => ((b) => c); // So these parens are dropped
|
|
||||||
() => (b,c) => d; // func returns func returns func
|
|
||||||
a=>{return b;}
|
|
||||||
a => 'lel'; // Dropping the parens
|
|
||||||
}
|
|
||||||
expect_exact: "a=>b;(a,b)=>c;()=>b;a=>b=>c;a=>b=>c;()=>(b,c)=>d;a=>b;a=>\"lel\";"
|
|
||||||
}
|
|
||||||
|
|
||||||
arrow_return: {
|
|
||||||
options = {
|
|
||||||
arrows: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
() => {};
|
|
||||||
() => { return; };
|
|
||||||
a => { return 1; }
|
|
||||||
a => { return -b }
|
|
||||||
a => { return b; var b; }
|
|
||||||
(x, y) => { return x - y; }
|
|
||||||
}
|
|
||||||
expect_exact: "()=>{};()=>{};a=>1;a=>-b;a=>{return b;var b};(x,y)=>x-y;"
|
|
||||||
}
|
|
||||||
|
|
||||||
regression_arrow_functions_and_hoist: {
|
|
||||||
options = {
|
|
||||||
hoist_vars: true,
|
|
||||||
hoist_funs: true
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
(a) => b;
|
|
||||||
}
|
|
||||||
expect_exact: "a=>b;"
|
|
||||||
}
|
|
||||||
|
|
||||||
regression_assign_arrow_functions: {
|
|
||||||
input: {
|
|
||||||
oninstall = e => false;
|
|
||||||
oninstall = () => false;
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
oninstall=e=>false;
|
|
||||||
oninstall=()=>false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
destructuring_arguments_1: {
|
|
||||||
input: {
|
|
||||||
(function ( a ) { });
|
|
||||||
(function ( [ a ] ) { });
|
|
||||||
(function ( [ a, b ] ) { });
|
|
||||||
(function ( [ [ a ] ] ) { });
|
|
||||||
(function ( [ [ a, b ] ] ) { });
|
|
||||||
(function ( [ a, [ b ] ] ) { });
|
|
||||||
(function ( [ [ b ], a ] ) { });
|
|
||||||
|
|
||||||
(function ( { a } ) { });
|
|
||||||
(function ( { a, b } ) { });
|
|
||||||
|
|
||||||
(function ( [ { a } ] ) { });
|
|
||||||
(function ( [ { a, b } ] ) { });
|
|
||||||
(function ( [ a, { b } ] ) { });
|
|
||||||
(function ( [ { b }, a ] ) { });
|
|
||||||
|
|
||||||
( [ a ] ) => { };
|
|
||||||
( [ a, b ] ) => { };
|
|
||||||
|
|
||||||
( { a } ) => { };
|
|
||||||
( { a, b, c, d, e } ) => { };
|
|
||||||
|
|
||||||
( [ a ] ) => b;
|
|
||||||
( [ a, b ] ) => c;
|
|
||||||
|
|
||||||
( { a } ) => b;
|
|
||||||
( { a, b } ) => c;
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
(function(a){});
|
|
||||||
(function([a]){});
|
|
||||||
(function([a,b]){});
|
|
||||||
(function([[a]]){});
|
|
||||||
(function([[a,b]]){});
|
|
||||||
(function([a,[b]]){});
|
|
||||||
(function([[b],a]){});
|
|
||||||
|
|
||||||
(function({a}){});
|
|
||||||
(function({a,b}){});
|
|
||||||
|
|
||||||
(function([{a}]){});
|
|
||||||
(function([{a,b}]){});
|
|
||||||
(function([a,{b}]){});
|
|
||||||
(function([{b},a]){});
|
|
||||||
|
|
||||||
([a])=>{};
|
|
||||||
([a,b])=>{};
|
|
||||||
|
|
||||||
({a})=>{};
|
|
||||||
({a,b,c,d,e})=>{};
|
|
||||||
|
|
||||||
([a])=>b;
|
|
||||||
([a,b])=>c;
|
|
||||||
|
|
||||||
({a})=>b;
|
|
||||||
({a,b})=>c;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
destructuring_arguments_2: {
|
|
||||||
input: {
|
|
||||||
(function([]) {});
|
|
||||||
(function({}) {});
|
|
||||||
(function([,,,,,]) {});
|
|
||||||
(function ([a, {b: c}]) {});
|
|
||||||
(function ([...args]) {});
|
|
||||||
(function ({x,}) {});
|
|
||||||
class a { *method({ [thrower()]: x } = {}) {}};
|
|
||||||
(function(a, b, c, d, [{e: [...f]}]){})(1, 2, 3, 4, [{e: [1, 2, 3]}]);
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
(function([]) {});
|
|
||||||
(function({}) {});
|
|
||||||
(function([,,,,,]) {});
|
|
||||||
(function ([a, {b: c}]) {});
|
|
||||||
(function ([...args]) {});
|
|
||||||
(function ({x,}) {});
|
|
||||||
class a { *method({ [thrower()]: x } = {}) {}};
|
|
||||||
(function(a, b, c, d, [{e: [...f]}]){})(1, 2, 3, 4, [{e: [1, 2, 3]}]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
destructuring_arguments_3: {
|
|
||||||
beautify = {
|
|
||||||
ecma: 6
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
function fn3({x: {y: {z: {} = 42}}}) {}
|
|
||||||
const { a = (function () {}), b = (0, function() {}) } = {};
|
|
||||||
let { c = (function () {}), d = (0, function() {}) } = {};
|
|
||||||
var { e = (function () {}), f = (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: {
|
|
||||||
beautify = {
|
|
||||||
ecma: 6
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
function x(a = 6) { }
|
|
||||||
function x(a = (6 + 5)) { }
|
|
||||||
function x({ foo } = {}, [ bar ] = [ 1 ]) { }
|
|
||||||
}
|
|
||||||
expect_exact: "function x(a=6){}function x(a=6+5){}function x({foo}={},[bar]=[1]){}"
|
|
||||||
}
|
|
||||||
|
|
||||||
default_values_in_destructurings: {
|
|
||||||
beautify = {
|
|
||||||
ecma: 6
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
function x({a=(4), b}) {}
|
|
||||||
function x([b, c=(12)]) {}
|
|
||||||
var { x = (6), y } = x;
|
|
||||||
var [ x, y = (6) ] = x;
|
|
||||||
}
|
|
||||||
expect_exact: "function x({a=4,b}){}function x([b,c=12]){}var{x=6,y}=x;var[x,y=6]=x;"
|
|
||||||
}
|
|
||||||
|
|
||||||
accept_duplicated_parameters_in_non_strict_without_spread_or_default_assignment: {
|
|
||||||
input: {
|
|
||||||
function a(b, b){}
|
|
||||||
function b({c: test, c: test}){}
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
function a(b, b){}
|
|
||||||
function b({c: test, c: test}){}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -159,7 +159,6 @@ mangle_unquoted_properties: {
|
|||||||
}
|
}
|
||||||
mangle = {
|
mangle = {
|
||||||
properties: {
|
properties: {
|
||||||
builtins: true,
|
|
||||||
keep_quoted: true,
|
keep_quoted: true,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
@@ -259,7 +258,6 @@ mangle_debug_suffix_keep_quoted: {
|
|||||||
}
|
}
|
||||||
mangle = {
|
mangle = {
|
||||||
properties: {
|
properties: {
|
||||||
builtins: true,
|
|
||||||
debug: "XYZ",
|
debug: "XYZ",
|
||||||
keep_quoted: true,
|
keep_quoted: true,
|
||||||
reserved: [],
|
reserved: [],
|
||||||
@@ -569,16 +567,41 @@ native_prototype: {
|
|||||||
}
|
}
|
||||||
input: {
|
input: {
|
||||||
Array.prototype.splice.apply(a, [1, 2, b, c]);
|
Array.prototype.splice.apply(a, [1, 2, b, c]);
|
||||||
|
Function.prototype.call.apply(console.log, console, [ "foo" ]);
|
||||||
|
Number.prototype.toFixed.call(Math.PI, 2);
|
||||||
Object.prototype.hasOwnProperty.call(d, "foo");
|
Object.prototype.hasOwnProperty.call(d, "foo");
|
||||||
|
RegExp.prototype.test.call(/foo/, "bar");
|
||||||
String.prototype.indexOf.call(e, "bar");
|
String.prototype.indexOf.call(e, "bar");
|
||||||
}
|
}
|
||||||
expect: {
|
expect: {
|
||||||
[].splice.apply(a, [1, 2, b, c]);
|
[].splice.apply(a, [1, 2, b, c]);
|
||||||
|
(function() {}).call.apply(console.log, console, [ "foo" ]);
|
||||||
|
0..toFixed.call(Math.PI, 2);
|
||||||
({}).hasOwnProperty.call(d, "foo");
|
({}).hasOwnProperty.call(d, "foo");
|
||||||
|
/t/.test.call(/foo/, "bar");
|
||||||
"".indexOf.call(e, "bar");
|
"".indexOf.call(e, "bar");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
native_prototype_lhs: {
|
||||||
|
options = {
|
||||||
|
unsafe_proto: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
console.log(function() {
|
||||||
|
Function.prototype.bar = "PASS";
|
||||||
|
return function() {};
|
||||||
|
}().bar);
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
console.log(function() {
|
||||||
|
Function.prototype.bar = "PASS";
|
||||||
|
return function() {};
|
||||||
|
}().bar);
|
||||||
|
}
|
||||||
|
expect_stdout: "PASS"
|
||||||
|
}
|
||||||
|
|
||||||
accessor_boolean: {
|
accessor_boolean: {
|
||||||
input: {
|
input: {
|
||||||
var a = 1;
|
var a = 1;
|
||||||
@@ -794,172 +817,6 @@ issue_2208_5: {
|
|||||||
expect_stdout: "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: {
|
issue_2256: {
|
||||||
options = {
|
options = {
|
||||||
side_effects: true,
|
side_effects: true,
|
||||||
@@ -978,91 +835,6 @@ issue_2256: {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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: {
|
lhs_prop_1: {
|
||||||
options = {
|
options = {
|
||||||
evaluate: true,
|
evaluate: true,
|
||||||
@@ -1263,30 +1035,6 @@ array_hole: {
|
|||||||
expect_stdout: "2 undefined 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: {
|
new_this: {
|
||||||
options = {
|
options = {
|
||||||
properties: true,
|
properties: true,
|
||||||
@@ -1331,3 +1079,512 @@ issue_2513: {
|
|||||||
"undefined undefined",
|
"undefined undefined",
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const_prop_assign_strict: {
|
||||||
|
options = {
|
||||||
|
pure_getters: "strict",
|
||||||
|
side_effects: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
function Simulator() {
|
||||||
|
/abc/.index = 1;
|
||||||
|
this._aircraft = [];
|
||||||
|
}
|
||||||
|
(function() {}).prototype.destroy = x();
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
function Simulator() {
|
||||||
|
this._aircraft = [];
|
||||||
|
}
|
||||||
|
x();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const_prop_assign_pure: {
|
||||||
|
options = {
|
||||||
|
pure_getters: true,
|
||||||
|
side_effects: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
function Simulator() {
|
||||||
|
/abc/.index = 1;
|
||||||
|
this._aircraft = [];
|
||||||
|
}
|
||||||
|
(function() {}).prototype.destroy = x();
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
function Simulator() {
|
||||||
|
this._aircraft = [];
|
||||||
|
}
|
||||||
|
x();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
join_object_assignments_1: {
|
||||||
|
options = {
|
||||||
|
evaluate: true,
|
||||||
|
join_vars: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
console.log(function() {
|
||||||
|
var x = {
|
||||||
|
a: 1,
|
||||||
|
c: (console.log("c"), "C"),
|
||||||
|
};
|
||||||
|
x.b = 2;
|
||||||
|
x[3] = function() {
|
||||||
|
console.log(x);
|
||||||
|
},
|
||||||
|
x["a"] = /foo/,
|
||||||
|
x.bar = x;
|
||||||
|
return x;
|
||||||
|
}());
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
console.log(function() {
|
||||||
|
var x = {
|
||||||
|
a: 1,
|
||||||
|
c: (console.log("c"), "C"),
|
||||||
|
b: 2,
|
||||||
|
3: function() {
|
||||||
|
console.log(x);
|
||||||
|
},
|
||||||
|
a: /foo/,
|
||||||
|
};
|
||||||
|
x.bar = x;
|
||||||
|
return x;
|
||||||
|
}());
|
||||||
|
}
|
||||||
|
expect_stdout: true
|
||||||
|
}
|
||||||
|
|
||||||
|
join_object_assignments_2: {
|
||||||
|
options = {
|
||||||
|
evaluate: true,
|
||||||
|
hoist_props: true,
|
||||||
|
join_vars: true,
|
||||||
|
passes: 3,
|
||||||
|
reduce_vars: true,
|
||||||
|
toplevel: true,
|
||||||
|
unused: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
var o = {
|
||||||
|
foo: 1,
|
||||||
|
};
|
||||||
|
o.bar = 2;
|
||||||
|
o.baz = 3;
|
||||||
|
console.log(o.foo, o.bar + o.bar, o.foo * o.bar * o.baz);
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
console.log(1, 4, 6);
|
||||||
|
}
|
||||||
|
expect_stdout: "1 4 6"
|
||||||
|
}
|
||||||
|
|
||||||
|
join_object_assignments_3: {
|
||||||
|
options = {
|
||||||
|
evaluate: true,
|
||||||
|
join_vars: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
console.log(function() {
|
||||||
|
var o = {
|
||||||
|
a: "PASS",
|
||||||
|
}, a = o.a;
|
||||||
|
o.a = "FAIL";
|
||||||
|
return a;
|
||||||
|
}());
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
console.log(function() {
|
||||||
|
var o = {
|
||||||
|
a: "PASS",
|
||||||
|
}, a = o.a;
|
||||||
|
o.a = "FAIL";
|
||||||
|
return a;
|
||||||
|
}());
|
||||||
|
}
|
||||||
|
expect_stdout: "PASS"
|
||||||
|
}
|
||||||
|
|
||||||
|
join_object_assignments_return_1: {
|
||||||
|
options = {
|
||||||
|
join_vars: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
console.log(function() {
|
||||||
|
var o = {
|
||||||
|
p: 3
|
||||||
|
};
|
||||||
|
return o.q = "foo";
|
||||||
|
}());
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
console.log(function() {
|
||||||
|
var o = {
|
||||||
|
p: 3,
|
||||||
|
q: "foo"
|
||||||
|
};
|
||||||
|
return o.q;
|
||||||
|
}());
|
||||||
|
}
|
||||||
|
expect_stdout: "foo"
|
||||||
|
}
|
||||||
|
|
||||||
|
join_object_assignments_return_2: {
|
||||||
|
options = {
|
||||||
|
join_vars: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
console.log(function() {
|
||||||
|
var o = {
|
||||||
|
p: 3
|
||||||
|
};
|
||||||
|
return o.q = /foo/,
|
||||||
|
o.r = "bar";
|
||||||
|
}());
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
console.log(function() {
|
||||||
|
var o = {
|
||||||
|
p: 3,
|
||||||
|
q: /foo/,
|
||||||
|
r: "bar"
|
||||||
|
};
|
||||||
|
return o.r;
|
||||||
|
}());
|
||||||
|
}
|
||||||
|
expect_stdout: "bar"
|
||||||
|
}
|
||||||
|
|
||||||
|
join_object_assignments_return_3: {
|
||||||
|
options = {
|
||||||
|
join_vars: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
console.log(function() {
|
||||||
|
var o = {
|
||||||
|
p: 3
|
||||||
|
};
|
||||||
|
return o.q = "foo",
|
||||||
|
o.p += "",
|
||||||
|
console.log(o.q),
|
||||||
|
o.p;
|
||||||
|
}());
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
console.log(function() {
|
||||||
|
var o = {
|
||||||
|
p: 3,
|
||||||
|
q: "foo"
|
||||||
|
};
|
||||||
|
return o.p += "",
|
||||||
|
console.log(o.q),
|
||||||
|
o.p;
|
||||||
|
}());
|
||||||
|
}
|
||||||
|
expect_stdout: [
|
||||||
|
"foo",
|
||||||
|
"3",
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
|
join_object_assignments_for: {
|
||||||
|
options = {
|
||||||
|
join_vars: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
console.log(function() {
|
||||||
|
var o = {
|
||||||
|
p: 3
|
||||||
|
};
|
||||||
|
for (o.q = "foo"; console.log(o.q););
|
||||||
|
return o.p;
|
||||||
|
}());
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
console.log(function() {
|
||||||
|
for (var o = {
|
||||||
|
p: 3,
|
||||||
|
q: "foo"
|
||||||
|
}; console.log(o.q););
|
||||||
|
return o.p;
|
||||||
|
}());
|
||||||
|
}
|
||||||
|
expect_stdout: [
|
||||||
|
"foo",
|
||||||
|
"3",
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
|
join_object_assignments_if: {
|
||||||
|
options = {
|
||||||
|
join_vars: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
console.log(function() {
|
||||||
|
var o = {};
|
||||||
|
if (o.a = "PASS") return o.a;
|
||||||
|
}())
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
console.log(function() {
|
||||||
|
var o = { a: "PASS" };
|
||||||
|
if (o.a) return o.a;
|
||||||
|
}());
|
||||||
|
}
|
||||||
|
expect_stdout: "PASS"
|
||||||
|
}
|
||||||
|
|
||||||
|
join_object_assignments_forin: {
|
||||||
|
options = {
|
||||||
|
join_vars: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
console.log(function() {
|
||||||
|
var o = {};
|
||||||
|
for (var a in o.a = "PASS", o)
|
||||||
|
return o[a];
|
||||||
|
}())
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
console.log(function() {
|
||||||
|
var o = { a: "PASS" };
|
||||||
|
for (var a in o)
|
||||||
|
return o[a];
|
||||||
|
}());
|
||||||
|
}
|
||||||
|
expect_stdout: "PASS"
|
||||||
|
}
|
||||||
|
|
||||||
|
join_object_assignments_negative: {
|
||||||
|
options = {
|
||||||
|
evaluate: true,
|
||||||
|
join_vars: true,
|
||||||
|
properties: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
var o = {};
|
||||||
|
o[0] = 0;
|
||||||
|
o[-0] = 1;
|
||||||
|
o[-1] = 2;
|
||||||
|
console.log(o[0], o[-0], o[-1]);
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
var o = {
|
||||||
|
0: 0,
|
||||||
|
0: 1,
|
||||||
|
"-1": 2
|
||||||
|
};
|
||||||
|
console.log(o[0], o[-0], o[-1]);
|
||||||
|
}
|
||||||
|
expect_stdout: "1 1 2"
|
||||||
|
}
|
||||||
|
|
||||||
|
join_object_assignments_NaN_1: {
|
||||||
|
options = {
|
||||||
|
join_vars: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
var o = {};
|
||||||
|
o[NaN] = 1;
|
||||||
|
o[0/0] = 2;
|
||||||
|
console.log(o[NaN], o[NaN]);
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
var o = {};
|
||||||
|
o[NaN] = 1;
|
||||||
|
o[0/0] = 2;
|
||||||
|
console.log(o[NaN], o[NaN]);
|
||||||
|
}
|
||||||
|
expect_stdout: "2 2"
|
||||||
|
}
|
||||||
|
|
||||||
|
join_object_assignments_NaN_2: {
|
||||||
|
options = {
|
||||||
|
evaluate: true,
|
||||||
|
join_vars: true,
|
||||||
|
properties: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
var o = {};
|
||||||
|
o[NaN] = 1;
|
||||||
|
o[0/0] = 2;
|
||||||
|
console.log(o[NaN], o[NaN]);
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
var o = {
|
||||||
|
NaN: 1,
|
||||||
|
NaN: 2
|
||||||
|
};
|
||||||
|
console.log(o.NaN, o.NaN);
|
||||||
|
}
|
||||||
|
expect_stdout: "2 2"
|
||||||
|
}
|
||||||
|
|
||||||
|
join_object_assignments_null_0: {
|
||||||
|
options = {
|
||||||
|
join_vars: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
var o = {};
|
||||||
|
o[null] = 1;
|
||||||
|
console.log(o[null]);
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
var o = {};
|
||||||
|
o[null] = 1;
|
||||||
|
console.log(o[null]);
|
||||||
|
}
|
||||||
|
expect_stdout: "1"
|
||||||
|
}
|
||||||
|
|
||||||
|
join_object_assignments_null_1: {
|
||||||
|
options = {
|
||||||
|
evaluate: true,
|
||||||
|
join_vars: true,
|
||||||
|
properties: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
var o = {};
|
||||||
|
o[null] = 1;
|
||||||
|
console.log(o[null]);
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
var o = {
|
||||||
|
null: 1
|
||||||
|
};
|
||||||
|
console.log(o.null);
|
||||||
|
}
|
||||||
|
expect_stdout: "1"
|
||||||
|
}
|
||||||
|
|
||||||
|
join_object_assignments_void_0: {
|
||||||
|
options = {
|
||||||
|
evaluate: true,
|
||||||
|
join_vars: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
var o = {};
|
||||||
|
o[void 0] = 1;
|
||||||
|
console.log(o[void 0]);
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
var o = {
|
||||||
|
undefined: 1
|
||||||
|
};
|
||||||
|
console.log(o[void 0]);
|
||||||
|
}
|
||||||
|
expect_stdout: "1"
|
||||||
|
}
|
||||||
|
|
||||||
|
join_object_assignments_undefined_1: {
|
||||||
|
options = {
|
||||||
|
join_vars: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
var o = {};
|
||||||
|
o[undefined] = 1;
|
||||||
|
console.log(o[undefined]);
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
var o = {};
|
||||||
|
o[void 0] = 1;
|
||||||
|
console.log(o[void 0]);
|
||||||
|
}
|
||||||
|
expect_stdout: "1"
|
||||||
|
}
|
||||||
|
|
||||||
|
join_object_assignments_undefined_2: {
|
||||||
|
options = {
|
||||||
|
evaluate: true,
|
||||||
|
join_vars: true,
|
||||||
|
properties: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
var o = {};
|
||||||
|
o[undefined] = 1;
|
||||||
|
console.log(o[undefined]);
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
var o = {
|
||||||
|
undefined : 1
|
||||||
|
};
|
||||||
|
console.log(o[void 0]);
|
||||||
|
}
|
||||||
|
expect_stdout: "1"
|
||||||
|
}
|
||||||
|
|
||||||
|
join_object_assignments_Infinity: {
|
||||||
|
options = {
|
||||||
|
evaluate: true,
|
||||||
|
join_vars: true,
|
||||||
|
properties: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
var o = {};
|
||||||
|
o[Infinity] = 1;
|
||||||
|
o[1/0] = 2;
|
||||||
|
o[-Infinity] = 3;
|
||||||
|
o[-1/0] = 4;
|
||||||
|
console.log(o[Infinity], o[1/0], o[-Infinity], o[-1/0]);
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
var o = {
|
||||||
|
Infinity: 1,
|
||||||
|
Infinity: 2,
|
||||||
|
"-Infinity": 3,
|
||||||
|
"-Infinity": 4
|
||||||
|
};
|
||||||
|
console.log(o[1/0], o[1/0], o[-1/0], o[-1/0]);
|
||||||
|
}
|
||||||
|
expect_stdout: "2 2 4 4"
|
||||||
|
}
|
||||||
|
|
||||||
|
join_object_assignments_regex: {
|
||||||
|
options = {
|
||||||
|
evaluate: true,
|
||||||
|
join_vars: true,
|
||||||
|
properties: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
var o = {};
|
||||||
|
o[/rx/] = 1;
|
||||||
|
console.log(o[/rx/]);
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
var o = {
|
||||||
|
"/rx/": 1
|
||||||
|
};
|
||||||
|
console.log(o[/rx/]);
|
||||||
|
}
|
||||||
|
expect_stdout: "1"
|
||||||
|
}
|
||||||
|
|
||||||
|
issue_2816: {
|
||||||
|
options = {
|
||||||
|
join_vars: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
"use strict";
|
||||||
|
var o = {
|
||||||
|
a: 1
|
||||||
|
};
|
||||||
|
o.b = 2;
|
||||||
|
o.a = 3;
|
||||||
|
o.c = 4;
|
||||||
|
console.log(o.a, o.b, o.c);
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
"use strict";
|
||||||
|
var o = {
|
||||||
|
a: 1,
|
||||||
|
b: 2
|
||||||
|
};
|
||||||
|
o.a = 3;
|
||||||
|
o.c = 4;
|
||||||
|
console.log(o.a, o.b, o.c);
|
||||||
|
}
|
||||||
|
expect_stdout: "3 2 4"
|
||||||
|
}
|
||||||
|
|||||||
@@ -293,3 +293,245 @@ unary: {
|
|||||||
bar();
|
bar();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
issue_2629_1: {
|
||||||
|
options = {
|
||||||
|
side_effects: true,
|
||||||
|
}
|
||||||
|
beautify = {
|
||||||
|
comments: "all",
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
/*@__PURE__*/ a();
|
||||||
|
/*@__PURE__*/ (b());
|
||||||
|
(/*@__PURE__*/ c)();
|
||||||
|
(/*@__PURE__*/ d());
|
||||||
|
}
|
||||||
|
expect_exact: [
|
||||||
|
"/* */c();",
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
|
issue_2629_2: {
|
||||||
|
options = {
|
||||||
|
side_effects: true,
|
||||||
|
}
|
||||||
|
beautify = {
|
||||||
|
comments: "all",
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
/*@__PURE__*/ a(1)(2)(3);
|
||||||
|
/*@__PURE__*/ (b(1))(2)(3);
|
||||||
|
/*@__PURE__*/ (c(1)(2))(3);
|
||||||
|
/*@__PURE__*/ (d(1)(2)(3));
|
||||||
|
(/*@__PURE__*/ e)(1)(2)(3);
|
||||||
|
(/*@__PURE__*/ f(1))(2)(3);
|
||||||
|
(/*@__PURE__*/ g(1)(2))(3);
|
||||||
|
(/*@__PURE__*/ h(1)(2)(3));
|
||||||
|
}
|
||||||
|
expect_exact: [
|
||||||
|
"/* */e(1)(2)(3);",
|
||||||
|
"/* */f(1)(2)(3);",
|
||||||
|
"/* */g(1)(2)(3);",
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
|
issue_2629_3: {
|
||||||
|
options = {
|
||||||
|
side_effects: true,
|
||||||
|
}
|
||||||
|
beautify = {
|
||||||
|
comments: "all",
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
/*@__PURE__*/ a.x(1).y(2).z(3);
|
||||||
|
/*@__PURE__*/ (b.x)(1).y(2).z(3);
|
||||||
|
/*@__PURE__*/ (c.x(1)).y(2).z(3);
|
||||||
|
/*@__PURE__*/ (d.x(1).y)(2).z(3);
|
||||||
|
/*@__PURE__*/ (e.x(1).y(2)).z(3);
|
||||||
|
/*@__PURE__*/ (f.x(1).y(2).z)(3);
|
||||||
|
/*@__PURE__*/ (g.x(1).y(2).z(3));
|
||||||
|
(/*@__PURE__*/ h).x(1).y(2).z(3);
|
||||||
|
(/*@__PURE__*/ i.x)(1).y(2).z(3);
|
||||||
|
(/*@__PURE__*/ j.x(1)).y(2).z(3);
|
||||||
|
(/*@__PURE__*/ k.x(1).y)(2).z(3);
|
||||||
|
(/*@__PURE__*/ l.x(1).y(2)).z(3);
|
||||||
|
(/*@__PURE__*/ m.x(1).y(2).z)(3);
|
||||||
|
(/*@__PURE__*/ n.x(1).y(2).z(3));
|
||||||
|
}
|
||||||
|
expect_exact: [
|
||||||
|
"/* */h.x(1).y(2).z(3);",
|
||||||
|
"/* */i.x(1).y(2).z(3);",
|
||||||
|
"/* */j.x(1).y(2).z(3);",
|
||||||
|
"/* */k.x(1).y(2).z(3);",
|
||||||
|
"/* */l.x(1).y(2).z(3);",
|
||||||
|
"/* */m.x(1).y(2).z(3);",
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
|
issue_2629_4: {
|
||||||
|
options = {
|
||||||
|
side_effects: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
(/*@__PURE__*/ x(), y());
|
||||||
|
(w(), /*@__PURE__*/ x(), y());
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
y();
|
||||||
|
w(), y();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
issue_2629_5: {
|
||||||
|
options = {
|
||||||
|
side_effects: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
[ /*@__PURE__*/ x() ];
|
||||||
|
[ /*@__PURE__*/ x(), y() ];
|
||||||
|
[ w(), /*@__PURE__*/ x(), y() ];
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
y();
|
||||||
|
w(), y();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
issue_2638: {
|
||||||
|
options = {
|
||||||
|
side_effects: true,
|
||||||
|
}
|
||||||
|
beautify = {
|
||||||
|
comments: "all",
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
/*@__PURE__*/(g() || h())(x(), y());
|
||||||
|
(/*@__PURE__*/ (a() || b()))(c(), d());
|
||||||
|
}
|
||||||
|
expect_exact: [
|
||||||
|
"/* */x(),y();",
|
||||||
|
"/* */(a()||b())(c(),d());",
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
|
issue_2705_1: {
|
||||||
|
options = {
|
||||||
|
side_effects: true,
|
||||||
|
}
|
||||||
|
beautify = {
|
||||||
|
comments: "all",
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
/*@__PURE__*/ new a();
|
||||||
|
/*@__PURE__*/ (new b());
|
||||||
|
new (/*@__PURE__*/ c)();
|
||||||
|
(/*@__PURE__*/ new d());
|
||||||
|
}
|
||||||
|
expect_exact: [
|
||||||
|
"new/* */c;",
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
|
issue_2705_2: {
|
||||||
|
options = {
|
||||||
|
side_effects: true,
|
||||||
|
}
|
||||||
|
beautify = {
|
||||||
|
comments: "all",
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
/*@__PURE__*/ new a(1)(2)(3);
|
||||||
|
/*@__PURE__*/ new (b(1))(2)(3);
|
||||||
|
/*@__PURE__*/ new (c(1)(2))(3);
|
||||||
|
/*@__PURE__*/ new (d(1)(2)(3));
|
||||||
|
new (/*@__PURE__*/ e)(1)(2)(3);
|
||||||
|
(/*@__PURE__*/ new f(1))(2)(3);
|
||||||
|
(/*@__PURE__*/ new g(1)(2))(3);
|
||||||
|
(/*@__PURE__*/ new h(1)(2)(3));
|
||||||
|
}
|
||||||
|
expect_exact: [
|
||||||
|
"new/* */e(1)(2)(3);",
|
||||||
|
"/* */new f(1)(2)(3);",
|
||||||
|
"/* */new g(1)(2)(3);",
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
|
issue_2705_3: {
|
||||||
|
options = {
|
||||||
|
side_effects: true,
|
||||||
|
}
|
||||||
|
beautify = {
|
||||||
|
comments: "all",
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
/*@__PURE__*/ new a.x(1).y(2).z(3);
|
||||||
|
/*@__PURE__*/ new (b.x)(1).y(2).z(3);
|
||||||
|
/*@__PURE__*/ new (c.x(1)).y(2).z(3);
|
||||||
|
/*@__PURE__*/ new (d.x(1).y)(2).z(3);
|
||||||
|
/*@__PURE__*/ new (e.x(1).y(2)).z(3);
|
||||||
|
/*@__PURE__*/ new (f.x(1).y(2).z)(3);
|
||||||
|
/*@__PURE__*/ new (g.x(1).y(2).z(3));
|
||||||
|
new (/*@__PURE__*/ h).x(1).y(2).z(3);
|
||||||
|
/* */ new (/*@__PURE__*/ i.x)(1).y(2).z(3);
|
||||||
|
(/*@__PURE__*/ new j.x(1)).y(2).z(3);
|
||||||
|
(/*@__PURE__*/ new k.x(1).y)(2).z(3);
|
||||||
|
(/*@__PURE__*/ new l.x(1).y(2)).z(3);
|
||||||
|
(/*@__PURE__*/ new m.x(1).y(2).z)(3);
|
||||||
|
(/*@__PURE__*/ new n.x(1).y(2).z(3));
|
||||||
|
}
|
||||||
|
expect_exact: [
|
||||||
|
"new/* */h.x(1).y(2).z(3);",
|
||||||
|
"/* */new/* */i.x(1).y(2).z(3);",
|
||||||
|
"/* */new j.x(1).y(2).z(3);",
|
||||||
|
"/* */new k.x(1).y(2).z(3);",
|
||||||
|
"/* */new l.x(1).y(2).z(3);",
|
||||||
|
"/* */new m.x(1).y(2).z(3);",
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
|
issue_2705_4: {
|
||||||
|
options = {
|
||||||
|
side_effects: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
(/*@__PURE__*/ new x(), y());
|
||||||
|
(w(), /*@__PURE__*/ new x(), y());
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
y();
|
||||||
|
w(), y();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
issue_2705_5: {
|
||||||
|
options = {
|
||||||
|
side_effects: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
[ /*@__PURE__*/ new x() ];
|
||||||
|
[ /*@__PURE__*/ new x(), y() ];
|
||||||
|
[ w(), /*@__PURE__*/ new x(), y() ];
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
y();
|
||||||
|
w(), y();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
issue_2705_6: {
|
||||||
|
options = {
|
||||||
|
side_effects: true,
|
||||||
|
}
|
||||||
|
beautify = {
|
||||||
|
comments: "all",
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
/*@__PURE__*/new (g() || h())(x(), y());
|
||||||
|
/* */ new (/*@__PURE__*/ (a() || b()))(c(), d());
|
||||||
|
}
|
||||||
|
expect_exact: [
|
||||||
|
"/* */x(),y();",
|
||||||
|
"/* */new(/* */a()||b())(c(),d());",
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|||||||
@@ -185,7 +185,7 @@ impure_getter_2: {
|
|||||||
|
|
||||||
issue_2110_1: {
|
issue_2110_1: {
|
||||||
options = {
|
options = {
|
||||||
cascade: true,
|
collapse_vars: true,
|
||||||
pure_getters: "strict",
|
pure_getters: "strict",
|
||||||
sequences: true,
|
sequences: true,
|
||||||
side_effects: true,
|
side_effects: true,
|
||||||
@@ -274,7 +274,7 @@ set_immutable_1: {
|
|||||||
|
|
||||||
set_immutable_2: {
|
set_immutable_2: {
|
||||||
options = {
|
options = {
|
||||||
cascade: true,
|
collapse_vars: true,
|
||||||
conditionals: true,
|
conditionals: true,
|
||||||
pure_getters: "strict",
|
pure_getters: "strict",
|
||||||
reduce_funcs: true,
|
reduce_funcs: true,
|
||||||
@@ -324,7 +324,7 @@ set_immutable_3: {
|
|||||||
|
|
||||||
set_immutable_4: {
|
set_immutable_4: {
|
||||||
options = {
|
options = {
|
||||||
cascade: true,
|
collapse_vars: true,
|
||||||
conditionals: true,
|
conditionals: true,
|
||||||
pure_getters: "strict",
|
pure_getters: "strict",
|
||||||
reduce_funcs: true,
|
reduce_funcs: true,
|
||||||
@@ -348,6 +348,57 @@ set_immutable_4: {
|
|||||||
expect_stdout: true
|
expect_stdout: true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
set_immutable_5: {
|
||||||
|
options = {
|
||||||
|
collapse_vars: true,
|
||||||
|
conditionals: true,
|
||||||
|
evaluate: true,
|
||||||
|
pure_getters: "strict",
|
||||||
|
reduce_funcs: true,
|
||||||
|
reduce_vars: true,
|
||||||
|
side_effects: true,
|
||||||
|
toplevel: true,
|
||||||
|
unused: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
"use strict";
|
||||||
|
var a = 1;
|
||||||
|
a.foo += "";
|
||||||
|
if (a.foo) console.log("FAIL");
|
||||||
|
else console.log("PASS");
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
"use strict";
|
||||||
|
1..foo += "";
|
||||||
|
1..foo ? console.log("FAIL") : console.log("PASS");
|
||||||
|
}
|
||||||
|
expect_stdout: true
|
||||||
|
}
|
||||||
|
|
||||||
|
set_immutable_6: {
|
||||||
|
options = {
|
||||||
|
collapse_vars: true,
|
||||||
|
conditionals: true,
|
||||||
|
evaluate: true,
|
||||||
|
pure_getters: "strict",
|
||||||
|
reduce_funcs: true,
|
||||||
|
reduce_vars: true,
|
||||||
|
side_effects: true,
|
||||||
|
toplevel: true,
|
||||||
|
unused: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
var a = 1;
|
||||||
|
a.foo += "";
|
||||||
|
if (a.foo) console.log("FAIL");
|
||||||
|
else console.log("PASS");
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
1..foo ? console.log("FAIL") : console.log("PASS");
|
||||||
|
}
|
||||||
|
expect_stdout: true
|
||||||
|
}
|
||||||
|
|
||||||
set_mutable_1: {
|
set_mutable_1: {
|
||||||
options = {
|
options = {
|
||||||
collapse_vars: true,
|
collapse_vars: true,
|
||||||
@@ -375,7 +426,7 @@ set_mutable_1: {
|
|||||||
|
|
||||||
set_mutable_2: {
|
set_mutable_2: {
|
||||||
options = {
|
options = {
|
||||||
cascade: true,
|
collapse_vars: true,
|
||||||
conditionals: true,
|
conditionals: true,
|
||||||
pure_getters: "strict",
|
pure_getters: "strict",
|
||||||
reduce_funcs: true,
|
reduce_funcs: true,
|
||||||
@@ -398,85 +449,9 @@ 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: {
|
issue_2313_1: {
|
||||||
options = {
|
options = {
|
||||||
cascade: true,
|
collapse_vars: true,
|
||||||
conditionals: true,
|
conditionals: true,
|
||||||
pure_getters: "strict",
|
pure_getters: "strict",
|
||||||
sequences: true,
|
sequences: true,
|
||||||
@@ -522,7 +497,7 @@ issue_2313_1: {
|
|||||||
|
|
||||||
issue_2313_2: {
|
issue_2313_2: {
|
||||||
options = {
|
options = {
|
||||||
cascade: true,
|
collapse_vars: true,
|
||||||
conditionals: true,
|
conditionals: true,
|
||||||
pure_getters: true,
|
pure_getters: true,
|
||||||
sequences: true,
|
sequences: true,
|
||||||
@@ -688,50 +663,61 @@ issue_2313_6: {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
issue_2313_7: {
|
issue_2678: {
|
||||||
options = {
|
options = {
|
||||||
collapse_vars: true,
|
pure_getters: "strict",
|
||||||
conditionals: true,
|
side_effects: true,
|
||||||
pure_getters: true,
|
|
||||||
}
|
}
|
||||||
input: {
|
input: {
|
||||||
var a = 0, b = 0;
|
var a = 1, c = "FAIL";
|
||||||
class foo {
|
(function f() {
|
||||||
get c() {
|
(a-- && f()).p;
|
||||||
a++;
|
return {
|
||||||
return 42;
|
get p() {
|
||||||
}
|
c = "PASS";
|
||||||
set c(c) {
|
}
|
||||||
b++;
|
};
|
||||||
}
|
})();
|
||||||
}
|
console.log(c);
|
||||||
class bar extends foo {
|
|
||||||
d() {
|
|
||||||
super.c++;
|
|
||||||
if (super.c) console.log(a, b);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
new bar().d();
|
|
||||||
}
|
}
|
||||||
expect: {
|
expect: {
|
||||||
var a = 0, b = 0;
|
var a = 1, c = "FAIL";
|
||||||
class foo {
|
(function f() {
|
||||||
get c() {
|
(a-- && f()).p;
|
||||||
a++;
|
return {
|
||||||
return 42;
|
get p() {
|
||||||
}
|
c = "PASS";
|
||||||
set c(c) {
|
}
|
||||||
b++;
|
};
|
||||||
}
|
})();
|
||||||
}
|
console.log(c);
|
||||||
class bar extends foo {
|
|
||||||
d() {
|
|
||||||
super.c++;
|
|
||||||
super.c && console.log(a, b);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
new bar().d();
|
|
||||||
}
|
}
|
||||||
expect_stdout: "2 1"
|
expect_stdout: "PASS"
|
||||||
node_version: ">=6"
|
}
|
||||||
|
|
||||||
|
issue_2838: {
|
||||||
|
options = {
|
||||||
|
pure_getters: true,
|
||||||
|
side_effects: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
function f(a, b) {
|
||||||
|
(a || b).c = "PASS";
|
||||||
|
(function() {
|
||||||
|
return f(a, b);
|
||||||
|
}).prototype.foo = "bar";
|
||||||
|
}
|
||||||
|
var o = {};
|
||||||
|
f(null, o);
|
||||||
|
console.log(o.c);
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
function f(a, b) {
|
||||||
|
(a || b).c = "PASS";
|
||||||
|
}
|
||||||
|
var o = {};
|
||||||
|
f(null, o);
|
||||||
|
console.log(o.c);
|
||||||
|
}
|
||||||
|
expect_stdout: "PASS"
|
||||||
}
|
}
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@@ -17,7 +17,6 @@ return_undefined: {
|
|||||||
keep_fnames : false,
|
keep_fnames : false,
|
||||||
hoist_vars : true,
|
hoist_vars : true,
|
||||||
join_vars : true,
|
join_vars : true,
|
||||||
cascade : true,
|
|
||||||
negate_iife : true
|
negate_iife : true
|
||||||
};
|
};
|
||||||
input: {
|
input: {
|
||||||
@@ -122,3 +121,25 @@ return_undefined: {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return_void: {
|
||||||
|
options = {
|
||||||
|
if_return: true,
|
||||||
|
inline: true,
|
||||||
|
reduce_vars: true,
|
||||||
|
unused: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
function f() {
|
||||||
|
function g() {
|
||||||
|
h();
|
||||||
|
}
|
||||||
|
return g();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
function f() {
|
||||||
|
h();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -288,7 +288,7 @@ unsafe_undefined: {
|
|||||||
if_return: true,
|
if_return: true,
|
||||||
sequences: true,
|
sequences: true,
|
||||||
side_effects: true,
|
side_effects: true,
|
||||||
unsafe: true,
|
unsafe_undefined: true,
|
||||||
}
|
}
|
||||||
input: {
|
input: {
|
||||||
function f(undefined) {
|
function f(undefined) {
|
||||||
@@ -317,7 +317,7 @@ unsafe_undefined: {
|
|||||||
|
|
||||||
issue_1685: {
|
issue_1685: {
|
||||||
options = {
|
options = {
|
||||||
cascade: true,
|
collapse_vars: true,
|
||||||
side_effects: true,
|
side_effects: true,
|
||||||
}
|
}
|
||||||
input: {
|
input: {
|
||||||
@@ -341,7 +341,7 @@ issue_1685: {
|
|||||||
|
|
||||||
func_def_1: {
|
func_def_1: {
|
||||||
options = {
|
options = {
|
||||||
cascade: true,
|
collapse_vars: true,
|
||||||
side_effects: true,
|
side_effects: true,
|
||||||
}
|
}
|
||||||
input: {
|
input: {
|
||||||
@@ -361,7 +361,7 @@ func_def_1: {
|
|||||||
|
|
||||||
func_def_2: {
|
func_def_2: {
|
||||||
options = {
|
options = {
|
||||||
cascade: true,
|
collapse_vars: true,
|
||||||
side_effects: true,
|
side_effects: true,
|
||||||
}
|
}
|
||||||
input: {
|
input: {
|
||||||
@@ -379,7 +379,7 @@ func_def_2: {
|
|||||||
|
|
||||||
func_def_3: {
|
func_def_3: {
|
||||||
options = {
|
options = {
|
||||||
cascade: true,
|
collapse_vars: true,
|
||||||
side_effects: true,
|
side_effects: true,
|
||||||
}
|
}
|
||||||
input: {
|
input: {
|
||||||
@@ -401,7 +401,7 @@ func_def_3: {
|
|||||||
|
|
||||||
func_def_4: {
|
func_def_4: {
|
||||||
options = {
|
options = {
|
||||||
cascade: true,
|
collapse_vars: true,
|
||||||
side_effects: true,
|
side_effects: true,
|
||||||
}
|
}
|
||||||
input: {
|
input: {
|
||||||
@@ -427,7 +427,7 @@ func_def_4: {
|
|||||||
|
|
||||||
func_def_5: {
|
func_def_5: {
|
||||||
options = {
|
options = {
|
||||||
cascade: true,
|
collapse_vars: true,
|
||||||
side_effects: true,
|
side_effects: true,
|
||||||
}
|
}
|
||||||
input: {
|
input: {
|
||||||
@@ -634,7 +634,7 @@ side_effects: {
|
|||||||
|
|
||||||
side_effects_cascade_1: {
|
side_effects_cascade_1: {
|
||||||
options = {
|
options = {
|
||||||
cascade: true,
|
collapse_vars: true,
|
||||||
conditionals: true,
|
conditionals: true,
|
||||||
sequences: true,
|
sequences: true,
|
||||||
side_effects: true,
|
side_effects: true,
|
||||||
@@ -655,7 +655,7 @@ side_effects_cascade_1: {
|
|||||||
|
|
||||||
side_effects_cascade_2: {
|
side_effects_cascade_2: {
|
||||||
options = {
|
options = {
|
||||||
cascade: true,
|
collapse_vars: true,
|
||||||
side_effects: true,
|
side_effects: true,
|
||||||
}
|
}
|
||||||
input: {
|
input: {
|
||||||
@@ -677,7 +677,7 @@ side_effects_cascade_2: {
|
|||||||
|
|
||||||
side_effects_cascade_3: {
|
side_effects_cascade_3: {
|
||||||
options = {
|
options = {
|
||||||
cascade: true,
|
collapse_vars: true,
|
||||||
conditionals: true,
|
conditionals: true,
|
||||||
side_effects: true,
|
side_effects: true,
|
||||||
}
|
}
|
||||||
@@ -692,14 +692,14 @@ side_effects_cascade_3: {
|
|||||||
expect: {
|
expect: {
|
||||||
function f(a, b) {
|
function f(a, b) {
|
||||||
!(b += a) && ((b = a) || (b -= a, b ^= a)),
|
!(b += a) && ((b = a) || (b -= a, b ^= a)),
|
||||||
--a;
|
a--;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
issue_27: {
|
issue_27: {
|
||||||
options = {
|
options = {
|
||||||
cascade: true,
|
collapse_vars: true,
|
||||||
passes: 2,
|
passes: 2,
|
||||||
sequences: true,
|
sequences: true,
|
||||||
side_effects: true,
|
side_effects: true,
|
||||||
@@ -719,34 +719,10 @@ issue_27: {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
reassign_const: {
|
|
||||||
options = {
|
|
||||||
cascade: true,
|
|
||||||
sequences: true,
|
|
||||||
side_effects: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
function f() {
|
|
||||||
const a = 1;
|
|
||||||
a++;
|
|
||||||
return a;
|
|
||||||
}
|
|
||||||
console.log(f());
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
function f() {
|
|
||||||
const a = 1;
|
|
||||||
return a++, a;
|
|
||||||
}
|
|
||||||
console.log(f());
|
|
||||||
}
|
|
||||||
expect_stdout: true
|
|
||||||
}
|
|
||||||
|
|
||||||
issue_2062: {
|
issue_2062: {
|
||||||
options = {
|
options = {
|
||||||
booleans: true,
|
booleans: true,
|
||||||
cascade: true,
|
collapse_vars: true,
|
||||||
conditionals: true,
|
conditionals: true,
|
||||||
side_effects: true,
|
side_effects: true,
|
||||||
}
|
}
|
||||||
@@ -765,7 +741,7 @@ issue_2062: {
|
|||||||
|
|
||||||
issue_2313: {
|
issue_2313: {
|
||||||
options = {
|
options = {
|
||||||
cascade: true,
|
collapse_vars: true,
|
||||||
sequences: true,
|
sequences: true,
|
||||||
side_effects: true,
|
side_effects: true,
|
||||||
}
|
}
|
||||||
@@ -803,3 +779,101 @@ issue_2313: {
|
|||||||
}
|
}
|
||||||
expect_stdout: "2 1"
|
expect_stdout: "2 1"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
cascade_assignment_in_return: {
|
||||||
|
options = {
|
||||||
|
collapse_vars: true,
|
||||||
|
unused: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
function f(a, b) {
|
||||||
|
return a = x(), b(a);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
function f(a, b) {
|
||||||
|
return b(x());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
hoist_defun: {
|
||||||
|
options = {
|
||||||
|
join_vars: true,
|
||||||
|
sequences: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
x();
|
||||||
|
function f() {}
|
||||||
|
y();
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
function f() {}
|
||||||
|
x(), y();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
hoist_decl: {
|
||||||
|
options = {
|
||||||
|
join_vars: true,
|
||||||
|
sequences: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
var a;
|
||||||
|
w();
|
||||||
|
var b = x();
|
||||||
|
y();
|
||||||
|
for (var c; 0;) z();
|
||||||
|
var d;
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
var a;
|
||||||
|
w();
|
||||||
|
var b = x(), c, d;
|
||||||
|
for (y(); 0;) z();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for_init_var: {
|
||||||
|
options = {
|
||||||
|
join_vars: true,
|
||||||
|
unused: false,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
var a = "PASS";
|
||||||
|
(function() {
|
||||||
|
var b = 42;
|
||||||
|
for (var c = 5; c > 0;) c--;
|
||||||
|
a = "FAIL";
|
||||||
|
var a;
|
||||||
|
})();
|
||||||
|
console.log(a);
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
var a = "PASS";
|
||||||
|
(function() {
|
||||||
|
for (var b = 42, c = 5, a; c > 0;) c--;
|
||||||
|
a = "FAIL";
|
||||||
|
})();
|
||||||
|
console.log(a);
|
||||||
|
}
|
||||||
|
expect_stdout: "PASS"
|
||||||
|
}
|
||||||
|
|
||||||
|
forin: {
|
||||||
|
options = {
|
||||||
|
sequences: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
var o = [];
|
||||||
|
o.push("PASS");
|
||||||
|
for (var a in o)
|
||||||
|
console.log(o[a]);
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
var o = [];
|
||||||
|
for (var a in o.push("PASS"), o)
|
||||||
|
console.log(o[a]);
|
||||||
|
}
|
||||||
|
expect_stdout: "PASS"
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,9 +0,0 @@
|
|||||||
|
|
||||||
super_can_be_parsed: {
|
|
||||||
input: {
|
|
||||||
super(1,2);
|
|
||||||
super.meth();
|
|
||||||
}
|
|
||||||
expect_exact: "super(1,2);super.meth();"
|
|
||||||
}
|
|
||||||
|
|
||||||
@@ -1,508 +0,0 @@
|
|||||||
template_strings: {
|
|
||||||
beautify = {
|
|
||||||
quote_style: 3
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
``;
|
|
||||||
`xx\`x`;
|
|
||||||
`${ foo + 2 }`;
|
|
||||||
` foo ${ bar + `baz ${ qux }` }`;
|
|
||||||
}
|
|
||||||
expect_exact: "``;`xx\\`x`;`${foo+2}`;` foo ${bar+`baz ${qux}`}`;";
|
|
||||||
}
|
|
||||||
|
|
||||||
template_string_prefixes: {
|
|
||||||
beautify = {
|
|
||||||
quote_style: 3
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
String.raw`foo`;
|
|
||||||
foo `bar`;
|
|
||||||
}
|
|
||||||
expect_exact: "String.raw`foo`;foo`bar`;";
|
|
||||||
}
|
|
||||||
|
|
||||||
template_strings_ascii_only: {
|
|
||||||
beautify = {
|
|
||||||
ascii_only: true,
|
|
||||||
quote_style: 3
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
var foo = `foo
|
|
||||||
bar
|
|
||||||
ↂωↂ`;
|
|
||||||
var bar = `\``;
|
|
||||||
}
|
|
||||||
expect_exact: "var foo=`foo\\n bar\\n \\u2182\\u03c9\\u2182`;var bar=`\\``;"
|
|
||||||
}
|
|
||||||
|
|
||||||
template_strings_without_ascii_only: {
|
|
||||||
beautify = {
|
|
||||||
quote_style: 3
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
var foo = `foo
|
|
||||||
bar
|
|
||||||
ↂωↂ`
|
|
||||||
}
|
|
||||||
expect_exact: "var foo=`foo\\n bar\\n ↂωↂ`;"
|
|
||||||
}
|
|
||||||
|
|
||||||
template_string_with_constant_expression: {
|
|
||||||
options = {
|
|
||||||
evaluate: true
|
|
||||||
}
|
|
||||||
beautify = {
|
|
||||||
quote_style: 3
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
var foo = `${4 + 4} equals 4 + 4`;
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
var foo = "8 equals 4 + 4";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
template_string_with_predefined_constants: {
|
|
||||||
options = {
|
|
||||||
evaluate: true
|
|
||||||
}
|
|
||||||
beautify = {
|
|
||||||
quote_style: 3
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
var foo = `This is ${undefined}`;
|
|
||||||
var bar = `This is ${NaN}`;
|
|
||||||
var baz = `This is ${null}`;
|
|
||||||
var foofoo = `This is ${Infinity}`;
|
|
||||||
var foobar = "This is ${1/0}";
|
|
||||||
var foobaz = 'This is ${1/0}';
|
|
||||||
var barfoo = "This is ${NaN}";
|
|
||||||
var bazfoo = "This is ${null}";
|
|
||||||
var bazbaz = `This is ${1/0}`;
|
|
||||||
var barbar = `This is ${0/0}`;
|
|
||||||
var barbar = "This is ${0/0}";
|
|
||||||
var barber = 'This is ${0/0}';
|
|
||||||
|
|
||||||
var a = `${4**11}`; // 8 in template vs 7 chars - 4194304
|
|
||||||
var b = `${4**12}`; // 8 in template vs 8 chars - 16777216
|
|
||||||
var c = `${4**14}`; // 8 in template vs 9 chars - 268435456
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
var foo = "This is undefined";
|
|
||||||
var bar = "This is NaN";
|
|
||||||
var baz = "This is null";
|
|
||||||
var foofoo = `This is ${1/0}`;
|
|
||||||
var foobar = "This is ${1/0}";
|
|
||||||
var foobaz = 'This is ${1/0}';
|
|
||||||
var barfoo = "This is ${NaN}";
|
|
||||||
var bazfoo = "This is ${null}";
|
|
||||||
var bazbaz = `This is ${1/0}`;
|
|
||||||
var barbar = "This is NaN";
|
|
||||||
var barbar = "This is ${0/0}";
|
|
||||||
var barber = 'This is ${0/0}';
|
|
||||||
|
|
||||||
var a = "4194304";
|
|
||||||
var b = "16777216"; // Potential for further concatentation
|
|
||||||
var c = `${4**14}`; // Not worth converting
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
template_string_evaluate_with_many_segments: {
|
|
||||||
options = {
|
|
||||||
evaluate: true
|
|
||||||
}
|
|
||||||
beautify = {
|
|
||||||
quote_style: 3
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
var foo = `Hello ${guest()}, welcome to ${location()}${"."}`;
|
|
||||||
var bar = `${1}${2}${3}${4}${5}${6}${7}${8}${9}${0}`;
|
|
||||||
var baz = `${foobar()}${foobar()}${foobar()}${foobar()}`;
|
|
||||||
var buzz = `${1}${foobar()}${2}${foobar()}${3}${foobar()}`;
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
var foo = `Hello ${guest()}, welcome to ${location()}.`;
|
|
||||||
var bar = "1234567890";
|
|
||||||
var baz = `${foobar()}${foobar()}${foobar()}${foobar()}`;
|
|
||||||
var buzz = `1${foobar()}2${foobar()}3${foobar()}`;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
template_string_with_many_segments: {
|
|
||||||
beautify = {
|
|
||||||
quote_style: 3
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
var foo = `Hello ${guest()}, welcome to ${location()}${"."}`;
|
|
||||||
var bar = `${1}${2}${3}${4}${5}${6}${7}${8}${9}${0}`;
|
|
||||||
var baz = `${foobar()}${foobar()}${foobar()}${foobar()}`;
|
|
||||||
var buzz = `${1}${foobar()}${2}${foobar()}${3}${foobar()}`;
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
var foo = `Hello ${guest()}, welcome to ${location()}${"."}`;
|
|
||||||
var bar = `${1}${2}${3}${4}${5}${6}${7}${8}${9}${0}`;
|
|
||||||
var baz = `${foobar()}${foobar()}${foobar()}${foobar()}`;
|
|
||||||
var buzz = `${1}${foobar()}${2}${foobar()}${3}${foobar()}`;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
template_string_to_normal_string: {
|
|
||||||
options = {
|
|
||||||
evaluate: true
|
|
||||||
}
|
|
||||||
beautify = {
|
|
||||||
quote_style: 0
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
var foo = `This is ${undefined}`;
|
|
||||||
var bar = "Decimals " + `${1}${2}${3}${4}${5}${6}${7}${8}${9}${0}`;
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
var foo = "This is undefined";
|
|
||||||
var bar = "Decimals 1234567890";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
template_concattenating_string: {
|
|
||||||
options = {
|
|
||||||
evaluate: true
|
|
||||||
}
|
|
||||||
beautify = {
|
|
||||||
quote_style: 3 // Yes, keep quotes
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
var foo = "Have a nice " + `day. ${`day. ` + `day.`}`;
|
|
||||||
var bar = "Have a nice " + `${day()}`;
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
var foo = "Have a nice day. day. day.";
|
|
||||||
var bar = "Have a nice " + `${day()}`;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
evaluate_nested_templates: {
|
|
||||||
options = {
|
|
||||||
evaluate: true
|
|
||||||
}
|
|
||||||
beautify = {
|
|
||||||
quote_style: 0
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
var baz = `${`${`${`foo`}`}`}`;
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
var baz = "foo";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
enforce_double_quotes: {
|
|
||||||
beautify = {
|
|
||||||
quote_style: 1
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
var foo = `Hello world`;
|
|
||||||
var bar = `Hello ${'world'}`;
|
|
||||||
var baz = `Hello ${world()}`;
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
var foo = `Hello world`;
|
|
||||||
var bar = `Hello ${"world"}`;
|
|
||||||
var baz = `Hello ${world()}`;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
enforce_single_quotes: {
|
|
||||||
beautify = {
|
|
||||||
quote_style: 2
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
var foo = `Hello world`;
|
|
||||||
var bar = `Hello ${"world"}`;
|
|
||||||
var baz = `Hello ${world()}`;
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
var foo = `Hello world`;
|
|
||||||
var bar = `Hello ${'world'}`;
|
|
||||||
var baz = `Hello ${world()}`;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
enforce_double_quotes_and_evaluate: {
|
|
||||||
beautify = {
|
|
||||||
quote_style: 1
|
|
||||||
}
|
|
||||||
options = {
|
|
||||||
evaluate: true
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
var foo = `Hello world`;
|
|
||||||
var bar = `Hello ${'world'}`;
|
|
||||||
var baz = `Hello ${world()}`;
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
var foo = "Hello world";
|
|
||||||
var bar = "Hello world";
|
|
||||||
var baz = `Hello ${world()}`;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
enforce_single_quotes_and_evaluate: {
|
|
||||||
beautify = {
|
|
||||||
quote_style: 2
|
|
||||||
}
|
|
||||||
options = {
|
|
||||||
evaluate: true
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
var foo = `Hello world`;
|
|
||||||
var bar = `Hello ${"world"}`;
|
|
||||||
var baz = `Hello ${world()}`;
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
var foo = "Hello world";
|
|
||||||
var bar = "Hello world";
|
|
||||||
var baz = `Hello ${world()}`;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
respect_inline_script: {
|
|
||||||
beautify = {
|
|
||||||
inline_script: true,
|
|
||||||
quote_style: 3
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
var foo = `</script>${content}`;
|
|
||||||
var bar = `<!--`;
|
|
||||||
var baz = `-->`;
|
|
||||||
}
|
|
||||||
expect_exact: "var foo=`<\\/script>${content}`;var bar=`\\x3c!--`;var baz=`--\\x3e`;";
|
|
||||||
}
|
|
||||||
|
|
||||||
do_not_optimize_tagged_template_1: {
|
|
||||||
beautify = {
|
|
||||||
quote_style: 0
|
|
||||||
}
|
|
||||||
options = {
|
|
||||||
evaluate: true
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
var foo = tag`Shall not be optimized. ${"But " + "this " + "is " + "fine."}`;
|
|
||||||
var bar = tag`Don't even mind changing my quotes!`;
|
|
||||||
}
|
|
||||||
expect_exact:
|
|
||||||
'var foo=tag`Shall not be optimized. ${"But this is fine."}`;var bar=tag`Don\'t even mind changing my quotes!`;';
|
|
||||||
}
|
|
||||||
|
|
||||||
do_not_optimize_tagged_template_2: {
|
|
||||||
options = {
|
|
||||||
evaluate: true
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
var foo = tag`test` + " something out";
|
|
||||||
}
|
|
||||||
expect_exact: 'var foo=tag`test`+" something out";';
|
|
||||||
}
|
|
||||||
|
|
||||||
keep_raw_content_in_tagged_template: {
|
|
||||||
options = {
|
|
||||||
evaluate: true
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
var foo = tag`\u0020\u{20}\u{00020}\x20\40\040 `;
|
|
||||||
}
|
|
||||||
expect_exact: "var foo=tag`\\u0020\\u{20}\\u{00020}\\x20\\40\\040 `;";
|
|
||||||
}
|
|
||||||
|
|
||||||
allow_chained_templates: {
|
|
||||||
input: {
|
|
||||||
var foo = tag`a``b``c``d`;
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
var foo = tag`a``b``c``d`;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
check_escaped_chars: {
|
|
||||||
input: {
|
|
||||||
var foo = `\u0020\u{20}\u{00020}\x20\40\040 `;
|
|
||||||
}
|
|
||||||
expect_exact: "var foo=` `;";
|
|
||||||
}
|
|
||||||
|
|
||||||
escape_dollar_curly: {
|
|
||||||
options = {
|
|
||||||
evaluate: true
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
console.log(`\$\{ beep \}`)
|
|
||||||
console.log(`${1-0}\${2-0}$\{3-0}${4-0}`)
|
|
||||||
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: {
|
|
||||||
options = {
|
|
||||||
dead_code: true
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
function foo(e) {
|
|
||||||
return `
|
|
||||||
this is a template string!`;
|
|
||||||
};
|
|
||||||
}
|
|
||||||
expect_exact: "function foo(e){return`\\nthis is a template string!`}"
|
|
||||||
}
|
|
||||||
|
|
||||||
template_with_newline: {
|
|
||||||
options = {
|
|
||||||
dead_code: true
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
function foo(e) {
|
|
||||||
return `yep,
|
|
||||||
this is a template string!`;
|
|
||||||
};
|
|
||||||
}
|
|
||||||
expect_exact: "function foo(e){return`yep,\\nthis is a template string!`}"
|
|
||||||
}
|
|
||||||
|
|
||||||
template_ending_with_newline: {
|
|
||||||
options = {
|
|
||||||
dead_code: true
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
function foo(e) {
|
|
||||||
return `this is a template string!
|
|
||||||
`;
|
|
||||||
};
|
|
||||||
}
|
|
||||||
expect_exact: "function foo(e){return`this is a template string!\\n`}"
|
|
||||||
}
|
|
||||||
|
|
||||||
issue_1856: {
|
|
||||||
beautify = {
|
|
||||||
ascii_only: false,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
console.log(`\\n\\r\\u2028\\u2029\n\r\u2028\u2029`);
|
|
||||||
}
|
|
||||||
expect_exact: "console.log(`\\\\n\\\\r\\\\u2028\\\\u2029\\n\\r\\u2028\\u2029`);"
|
|
||||||
}
|
|
||||||
|
|
||||||
issue_1856_ascii_only: {
|
|
||||||
beautify = {
|
|
||||||
ascii_only: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
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"
|
|
||||||
}
|
|
||||||
@@ -1,12 +0,0 @@
|
|||||||
catch_destructuring_with_sequence: {
|
|
||||||
beautify = {
|
|
||||||
ecma: 6
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
try {
|
|
||||||
throw {};
|
|
||||||
} catch ({xCover = (0, function() {})} ) {
|
|
||||||
}
|
|
||||||
}
|
|
||||||
expect_exact: "try{throw{}}catch({xCover=(0,function(){})}){}"
|
|
||||||
}
|
|
||||||
@@ -100,7 +100,7 @@ typeof_defun_1: {
|
|||||||
g = 42;
|
g = 42;
|
||||||
console.log("YES");
|
console.log("YES");
|
||||||
"function" == typeof g && g();
|
"function" == typeof g && g();
|
||||||
h();
|
"function" == typeof h && h();
|
||||||
}
|
}
|
||||||
expect_stdout: [
|
expect_stdout: [
|
||||||
"YES",
|
"YES",
|
||||||
@@ -138,3 +138,166 @@ typeof_defun_2: {
|
|||||||
"2",
|
"2",
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
duplicate_defun_arg_name: {
|
||||||
|
options = {
|
||||||
|
evaluate: true,
|
||||||
|
reduce_vars: true,
|
||||||
|
typeofs: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
function long_name(long_name) {
|
||||||
|
return typeof long_name;
|
||||||
|
}
|
||||||
|
console.log(typeof long_name, long_name());
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
function long_name(long_name) {
|
||||||
|
return typeof long_name;
|
||||||
|
}
|
||||||
|
console.log(typeof long_name, long_name());
|
||||||
|
}
|
||||||
|
expect_stdout: "function undefined"
|
||||||
|
}
|
||||||
|
|
||||||
|
duplicate_lambda_arg_name: {
|
||||||
|
options = {
|
||||||
|
evaluate: true,
|
||||||
|
reduce_vars: true,
|
||||||
|
typeofs: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
console.log(function long_name(long_name) {
|
||||||
|
return typeof long_name;
|
||||||
|
}());
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
console.log(function long_name(long_name) {
|
||||||
|
return typeof long_name;
|
||||||
|
}());
|
||||||
|
}
|
||||||
|
expect_stdout: "undefined"
|
||||||
|
}
|
||||||
|
|
||||||
|
issue_2728_1: {
|
||||||
|
options = {
|
||||||
|
evaluate: true,
|
||||||
|
reduce_vars: true,
|
||||||
|
typeofs: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
(function arguments() {
|
||||||
|
console.log(typeof arguments);
|
||||||
|
})();
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
(function arguments() {
|
||||||
|
console.log(typeof arguments);
|
||||||
|
})();
|
||||||
|
}
|
||||||
|
expect_stdout: "object"
|
||||||
|
}
|
||||||
|
|
||||||
|
issue_2728_2: {
|
||||||
|
options = {
|
||||||
|
evaluate: true,
|
||||||
|
reduce_vars: true,
|
||||||
|
typeofs: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
function arguments() {
|
||||||
|
return typeof arguments;
|
||||||
|
}
|
||||||
|
console.log(typeof arguments, arguments());
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
function arguments() {
|
||||||
|
return typeof arguments;
|
||||||
|
}
|
||||||
|
console.log(typeof arguments, arguments());
|
||||||
|
}
|
||||||
|
expect_stdout: "function object"
|
||||||
|
}
|
||||||
|
|
||||||
|
issue_2728_3: {
|
||||||
|
options = {
|
||||||
|
evaluate: true,
|
||||||
|
reduce_vars: true,
|
||||||
|
typeofs: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
(function() {
|
||||||
|
function arguments() {
|
||||||
|
}
|
||||||
|
console.log(typeof arguments);
|
||||||
|
})();
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
(function() {
|
||||||
|
function arguments() {
|
||||||
|
}
|
||||||
|
console.log("function");
|
||||||
|
})();
|
||||||
|
}
|
||||||
|
expect_stdout: "function"
|
||||||
|
}
|
||||||
|
|
||||||
|
issue_2728_4: {
|
||||||
|
options = {
|
||||||
|
evaluate: true,
|
||||||
|
reduce_vars: true,
|
||||||
|
toplevel: true,
|
||||||
|
typeofs: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
function arguments() {
|
||||||
|
}
|
||||||
|
console.log(typeof arguments);
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
function arguments() {
|
||||||
|
}
|
||||||
|
console.log("function");
|
||||||
|
}
|
||||||
|
expect_stdout: "function"
|
||||||
|
}
|
||||||
|
|
||||||
|
issue_2728_5: {
|
||||||
|
options = {
|
||||||
|
evaluate: true,
|
||||||
|
reduce_vars: true,
|
||||||
|
typeofs: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
(function arguments(arguments) {
|
||||||
|
console.log(typeof arguments);
|
||||||
|
})();
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
(function arguments(arguments) {
|
||||||
|
console.log(typeof arguments);
|
||||||
|
})();
|
||||||
|
}
|
||||||
|
expect_stdout: "undefined"
|
||||||
|
}
|
||||||
|
|
||||||
|
issue_2728_6: {
|
||||||
|
options = {
|
||||||
|
evaluate: true,
|
||||||
|
reduce_vars: true,
|
||||||
|
typeofs: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
function arguments(arguments) {
|
||||||
|
return typeof arguments;
|
||||||
|
}
|
||||||
|
console.log(typeof arguments, arguments());
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
function arguments(arguments) {
|
||||||
|
return typeof arguments;
|
||||||
|
}
|
||||||
|
console.log(typeof arguments, arguments());
|
||||||
|
}
|
||||||
|
expect_stdout: "function undefined"
|
||||||
|
}
|
||||||
|
|||||||
@@ -16,70 +16,6 @@ unicode_parse_variables: {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
unicode_escaped_identifier: {
|
|
||||||
beautify = {ecma: 6}
|
|
||||||
input: {
|
|
||||||
var \u{61} = "foo";
|
|
||||||
var \u{10000} = "bar";
|
|
||||||
}
|
|
||||||
expect_exact: 'var a="foo";var \u{10000}="bar";';
|
|
||||||
}
|
|
||||||
|
|
||||||
unicode_identifier_ascii_only: {
|
|
||||||
beautify = {ascii_only: true, ecma: 6}
|
|
||||||
input: {
|
|
||||||
var \u{0061} = "hi";
|
|
||||||
var bar = "h\u{0065}llo";
|
|
||||||
var \u{10000} = "testing \u{101111}";
|
|
||||||
}
|
|
||||||
expect_exact: 'var a="hi";var bar="hello";var \\u{10000}="testing \\u{101111}";'
|
|
||||||
}
|
|
||||||
|
|
||||||
unicode_string_literals: {
|
|
||||||
beautify = {ascii_only: true, ecma: 6}
|
|
||||||
input: {
|
|
||||||
var a = "6 length unicode character: \u{101111}";
|
|
||||||
}
|
|
||||||
expect_exact: 'var a="6 length unicode character: \\u{101111}";'
|
|
||||||
}
|
|
||||||
|
|
||||||
check_escape_style: {
|
|
||||||
beautify = {ascii_only: true, ecma: 6}
|
|
||||||
input: {
|
|
||||||
var a = "\x01";
|
|
||||||
var \ua0081 = "\x10"; // \u0081 only in ID_Continue
|
|
||||||
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}";'
|
|
||||||
}
|
|
||||||
|
|
||||||
ID_continue_with_surrogate_pair: {
|
|
||||||
beautify = {ascii_only: true, ecma: 6}
|
|
||||||
input: {
|
|
||||||
var \u{2f800}\u{2f800}\u{2f800}\u{2f800} = "\u{100000}\u{100000}\u{100000}\u{100000}\u{100000}";
|
|
||||||
}
|
|
||||||
expect_exact: 'var \\u{2f800}\\u{2f800}\\u{2f800}\\u{2f800}="\\u{100000}\\u{100000}\\u{100000}\\u{100000}\\u{100000}";'
|
|
||||||
}
|
|
||||||
|
|
||||||
escape_non_escaped_identifier: {
|
|
||||||
beautify = {ascii_only: true, ecma: 6}
|
|
||||||
input: {
|
|
||||||
var µþ = "µþ";
|
|
||||||
}
|
|
||||||
expect_exact: 'var \\u00b5\\u00fe="\\xb5\\xfe";'
|
|
||||||
}
|
|
||||||
|
|
||||||
non_escape_2_non_escape: {
|
|
||||||
beautify = {ascii_only: false, ecma: 6}
|
|
||||||
input: {
|
|
||||||
var µþ = "µþ";
|
|
||||||
}
|
|
||||||
expect_exact: 'var µþ="µþ";'
|
|
||||||
}
|
|
||||||
|
|
||||||
issue_2242_1: {
|
issue_2242_1: {
|
||||||
beautify = {
|
beautify = {
|
||||||
ascii_only: false,
|
ascii_only: false,
|
||||||
@@ -119,3 +55,10 @@ issue_2242_4: {
|
|||||||
}
|
}
|
||||||
expect_exact: 'console.log("\ud83d\ude00","\\ud83d@\\ude00");'
|
expect_exact: 'console.log("\ud83d\ude00","\\ud83d@\\ude00");'
|
||||||
}
|
}
|
||||||
|
|
||||||
|
issue_2569: {
|
||||||
|
input: {
|
||||||
|
new RegExp("[\udc42-\udcaa\udd74-\udd96\ude45-\ude4f\udea3-\udecc]");
|
||||||
|
}
|
||||||
|
expect_exact: 'new RegExp("[\\udc42-\\udcaa\\udd74-\\udd96\\ude45-\\ude4f\\udea3-\\udecc]");'
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,201 +0,0 @@
|
|||||||
generators: {
|
|
||||||
input: {
|
|
||||||
function* fn() {};
|
|
||||||
}
|
|
||||||
expect_exact: "function*fn(){}"
|
|
||||||
}
|
|
||||||
|
|
||||||
generators_yield: {
|
|
||||||
input: {
|
|
||||||
function* fn() {
|
|
||||||
yield remote();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
expect_exact: "function*fn(){yield remote()}"
|
|
||||||
}
|
|
||||||
|
|
||||||
generators_yield_assign: {
|
|
||||||
input: {
|
|
||||||
function* fn() {
|
|
||||||
var x = {};
|
|
||||||
x.prop = yield 5;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
expect_exact: "function*fn(){var x={};x.prop=yield 5}"
|
|
||||||
}
|
|
||||||
|
|
||||||
generator_yield_undefined: {
|
|
||||||
input: {
|
|
||||||
function* fn() {
|
|
||||||
yield;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
expect_exact: "function*fn(){yield}"
|
|
||||||
}
|
|
||||||
|
|
||||||
yield_optimize_expression: {
|
|
||||||
options = {
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
function* f1() { yield; }
|
|
||||||
function* f2() { yield undefined; }
|
|
||||||
function* f3() { yield null; }
|
|
||||||
function* f4() { yield* undefined; }
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
function* f1() { yield }
|
|
||||||
function* f2() { yield; }
|
|
||||||
function* f3() { yield null; }
|
|
||||||
function* f4() { yield* void 0; }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
yield_statements: {
|
|
||||||
input: {
|
|
||||||
function* fn() {
|
|
||||||
var a = (yield 1) + (yield 2);
|
|
||||||
var b = (yield 3) === (yield 4);
|
|
||||||
var c = (yield 5) << (yield 6);
|
|
||||||
var d = yield 7;
|
|
||||||
var e = (yield 8) ? yield 9 : yield 10;
|
|
||||||
var f = -(yield 11);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
expect_exact: "function*fn(){var a=(yield 1)+(yield 2);var b=(yield 3)===(yield 4);var c=(yield 5)<<(yield 6);var d=yield 7;var e=(yield 8)?yield 9:yield 10;var f=-(yield 11)}"
|
|
||||||
}
|
|
||||||
|
|
||||||
yield_as_identifier_in_function_in_generator: {
|
|
||||||
input: {
|
|
||||||
var g = function*() {
|
|
||||||
function h() {
|
|
||||||
yield = 1;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
var g = function*() {
|
|
||||||
function h() {
|
|
||||||
yield = 1;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
yield_before_punctuators: {
|
|
||||||
input: {
|
|
||||||
iter = (function*() {
|
|
||||||
assignmentResult = [ x = yield ] = value;
|
|
||||||
})();
|
|
||||||
function* g1() { (yield) }
|
|
||||||
function* g2() { [yield] }
|
|
||||||
function* g3() { return {yield} } // Added return to avoid {} drop
|
|
||||||
function* g4() { yield, yield; }
|
|
||||||
function* g5() { (yield) ? yield : yield; }
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
iter = (function*() {
|
|
||||||
assignmentResult = [ x = yield ] = value;
|
|
||||||
})();
|
|
||||||
function* g1() { (yield) }
|
|
||||||
function* g2() { [yield] }
|
|
||||||
function* g3() { return {yield} }
|
|
||||||
function* g4() { yield, yield; }
|
|
||||||
function* g5() { (yield) ? yield : yield; }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
yield_as_identifier_outside_strict_mode: {
|
|
||||||
input: {
|
|
||||||
import yield from "bar";
|
|
||||||
yield = 123;
|
|
||||||
while (true) {
|
|
||||||
yield:
|
|
||||||
for(;;) break yield;
|
|
||||||
|
|
||||||
foo();
|
|
||||||
}
|
|
||||||
while (true)
|
|
||||||
yield: for(;;) continue yield;
|
|
||||||
function yield(){}
|
|
||||||
function foo(...yield){}
|
|
||||||
try { new Error("") } catch (yield) {}
|
|
||||||
var yield = "foo";
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
import yield from "bar";
|
|
||||||
yield = 123;
|
|
||||||
while (true) {
|
|
||||||
yield:
|
|
||||||
for(;;) break yield;
|
|
||||||
|
|
||||||
foo();
|
|
||||||
}
|
|
||||||
while (true)
|
|
||||||
yield: for(;;) continue yield;
|
|
||||||
function yield(){}
|
|
||||||
function foo(...yield){}
|
|
||||||
try { new Error("") } catch (yield) {}
|
|
||||||
var yield = "foo";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
empty_generator_as_parameter_with_side_effects: {
|
|
||||||
options = {
|
|
||||||
side_effects: true
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
var GeneratorPrototype = Object.getPrototypeOf(
|
|
||||||
Object.getPrototypeOf(function*() {}())
|
|
||||||
);
|
|
||||||
evaluate(GeneratorPrototype);
|
|
||||||
}
|
|
||||||
expect_exact: "var GeneratorPrototype=Object.getPrototypeOf(Object.getPrototypeOf(function*(){}()));evaluate(GeneratorPrototype);"
|
|
||||||
}
|
|
||||||
|
|
||||||
empty_generator_as_parameter_without_side_effects: {
|
|
||||||
options = {
|
|
||||||
side_effects: false
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
var GeneratorPrototype = Object.getPrototypeOf(
|
|
||||||
Object.getPrototypeOf(function*() {}())
|
|
||||||
);
|
|
||||||
evaluate(GeneratorPrototype);
|
|
||||||
}
|
|
||||||
expect_exact: "var GeneratorPrototype=Object.getPrototypeOf(Object.getPrototypeOf(function*(){}()));evaluate(GeneratorPrototype);"
|
|
||||||
}
|
|
||||||
|
|
||||||
yield_dot: {
|
|
||||||
options = {
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
function* foo(){
|
|
||||||
yield x.foo;
|
|
||||||
(yield x).foo;
|
|
||||||
yield (yield obj.foo()).bar();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
expect_exact: "function*foo(){yield x.foo;(yield x).foo;yield(yield obj.foo()).bar()}"
|
|
||||||
}
|
|
||||||
|
|
||||||
yield_sub: {
|
|
||||||
options = {
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
function* foo(){
|
|
||||||
yield x['foo'];
|
|
||||||
(yield x)['foo'];
|
|
||||||
yield (yield obj.foo())['bar']();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
expect_exact: 'function*foo(){yield x["foo"];(yield x)["foo"];yield(yield obj.foo())["bar"]()}'
|
|
||||||
}
|
|
||||||
|
|
||||||
yield_as_ES5_property: {
|
|
||||||
input: {
|
|
||||||
"use strict";
|
|
||||||
console.log({yield: 42}.yield);
|
|
||||||
}
|
|
||||||
expect_exact: '"use strict";console.log({yield:42}.yield);'
|
|
||||||
expect_stdout: "42"
|
|
||||||
}
|
|
||||||
@@ -1,8 +0,0 @@
|
|||||||
function f() {
|
|
||||||
const a;
|
|
||||||
}
|
|
||||||
|
|
||||||
function g() {
|
|
||||||
"use strict";
|
|
||||||
const a;
|
|
||||||
}
|
|
||||||
@@ -1,3 +0,0 @@
|
|||||||
{
|
|
||||||
export var V = 1;
|
|
||||||
}
|
|
||||||
@@ -1 +0,0 @@
|
|||||||
export class{};
|
|
||||||
@@ -1 +0,0 @@
|
|||||||
export function(){};
|
|
||||||
@@ -1,3 +0,0 @@
|
|||||||
{
|
|
||||||
import A from "B";
|
|
||||||
}
|
|
||||||
@@ -1 +0,0 @@
|
|||||||
(a, ...b);
|
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
var a = bar(1+2);
|
var x = bar(1+2);
|
||||||
var b = baz(3+9);
|
var y = baz(3+9);
|
||||||
print('q' + 'u' + 'x', a, b);
|
print('q' + 'u' + 'x', x, y);
|
||||||
foo(5+6);
|
foo(5+6);
|
||||||
|
|||||||
6
test/input/rename/input.js
Normal file
6
test/input/rename/input.js
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
function f(x) {
|
||||||
|
return g(x);
|
||||||
|
function g(x) {
|
||||||
|
return x;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -5,11 +5,7 @@
|
|||||||
|
|
||||||
var site = "http://browserbench.org/JetStream";
|
var site = "http://browserbench.org/JetStream";
|
||||||
if (typeof phantom == "undefined") {
|
if (typeof phantom == "undefined") {
|
||||||
// workaround for tty output truncation upon process.exit()
|
require("../tools/exit");
|
||||||
[process.stdout, process.stderr].forEach(function(stream){
|
|
||||||
if (stream._handle && stream._handle.setBlocking)
|
|
||||||
stream._handle.setBlocking(true);
|
|
||||||
});
|
|
||||||
var args = process.argv.slice(2);
|
var args = process.argv.slice(2);
|
||||||
var debug = args.indexOf("--debug");
|
var debug = args.indexOf("--debug");
|
||||||
if (debug >= 0) {
|
if (debug >= 0) {
|
||||||
|
|||||||
@@ -1,29 +1,24 @@
|
|||||||
var Mocha = require('mocha'),
|
var fs = require("fs");
|
||||||
fs = require('fs'),
|
var Mocha = require("mocha");
|
||||||
path = require('path');
|
var path = require("path");
|
||||||
|
|
||||||
// Instantiate a Mocha instance.
|
// Instantiate a Mocha instance
|
||||||
var mocha = new Mocha({});
|
var mocha = new Mocha({
|
||||||
|
timeout: 5000
|
||||||
|
});
|
||||||
|
var testDir = __dirname + "/mocha/";
|
||||||
|
|
||||||
var testDir = __dirname + '/mocha/';
|
// Add each .js file to the Mocha instance
|
||||||
|
fs.readdirSync(testDir).filter(function(file) {
|
||||||
// Add each .js file to the mocha instance
|
return /\.js$/.test(file);
|
||||||
fs.readdirSync(testDir).filter(function(file){
|
}).forEach(function(file) {
|
||||||
// Only keep the .js files
|
mocha.addFile(path.join(testDir, file));
|
||||||
return file.substr(-3) === '.js';
|
|
||||||
|
|
||||||
}).forEach(function(file){
|
|
||||||
mocha.addFile(
|
|
||||||
path.join(testDir, file)
|
|
||||||
);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
module.exports = function() {
|
module.exports = function() {
|
||||||
mocha.run(function(failures) {
|
mocha.run(function(failures) {
|
||||||
if (failures !== 0) {
|
if (failures) process.on("exit", function() {
|
||||||
process.on('exit', function () {
|
process.exit(failures);
|
||||||
process.exit(failures);
|
});
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -16,8 +16,8 @@ describe("Accessor tokens", function() {
|
|||||||
assert.equal(node.start.pos, 12);
|
assert.equal(node.start.pos, 12);
|
||||||
assert.equal(node.end.endpos, 46);
|
assert.equal(node.end.endpos, 46);
|
||||||
|
|
||||||
assert(node.key instanceof UglifyJS.AST_SymbolMethod);
|
assert(node.key instanceof UglifyJS.AST_SymbolAccessor);
|
||||||
assert.equal(node.key.start.pos, 12);
|
assert.equal(node.key.start.pos, 16);
|
||||||
assert.equal(node.key.end.endpos, 22);
|
assert.equal(node.key.end.endpos, 22);
|
||||||
|
|
||||||
assert(node.value instanceof UglifyJS.AST_Accessor);
|
assert(node.value instanceof UglifyJS.AST_Accessor);
|
||||||
|
|||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user