Compare commits
472 Commits
v3.4.2
...
harmony-v3
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
1b2e6b81a2 | ||
|
|
f9e9898dc1 | ||
|
|
c44d78db55 | ||
|
|
8c763bf2b5 | ||
|
|
aa1786dedf | ||
|
|
0d5df271a1 | ||
|
|
b56e1f178f | ||
|
|
9acace2cb6 | ||
|
|
0f2be1456c | ||
|
|
1eb15f46f1 | ||
|
|
137cb73d1f | ||
|
|
1f3f8f25eb | ||
|
|
4b1799ecdd | ||
|
|
7a8eff62ca | ||
|
|
f76b5e0f43 | ||
|
|
ffc64e2279 | ||
|
|
a6653e2102 | ||
|
|
3bbe839518 | ||
|
|
ace272f0c5 | ||
|
|
725aac8b46 | ||
|
|
53600e9869 | ||
|
|
7dea749f58 | ||
|
|
0a3fac6e68 | ||
|
|
9f7d1f7ac6 | ||
|
|
ef74f2eaaf | ||
|
|
96082f7a9b | ||
|
|
a53784e0c5 | ||
|
|
a3b8dec347 | ||
|
|
49ce573971 | ||
|
|
01bb08b553 | ||
|
|
fc3010bec5 | ||
|
|
7de541f9c8 | ||
|
|
dbf8684287 | ||
|
|
8d156b51fe | ||
|
|
85bfa17139 | ||
|
|
80c8dfcde6 | ||
|
|
f8ff349ba7 | ||
|
|
f2b179ae94 | ||
|
|
c7e8fc4830 | ||
|
|
f778a0aa01 | ||
|
|
7fd4b66eaa | ||
|
|
21c986ff5b | ||
|
|
87bae623e9 | ||
|
|
606f7a5b37 | ||
|
|
b91a2e018a | ||
|
|
c9dbe9deb1 | ||
|
|
1885f91f13 | ||
|
|
736c366d93 | ||
|
|
1646c5844f | ||
|
|
aacf760fb4 | ||
|
|
755e2a62c6 | ||
|
|
62d2817d6c | ||
|
|
37cbd7080c | ||
|
|
b84c99ef5c | ||
|
|
4f08c2f504 | ||
|
|
ba4894af18 | ||
|
|
f1e3ef5262 | ||
|
|
bbf38dc9c0 | ||
|
|
3d8341a7ab | ||
|
|
567cb0e4e3 | ||
|
|
227b58812d | ||
|
|
f25bd13be6 | ||
|
|
e826973b76 | ||
|
|
9632f79e46 | ||
|
|
a3fbb27194 | ||
|
|
11c0b1e1f9 | ||
|
|
650d5d5c9b | ||
|
|
dd0a36119b | ||
|
|
94b19a9c46 | ||
|
|
bcf95ac02c | ||
|
|
e11cec1ab8 | ||
|
|
0c43519097 | ||
|
|
352a7de204 | ||
|
|
df9c8dfd72 | ||
|
|
29bbc41dfe | ||
|
|
d535daa2c7 | ||
|
|
0a9cdb6c73 | ||
|
|
3ae34177a6 | ||
|
|
086cb33163 | ||
|
|
6371e2ee63 | ||
|
|
6ab73c7bd5 | ||
|
|
2848596280 | ||
|
|
7d9a8596a9 | ||
|
|
44352eb26a | ||
|
|
9f1c72ae28 | ||
|
|
c60fa67827 | ||
|
|
f9c57dfee0 | ||
|
|
6bf5fea008 | ||
|
|
b6a7ca292e | ||
|
|
a89f126db6 | ||
|
|
d8ee2de95c | ||
|
|
58a5608b66 | ||
|
|
f496ac5c85 | ||
|
|
f79f737fb2 | ||
|
|
336b1add4f | ||
|
|
873755b35c | ||
|
|
744032755d | ||
|
|
4fac8076b8 | ||
|
|
a020d2ead3 | ||
|
|
68645b28d3 | ||
|
|
aaa8212837 | ||
|
|
bd84007cf4 | ||
|
|
1241600013 | ||
|
|
a784717fe2 | ||
|
|
e8235657e4 | ||
|
|
c46b9f361a | ||
|
|
3b0b4d6abf | ||
|
|
d73500e8d1 | ||
|
|
d8685f528d | ||
|
|
8891495789 | ||
|
|
2779a29a86 | ||
|
|
067d52b6ba | ||
|
|
e0e009ace2 | ||
|
|
ae0f117da6 | ||
|
|
a5461e0adc | ||
|
|
2bf8216e50 | ||
|
|
2ed3f8db44 | ||
|
|
4700c14855 | ||
|
|
f54ab16843 | ||
|
|
69cb459c16 | ||
|
|
1eae8f2dcc | ||
|
|
d600c78d7b | ||
|
|
d3df2f985d | ||
|
|
69861824b5 | ||
|
|
1e0c7d2bc5 | ||
|
|
98b850580b | ||
|
|
29011ea60a | ||
|
|
77d18be073 | ||
|
|
91f8b57b3e | ||
|
|
3a2b737c42 | ||
|
|
0f4278148d | ||
|
|
f30375052b | ||
|
|
3e1a8598bf | ||
|
|
ef63de6968 | ||
|
|
2539fb8096 | ||
|
|
a556dd2dcb | ||
|
|
e7334b4048 | ||
|
|
f5c46db738 | ||
|
|
fdbb1d09ef | ||
|
|
33ad0d258c | ||
|
|
5ea1da2d42 | ||
|
|
e77b6d525c | ||
|
|
a9eecd844f | ||
|
|
ed3032e52a | ||
|
|
52cc21d999 | ||
|
|
a938fe5e1f | ||
|
|
07a5a57336 | ||
|
|
945db924fc | ||
|
|
087bce508a | ||
|
|
fc7e33453f | ||
|
|
d052394621 | ||
|
|
4d5aeeddfb | ||
|
|
ad139aa34d | ||
|
|
26be15f111 | ||
|
|
179f33f08a | ||
|
|
d260fe9018 | ||
|
|
96f9b8cba3 | ||
|
|
11afa816e3 | ||
|
|
49f3de8397 | ||
|
|
94f93ad82d | ||
|
|
d1f085bce7 | ||
|
|
7b95b63ca1 | ||
|
|
137e4c4753 | ||
|
|
b163b13a0b | ||
|
|
402954bdf3 | ||
|
|
f5931866e0 | ||
|
|
471db8a717 | ||
|
|
8ba9e4e0da | ||
|
|
71556d00b5 | ||
|
|
8709753bfb | ||
|
|
db877e8729 | ||
|
|
11923e3ae8 | ||
|
|
62d1fbf645 | ||
|
|
849ba79dee | ||
|
|
a298bcce02 | ||
|
|
daaf1273fa | ||
|
|
3fa862ce19 | ||
|
|
370f2cc906 | ||
|
|
78cf35f89c | ||
|
|
100e18305d | ||
|
|
7cc03d4d40 | ||
|
|
c28056d7ed | ||
|
|
8af362ed57 | ||
|
|
68138f2281 | ||
|
|
a7971f4e34 | ||
|
|
82fefc5d29 | ||
|
|
753932b302 | ||
|
|
1edbd6556f | ||
|
|
888a321417 | ||
|
|
ee5c03f7f1 | ||
|
|
0cb75089f0 | ||
|
|
a1647ee0c5 | ||
|
|
c814060b4a | ||
|
|
303293e4aa | ||
|
|
23265ac253 | ||
|
|
0cc6dedccc | ||
|
|
ec63588496 | ||
|
|
c2e471e3ad | ||
|
|
ee23a84e14 | ||
|
|
520da57fdc | ||
|
|
e5e0ce0b42 | ||
|
|
94d2aeee89 | ||
|
|
aa835eb0f6 | ||
|
|
39d4d7e20a | ||
|
|
02811ce35e | ||
|
|
c988e5f4d6 | ||
|
|
075b648bb1 | ||
|
|
37e549ff4f | ||
|
|
7bcb442e4c | ||
|
|
a658cd84a5 | ||
|
|
5b22334f3b | ||
|
|
a3053c537a | ||
|
|
d6f77a6352 | ||
|
|
a2172e1a99 | ||
|
|
9a074c2637 | ||
|
|
02b14528fa | ||
|
|
3db2001633 | ||
|
|
aaba482e48 | ||
|
|
5f29fced0a | ||
|
|
b1b918e6d6 | ||
|
|
ebb469e4cd | ||
|
|
c22d26b483 | ||
|
|
f751e64d49 | ||
|
|
60c56a24b9 | ||
|
|
01f23cf5a1 | ||
|
|
99fb3e8f0d | ||
|
|
756c9aa7dc | ||
|
|
07d6bfd707 | ||
|
|
81243c4e71 | ||
|
|
cd6e849555 | ||
|
|
91de285166 | ||
|
|
4d8f289eb0 | ||
|
|
945ba64160 | ||
|
|
c699200398 | ||
|
|
daf44f2b21 | ||
|
|
fcd90db30d | ||
|
|
e2888bdc43 | ||
|
|
fb50b7b627 | ||
|
|
9d59c693c2 | ||
|
|
6ddb5bd94d | ||
|
|
eda49605c5 | ||
|
|
1e9ef17e32 | ||
|
|
222100ea4c | ||
|
|
93db48a317 | ||
|
|
2944e3df7d | ||
|
|
e0ae8da089 | ||
|
|
81f1311b24 | ||
|
|
2433bb4e52 | ||
|
|
3fac29a017 | ||
|
|
b4c18f6b83 | ||
|
|
73d6438773 | ||
|
|
5c6316a37d | ||
|
|
278577f3cb | ||
|
|
0d8597e904 | ||
|
|
c20bb99a62 | ||
|
|
2377171200 | ||
|
|
603d92effc | ||
|
|
17f0cc359f | ||
|
|
35bae3fcd0 | ||
|
|
4614b5b46e | ||
|
|
2f93058c6e | ||
|
|
a729c43e87 | ||
|
|
66e9039350 | ||
|
|
d717bf9ce8 | ||
|
|
5dea52266b | ||
|
|
fccefbeaca | ||
|
|
1e2b0aaa04 | ||
|
|
6a54de79b5 | ||
|
|
9e2290b29c | ||
|
|
97d0fc271d | ||
|
|
7906033e82 | ||
|
|
4bf21ce5c1 | ||
|
|
44d6b47bdc | ||
|
|
129e449c8e | ||
|
|
75c3c8963f | ||
|
|
d26b7522d9 | ||
|
|
2fd86d3cb0 | ||
|
|
8f7ab602e2 | ||
|
|
1dd339f95e | ||
|
|
c7063c1f38 | ||
|
|
f4a12b34f2 | ||
|
|
5d5c7934a5 | ||
|
|
8f4b45f4f8 | ||
|
|
952e2656eb | ||
|
|
240383a314 | ||
|
|
250b782b1e | ||
|
|
3c2b3aeddb | ||
|
|
aa605495f8 | ||
|
|
33a26d456b | ||
|
|
49d9ac1c43 | ||
|
|
c8e61448cb | ||
|
|
f704e9b65c | ||
|
|
0b77d861a8 | ||
|
|
e27dab7e7c | ||
|
|
80f3ad3ce0 | ||
|
|
22f7af205d | ||
|
|
8a7a4749c7 | ||
|
|
514fc68f4f | ||
|
|
478aaab469 | ||
|
|
ab217539e9 | ||
|
|
a942dc07c4 | ||
|
|
a0eaff750d | ||
|
|
57777b6cfa | ||
|
|
8d205f7f39 | ||
|
|
bc9bfd15a2 | ||
|
|
9fc1c4b3b5 | ||
|
|
c59bf5e8d8 | ||
|
|
d2d3a6e065 | ||
|
|
7755733716 | ||
|
|
b3a987b0df | ||
|
|
88a338f29e | ||
|
|
07734b000a | ||
|
|
85c1cba760 | ||
|
|
4bd31607f6 | ||
|
|
4728bc73ad | ||
|
|
52ce9a333c | ||
|
|
abbeb266b5 | ||
|
|
b11c5151bc | ||
|
|
962b1f3d40 | ||
|
|
3ee46e91e8 | ||
|
|
ee26e7f11b | ||
|
|
937f534392 | ||
|
|
1b2c02c944 | ||
|
|
0aa526e72c | ||
|
|
c2112d5886 | ||
|
|
5f6825f9ec | ||
|
|
7e80a979a7 | ||
|
|
b7bb706150 | ||
|
|
32c2cc33bb | ||
|
|
947b8750e8 | ||
|
|
88f6ff38d1 | ||
|
|
4198095a9c | ||
|
|
13ed445607 | ||
|
|
1db50c3b16 | ||
|
|
7f6b5d662b | ||
|
|
1c15d0db45 | ||
|
|
67461666dc | ||
|
|
45d81f881b | ||
|
|
8c7d23dfb1 | ||
|
|
7fa0dbdeb9 | ||
|
|
c644c1292d | ||
|
|
d224d71b8d | ||
|
|
27d3669800 | ||
|
|
110a1ac885 | ||
|
|
3f8fc3a316 | ||
|
|
88384cf351 | ||
|
|
72a9d799b6 | ||
|
|
766fafda8b | ||
|
|
842ac27efb | ||
|
|
0af42d1831 | ||
|
|
ff7f6139ba | ||
|
|
0db7caf13b | ||
|
|
d9bc6f303c | ||
|
|
6fd9b338dd | ||
|
|
d8d4e71b9e | ||
|
|
fb2f8d1a51 | ||
|
|
54a783ba84 | ||
|
|
63c432f4fa | ||
|
|
07785d0003 | ||
|
|
6eaeb19a4a | ||
|
|
2246c79318 | ||
|
|
dda58244b6 | ||
|
|
ca04508cd1 | ||
|
|
6b03b800b3 | ||
|
|
f9cab7ad61 | ||
|
|
0a3d780327 | ||
|
|
b0555a123a | ||
|
|
fa29344781 | ||
|
|
dcfc514c38 | ||
|
|
8ad8d7b717 | ||
|
|
0357e5923f | ||
|
|
f63803e3e3 | ||
|
|
63be1f3a4d | ||
|
|
e36e07fa77 | ||
|
|
d1b4f61f93 | ||
|
|
5b893c8ec3 | ||
|
|
8571a08a93 | ||
|
|
68cc14f846 | ||
|
|
f94497d1d6 | ||
|
|
eaf3911c31 | ||
|
|
91cdb93e57 | ||
|
|
634f231b78 | ||
|
|
6702cae918 | ||
|
|
6d2f77c180 | ||
|
|
accca2445f | ||
|
|
0bc4f6edb4 | ||
|
|
ce84a706a3 | ||
|
|
86b5248837 | ||
|
|
59e1601fb8 | ||
|
|
d35a9e7839 | ||
|
|
0465bd270d | ||
|
|
6780d0906c | ||
|
|
0b303379c0 | ||
|
|
d7ec2ecc12 | ||
|
|
2827fa8699 | ||
|
|
c80ec625ec | ||
|
|
5e78f20f1c | ||
|
|
1f75232062 | ||
|
|
028ff64e9a | ||
|
|
7a8cffd631 | ||
|
|
5b553aafe2 | ||
|
|
084437bc6d | ||
|
|
1cd9a2df9a | ||
|
|
7f3dbb6df7 | ||
|
|
e4d73d8b7c | ||
|
|
8220dbbea0 | ||
|
|
59e999597e | ||
|
|
cbcb3ac44e | ||
|
|
f07ab4666f | ||
|
|
a800356ad0 | ||
|
|
e076abdbf2 | ||
|
|
425613b0d2 | ||
|
|
69da8e53e0 | ||
|
|
bb6b3a773a | ||
|
|
364d20f8fb | ||
|
|
392ac4ff31 | ||
|
|
9ffed2bea6 | ||
|
|
5f7cb6939c | ||
|
|
64e7a00399 | ||
|
|
c99eaae360 | ||
|
|
34213ea2f8 | ||
|
|
da8c428a07 | ||
|
|
0d8dea9538 | ||
|
|
2babe737e0 | ||
|
|
2cce61c564 | ||
|
|
246ec416c0 | ||
|
|
6be9c752d5 | ||
|
|
76ed083e47 | ||
|
|
b31918bbf0 | ||
|
|
b14496c742 | ||
|
|
991fa99655 | ||
|
|
3d7f73114d | ||
|
|
dde9e293df | ||
|
|
34685a6f55 | ||
|
|
9812c826e0 | ||
|
|
2fac2bbfe4 | ||
|
|
242c61be94 | ||
|
|
e1cb1a0e3c | ||
|
|
af22b9c657 | ||
|
|
adee5023c0 | ||
|
|
7ee8f3512e | ||
|
|
dc5db9b6ca | ||
|
|
079aaa0d48 | ||
|
|
d4f17f29ae | ||
|
|
e99bc914ca | ||
|
|
025d34bfa2 | ||
|
|
c44c2d6c21 | ||
|
|
824ecfb8a2 | ||
|
|
ceebc466b9 | ||
|
|
35b31bdd4e | ||
|
|
c8b82583d2 | ||
|
|
9f9179ba1a | ||
|
|
872231a0ca | ||
|
|
36420183fd | ||
|
|
a8f8aa518b | ||
|
|
4c12cccff9 | ||
|
|
dcce4e5c66 | ||
|
|
56c0b834d6 | ||
|
|
6f864402d3 | ||
|
|
8909e9e1cb | ||
|
|
e80ed38772 | ||
|
|
9863f0efa3 | ||
|
|
e8664e63ef | ||
|
|
ddd30eeaaa | ||
|
|
a68953c491 | ||
|
|
fa5c4f2d03 | ||
|
|
9d7d365c2b | ||
|
|
ad344c5be3 | ||
|
|
96b89e34a3 | ||
|
|
4644becb9b | ||
|
|
f7460166dd | ||
|
|
32f76f7ff8 |
10
.github/ISSUE_TEMPLATE.md
vendored
10
.github/ISSUE_TEMPLATE.md
vendored
@@ -1,7 +1,11 @@
|
|||||||
**Bug report or feature request?**
|
**Bug report or feature request?**
|
||||||
|
|
||||||
<!-- Note: sub-optimal but correct code is not a bug -->
|
<!-- Note: sub-optimal but correct code is not a bug -->
|
||||||
|
|
||||||
|
**ES5 or ES6+ input?**
|
||||||
|
|
||||||
|
<!-- Note: for ES6 see: https://github.com/mishoo/UglifyJS2/tree/harmony#harmony -->
|
||||||
|
|
||||||
**Uglify version (`uglifyjs -V`)**
|
**Uglify version (`uglifyjs -V`)**
|
||||||
|
|
||||||
**JavaScript input**
|
**JavaScript input**
|
||||||
@@ -20,6 +24,6 @@
|
|||||||
**JavaScript output or error produced.**
|
**JavaScript output or error produced.**
|
||||||
|
|
||||||
<!--
|
<!--
|
||||||
Note: `uglify-js` only supports JavaScript.
|
Note: `uglify-js` only supports ES5.
|
||||||
Those wishing to minify ES6+ should transpile first.
|
Those wishing to minify ES6 should use `uglify-es`.
|
||||||
-->
|
-->
|
||||||
|
|||||||
@@ -1,61 +0,0 @@
|
|||||||
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-2018 (c) Mihai Bazon <mihai.bazon@gmail.com>
|
Copyright 2012-2013 (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
|
||||||
|
|||||||
169
README.md
169
README.md
@@ -1,13 +1,11 @@
|
|||||||
UglifyJS 3
|
uglify-es
|
||||||
==========
|
=========
|
||||||
|
|
||||||
UglifyJS is a JavaScript parser, minifier, compressor and beautifier toolkit.
|
A JavaScript parser, mangler/compressor and beautifier toolkit for ES6+.
|
||||||
|
|
||||||
#### Note:
|
#### Note:
|
||||||
- **`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 API/CLI compatible with `uglify-js@3`.**
|
||||||
- **Documentation for UglifyJS `2.x` releases can be found [here](https://github.com/mishoo/UglifyJS2/tree/v2.x)**.
|
- **`uglify-es` is not backwards compatible with `uglify-js@2`.**
|
||||||
- `uglify-js` only supports JavaScript (ECMAScript 5).
|
|
||||||
- To minify ECMAScript 2015 or above, transpile using tools like [Babel](https://babeljs.io/).
|
|
||||||
|
|
||||||
Install
|
Install
|
||||||
-------
|
-------
|
||||||
@@ -17,11 +15,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-js -g
|
npm install uglify-es -g
|
||||||
|
|
||||||
From NPM for programmatic use:
|
From NPM for programmatic use:
|
||||||
|
|
||||||
npm install uglify-js
|
npm install uglify-es
|
||||||
|
|
||||||
# Command line usage
|
# Command line usage
|
||||||
|
|
||||||
@@ -69,7 +67,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 properties.
|
`keep_quoted` Only mangle unquoted properies.
|
||||||
`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:
|
||||||
@@ -104,15 +102,20 @@ 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.
|
||||||
-e, --enclose [arg[:value]] Embed everything in a big function, with configurable
|
--ecma <version> Specify ECMAScript release: 5, 6, 7 or 8.
|
||||||
argument(s) & value(s).
|
|
||||||
--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.
|
||||||
@@ -120,8 +123,7 @@ a double dash to prevent input files being used as option arguments:
|
|||||||
JS that was generated from some other original
|
JS that was generated from some other original
|
||||||
code. Specify "inline" if the source map is
|
code. Specify "inline" if the source map is
|
||||||
included within the sources.
|
included within the sources.
|
||||||
`filename` Filename and/or location of the output source
|
`filename` Name and/or location of the output source.
|
||||||
(sets `file` attribute in source map).
|
|
||||||
`includeSources` Pass this flag if you want to include
|
`includeSources` Pass this flag if you want to include
|
||||||
the content of source files in the
|
the content of source files in the
|
||||||
source map as sourcesContent property.
|
source map as sourcesContent property.
|
||||||
@@ -152,9 +154,7 @@ debugging your compressed JavaScript. To get a source map, pass
|
|||||||
|
|
||||||
Additional options:
|
Additional options:
|
||||||
|
|
||||||
- `--source-map "filename='<NAME>'"` to specify the name of the source map. The value of
|
- `--source-map "filename='<NAME>'"` to specify the name of the source map.
|
||||||
`filename` is only used to set `file` attribute (see [the spec][sm-spec])
|
|
||||||
in source map file.
|
|
||||||
|
|
||||||
- `--source-map "root='<URL>'"` to pass the URL where the original files can be found.
|
- `--source-map "root='<URL>'"` to pass the URL where the original files can be found.
|
||||||
|
|
||||||
@@ -349,7 +349,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-js");
|
var UglifyJS = require("uglify-es");
|
||||||
```
|
```
|
||||||
|
|
||||||
There is a single high level function, **`minify(code, options)`**,
|
There is a single high level function, **`minify(code, options)`**,
|
||||||
@@ -478,6 +478,9 @@ 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.
|
||||||
|
|
||||||
@@ -512,8 +515,17 @@ 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`.
|
of function names. Useful for code relying on `Function.prototype.name`. If the
|
||||||
|
top level minify option `keep_classnames` is `undefined` it will be overriden with
|
||||||
|
the value of the top level minify option `keep_fnames`.
|
||||||
|
|
||||||
|
- `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
|
||||||
|
|
||||||
@@ -538,9 +550,13 @@ if (result.error) throw result.error;
|
|||||||
sourceMap: {
|
sourceMap: {
|
||||||
// source map options
|
// source map options
|
||||||
},
|
},
|
||||||
nameCache: null, // or specify a name cache object
|
ecma: 5, // specify one of: 5, 6, 7 or 8
|
||||||
toplevel: false,
|
keep_classnames: false,
|
||||||
|
keep_fnames: false,
|
||||||
ie8: false,
|
ie8: false,
|
||||||
|
nameCache: null, // or specify a name cache object
|
||||||
|
safari10: false,
|
||||||
|
toplevel: false,
|
||||||
warnings: false,
|
warnings: false,
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
@@ -596,14 +612,20 @@ 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
|
||||||
|
|
||||||
- `arguments` (default: `true`) -- replace `arguments[index]` with function
|
- `arrows` (default: `true`) -- Converts `()=>{return x}` to `()=>x`. Class
|
||||||
parameter name whenever possible.
|
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`
|
||||||
@@ -612,8 +634,11 @@ If you're using the `X-SourceMap` header instead, you can just omit `sourceMap.u
|
|||||||
side effects permitting.
|
side effects permitting.
|
||||||
|
|
||||||
- `comparisons` (default: `true`) -- apply certain optimizations to binary nodes,
|
- `comparisons` (default: `true`) -- apply certain optimizations to binary nodes,
|
||||||
e.g. `!(a <= b) → a > b`, attempts to negate binary nodes, e.g.
|
e.g. `!(a <= b) → a > b` (only when `unsafe_comps`), attempts to negate binary
|
||||||
`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
|
||||||
@@ -627,6 +652,9 @@ 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
|
||||||
@@ -657,6 +685,10 @@ If you're using the `X-SourceMap` header instead, you can just omit `sourceMap.u
|
|||||||
|
|
||||||
- `join_vars` (default: `true`) -- join consecutive `var` statements
|
- `join_vars` (default: `true`) -- join consecutive `var` statements
|
||||||
|
|
||||||
|
- `keep_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`.
|
||||||
|
|
||||||
@@ -690,8 +722,7 @@ If you're using the `X-SourceMap` header instead, you can just omit `sourceMap.u
|
|||||||
pass `pure_funcs: [ 'Math.floor' ]` to let it know that this
|
pass `pure_funcs: [ 'Math.floor' ]` to let it know that this
|
||||||
function won't produce any side effect, in which case the whole
|
function won't produce any side effect, in which case the whole
|
||||||
statement would get discarded. The current implementation adds some
|
statement would get discarded. The current implementation adds some
|
||||||
overhead (compression will be slower). Make sure symbols under `pure_funcs`
|
overhead (compression will be slower).
|
||||||
are also under `mangle.reserved` to avoid mangling.
|
|
||||||
|
|
||||||
- `pure_getters` (default: `"strict"`) -- If you pass `true` for
|
- `pure_getters` (default: `"strict"`) -- If you pass `true` for
|
||||||
this, UglifyJS will assume that object property access
|
this, UglifyJS will assume that object property access
|
||||||
@@ -738,25 +769,38 @@ 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_comps` (default: `false`) -- compress expressions like `a <= b` assuming
|
- `unsafe_arrows` (default: `false`) -- Convert ES5 style anonymous function
|
||||||
none of the operands can be (coerced to) `NaN`.
|
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_Function` (default: `false`) -- compress and mangle `Function(args, code)`
|
- `unsafe_comps` (default: `false`) -- Reverse `<` and `<=` to `>` and `>=` to
|
||||||
|
allow improved compression. This might be unsafe when an at least one of two
|
||||||
|
operands is an object with computed values due the use of methods like `get`,
|
||||||
|
or `valueOf`. This could cause change in execution order after operands in the
|
||||||
|
comparison are switching. Compression only works if both `comparisons` and
|
||||||
|
`unsafe_comps` are both set to true.
|
||||||
|
|
||||||
|
- `unsafe_Func` (default: `false`) -- compress and mangle `Function(args, code)`
|
||||||
when both `args` and `code` are string literals.
|
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"`)
|
||||||
|
|
||||||
@@ -768,6 +812,9 @@ 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).
|
||||||
@@ -778,6 +825,11 @@ 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
|
||||||
@@ -830,7 +882,7 @@ can pass additional arguments that control the code output:
|
|||||||
when you want to generate minified code, in order to specify additional
|
when you want to generate minified code, in order to specify additional
|
||||||
arguments, so you can use `-b beautify=false` to override it.
|
arguments, so you can use `-b beautify=false` to override it.
|
||||||
|
|
||||||
- `braces` (default `false`) -- always insert braces in `if`, `for`,
|
- `bracketize` (default `false`) -- always insert brackets in `if`, `for`,
|
||||||
`do`, `while` or `with` statements, even if their body is a single
|
`do`, `while` or `with` statements, even if their body is a single
|
||||||
statement.
|
statement.
|
||||||
|
|
||||||
@@ -838,12 +890,19 @@ 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
|
||||||
|
|
||||||
- `inline_script` (default `true`) -- escape HTML comments and the slash in
|
- `inline_script` (default `false`) -- escape the slash in occurrences of
|
||||||
occurrences of `</script>` in strings
|
`</script` in strings
|
||||||
|
|
||||||
- `keep_quoted_props` (default `false`) -- when turned on, prevents stripping
|
- `keep_quoted_props` (default `false`) -- when turned on, prevents stripping
|
||||||
quotes from property names in object literals.
|
quotes from property names in object literals.
|
||||||
@@ -869,6 +928,10 @@ 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
|
||||||
@@ -930,6 +993,9 @@ 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
|
||||||
|
|
||||||
@@ -1046,9 +1112,8 @@ var result = UglifyJS.minify(ast, {
|
|||||||
### Working with Uglify AST
|
### Working with Uglify AST
|
||||||
|
|
||||||
Transversal and transformation of the native AST can be performed through
|
Transversal and transformation of the native AST can be performed through
|
||||||
[`TreeWalker`](https://github.com/mishoo/UglifyJS2/blob/master/lib/ast.js) and
|
[`TreeWalker`](http://lisperator.net/uglifyjs/walk) and
|
||||||
[`TreeTransformer`](https://github.com/mishoo/UglifyJS2/blob/master/lib/transform.js)
|
[`TreeTransformer`](http://lisperator.net/uglifyjs/transform) respectively.
|
||||||
respectively.
|
|
||||||
|
|
||||||
### ESTree / SpiderMonkey AST
|
### ESTree / SpiderMonkey AST
|
||||||
|
|
||||||
@@ -1107,27 +1172,3 @@ 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()`).
|
|
||||||
|
|||||||
48
bin/uglifyjs
48
bin/uglifyjs
@@ -40,15 +40,16 @@ 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("-e, --enclose [arg[,...][:value[,...]]]", "Embed everything in a big function, with configurable argument(s) & value(s).");
|
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_js());
|
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.")
|
||||||
program.option("--toplevel", "Compress and/or mangle variables in toplevel scope.");
|
program.option("--toplevel", "Compress and/or mangle variables in toplevel scope.");
|
||||||
program.option("--verbose", "Print diagnostic messages.");
|
program.option("--verbose", "Print diagnostic messages.");
|
||||||
program.option("--warn", "Print warning messages.");
|
program.option("--warn", "Print warning messages.");
|
||||||
@@ -62,17 +63,23 @@ if (!program.output && program.sourceMap && program.sourceMap.url != "inline") {
|
|||||||
}
|
}
|
||||||
[
|
[
|
||||||
"compress",
|
"compress",
|
||||||
"enclose",
|
|
||||||
"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)) {
|
||||||
@@ -90,6 +97,9 @@ if (program.define) {
|
|||||||
options.compress.global_defs[expr] = program.define[expr];
|
options.compress.global_defs[expr] = program.define[expr];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (program.keepClassnames) {
|
||||||
|
options.keep_classnames = true;
|
||||||
|
}
|
||||||
if (program.keepFnames) {
|
if (program.keepFnames) {
|
||||||
options.keep_fnames = true;
|
options.keep_fnames = true;
|
||||||
}
|
}
|
||||||
@@ -122,11 +132,6 @@ 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;
|
||||||
};
|
};
|
||||||
@@ -178,11 +183,6 @@ function run() {
|
|||||||
UglifyJS.AST_Node.warn_function = function(msg) {
|
UglifyJS.AST_Node.warn_function = function(msg) {
|
||||||
print_error("WARN: " + msg);
|
print_error("WARN: " + msg);
|
||||||
};
|
};
|
||||||
var content = program.sourceMap && program.sourceMap.content;
|
|
||||||
if (content && content != "inline") {
|
|
||||||
print_error("INFO: Using input source map: " + content);
|
|
||||||
options.sourceMap.content = read_file(content, content);
|
|
||||||
}
|
|
||||||
if (program.timings) options.timings = true;
|
if (program.timings) options.timings = true;
|
||||||
try {
|
try {
|
||||||
if (program.parse) {
|
if (program.parse) {
|
||||||
@@ -255,6 +255,11 @@ function run() {
|
|||||||
var result = {
|
var result = {
|
||||||
_class: "AST_" + value.TYPE
|
_class: "AST_" + value.TYPE
|
||||||
};
|
};
|
||||||
|
if (value.block_scope) {
|
||||||
|
result.variables = value.block_scope.variables;
|
||||||
|
result.functions = value.block_scope.functions;
|
||||||
|
result.enclosed = value.block_scope.enclosed;
|
||||||
|
}
|
||||||
value.CTOR.PROPS.forEach(function(prop) {
|
value.CTOR.PROPS.forEach(function(prop) {
|
||||||
result[prop] = value[prop];
|
result[prop] = value[prop];
|
||||||
});
|
});
|
||||||
@@ -384,6 +389,19 @@ function parse_js(flag) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function parse_source_map() {
|
||||||
|
var parse = parse_js();
|
||||||
|
return function(value, options) {
|
||||||
|
var hasContent = options && "content" in options;
|
||||||
|
var settings = parse(value, options);
|
||||||
|
if (!hasContent && settings.content && settings.content != "inline") {
|
||||||
|
print_error("INFO: Using input source map: " + settings.content);
|
||||||
|
settings.content = read_file(settings.content, settings.content);
|
||||||
|
}
|
||||||
|
return settings;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function skip_key(key) {
|
function skip_key(key) {
|
||||||
return skip_keys.indexOf(key) >= 0;
|
return skip_keys.indexOf(key) >= 0;
|
||||||
}
|
}
|
||||||
|
|||||||
545
lib/ast.js
545
lib/ast.js
@@ -44,21 +44,21 @@
|
|||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
function DEFNODE(type, props, methods, base) {
|
function DEFNODE(type, props, methods, base) {
|
||||||
if (typeof base === "undefined") base = AST_Node;
|
if (arguments.length < 4) base = AST_Node;
|
||||||
props = props ? props.split(/\s+/) : [];
|
if (!props) props = [];
|
||||||
|
else props = props.split(/\s+/);
|
||||||
var self_props = props;
|
var self_props = props;
|
||||||
if (base && base.PROPS) props = props.concat(base.PROPS);
|
if (base && base.PROPS)
|
||||||
var code = [
|
props = props.concat(base.PROPS);
|
||||||
"return function AST_", type, "(props){",
|
var code = "return function AST_" + type + "(props){ if (props) { ";
|
||||||
"if(props){",
|
for (var i = props.length; --i >= 0;) {
|
||||||
];
|
code += "this." + props[i] + " = props." + props[i] + ";";
|
||||||
props.forEach(function(prop) {
|
}
|
||||||
code.push("this.", prop, "=props.", prop, ";");
|
|
||||||
});
|
|
||||||
var proto = base && new base;
|
var proto = base && new base;
|
||||||
if (proto && proto.initialize || methods && methods.initialize) code.push("this.initialize();");
|
if (proto && proto.initialize || (methods && methods.initialize))
|
||||||
code.push("}}");
|
code += "this.initialize();";
|
||||||
var ctor = new Function(code.join(""))();
|
code += "}}";
|
||||||
|
var ctor = new Function(code)();
|
||||||
if (proto) {
|
if (proto) {
|
||||||
ctor.prototype = proto;
|
ctor.prototype = proto;
|
||||||
ctor.BASE = base;
|
ctor.BASE = base;
|
||||||
@@ -71,11 +71,11 @@ function DEFNODE(type, props, methods, base) {
|
|||||||
if (type) {
|
if (type) {
|
||||||
ctor.prototype.TYPE = ctor.TYPE = type;
|
ctor.prototype.TYPE = ctor.TYPE = type;
|
||||||
}
|
}
|
||||||
if (methods) for (var name in methods) if (HOP(methods, name)) {
|
if (methods) for (i in methods) if (HOP(methods, i)) {
|
||||||
if (/^\$/.test(name)) {
|
if (/^\$/.test(i)) {
|
||||||
ctor[name.substr(1)] = methods[name];
|
ctor[i.substr(1)] = methods[i];
|
||||||
} else {
|
} else {
|
||||||
ctor.prototype[name] = methods[name];
|
ctor.prototype[i] = methods[i];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ctor.DEFMETHOD = function(name, method) {
|
ctor.DEFMETHOD = function(name, method) {
|
||||||
@@ -85,7 +85,7 @@ function DEFNODE(type, props, methods, base) {
|
|||||||
exports["AST_" + type] = ctor;
|
exports["AST_" + type] = ctor;
|
||||||
}
|
}
|
||||||
return ctor;
|
return ctor;
|
||||||
}
|
};
|
||||||
|
|
||||||
var AST_Token = DEFNODE("Token", "type value line col pos endline endcol endpos nlb comments_before comments_after file raw", {
|
var AST_Token = DEFNODE("Token", "type value line col pos endline endcol endpos nlb comments_before comments_after file raw", {
|
||||||
}, null);
|
}, null);
|
||||||
@@ -148,7 +148,7 @@ var AST_SimpleStatement = DEFNODE("SimpleStatement", "body", {
|
|||||||
body: "[AST_Node] an expression node (should not be instanceof AST_Statement)"
|
body: "[AST_Node] an expression node (should not be instanceof AST_Statement)"
|
||||||
},
|
},
|
||||||
_walk: function(visitor) {
|
_walk: function(visitor) {
|
||||||
return visitor._visit(this, function() {
|
return visitor._visit(this, function(){
|
||||||
this.body._walk(visitor);
|
this.body._walk(visitor);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -156,20 +156,21 @@ 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_Statement) {
|
if (body instanceof AST_Node) {
|
||||||
body._walk(visitor);
|
body._walk(visitor);
|
||||||
} else body.forEach(function(node) {
|
}
|
||||||
node._walk(visitor);
|
else for (var i = 0, len = body.length; i < len; i++) {
|
||||||
});
|
body[i]._walk(visitor);
|
||||||
}
|
}
|
||||||
|
};
|
||||||
|
|
||||||
var AST_Block = DEFNODE("Block", "body", {
|
var AST_Block = DEFNODE("Block", "body", {
|
||||||
$documentation: "A body of statements (usually braced)",
|
$documentation: "A body of statements (usually bracketed)",
|
||||||
$propdoc: {
|
$propdoc: {
|
||||||
body: "[AST_Statement*] an array of statements"
|
body: "[AST_Statement*] an array of statements"
|
||||||
},
|
},
|
||||||
_walk: function(visitor) {
|
_walk: function(visitor) {
|
||||||
return visitor._visit(this, function() {
|
return visitor._visit(this, function(){
|
||||||
walk_body(this, visitor);
|
walk_body(this, visitor);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -196,7 +197,7 @@ var AST_LabeledStatement = DEFNODE("LabeledStatement", "label", {
|
|||||||
label: "[AST_Label] a label definition"
|
label: "[AST_Label] a label definition"
|
||||||
},
|
},
|
||||||
_walk: function(visitor) {
|
_walk: function(visitor) {
|
||||||
return visitor._visit(this, function() {
|
return visitor._visit(this, function(){
|
||||||
this.label._walk(visitor);
|
this.label._walk(visitor);
|
||||||
this.body._walk(visitor);
|
this.body._walk(visitor);
|
||||||
});
|
});
|
||||||
@@ -232,7 +233,7 @@ var AST_DWLoop = DEFNODE("DWLoop", "condition", {
|
|||||||
var AST_Do = DEFNODE("Do", null, {
|
var AST_Do = DEFNODE("Do", null, {
|
||||||
$documentation: "A `do` statement",
|
$documentation: "A `do` statement",
|
||||||
_walk: function(visitor) {
|
_walk: function(visitor) {
|
||||||
return visitor._visit(this, function() {
|
return visitor._visit(this, function(){
|
||||||
this.body._walk(visitor);
|
this.body._walk(visitor);
|
||||||
this.condition._walk(visitor);
|
this.condition._walk(visitor);
|
||||||
});
|
});
|
||||||
@@ -242,7 +243,7 @@ var AST_Do = DEFNODE("Do", null, {
|
|||||||
var AST_While = DEFNODE("While", null, {
|
var AST_While = DEFNODE("While", null, {
|
||||||
$documentation: "A `while` statement",
|
$documentation: "A `while` statement",
|
||||||
_walk: function(visitor) {
|
_walk: function(visitor) {
|
||||||
return visitor._visit(this, function() {
|
return visitor._visit(this, function(){
|
||||||
this.condition._walk(visitor);
|
this.condition._walk(visitor);
|
||||||
this.body._walk(visitor);
|
this.body._walk(visitor);
|
||||||
});
|
});
|
||||||
@@ -257,7 +258,7 @@ var AST_For = DEFNODE("For", "init condition step", {
|
|||||||
step: "[AST_Node?] the `for` update clause, or null if empty"
|
step: "[AST_Node?] the `for` update clause, or null if empty"
|
||||||
},
|
},
|
||||||
_walk: function(visitor) {
|
_walk: function(visitor) {
|
||||||
return visitor._visit(this, function() {
|
return visitor._visit(this, function(){
|
||||||
if (this.init) this.init._walk(visitor);
|
if (this.init) this.init._walk(visitor);
|
||||||
if (this.condition) this.condition._walk(visitor);
|
if (this.condition) this.condition._walk(visitor);
|
||||||
if (this.step) this.step._walk(visitor);
|
if (this.step) this.step._walk(visitor);
|
||||||
@@ -266,14 +267,15 @@ var AST_For = DEFNODE("For", "init condition step", {
|
|||||||
}
|
}
|
||||||
}, AST_IterationStatement);
|
}, AST_IterationStatement);
|
||||||
|
|
||||||
var AST_ForIn = DEFNODE("ForIn", "init object", {
|
var AST_ForIn = DEFNODE("ForIn", "init name 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) {
|
||||||
return visitor._visit(this, function() {
|
return visitor._visit(this, function(){
|
||||||
this.init._walk(visitor);
|
this.init._walk(visitor);
|
||||||
this.object._walk(visitor);
|
this.object._walk(visitor);
|
||||||
this.body._walk(visitor);
|
this.body._walk(visitor);
|
||||||
@@ -281,13 +283,17 @@ var AST_ForIn = DEFNODE("ForIn", "init 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: {
|
||||||
expression: "[AST_Node] the `with` expression"
|
expression: "[AST_Node] the `with` expression"
|
||||||
},
|
},
|
||||||
_walk: function(visitor) {
|
_walk: function(visitor) {
|
||||||
return visitor._visit(this, function() {
|
return visitor._visit(this, function(){
|
||||||
this.expression._walk(visitor);
|
this.expression._walk(visitor);
|
||||||
this.body._walk(visitor);
|
this.body._walk(visitor);
|
||||||
});
|
});
|
||||||
@@ -307,15 +313,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)",
|
||||||
},
|
},
|
||||||
clone: function(deep) {
|
get_defun_scope: function() {
|
||||||
var node = this._clone(deep);
|
var self = this;
|
||||||
if (this.variables) node.variables = this.variables.clone();
|
while (self.is_block_scope()) {
|
||||||
if (this.functions) node.functions = this.functions.clone();
|
self = self.parent_scope;
|
||||||
if (this.enclosed) node.enclosed = this.enclosed.slice();
|
}
|
||||||
return node;
|
return self;
|
||||||
},
|
|
||||||
pinned: function() {
|
|
||||||
return this.uses_eval || this.uses_with;
|
|
||||||
}
|
}
|
||||||
}, AST_Block);
|
}, AST_Block);
|
||||||
|
|
||||||
@@ -328,45 +331,55 @@ var AST_Toplevel = DEFNODE("Toplevel", "globals", {
|
|||||||
var body = this.body;
|
var body = this.body;
|
||||||
var wrapped_tl = "(function(exports){'$ORIG';})(typeof " + name + "=='undefined'?(" + name + "={}):" + name + ");";
|
var wrapped_tl = "(function(exports){'$ORIG';})(typeof " + name + "=='undefined'?(" + name + "={}):" + name + ");";
|
||||||
wrapped_tl = parse(wrapped_tl);
|
wrapped_tl = parse(wrapped_tl);
|
||||||
wrapped_tl = wrapped_tl.transform(new TreeTransformer(function before(node) {
|
wrapped_tl = wrapped_tl.transform(new TreeTransformer(function before(node){
|
||||||
if (node instanceof AST_Directive && node.value == "$ORIG") {
|
if (node instanceof AST_Directive && node.value == "$ORIG") {
|
||||||
return MAP.splice(body);
|
return MAP.splice(body);
|
||||||
}
|
}
|
||||||
}));
|
}));
|
||||||
return wrapped_tl;
|
return wrapped_tl;
|
||||||
},
|
|
||||||
wrap_enclose: function(args_values) {
|
|
||||||
if (typeof args_values != "string") args_values = "";
|
|
||||||
var index = args_values.indexOf(":");
|
|
||||||
if (index < 0) index = args_values.length;
|
|
||||||
var body = this.body;
|
|
||||||
return parse([
|
|
||||||
"(function(",
|
|
||||||
args_values.slice(0, index),
|
|
||||||
'){"$ORIG"})(',
|
|
||||||
args_values.slice(index + 1),
|
|
||||||
")"
|
|
||||||
].join("")).transform(new TreeTransformer(function(node) {
|
|
||||||
if (node instanceof AST_Directive && node.value == "$ORIG") {
|
|
||||||
return MAP.splice(body);
|
|
||||||
}
|
|
||||||
}));
|
|
||||||
}
|
}
|
||||||
}, AST_Scope);
|
}, AST_Scope);
|
||||||
|
|
||||||
var AST_Lambda = DEFNODE("Lambda", "name argnames uses_arguments", {
|
var AST_Expansion = DEFNODE("Expansion", "expression", {
|
||||||
|
$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*] array of function arguments",
|
argnames: "[AST_SymbolFunarg|AST_Destructuring|AST_Expansion|AST_DefaultAssign*] array of function arguments, destructurings, or expanding 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(){
|
||||||
if (this.name) this.name._walk(visitor);
|
if (this.name) this.name._walk(visitor);
|
||||||
this.argnames.forEach(function(argname) {
|
var argnames = this.argnames;
|
||||||
argname._walk(visitor);
|
for (var i = 0, len = argnames.length; i < len; i++) {
|
||||||
});
|
argnames[i]._walk(visitor);
|
||||||
|
}
|
||||||
walk_body(this, visitor);
|
walk_body(this, visitor);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -380,10 +393,76 @@ 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, {
|
||||||
@@ -396,7 +475,7 @@ var AST_Exit = DEFNODE("Exit", "value", {
|
|||||||
value: "[AST_Node?] the value returned or thrown by this statement; could be null for AST_Return"
|
value: "[AST_Node?] the value returned or thrown by this statement; could be null for AST_Return"
|
||||||
},
|
},
|
||||||
_walk: function(visitor) {
|
_walk: function(visitor) {
|
||||||
return visitor._visit(this, this.value && function() {
|
return visitor._visit(this, this.value && function(){
|
||||||
this.value._walk(visitor);
|
this.value._walk(visitor);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -416,7 +495,7 @@ var AST_LoopControl = DEFNODE("LoopControl", "label", {
|
|||||||
label: "[AST_LabelRef?] the label, or null if none",
|
label: "[AST_LabelRef?] the label, or null if none",
|
||||||
},
|
},
|
||||||
_walk: function(visitor) {
|
_walk: function(visitor) {
|
||||||
return visitor._visit(this, this.label && function() {
|
return visitor._visit(this, this.label && function(){
|
||||||
this.label._walk(visitor);
|
this.label._walk(visitor);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -439,7 +518,7 @@ var AST_If = DEFNODE("If", "condition alternative", {
|
|||||||
alternative: "[AST_Statement?] the `else` part, or null if not present"
|
alternative: "[AST_Statement?] the `else` part, or null if not present"
|
||||||
},
|
},
|
||||||
_walk: function(visitor) {
|
_walk: function(visitor) {
|
||||||
return visitor._visit(this, function() {
|
return visitor._visit(this, function(){
|
||||||
this.condition._walk(visitor);
|
this.condition._walk(visitor);
|
||||||
this.body._walk(visitor);
|
this.body._walk(visitor);
|
||||||
if (this.alternative) this.alternative._walk(visitor);
|
if (this.alternative) this.alternative._walk(visitor);
|
||||||
@@ -455,7 +534,7 @@ var AST_Switch = DEFNODE("Switch", "expression", {
|
|||||||
expression: "[AST_Node] the `switch` “discriminant”"
|
expression: "[AST_Node] the `switch` “discriminant”"
|
||||||
},
|
},
|
||||||
_walk: function(visitor) {
|
_walk: function(visitor) {
|
||||||
return visitor._visit(this, function() {
|
return visitor._visit(this, function(){
|
||||||
this.expression._walk(visitor);
|
this.expression._walk(visitor);
|
||||||
walk_body(this, visitor);
|
walk_body(this, visitor);
|
||||||
});
|
});
|
||||||
@@ -476,7 +555,7 @@ var AST_Case = DEFNODE("Case", "expression", {
|
|||||||
expression: "[AST_Node] the `case` expression"
|
expression: "[AST_Node] the `case` expression"
|
||||||
},
|
},
|
||||||
_walk: function(visitor) {
|
_walk: function(visitor) {
|
||||||
return visitor._visit(this, function() {
|
return visitor._visit(this, function(){
|
||||||
this.expression._walk(visitor);
|
this.expression._walk(visitor);
|
||||||
walk_body(this, visitor);
|
walk_body(this, visitor);
|
||||||
});
|
});
|
||||||
@@ -492,7 +571,7 @@ var AST_Try = DEFNODE("Try", "bcatch bfinally", {
|
|||||||
bfinally: "[AST_Finally?] the finally block, or null if not present"
|
bfinally: "[AST_Finally?] the finally block, or null if not present"
|
||||||
},
|
},
|
||||||
_walk: function(visitor) {
|
_walk: function(visitor) {
|
||||||
return visitor._visit(this, function() {
|
return visitor._visit(this, function(){
|
||||||
walk_body(this, visitor);
|
walk_body(this, visitor);
|
||||||
if (this.bcatch) this.bcatch._walk(visitor);
|
if (this.bcatch) this.bcatch._walk(visitor);
|
||||||
if (this.bfinally) this.bfinally._walk(visitor);
|
if (this.bfinally) this.bfinally._walk(visitor);
|
||||||
@@ -503,10 +582,10 @@ 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] symbol for the exception"
|
argname: "[AST_SymbolCatch|AST_Destructuring|AST_Expansion|AST_DefaultAssign] symbol for the exception"
|
||||||
},
|
},
|
||||||
_walk: function(visitor) {
|
_walk: function(visitor) {
|
||||||
return visitor._visit(this, function() {
|
return visitor._visit(this, function(){
|
||||||
this.argname._walk(visitor);
|
this.argname._walk(visitor);
|
||||||
walk_body(this, visitor);
|
walk_body(this, visitor);
|
||||||
});
|
});
|
||||||
@@ -517,18 +596,19 @@ 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 ]----- */
|
/* -----[ VAR/CONST ]----- */
|
||||||
|
|
||||||
var AST_Definitions = DEFNODE("Definitions", "definitions", {
|
var AST_Definitions = DEFNODE("Definitions", "definitions", {
|
||||||
$documentation: "Base class for `var` nodes (variable declarations/initializations)",
|
$documentation: "Base class for `var` or `const` nodes (variable declarations/initializations)",
|
||||||
$propdoc: {
|
$propdoc: {
|
||||||
definitions: "[AST_VarDef*] array of variable definitions"
|
definitions: "[AST_VarDef*] array of variable definitions"
|
||||||
},
|
},
|
||||||
_walk: function(visitor) {
|
_walk: function(visitor) {
|
||||||
return visitor._visit(this, function() {
|
return visitor._visit(this, function(){
|
||||||
this.definitions.forEach(function(defn) {
|
var definitions = this.definitions;
|
||||||
defn._walk(visitor);
|
for (var i = 0, len = definitions.length; i < len; i++) {
|
||||||
});
|
definitions[i]._walk(visitor);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}, AST_Statement);
|
}, AST_Statement);
|
||||||
@@ -537,14 +617,87 @@ var AST_Var = DEFNODE("Var", null, {
|
|||||||
$documentation: "A `var` statement"
|
$documentation: "A `var` statement"
|
||||||
}, AST_Definitions);
|
}, AST_Definitions);
|
||||||
|
|
||||||
var AST_VarDef = DEFNODE("VarDef", "name value", {
|
var AST_Let = DEFNODE("Let", null, {
|
||||||
$documentation: "A variable declaration; only appears in a AST_Definitions node",
|
$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: {
|
$propdoc: {
|
||||||
name: "[AST_SymbolVar] name of the variable",
|
foreign_name: "[AST_SymbolExportForeign|AST_SymbolImportForeign] The name being exported/imported (as specified in the module)",
|
||||||
value: "[AST_Node?] initializer, or null of there's no initializer"
|
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) {
|
_walk: function(visitor) {
|
||||||
return visitor._visit(this, function() {
|
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", {
|
||||||
|
$documentation: "A variable declaration; only appears in a AST_Definitions node",
|
||||||
|
$propdoc: {
|
||||||
|
name: "[AST_Destructuring|AST_SymbolConst|AST_SymbolLet|AST_SymbolVar] name of the variable",
|
||||||
|
value: "[AST_Node?] initializer, or null of there's no initializer"
|
||||||
|
},
|
||||||
|
_walk: function(visitor) {
|
||||||
|
return visitor._visit(this, function(){
|
||||||
this.name._walk(visitor);
|
this.name._walk(visitor);
|
||||||
if (this.value) this.value._walk(visitor);
|
if (this.value) this.value._walk(visitor);
|
||||||
});
|
});
|
||||||
@@ -560,11 +713,12 @@ var AST_Call = DEFNODE("Call", "expression args", {
|
|||||||
args: "[AST_Node*] array of arguments"
|
args: "[AST_Node*] array of arguments"
|
||||||
},
|
},
|
||||||
_walk: function(visitor) {
|
_walk: function(visitor) {
|
||||||
return visitor._visit(this, function() {
|
return visitor._visit(this, function(){
|
||||||
|
var args = this.args;
|
||||||
|
for (var i = 0, len = args.length; i < len; i++) {
|
||||||
|
args[i]._walk(visitor);
|
||||||
|
}
|
||||||
this.expression._walk(visitor);
|
this.expression._walk(visitor);
|
||||||
this.args.forEach(function(node) {
|
|
||||||
node._walk(visitor);
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -579,7 +733,7 @@ var AST_Sequence = DEFNODE("Sequence", "expressions", {
|
|||||||
expressions: "[AST_Node*] array of expressions (at least two)"
|
expressions: "[AST_Node*] array of expressions (at least two)"
|
||||||
},
|
},
|
||||||
_walk: function(visitor) {
|
_walk: function(visitor) {
|
||||||
return visitor._visit(this, function() {
|
return visitor._visit(this, function(){
|
||||||
this.expressions.forEach(function(node) {
|
this.expressions.forEach(function(node) {
|
||||||
node._walk(visitor);
|
node._walk(visitor);
|
||||||
});
|
});
|
||||||
@@ -598,7 +752,7 @@ var AST_PropAccess = DEFNODE("PropAccess", "expression property", {
|
|||||||
var AST_Dot = DEFNODE("Dot", null, {
|
var AST_Dot = DEFNODE("Dot", null, {
|
||||||
$documentation: "A dotted property access expression",
|
$documentation: "A dotted property access expression",
|
||||||
_walk: function(visitor) {
|
_walk: function(visitor) {
|
||||||
return visitor._visit(this, function() {
|
return visitor._visit(this, function(){
|
||||||
this.expression._walk(visitor);
|
this.expression._walk(visitor);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -607,7 +761,7 @@ var AST_Dot = DEFNODE("Dot", null, {
|
|||||||
var AST_Sub = DEFNODE("Sub", null, {
|
var AST_Sub = DEFNODE("Sub", null, {
|
||||||
$documentation: "Index-style property access, i.e. `a[\"foo\"]`",
|
$documentation: "Index-style property access, i.e. `a[\"foo\"]`",
|
||||||
_walk: function(visitor) {
|
_walk: function(visitor) {
|
||||||
return visitor._visit(this, function() {
|
return visitor._visit(this, function(){
|
||||||
this.expression._walk(visitor);
|
this.expression._walk(visitor);
|
||||||
this.property._walk(visitor);
|
this.property._walk(visitor);
|
||||||
});
|
});
|
||||||
@@ -621,7 +775,7 @@ var AST_Unary = DEFNODE("Unary", "operator expression", {
|
|||||||
expression: "[AST_Node] expression that this unary operator applies to"
|
expression: "[AST_Node] expression that this unary operator applies to"
|
||||||
},
|
},
|
||||||
_walk: function(visitor) {
|
_walk: function(visitor) {
|
||||||
return visitor._visit(this, function() {
|
return visitor._visit(this, function(){
|
||||||
this.expression._walk(visitor);
|
this.expression._walk(visitor);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -643,7 +797,7 @@ var AST_Binary = DEFNODE("Binary", "operator left right", {
|
|||||||
right: "[AST_Node] right-hand side expression"
|
right: "[AST_Node] right-hand side expression"
|
||||||
},
|
},
|
||||||
_walk: function(visitor) {
|
_walk: function(visitor) {
|
||||||
return visitor._visit(this, function() {
|
return visitor._visit(this, function(){
|
||||||
this.left._walk(visitor);
|
this.left._walk(visitor);
|
||||||
this.right._walk(visitor);
|
this.right._walk(visitor);
|
||||||
});
|
});
|
||||||
@@ -658,7 +812,7 @@ var AST_Conditional = DEFNODE("Conditional", "condition consequent alternative",
|
|||||||
alternative: "[AST_Node]"
|
alternative: "[AST_Node]"
|
||||||
},
|
},
|
||||||
_walk: function(visitor) {
|
_walk: function(visitor) {
|
||||||
return visitor._visit(this, function() {
|
return visitor._visit(this, function(){
|
||||||
this.condition._walk(visitor);
|
this.condition._walk(visitor);
|
||||||
this.consequent._walk(visitor);
|
this.consequent._walk(visitor);
|
||||||
this.alternative._walk(visitor);
|
this.alternative._walk(visitor);
|
||||||
@@ -670,6 +824,10 @@ 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", {
|
||||||
@@ -678,10 +836,11 @@ var AST_Array = DEFNODE("Array", "elements", {
|
|||||||
elements: "[AST_Node*] array of elements"
|
elements: "[AST_Node*] array of elements"
|
||||||
},
|
},
|
||||||
_walk: function(visitor) {
|
_walk: function(visitor) {
|
||||||
return visitor._visit(this, function() {
|
return visitor._visit(this, function(){
|
||||||
this.elements.forEach(function(element) {
|
var elements = this.elements;
|
||||||
element._walk(visitor);
|
for (var i = 0, len = elements.length; i < len; i++) {
|
||||||
});
|
elements[i]._walk(visitor);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -692,10 +851,11 @@ var AST_Object = DEFNODE("Object", "properties", {
|
|||||||
properties: "[AST_ObjectProperty*] array of properties"
|
properties: "[AST_ObjectProperty*] array of properties"
|
||||||
},
|
},
|
||||||
_walk: function(visitor) {
|
_walk: function(visitor) {
|
||||||
return visitor._visit(this, function() {
|
return visitor._visit(this, function(){
|
||||||
this.properties.forEach(function(prop) {
|
var properties = this.properties;
|
||||||
prop._walk(visitor);
|
for (var i = 0, len = properties.length; i < len; i++) {
|
||||||
});
|
properties[i]._walk(visitor);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -703,11 +863,13 @@ 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_SymbolAccessor] property name. For ObjectKeyVal this is a string. For getters and setters this is an AST_SymbolAccessor.",
|
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",
|
||||||
value: "[AST_Node] property value. For getters and setters this is an AST_Accessor."
|
value: "[AST_Node] property value. For setters and getters 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);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -720,35 +882,95 @@ var AST_ObjectKeyVal = DEFNODE("ObjectKeyVal", "quote", {
|
|||||||
}
|
}
|
||||||
}, AST_ObjectProperty);
|
}, AST_ObjectProperty);
|
||||||
|
|
||||||
var AST_ObjectSetter = DEFNODE("ObjectSetter", null, {
|
var AST_ObjectSetter = DEFNODE("ObjectSetter", "quote static", {
|
||||||
|
$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", null, {
|
var AST_ObjectGetter = DEFNODE("ObjectGetter", "quote static", {
|
||||||
|
$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_SymbolAccessor = DEFNODE("SymbolAccessor", null, {
|
var AST_NewTarget = DEFNODE("NewTarget", null, {
|
||||||
$documentation: "The name of a property accessor (setter/getter function)"
|
$documentation: "A reference to new.target"
|
||||||
}, AST_Symbol);
|
});
|
||||||
|
|
||||||
var AST_SymbolDeclaration = DEFNODE("SymbolDeclaration", "init", {
|
var AST_SymbolDeclaration = DEFNODE("SymbolDeclaration", "init", {
|
||||||
$documentation: "A declaration symbol (symbol in var, function name or argument, symbol in catch)",
|
$documentation: "A declaration symbol (symbol in var/const, 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);
|
||||||
@@ -757,13 +979,33 @@ 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_SymbolDeclaration);
|
}, AST_SymbolBlockDeclaration);
|
||||||
|
|
||||||
|
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)",
|
||||||
@@ -780,6 +1022,14 @@ 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);
|
||||||
@@ -788,6 +1038,10 @@ 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() {
|
||||||
@@ -834,12 +1088,12 @@ var AST_NaN = DEFNODE("NaN", null, {
|
|||||||
|
|
||||||
var AST_Undefined = DEFNODE("Undefined", null, {
|
var AST_Undefined = DEFNODE("Undefined", null, {
|
||||||
$documentation: "The `undefined` value",
|
$documentation: "The `undefined` value",
|
||||||
value: function(){}()
|
value: (function(){}())
|
||||||
}, AST_Atom);
|
}, AST_Atom);
|
||||||
|
|
||||||
var AST_Hole = DEFNODE("Hole", null, {
|
var AST_Hole = DEFNODE("Hole", null, {
|
||||||
$documentation: "A hole in an array",
|
$documentation: "A hole in an array",
|
||||||
value: function(){}()
|
value: (function(){}())
|
||||||
}, AST_Atom);
|
}, AST_Atom);
|
||||||
|
|
||||||
var AST_Infinity = DEFNODE("Infinity", null, {
|
var AST_Infinity = DEFNODE("Infinity", null, {
|
||||||
@@ -861,17 +1115,42 @@ 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) {
|
||||||
this.visit = callback;
|
this.visit = callback;
|
||||||
this.stack = [];
|
this.stack = [];
|
||||||
this.directives = Object.create(null);
|
this.directives = Object.create(null);
|
||||||
}
|
};
|
||||||
TreeWalker.prototype = {
|
TreeWalker.prototype = {
|
||||||
_visit: function(node, descend) {
|
_visit: function(node, descend) {
|
||||||
this.push(node);
|
this.push(node);
|
||||||
var ret = this.visit(node, descend ? function() {
|
var ret = this.visit(node, descend ? function(){
|
||||||
descend.call(node);
|
descend.call(node);
|
||||||
} : noop);
|
} : noop);
|
||||||
if (!ret && descend) {
|
if (!ret && descend) {
|
||||||
@@ -888,11 +1167,17 @@ 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() {
|
||||||
if (this.stack.pop() instanceof AST_Lambda) {
|
var node = this.stack.pop();
|
||||||
|
if (node instanceof AST_Lambda || node instanceof AST_Class) {
|
||||||
this.directives = Object.getPrototypeOf(this.directives);
|
this.directives = Object.getPrototypeOf(this.directives);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@@ -910,7 +1195,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) {
|
if (node instanceof AST_Scope && node.body) {
|
||||||
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;
|
||||||
@@ -930,25 +1215,5 @@ TreeWalker.prototype = {
|
|||||||
|| node instanceof AST_Break && x instanceof AST_Switch)
|
|| node instanceof AST_Break && x instanceof AST_Switch)
|
||||||
return x;
|
return x;
|
||||||
}
|
}
|
||||||
},
|
|
||||||
in_boolean_context: function() {
|
|
||||||
var self = this.self();
|
|
||||||
for (var i = 0, p; p = this.parent(i); i++) {
|
|
||||||
if (p instanceof AST_SimpleStatement
|
|
||||||
|| p instanceof AST_Conditional && p.condition === self
|
|
||||||
|| p instanceof AST_DWLoop && p.condition === self
|
|
||||||
|| p instanceof AST_For && p.condition === self
|
|
||||||
|| p instanceof AST_If && p.condition === self
|
|
||||||
|| p instanceof AST_UnaryPrefix && p.operator == "!" && p.expression === self) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
if (p instanceof AST_Binary && (p.operator == "&&" || p.operator == "||")
|
|
||||||
|| p instanceof AST_Conditional
|
|
||||||
|| p.tail_node() === self) {
|
|
||||||
self = p;
|
|
||||||
} else {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
3212
lib/compress.js
3212
lib/compress.js
File diff suppressed because it is too large
Load Diff
@@ -7,23 +7,15 @@ var to_base64 = typeof btoa == "undefined" ? function(str) {
|
|||||||
return new Buffer(str).toString("base64");
|
return new Buffer(str).toString("base64");
|
||||||
} : btoa;
|
} : btoa;
|
||||||
|
|
||||||
function read_source_map(name, code) {
|
function read_source_map(code) {
|
||||||
var match = /\n\/\/# sourceMappingURL=data:application\/json(;.*?)?;base64,(.*)/.exec(code);
|
var match = /\n\/\/# sourceMappingURL=data:application\/json(;.*?)?;base64,(.*)/.exec(code);
|
||||||
if (!match) {
|
if (!match) {
|
||||||
AST_Node.warn("inline source map not found: " + name);
|
AST_Node.warn("inline source map not found");
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
return to_ascii(match[2]);
|
return to_ascii(match[2]);
|
||||||
}
|
}
|
||||||
|
|
||||||
function parse_source_map(content) {
|
|
||||||
try {
|
|
||||||
return JSON.parse(content);
|
|
||||||
} catch (ex) {
|
|
||||||
throw new Error("invalid input source map: " + content);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function set_shorthand(name, options, keys) {
|
function set_shorthand(name, options, keys) {
|
||||||
if (options[name]) {
|
if (options[name]) {
|
||||||
keys.forEach(function(key) {
|
keys.forEach(function(key) {
|
||||||
@@ -55,14 +47,16 @@ function minify(files, options) {
|
|||||||
try {
|
try {
|
||||||
options = defaults(options, {
|
options = defaults(options, {
|
||||||
compress: {},
|
compress: {},
|
||||||
enclose: false,
|
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,
|
||||||
@@ -72,11 +66,17 @@ 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;
|
||||||
@@ -85,9 +85,11 @@ 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) {
|
||||||
@@ -122,7 +124,7 @@ function minify(files, options) {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
if (timings) timings.parse = Date.now();
|
if (timings) timings.parse = Date.now();
|
||||||
var source_maps, toplevel;
|
var toplevel;
|
||||||
if (files instanceof AST_Toplevel) {
|
if (files instanceof AST_Toplevel) {
|
||||||
toplevel = files;
|
toplevel = files;
|
||||||
} else {
|
} else {
|
||||||
@@ -131,23 +133,13 @@ function minify(files, options) {
|
|||||||
}
|
}
|
||||||
options.parse = options.parse || {};
|
options.parse = options.parse || {};
|
||||||
options.parse.toplevel = null;
|
options.parse.toplevel = null;
|
||||||
var source_map_content = options.sourceMap && options.sourceMap.content;
|
|
||||||
if (typeof source_map_content == "string" && source_map_content != "inline") {
|
|
||||||
source_map_content = parse_source_map(source_map_content);
|
|
||||||
}
|
|
||||||
source_maps = source_map_content && Object.create(null);
|
|
||||||
for (var name in files) if (HOP(files, name)) {
|
for (var name in files) if (HOP(files, name)) {
|
||||||
options.parse.filename = name;
|
options.parse.filename = name;
|
||||||
options.parse.toplevel = parse(files[name], options.parse);
|
options.parse.toplevel = parse(files[name], options.parse);
|
||||||
if (source_maps) {
|
if (options.sourceMap && options.sourceMap.content == "inline") {
|
||||||
if (source_map_content == "inline") {
|
if (Object.keys(files).length > 1)
|
||||||
var inlined_content = read_source_map(name, files[name]);
|
throw new Error("inline source map only works with singular input");
|
||||||
if (inlined_content) {
|
options.sourceMap.content = read_source_map(files[name]);
|
||||||
source_maps[name] = parse_source_map(inlined_content);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
source_maps[name] = source_map_content;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
toplevel = options.parse.toplevel;
|
toplevel = options.parse.toplevel;
|
||||||
@@ -158,9 +150,6 @@ function minify(files, options) {
|
|||||||
if (options.wrap) {
|
if (options.wrap) {
|
||||||
toplevel = toplevel.wrap_commonjs(options.wrap);
|
toplevel = toplevel.wrap_commonjs(options.wrap);
|
||||||
}
|
}
|
||||||
if (options.enclose) {
|
|
||||||
toplevel = toplevel.wrap_enclose(options.enclose);
|
|
||||||
}
|
|
||||||
if (timings) timings.rename = Date.now();
|
if (timings) timings.rename = Date.now();
|
||||||
if (options.rename) {
|
if (options.rename) {
|
||||||
toplevel.figure_out_scope(options.mangle);
|
toplevel.figure_out_scope(options.mangle);
|
||||||
@@ -172,6 +161,7 @@ function minify(files, options) {
|
|||||||
if (options.mangle) toplevel.figure_out_scope(options.mangle);
|
if (options.mangle) toplevel.figure_out_scope(options.mangle);
|
||||||
if (timings) timings.mangle = Date.now();
|
if (timings) timings.mangle = Date.now();
|
||||||
if (options.mangle) {
|
if (options.mangle) {
|
||||||
|
base54.reset();
|
||||||
toplevel.compute_char_frequency(options.mangle);
|
toplevel.compute_char_frequency(options.mangle);
|
||||||
toplevel.mangle_names(options.mangle);
|
toplevel.mangle_names(options.mangle);
|
||||||
}
|
}
|
||||||
@@ -186,9 +176,12 @@ function minify(files, options) {
|
|||||||
}
|
}
|
||||||
if (!HOP(options.output, "code") || options.output.code) {
|
if (!HOP(options.output, "code") || options.output.code) {
|
||||||
if (options.sourceMap) {
|
if (options.sourceMap) {
|
||||||
|
if (typeof options.sourceMap.content == "string") {
|
||||||
|
options.sourceMap.content = JSON.parse(options.sourceMap.content);
|
||||||
|
}
|
||||||
options.output.source_map = SourceMap({
|
options.output.source_map = SourceMap({
|
||||||
file: options.sourceMap.filename,
|
file: options.sourceMap.filename,
|
||||||
orig: source_maps,
|
orig: options.sourceMap.content,
|
||||||
root: options.sourceMap.root
|
root: options.sourceMap.root
|
||||||
});
|
});
|
||||||
if (options.sourceMap.includeSources) {
|
if (options.sourceMap.includeSources) {
|
||||||
@@ -197,8 +190,6 @@ function minify(files, options) {
|
|||||||
} else for (var name in files) if (HOP(files, name)) {
|
} else for (var name in files) if (HOP(files, name)) {
|
||||||
options.output.source_map.get().setSourceContent(name, files[name]);
|
options.output.source_map.get().setSourceContent(name, files[name]);
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
options.output.source_map.get()._sourcesContents = null;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
delete options.output.ast;
|
delete options.output.ast;
|
||||||
|
|||||||
@@ -43,9 +43,11 @@
|
|||||||
|
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
(function() {
|
(function(){
|
||||||
function normalize_directives(body) {
|
|
||||||
|
var normalize_directives = function(body) {
|
||||||
var in_directive = true;
|
var in_directive = true;
|
||||||
|
|
||||||
for (var i = 0; i < body.length; i++) {
|
for (var i = 0; i < body.length; i++) {
|
||||||
if (in_directive && body[i] instanceof AST_Statement && body[i].body instanceof AST_String) {
|
if (in_directive && body[i] instanceof AST_Statement && body[i].body instanceof AST_String) {
|
||||||
body[i] = new AST_Directive({
|
body[i] = new AST_Directive({
|
||||||
@@ -57,8 +59,9 @@
|
|||||||
in_directive = false;
|
in_directive = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return body;
|
return body;
|
||||||
}
|
};
|
||||||
|
|
||||||
var MOZ_TO_ME = {
|
var MOZ_TO_ME = {
|
||||||
Program: function(M) {
|
Program: function(M) {
|
||||||
@@ -115,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_SymbolAccessor({
|
args.key = new AST_SymbolMethod({
|
||||||
name: args.key
|
name: args.key
|
||||||
});
|
});
|
||||||
args.value = new AST_Accessor(args.value);
|
args.value = new AST_Accessor(args.value);
|
||||||
@@ -126,7 +129,7 @@
|
|||||||
return new AST_Array({
|
return new AST_Array({
|
||||||
start : my_start_token(M),
|
start : my_start_token(M),
|
||||||
end : my_end_token(M),
|
end : my_end_token(M),
|
||||||
elements : M.elements.map(function(elem) {
|
elements : M.elements.map(function(elem){
|
||||||
return elem === null ? new AST_Hole() : from_moz(elem);
|
return elem === null ? new AST_Hole() : from_moz(elem);
|
||||||
})
|
})
|
||||||
});
|
});
|
||||||
@@ -135,7 +138,7 @@
|
|||||||
return new AST_Object({
|
return new AST_Object({
|
||||||
start : my_start_token(M),
|
start : my_start_token(M),
|
||||||
end : my_end_token(M),
|
end : my_end_token(M),
|
||||||
properties : M.properties.map(function(prop) {
|
properties : M.properties.map(function(prop){
|
||||||
prop.type = "Property";
|
prop.type = "Property";
|
||||||
return from_moz(prop)
|
return from_moz(prop)
|
||||||
})
|
})
|
||||||
@@ -165,7 +168,7 @@
|
|||||||
});
|
});
|
||||||
},
|
},
|
||||||
VariableDeclaration: function(M) {
|
VariableDeclaration: function(M) {
|
||||||
return new AST_Var({
|
return new (M.kind === "const" ? AST_Const : 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)
|
||||||
@@ -177,17 +180,6 @@
|
|||||||
end : my_end_token(M)
|
end : my_end_token(M)
|
||||||
};
|
};
|
||||||
if (val === null) return new AST_Null(args);
|
if (val === null) return new AST_Null(args);
|
||||||
var rx = M.regex;
|
|
||||||
if (rx && rx.pattern) {
|
|
||||||
// RegExpLiteral as per ESTree AST spec
|
|
||||||
args.value = new RegExp(rx.pattern, rx.flags);
|
|
||||||
args.value.raw_source = rx.pattern;
|
|
||||||
return new AST_RegExp(args);
|
|
||||||
} else if (rx) {
|
|
||||||
// support legacy RegExp
|
|
||||||
args.value = M.regex && M.raw ? M.raw : val;
|
|
||||||
return new AST_RegExp(args);
|
|
||||||
}
|
|
||||||
switch (typeof val) {
|
switch (typeof val) {
|
||||||
case "string":
|
case "string":
|
||||||
args.value = val;
|
args.value = val;
|
||||||
@@ -197,12 +189,22 @@
|
|||||||
return new AST_Number(args);
|
return new AST_Number(args);
|
||||||
case "boolean":
|
case "boolean":
|
||||||
return new (val ? AST_True : AST_False)(args);
|
return new (val ? AST_True : AST_False)(args);
|
||||||
|
default:
|
||||||
|
var rx = M.regex;
|
||||||
|
if (rx && rx.pattern) {
|
||||||
|
// RegExpLiteral as per ESTree AST spec
|
||||||
|
args.value = new RegExp(rx.pattern, rx.flags).toString();
|
||||||
|
} else {
|
||||||
|
// support legacy RegExp
|
||||||
|
args.value = M.regex && M.raw ? M.raw : val;
|
||||||
|
}
|
||||||
|
return new AST_RegExp(args);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
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 ? AST_SymbolVar
|
: p.type == "VariableDeclarator" && p.id === M ? (p.kind == "const" ? AST_SymbolConst : 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
|
||||||
@@ -322,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: "var",
|
kind: M instanceof AST_Const ? "const" : "var",
|
||||||
declarations: M.definitions.map(to_moz)
|
declarations: M.definitions.map(to_moz)
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
@@ -379,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_SymbolAccessor ? M.key.name : M.key
|
value: M.key instanceof AST_SymbolMethod ? M.key.name : M.key
|
||||||
};
|
};
|
||||||
var kind;
|
var kind;
|
||||||
if (M instanceof AST_ObjectKeyVal) {
|
if (M instanceof AST_ObjectKeyVal) {
|
||||||
@@ -408,15 +410,14 @@
|
|||||||
});
|
});
|
||||||
|
|
||||||
def_to_moz(AST_RegExp, function To_Moz_RegExpLiteral(M) {
|
def_to_moz(AST_RegExp, function To_Moz_RegExpLiteral(M) {
|
||||||
var flags = M.value.toString().match(/[gimuy]*$/)[0];
|
var value = M.value;
|
||||||
var value = "/" + M.value.raw_source + "/" + flags;
|
|
||||||
return {
|
return {
|
||||||
type: "Literal",
|
type: "Literal",
|
||||||
value: value,
|
value: value,
|
||||||
raw: value,
|
raw: value.toString(),
|
||||||
regex: {
|
regex: {
|
||||||
pattern: M.value.raw_source,
|
pattern: value.source,
|
||||||
flags: flags
|
flags: value.toString().match(/[gimuy]*$/)[0]
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
@@ -477,7 +478,7 @@
|
|||||||
endpos : range ? range[0] : moznode.start,
|
endpos : range ? range[0] : moznode.start,
|
||||||
raw : raw_token(moznode),
|
raw : raw_token(moznode),
|
||||||
});
|
});
|
||||||
}
|
};
|
||||||
|
|
||||||
function my_end_token(moznode) {
|
function my_end_token(moznode) {
|
||||||
var loc = moznode.loc, end = loc && loc.end;
|
var loc = moznode.loc, end = loc && loc.end;
|
||||||
@@ -492,7 +493,7 @@
|
|||||||
endpos : range ? range[1] : moznode.end,
|
endpos : range ? range[1] : moznode.end,
|
||||||
raw : raw_token(moznode),
|
raw : raw_token(moznode),
|
||||||
});
|
});
|
||||||
}
|
};
|
||||||
|
|
||||||
function map(moztype, mytype, propmap) {
|
function map(moztype, mytype, propmap) {
|
||||||
var moz_to_me = "function From_Moz_" + moztype + "(M){\n";
|
var moz_to_me = "function From_Moz_" + moztype + "(M){\n";
|
||||||
@@ -504,7 +505,7 @@
|
|||||||
me_to_moz += "return {\n" +
|
me_to_moz += "return {\n" +
|
||||||
"type: " + JSON.stringify(moztype);
|
"type: " + JSON.stringify(moztype);
|
||||||
|
|
||||||
if (propmap) propmap.split(/\s*,\s*/).forEach(function(prop) {
|
if (propmap) propmap.split(/\s*,\s*/).forEach(function(prop){
|
||||||
var m = /([a-z0-9$_]+)(=|@|>|%)([a-z0-9$_]+)/i.exec(prop);
|
var m = /([a-z0-9$_]+)(=|@|>|%)([a-z0-9$_]+)/i.exec(prop);
|
||||||
if (!m) throw new Error("Can't understand property map: " + prop);
|
if (!m) throw new Error("Can't understand property map: " + prop);
|
||||||
var moz = m[1], how = m[2], my = m[3];
|
var moz = m[1], how = m[2], my = m[3];
|
||||||
@@ -547,7 +548,7 @@
|
|||||||
);
|
);
|
||||||
MOZ_TO_ME[moztype] = moz_to_me;
|
MOZ_TO_ME[moztype] = moz_to_me;
|
||||||
def_to_moz(mytype, me_to_moz);
|
def_to_moz(mytype, me_to_moz);
|
||||||
}
|
};
|
||||||
|
|
||||||
var FROM_MOZ_STACK = null;
|
var FROM_MOZ_STACK = null;
|
||||||
|
|
||||||
@@ -556,28 +557,13 @@
|
|||||||
var ret = node != null ? MOZ_TO_ME[node.type](node) : null;
|
var ret = node != null ? MOZ_TO_ME[node.type](node) : null;
|
||||||
FROM_MOZ_STACK.pop();
|
FROM_MOZ_STACK.pop();
|
||||||
return ret;
|
return ret;
|
||||||
}
|
};
|
||||||
|
|
||||||
AST_Node.from_mozilla_ast = function(node) {
|
AST_Node.from_mozilla_ast = function(node){
|
||||||
var save_stack = FROM_MOZ_STACK;
|
var save_stack = FROM_MOZ_STACK;
|
||||||
FROM_MOZ_STACK = [];
|
FROM_MOZ_STACK = [];
|
||||||
var ast = from_moz(node);
|
var ast = from_moz(node);
|
||||||
FROM_MOZ_STACK = save_stack;
|
FROM_MOZ_STACK = save_stack;
|
||||||
ast.walk(new TreeWalker(function(node) {
|
|
||||||
if (node instanceof AST_LabelRef) {
|
|
||||||
for (var level = 0, parent; parent = this.parent(level); level++) {
|
|
||||||
if (parent instanceof AST_Scope) break;
|
|
||||||
if (parent instanceof AST_LabeledStatement && parent.label.name == node.name) {
|
|
||||||
node.thedef = parent.label;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (!node.thedef) {
|
|
||||||
var s = node.start;
|
|
||||||
js_error("Undefined label " + node.name, s.file, s.line, s.col, s.pos);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}));
|
|
||||||
return ast;
|
return ast;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -597,24 +583,24 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
return moznode;
|
return moznode;
|
||||||
}
|
};
|
||||||
|
|
||||||
function def_to_moz(mytype, handler) {
|
function def_to_moz(mytype, handler) {
|
||||||
mytype.DEFMETHOD("to_mozilla_ast", function() {
|
mytype.DEFMETHOD("to_mozilla_ast", function() {
|
||||||
return set_moz_loc(this, handler(this));
|
return set_moz_loc(this, handler(this));
|
||||||
});
|
});
|
||||||
}
|
};
|
||||||
|
|
||||||
function to_moz(node) {
|
function to_moz(node) {
|
||||||
return node != null ? node.to_mozilla_ast() : null;
|
return node != null ? node.to_mozilla_ast() : null;
|
||||||
}
|
};
|
||||||
|
|
||||||
function to_moz_block(node) {
|
function to_moz_block(node) {
|
||||||
return {
|
return {
|
||||||
type: "BlockStatement",
|
type: "BlockStatement",
|
||||||
body: node.body.map(to_moz)
|
body: node.body.map(to_moz)
|
||||||
};
|
};
|
||||||
}
|
};
|
||||||
|
|
||||||
function to_moz_scope(type, node) {
|
function to_moz_scope(type, node) {
|
||||||
var body = node.body.map(to_moz);
|
var body = node.body.map(to_moz);
|
||||||
@@ -625,5 +611,5 @@
|
|||||||
type: type,
|
type: type,
|
||||||
body: body
|
body: body
|
||||||
};
|
};
|
||||||
}
|
};
|
||||||
})();
|
})();
|
||||||
|
|||||||
913
lib/output.js
913
lib/output.js
File diff suppressed because it is too large
Load Diff
1892
lib/parse.js
1892
lib/parse.js
File diff suppressed because one or more lines are too long
@@ -44,6 +44,16 @@
|
|||||||
"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",
|
||||||
@@ -55,8 +65,16 @@ 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
|
Date, RegExp, objects.Symbol, ArrayBuffer,
|
||||||
].forEach(function(ctor) {
|
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){
|
||||||
Object.getOwnPropertyNames(ctor).map(add);
|
Object.getOwnPropertyNames(ctor).map(add);
|
||||||
if (ctor.prototype) {
|
if (ctor.prototype) {
|
||||||
Object.getOwnPropertyNames(ctor.prototype).map(add);
|
Object.getOwnPropertyNames(ctor.prototype).map(add);
|
||||||
@@ -75,6 +93,8 @@ 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);
|
||||||
}
|
}
|
||||||
@@ -136,7 +156,7 @@ function mangle_properties(ast, options) {
|
|||||||
var unmangleable = [];
|
var unmangleable = [];
|
||||||
|
|
||||||
// step 1: find candidates to mangle
|
// step 1: find candidates to mangle
|
||||||
ast.walk(new TreeWalker(function(node) {
|
ast.walk(new TreeWalker(function(node){
|
||||||
if (node instanceof AST_ObjectKeyVal) {
|
if (node instanceof AST_ObjectKeyVal) {
|
||||||
add(node.key);
|
add(node.key);
|
||||||
}
|
}
|
||||||
@@ -150,14 +170,10 @@ function mangle_properties(ast, options) {
|
|||||||
else if (node instanceof AST_Sub) {
|
else if (node instanceof AST_Sub) {
|
||||||
addStrings(node.property, add);
|
addStrings(node.property, add);
|
||||||
}
|
}
|
||||||
else if (node instanceof AST_Call
|
|
||||||
&& node.expression.print_to_string() == "Object.defineProperty") {
|
|
||||||
addStrings(node.args[1], add);
|
|
||||||
}
|
|
||||||
}));
|
}));
|
||||||
|
|
||||||
// step 2: transform the tree, renaming properties
|
// step 2: transform the tree, renaming properties
|
||||||
return ast.transform(new TreeTransformer(function(node) {
|
return ast.transform(new TreeTransformer(function(node){
|
||||||
if (node instanceof AST_ObjectKeyVal) {
|
if (node instanceof AST_ObjectKeyVal) {
|
||||||
node.key = mangle(node.key);
|
node.key = mangle(node.key);
|
||||||
}
|
}
|
||||||
@@ -171,10 +187,6 @@ function mangle_properties(ast, options) {
|
|||||||
else if (!options.keep_quoted && node instanceof AST_Sub) {
|
else if (!options.keep_quoted && node instanceof AST_Sub) {
|
||||||
node.property = mangleStrings(node.property);
|
node.property = mangleStrings(node.property);
|
||||||
}
|
}
|
||||||
else if (node instanceof AST_Call
|
|
||||||
&& node.expression.print_to_string() == "Object.defineProperty") {
|
|
||||||
node.args[1] = mangleStrings(node.args[1]);
|
|
||||||
}
|
|
||||||
}));
|
}));
|
||||||
|
|
||||||
// only function declarations after this line
|
// only function declarations after this line
|
||||||
@@ -234,7 +246,7 @@ function mangle_properties(ast, options) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function mangleStrings(node) {
|
function mangleStrings(node) {
|
||||||
return node.transform(new TreeTransformer(function(node) {
|
return node.transform(new TreeTransformer(function(node){
|
||||||
if (node instanceof AST_Sequence) {
|
if (node instanceof AST_Sequence) {
|
||||||
var last = node.expressions.length - 1;
|
var last = node.expressions.length - 1;
|
||||||
node.expressions[last] = mangleStrings(node.expressions[last]);
|
node.expressions[last] = mangleStrings(node.expressions[last]);
|
||||||
|
|||||||
398
lib/scope.js
398
lib/scope.js
@@ -52,10 +52,11 @@ function SymbolDef(scope, orig, init) {
|
|||||||
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++;
|
||||||
}
|
};
|
||||||
|
|
||||||
SymbolDef.next_id = 1;
|
SymbolDef.next_id = 1;
|
||||||
|
|
||||||
@@ -63,24 +64,33 @@ SymbolDef.prototype = {
|
|||||||
unmangleable: function(options) {
|
unmangleable: function(options) {
|
||||||
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.pinned()
|
|| (!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;
|
||||||
if (this.global && cache && cache.has(this.name)) {
|
if (this.global && cache && cache.has(this.name)) {
|
||||||
this.mangled_name = cache.get(this.name);
|
this.mangled_name = cache.get(this.name);
|
||||||
} else if (!this.mangled_name && !this.unmangleable(options)) {
|
}
|
||||||
|
else if (!this.mangled_name && !this.unmangleable(options)) {
|
||||||
|
var s = this.scope;
|
||||||
|
var sym = this.orig[0];
|
||||||
|
if (options.ie8 && sym instanceof AST_SymbolLambda)
|
||||||
|
s = s.parent_scope;
|
||||||
var def;
|
var def;
|
||||||
if (def = this.redefined()) {
|
if (def = this.redefined()) {
|
||||||
this.mangled_name = def.mangled_name || def.name;
|
this.mangled_name = def.mangled_name || def.name;
|
||||||
} else {
|
} else
|
||||||
this.mangled_name = next_mangled_name(this.scope, options, this);
|
this.mangled_name = s.next_mangled(options, this);
|
||||||
}
|
|
||||||
if (this.global && cache) {
|
if (this.global && cache) {
|
||||||
cache.set(this.name, this.mangled_name);
|
cache.set(this.name, this.mangled_name);
|
||||||
}
|
}
|
||||||
@@ -91,35 +101,68 @@ SymbolDef.prototype = {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
AST_Toplevel.DEFMETHOD("figure_out_scope", function(options) {
|
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
|
||||||
var self = this;
|
var self = this;
|
||||||
var scope = self.parent_scope = null;
|
var scope = self.parent_scope = null;
|
||||||
|
var labels = new Dictionary();
|
||||||
var defun = null;
|
var defun = null;
|
||||||
var tw = new TreeWalker(function(node, descend) {
|
var in_destructuring = null;
|
||||||
if (node instanceof AST_Catch) {
|
var for_scopes = [];
|
||||||
|
var tw = new TreeWalker(function(node, descend){
|
||||||
|
if (node.is_block_scope()) {
|
||||||
var save_scope = scope;
|
var save_scope = scope;
|
||||||
scope = new AST_Scope(node);
|
node.block_scope = scope = new AST_Scope(node);
|
||||||
scope.init_scope_vars(save_scope);
|
scope.init_scope_vars(save_scope);
|
||||||
|
if (!(node instanceof AST_Scope)) {
|
||||||
|
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;
|
||||||
var save_defun = defun;
|
var save_defun = defun;
|
||||||
|
var save_labels = labels;
|
||||||
defun = scope = node;
|
defun = scope = node;
|
||||||
|
labels = new Dictionary();
|
||||||
descend();
|
descend();
|
||||||
scope = save_scope;
|
scope = save_scope;
|
||||||
defun = save_defun;
|
defun = save_defun;
|
||||||
|
labels = save_labels;
|
||||||
return true; // don't descend again in TreeWalker
|
return true; // don't descend again in TreeWalker
|
||||||
}
|
}
|
||||||
|
if (node instanceof AST_LabeledStatement) {
|
||||||
|
var l = node.label;
|
||||||
|
if (labels.has(l.name)) {
|
||||||
|
throw new Error(string_template("Label {name} defined twice", l));
|
||||||
|
}
|
||||||
|
labels.set(l.name, l);
|
||||||
|
descend();
|
||||||
|
labels.del(l.name);
|
||||||
|
return true; // no descend again
|
||||||
|
}
|
||||||
if (node instanceof AST_With) {
|
if (node instanceof AST_With) {
|
||||||
for (var s = scope; s; s = s.parent_scope)
|
for (var s = scope; s; s = s.parent_scope)
|
||||||
s.uses_with = true;
|
s.uses_with = true;
|
||||||
@@ -132,37 +175,101 @@ AST_Toplevel.DEFMETHOD("figure_out_scope", function(options) {
|
|||||||
node.thedef = node;
|
node.thedef = node;
|
||||||
node.references = [];
|
node.references = [];
|
||||||
}
|
}
|
||||||
if (node instanceof AST_SymbolDefun || options.ie8 && node instanceof AST_SymbolLambda) {
|
if (node instanceof AST_SymbolLambda) {
|
||||||
|
defun.def_function(node, node.name == "arguments" ? undefined : defun);
|
||||||
|
}
|
||||||
|
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
|
||||||
// the parent scope. The reason is that we enter a new
|
// the parent scope. The reason is that we enter a new
|
||||||
// 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.
|
||||||
(node.scope = defun.parent_scope).def_function(node, defun);
|
mark_export((node.scope = defun.parent_scope.get_defun_scope()).def_function(node, defun), 1);
|
||||||
}
|
}
|
||||||
else if (node instanceof AST_SymbolLambda) {
|
else if (node instanceof AST_SymbolClass) {
|
||||||
defun.def_function(node, node.name == "arguments" ? undefined : defun);
|
mark_export(defun.def_variable(node, defun), 1);
|
||||||
}
|
}
|
||||||
else if (node instanceof AST_SymbolVar) {
|
else if (node instanceof AST_SymbolImport) {
|
||||||
defun.def_variable(node, node.TYPE == "SymbolVar" ? null : undefined);
|
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, defun), 1);
|
||||||
|
}
|
||||||
|
else if (node instanceof AST_SymbolVar
|
||||||
|
|| node instanceof AST_SymbolLet
|
||||||
|
|| node instanceof AST_SymbolConst) {
|
||||||
|
var def;
|
||||||
|
if (node instanceof AST_SymbolBlockDeclaration) {
|
||||||
|
def = scope.def_variable(node, null);
|
||||||
|
} else {
|
||||||
|
def = defun.def_variable(node, node.TYPE == "SymbolVar" ? null : undefined);
|
||||||
|
}
|
||||||
|
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);
|
||||||
if (node.thedef !== def) {
|
if (node.thedef !== def) {
|
||||||
node.thedef = def;
|
node.thedef = def;
|
||||||
|
node.reference(options);
|
||||||
}
|
}
|
||||||
node.reference(options);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (node instanceof AST_SymbolCatch) {
|
else if (node instanceof AST_SymbolCatch) {
|
||||||
scope.def_variable(node).defun = defun;
|
scope.def_variable(node).defun = defun;
|
||||||
}
|
}
|
||||||
|
else if (node instanceof AST_LabelRef) {
|
||||||
|
var sym = labels.get(node.name);
|
||||||
|
if (!sym) throw new Error(string_template("Undefined label {name} [{line},{col}]", {
|
||||||
|
name: node.name,
|
||||||
|
line: node.start.line,
|
||||||
|
col: node.start.col
|
||||||
|
}));
|
||||||
|
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);
|
||||||
|
|
||||||
// pass 2: find back references and eval
|
// pass 2: find back references and eval
|
||||||
self.globals = new Dictionary();
|
self.globals = new Dictionary();
|
||||||
var tw = new TreeWalker(function(node, descend) {
|
var tw = new TreeWalker(function(node, descend){
|
||||||
if (node instanceof AST_LoopControl && node.label) {
|
if (node instanceof AST_LoopControl && node.label) {
|
||||||
node.label.thedef.references.push(node);
|
node.label.thedef.references.push(node);
|
||||||
return true;
|
return true;
|
||||||
@@ -174,14 +281,19 @@ AST_Toplevel.DEFMETHOD("figure_out_scope", function(options) {
|
|||||||
s.uses_eval = true;
|
s.uses_eval = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
var sym = node.scope.find_variable(name);
|
var sym;
|
||||||
if (!sym) {
|
if (tw.parent() instanceof AST_NameMapping && tw.parent(1).module_name
|
||||||
|
|| !(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;
|
||||||
}
|
}
|
||||||
node.thedef = sym;
|
node.thedef = sym;
|
||||||
node.reference(options);
|
node.reference(options);
|
||||||
|
if (node.scope.is_block_scope()
|
||||||
|
&& !(sym.orig[0] instanceof AST_SymbolBlockDeclaration)) {
|
||||||
|
node.scope = node.scope.get_defun_scope();
|
||||||
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
// ensure mangling works if catch reuses a scope variable
|
// ensure mangling works if catch reuses a scope variable
|
||||||
@@ -215,9 +327,22 @@ 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);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
AST_Toplevel.DEFMETHOD("def_global", function(node) {
|
AST_Toplevel.DEFMETHOD("def_global", function(node){
|
||||||
var globals = this.globals, name = node.name;
|
var globals = this.globals, name = node.name;
|
||||||
if (globals.has(name)) {
|
if (globals.has(name)) {
|
||||||
return globals.get(name);
|
return globals.get(name);
|
||||||
@@ -230,7 +355,7 @@ AST_Toplevel.DEFMETHOD("def_global", function(node) {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
AST_Scope.DEFMETHOD("init_scope_vars", function(parent_scope) {
|
AST_Scope.DEFMETHOD("init_scope_vars", function(parent_scope){
|
||||||
this.variables = new Dictionary(); // map name to AST_SymbolVar (variables defined in this scope; includes functions)
|
this.variables = new Dictionary(); // map name to AST_SymbolVar (variables defined in this scope; includes functions)
|
||||||
this.functions = new Dictionary(); // map name to AST_SymbolDefun (functions defined in this scope)
|
this.functions = new Dictionary(); // map name to AST_SymbolDefun (functions defined in this scope)
|
||||||
this.uses_with = false; // will be set to true if this or some nested scope uses the `with` statement
|
this.uses_with = false; // will be set to true if this or some nested scope uses the `with` statement
|
||||||
@@ -240,7 +365,15 @@ 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_Lambda.DEFMETHOD("init_scope_vars", function() {
|
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_Scope.prototype.init_scope_vars.apply(this, arguments);
|
AST_Scope.prototype.init_scope_vars.apply(this, arguments);
|
||||||
this.uses_arguments = false;
|
this.uses_arguments = false;
|
||||||
this.def_variable(new AST_SymbolFunarg({
|
this.def_variable(new AST_SymbolFunarg({
|
||||||
@@ -270,20 +403,20 @@ AST_Symbol.DEFMETHOD("reference", function(options) {
|
|||||||
this.mark_enclosed(options);
|
this.mark_enclosed(options);
|
||||||
});
|
});
|
||||||
|
|
||||||
AST_Scope.DEFMETHOD("find_variable", function(name) {
|
AST_Scope.DEFMETHOD("find_variable", function(name){
|
||||||
if (name instanceof AST_Symbol) name = name.name;
|
if (name instanceof AST_Symbol) name = name.name;
|
||||||
return this.variables.get(name)
|
return this.variables.get(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, init) {
|
AST_Scope.DEFMETHOD("def_function", function(symbol, init){
|
||||||
var def = this.def_variable(symbol, init);
|
var def = this.def_variable(symbol, init);
|
||||||
if (!def.init || def.init instanceof AST_Defun) def.init = init;
|
if (!def.init) 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, init) {
|
AST_Scope.DEFMETHOD("def_variable", function(symbol, init){
|
||||||
var def = this.variables.get(symbol.name);
|
var def = this.variables.get(symbol.name);
|
||||||
if (def) {
|
if (def) {
|
||||||
def.orig.push(symbol);
|
def.orig.push(symbol);
|
||||||
@@ -298,61 +431,58 @@ AST_Scope.DEFMETHOD("def_variable", function(symbol, init) {
|
|||||||
return symbol.thedef = def;
|
return symbol.thedef = def;
|
||||||
});
|
});
|
||||||
|
|
||||||
function names_in_use(scope, options) {
|
function next_mangled(scope, options) {
|
||||||
var names = scope.names_in_use;
|
var ext = scope.enclosed;
|
||||||
if (!names) {
|
out: while (true) {
|
||||||
scope.names_in_use = names = Object.create(scope.mangled_names || null);
|
var m = base54(++scope.cname);
|
||||||
scope.cname_holes = [];
|
if (!is_identifier(m)) continue; // skip over "do"
|
||||||
scope.enclosed.forEach(function(def) {
|
|
||||||
if (def.unmangleable(options)) names[def.name] = true;
|
// https://github.com/mishoo/UglifyJS2/issues/242 -- do not
|
||||||
});
|
// shadow a name reserved from mangling.
|
||||||
|
if (member(m, options.reserved)) continue;
|
||||||
|
|
||||||
|
// we must ensure that the mangled name does not shadow a name
|
||||||
|
// from some parent scope that is referenced in this or in
|
||||||
|
// inner scopes.
|
||||||
|
for (var i = ext.length; --i >= 0;) {
|
||||||
|
var sym = ext[i];
|
||||||
|
var name = sym.mangled_name || (sym.unmangleable(options) && sym.name);
|
||||||
|
if (m == name) continue out;
|
||||||
|
}
|
||||||
|
return m;
|
||||||
}
|
}
|
||||||
return names;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function next_mangled_name(scope, options, def) {
|
AST_Scope.DEFMETHOD("next_mangled", function(options){
|
||||||
var in_use = names_in_use(scope, options);
|
return next_mangled(this, options);
|
||||||
var holes = scope.cname_holes;
|
});
|
||||||
var names = Object.create(null);
|
|
||||||
|
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){
|
||||||
// #179, #326
|
// #179, #326
|
||||||
// in Safari strict mode, something like (function x(x){...}) is a syntax error;
|
// in Safari strict mode, something like (function x(x){...}) is a syntax error;
|
||||||
// a function expression's argument cannot shadow the function expression's name
|
// a function expression's argument cannot shadow the function expression's name
|
||||||
if (scope instanceof AST_Function && scope.name && def.orig[0] instanceof AST_SymbolFunarg) {
|
|
||||||
var tricky_def = scope.name.definition();
|
|
||||||
// the function's mangled_name is null when keep_fnames is true
|
|
||||||
names[tricky_def.mangled_name || tricky_def.name] = true;
|
|
||||||
}
|
|
||||||
var scopes = [ scope ];
|
|
||||||
def.references.forEach(function(sym) {
|
|
||||||
var scope = sym.scope;
|
|
||||||
do {
|
|
||||||
if (scopes.indexOf(scope) < 0) {
|
|
||||||
for (var name in names_in_use(scope, options)) {
|
|
||||||
names[name] = true;
|
|
||||||
}
|
|
||||||
scopes.push(scope);
|
|
||||||
} else break;
|
|
||||||
} while (scope = scope.parent_scope);
|
|
||||||
});
|
|
||||||
var name;
|
|
||||||
for (var i = 0, len = holes.length; i < len; i++) {
|
|
||||||
name = base54(holes[i]);
|
|
||||||
if (names[name]) continue;
|
|
||||||
holes.splice(i, 1);
|
|
||||||
scope.names_in_use[name] = true;
|
|
||||||
return name;
|
|
||||||
}
|
|
||||||
while (true) {
|
|
||||||
name = base54(++scope.cname);
|
|
||||||
if (in_use[name] || !is_identifier(name) || options.reserved.has[name]) continue;
|
|
||||||
if (!names[name]) break;
|
|
||||||
holes.push(scope.cname);
|
|
||||||
}
|
|
||||||
scope.names_in_use[name] = true;
|
|
||||||
return name;
|
|
||||||
}
|
|
||||||
|
|
||||||
AST_Symbol.DEFMETHOD("unmangleable", function(options) {
|
var tricky_def = def.orig[0] instanceof AST_SymbolFunarg && this.name && this.name.definition();
|
||||||
|
|
||||||
|
// the function's mangled_name is null when keep_fnames is true
|
||||||
|
var tricky_name = tricky_def ? tricky_def.mangled_name || tricky_def.name : null;
|
||||||
|
|
||||||
|
while (true) {
|
||||||
|
var name = next_mangled(this, options);
|
||||||
|
if (!tricky_name || tricky_name != name)
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
AST_Symbol.DEFMETHOD("unmangleable", function(options){
|
||||||
var def = this.definition();
|
var def = this.definition();
|
||||||
return !def || def.unmangleable(options);
|
return !def || def.unmangleable(options);
|
||||||
});
|
});
|
||||||
@@ -360,22 +490,24 @@ AST_Symbol.DEFMETHOD("unmangleable", function(options) {
|
|||||||
// labels are always mangleable
|
// labels are always mangleable
|
||||||
AST_Label.DEFMETHOD("unmangleable", return_false);
|
AST_Label.DEFMETHOD("unmangleable", return_false);
|
||||||
|
|
||||||
AST_Symbol.DEFMETHOD("unreferenced", function() {
|
AST_Symbol.DEFMETHOD("unreferenced", function(){
|
||||||
return !this.definition().references.length && !this.scope.pinned();
|
return this.definition().references.length == 0
|
||||||
|
&& !(this.scope.uses_eval || this.scope.uses_with);
|
||||||
});
|
});
|
||||||
|
|
||||||
AST_Symbol.DEFMETHOD("definition", function() {
|
AST_Symbol.DEFMETHOD("definition", function(){
|
||||||
return this.thedef;
|
return this.thedef;
|
||||||
});
|
});
|
||||||
|
|
||||||
AST_Symbol.DEFMETHOD("global", function() {
|
AST_Symbol.DEFMETHOD("global", function(){
|
||||||
return this.definition().global;
|
return this.definition().global;
|
||||||
});
|
});
|
||||||
|
|
||||||
function _default_mangler_options(options) {
|
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,
|
||||||
@@ -383,28 +515,30 @@ function _default_mangler_options(options) {
|
|||||||
if (!Array.isArray(options.reserved)) options.reserved = [];
|
if (!Array.isArray(options.reserved)) options.reserved = [];
|
||||||
// Never mangle arguments
|
// Never mangle arguments
|
||||||
push_uniq(options.reserved, "arguments");
|
push_uniq(options.reserved, "arguments");
|
||||||
options.reserved.has = makePredicate(options.reserved);
|
|
||||||
return options;
|
return options;
|
||||||
}
|
});
|
||||||
|
|
||||||
AST_Toplevel.DEFMETHOD("mangle_names", function(options) {
|
AST_Toplevel.DEFMETHOD("mangle_names", function(options){
|
||||||
options = _default_mangler_options(options);
|
options = this._default_mangler_options(options);
|
||||||
|
|
||||||
// We only need to mangle declaration nodes. Special logic wired
|
// We only need to mangle declaration nodes. Special logic wired
|
||||||
// into the code generator will display the mangled name if it's
|
// into the code generator will display the mangled name if it's
|
||||||
// present (and for AST_SymbolRef-s it'll use the mangled name of
|
// present (and for AST_SymbolRef-s it'll use the mangled name of
|
||||||
// the AST_SymbolDeclaration that it points to).
|
// the AST_SymbolDeclaration that it points to).
|
||||||
var lname = -1;
|
var lname = -1;
|
||||||
|
var to_mangle = [];
|
||||||
|
|
||||||
if (options.cache && options.cache.props) {
|
var mangled_names = this.mangled_names = [];
|
||||||
var mangled_names = this.mangled_names = Object.create(null);
|
if (options.cache) {
|
||||||
options.cache.props.each(function(mangled_name) {
|
this.globals.each(collect);
|
||||||
mangled_names[mangled_name] = true;
|
if (options.cache.props) {
|
||||||
});
|
options.cache.props.each(function(mangled_name) {
|
||||||
|
push_uniq(mangled_names, mangled_name);
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var redefined = [];
|
var tw = new TreeWalker(function(node, descend){
|
||||||
var tw = new TreeWalker(function(node, descend) {
|
|
||||||
if (node instanceof AST_LabeledStatement) {
|
if (node instanceof AST_LabeledStatement) {
|
||||||
// lname is incremented when we get to the AST_Label
|
// lname is incremented when we get to the AST_Label
|
||||||
var save_nesting = lname;
|
var save_nesting = lname;
|
||||||
@@ -413,12 +547,12 @@ AST_Toplevel.DEFMETHOD("mangle_names", function(options) {
|
|||||||
return true; // don't descend again in TreeWalker
|
return true; // don't descend again in TreeWalker
|
||||||
}
|
}
|
||||||
if (node instanceof AST_Scope) {
|
if (node instanceof AST_Scope) {
|
||||||
descend();
|
node.variables.each(collect);
|
||||||
if (options.cache && node instanceof AST_Toplevel) {
|
return;
|
||||||
node.globals.each(mangle);
|
}
|
||||||
}
|
if (node.is_block_scope()) {
|
||||||
node.variables.each(mangle);
|
node.block_scope.variables.each(collect);
|
||||||
return true;
|
return;
|
||||||
}
|
}
|
||||||
if (node instanceof AST_Label) {
|
if (node instanceof AST_Label) {
|
||||||
var name;
|
var name;
|
||||||
@@ -426,31 +560,18 @@ AST_Toplevel.DEFMETHOD("mangle_names", function(options) {
|
|||||||
node.mangled_name = name;
|
node.mangled_name = name;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (!options.ie8 && node instanceof AST_Catch) {
|
if (!options.ie8 && node instanceof AST_SymbolCatch) {
|
||||||
var def = node.argname.definition();
|
to_mangle.push(node.definition());
|
||||||
var redef = def.redefined();
|
return;
|
||||||
if (redef) {
|
|
||||||
redefined.push(def);
|
|
||||||
reference(node.argname);
|
|
||||||
def.references.forEach(reference);
|
|
||||||
}
|
|
||||||
descend();
|
|
||||||
if (!redef) mangle(def);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
function reference(sym) {
|
|
||||||
sym.thedef = redef;
|
|
||||||
sym.reference(options);
|
|
||||||
sym.thedef = def;
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
this.walk(tw);
|
this.walk(tw);
|
||||||
redefined.forEach(mangle);
|
to_mangle.forEach(function(def){ def.mangle(options) });
|
||||||
|
|
||||||
function mangle(def) {
|
function collect(symbol) {
|
||||||
if (options.reserved.has[def.name]) return;
|
if (!member(symbol.name, options.reserved)) {
|
||||||
def.mangle(options);
|
to_mangle.push(symbol);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -480,7 +601,7 @@ AST_Toplevel.DEFMETHOD("find_colliding_names", function(options) {
|
|||||||
AST_Toplevel.DEFMETHOD("expand_names", function(options) {
|
AST_Toplevel.DEFMETHOD("expand_names", function(options) {
|
||||||
base54.reset();
|
base54.reset();
|
||||||
base54.sort();
|
base54.sort();
|
||||||
options = _default_mangler_options(options);
|
options = this._default_mangler_options(options);
|
||||||
var avoid = this.find_colliding_names(options);
|
var avoid = this.find_colliding_names(options);
|
||||||
var cname = 0;
|
var cname = 0;
|
||||||
this.globals.each(rename);
|
this.globals.each(rename);
|
||||||
@@ -500,7 +621,7 @@ AST_Toplevel.DEFMETHOD("expand_names", function(options) {
|
|||||||
function rename(def) {
|
function rename(def) {
|
||||||
if (def.global && options.cache) return;
|
if (def.global && options.cache) return;
|
||||||
if (def.unmangleable(options)) return;
|
if (def.unmangleable(options)) return;
|
||||||
if (options.reserved.has[def.name]) return;
|
if (member(def.name, options.reserved)) return;
|
||||||
var d = def.redefined();
|
var d = def.redefined();
|
||||||
def.name = d ? d.name : next_name();
|
def.name = d ? d.name : next_name();
|
||||||
def.orig.forEach(function(sym) {
|
def.orig.forEach(function(sym) {
|
||||||
@@ -517,9 +638,8 @@ AST_Sequence.DEFMETHOD("tail_node", function() {
|
|||||||
return this.expressions[this.expressions.length - 1];
|
return this.expressions[this.expressions.length - 1];
|
||||||
});
|
});
|
||||||
|
|
||||||
AST_Toplevel.DEFMETHOD("compute_char_frequency", function(options) {
|
AST_Toplevel.DEFMETHOD("compute_char_frequency", function(options){
|
||||||
options = _default_mangler_options(options);
|
options = this._default_mangler_options(options);
|
||||||
base54.reset();
|
|
||||||
try {
|
try {
|
||||||
AST_Node.prototype.print = function(stream, force_parens) {
|
AST_Node.prototype.print = function(stream, force_parens) {
|
||||||
this._print(stream, force_parens);
|
this._print(stream, force_parens);
|
||||||
@@ -552,21 +672,17 @@ AST_Toplevel.DEFMETHOD("compute_char_frequency", function(options) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
var base54 = (function() {
|
var base54 = (function() {
|
||||||
var freq = Object.create(null);
|
var leading = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ$_".split("");
|
||||||
function init(chars) {
|
var digits = "0123456789".split("");
|
||||||
var array = [];
|
|
||||||
for (var i = 0, len = chars.length; i < len; i++) {
|
|
||||||
var ch = chars[i];
|
|
||||||
array.push(ch);
|
|
||||||
freq[ch] = -1e-2 * i;
|
|
||||||
}
|
|
||||||
return array;
|
|
||||||
}
|
|
||||||
var digits = init("0123456789");
|
|
||||||
var leading = init("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ$_");
|
|
||||||
var chars, frequency;
|
var chars, frequency;
|
||||||
function reset() {
|
function reset() {
|
||||||
frequency = Object.create(freq);
|
frequency = Object.create(null);
|
||||||
|
leading.forEach(function(ch) {
|
||||||
|
frequency[ch] = 0;
|
||||||
|
});
|
||||||
|
digits.forEach(function(ch) {
|
||||||
|
frequency[ch] = 0;
|
||||||
|
});
|
||||||
}
|
}
|
||||||
base54.consider = function(str, delta) {
|
base54.consider = function(str, delta) {
|
||||||
for (var i = str.length; --i >= 0;) {
|
for (var i = str.length; --i >= 0;) {
|
||||||
@@ -577,7 +693,7 @@ var base54 = (function() {
|
|||||||
return frequency[b] - frequency[a];
|
return frequency[b] - frequency[a];
|
||||||
}
|
}
|
||||||
base54.sort = function() {
|
base54.sort = function() {
|
||||||
chars = leading.sort(compare).concat(digits.sort(compare));
|
chars = mergeSort(leading, compare).concat(mergeSort(digits, compare));
|
||||||
};
|
};
|
||||||
base54.reset = reset;
|
base54.reset = reset;
|
||||||
reset();
|
reset();
|
||||||
@@ -591,6 +707,6 @@ var base54 = (function() {
|
|||||||
base = 64;
|
base = 64;
|
||||||
} while (num > 0);
|
} while (num > 0);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
};
|
||||||
return base54;
|
return base54;
|
||||||
})();
|
})();
|
||||||
|
|||||||
@@ -46,59 +46,52 @@
|
|||||||
// a small wrapper around fitzgen's source-map library
|
// a small wrapper around fitzgen's source-map library
|
||||||
function SourceMap(options) {
|
function SourceMap(options) {
|
||||||
options = defaults(options, {
|
options = defaults(options, {
|
||||||
file: null,
|
file : null,
|
||||||
root: null,
|
root : null,
|
||||||
orig: null,
|
orig : null,
|
||||||
orig_line_diff: 0,
|
|
||||||
dest_line_diff: 0,
|
orig_line_diff : 0,
|
||||||
}, true);
|
dest_line_diff : 0,
|
||||||
var generator = new MOZ_SourceMap.SourceMapGenerator({
|
|
||||||
file: options.file,
|
|
||||||
sourceRoot: options.root
|
|
||||||
});
|
});
|
||||||
var maps = options.orig && Object.create(null);
|
var generator = new MOZ_SourceMap.SourceMapGenerator({
|
||||||
if (maps) for (var source in options.orig) {
|
file : options.file,
|
||||||
var map = new MOZ_SourceMap.SourceMapConsumer(options.orig[source]);
|
sourceRoot : options.root
|
||||||
if (Array.isArray(options.orig[source].sources)) {
|
});
|
||||||
map._sources.toArray().forEach(function(source) {
|
var orig_map = options.orig && new MOZ_SourceMap.SourceMapConsumer(options.orig);
|
||||||
var sourceContent = map.sourceContentFor(source, true);
|
|
||||||
if (sourceContent) generator.setSourceContent(source, sourceContent);
|
if (orig_map && Array.isArray(options.orig.sources)) {
|
||||||
});
|
orig_map._sources.toArray().forEach(function(source) {
|
||||||
}
|
var sourceContent = orig_map.sourceContentFor(source, true);
|
||||||
maps[source] = map;
|
if (sourceContent) {
|
||||||
}
|
generator.setSourceContent(source, sourceContent);
|
||||||
return {
|
|
||||||
add: function(source, gen_line, gen_col, orig_line, orig_col, name) {
|
|
||||||
var map = maps && maps[source];
|
|
||||||
if (map) {
|
|
||||||
var info = map.originalPositionFor({
|
|
||||||
line: orig_line,
|
|
||||||
column: orig_col
|
|
||||||
});
|
|
||||||
if (info.source === null) return;
|
|
||||||
source = info.source;
|
|
||||||
orig_line = info.line;
|
|
||||||
orig_col = info.column;
|
|
||||||
name = info.name || name;
|
|
||||||
}
|
}
|
||||||
generator.addMapping({
|
});
|
||||||
name: name,
|
}
|
||||||
source: source,
|
|
||||||
generated: {
|
function add(source, gen_line, gen_col, orig_line, orig_col, name) {
|
||||||
line: gen_line + options.dest_line_diff,
|
if (orig_map) {
|
||||||
column: gen_col
|
var info = orig_map.originalPositionFor({
|
||||||
},
|
line: orig_line,
|
||||||
original: {
|
column: orig_col
|
||||||
line: orig_line + options.orig_line_diff,
|
|
||||||
column: orig_col
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
},
|
if (info.source === null) {
|
||||||
get: function() {
|
return;
|
||||||
return generator;
|
}
|
||||||
},
|
source = info.source;
|
||||||
toString: function() {
|
orig_line = info.line;
|
||||||
return JSON.stringify(generator.toJSON());
|
orig_col = info.column;
|
||||||
|
name = info.name || name;
|
||||||
}
|
}
|
||||||
|
generator.addMapping({
|
||||||
|
generated : { line: gen_line + options.dest_line_diff, column: gen_col },
|
||||||
|
original : { line: orig_line + options.orig_line_diff, column: orig_col },
|
||||||
|
source : source,
|
||||||
|
name : name
|
||||||
|
});
|
||||||
};
|
};
|
||||||
}
|
return {
|
||||||
|
add : add,
|
||||||
|
get : function() { return generator },
|
||||||
|
toString : function() { return JSON.stringify(generator.toJSON()); }
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|||||||
188
lib/transform.js
188
lib/transform.js
@@ -43,6 +43,8 @@
|
|||||||
|
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
|
// Tree transformer helpers.
|
||||||
|
|
||||||
function TreeTransformer(before, after) {
|
function TreeTransformer(before, after) {
|
||||||
TreeWalker.call(this);
|
TreeWalker.call(this);
|
||||||
this.before = before;
|
this.before = before;
|
||||||
@@ -50,136 +52,218 @@ function TreeTransformer(before, after) {
|
|||||||
}
|
}
|
||||||
TreeTransformer.prototype = new TreeWalker;
|
TreeTransformer.prototype = new TreeWalker;
|
||||||
|
|
||||||
(function(DEF) {
|
(function(undefined){
|
||||||
|
|
||||||
|
function _(node, descend) {
|
||||||
|
node.DEFMETHOD("transform", function(tw, in_list){
|
||||||
|
var x, y;
|
||||||
|
tw.push(this);
|
||||||
|
if (tw.before) x = tw.before(this, descend, in_list);
|
||||||
|
if (x === undefined) {
|
||||||
|
x = this;
|
||||||
|
descend(x, tw);
|
||||||
|
if (tw.after) {
|
||||||
|
y = tw.after(x, in_list);
|
||||||
|
if (y !== undefined) x = y;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
tw.pop();
|
||||||
|
return x;
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
function do_list(list, tw) {
|
function do_list(list, tw) {
|
||||||
return MAP(list, function(node) {
|
return MAP(list, function(node){
|
||||||
return node.transform(tw, true);
|
return node.transform(tw, true);
|
||||||
});
|
});
|
||||||
}
|
};
|
||||||
|
|
||||||
DEF(AST_Node, noop);
|
_(AST_Node, noop);
|
||||||
DEF(AST_LabeledStatement, function(self, tw) {
|
|
||||||
|
_(AST_LabeledStatement, function(self, tw){
|
||||||
self.label = self.label.transform(tw);
|
self.label = self.label.transform(tw);
|
||||||
self.body = self.body.transform(tw);
|
self.body = self.body.transform(tw);
|
||||||
});
|
});
|
||||||
DEF(AST_SimpleStatement, function(self, tw) {
|
|
||||||
|
_(AST_SimpleStatement, function(self, tw){
|
||||||
self.body = self.body.transform(tw);
|
self.body = self.body.transform(tw);
|
||||||
});
|
});
|
||||||
DEF(AST_Block, function(self, tw) {
|
|
||||||
|
_(AST_Block, function(self, tw){
|
||||||
self.body = do_list(self.body, tw);
|
self.body = do_list(self.body, tw);
|
||||||
});
|
});
|
||||||
DEF(AST_Do, function(self, tw) {
|
|
||||||
self.body = self.body.transform(tw);
|
_(AST_DWLoop, function(self, tw){
|
||||||
self.condition = self.condition.transform(tw);
|
|
||||||
});
|
|
||||||
DEF(AST_While, function(self, tw) {
|
|
||||||
self.condition = self.condition.transform(tw);
|
self.condition = self.condition.transform(tw);
|
||||||
self.body = self.body.transform(tw);
|
self.body = self.body.transform(tw);
|
||||||
});
|
});
|
||||||
DEF(AST_For, function(self, tw) {
|
|
||||||
|
_(AST_For, function(self, tw){
|
||||||
if (self.init) self.init = self.init.transform(tw);
|
if (self.init) self.init = self.init.transform(tw);
|
||||||
if (self.condition) self.condition = self.condition.transform(tw);
|
if (self.condition) self.condition = self.condition.transform(tw);
|
||||||
if (self.step) self.step = self.step.transform(tw);
|
if (self.step) self.step = self.step.transform(tw);
|
||||||
self.body = self.body.transform(tw);
|
self.body = self.body.transform(tw);
|
||||||
});
|
});
|
||||||
DEF(AST_ForIn, function(self, tw) {
|
|
||||||
|
_(AST_ForIn, function(self, tw){
|
||||||
self.init = self.init.transform(tw);
|
self.init = self.init.transform(tw);
|
||||||
self.object = self.object.transform(tw);
|
self.object = self.object.transform(tw);
|
||||||
self.body = self.body.transform(tw);
|
self.body = self.body.transform(tw);
|
||||||
});
|
});
|
||||||
DEF(AST_With, function(self, tw) {
|
|
||||||
|
_(AST_With, function(self, tw){
|
||||||
self.expression = self.expression.transform(tw);
|
self.expression = self.expression.transform(tw);
|
||||||
self.body = self.body.transform(tw);
|
self.body = self.body.transform(tw);
|
||||||
});
|
});
|
||||||
DEF(AST_Exit, function(self, tw) {
|
|
||||||
|
_(AST_Exit, function(self, tw){
|
||||||
if (self.value) self.value = self.value.transform(tw);
|
if (self.value) self.value = self.value.transform(tw);
|
||||||
});
|
});
|
||||||
DEF(AST_LoopControl, function(self, tw) {
|
|
||||||
|
_(AST_LoopControl, function(self, tw){
|
||||||
if (self.label) self.label = self.label.transform(tw);
|
if (self.label) self.label = self.label.transform(tw);
|
||||||
});
|
});
|
||||||
DEF(AST_If, function(self, tw) {
|
|
||||||
|
_(AST_If, function(self, tw){
|
||||||
self.condition = self.condition.transform(tw);
|
self.condition = self.condition.transform(tw);
|
||||||
self.body = self.body.transform(tw);
|
self.body = self.body.transform(tw);
|
||||||
if (self.alternative) self.alternative = self.alternative.transform(tw);
|
if (self.alternative) self.alternative = self.alternative.transform(tw);
|
||||||
});
|
});
|
||||||
DEF(AST_Switch, function(self, tw) {
|
|
||||||
|
_(AST_Switch, function(self, tw){
|
||||||
self.expression = self.expression.transform(tw);
|
self.expression = self.expression.transform(tw);
|
||||||
self.body = do_list(self.body, tw);
|
self.body = do_list(self.body, tw);
|
||||||
});
|
});
|
||||||
DEF(AST_Case, function(self, tw) {
|
|
||||||
|
_(AST_Case, function(self, tw){
|
||||||
self.expression = self.expression.transform(tw);
|
self.expression = self.expression.transform(tw);
|
||||||
self.body = do_list(self.body, tw);
|
self.body = do_list(self.body, tw);
|
||||||
});
|
});
|
||||||
DEF(AST_Try, function(self, tw) {
|
|
||||||
|
_(AST_Try, function(self, tw){
|
||||||
self.body = do_list(self.body, tw);
|
self.body = do_list(self.body, tw);
|
||||||
if (self.bcatch) self.bcatch = self.bcatch.transform(tw);
|
if (self.bcatch) self.bcatch = self.bcatch.transform(tw);
|
||||||
if (self.bfinally) self.bfinally = self.bfinally.transform(tw);
|
if (self.bfinally) self.bfinally = self.bfinally.transform(tw);
|
||||||
});
|
});
|
||||||
DEF(AST_Catch, function(self, tw) {
|
|
||||||
|
_(AST_Catch, function(self, tw){
|
||||||
self.argname = self.argname.transform(tw);
|
self.argname = self.argname.transform(tw);
|
||||||
self.body = do_list(self.body, tw);
|
self.body = do_list(self.body, tw);
|
||||||
});
|
});
|
||||||
DEF(AST_Definitions, function(self, tw) {
|
|
||||||
|
_(AST_Definitions, function(self, tw){
|
||||||
self.definitions = do_list(self.definitions, tw);
|
self.definitions = do_list(self.definitions, tw);
|
||||||
});
|
});
|
||||||
DEF(AST_VarDef, function(self, tw) {
|
|
||||||
|
_(AST_VarDef, function(self, tw){
|
||||||
self.name = self.name.transform(tw);
|
self.name = self.name.transform(tw);
|
||||||
if (self.value) self.value = self.value.transform(tw);
|
if (self.value) self.value = self.value.transform(tw);
|
||||||
});
|
});
|
||||||
DEF(AST_Lambda, function(self, tw) {
|
|
||||||
|
_(AST_Destructuring, function(self, tw) {
|
||||||
|
self.names = do_list(self.names, 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);
|
||||||
self.body = do_list(self.body, tw);
|
if (self.body instanceof AST_Node) {
|
||||||
|
self.body = self.body.transform(tw);
|
||||||
|
} else {
|
||||||
|
self.body = do_list(self.body, tw);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
DEF(AST_Call, function(self, tw) {
|
|
||||||
|
_(AST_Call, function(self, tw){
|
||||||
self.expression = self.expression.transform(tw);
|
self.expression = self.expression.transform(tw);
|
||||||
self.args = do_list(self.args, tw);
|
self.args = do_list(self.args, tw);
|
||||||
});
|
});
|
||||||
DEF(AST_Sequence, function(self, tw) {
|
|
||||||
|
_(AST_Sequence, function(self, tw){
|
||||||
self.expressions = do_list(self.expressions, tw);
|
self.expressions = do_list(self.expressions, tw);
|
||||||
});
|
});
|
||||||
DEF(AST_Dot, function(self, tw) {
|
|
||||||
|
_(AST_Dot, function(self, tw){
|
||||||
self.expression = self.expression.transform(tw);
|
self.expression = self.expression.transform(tw);
|
||||||
});
|
});
|
||||||
DEF(AST_Sub, function(self, tw) {
|
|
||||||
|
_(AST_Sub, function(self, tw){
|
||||||
self.expression = self.expression.transform(tw);
|
self.expression = self.expression.transform(tw);
|
||||||
self.property = self.property.transform(tw);
|
self.property = self.property.transform(tw);
|
||||||
});
|
});
|
||||||
DEF(AST_Unary, function(self, 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);
|
self.expression = self.expression.transform(tw);
|
||||||
});
|
});
|
||||||
DEF(AST_Binary, function(self, tw) {
|
|
||||||
|
_(AST_Unary, function(self, tw){
|
||||||
|
self.expression = self.expression.transform(tw);
|
||||||
|
});
|
||||||
|
|
||||||
|
_(AST_Binary, function(self, tw){
|
||||||
self.left = self.left.transform(tw);
|
self.left = self.left.transform(tw);
|
||||||
self.right = self.right.transform(tw);
|
self.right = self.right.transform(tw);
|
||||||
});
|
});
|
||||||
DEF(AST_Conditional, function(self, tw) {
|
|
||||||
|
_(AST_Conditional, function(self, tw){
|
||||||
self.condition = self.condition.transform(tw);
|
self.condition = self.condition.transform(tw);
|
||||||
self.consequent = self.consequent.transform(tw);
|
self.consequent = self.consequent.transform(tw);
|
||||||
self.alternative = self.alternative.transform(tw);
|
self.alternative = self.alternative.transform(tw);
|
||||||
});
|
});
|
||||||
DEF(AST_Array, function(self, tw) {
|
|
||||||
|
_(AST_Array, function(self, tw){
|
||||||
self.elements = do_list(self.elements, tw);
|
self.elements = do_list(self.elements, tw);
|
||||||
});
|
});
|
||||||
DEF(AST_Object, function(self, tw) {
|
|
||||||
|
_(AST_Object, function(self, tw){
|
||||||
self.properties = do_list(self.properties, tw);
|
self.properties = do_list(self.properties, tw);
|
||||||
});
|
});
|
||||||
DEF(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);
|
||||||
});
|
});
|
||||||
})(function(node, descend) {
|
|
||||||
node.DEFMETHOD("transform", function(tw, in_list) {
|
_(AST_Class, function(self, tw){
|
||||||
var x, y;
|
if (self.name) self.name = self.name.transform(tw);
|
||||||
tw.push(this);
|
if (self.extends) self.extends = self.extends.transform(tw);
|
||||||
if (tw.before) x = tw.before(this, descend, in_list);
|
self.properties = do_list(self.properties, tw);
|
||||||
if (typeof x === "undefined") {
|
|
||||||
x = this;
|
|
||||||
descend(x, tw);
|
|
||||||
if (tw.after) {
|
|
||||||
y = tw.after(x, in_list);
|
|
||||||
if (typeof y !== "undefined") x = y;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
tw.pop();
|
|
||||||
return x;
|
|
||||||
});
|
});
|
||||||
});
|
|
||||||
|
_(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);
|
||||||
|
});
|
||||||
|
|
||||||
|
})();
|
||||||
|
|||||||
172
lib/utils.js
172
lib/utils.js
@@ -45,23 +45,27 @@
|
|||||||
|
|
||||||
function characters(str) {
|
function characters(str) {
|
||||||
return str.split("");
|
return str.split("");
|
||||||
}
|
};
|
||||||
|
|
||||||
function member(name, array) {
|
function member(name, array) {
|
||||||
return array.indexOf(name) >= 0;
|
return array.indexOf(name) >= 0;
|
||||||
}
|
};
|
||||||
|
|
||||||
function find_if(func, array) {
|
function find_if(func, array) {
|
||||||
for (var i = array.length; --i >= 0;) if (func(array[i])) return array[i];
|
for (var i = 0, n = array.length; i < n; ++i) {
|
||||||
}
|
if (func(array[i]))
|
||||||
|
return array[i];
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
function repeat_string(str, i) {
|
function repeat_string(str, i) {
|
||||||
if (i <= 0) return "";
|
if (i <= 0) return "";
|
||||||
if (i == 1) return str;
|
if (i == 1) return str;
|
||||||
var d = repeat_string(str, i >> 1);
|
var d = repeat_string(str, i >> 1);
|
||||||
d += d;
|
d += d;
|
||||||
return i & 1 ? d + str : d;
|
if (i & 1) d += str;
|
||||||
}
|
return d;
|
||||||
|
};
|
||||||
|
|
||||||
function configure_error_stack(fn) {
|
function configure_error_stack(fn) {
|
||||||
Object.defineProperty(fn.prototype, "stack", {
|
Object.defineProperty(fn.prototype, "stack", {
|
||||||
@@ -80,23 +84,27 @@ function configure_error_stack(fn) {
|
|||||||
function DefaultsError(msg, defs) {
|
function DefaultsError(msg, defs) {
|
||||||
this.message = msg;
|
this.message = msg;
|
||||||
this.defs = defs;
|
this.defs = defs;
|
||||||
}
|
};
|
||||||
DefaultsError.prototype = Object.create(Error.prototype);
|
DefaultsError.prototype = Object.create(Error.prototype);
|
||||||
DefaultsError.prototype.constructor = DefaultsError;
|
DefaultsError.prototype.constructor = DefaultsError;
|
||||||
DefaultsError.prototype.name = "DefaultsError";
|
DefaultsError.prototype.name = "DefaultsError";
|
||||||
configure_error_stack(DefaultsError);
|
configure_error_stack(DefaultsError);
|
||||||
|
|
||||||
|
DefaultsError.croak = function(msg, defs) {
|
||||||
|
throw new DefaultsError(msg, defs);
|
||||||
|
};
|
||||||
|
|
||||||
function defaults(args, defs, croak) {
|
function defaults(args, defs, croak) {
|
||||||
if (args === true) args = {};
|
if (args === true)
|
||||||
|
args = {};
|
||||||
var ret = args || {};
|
var ret = args || {};
|
||||||
if (croak) for (var i in ret) if (HOP(ret, i) && !HOP(defs, i)) {
|
if (croak) for (var i in ret) if (HOP(ret, i) && !HOP(defs, i))
|
||||||
throw new DefaultsError("`" + i + "` is not a supported option", defs);
|
DefaultsError.croak("`" + i + "` is not a supported option", defs);
|
||||||
}
|
|
||||||
for (var i in defs) if (HOP(defs, i)) {
|
for (var i in defs) if (HOP(defs, i)) {
|
||||||
ret[i] = (args && HOP(args, i)) ? args[i] : defs[i];
|
ret[i] = (args && HOP(args, i)) ? args[i] : defs[i];
|
||||||
}
|
}
|
||||||
return ret;
|
return ret;
|
||||||
}
|
};
|
||||||
|
|
||||||
function merge(obj, ext) {
|
function merge(obj, ext) {
|
||||||
var count = 0;
|
var count = 0;
|
||||||
@@ -105,7 +113,7 @@ function merge(obj, ext) {
|
|||||||
count++;
|
count++;
|
||||||
}
|
}
|
||||||
return count;
|
return count;
|
||||||
}
|
};
|
||||||
|
|
||||||
function noop() {}
|
function noop() {}
|
||||||
function return_false() { return false; }
|
function return_false() { return false; }
|
||||||
@@ -113,7 +121,7 @@ function return_true() { return true; }
|
|||||||
function return_this() { return this; }
|
function return_this() { return this; }
|
||||||
function return_null() { return null; }
|
function return_null() { return null; }
|
||||||
|
|
||||||
var MAP = (function() {
|
var MAP = (function(){
|
||||||
function MAP(a, f, backwards) {
|
function MAP(a, f, backwards) {
|
||||||
var ret = [], top = [], i;
|
var ret = [], top = [], i;
|
||||||
function doit() {
|
function doit() {
|
||||||
@@ -136,8 +144,8 @@ var MAP = (function() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
return is_last;
|
return is_last;
|
||||||
}
|
};
|
||||||
if (Array.isArray(a)) {
|
if (a instanceof Array) {
|
||||||
if (backwards) {
|
if (backwards) {
|
||||||
for (i = a.length; --i >= 0;) if (doit()) break;
|
for (i = a.length; --i >= 0;) if (doit()) break;
|
||||||
ret.reverse();
|
ret.reverse();
|
||||||
@@ -150,54 +158,115 @@ var MAP = (function() {
|
|||||||
for (i in a) if (HOP(a, i)) if (doit()) break;
|
for (i in a) if (HOP(a, i)) if (doit()) break;
|
||||||
}
|
}
|
||||||
return top.concat(ret);
|
return top.concat(ret);
|
||||||
}
|
};
|
||||||
MAP.at_top = function(val) { return new AtTop(val) };
|
MAP.at_top = function(val) { return new AtTop(val) };
|
||||||
MAP.splice = function(val) { return new Splice(val) };
|
MAP.splice = function(val) { return new Splice(val) };
|
||||||
MAP.last = function(val) { return new Last(val) };
|
MAP.last = function(val) { return new Last(val) };
|
||||||
var skip = MAP.skip = {};
|
var skip = MAP.skip = {};
|
||||||
function AtTop(val) { this.v = val }
|
function AtTop(val) { this.v = val };
|
||||||
function Splice(val) { this.v = val }
|
function Splice(val) { this.v = val };
|
||||||
function Last(val) { this.v = val }
|
function Last(val) { this.v = val };
|
||||||
return MAP;
|
return MAP;
|
||||||
})();
|
})();
|
||||||
|
|
||||||
function push_uniq(array, el) {
|
function push_uniq(array, el) {
|
||||||
if (array.indexOf(el) < 0)
|
if (array.indexOf(el) < 0)
|
||||||
array.push(el);
|
array.push(el);
|
||||||
}
|
};
|
||||||
|
|
||||||
function string_template(text, props) {
|
function string_template(text, props) {
|
||||||
return text.replace(/\{(.+?)\}/g, function(str, p) {
|
return text.replace(/\{(.+?)\}/g, function(str, p){
|
||||||
return props && props[p];
|
return props && props[p];
|
||||||
});
|
});
|
||||||
}
|
};
|
||||||
|
|
||||||
function remove(array, el) {
|
function remove(array, el) {
|
||||||
for (var i = array.length; --i >= 0;) {
|
for (var i = array.length; --i >= 0;) {
|
||||||
if (array[i] === el) array.splice(i, 1);
|
if (array[i] === el) array.splice(i, 1);
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
|
|
||||||
|
function mergeSort(array, cmp) {
|
||||||
|
if (array.length < 2) return array.slice();
|
||||||
|
function merge(a, b) {
|
||||||
|
var r = [], ai = 0, bi = 0, i = 0;
|
||||||
|
while (ai < a.length && bi < b.length) {
|
||||||
|
cmp(a[ai], b[bi]) <= 0
|
||||||
|
? r[i++] = a[ai++]
|
||||||
|
: r[i++] = b[bi++];
|
||||||
|
}
|
||||||
|
if (ai < a.length) r.push.apply(r, a.slice(ai));
|
||||||
|
if (bi < b.length) r.push.apply(r, b.slice(bi));
|
||||||
|
return r;
|
||||||
|
};
|
||||||
|
function _ms(a) {
|
||||||
|
if (a.length <= 1)
|
||||||
|
return a;
|
||||||
|
var m = Math.floor(a.length / 2), left = a.slice(0, m), right = a.slice(m);
|
||||||
|
left = _ms(left);
|
||||||
|
right = _ms(right);
|
||||||
|
return merge(left, right);
|
||||||
|
};
|
||||||
|
return _ms(array);
|
||||||
|
};
|
||||||
|
|
||||||
|
// this function is taken from Acorn [1], written by Marijn Haverbeke
|
||||||
|
// [1] https://github.com/marijnh/acorn
|
||||||
function makePredicate(words) {
|
function makePredicate(words) {
|
||||||
if (!Array.isArray(words)) words = words.split(" ");
|
if (!(words instanceof Array)) words = words.split(" ");
|
||||||
var map = Object.create(null);
|
var f = "", cats = [];
|
||||||
words.forEach(function(word) {
|
out: for (var i = 0; i < words.length; ++i) {
|
||||||
map[word] = true;
|
for (var j = 0; j < cats.length; ++j)
|
||||||
});
|
if (cats[j][0].length == words[i].length) {
|
||||||
return map;
|
cats[j].push(words[i]);
|
||||||
}
|
continue out;
|
||||||
|
}
|
||||||
|
cats.push([words[i]]);
|
||||||
|
}
|
||||||
|
function quote(word) {
|
||||||
|
return JSON.stringify(word).replace(/[\u2028\u2029]/g, function(s) {
|
||||||
|
switch (s) {
|
||||||
|
case "\u2028": return "\\u2028";
|
||||||
|
case "\u2029": return "\\u2029";
|
||||||
|
}
|
||||||
|
return s;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
function compareTo(arr) {
|
||||||
|
if (arr.length == 1) return f += "return str === " + quote(arr[0]) + ";";
|
||||||
|
f += "switch(str){";
|
||||||
|
for (var i = 0; i < arr.length; ++i) f += "case " + quote(arr[i]) + ":";
|
||||||
|
f += "return true}return false;";
|
||||||
|
}
|
||||||
|
// When there are more than three length categories, an outer
|
||||||
|
// switch first dispatches on the lengths, to save on comparisons.
|
||||||
|
if (cats.length > 3) {
|
||||||
|
cats.sort(function(a, b) {return b.length - a.length;});
|
||||||
|
f += "switch(str.length){";
|
||||||
|
for (var i = 0; i < cats.length; ++i) {
|
||||||
|
var cat = cats[i];
|
||||||
|
f += "case " + cat[0].length + ":";
|
||||||
|
compareTo(cat);
|
||||||
|
}
|
||||||
|
f += "}";
|
||||||
|
// Otherwise, simply generate a flat `switch` statement.
|
||||||
|
} else {
|
||||||
|
compareTo(words);
|
||||||
|
}
|
||||||
|
return new Function("str", f);
|
||||||
|
};
|
||||||
|
|
||||||
function all(array, predicate) {
|
function all(array, predicate) {
|
||||||
for (var i = array.length; --i >= 0;)
|
for (var i = array.length; --i >= 0;)
|
||||||
if (!predicate(array[i]))
|
if (!predicate(array[i]))
|
||||||
return false;
|
return false;
|
||||||
return true;
|
return true;
|
||||||
}
|
};
|
||||||
|
|
||||||
function Dictionary() {
|
function Dictionary() {
|
||||||
this._values = Object.create(null);
|
this._values = Object.create(null);
|
||||||
this._size = 0;
|
this._size = 0;
|
||||||
}
|
};
|
||||||
Dictionary.prototype = {
|
Dictionary.prototype = {
|
||||||
set: function(key, val) {
|
set: function(key, val) {
|
||||||
if (!this.has(key)) ++this._size;
|
if (!this.has(key)) ++this._size;
|
||||||
@@ -234,13 +303,6 @@ 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) {
|
||||||
@@ -258,22 +320,20 @@ function HOP(obj, prop) {
|
|||||||
// a statement.
|
// a statement.
|
||||||
function first_in_statement(stack) {
|
function first_in_statement(stack) {
|
||||||
var node = stack.parent(-1);
|
var node = stack.parent(-1);
|
||||||
for (var i = 0, p; p = stack.parent(i++); node = p) {
|
for (var i = 0, p; p = stack.parent(i); i++) {
|
||||||
if (p.TYPE == "Call") {
|
if (p instanceof AST_Statement && p.body === node)
|
||||||
if (p.expression === node) continue;
|
return true;
|
||||||
} else if (p instanceof AST_Binary) {
|
if ((p instanceof AST_Sequence && p.expressions[0] === node) ||
|
||||||
if (p.left === node) continue;
|
(p.TYPE == "Call" && p.expression === node ) ||
|
||||||
} else if (p instanceof AST_Conditional) {
|
(p instanceof AST_Dot && p.expression === node ) ||
|
||||||
if (p.condition === node) continue;
|
(p instanceof AST_Sub && p.expression === node ) ||
|
||||||
} else if (p instanceof AST_PropAccess) {
|
(p instanceof AST_Conditional && p.condition === node ) ||
|
||||||
if (p.expression === node) continue;
|
(p instanceof AST_Binary && p.left === node ) ||
|
||||||
} else if (p instanceof AST_Sequence) {
|
(p instanceof AST_UnaryPostfix && p.expression === node ))
|
||||||
if (p.expressions[0] === node) continue;
|
{
|
||||||
} else if (p instanceof AST_Statement) {
|
node = p;
|
||||||
return p.body === node;
|
} else {
|
||||||
} else if (p instanceof AST_UnaryPostfix) {
|
return false;
|
||||||
if (p.expression === node) continue;
|
|
||||||
}
|
}
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
52
package.json
52
package.json
@@ -1,9 +1,10 @@
|
|||||||
{
|
{
|
||||||
"name": "uglify-js",
|
"name": "uglify-es",
|
||||||
"description": "JavaScript parser, mangler/compressor and beautifier toolkit",
|
"description": "JavaScript parser, mangler/compressor and beautifier toolkit for ES6+",
|
||||||
|
"homepage": "https://github.com/mishoo/UglifyJS2/tree/harmony",
|
||||||
"author": "Mihai Bazon <mihai.bazon@gmail.com> (http://lisperator.net/)",
|
"author": "Mihai Bazon <mihai.bazon@gmail.com> (http://lisperator.net/)",
|
||||||
"license": "BSD-2-Clause",
|
"license": "BSD-2-Clause",
|
||||||
"version": "3.4.2",
|
"version": "3.3.7",
|
||||||
"engines": {
|
"engines": {
|
||||||
"node": ">=0.8.0"
|
"node": ">=0.8.0"
|
||||||
},
|
},
|
||||||
@@ -11,7 +12,7 @@
|
|||||||
"Alex Lam <alexlamsl@gmail.com>",
|
"Alex Lam <alexlamsl@gmail.com>",
|
||||||
"Mihai Bazon <mihai.bazon@gmail.com> (http://lisperator.net/)"
|
"Mihai Bazon <mihai.bazon@gmail.com> (http://lisperator.net/)"
|
||||||
],
|
],
|
||||||
"repository": "mishoo/UglifyJS2",
|
"repository": "https://github.com/mishoo/UglifyJS2.git#harmony",
|
||||||
"main": "tools/node.js",
|
"main": "tools/node.js",
|
||||||
"bin": {
|
"bin": {
|
||||||
"uglifyjs": "bin/uglifyjs"
|
"uglifyjs": "bin/uglifyjs"
|
||||||
@@ -23,38 +24,33 @@
|
|||||||
"LICENSE"
|
"LICENSE"
|
||||||
],
|
],
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"commander": "~2.15.0",
|
"commander": "~2.13.0",
|
||||||
"source-map": "~0.6.1"
|
"source-map": "~0.6.1"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"acorn": "~5.5.3",
|
"acorn": "~5.3.0",
|
||||||
"semver": "~5.5.0"
|
"mocha": "~3.5.1",
|
||||||
|
"semver": "~5.4.1"
|
||||||
},
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"test": "node test/run-tests.js"
|
"test": "node test/run-tests.js"
|
||||||
},
|
},
|
||||||
"keywords": [
|
"keywords": [
|
||||||
"cli",
|
"uglify",
|
||||||
"compress",
|
"uglify-es",
|
||||||
"compressor",
|
"uglify-js",
|
||||||
"ecma",
|
|
||||||
"ecmascript",
|
|
||||||
"es",
|
|
||||||
"es5",
|
|
||||||
"javascript",
|
|
||||||
"js",
|
|
||||||
"jsmin",
|
|
||||||
"min",
|
|
||||||
"minification",
|
|
||||||
"minifier",
|
|
||||||
"minify",
|
"minify",
|
||||||
"optimize",
|
"minifier",
|
||||||
"optimizer",
|
"javascript",
|
||||||
"pack",
|
"ecmascript",
|
||||||
"packer",
|
"es5",
|
||||||
"parse",
|
"es6",
|
||||||
"parser",
|
"es7",
|
||||||
"uglifier",
|
"es8",
|
||||||
"uglify"
|
"es2015",
|
||||||
|
"es2016",
|
||||||
|
"es2017",
|
||||||
|
"async",
|
||||||
|
"await"
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -28,7 +28,6 @@ var remaining = 2 * urls.length;
|
|||||||
function done() {
|
function done() {
|
||||||
if (!--remaining) {
|
if (!--remaining) {
|
||||||
var failures = [];
|
var failures = [];
|
||||||
var sum = { input: 0, output: 0, gzip: 0 };
|
|
||||||
urls.forEach(function(url) {
|
urls.forEach(function(url) {
|
||||||
var info = results[url];
|
var info = results[url];
|
||||||
console.log();
|
console.log();
|
||||||
@@ -41,9 +40,6 @@ function done() {
|
|||||||
if (info.code) {
|
if (info.code) {
|
||||||
failures.push(url);
|
failures.push(url);
|
||||||
}
|
}
|
||||||
sum.input += info.input;
|
|
||||||
sum.output += info.output;
|
|
||||||
sum.gzip += info.gzip;
|
|
||||||
});
|
});
|
||||||
if (failures.length) {
|
if (failures.length) {
|
||||||
console.error("Benchmark failed:");
|
console.error("Benchmark failed:");
|
||||||
@@ -51,13 +47,6 @@ function done() {
|
|||||||
console.error(url);
|
console.error(url);
|
||||||
});
|
});
|
||||||
process.exit(1);
|
process.exit(1);
|
||||||
} else {
|
|
||||||
console.log();
|
|
||||||
console.log("Subtotal");
|
|
||||||
console.log();
|
|
||||||
console.log("Original:", sum.input, "bytes");
|
|
||||||
console.log("Uglified:", sum.output, "bytes");
|
|
||||||
console.log("GZipped: ", sum.gzip, "bytes");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,239 +0,0 @@
|
|||||||
replace_index: {
|
|
||||||
options = {
|
|
||||||
arguments: true,
|
|
||||||
evaluate: true,
|
|
||||||
properties: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
var arguments = [];
|
|
||||||
console.log(arguments[0]);
|
|
||||||
(function() {
|
|
||||||
console.log(arguments[1], arguments["1"], arguments["foo"]);
|
|
||||||
})("bar", 42);
|
|
||||||
(function(a, b) {
|
|
||||||
console.log(arguments[1], arguments["1"], arguments["foo"]);
|
|
||||||
})("bar", 42);
|
|
||||||
(function(arguments) {
|
|
||||||
console.log(arguments[1], arguments["1"], arguments["foo"]);
|
|
||||||
})("bar", 42);
|
|
||||||
(function() {
|
|
||||||
var arguments;
|
|
||||||
console.log(arguments[1], arguments["1"], arguments["foo"]);
|
|
||||||
})("bar", 42);
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
var arguments = [];
|
|
||||||
console.log(arguments[0]);
|
|
||||||
(function() {
|
|
||||||
console.log(arguments[1], arguments[1], arguments.foo);
|
|
||||||
})("bar", 42);
|
|
||||||
(function(a, b) {
|
|
||||||
console.log(b, b, arguments.foo);
|
|
||||||
})("bar", 42);
|
|
||||||
(function(arguments) {
|
|
||||||
console.log(arguments[1], arguments[1], arguments.foo);
|
|
||||||
})("bar", 42);
|
|
||||||
(function() {
|
|
||||||
var arguments;
|
|
||||||
console.log(arguments[1], arguments[1], arguments.foo);
|
|
||||||
})("bar", 42);
|
|
||||||
}
|
|
||||||
expect_stdout: [
|
|
||||||
"undefined",
|
|
||||||
"42 42 undefined",
|
|
||||||
"42 42 undefined",
|
|
||||||
"a a undefined",
|
|
||||||
"42 42 undefined",
|
|
||||||
]
|
|
||||||
}
|
|
||||||
|
|
||||||
replace_index_strict: {
|
|
||||||
options = {
|
|
||||||
arguments: true,
|
|
||||||
evaluate: true,
|
|
||||||
properties: true,
|
|
||||||
reduce_vars: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
"use strict";
|
|
||||||
(function() {
|
|
||||||
console.log(arguments[1], arguments["1"], arguments["foo"]);
|
|
||||||
})("bar", 42);
|
|
||||||
(function(a, b) {
|
|
||||||
console.log(arguments[1], arguments["1"], arguments["foo"]);
|
|
||||||
})("bar", 42);
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
"use strict";
|
|
||||||
(function() {
|
|
||||||
console.log(arguments[1], arguments[1], arguments.foo);
|
|
||||||
})("bar", 42);
|
|
||||||
(function(a, b) {
|
|
||||||
console.log(b, b, arguments.foo);
|
|
||||||
})("bar", 42);
|
|
||||||
}
|
|
||||||
expect_stdout: [
|
|
||||||
"42 42 undefined",
|
|
||||||
"42 42 undefined",
|
|
||||||
]
|
|
||||||
}
|
|
||||||
|
|
||||||
replace_index_keep_fargs: {
|
|
||||||
options = {
|
|
||||||
arguments: true,
|
|
||||||
evaluate: true,
|
|
||||||
keep_fargs: false,
|
|
||||||
properties: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
var arguments = [];
|
|
||||||
console.log(arguments[0]);
|
|
||||||
(function() {
|
|
||||||
console.log(arguments[1], arguments["1"], arguments["foo"]);
|
|
||||||
})("bar", 42);
|
|
||||||
(function(a, b) {
|
|
||||||
console.log(arguments[1], arguments["1"], arguments["foo"]);
|
|
||||||
})("bar", 42);
|
|
||||||
(function(arguments) {
|
|
||||||
console.log(arguments[1], arguments["1"], arguments["foo"]);
|
|
||||||
})("bar", 42);
|
|
||||||
(function() {
|
|
||||||
var arguments;
|
|
||||||
console.log(arguments[1], arguments["1"], arguments["foo"]);
|
|
||||||
})("bar", 42);
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
var arguments = [];
|
|
||||||
console.log(arguments[0]);
|
|
||||||
(function(argument_0, argument_1) {
|
|
||||||
console.log(argument_1, argument_1, arguments.foo);
|
|
||||||
})("bar", 42);
|
|
||||||
(function(a, b) {
|
|
||||||
console.log(b, b, arguments.foo);
|
|
||||||
})("bar", 42);
|
|
||||||
(function(arguments) {
|
|
||||||
console.log(arguments[1], arguments[1], arguments.foo);
|
|
||||||
})("bar", 42);
|
|
||||||
(function() {
|
|
||||||
var arguments;
|
|
||||||
console.log(arguments[1], arguments[1], arguments.foo);
|
|
||||||
})("bar", 42);
|
|
||||||
}
|
|
||||||
expect_stdout: [
|
|
||||||
"undefined",
|
|
||||||
"42 42 undefined",
|
|
||||||
"42 42 undefined",
|
|
||||||
"a a undefined",
|
|
||||||
"42 42 undefined",
|
|
||||||
]
|
|
||||||
}
|
|
||||||
|
|
||||||
replace_index_keep_fargs_strict: {
|
|
||||||
options = {
|
|
||||||
arguments: true,
|
|
||||||
evaluate: true,
|
|
||||||
keep_fargs: false,
|
|
||||||
properties: true,
|
|
||||||
reduce_vars: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
"use strict";
|
|
||||||
(function() {
|
|
||||||
console.log(arguments[1], arguments["1"], arguments["foo"]);
|
|
||||||
})("bar", 42);
|
|
||||||
(function(a, b) {
|
|
||||||
console.log(arguments[1], arguments["1"], arguments["foo"]);
|
|
||||||
})("bar", 42);
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
"use strict";
|
|
||||||
(function(argument_0, argument_1) {
|
|
||||||
console.log(argument_1, argument_1, arguments.foo);
|
|
||||||
})("bar", 42);
|
|
||||||
(function(a, b) {
|
|
||||||
console.log(b, b, arguments.foo);
|
|
||||||
})("bar", 42);
|
|
||||||
}
|
|
||||||
expect_stdout: [
|
|
||||||
"42 42 undefined",
|
|
||||||
"42 42 undefined",
|
|
||||||
]
|
|
||||||
}
|
|
||||||
|
|
||||||
modified: {
|
|
||||||
options = {
|
|
||||||
arguments: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
(function(a, b) {
|
|
||||||
var c = arguments[0];
|
|
||||||
var d = arguments[1];
|
|
||||||
var a = "foo";
|
|
||||||
b++;
|
|
||||||
arguments[0] = "moo";
|
|
||||||
arguments[1] *= 2;
|
|
||||||
console.log(a, b, c, d, arguments[0], arguments[1]);
|
|
||||||
})("bar", 42);
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
(function(a, b) {
|
|
||||||
var c = a;
|
|
||||||
var d = b;
|
|
||||||
var a = "foo";
|
|
||||||
b++;
|
|
||||||
a = "moo";
|
|
||||||
b *= 2;
|
|
||||||
console.log(a, b, c, d, a, b);
|
|
||||||
})("bar", 42);
|
|
||||||
}
|
|
||||||
expect_stdout: "moo 86 bar 42 moo 86"
|
|
||||||
}
|
|
||||||
|
|
||||||
modified_strict: {
|
|
||||||
options = {
|
|
||||||
arguments: true,
|
|
||||||
reduce_vars: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
"use strict";
|
|
||||||
(function(a, b) {
|
|
||||||
var c = arguments[0];
|
|
||||||
var d = arguments[1];
|
|
||||||
var a = "foo";
|
|
||||||
b++;
|
|
||||||
arguments[0] = "moo";
|
|
||||||
arguments[1] *= 2;
|
|
||||||
console.log(a, b, c, d, arguments[0], arguments[1]);
|
|
||||||
})("bar", 42);
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
"use strict";
|
|
||||||
(function(a, b) {
|
|
||||||
var c = arguments[0];
|
|
||||||
var d = arguments[1];
|
|
||||||
var a = "foo";
|
|
||||||
b++;
|
|
||||||
arguments[0] = "moo";
|
|
||||||
arguments[1] *= 2;
|
|
||||||
console.log(a, b, c, d, arguments[0], arguments[1]);
|
|
||||||
})("bar", 42);
|
|
||||||
}
|
|
||||||
expect_stdout: "foo 43 bar 42 moo 84"
|
|
||||||
}
|
|
||||||
|
|
||||||
duplicate_argname: {
|
|
||||||
options = {
|
|
||||||
arguments: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
(function(a, b, a) {
|
|
||||||
console.log(a, b, arguments[0], arguments[1], arguments[2]);
|
|
||||||
})("foo", 42, "bar");
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
(function(a, b, a) {
|
|
||||||
console.log(a, b, arguments[0], b, a);
|
|
||||||
})("foo", 42, "bar");
|
|
||||||
}
|
|
||||||
expect_stdout: "bar 42 foo 42 bar"
|
|
||||||
}
|
|
||||||
@@ -1,3 +1,5 @@
|
|||||||
|
// 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,,];
|
||||||
@@ -91,6 +93,79 @@ 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,
|
||||||
|
|||||||
656
test/compress/arrow.js
Normal file
656
test/compress/arrow.js
Normal file
@@ -0,0 +1,656 @@
|
|||||||
|
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"
|
||||||
|
}
|
||||||
323
test/compress/async.js
Normal file
323
test/compress/async.js
Normal file
@@ -0,0 +1,323 @@
|
|||||||
|
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};"
|
||||||
|
}
|
||||||
191
test/compress/block-scope.js
Normal file
191
test/compress/block-scope.js
Normal file
@@ -0,0 +1,191 @@
|
|||||||
|
|
||||||
|
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 = 1;
|
||||||
|
class Zee {};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
{
|
||||||
|
let y;
|
||||||
|
}
|
||||||
|
{
|
||||||
|
var y;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
function x(){
|
||||||
|
{
|
||||||
|
let x
|
||||||
|
}
|
||||||
|
var x;
|
||||||
|
{
|
||||||
|
const y = 1;
|
||||||
|
class Zee {}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
{
|
||||||
|
let y
|
||||||
|
}
|
||||||
|
var y;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
remove_unused_in_global_block: {
|
||||||
|
options = {
|
||||||
|
unused: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
{
|
||||||
|
let x;
|
||||||
|
const y = 1;
|
||||||
|
class Zee {};
|
||||||
|
var w;
|
||||||
|
}
|
||||||
|
let ex;
|
||||||
|
const why = 2;
|
||||||
|
class Zed {};
|
||||||
|
var wut;
|
||||||
|
console.log(x, y, Zee);
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
var w;
|
||||||
|
let ex;
|
||||||
|
const why = 2;
|
||||||
|
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,3 +47,142 @@ 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
@@ -1,42 +1,62 @@
|
|||||||
comparisons: {
|
keep_comparisons: {
|
||||||
options = {
|
options = {
|
||||||
comparisons: true,
|
comparisons: true,
|
||||||
|
unsafe_comps: false
|
||||||
}
|
}
|
||||||
input: {
|
input: {
|
||||||
var obj1, obj2;
|
var obj1 = {
|
||||||
|
valueOf: function() {triggeredFirst();}
|
||||||
|
}
|
||||||
|
var obj2 = {
|
||||||
|
valueOf: function() {triggeredSecond();}
|
||||||
|
}
|
||||||
var result1 = obj1 <= obj2;
|
var result1 = obj1 <= obj2;
|
||||||
var result2 = obj1 < obj2;
|
var result2 = obj1 < obj2;
|
||||||
var result3 = obj1 >= obj2;
|
var result3 = obj1 >= obj2;
|
||||||
var result4 = obj1 > obj2;
|
var result4 = obj1 > obj2;
|
||||||
}
|
}
|
||||||
expect: {
|
expect: {
|
||||||
var obj1, obj2;
|
var obj1 = {
|
||||||
|
valueOf: function() {triggeredFirst();}
|
||||||
|
}
|
||||||
|
var obj2 = {
|
||||||
|
valueOf: function() {triggeredSecond();}
|
||||||
|
}
|
||||||
var result1 = obj1 <= obj2;
|
var result1 = obj1 <= obj2;
|
||||||
var result2 = obj1 < obj2;
|
var result2 = obj1 < obj2;
|
||||||
var result3 = obj2 <= obj1;
|
var result3 = obj1 >= obj2;
|
||||||
var result4 = obj2 < obj1;
|
var result4 = obj1 > obj2;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
unsafe_comps: {
|
keep_comparisons_with_unsafe_comps: {
|
||||||
options = {
|
options = {
|
||||||
comparisons: true,
|
comparisons: true,
|
||||||
conditionals: true,
|
unsafe_comps: true
|
||||||
unsafe_comps: true,
|
|
||||||
}
|
}
|
||||||
input: {
|
input: {
|
||||||
var obj1, obj2;
|
var obj1 = {
|
||||||
obj1 <= obj2 ? f1() : g1();
|
valueOf: function() {triggeredFirst();}
|
||||||
obj1 < obj2 ? f2() : g2();
|
}
|
||||||
obj1 >= obj2 ? f3() : g3();
|
var obj2 = {
|
||||||
obj1 > obj2 ? f4() : g4();
|
valueOf: function() {triggeredSecond();}
|
||||||
|
}
|
||||||
|
var result1 = obj1 <= obj2;
|
||||||
|
var result2 = obj1 < obj2;
|
||||||
|
var result3 = obj1 >= obj2;
|
||||||
|
var result4 = obj1 > obj2;
|
||||||
}
|
}
|
||||||
expect: {
|
expect: {
|
||||||
var obj1, obj2;
|
var obj1 = {
|
||||||
obj2 < obj1 ? g1() : f1();
|
valueOf: function() {triggeredFirst();}
|
||||||
obj1 < obj2 ? f2() : g2();
|
}
|
||||||
obj1 < obj2 ? g3() : f3();
|
var obj2 = {
|
||||||
obj2 < obj1 ? f4() : g4();
|
valueOf: function() {triggeredSecond();}
|
||||||
|
}
|
||||||
|
var result1 = obj2 >= obj1;
|
||||||
|
var result2 = obj2 > obj1;
|
||||||
|
var result3 = obj1 >= obj2;
|
||||||
|
var result4 = obj1 > obj2;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -92,206 +112,3 @@ 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"
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -332,7 +332,7 @@ cond_7: {
|
|||||||
x = 'foo';
|
x = 'foo';
|
||||||
x = 'foo';
|
x = 'foo';
|
||||||
x = (condition(), 20);
|
x = (condition(), 20);
|
||||||
x = (z || condition(), 'fuji');
|
x = z ? 'fuji' : (condition(), 'fuji');
|
||||||
x = (condition(), 'foobar');
|
x = (condition(), 'foobar');
|
||||||
x = y ? a : b;
|
x = y ? a : b;
|
||||||
x = y ? 'foo' : 'fo';
|
x = y ? 'foo' : 'fo';
|
||||||
@@ -703,11 +703,10 @@ ternary_boolean_alternative: {
|
|||||||
|
|
||||||
trivial_boolean_ternary_expressions : {
|
trivial_boolean_ternary_expressions : {
|
||||||
options = {
|
options = {
|
||||||
booleans: true,
|
|
||||||
conditionals: true,
|
conditionals: true,
|
||||||
evaluate: true,
|
evaluate : true,
|
||||||
side_effects: true,
|
booleans : true
|
||||||
}
|
};
|
||||||
input: {
|
input: {
|
||||||
f('foo' in m ? true : false);
|
f('foo' in m ? true : false);
|
||||||
f('foo' in m ? false : true);
|
f('foo' in m ? false : true);
|
||||||
|
|||||||
170
test/compress/const.js
Normal file
170
test/compress/const.js
Normal file
@@ -0,0 +1,170 @@
|
|||||||
|
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,12 +54,52 @@ dead_code_2_should_warn: {
|
|||||||
x = 10;
|
x = 10;
|
||||||
throw new Error("foo");
|
throw new Error("foo");
|
||||||
var x;
|
var x;
|
||||||
function g(){};
|
var g;
|
||||||
}
|
}
|
||||||
f();
|
f();
|
||||||
}
|
}
|
||||||
expect_stdout: true
|
expect_stdout: true
|
||||||
node_version: "<=4"
|
node_version: ">=6"
|
||||||
|
}
|
||||||
|
|
||||||
|
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: {
|
||||||
@@ -86,7 +126,7 @@ dead_code_constant_boolean_should_warn_more: {
|
|||||||
}
|
}
|
||||||
expect: {
|
expect: {
|
||||||
var foo;
|
var foo;
|
||||||
function bar() {}
|
var 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;
|
||||||
@@ -94,7 +134,198 @@ dead_code_constant_boolean_should_warn_more: {
|
|||||||
bar();
|
bar();
|
||||||
}
|
}
|
||||||
expect_stdout: true
|
expect_stdout: true
|
||||||
node_version: "<=4"
|
node_version: ">=6"
|
||||||
|
}
|
||||||
|
|
||||||
|
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: {
|
||||||
@@ -342,6 +573,70 @@ global_fns: {
|
|||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
issue_2383_1: {
|
||||||
|
options = {
|
||||||
|
conditionals: true,
|
||||||
|
dead_code: true,
|
||||||
|
evaluate: true,
|
||||||
|
side_effects: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
if (0) {
|
||||||
|
var {x, y} = foo();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
var x, y;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
issue_2383_2: {
|
||||||
|
options = {
|
||||||
|
conditionals: true,
|
||||||
|
dead_code: true,
|
||||||
|
evaluate: true,
|
||||||
|
side_effects: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
if (0) {
|
||||||
|
var {
|
||||||
|
x = 0,
|
||||||
|
y: [ w, , { z, p: q = 7 } ] = [ 1, 2, { z: 3 } ]
|
||||||
|
} = {};
|
||||||
|
}
|
||||||
|
console.log(x, q, w, z);
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
var x, w, z, q;
|
||||||
|
console.log(x, q, w, z);
|
||||||
|
}
|
||||||
|
expect_stdout: "undefined undefined undefined undefined"
|
||||||
|
node_version: ">=6"
|
||||||
|
}
|
||||||
|
|
||||||
|
issue_2383_3: {
|
||||||
|
options = {
|
||||||
|
conditionals: true,
|
||||||
|
dead_code: true,
|
||||||
|
evaluate: true,
|
||||||
|
side_effects: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
var b = 7, y = 8;
|
||||||
|
if (0) {
|
||||||
|
var a = 1, [ x, y, z ] = [ 2, 3, 4 ], b = 5;
|
||||||
|
}
|
||||||
|
console.log(a, x, y, z, b);
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
var b = 7, y = 8;
|
||||||
|
var a, x, y, z, b;
|
||||||
|
console.log(a, x, y, z, b);
|
||||||
|
}
|
||||||
|
expect_stdout: "undefined undefined 8 undefined 7"
|
||||||
|
node_version: ">=6"
|
||||||
|
}
|
||||||
|
|
||||||
collapse_vars_assignment: {
|
collapse_vars_assignment: {
|
||||||
options = {
|
options = {
|
||||||
collapse_vars: true,
|
collapse_vars: true,
|
||||||
@@ -862,83 +1157,3 @@ issue_2749: {
|
|||||||
}
|
}
|
||||||
expect_stdout: "PASS"
|
expect_stdout: "PASS"
|
||||||
}
|
}
|
||||||
|
|
||||||
unsafe_builtin: {
|
|
||||||
options = {
|
|
||||||
side_effects: true,
|
|
||||||
unsafe: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
(!w).constructor(x);
|
|
||||||
Math.abs(y);
|
|
||||||
[ 1, 2, z ].valueOf();
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
w, x;
|
|
||||||
y;
|
|
||||||
z;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
issue_2860_1: {
|
|
||||||
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"
|
|
||||||
}
|
|
||||||
|
|
||||||
issue_2929: {
|
|
||||||
options = {
|
|
||||||
dead_code: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
console.log(function(a) {
|
|
||||||
try {
|
|
||||||
return null.p = a = 1;
|
|
||||||
} catch (e) {
|
|
||||||
return a ? "PASS" : "FAIL";
|
|
||||||
}
|
|
||||||
}());
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
console.log(function(a) {
|
|
||||||
try {
|
|
||||||
return null.p = a = 1;
|
|
||||||
} catch (e) {
|
|
||||||
return a ? "PASS" : "FAIL";
|
|
||||||
}
|
|
||||||
}());
|
|
||||||
}
|
|
||||||
expect_stdout: "PASS"
|
|
||||||
}
|
|
||||||
|
|||||||
662
test/compress/destructuring.js
Normal file
662
test/compress/destructuring.js
Normal file
@@ -0,0 +1,662 @@
|
|||||||
|
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"
|
||||||
|
}
|
||||||
10
test/compress/directives.js
Normal file
10
test/compress/directives.js
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
class_directives_compression: {
|
||||||
|
input: {
|
||||||
|
class foo {
|
||||||
|
foo() {
|
||||||
|
"use strict";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
expect_exact: "class foo{foo(){}}"
|
||||||
|
}
|
||||||
@@ -164,6 +164,87 @@ used_var_in_catch: {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
unused_block_decls_in_catch: {
|
||||||
|
options = { unused: true };
|
||||||
|
input: {
|
||||||
|
function foo() {
|
||||||
|
try {
|
||||||
|
foo();
|
||||||
|
} catch(ex) {
|
||||||
|
let x = 10;
|
||||||
|
const y = 10;
|
||||||
|
class Zee {};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
function foo() {
|
||||||
|
try {
|
||||||
|
foo();
|
||||||
|
} catch(ex) {}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
used_block_decls_in_catch: {
|
||||||
|
options = { unused: true };
|
||||||
|
input: {
|
||||||
|
function foo() {
|
||||||
|
try {
|
||||||
|
foo();
|
||||||
|
} catch(ex) {
|
||||||
|
let x = 10;
|
||||||
|
const y = 10;
|
||||||
|
class Zee {};
|
||||||
|
}
|
||||||
|
console.log(x, y, Zee);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
function foo() {
|
||||||
|
try {
|
||||||
|
foo();
|
||||||
|
} catch(ex) {}
|
||||||
|
console.log(x, y, Zee);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
unused_block_decls: {
|
||||||
|
options = { unused: true };
|
||||||
|
input: {
|
||||||
|
function foo() {
|
||||||
|
{
|
||||||
|
const x = 1;
|
||||||
|
}
|
||||||
|
{
|
||||||
|
let y;
|
||||||
|
}
|
||||||
|
console.log(x, y);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
function foo() {
|
||||||
|
console.log(x, y);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
unused_keep_harmony_destructuring: {
|
||||||
|
options = { unused: true };
|
||||||
|
input: {
|
||||||
|
function foo() {
|
||||||
|
var {x, y} = foo;
|
||||||
|
var a = foo;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
function foo() {
|
||||||
|
var {x, y} = foo;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
keep_fnames: {
|
keep_fnames: {
|
||||||
options = { unused: true, keep_fnames: true, unsafe: true };
|
options = { unused: true, keep_fnames: true, unsafe: true };
|
||||||
input: {
|
input: {
|
||||||
@@ -683,6 +764,38 @@ drop_value: {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const_assign: {
|
||||||
|
options = {
|
||||||
|
evaluate: true,
|
||||||
|
reduce_funcs: true,
|
||||||
|
reduce_vars: true,
|
||||||
|
unused: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
function f() {
|
||||||
|
const b = 2;
|
||||||
|
return 1 + b;
|
||||||
|
}
|
||||||
|
|
||||||
|
function g() {
|
||||||
|
const b = 2;
|
||||||
|
b = 3;
|
||||||
|
return 1 + b;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
function f() {
|
||||||
|
return 3;
|
||||||
|
}
|
||||||
|
|
||||||
|
function g() {
|
||||||
|
const b = 2;
|
||||||
|
b = 3;
|
||||||
|
return 1 + b;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
issue_1539: {
|
issue_1539: {
|
||||||
options = {
|
options = {
|
||||||
collapse_vars: true,
|
collapse_vars: true,
|
||||||
@@ -821,6 +934,10 @@ issue_1709: {
|
|||||||
var x = 1;
|
var x = 1;
|
||||||
return x;
|
return x;
|
||||||
}(),
|
}(),
|
||||||
|
function y() {
|
||||||
|
const y = 2;
|
||||||
|
return y;
|
||||||
|
}(),
|
||||||
function z() {
|
function z() {
|
||||||
function z() {}
|
function z() {}
|
||||||
return z;
|
return z;
|
||||||
@@ -833,6 +950,10 @@ issue_1709: {
|
|||||||
var x = 1;
|
var x = 1;
|
||||||
return x;
|
return x;
|
||||||
}(),
|
}(),
|
||||||
|
function() {
|
||||||
|
const y = 2;
|
||||||
|
return y;
|
||||||
|
}(),
|
||||||
function() {
|
function() {
|
||||||
function z() {}
|
function z() {}
|
||||||
return z;
|
return z;
|
||||||
@@ -1116,6 +1237,7 @@ var_catch_toplevel: {
|
|||||||
options = {
|
options = {
|
||||||
conditionals: true,
|
conditionals: true,
|
||||||
negate_iife: true,
|
negate_iife: true,
|
||||||
|
passes: 2,
|
||||||
reduce_funcs: true,
|
reduce_funcs: true,
|
||||||
reduce_vars: true,
|
reduce_vars: true,
|
||||||
side_effects: true,
|
side_effects: true,
|
||||||
@@ -1146,6 +1268,71 @@ var_catch_toplevel: {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
reassign_const: {
|
||||||
|
options = {
|
||||||
|
collapse_vars: true,
|
||||||
|
sequences: true,
|
||||||
|
side_effects: true,
|
||||||
|
unused: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
function f() {
|
||||||
|
const a = 1;
|
||||||
|
a = 2;
|
||||||
|
return a;
|
||||||
|
}
|
||||||
|
console.log(f());
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
function f() {
|
||||||
|
const a = 1;
|
||||||
|
return a = 2, a;
|
||||||
|
}
|
||||||
|
console.log(f());
|
||||||
|
}
|
||||||
|
expect_stdout: true
|
||||||
|
}
|
||||||
|
|
||||||
|
issue_1968: {
|
||||||
|
options = {
|
||||||
|
unused: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
function f(c) {
|
||||||
|
var a;
|
||||||
|
if (c) {
|
||||||
|
let b;
|
||||||
|
return (a = 2) + (b = 3);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
console.log(f(1));
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
function f(c) {
|
||||||
|
if (c) {
|
||||||
|
let b;
|
||||||
|
return 2 + (b = 3);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
console.log(f(1));
|
||||||
|
}
|
||||||
|
expect_stdout: "5"
|
||||||
|
node_version: ">=6"
|
||||||
|
}
|
||||||
|
|
||||||
|
issue_2063: {
|
||||||
|
options = {
|
||||||
|
unused: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
var a;
|
||||||
|
var a;
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
var a;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
issue_2105_1: {
|
issue_2105_1: {
|
||||||
options = {
|
options = {
|
||||||
collapse_vars: true,
|
collapse_vars: true,
|
||||||
@@ -1226,6 +1413,95 @@ issue_2105_2: {
|
|||||||
expect_stdout: "PASS"
|
expect_stdout: "PASS"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
issue_2136_1: {
|
||||||
|
options = {
|
||||||
|
inline: true,
|
||||||
|
unused: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
!function(a, ...b) {
|
||||||
|
console.log(b);
|
||||||
|
}();
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
!function(a, ...b) {
|
||||||
|
console.log(b);
|
||||||
|
}();
|
||||||
|
}
|
||||||
|
expect_stdout: "[]"
|
||||||
|
node_version: ">=6"
|
||||||
|
}
|
||||||
|
|
||||||
|
issue_2136_2: {
|
||||||
|
options = {
|
||||||
|
collapse_vars: true,
|
||||||
|
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 = {
|
||||||
|
collapse_vars: true,
|
||||||
|
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"
|
||||||
|
}
|
||||||
|
|
||||||
|
issue_2163: {
|
||||||
|
options = {
|
||||||
|
pure_funcs: [ "pure" ],
|
||||||
|
side_effects: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
var c;
|
||||||
|
/*@__PURE__*/f(...a);
|
||||||
|
pure(b, ...c);
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
var c;
|
||||||
|
a;
|
||||||
|
b;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
issue_2226_1: {
|
issue_2226_1: {
|
||||||
options = {
|
options = {
|
||||||
side_effects: true,
|
side_effects: true,
|
||||||
@@ -1414,6 +1690,104 @@ issue_2516_2: {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
issue_2418_1: {
|
||||||
|
options = {
|
||||||
|
unused: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
class C {}
|
||||||
|
function F() {}
|
||||||
|
(class c {});
|
||||||
|
(function f() {});
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
class C {}
|
||||||
|
function F() {}
|
||||||
|
(class {});
|
||||||
|
(function() {});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
issue_2418_2: {
|
||||||
|
options = {
|
||||||
|
keep_classnames: false,
|
||||||
|
keep_fnames: false,
|
||||||
|
unused: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
class C {}
|
||||||
|
function F() {}
|
||||||
|
(class c {});
|
||||||
|
(function f() {});
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
class C {}
|
||||||
|
function F() {}
|
||||||
|
(class {});
|
||||||
|
(function() {});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
issue_2418_3: {
|
||||||
|
options = {
|
||||||
|
keep_classnames: false,
|
||||||
|
keep_fnames: true,
|
||||||
|
unused: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
class C {}
|
||||||
|
function F() {}
|
||||||
|
(class c {});
|
||||||
|
(function f() {});
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
class C {}
|
||||||
|
function F() {}
|
||||||
|
(class {});
|
||||||
|
(function f() {});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
issue_2418_4: {
|
||||||
|
options = {
|
||||||
|
keep_classnames: true,
|
||||||
|
keep_fnames: false,
|
||||||
|
unused: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
class C {}
|
||||||
|
function F() {}
|
||||||
|
(class c {});
|
||||||
|
(function f() {});
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
class C {}
|
||||||
|
function F() {}
|
||||||
|
(class c {});
|
||||||
|
(function() {});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
issue_2418_5: {
|
||||||
|
options = {
|
||||||
|
keep_classnames: true,
|
||||||
|
keep_fnames: true,
|
||||||
|
unused: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
class C {}
|
||||||
|
function F() {}
|
||||||
|
(class c {});
|
||||||
|
(function f() {});
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
class C {}
|
||||||
|
function F() {}
|
||||||
|
(class c {});
|
||||||
|
(function f() {});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
defun_lambda_same_name: {
|
defun_lambda_same_name: {
|
||||||
options = {
|
options = {
|
||||||
toplevel: true,
|
toplevel: true,
|
||||||
@@ -1692,265 +2066,3 @@ issue_2768: {
|
|||||||
}
|
}
|
||||||
expect_stdout: "PASS undefined"
|
expect_stdout: "PASS undefined"
|
||||||
}
|
}
|
||||||
|
|
||||||
issue_2846: {
|
|
||||||
options = {
|
|
||||||
collapse_vars: true,
|
|
||||||
reduce_vars: true,
|
|
||||||
toplevel: true,
|
|
||||||
unused: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
function f(a, b) {
|
|
||||||
var a = 0;
|
|
||||||
b && b(a);
|
|
||||||
return a++;
|
|
||||||
}
|
|
||||||
var c = f();
|
|
||||||
console.log(c);
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
var c = function(a, b) {
|
|
||||||
a = 0;
|
|
||||||
b && b(a);
|
|
||||||
return a++;
|
|
||||||
}();
|
|
||||||
console.log(c);
|
|
||||||
}
|
|
||||||
expect_stdout: "0"
|
|
||||||
}
|
|
||||||
|
|
||||||
issue_805_1: {
|
|
||||||
options = {
|
|
||||||
inline: true,
|
|
||||||
passes: 2,
|
|
||||||
pure_getters: "strict",
|
|
||||||
reduce_vars: true,
|
|
||||||
sequences: true,
|
|
||||||
side_effects: true,
|
|
||||||
unused: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
(function(a) {
|
|
||||||
var unused = function() {};
|
|
||||||
unused.prototype[a()] = 42;
|
|
||||||
(unused.prototype.bar = function() {
|
|
||||||
console.log("bar");
|
|
||||||
})();
|
|
||||||
return unused;
|
|
||||||
})(function() {
|
|
||||||
console.log("foo");
|
|
||||||
return "foo";
|
|
||||||
});
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
console.log("foo"),
|
|
||||||
console.log("bar");
|
|
||||||
}
|
|
||||||
expect_stdout: [
|
|
||||||
"foo",
|
|
||||||
"bar",
|
|
||||||
]
|
|
||||||
}
|
|
||||||
|
|
||||||
issue_805_2: {
|
|
||||||
options = {
|
|
||||||
inline: true,
|
|
||||||
passes: 2,
|
|
||||||
pure_getters: "strict",
|
|
||||||
reduce_vars: true,
|
|
||||||
sequences: true,
|
|
||||||
side_effects: true,
|
|
||||||
unused: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
(function(a) {
|
|
||||||
function unused() {}
|
|
||||||
unused.prototype[a()] = 42;
|
|
||||||
(unused.prototype.bar = function() {
|
|
||||||
console.log("bar");
|
|
||||||
})();
|
|
||||||
return unused;
|
|
||||||
})(function() {
|
|
||||||
console.log("foo");
|
|
||||||
return "foo";
|
|
||||||
});
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
console.log("foo"),
|
|
||||||
console.log("bar");
|
|
||||||
}
|
|
||||||
expect_stdout: [
|
|
||||||
"foo",
|
|
||||||
"bar",
|
|
||||||
]
|
|
||||||
}
|
|
||||||
|
|
||||||
issue_2995: {
|
|
||||||
options = {
|
|
||||||
pure_getters: "strict",
|
|
||||||
reduce_vars: true,
|
|
||||||
unused: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
function f(a) {
|
|
||||||
var b;
|
|
||||||
a.b = b = function() {};
|
|
||||||
b.c = "PASS";
|
|
||||||
}
|
|
||||||
var o = {};
|
|
||||||
f(o);
|
|
||||||
console.log(o.b.c);
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
function f(a) {
|
|
||||||
var b;
|
|
||||||
a.b = b = function() {};
|
|
||||||
b.c = "PASS";
|
|
||||||
}
|
|
||||||
var o = {};
|
|
||||||
f(o);
|
|
||||||
console.log(o.b.c);
|
|
||||||
}
|
|
||||||
expect_stdout: "PASS"
|
|
||||||
}
|
|
||||||
|
|
||||||
issue_3146_1: {
|
|
||||||
options = {
|
|
||||||
collapse_vars: true,
|
|
||||||
unused: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
(function(f) {
|
|
||||||
f("g()");
|
|
||||||
})(function(a) {
|
|
||||||
eval(a);
|
|
||||||
function g(b) {
|
|
||||||
if (!b) b = "PASS";
|
|
||||||
console.log(b);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
(function(f) {
|
|
||||||
f("g()");
|
|
||||||
})(function(a) {
|
|
||||||
eval(a);
|
|
||||||
function g(b) {
|
|
||||||
if (!b) b = "PASS";
|
|
||||||
console.log(b);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
expect_stdout: "PASS"
|
|
||||||
}
|
|
||||||
|
|
||||||
issue_3146_2: {
|
|
||||||
options = {
|
|
||||||
reduce_vars: true,
|
|
||||||
unused: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
(function(f) {
|
|
||||||
f("g()");
|
|
||||||
})(function(a) {
|
|
||||||
eval(a);
|
|
||||||
function g(b) {
|
|
||||||
if (!b) b = "PASS";
|
|
||||||
console.log(b);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
(function(f) {
|
|
||||||
f("g()");
|
|
||||||
})(function(a) {
|
|
||||||
eval(a);
|
|
||||||
function g(b) {
|
|
||||||
if (!b) b = "PASS";
|
|
||||||
console.log(b);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
expect_stdout: "PASS"
|
|
||||||
}
|
|
||||||
|
|
||||||
issue_3146_3: {
|
|
||||||
options = {
|
|
||||||
collapse_vars: true,
|
|
||||||
unused: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
var g = "PASS";
|
|
||||||
(function(f) {
|
|
||||||
var g = "FAIL";
|
|
||||||
f("console.log(g)", g[g]);
|
|
||||||
})(function(a) {
|
|
||||||
eval(a);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
var g = "PASS";
|
|
||||||
(function(f) {
|
|
||||||
var g = "FAIL";
|
|
||||||
f("console.log(g)", g[g]);
|
|
||||||
})(function(a) {
|
|
||||||
eval(a);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
expect_stdout: "PASS"
|
|
||||||
}
|
|
||||||
|
|
||||||
issue_3146_4: {
|
|
||||||
options = {
|
|
||||||
reduce_vars: true,
|
|
||||||
unused: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
var g = "PASS";
|
|
||||||
(function(f) {
|
|
||||||
var g = "FAIL";
|
|
||||||
f("console.log(g)", g[g]);
|
|
||||||
})(function(a) {
|
|
||||||
eval(a);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
var g = "PASS";
|
|
||||||
(function(f) {
|
|
||||||
var g = "FAIL";
|
|
||||||
f("console.log(g)", g[g]);
|
|
||||||
})(function(a) {
|
|
||||||
eval(a);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
expect_stdout: "PASS"
|
|
||||||
}
|
|
||||||
|
|
||||||
issue_3192: {
|
|
||||||
options = {
|
|
||||||
unused: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
(function(a) {
|
|
||||||
console.log(a = "foo", arguments[0]);
|
|
||||||
})("bar");
|
|
||||||
(function(a) {
|
|
||||||
"use strict";
|
|
||||||
console.log(a = "foo", arguments[0]);
|
|
||||||
})("bar");
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
(function(a) {
|
|
||||||
console.log(a = "foo", arguments[0]);
|
|
||||||
})("bar");
|
|
||||||
(function(a) {
|
|
||||||
"use strict";
|
|
||||||
console.log("foo", arguments[0]);
|
|
||||||
})("bar");
|
|
||||||
}
|
|
||||||
expect_stdout: [
|
|
||||||
"foo foo",
|
|
||||||
"foo bar",
|
|
||||||
]
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -227,6 +227,100 @@ 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,
|
||||||
@@ -673,17 +767,16 @@ call_args: {
|
|||||||
inline: true,
|
inline: true,
|
||||||
reduce_funcs: true,
|
reduce_funcs: true,
|
||||||
reduce_vars: true,
|
reduce_vars: true,
|
||||||
toplevel: true,
|
|
||||||
}
|
}
|
||||||
input: {
|
input: {
|
||||||
var a = 1;
|
const a = 1;
|
||||||
console.log(a);
|
console.log(a);
|
||||||
+function(a) {
|
+function(a) {
|
||||||
return a;
|
return a;
|
||||||
}(a);
|
}(a);
|
||||||
}
|
}
|
||||||
expect: {
|
expect: {
|
||||||
var a = 1;
|
const a = 1;
|
||||||
console.log(1);
|
console.log(1);
|
||||||
+(1, 1);
|
+(1, 1);
|
||||||
}
|
}
|
||||||
@@ -697,17 +790,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: {
|
||||||
var a = 1;
|
const 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);
|
||||||
}
|
}
|
||||||
@@ -745,7 +838,7 @@ in_boolean_context: {
|
|||||||
!b("foo"),
|
!b("foo"),
|
||||||
!b([1, 2]),
|
!b([1, 2]),
|
||||||
!b(/foo/),
|
!b(/foo/),
|
||||||
(foo(), !1),
|
![1, foo()],
|
||||||
(foo(), !1)
|
(foo(), !1)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -1194,9 +1287,6 @@ 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: {
|
||||||
@@ -1211,23 +1301,6 @@ 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: {
|
||||||
@@ -1350,259 +1423,13 @@ issue_2535_3: {
|
|||||||
}
|
}
|
||||||
expect_stdout: true
|
expect_stdout: true
|
||||||
expect_warnings: [
|
expect_warnings: [
|
||||||
"WARN: Dropping side-effect-free && [test/compress/evaluate.js:1336,20]",
|
"WARN: Dropping side-effect-free && [test/compress/evaluate.js:1409,20]",
|
||||||
"WARN: Dropping side-effect-free && [test/compress/evaluate.js:1337,20]",
|
"WARN: Dropping side-effect-free && [test/compress/evaluate.js:1410,20]",
|
||||||
"WARN: Dropping side-effect-free && [test/compress/evaluate.js:1338,20]",
|
"WARN: Dropping side-effect-free && [test/compress/evaluate.js:1411,20]",
|
||||||
"WARN: Condition left of && always false [test/compress/evaluate.js:1338,20]",
|
"WARN: Condition left of && always false [test/compress/evaluate.js:1411,20]",
|
||||||
"WARN: Dropping side-effect-free || [test/compress/evaluate.js:1339,20]",
|
"WARN: Dropping side-effect-free || [test/compress/evaluate.js:1412,20]",
|
||||||
"WARN: Dropping side-effect-free || [test/compress/evaluate.js:1340,20]",
|
"WARN: Dropping side-effect-free || [test/compress/evaluate.js:1413,20]",
|
||||||
"WARN: Dropping side-effect-free || [test/compress/evaluate.js:1341,20]",
|
"WARN: Dropping side-effect-free || [test/compress/evaluate.js:1414,20]",
|
||||||
"WARN: Condition left of || always true [test/compress/evaluate.js:1341,20]",
|
"WARN: Condition left of || always true [test/compress/evaluate.js:1414,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",
|
|
||||||
]
|
|
||||||
}
|
|
||||||
|
|
||||||
issue_2916_1: {
|
|
||||||
options = {
|
|
||||||
evaluate: true,
|
|
||||||
reduce_vars: true,
|
|
||||||
unsafe: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
var c = "PASS";
|
|
||||||
(function(a, b) {
|
|
||||||
(function(d) {
|
|
||||||
d[0] = 1;
|
|
||||||
})(b);
|
|
||||||
a == b && (c = "FAIL");
|
|
||||||
})("", []);
|
|
||||||
console.log(c);
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
var c = "PASS";
|
|
||||||
(function(a, b) {
|
|
||||||
(function(d) {
|
|
||||||
d[0] = 1;
|
|
||||||
})(b);
|
|
||||||
a == b && (c = "FAIL");
|
|
||||||
})("", []);
|
|
||||||
console.log(c);
|
|
||||||
}
|
|
||||||
expect_stdout: "PASS"
|
|
||||||
}
|
|
||||||
|
|
||||||
issue_2916_2: {
|
|
||||||
options = {
|
|
||||||
collapse_vars: true,
|
|
||||||
evaluate: true,
|
|
||||||
inline: true,
|
|
||||||
reduce_vars: true,
|
|
||||||
side_effects: true,
|
|
||||||
unsafe: true,
|
|
||||||
unused: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
var c = "FAIL";
|
|
||||||
(function(b) {
|
|
||||||
(function(d) {
|
|
||||||
d[0] = 1;
|
|
||||||
})(b);
|
|
||||||
+b && (c = "PASS");
|
|
||||||
})([]);
|
|
||||||
console.log(c);
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
var c = "FAIL";
|
|
||||||
(function(b) {
|
|
||||||
b[0] = 1;
|
|
||||||
+b && (c = "PASS");
|
|
||||||
})([]);
|
|
||||||
console.log(c);
|
|
||||||
}
|
|
||||||
expect_stdout: "PASS"
|
|
||||||
}
|
|
||||||
|
|
||||||
issue_2919: {
|
|
||||||
options = {
|
|
||||||
evaluate: true,
|
|
||||||
unsafe: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
console.log([ function() {} ].toString());
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
console.log("function(){}");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
issue_2926_1: {
|
|
||||||
options = {
|
|
||||||
evaluate: true,
|
|
||||||
reduce_vars: true,
|
|
||||||
unsafe: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
(function f(a) {
|
|
||||||
console.log(f.name.length, f.length);
|
|
||||||
})();
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
(function f(a) {
|
|
||||||
console.log(1, 1);
|
|
||||||
})();
|
|
||||||
}
|
|
||||||
expect_stdout: "1 1"
|
|
||||||
}
|
|
||||||
|
|
||||||
issue_2926_2: {
|
|
||||||
options = {
|
|
||||||
evaluate: true,
|
|
||||||
unsafe: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
console.log(typeof function() {}.valueOf());
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
console.log("function");
|
|
||||||
}
|
|
||||||
expect_stdout: "function"
|
|
||||||
}
|
|
||||||
|
|
||||||
issue_2968: {
|
|
||||||
options = {
|
|
||||||
collapse_vars: true,
|
|
||||||
evaluate: true,
|
|
||||||
inline: true,
|
|
||||||
passes: 2,
|
|
||||||
reduce_vars: true,
|
|
||||||
unused: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
var c = "FAIL";
|
|
||||||
(function() {
|
|
||||||
(function(a, b) {
|
|
||||||
a <<= 0;
|
|
||||||
a && (a[(c = "PASS", 0 >>> (b += 1))] = 0);
|
|
||||||
})(42, -42);
|
|
||||||
})();
|
|
||||||
console.log(c);
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
var c = "FAIL";
|
|
||||||
(function() {
|
|
||||||
b = -(a = 42),
|
|
||||||
void ((a <<= 0) && (a[(c = "PASS", 0 >>> (b += 1))] = 0));
|
|
||||||
var a, b;
|
|
||||||
})();
|
|
||||||
console.log(c);
|
|
||||||
}
|
|
||||||
expect_stdout: "PASS"
|
|
||||||
}
|
|
||||||
|
|
||||||
truthy_conditionals: {
|
|
||||||
options = {
|
|
||||||
conditionals: true,
|
|
||||||
evaluate: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
if (a = {}) x();
|
|
||||||
(b = /foo/) && y();
|
|
||||||
(c = function() {}) || z();
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
a = {}, x();
|
|
||||||
b = /foo/, y();
|
|
||||||
c = function() {};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
truthy_loops: {
|
|
||||||
options = {
|
|
||||||
evaluate: true,
|
|
||||||
loops: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
while ([]) x();
|
|
||||||
do {
|
|
||||||
y();
|
|
||||||
} while(a = {});
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
for (;;) {
|
|
||||||
[];
|
|
||||||
x();
|
|
||||||
}
|
|
||||||
for (;;) {
|
|
||||||
y();
|
|
||||||
a = {};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
71
test/compress/expansions.js
Normal file
71
test/compress/expansions.js
Normal file
@@ -0,0 +1,71 @@
|
|||||||
|
|
||||||
|
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], m = Math;
|
||||||
|
|
||||||
|
if (m)
|
||||||
|
print(a);
|
||||||
|
else
|
||||||
|
print(b);
|
||||||
|
|
||||||
|
if (m)
|
||||||
|
print(...a);
|
||||||
|
else
|
||||||
|
print(b);
|
||||||
|
|
||||||
|
if (m.no_such_property)
|
||||||
|
print(a);
|
||||||
|
else
|
||||||
|
print(...b);
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
function print(...x) {
|
||||||
|
console.log(...x);
|
||||||
|
}
|
||||||
|
var a = [ 1, 2 ], b = [ 3, 4 ], m = Math;
|
||||||
|
print(m ? a : b);
|
||||||
|
m ? print(...a) : print(b);
|
||||||
|
m.no_such_property ? print(a) : print(...b);
|
||||||
|
}
|
||||||
|
expect_stdout: [
|
||||||
|
"[ 1, 2 ]",
|
||||||
|
"1 2",
|
||||||
|
"3 4",
|
||||||
|
]
|
||||||
|
node_version: ">=6"
|
||||||
|
}
|
||||||
446
test/compress/export.js
Normal file
446
test/compress/export.js
Normal file
@@ -0,0 +1,446 @@
|
|||||||
|
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;"
|
||||||
|
}
|
||||||
|
|
||||||
|
export_default_anonymous_function: {
|
||||||
|
options = {
|
||||||
|
reduce_vars: true,
|
||||||
|
toplevel: true,
|
||||||
|
unused: true,
|
||||||
|
}
|
||||||
|
mangle = {
|
||||||
|
toplevel: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
export default function () {
|
||||||
|
foo();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
expect_exact: "export default function(){foo()};"
|
||||||
|
}
|
||||||
|
|
||||||
|
export_default_arrow: {
|
||||||
|
options = {
|
||||||
|
reduce_vars: true,
|
||||||
|
toplevel: true,
|
||||||
|
unused: true,
|
||||||
|
}
|
||||||
|
mangle = {
|
||||||
|
toplevel: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
export default () => foo();
|
||||||
|
}
|
||||||
|
expect_exact: "export default()=>foo();"
|
||||||
|
}
|
||||||
|
|
||||||
|
export_default_anonymous_generator: {
|
||||||
|
options = {
|
||||||
|
reduce_vars: true,
|
||||||
|
toplevel: true,
|
||||||
|
unused: true,
|
||||||
|
}
|
||||||
|
mangle = {
|
||||||
|
toplevel: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
export default function * () {
|
||||||
|
yield foo();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
expect_exact: "export default function*(){yield foo()};"
|
||||||
|
}
|
||||||
|
|
||||||
|
export_default_anonymous_async_function: {
|
||||||
|
options = {
|
||||||
|
reduce_vars: true,
|
||||||
|
toplevel: true,
|
||||||
|
unused: true,
|
||||||
|
}
|
||||||
|
mangle = {
|
||||||
|
toplevel: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
export default async function() {
|
||||||
|
return await foo();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
expect_exact: "export default async function(){return await foo()};"
|
||||||
|
}
|
||||||
|
|
||||||
|
export_default_async_arrow_function: {
|
||||||
|
options = {
|
||||||
|
reduce_vars: true,
|
||||||
|
toplevel: true,
|
||||||
|
unused: true,
|
||||||
|
}
|
||||||
|
mangle = {
|
||||||
|
toplevel: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
export default async () => await foo();
|
||||||
|
}
|
||||||
|
expect_exact: "export default async()=>await foo();"
|
||||||
|
}
|
||||||
|
|
||||||
|
export_default_named_generator: {
|
||||||
|
options = {
|
||||||
|
reduce_vars: true,
|
||||||
|
toplevel: true,
|
||||||
|
unused: true,
|
||||||
|
}
|
||||||
|
mangle = {
|
||||||
|
toplevel: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
export default function * gen() {
|
||||||
|
yield foo();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
expect_exact: "export default function*gen(){yield foo()};"
|
||||||
|
}
|
||||||
|
|
||||||
|
export_default_named_async_function: {
|
||||||
|
options = {
|
||||||
|
reduce_vars: true,
|
||||||
|
toplevel: true,
|
||||||
|
unused: true,
|
||||||
|
}
|
||||||
|
mangle = {
|
||||||
|
toplevel: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
export default async function bar() {
|
||||||
|
return await foo();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
expect_exact: "export default async function bar(){return await foo()};"
|
||||||
|
}
|
||||||
|
|
||||||
|
export_default_anonymous_class: {
|
||||||
|
options = {
|
||||||
|
reduce_vars: true,
|
||||||
|
toplevel: true,
|
||||||
|
unused: true,
|
||||||
|
}
|
||||||
|
mangle = {
|
||||||
|
toplevel: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
export default class {
|
||||||
|
constructor() {
|
||||||
|
foo();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
expect_exact: "export default class{constructor(){foo()}};"
|
||||||
|
}
|
||||||
|
|
||||||
|
export_default_anonymous_function_not_call: {
|
||||||
|
options = {
|
||||||
|
reduce_vars: true,
|
||||||
|
toplevel: true,
|
||||||
|
unused: true,
|
||||||
|
}
|
||||||
|
mangle = {
|
||||||
|
toplevel: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
export default function(){}(foo);
|
||||||
|
}
|
||||||
|
// FIXME: should be `export default function(){};foo;`
|
||||||
|
expect_exact: "export default function(){}(foo);"
|
||||||
|
}
|
||||||
|
|
||||||
|
export_default_anonymous_generator_not_call: {
|
||||||
|
options = {
|
||||||
|
reduce_vars: true,
|
||||||
|
toplevel: true,
|
||||||
|
unused: true,
|
||||||
|
}
|
||||||
|
mangle = {
|
||||||
|
toplevel: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
export default function*(){}(foo);
|
||||||
|
}
|
||||||
|
// agrees with `acorn` and `babylon 7`
|
||||||
|
expect_exact: "export default function*(){};foo;"
|
||||||
|
}
|
||||||
|
|
||||||
|
export_default_anonymous_async_function_not_call: {
|
||||||
|
options = {
|
||||||
|
reduce_vars: true,
|
||||||
|
toplevel: true,
|
||||||
|
unused: true,
|
||||||
|
}
|
||||||
|
mangle = {
|
||||||
|
toplevel: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
export default async function(){}(foo);
|
||||||
|
}
|
||||||
|
// agrees with `acorn` and `babylon 7`
|
||||||
|
expect_exact: "export default async function(){};foo;"
|
||||||
|
}
|
||||||
52
test/compress/expression.js
Normal file
52
test/compress/expression.js
Normal file
@@ -0,0 +1,52 @@
|
|||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -193,32 +193,72 @@ hoist_funs: {
|
|||||||
console.log(6, typeof f, typeof g);
|
console.log(6, typeof f, typeof g);
|
||||||
}
|
}
|
||||||
expect: {
|
expect: {
|
||||||
function f() {}
|
|
||||||
function g() {}
|
function g() {}
|
||||||
console.log(1, typeof f, typeof g);
|
console.log(1, typeof f, typeof g);
|
||||||
if (console.log(2, typeof f, typeof g))
|
if (console.log(2, typeof f, typeof g))
|
||||||
console.log(3, typeof f, typeof g);
|
console.log(3, typeof f, typeof g);
|
||||||
else {
|
else {
|
||||||
console.log(4, typeof f, typeof g);
|
console.log(4, typeof f, typeof g);
|
||||||
|
function f() {}
|
||||||
console.log(5, typeof f, typeof g);
|
console.log(5, typeof f, typeof g);
|
||||||
}
|
}
|
||||||
console.log(6, typeof f, typeof g);
|
console.log(6, typeof f, typeof g);
|
||||||
}
|
}
|
||||||
expect_stdout: [
|
expect_stdout: [
|
||||||
"1 'function' 'function'",
|
"1 'undefined' 'function'",
|
||||||
"2 'function' 'function'",
|
"2 'undefined' 'function'",
|
||||||
"4 'function' 'function'",
|
"4 'function' 'function'",
|
||||||
"5 'function' 'function'",
|
"5 'function' 'function'",
|
||||||
"6 'function' 'function'",
|
"6 'function' 'function'",
|
||||||
]
|
]
|
||||||
node_version: "<=4"
|
node_version: ">=6"
|
||||||
|
}
|
||||||
|
|
||||||
|
hoist_funs_strict: {
|
||||||
|
options = {
|
||||||
|
hoist_funs: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
"use strict";
|
||||||
|
console.log(1, typeof f, typeof g);
|
||||||
|
if (console.log(2, typeof f, typeof g))
|
||||||
|
console.log(3, typeof f, typeof g);
|
||||||
|
else {
|
||||||
|
console.log(4, typeof f, typeof g);
|
||||||
|
function f() {}
|
||||||
|
console.log(5, typeof f, typeof g);
|
||||||
|
}
|
||||||
|
function g() {}
|
||||||
|
console.log(6, typeof f, typeof g);
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
"use strict";
|
||||||
|
function g() {}
|
||||||
|
console.log(1, typeof f, typeof g);
|
||||||
|
if (console.log(2, typeof f, typeof g))
|
||||||
|
console.log(3, typeof f, typeof g);
|
||||||
|
else {
|
||||||
|
console.log(4, typeof f, typeof g);
|
||||||
|
function f() {}
|
||||||
|
console.log(5, typeof f, typeof g);
|
||||||
|
}
|
||||||
|
console.log(6, typeof f, typeof g);
|
||||||
|
}
|
||||||
|
expect_stdout: [
|
||||||
|
"1 'undefined' 'function'",
|
||||||
|
"2 'undefined' 'function'",
|
||||||
|
"4 'function' 'function'",
|
||||||
|
"5 'function' 'function'",
|
||||||
|
"6 'undefined' 'function'",
|
||||||
|
]
|
||||||
|
node_version: ">=4"
|
||||||
}
|
}
|
||||||
|
|
||||||
issue_203: {
|
issue_203: {
|
||||||
options = {
|
options = {
|
||||||
keep_fargs: false,
|
keep_fargs: false,
|
||||||
side_effects: true,
|
side_effects: true,
|
||||||
unsafe_Function: true,
|
unsafe_Func: true,
|
||||||
unused: true,
|
unused: true,
|
||||||
}
|
}
|
||||||
input: {
|
input: {
|
||||||
@@ -292,12 +332,11 @@ issue_2084: {
|
|||||||
}
|
}
|
||||||
expect: {
|
expect: {
|
||||||
var c = 0;
|
var c = 0;
|
||||||
!function() {
|
!function(c) {
|
||||||
var c;
|
c = 1 + c,
|
||||||
c = 1 + (c = -1),
|
|
||||||
c = 1 + (c = 0),
|
c = 1 + (c = 0),
|
||||||
0 !== 23..toString() && (c = 1 + c);
|
0 !== 23..toString() && (c = 1 + c);
|
||||||
}(),
|
}(-1),
|
||||||
console.log(c);
|
console.log(c);
|
||||||
}
|
}
|
||||||
expect_stdout: "0"
|
expect_stdout: "0"
|
||||||
@@ -951,6 +990,20 @@ unsafe_apply_2: {
|
|||||||
expect_stdout: true
|
expect_stdout: true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
unsafe_apply_expansion: {
|
||||||
|
options = {
|
||||||
|
unsafe: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
console.log.apply(console, [1, ...[2, 3], 4]);
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
console.log.call(console, 1, ...[2, 3], 4);
|
||||||
|
}
|
||||||
|
expect_stdout: "1 2 3 4"
|
||||||
|
node_version: ">=6"
|
||||||
|
}
|
||||||
|
|
||||||
unsafe_call_1: {
|
unsafe_call_1: {
|
||||||
options = {
|
options = {
|
||||||
inline: true,
|
inline: true,
|
||||||
@@ -1029,6 +1082,25 @@ unsafe_call_3: {
|
|||||||
expect_stdout: "3"
|
expect_stdout: "3"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
unsafe_call_expansion: {
|
||||||
|
options = {
|
||||||
|
unsafe: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
(function(...a) {
|
||||||
|
console.log(...a);
|
||||||
|
}).call(console, 1, ...[2, 3], 4);
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
console,
|
||||||
|
(function(...a) {
|
||||||
|
console.log(...a);
|
||||||
|
})(1, ...[2, 3], 4);
|
||||||
|
}
|
||||||
|
expect_stdout: "1 2 3 4"
|
||||||
|
node_version: ">=6"
|
||||||
|
}
|
||||||
|
|
||||||
issue_2616: {
|
issue_2616: {
|
||||||
options = {
|
options = {
|
||||||
evaluate: true,
|
evaluate: true,
|
||||||
@@ -1052,9 +1124,11 @@ issue_2616: {
|
|||||||
}
|
}
|
||||||
expect: {
|
expect: {
|
||||||
var c = "FAIL";
|
var c = "FAIL";
|
||||||
!function(NaN) {
|
(function() {
|
||||||
(true << NaN) - 0/0 || (c = "PASS");
|
!function(NaN) {
|
||||||
}([]);
|
(true << NaN) - 0/0 || (c = "PASS");
|
||||||
|
}([]);
|
||||||
|
})();
|
||||||
console.log(c);
|
console.log(c);
|
||||||
}
|
}
|
||||||
expect_stdout: "PASS"
|
expect_stdout: "PASS"
|
||||||
@@ -1085,11 +1159,13 @@ issue_2620_1: {
|
|||||||
}
|
}
|
||||||
expect: {
|
expect: {
|
||||||
var c = "FAIL";
|
var c = "FAIL";
|
||||||
!function(a) {
|
(function() {
|
||||||
if (function(a) {
|
(function(a) {
|
||||||
a && a();
|
if (function(a) {
|
||||||
}(), a) c = "PASS";
|
a && a();
|
||||||
}(1),
|
}(), a) c = "PASS";
|
||||||
|
})(1);
|
||||||
|
})(),
|
||||||
console.log(c);
|
console.log(c);
|
||||||
}
|
}
|
||||||
expect_stdout: "PASS"
|
expect_stdout: "PASS"
|
||||||
@@ -1157,16 +1233,18 @@ issue_2620_3: {
|
|||||||
}
|
}
|
||||||
expect: {
|
expect: {
|
||||||
var c = "FAIL";
|
var c = "FAIL";
|
||||||
!function(a, NaN) {
|
(function() {
|
||||||
(function() {
|
(function(a, NaN) {
|
||||||
switch (a) {
|
(function() {
|
||||||
case a:
|
switch (a) {
|
||||||
break;
|
case a:
|
||||||
case c = "PASS", NaN:
|
break;
|
||||||
break;
|
case c = "PASS", NaN:
|
||||||
}
|
break;
|
||||||
})();
|
}
|
||||||
}(NaN);
|
})();
|
||||||
|
})(NaN);
|
||||||
|
})();
|
||||||
console.log(c);
|
console.log(c);
|
||||||
}
|
}
|
||||||
expect_stdout: "PASS"
|
expect_stdout: "PASS"
|
||||||
@@ -1336,9 +1414,11 @@ issue_2630_4: {
|
|||||||
}
|
}
|
||||||
expect: {
|
expect: {
|
||||||
var x = 3, a = 1, b = 2;
|
var x = 3, a = 1, b = 2;
|
||||||
!function() {
|
(function() {
|
||||||
while (--x >= 0 && void (b += ++a));
|
(function() {
|
||||||
}();
|
while (--x >= 0 && void (a++, b += a));
|
||||||
|
})();
|
||||||
|
})();
|
||||||
console.log(a);
|
console.log(a);
|
||||||
}
|
}
|
||||||
expect_stdout: "2"
|
expect_stdout: "2"
|
||||||
@@ -1377,6 +1457,99 @@ issue_2630_5: {
|
|||||||
expect_stdout: "155"
|
expect_stdout: "155"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
issue_2647_1: {
|
||||||
|
options = {
|
||||||
|
inline: true,
|
||||||
|
reduce_vars: true,
|
||||||
|
side_effects: true,
|
||||||
|
unused: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
(function(n, o = "FAIL") {
|
||||||
|
console.log(n);
|
||||||
|
})("PASS");
|
||||||
|
(function(n, o = "PASS") {
|
||||||
|
console.log(o);
|
||||||
|
})("FAIL");
|
||||||
|
(function(o = "PASS") {
|
||||||
|
console.log(o);
|
||||||
|
})();
|
||||||
|
(function(n, {o = "FAIL"}) {
|
||||||
|
console.log(n);
|
||||||
|
})("PASS", {});
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
console.log("PASS");
|
||||||
|
(function(n, o = "PASS") {
|
||||||
|
console.log(o);
|
||||||
|
})();
|
||||||
|
(function(o = "PASS") {
|
||||||
|
console.log(o);
|
||||||
|
})();
|
||||||
|
(function(n, {o = "FAIL"}) {
|
||||||
|
console.log("PASS");
|
||||||
|
})(0, {});
|
||||||
|
}
|
||||||
|
expect_stdout: [
|
||||||
|
"PASS",
|
||||||
|
"PASS",
|
||||||
|
"PASS",
|
||||||
|
"PASS",
|
||||||
|
]
|
||||||
|
node_version: ">=6"
|
||||||
|
}
|
||||||
|
|
||||||
|
issue_2647_2: {
|
||||||
|
options = {
|
||||||
|
collapse_vars: true,
|
||||||
|
inline: true,
|
||||||
|
reduce_vars: true,
|
||||||
|
unused: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
(function() {
|
||||||
|
function foo(x) {
|
||||||
|
return x.toUpperCase();
|
||||||
|
}
|
||||||
|
console.log((() => foo("pass"))());
|
||||||
|
}());
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
(function() {
|
||||||
|
console.log((() => (x = "pass", x.toUpperCase()))());
|
||||||
|
var x;
|
||||||
|
})();
|
||||||
|
}
|
||||||
|
expect_stdout: "PASS"
|
||||||
|
node_version: ">=4"
|
||||||
|
}
|
||||||
|
|
||||||
|
issue_2647_3: {
|
||||||
|
options = {
|
||||||
|
collapse_vars: true,
|
||||||
|
inline: true,
|
||||||
|
reduce_vars: true,
|
||||||
|
unused: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
(function() {
|
||||||
|
function foo(x) {
|
||||||
|
return x.toUpperCase();
|
||||||
|
}
|
||||||
|
console.log((() => {
|
||||||
|
return foo("pass");
|
||||||
|
})());
|
||||||
|
}());
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
(function() {
|
||||||
|
console.log("pass".toUpperCase());
|
||||||
|
})();
|
||||||
|
}
|
||||||
|
expect_stdout: "PASS"
|
||||||
|
node_version: ">=4"
|
||||||
|
}
|
||||||
|
|
||||||
recursive_inline_1: {
|
recursive_inline_1: {
|
||||||
options = {
|
options = {
|
||||||
inline: true,
|
inline: true,
|
||||||
@@ -1533,7 +1706,7 @@ issue_2663_3: {
|
|||||||
unused: true,
|
unused: true,
|
||||||
}
|
}
|
||||||
input: {
|
input: {
|
||||||
(function() {
|
(function () {
|
||||||
var outputs = [
|
var outputs = [
|
||||||
{ type: 0, target: null, eventName: "ngSubmit", propName: null },
|
{ type: 0, target: null, eventName: "ngSubmit", propName: null },
|
||||||
{ type: 0, target: null, eventName: "submit", propName: null },
|
{ type: 0, target: null, eventName: "submit", propName: null },
|
||||||
@@ -1550,11 +1723,11 @@ issue_2663_3: {
|
|||||||
return handlers;
|
return handlers;
|
||||||
}
|
}
|
||||||
function renderEventHandlerClosure(eventName) {
|
function renderEventHandlerClosure(eventName) {
|
||||||
return function() {
|
return function () {
|
||||||
return console.log(eventName);
|
return console.log(eventName);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
listenToElementOutputs(outputs).forEach(function(handler) {
|
listenToElementOutputs(outputs).forEach(function (handler) {
|
||||||
return handler()
|
return handler()
|
||||||
});
|
});
|
||||||
})();
|
})();
|
||||||
@@ -1634,7 +1807,7 @@ loop_init_arg: {
|
|||||||
}
|
}
|
||||||
input: {
|
input: {
|
||||||
var a = "PASS";
|
var a = "PASS";
|
||||||
for (var k in "12") (function(b) {
|
for (var k in "12") (function (b) {
|
||||||
(b >>= 1) && (a = "FAIL"), b = 2;
|
(b >>= 1) && (a = "FAIL"), b = 2;
|
||||||
})();
|
})();
|
||||||
console.log(a);
|
console.log(a);
|
||||||
@@ -1944,378 +2117,3 @@ issue_2737_2: {
|
|||||||
}
|
}
|
||||||
expect_stdout: "PASS"
|
expect_stdout: "PASS"
|
||||||
}
|
}
|
||||||
|
|
||||||
issue_2783: {
|
|
||||||
options = {
|
|
||||||
collapse_vars: true,
|
|
||||||
conditionals: true,
|
|
||||||
if_return: true,
|
|
||||||
inline: true,
|
|
||||||
reduce_vars: true,
|
|
||||||
unused: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
(function() {
|
|
||||||
return g;
|
|
||||||
function f(a) {
|
|
||||||
var b = a.b;
|
|
||||||
if (b) return b;
|
|
||||||
return a;
|
|
||||||
}
|
|
||||||
function g(o, i) {
|
|
||||||
while (i--) {
|
|
||||||
console.log(f(o));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
})()({ b: "PASS" }, 1);
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
(function() {
|
|
||||||
return function(o,i) {
|
|
||||||
while (i--) console.log(f(o));
|
|
||||||
};
|
|
||||||
function f(a) {
|
|
||||||
var b = a.b;
|
|
||||||
return b || a;
|
|
||||||
}
|
|
||||||
})()({ b: "PASS" },1);
|
|
||||||
}
|
|
||||||
expect_stdout: "PASS"
|
|
||||||
}
|
|
||||||
|
|
||||||
issue_2898: {
|
|
||||||
options = {
|
|
||||||
collapse_vars: true,
|
|
||||||
inline: true,
|
|
||||||
reduce_vars: true,
|
|
||||||
sequences: true,
|
|
||||||
unused: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
var c = 0;
|
|
||||||
(function() {
|
|
||||||
while (f());
|
|
||||||
function f() {
|
|
||||||
var b = (c = 1 + c, void (c = 1 + c));
|
|
||||||
b && b[0];
|
|
||||||
}
|
|
||||||
})();
|
|
||||||
console.log(c);
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
var c = 0;
|
|
||||||
(function() {
|
|
||||||
while (b = void 0, void ((b = void (c = 1 + (c = 1 + c))) && b[0]));
|
|
||||||
var b;
|
|
||||||
})(),
|
|
||||||
console.log(c);
|
|
||||||
}
|
|
||||||
expect_stdout: "2"
|
|
||||||
}
|
|
||||||
|
|
||||||
deduplicate_parenthesis: {
|
|
||||||
input: {
|
|
||||||
({}).a = b;
|
|
||||||
(({}).a = b)();
|
|
||||||
(function() {}).a = b;
|
|
||||||
((function() {}).a = b)();
|
|
||||||
}
|
|
||||||
expect_exact: "({}).a=b;({}.a=b)();(function(){}).a=b;(function(){}.a=b)();"
|
|
||||||
}
|
|
||||||
|
|
||||||
drop_lone_use_strict: {
|
|
||||||
options = {
|
|
||||||
side_effects: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
function f1() {
|
|
||||||
"use strict";
|
|
||||||
}
|
|
||||||
function f2() {
|
|
||||||
"use strict";
|
|
||||||
function f3() {
|
|
||||||
"use strict";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
(function f4() {
|
|
||||||
"use strict";
|
|
||||||
})();
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
function f1() {
|
|
||||||
}
|
|
||||||
function f2() {
|
|
||||||
"use strict";
|
|
||||||
function f3() {
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
issue_3016_1: {
|
|
||||||
options = {
|
|
||||||
inline: true,
|
|
||||||
toplevel: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
var b = 1;
|
|
||||||
do {
|
|
||||||
(function(a) {
|
|
||||||
return a[b];
|
|
||||||
var a;
|
|
||||||
})(3);
|
|
||||||
} while (0);
|
|
||||||
console.log(b);
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
var b = 1;
|
|
||||||
do {
|
|
||||||
a = 3,
|
|
||||||
a[b];
|
|
||||||
} while(0);
|
|
||||||
var a;
|
|
||||||
console.log(b);
|
|
||||||
}
|
|
||||||
expect_stdout: "1"
|
|
||||||
}
|
|
||||||
|
|
||||||
issue_3016_2: {
|
|
||||||
options = {
|
|
||||||
dead_code: true,
|
|
||||||
inline: true,
|
|
||||||
toplevel: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
var b = 1;
|
|
||||||
do {
|
|
||||||
(function(a) {
|
|
||||||
return a[b];
|
|
||||||
try {
|
|
||||||
a = 2;
|
|
||||||
} catch (a) {
|
|
||||||
var a;
|
|
||||||
}
|
|
||||||
})(3);
|
|
||||||
} while (0);
|
|
||||||
console.log(b);
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
var b = 1;
|
|
||||||
do {
|
|
||||||
a = 3,
|
|
||||||
a[b];
|
|
||||||
} while(0);
|
|
||||||
var a;
|
|
||||||
console.log(b);
|
|
||||||
}
|
|
||||||
expect_stdout: "1"
|
|
||||||
}
|
|
||||||
|
|
||||||
issue_3016_2_ie8: {
|
|
||||||
options = {
|
|
||||||
dead_code: true,
|
|
||||||
ie8: true,
|
|
||||||
inline: true,
|
|
||||||
toplevel: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
var b = 1;
|
|
||||||
do {
|
|
||||||
(function(a) {
|
|
||||||
return a[b];
|
|
||||||
try {
|
|
||||||
a = 2;
|
|
||||||
} catch (a) {
|
|
||||||
var a;
|
|
||||||
}
|
|
||||||
})(3);
|
|
||||||
} while (0);
|
|
||||||
console.log(b);
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
var b = 1;
|
|
||||||
do {
|
|
||||||
a = 3,
|
|
||||||
a[b];
|
|
||||||
} while(0);
|
|
||||||
var a;
|
|
||||||
console.log(b);
|
|
||||||
}
|
|
||||||
expect_stdout: "1"
|
|
||||||
}
|
|
||||||
|
|
||||||
issue_3016_3: {
|
|
||||||
options = {
|
|
||||||
dead_code: true,
|
|
||||||
inline: true,
|
|
||||||
toplevel: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
var b = 1;
|
|
||||||
do {
|
|
||||||
console.log(function() {
|
|
||||||
return a ? "FAIL" : a = "PASS";
|
|
||||||
try {
|
|
||||||
a = 2;
|
|
||||||
} catch (a) {
|
|
||||||
var a;
|
|
||||||
}
|
|
||||||
}());
|
|
||||||
} while (b--);
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
var b = 1;
|
|
||||||
do {
|
|
||||||
console.log((a = void 0, a ? "FAIL" : a = "PASS"));
|
|
||||||
} while(b--);
|
|
||||||
var a;
|
|
||||||
}
|
|
||||||
expect_stdout: [
|
|
||||||
"PASS",
|
|
||||||
"PASS",
|
|
||||||
]
|
|
||||||
}
|
|
||||||
|
|
||||||
issue_3016_3_ie8: {
|
|
||||||
options = {
|
|
||||||
dead_code: true,
|
|
||||||
ie8: true,
|
|
||||||
inline: true,
|
|
||||||
toplevel: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
var b = 1;
|
|
||||||
do {
|
|
||||||
console.log(function() {
|
|
||||||
return a ? "FAIL" : a = "PASS";
|
|
||||||
try {
|
|
||||||
a = 2;
|
|
||||||
} catch (a) {
|
|
||||||
var a;
|
|
||||||
}
|
|
||||||
}());
|
|
||||||
} while (b--);
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
var b = 1;
|
|
||||||
do {
|
|
||||||
console.log((a = void 0, a ? "FAIL" : a = "PASS"));
|
|
||||||
} while(b--);
|
|
||||||
var a;
|
|
||||||
}
|
|
||||||
expect_stdout: [
|
|
||||||
"PASS",
|
|
||||||
"PASS",
|
|
||||||
]
|
|
||||||
}
|
|
||||||
|
|
||||||
issue_3018: {
|
|
||||||
options = {
|
|
||||||
inline: true,
|
|
||||||
side_effects: true,
|
|
||||||
toplevel: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
var b = 1, c = "PASS";
|
|
||||||
do {
|
|
||||||
(function() {
|
|
||||||
(function(a) {
|
|
||||||
a = 0 != (a && (c = "FAIL"));
|
|
||||||
})();
|
|
||||||
})();
|
|
||||||
} while (b--);
|
|
||||||
console.log(c);
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
var b = 1, c = "PASS";
|
|
||||||
do {
|
|
||||||
a = void 0,
|
|
||||||
a = 0 != (a && (c = "FAIL"));
|
|
||||||
} while (b--);
|
|
||||||
var a;
|
|
||||||
console.log(c);
|
|
||||||
}
|
|
||||||
expect_stdout: "PASS"
|
|
||||||
}
|
|
||||||
|
|
||||||
issue_3054: {
|
|
||||||
options = {
|
|
||||||
booleans: true,
|
|
||||||
collapse_vars: true,
|
|
||||||
inline: 1,
|
|
||||||
reduce_vars: true,
|
|
||||||
toplevel: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
"use strict";
|
|
||||||
function f() {
|
|
||||||
return { a: true };
|
|
||||||
}
|
|
||||||
console.log(function(b) {
|
|
||||||
b = false;
|
|
||||||
return f();
|
|
||||||
}().a, f.call().a);
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
"use strict";
|
|
||||||
function f() {
|
|
||||||
return { a: !0 };
|
|
||||||
}
|
|
||||||
console.log(function(b) {
|
|
||||||
return { a: !(b = !1) };
|
|
||||||
}().a, f.call().a);
|
|
||||||
}
|
|
||||||
expect_stdout: "true true"
|
|
||||||
}
|
|
||||||
|
|
||||||
issue_3076: {
|
|
||||||
options = {
|
|
||||||
dead_code: true,
|
|
||||||
inline: true,
|
|
||||||
sequences: true,
|
|
||||||
unused: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
var c = "PASS";
|
|
||||||
(function(b) {
|
|
||||||
var n = 2;
|
|
||||||
while (--b + function() {
|
|
||||||
e && (c = "FAIL");
|
|
||||||
e = 5;
|
|
||||||
return 1;
|
|
||||||
try {
|
|
||||||
var a = 5;
|
|
||||||
} catch (e) {
|
|
||||||
var e;
|
|
||||||
}
|
|
||||||
}().toString() && --n > 0);
|
|
||||||
})(2);
|
|
||||||
console.log(c);
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
var c = "PASS";
|
|
||||||
(function(b) {
|
|
||||||
var n = 2;
|
|
||||||
while (--b + (e = void 0, e && (c = "FAIL"), e = 5, 1).toString() && --n > 0);
|
|
||||||
var e;
|
|
||||||
})(2),
|
|
||||||
console.log(c);
|
|
||||||
}
|
|
||||||
expect_stdout: "PASS"
|
|
||||||
}
|
|
||||||
|
|
||||||
issue_3125: {
|
|
||||||
options = {
|
|
||||||
inline: true,
|
|
||||||
unsafe: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
console.log(function() {
|
|
||||||
return "PASS";
|
|
||||||
}.call());
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
console.log("PASS");
|
|
||||||
}
|
|
||||||
expect_stdout: "PASS"
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -121,7 +121,7 @@ mixed: {
|
|||||||
properties: true,
|
properties: true,
|
||||||
}
|
}
|
||||||
input: {
|
input: {
|
||||||
var FOO = { BAR: 0 };
|
const 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: {
|
||||||
var FOO = { BAR: 0 };
|
const 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);
|
||||||
|
|||||||
1247
test/compress/harmony.js
Normal file
1247
test/compress/harmony.js
Normal file
File diff suppressed because it is too large
Load Diff
85
test/compress/hoist.js
Normal file
85
test/compress/hoist.js
Normal file
@@ -0,0 +1,85 @@
|
|||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -239,14 +239,14 @@ name_collision_2: {
|
|||||||
input: {
|
input: {
|
||||||
var o = {
|
var o = {
|
||||||
p: 1,
|
p: 1,
|
||||||
"+": function(x) {
|
0: function(x) {
|
||||||
return x;
|
return x;
|
||||||
},
|
},
|
||||||
"-": function(x) {
|
1: function(x) {
|
||||||
return x + 1;
|
return x + 1;
|
||||||
}
|
}
|
||||||
}, o__$0 = 2, o__$1 = 3;
|
}, o__$0 = 2, o__$1 = 3;
|
||||||
console.log(o.p === o.p, o["+"](4), o["-"](5), o__$0, o__$1);
|
console.log(o.p === o.p, o[0](4), o[1](5), o__$0, o__$1);
|
||||||
}
|
}
|
||||||
expect: {
|
expect: {
|
||||||
var o_p = 1,
|
var o_p = 1,
|
||||||
@@ -273,14 +273,14 @@ name_collision_3: {
|
|||||||
input: {
|
input: {
|
||||||
var o = {
|
var o = {
|
||||||
p: 1,
|
p: 1,
|
||||||
"+": function(x) {
|
0: function(x) {
|
||||||
return x;
|
return x;
|
||||||
},
|
},
|
||||||
"-": function(x) {
|
1: function(x) {
|
||||||
return x + 1;
|
return x + 1;
|
||||||
}
|
}
|
||||||
}, o__$0 = 2, o__$1 = 3;
|
}, o__$0 = 2, o__$1 = 3;
|
||||||
console.log(o.p === o.p, o["+"](4), o["-"](5));
|
console.log(o.p === o.p, o[0](4), o[1](5));
|
||||||
}
|
}
|
||||||
expect: {
|
expect: {
|
||||||
var o_p = 1,
|
var o_p = 1,
|
||||||
@@ -383,6 +383,124 @@ 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;
|
||||||
|
},
|
||||||
|
x: 1,
|
||||||
|
y: 2
|
||||||
|
};
|
||||||
|
console.log(o.p.name, o.p == o.p, o.p(o.x), o.p(o.y));
|
||||||
|
}
|
||||||
|
expect_stdout: "Foo true 10 20"
|
||||||
|
}
|
||||||
|
|
||||||
new_this: {
|
new_this: {
|
||||||
options = {
|
options = {
|
||||||
evaluate: true,
|
evaluate: true,
|
||||||
@@ -412,6 +530,26 @@ 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,
|
||||||
@@ -634,6 +772,31 @@ 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,
|
||||||
@@ -665,194 +828,72 @@ issue_2519: {
|
|||||||
expect_stdout: "5.5"
|
expect_stdout: "5.5"
|
||||||
}
|
}
|
||||||
|
|
||||||
undefined_key: {
|
toplevel_const: {
|
||||||
options = {
|
options = {
|
||||||
evaluate: true,
|
|
||||||
hoist_props: true,
|
hoist_props: true,
|
||||||
join_vars: true,
|
|
||||||
passes: 4,
|
|
||||||
reduce_vars: true,
|
reduce_vars: true,
|
||||||
toplevel: true,
|
toplevel: false,
|
||||||
unused: true,
|
|
||||||
}
|
}
|
||||||
input: {
|
input: {
|
||||||
var a, o = {};
|
const a = {
|
||||||
o[a] = 1;
|
b: 1,
|
||||||
o.b = 2;
|
c: 2
|
||||||
console.log(o[a] + o.b);
|
};
|
||||||
|
console.log(a.b + a.c);
|
||||||
}
|
}
|
||||||
expect: {
|
expect: {
|
||||||
console.log(3);
|
const a = {
|
||||||
|
b: 1,
|
||||||
|
c: 2
|
||||||
|
};
|
||||||
|
console.log(a.b + a.c);
|
||||||
}
|
}
|
||||||
expect_stdout: "3"
|
expect_stdout: "3"
|
||||||
}
|
}
|
||||||
|
|
||||||
issue_3021: {
|
toplevel_let: {
|
||||||
options = {
|
options = {
|
||||||
hoist_props: true,
|
hoist_props: true,
|
||||||
reduce_vars: true,
|
reduce_vars: true,
|
||||||
|
toplevel: false,
|
||||||
}
|
}
|
||||||
input: {
|
input: {
|
||||||
var a = 1, b = 2;
|
let a = {
|
||||||
(function() {
|
b: 1,
|
||||||
b = a;
|
c: 2
|
||||||
if (a++ + b--)
|
};
|
||||||
return 1;
|
console.log(a.b + a.c);
|
||||||
return;
|
|
||||||
var b = {};
|
|
||||||
})();
|
|
||||||
console.log(a, b);
|
|
||||||
}
|
}
|
||||||
expect: {
|
expect: {
|
||||||
var a = 1, b = 2;
|
let a = {
|
||||||
(function() {
|
b: 1,
|
||||||
b = a;
|
c: 2
|
||||||
if (a++ + b--)
|
};
|
||||||
return 1;
|
console.log(a.b + a.c);
|
||||||
return;
|
|
||||||
var b = {};
|
|
||||||
})();
|
|
||||||
console.log(a, b);
|
|
||||||
}
|
}
|
||||||
expect_stdout: "2 2"
|
expect_stdout: "3"
|
||||||
|
node_version: ">=6"
|
||||||
}
|
}
|
||||||
|
|
||||||
issue_3046: {
|
toplevel_var: {
|
||||||
options = {
|
options = {
|
||||||
hoist_props: true,
|
hoist_props: true,
|
||||||
reduce_vars: true,
|
reduce_vars: true,
|
||||||
|
toplevel: false,
|
||||||
}
|
}
|
||||||
input: {
|
input: {
|
||||||
console.log(function(a) {
|
var a = {
|
||||||
do {
|
b: 1,
|
||||||
var b = {
|
c: 2
|
||||||
c: a++
|
};
|
||||||
};
|
console.log(a.b + a.c);
|
||||||
} while (b.c && a);
|
|
||||||
return a;
|
|
||||||
}(0));
|
|
||||||
}
|
}
|
||||||
expect: {
|
expect: {
|
||||||
console.log(function(a) {
|
var a = {
|
||||||
do {
|
b: 1,
|
||||||
var b_c = a++;
|
c: 2
|
||||||
} while (b_c && a);
|
};
|
||||||
return a;
|
console.log(a.b + a.c);
|
||||||
}(0));
|
|
||||||
}
|
}
|
||||||
expect_stdout: "1"
|
expect_stdout: "3"
|
||||||
}
|
|
||||||
|
|
||||||
issue_3071_1: {
|
|
||||||
options = {
|
|
||||||
evaluate: true,
|
|
||||||
inline: true,
|
|
||||||
join_vars: true,
|
|
||||||
hoist_props: true,
|
|
||||||
passes: 3,
|
|
||||||
reduce_vars: true,
|
|
||||||
sequences: true,
|
|
||||||
side_effects: true,
|
|
||||||
toplevel: true,
|
|
||||||
unused: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
(function() {
|
|
||||||
var obj = {};
|
|
||||||
obj.one = 1;
|
|
||||||
obj.two = 2;
|
|
||||||
console.log(obj.one);
|
|
||||||
})();
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
console.log(1);
|
|
||||||
}
|
|
||||||
expect_stdout: "1"
|
|
||||||
}
|
|
||||||
|
|
||||||
issue_3071_2: {
|
|
||||||
options = {
|
|
||||||
evaluate: true,
|
|
||||||
inline: true,
|
|
||||||
join_vars: true,
|
|
||||||
hoist_props: true,
|
|
||||||
passes: 3,
|
|
||||||
reduce_vars: true,
|
|
||||||
sequences: true,
|
|
||||||
side_effects: true,
|
|
||||||
unused: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
(function() {
|
|
||||||
obj = {};
|
|
||||||
obj.one = 1;
|
|
||||||
obj.two = 2;
|
|
||||||
console.log(obj.one);
|
|
||||||
var obj;
|
|
||||||
})();
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
console.log(1);
|
|
||||||
}
|
|
||||||
expect_stdout: "1"
|
|
||||||
}
|
|
||||||
|
|
||||||
issue_3071_2_toplevel: {
|
|
||||||
options = {
|
|
||||||
evaluate: true,
|
|
||||||
inline: true,
|
|
||||||
join_vars: true,
|
|
||||||
hoist_props: true,
|
|
||||||
passes: 3,
|
|
||||||
reduce_vars: true,
|
|
||||||
sequences: true,
|
|
||||||
side_effects: true,
|
|
||||||
toplevel: true,
|
|
||||||
unused: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
(function() {
|
|
||||||
obj = {};
|
|
||||||
obj.one = 1;
|
|
||||||
obj.two = 2;
|
|
||||||
console.log(obj.one);
|
|
||||||
var obj;
|
|
||||||
})();
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
console.log(1);
|
|
||||||
}
|
|
||||||
expect_stdout: "1"
|
|
||||||
}
|
|
||||||
|
|
||||||
issue_3071_3: {
|
|
||||||
options = {
|
|
||||||
hoist_props: true,
|
|
||||||
reduce_vars: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
var c = 0;
|
|
||||||
(function(a, b) {
|
|
||||||
(function f(o) {
|
|
||||||
var n = 2;
|
|
||||||
while (--b + (o = {
|
|
||||||
p: c++,
|
|
||||||
}) && --n > 0);
|
|
||||||
})();
|
|
||||||
})();
|
|
||||||
console.log(c);
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
var c = 0;
|
|
||||||
(function(a, b) {
|
|
||||||
(function f(o) {
|
|
||||||
var n = 2;
|
|
||||||
while (--b + (o = {
|
|
||||||
p: c++,
|
|
||||||
}) && --n > 0);
|
|
||||||
})();
|
|
||||||
})();
|
|
||||||
console.log(c);
|
|
||||||
}
|
|
||||||
expect_stdout: "2"
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -53,3 +53,12 @@ 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;"
|
||||||
|
}
|
||||||
|
|||||||
@@ -243,7 +243,7 @@ issue_1089: {
|
|||||||
expect: {
|
expect: {
|
||||||
function x() {
|
function x() {
|
||||||
var f = document.getElementById("fname");
|
var f = document.getElementById("fname");
|
||||||
if (12345 < f.files[0].size)
|
if (f.files[0].size > 12345)
|
||||||
return alert("alert"), f.focus(), !1;
|
return alert("alert"), f.focus(), !1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -327,6 +327,64 @@ issue_512: {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
issue_1317: {
|
||||||
|
options = {
|
||||||
|
if_return: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
!function(a) {
|
||||||
|
if (a) return;
|
||||||
|
let b = 1;
|
||||||
|
function g() {
|
||||||
|
return b;
|
||||||
|
}
|
||||||
|
console.log(g());
|
||||||
|
}();
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
!function(a) {
|
||||||
|
if (a) return;
|
||||||
|
let b = 1;
|
||||||
|
function g() {
|
||||||
|
return b;
|
||||||
|
}
|
||||||
|
console.log(g());
|
||||||
|
}();
|
||||||
|
}
|
||||||
|
expect_stdout: "1"
|
||||||
|
node_version: ">=6"
|
||||||
|
}
|
||||||
|
|
||||||
|
issue_1317_strict: {
|
||||||
|
options = {
|
||||||
|
if_return: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
"use strict";
|
||||||
|
!function(a) {
|
||||||
|
if (a) return;
|
||||||
|
let b = 1;
|
||||||
|
function g() {
|
||||||
|
return b;
|
||||||
|
}
|
||||||
|
console.log(g());
|
||||||
|
}();
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
"use strict";
|
||||||
|
!function(a) {
|
||||||
|
if (a) return;
|
||||||
|
let b = 1;
|
||||||
|
function g() {
|
||||||
|
return b;
|
||||||
|
}
|
||||||
|
console.log(g());
|
||||||
|
}();
|
||||||
|
}
|
||||||
|
expect_stdout: "1"
|
||||||
|
node_version: ">=4"
|
||||||
|
}
|
||||||
|
|
||||||
if_var_return: {
|
if_var_return: {
|
||||||
options = {
|
options = {
|
||||||
conditionals: true,
|
conditionals: true,
|
||||||
@@ -396,3 +454,39 @@ if_if_return_return: {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
issue_2747: {
|
||||||
|
options = {
|
||||||
|
conditionals: true,
|
||||||
|
if_return: true,
|
||||||
|
sequences: true,
|
||||||
|
unused: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
"use strict";
|
||||||
|
function f(baz) {
|
||||||
|
if (baz === 0) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
let r;
|
||||||
|
if (baz > 2) {
|
||||||
|
r = 4;
|
||||||
|
} else {
|
||||||
|
r = 5;
|
||||||
|
}
|
||||||
|
return r;
|
||||||
|
}
|
||||||
|
console.log(f(0), f(1), f(3));
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
"use strict";
|
||||||
|
function f(baz) {
|
||||||
|
if (0 === baz) return null;
|
||||||
|
let r;
|
||||||
|
return r = baz > 2 ? 4 : 5, r;
|
||||||
|
}
|
||||||
|
console.log(f(0), f(1), f(3));
|
||||||
|
}
|
||||||
|
expect_stdout: "null 5 4"
|
||||||
|
node_version: ">=4"
|
||||||
|
}
|
||||||
|
|||||||
8
test/compress/issue-1001.js
Normal file
8
test/compress/issue-1001.js
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
parenthesis_strings_in_parenthesis: {
|
||||||
|
input: {
|
||||||
|
var foo = ('(');
|
||||||
|
a(')');
|
||||||
|
|
||||||
|
}
|
||||||
|
expect_exact: 'var foo="(";a(")");'
|
||||||
|
}
|
||||||
@@ -1,3 +1,16 @@
|
|||||||
|
const_declaration: {
|
||||||
|
options = {
|
||||||
|
evaluate: true
|
||||||
|
};
|
||||||
|
|
||||||
|
input: {
|
||||||
|
const goog = goog || {};
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
const goog = goog || {};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const_pragma: {
|
const_pragma: {
|
||||||
options = {
|
options = {
|
||||||
evaluate: true,
|
evaluate: true,
|
||||||
|
|||||||
30
test/compress/issue-1043.js
Normal file
30
test/compress/issue-1043.js
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
9
test/compress/issue-1044.js
Normal file
9
test/compress/issue-1044.js
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
issue_1044: {
|
||||||
|
options = { evaluate: true, conditionals: true };
|
||||||
|
input: {
|
||||||
|
const mixed = Base ? class extends Base {} : class {}
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
const mixed = Base ? class extends Base {} : class {}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -134,9 +134,8 @@ defun_hoist_funs: {
|
|||||||
expect: {
|
expect: {
|
||||||
function e() {
|
function e() {
|
||||||
function f() {}
|
function f() {}
|
||||||
function g() {}
|
|
||||||
function h() {}
|
function h() {}
|
||||||
if (window);
|
if (window) function g() {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
76
test/compress/issue-1212.js
Normal file
76
test/compress/issue-1212.js
Normal file
@@ -0,0 +1,76 @@
|
|||||||
|
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,
|
||||||
|
collapse_vars : 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,
|
||||||
|
collapse_vars : 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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@@ -175,8 +175,8 @@ should_warn: {
|
|||||||
"WARN: Dropping __PURE__ call [test/compress/issue-1261.js:141,31]",
|
"WARN: Dropping __PURE__ call [test/compress/issue-1261.js:141,31]",
|
||||||
"WARN: Condition always true [test/compress/issue-1261.js:141,8]",
|
"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:143,8]",
|
|
||||||
"WARN: Dropping __PURE__ call [test/compress/issue-1261.js:143,24]",
|
"WARN: Dropping __PURE__ call [test/compress/issue-1261.js:143,24]",
|
||||||
|
"WARN: Condition always true [test/compress/issue-1261.js:143,8]",
|
||||||
"WARN: Dropping __PURE__ call [test/compress/issue-1261.js:144,31]",
|
"WARN: Dropping __PURE__ call [test/compress/issue-1261.js:144,31]",
|
||||||
"WARN: Condition always false [test/compress/issue-1261.js:144,8]",
|
"WARN: Condition always false [test/compress/issue-1261.js:144,8]",
|
||||||
]
|
]
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ unsafe_undefined: {
|
|||||||
options = {
|
options = {
|
||||||
conditionals: true,
|
conditionals: true,
|
||||||
if_return: true,
|
if_return: true,
|
||||||
unsafe_undefined: true,
|
unsafe: true
|
||||||
}
|
}
|
||||||
mangle = {}
|
mangle = {}
|
||||||
input: {
|
input: {
|
||||||
@@ -30,7 +30,7 @@ keep_fnames: {
|
|||||||
options = {
|
options = {
|
||||||
conditionals: true,
|
conditionals: true,
|
||||||
if_return: true,
|
if_return: true,
|
||||||
unsafe_undefined: true,
|
unsafe: true
|
||||||
}
|
}
|
||||||
mangle = {
|
mangle = {
|
||||||
keep_fnames: true
|
keep_fnames: true
|
||||||
|
|||||||
284
test/compress/issue-1466.js
Normal file
284
test/compress/issue-1466.js
Normal file
@@ -0,0 +1,284 @@
|
|||||||
|
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,
|
||||||
|
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,
|
||||||
|
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,
|
||||||
|
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,
|
||||||
|
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,
|
||||||
|
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,
|
||||||
|
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,
|
||||||
|
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_undefined: true,
|
unsafe: true,
|
||||||
}
|
}
|
||||||
mangle = {}
|
mangle = {}
|
||||||
input: {
|
input: {
|
||||||
@@ -85,3 +85,15 @@ 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
|
||||||
|
}
|
||||||
|
|||||||
@@ -104,7 +104,7 @@ mangle_catch_toplevel: {
|
|||||||
}
|
}
|
||||||
console.log(a);
|
console.log(a);
|
||||||
}
|
}
|
||||||
expect_exact: 'var c="FAIL";try{throw 1}catch(o){c="PASS"}console.log(c);'
|
expect_exact: 'var o="FAIL";try{throw 1}catch(c){o="PASS"}console.log(o);'
|
||||||
expect_stdout: "PASS"
|
expect_stdout: "PASS"
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -148,7 +148,7 @@ mangle_catch_var_toplevel: {
|
|||||||
}
|
}
|
||||||
console.log(a);
|
console.log(a);
|
||||||
}
|
}
|
||||||
expect_exact: 'var r="FAIL";try{throw 1}catch(o){var r="PASS"}console.log(r);'
|
expect_exact: 'var o="FAIL";try{throw 1}catch(r){var o="PASS"}console.log(o);'
|
||||||
expect_stdout: "PASS"
|
expect_stdout: "PASS"
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -345,95 +345,3 @@ mangle_catch_redef_2_ie8_toplevel: {
|
|||||||
expect_exact: 'try{throw"FAIL1"}catch(o){var o="FAIL2"}console.log(o);'
|
expect_exact: 'try{throw"FAIL1"}catch(o){var o="FAIL2"}console.log(o);'
|
||||||
expect_stdout: "undefined"
|
expect_stdout: "undefined"
|
||||||
}
|
}
|
||||||
|
|
||||||
mangle_catch_redef_3: {
|
|
||||||
mangle = {
|
|
||||||
ie8: false,
|
|
||||||
toplevel: false,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
var o = "PASS";
|
|
||||||
try {
|
|
||||||
throw 0;
|
|
||||||
} catch (o) {
|
|
||||||
(function() {
|
|
||||||
function f() {
|
|
||||||
o = "FAIL";
|
|
||||||
}
|
|
||||||
f(), f();
|
|
||||||
})();
|
|
||||||
}
|
|
||||||
console.log(o);
|
|
||||||
}
|
|
||||||
expect_exact: 'var o="PASS";try{throw 0}catch(o){(function(){function c(){o="FAIL"}c(),c()})()}console.log(o);'
|
|
||||||
expect_stdout: "PASS"
|
|
||||||
}
|
|
||||||
|
|
||||||
mangle_catch_redef_3_toplevel: {
|
|
||||||
mangle = {
|
|
||||||
ie8: false,
|
|
||||||
toplevel: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
var o = "PASS";
|
|
||||||
try {
|
|
||||||
throw 0;
|
|
||||||
} catch (o) {
|
|
||||||
(function() {
|
|
||||||
function f() {
|
|
||||||
o = "FAIL";
|
|
||||||
}
|
|
||||||
f(), f();
|
|
||||||
})();
|
|
||||||
}
|
|
||||||
console.log(o);
|
|
||||||
}
|
|
||||||
expect_exact: 'var c="PASS";try{throw 0}catch(c){(function(){function o(){c="FAIL"}o(),o()})()}console.log(c);'
|
|
||||||
expect_stdout: "PASS"
|
|
||||||
}
|
|
||||||
|
|
||||||
mangle_catch_redef_ie8_3: {
|
|
||||||
mangle = {
|
|
||||||
ie8: true,
|
|
||||||
toplevel: false,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
var o = "PASS";
|
|
||||||
try {
|
|
||||||
throw 0;
|
|
||||||
} catch (o) {
|
|
||||||
(function() {
|
|
||||||
function f() {
|
|
||||||
o = "FAIL";
|
|
||||||
}
|
|
||||||
f(), f();
|
|
||||||
})();
|
|
||||||
}
|
|
||||||
console.log(o);
|
|
||||||
}
|
|
||||||
expect_exact: 'var o="PASS";try{throw 0}catch(o){(function(){function c(){o="FAIL"}c(),c()})()}console.log(o);'
|
|
||||||
expect_stdout: "PASS"
|
|
||||||
}
|
|
||||||
|
|
||||||
mangle_catch_redef_3_ie8_toplevel: {
|
|
||||||
mangle = {
|
|
||||||
ie8: true,
|
|
||||||
toplevel: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
var o = "PASS";
|
|
||||||
try {
|
|
||||||
throw 0;
|
|
||||||
} catch (o) {
|
|
||||||
(function() {
|
|
||||||
function f() {
|
|
||||||
o = "FAIL";
|
|
||||||
}
|
|
||||||
f(), f();
|
|
||||||
})();
|
|
||||||
}
|
|
||||||
console.log(o);
|
|
||||||
}
|
|
||||||
expect_exact: 'var c="PASS";try{throw 0}catch(c){(function(){function o(){c="FAIL"}o(),o()})()}console.log(c);'
|
|
||||||
expect_stdout: "PASS"
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ function_iife_catch: {
|
|||||||
}
|
}
|
||||||
f();
|
f();
|
||||||
}
|
}
|
||||||
expect_exact: "function f(o){!function(){try{throw 0}catch(o){var c=1;console.log(o,c)}}()}f();"
|
expect_exact: "function f(o){!function(){try{throw 0}catch(c){var o=1;console.log(c,o)}}()}f();"
|
||||||
expect_stdout: "0 1"
|
expect_stdout: "0 1"
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -36,7 +36,7 @@ function_iife_catch_ie8: {
|
|||||||
}
|
}
|
||||||
f();
|
f();
|
||||||
}
|
}
|
||||||
expect_exact: "function f(c){!function(){try{throw 0}catch(c){var o=1;console.log(c,o)}}()}f();"
|
expect_exact: "function f(o){!function(){try{throw 0}catch(o){var c=1;console.log(o,c)}}()}f();"
|
||||||
expect_stdout: "0 1"
|
expect_stdout: "0 1"
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -61,7 +61,7 @@ function_catch_catch: {
|
|||||||
}
|
}
|
||||||
f();
|
f();
|
||||||
}
|
}
|
||||||
expect_exact: "var o=0;function f(){try{throw 1}catch(o){try{throw 2}catch(c){var c=3;console.log(c)}}console.log(c)}f();"
|
expect_exact: "var o=0;function f(){try{throw 1}catch(c){try{throw 2}catch(o){var o=3;console.log(o)}}console.log(o)}f();"
|
||||||
expect_stdout: [
|
expect_stdout: [
|
||||||
"3",
|
"3",
|
||||||
"undefined",
|
"undefined",
|
||||||
|
|||||||
@@ -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,',
|
||||||
' 1e42: 8',
|
' "1e+42": 8',
|
||||||
'};',
|
'};',
|
||||||
'',
|
'',
|
||||||
'console.log(obj[-0], obj[-""], obj["-0"]);',
|
'console.log(obj[-0], obj[-""], obj["-0"]);',
|
||||||
@@ -107,139 +107,3 @@ 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,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
283
test/compress/issue-2001.js
Normal file
283
test/compress/issue-2001.js
Normal file
@@ -0,0 +1,283 @@
|
|||||||
|
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();"
|
||||||
|
}
|
||||||
57
test/compress/issue-203.js
Normal file
57
test/compress/issue-203.js
Normal file
@@ -0,0 +1,57 @@
|
|||||||
|
|
||||||
|
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: {
|
||||||
var ENV = 3;
|
const 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: {
|
||||||
var ENV = 3;
|
const 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,12]',
|
'WARN: global_defs ENV redefined [test/compress/issue-208.js:41,14]',
|
||||||
'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]',
|
||||||
|
|||||||
@@ -399,7 +399,7 @@ wrap_iife_in_expression: {
|
|||||||
wrap_iife: true,
|
wrap_iife: true,
|
||||||
}
|
}
|
||||||
input: {
|
input: {
|
||||||
foo = (function() {
|
foo = (function () {
|
||||||
return bar();
|
return bar();
|
||||||
})();
|
})();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,37 +0,0 @@
|
|||||||
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,21 +0,0 @@
|
|||||||
inline_script_off: {
|
|
||||||
beautify = {
|
|
||||||
inline_script: false,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
console.log("</sCrIpT>");
|
|
||||||
}
|
|
||||||
expect_exact: 'console.log("</sCrIpT>");'
|
|
||||||
expect_stdout: "</sCrIpT>"
|
|
||||||
}
|
|
||||||
|
|
||||||
inline_script_on: {
|
|
||||||
beautify = {
|
|
||||||
inline_script: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
console.log("</sCrIpT>");
|
|
||||||
}
|
|
||||||
expect_exact: 'console.log("<\\/sCrIpT>");'
|
|
||||||
expect_stdout: "</sCrIpT>"
|
|
||||||
}
|
|
||||||
@@ -1,31 +1,11 @@
|
|||||||
remove_sequence: {
|
|
||||||
options = {
|
|
||||||
side_effects: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
(0, 1, eval)();
|
|
||||||
(0, 1, logThis)();
|
|
||||||
(0, 1, _decorators.logThis)();
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
eval();
|
|
||||||
logThis();
|
|
||||||
(0, _decorators.logThis)();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
remove_redundant_sequence_items: {
|
remove_redundant_sequence_items: {
|
||||||
options = {
|
options = { side_effects: true };
|
||||||
side_effects: true,
|
|
||||||
}
|
|
||||||
input: {
|
input: {
|
||||||
"use strict";
|
|
||||||
(0, 1, eval)();
|
(0, 1, eval)();
|
||||||
(0, 1, logThis)();
|
(0, 1, logThis)();
|
||||||
(0, 1, _decorators.logThis)();
|
(0, 1, _decorators.logThis)();
|
||||||
}
|
}
|
||||||
expect: {
|
expect: {
|
||||||
"use strict";
|
|
||||||
(0, eval)();
|
(0, eval)();
|
||||||
logThis();
|
logThis();
|
||||||
(0, _decorators.logThis)();
|
(0, _decorators.logThis)();
|
||||||
@@ -33,17 +13,13 @@ remove_redundant_sequence_items: {
|
|||||||
}
|
}
|
||||||
|
|
||||||
dont_remove_this_binding_sequence: {
|
dont_remove_this_binding_sequence: {
|
||||||
options = {
|
options = { side_effects: true };
|
||||||
side_effects: true,
|
|
||||||
}
|
|
||||||
input: {
|
input: {
|
||||||
"use strict";
|
|
||||||
(0, eval)();
|
(0, eval)();
|
||||||
(0, logThis)();
|
(0, logThis)();
|
||||||
(0, _decorators.logThis)();
|
(0, _decorators.logThis)();
|
||||||
}
|
}
|
||||||
expect: {
|
expect: {
|
||||||
"use strict";
|
|
||||||
(0, eval)();
|
(0, eval)();
|
||||||
logThis();
|
logThis();
|
||||||
(0, _decorators.logThis)();
|
(0, _decorators.logThis)();
|
||||||
|
|||||||
9
test/compress/issue-926.js
Normal file
9
test/compress/issue-926.js
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
template_strings: {
|
||||||
|
input: {
|
||||||
|
foo(
|
||||||
|
`<span>${contents}</span>`,
|
||||||
|
`<a href="${url}">${text}</a>`
|
||||||
|
);
|
||||||
|
}
|
||||||
|
expect_exact: "foo(`<span>${contents}</span>`,`<a href=\"${url}\">${text}</a>`);"
|
||||||
|
}
|
||||||
@@ -3,9 +3,8 @@ this_binding_conditionals: {
|
|||||||
conditionals: true,
|
conditionals: true,
|
||||||
evaluate: true,
|
evaluate: true,
|
||||||
side_effects: true,
|
side_effects: true,
|
||||||
}
|
};
|
||||||
input: {
|
input: {
|
||||||
"use strict";
|
|
||||||
(1 && a)();
|
(1 && a)();
|
||||||
(0 || a)();
|
(0 || a)();
|
||||||
(0 || 1 && a)();
|
(0 || 1 && a)();
|
||||||
@@ -27,7 +26,6 @@ this_binding_conditionals: {
|
|||||||
(1 ? eval : 0)();
|
(1 ? eval : 0)();
|
||||||
}
|
}
|
||||||
expect: {
|
expect: {
|
||||||
"use strict";
|
|
||||||
a();
|
a();
|
||||||
a();
|
a();
|
||||||
a();
|
a();
|
||||||
@@ -55,15 +53,13 @@ this_binding_collapse_vars: {
|
|||||||
collapse_vars: true,
|
collapse_vars: true,
|
||||||
toplevel: true,
|
toplevel: true,
|
||||||
unused: true,
|
unused: true,
|
||||||
}
|
};
|
||||||
input: {
|
input: {
|
||||||
"use strict";
|
|
||||||
var c = a; c();
|
var c = a; c();
|
||||||
var d = a.b; d();
|
var d = a.b; d();
|
||||||
var e = eval; e();
|
var e = eval; e();
|
||||||
}
|
}
|
||||||
expect: {
|
expect: {
|
||||||
"use strict";
|
|
||||||
a();
|
a();
|
||||||
(0, a.b)();
|
(0, a.b)();
|
||||||
(0, eval)();
|
(0, eval)();
|
||||||
@@ -73,88 +69,31 @@ this_binding_collapse_vars: {
|
|||||||
this_binding_side_effects: {
|
this_binding_side_effects: {
|
||||||
options = {
|
options = {
|
||||||
side_effects : true
|
side_effects : true
|
||||||
}
|
};
|
||||||
input: {
|
input: {
|
||||||
(function(foo) {
|
(function (foo) {
|
||||||
(0, foo)();
|
(0, foo)();
|
||||||
(0, foo.bar)();
|
(0, foo.bar)();
|
||||||
(0, eval)("console.log(foo);");
|
(0, eval)('console.log(foo);');
|
||||||
}());
|
}());
|
||||||
(function(foo) {
|
(function (foo) {
|
||||||
"use strict";
|
|
||||||
(0, foo)();
|
|
||||||
(0, foo.bar)();
|
|
||||||
(0, eval)("console.log(foo);");
|
|
||||||
}());
|
|
||||||
(function(foo) {
|
|
||||||
var eval = console;
|
var eval = console;
|
||||||
(0, foo)();
|
(0, foo)();
|
||||||
(0, foo.bar)();
|
(0, foo.bar)();
|
||||||
(0, eval)("console.log(foo);");
|
(0, eval)('console.log(foo);');
|
||||||
}());
|
}());
|
||||||
}
|
}
|
||||||
expect: {
|
expect: {
|
||||||
(function(foo) {
|
(function (foo) {
|
||||||
foo();
|
foo();
|
||||||
(0, foo.bar)();
|
(0, foo.bar)();
|
||||||
eval("console.log(foo);");
|
(0, eval)('console.log(foo);');
|
||||||
}());
|
}());
|
||||||
(function(foo) {
|
(function (foo) {
|
||||||
"use strict";
|
|
||||||
foo();
|
|
||||||
(0, foo.bar)();
|
|
||||||
(0, eval)("console.log(foo);");
|
|
||||||
}());
|
|
||||||
(function(foo) {
|
|
||||||
var eval = console;
|
var eval = console;
|
||||||
foo();
|
foo();
|
||||||
(0, foo.bar)();
|
(0, foo.bar)();
|
||||||
eval("console.log(foo);");
|
(0, eval)('console.log(foo);');
|
||||||
}());
|
}());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
this_binding_sequences: {
|
|
||||||
options = {
|
|
||||||
sequences: true,
|
|
||||||
side_effects: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
console.log(typeof function() {
|
|
||||||
return eval("this");
|
|
||||||
}());
|
|
||||||
console.log(typeof function() {
|
|
||||||
"use strict";
|
|
||||||
return eval("this");
|
|
||||||
}());
|
|
||||||
console.log(typeof function() {
|
|
||||||
return (0, eval)("this");
|
|
||||||
}());
|
|
||||||
console.log(typeof function() {
|
|
||||||
"use strict";
|
|
||||||
return (0, eval)("this");
|
|
||||||
}());
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
console.log(typeof function() {
|
|
||||||
return eval("this");
|
|
||||||
}()),
|
|
||||||
console.log(typeof function() {
|
|
||||||
"use strict";
|
|
||||||
return eval("this");
|
|
||||||
}()),
|
|
||||||
console.log(typeof function() {
|
|
||||||
return eval("this");
|
|
||||||
}()),
|
|
||||||
console.log(typeof function() {
|
|
||||||
"use strict";
|
|
||||||
return (0, eval)("this");
|
|
||||||
}());
|
|
||||||
}
|
|
||||||
expect_stdout: [
|
|
||||||
"object",
|
|
||||||
"undefined",
|
|
||||||
"object",
|
|
||||||
"object",
|
|
||||||
]
|
|
||||||
}
|
|
||||||
40
test/compress/join-vars.js
Normal file
40
test/compress/join-vars.js
Normal file
@@ -0,0 +1,40 @@
|
|||||||
|
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,6 +146,50 @@ 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,
|
||||||
@@ -294,10 +338,10 @@ issue_186_beautify_ie8: {
|
|||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
issue_186_braces: {
|
issue_186_bracketize: {
|
||||||
beautify = {
|
beautify = {
|
||||||
beautify: false,
|
beautify: false,
|
||||||
braces: true,
|
bracketize: true,
|
||||||
ie8: false,
|
ie8: false,
|
||||||
}
|
}
|
||||||
input: {
|
input: {
|
||||||
@@ -314,10 +358,10 @@ issue_186_braces: {
|
|||||||
expect_exact: 'var x=3;if(foo()){do{do{alert(x)}while(--x)}while(x)}else{bar()}'
|
expect_exact: 'var x=3;if(foo()){do{do{alert(x)}while(--x)}while(x)}else{bar()}'
|
||||||
}
|
}
|
||||||
|
|
||||||
issue_186_braces_ie8: {
|
issue_186_bracketize_ie8: {
|
||||||
beautify = {
|
beautify = {
|
||||||
beautify: false,
|
beautify: false,
|
||||||
braces: true,
|
bracketize: true,
|
||||||
ie8: true,
|
ie8: true,
|
||||||
}
|
}
|
||||||
input: {
|
input: {
|
||||||
@@ -334,10 +378,10 @@ issue_186_braces_ie8: {
|
|||||||
expect_exact: 'var x=3;if(foo()){do{do{alert(x)}while(--x)}while(x)}else{bar()}'
|
expect_exact: 'var x=3;if(foo()){do{do{alert(x)}while(--x)}while(x)}else{bar()}'
|
||||||
}
|
}
|
||||||
|
|
||||||
issue_186_beautify_braces: {
|
issue_186_beautify_bracketize: {
|
||||||
beautify = {
|
beautify = {
|
||||||
beautify: true,
|
beautify: true,
|
||||||
braces: true,
|
bracketize: true,
|
||||||
ie8: false,
|
ie8: false,
|
||||||
}
|
}
|
||||||
input: {
|
input: {
|
||||||
@@ -366,10 +410,10 @@ issue_186_beautify_braces: {
|
|||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
issue_186_beautify_braces_ie8: {
|
issue_186_beautify_bracketize_ie8: {
|
||||||
beautify = {
|
beautify = {
|
||||||
beautify: true,
|
beautify: true,
|
||||||
braces: true,
|
bracketize: true,
|
||||||
ie8: true,
|
ie8: true,
|
||||||
}
|
}
|
||||||
input: {
|
input: {
|
||||||
@@ -606,19 +650,68 @@ issue_2740_5: {
|
|||||||
expect_stdout: "0 undefined"
|
expect_stdout: "0 undefined"
|
||||||
}
|
}
|
||||||
|
|
||||||
issue_2904: {
|
issue_2740_6: {
|
||||||
options = {
|
options = {
|
||||||
join_vars: true,
|
dead_code: true,
|
||||||
loops: true,
|
loops: true,
|
||||||
}
|
}
|
||||||
input: {
|
input: {
|
||||||
var a = 1;
|
const a = 9, b = 0;
|
||||||
do {
|
for (const a = 1; a < 3; ++b) break;
|
||||||
console.log(a);
|
console.log(a, b);
|
||||||
} while (--a);
|
|
||||||
}
|
}
|
||||||
expect: {
|
expect: {
|
||||||
for (var a = 1; console.log(a), --a;);
|
const a = 9, b = 0;
|
||||||
|
{
|
||||||
|
const a = 1;
|
||||||
|
a < 3;
|
||||||
|
}
|
||||||
|
console.log(a, b);
|
||||||
}
|
}
|
||||||
expect_stdout: "1"
|
expect_stdout: "9 0"
|
||||||
|
node_version: ">=6"
|
||||||
|
}
|
||||||
|
|
||||||
|
issue_2740_7: {
|
||||||
|
options = {
|
||||||
|
dead_code: true,
|
||||||
|
loops: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
let a = 9, b = 0;
|
||||||
|
for (const a = 1; a < 3; ++b) break;
|
||||||
|
console.log(a, b);
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
let a = 9, b = 0;
|
||||||
|
{
|
||||||
|
const a = 1;
|
||||||
|
a < 3;
|
||||||
|
}
|
||||||
|
console.log(a, b);
|
||||||
|
}
|
||||||
|
expect_stdout: "9 0"
|
||||||
|
node_version: ">=6"
|
||||||
|
}
|
||||||
|
|
||||||
|
issue_2740_8: {
|
||||||
|
options = {
|
||||||
|
dead_code: true,
|
||||||
|
loops: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
var a = 9, b = 0;
|
||||||
|
for (const a = 1; a < 3; ++b) break;
|
||||||
|
console.log(a, b);
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
var a = 9, b = 0;
|
||||||
|
{
|
||||||
|
const a = 1;
|
||||||
|
a < 3;
|
||||||
|
}
|
||||||
|
console.log(a, b);
|
||||||
|
}
|
||||||
|
expect_stdout: "9 0"
|
||||||
|
node_version: ">=6"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,14 +8,14 @@ too_short: {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
expect_exact: [
|
expect_exact: [
|
||||||
"function f(",
|
'function f(a){',
|
||||||
"a){return{",
|
'return{',
|
||||||
"c:42,d:a(",
|
'c:42,',
|
||||||
'),e:"foo"}',
|
'd:a(),',
|
||||||
"}",
|
'e:"foo"}}',
|
||||||
]
|
]
|
||||||
expect_warnings: [
|
expect_warnings: [
|
||||||
"WARN: Output exceeds 10 characters",
|
"WARN: Output exceeds 10 characters"
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -29,25 +29,11 @@ just_enough: {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
expect_exact: [
|
expect_exact: [
|
||||||
"function f(a){",
|
'function f(a){',
|
||||||
"return{c:42,",
|
'return{c:42,',
|
||||||
'd:a(),e:"foo"}',
|
'd:a(),e:"foo"}',
|
||||||
"}",
|
'}',
|
||||||
]
|
]
|
||||||
expect_warnings: []
|
expect_warnings: [
|
||||||
}
|
|
||||||
|
|
||||||
issue_304: {
|
|
||||||
beautify = {
|
|
||||||
max_line_len: 10,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
var a = 0, b = 0, c = 0, d = 0, e = 0;
|
|
||||||
}
|
|
||||||
expect_exact: [
|
|
||||||
"var a=0,",
|
|
||||||
"b=0,c=0,",
|
|
||||||
"d=0,e=0;",
|
|
||||||
]
|
]
|
||||||
expect_warnings: []
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -67,7 +67,7 @@ negate_iife_3_evaluate: {
|
|||||||
(function(){ return true })() ? console.log(true) : console.log(false);
|
(function(){ return true })() ? console.log(true) : console.log(false);
|
||||||
}
|
}
|
||||||
expect: {
|
expect: {
|
||||||
true, console.log(true);
|
console.log(true);
|
||||||
}
|
}
|
||||||
expect_stdout: true
|
expect_stdout: true
|
||||||
}
|
}
|
||||||
@@ -110,7 +110,7 @@ negate_iife_3_off_evaluate: {
|
|||||||
(function(){ return true })() ? console.log(true) : console.log(false);
|
(function(){ return true })() ? console.log(true) : console.log(false);
|
||||||
}
|
}
|
||||||
expect: {
|
expect: {
|
||||||
true, console.log(true);
|
console.log(true);
|
||||||
}
|
}
|
||||||
expect_stdout: true
|
expect_stdout: true
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -83,6 +83,22 @@ 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,49 +1,21 @@
|
|||||||
hex_numbers_in_parentheses_for_prototype_functions: {
|
hex_numbers_in_parentheses_for_prototype_functions: {
|
||||||
beautify = {
|
|
||||||
beautify: true,
|
|
||||||
}
|
|
||||||
input: {
|
input: {
|
||||||
function f() {
|
(-2);
|
||||||
(-2);
|
(-2).toFixed(0);
|
||||||
(-2).toFixed(0);
|
|
||||||
|
|
||||||
(2);
|
(2);
|
||||||
(2).toFixed(0);
|
(2).toFixed(0);
|
||||||
|
|
||||||
(0.2);
|
(0.2);
|
||||||
(0.2).toFixed(0);
|
(0.2).toFixed(0);
|
||||||
|
|
||||||
(2.34e20);
|
(0.00000002);
|
||||||
(2.34e20).toFixed(0);
|
(0.00000002).toFixed(0);
|
||||||
|
|
||||||
(0.00000002);
|
(1000000000000000128);
|
||||||
(0.00000002).toFixed(0);
|
(1000000000000000128).toFixed(0);
|
||||||
|
|
||||||
(1000000000000000128);
|
|
||||||
(1000000000000000128).toFixed(0);
|
|
||||||
|
|
||||||
(-1000000000000000128);
|
|
||||||
(-1000000000000000128).toFixed(0);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
expect_exact: [
|
expect_exact: "-2;(-2).toFixed(0);2;2..toFixed(0);.2;.2.toFixed(0);2e-8;2e-8.toFixed(0);0xde0b6b3a7640080;(0xde0b6b3a7640080).toFixed(0);"
|
||||||
"function f() {",
|
|
||||||
" -2;",
|
|
||||||
" (-2).toFixed(0);",
|
|
||||||
" 2;",
|
|
||||||
" 2..toFixed(0);",
|
|
||||||
" .2;",
|
|
||||||
" .2.toFixed(0);",
|
|
||||||
" 234e18;",
|
|
||||||
" 234e18.toFixed(0);",
|
|
||||||
" 2e-8;",
|
|
||||||
" 2e-8.toFixed(0);",
|
|
||||||
" 0xde0b6b3a7640080;",
|
|
||||||
" (0xde0b6b3a7640080).toFixed(0);",
|
|
||||||
" -0xde0b6b3a7640080;",
|
|
||||||
" (-0xde0b6b3a7640080).toFixed(0);",
|
|
||||||
"}",
|
|
||||||
]
|
|
||||||
}
|
}
|
||||||
|
|
||||||
comparisons: {
|
comparisons: {
|
||||||
|
|||||||
1015
test/compress/object.js
Normal file
1015
test/compress/object.js
Normal file
File diff suppressed because it is too large
Load Diff
186
test/compress/parameters.js
Normal file
186
test/compress/parameters.js
Normal file
@@ -0,0 +1,186 @@
|
|||||||
|
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,6 +159,7 @@ mangle_unquoted_properties: {
|
|||||||
}
|
}
|
||||||
mangle = {
|
mangle = {
|
||||||
properties: {
|
properties: {
|
||||||
|
builtins: true,
|
||||||
keep_quoted: true,
|
keep_quoted: true,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
@@ -258,6 +259,7 @@ mangle_debug_suffix_keep_quoted: {
|
|||||||
}
|
}
|
||||||
mangle = {
|
mangle = {
|
||||||
properties: {
|
properties: {
|
||||||
|
builtins: true,
|
||||||
debug: "XYZ",
|
debug: "XYZ",
|
||||||
keep_quoted: true,
|
keep_quoted: true,
|
||||||
reserved: [],
|
reserved: [],
|
||||||
@@ -583,25 +585,6 @@ native_prototype: {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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;
|
||||||
@@ -817,6 +800,172 @@ 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,
|
||||||
@@ -835,6 +984,91 @@ 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,
|
||||||
@@ -1035,6 +1269,30 @@ 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,
|
||||||
@@ -1209,37 +1467,6 @@ join_object_assignments_3: {
|
|||||||
}
|
}
|
||||||
|
|
||||||
join_object_assignments_4: {
|
join_object_assignments_4: {
|
||||||
options = {
|
|
||||||
join_vars: true,
|
|
||||||
sequences: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
var o;
|
|
||||||
console.log(o);
|
|
||||||
o = {};
|
|
||||||
o.a = "foo";
|
|
||||||
console.log(o.b);
|
|
||||||
o.b = "bar";
|
|
||||||
console.log(o.a);
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
var o;
|
|
||||||
console.log(o),
|
|
||||||
o = {
|
|
||||||
a: "foo",
|
|
||||||
},
|
|
||||||
console.log(o.b),
|
|
||||||
o.b = "bar",
|
|
||||||
console.log(o.a);
|
|
||||||
}
|
|
||||||
expect_stdout: [
|
|
||||||
"undefined",
|
|
||||||
"undefined",
|
|
||||||
"foo",
|
|
||||||
]
|
|
||||||
}
|
|
||||||
|
|
||||||
join_object_assignments_return_1: {
|
|
||||||
options = {
|
options = {
|
||||||
join_vars: true,
|
join_vars: true,
|
||||||
}
|
}
|
||||||
@@ -1263,7 +1490,7 @@ join_object_assignments_return_1: {
|
|||||||
expect_stdout: "foo"
|
expect_stdout: "foo"
|
||||||
}
|
}
|
||||||
|
|
||||||
join_object_assignments_return_2: {
|
join_object_assignments_5: {
|
||||||
options = {
|
options = {
|
||||||
join_vars: true,
|
join_vars: true,
|
||||||
}
|
}
|
||||||
@@ -1289,7 +1516,7 @@ join_object_assignments_return_2: {
|
|||||||
expect_stdout: "bar"
|
expect_stdout: "bar"
|
||||||
}
|
}
|
||||||
|
|
||||||
join_object_assignments_return_3: {
|
join_object_assignments_6: {
|
||||||
options = {
|
options = {
|
||||||
join_vars: true,
|
join_vars: true,
|
||||||
}
|
}
|
||||||
@@ -1321,7 +1548,7 @@ join_object_assignments_return_3: {
|
|||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
join_object_assignments_for: {
|
join_object_assignments_7: {
|
||||||
options = {
|
options = {
|
||||||
join_vars: true,
|
join_vars: true,
|
||||||
}
|
}
|
||||||
@@ -1348,487 +1575,3 @@ join_object_assignments_for: {
|
|||||||
"3",
|
"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"
|
|
||||||
}
|
|
||||||
|
|
||||||
issue_2893_1: {
|
|
||||||
options = {
|
|
||||||
join_vars: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
var o = {
|
|
||||||
get a() {
|
|
||||||
return "PASS";
|
|
||||||
},
|
|
||||||
};
|
|
||||||
o.a = "FAIL";
|
|
||||||
console.log(o.a);
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
var o = {
|
|
||||||
get a() {
|
|
||||||
return "PASS";
|
|
||||||
},
|
|
||||||
};
|
|
||||||
o.a = "FAIL";
|
|
||||||
console.log(o.a);
|
|
||||||
}
|
|
||||||
expect_stdout: "PASS"
|
|
||||||
}
|
|
||||||
|
|
||||||
issue_2893_2: {
|
|
||||||
options = {
|
|
||||||
join_vars: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
var o = {
|
|
||||||
set a(v) {
|
|
||||||
this.b = v;
|
|
||||||
},
|
|
||||||
b: "FAIL",
|
|
||||||
};
|
|
||||||
o.a = "PASS";
|
|
||||||
console.log(o.b);
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
var o = {
|
|
||||||
set a(v) {
|
|
||||||
this.b = v;
|
|
||||||
},
|
|
||||||
b: "FAIL",
|
|
||||||
};
|
|
||||||
o.a = "PASS";
|
|
||||||
console.log(o.b);
|
|
||||||
}
|
|
||||||
expect_stdout: "PASS"
|
|
||||||
}
|
|
||||||
|
|
||||||
issue_869_1: {
|
|
||||||
mangle = {
|
|
||||||
properties: {
|
|
||||||
reserved: [ "get" ]
|
|
||||||
},
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
var o = { p: "FAIL" };
|
|
||||||
Object.defineProperty(o, "p", {
|
|
||||||
get: function() {
|
|
||||||
return "PASS";
|
|
||||||
}
|
|
||||||
});
|
|
||||||
console.log(o.p);
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
var o = { o: "FAIL" };
|
|
||||||
Object.defineProperty(o, "o", {
|
|
||||||
get: function() {
|
|
||||||
return "PASS";
|
|
||||||
}
|
|
||||||
});
|
|
||||||
console.log(o.o);
|
|
||||||
}
|
|
||||||
expect_stdout: "PASS"
|
|
||||||
}
|
|
||||||
|
|
||||||
issue_869_2: {
|
|
||||||
mangle = {
|
|
||||||
properties: {
|
|
||||||
reserved: [ "get" ]
|
|
||||||
},
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
var o = { p: "FAIL" };
|
|
||||||
Object.defineProperties(o, {
|
|
||||||
p: {
|
|
||||||
get: function() {
|
|
||||||
return "PASS";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
console.log(o.p);
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
var o = { o: "FAIL" };
|
|
||||||
Object.defineProperties(o, {
|
|
||||||
o: {
|
|
||||||
get: function() {
|
|
||||||
return "PASS";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
console.log(o.o);
|
|
||||||
}
|
|
||||||
expect_stdout: "PASS"
|
|
||||||
}
|
|
||||||
|
|
||||||
issue_3188_1: {
|
|
||||||
options = {
|
|
||||||
collapse_vars: true,
|
|
||||||
inline: true,
|
|
||||||
properties: true,
|
|
||||||
reduce_vars: true,
|
|
||||||
side_effects: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
(function() {
|
|
||||||
function f() {
|
|
||||||
console.log(this.p);
|
|
||||||
}
|
|
||||||
(function() {
|
|
||||||
var o = {
|
|
||||||
p: "PASS",
|
|
||||||
f: f
|
|
||||||
};
|
|
||||||
o.f();
|
|
||||||
})();
|
|
||||||
})();
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
(function() {
|
|
||||||
function f() {
|
|
||||||
console.log(this.p);
|
|
||||||
}
|
|
||||||
({
|
|
||||||
p: "PASS",
|
|
||||||
f: f
|
|
||||||
}).f();
|
|
||||||
var o;
|
|
||||||
})();
|
|
||||||
}
|
|
||||||
expect_stdout: "PASS"
|
|
||||||
}
|
|
||||||
|
|
||||||
issue_3188_2: {
|
|
||||||
options = {
|
|
||||||
collapse_vars: true,
|
|
||||||
inline: true,
|
|
||||||
properties: true,
|
|
||||||
reduce_vars: true,
|
|
||||||
side_effects: true,
|
|
||||||
unused: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
(function() {
|
|
||||||
var f = function() {
|
|
||||||
console.log(this.p);
|
|
||||||
};
|
|
||||||
function g() {
|
|
||||||
var o = {
|
|
||||||
p: "PASS",
|
|
||||||
f: f
|
|
||||||
};
|
|
||||||
o.f();
|
|
||||||
}
|
|
||||||
g();
|
|
||||||
})();
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
({
|
|
||||||
p: "PASS",
|
|
||||||
f: function() {
|
|
||||||
console.log(this.p);
|
|
||||||
}
|
|
||||||
}).f();
|
|
||||||
}
|
|
||||||
expect_stdout: "PASS"
|
|
||||||
}
|
|
||||||
|
|
||||||
issue_3188_3: {
|
|
||||||
options = {
|
|
||||||
collapse_vars: true,
|
|
||||||
inline: true,
|
|
||||||
properties: true,
|
|
||||||
reduce_vars: true,
|
|
||||||
side_effects: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
(function() {
|
|
||||||
function f() {
|
|
||||||
console.log(this[0]);
|
|
||||||
}
|
|
||||||
(function() {
|
|
||||||
var o = ["PASS", f];
|
|
||||||
o[1]();
|
|
||||||
})();
|
|
||||||
})();
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
(function() {
|
|
||||||
function f() {
|
|
||||||
console.log(this[0]);
|
|
||||||
}
|
|
||||||
["PASS", f][1]();
|
|
||||||
var o;
|
|
||||||
})();
|
|
||||||
}
|
|
||||||
expect_stdout: "PASS"
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -535,110 +535,3 @@ issue_2705_6: {
|
|||||||
"/* */new(/* */a()||b())(c(),d());",
|
"/* */new(/* */a()||b())(c(),d());",
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
issue_3065_1: {
|
|
||||||
options = {
|
|
||||||
inline: true,
|
|
||||||
pure_funcs: [ "pureFunc" ],
|
|
||||||
reduce_vars: true,
|
|
||||||
side_effects: true,
|
|
||||||
toplevel: true,
|
|
||||||
unused: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
function modifyWrapper(a, f, wrapper) {
|
|
||||||
wrapper.a = a;
|
|
||||||
wrapper.f = f;
|
|
||||||
return wrapper;
|
|
||||||
}
|
|
||||||
function pureFunc(fun) {
|
|
||||||
return modifyWrapper(1, fun, function(a) {
|
|
||||||
return fun(a);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
var unused = pureFunc(function(x) {
|
|
||||||
return x;
|
|
||||||
});
|
|
||||||
}
|
|
||||||
expect: {}
|
|
||||||
}
|
|
||||||
|
|
||||||
issue_3065_2: {
|
|
||||||
rename = true
|
|
||||||
options = {
|
|
||||||
inline: true,
|
|
||||||
pure_funcs: [ "pureFunc" ],
|
|
||||||
reduce_vars: true,
|
|
||||||
side_effects: true,
|
|
||||||
toplevel: true,
|
|
||||||
unused: true,
|
|
||||||
}
|
|
||||||
mangle = {
|
|
||||||
reserved: [ "pureFunc" ],
|
|
||||||
toplevel: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
function modifyWrapper(a, f, wrapper) {
|
|
||||||
wrapper.a = a;
|
|
||||||
wrapper.f = f;
|
|
||||||
return wrapper;
|
|
||||||
}
|
|
||||||
function pureFunc(fun) {
|
|
||||||
return modifyWrapper(1, fun, function(a) {
|
|
||||||
return fun(a);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
var unused = pureFunc(function(x) {
|
|
||||||
return x;
|
|
||||||
});
|
|
||||||
}
|
|
||||||
expect: {}
|
|
||||||
}
|
|
||||||
|
|
||||||
issue_3065_3: {
|
|
||||||
options = {
|
|
||||||
pure_funcs: [ "debug" ],
|
|
||||||
reduce_vars: true,
|
|
||||||
side_effects: true,
|
|
||||||
toplevel: true,
|
|
||||||
unused: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
function debug(msg) {
|
|
||||||
console.log(msg);
|
|
||||||
}
|
|
||||||
debug(function() {
|
|
||||||
console.log("PASS");
|
|
||||||
return "FAIL";
|
|
||||||
}());
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
(function() {
|
|
||||||
console.log("PASS");
|
|
||||||
})();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
issue_3065_4: {
|
|
||||||
options = {
|
|
||||||
pure_funcs: [ "debug" ],
|
|
||||||
reduce_vars: true,
|
|
||||||
side_effects: true,
|
|
||||||
toplevel: true,
|
|
||||||
unused: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
var debug = function(msg) {
|
|
||||||
console.log(msg);
|
|
||||||
};
|
|
||||||
debug(function() {
|
|
||||||
console.log("PASS");
|
|
||||||
return "FAIL";
|
|
||||||
}());
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
(function() {
|
|
||||||
console.log("PASS");
|
|
||||||
})();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -449,6 +449,82 @@ 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 = {
|
||||||
collapse_vars: true,
|
collapse_vars: true,
|
||||||
@@ -663,6 +739,54 @@ issue_2313_6: {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
issue_2313_7: {
|
||||||
|
options = {
|
||||||
|
collapse_vars: true,
|
||||||
|
conditionals: true,
|
||||||
|
pure_getters: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
var a = 0, b = 0;
|
||||||
|
class foo {
|
||||||
|
get c() {
|
||||||
|
a++;
|
||||||
|
return 42;
|
||||||
|
}
|
||||||
|
set c(c) {
|
||||||
|
b++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
class bar extends foo {
|
||||||
|
d() {
|
||||||
|
super.c++;
|
||||||
|
if (super.c) console.log(a, b);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
new bar().d();
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
var a = 0, b = 0;
|
||||||
|
class foo {
|
||||||
|
get c() {
|
||||||
|
a++;
|
||||||
|
return 42;
|
||||||
|
}
|
||||||
|
set c(c) {
|
||||||
|
b++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
class bar extends foo {
|
||||||
|
d() {
|
||||||
|
super.c++;
|
||||||
|
super.c && console.log(a, b);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
new bar().d();
|
||||||
|
}
|
||||||
|
expect_stdout: "2 1"
|
||||||
|
node_version: ">=6"
|
||||||
|
}
|
||||||
|
|
||||||
issue_2678: {
|
issue_2678: {
|
||||||
options = {
|
options = {
|
||||||
pure_getters: "strict",
|
pure_getters: "strict",
|
||||||
@@ -694,470 +818,3 @@ issue_2678: {
|
|||||||
}
|
}
|
||||||
expect_stdout: "PASS"
|
expect_stdout: "PASS"
|
||||||
}
|
}
|
||||||
|
|
||||||
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"
|
|
||||||
}
|
|
||||||
|
|
||||||
issue_2938_1: {
|
|
||||||
options = {
|
|
||||||
pure_getters: true,
|
|
||||||
unused: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
function f(a) {
|
|
||||||
a.b = "PASS";
|
|
||||||
}
|
|
||||||
var o = {};
|
|
||||||
f(o);
|
|
||||||
console.log(o.b);
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
function f(a) {
|
|
||||||
a.b = "PASS";
|
|
||||||
}
|
|
||||||
var o = {};
|
|
||||||
f(o);
|
|
||||||
console.log(o.b);
|
|
||||||
}
|
|
||||||
expect_stdout: "PASS"
|
|
||||||
}
|
|
||||||
|
|
||||||
issue_2938_2: {
|
|
||||||
options = {
|
|
||||||
pure_getters: true,
|
|
||||||
toplevel: true,
|
|
||||||
unused: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
var Parser = function Parser() {};
|
|
||||||
var p = Parser.prototype;
|
|
||||||
p.initialContext = function initialContext() {
|
|
||||||
console.log("PASS");
|
|
||||||
};
|
|
||||||
p.braceIsBlock = function() {};
|
|
||||||
(new Parser).initialContext();
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
var Parser = function() {};
|
|
||||||
var p = Parser.prototype;
|
|
||||||
p.initialContext = function() {
|
|
||||||
console.log("PASS");
|
|
||||||
};
|
|
||||||
p.braceIsBlock = function() {};
|
|
||||||
(new Parser).initialContext();
|
|
||||||
}
|
|
||||||
expect_stdout: "PASS"
|
|
||||||
}
|
|
||||||
|
|
||||||
issue_2938_3: {
|
|
||||||
options = {
|
|
||||||
pure_getters: true,
|
|
||||||
side_effects: true,
|
|
||||||
unused: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
function f(a) {
|
|
||||||
var unused = a.a;
|
|
||||||
a.b = "PASS";
|
|
||||||
a.c;
|
|
||||||
}
|
|
||||||
var o = {};
|
|
||||||
o.d;
|
|
||||||
f(o);
|
|
||||||
console.log(o.b);
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
function f(a) {
|
|
||||||
a.b = "PASS";
|
|
||||||
}
|
|
||||||
var o = {};
|
|
||||||
f(o);
|
|
||||||
console.log(o.b);
|
|
||||||
}
|
|
||||||
expect_stdout: "PASS"
|
|
||||||
}
|
|
||||||
|
|
||||||
issue_2938_4: {
|
|
||||||
options = {
|
|
||||||
pure_getters: true,
|
|
||||||
side_effects: true,
|
|
||||||
toplevel: true,
|
|
||||||
unused: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
var Parser = function Parser() {};
|
|
||||||
var p = Parser.prototype;
|
|
||||||
var unused = p.x;
|
|
||||||
p.initialContext = function initialContext() {
|
|
||||||
p.y;
|
|
||||||
console.log("PASS");
|
|
||||||
};
|
|
||||||
p.braceIsBlock = function() {};
|
|
||||||
(new Parser).initialContext();
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
var Parser = function() {};
|
|
||||||
var p = Parser.prototype;
|
|
||||||
p.initialContext = function() {
|
|
||||||
console.log("PASS");
|
|
||||||
};
|
|
||||||
p.braceIsBlock = function() {};
|
|
||||||
(new Parser).initialContext();
|
|
||||||
}
|
|
||||||
expect_stdout: "PASS"
|
|
||||||
}
|
|
||||||
|
|
||||||
collapse_vars_1_true: {
|
|
||||||
options = {
|
|
||||||
collapse_vars: true,
|
|
||||||
pure_getters: true,
|
|
||||||
unused: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
function f(a, b) {
|
|
||||||
for (;;) {
|
|
||||||
var c = a.g();
|
|
||||||
var d = b.p;
|
|
||||||
if (c || d) break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
function f(a, b) {
|
|
||||||
for (;;) {
|
|
||||||
if (a.g() || b.p) break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
collapse_vars_1_false: {
|
|
||||||
options = {
|
|
||||||
collapse_vars: true,
|
|
||||||
pure_getters: false,
|
|
||||||
unused: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
function f(a, b) {
|
|
||||||
for (;;) {
|
|
||||||
var c = a.g();
|
|
||||||
var d = b.p;
|
|
||||||
if (c || d) break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
function f(a, b) {
|
|
||||||
for (;;) {
|
|
||||||
var c = a.g();
|
|
||||||
var d = b.p;
|
|
||||||
if (c || d) break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
collapse_vars_1_strict: {
|
|
||||||
options = {
|
|
||||||
collapse_vars: true,
|
|
||||||
pure_getters: "strict",
|
|
||||||
unused: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
function f(a, b) {
|
|
||||||
for (;;) {
|
|
||||||
var c = a.g();
|
|
||||||
var d = b.p;
|
|
||||||
if (c || d) break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
function f(a, b) {
|
|
||||||
for (;;) {
|
|
||||||
var c = a.g();
|
|
||||||
var d = b.p;
|
|
||||||
if (c || d) break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
collapse_vars_2_true: {
|
|
||||||
options = {
|
|
||||||
collapse_vars: true,
|
|
||||||
pure_getters: true,
|
|
||||||
reduce_vars: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
function f() {
|
|
||||||
function g() {}
|
|
||||||
g.a = function() {};
|
|
||||||
g.b = g.a;
|
|
||||||
return g;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
function f() {
|
|
||||||
function g() {}
|
|
||||||
g.b = g.a = function() {};
|
|
||||||
return g;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
collapse_vars_2_false: {
|
|
||||||
options = {
|
|
||||||
collapse_vars: true,
|
|
||||||
pure_getters: false,
|
|
||||||
reduce_vars: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
function f() {
|
|
||||||
function g() {}
|
|
||||||
g.a = function() {};
|
|
||||||
g.b = g.a;
|
|
||||||
return g;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
function f() {
|
|
||||||
function g() {}
|
|
||||||
g.a = function() {};
|
|
||||||
g.b = g.a;
|
|
||||||
return g;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
collapse_vars_2_strict: {
|
|
||||||
options = {
|
|
||||||
collapse_vars: true,
|
|
||||||
pure_getters: "strict",
|
|
||||||
reduce_vars: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
function f() {
|
|
||||||
function g() {}
|
|
||||||
g.a = function() {};
|
|
||||||
g.b = g.a;
|
|
||||||
return g;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
function f() {
|
|
||||||
function g() {}
|
|
||||||
g.b = g.a = function() {};
|
|
||||||
return g;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
collapse_rhs_true: {
|
|
||||||
options = {
|
|
||||||
collapse_vars: true,
|
|
||||||
pure_getters: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
console.log((42..length = "PASS", "PASS"));
|
|
||||||
console.log(("foo".length = "PASS", "PASS"));
|
|
||||||
console.log((false.length = "PASS", "PASS"));
|
|
||||||
console.log((function() {}.length = "PASS", "PASS"));
|
|
||||||
console.log(({
|
|
||||||
get length() {
|
|
||||||
return "FAIL";
|
|
||||||
}
|
|
||||||
}.length = "PASS", "PASS"));
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
console.log(42..length = "PASS");
|
|
||||||
console.log("foo".length = "PASS");
|
|
||||||
console.log(false.length = "PASS");
|
|
||||||
console.log(function() {}.length = "PASS");
|
|
||||||
console.log({
|
|
||||||
get length() {
|
|
||||||
return "FAIL";
|
|
||||||
}
|
|
||||||
}.length = "PASS");
|
|
||||||
}
|
|
||||||
expect_stdout: [
|
|
||||||
"PASS",
|
|
||||||
"PASS",
|
|
||||||
"PASS",
|
|
||||||
"PASS",
|
|
||||||
"PASS",
|
|
||||||
]
|
|
||||||
}
|
|
||||||
|
|
||||||
collapse_rhs_false: {
|
|
||||||
options = {
|
|
||||||
collapse_vars: true,
|
|
||||||
pure_getters: false,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
console.log((42..length = "PASS", "PASS"));
|
|
||||||
console.log(("foo".length = "PASS", "PASS"));
|
|
||||||
console.log((false.length = "PASS", "PASS"));
|
|
||||||
console.log((function() {}.length = "PASS", "PASS"));
|
|
||||||
console.log(({
|
|
||||||
get length() {
|
|
||||||
return "FAIL";
|
|
||||||
}
|
|
||||||
}.length = "PASS", "PASS"));
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
console.log(42..length = "PASS");
|
|
||||||
console.log("foo".length = "PASS");
|
|
||||||
console.log(false.length = "PASS");
|
|
||||||
console.log(function() {}.length = "PASS");
|
|
||||||
console.log({
|
|
||||||
get length() {
|
|
||||||
return "FAIL";
|
|
||||||
}
|
|
||||||
}.length = "PASS");
|
|
||||||
}
|
|
||||||
expect_stdout: [
|
|
||||||
"PASS",
|
|
||||||
"PASS",
|
|
||||||
"PASS",
|
|
||||||
"PASS",
|
|
||||||
"PASS",
|
|
||||||
]
|
|
||||||
}
|
|
||||||
|
|
||||||
collapse_rhs_strict: {
|
|
||||||
options = {
|
|
||||||
collapse_vars: true,
|
|
||||||
pure_getters: "strict",
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
console.log((42..length = "PASS", "PASS"));
|
|
||||||
console.log(("foo".length = "PASS", "PASS"));
|
|
||||||
console.log((false.length = "PASS", "PASS"));
|
|
||||||
console.log((function() {}.length = "PASS", "PASS"));
|
|
||||||
console.log(({
|
|
||||||
get length() {
|
|
||||||
return "FAIL";
|
|
||||||
}
|
|
||||||
}.length = "PASS", "PASS"));
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
console.log(42..length = "PASS");
|
|
||||||
console.log("foo".length = "PASS");
|
|
||||||
console.log(false.length = "PASS");
|
|
||||||
console.log(function() {}.length = "PASS");
|
|
||||||
console.log({
|
|
||||||
get length() {
|
|
||||||
return "FAIL";
|
|
||||||
}
|
|
||||||
}.length = "PASS");
|
|
||||||
}
|
|
||||||
expect_stdout: [
|
|
||||||
"PASS",
|
|
||||||
"PASS",
|
|
||||||
"PASS",
|
|
||||||
"PASS",
|
|
||||||
"PASS",
|
|
||||||
]
|
|
||||||
}
|
|
||||||
|
|
||||||
collapse_rhs_setter: {
|
|
||||||
options = {
|
|
||||||
collapse_vars: true,
|
|
||||||
pure_getters: "strict",
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
try {
|
|
||||||
console.log(({
|
|
||||||
set length(v) {
|
|
||||||
throw "PASS";
|
|
||||||
}
|
|
||||||
}.length = "FAIL", "FAIL"));
|
|
||||||
} catch (e) {
|
|
||||||
console.log(e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
try {
|
|
||||||
console.log({
|
|
||||||
set length(v) {
|
|
||||||
throw "PASS";
|
|
||||||
}
|
|
||||||
}.length = "FAIL");
|
|
||||||
} catch (e) {
|
|
||||||
console.log(e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
expect_stdout: "PASS"
|
|
||||||
}
|
|
||||||
|
|
||||||
collapse_rhs_call: {
|
|
||||||
options = {
|
|
||||||
collapse_vars: true,
|
|
||||||
passes: 2,
|
|
||||||
pure_getters: "strict",
|
|
||||||
reduce_vars: true,
|
|
||||||
toplevel: true,
|
|
||||||
unused: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
var o = {};
|
|
||||||
function f() {
|
|
||||||
console.log("PASS");
|
|
||||||
}
|
|
||||||
o.f = f;
|
|
||||||
f();
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
({}.f = function() {
|
|
||||||
console.log("PASS");
|
|
||||||
})();
|
|
||||||
}
|
|
||||||
expect_stdout: "PASS"
|
|
||||||
}
|
|
||||||
|
|
||||||
collapse_rhs_lhs: {
|
|
||||||
options = {
|
|
||||||
collapse_vars: true,
|
|
||||||
pure_getters: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
function f(a, b) {
|
|
||||||
a.b = b, b += 2;
|
|
||||||
console.log(a.b, b);
|
|
||||||
}
|
|
||||||
f({}, 1);
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
function f(a, b) {
|
|
||||||
a.b = b, b += 2;
|
|
||||||
console.log(a.b, b);
|
|
||||||
}
|
|
||||||
f({}, 1);
|
|
||||||
}
|
|
||||||
expect_stdout: "1 3"
|
|
||||||
}
|
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@@ -1,37 +0,0 @@
|
|||||||
regexp_simple: {
|
|
||||||
input: {
|
|
||||||
/rx/ig
|
|
||||||
}
|
|
||||||
expect_exact: "/rx/gi;"
|
|
||||||
}
|
|
||||||
|
|
||||||
regexp_slashes: {
|
|
||||||
input: {
|
|
||||||
/\\\/rx\/\\/ig
|
|
||||||
}
|
|
||||||
expect_exact: "/\\\\\\/rx\\/\\\\/gi;"
|
|
||||||
}
|
|
||||||
|
|
||||||
regexp_1: {
|
|
||||||
input: {
|
|
||||||
console.log(JSON.stringify("COMPASS? Overpass.".match(/([Sap]+)/ig)));
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
console.log(JSON.stringify("COMPASS? Overpass.".match(/([Sap]+)/gi)));
|
|
||||||
}
|
|
||||||
expect_stdout: '["PASS","pass"]'
|
|
||||||
}
|
|
||||||
|
|
||||||
regexp_2: {
|
|
||||||
options = {
|
|
||||||
evaluate: true,
|
|
||||||
unsafe: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
console.log(JSON.stringify("COMPASS? Overpass.".match(new RegExp("([Sap]+)", "ig"))));
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
console.log(JSON.stringify("COMPASS? Overpass.".match(/([Sap]+)/gi)));
|
|
||||||
}
|
|
||||||
expect_stdout: '["PASS","pass"]'
|
|
||||||
}
|
|
||||||
@@ -109,7 +109,7 @@ mangle_catch_toplevel: {
|
|||||||
}
|
}
|
||||||
console.log(a);
|
console.log(a);
|
||||||
}
|
}
|
||||||
expect_exact: 'var c="FAIL";try{throw 1}catch(o){c="PASS"}console.log(c);'
|
expect_exact: 'var o="FAIL";try{throw 1}catch(c){o="PASS"}console.log(o);'
|
||||||
expect_stdout: "PASS"
|
expect_stdout: "PASS"
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -155,7 +155,7 @@ mangle_catch_var_toplevel: {
|
|||||||
}
|
}
|
||||||
console.log(a);
|
console.log(a);
|
||||||
}
|
}
|
||||||
expect_exact: 'var r="FAIL";try{throw 1}catch(o){var r="PASS"}console.log(r);'
|
expect_exact: 'var o="FAIL";try{throw 1}catch(r){var o="PASS"}console.log(o);'
|
||||||
expect_stdout: "PASS"
|
expect_stdout: "PASS"
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -451,7 +451,7 @@ function_iife_catch: {
|
|||||||
}
|
}
|
||||||
f();
|
f();
|
||||||
}
|
}
|
||||||
expect_exact: "function f(o){!function(){try{throw 0}catch(o){var c=1;console.log(o,c)}}()}f();"
|
expect_exact: "function f(o){!function(){try{throw 0}catch(c){var o=1;console.log(c,o)}}()}f();"
|
||||||
expect_stdout: "0 1"
|
expect_stdout: "0 1"
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -473,7 +473,7 @@ function_iife_catch_ie8: {
|
|||||||
}
|
}
|
||||||
f();
|
f();
|
||||||
}
|
}
|
||||||
expect_exact: "function f(c){!function(){try{throw 0}catch(c){var o=1;console.log(c,o)}}()}f();"
|
expect_exact: "function f(o){!function(){try{throw 0}catch(o){var c=1;console.log(o,c)}}()}f();"
|
||||||
expect_stdout: "0 1"
|
expect_stdout: "0 1"
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -499,7 +499,7 @@ function_catch_catch: {
|
|||||||
}
|
}
|
||||||
f();
|
f();
|
||||||
}
|
}
|
||||||
expect_exact: "var o=0;function f(){try{throw 1}catch(o){try{throw 2}catch(c){var c=3;console.log(c)}}console.log(c)}f();"
|
expect_exact: "var o=0;function f(){try{throw 1}catch(c){try{throw 2}catch(o){var o=3;console.log(o)}}console.log(o)}f();"
|
||||||
expect_stdout: [
|
expect_stdout: [
|
||||||
"3",
|
"3",
|
||||||
"undefined",
|
"undefined",
|
||||||
|
|||||||
@@ -102,12 +102,12 @@ dont_screw_try_catch: {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
expect: {
|
expect: {
|
||||||
bad = function(t){
|
bad = function(n){
|
||||||
return function(n){
|
return function(t){
|
||||||
try{
|
try{
|
||||||
t()
|
n()
|
||||||
} catch(t) {
|
} catch(n) {
|
||||||
n(t)
|
t(n)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@@ -349,11 +349,11 @@ issue_2254_1: {
|
|||||||
try {
|
try {
|
||||||
console.log(f("PASS"));
|
console.log(f("PASS"));
|
||||||
} catch (e) {}
|
} catch (e) {}
|
||||||
function f(t) {
|
function f(e) {
|
||||||
try {
|
try {
|
||||||
throw "FAIL";
|
throw "FAIL";
|
||||||
} catch (e) {
|
} catch (t) {
|
||||||
return t;
|
return e;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -392,277 +392,3 @@ issue_2254_2: {
|
|||||||
}
|
}
|
||||||
expect_stdout: "PASS"
|
expect_stdout: "PASS"
|
||||||
}
|
}
|
||||||
|
|
||||||
issue_24_1: {
|
|
||||||
mangle = {
|
|
||||||
ie8: false,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
(function(a) {
|
|
||||||
console.log(typeof function f(){} === typeof a ? "FAIL" : "PASS");
|
|
||||||
})();
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
(function(o) {
|
|
||||||
console.log(typeof function o(){} === typeof o ? "FAIL" : "PASS");
|
|
||||||
})();
|
|
||||||
}
|
|
||||||
expect_stdout: "PASS"
|
|
||||||
}
|
|
||||||
|
|
||||||
issue_24_2: {
|
|
||||||
mangle = {
|
|
||||||
ie8: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
(function(a) {
|
|
||||||
console.log(typeof function f(){} === typeof a ? "FAIL" : "PASS");
|
|
||||||
})();
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
(function(o) {
|
|
||||||
console.log(typeof function n(){} === typeof o ? "FAIL" : "PASS");
|
|
||||||
})();
|
|
||||||
}
|
|
||||||
expect_stdout: "PASS"
|
|
||||||
}
|
|
||||||
|
|
||||||
issue_2976_1: {
|
|
||||||
mangle = {
|
|
||||||
ie8: false,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
console.log(function f() {
|
|
||||||
var a;
|
|
||||||
return a === f ? "FAIL" : "PASS";
|
|
||||||
}());
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
console.log(function n() {
|
|
||||||
var o;
|
|
||||||
return o === n ? "FAIL" : "PASS";
|
|
||||||
}());
|
|
||||||
}
|
|
||||||
expect_stdout: "PASS"
|
|
||||||
}
|
|
||||||
|
|
||||||
issue_2976_2: {
|
|
||||||
mangle = {
|
|
||||||
ie8: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
console.log(function f() {
|
|
||||||
var a;
|
|
||||||
return a === f ? "FAIL" : "PASS";
|
|
||||||
}());
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
console.log(function f() {
|
|
||||||
var n;
|
|
||||||
return n === f ? "FAIL" : "PASS";
|
|
||||||
}());
|
|
||||||
}
|
|
||||||
expect_stdout: "PASS"
|
|
||||||
}
|
|
||||||
|
|
||||||
issue_2976_3: {
|
|
||||||
mangle = {
|
|
||||||
ie8: true,
|
|
||||||
toplevel: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
console.log(function f() {
|
|
||||||
var a;
|
|
||||||
return a === f ? "FAIL" : "PASS";
|
|
||||||
}());
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
console.log(function o() {
|
|
||||||
var n;
|
|
||||||
return n === o ? "FAIL" : "PASS";
|
|
||||||
}());
|
|
||||||
}
|
|
||||||
expect_stdout: "PASS"
|
|
||||||
}
|
|
||||||
|
|
||||||
issue_3035: {
|
|
||||||
mangle = {
|
|
||||||
ie8: false,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
var c = "FAIL";
|
|
||||||
(function(a) {
|
|
||||||
try {
|
|
||||||
throw 1;
|
|
||||||
} catch (b) {
|
|
||||||
try {
|
|
||||||
throw 0;
|
|
||||||
} catch (a) {
|
|
||||||
b && (c = "PASS");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
})();
|
|
||||||
console.log(c);
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
var c = "FAIL";
|
|
||||||
(function(o) {
|
|
||||||
try {
|
|
||||||
throw 1;
|
|
||||||
} catch (t) {
|
|
||||||
try {
|
|
||||||
throw 0;
|
|
||||||
} catch (o) {
|
|
||||||
t && (c = "PASS");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
})();
|
|
||||||
console.log(c);
|
|
||||||
}
|
|
||||||
expect_stdout: "PASS"
|
|
||||||
}
|
|
||||||
|
|
||||||
issue_3035_ie8: {
|
|
||||||
mangle = {
|
|
||||||
ie8: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
var c = "FAIL";
|
|
||||||
(function(a) {
|
|
||||||
try {
|
|
||||||
throw 1;
|
|
||||||
} catch (b) {
|
|
||||||
try {
|
|
||||||
throw 0;
|
|
||||||
} catch (a) {
|
|
||||||
b && (c = "PASS");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
})();
|
|
||||||
console.log(c);
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
var c = "FAIL";
|
|
||||||
(function(t) {
|
|
||||||
try {
|
|
||||||
throw 1;
|
|
||||||
} catch (o) {
|
|
||||||
try {
|
|
||||||
throw 0;
|
|
||||||
} catch (t) {
|
|
||||||
o && (c = "PASS");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
})();
|
|
||||||
console.log(c);
|
|
||||||
}
|
|
||||||
expect_stdout: "PASS"
|
|
||||||
}
|
|
||||||
|
|
||||||
issue_3197_1: {
|
|
||||||
options = {
|
|
||||||
ie8: false,
|
|
||||||
inline: true,
|
|
||||||
reduce_vars: true,
|
|
||||||
side_effects: true,
|
|
||||||
unused: true,
|
|
||||||
}
|
|
||||||
mangle = {
|
|
||||||
ie8: false,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
var window = {};
|
|
||||||
!function() {
|
|
||||||
function Foo() {
|
|
||||||
console.log(this instanceof Foo);
|
|
||||||
}
|
|
||||||
window.Foo = Foo;
|
|
||||||
}();
|
|
||||||
new window.Foo();
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
var window = {};
|
|
||||||
window.Foo = function o() {
|
|
||||||
console.log(this instanceof o);
|
|
||||||
};
|
|
||||||
new window.Foo();
|
|
||||||
}
|
|
||||||
expect_stdout: "true"
|
|
||||||
}
|
|
||||||
|
|
||||||
issue_3197_1_ie8: {
|
|
||||||
options = {
|
|
||||||
ie8: true,
|
|
||||||
inline: true,
|
|
||||||
reduce_vars: true,
|
|
||||||
side_effects: true,
|
|
||||||
unused: true,
|
|
||||||
}
|
|
||||||
mangle = {
|
|
||||||
ie8: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
var window = {};
|
|
||||||
!function() {
|
|
||||||
function Foo() {
|
|
||||||
console.log(this instanceof Foo);
|
|
||||||
}
|
|
||||||
window.Foo = Foo;
|
|
||||||
}();
|
|
||||||
new window.Foo();
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
var window = {};
|
|
||||||
window.Foo = function Foo() {
|
|
||||||
console.log(this instanceof Foo);
|
|
||||||
};
|
|
||||||
new window.Foo();
|
|
||||||
}
|
|
||||||
expect_stdout: "true"
|
|
||||||
}
|
|
||||||
|
|
||||||
issue_3197_2: {
|
|
||||||
mangle = {
|
|
||||||
ie8: false,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
(function(a) {
|
|
||||||
var f = function f() {
|
|
||||||
console.log(this instanceof f);
|
|
||||||
};
|
|
||||||
new f(a);
|
|
||||||
})();
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
(function(n) {
|
|
||||||
var o = function n() {
|
|
||||||
console.log(this instanceof n);
|
|
||||||
};
|
|
||||||
new o(n);
|
|
||||||
})();
|
|
||||||
}
|
|
||||||
expect_stdout: "true"
|
|
||||||
}
|
|
||||||
|
|
||||||
issue_3197_2_ie8: {
|
|
||||||
mangle = {
|
|
||||||
ie8: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
(function(a) {
|
|
||||||
var f = function f() {
|
|
||||||
console.log(this instanceof f);
|
|
||||||
};
|
|
||||||
new f(a);
|
|
||||||
})();
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
(function(n) {
|
|
||||||
var o = function o() {
|
|
||||||
console.log(this instanceof o);
|
|
||||||
};
|
|
||||||
new o(n);
|
|
||||||
})();
|
|
||||||
}
|
|
||||||
expect_stdout: "true"
|
|
||||||
}
|
|
||||||
@@ -288,7 +288,7 @@ unsafe_undefined: {
|
|||||||
if_return: true,
|
if_return: true,
|
||||||
sequences: true,
|
sequences: true,
|
||||||
side_effects: true,
|
side_effects: true,
|
||||||
unsafe_undefined: true,
|
unsafe: true,
|
||||||
}
|
}
|
||||||
input: {
|
input: {
|
||||||
function f(undefined) {
|
function f(undefined) {
|
||||||
@@ -668,7 +668,8 @@ side_effects_cascade_2: {
|
|||||||
}
|
}
|
||||||
expect: {
|
expect: {
|
||||||
function f(a, b) {
|
function f(a, b) {
|
||||||
!(b = a) + (b += a) || (b += a),
|
b = a,
|
||||||
|
!a + (b += a) || (b += a),
|
||||||
b = a;
|
b = a;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -718,6 +719,30 @@ issue_27: {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
reassign_const: {
|
||||||
|
options = {
|
||||||
|
collapse_vars: 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,
|
||||||
@@ -858,77 +883,3 @@ for_init_var: {
|
|||||||
}
|
}
|
||||||
expect_stdout: "PASS"
|
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"
|
|
||||||
}
|
|
||||||
|
|
||||||
call: {
|
|
||||||
options = {
|
|
||||||
sequences: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
var a = function() {
|
|
||||||
return this;
|
|
||||||
}();
|
|
||||||
function b() {
|
|
||||||
console.log("foo");
|
|
||||||
}
|
|
||||||
b.c = function() {
|
|
||||||
console.log(this === b ? "bar" : "baz");
|
|
||||||
};
|
|
||||||
(a, b)();
|
|
||||||
(a, b.c)();
|
|
||||||
(a, function() {
|
|
||||||
console.log(this === a);
|
|
||||||
})();
|
|
||||||
new (a, b)();
|
|
||||||
new (a, b.c)();
|
|
||||||
new (a, function() {
|
|
||||||
console.log(this === a);
|
|
||||||
})();
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
var a = function() {
|
|
||||||
return this;
|
|
||||||
}();
|
|
||||||
function b() {
|
|
||||||
console.log("foo");
|
|
||||||
}
|
|
||||||
b.c = function() {
|
|
||||||
console.log(this === b ? "bar" : "baz");
|
|
||||||
},
|
|
||||||
a, b(),
|
|
||||||
(a, b.c)(),
|
|
||||||
a, function() {
|
|
||||||
console.log(this === a);
|
|
||||||
}(),
|
|
||||||
a, new b(),
|
|
||||||
a, new b.c(),
|
|
||||||
a, new function() {
|
|
||||||
console.log(this === a);
|
|
||||||
}();
|
|
||||||
}
|
|
||||||
expect_stdout: [
|
|
||||||
"foo",
|
|
||||||
"baz",
|
|
||||||
"true",
|
|
||||||
"foo",
|
|
||||||
"baz",
|
|
||||||
"false",
|
|
||||||
]
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -14,13 +14,6 @@ issue_1929: {
|
|||||||
function f(s) {
|
function f(s) {
|
||||||
return s.split(/[\\/]/);
|
return s.split(/[\\/]/);
|
||||||
}
|
}
|
||||||
console.log(JSON.stringify(f("A/B\\C\\D/E\\F")));
|
|
||||||
}
|
}
|
||||||
expect: {
|
expect_exact: "function f(s){return s.split(/[\\\\/]/)}"
|
||||||
function f(s) {
|
|
||||||
return s.split(/[\\/]/);
|
|
||||||
}
|
|
||||||
console.log(JSON.stringify(f("A/B\\C\\D/E\\F")));
|
|
||||||
}
|
|
||||||
expect_stdout: '["A","B","C","D","E","F"]'
|
|
||||||
}
|
}
|
||||||
|
|||||||
9
test/compress/super.js
Normal file
9
test/compress/super.js
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
|
||||||
|
super_can_be_parsed: {
|
||||||
|
input: {
|
||||||
|
super(1,2);
|
||||||
|
super.meth();
|
||||||
|
}
|
||||||
|
expect_exact: "super(1,2);super.meth();"
|
||||||
|
}
|
||||||
|
|
||||||
508
test/compress/template-string.js
Normal file
508
test/compress/template-string.js
Normal file
@@ -0,0 +1,508 @@
|
|||||||
|
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"
|
||||||
|
}
|
||||||
@@ -59,7 +59,7 @@ if_else_empty: {
|
|||||||
if ({} ? a : b); else {}
|
if ({} ? a : b); else {}
|
||||||
}
|
}
|
||||||
expect: {
|
expect: {
|
||||||
({}), a;
|
!{} ? b : a;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -104,7 +104,6 @@ if_return: {
|
|||||||
conditionals: true,
|
conditionals: true,
|
||||||
if_return: true,
|
if_return: true,
|
||||||
sequences: true,
|
sequences: true,
|
||||||
side_effects: true,
|
|
||||||
}
|
}
|
||||||
input: {
|
input: {
|
||||||
function f(w, x, y, z) {
|
function f(w, x, y, z) {
|
||||||
@@ -125,7 +124,7 @@ if_return: {
|
|||||||
if (w) {
|
if (w) {
|
||||||
if (y) return;
|
if (y) return;
|
||||||
} else if (z) return;
|
} else if (z) return;
|
||||||
return x == y || (x && w(), y && z()), !0;
|
return x == y || (x && w(), y && z(), !0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
12
test/compress/try-catch.js
Normal file
12
test/compress/try-catch.js
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
catch_destructuring_with_sequence: {
|
||||||
|
beautify = {
|
||||||
|
ecma: 6
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
try {
|
||||||
|
throw {};
|
||||||
|
} catch ({xCover = (0, function() {})} ) {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
expect_exact: "try{throw{}}catch({xCover=(0,function(){})}){}"
|
||||||
|
}
|
||||||
@@ -90,11 +90,17 @@ typeof_defun_1: {
|
|||||||
"function" == typeof h && h();
|
"function" == typeof h && h();
|
||||||
}
|
}
|
||||||
expect: {
|
expect: {
|
||||||
|
function g() {
|
||||||
|
h = 42;
|
||||||
|
console.log("NOPE");
|
||||||
|
}
|
||||||
function h() {
|
function h() {
|
||||||
console.log("YUP");
|
console.log("YUP");
|
||||||
}
|
}
|
||||||
|
g = 42;
|
||||||
console.log("YES");
|
console.log("YES");
|
||||||
h();
|
"function" == typeof g && g();
|
||||||
|
"function" == typeof h && h();
|
||||||
}
|
}
|
||||||
expect_stdout: [
|
expect_stdout: [
|
||||||
"YES",
|
"YES",
|
||||||
|
|||||||
@@ -16,6 +16,70 @@ 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,
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ wrap_iife_in_expression: {
|
|||||||
wrap_iife: true,
|
wrap_iife: true,
|
||||||
}
|
}
|
||||||
input: {
|
input: {
|
||||||
foo = (function() {
|
foo = (function () {
|
||||||
return bar();
|
return bar();
|
||||||
})();
|
})();
|
||||||
}
|
}
|
||||||
|
|||||||
213
test/compress/yield.js
Normal file
213
test/compress/yield.js
Normal file
@@ -0,0 +1,213 @@
|
|||||||
|
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() { yield, yield; }
|
||||||
|
function* g4() { (yield) ? yield : yield; }
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
iter = (function*() {
|
||||||
|
assignmentResult = [ x = yield ] = value;
|
||||||
|
})();
|
||||||
|
function* g1() { (yield) }
|
||||||
|
function* g2() { [yield] }
|
||||||
|
function* g3() { yield, yield; }
|
||||||
|
function* g4() { (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"
|
||||||
|
}
|
||||||
|
|
||||||
|
issue_2689: {
|
||||||
|
options = {
|
||||||
|
collapse_vars: true,
|
||||||
|
unused: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
function* y() {
|
||||||
|
var t = yield x();
|
||||||
|
return new t();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
expect_exact: "function*y(){return new(yield x())}"
|
||||||
|
}
|
||||||
@@ -1,5 +1,4 @@
|
|||||||
var fs = require("fs");
|
var fs = require("fs");
|
||||||
var parse = require("url").parse;
|
|
||||||
var path = require("path");
|
var path = require("path");
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@@ -20,9 +19,7 @@ module.exports = function(url, callback) {
|
|||||||
var result = read(url);
|
var result = read(url);
|
||||||
result.on("error", function(e) {
|
result.on("error", function(e) {
|
||||||
if (e.code != "ENOENT") return callback(e);
|
if (e.code != "ENOENT") return callback(e);
|
||||||
var options = parse(url);
|
require(url.slice(0, url.indexOf(":"))).get(url, function(res) {
|
||||||
options.rejectUnauthorized = false;
|
|
||||||
require(options.protocol.slice(0, -1)).get(options, function(res) {
|
|
||||||
if (res.statusCode !== 200) return callback(res);
|
if (res.statusCode !== 200) return callback(res);
|
||||||
res.pipe(fs.createWriteStream(local(url)).on("close", function() {
|
res.pipe(fs.createWriteStream(local(url)).on("close", function() {
|
||||||
callback(null, read(url));
|
callback(null, read(url));
|
||||||
|
|||||||
@@ -1,4 +0,0 @@
|
|||||||
function enclose() {
|
|
||||||
console.log("test enclose");
|
|
||||||
}
|
|
||||||
enclose();
|
|
||||||
3
test/input/invalid/const.js
Normal file
3
test/input/invalid/const.js
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
function f() {
|
||||||
|
const a;
|
||||||
|
}
|
||||||
3
test/input/invalid/export_1.js
Normal file
3
test/input/invalid/export_1.js
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
{
|
||||||
|
export var V = 1;
|
||||||
|
}
|
||||||
1
test/input/invalid/export_2.js
Normal file
1
test/input/invalid/export_2.js
Normal file
@@ -0,0 +1 @@
|
|||||||
|
export class{};
|
||||||
1
test/input/invalid/export_3.js
Normal file
1
test/input/invalid/export_3.js
Normal file
@@ -0,0 +1 @@
|
|||||||
|
export function(){};
|
||||||
3
test/input/invalid/import.js
Normal file
3
test/input/invalid/import.js
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
{
|
||||||
|
import A from "B";
|
||||||
|
}
|
||||||
1
test/input/invalid/sequence.js
Normal file
1
test/input/invalid/sequence.js
Normal file
@@ -0,0 +1 @@
|
|||||||
|
(a, ...b);
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
var bar = (function() {
|
var bar = (function () {
|
||||||
function foo (bar) {
|
function foo (bar) {
|
||||||
return bar;
|
return bar;
|
||||||
}
|
}
|
||||||
|
|||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user