Compare commits
744 Commits
harmony-v3
...
v3.9.4
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
49ea629f3f | ||
|
|
13c72a986c | ||
|
|
08af3eae44 | ||
|
|
27bdcbbd83 | ||
|
|
2c4d7d66ef | ||
|
|
d1cc5270a3 | ||
|
|
75c5b6029b | ||
|
|
fa14a9cfcd | ||
|
|
aeb9ea5ac2 | ||
|
|
798841be82 | ||
|
|
cc6eb4b15f | ||
|
|
14eee81dc6 | ||
|
|
55ebb27878 | ||
|
|
87046410ef | ||
|
|
f9b3198714 | ||
|
|
48b62393a4 | ||
|
|
a00f8dade7 | ||
|
|
9daa2fb6f5 | ||
|
|
8d81d264f4 | ||
|
|
5ef7060098 | ||
|
|
938368ba21 | ||
|
|
fe2f1965d6 | ||
|
|
30ed8f5580 | ||
|
|
dc9e7cd1fe | ||
|
|
76f40e2528 | ||
|
|
8024f7f7a8 | ||
|
|
eb7fa25270 | ||
|
|
ee7647dc67 | ||
|
|
bd2f53bc8b | ||
|
|
e8a7956b6f | ||
|
|
2b24dc25fb | ||
|
|
35cc5aa06f | ||
|
|
c1dd49e075 | ||
|
|
c76ee4b868 | ||
|
|
e23bf48052 | ||
|
|
7e0ad232b0 | ||
|
|
63adfb1590 | ||
|
|
f9806b43c3 | ||
|
|
c4c9c6d37d | ||
|
|
33f3b0c1d9 | ||
|
|
abb8ae02a5 | ||
|
|
97728c4f0b | ||
|
|
f74b7f7401 | ||
|
|
b06fd8a933 | ||
|
|
1bb0804d60 | ||
|
|
998245ffd6 | ||
|
|
7a033bb825 | ||
|
|
a441b00951 | ||
|
|
88985a46ed | ||
|
|
34ead0430b | ||
|
|
66ab2df97f | ||
|
|
b656f7c083 | ||
|
|
873db281e8 | ||
|
|
6bf1486935 | ||
|
|
ffa1943177 | ||
|
|
ac429dc8e1 | ||
|
|
3766d5c962 | ||
|
|
20f9a1d908 | ||
|
|
dcb74f558e | ||
|
|
0794aaa2c2 | ||
|
|
74801de315 | ||
|
|
f80d5b8c9e | ||
|
|
d900006973 | ||
|
|
39f849590b | ||
|
|
818738beec | ||
|
|
bc2a4a3bb8 | ||
|
|
a4a8ccea8c | ||
|
|
36dcfa3e82 | ||
|
|
94f33570e3 | ||
|
|
44d6912a55 | ||
|
|
3a4497a1c3 | ||
|
|
3ee13cae02 | ||
|
|
99cf3a38c5 | ||
|
|
3ae24329eb | ||
|
|
01b13d797c | ||
|
|
306e8e9873 | ||
|
|
9577c8c1b7 | ||
|
|
925a0ca1a0 | ||
|
|
b694bfa351 | ||
|
|
a2fc32c64b | ||
|
|
88504ab869 | ||
|
|
e38754e802 | ||
|
|
eb6f32bfc3 | ||
|
|
f110601fb4 | ||
|
|
2a508c6e5f | ||
|
|
fd6144d95b | ||
|
|
60d4e7b09f | ||
|
|
b38838c6bf | ||
|
|
708973e51d | ||
|
|
dac9e69f9e | ||
|
|
39aa33749b | ||
|
|
da68ec6e19 | ||
|
|
15a3ebd467 | ||
|
|
9110fac9a2 | ||
|
|
83f42ede36 | ||
|
|
0ce71bbec0 | ||
|
|
46d142cbf6 | ||
|
|
38c3bcf9a0 | ||
|
|
6e9afdc94f | ||
|
|
c4d28e3b2a | ||
|
|
77261e1ee0 | ||
|
|
903a5df9a5 | ||
|
|
c810ecd081 | ||
|
|
dce9dfce0e | ||
|
|
3d72663689 | ||
|
|
a2b16e89a4 | ||
|
|
b35f4c5a83 | ||
|
|
41eb4f1725 | ||
|
|
94bc221669 | ||
|
|
822d298a55 | ||
|
|
273c6020ba | ||
|
|
1b07f64057 | ||
|
|
80d9c44b22 | ||
|
|
dc0cd088cf | ||
|
|
c69c026728 | ||
|
|
b5f4e1187f | ||
|
|
827bcec186 | ||
|
|
d105ab9722 | ||
|
|
b39228892d | ||
|
|
ff72eaa3c3 | ||
|
|
0a1c9b34ce | ||
|
|
03e968be62 | ||
|
|
421bb7083a | ||
|
|
bdc8ef2218 | ||
|
|
bca52fcba2 | ||
|
|
d6d31cbb5a | ||
|
|
a051846d22 | ||
|
|
3485472866 | ||
|
|
c8d60d6983 | ||
|
|
6092bf23de | ||
|
|
7052ce5aef | ||
|
|
d13b71297e | ||
|
|
457f958af3 | ||
|
|
53517db3e4 | ||
|
|
c13caf4876 | ||
|
|
fbfa6178a6 | ||
|
|
5315dd95b0 | ||
|
|
31a7bf2a22 | ||
|
|
f0a29902ac | ||
|
|
0d820e4c0a | ||
|
|
f01f580d6c | ||
|
|
c01ff76288 | ||
|
|
83a42716c3 | ||
|
|
2557148bba | ||
|
|
dd22eda888 | ||
|
|
f4c77886e7 | ||
|
|
df547ffd97 | ||
|
|
70551febc8 | ||
|
|
44499a6643 | ||
|
|
470a7d4df1 | ||
|
|
551420132c | ||
|
|
b0040ba654 | ||
|
|
c93ca6ee53 | ||
|
|
df506439b1 | ||
|
|
36b2d35bf3 | ||
|
|
79c60032a5 | ||
|
|
a3754068dd | ||
|
|
2ba5f391e0 | ||
|
|
87119e44a0 | ||
|
|
b499e03f82 | ||
|
|
a478f275e4 | ||
|
|
e9e76dcf04 | ||
|
|
0dcedad2d5 | ||
|
|
36a430cd1e | ||
|
|
41a6eb892a | ||
|
|
91d87ae663 | ||
|
|
5beb7e4797 | ||
|
|
46caaa82ba | ||
|
|
5d258259a4 | ||
|
|
14c35739dd | ||
|
|
f5ceff6e4b | ||
|
|
4d6771b9b1 | ||
|
|
d17191111a | ||
|
|
0ff607cb80 | ||
|
|
1988495d71 | ||
|
|
fdc10086da | ||
|
|
746f5f6c62 | ||
|
|
d83d3d741a | ||
|
|
99ac73a635 | ||
|
|
a2e4c2fd97 | ||
|
|
94785e8e14 | ||
|
|
4dbdac9c31 | ||
|
|
78c8efd851 | ||
|
|
af310ba2d0 | ||
|
|
2f3930d1b9 | ||
|
|
d1a78920d9 | ||
|
|
d9cd3d33c8 | ||
|
|
22b47cdd63 | ||
|
|
4cf612dc9f | ||
|
|
a19d31dd33 | ||
|
|
01d6e0f223 | ||
|
|
ab050e7a94 | ||
|
|
75aa6ef848 | ||
|
|
519a00bd8a | ||
|
|
3ff0feddee | ||
|
|
74396acc86 | ||
|
|
036bca980c | ||
|
|
18c2b1841b | ||
|
|
fe19ab7c57 | ||
|
|
9074f05129 | ||
|
|
04fbb1f949 | ||
|
|
bf7e4ca1a3 | ||
|
|
d68ddc31f9 | ||
|
|
500e31e03b | ||
|
|
bef856addb | ||
|
|
9a6faf365b | ||
|
|
e915832a36 | ||
|
|
0593892d6e | ||
|
|
b866a23671 | ||
|
|
1283d73853 | ||
|
|
1b61a81b5d | ||
|
|
5a88c30d65 | ||
|
|
168ae747ad | ||
|
|
d4b7010678 | ||
|
|
e27493f3c2 | ||
|
|
292d1de363 | ||
|
|
6768e6578f | ||
|
|
48a0f6fe41 | ||
|
|
81caadb709 | ||
|
|
d959e0b86f | ||
|
|
67278e76c8 | ||
|
|
c289ba1139 | ||
|
|
02cc4a0d03 | ||
|
|
4e06e1ca34 | ||
|
|
644f65feca | ||
|
|
8504a4ea0e | ||
|
|
10c1a78772 | ||
|
|
a6a0319f1c | ||
|
|
d1b2ecec27 | ||
|
|
552be61c4d | ||
|
|
dcfc4aca5b | ||
|
|
4027f87717 | ||
|
|
910799ca99 | ||
|
|
4bd36dc8da | ||
|
|
ab15c40770 | ||
|
|
fe65ce9658 | ||
|
|
d6fd18d0b0 | ||
|
|
0d17c5b0fa | ||
|
|
5b20bad4b3 | ||
|
|
765a06340f | ||
|
|
5045e140b1 | ||
|
|
10648c9af6 | ||
|
|
87e67ec299 | ||
|
|
61a0dad9fe | ||
|
|
3e2c51a4da | ||
|
|
0e29ad5eb9 | ||
|
|
0f2687ecfc | ||
|
|
1c0defdc03 | ||
|
|
dcbf2236c7 | ||
|
|
24bb288832 | ||
|
|
6ad8e1081f | ||
|
|
815eff1f7c | ||
|
|
1e9b576ee9 | ||
|
|
3797458365 | ||
|
|
1858c2018c | ||
|
|
ec7f071272 | ||
|
|
f1eb03f2c0 | ||
|
|
0f4cfa877a | ||
|
|
1d5c2becbd | ||
|
|
22a09ea7c5 | ||
|
|
bad664c632 | ||
|
|
8a191c0a84 | ||
|
|
83fb8b4ca1 | ||
|
|
f38e31bd1e | ||
|
|
24e8b47977 | ||
|
|
95618793a4 | ||
|
|
2f3b460212 | ||
|
|
06e135e35f | ||
|
|
ebbf3d4a51 | ||
|
|
a270ba6b59 | ||
|
|
37f35e4ac2 | ||
|
|
50a578c1f6 | ||
|
|
85237b08d4 | ||
|
|
27b159e711 | ||
|
|
82b3eed5ef | ||
|
|
0f7aa41e33 | ||
|
|
370c8e0385 | ||
|
|
4240fba9b8 | ||
|
|
267bc70d33 | ||
|
|
a53ab99378 | ||
|
|
02308a7b56 | ||
|
|
0b3705e82f | ||
|
|
da5a21b240 | ||
|
|
5bd0cf8633 | ||
|
|
9199ab5846 | ||
|
|
ca6dce43fe | ||
|
|
543dd7d3d7 | ||
|
|
6b4886c908 | ||
|
|
0201cb4b52 | ||
|
|
cd072317d0 | ||
|
|
0785a15ace | ||
|
|
b1279a46d9 | ||
|
|
b571619d31 | ||
|
|
7b5350b459 | ||
|
|
1549db70e6 | ||
|
|
8ff9a3c8fb | ||
|
|
91cae51d8f | ||
|
|
8af2f5fbcf | ||
|
|
86a8016323 | ||
|
|
009dcdae01 | ||
|
|
f86f615d83 | ||
|
|
d3d1d11926 | ||
|
|
736019b767 | ||
|
|
a39bdb5840 | ||
|
|
e8ab0a44b2 | ||
|
|
c3ca293e6b | ||
|
|
516b67a43b | ||
|
|
eba3a37bb5 | ||
|
|
6d57ca1a59 | ||
|
|
3320251b4b | ||
|
|
33c94d3bd9 | ||
|
|
b18f717b46 | ||
|
|
a0d4b648bb | ||
|
|
6db880e16d | ||
|
|
a82003d6ac | ||
|
|
da9f1622fc | ||
|
|
8a4c7077bb | ||
|
|
0a63f2f2b0 | ||
|
|
931ac66638 | ||
|
|
35338a100f | ||
|
|
d57b606e73 | ||
|
|
00ada04111 | ||
|
|
a31c477fea | ||
|
|
bde7418ce1 | ||
|
|
70bb304a0a | ||
|
|
9d3b1efd86 | ||
|
|
482e1baea3 | ||
|
|
e4f5ba1d29 | ||
|
|
b9053c7a25 | ||
|
|
d357a7aabc | ||
|
|
ae77ebe5a5 | ||
|
|
04439edcec | ||
|
|
a246195412 | ||
|
|
8939a36bc7 | ||
|
|
a21c348d93 | ||
|
|
1f0def10eb | ||
|
|
f87caac9d8 | ||
|
|
d538a73250 | ||
|
|
2e4fbdeb08 | ||
|
|
3bc7cc82bb | ||
|
|
45fbdbc2dc | ||
|
|
54cb678055 | ||
|
|
e88c439eac | ||
|
|
9fc8cd4076 | ||
|
|
5476cb8f05 | ||
|
|
6a30e1d6be | ||
|
|
e4881245d9 | ||
|
|
354fec8a9c | ||
|
|
11cdab745d | ||
|
|
a89d424a0b | ||
|
|
429d2b56b7 | ||
|
|
2ea96549c5 | ||
|
|
fba008e298 | ||
|
|
c37a8e927e | ||
|
|
413bbe0480 | ||
|
|
34075fc4c4 | ||
|
|
e5436ca566 | ||
|
|
cfde686eab | ||
|
|
a206964c0a | ||
|
|
c56d89f804 | ||
|
|
c215706350 | ||
|
|
d3b93ec682 | ||
|
|
6fe20dbe33 | ||
|
|
7ccdf3337b | ||
|
|
dafed54764 | ||
|
|
a84beafd1b | ||
|
|
f01cc1e413 | ||
|
|
338dd144b8 | ||
|
|
c719552317 | ||
|
|
855964a87a | ||
|
|
a438e2fca9 | ||
|
|
00833e893a | ||
|
|
f1a77e4fc0 | ||
|
|
b55a2fd531 | ||
|
|
e8a2c0b5bf | ||
|
|
21cd7e3f57 | ||
|
|
5172ba5f2a | ||
|
|
a57b069409 | ||
|
|
4454656c3b | ||
|
|
fa43768ce0 | ||
|
|
a74e600fa0 | ||
|
|
4b21526310 | ||
|
|
a7a7b1daed | ||
|
|
7436977aa5 | ||
|
|
e3c565b46f | ||
|
|
54b0b49b68 | ||
|
|
65648d84a5 | ||
|
|
fd788590f6 | ||
|
|
143f9054da | ||
|
|
f2286c33f1 | ||
|
|
b9615f7a62 | ||
|
|
c520e99eda | ||
|
|
615ae37ca3 | ||
|
|
7aa7f21872 | ||
|
|
4430a436eb | ||
|
|
9707ccdc9f | ||
|
|
cb8f3a2a31 | ||
|
|
8b3259e0c2 | ||
|
|
b66f47b8dd | ||
|
|
8d2e6f333e | ||
|
|
b3ef5e514d | ||
|
|
627f5fb41e | ||
|
|
d90777b724 | ||
|
|
e49297e5eb | ||
|
|
ebd82b3fb6 | ||
|
|
d074aa6e27 | ||
|
|
b052f62710 | ||
|
|
d4ac84b255 | ||
|
|
e250396d7e | ||
|
|
c6fa39b482 | ||
|
|
9aae4f2424 | ||
|
|
008c236137 | ||
|
|
b1c0664066 | ||
|
|
ea999b0e92 | ||
|
|
ce7e220de4 | ||
|
|
2bdaca10ae | ||
|
|
aa0029204e | ||
|
|
f352bcec3a | ||
|
|
08514030f4 | ||
|
|
694ca5d045 | ||
|
|
57fb58b263 | ||
|
|
18c1c9b38a | ||
|
|
5c1ae3662d | ||
|
|
cfebeb2f63 | ||
|
|
fc78423f1d | ||
|
|
2a5277b391 | ||
|
|
d47547dc71 | ||
|
|
304db15a20 | ||
|
|
7cf72b8d66 | ||
|
|
cea685f8d9 | ||
|
|
8d4b5344f4 | ||
|
|
34a0ab6f2c | ||
|
|
bcebacbb9e | ||
|
|
018a5a750a | ||
|
|
b468103f26 | ||
|
|
66c126ffde | ||
|
|
fdee083465 | ||
|
|
5ffc17d4aa | ||
|
|
6aa750010f | ||
|
|
76df77c08c | ||
|
|
957d5537a8 | ||
|
|
88c8f4e363 | ||
|
|
ab36b9b10a | ||
|
|
28330913d8 | ||
|
|
766a4147d4 | ||
|
|
915c7e234d | ||
|
|
e54ddcbb8a | ||
|
|
9e19e63551 | ||
|
|
bce7ee5f6a | ||
|
|
b39043f3ab | ||
|
|
caf96acb08 | ||
|
|
c76749084b | ||
|
|
5843494ee2 | ||
|
|
efa21ae3e6 | ||
|
|
24d9633a35 | ||
|
|
7963b96681 | ||
|
|
8c62d854ce | ||
|
|
69931574e1 | ||
|
|
b5af8a1914 | ||
|
|
c14d09ba84 | ||
|
|
4fc39d8dad | ||
|
|
0b7c70f726 | ||
|
|
f72d3029dd | ||
|
|
1a0d6edc81 | ||
|
|
7b59b2f5b2 | ||
|
|
7bc7704edf | ||
|
|
14e712ee80 | ||
|
|
f83adcc995 | ||
|
|
df8a99439a | ||
|
|
6b91d12ec3 | ||
|
|
f37b91879f | ||
|
|
d835c72c80 | ||
|
|
c4cebb4b01 | ||
|
|
d51a00a450 | ||
|
|
fc0f168a0c | ||
|
|
a0ca595c2c | ||
|
|
1a314e9f60 | ||
|
|
6fcbd5e217 | ||
|
|
22cea023d1 | ||
|
|
70d4477e05 | ||
|
|
838f837379 | ||
|
|
82a8b6f612 | ||
|
|
69fc7ca8da | ||
|
|
0a79496e0a | ||
|
|
9e87edfc2e | ||
|
|
27211cf2d5 | ||
|
|
b5ce199711 | ||
|
|
c71ed91e63 | ||
|
|
f7545d0f1c | ||
|
|
59eecb6bf5 | ||
|
|
d83c6490ab | ||
|
|
7362f57966 | ||
|
|
eaa2c1f6af | ||
|
|
6a916523d4 | ||
|
|
ba7069d52b | ||
|
|
4dd7d0e39b | ||
|
|
90199d0a96 | ||
|
|
b82fd0ad41 | ||
|
|
183da16896 | ||
|
|
87857b0f1b | ||
|
|
e5f6a88233 | ||
|
|
8d0b00317e | ||
|
|
db49daf365 | ||
|
|
923deeff35 | ||
|
|
0b62a28b47 | ||
|
|
44116c6d2b | ||
|
|
b5bab254ce | ||
|
|
81603ecd15 | ||
|
|
e67553fa55 | ||
|
|
fcf542f262 | ||
|
|
8adfc29f91 | ||
|
|
02f47e1713 | ||
|
|
07f64d4050 | ||
|
|
6982a0554c | ||
|
|
fa3250199a | ||
|
|
06b9894c19 | ||
|
|
9f9db504d7 | ||
|
|
82ae95c334 | ||
|
|
9a5e2052c4 | ||
|
|
b1410be443 | ||
|
|
12985d86c2 | ||
|
|
49bfc6b555 | ||
|
|
d1c6bb8c7c | ||
|
|
5c169615a8 | ||
|
|
73d77f4f64 | ||
|
|
ccf0e2ef4f | ||
|
|
20ca0f5906 | ||
|
|
b29d435bb5 | ||
|
|
90585e29c2 | ||
|
|
d8fc281915 | ||
|
|
188c39e8d5 | ||
|
|
5429234138 | ||
|
|
b9f72a4a81 | ||
|
|
fc6ebd04a5 | ||
|
|
7e00a12741 | ||
|
|
10b3752b1e | ||
|
|
fe51a91395 | ||
|
|
951d87ca94 | ||
|
|
798fc21530 | ||
|
|
a75a046abb | ||
|
|
38f2b4579f | ||
|
|
56e2a369d0 | ||
|
|
0daa199fa8 | ||
|
|
73e98dcda4 | ||
|
|
36bca6934d | ||
|
|
ace5811691 | ||
|
|
ba7bad0dbd | ||
|
|
b8b2ac5230 | ||
|
|
ea2359381b | ||
|
|
52de64cf16 | ||
|
|
455790202a | ||
|
|
f40f5eb228 | ||
|
|
604caa09e7 | ||
|
|
29a71d3aae | ||
|
|
39a907bde3 | ||
|
|
70474310f3 | ||
|
|
b5f0f4f3a1 | ||
|
|
2905fd625a | ||
|
|
4facd94029 | ||
|
|
4b5993ff15 | ||
|
|
2351a672ea | ||
|
|
4a528c469c | ||
|
|
82d1ef0242 | ||
|
|
7fdd2082a6 | ||
|
|
e529f54e90 | ||
|
|
d626e9bf19 | ||
|
|
a2a9459684 | ||
|
|
a3dfeea144 | ||
|
|
d316fb139d | ||
|
|
83d8aa8b12 | ||
|
|
4f1c12b6fd | ||
|
|
d8e0e34354 | ||
|
|
0c4f315c02 | ||
|
|
0809699bdc | ||
|
|
2088e1c19d | ||
|
|
bf1d47180c | ||
|
|
0cfbd79aa1 | ||
|
|
d66d86f20b | ||
|
|
905325d3e2 | ||
|
|
dea0cc0662 | ||
|
|
d69d8007d6 | ||
|
|
c0b8f2a16d | ||
|
|
cb0257dbbf | ||
|
|
9637f51b68 | ||
|
|
3026bd8975 | ||
|
|
78a44d5ab0 | ||
|
|
7e13c0db40 | ||
|
|
e6a2e9e4d0 | ||
|
|
e773f03927 | ||
|
|
b16380d669 | ||
|
|
334b07a3db | ||
|
|
3cc1527f00 | ||
|
|
525a61fb55 | ||
|
|
c3a002ff97 | ||
|
|
fad6766a90 | ||
|
|
aa664dea0a | ||
|
|
102f994b9d | ||
|
|
2a4c68be4f | ||
|
|
541e6011af | ||
|
|
6fa3fbeae8 | ||
|
|
4eb4cb656c | ||
|
|
193612ac67 | ||
|
|
95cfce68ea | ||
|
|
ec4202590d | ||
|
|
5e2cd07d6f | ||
|
|
06166df999 | ||
|
|
e2dc9cf091 | ||
|
|
069df27bf1 | ||
|
|
3e7873217c | ||
|
|
e21bab7ce6 | ||
|
|
ac9a168fba | ||
|
|
81b64549ce | ||
|
|
082e004b87 | ||
|
|
983e69128b | ||
|
|
b335912e86 | ||
|
|
cc07f3b806 | ||
|
|
07e4b64f3a | ||
|
|
d3ce2bc9e7 | ||
|
|
cff3bf4914 | ||
|
|
79cfac77bd | ||
|
|
224c14d49d | ||
|
|
7857354d85 | ||
|
|
b4aef753e7 | ||
|
|
424173d311 | ||
|
|
ec7cd1dcf7 | ||
|
|
7def684730 | ||
|
|
10f961c27b | ||
|
|
b483678ca7 | ||
|
|
cbbe6fad60 | ||
|
|
f96929c031 | ||
|
|
2b6657e967 | ||
|
|
7c0c92943f | ||
|
|
62a66dfff4 | ||
|
|
2cab348341 | ||
|
|
460218a3f8 | ||
|
|
e49416e4aa | ||
|
|
d4d7d99b70 | ||
|
|
6a696d0a7b | ||
|
|
1c9e13f47d | ||
|
|
b757450cd8 | ||
|
|
23ec484806 | ||
|
|
f1e1bb419a | ||
|
|
6a0af85c8b | ||
|
|
09269be974 | ||
|
|
bf832cde16 | ||
|
|
2972d58dbb | ||
|
|
2e22d38a02 | ||
|
|
ce27bcd69a | ||
|
|
9336cc8247 | ||
|
|
9809567dfc | ||
|
|
1ee8be8d91 | ||
|
|
8430c2f9f8 | ||
|
|
659c8a7632 | ||
|
|
3564b4f20d | ||
|
|
3505a3604a | ||
|
|
9b1bc6c014 | ||
|
|
9f23185f2b | ||
|
|
b82feb9302 | ||
|
|
7f2a591c7e | ||
|
|
afbcebddf6 | ||
|
|
484e484571 | ||
|
|
6f3f21233f | ||
|
|
a6873a3859 | ||
|
|
7a6d452b54 | ||
|
|
9b58b54e2d | ||
|
|
c598a12af9 | ||
|
|
cfe3a98ce5 | ||
|
|
14778e049b | ||
|
|
446fb0198b | ||
|
|
7d3cddf9d6 | ||
|
|
6dead95eb3 | ||
|
|
cc931b3ad8 | ||
|
|
d838b4b52e | ||
|
|
2f3bddbaca | ||
|
|
673b071637 | ||
|
|
da82fa59a7 | ||
|
|
333792352e | ||
|
|
e2ec270b04 | ||
|
|
ed7a0a454e | ||
|
|
d819559a01 | ||
|
|
8ca49155a8 | ||
|
|
b95e3338d9 | ||
|
|
e40a0ee9c6 | ||
|
|
cb62bd98d3 | ||
|
|
f30790b11b | ||
|
|
5205dbcbf4 | ||
|
|
3ff625de7e | ||
|
|
4832bc5d88 | ||
|
|
7f342cb3e3 | ||
|
|
05e7d34ed4 | ||
|
|
86607156e3 | ||
|
|
0fe259e9c5 | ||
|
|
8701a99a15 | ||
|
|
1476c78b53 | ||
|
|
cb6a92892f | ||
|
|
f1556cb945 | ||
|
|
efffb81735 | ||
|
|
202f90ef8f | ||
|
|
c07ea17c01 | ||
|
|
edb4e3bd52 | ||
|
|
4113609dd4 | ||
|
|
7ac7b0872f | ||
|
|
86ae5881b7 | ||
|
|
fac003c64f | ||
|
|
2273655c17 | ||
|
|
01057cf76d | ||
|
|
032f096b7f | ||
|
|
4b334edf49 | ||
|
|
8ddcbc39e6 | ||
|
|
0b0eac1d5d | ||
|
|
b29fc8b27c | ||
|
|
5de369fa67 | ||
|
|
7918a50d52 | ||
|
|
21794c9b8d | ||
|
|
6c686ce593 | ||
|
|
db902af4c6 | ||
|
|
7d6907cb99 | ||
|
|
092d9affb8 | ||
|
|
8f681b1d17 | ||
|
|
90313875f7 | ||
|
|
3f18a61532 | ||
|
|
02a6ce07eb | ||
|
|
738fd52bc4 | ||
|
|
d18979bb23 | ||
|
|
8266993c6e | ||
|
|
9a137e8613 | ||
|
|
ef618332ea | ||
|
|
7f418978c9 | ||
|
|
04cc395c35 | ||
|
|
e008dc1bde | ||
|
|
ddf96cfda2 | ||
|
|
ebfd5c5c74 | ||
|
|
f2ad542679 | ||
|
|
c43118be4f | ||
|
|
93f3b2b114 | ||
|
|
bf000beae7 | ||
|
|
0e16d92786 | ||
|
|
2441827408 | ||
|
|
0aff037a35 | ||
|
|
74a2f53683 | ||
|
|
e20935c3f2 | ||
|
|
3e34f62a1c | ||
|
|
d21cb84696 | ||
|
|
3dd495ecdd |
10
.github/ISSUE_TEMPLATE.md
vendored
10
.github/ISSUE_TEMPLATE.md
vendored
@@ -1,11 +1,7 @@
|
|||||||
**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**
|
||||||
@@ -24,6 +20,6 @@
|
|||||||
**JavaScript output or error produced.**
|
**JavaScript output or error produced.**
|
||||||
|
|
||||||
<!--
|
<!--
|
||||||
Note: `uglify-js` only supports ES5.
|
Note: `uglify-js` only supports JavaScript.
|
||||||
Those wishing to minify ES6 should use `uglify-es`.
|
Those wishing to minify ES6+ should transpile first.
|
||||||
-->
|
-->
|
||||||
|
|||||||
45
.github/workflows/ci.yml
vendored
Normal file
45
.github/workflows/ci.yml
vendored
Normal file
@@ -0,0 +1,45 @@
|
|||||||
|
name: CI
|
||||||
|
on: [ push, pull_request ]
|
||||||
|
jobs:
|
||||||
|
test:
|
||||||
|
strategy:
|
||||||
|
matrix:
|
||||||
|
node: [ "0.8", "0.10", "0.12", "4", "6", "8", "10", "12", latest ]
|
||||||
|
os: [ ubuntu-latest, windows-latest ]
|
||||||
|
script: [ compress, mocha, release/benchmark, release/jetstream ]
|
||||||
|
exclude:
|
||||||
|
- node: "0.8"
|
||||||
|
script: release/benchmark
|
||||||
|
- node: "0.8"
|
||||||
|
script: release/jetstream
|
||||||
|
name: ${{ matrix.node }} ${{ matrix.os }} ${{ matrix.script }}
|
||||||
|
runs-on: ${{ matrix.os }}
|
||||||
|
env:
|
||||||
|
NODE: ${{ matrix.node }}
|
||||||
|
TYPE: ${{ matrix.script }}
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v2
|
||||||
|
- uses: actions/cache@v1
|
||||||
|
with:
|
||||||
|
path: tmp
|
||||||
|
key: tmp ${{ matrix.script }}
|
||||||
|
- name: Perform tests
|
||||||
|
shell: bash
|
||||||
|
run: |
|
||||||
|
git clone --branch v1.5.4 --depth 1 https://github.com/jasongin/nvs.git ~/.nvs
|
||||||
|
while ! timeout 60 bash -c '. ~/.nvs/nvs.sh add $NODE && nvs use $NODE'; do
|
||||||
|
cd ~/.nvs
|
||||||
|
while !(git clean -xdf); do echo "'git clean' failed - retrying..."; done
|
||||||
|
cd -
|
||||||
|
done
|
||||||
|
. ~/.nvs/nvs.sh --version
|
||||||
|
nvs use $NODE
|
||||||
|
node --version
|
||||||
|
npm config set audit false
|
||||||
|
npm config set optional false
|
||||||
|
npm config set save false
|
||||||
|
npm config set strict-ssl false
|
||||||
|
npm config set update-notifier false
|
||||||
|
npm --version
|
||||||
|
while !(npm install); do echo "'npm install' failed - retrying..."; done
|
||||||
|
node test/$TYPE
|
||||||
35
.github/workflows/ufuzz.yml
vendored
Normal file
35
.github/workflows/ufuzz.yml
vendored
Normal file
@@ -0,0 +1,35 @@
|
|||||||
|
name: Fuzzing
|
||||||
|
on:
|
||||||
|
pull_request:
|
||||||
|
schedule:
|
||||||
|
- cron: "*/8 * * * *"
|
||||||
|
jobs:
|
||||||
|
ufuzz:
|
||||||
|
strategy:
|
||||||
|
fail-fast: false
|
||||||
|
matrix:
|
||||||
|
os: [ ubuntu-latest, windows-latest ]
|
||||||
|
name: ${{ matrix.os }}
|
||||||
|
runs-on: ${{ matrix.os }}
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v2
|
||||||
|
- name: Perform fuzzing
|
||||||
|
shell: bash
|
||||||
|
run: |
|
||||||
|
git clone --branch v1.5.4 --depth 1 https://github.com/jasongin/nvs.git ~/.nvs
|
||||||
|
while ! timeout 60 bash -c '. ~/.nvs/nvs.sh add 10 && nvs use 10'; do
|
||||||
|
cd ~/.nvs
|
||||||
|
while !(git clean -xdf); do echo "'git clean' failed - retrying..."; done
|
||||||
|
cd -
|
||||||
|
done
|
||||||
|
. ~/.nvs/nvs.sh --version
|
||||||
|
nvs use 10
|
||||||
|
node --version
|
||||||
|
npm config set audit false
|
||||||
|
npm config set optional false
|
||||||
|
npm config set save false
|
||||||
|
npm config set strict-ssl false
|
||||||
|
npm config set update-notifier false
|
||||||
|
npm --version
|
||||||
|
while !(npm install); do echo "'npm install' failed - retrying..."; done
|
||||||
|
node test/ufuzz/job 3600000
|
||||||
14
.travis.yml
14
.travis.yml
@@ -1,14 +0,0 @@
|
|||||||
language: node_js
|
|
||||||
node_js:
|
|
||||||
- "0.10"
|
|
||||||
- "0.12"
|
|
||||||
- "4"
|
|
||||||
- "6"
|
|
||||||
- "8"
|
|
||||||
env:
|
|
||||||
- UGLIFYJS_TEST_ALL=1
|
|
||||||
matrix:
|
|
||||||
fast_finish: true
|
|
||||||
sudo: false
|
|
||||||
cache:
|
|
||||||
directories: tmp
|
|
||||||
61
CONTRIBUTING.md
Normal file
61
CONTRIBUTING.md
Normal file
@@ -0,0 +1,61 @@
|
|||||||
|
Contributing
|
||||||
|
============
|
||||||
|
|
||||||
|
## Documentation
|
||||||
|
|
||||||
|
Every new feature and API change should be accompanied by a README additon.
|
||||||
|
|
||||||
|
## Testing
|
||||||
|
|
||||||
|
All features and bugs should have tests that verify the fix. You can run all
|
||||||
|
tests using `npm test`.
|
||||||
|
|
||||||
|
The most common type of test are tests that verify input and output of the
|
||||||
|
Uglify transforms. These tests exist in `test/compress`. New tests can be added
|
||||||
|
either to an existing file or in a new file `issue-xxx.js`.
|
||||||
|
|
||||||
|
Tests that cannot be expressed as a simple AST can be found in `test/mocha`.
|
||||||
|
|
||||||
|
## Code style
|
||||||
|
|
||||||
|
- File encoding must be `UTF-8`.
|
||||||
|
- `LF` is always used as a line ending.
|
||||||
|
- Statements end with semicolons.
|
||||||
|
- Indentation uses 4 spaces, switch `case` 2 spaces.
|
||||||
|
- Identifiers use `snake_case`.
|
||||||
|
- Strings use double quotes (`"`).
|
||||||
|
- Use a trailing comma for multiline array and object literals to minimize diffs.
|
||||||
|
- The Uglify code only uses ES5, even in the `harmony` branch.
|
||||||
|
- Line length should be at most 80 cols, except when it is easier to read a
|
||||||
|
longer line.
|
||||||
|
- If both sides of a comparison are of the same type, `==` and `!=` are used.
|
||||||
|
- Multiline conditions place `&&` and `||` first on the line.
|
||||||
|
|
||||||
|
**Example feature**
|
||||||
|
|
||||||
|
```js
|
||||||
|
OPT(AST_Debugger, function(self, compressor) {
|
||||||
|
if (compressor.option("drop_debugger"))
|
||||||
|
return make_node(AST_EmptyStatement, self);
|
||||||
|
return self;
|
||||||
|
});
|
||||||
|
```
|
||||||
|
|
||||||
|
**Example test case**
|
||||||
|
|
||||||
|
```js
|
||||||
|
drop_debugger: {
|
||||||
|
options = {
|
||||||
|
drop_debugger: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
debugger;
|
||||||
|
if (foo) debugger;
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
if (foo);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
2
LICENSE
2
LICENSE
@@ -1,6 +1,6 @@
|
|||||||
UglifyJS is released under the BSD license:
|
UglifyJS is released under the BSD license:
|
||||||
|
|
||||||
Copyright 2012-2013 (c) Mihai Bazon <mihai.bazon@gmail.com>
|
Copyright 2012-2019 (c) Mihai Bazon <mihai.bazon@gmail.com>
|
||||||
|
|
||||||
Redistribution and use in source and binary forms, with or without
|
Redistribution and use in source and binary forms, with or without
|
||||||
modification, are permitted provided that the following conditions
|
modification, are permitted provided that the following conditions
|
||||||
|
|||||||
264
README.md
264
README.md
@@ -1,11 +1,13 @@
|
|||||||
uglify-es
|
UglifyJS 3
|
||||||
=========
|
==========
|
||||||
|
|
||||||
A JavaScript parser, mangler/compressor and beautifier toolkit for ES6+.
|
UglifyJS is a JavaScript parser, minifier, compressor and beautifier toolkit.
|
||||||
|
|
||||||
#### Note:
|
#### Note:
|
||||||
- **`uglify-es` is API/CLI compatible with `uglify-js@3`.**
|
- **`uglify-js@3` has a simplified [API](#api-reference) and [CLI](#command-line-usage) that is not backwards compatible with [`uglify-js@2`](https://github.com/mishoo/UglifyJS/tree/v2.x)**.
|
||||||
- **`uglify-es` is not backwards compatible with `uglify-js@2`.**
|
- **Documentation for UglifyJS `2.x` releases can be found [here](https://github.com/mishoo/UglifyJS/tree/v2.x)**.
|
||||||
|
- `uglify-js` only supports JavaScript (ECMAScript 5).
|
||||||
|
- To minify ECMAScript 2015 or above, transpile using tools like [Babel](https://babeljs.io/).
|
||||||
|
|
||||||
Install
|
Install
|
||||||
-------
|
-------
|
||||||
@@ -15,11 +17,11 @@ First make sure you have installed the latest version of [node.js](http://nodejs
|
|||||||
|
|
||||||
From NPM for use as a command line app:
|
From NPM for use as a command line app:
|
||||||
|
|
||||||
npm install uglify-es -g
|
npm install uglify-js -g
|
||||||
|
|
||||||
From NPM for programmatic use:
|
From NPM for programmatic use:
|
||||||
|
|
||||||
npm install uglify-es
|
npm install uglify-js
|
||||||
|
|
||||||
# Command line usage
|
# Command line usage
|
||||||
|
|
||||||
@@ -67,7 +69,7 @@ a double dash to prevent input files being used as option arguments:
|
|||||||
`debug` Add debug prefix and suffix.
|
`debug` Add debug prefix and suffix.
|
||||||
`domprops` Mangle property names that overlaps
|
`domprops` Mangle property names that overlaps
|
||||||
with DOM properties.
|
with DOM properties.
|
||||||
`keep_quoted` Only mangle unquoted properies.
|
`keep_quoted` Only mangle unquoted properties.
|
||||||
`regex` Only mangle matched property names.
|
`regex` Only mangle matched property names.
|
||||||
`reserved` List of names that should not be mangled.
|
`reserved` List of names that should not be mangled.
|
||||||
-b, --beautify [options] Beautify output/specify output options:
|
-b, --beautify [options] Beautify output/specify output options:
|
||||||
@@ -85,6 +87,7 @@ a double dash to prevent input files being used as option arguments:
|
|||||||
`wrap_iife` Wrap IIFEs in parenthesis. Note: you may
|
`wrap_iife` Wrap IIFEs in parenthesis. Note: you may
|
||||||
want to disable `negate_iife` under
|
want to disable `negate_iife` under
|
||||||
compressor options.
|
compressor options.
|
||||||
|
-O, --output-opts [options] Specify output options (`beautify` disabled by default).
|
||||||
-o, --output <file> Output file path (default STDOUT). Specify `ast` or
|
-o, --output <file> Output file path (default STDOUT). Specify `ast` or
|
||||||
`spidermonkey` to write UglifyJS or SpiderMonkey AST
|
`spidermonkey` to write UglifyJS or SpiderMonkey AST
|
||||||
as JSON to STDOUT respectively.
|
as JSON to STDOUT respectively.
|
||||||
@@ -102,20 +105,15 @@ a double dash to prevent input files being used as option arguments:
|
|||||||
sequences.
|
sequences.
|
||||||
--config-file <file> Read `minify()` options from JSON file.
|
--config-file <file> Read `minify()` options from JSON file.
|
||||||
-d, --define <expr>[=value] Global definitions.
|
-d, --define <expr>[=value] Global definitions.
|
||||||
--ecma <version> Specify ECMAScript release: 5, 6, 7 or 8.
|
-e, --enclose [arg[:value]] Embed everything in a big function, with configurable
|
||||||
|
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.
|
||||||
@@ -123,10 +121,12 @@ 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` Name and/or location of the output source.
|
`filename` Filename 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.
|
||||||
|
`names` Include symbol names in the source map.
|
||||||
`root` Path to the original source to be included in
|
`root` Path to the original source to be included in
|
||||||
the source map.
|
the source map.
|
||||||
`url` If specified, path to the source map to append in
|
`url` If specified, path to the source map to append in
|
||||||
@@ -154,10 +154,15 @@ debugging your compressed JavaScript. To get a source map, pass
|
|||||||
|
|
||||||
Additional options:
|
Additional options:
|
||||||
|
|
||||||
- `--source-map "filename='<NAME>'"` to specify the name of the source map.
|
- `--source-map "filename='<NAME>'"` to specify the name of the source map. The value of
|
||||||
|
`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.
|
||||||
|
|
||||||
|
- `--source-map "names=false"` to omit symbol names if you want to reduce size
|
||||||
|
of the source map file.
|
||||||
|
|
||||||
- `--source-map "url='<URL>'"` to specify the URL where the source map can be found.
|
- `--source-map "url='<URL>'"` to specify the URL where the source map can be found.
|
||||||
Otherwise UglifyJS assumes HTTP `X-SourceMap` is being used and will omit the
|
Otherwise UglifyJS assumes HTTP `X-SourceMap` is being used and will omit the
|
||||||
`//# sourceMappingURL=` directive.
|
`//# sourceMappingURL=` directive.
|
||||||
@@ -349,7 +354,7 @@ identify mistakes like writing mangled keys to storage.
|
|||||||
Assuming installation via NPM, you can load UglifyJS in your application
|
Assuming installation via NPM, you can load UglifyJS in your application
|
||||||
like this:
|
like this:
|
||||||
```javascript
|
```javascript
|
||||||
var UglifyJS = require("uglify-es");
|
var UglifyJS = require("uglify-js");
|
||||||
```
|
```
|
||||||
|
|
||||||
There is a single high level function, **`minify(code, options)`**,
|
There is a single high level function, **`minify(code, options)`**,
|
||||||
@@ -478,54 +483,42 @@ 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
|
|
||||||
in `result.warnings`. Use the value `"verbose"` for more detailed warnings.
|
|
||||||
|
|
||||||
- `parse` (default `{}`) — pass an object if you wish to specify some
|
|
||||||
additional [parse options](#parse-options).
|
|
||||||
|
|
||||||
- `compress` (default `{}`) — pass `false` to skip compressing entirely.
|
- `compress` (default `{}`) — pass `false` to skip compressing entirely.
|
||||||
Pass an object to specify custom [compress options](#compress-options).
|
Pass an object to specify custom [compress options](#compress-options).
|
||||||
|
|
||||||
|
- `ie8` (default `false`) -- set to `true` to support IE8.
|
||||||
|
|
||||||
|
- `keep_fnames` (default: `false`) -- pass `true` to prevent discarding or mangling
|
||||||
|
of function names. Useful for code relying on `Function.prototype.name`.
|
||||||
|
|
||||||
- `mangle` (default `true`) — pass `false` to skip mangling names, or pass
|
- `mangle` (default `true`) — pass `false` to skip mangling names, or pass
|
||||||
an object to specify [mangle options](#mangle-options) (see below).
|
an object to specify [mangle options](#mangle-options) (see below).
|
||||||
|
|
||||||
- `mangle.properties` (default `false`) — a subcategory of the mangle option.
|
- `mangle.properties` (default `false`) — a subcategory of the mangle option.
|
||||||
Pass an object to specify custom [mangle property options](#mangle-properties-options).
|
Pass an object to specify custom [mangle property options](#mangle-properties-options).
|
||||||
|
|
||||||
- `output` (default `null`) — pass an object if you wish to specify
|
- `nameCache` (default `null`) -- pass an empty object `{}` or a previously
|
||||||
additional [output options](#output-options). The defaults are optimized
|
|
||||||
for best compression.
|
|
||||||
|
|
||||||
- `sourceMap` (default `false`) - pass an object if you wish to specify
|
|
||||||
[source map options](#source-map-options).
|
|
||||||
|
|
||||||
- `toplevel` (default `false`) - set to `true` if you wish to enable top level
|
|
||||||
variable and function name mangling and to drop unused variables and functions.
|
|
||||||
|
|
||||||
- `nameCache` (default `null`) - pass an empty object `{}` or a previously
|
|
||||||
used `nameCache` object if you wish to cache mangled variable and
|
used `nameCache` object if you wish to cache mangled variable and
|
||||||
property names across multiple invocations of `minify()`. Note: this is
|
property names across multiple invocations of `minify()`. Note: this is
|
||||||
a read/write property. `minify()` will read the name cache state of this
|
a read/write property. `minify()` will read the name cache state of this
|
||||||
object and update it during minification so that it may be
|
object and update it during minification so that it may be
|
||||||
reused or externally persisted by the user.
|
reused or externally persisted by the user.
|
||||||
|
|
||||||
- `ie8` (default `false`) - set to `true` to support IE8.
|
- `output` (default `null`) — pass an object if you wish to specify
|
||||||
|
additional [output options](#output-options). The defaults are optimized
|
||||||
|
for best compression.
|
||||||
|
|
||||||
- `keep_classnames` (default: `undefined`) - pass `true` to prevent discarding or mangling
|
- `parse` (default `{}`) — pass an object if you wish to specify some
|
||||||
of class names.
|
additional [parse options](#parse-options).
|
||||||
|
|
||||||
- `keep_fnames` (default: `false`) - pass `true` to prevent discarding or mangling
|
- `sourceMap` (default `false`) -- pass an object if you wish to specify
|
||||||
of function names. Useful for code relying on `Function.prototype.name`. If the
|
[source map options](#source-map-options).
|
||||||
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
|
- `toplevel` (default `false`) -- set to `true` if you wish to enable top level
|
||||||
loop scoping and `await`. See `safari10` options in [`mangle`](#mangle-options)
|
variable and function name mangling and to drop unused variables and functions.
|
||||||
and [`output`](#output-options) for details.
|
|
||||||
|
- `warnings` (default `false`) — pass `true` to return compressor warnings
|
||||||
|
in `result.warnings`. Use the value `"verbose"` for more detailed warnings.
|
||||||
|
|
||||||
## Minify options structure
|
## Minify options structure
|
||||||
|
|
||||||
@@ -550,13 +543,9 @@ if (result.error) throw result.error;
|
|||||||
sourceMap: {
|
sourceMap: {
|
||||||
// source map options
|
// source map options
|
||||||
},
|
},
|
||||||
ecma: 5, // specify one of: 5, 6, 7 or 8
|
|
||||||
keep_classnames: false,
|
|
||||||
keep_fnames: false,
|
|
||||||
ie8: false,
|
|
||||||
nameCache: null, // or specify a name cache object
|
nameCache: null, // or specify a name cache object
|
||||||
safari10: false,
|
|
||||||
toplevel: false,
|
toplevel: false,
|
||||||
|
ie8: false,
|
||||||
warnings: false,
|
warnings: false,
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
@@ -608,46 +597,41 @@ var result = UglifyJS.minify({"compiled.js": "compiled code"}, {
|
|||||||
|
|
||||||
If you're using the `X-SourceMap` header instead, you can just omit `sourceMap.url`.
|
If you're using the `X-SourceMap` header instead, you can just omit `sourceMap.url`.
|
||||||
|
|
||||||
|
If you wish to reduce file size of the source map, set option `sourceMap.names`
|
||||||
|
to be `false` and all symbol names will be omitted.
|
||||||
|
|
||||||
## Parse options
|
## Parse options
|
||||||
|
|
||||||
- `bare_returns` (default `false`) -- support top level `return` statements
|
- `bare_returns` (default `false`) -- support top level `return` statements
|
||||||
|
|
||||||
- `ecma` (default: `8`) -- specify one of `5`, `6`, `7` or `8`. Note: this setting
|
|
||||||
is not presently enforced except for ES8 optional trailing commas in function
|
|
||||||
parameter lists and calls with `ecma` `8`.
|
|
||||||
|
|
||||||
- `html5_comments` (default `true`)
|
- `html5_comments` (default `true`)
|
||||||
|
|
||||||
- `shebang` (default `true`) -- support `#!command` as the first line
|
- `shebang` (default `true`) -- support `#!command` as the first line
|
||||||
|
|
||||||
## Compress options
|
## Compress options
|
||||||
|
|
||||||
- `arrows` (default: `true`) -- Converts `()=>{return x}` to `()=>x`. Class
|
- `arguments` (default: `true`) -- replace `arguments[index]` with function
|
||||||
and object literal methods will also be converted to arrow expressions if
|
parameter name whenever possible.
|
||||||
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.
|
- `assignments` (default: `true`) -- apply optimizations to assignment expressions.
|
||||||
|
|
||||||
- `booleans` (default: `true`) -- various optimizations for boolean context,
|
- `booleans` (default: `true`) -- various optimizations for boolean context,
|
||||||
for example `!!a ? b : c → a ? b : c`
|
for example `!!a ? b : c → a ? b : c`
|
||||||
|
|
||||||
- `cascade` (default: `true`) -- small optimization for sequences, transform
|
|
||||||
`x, x` into `x` and `x = something(), x` into `x = something()`
|
|
||||||
|
|
||||||
- `collapse_vars` (default: `true`) -- Collapse single-use non-constant variables,
|
- `collapse_vars` (default: `true`) -- Collapse single-use non-constant variables,
|
||||||
side effects permitting.
|
side effects permitting.
|
||||||
|
|
||||||
- `comparisons` (default: `true`) -- apply certain optimizations to binary nodes,
|
- `comparisons` (default: `true`) -- apply certain optimizations to binary nodes,
|
||||||
e.g. `!(a <= b) → a > b` (only when `unsafe_comps`), attempts to negate binary
|
e.g. `!(a <= b) → a > b`, attempts to negate binary nodes, e.g.
|
||||||
nodes, e.g. `a = !b && !c && !d && !e → a=!(b||c||d||e)` etc.
|
`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
|
||||||
|
|
||||||
- `dead_code` (default: `true`) -- remove unreachable code
|
- `dead_code` (default: `true`) -- remove unreachable code
|
||||||
|
|
||||||
|
- `directives` (default: `true`) -- remove redundant or non-standard directives
|
||||||
|
|
||||||
- `drop_console` (default: `false`) -- Pass `true` to discard calls to
|
- `drop_console` (default: `false`) -- Pass `true` to discard calls to
|
||||||
`console.*` functions. If you wish to drop a specific function call
|
`console.*` functions. If you wish to drop a specific function call
|
||||||
such as `console.info` and/or retain side effects from function arguments
|
such as `console.info` and/or retain side effects from function arguments
|
||||||
@@ -655,17 +639,20 @@ 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
|
- `evaluate` (default: `true`) -- Evaluate expression for shorter constant
|
||||||
will transform ES5 code into smaller ES6+ equivalent forms.
|
representation. Pass `"eager"` to always replace function calls whenever
|
||||||
|
possible, or a positive integer to specify an upper bound for each individual
|
||||||
- `evaluate` (default: `true`) -- attempt to evaluate constant expressions
|
evaluation in number of characters.
|
||||||
|
|
||||||
- `expression` (default: `false`) -- Pass `true` to preserve completion values
|
- `expression` (default: `false`) -- Pass `true` to preserve completion values
|
||||||
from terminal statements without `return`, e.g. in bookmarklets.
|
from terminal statements without `return`, e.g. in bookmarklets.
|
||||||
|
|
||||||
|
- `functions` (default: `true`) -- convert declarations from `var`to `function`
|
||||||
|
whenever possible.
|
||||||
|
|
||||||
- `global_defs` (default: `{}`) -- see [conditional compilation](#conditional-compilation)
|
- `global_defs` (default: `{}`) -- see [conditional compilation](#conditional-compilation)
|
||||||
|
|
||||||
- `hoist_funs` (default: `true`) -- hoist function declarations
|
- `hoist_funs` (default: `false`) -- hoist function declarations
|
||||||
|
|
||||||
- `hoist_props` (default: `true`) -- hoist properties from constant object and
|
- `hoist_props` (default: `true`) -- hoist properties from constant object and
|
||||||
array literals into regular variables subject to a set of constraints. For example:
|
array literals into regular variables subject to a set of constraints. For example:
|
||||||
@@ -678,20 +665,23 @@ If you're using the `X-SourceMap` header instead, you can just omit `sourceMap.u
|
|||||||
|
|
||||||
- `if_return` (default: `true`) -- optimizations for if/return and if/continue
|
- `if_return` (default: `true`) -- optimizations for if/return and if/continue
|
||||||
|
|
||||||
- `inline` (default: `true`) -- embed simple functions
|
- `inline` (default: `true`) -- inline calls to function with simple/`return` statement:
|
||||||
|
- `false` -- same as `0`
|
||||||
|
- `0` -- disabled inlining
|
||||||
|
- `1` -- inline simple functions
|
||||||
|
- `2` -- inline functions with arguments
|
||||||
|
- `3` -- inline functions with arguments and variables
|
||||||
|
- `true` -- same as `3`
|
||||||
|
|
||||||
- `join_vars` (default: `true`) -- join consecutive `var` statements
|
- `join_vars` (default: `true`) -- join consecutive `var` statements
|
||||||
|
|
||||||
- `keep_classnames` (default: `false`) -- Pass `true` to prevent the
|
- `keep_fargs` (default: `strict`) -- Discard unused function arguments. Code
|
||||||
compressor from discarding class names. See also: the `keep_classnames`
|
which relies on `Function.length` will break if this is done indiscriminately,
|
||||||
[mangle option](#mangle).
|
i.e. when passing `true`. Pass `false` to always retain function arguments.
|
||||||
|
|
||||||
- `keep_fargs` (default: `true`) -- Prevents the compressor from discarding unused
|
|
||||||
function arguments. You need this for code which relies on `Function.length`.
|
|
||||||
|
|
||||||
- `keep_fnames` (default: `false`) -- Pass `true` to prevent the
|
- `keep_fnames` (default: `false`) -- Pass `true` to prevent the
|
||||||
compressor from discarding function names. Useful for code relying on
|
compressor from discarding function names. Useful for code relying on
|
||||||
`Function.prototype.name`. See also: the `keep_fnames` [mangle option](#mangle).
|
`Function.prototype.name`. See also: the `keep_fnames` [mangle option](#mangle-options).
|
||||||
|
|
||||||
- `keep_infinity` (default: `false`) -- Pass `true` to prevent `Infinity` from
|
- `keep_infinity` (default: `false`) -- Pass `true` to prevent `Infinity` from
|
||||||
being compressed into `1/0`, which may cause performance issues on Chrome.
|
being compressed into `1/0`, which may cause performance issues on Chrome.
|
||||||
@@ -703,6 +693,8 @@ If you're using the `X-SourceMap` header instead, you can just omit `sourceMap.u
|
|||||||
where the return value is discarded, to avoid the parens that the
|
where the return value is discarded, to avoid the parens that the
|
||||||
code generator would insert.
|
code generator would insert.
|
||||||
|
|
||||||
|
- `objects` (default: `true`) -- compact duplicate keys in object literals.
|
||||||
|
|
||||||
- `passes` (default: `1`) -- The maximum number of times to run compress.
|
- `passes` (default: `1`) -- The maximum number of times to run compress.
|
||||||
In some cases more than one pass leads to further compressed code. Keep in
|
In some cases more than one pass leads to further compressed code. Keep in
|
||||||
mind more passes will take more time.
|
mind more passes will take more time.
|
||||||
@@ -719,7 +711,8 @@ 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).
|
overhead (compression will be slower). Make sure symbols under `pure_funcs`
|
||||||
|
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
|
||||||
@@ -750,6 +743,8 @@ If you're using the `X-SourceMap` header instead, you can just omit `sourceMap.u
|
|||||||
annotation `/*@__PURE__*/` or `/*#__PURE__*/` immediately precedes the call. For
|
annotation `/*@__PURE__*/` or `/*#__PURE__*/` immediately precedes the call. For
|
||||||
example: `/*@__PURE__*/foo();`
|
example: `/*@__PURE__*/foo();`
|
||||||
|
|
||||||
|
- `strings` (default: `true`) -- compact string concatenations.
|
||||||
|
|
||||||
- `switches` (default: `true`) -- de-duplicate and remove unreachable `switch` branches
|
- `switches` (default: `true`) -- de-duplicate and remove unreachable `switch` branches
|
||||||
|
|
||||||
- `toplevel` (default: `false`) -- drop unreferenced functions (`"funcs"`) and/or
|
- `toplevel` (default: `false`) -- drop unreferenced functions (`"funcs"`) and/or
|
||||||
@@ -766,52 +761,33 @@ If you're using the `X-SourceMap` header instead, you can just omit `sourceMap.u
|
|||||||
|
|
||||||
- `unsafe` (default: `false`) -- apply "unsafe" transformations (discussion below)
|
- `unsafe` (default: `false`) -- apply "unsafe" transformations (discussion below)
|
||||||
|
|
||||||
- `unsafe_arrows` (default: `false`) -- Convert ES5 style anonymous function
|
- `unsafe_comps` (default: `false`) -- compress expressions like `a <= b` assuming
|
||||||
expressions to arrow functions if the function body does not reference `this`.
|
none of the operands can be (coerced to) `NaN`.
|
||||||
Note: it is not always safe to perform this conversion if code relies on the
|
|
||||||
the function having a `prototype`, which arrow functions lack.
|
|
||||||
This transform requires that the `ecma` compress option is set to `6` or greater.
|
|
||||||
|
|
||||||
- `unsafe_comps` (default: `false`) -- Reverse `<` and `<=` to `>` and `>=` to
|
- `unsafe_Function` (default: `false`) -- compress and mangle `Function(args, code)`
|
||||||
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"`)
|
||||||
|
|
||||||
- `warnings` (default: `false`) -- display warnings when dropping unreachable
|
|
||||||
code or unused declarations etc.
|
|
||||||
|
|
||||||
## Mangle options
|
## Mangle options
|
||||||
|
|
||||||
- `eval` (default `false`) -- Pass `true` to mangle names visible in scopes
|
- `eval` (default `false`) -- Pass `true` to mangle names visible in scopes
|
||||||
where `eval` or `with` are used.
|
where `eval` or `with` are used.
|
||||||
|
|
||||||
- `keep_classnames` (default `false`) -- Pass `true` to not mangle class names.
|
|
||||||
See also: the `keep_classnames` [compress option](#compress-options).
|
|
||||||
|
|
||||||
- `keep_fnames` (default `false`) -- Pass `true` to not mangle function names.
|
- `keep_fnames` (default `false`) -- Pass `true` to not mangle function names.
|
||||||
Useful for code relying on `Function.prototype.name`. See also: the `keep_fnames`
|
Useful for code relying on `Function.prototype.name`. See also: the `keep_fnames`
|
||||||
[compress option](#compress-options).
|
[compress option](#compress-options).
|
||||||
@@ -822,11 +798,6 @@ If you're using the `X-SourceMap` header instead, you can just omit `sourceMap.u
|
|||||||
- `toplevel` (default `false`) -- Pass `true` to mangle names declared in the
|
- `toplevel` (default `false`) -- Pass `true` to mangle names declared in the
|
||||||
top level scope.
|
top level scope.
|
||||||
|
|
||||||
- `safari10` (default `false`) -- Pass `true` to work around the Safari 10 loop
|
|
||||||
iterator [bug](https://bugs.webkit.org/show_bug.cgi?id=171041)
|
|
||||||
"Cannot declare a let variable twice".
|
|
||||||
See also: the `safari10` [output option](#output-options).
|
|
||||||
|
|
||||||
Examples:
|
Examples:
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
@@ -879,27 +850,26 @@ 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.
|
||||||
|
|
||||||
- `bracketize` (default `false`) -- always insert brackets in `if`, `for`,
|
- `braces` (default `false`) -- always insert braces in `if`, `for`,
|
||||||
`do`, `while` or `with` statements, even if their body is a single
|
`do`, `while` or `with` statements, even if their body is a single
|
||||||
statement.
|
statement.
|
||||||
|
|
||||||
- `comments` (default `false`) -- pass `true` or `"all"` to preserve all
|
- `comments` (default `false`) -- pass `true` or `"all"` to preserve all
|
||||||
comments, `"some"` to preserve some comments, a regular expression string
|
comments, `"some"` to preserve multi-line comments that contain `@cc_on`,
|
||||||
(e.g. `/^!/`) or a function.
|
`@license`, or `@preserve` (case-insensitive), a regular expression string
|
||||||
|
(e.g. `/^!/`), or a function which returns `boolean`, e.g.
|
||||||
- `ecma` (default `5`) -- set output printing mode. Set `ecma` to `6` or
|
```js
|
||||||
greater to emit shorthand object properties - i.e.: `{a}` instead of `{a: a}`.
|
function(node, comment) {
|
||||||
The `ecma` option will only change the output in direct control of the
|
return comment.value.indexOf("@type " + node.TYPE) >= 0;
|
||||||
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 `false`) -- escape the slash in occurrences of
|
- `inline_script` (default `true`) -- escape HTML comments and the slash in
|
||||||
`</script` in strings
|
occurrences of `</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.
|
||||||
@@ -911,8 +881,8 @@ can pass additional arguments that control the code output:
|
|||||||
adjust for this text. Can be used to insert a comment containing
|
adjust for this text. Can be used to insert a comment containing
|
||||||
licensing information, for example.
|
licensing information, for example.
|
||||||
|
|
||||||
- `preserve_line` (default `false`) -- pass `true` to preserve lines, but it
|
- `preserve_line` (default `false`) -- pass `true` to retain line numbering on
|
||||||
only works if `beautify` is set to `false`.
|
a best effort basis.
|
||||||
|
|
||||||
- `quote_keys` (default `false`) -- pass `true` to quote all keys in literal
|
- `quote_keys` (default `false`) -- pass `true` to quote all keys in literal
|
||||||
objects
|
objects
|
||||||
@@ -925,10 +895,6 @@ can pass additional arguments that control the code output:
|
|||||||
- `2` -- always use double quotes
|
- `2` -- always use double quotes
|
||||||
- `3` -- always use the original quotes
|
- `3` -- always use the original quotes
|
||||||
|
|
||||||
- `safari10` (default `false`) -- set this option to `true` to work around
|
|
||||||
the [Safari 10/11 await bug](https://bugs.webkit.org/show_bug.cgi?id=176685).
|
|
||||||
See also: the `safari10` [mangle option](#mangle-options).
|
|
||||||
|
|
||||||
- `semicolons` (default `true`) -- separate statements with semicolons. If
|
- `semicolons` (default `true`) -- separate statements with semicolons. If
|
||||||
you pass `false` then whenever possible we will use a newline instead of a
|
you pass `false` then whenever possible we will use a newline instead of a
|
||||||
semicolon, leading to more readable output of uglified code (size before
|
semicolon, leading to more readable output of uglified code (size before
|
||||||
@@ -947,7 +913,7 @@ can pass additional arguments that control the code output:
|
|||||||
|
|
||||||
- `wrap_iife` (default `false`) -- pass `true` to wrap immediately invoked
|
- `wrap_iife` (default `false`) -- pass `true` to wrap immediately invoked
|
||||||
function expressions. See
|
function expressions. See
|
||||||
[#640](https://github.com/mishoo/UglifyJS2/issues/640) for more details.
|
[#640](https://github.com/mishoo/UglifyJS/issues/640) for more details.
|
||||||
|
|
||||||
# Miscellaneous
|
# Miscellaneous
|
||||||
|
|
||||||
@@ -990,9 +956,6 @@ when this flag is on:
|
|||||||
- `new Object()` → `{}`
|
- `new Object()` → `{}`
|
||||||
- `String(exp)` or `exp.toString()` → `"" + exp`
|
- `String(exp)` or `exp.toString()` → `"" + exp`
|
||||||
- `new Object/RegExp/Function/Error/Array (...)` → we discard the `new`
|
- `new Object/RegExp/Function/Error/Array (...)` → we discard the `new`
|
||||||
- `void 0` → `undefined` (if there is a variable named "undefined" in
|
|
||||||
scope; we do it because the variable name will be mangled, typically
|
|
||||||
reduced to a single character)
|
|
||||||
|
|
||||||
### Conditional compilation
|
### Conditional compilation
|
||||||
|
|
||||||
@@ -1109,8 +1072,9 @@ 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`](http://lisperator.net/uglifyjs/walk) and
|
[`TreeWalker`](https://github.com/mishoo/UglifyJS/blob/master/lib/ast.js) and
|
||||||
[`TreeTransformer`](http://lisperator.net/uglifyjs/transform) respectively.
|
[`TreeTransformer`](https://github.com/mishoo/UglifyJS/blob/master/lib/transform.js)
|
||||||
|
respectively.
|
||||||
|
|
||||||
### ESTree / SpiderMonkey AST
|
### ESTree / SpiderMonkey AST
|
||||||
|
|
||||||
@@ -1169,3 +1133,27 @@ To enable fast minify mode with the API use:
|
|||||||
```js
|
```js
|
||||||
UglifyJS.minify(code, { compress: false, mangle: true });
|
UglifyJS.minify(code, { compress: false, mangle: true });
|
||||||
```
|
```
|
||||||
|
|
||||||
|
#### Source maps and debugging
|
||||||
|
|
||||||
|
Various `compress` transforms that simplify, rearrange, inline and remove code
|
||||||
|
are known to have an adverse effect on debugging with source maps. This is
|
||||||
|
expected as code is optimized and mappings are often simply not possible as
|
||||||
|
some code no longer exists. For highest fidelity in source map debugging
|
||||||
|
disable the Uglify `compress` option and just use `mangle`.
|
||||||
|
|
||||||
|
### Compiler assumptions
|
||||||
|
|
||||||
|
To allow for better optimizations, the compiler makes various assumptions:
|
||||||
|
|
||||||
|
- `.toString()` and `.valueOf()` don't have side effects, and for built-in
|
||||||
|
objects they have not been overridden.
|
||||||
|
- `undefined`, `NaN` and `Infinity` have not been externally redefined.
|
||||||
|
- `arguments.callee`, `arguments.caller` and `Function.prototype.caller` are not used.
|
||||||
|
- The code doesn't expect the contents of `Function.prototype.toString()` or
|
||||||
|
`Error.prototype.stack` to be anything in particular.
|
||||||
|
- Getting and setting properties on a plain object does not cause other side effects
|
||||||
|
(using `.watch()` or `Proxy`).
|
||||||
|
- Object properties can be added, removed and modified (not prevented with
|
||||||
|
`Object.defineProperty()`, `Object.defineProperties()`, `Object.freeze()`,
|
||||||
|
`Object.preventExtensions()` or `Object.seal()`).
|
||||||
|
|||||||
23
appveyor.yml
23
appveyor.yml
@@ -1,24 +1,5 @@
|
|||||||
environment:
|
build: off
|
||||||
matrix:
|
|
||||||
- nodejs_version: "0.10"
|
|
||||||
- nodejs_version: "0.12"
|
|
||||||
- nodejs_version: "4.0"
|
|
||||||
- nodejs_version: "6.0"
|
|
||||||
|
|
||||||
matrix:
|
matrix:
|
||||||
fast_finish: true
|
fast_finish: true
|
||||||
|
|
||||||
platform:
|
|
||||||
- x86
|
|
||||||
- x64
|
|
||||||
|
|
||||||
install:
|
|
||||||
- ps: Install-Product node $env:nodejs_version $env:platform
|
|
||||||
- npm install
|
|
||||||
|
|
||||||
test_script:
|
test_script:
|
||||||
- node --version
|
- echo No longer in use
|
||||||
- npm --version
|
|
||||||
- npm test
|
|
||||||
|
|
||||||
build: off
|
|
||||||
|
|||||||
208
bin/uglifyjs
208
bin/uglifyjs
@@ -3,11 +3,7 @@
|
|||||||
|
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
// workaround for tty output truncation upon process.exit()
|
require("../tools/exit");
|
||||||
[process.stdout, process.stderr].forEach(function(stream){
|
|
||||||
if (stream._handle && stream._handle.setBlocking)
|
|
||||||
stream._handle.setBlocking(true);
|
|
||||||
});
|
|
||||||
|
|
||||||
var fs = require("fs");
|
var fs = require("fs");
|
||||||
var info = require("../package.json");
|
var info = require("../package.json");
|
||||||
@@ -15,7 +11,7 @@ var path = require("path");
|
|||||||
var program = require("commander");
|
var program = require("commander");
|
||||||
var UglifyJS = require("../tools/node");
|
var UglifyJS = require("../tools/node");
|
||||||
|
|
||||||
var skip_keys = [ "cname", "enclosed", "inlined", "parent_scope", "scope", "thedef", "uses_eval", "uses_with" ];
|
var skip_keys = [ "cname", "inlined", "parent_scope", "scope", "uses_eval", "uses_with" ];
|
||||||
var files = {};
|
var files = {};
|
||||||
var options = {
|
var options = {
|
||||||
compress: false,
|
compress: false,
|
||||||
@@ -27,12 +23,29 @@ program.parse = undefined;
|
|||||||
if (process.argv.indexOf("ast") >= 0) program.helpInformation = UglifyJS.describe_ast;
|
if (process.argv.indexOf("ast") >= 0) program.helpInformation = UglifyJS.describe_ast;
|
||||||
else if (process.argv.indexOf("options") >= 0) program.helpInformation = function() {
|
else if (process.argv.indexOf("options") >= 0) program.helpInformation = function() {
|
||||||
var text = [];
|
var text = [];
|
||||||
|
var toplevels = [];
|
||||||
|
var padding = "";
|
||||||
var options = UglifyJS.default_options();
|
var options = UglifyJS.default_options();
|
||||||
for (var option in options) {
|
for (var name in options) {
|
||||||
text.push("--" + (option == "output" ? "beautify" : option == "sourceMap" ? "source-map" : option) + " options:");
|
var option = options[name];
|
||||||
text.push(format_object(options[option]));
|
if (option && typeof option == "object") {
|
||||||
text.push("");
|
text.push("--" + ({
|
||||||
|
output: "beautify",
|
||||||
|
sourceMap: "source-map",
|
||||||
|
}[name] || name) + " options:");
|
||||||
|
text.push(format_object(option));
|
||||||
|
text.push("");
|
||||||
|
} else {
|
||||||
|
if (padding.length < name.length) padding = Array(name.length + 1).join(" ");
|
||||||
|
toplevels.push([ {
|
||||||
|
keep_fnames: "keep-fnames",
|
||||||
|
nameCache: "name-cache",
|
||||||
|
}[name] || name, option ]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
toplevels.forEach(function(tokens) {
|
||||||
|
text.push("--" + tokens[0] + padding.slice(tokens[0].length - 2) + tokens[1]);
|
||||||
|
});
|
||||||
return text.join("\n");
|
return text.join("\n");
|
||||||
};
|
};
|
||||||
program.option("-p, --parse <options>", "Specify parser options.", parse_js());
|
program.option("-p, --parse <options>", "Specify parser options.", parse_js());
|
||||||
@@ -40,49 +53,60 @@ program.option("-c, --compress [options]", "Enable compressor/specify compressor
|
|||||||
program.option("-m, --mangle [options]", "Mangle names/specify mangler options.", parse_js());
|
program.option("-m, --mangle [options]", "Mangle names/specify mangler options.", parse_js());
|
||||||
program.option("--mangle-props [options]", "Mangle properties/specify mangler options.", parse_js());
|
program.option("--mangle-props [options]", "Mangle properties/specify mangler options.", parse_js());
|
||||||
program.option("-b, --beautify [options]", "Beautify output/specify output options.", parse_js());
|
program.option("-b, --beautify [options]", "Beautify output/specify output options.", parse_js());
|
||||||
|
program.option("-O, --output-opts [options]", "Output options (beautify disabled).", parse_js());
|
||||||
program.option("-o, --output <file>", "Output file (default STDOUT).");
|
program.option("-o, --output <file>", "Output file (default STDOUT).");
|
||||||
program.option("--comments [filter]", "Preserve copyright comments in the output.");
|
program.option("--comments [filter]", "Preserve copyright comments in the output.");
|
||||||
program.option("--config-file <file>", "Read minify() options from JSON file.");
|
program.option("--config-file <file>", "Read minify() options from JSON file.");
|
||||||
program.option("-d, --define <expr>[=value]", "Global definitions.", parse_js("define"));
|
program.option("-d, --define <expr>[=value]", "Global definitions.", parse_js("define"));
|
||||||
program.option("--ecma <version>", "Specify ECMAScript release: 5, 6, 7 or 8.");
|
program.option("-e, --enclose [arg[,...][:value[,...]]]", "Embed everything in a big function, with configurable argument(s) & value(s).");
|
||||||
program.option("--ie8", "Support non-standard Internet Explorer 8.");
|
program.option("--ie8", "Support non-standard Internet Explorer 8.");
|
||||||
program.option("--keep-classnames", "Do not mangle/drop class names.");
|
|
||||||
program.option("--keep-fnames", "Do not mangle/drop function names. Useful for code relying on Function.prototype.name.");
|
program.option("--keep-fnames", "Do not mangle/drop function names. Useful for code relying on Function.prototype.name.");
|
||||||
program.option("--name-cache <file>", "File to hold mangled name mappings.");
|
program.option("--name-cache <file>", "File to hold mangled name mappings.");
|
||||||
|
program.option("--rename", "Force symbol expansion.");
|
||||||
program.option("--no-rename", "Disable symbol expansion.");
|
program.option("--no-rename", "Disable symbol expansion.");
|
||||||
program.option("--safari10", "Support non-standard Safari 10.");
|
|
||||||
program.option("--self", "Build UglifyJS as a library (implies --wrap UglifyJS)");
|
program.option("--self", "Build UglifyJS as a library (implies --wrap UglifyJS)");
|
||||||
program.option("--source-map [options]", "Enable source map/specify source map options.", parse_source_map());
|
program.option("--source-map [options]", "Enable source map/specify source map options.", parse_js());
|
||||||
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("--validate", "Perform validation during AST manipulations.");
|
||||||
program.option("--verbose", "Print diagnostic messages.");
|
program.option("--verbose", "Print diagnostic messages.");
|
||||||
program.option("--warn", "Print warning messages.");
|
program.option("--warn", "Print warning messages.");
|
||||||
program.option("--wrap <name>", "Embed everything as a function with “exports” corresponding to “name” globally.");
|
program.option("--wrap <name>", "Embed everything as a function with “exports” corresponding to “name” globally.");
|
||||||
|
program.option("--reduce-test", "Reduce a standalone `console.log` based test case.");
|
||||||
program.arguments("[files...]").parseArgv(process.argv);
|
program.arguments("[files...]").parseArgv(process.argv);
|
||||||
if (program.configFile) {
|
if (program.configFile) {
|
||||||
options = JSON.parse(read_file(program.configFile));
|
options = JSON.parse(read_file(program.configFile));
|
||||||
|
if (options.mangle && options.mangle.properties && options.mangle.properties.regex) {
|
||||||
|
options.mangle.properties.regex = UglifyJS.parse(options.mangle.properties.regex, {
|
||||||
|
expression: true
|
||||||
|
}).value;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (!program.output && program.sourceMap && program.sourceMap.url != "inline") {
|
if (!program.output && program.sourceMap && program.sourceMap.url != "inline") {
|
||||||
fatal("ERROR: cannot write source map to STDOUT");
|
fatal("cannot write source map to STDOUT");
|
||||||
}
|
}
|
||||||
[
|
[
|
||||||
"compress",
|
"compress",
|
||||||
|
"enclose",
|
||||||
"ie8",
|
"ie8",
|
||||||
"mangle",
|
"mangle",
|
||||||
"rename",
|
|
||||||
"safari10",
|
|
||||||
"sourceMap",
|
"sourceMap",
|
||||||
"toplevel",
|
"toplevel",
|
||||||
|
"validate",
|
||||||
"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.verbose) {
|
||||||
if (program.ecma != (program.ecma | 0)) fatal("ERROR: ecma must be an integer");
|
options.warnings = "verbose";
|
||||||
options.ecma = program.ecma | 0;
|
} else if (program.warn) {
|
||||||
|
options.warnings = true;
|
||||||
|
}
|
||||||
|
if (options.warnings) {
|
||||||
|
UglifyJS.AST_Node.log_function(print_error, options.warnings == "verbose");
|
||||||
|
delete options.warnings;
|
||||||
}
|
}
|
||||||
if (program.beautify) {
|
if (program.beautify) {
|
||||||
options.output = typeof program.beautify == "object" ? program.beautify : {};
|
options.output = typeof program.beautify == "object" ? program.beautify : {};
|
||||||
@@ -90,6 +114,10 @@ if (program.beautify) {
|
|||||||
options.output.beautify = true;
|
options.output.beautify = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (program.outputOpts) {
|
||||||
|
if (program.beautify) fatal("--beautify cannot be used with --output-opts");
|
||||||
|
options.output = typeof program.outputOpts == "object" ? program.outputOpts : {};
|
||||||
|
}
|
||||||
if (program.comments) {
|
if (program.comments) {
|
||||||
if (typeof options.output != "object") options.output = {};
|
if (typeof options.output != "object") options.output = {};
|
||||||
options.output.comments = typeof program.comments == "string" ? program.comments : "some";
|
options.output.comments = typeof program.comments == "string" ? program.comments : "some";
|
||||||
@@ -101,9 +129,6 @@ if (program.define) {
|
|||||||
options.compress.global_defs[expr] = program.define[expr];
|
options.compress.global_defs[expr] = program.define[expr];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (program.keepClassnames) {
|
|
||||||
options.keep_classnames = true;
|
|
||||||
}
|
|
||||||
if (program.keepFnames) {
|
if (program.keepFnames) {
|
||||||
options.keep_fnames = true;
|
options.keep_fnames = true;
|
||||||
}
|
}
|
||||||
@@ -114,7 +139,7 @@ if (program.mangleProps) {
|
|||||||
if (typeof program.mangleProps != "object") program.mangleProps = {};
|
if (typeof program.mangleProps != "object") program.mangleProps = {};
|
||||||
if (!Array.isArray(program.mangleProps.reserved)) program.mangleProps.reserved = [];
|
if (!Array.isArray(program.mangleProps.reserved)) program.mangleProps.reserved = [];
|
||||||
require("../tools/domprops").forEach(function(name) {
|
require("../tools/domprops").forEach(function(name) {
|
||||||
UglifyJS._push_uniq(program.mangleProps.reserved, name);
|
UglifyJS.push_uniq(program.mangleProps.reserved, name);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
if (typeof options.mangle != "object") options.mangle = {};
|
if (typeof options.mangle != "object") options.mangle = {};
|
||||||
@@ -133,9 +158,14 @@ if (program.parse) {
|
|||||||
if (!program.parse.acorn && !program.parse.spidermonkey) {
|
if (!program.parse.acorn && !program.parse.spidermonkey) {
|
||||||
options.parse = program.parse;
|
options.parse = program.parse;
|
||||||
} else if (program.sourceMap && program.sourceMap.content == "inline") {
|
} else if (program.sourceMap && program.sourceMap.content == "inline") {
|
||||||
fatal("ERROR: inline source map only works with built-in parser");
|
fatal("inline source map only works with built-in parser");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (~program.rawArgs.indexOf("--rename")) {
|
||||||
|
options.rename = true;
|
||||||
|
} else if (!program.rename) {
|
||||||
|
options.rename = false;
|
||||||
|
}
|
||||||
var convert_path = function(name) {
|
var convert_path = function(name) {
|
||||||
return name;
|
return name;
|
||||||
};
|
};
|
||||||
@@ -148,15 +178,8 @@ if (typeof program.sourceMap == "object" && "base" in program.sourceMap) {
|
|||||||
};
|
};
|
||||||
}();
|
}();
|
||||||
}
|
}
|
||||||
if (program.verbose) {
|
|
||||||
options.warnings = "verbose";
|
|
||||||
} else if (program.warn) {
|
|
||||||
options.warnings = true;
|
|
||||||
}
|
|
||||||
if (program.self) {
|
if (program.self) {
|
||||||
if (program.args.length) {
|
if (program.args.length) UglifyJS.AST_Node.warn("Ignoring input files since --self was passed");
|
||||||
print_error("WARN: Ignoring input files since --self was passed");
|
|
||||||
}
|
|
||||||
if (!options.wrap) options.wrap = "UglifyJS";
|
if (!options.wrap) options.wrap = "UglifyJS";
|
||||||
simple_glob(UglifyJS.FILES).forEach(function(name) {
|
simple_glob(UglifyJS.FILES).forEach(function(name) {
|
||||||
files[convert_path(name)] = read_file(name);
|
files[convert_path(name)] = read_file(name);
|
||||||
@@ -184,9 +207,11 @@ function convert_ast(fn) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function run() {
|
function run() {
|
||||||
UglifyJS.AST_Node.warn_function = function(msg) {
|
var content = program.sourceMap && program.sourceMap.content;
|
||||||
print_error("WARN: " + msg);
|
if (content && content != "inline") {
|
||||||
};
|
UglifyJS.AST_Node.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) {
|
||||||
@@ -210,35 +235,61 @@ function run() {
|
|||||||
} catch (ex) {
|
} catch (ex) {
|
||||||
fatal(ex);
|
fatal(ex);
|
||||||
}
|
}
|
||||||
var result = UglifyJS.minify(files, options);
|
if (program.reduceTest) {
|
||||||
|
// load on demand - assumes dev tree checked out
|
||||||
|
var reduce_test = require("../test/reduce");
|
||||||
|
var testcase = files[0] || files[Object.keys(files)[0]];
|
||||||
|
var result = reduce_test(testcase, options, {
|
||||||
|
log: print_error,
|
||||||
|
verbose: true,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
var result = UglifyJS.minify(files, options);
|
||||||
|
}
|
||||||
if (result.error) {
|
if (result.error) {
|
||||||
var ex = result.error;
|
var ex = result.error;
|
||||||
if (ex.name == "SyntaxError") {
|
if (ex.name == "SyntaxError") {
|
||||||
print_error("Parse error at " + ex.filename + ":" + ex.line + "," + ex.col);
|
print_error("Parse error at " + ex.filename + ":" + ex.line + "," + ex.col);
|
||||||
var col = ex.col;
|
var file = files[ex.filename];
|
||||||
var lines = files[ex.filename].split(/\r?\n/);
|
if (file) {
|
||||||
var line = lines[ex.line - 1];
|
var col = ex.col;
|
||||||
if (!line && !col) {
|
var lines = file.split(/\r?\n/);
|
||||||
line = lines[ex.line - 2];
|
var line = lines[ex.line - 1];
|
||||||
col = line.length;
|
if (!line && !col) {
|
||||||
}
|
line = lines[ex.line - 2];
|
||||||
if (line) {
|
col = line.length;
|
||||||
var limit = 70;
|
}
|
||||||
if (col > limit) {
|
if (line) {
|
||||||
line = line.slice(col - limit);
|
var limit = 70;
|
||||||
col = limit;
|
if (col > limit) {
|
||||||
|
line = line.slice(col - limit);
|
||||||
|
col = limit;
|
||||||
|
}
|
||||||
|
print_error(line.slice(0, 80));
|
||||||
|
print_error(line.slice(0, col).replace(/\S/g, " ") + "^");
|
||||||
}
|
}
|
||||||
print_error(line.slice(0, 80));
|
|
||||||
print_error(line.slice(0, col).replace(/\S/g, " ") + "^");
|
|
||||||
}
|
}
|
||||||
}
|
} else if (ex.defs) {
|
||||||
if (ex.defs) {
|
|
||||||
print_error("Supported options:");
|
print_error("Supported options:");
|
||||||
print_error(format_object(ex.defs));
|
print_error(format_object(ex.defs));
|
||||||
}
|
}
|
||||||
fatal(ex);
|
fatal(ex);
|
||||||
} else if (program.output == "ast") {
|
} else if (program.output == "ast") {
|
||||||
|
if (!options.compress && !options.mangle) {
|
||||||
|
result.ast.figure_out_scope({});
|
||||||
|
}
|
||||||
print(JSON.stringify(result.ast, function(key, value) {
|
print(JSON.stringify(result.ast, function(key, value) {
|
||||||
|
if (value) switch (key) {
|
||||||
|
case "thedef":
|
||||||
|
return symdef(value);
|
||||||
|
case "enclosed":
|
||||||
|
return value.length ? value.map(symdef) : undefined;
|
||||||
|
case "variables":
|
||||||
|
case "functions":
|
||||||
|
case "globals":
|
||||||
|
return value.size() ? value.map(symdef) : undefined;
|
||||||
|
}
|
||||||
if (skip_key(key)) return;
|
if (skip_key(key)) return;
|
||||||
if (value instanceof UglifyJS.AST_Token) return;
|
if (value instanceof UglifyJS.AST_Token) return;
|
||||||
if (value instanceof UglifyJS.Dictionary) return;
|
if (value instanceof UglifyJS.Dictionary) return;
|
||||||
@@ -279,7 +330,11 @@ function run() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function fatal(message) {
|
function fatal(message) {
|
||||||
if (message instanceof Error) message = message.stack.replace(/^\S*?Error:/, "ERROR:")
|
if (message instanceof Error) {
|
||||||
|
message = message.stack.replace(/^\S*?Error:/, "ERROR:")
|
||||||
|
} else {
|
||||||
|
message = "ERROR: " + message;
|
||||||
|
}
|
||||||
print_error(message);
|
print_error(message);
|
||||||
process.exit(1);
|
process.exit(1);
|
||||||
}
|
}
|
||||||
@@ -304,7 +359,7 @@ function simple_glob(glob) {
|
|||||||
.replace(/\?/g, "[^/\\\\]") + "$";
|
.replace(/\?/g, "[^/\\\\]") + "$";
|
||||||
var mod = process.platform === "win32" ? "i" : "";
|
var mod = process.platform === "win32" ? "i" : "";
|
||||||
var rx = new RegExp(pattern, mod);
|
var rx = new RegExp(pattern, mod);
|
||||||
var results = entries.filter(function(name) {
|
var results = entries.sort().filter(function(name) {
|
||||||
return rx.test(name);
|
return rx.test(name);
|
||||||
}).map(function(name) {
|
}).map(function(name) {
|
||||||
return path.join(dir, name);
|
return path.join(dir, name);
|
||||||
@@ -328,17 +383,9 @@ function parse_js(flag) {
|
|||||||
return function(value, options) {
|
return function(value, options) {
|
||||||
options = options || {};
|
options = options || {};
|
||||||
try {
|
try {
|
||||||
UglifyJS.minify(value, {
|
UglifyJS.parse(value, {
|
||||||
parse: {
|
expression: true
|
||||||
expression: true
|
}).walk(new UglifyJS.TreeWalker(function(node) {
|
||||||
},
|
|
||||||
compress: false,
|
|
||||||
mangle: false,
|
|
||||||
output: {
|
|
||||||
ast: true,
|
|
||||||
code: false
|
|
||||||
}
|
|
||||||
}).ast.walk(new UglifyJS.TreeWalker(function(node) {
|
|
||||||
if (node instanceof UglifyJS.AST_Assign) {
|
if (node instanceof UglifyJS.AST_Assign) {
|
||||||
var name = node.left.print_to_string();
|
var name = node.left.print_to_string();
|
||||||
var value = node.right;
|
var value = node.right;
|
||||||
@@ -359,14 +406,14 @@ function parse_js(flag) {
|
|||||||
if (!(node instanceof UglifyJS.AST_Sequence)) throw node;
|
if (!(node instanceof UglifyJS.AST_Sequence)) throw node;
|
||||||
|
|
||||||
function to_string(value) {
|
function to_string(value) {
|
||||||
return value instanceof UglifyJS.AST_Constant ? value.getValue() : value.print_to_string({
|
return value instanceof UglifyJS.AST_Constant ? value.value : value.print_to_string({
|
||||||
quote_keys: true
|
quote_keys: true
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}));
|
}));
|
||||||
} catch(ex) {
|
} catch (ex) {
|
||||||
if (flag) {
|
if (flag) {
|
||||||
fatal("Error parsing arguments for '" + flag + "': " + value);
|
fatal("cannot parse arguments for '" + flag + "': " + value);
|
||||||
} else {
|
} else {
|
||||||
options[value] = null;
|
options[value] = null;
|
||||||
}
|
}
|
||||||
@@ -375,23 +422,16 @@ 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;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function symdef(def) {
|
||||||
|
var ret = (1e6 + def.id) + " " + def.name;
|
||||||
|
if (def.mangled_name) ret += " " + def.mangled_name;
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
function format_object(obj) {
|
function format_object(obj) {
|
||||||
var lines = [];
|
var lines = [];
|
||||||
var padding = "";
|
var padding = "";
|
||||||
|
|||||||
1120
lib/ast.js
1120
lib/ast.js
File diff suppressed because it is too large
Load Diff
8683
lib/compress.js
8683
lib/compress.js
File diff suppressed because it is too large
Load Diff
136
lib/minify.js
136
lib/minify.js
@@ -1,19 +1,47 @@
|
|||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
var to_ascii = typeof atob == "undefined" ? function(b64) {
|
var to_ascii, to_base64;
|
||||||
return new Buffer(b64, "base64").toString();
|
if (typeof Buffer == "undefined") {
|
||||||
} : atob;
|
to_ascii = atob;
|
||||||
var to_base64 = typeof btoa == "undefined" ? function(str) {
|
to_base64 = btoa;
|
||||||
return new Buffer(str).toString("base64");
|
} else if (typeof Buffer.alloc == "undefined") {
|
||||||
} : btoa;
|
to_ascii = function(b64) {
|
||||||
|
return new Buffer(b64, "base64").toString();
|
||||||
|
};
|
||||||
|
to_base64 = function(str) {
|
||||||
|
return new Buffer(str).toString("base64");
|
||||||
|
};
|
||||||
|
} else {
|
||||||
|
to_ascii = function(b64) {
|
||||||
|
return Buffer.from(b64, "base64").toString();
|
||||||
|
};
|
||||||
|
to_base64 = function(str) {
|
||||||
|
return Buffer.from(str).toString("base64");
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
function read_source_map(code) {
|
function read_source_map(name, toplevel) {
|
||||||
var match = /\n\/\/# sourceMappingURL=data:application\/json(;.*?)?;base64,(.*)/.exec(code);
|
var comments = toplevel.end.comments_after;
|
||||||
if (!match) {
|
for (var i = comments.length; --i >= 0;) {
|
||||||
AST_Node.warn("inline source map not found");
|
var comment = comments[i];
|
||||||
return null;
|
if (comment.type != "comment1") break;
|
||||||
|
var match = /^# ([^\s=]+)=(\S+)\s*$/.exec(comment.value);
|
||||||
|
if (!match) break;
|
||||||
|
if (match[1] == "sourceMappingURL") {
|
||||||
|
match = /^data:application\/json(;.*?)?;base64,(\S+)$/.exec(match[2]);
|
||||||
|
if (!match) break;
|
||||||
|
return to_ascii(match[2]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
AST_Node.warn("inline source map not found: " + name);
|
||||||
|
}
|
||||||
|
|
||||||
|
function parse_source_map(content) {
|
||||||
|
try {
|
||||||
|
return JSON.parse(content);
|
||||||
|
} catch (ex) {
|
||||||
|
throw new Error("invalid input source map: " + content);
|
||||||
}
|
}
|
||||||
return to_ascii(match[2]);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function set_shorthand(name, options, keys) {
|
function set_shorthand(name, options, keys) {
|
||||||
@@ -29,7 +57,6 @@ function set_shorthand(name, options, keys) {
|
|||||||
|
|
||||||
function init_cache(cache) {
|
function init_cache(cache) {
|
||||||
if (!cache) return;
|
if (!cache) return;
|
||||||
if (!("cname" in cache)) cache.cname = -1;
|
|
||||||
if (!("props" in cache)) {
|
if (!("props" in cache)) {
|
||||||
cache.props = new Dictionary();
|
cache.props = new Dictionary();
|
||||||
} else if (!(cache.props instanceof Dictionary)) {
|
} else if (!(cache.props instanceof Dictionary)) {
|
||||||
@@ -39,59 +66,48 @@ function init_cache(cache) {
|
|||||||
|
|
||||||
function to_json(cache) {
|
function to_json(cache) {
|
||||||
return {
|
return {
|
||||||
cname: cache.cname,
|
|
||||||
props: cache.props.toObject()
|
props: cache.props.toObject()
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
function minify(files, options) {
|
function minify(files, options) {
|
||||||
var warn_function = AST_Node.warn_function;
|
|
||||||
try {
|
try {
|
||||||
options = defaults(options, {
|
options = defaults(options, {
|
||||||
compress: {},
|
compress: {},
|
||||||
ecma: undefined,
|
enclose: false,
|
||||||
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,
|
||||||
|
validate: false,
|
||||||
warnings: false,
|
warnings: false,
|
||||||
wrap: false,
|
wrap: false,
|
||||||
}, true);
|
}, true);
|
||||||
|
if (options.validate) AST_Node.enable_validation();
|
||||||
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" ]);
|
|
||||||
var quoted_props;
|
var quoted_props;
|
||||||
if (options.mangle) {
|
if (options.mangle) {
|
||||||
options.mangle = defaults(options.mangle, {
|
options.mangle = defaults(options.mangle, {
|
||||||
cache: options.nameCache && (options.nameCache.vars || {}),
|
cache: options.nameCache && (options.nameCache.vars || {}),
|
||||||
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) {
|
||||||
@@ -115,16 +131,15 @@ function minify(files, options) {
|
|||||||
content: null,
|
content: null,
|
||||||
filename: null,
|
filename: null,
|
||||||
includeSources: false,
|
includeSources: false,
|
||||||
|
names: true,
|
||||||
root: null,
|
root: null,
|
||||||
url: null,
|
url: null,
|
||||||
}, true);
|
}, true);
|
||||||
}
|
}
|
||||||
var warnings = [];
|
var warnings = [];
|
||||||
if (options.warnings && !AST_Node.warn_function) {
|
if (options.warnings) AST_Node.log_function(function(warning) {
|
||||||
AST_Node.warn_function = function(warning) {
|
warnings.push(warning);
|
||||||
warnings.push(warning);
|
}, options.warnings == "verbose");
|
||||||
};
|
|
||||||
}
|
|
||||||
if (timings) timings.parse = Date.now();
|
if (timings) timings.parse = Date.now();
|
||||||
var toplevel;
|
var toplevel;
|
||||||
if (files instanceof AST_Toplevel) {
|
if (files instanceof AST_Toplevel) {
|
||||||
@@ -135,23 +150,34 @@ 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);
|
||||||
|
}
|
||||||
|
if (source_map_content) options.sourceMap.orig = Object.create(null);
|
||||||
for (var name in files) if (HOP(files, name)) {
|
for (var name in files) if (HOP(files, name)) {
|
||||||
options.parse.filename = name;
|
options.parse.filename = name;
|
||||||
options.parse.toplevel = parse(files[name], options.parse);
|
options.parse.toplevel = toplevel = parse(files[name], options.parse);
|
||||||
if (options.sourceMap && options.sourceMap.content == "inline") {
|
if (source_map_content == "inline") {
|
||||||
if (Object.keys(files).length > 1)
|
var inlined_content = read_source_map(name, toplevel);
|
||||||
throw new Error("inline source map only works with singular input");
|
if (inlined_content) {
|
||||||
options.sourceMap.content = read_source_map(files[name]);
|
options.sourceMap.orig[name] = parse_source_map(inlined_content);
|
||||||
|
}
|
||||||
|
} else if (source_map_content) {
|
||||||
|
options.sourceMap.orig[name] = source_map_content;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
toplevel = options.parse.toplevel;
|
|
||||||
}
|
}
|
||||||
if (quoted_props) {
|
if (quoted_props) {
|
||||||
reserve_quoted_keys(toplevel, quoted_props);
|
reserve_quoted_keys(toplevel, quoted_props);
|
||||||
}
|
}
|
||||||
if (options.wrap) {
|
[ "enclose", "wrap" ].forEach(function(action) {
|
||||||
toplevel = toplevel.wrap_commonjs(options.wrap);
|
var option = options[action];
|
||||||
}
|
if (!option) return;
|
||||||
|
var orig = toplevel.print_to_string().slice(0, -1);
|
||||||
|
toplevel = toplevel[action](option);
|
||||||
|
files[toplevel.start.file] = toplevel.print_to_string().replace(orig, "");
|
||||||
|
});
|
||||||
if (timings) timings.rename = Date.now();
|
if (timings) timings.rename = Date.now();
|
||||||
if (options.rename) {
|
if (options.rename) {
|
||||||
toplevel.figure_out_scope(options.mangle);
|
toplevel.figure_out_scope(options.mangle);
|
||||||
@@ -163,7 +189,6 @@ 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);
|
||||||
}
|
}
|
||||||
@@ -178,19 +203,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.output.source_map = SourceMap(options.sourceMap);
|
||||||
options.sourceMap.content = JSON.parse(options.sourceMap.content);
|
|
||||||
}
|
|
||||||
options.output.source_map = SourceMap({
|
|
||||||
file: options.sourceMap.filename,
|
|
||||||
orig: options.sourceMap.content,
|
|
||||||
root: options.sourceMap.root
|
|
||||||
});
|
|
||||||
if (options.sourceMap.includeSources) {
|
if (options.sourceMap.includeSources) {
|
||||||
if (files instanceof AST_Toplevel) {
|
if (files instanceof AST_Toplevel) {
|
||||||
throw new Error("original source content unavailable");
|
throw new Error("original source content unavailable");
|
||||||
} 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.setSourceContent(name, files[name]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -201,10 +219,14 @@ function minify(files, options) {
|
|||||||
result.code = stream.get();
|
result.code = stream.get();
|
||||||
if (options.sourceMap) {
|
if (options.sourceMap) {
|
||||||
result.map = options.output.source_map.toString();
|
result.map = options.output.source_map.toString();
|
||||||
if (options.sourceMap.url == "inline") {
|
var url = options.sourceMap.url;
|
||||||
result.code += "\n//# sourceMappingURL=data:application/json;charset=utf-8;base64," + to_base64(result.map);
|
if (url) {
|
||||||
} else if (options.sourceMap.url) {
|
result.code = result.code.replace(/\n\/\/# sourceMappingURL=\S+\s*$/, "");
|
||||||
result.code += "\n//# sourceMappingURL=" + options.sourceMap.url;
|
if (url == "inline") {
|
||||||
|
result.code += "\n//# sourceMappingURL=data:application/json;charset=utf-8;base64," + to_base64(result.map);
|
||||||
|
} else {
|
||||||
|
result.code += "\n//# sourceMappingURL=" + url;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -225,7 +247,7 @@ function minify(files, options) {
|
|||||||
properties: 1e-3 * (timings.output - timings.properties),
|
properties: 1e-3 * (timings.output - timings.properties),
|
||||||
output: 1e-3 * (timings.end - timings.output),
|
output: 1e-3 * (timings.end - timings.output),
|
||||||
total: 1e-3 * (timings.end - timings.start)
|
total: 1e-3 * (timings.end - timings.start)
|
||||||
}
|
};
|
||||||
}
|
}
|
||||||
if (warnings.length) {
|
if (warnings.length) {
|
||||||
result.warnings = warnings;
|
result.warnings = warnings;
|
||||||
@@ -234,6 +256,6 @@ function minify(files, options) {
|
|||||||
} catch (ex) {
|
} catch (ex) {
|
||||||
return { error: ex };
|
return { error: ex };
|
||||||
} finally {
|
} finally {
|
||||||
AST_Node.warn_function = warn_function;
|
AST_Node.disable_validation();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
/***********************************************************************
|
/***********************************************************************
|
||||||
|
|
||||||
A JavaScript tokenizer / parser / beautifier / compressor.
|
A JavaScript tokenizer / parser / beautifier / compressor.
|
||||||
https://github.com/mishoo/UglifyJS2
|
https://github.com/mishoo/UglifyJS
|
||||||
|
|
||||||
-------------------------------- (C) ---------------------------------
|
-------------------------------- (C) ---------------------------------
|
||||||
|
|
||||||
@@ -43,11 +43,9 @@
|
|||||||
|
|
||||||
"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({
|
||||||
@@ -59,9 +57,8 @@
|
|||||||
in_directive = false;
|
in_directive = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return body;
|
return body;
|
||||||
};
|
}
|
||||||
|
|
||||||
var MOZ_TO_ME = {
|
var MOZ_TO_ME = {
|
||||||
Program: function(M) {
|
Program: function(M) {
|
||||||
@@ -114,11 +111,11 @@
|
|||||||
var args = {
|
var args = {
|
||||||
start : my_start_token(key),
|
start : my_start_token(key),
|
||||||
end : my_end_token(M.value),
|
end : my_end_token(M.value),
|
||||||
key : key.type == "Identifier" ? key.name : key.value,
|
key : "" + key[key.type == "Identifier" ? "name" : "value"],
|
||||||
value : from_moz(M.value)
|
value : from_moz(M.value)
|
||||||
};
|
};
|
||||||
if (M.kind == "init") return new AST_ObjectKeyVal(args);
|
if (M.kind == "init") return new AST_ObjectKeyVal(args);
|
||||||
args.key = new AST_SymbolMethod({
|
args.key = new AST_SymbolAccessor({
|
||||||
name: args.key
|
name: args.key
|
||||||
});
|
});
|
||||||
args.value = new AST_Accessor(args.value);
|
args.value = new AST_Accessor(args.value);
|
||||||
@@ -129,7 +126,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);
|
||||||
})
|
})
|
||||||
});
|
});
|
||||||
@@ -138,7 +135,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)
|
||||||
})
|
})
|
||||||
@@ -168,7 +165,7 @@
|
|||||||
});
|
});
|
||||||
},
|
},
|
||||||
VariableDeclaration: function(M) {
|
VariableDeclaration: function(M) {
|
||||||
return new (M.kind === "const" ? AST_Const : AST_Var)({
|
return new AST_Var({
|
||||||
start : my_start_token(M),
|
start : my_start_token(M),
|
||||||
end : my_end_token(M),
|
end : my_end_token(M),
|
||||||
definitions : M.declarations.map(from_moz)
|
definitions : M.declarations.map(from_moz)
|
||||||
@@ -180,6 +177,17 @@
|
|||||||
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;
|
||||||
@@ -189,22 +197,12 @@
|
|||||||
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 ? (p.kind == "const" ? AST_SymbolConst : AST_SymbolVar)
|
: p.type == "VariableDeclarator" && p.id === M ? AST_SymbolVar
|
||||||
: p.type == "FunctionExpression" ? (p.id === M ? AST_SymbolLambda : AST_SymbolFunarg)
|
: p.type == "FunctionExpression" ? (p.id === M ? AST_SymbolLambda : AST_SymbolFunarg)
|
||||||
: p.type == "FunctionDeclaration" ? (p.id === M ? AST_SymbolDefun : AST_SymbolFunarg)
|
: p.type == "FunctionDeclaration" ? (p.id === M ? AST_SymbolDefun : AST_SymbolFunarg)
|
||||||
: p.type == "CatchClause" ? AST_SymbolCatch
|
: p.type == "CatchClause" ? AST_SymbolCatch
|
||||||
@@ -214,7 +212,14 @@
|
|||||||
end : my_end_token(M),
|
end : my_end_token(M),
|
||||||
name : M.name
|
name : M.name
|
||||||
});
|
});
|
||||||
}
|
},
|
||||||
|
ThisExpression: function(M) {
|
||||||
|
return new AST_This({
|
||||||
|
start : my_start_token(M),
|
||||||
|
end : my_end_token(M),
|
||||||
|
name : "this",
|
||||||
|
});
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
MOZ_TO_ME.UpdateExpression =
|
MOZ_TO_ME.UpdateExpression =
|
||||||
@@ -247,7 +252,6 @@
|
|||||||
map("VariableDeclarator", AST_VarDef, "id>name, init>value");
|
map("VariableDeclarator", AST_VarDef, "id>name, init>value");
|
||||||
map("CatchClause", AST_Catch, "param>argname, body%body");
|
map("CatchClause", AST_Catch, "param>argname, body%body");
|
||||||
|
|
||||||
map("ThisExpression", AST_This);
|
|
||||||
map("BinaryExpression", AST_Binary, "operator=operator, left>left, right>right");
|
map("BinaryExpression", AST_Binary, "operator=operator, left>left, right>right");
|
||||||
map("LogicalExpression", AST_Binary, "operator=operator, left>left, right>right");
|
map("LogicalExpression", AST_Binary, "operator=operator, left>left, right>right");
|
||||||
map("AssignmentExpression", AST_Assign, "operator=operator, left>left, right>right");
|
map("AssignmentExpression", AST_Assign, "operator=operator, left>left, right>right");
|
||||||
@@ -324,7 +328,7 @@
|
|||||||
def_to_moz(AST_Definitions, function To_Moz_VariableDeclaration(M) {
|
def_to_moz(AST_Definitions, function To_Moz_VariableDeclaration(M) {
|
||||||
return {
|
return {
|
||||||
type: "VariableDeclaration",
|
type: "VariableDeclaration",
|
||||||
kind: M instanceof AST_Const ? "const" : "var",
|
kind: "var",
|
||||||
declarations: M.definitions.map(to_moz)
|
declarations: M.definitions.map(to_moz)
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
@@ -381,7 +385,7 @@
|
|||||||
def_to_moz(AST_ObjectProperty, function To_Moz_Property(M) {
|
def_to_moz(AST_ObjectProperty, function To_Moz_Property(M) {
|
||||||
var key = {
|
var key = {
|
||||||
type: "Literal",
|
type: "Literal",
|
||||||
value: M.key instanceof AST_SymbolMethod ? M.key.name : M.key
|
value: M.key instanceof AST_SymbolAccessor ? M.key.name : M.key
|
||||||
};
|
};
|
||||||
var kind;
|
var kind;
|
||||||
if (M instanceof AST_ObjectKeyVal) {
|
if (M instanceof AST_ObjectKeyVal) {
|
||||||
@@ -405,19 +409,24 @@
|
|||||||
var def = M.definition();
|
var def = M.definition();
|
||||||
return {
|
return {
|
||||||
type: "Identifier",
|
type: "Identifier",
|
||||||
name: def ? def.mangled_name || def.name : M.name
|
name: def && def.mangled_name || M.name
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
|
def_to_moz(AST_This, function To_Moz_ThisExpression() {
|
||||||
|
return { type: "ThisExpression" };
|
||||||
|
});
|
||||||
|
|
||||||
def_to_moz(AST_RegExp, function To_Moz_RegExpLiteral(M) {
|
def_to_moz(AST_RegExp, function To_Moz_RegExpLiteral(M) {
|
||||||
var value = M.value;
|
var flags = M.value.toString().match(/[gimuy]*$/)[0];
|
||||||
|
var value = "/" + M.value.raw_source + "/" + flags;
|
||||||
return {
|
return {
|
||||||
type: "Literal",
|
type: "Literal",
|
||||||
value: value,
|
value: value,
|
||||||
raw: value.toString(),
|
raw: value,
|
||||||
regex: {
|
regex: {
|
||||||
pattern: value.source,
|
pattern: M.value.raw_source,
|
||||||
flags: value.toString().match(/[gimuy]*$/)[0]
|
flags: flags
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
@@ -478,7 +487,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;
|
||||||
@@ -493,7 +502,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";
|
||||||
@@ -505,7 +514,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];
|
||||||
@@ -548,7 +557,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;
|
||||||
|
|
||||||
@@ -557,13 +566,28 @@
|
|||||||
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;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -583,24 +607,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);
|
||||||
@@ -611,5 +635,5 @@
|
|||||||
type: type,
|
type: type,
|
||||||
body: body
|
body: body
|
||||||
};
|
};
|
||||||
};
|
}
|
||||||
})();
|
})();
|
||||||
|
|||||||
1478
lib/output.js
1478
lib/output.js
File diff suppressed because it is too large
Load Diff
2065
lib/parse.js
2065
lib/parse.js
File diff suppressed because one or more lines are too long
@@ -1,7 +1,7 @@
|
|||||||
/***********************************************************************
|
/***********************************************************************
|
||||||
|
|
||||||
A JavaScript tokenizer / parser / beautifier / compressor.
|
A JavaScript tokenizer / parser / beautifier / compressor.
|
||||||
https://github.com/mishoo/UglifyJS2
|
https://github.com/mishoo/UglifyJS
|
||||||
|
|
||||||
-------------------------------- (C) ---------------------------------
|
-------------------------------- (C) ---------------------------------
|
||||||
|
|
||||||
@@ -44,16 +44,6 @@
|
|||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
function find_builtins(reserved) {
|
function find_builtins(reserved) {
|
||||||
|
|
||||||
// Compatibility fix for some standard defined globals not defined on every js environment
|
|
||||||
var new_globals = ["Symbol", "Map", "Promise", "Proxy", "Reflect", "Set", "WeakMap", "WeakSet"];
|
|
||||||
var objects = {};
|
|
||||||
var global_ref = typeof global === "object" ? global : self;
|
|
||||||
|
|
||||||
new_globals.forEach(function (new_global) {
|
|
||||||
objects[new_global] = global_ref[new_global] || new Function();
|
|
||||||
});
|
|
||||||
|
|
||||||
// NaN will be included due to Number.NaN
|
// NaN will be included due to Number.NaN
|
||||||
[
|
[
|
||||||
"null",
|
"null",
|
||||||
@@ -63,42 +53,41 @@ function find_builtins(reserved) {
|
|||||||
"-Infinity",
|
"-Infinity",
|
||||||
"undefined",
|
"undefined",
|
||||||
].forEach(add);
|
].forEach(add);
|
||||||
[ Object, Array, Function, Number,
|
[
|
||||||
String, Boolean, Error, Math,
|
Array,
|
||||||
Date, RegExp, objects.Symbol, ArrayBuffer,
|
Boolean,
|
||||||
DataView, decodeURI, decodeURIComponent,
|
Date,
|
||||||
encodeURI, encodeURIComponent, eval, EvalError,
|
Error,
|
||||||
Float32Array, Float64Array, Int8Array, Int16Array,
|
Function,
|
||||||
Int32Array, isFinite, isNaN, JSON, objects.Map, parseFloat,
|
Math,
|
||||||
parseInt, objects.Promise, objects.Proxy, RangeError, ReferenceError,
|
Number,
|
||||||
objects.Reflect, objects.Set, SyntaxError, TypeError, Uint8Array,
|
Object,
|
||||||
Uint8ClampedArray, Uint16Array, Uint32Array, URIError,
|
RegExp,
|
||||||
objects.WeakMap, objects.WeakSet
|
String,
|
||||||
].forEach(function(ctor){
|
].forEach(function(ctor) {
|
||||||
Object.getOwnPropertyNames(ctor).map(add);
|
Object.getOwnPropertyNames(ctor).map(add);
|
||||||
if (ctor.prototype) {
|
if (ctor.prototype) {
|
||||||
Object.getOwnPropertyNames(ctor.prototype).map(add);
|
Object.getOwnPropertyNames(ctor.prototype).map(add);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
function add(name) {
|
function add(name) {
|
||||||
push_uniq(reserved, name);
|
push_uniq(reserved, name);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function reserve_quoted_keys(ast, reserved) {
|
function reserve_quoted_keys(ast, reserved) {
|
||||||
function add(name) {
|
|
||||||
push_uniq(reserved, name);
|
|
||||||
}
|
|
||||||
|
|
||||||
ast.walk(new TreeWalker(function(node) {
|
ast.walk(new TreeWalker(function(node) {
|
||||||
if (node instanceof AST_ObjectKeyVal && node.quote) {
|
if (node instanceof AST_ObjectKeyVal && node.quote) {
|
||||||
add(node.key);
|
add(node.key);
|
||||||
} 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);
|
||||||
}
|
}
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
function add(name) {
|
||||||
|
push_uniq(reserved, name);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function addStrings(node, add) {
|
function addStrings(node, add) {
|
||||||
@@ -130,12 +119,15 @@ function mangle_properties(ast, options) {
|
|||||||
if (!Array.isArray(reserved)) reserved = [];
|
if (!Array.isArray(reserved)) reserved = [];
|
||||||
if (!options.builtins) find_builtins(reserved);
|
if (!options.builtins) find_builtins(reserved);
|
||||||
|
|
||||||
var cache = options.cache;
|
var cname = -1;
|
||||||
if (cache == null) {
|
var cache;
|
||||||
cache = {
|
if (options.cache) {
|
||||||
cname: -1,
|
cache = options.cache.props;
|
||||||
props: new Dictionary()
|
cache.each(function(mangled_name) {
|
||||||
};
|
push_uniq(reserved, mangled_name);
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
cache = new Dictionary();
|
||||||
}
|
}
|
||||||
|
|
||||||
var regex = options.regex;
|
var regex = options.regex;
|
||||||
@@ -144,45 +136,43 @@ function mangle_properties(ast, options) {
|
|||||||
// note debug may be enabled as an empty string, which is falsey. Also treat passing 'true'
|
// note debug may be enabled as an empty string, which is falsey. Also treat passing 'true'
|
||||||
// the same as passing an empty string.
|
// the same as passing an empty string.
|
||||||
var debug = options.debug !== false;
|
var debug = options.debug !== false;
|
||||||
var debug_name_suffix;
|
var debug_suffix;
|
||||||
if (debug) {
|
if (debug) debug_suffix = options.debug === true ? "" : options.debug;
|
||||||
debug_name_suffix = (options.debug === true ? "" : options.debug);
|
|
||||||
}
|
|
||||||
|
|
||||||
var names_to_mangle = [];
|
var names_to_mangle = [];
|
||||||
var unmangleable = [];
|
var unmangleable = [];
|
||||||
|
|
||||||
// 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);
|
||||||
}
|
} else if (node instanceof AST_ObjectProperty) {
|
||||||
else if (node instanceof AST_ObjectProperty) {
|
|
||||||
// setter or getter, since KeyVal is handled above
|
// setter or getter, since KeyVal is handled above
|
||||||
add(node.key.name);
|
add(node.key.name);
|
||||||
}
|
} else if (node instanceof AST_Dot) {
|
||||||
else if (node instanceof AST_Dot) {
|
|
||||||
add(node.property);
|
add(node.property);
|
||||||
}
|
} else if (node instanceof AST_Sub) {
|
||||||
else if (node instanceof AST_Sub) {
|
|
||||||
addStrings(node.property, add);
|
addStrings(node.property, add);
|
||||||
|
} else if (node instanceof AST_Call
|
||||||
|
&& 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);
|
||||||
}
|
} else if (node instanceof AST_ObjectProperty) {
|
||||||
else if (node instanceof AST_ObjectProperty) {
|
|
||||||
// setter or getter
|
// setter or getter
|
||||||
node.key.name = mangle(node.key.name);
|
node.key.name = mangle(node.key.name);
|
||||||
}
|
} else if (node instanceof AST_Dot) {
|
||||||
else if (node instanceof AST_Dot) {
|
|
||||||
node.property = mangle(node.property);
|
node.property = mangle(node.property);
|
||||||
}
|
} else if (!options.keep_quoted && node instanceof AST_Sub) {
|
||||||
else if (!options.keep_quoted && node instanceof AST_Sub) {
|
|
||||||
node.property = mangleStrings(node.property);
|
node.property = mangleStrings(node.property);
|
||||||
|
} else if (node instanceof AST_Call
|
||||||
|
&& node.expression.print_to_string() == "Object.defineProperty") {
|
||||||
|
node.args[1] = mangleStrings(node.args[1]);
|
||||||
}
|
}
|
||||||
}));
|
}));
|
||||||
|
|
||||||
@@ -191,9 +181,7 @@ function mangle_properties(ast, options) {
|
|||||||
function can_mangle(name) {
|
function can_mangle(name) {
|
||||||
if (unmangleable.indexOf(name) >= 0) return false;
|
if (unmangleable.indexOf(name) >= 0) return false;
|
||||||
if (reserved.indexOf(name) >= 0) return false;
|
if (reserved.indexOf(name) >= 0) return false;
|
||||||
if (options.only_cache) {
|
if (options.only_cache) return cache.has(name);
|
||||||
return cache.props.has(name);
|
|
||||||
}
|
|
||||||
if (/^-?[0-9]+(\.[0-9]+)?(e[+-][0-9]+)?$/.test(name)) return false;
|
if (/^-?[0-9]+(\.[0-9]+)?(e[+-][0-9]+)?$/.test(name)) return false;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -201,57 +189,42 @@ function mangle_properties(ast, options) {
|
|||||||
function should_mangle(name) {
|
function should_mangle(name) {
|
||||||
if (regex && !regex.test(name)) return false;
|
if (regex && !regex.test(name)) return false;
|
||||||
if (reserved.indexOf(name) >= 0) return false;
|
if (reserved.indexOf(name) >= 0) return false;
|
||||||
return cache.props.has(name)
|
return cache.has(name) || names_to_mangle.indexOf(name) >= 0;
|
||||||
|| names_to_mangle.indexOf(name) >= 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function add(name) {
|
function add(name) {
|
||||||
if (can_mangle(name))
|
if (can_mangle(name)) push_uniq(names_to_mangle, name);
|
||||||
push_uniq(names_to_mangle, name);
|
if (!should_mangle(name)) push_uniq(unmangleable, name);
|
||||||
|
|
||||||
if (!should_mangle(name)) {
|
|
||||||
push_uniq(unmangleable, name);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function mangle(name) {
|
function mangle(name) {
|
||||||
if (!should_mangle(name)) {
|
if (!should_mangle(name)) {
|
||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
|
var mangled = cache.get(name);
|
||||||
var mangled = cache.props.get(name);
|
|
||||||
if (!mangled) {
|
if (!mangled) {
|
||||||
if (debug) {
|
if (debug) {
|
||||||
// debug mode: use a prefix and suffix to preserve readability, e.g. o.foo -> o._$foo$NNN_.
|
// debug mode: use a prefix and suffix to preserve readability, e.g. o.foo -> o._$foo$NNN_.
|
||||||
var debug_mangled = "_$" + name + "$" + debug_name_suffix + "_";
|
var debug_mangled = "_$" + name + "$" + debug_suffix + "_";
|
||||||
|
if (can_mangle(debug_mangled)) mangled = debug_mangled;
|
||||||
if (can_mangle(debug_mangled)) {
|
|
||||||
mangled = debug_mangled;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// either debug mode is off, or it is on and we could not use the mangled name
|
// either debug mode is off, or it is on and we could not use the mangled name
|
||||||
if (!mangled) {
|
if (!mangled) do {
|
||||||
do {
|
mangled = base54(++cname);
|
||||||
mangled = base54(++cache.cname);
|
} while (!can_mangle(mangled));
|
||||||
} while (!can_mangle(mangled));
|
cache.set(name, mangled);
|
||||||
}
|
|
||||||
|
|
||||||
cache.props.set(name, mangled);
|
|
||||||
}
|
}
|
||||||
return mangled;
|
return mangled;
|
||||||
}
|
}
|
||||||
|
|
||||||
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]);
|
||||||
}
|
} else if (node instanceof AST_String) {
|
||||||
else if (node instanceof AST_String) {
|
|
||||||
node.value = mangle(node.value);
|
node.value = mangle(node.value);
|
||||||
}
|
} else if (node instanceof AST_Conditional) {
|
||||||
else if (node instanceof AST_Conditional) {
|
|
||||||
node.consequent = mangleStrings(node.consequent);
|
node.consequent = mangleStrings(node.consequent);
|
||||||
node.alternative = mangleStrings(node.alternative);
|
node.alternative = mangleStrings(node.alternative);
|
||||||
}
|
}
|
||||||
|
|||||||
594
lib/scope.js
594
lib/scope.js
@@ -1,7 +1,7 @@
|
|||||||
/***********************************************************************
|
/***********************************************************************
|
||||||
|
|
||||||
A JavaScript tokenizer / parser / beautifier / compressor.
|
A JavaScript tokenizer / parser / beautifier / compressor.
|
||||||
https://github.com/mishoo/UglifyJS2
|
https://github.com/mishoo/UglifyJS
|
||||||
|
|
||||||
-------------------------------- (C) ---------------------------------
|
-------------------------------- (C) ---------------------------------
|
||||||
|
|
||||||
@@ -43,53 +43,41 @@
|
|||||||
|
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
function SymbolDef(scope, orig) {
|
function SymbolDef(id, scope, orig, init) {
|
||||||
|
this.eliminated = 0;
|
||||||
|
this.global = false;
|
||||||
|
this.id = id;
|
||||||
|
this.init = init;
|
||||||
|
this.lambda = orig instanceof AST_SymbolLambda;
|
||||||
|
this.mangled_name = null;
|
||||||
this.name = orig.name;
|
this.name = orig.name;
|
||||||
this.orig = [ orig ];
|
this.orig = [ orig ];
|
||||||
this.eliminated = 0;
|
|
||||||
this.scope = scope;
|
|
||||||
this.references = [];
|
this.references = [];
|
||||||
this.replaced = 0;
|
this.replaced = 0;
|
||||||
this.global = false;
|
this.scope = scope;
|
||||||
this.export = false;
|
|
||||||
this.mangled_name = null;
|
|
||||||
this.undeclared = false;
|
this.undeclared = false;
|
||||||
this.id = SymbolDef.next_id++;
|
}
|
||||||
};
|
|
||||||
|
|
||||||
SymbolDef.next_id = 1;
|
|
||||||
|
|
||||||
SymbolDef.prototype = {
|
SymbolDef.prototype = {
|
||||||
unmangleable: function(options) {
|
unmangleable: function(options) {
|
||||||
if (!options) options = {};
|
return this.global && !options.toplevel
|
||||||
|
|
||||||
return (this.global && !options.toplevel)
|
|
||||||
|| this.export
|
|
||||||
|| this.undeclared
|
|| this.undeclared
|
||||||
|| (!options.eval && (this.scope.uses_eval || this.scope.uses_with))
|
|| !options.eval && this.scope.pinned()
|
||||||
|| (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 = s.next_mangled(options, this);
|
this.mangled_name = next_mangled_name(this.scope, options, this);
|
||||||
|
}
|
||||||
if (this.global && cache) {
|
if (this.global && cache) {
|
||||||
cache.set(this.name, this.mangled_name);
|
cache.set(this.name, this.mangled_name);
|
||||||
}
|
}
|
||||||
@@ -100,71 +88,37 @@ 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 in_destructuring = null;
|
var tw = new TreeWalker(function(node, descend) {
|
||||||
var for_scopes = [];
|
if (node instanceof AST_Catch) {
|
||||||
var tw = new TreeWalker(function(node, descend){
|
|
||||||
if (node.is_block_scope()) {
|
|
||||||
var save_scope = scope;
|
var save_scope = scope;
|
||||||
node.block_scope = scope = new AST_Scope(node);
|
scope = new AST_Scope(node);
|
||||||
scope.init_scope_vars(save_scope);
|
scope.init_scope_vars(save_scope);
|
||||||
if (!(node instanceof AST_Scope)) {
|
|
||||||
scope.uses_with = save_scope.uses_with;
|
|
||||||
scope.uses_eval = save_scope.uses_eval;
|
|
||||||
scope.directives = save_scope.directives;
|
|
||||||
}
|
|
||||||
if (options.safari10) {
|
|
||||||
if (node instanceof AST_For || node instanceof AST_ForIn) {
|
|
||||||
for_scopes.push(scope);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
descend();
|
descend();
|
||||||
scope = save_scope;
|
scope = save_scope;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (node instanceof AST_Destructuring) {
|
|
||||||
in_destructuring = node; // These don't nest
|
|
||||||
descend();
|
|
||||||
in_destructuring = null;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
if (node instanceof AST_Scope) {
|
if (node instanceof AST_Scope) {
|
||||||
node.init_scope_vars(scope);
|
node.init_scope_vars(scope);
|
||||||
var save_scope = scope;
|
var save_scope = scope;
|
||||||
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;
|
||||||
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;
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (node instanceof AST_Symbol) {
|
if (node instanceof AST_Symbol) {
|
||||||
@@ -174,174 +128,129 @@ AST_Toplevel.DEFMETHOD("figure_out_scope", function(options){
|
|||||||
node.thedef = node;
|
node.thedef = node;
|
||||||
node.references = [];
|
node.references = [];
|
||||||
}
|
}
|
||||||
if (node instanceof AST_SymbolLambda) {
|
if (node instanceof AST_SymbolDefun) {
|
||||||
defun.def_function(node);
|
// This should be defined in the parent scope, as we encounter the
|
||||||
}
|
// AST_Defun node before getting to its AST_Symbol.
|
||||||
else if (node instanceof AST_SymbolDefun) {
|
(node.scope = defun.parent_scope.resolve()).def_function(node, defun);
|
||||||
// Careful here, the scope where this should be defined is
|
} else if (node instanceof AST_SymbolLambda) {
|
||||||
// the parent scope. The reason is that we enter a new
|
var def = defun.def_function(node, node.name == "arguments" ? undefined : defun);
|
||||||
// scope when we encounter the AST_Defun node (which is
|
if (options.ie8) def.defun = defun.parent_scope.resolve();
|
||||||
// instanceof AST_Scope) but we get to the symbol a bit
|
} else if (node instanceof AST_SymbolVar) {
|
||||||
// later.
|
defun.def_variable(node, node.TYPE == "SymbolVar" ? null : undefined);
|
||||||
mark_export((node.scope = defun.parent_scope.get_defun_scope()).def_function(node), 1);
|
|
||||||
}
|
|
||||||
else if (node instanceof AST_SymbolClass) {
|
|
||||||
mark_export(defun.def_variable(node), 1);
|
|
||||||
}
|
|
||||||
else if (node instanceof AST_SymbolImport) {
|
|
||||||
scope.def_variable(node);
|
|
||||||
}
|
|
||||||
else if (node instanceof AST_SymbolDefClass) {
|
|
||||||
// This deals with the name of the class being available
|
|
||||||
// inside the class.
|
|
||||||
mark_export((node.scope = defun.parent_scope).def_function(node), 1);
|
|
||||||
}
|
|
||||||
else if (node instanceof AST_SymbolVar
|
|
||||||
|| node instanceof AST_SymbolLet
|
|
||||||
|| node instanceof AST_SymbolConst) {
|
|
||||||
var def = ((node instanceof AST_SymbolBlockDeclaration) ? scope : defun).def_variable(node);
|
|
||||||
if (!all(def.orig, function(sym) {
|
|
||||||
if (sym === node) return true;
|
|
||||||
if (node instanceof AST_SymbolBlockDeclaration) {
|
|
||||||
return sym instanceof AST_SymbolLambda;
|
|
||||||
}
|
|
||||||
return !(sym instanceof AST_SymbolLet || sym instanceof AST_SymbolConst);
|
|
||||||
})) {
|
|
||||||
js_error(
|
|
||||||
node.name + " redeclared",
|
|
||||||
node.start.file,
|
|
||||||
node.start.line,
|
|
||||||
node.start.col,
|
|
||||||
node.start.pos
|
|
||||||
);
|
|
||||||
}
|
|
||||||
if (!(node instanceof AST_SymbolFunarg)) mark_export(def, 2);
|
|
||||||
def.destructuring = in_destructuring;
|
|
||||||
if (defun !== scope) {
|
if (defun !== scope) {
|
||||||
node.mark_enclosed(options);
|
node.mark_enclosed(options);
|
||||||
var def = scope.find_variable(node);
|
var def = scope.find_variable(node);
|
||||||
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.next_def_id = 0;
|
||||||
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) {
|
||||||
if (node instanceof AST_LoopControl && node.label) {
|
if (node instanceof AST_LoopControl) {
|
||||||
node.label.thedef.references.push(node);
|
if (node.label) node.label.thedef.references.push(node);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (node instanceof AST_SymbolRef) {
|
if (node instanceof AST_SymbolRef) {
|
||||||
var name = node.name;
|
var name = node.name;
|
||||||
if (name == "eval" && tw.parent() instanceof AST_Call) {
|
var sym = node.scope.find_variable(name);
|
||||||
for (var s = node.scope; s && !s.uses_eval; s = s.parent_scope) {
|
if (!sym) {
|
||||||
s.uses_eval = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
var 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;
|
||||||
}
|
}
|
||||||
|
if (name == "eval") {
|
||||||
|
var parent = tw.parent();
|
||||||
|
if (parent.TYPE == "Call" && parent.expression === node) {
|
||||||
|
for (var s = node.scope; s && !s.uses_eval; s = s.parent_scope) {
|
||||||
|
s.uses_eval = true;
|
||||||
|
}
|
||||||
|
} else if (sym.undeclared) {
|
||||||
|
self.uses_eval = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
node.thedef = sym;
|
node.thedef = sym;
|
||||||
node.reference(options);
|
node.reference(options);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
// ensure mangling works if catch reuses a scope variable
|
// ensure mangling works if catch reuses a scope variable
|
||||||
var def;
|
if (node instanceof AST_SymbolCatch) {
|
||||||
if (node instanceof AST_SymbolCatch && (def = node.definition().redefined())) {
|
var def = node.definition().redefined();
|
||||||
var s = node.scope;
|
if (def) for (var s = node.scope; s; s = s.parent_scope) {
|
||||||
while (s) {
|
|
||||||
push_uniq(s.enclosed, def);
|
push_uniq(s.enclosed, def);
|
||||||
if (s === def.scope) break;
|
if (s === def.scope) break;
|
||||||
s = s.parent_scope;
|
|
||||||
}
|
}
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
self.walk(tw);
|
self.walk(tw);
|
||||||
|
|
||||||
// pass 3: fix up any scoping issue with IE8
|
// pass 3: fix up any scoping issue with IE8
|
||||||
if (options.ie8) {
|
if (options.ie8) self.walk(new TreeWalker(function(node) {
|
||||||
self.walk(new TreeWalker(function(node, descend) {
|
if (node instanceof AST_SymbolCatch) {
|
||||||
if (node instanceof AST_SymbolCatch) {
|
var scope = node.thedef.defun;
|
||||||
var name = node.name;
|
if (scope.name instanceof AST_SymbolLambda && scope.name.name == node.name) {
|
||||||
var refs = node.thedef.references;
|
scope = scope.parent_scope.resolve();
|
||||||
var scope = node.thedef.defun;
|
|
||||||
var def = scope.find_variable(name) || self.globals.get(name) || scope.def_variable(node);
|
|
||||||
refs.forEach(function(ref) {
|
|
||||||
ref.thedef = def;
|
|
||||||
ref.reference(options);
|
|
||||||
});
|
|
||||||
node.thedef = def;
|
|
||||||
node.reference(options);
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
}));
|
redefine(node, scope);
|
||||||
}
|
return true;
|
||||||
|
|
||||||
// pass 4: add symbol definitions to loop scopes
|
|
||||||
// Safari/Webkit bug workaround - loop init let variable shadowing argument.
|
|
||||||
// https://github.com/mishoo/UglifyJS2/issues/1753
|
|
||||||
// https://bugs.webkit.org/show_bug.cgi?id=171041
|
|
||||||
if (options.safari10) {
|
|
||||||
for (var i = 0; i < for_scopes.length; i++) {
|
|
||||||
var scope = for_scopes[i];
|
|
||||||
scope.parent_scope.variables.each(function(def) {
|
|
||||||
push_uniq(scope.enclosed, def);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
if (node instanceof AST_SymbolLambda) {
|
||||||
|
var def = node.thedef;
|
||||||
|
redefine(node, node.scope.parent_scope.resolve());
|
||||||
|
if (typeof node.thedef.init !== "undefined") {
|
||||||
|
node.thedef.init = false;
|
||||||
|
} else if (def.init) {
|
||||||
|
node.thedef.init = def.init;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}));
|
||||||
|
|
||||||
if (options.cache) {
|
function redefine(node, scope) {
|
||||||
this.cname = options.cache.cname;
|
var name = node.name;
|
||||||
|
var old_def = node.thedef;
|
||||||
|
var new_def = scope.find_variable(name);
|
||||||
|
if (new_def) {
|
||||||
|
var redef;
|
||||||
|
while (redef = new_def.redefined()) new_def = redef;
|
||||||
|
} else {
|
||||||
|
new_def = self.globals.get(name);
|
||||||
|
}
|
||||||
|
if (new_def) {
|
||||||
|
new_def.orig.push(node);
|
||||||
|
} else {
|
||||||
|
new_def = scope.def_variable(node);
|
||||||
|
}
|
||||||
|
old_def.orig.concat(old_def.references).forEach(function(node) {
|
||||||
|
node.thedef = new_def;
|
||||||
|
node.reference(options);
|
||||||
|
});
|
||||||
|
if (old_def.lambda) new_def.lambda = true;
|
||||||
|
if (new_def.undeclared) self.variables.set(name, new_def);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
AST_Toplevel.DEFMETHOD("def_global", function(node){
|
AST_Scope.DEFMETHOD("make_def", function(orig, init) {
|
||||||
|
var top = this;
|
||||||
|
while (top.parent_scope) top = top.parent_scope;
|
||||||
|
return new SymbolDef(++top.next_def_id, this, orig, init);
|
||||||
|
});
|
||||||
|
|
||||||
|
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);
|
||||||
} else {
|
} else {
|
||||||
var g = new SymbolDef(this, node);
|
var g = this.make_def(node);
|
||||||
g.undeclared = true;
|
g.undeclared = true;
|
||||||
g.global = true;
|
g.global = true;
|
||||||
globals.set(name, g);
|
globals.set(name, g);
|
||||||
@@ -349,7 +258,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
|
||||||
@@ -359,15 +268,7 @@ AST_Scope.DEFMETHOD("init_scope_vars", function(parent_scope){
|
|||||||
this.cname = -1; // the current index for mangling functions/variables
|
this.cname = -1; // the current index for mangling functions/variables
|
||||||
});
|
});
|
||||||
|
|
||||||
AST_Node.DEFMETHOD("is_block_scope", return_false);
|
AST_Lambda.DEFMETHOD("init_scope_vars", function() {
|
||||||
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({
|
||||||
@@ -379,8 +280,7 @@ AST_Lambda.DEFMETHOD("init_scope_vars", function(){
|
|||||||
|
|
||||||
AST_Symbol.DEFMETHOD("mark_enclosed", function(options) {
|
AST_Symbol.DEFMETHOD("mark_enclosed", function(options) {
|
||||||
var def = this.definition();
|
var def = this.definition();
|
||||||
var s = this.scope;
|
for (var s = this.scope; s; s = s.parent_scope) {
|
||||||
while (s) {
|
|
||||||
push_uniq(s.enclosed, def);
|
push_uniq(s.enclosed, def);
|
||||||
if (options.keep_fnames) {
|
if (options.keep_fnames) {
|
||||||
s.functions.each(function(d) {
|
s.functions.each(function(d) {
|
||||||
@@ -388,7 +288,6 @@ AST_Symbol.DEFMETHOD("mark_enclosed", function(options) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
if (s === def.scope) break;
|
if (s === def.scope) break;
|
||||||
s = s.parent_scope;
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -397,71 +296,89 @@ 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){
|
AST_Scope.DEFMETHOD("def_function", function(symbol, init) {
|
||||||
var def = this.def_variable(symbol);
|
var def = this.def_variable(symbol, init);
|
||||||
|
if (!def.init || def.init instanceof AST_Defun) def.init = init;
|
||||||
this.functions.set(symbol.name, def);
|
this.functions.set(symbol.name, def);
|
||||||
return def;
|
return def;
|
||||||
});
|
});
|
||||||
|
|
||||||
AST_Scope.DEFMETHOD("def_variable", function(symbol){
|
AST_Scope.DEFMETHOD("def_variable", function(symbol, init) {
|
||||||
var def;
|
var def = this.variables.get(symbol.name);
|
||||||
if (!this.variables.has(symbol.name)) {
|
if (def) {
|
||||||
def = new SymbolDef(this, symbol);
|
def.orig.push(symbol);
|
||||||
|
if (def.init instanceof AST_Function) def.init = init;
|
||||||
|
} else {
|
||||||
|
def = this.make_def(symbol, init);
|
||||||
this.variables.set(symbol.name, def);
|
this.variables.set(symbol.name, def);
|
||||||
def.global = !this.parent_scope;
|
def.global = !this.parent_scope;
|
||||||
} else {
|
|
||||||
def = this.variables.get(symbol.name);
|
|
||||||
def.orig.push(symbol);
|
|
||||||
}
|
}
|
||||||
return symbol.thedef = def;
|
return symbol.thedef = def;
|
||||||
});
|
});
|
||||||
|
|
||||||
AST_Scope.DEFMETHOD("next_mangled", function(options){
|
AST_Lambda.DEFMETHOD("resolve", return_this);
|
||||||
var ext = this.enclosed;
|
AST_Scope.DEFMETHOD("resolve", function() {
|
||||||
out: while (true) {
|
return this.parent_scope.resolve();
|
||||||
var m = base54(++this.cname);
|
|
||||||
if (!is_identifier(m)) continue; // skip over "do"
|
|
||||||
|
|
||||||
// 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;
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
AST_Toplevel.DEFMETHOD("resolve", return_this);
|
||||||
|
|
||||||
AST_Function.DEFMETHOD("next_mangled", function(options, def){
|
function names_in_use(scope, options) {
|
||||||
// #179, #326
|
var names = scope.names_in_use;
|
||||||
// in Safari strict mode, something like (function x(x){...}) is a syntax error;
|
if (!names) {
|
||||||
// a function expression's argument cannot shadow the function expression's name
|
scope.names_in_use = names = Object.create(scope.mangled_names || null);
|
||||||
|
scope.cname_holes = [];
|
||||||
var tricky_def = def.orig[0] instanceof AST_SymbolFunarg && this.name && this.name.definition();
|
var cache = options.cache && options.cache.props;
|
||||||
|
scope.enclosed.forEach(function(def) {
|
||||||
// the function's mangled_name is null when keep_fnames is true
|
if (def.unmangleable(options)) names[def.name] = true;
|
||||||
var tricky_name = tricky_def ? tricky_def.mangled_name || tricky_def.name : null;
|
if (def.global && cache && cache.has(def.name)) {
|
||||||
|
names[cache.get(def.name)] = true;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
return names;
|
||||||
|
}
|
||||||
|
|
||||||
|
function next_mangled_name(scope, options, def) {
|
||||||
|
var in_use = names_in_use(scope, options);
|
||||||
|
var holes = scope.cname_holes;
|
||||||
|
var names = Object.create(null);
|
||||||
|
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; i < holes.length; i++) {
|
||||||
|
name = base54(holes[i]);
|
||||||
|
if (names[name]) continue;
|
||||||
|
holes.splice(i, 1);
|
||||||
|
scope.names_in_use[name] = true;
|
||||||
|
return name;
|
||||||
|
}
|
||||||
while (true) {
|
while (true) {
|
||||||
var name = AST_Lambda.prototype.next_mangled.call(this, options, def);
|
name = base54(++scope.cname);
|
||||||
if (!tricky_name || tricky_name != name)
|
if (in_use[name] || RESERVED_WORDS[name] || options.reserved.has[name]) continue;
|
||||||
return name;
|
if (!names[name]) break;
|
||||||
|
holes.push(scope.cname);
|
||||||
}
|
}
|
||||||
});
|
scope.names_in_use[name] = true;
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
AST_Symbol.DEFMETHOD("unmangleable", function(options){
|
AST_Symbol.DEFMETHOD("unmangleable", function(options) {
|
||||||
var def = this.definition();
|
var def = this.definition();
|
||||||
return !def || def.unmangleable(options);
|
return !def || def.unmangleable(options);
|
||||||
});
|
});
|
||||||
@@ -469,24 +386,22 @@ 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 == 0
|
return !this.definition().references.length && !this.scope.pinned();
|
||||||
&& !(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;
|
||||||
});
|
});
|
||||||
|
|
||||||
AST_Toplevel.DEFMETHOD("_default_mangler_options", function(options) {
|
function _default_mangler_options(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,
|
||||||
@@ -494,123 +409,145 @@ AST_Toplevel.DEFMETHOD("_default_mangler_options", function(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 = this._default_mangler_options(options);
|
options = _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) {
|
if (options.cache && options.cache.props) {
|
||||||
this.globals.each(collect);
|
var mangled_names = this.mangled_names = Object.create(null);
|
||||||
|
options.cache.props.each(function(mangled_name) {
|
||||||
|
mangled_names[mangled_name] = true;
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
var tw = new TreeWalker(function(node, descend){
|
var redefined = [];
|
||||||
|
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;
|
||||||
descend();
|
descend();
|
||||||
lname = save_nesting;
|
lname = save_nesting;
|
||||||
return true; // don't descend again in TreeWalker
|
return true;
|
||||||
}
|
}
|
||||||
if (node instanceof AST_Scope) {
|
if (node instanceof AST_Scope) {
|
||||||
node.variables.each(collect);
|
descend();
|
||||||
return;
|
if (options.cache && node instanceof AST_Toplevel) {
|
||||||
|
node.globals.each(mangle);
|
||||||
|
}
|
||||||
|
if (node instanceof AST_Defun && tw.has_directive("use asm")) {
|
||||||
|
var sym = new AST_SymbolRef(node.name);
|
||||||
|
sym.scope = node;
|
||||||
|
sym.reference(options);
|
||||||
|
}
|
||||||
|
node.variables.each(function(def) {
|
||||||
|
if (!defer_redef(def)) mangle(def);
|
||||||
|
});
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
if (node instanceof AST_Label) {
|
if (node instanceof AST_Label) {
|
||||||
var name;
|
var name;
|
||||||
do name = base54(++lname); while (!is_identifier(name));
|
do {
|
||||||
|
name = base54(++lname);
|
||||||
|
} while (RESERVED_WORDS[name]);
|
||||||
node.mangled_name = name;
|
node.mangled_name = name;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
var mangle_with_block_scope =
|
if (!options.ie8 && node instanceof AST_Catch) {
|
||||||
(!options.ie8 && node instanceof AST_SymbolCatch) ||
|
var def = node.argname.definition();
|
||||||
node instanceof AST_SymbolBlockDeclaration;
|
var redef = defer_redef(def, node.argname);
|
||||||
if (mangle_with_block_scope && options.reserved.indexOf(node.name) < 0) {
|
descend();
|
||||||
to_mangle.push(node.definition());
|
if (!redef) mangle(def);
|
||||||
return;
|
return true;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
this.walk(tw);
|
this.walk(tw);
|
||||||
to_mangle.forEach(function(def){
|
redefined.forEach(mangle);
|
||||||
def.mangle(options);
|
|
||||||
});
|
|
||||||
|
|
||||||
if (options.cache) {
|
function mangle(def) {
|
||||||
options.cache.cname = this.cname;
|
if (options.reserved.has[def.name]) return;
|
||||||
|
def.mangle(options);
|
||||||
}
|
}
|
||||||
|
|
||||||
function collect(symbol) {
|
function defer_redef(def, node) {
|
||||||
if (!member(symbol.name, options.reserved)) {
|
var redef = def.redefined();
|
||||||
to_mangle.push(symbol);
|
if (!redef) return false;
|
||||||
|
redefined.push(def);
|
||||||
|
def.references.forEach(reference);
|
||||||
|
if (node) reference(node);
|
||||||
|
return true;
|
||||||
|
|
||||||
|
function reference(sym) {
|
||||||
|
sym.thedef = redef;
|
||||||
|
sym.reference(options);
|
||||||
|
sym.thedef = def;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
AST_Toplevel.DEFMETHOD("find_unique_prefix", function(options) {
|
AST_Toplevel.DEFMETHOD("find_colliding_names", function(options) {
|
||||||
var letters = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ$_";
|
|
||||||
var cache = options.cache && options.cache.props;
|
var cache = options.cache && options.cache.props;
|
||||||
var prefixes = Object.create(null);
|
var avoid = Object.create(null);
|
||||||
options.reserved.forEach(add_prefix);
|
options.reserved.forEach(to_avoid);
|
||||||
this.globals.each(add_def);
|
this.globals.each(add_def);
|
||||||
this.walk(new TreeWalker(function(node) {
|
this.walk(new TreeWalker(function(node) {
|
||||||
if (node instanceof AST_Scope) node.variables.each(add_def);
|
if (node instanceof AST_Scope) node.variables.each(add_def);
|
||||||
if (node instanceof AST_SymbolCatch) add_def(node.definition());
|
if (node instanceof AST_SymbolCatch) add_def(node.definition());
|
||||||
}));
|
}));
|
||||||
var prefix, i = 0;
|
return avoid;
|
||||||
do {
|
|
||||||
prefix = create_name(i++);
|
|
||||||
} while (prefixes[prefix]);
|
|
||||||
return prefix;
|
|
||||||
|
|
||||||
function add_prefix(name) {
|
function to_avoid(name) {
|
||||||
if (/[0-9]$/.test(name)) {
|
avoid[name] = true;
|
||||||
prefixes[name.replace(/[0-9]+$/, "")] = true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function add_def(def) {
|
function add_def(def) {
|
||||||
var name = def.name;
|
var name = def.name;
|
||||||
if (def.global && cache && cache.has(name)) name = cache.get(name);
|
if (def.global && cache && cache.has(name)) name = cache.get(name);
|
||||||
else if (!def.unmangleable(options)) return;
|
else if (!def.unmangleable(options)) return;
|
||||||
add_prefix(name);
|
to_avoid(name);
|
||||||
}
|
|
||||||
|
|
||||||
function create_name(num) {
|
|
||||||
var name = "";
|
|
||||||
do {
|
|
||||||
name += letters[num % letters.length];
|
|
||||||
num = Math.floor(num / letters.length);
|
|
||||||
} while (num);
|
|
||||||
return name;
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
AST_Toplevel.DEFMETHOD("expand_names", function(options) {
|
AST_Toplevel.DEFMETHOD("expand_names", function(options) {
|
||||||
options = this._default_mangler_options(options);
|
base54.reset();
|
||||||
var prefix = this.find_unique_prefix(options);
|
base54.sort();
|
||||||
|
options = _default_mangler_options(options);
|
||||||
|
var avoid = this.find_colliding_names(options);
|
||||||
|
var cname = 0;
|
||||||
this.globals.each(rename);
|
this.globals.each(rename);
|
||||||
this.walk(new TreeWalker(function(node) {
|
this.walk(new TreeWalker(function(node) {
|
||||||
if (node instanceof AST_Scope) node.variables.each(rename);
|
if (node instanceof AST_Scope) node.variables.each(rename);
|
||||||
if (node instanceof AST_SymbolCatch) rename(node.definition());
|
if (node instanceof AST_SymbolCatch) rename(node.definition());
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
function next_name() {
|
||||||
|
var name;
|
||||||
|
do {
|
||||||
|
name = base54(cname++);
|
||||||
|
} while (avoid[name] || RESERVED_WORDS[name]);
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
function rename(def) {
|
function rename(def) {
|
||||||
if (def.global || def.unmangleable(options)) return;
|
if (def.global && options.cache) return;
|
||||||
if (member(def.name, options.reserved)) return;
|
if (def.unmangleable(options)) return;
|
||||||
var d = def.redefined();
|
if (options.reserved.has[def.name]) return;
|
||||||
def.name = d ? d.name : prefix + def.id;
|
var redef = def.redefined();
|
||||||
|
var name = redef ? redef.rename || redef.name : next_name();
|
||||||
|
def.rename = name;
|
||||||
def.orig.forEach(function(sym) {
|
def.orig.forEach(function(sym) {
|
||||||
sym.name = def.name;
|
sym.name = name;
|
||||||
});
|
});
|
||||||
def.references.forEach(function(sym) {
|
def.references.forEach(function(sym) {
|
||||||
sym.name = def.name;
|
sym.name = name;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -620,8 +557,9 @@ 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 = this._default_mangler_options(options);
|
options = _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);
|
||||||
@@ -654,17 +592,21 @@ AST_Toplevel.DEFMETHOD("compute_char_frequency", function(options){
|
|||||||
});
|
});
|
||||||
|
|
||||||
var base54 = (function() {
|
var base54 = (function() {
|
||||||
var leading = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ$_".split("");
|
var freq = Object.create(null);
|
||||||
var digits = "0123456789".split("");
|
function init(chars) {
|
||||||
|
var array = [];
|
||||||
|
for (var i = 0; i < chars.length; 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(null);
|
frequency = Object.create(freq);
|
||||||
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;) {
|
||||||
@@ -675,7 +617,7 @@ var base54 = (function() {
|
|||||||
return frequency[b] - frequency[a];
|
return frequency[b] - frequency[a];
|
||||||
}
|
}
|
||||||
base54.sort = function() {
|
base54.sort = function() {
|
||||||
chars = mergeSort(leading, compare).concat(mergeSort(digits, compare));
|
chars = leading.sort(compare).concat(digits.sort(compare));
|
||||||
};
|
};
|
||||||
base54.reset = reset;
|
base54.reset = reset;
|
||||||
reset();
|
reset();
|
||||||
@@ -689,6 +631,6 @@ var base54 = (function() {
|
|||||||
base = 64;
|
base = 64;
|
||||||
} while (num > 0);
|
} while (num > 0);
|
||||||
return ret;
|
return ret;
|
||||||
};
|
}
|
||||||
return base54;
|
return base54;
|
||||||
})();
|
})();
|
||||||
|
|||||||
190
lib/sourcemap.js
190
lib/sourcemap.js
@@ -1,7 +1,7 @@
|
|||||||
/***********************************************************************
|
/***********************************************************************
|
||||||
|
|
||||||
A JavaScript tokenizer / parser / beautifier / compressor.
|
A JavaScript tokenizer / parser / beautifier / compressor.
|
||||||
https://github.com/mishoo/UglifyJS2
|
https://github.com/mishoo/UglifyJS
|
||||||
|
|
||||||
-------------------------------- (C) ---------------------------------
|
-------------------------------- (C) ---------------------------------
|
||||||
|
|
||||||
@@ -43,55 +43,149 @@
|
|||||||
|
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
// a small wrapper around fitzgen's source-map library
|
var vlq_char = characters("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/");
|
||||||
function SourceMap(options) {
|
var vlq_bits = vlq_char.reduce(function(map, ch, bits) {
|
||||||
options = defaults(options, {
|
map[ch] = bits;
|
||||||
file : null,
|
return map;
|
||||||
root : null,
|
}, Object.create(null));
|
||||||
orig : null,
|
|
||||||
|
|
||||||
orig_line_diff : 0,
|
function vlq_decode(indices, str) {
|
||||||
dest_line_diff : 0,
|
var value = 0;
|
||||||
});
|
var shift = 0;
|
||||||
var generator = new MOZ_SourceMap.SourceMapGenerator({
|
for (var i = 0, j = 0; i < str.length; i++) {
|
||||||
file : options.file,
|
var bits = vlq_bits[str[i]];
|
||||||
sourceRoot : options.root
|
value += (bits & 31) << shift;
|
||||||
});
|
if (bits & 32) {
|
||||||
var orig_map = options.orig && new MOZ_SourceMap.SourceMapConsumer(options.orig);
|
shift += 5;
|
||||||
|
} else {
|
||||||
if (orig_map && Array.isArray(options.orig.sources)) {
|
indices[j++] += value & 1 ? 0x80000000 | -(value >> 1) : value >> 1;
|
||||||
orig_map._sources.toArray().forEach(function(source) {
|
value = shift = 0;
|
||||||
var sourceContent = orig_map.sourceContentFor(source, true);
|
}
|
||||||
if (sourceContent) {
|
|
||||||
generator.setSourceContent(source, sourceContent);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
return j;
|
||||||
|
}
|
||||||
|
|
||||||
|
function vlq_encode(num) {
|
||||||
|
var result = "";
|
||||||
|
num = Math.abs(num) << 1 | num >>> 31;
|
||||||
|
do {
|
||||||
|
var bits = num & 31;
|
||||||
|
if (num >>>= 5) bits |= 32;
|
||||||
|
result += vlq_char[bits];
|
||||||
|
} while (num);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
function create_array_map() {
|
||||||
|
var map = Object.create(null);
|
||||||
|
var array = [];
|
||||||
|
array.index = function(name) {
|
||||||
|
if (!HOP(map, name)) {
|
||||||
|
map[name] = array.length;
|
||||||
|
array.push(name);
|
||||||
|
}
|
||||||
|
return map[name];
|
||||||
|
};
|
||||||
|
return array;
|
||||||
|
}
|
||||||
|
|
||||||
|
function SourceMap(options) {
|
||||||
|
var sources = create_array_map();
|
||||||
|
var sources_content = options.includeSources && Object.create(null);
|
||||||
|
var names = create_array_map();
|
||||||
|
var mappings = "";
|
||||||
|
if (options.orig) Object.keys(options.orig).forEach(function(name) {
|
||||||
|
var map = options.orig[name];
|
||||||
|
var indices = [ 0, 0, 1, 0, 0 ];
|
||||||
|
options.orig[name] = {
|
||||||
|
names: map.names,
|
||||||
|
mappings: map.mappings.split(/;/).map(function(line) {
|
||||||
|
indices[0] = 0;
|
||||||
|
return line.split(/,/).map(function(segment) {
|
||||||
|
return indices.slice(0, vlq_decode(indices, segment));
|
||||||
|
});
|
||||||
|
}),
|
||||||
|
sources: map.sources,
|
||||||
|
};
|
||||||
|
if (!sources_content || !map.sourcesContent) return;
|
||||||
|
for (var i = 0; i < map.sources.length; i++) {
|
||||||
|
var content = map.sourcesContent[i];
|
||||||
|
if (content) sources_content[map.sources[i]] = content;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
var prev_source;
|
||||||
|
var generated_line = 1;
|
||||||
|
var generated_column = 0;
|
||||||
|
var source_index = 0;
|
||||||
|
var original_line = 1;
|
||||||
|
var original_column = 0;
|
||||||
|
var name_index = 0;
|
||||||
|
return {
|
||||||
|
add: options.orig ? function(source, gen_line, gen_col, orig_line, orig_col, name) {
|
||||||
|
var map = options.orig[source];
|
||||||
|
if (map) {
|
||||||
|
var segments = map.mappings[orig_line - 1];
|
||||||
|
if (!segments) return;
|
||||||
|
var indices;
|
||||||
|
for (var i = 0; i < segments.length; i++) {
|
||||||
|
var col = segments[i][0];
|
||||||
|
if (orig_col >= col) indices = segments[i];
|
||||||
|
if (orig_col <= col) break;
|
||||||
|
}
|
||||||
|
if (!indices || indices.length < 4) {
|
||||||
|
source = null;
|
||||||
|
} else {
|
||||||
|
source = map.sources[indices[1]];
|
||||||
|
orig_line = indices[2];
|
||||||
|
orig_col = indices[3];
|
||||||
|
if (indices.length > 4) name = map.names[indices[4]];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
add(source, gen_line, gen_col, orig_line, orig_col, name);
|
||||||
|
} : add,
|
||||||
|
setSourceContent: sources_content ? function(source, content) {
|
||||||
|
sources_content[source] = content;
|
||||||
|
} : noop,
|
||||||
|
toString: function() {
|
||||||
|
return JSON.stringify({
|
||||||
|
version: 3,
|
||||||
|
file: options.filename || undefined,
|
||||||
|
sourceRoot: options.root || undefined,
|
||||||
|
sources: sources,
|
||||||
|
sourcesContent: sources_content ? sources.map(function(source) {
|
||||||
|
return sources_content[source] || null;
|
||||||
|
}) : undefined,
|
||||||
|
names: names,
|
||||||
|
mappings: mappings,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
function add(source, gen_line, gen_col, orig_line, orig_col, name) {
|
function add(source, gen_line, gen_col, orig_line, orig_col, name) {
|
||||||
if (orig_map) {
|
if (prev_source == null && source == null) return;
|
||||||
var info = orig_map.originalPositionFor({
|
prev_source = source;
|
||||||
line: orig_line,
|
if (generated_line < gen_line) {
|
||||||
column: orig_col
|
generated_column = 0;
|
||||||
});
|
do {
|
||||||
if (info.source === null) {
|
mappings += ";";
|
||||||
return;
|
} while (++generated_line < gen_line);
|
||||||
}
|
} else if (mappings) {
|
||||||
source = info.source;
|
mappings += ",";
|
||||||
orig_line = info.line;
|
|
||||||
orig_col = info.column;
|
|
||||||
name = info.name || name;
|
|
||||||
}
|
}
|
||||||
generator.addMapping({
|
mappings += vlq_encode(gen_col - generated_column);
|
||||||
generated : { line: gen_line + options.dest_line_diff, column: gen_col },
|
generated_column = gen_col;
|
||||||
original : { line: orig_line + options.orig_line_diff, column: orig_col },
|
if (source == null) return;
|
||||||
source : source,
|
var src_idx = sources.index(source);
|
||||||
name : name
|
mappings += vlq_encode(src_idx - source_index);
|
||||||
});
|
source_index = src_idx;
|
||||||
};
|
mappings += vlq_encode(orig_line - original_line);
|
||||||
return {
|
original_line = orig_line;
|
||||||
add : add,
|
mappings += vlq_encode(orig_col - original_column);
|
||||||
get : function() { return generator },
|
original_column = orig_col;
|
||||||
toString : function() { return JSON.stringify(generator.toJSON()); }
|
if (options.names && name != null) {
|
||||||
};
|
var name_idx = names.index(name);
|
||||||
};
|
mappings += vlq_encode(name_idx - name_index);
|
||||||
|
name_index = name_idx;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
193
lib/transform.js
193
lib/transform.js
@@ -1,7 +1,7 @@
|
|||||||
/***********************************************************************
|
/***********************************************************************
|
||||||
|
|
||||||
A JavaScript tokenizer / parser / beautifier / compressor.
|
A JavaScript tokenizer / parser / beautifier / compressor.
|
||||||
https://github.com/mishoo/UglifyJS2
|
https://github.com/mishoo/UglifyJS
|
||||||
|
|
||||||
-------------------------------- (C) ---------------------------------
|
-------------------------------- (C) ---------------------------------
|
||||||
|
|
||||||
@@ -43,8 +43,6 @@
|
|||||||
|
|
||||||
"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;
|
||||||
@@ -52,221 +50,136 @@ function TreeTransformer(before, after) {
|
|||||||
}
|
}
|
||||||
TreeTransformer.prototype = new TreeWalker;
|
TreeTransformer.prototype = new TreeWalker;
|
||||||
|
|
||||||
(function(undefined){
|
(function(DEF) {
|
||||||
|
|
||||||
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) {
|
|
||||||
if (!tw.after) {
|
|
||||||
x = this;
|
|
||||||
descend(x, tw);
|
|
||||||
} else {
|
|
||||||
tw.stack[tw.stack.length - 1] = x = this;
|
|
||||||
descend(x, tw);
|
|
||||||
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 List(list, function(node) {
|
||||||
return node.transform(tw, true);
|
return node.transform(tw, true);
|
||||||
});
|
});
|
||||||
};
|
}
|
||||||
|
|
||||||
_(AST_Node, noop);
|
DEF(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) {
|
||||||
_(AST_DWLoop, function(self, tw){
|
self.body = self.body.transform(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);
|
||||||
if (self.body instanceof AST_Node) {
|
self.body = do_list(self.body, tw);
|
||||||
self.body = self.body.transform(tw);
|
|
||||||
} else {
|
|
||||||
self.body = do_list(self.body, tw);
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
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) {
|
||||||
_(AST_Class, function(self, tw){
|
node.DEFMETHOD("transform", function(tw, in_list) {
|
||||||
if (self.name) self.name = self.name.transform(tw);
|
var x, y;
|
||||||
if (self.extends) self.extends = self.extends.transform(tw);
|
tw.push(this);
|
||||||
self.properties = do_list(self.properties, tw);
|
if (tw.before) x = tw.before(this, descend, in_list);
|
||||||
|
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);
|
|
||||||
});
|
|
||||||
|
|
||||||
})();
|
|
||||||
|
|||||||
233
lib/utils.js
233
lib/utils.js
@@ -1,7 +1,7 @@
|
|||||||
/***********************************************************************
|
/***********************************************************************
|
||||||
|
|
||||||
A JavaScript tokenizer / parser / beautifier / compressor.
|
A JavaScript tokenizer / parser / beautifier / compressor.
|
||||||
https://github.com/mishoo/UglifyJS2
|
https://github.com/mishoo/UglifyJS
|
||||||
|
|
||||||
-------------------------------- (C) ---------------------------------
|
-------------------------------- (C) ---------------------------------
|
||||||
|
|
||||||
@@ -43,33 +43,25 @@
|
|||||||
|
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
function slice(a, start) {
|
|
||||||
return Array.prototype.slice.call(a, start || 0);
|
|
||||||
};
|
|
||||||
|
|
||||||
function characters(str) {
|
function characters(str) {
|
||||||
return str.split("");
|
return str.split("");
|
||||||
};
|
}
|
||||||
|
|
||||||
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 = 0, n = array.length; i < n; ++i) {
|
for (var i = array.length; --i >= 0;) if (func(array[i])) return array[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;
|
||||||
if (i & 1) d += str;
|
return i & 1 ? d + str : d;
|
||||||
return d;
|
}
|
||||||
};
|
|
||||||
|
|
||||||
function configure_error_stack(fn) {
|
function configure_error_stack(fn) {
|
||||||
Object.defineProperty(fn.prototype, "stack", {
|
Object.defineProperty(fn.prototype, "stack", {
|
||||||
@@ -78,7 +70,7 @@ function configure_error_stack(fn) {
|
|||||||
err.name = this.name;
|
err.name = this.name;
|
||||||
try {
|
try {
|
||||||
throw err;
|
throw err;
|
||||||
} catch(e) {
|
} catch (e) {
|
||||||
return e.stack;
|
return e.stack;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -88,27 +80,21 @@ 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)
|
if (croak) for (var i in args) {
|
||||||
args = {};
|
if (HOP(args, i) && !HOP(defs, i)) throw new DefaultsError("`" + i + "` is not a supported option", defs);
|
||||||
var ret = args || {};
|
|
||||||
if (croak) for (var i in ret) if (HOP(ret, i) && !HOP(defs, i))
|
|
||||||
DefaultsError.croak("`" + i + "` is not a supported option", defs);
|
|
||||||
for (var i in defs) if (HOP(defs, i)) {
|
|
||||||
ret[i] = (args && HOP(args, i)) ? args[i] : defs[i];
|
|
||||||
}
|
}
|
||||||
return ret;
|
for (var i in args) {
|
||||||
};
|
if (HOP(args, i)) defs[i] = args[i];
|
||||||
|
}
|
||||||
|
return defs;
|
||||||
|
}
|
||||||
|
|
||||||
function merge(obj, ext) {
|
function merge(obj, ext) {
|
||||||
var count = 0;
|
var count = 0;
|
||||||
@@ -117,7 +103,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; }
|
||||||
@@ -125,8 +111,8 @@ 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 List = (function() {
|
||||||
function MAP(a, f, backwards) {
|
function List(a, f, backwards) {
|
||||||
var ret = [], top = [], i;
|
var ret = [], top = [], i;
|
||||||
function doit() {
|
function doit() {
|
||||||
var val = f(a[i], i);
|
var val = f(a[i], i);
|
||||||
@@ -139,8 +125,7 @@ var MAP = (function(){
|
|||||||
} else {
|
} else {
|
||||||
top.push(val);
|
top.push(val);
|
||||||
}
|
}
|
||||||
}
|
} else if (val !== skip) {
|
||||||
else if (val !== skip) {
|
|
||||||
if (val instanceof Splice) {
|
if (val instanceof Splice) {
|
||||||
ret.push.apply(ret, backwards ? val.v.slice().reverse() : val.v);
|
ret.push.apply(ret, backwards ? val.v.slice().reverse() : val.v);
|
||||||
} else {
|
} else {
|
||||||
@@ -148,8 +133,8 @@ var MAP = (function(){
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
return is_last;
|
return is_last;
|
||||||
};
|
}
|
||||||
if (a instanceof Array) {
|
if (Array.isArray(a)) {
|
||||||
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();
|
||||||
@@ -157,132 +142,59 @@ var MAP = (function(){
|
|||||||
} else {
|
} else {
|
||||||
for (i = 0; i < a.length; ++i) if (doit()) break;
|
for (i = 0; i < a.length; ++i) if (doit()) break;
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
for (i in a) if (HOP(a, i)) if (doit()) break;
|
for (i in a) if (HOP(a, i)) if (doit()) break;
|
||||||
}
|
}
|
||||||
return top.concat(ret);
|
return top.concat(ret);
|
||||||
|
}
|
||||||
|
List.is_op = function(val) {
|
||||||
|
return val === skip || val instanceof AtTop || val instanceof Last || val instanceof Splice;
|
||||||
};
|
};
|
||||||
MAP.at_top = function(val) { return new AtTop(val) };
|
List.at_top = function(val) { return new AtTop(val); };
|
||||||
MAP.splice = function(val) { return new Splice(val) };
|
List.splice = function(val) { return new Splice(val); };
|
||||||
MAP.last = function(val) { return new Last(val) };
|
List.last = function(val) { return new Last(val); };
|
||||||
var skip = MAP.skip = {};
|
var skip = List.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 List;
|
||||||
})();
|
})();
|
||||||
|
|
||||||
function push_uniq(array, el) {
|
function push_uniq(array, el) {
|
||||||
if (array.indexOf(el) < 0)
|
if (array.indexOf(el) < 0) return array.push(el);
|
||||||
array.push(el);
|
}
|
||||||
};
|
|
||||||
|
|
||||||
function string_template(text, props) {
|
function string_template(text, props) {
|
||||||
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;) {
|
var index = array.indexOf(el);
|
||||||
if (array[i] === el) array.splice(i, 1);
|
if (index >= 0) array.splice(index, 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);
|
|
||||||
};
|
|
||||||
|
|
||||||
function set_difference(a, b) {
|
|
||||||
return a.filter(function(el){
|
|
||||||
return b.indexOf(el) < 0;
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
function set_intersection(a, b) {
|
|
||||||
return a.filter(function(el){
|
|
||||||
return b.indexOf(el) >= 0;
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
// this function is taken from Acorn [1], written by Marijn Haverbeke
|
|
||||||
// [1] https://github.com/marijnh/acorn
|
|
||||||
function makePredicate(words) {
|
function makePredicate(words) {
|
||||||
if (!(words instanceof Array)) words = words.split(" ");
|
if (!Array.isArray(words)) words = words.split(" ");
|
||||||
var f = "", cats = [];
|
var map = Object.create(null);
|
||||||
out: for (var i = 0; i < words.length; ++i) {
|
words.forEach(function(word) {
|
||||||
for (var j = 0; j < cats.length; ++j)
|
map[word] = true;
|
||||||
if (cats[j][0].length == words[i].length) {
|
});
|
||||||
cats[j].push(words[i]);
|
return map;
|
||||||
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], 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;
|
||||||
@@ -306,6 +218,12 @@ Dictionary.prototype = {
|
|||||||
return this;
|
return this;
|
||||||
},
|
},
|
||||||
has: function(key) { return ("$" + key) in this._values },
|
has: function(key) { return ("$" + key) in this._values },
|
||||||
|
all: function(predicate) {
|
||||||
|
for (var i in this._values)
|
||||||
|
if (!predicate(this._values[i], i.substr(1)))
|
||||||
|
return false;
|
||||||
|
return true;
|
||||||
|
},
|
||||||
each: function(f) {
|
each: function(f) {
|
||||||
for (var i in this._values)
|
for (var i in this._values)
|
||||||
f(this._values[i], i.substr(1));
|
f(this._values[i], i.substr(1));
|
||||||
@@ -319,6 +237,13 @@ Dictionary.prototype = {
|
|||||||
ret.push(f(this._values[i], i.substr(1)));
|
ret.push(f(this._values[i], i.substr(1)));
|
||||||
return ret;
|
return ret;
|
||||||
},
|
},
|
||||||
|
clone: function() {
|
||||||
|
var ret = new Dictionary();
|
||||||
|
for (var i in this._values)
|
||||||
|
ret._values[i] = this._values[i];
|
||||||
|
ret._size = this._size;
|
||||||
|
return ret;
|
||||||
|
},
|
||||||
toObject: function() { return this._values }
|
toObject: function() { return this._values }
|
||||||
};
|
};
|
||||||
Dictionary.fromObject = function(obj) {
|
Dictionary.fromObject = function(obj) {
|
||||||
@@ -336,20 +261,22 @@ 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); i++) {
|
for (var i = 0, p; p = stack.parent(i++); node = p) {
|
||||||
if (p instanceof AST_Statement && p.body === node)
|
if (p.TYPE == "Call") {
|
||||||
return true;
|
if (p.expression === node) continue;
|
||||||
if ((p instanceof AST_Sequence && p.expressions[0] === node) ||
|
} else if (p instanceof AST_Binary) {
|
||||||
(p instanceof AST_Call && p.expression === node && !(p instanceof AST_New) ) ||
|
if (p.left === node) continue;
|
||||||
(p instanceof AST_Dot && p.expression === node ) ||
|
} else if (p instanceof AST_Conditional) {
|
||||||
(p instanceof AST_Sub && p.expression === node ) ||
|
if (p.condition === node) continue;
|
||||||
(p instanceof AST_Conditional && p.condition === node ) ||
|
} else if (p instanceof AST_PropAccess) {
|
||||||
(p instanceof AST_Binary && p.left === node ) ||
|
if (p.expression === node) continue;
|
||||||
(p instanceof AST_UnaryPostfix && p.expression === node ))
|
} else if (p instanceof AST_Sequence) {
|
||||||
{
|
if (p.expressions[0] === node) continue;
|
||||||
node = p;
|
} else if (p instanceof AST_Statement) {
|
||||||
} else {
|
return p.body === node;
|
||||||
return false;
|
} else if (p instanceof AST_UnaryPostfix) {
|
||||||
|
if (p.expression === node) continue;
|
||||||
}
|
}
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
57
package.json
57
package.json
@@ -1,20 +1,17 @@
|
|||||||
{
|
{
|
||||||
"name": "uglify-es",
|
"name": "uglify-js",
|
||||||
"description": "JavaScript parser, mangler/compressor and beautifier toolkit for ES6+",
|
"description": "JavaScript parser, mangler/compressor and beautifier toolkit",
|
||||||
"homepage": "https://github.com/mishoo/UglifyJS2/tree/harmony",
|
|
||||||
"author": "Mihai Bazon <mihai.bazon@gmail.com> (http://lisperator.net/)",
|
"author": "Mihai Bazon <mihai.bazon@gmail.com> (http://lisperator.net/)",
|
||||||
"license": "BSD-2-Clause",
|
"license": "BSD-2-Clause",
|
||||||
"version": "3.2.1",
|
"version": "3.9.4",
|
||||||
"engines": {
|
"engines": {
|
||||||
"node": ">=0.8.0"
|
"node": ">=0.8.0"
|
||||||
},
|
},
|
||||||
"maintainers": [
|
"maintainers": [
|
||||||
|
"Alex Lam <alexlamsl@gmail.com>",
|
||||||
"Mihai Bazon <mihai.bazon@gmail.com> (http://lisperator.net/)"
|
"Mihai Bazon <mihai.bazon@gmail.com> (http://lisperator.net/)"
|
||||||
],
|
],
|
||||||
"repository": "git+https://github.com/mishoo/UglifyJS2.git#harmony",
|
"repository": "mishoo/UglifyJS",
|
||||||
"bugs": {
|
|
||||||
"url": "https://github.com/mishoo/UglifyJS2/issues"
|
|
||||||
},
|
|
||||||
"main": "tools/node.js",
|
"main": "tools/node.js",
|
||||||
"bin": {
|
"bin": {
|
||||||
"uglifyjs": "bin/uglifyjs"
|
"uglifyjs": "bin/uglifyjs"
|
||||||
@@ -26,33 +23,37 @@
|
|||||||
"LICENSE"
|
"LICENSE"
|
||||||
],
|
],
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"commander": "~2.12.1",
|
"commander": "~2.20.3"
|
||||||
"source-map": "~0.6.1"
|
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"acorn": "~5.2.1",
|
"acorn": "~7.1.0",
|
||||||
"mocha": "~3.5.1",
|
"semver": "~6.3.0"
|
||||||
"semver": "~5.4.1"
|
|
||||||
},
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"test": "node test/run-tests.js"
|
"test": "node test/compress.js && node test/mocha.js"
|
||||||
},
|
},
|
||||||
"keywords": [
|
"keywords": [
|
||||||
"uglify",
|
"cli",
|
||||||
"uglify-es",
|
"compress",
|
||||||
"uglify-js",
|
"compressor",
|
||||||
"minify",
|
"ecma",
|
||||||
"minifier",
|
|
||||||
"javascript",
|
|
||||||
"ecmascript",
|
"ecmascript",
|
||||||
|
"es",
|
||||||
"es5",
|
"es5",
|
||||||
"es6",
|
"javascript",
|
||||||
"es7",
|
"js",
|
||||||
"es8",
|
"jsmin",
|
||||||
"es2015",
|
"min",
|
||||||
"es2016",
|
"minification",
|
||||||
"es2017",
|
"minifier",
|
||||||
"async",
|
"minify",
|
||||||
"await"
|
"optimize",
|
||||||
|
"optimizer",
|
||||||
|
"pack",
|
||||||
|
"packer",
|
||||||
|
"parse",
|
||||||
|
"parser",
|
||||||
|
"uglifier",
|
||||||
|
"uglify"
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,28 +5,29 @@
|
|||||||
|
|
||||||
var createHash = require("crypto").createHash;
|
var createHash = require("crypto").createHash;
|
||||||
var fetch = require("./fetch");
|
var fetch = require("./fetch");
|
||||||
var fork = require("child_process").fork;
|
var spawn = require("child_process").spawn;
|
||||||
var zlib = require("zlib");
|
var zlib = require("zlib");
|
||||||
var args = process.argv.slice(2);
|
var args = process.argv.slice(2);
|
||||||
if (!args.length) {
|
if (!args.length) args.push("-mc");
|
||||||
args.push("-mc");
|
args.unshift("bin/uglifyjs");
|
||||||
}
|
|
||||||
args.push("--timings");
|
args.push("--timings");
|
||||||
var urls = [
|
var urls = [
|
||||||
"https://code.jquery.com/jquery-3.2.1.js",
|
"https://code.jquery.com/jquery-3.4.1.js",
|
||||||
"https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.6.4/angular.js",
|
"https://code.angularjs.org/1.7.8/angular.js",
|
||||||
"https://cdnjs.cloudflare.com/ajax/libs/mathjs/3.9.0/math.js",
|
"https://unpkg.com/mathjs@6.2.3/dist/math.js",
|
||||||
"https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.js",
|
|
||||||
"https://unpkg.com/react@15.3.2/dist/react.js",
|
"https://unpkg.com/react@15.3.2/dist/react.js",
|
||||||
"http://builds.emberjs.com/tags/v2.11.0/ember.prod.js",
|
"https://cdnjs.cloudflare.com/ajax/libs/d3/5.12.0/d3.js",
|
||||||
"https://cdn.jsdelivr.net/lodash/4.17.4/lodash.js",
|
"https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.js",
|
||||||
"https://cdnjs.cloudflare.com/ajax/libs/d3/4.5.0/d3.js",
|
"https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.15/lodash.js",
|
||||||
|
"https://cdnjs.cloudflare.com/ajax/libs/ember.js/2.12.2/ember.prod.js",
|
||||||
|
"https://raw.githubusercontent.com/kangax/html-minifier/v4.0.0/dist/htmlminifier.js",
|
||||||
];
|
];
|
||||||
var results = {};
|
var results = {};
|
||||||
var remaining = 2 * urls.length;
|
var remaining = 2 * urls.length;
|
||||||
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();
|
||||||
@@ -39,6 +40,9 @@ 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:");
|
||||||
@@ -46,6 +50,13 @@ 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");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -58,18 +69,20 @@ urls.forEach(function(url) {
|
|||||||
};
|
};
|
||||||
fetch(url, function(err, res) {
|
fetch(url, function(err, res) {
|
||||||
if (err) throw err;
|
if (err) throw err;
|
||||||
var uglifyjs = fork("bin/uglifyjs", args, { silent: true });
|
var uglifyjs = spawn(process.argv[0], args, { silent: true });
|
||||||
res.on("data", function(data) {
|
res.on("data", function(data) {
|
||||||
results[url].input += data.length;
|
results[url].input += data.length;
|
||||||
}).pipe(uglifyjs.stdin);
|
}).pipe(uglifyjs.stdin);
|
||||||
|
var sha1 = createHash("sha1");
|
||||||
uglifyjs.stdout.on("data", function(data) {
|
uglifyjs.stdout.on("data", function(data) {
|
||||||
results[url].output += data.length;
|
results[url].output += data.length;
|
||||||
}).pipe(zlib.createGzip({
|
}).pipe(zlib.createGzip({
|
||||||
level: zlib.Z_BEST_COMPRESSION
|
level: zlib.Z_BEST_COMPRESSION
|
||||||
})).on("data", function(data) {
|
})).on("data", function(data) {
|
||||||
results[url].gzip += data.length;
|
results[url].gzip += data.length;
|
||||||
}).pipe(createHash("sha1")).on("data", function(data) {
|
sha1.update(data);
|
||||||
results[url].sha1 = data.toString("hex");
|
}).on("end", function() {
|
||||||
|
results[url].sha1 = sha1.digest("hex");
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
uglifyjs.stderr.setEncoding("utf8");
|
uglifyjs.stderr.setEncoding("utf8");
|
||||||
|
|||||||
460
test/compress.js
Normal file
460
test/compress.js
Normal file
@@ -0,0 +1,460 @@
|
|||||||
|
"use strict";
|
||||||
|
|
||||||
|
require("../tools/exit");
|
||||||
|
|
||||||
|
var assert = require("assert");
|
||||||
|
var child_process = require("child_process");
|
||||||
|
var fs = require("fs");
|
||||||
|
var path = require("path");
|
||||||
|
var sandbox = require("./sandbox");
|
||||||
|
var semver = require("semver");
|
||||||
|
var U = require("./node");
|
||||||
|
|
||||||
|
var file = process.argv[2];
|
||||||
|
var dir = path.resolve(path.dirname(module.filename), "compress");
|
||||||
|
if (file) {
|
||||||
|
var minify_options = require("./ufuzz/options.json").map(JSON.stringify);
|
||||||
|
log("--- {file}", { file: file });
|
||||||
|
var tests = parse_test(path.resolve(dir, file));
|
||||||
|
process.exit(Object.keys(tests).filter(function(name) {
|
||||||
|
return !test_case(tests[name]);
|
||||||
|
}).length);
|
||||||
|
} else {
|
||||||
|
var files = fs.readdirSync(dir).filter(function(name) {
|
||||||
|
return /\.js$/i.test(name);
|
||||||
|
});
|
||||||
|
var failures = 0;
|
||||||
|
var failed_files = Object.create(null);
|
||||||
|
(function next() {
|
||||||
|
var file = files.shift();
|
||||||
|
if (file) {
|
||||||
|
child_process.spawn(process.argv[0], [ process.argv[1], file ], {
|
||||||
|
stdio: [ "ignore", 1, 2 ]
|
||||||
|
}).on("exit", function(code) {
|
||||||
|
if (code) {
|
||||||
|
failures += code;
|
||||||
|
failed_files[file] = code;
|
||||||
|
}
|
||||||
|
next();
|
||||||
|
});
|
||||||
|
} else if (failures) {
|
||||||
|
console.error();
|
||||||
|
console.error("!!! Failed " + failures + " test case(s).");
|
||||||
|
console.error("!!! " + Object.keys(failed_files).join(", "));
|
||||||
|
process.exit(1);
|
||||||
|
}
|
||||||
|
})();
|
||||||
|
}
|
||||||
|
|
||||||
|
function evaluate(code) {
|
||||||
|
if (code instanceof U.AST_Node) code = make_code(code, { beautify: true });
|
||||||
|
return new Function("return(" + code + ")")();
|
||||||
|
}
|
||||||
|
|
||||||
|
function log() {
|
||||||
|
console.log("%s", tmpl.apply(null, arguments));
|
||||||
|
}
|
||||||
|
|
||||||
|
function make_code(ast, options) {
|
||||||
|
var stream = U.OutputStream(options);
|
||||||
|
ast.print(stream);
|
||||||
|
return stream.get();
|
||||||
|
}
|
||||||
|
|
||||||
|
function parse_test(file) {
|
||||||
|
var script = fs.readFileSync(file, "utf8");
|
||||||
|
// TODO try/catch can be removed after fixing https://github.com/mishoo/UglifyJS/issues/348
|
||||||
|
try {
|
||||||
|
var ast = U.parse(script, {
|
||||||
|
filename: file
|
||||||
|
});
|
||||||
|
} catch (e) {
|
||||||
|
console.error("Caught error while parsing tests in " + file);
|
||||||
|
console.error(e);
|
||||||
|
process.exit(1);
|
||||||
|
}
|
||||||
|
var tests = Object.create(null);
|
||||||
|
var tw = new U.TreeWalker(function(node, descend) {
|
||||||
|
if (node instanceof U.AST_LabeledStatement
|
||||||
|
&& tw.parent() instanceof U.AST_Toplevel) {
|
||||||
|
var name = node.label.name;
|
||||||
|
if (name in tests) {
|
||||||
|
throw new Error('Duplicated test name "' + name + '" in ' + file);
|
||||||
|
}
|
||||||
|
tests[name] = get_one_test(name, node.body);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (!(node instanceof U.AST_Toplevel)) croak(node);
|
||||||
|
});
|
||||||
|
ast.walk(tw);
|
||||||
|
return tests;
|
||||||
|
|
||||||
|
function croak(node) {
|
||||||
|
throw new Error(tmpl("Can't understand test file {file} [{line},{col}]\n{code}", {
|
||||||
|
file: file,
|
||||||
|
line: node.start.line,
|
||||||
|
col: node.start.col,
|
||||||
|
code: make_code(node, { beautify: false })
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
|
||||||
|
function read_string(stat) {
|
||||||
|
if (stat.TYPE == "SimpleStatement") {
|
||||||
|
var body = stat.body;
|
||||||
|
switch(body.TYPE) {
|
||||||
|
case "String":
|
||||||
|
return body.value;
|
||||||
|
case "Array":
|
||||||
|
return body.elements.map(function(element) {
|
||||||
|
if (element.TYPE !== "String")
|
||||||
|
throw new Error("Should be array of strings");
|
||||||
|
return element.value;
|
||||||
|
}).join("\n");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
throw new Error("Should be string or array of strings");
|
||||||
|
}
|
||||||
|
|
||||||
|
function get_one_test(name, block) {
|
||||||
|
var test = { name: name, options: {} };
|
||||||
|
var tw = new U.TreeWalker(function(node, descend) {
|
||||||
|
if (node instanceof U.AST_Assign) {
|
||||||
|
if (!(node.left instanceof U.AST_SymbolRef)) {
|
||||||
|
croak(node);
|
||||||
|
}
|
||||||
|
var name = node.left.name;
|
||||||
|
test[name] = evaluate(node.right);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (node instanceof U.AST_LabeledStatement) {
|
||||||
|
var label = node.label;
|
||||||
|
assert.ok([
|
||||||
|
"input",
|
||||||
|
"expect",
|
||||||
|
"expect_exact",
|
||||||
|
"expect_warnings",
|
||||||
|
"expect_stdout",
|
||||||
|
"node_version",
|
||||||
|
].indexOf(label.name) >= 0, tmpl("Unsupported label {name} [{line},{col}]", {
|
||||||
|
name: label.name,
|
||||||
|
line: label.start.line,
|
||||||
|
col: label.start.col
|
||||||
|
}));
|
||||||
|
var stat = node.body;
|
||||||
|
if (label.name == "expect_exact" || label.name == "node_version") {
|
||||||
|
test[label.name] = read_string(stat);
|
||||||
|
} else if (label.name == "expect_stdout") {
|
||||||
|
var body = stat.body;
|
||||||
|
if (body instanceof U.AST_Boolean) {
|
||||||
|
test[label.name] = body.value;
|
||||||
|
} else if (body instanceof U.AST_Call) {
|
||||||
|
var ctor = global[body.expression.name];
|
||||||
|
assert.ok(ctor === Error || ctor.prototype instanceof Error, tmpl("Unsupported expect_stdout format [{line},{col}]", {
|
||||||
|
line: label.start.line,
|
||||||
|
col: label.start.col
|
||||||
|
}));
|
||||||
|
test[label.name] = ctor.apply(null, body.args.map(function(node) {
|
||||||
|
assert.ok(node instanceof U.AST_Constant, tmpl("Unsupported expect_stdout format [{line},{col}]", {
|
||||||
|
line: label.start.line,
|
||||||
|
col: label.start.col
|
||||||
|
}));
|
||||||
|
return node.value;
|
||||||
|
}));
|
||||||
|
} else {
|
||||||
|
test[label.name] = read_string(stat) + "\n";
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
test[label.name] = stat;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
block.walk(tw);
|
||||||
|
return test;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Try to reminify original input with standard options
|
||||||
|
// to see if it matches expect_stdout.
|
||||||
|
function reminify(orig_options, input_code, input_formatted, stdout) {
|
||||||
|
for (var i = 0; i < minify_options.length; i++) {
|
||||||
|
var options = JSON.parse(minify_options[i]);
|
||||||
|
if (options.compress) [
|
||||||
|
"keep_fargs",
|
||||||
|
"keep_fnames",
|
||||||
|
].forEach(function(name) {
|
||||||
|
if (name in orig_options) {
|
||||||
|
options.compress[name] = orig_options[name];
|
||||||
|
}
|
||||||
|
});
|
||||||
|
var options_formatted = JSON.stringify(options, null, 4);
|
||||||
|
options.validate = true;
|
||||||
|
var result = U.minify(input_code, options);
|
||||||
|
if (result.error) {
|
||||||
|
log([
|
||||||
|
"!!! failed input reminify",
|
||||||
|
"---INPUT---",
|
||||||
|
"{input}",
|
||||||
|
"---OPTIONS---",
|
||||||
|
"{options}",
|
||||||
|
"--ERROR---",
|
||||||
|
"{error}",
|
||||||
|
"",
|
||||||
|
"",
|
||||||
|
].join("\n"), {
|
||||||
|
input: input_formatted,
|
||||||
|
options: options_formatted,
|
||||||
|
error: result.error,
|
||||||
|
});
|
||||||
|
return false;
|
||||||
|
} else {
|
||||||
|
var toplevel = sandbox.has_toplevel(options);
|
||||||
|
var expected = stdout[toplevel ? 1 : 0];
|
||||||
|
var actual = run_code(result.code, toplevel);
|
||||||
|
if (typeof expected != "string" && typeof actual != "string" && expected.name == actual.name) {
|
||||||
|
actual = expected;
|
||||||
|
}
|
||||||
|
if (!sandbox.same_stdout(expected, actual)) {
|
||||||
|
log([
|
||||||
|
"!!! failed running reminified input",
|
||||||
|
"---INPUT---",
|
||||||
|
"{input}",
|
||||||
|
"---OPTIONS---",
|
||||||
|
"{options}",
|
||||||
|
"---OUTPUT---",
|
||||||
|
"{output}",
|
||||||
|
"---EXPECTED {expected_type}---",
|
||||||
|
"{expected}",
|
||||||
|
"---ACTUAL {actual_type}---",
|
||||||
|
"{actual}",
|
||||||
|
"",
|
||||||
|
"",
|
||||||
|
].join("\n"), {
|
||||||
|
input: input_formatted,
|
||||||
|
options: options_formatted,
|
||||||
|
output: result.code,
|
||||||
|
expected_type: typeof expected == "string" ? "STDOUT" : "ERROR",
|
||||||
|
expected: expected,
|
||||||
|
actual_type: typeof actual == "string" ? "STDOUT" : "ERROR",
|
||||||
|
actual: actual,
|
||||||
|
});
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
function run_code(code, toplevel) {
|
||||||
|
var result = sandbox.run_code(code, toplevel);
|
||||||
|
return typeof result == "string" ? result.replace(/\u001b\[\d+m/g, "") : result;
|
||||||
|
}
|
||||||
|
|
||||||
|
function test_case(test) {
|
||||||
|
log(" Running test [{name}]", { name: test.name });
|
||||||
|
U.AST_Node.enable_validation();
|
||||||
|
var output_options = test.beautify || {};
|
||||||
|
var expect;
|
||||||
|
if (test.expect) {
|
||||||
|
expect = make_code(to_toplevel(test.expect, test.mangle), output_options);
|
||||||
|
} else {
|
||||||
|
expect = test.expect_exact;
|
||||||
|
}
|
||||||
|
var input = to_toplevel(test.input, test.mangle);
|
||||||
|
var input_code = make_code(input);
|
||||||
|
var input_formatted = make_code(test.input, {
|
||||||
|
beautify: true,
|
||||||
|
comments: "all",
|
||||||
|
keep_quoted_props: true,
|
||||||
|
quote_style: 3,
|
||||||
|
});
|
||||||
|
try {
|
||||||
|
U.parse(input_code);
|
||||||
|
} catch (ex) {
|
||||||
|
log([
|
||||||
|
"!!! Cannot parse input",
|
||||||
|
"---INPUT---",
|
||||||
|
"{input}",
|
||||||
|
"--PARSE ERROR--",
|
||||||
|
"{error}",
|
||||||
|
"",
|
||||||
|
"",
|
||||||
|
].join("\n"), {
|
||||||
|
input: input_formatted,
|
||||||
|
error: ex,
|
||||||
|
});
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
var warnings_emitted = [];
|
||||||
|
if (test.expect_warnings) {
|
||||||
|
var expected_warnings = make_code(test.expect_warnings, {
|
||||||
|
beautify: false,
|
||||||
|
quote_style: 2, // force double quote to match JSON
|
||||||
|
});
|
||||||
|
U.AST_Node.log_function(function(text) {
|
||||||
|
warnings_emitted.push(text);
|
||||||
|
}, /"INFO: /.test(expected_warnings));
|
||||||
|
}
|
||||||
|
if (test.mangle && test.mangle.properties && test.mangle.properties.keep_quoted) {
|
||||||
|
var quoted_props = test.mangle.properties.reserved;
|
||||||
|
if (!Array.isArray(quoted_props)) quoted_props = [];
|
||||||
|
test.mangle.properties.reserved = quoted_props;
|
||||||
|
U.reserve_quoted_keys(input, quoted_props);
|
||||||
|
}
|
||||||
|
if (test.rename) {
|
||||||
|
input.figure_out_scope(test.mangle);
|
||||||
|
input.expand_names(test.mangle);
|
||||||
|
}
|
||||||
|
var cmp = new U.Compressor(test.options, true);
|
||||||
|
var output = cmp.compress(input);
|
||||||
|
output.figure_out_scope(test.mangle);
|
||||||
|
if (test.mangle) {
|
||||||
|
output.compute_char_frequency(test.mangle);
|
||||||
|
output.mangle_names(test.mangle);
|
||||||
|
if (test.mangle.properties) {
|
||||||
|
output = U.mangle_properties(output, test.mangle.properties);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
output = make_code(output, output_options);
|
||||||
|
if (expect != output) {
|
||||||
|
log([
|
||||||
|
"!!! failed",
|
||||||
|
"---INPUT---",
|
||||||
|
"{input}",
|
||||||
|
"---OUTPUT---",
|
||||||
|
"{output}",
|
||||||
|
"---EXPECTED---",
|
||||||
|
"{expected}",
|
||||||
|
"",
|
||||||
|
"",
|
||||||
|
].join("\n"), {
|
||||||
|
input: input_formatted,
|
||||||
|
output: output,
|
||||||
|
expected: expect
|
||||||
|
});
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
// expect == output
|
||||||
|
try {
|
||||||
|
U.parse(output);
|
||||||
|
} catch (ex) {
|
||||||
|
log([
|
||||||
|
"!!! Test matched expected result but cannot parse output",
|
||||||
|
"---INPUT---",
|
||||||
|
"{input}",
|
||||||
|
"---OUTPUT---",
|
||||||
|
"{output}",
|
||||||
|
"--REPARSE ERROR--",
|
||||||
|
"{error}",
|
||||||
|
"",
|
||||||
|
"",
|
||||||
|
].join("\n"), {
|
||||||
|
input: input_formatted,
|
||||||
|
output: output,
|
||||||
|
error: ex,
|
||||||
|
});
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (test.expect_warnings) {
|
||||||
|
warnings_emitted = warnings_emitted.map(function(input) {
|
||||||
|
return input.split(process.cwd() + path.sep).join("").split(path.sep).join("/");
|
||||||
|
});
|
||||||
|
var actual_warnings = JSON.stringify(warnings_emitted);
|
||||||
|
if (expected_warnings != actual_warnings) {
|
||||||
|
log([
|
||||||
|
"!!! failed",
|
||||||
|
"---INPUT---",
|
||||||
|
"{input}",
|
||||||
|
"---EXPECTED WARNINGS---",
|
||||||
|
"{expected_warnings}",
|
||||||
|
"---ACTUAL WARNINGS---",
|
||||||
|
"{actual_warnings}",
|
||||||
|
"",
|
||||||
|
"",
|
||||||
|
].join("\n"), {
|
||||||
|
input: input_formatted,
|
||||||
|
expected_warnings: expected_warnings,
|
||||||
|
actual_warnings: actual_warnings,
|
||||||
|
});
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (test.expect_stdout && (!test.node_version || semver.satisfies(process.version, test.node_version))) {
|
||||||
|
var stdout = [ run_code(input_code), run_code(input_code, true) ];
|
||||||
|
var toplevel = sandbox.has_toplevel({
|
||||||
|
compress: test.options,
|
||||||
|
mangle: test.mangle
|
||||||
|
});
|
||||||
|
var actual = stdout[toplevel ? 1 : 0];
|
||||||
|
if (test.expect_stdout === true) {
|
||||||
|
test.expect_stdout = actual;
|
||||||
|
}
|
||||||
|
if (!sandbox.same_stdout(test.expect_stdout, actual)) {
|
||||||
|
log([
|
||||||
|
"!!! Invalid input or expected stdout",
|
||||||
|
"---INPUT---",
|
||||||
|
"{input}",
|
||||||
|
"---EXPECTED {expected_type}---",
|
||||||
|
"{expected}",
|
||||||
|
"---ACTUAL {actual_type}---",
|
||||||
|
"{actual}",
|
||||||
|
"",
|
||||||
|
"",
|
||||||
|
].join("\n"), {
|
||||||
|
input: input_formatted,
|
||||||
|
expected_type: typeof test.expect_stdout == "string" ? "STDOUT" : "ERROR",
|
||||||
|
expected: test.expect_stdout,
|
||||||
|
actual_type: typeof actual == "string" ? "STDOUT" : "ERROR",
|
||||||
|
actual: actual,
|
||||||
|
});
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
actual = run_code(output, toplevel);
|
||||||
|
if (!sandbox.same_stdout(test.expect_stdout, actual)) {
|
||||||
|
log([
|
||||||
|
"!!! failed",
|
||||||
|
"---INPUT---",
|
||||||
|
"{input}",
|
||||||
|
"---EXPECTED {expected_type}---",
|
||||||
|
"{expected}",
|
||||||
|
"---ACTUAL {actual_type}---",
|
||||||
|
"{actual}",
|
||||||
|
"",
|
||||||
|
"",
|
||||||
|
].join("\n"), {
|
||||||
|
input: input_formatted,
|
||||||
|
expected_type: typeof test.expect_stdout == "string" ? "STDOUT" : "ERROR",
|
||||||
|
expected: test.expect_stdout,
|
||||||
|
actual_type: typeof actual == "string" ? "STDOUT" : "ERROR",
|
||||||
|
actual: actual,
|
||||||
|
});
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (!reminify(test.options, input_code, input_formatted, stdout)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
function tmpl() {
|
||||||
|
return U.string_template.apply(null, arguments);
|
||||||
|
}
|
||||||
|
|
||||||
|
function to_toplevel(input, mangle_options) {
|
||||||
|
if (!(input instanceof U.AST_BlockStatement)) throw new Error("Unsupported input syntax");
|
||||||
|
var directive = true;
|
||||||
|
var offset = input.start.line;
|
||||||
|
var tokens = [];
|
||||||
|
var toplevel = new U.AST_Toplevel(input.transform(new U.TreeTransformer(function(node) {
|
||||||
|
if (U.push_uniq(tokens, node.start)) node.start.line -= offset;
|
||||||
|
if (!directive || node === input) return;
|
||||||
|
if (node instanceof U.AST_SimpleStatement && node.body instanceof U.AST_String) {
|
||||||
|
return new U.AST_Directive(node.body);
|
||||||
|
} else {
|
||||||
|
directive = false;
|
||||||
|
}
|
||||||
|
})));
|
||||||
|
toplevel.figure_out_scope(mangle_options);
|
||||||
|
return toplevel;
|
||||||
|
}
|
||||||
778
test/compress/arguments.js
Normal file
778
test/compress/arguments.js
Normal file
@@ -0,0 +1,778 @@
|
|||||||
|
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"
|
||||||
|
}
|
||||||
|
|
||||||
|
issue_3273: {
|
||||||
|
options = {
|
||||||
|
arguments: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
function f(a) {
|
||||||
|
console.log(arguments[0], a);
|
||||||
|
arguments[0]++;
|
||||||
|
console.log(arguments[0], a);
|
||||||
|
}
|
||||||
|
f(0);
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
function f(a) {
|
||||||
|
console.log(a, a);
|
||||||
|
a++;
|
||||||
|
console.log(a, a);
|
||||||
|
}
|
||||||
|
f(0);
|
||||||
|
}
|
||||||
|
expect_stdout: [
|
||||||
|
"0 0",
|
||||||
|
"1 1",
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
|
issue_3273_reduce_vars: {
|
||||||
|
options = {
|
||||||
|
arguments: true,
|
||||||
|
reduce_vars: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
function f(a) {
|
||||||
|
console.log(arguments[0], a);
|
||||||
|
arguments[0]++;
|
||||||
|
console.log(arguments[0], a);
|
||||||
|
}
|
||||||
|
f(0);
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
function f(a) {
|
||||||
|
console.log(a, a);
|
||||||
|
a++;
|
||||||
|
console.log(a, a);
|
||||||
|
}
|
||||||
|
f(0);
|
||||||
|
}
|
||||||
|
expect_stdout: [
|
||||||
|
"0 0",
|
||||||
|
"1 1",
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
|
issue_3273_local_strict: {
|
||||||
|
options = {
|
||||||
|
arguments: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
function f(a) {
|
||||||
|
"use strict";
|
||||||
|
console.log(arguments[0], a);
|
||||||
|
arguments[0]++;
|
||||||
|
console.log(arguments[0], a);
|
||||||
|
}
|
||||||
|
f(0);
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
function f(a) {
|
||||||
|
"use strict";
|
||||||
|
console.log(arguments[0], a);
|
||||||
|
arguments[0]++;
|
||||||
|
console.log(arguments[0], a);
|
||||||
|
}
|
||||||
|
f(0);
|
||||||
|
}
|
||||||
|
expect_stdout: [
|
||||||
|
"0 0",
|
||||||
|
"1 0",
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
|
issue_3273_local_strict_reduce_vars: {
|
||||||
|
options = {
|
||||||
|
arguments: true,
|
||||||
|
reduce_vars: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
function f(a) {
|
||||||
|
"use strict";
|
||||||
|
console.log(arguments[0], a);
|
||||||
|
arguments[0]++;
|
||||||
|
console.log(arguments[0], a);
|
||||||
|
}
|
||||||
|
f(0);
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
function f(a) {
|
||||||
|
"use strict";
|
||||||
|
console.log(arguments[0], a);
|
||||||
|
arguments[0]++;
|
||||||
|
console.log(arguments[0], a);
|
||||||
|
}
|
||||||
|
f(0);
|
||||||
|
}
|
||||||
|
expect_stdout: [
|
||||||
|
"0 0",
|
||||||
|
"1 0",
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
|
issue_3273_global_strict: {
|
||||||
|
options = {
|
||||||
|
arguments: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
"use strict";
|
||||||
|
function f(a) {
|
||||||
|
console.log(arguments[0], a);
|
||||||
|
arguments[0]++;
|
||||||
|
console.log(arguments[0], a);
|
||||||
|
}
|
||||||
|
f(0);
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
"use strict";
|
||||||
|
function f(a) {
|
||||||
|
console.log(arguments[0], a);
|
||||||
|
arguments[0]++;
|
||||||
|
console.log(arguments[0], a);
|
||||||
|
}
|
||||||
|
f(0);
|
||||||
|
}
|
||||||
|
expect_stdout: [
|
||||||
|
"0 0",
|
||||||
|
"1 0",
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
|
issue_3273_global_strict_reduce_vars: {
|
||||||
|
options = {
|
||||||
|
arguments: true,
|
||||||
|
reduce_vars: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
"use strict";
|
||||||
|
function f(a) {
|
||||||
|
console.log(arguments[0], a);
|
||||||
|
arguments[0]++;
|
||||||
|
console.log(arguments[0], a);
|
||||||
|
}
|
||||||
|
f(0);
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
"use strict";
|
||||||
|
function f(a) {
|
||||||
|
console.log(arguments[0], a);
|
||||||
|
arguments[0]++;
|
||||||
|
console.log(arguments[0], a);
|
||||||
|
}
|
||||||
|
f(0);
|
||||||
|
}
|
||||||
|
expect_stdout: [
|
||||||
|
"0 0",
|
||||||
|
"1 0",
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
|
issue_3273_keep_fargs_false: {
|
||||||
|
options = {
|
||||||
|
arguments: true,
|
||||||
|
keep_fargs: false,
|
||||||
|
reduce_vars: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
(function() {
|
||||||
|
"use strict";
|
||||||
|
arguments[0]++;
|
||||||
|
console.log(arguments[0]);
|
||||||
|
})(0);
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
(function(argument_0) {
|
||||||
|
"use strict";
|
||||||
|
argument_0++;
|
||||||
|
console.log(argument_0);
|
||||||
|
})(0);
|
||||||
|
}
|
||||||
|
expect_stdout: "1"
|
||||||
|
}
|
||||||
|
|
||||||
|
issue_3273_keep_fargs_strict: {
|
||||||
|
options = {
|
||||||
|
arguments: true,
|
||||||
|
keep_fargs: "strict",
|
||||||
|
reduce_vars: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
(function() {
|
||||||
|
"use strict";
|
||||||
|
arguments[0]++;
|
||||||
|
console.log(arguments[0]);
|
||||||
|
})(0);
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
(function(argument_0) {
|
||||||
|
"use strict";
|
||||||
|
argument_0++;
|
||||||
|
console.log(argument_0);
|
||||||
|
})(0);
|
||||||
|
}
|
||||||
|
expect_stdout: "1"
|
||||||
|
}
|
||||||
|
|
||||||
|
issue_3282_1: {
|
||||||
|
options = {
|
||||||
|
arguments: true,
|
||||||
|
reduce_funcs: true,
|
||||||
|
reduce_vars: true,
|
||||||
|
keep_fargs: false,
|
||||||
|
unused: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
(function(t) {
|
||||||
|
return function() {
|
||||||
|
t();
|
||||||
|
};
|
||||||
|
})(function() {
|
||||||
|
'use strict';
|
||||||
|
function e() {
|
||||||
|
return arguments[0];
|
||||||
|
}
|
||||||
|
e();
|
||||||
|
e();
|
||||||
|
})();
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
(function() {
|
||||||
|
return function() {
|
||||||
|
(function() {
|
||||||
|
"use strict";
|
||||||
|
function e() {
|
||||||
|
return arguments[0];
|
||||||
|
}
|
||||||
|
e();
|
||||||
|
e();
|
||||||
|
})();
|
||||||
|
};
|
||||||
|
})()();
|
||||||
|
}
|
||||||
|
expect_stdout: true
|
||||||
|
}
|
||||||
|
|
||||||
|
issue_3282_1_passes: {
|
||||||
|
options = {
|
||||||
|
arguments: true,
|
||||||
|
passes: 2,
|
||||||
|
reduce_funcs: true,
|
||||||
|
reduce_vars: true,
|
||||||
|
keep_fargs: false,
|
||||||
|
unused: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
(function(t) {
|
||||||
|
return function() {
|
||||||
|
t();
|
||||||
|
};
|
||||||
|
})(function() {
|
||||||
|
'use strict';
|
||||||
|
function e() {
|
||||||
|
return arguments[0];
|
||||||
|
}
|
||||||
|
e();
|
||||||
|
e();
|
||||||
|
})();
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
(function() {
|
||||||
|
return function() {
|
||||||
|
(function() {
|
||||||
|
"use strict";
|
||||||
|
function e(argument_0) {
|
||||||
|
return argument_0;
|
||||||
|
}
|
||||||
|
e();
|
||||||
|
e();
|
||||||
|
})();
|
||||||
|
};
|
||||||
|
})()();
|
||||||
|
}
|
||||||
|
expect_stdout: true
|
||||||
|
}
|
||||||
|
|
||||||
|
issue_3282_2: {
|
||||||
|
options = {
|
||||||
|
arguments: true,
|
||||||
|
reduce_vars: true,
|
||||||
|
keep_fargs: false,
|
||||||
|
unused: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
(function(f) {
|
||||||
|
f();
|
||||||
|
})(function() {
|
||||||
|
return (function(t) {
|
||||||
|
return function() {
|
||||||
|
t();
|
||||||
|
};
|
||||||
|
})(function() {
|
||||||
|
'use strict';
|
||||||
|
function e() {
|
||||||
|
return arguments[0];
|
||||||
|
}
|
||||||
|
e();
|
||||||
|
e();
|
||||||
|
})();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
(function() {
|
||||||
|
(function() {
|
||||||
|
return function(t) {
|
||||||
|
return function() {
|
||||||
|
t();
|
||||||
|
};
|
||||||
|
}(function() {
|
||||||
|
"use strict";
|
||||||
|
function e() {
|
||||||
|
return arguments[0];
|
||||||
|
}
|
||||||
|
e();
|
||||||
|
e();
|
||||||
|
})();
|
||||||
|
})();
|
||||||
|
})();
|
||||||
|
}
|
||||||
|
expect_stdout: true
|
||||||
|
}
|
||||||
|
|
||||||
|
issue_3282_2_passes: {
|
||||||
|
options = {
|
||||||
|
arguments: true,
|
||||||
|
passes: 2,
|
||||||
|
reduce_vars: true,
|
||||||
|
keep_fargs: false,
|
||||||
|
unused: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
(function(f) {
|
||||||
|
f();
|
||||||
|
})(function() {
|
||||||
|
return (function(t) {
|
||||||
|
return function() {
|
||||||
|
t();
|
||||||
|
};
|
||||||
|
})(function() {
|
||||||
|
'use strict';
|
||||||
|
function e() {
|
||||||
|
return arguments[0];
|
||||||
|
}
|
||||||
|
e();
|
||||||
|
e();
|
||||||
|
})();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
(function() {
|
||||||
|
(function() {
|
||||||
|
return function(t) {
|
||||||
|
return function() {
|
||||||
|
t();
|
||||||
|
};
|
||||||
|
}(function() {
|
||||||
|
"use strict";
|
||||||
|
function e(argument_0) {
|
||||||
|
return argument_0;
|
||||||
|
}
|
||||||
|
e();
|
||||||
|
e();
|
||||||
|
})();
|
||||||
|
})();
|
||||||
|
})();
|
||||||
|
}
|
||||||
|
expect_stdout: true
|
||||||
|
}
|
||||||
|
|
||||||
|
issue_3420_1: {
|
||||||
|
options = {
|
||||||
|
arguments: true,
|
||||||
|
keep_fargs: "strict",
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
console.log(function() {
|
||||||
|
return function() {
|
||||||
|
return arguments[0];
|
||||||
|
};
|
||||||
|
}().length);
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
console.log(function() {
|
||||||
|
return function() {
|
||||||
|
return arguments[0];
|
||||||
|
};
|
||||||
|
}().length);
|
||||||
|
}
|
||||||
|
expect_stdout: "0"
|
||||||
|
}
|
||||||
|
|
||||||
|
issue_3420_2: {
|
||||||
|
options = {
|
||||||
|
arguments: true,
|
||||||
|
keep_fargs: "strict",
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
var foo = function() {
|
||||||
|
delete arguments[0];
|
||||||
|
};
|
||||||
|
foo();
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
var foo = function() {
|
||||||
|
delete arguments[0];
|
||||||
|
};
|
||||||
|
foo();
|
||||||
|
}
|
||||||
|
expect_stdout: true
|
||||||
|
}
|
||||||
|
|
||||||
|
issue_3420_3: {
|
||||||
|
options = {
|
||||||
|
arguments: true,
|
||||||
|
keep_fargs: "strict",
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
"use strict";
|
||||||
|
var foo = function() {
|
||||||
|
delete arguments[0];
|
||||||
|
};
|
||||||
|
foo();
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
"use strict";
|
||||||
|
var foo = function() {
|
||||||
|
delete arguments[0];
|
||||||
|
};
|
||||||
|
foo();
|
||||||
|
}
|
||||||
|
expect_stdout: true
|
||||||
|
}
|
||||||
|
|
||||||
|
issue_3420_4: {
|
||||||
|
options = {
|
||||||
|
arguments: true,
|
||||||
|
keep_fargs: "strict",
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
!function() {
|
||||||
|
console.log(arguments[0]);
|
||||||
|
delete arguments[0];
|
||||||
|
console.log(arguments[0]);
|
||||||
|
}(42);
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
!function(argument_0) {
|
||||||
|
console.log(argument_0);
|
||||||
|
delete arguments[0];
|
||||||
|
console.log(arguments[0]);
|
||||||
|
}(42);
|
||||||
|
}
|
||||||
|
expect_stdout: [
|
||||||
|
"42",
|
||||||
|
"undefined",
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
|
issue_3420_5: {
|
||||||
|
options = {
|
||||||
|
arguments: true,
|
||||||
|
keep_fargs: "strict",
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
"use strict";
|
||||||
|
!function() {
|
||||||
|
console.log(arguments[0]);
|
||||||
|
delete arguments[0];
|
||||||
|
console.log(arguments[0]);
|
||||||
|
}(42);
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
"use strict";
|
||||||
|
!function(argument_0) {
|
||||||
|
console.log(argument_0);
|
||||||
|
delete arguments[0];
|
||||||
|
console.log(arguments[0]);
|
||||||
|
}(42);
|
||||||
|
}
|
||||||
|
expect_stdout: [
|
||||||
|
"42",
|
||||||
|
"undefined",
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
|
issue_3420_6: {
|
||||||
|
options = {
|
||||||
|
arguments: true,
|
||||||
|
keep_fargs: "strict",
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
console.log(function() {
|
||||||
|
return delete arguments[0];
|
||||||
|
}());
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
console.log(function() {
|
||||||
|
return delete arguments[0];
|
||||||
|
}());
|
||||||
|
}
|
||||||
|
expect_stdout: "true"
|
||||||
|
}
|
||||||
|
|
||||||
|
issue_3420_7: {
|
||||||
|
options = {
|
||||||
|
arguments: true,
|
||||||
|
keep_fargs: "strict",
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
"use strict";
|
||||||
|
console.log(function() {
|
||||||
|
return delete arguments[0];
|
||||||
|
}());
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
"use strict";
|
||||||
|
console.log(function() {
|
||||||
|
return delete arguments[0];
|
||||||
|
}());
|
||||||
|
}
|
||||||
|
expect_stdout: "true"
|
||||||
|
}
|
||||||
@@ -1,5 +1,3 @@
|
|||||||
// NOTE trailing comma doesn't contribute to length of an array
|
|
||||||
// That also means the array changes length if previous element is a hole too and got cut off
|
|
||||||
holes_and_undefined: {
|
holes_and_undefined: {
|
||||||
input: {
|
input: {
|
||||||
w = [1,,];
|
w = [1,,];
|
||||||
@@ -17,9 +15,10 @@ holes_and_undefined: {
|
|||||||
|
|
||||||
constant_join: {
|
constant_join: {
|
||||||
options = {
|
options = {
|
||||||
unsafe : true,
|
evaluate: true,
|
||||||
evaluate : true
|
strings: true,
|
||||||
};
|
unsafe: true,
|
||||||
|
}
|
||||||
input: {
|
input: {
|
||||||
var a = [ "foo", "bar", "baz" ].join("");
|
var a = [ "foo", "bar", "baz" ].join("");
|
||||||
var a1 = [ "foo", "bar", "baz" ].join();
|
var a1 = [ "foo", "bar", "baz" ].join();
|
||||||
@@ -66,9 +65,10 @@ constant_join: {
|
|||||||
|
|
||||||
constant_join_2: {
|
constant_join_2: {
|
||||||
options = {
|
options = {
|
||||||
unsafe : true,
|
evaluate: true,
|
||||||
evaluate : true
|
strings: true,
|
||||||
};
|
unsafe: true,
|
||||||
|
}
|
||||||
input: {
|
input: {
|
||||||
var a = [ "foo", "bar", boo(), "baz", "x", "y" ].join("");
|
var a = [ "foo", "bar", boo(), "baz", "x", "y" ].join("");
|
||||||
var b = [ "foo", "bar", boo(), "baz", "x", "y" ].join("-");
|
var b = [ "foo", "bar", boo(), "baz", "x", "y" ].join("-");
|
||||||
@@ -93,85 +93,14 @@ 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,
|
|
||||||
evaluate: true,
|
evaluate: true,
|
||||||
};
|
strings: true,
|
||||||
|
unsafe: true,
|
||||||
|
}
|
||||||
input: {
|
input: {
|
||||||
|
var foo, bar, baz;
|
||||||
var a = [ null ].join();
|
var a = [ null ].join();
|
||||||
var b = [ , ].join();
|
var b = [ , ].join();
|
||||||
var c = [ , 1, , 3 ].join();
|
var c = [ , 1, , 3 ].join();
|
||||||
@@ -186,6 +115,7 @@ constant_join_3: {
|
|||||||
var l = [ foo, bar + "baz" ].join("");
|
var l = [ foo, bar + "baz" ].join("");
|
||||||
}
|
}
|
||||||
expect: {
|
expect: {
|
||||||
|
var foo, bar, baz;
|
||||||
var a = "";
|
var a = "";
|
||||||
var b = "";
|
var b = "";
|
||||||
var c = ",1,,3";
|
var c = ",1,,3";
|
||||||
@@ -208,7 +138,7 @@ for_loop: {
|
|||||||
reduce_vars: true,
|
reduce_vars: true,
|
||||||
unsafe: true,
|
unsafe: true,
|
||||||
unused: true,
|
unused: true,
|
||||||
};
|
}
|
||||||
input: {
|
input: {
|
||||||
function f0() {
|
function f0() {
|
||||||
var a = [1, 2, 3];
|
var a = [1, 2, 3];
|
||||||
@@ -314,3 +244,113 @@ index_length: {
|
|||||||
}
|
}
|
||||||
expect_stdout: "1 2"
|
expect_stdout: "1 2"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
constructor_bad: {
|
||||||
|
options = {
|
||||||
|
unsafe: true
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
try {
|
||||||
|
Array(NaN);
|
||||||
|
console.log("FAIL1");
|
||||||
|
} catch (ex) {
|
||||||
|
try {
|
||||||
|
new Array(NaN);
|
||||||
|
console.log("FAIL2");
|
||||||
|
} catch (ex) {
|
||||||
|
console.log("PASS");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
Array(3.14);
|
||||||
|
console.log("FAIL1");
|
||||||
|
} catch (ex) {
|
||||||
|
try {
|
||||||
|
new Array(3.14);
|
||||||
|
console.log("FAIL2");
|
||||||
|
} catch (ex) {
|
||||||
|
console.log("PASS");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
try {
|
||||||
|
Array(NaN);
|
||||||
|
console.log("FAIL1");
|
||||||
|
} catch (ex) {
|
||||||
|
try {
|
||||||
|
Array(NaN);
|
||||||
|
console.log("FAIL2");
|
||||||
|
} catch (ex) {
|
||||||
|
console.log("PASS");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
Array(3.14);
|
||||||
|
console.log("FAIL1");
|
||||||
|
} catch (ex) {
|
||||||
|
try {
|
||||||
|
Array(3.14);
|
||||||
|
console.log("FAIL2");
|
||||||
|
} catch (ex) {
|
||||||
|
console.log("PASS");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
expect_stdout: [
|
||||||
|
"PASS",
|
||||||
|
"PASS",
|
||||||
|
]
|
||||||
|
expect_warnings: [
|
||||||
|
"WARN: Invalid array length: 3.14 [test/compress/arrays.js:13,12]",
|
||||||
|
"WARN: Invalid array length: 3.14 [test/compress/arrays.js:17,16]",
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
|
constructor_good: {
|
||||||
|
options = {
|
||||||
|
unsafe: true
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
console.log(Array());
|
||||||
|
console.log(Array(0));
|
||||||
|
console.log(Array(1));
|
||||||
|
console.log(Array(6));
|
||||||
|
console.log(Array(7));
|
||||||
|
console.log(Array(1, 2));
|
||||||
|
console.log(Array(false));
|
||||||
|
console.log(Array("foo"));
|
||||||
|
console.log(Array(Array));
|
||||||
|
console.log(new Array());
|
||||||
|
console.log(new Array(0));
|
||||||
|
console.log(new Array(1));
|
||||||
|
console.log(new Array(6));
|
||||||
|
console.log(new Array(7));
|
||||||
|
console.log(new Array(1, 2));
|
||||||
|
console.log(new Array(false));
|
||||||
|
console.log(new Array("foo"));
|
||||||
|
console.log(new Array(Array));
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
console.log([]);
|
||||||
|
console.log([]);
|
||||||
|
console.log([,]);
|
||||||
|
console.log([,,,,,,]);
|
||||||
|
console.log(Array(7));
|
||||||
|
console.log([ 1, 2 ]);
|
||||||
|
console.log([ false ]);
|
||||||
|
console.log([ "foo" ]);
|
||||||
|
console.log(Array(Array));
|
||||||
|
console.log([]);
|
||||||
|
console.log([]);
|
||||||
|
console.log([,]);
|
||||||
|
console.log([,,,,,,]);
|
||||||
|
console.log(Array(7));
|
||||||
|
console.log([ 1, 2 ]);
|
||||||
|
console.log([ false ]);
|
||||||
|
console.log([ "foo" ]);
|
||||||
|
console.log(Array(Array));
|
||||||
|
}
|
||||||
|
expect_stdout: true
|
||||||
|
expect_warnings: []
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,656 +0,0 @@
|
|||||||
arrow_functions_without_body: {
|
|
||||||
input: {
|
|
||||||
var a1 = () => 42;
|
|
||||||
var a2 = (p) => p;
|
|
||||||
var a3 = p => p;
|
|
||||||
var a4 = (...p) => p;
|
|
||||||
var a5 = (b, c) => b + c;
|
|
||||||
var a6 = (b, ...c) => b + c[0];
|
|
||||||
var a7 = (...b) => b.join();
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
var a1 = () => 42;
|
|
||||||
var a2 = (p) => p;
|
|
||||||
var a3 = p => p;
|
|
||||||
var a4 = (...p) => p;
|
|
||||||
var a5 = (b, c) => b + c;
|
|
||||||
var a6 = (b, ...c) => b + c[0];
|
|
||||||
var a7 = (...b) => b.join();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
arrow_functions_with_body: {
|
|
||||||
input: {
|
|
||||||
var a1 = () => {
|
|
||||||
var a = 42 * Math.random();
|
|
||||||
return a;
|
|
||||||
};
|
|
||||||
var a2 = (p) => {
|
|
||||||
var a = Math.random() * p;
|
|
||||||
return a;
|
|
||||||
};
|
|
||||||
var a3 = p => {
|
|
||||||
var a = Math.random() * p;
|
|
||||||
return a;
|
|
||||||
};
|
|
||||||
var a4 = (...p) => {
|
|
||||||
var a = Math.random() * p;
|
|
||||||
return a;
|
|
||||||
};
|
|
||||||
var a5 = (b, c) => {
|
|
||||||
var result = b * c + b / c;
|
|
||||||
return result
|
|
||||||
};
|
|
||||||
var a6 = (b, ...c) => {
|
|
||||||
var result = b;
|
|
||||||
for (var i = 0; i < c.length; i++)
|
|
||||||
result += c[i];
|
|
||||||
return result
|
|
||||||
};
|
|
||||||
var a7 = (...b) => {
|
|
||||||
b.join();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
var a1 = () => {
|
|
||||||
var a = 42 * Math.random();
|
|
||||||
return a;
|
|
||||||
};
|
|
||||||
var a2 = (p) => {
|
|
||||||
var a = Math.random() * p;
|
|
||||||
return a;
|
|
||||||
};
|
|
||||||
var a3 = p => {
|
|
||||||
var a = Math.random() * p;
|
|
||||||
return a;
|
|
||||||
};
|
|
||||||
var a4 = (...p) => {
|
|
||||||
var a = Math.random() * p;
|
|
||||||
return a;
|
|
||||||
};
|
|
||||||
var a5 = (b, c) => {
|
|
||||||
var result = b * c + b / c;
|
|
||||||
return result
|
|
||||||
};
|
|
||||||
var a6 = (b, ...c) => {
|
|
||||||
var result = b;
|
|
||||||
for (var i = 0; i < c.length; i++)
|
|
||||||
result += c[i];
|
|
||||||
return result
|
|
||||||
};
|
|
||||||
var a7 = (...b) => {
|
|
||||||
b.join();
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
arrow_function_with_single_parameter_with_default: {
|
|
||||||
input: {
|
|
||||||
var foo = (a = 0) => doSomething(a);
|
|
||||||
}
|
|
||||||
expect_exact: "var foo=(a=0)=>doSomething(a);"
|
|
||||||
}
|
|
||||||
|
|
||||||
arrow_binding_pattern: {
|
|
||||||
input: {
|
|
||||||
var foo = ([]) => "foo";
|
|
||||||
var bar = ({}) => "bar";
|
|
||||||
var with_default = (foo = "default") => foo;
|
|
||||||
var object_with_default = ({foo = "default", bar: baz = "default"}) => foo;
|
|
||||||
var array_after_spread = (...[foo]) => foo;
|
|
||||||
var array_after_spread = (...{foo}) => foo;
|
|
||||||
var computed = ({ [compute()]: x }) => {};
|
|
||||||
var array_hole = ([, , ...x] = [1, 2]) => {};
|
|
||||||
var object_trailing_elision = ({foo,}) => {};
|
|
||||||
var spread_empty_array = (...[]) => "foo";
|
|
||||||
var spread_empty_object = (...{}) => "foo";
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
var foo = ([]) => "foo";
|
|
||||||
var bar = ({}) => "bar";
|
|
||||||
var with_default = (foo = "default") => foo;
|
|
||||||
var object_with_default = ({foo = "default", bar: baz = "default"}) => foo;
|
|
||||||
var array_after_spread = (...[foo]) => foo;
|
|
||||||
var array_after_spread = (...{foo}) => foo;
|
|
||||||
var computed = ({ [compute()]: x }) => {};
|
|
||||||
var array_hole = ([, , ...x] = [1, 2]) => {};
|
|
||||||
var object_trailing_elision = ({foo,}) => {};
|
|
||||||
var spread_empty_array = (...[]) => "foo";
|
|
||||||
var spread_empty_object = (...{}) => "foo";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
arrow_binding_pattern_strict: {
|
|
||||||
input: {
|
|
||||||
var foo = ([,]) => "foo";
|
|
||||||
}
|
|
||||||
expect_exact: 'var foo=([,])=>"foo";'
|
|
||||||
}
|
|
||||||
|
|
||||||
arrow_with_regexp: {
|
|
||||||
input: {
|
|
||||||
num => /\d{11,14}/.test( num )
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
num => /\d{11,14}/.test( num )
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
arrow_unused: {
|
|
||||||
options = {
|
|
||||||
toplevel: false,
|
|
||||||
side_effects: true,
|
|
||||||
unused: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
top => dog;
|
|
||||||
let fn = a => { console.log(a * a); };
|
|
||||||
let u = (x, y) => x - y + g;
|
|
||||||
(() => { console.log("0"); })();
|
|
||||||
!function(x) {
|
|
||||||
(() => { console.log("1"); })();
|
|
||||||
let unused = x => { console.log(x); };
|
|
||||||
let baz = e => e + e;
|
|
||||||
console.log(baz(x));
|
|
||||||
}(1);
|
|
||||||
fn(3);
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
let fn = a => { console.log(a * a); };
|
|
||||||
let u = (x, y) => x - y + g;
|
|
||||||
(() => { console.log("0"); })();
|
|
||||||
!function(x) {
|
|
||||||
(() => { console.log("1"); })();
|
|
||||||
let baz = e => e + e;
|
|
||||||
console.log(baz(x));
|
|
||||||
}(1);
|
|
||||||
fn(3);
|
|
||||||
}
|
|
||||||
expect_stdout: [ "0", "1", "2", "9" ]
|
|
||||||
node_version: ">=6"
|
|
||||||
}
|
|
||||||
|
|
||||||
arrow_unused_toplevel: {
|
|
||||||
options = {
|
|
||||||
toplevel: true,
|
|
||||||
side_effects: true,
|
|
||||||
unused: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
top => dog;
|
|
||||||
let fn = a => { console.log(a * a); };
|
|
||||||
let u = (x, y) => x - y + g;
|
|
||||||
(() => { console.log("0"); })();
|
|
||||||
!function(x) {
|
|
||||||
(() => { console.log("1"); })();
|
|
||||||
let unused = x => { console.log(x); };
|
|
||||||
let baz = e => e + e;
|
|
||||||
console.log(baz(x));
|
|
||||||
}(1);
|
|
||||||
fn(3);
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
let fn = a => { console.log(a * a); };
|
|
||||||
(() => { console.log("0"); })();
|
|
||||||
!function(x) {
|
|
||||||
(() => { console.log("1"); })();
|
|
||||||
let baz = e => e + e;
|
|
||||||
console.log(baz(x));
|
|
||||||
}(1);
|
|
||||||
fn(3);
|
|
||||||
}
|
|
||||||
expect_stdout: [ "0", "1", "2", "9" ]
|
|
||||||
node_version: ">=6"
|
|
||||||
}
|
|
||||||
|
|
||||||
no_leading_parentheses: {
|
|
||||||
input: {
|
|
||||||
(x,y) => x(y);
|
|
||||||
async (x,y) => await x(y);
|
|
||||||
}
|
|
||||||
expect_exact: "(x,y)=>x(y);async(x,y)=>await x(y);"
|
|
||||||
}
|
|
||||||
|
|
||||||
async_identifiers: {
|
|
||||||
options = {
|
|
||||||
unsafe_arrows: true,
|
|
||||||
ecma: 6,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
var async = function(x){ console.log("async", x); };
|
|
||||||
var await = function(x){ console.log("await", x); };
|
|
||||||
async(1);
|
|
||||||
await(2);
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
var async = x => { console.log("async", x); };
|
|
||||||
var await = x => { console.log("await", x); };
|
|
||||||
async(1);
|
|
||||||
await(2);
|
|
||||||
}
|
|
||||||
expect_stdout: [
|
|
||||||
"async 1",
|
|
||||||
"await 2",
|
|
||||||
]
|
|
||||||
node_version: ">=4"
|
|
||||||
}
|
|
||||||
|
|
||||||
async_function_expression: {
|
|
||||||
options = {
|
|
||||||
unsafe_arrows: true,
|
|
||||||
ecma: 6,
|
|
||||||
evaluate: true,
|
|
||||||
side_effects: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
var named = async function foo() {
|
|
||||||
await bar(1 + 0) + (2 + 0);
|
|
||||||
}
|
|
||||||
var anon = async function() {
|
|
||||||
await (1 + 0) + bar(2 + 0);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
var named = async function foo() {
|
|
||||||
await bar(1);
|
|
||||||
};
|
|
||||||
var anon = async () => {
|
|
||||||
await 1, bar(2);
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
issue_27: {
|
|
||||||
options = {
|
|
||||||
unsafe_arrows: true,
|
|
||||||
collapse_vars: true,
|
|
||||||
ecma: 6,
|
|
||||||
unused: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
(function(jQuery) {
|
|
||||||
var $;
|
|
||||||
$ = jQuery;
|
|
||||||
$("body").addClass("foo");
|
|
||||||
})(jQuery);
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
(jQuery => {
|
|
||||||
jQuery("body").addClass("foo");
|
|
||||||
})(jQuery);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
issue_2105_1: {
|
|
||||||
options = {
|
|
||||||
unsafe_arrows: true,
|
|
||||||
collapse_vars: true,
|
|
||||||
ecma: 6,
|
|
||||||
inline: true,
|
|
||||||
passes: 3,
|
|
||||||
reduce_funcs: true,
|
|
||||||
reduce_vars: true,
|
|
||||||
side_effects: true,
|
|
||||||
unsafe_methods: true,
|
|
||||||
unused: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
!function(factory) {
|
|
||||||
factory();
|
|
||||||
}( function() {
|
|
||||||
return function(fn) {
|
|
||||||
fn()().prop();
|
|
||||||
}( function() {
|
|
||||||
function bar() {
|
|
||||||
var quux = function() {
|
|
||||||
console.log("PASS");
|
|
||||||
}, foo = function() {
|
|
||||||
console.log;
|
|
||||||
quux();
|
|
||||||
};
|
|
||||||
return { prop: foo };
|
|
||||||
}
|
|
||||||
return bar;
|
|
||||||
} );
|
|
||||||
});
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
({
|
|
||||||
prop() {
|
|
||||||
console.log;
|
|
||||||
console.log("PASS");
|
|
||||||
}
|
|
||||||
}).prop();
|
|
||||||
}
|
|
||||||
expect_stdout: "PASS"
|
|
||||||
node_version: ">=4"
|
|
||||||
}
|
|
||||||
|
|
||||||
issue_2105_2: {
|
|
||||||
options = {
|
|
||||||
collapse_vars: true,
|
|
||||||
inline: true,
|
|
||||||
passes: 2,
|
|
||||||
reduce_funcs: true,
|
|
||||||
reduce_vars: true,
|
|
||||||
side_effects: true,
|
|
||||||
unused: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
((factory) => {
|
|
||||||
factory();
|
|
||||||
})( () => {
|
|
||||||
return ((fn) => {
|
|
||||||
fn()().prop();
|
|
||||||
})( () => {
|
|
||||||
let bar = () => {
|
|
||||||
var quux = () => {
|
|
||||||
console.log("PASS");
|
|
||||||
}, foo = () => {
|
|
||||||
console.log;
|
|
||||||
quux();
|
|
||||||
};
|
|
||||||
return { prop: foo };
|
|
||||||
};
|
|
||||||
return bar;
|
|
||||||
} );
|
|
||||||
});
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
({
|
|
||||||
prop: () => {
|
|
||||||
console.log;
|
|
||||||
console.log("PASS");
|
|
||||||
}
|
|
||||||
}).prop();
|
|
||||||
}
|
|
||||||
expect_stdout: "PASS"
|
|
||||||
node_version: ">=6"
|
|
||||||
}
|
|
||||||
|
|
||||||
issue_2136_2: {
|
|
||||||
options = {
|
|
||||||
arrows: true,
|
|
||||||
collapse_vars: true,
|
|
||||||
ecma: 6,
|
|
||||||
inline: true,
|
|
||||||
side_effects: true,
|
|
||||||
unused: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
function f(x) {
|
|
||||||
console.log(x);
|
|
||||||
}
|
|
||||||
!function(a, ...b) {
|
|
||||||
f(b[0]);
|
|
||||||
}(1, 2, 3);
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
function f(x) {
|
|
||||||
console.log(x);
|
|
||||||
}
|
|
||||||
f([2,3][0]);
|
|
||||||
}
|
|
||||||
expect_stdout: "2"
|
|
||||||
node_version: ">=6"
|
|
||||||
}
|
|
||||||
|
|
||||||
issue_2136_3: {
|
|
||||||
options = {
|
|
||||||
arrows: true,
|
|
||||||
collapse_vars: true,
|
|
||||||
ecma: 6,
|
|
||||||
evaluate: true,
|
|
||||||
inline: true,
|
|
||||||
passes: 3,
|
|
||||||
reduce_funcs: true,
|
|
||||||
reduce_vars: true,
|
|
||||||
side_effects: true,
|
|
||||||
toplevel: true,
|
|
||||||
unsafe: true,
|
|
||||||
unused: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
function f(x) {
|
|
||||||
console.log(x);
|
|
||||||
}
|
|
||||||
!function(a, ...b) {
|
|
||||||
f(b[0]);
|
|
||||||
}(1, 2, 3);
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
console.log(2);
|
|
||||||
}
|
|
||||||
expect_stdout: "2"
|
|
||||||
node_version: ">=6"
|
|
||||||
}
|
|
||||||
|
|
||||||
call_args: {
|
|
||||||
options = {
|
|
||||||
arrows: true,
|
|
||||||
ecma: 6,
|
|
||||||
evaluate: true,
|
|
||||||
inline: true,
|
|
||||||
reduce_funcs: true,
|
|
||||||
reduce_vars: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
const a = 1;
|
|
||||||
console.log(a);
|
|
||||||
+function(a) {
|
|
||||||
return a;
|
|
||||||
}(a);
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
const a = 1;
|
|
||||||
console.log(1);
|
|
||||||
+(1, 1);
|
|
||||||
}
|
|
||||||
expect_stdout: true
|
|
||||||
}
|
|
||||||
|
|
||||||
call_args_drop_param: {
|
|
||||||
options = {
|
|
||||||
arrows: true,
|
|
||||||
ecma: 6,
|
|
||||||
evaluate: true,
|
|
||||||
inline: true,
|
|
||||||
keep_fargs: false,
|
|
||||||
reduce_funcs: true,
|
|
||||||
reduce_vars: true,
|
|
||||||
unused: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
const a = 1;
|
|
||||||
console.log(a);
|
|
||||||
+function(a) {
|
|
||||||
return a;
|
|
||||||
}(a, b);
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
const a = 1;
|
|
||||||
console.log(1);
|
|
||||||
+(b, 1);
|
|
||||||
}
|
|
||||||
expect_stdout: true
|
|
||||||
}
|
|
||||||
|
|
||||||
issue_485_crashing_1530: {
|
|
||||||
options = {
|
|
||||||
arrows: true,
|
|
||||||
conditionals: true,
|
|
||||||
dead_code: true,
|
|
||||||
ecma: 6,
|
|
||||||
evaluate: true,
|
|
||||||
inline: true,
|
|
||||||
side_effects: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
(function(a) {
|
|
||||||
if (true) return;
|
|
||||||
var b = 42;
|
|
||||||
})(this);
|
|
||||||
}
|
|
||||||
expect: {}
|
|
||||||
}
|
|
||||||
|
|
||||||
issue_2084: {
|
|
||||||
options = {
|
|
||||||
unsafe_arrows: true,
|
|
||||||
collapse_vars: true,
|
|
||||||
conditionals: true,
|
|
||||||
ecma: 6,
|
|
||||||
evaluate: true,
|
|
||||||
inline: true,
|
|
||||||
passes: 2,
|
|
||||||
reduce_funcs: true,
|
|
||||||
reduce_vars: true,
|
|
||||||
sequences: true,
|
|
||||||
side_effects: true,
|
|
||||||
unused: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
var c = 0;
|
|
||||||
!function() {
|
|
||||||
!function(c) {
|
|
||||||
c = 1 + c;
|
|
||||||
var c = 0;
|
|
||||||
function f14(a_1) {
|
|
||||||
if (c = 1 + c, 0 !== 23..toString())
|
|
||||||
c = 1 + c, a_1 && (a_1[0] = 0);
|
|
||||||
}
|
|
||||||
f14();
|
|
||||||
}(-1);
|
|
||||||
}();
|
|
||||||
console.log(c);
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
var c = 0;
|
|
||||||
((c) => {
|
|
||||||
c = 1 + c,
|
|
||||||
c = 1 + (c = 0),
|
|
||||||
0 !== 23..toString() && (c = 1 + c);
|
|
||||||
})(-1),
|
|
||||||
console.log(c);
|
|
||||||
}
|
|
||||||
expect_stdout: "0"
|
|
||||||
node_version: ">=4"
|
|
||||||
}
|
|
||||||
|
|
||||||
export_default_object_expression: {
|
|
||||||
options = {
|
|
||||||
arrows: true,
|
|
||||||
evaluate: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
export default {
|
|
||||||
foo: 1 + 2,
|
|
||||||
bar() { return 4; },
|
|
||||||
get baz() { return this.foo; },
|
|
||||||
};
|
|
||||||
}
|
|
||||||
expect_exact: "export default{foo:3,bar:()=>4,get baz(){return this.foo}};"
|
|
||||||
}
|
|
||||||
|
|
||||||
concise_methods_with_computed_property2: {
|
|
||||||
options = {
|
|
||||||
arrows: true,
|
|
||||||
evaluate: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
var foo = {
|
|
||||||
[[1]](v) {
|
|
||||||
return v;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
console.log(foo[[1]]("PASS"));
|
|
||||||
}
|
|
||||||
expect_exact: 'var foo={[[1]]:v=>v};console.log(foo[[1]]("PASS"));'
|
|
||||||
expect_stdout: "PASS"
|
|
||||||
node_version: ">=4"
|
|
||||||
}
|
|
||||||
|
|
||||||
async_object_literal: {
|
|
||||||
options = {
|
|
||||||
arrows: true,
|
|
||||||
unsafe_arrows: true,
|
|
||||||
ecma: 6,
|
|
||||||
evaluate: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
var obj = {
|
|
||||||
async a() {
|
|
||||||
return await foo(1 + 0);
|
|
||||||
},
|
|
||||||
anon: async function() {
|
|
||||||
return await foo(2 + 0);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
var obj = {
|
|
||||||
a: async () => await foo(1),
|
|
||||||
anon: async () => await foo(2)
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
issue_2271: {
|
|
||||||
options = {
|
|
||||||
arrows: true,
|
|
||||||
ecma: 6,
|
|
||||||
evaluate: true,
|
|
||||||
unsafe_arrows: false,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
var Foo = function() {};
|
|
||||||
Foo.prototype.set = function(value) {
|
|
||||||
this.value = value;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
Foo.prototype.print = function() {
|
|
||||||
console.log(this.value);
|
|
||||||
}
|
|
||||||
new Foo().set("PASS").print();
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
var Foo = function() {};
|
|
||||||
Foo.prototype.set = function(value) {
|
|
||||||
this.value = value;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
Foo.prototype.print = function() {
|
|
||||||
console.log(this.value);
|
|
||||||
}
|
|
||||||
new Foo().set("PASS").print();
|
|
||||||
}
|
|
||||||
expect_stdout: "PASS"
|
|
||||||
}
|
|
||||||
|
|
||||||
concise_method_with_super: {
|
|
||||||
options = {
|
|
||||||
arrows: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
var o = {
|
|
||||||
f: "FAIL",
|
|
||||||
g() {
|
|
||||||
return super.f;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Object.setPrototypeOf(o, { f: "PASS" });
|
|
||||||
console.log(o.g());
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
var o = {
|
|
||||||
f: "FAIL",
|
|
||||||
g() {
|
|
||||||
return super.f;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Object.setPrototypeOf(o, { f: "PASS" });
|
|
||||||
console.log(o.g());
|
|
||||||
}
|
|
||||||
expect_stdout: "PASS"
|
|
||||||
node_version: ">=4"
|
|
||||||
}
|
|
||||||
@@ -1,25 +1,25 @@
|
|||||||
asm_mixed: {
|
asm_mixed: {
|
||||||
options = {
|
options = {
|
||||||
sequences : true,
|
assignments: true,
|
||||||
properties : true,
|
booleans: true,
|
||||||
dead_code : true,
|
comparisons: true,
|
||||||
drop_debugger : true,
|
conditionals: true,
|
||||||
conditionals : true,
|
dead_code: true,
|
||||||
comparisons : true,
|
drop_debugger: true,
|
||||||
evaluate : true,
|
evaluate: true,
|
||||||
booleans : true,
|
hoist_funs: true,
|
||||||
loops : true,
|
hoist_vars: true,
|
||||||
unused : true,
|
if_return: true,
|
||||||
hoist_funs : true,
|
join_vars: true,
|
||||||
keep_fargs : true,
|
keep_fargs: true,
|
||||||
keep_fnames : false,
|
keep_fnames: false,
|
||||||
hoist_vars : true,
|
loops: true,
|
||||||
if_return : true,
|
negate_iife: true,
|
||||||
join_vars : true,
|
properties: true,
|
||||||
cascade : true,
|
sequences: true,
|
||||||
side_effects : true,
|
side_effects: true,
|
||||||
negate_iife : true
|
unused: true,
|
||||||
};
|
}
|
||||||
input: {
|
input: {
|
||||||
// adapted from http://asmjs.org/spec/latest/
|
// adapted from http://asmjs.org/spec/latest/
|
||||||
function asm_GeometricMean(stdlib, foreign, buffer) {
|
function asm_GeometricMean(stdlib, foreign, buffer) {
|
||||||
@@ -91,12 +91,11 @@ asm_mixed: {
|
|||||||
function no_asm_GeometricMean(stdlib, foreign, buffer) {
|
function no_asm_GeometricMean(stdlib, foreign, buffer) {
|
||||||
function logSum(start, end) {
|
function logSum(start, end) {
|
||||||
start |= 0, end |= 0;
|
start |= 0, end |= 0;
|
||||||
var sum = 0, p = 0, q = 0;
|
for (var sum = 0, p = 0, q = 0, p = start << 3, q = end << 3; (0 | p) < (0 | q); p = p + 8 | 0) sum += +log(values[p >> 3]);
|
||||||
for (p = start << 3, q = end << 3; (0 | p) < (0 | q); p = p + 8 | 0) sum += +log(values[p >> 3]);
|
|
||||||
return +sum;
|
return +sum;
|
||||||
}
|
}
|
||||||
function geometricMean(start, end) {
|
function geometricMean(start, end) {
|
||||||
return start |= 0, end |= 0, +exp(+logSum(start, end) / +(end - start | 0));
|
return start |= 0, end |= 0, +exp(logSum(start, end) / (end - start | 0));
|
||||||
}
|
}
|
||||||
var exp = stdlib.Math.exp, log = stdlib.Math.log, values = new stdlib.Float64Array(buffer);
|
var exp = stdlib.Math.exp, log = stdlib.Math.log, values = new stdlib.Float64Array(buffer);
|
||||||
return { geometricMean: geometricMean };
|
return { geometricMean: geometricMean };
|
||||||
@@ -166,3 +165,69 @@ asm_nested_functions: {
|
|||||||
}
|
}
|
||||||
expect_exact: '0;function a(){"use asm";0.0}0;function b(){0;function c(){"use asm";0.0}0;function d(){0}0}0;'
|
expect_exact: '0;function a(){"use asm";0.0}0;function b(){0;function c(){"use asm";0.0}0;function d(){0}0}0;'
|
||||||
}
|
}
|
||||||
|
|
||||||
|
issue_3636_1: {
|
||||||
|
mangle = {}
|
||||||
|
input: {
|
||||||
|
function n(stdlib, foreign, buffer) {
|
||||||
|
"use asm";
|
||||||
|
function add(x, y) {
|
||||||
|
x = x | 0;
|
||||||
|
y = y | 0;
|
||||||
|
return x + y | 0;
|
||||||
|
}
|
||||||
|
return {
|
||||||
|
add: add
|
||||||
|
};
|
||||||
|
}
|
||||||
|
console.log(new n().add("foo", 42));
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
function n(o, e, u) {
|
||||||
|
"use asm";
|
||||||
|
function d(n, o) {
|
||||||
|
n = n | 0;
|
||||||
|
o = o | 0;
|
||||||
|
return n + o | 0;
|
||||||
|
}
|
||||||
|
return {
|
||||||
|
add: d
|
||||||
|
};
|
||||||
|
}
|
||||||
|
console.log(new n().add("foo", 42));
|
||||||
|
}
|
||||||
|
expect_stdout: "42"
|
||||||
|
}
|
||||||
|
|
||||||
|
issue_3636_2: {
|
||||||
|
mangle = {}
|
||||||
|
input: {
|
||||||
|
var n = function(stdlib, foreign, buffer) {
|
||||||
|
"use asm";
|
||||||
|
function add(x, y) {
|
||||||
|
x = x | 0;
|
||||||
|
y = y | 0;
|
||||||
|
return x + y | 0;
|
||||||
|
}
|
||||||
|
return {
|
||||||
|
add: add
|
||||||
|
};
|
||||||
|
};
|
||||||
|
console.log(new n().add("foo", 42));
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
var n = function(n, o, e) {
|
||||||
|
"use asm";
|
||||||
|
function r(n, o) {
|
||||||
|
n = n | 0;
|
||||||
|
o = o | 0;
|
||||||
|
return n + o | 0;
|
||||||
|
}
|
||||||
|
return {
|
||||||
|
add: r
|
||||||
|
};
|
||||||
|
};
|
||||||
|
console.log(new n().add("foo", 42));
|
||||||
|
}
|
||||||
|
expect_stdout: "42"
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
op_equals_left_local_var: {
|
op_equals_left_local_var: {
|
||||||
options = {
|
options = {
|
||||||
|
assignments: true,
|
||||||
evaluate: true,
|
evaluate: true,
|
||||||
}
|
}
|
||||||
input: {
|
input: {
|
||||||
@@ -60,6 +61,7 @@ op_equals_left_local_var: {
|
|||||||
|
|
||||||
op_equals_right_local_var: {
|
op_equals_right_local_var: {
|
||||||
options = {
|
options = {
|
||||||
|
assignments: true,
|
||||||
evaluate: true,
|
evaluate: true,
|
||||||
}
|
}
|
||||||
input: {
|
input: {
|
||||||
@@ -123,6 +125,7 @@ op_equals_right_local_var: {
|
|||||||
}
|
}
|
||||||
op_equals_left_global_var: {
|
op_equals_left_global_var: {
|
||||||
options = {
|
options = {
|
||||||
|
assignments: true,
|
||||||
evaluate: true,
|
evaluate: true,
|
||||||
}
|
}
|
||||||
input: {
|
input: {
|
||||||
@@ -179,6 +182,7 @@ op_equals_left_global_var: {
|
|||||||
|
|
||||||
op_equals_right_global_var: {
|
op_equals_right_global_var: {
|
||||||
options = {
|
options = {
|
||||||
|
assignments: true,
|
||||||
evaluate: true,
|
evaluate: true,
|
||||||
}
|
}
|
||||||
input: {
|
input: {
|
||||||
@@ -236,3 +240,170 @@ op_equals_right_global_var: {
|
|||||||
x = g() & x;
|
x = g() & x;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
increment_decrement_1: {
|
||||||
|
options = {
|
||||||
|
assignments: true,
|
||||||
|
reduce_vars: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
console.log(function(a) {
|
||||||
|
a += 1;
|
||||||
|
a -= 1;
|
||||||
|
return a;
|
||||||
|
}(42));
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
console.log(function(a){
|
||||||
|
++a;
|
||||||
|
--a;
|
||||||
|
return a;
|
||||||
|
}(42));
|
||||||
|
}
|
||||||
|
expect_stdout: "42"
|
||||||
|
}
|
||||||
|
|
||||||
|
increment_decrement_2: {
|
||||||
|
options = {
|
||||||
|
assignments: true,
|
||||||
|
passes: 2,
|
||||||
|
reduce_vars: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
console.log(function(a) {
|
||||||
|
a = a + 1;
|
||||||
|
a = a - 1;
|
||||||
|
a += 1;
|
||||||
|
a -= 1;
|
||||||
|
return a;
|
||||||
|
}(42));
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
console.log(function(a){
|
||||||
|
++a;
|
||||||
|
--a;
|
||||||
|
++a;
|
||||||
|
--a;
|
||||||
|
return a;
|
||||||
|
}(42));
|
||||||
|
}
|
||||||
|
expect_stdout: "42"
|
||||||
|
}
|
||||||
|
|
||||||
|
issue_3375_1: {
|
||||||
|
options = {
|
||||||
|
assignments: true,
|
||||||
|
reduce_vars: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
function p(o) {
|
||||||
|
console.log(typeof o, o);
|
||||||
|
}
|
||||||
|
p(function(b) {
|
||||||
|
var a = b += 1;
|
||||||
|
--b;
|
||||||
|
return a;
|
||||||
|
}("object"));
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
function p(o) {
|
||||||
|
console.log(typeof o, o);
|
||||||
|
}
|
||||||
|
p(function(b) {
|
||||||
|
var a = b += 1;
|
||||||
|
--b;
|
||||||
|
return a;
|
||||||
|
}("object"));
|
||||||
|
}
|
||||||
|
expect_stdout: "string object1"
|
||||||
|
}
|
||||||
|
|
||||||
|
issue_3375_2: {
|
||||||
|
options = {
|
||||||
|
assignments: true,
|
||||||
|
reduce_vars: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
function p(o) {
|
||||||
|
console.log(typeof o, o);
|
||||||
|
}
|
||||||
|
p(function(b) {
|
||||||
|
var a = b -= 1;
|
||||||
|
--b;
|
||||||
|
return a;
|
||||||
|
}("object"));
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
function p(o) {
|
||||||
|
console.log(typeof o, o);
|
||||||
|
}
|
||||||
|
p(function(b) {
|
||||||
|
var a = --b;
|
||||||
|
--b;
|
||||||
|
return a;
|
||||||
|
}("object"));
|
||||||
|
}
|
||||||
|
expect_stdout: "number NaN"
|
||||||
|
}
|
||||||
|
|
||||||
|
issue_3427: {
|
||||||
|
options = {
|
||||||
|
assignments: true,
|
||||||
|
sequences: true,
|
||||||
|
side_effects: true,
|
||||||
|
unused: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
(function() {
|
||||||
|
var a;
|
||||||
|
a || (a = {});
|
||||||
|
})();
|
||||||
|
}
|
||||||
|
expect: {}
|
||||||
|
}
|
||||||
|
|
||||||
|
issue_3429_1: {
|
||||||
|
options = {
|
||||||
|
assignments: true,
|
||||||
|
side_effects: true,
|
||||||
|
unused: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
var a = "PASS";
|
||||||
|
(function(b) {
|
||||||
|
b && (b = a = "FAIL");
|
||||||
|
})();
|
||||||
|
console.log(a);
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
var a = "PASS";
|
||||||
|
(function(b) {
|
||||||
|
b = b && (a = "FAIL");
|
||||||
|
})();
|
||||||
|
console.log(a);
|
||||||
|
}
|
||||||
|
expect_stdout: "PASS"
|
||||||
|
}
|
||||||
|
|
||||||
|
issue_3429_2: {
|
||||||
|
options = {
|
||||||
|
assignments: true,
|
||||||
|
side_effects: true,
|
||||||
|
unused: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
var a;
|
||||||
|
(function(b) {
|
||||||
|
b || (b = a = "FAIL");
|
||||||
|
})(42);
|
||||||
|
console.log(a);
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
var a;
|
||||||
|
(function(b) {
|
||||||
|
b = b || (a = "FAIL");
|
||||||
|
})(42);
|
||||||
|
console.log(a);
|
||||||
|
}
|
||||||
|
expect_stdout: "undefined"
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,323 +0,0 @@
|
|||||||
await_precedence: {
|
|
||||||
input: {
|
|
||||||
async function f1() { await x + y; }
|
|
||||||
async function f2() { await (x + y); }
|
|
||||||
}
|
|
||||||
expect_exact: "async function f1(){await x+y}async function f2(){await(x+y)}"
|
|
||||||
}
|
|
||||||
|
|
||||||
await_precedence_prop: {
|
|
||||||
input: {
|
|
||||||
async function f1(){ return (await foo()).bar; }
|
|
||||||
async function f2(){ return (await foo().bar); }
|
|
||||||
}
|
|
||||||
expect_exact: "async function f1(){return(await foo()).bar}async function f2(){return await foo().bar}"
|
|
||||||
}
|
|
||||||
|
|
||||||
await_precedence_call: {
|
|
||||||
input: {
|
|
||||||
async function f3(){ return (await foo())(); }
|
|
||||||
async function f4(){ return await (foo()()); }
|
|
||||||
}
|
|
||||||
expect_exact: "async function f3(){return(await foo())()}async function f4(){return await foo()()}"
|
|
||||||
}
|
|
||||||
|
|
||||||
async_function_declaration: {
|
|
||||||
options = {
|
|
||||||
side_effects: true,
|
|
||||||
unused: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
async function f0() {}
|
|
||||||
async function f1() { await x + y; }
|
|
||||||
async function f2() { await (x + y); }
|
|
||||||
async function f3() { await x + await y; }
|
|
||||||
async function f4() { await (x + await y); }
|
|
||||||
async function f5() { await x; await y; }
|
|
||||||
async function f6() { await x, await y; }
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
async function f0() {}
|
|
||||||
async function f1() { await x, y; }
|
|
||||||
async function f2() { await (x + y); }
|
|
||||||
async function f3() { await x, await y; }
|
|
||||||
async function f4() { await (x + await y); }
|
|
||||||
async function f5() { await x; await y; }
|
|
||||||
async function f6() { await x, await y; }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
async_function_expression: {
|
|
||||||
options = {
|
|
||||||
evaluate: true,
|
|
||||||
side_effects: true,
|
|
||||||
unused: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
var named = async function foo() {
|
|
||||||
await bar(1 + 0) + (2 + 0);
|
|
||||||
}
|
|
||||||
var anon = async function() {
|
|
||||||
await (1 + 0) + bar(2 + 0);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
var named = async function() {
|
|
||||||
await bar(1);
|
|
||||||
};
|
|
||||||
var anon = async function() {
|
|
||||||
await 1, bar(2);
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
async_class: {
|
|
||||||
options = {
|
|
||||||
evaluate: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
class Foo {
|
|
||||||
async m1() {
|
|
||||||
return await foo(1 + 2);
|
|
||||||
}
|
|
||||||
static async m2() {
|
|
||||||
return await foo(3 + 4);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
class Foo {
|
|
||||||
async m1() {
|
|
||||||
return await foo(3);
|
|
||||||
}
|
|
||||||
static async m2() {
|
|
||||||
return await foo(7);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
async_object_literal: {
|
|
||||||
options = {
|
|
||||||
evaluate: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
var obj = {
|
|
||||||
async a() {
|
|
||||||
await foo(1 + 0);
|
|
||||||
},
|
|
||||||
anon: async function(){
|
|
||||||
await foo(2 + 0);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
var obj = {
|
|
||||||
async a() {
|
|
||||||
await foo(1);
|
|
||||||
},
|
|
||||||
anon: async function() {
|
|
||||||
await foo(2);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
async_export: {
|
|
||||||
input: {
|
|
||||||
export async function run() {};
|
|
||||||
export default async function def() {};
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
export async function run() {};
|
|
||||||
export default async function def() {};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
async_inline: {
|
|
||||||
options = {
|
|
||||||
collapse_vars: true,
|
|
||||||
conditionals: true,
|
|
||||||
evaluate: true,
|
|
||||||
inline: true,
|
|
||||||
negate_iife: true,
|
|
||||||
reduce_funcs: true,
|
|
||||||
reduce_vars: true,
|
|
||||||
side_effects: true,
|
|
||||||
toplevel: true,
|
|
||||||
unused: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
(async function(){ return await 3; })();
|
|
||||||
(async function(x){ await console.log(x); })(4);
|
|
||||||
|
|
||||||
function echo(x) { return x; }
|
|
||||||
echo( async function(){ return await 1; }() );
|
|
||||||
echo( async function(x){ await console.log(x); }(2) );
|
|
||||||
|
|
||||||
function top() { console.log("top"); }
|
|
||||||
top();
|
|
||||||
|
|
||||||
async function async_top() { console.log("async_top"); }
|
|
||||||
async_top();
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
!async function(){await 3}();
|
|
||||||
!async function(x){await console.log(4)}();
|
|
||||||
|
|
||||||
function echo(x){return x}
|
|
||||||
echo(async function(){return await 1}());
|
|
||||||
echo(async function(x){await console.log(2)}());
|
|
||||||
|
|
||||||
console.log("top");
|
|
||||||
|
|
||||||
!async function(){console.log("async_top")}();
|
|
||||||
}
|
|
||||||
expect_stdout: [
|
|
||||||
"4",
|
|
||||||
"2",
|
|
||||||
"top",
|
|
||||||
"async_top",
|
|
||||||
]
|
|
||||||
node_version: ">=8"
|
|
||||||
}
|
|
||||||
|
|
||||||
async_identifiers: {
|
|
||||||
input: {
|
|
||||||
var async = function(x){ console.log("async", x); };
|
|
||||||
var await = function(x){ console.log("await", x); };
|
|
||||||
async(1);
|
|
||||||
await(2);
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
var async = function(x){ console.log("async", x); };
|
|
||||||
var await = function(x){ console.log("await", x); };
|
|
||||||
async(1);
|
|
||||||
await(2);
|
|
||||||
}
|
|
||||||
expect_stdout: [
|
|
||||||
"async 1",
|
|
||||||
"await 2",
|
|
||||||
]
|
|
||||||
}
|
|
||||||
|
|
||||||
async_shorthand_property: {
|
|
||||||
mangle = {
|
|
||||||
toplevel: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
function print(o) { console.log(o.async + " " + o.await); }
|
|
||||||
var async = "Async", await = "Await";
|
|
||||||
|
|
||||||
print({ async });
|
|
||||||
print({ await });
|
|
||||||
print({ async, await });
|
|
||||||
print({ await, async });
|
|
||||||
|
|
||||||
print({ async: async });
|
|
||||||
print({ await: await });
|
|
||||||
print({ async: async, await: await });
|
|
||||||
print({ await: await, async: async });
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
function a(a) { console.log(a.async + " " + a.await); }
|
|
||||||
var n = "Async", c = "Await";
|
|
||||||
|
|
||||||
a({ async: n });
|
|
||||||
a({ await: c });
|
|
||||||
a({ async: n, await: c });
|
|
||||||
a({ await: c, async: n });
|
|
||||||
|
|
||||||
a({ async: n });
|
|
||||||
a({ await: c });
|
|
||||||
a({ async: n, await: c });
|
|
||||||
a({ await: c, async: n });
|
|
||||||
}
|
|
||||||
expect_stdout: [
|
|
||||||
"Async undefined",
|
|
||||||
"undefined Await",
|
|
||||||
"Async Await",
|
|
||||||
"Async Await",
|
|
||||||
"Async undefined",
|
|
||||||
"undefined Await",
|
|
||||||
"Async Await",
|
|
||||||
"Async Await",
|
|
||||||
]
|
|
||||||
node_version: ">=4"
|
|
||||||
}
|
|
||||||
|
|
||||||
async_arrow: {
|
|
||||||
input: {
|
|
||||||
let a1 = async x => await foo(x);
|
|
||||||
let a2 = async () => await bar();
|
|
||||||
let a3 = async (x) => await baz(x);
|
|
||||||
let a4 = async (x, y) => { await far(x, y); }
|
|
||||||
let a5 = async ({x = [1], y: z = 2}) => { await wow(x, z); }
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
let a1 = async x => await foo(x);
|
|
||||||
let a2 = async () => await bar();
|
|
||||||
let a3 = async (x) => await baz(x);
|
|
||||||
let a4 = async (x, y) => { await far(x, y); }
|
|
||||||
let a5 = async ({x = [1], y: z = 2}) => { await wow(x, z); }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
async_arrow_wait: {
|
|
||||||
input: {
|
|
||||||
var a = async (x, y) => await x(y);
|
|
||||||
}
|
|
||||||
expect_exact: "var a=async(x,y)=>await x(y);"
|
|
||||||
}
|
|
||||||
|
|
||||||
async_arrow_iife: {
|
|
||||||
input: {
|
|
||||||
(async () => {
|
|
||||||
await fetch({});
|
|
||||||
})();
|
|
||||||
}
|
|
||||||
expect_exact: "(async()=>{await fetch({})})();"
|
|
||||||
}
|
|
||||||
|
|
||||||
async_arrow_iife_negate_iife: {
|
|
||||||
options = {
|
|
||||||
negate_iife: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
(async () => {
|
|
||||||
await fetch();
|
|
||||||
})();
|
|
||||||
(() => {
|
|
||||||
plain();
|
|
||||||
})();
|
|
||||||
}
|
|
||||||
expect_exact: "(async()=>{await fetch()})();(()=>{plain()})();"
|
|
||||||
}
|
|
||||||
|
|
||||||
issue_2344_1: {
|
|
||||||
beautify = {
|
|
||||||
safari10: false,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
async () => {
|
|
||||||
+await x;
|
|
||||||
await y;
|
|
||||||
return await z;
|
|
||||||
};
|
|
||||||
}
|
|
||||||
expect_exact: "async()=>{+await x;await y;return await z};"
|
|
||||||
}
|
|
||||||
|
|
||||||
issue_2344_2: {
|
|
||||||
beautify = {
|
|
||||||
safari10: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
async () => {
|
|
||||||
+await x;
|
|
||||||
await y;
|
|
||||||
return await z;
|
|
||||||
};
|
|
||||||
}
|
|
||||||
expect_exact: "async()=>{+(await x);await y;return await z};"
|
|
||||||
}
|
|
||||||
@@ -1,191 +0,0 @@
|
|||||||
|
|
||||||
let_statement: {
|
|
||||||
input: {
|
|
||||||
let x = 6;
|
|
||||||
}
|
|
||||||
expect_exact: "let x=6;"
|
|
||||||
}
|
|
||||||
|
|
||||||
do_not_hoist_let: {
|
|
||||||
options = {
|
|
||||||
hoist_vars: true,
|
|
||||||
};
|
|
||||||
input: {
|
|
||||||
function x() {
|
|
||||||
if (FOO) {
|
|
||||||
let let1;
|
|
||||||
let let2;
|
|
||||||
var var1;
|
|
||||||
var var2;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
function x() {
|
|
||||||
var var1, var2;
|
|
||||||
if (FOO) {
|
|
||||||
let let1;
|
|
||||||
let let2;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
do_not_remove_anon_blocks_if_they_have_decls: {
|
|
||||||
input: {
|
|
||||||
function x() {
|
|
||||||
{
|
|
||||||
let x;
|
|
||||||
}
|
|
||||||
{
|
|
||||||
var x;
|
|
||||||
}
|
|
||||||
{
|
|
||||||
const y;
|
|
||||||
class Zee {};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
{
|
|
||||||
let y;
|
|
||||||
}
|
|
||||||
{
|
|
||||||
var y;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
function x(){
|
|
||||||
{
|
|
||||||
let x
|
|
||||||
}
|
|
||||||
var x;
|
|
||||||
{
|
|
||||||
const y;
|
|
||||||
class Zee {}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
{
|
|
||||||
let y
|
|
||||||
}
|
|
||||||
var y;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
remove_unused_in_global_block: {
|
|
||||||
options = {
|
|
||||||
unused: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
{
|
|
||||||
let x;
|
|
||||||
const y;
|
|
||||||
class Zee {};
|
|
||||||
var w;
|
|
||||||
}
|
|
||||||
let ex;
|
|
||||||
const why;
|
|
||||||
class Zed {};
|
|
||||||
var wut;
|
|
||||||
console.log(x, y, Zee);
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
var w;
|
|
||||||
let ex;
|
|
||||||
const why;
|
|
||||||
class Zed {};
|
|
||||||
var wut;
|
|
||||||
console.log(x, y, Zee);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
regression_block_scope_resolves: {
|
|
||||||
mangle = { };
|
|
||||||
options = {
|
|
||||||
dead_code: false
|
|
||||||
};
|
|
||||||
input: {
|
|
||||||
(function () {
|
|
||||||
if (1) {
|
|
||||||
let x;
|
|
||||||
const y = 1;
|
|
||||||
class Zee {};
|
|
||||||
}
|
|
||||||
if (1) {
|
|
||||||
let ex;
|
|
||||||
const why = 2;
|
|
||||||
class Zi {};
|
|
||||||
}
|
|
||||||
console.log(typeof x, typeof y, typeof Zee, typeof ex, typeof why, typeof Zi);
|
|
||||||
}());
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
(function () {
|
|
||||||
if (1) {
|
|
||||||
let e;
|
|
||||||
const o = 1;
|
|
||||||
class t {};
|
|
||||||
}
|
|
||||||
if (1) {
|
|
||||||
let e;
|
|
||||||
const o = 2;
|
|
||||||
class t {};
|
|
||||||
}
|
|
||||||
console.log(typeof x, typeof y, typeof Zee, typeof ex, typeof why, typeof Zi);
|
|
||||||
}());
|
|
||||||
}
|
|
||||||
expect_stdout: "undefined undefined undefined undefined undefined undefined"
|
|
||||||
node_version: ">=6"
|
|
||||||
}
|
|
||||||
|
|
||||||
switch_block_scope_mangler: {
|
|
||||||
mangle = {}
|
|
||||||
input: {
|
|
||||||
var fn = function(code) {
|
|
||||||
switch (code) {
|
|
||||||
case 1:
|
|
||||||
let apple = code + 1;
|
|
||||||
let dog = code + 4;
|
|
||||||
console.log(apple, dog);
|
|
||||||
break;
|
|
||||||
case 2:
|
|
||||||
let banana = code + 2;
|
|
||||||
console.log(banana);
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
let cat = code + 3;
|
|
||||||
console.log(cat);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
fn(1);
|
|
||||||
fn(2);
|
|
||||||
fn(3);
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
var fn = function(e) {
|
|
||||||
switch (e) {
|
|
||||||
case 1:
|
|
||||||
let l = e + 1
|
|
||||||
let o = e + 4;
|
|
||||||
console.log(l, o);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 2:
|
|
||||||
let n = e + 2;
|
|
||||||
console.log(n);
|
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
|
||||||
let c = e + 3;
|
|
||||||
console.log(c);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
fn(1);
|
|
||||||
fn(2);
|
|
||||||
fn(3);
|
|
||||||
}
|
|
||||||
expect_stdout: [
|
|
||||||
"2 5",
|
|
||||||
"4",
|
|
||||||
"6",
|
|
||||||
]
|
|
||||||
node_version: ">=6"
|
|
||||||
}
|
|
||||||
@@ -47,142 +47,3 @@ keep_some_blocks: {
|
|||||||
} else stuff();
|
} else stuff();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
issue_1664: {
|
|
||||||
input: {
|
|
||||||
var a = 1;
|
|
||||||
function f() {
|
|
||||||
if (undefined) a = 2;
|
|
||||||
{
|
|
||||||
function undefined() {}
|
|
||||||
undefined();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
f();
|
|
||||||
console.log(a);
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
var a = 1;
|
|
||||||
function f() {
|
|
||||||
if (undefined) a = 2;
|
|
||||||
{
|
|
||||||
function undefined() {}
|
|
||||||
undefined();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
f();
|
|
||||||
console.log(a);
|
|
||||||
}
|
|
||||||
expect_stdout: "1"
|
|
||||||
node_version: ">=6"
|
|
||||||
}
|
|
||||||
|
|
||||||
issue_1672_for: {
|
|
||||||
input: {
|
|
||||||
switch (function() {
|
|
||||||
return xxx;
|
|
||||||
}) {
|
|
||||||
case xxx:
|
|
||||||
for (; console.log("FAIL");) {
|
|
||||||
function xxx() {}
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
switch (function() {
|
|
||||||
return xxx;
|
|
||||||
}) {
|
|
||||||
case xxx:
|
|
||||||
for (; console.log("FAIL");) {
|
|
||||||
function xxx() {}
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
expect_stdout: true
|
|
||||||
node_version: ">=6"
|
|
||||||
}
|
|
||||||
|
|
||||||
issue_1672_for_strict: {
|
|
||||||
input: {
|
|
||||||
"use strict";
|
|
||||||
switch (function() {
|
|
||||||
return xxx;
|
|
||||||
}) {
|
|
||||||
case xxx:
|
|
||||||
for (; console.log("FAIL");) {
|
|
||||||
function xxx() {}
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
"use strict";
|
|
||||||
switch (function() {
|
|
||||||
return xxx;
|
|
||||||
}) {
|
|
||||||
case xxx:
|
|
||||||
for (; console.log("FAIL");) {
|
|
||||||
function xxx() {}
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
expect_stdout: true
|
|
||||||
node_version: ">=6"
|
|
||||||
}
|
|
||||||
|
|
||||||
issue_1672_if: {
|
|
||||||
input: {
|
|
||||||
switch (function() {
|
|
||||||
return xxx;
|
|
||||||
}) {
|
|
||||||
case xxx:
|
|
||||||
if (console.log("FAIL")) {
|
|
||||||
function xxx() {}
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
switch (function() {
|
|
||||||
return xxx;
|
|
||||||
}) {
|
|
||||||
case xxx:
|
|
||||||
if (console.log("FAIL")) function xxx() {}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
expect_stdout: true
|
|
||||||
node_version: ">=6"
|
|
||||||
}
|
|
||||||
|
|
||||||
issue_1672_if_strict: {
|
|
||||||
input: {
|
|
||||||
"use strict";
|
|
||||||
switch (function() {
|
|
||||||
return xxx;
|
|
||||||
}) {
|
|
||||||
case xxx:
|
|
||||||
if (console.log("FAIL")) {
|
|
||||||
function xxx() {}
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
"use strict";
|
|
||||||
switch (function() {
|
|
||||||
return xxx;
|
|
||||||
}) {
|
|
||||||
case xxx:
|
|
||||||
if (console.log("FAIL")) {
|
|
||||||
function xxx() {}
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
expect_stdout: true
|
|
||||||
node_version: ">=6"
|
|
||||||
}
|
|
||||||
|
|||||||
155
test/compress/booleans.js
Normal file
155
test/compress/booleans.js
Normal file
@@ -0,0 +1,155 @@
|
|||||||
|
iife_boolean_context: {
|
||||||
|
options = {
|
||||||
|
booleans: true,
|
||||||
|
evaluate: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
console.log(function() {
|
||||||
|
return Object(1) || false;
|
||||||
|
}() ? "PASS" : "FAIL");
|
||||||
|
console.log(function() {
|
||||||
|
return [].length || true;
|
||||||
|
}() ? "PASS" : "FAIL");
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
console.log(function() {
|
||||||
|
return Object(1);
|
||||||
|
}() ? "PASS" : "FAIL");
|
||||||
|
console.log(function() {
|
||||||
|
return [].length, 1;
|
||||||
|
}() ? "PASS" : "FAIL");
|
||||||
|
}
|
||||||
|
expect_stdout: [
|
||||||
|
"PASS",
|
||||||
|
"PASS",
|
||||||
|
]
|
||||||
|
expect_warnings: [
|
||||||
|
"WARN: Dropping side-effect-free || [test/compress/booleans.js:2,19]",
|
||||||
|
"WARN: Boolean || always true [test/compress/booleans.js:5,19]",
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
|
issue_3465_1: {
|
||||||
|
options = {
|
||||||
|
booleans: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
console.log(function(a) {
|
||||||
|
return typeof a;
|
||||||
|
}() ? "PASS" : "FAIL");
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
console.log(function(a) {
|
||||||
|
return 1;
|
||||||
|
}() ? "PASS" : "FAIL");
|
||||||
|
}
|
||||||
|
expect_stdout: "PASS"
|
||||||
|
}
|
||||||
|
|
||||||
|
issue_3465_2: {
|
||||||
|
options = {
|
||||||
|
booleans: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
console.log(function f(a) {
|
||||||
|
if (!a) console.log(f(42));
|
||||||
|
return typeof a;
|
||||||
|
}() ? "PASS" : "FAIL");
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
console.log(function f(a) {
|
||||||
|
if (!a) console.log(f(42));
|
||||||
|
return typeof a;
|
||||||
|
}() ? "PASS" : "FAIL");
|
||||||
|
}
|
||||||
|
expect_stdout: [
|
||||||
|
"number",
|
||||||
|
"PASS",
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
|
issue_3465_3: {
|
||||||
|
options = {
|
||||||
|
booleans: true,
|
||||||
|
passes: 2,
|
||||||
|
unused: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
console.log(function f(a) {
|
||||||
|
return typeof a;
|
||||||
|
}() ? "PASS" : "FAIL");
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
console.log(function(a) {
|
||||||
|
return 1;
|
||||||
|
}() ? "PASS" : "FAIL");
|
||||||
|
}
|
||||||
|
expect_stdout: "PASS"
|
||||||
|
}
|
||||||
|
|
||||||
|
issue_2737_2: {
|
||||||
|
options = {
|
||||||
|
booleans: true,
|
||||||
|
inline: true,
|
||||||
|
reduce_vars: true,
|
||||||
|
unused: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
(function(bar) {
|
||||||
|
for (;bar();) break;
|
||||||
|
})(function qux() {
|
||||||
|
return console.log("PASS"), qux;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
(function(bar) {
|
||||||
|
for (;bar();) break;
|
||||||
|
})(function() {
|
||||||
|
return console.log("PASS"), 1;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
expect_stdout: "PASS"
|
||||||
|
}
|
||||||
|
|
||||||
|
issue_3658: {
|
||||||
|
options = {
|
||||||
|
booleans: true,
|
||||||
|
evaluate: true,
|
||||||
|
reduce_vars: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
console.log(function f() {
|
||||||
|
console || f();
|
||||||
|
return "PASS";
|
||||||
|
}());
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
console.log(function f() {
|
||||||
|
console || f();
|
||||||
|
return "PASS";
|
||||||
|
}());
|
||||||
|
}
|
||||||
|
expect_stdout: "PASS"
|
||||||
|
}
|
||||||
|
|
||||||
|
issue_3690: {
|
||||||
|
options = {
|
||||||
|
booleans: true,
|
||||||
|
unused: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
console.log(function(a) {
|
||||||
|
return function() {
|
||||||
|
return a = [ this ];
|
||||||
|
}() ? "PASS" : "FAIL";
|
||||||
|
}());
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
console.log(function(a) {
|
||||||
|
return function() {
|
||||||
|
return 1;
|
||||||
|
}() ? "PASS" : "FAIL";
|
||||||
|
}());
|
||||||
|
}
|
||||||
|
expect_stdout: "PASS"
|
||||||
|
}
|
||||||
File diff suppressed because it is too large
Load Diff
@@ -1,114 +0,0 @@
|
|||||||
keep_comparisons: {
|
|
||||||
options = {
|
|
||||||
comparisons: true,
|
|
||||||
unsafe_comps: false
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
var obj1 = {
|
|
||||||
valueOf: function() {triggeredFirst();}
|
|
||||||
}
|
|
||||||
var obj2 = {
|
|
||||||
valueOf: function() {triggeredSecond();}
|
|
||||||
}
|
|
||||||
var result1 = obj1 <= obj2;
|
|
||||||
var result2 = obj1 < obj2;
|
|
||||||
var result3 = obj1 >= obj2;
|
|
||||||
var result4 = obj1 > obj2;
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
var obj1 = {
|
|
||||||
valueOf: function() {triggeredFirst();}
|
|
||||||
}
|
|
||||||
var obj2 = {
|
|
||||||
valueOf: function() {triggeredSecond();}
|
|
||||||
}
|
|
||||||
var result1 = obj1 <= obj2;
|
|
||||||
var result2 = obj1 < obj2;
|
|
||||||
var result3 = obj1 >= obj2;
|
|
||||||
var result4 = obj1 > obj2;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
keep_comparisons_with_unsafe_comps: {
|
|
||||||
options = {
|
|
||||||
comparisons: true,
|
|
||||||
unsafe_comps: true
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
var obj1 = {
|
|
||||||
valueOf: function() {triggeredFirst();}
|
|
||||||
}
|
|
||||||
var obj2 = {
|
|
||||||
valueOf: function() {triggeredSecond();}
|
|
||||||
}
|
|
||||||
var result1 = obj1 <= obj2;
|
|
||||||
var result2 = obj1 < obj2;
|
|
||||||
var result3 = obj1 >= obj2;
|
|
||||||
var result4 = obj1 > obj2;
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
var obj1 = {
|
|
||||||
valueOf: function() {triggeredFirst();}
|
|
||||||
}
|
|
||||||
var obj2 = {
|
|
||||||
valueOf: function() {triggeredSecond();}
|
|
||||||
}
|
|
||||||
var result1 = obj2 >= obj1;
|
|
||||||
var result2 = obj2 > obj1;
|
|
||||||
var result3 = obj1 >= obj2;
|
|
||||||
var result4 = obj1 > obj2;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
dont_change_in_or_instanceof_expressions: {
|
|
||||||
input: {
|
|
||||||
1 in 1;
|
|
||||||
null in null;
|
|
||||||
1 instanceof 1;
|
|
||||||
null instanceof null;
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
1 in 1;
|
|
||||||
null in null;
|
|
||||||
1 instanceof 1;
|
|
||||||
null instanceof null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
self_comparison_1: {
|
|
||||||
options = {
|
|
||||||
comparisons: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
a === a;
|
|
||||||
a !== b;
|
|
||||||
b.c === a.c;
|
|
||||||
b.c !== b.c;
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
a == a;
|
|
||||||
a !== b;
|
|
||||||
b.c === a.c;
|
|
||||||
b.c != b.c;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
self_comparison_2: {
|
|
||||||
options = {
|
|
||||||
comparisons: true,
|
|
||||||
reduce_funcs: true,
|
|
||||||
reduce_vars: true,
|
|
||||||
toplevel: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
function f() {}
|
|
||||||
var o = {};
|
|
||||||
console.log(f != f, o === o);
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
function f() {}
|
|
||||||
var o = {};
|
|
||||||
console.log(false, true);
|
|
||||||
}
|
|
||||||
expect_stdout: "false true"
|
|
||||||
}
|
|
||||||
472
test/compress/comparisons.js
Normal file
472
test/compress/comparisons.js
Normal file
@@ -0,0 +1,472 @@
|
|||||||
|
comparisons: {
|
||||||
|
options = {
|
||||||
|
comparisons: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
var obj1, obj2;
|
||||||
|
var result1 = obj1 <= obj2;
|
||||||
|
var result2 = obj1 < obj2;
|
||||||
|
var result3 = obj1 >= obj2;
|
||||||
|
var result4 = obj1 > obj2;
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
var obj1, obj2;
|
||||||
|
var result1 = obj1 <= obj2;
|
||||||
|
var result2 = obj1 < obj2;
|
||||||
|
var result3 = obj2 <= obj1;
|
||||||
|
var result4 = obj2 < obj1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
unsafe_comps: {
|
||||||
|
options = {
|
||||||
|
comparisons: true,
|
||||||
|
conditionals: true,
|
||||||
|
unsafe_comps: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
var obj1, obj2;
|
||||||
|
obj1 <= obj2 ? f1() : g1();
|
||||||
|
obj1 < obj2 ? f2() : g2();
|
||||||
|
obj1 >= obj2 ? f3() : g3();
|
||||||
|
obj1 > obj2 ? f4() : g4();
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
var obj1, obj2;
|
||||||
|
(obj2 < obj1 ? g1 : f1)();
|
||||||
|
(obj1 < obj2 ? f2 : g2)();
|
||||||
|
(obj1 < obj2 ? g3 : f3)();
|
||||||
|
(obj2 < obj1 ? f4 : g4)();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
dont_change_in_or_instanceof_expressions: {
|
||||||
|
input: {
|
||||||
|
1 in 1;
|
||||||
|
null in null;
|
||||||
|
1 instanceof 1;
|
||||||
|
null instanceof null;
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
1 in 1;
|
||||||
|
null in null;
|
||||||
|
1 instanceof 1;
|
||||||
|
null instanceof null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
self_comparison_1: {
|
||||||
|
options = {
|
||||||
|
comparisons: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
a === a;
|
||||||
|
a !== b;
|
||||||
|
b.c === a.c;
|
||||||
|
b.c !== b.c;
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
a == a;
|
||||||
|
a !== b;
|
||||||
|
b.c === a.c;
|
||||||
|
b.c != b.c;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
self_comparison_2: {
|
||||||
|
options = {
|
||||||
|
comparisons: true,
|
||||||
|
reduce_funcs: true,
|
||||||
|
reduce_vars: true,
|
||||||
|
toplevel: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
function f() {}
|
||||||
|
var o = {};
|
||||||
|
console.log(f != f, o === o);
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
function f() {}
|
||||||
|
var o = {};
|
||||||
|
console.log(false, true);
|
||||||
|
}
|
||||||
|
expect_stdout: "false true"
|
||||||
|
}
|
||||||
|
|
||||||
|
self_comparison_3: {
|
||||||
|
options = {
|
||||||
|
comparisons: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
var a;
|
||||||
|
function f() {
|
||||||
|
var b = a;
|
||||||
|
a = null;
|
||||||
|
return b;
|
||||||
|
}
|
||||||
|
for (var i = 0; i < 2; i++)
|
||||||
|
console.log(f() === f());
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
var a;
|
||||||
|
function f() {
|
||||||
|
var b = a;
|
||||||
|
a = null;
|
||||||
|
return b;
|
||||||
|
}
|
||||||
|
for (var i = 0; i < 2; i++)
|
||||||
|
console.log(f() === f());
|
||||||
|
}
|
||||||
|
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"
|
||||||
|
}
|
||||||
|
|
||||||
|
is_boolean_unsafe: {
|
||||||
|
options = {
|
||||||
|
comparisons: true,
|
||||||
|
unsafe: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
console.log(/foo/.test("bar") === [].isPrototypeOf({}));
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
console.log(/foo/.test("bar") == [].isPrototypeOf({}));
|
||||||
|
}
|
||||||
|
expect_stdout: "true"
|
||||||
|
}
|
||||||
|
|
||||||
|
is_number_unsafe: {
|
||||||
|
options = {
|
||||||
|
comparisons: true,
|
||||||
|
unsafe: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
console.log(Math.acos(42) !== "foo".charCodeAt(4));
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
console.log(Math.acos(42) != "foo".charCodeAt(4));
|
||||||
|
}
|
||||||
|
expect_stdout: "true"
|
||||||
|
}
|
||||||
|
|
||||||
|
is_boolean_var: {
|
||||||
|
options = {
|
||||||
|
comparisons: true,
|
||||||
|
reduce_vars: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
console.log(function(a, b) {
|
||||||
|
for (var i = 0, c = !b; i < a.length; i++)
|
||||||
|
if (!a[i] === c)
|
||||||
|
return i;
|
||||||
|
}([ false, true ], 42));
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
console.log(function(a, b) {
|
||||||
|
for (var i = 0, c = !b; i < a.length; i++)
|
||||||
|
if (!a[i] == c)
|
||||||
|
return i;
|
||||||
|
}([ false, true ], 42));
|
||||||
|
}
|
||||||
|
expect_stdout: "1"
|
||||||
|
}
|
||||||
|
|
||||||
|
is_defined: {
|
||||||
|
options = {
|
||||||
|
comparisons: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
console.log(function a() {
|
||||||
|
return void 0 === a;
|
||||||
|
}());
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
console.log(function a() {
|
||||||
|
return a, false;
|
||||||
|
}());
|
||||||
|
}
|
||||||
|
expect_stdout: "false"
|
||||||
|
expect_warnings: [
|
||||||
|
"WARN: Expression always defined [test/compress/comparisons.js:2,19]",
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
|
unsafe_indexOf: {
|
||||||
|
options = {
|
||||||
|
booleans: true,
|
||||||
|
comparisons: true,
|
||||||
|
unsafe: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
var a = Object.keys({ foo: 42 });
|
||||||
|
if (a.indexOf("bar") < 0) console.log("PASS");
|
||||||
|
if (0 > a.indexOf("bar")) console.log("PASS");
|
||||||
|
if (a.indexOf("foo") >= 0) console.log("PASS");
|
||||||
|
if (0 <= a.indexOf("foo")) console.log("PASS");
|
||||||
|
if (a.indexOf("foo") > -1) console.log("PASS");
|
||||||
|
if (-1 < a.indexOf("foo")) console.log("PASS");
|
||||||
|
if (a.indexOf("bar") == -1) console.log("PASS");
|
||||||
|
if (-1 == a.indexOf("bar")) console.log("PASS");
|
||||||
|
if (a.indexOf("bar") === -1) console.log("PASS");
|
||||||
|
if (-1 === a.indexOf("bar")) console.log("PASS");
|
||||||
|
if (a.indexOf("foo") != -1) console.log("PASS");
|
||||||
|
if (-1 != a.indexOf("foo")) console.log("PASS");
|
||||||
|
if (a.indexOf("foo") !== -1) console.log("PASS");
|
||||||
|
if (-1 !== a.indexOf("foo")) console.log("PASS");
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
var a = Object.keys({ foo: 42 });
|
||||||
|
if (!~a.indexOf("bar")) console.log("PASS");
|
||||||
|
if (!~a.indexOf("bar")) console.log("PASS");
|
||||||
|
if (~a.indexOf("foo")) console.log("PASS");
|
||||||
|
if (~a.indexOf("foo")) console.log("PASS");
|
||||||
|
if (~a.indexOf("foo")) console.log("PASS");
|
||||||
|
if (~a.indexOf("foo")) console.log("PASS");
|
||||||
|
if (!~a.indexOf("bar")) console.log("PASS");
|
||||||
|
if (!~a.indexOf("bar")) console.log("PASS");
|
||||||
|
if (!~a.indexOf("bar")) console.log("PASS");
|
||||||
|
if (!~a.indexOf("bar")) console.log("PASS");
|
||||||
|
if (~a.indexOf("foo")) console.log("PASS");
|
||||||
|
if (~a.indexOf("foo")) console.log("PASS");
|
||||||
|
if (~a.indexOf("foo")) console.log("PASS");
|
||||||
|
if (~a.indexOf("foo")) console.log("PASS");
|
||||||
|
}
|
||||||
|
expect_stdout: [
|
||||||
|
"PASS",
|
||||||
|
"PASS",
|
||||||
|
"PASS",
|
||||||
|
"PASS",
|
||||||
|
"PASS",
|
||||||
|
"PASS",
|
||||||
|
"PASS",
|
||||||
|
"PASS",
|
||||||
|
"PASS",
|
||||||
|
"PASS",
|
||||||
|
"PASS",
|
||||||
|
"PASS",
|
||||||
|
"PASS",
|
||||||
|
"PASS",
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
|
issue_3413: {
|
||||||
|
options = {
|
||||||
|
comparisons: true,
|
||||||
|
evaluate: true,
|
||||||
|
side_effects: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
var b;
|
||||||
|
void 0 !== ("" < b || void 0) || console.log("PASS");
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
var b;
|
||||||
|
void 0 !== ("" < b || void 0) || console.log("PASS");
|
||||||
|
}
|
||||||
|
expect_stdout: "PASS"
|
||||||
|
}
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
concat_1: {
|
concat_1: {
|
||||||
options = {
|
options = {
|
||||||
evaluate: true
|
evaluate: true,
|
||||||
};
|
}
|
||||||
input: {
|
input: {
|
||||||
var a = "foo" + "bar" + x() + "moo" + "foo" + y() + "x" + "y" + "z" + q();
|
var a = "foo" + "bar" + x() + "moo" + "foo" + y() + "x" + "y" + "z" + q();
|
||||||
var b = "foo" + 1 + x() + 2 + "boo";
|
var b = "foo" + 1 + x() + 2 + "boo";
|
||||||
@@ -26,7 +26,9 @@ concat_1: {
|
|||||||
}
|
}
|
||||||
|
|
||||||
concat_2: {
|
concat_2: {
|
||||||
options = {};
|
options = {
|
||||||
|
strings: true,
|
||||||
|
}
|
||||||
input: {
|
input: {
|
||||||
console.log(
|
console.log(
|
||||||
1 + (2 + 3),
|
1 + (2 + 3),
|
||||||
@@ -55,7 +57,9 @@ concat_2: {
|
|||||||
}
|
}
|
||||||
|
|
||||||
concat_3: {
|
concat_3: {
|
||||||
options = {};
|
options = {
|
||||||
|
strings: true,
|
||||||
|
}
|
||||||
input: {
|
input: {
|
||||||
console.log(
|
console.log(
|
||||||
1 + 2 + (3 + 4 + 5),
|
1 + 2 + (3 + 4 + 5),
|
||||||
@@ -84,7 +88,9 @@ concat_3: {
|
|||||||
}
|
}
|
||||||
|
|
||||||
concat_4: {
|
concat_4: {
|
||||||
options = {};
|
options = {
|
||||||
|
strings: true,
|
||||||
|
}
|
||||||
input: {
|
input: {
|
||||||
console.log(
|
console.log(
|
||||||
1 + "2" + (3 + 4 + 5),
|
1 + "2" + (3 + 4 + 5),
|
||||||
@@ -113,7 +119,9 @@ concat_4: {
|
|||||||
}
|
}
|
||||||
|
|
||||||
concat_5: {
|
concat_5: {
|
||||||
options = {};
|
options = {
|
||||||
|
strings: true,
|
||||||
|
}
|
||||||
input: {
|
input: {
|
||||||
console.log(
|
console.log(
|
||||||
"1" + 2 + (3 + 4 + 5),
|
"1" + 2 + (3 + 4 + 5),
|
||||||
@@ -142,7 +150,9 @@ concat_5: {
|
|||||||
}
|
}
|
||||||
|
|
||||||
concat_6: {
|
concat_6: {
|
||||||
options = {};
|
options = {
|
||||||
|
strings: true,
|
||||||
|
}
|
||||||
input: {
|
input: {
|
||||||
console.log(
|
console.log(
|
||||||
"1" + "2" + (3 + 4 + 5),
|
"1" + "2" + (3 + 4 + 5),
|
||||||
@@ -171,6 +181,9 @@ concat_6: {
|
|||||||
}
|
}
|
||||||
|
|
||||||
concat_7: {
|
concat_7: {
|
||||||
|
options = {
|
||||||
|
strings: true,
|
||||||
|
}
|
||||||
input: {
|
input: {
|
||||||
console.log(
|
console.log(
|
||||||
"" + 1,
|
"" + 1,
|
||||||
@@ -197,6 +210,9 @@ concat_7: {
|
|||||||
}
|
}
|
||||||
|
|
||||||
concat_8: {
|
concat_8: {
|
||||||
|
options = {
|
||||||
|
strings: true,
|
||||||
|
}
|
||||||
input: {
|
input: {
|
||||||
console.log(
|
console.log(
|
||||||
1 + "",
|
1 + "",
|
||||||
@@ -221,3 +237,20 @@ concat_8: {
|
|||||||
}
|
}
|
||||||
expect_stdout: true
|
expect_stdout: true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
issue_3689: {
|
||||||
|
options = {
|
||||||
|
strings: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
console.log(function(a) {
|
||||||
|
return a + ("" + (a[0] = 0));
|
||||||
|
}([]));
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
console.log(function(a) {
|
||||||
|
return a + ("" + (a[0] = 0));
|
||||||
|
}([]));
|
||||||
|
}
|
||||||
|
expect_stdout: "00"
|
||||||
|
}
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@@ -1,170 +0,0 @@
|
|||||||
issue_1191: {
|
|
||||||
options = {
|
|
||||||
evaluate : true,
|
|
||||||
booleans : true,
|
|
||||||
comparisons : true,
|
|
||||||
dead_code : true,
|
|
||||||
conditionals : true,
|
|
||||||
side_effects : true,
|
|
||||||
unused : true,
|
|
||||||
hoist_funs : true,
|
|
||||||
if_return : true,
|
|
||||||
join_vars : true,
|
|
||||||
sequences : false,
|
|
||||||
collapse_vars : false,
|
|
||||||
reduce_funcs : true,
|
|
||||||
reduce_vars : true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
function foo(rot) {
|
|
||||||
const rotTol = 5;
|
|
||||||
if (rot < -rotTol || rot > rotTol)
|
|
||||||
bar();
|
|
||||||
baz();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
function foo(rot) {
|
|
||||||
(rot < -5 || rot > 5) && bar();
|
|
||||||
baz();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
issue_1194: {
|
|
||||||
options = {
|
|
||||||
evaluate : true,
|
|
||||||
booleans : true,
|
|
||||||
comparisons : true,
|
|
||||||
dead_code : true,
|
|
||||||
conditionals : true,
|
|
||||||
side_effects : true,
|
|
||||||
unused : true,
|
|
||||||
hoist_funs : true,
|
|
||||||
if_return : true,
|
|
||||||
join_vars : true,
|
|
||||||
sequences : false,
|
|
||||||
collapse_vars : false,
|
|
||||||
reduce_funcs : true,
|
|
||||||
reduce_vars : true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
function f1() {const a = "X"; return a + a;}
|
|
||||||
function f2() {const aa = "X"; return aa + aa;}
|
|
||||||
function f3() {const aaa = "X"; return aaa + aaa;}
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
function f1(){return"XX"}
|
|
||||||
function f2(){return"XX"}
|
|
||||||
function f3(){return"XX"}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
issue_1396: {
|
|
||||||
options = {
|
|
||||||
evaluate : true,
|
|
||||||
booleans : true,
|
|
||||||
comparisons : true,
|
|
||||||
dead_code : true,
|
|
||||||
conditionals : true,
|
|
||||||
side_effects : true,
|
|
||||||
unused : true,
|
|
||||||
hoist_funs : true,
|
|
||||||
if_return : true,
|
|
||||||
join_vars : true,
|
|
||||||
sequences : false,
|
|
||||||
collapse_vars : false,
|
|
||||||
reduce_funcs : true,
|
|
||||||
reduce_vars : true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
function foo(a) {
|
|
||||||
const VALUE = 1;
|
|
||||||
console.log(2 | VALUE);
|
|
||||||
console.log(VALUE + 1);
|
|
||||||
console.log(VALUE);
|
|
||||||
console.log(a & VALUE);
|
|
||||||
}
|
|
||||||
function bar() {
|
|
||||||
const s = "01234567890123456789";
|
|
||||||
console.log(s + s + s + s + s);
|
|
||||||
|
|
||||||
const CONSTANT = "abc";
|
|
||||||
console.log(CONSTANT + CONSTANT + CONSTANT + CONSTANT + CONSTANT);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
function foo(a) {
|
|
||||||
console.log(3);
|
|
||||||
console.log(2);
|
|
||||||
console.log(1);
|
|
||||||
console.log(1 & a);
|
|
||||||
}
|
|
||||||
function bar() {
|
|
||||||
const s = "01234567890123456789";
|
|
||||||
console.log(s + s + s + s + s);
|
|
||||||
|
|
||||||
console.log("abcabcabcabcabc");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
unused_regexp_literal: {
|
|
||||||
options = {
|
|
||||||
evaluate : true,
|
|
||||||
booleans : true,
|
|
||||||
comparisons : true,
|
|
||||||
dead_code : true,
|
|
||||||
conditionals : true,
|
|
||||||
side_effects : true,
|
|
||||||
unused : true,
|
|
||||||
hoist_funs : true,
|
|
||||||
if_return : true,
|
|
||||||
join_vars : true,
|
|
||||||
sequences : false,
|
|
||||||
collapse_vars : false,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
function f(){ var a = /b/; }
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
function f(){}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
regexp_literal_not_const: {
|
|
||||||
options = {
|
|
||||||
evaluate : true,
|
|
||||||
booleans : true,
|
|
||||||
comparisons : true,
|
|
||||||
dead_code : true,
|
|
||||||
conditionals : true,
|
|
||||||
side_effects : true,
|
|
||||||
unused : true,
|
|
||||||
hoist_funs : true,
|
|
||||||
if_return : true,
|
|
||||||
join_vars : true,
|
|
||||||
sequences : false,
|
|
||||||
collapse_vars : false,
|
|
||||||
reduce_funcs : true,
|
|
||||||
reduce_vars : true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
(function(){
|
|
||||||
var result;
|
|
||||||
const s = 'acdabcdeabbb';
|
|
||||||
const REGEXP_LITERAL = /ab*/g;
|
|
||||||
while (result = REGEXP_LITERAL.exec(s)) {
|
|
||||||
console.log(result[0]);
|
|
||||||
}
|
|
||||||
})();
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
(function() {
|
|
||||||
var result;
|
|
||||||
const REGEXP_LITERAL = /ab*/g;
|
|
||||||
while (result = REGEXP_LITERAL.exec("acdabcdeabbb")) console.log(result[0]);
|
|
||||||
})();
|
|
||||||
}
|
|
||||||
expect_stdout: true
|
|
||||||
}
|
|
||||||
File diff suppressed because it is too large
Load Diff
@@ -1,7 +1,7 @@
|
|||||||
keep_debugger: {
|
keep_debugger: {
|
||||||
options = {
|
options = {
|
||||||
drop_debugger: false
|
drop_debugger: false,
|
||||||
};
|
}
|
||||||
input: {
|
input: {
|
||||||
debugger;
|
debugger;
|
||||||
}
|
}
|
||||||
@@ -12,8 +12,8 @@ keep_debugger: {
|
|||||||
|
|
||||||
drop_debugger: {
|
drop_debugger: {
|
||||||
options = {
|
options = {
|
||||||
drop_debugger: true
|
drop_debugger: true,
|
||||||
};
|
}
|
||||||
input: {
|
input: {
|
||||||
debugger;
|
debugger;
|
||||||
if (foo) debugger;
|
if (foo) debugger;
|
||||||
|
|||||||
@@ -1,662 +0,0 @@
|
|||||||
destructuring_arrays: {
|
|
||||||
input: {
|
|
||||||
{const [aa, bb] = cc;}
|
|
||||||
{const [aa, [bb, cc]] = dd;}
|
|
||||||
{let [aa, bb] = cc;}
|
|
||||||
{let [aa, [bb, cc]] = dd;}
|
|
||||||
var [aa, bb] = cc;
|
|
||||||
var [aa, [bb, cc]] = dd;
|
|
||||||
var [,[,,,,,],,,zz,] = xx; // Trailing comma
|
|
||||||
var [,,zzz,,] = xxx; // Trailing comma after hole
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
{const [aa, bb] = cc;}
|
|
||||||
{const [aa, [bb, cc]] = dd;}
|
|
||||||
{let [aa, bb] = cc;}
|
|
||||||
{let [aa, [bb, cc]] = dd;}
|
|
||||||
var [aa, bb] = cc;
|
|
||||||
var [aa, [bb, cc]] = dd;
|
|
||||||
var [,[,,,,,],,,zz] = xx;
|
|
||||||
var [,,zzz,,] = xxx;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
destructuring_arrays_holes: {
|
|
||||||
input: {
|
|
||||||
var [,,,,] = a;
|
|
||||||
var [,,b,] = c;
|
|
||||||
var [d,,] = e;
|
|
||||||
}
|
|
||||||
expect_exact: "var[,,,,]=a;var[,,b]=c;var[d,,]=e;"
|
|
||||||
}
|
|
||||||
|
|
||||||
destructuring_objects: {
|
|
||||||
input: {
|
|
||||||
{const {aa, bb} = {aa:1, bb:2};}
|
|
||||||
{const {aa, bb: {cc, dd}} = {aa:1, bb: {cc:2, dd: 3}};}
|
|
||||||
{let {aa, bb} = {aa:1, bb:2};}
|
|
||||||
{let {aa, bb: {cc, dd}} = {aa:1, bb: {cc:2, dd: 3}};}
|
|
||||||
var {aa, bb} = {aa:1, bb:2};
|
|
||||||
var {aa, bb: {cc, dd}} = {aa:1, bb: {cc:2, dd: 3}};
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
{const {aa, bb} = {aa:1, bb:2};}
|
|
||||||
{const {aa, bb: {cc, dd}} = {aa:1, bb: {cc:2, dd: 3}};}
|
|
||||||
{let {aa, bb} = {aa:1, bb:2};}
|
|
||||||
{let {aa, bb: {cc, dd}} = {aa:1, bb: {cc:2, dd: 3}};}
|
|
||||||
var {aa, bb} = {aa:1, bb:2};
|
|
||||||
var {aa, bb: {cc, dd}} = {aa:1, bb: {cc:2, dd: 3}};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
destructuring_objects_trailing_elision: {
|
|
||||||
beautify = {
|
|
||||||
ecma: 6
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
var {cc,} = foo;
|
|
||||||
}
|
|
||||||
expect_exact: "var{cc}=foo;"
|
|
||||||
}
|
|
||||||
|
|
||||||
nested_destructuring_objects: {
|
|
||||||
beautify = {
|
|
||||||
ecma: 6
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
const [{a},b] = c;
|
|
||||||
let [{d},e] = f;
|
|
||||||
var [{g},h] = i;
|
|
||||||
}
|
|
||||||
expect_exact: 'const[{a},b]=c;let[{d},e]=f;var[{g},h]=i;';
|
|
||||||
}
|
|
||||||
|
|
||||||
destructuring_constdef_in_loops: {
|
|
||||||
beautify = {
|
|
||||||
ecma: 6
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
for (const [x,y] in pairs);
|
|
||||||
for (const [a] = 0;;);
|
|
||||||
for (const {c} of cees);
|
|
||||||
}
|
|
||||||
expect_exact: "for(const[x,y]in pairs);for(const[a]=0;;);for(const{c}of cees);"
|
|
||||||
}
|
|
||||||
|
|
||||||
destructuring_letdef_in_loops: {
|
|
||||||
beautify = {
|
|
||||||
ecma: 6
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
for (let [x,y] in pairs);
|
|
||||||
for (let [a] = 0;;);
|
|
||||||
for (let {c} of cees);
|
|
||||||
}
|
|
||||||
expect_exact: "for(let[x,y]in pairs);for(let[a]=0;;);for(let{c}of cees);"
|
|
||||||
}
|
|
||||||
|
|
||||||
destructuring_vardef_in_loops: {
|
|
||||||
beautify = {
|
|
||||||
ecma: 6
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
for (var [x,y] in pairs);
|
|
||||||
for (var [a] = 0;;);
|
|
||||||
for (var {c} of cees);
|
|
||||||
}
|
|
||||||
expect_exact: "for(var[x,y]in pairs);for(var[a]=0;;);for(var{c}of cees);"
|
|
||||||
}
|
|
||||||
|
|
||||||
destructuring_expressions: {
|
|
||||||
beautify = {
|
|
||||||
ecma: 6
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
({a, b});
|
|
||||||
[{a}];
|
|
||||||
f({x});
|
|
||||||
}
|
|
||||||
expect_exact: "({a,b});[{a}];f({x});"
|
|
||||||
}
|
|
||||||
|
|
||||||
destructuring_remove_unused_1: {
|
|
||||||
options = {
|
|
||||||
unused: true
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
function a() {
|
|
||||||
var unused = "foo";
|
|
||||||
var a = [1];
|
|
||||||
var [b] = a;
|
|
||||||
f(b);
|
|
||||||
}
|
|
||||||
function b() {
|
|
||||||
var unused = "foo";
|
|
||||||
var a = {b: 1};
|
|
||||||
var {b} = a;
|
|
||||||
f(b);
|
|
||||||
}
|
|
||||||
function c() {
|
|
||||||
var unused = "foo";
|
|
||||||
var a = [[1]];
|
|
||||||
var [[b]] = a;
|
|
||||||
f(b);
|
|
||||||
}
|
|
||||||
function d() {
|
|
||||||
var unused = "foo";
|
|
||||||
var a = {b: {b:1}};
|
|
||||||
var {b:{b}} = a;
|
|
||||||
f(b);
|
|
||||||
}
|
|
||||||
function e() {
|
|
||||||
var unused = "foo";
|
|
||||||
var a = [1, 2, 3, 4, 5];
|
|
||||||
var x = [[1, 2, 3]];
|
|
||||||
var y = {h: 1};
|
|
||||||
var [b, ...c] = a;
|
|
||||||
var [...[e, f]] = x;
|
|
||||||
var [...{g: h}] = y;
|
|
||||||
f(b, c, e, f, g);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
function a() {
|
|
||||||
var a = [1];
|
|
||||||
var [b] = a;
|
|
||||||
f(b);
|
|
||||||
}
|
|
||||||
function b() {
|
|
||||||
var a = {b: 1};
|
|
||||||
var {b} = a;
|
|
||||||
f(b);
|
|
||||||
}
|
|
||||||
function c() {
|
|
||||||
var a = [[1]];
|
|
||||||
var [[b]] = a;
|
|
||||||
f(b);
|
|
||||||
}
|
|
||||||
function d() {
|
|
||||||
var a = {b: {b:1}};
|
|
||||||
var {b:{b}} = a;
|
|
||||||
f(b);
|
|
||||||
}
|
|
||||||
function e() {
|
|
||||||
var a = [1, 2, 3, 4, 5];
|
|
||||||
var x = [[1, 2, 3]];
|
|
||||||
var y = {h: 1};
|
|
||||||
var [b, ...c] = a;
|
|
||||||
var [...[e, f]] = x;
|
|
||||||
var [...{g: h}] = y;
|
|
||||||
f(b, c, e, f, g);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
destructuring_remove_unused_2: {
|
|
||||||
options = {
|
|
||||||
unused: true
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
function a() {
|
|
||||||
var unused = "foo";
|
|
||||||
var a = [,,1];
|
|
||||||
var [b] = a;
|
|
||||||
f(b);
|
|
||||||
}
|
|
||||||
function b() {
|
|
||||||
var unused = "foo";
|
|
||||||
var a = [{a: [1]}];
|
|
||||||
var [{b: a}] = a;
|
|
||||||
f(b);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
function a() {
|
|
||||||
var a = [,,1];
|
|
||||||
var [b] = a;
|
|
||||||
f(b);
|
|
||||||
}
|
|
||||||
function b() {
|
|
||||||
var a = [{a: [1]}];
|
|
||||||
var [{b: a}] = a;
|
|
||||||
f(b);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
object_destructuring_may_need_parentheses: {
|
|
||||||
beautify = {
|
|
||||||
ecma: 6
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
({a, b} = {a: 1, b: 2});
|
|
||||||
}
|
|
||||||
expect_exact: "({a,b}={a:1,b:2});"
|
|
||||||
}
|
|
||||||
|
|
||||||
destructuring_with_undefined_as_default_assignment: {
|
|
||||||
options = {
|
|
||||||
evaluate: true
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
[foo = undefined] = bar;
|
|
||||||
[foo = void 0] = bar;
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
[foo] = bar;
|
|
||||||
[foo] = bar;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
destructuring_dont_evaluate_with_undefined_as_default_assignment: {
|
|
||||||
options = {
|
|
||||||
evaluate: false
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
[foo = undefined] = bar;
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
[foo = void 0] = bar;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
reduce_vars: {
|
|
||||||
options = {
|
|
||||||
reduce_funcs: true,
|
|
||||||
reduce_vars: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
{const [aa, [bb, cc]] = dd;}
|
|
||||||
{let [aa, [bb, cc]] = dd;}
|
|
||||||
var [aa, [bb, cc]] = dd;
|
|
||||||
[aa, [bb, cc]] = dd;
|
|
||||||
{const {aa, bb: {cc, dd}} = {aa:1, bb: {cc:2, dd: 3}};}
|
|
||||||
{let {aa, bb: {cc, dd}} = {aa:1, bb: {cc:2, dd: 3}};}
|
|
||||||
var {aa, bb: {cc, dd}} = {aa:1, bb: {cc:2, dd: 3}};
|
|
||||||
({aa, bb: {cc, dd}} = {aa:1, bb: {cc:2, dd: 3}});
|
|
||||||
const [{a},b] = c;
|
|
||||||
let [{d},e] = f;
|
|
||||||
var [{g},h] = i;
|
|
||||||
[{a},b] = c;
|
|
||||||
for (const [x,y] in pairs);
|
|
||||||
for (let [x,y] in pairs);
|
|
||||||
for (var [x,y] in pairs);
|
|
||||||
for ([x,y] in pairs);
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
{const [aa, [bb, cc]] = dd;}
|
|
||||||
{let [aa, [bb, cc]] = dd;}
|
|
||||||
var [aa, [bb, cc]] = dd;
|
|
||||||
[aa, [bb, cc]] = dd;
|
|
||||||
{const {aa, bb: {cc, dd}} = {aa:1, bb: {cc:2, dd: 3}};}
|
|
||||||
{let {aa, bb: {cc, dd}} = {aa:1, bb: {cc:2, dd: 3}};}
|
|
||||||
var {aa, bb: {cc, dd}} = {aa:1, bb: {cc:2, dd: 3}};
|
|
||||||
({aa, bb: {cc, dd}} = {aa:1, bb: {cc:2, dd: 3}});
|
|
||||||
const [{a},b] = c;
|
|
||||||
let [{d},e] = f;
|
|
||||||
var [{g},h] = i;
|
|
||||||
[{a},b] = c;
|
|
||||||
for (const [x,y] in pairs);
|
|
||||||
for (let [x,y] in pairs);
|
|
||||||
for (var [x,y] in pairs);
|
|
||||||
for ([x,y] in pairs);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
unused: {
|
|
||||||
options = {
|
|
||||||
unused: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
let { foo: [, , ...a] } = { foo: [1, 2, 3, 4], bar: 5 };
|
|
||||||
console.log(a);
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
let { foo: [, , ...a] } = { foo: [1, 2, 3, 4], bar: 5 };
|
|
||||||
console.log(a);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
issue_1886: {
|
|
||||||
options = {
|
|
||||||
collapse_vars: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
let [a] = [1];
|
|
||||||
console.log(a);
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
let [a] = [1];
|
|
||||||
console.log(a);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
destructuring_decl_of_numeric_key: {
|
|
||||||
options = {
|
|
||||||
evaluate: true,
|
|
||||||
unused: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
let { 3: x } = { [1 + 2]: 42 };
|
|
||||||
console.log(x);
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
let { 3: x } = { [3]: 42 };
|
|
||||||
console.log(x);
|
|
||||||
}
|
|
||||||
expect_stdout: "42"
|
|
||||||
node_version: ">=6"
|
|
||||||
}
|
|
||||||
|
|
||||||
destructuring_decl_of_computed_key: {
|
|
||||||
options = {
|
|
||||||
evaluate: true,
|
|
||||||
unused: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
let four = 4;
|
|
||||||
let { [7 - four]: x } = { [1 + 2]: 42 };
|
|
||||||
console.log(x);
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
let four = 4;
|
|
||||||
let { [7 - four]: x } = { [3]: 42 };
|
|
||||||
console.log(x);
|
|
||||||
}
|
|
||||||
expect_stdout: "42"
|
|
||||||
node_version: ">=6"
|
|
||||||
}
|
|
||||||
|
|
||||||
destructuring_assign_of_numeric_key: {
|
|
||||||
options = {
|
|
||||||
evaluate: true,
|
|
||||||
unused: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
let x;
|
|
||||||
({ 3: x } = { [1 + 2]: 42 });
|
|
||||||
console.log(x);
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
let x;
|
|
||||||
({ 3: x } = { [3]: 42 });
|
|
||||||
console.log(x);
|
|
||||||
}
|
|
||||||
expect_stdout: "42"
|
|
||||||
node_version: ">=6"
|
|
||||||
}
|
|
||||||
|
|
||||||
destructuring_assign_of_computed_key: {
|
|
||||||
options = {
|
|
||||||
evaluate: true,
|
|
||||||
unused: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
let x;
|
|
||||||
let four = 4;
|
|
||||||
({ [(5 + 2) - four]: x } = { [1 + 2]: 42 });
|
|
||||||
console.log(x);
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
let x;
|
|
||||||
let four = 4;
|
|
||||||
({ [7 - four]: x } = { [3]: 42 });
|
|
||||||
console.log(x);
|
|
||||||
}
|
|
||||||
expect_stdout: "42"
|
|
||||||
node_version: ">=6"
|
|
||||||
}
|
|
||||||
|
|
||||||
mangle_destructuring_decl: {
|
|
||||||
options = {
|
|
||||||
evaluate: true,
|
|
||||||
unused: true,
|
|
||||||
}
|
|
||||||
mangle = {
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
function test(opts) {
|
|
||||||
let a = opts.a || { e: 7, n: 8 };
|
|
||||||
let { t, e, n, s = 5 + 4, o, r } = a;
|
|
||||||
console.log(t, e, n, s, o, r);
|
|
||||||
}
|
|
||||||
test({a: { t: 1, e: 2, n: 3, s: 4, o: 5, r: 6 }});
|
|
||||||
test({});
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
function test(t) {
|
|
||||||
let e = t.a || { e: 7, n: 8 };
|
|
||||||
let {t: n, e: o, n: s, s: l = 9, o: a, r: c} = e;
|
|
||||||
console.log(n, o, s, l, a, c);
|
|
||||||
}
|
|
||||||
test({ a: { t: 1, e: 2, n: 3, s: 4, o: 5, r: 6 } });
|
|
||||||
test({});
|
|
||||||
}
|
|
||||||
expect_stdout: [
|
|
||||||
"1 2 3 4 5 6",
|
|
||||||
"undefined 7 8 9 undefined undefined",
|
|
||||||
]
|
|
||||||
node_version: ">=6"
|
|
||||||
}
|
|
||||||
|
|
||||||
mangle_destructuring_assign_toplevel_true: {
|
|
||||||
options = {
|
|
||||||
toplevel: true,
|
|
||||||
evaluate: true,
|
|
||||||
unused: true,
|
|
||||||
}
|
|
||||||
mangle = {
|
|
||||||
toplevel: true,
|
|
||||||
}
|
|
||||||
beautify = {
|
|
||||||
ecma: 6
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
function test(opts) {
|
|
||||||
let s, o, r;
|
|
||||||
let a = opts.a || { e: 7, n: 8 };
|
|
||||||
({ t, e, n, s = 5 + 4, o, r } = a);
|
|
||||||
console.log(t, e, n, s, o, r);
|
|
||||||
}
|
|
||||||
let t, e, n;
|
|
||||||
test({a: { t: 1, e: 2, n: 3, s: 4, o: 5, r: 6 }});
|
|
||||||
test({});
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
function e(e) {
|
|
||||||
let l, s, a;
|
|
||||||
let c = e.a || { e: 7, n: 8 };
|
|
||||||
({t: n, e: o, n: t, s: l = 9, o: s, r: a} = c);
|
|
||||||
console.log(n, o, t, l, s, a);
|
|
||||||
}
|
|
||||||
let n, o, t;
|
|
||||||
e({ a: { t: 1, e: 2, n: 3, s: 4, o: 5, r: 6 } });
|
|
||||||
e({});
|
|
||||||
}
|
|
||||||
expect_stdout: [
|
|
||||||
"1 2 3 4 5 6",
|
|
||||||
"undefined 7 8 9 undefined undefined",
|
|
||||||
]
|
|
||||||
node_version: ">=6"
|
|
||||||
}
|
|
||||||
|
|
||||||
mangle_destructuring_assign_toplevel_false: {
|
|
||||||
options = {
|
|
||||||
toplevel: false,
|
|
||||||
evaluate: true,
|
|
||||||
unused: true,
|
|
||||||
}
|
|
||||||
mangle = {
|
|
||||||
toplevel: false,
|
|
||||||
}
|
|
||||||
beautify = {
|
|
||||||
ecma: 6
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
function test(opts) {
|
|
||||||
let s, o, r;
|
|
||||||
let a = opts.a || { e: 7, n: 8 };
|
|
||||||
({ t, e, n, s = 9, o, r } = a);
|
|
||||||
console.log(t, e, n, s, o, r);
|
|
||||||
}
|
|
||||||
let t, e, n;
|
|
||||||
test({a: { t: 1, e: 2, n: 3, s: 4, o: 5, r: 6 }});
|
|
||||||
test({});
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
function test(o) {
|
|
||||||
let s, l, a;
|
|
||||||
let c = o.a || { e: 7, n: 8 };
|
|
||||||
({t, e, n, s = 9, o: l, r: a} = c);
|
|
||||||
console.log(t, e, n, s, l, a);
|
|
||||||
}
|
|
||||||
let t, e, n;
|
|
||||||
test({ a: { t: 1, e: 2, n: 3, s: 4, o: 5, r: 6 } });
|
|
||||||
test({});
|
|
||||||
}
|
|
||||||
expect_stdout: [
|
|
||||||
"1 2 3 4 5 6",
|
|
||||||
"undefined 7 8 9 undefined undefined",
|
|
||||||
]
|
|
||||||
node_version: ">=6"
|
|
||||||
}
|
|
||||||
|
|
||||||
mangle_destructuring_decl_array: {
|
|
||||||
options = {
|
|
||||||
evaluate: true,
|
|
||||||
unused: true,
|
|
||||||
toplevel: true,
|
|
||||||
}
|
|
||||||
mangle = {
|
|
||||||
toplevel: true,
|
|
||||||
}
|
|
||||||
beautify = {
|
|
||||||
ecma: 6
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
var [, t, e, n, s, o = 2, r = [ 1 + 2 ]] = [ 9, 8, 7, 6 ];
|
|
||||||
console.log(t, e, n, s, o, r);
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
var [, o, l, a, c, e = 2, g = [ 3 ]] = [ 9, 8, 7, 6 ];
|
|
||||||
console.log(o, l, a, c, e, g);
|
|
||||||
}
|
|
||||||
expect_stdout: "8 7 6 undefined 2 [ 3 ]"
|
|
||||||
node_version: ">=6"
|
|
||||||
}
|
|
||||||
|
|
||||||
anon_func_with_destructuring_args: {
|
|
||||||
options = {
|
|
||||||
evaluate: true,
|
|
||||||
unused: true,
|
|
||||||
toplevel: true,
|
|
||||||
}
|
|
||||||
mangle = {
|
|
||||||
toplevel: true,
|
|
||||||
}
|
|
||||||
beautify = {
|
|
||||||
ecma: 5,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
(function({foo = 1 + 0, bar = 2}, [car = 3, far = 4]) {
|
|
||||||
console.log(foo, bar, car, far);
|
|
||||||
})({bar: 5 - 0}, [, 6]);
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
(function({foo: o = 1, bar: n = 2}, [a = 3, b = 4]) {
|
|
||||||
console.log(o, n, a, b);
|
|
||||||
})({bar: 5}, [, 6]);
|
|
||||||
}
|
|
||||||
expect_stdout: "1 5 3 6"
|
|
||||||
node_version: ">=6"
|
|
||||||
}
|
|
||||||
|
|
||||||
arrow_func_with_destructuring_args: {
|
|
||||||
options = {
|
|
||||||
evaluate: true,
|
|
||||||
unused: true,
|
|
||||||
toplevel: true,
|
|
||||||
}
|
|
||||||
mangle = {
|
|
||||||
toplevel: true,
|
|
||||||
}
|
|
||||||
beautify = {
|
|
||||||
ecma: 5,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
(({foo = 1 + 0, bar = 2}, [car = 3, far = 4]) => {
|
|
||||||
console.log(foo, bar, car, far);
|
|
||||||
})({bar: 5 - 0}, [, 6]);
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
(({foo: o = 1, bar: a = 2}, [b = 3, l = 4]) => {
|
|
||||||
console.log(o, a, b, l);
|
|
||||||
})({bar: 5}, [, 6]);
|
|
||||||
}
|
|
||||||
expect_stdout: "1 5 3 6"
|
|
||||||
node_version: ">=6"
|
|
||||||
}
|
|
||||||
|
|
||||||
issue_2044_ecma_5: {
|
|
||||||
beautify = {
|
|
||||||
beautify: false,
|
|
||||||
ecma: 5,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
({x : a = 1, y = 2 + b, z = 3 - c} = obj);
|
|
||||||
}
|
|
||||||
expect_exact: "({x:a=1,y:y=2+b,z:z=3-c}=obj);"
|
|
||||||
}
|
|
||||||
|
|
||||||
issue_2044_ecma_6: {
|
|
||||||
beautify = {
|
|
||||||
beautify: false,
|
|
||||||
ecma: 6,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
({x : a = 1, y = 2 + b, z = 3 - c} = obj);
|
|
||||||
}
|
|
||||||
expect_exact: "({x:a=1,y=2+b,z=3-c}=obj);"
|
|
||||||
}
|
|
||||||
|
|
||||||
issue_2044_ecma_5_beautify: {
|
|
||||||
beautify = {
|
|
||||||
beautify: true,
|
|
||||||
ecma: 5,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
({x : a = 1, y = 2 + b, z = 3 - c} = obj);
|
|
||||||
}
|
|
||||||
expect_exact: "({x: a = 1, y: y = 2 + b, z: z = 3 - c} = obj);"
|
|
||||||
}
|
|
||||||
|
|
||||||
issue_2044_ecma_6_beautify: {
|
|
||||||
beautify = {
|
|
||||||
beautify: true,
|
|
||||||
ecma: 6,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
({x : a = 1, y = 2 + b, z = 3 - c} = obj);
|
|
||||||
}
|
|
||||||
expect_exact: "({x: a = 1, y = 2 + b, z = 3 - c} = obj);"
|
|
||||||
}
|
|
||||||
|
|
||||||
issue_2140: {
|
|
||||||
options = {
|
|
||||||
unused: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
!function() {
|
|
||||||
var t = {};
|
|
||||||
console.log(([t.a] = [42])[0]);
|
|
||||||
}();
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
!function() {
|
|
||||||
var t = {};
|
|
||||||
console.log(([t.a] = [42])[0]);
|
|
||||||
}();
|
|
||||||
}
|
|
||||||
expect_stdout: "42"
|
|
||||||
node_version: ">=6"
|
|
||||||
}
|
|
||||||
@@ -1,10 +1,131 @@
|
|||||||
class_directives_compression: {
|
simple_statement_is_not_a_directive: {
|
||||||
input: {
|
input: {
|
||||||
class foo {
|
"use strict"
|
||||||
foo() {
|
.split(" ")
|
||||||
|
.forEach(function(s) {
|
||||||
|
console.log(s);
|
||||||
|
});
|
||||||
|
console.log(!this); // is strict mode?
|
||||||
|
(function() {
|
||||||
|
"directive"
|
||||||
|
""
|
||||||
|
"use strict"
|
||||||
|
"hello world"
|
||||||
|
.split(" ")
|
||||||
|
.forEach(function(s) {
|
||||||
|
console.log(s);
|
||||||
|
});
|
||||||
|
console.log(!this); // is strict mode?
|
||||||
|
})();
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
"use strict".split(" ").forEach(function(s) {
|
||||||
|
console.log(s);
|
||||||
|
});
|
||||||
|
console.log(!this);
|
||||||
|
(function() {
|
||||||
|
"directive";
|
||||||
|
"";
|
||||||
|
"use strict";
|
||||||
|
"hello world".split(" ").forEach(function(s) {
|
||||||
|
console.log(s);
|
||||||
|
});
|
||||||
|
console.log(!this);
|
||||||
|
})();
|
||||||
|
}
|
||||||
|
expect_stdout: [
|
||||||
|
"use",
|
||||||
|
"strict",
|
||||||
|
"false",
|
||||||
|
"hello",
|
||||||
|
"world",
|
||||||
|
"true",
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
|
drop_lone_use_strict: {
|
||||||
|
options = {
|
||||||
|
directives: true,
|
||||||
|
unused: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
function f1() {
|
||||||
|
"use strict";
|
||||||
|
}
|
||||||
|
function f2() {
|
||||||
|
"use strict";
|
||||||
|
function f3() {
|
||||||
"use strict";
|
"use strict";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
(function f4() {
|
||||||
|
"use strict";
|
||||||
|
})();
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
function f1() {
|
||||||
|
}
|
||||||
|
function f2() {
|
||||||
|
}
|
||||||
|
(function() {})();
|
||||||
}
|
}
|
||||||
expect_exact: "class foo{foo(){}}"
|
}
|
||||||
|
|
||||||
|
issue_3166: {
|
||||||
|
options = {
|
||||||
|
directives: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
"foo";
|
||||||
|
"use strict";
|
||||||
|
function f() {
|
||||||
|
"use strict";
|
||||||
|
"bar";
|
||||||
|
"use asm";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
"use strict";
|
||||||
|
function f() {
|
||||||
|
"use asm";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
valid_after_invalid_1: {
|
||||||
|
input: {
|
||||||
|
console.log(typeof function() {
|
||||||
|
"use\x20strict";
|
||||||
|
"use strict";
|
||||||
|
return this;
|
||||||
|
}());
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
console.log(typeof function() {
|
||||||
|
"use\x20strict";
|
||||||
|
"use strict";
|
||||||
|
return this;
|
||||||
|
}());
|
||||||
|
}
|
||||||
|
expect_stdout: "undefined"
|
||||||
|
}
|
||||||
|
|
||||||
|
valid_after_invalid_2: {
|
||||||
|
options = {
|
||||||
|
directives: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
console.log(typeof function() {
|
||||||
|
"use\x20strict";
|
||||||
|
"use strict";
|
||||||
|
return this;
|
||||||
|
}());
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
console.log(typeof function() {
|
||||||
|
"use strict";
|
||||||
|
return this;
|
||||||
|
}());
|
||||||
|
}
|
||||||
|
expect_stdout: "undefined"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
drop_console_1: {
|
drop_console_1: {
|
||||||
options = {};
|
options = {}
|
||||||
input: {
|
input: {
|
||||||
console.log('foo');
|
console.log('foo');
|
||||||
console.log.apply(console, arguments);
|
console.log.apply(console, arguments);
|
||||||
@@ -11,7 +11,9 @@ drop_console_1: {
|
|||||||
}
|
}
|
||||||
|
|
||||||
drop_console_2: {
|
drop_console_2: {
|
||||||
options = { drop_console: true };
|
options = {
|
||||||
|
drop_console: true,
|
||||||
|
}
|
||||||
input: {
|
input: {
|
||||||
console.log('foo');
|
console.log('foo');
|
||||||
console.log.apply(console, arguments);
|
console.log.apply(console, arguments);
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -1,71 +0,0 @@
|
|||||||
|
|
||||||
expand_arguments: {
|
|
||||||
input: {
|
|
||||||
func(a, ...rest);
|
|
||||||
func(...all);
|
|
||||||
}
|
|
||||||
expect_exact: "func(a,...rest);func(...all);"
|
|
||||||
}
|
|
||||||
|
|
||||||
expand_expression_arguments: {
|
|
||||||
input: {
|
|
||||||
f(...a.b);
|
|
||||||
f(...a.b());
|
|
||||||
f(...(a));
|
|
||||||
f(...(a.b));
|
|
||||||
f(...a[i]);
|
|
||||||
}
|
|
||||||
expect_exact: "f(...a.b);f(...a.b());f(...a);f(...a.b);f(...a[i]);"
|
|
||||||
}
|
|
||||||
|
|
||||||
expand_parameters: {
|
|
||||||
input: {
|
|
||||||
(function (a, ...b){});
|
|
||||||
(function (...args){});
|
|
||||||
}
|
|
||||||
expect_exact: "(function(a,...b){});(function(...args){});"
|
|
||||||
}
|
|
||||||
|
|
||||||
avoid_spread_in_ternary: {
|
|
||||||
options = {
|
|
||||||
comparisons: true,
|
|
||||||
conditionals: true,
|
|
||||||
evaluate: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
function print(...x) {
|
|
||||||
console.log(...x);
|
|
||||||
}
|
|
||||||
var a = [1, 2], b = [3, 4];
|
|
||||||
|
|
||||||
if (Math)
|
|
||||||
print(a);
|
|
||||||
else
|
|
||||||
print(b);
|
|
||||||
|
|
||||||
if (Math)
|
|
||||||
print(...a);
|
|
||||||
else
|
|
||||||
print(b);
|
|
||||||
|
|
||||||
if (Math.no_such_property)
|
|
||||||
print(a);
|
|
||||||
else
|
|
||||||
print(...b);
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
function print(...x) {
|
|
||||||
console.log(...x);
|
|
||||||
}
|
|
||||||
var a = [ 1, 2 ], b = [ 3, 4 ];
|
|
||||||
print(Math ? a : b);
|
|
||||||
Math ? print(...a) : print(b);
|
|
||||||
Math.no_such_property ? print(a) : print(...b);
|
|
||||||
}
|
|
||||||
expect_stdout: [
|
|
||||||
"[ 1, 2 ]",
|
|
||||||
"1 2",
|
|
||||||
"3 4",
|
|
||||||
]
|
|
||||||
node_version: ">=6"
|
|
||||||
}
|
|
||||||
@@ -1,264 +0,0 @@
|
|||||||
issue_2038_1: {
|
|
||||||
options = {
|
|
||||||
toplevel: true,
|
|
||||||
unused: true,
|
|
||||||
}
|
|
||||||
mangle = {
|
|
||||||
toplevel: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
export var V = 1;
|
|
||||||
export let L = 2;
|
|
||||||
export const C = 3;
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
export var V = 1;
|
|
||||||
export let L = 2;
|
|
||||||
export const C = 3;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
issue_2038_2: {
|
|
||||||
options = {
|
|
||||||
toplevel: true,
|
|
||||||
unused: true,
|
|
||||||
}
|
|
||||||
mangle = {
|
|
||||||
toplevel: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
let LET = 1;
|
|
||||||
const CONST = 2;
|
|
||||||
var VAR = 3;
|
|
||||||
export { LET, CONST, VAR };
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
let t = 1;
|
|
||||||
const e = 2;
|
|
||||||
var o = 3;
|
|
||||||
export { t as LET, e as CONST, o as VAR };
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
issue_2126: {
|
|
||||||
mangle = {
|
|
||||||
toplevel: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
import { foo as bar, cat as dog } from "stuff";
|
|
||||||
console.log(bar, dog);
|
|
||||||
export { bar as qux };
|
|
||||||
export { dog };
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
import { foo as o, cat as s } from "stuff";
|
|
||||||
console.log(o, s);
|
|
||||||
export { o as qux };
|
|
||||||
export { s as dog };
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
beautify: {
|
|
||||||
beautify = {
|
|
||||||
beautify: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
export { A as B, C as D };
|
|
||||||
}
|
|
||||||
expect_exact: "export { A as B, C as D };"
|
|
||||||
}
|
|
||||||
|
|
||||||
issue_2131: {
|
|
||||||
options = {
|
|
||||||
toplevel: true,
|
|
||||||
unused: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
function no() {
|
|
||||||
console.log(42);
|
|
||||||
}
|
|
||||||
function go() {
|
|
||||||
console.log(42);
|
|
||||||
}
|
|
||||||
var X = 1, Y = 2;
|
|
||||||
export function main() {
|
|
||||||
go(X);
|
|
||||||
};
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
function go() {
|
|
||||||
console.log(42);
|
|
||||||
}
|
|
||||||
var X = 1;
|
|
||||||
export function main() {
|
|
||||||
go(X);
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
issue_2129: {
|
|
||||||
mangle = {
|
|
||||||
toplevel: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
export const { keys } = Object;
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
export const { keys } = Object;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
async_func: {
|
|
||||||
options = {
|
|
||||||
keep_fargs: false,
|
|
||||||
unused: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
export async function Foo(x){};
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
export async function Foo(){};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
issue_2134_1: {
|
|
||||||
options = {
|
|
||||||
keep_fargs: false,
|
|
||||||
reduce_funcs: true,
|
|
||||||
reduce_vars: true,
|
|
||||||
toplevel: true,
|
|
||||||
unused: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
export function Foo(x){};
|
|
||||||
Foo.prototype = {};
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
export function Foo(){};
|
|
||||||
Foo.prototype = {};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
issue_2134_2: {
|
|
||||||
options = {
|
|
||||||
keep_fargs: false,
|
|
||||||
reduce_funcs: true,
|
|
||||||
reduce_vars: true,
|
|
||||||
toplevel: true,
|
|
||||||
unused: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
export async function Foo(x){};
|
|
||||||
Foo.prototype = {};
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
export async function Foo(){};
|
|
||||||
Foo.prototype = {};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
redirection: {
|
|
||||||
mangle = {
|
|
||||||
toplevel: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
let foo = 1, bar = 2;
|
|
||||||
export { foo as delete };
|
|
||||||
export { bar as default };
|
|
||||||
export { foo as var } from "module.js";
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
let e = 1, o = 2;
|
|
||||||
export { e as delete };
|
|
||||||
export { o as default };
|
|
||||||
export { foo as var } from "module.js";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
keyword_invalid_1: {
|
|
||||||
input: {
|
|
||||||
export { default };
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
export { default };
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
keyword_invalid_2: {
|
|
||||||
input: {
|
|
||||||
export { default as Alias };
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
export { default as Alias };
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
keyword_invalid_3: {
|
|
||||||
input: {
|
|
||||||
export { default as default };
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
export { default as default };
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
keyword_valid_1: {
|
|
||||||
input: {
|
|
||||||
export { default } from "module.js";
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
export { default } from "module.js";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
keyword_valid_2: {
|
|
||||||
input: {
|
|
||||||
export { default as Alias } from "module.js";
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
export { default as Alias } from "module.js";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
keyword_valid_3: {
|
|
||||||
input: {
|
|
||||||
export { default as default } from "module.js";
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
export { default as default } from "module.js";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
dynamic_import: {
|
|
||||||
mangle = {
|
|
||||||
toplevel: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
import traditional from './traditional.js';
|
|
||||||
function imp(x) {
|
|
||||||
return import(x);
|
|
||||||
}
|
|
||||||
import("module_for_side_effects.js");
|
|
||||||
let dynamic = import("some/module.js");
|
|
||||||
dynamic.foo();
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
import o from "./traditional.js";
|
|
||||||
function t(o) {
|
|
||||||
return import(o);
|
|
||||||
}
|
|
||||||
import("module_for_side_effects.js");
|
|
||||||
let r = import("some/module.js");
|
|
||||||
r.foo();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
trailing_comma: {
|
|
||||||
beautify = {
|
|
||||||
beautify: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
export const a = 1;
|
|
||||||
}
|
|
||||||
expect_exact: "export const a = 1;"
|
|
||||||
}
|
|
||||||
@@ -1,52 +0,0 @@
|
|||||||
pow: {
|
|
||||||
input: {
|
|
||||||
var a = 2 ** 7;
|
|
||||||
var b = 3;
|
|
||||||
b **= 2;
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
var a = 2 ** 7;
|
|
||||||
var b = 3;
|
|
||||||
b **= 2;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pow_with_number_constants: {
|
|
||||||
input: {
|
|
||||||
var a = 5 ** NaN;
|
|
||||||
var b = 42 ** +0;
|
|
||||||
var c = 42 ** -0;
|
|
||||||
var d = NaN ** 1;
|
|
||||||
var e = 2 ** Infinity;
|
|
||||||
var f = 2 ** -Infinity;
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
var a = 5 ** NaN;
|
|
||||||
var b = 42 ** +0;
|
|
||||||
var c = 42 ** -0;
|
|
||||||
var d = NaN ** 1;
|
|
||||||
var e = 2 ** (1/0);
|
|
||||||
var f = 2 ** (-1/0);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pow_with_parentheses: {
|
|
||||||
input: {
|
|
||||||
var g = (-7) ** (0.5);
|
|
||||||
var h = 2324334 ** 34343443;
|
|
||||||
var i = (-2324334) ** 34343443;
|
|
||||||
var j = 2 ** (-3);
|
|
||||||
var k = 2.0 ** -3;
|
|
||||||
var l = 2.0 ** (5 - 7);
|
|
||||||
}
|
|
||||||
expect_exact: "var g=(-7)**.5;var h=2324334**34343443;var i=(-2324334)**34343443;var j=2**-3;var k=2**-3;var l=2**(5-7);"
|
|
||||||
}
|
|
||||||
|
|
||||||
pow_with_unary_between_brackets: {
|
|
||||||
input: {
|
|
||||||
var a = (-(+5)) ** 3;
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
var a = (-+5)**3;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
File diff suppressed because it is too large
Load Diff
@@ -2,7 +2,7 @@ must_replace: {
|
|||||||
options = {
|
options = {
|
||||||
global_defs: {
|
global_defs: {
|
||||||
D: "foo bar",
|
D: "foo bar",
|
||||||
}
|
},
|
||||||
}
|
}
|
||||||
input: {
|
input: {
|
||||||
console.log(D);
|
console.log(D);
|
||||||
@@ -121,7 +121,7 @@ mixed: {
|
|||||||
properties: true,
|
properties: true,
|
||||||
}
|
}
|
||||||
input: {
|
input: {
|
||||||
const FOO = { BAR: 0 };
|
var FOO = { BAR: 0 };
|
||||||
console.log(FOO.BAR);
|
console.log(FOO.BAR);
|
||||||
console.log(++CONFIG.DEBUG);
|
console.log(++CONFIG.DEBUG);
|
||||||
console.log(++CONFIG.VALUE);
|
console.log(++CONFIG.VALUE);
|
||||||
@@ -131,7 +131,7 @@ mixed: {
|
|||||||
console.log(CONFIG);
|
console.log(CONFIG);
|
||||||
}
|
}
|
||||||
expect: {
|
expect: {
|
||||||
const FOO = { BAR: 0 };
|
var FOO = { BAR: 0 };
|
||||||
console.log("moo");
|
console.log("moo");
|
||||||
console.log(++CONFIG.DEBUG);
|
console.log(++CONFIG.DEBUG);
|
||||||
console.log(++CONFIG.VALUE);
|
console.log(++CONFIG.VALUE);
|
||||||
@@ -141,9 +141,8 @@ mixed: {
|
|||||||
console.log(CONFIG);
|
console.log(CONFIG);
|
||||||
}
|
}
|
||||||
expect_warnings: [
|
expect_warnings: [
|
||||||
'WARN: global_defs CONFIG.VALUE redefined [test/compress/global_defs.js:127,22]',
|
"WARN: global_defs CONFIG.VALUE redefined [test/compress/global_defs.js:4,22]",
|
||||||
'WARN: global_defs CONFIG.VALUE redefined [test/compress/global_defs.js:128,22]',
|
"WARN: global_defs CONFIG.VALUE redefined [test/compress/global_defs.js:7,8]",
|
||||||
'WARN: global_defs CONFIG.VALUE redefined [test/compress/global_defs.js:130,8]',
|
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -197,3 +196,23 @@ issue_2167: {
|
|||||||
doWork();
|
doWork();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
issue_3217: {
|
||||||
|
options = {
|
||||||
|
collapse_vars: true,
|
||||||
|
global_defs: {
|
||||||
|
"@o": "{fn:function(){var a=42;console.log(a)}}",
|
||||||
|
},
|
||||||
|
inline: true,
|
||||||
|
properties: true,
|
||||||
|
reduce_vars: true,
|
||||||
|
side_effects: true,
|
||||||
|
unused: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
o.fn();
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
console.log(42);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@@ -1,85 +0,0 @@
|
|||||||
|
|
||||||
hoist_vars: {
|
|
||||||
options = {
|
|
||||||
hoist_vars: true
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
function a() {
|
|
||||||
bar();
|
|
||||||
var var1;
|
|
||||||
var var2;
|
|
||||||
}
|
|
||||||
function b(anArg) {
|
|
||||||
bar();
|
|
||||||
var var1;
|
|
||||||
var anArg;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
function a() {
|
|
||||||
var var1, var2; // Vars go up and are joined
|
|
||||||
bar();
|
|
||||||
}
|
|
||||||
function b(anArg) {
|
|
||||||
var var1;
|
|
||||||
bar();
|
|
||||||
// But vars named like arguments go away!
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
hoist_funs: {
|
|
||||||
options = {
|
|
||||||
hoist_funs: true
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
function a() {
|
|
||||||
bar();
|
|
||||||
function foo() {}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
function a() {
|
|
||||||
function foo() {} // Funs go up
|
|
||||||
bar();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
hoist_no_destructurings: {
|
|
||||||
options = {
|
|
||||||
hoist_vars: true,
|
|
||||||
hoist_funs: true
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
function a([anArg]) {
|
|
||||||
bar();
|
|
||||||
var var1;
|
|
||||||
var anArg; // Because anArg is already declared, this goes away!
|
|
||||||
}
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
function a([anArg]) {
|
|
||||||
var var1;
|
|
||||||
bar();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
dont_hoist_var_destructurings: {
|
|
||||||
options = {
|
|
||||||
hoist_vars: true,
|
|
||||||
hoist_funs: true
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
function x() {
|
|
||||||
// If foo is null or undefined, this should be an exception
|
|
||||||
var {x,y} = foo;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
function x() {
|
|
||||||
var {x,y} = foo;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,8 +1,8 @@
|
|||||||
issue_2377_1: {
|
issue_2377_1: {
|
||||||
options = {
|
options = {
|
||||||
evaluate: true,
|
evaluate: true,
|
||||||
inline: true,
|
|
||||||
hoist_props: true,
|
hoist_props: true,
|
||||||
|
inline: true,
|
||||||
reduce_funcs: true,
|
reduce_funcs: true,
|
||||||
reduce_vars: true,
|
reduce_vars: true,
|
||||||
toplevel: true,
|
toplevel: true,
|
||||||
@@ -33,8 +33,8 @@ issue_2377_1: {
|
|||||||
issue_2377_2: {
|
issue_2377_2: {
|
||||||
options = {
|
options = {
|
||||||
evaluate: true,
|
evaluate: true,
|
||||||
inline: true,
|
|
||||||
hoist_props: true,
|
hoist_props: true,
|
||||||
|
inline: true,
|
||||||
passes: 2,
|
passes: 2,
|
||||||
reduce_funcs: true,
|
reduce_funcs: true,
|
||||||
reduce_vars: true,
|
reduce_vars: true,
|
||||||
@@ -55,9 +55,8 @@ issue_2377_2: {
|
|||||||
console.log(obj.foo, obj.cube(3));
|
console.log(obj.foo, obj.cube(3));
|
||||||
}
|
}
|
||||||
expect: {
|
expect: {
|
||||||
console.log(1, function(x) {
|
console.log(1, (x = 3, x * x * x));
|
||||||
return x * x * x;
|
var x;
|
||||||
}(3));
|
|
||||||
}
|
}
|
||||||
expect_stdout: "1 27"
|
expect_stdout: "1 27"
|
||||||
}
|
}
|
||||||
@@ -65,11 +64,12 @@ issue_2377_2: {
|
|||||||
issue_2377_3: {
|
issue_2377_3: {
|
||||||
options = {
|
options = {
|
||||||
evaluate: true,
|
evaluate: true,
|
||||||
inline: true,
|
|
||||||
hoist_props: true,
|
hoist_props: true,
|
||||||
passes: 3,
|
inline: true,
|
||||||
|
passes: 4,
|
||||||
reduce_funcs: true,
|
reduce_funcs: true,
|
||||||
reduce_vars: true,
|
reduce_vars: true,
|
||||||
|
side_effects: true,
|
||||||
toplevel: true,
|
toplevel: true,
|
||||||
unused: true,
|
unused: true,
|
||||||
}
|
}
|
||||||
@@ -239,14 +239,14 @@ name_collision_2: {
|
|||||||
input: {
|
input: {
|
||||||
var o = {
|
var o = {
|
||||||
p: 1,
|
p: 1,
|
||||||
0: function(x) {
|
"+": function(x) {
|
||||||
return x;
|
return x;
|
||||||
},
|
},
|
||||||
1: function(x) {
|
"-": 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[0](4), o[1](5), o__$0, o__$1);
|
console.log(o.p === o.p, o["+"](4), o["-"](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,
|
||||||
0: function(x) {
|
"+": function(x) {
|
||||||
return x;
|
return x;
|
||||||
},
|
},
|
||||||
1: function(x) {
|
"-": 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[0](4), o[1](5));
|
console.log(o.p === o.p, o["+"](4), o["-"](5));
|
||||||
}
|
}
|
||||||
expect: {
|
expect: {
|
||||||
var o_p = 1,
|
var o_p = 1,
|
||||||
@@ -383,120 +383,6 @@ contains_this_3: {
|
|||||||
expect_stdout: "1 1 true"
|
expect_stdout: "1 1 true"
|
||||||
}
|
}
|
||||||
|
|
||||||
hoist_class: {
|
|
||||||
options = {
|
|
||||||
comparisons: true,
|
|
||||||
evaluate: true,
|
|
||||||
hoist_props: true,
|
|
||||||
inline: true,
|
|
||||||
keep_classnames: true,
|
|
||||||
keep_fnames: true,
|
|
||||||
passes: 2,
|
|
||||||
reduce_funcs: true,
|
|
||||||
reduce_vars: true,
|
|
||||||
toplevel: true,
|
|
||||||
unused: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
function run(c, v) {
|
|
||||||
return new c(v).value;
|
|
||||||
}
|
|
||||||
var o = {
|
|
||||||
p: class Foo {
|
|
||||||
constructor(value) {
|
|
||||||
this.value = value * 10;
|
|
||||||
}
|
|
||||||
},
|
|
||||||
x: 1,
|
|
||||||
y: 2,
|
|
||||||
};
|
|
||||||
console.log(o.p.name, o.p === o.p, run(o.p, o.x), run(o.p, o.y));
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
function run(c, v) {
|
|
||||||
return new c(v).value;
|
|
||||||
}
|
|
||||||
var o_p = class Foo {
|
|
||||||
constructor(value) {
|
|
||||||
this.value = 10 * value;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
console.log(o_p.name, true, run(o_p, 1), run(o_p, 2));
|
|
||||||
}
|
|
||||||
node_version: ">=6"
|
|
||||||
expect_stdout: "Foo true 10 20"
|
|
||||||
}
|
|
||||||
|
|
||||||
hoist_class_with_new: {
|
|
||||||
options = {
|
|
||||||
comparisons: true,
|
|
||||||
evaluate: true,
|
|
||||||
hoist_props: true,
|
|
||||||
inline: true,
|
|
||||||
keep_classnames: true,
|
|
||||||
keep_fnames: true,
|
|
||||||
passes: 2,
|
|
||||||
reduce_funcs: true,
|
|
||||||
reduce_vars: true,
|
|
||||||
toplevel: true,
|
|
||||||
unused: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
var o = {
|
|
||||||
p: class Foo {
|
|
||||||
constructor(value) {
|
|
||||||
this.value = value * 10;
|
|
||||||
}
|
|
||||||
},
|
|
||||||
x: 1,
|
|
||||||
y: 2,
|
|
||||||
};
|
|
||||||
console.log(o.p.name, o.p === o.p, new o.p(o.x).value, new o.p(o.y).value);
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
var o_p = class Foo {
|
|
||||||
constructor(value) {
|
|
||||||
this.value = 10 * value;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
console.log(o_p.name, true, new o_p(1).value, new o_p(2).value);
|
|
||||||
}
|
|
||||||
node_version: ">=6"
|
|
||||||
expect_stdout: "Foo true 10 20"
|
|
||||||
}
|
|
||||||
|
|
||||||
hoist_function_with_call: {
|
|
||||||
options = {
|
|
||||||
comparisons: true,
|
|
||||||
evaluate: true,
|
|
||||||
hoist_props: true,
|
|
||||||
inline: true,
|
|
||||||
keep_fnames: true,
|
|
||||||
passes: 2,
|
|
||||||
reduce_funcs: true,
|
|
||||||
reduce_vars: true,
|
|
||||||
toplevel: true,
|
|
||||||
unused: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
var o = {
|
|
||||||
p: function Foo(value) {
|
|
||||||
return 10 * value;
|
|
||||||
},
|
|
||||||
x: 1,
|
|
||||||
y: 2
|
|
||||||
};
|
|
||||||
console.log(o.p.name, o.p === o.p, o.p(o.x), o.p(o.y));
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
var o_p = function Foo(value){
|
|
||||||
return 10 * value
|
|
||||||
};
|
|
||||||
console.log(o_p.name, true, o_p(1), o_p(2));
|
|
||||||
}
|
|
||||||
expect_stdout: "Foo true 10 20"
|
|
||||||
}
|
|
||||||
|
|
||||||
new_this: {
|
new_this: {
|
||||||
options = {
|
options = {
|
||||||
evaluate: true,
|
evaluate: true,
|
||||||
@@ -526,31 +412,14 @@ 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,
|
||||||
reduce_vars: true,
|
reduce_vars: true,
|
||||||
top_retain: [ "x", "y" ],
|
top_retain: [
|
||||||
|
"x",
|
||||||
|
"y"
|
||||||
|
],
|
||||||
toplevel: true,
|
toplevel: true,
|
||||||
unused: true,
|
unused: true,
|
||||||
}
|
}
|
||||||
@@ -569,7 +438,10 @@ issue_2473_2: {
|
|||||||
options = {
|
options = {
|
||||||
hoist_props: true,
|
hoist_props: true,
|
||||||
reduce_vars: true,
|
reduce_vars: true,
|
||||||
top_retain: [ "x", "y" ],
|
top_retain: [
|
||||||
|
"x",
|
||||||
|
"y"
|
||||||
|
],
|
||||||
toplevel: true,
|
toplevel: true,
|
||||||
unused: true,
|
unused: true,
|
||||||
}
|
}
|
||||||
@@ -768,31 +640,6 @@ issue_2508_5: {
|
|||||||
expect_stdout: true
|
expect_stdout: true
|
||||||
}
|
}
|
||||||
|
|
||||||
issue_2508_6: {
|
|
||||||
options = {
|
|
||||||
collapse_vars: true,
|
|
||||||
hoist_props: true,
|
|
||||||
reduce_vars: true,
|
|
||||||
toplevel: true,
|
|
||||||
unused: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
var o = {
|
|
||||||
f: x => {
|
|
||||||
console.log(x);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
o.f(o.f);
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
var o_f = x => {
|
|
||||||
console.log(x);
|
|
||||||
};
|
|
||||||
o_f(o_f);
|
|
||||||
}
|
|
||||||
expect_stdout: true
|
|
||||||
}
|
|
||||||
|
|
||||||
issue_2519: {
|
issue_2519: {
|
||||||
options = {
|
options = {
|
||||||
collapse_vars: true,
|
collapse_vars: true,
|
||||||
@@ -817,9 +664,311 @@ issue_2519: {
|
|||||||
}
|
}
|
||||||
expect: {
|
expect: {
|
||||||
function testFunc() {
|
function testFunc() {
|
||||||
return 1 * ((6 + 5) / 2);
|
return +((6 + 5) / 2);
|
||||||
}
|
}
|
||||||
console.log(testFunc());
|
console.log(testFunc());
|
||||||
}
|
}
|
||||||
expect_stdout: "5.5"
|
expect_stdout: "5.5"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
undefined_key: {
|
||||||
|
options = {
|
||||||
|
evaluate: true,
|
||||||
|
hoist_props: true,
|
||||||
|
join_vars: true,
|
||||||
|
passes: 4,
|
||||||
|
reduce_vars: true,
|
||||||
|
toplevel: true,
|
||||||
|
unused: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
var a, o = {};
|
||||||
|
o[a] = 1;
|
||||||
|
o.b = 2;
|
||||||
|
console.log(o[a] + o.b);
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
console.log(3);
|
||||||
|
}
|
||||||
|
expect_stdout: "3"
|
||||||
|
}
|
||||||
|
|
||||||
|
issue_3021: {
|
||||||
|
options = {
|
||||||
|
hoist_props: true,
|
||||||
|
reduce_vars: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
var a = 1, b = 2;
|
||||||
|
(function() {
|
||||||
|
b = a;
|
||||||
|
if (a++ + b--)
|
||||||
|
return 1;
|
||||||
|
return;
|
||||||
|
var b = {};
|
||||||
|
})();
|
||||||
|
console.log(a, b);
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
var a = 1, b = 2;
|
||||||
|
(function() {
|
||||||
|
b = a;
|
||||||
|
if (a++ + b--)
|
||||||
|
return 1;
|
||||||
|
return;
|
||||||
|
var b = {};
|
||||||
|
})();
|
||||||
|
console.log(a, b);
|
||||||
|
}
|
||||||
|
expect_stdout: "2 2"
|
||||||
|
}
|
||||||
|
|
||||||
|
issue_3046: {
|
||||||
|
options = {
|
||||||
|
hoist_props: true,
|
||||||
|
reduce_vars: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
console.log(function(a) {
|
||||||
|
do {
|
||||||
|
var b = {
|
||||||
|
c: a++
|
||||||
|
};
|
||||||
|
} while (b.c && a);
|
||||||
|
return a;
|
||||||
|
}(0));
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
console.log(function(a) {
|
||||||
|
do {
|
||||||
|
var b_c = a++;
|
||||||
|
} while (b_c && a);
|
||||||
|
return a;
|
||||||
|
}(0));
|
||||||
|
}
|
||||||
|
expect_stdout: "1"
|
||||||
|
}
|
||||||
|
|
||||||
|
issue_3071_1: {
|
||||||
|
options = {
|
||||||
|
evaluate: true,
|
||||||
|
hoist_props: true,
|
||||||
|
inline: true,
|
||||||
|
join_vars: 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, obj.two);
|
||||||
|
})();
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
console.log(1, 2);
|
||||||
|
}
|
||||||
|
expect_stdout: "1 2"
|
||||||
|
}
|
||||||
|
|
||||||
|
issue_3071_2: {
|
||||||
|
options = {
|
||||||
|
hoist_props: true,
|
||||||
|
inline: true,
|
||||||
|
join_vars: 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, obj.two);
|
||||||
|
var obj;
|
||||||
|
})();
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
console.log(1, 2);
|
||||||
|
}
|
||||||
|
expect_stdout: "1 2"
|
||||||
|
}
|
||||||
|
|
||||||
|
issue_3071_2_toplevel: {
|
||||||
|
options = {
|
||||||
|
hoist_props: true,
|
||||||
|
inline: true,
|
||||||
|
join_vars: 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, obj.two);
|
||||||
|
var obj;
|
||||||
|
})();
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
console.log(1, 2);
|
||||||
|
}
|
||||||
|
expect_stdout: "1 2"
|
||||||
|
}
|
||||||
|
|
||||||
|
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"
|
||||||
|
}
|
||||||
|
|
||||||
|
issue_3411: {
|
||||||
|
options = {
|
||||||
|
hoist_props: true,
|
||||||
|
reduce_vars: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
var c = 1;
|
||||||
|
!function f() {
|
||||||
|
var o = {
|
||||||
|
p: --c && f()
|
||||||
|
};
|
||||||
|
+o || console.log("PASS");
|
||||||
|
}();
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
var c = 1;
|
||||||
|
!function f() {
|
||||||
|
var o_p = --c && f();
|
||||||
|
+{} || console.log("PASS");
|
||||||
|
}();
|
||||||
|
}
|
||||||
|
expect_stdout: "PASS"
|
||||||
|
}
|
||||||
|
|
||||||
|
issue_3440: {
|
||||||
|
options = {
|
||||||
|
hoist_props: true,
|
||||||
|
reduce_vars: true,
|
||||||
|
unused: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
(function() {
|
||||||
|
function f() {
|
||||||
|
console.log(o.p);
|
||||||
|
}
|
||||||
|
var o = {
|
||||||
|
p: "PASS",
|
||||||
|
};
|
||||||
|
return f;
|
||||||
|
})()();
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
(function() {
|
||||||
|
var o_p = "PASS";
|
||||||
|
return function() {
|
||||||
|
console.log(o_p);
|
||||||
|
};
|
||||||
|
})()();
|
||||||
|
}
|
||||||
|
expect_stdout: "PASS"
|
||||||
|
}
|
||||||
|
|
||||||
|
issue_3868: {
|
||||||
|
options = {
|
||||||
|
hoist_props: true,
|
||||||
|
passes: 2,
|
||||||
|
reduce_vars: true,
|
||||||
|
side_effects: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
(function(t) {
|
||||||
|
t = {};
|
||||||
|
({
|
||||||
|
get p() {},
|
||||||
|
q: (console.log("PASS"), +t),
|
||||||
|
}).r;
|
||||||
|
})();
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
(function(t) {
|
||||||
|
t = {};
|
||||||
|
({
|
||||||
|
get p() {},
|
||||||
|
q: (console.log("PASS"), +t),
|
||||||
|
}).r;
|
||||||
|
})();
|
||||||
|
}
|
||||||
|
expect_stdout: "PASS"
|
||||||
|
}
|
||||||
|
|
||||||
|
issue_3871: {
|
||||||
|
options = {
|
||||||
|
hoist_props: true,
|
||||||
|
reduce_vars: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
console.log(function() {
|
||||||
|
do {
|
||||||
|
var b = {
|
||||||
|
get null() {
|
||||||
|
c;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
} while (!b);
|
||||||
|
return "PASS";
|
||||||
|
}());
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
console.log(function() {
|
||||||
|
do {
|
||||||
|
var b = {
|
||||||
|
get null() {
|
||||||
|
c;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
} while (!b);
|
||||||
|
return "PASS";
|
||||||
|
}());
|
||||||
|
}
|
||||||
|
expect_stdout: "PASS"
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,64 +1,107 @@
|
|||||||
html_comment_in_expression: {
|
html_comment_in_expression: {
|
||||||
input: {
|
input: {
|
||||||
function f(a, b, x, y) { return a < !--b && x-- > y; }
|
(function(a, b) {
|
||||||
|
console.log(a < !--b && a-- > b, a, b);
|
||||||
|
})(1, 2);
|
||||||
}
|
}
|
||||||
expect_exact: "function f(a,b,x,y){return a< !--b&&x-- >y}";
|
expect_exact: "(function(a,b){console.log(a<! --b&&a-- >b,a,b)})(1,2);"
|
||||||
|
expect_stdout: "false 1 1"
|
||||||
}
|
}
|
||||||
|
|
||||||
html_comment_in_less_than: {
|
html_comment_in_less_than: {
|
||||||
input: {
|
input: {
|
||||||
function f(a, b) { return a < !--b; }
|
(function(a, b, c) {
|
||||||
|
console.log(
|
||||||
|
a < !--b,
|
||||||
|
a < !--b + c,
|
||||||
|
a + b < !--c,
|
||||||
|
a, b, c
|
||||||
|
);
|
||||||
|
})(1, 2, 3);
|
||||||
}
|
}
|
||||||
expect_exact: "function f(a,b){return a< !--b}";
|
expect_exact: "(function(a,b,c){console.log(a<! --b,a<! --b+c,a+b<! --c,a,b,c)})(1,2,3);"
|
||||||
|
expect_stdout: "false true false 1 0 2"
|
||||||
}
|
}
|
||||||
|
|
||||||
html_comment_in_left_shift: {
|
html_comment_in_left_shift: {
|
||||||
input: {
|
input: {
|
||||||
function f(a, b) { return a << !--b; }
|
(function(a, b, c) {
|
||||||
|
console.log(
|
||||||
|
a << !--b,
|
||||||
|
a << !--b + c,
|
||||||
|
a + b << !--c,
|
||||||
|
a, b, c
|
||||||
|
);
|
||||||
|
})(1, 2, 3);
|
||||||
}
|
}
|
||||||
expect_exact: "function f(a,b){return a<< !--b}";
|
expect_exact: "(function(a,b,c){console.log(a<<! --b,a<<! --b+c,a+b<<! --c,a,b,c)})(1,2,3);"
|
||||||
}
|
expect_stdout: "1 16 1 1 0 2"
|
||||||
|
|
||||||
html_comment_in_right_shift: {
|
|
||||||
input: {
|
|
||||||
function f(a, b) { return a-- >> b; }
|
|
||||||
}
|
|
||||||
expect_exact: "function f(a,b){return a-- >>b}";
|
|
||||||
}
|
|
||||||
|
|
||||||
html_comment_in_zero_fill_right_shift: {
|
|
||||||
input: {
|
|
||||||
function f(a, b) { return a-- >>> b; }
|
|
||||||
}
|
|
||||||
expect_exact: "function f(a,b){return a-- >>>b}";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
html_comment_in_greater_than: {
|
html_comment_in_greater_than: {
|
||||||
input: {
|
input: {
|
||||||
function f(a, b) { return a-- > b; }
|
(function(a, b, c) {
|
||||||
|
console.log(
|
||||||
|
a-- > b,
|
||||||
|
a-- > b + c,
|
||||||
|
a + b-- > c,
|
||||||
|
a, b, c
|
||||||
|
);
|
||||||
|
})(1, 2, 3);
|
||||||
}
|
}
|
||||||
expect_exact: "function f(a,b){return a-- >b}";
|
expect_exact: "(function(a,b,c){console.log(a-- >b,a-- >b+c,a+b-- >c,a,b,c)})(1,2,3);"
|
||||||
|
expect_stdout: "false false false -1 1 3"
|
||||||
}
|
}
|
||||||
|
|
||||||
html_comment_in_greater_than_or_equal: {
|
html_comment_in_greater_than_or_equal: {
|
||||||
input: {
|
input: {
|
||||||
function f(a, b) { return a-- >= b; }
|
(function(a, b, c) {
|
||||||
|
console.log(
|
||||||
|
a-- >= b,
|
||||||
|
a-- >= b + c,
|
||||||
|
a + b-- >= c,
|
||||||
|
a, b, c
|
||||||
|
);
|
||||||
|
})(1, 2, 3);
|
||||||
}
|
}
|
||||||
expect_exact: "function f(a,b){return a-- >=b}";
|
expect_exact: "(function(a,b,c){console.log(a-- >=b,a-- >=b+c,a+b-- >=c,a,b,c)})(1,2,3);"
|
||||||
|
expect_stdout: "false false false -1 1 3"
|
||||||
|
}
|
||||||
|
|
||||||
|
html_comment_in_right_shift: {
|
||||||
|
input: {
|
||||||
|
(function(a, b, c) {
|
||||||
|
console.log(
|
||||||
|
a-- >> b,
|
||||||
|
a-- >> b + c,
|
||||||
|
a + b-- >> c,
|
||||||
|
a, b, c
|
||||||
|
);
|
||||||
|
})(1, 2, 3);
|
||||||
|
}
|
||||||
|
expect_exact: "(function(a,b,c){console.log(a-- >>b,a-- >>b+c,a+b-- >>c,a,b,c)})(1,2,3);"
|
||||||
|
expect_stdout: "0 0 0 -1 1 3"
|
||||||
|
}
|
||||||
|
|
||||||
|
html_comment_in_zero_fill_right_shift: {
|
||||||
|
input: {
|
||||||
|
(function(a, b, c) {
|
||||||
|
console.log(
|
||||||
|
a-- >>> b,
|
||||||
|
a-- >>> b + c,
|
||||||
|
a + b-- >>> c,
|
||||||
|
a, b, c
|
||||||
|
);
|
||||||
|
})(1, 2, 3);
|
||||||
|
}
|
||||||
|
expect_exact: "(function(a,b,c){console.log(a-- >>>b,a-- >>>b+c,a+b-- >>>c,a,b,c)})(1,2,3);"
|
||||||
|
expect_stdout: "0 0 0 -1 1 3"
|
||||||
}
|
}
|
||||||
|
|
||||||
html_comment_in_string_literal: {
|
html_comment_in_string_literal: {
|
||||||
input: {
|
input: {
|
||||||
function f() { return "<!--HTML-->comment in<!--string literal-->"; }
|
console.log("<!--HTML-->comment in<!--string literal-->".length);
|
||||||
}
|
}
|
||||||
expect_exact: 'function f(){return"\\x3c!--HTML--\\x3ecomment in\\x3c!--string literal--\\x3e"}';
|
expect_exact: 'console.log("\\x3c!--HTML--\\x3ecomment in\\x3c!--string literal--\\x3e".length);'
|
||||||
}
|
expect_stdout: "42"
|
||||||
|
|
||||||
html_comment_after_multiline_comment: {
|
|
||||||
input: {
|
|
||||||
var foo; /*
|
|
||||||
*/--> var bar;
|
|
||||||
var foobar;
|
|
||||||
}
|
|
||||||
expect_exact: "var foo;var foobar;"
|
|
||||||
}
|
}
|
||||||
|
|||||||
2524
test/compress/ie8.js
Normal file
2524
test/compress/ie8.js
Normal file
File diff suppressed because it is too large
Load Diff
@@ -1,14 +1,14 @@
|
|||||||
if_return_1: {
|
if_return_1: {
|
||||||
options = {
|
options = {
|
||||||
if_return : true,
|
booleans: true,
|
||||||
sequences : true,
|
comparisons: true,
|
||||||
conditionals : true,
|
conditionals: true,
|
||||||
comparisons : true,
|
dead_code: true,
|
||||||
evaluate : true,
|
evaluate: true,
|
||||||
booleans : true,
|
if_return: true,
|
||||||
unused : true,
|
sequences: true,
|
||||||
side_effects : true,
|
side_effects: true,
|
||||||
dead_code : true,
|
unused: true,
|
||||||
}
|
}
|
||||||
input: {
|
input: {
|
||||||
function f(x) {
|
function f(x) {
|
||||||
@@ -24,15 +24,15 @@ if_return_1: {
|
|||||||
|
|
||||||
if_return_2: {
|
if_return_2: {
|
||||||
options = {
|
options = {
|
||||||
if_return : true,
|
booleans: true,
|
||||||
sequences : true,
|
comparisons: true,
|
||||||
conditionals : true,
|
conditionals: true,
|
||||||
comparisons : true,
|
dead_code: true,
|
||||||
evaluate : true,
|
evaluate: true,
|
||||||
booleans : true,
|
if_return: true,
|
||||||
unused : true,
|
sequences: true,
|
||||||
side_effects : true,
|
side_effects: true,
|
||||||
dead_code : true,
|
unused: true,
|
||||||
}
|
}
|
||||||
input: {
|
input: {
|
||||||
function f(x, y) {
|
function f(x, y) {
|
||||||
@@ -49,15 +49,15 @@ if_return_2: {
|
|||||||
|
|
||||||
if_return_3: {
|
if_return_3: {
|
||||||
options = {
|
options = {
|
||||||
if_return : true,
|
booleans: true,
|
||||||
sequences : true,
|
comparisons: true,
|
||||||
conditionals : true,
|
conditionals: true,
|
||||||
comparisons : true,
|
dead_code: true,
|
||||||
evaluate : true,
|
evaluate: true,
|
||||||
booleans : true,
|
if_return: true,
|
||||||
unused : true,
|
sequences: true,
|
||||||
side_effects : true,
|
side_effects: true,
|
||||||
dead_code : true,
|
unused: true,
|
||||||
}
|
}
|
||||||
input: {
|
input: {
|
||||||
function f(x) {
|
function f(x) {
|
||||||
@@ -75,15 +75,15 @@ if_return_3: {
|
|||||||
|
|
||||||
if_return_4: {
|
if_return_4: {
|
||||||
options = {
|
options = {
|
||||||
if_return : true,
|
booleans: true,
|
||||||
sequences : true,
|
comparisons: true,
|
||||||
conditionals : true,
|
conditionals: true,
|
||||||
comparisons : true,
|
dead_code: true,
|
||||||
evaluate : true,
|
evaluate: true,
|
||||||
booleans : true,
|
if_return: true,
|
||||||
unused : true,
|
sequences: true,
|
||||||
side_effects : true,
|
side_effects: true,
|
||||||
dead_code : true,
|
unused: true,
|
||||||
}
|
}
|
||||||
input: {
|
input: {
|
||||||
function f(x, y) {
|
function f(x, y) {
|
||||||
@@ -100,15 +100,15 @@ if_return_4: {
|
|||||||
|
|
||||||
if_return_5: {
|
if_return_5: {
|
||||||
options = {
|
options = {
|
||||||
if_return : true,
|
booleans: true,
|
||||||
sequences : true,
|
comparisons: true,
|
||||||
conditionals : true,
|
conditionals: true,
|
||||||
comparisons : true,
|
dead_code: true,
|
||||||
evaluate : true,
|
evaluate: true,
|
||||||
booleans : true,
|
if_return: true,
|
||||||
unused : true,
|
sequences: true,
|
||||||
side_effects : true,
|
side_effects: true,
|
||||||
dead_code : true,
|
unused: true,
|
||||||
}
|
}
|
||||||
input: {
|
input: {
|
||||||
function f() {
|
function f() {
|
||||||
@@ -126,15 +126,15 @@ if_return_5: {
|
|||||||
|
|
||||||
if_return_6: {
|
if_return_6: {
|
||||||
options = {
|
options = {
|
||||||
if_return : true,
|
booleans: true,
|
||||||
sequences : true,
|
comparisons: true,
|
||||||
conditionals : true,
|
conditionals: true,
|
||||||
comparisons : true,
|
dead_code: true,
|
||||||
evaluate : true,
|
evaluate: true,
|
||||||
booleans : true,
|
if_return: true,
|
||||||
unused : true,
|
sequences: true,
|
||||||
side_effects : true,
|
side_effects: true,
|
||||||
dead_code : true,
|
unused: true,
|
||||||
}
|
}
|
||||||
input: {
|
input: {
|
||||||
function f(x) {
|
function f(x) {
|
||||||
@@ -150,15 +150,15 @@ if_return_6: {
|
|||||||
|
|
||||||
if_return_7: {
|
if_return_7: {
|
||||||
options = {
|
options = {
|
||||||
if_return : true,
|
booleans: true,
|
||||||
sequences : true,
|
comparisons: true,
|
||||||
conditionals : true,
|
conditionals: true,
|
||||||
comparisons : true,
|
dead_code: true,
|
||||||
evaluate : true,
|
evaluate: true,
|
||||||
booleans : true,
|
if_return: true,
|
||||||
unused : true,
|
sequences: true,
|
||||||
side_effects : true,
|
side_effects: true,
|
||||||
dead_code : true,
|
unused: true,
|
||||||
}
|
}
|
||||||
input: {
|
input: {
|
||||||
function f(x) {
|
function f(x) {
|
||||||
@@ -176,10 +176,10 @@ if_return_7: {
|
|||||||
|
|
||||||
if_return_8: {
|
if_return_8: {
|
||||||
options = {
|
options = {
|
||||||
if_return: true,
|
conditionals: true,
|
||||||
sequences: true,
|
if_return: true,
|
||||||
conditionals: true,
|
sequences: true,
|
||||||
side_effects : true,
|
side_effects: true,
|
||||||
}
|
}
|
||||||
input: {
|
input: {
|
||||||
function f(e) {
|
function f(e) {
|
||||||
@@ -220,15 +220,15 @@ if_return_8: {
|
|||||||
|
|
||||||
issue_1089: {
|
issue_1089: {
|
||||||
options = {
|
options = {
|
||||||
if_return : true,
|
booleans: true,
|
||||||
sequences : true,
|
comparisons: true,
|
||||||
conditionals : true,
|
conditionals: true,
|
||||||
comparisons : true,
|
dead_code: true,
|
||||||
evaluate : true,
|
evaluate: true,
|
||||||
booleans : true,
|
if_return: true,
|
||||||
unused : true,
|
sequences: true,
|
||||||
side_effects : true,
|
side_effects: true,
|
||||||
dead_code : true,
|
unused: true,
|
||||||
}
|
}
|
||||||
input: {
|
input: {
|
||||||
function x() {
|
function x() {
|
||||||
@@ -243,7 +243,7 @@ issue_1089: {
|
|||||||
expect: {
|
expect: {
|
||||||
function x() {
|
function x() {
|
||||||
var f = document.getElementById("fname");
|
var f = document.getElementById("fname");
|
||||||
if (f.files[0].size > 12345)
|
if (12345 < f.files[0].size)
|
||||||
return alert("alert"), f.focus(), !1;
|
return alert("alert"), f.focus(), !1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -251,9 +251,9 @@ issue_1089: {
|
|||||||
|
|
||||||
issue_1437: {
|
issue_1437: {
|
||||||
options = {
|
options = {
|
||||||
if_return : true,
|
conditionals: false,
|
||||||
sequences : true,
|
if_return: true,
|
||||||
conditionals : false
|
sequences: true,
|
||||||
}
|
}
|
||||||
input: {
|
input: {
|
||||||
function x() {
|
function x() {
|
||||||
@@ -281,9 +281,9 @@ issue_1437: {
|
|||||||
|
|
||||||
issue_1437_conditionals: {
|
issue_1437_conditionals: {
|
||||||
options = {
|
options = {
|
||||||
conditionals : true,
|
conditionals: true,
|
||||||
if_return : true,
|
if_return: true,
|
||||||
sequences : true
|
sequences: true,
|
||||||
}
|
}
|
||||||
input: {
|
input: {
|
||||||
function x() {
|
function x() {
|
||||||
@@ -327,60 +327,270 @@ issue_512: {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
issue_1317: {
|
if_var_return: {
|
||||||
options = {
|
options = {
|
||||||
|
conditionals: true,
|
||||||
if_return: true,
|
if_return: true,
|
||||||
|
join_vars: true,
|
||||||
|
sequences: true,
|
||||||
}
|
}
|
||||||
input: {
|
input: {
|
||||||
!function(a) {
|
function f() {
|
||||||
if (a) return;
|
var a;
|
||||||
let b = 1;
|
return;
|
||||||
function g() {
|
var b;
|
||||||
return b;
|
}
|
||||||
|
function g() {
|
||||||
|
var a;
|
||||||
|
if (u()) {
|
||||||
|
var b;
|
||||||
|
return v();
|
||||||
|
var c;
|
||||||
}
|
}
|
||||||
console.log(g());
|
var d;
|
||||||
}();
|
if (w()) {
|
||||||
|
var e;
|
||||||
|
return x();
|
||||||
|
var f;
|
||||||
|
} else {
|
||||||
|
var g;
|
||||||
|
y();
|
||||||
|
var h;
|
||||||
|
}
|
||||||
|
var i;
|
||||||
|
z();
|
||||||
|
var j;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
expect: {
|
expect: {
|
||||||
!function(a) {
|
function f() {
|
||||||
if (a) return;
|
var a, b;
|
||||||
let b = 1;
|
}
|
||||||
function g() {
|
function g() {
|
||||||
return b;
|
var a, b, c, d, e, f, g, h, i, j;
|
||||||
}
|
return u() ? v() : w() ? x() : (y(), z(), void 0);
|
||||||
console.log(g());
|
}
|
||||||
}();
|
|
||||||
}
|
}
|
||||||
expect_stdout: "1"
|
|
||||||
node_version: ">=6"
|
|
||||||
}
|
}
|
||||||
|
|
||||||
issue_1317_strict: {
|
if_if_return_return: {
|
||||||
|
options = {
|
||||||
|
conditionals: true,
|
||||||
|
if_return: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
function f(a, b) {
|
||||||
|
if (a) {
|
||||||
|
if (b)
|
||||||
|
return b;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
g();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
function f(a, b) {
|
||||||
|
if (a)
|
||||||
|
return b || void 0;
|
||||||
|
g();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if_body_return_1: {
|
||||||
options = {
|
options = {
|
||||||
if_return: true,
|
if_return: true,
|
||||||
}
|
}
|
||||||
input: {
|
input: {
|
||||||
"use strict";
|
var c = "PASS";
|
||||||
!function(a) {
|
function f(a, b) {
|
||||||
if (a) return;
|
if (a) {
|
||||||
let b = 1;
|
if (b) throw new Error(c);
|
||||||
function g() {
|
return 42;
|
||||||
return b;
|
|
||||||
}
|
}
|
||||||
console.log(g());
|
return true;
|
||||||
}();
|
}
|
||||||
|
console.log(f(0, 0));
|
||||||
|
console.log(f(0, 1));
|
||||||
|
console.log(f(1, 0));
|
||||||
|
try {
|
||||||
|
f(1, 1);
|
||||||
|
console.log("FAIL");
|
||||||
|
} catch (e) {
|
||||||
|
console.log(e.message);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
expect: {
|
expect: {
|
||||||
"use strict";
|
var c = "PASS";
|
||||||
!function(a) {
|
function f(a, b) {
|
||||||
if (a) return;
|
if (a) {
|
||||||
let b = 1;
|
if (b) throw new Error(c);
|
||||||
function g() {
|
return 42;
|
||||||
return b;
|
|
||||||
}
|
}
|
||||||
console.log(g());
|
return true;
|
||||||
}();
|
}
|
||||||
|
console.log(f(0, 0));
|
||||||
|
console.log(f(0, 1));
|
||||||
|
console.log(f(1, 0));
|
||||||
|
try {
|
||||||
|
f(1, 1);
|
||||||
|
console.log("FAIL");
|
||||||
|
} catch (e) {
|
||||||
|
console.log(e.message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
expect_stdout: [
|
||||||
|
"true",
|
||||||
|
"true",
|
||||||
|
"42",
|
||||||
|
"PASS",
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
|
if_body_return_2: {
|
||||||
|
options = {
|
||||||
|
if_return: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
var c = "PASS";
|
||||||
|
function f(a, b) {
|
||||||
|
if (0 + a) {
|
||||||
|
if (b) throw new Error(c);
|
||||||
|
return 42;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
console.log(f(0, 0));
|
||||||
|
console.log(f(0, 1));
|
||||||
|
console.log(f(1, 0));
|
||||||
|
try {
|
||||||
|
f(1, 1);
|
||||||
|
console.log("FAIL");
|
||||||
|
} catch (e) {
|
||||||
|
console.log(e.message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
var c = "PASS";
|
||||||
|
function f(a, b) {
|
||||||
|
if (0 + a) {
|
||||||
|
if (b) throw new Error(c);
|
||||||
|
return 42;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
console.log(f(0, 0));
|
||||||
|
console.log(f(0, 1));
|
||||||
|
console.log(f(1, 0));
|
||||||
|
try {
|
||||||
|
f(1, 1);
|
||||||
|
console.log("FAIL");
|
||||||
|
} catch (e) {
|
||||||
|
console.log(e.message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
expect_stdout: [
|
||||||
|
"true",
|
||||||
|
"true",
|
||||||
|
"42",
|
||||||
|
"PASS",
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
|
if_body_return_3: {
|
||||||
|
options = {
|
||||||
|
if_return: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
var c = "PASS";
|
||||||
|
function f(a, b) {
|
||||||
|
if (1 == a) {
|
||||||
|
if (b) throw new Error(c);
|
||||||
|
return 42;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
console.log(f(0, 0));
|
||||||
|
console.log(f(0, 1));
|
||||||
|
console.log(f(1, 0));
|
||||||
|
try {
|
||||||
|
f(1, 1);
|
||||||
|
console.log("FAIL");
|
||||||
|
} catch (e) {
|
||||||
|
console.log(e.message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
var c = "PASS";
|
||||||
|
function f(a, b) {
|
||||||
|
if (1 != a) return true;
|
||||||
|
if (b) throw new Error(c);
|
||||||
|
return 42;
|
||||||
|
}
|
||||||
|
console.log(f(0, 0));
|
||||||
|
console.log(f(0, 1));
|
||||||
|
console.log(f(1, 0));
|
||||||
|
try {
|
||||||
|
f(1, 1);
|
||||||
|
console.log("FAIL");
|
||||||
|
} catch (e) {
|
||||||
|
console.log(e.message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
expect_stdout: [
|
||||||
|
"true",
|
||||||
|
"true",
|
||||||
|
"42",
|
||||||
|
"PASS",
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
|
issue_3600: {
|
||||||
|
options = {
|
||||||
|
if_return: true,
|
||||||
|
inline: true,
|
||||||
|
side_effects: true,
|
||||||
|
unused: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
var c = 0;
|
||||||
|
(function() {
|
||||||
|
if ([ ][c++]); else return;
|
||||||
|
return void function() {
|
||||||
|
var b = --b, a = c = 42;
|
||||||
|
return c;
|
||||||
|
}();
|
||||||
|
})();
|
||||||
|
console.log(c);
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
var c = 0;
|
||||||
|
(function() {
|
||||||
|
if ([][c++]) b = --b, c = 42;
|
||||||
|
var b;
|
||||||
|
})();
|
||||||
|
console.log(c);
|
||||||
}
|
}
|
||||||
expect_stdout: "1"
|
expect_stdout: "1"
|
||||||
node_version: ">=4"
|
}
|
||||||
|
|
||||||
|
iife_if_return_simple: {
|
||||||
|
options = {
|
||||||
|
conditionals: true,
|
||||||
|
if_return: true,
|
||||||
|
inline: true,
|
||||||
|
sequences: true,
|
||||||
|
side_effects: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
(function() {
|
||||||
|
if (console)
|
||||||
|
return console.log("PASS");
|
||||||
|
console.log("FAIL");
|
||||||
|
})();
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
console ? console.log("PASS") : console.log("FAIL");
|
||||||
|
}
|
||||||
|
expect_stdout: "PASS"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,8 +0,0 @@
|
|||||||
parenthesis_strings_in_parenthesis: {
|
|
||||||
input: {
|
|
||||||
var foo = ('(');
|
|
||||||
a(')');
|
|
||||||
|
|
||||||
}
|
|
||||||
expect_exact: 'var foo="(";a(")");'
|
|
||||||
}
|
|
||||||
@@ -1,8 +1,17 @@
|
|||||||
non_hoisted_function_after_return: {
|
non_hoisted_function_after_return: {
|
||||||
options = {
|
options = {
|
||||||
hoist_funs: false, dead_code: true, conditionals: true, comparisons: true,
|
booleans: true,
|
||||||
evaluate: true, booleans: true, loops: true, unused: true, keep_fargs: true,
|
comparisons: true,
|
||||||
if_return: true, join_vars: true, cascade: true, side_effects: true
|
conditionals: true,
|
||||||
|
dead_code: true,
|
||||||
|
evaluate: true,
|
||||||
|
hoist_funs: false,
|
||||||
|
if_return: true,
|
||||||
|
join_vars: true,
|
||||||
|
keep_fargs: true,
|
||||||
|
loops: true,
|
||||||
|
side_effects: true,
|
||||||
|
unused: true,
|
||||||
}
|
}
|
||||||
input: {
|
input: {
|
||||||
function foo(x) {
|
function foo(x) {
|
||||||
@@ -21,25 +30,35 @@ non_hoisted_function_after_return: {
|
|||||||
}
|
}
|
||||||
expect: {
|
expect: {
|
||||||
function foo(x) {
|
function foo(x) {
|
||||||
return x ? bar() : baz();
|
return (x ? bar : baz)();
|
||||||
function bar() { return 7 }
|
function bar() { return 7 }
|
||||||
function baz() { return 8 }
|
function baz() { return 8 }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
expect_warnings: [
|
expect_warnings: [
|
||||||
'WARN: Dropping unreachable code [test/compress/issue-1034.js:11,16]',
|
"WARN: Dropping unreachable code [test/compress/issue-1034.js:4,16]",
|
||||||
"WARN: Dropping unreachable code [test/compress/issue-1034.js:14,16]",
|
"WARN: Dropping unreachable code [test/compress/issue-1034.js:7,16]",
|
||||||
"WARN: Dropping unreachable code [test/compress/issue-1034.js:17,12]",
|
"WARN: Dropping unreachable code [test/compress/issue-1034.js:10,12]",
|
||||||
"WARN: Dropping unused function UnusedFunction [test/compress/issue-1034.js:18,21]"
|
"WARN: Dropping unused function UnusedFunction [test/compress/issue-1034.js:11,21]"
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
non_hoisted_function_after_return_2a: {
|
non_hoisted_function_after_return_2a: {
|
||||||
options = {
|
options = {
|
||||||
hoist_funs: false, dead_code: true, conditionals: true, comparisons: true,
|
booleans: true,
|
||||||
evaluate: true, booleans: true, loops: true, unused: true, keep_fargs: true,
|
collapse_vars: false,
|
||||||
if_return: true, join_vars: true, cascade: true, side_effects: true,
|
comparisons: true,
|
||||||
collapse_vars: false, passes: 2, warnings: "verbose"
|
conditionals: true,
|
||||||
|
dead_code: true,
|
||||||
|
evaluate: true,
|
||||||
|
hoist_funs: false,
|
||||||
|
if_return: true,
|
||||||
|
join_vars: true,
|
||||||
|
keep_fargs: true,
|
||||||
|
loops: true,
|
||||||
|
passes: 2,
|
||||||
|
side_effects: true,
|
||||||
|
unused: true,
|
||||||
}
|
}
|
||||||
input: {
|
input: {
|
||||||
function foo(x) {
|
function foo(x) {
|
||||||
@@ -65,28 +84,37 @@ non_hoisted_function_after_return_2a: {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
expect_warnings: [
|
expect_warnings: [
|
||||||
"WARN: Dropping unreachable code [test/compress/issue-1034.js:48,16]",
|
"WARN: Dropping unreachable code [test/compress/issue-1034.js:4,16]",
|
||||||
"WARN: Declarations in unreachable code! [test/compress/issue-1034.js:48,16]",
|
"WARN: Declarations in unreachable code! [test/compress/issue-1034.js:4,16]",
|
||||||
"WARN: Dropping unreachable code [test/compress/issue-1034.js:51,16]",
|
"WARN: Dropping unreachable code [test/compress/issue-1034.js:7,16]",
|
||||||
"WARN: Declarations in unreachable code! [test/compress/issue-1034.js:51,16]",
|
"WARN: Declarations in unreachable code! [test/compress/issue-1034.js:7,16]",
|
||||||
"WARN: Dropping unused variable a [test/compress/issue-1034.js:48,20]",
|
"WARN: Dropping unused variable a [test/compress/issue-1034.js:4,20]",
|
||||||
"WARN: Dropping unused function nope [test/compress/issue-1034.js:55,21]",
|
"WARN: Dropping unused function nope [test/compress/issue-1034.js:11,21]",
|
||||||
"WARN: pass 0: last_count: Infinity, count: 37",
|
"INFO: pass 0: last_count: Infinity, count: 36",
|
||||||
"WARN: Dropping unreachable code [test/compress/issue-1034.js:53,12]",
|
"WARN: Dropping unreachable code [test/compress/issue-1034.js:9,12]",
|
||||||
"WARN: Declarations in unreachable code! [test/compress/issue-1034.js:53,12]",
|
"WARN: Declarations in unreachable code! [test/compress/issue-1034.js:9,12]",
|
||||||
"WARN: Dropping unreachable code [test/compress/issue-1034.js:56,12]",
|
"WARN: Dropping unreachable code [test/compress/issue-1034.js:12,12]",
|
||||||
"WARN: Dropping unused variable b [test/compress/issue-1034.js:51,20]",
|
"INFO: Dropping unused variable b [test/compress/issue-1034.js:7,20]",
|
||||||
"WARN: Dropping unused variable c [test/compress/issue-1034.js:53,16]",
|
"INFO: Dropping unused variable c [test/compress/issue-1034.js:9,16]",
|
||||||
"WARN: pass 1: last_count: 37, count: 18",
|
"INFO: pass 1: last_count: 36, count: 18",
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
non_hoisted_function_after_return_2b: {
|
non_hoisted_function_after_return_2b: {
|
||||||
options = {
|
options = {
|
||||||
hoist_funs: false, dead_code: true, conditionals: true, comparisons: true,
|
booleans: true,
|
||||||
evaluate: true, booleans: true, loops: true, unused: true, keep_fargs: true,
|
collapse_vars: false,
|
||||||
if_return: true, join_vars: true, cascade: true, side_effects: true,
|
comparisons: true,
|
||||||
collapse_vars: false
|
conditionals: true,
|
||||||
|
dead_code: true,
|
||||||
|
evaluate: true,
|
||||||
|
hoist_funs: false,
|
||||||
|
if_return: true,
|
||||||
|
join_vars: true,
|
||||||
|
keep_fargs: true,
|
||||||
|
loops: true,
|
||||||
|
side_effects: true,
|
||||||
|
unused: true,
|
||||||
}
|
}
|
||||||
input: {
|
input: {
|
||||||
function foo(x) {
|
function foo(x) {
|
||||||
@@ -110,20 +138,28 @@ non_hoisted_function_after_return_2b: {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
expect_warnings: [
|
expect_warnings: [
|
||||||
// duplicate warnings no longer emitted
|
"WARN: Dropping unreachable code [test/compress/issue-1034.js:6,16]",
|
||||||
"WARN: Dropping unreachable code [test/compress/issue-1034.js:97,16]",
|
"WARN: Declarations in unreachable code! [test/compress/issue-1034.js:6,16]",
|
||||||
"WARN: Declarations in unreachable code! [test/compress/issue-1034.js:97,16]",
|
"WARN: Dropping unreachable code [test/compress/issue-1034.js:8,12]",
|
||||||
"WARN: Dropping unreachable code [test/compress/issue-1034.js:99,12]",
|
"WARN: Declarations in unreachable code! [test/compress/issue-1034.js:8,12]",
|
||||||
"WARN: Declarations in unreachable code! [test/compress/issue-1034.js:99,12]",
|
"WARN: Dropping unreachable code [test/compress/issue-1034.js:12,12]",
|
||||||
"WARN: Dropping unreachable code [test/compress/issue-1034.js:103,12]",
|
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
non_hoisted_function_after_return_strict: {
|
non_hoisted_function_after_return_strict: {
|
||||||
options = {
|
options = {
|
||||||
hoist_funs: false, dead_code: true, conditionals: true, comparisons: true,
|
booleans: true,
|
||||||
evaluate: true, booleans: true, loops: true, unused: true, keep_fargs: true,
|
comparisons: true,
|
||||||
if_return: true, join_vars: true, cascade: true, side_effects: true
|
conditionals: true,
|
||||||
|
dead_code: true,
|
||||||
|
evaluate: true,
|
||||||
|
hoist_funs: false,
|
||||||
|
if_return: true,
|
||||||
|
join_vars: true,
|
||||||
|
keep_fargs: true,
|
||||||
|
loops: true,
|
||||||
|
side_effects: true,
|
||||||
|
unused: true,
|
||||||
}
|
}
|
||||||
input: {
|
input: {
|
||||||
"use strict";
|
"use strict";
|
||||||
@@ -145,7 +181,7 @@ non_hoisted_function_after_return_strict: {
|
|||||||
expect: {
|
expect: {
|
||||||
"use strict";
|
"use strict";
|
||||||
function foo(x) {
|
function foo(x) {
|
||||||
return x ? bar() : baz();
|
return (x ? bar : baz)();
|
||||||
function bar() { return 7 }
|
function bar() { return 7 }
|
||||||
function baz() { return 8 }
|
function baz() { return 8 }
|
||||||
}
|
}
|
||||||
@@ -153,19 +189,29 @@ non_hoisted_function_after_return_strict: {
|
|||||||
}
|
}
|
||||||
expect_stdout: "8 7"
|
expect_stdout: "8 7"
|
||||||
expect_warnings: [
|
expect_warnings: [
|
||||||
"WARN: Dropping unreachable code [test/compress/issue-1034.js:133,16]",
|
"WARN: Dropping unreachable code [test/compress/issue-1034.js:5,16]",
|
||||||
"WARN: Dropping unreachable code [test/compress/issue-1034.js:136,16]",
|
"WARN: Dropping unreachable code [test/compress/issue-1034.js:8,16]",
|
||||||
"WARN: Dropping unreachable code [test/compress/issue-1034.js:139,12]",
|
"WARN: Dropping unreachable code [test/compress/issue-1034.js:11,12]",
|
||||||
"WARN: Dropping unused function UnusedFunction [test/compress/issue-1034.js:140,21]",
|
"WARN: Dropping unused function UnusedFunction [test/compress/issue-1034.js:12,21]",
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
non_hoisted_function_after_return_2a_strict: {
|
non_hoisted_function_after_return_2a_strict: {
|
||||||
options = {
|
options = {
|
||||||
hoist_funs: false, dead_code: true, conditionals: true, comparisons: true,
|
booleans: true,
|
||||||
evaluate: true, booleans: true, loops: true, unused: true, keep_fargs: true,
|
collapse_vars: false,
|
||||||
if_return: true, join_vars: true, cascade: true, side_effects: true,
|
comparisons: true,
|
||||||
collapse_vars: false, passes: 2, warnings: "verbose"
|
conditionals: true,
|
||||||
|
dead_code: true,
|
||||||
|
evaluate: true,
|
||||||
|
hoist_funs: false,
|
||||||
|
if_return: true,
|
||||||
|
join_vars: true,
|
||||||
|
keep_fargs: true,
|
||||||
|
loops: true,
|
||||||
|
passes: 2,
|
||||||
|
side_effects: true,
|
||||||
|
unused: true,
|
||||||
}
|
}
|
||||||
input: {
|
input: {
|
||||||
"use strict";
|
"use strict";
|
||||||
@@ -196,28 +242,37 @@ non_hoisted_function_after_return_2a_strict: {
|
|||||||
}
|
}
|
||||||
expect_stdout: "5 6"
|
expect_stdout: "5 6"
|
||||||
expect_warnings: [
|
expect_warnings: [
|
||||||
"WARN: Dropping unreachable code [test/compress/issue-1034.js:175,16]",
|
"WARN: Dropping unreachable code [test/compress/issue-1034.js:5,16]",
|
||||||
"WARN: Declarations in unreachable code! [test/compress/issue-1034.js:175,16]",
|
"WARN: Declarations in unreachable code! [test/compress/issue-1034.js:5,16]",
|
||||||
"WARN: Dropping unreachable code [test/compress/issue-1034.js:178,16]",
|
"WARN: Dropping unreachable code [test/compress/issue-1034.js:8,16]",
|
||||||
"WARN: Declarations in unreachable code! [test/compress/issue-1034.js:178,16]",
|
"WARN: Declarations in unreachable code! [test/compress/issue-1034.js:8,16]",
|
||||||
"WARN: Dropping unused variable a [test/compress/issue-1034.js:175,20]",
|
"WARN: Dropping unused variable a [test/compress/issue-1034.js:5,20]",
|
||||||
"WARN: Dropping unused function nope [test/compress/issue-1034.js:182,21]",
|
"WARN: Dropping unused function nope [test/compress/issue-1034.js:12,21]",
|
||||||
"WARN: pass 0: last_count: Infinity, count: 48",
|
"INFO: pass 0: last_count: Infinity, count: 47",
|
||||||
"WARN: Dropping unreachable code [test/compress/issue-1034.js:180,12]",
|
"WARN: Dropping unreachable code [test/compress/issue-1034.js:10,12]",
|
||||||
"WARN: Declarations in unreachable code! [test/compress/issue-1034.js:180,12]",
|
"WARN: Declarations in unreachable code! [test/compress/issue-1034.js:10,12]",
|
||||||
"WARN: Dropping unreachable code [test/compress/issue-1034.js:183,12]",
|
"WARN: Dropping unreachable code [test/compress/issue-1034.js:13,12]",
|
||||||
"WARN: Dropping unused variable b [test/compress/issue-1034.js:178,20]",
|
"INFO: Dropping unused variable b [test/compress/issue-1034.js:8,20]",
|
||||||
"WARN: Dropping unused variable c [test/compress/issue-1034.js:180,16]",
|
"INFO: Dropping unused variable c [test/compress/issue-1034.js:10,16]",
|
||||||
"WARN: pass 1: last_count: 48, count: 29",
|
"INFO: pass 1: last_count: 47, count: 29",
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
non_hoisted_function_after_return_2b_strict: {
|
non_hoisted_function_after_return_2b_strict: {
|
||||||
options = {
|
options = {
|
||||||
hoist_funs: false, dead_code: true, conditionals: true, comparisons: true,
|
booleans: true,
|
||||||
evaluate: true, booleans: true, loops: true, unused: true, keep_fargs: true,
|
collapse_vars: false,
|
||||||
if_return: true, join_vars: true, cascade: true, side_effects: true,
|
comparisons: true,
|
||||||
collapse_vars: false
|
conditionals: true,
|
||||||
|
dead_code: true,
|
||||||
|
evaluate: true,
|
||||||
|
hoist_funs: false,
|
||||||
|
if_return: true,
|
||||||
|
join_vars: true,
|
||||||
|
keep_fargs: true,
|
||||||
|
loops: true,
|
||||||
|
side_effects: true,
|
||||||
|
unused: true,
|
||||||
}
|
}
|
||||||
input: {
|
input: {
|
||||||
"use strict";
|
"use strict";
|
||||||
@@ -246,11 +301,10 @@ non_hoisted_function_after_return_2b_strict: {
|
|||||||
}
|
}
|
||||||
expect_stdout: "5 6"
|
expect_stdout: "5 6"
|
||||||
expect_warnings: [
|
expect_warnings: [
|
||||||
// duplicate warnings no longer emitted
|
"WARN: Dropping unreachable code [test/compress/issue-1034.js:7,16]",
|
||||||
"WARN: Dropping unreachable code [test/compress/issue-1034.js:229,16]",
|
"WARN: Declarations in unreachable code! [test/compress/issue-1034.js:7,16]",
|
||||||
"WARN: Declarations in unreachable code! [test/compress/issue-1034.js:229,16]",
|
"WARN: Dropping unreachable code [test/compress/issue-1034.js:9,12]",
|
||||||
"WARN: Dropping unreachable code [test/compress/issue-1034.js:231,12]",
|
"WARN: Declarations in unreachable code! [test/compress/issue-1034.js:9,12]",
|
||||||
"WARN: Declarations in unreachable code! [test/compress/issue-1034.js:231,12]",
|
"WARN: Dropping unreachable code [test/compress/issue-1034.js:13,12]",
|
||||||
"WARN: Dropping unreachable code [test/compress/issue-1034.js:235,12]",
|
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,22 +1,9 @@
|
|||||||
const_declaration: {
|
|
||||||
options = {
|
|
||||||
evaluate: true
|
|
||||||
};
|
|
||||||
|
|
||||||
input: {
|
|
||||||
const goog = goog || {};
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
const goog = goog || {};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const_pragma: {
|
const_pragma: {
|
||||||
options = {
|
options = {
|
||||||
evaluate: true,
|
evaluate: true,
|
||||||
reduce_funcs: true,
|
reduce_funcs: true,
|
||||||
reduce_vars: true,
|
reduce_vars: true,
|
||||||
};
|
}
|
||||||
|
|
||||||
input: {
|
input: {
|
||||||
/** @const */ var goog = goog || {};
|
/** @const */ var goog = goog || {};
|
||||||
@@ -32,7 +19,7 @@ not_const: {
|
|||||||
evaluate: true,
|
evaluate: true,
|
||||||
reduce_funcs: true,
|
reduce_funcs: true,
|
||||||
reduce_vars: true,
|
reduce_vars: true,
|
||||||
};
|
}
|
||||||
|
|
||||||
input: {
|
input: {
|
||||||
var goog = goog || {};
|
var goog = goog || {};
|
||||||
|
|||||||
@@ -1,30 +0,0 @@
|
|||||||
issue_1043: {
|
|
||||||
options = {
|
|
||||||
side_effects: true
|
|
||||||
};
|
|
||||||
|
|
||||||
input: {
|
|
||||||
function* range(start = 0, end = null, step = 1) {
|
|
||||||
if (end == null) {
|
|
||||||
end = start;
|
|
||||||
start = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (let i = start; i < end; i += step) {
|
|
||||||
yield i;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
expect: {
|
|
||||||
function* range(start = 0, end = null, step = 1) {
|
|
||||||
if (null == end) {
|
|
||||||
end = start;
|
|
||||||
start = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (let i = start; i < end; i += step)
|
|
||||||
yield i;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,9 +0,0 @@
|
|||||||
issue_1044: {
|
|
||||||
options = { evaluate: true, conditionals: true };
|
|
||||||
input: {
|
|
||||||
const mixed = Base ? class extends Base {} : class {}
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
const mixed = Base ? class extends Base {} : class {}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -134,8 +134,9 @@ defun_hoist_funs: {
|
|||||||
expect: {
|
expect: {
|
||||||
function e() {
|
function e() {
|
||||||
function f() {}
|
function f() {}
|
||||||
|
function g() {}
|
||||||
function h() {}
|
function h() {}
|
||||||
if (window) function g() {}
|
if (window);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
with_in_global_scope: {
|
with_in_global_scope: {
|
||||||
options = {
|
options = {
|
||||||
unused: true
|
unused: true,
|
||||||
}
|
}
|
||||||
input: {
|
input: {
|
||||||
var o = 42;
|
var o = 42;
|
||||||
@@ -18,7 +18,7 @@ with_in_global_scope: {
|
|||||||
}
|
}
|
||||||
with_in_function_scope: {
|
with_in_function_scope: {
|
||||||
options = {
|
options = {
|
||||||
unused: true
|
unused: true,
|
||||||
}
|
}
|
||||||
input: {
|
input: {
|
||||||
function foo() {
|
function foo() {
|
||||||
@@ -40,7 +40,7 @@ with_in_function_scope: {
|
|||||||
}
|
}
|
||||||
compress_with_with_in_other_scope: {
|
compress_with_with_in_other_scope: {
|
||||||
options = {
|
options = {
|
||||||
unused: true
|
unused: true,
|
||||||
}
|
}
|
||||||
input: {
|
input: {
|
||||||
function foo() {
|
function foo() {
|
||||||
@@ -69,7 +69,7 @@ compress_with_with_in_other_scope: {
|
|||||||
}
|
}
|
||||||
with_using_existing_variable_outside_scope: {
|
with_using_existing_variable_outside_scope: {
|
||||||
options = {
|
options = {
|
||||||
unused: true
|
unused: true,
|
||||||
}
|
}
|
||||||
input: {
|
input: {
|
||||||
function f() {
|
function f() {
|
||||||
@@ -99,7 +99,7 @@ with_using_existing_variable_outside_scope: {
|
|||||||
}
|
}
|
||||||
check_drop_unused_in_peer_function: {
|
check_drop_unused_in_peer_function: {
|
||||||
options = {
|
options = {
|
||||||
unused: true
|
unused: true,
|
||||||
}
|
}
|
||||||
input: {
|
input: {
|
||||||
function outer() {
|
function outer() {
|
||||||
@@ -148,7 +148,7 @@ check_drop_unused_in_peer_function: {
|
|||||||
|
|
||||||
Infinity_not_in_with_scope: {
|
Infinity_not_in_with_scope: {
|
||||||
options = {
|
options = {
|
||||||
unused: true
|
unused: true,
|
||||||
}
|
}
|
||||||
input: {
|
input: {
|
||||||
var o = { Infinity: 'oInfinity' };
|
var o = { Infinity: 'oInfinity' };
|
||||||
@@ -164,7 +164,7 @@ Infinity_not_in_with_scope: {
|
|||||||
|
|
||||||
Infinity_in_with_scope: {
|
Infinity_in_with_scope: {
|
||||||
options = {
|
options = {
|
||||||
unused: true
|
unused: true,
|
||||||
}
|
}
|
||||||
input: {
|
input: {
|
||||||
var o = { Infinity: 'oInfinity' };
|
var o = { Infinity: 'oInfinity' };
|
||||||
@@ -180,20 +180,19 @@ Infinity_in_with_scope: {
|
|||||||
|
|
||||||
assorted_Infinity_NaN_undefined_in_with_scope: {
|
assorted_Infinity_NaN_undefined_in_with_scope: {
|
||||||
options = {
|
options = {
|
||||||
unused: true,
|
booleans: true,
|
||||||
evaluate: true,
|
comparisons: true,
|
||||||
dead_code: true,
|
conditionals: true,
|
||||||
conditionals: true,
|
dead_code: true,
|
||||||
comparisons: true,
|
evaluate: true,
|
||||||
booleans: true,
|
hoist_funs: true,
|
||||||
hoist_funs: true,
|
if_return: true,
|
||||||
keep_fargs: true,
|
join_vars: true,
|
||||||
if_return: true,
|
keep_fargs: true,
|
||||||
join_vars: true,
|
|
||||||
cascade: true,
|
|
||||||
side_effects: true,
|
|
||||||
sequences: false,
|
|
||||||
keep_infinity: false,
|
keep_infinity: false,
|
||||||
|
sequences: false,
|
||||||
|
side_effects: true,
|
||||||
|
unused: true,
|
||||||
}
|
}
|
||||||
input: {
|
input: {
|
||||||
var f = console.log;
|
var f = console.log;
|
||||||
@@ -243,20 +242,19 @@ assorted_Infinity_NaN_undefined_in_with_scope: {
|
|||||||
|
|
||||||
assorted_Infinity_NaN_undefined_in_with_scope_keep_infinity: {
|
assorted_Infinity_NaN_undefined_in_with_scope_keep_infinity: {
|
||||||
options = {
|
options = {
|
||||||
unused: true,
|
booleans: true,
|
||||||
evaluate: true,
|
comparisons: true,
|
||||||
dead_code: true,
|
conditionals: true,
|
||||||
conditionals: true,
|
dead_code: true,
|
||||||
comparisons: true,
|
evaluate: true,
|
||||||
booleans: true,
|
hoist_funs: true,
|
||||||
hoist_funs: true,
|
if_return: true,
|
||||||
keep_fargs: true,
|
join_vars: true,
|
||||||
if_return: true,
|
keep_fargs: true,
|
||||||
join_vars: true,
|
|
||||||
cascade: true,
|
|
||||||
side_effects: true,
|
|
||||||
sequences: false,
|
|
||||||
keep_infinity: true,
|
keep_infinity: true,
|
||||||
|
sequences: false,
|
||||||
|
side_effects: true,
|
||||||
|
unused: true,
|
||||||
}
|
}
|
||||||
input: {
|
input: {
|
||||||
var f = console.log;
|
var f = console.log;
|
||||||
|
|||||||
@@ -1,11 +1,15 @@
|
|||||||
keep_name_of_getter: {
|
keep_name_of_getter: {
|
||||||
options = { unused: true };
|
options = {
|
||||||
|
unused: true,
|
||||||
|
}
|
||||||
input: { a = { get foo () {} } }
|
input: { a = { get foo () {} } }
|
||||||
expect: { a = { get foo () {} } }
|
expect: { a = { get foo () {} } }
|
||||||
}
|
}
|
||||||
|
|
||||||
keep_name_of_setter: {
|
keep_name_of_setter: {
|
||||||
options = { unused: true };
|
options = {
|
||||||
|
unused: true,
|
||||||
|
}
|
||||||
input: { a = { set foo () {} } }
|
input: { a = { set foo () {} } }
|
||||||
expect: { a = { set foo () {} } }
|
expect: { a = { set foo () {} } }
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
mangle_keep_fnames_false: {
|
mangle_keep_fnames_false: {
|
||||||
options = {
|
options = {
|
||||||
keep_fnames : true,
|
keep_fargs: true,
|
||||||
keep_fargs : true,
|
keep_fnames: true,
|
||||||
}
|
}
|
||||||
mangle = {
|
mangle = {
|
||||||
keep_fnames : false,
|
keep_fnames : false,
|
||||||
@@ -26,8 +26,8 @@ mangle_keep_fnames_false: {
|
|||||||
|
|
||||||
mangle_keep_fnames_true: {
|
mangle_keep_fnames_true: {
|
||||||
options = {
|
options = {
|
||||||
keep_fnames : true,
|
keep_fargs: true,
|
||||||
keep_fargs : true,
|
keep_fnames: true,
|
||||||
}
|
}
|
||||||
mangle = {
|
mangle = {
|
||||||
keep_fnames : true,
|
keep_fnames : true,
|
||||||
|
|||||||
@@ -1,76 +0,0 @@
|
|||||||
issue_1212_debug_false: {
|
|
||||||
options = {
|
|
||||||
global_defs : { DEBUG: false },
|
|
||||||
sequences : true,
|
|
||||||
properties : true,
|
|
||||||
dead_code : true,
|
|
||||||
conditionals : true,
|
|
||||||
comparisons : true,
|
|
||||||
evaluate : true,
|
|
||||||
booleans : true,
|
|
||||||
loops : true,
|
|
||||||
unused : true,
|
|
||||||
hoist_funs : true,
|
|
||||||
keep_fargs : true,
|
|
||||||
if_return : true,
|
|
||||||
join_vars : true,
|
|
||||||
cascade : true,
|
|
||||||
side_effects : true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
class foo {
|
|
||||||
bar() {
|
|
||||||
if (DEBUG)
|
|
||||||
console.log("DEV");
|
|
||||||
else
|
|
||||||
console.log("PROD");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
new foo().bar();
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
class foo{
|
|
||||||
bar() { console.log("PROD") }
|
|
||||||
}
|
|
||||||
(new foo).bar();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
issue_1212_debug_true: {
|
|
||||||
options = {
|
|
||||||
global_defs : { DEBUG: true },
|
|
||||||
sequences : true,
|
|
||||||
properties : true,
|
|
||||||
dead_code : true,
|
|
||||||
conditionals : true,
|
|
||||||
comparisons : true,
|
|
||||||
evaluate : true,
|
|
||||||
booleans : true,
|
|
||||||
loops : true,
|
|
||||||
unused : true,
|
|
||||||
hoist_funs : true,
|
|
||||||
keep_fargs : true,
|
|
||||||
if_return : true,
|
|
||||||
join_vars : true,
|
|
||||||
cascade : true,
|
|
||||||
side_effects : true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
class foo {
|
|
||||||
bar() {
|
|
||||||
if (DEBUG)
|
|
||||||
console.log("DEV");
|
|
||||||
else
|
|
||||||
console.log("PROD");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
new foo().bar();
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
class foo{
|
|
||||||
bar() { console.log("DEV") }
|
|
||||||
}
|
|
||||||
(new foo).bar();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@@ -1,15 +1,14 @@
|
|||||||
pure_function_calls: {
|
pure_function_calls: {
|
||||||
options = {
|
options = {
|
||||||
evaluate : true,
|
booleans: true,
|
||||||
conditionals : true,
|
comparisons: true,
|
||||||
comparisons : true,
|
conditionals: true,
|
||||||
side_effects : true,
|
evaluate: true,
|
||||||
booleans : true,
|
if_return: true,
|
||||||
unused : true,
|
join_vars: true,
|
||||||
if_return : true,
|
negate_iife: true,
|
||||||
join_vars : true,
|
side_effects: true,
|
||||||
cascade : true,
|
unused: true,
|
||||||
negate_iife : true,
|
|
||||||
}
|
}
|
||||||
input: {
|
input: {
|
||||||
// pure top-level IIFE will be dropped
|
// pure top-level IIFE will be dropped
|
||||||
@@ -49,29 +48,28 @@ pure_function_calls: {
|
|||||||
a.b(), f.g();
|
a.b(), f.g();
|
||||||
}
|
}
|
||||||
expect_warnings: [
|
expect_warnings: [
|
||||||
"WARN: Dropping __PURE__ call [test/compress/issue-1261.js:17,8]",
|
"WARN: Dropping __PURE__ call [test/compress/issue-1261.js:3,8]",
|
||||||
"WARN: Dropping side-effect-free statement [test/compress/issue-1261.js:17,8]",
|
"WARN: Dropping side-effect-free statement [test/compress/issue-1261.js:3,8]",
|
||||||
"WARN: Dropping __PURE__ call [test/compress/issue-1261.js:30,37]",
|
"WARN: Dropping __PURE__ call [test/compress/issue-1261.js:16,37]",
|
||||||
"WARN: Dropping unused variable iife2 [test/compress/issue-1261.js:30,16]",
|
"WARN: Dropping unused variable iife2 [test/compress/issue-1261.js:16,16]",
|
||||||
"WARN: Dropping side-effect-free statement [test/compress/issue-1261.js:28,8]",
|
"WARN: Dropping side-effect-free statement [test/compress/issue-1261.js:14,8]",
|
||||||
"WARN: Dropping __PURE__ call [test/compress/issue-1261.js:38,8]",
|
"WARN: Dropping __PURE__ call [test/compress/issue-1261.js:24,8]",
|
||||||
"WARN: Dropping __PURE__ call [test/compress/issue-1261.js:39,31]",
|
"WARN: Dropping __PURE__ call [test/compress/issue-1261.js:25,31]",
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
pure_function_calls_toplevel: {
|
pure_function_calls_toplevel: {
|
||||||
options = {
|
options = {
|
||||||
evaluate : true,
|
booleans: true,
|
||||||
conditionals : true,
|
comparisons: true,
|
||||||
comparisons : true,
|
conditionals: true,
|
||||||
side_effects : true,
|
evaluate: true,
|
||||||
booleans : true,
|
if_return: true,
|
||||||
unused : true,
|
join_vars: true,
|
||||||
if_return : true,
|
negate_iife: true,
|
||||||
join_vars : true,
|
side_effects: true,
|
||||||
cascade : true,
|
toplevel: true,
|
||||||
negate_iife : true,
|
unused: true,
|
||||||
toplevel : true,
|
|
||||||
}
|
}
|
||||||
input: {
|
input: {
|
||||||
// pure top-level IIFE will be dropped
|
// pure top-level IIFE will be dropped
|
||||||
@@ -112,17 +110,17 @@ pure_function_calls_toplevel: {
|
|||||||
a.b(), f.g();
|
a.b(), f.g();
|
||||||
}
|
}
|
||||||
expect_warnings: [
|
expect_warnings: [
|
||||||
"WARN: Dropping __PURE__ call [test/compress/issue-1261.js:79,8]",
|
"WARN: Dropping __PURE__ call [test/compress/issue-1261.js:3,8]",
|
||||||
"WARN: Dropping side-effect-free statement [test/compress/issue-1261.js:79,8]",
|
"WARN: Dropping side-effect-free statement [test/compress/issue-1261.js:3,8]",
|
||||||
"WARN: Dropping __PURE__ call [test/compress/issue-1261.js:92,37]",
|
"WARN: Dropping __PURE__ call [test/compress/issue-1261.js:16,37]",
|
||||||
"WARN: Dropping unused variable iife2 [test/compress/issue-1261.js:92,16]",
|
"WARN: Dropping unused variable iife2 [test/compress/issue-1261.js:16,16]",
|
||||||
"WARN: Dropping side-effect-free statement [test/compress/issue-1261.js:90,8]",
|
"WARN: Dropping side-effect-free statement [test/compress/issue-1261.js:14,8]",
|
||||||
"WARN: Dropping __PURE__ call [test/compress/issue-1261.js:107,8]",
|
"WARN: Dropping __PURE__ call [test/compress/issue-1261.js:31,8]",
|
||||||
"WARN: Dropping __PURE__ call [test/compress/issue-1261.js:108,31]",
|
"WARN: Dropping __PURE__ call [test/compress/issue-1261.js:32,31]",
|
||||||
"WARN: Dropping __PURE__ call [test/compress/issue-1261.js:84,33]",
|
"WARN: Dropping __PURE__ call [test/compress/issue-1261.js:8,33]",
|
||||||
"WARN: Dropping unused variable iife1 [test/compress/issue-1261.js:84,12]",
|
"WARN: Dropping unused variable iife1 [test/compress/issue-1261.js:8,12]",
|
||||||
"WARN: Dropping __PURE__ call [test/compress/issue-1261.js:100,45]",
|
"WARN: Dropping __PURE__ call [test/compress/issue-1261.js:24,45]",
|
||||||
"WARN: Dropping unused variable MyClass [test/compress/issue-1261.js:100,12]",
|
"WARN: Dropping unused variable MyClass [test/compress/issue-1261.js:24,12]",
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -157,29 +155,29 @@ should_warn: {
|
|||||||
baz();
|
baz();
|
||||||
}
|
}
|
||||||
expect_warnings: [
|
expect_warnings: [
|
||||||
"WARN: Dropping __PURE__ call [test/compress/issue-1261.js:137,61]",
|
"WARN: Dropping __PURE__ call [test/compress/issue-1261.js:1,61]",
|
||||||
"WARN: Dropping __PURE__ call [test/compress/issue-1261.js:137,23]",
|
"WARN: Dropping __PURE__ call [test/compress/issue-1261.js:1,23]",
|
||||||
"WARN: Dropping side-effect-free statement [test/compress/issue-1261.js:137,23]",
|
"WARN: Dropping side-effect-free statement [test/compress/issue-1261.js:1,23]",
|
||||||
"WARN: Boolean || always true [test/compress/issue-1261.js:138,23]",
|
"WARN: Boolean || always true [test/compress/issue-1261.js:2,23]",
|
||||||
"WARN: Dropping __PURE__ call [test/compress/issue-1261.js:138,23]",
|
"WARN: Dropping __PURE__ call [test/compress/issue-1261.js:2,23]",
|
||||||
"WARN: Condition always true [test/compress/issue-1261.js:138,23]",
|
"WARN: Condition always true [test/compress/issue-1261.js:2,23]",
|
||||||
"WARN: Condition left of || always true [test/compress/issue-1261.js:139,8]",
|
"WARN: Condition left of || always true [test/compress/issue-1261.js:3,8]",
|
||||||
"WARN: Condition always true [test/compress/issue-1261.js:139,8]",
|
"WARN: Condition always true [test/compress/issue-1261.js:3,8]",
|
||||||
"WARN: Boolean && always false [test/compress/issue-1261.js:140,23]",
|
"WARN: Boolean && always false [test/compress/issue-1261.js:4,23]",
|
||||||
"WARN: Dropping __PURE__ call [test/compress/issue-1261.js:140,23]",
|
"WARN: Dropping __PURE__ call [test/compress/issue-1261.js:4,23]",
|
||||||
"WARN: Condition always false [test/compress/issue-1261.js:140,23]",
|
"WARN: Condition always false [test/compress/issue-1261.js:4,23]",
|
||||||
"WARN: Condition left of && always false [test/compress/issue-1261.js:141,8]",
|
"WARN: Condition left of && always false [test/compress/issue-1261.js:5,8]",
|
||||||
"WARN: Condition always false [test/compress/issue-1261.js:141,8]",
|
"WARN: Condition always false [test/compress/issue-1261.js:5,8]",
|
||||||
"WARN: + in boolean context always true [test/compress/issue-1261.js:142,23]",
|
"WARN: + in boolean context always true [test/compress/issue-1261.js:6,23]",
|
||||||
"WARN: Dropping __PURE__ call [test/compress/issue-1261.js:142,23]",
|
"WARN: Dropping __PURE__ call [test/compress/issue-1261.js:6,23]",
|
||||||
"WARN: Condition always true [test/compress/issue-1261.js:142,23]",
|
"WARN: Condition always true [test/compress/issue-1261.js:6,23]",
|
||||||
"WARN: + in boolean context always true [test/compress/issue-1261.js:143,8]",
|
"WARN: + in boolean context always true [test/compress/issue-1261.js:7,8]",
|
||||||
"WARN: Dropping __PURE__ call [test/compress/issue-1261.js:143,31]",
|
"WARN: Dropping __PURE__ call [test/compress/issue-1261.js:7,31]",
|
||||||
"WARN: Condition always true [test/compress/issue-1261.js:143,8]",
|
"WARN: Condition always true [test/compress/issue-1261.js:7,8]",
|
||||||
"WARN: Dropping __PURE__ call [test/compress/issue-1261.js:144,23]",
|
"WARN: Dropping __PURE__ call [test/compress/issue-1261.js:8,23]",
|
||||||
"WARN: Dropping __PURE__ call [test/compress/issue-1261.js:145,24]",
|
"WARN: Condition always true [test/compress/issue-1261.js:9,8]",
|
||||||
"WARN: Condition always true [test/compress/issue-1261.js:145,8]",
|
"WARN: Dropping __PURE__ call [test/compress/issue-1261.js:9,24]",
|
||||||
"WARN: Dropping __PURE__ call [test/compress/issue-1261.js:146,31]",
|
"WARN: Dropping __PURE__ call [test/compress/issue-1261.js:10,31]",
|
||||||
"WARN: Condition always false [test/compress/issue-1261.js:146,8]",
|
"WARN: Condition always false [test/compress/issue-1261.js:10,8]",
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,17 +1,16 @@
|
|||||||
string_plus_optimization: {
|
string_plus_optimization: {
|
||||||
options = {
|
options = {
|
||||||
side_effects : true,
|
booleans: true,
|
||||||
evaluate : true,
|
comparisons: true,
|
||||||
conditionals : true,
|
conditionals: true,
|
||||||
comparisons : true,
|
dead_code: true,
|
||||||
dead_code : true,
|
evaluate: true,
|
||||||
booleans : true,
|
hoist_funs: true,
|
||||||
unused : true,
|
if_return: true,
|
||||||
if_return : true,
|
join_vars: true,
|
||||||
join_vars : true,
|
side_effects: true,
|
||||||
cascade : true,
|
unused: true,
|
||||||
hoist_funs : true,
|
}
|
||||||
};
|
|
||||||
input: {
|
input: {
|
||||||
function foo(anything) {
|
function foo(anything) {
|
||||||
function throwing_function() {
|
function throwing_function() {
|
||||||
|
|||||||
@@ -15,7 +15,7 @@
|
|||||||
tranformation_sort_order_equal: {
|
tranformation_sort_order_equal: {
|
||||||
options = {
|
options = {
|
||||||
comparisons: true,
|
comparisons: true,
|
||||||
};
|
}
|
||||||
|
|
||||||
input: { (a = parseInt('100')) == a }
|
input: { (a = parseInt('100')) == a }
|
||||||
expect: { (a = parseInt('100')) == a }
|
expect: { (a = parseInt('100')) == a }
|
||||||
@@ -24,7 +24,7 @@ tranformation_sort_order_equal: {
|
|||||||
tranformation_sort_order_unequal: {
|
tranformation_sort_order_unequal: {
|
||||||
options = {
|
options = {
|
||||||
comparisons: true,
|
comparisons: true,
|
||||||
};
|
}
|
||||||
|
|
||||||
input: { (a = parseInt('100')) != a }
|
input: { (a = parseInt('100')) != a }
|
||||||
expect: { (a = parseInt('100')) != a }
|
expect: { (a = parseInt('100')) != a }
|
||||||
@@ -33,7 +33,7 @@ tranformation_sort_order_unequal: {
|
|||||||
tranformation_sort_order_lesser_or_equal: {
|
tranformation_sort_order_lesser_or_equal: {
|
||||||
options = {
|
options = {
|
||||||
comparisons: true,
|
comparisons: true,
|
||||||
};
|
}
|
||||||
|
|
||||||
input: { (a = parseInt('100')) <= a }
|
input: { (a = parseInt('100')) <= a }
|
||||||
expect: { (a = parseInt('100')) <= a }
|
expect: { (a = parseInt('100')) <= a }
|
||||||
@@ -41,7 +41,7 @@ tranformation_sort_order_lesser_or_equal: {
|
|||||||
tranformation_sort_order_greater_or_equal: {
|
tranformation_sort_order_greater_or_equal: {
|
||||||
options = {
|
options = {
|
||||||
comparisons: true,
|
comparisons: true,
|
||||||
};
|
}
|
||||||
|
|
||||||
input: { (a = parseInt('100')) >= a }
|
input: { (a = parseInt('100')) >= a }
|
||||||
expect: { (a = parseInt('100')) >= a }
|
expect: { (a = parseInt('100')) >= a }
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
level_zero: {
|
level_zero: {
|
||||||
options = {
|
options = {
|
||||||
keep_fnames: true
|
keep_fnames: true,
|
||||||
}
|
}
|
||||||
mangle = {
|
mangle = {
|
||||||
keep_fnames: true
|
keep_fnames: true
|
||||||
@@ -29,7 +29,7 @@ level_zero: {
|
|||||||
|
|
||||||
level_one: {
|
level_one: {
|
||||||
options = {
|
options = {
|
||||||
keep_fnames: true
|
keep_fnames: true,
|
||||||
}
|
}
|
||||||
mangle = {
|
mangle = {
|
||||||
keep_fnames: true
|
keep_fnames: true
|
||||||
@@ -58,7 +58,7 @@ level_one: {
|
|||||||
|
|
||||||
level_two: {
|
level_two: {
|
||||||
options = {
|
options = {
|
||||||
keep_fnames: true
|
keep_fnames: true,
|
||||||
}
|
}
|
||||||
mangle = {
|
mangle = {
|
||||||
keep_fnames: true
|
keep_fnames: true
|
||||||
@@ -97,7 +97,7 @@ level_two: {
|
|||||||
|
|
||||||
level_three: {
|
level_three: {
|
||||||
options = {
|
options = {
|
||||||
keep_fnames: true
|
keep_fnames: true,
|
||||||
}
|
}
|
||||||
mangle = {
|
mangle = {
|
||||||
keep_fnames: true
|
keep_fnames: true
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ unsafe_undefined: {
|
|||||||
options = {
|
options = {
|
||||||
conditionals: true,
|
conditionals: true,
|
||||||
if_return: true,
|
if_return: true,
|
||||||
unsafe: true
|
unsafe_undefined: true,
|
||||||
}
|
}
|
||||||
mangle = {}
|
mangle = {}
|
||||||
input: {
|
input: {
|
||||||
@@ -30,7 +30,7 @@ keep_fnames: {
|
|||||||
options = {
|
options = {
|
||||||
conditionals: true,
|
conditionals: true,
|
||||||
if_return: true,
|
if_return: true,
|
||||||
unsafe: true
|
unsafe_undefined: true,
|
||||||
}
|
}
|
||||||
mangle = {
|
mangle = {
|
||||||
keep_fnames: true
|
keep_fnames: true
|
||||||
|
|||||||
@@ -22,18 +22,17 @@ else_with_empty_statement: {
|
|||||||
|
|
||||||
conditional_false_stray_else_in_loop: {
|
conditional_false_stray_else_in_loop: {
|
||||||
options = {
|
options = {
|
||||||
evaluate : true,
|
booleans: true,
|
||||||
comparisons : true,
|
comparisons: true,
|
||||||
booleans : true,
|
conditionals: false,
|
||||||
unused : true,
|
dead_code: true,
|
||||||
loops : true,
|
evaluate: true,
|
||||||
side_effects : true,
|
hoist_vars: true,
|
||||||
dead_code : true,
|
if_return: true,
|
||||||
hoist_vars : true,
|
join_vars: true,
|
||||||
join_vars : true,
|
loops: true,
|
||||||
if_return : true,
|
side_effects: true,
|
||||||
cascade : true,
|
unused: true,
|
||||||
conditionals : false,
|
|
||||||
}
|
}
|
||||||
input: {
|
input: {
|
||||||
for (var i = 1; i <= 4; ++i) {
|
for (var i = 1; i <= 4; ++i) {
|
||||||
|
|||||||
@@ -1,291 +0,0 @@
|
|||||||
same_variable_in_multiple_for_loop: {
|
|
||||||
options = {
|
|
||||||
hoist_funs: true,
|
|
||||||
dead_code: true,
|
|
||||||
conditionals: true,
|
|
||||||
comparisons: true,
|
|
||||||
evaluate: true,
|
|
||||||
booleans: true,
|
|
||||||
loops: true,
|
|
||||||
unused: true,
|
|
||||||
keep_fargs: true,
|
|
||||||
if_return: true,
|
|
||||||
join_vars: true,
|
|
||||||
cascade: true,
|
|
||||||
side_effects: true,
|
|
||||||
collapse_vars: true,
|
|
||||||
}
|
|
||||||
mangle = {}
|
|
||||||
input: {
|
|
||||||
for (let i = 0; i < 3; i++) {
|
|
||||||
let a = 100;
|
|
||||||
console.log(i, a);
|
|
||||||
for (let i = 0; i < 2; i++) {
|
|
||||||
console.log(i, a);
|
|
||||||
let c = 2;
|
|
||||||
console.log(c);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
for (let o = 0; o < 3; o++) {
|
|
||||||
let l = 100;
|
|
||||||
console.log(o, l);
|
|
||||||
for (let o = 0; o < 2; o++) {
|
|
||||||
console.log(o, l);
|
|
||||||
let e = 2;
|
|
||||||
console.log(e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
expect_stdout: true
|
|
||||||
}
|
|
||||||
|
|
||||||
same_variable_in_multiple_forOf: {
|
|
||||||
options = {
|
|
||||||
hoist_funs: true,
|
|
||||||
dead_code: true,
|
|
||||||
conditionals: true,
|
|
||||||
comparisons: true,
|
|
||||||
evaluate: true,
|
|
||||||
booleans: true,
|
|
||||||
loops: true,
|
|
||||||
unused: true,
|
|
||||||
keep_fargs: true,
|
|
||||||
if_return: true,
|
|
||||||
join_vars: true,
|
|
||||||
cascade: true,
|
|
||||||
side_effects: true,
|
|
||||||
collapse_vars: true,
|
|
||||||
}
|
|
||||||
mangle = {}
|
|
||||||
input: {
|
|
||||||
var test = [ "a", "b", "c" ];
|
|
||||||
for (let tmp of test) {
|
|
||||||
console.log(tmp);
|
|
||||||
let dd;
|
|
||||||
dd = [ "e", "f", "g" ];
|
|
||||||
for (let tmp of dd) {
|
|
||||||
console.log(tmp);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
var test = [ "a", "b", "c" ];
|
|
||||||
for (let o of test) {
|
|
||||||
console.log(o);
|
|
||||||
let e;
|
|
||||||
e = [ "e", "f", "g" ];
|
|
||||||
for (let o of e)
|
|
||||||
console.log(o);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
expect_stdout: true
|
|
||||||
}
|
|
||||||
|
|
||||||
same_variable_in_multiple_forIn: {
|
|
||||||
options = {
|
|
||||||
hoist_funs: true,
|
|
||||||
dead_code: true,
|
|
||||||
conditionals: true,
|
|
||||||
comparisons: true,
|
|
||||||
evaluate: true,
|
|
||||||
booleans: true,
|
|
||||||
loops: true,
|
|
||||||
unused: false,
|
|
||||||
keep_fargs: true,
|
|
||||||
if_return: true,
|
|
||||||
join_vars: true,
|
|
||||||
cascade: true,
|
|
||||||
side_effects: true,
|
|
||||||
collapse_vars: true,
|
|
||||||
}
|
|
||||||
mangle = {}
|
|
||||||
input: {
|
|
||||||
var test = [ "a", "b", "c" ];
|
|
||||||
for (let tmp in test) {
|
|
||||||
console.log(tmp);
|
|
||||||
let dd;
|
|
||||||
dd = [ "e", "f", "g" ];
|
|
||||||
for (let tmp in test) {
|
|
||||||
console.log(tmp);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
var test = [ "a", "b", "c" ];
|
|
||||||
for (let e in test) {
|
|
||||||
console.log(e);
|
|
||||||
let t;
|
|
||||||
t = [ "e", "f", "g" ];
|
|
||||||
for (let e in test)
|
|
||||||
console.log(e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
expect_stdout: true
|
|
||||||
}
|
|
||||||
|
|
||||||
different_variable_in_multiple_for_loop: {
|
|
||||||
options = {
|
|
||||||
hoist_funs: true,
|
|
||||||
dead_code: true,
|
|
||||||
conditionals: true,
|
|
||||||
comparisons: true,
|
|
||||||
evaluate: true,
|
|
||||||
booleans: true,
|
|
||||||
loops: true,
|
|
||||||
unused: true,
|
|
||||||
keep_fargs: true,
|
|
||||||
if_return: true,
|
|
||||||
join_vars: true,
|
|
||||||
cascade: true,
|
|
||||||
side_effects: true,
|
|
||||||
collapse_vars: true,
|
|
||||||
}
|
|
||||||
mangle = {}
|
|
||||||
input: {
|
|
||||||
for (let i = 0; i < 3; i++) {
|
|
||||||
let a = 100;
|
|
||||||
console.log(i, a);
|
|
||||||
for (let j = 0; j < 2; j++) {
|
|
||||||
console.log(j, a);
|
|
||||||
let c = 2;
|
|
||||||
console.log(c);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
for (let o = 0; o < 3; o++) {
|
|
||||||
let l = 100;
|
|
||||||
console.log(o, l);
|
|
||||||
for (let o = 0; o < 2; o++) {
|
|
||||||
console.log(o, l);
|
|
||||||
let e = 2;
|
|
||||||
console.log(e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
expect_stdout: true
|
|
||||||
}
|
|
||||||
|
|
||||||
different_variable_in_multiple_forOf: {
|
|
||||||
options = {
|
|
||||||
hoist_funs: true,
|
|
||||||
dead_code: true,
|
|
||||||
conditionals: true,
|
|
||||||
comparisons: true,
|
|
||||||
evaluate: true,
|
|
||||||
booleans: true,
|
|
||||||
loops: true,
|
|
||||||
unused: true,
|
|
||||||
keep_fargs: true,
|
|
||||||
if_return: true,
|
|
||||||
join_vars: true,
|
|
||||||
cascade: true,
|
|
||||||
side_effects: true,
|
|
||||||
collapse_vars: true,
|
|
||||||
}
|
|
||||||
mangle = {}
|
|
||||||
input: {
|
|
||||||
var test = [ "a", "b", "c" ];
|
|
||||||
for (let tmp of test) {
|
|
||||||
console.log(tmp);
|
|
||||||
let dd;
|
|
||||||
dd = [ "e", "f", "g" ];
|
|
||||||
for (let t of dd) {
|
|
||||||
console.log(t);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
var test = [ "a", "b", "c" ];
|
|
||||||
for (let o of test) {
|
|
||||||
console.log(o);
|
|
||||||
let e;
|
|
||||||
e = [ "e", "f", "g" ];
|
|
||||||
for (let o of e)
|
|
||||||
console.log(o);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
expect_stdout: true
|
|
||||||
}
|
|
||||||
|
|
||||||
different_variable_in_multiple_forIn: {
|
|
||||||
options = {
|
|
||||||
hoist_funs: true,
|
|
||||||
dead_code: true,
|
|
||||||
conditionals: true,
|
|
||||||
comparisons: true,
|
|
||||||
evaluate: true,
|
|
||||||
booleans: true,
|
|
||||||
loops: true,
|
|
||||||
unused: false,
|
|
||||||
keep_fargs: true,
|
|
||||||
if_return: true,
|
|
||||||
join_vars: true,
|
|
||||||
cascade: true,
|
|
||||||
side_effects: true,
|
|
||||||
collapse_vars: true,
|
|
||||||
}
|
|
||||||
mangle = {}
|
|
||||||
input: {
|
|
||||||
var test = [ "a", "b", "c" ];
|
|
||||||
for (let tmp in test) {
|
|
||||||
console.log(tmp);
|
|
||||||
let dd;
|
|
||||||
dd = [ "e", "f", "g" ];
|
|
||||||
for (let t in test) {
|
|
||||||
console.log(t);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
var test = [ "a", "b", "c" ];
|
|
||||||
for (let e in test) {
|
|
||||||
console.log(e);
|
|
||||||
let t;
|
|
||||||
t = [ "e", "f", "g" ];
|
|
||||||
for (let e in test)
|
|
||||||
console.log(e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
expect_stdout: true
|
|
||||||
}
|
|
||||||
|
|
||||||
more_variable_in_multiple_for: {
|
|
||||||
options = {
|
|
||||||
hoist_funs: true,
|
|
||||||
dead_code: true,
|
|
||||||
conditionals: true,
|
|
||||||
comparisons: true,
|
|
||||||
evaluate: true,
|
|
||||||
booleans: true,
|
|
||||||
loops: true,
|
|
||||||
unused: false,
|
|
||||||
keep_fargs: true,
|
|
||||||
if_return: true,
|
|
||||||
join_vars: true,
|
|
||||||
cascade: true,
|
|
||||||
side_effects: true,
|
|
||||||
collapse_vars: true,
|
|
||||||
}
|
|
||||||
mangle = {}
|
|
||||||
input: {
|
|
||||||
for (let a = 9, i = 0; i < 20; i += a) {
|
|
||||||
let b = a++ + i;
|
|
||||||
console.log(a, b, i);
|
|
||||||
for (let k = b, m = b*b, i = 0; i < 10; i++) {
|
|
||||||
console.log(a, b, m, k, i);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
for (let o = 9, l = 0; l < 20; l += o) {
|
|
||||||
let e = o++ + l;
|
|
||||||
console.log(o, e, l);
|
|
||||||
for (let l = e, t = e * e, c = 0; c < 10; c++)
|
|
||||||
console.log(o, e, t, l, c);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
expect_stdout: true
|
|
||||||
}
|
|
||||||
@@ -61,7 +61,7 @@ unsafe_undefined: {
|
|||||||
options = {
|
options = {
|
||||||
conditionals: true,
|
conditionals: true,
|
||||||
if_return: true,
|
if_return: true,
|
||||||
unsafe: true,
|
unsafe_undefined: true,
|
||||||
}
|
}
|
||||||
mangle = {}
|
mangle = {}
|
||||||
input: {
|
input: {
|
||||||
@@ -85,15 +85,3 @@ unsafe_undefined: {
|
|||||||
}
|
}
|
||||||
expect_stdout: true
|
expect_stdout: true
|
||||||
}
|
}
|
||||||
|
|
||||||
runtime_error: {
|
|
||||||
input: {
|
|
||||||
const a = 1;
|
|
||||||
console.log(a++);
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
const a = 1;
|
|
||||||
console.log(a++);
|
|
||||||
}
|
|
||||||
expect_stdout: true
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -52,3 +52,30 @@ chained_evaluation_2: {
|
|||||||
})();
|
})();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
chained_evaluation_3: {
|
||||||
|
options = {
|
||||||
|
collapse_vars: true,
|
||||||
|
evaluate: 10,
|
||||||
|
reduce_funcs: true,
|
||||||
|
reduce_vars: true,
|
||||||
|
unused: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
(function() {
|
||||||
|
var a = "long piece of string";
|
||||||
|
(function() {
|
||||||
|
var b = a, c;
|
||||||
|
c = f(b);
|
||||||
|
c.bar = b;
|
||||||
|
})();
|
||||||
|
})();
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
(function() {
|
||||||
|
(function() {
|
||||||
|
f("long piece of string").bar = "long piece of string";
|
||||||
|
})();
|
||||||
|
})();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,8 +1,7 @@
|
|||||||
|
|
||||||
issue_1639_1: {
|
issue_1639_1: {
|
||||||
options = {
|
options = {
|
||||||
booleans: true,
|
booleans: true,
|
||||||
cascade: true,
|
collapse_vars: true,
|
||||||
conditionals: true,
|
conditionals: true,
|
||||||
evaluate: true,
|
evaluate: true,
|
||||||
join_vars: true,
|
join_vars: true,
|
||||||
@@ -12,7 +11,6 @@ issue_1639_1: {
|
|||||||
}
|
}
|
||||||
input: {
|
input: {
|
||||||
var a = 100, b = 10;
|
var a = 100, b = 10;
|
||||||
|
|
||||||
var L1 = 5;
|
var L1 = 5;
|
||||||
while (--L1 > 0) {
|
while (--L1 > 0) {
|
||||||
if ((--b), false) {
|
if ((--b), false) {
|
||||||
@@ -21,21 +19,21 @@ issue_1639_1: {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log(a, b);
|
console.log(a, b);
|
||||||
}
|
}
|
||||||
expect: {
|
expect: {
|
||||||
for (var a = 100, b = 10, L1 = 5; --L1 > 0;)
|
for (var a = 100, b = 10, L1 = 5, ignore; --L1 > 0;) {
|
||||||
if (--b, 0) var ignore = 0;
|
--b;
|
||||||
|
}
|
||||||
console.log(a, b);
|
console.log(a, b);
|
||||||
}
|
}
|
||||||
expect_stdout: true
|
expect_stdout: "100 6"
|
||||||
}
|
}
|
||||||
|
|
||||||
issue_1639_2: {
|
issue_1639_2: {
|
||||||
options = {
|
options = {
|
||||||
booleans: true,
|
booleans: true,
|
||||||
cascade: true,
|
collapse_vars: true,
|
||||||
conditionals: true,
|
conditionals: true,
|
||||||
evaluate: true,
|
evaluate: true,
|
||||||
join_vars: true,
|
join_vars: true,
|
||||||
@@ -44,31 +42,29 @@ issue_1639_2: {
|
|||||||
}
|
}
|
||||||
input: {
|
input: {
|
||||||
var a = 100, b = 10;
|
var a = 100, b = 10;
|
||||||
|
|
||||||
function f19() {
|
function f19() {
|
||||||
if (++a, false)
|
if (++a, false)
|
||||||
if (a)
|
if (a)
|
||||||
if (++a);
|
if (++a);
|
||||||
}
|
}
|
||||||
f19();
|
f19();
|
||||||
|
|
||||||
console.log(a, b);
|
console.log(a, b);
|
||||||
}
|
}
|
||||||
expect: {
|
expect: {
|
||||||
var a = 100, b = 10;
|
var a = 100, b = 10;
|
||||||
function f19() {
|
function f19() {
|
||||||
++a, 0;
|
++a, 1;
|
||||||
}
|
}
|
||||||
f19(),
|
f19(),
|
||||||
console.log(a, b);
|
console.log(a, b);
|
||||||
}
|
}
|
||||||
expect_stdout: true
|
expect_stdout: "101 10"
|
||||||
}
|
}
|
||||||
|
|
||||||
issue_1639_3: {
|
issue_1639_3: {
|
||||||
options = {
|
options = {
|
||||||
booleans: true,
|
booleans: true,
|
||||||
cascade: true,
|
collapse_vars: true,
|
||||||
conditionals: true,
|
conditionals: true,
|
||||||
evaluate: true,
|
evaluate: true,
|
||||||
sequences: true,
|
sequences: true,
|
||||||
@@ -84,5 +80,5 @@ issue_1639_3: {
|
|||||||
a++,
|
a++,
|
||||||
console.log(a, b);
|
console.log(a, b);
|
||||||
}
|
}
|
||||||
expect_stdout: true
|
expect_stdout: "101 10"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
f7: {
|
f7: {
|
||||||
options = {
|
options = {
|
||||||
booleans: true,
|
booleans: true,
|
||||||
cascade: true,
|
|
||||||
collapse_vars: true,
|
collapse_vars: true,
|
||||||
comparisons: true,
|
comparisons: true,
|
||||||
conditionals: true,
|
conditionals: true,
|
||||||
@@ -36,11 +35,7 @@ f7: {
|
|||||||
console.log(a, b);
|
console.log(a, b);
|
||||||
}
|
}
|
||||||
expect_exact: [
|
expect_exact: [
|
||||||
"var b = 10;",
|
"console.log(100, 100);",
|
||||||
"",
|
|
||||||
"!function() {",
|
|
||||||
" b = 100;",
|
|
||||||
"}(), console.log(100, b);",
|
|
||||||
]
|
]
|
||||||
expect_stdout: true
|
expect_stdout: "100 100"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -104,7 +104,7 @@ mangle_catch_toplevel: {
|
|||||||
}
|
}
|
||||||
console.log(a);
|
console.log(a);
|
||||||
}
|
}
|
||||||
expect_exact: 'var o="FAIL";try{throw 1}catch(c){o="PASS"}console.log(o);'
|
expect_exact: 'var c="FAIL";try{throw 1}catch(o){c="PASS"}console.log(c);'
|
||||||
expect_stdout: "PASS"
|
expect_stdout: "PASS"
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -148,7 +148,7 @@ mangle_catch_var_toplevel: {
|
|||||||
}
|
}
|
||||||
console.log(a);
|
console.log(a);
|
||||||
}
|
}
|
||||||
expect_exact: 'var o="FAIL";try{throw 1}catch(r){var o="PASS"}console.log(o);'
|
expect_exact: 'var r="FAIL";try{throw 1}catch(o){var r="PASS"}console.log(r);'
|
||||||
expect_stdout: "PASS"
|
expect_stdout: "PASS"
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -345,3 +345,95 @@ 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: true
|
||||||
|
}
|
||||||
|
|
||||||
|
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: true
|
||||||
|
}
|
||||||
|
|
||||||
|
mangle_catch_redef_3_ie8: {
|
||||||
|
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: true
|
||||||
|
}
|
||||||
|
|
||||||
|
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: true
|
||||||
|
}
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ function_iife_catch: {
|
|||||||
}
|
}
|
||||||
f();
|
f();
|
||||||
}
|
}
|
||||||
expect_exact: "function f(o){!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"
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -36,7 +36,7 @@ function_iife_catch_ie8: {
|
|||||||
}
|
}
|
||||||
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(c){!function(){try{throw 0}catch(c){var o=1;console.log(c,o)}}()}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(c){try{throw 2}catch(o){var o=3;console.log(o)}}console.log(o)}f();"
|
expect_exact: "var o=0;function f(){try{throw 1}catch(o){try{throw 2}catch(c){var c=3;console.log(c)}}console.log(c)}f();"
|
||||||
expect_stdout: [
|
expect_stdout: [
|
||||||
"3",
|
"3",
|
||||||
"undefined",
|
"undefined",
|
||||||
|
|||||||
@@ -46,7 +46,7 @@ mangle_props: {
|
|||||||
obj[1/0],
|
obj[1/0],
|
||||||
obj["Infinity"],
|
obj["Infinity"],
|
||||||
obj[-1/0],
|
obj[-1/0],
|
||||||
obj[-1/0],
|
obj[-(1/0)],
|
||||||
obj["-Infinity"],
|
obj["-Infinity"],
|
||||||
obj[null],
|
obj[null],
|
||||||
obj["null"]
|
obj["null"]
|
||||||
@@ -84,12 +84,12 @@ numeric_literal: {
|
|||||||
' 0: 0,',
|
' 0: 0,',
|
||||||
' "-0": 1,',
|
' "-0": 1,',
|
||||||
' 42: 2,',
|
' 42: 2,',
|
||||||
' "42": 3,',
|
' 42: 3,',
|
||||||
' 37: 4,',
|
' 37: 4,',
|
||||||
' o: 5,',
|
' o: 5,',
|
||||||
' 1e42: 6,',
|
' 1e42: 6,',
|
||||||
' b: 7,',
|
' b: 7,',
|
||||||
' "1e+42": 8',
|
' 1e42: 8',
|
||||||
'};',
|
'};',
|
||||||
'',
|
'',
|
||||||
'console.log(obj[-0], obj[-""], obj["-0"]);',
|
'console.log(obj[-0], obj[-""], obj["-0"]);',
|
||||||
@@ -107,3 +107,139 @@ numeric_literal: {
|
|||||||
"8 7 8",
|
"8 7 8",
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
identifier: {
|
||||||
|
mangle = {
|
||||||
|
properties: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
var obj = {
|
||||||
|
abstract: 1,
|
||||||
|
boolean: 2,
|
||||||
|
byte: 3,
|
||||||
|
char: 4,
|
||||||
|
class: 5,
|
||||||
|
double: 6,
|
||||||
|
enum: 7,
|
||||||
|
export: 8,
|
||||||
|
extends: 9,
|
||||||
|
final: 10,
|
||||||
|
float: 11,
|
||||||
|
goto: 12,
|
||||||
|
implements: 13,
|
||||||
|
import: 14,
|
||||||
|
int: 15,
|
||||||
|
interface: 16,
|
||||||
|
let: 17,
|
||||||
|
long: 18,
|
||||||
|
native: 19,
|
||||||
|
package: 20,
|
||||||
|
private: 21,
|
||||||
|
protected: 22,
|
||||||
|
public: 23,
|
||||||
|
short: 24,
|
||||||
|
static: 25,
|
||||||
|
super: 26,
|
||||||
|
synchronized: 27,
|
||||||
|
this: 28,
|
||||||
|
throws: 29,
|
||||||
|
transient: 30,
|
||||||
|
volatile: 31,
|
||||||
|
yield: 32,
|
||||||
|
false: 33,
|
||||||
|
null: 34,
|
||||||
|
true: 35,
|
||||||
|
break: 36,
|
||||||
|
case: 37,
|
||||||
|
catch: 38,
|
||||||
|
const: 39,
|
||||||
|
continue: 40,
|
||||||
|
debugger: 41,
|
||||||
|
default: 42,
|
||||||
|
delete: 43,
|
||||||
|
do: 44,
|
||||||
|
else: 45,
|
||||||
|
finally: 46,
|
||||||
|
for: 47,
|
||||||
|
function: 48,
|
||||||
|
if: 49,
|
||||||
|
in: 50,
|
||||||
|
instanceof: 51,
|
||||||
|
new: 52,
|
||||||
|
return: 53,
|
||||||
|
switch: 54,
|
||||||
|
throw: 55,
|
||||||
|
try: 56,
|
||||||
|
typeof: 57,
|
||||||
|
var: 58,
|
||||||
|
void: 59,
|
||||||
|
while: 60,
|
||||||
|
with: 61,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
var obj = {
|
||||||
|
e: 1,
|
||||||
|
t: 2,
|
||||||
|
n: 3,
|
||||||
|
a: 4,
|
||||||
|
i: 5,
|
||||||
|
o: 6,
|
||||||
|
r: 7,
|
||||||
|
l: 8,
|
||||||
|
s: 9,
|
||||||
|
c: 10,
|
||||||
|
f: 11,
|
||||||
|
u: 12,
|
||||||
|
d: 13,
|
||||||
|
h: 14,
|
||||||
|
p: 15,
|
||||||
|
b: 16,
|
||||||
|
v: 17,
|
||||||
|
w: 18,
|
||||||
|
y: 19,
|
||||||
|
g: 20,
|
||||||
|
m: 21,
|
||||||
|
k: 22,
|
||||||
|
x: 23,
|
||||||
|
j: 24,
|
||||||
|
z: 25,
|
||||||
|
q: 26,
|
||||||
|
A: 27,
|
||||||
|
B: 28,
|
||||||
|
C: 29,
|
||||||
|
D: 30,
|
||||||
|
F: 31,
|
||||||
|
G: 32,
|
||||||
|
false: 33,
|
||||||
|
null: 34,
|
||||||
|
true: 35,
|
||||||
|
H: 36,
|
||||||
|
I: 37,
|
||||||
|
J: 38,
|
||||||
|
K: 39,
|
||||||
|
L: 40,
|
||||||
|
M: 41,
|
||||||
|
N: 42,
|
||||||
|
O: 43,
|
||||||
|
P: 44,
|
||||||
|
Q: 45,
|
||||||
|
R: 46,
|
||||||
|
S: 47,
|
||||||
|
T: 48,
|
||||||
|
U: 49,
|
||||||
|
V: 50,
|
||||||
|
W: 51,
|
||||||
|
X: 52,
|
||||||
|
Y: 53,
|
||||||
|
Z: 54,
|
||||||
|
$: 55,
|
||||||
|
_: 56,
|
||||||
|
ee: 57,
|
||||||
|
te: 58,
|
||||||
|
ne: 59,
|
||||||
|
ae: 60,
|
||||||
|
ie: 61,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -125,8 +125,8 @@ label_do: {
|
|||||||
|
|
||||||
label_while: {
|
label_while: {
|
||||||
options = {
|
options = {
|
||||||
evaluate: true,
|
|
||||||
dead_code: true,
|
dead_code: true,
|
||||||
|
evaluate: true,
|
||||||
loops: true,
|
loops: true,
|
||||||
}
|
}
|
||||||
input: {
|
input: {
|
||||||
|
|||||||
@@ -1,283 +0,0 @@
|
|||||||
export_func_1: {
|
|
||||||
options = {
|
|
||||||
hoist_funs: true,
|
|
||||||
toplevel: true,
|
|
||||||
unused: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
export function f(){};
|
|
||||||
}
|
|
||||||
expect_exact: "export function f(){};"
|
|
||||||
}
|
|
||||||
|
|
||||||
export_func_2: {
|
|
||||||
options = {
|
|
||||||
hoist_funs: true,
|
|
||||||
side_effects: false,
|
|
||||||
toplevel: true,
|
|
||||||
unused: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
export function f(){}(1);
|
|
||||||
}
|
|
||||||
expect_exact: "export function f(){};1;"
|
|
||||||
}
|
|
||||||
|
|
||||||
export_func_3: {
|
|
||||||
options = {
|
|
||||||
hoist_funs: true,
|
|
||||||
side_effects: true,
|
|
||||||
toplevel: true,
|
|
||||||
unused: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
export function f(){}(1);
|
|
||||||
}
|
|
||||||
expect_exact: "export function f(){};"
|
|
||||||
}
|
|
||||||
|
|
||||||
export_default_func_1: {
|
|
||||||
options = {
|
|
||||||
hoist_funs: true,
|
|
||||||
toplevel: true,
|
|
||||||
unused: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
export default function f(){};
|
|
||||||
}
|
|
||||||
expect_exact: "export default function f(){};"
|
|
||||||
}
|
|
||||||
|
|
||||||
export_default_func_2: {
|
|
||||||
options = {
|
|
||||||
hoist_funs: true,
|
|
||||||
side_effects: false,
|
|
||||||
toplevel: true,
|
|
||||||
unused: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
export default function f(){}(1);
|
|
||||||
}
|
|
||||||
expect_exact: "export default function f(){};1;"
|
|
||||||
}
|
|
||||||
|
|
||||||
export_default_func_3: {
|
|
||||||
options = {
|
|
||||||
hoist_funs: true,
|
|
||||||
side_effects: true,
|
|
||||||
toplevel: true,
|
|
||||||
unused: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
export default function f(){}(1);
|
|
||||||
}
|
|
||||||
expect_exact: "export default function f(){};"
|
|
||||||
}
|
|
||||||
|
|
||||||
export_class_1: {
|
|
||||||
options = {
|
|
||||||
hoist_funs: true,
|
|
||||||
toplevel: true,
|
|
||||||
unused: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
export class C {};
|
|
||||||
}
|
|
||||||
expect_exact: "export class C{};"
|
|
||||||
}
|
|
||||||
|
|
||||||
export_class_2: {
|
|
||||||
options = {
|
|
||||||
hoist_funs: true,
|
|
||||||
side_effects: false,
|
|
||||||
toplevel: true,
|
|
||||||
unused: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
export class C {}(1);
|
|
||||||
}
|
|
||||||
expect_exact: "export class C{};1;"
|
|
||||||
}
|
|
||||||
|
|
||||||
export_class_3: {
|
|
||||||
options = {
|
|
||||||
hoist_funs: true,
|
|
||||||
side_effects: true,
|
|
||||||
toplevel: true,
|
|
||||||
unused: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
export class C {}(1);
|
|
||||||
}
|
|
||||||
expect_exact: "export class C{};"
|
|
||||||
}
|
|
||||||
|
|
||||||
export_default_class_1: {
|
|
||||||
options = {
|
|
||||||
hoist_funs: true,
|
|
||||||
toplevel: true,
|
|
||||||
unused: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
export default class C {};
|
|
||||||
}
|
|
||||||
expect_exact: "export default class C{};"
|
|
||||||
}
|
|
||||||
|
|
||||||
export_default_class_2: {
|
|
||||||
options = {
|
|
||||||
hoist_funs: true,
|
|
||||||
side_effects: false,
|
|
||||||
toplevel: true,
|
|
||||||
unused: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
export default class C {}(1);
|
|
||||||
}
|
|
||||||
expect_exact: "export default class C{};1;"
|
|
||||||
}
|
|
||||||
|
|
||||||
export_default_class_3: {
|
|
||||||
options = {
|
|
||||||
hoist_funs: true,
|
|
||||||
side_effects: true,
|
|
||||||
toplevel: true,
|
|
||||||
unused: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
export default class C {}(1);
|
|
||||||
}
|
|
||||||
expect_exact: "export default class C{};"
|
|
||||||
}
|
|
||||||
|
|
||||||
export_mangle_1: {
|
|
||||||
mangle = {
|
|
||||||
toplevel: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
export function foo(one, two) {
|
|
||||||
return one - two;
|
|
||||||
};
|
|
||||||
}
|
|
||||||
expect_exact: "export function foo(o,n){return o-n};"
|
|
||||||
}
|
|
||||||
|
|
||||||
export_mangle_2: {
|
|
||||||
mangle = {
|
|
||||||
toplevel: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
export default function foo(one, two) {
|
|
||||||
return one - two;
|
|
||||||
};
|
|
||||||
}
|
|
||||||
expect_exact: "export default function foo(o,t){return o-t};"
|
|
||||||
}
|
|
||||||
|
|
||||||
export_mangle_3: {
|
|
||||||
options = {
|
|
||||||
collapse_vars: true,
|
|
||||||
unused: true,
|
|
||||||
}
|
|
||||||
mangle = {
|
|
||||||
toplevel: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
export class C {
|
|
||||||
go(one, two) {
|
|
||||||
var z = one;
|
|
||||||
return one - two + z;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
expect_exact: "export class C{go(r,e){return r-e+r}};"
|
|
||||||
}
|
|
||||||
|
|
||||||
export_mangle_4: {
|
|
||||||
options = {
|
|
||||||
collapse_vars: true,
|
|
||||||
unused: true,
|
|
||||||
}
|
|
||||||
mangle = {
|
|
||||||
toplevel: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
export default class C {
|
|
||||||
go(one, two) {
|
|
||||||
var z = one;
|
|
||||||
return one - two + z;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
expect_exact: "export default class C{go(e,r){return e-r+e}};"
|
|
||||||
}
|
|
||||||
|
|
||||||
export_mangle_5: {
|
|
||||||
mangle = {
|
|
||||||
toplevel: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
export default {
|
|
||||||
prop: function(one, two) {
|
|
||||||
return one - two;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
expect_exact: "export default{prop:function(r,t){return r-t}};"
|
|
||||||
}
|
|
||||||
|
|
||||||
export_mangle_6: {
|
|
||||||
mangle = {
|
|
||||||
toplevel: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
var baz = 2;
|
|
||||||
export let foo = 1, bar = baz;
|
|
||||||
}
|
|
||||||
expect_exact: "var o=2;export let foo=1,bar=o;"
|
|
||||||
}
|
|
||||||
|
|
||||||
export_toplevel_1: {
|
|
||||||
options = {
|
|
||||||
toplevel: true,
|
|
||||||
unused: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
function f(){}
|
|
||||||
export function g(){};
|
|
||||||
export default function h(){};
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
export function g(){};
|
|
||||||
export default function h(){};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export_toplevel_2: {
|
|
||||||
options = {
|
|
||||||
toplevel: true,
|
|
||||||
unused: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
class A {}
|
|
||||||
export class B {};
|
|
||||||
export default class C {};
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
export class B {};
|
|
||||||
export default class C {};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export_default_func_ref: {
|
|
||||||
options = {
|
|
||||||
hoist_funs: true,
|
|
||||||
toplevel: true,
|
|
||||||
unused: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
export default function f(){};
|
|
||||||
f();
|
|
||||||
}
|
|
||||||
expect_exact: "export default function f(){};f();"
|
|
||||||
}
|
|
||||||
@@ -1,57 +0,0 @@
|
|||||||
|
|
||||||
compress_new_function: {
|
|
||||||
options = {
|
|
||||||
unsafe: true,
|
|
||||||
unsafe_Func: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
new Function("aa, bb", 'return aa;');
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
Function("n,r", "return n");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
compress_new_function_with_destruct: {
|
|
||||||
options = {
|
|
||||||
unsafe: true,
|
|
||||||
unsafe_Func: true,
|
|
||||||
ecma: 6
|
|
||||||
}
|
|
||||||
beautify = {
|
|
||||||
ecma: 6
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
new Function("aa, [bb]", 'return aa;');
|
|
||||||
new Function("aa, {bb}", 'return aa;');
|
|
||||||
new Function("[[aa]], [{bb}]", 'return aa;');
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
Function("n,[r]", "return n");
|
|
||||||
Function("n,{bb:b}", "return n");
|
|
||||||
Function("[[n]],[{bb:b}]", "return n");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
compress_new_function_with_destruct_arrows: {
|
|
||||||
options = {
|
|
||||||
arrows: true,
|
|
||||||
unsafe_arrows: true,
|
|
||||||
unsafe: true,
|
|
||||||
unsafe_Func: true,
|
|
||||||
ecma: 6,
|
|
||||||
}
|
|
||||||
beautify = {
|
|
||||||
ecma: 6
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
new Function("aa, [bb]", 'return aa;');
|
|
||||||
new Function("aa, {bb}", 'return aa;');
|
|
||||||
new Function("[[aa]], [{bb}]", 'return aa;');
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
Function("n,[a]", "return n");
|
|
||||||
Function("b,{bb:n}", "return b");
|
|
||||||
Function("[[b]],[{bb:n}]", "return b");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,6 +1,8 @@
|
|||||||
do_not_update_lhs: {
|
do_not_update_lhs: {
|
||||||
options = {
|
options = {
|
||||||
global_defs: { DEBUG: 0 }
|
global_defs: {
|
||||||
|
DEBUG: 0,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
input: {
|
input: {
|
||||||
DEBUG++;
|
DEBUG++;
|
||||||
@@ -16,7 +18,9 @@ do_not_update_lhs: {
|
|||||||
|
|
||||||
do_update_rhs: {
|
do_update_rhs: {
|
||||||
options = {
|
options = {
|
||||||
global_defs: { DEBUG: 0 }
|
global_defs: {
|
||||||
|
DEBUG: 0,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
input: {
|
input: {
|
||||||
MY_DEBUG = DEBUG;
|
MY_DEBUG = DEBUG;
|
||||||
@@ -35,10 +39,10 @@ mixed: {
|
|||||||
DEBUG: 0,
|
DEBUG: 0,
|
||||||
ENV: 1,
|
ENV: 1,
|
||||||
FOO: 2,
|
FOO: 2,
|
||||||
}
|
},
|
||||||
}
|
}
|
||||||
input: {
|
input: {
|
||||||
const ENV = 3;
|
var ENV = 3;
|
||||||
var FOO = 4;
|
var FOO = 4;
|
||||||
f(ENV * 10);
|
f(ENV * 10);
|
||||||
--FOO;
|
--FOO;
|
||||||
@@ -49,7 +53,7 @@ mixed: {
|
|||||||
x = DEBUG;
|
x = DEBUG;
|
||||||
}
|
}
|
||||||
expect: {
|
expect: {
|
||||||
const ENV = 3;
|
var ENV = 3;
|
||||||
var FOO = 4;
|
var FOO = 4;
|
||||||
f(10);
|
f(10);
|
||||||
--FOO;
|
--FOO;
|
||||||
@@ -60,11 +64,11 @@ mixed: {
|
|||||||
x = 0;
|
x = 0;
|
||||||
}
|
}
|
||||||
expect_warnings: [
|
expect_warnings: [
|
||||||
'WARN: global_defs ENV redefined [test/compress/issue-208.js:41,14]',
|
"WARN: global_defs ENV redefined [test/compress/issue-208.js:1,12]",
|
||||||
'WARN: global_defs FOO redefined [test/compress/issue-208.js:42,12]',
|
"WARN: global_defs FOO redefined [test/compress/issue-208.js:2,12]",
|
||||||
'WARN: global_defs FOO redefined [test/compress/issue-208.js:44,10]',
|
"WARN: global_defs FOO redefined [test/compress/issue-208.js:4,10]",
|
||||||
'WARN: global_defs DEBUG redefined [test/compress/issue-208.js:45,8]',
|
"WARN: global_defs DEBUG redefined [test/compress/issue-208.js:5,8]",
|
||||||
'WARN: global_defs DEBUG redefined [test/compress/issue-208.js:46,8]',
|
"WARN: global_defs DEBUG redefined [test/compress/issue-208.js:6,8]",
|
||||||
'WARN: global_defs DEBUG redefined [test/compress/issue-208.js:47,8]',
|
"WARN: global_defs DEBUG redefined [test/compress/issue-208.js:7,8]",
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
return_with_no_value_in_if_body: {
|
return_with_no_value_in_if_body: {
|
||||||
options = { conditionals: true };
|
options = {
|
||||||
|
conditionals: true,
|
||||||
|
}
|
||||||
input: {
|
input: {
|
||||||
function foo(bar) {
|
function foo(bar) {
|
||||||
if (bar) {
|
if (bar) {
|
||||||
|
|||||||
33
test/compress/issue-2652.js
Normal file
33
test/compress/issue-2652.js
Normal file
@@ -0,0 +1,33 @@
|
|||||||
|
insert_semicolon: {
|
||||||
|
beautify = {
|
||||||
|
beautify: true,
|
||||||
|
comments: "all",
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
var a
|
||||||
|
/* foo */ var b
|
||||||
|
}
|
||||||
|
expect_exact: [
|
||||||
|
"var a",
|
||||||
|
"/* foo */;",
|
||||||
|
"",
|
||||||
|
"var b;",
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
|
unary_postfix: {
|
||||||
|
beautify = {
|
||||||
|
beautify: true,
|
||||||
|
comments: "all",
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
a
|
||||||
|
/* foo */++b
|
||||||
|
}
|
||||||
|
expect_exact: [
|
||||||
|
"a",
|
||||||
|
"/* foo */;",
|
||||||
|
"",
|
||||||
|
"++b;",
|
||||||
|
]
|
||||||
|
}
|
||||||
@@ -1,5 +1,7 @@
|
|||||||
issue_267: {
|
issue_267: {
|
||||||
options = { comparisons: true };
|
options = {
|
||||||
|
comparisons: true,
|
||||||
|
}
|
||||||
input: {
|
input: {
|
||||||
x = a % b / b * c * 2;
|
x = a % b / b * c * 2;
|
||||||
x = a % b * 2
|
x = a % b * 2
|
||||||
|
|||||||
@@ -1,66 +1,111 @@
|
|||||||
issue_269_1: {
|
issue_269_1: {
|
||||||
options = {unsafe: true};
|
options = {
|
||||||
input: {
|
unsafe: true,
|
||||||
f(
|
}
|
||||||
String(x),
|
input: {
|
||||||
Number(x),
|
var x = {};
|
||||||
Boolean(x),
|
console.log(
|
||||||
|
String(x),
|
||||||
|
Number(x),
|
||||||
|
Boolean(x),
|
||||||
|
|
||||||
String(),
|
String(),
|
||||||
Number(),
|
Number(),
|
||||||
Boolean()
|
Boolean()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
expect: {
|
expect: {
|
||||||
f(
|
var x = {};
|
||||||
x + '', +x, !!x,
|
console.log(
|
||||||
'', 0, false
|
x + "", +x, !!x,
|
||||||
);
|
"", 0, false
|
||||||
}
|
);
|
||||||
|
}
|
||||||
|
expect_stdout: true
|
||||||
}
|
}
|
||||||
|
|
||||||
issue_269_dangers: {
|
issue_269_dangers: {
|
||||||
options = {unsafe: true};
|
options = {
|
||||||
input: {
|
unsafe: true,
|
||||||
f(
|
}
|
||||||
String(x, x),
|
input: {
|
||||||
Number(x, x),
|
var x = {};
|
||||||
Boolean(x, x)
|
console.log(
|
||||||
);
|
String(x, x),
|
||||||
}
|
Number(x, x),
|
||||||
expect: {
|
Boolean(x, x)
|
||||||
f(String(x, x), Number(x, x), Boolean(x, x));
|
);
|
||||||
}
|
}
|
||||||
|
expect: {
|
||||||
|
var x = {};
|
||||||
|
console.log(String(x, x), Number(x, x), Boolean(x, x));
|
||||||
|
}
|
||||||
|
expect_stdout: true
|
||||||
}
|
}
|
||||||
|
|
||||||
issue_269_in_scope: {
|
issue_269_in_scope: {
|
||||||
options = {unsafe: true};
|
options = {
|
||||||
input: {
|
unsafe: true,
|
||||||
var String, Number, Boolean;
|
}
|
||||||
f(
|
input: {
|
||||||
String(x),
|
var String, Number, Boolean;
|
||||||
Number(x, x),
|
var x = {};
|
||||||
Boolean(x)
|
console.log(
|
||||||
);
|
String(x),
|
||||||
}
|
Number(x, x),
|
||||||
expect: {
|
Boolean(x)
|
||||||
var String, Number, Boolean;
|
);
|
||||||
f(String(x), Number(x, x), Boolean(x));
|
}
|
||||||
}
|
expect: {
|
||||||
|
var String, Number, Boolean;
|
||||||
|
var x = {};
|
||||||
|
console.log(String(x), Number(x, x), Boolean(x));
|
||||||
|
}
|
||||||
|
expect_stdout: true
|
||||||
}
|
}
|
||||||
|
|
||||||
strings_concat: {
|
strings_concat: {
|
||||||
options = {unsafe: true};
|
options = {
|
||||||
input: {
|
strings: true,
|
||||||
f(
|
unsafe: true,
|
||||||
String(x + 'str'),
|
}
|
||||||
String('str' + x)
|
input: {
|
||||||
);
|
var x = {};
|
||||||
}
|
console.log(
|
||||||
expect: {
|
String(x + "str"),
|
||||||
f(
|
String("str" + x)
|
||||||
x + 'str',
|
);
|
||||||
'str' + x
|
}
|
||||||
);
|
expect: {
|
||||||
}
|
var x = {};
|
||||||
|
console.log(
|
||||||
|
x + "str",
|
||||||
|
"str" + x
|
||||||
|
);
|
||||||
|
}
|
||||||
|
expect_stdout: true
|
||||||
|
}
|
||||||
|
|
||||||
|
regexp: {
|
||||||
|
options = {
|
||||||
|
evaluate: true,
|
||||||
|
unsafe: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
RegExp("foo");
|
||||||
|
RegExp("bar", "ig");
|
||||||
|
RegExp(foo);
|
||||||
|
RegExp("bar", ig);
|
||||||
|
RegExp("should", "fail");
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
/foo/;
|
||||||
|
/bar/ig;
|
||||||
|
RegExp(foo);
|
||||||
|
RegExp("bar", ig);
|
||||||
|
RegExp("should", "fail");
|
||||||
|
}
|
||||||
|
expect_warnings: [
|
||||||
|
'WARN: Error converting RegExp("should","fail") [test/compress/issue-269.js:5,8]',
|
||||||
|
]
|
||||||
}
|
}
|
||||||
|
|||||||
32
test/compress/issue-2719.js
Normal file
32
test/compress/issue-2719.js
Normal file
@@ -0,0 +1,32 @@
|
|||||||
|
warn: {
|
||||||
|
options = {
|
||||||
|
evaluate: true,
|
||||||
|
inline: true,
|
||||||
|
passes: 2,
|
||||||
|
properties: true,
|
||||||
|
reduce_funcs: true,
|
||||||
|
reduce_vars: true,
|
||||||
|
toplevel: true,
|
||||||
|
unused: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
function f() {
|
||||||
|
return g();
|
||||||
|
}
|
||||||
|
function g() {
|
||||||
|
return g["call" + "er"].arguments;
|
||||||
|
}
|
||||||
|
// 3
|
||||||
|
console.log(f(1, 2, 3).length);
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
// TypeError: Cannot read property 'arguments' of null
|
||||||
|
console.log(function g() {
|
||||||
|
return g.caller.arguments;
|
||||||
|
}().length);
|
||||||
|
}
|
||||||
|
expect_warnings: [
|
||||||
|
"WARN: Function.prototype.arguments not supported [test/compress/issue-2719.js:5,19]",
|
||||||
|
"WARN: Function.prototype.caller not supported [test/compress/issue-2719.js:5,19]",
|
||||||
|
]
|
||||||
|
}
|
||||||
@@ -186,7 +186,7 @@ negate_iife_5_off: {
|
|||||||
inline: true,
|
inline: true,
|
||||||
negate_iife: false,
|
negate_iife: false,
|
||||||
sequences: true,
|
sequences: true,
|
||||||
};
|
}
|
||||||
input: {
|
input: {
|
||||||
if ((function(){ return t })()) {
|
if ((function(){ return t })()) {
|
||||||
foo(true);
|
foo(true);
|
||||||
@@ -245,7 +245,7 @@ negate_iife_issue_1073: {
|
|||||||
reduce_vars: true,
|
reduce_vars: true,
|
||||||
sequences: true,
|
sequences: true,
|
||||||
unused: true,
|
unused: true,
|
||||||
};
|
}
|
||||||
input: {
|
input: {
|
||||||
new (function(a) {
|
new (function(a) {
|
||||||
return function Foo() {
|
return function Foo() {
|
||||||
@@ -273,7 +273,7 @@ issue_1288_side_effects: {
|
|||||||
reduce_vars: true,
|
reduce_vars: true,
|
||||||
side_effects: true,
|
side_effects: true,
|
||||||
unused: true,
|
unused: true,
|
||||||
};
|
}
|
||||||
input: {
|
input: {
|
||||||
if (w) ;
|
if (w) ;
|
||||||
else {
|
else {
|
||||||
@@ -399,7 +399,7 @@ wrap_iife_in_expression: {
|
|||||||
wrap_iife: true,
|
wrap_iife: true,
|
||||||
}
|
}
|
||||||
input: {
|
input: {
|
||||||
foo = (function () {
|
foo = (function() {
|
||||||
return bar();
|
return bar();
|
||||||
})();
|
})();
|
||||||
}
|
}
|
||||||
@@ -453,7 +453,7 @@ pure_annotation_2: {
|
|||||||
|
|
||||||
drop_fargs: {
|
drop_fargs: {
|
||||||
options = {
|
options = {
|
||||||
cascade: true,
|
collapse_vars: true,
|
||||||
inline: true,
|
inline: true,
|
||||||
keep_fargs: false,
|
keep_fargs: false,
|
||||||
side_effects: true,
|
side_effects: true,
|
||||||
@@ -476,7 +476,7 @@ drop_fargs: {
|
|||||||
|
|
||||||
keep_fargs: {
|
keep_fargs: {
|
||||||
options = {
|
options = {
|
||||||
cascade: true,
|
collapse_vars: true,
|
||||||
inline: true,
|
inline: true,
|
||||||
keep_fargs: true,
|
keep_fargs: true,
|
||||||
side_effects: true,
|
side_effects: true,
|
||||||
|
|||||||
37
test/compress/issue-2871.js
Normal file
37
test/compress/issue-2871.js
Normal file
@@ -0,0 +1,37 @@
|
|||||||
|
comparison_with_undefined: {
|
||||||
|
options = {
|
||||||
|
comparisons: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
a == undefined;
|
||||||
|
a != undefined;
|
||||||
|
a === undefined;
|
||||||
|
a !== undefined;
|
||||||
|
|
||||||
|
undefined == a;
|
||||||
|
undefined != a;
|
||||||
|
undefined === a;
|
||||||
|
undefined !== a;
|
||||||
|
|
||||||
|
void 0 == a;
|
||||||
|
void 0 != a;
|
||||||
|
void 0 === a;
|
||||||
|
void 0 !== a;
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
null == a;
|
||||||
|
null != a;
|
||||||
|
void 0 === a;
|
||||||
|
void 0 !== a;
|
||||||
|
|
||||||
|
null == a;
|
||||||
|
null != a;
|
||||||
|
void 0 === a;
|
||||||
|
void 0 !== a;
|
||||||
|
|
||||||
|
null == a;
|
||||||
|
null != a;
|
||||||
|
void 0 === a;
|
||||||
|
void 0 !== a;
|
||||||
|
}
|
||||||
|
}
|
||||||
21
test/compress/issue-2989.js
Normal file
21
test/compress/issue-2989.js
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
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,6 +1,6 @@
|
|||||||
collapse: {
|
collapse: {
|
||||||
options = {
|
options = {
|
||||||
cascade: true,
|
collapse_vars: true,
|
||||||
sequences: true,
|
sequences: true,
|
||||||
side_effects: true,
|
side_effects: true,
|
||||||
unused: true,
|
unused: true,
|
||||||
@@ -41,7 +41,7 @@ collapse: {
|
|||||||
return void 0 !== ('function' === typeof b ? b() : b) && c();
|
return void 0 !== ('function' === typeof b ? b() : b) && c();
|
||||||
}
|
}
|
||||||
function f2(b) {
|
function f2(b) {
|
||||||
return b = c(), 'stirng' == typeof ('function' === typeof b ? b() : b) && d();
|
return 'stirng' == typeof ('function' === typeof (b = c()) ? b() : b) && d();
|
||||||
}
|
}
|
||||||
function f3(c) {
|
function f3(c) {
|
||||||
var a;
|
var a;
|
||||||
|
|||||||
128
test/compress/issue-3768.js
Normal file
128
test/compress/issue-3768.js
Normal file
@@ -0,0 +1,128 @@
|
|||||||
|
mangle: {
|
||||||
|
mangle = {
|
||||||
|
toplevel: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
var e = eval, x = 42;
|
||||||
|
(function() {
|
||||||
|
console.log(e("typeof x"));
|
||||||
|
})();
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
var e = eval, x = 42;
|
||||||
|
(function() {
|
||||||
|
console.log(e("typeof x"));
|
||||||
|
})();
|
||||||
|
}
|
||||||
|
expect_stdout: true
|
||||||
|
}
|
||||||
|
|
||||||
|
compress: {
|
||||||
|
options = {
|
||||||
|
collapse_vars: true,
|
||||||
|
inline: true,
|
||||||
|
unused: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
console.log(function() {
|
||||||
|
var a = 42;
|
||||||
|
return eval("typeof a");
|
||||||
|
}(), function(e) {
|
||||||
|
var a = null;
|
||||||
|
return e("typeof a");
|
||||||
|
}(eval), function(eval) {
|
||||||
|
var a = false;
|
||||||
|
return eval("typeof a");
|
||||||
|
}(eval), function(f) {
|
||||||
|
var a = "STRING";
|
||||||
|
var eval = f;
|
||||||
|
return eval("typeof a");
|
||||||
|
}(eval), function(g) {
|
||||||
|
var a = eval;
|
||||||
|
function eval() {
|
||||||
|
return g;
|
||||||
|
}
|
||||||
|
return eval()("typeof a");
|
||||||
|
}(eval));
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
console.log(function() {
|
||||||
|
var a = 42;
|
||||||
|
return eval("typeof a");
|
||||||
|
}(), (0, eval)("typeof a"), function(eval) {
|
||||||
|
var a = false;
|
||||||
|
return eval("typeof a");
|
||||||
|
}(eval), function(f) {
|
||||||
|
var a = "STRING";
|
||||||
|
var eval = f;
|
||||||
|
return eval("typeof a");
|
||||||
|
}(eval), function(g) {
|
||||||
|
var a = eval;
|
||||||
|
function eval() {
|
||||||
|
return g;
|
||||||
|
}
|
||||||
|
return eval()("typeof a");
|
||||||
|
}(eval));
|
||||||
|
}
|
||||||
|
expect_stdout: "number undefined boolean string undefined"
|
||||||
|
}
|
||||||
|
|
||||||
|
call_arg_1: {
|
||||||
|
mangle = {
|
||||||
|
toplevel: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
var z = "foo";
|
||||||
|
(function() {
|
||||||
|
var z = false;
|
||||||
|
(function(e) {
|
||||||
|
var z = 42;
|
||||||
|
e("console.log(typeof z)");
|
||||||
|
})(eval);
|
||||||
|
})();
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
var z = "foo";
|
||||||
|
(function() {
|
||||||
|
var o = false;
|
||||||
|
(function(o) {
|
||||||
|
var a = 42;
|
||||||
|
o("console.log(typeof z)");
|
||||||
|
})(eval);
|
||||||
|
})();
|
||||||
|
}
|
||||||
|
expect_stdout: true
|
||||||
|
}
|
||||||
|
|
||||||
|
call_arg_2: {
|
||||||
|
mangle = {
|
||||||
|
toplevel: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
function eval() {
|
||||||
|
console.log("PASS");
|
||||||
|
}
|
||||||
|
var z = "foo";
|
||||||
|
(function() {
|
||||||
|
var z = false;
|
||||||
|
(function(e) {
|
||||||
|
var z = 42;
|
||||||
|
e("console.log(typeof z)");
|
||||||
|
})(eval);
|
||||||
|
})();
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
function n() {
|
||||||
|
console.log("PASS");
|
||||||
|
}
|
||||||
|
var o = "foo";
|
||||||
|
(function() {
|
||||||
|
var o = false;
|
||||||
|
(function(o) {
|
||||||
|
var n = 42;
|
||||||
|
o("console.log(typeof z)");
|
||||||
|
})(n);
|
||||||
|
})();
|
||||||
|
}
|
||||||
|
expect_stdout: "PASS"
|
||||||
|
}
|
||||||
@@ -1,5 +1,7 @@
|
|||||||
issue_44_valid_ast_1: {
|
issue_44_valid_ast_1: {
|
||||||
options = { unused: true };
|
options = {
|
||||||
|
unused: true,
|
||||||
|
}
|
||||||
input: {
|
input: {
|
||||||
function a(b) {
|
function a(b) {
|
||||||
for (var i = 0, e = b.qoo(); ; i++) {}
|
for (var i = 0, e = b.qoo(); ; i++) {}
|
||||||
@@ -14,7 +16,9 @@ issue_44_valid_ast_1: {
|
|||||||
}
|
}
|
||||||
|
|
||||||
issue_44_valid_ast_2: {
|
issue_44_valid_ast_2: {
|
||||||
options = { unused: true };
|
options = {
|
||||||
|
unused: true,
|
||||||
|
}
|
||||||
input: {
|
input: {
|
||||||
function a(b) {
|
function a(b) {
|
||||||
if (foo) for (var i = 0, e = b.qoo(); ; i++) {}
|
if (foo) for (var i = 0, e = b.qoo(); ; i++) {}
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
keep_continue: {
|
keep_continue: {
|
||||||
options = {
|
options = {
|
||||||
dead_code: true,
|
dead_code: true,
|
||||||
evaluate: true
|
evaluate: true,
|
||||||
};
|
}
|
||||||
input: {
|
input: {
|
||||||
while (a) {
|
while (a) {
|
||||||
if (b) {
|
if (b) {
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
NaN_and_Infinity_must_have_parens: {
|
NaN_and_Infinity_must_have_parens: {
|
||||||
options = {};
|
options = {}
|
||||||
input: {
|
input: {
|
||||||
Infinity.toString();
|
Infinity.toString();
|
||||||
NaN.toString();
|
NaN.toString();
|
||||||
@@ -11,7 +11,7 @@ NaN_and_Infinity_must_have_parens: {
|
|||||||
}
|
}
|
||||||
|
|
||||||
NaN_and_Infinity_should_not_be_replaced_when_they_are_redefined: {
|
NaN_and_Infinity_should_not_be_replaced_when_they_are_redefined: {
|
||||||
options = {};
|
options = {}
|
||||||
input: {
|
input: {
|
||||||
var Infinity, NaN;
|
var Infinity, NaN;
|
||||||
Infinity.toString();
|
Infinity.toString();
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
issue_611: {
|
issue_611: {
|
||||||
options = {
|
options = {
|
||||||
sequences: true,
|
sequences: true,
|
||||||
side_effects: true
|
side_effects: true,
|
||||||
};
|
}
|
||||||
input: {
|
input: {
|
||||||
define(function() {
|
define(function() {
|
||||||
function fn() {}
|
function fn() {}
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
wrongly_optimized: {
|
wrongly_optimized: {
|
||||||
options = {
|
options = {
|
||||||
conditionals: true,
|
|
||||||
booleans: true,
|
booleans: true,
|
||||||
evaluate: true
|
conditionals: true,
|
||||||
};
|
evaluate: true,
|
||||||
|
}
|
||||||
input: {
|
input: {
|
||||||
function func() {
|
function func() {
|
||||||
foo();
|
foo();
|
||||||
@@ -16,7 +16,6 @@ wrongly_optimized: {
|
|||||||
function func() {
|
function func() {
|
||||||
foo();
|
foo();
|
||||||
}
|
}
|
||||||
// TODO: optimize to `func(), bar()`
|
func(), 1, bar();
|
||||||
(func(), 1) && bar();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,19 +21,19 @@ cond_5: {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
expect: {
|
expect: {
|
||||||
some_condition() && some_other_condition() ? do_something() : alternate();
|
(some_condition() && some_other_condition() ? do_something : alternate)();
|
||||||
if (some_condition() && some_other_condition()) do_something();
|
if (some_condition() && some_other_condition()) do_something();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
dead_code_const_annotation_regex: {
|
dead_code_const_annotation_regex: {
|
||||||
options = {
|
options = {
|
||||||
booleans : true,
|
booleans: true,
|
||||||
conditionals : true,
|
conditionals: true,
|
||||||
dead_code : true,
|
dead_code: true,
|
||||||
evaluate : true,
|
evaluate: true,
|
||||||
expression : true,
|
expression: true,
|
||||||
loops : true,
|
loops: true,
|
||||||
}
|
}
|
||||||
input: {
|
input: {
|
||||||
var unused;
|
var unused;
|
||||||
@@ -82,8 +82,9 @@ drop_value: {
|
|||||||
|
|
||||||
wrongly_optimized: {
|
wrongly_optimized: {
|
||||||
options = {
|
options = {
|
||||||
conditionals: true,
|
|
||||||
booleans: true,
|
booleans: true,
|
||||||
|
conditionals: true,
|
||||||
|
dead_code: true,
|
||||||
evaluate: true,
|
evaluate: true,
|
||||||
expression: true,
|
expression: true,
|
||||||
}
|
}
|
||||||
@@ -99,8 +100,8 @@ wrongly_optimized: {
|
|||||||
function func() {
|
function func() {
|
||||||
foo();
|
foo();
|
||||||
}
|
}
|
||||||
// TODO: optimize to `func(), bar()`
|
func(), 1;
|
||||||
if (func(), 1) bar();
|
bar();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -195,7 +196,7 @@ negate_iife_5_off: {
|
|||||||
expression: true,
|
expression: true,
|
||||||
negate_iife: false,
|
negate_iife: false,
|
||||||
sequences: true,
|
sequences: true,
|
||||||
};
|
}
|
||||||
input: {
|
input: {
|
||||||
if ((function(){ return t })()) {
|
if ((function(){ return t })()) {
|
||||||
foo(true);
|
foo(true);
|
||||||
@@ -248,7 +249,9 @@ issue_1254_negate_iife_nested: {
|
|||||||
conditional: {
|
conditional: {
|
||||||
options = {
|
options = {
|
||||||
expression: true,
|
expression: true,
|
||||||
pure_funcs: [ "pure" ],
|
pure_funcs: [
|
||||||
|
"pure"
|
||||||
|
],
|
||||||
side_effects: true,
|
side_effects: true,
|
||||||
}
|
}
|
||||||
input: {
|
input: {
|
||||||
|
|||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user