Compare commits
1079 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
36423f2e78 | ||
|
|
06eaba5ad1 | ||
|
|
7e8cd2ca8a | ||
|
|
2541dcf960 | ||
|
|
5d45e1475c | ||
|
|
9964de9b2f | ||
|
|
5b75b11628 | ||
|
|
1890fb5bd3 | ||
|
|
df20b3df5a | ||
|
|
56e74dfd10 | ||
|
|
513d05143a | ||
|
|
84068943dd | ||
|
|
d3c75378ec | ||
|
|
ffe058bf69 | ||
|
|
765d95cd6f | ||
|
|
33e82222ca | ||
|
|
82d1c29696 | ||
|
|
211c9802a5 | ||
|
|
f5a81e71bd | ||
|
|
4ea7a864fa | ||
|
|
d645659770 | ||
|
|
75ec9c8f2c | ||
|
|
3bffdc2be0 | ||
|
|
820db09613 | ||
|
|
f24ae6feab | ||
|
|
5b09114b85 | ||
|
|
28c948e5ea | ||
|
|
bbf5a8f4aa | ||
|
|
5f2865883b | ||
|
|
c8433f950d | ||
|
|
9135e700c6 | ||
|
|
eb17568c94 | ||
|
|
407ff1e4a0 | ||
|
|
fbaaf63c49 | ||
|
|
f93daa3ca5 | ||
|
|
7fc1d04f9b | ||
|
|
d6a34f02ca | ||
|
|
fc3cb099c5 | ||
|
|
fc663d54fa | ||
|
|
bf2418db66 | ||
|
|
5bd75db0b6 | ||
|
|
13b3335a67 | ||
|
|
4987f9e668 | ||
|
|
e585aa6bed | ||
|
|
d6c7be760b | ||
|
|
a19321ea69 | ||
|
|
73fc1ac64e | ||
|
|
1d14764471 | ||
|
|
e336ecd9cc | ||
|
|
5737a96f9f | ||
|
|
d7d4ec54cd | ||
|
|
98056e26af | ||
|
|
afd07c9172 | ||
|
|
af785126bf | ||
|
|
39c5849604 | ||
|
|
1b6e465317 | ||
|
|
15dff73cc8 | ||
|
|
186a15b3ce | ||
|
|
610e52d767 | ||
|
|
b0467fcb6d | ||
|
|
05be131647 | ||
|
|
f2300a5463 | ||
|
|
86acc99fb3 | ||
|
|
21909cee76 | ||
|
|
c97b53b52d | ||
|
|
c5e01146fd | ||
|
|
010ff3ec31 | ||
|
|
17532bfd82 | ||
|
|
545e9499c3 | ||
|
|
02046c5448 | ||
|
|
1d34d03ac8 | ||
|
|
e05aed0394 | ||
|
|
2d3b595a8b | ||
|
|
8f0b7683a1 | ||
|
|
f0d2cbb055 | ||
|
|
602c5e0ca0 | ||
|
|
2a2dff0eaf | ||
|
|
e1151e08c9 | ||
|
|
84f54ca3c7 | ||
|
|
5fb793b75f | ||
|
|
1adc9bfc70 | ||
|
|
3649fad485 | ||
|
|
0e1743738e | ||
|
|
6ad16302cd | ||
|
|
4b6b7af332 | ||
|
|
55dfb423ee | ||
|
|
9d1bc4817d | ||
|
|
fc8666e7a4 | ||
|
|
07b6881d67 | ||
|
|
1f208a06db | ||
|
|
b5c9c84542 | ||
|
|
492555bb4e | ||
|
|
53d88c0f63 | ||
|
|
8a5da57162 | ||
|
|
1627e2f47e | ||
|
|
e195d6ca55 | ||
|
|
71d5d4fb2c | ||
|
|
dfe13cda0d | ||
|
|
a4c6660d21 | ||
|
|
9676666e7c | ||
|
|
388133642d | ||
|
|
23b5eeb72f | ||
|
|
db36c3a7c2 | ||
|
|
e841b88cbc | ||
|
|
3d874f2479 | ||
|
|
228719102a | ||
|
|
c6ce1a248c | ||
|
|
ba9b85f64b | ||
|
|
56c868efee | ||
|
|
1f3c3832ba | ||
|
|
3b04a8c648 | ||
|
|
2270057b54 | ||
|
|
c3206aa9a4 | ||
|
|
1912d1b26a | ||
|
|
9208e7e594 | ||
|
|
ce332b3384 | ||
|
|
a567531f77 | ||
|
|
9cce72def0 | ||
|
|
2d8581c6dc | ||
|
|
14a000396a | ||
|
|
4c41f5a22f | ||
|
|
6be2a6e02a | ||
|
|
0a4fc16ca0 | ||
|
|
25d8377411 | ||
|
|
14267a788d | ||
|
|
ba5c5760b1 | ||
|
|
49904b3ab3 | ||
|
|
a212f035e4 | ||
|
|
ea471a6a17 | ||
|
|
f5bae0b696 | ||
|
|
9ec9e13aeb | ||
|
|
0b042b2681 | ||
|
|
83b4d12884 | ||
|
|
98d555498d | ||
|
|
fdc05cb977 | ||
|
|
928ebda5bc | ||
|
|
0a2003af66 | ||
|
|
02392635ef | ||
|
|
298cfac7f4 | ||
|
|
476b683f0f | ||
|
|
5c5b66df54 | ||
|
|
e7f6572a3b | ||
|
|
e9cfd2df3e | ||
|
|
a425136680 | ||
|
|
8d06a4301c | ||
|
|
1909a16dc7 | ||
|
|
3bfa1f610c | ||
|
|
4faf2b7730 | ||
|
|
4e5d6ee976 | ||
|
|
afb1ee79a1 | ||
|
|
efe3f30741 | ||
|
|
5ff0285ba7 | ||
|
|
d7bea2f325 | ||
|
|
32316ad942 | ||
|
|
7953eb560e | ||
|
|
faa10df84c | ||
|
|
ae344aa23e | ||
|
|
e0bfc72700 | ||
|
|
bf8f80faf7 | ||
|
|
77fa8bf01c | ||
|
|
34ca1ac04f | ||
|
|
85d33536e0 | ||
|
|
a4932e0e0f | ||
|
|
4ebd0a1e8a | ||
|
|
14e92e9e3f | ||
|
|
13687d98ed | ||
|
|
db93c52182 | ||
|
|
56a953df64 | ||
|
|
c38edbbb42 | ||
|
|
017bb6427a | ||
|
|
714ad40cb0 | ||
|
|
904a72fb3a | ||
|
|
146835e0f1 | ||
|
|
79ba97872c | ||
|
|
897566ccb3 | ||
|
|
4df1b6700b | ||
|
|
50f903caf7 | ||
|
|
7b8118d8bd | ||
|
|
0c1e1e757c | ||
|
|
62fa583fc1 | ||
|
|
8598000a69 | ||
|
|
edc8bee38e | ||
|
|
45b70d7fba | ||
|
|
49a53b26bb | ||
|
|
329b4e9d21 | ||
|
|
f1bca0013e | ||
|
|
87af83f1cb | ||
|
|
5156574bf2 | ||
|
|
ac098255be | ||
|
|
47b803ef24 | ||
|
|
7f61c8b65e | ||
|
|
4fa9aa63a3 | ||
|
|
d582c7c93a | ||
|
|
6266f5b924 | ||
|
|
c6920a0e60 | ||
|
|
825d84ba52 | ||
|
|
94a0eb5b06 | ||
|
|
b6d708caf2 | ||
|
|
0d542b61d3 | ||
|
|
5a842ab623 | ||
|
|
26d4b5f2cf | ||
|
|
ba0dfac53d | ||
|
|
8a4296a948 | ||
|
|
478f9e028f | ||
|
|
c4e56894d9 | ||
|
|
c6f13844ed | ||
|
|
5e81653680 | ||
|
|
8e2df3f1f9 | ||
|
|
a2cc384172 | ||
|
|
d37bf292a1 | ||
|
|
70eb641530 | ||
|
|
f845a9b2c4 | ||
|
|
ee5cb8d9ed | ||
|
|
9020a21ba2 | ||
|
|
fdda013d07 | ||
|
|
64477d934d | ||
|
|
45c507056a | ||
|
|
730b96c195 | ||
|
|
a185f91433 | ||
|
|
d053622802 | ||
|
|
74d6b61973 | ||
|
|
97784c8cca | ||
|
|
812d93553a | ||
|
|
d251b4cb56 | ||
|
|
caf38e1962 | ||
|
|
4ccbee4639 | ||
|
|
84196a3a07 | ||
|
|
29361c055a | ||
|
|
4277265591 | ||
|
|
812a2b315d | ||
|
|
0a1724fc3f | ||
|
|
bcc9e016b1 | ||
|
|
4ea0175ca7 | ||
|
|
799445c745 | ||
|
|
481ea12999 | ||
|
|
de6b608dda | ||
|
|
606f813822 | ||
|
|
e06c8cd106 | ||
|
|
9e3c67a8a2 | ||
|
|
91362f80b1 | ||
|
|
cde988f99f | ||
|
|
9ec0854659 | ||
|
|
bb17571e56 | ||
|
|
9161af58c0 | ||
|
|
e39f4e8025 | ||
|
|
f5e9909e71 | ||
|
|
46913fc55f | ||
|
|
d358a86e98 | ||
|
|
055545980c | ||
|
|
6fd7f9868e | ||
|
|
e8184a9bc5 | ||
|
|
f74de3ef55 | ||
|
|
9624f8287d | ||
|
|
e42d5a889e | ||
|
|
4c8e6481b6 | ||
|
|
0867df2691 | ||
|
|
b06f99ab30 | ||
|
|
9afa3f6b58 | ||
|
|
785cb4b72f | ||
|
|
dabe69856a | ||
|
|
24e70802b5 | ||
|
|
c1ba55a52d | ||
|
|
4c318166e1 | ||
|
|
c0af67eca1 | ||
|
|
eb14f1da00 | ||
|
|
3361b81658 | ||
|
|
a15f218e9b | ||
|
|
067cf43f52 | ||
|
|
689ce048e6 | ||
|
|
8a143bf957 | ||
|
|
9f7bcf585d | ||
|
|
f9efd8a272 | ||
|
|
8cd2326ff9 | ||
|
|
eb1ae70bfa | ||
|
|
24ef81908c | ||
|
|
b53b41cef3 | ||
|
|
ad245ed46a | ||
|
|
3f6199493e | ||
|
|
e06aac4783 | ||
|
|
6a5adfe338 | ||
|
|
07c7b5b419 | ||
|
|
7f985fe08a | ||
|
|
38f02a6429 | ||
|
|
f943bdcac0 | ||
|
|
8dc634edfc | ||
|
|
05b9cf17f0 | ||
|
|
69bbe89616 | ||
|
|
6b49958f7c | ||
|
|
e75ce94578 | ||
|
|
f666473724 | ||
|
|
ae817e3c9c | ||
|
|
2e9352de14 | ||
|
|
1e9e55ddef | ||
|
|
0799ed7116 | ||
|
|
5537250d4f | ||
|
|
7ada50937b | ||
|
|
f2ae88af93 | ||
|
|
726451f86f | ||
|
|
306cfc6328 | ||
|
|
a051a47048 | ||
|
|
5b2216b348 | ||
|
|
ad60d49611 | ||
|
|
a6d1a5a724 | ||
|
|
399d835285 | ||
|
|
b66367ddde | ||
|
|
37d29b7a6f | ||
|
|
1e708fb373 | ||
|
|
76ae1682a3 | ||
|
|
2ef0aa95c5 | ||
|
|
9cbb49c6b2 | ||
|
|
f04a734838 | ||
|
|
beb5ccab25 | ||
|
|
b8f8f24e82 | ||
|
|
c35a007401 | ||
|
|
e639c82f2f | ||
|
|
f365cc1248 | ||
|
|
2b75c67448 | ||
|
|
e5e9ae7e0f | ||
|
|
009422e997 | ||
|
|
386e221a0f | ||
|
|
58db94401e | ||
|
|
f9be9bab89 | ||
|
|
dc7e963c9f | ||
|
|
a786f39b1b | ||
|
|
95cf793df4 | ||
|
|
ea2ad96089 | ||
|
|
4b2cf2e2c5 | ||
|
|
23b8c72e9a | ||
|
|
80876a2c0a | ||
|
|
c923010292 | ||
|
|
c84af909f7 | ||
|
|
d6b39bc89b | ||
|
|
39fe737cb6 | ||
|
|
37ef976515 | ||
|
|
fa5a3022d4 | ||
|
|
58bed088f5 | ||
|
|
4f023e83f8 | ||
|
|
7d950cd60a | ||
|
|
ffc9244f88 | ||
|
|
6ede3986c7 | ||
|
|
5a81d22167 | ||
|
|
2bf2e26a64 | ||
|
|
ee466e90ca | ||
|
|
911e3939b9 | ||
|
|
ca6f8e9a96 | ||
|
|
55f2cffc22 | ||
|
|
ca482b79ad | ||
|
|
b1f0ecf244 | ||
|
|
36fa174901 | ||
|
|
e8dc4628ae | ||
|
|
7a0dbb0203 | ||
|
|
8d81a382f7 | ||
|
|
86fbba08d8 | ||
|
|
23c6e7e168 | ||
|
|
c35f041091 | ||
|
|
618c6a8e67 | ||
|
|
23429f7b7f | ||
|
|
d6052b483a | ||
|
|
3b3255a964 | ||
|
|
49847e70af | ||
|
|
c228d76e44 | ||
|
|
2562b0c201 | ||
|
|
6da6bc3eb8 | ||
|
|
bbcfc3c9f2 | ||
|
|
12b1de7c9d | ||
|
|
721636f475 | ||
|
|
4c94941ceb | ||
|
|
f06535e915 | ||
|
|
389914c427 | ||
|
|
c7f5715d8e | ||
|
|
29f866525e | ||
|
|
de61455a55 | ||
|
|
fd579a8772 | ||
|
|
8e708906a8 | ||
|
|
b7680059c8 | ||
|
|
239369314c | ||
|
|
f2d1fc47d1 | ||
|
|
aab35736c5 | ||
|
|
a9405e5e80 | ||
|
|
9880990fa7 | ||
|
|
6674611b26 | ||
|
|
e92ec6aba7 | ||
|
|
1801b725bd | ||
|
|
72de8f5c9b | ||
|
|
895d965568 | ||
|
|
3a11c7d46b | ||
|
|
92d9b3ff5f | ||
|
|
630f1717f0 | ||
|
|
e6e93840a6 | ||
|
|
b2ad79cf88 | ||
|
|
706797eb47 | ||
|
|
4163d1372a | ||
|
|
4413da8d6e | ||
|
|
8e23d623c8 | ||
|
|
e712c5225b | ||
|
|
8bdb723004 | ||
|
|
9f912f548e | ||
|
|
41d721e372 | ||
|
|
df6ffe025c | ||
|
|
28b6b4af44 | ||
|
|
9e80071caa | ||
|
|
0da4303358 | ||
|
|
83e225f30a | ||
|
|
420505ca40 | ||
|
|
f9a26fd903 | ||
|
|
ca0539190e | ||
|
|
2e3226b520 | ||
|
|
7959852eeb | ||
|
|
c129eba712 | ||
|
|
0e2d7fa941 | ||
|
|
0b33a62032 | ||
|
|
6919ed2b34 | ||
|
|
435320e3f9 | ||
|
|
7b846af965 | ||
|
|
18b836c16a | ||
|
|
fb360039ce | ||
|
|
4763b95a0d | ||
|
|
9fe1e37ca7 | ||
|
|
8a9aac3e68 | ||
|
|
27138abd29 | ||
|
|
dcf91db475 | ||
|
|
ab63345764 | ||
|
|
a35e63fb29 | ||
|
|
3fe7df9a48 | ||
|
|
5288f3afda | ||
|
|
25566a24f6 | ||
|
|
2ff6dee0ec | ||
|
|
491d1238c2 | ||
|
|
234414c2f2 | ||
|
|
3ff544bbab | ||
|
|
416c4cbb84 | ||
|
|
db5bf1749b | ||
|
|
41349afea3 | ||
|
|
27da6de723 | ||
|
|
2cdb4e3343 | ||
|
|
981d3e40f8 | ||
|
|
c7a616730c | ||
|
|
5aa8ece242 | ||
|
|
8c7ba20f86 | ||
|
|
1cc9027fcf | ||
|
|
e63dbaa646 | ||
|
|
4a720625d9 | ||
|
|
ad428b107a | ||
|
|
c0299320f0 | ||
|
|
efaee3d5d9 | ||
|
|
12bee73070 | ||
|
|
82c18a837d | ||
|
|
fed51e8246 | ||
|
|
71f17e464f | ||
|
|
026fd7eddb | ||
|
|
456b2d3910 | ||
|
|
4208bf3f4b | ||
|
|
a81678d327 | ||
|
|
be55f42f80 | ||
|
|
b1b326cf9c | ||
|
|
a9ff73b4f6 | ||
|
|
f5ccb9c0ba | ||
|
|
1cbbe00b7a | ||
|
|
055dd5d2c3 | ||
|
|
0fea437536 | ||
|
|
f325d3b065 | ||
|
|
e514660fbd | ||
|
|
a5d8144cce | ||
|
|
8145840264 | ||
|
|
a02eafedfd | ||
|
|
3f3cd2bb3a | ||
|
|
503a3f2e3a | ||
|
|
48a8723fdb | ||
|
|
92c297b1be | ||
|
|
56e26378ff | ||
|
|
f3f69ab4fa | ||
|
|
2a488b951d | ||
|
|
ac01caacd3 | ||
|
|
cbdf746474 | ||
|
|
ad0a1ae66d | ||
|
|
3b783979d8 | ||
|
|
b2ec15accc | ||
|
|
3b7cfc908e | ||
|
|
010ca83d0d | ||
|
|
161c895a90 | ||
|
|
47a45f3731 | ||
|
|
7bb3cfd932 | ||
|
|
16a94a769a | ||
|
|
f7c7918efe | ||
|
|
bf393c025f | ||
|
|
bbbc9c0c5e | ||
|
|
579db9107f | ||
|
|
d1d30e9ec9 | ||
|
|
ee782f93c4 | ||
|
|
9ed6aa48a0 | ||
|
|
ecebedd5a2 | ||
|
|
31df576d26 | ||
|
|
63d6335d99 | ||
|
|
9e21994c01 | ||
|
|
b8ee654ac2 | ||
|
|
00b22b1231 | ||
|
|
2e589904c7 | ||
|
|
1cd475d118 | ||
|
|
fbdea41399 | ||
|
|
5d720dbc43 | ||
|
|
3940149517 | ||
|
|
e963798067 | ||
|
|
36acfd16ea | ||
|
|
dda372f93e | ||
|
|
62bc815f81 | ||
|
|
4e68f94023 | ||
|
|
2687b435e0 | ||
|
|
9ddf411f2c | ||
|
|
c2fc89af6c | ||
|
|
a5eda35ff4 | ||
|
|
b5e1221c54 | ||
|
|
03942da57a | ||
|
|
e469c864bc | ||
|
|
9d50cae9fd | ||
|
|
249d749580 | ||
|
|
ea860ac5a5 | ||
|
|
30259f3a99 | ||
|
|
a3d7a29961 | ||
|
|
8ce762846e | ||
|
|
8092716b79 | ||
|
|
b7ba54724c | ||
|
|
7f7ee41315 | ||
|
|
b33f05bd3d | ||
|
|
1ae6eabedd | ||
|
|
973be9ad96 | ||
|
|
979ce93499 | ||
|
|
642e36c259 | ||
|
|
efaf56c6de | ||
|
|
a0c7950d8a | ||
|
|
f7be1b74d7 | ||
|
|
e264ac03b3 | ||
|
|
425f0c5fdf | ||
|
|
960a70287d | ||
|
|
c25c33e3ee | ||
|
|
d72081f82c | ||
|
|
d4debc3c85 | ||
|
|
7894f1a079 | ||
|
|
5ffaeb5e9f | ||
|
|
e50a7406ad | ||
|
|
962eeed252 | ||
|
|
2d8944fbd5 | ||
|
|
ddfb492ed9 | ||
|
|
3d98364adb | ||
|
|
3affa543ef | ||
|
|
2a47afebde | ||
|
|
f2fc6d8852 | ||
|
|
28c4c18ee2 | ||
|
|
968db67d0a | ||
|
|
b22ef22e36 | ||
|
|
044ce45d98 | ||
|
|
69f2a0d3f1 | ||
|
|
4b66dcb738 | ||
|
|
dfc6f1d1cf | ||
|
|
a64e040ac7 | ||
|
|
4f9414dbb0 | ||
|
|
bc6b31efbc | ||
|
|
244aed1ae9 | ||
|
|
4fdb2ce939 | ||
|
|
fe57eb554c | ||
|
|
3b798943e3 | ||
|
|
4ff66a5cfc | ||
|
|
5477a990bc | ||
|
|
656ca422a5 | ||
|
|
7a3071a094 | ||
|
|
77361582f4 | ||
|
|
f585039430 | ||
|
|
21dcb6037a | ||
|
|
d10d96d19a | ||
|
|
64766eea44 | ||
|
|
a9e682836b | ||
|
|
f504b8d529 | ||
|
|
30b2b55c86 | ||
|
|
836bc3a9a4 | ||
|
|
630bfcc6cd | ||
|
|
117203010a | ||
|
|
f0986fe9c7 | ||
|
|
4379441277 | ||
|
|
a955af06e0 | ||
|
|
8f69e59f29 | ||
|
|
efda5ca897 | ||
|
|
8a99fd3c8d | ||
|
|
614ce4de0a | ||
|
|
06b2cffbfc | ||
|
|
f3dfe9571e | ||
|
|
9b9e2c4ac0 | ||
|
|
28e0b17a81 | ||
|
|
b02f10053e | ||
|
|
979dcd5330 | ||
|
|
ff18fd37df | ||
|
|
dd56d53556 | ||
|
|
2b85045b61 | ||
|
|
a1e11aba61 | ||
|
|
946ba7a8d3 | ||
|
|
4a94ef3aa6 | ||
|
|
fd45e9218c | ||
|
|
24d4d6d73a | ||
|
|
d87b70b57e | ||
|
|
bbfb297d73 | ||
|
|
9b68d08604 | ||
|
|
47b56d089f | ||
|
|
10ede7c934 | ||
|
|
344390d1b5 | ||
|
|
2869878046 | ||
|
|
2f79bee367 | ||
|
|
202d98c318 | ||
|
|
442a39359e | ||
|
|
c907f8703a | ||
|
|
6f2925ed83 | ||
|
|
f256e18182 | ||
|
|
f9521e5599 | ||
|
|
41ae06f1aa | ||
|
|
e5613e9e0d | ||
|
|
779d14311a | ||
|
|
971da50129 | ||
|
|
c49438da60 | ||
|
|
e4a030c916 | ||
|
|
c72f9d894d | ||
|
|
59283c1148 | ||
|
|
cfe9a4e270 | ||
|
|
0110d18d4c | ||
|
|
2bd1afc5fd | ||
|
|
6875277375 | ||
|
|
9b5045bb91 | ||
|
|
f14c0fa5d6 | ||
|
|
4b6203d1f4 | ||
|
|
3db7811f00 | ||
|
|
8243a34b69 | ||
|
|
a821b2249b | ||
|
|
0a851ced19 | ||
|
|
a2a1ab4c52 | ||
|
|
876d88c761 | ||
|
|
d473826a68 | ||
|
|
cfd0059fc7 | ||
|
|
b21b0e753e | ||
|
|
5253502846 | ||
|
|
526e743c58 | ||
|
|
7df0d0530f | ||
|
|
567479787b | ||
|
|
59e3eb2bd1 | ||
|
|
b449dbe891 | ||
|
|
c7c99efa8e | ||
|
|
2808bc2c90 | ||
|
|
9b7eb2dcd8 | ||
|
|
274b58573b | ||
|
|
d7f33121c9 | ||
|
|
75460b91d8 | ||
|
|
3d355566dc | ||
|
|
a3b58edc52 | ||
|
|
5c71b1a031 | ||
|
|
585e21a734 | ||
|
|
a46f4f7873 | ||
|
|
456bce1c9a | ||
|
|
d8046333c0 | ||
|
|
49c28d449e | ||
|
|
3fdf492dcf | ||
|
|
99a4343626 | ||
|
|
8eb3091a9d | ||
|
|
befa221bd9 | ||
|
|
a954ae3a6e | ||
|
|
afa0a31b91 | ||
|
|
8a13c12738 | ||
|
|
b938e1aece | ||
|
|
89a3206553 | ||
|
|
66e9df6b0b | ||
|
|
2fb299da22 | ||
|
|
23d962b838 | ||
|
|
519454c343 | ||
|
|
9cf1c62147 | ||
|
|
0e6bd3ed08 | ||
|
|
95a3a02469 | ||
|
|
1a0cad2ac1 | ||
|
|
d78a01086d | ||
|
|
3607689fbc | ||
|
|
70ce6e0ab8 | ||
|
|
914ef4c5f5 | ||
|
|
75389b04a6 | ||
|
|
3167d66154 | ||
|
|
bd789ff032 | ||
|
|
c118c10a9d | ||
|
|
8ed1325dfc | ||
|
|
33cd9eeafd | ||
|
|
b280303a10 | ||
|
|
0ad071af4e | ||
|
|
a22cd72440 | ||
|
|
4fee58e7bc | ||
|
|
86b6904e77 | ||
|
|
9f435d02f2 | ||
|
|
5419616063 | ||
|
|
5f8f9e35d7 | ||
|
|
e1d2def4b1 | ||
|
|
36fef5676a | ||
|
|
063fec0ca6 | ||
|
|
c7e4213641 | ||
|
|
bff150f69d | ||
|
|
dc209417e7 | ||
|
|
fb74832594 | ||
|
|
49cd1753e6 | ||
|
|
36fa887be8 | ||
|
|
dacb187f11 | ||
|
|
5815b17dee | ||
|
|
fe594dfe0c | ||
|
|
4fe6ad43c1 | ||
|
|
377212290f | ||
|
|
51b6946a98 | ||
|
|
c90904a139 | ||
|
|
8f68f62f8a | ||
|
|
8678917e2a | ||
|
|
115509653f | ||
|
|
f43fc08a8f | ||
|
|
31504a5187 | ||
|
|
9bfe6e7aac | ||
|
|
2e0a185db6 | ||
|
|
f63ce4ddd4 | ||
|
|
c4fb5a5e40 | ||
|
|
738203485c | ||
|
|
5218d07b0d | ||
|
|
b9b1a44c28 | ||
|
|
c0a4e7ad55 | ||
|
|
9ed8e4a35b | ||
|
|
3e2d611707 | ||
|
|
5463872926 | ||
|
|
81ff635c60 | ||
|
|
7072f64397 | ||
|
|
418de75e77 | ||
|
|
bed2826e3b | ||
|
|
f2a432531e | ||
|
|
da6c2b8d6a | ||
|
|
b02e28f3fd | ||
|
|
da8888a350 | ||
|
|
43856136d5 | ||
|
|
589d20019f | ||
|
|
50d3599f76 | ||
|
|
870954c6be | ||
|
|
6959e60e2c | ||
|
|
9cdbb99eb9 | ||
|
|
48cebd5e30 | ||
|
|
4e829f3e1b | ||
|
|
7cbe914b22 | ||
|
|
c2d61ad660 | ||
|
|
878a7ada06 | ||
|
|
b7b2845160 | ||
|
|
2ab4a3d362 | ||
|
|
cfd95a1398 | ||
|
|
ccdb480d44 | ||
|
|
ac373a9e1c | ||
|
|
4ce7d5a5b4 | ||
|
|
1e217c745b | ||
|
|
287bfc77b2 | ||
|
|
3205c78f01 | ||
|
|
0b6d49e421 | ||
|
|
546a44d1d7 | ||
|
|
ac891bebaa | ||
|
|
0ab4326026 | ||
|
|
5fcfff23a4 | ||
|
|
28fe45bd1d | ||
|
|
f312026c23 | ||
|
|
8023788305 | ||
|
|
0d0d89fd9c | ||
|
|
019f2ee932 | ||
|
|
8558505b65 | ||
|
|
c51f8c48b6 | ||
|
|
3d9d842a0d | ||
|
|
cfd028288f | ||
|
|
194c080c64 | ||
|
|
4c6076e529 | ||
|
|
df65ec08a2 | ||
|
|
62f11011b0 | ||
|
|
9385c7e4ad | ||
|
|
3c06e68cae | ||
|
|
e8810f5124 | ||
|
|
3c258c4716 | ||
|
|
193a3c167e | ||
|
|
4b525daf72 | ||
|
|
e46f42872a | ||
|
|
4790e4068a | ||
|
|
26cb5d5a65 | ||
|
|
031bda61cc | ||
|
|
61f1fae83b | ||
|
|
d911bdaf63 | ||
|
|
1859226e76 | ||
|
|
e4523de16d | ||
|
|
6a3829d605 | ||
|
|
437ba46889 | ||
|
|
7007f7e0bb | ||
|
|
ff12a996de | ||
|
|
faba02afd4 | ||
|
|
5436e95c9a | ||
|
|
031099b58e | ||
|
|
e75d1a1666 | ||
|
|
7f6eb3dba3 | ||
|
|
33d2463c65 | ||
|
|
ab134d0919 | ||
|
|
d6412d0a1b | ||
|
|
9f41d6231e | ||
|
|
9d2e12dfa6 | ||
|
|
043bf13d24 | ||
|
|
3f96cf3963 | ||
|
|
22fb346983 | ||
|
|
e7acfd7bb7 | ||
|
|
31cf740b99 | ||
|
|
d75139a059 | ||
|
|
7257e2445d | ||
|
|
f322252c36 | ||
|
|
da16bf1e42 | ||
|
|
157f5c3304 | ||
|
|
4a1addc558 | ||
|
|
e2bf61379f | ||
|
|
02019d4d8f | ||
|
|
c81cc5cda0 | ||
|
|
8d288c01ca | ||
|
|
857abf5024 | ||
|
|
6d67105bab | ||
|
|
e2f4ca106e | ||
|
|
061bbe0409 | ||
|
|
078b09676f | ||
|
|
b719eaf6ab | ||
|
|
b63accca25 | ||
|
|
2d41b09c3b | ||
|
|
0b44137d1f | ||
|
|
8d8dd5fa37 | ||
|
|
16b7ff972c | ||
|
|
ca41612109 | ||
|
|
8fc7af5480 | ||
|
|
7e6da1d368 | ||
|
|
d4cc8fefd1 | ||
|
|
81bec3e5c4 | ||
|
|
e985d8b25d | ||
|
|
84ee0efe32 | ||
|
|
e9a024e58a | ||
|
|
e8237910e8 | ||
|
|
1c6cb7ce40 | ||
|
|
24d6c3f488 | ||
|
|
d877a04397 | ||
|
|
4844882f5e | ||
|
|
a80945cfb4 | ||
|
|
6a884c58a7 | ||
|
|
7c4701716c | ||
|
|
ecfd5fadc6 | ||
|
|
c6be5cccd7 | ||
|
|
dd256dc3f8 | ||
|
|
622da331a6 | ||
|
|
5a44793dcb | ||
|
|
9c9a9b0325 | ||
|
|
2534f7f2a0 | ||
|
|
36a933a004 | ||
|
|
62c168b13c | ||
|
|
810c97d7ab | ||
|
|
c2b20b18b3 | ||
|
|
309d19960f | ||
|
|
774cb66d9b | ||
|
|
d360bd5bb7 | ||
|
|
74f5a73d31 | ||
|
|
26395a86fa | ||
|
|
436c488ee3 | ||
|
|
93d99077e5 | ||
|
|
0bb52d6e3d | ||
|
|
320c78b815 | ||
|
|
ddd59b94b0 | ||
|
|
c210d64557 | ||
|
|
a0f605bbab | ||
|
|
f4b2768194 | ||
|
|
95d9f59668 | ||
|
|
c41d799b9b | ||
|
|
e7d4642d48 | ||
|
|
41949fd58b | ||
|
|
d0dc972840 | ||
|
|
621e66e9ac | ||
|
|
529544ce0e | ||
|
|
f298cd3f0f | ||
|
|
67029ac8e8 | ||
|
|
b54800234f | ||
|
|
ecd85f53b4 | ||
|
|
9098852897 | ||
|
|
3eb4d5b466 | ||
|
|
ddb1c718f1 | ||
|
|
8919873ea1 | ||
|
|
eb9cd95d5a | ||
|
|
4ec701fc44 | ||
|
|
ff9511d435 | ||
|
|
ac5a6da1fa | ||
|
|
616640a128 | ||
|
|
1f9ce96e43 | ||
|
|
dc6a862bec | ||
|
|
f9480b5280 | ||
|
|
8dc4996547 | ||
|
|
4f01f67dd6 | ||
|
|
938026abeb | ||
|
|
76b8945207 | ||
|
|
e78859fae0 | ||
|
|
d68f1e9910 | ||
|
|
20e97f2d9b | ||
|
|
750ec7783f | ||
|
|
14ae438735 | ||
|
|
2f8bdd7e27 | ||
|
|
87da9fcfc5 | ||
|
|
51f6cfddca | ||
|
|
b9ad4c2773 | ||
|
|
228b3dbc34 | ||
|
|
a01802300f | ||
|
|
51c6a3fffc | ||
|
|
4668e1d67b | ||
|
|
75e9097e19 | ||
|
|
0627cd94d4 | ||
|
|
71879d6e8f | ||
|
|
d7810cac08 | ||
|
|
dc9efd21d3 | ||
|
|
347e490614 | ||
|
|
e512264be7 | ||
|
|
9624663e60 | ||
|
|
3cf8a6df01 | ||
|
|
88eacecd72 | ||
|
|
fcd3c9ce65 | ||
|
|
1733bac3bb | ||
|
|
21cd063274 | ||
|
|
db5750643a | ||
|
|
60dae7a88d | ||
|
|
790c924b54 | ||
|
|
50d7a46c7f | ||
|
|
6f7da38957 | ||
|
|
80764c214a | ||
|
|
55054e45da | ||
|
|
060aa5ba0b | ||
|
|
688d619bfe | ||
|
|
6db7fce543 | ||
|
|
41ff1d4ace | ||
|
|
1c6eeba2e9 | ||
|
|
488b719fde | ||
|
|
af32080287 | ||
|
|
4c1cd13536 | ||
|
|
1002cf7796 | ||
|
|
081dd33e73 | ||
|
|
bd9dc4f15d | ||
|
|
c7ba566ad6 | ||
|
|
a1b326a0ab | ||
|
|
a452f781b8 | ||
|
|
e5463cc2a9 | ||
|
|
7d732ef503 | ||
|
|
25cb0c6344 | ||
|
|
45a52bf478 | ||
|
|
a14f971b8a | ||
|
|
da65500545 | ||
|
|
58a91ee9e9 | ||
|
|
19eaa181a5 | ||
|
|
c7c90acf3f | ||
|
|
c6f3a55c03 | ||
|
|
e01b7d288f | ||
|
|
98c0e185b8 | ||
|
|
bf66d78210 | ||
|
|
b60eca0a76 | ||
|
|
44f06c0b4c | ||
|
|
6c5606b7e8 | ||
|
|
07ddfbeb5d | ||
|
|
87b890c172 | ||
|
|
245fcfe110 | ||
|
|
bb19f24923 | ||
|
|
4744719040 | ||
|
|
a3b814a897 | ||
|
|
f5f17f0ccb | ||
|
|
f6a2acdfb1 | ||
|
|
e8dba2ad1e | ||
|
|
8ce5c5b608 | ||
|
|
0cbcbc60de | ||
|
|
f33cd7184f | ||
|
|
59d6400eb9 | ||
|
|
5c575ebf8f | ||
|
|
274205bccd | ||
|
|
e85c9b633a | ||
|
|
0dfea1a51b | ||
|
|
a4e528e2b3 | ||
|
|
99ca9b7e9a | ||
|
|
313e932e7c | ||
|
|
6a57a4e565 | ||
|
|
fc3a5f25fb | ||
|
|
e258b85420 | ||
|
|
6b836de306 | ||
|
|
fe6f53d471 | ||
|
|
3b259c6b1e | ||
|
|
2005df3fa2 | ||
|
|
4fdcf685d3 | ||
|
|
afd3af834d | ||
|
|
8afec8b12a | ||
|
|
f25ed0b5de | ||
|
|
4898770d60 | ||
|
|
bd2fa77446 | ||
|
|
1c2bafe0e1 | ||
|
|
f8915333b0 | ||
|
|
f8275adc6f | ||
|
|
2a97a4233d | ||
|
|
70eae9f6ce | ||
|
|
f560062d82 | ||
|
|
0f55a66f5b | ||
|
|
f14f72b635 | ||
|
|
9aa010d987 | ||
|
|
bd179ace86 | ||
|
|
4df6d6043e | ||
|
|
7ed7475c46 | ||
|
|
b2dc560a2d | ||
|
|
010dbe1cce | ||
|
|
75cd0bab02 | ||
|
|
3283991ed0 | ||
|
|
a66ce5b6ce | ||
|
|
9620f50f22 | ||
|
|
cc049ea851 | ||
|
|
e5a04ae117 | ||
|
|
e07e74f010 | ||
|
|
7b04c501eb | ||
|
|
70349dd4b3 | ||
|
|
2cedc843a8 | ||
|
|
cf40fe3430 | ||
|
|
09ffeed139 | ||
|
|
18f79d6253 | ||
|
|
6f5270f38f | ||
|
|
aac7aac373 | ||
|
|
9361470dc7 | ||
|
|
cf579f4b6e | ||
|
|
2e497eef98 | ||
|
|
7867daaa04 | ||
|
|
eabbcd31ad | ||
|
|
17d198f3d6 | ||
|
|
afd5376c8d | ||
|
|
02a50c9f7e | ||
|
|
df9fa32b82 | ||
|
|
831b420df3 | ||
|
|
123186003c | ||
|
|
fbb150cfc1 | ||
|
|
ea627ed57c | ||
|
|
157bb48776 | ||
|
|
76a3771943 | ||
|
|
54f8889a30 | ||
|
|
bab159bc08 | ||
|
|
23950963e5 | ||
|
|
d1daac5550 | ||
|
|
d93ece5ccf | ||
|
|
c8c667bf16 | ||
|
|
49cdacbcb4 | ||
|
|
f97bd584f7 | ||
|
|
f1328aa82f | ||
|
|
e298a5d350 | ||
|
|
89a6ef0b26 | ||
|
|
c7ac9b7815 | ||
|
|
55c99b9122 | ||
|
|
545c8c3adb | ||
|
|
d093dc8231 | ||
|
|
eaf9d58b8d | ||
|
|
6131cea5b2 | ||
|
|
ca4831febe | ||
|
|
9cf8d05a19 | ||
|
|
2a4f03330b | ||
|
|
83bc614bad | ||
|
|
99ccb4111a | ||
|
|
f6c72e9ae9 | ||
|
|
a90730d4bf | ||
|
|
29503d2d37 | ||
|
|
35451ed408 | ||
|
|
7167aeb65a | ||
|
|
29d0489443 | ||
|
|
82aa2686f9 | ||
|
|
24616fa08a | ||
|
|
9f3e1eabfd | ||
|
|
286d2f84bd | ||
|
|
7fc484d82e | ||
|
|
ad6ab57fe3 | ||
|
|
348fe045d3 | ||
|
|
980b20316b | ||
|
|
5b52e507ca | ||
|
|
9853c9d78d | ||
|
|
72ec771725 | ||
|
|
75e97d9f7e | ||
|
|
295faf185c | ||
|
|
54b05f33f2 | ||
|
|
1985146760 | ||
|
|
13a52dd300 | ||
|
|
9d4bea70e6 | ||
|
|
421906bcc1 | ||
|
|
508b3531e5 | ||
|
|
393d52088a | ||
|
|
5783973734 | ||
|
|
55e01afd0d | ||
|
|
1231dc6cef |
5
.babelrc
Normal file
5
.babelrc
Normal file
@@ -0,0 +1,5 @@
|
||||
{
|
||||
"experimental": true,
|
||||
"playground": true,
|
||||
"loose": true
|
||||
}
|
||||
@@ -6,6 +6,6 @@ charset = utf-8
|
||||
trim_trailing_whitespace = true
|
||||
insert_final_newline = true
|
||||
|
||||
[*.js]
|
||||
[*.{js,json}]
|
||||
indent_style = space
|
||||
indent_size = 2
|
||||
|
||||
2
.gitignore
vendored
2
.gitignore
vendored
@@ -11,3 +11,5 @@ test/tmp
|
||||
coverage
|
||||
dist
|
||||
.package.json
|
||||
packages/babel-runtime/*.js
|
||||
packages/babel-runtime/regenerator/*.js
|
||||
|
||||
5
.gitmodules
vendored
5
.gitmodules
vendored
@@ -3,7 +3,10 @@
|
||||
url = https://github.com/google/traceur-compiler
|
||||
[submodule "vendor/regenerator"]
|
||||
path = vendor/regenerator
|
||||
url = https://github.com/facebook/regenerator
|
||||
url = https://github.com/babel/regenerator-babel
|
||||
[submodule "vendor/test262"]
|
||||
path = vendor/test262
|
||||
url = https://github.com/tc39/test262
|
||||
[submodule "vendor/compat-table"]
|
||||
path = vendor/compat-table
|
||||
url = https://github.com/kangax/compat-table
|
||||
|
||||
2
.istanbul.yml
Normal file
2
.istanbul.yml
Normal file
@@ -0,0 +1,2 @@
|
||||
instrumentation:
|
||||
root: lib
|
||||
58
.jscsrc
Normal file
58
.jscsrc
Normal file
@@ -0,0 +1,58 @@
|
||||
{
|
||||
"excludeFiles": ["lib/babel/transformation/templates"],
|
||||
"disallowSpacesInNamedFunctionExpression": {
|
||||
"beforeOpeningRoundBrace": true
|
||||
},
|
||||
"requireSpacesInAnonymousFunctionExpression": {
|
||||
"beforeOpeningRoundBrace": true
|
||||
},
|
||||
"requireSpacesInAnonymousFunctionExpression": {
|
||||
"beforeOpeningRoundBrace": true
|
||||
},
|
||||
"disallowSpacesInFunctionDeclaration": {
|
||||
"beforeOpeningRoundBrace": true
|
||||
},
|
||||
"disallowSpacesInsideArrayBrackets": true,
|
||||
"disallowSpacesInsideParentheses": true,
|
||||
"disallowSpaceAfterObjectKeys": true,
|
||||
"disallowSpaceAfterPrefixUnaryOperators": true,
|
||||
"disallowSpaceBeforePostfixUnaryOperators": true,
|
||||
"disallowSpaceBeforeBinaryOperators": [
|
||||
","
|
||||
],
|
||||
"disallowMixedSpacesAndTabs": true,
|
||||
"disallowTrailingWhitespace": true,
|
||||
"disallowYodaConditions": true,
|
||||
"disallowKeywords": [ "with" ],
|
||||
"disallowMultipleLineBreaks": true,
|
||||
"requireSpaceBeforeBlockStatements": true,
|
||||
"requireParenthesesAroundIIFE": true,
|
||||
"requireSpacesInConditionalExpression": true,
|
||||
"requireBlocksOnNewline": 1,
|
||||
"requireCommaBeforeLineBreak": true,
|
||||
"requireSpaceBeforeBinaryOperators": true,
|
||||
"requireSpaceAfterBinaryOperators": true,
|
||||
"requireLineFeedAtFileEnd": true,
|
||||
"requireCapitalizedConstructors": true,
|
||||
"requireSpacesInForStatement": true,
|
||||
"requireCurlyBraces": [
|
||||
"do"
|
||||
],
|
||||
"requireSpaceAfterKeywords": [
|
||||
"if",
|
||||
"else",
|
||||
"for",
|
||||
"while",
|
||||
"do",
|
||||
"switch",
|
||||
"case",
|
||||
"return",
|
||||
"try",
|
||||
"catch",
|
||||
"typeof",
|
||||
"function"
|
||||
],
|
||||
"validateLineBreaks": "LF",
|
||||
"validateQuoteMarks": "\"",
|
||||
"validateIndentation": 2
|
||||
}
|
||||
@@ -1,3 +1 @@
|
||||
node_modules
|
||||
test
|
||||
lib/6to5/transformation/templates
|
||||
lib/babel/transformation/templates
|
||||
|
||||
@@ -2,10 +2,10 @@
|
||||
"esnext": true,
|
||||
"indent": 2,
|
||||
"freeze": true,
|
||||
"validthis": true,
|
||||
"camelcase": true,
|
||||
"unused": true,
|
||||
"eqnull": true,
|
||||
"proto": true,
|
||||
"newcap": true,
|
||||
"supernew": true,
|
||||
"noyield": true,
|
||||
@@ -14,8 +14,6 @@
|
||||
"boss": true,
|
||||
"expr": true,
|
||||
"undef": true,
|
||||
"loopfunc": true,
|
||||
"white": true,
|
||||
"maxparams": 5,
|
||||
"maxdepth": 4,
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
node_modules
|
||||
*.log
|
||||
*.cache
|
||||
lib/6to5/transformation/templates
|
||||
lib/babel/transformation/templates
|
||||
test
|
||||
benchmark
|
||||
Makefile
|
||||
@@ -10,3 +10,6 @@ dist
|
||||
tests.json
|
||||
CHANGELOG.md
|
||||
.package.json
|
||||
coverage
|
||||
vendor
|
||||
packages
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
sudo: false
|
||||
language: node_js
|
||||
node_js:
|
||||
- "0.10"
|
||||
- "0.11"
|
||||
- "0.12"
|
||||
- "iojs"
|
||||
|
||||
branches:
|
||||
except:
|
||||
|
||||
1093
CHANGELOG-6to5.md
Normal file
1093
CHANGELOG-6to5.md
Normal file
File diff suppressed because it is too large
Load Diff
536
CHANGELOG.md
536
CHANGELOG.md
@@ -11,533 +11,31 @@
|
||||
|
||||
_Note: Gaps between patch versions are faulty/broken releases._
|
||||
|
||||
## 2.9.4
|
||||
See [CHANGELOG - 6to5](CHANGELOG-6to5.md) for the pre-4.0.0 version changelog.
|
||||
|
||||
* **Bug Fix**
|
||||
* Support `UpdateExpression`s as `MemberExpression` objects.
|
||||
|
||||
## 2.9.3
|
||||
|
||||
* **Bug Fix**
|
||||
* Remove `exportsWildcard` helper in favor of `defaults`.
|
||||
|
||||
## 2.9.2
|
||||
|
||||
* **Bug Fix**
|
||||
* Pass `exports` to `exportWildcard` helper to allow for use inside the optional runtime.
|
||||
|
||||
## 2.9.1
|
||||
|
||||
* **Bug Fix**
|
||||
* Fix runtime generator breaking the helper inclusion loop.
|
||||
|
||||
## 2.9.0
|
||||
|
||||
* **Internal**
|
||||
* Upgrade `acorn-6to5`.
|
||||
* Now supports destructuring shorthand properties.
|
||||
|
||||
## 2.8.1
|
||||
|
||||
* **Bug Fix**
|
||||
* Fix computed accessors on object literals.
|
||||
|
||||
## 2.8.0
|
||||
|
||||
* **New Feature**
|
||||
* Add `commonStrict`, `amdStrict` and `umdStrict` module formatters that remove `module.exports` interop assignment.
|
||||
* Add `--indent` option to the 6to5 CLI.
|
||||
|
||||
## 2.7.4
|
||||
## 4.2.0
|
||||
|
||||
* **Polish**
|
||||
* Inherit assignments from their declaration in destructuring.
|
||||
* Properly align multi-declarator variable declarations.
|
||||
|
||||
## 2.7.3
|
||||
|
||||
* **Polish**
|
||||
* Indent and add newlines to `React.createElement` calls in `react` transformer.
|
||||
* Remove `Object.assign` calls and replace it with an `extends` helper.
|
||||
|
||||
## 2.7.1
|
||||
|
||||
* **New Feature**
|
||||
* Expose `version` on browser and node API.
|
||||
* Use an assignment instead of a define for `__esModule` in loose mode.
|
||||
* **Internal**
|
||||
* Upgrade `core-js` to 0.4.1
|
||||
* Add error for `eval();` usage and enable strict mode for parsing.
|
||||
|
||||
## 2.7.0
|
||||
## 4.1.0
|
||||
|
||||
* **Spec Compliancy**
|
||||
* Disallow reassignments of imports.
|
||||
* **New Feature**
|
||||
* `reactCompat` option to enable pre-v0.12 react components.
|
||||
|
||||
## 2.6.3
|
||||
|
||||
* **Bug Fix**
|
||||
* Fix 2.6.0 regression caused by faulty export default from a source handling.
|
||||
|
||||
## 2.6.2
|
||||
|
||||
* **Bug Fix**
|
||||
* Fix rest parameter keys when on functions with params.
|
||||
|
||||
## 2.6.1
|
||||
|
||||
* **Bug Fix**
|
||||
* Fix rest parameter arguments key.
|
||||
|
||||
## 2.6.0
|
||||
|
||||
* **Bug Fix**
|
||||
* Better handling of number literal property keys.
|
||||
* Handle `NewExpression` paren insertion edegcases better.
|
||||
* Add `BABEL_CACHE_PATH` and `BABEL_DISABLE_CACHE` environment variables.
|
||||
* **Internal**
|
||||
* Fix incorrect AST node `identifier("this")`.
|
||||
* Better `toIdentifier` method that handles reserved words.
|
||||
* Upgrade `acorn-6to5`.
|
||||
* Fix exponentiation operator precedence.
|
||||
* Fix line terminators after async contextual keywords.
|
||||
* Add semicolons as class elements inside of a class body.
|
||||
* Upgrade to `core-js` 4.0.0.
|
||||
* Upgrade to `regenerator` 0.8.3.
|
||||
* Fix non-loop labeled statements.
|
||||
* **New Feature**
|
||||
* Basic destructuring defaults
|
||||
* Add `.es` to list of supported extensions.
|
||||
* Add optional `typeofSymbol` transformer.
|
||||
* Use a `for` loop for rest parameters instead of `Array.prototype.slice`.
|
||||
* Replace many internal util functions with modules. Thanks [@sindresorhus](https://github.com/sindresorhus)!
|
||||
|
||||
## 4.0.2
|
||||
|
||||
* **Bug Fix**
|
||||
* Fix generators not properly propagating their internal declarations.
|
||||
* **Polish**
|
||||
* Move `"use strict";` to inside module bodies instead of at the top of the file.
|
||||
* Better handling of dynamic imports.
|
||||
* **Spec Compliancy**
|
||||
* Class inheritance now has a `function` or `null` type check.
|
||||
* Add `interopRequireWildcard` around wildcard imports and exports to handle non-object exports.
|
||||
* Update setter param length error message.
|
||||
* Use ranges on dependencies.
|
||||
|
||||
## 2.5.0
|
||||
## 4.0.0
|
||||
|
||||
* Remove `noDuplicateProperties` transformer.
|
||||
* Better generated UIDs based on nodes.
|
||||
* Default parameters now use `arguments[i]`, conditionals and variable declarations instead of using long-form if statements.
|
||||
|
||||
## 2.4.10
|
||||
|
||||
* Upgrade `acorn-6to5`.
|
||||
|
||||
## 2.4.9
|
||||
|
||||
* Upgrade `acorn-6to5`.
|
||||
* Add optional `protoToAssign` transformer.
|
||||
* Fix missing properties from computed property keys.
|
||||
* Make ES7 comprehensions `let` variables.
|
||||
|
||||
## 2.4.8
|
||||
|
||||
* Make `require("6to5/register")` work with browserify - [#370](https://github.com/6to5/6to5/pull/370). Thanks [@hughsk](https://github.com/hughsk)!
|
||||
|
||||
## 2.4.7
|
||||
|
||||
* Upgrade `acorn-6to5`.
|
||||
|
||||
## 2.4.6
|
||||
|
||||
* Move `coreAliasing` and `undefinedToVoid` transformers down to catch `moduleFormatter` transforms.
|
||||
|
||||
## 2.4.5
|
||||
|
||||
* Avoid printing comments if they've already been output.
|
||||
|
||||
## 2.4.4
|
||||
|
||||
* Add `module` type to browser build `<script>` handler.
|
||||
* Fix some `MemberExpression` modifying incorrectly setting `property` to a `MemberExpression`.
|
||||
|
||||
## 2.4.3
|
||||
|
||||
* Upgrade `acorn-6to5`.
|
||||
* Add support for `FunctionDeclaration`s in `bluebirdCoroutines` and `asyncToGenerators` transformers.
|
||||
|
||||
## 2.4.2
|
||||
|
||||
* Upgrade `acorn-6to5`.
|
||||
* Better uids generated for various transformers based on parent node.
|
||||
* Alias flat references in `coreAliasing` transformer.
|
||||
|
||||
## 2.4.1
|
||||
|
||||
* Better whitespace handling of parenthesized expressions due to trailing comments.
|
||||
* Fix `yield` inside of comprehensions.
|
||||
|
||||
## 2.4.0
|
||||
|
||||
* Use a closure always for classes with a super.
|
||||
* Always use native loops for array comprehensions.
|
||||
* Allow `yield` inside of comprehensions.
|
||||
* Add optional `bluebirdCoroutine` transformer.
|
||||
* Add optional `asyncToGenerator` transformer.
|
||||
* Move `useStrict` transformer to before `_moduleFormatter` causing `"use strict";` to always be placed the very top.
|
||||
|
||||
## 2.3.2
|
||||
|
||||
* Add parens on expressions with trailing comments.
|
||||
|
||||
## 2.3.1
|
||||
|
||||
* Add `undefinedToVoid` optional transformer.
|
||||
* Use `Object.defineProperty` for computed properties.
|
||||
|
||||
## 2.3.0
|
||||
|
||||
* Upgrade `acorn-6to5`.
|
||||
* Support circular references and hoist variable declarations in `system` module formatter.
|
||||
* Add optional transformers, including a new `coreAliasing` transformer that aliases native ES6 static properties to their `core-js` equivalent.
|
||||
|
||||
## 2.2.0
|
||||
|
||||
* Make `system` module formatter modules anonymous by default.
|
||||
* Fix duplicate comments being output, breaking code.
|
||||
|
||||
## 2.1.0
|
||||
|
||||
* Add `cache` option to register hook.
|
||||
* Update `core-js`.
|
||||
* Fix starting newline not being added on case statements.
|
||||
* Fix destructuring `VariableDeclaration`s not inside `BlockStatement`s and `Program`.
|
||||
|
||||
## 2.0.4
|
||||
|
||||
* Avoid being greedy when destructuring array iterables.
|
||||
|
||||
## 2.0.3
|
||||
|
||||
* Hoist function declarations in system module formatter for circular references.
|
||||
* Hoist default function declarations in umd and amd module formatters for circular references.
|
||||
|
||||
## 2.0.2
|
||||
|
||||
* Inherit comments in `for-of` transformer.
|
||||
* Remove `interopRequire` from `system` module formatter.
|
||||
|
||||
## 2.0.1
|
||||
|
||||
* Remap `UpdateExpression` module export binding.
|
||||
* Fix automatic closure on `PrivateDeclaration` in classes.
|
||||
|
||||
## 2.0.0
|
||||
|
||||
* Make string literal generation only escapes unicode that it has to.
|
||||
* Internal code generation format options have been exposed.
|
||||
* Change playground method binding operator from `:` to `#` removing ambiguous syntax with terns.
|
||||
* Fix rest parameters in async and generator functions.
|
||||
* Export/import declarations replace by the modules transformer now inherit comments.
|
||||
* Added playground flag to `6to5-node`.
|
||||
* `6to5-node` now behaves the same as `node`.
|
||||
* `6to5-node` now uses `kexec` to become the forked process to correctly propagate signals on unix.
|
||||
* Constants are now block scoped.
|
||||
* Exposed ast transformer.
|
||||
* Merged `commonInterop` and `common` module formatters.
|
||||
* Fix generator comprehensions not inheriting `arguments`, `this` etc.
|
||||
* Object and class mutator shorthand are now enumerable.
|
||||
* Remove regenerator `Generator has already finished` error which isn't spec-compliant.
|
||||
* Expose internal `spec` transformers that nicen up code output.
|
||||
* Add export variable declaration default initializers.
|
||||
* Propagate export declaration reassignments.
|
||||
* Add initializer default to block scoped variable declarations within a loop.
|
||||
* Flow type support.
|
||||
* Make async/await contextual keywords.
|
||||
* Allow `yield`ing of non-objects.
|
||||
* Class declarations now lack an IIFE.
|
||||
* Support falsy and `null` super classes.
|
||||
* Add support for experimental abstract references `private` declarations.
|
||||
* Leave out IIFE for class declarations.
|
||||
* Switched to [core-js](https://github.com/zloirock/core-js) from [es6-symbol](https://github.com/medikoo/es6-symbol) and [es6-shim](https://github.com/paulmillr/es6-shim/) for built-in polyfill.
|
||||
* `amd` and `umd` module formatters now behave the same as `common` with `interopRequire`.
|
||||
* Micro-optimizations to boost performance by 200%.
|
||||
* Rename module formatter methods `import` to `importDeclaration` and `export` to `exportDeclaration`.
|
||||
* Support multiple declarators in export variable declarations.
|
||||
* Freeze tagged template literal object.
|
||||
* Remove inlined `regenerator` fork.
|
||||
* Remove `ParenthesizedExpression`.
|
||||
* Rename `object-spread` helper to `object-without-properties`.
|
||||
* Rename `class-props` helper to `prototype-properties`.
|
||||
* Rename `extends` helper to `inherits`.
|
||||
* Completely rewritten `system` module formatter.
|
||||
|
||||
## 1.15.0
|
||||
|
||||
* Don't alias `GeneratorFunction` and check the name which causes minifiers to remove the name and throw an error later on when we check if it's set.
|
||||
|
||||
## 1.14.18
|
||||
|
||||
* Fix files only containg comments not being output.
|
||||
* Fix duplicate comments on property key shorthands.
|
||||
|
||||
## 1.14.17
|
||||
|
||||
* Add default initializer to let variables within loop bodies.
|
||||
* Fix excessive `break` replacement inside of switches in let scoping.
|
||||
|
||||
## 1.14.16
|
||||
|
||||
* Add object getter memos and this shorthand to playground.
|
||||
* Fix while loops in let scoping.
|
||||
* Upgrade `acorn-6to5`.
|
||||
|
||||
## 1.14.14
|
||||
|
||||
* Fix template literals escaping.
|
||||
|
||||
## 1.14.13
|
||||
|
||||
* Fix let scoping of `while` loops.
|
||||
* Make class methods enumerable.
|
||||
|
||||
## 1.14.12
|
||||
|
||||
* Fix duplicate dynamic expressions in call spread.
|
||||
|
||||
## 1.14.10
|
||||
|
||||
* Fix let scoping unneccesary override.
|
||||
|
||||
## 1.14.6
|
||||
|
||||
* Avoid ensuring a block on non-array node replacements.
|
||||
|
||||
## 1.14.5
|
||||
|
||||
* Upgrade `acorn-6to5`.
|
||||
* Fix JSON recursion error for unknown code generator node types.
|
||||
* Ensure that a statement is a block on block/statement types when replacing them with multiple nodes.
|
||||
|
||||
## 1.14.4
|
||||
|
||||
* Merge pretzel maps and method binding.
|
||||
|
||||
## 1.14.3
|
||||
|
||||
* Add playground pretzel maps.
|
||||
|
||||
## 1.14.2
|
||||
|
||||
* Fix `commonInterop` default export handling.
|
||||
* Fix keyworded property key identifiers being turned into computed property key literals.
|
||||
|
||||
## 1.14.1
|
||||
|
||||
* Inherit comments from `ClassDeclaration`.
|
||||
|
||||
## 1.14.0
|
||||
|
||||
* Add [playground](https://6to5.github.io/playground.html).
|
||||
|
||||
## 1.13.13
|
||||
|
||||
* Fix `--debug` in `bin/6to5-node`. Thanks [@timoxley](https://github.com/timoxley).
|
||||
|
||||
## 1.13.12
|
||||
|
||||
* Ignore `XJSEmptyExpression`s in `react` transformer output.
|
||||
|
||||
## 1.13.11
|
||||
|
||||
* Fix `util.regexify` on falsy values.
|
||||
* Fix `_aliasFunction` with rest parameters.
|
||||
* Export as `module.exports` instead of `exports.default` if there are no other `ExportDeclaration`s in `commonInterop` module formatter.
|
||||
* Add `system` module formatter. Thanks [@douglasduteil](https://github.com/douglasduteil).
|
||||
|
||||
## 1.13.10
|
||||
|
||||
* Add support for `AssignmentExpression` destructuring outside of `ExpressionStatement`.
|
||||
|
||||
## 1.13.9
|
||||
|
||||
* Fix `VirtualPropertyExpression` visitor keys.
|
||||
|
||||
## 1.13.8
|
||||
|
||||
* Only use a single reference in abstract references.
|
||||
|
||||
## 1.13.7
|
||||
|
||||
* Upgrade `acorn-6to5`.
|
||||
* Add experimental exponentiation operator support.
|
||||
|
||||
## 1.13.6
|
||||
|
||||
* Fix experimental object spread/rest helper.
|
||||
|
||||
## 1.13.5
|
||||
|
||||
* Upgrade `acorn-6to5`.
|
||||
* Add experimental support for object spread/rest.
|
||||
* Change `arguments` to array to an additional helper method.
|
||||
|
||||
## 1.13.4
|
||||
|
||||
* Fix single spread element returning itself.
|
||||
|
||||
## 1.13.3
|
||||
|
||||
* Upgrade `acorn-6to5`.
|
||||
* Add experimental support for abstract references.
|
||||
|
||||
## 1.13.2
|
||||
|
||||
* Optimise `Array.from` usage by adding a helper method.
|
||||
* Upgrade `acorn-6to5`.
|
||||
|
||||
## 1.13.1
|
||||
|
||||
* Fix constructor spread optimisation. Thanks [@zloirock](https://github.com/zloirock).
|
||||
|
||||
## 1.13.0
|
||||
|
||||
* Put experimental ES7 features behind a flag `--experimental` and `experimental` option.
|
||||
* Constructor spread performance increase. Thanks [@RReverser](https://github.com/RReverser).
|
||||
* Use `self` instead of `window` in the optional 6to5 runtime. Thanks [@RReverser](https://github.com/RReverser).
|
||||
|
||||
## 1.12.26
|
||||
|
||||
* Support computed property destructuring.
|
||||
|
||||
## 1.12.25
|
||||
|
||||
* Update `acorn-6to5`, `ast-types`, `es6-shim`, `chokidar`, `estraverse` and `private`.
|
||||
|
||||
## 1.12.24
|
||||
|
||||
* Collect references that haven't been declared in scope.
|
||||
|
||||
## 1.12.23
|
||||
|
||||
* Fix generator function export hoisting.
|
||||
|
||||
## 1.12.22
|
||||
|
||||
* Update `fs-readdir-recursive` and `chokidar`.
|
||||
* Support array destructuring on iterables.
|
||||
* Make amd module id optional. Thanks [@webpro](https://github.com/webpro).
|
||||
|
||||
## 1.12.21
|
||||
|
||||
* Fix unneccesary let scoping replacement.
|
||||
* Add `commonInterop` module formatter. Thanks [@Naddiseo](https://github.com/Naddiseo).
|
||||
* Fix `return` outside of function body bug. Thanks [@brentburg](https://github.com/brentburg).
|
||||
* Add more flexible option types.
|
||||
|
||||
## 1.12.20
|
||||
|
||||
* Append `sourceMappingURL` when using `bin/6to5` and output sourcemaps.
|
||||
|
||||
## 1.12.19
|
||||
|
||||
* Add `comments` option and `--remove-comments` flag. Thanks [@webpro](htps://github.com/webpro).
|
||||
* Embed `regenerator`.
|
||||
|
||||
## 1.12.18
|
||||
|
||||
* Use `global` reference instead of `window`.
|
||||
|
||||
## 1.12.17
|
||||
|
||||
* Add `moduleName`, `sourceRoot` and `filenameRelative` options. Thanks [@darvelo](https://github.com/darvelo).
|
||||
* Traversal optimisations.
|
||||
|
||||
## 1.12.16
|
||||
|
||||
* Fix comments not being retained from `MethodDefinition` in classes.
|
||||
* Add temporal dead zone in default parameters.
|
||||
|
||||
## 1.12.15
|
||||
|
||||
* Update `acorn-6to5`.
|
||||
|
||||
## 1.12.14
|
||||
|
||||
* Fix duplicate let scoping in functions.
|
||||
* Make JSX whitespace more React-compliant.
|
||||
* Add `_memberExpressionKeywords` transformer that turns keyword identifiers to computed literals.
|
||||
* Upgrade `regenerator-6to5`.
|
||||
|
||||
## 1.12.13
|
||||
|
||||
* Support duplicate constants within different block scopes.
|
||||
* Fix for-head duplication testing and replacement.
|
||||
* Support `raw` property on tagged template literals.
|
||||
|
||||
## 1.12.12
|
||||
|
||||
* Make scope tracker more reliable to handle all edgecases.
|
||||
|
||||
## 1.12.11
|
||||
|
||||
* Block scope classes.
|
||||
* Fix generation of integer `Literal`s in `MemberExpression`.
|
||||
|
||||
## 1.12.10
|
||||
|
||||
* Fix let scoping var hoisting.
|
||||
|
||||
## 1.12.9
|
||||
|
||||
* Escape unicode characters when generating string `Literal`s.
|
||||
* Fix semicolons being output for statements in `ExportDeclaration`.
|
||||
* Fix `WithStatement` missing parenthesis.
|
||||
|
||||
## 1.12.8
|
||||
|
||||
* Temporarily forbid `AssignmentExpression` destructuring outside of `ExpressionStatement`.
|
||||
|
||||
## 1.12.7
|
||||
|
||||
* Update to latest `acorn-6to5`.
|
||||
|
||||
## 1.12.6
|
||||
|
||||
* Update to latest `acorn-6to5`.
|
||||
|
||||
## 1.12.5
|
||||
|
||||
* Fix excessive whitespace trimming resulting in innaccurate sourcemap line.
|
||||
|
||||
## 1.12.4
|
||||
|
||||
* Add `doc` folder for documentation.
|
||||
|
||||
## 1.12.3
|
||||
|
||||
* Support generator comprehensions.
|
||||
* Use `Array.from` instead of `Array.prototype.slice` in spread transformer.
|
||||
* Support spread in `NewExpression`s.
|
||||
|
||||
## 1.12.2
|
||||
|
||||
* Upgrade `matcha` to `0.6.0` and `browserify` to `6.3.2`.
|
||||
* Add own `trimRight` helper instead of relying on the string instance method.
|
||||
* Support JSX spreads that aren't the first.
|
||||
|
||||
## 1.12.1
|
||||
|
||||
* Fix `this` and `arguments` mapping in the `_aliasFunctions` transformer.
|
||||
|
||||
## 1.12.0
|
||||
|
||||
* Combine `jsx` and `react` transformers to `react`.
|
||||
* Update `react` syntax output to React v0.12.
|
||||
|
||||
## 1.11.15
|
||||
|
||||
* Fix JSX literal whitespace generation.
|
||||
|
||||
## 1.11.14
|
||||
|
||||
* Avoid using a switch for let-scoping continue and break statements and use an if statement instead.
|
||||
* Remove excess whitespace and newlines from JSX literals.
|
||||
|
||||
## 1.11.13
|
||||
|
||||
* Update regenerator-6to5
|
||||
* Add support for most escodegen formatting options
|
||||
* 6to5 is now known as Babel.
|
||||
* Global helpers/runtime has now been given the more descriptive name of "external helpers".
|
||||
|
||||
@@ -1,6 +1,27 @@
|
||||
# Contributing
|
||||
|
||||
Before contributing, please read the [code of conduct](https://github.com/6to5/6to5/blob/master/CODE_OF_CONDUCT.md).
|
||||
Contributions are always welcome, no matter how large or small. Before
|
||||
contributing, please read the
|
||||
[code of conduct](https://github.com/babel/babel/blob/master/CODE_OF_CONDUCT.md).
|
||||
|
||||
**NOTE:** Please do not send pull requests that fix linting issues. It's highly
|
||||
likely that they've already been fixed by the time it's submitted and it just
|
||||
pollutes the git tree.
|
||||
|
||||
## Developing
|
||||
|
||||
#### Workflow
|
||||
|
||||
* Fork the repository
|
||||
* Clone your fork and change directory to it (`git clone git@github.com:yourUserName/babel.git && cd babel`)
|
||||
* Install the project dependencies (`make bootstrap`)
|
||||
* Link your forked clone (`npm link`)
|
||||
* Develop your changes ensuring you're fetching updates from upstream often
|
||||
* Ensure the test are passing (`make test`)
|
||||
* Create new pull request explaining your proposed change or reference an issue
|
||||
in your commit message
|
||||
|
||||
#### Code Standards
|
||||
|
||||
* **General**
|
||||
* No ES6 syntax features or methods, exclusively ES5.
|
||||
|
||||
2
LICENSE
2
LICENSE
@@ -1,4 +1,4 @@
|
||||
Copyright (c) 2014-2015 Sebastian McKenzie
|
||||
Copyright (c) 2014-2015 Sebastian McKenzie <sebmck@gmail.com>
|
||||
|
||||
MIT License
|
||||
|
||||
|
||||
66
Makefile
66
Makefile
@@ -1,26 +1,35 @@
|
||||
BROWSERIFY_CMD = node_modules/browserify/bin/cmd.js
|
||||
ISTANBUL_CMD = node_modules/istanbul/lib/cli.js cover
|
||||
UGLIFY_CMD = node_modules/uglify-js/bin/uglifyjs
|
||||
#UGLIFY_CMD = node_modules/uglify-js/bin/uglifyjs --mangle sort
|
||||
JSHINT_CMD = node_modules/jshint/bin/jshint
|
||||
MOCHA_CMD = node_modules/mocha/bin/_mocha
|
||||
JSCS_CMD = node_modules/jscs/bin/jscs
|
||||
BABEL_CMD = node_modules/babel/bin/babel
|
||||
|
||||
export NODE_ENV = test
|
||||
|
||||
.PHONY: clean test test-cov test-clean lint test-travis test-simple test-all test-browser publish build bootstrap publish-core
|
||||
.PHONY: clean test test-cov test-clean lint test-travis test-simple test-all test-browser publish build bootstrap publish-core publish-runtime build-core watch-core
|
||||
|
||||
build-core:
|
||||
#node $(BABEL_CMD) src --out-dir lib
|
||||
|
||||
watch-core:
|
||||
#node $(BABEL_CMD) src --out-dir lib --watch
|
||||
|
||||
build:
|
||||
mkdir -p dist
|
||||
|
||||
node bin/cache-templates
|
||||
node tools/cache-templates
|
||||
|
||||
node $(BROWSERIFY_CMD) -e lib/6to5/polyfill.js >dist/polyfill.js
|
||||
node $(BROWSERIFY_CMD) -e lib/babel/polyfill.js >dist/polyfill.js
|
||||
node $(UGLIFY_CMD) dist/polyfill.js >dist/polyfill.min.js
|
||||
|
||||
node $(BROWSERIFY_CMD) lib/6to5/browser.js -s to5 >dist/6to5.js
|
||||
node $(UGLIFY_CMD) dist/6to5.js >dist/6to5.min.js
|
||||
node $(BROWSERIFY_CMD) lib/babel/api/browser.js -s babel >dist/babel.js
|
||||
node $(UGLIFY_CMD) dist/babel.js >dist/babel.min.js
|
||||
|
||||
node bin/6to5-runtime >dist/runtime.js
|
||||
node $(UGLIFY_CMD) dist/runtime.js >dist/runtime.min.js
|
||||
node bin/babel-external-helpers >dist/external-helpers.js
|
||||
node $(UGLIFY_CMD) dist/external-helpers.js >dist/external-helpers.min.js
|
||||
|
||||
rm -rf templates.json
|
||||
|
||||
@@ -29,6 +38,7 @@ clean:
|
||||
|
||||
lint:
|
||||
$(JSHINT_CMD) --reporter node_modules/jshint-stylish/stylish.js lib bin
|
||||
$(JSCS_CMD) lib bin
|
||||
|
||||
test-clean:
|
||||
rm -rf test/tmp
|
||||
@@ -39,29 +49,28 @@ test: lint
|
||||
|
||||
test-simple:
|
||||
# excludes test262
|
||||
export SIMPLE_6TO5_TESTS=1
|
||||
export SIMPLE_BABEL_TESTS=1; \
|
||||
make test
|
||||
|
||||
test-all:
|
||||
# includes traceur, esnext, regenerator
|
||||
export ALL_6TO5_TESTS=1
|
||||
export ALL_BABEL_TESTS=1; \
|
||||
make test
|
||||
|
||||
test-cov:
|
||||
export SIMPLE_6TO5_TESTS=1
|
||||
rm -rf coverage
|
||||
export SIMPLE_BABEL_TESTS=1; \
|
||||
node $(ISTANBUL_CMD) $(MOCHA_CMD) --
|
||||
|
||||
test-travis: bootstrap
|
||||
test-travis: build-core bootstrap
|
||||
node $(ISTANBUL_CMD) $(MOCHA_CMD) --
|
||||
if test -n "$$CODECLIMATE_REPO_TOKEN"; then codeclimate < coverage/lcov.info; fi
|
||||
|
||||
test-browser:
|
||||
mkdir -p dist
|
||||
|
||||
node bin/cache-templates
|
||||
node bin/cache-tests
|
||||
node $(BROWSERIFY_CMD) -e test/_browser.js >dist/6to5-test.js
|
||||
node tools/cache-templates
|
||||
node tools/cache-tests
|
||||
node $(BROWSERIFY_CMD) -e test/_browser.js >dist/babel-test.js
|
||||
rm -rf templates.json tests.json
|
||||
|
||||
test -n "`which open`" && open test/browser.html
|
||||
@@ -71,35 +80,44 @@ publish:
|
||||
|
||||
make test
|
||||
|
||||
read -p "Version: " version; \
|
||||
read -p "Version: " version; \
|
||||
npm version $$version --message "v%s"
|
||||
|
||||
make build
|
||||
cp dist/6to5.min.js browser.js
|
||||
cp dist/babel.min.js browser.js
|
||||
cp dist/polyfill.min.js browser-polyfill.js
|
||||
cp dist/runtime.min.js runtime.js
|
||||
cp dist/external-helpers.min.js external-helpers.js
|
||||
|
||||
node bin/cache-templates
|
||||
node tools/cache-templates
|
||||
test -f templates.json
|
||||
|
||||
npm publish
|
||||
|
||||
git push --follow-tags
|
||||
|
||||
# generate
|
||||
bin/generate-core-package-json >package2.json
|
||||
make publish-core
|
||||
make publish-runtime
|
||||
|
||||
rm -rf templates.json browser.js browser-polyfill.js external-helpers.js
|
||||
|
||||
publish-runtime:
|
||||
cd packages; \
|
||||
node build-runtime.js; \
|
||||
cd babel-runtime; \
|
||||
npm publish
|
||||
|
||||
publish-core:
|
||||
tools/generate-core-package-json >package2.json
|
||||
mv package.json .package.json
|
||||
mv package2.json package.json
|
||||
|
||||
npm publish
|
||||
|
||||
# restore
|
||||
rm -rf package.json
|
||||
mv .package.json package.json
|
||||
|
||||
rm -rf templates.json browser.js runtime.js browser-polyfill.js
|
||||
|
||||
bootstrap:
|
||||
npm install
|
||||
git submodule update --init
|
||||
cd vendor/regenerator; npm install
|
||||
cd vendor/compat-table; npm install object-assign
|
||||
|
||||
9
NOTES.md
9
NOTES.md
@@ -1,9 +0,0 @@
|
||||
# Notes
|
||||
|
||||
* Wildcard exports/imports wont normalise if `export default` is a non-object. See [#224](https://github.com/6to5/6to5/issues/224).
|
||||
|
||||
## 3.0.0 breaking changes
|
||||
|
||||
* Remove `allowImportExportEverywhere` option from acorn.
|
||||
* Remove this shorthand from playground.
|
||||
* Remove `super()` inside non-constructors - add descriptive error message.
|
||||
30
README.md
30
README.md
@@ -1,34 +1,12 @@
|
||||
<p align="center">
|
||||
<img alt="6to5" src="https://raw.githubusercontent.com/6to5/logo/master/logo.png" width="546">
|
||||
<img alt="babel" src="https://raw.githubusercontent.com/babel/logo/master/logo.png" width="546">
|
||||
</p>
|
||||
|
||||
<p align="center">
|
||||
<a href="https://gratipay.com/sebmck">
|
||||
<img alt="Gratipay" src="https://img.shields.io/gratipay/sebmck.svg?style=flat">
|
||||
</a>
|
||||
|
||||
<a href="https://travis-ci.org/6to5/6to5">
|
||||
<img alt="Travis Status" src="http://img.shields.io/travis/6to5/6to5/master.svg?style=flat&label=travis">
|
||||
</a>
|
||||
|
||||
<a href="https://codeclimate.com/github/6to5/6to5">
|
||||
<img alt="Code Climate Score" src="http://img.shields.io/codeclimate/github/6to5/6to5.svg?style=flat">
|
||||
</a>
|
||||
|
||||
<a href="https://codeclimate.com/github/6to5/6to5">
|
||||
<img alt="Coverage" src="http://img.shields.io/codeclimate/coverage/github/6to5/6to5.svg?style=flat">
|
||||
</a>
|
||||
|
||||
<a href="https://david-dm.org/6to5/6to5">
|
||||
<img alt="Dependency Status" src="http://img.shields.io/david/6to5/6to5.svg?style=flat">
|
||||
</a>
|
||||
<strong>Babel</strong> is a transpiler for writing next generation JavaScript.
|
||||
</p>
|
||||
|
||||
<p align="center">
|
||||
<strong>6to5</strong> turns ES6+ code into vanilla ES5, so you can use next generation features <strong>today.</strong>
|
||||
</p>
|
||||
|
||||
<p align="center">
|
||||
For more information view the <a href="https://6to5.github.io">documentation</a>. For
|
||||
support visit the <a href="https://gitter.im/6to5/6to5">gitter room</a>.
|
||||
For more information view the <a href="https://babeljs.io/">documentation</a>. For
|
||||
support visit the <a href="https://gitter.im/babel/babel">gitter room</a>.
|
||||
</p>
|
||||
|
||||
17
appveyor.yml
17
appveyor.yml
@@ -1,17 +0,0 @@
|
||||
environment:
|
||||
matrix:
|
||||
- nodejs_version: "0.10"
|
||||
- nodejs_version: "0.11"
|
||||
|
||||
install:
|
||||
- "npm install"
|
||||
- "cinst make"
|
||||
|
||||
test_script:
|
||||
- "node --version"
|
||||
- "npm --version"
|
||||
- "make test-spec"
|
||||
|
||||
build: "off"
|
||||
|
||||
version: "{build}"
|
||||
@@ -1,4 +0,0 @@
|
||||
#!/usr/bin/env node
|
||||
|
||||
var runtime = require("../lib/6to5/runtime-generator");
|
||||
console.log(runtime(process.argv[2]));
|
||||
107
bin/_6to5-node
107
bin/_6to5-node
@@ -1,107 +0,0 @@
|
||||
#!/usr/bin/env node
|
||||
|
||||
var roadrunner = require("roadrunner");
|
||||
var commander = require("commander");
|
||||
var Module = require("module");
|
||||
var path = require("path");
|
||||
var repl = require("repl");
|
||||
var to5 = require("../lib/6to5");
|
||||
var util = require("../lib/6to5/util");
|
||||
var vm = require("vm");
|
||||
var _ = require("lodash");
|
||||
|
||||
commander.option("-e, --eval [script]", "Evaluate script");
|
||||
commander.option("-p, --print", "Evaluate script and print result");
|
||||
commander.option("-i, --ignore [regex]", "Ignore all files that match this regex when using the require hook");
|
||||
commander.option("-x, --extensions [extensions]", "List of extensions to hook into [.es6,.js]");
|
||||
commander.option("-r, --experimental", "Enable experimental support for proposed ES7 features");
|
||||
commander.option("-g, --playground", "Enable playground support");
|
||||
commander.option("-c, --cache", "Cache compiled files and require paths");
|
||||
|
||||
var pkg = require("../package.json");
|
||||
commander.version(pkg.version);
|
||||
commander.usage("[options] [ -e script | script.js ] [arguments]");
|
||||
commander.parse(process.argv);
|
||||
|
||||
if (commander.cache) roadrunner.load();
|
||||
|
||||
//
|
||||
|
||||
to5.register({
|
||||
experimental: commander.experimental,
|
||||
extensions: commander.extensions,
|
||||
playground: commander.playground,
|
||||
ignore: commander.ignore,
|
||||
cache: commander.cache && roadrunner.get("6to5")
|
||||
});
|
||||
|
||||
//
|
||||
|
||||
var _eval = function (code, filename) {
|
||||
code = to5.transform(code, {
|
||||
filename: filename,
|
||||
blacklist: ["useStrict"],
|
||||
experimental: commander.experimental,
|
||||
playground: commander.playground
|
||||
}).code;
|
||||
return vm.runInThisContext(code, filename);
|
||||
};
|
||||
|
||||
if (commander.eval) {
|
||||
var result = _eval(commander.eval, "eval");
|
||||
if (commander.print) console.log(result);
|
||||
} else {
|
||||
if (commander.args.length) {
|
||||
// slice all arguments up to the first filename since they're 6to5 args that we handle
|
||||
var args = process.argv.slice(2);
|
||||
|
||||
var i = 0;
|
||||
_.each(args, function (arg, i2) {
|
||||
if (arg[0] !== "-") {
|
||||
i = i2;
|
||||
return false;
|
||||
}
|
||||
});
|
||||
args = args.slice(i);
|
||||
|
||||
// make the filename absolute
|
||||
var filename = args[0]
|
||||
if (!util.isAbsolute(filename)) args[0] = path.join(process.cwd(), filename);
|
||||
|
||||
// add back on node and concat the sliced args
|
||||
process.argv = ["node"].concat(args);
|
||||
|
||||
Module.runMain();
|
||||
} else {
|
||||
replStart();
|
||||
}
|
||||
}
|
||||
|
||||
if (commander.cache) roadrunner.save();
|
||||
|
||||
function replStart() {
|
||||
repl.start({
|
||||
prompt: "> ",
|
||||
input: process.stdin,
|
||||
output: process.stdout,
|
||||
eval: replEval,
|
||||
useGlobal: true
|
||||
});
|
||||
}
|
||||
|
||||
function replEval(code, context, filename, callback) {
|
||||
var err;
|
||||
var result;
|
||||
|
||||
try {
|
||||
if (/^\((.*?)\n\)$/.test(code)) {
|
||||
code = code.slice(1, -2); // remove "(" and "\n)"
|
||||
}
|
||||
|
||||
result = _eval(code, filename);
|
||||
} catch (e) {
|
||||
err = e;
|
||||
}
|
||||
|
||||
callback(err, result);
|
||||
}
|
||||
125
bin/_babel-node
Normal file
125
bin/_babel-node
Normal file
@@ -0,0 +1,125 @@
|
||||
#!/usr/bin/env node
|
||||
|
||||
var pathIsAbsolute = require("path-is-absolute");
|
||||
var commander = require("commander");
|
||||
var Module = require("module");
|
||||
var babel = require("../lib/babel/api/node");
|
||||
var path = require("path");
|
||||
var repl = require("repl");
|
||||
var util = require("../lib/babel/util");
|
||||
var vm = require("vm");
|
||||
var _ = require("lodash");
|
||||
|
||||
var program = new commander.Command("babel-node");
|
||||
|
||||
program.option("-e, --eval [script]", "Evaluate script");
|
||||
program.option("-p, --print [code]", "Evaluate script and print result");
|
||||
program.option("-i, --ignore [regex]", "Ignore all files that match this regex when using the require hook");
|
||||
program.option("-x, --extensions [extensions]", "List of extensions to hook into [.es6,.js,.es,.jsx]");
|
||||
program.option("-r, --experimental", "Enable experimental support for proposed ES7 features");
|
||||
program.option("-g, --playground", "Enable playground support");
|
||||
program.option("-w, --whitelist [whitelist]", "Whitelist of transformers to ONLY use", util.list);
|
||||
program.option("-b, --blacklist [blacklist]", "Blacklist of transformers to NOT use", util.list);
|
||||
program.option("-o, --optional [optional]", "List of optional transformers to enable", util.list);
|
||||
|
||||
var pkg = require("../package.json");
|
||||
program.version(pkg.version);
|
||||
program.usage("[options] [ -e script | script.js ] [arguments]");
|
||||
program.parse(process.argv);
|
||||
|
||||
//
|
||||
|
||||
babel.register({
|
||||
experimental: program.experimental,
|
||||
extensions: program.extensions,
|
||||
playground: program.playground,
|
||||
blacklist: program.blacklist,
|
||||
whitelist: program.whitelist,
|
||||
optional: program.optional,
|
||||
ignore: program.ignore
|
||||
});
|
||||
|
||||
//
|
||||
|
||||
var _eval = function (code, filename) {
|
||||
code = babel.transform(code, {
|
||||
filename: filename,
|
||||
blacklist: ["useStrict"].concat(program.blacklist || []),
|
||||
whitelist: program.whitelist,
|
||||
optional: program.optional,
|
||||
experimental: program.experimental,
|
||||
playground: program.playground
|
||||
}).code;
|
||||
return vm.runInThisContext(code, filename);
|
||||
};
|
||||
|
||||
if (program.eval || program.print) {
|
||||
var code = program.eval;
|
||||
if (!code || code === true) code = program.print;
|
||||
|
||||
var result = _eval(code, "eval");
|
||||
if (program.print) console.log(result);
|
||||
} else {
|
||||
if (program.args.length) {
|
||||
// slice all arguments up to the first filename since they're babel args that we handle
|
||||
var args = process.argv.slice(2);
|
||||
|
||||
var i = 0;
|
||||
var ignoreNext = false;
|
||||
_.each(args, function (arg, i2) {
|
||||
if (ignoreNext) {
|
||||
ignoreNext = false;
|
||||
return;
|
||||
}
|
||||
|
||||
if (arg[0] === "-") {
|
||||
var parsedArg = program[arg.slice(2)];
|
||||
if (parsedArg && parsedArg !== true) {
|
||||
ignoreNext = true;
|
||||
}
|
||||
} else {
|
||||
i = i2;
|
||||
return false;
|
||||
}
|
||||
});
|
||||
args = args.slice(i);
|
||||
|
||||
// make the filename absolute
|
||||
var filename = args[0]
|
||||
if (!pathIsAbsolute(filename)) args[0] = path.join(process.cwd(), filename);
|
||||
|
||||
// add back on node and concat the sliced args
|
||||
process.argv = ["node"].concat(args);
|
||||
|
||||
Module.runMain();
|
||||
} else {
|
||||
replStart();
|
||||
}
|
||||
}
|
||||
|
||||
function replStart() {
|
||||
repl.start({
|
||||
prompt: "> ",
|
||||
input: process.stdin,
|
||||
output: process.stdout,
|
||||
eval: replEval,
|
||||
useGlobal: true
|
||||
});
|
||||
}
|
||||
|
||||
function replEval(code, context, filename, callback) {
|
||||
var err;
|
||||
var result;
|
||||
|
||||
try {
|
||||
if (code[0] === "(" && code[code.length - 1] === ")") {
|
||||
code = code.slice(1, -1); // remove "(" and ")"
|
||||
}
|
||||
|
||||
result = _eval(code, filename);
|
||||
} catch (e) {
|
||||
err = e;
|
||||
}
|
||||
|
||||
callback(err, result);
|
||||
}
|
||||
4
bin/babel-external-helpers
Executable file
4
bin/babel-external-helpers
Executable file
@@ -0,0 +1,4 @@
|
||||
#!/usr/bin/env node
|
||||
|
||||
var runtime = require("../lib/babel/build-external-helpers");
|
||||
console.log(runtime());
|
||||
7
bin/babel-minify
Executable file
7
bin/babel-minify
Executable file
@@ -0,0 +1,7 @@
|
||||
#!/usr/bin/env node
|
||||
|
||||
var opts = require("./babel").opts;
|
||||
opts.optional = (opts.optional || []).concat("minification");
|
||||
opts.format = {
|
||||
compact: true
|
||||
};
|
||||
@@ -2,10 +2,10 @@
|
||||
|
||||
/**
|
||||
* This tiny wrapper file checks for known node flags and appends them
|
||||
* when found, before invoking the "real" _6to5-node(1) executable.
|
||||
* when found, before invoking the "real" _babel-node(1) executable.
|
||||
*/
|
||||
|
||||
var args = ["--harmony", __dirname + "/_6to5-node"];
|
||||
var args = [__dirname + "/_babel-node"];
|
||||
|
||||
process.argv.slice(2).forEach(function(arg){
|
||||
var flag = arg.split("=")[0];
|
||||
@@ -35,6 +35,7 @@ process.argv.slice(2).forEach(function(arg){
|
||||
case "--prof":
|
||||
case "--throw-deprecation":
|
||||
case "--trace-deprecation":
|
||||
case "--use-strict":
|
||||
args.unshift(arg);
|
||||
break;
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
var chokidar = require("chokidar");
|
||||
var mkdirp = require("mkdirp");
|
||||
var path = require("path");
|
||||
var util = require("./util");
|
||||
var fs = require("fs");
|
||||
var _ = require("lodash");
|
||||
var outputFileSync = require("output-file-sync");
|
||||
var chokidar = require("chokidar");
|
||||
var path = require("path");
|
||||
var util = require("./util");
|
||||
var fs = require("fs");
|
||||
var _ = require("lodash");
|
||||
|
||||
module.exports = function (commander, filenames, opts) {
|
||||
if (commander.sourceMapsInline) {
|
||||
@@ -11,20 +11,22 @@ module.exports = function (commander, filenames, opts) {
|
||||
}
|
||||
|
||||
var write = function (src, relative) {
|
||||
// remove extension and then append back on .js
|
||||
relative = relative.replace(/\.(\w*?)$/, "") + ".js";
|
||||
|
||||
var dest = path.join(commander.outDir, relative);
|
||||
|
||||
var data = util.compile(src, { sourceMapName: dest });
|
||||
|
||||
var up = path.normalize(dest + "/..");
|
||||
mkdirp.sync(up);
|
||||
var data = util.compile(src, {
|
||||
sourceFileName: path.relative(dest + "/..", src)
|
||||
});
|
||||
|
||||
if (commander.sourceMaps) {
|
||||
var mapLoc = dest + ".map";
|
||||
data.code = util.addSourceMappingUrl(data.code, mapLoc);
|
||||
fs.writeFileSync(mapLoc, JSON.stringify(data.map));
|
||||
outputFileSync(mapLoc, JSON.stringify(data.map));
|
||||
}
|
||||
|
||||
fs.writeFileSync(dest, data.code);
|
||||
outputFileSync(dest, data.code);
|
||||
|
||||
console.log(src + " -> " + dest);
|
||||
};
|
||||
@@ -37,8 +39,13 @@ module.exports = function (commander, filenames, opts) {
|
||||
if (stat.isDirectory(filename)) {
|
||||
var dirname = filename;
|
||||
|
||||
_.each(util.readdirFilter(dirname), function (filename) {
|
||||
write(path.join(dirname, filename), filename);
|
||||
_.each(util.readdir(dirname), function (filename) {
|
||||
var src = path.join(dirname, filename);
|
||||
if (util.canCompile(filename)) {
|
||||
write(src, filename);
|
||||
} else {
|
||||
outputFileSync(path.join(commander.outDir, filename), fs.readFileSync(src));
|
||||
}
|
||||
});
|
||||
} else {
|
||||
write(filename, filename);
|
||||
@@ -54,12 +61,9 @@ module.exports = function (commander, filenames, opts) {
|
||||
ignoreInitial: true
|
||||
});
|
||||
|
||||
_.each(["add", "change", "unlink"], function (type) {
|
||||
_.each(["add", "change"], function (type) {
|
||||
watcher.on(type, function (filename) {
|
||||
// chop off the dirname plus the path separator
|
||||
var relative = filename.slice(dirname.length + 1);
|
||||
|
||||
console.log(type, filename);
|
||||
var relative = path.relative(dirname, filename) || filename;
|
||||
write(filename, relative);
|
||||
});
|
||||
});
|
||||
@@ -1,10 +1,10 @@
|
||||
var sourceMap = require("source-map");
|
||||
var chokidar = require("chokidar");
|
||||
var util2 = require("../../lib/6to5/util");
|
||||
var path = require("path");
|
||||
var util = require("./util");
|
||||
var fs = require("fs");
|
||||
var _ = require("lodash");
|
||||
var sourceMapToComment = require("source-map-to-comment");
|
||||
var sourceMap = require("source-map");
|
||||
var chokidar = require("chokidar");
|
||||
var path = require("path");
|
||||
var util = require("./util");
|
||||
var fs = require("fs");
|
||||
var _ = require("lodash");
|
||||
|
||||
module.exports = function (commander, filenames) {
|
||||
var results = [];
|
||||
@@ -28,7 +28,7 @@ module.exports = function (commander, filenames) {
|
||||
map.setSourceContent(filename, result.actual);
|
||||
|
||||
consumer.eachMapping(function (mapping) {
|
||||
map._mappings.push({
|
||||
map._mappings.add({
|
||||
generatedLine: mapping.generatedLine + offset,
|
||||
generatedColumn: mapping.generatedColumn,
|
||||
originalLine: mapping.originalLine,
|
||||
@@ -42,7 +42,7 @@ module.exports = function (commander, filenames) {
|
||||
});
|
||||
|
||||
if (commander.sourceMapsInline || (!commander.outFile && commander.sourceMaps)) {
|
||||
code += "\n" + util2.sourceMapToComment(map);
|
||||
code += "\n" + sourceMapToComment(map);
|
||||
}
|
||||
|
||||
return {
|
||||
@@ -63,7 +63,7 @@ module.exports = function (commander, filenames) {
|
||||
|
||||
fs.writeFileSync(commander.outFile, result.code);
|
||||
} else {
|
||||
console.log(result.code);
|
||||
process.stdout.write(result.code + "\n");
|
||||
}
|
||||
};
|
||||
|
||||
@@ -77,7 +77,7 @@ module.exports = function (commander, filenames) {
|
||||
if (chunk !== null) code += chunk;
|
||||
});
|
||||
|
||||
process.stdin.on("end", function() {
|
||||
process.stdin.on("end", function () {
|
||||
results.push(util.transform(commander.filename, code));
|
||||
output();
|
||||
});
|
||||
@@ -117,7 +117,7 @@ module.exports = function (commander, filenames) {
|
||||
persistent: true,
|
||||
ignoreInitial: true
|
||||
}).on("all", function (type, filename) {
|
||||
if (type === "add" || type === "change" || type === "unlink" ) {
|
||||
if (type === "add" || type === "change") {
|
||||
console.log(type, filename);
|
||||
walk();
|
||||
}
|
||||
@@ -1,42 +1,42 @@
|
||||
#!/usr/bin/env node
|
||||
|
||||
var commander = require("commander");
|
||||
var transform = require("../../lib/6to5/transformation/transform");
|
||||
var util = require("../../lib/6to5/util");
|
||||
var transform = require("../../lib/babel/transformation");
|
||||
var util = require("../../lib/babel/util");
|
||||
var fs = require("fs");
|
||||
var _ = require("lodash");
|
||||
var each = require("lodash/collection/each");
|
||||
var keys = require("lodash/object/keys");
|
||||
|
||||
commander.option("-t, --source-maps-inline", "Append sourceMappingURL comment to bottom of code");
|
||||
commander.option("-s, --source-maps", "Save source map alongside the compiled code");
|
||||
commander.option("-f, --filename [filename]", "Filename to use when reading from stdin - this will be used in source-maps, errors etc [stdin]", "stdin");
|
||||
commander.option("-w, --watch", "Recompile files on changes");
|
||||
commander.option("-r, --runtime", "Replace 6to5 declarations with references to a runtime");
|
||||
commander.option("-r, --external-helpers", "Replace helpers with references to a `babelHelpers` global");
|
||||
commander.option("-e, --experimental", "Enable experimental support for proposed ES7 features");
|
||||
commander.option("-p, --playground", "Enable playground support");
|
||||
|
||||
commander.option("-m, --modules [modules]", "Module formatter type to use [common]", "common");
|
||||
commander.option("-w, --whitelist [whitelist]", "Whitelist of transformers to ONLY use", util.list);
|
||||
commander.option("-l, --whitelist [whitelist]", "Whitelist of transformers to ONLY use", util.list);
|
||||
commander.option("-b, --blacklist [blacklist]", "Blacklist of transformers to NOT use", util.list);
|
||||
commander.option("-i, --optional [list]", "List of optional transformers to enable", util.list);
|
||||
commander.option("-L, --loose [list]", "List of transformers to enable loose mode ON", util.list);
|
||||
commander.option("-o, --out-file [out]", "Compile all input files into a single file");
|
||||
commander.option("-d, --out-dir [out]", "Compile an input directory of modules into an output directory");
|
||||
commander.option("-c, --remove-comments", "Remove comments from the compiled code", false);
|
||||
commander.option("-I, --indent [width]", "Indent width [2]", 2);
|
||||
commander.option("-a, --amd-module-ids", "Insert module id in AMD modules", false); // todo: remove in 3.0.0
|
||||
commander.option("-m, --module-ids", "Insert module id in modules", false);
|
||||
commander.option("-M, --module-ids", "Insert module id in modules", false);
|
||||
commander.option("-R, --react-compat", "Makes the react transformer produce pre-v0.12 code");
|
||||
commander.option("--keep-module-id-extensions", "Keep extensions when generating module ids", false);
|
||||
commander.option("-a, --auxiliary-comment [comment]", "Comment text to prepend to all auxiliary code");
|
||||
|
||||
commander.on("--help", function(){
|
||||
commander.on("--help", function () {
|
||||
var outKeys = function (title, obj) {
|
||||
console.log(" " + title + ":");
|
||||
console.log();
|
||||
|
||||
var hasOptional = true;
|
||||
|
||||
_.each(_.keys(obj).sort(), function (key) {
|
||||
each(keys(obj).sort(), function (key) {
|
||||
if (key[0] === "_") return;
|
||||
|
||||
if (obj[key].optional) {
|
||||
hasOptional = true;
|
||||
key = "[" + key + "]";
|
||||
}
|
||||
|
||||
@@ -61,7 +61,7 @@ var errors = [];
|
||||
|
||||
var filenames = commander.args;
|
||||
|
||||
_.each(filenames, function (filename) {
|
||||
each(filenames, function (filename) {
|
||||
if (!fs.existsSync(filename)) {
|
||||
errors.push(filename + " doesn't exist");
|
||||
}
|
||||
@@ -99,30 +99,34 @@ if (errors.length) {
|
||||
//
|
||||
|
||||
exports.opts = {
|
||||
sourceMapName: commander.outFile,
|
||||
experimental: commander.experimental,
|
||||
playground: commander.playground,
|
||||
moduleIds: commander.amdModuleIds || commander.moduleIds,
|
||||
blacklist: commander.blacklist,
|
||||
whitelist: commander.whitelist,
|
||||
sourceMap: commander.sourceMaps || commander.sourceMapsInline,
|
||||
optional: commander.optional,
|
||||
comments: !commander.removeComments,
|
||||
runtime: commander.runtime,
|
||||
modules: commander.modules,
|
||||
format: {
|
||||
indent: {
|
||||
style: util.repeat(parseInt(commander.indent))
|
||||
}
|
||||
}
|
||||
keepModuleIdExtensions: commander.keepModuleIdExtensions,
|
||||
auxiliaryComment: commander.auxiliaryComment,
|
||||
externalHelpers: commander.externalHelpers,
|
||||
sourceMapName: commander.outFile,
|
||||
experimental: commander.experimental,
|
||||
reactCompat: commander.reactCompat,
|
||||
playground: commander.playground,
|
||||
moduleIds: commander.moduleIds,
|
||||
blacklist: commander.blacklist,
|
||||
whitelist: commander.whitelist,
|
||||
sourceMap: commander.sourceMaps || commander.sourceMapsInline,
|
||||
optional: commander.optional,
|
||||
comments: !commander.removeComments,
|
||||
modules: commander.modules,
|
||||
loose: commander.loose
|
||||
};
|
||||
|
||||
var fn;
|
||||
setTimeout(function () {
|
||||
// this is just a hack to give `babel-minify` and other files including this
|
||||
// time to modify `exports.opts`
|
||||
|
||||
if (commander.outDir) {
|
||||
fn = require("./dir");
|
||||
} else {
|
||||
fn = require("./file");
|
||||
}
|
||||
var fn;
|
||||
|
||||
fn(commander, filenames, exports.opts);
|
||||
if (commander.outDir) {
|
||||
fn = require("./dir");
|
||||
} else {
|
||||
fn = require("./file");
|
||||
}
|
||||
|
||||
fn(commander, filenames, exports.opts);
|
||||
}, 0);
|
||||
@@ -1,8 +1,8 @@
|
||||
var readdir = require("fs-readdir-recursive");
|
||||
var index = require("./index");
|
||||
var util = require("../../lib/6to5/util");
|
||||
var babel = require("../../lib/babel/api/node");
|
||||
var util = require("../../lib/babel/util");
|
||||
var path = require("path");
|
||||
var to5 = require("../../lib/6to5");
|
||||
var fs = require("fs");
|
||||
var _ = require("lodash");
|
||||
|
||||
@@ -12,15 +12,29 @@ exports.readdirFilter = function (filename) {
|
||||
});
|
||||
};
|
||||
|
||||
exports.readdir = readdir;
|
||||
|
||||
exports.canCompile = util.canCompile;
|
||||
|
||||
exports.addSourceMappingUrl = function (code, loc) {
|
||||
return code + "\n//# sourceMappingURL=" + path.basename(loc);
|
||||
};
|
||||
|
||||
exports.transform = function (filename, code, opts) {
|
||||
opts = _.extend(opts || {}, index.opts);
|
||||
opts = _.defaults(opts || {}, index.opts);
|
||||
opts.filename = filename;
|
||||
|
||||
var result = to5.transform(code, opts);
|
||||
var result;
|
||||
try {
|
||||
result = babel.transform(code, opts);
|
||||
} catch (e) {
|
||||
if (e instanceof SyntaxError) {
|
||||
console.error("SyntaxError:", e.message);
|
||||
process.exit(1);
|
||||
} else {
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
result.filename = filename;
|
||||
result.actual = code;
|
||||
return result;
|
||||
3
bin/deprecated/6to5
Executable file
3
bin/deprecated/6to5
Executable file
@@ -0,0 +1,3 @@
|
||||
#!/usr/bin/env node
|
||||
console.error("`6to5` has been renamed to `babel`");
|
||||
require("../babel");
|
||||
3
bin/deprecated/6to5-minify
Executable file
3
bin/deprecated/6to5-minify
Executable file
@@ -0,0 +1,3 @@
|
||||
#!/usr/bin/env node
|
||||
console.error("`6to5-minify` has been renamed to `babel-minify`");
|
||||
require("../babel-minify");
|
||||
3
bin/deprecated/6to5-node
Executable file
3
bin/deprecated/6to5-node
Executable file
@@ -0,0 +1,3 @@
|
||||
#!/usr/bin/env node
|
||||
console.error("`6to5-node` has been renamed to `babel-node`");
|
||||
require("../_babel-node");
|
||||
3
bin/deprecated/6to5-runtime
Executable file
3
bin/deprecated/6to5-runtime
Executable file
@@ -0,0 +1,3 @@
|
||||
#!/usr/bin/env node
|
||||
console.error("`6to5-runtime` has been renamed to `babel-external-helpers`");
|
||||
require("../babel-external-helpers");
|
||||
@@ -1 +1 @@
|
||||
See [6to5.github.io/docs](https://github.com/6to5/6to5.github.io/tree/master/docs).
|
||||
See [babel.github.io/docs](https://github.com/babel/babel.github.io/tree/master/docs).
|
||||
|
||||
316
lib/6to5/file.js
316
lib/6to5/file.js
@@ -1,316 +0,0 @@
|
||||
module.exports = File;
|
||||
|
||||
var SHEBANG_REGEX = /^\#\!.*/;
|
||||
|
||||
var transform = require("./transformation/transform");
|
||||
var generate = require("./generation/generator");
|
||||
var Scope = require("./traverse/scope");
|
||||
var util = require("./util");
|
||||
var t = require("./types");
|
||||
var _ = require("lodash");
|
||||
|
||||
function File(opts) {
|
||||
this.dynamicImports = [];
|
||||
this.dynamicImportIds = {};
|
||||
this.opts = File.normaliseOptions(opts);
|
||||
this.transformers = this.getTransformers();
|
||||
this.uids = {};
|
||||
this.ast = {};
|
||||
}
|
||||
|
||||
File.helpers = [
|
||||
"inherits",
|
||||
"defaults",
|
||||
"prototype-properties",
|
||||
"apply-constructor",
|
||||
"tagged-template-literal",
|
||||
"interop-require",
|
||||
"to-array",
|
||||
"sliced-to-array",
|
||||
"object-without-properties",
|
||||
"has-own",
|
||||
"slice",
|
||||
"bind",
|
||||
"define-property",
|
||||
"async-to-generator",
|
||||
"interop-require-wildcard",
|
||||
"typeof",
|
||||
"extends",
|
||||
"get"
|
||||
];
|
||||
|
||||
File.excludeHelpersFromRuntime = [
|
||||
"async-to-generator",
|
||||
"typeof"
|
||||
];
|
||||
|
||||
File.normaliseOptions = function (opts) {
|
||||
opts = _.cloneDeep(opts || {});
|
||||
|
||||
_.defaults(opts, {
|
||||
experimental: false,
|
||||
reactCompat: false,
|
||||
playground: false,
|
||||
whitespace: true,
|
||||
moduleIds: opts.amdModuleIds || false,
|
||||
blacklist: [],
|
||||
whitelist: [],
|
||||
sourceMap: false,
|
||||
optional: [],
|
||||
comments: true,
|
||||
filename: "unknown",
|
||||
modules: "common",
|
||||
runtime: false,
|
||||
code: true,
|
||||
ast: true
|
||||
});
|
||||
|
||||
// normalise windows path separators to unix
|
||||
opts.filename = opts.filename.replace(/\\/g, "/");
|
||||
|
||||
opts.blacklist = util.arrayify(opts.blacklist);
|
||||
opts.whitelist = util.arrayify(opts.whitelist);
|
||||
|
||||
_.defaults(opts, {
|
||||
moduleRoot: opts.sourceRoot
|
||||
});
|
||||
|
||||
_.defaults(opts, {
|
||||
sourceRoot: opts.moduleRoot
|
||||
});
|
||||
|
||||
_.defaults(opts, {
|
||||
filenameRelative: opts.filename
|
||||
});
|
||||
|
||||
_.defaults(opts, {
|
||||
sourceFileName: opts.filenameRelative,
|
||||
sourceMapName: opts.filenameRelative
|
||||
});
|
||||
|
||||
if (opts.runtime === true) {
|
||||
opts.runtime = "to5Runtime";
|
||||
}
|
||||
|
||||
if (opts.playground) {
|
||||
opts.experimental = true;
|
||||
}
|
||||
|
||||
transform._ensureTransformerNames("blacklist", opts.blacklist);
|
||||
transform._ensureTransformerNames("whitelist", opts.whitelist);
|
||||
transform._ensureTransformerNames("optional", opts.optional);
|
||||
|
||||
return opts;
|
||||
};
|
||||
|
||||
File.prototype.getTransformers = function () {
|
||||
var file = this;
|
||||
var transformers = [];
|
||||
var secondPassTransformers = [];
|
||||
|
||||
_.each(transform.transformers, function (transformer) {
|
||||
if (transformer.canRun(file)) {
|
||||
transformers.push(transformer);
|
||||
|
||||
if (transformer.secondPass) {
|
||||
secondPassTransformers.push(transformer);
|
||||
}
|
||||
|
||||
if (transformer.manipulateOptions) {
|
||||
transformer.manipulateOptions(file.opts, file);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
return transformers.concat(secondPassTransformers);
|
||||
};
|
||||
|
||||
File.prototype.toArray = function (node, i) {
|
||||
if (t.isArrayExpression(node)) {
|
||||
return node;
|
||||
} else if (t.isIdentifier(node) && node.name === "arguments") {
|
||||
return t.callExpression(t.memberExpression(this.addHelper("slice"), t.identifier("call")), [node]);
|
||||
} else {
|
||||
var declarationName = "to-array";
|
||||
var args = [node];
|
||||
if (i) {
|
||||
args.push(t.literal(i));
|
||||
declarationName = "sliced-to-array";
|
||||
}
|
||||
return t.callExpression(this.addHelper(declarationName), args);
|
||||
}
|
||||
};
|
||||
|
||||
File.prototype.getModuleFormatter = function (type) {
|
||||
var ModuleFormatter = _.isFunction(type) ? type : transform.moduleFormatters[type];
|
||||
|
||||
if (!ModuleFormatter) {
|
||||
var loc = util.resolve(type);
|
||||
if (loc) ModuleFormatter = require(loc);
|
||||
}
|
||||
|
||||
if (!ModuleFormatter) {
|
||||
throw new ReferenceError("Unknown module formatter type " + JSON.stringify(type));
|
||||
}
|
||||
|
||||
return new ModuleFormatter(this);
|
||||
};
|
||||
|
||||
File.prototype.parseShebang = function (code) {
|
||||
var shebangMatch = code.match(SHEBANG_REGEX);
|
||||
if (shebangMatch) {
|
||||
this.shebang = shebangMatch[0];
|
||||
|
||||
// remove shebang
|
||||
code = code.replace(SHEBANG_REGEX, "");
|
||||
}
|
||||
|
||||
return code;
|
||||
};
|
||||
|
||||
File.prototype.addImport = function (source, name) {
|
||||
name = name || source;
|
||||
var id = this.dynamicImportIds[name];
|
||||
|
||||
if (!id) {
|
||||
id = this.dynamicImportIds[name] = this.generateUidIdentifier(name);
|
||||
|
||||
var specifiers = [t.importSpecifier(t.identifier("default"), id)];
|
||||
var declar = t.importDeclaration(specifiers, t.literal(source));
|
||||
declar._blockHoist = 3;
|
||||
this.dynamicImports.push(declar);
|
||||
}
|
||||
|
||||
return id;
|
||||
};
|
||||
|
||||
File.prototype.addHelper = function (name) {
|
||||
if (!_.contains(File.helpers, name)) {
|
||||
throw new ReferenceError("unknown declaration " + name);
|
||||
}
|
||||
|
||||
var program = this.ast.program;
|
||||
|
||||
var declar = program._declarations && program._declarations[name];
|
||||
if (declar) return declar.id;
|
||||
|
||||
var ref;
|
||||
var runtimeNamespace = this.opts.runtime;
|
||||
if (runtimeNamespace && !_.contains(File.excludeHelpersFromRuntime, name)) {
|
||||
name = t.identifier(t.toIdentifier(name));
|
||||
return t.memberExpression(t.identifier(runtimeNamespace), name);
|
||||
} else {
|
||||
ref = util.template(name);
|
||||
}
|
||||
|
||||
var uid = this.generateUidIdentifier(name);
|
||||
this.scope.push({
|
||||
key: name,
|
||||
id: uid,
|
||||
init: ref
|
||||
});
|
||||
return uid;
|
||||
};
|
||||
|
||||
File.prototype.errorWithNode = function (node, msg, Error) {
|
||||
Error = Error || SyntaxError;
|
||||
|
||||
var loc = node.loc.start;
|
||||
var err = new Error("Line " + loc.line + ": " + msg);
|
||||
err.loc = loc;
|
||||
return err;
|
||||
};
|
||||
|
||||
File.prototype.addCode = function (code) {
|
||||
code = (code || "") + "";
|
||||
this.code = code;
|
||||
return this.parseShebang(code);
|
||||
};
|
||||
|
||||
File.prototype.parse = function (code) {
|
||||
var self = this;
|
||||
|
||||
code = this.addCode(code);
|
||||
|
||||
return util.parse(this.opts, code, function (tree) {
|
||||
self.transform(tree);
|
||||
return self.generate();
|
||||
});
|
||||
};
|
||||
|
||||
File.prototype.transform = function (ast) {
|
||||
var self = this;
|
||||
|
||||
this.ast = ast;
|
||||
this.scope = new Scope(ast.program);
|
||||
this.moduleFormatter = this.getModuleFormatter(this.opts.modules);
|
||||
|
||||
var astRun = function (key) {
|
||||
_.each(self.transformers, function (transformer) {
|
||||
transformer.astRun(self, key);
|
||||
});
|
||||
};
|
||||
|
||||
astRun("enter");
|
||||
|
||||
_.each(this.transformers, function (transformer) {
|
||||
transformer.transform(self);
|
||||
});
|
||||
|
||||
astRun("exit");
|
||||
};
|
||||
|
||||
File.prototype.generate = function () {
|
||||
var opts = this.opts;
|
||||
var ast = this.ast;
|
||||
|
||||
var result = {
|
||||
code: "",
|
||||
map: null,
|
||||
ast: null
|
||||
};
|
||||
|
||||
if (opts.ast) result.ast = ast;
|
||||
if (!opts.code) return result;
|
||||
|
||||
var _result = generate(ast, opts, this.code);
|
||||
result.code = _result.code;
|
||||
result.map = _result.map;
|
||||
|
||||
if (this.shebang) {
|
||||
// add back shebang
|
||||
result.code = this.shebang + "\n" + result.code;
|
||||
}
|
||||
|
||||
if (opts.sourceMap === "inline") {
|
||||
result.code += "\n" + util.sourceMapToComment(result.map);
|
||||
}
|
||||
|
||||
return result;
|
||||
};
|
||||
|
||||
File.prototype.generateUid = function (name, scope) {
|
||||
name = t.toIdentifier(name).replace(/^_+/, "");
|
||||
|
||||
scope = scope || this.scope;
|
||||
|
||||
var uid;
|
||||
do {
|
||||
uid = this._generateUid(name);
|
||||
} while (scope.has(uid));
|
||||
return uid;
|
||||
};
|
||||
|
||||
File.prototype.generateUidIdentifier = function (name, scope) {
|
||||
return t.identifier(this.generateUid(name, scope));
|
||||
};
|
||||
|
||||
File.prototype._generateUid = function (name) {
|
||||
var uids = this.uids;
|
||||
var i = uids[name] || 1;
|
||||
|
||||
var id = name;
|
||||
if (i > 1) id += i;
|
||||
uids[name] = i + 1;
|
||||
return "_" + id;
|
||||
};
|
||||
@@ -1,3 +0,0 @@
|
||||
exports.ClassProperty = function () {
|
||||
throw new Error("not implemented");
|
||||
};
|
||||
@@ -1,33 +0,0 @@
|
||||
module.exports = Position;
|
||||
|
||||
var _ = require("lodash");
|
||||
|
||||
function Position() {
|
||||
this.line = 1;
|
||||
this.column = 0;
|
||||
}
|
||||
|
||||
Position.prototype.push = function (str) {
|
||||
var self = this;
|
||||
|
||||
_.each(str, function (cha) {
|
||||
if (cha === "\n") {
|
||||
self.line++;
|
||||
self.column = 0;
|
||||
} else {
|
||||
self.column++;
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
Position.prototype.unshift = function (str) {
|
||||
var self = this;
|
||||
|
||||
_.each(str, function (cha) {
|
||||
if (cha === "\n") {
|
||||
self.line--;
|
||||
} else {
|
||||
self.column--;
|
||||
}
|
||||
});
|
||||
};
|
||||
@@ -1,62 +0,0 @@
|
||||
module.exports = Whitespace;
|
||||
|
||||
var _ = require("lodash");
|
||||
|
||||
function Whitespace(tokens, comments) {
|
||||
this.tokens = _.sortBy(tokens.concat(comments), "start");
|
||||
this.used = [];
|
||||
}
|
||||
|
||||
Whitespace.prototype.getNewlinesBefore = function (node) {
|
||||
var startToken;
|
||||
var endToken;
|
||||
var tokens = this.tokens;
|
||||
|
||||
_.each(tokens, function (token, i) {
|
||||
// this is the token this node starts with
|
||||
if (node.start === token.start) {
|
||||
startToken = tokens[i - 1];
|
||||
endToken = token;
|
||||
return false;
|
||||
}
|
||||
});
|
||||
|
||||
return this.getNewlinesBetween(startToken, endToken);
|
||||
};
|
||||
|
||||
Whitespace.prototype.getNewlinesAfter = function (node) {
|
||||
var startToken;
|
||||
var endToken;
|
||||
var tokens = this.tokens;
|
||||
|
||||
_.each(tokens, function (token, i) {
|
||||
// this is the token this node ends with
|
||||
if (node.end === token.end) {
|
||||
startToken = token;
|
||||
endToken = tokens[i + 1];
|
||||
return false;
|
||||
}
|
||||
});
|
||||
|
||||
if (endToken.type.type === "eof") {
|
||||
return 1;
|
||||
} else {
|
||||
return this.getNewlinesBetween(startToken, endToken);
|
||||
}
|
||||
};
|
||||
|
||||
Whitespace.prototype.getNewlinesBetween = function (startToken, endToken) {
|
||||
var start = startToken ? startToken.loc.end.line : 1;
|
||||
var end = endToken.loc.start.line;
|
||||
|
||||
var lines = 0;
|
||||
|
||||
for (var line = start; line < end; line++) {
|
||||
if (!_.contains(this.used, line)) {
|
||||
this.used.push(line);
|
||||
lines++;
|
||||
}
|
||||
}
|
||||
|
||||
return lines;
|
||||
};
|
||||
@@ -1,2 +0,0 @@
|
||||
require("core-js/shim");
|
||||
require("regenerator/runtime");
|
||||
@@ -1,4 +0,0 @@
|
||||
// Required to safely use 6to5/register within a browserify codebase.
|
||||
module.exports = function () {};
|
||||
|
||||
require("./polyfill");
|
||||
@@ -1,148 +0,0 @@
|
||||
require("./polyfill");
|
||||
|
||||
var sourceMapSupport = require("source-map-support");
|
||||
var roadrunner = require("roadrunner");
|
||||
var util = require("./util");
|
||||
var to5 = require("./index");
|
||||
var fs = require("fs");
|
||||
var _ = require("lodash");
|
||||
|
||||
sourceMapSupport.install({
|
||||
retrieveSourceMap: function (source) {
|
||||
var map = maps && maps[source];
|
||||
if (map) {
|
||||
return {
|
||||
url: null,
|
||||
map: map
|
||||
};
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
//
|
||||
|
||||
var blacklist = [];
|
||||
|
||||
var blacklistTest = function (transformer, code) {
|
||||
try {
|
||||
if (_.isFunction(code)) {
|
||||
code();
|
||||
} else {
|
||||
new Function(code);
|
||||
}
|
||||
blacklist.push(transformer);
|
||||
} catch (err) {
|
||||
if (err.name !== "SyntaxError") throw err;
|
||||
}
|
||||
};
|
||||
|
||||
blacklistTest("arrayComprehension", "var foo = [for (foo of bar) foo * foo];");
|
||||
blacklistTest("generatorComprehension", "var foo = (for (foo of bar) foo * foo)");
|
||||
blacklistTest("arrowFunctions", "var foo = x => x * x;");
|
||||
blacklistTest("classes", "class Foo {}");
|
||||
blacklistTest("computedPropertyNames", "var foo = { [foo]: bar };");
|
||||
blacklistTest("constants", function () {
|
||||
try {
|
||||
new Function("const foo = 'foo';\nfoo = 'wow';");
|
||||
} catch (err) {
|
||||
return; // constants are supported
|
||||
}
|
||||
throw new SyntaxError;
|
||||
});
|
||||
blacklistTest("defaultParamaters", "var foo = function (bar = 0) {};");
|
||||
blacklistTest("destructuring", "var { x, y } = { x: 0, y: 0 };");
|
||||
blacklistTest("forOf", "for (var foo of bar) {}");
|
||||
blacklistTest("generators", "function* foo() {}\nasync function bar() {}"); // generators/async functions delegated to same transformer
|
||||
blacklistTest("letScoping", "let foo = 0;");
|
||||
blacklistTest("modules", 'import foo from "from";');
|
||||
blacklistTest("propertyMethodAssignment", "{ get foo() {} }");
|
||||
blacklistTest("propertyNameShorthand", "var foo = { x, y };");
|
||||
blacklistTest("restParameters", "function foo(...bar) {}");
|
||||
blacklistTest("spread", "foo(...bar);");
|
||||
blacklistTest("templateLiterals", "var foo = `foo`;");
|
||||
blacklistTest("unicodeRegex", function () { new RegExp("foo", "u"); });
|
||||
|
||||
//
|
||||
|
||||
var transformOpts = {};
|
||||
var ignoreRegex = /node_modules/;
|
||||
var onlyRegex;
|
||||
var whitelist = [];
|
||||
var cache;
|
||||
var exts = {};
|
||||
var maps = {};
|
||||
var old = require.extensions[".js"];
|
||||
|
||||
var mtime = function (filename) {
|
||||
return +fs.statSync(filename).mtime;
|
||||
};
|
||||
|
||||
var loader = function (m, filename) {
|
||||
if ((ignoreRegex && ignoreRegex.test(filename)) || (onlyRegex && !onlyRegex.test(filename))) {
|
||||
return old.apply(this, arguments);
|
||||
}
|
||||
|
||||
var result;
|
||||
|
||||
if (cache) {
|
||||
var cached = cache[filename];
|
||||
if (cached && cached.mtime === mtime(filename)) {
|
||||
result = cached;
|
||||
}
|
||||
}
|
||||
|
||||
result = result || to5.transformFileSync(filename, _.extend({
|
||||
whitelist: whitelist,
|
||||
blacklist: blacklist,
|
||||
sourceMap: true,
|
||||
ast: false
|
||||
}, transformOpts));
|
||||
|
||||
if (cache) {
|
||||
result.mtime = mtime(filename);
|
||||
cache[filename] = result;
|
||||
}
|
||||
|
||||
maps[filename] = result.map;
|
||||
|
||||
m._compile(result.code, filename);
|
||||
};
|
||||
|
||||
var hookExtensions = function (_exts) {
|
||||
_.each(exts, function (old, ext) {
|
||||
require.extensions[ext] = old;
|
||||
});
|
||||
|
||||
exts = {};
|
||||
|
||||
_.each(_exts, function (ext) {
|
||||
exts[ext] = require.extensions[ext];
|
||||
require.extensions[ext] = loader;
|
||||
});
|
||||
};
|
||||
|
||||
hookExtensions([".es6", ".es", ".js"]);
|
||||
|
||||
module.exports = function (opts) {
|
||||
// normalise options
|
||||
opts = opts || {};
|
||||
if (_.isRegExp(opts)) opts = { ignore: opts };
|
||||
if (opts.ignoreRegex != null) opts.ignore = opts.ignoreRegex;
|
||||
|
||||
if (opts.only != null) onlyRegex = util.regexify(opts.only);
|
||||
if (opts.ignore != null) ignoreRegex = util.regexify(opts.ignore);
|
||||
|
||||
if (opts.extensions) hookExtensions(util.arrayify(opts.extensions));
|
||||
|
||||
if (opts.cache) cache = opts.cache;
|
||||
if (opts.cache === false) cache = null;
|
||||
if (opts.cache === true) {
|
||||
roadrunner.load();
|
||||
roadrunner.setup();
|
||||
cache = roadrunner.get("6to5");
|
||||
}
|
||||
|
||||
_.extend(transformOpts, opts);
|
||||
};
|
||||
@@ -1,33 +0,0 @@
|
||||
var generator = require("./generation/generator");
|
||||
var util = require("./util");
|
||||
var File = require("./file");
|
||||
var t = require("./types");
|
||||
var _ = require("lodash");
|
||||
|
||||
module.exports = function (namespace) {
|
||||
namespace = t.identifier(t.toIdentifier(namespace || "to5Runtime"));
|
||||
|
||||
var body = [];
|
||||
var container = t.functionExpression(null, [t.identifier("global")], t.blockStatement(body));
|
||||
var tree = t.program([t.expressionStatement(t.callExpression(container, [util.template("self-global")]))]);
|
||||
|
||||
body.push(t.variableDeclaration("var", [
|
||||
t.variableDeclarator(
|
||||
namespace,
|
||||
t.assignmentExpression("=", t.memberExpression(t.identifier("global"), namespace), t.objectExpression([]))
|
||||
)
|
||||
]));
|
||||
|
||||
_.each(File.helpers, function (name) {
|
||||
if (_.contains(File.excludeHelpersFromRuntime, name)) {
|
||||
return;
|
||||
}
|
||||
|
||||
var key = t.identifier(t.toIdentifier(name));
|
||||
body.push(t.expressionStatement(
|
||||
t.assignmentExpression("=", t.memberExpression(namespace, key), util.template(name))
|
||||
));
|
||||
});
|
||||
|
||||
return generator(tree).code;
|
||||
};
|
||||
@@ -1,268 +0,0 @@
|
||||
module.exports = DefaultFormatter;
|
||||
|
||||
var traverse = require("../../traverse");
|
||||
var util = require("../../util");
|
||||
var t = require("../../types");
|
||||
var _ = require("lodash");
|
||||
|
||||
function DefaultFormatter(file) {
|
||||
this.file = file;
|
||||
|
||||
this.localExports = this.getLocalExports();
|
||||
this.localImports = this.getLocalImports();
|
||||
|
||||
this.remapAssignments();
|
||||
|
||||
//this.checkCollisions();
|
||||
}
|
||||
|
||||
DefaultFormatter.prototype.getLocalExports = function () {
|
||||
var localExports = {};
|
||||
|
||||
traverse(this.file.ast, {
|
||||
enter: function (node) {
|
||||
var declar = node && node.declaration;
|
||||
if (t.isExportDeclaration(node) && declar && t.isStatement(declar)) {
|
||||
_.extend(localExports, t.getIds(declar, true));
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
return localExports;
|
||||
};
|
||||
|
||||
DefaultFormatter.prototype.getLocalImports = function () {
|
||||
var localImports = {};
|
||||
|
||||
traverse(this.file.ast, {
|
||||
enter: function (node) {
|
||||
if (t.isImportDeclaration(node)) {
|
||||
_.extend(localImports, t.getIds(node, true));
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
return localImports;
|
||||
};
|
||||
|
||||
DefaultFormatter.prototype.checkCollisions = function () {
|
||||
// todo: all check export collissions
|
||||
|
||||
var localImports = this.localImports;
|
||||
var file = this.file;
|
||||
|
||||
var isLocalReference = function (node) {
|
||||
return t.isIdentifier(node) && _.has(localImports, node.name) && localImports[node.name] !== node;
|
||||
};
|
||||
|
||||
var check = function (node) {
|
||||
if (isLocalReference(node)) {
|
||||
throw file.errorWithNode(node, "Illegal assignment of module import");
|
||||
}
|
||||
};
|
||||
|
||||
traverse(file.ast, {
|
||||
enter: function (node) {
|
||||
if (t.isAssignmentExpression(node)) {
|
||||
|
||||
var left = node.left;
|
||||
if (t.isMemberExpression(left)) {
|
||||
while (left.object) left = left.object;
|
||||
}
|
||||
|
||||
check(left);
|
||||
} else if (t.isDeclaration(node)) {
|
||||
_.each(t.getIds(node, true), check);
|
||||
}
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
DefaultFormatter.prototype.remapExportAssignment = function (node) {
|
||||
return t.assignmentExpression(
|
||||
"=",
|
||||
node.left,
|
||||
t.assignmentExpression(
|
||||
node.operator,
|
||||
t.memberExpression(t.identifier("exports"), node.left),
|
||||
node.right
|
||||
)
|
||||
);
|
||||
};
|
||||
|
||||
DefaultFormatter.prototype.remapAssignments = function () {
|
||||
var localExports = this.localExports;
|
||||
var self = this;
|
||||
|
||||
var isLocalReference = function (node, scope) {
|
||||
var name = node.name;
|
||||
return t.isIdentifier(node) && localExports[name] && localExports[name] === scope.get(name, true);
|
||||
};
|
||||
|
||||
traverse(this.file.ast, {
|
||||
enter: function (node, parent, scope) {
|
||||
if (t.isUpdateExpression(node) && isLocalReference(node.argument, scope)) {
|
||||
this.skip();
|
||||
|
||||
// expand to long file assignment expression
|
||||
var assign = t.assignmentExpression(node.operator[0] + "=", node.argument, t.literal(1));
|
||||
|
||||
// remap this assignment expression
|
||||
var remapped = self.remapExportAssignment(assign);
|
||||
|
||||
// we don't need to change the result
|
||||
if (t.isExpressionStatement(parent) || node.prefix) {
|
||||
return remapped;
|
||||
}
|
||||
|
||||
var nodes = [];
|
||||
nodes.push(remapped);
|
||||
|
||||
var operator;
|
||||
if (node.operator === "--") {
|
||||
operator = "+";
|
||||
} else { // "++"
|
||||
operator = "-";
|
||||
}
|
||||
nodes.push(t.binaryExpression(operator, node.argument, t.literal(1)));
|
||||
|
||||
return t.sequenceExpression(nodes);
|
||||
}
|
||||
|
||||
if (t.isAssignmentExpression(node) && isLocalReference(node.left, scope)) {
|
||||
this.skip();
|
||||
return self.remapExportAssignment(node);
|
||||
}
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
DefaultFormatter.prototype.getModuleName = function () {
|
||||
var opts = this.file.opts;
|
||||
var filenameRelative = opts.filenameRelative;
|
||||
var moduleName = "";
|
||||
|
||||
if (opts.moduleRoot) {
|
||||
moduleName = opts.moduleRoot + "/";
|
||||
}
|
||||
|
||||
if (!opts.filenameRelative) {
|
||||
return moduleName + opts.filename.replace(/^\//, "");
|
||||
}
|
||||
|
||||
if (opts.sourceRoot) {
|
||||
// remove sourceRoot from filename
|
||||
var sourceRootRegEx = new RegExp("^" + opts.sourceRoot + "\/?");
|
||||
filenameRelative = filenameRelative.replace(sourceRootRegEx, "");
|
||||
}
|
||||
|
||||
// remove extension
|
||||
filenameRelative = filenameRelative.replace(/\.(.*?)$/, "");
|
||||
|
||||
moduleName += filenameRelative;
|
||||
|
||||
// normalise path separators
|
||||
moduleName = moduleName.replace(/\\/g, "/");
|
||||
|
||||
return moduleName;
|
||||
};
|
||||
|
||||
DefaultFormatter.prototype._pushStatement = function (ref, nodes) {
|
||||
if (t.isClass(ref) || t.isFunction(ref)) {
|
||||
if (ref.id) {
|
||||
nodes.push(t.toStatement(ref));
|
||||
ref = ref.id;
|
||||
}
|
||||
}
|
||||
|
||||
return ref;
|
||||
};
|
||||
|
||||
DefaultFormatter.prototype._hoistExport = function (declar, assign, priority) {
|
||||
if (t.isFunctionDeclaration(declar)) {
|
||||
assign._blockHoist = priority || 2;
|
||||
}
|
||||
|
||||
return assign;
|
||||
};
|
||||
|
||||
DefaultFormatter.prototype._exportSpecifier = function (getRef, specifier, node, nodes) {
|
||||
var inherits = false;
|
||||
if (node.specifiers.length === 1) inherits = node;
|
||||
|
||||
if (node.source) {
|
||||
if (t.isExportBatchSpecifier(specifier)) {
|
||||
// export * from "foo";
|
||||
nodes.push(this._exportsWildcard(getRef(), node));
|
||||
} else {
|
||||
var ref;
|
||||
if (t.isSpecifierDefault(specifier) && !this.noInteropRequire) {
|
||||
// importing a default so we need to normalise it
|
||||
ref = t.callExpression(this.file.addHelper("interop-require"), [getRef()]);
|
||||
} else {
|
||||
ref = t.memberExpression(getRef(), specifier.id);
|
||||
}
|
||||
|
||||
// export { foo } from "test";
|
||||
nodes.push(this._exportsAssign(
|
||||
t.getSpecifierName(specifier),
|
||||
ref,
|
||||
node
|
||||
));
|
||||
}
|
||||
} else {
|
||||
// export { foo };
|
||||
nodes.push(this._exportsAssign(t.getSpecifierName(specifier), specifier.id, node));
|
||||
}
|
||||
};
|
||||
|
||||
DefaultFormatter.prototype._exportsWildcard = function (objectIdentifier) {
|
||||
return t.expressionStatement(t.callExpression(this.file.addHelper("defaults"), [
|
||||
t.identifier("exports"),
|
||||
t.callExpression(this.file.addHelper("interop-require-wildcard"), [objectIdentifier])
|
||||
]));
|
||||
};
|
||||
|
||||
DefaultFormatter.prototype._exportsAssign = function (id, init) {
|
||||
return util.template("exports-assign", {
|
||||
VALUE: init,
|
||||
KEY: id
|
||||
}, true);
|
||||
};
|
||||
|
||||
DefaultFormatter.prototype.exportDeclaration = function (node, nodes) {
|
||||
var declar = node.declaration;
|
||||
|
||||
var id = declar.id;
|
||||
|
||||
if (node.default) {
|
||||
id = t.identifier("default");
|
||||
}
|
||||
|
||||
var assign;
|
||||
|
||||
if (t.isVariableDeclaration(declar)) {
|
||||
for (var i in declar.declarations) {
|
||||
var decl = declar.declarations[i];
|
||||
|
||||
decl.init = this._exportsAssign(decl.id, decl.init, node).expression;
|
||||
|
||||
var newDeclar = t.variableDeclaration(declar.kind, [decl]);
|
||||
if (i === "0") t.inherits(newDeclar, declar);
|
||||
nodes.push(newDeclar);
|
||||
}
|
||||
} else {
|
||||
var ref = declar;
|
||||
|
||||
if (t.isFunctionDeclaration(declar) || t.isClassDeclaration(declar)) {
|
||||
ref = declar.id;
|
||||
nodes.push(declar);
|
||||
}
|
||||
|
||||
assign = this._exportsAssign(id, ref, node);
|
||||
|
||||
nodes.push(assign);
|
||||
|
||||
this._hoistExport(declar, assign);
|
||||
}
|
||||
};
|
||||
@@ -1,105 +0,0 @@
|
||||
module.exports = CommonJSFormatter;
|
||||
|
||||
var DefaultFormatter = require("./_default");
|
||||
var traverse = require("../../traverse");
|
||||
var util = require("../../util");
|
||||
var t = require("../../types");
|
||||
|
||||
function CommonJSFormatter(file) {
|
||||
DefaultFormatter.apply(this, arguments);
|
||||
|
||||
var hasNonDefaultExports = false;
|
||||
traverse(file.ast, {
|
||||
enter: function (node) {
|
||||
if (t.isExportDeclaration(node) && !node.default) hasNonDefaultExports = true;
|
||||
}
|
||||
});
|
||||
this.hasNonDefaultExports = hasNonDefaultExports;
|
||||
}
|
||||
|
||||
util.inherits(CommonJSFormatter, DefaultFormatter);
|
||||
|
||||
CommonJSFormatter.prototype.importSpecifier = function (specifier, node, nodes) {
|
||||
var variableName = t.getSpecifierName(specifier);
|
||||
|
||||
// import foo from "foo";
|
||||
if (t.isSpecifierDefault(specifier)) {
|
||||
nodes.push(t.variableDeclaration("var", [
|
||||
t.variableDeclarator(variableName,
|
||||
t.callExpression(this.file.addHelper("interop-require"), [util.template("require", {
|
||||
MODULE_NAME: node.source
|
||||
})])
|
||||
)
|
||||
]));
|
||||
} else {
|
||||
if (specifier.type === "ImportBatchSpecifier") {
|
||||
// import * as bar from "foo";
|
||||
nodes.push(t.variableDeclaration("var", [
|
||||
t.variableDeclarator(
|
||||
variableName,
|
||||
t.callExpression(this.file.addHelper("interop-require-wildcard"), [
|
||||
t.callExpression(t.identifier("require"), [node.source])
|
||||
])
|
||||
)
|
||||
]));
|
||||
} else {
|
||||
// import foo from "foo";
|
||||
nodes.push(util.template("require-assign-key", {
|
||||
VARIABLE_NAME: variableName,
|
||||
MODULE_NAME: node.source,
|
||||
KEY: specifier.id
|
||||
}));
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
CommonJSFormatter.prototype.importDeclaration = function (node, nodes) {
|
||||
// import "foo";
|
||||
nodes.push(util.template("require", {
|
||||
MODULE_NAME: node.source
|
||||
}, true));
|
||||
};
|
||||
|
||||
CommonJSFormatter.prototype.exportDeclaration = function (node, nodes) {
|
||||
if (node.default && !this.noInteropRequire && !this.noInteropExport) {
|
||||
var declar = node.declaration;
|
||||
var assign;
|
||||
|
||||
// module.exports = VALUE;
|
||||
var templateName = "exports-default-module";
|
||||
|
||||
// exports = module.exports = VALUE;
|
||||
if (this.hasNonDefaultExports) templateName = "exports-default-module-override";
|
||||
|
||||
if (t.isFunctionDeclaration(declar) || !this.hasNonDefaultExports) {
|
||||
assign = util.template(templateName, {
|
||||
VALUE: this._pushStatement(declar, nodes)
|
||||
}, true);
|
||||
|
||||
// hoist to the top if this default is a function
|
||||
nodes.push(this._hoistExport(declar, assign, 3));
|
||||
return;
|
||||
} else {
|
||||
// this export isn't a function so we can't hoist it to the top so we need to set it
|
||||
// at the very end of the file with something like:
|
||||
//
|
||||
// module.exports = _extends(exports["default"], exports)
|
||||
//
|
||||
|
||||
assign = util.template("common-export-default-assign", {
|
||||
EXTENDS_HELPER: this.file.addHelper("extends")
|
||||
}, true);
|
||||
assign._blockHoist = 0;
|
||||
|
||||
nodes.push(assign);
|
||||
}
|
||||
}
|
||||
|
||||
DefaultFormatter.prototype.exportDeclaration.apply(this, arguments);
|
||||
};
|
||||
|
||||
CommonJSFormatter.prototype.exportSpecifier = function (specifier, node, nodes) {
|
||||
this._exportSpecifier(function () {
|
||||
return t.callExpression(t.identifier("require"), [node.source]);
|
||||
}, specifier, node, nodes);
|
||||
};
|
||||
@@ -1,179 +0,0 @@
|
||||
module.exports = SystemFormatter;
|
||||
|
||||
var AMDFormatter = require("./amd");
|
||||
var useStrict = require("../transformers/use-strict");
|
||||
var traverse = require("../../traverse");
|
||||
var util = require("../../util");
|
||||
var t = require("../../types");
|
||||
var _ = require("lodash");
|
||||
|
||||
function SystemFormatter(file) {
|
||||
this.exportIdentifier = file.generateUidIdentifier("export");
|
||||
this.noInteropRequire = true;
|
||||
|
||||
AMDFormatter.apply(this, arguments);
|
||||
}
|
||||
|
||||
util.inherits(SystemFormatter, AMDFormatter);
|
||||
|
||||
SystemFormatter.prototype._addImportSource = function (node, exportNode) {
|
||||
node._importSource = exportNode.source && exportNode.source.value;
|
||||
return node;
|
||||
};
|
||||
|
||||
SystemFormatter.prototype._exportsWildcard = function (objectIdentifier, node) {
|
||||
var leftIdentifier = this.file.generateUidIdentifier("key");
|
||||
var valIdentifier = t.memberExpression(objectIdentifier, leftIdentifier, true);
|
||||
|
||||
var left = t.variableDeclaration("var", [
|
||||
t.variableDeclarator(leftIdentifier)
|
||||
]);
|
||||
|
||||
var right = objectIdentifier;
|
||||
|
||||
var block = t.blockStatement([
|
||||
t.expressionStatement(this.buildExportCall(leftIdentifier, valIdentifier))
|
||||
]);
|
||||
|
||||
return this._addImportSource(t.forInStatement(left, right, block), node);
|
||||
};
|
||||
|
||||
SystemFormatter.prototype._exportsAssign = function (id, init, node) {
|
||||
var call = this.buildExportCall(t.literal(id.name), init, true);
|
||||
return this._addImportSource(call, node);
|
||||
};
|
||||
|
||||
SystemFormatter.prototype.remapExportAssignment = function (node) {
|
||||
return this.buildExportCall(t.literal(node.left.name), node);
|
||||
};
|
||||
|
||||
SystemFormatter.prototype.buildExportCall = function (id, init, isStatement) {
|
||||
var call = t.callExpression(this.exportIdentifier, [id, init]);
|
||||
if (isStatement) {
|
||||
return t.expressionStatement(call);
|
||||
} else {
|
||||
return call;
|
||||
}
|
||||
};
|
||||
|
||||
SystemFormatter.prototype.importSpecifier = function (specifier, node, nodes) {
|
||||
AMDFormatter.prototype.importSpecifier.apply(this, arguments);
|
||||
this._addImportSource(_.last(nodes), node);
|
||||
};
|
||||
|
||||
SystemFormatter.prototype.buildRunnerSetters = function (block, hoistDeclarators) {
|
||||
return t.arrayExpression(_.map(this.ids, function (uid, source) {
|
||||
var nodes = [];
|
||||
|
||||
traverse(block, {
|
||||
enter: function (node) {
|
||||
if (node._importSource === source) {
|
||||
if (t.isVariableDeclaration(node)) {
|
||||
_.each(node.declarations, function (declar) {
|
||||
hoistDeclarators.push(t.variableDeclarator(declar.id));
|
||||
nodes.push(t.expressionStatement(
|
||||
t.assignmentExpression("=", declar.id, declar.init)
|
||||
));
|
||||
});
|
||||
} else {
|
||||
nodes.push(node);
|
||||
}
|
||||
|
||||
this.remove();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
return t.functionExpression(null, [uid], t.blockStatement(nodes));
|
||||
}));
|
||||
};
|
||||
|
||||
SystemFormatter.prototype.transform = function (ast) {
|
||||
var program = ast.program;
|
||||
|
||||
var hoistDeclarators = [];
|
||||
var moduleName = this.getModuleName();
|
||||
var moduleNameLiteral = t.literal(moduleName);
|
||||
|
||||
var block = t.blockStatement(program.body);
|
||||
|
||||
var runner = util.template("system", {
|
||||
MODULE_NAME: moduleNameLiteral,
|
||||
MODULE_DEPENDENCIES: t.arrayExpression(this.buildDependencyLiterals()),
|
||||
EXPORT_IDENTIFIER: this.exportIdentifier,
|
||||
SETTERS: this.buildRunnerSetters(block, hoistDeclarators),
|
||||
EXECUTE: t.functionExpression(null, [], block)
|
||||
}, true);
|
||||
|
||||
var handlerBody = runner.expression.arguments[2].body.body;
|
||||
if (!moduleName) runner.expression.arguments.shift();
|
||||
|
||||
var returnStatement = handlerBody.pop();
|
||||
|
||||
// hoist up all variable declarations
|
||||
traverse(block, {
|
||||
enter: function (node, parent, scope) {
|
||||
if (t.isFunction(node)) {
|
||||
// nothing inside is accessible
|
||||
return this.skip();
|
||||
}
|
||||
|
||||
if (t.isVariableDeclaration(node)) {
|
||||
if (node.kind !== "var" && !t.isProgram(parent)) { // let, const
|
||||
// can't be accessed
|
||||
return;
|
||||
}
|
||||
|
||||
var nodes = [];
|
||||
|
||||
_.each(node.declarations, function (declar) {
|
||||
hoistDeclarators.push(t.variableDeclarator(declar.id));
|
||||
if (declar.init) {
|
||||
// no initializer so we can just hoist it as-is
|
||||
var assign = t.expressionStatement(t.assignmentExpression("=", declar.id, declar.init));
|
||||
nodes.push(assign);
|
||||
}
|
||||
});
|
||||
|
||||
// for (var i in test)
|
||||
// for (var i = 0;;)
|
||||
if (t.isFor(parent)) {
|
||||
if (parent.left === node) {
|
||||
return node.declarations[0].id;
|
||||
}
|
||||
|
||||
if (parent.init === node) {
|
||||
return t.toSequenceExpression(nodes, scope);
|
||||
}
|
||||
}
|
||||
|
||||
return nodes;
|
||||
}
|
||||
}
|
||||
});
|
||||
if (hoistDeclarators.length) {
|
||||
var hoistDeclar = t.variableDeclaration("var", hoistDeclarators);
|
||||
hoistDeclar._blockHoist = true;
|
||||
handlerBody.unshift(hoistDeclar);
|
||||
}
|
||||
|
||||
// hoist up function declarations for circular references
|
||||
traverse(block, {
|
||||
enter: function (node) {
|
||||
if (t.isFunction(node)) this.skip();
|
||||
|
||||
if (t.isFunctionDeclaration(node) || node._blockHoist) {
|
||||
handlerBody.push(node);
|
||||
this.remove();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
handlerBody.push(returnStatement);
|
||||
|
||||
if (useStrict._has(block)) {
|
||||
handlerBody.unshift(block.body.shift());
|
||||
}
|
||||
|
||||
program.body = [runner];
|
||||
};
|
||||
@@ -1,3 +0,0 @@
|
||||
ARRAY.forEach(function (KEY) {
|
||||
|
||||
});
|
||||
@@ -1,37 +0,0 @@
|
||||
(function (fn) {
|
||||
return function () {
|
||||
var gen = fn.apply(this, arguments);
|
||||
|
||||
return new Promise(function (resolve, reject) {
|
||||
function step(getNext) {
|
||||
var next;
|
||||
|
||||
try {
|
||||
next = getNext();
|
||||
} catch(e) {
|
||||
reject(e);
|
||||
return;
|
||||
}
|
||||
|
||||
if (next.done) {
|
||||
resolve(next.value);
|
||||
return;
|
||||
}
|
||||
|
||||
Promise.resolve(next.value).then(function (v) {
|
||||
step(function () {
|
||||
return gen.next(v);
|
||||
});
|
||||
}, function (e) {
|
||||
step(function () {
|
||||
return gen["throw"](e);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
step(function () {
|
||||
return gen.next();
|
||||
});
|
||||
});
|
||||
}
|
||||
})
|
||||
@@ -1,3 +0,0 @@
|
||||
if (Object.getPrototypeOf(CLASS_NAME) !== null) {
|
||||
Object.getPrototypeOf(CLASS_NAME).apply(this, arguments);
|
||||
}
|
||||
@@ -1 +0,0 @@
|
||||
module.exports = EXTENDS_HELPER(exports["default"], exports);
|
||||
@@ -1 +0,0 @@
|
||||
var VARIABLE_NAME = ARGUMENTS[ARGUMENT_KEY] === undefined ? DEFAULT_VALUE : ARGUMENTS[ARGUMENT_KEY];
|
||||
@@ -1,8 +0,0 @@
|
||||
(function (obj, defaults) {
|
||||
for (var key in defaults) {
|
||||
if (obj[key] === undefined) {
|
||||
obj[key] = defaults[key];
|
||||
}
|
||||
}
|
||||
return obj;
|
||||
})
|
||||
@@ -1 +0,0 @@
|
||||
exports = module.exports = VALUE;
|
||||
@@ -1,9 +0,0 @@
|
||||
(function (target) {
|
||||
for (var i = 1; i < arguments.length; i++) {
|
||||
var source = arguments[i];
|
||||
for (var key in source) {
|
||||
target[key] = source[key];
|
||||
}
|
||||
}
|
||||
return target;
|
||||
})
|
||||
@@ -1,14 +0,0 @@
|
||||
(function (child, parent) {
|
||||
if (typeof parent !== "function" && parent !== null) {
|
||||
throw new TypeError("Super expression must either be null or a function, not " + typeof parent);
|
||||
}
|
||||
child.prototype = Object.create(parent && parent.prototype, {
|
||||
constructor: {
|
||||
value: child,
|
||||
enumerable: false,
|
||||
writable: true,
|
||||
configurable: true
|
||||
}
|
||||
});
|
||||
if (parent) child.__proto__ = parent;
|
||||
})
|
||||
@@ -1,3 +0,0 @@
|
||||
(function (obj) {
|
||||
return obj && obj.constructor === Object ? obj : { default: obj };
|
||||
})
|
||||
@@ -1,3 +0,0 @@
|
||||
(function (obj) {
|
||||
return obj && (obj["default"] || obj);
|
||||
})
|
||||
@@ -1,5 +0,0 @@
|
||||
|
||||
(function (KEY) {
|
||||
CONTENT;
|
||||
return KEY;
|
||||
})(OBJECT);
|
||||
@@ -1 +0,0 @@
|
||||
Object.defineProperties(OBJECT, PROPS);
|
||||
@@ -1,3 +0,0 @@
|
||||
for (var KEY = START; KEY < ARGUMENTS.length; KEY++) {
|
||||
ARRAY[ARRAY_KEY] = ARGUMENTS[KEY];
|
||||
}
|
||||
@@ -1,101 +0,0 @@
|
||||
module.exports = transform;
|
||||
|
||||
var Transformer = require("./transformer");
|
||||
var File = require("../file");
|
||||
var util = require("../util");
|
||||
var _ = require("lodash");
|
||||
|
||||
function transform(code, opts) {
|
||||
var file = new File(opts);
|
||||
return file.parse(code);
|
||||
}
|
||||
|
||||
transform.fromAst = function (ast, code, opts) {
|
||||
ast = util.normaliseAst(ast);
|
||||
|
||||
var file = new File(opts);
|
||||
file.addCode(code);
|
||||
file.transform(ast);
|
||||
return file.generate();
|
||||
};
|
||||
|
||||
transform._ensureTransformerNames = function (type, keys) {
|
||||
for (var i in keys) {
|
||||
var key = keys[i];
|
||||
if (!_.has(transform.transformers, key)) {
|
||||
throw new ReferenceError("unknown transformer " + key + " specified in " + type);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
transform.transformers = {};
|
||||
|
||||
transform.moduleFormatters = {
|
||||
commonStrict: require("./modules/common-strict"),
|
||||
umdStrict: require("./modules/umd-strict"),
|
||||
amdStrict: require("./modules/amd-strict"),
|
||||
common: require("./modules/common"),
|
||||
system: require("./modules/system"),
|
||||
ignore: require("./modules/ignore"),
|
||||
amd: require("./modules/amd"),
|
||||
umd: require("./modules/umd")
|
||||
};
|
||||
|
||||
_.each({
|
||||
specNoForInOfAssignment: require("./transformers/spec-no-for-in-of-assignment"),
|
||||
|
||||
// playground
|
||||
methodBinding: require("./transformers/playground-method-binding"),
|
||||
memoizationOperator: require("./transformers/playground-memoization-operator"),
|
||||
objectGetterMemoization: require("./transformers/playground-object-getter-memoization"),
|
||||
|
||||
asyncToGenerator: require("./transformers/optional-async-to-generator"),
|
||||
bluebirdCoroutines: require("./transformers/optional-bluebird-coroutines"),
|
||||
|
||||
react: require("./transformers/react"),
|
||||
modules: require("./transformers/es6-modules"),
|
||||
propertyNameShorthand: require("./transformers/es6-property-name-shorthand"),
|
||||
arrayComprehension: require("./transformers/es7-array-comprehension"),
|
||||
generatorComprehension: require("./transformers/es7-generator-comprehension"),
|
||||
arrowFunctions: require("./transformers/es6-arrow-functions"),
|
||||
classes: require("./transformers/es6-classes"),
|
||||
|
||||
objectSpread: require("./transformers/es7-object-spread"),
|
||||
exponentiationOperator: require("./transformers/es7-exponentiation-operator"),
|
||||
spread: require("./transformers/es6-spread"),
|
||||
templateLiterals: require("./transformers/es6-template-literals"),
|
||||
propertyMethodAssignment: require("./transformers/es6-property-method-assignment"),
|
||||
computedPropertyNames: require("./transformers/es6-computed-property-names"),
|
||||
destructuring: require("./transformers/es6-destructuring"),
|
||||
defaultParameters: require("./transformers/es6-default-parameters"),
|
||||
forOf: require("./transformers/es6-for-of"),
|
||||
unicodeRegex: require("./transformers/es6-unicode-regex"),
|
||||
abstractReferences: require("./transformers/es7-abstract-references"),
|
||||
|
||||
constants: require("./transformers/es6-constants"),
|
||||
letScoping: require("./transformers/es6-let-scoping"),
|
||||
|
||||
_blockHoist: require("./transformers/_block-hoist"),
|
||||
|
||||
generators: require("./transformers/es6-generators"),
|
||||
restParameters: require("./transformers/es6-rest-parameters"),
|
||||
|
||||
protoToAssign: require("./transformers/optional-proto-to-assign"),
|
||||
|
||||
_declarations: require("./transformers/_declarations"),
|
||||
|
||||
// wrap up
|
||||
useStrict: require("./transformers/use-strict"),
|
||||
_aliasFunctions: require("./transformers/_alias-functions"),
|
||||
_moduleFormatter: require("./transformers/_module-formatter"),
|
||||
|
||||
typeofSymbol: require("./transformers/optional-typeof-symbol"),
|
||||
coreAliasing: require("./transformers/optional-core-aliasing"),
|
||||
undefinedToVoid: require("./transformers/optional-undefined-to-void"),
|
||||
|
||||
// spec
|
||||
specPropertyLiterals: require("./transformers/spec-property-literals"),
|
||||
specMemberExpressionLiterals: require("./transformers/spec-member-expression-literals")
|
||||
}, function (transformer, key) {
|
||||
transform.transformers[key] = new Transformer(key, transformer);
|
||||
});
|
||||
@@ -1,98 +0,0 @@
|
||||
module.exports = Transformer;
|
||||
|
||||
var traverse = require("../traverse");
|
||||
var t = require("../types");
|
||||
var _ = require("lodash");
|
||||
|
||||
function Transformer(key, transformer, opts) {
|
||||
this.manipulateOptions = transformer.manipulateOptions;
|
||||
this.experimental = !!transformer.experimental;
|
||||
this.secondPass = !!transformer.secondPass;
|
||||
this.transformer = this.normalise(transformer);
|
||||
this.optional = !!transformer.optional;
|
||||
this.opts = opts || {};
|
||||
this.key = key;
|
||||
}
|
||||
|
||||
Transformer.prototype.normalise = function (transformer) {
|
||||
var self = this;
|
||||
|
||||
if (_.isFunction(transformer)) {
|
||||
transformer = { ast: transformer };
|
||||
}
|
||||
|
||||
_.each(transformer, function (fns, type) {
|
||||
// hidden property
|
||||
if (type[0] === "_") {
|
||||
self[type] = fns;
|
||||
return;
|
||||
}
|
||||
|
||||
if (_.isFunction(fns)) fns = { enter: fns };
|
||||
|
||||
if (!_.isObject(fns)) return;
|
||||
|
||||
transformer[type] = fns;
|
||||
|
||||
var aliases = t.FLIPPED_ALIAS_KEYS[type];
|
||||
if (aliases) {
|
||||
_.each(aliases, function (alias) {
|
||||
transformer[alias] = fns;
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
return transformer;
|
||||
};
|
||||
|
||||
Transformer.prototype.astRun = function (file, key) {
|
||||
var transformer = this.transformer;
|
||||
|
||||
if (transformer.ast && transformer.ast[key]) {
|
||||
transformer.ast[key](file.ast, file);
|
||||
}
|
||||
};
|
||||
|
||||
Transformer.prototype.transform = function (file) {
|
||||
var transformer = this.transformer;
|
||||
|
||||
var build = function (exit) {
|
||||
return function (node, parent, scope) {
|
||||
var fns = transformer[node.type];
|
||||
if (!fns) return;
|
||||
|
||||
var fn = fns.enter;
|
||||
if (exit) fn = fns.exit;
|
||||
if (!fn) return;
|
||||
|
||||
return fn(node, parent, file, scope);
|
||||
};
|
||||
};
|
||||
|
||||
this.astRun(file, "before");
|
||||
|
||||
traverse(file.ast, {
|
||||
enter: build(),
|
||||
exit: build(true)
|
||||
});
|
||||
|
||||
this.astRun(file, "after");
|
||||
};
|
||||
|
||||
Transformer.prototype.canRun = function (file) {
|
||||
var opts = file.opts;
|
||||
var key = this.key;
|
||||
if (key[0] === "_") return true;
|
||||
|
||||
var blacklist = opts.blacklist;
|
||||
if (blacklist.length && _.contains(blacklist, key)) return false;
|
||||
|
||||
var whitelist = opts.whitelist;
|
||||
if (whitelist.length && !_.contains(whitelist, key)) return false;
|
||||
|
||||
if (this.optional && !_.contains(opts.optional, key)) return false;
|
||||
|
||||
if (this.experimental && !opts.experimental) return false;
|
||||
|
||||
return true;
|
||||
};
|
||||
@@ -1,86 +0,0 @@
|
||||
var traverse = require("../../traverse");
|
||||
var t = require("../../types");
|
||||
|
||||
var go = function (getBody, node, file, scope) {
|
||||
var argumentsId;
|
||||
var thisId;
|
||||
|
||||
var getArgumentsId = function () {
|
||||
return argumentsId = argumentsId || file.generateUidIdentifier("arguments", scope);
|
||||
};
|
||||
|
||||
var getThisId = function () {
|
||||
return thisId = thisId || file.generateUidIdentifier("this", scope);
|
||||
};
|
||||
|
||||
// traverse the function and find all alias functions so we can alias
|
||||
// `arguments` and `this` if necessary
|
||||
traverse(node, {
|
||||
enter: function (node) {
|
||||
if (!node._aliasFunction) {
|
||||
if (t.isFunction(node)) {
|
||||
// stop traversal of this node as it'll be hit again by this transformer
|
||||
return this.skip();
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// traverse all child nodes of this function and find `arguments` and `this`
|
||||
traverse(node, {
|
||||
enter: function (node, parent) {
|
||||
if (t.isFunction(node) && !node._aliasFunction) {
|
||||
return this.skip();
|
||||
}
|
||||
|
||||
if (node._ignoreAliasFunctions) return this.skip();
|
||||
|
||||
var getId;
|
||||
|
||||
if (t.isIdentifier(node) && node.name === "arguments") {
|
||||
getId = getArgumentsId;
|
||||
} else if (t.isThisExpression(node)) {
|
||||
getId = getThisId;
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
|
||||
if (t.isReferenced(node, parent)) return getId();
|
||||
}
|
||||
});
|
||||
|
||||
return this.skip();
|
||||
}
|
||||
});
|
||||
|
||||
var body;
|
||||
|
||||
var pushDeclaration = function (id, init) {
|
||||
body = body || getBody();
|
||||
body.unshift(t.variableDeclaration("var", [
|
||||
t.variableDeclarator(id, init)
|
||||
]));
|
||||
};
|
||||
|
||||
if (argumentsId) {
|
||||
pushDeclaration(argumentsId, t.identifier("arguments"));
|
||||
}
|
||||
|
||||
if (thisId) {
|
||||
pushDeclaration(thisId, t.thisExpression());
|
||||
}
|
||||
};
|
||||
|
||||
exports.Program = function (node, parent, file, scope) {
|
||||
go(function () {
|
||||
return node.body;
|
||||
}, node, file, scope);
|
||||
};
|
||||
|
||||
exports.FunctionDeclaration =
|
||||
exports.FunctionExpression = function (node, parent, file, scope) {
|
||||
go(function () {
|
||||
t.ensureBlock(node);
|
||||
return node.body.body;
|
||||
}, node, file, scope);
|
||||
};
|
||||
@@ -1,32 +0,0 @@
|
||||
var useStrict = require("./use-strict");
|
||||
var t = require("../../types");
|
||||
|
||||
exports.secondPass = true;
|
||||
|
||||
exports.BlockStatement =
|
||||
exports.Program = function (node) {
|
||||
var kinds = {};
|
||||
var kind;
|
||||
|
||||
useStrict._wrap(node, function () {
|
||||
for (var i in node._declarations) {
|
||||
var declar = node._declarations[i];
|
||||
|
||||
kind = declar.kind || "var";
|
||||
var declarNode = t.variableDeclarator(declar.id, declar.init);
|
||||
|
||||
if (!declar.init) {
|
||||
kinds[kind] = kinds[kind] || [];
|
||||
kinds[kind].push(declarNode);
|
||||
} else {
|
||||
node.body.unshift(t.variableDeclaration(kind, [declarNode]));
|
||||
}
|
||||
}
|
||||
|
||||
for (kind in kinds) {
|
||||
node.body.unshift(t.variableDeclaration(kind, kinds[kind]));
|
||||
}
|
||||
});
|
||||
|
||||
node._declarations = null;
|
||||
};
|
||||
@@ -1,11 +0,0 @@
|
||||
var transform = require("../transform");
|
||||
|
||||
exports.ast = {
|
||||
exit: function (ast, file) {
|
||||
if (!transform.transformers.modules.canRun(file)) return;
|
||||
|
||||
if (file.moduleFormatter.transform) {
|
||||
file.moduleFormatter.transform(ast);
|
||||
}
|
||||
}
|
||||
};
|
||||
@@ -1,341 +0,0 @@
|
||||
var traverse = require("../../traverse");
|
||||
var util = require("../../util");
|
||||
var t = require("../../types");
|
||||
|
||||
exports.ClassDeclaration = function (node, parent, file, scope) {
|
||||
var closure = true;
|
||||
if (t.isProgram(parent) || t.isBlockStatement(parent)) {
|
||||
closure = false;
|
||||
}
|
||||
|
||||
var factory = new Class(node, file, scope, closure);
|
||||
var newNode = factory.run();
|
||||
if (factory.closure) {
|
||||
if (closure) {
|
||||
// declaration in an expression context...
|
||||
// export default class Foo {}
|
||||
scope.push({
|
||||
kind: "var",
|
||||
key: node.id.key,
|
||||
id: node.id
|
||||
});
|
||||
return t.assignmentExpression("=", node.id, newNode);
|
||||
} else {
|
||||
// has a super class or PrivateDeclaration etc
|
||||
return t.variableDeclaration("let", [
|
||||
t.variableDeclarator(node.id, newNode)
|
||||
]);
|
||||
}
|
||||
} else {
|
||||
return newNode;
|
||||
}
|
||||
};
|
||||
|
||||
exports.ClassExpression = function (node, parent, file, scope) {
|
||||
return new Class(node, file, scope, true).run();
|
||||
};
|
||||
|
||||
/**
|
||||
* Description
|
||||
*
|
||||
* @param {Node} node
|
||||
* @param {File} file
|
||||
* @param {Scope} scope
|
||||
* @param {Boolean} closure
|
||||
*/
|
||||
|
||||
function Class(node, file, scope, closure) {
|
||||
this.closure = closure;
|
||||
this.scope = scope;
|
||||
this.node = node;
|
||||
this.file = file;
|
||||
|
||||
this.hasInstanceMutators = false;
|
||||
this.hasStaticMutators = false;
|
||||
|
||||
this.instanceMutatorMap = {};
|
||||
this.staticMutatorMap = {};
|
||||
this.hasConstructor = false;
|
||||
this.className = node.id || file.generateUidIdentifier("class", scope);
|
||||
this.superName = node.superClass;
|
||||
}
|
||||
|
||||
/**
|
||||
* Description
|
||||
*
|
||||
* @returns {Array}
|
||||
*/
|
||||
|
||||
Class.prototype.run = function () {
|
||||
var superName = this.superName;
|
||||
var className = this.className;
|
||||
var file = this.file;
|
||||
|
||||
//
|
||||
|
||||
var body = this.body = [];
|
||||
|
||||
var constructor = t.functionExpression(null, [], t.blockStatement([]));
|
||||
if (this.node.id) constructor.id = className;
|
||||
this.constructor = constructor;
|
||||
|
||||
body.push(t.variableDeclaration("let", [
|
||||
t.variableDeclarator(className, constructor)
|
||||
]));
|
||||
|
||||
//
|
||||
|
||||
if (superName) {
|
||||
this.closure = true;
|
||||
|
||||
// so we're only evaluating it once
|
||||
var superRef = this.scope.generateUidBasedOnNode(superName, this.file);
|
||||
body.unshift(t.variableDeclaration("var", [
|
||||
t.variableDeclarator(superRef, superName)
|
||||
]));
|
||||
superName = superRef;
|
||||
|
||||
this.superName = superName;
|
||||
body.push(t.expressionStatement(t.callExpression(file.addHelper("inherits"), [className, superName])));
|
||||
}
|
||||
|
||||
this.buildBody();
|
||||
|
||||
t.inheritsComments(body[0], this.node);
|
||||
|
||||
if (this.closure) {
|
||||
if (body.length === 1) {
|
||||
// only a constructor so no need for a closure container
|
||||
return constructor;
|
||||
} else {
|
||||
body.push(t.returnStatement(className));
|
||||
return t.callExpression(
|
||||
t.functionExpression(null, [], t.blockStatement(body)),
|
||||
[]
|
||||
);
|
||||
}
|
||||
} else {
|
||||
return body;
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Description
|
||||
*/
|
||||
|
||||
Class.prototype.buildBody = function () {
|
||||
var constructor = this.constructor;
|
||||
var className = this.className;
|
||||
var superName = this.superName;
|
||||
var classBody = this.node.body.body;
|
||||
var body = this.body;
|
||||
var self = this;
|
||||
|
||||
for (var i in classBody) {
|
||||
var node = classBody[i];
|
||||
if (t.isMethodDefinition(node)) {
|
||||
self.replaceInstanceSuperReferences(node);
|
||||
|
||||
if (node.key.name === "constructor") {
|
||||
self.pushConstructor(node);
|
||||
} else {
|
||||
self.pushMethod(node);
|
||||
}
|
||||
} else if (t.isPrivateDeclaration(node)) {
|
||||
self.closure = true;
|
||||
body.unshift(node);
|
||||
}
|
||||
}
|
||||
|
||||
if (!this.hasConstructor && superName && !t.isFalsyExpression(superName)) {
|
||||
constructor.body.body.push(util.template("class-super-constructor-call", {
|
||||
CLASS_NAME: className
|
||||
}, true));
|
||||
}
|
||||
|
||||
var instanceProps;
|
||||
var staticProps;
|
||||
|
||||
if (this.hasInstanceMutators) {
|
||||
var protoId = util.template("prototype-identifier", {
|
||||
CLASS_NAME: className
|
||||
});
|
||||
|
||||
instanceProps = util.buildDefineProperties(this.instanceMutatorMap, protoId);
|
||||
}
|
||||
|
||||
if (this.hasStaticMutators) {
|
||||
staticProps = util.buildDefineProperties(this.staticMutatorMap, className);
|
||||
}
|
||||
|
||||
if (instanceProps || staticProps) {
|
||||
staticProps = staticProps || t.literal(null);
|
||||
|
||||
var args = [className, staticProps];
|
||||
if (instanceProps) args.push(instanceProps);
|
||||
|
||||
body.push(t.expressionStatement(
|
||||
t.callExpression(this.file.addHelper("prototype-properties"), args)
|
||||
));
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Push a method to it's respective mutatorMap.
|
||||
*
|
||||
* @param {Node} node MethodDefinition
|
||||
*/
|
||||
|
||||
Class.prototype.pushMethod = function (node) {
|
||||
var methodName = node.key;
|
||||
|
||||
var kind = node.kind;
|
||||
|
||||
if (kind === "") {
|
||||
// method
|
||||
|
||||
var className = this.className;
|
||||
if (!node.static) className = t.memberExpression(className, t.identifier("prototype"));
|
||||
methodName = t.memberExpression(className, methodName, node.computed);
|
||||
|
||||
var expr = t.expressionStatement(t.assignmentExpression("=", methodName, node.value));
|
||||
t.inheritsComments(expr, node);
|
||||
this.body.push(expr);
|
||||
} else {
|
||||
// mutator
|
||||
var mutatorMap = this.instanceMutatorMap;
|
||||
if (node.static) {
|
||||
this.hasStaticMutators = true;
|
||||
mutatorMap = this.staticMutatorMap;
|
||||
} else {
|
||||
this.hasInstanceMutators = true;
|
||||
}
|
||||
util.pushMutatorMap(mutatorMap, methodName, kind, node.computed, node);
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Gets a node representing the super class value of the named property.
|
||||
*
|
||||
* @example
|
||||
*
|
||||
* _get(Object.getPrototypeOf(CLASS.prototype), "METHOD", this)
|
||||
*
|
||||
* @param {Node} property
|
||||
* @param {boolean} isStatic
|
||||
* @param {boolean} isComputed
|
||||
*
|
||||
* @returns {Node}
|
||||
*/
|
||||
|
||||
Class.prototype.superProperty = function (property, isStatic, isComputed) {
|
||||
return t.callExpression(
|
||||
this.file.addHelper("get"),
|
||||
[
|
||||
t.callExpression(
|
||||
t.memberExpression(
|
||||
t.identifier("Object"),
|
||||
t.identifier("getPrototypeOf"),
|
||||
false
|
||||
),
|
||||
[
|
||||
isStatic ?
|
||||
this.className :
|
||||
t.memberExpression(
|
||||
this.className,
|
||||
t.identifier("prototype"),
|
||||
false
|
||||
)
|
||||
]
|
||||
),
|
||||
isComputed ?
|
||||
property :
|
||||
t.literal(property.name),
|
||||
t.thisExpression()
|
||||
]
|
||||
);
|
||||
};
|
||||
|
||||
/**
|
||||
* Replace all `super` references with a reference to our `superClass`.
|
||||
*
|
||||
* @param {Node} methodNode MethodDefinition
|
||||
*/
|
||||
|
||||
Class.prototype.replaceInstanceSuperReferences = function (methodNode) {
|
||||
var method = methodNode.value;
|
||||
var self = this;
|
||||
|
||||
traverse(method, {
|
||||
enter: function (node, parent) {
|
||||
var property;
|
||||
var computed;
|
||||
var args;
|
||||
|
||||
if (t.isIdentifier(node, { name: "super" })) {
|
||||
if (!(t.isMemberExpression(parent) && !parent.computed && parent.property === node)) {
|
||||
throw self.file.errorWithNode(node, "illegal use of bare super");
|
||||
}
|
||||
} else if (t.isCallExpression(node)) {
|
||||
var callee = node.callee;
|
||||
if (t.isIdentifier(callee) && callee.name === "super") {
|
||||
// super(); -> _get(Object.getPrototypeOf(ClassName), "MethodName", this).call(this);
|
||||
property = methodNode.key;
|
||||
computed = methodNode.computed;
|
||||
args = node.arguments;
|
||||
} else {
|
||||
if (!t.isMemberExpression(callee)) return;
|
||||
if (callee.object.name !== "super") return;
|
||||
|
||||
// super.test(); -> _get(Object.getPrototypeOf(ClassName.prototype), "test", this).call(this);
|
||||
property = callee.property;
|
||||
computed = callee.computed;
|
||||
args = node.arguments;
|
||||
}
|
||||
} else if (t.isMemberExpression(node)) {
|
||||
if (!t.isIdentifier(node.object, { name: "super" })) return;
|
||||
|
||||
// super.name; -> _get(Object.getPrototypeOf(ClassName.prototype), "name", this);
|
||||
property = node.property;
|
||||
computed = node.computed;
|
||||
}
|
||||
|
||||
if (property) {
|
||||
var superProperty = self.superProperty(property, methodNode.static, computed);
|
||||
if (args) {
|
||||
return t.callExpression(
|
||||
t.memberExpression(superProperty, t.identifier("call"), false),
|
||||
[t.thisExpression()].concat(args)
|
||||
);
|
||||
} else {
|
||||
return superProperty;
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* Replace the constructor body of our class.
|
||||
*
|
||||
* @param {Node} method MethodDefinition
|
||||
*/
|
||||
|
||||
Class.prototype.pushConstructor = function (method) {
|
||||
if (method.kind !== "") {
|
||||
throw this.file.errorWithNode(method, "illegal kind for constructor method");
|
||||
}
|
||||
|
||||
var construct = this.constructor;
|
||||
var fn = method.value;
|
||||
|
||||
this.hasConstructor = true;
|
||||
|
||||
t.inherits(construct, fn);
|
||||
t.inheritsComments(construct, method);
|
||||
|
||||
construct.defaults = fn.defaults;
|
||||
construct.params = fn.params;
|
||||
construct.body = fn.body;
|
||||
construct.rest = fn.rest;
|
||||
};
|
||||
@@ -1,82 +0,0 @@
|
||||
var traverse = require("../../traverse");
|
||||
var t = require("../../types");
|
||||
var _ = require("lodash");
|
||||
|
||||
exports.Program =
|
||||
exports.BlockStatement =
|
||||
exports.ForInStatement =
|
||||
exports.ForOfStatement =
|
||||
exports.ForStatement = function (node, parent, file) {
|
||||
var hasConstants = false;
|
||||
var constants = {};
|
||||
|
||||
/**
|
||||
* Check the results of `util.getIds` as `names` generated from a
|
||||
* node against it's parent.
|
||||
*/
|
||||
|
||||
var check = function (parent, names, scope) {
|
||||
for (var name in names) {
|
||||
var nameNode = names[name];
|
||||
if (!_.has(constants, name)) continue;
|
||||
if (parent && t.isBlockStatement(parent) && parent !== constants[name]) continue;
|
||||
|
||||
if (scope) {
|
||||
var defined = scope.get(name);
|
||||
if (defined && defined === nameNode) continue;
|
||||
}
|
||||
|
||||
throw file.errorWithNode(nameNode, name + " is read-only");
|
||||
}
|
||||
};
|
||||
|
||||
var getIds = function (node) {
|
||||
return t.getIds(node, true, ["MemberExpression"]);
|
||||
};
|
||||
|
||||
/**
|
||||
* Collect all constants in this scope.
|
||||
*/
|
||||
|
||||
_.each(node.body, function (child, parent) {
|
||||
if (t.isExportDeclaration(child)) {
|
||||
child = child.declaration;
|
||||
}
|
||||
|
||||
if (t.isVariableDeclaration(child, { kind: "const" })) {
|
||||
for (var i in child.declarations) {
|
||||
var declar = child.declarations[i];
|
||||
|
||||
var ids = getIds(declar);
|
||||
for (var name in ids) {
|
||||
var nameNode = ids[name];
|
||||
|
||||
var names = {};
|
||||
names[name] = nameNode;
|
||||
check(parent, names);
|
||||
|
||||
constants[name] = parent;
|
||||
hasConstants = true;
|
||||
}
|
||||
|
||||
declar._ignoreConstant = true;
|
||||
}
|
||||
|
||||
child._ignoreConstant = true;
|
||||
child.kind = "let";
|
||||
}
|
||||
});
|
||||
|
||||
if (!hasConstants) return;
|
||||
|
||||
traverse(node, {
|
||||
enter: function (child, parent, scope) {
|
||||
if (child._ignoreConstant) return;
|
||||
if (t.isVariableDeclaration(child)) return;
|
||||
|
||||
if (t.isVariableDeclarator(child) || t.isDeclaration(child) || t.isAssignmentExpression(child)) {
|
||||
check(parent, getIds(child), scope);
|
||||
}
|
||||
}
|
||||
});
|
||||
};
|
||||
@@ -1,87 +0,0 @@
|
||||
var traverse = require("../../traverse");
|
||||
var util = require("../../util");
|
||||
var t = require("../../types");
|
||||
var _ = require("lodash");
|
||||
|
||||
exports.Function = function (node, parent, file, scope) {
|
||||
if (!node.defaults || !node.defaults.length) return;
|
||||
t.ensureBlock(node);
|
||||
|
||||
var ids = node.params.map(function (param) {
|
||||
return t.getIds(param);
|
||||
});
|
||||
|
||||
var iife = false;
|
||||
var i;
|
||||
var def;
|
||||
|
||||
for (i in node.defaults) {
|
||||
def = node.defaults[i];
|
||||
if (!def) continue;
|
||||
|
||||
var param = node.params[i];
|
||||
|
||||
// temporal dead zone check - here we prevent accessing of params that
|
||||
// are to the right - ie. uninitialized parameters
|
||||
_.each(ids.slice(i), function (ids) {
|
||||
var check = function (node, parent) {
|
||||
if (!t.isIdentifier(node) || !t.isReferenced(node, parent)) return;
|
||||
|
||||
if (ids.indexOf(node.name) >= 0) {
|
||||
throw file.errorWithNode(node, "Temporal dead zone - accessing a variable before it's initialized");
|
||||
}
|
||||
|
||||
if (scope.has(node.name)) {
|
||||
iife = true;
|
||||
}
|
||||
};
|
||||
|
||||
check(def, node);
|
||||
traverse(def, { enter: check });
|
||||
});
|
||||
|
||||
// we're accessing a variable that's already defined within this function
|
||||
var has = scope.get(param.name);
|
||||
if (has && node.params.indexOf(has) < 0) {
|
||||
iife = true;
|
||||
}
|
||||
}
|
||||
|
||||
var body = [];
|
||||
|
||||
var argsIdentifier = t.identifier("arguments");
|
||||
argsIdentifier._ignoreAliasFunctions = true;
|
||||
|
||||
var lastNonDefaultParam = 0;
|
||||
|
||||
for (i in node.defaults) {
|
||||
def = node.defaults[i];
|
||||
if (!def) {
|
||||
lastNonDefaultParam = +i + 1;
|
||||
continue;
|
||||
}
|
||||
|
||||
body.push(util.template("default-parameter", {
|
||||
VARIABLE_NAME: node.params[i],
|
||||
DEFAULT_VALUE: def,
|
||||
ARGUMENT_KEY: t.literal(+i),
|
||||
ARGUMENTS: argsIdentifier
|
||||
}, true));
|
||||
}
|
||||
|
||||
// we need to cut off all trailing default parameters
|
||||
node.params = node.params.slice(0, lastNonDefaultParam);
|
||||
|
||||
if (iife) {
|
||||
var container = t.functionExpression(null, [], node.body, node.generator);
|
||||
container._aliasFunction = true;
|
||||
|
||||
body.push(t.returnStatement(t.callExpression(container, [])));
|
||||
|
||||
node.body = t.blockStatement(body);
|
||||
} else {
|
||||
node.body.body = body.concat(node.body.body);
|
||||
}
|
||||
|
||||
node.defaults = [];
|
||||
};
|
||||
@@ -1,335 +0,0 @@
|
||||
// TODO: Clean up
|
||||
|
||||
var t = require("../../types");
|
||||
|
||||
var buildVariableAssign = function (opts, id, init) {
|
||||
var op = opts.operator;
|
||||
if (t.isMemberExpression(id)) op = "=";
|
||||
|
||||
if (op) {
|
||||
return t.expressionStatement(t.assignmentExpression("=", id, init));
|
||||
} else {
|
||||
return t.variableDeclaration(opts.kind, [
|
||||
t.variableDeclarator(id, init)
|
||||
]);
|
||||
}
|
||||
};
|
||||
|
||||
var push = function (opts, nodes, elem, parentId) {
|
||||
if (t.isObjectPattern(elem)) {
|
||||
pushObjectPattern(opts, nodes, elem, parentId);
|
||||
} else if (t.isArrayPattern(elem)) {
|
||||
pushArrayPattern(opts, nodes, elem, parentId);
|
||||
} else if (t.isAssignmentPattern(elem)) {
|
||||
pushAssignmentPattern(opts, nodes, elem, parentId);
|
||||
} else {
|
||||
nodes.push(buildVariableAssign(opts, elem, parentId));
|
||||
}
|
||||
};
|
||||
|
||||
var pushAssignmentPattern = function (opts, nodes, pattern, parentId) {
|
||||
var tempParentId = opts.scope.generateUidBasedOnNode(parentId, opts.file);
|
||||
|
||||
nodes.push(t.variableDeclaration("var", [
|
||||
t.variableDeclarator(tempParentId, parentId)
|
||||
]));
|
||||
|
||||
nodes.push(buildVariableAssign(
|
||||
opts,
|
||||
pattern.left,
|
||||
t.conditionalExpression(
|
||||
t.binaryExpression("===", tempParentId, t.identifier("undefined")),
|
||||
pattern.right,
|
||||
tempParentId
|
||||
)
|
||||
));
|
||||
};
|
||||
|
||||
var pushObjectPattern = function (opts, nodes, pattern, parentId) {
|
||||
for (var i in pattern.properties) {
|
||||
var prop = pattern.properties[i];
|
||||
if (t.isSpreadProperty(prop)) {
|
||||
// get all the keys that appear in this object before the current spread
|
||||
var keys = [];
|
||||
for (var i2 in pattern.properties) {
|
||||
var prop2 = pattern.properties[i2];
|
||||
|
||||
if (i2 >= i) break;
|
||||
if (t.isSpreadProperty(prop2)) continue;
|
||||
|
||||
var key = prop2.key;
|
||||
if (t.isIdentifier(key)) {
|
||||
key = t.literal(prop2.key.name);
|
||||
}
|
||||
keys.push(key);
|
||||
}
|
||||
keys = t.arrayExpression(keys);
|
||||
|
||||
var value = t.callExpression(opts.file.addHelper("object-without-properties"), [parentId, keys]);
|
||||
nodes.push(buildVariableAssign(opts, prop.argument, value));
|
||||
} else {
|
||||
if (t.isLiteral(prop.key)) prop.computed = true;
|
||||
|
||||
var pattern2 = prop.value;
|
||||
var patternId2 = t.memberExpression(parentId, prop.key, prop.computed);
|
||||
|
||||
if (t.isPattern(pattern2)) {
|
||||
push(opts, nodes, pattern2, patternId2);
|
||||
} else {
|
||||
nodes.push(buildVariableAssign(opts, pattern2, patternId2));
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
var pushArrayPattern = function (opts, nodes, pattern, parentId) {
|
||||
if (!pattern.elements) return;
|
||||
|
||||
var i;
|
||||
|
||||
var hasSpreadElement = false;
|
||||
for (i in pattern.elements) {
|
||||
if (t.isSpreadElement(pattern.elements[i])) {
|
||||
hasSpreadElement = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
var toArray = opts.file.toArray(parentId, !hasSpreadElement && pattern.elements.length);
|
||||
|
||||
var _parentId = opts.scope.generateUidBasedOnNode(parentId, opts.file);
|
||||
nodes.push(t.variableDeclaration("var", [
|
||||
t.variableDeclarator(_parentId, toArray)
|
||||
]));
|
||||
parentId = _parentId;
|
||||
|
||||
for (i in pattern.elements) {
|
||||
var elem = pattern.elements[i];
|
||||
if (!elem) continue;
|
||||
|
||||
i = +i;
|
||||
|
||||
var newPatternId;
|
||||
|
||||
if (t.isSpreadElement(elem)) {
|
||||
newPatternId = opts.file.toArray(parentId);
|
||||
|
||||
if (i > 0) {
|
||||
newPatternId = t.callExpression(t.memberExpression(newPatternId, t.identifier("slice")), [t.literal(i)]);
|
||||
}
|
||||
|
||||
elem = elem.argument;
|
||||
} else {
|
||||
newPatternId = t.memberExpression(parentId, t.literal(i), true);
|
||||
}
|
||||
|
||||
push(opts, nodes, elem, newPatternId);
|
||||
}
|
||||
};
|
||||
|
||||
var pushPattern = function (opts) {
|
||||
var nodes = opts.nodes;
|
||||
var pattern = opts.pattern;
|
||||
var parentId = opts.id;
|
||||
var file = opts.file;
|
||||
var scope = opts.scope;
|
||||
|
||||
if (!t.isArrayExpression(parentId) && !t.isMemberExpression(parentId) && !t.isIdentifier(parentId)) {
|
||||
var key = scope.generateUidBasedOnNode(parentId, file);
|
||||
|
||||
nodes.push(t.variableDeclaration("var", [
|
||||
t.variableDeclarator(key, parentId)
|
||||
]));
|
||||
|
||||
parentId = key;
|
||||
}
|
||||
|
||||
push(opts, nodes, pattern, parentId);
|
||||
};
|
||||
|
||||
exports.ForInStatement =
|
||||
exports.ForOfStatement = function (node, parent, file, scope) {
|
||||
var declar = node.left;
|
||||
if (!t.isVariableDeclaration(declar)) return;
|
||||
|
||||
var pattern = declar.declarations[0].id;
|
||||
if (!t.isPattern(pattern)) return;
|
||||
|
||||
var key = file.generateUidIdentifier("ref", scope);
|
||||
node.left = t.variableDeclaration(declar.kind, [
|
||||
t.variableDeclarator(key, null)
|
||||
]);
|
||||
|
||||
var nodes = [];
|
||||
|
||||
push({
|
||||
kind: declar.kind,
|
||||
file: file,
|
||||
scope: scope
|
||||
}, nodes, pattern, key);
|
||||
|
||||
t.ensureBlock(node);
|
||||
|
||||
var block = node.body;
|
||||
block.body = nodes.concat(block.body);
|
||||
};
|
||||
|
||||
exports.Function = function (node, parent, file, scope) {
|
||||
var nodes = [];
|
||||
|
||||
var hasDestructuring = false;
|
||||
|
||||
node.params = node.params.map(function (pattern) {
|
||||
if (!t.isPattern(pattern)) return pattern;
|
||||
|
||||
hasDestructuring = true;
|
||||
var parentId = file.generateUidIdentifier("ref", scope);
|
||||
|
||||
pushPattern({
|
||||
kind: "var",
|
||||
nodes: nodes,
|
||||
pattern: pattern,
|
||||
id: parentId,
|
||||
file: file,
|
||||
scope: scope
|
||||
});
|
||||
|
||||
return parentId;
|
||||
});
|
||||
|
||||
if (!hasDestructuring) return;
|
||||
|
||||
t.ensureBlock(node);
|
||||
|
||||
var block = node.body;
|
||||
block.body = nodes.concat(block.body);
|
||||
};
|
||||
|
||||
exports.CatchClause = function (node, parent, file, scope) {
|
||||
var pattern = node.param;
|
||||
if (!t.isPattern(pattern)) return;
|
||||
|
||||
var ref = file.generateUidIdentifier("ref", scope);
|
||||
node.param = ref;
|
||||
|
||||
var nodes = [];
|
||||
|
||||
push({
|
||||
kind: "var",
|
||||
file: file,
|
||||
scope: scope
|
||||
}, nodes, pattern, ref);
|
||||
|
||||
node.body.body = nodes.concat(node.body.body);
|
||||
};
|
||||
|
||||
exports.ExpressionStatement = function (node, parent, file, scope) {
|
||||
var expr = node.expression;
|
||||
if (expr.type !== "AssignmentExpression") return;
|
||||
|
||||
if (!t.isPattern(expr.left)) return;
|
||||
|
||||
var nodes = [];
|
||||
|
||||
var ref = file.generateUidIdentifier("ref", scope);
|
||||
nodes.push(t.variableDeclaration("var", [
|
||||
t.variableDeclarator(ref, expr.right)
|
||||
]));
|
||||
|
||||
push({
|
||||
operator: expr.operator,
|
||||
file: file,
|
||||
scope: scope
|
||||
}, nodes, expr.left, ref);
|
||||
|
||||
return nodes;
|
||||
};
|
||||
|
||||
exports.AssignmentExpression = function (node, parent, file, scope) {
|
||||
if (parent.type === "ExpressionStatement") return;
|
||||
if (!t.isPattern(node.left)) return;
|
||||
|
||||
var tempName = file.generateUid("temp", scope);
|
||||
var ref = t.identifier(tempName);
|
||||
scope.push({
|
||||
key: tempName,
|
||||
id: ref
|
||||
});
|
||||
|
||||
var nodes = [];
|
||||
nodes.push(t.assignmentExpression("=", ref, node.right));
|
||||
|
||||
push({
|
||||
operator: node.operator,
|
||||
file: file,
|
||||
scope: scope
|
||||
}, nodes, node.left, ref);
|
||||
|
||||
nodes.push(ref);
|
||||
|
||||
return t.toSequenceExpression(nodes, scope);
|
||||
};
|
||||
|
||||
exports.VariableDeclaration = function (node, parent, file, scope) {
|
||||
if (t.isForInStatement(parent) || t.isForOfStatement(parent)) return;
|
||||
|
||||
var nodes = [];
|
||||
var i;
|
||||
var declar;
|
||||
|
||||
var hasPattern = false;
|
||||
for (i in node.declarations) {
|
||||
declar = node.declarations[i];
|
||||
if (t.isPattern(declar.id)) {
|
||||
hasPattern = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!hasPattern) return;
|
||||
|
||||
for (i in node.declarations) {
|
||||
declar = node.declarations[i];
|
||||
|
||||
var patternId = declar.init;
|
||||
var pattern = declar.id;
|
||||
var opts = {
|
||||
kind: node.kind,
|
||||
nodes: nodes,
|
||||
pattern: pattern,
|
||||
id: patternId,
|
||||
file: file,
|
||||
scope: scope
|
||||
};
|
||||
|
||||
if (t.isPattern(pattern) && patternId) {
|
||||
pushPattern(opts);
|
||||
|
||||
if (+i !== node.declarations.length - 1) {
|
||||
// we aren't the last declarator so let's just make the
|
||||
// last transformed node inherit from us
|
||||
t.inherits(nodes[nodes.length - 1], declar);
|
||||
}
|
||||
} else {
|
||||
nodes.push(t.inherits(buildVariableAssign(opts, declar.id, declar.init), declar));
|
||||
}
|
||||
}
|
||||
|
||||
if (!t.isProgram(parent) && !t.isBlockStatement(parent)) {
|
||||
declar = null;
|
||||
|
||||
for (i in nodes) {
|
||||
node = nodes[i];
|
||||
declar = declar || t.variableDeclaration(node.kind, []);
|
||||
|
||||
if (!t.isVariableDeclaration(node) && declar.kind !== node.kind) {
|
||||
throw file.errorWithNode(node, "Cannot use this node within the current parent");
|
||||
}
|
||||
|
||||
declar.declarations = declar.declarations.concat(node.declarations);
|
||||
}
|
||||
|
||||
return declar;
|
||||
}
|
||||
|
||||
return nodes;
|
||||
};
|
||||
@@ -1,35 +0,0 @@
|
||||
var util = require("../../util");
|
||||
var t = require("../../types");
|
||||
|
||||
exports.ForOfStatement = function (node, parent, file, scope) {
|
||||
var left = node.left;
|
||||
var declar;
|
||||
|
||||
var stepKey = file.generateUidIdentifier("step", scope);
|
||||
var stepValue = t.memberExpression(stepKey, t.identifier("value"));
|
||||
|
||||
if (t.isIdentifier(left)) {
|
||||
declar = t.expressionStatement(t.assignmentExpression("=", left, stepValue));
|
||||
} else if (t.isVariableDeclaration(left)) {
|
||||
declar = t.variableDeclaration(left.kind, [
|
||||
t.variableDeclarator(left.declarations[0].id, stepValue)
|
||||
]);
|
||||
} else {
|
||||
throw file.errorWithNode(left, "Unknown node type " + left.type + " in ForOfStatement");
|
||||
}
|
||||
|
||||
var node2 = util.template("for-of", {
|
||||
ITERATOR_KEY: file.generateUidIdentifier("iterator", scope),
|
||||
STEP_KEY: stepKey,
|
||||
OBJECT: node.right
|
||||
});
|
||||
|
||||
t.inheritsComments(node2, node);
|
||||
t.ensureBlock(node);
|
||||
|
||||
var block = node2.body;
|
||||
block.body.push(declar);
|
||||
block.body = block.body.concat(node.body.body);
|
||||
|
||||
return node2;
|
||||
};
|
||||
@@ -1,3 +0,0 @@
|
||||
exports.ast = {
|
||||
before: require("regenerator").transform
|
||||
};
|
||||
@@ -1,496 +0,0 @@
|
||||
var traverse = require("../../traverse");
|
||||
var util = require("../../util");
|
||||
var t = require("../../types");
|
||||
var _ = require("lodash");
|
||||
|
||||
var isLet = function (node, parent) {
|
||||
if (!t.isVariableDeclaration(node)) return false;
|
||||
if (node._let) return true;
|
||||
if (node.kind !== "let") return false;
|
||||
|
||||
// https://github.com/6to5/6to5/issues/255
|
||||
if (!t.isFor(parent) || t.isFor(parent) && parent.left !== node) {
|
||||
_.each(node.declarations, function (declar) {
|
||||
declar.init = declar.init || t.identifier("undefined");
|
||||
});
|
||||
}
|
||||
|
||||
node._let = true;
|
||||
node.kind = "var";
|
||||
return true;
|
||||
};
|
||||
|
||||
var isVar = function (node, parent) {
|
||||
return t.isVariableDeclaration(node, { kind: "var" }) && !isLet(node, parent);
|
||||
};
|
||||
|
||||
var standardiseLets = function (declars) {
|
||||
for (var i in declars) {
|
||||
delete declars[i]._let;
|
||||
}
|
||||
};
|
||||
|
||||
exports.VariableDeclaration = function (node, parent) {
|
||||
isLet(node, parent);
|
||||
};
|
||||
|
||||
exports.Loop = function (node, parent, file, scope) {
|
||||
var init = node.left || node.init;
|
||||
if (isLet(init, node)) {
|
||||
t.ensureBlock(node);
|
||||
node.body._letDeclars = [init];
|
||||
}
|
||||
|
||||
if (t.isLabeledStatement(parent)) {
|
||||
// set label so `run` has access to it
|
||||
node.label = parent.label;
|
||||
}
|
||||
|
||||
var letScoping = new LetScoping(node, node.body, parent, file, scope);
|
||||
letScoping.run();
|
||||
|
||||
if (node.label && !t.isLabeledStatement(parent)) {
|
||||
// we've been given a label so let's wrap ourselves
|
||||
return t.labeledStatement(node.label, node);
|
||||
}
|
||||
};
|
||||
|
||||
exports.BlockStatement = function (block, parent, file, scope) {
|
||||
if (!t.isLoop(parent)) {
|
||||
var letScoping = new LetScoping(false, block, parent, file, scope);
|
||||
letScoping.run();
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Description
|
||||
*
|
||||
* @param {Boolean|Node} loopParent
|
||||
* @param {Node} block
|
||||
* @param {Node} parent
|
||||
* @param {File} file
|
||||
* @param {Scope} scope
|
||||
*/
|
||||
|
||||
function LetScoping(loopParent, block, parent, file, scope) {
|
||||
this.loopParent = loopParent;
|
||||
this.parent = parent;
|
||||
this.scope = scope;
|
||||
this.block = block;
|
||||
this.file = file;
|
||||
|
||||
this.letReferences = {};
|
||||
this.body = [];
|
||||
}
|
||||
|
||||
/**
|
||||
* Start the ball rolling.
|
||||
*/
|
||||
|
||||
LetScoping.prototype.run = function () {
|
||||
var block = this.block;
|
||||
|
||||
if (block._letDone) return;
|
||||
block._letDone = true;
|
||||
|
||||
this.info = this.getInfo();
|
||||
|
||||
// remap all let references that exist in upper scopes to their uid
|
||||
this.remap();
|
||||
|
||||
// this is a block within a `Function` so we can safely leave it be
|
||||
if (t.isFunction(this.parent)) return this.noClosure();
|
||||
|
||||
// this block has no let references so let's clean up
|
||||
if (!this.info.keys.length) return this.noClosure();
|
||||
|
||||
// returns whether or not there are any outside let references within any
|
||||
// functions
|
||||
var referencesInClosure = this.getLetReferences();
|
||||
|
||||
// no need for a closure so let's clean up
|
||||
if (!referencesInClosure) return this.noClosure();
|
||||
|
||||
// if we're inside of a for loop then we search to see if there are any
|
||||
// `break`s, `continue`s, `return`s etc
|
||||
this.has = this.checkLoop();
|
||||
|
||||
// hoist var references to retain scope
|
||||
this.hoistVarDeclarations();
|
||||
|
||||
// set let references to plain var references
|
||||
standardiseLets(this.info.declarators);
|
||||
|
||||
// turn letReferences into an array
|
||||
var letReferences = _.values(this.letReferences);
|
||||
|
||||
// build the closure that we're going to wrap the block with
|
||||
var fn = t.functionExpression(null, letReferences, t.blockStatement(block.body));
|
||||
fn._aliasFunction = true;
|
||||
|
||||
// replace the current block body with the one we're going to build
|
||||
block.body = this.body;
|
||||
|
||||
// change upper scope references with their uid if they have one
|
||||
var params = this.getParams(letReferences);
|
||||
|
||||
// build a call and a unique id that we can assign the return value to
|
||||
var call = t.callExpression(fn, params);
|
||||
var ret = this.file.generateUidIdentifier("ret", this.scope);
|
||||
|
||||
var hasYield = traverse.hasType(fn.body, "YieldExpression", t.FUNCTION_TYPES);
|
||||
if (hasYield) {
|
||||
fn.generator = true;
|
||||
call = t.yieldExpression(call, true);
|
||||
}
|
||||
|
||||
this.build(ret, call);
|
||||
};
|
||||
|
||||
/**
|
||||
* There are no let references accessed within a closure so we can just turn the
|
||||
* lets into vars.
|
||||
*/
|
||||
|
||||
LetScoping.prototype.noClosure = function () {
|
||||
standardiseLets(this.info.declarators);
|
||||
};
|
||||
|
||||
/**
|
||||
* Traverse through block and replace all references that exist in a higher
|
||||
* scope to their uids.
|
||||
*/
|
||||
|
||||
LetScoping.prototype.remap = function () {
|
||||
var replacements = this.info.duplicates;
|
||||
var block = this.block;
|
||||
|
||||
if (!this.info.hasDuplicates) return;
|
||||
|
||||
var replace = function (node, parent, scope) {
|
||||
if (!t.isIdentifier(node)) return;
|
||||
if (!t.isReferenced(node, parent)) return;
|
||||
if (scope && scope.hasOwn(node.name)) return;
|
||||
node.name = replacements[node.name] || node.name;
|
||||
};
|
||||
|
||||
var traverseReplace = function (node, parent) {
|
||||
replace(node, parent);
|
||||
traverse(node, { enter: replace });
|
||||
};
|
||||
|
||||
var loopParent = this.loopParent;
|
||||
if (loopParent) {
|
||||
traverseReplace(loopParent.right, loopParent);
|
||||
traverseReplace(loopParent.test, loopParent);
|
||||
traverseReplace(loopParent.update, loopParent);
|
||||
}
|
||||
|
||||
traverse(block, { enter: replace });
|
||||
};
|
||||
|
||||
/**
|
||||
* Description
|
||||
*
|
||||
* @returns {Object}
|
||||
*/
|
||||
|
||||
LetScoping.prototype.getInfo = function () {
|
||||
var block = this.block;
|
||||
var scope = this.scope;
|
||||
var file = this.file;
|
||||
|
||||
var opts = {
|
||||
// array of `Identifier` names of let variables that appear lexically out of
|
||||
// this scope but should be accessible - eg. `ForOfStatement`.left
|
||||
outsideKeys: [],
|
||||
|
||||
// array of let `VariableDeclarator`s that are a part of this block
|
||||
declarators: block._letDeclars || [],
|
||||
|
||||
// object of duplicate ids and their aliases - if there's an `Identifier`
|
||||
// name that's used in an upper scope we generate a unique id and replace
|
||||
// all references with it
|
||||
duplicates: {},
|
||||
|
||||
hasDuplicates: false,
|
||||
|
||||
// array of `Identifier` names of let variables that are accessible within
|
||||
// the current block
|
||||
keys: []
|
||||
};
|
||||
|
||||
var duplicates = function (id, key) {
|
||||
var has = scope.parentGet(key);
|
||||
|
||||
if (has && has !== id) {
|
||||
// there's a variable with this exact name in an upper scope so we need
|
||||
// to generate a new name
|
||||
opts.duplicates[key] = id.name = file.generateUid(key, scope);
|
||||
opts.hasDuplicates = true;
|
||||
}
|
||||
};
|
||||
|
||||
var i;
|
||||
var declar;
|
||||
|
||||
for (i in opts.declarators) {
|
||||
declar = opts.declarators[i];
|
||||
opts.declarators.push(declar);
|
||||
|
||||
var keys = t.getIds(declar, true);
|
||||
_.each(keys, duplicates);
|
||||
keys = Object.keys(keys);
|
||||
|
||||
opts.outsideKeys = opts.outsideKeys.concat(keys);
|
||||
opts.keys = opts.keys.concat(keys);
|
||||
}
|
||||
|
||||
for (i in block.body) {
|
||||
declar = block.body[i];
|
||||
if (!isLet(declar, block)) continue;
|
||||
|
||||
_.each(t.getIds(declar, true), function (id, key) {
|
||||
duplicates(id, key);
|
||||
opts.keys.push(key);
|
||||
});
|
||||
}
|
||||
|
||||
return opts;
|
||||
};
|
||||
|
||||
/**
|
||||
* If we're inside of a loop then traverse it and check if it has one of
|
||||
* the following node types `ReturnStatement`, `BreakStatement`,
|
||||
* `ContinueStatement` and replace it with a return value that we can track
|
||||
* later on.
|
||||
*
|
||||
* @returns {Object}
|
||||
*/
|
||||
|
||||
LetScoping.prototype.checkLoop = function () {
|
||||
var has = {
|
||||
hasContinue: false,
|
||||
hasReturn: false,
|
||||
hasBreak: false,
|
||||
};
|
||||
|
||||
traverse(this.block, {
|
||||
enter: function (node, parent) {
|
||||
var replace;
|
||||
|
||||
if (t.isFunction(node) || t.isLoop(node)) {
|
||||
return this.skip();
|
||||
}
|
||||
|
||||
if (node && !node.label) {
|
||||
if (t.isBreakStatement(node)) {
|
||||
if (t.isSwitchCase(parent)) return;
|
||||
|
||||
has.hasBreak = true;
|
||||
replace = t.returnStatement(t.literal("break"));
|
||||
} else if (t.isContinueStatement(node)) {
|
||||
has.hasContinue = true;
|
||||
replace = t.returnStatement(t.literal("continue"));
|
||||
}
|
||||
}
|
||||
|
||||
if (t.isReturnStatement(node)) {
|
||||
has.hasReturn = true;
|
||||
replace = t.returnStatement(t.objectExpression([
|
||||
t.property("init", t.identifier("v"), node.argument || t.identifier("undefined"))
|
||||
]));
|
||||
}
|
||||
|
||||
if (replace) return t.inherits(replace, node);
|
||||
}
|
||||
});
|
||||
|
||||
return has;
|
||||
};
|
||||
|
||||
/**
|
||||
* Hoist all var declarations in this block to before it so they retain scope
|
||||
* once we wrap everything in a closure.
|
||||
*/
|
||||
|
||||
LetScoping.prototype.hoistVarDeclarations = function () {
|
||||
var self = this;
|
||||
traverse(this.block, {
|
||||
enter: function (node, parent) {
|
||||
if (t.isForStatement(node)) {
|
||||
if (isVar(node.init, node)) {
|
||||
node.init = t.sequenceExpression(self.pushDeclar(node.init));
|
||||
}
|
||||
} else if (t.isFor(node)) {
|
||||
if (isVar(node.left, node)) {
|
||||
node.left = node.left.declarations[0].id;
|
||||
}
|
||||
} else if (isVar(node, parent)) {
|
||||
return self.pushDeclar(node).map(t.expressionStatement);
|
||||
} else if (t.isFunction(node)) {
|
||||
return this.skip();
|
||||
}
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* Build up a parameter list that we'll call our closure wrapper with, replacing
|
||||
* all duplicate ids with their uid.
|
||||
*
|
||||
* @param {Array} params
|
||||
* @returns {Array}
|
||||
*/
|
||||
|
||||
LetScoping.prototype.getParams = function (params) {
|
||||
var info = this.info;
|
||||
params = _.cloneDeep(params);
|
||||
_.each(params, function (param) {
|
||||
param.name = info.duplicates[param.name] || param.name;
|
||||
});
|
||||
return params;
|
||||
};
|
||||
|
||||
/**
|
||||
* Get all let references within this block. Stopping whenever we reach another
|
||||
* block.
|
||||
*/
|
||||
|
||||
LetScoping.prototype.getLetReferences = function () {
|
||||
var closurify = false;
|
||||
var self = this;
|
||||
|
||||
// traverse through this block, stopping on functions and checking if they
|
||||
// contain any outside let references
|
||||
traverse(this.block, {
|
||||
enter: function (node, parent, scope) {
|
||||
if (t.isFunction(node)) {
|
||||
traverse(node, {
|
||||
enter: function (node, parent) {
|
||||
// not an identifier so we have no use
|
||||
if (!t.isIdentifier(node)) return;
|
||||
|
||||
// not a direct reference
|
||||
if (!t.isReferenced(node, parent)) return;
|
||||
|
||||
// this scope has a variable with the same name so it couldn't belong
|
||||
// to our let scope
|
||||
if (scope.hasOwn(node.name, true)) return;
|
||||
|
||||
closurify = true;
|
||||
|
||||
// this key doesn't appear just outside our scope
|
||||
if (!_.contains(self.info.outsideKeys, node.name)) return;
|
||||
|
||||
// push this badboy
|
||||
self.letReferences[node.name] = node;
|
||||
}
|
||||
});
|
||||
|
||||
return this.skip();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
return closurify;
|
||||
};
|
||||
|
||||
/**
|
||||
* Turn a `VariableDeclaration` into an array of `AssignmentExpressions` with
|
||||
* their declarations hoisted to before the closure wrapper.
|
||||
*
|
||||
* @param {Node} node VariableDeclaration
|
||||
* @returns {Array}
|
||||
*/
|
||||
|
||||
LetScoping.prototype.pushDeclar = function (node) {
|
||||
this.body.push(t.variableDeclaration(node.kind, node.declarations.map(function (declar) {
|
||||
return t.variableDeclarator(declar.id);
|
||||
})));
|
||||
|
||||
var replace = [];
|
||||
|
||||
for (var i in node.declarations) {
|
||||
var declar = node.declarations[i];
|
||||
if (!declar.init) continue;
|
||||
|
||||
var expr = t.assignmentExpression("=", declar.id, declar.init);
|
||||
replace.push(t.inherits(expr, declar));
|
||||
}
|
||||
|
||||
return replace;
|
||||
};
|
||||
|
||||
/**
|
||||
* Push the closure to the body.
|
||||
*
|
||||
* @param {Node} ret Identifier
|
||||
* @param {Node} call CallExpression
|
||||
*/
|
||||
|
||||
LetScoping.prototype.build = function (ret, call) {
|
||||
var has = this.has;
|
||||
if (has.hasReturn || has.hasBreak || has.hasContinue) {
|
||||
this.buildHas(ret, call);
|
||||
} else {
|
||||
this.body.push(t.expressionStatement(call));
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Description
|
||||
*
|
||||
* @param {Node} ret Identifier
|
||||
* @param {Node} call CallExpression
|
||||
*/
|
||||
|
||||
LetScoping.prototype.buildHas = function (ret, call) {
|
||||
var body = this.body;
|
||||
|
||||
body.push(t.variableDeclaration("var", [
|
||||
t.variableDeclarator(ret, call)
|
||||
]));
|
||||
|
||||
var loopParent = this.loopParent;
|
||||
var retCheck;
|
||||
var has = this.has;
|
||||
var cases = [];
|
||||
|
||||
if (has.hasReturn) {
|
||||
// typeof ret === "object"
|
||||
retCheck = util.template("let-scoping-return", {
|
||||
RETURN: ret
|
||||
});
|
||||
}
|
||||
|
||||
if (has.hasBreak || has.hasContinue) {
|
||||
// ensure that the parent has a label as we're building a switch and we
|
||||
// need to be able to access it
|
||||
var label = loopParent.label = loopParent.label || this.file.generateUidIdentifier("loop", this.scope);
|
||||
|
||||
if (has.hasBreak) {
|
||||
cases.push(t.switchCase(t.literal("break"), [t.breakStatement(label)]));
|
||||
}
|
||||
|
||||
if (has.hasContinue) {
|
||||
cases.push(t.switchCase(t.literal("continue"), [t.continueStatement(label)]));
|
||||
}
|
||||
|
||||
if (has.hasReturn) {
|
||||
cases.push(t.switchCase(null, [retCheck]));
|
||||
}
|
||||
|
||||
if (cases.length === 1) {
|
||||
var single = cases[0];
|
||||
body.push(t.ifStatement(
|
||||
t.binaryExpression("===", ret, single.test),
|
||||
single.consequent[0]
|
||||
));
|
||||
} else {
|
||||
body.push(t.switchStatement(ret, cases));
|
||||
}
|
||||
} else {
|
||||
if (has.hasReturn) body.push(retCheck);
|
||||
}
|
||||
};
|
||||
@@ -1,82 +0,0 @@
|
||||
var traverse = require("../../traverse");
|
||||
var util = require("../../util");
|
||||
var t = require("../../types");
|
||||
|
||||
exports.Property = function (node, parent, file, scope) {
|
||||
if (!node.method) return;
|
||||
|
||||
node.method = false;
|
||||
|
||||
var key = t.toComputedKey(node, node.key);
|
||||
if (!t.isLiteral(key)) return; // we can't set a function id with this
|
||||
|
||||
var id = t.toIdentifier(key.value);
|
||||
key = t.identifier(id);
|
||||
|
||||
var selfReference = false;
|
||||
var outerDeclar = scope.get(id, true);
|
||||
|
||||
traverse(node, {
|
||||
enter: function (node, parent, scope) {
|
||||
// check if this node is an identifier that matches the same as our function id
|
||||
if (!t.isIdentifier(node, { name: id })) return;
|
||||
|
||||
// check if this node is the one referenced
|
||||
if (!t.isReferenced(node, parent)) return;
|
||||
|
||||
// check that we don't have a local variable declared as that removes the need
|
||||
// for the wrapper
|
||||
var localDeclar = scope.get(id, true);
|
||||
if (localDeclar !== outerDeclar) return;
|
||||
|
||||
selfReference = true;
|
||||
this.stop();
|
||||
}
|
||||
}, scope);
|
||||
|
||||
if (selfReference) {
|
||||
node.value = util.template("property-method-assignment-wrapper", {
|
||||
FUNCTION: node.value,
|
||||
FUNCTION_ID: key,
|
||||
FUNCTION_KEY: file.generateUidIdentifier(id, scope),
|
||||
WRAPPER_KEY: file.generateUidIdentifier(id + "Wrapper", scope)
|
||||
});
|
||||
} else {
|
||||
node.value.id = key;
|
||||
}
|
||||
};
|
||||
|
||||
exports.ObjectExpression = function (node, parent, file, scope) {
|
||||
var mutatorMap = {};
|
||||
var hasAny = false;
|
||||
|
||||
node.properties = node.properties.filter(function (prop) {
|
||||
if (prop.kind === "get" || prop.kind === "set") {
|
||||
hasAny = true;
|
||||
util.pushMutatorMap(mutatorMap, prop.key, prop.kind, prop.computed, prop.value);
|
||||
return false;
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
});
|
||||
|
||||
if (!hasAny) return;
|
||||
|
||||
if (node.properties.length) {
|
||||
var objId = scope.generateUidBasedOnNode(parent, file);
|
||||
|
||||
return util.template("object-define-properties-closure", {
|
||||
KEY: objId,
|
||||
OBJECT: node,
|
||||
CONTENT: util.template("object-define-properties", {
|
||||
OBJECT: objId,
|
||||
PROPS: util.buildDefineProperties(mutatorMap)
|
||||
})
|
||||
});
|
||||
} else {
|
||||
return util.template("object-define-properties", {
|
||||
OBJECT: node,
|
||||
PROPS: util.buildDefineProperties(mutatorMap)
|
||||
});
|
||||
}
|
||||
};
|
||||
@@ -1,8 +0,0 @@
|
||||
var t = require("../../types");
|
||||
var _ = require("lodash");
|
||||
|
||||
exports.Property = function (node) {
|
||||
if (!node.shorthand) return;
|
||||
node.shorthand = false;
|
||||
node.key = t.removeComments(_.clone(node.key));
|
||||
};
|
||||
@@ -1,36 +0,0 @@
|
||||
var util = require("../../util");
|
||||
var t = require("../../types");
|
||||
|
||||
exports.Function = function (node, parent, file) {
|
||||
if (!node.rest) return;
|
||||
|
||||
var rest = node.rest;
|
||||
delete node.rest;
|
||||
|
||||
t.ensureBlock(node);
|
||||
|
||||
var argsId = t.identifier("arguments");
|
||||
argsId._ignoreAliasFunctions = true;
|
||||
|
||||
var start = t.literal(node.params.length);
|
||||
var key = file.generateUidIdentifier("key");
|
||||
|
||||
var arrKey = key;
|
||||
if (node.params.length) {
|
||||
arrKey = t.binaryExpression("-", arrKey, start);
|
||||
}
|
||||
|
||||
node.body.body.unshift(
|
||||
t.variableDeclaration("var", [
|
||||
t.variableDeclarator(rest, t.arrayExpression([]))
|
||||
]),
|
||||
|
||||
util.template("rest", {
|
||||
ARGUMENTS: argsId,
|
||||
ARRAY_KEY: arrKey,
|
||||
START: start,
|
||||
ARRAY: rest,
|
||||
KEY: key
|
||||
})
|
||||
);
|
||||
};
|
||||
@@ -1,62 +0,0 @@
|
||||
var traverse = require("../../traverse");
|
||||
var util = require("../../util");
|
||||
var t = require("../../types");
|
||||
|
||||
exports.experimental = true;
|
||||
|
||||
var build = function (node, parent, file, scope) {
|
||||
var uid = scope.generateUidBasedOnNode(parent, file);
|
||||
|
||||
var container = util.template("array-comprehension-container", {
|
||||
KEY: uid
|
||||
});
|
||||
container.callee._aliasFunction = true;
|
||||
|
||||
var block = container.callee.body;
|
||||
var body = block.body;
|
||||
|
||||
if (traverse.hasType(node, "YieldExpression", t.FUNCTION_TYPES)) {
|
||||
container.callee.generator = true;
|
||||
container = t.yieldExpression(container, true);
|
||||
}
|
||||
|
||||
var returnStatement = body.pop();
|
||||
|
||||
body.push(exports._build(node, function () {
|
||||
return util.template("array-push", {
|
||||
STATEMENT: node.body,
|
||||
KEY: uid
|
||||
}, true);
|
||||
}));
|
||||
body.push(returnStatement);
|
||||
|
||||
return container;
|
||||
};
|
||||
|
||||
exports._build = function (node, buildBody) {
|
||||
var self = node.blocks.shift();
|
||||
if (!self) return;
|
||||
|
||||
var child = exports._build(node, buildBody);
|
||||
if (!child) {
|
||||
// last item
|
||||
child = buildBody();
|
||||
|
||||
// add a filter as this is our final stop
|
||||
if (node.filter) {
|
||||
child = t.ifStatement(node.filter, t.blockStatement([child]));
|
||||
}
|
||||
}
|
||||
|
||||
return t.forOfStatement(
|
||||
t.variableDeclaration("let", [t.variableDeclarator(self.left)]),
|
||||
self.right,
|
||||
t.blockStatement([child])
|
||||
);
|
||||
};
|
||||
|
||||
exports.ComprehensionExpression = function (node, parent, file, scope) {
|
||||
if (node.generator) return;
|
||||
|
||||
return build(node, parent, file, scope);
|
||||
};
|
||||
@@ -1,18 +0,0 @@
|
||||
// https://github.com/rwaldron/exponentiation-operator
|
||||
|
||||
exports.experimental = true;
|
||||
|
||||
var t = require("../../types");
|
||||
var pow = t.memberExpression(t.identifier("Math"), t.identifier("pow"));
|
||||
|
||||
exports.AssignmentExpression = function (node) {
|
||||
if (node.operator !== "**=") return;
|
||||
node.operator = "=";
|
||||
node.right = t.callExpression(pow, [node.left, node.right]);
|
||||
};
|
||||
|
||||
exports.BinaryExpression = function (node) {
|
||||
if (node.operator !== "**") return;
|
||||
|
||||
return t.callExpression(pow, [node.left, node.right]);
|
||||
};
|
||||
@@ -1,18 +0,0 @@
|
||||
var arrayComprehension = require("./es7-array-comprehension");
|
||||
var t = require("../../types");
|
||||
|
||||
exports.experimental = true;
|
||||
|
||||
exports.ComprehensionExpression = function (node) {
|
||||
if (!node.generator) return;
|
||||
|
||||
var body = [];
|
||||
var container = t.functionExpression(null, [], t.blockStatement(body), true);
|
||||
container._aliasFunction = true;
|
||||
|
||||
body.push(arrayComprehension._build(node, function () {
|
||||
return t.expressionStatement(t.yieldExpression(node.body));
|
||||
}));
|
||||
|
||||
return t.callExpression(container, []);
|
||||
};
|
||||
@@ -1,11 +0,0 @@
|
||||
var bluebirdCoroutines = require("./optional-bluebird-coroutines");
|
||||
|
||||
exports.optional = true;
|
||||
|
||||
exports.manipulateOptions = bluebirdCoroutines.manipulateOptions;
|
||||
|
||||
exports.Function = function (node, parent, file) {
|
||||
if (!node.async || node.generator) return;
|
||||
|
||||
return bluebirdCoroutines._Function(node, file.addHelper("async-to-generator"));
|
||||
};
|
||||
@@ -1,43 +0,0 @@
|
||||
var traverse = require("../../traverse");
|
||||
var t = require("../../types");
|
||||
|
||||
exports.manipulateOptions = function (opts) {
|
||||
opts.experimental = true;
|
||||
opts.blacklist.push("generators");
|
||||
};
|
||||
|
||||
exports.optional = true;
|
||||
|
||||
exports._Function = function (node, callId) {
|
||||
node.async = false;
|
||||
node.generator = true;
|
||||
|
||||
traverse(node, {
|
||||
enter: function (node) {
|
||||
if (t.isFunction(node)) this.skip();
|
||||
|
||||
if (t.isAwaitExpression(node)) {
|
||||
node.type = "YieldExpression";
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
var call = t.callExpression(callId, [node]);
|
||||
|
||||
if (t.isFunctionDeclaration(node)) {
|
||||
var declar = t.variableDeclaration("var", [
|
||||
t.variableDeclarator(node.id, call)
|
||||
]);
|
||||
declar._blockHoist = true;
|
||||
return declar;
|
||||
} else {
|
||||
return call;
|
||||
}
|
||||
};
|
||||
|
||||
exports.Function = function (node, parent, file) {
|
||||
if (!node.async || node.generator) return;
|
||||
|
||||
var id = file.addImport("bluebird");
|
||||
return exports._Function(node, t.memberExpression(id, t.identifier("coroutine")));
|
||||
};
|
||||
@@ -1,58 +0,0 @@
|
||||
var traverse = require("../../traverse");
|
||||
var util = require("../../util");
|
||||
var core = require("core-js/library");
|
||||
var t = require("../../types");
|
||||
var _ = require("lodash");
|
||||
|
||||
var coreHas = function (node) {
|
||||
return node.name !== "_" && _.has(core, node.name);
|
||||
};
|
||||
|
||||
exports.optional = true;
|
||||
|
||||
exports.ast = {
|
||||
enter: function (ast, file) {
|
||||
file._coreId = file.addImport("core-js/library", "core");
|
||||
},
|
||||
|
||||
exit: function (ast, file) {
|
||||
traverse(ast, {
|
||||
enter: function (node, parent) {
|
||||
var prop;
|
||||
|
||||
if (t.isMemberExpression(node) && t.isReferenced(node, parent)) {
|
||||
// Array.from -> _core.Array.from
|
||||
var obj = node.object;
|
||||
prop = node.property;
|
||||
|
||||
if (!t.isReferenced(obj, node)) return;
|
||||
|
||||
if (!node.computed && coreHas(obj) && _.has(core[obj.name], prop.name)) {
|
||||
this.skip();
|
||||
return t.prependToMemberExpression(node, file._coreId);
|
||||
}
|
||||
} else if (t.isIdentifier(node) && !t.isMemberExpression(parent) && t.isReferenced(node, parent) && coreHas(node)) {
|
||||
// new Promise -> new _core.Promise
|
||||
return t.memberExpression(file._coreId, node);
|
||||
} else if (t.isCallExpression(node)) {
|
||||
// arr[Symbol.iterator]() -> _core.$for.getIterator(arr)
|
||||
|
||||
if (node.arguments.length) return;
|
||||
|
||||
var callee = node.callee;
|
||||
if (!t.isMemberExpression(callee)) return;
|
||||
if (!callee.computed) return;
|
||||
|
||||
prop = callee.property;
|
||||
if (!t.isIdentifier(prop.object, { name: "Symbol" })) return;
|
||||
if (!t.isIdentifier(prop.property, { name: "iterator" })) return;
|
||||
|
||||
return util.template("corejs-iterator", {
|
||||
CORE_ID: file._coreId,
|
||||
VALUE: callee.object
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
};
|
||||
@@ -1,9 +0,0 @@
|
||||
var t = require("../../types");
|
||||
|
||||
exports.optional = true;
|
||||
|
||||
exports.UnaryExpression = function (node, parent, file) {
|
||||
if (node.operator === "typeof") {
|
||||
return t.callExpression(file.addHelper("typeof"), [node.argument]);
|
||||
}
|
||||
};
|
||||
@@ -1,86 +0,0 @@
|
||||
var t = require("../../types");
|
||||
|
||||
var isMemo = function (node) {
|
||||
var is = t.isAssignmentExpression(node) && node.operator === "?=";
|
||||
if (is) t.assertMemberExpression(node.left);
|
||||
return is;
|
||||
};
|
||||
|
||||
var getPropRef = function (nodes, prop, file, scope) {
|
||||
if (t.isIdentifier(prop)) {
|
||||
return t.literal(prop.name);
|
||||
} else {
|
||||
var temp = scope.generateUidBasedOnNode(prop, file);
|
||||
nodes.push(t.variableDeclaration("var", [
|
||||
t.variableDeclarator(temp, prop)
|
||||
]));
|
||||
return temp;
|
||||
}
|
||||
};
|
||||
|
||||
var getObjRef = function (nodes, obj, file, scope) {
|
||||
var temp = scope.generateUidBasedOnNode(obj, file);
|
||||
nodes.push(t.variableDeclaration("var", [
|
||||
t.variableDeclarator(temp, obj)
|
||||
]));
|
||||
return temp;
|
||||
};
|
||||
|
||||
var buildHasOwn = function (obj, prop, file) {
|
||||
return t.unaryExpression(
|
||||
"!",
|
||||
t.callExpression(
|
||||
t.memberExpression(file.addHelper("has-own"), t.identifier("call")),
|
||||
[obj, prop]
|
||||
),
|
||||
true
|
||||
);
|
||||
};
|
||||
|
||||
var buildAbsoluteRef = function (left, obj, prop) {
|
||||
var computed = left.computed || t.isLiteral(prop);
|
||||
return t.memberExpression(obj, prop, computed);
|
||||
};
|
||||
|
||||
var buildAssignment = function (expr, obj, prop) {
|
||||
return t.assignmentExpression("=", buildAbsoluteRef(expr.left, obj, prop), expr.right);
|
||||
};
|
||||
|
||||
exports.ExpressionStatement = function (node, parent, file, scope) {
|
||||
var expr = node.expression;
|
||||
if (!isMemo(expr)) return;
|
||||
|
||||
var nodes = [];
|
||||
|
||||
var left = expr.left;
|
||||
var obj = getObjRef(nodes, left.object, file, scope);
|
||||
var prop = getPropRef(nodes, left.property, file, scope);
|
||||
|
||||
nodes.push(t.ifStatement(
|
||||
buildHasOwn(obj, prop, file),
|
||||
t.expressionStatement(buildAssignment(expr, obj, prop))
|
||||
));
|
||||
|
||||
return nodes;
|
||||
};
|
||||
|
||||
exports.AssignmentExpression = function (node, parent, file, scope) {
|
||||
if (t.isExpressionStatement(parent)) return;
|
||||
if (!isMemo(node)) return;
|
||||
|
||||
var nodes = [];
|
||||
|
||||
var left = node.left;
|
||||
var obj = getObjRef(nodes, left.object, file, scope);
|
||||
var prop = getPropRef(nodes, left.property, file, scope);
|
||||
|
||||
nodes.push(t.logicalExpression(
|
||||
"&&",
|
||||
buildHasOwn(obj, prop, file),
|
||||
buildAssignment(node, obj, prop)
|
||||
));
|
||||
|
||||
nodes.push(buildAbsoluteRef(left, obj, prop));
|
||||
|
||||
return t.toSequenceExpression(nodes, scope);
|
||||
};
|
||||
@@ -1,31 +0,0 @@
|
||||
var traverse = require("../../traverse");
|
||||
var t = require("../../types");
|
||||
|
||||
exports.Property =
|
||||
exports.MethodDefinition = function (node, parent, file) {
|
||||
if (node.kind !== "memo") return;
|
||||
node.kind = "get";
|
||||
|
||||
var value = node.value;
|
||||
t.ensureBlock(value);
|
||||
|
||||
var key = node.key;
|
||||
|
||||
if (t.isIdentifier(key) && !node.computed) {
|
||||
key = t.literal(key.name);
|
||||
}
|
||||
|
||||
traverse(value, {
|
||||
enter: function (node) {
|
||||
if (t.isFunction(node)) return;
|
||||
|
||||
if (t.isReturnStatement(node) && node.argument) {
|
||||
node.argument = t.memberExpression(t.callExpression(file.addHelper("define-property"), [
|
||||
t.thisExpression(),
|
||||
key,
|
||||
node.argument
|
||||
]), key, true);
|
||||
}
|
||||
}
|
||||
});
|
||||
};
|
||||
239
lib/6to5/transformation/transformers/react.js
vendored
239
lib/6to5/transformation/transformers/react.js
vendored
@@ -1,239 +0,0 @@
|
||||
// Based upon the excellent jsx-transpiler by Ingvar Stepanyan (RReverser)
|
||||
// https://github.com/RReverser/jsx-transpiler
|
||||
|
||||
// jsx
|
||||
|
||||
var esutils = require("esutils");
|
||||
var t = require("../../types");
|
||||
|
||||
exports.XJSIdentifier = function (node) {
|
||||
if (esutils.keyword.isIdentifierName(node.name)) {
|
||||
node.type = "Identifier";
|
||||
} else {
|
||||
return t.literal(node.name);
|
||||
}
|
||||
};
|
||||
|
||||
exports.XJSNamespacedName = function (node, parent, file) {
|
||||
throw file.errorWithNode(node, "Namespace tags are not supported. ReactJSX is not XML.");
|
||||
};
|
||||
|
||||
exports.XJSMemberExpression = {
|
||||
exit: function (node) {
|
||||
node.computed = t.isLiteral(node.property);
|
||||
node.type = "MemberExpression";
|
||||
}
|
||||
};
|
||||
|
||||
exports.XJSExpressionContainer = function (node) {
|
||||
return node.expression;
|
||||
};
|
||||
|
||||
exports.XJSAttribute = {
|
||||
exit: function (node) {
|
||||
var value = node.value || t.literal(true);
|
||||
return t.inherits(t.property("init", node.name, value), node);
|
||||
}
|
||||
};
|
||||
|
||||
var isTag = function(tagName) {
|
||||
return (/^[a-z]|\-/).test(tagName);
|
||||
};
|
||||
|
||||
exports.XJSOpeningElement = {
|
||||
exit: function (node, parent, file) {
|
||||
var reactCompat = file.opts.reactCompat;
|
||||
var tagExpr = node.name;
|
||||
var args = [];
|
||||
|
||||
var tagName;
|
||||
if (t.isIdentifier(tagExpr)) {
|
||||
tagName = tagExpr.name;
|
||||
} else if (t.isLiteral(tagExpr)) {
|
||||
tagName = tagExpr.value;
|
||||
}
|
||||
|
||||
if (!reactCompat) {
|
||||
if (tagName && isTag(tagName)) {
|
||||
args.push(t.literal(tagName));
|
||||
} else {
|
||||
args.push(tagExpr);
|
||||
}
|
||||
}
|
||||
|
||||
var props = node.attributes;
|
||||
if (props.length) {
|
||||
var _props = [];
|
||||
var objs = [];
|
||||
|
||||
var pushProps = function () {
|
||||
if (!_props.length) return;
|
||||
|
||||
objs.push(t.objectExpression(_props));
|
||||
_props = [];
|
||||
};
|
||||
|
||||
while (props.length) {
|
||||
var prop = props.shift();
|
||||
if (t.isXJSSpreadAttribute(prop)) {
|
||||
pushProps();
|
||||
objs.push(prop.argument);
|
||||
} else {
|
||||
_props.push(prop);
|
||||
}
|
||||
}
|
||||
|
||||
pushProps();
|
||||
|
||||
if (objs.length === 1) {
|
||||
props = objs[0];
|
||||
} else {
|
||||
if (!t.isObjectExpression(objs[0])) {
|
||||
objs.unshift(t.objectExpression([]));
|
||||
}
|
||||
|
||||
props = t.callExpression(
|
||||
t.memberExpression(t.identifier("React"), t.identifier("__spread")),
|
||||
objs
|
||||
);
|
||||
}
|
||||
} else {
|
||||
props = t.literal(null);
|
||||
}
|
||||
|
||||
args.push(props);
|
||||
|
||||
if (reactCompat) {
|
||||
if (tagName && isTag(tagName)) {
|
||||
return t.callExpression(
|
||||
t.memberExpression(
|
||||
t.memberExpression(t.identifier("React"), t.identifier("DOM")),
|
||||
tagExpr,
|
||||
t.isLiteral(tagExpr)
|
||||
),
|
||||
args
|
||||
);
|
||||
}
|
||||
} else {
|
||||
tagExpr = t.memberExpression(t.identifier("React"), t.identifier("createElement"));
|
||||
}
|
||||
|
||||
return t.callExpression(tagExpr, args);
|
||||
}
|
||||
};
|
||||
|
||||
exports.XJSElement = {
|
||||
exit: function (node) {
|
||||
var callExpr = node.openingElement;
|
||||
var i;
|
||||
|
||||
for (i in node.children) {
|
||||
var child = node.children[i];
|
||||
|
||||
if (t.isLiteral(child)) {
|
||||
var lines = child.value.split(/\r\n|\n|\r/);
|
||||
|
||||
for (i in lines) {
|
||||
var line = lines[i];
|
||||
|
||||
var isFirstLine = i === "0";
|
||||
var isLastLine = +i === lines.length - 1;
|
||||
|
||||
// replace rendered whitespace tabs with spaces
|
||||
var trimmedLine = line.replace(/\t/g, " ");
|
||||
|
||||
// trim whitespace touching a newline
|
||||
if (!isFirstLine) {
|
||||
trimmedLine = trimmedLine.replace(/^[ ]+/, "");
|
||||
}
|
||||
|
||||
// trim whitespace touching an endline
|
||||
if (!isLastLine) {
|
||||
trimmedLine = trimmedLine.replace(/[ ]+$/, "");
|
||||
}
|
||||
|
||||
if (trimmedLine) {
|
||||
callExpr.arguments.push(t.literal(trimmedLine));
|
||||
}
|
||||
}
|
||||
|
||||
continue;
|
||||
} else if (t.isXJSEmptyExpression(child)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
callExpr.arguments.push(child);
|
||||
}
|
||||
|
||||
if (callExpr.arguments.length >= 3) {
|
||||
callExpr._prettyCall = true;
|
||||
}
|
||||
|
||||
return t.inherits(callExpr, node);
|
||||
}
|
||||
};
|
||||
|
||||
// display names
|
||||
|
||||
var addDisplayName = function (id, call) {
|
||||
if (!call || !t.isCallExpression(call)) return;
|
||||
|
||||
var callee = call.callee;
|
||||
if (!t.isMemberExpression(callee)) return;
|
||||
|
||||
// not React
|
||||
var obj = callee.object;
|
||||
if (!t.isIdentifier(obj, { name: "React" })) return;
|
||||
|
||||
// not createClass
|
||||
var prop = callee.property;
|
||||
if (!t.isIdentifier(prop, { name: "createClass" })) return;
|
||||
|
||||
// no arguments
|
||||
var args = call.arguments;
|
||||
if (args.length !== 1) return;
|
||||
|
||||
// not an object
|
||||
var first = args[0];
|
||||
if (!t.isObjectExpression(first)) return;
|
||||
|
||||
var props = first.properties;
|
||||
var safe = true;
|
||||
|
||||
for (var i in props) {
|
||||
prop = props[i];
|
||||
if (t.isIdentifier(prop.key, { name: "displayName" })) {
|
||||
safe = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (safe) {
|
||||
props.unshift(t.property("init", t.identifier("displayName"), t.literal(id)));
|
||||
}
|
||||
};
|
||||
|
||||
exports.AssignmentExpression =
|
||||
exports.Property =
|
||||
exports.VariableDeclarator = function (node) {
|
||||
var left, right;
|
||||
|
||||
if (t.isAssignmentExpression(node)) {
|
||||
left = node.left;
|
||||
right = node.right;
|
||||
} else if (t.isProperty(node)) {
|
||||
left = node.key;
|
||||
right = node.value;
|
||||
} else if (t.isVariableDeclarator(node)) {
|
||||
left = node.id;
|
||||
right = node.init;
|
||||
}
|
||||
|
||||
if (t.isMemberExpression(left)) {
|
||||
left = left.property;
|
||||
}
|
||||
|
||||
if (t.isIdentifier(left)) {
|
||||
addDisplayName(left.name, right);
|
||||
}
|
||||
};
|
||||
@@ -1,10 +0,0 @@
|
||||
var t = require("../../types");
|
||||
|
||||
exports.ForInStatement =
|
||||
exports.ForOfStatement = function (node, parent, file) {
|
||||
var left = node.left;
|
||||
if (t.isVariableDeclaration(left)) {
|
||||
var declar = left.declarations[0];
|
||||
if (declar.init) throw file.errorWithNode(declar, "No assignments allowed in for-in/of head");
|
||||
}
|
||||
};
|
||||
@@ -1,179 +0,0 @@
|
||||
module.exports = traverse;
|
||||
|
||||
var Scope = require("./scope");
|
||||
var t = require("../types");
|
||||
var _ = require("lodash");
|
||||
|
||||
function traverse(parent, opts, scope) {
|
||||
// falsy node
|
||||
if (!parent) return;
|
||||
|
||||
// array of nodes
|
||||
if (_.isArray(parent)) {
|
||||
_.each(parent, function (node) {
|
||||
traverse(node, opts, scope);
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
// unknown node type to traverse
|
||||
var keys = t.VISITOR_KEYS[parent.type];
|
||||
if (!keys) return;
|
||||
|
||||
opts = opts || {};
|
||||
|
||||
var stopped = false;
|
||||
|
||||
for (var i in keys) {
|
||||
var key = keys[i];
|
||||
var nodes = parent[key];
|
||||
if (!nodes) continue;
|
||||
|
||||
var flatten = false;
|
||||
|
||||
var handle = function (obj, key) {
|
||||
var node = obj[key];
|
||||
if (!node) return;
|
||||
|
||||
// type is blacklisted
|
||||
if (opts.blacklist && opts.blacklist.indexOf(node.type) > -1) return;
|
||||
|
||||
// replace node
|
||||
var maybeReplace = function (result) {
|
||||
if (result === false) return;
|
||||
if (result == null) return;
|
||||
|
||||
var isArray = _.isArray(result);
|
||||
|
||||
// inherit comments from original node to the first replacement node
|
||||
var inheritTo = result;
|
||||
if (isArray) inheritTo = result[0];
|
||||
if (inheritTo) t.inheritsComments(inheritTo, node);
|
||||
|
||||
// replace the node
|
||||
node = obj[key] = result;
|
||||
|
||||
if (isArray) flatten = true;
|
||||
|
||||
// we're replacing a statement or block node with an array of statements so we better
|
||||
// ensure that it's a block
|
||||
if (isArray && _.contains(t.STATEMENT_OR_BLOCK_KEYS, key) && !t.isBlockStatement(obj)) {
|
||||
t.ensureBlock(obj, key);
|
||||
}
|
||||
};
|
||||
|
||||
var skipped = false;
|
||||
var removed = false;
|
||||
|
||||
var context = {
|
||||
stop: function () {
|
||||
skipped = stopped = true;
|
||||
},
|
||||
|
||||
skip: function () {
|
||||
skipped = true;
|
||||
},
|
||||
|
||||
remove: function () {
|
||||
this.skip();
|
||||
removed = true;
|
||||
}
|
||||
};
|
||||
|
||||
//
|
||||
var ourScope = scope;
|
||||
if (t.isScope(node)) ourScope = new Scope(node, scope);
|
||||
|
||||
// enter
|
||||
if (opts.enter) {
|
||||
var result = opts.enter.call(context, node, parent, ourScope);
|
||||
maybeReplace(result);
|
||||
|
||||
if (removed) {
|
||||
obj[key] = null;
|
||||
flatten = true;
|
||||
}
|
||||
|
||||
// stop iteration
|
||||
if (skipped) return;
|
||||
}
|
||||
|
||||
// traverse node
|
||||
traverse(node, opts, ourScope);
|
||||
|
||||
// exit
|
||||
if (opts.exit) {
|
||||
maybeReplace(opts.exit.call(context, node, parent, ourScope));
|
||||
}
|
||||
};
|
||||
|
||||
if (_.isArray(nodes)) {
|
||||
for (i in nodes) {
|
||||
handle(nodes, i);
|
||||
if (stopped) return;
|
||||
}
|
||||
|
||||
if (flatten) {
|
||||
parent[key] = _.flatten(parent[key]);
|
||||
|
||||
if (key === "body") {
|
||||
// we can safely compact this
|
||||
parent[key] = _.compact(parent[key]);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
handle(parent, key);
|
||||
if (stopped) return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
traverse.removeProperties = function (tree) {
|
||||
var clear = function (node) {
|
||||
delete node._declarations;
|
||||
delete node.extendedRange;
|
||||
delete node._scopeInfo;
|
||||
delete node.tokens;
|
||||
delete node.range;
|
||||
delete node.start;
|
||||
delete node.end;
|
||||
delete node.loc;
|
||||
delete node.raw;
|
||||
|
||||
clearComments(node.trailingComments);
|
||||
clearComments(node.leadingComments);
|
||||
};
|
||||
|
||||
var clearComments = function (comments) {
|
||||
_.each(comments, clear);
|
||||
};
|
||||
|
||||
clear(tree);
|
||||
traverse(tree, { enter: clear });
|
||||
|
||||
return tree;
|
||||
};
|
||||
|
||||
traverse.hasType = function (tree, type, blacklistTypes) {
|
||||
blacklistTypes = [].concat(blacklistTypes || []);
|
||||
|
||||
var has = false;
|
||||
|
||||
// the node we're searching in is blacklisted
|
||||
if (_.contains(blacklistTypes, tree.type)) return false;
|
||||
|
||||
// the type we're looking for is the same as the passed node
|
||||
if (tree.type === type) return true;
|
||||
|
||||
traverse(tree, {
|
||||
blacklist: blacklistTypes,
|
||||
enter: function (node) {
|
||||
if (node.type === type) {
|
||||
has = true;
|
||||
this.skip();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
return has;
|
||||
};
|
||||
@@ -1,303 +0,0 @@
|
||||
module.exports = Scope;
|
||||
|
||||
var traverse = require("./index");
|
||||
var t = require("../types");
|
||||
var _ = require("lodash");
|
||||
|
||||
var FOR_KEYS = ["left", "init"];
|
||||
|
||||
/**
|
||||
* This searches the current "scope" and collects all references/declarations
|
||||
* within.
|
||||
*
|
||||
* @param {Node} block
|
||||
* @param {Scope} [parent]
|
||||
*/
|
||||
|
||||
function Scope(block, parent) {
|
||||
this.parent = parent;
|
||||
this.block = block;
|
||||
|
||||
var info = this.getInfo();
|
||||
this.references = info.references;
|
||||
this.declarations = info.declarations;
|
||||
}
|
||||
|
||||
var vars = require("jshint/src/vars");
|
||||
Scope.defaultDeclarations = _.flatten([vars.newEcmaIdentifiers, vars.node, vars.ecmaIdentifiers, vars.reservedVars].map(_.keys));
|
||||
|
||||
Scope.add = function (node, references) {
|
||||
if (!node) return;
|
||||
_.defaults(references, t.getIds(node, true));
|
||||
};
|
||||
|
||||
/**
|
||||
* Description
|
||||
*
|
||||
* @param {File} file
|
||||
* @param {String} [name="temp"]
|
||||
*/
|
||||
|
||||
Scope.prototype.generateTemp = function (file, name) {
|
||||
var id = file.generateUidIdentifier(name || "temp", this);
|
||||
this.push({
|
||||
key: id.name,
|
||||
id: id
|
||||
});
|
||||
return id;
|
||||
};
|
||||
|
||||
/*
|
||||
* Description
|
||||
*
|
||||
* @param {Object} parent
|
||||
* @param {File} file
|
||||
* @param {Scope} scope
|
||||
* @returns {Object}
|
||||
*/
|
||||
|
||||
Scope.prototype.generateUidBasedOnNode = function (parent, file) {
|
||||
var node = parent;
|
||||
|
||||
if (t.isAssignmentExpression(parent)) {
|
||||
node = parent.left;
|
||||
} else if (t.isVariableDeclarator(parent)) {
|
||||
node = parent.id;
|
||||
} else if (t.isProperty(node)) {
|
||||
node = node.key;
|
||||
}
|
||||
|
||||
var parts = [];
|
||||
|
||||
var add = function (node) {
|
||||
if (t.isMemberExpression(node)) {
|
||||
add(node.object);
|
||||
add(node.property);
|
||||
} else if (t.isIdentifier(node)) {
|
||||
parts.push(node.name);
|
||||
} else if (t.isLiteral(node)) {
|
||||
parts.push(node.value);
|
||||
} else if (t.isCallExpression(node)) {
|
||||
add(node.callee);
|
||||
}
|
||||
};
|
||||
|
||||
add(node);
|
||||
|
||||
var id = parts.join("$");
|
||||
id = id.replace(/^_/, "") || "ref";
|
||||
|
||||
return file.generateUidIdentifier(id, this);
|
||||
};
|
||||
|
||||
/**
|
||||
* Description
|
||||
*
|
||||
* @param {Object} node
|
||||
* @param {File} file
|
||||
* @returns {Object}
|
||||
*/
|
||||
|
||||
Scope.prototype.generateTempBasedOnNode = function (node, file) {
|
||||
if (t.isIdentifier(node) && this.has(node.name, true)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
var id = this.generateUidBasedOnNode(node, file);
|
||||
this.push({
|
||||
key: id.name,
|
||||
id: id
|
||||
});
|
||||
return id;
|
||||
};
|
||||
|
||||
Scope.prototype.getInfo = function () {
|
||||
var block = this.block;
|
||||
if (block._scopeInfo) return block._scopeInfo;
|
||||
|
||||
var info = block._scopeInfo = {};
|
||||
var references = info.references = {};
|
||||
var declarations = info.declarations = {};
|
||||
|
||||
var add = function (node, reference) {
|
||||
Scope.add(node, references);
|
||||
if (!reference) Scope.add(node, declarations);
|
||||
};
|
||||
|
||||
// ForStatement - left, init
|
||||
|
||||
if (t.isFor(block)) {
|
||||
_.each(FOR_KEYS, function (key) {
|
||||
var node = block[key];
|
||||
if (t.isLet(node)) add(node);
|
||||
});
|
||||
|
||||
block = block.body;
|
||||
}
|
||||
|
||||
// Program, BlockStatement - let variables
|
||||
|
||||
if (t.isBlockStatement(block) || t.isProgram(block)) {
|
||||
_.each(block.body, function (node) {
|
||||
// check for non-var `VariableDeclaration`s
|
||||
if (t.isLet(node)) add(node);
|
||||
});
|
||||
}
|
||||
|
||||
// CatchClause - param
|
||||
|
||||
if (t.isCatchClause(block)) {
|
||||
add(block.param);
|
||||
}
|
||||
|
||||
// Program, Function - var variables
|
||||
|
||||
if (t.isProgram(block) || t.isFunction(block)) {
|
||||
traverse(block, {
|
||||
enter: function (node, parent, scope) {
|
||||
if (t.isFor(node)) {
|
||||
_.each(FOR_KEYS, function (key) {
|
||||
var declar = node[key];
|
||||
if (t.isVar(declar)) add(declar);
|
||||
});
|
||||
}
|
||||
|
||||
// this block is a function so we'll stop since none of the variables
|
||||
// declared within are accessible
|
||||
if (t.isFunction(node)) return this.skip();
|
||||
|
||||
// function identifier doesn't belong to this scope
|
||||
if (block.id && node === block.id) return;
|
||||
|
||||
if (t.isIdentifier(node) && t.isReferenced(node, parent) && !scope.has(node.name)) {
|
||||
add(node, true);
|
||||
}
|
||||
|
||||
// we've ran into a declaration!
|
||||
// we'll let the BlockStatement scope deal with `let` declarations unless
|
||||
if (t.isDeclaration(node) && !t.isLet(node)) {
|
||||
add(node);
|
||||
}
|
||||
}
|
||||
}, this);
|
||||
}
|
||||
|
||||
// Function - params, rest
|
||||
|
||||
if (t.isFunction(block)) {
|
||||
add(block.rest);
|
||||
_.each(block.params, function (param) {
|
||||
add(param);
|
||||
});
|
||||
}
|
||||
|
||||
return info;
|
||||
};
|
||||
|
||||
/**
|
||||
* Description
|
||||
*
|
||||
* @param {Object} opts
|
||||
*/
|
||||
|
||||
Scope.prototype.push = function (opts) {
|
||||
var block = this.block;
|
||||
|
||||
if (t.isFor(block) || t.isCatchClause(block) || t.isFunction(block)) {
|
||||
t.ensureBlock(block);
|
||||
block = block.body;
|
||||
}
|
||||
|
||||
if (t.isBlockStatement(block) || t.isProgram(block)) {
|
||||
block._declarations = block._declarations || {};
|
||||
block._declarations[opts.key] = {
|
||||
kind: opts.kind,
|
||||
id: opts.id,
|
||||
init: opts.init
|
||||
};
|
||||
} else {
|
||||
throw new TypeError("cannot add a declaration here in node type " + block.type);
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Description
|
||||
*
|
||||
* @param {Object} node
|
||||
*/
|
||||
|
||||
Scope.prototype.add = function (node) {
|
||||
Scope.add(node, this.references);
|
||||
};
|
||||
|
||||
/**
|
||||
* Description
|
||||
*
|
||||
* @param {String} [id]
|
||||
* @param {Boolean} [decl]
|
||||
*/
|
||||
|
||||
Scope.prototype.get = function (id, decl) {
|
||||
return id && (this.getOwn(id, decl) || this.parentGet(id, decl));
|
||||
};
|
||||
|
||||
/**
|
||||
* Description
|
||||
*
|
||||
* @param {String} [id]
|
||||
* @param {Boolean} [decl]
|
||||
*/
|
||||
|
||||
Scope.prototype.getOwn = function (id, decl) {
|
||||
var refs = this.references;
|
||||
if (decl) refs = this.declarations;
|
||||
return _.has(refs, id) && refs[id];
|
||||
};
|
||||
|
||||
/**
|
||||
* Description
|
||||
*
|
||||
* @param {String} [id]
|
||||
* @param {Boolean} [decl]
|
||||
*/
|
||||
|
||||
Scope.prototype.parentGet = function (id, decl) {
|
||||
return this.parent && this.parent.get(id, decl);
|
||||
};
|
||||
|
||||
/**
|
||||
* Description
|
||||
*
|
||||
* @param {String} [id]
|
||||
* @param {Boolean} [decl]
|
||||
* @returns {Boolean}
|
||||
*/
|
||||
|
||||
Scope.prototype.has = function (id, decl) {
|
||||
return (id && (this.hasOwn(id, decl) || this.parentHas(id, decl))) ||
|
||||
_.contains(Scope.defaultDeclarations, id);
|
||||
};
|
||||
|
||||
/**
|
||||
* Description
|
||||
*
|
||||
* @param {String} [id]
|
||||
* @param {Boolean} [decl]
|
||||
* @returns {Boolean}
|
||||
*/
|
||||
|
||||
Scope.prototype.hasOwn = function (id, decl) {
|
||||
return !!this.getOwn(id, decl);
|
||||
};
|
||||
|
||||
/**
|
||||
* Description
|
||||
*
|
||||
* @param {String} [id]
|
||||
* @param {Boolean} [decl]
|
||||
* @returns {Boolean}
|
||||
*/
|
||||
|
||||
Scope.prototype.parentHas = function (id, decl) {
|
||||
return this.parent && this.parent.has(id, decl);
|
||||
};
|
||||
@@ -1,70 +0,0 @@
|
||||
{
|
||||
"ExpressionStatement": ["Statement"],
|
||||
"BreakStatement": ["Statement"],
|
||||
"ContinueStatement": ["Statement"],
|
||||
"DebuggerStatement": ["Statement"],
|
||||
"DoWhileStatement": ["Statement", "Loop", "While"],
|
||||
"IfStatement": ["Statement"],
|
||||
"ReturnStatement": ["Statement"],
|
||||
"SwitchStatement": ["Statement"],
|
||||
"ThrowStatement": ["Statement"],
|
||||
"TryStatement": ["Statement"],
|
||||
"WhileStatement": ["Statement", "Loop", "While"],
|
||||
"WithStatement": ["Statement"],
|
||||
"EmptyStatement": ["Statement"],
|
||||
"LabeledStatement": ["Statement"],
|
||||
"VariableDeclaration": ["Statement", "Declaration"],
|
||||
"ExportDeclaration": ["Statement", "Declaration"],
|
||||
"ImportDeclaration": ["Statement", "Declaration"],
|
||||
|
||||
"ArrowFunctionExpression": ["Scope", "Function", "Expression"],
|
||||
"FunctionDeclaration": ["Statement", "Declaration", "Scope", "Function"],
|
||||
"FunctionExpression": ["Scope", "Function", "Expression"],
|
||||
|
||||
"BlockStatement": ["Statement", "Scope"],
|
||||
"Program": ["Scope"],
|
||||
"CatchClause": ["Scope"],
|
||||
|
||||
"LogicalExpression": ["Binary", "Expression"],
|
||||
"BinaryExpression": ["Binary", "Expression"],
|
||||
|
||||
"UnaryExpression": ["UnaryLike", "Expression"],
|
||||
"SpreadProperty": ["UnaryLike"],
|
||||
"SpreadElement": ["UnaryLike"],
|
||||
|
||||
"ClassDeclaration": ["Statement", "Declaration", "Class"],
|
||||
"ClassExpression": ["Class", "Expression"],
|
||||
|
||||
"ForOfStatement": ["Statement", "For", "Scope", "Loop"],
|
||||
"ForInStatement": ["Statement", "For", "Scope", "Loop"],
|
||||
"ForStatement": ["Statement", "For", "Scope", "Loop"],
|
||||
|
||||
"ObjectPattern": ["Pattern"],
|
||||
"ArrayPattern": ["Pattern"],
|
||||
"AssignmentPattern": ["Pattern"],
|
||||
|
||||
"Property": ["UserWhitespacable"],
|
||||
"XJSElement": ["UserWhitespacable", "Expression"],
|
||||
|
||||
"ArrayExpression": ["Expression"],
|
||||
"AssignmentExpression": ["Expression"],
|
||||
"AwaitExpression": ["Expression"],
|
||||
"BindFunctionExpression": ["Expression"],
|
||||
"BindMemberExpression": ["Expression"],
|
||||
"CallExpression": ["Expression"],
|
||||
"ComprehensionExpression": ["Expression"],
|
||||
"ConditionalExpression": ["Expression"],
|
||||
"Identifier": ["Expression"],
|
||||
"Literal": ["Expression"],
|
||||
"MemberExpression": ["Expression"],
|
||||
"NewExpression": ["Expression"],
|
||||
"ObjectExpression": ["Expression"],
|
||||
"SequenceExpression": ["Expression"],
|
||||
"TaggedTemplateExpression": ["Expression"],
|
||||
"ThisExpression": ["Expression"],
|
||||
"UpdateExpression": ["Expression"],
|
||||
"VirtualPropertyExpression": ["Expression"],
|
||||
"XJSEmptyExpression": ["Expression"],
|
||||
"XJSMemberExpression": ["Expression"],
|
||||
"YieldExpression": ["Expression"]
|
||||
}
|
||||
@@ -1,31 +0,0 @@
|
||||
{
|
||||
"ArrayExpression": ["elements"],
|
||||
"ArrowFunctionExpression": ["params", "body"],
|
||||
"AssignmentExpression": ["operator", "left", "right"],
|
||||
"BinaryExpression": ["operator", "left", "right"],
|
||||
"BlockStatement": ["body"],
|
||||
"CallExpression": ["callee", "arguments"],
|
||||
"ConditionalExpression": ["test", "consequent", "alternate"],
|
||||
"ExpressionStatement": ["expression"],
|
||||
"File": ["program", "comments", "tokens"],
|
||||
"FunctionExpression": ["id", "params", "body", "generator"],
|
||||
"Identifier": ["name"],
|
||||
"IfStatement": ["test", "consequent", "alternate"],
|
||||
"ImportDeclaration": ["specifiers", "source"],
|
||||
"ImportSpecifier": ["id", "name"],
|
||||
"Literal": ["value"],
|
||||
"LogicalExpression": ["operator", "left", "right"],
|
||||
"MemberExpression": ["object", "property", "computed"],
|
||||
"NewExpression": ["callee", "arguments"],
|
||||
"ObjectExpression": ["properties"],
|
||||
"Program": ["body"],
|
||||
"Property": ["kind", "key", "value", "computed"],
|
||||
"ReturnStatement": ["argument"],
|
||||
"SequenceExpression": ["expressions"],
|
||||
"ThrowExpression": ["argument"],
|
||||
"UnaryExpression": ["operator", "argument", "prefix"],
|
||||
"VariableDeclaration": ["kind", "declarations"],
|
||||
"VariableDeclarator": ["id", "init"],
|
||||
"WithStatement": ["object", "body"],
|
||||
"YieldExpression": ["argument", "delegate"]
|
||||
}
|
||||
@@ -1,498 +0,0 @@
|
||||
var esutils = require("esutils");
|
||||
var _ = require("lodash");
|
||||
|
||||
var t = exports;
|
||||
|
||||
t.NATIVE_TYPE_NAMES = ["Array", "Object", "Number", "Boolean", "Date", "Array", "String"];
|
||||
|
||||
//
|
||||
|
||||
var addAssert = function (type, is) {
|
||||
t["assert" + type] = function (node, opts) {
|
||||
opts = opts || {};
|
||||
if (!is(node, opts)) {
|
||||
throw new Error("Expected type " + JSON.stringify(type) + " with option " + JSON.stringify(opts));
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
t.STATEMENT_OR_BLOCK_KEYS = ["consequent", "body"];
|
||||
|
||||
//
|
||||
|
||||
t.VISITOR_KEYS = require("./visitor-keys");
|
||||
|
||||
_.each(t.VISITOR_KEYS, function (keys, type) {
|
||||
var is = t["is" + type] = function (node, opts) {
|
||||
return node && node.type === type && t.shallowEqual(node, opts);
|
||||
};
|
||||
|
||||
addAssert(type, is);
|
||||
});
|
||||
|
||||
//
|
||||
|
||||
t.BUILDER_KEYS = _.defaults(require("./builder-keys"), t.VISITOR_KEYS);
|
||||
|
||||
_.each(t.BUILDER_KEYS, function (keys, type) {
|
||||
t[type[0].toLowerCase() + type.slice(1)] = function () {
|
||||
var args = arguments;
|
||||
var node = { type: type };
|
||||
_.each(keys, function (key, i) {
|
||||
node[key] = args[i];
|
||||
});
|
||||
return node;
|
||||
};
|
||||
});
|
||||
|
||||
//
|
||||
|
||||
t.ALIAS_KEYS = require("./alias-keys");
|
||||
|
||||
t.FLIPPED_ALIAS_KEYS = {};
|
||||
|
||||
_.each(t.ALIAS_KEYS, function (aliases, type) {
|
||||
_.each(aliases, function (alias) {
|
||||
var types = t.FLIPPED_ALIAS_KEYS[alias] = t.FLIPPED_ALIAS_KEYS[alias] || [];
|
||||
types.push(type);
|
||||
});
|
||||
});
|
||||
|
||||
_.each(t.FLIPPED_ALIAS_KEYS, function (types, type) {
|
||||
t[type.toUpperCase() + "_TYPES"] = types;
|
||||
|
||||
var is = t["is" + type] = function (node, opts) {
|
||||
return node && types.indexOf(node.type) >= 0 && t.shallowEqual(node, opts);
|
||||
};
|
||||
|
||||
addAssert(type, is);
|
||||
});
|
||||
|
||||
/**
|
||||
* Description
|
||||
*
|
||||
* @param {Object} node
|
||||
* @returns {Object}
|
||||
*/
|
||||
|
||||
t.toComputedKey = function (node, key) {
|
||||
if (!node.computed) {
|
||||
if (t.isIdentifier(key)) key = t.literal(key.name);
|
||||
}
|
||||
return key;
|
||||
};
|
||||
|
||||
/*
|
||||
* Shallowly checks to see if the passed `node` will evaluate to a
|
||||
* falsy. This is if `node` is a `Literal` and `value` is falsy or
|
||||
* `node` is an `Identifier` with a name of `undefiend`.
|
||||
*
|
||||
* @param {Object} node
|
||||
* @returns {Boolean}
|
||||
*/
|
||||
|
||||
t.isFalsyExpression = function (node) {
|
||||
if (t.isLiteral(node)) {
|
||||
return !node.value;
|
||||
} else if (t.isIdentifier(node)) {
|
||||
return node.name === "undefined";
|
||||
}
|
||||
return false;
|
||||
};
|
||||
|
||||
/**
|
||||
* Turn an array of statement `nodes` into a `SequenceExpression`.
|
||||
*
|
||||
* Variable declarations are turned into simple assignments and their
|
||||
* declarations hoisted to the top of the current scope.
|
||||
*
|
||||
* Expression statements are just resolved to their standard expression.
|
||||
*/
|
||||
|
||||
t.toSequenceExpression = function (nodes, scope) {
|
||||
var exprs = [];
|
||||
|
||||
_.each(nodes, function (node) {
|
||||
if (t.isExpression(node)) {
|
||||
exprs.push(node);
|
||||
} if (t.isExpressionStatement(node)) {
|
||||
exprs.push(node.expression);
|
||||
} else if (t.isVariableDeclaration(node)) {
|
||||
_.each(node.declarations, function (declar) {
|
||||
scope.push({
|
||||
kind: node.kind,
|
||||
key: declar.id.name,
|
||||
id: declar.id
|
||||
});
|
||||
exprs.push(t.assignmentExpression("=", declar.id, declar.init));
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
if (exprs.length === 1) {
|
||||
return exprs[0];
|
||||
} else {
|
||||
return t.sequenceExpression(exprs);
|
||||
}
|
||||
};
|
||||
|
||||
//
|
||||
|
||||
t.shallowEqual = function (actual, expected) {
|
||||
var same = true;
|
||||
|
||||
if (expected) {
|
||||
_.each(expected, function (val, key) {
|
||||
if (actual[key] !== val) {
|
||||
return same = false;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
return same;
|
||||
};
|
||||
|
||||
/**
|
||||
* Description
|
||||
*
|
||||
* @param {Object} member
|
||||
* @param {Object} append
|
||||
* @param {Boolean} [computed]
|
||||
* @returns {Object} member
|
||||
*/
|
||||
|
||||
t.appendToMemberExpression = function (member, append, computed) {
|
||||
member.object = t.memberExpression(member.object, member.property, member.computed);
|
||||
member.property = append;
|
||||
member.computed = !!computed;
|
||||
return member;
|
||||
};
|
||||
|
||||
/**
|
||||
* Description
|
||||
*
|
||||
* @param {Object} member
|
||||
* @param {Object} append
|
||||
* @returns {Object} member
|
||||
*/
|
||||
|
||||
t.prependToMemberExpression = function (member, append) {
|
||||
member.object = t.memberExpression(append, member.object);
|
||||
return member;
|
||||
};
|
||||
|
||||
/**
|
||||
* Description
|
||||
*
|
||||
* @param {Object} node
|
||||
* @param {Object} parent
|
||||
* @returns {Boolean}
|
||||
*/
|
||||
|
||||
t.isReferenced = function (node, parent) {
|
||||
// we're a property key and we aren't computed so we aren't referenced
|
||||
if (t.isProperty(parent) && parent.key === node && !parent.computed) return false;
|
||||
|
||||
// we're a variable declarator id so we aren't referenced
|
||||
if (t.isVariableDeclarator(parent) && parent.id === node) return false;
|
||||
|
||||
var isMemberExpression = t.isMemberExpression(parent);
|
||||
|
||||
// we're in a member expression and we're the computed property so we're referenced
|
||||
var isComputedProperty = isMemberExpression && parent.property === node && parent.computed;
|
||||
|
||||
// we're in a member expression and we're the object so we're referenced
|
||||
var isObject = isMemberExpression && parent.object === node;
|
||||
|
||||
// we are referenced
|
||||
if (!isMemberExpression || isComputedProperty || isObject) return true;
|
||||
|
||||
return false;
|
||||
};
|
||||
|
||||
/**
|
||||
* Description
|
||||
*
|
||||
* @param {String} name
|
||||
* @returns {Boolean}
|
||||
*/
|
||||
|
||||
t.isValidIdentifier = function (name) {
|
||||
return _.isString(name) && esutils.keyword.isIdentifierName(name) && !esutils.keyword.isReservedWordES6(name, true);
|
||||
};
|
||||
|
||||
/*
|
||||
* Description
|
||||
*
|
||||
* @param {String} name
|
||||
* @returns {String}
|
||||
*/
|
||||
|
||||
t.toIdentifier = function (name) {
|
||||
if (t.isIdentifier(name)) return name.name;
|
||||
|
||||
name = name + "";
|
||||
|
||||
// replace all non-valid identifiers with dashes
|
||||
name = name.replace(/[^a-zA-Z0-9$_]/g, "-");
|
||||
|
||||
// remove all dashes and numbers from start of name
|
||||
name = name.replace(/^[-0-9]+/, "");
|
||||
|
||||
// camel case
|
||||
name = name.replace(/[-_\s]+(.)?/g, function (match, c) {
|
||||
return c ? c.toUpperCase() : "";
|
||||
});
|
||||
|
||||
// remove underscores from start of name
|
||||
name = name.replace(/^\_/, "");
|
||||
|
||||
if (!t.isValidIdentifier(name)) {
|
||||
name = "_" + name;
|
||||
}
|
||||
|
||||
return name || '_';
|
||||
};
|
||||
|
||||
/**
|
||||
* Description
|
||||
*
|
||||
* @param {Object} node
|
||||
* @param {String} key
|
||||
*/
|
||||
|
||||
t.ensureBlock = function (node, key) {
|
||||
key = key || "body";
|
||||
node[key] = t.toBlock(node[key], node);
|
||||
};
|
||||
|
||||
/**
|
||||
* Description
|
||||
*
|
||||
* @param {Object} node
|
||||
* @param {Boolean} [ignore]
|
||||
* @returns {Object|Boolean}
|
||||
*/
|
||||
|
||||
t.toStatement = function (node, ignore) {
|
||||
if (t.isStatement(node)) {
|
||||
return node;
|
||||
}
|
||||
|
||||
var mustHaveId = false;
|
||||
var newType;
|
||||
|
||||
if (t.isClass(node)) {
|
||||
mustHaveId = true;
|
||||
newType = "ClassDeclaration";
|
||||
} else if (t.isFunction(node)) {
|
||||
mustHaveId = true;
|
||||
newType = "FunctionDeclaration";
|
||||
}
|
||||
|
||||
if (mustHaveId && !node.id) {
|
||||
newType = false;
|
||||
}
|
||||
|
||||
if (!newType) {
|
||||
if (ignore) {
|
||||
return false;
|
||||
} else {
|
||||
throw new Error("cannot turn " + node.type + " to a statement");
|
||||
}
|
||||
}
|
||||
|
||||
node.type = newType;
|
||||
|
||||
return node;
|
||||
};
|
||||
|
||||
/**
|
||||
* Description
|
||||
*
|
||||
* @param {Object} node
|
||||
* @param {Object} parent
|
||||
* @returns {Object}
|
||||
*/
|
||||
|
||||
t.toBlock = function (node, parent) {
|
||||
if (t.isBlockStatement(node)) {
|
||||
return node;
|
||||
}
|
||||
|
||||
if (!_.isArray(node)) {
|
||||
if (!t.isStatement(node)) {
|
||||
if (t.isFunction(parent)) {
|
||||
node = t.returnStatement(node);
|
||||
} else {
|
||||
node = t.expressionStatement(node);
|
||||
}
|
||||
}
|
||||
|
||||
node = [node];
|
||||
}
|
||||
|
||||
return t.blockStatement(node);
|
||||
};
|
||||
|
||||
/**
|
||||
* Description
|
||||
*
|
||||
* @param {Object} node
|
||||
* @param {Boolean} [map]
|
||||
* @param {Array} [ignoreTypes]
|
||||
* @returns {Array|Object}
|
||||
*/
|
||||
|
||||
t.getIds = function (node, map, ignoreTypes) {
|
||||
ignoreTypes = ignoreTypes || [];
|
||||
|
||||
var search = [].concat(node);
|
||||
var ids = {};
|
||||
|
||||
while (search.length) {
|
||||
var id = search.shift();
|
||||
if (!id) continue;
|
||||
if (_.contains(ignoreTypes, id.type)) continue;
|
||||
|
||||
var nodeKeys = t.getIds.nodes[id.type];
|
||||
var arrKeys = t.getIds.arrays[id.type];
|
||||
|
||||
var i, key;
|
||||
|
||||
if (t.isIdentifier(id)) {
|
||||
ids[id.name] = id;
|
||||
} else if (nodeKeys) {
|
||||
for (i in nodeKeys) {
|
||||
key = nodeKeys[i];
|
||||
if (id[key]) {
|
||||
search.push(id[key]);
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else if (arrKeys) {
|
||||
for (i in arrKeys) {
|
||||
key = arrKeys[i];
|
||||
search = search.concat(id[key] || []);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!map) ids = _.keys(ids);
|
||||
return ids;
|
||||
};
|
||||
|
||||
t.getIds.nodes = {
|
||||
AssignmentExpression: ["left"],
|
||||
ImportBatchSpecifier: ["name"],
|
||||
ImportSpecifier: ["name", "id"],
|
||||
ExportSpecifier: ["name", "id"],
|
||||
VariableDeclarator: ["id"],
|
||||
FunctionDeclaration: ["id"],
|
||||
ClassDeclaration: ["id"],
|
||||
MemeberExpression: ["object"],
|
||||
SpreadElement: ["argument"],
|
||||
Property: ["value"]
|
||||
};
|
||||
|
||||
t.getIds.arrays = {
|
||||
ExportDeclaration: ["specifiers", "declaration"],
|
||||
ImportDeclaration: ["specifiers"],
|
||||
VariableDeclaration: ["declarations"],
|
||||
ArrayPattern: ["elements"],
|
||||
ObjectPattern: ["properties"]
|
||||
};
|
||||
|
||||
/**
|
||||
* Description
|
||||
*
|
||||
* @param {Object} node
|
||||
* @returns {Boolean}
|
||||
*/
|
||||
|
||||
t.isLet = function (node) {
|
||||
return t.isVariableDeclaration(node) && (node.kind !== "var" || node._let);
|
||||
};
|
||||
|
||||
/**
|
||||
* Description
|
||||
*
|
||||
* @param {Object} node
|
||||
* @returns {Boolean}
|
||||
*/
|
||||
|
||||
t.isVar = function (node) {
|
||||
return t.isVariableDeclaration(node, { kind: "var" }) && !node._let;
|
||||
};
|
||||
|
||||
//
|
||||
|
||||
t.COMMENT_KEYS = ["leadingComments", "trailingComments"];
|
||||
|
||||
/**
|
||||
* Description
|
||||
*
|
||||
* @param {Object} child
|
||||
* @returns {Object} child
|
||||
*/
|
||||
|
||||
t.removeComments = function (child) {
|
||||
_.each(t.COMMENT_KEYS, function (key) {
|
||||
delete child[key];
|
||||
});
|
||||
return child;
|
||||
};
|
||||
|
||||
/**
|
||||
* Description
|
||||
*
|
||||
* @param {Object} child
|
||||
* @param {Object} parent
|
||||
* @returns {Object} child
|
||||
*/
|
||||
|
||||
t.inheritsComments = function (child, parent) {
|
||||
_.each(t.COMMENT_KEYS, function (key) {
|
||||
child[key] = _.uniq(_.compact([].concat(child[key], parent[key])));
|
||||
});
|
||||
return child;
|
||||
};
|
||||
|
||||
/**
|
||||
* Description
|
||||
*
|
||||
* @param {Object} child
|
||||
* @param {Object} parent
|
||||
* @returns {Object} child
|
||||
*/
|
||||
|
||||
t.inherits = function (child, parent) {
|
||||
child.loc = parent.loc;
|
||||
child.end = parent.end;
|
||||
child.range = parent.range;
|
||||
child.start = parent.start;
|
||||
t.inheritsComments(child, parent);
|
||||
return child;
|
||||
};
|
||||
|
||||
/**
|
||||
* Description
|
||||
*
|
||||
* @param {Object} specifier
|
||||
* @returns {String}
|
||||
*/
|
||||
|
||||
t.getSpecifierName = function (specifier) {
|
||||
return specifier.name || specifier.id;
|
||||
};
|
||||
|
||||
/**
|
||||
* Description
|
||||
*
|
||||
* @param {Object} specifier
|
||||
* @returns {Boolean}
|
||||
*/
|
||||
|
||||
t.isSpecifierDefault = function (specifier) {
|
||||
return t.isIdentifier(specifier.id) && specifier.id.name === "default";
|
||||
};
|
||||
281
lib/6to5/util.js
281
lib/6to5/util.js
@@ -1,281 +0,0 @@
|
||||
require("./patch");
|
||||
|
||||
var estraverse = require("estraverse");
|
||||
var traverse = require("./traverse");
|
||||
var acorn = require("acorn-6to5");
|
||||
var path = require("path");
|
||||
var util = require("util");
|
||||
var fs = require("fs");
|
||||
var t = require("./types");
|
||||
var _ = require("lodash");
|
||||
|
||||
exports.inherits = util.inherits;
|
||||
|
||||
exports.canCompile = function (filename, altExts) {
|
||||
var exts = altExts || [".js", ".jsx", ".es6", ".es"];
|
||||
var ext = path.extname(filename);
|
||||
return _.contains(exts, ext);
|
||||
};
|
||||
|
||||
exports.isInteger = function (i) {
|
||||
return _.isNumber(i) && i % 1 === 0;
|
||||
};
|
||||
|
||||
exports.resolve = function (loc) {
|
||||
try {
|
||||
return require.resolve(loc);
|
||||
} catch (err) {
|
||||
return null;
|
||||
}
|
||||
};
|
||||
|
||||
exports.trimRight = function (str) {
|
||||
return str.replace(/[\n\s]+$/g, "");
|
||||
};
|
||||
|
||||
exports.list = function (val) {
|
||||
return val ? val.split(",") : [];
|
||||
};
|
||||
|
||||
exports.regexify = function (val) {
|
||||
if (!val) return new RegExp(/.^/);
|
||||
if (_.isArray(val)) val = val.join("|");
|
||||
if (_.isString(val)) return new RegExp(val);
|
||||
if (_.isRegExp(val)) return val;
|
||||
throw new TypeError("illegal type for regexify");
|
||||
};
|
||||
|
||||
exports.arrayify = function (val) {
|
||||
if (!val) return [];
|
||||
if (_.isString(val)) return exports.list(val);
|
||||
if (_.isArray(val)) return val;
|
||||
throw new TypeError("illegal type for arrayify");
|
||||
};
|
||||
|
||||
exports.isAbsolute = function (loc) {
|
||||
if (!loc) return false;
|
||||
if (loc[0] === "/") return true; // unix
|
||||
if (loc[1] === ":" && loc[2] === "\\") return true; // windows
|
||||
return false;
|
||||
};
|
||||
|
||||
exports.sourceMapToComment = function (map) {
|
||||
var json = JSON.stringify(map);
|
||||
var base64 = new Buffer(json).toString("base64");
|
||||
return "//# sourceMappingURL=data:application/json;base64," + base64;
|
||||
};
|
||||
|
||||
exports.pushMutatorMap = function (mutatorMap, key, kind, computed, method) {
|
||||
var alias;
|
||||
|
||||
if (t.isIdentifier(key)) {
|
||||
alias = key.name;
|
||||
if (computed) alias = "computed:" + alias;
|
||||
} else if (t.isLiteral(key)) {
|
||||
alias = String(key.value);
|
||||
} else {
|
||||
alias = JSON.stringify(traverse.removeProperties(_.cloneDeep(key)));
|
||||
}
|
||||
|
||||
var map;
|
||||
if (_.has(mutatorMap, alias)) {
|
||||
map = mutatorMap[alias];
|
||||
} else {
|
||||
map = {};
|
||||
}
|
||||
mutatorMap[alias] = map;
|
||||
|
||||
map._key = key;
|
||||
if (computed) {
|
||||
map._computed = true;
|
||||
}
|
||||
|
||||
map[kind] = method;
|
||||
};
|
||||
|
||||
exports.buildDefineProperties = function (mutatorMap) {
|
||||
var objExpr = t.objectExpression([]);
|
||||
|
||||
_.each(mutatorMap, function (map) {
|
||||
var mapNode = t.objectExpression([]);
|
||||
|
||||
var propNode = t.property("init", map._key, mapNode, map._computed);
|
||||
|
||||
map.enumerable = t.literal(true);
|
||||
|
||||
_.each(map, function (node, key) {
|
||||
if (key[0] === "_") return;
|
||||
|
||||
node = _.clone(node);
|
||||
var inheritNode = node;
|
||||
if (t.isMethodDefinition(node)) node = node.value;
|
||||
|
||||
var prop = t.property("init", t.identifier(key), node);
|
||||
t.inheritsComments(prop, inheritNode);
|
||||
t.removeComments(inheritNode);
|
||||
mapNode.properties.push(prop);
|
||||
});
|
||||
|
||||
objExpr.properties.push(propNode);
|
||||
});
|
||||
|
||||
return objExpr;
|
||||
};
|
||||
|
||||
exports.template = function (name, nodes, keepExpression) {
|
||||
var template = exports.templates[name];
|
||||
if (!template) throw new ReferenceError("unknown template " + name);
|
||||
|
||||
if (nodes === true) {
|
||||
keepExpression = true;
|
||||
nodes = null;
|
||||
}
|
||||
|
||||
template = _.cloneDeep(template);
|
||||
|
||||
if (!_.isEmpty(nodes)) {
|
||||
traverse(template, {
|
||||
enter: function (node) {
|
||||
if (t.isIdentifier(node) && _.has(nodes, node.name)) {
|
||||
return nodes[node.name];
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
var node = template.body[0];
|
||||
|
||||
if (!keepExpression && t.isExpressionStatement(node)) {
|
||||
return node.expression;
|
||||
} else {
|
||||
return node;
|
||||
}
|
||||
};
|
||||
|
||||
exports.codeFrame = function (lines, lineNumber, colNumber) {
|
||||
colNumber = Math.max(colNumber, 0);
|
||||
|
||||
lines = lines.split("\n");
|
||||
|
||||
var start = Math.max(lineNumber - 3, 0);
|
||||
var end = Math.min(lines.length, lineNumber + 3);
|
||||
var width = (end + "").length;
|
||||
|
||||
if (!lineNumber && !colNumber) {
|
||||
start = 0;
|
||||
end = lines.length;
|
||||
}
|
||||
|
||||
return "\n" + lines.slice(start, end).map(function (line, i) {
|
||||
var curr = i + start + 1;
|
||||
|
||||
var gutter = curr === lineNumber ? "> " : " ";
|
||||
|
||||
var sep = curr + exports.repeat(width + 1);
|
||||
gutter += sep + "| ";
|
||||
|
||||
var str = gutter + line;
|
||||
|
||||
if (colNumber && curr === lineNumber) {
|
||||
str += "\n";
|
||||
str += exports.repeat(gutter.length - 2);
|
||||
str += "|" + exports.repeat(colNumber) + "^";
|
||||
}
|
||||
|
||||
return str;
|
||||
}).join("\n");
|
||||
};
|
||||
|
||||
exports.repeat = function (width, cha) {
|
||||
cha = cha || " ";
|
||||
return new Array(width + 1).join(cha);
|
||||
};
|
||||
|
||||
exports.normaliseAst = function (ast, comments, tokens) {
|
||||
if (ast && ast.type === "Program") {
|
||||
return t.file(ast, comments || [], tokens || []);
|
||||
} else {
|
||||
throw new Error("Not a valid ast?");
|
||||
}
|
||||
};
|
||||
|
||||
exports.parse = function (opts, code, callback) {
|
||||
try {
|
||||
var comments = [];
|
||||
var tokens = [];
|
||||
|
||||
var ast = acorn.parse(code, {
|
||||
allowImportExportEverywhere: true,
|
||||
allowReturnOutsideFunction: true,
|
||||
ecmaVersion: opts.experimental ? 7 : 6,
|
||||
playground: opts.playground,
|
||||
strictMode: true,
|
||||
onComment: comments,
|
||||
locations: true,
|
||||
onToken: tokens,
|
||||
ranges: true
|
||||
});
|
||||
|
||||
estraverse.attachComments(ast, comments, tokens);
|
||||
|
||||
ast = exports.normaliseAst(ast, comments, tokens);
|
||||
|
||||
if (callback) {
|
||||
return callback(ast);
|
||||
} else {
|
||||
return ast;
|
||||
}
|
||||
} catch (err) {
|
||||
if (!err._6to5) {
|
||||
err._6to5 = true;
|
||||
var message = opts.filename + ": " + err.message;
|
||||
|
||||
var loc = err.loc;
|
||||
if (loc) {
|
||||
var frame = exports.codeFrame(code, loc.line, loc.column);
|
||||
message += frame;
|
||||
}
|
||||
|
||||
if (err.stack) err.stack = err.stack.replace(err.message, message);
|
||||
err.message = message;
|
||||
}
|
||||
|
||||
throw err;
|
||||
}
|
||||
};
|
||||
|
||||
exports.parseTemplate = function (loc, code) {
|
||||
var ast = exports.parse({ filename: loc }, code).program;
|
||||
return traverse.removeProperties(ast);
|
||||
};
|
||||
|
||||
var loadTemplates = function () {
|
||||
var templates = {};
|
||||
|
||||
var templatesLoc = __dirname + "/transformation/templates";
|
||||
if (!fs.existsSync(templatesLoc)) {
|
||||
throw new Error("no templates directory - this is most likely the " +
|
||||
"result of a broken `npm publish`. Please report to " +
|
||||
"https://github.com/6to5/6to5/issues");
|
||||
}
|
||||
|
||||
_.each(fs.readdirSync(templatesLoc), function (name) {
|
||||
if (name[0] === ".") return;
|
||||
|
||||
var key = path.basename(name, path.extname(name));
|
||||
var loc = templatesLoc + "/" + name;
|
||||
var code = fs.readFileSync(loc, "utf8");
|
||||
|
||||
templates[key] = exports.parseTemplate(loc, code);
|
||||
});
|
||||
|
||||
return templates;
|
||||
};
|
||||
|
||||
try {
|
||||
exports.templates = require("../../templates.json");
|
||||
} catch (err) {
|
||||
if (err.code !== "MODULE_NOT_FOUND") throw err;
|
||||
|
||||
exports.templates = loadTemplates();
|
||||
}
|
||||
@@ -1,6 +1,8 @@
|
||||
var transform = module.exports = require("./transformation/transform");
|
||||
"use strict";
|
||||
|
||||
transform.version = require("../../package").version;
|
||||
var transform = module.exports = require("../transformation");
|
||||
|
||||
transform.version = require("../../../package").version;
|
||||
|
||||
transform.transform = transform;
|
||||
|
||||
@@ -36,7 +38,7 @@ transform.load = function (url, callback, opts, hold) {
|
||||
|
||||
var runScripts = function () {
|
||||
var scripts = [];
|
||||
var types = ["text/ecmascript-6", "text/6to5", "module"];
|
||||
var types = ["text/ecmascript-6", "text/6to5", "text/babel", "module"];
|
||||
var index = 0;
|
||||
|
||||
var exec = function () {
|
||||
@@ -1,33 +1,35 @@
|
||||
var transform = require("./transformation/transform");
|
||||
var util = require("./util");
|
||||
var fs = require("fs");
|
||||
var _ = require("lodash");
|
||||
"use strict";
|
||||
|
||||
exports.version = require("../../package").version;
|
||||
var isFunction = require("lodash/lang/isFunction");
|
||||
var transform = require("../transformation");
|
||||
var util = require("../util");
|
||||
var fs = require("fs");
|
||||
|
||||
exports.types = require("./types");
|
||||
exports.version = require("../../../package").version;
|
||||
|
||||
exports.runtime = require("./runtime-generator");
|
||||
exports.buildExternalHelpers = require("../build-external-helpers");
|
||||
|
||||
exports.types = require("../types");
|
||||
|
||||
exports.register = function (opts) {
|
||||
var register = require("./register");
|
||||
var register = require("./register/node");
|
||||
if (opts != null) register(opts);
|
||||
return register;
|
||||
};
|
||||
|
||||
exports.polyfill = function () {
|
||||
require("./polyfill");
|
||||
require("../polyfill");
|
||||
};
|
||||
|
||||
exports.canCompile = util.canCompile;
|
||||
|
||||
// do not use this - this is for use by official maintained 6to5 plugins
|
||||
// do not use this - this is for use by official maintained babel plugins
|
||||
exports._util = util;
|
||||
|
||||
exports.transform = transform;
|
||||
|
||||
exports.transformFile = function (filename, opts, callback) {
|
||||
if (_.isFunction(opts)) {
|
||||
if (isFunction(opts)) {
|
||||
callback = opts;
|
||||
opts = {};
|
||||
}
|
||||
7
lib/babel/api/register/browser.js
Normal file
7
lib/babel/api/register/browser.js
Normal file
@@ -0,0 +1,7 @@
|
||||
"use strict";
|
||||
|
||||
// required to safely use babel/register within a browserify codebase
|
||||
|
||||
module.exports = function () {};
|
||||
|
||||
require("../../polyfill");
|
||||
38
lib/babel/api/register/cache.js
Normal file
38
lib/babel/api/register/cache.js
Normal file
@@ -0,0 +1,38 @@
|
||||
"use strict";
|
||||
|
||||
var path = require("path");
|
||||
var os = require("os");
|
||||
var fs = require("fs");
|
||||
|
||||
var FILENAME = process.env.BABEL_CACHE_PATH || path.join(os.tmpdir(), "babel.json");
|
||||
var data = {};
|
||||
|
||||
exports.save = function () {
|
||||
fs.writeFileSync(FILENAME, JSON.stringify(data, null, " "));
|
||||
};
|
||||
|
||||
exports.load = function () {
|
||||
if (process.env.BABEL_DISABLE_CACHE) return;
|
||||
|
||||
process.on("exit", exports.save);
|
||||
|
||||
var sigint = function () {
|
||||
process.removeListener("SIGINT", sigint);
|
||||
exports.save();
|
||||
process.kill(process.pid, "SIGINT");
|
||||
};
|
||||
|
||||
process.on("SIGINT", sigint);
|
||||
|
||||
if (!fs.existsSync(FILENAME)) return;
|
||||
|
||||
try {
|
||||
data = JSON.parse(fs.readFileSync(FILENAME));
|
||||
} catch (err) {
|
||||
return;
|
||||
}
|
||||
};
|
||||
|
||||
exports.get = function () {
|
||||
return data;
|
||||
};
|
||||
152
lib/babel/api/register/node.js
Normal file
152
lib/babel/api/register/node.js
Normal file
@@ -0,0 +1,152 @@
|
||||
"use strict";
|
||||
|
||||
require("../../polyfill");
|
||||
|
||||
var sourceMapSupport = require("source-map-support");
|
||||
var registerCache = require("./cache");
|
||||
var extend = require("lodash/object/extend");
|
||||
var babel = require("../node");
|
||||
var each = require("lodash/collection/each");
|
||||
var util = require("../../util");
|
||||
var fs = require("fs");
|
||||
|
||||
sourceMapSupport.install({
|
||||
retrieveSourceMap: function (source) {
|
||||
var map = maps && maps[source];
|
||||
if (map) {
|
||||
return {
|
||||
url: null,
|
||||
map: map
|
||||
};
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
//
|
||||
|
||||
registerCache.load();
|
||||
var cache = registerCache.get();
|
||||
|
||||
//
|
||||
|
||||
var transformOpts = {};
|
||||
var ignoreRegex = /node_modules/;
|
||||
var onlyRegex;
|
||||
var exts = {};
|
||||
var maps = {};
|
||||
|
||||
var mtime = function (filename) {
|
||||
return +fs.statSync(filename).mtime;
|
||||
};
|
||||
|
||||
var compile = function (filename) {
|
||||
var result;
|
||||
|
||||
var cacheKey = filename + ":" + JSON.stringify(transformOpts);
|
||||
|
||||
if (cache) {
|
||||
var cached = cache[cacheKey];
|
||||
if (cached && cached.mtime === mtime(filename)) {
|
||||
result = cached;
|
||||
}
|
||||
}
|
||||
|
||||
if (!result) {
|
||||
result = babel.transformFileSync(filename, extend({
|
||||
sourceMap: true,
|
||||
ast: false
|
||||
}, transformOpts));
|
||||
}
|
||||
|
||||
if (cache) {
|
||||
result.mtime = mtime(filename);
|
||||
cache[cacheKey] = result;
|
||||
}
|
||||
|
||||
maps[filename] = result.map;
|
||||
|
||||
return result.code;
|
||||
};
|
||||
|
||||
var shouldIgnore = function (filename) {
|
||||
return (ignoreRegex && ignoreRegex.test(filename)) || (onlyRegex && !onlyRegex.test(filename));
|
||||
};
|
||||
|
||||
var istanbulMonkey = {};
|
||||
|
||||
if (process.env.running_under_istanbul) { // jshint ignore:line
|
||||
// we need to monkey patch fs.readFileSync so we can hook into
|
||||
// what istanbul gets, it's extremely dirty but it's the only way
|
||||
var _readFileSync = fs.readFileSync;
|
||||
|
||||
fs.readFileSync = function (filename) {
|
||||
if (istanbulMonkey[filename]) {
|
||||
delete istanbulMonkey[filename];
|
||||
var code = compile(filename);
|
||||
istanbulMonkey[filename] = true;
|
||||
return code;
|
||||
} else {
|
||||
return _readFileSync.apply(this, arguments);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
var istanbulLoader = function (m, filename, old) {
|
||||
istanbulMonkey[filename] = true;
|
||||
old(m, filename);
|
||||
};
|
||||
|
||||
var normalLoader = function (m, filename) {
|
||||
m._compile(compile(filename), filename);
|
||||
};
|
||||
|
||||
var registerExtension = function (ext) {
|
||||
var old = require.extensions[ext];
|
||||
|
||||
var loader = normalLoader;
|
||||
if (process.env.running_under_istanbul) loader = istanbulLoader; // jshint ignore:line
|
||||
|
||||
require.extensions[ext] = function (m, filename) {
|
||||
if (shouldIgnore(filename)) {
|
||||
old(m, filename);
|
||||
} else {
|
||||
loader(m, filename, old);
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
var hookExtensions = function (_exts) {
|
||||
each(exts, function (old, ext) {
|
||||
require.extensions[ext] = old;
|
||||
});
|
||||
|
||||
exts = {};
|
||||
|
||||
each(_exts, function (ext) {
|
||||
exts[ext] = require.extensions[ext];
|
||||
registerExtension(ext);
|
||||
});
|
||||
};
|
||||
|
||||
hookExtensions(util.canCompile.EXTENSIONS);
|
||||
|
||||
module.exports = function (opts) {
|
||||
// normalize options
|
||||
opts = opts || {};
|
||||
|
||||
if (opts.only != null) onlyRegex = util.regexify(opts.only);
|
||||
if (opts.ignore != null) ignoreRegex = util.regexify(opts.ignore);
|
||||
|
||||
if (opts.extensions) hookExtensions(util.arrayify(opts.extensions));
|
||||
|
||||
if (opts.cache === false) cache = null;
|
||||
|
||||
delete opts.extensions;
|
||||
delete opts.ignore;
|
||||
delete opts.cache;
|
||||
delete opts.only;
|
||||
|
||||
extend(transformOpts, opts);
|
||||
};
|
||||
25
lib/babel/build-external-helpers.js
Normal file
25
lib/babel/build-external-helpers.js
Normal file
@@ -0,0 +1,25 @@
|
||||
"use strict";
|
||||
|
||||
var buildHelpers = require("./build-helpers");
|
||||
var generator = require("./generation");
|
||||
var util = require("./util");
|
||||
var t = require("./types");
|
||||
|
||||
module.exports = function () {
|
||||
var namespace = t.identifier("babelHelpers");
|
||||
|
||||
var body = [];
|
||||
var container = t.functionExpression(null, [t.identifier("global")], t.blockStatement(body));
|
||||
var tree = t.program([t.expressionStatement(t.callExpression(container, [util.template("self-global")]))]);
|
||||
|
||||
body.push(t.variableDeclaration("var", [
|
||||
t.variableDeclarator(
|
||||
namespace,
|
||||
t.assignmentExpression("=", t.memberExpression(t.identifier("global"), namespace), t.objectExpression([]))
|
||||
)
|
||||
]));
|
||||
|
||||
buildHelpers(body, namespace);
|
||||
|
||||
return generator(tree).code;
|
||||
};
|
||||
13
lib/babel/build-helpers.js
Normal file
13
lib/babel/build-helpers.js
Normal file
@@ -0,0 +1,13 @@
|
||||
var File = require("./transformation/file");
|
||||
var util = require("./util");
|
||||
var each = require("lodash/collection/each");
|
||||
var t = require("./types");
|
||||
|
||||
module.exports = function (body, namespace) {
|
||||
each(File.helpers, function (name) {
|
||||
var key = t.identifier(t.toIdentifier(name));
|
||||
body.push(t.expressionStatement(
|
||||
t.assignmentExpression("=", t.memberExpression(namespace, key), util.template(name))
|
||||
));
|
||||
});
|
||||
};
|
||||
29
lib/babel/detection/index.js
Normal file
29
lib/babel/detection/index.js
Normal file
@@ -0,0 +1,29 @@
|
||||
module.exports = detect;
|
||||
|
||||
var SYNTAX_KEYS = require("./syntax-keys");
|
||||
var traverse = require("../traversal");
|
||||
var visitors = traverse.explode(require("./visitors"));
|
||||
|
||||
function detect(ast) {
|
||||
var stats = {
|
||||
syntax: {},
|
||||
builtins: {}
|
||||
};
|
||||
|
||||
var detectedSyntax = function (name) {
|
||||
stats.syntax[name] = true;
|
||||
};
|
||||
|
||||
traverse(ast, {
|
||||
enter: function (node, parent) {
|
||||
if (SYNTAX_KEYS[node.type]) {
|
||||
detectedSyntax(SYNTAX_KEYS[node.type]);
|
||||
}
|
||||
|
||||
var visitor = visitors[node.type];
|
||||
if (visitor) visitor(node, parent, detectedSyntax);
|
||||
}
|
||||
});
|
||||
|
||||
return stats;
|
||||
}
|
||||
84
lib/babel/detection/syntax-keys.json
Normal file
84
lib/babel/detection/syntax-keys.json
Normal file
@@ -0,0 +1,84 @@
|
||||
{
|
||||
"ArrowFunctionExpression": "es6.arrowFunctions",
|
||||
|
||||
"AwaitExpression": "es7.asyncFunctions",
|
||||
|
||||
"ClassBody": "es6.classes",
|
||||
"ClassDeclaration": "es6.classes",
|
||||
"ClassExpression": "es6.classes",
|
||||
"MethodDefinition": "es6.classes",
|
||||
|
||||
"ComprehensionBlock": "es7.comprehensions",
|
||||
"ComprehensionExpression": "es7.comprehensions",
|
||||
|
||||
"ForOfStatement": "es6.forOf",
|
||||
|
||||
"ExportBatchSpecifier": "es6.modules",
|
||||
"ExportDeclaration": "es6.modules",
|
||||
"ExportSpecifier": "es6.modules",
|
||||
"ImportBatchSpecifier": "es6.modules",
|
||||
"ImportDeclaration": "es6.modules",
|
||||
"ImportSpecifier": "es6.modules",
|
||||
|
||||
"ArrayPattern": "es6.destructuring",
|
||||
"AssignmentPattern": "es6.destructuring",
|
||||
"ObjectPattern": "es6.destructuring",
|
||||
|
||||
"RestElement": "es6.parameters.rest",
|
||||
|
||||
"SpreadElement": "es6.spread",
|
||||
|
||||
"SpreadProperty": "es7.objectSpread",
|
||||
|
||||
"TaggedTemplateExpression": "es6.templateLiterals",
|
||||
"TemplateElement": "es6.templateLiterals",
|
||||
"TemplateLiteral": "es6.templateLiterals",
|
||||
|
||||
"VirtualPropertyExpression": "es7.abstractReferences",
|
||||
"PrivateDeclaration": "es7.abstractReferences",
|
||||
|
||||
"YieldExpression": "es6.generators",
|
||||
|
||||
"AnyTypeAnnotation": "flow",
|
||||
"ArrayTypeAnnotation": "flow",
|
||||
"BooleanTypeAnnotation": "flow",
|
||||
"ClassProperty": "flow",
|
||||
"DeclareClass": "flow",
|
||||
"DeclareFunction": "flow",
|
||||
"DeclareModule": "flow",
|
||||
"DeclareVariable": "flow",
|
||||
"FunctionTypeAnnotation": "flow",
|
||||
"FunctionTypeParam": "flow",
|
||||
"GenericTypeAnnotation": "flow",
|
||||
"InterfaceExtends": "flow",
|
||||
"InterfaceDeclaration": "flow",
|
||||
"IntersectionTypeAnnotation": "flow",
|
||||
"NullableTypeAnnotation": "flow",
|
||||
"NumberTypeAnnotation": "flow",
|
||||
"StringLiteralTypeAnnotation": "flow",
|
||||
"StringTypeAnnotation": "flow",
|
||||
"TupleTypeAnnotation": "flow",
|
||||
"TypeofTypeAnnotation": "flow",
|
||||
"TypeAlias": "flow",
|
||||
"TypeAnnotation": "flow",
|
||||
"TypeParameterDeclaration": "flow",
|
||||
"TypeParameterInstantiation": "flow",
|
||||
"ObjectTypeAnnotation": "flow",
|
||||
"ObjectTypeCallProperty": "flow",
|
||||
"ObjectTypeIndexer": "flow",
|
||||
"ObjectTypeProperty": "flow",
|
||||
"QualifiedTypeIdentifier": "flow",
|
||||
"UnionTypeAnnotation": "flow",
|
||||
"VoidTypeAnnotation": "flow",
|
||||
|
||||
"JSXAttribute": "jsx",
|
||||
"JSXClosingElement": "jsx",
|
||||
"JSXElement": "jsx",
|
||||
"JSXEmptyExpression": "jsx",
|
||||
"JSXExpressionContainer": "jsx",
|
||||
"JSXIdentifier": "jsx",
|
||||
"JSXMemberExpression": "jsx",
|
||||
"JSXNamespacedName": "jsx",
|
||||
"JSXOpeningElement": "jsx",
|
||||
"JSXSpreadAttribute": "jsx"
|
||||
}
|
||||
54
lib/babel/detection/visitors.js
Normal file
54
lib/babel/detection/visitors.js
Normal file
@@ -0,0 +1,54 @@
|
||||
var t = require("../types");
|
||||
var includes = require("lodash/collection/includes");
|
||||
|
||||
exports.AssignmentExpression = function (node, parent, detected) {
|
||||
if (node.operator === "**=") {
|
||||
detected("es6.exponentation");
|
||||
}
|
||||
};
|
||||
|
||||
exports.BinaryExpression = function (node, parent, detected) {
|
||||
if (node.operator === "**") {
|
||||
detected("es6.exponentation");
|
||||
}
|
||||
};
|
||||
|
||||
exports.VariableDeclaration = function (node, parent, detected) {
|
||||
if (node.kind === "let" || node.kind === "const") {
|
||||
detected("es6.blockScoping");
|
||||
}
|
||||
|
||||
if (node.kind === "const") {
|
||||
detected("es6.constants");
|
||||
}
|
||||
};
|
||||
|
||||
exports.Property = function (node, parent, detected) {
|
||||
if (node.shorthand || node.method) {
|
||||
detected("es6.properties.shorthand");
|
||||
}
|
||||
|
||||
if (node.kind === "set" || node.kind === "get") {
|
||||
detected("es5.properties.mutators");
|
||||
}
|
||||
|
||||
if (node.computed) {
|
||||
detected("es6.properties.computed");
|
||||
}
|
||||
};
|
||||
|
||||
exports.AssignmentPattern = function (node, parent, detected) {
|
||||
if (t.isFunction(parent) && includes(parent.params, node)) {
|
||||
detected("es6.parameters.default");
|
||||
}
|
||||
};
|
||||
|
||||
exports.Function = function (node, parent, detected) {
|
||||
if (node.generator) {
|
||||
detected("es6.generators");
|
||||
}
|
||||
|
||||
if (node.async) {
|
||||
detected("es7.asyncFunctions");
|
||||
}
|
||||
};
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user