Compare commits
597 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a38ae381e2 | ||
|
|
9a2e56f003 | ||
|
|
5bc78b0237 | ||
|
|
c5af8b8694 | ||
|
|
c637575cab | ||
|
|
bc8d49c95c | ||
|
|
59ff0fd9a9 | ||
|
|
b1f794eb84 | ||
|
|
79ab92b5d4 | ||
|
|
f6512b45d5 | ||
|
|
8065c981dc | ||
|
|
7927aa2e18 | ||
|
|
35bd510930 | ||
|
|
74186241f9 | ||
|
|
1effa72a33 | ||
|
|
b03a806d7c | ||
|
|
6220fd9fc3 | ||
|
|
8d92a75190 | ||
|
|
60a7e40140 | ||
|
|
299e462a29 | ||
|
|
62556f6102 | ||
|
|
f2c5accab3 | ||
|
|
15f1978cae | ||
|
|
710ff548cb | ||
|
|
fbb19fc656 | ||
|
|
e87ef80bc5 | ||
|
|
aca750e881 | ||
|
|
672e55082c | ||
|
|
a49f746700 | ||
|
|
83cd3bef92 | ||
|
|
5e4a008a06 | ||
|
|
1594efbc20 | ||
|
|
002be9a05c | ||
|
|
8e06db8f7d | ||
|
|
b1238a1746 | ||
|
|
0874f390ff | ||
|
|
eeff4ac9d1 | ||
|
|
8f0ffc7302 | ||
|
|
bb19649af8 | ||
|
|
692262df1b | ||
|
|
067047da34 | ||
|
|
1c5d169b1e | ||
|
|
3f82b4ec72 | ||
|
|
9c6e632021 | ||
|
|
45553f1fb7 | ||
|
|
f228edbb84 | ||
|
|
64e657e53d | ||
|
|
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 | ||
|
|
17e65cc772 | ||
|
|
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 | ||
|
|
d87b70b57e | ||
|
|
bbfb297d73 | ||
|
|
9b68d08604 |
5
.babelrc
Normal file
5
.babelrc
Normal file
@@ -0,0 +1,5 @@
|
||||
{
|
||||
"experimental": true,
|
||||
"playground": true,
|
||||
"loose": true
|
||||
}
|
||||
@@ -5,7 +5,8 @@ insert_final_newline = true
|
||||
charset = utf-8
|
||||
trim_trailing_whitespace = true
|
||||
insert_final_newline = true
|
||||
end_of_line = lf
|
||||
|
||||
[*.js]
|
||||
[*.{js,json}]
|
||||
indent_style = space
|
||||
indent_size = 2
|
||||
|
||||
4
.gitignore
vendored
4
.gitignore
vendored
@@ -11,5 +11,5 @@ test/tmp
|
||||
coverage
|
||||
dist
|
||||
.package.json
|
||||
packages/6to5-runtime/*.js
|
||||
packages/6to5-runtime/regenerator/*.js
|
||||
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/6to5/regenerator-6to5
|
||||
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
|
||||
8
.jscsrc
8
.jscsrc
@@ -1,5 +1,5 @@
|
||||
{
|
||||
"excludeFiles": ["lib/6to5/transformation/templates"],
|
||||
"excludeFiles": ["lib/babel/transformation/templates"],
|
||||
"disallowSpacesInNamedFunctionExpression": {
|
||||
"beforeOpeningRoundBrace": true
|
||||
},
|
||||
@@ -14,7 +14,6 @@
|
||||
},
|
||||
"disallowSpacesInsideArrayBrackets": true,
|
||||
"disallowSpacesInsideParentheses": true,
|
||||
"disallowQuotedKeysInObjects": true,
|
||||
"disallowSpaceAfterObjectKeys": true,
|
||||
"disallowSpaceAfterPrefixUnaryOperators": true,
|
||||
"disallowSpaceBeforePostfixUnaryOperators": true,
|
||||
@@ -33,10 +32,8 @@
|
||||
"requireCommaBeforeLineBreak": true,
|
||||
"requireSpaceBeforeBinaryOperators": true,
|
||||
"requireSpaceAfterBinaryOperators": true,
|
||||
"requireCamelCaseOrUpperCaseIdentifiers": true,
|
||||
"requireLineFeedAtFileEnd": true,
|
||||
"requireCapitalizedConstructors": true,
|
||||
"requireDotNotation": true,
|
||||
"requireSpacesInForStatement": true,
|
||||
"requireCurlyBraces": [
|
||||
"do"
|
||||
@@ -52,7 +49,8 @@
|
||||
"return",
|
||||
"try",
|
||||
"catch",
|
||||
"typeof"
|
||||
"typeof",
|
||||
"function"
|
||||
],
|
||||
"validateLineBreaks": "LF",
|
||||
"validateQuoteMarks": "\"",
|
||||
|
||||
@@ -1 +1 @@
|
||||
lib/6to5/transformation/templates
|
||||
lib/babel/transformation/templates
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
"esnext": true,
|
||||
"indent": 2,
|
||||
"freeze": true,
|
||||
"validthis": true,
|
||||
"camelcase": true,
|
||||
"unused": true,
|
||||
"eqnull": true,
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
node_modules
|
||||
*.log
|
||||
*.cache
|
||||
lib/6to5/transformation/templates
|
||||
lib/babel/transformation/templates
|
||||
test
|
||||
benchmark
|
||||
Makefile
|
||||
|
||||
@@ -2,7 +2,8 @@ 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
860
CHANGELOG.md
860
CHANGELOG.md
@@ -11,842 +11,60 @@
|
||||
|
||||
_Note: Gaps between patch versions are faulty/broken releases._
|
||||
|
||||
## 3.0.9
|
||||
See [CHANGELOG - 6to5](CHANGELOG-6to5.md) for the pre-4.0.0 version changelog.
|
||||
|
||||
* **Bug Fix**
|
||||
* Make `t.isReferenced` more powerful, actually take into consideration all contexts were identifier nodes aren't actually references.
|
||||
* Don't camelcase underscores when converting a string to a valid identifier.
|
||||
## 4.4.2
|
||||
|
||||
## 3.0.8
|
||||
|
||||
* **Bug Fix**
|
||||
* Split up default function declaration exports due to regenerator destroying the parent export declaration.
|
||||
|
||||
## 3.0.7
|
||||
|
||||
* **Internal**
|
||||
* Upgrade `core-js` to `0.4.9`.
|
||||
* **Bug Fix**
|
||||
* Add id to function express scope tracking.
|
||||
|
||||
## 3.0.6
|
||||
|
||||
* **Bug Fix**
|
||||
* Fix block scope variable tracking stopping whenever it hits a new scope.
|
||||
* Fix block scope variable tracking breaking on all block statement scopes that have a for loop parent.
|
||||
|
||||
## 3.0.5
|
||||
|
||||
* **Internal**
|
||||
* More reliable default parameter scope.
|
||||
|
||||
## 3.0.4
|
||||
|
||||
* **Bug Fix**
|
||||
* Remove traversal stops from block scope tracking.
|
||||
|
||||
## 3.0.3
|
||||
|
||||
* **Internal**
|
||||
* Ignore options starting with `_`.
|
||||
|
||||
## 3.0.2
|
||||
|
||||
* **Internal**
|
||||
* Add common plugin options to valid options list.
|
||||
|
||||
## 3.0.1
|
||||
|
||||
* **Internal**
|
||||
* Downgrade `kexec` as `1.1.0` throws compilation errors.
|
||||
|
||||
## 3.0.0
|
||||
|
||||
* **Polish**
|
||||
* Generated code autoindentation.
|
||||
* Moved global uid registry to a scope registry resulting in nicer uids.
|
||||
* `this` is now illegal in the top level scope when using the default `useStrict` transformer.
|
||||
* New `asyncToGenerator` helper that's much more compact.
|
||||
* Throw errors on unknown options.
|
||||
* More reliable default parameter scope.
|
||||
* Helpers are now compact and have no newlines.
|
||||
* **Internal**
|
||||
* Rewritten a lot of the internals to much simpler.
|
||||
* Removed TDZ from default parameters as it was very wonky and unreliable.
|
||||
* Upgrade `core-js` to `0.4.6`.
|
||||
* Upgrade `acorn-6to5`.
|
||||
* JSX support is now on-par with react-tools/esprima.
|
||||
* Shorthand destructuring.
|
||||
* **Bug Fix**
|
||||
* Generators now work flawlessly with any parameter transformers.
|
||||
* Optional async function transformers should not name their functions.
|
||||
* Remove `unlink` event watching in `bin/6to5`.
|
||||
* Fix regenerator variable declarations being incorrectly hoisted breaking scope.
|
||||
* Transformers that attempted to simplify expressions that had no consequence now take into account whether it's one of the last statements/expressions in the script.
|
||||
* **New Feature**
|
||||
* New `selfContained` transformer.
|
||||
* New `undeclaredVariableCheck` optional transformer.
|
||||
* Added `--blacklist` and `--whitelist` options to `6to5-node`.
|
||||
* Add `moduleId` option for specifying a custom module id.
|
||||
|
||||
## 4.4.0
|
||||
|
||||
* **New Feature**
|
||||
* `/*** @jsx NAMESPACE **/` comments are now honored by the `react` transformer.
|
||||
* `getModuleName` option.
|
||||
* Infer function expression names. Thanks [@RReverser](https://github.com/RReverser)!
|
||||
* **Bug Fix**
|
||||
* Add proper control flow for tail recursion optimisation.
|
||||
* **Internal**
|
||||
* Remove useless `format` options and move the `format.compact` option to `format`.
|
||||
* **Polish**
|
||||
* Newline handling of the code generator has been heavily improved.
|
||||
* Code generator now deopts whitespace if the input size is >100KB.
|
||||
|
||||
## 4.3.0
|
||||
|
||||
* **Breaking Change**
|
||||
* Caching is now always enabled for the require hook. It also now no longer caches require resolutions.
|
||||
* Bare `super();` only works inside of constructors.
|
||||
* Removed the optional runtime in favor of the `selfContained` transformer.
|
||||
* This shorthand has been removed from the playground.
|
||||
* `6to5/polyfill` can now only be required **once**.
|
||||
* **CLI**
|
||||
* `--indent` option has been removed.
|
||||
* `--include-regenerator` option has been removed.
|
||||
* `--amd-modules-id` option has been removed, use `--module-ids` instead.
|
||||
* **Options**
|
||||
* `amdModuleIds` option has been removed, use `moduleIds` instead.
|
||||
* `includeRegenerator` has been removed.
|
||||
* `ignoreRegex` fallback has now been dropped from the require hook. `register(/foo/);`, `register({ ignoreRegex: /foo/ })` -> `register({ ignore: /foo/ })`.
|
||||
* **Modules**
|
||||
* Module interop now only collapses to `module.exports` when there's a **single** export that's default.
|
||||
* Imports and exports are now illegal anywhere except the root level by default. Set `modules` to [loose mode](http://6to5.org/docs/usage/loose) to allow them everywhere.
|
||||
* **Transformers**
|
||||
* Optional fast transformer backwards compatibility support has been removed. Use [loose mode](https://6to5.org/docs/usage/loose).
|
||||
* Removed the `coreAliasing` transformer in favor of `selfContained`.
|
||||
* Renamed transformers:
|
||||
* `specNoForInOfAssignment` -> `validation.noForInOfAssignment`
|
||||
* `specSetters` -> `validation.setters`
|
||||
* `specBlockScopedFunctions` -> `spec.blockScopedFunctions`
|
||||
* `malletOperator` -> `playground.malletOperator`
|
||||
* `methodBinding` -> `playground.methodBinding`
|
||||
* `memoizationOperator` -> `playground.memoizationOperator`
|
||||
* `objectGetterMemoization` -> `playground.objectGetterMemoization`
|
||||
* `modules` -> `es6.modules`
|
||||
* `propertyNameShorthand` -> `es6.properties.shorthand`
|
||||
* `arrayComprehension` -> `es7.comprehensions`
|
||||
* `generatorComprehension` -> `es7.comprehensions`
|
||||
* `arrowFunctions` -> `es6.arrowFunctions`
|
||||
* `classes` -> `es6.classes`
|
||||
* `objectSpread` -> `es7.objectSpread`
|
||||
* `exponentiationOperator` -> `es7.exponentiationOperator`
|
||||
* `spread` -> `es6.spread`
|
||||
* `templateLiterals` -> `es6.templateLiterals`
|
||||
* `propertyMethodAssignment` -> `es6.properties.shorthand`
|
||||
* `computedPropertyNames` -> `es6.properties.computed`
|
||||
* `defaultParameters` -> `es6.parameters.default`
|
||||
* `restParameters` -> `es6.parameters.rest`
|
||||
* `destructuring` -> `es6.destructuring`
|
||||
* `forOf` -> `es6.forOf`
|
||||
* `unicodeRegex` -> `es6.unicodeRegex`
|
||||
* `abstractReferences` -> `es7.abstractReferences`
|
||||
* `constants` -> `es6.constants`
|
||||
* `letScoping` -> `es6.blockScoping`
|
||||
* `blockScopingTDZ` -> `es6.blockScopingTDZ`
|
||||
* `generators` -> `regenerator`
|
||||
* `protoToAssign` -> `spec.protoToAssign`
|
||||
* `typeofSymbol` -> `spec.typeofSymbol`
|
||||
* `coreAliasing` -> `selfContained`
|
||||
* `undefinedToVoid` -> `spec.undefinedToVoid`
|
||||
* `undeclaredVariableCheck` -> `validation.undeclaredVariableCheck`
|
||||
* `specPropertyLiterals` -> `minification.propertyLiterals`
|
||||
* `specMemberExpressionLiterals` -> `minification.memberExpressionLiterals`
|
||||
* Remove `commonStandard` module formatter and make it the default behaviour of all the strict module formatters.
|
||||
|
||||
## 2.13.7
|
||||
|
||||
* **Bug Fix**
|
||||
* Don't realias variables that are already declared in optional `coreAliasing` transformer.
|
||||
|
||||
## 2.13.6
|
||||
|
||||
* **Bug Fix**
|
||||
* Add `NewExpression` as a valid parent for parentheses insertion for `ConditionalExpression`.
|
||||
|
||||
## 2.13.5
|
||||
|
||||
* **Bug Fix**
|
||||
* Allow rest parameters to be destructuring patterns.
|
||||
* **Internal**
|
||||
* Upgrade `kexec` to `1.1.0`.
|
||||
|
||||
## 2.13.4
|
||||
|
||||
* **Bug Fix**
|
||||
* Fix ordering of destructuring and default params.
|
||||
* Fix loop body scope.
|
||||
* Fix `for...of` transformation not retaining it's scope.
|
||||
* Add destructuring assignment support to scope tracking.
|
||||
* **Polish**
|
||||
* More reliable newlines for pretty printing variable declarations.
|
||||
|
||||
## 2.13.3
|
||||
|
||||
* **Internal**
|
||||
* Add `coverage` and `vendor` to npmignore.
|
||||
|
||||
## 2.13.2
|
||||
|
||||
* **Bug Fix**
|
||||
* Fix `super` inside of nested functions.
|
||||
* **Internal**
|
||||
* Move let scoping TDZ into a separate transformer until it's more solid.
|
||||
* Use `process.stdin.write` instead of `console.log` in `bin` to avoid sprintfification.
|
||||
|
||||
## 2.13.1
|
||||
|
||||
* **New Feature**
|
||||
* Temporal dead zone for block binding.
|
||||
|
||||
## 2.13.0
|
||||
|
||||
* **New Feature**
|
||||
* Block scoped functions.
|
||||
* Add `--loose all` option.
|
||||
* Add playground mallet operator thanks to [@jridgewell](https://github.com/jridgewell).
|
||||
* **Bug Fix**
|
||||
* Rewrote large parts of the let scoping transformer. Now passes all known tests.
|
||||
* **Internal**
|
||||
* Even more optimisations thanks to the awesome [@gaearon](https://github.com/gaearon).
|
||||
* Upgrade `acorn-6to5`.
|
||||
* Fixes exponentation operator thanks to [@charliesome](https://github.com/charliesome).
|
||||
* Fix flow optional parameters with types.
|
||||
* Upgrade `chokidar` to `0.12.6`.
|
||||
* Upgrade `commander` to `2.6.0`.
|
||||
* Upgrade `core-js` to `0.4.5`.
|
||||
* Upgrade `estraverse` to `1.9.1`.
|
||||
* Upgrade `jshint` to `2.5.11`.
|
||||
* Upgrade `regenerator` to `0.8.9`.
|
||||
* Upgrade `regexpu` to `1.0.0`.
|
||||
* Upgrade `source-map` to `0.1.43`.
|
||||
* Upgrade `source-map-support` to `0.2.9`.
|
||||
* Upgrade `browserify` to `8.1.1`.
|
||||
* Upgrade `chai` to `1.10.0`.
|
||||
* Upgrade `istanbul` to `0.3.5`.
|
||||
* Upgrade `mocha` to `2.1.0`.
|
||||
* Upgrade `uglify-js` to `2.4.16`.
|
||||
|
||||
## 2.12.6
|
||||
|
||||
* **Bug Fix**
|
||||
* Add missing flow type traversal keys.
|
||||
|
||||
## 2.12.5
|
||||
|
||||
* **Internal**
|
||||
* Fix incorrect `for...in` loop still causing `ember-script` issues.
|
||||
|
||||
## 2.12.4
|
||||
## 4.2.1
|
||||
|
||||
* **Polish**
|
||||
* Rest parameters now allocate the array before populating.
|
||||
* **Internal**
|
||||
* `for...in` loops have been changed to optimised `for` loops - better performance and no enumeration of protoype keys.
|
||||
* Parts of the code generator have now been optimised thanks to [gaearon](https://github.com/gaearon).
|
||||
* Add auxiliary comment to let scoping closure flow control.
|
||||
|
||||
## 2.12.3
|
||||
|
||||
* **Spec Compliancy**
|
||||
* Optional `typeof` transformer checks for `undefined` before passing it to the helper.
|
||||
* Class methods are now named.
|
||||
|
||||
## 2.12.2
|
||||
|
||||
* **Internal**
|
||||
* Exclude nodes in function parameters and catch clauses from `isReferenced` check.
|
||||
|
||||
## 2.12.1
|
||||
|
||||
* **Internal**
|
||||
* Add `.jsx` to list of allowed extensions.
|
||||
|
||||
## 2.12.0
|
||||
|
||||
* **Bug Fix**
|
||||
* Support non-string JSX literals.
|
||||
* **New Feature**
|
||||
* Loose mode for some transformers that enables non-spec behaviour.
|
||||
* **Internal**
|
||||
* Uglify `--mangle sort` has been added to the build script, cutting minified scripts in half.
|
||||
|
||||
## 2.11.4
|
||||
|
||||
* **Internal**
|
||||
* Make all dependency versions fixed.
|
||||
|
||||
## 2.11.3
|
||||
|
||||
* **Bug Fix**
|
||||
* Allow a string to be passed as the `optional` option.
|
||||
|
||||
## 2.11.2
|
||||
|
||||
* **Bug Fix**
|
||||
* Support esprima-style catch clause handlers.
|
||||
* **Polish**
|
||||
* Don't print a stacktrace for syntax errors in the CLI.
|
||||
|
||||
## 2.11.1
|
||||
|
||||
* **Bug Fix**
|
||||
* Remove stray `console.log` outputting debug code.
|
||||
* Remove `Dict` from `coreAliasing`.
|
||||
|
||||
## 2.11.0
|
||||
|
||||
* **Bug Fix**
|
||||
* Fix unnecessary IIFE in default parameters on method calls.
|
||||
* Add support for supers inside of closures.
|
||||
* **New Feature**
|
||||
* Add `--keep-module-id-extensions`/`keepModuleIdExtensions` option to keep extensions in module ids.
|
||||
* **Polish**
|
||||
* Special case single argument spread properties in `super` inside classes.
|
||||
* Don't use a variable declaration for class declaration IFFE.
|
||||
* Rename `inherits` helper parameters.
|
||||
* `coreAliasing` transformer now aliases `Promise`, `Set`, `Map` and more. Thanks [@AluisioASG](https://github.com/AluisioASG).
|
||||
|
||||
## 2.10.1
|
||||
|
||||
* **Internal**
|
||||
* Upgrade `core-js` to `0.4.4`.
|
||||
* **New Feature**
|
||||
* Added `--include-regenerator` option to CLI and `includeRegenerator` option to API that includes the regenerator runtime if necessary.
|
||||
|
||||
## 2.10.0
|
||||
|
||||
* **New Feature**
|
||||
* Add `classesFastSuper` optional transformer that doesn't support parent getters and prototype changing.
|
||||
* Add `forOfFast` transformer that speeds up `for...of` on arrays but produces more code.
|
||||
* Add `--react-compat` to `bin/6to5`.
|
||||
* **Spec Compliancy**
|
||||
* Disallow setters without a single parameter.
|
||||
* Add `configurable` and `writable` to defined properties.
|
||||
* Use define instead of assignment for class methods.
|
||||
* **Polish**
|
||||
* Fix bin name in `6to5-node --help`.
|
||||
* Fix shorthand `--whitelist` name in `bin/6to5`.
|
||||
* **Internal**
|
||||
* Hot code optimisation of traversal etc thanks to [gaearon](https://github.com/gaearon).
|
||||
|
||||
## 2.9.4
|
||||
|
||||
* **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,18 +1,25 @@
|
||||
# Contributing
|
||||
|
||||
Contributions are always welcome, no matter how large or small. 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/6to5.git && cd 6to5`)
|
||||
* 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
|
||||
* Create new pull request explaining your proposed change or reference an issue
|
||||
in your commit message
|
||||
|
||||
#### Code Standards
|
||||
|
||||
|
||||
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
|
||||
|
||||
|
||||
37
Makefile
37
Makefile
@@ -5,21 +5,31 @@ UGLIFY_CMD = node_modules/uglify-js/bin/uglifyjs
|
||||
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 publish-runtime
|
||||
.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 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/babel-external-helpers >dist/external-helpers.js
|
||||
node $(UGLIFY_CMD) dist/external-helpers.js >dist/external-helpers.min.js
|
||||
|
||||
rm -rf templates.json
|
||||
|
||||
@@ -39,20 +49,19 @@ 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:
|
||||
rm -rf coverage
|
||||
export SIMPLE_6TO5_TESTS=1; \
|
||||
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
|
||||
|
||||
@@ -61,7 +70,7 @@ test-browser:
|
||||
|
||||
node tools/cache-templates
|
||||
node tools/cache-tests
|
||||
node $(BROWSERIFY_CMD) -e test/_browser.js >dist/6to5-test.js
|
||||
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
|
||||
@@ -75,8 +84,9 @@ publish:
|
||||
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/external-helpers.min.js external-helpers.js
|
||||
|
||||
node tools/cache-templates
|
||||
test -f templates.json
|
||||
@@ -88,12 +98,12 @@ publish:
|
||||
make publish-core
|
||||
make publish-runtime
|
||||
|
||||
rm -rf templates.json browser.js browser-polyfill.js
|
||||
rm -rf templates.json browser.js browser-polyfill.js external-helpers.js
|
||||
|
||||
publish-runtime:
|
||||
cd packages; \
|
||||
node build-runtime.js; \
|
||||
cd 6to5-runtime; \
|
||||
cd babel-runtime; \
|
||||
npm publish
|
||||
|
||||
publish-core:
|
||||
@@ -110,3 +120,4 @@ bootstrap:
|
||||
npm install
|
||||
git submodule update --init
|
||||
cd vendor/regenerator; npm install
|
||||
cd vendor/compat-table; npm install object-assign
|
||||
|
||||
3
NOTES.md
3
NOTES.md
@@ -1,3 +0,0 @@
|
||||
# Notes
|
||||
|
||||
* Wildcard exports/imports wont normalise if `export default` is a non-object. See [#224](https://github.com/6to5/6to5/issues/224).
|
||||
14
README.md
14
README.md
@@ -1,12 +1,18 @@
|
||||
<p align="center">
|
||||
<img alt="6to5" src="https://raw.githubusercontent.com/6to5/logo/master/logo.png" width="546">
|
||||
<a href="https://babeljs.io/">
|
||||
<img alt="babel" src="https://raw.githubusercontent.com/babel/logo/master/logo.png" width="546">
|
||||
</a>
|
||||
</p>
|
||||
|
||||
<p align="center">
|
||||
<strong>6to5</strong> turns ES6+ code into vanilla ES5, so you can use next generation features <strong>today.</strong>
|
||||
<strong>Babel</strong> is a transpiler for writing next generation JavaScript.
|
||||
</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>
|
||||
|
||||
<p align="center">
|
||||
For documentation and website issues please visit the <a href="https://github.com/babel/babel.github.io">babel.github.io</a> repo.
|
||||
</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,15 +1,16 @@
|
||||
#!/usr/bin/env node
|
||||
|
||||
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");
|
||||
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("6to5-node");
|
||||
var program = new commander.Command("babel-node");
|
||||
|
||||
program.option("-e, --eval [script]", "Evaluate script");
|
||||
program.option("-p, --print [code]", "Evaluate script and print result");
|
||||
@@ -19,6 +20,7 @@ program.option("-r, --experimental", "Enable experimental support for proposed E
|
||||
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);
|
||||
@@ -27,22 +29,24 @@ program.parse(process.argv);
|
||||
|
||||
//
|
||||
|
||||
to5.register({
|
||||
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 = to5.transform(code, {
|
||||
code = babel.transform(code, {
|
||||
filename: filename,
|
||||
blacklist: ["useStrict"].concat(program.blacklist || []),
|
||||
whitelist: program.whitelist,
|
||||
optional: program.optional,
|
||||
experimental: program.experimental,
|
||||
playground: program.playground
|
||||
}).code;
|
||||
@@ -57,12 +61,23 @@ if (program.eval || program.print) {
|
||||
if (program.print) console.log(result);
|
||||
} else {
|
||||
if (program.args.length) {
|
||||
// slice all arguments up to the first filename since they're 6to5 args that we handle
|
||||
// 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 (arg[0] !== "-") {
|
||||
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;
|
||||
}
|
||||
@@ -71,7 +86,7 @@ if (program.eval || program.print) {
|
||||
|
||||
// make the filename absolute
|
||||
var filename = args[0]
|
||||
if (!util.isAbsolute(filename)) args[0] = path.join(process.cwd(), filename);
|
||||
if (!pathIsAbsolute(filename)) args[0] = path.join(process.cwd(), filename);
|
||||
|
||||
// add back on node and concat the sliced args
|
||||
process.argv = ["node"].concat(args);
|
||||
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());
|
||||
@@ -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;
|
||||
|
||||
@@ -11,9 +11,14 @@ 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 data = util.compile(src, {
|
||||
sourceFileName: path.relative(dest + "/..", src)
|
||||
});
|
||||
|
||||
if (commander.sourceMaps) {
|
||||
var mapLoc = dest + ".map";
|
||||
@@ -34,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);
|
||||
@@ -53,10 +63,7 @@ module.exports = function (commander, filenames, opts) {
|
||||
|
||||
_.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 = [];
|
||||
@@ -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 {
|
||||
@@ -1,18 +1,21 @@
|
||||
#!/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, --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("-c, --compact [mode]", "When set to \"auto\" compact is `true` when the input size exceeds 100KB. (auto|true|false)", "auto");
|
||||
commander.option("-m, --modules [modules]", "Module formatter type to use [common]", "common");
|
||||
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);
|
||||
@@ -21,16 +24,17 @@ commander.option("-L, --loose [list]", "List of transformers to enable loose mod
|
||||
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("-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 () {
|
||||
var outKeys = function (title, obj) {
|
||||
console.log(" " + title + ":");
|
||||
console.log();
|
||||
|
||||
_.each(_.keys(obj).sort(), function (key) {
|
||||
each(keys(obj).sort(), function (key) {
|
||||
if (key[0] === "_") return;
|
||||
|
||||
if (obj[key].optional) {
|
||||
@@ -58,7 +62,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");
|
||||
}
|
||||
@@ -97,6 +101,8 @@ if (errors.length) {
|
||||
|
||||
exports.opts = {
|
||||
keepModuleIdExtensions: commander.keepModuleIdExtensions,
|
||||
auxiliaryComment: commander.auxiliaryComment,
|
||||
externalHelpers: commander.externalHelpers,
|
||||
sourceMapName: commander.outFile,
|
||||
experimental: commander.experimental,
|
||||
reactCompat: commander.reactCompat,
|
||||
@@ -108,6 +114,7 @@ exports.opts = {
|
||||
optional: commander.optional,
|
||||
comments: !commander.removeComments,
|
||||
modules: commander.modules,
|
||||
compact: commander.compact,
|
||||
loose: commander.loose
|
||||
};
|
||||
|
||||
@@ -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,17 +12,21 @@ 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;
|
||||
try {
|
||||
result = to5.transform(code, opts);
|
||||
result = babel.transform(code, opts);
|
||||
} catch (e) {
|
||||
if (e instanceof SyntaxError) {
|
||||
console.error("SyntaxError:", e.message);
|
||||
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-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).
|
||||
|
||||
@@ -1,78 +0,0 @@
|
||||
"use strict";
|
||||
|
||||
var _ = require("lodash");
|
||||
var t = require("../../types");
|
||||
|
||||
exports.before = {
|
||||
nodes: {
|
||||
Property: function (node, parent) {
|
||||
if (parent.properties[0] === node) {
|
||||
return 1;
|
||||
}
|
||||
},
|
||||
|
||||
SpreadProperty: function (node, parent) {
|
||||
return exports.before.nodes.Property(node, parent);
|
||||
},
|
||||
|
||||
SwitchCase: function (node, parent) {
|
||||
if (parent.cases[0] === node) {
|
||||
return 1;
|
||||
}
|
||||
},
|
||||
|
||||
CallExpression: function (node) {
|
||||
if (t.isFunction(node.callee)) {
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
exports.after = {
|
||||
nodes: {
|
||||
AssignmentExpression: function (node) {
|
||||
if (t.isFunction(node.right)) {
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
list: {
|
||||
VariableDeclaration: function (node) {
|
||||
return _.map(node.declarations, "init");
|
||||
},
|
||||
|
||||
ArrayExpression: function (node) {
|
||||
return node.elements;
|
||||
},
|
||||
|
||||
ObjectExpression: function (node) {
|
||||
return node.properties;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
_.each({
|
||||
Function: 1,
|
||||
Class: 1,
|
||||
For: 1,
|
||||
ArrayExpression: { after: 1 },
|
||||
ObjectExpression: { after: 1 },
|
||||
SwitchStatement: 1,
|
||||
IfStatement: { before: 1 },
|
||||
CallExpression: { after: 1 },
|
||||
Literal: { after: 1 }
|
||||
}, function (amounts, type) {
|
||||
if (_.isNumber(amounts)) {
|
||||
amounts = { after: amounts, before: amounts };
|
||||
}
|
||||
|
||||
_.each([type].concat(t.FLIPPED_ALIAS_KEYS[type] || []), function (type) {
|
||||
_.each(amounts, function (amount, key) {
|
||||
exports[key].nodes[type] = function () {
|
||||
return amount;
|
||||
};
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -1,12 +0,0 @@
|
||||
"use strict";
|
||||
|
||||
module.exports = function cloneDeep(obj) {
|
||||
var obj2 = {};
|
||||
if (!obj) return obj2;
|
||||
|
||||
for (var key in obj) {
|
||||
obj2[key] = obj[key];
|
||||
}
|
||||
|
||||
return obj2;
|
||||
};
|
||||
@@ -1,9 +0,0 @@
|
||||
"use strict";
|
||||
|
||||
if (global._6to5Polyfill) {
|
||||
throw new Error("only one instance of 6to5/polyfill is allowed");
|
||||
}
|
||||
global._6to5Polyfill = true;
|
||||
|
||||
require("core-js/shim");
|
||||
require("regenerator-6to5/runtime");
|
||||
@@ -1,7 +0,0 @@
|
||||
"use strict";
|
||||
|
||||
// required to safely use 6to5/register within a browserify codebase
|
||||
|
||||
module.exports = function () {};
|
||||
|
||||
require("./polyfill");
|
||||
@@ -1,107 +0,0 @@
|
||||
"use strict";
|
||||
|
||||
require("./polyfill");
|
||||
|
||||
var sourceMapSupport = require("source-map-support");
|
||||
var registerCache = require("./register-cache");
|
||||
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;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
//
|
||||
|
||||
registerCache.load();
|
||||
var cache = registerCache.get();
|
||||
|
||||
//
|
||||
|
||||
var transformOpts = {};
|
||||
var ignoreRegex = /node_modules/;
|
||||
var onlyRegex;
|
||||
var whitelist = [];
|
||||
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,
|
||||
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(util.canCompile.EXTENSIONS);
|
||||
|
||||
module.exports = function (opts) {
|
||||
// normalise 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);
|
||||
};
|
||||
@@ -1,21 +0,0 @@
|
||||
"use strict";
|
||||
|
||||
var t = require("../../types");
|
||||
|
||||
exports.has = function (node) {
|
||||
var first = node.body[0];
|
||||
return t.isExpressionStatement(first) && t.isLiteral(first.expression, { value: "use strict" });
|
||||
};
|
||||
|
||||
exports.wrap = function (node, callback) {
|
||||
var useStrictNode;
|
||||
if (exports.has(node)) {
|
||||
useStrictNode = node.body.shift();
|
||||
}
|
||||
|
||||
callback();
|
||||
|
||||
if (useStrictNode) {
|
||||
node.body.unshift(useStrictNode);
|
||||
}
|
||||
};
|
||||
@@ -1,3 +0,0 @@
|
||||
if (Object.getPrototypeOf(CLASS_NAME) !== null) {
|
||||
Object.getPrototypeOf(CLASS_NAME).apply(this, arguments);
|
||||
}
|
||||
@@ -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,69 +0,0 @@
|
||||
module.exports = TransformerPass;
|
||||
|
||||
var traverse = require("../traverse");
|
||||
var _ = require("lodash");
|
||||
|
||||
/**
|
||||
* This class is responsible for traversing over the provided `File`s
|
||||
* AST and running it's parent transformers handlers over it.
|
||||
*/
|
||||
|
||||
function TransformerPass(file, transformer) {
|
||||
this.transformer = transformer;
|
||||
this.handlers = transformer.handlers;
|
||||
this.file = file;
|
||||
}
|
||||
|
||||
TransformerPass.prototype.astRun = function (key) {
|
||||
var handlers = this.handlers;
|
||||
var file = this.file;
|
||||
|
||||
if (handlers.ast && handlers.ast[key]) {
|
||||
handlers.ast[key](file.ast, file);
|
||||
}
|
||||
};
|
||||
|
||||
TransformerPass.prototype.canRun = function () {
|
||||
var transformer = this.transformer;
|
||||
|
||||
var opts = this.file.opts;
|
||||
var key = transformer.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 (transformer.optional && !_.contains(opts.optional, key)) return false;
|
||||
|
||||
if (transformer.experimental && !opts.experimental) return false;
|
||||
|
||||
return true;
|
||||
};
|
||||
|
||||
var transformVisitor = {
|
||||
enter: function (node, parent, scope, context, state) {
|
||||
var fns = state.handlers[node.type];
|
||||
if (!fns) return;
|
||||
return fns.enter(node, parent, scope, context, state.file, state.pass);
|
||||
},
|
||||
|
||||
exit: function (node, parent, scope, context, state) {
|
||||
var fns = state.handlers[node.type];
|
||||
if (!fns) return;
|
||||
return fns.exit(node, parent, scope, context, state.file, state.pass);
|
||||
}
|
||||
};
|
||||
|
||||
TransformerPass.prototype.transform = function () {
|
||||
var file = this.file;
|
||||
|
||||
this.astRun("before");
|
||||
|
||||
var state = { file: file, handlers: this.handlers, pass: this };
|
||||
traverse(file.ast, transformVisitor, file.scope, state);
|
||||
|
||||
this.astRun("after");
|
||||
};
|
||||
@@ -1,61 +0,0 @@
|
||||
"use strict";
|
||||
|
||||
module.exports = Transformer;
|
||||
|
||||
var TransformerPass = require("./transformer-pass");
|
||||
var t = require("../types");
|
||||
var _ = require("lodash");
|
||||
|
||||
/**
|
||||
* This is the class responsible for normalising a transformers handlers
|
||||
* as well as constructing a `TransformerPass` that is repsonsible for
|
||||
* actually running the transformer over the provided `File`.
|
||||
*/
|
||||
|
||||
function Transformer(key, transformer, opts) {
|
||||
this.manipulateOptions = transformer.manipulateOptions;
|
||||
this.experimental = !!transformer.experimental;
|
||||
this.secondPass = !!transformer.secondPass;
|
||||
this.optional = !!transformer.optional;
|
||||
this.handlers = this.normalise(transformer);
|
||||
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;
|
||||
|
||||
if (!fns.enter) fns.enter = _.noop;
|
||||
if (!fns.exit) fns.exit = _.noop;
|
||||
|
||||
transformer[type] = fns;
|
||||
|
||||
var aliases = t.FLIPPED_ALIAS_KEYS[type];
|
||||
if (aliases) {
|
||||
_.each(aliases, function (alias) {
|
||||
transformer[alias] = fns;
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
return transformer;
|
||||
};
|
||||
|
||||
Transformer.prototype.buildPass = function (file) {
|
||||
return new TransformerPass(file, this);
|
||||
};
|
||||
@@ -1,38 +0,0 @@
|
||||
{
|
||||
"specNoForInOfAssignment": "validation.noForInOfAssignment",
|
||||
"specSetters": "validation.setters",
|
||||
"specBlockScopedFunctions": "spec.blockScopedFunctions",
|
||||
"malletOperator": "playground.malletOperator",
|
||||
"methodBinding": "playground.methodBinding",
|
||||
"memoizationOperator": "playground.memoizationOperator",
|
||||
"objectGetterMemoization": "playground.objectGetterMemoization",
|
||||
"modules": "es6.modules",
|
||||
"propertyNameShorthand": "es6.properties.shorthand",
|
||||
"arrayComprehension": "es7.comprehensions",
|
||||
"generatorComprehension": "es7.comprehensions",
|
||||
"arrowFunctions": "es6.arrowFunctions",
|
||||
"classes": "es6.classes",
|
||||
"objectSpread": "es7.objectSpread",
|
||||
"exponentiationOperator": "es7.exponentiationOperator",
|
||||
"spread": "es6.spread",
|
||||
"templateLiterals": "es6.templateLiterals",
|
||||
"propertyMethodAssignment": "es6.properties.shorthand",
|
||||
"computedPropertyNames": "es6.properties.computed",
|
||||
"defaultParameters": "es6.parameters.default",
|
||||
"restParameters": "es6.parameters.rest",
|
||||
"destructuring": "es6.destructuring",
|
||||
"forOf": "es6.forOf",
|
||||
"unicodeRegex": "es6.unicodeRegex",
|
||||
"abstractReferences": "es7.abstractReferences",
|
||||
"constants": "es6.constants",
|
||||
"letScoping": "es6.letScoping",
|
||||
"blockScopingTDZ": "es6.blockScopingTDZ",
|
||||
"generators": "regenerator",
|
||||
"protoToAssign": "spec.protoToAssign",
|
||||
"typeofSymbol": "spec.typeofSymbol",
|
||||
"coreAliasing": "selfContained",
|
||||
"undefinedToVoid": "spec.undefinedToVoid",
|
||||
"undeclaredVariableCheck": "validation.undeclaredVariableCheck",
|
||||
"specPropertyLiterals": "minification.propertyLiterals",
|
||||
"specMemberExpressionLiterals": "minification.memberExpressionLiterals"
|
||||
}
|
||||
@@ -1,50 +0,0 @@
|
||||
"use strict";
|
||||
|
||||
var traverse = require("../../../traverse");
|
||||
var t = require("../../../types");
|
||||
|
||||
var visitor = {
|
||||
enter: function (node, parent, scope, context, state) {
|
||||
if (!t.isReferencedIdentifier(node, parent)) return;
|
||||
|
||||
var declared = state.letRefs[node.name];
|
||||
if (!declared) return;
|
||||
|
||||
// declared node is different in this scope
|
||||
if (scope.get(node.name, true) !== declared) return;
|
||||
|
||||
var declaredLoc = declared.loc;
|
||||
var referenceLoc = node.loc;
|
||||
|
||||
if (!declaredLoc || !referenceLoc) return;
|
||||
|
||||
// does this reference appear on a line before the declaration?
|
||||
var before = referenceLoc.start.line < declaredLoc.start.line;
|
||||
|
||||
if (referenceLoc.start.line === declaredLoc.start.line) {
|
||||
// this reference appears on the same line
|
||||
// check it appears before the declaration
|
||||
before = referenceLoc.start.col < declaredLoc.start.col;
|
||||
}
|
||||
|
||||
if (before) {
|
||||
throw state.file.errorWithNode(node, "Temporal dead zone - accessing a variable before it's initialized");
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
exports.optional = true;
|
||||
|
||||
exports.Loop =
|
||||
exports.Program =
|
||||
exports.BlockStatement = function (node, parent, scope, context, file) {
|
||||
var letRefs = node._letReferences;
|
||||
if (!letRefs) return;
|
||||
|
||||
var state = {
|
||||
letRefs: letRefs,
|
||||
file: file
|
||||
};
|
||||
|
||||
traverse(node, visitor, scope, state);
|
||||
};
|
||||
@@ -1,41 +0,0 @@
|
||||
"use strict";
|
||||
|
||||
var traverse = require("../../../traverse");
|
||||
var t = require("../../../types");
|
||||
|
||||
var visitor = {
|
||||
enter: function (node, parent, scope, context, state) {
|
||||
if (t.isDeclaration(node) || t.isAssignmentExpression(node)) {
|
||||
var ids = t.getIds(node, true);
|
||||
|
||||
for (var key in ids) {
|
||||
var id = ids[key];
|
||||
|
||||
var constant = state.constants[key];
|
||||
|
||||
// no constant exists
|
||||
if (!constant) continue;
|
||||
|
||||
// check if the assignment id matches the constant declaration id
|
||||
// if it does then it was the id used to initially declare the
|
||||
// constant so we can just ignore it
|
||||
if (id === constant) continue;
|
||||
|
||||
throw state.file.errorWithNode(id, key + " is read-only");
|
||||
}
|
||||
} else if (t.isScope(node)) {
|
||||
context.skip();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
exports.Scope = function (node, parent, scope, context, file) {
|
||||
traverse(node, visitor, scope, {
|
||||
constants: scope.getAllOfKind("const"),
|
||||
file: file
|
||||
});
|
||||
};
|
||||
|
||||
exports.VariableDeclaration = function (node) {
|
||||
if (node.kind === "const") node.kind = "let";
|
||||
};
|
||||
@@ -1,343 +0,0 @@
|
||||
"use strict";
|
||||
|
||||
// TODO: Clean up
|
||||
|
||||
var t = require("../../../types");
|
||||
|
||||
var buildVariableAssign = function (opts, id, init) {
|
||||
var op = opts.operator;
|
||||
if (t.isMemberExpression(id)) op = "=";
|
||||
|
||||
var node;
|
||||
|
||||
if (op) {
|
||||
node = t.expressionStatement(t.assignmentExpression(op, id, init));
|
||||
} else {
|
||||
node = t.variableDeclaration(opts.kind, [
|
||||
t.variableDeclarator(id, init)
|
||||
]);
|
||||
}
|
||||
|
||||
node._blockHoist = opts.blockHoist;
|
||||
|
||||
return node;
|
||||
};
|
||||
|
||||
var buildVariableDeclar = function (opts, id, init) {
|
||||
var declar = t.variableDeclaration("var", [
|
||||
t.variableDeclarator(id, init)
|
||||
]);
|
||||
declar._blockHoist = opts.blockHoist;
|
||||
return declar;
|
||||
};
|
||||
|
||||
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 = 0; i < pattern.properties.length; i++) {
|
||||
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 = 0; i2 < pattern.properties.length; i2++) {
|
||||
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 hasRest = false;
|
||||
for (i = 0; i < pattern.elements.length; i++) {
|
||||
if (t.isRestElement(pattern.elements[i])) {
|
||||
hasRest = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
var toArray = opts.file.toArray(parentId, !hasRest && pattern.elements.length);
|
||||
|
||||
var _parentId = opts.scope.generateUidBasedOnNode(parentId, opts.file);
|
||||
nodes.push(buildVariableDeclar(opts, _parentId, toArray));
|
||||
parentId = _parentId;
|
||||
|
||||
for (i = 0; i < pattern.elements.length; i++) {
|
||||
var elem = pattern.elements[i];
|
||||
if (!elem) continue;
|
||||
|
||||
i = +i;
|
||||
|
||||
var newPatternId;
|
||||
|
||||
if (t.isRestElement(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 scope = opts.scope;
|
||||
|
||||
if (!t.isArrayExpression(parentId) && !t.isMemberExpression(parentId) && !t.isIdentifier(parentId)) {
|
||||
var key = scope.generateUidBasedOnNode(parentId);
|
||||
nodes.push(buildVariableDeclar(opts, key, parentId));
|
||||
parentId = key;
|
||||
}
|
||||
|
||||
push(opts, nodes, pattern, parentId);
|
||||
};
|
||||
|
||||
exports.ForInStatement =
|
||||
exports.ForOfStatement = function (node, parent, scope, context, file) {
|
||||
var declar = node.left;
|
||||
if (!t.isVariableDeclaration(declar)) return;
|
||||
|
||||
var pattern = declar.declarations[0].id;
|
||||
if (!t.isPattern(pattern)) return;
|
||||
|
||||
var key = scope.generateUidIdentifier("ref");
|
||||
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, scope, context, file) {
|
||||
var nodes = [];
|
||||
|
||||
var hasDestructuring = false;
|
||||
|
||||
node.params = node.params.map(function (pattern, i) {
|
||||
if (!t.isPattern(pattern)) return pattern;
|
||||
|
||||
hasDestructuring = true;
|
||||
var parentId = scope.generateUidIdentifier("ref");
|
||||
|
||||
pushPattern({
|
||||
blockHoist: node.params.length - i,
|
||||
pattern: pattern,
|
||||
nodes: nodes,
|
||||
scope: scope,
|
||||
file: file,
|
||||
kind: "var",
|
||||
id: parentId
|
||||
});
|
||||
|
||||
return parentId;
|
||||
});
|
||||
|
||||
if (!hasDestructuring) return;
|
||||
|
||||
t.ensureBlock(node);
|
||||
|
||||
var block = node.body;
|
||||
block.body = nodes.concat(block.body);
|
||||
};
|
||||
|
||||
exports.CatchClause = function (node, parent, scope, context, file) {
|
||||
var pattern = node.param;
|
||||
if (!t.isPattern(pattern)) return;
|
||||
|
||||
var ref = scope.generateUidIdentifier("ref");
|
||||
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, scope, context, file) {
|
||||
var expr = node.expression;
|
||||
if (expr.type !== "AssignmentExpression") return;
|
||||
if (!t.isPattern(expr.left)) return;
|
||||
if (file.isConsequenceExpressionStatement(node)) return;
|
||||
|
||||
var nodes = [];
|
||||
|
||||
var ref = scope.generateUidIdentifier("ref");
|
||||
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, scope, context, file) {
|
||||
if (!t.isPattern(node.left)) return;
|
||||
|
||||
var ref = scope.generateUidIdentifier("temp");
|
||||
scope.push({
|
||||
key: ref.name,
|
||||
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, scope, context, file) {
|
||||
if (t.isForInStatement(parent) || t.isForOfStatement(parent)) return;
|
||||
|
||||
var nodes = [];
|
||||
var i;
|
||||
var declar;
|
||||
|
||||
var hasPattern = false;
|
||||
for (i = 0; i < node.declarations.length; i++) {
|
||||
declar = node.declarations[i];
|
||||
if (t.isPattern(declar.id)) {
|
||||
hasPattern = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!hasPattern) return;
|
||||
|
||||
for (i = 0; i < node.declarations.length; i++) {
|
||||
declar = node.declarations[i];
|
||||
|
||||
var patternId = declar.init;
|
||||
var pattern = declar.id;
|
||||
var opts = {
|
||||
pattern: pattern,
|
||||
nodes: nodes,
|
||||
scope: scope,
|
||||
kind: node.kind,
|
||||
file: file,
|
||||
id: patternId,
|
||||
};
|
||||
|
||||
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 = 0; i < nodes.length; i++) {
|
||||
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,100 +0,0 @@
|
||||
"use strict";
|
||||
|
||||
var util = require("../../../util");
|
||||
var t = require("../../../types");
|
||||
|
||||
exports.ForOfStatement = function (node, parent, scope, context, file) {
|
||||
var callback = spec;
|
||||
if (file.isLoose("es6.forOf")) callback = loose;
|
||||
|
||||
var build = callback(node, parent, scope, context, file);
|
||||
var declar = build.declar;
|
||||
var loop = build.loop;
|
||||
var block = loop.body;
|
||||
|
||||
// inherit comments from the original loop
|
||||
t.inheritsComments(loop, node);
|
||||
|
||||
// ensure that it's a block so we can take all it's statemetns
|
||||
t.ensureBlock(node);
|
||||
|
||||
// add the value declaration to the new loop body
|
||||
if (declar) {
|
||||
if (build.shouldUnshift) {
|
||||
block.body.unshift(declar);
|
||||
} else {
|
||||
block.body.push(declar);
|
||||
}
|
||||
}
|
||||
|
||||
// push the rest of the original loop body onto our new body
|
||||
block.body = block.body.concat(node.body.body);
|
||||
|
||||
// todo: find out why this is necessary? #538
|
||||
loop._scopeInfo = node._scopeInfo;
|
||||
|
||||
return loop;
|
||||
};
|
||||
|
||||
var loose = function (node, parent, scope, context, file) {
|
||||
var left = node.left;
|
||||
var declar, id;
|
||||
|
||||
if (t.isIdentifier(left) || t.isPattern(left)) {
|
||||
// for (i of test), for ({ i } of test)
|
||||
id = left;
|
||||
} else if (t.isVariableDeclaration(left)) {
|
||||
// for (var i of test)
|
||||
id = left.declarations[0].id;
|
||||
declar = t.variableDeclaration(left.kind, [
|
||||
t.variableDeclarator(id)
|
||||
]);
|
||||
} else {
|
||||
throw file.errorWithNode(left, "Unknown node type " + left.type + " in ForOfStatement");
|
||||
}
|
||||
|
||||
var loop = util.template("for-of-loose", {
|
||||
LOOP_OBJECT: scope.generateUidIdentifier("iterator"),
|
||||
IS_ARRAY: scope.generateUidIdentifier("isArray"),
|
||||
OBJECT: node.right,
|
||||
INDEX: scope.generateUidIdentifier("i"),
|
||||
ID: id
|
||||
});
|
||||
|
||||
return {
|
||||
shouldUnshift: true,
|
||||
declar: declar,
|
||||
loop: loop
|
||||
};
|
||||
};
|
||||
|
||||
var spec = function (node, parent, scope, context, file) {
|
||||
var left = node.left;
|
||||
var declar;
|
||||
|
||||
var stepKey = scope.generateUidIdentifier("step");
|
||||
var stepValue = t.memberExpression(stepKey, t.identifier("value"));
|
||||
|
||||
if (t.isIdentifier(left) || t.isPattern(left)) {
|
||||
// for (i of test), for ({ i } of test)
|
||||
declar = t.expressionStatement(t.assignmentExpression("=", left, stepValue));
|
||||
} else if (t.isVariableDeclaration(left)) {
|
||||
// for (var i of test)
|
||||
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 loop = util.template("for-of", {
|
||||
ITERATOR_KEY: scope.generateUidIdentifier("iterator"),
|
||||
STEP_KEY: stepKey,
|
||||
OBJECT: node.right
|
||||
});
|
||||
|
||||
return {
|
||||
declar: declar,
|
||||
loop: loop
|
||||
};
|
||||
};
|
||||
@@ -1,17 +0,0 @@
|
||||
"use strict";
|
||||
|
||||
var nameMethod = require("../../helpers/name-method");
|
||||
var t = require("../../../types");
|
||||
var _ = require("lodash");
|
||||
|
||||
exports.Property = function (node, parent, scope, context, file) {
|
||||
if (node.method) {
|
||||
node.method = false;
|
||||
nameMethod.property(node, file, scope);
|
||||
}
|
||||
|
||||
if (node.shorthand) {
|
||||
node.shorthand = false;
|
||||
node.key = t.removeComments(_.clone(node.key));
|
||||
}
|
||||
};
|
||||
@@ -1,36 +0,0 @@
|
||||
"use strict";
|
||||
|
||||
var useStrict = require("../../helpers/use-strict");
|
||||
var t = require("../../../types");
|
||||
|
||||
exports.secondPass = true;
|
||||
|
||||
exports.BlockStatement =
|
||||
exports.Program = function (node) {
|
||||
if (!node._declarations) return;
|
||||
|
||||
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,17 +0,0 @@
|
||||
"use strict";
|
||||
|
||||
var useStrict = require("../../helpers/use-strict");
|
||||
|
||||
exports.ast = {
|
||||
exit: function (ast, file) {
|
||||
if (!file.transformers["es6.modules"].canRun()) return;
|
||||
|
||||
useStrict.wrap(ast.program, function () {
|
||||
ast.program.body = file.dynamicImports.concat(ast.program.body);
|
||||
});
|
||||
|
||||
if (file.moduleFormatter.transform) {
|
||||
file.moduleFormatter.transform(ast);
|
||||
}
|
||||
}
|
||||
};
|
||||
265
lib/6to5/transformation/transformers/other/react.js
vendored
265
lib/6to5/transformation/transformers/other/react.js
vendored
@@ -1,265 +0,0 @@
|
||||
"use strict";
|
||||
|
||||
// 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.JSXIdentifier = function (node) {
|
||||
if (esutils.keyword.isIdentifierName(node.name)) {
|
||||
node.type = "Identifier";
|
||||
} else {
|
||||
return t.literal(node.name);
|
||||
}
|
||||
};
|
||||
|
||||
exports.JSXNamespacedName = function (node, parent, scope, context, file) {
|
||||
throw file.errorWithNode(node, "Namespace tags are not supported. ReactJSX is not XML.");
|
||||
};
|
||||
|
||||
exports.JSXMemberExpression = {
|
||||
exit: function (node) {
|
||||
node.computed = t.isLiteral(node.property);
|
||||
node.type = "MemberExpression";
|
||||
}
|
||||
};
|
||||
|
||||
exports.JSXExpressionContainer = function (node) {
|
||||
return node.expression;
|
||||
};
|
||||
|
||||
exports.JSXAttribute = {
|
||||
exit: function (node) {
|
||||
var value = node.value || t.literal(true);
|
||||
return t.inherits(t.property("init", node.name, value), node);
|
||||
}
|
||||
};
|
||||
|
||||
var isCompatTag = function (tagName) {
|
||||
return /^[a-z]|\-/.test(tagName);
|
||||
};
|
||||
|
||||
exports.JSXOpeningElement = {
|
||||
exit: function (node, parent, scope, context, 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 && isCompatTag(tagName)) {
|
||||
args.push(t.literal(tagName));
|
||||
} else {
|
||||
args.push(tagExpr);
|
||||
}
|
||||
}
|
||||
|
||||
var attribs = node.attributes;
|
||||
if (attribs.length) {
|
||||
attribs = buildJSXOpeningElementAttributes(attribs, file);
|
||||
} else {
|
||||
attribs = t.literal(null);
|
||||
}
|
||||
|
||||
args.push(attribs);
|
||||
|
||||
if (reactCompat) {
|
||||
if (tagName && isCompatTag(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);
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* The logic for this is quite terse. It's because we need to
|
||||
* support spread elements. We loop over all attributes,
|
||||
* breaking on spreads, we then push a new object containg
|
||||
* all prior attributes to an array for later processing.
|
||||
*/
|
||||
|
||||
var buildJSXOpeningElementAttributes = function (attribs, file) {
|
||||
var _props = [];
|
||||
var objs = [];
|
||||
|
||||
var pushProps = function () {
|
||||
if (!_props.length) return;
|
||||
|
||||
objs.push(t.objectExpression(_props));
|
||||
_props = [];
|
||||
};
|
||||
|
||||
while (attribs.length) {
|
||||
var prop = attribs.shift();
|
||||
if (t.isJSXSpreadAttribute(prop)) {
|
||||
pushProps();
|
||||
objs.push(prop.argument);
|
||||
} else {
|
||||
_props.push(prop);
|
||||
}
|
||||
}
|
||||
|
||||
pushProps();
|
||||
|
||||
if (objs.length === 1) {
|
||||
// only one object
|
||||
attribs = objs[0];
|
||||
} else {
|
||||
// looks like we have multiple objects
|
||||
if (!t.isObjectExpression(objs[0])) {
|
||||
objs.unshift(t.objectExpression([]));
|
||||
}
|
||||
|
||||
// spread it
|
||||
attribs = t.callExpression(
|
||||
file.addHelper("extends"),
|
||||
objs
|
||||
);
|
||||
}
|
||||
|
||||
return attribs;
|
||||
};
|
||||
|
||||
exports.JSXElement = {
|
||||
exit: function (node) {
|
||||
var callExpr = node.openingElement;
|
||||
|
||||
for (var i = 0; i < node.children.length; i++) {
|
||||
var child = node.children[i];
|
||||
|
||||
if (t.isLiteral(child) && typeof child.value === "string") {
|
||||
cleanJSXElementLiteralChild(child, callExpr.arguments);
|
||||
continue;
|
||||
} else if (t.isJSXEmptyExpression(child)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
callExpr.arguments.push(child);
|
||||
}
|
||||
|
||||
if (callExpr.arguments.length >= 3) {
|
||||
callExpr._prettyCall = true;
|
||||
}
|
||||
|
||||
return t.inherits(callExpr, node);
|
||||
}
|
||||
};
|
||||
|
||||
var cleanJSXElementLiteralChild = function (child, args) {
|
||||
var lines = child.value.split(/\r\n|\n|\r/);
|
||||
|
||||
for (var i = 0; i < lines.length; i++) {
|
||||
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) {
|
||||
args.push(t.literal(trimmedLine));
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
// display names
|
||||
|
||||
var isCreateClass = function (call) {
|
||||
if (!call || !t.isCallExpression(call)) return false;
|
||||
|
||||
var callee = call.callee;
|
||||
if (!t.isMemberExpression(callee)) return false;
|
||||
|
||||
// not React call member object
|
||||
var obj = callee.object;
|
||||
if (!t.isIdentifier(obj, { name: "React" })) return false;
|
||||
|
||||
// not createClass call member property
|
||||
var prop = callee.property;
|
||||
if (!t.isIdentifier(prop, { name: "createClass" })) return false;
|
||||
|
||||
// no call arguments
|
||||
var args = call.arguments;
|
||||
if (args.length !== 1) return false;
|
||||
|
||||
// first call arg is not an object
|
||||
var first = args[0];
|
||||
if (!t.isObjectExpression(first)) return;
|
||||
|
||||
return true;
|
||||
};
|
||||
|
||||
var addDisplayName = function (id, call) {
|
||||
if (!isCreateClass(call)) return;
|
||||
|
||||
var props = call.arguments[0].properties;
|
||||
var safe = true;
|
||||
|
||||
for (var i = 0; i < props.length; i++) {
|
||||
var 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,11 +0,0 @@
|
||||
"use strict";
|
||||
|
||||
var regenerator = require("regenerator-6to5");
|
||||
|
||||
exports.ast = {
|
||||
before: function (ast, file) {
|
||||
regenerator.transform(ast, {
|
||||
includeRuntime: file.opts.includeRegenerator && "if used"
|
||||
});
|
||||
}
|
||||
};
|
||||
@@ -1,87 +0,0 @@
|
||||
"use strict";
|
||||
|
||||
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);
|
||||
};
|
||||
|
||||
var ALIASABLE_CONSTRUCTORS = [
|
||||
"Symbol",
|
||||
"Promise",
|
||||
"Map",
|
||||
"WeakMap",
|
||||
"Set",
|
||||
"WeakSet"
|
||||
];
|
||||
|
||||
var astVisitor = {
|
||||
enter: function (node, parent, scope, context, file) {
|
||||
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)) {
|
||||
context.skip();
|
||||
return t.prependToMemberExpression(node, file.get("coreIdentifier"));
|
||||
}
|
||||
} else if (t.isReferencedIdentifier(node, parent) && !t.isMemberExpression(parent) && _.contains(ALIASABLE_CONSTRUCTORS, node.name) && !scope.get(node.name, true)) {
|
||||
// Symbol() -> _core.Symbol(); new Promise -> new _core.Promise
|
||||
return t.memberExpression(file.get("coreIdentifier"), 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.get("coreIdentifier"),
|
||||
VALUE: callee.object
|
||||
});
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
exports.optional = true;
|
||||
|
||||
exports.ast = {
|
||||
enter: function (ast, file) {
|
||||
file.setDynamic("runtimeIdentifier", function () {
|
||||
return file.addImport("6to5-runtime/helpers", "to5Helpers");
|
||||
});
|
||||
|
||||
file.setDynamic("coreIdentifier", function () {
|
||||
return file.addImport("6to5-runtime/core-js", "core");
|
||||
});
|
||||
|
||||
file.setDynamic("regeneratorIdentifier", function () {
|
||||
return file.addImport("6to5-runtime/regenerator", "regeneratorRuntime");
|
||||
});
|
||||
},
|
||||
|
||||
after: function (ast, file) {
|
||||
traverse(ast, astVisitor, null, file);
|
||||
}
|
||||
};
|
||||
|
||||
exports.Identifier = function (node, parent, scope, context, file) {
|
||||
if (node.name === "regeneratorRuntime" && t.isReferenced(node, parent)) {
|
||||
return file.get("regeneratorIdentifier");
|
||||
}
|
||||
};
|
||||
@@ -1,21 +0,0 @@
|
||||
"use strict";
|
||||
|
||||
var useStrict = require("../../helpers/use-strict");
|
||||
var t = require("../../../types");
|
||||
|
||||
exports.ast = {
|
||||
exit: function (ast) {
|
||||
if (!useStrict.has(ast.program)) {
|
||||
ast.program.body.unshift(t.expressionStatement(t.literal("use strict")));
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
exports.FunctionDeclaration =
|
||||
exports.FunctionExpression = function (node, parent, scope, context) {
|
||||
context.skip();
|
||||
};
|
||||
|
||||
exports.ThisExpression = function (node, parent, scope, context, file) {
|
||||
throw file.errorWithNode(node, "Top level `this` is not allowed", ReferenceError);
|
||||
};
|
||||
@@ -1,12 +0,0 @@
|
||||
"use strict";
|
||||
|
||||
var t = require("../../../types");
|
||||
|
||||
exports.ForInStatement =
|
||||
exports.ForOfStatement = function (node, parent, scope, context, 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,8 +0,0 @@
|
||||
"use strict";
|
||||
|
||||
exports.MethodDefinition =
|
||||
exports.Property = function (node, parent, scope, context, file) {
|
||||
if (node.kind === "set" && node.value.params.length !== 1) {
|
||||
throw file.errorWithNode(node.value, "Setters must have only one parameter");
|
||||
}
|
||||
};
|
||||
@@ -1,9 +0,0 @@
|
||||
"use strict";
|
||||
|
||||
exports.optional = true;
|
||||
|
||||
exports.Identifier = function (node, parent, scope, context, file) {
|
||||
if (!scope.has(node.name, true)) {
|
||||
throw file.errorWithNode(node, "Reference to undeclared variable", ReferenceError);
|
||||
}
|
||||
};
|
||||
@@ -1,64 +0,0 @@
|
||||
[
|
||||
"Set",
|
||||
"Map",
|
||||
"WeakMap",
|
||||
"WeakSet",
|
||||
"Proxy",
|
||||
"Promise",
|
||||
"Reflect",
|
||||
"Symbol",
|
||||
"System",
|
||||
"__filename",
|
||||
"__dirname",
|
||||
"GLOBAL",
|
||||
"global",
|
||||
"module",
|
||||
"require",
|
||||
"Buffer",
|
||||
"console",
|
||||
"exports",
|
||||
"process",
|
||||
"setTimeout",
|
||||
"clearTimeout",
|
||||
"setInterval",
|
||||
"clearInterval",
|
||||
"setImmediate",
|
||||
"clearImmediate",
|
||||
"Array",
|
||||
"Boolean",
|
||||
"Date",
|
||||
"decodeURI",
|
||||
"decodeURIComponent",
|
||||
"encodeURI",
|
||||
"encodeURIComponent",
|
||||
"Error",
|
||||
"eval",
|
||||
"EvalError",
|
||||
"Function",
|
||||
"hasOwnProperty",
|
||||
"isFinite",
|
||||
"isNaN",
|
||||
"JSON",
|
||||
"Map",
|
||||
"Math",
|
||||
"Number",
|
||||
"Object",
|
||||
"Proxy",
|
||||
"Promise",
|
||||
"parseInt",
|
||||
"parseFloat",
|
||||
"RangeError",
|
||||
"ReferenceError",
|
||||
"RegExp",
|
||||
"Set",
|
||||
"String",
|
||||
"SyntaxError",
|
||||
"TypeError",
|
||||
"URIError",
|
||||
"WeakMap",
|
||||
"WeakSet",
|
||||
"arguments",
|
||||
"NaN",
|
||||
"window",
|
||||
"self"
|
||||
]
|
||||
@@ -1,260 +0,0 @@
|
||||
"use strict";
|
||||
|
||||
module.exports = traverse;
|
||||
|
||||
/* jshint maxparams:7 */
|
||||
|
||||
var Scope = require("./scope");
|
||||
var t = require("../types");
|
||||
var _ = require("lodash");
|
||||
|
||||
function TraversalContext() {
|
||||
this.shouldFlatten = false;
|
||||
this.shouldRemove = false;
|
||||
this.shouldSkip = false;
|
||||
this.shouldStop = false;
|
||||
}
|
||||
|
||||
TraversalContext.prototype.flatten = function () {
|
||||
this.shouldFlatten = true;
|
||||
};
|
||||
|
||||
TraversalContext.prototype.remove = function () {
|
||||
this.shouldRemove = true;
|
||||
this.shouldSkip = true;
|
||||
};
|
||||
|
||||
TraversalContext.prototype.skip = function () {
|
||||
this.shouldSkip = true;
|
||||
};
|
||||
|
||||
TraversalContext.prototype.stop = function () {
|
||||
this.shouldStop = true;
|
||||
this.shouldSkip = true;
|
||||
};
|
||||
|
||||
TraversalContext.prototype.reset = function () {
|
||||
this.shouldRemove = false;
|
||||
this.shouldSkip = false;
|
||||
this.shouldStop = false;
|
||||
};
|
||||
|
||||
function replaceNode(obj, key, node, result) {
|
||||
var isArray = Array.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
|
||||
obj[key] = result;
|
||||
|
||||
// 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);
|
||||
}
|
||||
|
||||
if (isArray) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
TraversalContext.prototype.enterNode = function (obj, key, node, enter, parent, scope, state) {
|
||||
var result = enter(node, parent, scope, this, state);
|
||||
var flatten = false;
|
||||
|
||||
if (result) {
|
||||
flatten = replaceNode(obj, key, node, result);
|
||||
node = result;
|
||||
|
||||
if (flatten) {
|
||||
this.shouldFlatten = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (this.shouldRemove) {
|
||||
obj[key] = null;
|
||||
this.shouldFlatten = true;
|
||||
}
|
||||
|
||||
return node;
|
||||
};
|
||||
|
||||
TraversalContext.prototype.exitNode = function (obj, key, node, exit, parent, scope, state) {
|
||||
var result = exit(node, parent, scope, this, state);
|
||||
var flatten = false;
|
||||
|
||||
if (result) {
|
||||
flatten = replaceNode(obj, key, node, result);
|
||||
node = result;
|
||||
|
||||
if (flatten) {
|
||||
this.shouldFlatten = true;
|
||||
}
|
||||
}
|
||||
|
||||
return node;
|
||||
};
|
||||
|
||||
TraversalContext.prototype.visitNode = function (obj, key, opts, scope, parent, state) {
|
||||
this.reset();
|
||||
|
||||
var node = obj[key];
|
||||
|
||||
// type is blacklisted
|
||||
if (opts.blacklist && opts.blacklist.indexOf(node.type) > -1) {
|
||||
return;
|
||||
}
|
||||
|
||||
var ourScope = scope;
|
||||
// we're entering a new scope so let's construct it!
|
||||
if (t.isScope(node)) {
|
||||
ourScope = new Scope(node, parent, scope);
|
||||
}
|
||||
|
||||
node = this.enterNode(obj, key, node, opts.enter, parent, ourScope, state);
|
||||
|
||||
if (this.shouldSkip) {
|
||||
return this.shouldStop;
|
||||
}
|
||||
|
||||
if (Array.isArray(node)) {
|
||||
// traverse over these replacement nodes we purposely don't call exitNode
|
||||
// as the original node has been destroyed
|
||||
for (var i = 0; i < node.length; i++) {
|
||||
traverseNode(node[i], opts, ourScope, state);
|
||||
}
|
||||
} else {
|
||||
traverseNode(node, opts, ourScope, state);
|
||||
this.exitNode(obj, key, node, opts.exit, parent, ourScope, state);
|
||||
}
|
||||
|
||||
return this.shouldStop;
|
||||
};
|
||||
|
||||
TraversalContext.prototype.visit = function (node, key, opts, scope, state) {
|
||||
var nodes = node[key];
|
||||
if (!nodes) return;
|
||||
|
||||
if (!Array.isArray(nodes)) {
|
||||
return this.visitNode(node, key, opts, scope, node, state);
|
||||
}
|
||||
|
||||
if (nodes.length === 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
for (var i = 0; i < nodes.length; i++) {
|
||||
if (nodes[i] && this.visitNode(nodes, i, opts, scope, node, state)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
if (this.shouldFlatten) {
|
||||
node[key] = _.flatten(node[key]);
|
||||
|
||||
if (key === "body") {
|
||||
// we can safely compact this
|
||||
node[key] = _.compact(node[key]);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
function traverseNode(node, opts, scope, state) {
|
||||
var keys = t.VISITOR_KEYS[node.type];
|
||||
if (!keys) return;
|
||||
|
||||
var context = new TraversalContext();
|
||||
for (var i = 0; i < keys.length; i++) {
|
||||
if (context.visit(node, keys[i], opts, scope, state)) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function traverse(parent, opts, scope, state) {
|
||||
if (!parent) return;
|
||||
|
||||
if (!scope) {
|
||||
if (parent.type !== "Program" && parent.type !== "File") {
|
||||
throw new Error("Must pass a scope unless traversing a Program/File got a " + parent.type + " node");
|
||||
}
|
||||
}
|
||||
|
||||
if (!opts) opts = {};
|
||||
if (!opts.enter) opts.enter = _.noop;
|
||||
if (!opts.exit) opts.exit = _.noop;
|
||||
|
||||
// array of nodes
|
||||
if (Array.isArray(parent)) {
|
||||
for (var i = 0; i < parent.length; i++) {
|
||||
traverseNode(parent[i], opts, scope, state);
|
||||
}
|
||||
} else {
|
||||
traverseNode(parent, opts, scope, state);
|
||||
}
|
||||
}
|
||||
|
||||
function clearNode(node) {
|
||||
node._declarations = null;
|
||||
node.extendedRange = null;
|
||||
node._scopeInfo = null;
|
||||
node.tokens = null;
|
||||
node.range = null;
|
||||
node.start = null;
|
||||
node.end = null;
|
||||
node.loc = null;
|
||||
node.raw = null;
|
||||
|
||||
if (Array.isArray(node.trailingComments)) {
|
||||
clearComments(node.trailingComments);
|
||||
}
|
||||
|
||||
if (Array.isArray(node.leadingComments)) {
|
||||
clearComments(node.leadingComments);
|
||||
}
|
||||
}
|
||||
|
||||
var clearVisitor = { enter: clearNode };
|
||||
|
||||
function clearComments(comments) {
|
||||
for (var i = 0; i < comments.length; i++) {
|
||||
clearNode(comments[i]);
|
||||
}
|
||||
}
|
||||
|
||||
traverse.removeProperties = function (tree) {
|
||||
clearNode(tree);
|
||||
traverse(tree, clearVisitor);
|
||||
|
||||
return tree;
|
||||
};
|
||||
|
||||
function hasBlacklistedType(node, parent, scope, context, state) {
|
||||
if (node.type === state.type) {
|
||||
state.has = true;
|
||||
context.skip();
|
||||
}
|
||||
}
|
||||
|
||||
traverse.hasType = function (tree, scope, type, blacklistTypes) {
|
||||
// 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;
|
||||
|
||||
var state = {
|
||||
has: false,
|
||||
type: type
|
||||
};
|
||||
|
||||
traverse(tree, {
|
||||
blacklist: blacklistTypes,
|
||||
enter: hasBlacklistedType
|
||||
}, scope, state);
|
||||
|
||||
return state.has;
|
||||
};
|
||||
@@ -1,411 +0,0 @@
|
||||
"use strict";
|
||||
|
||||
module.exports = Scope;
|
||||
|
||||
var traverse = require("./index");
|
||||
var object = require("../helpers/object");
|
||||
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 {Node} parentBlock
|
||||
* @param {Scope} [parent]
|
||||
* @param {File} [file]
|
||||
*/
|
||||
|
||||
function Scope(block, parentBlock, parent, file) {
|
||||
this.parent = parent;
|
||||
this.file = parent ? parent.file : file;
|
||||
|
||||
this.parentBlock = parentBlock;
|
||||
this.block = block;
|
||||
|
||||
var info = this.getInfo();
|
||||
this.references = info.references;
|
||||
this.declarations = info.declarations;
|
||||
this.declarationKinds = info.declarationKinds;
|
||||
}
|
||||
|
||||
Scope.defaultDeclarations = require("./global-keys");
|
||||
|
||||
Scope.prototype._add = function (node, references, throwOnDuplicate) {
|
||||
if (!node) return;
|
||||
|
||||
var ids = t.getIds(node, true);
|
||||
|
||||
for (var key in ids) {
|
||||
var id = ids[key];
|
||||
|
||||
if (throwOnDuplicate && references[key]) {
|
||||
throw this.file.errorWithNode(id, "Duplicate declaration", TypeError);
|
||||
}
|
||||
|
||||
references[key] = id;
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* 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 {String} name
|
||||
*/
|
||||
|
||||
Scope.prototype.generateUidIdentifier = function (name) {
|
||||
return this.file.generateUidIdentifier(name, this);
|
||||
};
|
||||
|
||||
/*
|
||||
* Description
|
||||
*
|
||||
* @param {Object} parent
|
||||
* @returns {Object}
|
||||
*/
|
||||
|
||||
Scope.prototype.generateUidBasedOnNode = function (parent) {
|
||||
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 this.file.generateUidIdentifier(id, this);
|
||||
};
|
||||
|
||||
/**
|
||||
* Description
|
||||
*
|
||||
* @param {Object} node
|
||||
* @returns {Object}
|
||||
*/
|
||||
|
||||
Scope.prototype.generateTempBasedOnNode = function (node) {
|
||||
if (t.isIdentifier(node) && this.has(node.name, true)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
var id = this.generateUidBasedOnNode(node);
|
||||
this.push({
|
||||
key: id.name,
|
||||
id: id
|
||||
});
|
||||
return id;
|
||||
};
|
||||
|
||||
var functionVariableVisitor = {
|
||||
enter: function (node, parent, scope, context, state) {
|
||||
if (t.isFor(node)) {
|
||||
_.each(FOR_KEYS, function (key) {
|
||||
var declar = node[key];
|
||||
if (t.isVar(declar)) state.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 context.skip();
|
||||
|
||||
// function identifier doesn't belong to this scope
|
||||
if (state.blockId && node === state.blockId) return;
|
||||
|
||||
// we've ran into a declaration!
|
||||
// we'll let the BlockStatement scope deal with `let` declarations unless
|
||||
if (t.isDeclaration(node) && !t.isBlockScoped(node)) {
|
||||
state.add(node);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
var programReferenceVisitor = {
|
||||
enter: function (node, parent, scope, context, add) {
|
||||
if (t.isReferencedIdentifier(node, parent) && !scope.has(node.name)) {
|
||||
add(node, true);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
var blockVariableVisitor = {
|
||||
enter: function (node, parent, scope, context, add) {
|
||||
if (t.isBlockScoped(node)) {
|
||||
add(node, false, t.isLet(node));
|
||||
} else if (t.isScope(node)) {
|
||||
context.skip();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
Scope.prototype.getInfo = function () {
|
||||
var parent = this.parent;
|
||||
var block = this.block;
|
||||
var self = this;
|
||||
if (block._scopeInfo) return block._scopeInfo;
|
||||
|
||||
var info = block._scopeInfo = {};
|
||||
var references = info.references = object();
|
||||
var declarations = info.declarations = object();
|
||||
var declarationKinds = info.declarationKinds = {};
|
||||
|
||||
var add = function (node, reference, throwOnDuplicate) {
|
||||
self._add(node, references);
|
||||
|
||||
if (!reference) {
|
||||
self._add(node, declarations, throwOnDuplicate);
|
||||
self._add(node, declarationKinds[node.kind] = declarationKinds[node.kind] || object());
|
||||
}
|
||||
};
|
||||
|
||||
if (parent && t.isBlockStatement(block) && t.isFor(parent.block, { body: block })) {
|
||||
// delegate block let declarations to the parent loop
|
||||
return info;
|
||||
}
|
||||
|
||||
// ForStatement - left, init
|
||||
|
||||
if (t.isFor(block)) {
|
||||
_.each(FOR_KEYS, function (key) {
|
||||
var node = block[key];
|
||||
if (t.isBlockScoped(node)) add(node, false, true);
|
||||
});
|
||||
|
||||
if (t.isBlockStatement(block.body)) {
|
||||
block = block.body;
|
||||
}
|
||||
}
|
||||
|
||||
// Program, BlockStatement - let variables
|
||||
|
||||
if (t.isBlockStatement(block) || t.isProgram(block)) {
|
||||
traverse(block, blockVariableVisitor, this, add);
|
||||
}
|
||||
|
||||
// CatchClause - param
|
||||
|
||||
if (t.isCatchClause(block)) {
|
||||
add(block.param);
|
||||
}
|
||||
|
||||
// ComprehensionExpression - blocks
|
||||
|
||||
if (t.isComprehensionExpression(block)) {
|
||||
add(block);
|
||||
}
|
||||
|
||||
// Program, Function - var variables
|
||||
|
||||
if (t.isProgram(block) || t.isFunction(block)) {
|
||||
traverse(block, functionVariableVisitor, this, {
|
||||
blockId: block.id,
|
||||
add: add
|
||||
});
|
||||
}
|
||||
|
||||
if (t.isFunctionExpression(block) && block.id) {
|
||||
if (!t.isProperty(this.parentBlock, { method: true })) {
|
||||
// SpiderMonkey AST doesn't use MethodDefinition here when it probably
|
||||
// should since they should be semantically the same?
|
||||
add(block.id);
|
||||
}
|
||||
}
|
||||
|
||||
// Program
|
||||
|
||||
if (t.isProgram(block)) {
|
||||
traverse(block, programReferenceVisitor, this, add);
|
||||
}
|
||||
|
||||
// Function - params, rest
|
||||
|
||||
if (t.isFunction(block)) {
|
||||
_.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);
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Walk up the scope tree until we hit a `Function` and then
|
||||
* push our `node` to it's references.
|
||||
*
|
||||
* @param {Object} node
|
||||
*/
|
||||
|
||||
Scope.prototype.add = function (node) {
|
||||
var scope = this.getFunctionParent();
|
||||
scope._add(node, scope.references);
|
||||
};
|
||||
|
||||
/**
|
||||
* Walk up the scope tree until we hit either a Function or reach the
|
||||
* very top at hit Program.
|
||||
*/
|
||||
|
||||
Scope.prototype.getFunctionParent = function () {
|
||||
var scope = this;
|
||||
while (scope.parent && !t.isFunction(scope.block)) {
|
||||
scope = scope.parent;
|
||||
}
|
||||
return scope;
|
||||
};
|
||||
|
||||
/**
|
||||
* Walks the scope tree and gathers all declarations of `kind`.
|
||||
*
|
||||
* @returns {Object}
|
||||
*/
|
||||
|
||||
Scope.prototype.getAllOfKind = function (kind) {
|
||||
var ids = object();
|
||||
|
||||
var scope = this;
|
||||
do {
|
||||
_.defaults(ids, scope.declarationKinds[kind]);
|
||||
scope = scope.parent;
|
||||
} while (scope);
|
||||
|
||||
return ids;
|
||||
};
|
||||
|
||||
/**
|
||||
* 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,71 +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"],
|
||||
"PrivateDeclaration": ["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"],
|
||||
"JSXElement": ["UserWhitespacable", "Expression"],
|
||||
|
||||
"ArrayExpression": ["Expression"],
|
||||
"AssignmentExpression": ["Expression"],
|
||||
"AwaitExpression": ["Expression"],
|
||||
"BindFunctionExpression": ["Expression"],
|
||||
"BindMemberExpression": ["Expression"],
|
||||
"CallExpression": ["Expression"],
|
||||
"ComprehensionExpression": ["Expression", "Scope"],
|
||||
"ConditionalExpression": ["Expression"],
|
||||
"Identifier": ["Expression"],
|
||||
"Literal": ["Expression"],
|
||||
"MemberExpression": ["Expression"],
|
||||
"NewExpression": ["Expression"],
|
||||
"ObjectExpression": ["Expression"],
|
||||
"SequenceExpression": ["Expression"],
|
||||
"TaggedTemplateExpression": ["Expression"],
|
||||
"ThisExpression": ["Expression"],
|
||||
"UpdateExpression": ["Expression"],
|
||||
"VirtualPropertyExpression": ["Expression"],
|
||||
"JSXEmptyExpression": ["Expression"],
|
||||
"JSXMemberExpression": ["Expression"],
|
||||
"YieldExpression": ["Expression"]
|
||||
}
|
||||
@@ -1,33 +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"],
|
||||
"FunctionDeclaration": ["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"],
|
||||
"MethodDefinition": ["key", "value", "computed", "kind"],
|
||||
"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,12 +0,0 @@
|
||||
"use strict";
|
||||
|
||||
module.exports = Node;
|
||||
|
||||
var acorn = require("acorn-6to5");
|
||||
|
||||
var oldNode = acorn.Node;
|
||||
acorn.Node = Node;
|
||||
|
||||
function Node() {
|
||||
oldNode.apply(this);
|
||||
}
|
||||
265
lib/6to5/util.js
265
lib/6to5/util.js
@@ -1,265 +0,0 @@
|
||||
"use strict";
|
||||
|
||||
require("./patch");
|
||||
|
||||
var estraverse = require("estraverse");
|
||||
var codeFrame = require("./helpers/code-frame");
|
||||
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 || exports.canCompile.EXTENSIONS;
|
||||
var ext = path.extname(filename);
|
||||
return _.contains(exts, ext);
|
||||
};
|
||||
|
||||
exports.canCompile.EXTENSIONS = [".js", ".jsx", ".es6", ".es"];
|
||||
|
||||
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 (Array.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 (Array.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);
|
||||
|
||||
if (!map.get && !map.set) {
|
||||
map.writable = t.literal(true);
|
||||
}
|
||||
|
||||
map.enumerable = t.literal(true);
|
||||
map.configurable = 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;
|
||||
};
|
||||
|
||||
var templateVisitor = {
|
||||
enter: function (node, parent, scope, context, nodes) {
|
||||
if (t.isIdentifier(node) && _.has(nodes, node.name)) {
|
||||
return nodes[node.name];
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
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, templateVisitor, null, nodes);
|
||||
}
|
||||
|
||||
var node = template.body[0];
|
||||
|
||||
if (!keepExpression && t.isExpressionStatement(node)) {
|
||||
return node.expression;
|
||||
} else {
|
||||
return node;
|
||||
}
|
||||
};
|
||||
|
||||
exports.repeat = function (width, cha) {
|
||||
cha = cha || " ";
|
||||
|
||||
var result = "";
|
||||
for (var i = 0; i < width; i++) {
|
||||
result += cha;
|
||||
}
|
||||
|
||||
return result;
|
||||
};
|
||||
|
||||
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: opts.allowImportExportEverywhere,
|
||||
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 = codeFrame(code, loc.line, loc.column + 1);
|
||||
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,8 +1,8 @@
|
||||
"use strict";
|
||||
|
||||
var transform = module.exports = require("./transformation/transform");
|
||||
var transform = module.exports = require("../transformation");
|
||||
|
||||
transform.version = require("../../package").version;
|
||||
transform.version = require("../../../package").version;
|
||||
|
||||
transform.transform = transform;
|
||||
|
||||
@@ -38,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 @@
|
||||
"use strict";
|
||||
|
||||
var transform = require("./transformation/transform");
|
||||
var util = require("./util");
|
||||
var fs = require("fs");
|
||||
var _ = require("lodash");
|
||||
var isFunction = require("lodash/lang/isFunction");
|
||||
var transform = require("../transformation");
|
||||
var util = require("../util");
|
||||
var fs = require("fs");
|
||||
|
||||
exports.version = require("../../package").version;
|
||||
exports.version = require("../../../package").version;
|
||||
|
||||
exports.types = require("./types");
|
||||
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");
|
||||
@@ -4,7 +4,7 @@ var path = require("path");
|
||||
var os = require("os");
|
||||
var fs = require("fs");
|
||||
|
||||
var FILENAME = path.join(os.tmpdir(), "6to5.json");
|
||||
var FILENAME = process.env.BABEL_CACHE_PATH || path.join(os.tmpdir(), "babel.json");
|
||||
var data = {};
|
||||
|
||||
exports.save = function () {
|
||||
@@ -12,13 +12,7 @@ exports.save = function () {
|
||||
};
|
||||
|
||||
exports.load = function () {
|
||||
if (!fs.existsSync(FILENAME)) return;
|
||||
|
||||
try {
|
||||
data = JSON.parse(fs.readFileSync(FILENAME));
|
||||
} catch (err) {
|
||||
return;
|
||||
}
|
||||
if (process.env.BABEL_DISABLE_CACHE) return;
|
||||
|
||||
process.on("exit", exports.save);
|
||||
|
||||
@@ -29,6 +23,14 @@ exports.load = function () {
|
||||
};
|
||||
|
||||
process.on("SIGINT", sigint);
|
||||
|
||||
if (!fs.existsSync(FILENAME)) return;
|
||||
|
||||
try {
|
||||
data = JSON.parse(fs.readFileSync(FILENAME));
|
||||
} catch (err) {
|
||||
return;
|
||||
}
|
||||
};
|
||||
|
||||
exports.get = function () {
|
||||
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");
|
||||
}
|
||||
};
|
||||
@@ -2,8 +2,11 @@
|
||||
|
||||
module.exports = Buffer;
|
||||
|
||||
var util = require("../util");
|
||||
var _ = require("lodash");
|
||||
var repeating = require("repeating");
|
||||
var trimRight = require("trim-right");
|
||||
var isBoolean = require("lodash/lang/isBoolean");
|
||||
var includes = require("lodash/collection/includes");
|
||||
var isNumber = require("lodash/lang/isNumber");
|
||||
|
||||
function Buffer(position, format) {
|
||||
this.position = position;
|
||||
@@ -13,14 +16,14 @@ function Buffer(position, format) {
|
||||
}
|
||||
|
||||
Buffer.prototype.get = function () {
|
||||
return util.trimRight(this.buf);
|
||||
return trimRight(this.buf);
|
||||
};
|
||||
|
||||
Buffer.prototype.getIndent = function () {
|
||||
if (this.format.compact) {
|
||||
if (this.format.compact || this.format.concise) {
|
||||
return "";
|
||||
} else {
|
||||
return util.repeat(this._indent, this.format.indent.style);
|
||||
return repeating(this.format.indent.style, this._indent);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -51,16 +54,18 @@ Buffer.prototype.rightBrace = function () {
|
||||
|
||||
Buffer.prototype.keyword = function (name) {
|
||||
this.push(name);
|
||||
this.push(" ");
|
||||
this.space();
|
||||
};
|
||||
|
||||
Buffer.prototype.space = function () {
|
||||
if (this.buf && !this.isLast([" ", "\n"])) {
|
||||
if (this.format.compact) return;
|
||||
if (this.buf && !this.isLast(" ") && !this.isLast("\n")) {
|
||||
this.push(" ");
|
||||
}
|
||||
};
|
||||
|
||||
Buffer.prototype.removeLast = function (cha) {
|
||||
if (this.format.compact) return;
|
||||
if (!this.isLast(cha)) return;
|
||||
|
||||
this.buf = this.buf.substr(0, this.buf.length - 1);
|
||||
@@ -68,24 +73,29 @@ Buffer.prototype.removeLast = function (cha) {
|
||||
};
|
||||
|
||||
Buffer.prototype.newline = function (i, removeLast) {
|
||||
if (this.format.compact) {
|
||||
if (this.format.compact) return;
|
||||
|
||||
if (this.format.concise) {
|
||||
this.space();
|
||||
return;
|
||||
}
|
||||
|
||||
removeLast = removeLast || false;
|
||||
|
||||
if (_.isNumber(i)) {
|
||||
if (this.endsWith("{\n")) i--;
|
||||
if (this.endsWith(util.repeat(i, "\n"))) return;
|
||||
if (isNumber(i)) {
|
||||
i = Math.min(2, i);
|
||||
|
||||
while (i--) {
|
||||
if (this.endsWith("{\n") || this.endsWith(":\n")) i--;
|
||||
if (i <= 0) return;
|
||||
|
||||
while (i > 0) {
|
||||
this._newline(removeLast);
|
||||
i--;
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (_.isBoolean(i)) {
|
||||
if (isBoolean(i)) {
|
||||
removeLast = i;
|
||||
}
|
||||
|
||||
@@ -93,11 +103,13 @@ Buffer.prototype.newline = function (i, removeLast) {
|
||||
};
|
||||
|
||||
Buffer.prototype._newline = function (removeLast) {
|
||||
// never allow more than two lines
|
||||
if (this.endsWith("\n\n")) return;
|
||||
|
||||
// remove the last newline
|
||||
if (removeLast && this.isLast("\n")) this.removeLast("\n");
|
||||
|
||||
this.removeLast(" ");
|
||||
|
||||
// remove whitespace if last character was a newline
|
||||
this._removeSpacesAfterLastNewline();
|
||||
this._push("\n");
|
||||
};
|
||||
@@ -105,6 +117,7 @@ Buffer.prototype._newline = function (removeLast) {
|
||||
/**
|
||||
* If buffer ends with a newline and some spaces after it, trim those spaces.
|
||||
*/
|
||||
|
||||
Buffer.prototype._removeSpacesAfterLastNewline = function () {
|
||||
var lastNewlineIndex = this.buf.lastIndexOf("\n");
|
||||
if (lastNewlineIndex === -1)
|
||||
@@ -125,7 +138,7 @@ Buffer.prototype._removeSpacesAfterLastNewline = function () {
|
||||
};
|
||||
|
||||
Buffer.prototype.push = function (str, noIndent) {
|
||||
if (this._indent && !noIndent && str !== "\n") {
|
||||
if (!this.format.compact && this._indent && !noIndent && str !== "\n") {
|
||||
// we have an indent level and we aren't pushing a newline
|
||||
var indent = this.getIndent();
|
||||
|
||||
@@ -133,7 +146,7 @@ Buffer.prototype.push = function (str, noIndent) {
|
||||
str = str.replace(/\n/g, "\n" + indent);
|
||||
|
||||
// we've got a newline before us so prepend on the indentation
|
||||
if (this.isLast("\n")) str = indent + str;
|
||||
if (this.isLast("\n")) this._push(indent);
|
||||
}
|
||||
|
||||
this._push(str);
|
||||
@@ -145,17 +158,17 @@ Buffer.prototype._push = function (str) {
|
||||
};
|
||||
|
||||
Buffer.prototype.endsWith = function (str) {
|
||||
var d = this.buf.length - str.length;
|
||||
return d >= 0 && this.buf.lastIndexOf(str) === d;
|
||||
return this.buf.slice(-str.length) === str;
|
||||
};
|
||||
|
||||
Buffer.prototype.isLast = function (cha, trimRight) {
|
||||
Buffer.prototype.isLast = function (cha) {
|
||||
if (this.format.compact) return false;
|
||||
|
||||
var buf = this.buf;
|
||||
if (trimRight) buf = util.trimRight(buf);
|
||||
var last = buf[buf.length - 1];
|
||||
|
||||
if (Array.isArray(cha)) {
|
||||
return _.contains(cha, last);
|
||||
return includes(cha, last);
|
||||
} else {
|
||||
return cha === last;
|
||||
}
|
||||
@@ -1,8 +1,8 @@
|
||||
"use strict";
|
||||
|
||||
var util = require("../../util");
|
||||
var t = require("../../types");
|
||||
var _ = require("lodash");
|
||||
var isInteger = require("is-integer");
|
||||
var isNumber = require("lodash/lang/isNumber");
|
||||
var t = require("../../types");
|
||||
|
||||
exports.UnaryExpression = function (node, print) {
|
||||
var hasSpace = /[a-z]$/.test(node.operator);
|
||||
@@ -17,7 +17,7 @@ exports.UnaryExpression = function (node, print) {
|
||||
}
|
||||
|
||||
this.push(node.operator);
|
||||
if (hasSpace) this.space();
|
||||
if (hasSpace) this.push(" ");
|
||||
print(node.argument);
|
||||
};
|
||||
|
||||
@@ -33,24 +33,26 @@ exports.UpdateExpression = function (node, print) {
|
||||
|
||||
exports.ConditionalExpression = function (node, print) {
|
||||
print(node.test);
|
||||
this.push(" ? ");
|
||||
this.space();
|
||||
this.push("?");
|
||||
this.space();
|
||||
print(node.consequent);
|
||||
this.push(" : ");
|
||||
this.space();
|
||||
this.push(":");
|
||||
this.space();
|
||||
print(node.alternate);
|
||||
};
|
||||
|
||||
exports.NewExpression = function (node, print) {
|
||||
this.push("new ");
|
||||
print(node.callee);
|
||||
if (node.arguments.length || this.format.parentheses) {
|
||||
this.push("(");
|
||||
print.join(node.arguments, { separator: ", " });
|
||||
this.push(")");
|
||||
}
|
||||
this.push("(");
|
||||
print.list(node.arguments);
|
||||
this.push(")");
|
||||
};
|
||||
|
||||
exports.SequenceExpression = function (node, print) {
|
||||
print.join(node.expressions, { separator: ", " });
|
||||
print.list(node.expressions);
|
||||
};
|
||||
|
||||
exports.ThisExpression = function () {
|
||||
@@ -72,9 +74,7 @@ exports.CallExpression = function (node, print) {
|
||||
separator += " ";
|
||||
}
|
||||
|
||||
print.join(node.arguments, {
|
||||
separator: separator
|
||||
});
|
||||
print.list(node.arguments, { separator: separator });
|
||||
|
||||
if (node._prettyCall) {
|
||||
this.newline();
|
||||
@@ -87,7 +87,11 @@ exports.CallExpression = function (node, print) {
|
||||
var buildYieldAwait = function (keyword) {
|
||||
return function (node, print) {
|
||||
this.push(keyword);
|
||||
if (node.delegate) this.push("*");
|
||||
|
||||
if (node.delegate || node.all) {
|
||||
this.push("*");
|
||||
}
|
||||
|
||||
if (node.argument) {
|
||||
this.space();
|
||||
print(node.argument);
|
||||
@@ -111,10 +115,11 @@ exports.BinaryExpression =
|
||||
exports.LogicalExpression =
|
||||
exports.AssignmentPattern =
|
||||
exports.AssignmentExpression = function (node, print) {
|
||||
// todo: add cases where the spaces can be dropped when in compact mode
|
||||
print(node.left);
|
||||
this.space();
|
||||
this.push(" ");
|
||||
this.push(node.operator);
|
||||
this.space();
|
||||
this.push(" ");
|
||||
print(node.right);
|
||||
};
|
||||
|
||||
@@ -129,7 +134,7 @@ exports.MemberExpression = function (node, print) {
|
||||
}
|
||||
|
||||
var computed = node.computed;
|
||||
if (t.isLiteral(node.property) && _.isNumber(node.property.value)) {
|
||||
if (t.isLiteral(node.property) && isNumber(node.property.value)) {
|
||||
computed = true;
|
||||
}
|
||||
|
||||
@@ -139,7 +144,7 @@ exports.MemberExpression = function (node, print) {
|
||||
this.push("]");
|
||||
} else {
|
||||
// 5..toFixed(2);
|
||||
if (t.isLiteral(obj) && util.isInteger(obj.value) && !SCIENTIFIC_NOTATION.test(obj.value.toString())) {
|
||||
if (t.isLiteral(obj) && isInteger(obj.value) && !SCIENTIFIC_NOTATION.test(obj.value.toString())) {
|
||||
this.push(".");
|
||||
}
|
||||
|
||||
@@ -30,6 +30,7 @@ exports.ObjectTypeIndexer =
|
||||
exports.ObjectTypeProperty =
|
||||
exports.QualifiedTypeIdentifier =
|
||||
exports.UnionTypeAnnotation =
|
||||
exports.TypeCastExpression =
|
||||
exports.VoidTypeAnnotation = function () {
|
||||
// todo: implement these once we have a `--keep-types` option
|
||||
};
|
||||
@@ -1,7 +1,7 @@
|
||||
"use strict";
|
||||
|
||||
var t = require("../../types");
|
||||
var _ = require("lodash");
|
||||
var t = require("../../types");
|
||||
var each = require("lodash/collection/each");
|
||||
|
||||
exports.JSXAttribute = function (node, print) {
|
||||
print(node.name);
|
||||
@@ -47,7 +47,7 @@ exports.JSXElement = function (node, print) {
|
||||
if (open.selfClosing) return;
|
||||
|
||||
this.indent();
|
||||
_.each(node.children, function (child) {
|
||||
each(node.children, function (child) {
|
||||
if (t.isLiteral(child)) {
|
||||
self.push(child.value);
|
||||
} else {
|
||||
@@ -75,6 +75,4 @@ exports.JSXClosingElement = function (node, print) {
|
||||
this.push(">");
|
||||
};
|
||||
|
||||
exports.JSXEmptyExpression = function () {
|
||||
|
||||
};
|
||||
exports.JSXEmptyExpression = function () {};
|
||||
@@ -4,11 +4,7 @@ var t = require("../../types");
|
||||
|
||||
exports._params = function (node, print) {
|
||||
this.push("(");
|
||||
|
||||
print.join(node.params, {
|
||||
separator: ", "
|
||||
});
|
||||
|
||||
print.list(node.params);
|
||||
this.push(")");
|
||||
};
|
||||
|
||||
@@ -45,11 +41,14 @@ exports.FunctionExpression = function (node, print) {
|
||||
if (node.async) this.push("async ");
|
||||
this.push("function");
|
||||
if (node.generator) this.push("*");
|
||||
this.push(" ");
|
||||
|
||||
if (node.id) {
|
||||
this.space();
|
||||
this.push(" ");
|
||||
print(node.id);
|
||||
} else {
|
||||
this.space();
|
||||
}
|
||||
|
||||
this._params(node, print);
|
||||
this.space();
|
||||
print(node.body);
|
||||
@@ -1,7 +1,7 @@
|
||||
"use strict";
|
||||
|
||||
var t = require("../../types");
|
||||
var _ = require("lodash");
|
||||
var t = require("../../types");
|
||||
var each = require("lodash/collection/each");
|
||||
|
||||
exports.ImportSpecifier = function (node, print) {
|
||||
if (t.isSpecifierDefault(node)) {
|
||||
@@ -62,11 +62,15 @@ exports.ImportDeclaration = function (node, print) {
|
||||
|
||||
this.push("import ");
|
||||
|
||||
if (node.isType) {
|
||||
this.push("type ");
|
||||
}
|
||||
|
||||
var specfiers = node.specifiers;
|
||||
if (specfiers && specfiers.length) {
|
||||
var foundImportSpecifier = false;
|
||||
|
||||
_.each(node.specifiers, function (spec, i) {
|
||||
each(node.specifiers, function (spec, i) {
|
||||
if (+i > 0) {
|
||||
self.push(", ");
|
||||
}
|
||||
@@ -1,8 +1,8 @@
|
||||
"use strict";
|
||||
|
||||
var _ = require("lodash");
|
||||
var each = require("lodash/collection/each");
|
||||
|
||||
_.each(["BindMemberExpression", "BindFunctionExpression"], function (type) {
|
||||
each(["BindMemberExpression", "BindFunctionExpression"], function (type) {
|
||||
exports[type] = function () {
|
||||
throw new ReferenceError("Trying to render non-standard playground node " + JSON.stringify(type));
|
||||
};
|
||||
@@ -1,7 +1,7 @@
|
||||
"use strict";
|
||||
|
||||
var util = require("../../util");
|
||||
var t = require("../../types");
|
||||
var repeating = require("repeating");
|
||||
var t = require("../../types");
|
||||
|
||||
exports.WithStatement = function (node, print) {
|
||||
this.keyword("with");
|
||||
@@ -21,8 +21,8 @@ exports.IfStatement = function (node, print) {
|
||||
print.indentOnComments(node.consequent);
|
||||
|
||||
if (node.alternate) {
|
||||
if (this.isLast("}")) this.push(" ");
|
||||
this.keyword("else");
|
||||
if (this.isLast("}")) this.space();
|
||||
this.push("else ");
|
||||
print.indentOnComments(node.alternate);
|
||||
}
|
||||
};
|
||||
@@ -148,7 +148,14 @@ exports.SwitchStatement = function (node, print) {
|
||||
this.push(")");
|
||||
this.space();
|
||||
this.push("{");
|
||||
print.sequence(node.cases, { indent: true });
|
||||
|
||||
print.sequence(node.cases, {
|
||||
indent: true,
|
||||
addNewlines: function (leading, cas) {
|
||||
if (!leading && node.cases[node.cases.length - 1] === cas) return -1;
|
||||
}
|
||||
});
|
||||
|
||||
this.push("}");
|
||||
};
|
||||
|
||||
@@ -161,8 +168,10 @@ exports.SwitchCase = function (node, print) {
|
||||
this.push("default:");
|
||||
}
|
||||
|
||||
this.newline();
|
||||
print.sequence(node.consequent, { indent: true });
|
||||
if (node.consequent.length) {
|
||||
this.newline();
|
||||
print.sequence(node.consequent, { indent: true });
|
||||
}
|
||||
};
|
||||
|
||||
exports.DebuggerStatement = function () {
|
||||
@@ -184,13 +193,13 @@ exports.VariableDeclaration = function (node, print, parent) {
|
||||
}
|
||||
|
||||
var sep = ",";
|
||||
if (hasInits) {
|
||||
sep += "\n" + util.repeat(node.kind.length + 1);
|
||||
if (!this.format.compact && hasInits) {
|
||||
sep += "\n" + repeating(" ", node.kind.length + 1);
|
||||
} else {
|
||||
sep += " ";
|
||||
}
|
||||
|
||||
print.join(node.declarations, { separator: sep });
|
||||
print.list(node.declarations, { separator: sep });
|
||||
|
||||
if (!t.isFor(parent)) {
|
||||
this.semicolon();
|
||||
@@ -1,6 +1,6 @@
|
||||
"use strict";
|
||||
|
||||
var _ = require("lodash");
|
||||
var each = require("lodash/collection/each");
|
||||
|
||||
exports.TaggedTemplateExpression = function (node, print) {
|
||||
print(node.tag);
|
||||
@@ -18,7 +18,7 @@ exports.TemplateLiteral = function (node, print) {
|
||||
var self = this;
|
||||
var len = quasis.length;
|
||||
|
||||
_.each(quasis, function (quasi, i) {
|
||||
each(quasis, function (quasi, i) {
|
||||
print(quasi);
|
||||
|
||||
if (i + 1 < len) {
|
||||
@@ -1,6 +1,6 @@
|
||||
"use strict";
|
||||
|
||||
var _ = require("lodash");
|
||||
var each = require("lodash/collection/each");
|
||||
|
||||
exports.Identifier = function (node) {
|
||||
this.push(node.name);
|
||||
@@ -27,7 +27,7 @@ exports.ObjectPattern = function (node, print) {
|
||||
this.push("{");
|
||||
this.space();
|
||||
|
||||
print.join(props, { separator: ", ", indent: true });
|
||||
print.list(props, { indent: true });
|
||||
|
||||
this.space();
|
||||
this.push("}");
|
||||
@@ -49,7 +49,8 @@ exports.Property = function (node, print) {
|
||||
if (node.shorthand) return;
|
||||
}
|
||||
|
||||
this.push(": ");
|
||||
this.push(":");
|
||||
this.space();
|
||||
print(node.value);
|
||||
}
|
||||
};
|
||||
@@ -62,7 +63,7 @@ exports.ArrayPattern = function (node, print) {
|
||||
|
||||
this.push("[");
|
||||
|
||||
_.each(elems, function (elem, i) {
|
||||
each(elems, function (elem, i) {
|
||||
if (!elem) {
|
||||
// If the array expression ends with a hole, that hole
|
||||
// will be ignored by the interpreter, but if it ends with
|
||||
@@ -93,8 +94,10 @@ exports.Literal = function (node) {
|
||||
});
|
||||
|
||||
this.push(val);
|
||||
} else if (type === "boolean" || type === "number") {
|
||||
this.push(JSON.stringify(val));
|
||||
} else if (type === "number") {
|
||||
this.push(val + "");
|
||||
} else if (type === "boolean") {
|
||||
this.push(val ? "true" : "false");
|
||||
} else if (node.regex) {
|
||||
this.push("/" + node.regex.pattern + "/" + node.regex.flags);
|
||||
} else if (val === null) {
|
||||
@@ -9,49 +9,63 @@ module.exports.CodeGenerator = CodeGenerator;
|
||||
|
||||
var detectIndent = require("detect-indent");
|
||||
var Whitespace = require("./whitespace");
|
||||
var repeating = require("repeating");
|
||||
var SourceMap = require("./source-map");
|
||||
var Position = require("./position");
|
||||
var messages = require("../messages");
|
||||
var Buffer = require("./buffer");
|
||||
var util = require("../util");
|
||||
var extend = require("lodash/object/extend");
|
||||
var each = require("lodash/collection/each");
|
||||
var n = require("./node");
|
||||
var t = require("../types");
|
||||
var _ = require("lodash");
|
||||
|
||||
function CodeGenerator(ast, opts, code) {
|
||||
opts = opts || {};
|
||||
|
||||
this.comments = ast.comments || [];
|
||||
this.tokens = ast.tokens || [];
|
||||
this.format = CodeGenerator.normaliseOptions(code, opts);
|
||||
this.format = CodeGenerator.normalizeOptions(code, opts);
|
||||
this.opts = opts;
|
||||
this.ast = ast;
|
||||
|
||||
this.whitespace = new Whitespace(this.tokens, this.comments);
|
||||
this.whitespace = new Whitespace(this.tokens, this.comments, this.format);
|
||||
this.position = new Position;
|
||||
this.map = new SourceMap(this.position, opts, code);
|
||||
this.buffer = new Buffer(this.position, this.format);
|
||||
}
|
||||
|
||||
_.each(Buffer.prototype, function (fn, key) {
|
||||
each(Buffer.prototype, function (fn, key) {
|
||||
CodeGenerator.prototype[key] = function () {
|
||||
return fn.apply(this.buffer, arguments);
|
||||
};
|
||||
});
|
||||
|
||||
CodeGenerator.normaliseOptions = function (code, opts) {
|
||||
var indent = detectIndent(code);
|
||||
var style = indent.indent;
|
||||
if (!style || style === " ") style = " ";
|
||||
CodeGenerator.normalizeOptions = function (code, opts) {
|
||||
var style = " ";
|
||||
if (code) {
|
||||
var indent = detectIndent(code).indent;
|
||||
if (indent && indent !== " ") style = indent;
|
||||
}
|
||||
|
||||
return _.merge({
|
||||
parentheses: true,
|
||||
var format = {
|
||||
comments: opts.comments == null || opts.comments,
|
||||
compact: false,
|
||||
compact: opts.compact,
|
||||
indent: {
|
||||
adjustMultilineComment: true,
|
||||
style: style,
|
||||
base: 0
|
||||
}
|
||||
}, opts.format || {});
|
||||
};
|
||||
|
||||
if (format.compact === "auto") {
|
||||
format.compact = code.length > 100000; // 100KB
|
||||
|
||||
if (format.compact) {
|
||||
console.error(messages.get("codeGeneratorDeopt", opts.filename, "100KB"));
|
||||
}
|
||||
}
|
||||
|
||||
return format;
|
||||
};
|
||||
|
||||
CodeGenerator.generators = {
|
||||
@@ -69,8 +83,8 @@ CodeGenerator.generators = {
|
||||
jsx: require("./generators/jsx")
|
||||
};
|
||||
|
||||
_.each(CodeGenerator.generators, function (generator) {
|
||||
_.extend(CodeGenerator.prototype, generator);
|
||||
each(CodeGenerator.generators, function (generator) {
|
||||
extend(CodeGenerator.prototype, generator);
|
||||
});
|
||||
|
||||
CodeGenerator.prototype.generate = function () {
|
||||
@@ -79,7 +93,7 @@ CodeGenerator.prototype.generate = function () {
|
||||
this.print(ast);
|
||||
|
||||
var comments = [];
|
||||
_.each(ast.comments, function (comment) {
|
||||
each(ast.comments, function (comment) {
|
||||
if (!comment._displayed) comments.push(comment);
|
||||
});
|
||||
this._printComments(comments);
|
||||
@@ -107,6 +121,12 @@ CodeGenerator.prototype.buildPrint = function (parent) {
|
||||
return self.printJoin(print, nodes, opts);
|
||||
};
|
||||
|
||||
print.list = function (items, opts) {
|
||||
opts = opts || {};
|
||||
opts.separator = opts.separator || ", ";
|
||||
print.join(items, opts);
|
||||
};
|
||||
|
||||
print.block = function (node) {
|
||||
return self.printBlock(print, node);
|
||||
};
|
||||
@@ -125,9 +145,9 @@ CodeGenerator.prototype.print = function (node, parent, opts) {
|
||||
node._compact = true;
|
||||
}
|
||||
|
||||
var oldCompact = this.format.compact;
|
||||
var oldConcise = this.format.concise;
|
||||
if (node._compact) {
|
||||
this.format.compact = true;
|
||||
this.format.concise = true;
|
||||
}
|
||||
|
||||
var self = this;
|
||||
@@ -151,13 +171,14 @@ CodeGenerator.prototype.print = function (node, parent, opts) {
|
||||
} else {
|
||||
// generated node
|
||||
if (!leading) lines++; // always include at least a single line after
|
||||
if (opts.addNewlines) lines += opts.addNewlines(leading, node) || 0;
|
||||
|
||||
var needs = n.needsWhitespaceAfter;
|
||||
if (leading) needs = n.needsWhitespaceBefore;
|
||||
lines += needs(node, parent);
|
||||
if (needs(node, parent)) lines++;
|
||||
|
||||
// generated nodes can't add starting file whitespace
|
||||
if (!self.buffer.get()) lines = 0;
|
||||
if (!self.buffer.buf) lines = 0;
|
||||
}
|
||||
|
||||
self.newline(lines);
|
||||
@@ -195,7 +216,7 @@ CodeGenerator.prototype.print = function (node, parent, opts) {
|
||||
throw new ReferenceError("unknown node of type " + JSON.stringify(node.type) + " with constructor " + JSON.stringify(node && node.constructor.name));
|
||||
}
|
||||
|
||||
this.format.compact = oldCompact;
|
||||
this.format.concise = oldConcise;
|
||||
};
|
||||
|
||||
CodeGenerator.prototype.printJoin = function (print, nodes, opts) {
|
||||
@@ -208,9 +229,10 @@ CodeGenerator.prototype.printJoin = function (print, nodes, opts) {
|
||||
|
||||
if (opts.indent) self.indent();
|
||||
|
||||
_.each(nodes, function (node, i) {
|
||||
each(nodes, function (node, i) {
|
||||
print(node, {
|
||||
statement: opts.statement,
|
||||
addNewlines: opts.addNewlines,
|
||||
after: function () {
|
||||
if (opts.iterator) {
|
||||
opts.iterator(node, i);
|
||||
@@ -273,7 +295,7 @@ CodeGenerator.prototype.getComments = function (key, node, parent) {
|
||||
nodes.push(node.argument);
|
||||
}
|
||||
|
||||
_.each(nodes, function (node) {
|
||||
each(nodes, function (node) {
|
||||
comments = comments.concat(self._getComments(key, node));
|
||||
});
|
||||
|
||||
@@ -286,16 +308,17 @@ CodeGenerator.prototype._getComments = function (key, node) {
|
||||
|
||||
CodeGenerator.prototype._printComments = function (comments) {
|
||||
if (this.format.compact) return;
|
||||
|
||||
if (!this.format.comments) return;
|
||||
if (!comments || !comments.length) return;
|
||||
|
||||
var self = this;
|
||||
|
||||
_.each(comments, function (comment) {
|
||||
each(comments, function (comment) {
|
||||
var skip = false;
|
||||
|
||||
// find the original comment in the ast and set it as displayed
|
||||
_.each(self.ast.comments, function (origComment) {
|
||||
each(self.ast.comments, function (origComment) {
|
||||
if (origComment.start === comment.start) {
|
||||
// comment has already been output
|
||||
if (origComment._displayed) skip = true;
|
||||
@@ -328,7 +351,7 @@ CodeGenerator.prototype._printComments = function (comments) {
|
||||
}
|
||||
|
||||
var indent = Math.max(self.indentSize(), column);
|
||||
val = val.replace(/\n/g, "\n" + util.repeat(indent));
|
||||
val = val.replace(/\n/g, "\n" + repeating(" ", indent));
|
||||
}
|
||||
|
||||
if (column === 0) {
|
||||
@@ -4,8 +4,9 @@ module.exports = Node;
|
||||
|
||||
var whitespace = require("./whitespace");
|
||||
var parens = require("./parentheses");
|
||||
var each = require("lodash/collection/each");
|
||||
var some = require("lodash/collection/some");
|
||||
var t = require("../../types");
|
||||
var _ = require("lodash");
|
||||
|
||||
var find = function (obj, node, parent) {
|
||||
if (!obj) return;
|
||||
@@ -41,14 +42,19 @@ Node.needsWhitespace = function (node, parent, type) {
|
||||
node = node.expression;
|
||||
}
|
||||
|
||||
var lines = find(whitespace[type].nodes, node, parent);
|
||||
if (lines) return lines;
|
||||
var linesInfo = find(whitespace.nodes, node, parent);
|
||||
|
||||
_.each(find(whitespace[type].list, node, parent), function (expr) {
|
||||
lines = Node.needsWhitespace(expr, node, type);
|
||||
if (lines) return false;
|
||||
});
|
||||
return lines || 0;
|
||||
if (!linesInfo) {
|
||||
var items = find(whitespace.list, node, parent);
|
||||
if (items) {
|
||||
for (var i = 0; i < items.length; i++) {
|
||||
linesInfo = Node.needsWhitespace(items[i], node, type);
|
||||
if (linesInfo) break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return (linesInfo && linesInfo[type]) || 0;
|
||||
};
|
||||
|
||||
Node.needsWhitespaceBefore = function (node, parent) {
|
||||
@@ -65,7 +71,7 @@ Node.needsParens = function (node, parent) {
|
||||
if (t.isNewExpression(parent) && parent.callee === node) {
|
||||
if (t.isCallExpression(node)) return true;
|
||||
|
||||
var hasCall = _.some(node, function (val) {
|
||||
var hasCall = some(node, function (val) {
|
||||
return t.isCallExpression(val);
|
||||
});
|
||||
if (hasCall) return true;
|
||||
@@ -94,7 +100,7 @@ Node.needsParensNoLineTerminator = function (node, parent) {
|
||||
return false;
|
||||
};
|
||||
|
||||
_.each(Node, function (fn, key) {
|
||||
each(Node, function (fn, key) {
|
||||
Node.prototype[key] = function () {
|
||||
// Avoid leaking arguments to prevent deoptimization
|
||||
var args = new Array(arguments.length + 2);
|
||||
@@ -1,11 +1,11 @@
|
||||
"use strict";
|
||||
|
||||
var t = require("../../types");
|
||||
var _ = require("lodash");
|
||||
var t = require("../../types");
|
||||
var each = require("lodash/collection/each");
|
||||
|
||||
var PRECEDENCE = {};
|
||||
|
||||
_.each([
|
||||
each([
|
||||
["||"],
|
||||
["&&"],
|
||||
["|"],
|
||||
@@ -18,7 +18,7 @@ _.each([
|
||||
["*", "/", "%"],
|
||||
["**"]
|
||||
], function (tier, i) {
|
||||
_.each(tier, function (op) {
|
||||
each(tier, function (op) {
|
||||
PRECEDENCE[op] = i;
|
||||
});
|
||||
});
|
||||
159
lib/babel/generation/node/whitespace.js
Normal file
159
lib/babel/generation/node/whitespace.js
Normal file
@@ -0,0 +1,159 @@
|
||||
"use strict";
|
||||
|
||||
var isBoolean = require("lodash/lang/isBoolean");
|
||||
var each = require("lodash/collection/each");
|
||||
var map = require("lodash/collection/map");
|
||||
var t = require("../../types");
|
||||
|
||||
var crawl = function (node, state) {
|
||||
state = state || {};
|
||||
|
||||
if (t.isMemberExpression(node)) {
|
||||
crawl(node.object, state);
|
||||
if (node.computed) crawl(node.property, state);
|
||||
} else if (t.isBinary(node) || t.isAssignmentExpression(node)) {
|
||||
crawl(node.left, state);
|
||||
crawl(node.right, state);
|
||||
} else if (t.isCallExpression(node)) {
|
||||
state.hasCall = true;
|
||||
crawl(node.callee, state);
|
||||
} else if (t.isFunction(node)) {
|
||||
state.hasFunction = true;
|
||||
} else if (t.isIdentifier(node)) {
|
||||
state.hasHelper = state.hasHelper || isHelper(node.callee);
|
||||
}
|
||||
|
||||
return state;
|
||||
};
|
||||
|
||||
var isHelper = function (node) {
|
||||
if (t.isMemberExpression(node)) {
|
||||
return isHelper(node.object) || isHelper(node.property);
|
||||
} else if (t.isIdentifier(node)) {
|
||||
return node.name === "require" || node.name[0] === "_";
|
||||
} else if (t.isCallExpression(node)) {
|
||||
return isHelper(node.callee);
|
||||
} else if (t.isBinary(node) || t.isAssignmentExpression(node)) {
|
||||
return (t.isIdentifier(node.left) && isHelper(node.left)) || isHelper(node.right);
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
var isType = function (node) {
|
||||
return t.isLiteral(node) || t.isObjectExpression(node) || t.isArrayExpression(node) ||
|
||||
t.isIdentifier(node) || t.isMemberExpression(node);
|
||||
};
|
||||
|
||||
exports.nodes = {
|
||||
AssignmentExpression: function (node) {
|
||||
var state = crawl(node.right);
|
||||
if ((state.hasCall && state.hasHelper) || state.hasFunction) {
|
||||
return {
|
||||
before: state.hasFunction,
|
||||
after: true
|
||||
};
|
||||
}
|
||||
},
|
||||
|
||||
SwitchCase: function (node, parent) {
|
||||
return {
|
||||
before: node.consequent.length || parent.cases[0] === node
|
||||
};
|
||||
},
|
||||
|
||||
LogicalExpression: function (node) {
|
||||
if (t.isFunction(node.left) || t.isFunction(node.right)) {
|
||||
return {
|
||||
after: true
|
||||
};
|
||||
}
|
||||
},
|
||||
|
||||
Literal: function (node) {
|
||||
if (node.value === "use strict") {
|
||||
return {
|
||||
after: true
|
||||
};
|
||||
}
|
||||
},
|
||||
|
||||
CallExpression: function (node) {
|
||||
if (t.isFunction(node.callee) || isHelper(node)) {
|
||||
return {
|
||||
before: true,
|
||||
after: true
|
||||
};
|
||||
}
|
||||
},
|
||||
|
||||
VariableDeclaration: function (node) {
|
||||
for (var i = 0; i < node.declarations.length; i++) {
|
||||
var declar = node.declarations[i];
|
||||
|
||||
var enabled = isHelper(declar.id) && !isType(declar.init);
|
||||
if (!enabled) {
|
||||
var state = crawl(declar.init);
|
||||
enabled = (isHelper(declar.init) && state.hasCall) || state.hasFunction;
|
||||
}
|
||||
|
||||
if (enabled) {
|
||||
return {
|
||||
before: true,
|
||||
after: true
|
||||
};
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
IfStatement: function (node) {
|
||||
if (t.isBlockStatement(node.consequent)) {
|
||||
return {
|
||||
before: true,
|
||||
after: true
|
||||
};
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
exports.nodes.Property =
|
||||
exports.nodes.SpreadProperty = function (node, parent) {
|
||||
if (parent.properties[0] === node) {
|
||||
return {
|
||||
before: true
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
exports.list = {
|
||||
VariableDeclaration: function (node) {
|
||||
return map(node.declarations, "init");
|
||||
},
|
||||
|
||||
ArrayExpression: function (node) {
|
||||
return node.elements;
|
||||
},
|
||||
|
||||
ObjectExpression: function (node) {
|
||||
return node.properties;
|
||||
}
|
||||
};
|
||||
|
||||
each({
|
||||
Function: true,
|
||||
Class: true,
|
||||
Loop: true,
|
||||
LabeledStatement: true,
|
||||
SwitchStatement: true,
|
||||
TryStatement: true
|
||||
}, function (amounts, type) {
|
||||
if (isBoolean(amounts)) {
|
||||
amounts = { after: amounts, before: amounts };
|
||||
}
|
||||
|
||||
each([type].concat(t.FLIPPED_ALIAS_KEYS[type] || []), function (type) {
|
||||
exports.nodes[type] = function () {
|
||||
return amounts;
|
||||
};
|
||||
});
|
||||
});
|
||||
@@ -48,8 +48,6 @@ SourceMap.prototype.mark = function (node, type) {
|
||||
|
||||
var original = loc[type];
|
||||
|
||||
if (generated.line === original.line && generated.column === original.column) return; // nothing to map
|
||||
|
||||
map.addMapping({
|
||||
source: this.opts.sourceFileName,
|
||||
generated: generated,
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
module.exports = Whitespace;
|
||||
|
||||
var _ = require("lodash");
|
||||
var sortBy = require("lodash/collection/sortBy");
|
||||
|
||||
/**
|
||||
* Returns `i`th number from `base`, continuing from 0 when `max` is reached.
|
||||
@@ -13,17 +13,19 @@ var _ = require("lodash");
|
||||
* @param {Number} max Array length
|
||||
* @returns {Number} shiftedIndex
|
||||
*/
|
||||
|
||||
function getLookupIndex(i, base, max) {
|
||||
i += base;
|
||||
|
||||
if (i >= max)
|
||||
if (i >= max) {
|
||||
i -= max;
|
||||
}
|
||||
|
||||
return i;
|
||||
}
|
||||
|
||||
function Whitespace(tokens, comments) {
|
||||
this.tokens = _.sortBy(tokens.concat(comments), "start");
|
||||
this.tokens = sortBy(tokens.concat(comments), "start");
|
||||
this.used = {};
|
||||
|
||||
// Profiling this code shows that while generator passes over it, indexes
|
||||
@@ -82,7 +84,7 @@ Whitespace.prototype.getNewlinesAfter = function (node) {
|
||||
}
|
||||
}
|
||||
|
||||
if (endToken.type.type === "eof") {
|
||||
if (endToken && endToken.type.type === "eof") {
|
||||
return 1;
|
||||
} else {
|
||||
var lines = this.getNewlinesBetween(startToken, endToken);
|
||||
@@ -96,6 +98,8 @@ Whitespace.prototype.getNewlinesAfter = function (node) {
|
||||
};
|
||||
|
||||
Whitespace.prototype.getNewlinesBetween = function (startToken, endToken) {
|
||||
if (!endToken || !endToken.loc) return 0;
|
||||
|
||||
var start = startToken ? startToken.loc.end.line : 1;
|
||||
var end = endToken.loc.start.line;
|
||||
var lines = 0;
|
||||
@@ -1,9 +1,8 @@
|
||||
// syntax highlighting based on https://github.com/dominictarr/ansi-highlight by the fantastic Dominic Tarr
|
||||
|
||||
var supportsColor = require("supports-color");
|
||||
var tokenize = require("js-tokenizer");
|
||||
var chalk = require("chalk");
|
||||
var util = require("../util");
|
||||
var repeating = require("repeating");
|
||||
var tokenize = require("js-tokenizer");
|
||||
var chalk = require("chalk");
|
||||
|
||||
var defs = {
|
||||
string1: "red",
|
||||
@@ -43,11 +42,11 @@ var highlight = function (text) {
|
||||
module.exports = function (lines, lineNumber, colNumber) {
|
||||
colNumber = Math.max(colNumber, 0);
|
||||
|
||||
if (supportsColor) {
|
||||
if (chalk.supportsColor) {
|
||||
lines = highlight(lines);
|
||||
}
|
||||
|
||||
lines = lines.split("\n");
|
||||
lines = lines.split(/\r\n|[\n\r\u2028\u2029]/);
|
||||
|
||||
var start = Math.max(lineNumber - 3, 0);
|
||||
var end = Math.min(lines.length, lineNumber + 3);
|
||||
@@ -63,15 +62,15 @@ module.exports = function (lines, lineNumber, colNumber) {
|
||||
|
||||
var gutter = curr === lineNumber ? "> " : " ";
|
||||
|
||||
var sep = curr + util.repeat(width + 1);
|
||||
var sep = curr + repeating(" ", width + 1);
|
||||
gutter += sep + "| ";
|
||||
|
||||
var str = gutter + line;
|
||||
|
||||
if (colNumber && curr === lineNumber) {
|
||||
str += "\n";
|
||||
str += util.repeat(gutter.length - 2);
|
||||
str += "|" + util.repeat(colNumber) + "^";
|
||||
str += repeating(" ", gutter.length - 2);
|
||||
str += "|" + repeating(" ", colNumber) + "^";
|
||||
}
|
||||
|
||||
return str;
|
||||
9
lib/babel/helpers/normalize-ast.js
Normal file
9
lib/babel/helpers/normalize-ast.js
Normal file
@@ -0,0 +1,9 @@
|
||||
var t = require("../types");
|
||||
|
||||
module.exports = function (ast, comments, tokens) {
|
||||
if (ast && ast.type === "Program") {
|
||||
return t.file(ast, comments || [], tokens || []);
|
||||
} else {
|
||||
throw new Error("Not a valid ast?");
|
||||
}
|
||||
};
|
||||
49
lib/babel/helpers/parse.js
Normal file
49
lib/babel/helpers/parse.js
Normal file
@@ -0,0 +1,49 @@
|
||||
var normalizeAst = require("./normalize-ast");
|
||||
var estraverse = require("estraverse");
|
||||
var codeFrame = require("./code-frame");
|
||||
var acorn = require("acorn-babel");
|
||||
|
||||
module.exports = function (opts, code, callback) {
|
||||
try {
|
||||
var comments = [];
|
||||
var tokens = [];
|
||||
|
||||
var ast = acorn.parse(code, {
|
||||
allowImportExportEverywhere: opts.allowImportExportEverywhere,
|
||||
allowReturnOutsideFunction: !opts._anal,
|
||||
ecmaVersion: opts.experimental ? 7 : 6,
|
||||
playground: opts.playground,
|
||||
strictMode: opts.strictMode,
|
||||
onComment: comments,
|
||||
locations: true,
|
||||
onToken: tokens,
|
||||
ranges: true
|
||||
});
|
||||
|
||||
estraverse.attachComments(ast, comments, tokens);
|
||||
|
||||
ast = normalizeAst(ast, comments, tokens);
|
||||
|
||||
if (callback) {
|
||||
return callback(ast);
|
||||
} else {
|
||||
return ast;
|
||||
}
|
||||
} catch (err) {
|
||||
if (!err._babel) {
|
||||
err._babel = true;
|
||||
var message = opts.filename + ": " + err.message;
|
||||
|
||||
var loc = err.loc;
|
||||
if (loc) {
|
||||
var frame = codeFrame(code, loc.line, loc.column + 1);
|
||||
message += frame;
|
||||
}
|
||||
|
||||
if (err.stack) err.stack = err.stack.replace(err.message, message);
|
||||
err.message = message;
|
||||
}
|
||||
|
||||
throw err;
|
||||
}
|
||||
};
|
||||
51
lib/babel/messages.js
Normal file
51
lib/babel/messages.js
Normal file
@@ -0,0 +1,51 @@
|
||||
var util = require("util");
|
||||
|
||||
exports.messages = {
|
||||
tailCallReassignmentDeopt: "Function reference has been reassigned so it's probably be dereferenced so we can't optimise this with confidence",
|
||||
JSXNamespacedTags: "Namespace tags are not supported. ReactJSX is not XML.",
|
||||
classesIllegalBareSuper: "Illegal use of bare super",
|
||||
classesIllegalSuperCall: "Direct super call is illegal in non-constructor, use super.$1() instead",
|
||||
classesIllegalConstructorKind: "Illegal kind for constructor method",
|
||||
scopeDuplicateDeclaration: "Duplicate declaration $1",
|
||||
undeclaredVariable: "Reference to undeclared variable $1",
|
||||
undeclaredVariableSuggestion: "Reference to undeclared variable $1 - did you mean $2?",
|
||||
settersInvalidParamLength: "Setters must have exactly one parameter",
|
||||
noAssignmentsInForHead: "No assignments allowed in for-in/of head",
|
||||
expectedMemberExpressionOrIdentifier: "Expected type MemeberExpression or Identifier",
|
||||
invalidParentForThisNode: "We don't know how to handle this node within the current parent - please open an issue",
|
||||
readOnly: "$1 is read-only",
|
||||
modulesIllegalExportName: "Illegal export $1",
|
||||
unknownForHead: "Unknown node type $1 in ForStatement",
|
||||
didYouMean: "Did you mean $1?",
|
||||
evalInStrictMode: "eval is not allowed in strict mode",
|
||||
codeGeneratorDeopt: "Note: The code generator has deoptimised the styling of $1 as it exceeds the max of $2."
|
||||
};
|
||||
|
||||
exports.get = function (key) {
|
||||
var msg = exports.messages[key];
|
||||
if (!msg) throw new ReferenceError("Unknown message `" + key + "`");
|
||||
|
||||
var args = [];
|
||||
for (var i = 1; i < arguments.length; i++) {
|
||||
args.push(arguments[i]);
|
||||
}
|
||||
args = exports.parseArgs(args);
|
||||
|
||||
return msg.replace(/\$(\d+)/g, function (str, i) {
|
||||
return args[--i];
|
||||
});
|
||||
};
|
||||
|
||||
exports.parseArgs = function (args) {
|
||||
return args.map(function (val) {
|
||||
if (val != null && val.inspect) {
|
||||
return val.inspect();
|
||||
} else {
|
||||
try {
|
||||
return JSON.stringify(val) || val + "";
|
||||
} catch (e) {
|
||||
return util.inspect(val);
|
||||
}
|
||||
}
|
||||
});
|
||||
};
|
||||
@@ -1,16 +1,14 @@
|
||||
"use strict";
|
||||
|
||||
var t = require("./types");
|
||||
var _ = require("lodash");
|
||||
|
||||
require("./types/node");
|
||||
var extend = require("lodash/object/extend");
|
||||
var t = require("./types");
|
||||
|
||||
// estraverse
|
||||
|
||||
var estraverse = require("estraverse");
|
||||
_.extend(estraverse.VisitorKeys, t.VISITOR_KEYS);
|
||||
extend(estraverse.VisitorKeys, t.VISITOR_KEYS);
|
||||
|
||||
// regenerator-6to5/ast-types
|
||||
// regenerator-babel/ast-types
|
||||
|
||||
var types = require("ast-types");
|
||||
var def = types.Type.def;
|
||||
@@ -34,9 +32,9 @@ def("ImportBatchSpecifier")
|
||||
.field("name", def("Identifier"));
|
||||
|
||||
def("RestElement")
|
||||
.bases("Node")
|
||||
.bases("Pattern")
|
||||
.build("argument")
|
||||
.field("argument", def("Pattern"));
|
||||
.field("argument", def("expression"));
|
||||
|
||||
// Abstract references
|
||||
def("VirtualPropertyExpression")
|
||||
9
lib/babel/polyfill.js
Normal file
9
lib/babel/polyfill.js
Normal file
@@ -0,0 +1,9 @@
|
||||
"use strict";
|
||||
|
||||
if (global._babelPolyfill) {
|
||||
throw new Error("only one instance of babel/polyfill is allowed");
|
||||
}
|
||||
global._babelPolyfill = true;
|
||||
|
||||
require("core-js/shim");
|
||||
require("regenerator-babel/runtime");
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user