Compare commits
1134 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
02cb397873 | ||
|
|
d9169a87ad | ||
|
|
f3b6f2fc61 | ||
|
|
04cc24ee82 | ||
|
|
f32079ef42 | ||
|
|
d1b69656ae | ||
|
|
09453a490b | ||
|
|
e2e7627f0f | ||
|
|
4fe24a9a3b | ||
|
|
d26e7ad577 | ||
|
|
571cb4928f | ||
|
|
c12e8122f8 | ||
|
|
92e7a01d14 | ||
|
|
b9ca9d42dc | ||
|
|
479c3e477a | ||
|
|
2c3d3d8105 | ||
|
|
ea03f67505 | ||
|
|
ee0c88a070 | ||
|
|
98206df864 | ||
|
|
1066a42fb2 | ||
|
|
062175586c | ||
|
|
0dc6b582a6 | ||
|
|
d8d70ba137 | ||
|
|
f23c916520 | ||
|
|
8ae4601177 | ||
|
|
9a466d3ef9 | ||
|
|
713845d14c | ||
|
|
471d60e5cd | ||
|
|
43864e0686 | ||
|
|
4c2ae5dd19 | ||
|
|
a540cbe801 | ||
|
|
34cc577fa2 | ||
|
|
c855b55133 | ||
|
|
16c86c25b7 | ||
|
|
4345f7945b | ||
|
|
f44c93add2 | ||
|
|
09e45c51a4 | ||
|
|
1a42b72b15 | ||
|
|
d30415d74a | ||
|
|
616ef8d840 | ||
|
|
56437f94bc | ||
|
|
881fa6430b | ||
|
|
b7971690f3 | ||
|
|
c01d0abbd3 | ||
|
|
7043119346 | ||
|
|
b5325df57f | ||
|
|
0fc958e0fc | ||
|
|
9cb16711dd | ||
|
|
04766b13f5 | ||
|
|
433d704739 | ||
|
|
30204d2ee6 | ||
|
|
374b7cca2c | ||
|
|
152ae388f0 | ||
|
|
04344026bb | ||
|
|
cfffaf6cdb | ||
|
|
2952d94e60 | ||
|
|
0276c3ae81 | ||
|
|
c00f8dce3f | ||
|
|
4e24ae39cf | ||
|
|
12bd6494b7 | ||
|
|
e35c7550fe | ||
|
|
e7046abe72 | ||
|
|
affa7f0c6f | ||
|
|
be650ffc61 | ||
|
|
3078d48178 | ||
|
|
0be93563dd | ||
|
|
3e55980145 | ||
|
|
470ebf3a46 | ||
|
|
b695369126 | ||
|
|
f4611469b4 | ||
|
|
68bfafe745 | ||
|
|
f72782b71c | ||
|
|
0f1f5e3565 | ||
|
|
dfe126f3d4 | ||
|
|
4c9cb957a9 | ||
|
|
8f997f8825 | ||
|
|
d789a6e7aa | ||
|
|
4007148d9f | ||
|
|
998f1d544e | ||
|
|
deed48a3db | ||
|
|
00c0a958db | ||
|
|
1511dcbd73 | ||
|
|
12fef25803 | ||
|
|
fd30eb1839 | ||
|
|
63344eb0a4 | ||
|
|
6e4e11a365 | ||
|
|
e330efe058 | ||
|
|
ce86eca8b0 | ||
|
|
03dbaa3e0e | ||
|
|
2bd35fac6e | ||
|
|
cdca4e50d9 | ||
|
|
bb041c1bd6 | ||
|
|
a36c1b4a92 | ||
|
|
b760daca21 | ||
|
|
ff63d8f60c | ||
|
|
74f04ed6a1 | ||
|
|
74d880bf18 | ||
|
|
5ce38cacaa | ||
|
|
829f642ad8 | ||
|
|
80a4b95da4 | ||
|
|
dc2a20dbcd | ||
|
|
f6278e43ce | ||
|
|
30bc80000b | ||
|
|
ef56042c93 | ||
|
|
b6498103db | ||
|
|
7af4302d07 | ||
|
|
543770960c | ||
|
|
a2975a72cc | ||
|
|
beb3fd51d8 | ||
|
|
9360860601 | ||
|
|
7d4ecea8fb | ||
|
|
a44831b3fa | ||
|
|
8357f3900f | ||
|
|
6b1c5bc358 | ||
|
|
3564309a77 | ||
|
|
c9518bb60d | ||
|
|
0f1215e33e | ||
|
|
d7b0b5bec0 | ||
|
|
3e5af404ab | ||
|
|
1818094577 | ||
|
|
6d712b3d14 | ||
|
|
11389fe165 | ||
|
|
0ee9531db3 | ||
|
|
1622d2498d | ||
|
|
b76e6f8e5b | ||
|
|
beac006832 | ||
|
|
20d7603c0b | ||
|
|
24b13c5e49 | ||
|
|
9e21074e88 | ||
|
|
9a825bced7 | ||
|
|
fcb78436c6 | ||
|
|
bb30a64f8d | ||
|
|
b483c16fe2 | ||
|
|
569f046045 | ||
|
|
4e969d3d92 | ||
|
|
0bca1de285 | ||
|
|
3a5bd06a7e | ||
|
|
66a908aaa7 | ||
|
|
cd0ed08237 | ||
|
|
dd84b554e6 | ||
|
|
b51411f090 | ||
|
|
4cc843ded3 | ||
|
|
47d253c732 | ||
|
|
09901274ab | ||
|
|
35196e20c7 | ||
|
|
35af771a29 | ||
|
|
dee80caa09 | ||
|
|
46b7cc0a72 | ||
|
|
3b189e22b7 | ||
|
|
6ca565d7fb | ||
|
|
64f5480f96 | ||
|
|
828fdc8769 | ||
|
|
6763c4415e | ||
|
|
fb30e79e03 | ||
|
|
85fb4304b0 | ||
|
|
c2da77d7ec | ||
|
|
c54c3d3c15 | ||
|
|
2a7c954155 | ||
|
|
3fb7f7c7cc | ||
|
|
c4b2818336 | ||
|
|
061561bfd8 | ||
|
|
d4944d606b | ||
|
|
736b689c3b | ||
|
|
e12b377014 | ||
|
|
5fd5b815ab | ||
|
|
92db8312f6 | ||
|
|
e080fe547d | ||
|
|
b967ecf063 | ||
|
|
365b7285d2 | ||
|
|
a40d532b0e | ||
|
|
0487bf911d | ||
|
|
57c72d1cd0 | ||
|
|
335bdffec2 | ||
|
|
e1d76a1dfe | ||
|
|
a4845323a2 | ||
|
|
792951b489 | ||
|
|
5adda836af | ||
|
|
4c2c3098c3 | ||
|
|
087c714098 | ||
|
|
5a33e4fe05 | ||
|
|
5f8667eaa7 | ||
|
|
31b4468514 | ||
|
|
2be9678bbe | ||
|
|
b5210877cf | ||
|
|
658dde768e | ||
|
|
8df1d81ca4 | ||
|
|
a505e4a121 | ||
|
|
71eafdcac7 | ||
|
|
65060b0c97 | ||
|
|
09883962f1 | ||
|
|
1583262807 | ||
|
|
04c7cd5c0c | ||
|
|
3f6969f4f8 | ||
|
|
23db842cb8 | ||
|
|
41c82e00f9 | ||
|
|
766099e783 | ||
|
|
53bc54b3b2 | ||
|
|
bb70f37123 | ||
|
|
8a0317132e | ||
|
|
f598c70841 | ||
|
|
61b57ea055 | ||
|
|
a971ad7fd2 | ||
|
|
27b6f804ce | ||
|
|
8ab79f3a72 | ||
|
|
0c2bf2f5a2 | ||
|
|
7e1a4be085 | ||
|
|
bbc951dfe1 | ||
|
|
b3e4aefe12 | ||
|
|
26b5174dfa | ||
|
|
652d3c7320 | ||
|
|
edc2cd320c | ||
|
|
274a6e01dc | ||
|
|
3561efdb86 | ||
|
|
1a30f1aafc | ||
|
|
e362512af3 | ||
|
|
cf5d2429b4 | ||
|
|
72098036b2 | ||
|
|
7905f48280 | ||
|
|
aba2d1c23c | ||
|
|
5326e0543d | ||
|
|
1360c93e4b | ||
|
|
235cbc18cf | ||
|
|
98c5255b91 | ||
|
|
2a9777cc20 | ||
|
|
a8702be756 | ||
|
|
0995cc3f4e | ||
|
|
1cfca745a4 | ||
|
|
a3459deecf | ||
|
|
070152f6c1 | ||
|
|
719fdf5ca1 | ||
|
|
f2460c6173 | ||
|
|
155c640409 | ||
|
|
7de4718b27 | ||
|
|
4e6aed0408 | ||
|
|
3be8ccf68d | ||
|
|
704b31f44f | ||
|
|
1a9f193841 | ||
|
|
7ff67589a7 | ||
|
|
80f109efeb | ||
|
|
77c72bb5a6 | ||
|
|
6c5e0e6590 | ||
|
|
83324b977d | ||
|
|
5feab11d3f | ||
|
|
7b4172ce7b | ||
|
|
84439384c0 | ||
|
|
c9e7c306cc | ||
|
|
1e398e45ff | ||
|
|
475324c4b5 | ||
|
|
407daf4bac | ||
|
|
4155590cd8 | ||
|
|
0be6fd7abe | ||
|
|
cf51bf1395 | ||
|
|
06a31c419a | ||
|
|
da566110c0 | ||
|
|
c12c4a5c39 | ||
|
|
d114349890 | ||
|
|
8d6ae0e1eb | ||
|
|
cb8b47ee2f | ||
|
|
daf24c5c59 | ||
|
|
cdb2784e75 | ||
|
|
93feabb82e | ||
|
|
982c142bf6 | ||
|
|
de5520a94f | ||
|
|
c239d06f10 | ||
|
|
a5fed376d8 | ||
|
|
e99fd77d89 | ||
|
|
1374863b9c | ||
|
|
e88c28f88b | ||
|
|
7a0fd26f56 | ||
|
|
17583e4807 | ||
|
|
37dd5137ff | ||
|
|
24fced406e | ||
|
|
0ab1362893 | ||
|
|
96506f4249 | ||
|
|
ed747f88bd | ||
|
|
3987545b4f | ||
|
|
148aa3f96d | ||
|
|
0cb5a7c91e | ||
|
|
fc34d5a9b0 | ||
|
|
f8d56d9612 | ||
|
|
737be0e95e | ||
|
|
26e2b392e8 | ||
|
|
708cdfb993 | ||
|
|
8cb3aabefa | ||
|
|
4a87b35d20 | ||
|
|
543554b258 | ||
|
|
afd95cf663 | ||
|
|
87ce4b9cd8 | ||
|
|
6b76f26ed8 | ||
|
|
c2776e63ae | ||
|
|
3f2fe363d1 | ||
|
|
8de28098f4 | ||
|
|
584532cc2c | ||
|
|
9a28f3fdb1 | ||
|
|
88941b3270 | ||
|
|
3a768db2bf | ||
|
|
320a39f4c4 | ||
|
|
dc98ac7c93 | ||
|
|
6e456f0ec1 | ||
|
|
793090628d | ||
|
|
9ed251cb08 | ||
|
|
480fa7f4e0 | ||
|
|
3e642dfa1b | ||
|
|
d9cbce1862 | ||
|
|
4bd19da3c2 | ||
|
|
7c710a0378 | ||
|
|
56335409d3 | ||
|
|
91d78afc67 | ||
|
|
54c6339f20 | ||
|
|
fdcf64265e | ||
|
|
ffdfb491eb | ||
|
|
eedd431f2b | ||
|
|
db9ed0235f | ||
|
|
6c98d39937 | ||
|
|
20651df3ce | ||
|
|
f3155919fe | ||
|
|
0ac8330899 | ||
|
|
67201e9698 | ||
|
|
c715d96e46 | ||
|
|
b7a08100a6 | ||
|
|
5f91ee8a1a | ||
|
|
bc1abb5103 | ||
|
|
4b9207e5df | ||
|
|
e847f3685f | ||
|
|
d64c2c0c45 | ||
|
|
76d0fb4ba6 | ||
|
|
0f33b7bfbc | ||
|
|
630224e504 | ||
|
|
62980ab6b4 | ||
|
|
d34480b42b | ||
|
|
306de2edbf | ||
|
|
c33e84730d | ||
|
|
20f28aba64 | ||
|
|
9c312607d1 | ||
|
|
33659711c3 | ||
|
|
b154af48a7 | ||
|
|
bad877946f | ||
|
|
dff3751e7f | ||
|
|
23038dcfff | ||
|
|
7c7a7ee17f | ||
|
|
9f467ef7c0 | ||
|
|
a52f9ab346 | ||
|
|
5ccbed585b | ||
|
|
f7c7da7526 | ||
|
|
ed58c80c64 | ||
|
|
d7fb9f67df | ||
|
|
eef6002324 | ||
|
|
32bcf4c3a5 | ||
|
|
86060cb0ce | ||
|
|
66a836d435 | ||
|
|
ecc14c2a31 | ||
|
|
7e9b60fba5 | ||
|
|
313f1e755a | ||
|
|
8c7ef0a2c9 | ||
|
|
8f79010b16 | ||
|
|
022e6f26aa | ||
|
|
138fa6c9f8 | ||
|
|
c07704cc80 | ||
|
|
bf811ea34a | ||
|
|
8af3ea1c43 | ||
|
|
5fbe147a5e | ||
|
|
a9e214b1db | ||
|
|
6812fca7a9 | ||
|
|
ebc42f5ce0 | ||
|
|
b12a97ddd6 | ||
|
|
e8daad38a7 | ||
|
|
c6c0bc07e2 | ||
|
|
c60f3f0e34 | ||
|
|
07078138f3 | ||
|
|
cb0026edfe | ||
|
|
ab55ec4ea2 | ||
|
|
e164123ce9 | ||
|
|
f42bacf4f6 | ||
|
|
46adb07d41 | ||
|
|
e10bdf7c5b | ||
|
|
83eea2acc7 | ||
|
|
8bdd4cc559 | ||
|
|
15d31b5608 | ||
|
|
9ed6a7b650 | ||
|
|
01a2aa7dd1 | ||
|
|
33fde5f143 | ||
|
|
682c775a97 | ||
|
|
4846b89931 | ||
|
|
25312396a5 | ||
|
|
cfff7aa6fb | ||
|
|
f88a4147a6 | ||
|
|
3c343adf33 | ||
|
|
269587cde5 | ||
|
|
121ba8c381 | ||
|
|
563a427b69 | ||
|
|
658164a0d2 | ||
|
|
135ba84abb | ||
|
|
76573093bd | ||
|
|
22b88487ee | ||
|
|
3686951dc1 | ||
|
|
f43ca32ff5 | ||
|
|
424a59a856 | ||
|
|
5f159853d5 | ||
|
|
f9c56c6dd7 | ||
|
|
613e77cd50 | ||
|
|
27c97aab34 | ||
|
|
ad857dddd1 | ||
|
|
d9762e9049 | ||
|
|
088846a347 | ||
|
|
7fc28cb63f | ||
|
|
3323e0f3a5 | ||
|
|
8c09a2198a | ||
|
|
eeb5b8d0c3 | ||
|
|
19e8274e79 | ||
|
|
6353abfd1b | ||
|
|
ee14770a5c | ||
|
|
d3b9b7251e | ||
|
|
3f7f89a6b9 | ||
|
|
7476b8c6a3 | ||
|
|
1ef41b6f32 | ||
|
|
6bc2bfce7d | ||
|
|
153e81261c | ||
|
|
b8f2a27e90 | ||
|
|
2f25c3bd17 | ||
|
|
59e07b65dd | ||
|
|
769f7fb81d | ||
|
|
7895857624 | ||
|
|
80fed5f395 | ||
|
|
1c7fabdd6d | ||
|
|
12f8fa229d | ||
|
|
c6546264d2 | ||
|
|
86cc5875cf | ||
|
|
9ea999b261 | ||
|
|
f81e841283 | ||
|
|
c14ffb8319 | ||
|
|
b9f4fe86f1 | ||
|
|
56ada634b4 | ||
|
|
c4d68897b3 | ||
|
|
1641caedc4 | ||
|
|
3d6e722fc7 | ||
|
|
253493a43f | ||
|
|
66471f044a | ||
|
|
5fa227eb73 | ||
|
|
f3b50f0bb9 | ||
|
|
92bba76bd5 | ||
|
|
46462e3e69 | ||
|
|
bc155f956c | ||
|
|
dc1ba58705 | ||
|
|
99e274921f | ||
|
|
862bd6d92a | ||
|
|
46d991e3e9 | ||
|
|
8e1b6df970 | ||
|
|
f9c8d7d1fd | ||
|
|
eb2f61e43f | ||
|
|
afe8792ba4 | ||
|
|
42a2430d2c | ||
|
|
c4d260231b | ||
|
|
ca5daca5dd | ||
|
|
3952eefd01 | ||
|
|
52c6fe2bc1 | ||
|
|
6a698f7ae4 | ||
|
|
2b0c07c2e7 | ||
|
|
e27e7facac | ||
|
|
0dd32e7d9c | ||
|
|
286ae68da2 | ||
|
|
e26f994075 | ||
|
|
94f005e324 | ||
|
|
93e37aaaf1 | ||
|
|
e4db93f6a5 | ||
|
|
c9243e8e97 | ||
|
|
bbba374783 | ||
|
|
7d95fddbed | ||
|
|
617ed09227 | ||
|
|
6d7887cfe2 | ||
|
|
b8e9171aaa | ||
|
|
22118c0be0 | ||
|
|
3754f7615f | ||
|
|
b54901018b | ||
|
|
121b9ca063 | ||
|
|
4988a27b6c | ||
|
|
e0297e08b8 | ||
|
|
79005d2f03 | ||
|
|
5cce8c32a4 | ||
|
|
95b1accddc | ||
|
|
6149e6325f | ||
|
|
4c9d4d0378 | ||
|
|
2e599bef4f | ||
|
|
885da177f9 | ||
|
|
463112517f | ||
|
|
8f10dc5c39 | ||
|
|
0f99bbe293 | ||
|
|
0a5d2c098f | ||
|
|
dcf4381e26 | ||
|
|
543582ef47 | ||
|
|
a4db58ccaa | ||
|
|
d3971e0874 | ||
|
|
ad98186afc | ||
|
|
df251fbfff | ||
|
|
dfbcf95b0e | ||
|
|
07646475d9 | ||
|
|
9bc67c28e3 | ||
|
|
c2990d3548 | ||
|
|
803f8a3bbc | ||
|
|
ee6efee4f8 | ||
|
|
3f144e6e74 | ||
|
|
afedfe15ae | ||
|
|
b522294d3c | ||
|
|
954af72476 | ||
|
|
de42a6f796 | ||
|
|
06a58f228c | ||
|
|
7a44576c26 | ||
|
|
eaa3865427 | ||
|
|
b83907cc67 | ||
|
|
a3620a58f8 | ||
|
|
67a12f03fa | ||
|
|
c49871d33c | ||
|
|
c828688d21 | ||
|
|
bd052aea50 | ||
|
|
ed74ccaa7d | ||
|
|
f3c9551b75 | ||
|
|
710a7f882d | ||
|
|
902ebd3fe7 | ||
|
|
23c20cc47c | ||
|
|
9b627ace5d | ||
|
|
4fa17341f5 | ||
|
|
1e019c0f16 | ||
|
|
ce25ebacbf | ||
|
|
daecec2a86 | ||
|
|
238f9c2e7e | ||
|
|
bc5f2b9be6 | ||
|
|
5390715705 | ||
|
|
aa1333123c | ||
|
|
048f9acc55 | ||
|
|
ed6421876a | ||
|
|
e60c9fba6a | ||
|
|
902db03e96 | ||
|
|
de88b28988 | ||
|
|
0ee230d13c | ||
|
|
c12cfe3ed0 | ||
|
|
1376f2f18f | ||
|
|
972c621f59 | ||
|
|
5c41a33e41 | ||
|
|
bc6d01d6fc | ||
|
|
01463faf36 | ||
|
|
b234603e24 | ||
|
|
ca79fff0c4 | ||
|
|
3c8f3cb521 | ||
|
|
c9974a42ea | ||
|
|
a87f6f6fdd | ||
|
|
3d28ce7903 | ||
|
|
e04ecc79c7 | ||
|
|
3e26511fb2 | ||
|
|
9c3493e02f | ||
|
|
a14e979897 | ||
|
|
a4ce653bed | ||
|
|
70d068226a | ||
|
|
30b1c0154d | ||
|
|
a602873281 | ||
|
|
c8b88182f6 | ||
|
|
64f1c114c1 | ||
|
|
4ac1a856ae | ||
|
|
0e68b6ca11 | ||
|
|
2dccc8c919 | ||
|
|
fdea18a289 | ||
|
|
c3bdecbd25 | ||
|
|
ee63fb52b7 | ||
|
|
8575392606 | ||
|
|
d28583bea1 | ||
|
|
b166f35218 | ||
|
|
0914378bba | ||
|
|
660d764390 | ||
|
|
27206d6b7c | ||
|
|
34dc56b435 | ||
|
|
d919d7837c | ||
|
|
b49cf4e779 | ||
|
|
e30dd7042b | ||
|
|
16d8d928e8 | ||
|
|
4966028397 | ||
|
|
82e04fffac | ||
|
|
a46313903d | ||
|
|
68340b1288 | ||
|
|
6a1b33b443 | ||
|
|
df7524d909 | ||
|
|
2c39d406d1 | ||
|
|
2ff1a5d98b | ||
|
|
7f9fe4af15 | ||
|
|
977290c7e4 | ||
|
|
ebbdb95278 | ||
|
|
9b586c7587 | ||
|
|
4b5ba6c8c6 | ||
|
|
67efb1b427 | ||
|
|
bc9c1ab61e | ||
|
|
65ffe07551 | ||
|
|
b606cc79ca | ||
|
|
0e7fd0741d | ||
|
|
276cafaae1 | ||
|
|
4f00de50d6 | ||
|
|
b07341a1f7 | ||
|
|
ec526f9224 | ||
|
|
76301a7713 | ||
|
|
67ac91815b | ||
|
|
976e8c1cfd | ||
|
|
4d965b0f46 | ||
|
|
b495370740 | ||
|
|
b1c5915ed3 | ||
|
|
d94bb2e048 | ||
|
|
25fa10e592 | ||
|
|
8d3a7acbd1 | ||
|
|
29d33dd31a | ||
|
|
4afd0f553e | ||
|
|
1fb877e9f5 | ||
|
|
866d3a8eab | ||
|
|
76e1f0dd9f | ||
|
|
1bbe52a022 | ||
|
|
cc0f43813c | ||
|
|
b13b4bbfba | ||
|
|
1c6ac0a07a | ||
|
|
5a319fd553 | ||
|
|
a8cedf813b | ||
|
|
9f037fa75e | ||
|
|
8681a78618 | ||
|
|
2d72d423b3 | ||
|
|
280964eafe | ||
|
|
5ee9b3c37e | ||
|
|
9676056f08 | ||
|
|
080a844457 | ||
|
|
1f9f57a2a6 | ||
|
|
056b7fc634 | ||
|
|
547ecc2f73 | ||
|
|
a1ab8fa0c1 | ||
|
|
9e61a307d4 | ||
|
|
d4d18f4230 | ||
|
|
f4ce216d1c | ||
|
|
d71c72de3c | ||
|
|
b1c21b8d4d | ||
|
|
e9b0005cf5 | ||
|
|
63bac550cd | ||
|
|
d0b6aa9882 | ||
|
|
0e877acfdf | ||
|
|
b670ee18df | ||
|
|
24807120bf | ||
|
|
33f7c0b67e | ||
|
|
c23b47f796 | ||
|
|
2871d8a710 | ||
|
|
3172b5de5d | ||
|
|
2c05303813 | ||
|
|
75dda10057 | ||
|
|
12664c6cd6 | ||
|
|
581f70c803 | ||
|
|
a00d2c33d8 | ||
|
|
c906bd3edc | ||
|
|
27fc574e9f | ||
|
|
a3b1fcc79c | ||
|
|
491cb26c1f | ||
|
|
7c3d052714 | ||
|
|
4971d0c7f0 | ||
|
|
eb4922b1ec | ||
|
|
bb26183b44 | ||
|
|
4b066f7f1b | ||
|
|
41a8257005 | ||
|
|
b44ba25d11 | ||
|
|
40a111abbf | ||
|
|
9cff51915d | ||
|
|
3cd110a7c9 | ||
|
|
a7f9e035a4 | ||
|
|
146b9e6708 | ||
|
|
0953c48620 | ||
|
|
056b90831d | ||
|
|
8ba276b209 | ||
|
|
8eaa9d29e3 | ||
|
|
6212791356 | ||
|
|
d436d32d82 | ||
|
|
2a29f70bba | ||
|
|
6ccb8957bd | ||
|
|
dc45415ee0 | ||
|
|
98ca541fde | ||
|
|
8328f638c2 | ||
|
|
5586ce280f | ||
|
|
0ca71f5e15 | ||
|
|
212776e220 | ||
|
|
4a95a9ec8f | ||
|
|
45953ffc8a | ||
|
|
9c79290bb2 | ||
|
|
cfdf6b7385 | ||
|
|
907e0e0f86 | ||
|
|
f3bd9cbcb8 | ||
|
|
3bd14f9e07 | ||
|
|
102b4b3d1e | ||
|
|
6564f1ff76 | ||
|
|
58d7a5e069 | ||
|
|
f5db53cebe | ||
|
|
2da010fcae | ||
|
|
52b99bdf93 | ||
|
|
9d7e953451 | ||
|
|
b1252b865b | ||
|
|
068b1341d9 | ||
|
|
20eb143915 | ||
|
|
1302a86bf2 | ||
|
|
b7831f1d7b | ||
|
|
e46cabb21f | ||
|
|
fff06a047e | ||
|
|
6b0320fc83 | ||
|
|
5dde63fa0a | ||
|
|
672118149a | ||
|
|
5e0236d9a7 | ||
|
|
5101664e7d | ||
|
|
2d684a06d3 | ||
|
|
e31bad8f42 | ||
|
|
644b4373fc | ||
|
|
62f37c1e62 | ||
|
|
fc0e89463b | ||
|
|
56b6a795a4 | ||
|
|
17b34a2959 | ||
|
|
c4da0253c5 | ||
|
|
5f2df40f6d | ||
|
|
7d20a9b882 | ||
|
|
ee0ac9f149 | ||
|
|
c5d3f42d8a | ||
|
|
d162919a53 | ||
|
|
d1f712344d | ||
|
|
e985912b54 | ||
|
|
97a21e4a34 | ||
|
|
d8fb7812f7 | ||
|
|
bfe63f5885 | ||
|
|
44ca6873a3 | ||
|
|
2f66ea7338 | ||
|
|
70967cf53c | ||
|
|
dc117a74ae | ||
|
|
b0f32a822d | ||
|
|
fd99ea1749 | ||
|
|
572129542d | ||
|
|
6f53980bfc | ||
|
|
348af1990d | ||
|
|
bd5f350728 | ||
|
|
958fa282f4 | ||
|
|
31e6b18346 | ||
|
|
d17ac92a3f | ||
|
|
188bcb70f7 | ||
|
|
b8bd11a0e7 | ||
|
|
45bc74efe7 | ||
|
|
7eb169a894 | ||
|
|
eed4f312d8 | ||
|
|
44e4dc970f | ||
|
|
5d32432e67 | ||
|
|
9c9af6dbbd | ||
|
|
70cd650e10 | ||
|
|
c7bb00d58d | ||
|
|
623be068c4 | ||
|
|
71f5c9791d | ||
|
|
3e6e86d073 | ||
|
|
a0fb398ca2 | ||
|
|
71b9f19e6a | ||
|
|
c45ce58f0c | ||
|
|
d32f587e3c | ||
|
|
9e1874ba89 | ||
|
|
35fdc5c5d8 | ||
|
|
a4035fc257 | ||
|
|
42e3dc7a70 | ||
|
|
cdccf24515 | ||
|
|
c8cd5c108b | ||
|
|
2b95b876e1 | ||
|
|
f801772fc2 | ||
|
|
8ad678e5bc | ||
|
|
35c49dbef7 | ||
|
|
119314df74 | ||
|
|
51e336b037 | ||
|
|
7d446807a9 | ||
|
|
8afdeaf557 | ||
|
|
4df50954a2 | ||
|
|
70b6317865 | ||
|
|
5ebdc44297 | ||
|
|
a4659fd239 | ||
|
|
19bfa4a35b | ||
|
|
f7fff7d35e | ||
|
|
130e0ebe6b | ||
|
|
69c836fc8d | ||
|
|
f62a3ef394 | ||
|
|
7a6e568940 | ||
|
|
65998c3437 | ||
|
|
160de340b0 | ||
|
|
76ca40f698 | ||
|
|
01ed824b5c | ||
|
|
6b0dbc4486 | ||
|
|
2648268f30 | ||
|
|
8cf5bf7037 | ||
|
|
60961bc3ff | ||
|
|
df16bc17e7 | ||
|
|
5337ab5a08 | ||
|
|
2eaeebcce4 | ||
|
|
ad71010144 | ||
|
|
864169c1eb | ||
|
|
930d7f9aa6 | ||
|
|
ed40ec03d1 | ||
|
|
73062ae240 | ||
|
|
bafa3e0d4c | ||
|
|
f3d2b2bb81 | ||
|
|
a74b67d4eb | ||
|
|
625416862f | ||
|
|
8dda8838ba | ||
|
|
96d3a25213 | ||
|
|
727208f376 | ||
|
|
1b046a6ecb | ||
|
|
3b8ed0d401 | ||
|
|
d4c98d7738 | ||
|
|
4e44af819f | ||
|
|
a65acd73ca | ||
|
|
b7cb2bcb7b | ||
|
|
5ac4dc0541 | ||
|
|
99ddd02b0a | ||
|
|
19cfee14fd | ||
|
|
fea487bf91 | ||
|
|
ff2cbd5a2e | ||
|
|
12e01f9e71 | ||
|
|
f62436909d | ||
|
|
e42c1adeb6 | ||
|
|
e30dbbab94 | ||
|
|
e3daa28e60 | ||
|
|
9e5d94126c | ||
|
|
95798bee0b | ||
|
|
63f25ab038 | ||
|
|
27a8f2d2ea | ||
|
|
78434bb404 | ||
|
|
82833a8901 | ||
|
|
93d5288d71 | ||
|
|
5d3074b460 | ||
|
|
a57475abc9 | ||
|
|
09e68d8d46 | ||
|
|
ee850c3aeb | ||
|
|
ff5a149cec | ||
|
|
957118fb41 | ||
|
|
e7ad0a9741 | ||
|
|
24f4b041c7 | ||
|
|
4c77d04b56 | ||
|
|
e945f0d10f | ||
|
|
fb04b2561f | ||
|
|
a4f8b41507 | ||
|
|
1fb6018e9c | ||
|
|
bca233d22c | ||
|
|
c78703e194 | ||
|
|
43fdbe3d6c | ||
|
|
8650ca7d55 | ||
|
|
3a0c226a34 | ||
|
|
73e8bdd048 | ||
|
|
e7c52a734e | ||
|
|
5a81b02569 | ||
|
|
999baf2888 | ||
|
|
70b25e8942 | ||
|
|
2ddbd4eecc | ||
|
|
7520807df3 | ||
|
|
974b71bcc3 | ||
|
|
0aee3c06ec | ||
|
|
a4382580fc | ||
|
|
166b2eda87 | ||
|
|
83c23d266f | ||
|
|
a9db70b60d | ||
|
|
5d90c442cb | ||
|
|
32606ddb93 | ||
|
|
330f6910c6 | ||
|
|
4ca8a0e6e2 | ||
|
|
f097ddeac3 | ||
|
|
1eb53dd13a | ||
|
|
75b5f32e7a | ||
|
|
f753cf4845 | ||
|
|
9a569f64da | ||
|
|
8efeae80af | ||
|
|
4df9cf6c05 | ||
|
|
7729cb4b68 | ||
|
|
307ffcd107 | ||
|
|
751557aef1 | ||
|
|
3f146b54ff | ||
|
|
19a173c622 | ||
|
|
89bcb307a2 | ||
|
|
ded1e02da7 | ||
|
|
564ba67190 | ||
|
|
00c964ed19 | ||
|
|
3ab88e02c7 | ||
|
|
bb2fc830eb | ||
|
|
c6a542fd1d | ||
|
|
553eb2d45e | ||
|
|
b5f3c3f4cc | ||
|
|
5d83638583 | ||
|
|
f7186980e5 | ||
|
|
0eaaaa503e | ||
|
|
51dff364db | ||
|
|
dc6129eb6a | ||
|
|
5b84b9c867 | ||
|
|
04c3027f4d | ||
|
|
95e2345b19 | ||
|
|
eafb02be31 | ||
|
|
b91997354c | ||
|
|
4b8039a00c | ||
|
|
0a0931dc2e | ||
|
|
24ace3c8c2 | ||
|
|
372c06eb80 | ||
|
|
b8121ed4d0 | ||
|
|
1f79445ee5 | ||
|
|
cb46ca60af | ||
|
|
24c0c7679f | ||
|
|
687b0f3180 | ||
|
|
e6855b974b | ||
|
|
a808742c19 | ||
|
|
d7ec337567 | ||
|
|
845f1ce65e | ||
|
|
c3f4091b6d | ||
|
|
edb880f87c | ||
|
|
e8741daee3 | ||
|
|
88563a0c26 | ||
|
|
ccd7a6560c | ||
|
|
c340597fdb | ||
|
|
e498358125 | ||
|
|
c5913564f8 | ||
|
|
662bddbaca | ||
|
|
8f540dfff3 | ||
|
|
1265bc5a92 | ||
|
|
e677c72d58 | ||
|
|
8ca854156a | ||
|
|
81ae656358 | ||
|
|
f2981b7e95 | ||
|
|
99b2e00d33 | ||
|
|
25232d3141 | ||
|
|
5b9878451a | ||
|
|
23d6fb6bb1 | ||
|
|
8d1b5c8ccb | ||
|
|
10bd7d1b91 | ||
|
|
f5d9636353 | ||
|
|
a7f713ef5a | ||
|
|
ba11069b1c | ||
|
|
c13f8a3f50 | ||
|
|
339bd2b6d9 | ||
|
|
a2843a5cb8 | ||
|
|
c31832439a | ||
|
|
b7f19221a9 | ||
|
|
46a37f4672 | ||
|
|
cfe2c19a02 | ||
|
|
649d91ef25 | ||
|
|
4d72bffa30 | ||
|
|
5889233adc | ||
|
|
7bb98352df | ||
|
|
12ebeed7c6 | ||
|
|
7d87e52377 | ||
|
|
2bab285970 | ||
|
|
00651e671e | ||
|
|
37588a6ceb | ||
|
|
a45d6960da | ||
|
|
b13aa41a75 | ||
|
|
20a4ed6140 | ||
|
|
c256e060b3 | ||
|
|
bef315efd6 | ||
|
|
2ec5390b63 | ||
|
|
f4c9dd8768 | ||
|
|
510c7a3e60 | ||
|
|
3ce9508a1c | ||
|
|
717ef280f7 | ||
|
|
8c5e7cf272 | ||
|
|
811a843be9 | ||
|
|
b7c297bb89 | ||
|
|
b7342ef4ea | ||
|
|
1a899f5e77 | ||
|
|
f2eb1643c0 | ||
|
|
9621d1bbeb | ||
|
|
3cf7b2b761 | ||
|
|
ae8b1e242b | ||
|
|
eea48f866d | ||
|
|
84d2d7b7d4 | ||
|
|
ea30a619dd | ||
|
|
87a201db22 | ||
|
|
bcc86c47bc | ||
|
|
b6df9b583b | ||
|
|
52ea7b5f59 | ||
|
|
7bff8239a1 | ||
|
|
04d79c1740 | ||
|
|
e387da7c2b | ||
|
|
53cf453480 | ||
|
|
341528ee4a | ||
|
|
5f6808ba92 | ||
|
|
0b2f1fedcb | ||
|
|
c3c94f0a4a | ||
|
|
f2d60aab9e | ||
|
|
ab6bb35a4f | ||
|
|
e11b943514 | ||
|
|
b44a6eb297 | ||
|
|
f3288ddb1f | ||
|
|
476aa44a90 | ||
|
|
c5589e9336 | ||
|
|
404eb2f972 | ||
|
|
366257915e | ||
|
|
e0cd9bdbe3 | ||
|
|
39854dc088 | ||
|
|
81132aa942 | ||
|
|
5ba2e6254b | ||
|
|
61ea720637 | ||
|
|
55357a331d | ||
|
|
5deaeba3a0 | ||
|
|
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 |
6
.babelrc
Normal file
6
.babelrc
Normal file
@@ -0,0 +1,6 @@
|
||||
{
|
||||
"stage": 0,
|
||||
"loose": ["all"],
|
||||
"blacklist": ["es6.tailCall"],
|
||||
"optional": ["optimisation.flow.forOf"]
|
||||
}
|
||||
@@ -4,7 +4,7 @@ root = true
|
||||
insert_final_newline = true
|
||||
charset = utf-8
|
||||
trim_trailing_whitespace = true
|
||||
insert_final_newline = true
|
||||
end_of_line = lf
|
||||
|
||||
[*.{js,json}]
|
||||
indent_style = space
|
||||
|
||||
1
.eslintignore
Normal file
1
.eslintignore
Normal file
@@ -0,0 +1 @@
|
||||
src/babel/transformation/templates
|
||||
22
.eslintrc
Normal file
22
.eslintrc
Normal file
@@ -0,0 +1,22 @@
|
||||
{
|
||||
"parser": "babel-eslint",
|
||||
"rules": {
|
||||
"strict": 0,
|
||||
"no-underscore-dangle": 0,
|
||||
"no-unused-vars": 0,
|
||||
"curly": 0,
|
||||
"no-multi-spaces": 0,
|
||||
"key-spacing": 0,
|
||||
"no-return-assign": 0,
|
||||
"consistent-return": 0,
|
||||
"no-shadow": 0,
|
||||
"no-comma-dangle": 0,
|
||||
"no-use-before-define": 0,
|
||||
"no-empty": 0,
|
||||
"new-parens": 0,
|
||||
"no-cond-assign": 0
|
||||
},
|
||||
"env": {
|
||||
"node": true
|
||||
}
|
||||
}
|
||||
8
.gitignore
vendored
8
.gitignore
vendored
@@ -1,6 +1,6 @@
|
||||
.DS_Store
|
||||
node_modules
|
||||
test/tmp
|
||||
test/core/tmp
|
||||
*.log
|
||||
*.cache
|
||||
/templates.json
|
||||
@@ -11,5 +11,7 @@ test/tmp
|
||||
coverage
|
||||
dist
|
||||
.package.json
|
||||
packages/6to5-runtime/*.js
|
||||
packages/6to5-runtime/regenerator/*.js
|
||||
packages/babel-runtime/core-js
|
||||
packages/babel-runtime/helpers/*.js
|
||||
packages/babel-runtime/regenerator/*.js
|
||||
lib
|
||||
|
||||
6
.gitmodules
vendored
6
.gitmodules
vendored
@@ -1,12 +1,6 @@
|
||||
[submodule "vendor/traceur"]
|
||||
path = vendor/traceur
|
||||
url = https://github.com/google/traceur-compiler
|
||||
[submodule "vendor/regenerator"]
|
||||
path = vendor/regenerator
|
||||
url = https://github.com/6to5/regenerator-6to5
|
||||
[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
|
||||
|
||||
58
.jscsrc
58
.jscsrc
@@ -1,58 +0,0 @@
|
||||
{
|
||||
"excludeFiles": ["lib/6to5/transformation/templates"],
|
||||
"disallowSpacesInNamedFunctionExpression": {
|
||||
"beforeOpeningRoundBrace": true
|
||||
},
|
||||
"requireSpacesInAnonymousFunctionExpression": {
|
||||
"beforeOpeningRoundBrace": true
|
||||
},
|
||||
"requireSpacesInAnonymousFunctionExpression": {
|
||||
"beforeOpeningRoundBrace": true
|
||||
},
|
||||
"disallowSpacesInFunctionDeclaration": {
|
||||
"beforeOpeningRoundBrace": true
|
||||
},
|
||||
"disallowSpacesInsideArrayBrackets": true,
|
||||
"disallowSpacesInsideParentheses": true,
|
||||
"disallowSpaceAfterObjectKeys": true,
|
||||
"disallowSpaceAfterPrefixUnaryOperators": true,
|
||||
"disallowSpaceBeforePostfixUnaryOperators": true,
|
||||
"disallowSpaceBeforeBinaryOperators": [
|
||||
","
|
||||
],
|
||||
"disallowMixedSpacesAndTabs": true,
|
||||
"disallowTrailingWhitespace": true,
|
||||
"disallowYodaConditions": true,
|
||||
"disallowKeywords": [ "with" ],
|
||||
"disallowMultipleLineBreaks": true,
|
||||
"requireSpaceBeforeBlockStatements": true,
|
||||
"requireParenthesesAroundIIFE": true,
|
||||
"requireSpacesInConditionalExpression": true,
|
||||
"requireBlocksOnNewline": 1,
|
||||
"requireCommaBeforeLineBreak": true,
|
||||
"requireSpaceBeforeBinaryOperators": true,
|
||||
"requireSpaceAfterBinaryOperators": true,
|
||||
"requireLineFeedAtFileEnd": true,
|
||||
"requireCapitalizedConstructors": true,
|
||||
"requireSpacesInForStatement": true,
|
||||
"requireCurlyBraces": [
|
||||
"do"
|
||||
],
|
||||
"requireSpaceAfterKeywords": [
|
||||
"if",
|
||||
"else",
|
||||
"for",
|
||||
"while",
|
||||
"do",
|
||||
"switch",
|
||||
"case",
|
||||
"return",
|
||||
"try",
|
||||
"catch",
|
||||
"typeof",
|
||||
"function"
|
||||
],
|
||||
"validateLineBreaks": "LF",
|
||||
"validateQuoteMarks": "\"",
|
||||
"validateIndentation": 2
|
||||
}
|
||||
@@ -1 +0,0 @@
|
||||
lib/6to5/transformation/templates
|
||||
27
.jshintrc
27
.jshintrc
@@ -1,27 +0,0 @@
|
||||
{
|
||||
"esnext": true,
|
||||
"indent": 2,
|
||||
"freeze": true,
|
||||
"validthis": true,
|
||||
"camelcase": true,
|
||||
"unused": true,
|
||||
"eqnull": true,
|
||||
"newcap": true,
|
||||
"supernew": true,
|
||||
"noyield": true,
|
||||
"evil": true,
|
||||
"node": true,
|
||||
"boss": true,
|
||||
"expr": true,
|
||||
"undef": true,
|
||||
"maxparams": 5,
|
||||
"maxdepth": 4,
|
||||
|
||||
"globals": {
|
||||
"window": true,
|
||||
"suite": true,
|
||||
"set": true,
|
||||
"before": true,
|
||||
"bench": true
|
||||
}
|
||||
}
|
||||
24
.npmignore
24
.npmignore
@@ -1,15 +1,15 @@
|
||||
node_modules
|
||||
*.log
|
||||
*.cache
|
||||
lib/6to5/transformation/templates
|
||||
test
|
||||
benchmark
|
||||
Makefile
|
||||
.*
|
||||
dist
|
||||
tests.json
|
||||
CHANGELOG.md
|
||||
.package.json
|
||||
coverage
|
||||
vendor
|
||||
packages
|
||||
/lib/babel/transformation/templates
|
||||
/test
|
||||
/benchmark
|
||||
/Makefile
|
||||
/dist
|
||||
/tests.json
|
||||
/CHANGELOG.md
|
||||
/.package.json
|
||||
/coverage
|
||||
/vendor
|
||||
/packages
|
||||
/src
|
||||
|
||||
12
.travis.yml
12
.travis.yml
@@ -1,13 +1,11 @@
|
||||
sudo: false
|
||||
#sudo: false
|
||||
language: node_js
|
||||
cache:
|
||||
directories:
|
||||
- node_modules
|
||||
node_js:
|
||||
- "0.10"
|
||||
- "0.11"
|
||||
- "0.12"
|
||||
|
||||
branches:
|
||||
except:
|
||||
- experimental
|
||||
- "iojs"
|
||||
|
||||
before_script: "npm install -g codeclimate-test-reporter"
|
||||
script: "make test-travis"
|
||||
|
||||
1093
CHANGELOG-6to5.md
Normal file
1093
CHANGELOG-6to5.md
Normal file
File diff suppressed because it is too large
Load Diff
1526
CHANGELOG.md
1526
CHANGELOG.md
File diff suppressed because it is too large
Load Diff
148
CONTRIBUTING.md
148
CONTRIBUTING.md
@@ -1,53 +1,169 @@
|
||||
<p align="center">
|
||||
<strong><a href="#setup">Setup</a></strong>
|
||||
|
|
||||
<strong><a href="#running-tests">Running tests</a></strong>
|
||||
|
|
||||
<strong><a href="#workflow">Workflow</a></strong>
|
||||
|
|
||||
<strong><a href="#dependencies">Dependencies</a></strong>
|
||||
|
|
||||
<strong><a href="#code-standards">Code Standards</a></strong>
|
||||
</p>
|
||||
|
||||
----
|
||||
|
||||
# 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).
|
||||
[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
|
||||
|
||||
#### Setup
|
||||
|
||||
```sh
|
||||
$ git clone https://github.com/babel/babel
|
||||
$ cd babel
|
||||
$ make bootstrap
|
||||
```
|
||||
|
||||
Then you can either run:
|
||||
|
||||
```sh
|
||||
$ make build-core
|
||||
```
|
||||
|
||||
to build Babel **once** or:
|
||||
|
||||
```sh
|
||||
$ make watch-core
|
||||
```
|
||||
|
||||
to have Babel build itself then incrementally build files on change.
|
||||
|
||||
#### Running tests
|
||||
|
||||
You can run tests via:
|
||||
|
||||
```sh
|
||||
$ make test
|
||||
```
|
||||
|
||||
This is mostly overkill and you can limit the tests to a select few by directly
|
||||
running them with `mocha`:
|
||||
|
||||
```sh
|
||||
$ mocha test/core/transformation.js
|
||||
```
|
||||
|
||||
Use mocha's `--grep` option to run a subset of tests by name:
|
||||
|
||||
```sh
|
||||
$ mocha test/core/transformation.js --grep es7
|
||||
```
|
||||
|
||||
If you don't have `mocha` installed globally, you can still use it from Babel's
|
||||
dependencies in `node_modules`, but make sure `node_modules/.bin` is added to
|
||||
your [`$PATH`](http://unix.stackexchange.com/questions/26047/how-to-correctly-add-a-path-to-path) environment variable.
|
||||
|
||||
|
||||
#### 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
|
||||
|
||||
|
||||
#### Dependencies
|
||||
|
||||
+ [ast-types](http://ghub.io/ast-types) This is required to monkeypatch regenerators AST definitions. Could be improved in the future.
|
||||
|
||||
+ [chalk](http://ghub.io/chalk) This is used for terminal color highlighting for syntax errors.
|
||||
|
||||
+ [convert-source-map](http://ghub.io/convert-source-map) Turns a source map object into a comment etc.
|
||||
|
||||
+ [core-js](http://ghub.io/core-js) Used for the polyfill.
|
||||
|
||||
+ [debug](http://ghub.io/debug) Used to output debugging information when NODE_DEBUG is set to babel.
|
||||
|
||||
+ [detect-indent](http://ghub.io/detect-indent) This is used in the code generator so it can infer indentation.
|
||||
|
||||
+ [estraverse](http://ghub.io/estraverse) The only method on this is attachComments. I'd like to implement our own comment attachment algorithm eventually though.
|
||||
|
||||
+ [esutils](http://ghub.io/esutils) Various ES related utilities. Check whether something is a keyword etc.
|
||||
|
||||
+ [fs-readdir-recursive](http://ghub.io/fs-readdir-recursive) Recursively search a directory for.
|
||||
|
||||
+ [globals](http://ghub.io/globals) A list of JavaScript global variables. This is used by the scope tracking to check for colliding variables.
|
||||
|
||||
+ [is-integer](http://ghub.io/is-integer) Checks if something is an integer.
|
||||
|
||||
+ [js-tokens](http://ghub.io/js-tokens) This is used to get tokens for syntax error highlighting.
|
||||
|
||||
+ [leven](http://ghub.io/leven) A levenstein algorithm to determine how close a word is to another. This is used to offer suggestions when using the utility.undeclaredVariableCheck transformer.
|
||||
|
||||
+ [line-numbers](http://ghub.io/line-numbers) Used to produce the code frames in syntax errors.
|
||||
|
||||
+ [lodash](http://ghub.io/lodash) Used for various utilities.
|
||||
|
||||
+ [minimatch](http://ghub.io/minimatch) This is used to match glob-style ignore/only filters.
|
||||
|
||||
+ [output-file-sync](http://ghub.io/output-file-sync) Synchronously writes a file and create its ancestor directories if needed.
|
||||
|
||||
+ [path-is-absolute](http://ghub.io/path-is-absolute) Checks if a path is absolute. C:\foo and \foo are considered absolute.
|
||||
|
||||
+ [regenerator](http://ghub.io/regenerator) This is used to transform generators/async functions.
|
||||
|
||||
+ [regexpu](http://ghub.io/regexpu) Used to transform unicode regex patterns.
|
||||
|
||||
+ [repeating](http://ghub.io/repeating) Repeats a string.
|
||||
|
||||
+ [shebang-regex](http://ghub.io/shebang-regex) Literally just a regex that matches shebangs.
|
||||
|
||||
+ [slash](http://ghub.io/slash) Normalises path separators.
|
||||
|
||||
+ [source-map](http://ghub.io/source-map) Generates sourcemaps.
|
||||
|
||||
+ [source-map-support](http://ghub.io/source-map-support) Adds source map support to babel-node/babel/register.
|
||||
|
||||
+ [strip-json-comments](http://ghub.io/strip-json-comments) Remove comments from a JSON string. This is used for .babelrc files.
|
||||
|
||||
+ [to-fast-properties](http://ghub.io/to-fast-properties) A V8 trick to put an object into fast properties mode.
|
||||
|
||||
+ [trim-right](http://ghub.io/trim-right) Trims the rightside whitespace.
|
||||
|
||||
+ [user-home](http://ghub.io/user-home) Gets the users home directory. This is used to resolve the babel-node/babel/register cache.
|
||||
|
||||
|
||||
#### Code Standards
|
||||
|
||||
* **General**
|
||||
* No ES6 syntax features or methods, exclusively ES5.
|
||||
* Max of five arguments for functions
|
||||
* Max depth of four nested blocks
|
||||
* 2-spaced soft tabs
|
||||
|
||||
* **Naming**
|
||||
* CamelCase all class names
|
||||
* camelBack all variable names
|
||||
|
||||
* **Spacing**
|
||||
* Spaces after all keywords
|
||||
* Spaces before all left curly braces
|
||||
|
||||
* **Comments**
|
||||
* Use JSDoc-style comments for methods
|
||||
* Single-line comments for ambiguous code
|
||||
|
||||
* **Quotes**
|
||||
* Always use double quotes
|
||||
* Only use single quotes when the string contains a double quote
|
||||
|
||||
* **Declaration**
|
||||
* No unused variables
|
||||
* No pollution of global variables and prototypes
|
||||
|
||||
## Testing
|
||||
|
||||
$ make test
|
||||
|
||||
## Linting
|
||||
|
||||
$ make lint
|
||||
|
||||
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
|
||||
|
||||
|
||||
93
Makefile
93
Makefile
@@ -1,77 +1,75 @@
|
||||
MAKEFLAGS = -j1
|
||||
BROWSERIFY_CMD = node_modules/browserify/bin/cmd.js
|
||||
ISTANBUL_CMD = node_modules/istanbul/lib/cli.js cover
|
||||
UGLIFY_CMD = node_modules/uglify-js/bin/uglifyjs
|
||||
#UGLIFY_CMD = node_modules/uglify-js/bin/uglifyjs --mangle sort
|
||||
JSHINT_CMD = node_modules/jshint/bin/jshint
|
||||
MOCHA_CMD = node_modules/mocha/bin/_mocha
|
||||
JSCS_CMD = node_modules/jscs/bin/jscs
|
||||
6TO5_CMD = node_modules/6to5/bin/6to5
|
||||
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 build-core watch-core
|
||||
.PHONY: clean test test-cov test-clean test-travis test-simple test-all test-browser test-parser publish build bootstrap publish-core publish-runtime build-core watch-core build-core-test clean-core
|
||||
|
||||
build-core:
|
||||
#node $(6TO5_CMD) src --out-dir lib
|
||||
build-core: clean-core
|
||||
node $(BABEL_CMD) src --out-dir lib --copy-files
|
||||
|
||||
watch-core:
|
||||
#node $(6TO5_CMD) src --out-dir lib --watch
|
||||
build-core-test: clean-core
|
||||
node $(BABEL_CMD) src --out-dir lib --copy-files --auxiliary-comment "istanbul ignore next"
|
||||
|
||||
watch-core: clean-core
|
||||
node $(BABEL_CMD) src --out-dir lib --watch --copy-files
|
||||
|
||||
clean-core:
|
||||
rm -rf lib
|
||||
|
||||
build:
|
||||
mkdir -p dist
|
||||
make build-core
|
||||
|
||||
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/api/browser.js -s to5 >dist/6to5.js
|
||||
node $(UGLIFY_CMD) dist/6to5.js >dist/6to5.min.js
|
||||
node $(BROWSERIFY_CMD) lib/babel/api/browser.js -s babel >dist/babel.js
|
||||
node $(UGLIFY_CMD) dist/babel.js >dist/babel.min.js
|
||||
|
||||
node bin/6to5-runtime >dist/runtime.js
|
||||
node $(UGLIFY_CMD) dist/runtime.js >dist/runtime.min.js
|
||||
node packages/babel-cli/bin/babel-external-helpers >dist/external-helpers.js
|
||||
node $(UGLIFY_CMD) dist/external-helpers.js >dist/external-helpers.min.js
|
||||
|
||||
rm -rf templates.json
|
||||
|
||||
clean:
|
||||
rm -rf coverage templates.json test/tmp dist
|
||||
|
||||
lint:
|
||||
$(JSHINT_CMD) --reporter node_modules/jshint-stylish/stylish.js lib bin
|
||||
$(JSCS_CMD) lib bin
|
||||
rm -rf coverage templates.json test/tmp dist lib
|
||||
|
||||
test-clean:
|
||||
rm -rf test/tmp
|
||||
|
||||
test: lint
|
||||
$(MOCHA_CMD)
|
||||
test: test-parser
|
||||
node $(MOCHA_CMD) test/core
|
||||
make test-clean
|
||||
|
||||
test-simple:
|
||||
# excludes test262
|
||||
export SIMPLE_6TO5_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; \
|
||||
node $(ISTANBUL_CMD) $(MOCHA_CMD) --
|
||||
make build-core-test
|
||||
node $(ISTANBUL_CMD) $(MOCHA_CMD) -- test/core
|
||||
|
||||
test-travis: build-core bootstrap
|
||||
node $(ISTANBUL_CMD) $(MOCHA_CMD) --
|
||||
if test -n "$$CODECLIMATE_REPO_TOKEN"; then codeclimate < coverage/lcov.info; fi
|
||||
test-parser:
|
||||
node test/acorn/run.js
|
||||
|
||||
test-travis: bootstrap build test
|
||||
|
||||
test-browser:
|
||||
mkdir -p dist
|
||||
|
||||
node tools/cache-templates
|
||||
node tools/cache-tests
|
||||
node $(BROWSERIFY_CMD) -e test/_browser.js >dist/6to5-test.js
|
||||
node tools/build-tests
|
||||
node $(BROWSERIFY_CMD) -e test/core/_browser.js >dist/babel-test.js
|
||||
rm -rf templates.json tests.json
|
||||
|
||||
test -n "`which open`" && open test/browser.html
|
||||
@@ -85,9 +83,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/runtime.min.js runtime.js
|
||||
cp dist/external-helpers.min.js external-helpers.js
|
||||
|
||||
node tools/cache-templates
|
||||
test -f templates.json
|
||||
@@ -96,29 +94,28 @@ publish:
|
||||
|
||||
git push --follow-tags
|
||||
|
||||
make publish-core
|
||||
make publish-cli
|
||||
make publish-runtime
|
||||
|
||||
rm -rf templates.json browser.js browser-polyfill.js runtime.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:
|
||||
tools/generate-core-package-json >package2.json
|
||||
mv package.json .package.json
|
||||
mv package2.json package.json
|
||||
|
||||
publish-cli:
|
||||
cd packages; \
|
||||
node build-cli.js; \
|
||||
cd babel-cli; \
|
||||
npm publish
|
||||
|
||||
rm -rf package.json
|
||||
mv .package.json package.json
|
||||
|
||||
bootstrap:
|
||||
npm list --global --depth 1 babel >/dev/null 2>&1 && npm uninstall -g babel || true
|
||||
npm install
|
||||
npm link
|
||||
cd packages/babel-cli && npm install && npm link && npm link babel-core
|
||||
git submodule update --init
|
||||
cd vendor/regenerator; npm install
|
||||
cd vendor/compat-table; npm install object-assign
|
||||
cd vendor/compat-table && npm install object-assign
|
||||
make build
|
||||
|
||||
3
NOTES.md
3
NOTES.md
@@ -1,3 +0,0 @@
|
||||
# Notes
|
||||
|
||||
* Wildcard exports/imports wont normalize if `export default` is a non-object. See [#224](https://github.com/6to5/6to5/issues/224).
|
||||
13
README.md
13
README.md
@@ -1,12 +1,17 @@
|
||||
<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 compiler 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 questions and support please visit the <a href="https://gitter.im/babel/babel">gitter room</a> or <a href="http://stackoverflow.com/questions/tagged/babeljs">StackOverflow</a>. The Babel issue tracker is <strong>exclusively</strong> for bug reports and feature requests.
|
||||
</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>
|
||||
|
||||
@@ -1,7 +0,0 @@
|
||||
#!/usr/bin/env node
|
||||
|
||||
var opts = require("./6to5").opts;
|
||||
opts.optional = (opts.optional || []).concat("minification");
|
||||
opts.format = {
|
||||
compact: true
|
||||
};
|
||||
@@ -1,69 +0,0 @@
|
||||
#!/usr/bin/env node
|
||||
|
||||
/**
|
||||
* This tiny wrapper file checks for known node flags and appends them
|
||||
* when found, before invoking the "real" _6to5-node(1) executable.
|
||||
*/
|
||||
|
||||
var args = [__dirname + "/_6to5-node"];
|
||||
|
||||
process.argv.slice(2).forEach(function(arg){
|
||||
var flag = arg.split("=")[0];
|
||||
|
||||
switch (flag) {
|
||||
case "-d":
|
||||
args.unshift("--debug");
|
||||
break;
|
||||
|
||||
case "debug":
|
||||
case "--debug":
|
||||
case "--debug-brk":
|
||||
args.unshift(arg);
|
||||
break;
|
||||
|
||||
case "-gc":
|
||||
case "--expose-gc":
|
||||
args.unshift("--expose-gc");
|
||||
break;
|
||||
|
||||
case "--gc-global":
|
||||
case "--harmony":
|
||||
case "--harmony-proxies":
|
||||
case "--harmony-collections":
|
||||
case "--harmony-generators":
|
||||
case "--no-deprecation":
|
||||
case "--prof":
|
||||
case "--throw-deprecation":
|
||||
case "--trace-deprecation":
|
||||
case "--use-strict":
|
||||
args.unshift(arg);
|
||||
break;
|
||||
|
||||
default:
|
||||
if (arg.indexOf("--trace") === 0) {
|
||||
args.unshift(arg);
|
||||
} else {
|
||||
args.push(arg);
|
||||
}
|
||||
break;
|
||||
}
|
||||
});
|
||||
|
||||
try {
|
||||
var kexec = require("kexec");
|
||||
kexec(process.argv[0], args);
|
||||
} catch (err) {
|
||||
if (err.code !== "MODULE_NOT_FOUND") throw err;
|
||||
|
||||
var child_process = require("child_process");
|
||||
var proc = child_process.spawn(process.argv[0], args, { stdio: "inherit" });
|
||||
proc.on("exit", function (code, signal) {
|
||||
process.on("exit", function () {
|
||||
if (signal) {
|
||||
process.kill(process.pid, signal);
|
||||
} else {
|
||||
process.exit(code);
|
||||
}
|
||||
})
|
||||
});
|
||||
}
|
||||
@@ -1,4 +0,0 @@
|
||||
#!/usr/bin/env node
|
||||
|
||||
var runtime = require("../lib/6to5/build-runtime");
|
||||
console.log(runtime());
|
||||
@@ -1,130 +0,0 @@
|
||||
#!/usr/bin/env node
|
||||
|
||||
var commander = require("commander");
|
||||
var transform = require("../../lib/6to5/transformation");
|
||||
var util = require("../../lib/6to5/util");
|
||||
var fs = require("fs");
|
||||
var each = require("lodash/collection/each");
|
||||
var keys = require("lodash/object/keys");
|
||||
|
||||
commander.option("-t, --source-maps-inline", "Append sourceMappingURL comment to bottom of code");
|
||||
commander.option("-s, --source-maps", "Save source map alongside the compiled code");
|
||||
commander.option("-f, --filename [filename]", "Filename to use when reading from stdin - this will be used in source-maps, errors etc [stdin]", "stdin");
|
||||
commander.option("-w, --watch", "Recompile files on changes");
|
||||
commander.option("-r, --runtime", "Replace 6to5 declarations with references to a runtime");
|
||||
commander.option("-e, --experimental", "Enable experimental support for proposed ES7 features");
|
||||
commander.option("-p, --playground", "Enable playground support");
|
||||
|
||||
commander.option("-m, --modules [modules]", "Module formatter type to use [common]", "common");
|
||||
commander.option("-l, --whitelist [whitelist]", "Whitelist of transformers to ONLY use", util.list);
|
||||
commander.option("-b, --blacklist [blacklist]", "Blacklist of transformers to NOT use", util.list);
|
||||
commander.option("-i, --optional [list]", "List of optional transformers to enable", util.list);
|
||||
commander.option("-L, --loose [list]", "List of transformers to enable loose mode ON", util.list);
|
||||
commander.option("-o, --out-file [out]", "Compile all input files into a single file");
|
||||
commander.option("-d, --out-dir [out]", "Compile an input directory of modules into an output directory");
|
||||
commander.option("-c, --remove-comments", "Remove comments from the compiled code", false);
|
||||
commander.option("-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.on("--help", function () {
|
||||
var outKeys = function (title, obj) {
|
||||
console.log(" " + title + ":");
|
||||
console.log();
|
||||
|
||||
each(keys(obj).sort(), function (key) {
|
||||
if (key[0] === "_") return;
|
||||
|
||||
if (obj[key].optional) {
|
||||
key = "[" + key + "]";
|
||||
}
|
||||
|
||||
console.log(" - " + key);
|
||||
});
|
||||
|
||||
console.log();
|
||||
};
|
||||
|
||||
outKeys("Transformers", transform.transformers);
|
||||
outKeys("Module formatters", transform.moduleFormatters);
|
||||
});
|
||||
|
||||
var pkg = require("../../package.json");
|
||||
commander.version(pkg.version);
|
||||
commander.usage("[options] <files ...>");
|
||||
commander.parse(process.argv);
|
||||
|
||||
//
|
||||
|
||||
var errors = [];
|
||||
|
||||
var filenames = commander.args;
|
||||
|
||||
each(filenames, function (filename) {
|
||||
if (!fs.existsSync(filename)) {
|
||||
errors.push(filename + " doesn't exist");
|
||||
}
|
||||
});
|
||||
|
||||
if (commander.outDir && !filenames.length) {
|
||||
errors.push("filenames required for --out-dir");
|
||||
}
|
||||
|
||||
if (commander.outFile && commander.outDir) {
|
||||
errors.push("cannot have --out-file and --out-dir");
|
||||
}
|
||||
|
||||
if (commander.watch) {
|
||||
if (!commander.outFile && !commander.outDir) {
|
||||
errors.push("--watch requires --out-file or --out-dir");
|
||||
}
|
||||
|
||||
if (!filenames.length) {
|
||||
errors.push("--watch requires filenames");
|
||||
}
|
||||
}
|
||||
|
||||
if (commander.sourceMaps) {
|
||||
if (!commander.outFile && !commander.outDir) {
|
||||
errors.push("--source-maps requires --out-file or --out-dir");
|
||||
}
|
||||
}
|
||||
|
||||
if (errors.length) {
|
||||
console.error(errors.join(". "));
|
||||
process.exit(2);
|
||||
}
|
||||
|
||||
//
|
||||
|
||||
exports.opts = {
|
||||
keepModuleIdExtensions: commander.keepModuleIdExtensions,
|
||||
sourceMapName: commander.outFile,
|
||||
experimental: commander.experimental,
|
||||
reactCompat: commander.reactCompat,
|
||||
playground: commander.playground,
|
||||
moduleIds: commander.moduleIds,
|
||||
blacklist: commander.blacklist,
|
||||
whitelist: commander.whitelist,
|
||||
sourceMap: commander.sourceMaps || commander.sourceMapsInline,
|
||||
optional: commander.optional,
|
||||
comments: !commander.removeComments,
|
||||
runtime: commander.runtime,
|
||||
modules: commander.modules,
|
||||
loose: commander.loose
|
||||
};
|
||||
|
||||
setTimeout(function () {
|
||||
// this is just a hack to give `6to5-minify` and other files including this
|
||||
// time to modify `exports.opts`
|
||||
|
||||
var fn;
|
||||
|
||||
if (commander.outDir) {
|
||||
fn = require("./dir");
|
||||
} else {
|
||||
fn = require("./file");
|
||||
}
|
||||
|
||||
fn(commander, filenames, exports.opts);
|
||||
}, 0);
|
||||
@@ -1 +0,0 @@
|
||||
See [6to5.github.io/docs](https://github.com/6to5/6to5.github.io/tree/master/docs).
|
||||
@@ -1,58 +0,0 @@
|
||||
"use strict";
|
||||
|
||||
var isFunction = require("lodash/lang/isFunction");
|
||||
var transform = require("../transformation");
|
||||
var util = require("../util");
|
||||
var fs = require("fs");
|
||||
|
||||
exports.version = require("../../../package").version;
|
||||
|
||||
exports.runtime = require("../build-runtime");
|
||||
|
||||
exports.types = require("../types");
|
||||
|
||||
exports.register = function (opts) {
|
||||
var register = require("./register/node");
|
||||
if (opts != null) register(opts);
|
||||
return register;
|
||||
};
|
||||
|
||||
exports.polyfill = function () {
|
||||
require("../polyfill");
|
||||
};
|
||||
|
||||
exports.canCompile = util.canCompile;
|
||||
|
||||
// do not use this - this is for use by official maintained 6to5 plugins
|
||||
exports._util = util;
|
||||
|
||||
exports.transform = transform;
|
||||
|
||||
exports.transformFile = function (filename, opts, callback) {
|
||||
if (isFunction(opts)) {
|
||||
callback = opts;
|
||||
opts = {};
|
||||
}
|
||||
|
||||
opts.filename = filename;
|
||||
|
||||
fs.readFile(filename, function (err, code) {
|
||||
if (err) return callback(err);
|
||||
|
||||
var result;
|
||||
|
||||
try {
|
||||
result = transform(code, opts);
|
||||
} catch (err) {
|
||||
return callback(err);
|
||||
}
|
||||
|
||||
callback(null, result);
|
||||
});
|
||||
};
|
||||
|
||||
exports.transformFileSync = function (filename, opts) {
|
||||
opts = opts || {};
|
||||
opts.filename = filename;
|
||||
return transform(fs.readFileSync(filename), opts);
|
||||
};
|
||||
@@ -1,7 +0,0 @@
|
||||
"use strict";
|
||||
|
||||
// required to safely use 6to5/register within a browserify codebase
|
||||
|
||||
module.exports = function () {};
|
||||
|
||||
require("../../polyfill");
|
||||
@@ -1,36 +0,0 @@
|
||||
"use strict";
|
||||
|
||||
var path = require("path");
|
||||
var os = require("os");
|
||||
var fs = require("fs");
|
||||
|
||||
var FILENAME = path.join(os.tmpdir(), "6to5.json");
|
||||
var data = {};
|
||||
|
||||
exports.save = function () {
|
||||
fs.writeFileSync(FILENAME, JSON.stringify(data, null, " "));
|
||||
};
|
||||
|
||||
exports.load = function () {
|
||||
process.on("exit", exports.save);
|
||||
|
||||
var sigint = function () {
|
||||
process.removeListener("SIGINT", sigint);
|
||||
exports.save();
|
||||
process.kill(process.pid, "SIGINT");
|
||||
};
|
||||
|
||||
process.on("SIGINT", sigint);
|
||||
|
||||
if (!fs.existsSync(FILENAME)) return;
|
||||
|
||||
try {
|
||||
data = JSON.parse(fs.readFileSync(FILENAME));
|
||||
} catch (err) {
|
||||
return;
|
||||
}
|
||||
};
|
||||
|
||||
exports.get = function () {
|
||||
return data;
|
||||
};
|
||||
@@ -1,13 +0,0 @@
|
||||
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))
|
||||
));
|
||||
});
|
||||
};
|
||||
@@ -1,25 +0,0 @@
|
||||
"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("to5Runtime");
|
||||
|
||||
var body = [];
|
||||
var container = t.functionExpression(null, [t.identifier("global")], t.blockStatement(body));
|
||||
var tree = t.program([t.expressionStatement(t.callExpression(container, [util.template("self-global")]))]);
|
||||
|
||||
body.push(t.variableDeclaration("var", [
|
||||
t.variableDeclarator(
|
||||
namespace,
|
||||
t.assignmentExpression("=", t.memberExpression(t.identifier("global"), namespace), t.objectExpression([]))
|
||||
)
|
||||
]));
|
||||
|
||||
buildHelpers(body, namespace);
|
||||
|
||||
return generator(tree).code;
|
||||
};
|
||||
@@ -1,29 +0,0 @@
|
||||
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;
|
||||
}
|
||||
@@ -1,84 +0,0 @@
|
||||
{
|
||||
"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"
|
||||
}
|
||||
@@ -1,54 +0,0 @@
|
||||
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");
|
||||
}
|
||||
};
|
||||
@@ -1,166 +0,0 @@
|
||||
"use strict";
|
||||
|
||||
module.exports = Buffer;
|
||||
|
||||
var isBoolean = require("lodash/lang/isBoolean");
|
||||
var includes = require("lodash/collection/includes");
|
||||
var isNumber = require("lodash/lang/isNumber");
|
||||
var util = require("../util");
|
||||
|
||||
function Buffer(position, format) {
|
||||
this.position = position;
|
||||
this._indent = format.indent.base;
|
||||
this.format = format;
|
||||
this.buf = "";
|
||||
}
|
||||
|
||||
Buffer.prototype.get = function () {
|
||||
return util.trimRight(this.buf);
|
||||
};
|
||||
|
||||
Buffer.prototype.getIndent = function () {
|
||||
if (this.format.compact || this.format.concise) {
|
||||
return "";
|
||||
} else {
|
||||
return util.repeat(this._indent, this.format.indent.style);
|
||||
}
|
||||
};
|
||||
|
||||
Buffer.prototype.indentSize = function () {
|
||||
return this.getIndent().length;
|
||||
};
|
||||
|
||||
Buffer.prototype.indent = function () {
|
||||
this._indent++;
|
||||
};
|
||||
|
||||
Buffer.prototype.dedent = function () {
|
||||
this._indent--;
|
||||
};
|
||||
|
||||
Buffer.prototype.semicolon = function () {
|
||||
this.push(";");
|
||||
};
|
||||
|
||||
Buffer.prototype.ensureSemicolon = function () {
|
||||
if (!this.isLast(";")) this.semicolon();
|
||||
};
|
||||
|
||||
Buffer.prototype.rightBrace = function () {
|
||||
this.newline(true);
|
||||
this.push("}");
|
||||
};
|
||||
|
||||
Buffer.prototype.keyword = function (name) {
|
||||
this.push(name);
|
||||
this.space();
|
||||
};
|
||||
|
||||
Buffer.prototype.space = function () {
|
||||
if (this.format.compact) return;
|
||||
|
||||
if (this.buf && !this.isLast([" ", "\n"])) {
|
||||
this.push(" ");
|
||||
}
|
||||
};
|
||||
|
||||
Buffer.prototype.removeLast = function (cha) {
|
||||
if (!this.isLast(cha)) return;
|
||||
|
||||
this.buf = this.buf.substr(0, this.buf.length - 1);
|
||||
this.position.unshift(cha);
|
||||
};
|
||||
|
||||
Buffer.prototype.newline = function (i, removeLast) {
|
||||
if (this.format.compact || 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;
|
||||
|
||||
while (i--) {
|
||||
this._newline(removeLast);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (isBoolean(i)) {
|
||||
removeLast = i;
|
||||
}
|
||||
|
||||
this._newline(removeLast);
|
||||
};
|
||||
|
||||
Buffer.prototype._newline = function (removeLast) {
|
||||
if (removeLast && this.isLast("\n")) this.removeLast("\n");
|
||||
|
||||
this.removeLast(" ");
|
||||
|
||||
// remove whitespace if last character was a newline
|
||||
this._removeSpacesAfterLastNewline();
|
||||
this._push("\n");
|
||||
};
|
||||
|
||||
/**
|
||||
* 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)
|
||||
return;
|
||||
|
||||
var index = this.buf.length - 1;
|
||||
while (index > lastNewlineIndex) {
|
||||
if (this.buf[index] !== " ") {
|
||||
break;
|
||||
}
|
||||
|
||||
index--;
|
||||
}
|
||||
|
||||
if (index === lastNewlineIndex) {
|
||||
this.buf = this.buf.substring(0, index + 1);
|
||||
}
|
||||
};
|
||||
|
||||
Buffer.prototype.push = function (str, noIndent) {
|
||||
if (this._indent && !noIndent && str !== "\n") {
|
||||
// we have an indent level and we aren't pushing a newline
|
||||
var indent = this.getIndent();
|
||||
|
||||
// replace all newlines with newlines with the indentation
|
||||
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;
|
||||
}
|
||||
|
||||
this._push(str);
|
||||
};
|
||||
|
||||
Buffer.prototype._push = function (str) {
|
||||
this.position.push(str);
|
||||
this.buf += str;
|
||||
};
|
||||
|
||||
Buffer.prototype.endsWith = function (str) {
|
||||
var d = this.buf.length - str.length;
|
||||
return d >= 0 && this.buf.lastIndexOf(str) === d;
|
||||
};
|
||||
|
||||
Buffer.prototype.isLast = function (cha, trimRight) {
|
||||
var buf = this.buf;
|
||||
if (trimRight) buf = util.trimRight(buf);
|
||||
var last = buf[buf.length - 1];
|
||||
|
||||
if (Array.isArray(cha)) {
|
||||
return includes(cha, last);
|
||||
} else {
|
||||
return cha === last;
|
||||
}
|
||||
};
|
||||
@@ -1,42 +0,0 @@
|
||||
"use strict";
|
||||
|
||||
exports.ClassExpression =
|
||||
exports.ClassDeclaration = function (node, print) {
|
||||
this.push("class");
|
||||
|
||||
if (node.id) {
|
||||
this.space();
|
||||
print(node.id);
|
||||
}
|
||||
|
||||
if (node.superClass) {
|
||||
this.push(" extends ");
|
||||
print(node.superClass);
|
||||
}
|
||||
|
||||
this.space();
|
||||
print(node.body);
|
||||
};
|
||||
|
||||
exports.ClassBody = function (node, print) {
|
||||
if (node.body.length === 0) {
|
||||
this.push("{}");
|
||||
} else {
|
||||
this.push("{");
|
||||
this.newline();
|
||||
|
||||
this.indent();
|
||||
print.sequence(node.body);
|
||||
this.dedent();
|
||||
|
||||
this.rightBrace();
|
||||
}
|
||||
};
|
||||
|
||||
exports.MethodDefinition = function (node, print) {
|
||||
if (node.static) {
|
||||
this.push("static ");
|
||||
}
|
||||
|
||||
this._method(node, print);
|
||||
};
|
||||
@@ -1,35 +0,0 @@
|
||||
"use strict";
|
||||
|
||||
exports.AnyTypeAnnotation =
|
||||
exports.ArrayTypeAnnotation =
|
||||
exports.BooleanTypeAnnotation =
|
||||
exports.ClassProperty =
|
||||
exports.DeclareClass =
|
||||
exports.DeclareFunction =
|
||||
exports.DeclareModule =
|
||||
exports.DeclareVariable =
|
||||
exports.FunctionTypeAnnotation =
|
||||
exports.FunctionTypeParam =
|
||||
exports.GenericTypeAnnotation =
|
||||
exports.InterfaceExtends =
|
||||
exports.InterfaceDeclaration =
|
||||
exports.IntersectionTypeAnnotation =
|
||||
exports.NullableTypeAnnotation =
|
||||
exports.NumberTypeAnnotation =
|
||||
exports.StringLiteralTypeAnnotation =
|
||||
exports.StringTypeAnnotation =
|
||||
exports.TupleTypeAnnotation =
|
||||
exports.TypeofTypeAnnotation =
|
||||
exports.TypeAlias =
|
||||
exports.TypeAnnotation =
|
||||
exports.TypeParameterDeclaration =
|
||||
exports.TypeParameterInstantiation =
|
||||
exports.ObjectTypeAnnotation =
|
||||
exports.ObjectTypeCallProperty =
|
||||
exports.ObjectTypeIndexer =
|
||||
exports.ObjectTypeProperty =
|
||||
exports.QualifiedTypeIdentifier =
|
||||
exports.UnionTypeAnnotation =
|
||||
exports.VoidTypeAnnotation = function () {
|
||||
// todo: implement these once we have a `--keep-types` option
|
||||
};
|
||||
@@ -1,98 +0,0 @@
|
||||
"use strict";
|
||||
|
||||
var t = require("../../types");
|
||||
var each = require("lodash/collection/each");
|
||||
|
||||
exports.ImportSpecifier = function (node, print) {
|
||||
if (t.isSpecifierDefault(node)) {
|
||||
print(t.getSpecifierName(node));
|
||||
} else {
|
||||
return exports.ExportSpecifier.apply(this, arguments);
|
||||
}
|
||||
};
|
||||
|
||||
exports.ExportSpecifier = function (node, print) {
|
||||
print(node.id);
|
||||
if (node.name) {
|
||||
this.push(" as ");
|
||||
print(node.name);
|
||||
}
|
||||
};
|
||||
|
||||
exports.ExportBatchSpecifier = function () {
|
||||
this.push("*");
|
||||
};
|
||||
|
||||
exports.ExportDeclaration = function (node, print) {
|
||||
this.push("export ");
|
||||
|
||||
var specifiers = node.specifiers;
|
||||
|
||||
if (node.default) {
|
||||
this.push("default ");
|
||||
}
|
||||
|
||||
if (node.declaration) {
|
||||
print(node.declaration);
|
||||
if (t.isStatement(node.declaration)) return;
|
||||
} else {
|
||||
if (specifiers.length === 1 && t.isExportBatchSpecifier(specifiers[0])) {
|
||||
print(specifiers[0]);
|
||||
} else {
|
||||
this.push("{");
|
||||
if (specifiers.length) {
|
||||
this.space();
|
||||
print.join(specifiers, { separator: ", " });
|
||||
this.space();
|
||||
}
|
||||
this.push("}");
|
||||
}
|
||||
|
||||
if (node.source) {
|
||||
this.push(" from ");
|
||||
print(node.source);
|
||||
}
|
||||
}
|
||||
|
||||
this.ensureSemicolon();
|
||||
};
|
||||
|
||||
exports.ImportDeclaration = function (node, print) {
|
||||
var self = this;
|
||||
|
||||
this.push("import ");
|
||||
|
||||
var specfiers = node.specifiers;
|
||||
if (specfiers && specfiers.length) {
|
||||
var foundImportSpecifier = false;
|
||||
|
||||
each(node.specifiers, function (spec, i) {
|
||||
if (+i > 0) {
|
||||
self.push(", ");
|
||||
}
|
||||
|
||||
var isDefault = t.isSpecifierDefault(spec);
|
||||
|
||||
if (!isDefault && spec.type !== "ImportBatchSpecifier" && !foundImportSpecifier) {
|
||||
foundImportSpecifier = true;
|
||||
self.push("{ ");
|
||||
}
|
||||
|
||||
print(spec);
|
||||
});
|
||||
|
||||
if (foundImportSpecifier) {
|
||||
this.push(" }");
|
||||
}
|
||||
|
||||
this.push(" from ");
|
||||
}
|
||||
|
||||
print(node.source);
|
||||
this.semicolon();
|
||||
};
|
||||
|
||||
exports.ImportBatchSpecifier = function (node, print) {
|
||||
this.push("* as ");
|
||||
print(node.name);
|
||||
};
|
||||
@@ -1,9 +0,0 @@
|
||||
"use strict";
|
||||
|
||||
var each = require("lodash/collection/each");
|
||||
|
||||
each(["BindMemberExpression", "BindFunctionExpression"], function (type) {
|
||||
exports[type] = function () {
|
||||
throw new ReferenceError("Trying to render non-standard playground node " + JSON.stringify(type));
|
||||
};
|
||||
});
|
||||
@@ -1,32 +0,0 @@
|
||||
"use strict";
|
||||
|
||||
var each = require("lodash/collection/each");
|
||||
|
||||
exports.TaggedTemplateExpression = function (node, print) {
|
||||
print(node.tag);
|
||||
print(node.quasi);
|
||||
};
|
||||
|
||||
exports.TemplateElement = function (node) {
|
||||
this._push(node.value.raw);
|
||||
};
|
||||
|
||||
exports.TemplateLiteral = function (node, print) {
|
||||
this.push("`");
|
||||
|
||||
var quasis = node.quasis;
|
||||
var self = this;
|
||||
var len = quasis.length;
|
||||
|
||||
each(quasis, function (quasi, i) {
|
||||
print(quasi);
|
||||
|
||||
if (i + 1 < len) {
|
||||
self.push("${ ");
|
||||
print(node.expressions[i]);
|
||||
self.push(" }");
|
||||
}
|
||||
});
|
||||
|
||||
this._push("`");
|
||||
};
|
||||
@@ -1,361 +0,0 @@
|
||||
"use strict";
|
||||
|
||||
module.exports = function (ast, opts, code) {
|
||||
var gen = new CodeGenerator(ast, opts, code);
|
||||
return gen.generate();
|
||||
};
|
||||
|
||||
module.exports.CodeGenerator = CodeGenerator;
|
||||
|
||||
var detectIndent = require("detect-indent");
|
||||
var Whitespace = require("./whitespace");
|
||||
var SourceMap = require("./source-map");
|
||||
var Position = require("./position");
|
||||
var Buffer = require("./buffer");
|
||||
var extend = require("lodash/object/extend");
|
||||
var merge = require("lodash/object/merge");
|
||||
var each = require("lodash/collection/each");
|
||||
var util = require("../util");
|
||||
var n = require("./node");
|
||||
var t = require("../types");
|
||||
|
||||
function CodeGenerator(ast, opts, code) {
|
||||
opts = opts || {};
|
||||
|
||||
this.comments = ast.comments || [];
|
||||
this.tokens = ast.tokens || [];
|
||||
this.format = CodeGenerator.normalizeOptions(code, opts);
|
||||
this.opts = opts;
|
||||
this.ast = ast;
|
||||
|
||||
this.whitespace = new Whitespace(this.tokens, this.comments);
|
||||
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) {
|
||||
CodeGenerator.prototype[key] = function () {
|
||||
return fn.apply(this.buffer, arguments);
|
||||
};
|
||||
});
|
||||
|
||||
CodeGenerator.normalizeOptions = function (code, opts) {
|
||||
var style = " ";
|
||||
if (code) {
|
||||
var indent = detectIndent(code).indent;
|
||||
if (indent && indent !== " ") style = indent;
|
||||
}
|
||||
|
||||
return merge({
|
||||
parentheses: true,
|
||||
comments: opts.comments == null || opts.comments,
|
||||
compact: false,
|
||||
concise: false,
|
||||
indent: {
|
||||
adjustMultilineComment: true,
|
||||
style: style,
|
||||
base: 0
|
||||
}
|
||||
}, opts.format || {});
|
||||
};
|
||||
|
||||
CodeGenerator.generators = {
|
||||
templateLiterals: require("./generators/template-literals"),
|
||||
comprehensions: require("./generators/comprehensions"),
|
||||
expressions: require("./generators/expressions"),
|
||||
statements: require("./generators/statements"),
|
||||
playground: require("./generators/playground"),
|
||||
classes: require("./generators/classes"),
|
||||
methods: require("./generators/methods"),
|
||||
modules: require("./generators/modules"),
|
||||
types: require("./generators/types"),
|
||||
flow: require("./generators/flow"),
|
||||
base: require("./generators/base"),
|
||||
jsx: require("./generators/jsx")
|
||||
};
|
||||
|
||||
each(CodeGenerator.generators, function (generator) {
|
||||
extend(CodeGenerator.prototype, generator);
|
||||
});
|
||||
|
||||
CodeGenerator.prototype.generate = function () {
|
||||
var ast = this.ast;
|
||||
|
||||
this.print(ast);
|
||||
|
||||
var comments = [];
|
||||
each(ast.comments, function (comment) {
|
||||
if (!comment._displayed) comments.push(comment);
|
||||
});
|
||||
this._printComments(comments);
|
||||
|
||||
return {
|
||||
map: this.map.get(),
|
||||
code: this.buffer.get()
|
||||
};
|
||||
};
|
||||
|
||||
CodeGenerator.prototype.buildPrint = function (parent) {
|
||||
var self = this;
|
||||
|
||||
var print = function (node, opts) {
|
||||
return self.print(node, parent, opts);
|
||||
};
|
||||
|
||||
print.sequence = function (nodes, opts) {
|
||||
opts = opts || {};
|
||||
opts.statement = true;
|
||||
return self.printJoin(print, nodes, opts);
|
||||
};
|
||||
|
||||
print.join = function (nodes, opts) {
|
||||
return self.printJoin(print, nodes, opts);
|
||||
};
|
||||
|
||||
print.list = function (items, opts) {
|
||||
opts = opts || {};
|
||||
|
||||
var sep = opts.separator || ", ";
|
||||
if (self.format.compact) sep = ",";
|
||||
opts.separator = sep;
|
||||
|
||||
print.join(items, opts);
|
||||
};
|
||||
|
||||
print.block = function (node) {
|
||||
return self.printBlock(print, node);
|
||||
};
|
||||
|
||||
print.indentOnComments = function (node) {
|
||||
return self.printAndIndentOnComments(print, node);
|
||||
};
|
||||
|
||||
return print;
|
||||
};
|
||||
|
||||
CodeGenerator.prototype.print = function (node, parent, opts) {
|
||||
if (!node) return "";
|
||||
|
||||
if (parent && parent._compact) {
|
||||
node._compact = true;
|
||||
}
|
||||
|
||||
var oldConcise = this.format.concise;
|
||||
if (node._compact) {
|
||||
this.format.concise = true;
|
||||
}
|
||||
|
||||
var self = this;
|
||||
|
||||
opts = opts || {};
|
||||
|
||||
var newline = function (leading) {
|
||||
if (!opts.statement && !n.isUserWhitespacable(node, parent)) {
|
||||
return;
|
||||
}
|
||||
|
||||
var lines = 0;
|
||||
|
||||
if (node.start != null && !node._ignoreUserWhitespace) {
|
||||
// user node
|
||||
if (leading) {
|
||||
lines = self.whitespace.getNewlinesBefore(node);
|
||||
} else {
|
||||
lines = self.whitespace.getNewlinesAfter(node);
|
||||
}
|
||||
} else {
|
||||
// generated node
|
||||
if (!leading) lines++; // always include at least a single line after
|
||||
|
||||
var needs = n.needsWhitespaceAfter;
|
||||
if (leading) needs = n.needsWhitespaceBefore;
|
||||
lines += needs(node, parent);
|
||||
|
||||
// generated nodes can't add starting file whitespace
|
||||
if (!self.buffer.get()) lines = 0;
|
||||
}
|
||||
|
||||
self.newline(lines);
|
||||
};
|
||||
|
||||
if (this[node.type]) {
|
||||
var needsNoLineTermParens = n.needsParensNoLineTerminator(node, parent);
|
||||
var needsParens = needsNoLineTermParens || n.needsParens(node, parent);
|
||||
|
||||
if (needsParens) this.push("(");
|
||||
if (needsNoLineTermParens) this.indent();
|
||||
|
||||
this.printLeadingComments(node, parent);
|
||||
|
||||
newline(true);
|
||||
|
||||
if (opts.before) opts.before();
|
||||
this.map.mark(node, "start");
|
||||
|
||||
this[node.type](node, this.buildPrint(node), parent);
|
||||
|
||||
if (needsNoLineTermParens) {
|
||||
this.newline();
|
||||
this.dedent();
|
||||
}
|
||||
if (needsParens) this.push(")");
|
||||
|
||||
this.map.mark(node, "end");
|
||||
if (opts.after) opts.after();
|
||||
|
||||
newline(false);
|
||||
|
||||
this.printTrailingComments(node, parent);
|
||||
} else {
|
||||
throw new ReferenceError("unknown node of type " + JSON.stringify(node.type) + " with constructor " + JSON.stringify(node && node.constructor.name));
|
||||
}
|
||||
|
||||
this.format.concise = oldConcise;
|
||||
};
|
||||
|
||||
CodeGenerator.prototype.printJoin = function (print, nodes, opts) {
|
||||
if (!nodes || !nodes.length) return;
|
||||
|
||||
opts = opts || {};
|
||||
|
||||
var self = this;
|
||||
var len = nodes.length;
|
||||
|
||||
if (opts.indent) self.indent();
|
||||
|
||||
each(nodes, function (node, i) {
|
||||
print(node, {
|
||||
statement: opts.statement,
|
||||
after: function () {
|
||||
if (opts.iterator) {
|
||||
opts.iterator(node, i);
|
||||
}
|
||||
|
||||
if (opts.separator && i < len - 1) {
|
||||
self.push(opts.separator);
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
if (opts.indent) self.dedent();
|
||||
};
|
||||
|
||||
CodeGenerator.prototype.printAndIndentOnComments = function (print, node) {
|
||||
var indent = !!node.leadingComments;
|
||||
if (indent) this.indent();
|
||||
print(node);
|
||||
if (indent) this.dedent();
|
||||
};
|
||||
|
||||
CodeGenerator.prototype.printBlock = function (print, node) {
|
||||
if (t.isEmptyStatement(node)) {
|
||||
this.semicolon();
|
||||
} else {
|
||||
this.push(" ");
|
||||
print(node);
|
||||
}
|
||||
};
|
||||
|
||||
CodeGenerator.prototype.generateComment = function (comment) {
|
||||
var val = comment.value;
|
||||
if (comment.type === "Line") {
|
||||
val = "//" + val;
|
||||
} else {
|
||||
val = "/*" + val + "*/";
|
||||
}
|
||||
return val;
|
||||
};
|
||||
|
||||
CodeGenerator.prototype.printTrailingComments = function (node, parent) {
|
||||
this._printComments(this.getComments("trailingComments", node, parent));
|
||||
};
|
||||
|
||||
CodeGenerator.prototype.printLeadingComments = function (node, parent) {
|
||||
this._printComments(this.getComments("leadingComments", node, parent));
|
||||
};
|
||||
|
||||
CodeGenerator.prototype.getComments = function (key, node, parent) {
|
||||
if (t.isExpressionStatement(parent)) {
|
||||
return [];
|
||||
}
|
||||
|
||||
var comments = [];
|
||||
var nodes = [node];
|
||||
var self = this;
|
||||
|
||||
if (t.isExpressionStatement(node)) {
|
||||
nodes.push(node.argument);
|
||||
}
|
||||
|
||||
each(nodes, function (node) {
|
||||
comments = comments.concat(self._getComments(key, node));
|
||||
});
|
||||
|
||||
return comments;
|
||||
};
|
||||
|
||||
CodeGenerator.prototype._getComments = function (key, node) {
|
||||
return (node && node[key]) || [];
|
||||
};
|
||||
|
||||
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) {
|
||||
var skip = false;
|
||||
|
||||
// find the original comment in the ast and set it as displayed
|
||||
each(self.ast.comments, function (origComment) {
|
||||
if (origComment.start === comment.start) {
|
||||
// comment has already been output
|
||||
if (origComment._displayed) skip = true;
|
||||
|
||||
origComment._displayed = true;
|
||||
return false;
|
||||
}
|
||||
});
|
||||
|
||||
if (skip) return;
|
||||
|
||||
// whitespace before
|
||||
self.newline(self.whitespace.getNewlinesBefore(comment));
|
||||
|
||||
var column = self.position.column;
|
||||
var val = self.generateComment(comment);
|
||||
|
||||
if (column && !self.isLast(["\n", " ", "[", "{"])) {
|
||||
self._push(" ");
|
||||
column++;
|
||||
}
|
||||
|
||||
//
|
||||
|
||||
if (comment.type === "Block" && self.format.indent.adjustMultilineComment) {
|
||||
var offset = comment.loc.start.column;
|
||||
if (offset) {
|
||||
var newlineRegex = new RegExp("\\n\\s{1," + offset + "}", "g");
|
||||
val = val.replace(newlineRegex, "\n");
|
||||
}
|
||||
|
||||
var indent = Math.max(self.indentSize(), column);
|
||||
val = val.replace(/\n/g, "\n" + util.repeat(indent));
|
||||
}
|
||||
|
||||
if (column === 0) {
|
||||
val = self.getIndent() + val;
|
||||
}
|
||||
|
||||
//
|
||||
|
||||
self._push(val);
|
||||
|
||||
// whitespace after
|
||||
self.newline(self.whitespace.getNewlinesAfter(comment));
|
||||
});
|
||||
};
|
||||
@@ -1,112 +0,0 @@
|
||||
"use strict";
|
||||
|
||||
module.exports = Node;
|
||||
|
||||
var whitespace = require("./whitespace");
|
||||
var parens = require("./parentheses");
|
||||
var t = require("../../types");
|
||||
var each = require("lodash/collection/each");
|
||||
var some = require("lodash/collection/some");
|
||||
|
||||
var find = function (obj, node, parent) {
|
||||
if (!obj) return;
|
||||
var result;
|
||||
|
||||
var types = Object.keys(obj);
|
||||
for (var i = 0; i < types.length; i++) {
|
||||
var type = types[i];
|
||||
|
||||
if (t.is(type, node)) {
|
||||
var fn = obj[type];
|
||||
result = fn(node, parent);
|
||||
if (result != null) break;
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
};
|
||||
|
||||
function Node(node, parent) {
|
||||
this.parent = parent;
|
||||
this.node = node;
|
||||
}
|
||||
|
||||
Node.isUserWhitespacable = function (node) {
|
||||
return t.isUserWhitespacable(node);
|
||||
};
|
||||
|
||||
Node.needsWhitespace = function (node, parent, type) {
|
||||
if (!node) return 0;
|
||||
|
||||
if (t.isExpressionStatement(node)) {
|
||||
node = node.expression;
|
||||
}
|
||||
|
||||
var lines = find(whitespace[type].nodes, node, parent);
|
||||
if (lines) return lines;
|
||||
|
||||
each(find(whitespace[type].list, node, parent), function (expr) {
|
||||
lines = Node.needsWhitespace(expr, node, type);
|
||||
if (lines) return false;
|
||||
});
|
||||
return lines || 0;
|
||||
};
|
||||
|
||||
Node.needsWhitespaceBefore = function (node, parent) {
|
||||
return Node.needsWhitespace(node, parent, "before");
|
||||
};
|
||||
|
||||
Node.needsWhitespaceAfter = function (node, parent) {
|
||||
return Node.needsWhitespace(node, parent, "after");
|
||||
};
|
||||
|
||||
Node.needsParens = function (node, parent) {
|
||||
if (!parent) return false;
|
||||
|
||||
if (t.isNewExpression(parent) && parent.callee === node) {
|
||||
if (t.isCallExpression(node)) return true;
|
||||
|
||||
var hasCall = some(node, function (val) {
|
||||
return t.isCallExpression(val);
|
||||
});
|
||||
if (hasCall) return true;
|
||||
}
|
||||
|
||||
return find(parens, node, parent);
|
||||
};
|
||||
|
||||
Node.needsParensNoLineTerminator = function (node, parent) {
|
||||
if (!parent) return false;
|
||||
|
||||
// no comments
|
||||
if (!node.leadingComments || !node.leadingComments.length) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (t.isYieldExpression(parent) || t.isAwaitExpression(parent)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (t.isContinueStatement(parent) || t.isBreakStatement(parent) ||
|
||||
t.isReturnStatement(parent) || t.isThrowStatement(parent)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
};
|
||||
|
||||
each(Node, function (fn, key) {
|
||||
Node.prototype[key] = function () {
|
||||
// Avoid leaking arguments to prevent deoptimization
|
||||
var args = new Array(arguments.length + 2);
|
||||
|
||||
args[0] = this.node;
|
||||
args[1] = this.parent;
|
||||
|
||||
for (var i = 0; i < args.length; i++) {
|
||||
args[i + 2] = arguments[i];
|
||||
}
|
||||
|
||||
return Node[key].apply(null, args);
|
||||
};
|
||||
});
|
||||
@@ -1,84 +0,0 @@
|
||||
"use strict";
|
||||
|
||||
var t = require("../../types");
|
||||
var each = require("lodash/collection/each");
|
||||
var map = require("lodash/collection/map");
|
||||
var isNumber = require("lodash/lang/isNumber");
|
||||
|
||||
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: {
|
||||
LogicalExpression: function (node) {
|
||||
return t.isFunction(node.left) || t.isFunction(node.right);
|
||||
},
|
||||
|
||||
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,29 +0,0 @@
|
||||
"use strict";
|
||||
|
||||
module.exports = Position;
|
||||
|
||||
function Position() {
|
||||
this.line = 1;
|
||||
this.column = 0;
|
||||
}
|
||||
|
||||
Position.prototype.push = function (str) {
|
||||
for (var i = 0; i < str.length; i++) {
|
||||
if (str[i] === "\n") {
|
||||
this.line++;
|
||||
this.column = 0;
|
||||
} else {
|
||||
this.column++;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
Position.prototype.unshift = function (str) {
|
||||
for (var i = 0; i < str.length; i++) {
|
||||
if (str[i] === "\n") {
|
||||
this.line--;
|
||||
} else {
|
||||
this.column--;
|
||||
}
|
||||
}
|
||||
};
|
||||
@@ -1,56 +0,0 @@
|
||||
"use strict";
|
||||
|
||||
module.exports = SourceMap;
|
||||
|
||||
var sourceMap = require("source-map");
|
||||
var t = require("../types");
|
||||
|
||||
function SourceMap(position, opts, code) {
|
||||
this.position = position;
|
||||
this.opts = opts;
|
||||
|
||||
if (opts.sourceMap) {
|
||||
this.map = new sourceMap.SourceMapGenerator({
|
||||
file: opts.sourceMapName,
|
||||
sourceRoot: opts.sourceRoot
|
||||
});
|
||||
|
||||
this.map.setSourceContent(opts.sourceFileName, code);
|
||||
} else {
|
||||
this.map = null;
|
||||
}
|
||||
}
|
||||
|
||||
SourceMap.prototype.get = function () {
|
||||
var map = this.map;
|
||||
if (map) {
|
||||
return map.toJSON();
|
||||
} else {
|
||||
return map;
|
||||
}
|
||||
};
|
||||
|
||||
SourceMap.prototype.mark = function (node, type) {
|
||||
var loc = node.loc;
|
||||
if (!loc) return; // no location info
|
||||
|
||||
var map = this.map;
|
||||
if (!map) return; // no source map
|
||||
|
||||
if (t.isProgram(node) || t.isFile(node)) return; // illegal mapping nodes
|
||||
|
||||
var position = this.position;
|
||||
|
||||
var generated = {
|
||||
line: position.line,
|
||||
column: position.column
|
||||
};
|
||||
|
||||
var original = loc[type];
|
||||
|
||||
map.addMapping({
|
||||
source: this.opts.sourceFileName,
|
||||
generated: generated,
|
||||
original: original
|
||||
});
|
||||
};
|
||||
@@ -1,111 +0,0 @@
|
||||
"use strict";
|
||||
|
||||
module.exports = Whitespace;
|
||||
|
||||
var sortBy = require("lodash/collection/sortBy");
|
||||
|
||||
/**
|
||||
* Returns `i`th number from `base`, continuing from 0 when `max` is reached.
|
||||
* Useful for shifting `for` loop by a fixed number but going over all items.
|
||||
*
|
||||
* @param {Number} i Current index in the loop
|
||||
* @param {Number} base Start index for which to return 0
|
||||
* @param {Number} max Array length
|
||||
* @returns {Number} shiftedIndex
|
||||
*/
|
||||
function getLookupIndex(i, base, max) {
|
||||
i += base;
|
||||
|
||||
if (i >= max)
|
||||
i -= max;
|
||||
|
||||
return i;
|
||||
}
|
||||
|
||||
function Whitespace(tokens, comments) {
|
||||
this.tokens = sortBy(tokens.concat(comments), "start");
|
||||
this.used = {};
|
||||
|
||||
// Profiling this code shows that while generator passes over it, indexes
|
||||
// returned by `getNewlinesBefore` and `getNewlinesAfter` are always increasing.
|
||||
|
||||
// We use this implementation detail for an optimization: instead of always
|
||||
// starting to look from `this.tokens[0]`, we will start `for` loops from the
|
||||
// previous successful match. We will enumerate all tokens—but the common
|
||||
// case will be much faster.
|
||||
|
||||
this._lastFoundIndex = 0;
|
||||
}
|
||||
|
||||
Whitespace.prototype.getNewlinesBefore = function (node) {
|
||||
var startToken;
|
||||
var endToken;
|
||||
var tokens = this.tokens;
|
||||
var token;
|
||||
|
||||
for (var j = 0; j < tokens.length; j++) {
|
||||
// optimize for forward traversal by shifting for loop index
|
||||
var i = getLookupIndex(j, this._lastFoundIndex, this.tokens.length);
|
||||
token = tokens[i];
|
||||
|
||||
// this is the token this node starts with
|
||||
if (node.start === token.start) {
|
||||
startToken = tokens[i - 1];
|
||||
endToken = token;
|
||||
|
||||
this._lastFoundIndex = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return this.getNewlinesBetween(startToken, endToken);
|
||||
};
|
||||
|
||||
Whitespace.prototype.getNewlinesAfter = function (node) {
|
||||
var startToken;
|
||||
var endToken;
|
||||
var tokens = this.tokens;
|
||||
var token;
|
||||
|
||||
for (var j = 0; j < tokens.length; j++) {
|
||||
// optimize for forward traversal by shifting for loop index
|
||||
var i = getLookupIndex(j, this._lastFoundIndex, this.tokens.length);
|
||||
token = tokens[i];
|
||||
|
||||
// this is the token this node ends with
|
||||
if (node.end === token.end) {
|
||||
startToken = token;
|
||||
endToken = tokens[i + 1];
|
||||
|
||||
this._lastFoundIndex = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (endToken.type.type === "eof") {
|
||||
return 1;
|
||||
} else {
|
||||
var lines = this.getNewlinesBetween(startToken, endToken);
|
||||
if (node.type === "Line" && !lines) {
|
||||
// line comment
|
||||
return 1;
|
||||
} else {
|
||||
return lines;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
Whitespace.prototype.getNewlinesBetween = function (startToken, endToken) {
|
||||
var start = startToken ? startToken.loc.end.line : 1;
|
||||
var end = endToken.loc.start.line;
|
||||
var lines = 0;
|
||||
|
||||
for (var line = start; line < end; line++) {
|
||||
if (typeof this.used[line] === "undefined") {
|
||||
this.used[line] = true;
|
||||
lines++;
|
||||
}
|
||||
}
|
||||
|
||||
return lines;
|
||||
};
|
||||
@@ -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,79 +0,0 @@
|
||||
// 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 defs = {
|
||||
string1: "red",
|
||||
string2: "red",
|
||||
punct: ["white", "bold"],
|
||||
curly: "green",
|
||||
parens: ["blue", "bold"],
|
||||
square: ["yellow"],
|
||||
name: "white",
|
||||
keyword: ["cyan"],
|
||||
number: "magenta",
|
||||
regexp: "magenta",
|
||||
comment1: "grey",
|
||||
comment2: "grey"
|
||||
};
|
||||
|
||||
var highlight = function (text) {
|
||||
var colorize = function (str, col) {
|
||||
if (!col) return str;
|
||||
|
||||
if (Array.isArray(col)) {
|
||||
col.forEach(function (col) {
|
||||
str = chalk[col](str);
|
||||
});
|
||||
} else {
|
||||
str = chalk[col](str);
|
||||
}
|
||||
return str;
|
||||
};
|
||||
|
||||
return tokenize(text, true).map(function (str) {
|
||||
var type = tokenize.type(str);
|
||||
return colorize(str, defs[type]);
|
||||
}).join("");
|
||||
};
|
||||
|
||||
module.exports = function (lines, lineNumber, colNumber) {
|
||||
colNumber = Math.max(colNumber, 0);
|
||||
|
||||
if (supportsColor) {
|
||||
lines = highlight(lines);
|
||||
}
|
||||
|
||||
lines = lines.split(/\r\n|[\n\r\u2028\u2029]/);
|
||||
|
||||
var start = Math.max(lineNumber - 3, 0);
|
||||
var end = Math.min(lines.length, lineNumber + 3);
|
||||
var width = (end + "").length;
|
||||
|
||||
if (!lineNumber && !colNumber) {
|
||||
start = 0;
|
||||
end = lines.length;
|
||||
}
|
||||
|
||||
return "\n" + lines.slice(start, end).map(function (line, i) {
|
||||
var curr = i + start + 1;
|
||||
|
||||
var gutter = curr === lineNumber ? "> " : " ";
|
||||
|
||||
var sep = curr + util.repeat(width + 1);
|
||||
gutter += sep + "| ";
|
||||
|
||||
var str = gutter + line;
|
||||
|
||||
if (colNumber && curr === lineNumber) {
|
||||
str += "\n";
|
||||
str += util.repeat(gutter.length - 2);
|
||||
str += "|" + util.repeat(colNumber) + "^";
|
||||
}
|
||||
|
||||
return str;
|
||||
}).join("\n");
|
||||
};
|
||||
@@ -1,38 +0,0 @@
|
||||
// taken from stackoverflow, it's crap i know.
|
||||
|
||||
module.exports = function (a, b) {
|
||||
if (a.length === 0) return b.length;
|
||||
if (b.length === 0) return a.length;
|
||||
|
||||
var matrix = [];
|
||||
|
||||
// increment along the first column of each row
|
||||
var i;
|
||||
for (i = 0; i <= b.length; i++) {
|
||||
matrix[i] = [i];
|
||||
}
|
||||
|
||||
// increment each column in the first row
|
||||
var j;
|
||||
for (j = 0; j <= a.length; j++) {
|
||||
matrix[0][j] = j;
|
||||
}
|
||||
|
||||
// Fill in the rest of the matrix
|
||||
for (i = 1; i <= b.length; i++) {
|
||||
for (j = 1; j <= a.length; j++) {
|
||||
if (b.charAt(i - 1) == a.charAt(j - 1)) {
|
||||
matrix[i][j] = matrix[i - 1][j - 1];
|
||||
} else {
|
||||
matrix[i][j] = Math.min(
|
||||
matrix[i - 1][j - 1] + 1, // substitution
|
||||
Math.min(
|
||||
matrix[i][j - 1] + 1, // insertion
|
||||
matrix[i - 1][j] + 1) // deletion
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return matrix[b.length][a.length];
|
||||
};
|
||||
@@ -1,5 +0,0 @@
|
||||
"use strict";
|
||||
|
||||
module.exports = function () {
|
||||
return Object.create(null);
|
||||
};
|
||||
@@ -1,49 +0,0 @@
|
||||
var normalizeAst = require("./normalize-ast");
|
||||
var estraverse = require("estraverse");
|
||||
var codeFrame = require("./code-frame");
|
||||
var acorn = require("acorn-6to5");
|
||||
|
||||
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._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;
|
||||
}
|
||||
};
|
||||
@@ -1,17 +0,0 @@
|
||||
"use strict";
|
||||
|
||||
/**
|
||||
* A trick from Bluebird to force V8 to use fast properties for an object.
|
||||
* Read more: http://stackoverflow.com/questions/24987896/
|
||||
*
|
||||
* Use %HasFastProperties(obj) and --allow-natives-syntax to check whether
|
||||
* a particular object already has fast properties.
|
||||
*/
|
||||
|
||||
module.exports = function toFastProperties(obj) {
|
||||
/*jshint -W027*/
|
||||
function f() {}
|
||||
f.prototype = obj;
|
||||
return f;
|
||||
eval(obj);
|
||||
};
|
||||
@@ -1,48 +0,0 @@
|
||||
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 only 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"
|
||||
};
|
||||
|
||||
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,65 +0,0 @@
|
||||
"use strict";
|
||||
|
||||
var extend = require("lodash/object/extend");
|
||||
var t = require("./types");
|
||||
|
||||
// estraverse
|
||||
|
||||
var estraverse = require("estraverse");
|
||||
extend(estraverse.VisitorKeys, t.VISITOR_KEYS);
|
||||
|
||||
// regenerator-6to5/ast-types
|
||||
|
||||
var types = require("ast-types");
|
||||
var def = types.Type.def;
|
||||
var or = types.Type.or;
|
||||
|
||||
def("File")
|
||||
.bases("Node")
|
||||
.build("program")
|
||||
.field("program", def("Program"));
|
||||
|
||||
def("AssignmentPattern")
|
||||
.bases("Pattern")
|
||||
.build("left", "right")
|
||||
.field("left", def("Pattern"))
|
||||
.field("right", def("Expression"));
|
||||
|
||||
// Acorn - Same as ImportNamespaceSpecifier but `id` is `name`
|
||||
def("ImportBatchSpecifier")
|
||||
.bases("Specifier")
|
||||
.build("name")
|
||||
.field("name", def("Identifier"));
|
||||
|
||||
def("RestElement")
|
||||
.bases("Pattern")
|
||||
.build("argument")
|
||||
.field("argument", def("expression"));
|
||||
|
||||
// Abstract references
|
||||
def("VirtualPropertyExpression")
|
||||
.bases("Expression")
|
||||
.build("object", "property")
|
||||
.field("object", def("Expression"))
|
||||
.field("property", or(def("Identifier"), def("Expression")));
|
||||
|
||||
def("PrivateDeclaration")
|
||||
.bases("Declaration")
|
||||
.build("declarations")
|
||||
.field("declarations", [def("Identifier")]);
|
||||
|
||||
// Playground
|
||||
def("BindMemberExpression")
|
||||
.bases("Expression")
|
||||
.build("object", "property", "arguments")
|
||||
.field("object", def("Expression"))
|
||||
.field("property", or(def("Identifier"), def("Expression")))
|
||||
.field("arguments", [def("Expression")]);
|
||||
|
||||
def("BindFunctionExpression")
|
||||
.bases("Expression")
|
||||
.build("callee", "arguments")
|
||||
.field("callee", def("Expression"))
|
||||
.field("arguments", [def("Expression")]);
|
||||
|
||||
types.finalize();
|
||||
@@ -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,445 +0,0 @@
|
||||
"use strict";
|
||||
|
||||
module.exports = File;
|
||||
|
||||
var SHEBANG_REGEX = /^\#\!.*/;
|
||||
|
||||
var isFunction = require("lodash/lang/isFunction");
|
||||
var transform = require("./index");
|
||||
var generate = require("../generation");
|
||||
var defaults = require("lodash/object/defaults");
|
||||
var includes = require("lodash/collection/includes");
|
||||
var clone = require("../helpers/clone");
|
||||
var parse = require("../helpers/parse");
|
||||
var Scope = require("../traversal/scope");
|
||||
var util = require("../util");
|
||||
var path = require("path");
|
||||
var each = require("lodash/collection/each");
|
||||
var t = require("../types");
|
||||
|
||||
function File(opts) {
|
||||
this.dynamicImportIds = {};
|
||||
this.dynamicImported = [];
|
||||
this.dynamicImports = [];
|
||||
|
||||
this.dynamicData = {};
|
||||
this.data = {};
|
||||
|
||||
this.lastStatements = [];
|
||||
this.opts = this.normalizeOptions(opts);
|
||||
this.ast = {};
|
||||
|
||||
this.buildTransformers();
|
||||
}
|
||||
|
||||
File.helpers = [
|
||||
"inherits",
|
||||
"defaults",
|
||||
"prototype-properties",
|
||||
"apply-constructor",
|
||||
"tagged-template-literal",
|
||||
"tagged-template-literal-loose",
|
||||
"interop-require",
|
||||
"to-array",
|
||||
"to-consumable-array",
|
||||
"sliced-to-array",
|
||||
"object-without-properties",
|
||||
"has-own",
|
||||
"slice",
|
||||
"bind",
|
||||
"define-property",
|
||||
"async-to-generator",
|
||||
"interop-require-wildcard",
|
||||
"typeof",
|
||||
"extends",
|
||||
"get",
|
||||
"set",
|
||||
"class-call-check",
|
||||
"object-destructuring-empty",
|
||||
"temporal-undefined",
|
||||
"temporal-assert-defined",
|
||||
"tail-call"
|
||||
];
|
||||
|
||||
File.validOptions = [
|
||||
"filename",
|
||||
"filenameRelative",
|
||||
"blacklist",
|
||||
"whitelist",
|
||||
"loose",
|
||||
"optional",
|
||||
"modules",
|
||||
"sourceMap",
|
||||
"sourceMapName",
|
||||
"sourceFileName",
|
||||
"sourceRoot",
|
||||
"moduleRoot",
|
||||
"moduleIds",
|
||||
"comments",
|
||||
"reactCompat",
|
||||
"keepModuleIdExtensions",
|
||||
"code",
|
||||
"ast",
|
||||
"format",
|
||||
"playground",
|
||||
"experimental",
|
||||
"resolveModuleSource",
|
||||
"runtime",
|
||||
|
||||
// these are used by plugins
|
||||
"ignore",
|
||||
"only",
|
||||
"extensions",
|
||||
"accept"
|
||||
];
|
||||
|
||||
File.prototype.normalizeOptions = function (opts) {
|
||||
opts = clone(opts);
|
||||
|
||||
for (var key in opts) {
|
||||
if (key[0] !== "_" && File.validOptions.indexOf(key) < 0) {
|
||||
throw new ReferenceError("Unknown option: " + key);
|
||||
}
|
||||
}
|
||||
|
||||
defaults(opts, {
|
||||
keepModuleIdExtensions: false,
|
||||
resolveModuleSource: null,
|
||||
experimental: false,
|
||||
reactCompat: false,
|
||||
playground: false,
|
||||
whitespace: true,
|
||||
moduleIds: false,
|
||||
blacklist: [],
|
||||
whitelist: [],
|
||||
sourceMap: false,
|
||||
optional: [],
|
||||
comments: true,
|
||||
filename: "unknown",
|
||||
modules: "common",
|
||||
runtime: false,
|
||||
loose: [],
|
||||
code: true,
|
||||
ast: true
|
||||
});
|
||||
|
||||
// normalize windows path separators to unix
|
||||
opts.filename = util.normalisePathSeparator(opts.filename);
|
||||
if (opts.sourceRoot) {
|
||||
opts.sourceRoot = util.normalisePathSeparator(opts.sourceRoot);
|
||||
}
|
||||
|
||||
opts.basename = path.basename(opts.filename, path.extname(opts.filename));
|
||||
|
||||
opts.blacklist = util.arrayify(opts.blacklist);
|
||||
opts.whitelist = util.arrayify(opts.whitelist);
|
||||
opts.optional = util.arrayify(opts.optional);
|
||||
opts.loose = util.arrayify(opts.loose);
|
||||
|
||||
if (includes(opts.loose, "all") || includes(opts.loose, true)) {
|
||||
opts.loose = Object.keys(transform.transformers);
|
||||
}
|
||||
|
||||
defaults(opts, {
|
||||
moduleRoot: opts.sourceRoot
|
||||
});
|
||||
|
||||
defaults(opts, {
|
||||
sourceRoot: opts.moduleRoot
|
||||
});
|
||||
|
||||
defaults(opts, {
|
||||
filenameRelative: opts.filename
|
||||
});
|
||||
|
||||
defaults(opts, {
|
||||
sourceFileName: opts.filenameRelative,
|
||||
sourceMapName: opts.filenameRelative
|
||||
});
|
||||
|
||||
if (opts.playground) {
|
||||
opts.experimental = true;
|
||||
}
|
||||
|
||||
if (opts.runtime) {
|
||||
this.set("runtimeIdentifier", t.identifier("to5Runtime"));
|
||||
}
|
||||
|
||||
opts.blacklist = transform._ensureTransformerNames("blacklist", opts.blacklist);
|
||||
opts.whitelist = transform._ensureTransformerNames("whitelist", opts.whitelist);
|
||||
opts.optional = transform._ensureTransformerNames("optional", opts.optional);
|
||||
opts.loose = transform._ensureTransformerNames("loose", opts.loose);
|
||||
|
||||
if (opts.reactCompat) {
|
||||
opts.optional.push("reactCompat");
|
||||
console.error("The reactCompat option has been moved into the optional transformer " +
|
||||
"`reactCompat` - backwards compatibility will be removed in v4.0.0");
|
||||
}
|
||||
|
||||
var ensureEnabled = function (key) {
|
||||
var namespace = transform.transformerNamespaces[key];
|
||||
if (namespace === "es7") opts.experimental = true;
|
||||
if (namespace === "playground") opts.playground = true;
|
||||
};
|
||||
|
||||
each(opts.whitelist, ensureEnabled);
|
||||
each(opts.optional, ensureEnabled);
|
||||
|
||||
return opts;
|
||||
};
|
||||
|
||||
File.prototype.isLoose = function (key) {
|
||||
return includes(this.opts.loose, key);
|
||||
};
|
||||
|
||||
File.prototype.buildTransformers = function () {
|
||||
var file = this;
|
||||
|
||||
var transformers = {};
|
||||
|
||||
var secondaryStack = [];
|
||||
var stack = [];
|
||||
|
||||
each(transform.transformers, function (transformer, key) {
|
||||
var pass = transformers[key] = transformer.buildPass(file);
|
||||
|
||||
if (pass.canRun(file)) {
|
||||
stack.push(pass);
|
||||
|
||||
if (transformer.secondPass) {
|
||||
secondaryStack.push(pass);
|
||||
}
|
||||
|
||||
if (transformer.manipulateOptions) {
|
||||
transformer.manipulateOptions(file.opts, file);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
this.transformerStack = stack.concat(secondaryStack);
|
||||
this.transformers = transformers;
|
||||
};
|
||||
|
||||
File.prototype.debug = function (msg) {
|
||||
var parts = this.opts.filename;
|
||||
if (msg) parts += ": " + msg;
|
||||
util.debug(parts);
|
||||
};
|
||||
|
||||
File.prototype.getModuleFormatter = function (type) {
|
||||
var ModuleFormatter = isFunction(type) ? type : transform.moduleFormatters[type];
|
||||
|
||||
if (!ModuleFormatter) {
|
||||
var loc = util.resolve(type);
|
||||
if (loc) ModuleFormatter = require(loc);
|
||||
}
|
||||
|
||||
if (!ModuleFormatter) {
|
||||
throw new ReferenceError("Unknown module formatter type " + JSON.stringify(type));
|
||||
}
|
||||
|
||||
return new ModuleFormatter(this);
|
||||
};
|
||||
|
||||
File.prototype.parseShebang = function (code) {
|
||||
var shebangMatch = code.match(SHEBANG_REGEX);
|
||||
if (shebangMatch) {
|
||||
this.shebang = shebangMatch[0];
|
||||
|
||||
// remove shebang
|
||||
code = code.replace(SHEBANG_REGEX, "");
|
||||
}
|
||||
|
||||
return code;
|
||||
};
|
||||
|
||||
File.prototype.set = function (key, val) {
|
||||
return this.data[key] = val;
|
||||
};
|
||||
|
||||
File.prototype.setDynamic = function (key, fn) {
|
||||
this.dynamicData[key] = fn;
|
||||
};
|
||||
|
||||
File.prototype.get = function (key) {
|
||||
var data = this.data[key];
|
||||
if (data) {
|
||||
return data;
|
||||
} else {
|
||||
var dynamic = this.dynamicData[key];
|
||||
if (dynamic) {
|
||||
return this.set(key, dynamic());
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
File.prototype.addImport = function (source, name) {
|
||||
name = name || source;
|
||||
var id = this.dynamicImportIds[name];
|
||||
|
||||
if (!id) {
|
||||
id = this.dynamicImportIds[name] = this.scope.generateUidIdentifier(name);
|
||||
|
||||
var specifiers = [t.importSpecifier(t.identifier("default"), id)];
|
||||
var declar = t.importDeclaration(specifiers, t.literal(source));
|
||||
declar._blockHoist = 3;
|
||||
this.dynamicImported.push(declar);
|
||||
|
||||
this.moduleFormatter.importSpecifier(specifiers[0], declar, this.dynamicImports);
|
||||
}
|
||||
|
||||
return id;
|
||||
};
|
||||
|
||||
File.prototype.isConsequenceExpressionStatement = function (node) {
|
||||
return t.isExpressionStatement(node) && this.lastStatements.indexOf(node) >= 0;
|
||||
};
|
||||
|
||||
File.prototype.addHelper = function (name) {
|
||||
if (!includes(File.helpers, name)) {
|
||||
throw new ReferenceError("Unknown helper " + name);
|
||||
}
|
||||
|
||||
var program = this.ast.program;
|
||||
|
||||
var declar = program._declarations && program._declarations[name];
|
||||
if (declar) return declar.id;
|
||||
|
||||
var runtime = this.get("runtimeIdentifier");
|
||||
if (runtime) {
|
||||
name = t.identifier(t.toIdentifier(name));
|
||||
return t.memberExpression(runtime, name);
|
||||
} else {
|
||||
var ref = util.template(name);
|
||||
ref._compact = true;
|
||||
var uid = this.scope.generateUidIdentifier(name);
|
||||
this.scope.push({
|
||||
key: name,
|
||||
id: uid,
|
||||
init: ref
|
||||
});
|
||||
return uid;
|
||||
}
|
||||
};
|
||||
|
||||
File.prototype.logDeopt = function () {
|
||||
// todo, (node, msg)
|
||||
};
|
||||
|
||||
File.prototype.errorWithNode = function (node, msg, Error) {
|
||||
Error = Error || SyntaxError;
|
||||
|
||||
var loc = node.loc.start;
|
||||
var err = new Error("Line " + loc.line + ": " + msg);
|
||||
err.loc = loc;
|
||||
return err;
|
||||
};
|
||||
|
||||
File.prototype.addCode = function (code) {
|
||||
code = (code || "") + "";
|
||||
this.code = code;
|
||||
return this.parseShebang(code);
|
||||
};
|
||||
|
||||
File.prototype.parse = function (code) {
|
||||
var self = this;
|
||||
|
||||
code = this.addCode(code);
|
||||
|
||||
var opts = this.opts;
|
||||
|
||||
opts.allowImportExportEverywhere = this.isLoose("es6.modules");
|
||||
//opts.strictMode = this.transformers.useStrict.canRun();
|
||||
|
||||
return parse(opts, code, function (tree) {
|
||||
self.transform(tree);
|
||||
return self.generate();
|
||||
});
|
||||
};
|
||||
|
||||
File.prototype.transform = function (ast) {
|
||||
this.debug();
|
||||
|
||||
this.ast = ast;
|
||||
this.lastStatements = t.getLastStatements(ast.program);
|
||||
this.scope = new Scope(ast.program, ast, null, this);
|
||||
|
||||
var modFormatter = this.moduleFormatter = this.getModuleFormatter(this.opts.modules);
|
||||
if (modFormatter.init && this.transformers["es6.modules"].canRun()) {
|
||||
modFormatter.init();
|
||||
}
|
||||
|
||||
this.checkNode(ast);
|
||||
|
||||
this.call("pre");
|
||||
|
||||
each(this.transformerStack, function (pass) {
|
||||
pass.transform();
|
||||
});
|
||||
|
||||
this.call("post");
|
||||
};
|
||||
|
||||
File.prototype.call = function (key) {
|
||||
var stack = this.transformerStack;
|
||||
for (var i = 0; i < stack.length; i++) {
|
||||
var transformer = stack[i].transformer;
|
||||
if (transformer[key]) {
|
||||
transformer[key](this);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
var checkTransformerVisitor = {
|
||||
enter: function (node, parent, scope, state) {
|
||||
checkNode(state.stack, node, scope);
|
||||
}
|
||||
};
|
||||
|
||||
var checkNode = function (stack, node, scope) {
|
||||
each(stack, function (pass) {
|
||||
if (pass.shouldRun) return;
|
||||
pass.checkNode(node, scope);
|
||||
});
|
||||
};
|
||||
|
||||
File.prototype.checkNode = function (node, scope) {
|
||||
var stack = this.transformerStack;
|
||||
scope = scope || this.scope;
|
||||
|
||||
checkNode(stack, node, scope);
|
||||
|
||||
scope.traverse(node, checkTransformerVisitor, {
|
||||
stack: stack
|
||||
});
|
||||
};
|
||||
|
||||
File.prototype.generate = function () {
|
||||
var opts = this.opts;
|
||||
var ast = this.ast;
|
||||
|
||||
var result = {
|
||||
code: "",
|
||||
map: null,
|
||||
ast: null
|
||||
};
|
||||
|
||||
if (opts.ast) result.ast = ast;
|
||||
if (!opts.code) return result;
|
||||
|
||||
var _result = generate(ast, opts, this.code);
|
||||
result.code = _result.code;
|
||||
result.map = _result.map;
|
||||
|
||||
if (this.shebang) {
|
||||
// add back shebang
|
||||
result.code = this.shebang + "\n" + result.code;
|
||||
}
|
||||
|
||||
if (opts.sourceMap === "inline") {
|
||||
result.code += "\n" + util.sourceMapToComment(result.map);
|
||||
result.map = null;
|
||||
}
|
||||
|
||||
return result;
|
||||
};
|
||||
@@ -1,73 +0,0 @@
|
||||
var cloneDeep = require("lodash/lang/cloneDeep");
|
||||
var traverse = require("../../traversal");
|
||||
var clone = require("lodash/lang/clone");
|
||||
var each = require("lodash/collection/each");
|
||||
var has = require("lodash/object/has");
|
||||
var t = require("../../types");
|
||||
|
||||
exports.push = function (mutatorMap, key, kind, computed, value) {
|
||||
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] = value;
|
||||
};
|
||||
|
||||
exports.build = 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);
|
||||
}
|
||||
|
||||
if (map.enumerable === false) {
|
||||
delete map.enumerable;
|
||||
} else {
|
||||
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;
|
||||
};
|
||||
@@ -1,53 +0,0 @@
|
||||
"use strict";
|
||||
|
||||
var util = require("../../util");
|
||||
var t = require("../../types");
|
||||
|
||||
var visitor = {
|
||||
enter: function (node, parent, scope, state) {
|
||||
// check if this node is an identifier that matches the same as our function id
|
||||
if (!t.isIdentifier(node, { name: state.id })) return;
|
||||
|
||||
// check if this node is the one referenced
|
||||
if (!t.isReferenced(node, parent)) return;
|
||||
|
||||
// check that we don't have a local variable declared as that removes the need
|
||||
// for the wrapper
|
||||
var localDeclar = scope.getBindingIdentifier(state.id);
|
||||
if (localDeclar !== state.outerDeclar) return;
|
||||
|
||||
state.selfReference = true;
|
||||
this.stop();
|
||||
}
|
||||
};
|
||||
|
||||
exports.property = function (node, file, scope) {
|
||||
var key = t.toComputedKey(node, node.key);
|
||||
if (!t.isLiteral(key)) return node; // we can't set a function id with this
|
||||
|
||||
var id = t.toIdentifier(key.value);
|
||||
key = t.identifier(id);
|
||||
|
||||
var state = {
|
||||
id: id,
|
||||
selfReference: false,
|
||||
outerDeclar: scope.getBindingIdentifier(id),
|
||||
};
|
||||
|
||||
scope.traverse(node, visitor, state);
|
||||
|
||||
var method = node.value;
|
||||
|
||||
if (state.selfReference) {
|
||||
var templateName = "property-method-assignment-wrapper";
|
||||
if (method.generator) templateName += "-generator";
|
||||
node.value = util.template(templateName, {
|
||||
FUNCTION: method,
|
||||
FUNCTION_ID: key,
|
||||
FUNCTION_KEY: scope.generateUidIdentifier(id),
|
||||
WRAPPER_KEY: scope.generateUidIdentifier(id + "Wrapper")
|
||||
});
|
||||
} else {
|
||||
method.id = key;
|
||||
}
|
||||
};
|
||||
26
lib/6to5/transformation/helpers/react.js
vendored
26
lib/6to5/transformation/helpers/react.js
vendored
@@ -1,26 +0,0 @@
|
||||
var t = require("../../types");
|
||||
|
||||
var isCreateClassCallExpression = t.buildMatchMemberExpression("React.createClass");
|
||||
|
||||
exports.isCreateClass = function (node) {
|
||||
if (!node || !t.isCallExpression(node)) return false;
|
||||
|
||||
// not React.createClass call member object
|
||||
if (!isCreateClassCallExpression(node.callee)) return false;
|
||||
|
||||
// no call arguments
|
||||
var args = node.arguments;
|
||||
if (args.length !== 1) return false;
|
||||
|
||||
// first node arg is not an object
|
||||
var first = args[0];
|
||||
if (!t.isObjectExpression(first)) return false;
|
||||
|
||||
return true;
|
||||
};
|
||||
|
||||
exports.isReactComponent = t.buildMatchMemberExpression("React.Component");
|
||||
|
||||
exports.isCompatTag = function (tagName) {
|
||||
return tagName && /^[a-z]|\-/.test(tagName);
|
||||
};
|
||||
@@ -1,40 +0,0 @@
|
||||
"use strict";
|
||||
|
||||
var t = require("../../types");
|
||||
|
||||
var visitor = {
|
||||
enter: function (node) {
|
||||
if (t.isFunction(node)) this.skip();
|
||||
|
||||
if (t.isAwaitExpression(node)) {
|
||||
node.type = "YieldExpression";
|
||||
|
||||
if (node.all) {
|
||||
// await* foo; -> yield Promise.all(foo);
|
||||
node.all = false;
|
||||
node.argument = t.callExpression(t.memberExpression(t.identifier("Promise"), t.identifier("all")), [node.argument]);
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = function (node, callId, scope) {
|
||||
node.async = false;
|
||||
node.generator = true;
|
||||
|
||||
scope.traverse(node, visitor);
|
||||
|
||||
var call = t.callExpression(callId, [node]);
|
||||
var id = node.id;
|
||||
delete node.id;
|
||||
|
||||
if (t.isFunctionDeclaration(node)) {
|
||||
var declar = t.variableDeclaration("let", [
|
||||
t.variableDeclarator(id, call)
|
||||
]);
|
||||
declar._blockHoist = true;
|
||||
return declar;
|
||||
} else {
|
||||
return call;
|
||||
}
|
||||
};
|
||||
@@ -1,303 +0,0 @@
|
||||
"use strict";
|
||||
|
||||
module.exports = ReplaceSupers;
|
||||
|
||||
var messages = require("../../messages");
|
||||
var t = require("../../types");
|
||||
|
||||
/**
|
||||
* Description
|
||||
*
|
||||
* @param {Object} opts
|
||||
* @param {Boolean} [inClass]
|
||||
*/
|
||||
|
||||
function ReplaceSupers(opts, inClass) {
|
||||
this.topLevelThisReference = opts.topLevelThisReference;
|
||||
this.methodNode = opts.methodNode;
|
||||
this.className = opts.className;
|
||||
this.superName = opts.superName;
|
||||
this.isStatic = opts.isStatic;
|
||||
this.hasSuper = false;
|
||||
this.inClass = inClass;
|
||||
this.isLoose = opts.isLoose;
|
||||
this.scope = opts.scope;
|
||||
this.file = opts.file;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets a super class value of the named property.
|
||||
*
|
||||
* @example
|
||||
*
|
||||
* _set(Object.getPrototypeOf(CLASS.prototype), "METHOD", "VALUE", this)
|
||||
*
|
||||
* @param {Node} property
|
||||
* @param {Node} value
|
||||
* @param {Boolean} isComputed
|
||||
* @param {Node} thisExpression
|
||||
*
|
||||
* @returns {Node}
|
||||
*/
|
||||
|
||||
ReplaceSupers.prototype.setSuperProperty = function (property, value, isComputed, thisExpression) {
|
||||
return t.callExpression(
|
||||
this.file.addHelper("set"),
|
||||
[
|
||||
t.callExpression(
|
||||
t.memberExpression(t.identifier("Object"), t.identifier("getPrototypeOf")),
|
||||
[
|
||||
this.isStatic ? this.className : t.memberExpression(this.className, t.identifier("prototype"))
|
||||
]
|
||||
),
|
||||
isComputed ? property : t.literal(property.name),
|
||||
value,
|
||||
thisExpression
|
||||
]
|
||||
);
|
||||
};
|
||||
|
||||
/**
|
||||
* Gets a node representing the super class value of the named property.
|
||||
*
|
||||
* @example
|
||||
*
|
||||
* _get(Object.getPrototypeOf(CLASS.prototype), "METHOD", this)
|
||||
*
|
||||
* @param {Node} property
|
||||
* @param {Boolean} isComputed
|
||||
* @param {Node} thisExpression
|
||||
*
|
||||
* @returns {Node}
|
||||
*/
|
||||
|
||||
ReplaceSupers.prototype.getSuperProperty = function (property, isComputed, thisExpression) {
|
||||
return t.callExpression(
|
||||
this.file.addHelper("get"),
|
||||
[
|
||||
t.callExpression(
|
||||
t.memberExpression(t.identifier("Object"), t.identifier("getPrototypeOf")),
|
||||
[
|
||||
this.isStatic ? this.className : t.memberExpression(this.className, t.identifier("prototype"))
|
||||
]
|
||||
),
|
||||
isComputed ? property : t.literal(property.name),
|
||||
thisExpression
|
||||
]
|
||||
);
|
||||
};
|
||||
|
||||
/**
|
||||
* Description
|
||||
*/
|
||||
|
||||
ReplaceSupers.prototype.replace = function () {
|
||||
this.traverseLevel(this.methodNode.value, true);
|
||||
};
|
||||
|
||||
var visitor = {
|
||||
enter: function (node, parent, scope, state) {
|
||||
var topLevel = state.topLevel;
|
||||
var self = state.self;
|
||||
|
||||
if (t.isFunction(node) && !t.isArrowFunctionExpression(node)) {
|
||||
// we need to call traverseLevel again so we're context aware
|
||||
self.traverseLevel(node, false);
|
||||
return this.skip();
|
||||
}
|
||||
|
||||
if (t.isProperty(node, { method: true }) || t.isMethodDefinition(node)) {
|
||||
// break on object methods
|
||||
return this.skip();
|
||||
}
|
||||
|
||||
var getThisReference = topLevel ?
|
||||
// top level so `this` is the instance
|
||||
t.thisExpression :
|
||||
// not in the top level so we need to create a reference
|
||||
self.getThisReference.bind(self);
|
||||
|
||||
var callback = self.specHandle;
|
||||
if (self.isLoose) callback = self.looseHandle;
|
||||
return callback.call(self, getThisReference, node, parent);
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Description
|
||||
*
|
||||
* @param {Object} node
|
||||
* @param {Boolean} topLevel
|
||||
*/
|
||||
|
||||
ReplaceSupers.prototype.traverseLevel = function (node, topLevel) {
|
||||
var state = { self: this, topLevel: topLevel };
|
||||
this.scope.traverse(node, visitor, state);
|
||||
};
|
||||
|
||||
/**
|
||||
* Description
|
||||
*/
|
||||
|
||||
ReplaceSupers.prototype.getThisReference = function () {
|
||||
if (this.topLevelThisReference) {
|
||||
return this.topLevelThisReference;
|
||||
} else {
|
||||
var ref = this.topLevelThisReference = this.scope.generateUidIdentifier("this");
|
||||
this.methodNode.value.body.body.unshift(t.variableDeclaration("var", [
|
||||
t.variableDeclarator(this.topLevelThisReference, t.thisExpression())
|
||||
]));
|
||||
return ref;
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Description
|
||||
*
|
||||
* @param {Object} node
|
||||
* @param {Object} id
|
||||
* @param {Object} parent
|
||||
* @returns {Object}
|
||||
*/
|
||||
|
||||
ReplaceSupers.prototype.getLooseSuperProperty = function (id, parent) {
|
||||
var methodNode = this.methodNode;
|
||||
var methodName = methodNode.key;
|
||||
var superName = this.superName || t.identifier("Function");
|
||||
|
||||
if (parent.property === id) {
|
||||
return;
|
||||
} else if (t.isCallExpression(parent, { callee: id })) {
|
||||
// super(); -> ClassName.prototype.MethodName.call(this);
|
||||
parent.arguments.unshift(t.thisExpression());
|
||||
|
||||
if (methodName.name === "constructor") {
|
||||
// constructor() { super(); }
|
||||
return t.memberExpression(superName, t.identifier("call"));
|
||||
} else {
|
||||
id = superName;
|
||||
|
||||
// foo() { super(); }
|
||||
if (!methodNode.static) {
|
||||
id = t.memberExpression(id, t.identifier("prototype"));
|
||||
}
|
||||
|
||||
id = t.memberExpression(id, methodName, methodNode.computed);
|
||||
return t.memberExpression(id, t.identifier("call"));
|
||||
}
|
||||
} else if (t.isMemberExpression(parent) && !methodNode.static) {
|
||||
// super.test -> ClassName.prototype.test
|
||||
return t.memberExpression(superName, t.identifier("prototype"));
|
||||
} else {
|
||||
return superName;
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Description
|
||||
*
|
||||
* @param {Function} getThisReference
|
||||
* @param {Object} node
|
||||
* @param {Object} parent
|
||||
*/
|
||||
|
||||
ReplaceSupers.prototype.looseHandle = function (getThisReference, node, parent) {
|
||||
if (t.isIdentifier(node, { name: "super" })) {
|
||||
this.hasSuper = true;
|
||||
return this.getLooseSuperProperty(node, parent);
|
||||
} else if (t.isCallExpression(node)) {
|
||||
var callee = node.callee;
|
||||
if (!t.isMemberExpression(callee)) return;
|
||||
if (callee.object.name !== "super") return;
|
||||
|
||||
// super.test(); -> ClassName.prototype.MethodName.call(this);
|
||||
this.hasSuper = true;
|
||||
t.appendToMemberExpression(callee, t.identifier("call"));
|
||||
node.arguments.unshift(getThisReference());
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Description
|
||||
*
|
||||
* @param {Function} getThisReference
|
||||
* @param {Object} node
|
||||
* @param {Object} parent
|
||||
*/
|
||||
|
||||
ReplaceSupers.prototype.specHandle = function (getThisReference, node, parent) {
|
||||
var methodNode = this.methodNode;
|
||||
var property;
|
||||
var computed;
|
||||
var args;
|
||||
var thisReference;
|
||||
|
||||
if (isIllegalBareSuper(node, parent)) {
|
||||
throw this.file.errorWithNode(node, messages.get("classesIllegalBareSuper"));
|
||||
}
|
||||
|
||||
if (t.isCallExpression(node)) {
|
||||
var callee = node.callee;
|
||||
if (isSuper(callee, node)) {
|
||||
// super(); -> _get(Object.getPrototypeOf(ClassName), "MethodName", this).call(this);
|
||||
property = methodNode.key;
|
||||
computed = methodNode.computed;
|
||||
args = node.arguments;
|
||||
|
||||
// bare `super` call is illegal inside non-constructors
|
||||
// - https://esdiscuss.org/topic/super-call-in-methods
|
||||
// - https://twitter.com/wycats/status/544553184396836864
|
||||
if (methodNode.key.name !== "constructor" || !this.inClass) {
|
||||
var methodName = methodNode.key.name || "METHOD_NAME";
|
||||
throw this.file.errorWithNode(node, messages.get("classesIllegalSuperCall", methodName));
|
||||
}
|
||||
} else if (t.isMemberExpression(callee) && isSuper(callee.object, callee)) {
|
||||
// super.test(); -> _get(Object.getPrototypeOf(ClassName.prototype), "test", this).call(this);
|
||||
property = callee.property;
|
||||
computed = callee.computed;
|
||||
args = node.arguments;
|
||||
}
|
||||
} else if (t.isMemberExpression(node) && isSuper(node.object, node)) {
|
||||
// super.name; -> _get(Object.getPrototypeOf(ClassName.prototype), "name", this);
|
||||
property = node.property;
|
||||
computed = node.computed;
|
||||
} else if (t.isAssignmentExpression(node) && isSuper(node.left.object, node.left) && methodNode.kind === "set") {
|
||||
// super.name = "val"; -> _set(Object.getPrototypeOf(ClassName.prototype), "name", this);
|
||||
this.hasSuper = true;
|
||||
return this.setSuperProperty(node.left.property, node.right, node.left.computed, getThisReference());
|
||||
}
|
||||
|
||||
if (!property) return;
|
||||
|
||||
this.hasSuper = true;
|
||||
|
||||
thisReference = getThisReference();
|
||||
var superProperty = this.getSuperProperty(property, computed, thisReference);
|
||||
if (args) {
|
||||
if (args.length === 1 && t.isSpreadElement(args[0])) {
|
||||
// super(...arguments);
|
||||
return t.callExpression(
|
||||
t.memberExpression(superProperty, t.identifier("apply")),
|
||||
[thisReference, args[0].argument]
|
||||
);
|
||||
} else {
|
||||
return t.callExpression(
|
||||
t.memberExpression(superProperty, t.identifier("call")),
|
||||
[thisReference].concat(args)
|
||||
);
|
||||
}
|
||||
} else {
|
||||
return superProperty;
|
||||
}
|
||||
};
|
||||
|
||||
var isIllegalBareSuper = function (node, parent) {
|
||||
if (!isSuper(node, parent)) return false;
|
||||
if (t.isMemberExpression(parent, { computed: false })) return false;
|
||||
if (t.isCallExpression(parent, { callee: node })) return false;
|
||||
return true;
|
||||
};
|
||||
|
||||
var isSuper = function (node, parent) {
|
||||
return t.isIdentifier(node, { name: "super" }) && t.isReferenced(node, parent);
|
||||
};
|
||||
@@ -1,293 +0,0 @@
|
||||
"use strict";
|
||||
|
||||
module.exports = DefaultFormatter;
|
||||
|
||||
var messages = require("../../messages");
|
||||
var extend = require("lodash/object/extend");
|
||||
var object = require("../../helpers/object");
|
||||
var util = require("../../util");
|
||||
var t = require("../../types");
|
||||
|
||||
function DefaultFormatter(file) {
|
||||
this.scope = file.scope;
|
||||
this.file = file;
|
||||
this.ids = object();
|
||||
|
||||
this.hasNonDefaultExports = false;
|
||||
|
||||
this.hasLocalExports = false;
|
||||
this.hasLocalImports = false;
|
||||
|
||||
this.localImportOccurences = object();
|
||||
this.localExports = object();
|
||||
this.localImports = object();
|
||||
|
||||
this.getLocalExports();
|
||||
this.getLocalImports();
|
||||
|
||||
this.remapAssignments();
|
||||
}
|
||||
|
||||
DefaultFormatter.prototype.doDefaultExportInterop = function (node) {
|
||||
return node.default && !this.noInteropRequireExport && !this.hasNonDefaultExports;
|
||||
};
|
||||
|
||||
DefaultFormatter.prototype.bumpImportOccurences = function (node) {
|
||||
var source = node.source.value;
|
||||
var occurs = this.localImportOccurences;
|
||||
occurs[source] = occurs[source] || 0;
|
||||
occurs[source] += node.specifiers.length;
|
||||
};
|
||||
|
||||
var exportsVisitor = {
|
||||
enter: function (node, parent, scope, formatter) {
|
||||
var declar = node && node.declaration;
|
||||
if (t.isExportDeclaration(node)) {
|
||||
formatter.hasLocalImports = true;
|
||||
|
||||
if (declar && t.isStatement(declar)) {
|
||||
extend(formatter.localExports, t.getBindingIdentifiers(declar));
|
||||
}
|
||||
|
||||
if (!node.default) {
|
||||
formatter.hasNonDefaultExports = true;
|
||||
}
|
||||
|
||||
if (node.source) {
|
||||
formatter.bumpImportOccurences(node);
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
DefaultFormatter.prototype.getLocalExports = function () {
|
||||
this.file.scope.traverse(this.file.ast, exportsVisitor, this);
|
||||
};
|
||||
|
||||
var importsVisitor = {
|
||||
enter: function (node, parent, scope, formatter) {
|
||||
if (t.isImportDeclaration(node)) {
|
||||
formatter.hasLocalImports = true;
|
||||
extend(formatter.localImports, t.getBindingIdentifiers(node));
|
||||
formatter.bumpImportOccurences(node);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
DefaultFormatter.prototype.getLocalImports = function () {
|
||||
this.file.scope.traverse(this.file.ast, importsVisitor, this);
|
||||
};
|
||||
|
||||
var remapVisitor = {
|
||||
enter: function (node, parent, scope, formatter) {
|
||||
if (t.isUpdateExpression(node) && formatter.isLocalReference(node.argument, scope)) {
|
||||
this.skip();
|
||||
|
||||
// expand to long file assignment expression
|
||||
var assign = t.assignmentExpression(node.operator[0] + "=", node.argument, t.literal(1));
|
||||
|
||||
// remap this assignment expression
|
||||
var remapped = formatter.remapExportAssignment(assign);
|
||||
|
||||
// we don't need to change the result
|
||||
if (t.isExpressionStatement(parent) || node.prefix) {
|
||||
return remapped;
|
||||
}
|
||||
|
||||
var nodes = [];
|
||||
nodes.push(remapped);
|
||||
|
||||
var operator;
|
||||
if (node.operator === "--") {
|
||||
operator = "+";
|
||||
} else { // "++"
|
||||
operator = "-";
|
||||
}
|
||||
nodes.push(t.binaryExpression(operator, node.argument, t.literal(1)));
|
||||
|
||||
return t.sequenceExpression(nodes);
|
||||
}
|
||||
|
||||
if (t.isAssignmentExpression(node) && formatter.isLocalReference(node.left, scope)) {
|
||||
this.skip();
|
||||
return formatter.remapExportAssignment(node);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
DefaultFormatter.prototype.remapAssignments = function () {
|
||||
if (this.hasLocalImports) {
|
||||
this.file.scope.traverse(this.file.ast, remapVisitor, this);
|
||||
}
|
||||
};
|
||||
|
||||
DefaultFormatter.prototype.isLocalReference = function (node) {
|
||||
var localImports = this.localImports;
|
||||
return t.isIdentifier(node) && localImports[node.name] && localImports[node.name] !== node;
|
||||
};
|
||||
|
||||
DefaultFormatter.prototype.remapExportAssignment = function (node) {
|
||||
return t.assignmentExpression(
|
||||
"=",
|
||||
node.left,
|
||||
t.assignmentExpression(
|
||||
node.operator,
|
||||
t.memberExpression(t.identifier("exports"), node.left),
|
||||
node.right
|
||||
)
|
||||
);
|
||||
};
|
||||
|
||||
DefaultFormatter.prototype.isLocalReference = function (node, scope) {
|
||||
var localExports = this.localExports;
|
||||
var name = node.name;
|
||||
return t.isIdentifier(node) && localExports[name] && localExports[name] === scope.getBindingIdentifier(name);
|
||||
};
|
||||
|
||||
DefaultFormatter.prototype.getModuleName = function () {
|
||||
var opts = this.file.opts;
|
||||
var filenameRelative = opts.filenameRelative;
|
||||
var moduleName = "";
|
||||
|
||||
if (opts.moduleRoot) {
|
||||
moduleName = opts.moduleRoot + "/";
|
||||
}
|
||||
|
||||
if (!opts.filenameRelative) {
|
||||
return moduleName + opts.filename.replace(/^\//, "");
|
||||
}
|
||||
|
||||
if (opts.sourceRoot) {
|
||||
// remove sourceRoot from filename
|
||||
var sourceRootRegEx = new RegExp("^" + opts.sourceRoot + "\/?");
|
||||
filenameRelative = filenameRelative.replace(sourceRootRegEx, "");
|
||||
}
|
||||
|
||||
if (!opts.keepModuleIdExtensions) {
|
||||
// remove extension
|
||||
filenameRelative = filenameRelative.replace(/\.(\w*?)$/, "");
|
||||
}
|
||||
|
||||
moduleName += filenameRelative;
|
||||
|
||||
// normalize path separators
|
||||
moduleName = moduleName.replace(/\\/g, "/");
|
||||
|
||||
return moduleName;
|
||||
};
|
||||
|
||||
DefaultFormatter.prototype._pushStatement = function (ref, nodes) {
|
||||
if (t.isClass(ref) || t.isFunction(ref)) {
|
||||
if (ref.id) {
|
||||
nodes.push(t.toStatement(ref));
|
||||
ref = ref.id;
|
||||
}
|
||||
}
|
||||
|
||||
return ref;
|
||||
};
|
||||
|
||||
DefaultFormatter.prototype._hoistExport = function (declar, assign, priority) {
|
||||
if (t.isFunctionDeclaration(declar)) {
|
||||
assign._blockHoist = priority || 2;
|
||||
}
|
||||
|
||||
return assign;
|
||||
};
|
||||
|
||||
DefaultFormatter.prototype.getExternalReference = function (node, nodes) {
|
||||
var ids = this.ids;
|
||||
var id = node.source.value;
|
||||
|
||||
if (ids[id]) {
|
||||
return ids[id];
|
||||
} else {
|
||||
return this.ids[id] = this._getExternalReference(node, nodes);
|
||||
}
|
||||
};
|
||||
|
||||
DefaultFormatter.prototype.checkExportIdentifier = function (node) {
|
||||
if (t.isIdentifier(node, { name: "__esModule" })) {
|
||||
throw this.file.errorWithNode(node, messages.get("modulesIllegalExportName", node.name));
|
||||
}
|
||||
};
|
||||
|
||||
DefaultFormatter.prototype.exportSpecifier = function (specifier, node, nodes) {
|
||||
if (node.source) {
|
||||
var ref = this.getExternalReference(node, nodes);
|
||||
|
||||
if (t.isExportBatchSpecifier(specifier)) {
|
||||
// export * from "foo";
|
||||
nodes.push(this.buildExportsWildcard(ref, node));
|
||||
} else {
|
||||
if (t.isSpecifierDefault(specifier) && !this.noInteropRequireExport) {
|
||||
// importing a default so we need to normalize it
|
||||
ref = t.callExpression(this.file.addHelper("interop-require"), [ref]);
|
||||
} else {
|
||||
ref = t.memberExpression(ref, t.getSpecifierId(specifier));
|
||||
}
|
||||
|
||||
// export { foo } from "test";
|
||||
nodes.push(this.buildExportsAssignment(
|
||||
t.getSpecifierName(specifier),
|
||||
ref,
|
||||
node
|
||||
));
|
||||
}
|
||||
} else {
|
||||
// export { foo };
|
||||
nodes.push(this.buildExportsAssignment(t.getSpecifierName(specifier), specifier.id, node));
|
||||
}
|
||||
};
|
||||
|
||||
DefaultFormatter.prototype.buildExportsWildcard = function (objectIdentifier) {
|
||||
return t.expressionStatement(t.callExpression(this.file.addHelper("defaults"), [
|
||||
t.identifier("exports"),
|
||||
t.callExpression(this.file.addHelper("interop-require-wildcard"), [objectIdentifier])
|
||||
]));
|
||||
};
|
||||
|
||||
DefaultFormatter.prototype.buildExportsAssignment = function (id, init) {
|
||||
this.checkExportIdentifier(id);
|
||||
return util.template("exports-assign", {
|
||||
VALUE: init,
|
||||
KEY: id
|
||||
}, true);
|
||||
};
|
||||
|
||||
DefaultFormatter.prototype.exportDeclaration = function (node, nodes) {
|
||||
var declar = node.declaration;
|
||||
|
||||
var id = declar.id;
|
||||
|
||||
if (node.default) {
|
||||
id = t.identifier("default");
|
||||
}
|
||||
|
||||
var assign;
|
||||
|
||||
if (t.isVariableDeclaration(declar)) {
|
||||
for (var i = 0; i < declar.declarations.length; i++) {
|
||||
var decl = declar.declarations[i];
|
||||
|
||||
decl.init = this.buildExportsAssignment(decl.id, decl.init, node).expression;
|
||||
|
||||
var newDeclar = t.variableDeclaration(declar.kind, [decl]);
|
||||
if (i === 0) t.inherits(newDeclar, declar);
|
||||
nodes.push(newDeclar);
|
||||
}
|
||||
} else {
|
||||
var ref = declar;
|
||||
|
||||
if (t.isFunctionDeclaration(declar) || t.isClassDeclaration(declar)) {
|
||||
ref = declar.id;
|
||||
nodes.push(declar);
|
||||
}
|
||||
|
||||
assign = this.buildExportsAssignment(id, ref, node);
|
||||
|
||||
nodes.push(assign);
|
||||
|
||||
this._hoistExport(declar, assign);
|
||||
}
|
||||
};
|
||||
@@ -1,3 +0,0 @@
|
||||
"use strict";
|
||||
|
||||
module.exports = require("./_strict")(require("./amd"));
|
||||
@@ -1,108 +0,0 @@
|
||||
"use strict";
|
||||
|
||||
module.exports = AMDFormatter;
|
||||
|
||||
var DefaultFormatter = require("./_default");
|
||||
var CommonFormatter = require("./common");
|
||||
var util = require("../../util");
|
||||
var t = require("../../types");
|
||||
var includes = require("lodash/collection/includes");
|
||||
var values = require("lodash/object/values");
|
||||
|
||||
function AMDFormatter() {
|
||||
CommonFormatter.apply(this, arguments);
|
||||
}
|
||||
|
||||
util.inherits(AMDFormatter, DefaultFormatter);
|
||||
|
||||
AMDFormatter.prototype.init = CommonFormatter.prototype.init;
|
||||
|
||||
AMDFormatter.prototype.buildDependencyLiterals = function () {
|
||||
var names = [];
|
||||
for (var name in this.ids) {
|
||||
names.push(t.literal(name));
|
||||
}
|
||||
return names;
|
||||
};
|
||||
|
||||
/**
|
||||
* Wrap the entire body in a `define` wrapper.
|
||||
*/
|
||||
|
||||
AMDFormatter.prototype.transform = function (program) {
|
||||
var body = program.body;
|
||||
|
||||
// build an array of module names
|
||||
|
||||
var names = [t.literal("exports")];
|
||||
if (this.passModuleArg) names.push(t.literal("module"));
|
||||
names = names.concat(this.buildDependencyLiterals());
|
||||
names = t.arrayExpression(names);
|
||||
|
||||
// build up define container
|
||||
|
||||
var params = values(this.ids);
|
||||
if (this.passModuleArg) params.unshift(t.identifier("module"));
|
||||
params.unshift(t.identifier("exports"));
|
||||
|
||||
var container = t.functionExpression(null, params, t.blockStatement(body));
|
||||
|
||||
var defineArgs = [names, container];
|
||||
var moduleName = this.getModuleName();
|
||||
if (moduleName) defineArgs.unshift(t.literal(moduleName));
|
||||
|
||||
var call = t.callExpression(t.identifier("define"), defineArgs);
|
||||
|
||||
program.body = [t.expressionStatement(call)];
|
||||
};
|
||||
|
||||
/**
|
||||
* Get the AMD module name that we'll prepend to the wrapper
|
||||
* to define this module
|
||||
*/
|
||||
|
||||
AMDFormatter.prototype.getModuleName = function () {
|
||||
if (this.file.opts.moduleIds) {
|
||||
return DefaultFormatter.prototype.getModuleName.apply(this, arguments);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
};
|
||||
|
||||
AMDFormatter.prototype._getExternalReference = function (node) {
|
||||
return this.scope.generateUidIdentifier(node.source.value);
|
||||
};
|
||||
|
||||
AMDFormatter.prototype.importDeclaration = function (node) {
|
||||
this.getExternalReference(node);
|
||||
};
|
||||
|
||||
AMDFormatter.prototype.importSpecifier = function (specifier, node, nodes) {
|
||||
var key = t.getSpecifierName(specifier);
|
||||
var ref = this.getExternalReference(node);
|
||||
|
||||
if (includes(this.file.dynamicImported, node)) {
|
||||
// Prevent unnecessary renaming of dynamic imports.
|
||||
this.ids[node.source.value] = ref;
|
||||
} else if (t.isImportBatchSpecifier(specifier)) {
|
||||
// import * as bar from "foo";
|
||||
} else if (t.isSpecifierDefault(specifier) && !this.noInteropRequireImport) {
|
||||
// import foo from "foo";
|
||||
ref = t.callExpression(this.file.addHelper("interop-require"), [ref]);
|
||||
} else {
|
||||
// import {foo} from "foo";
|
||||
ref = t.memberExpression(ref, t.getSpecifierId(specifier), false);
|
||||
}
|
||||
|
||||
nodes.push(t.variableDeclaration("var", [
|
||||
t.variableDeclarator(key, ref)
|
||||
]));
|
||||
};
|
||||
|
||||
AMDFormatter.prototype.exportDeclaration = function (node) {
|
||||
if (this.doDefaultExportInterop(node)) {
|
||||
this.passModuleArg = true;
|
||||
}
|
||||
|
||||
CommonFormatter.prototype.exportDeclaration.apply(this, arguments);
|
||||
};
|
||||
@@ -1,13 +0,0 @@
|
||||
"use strict";
|
||||
|
||||
module.exports = CommonStandardFormatter;
|
||||
|
||||
var CommonStrictFormatter = require("./common-strict");
|
||||
var util = require("../../util");
|
||||
|
||||
function CommonStandardFormatter() {
|
||||
this.noInteropRequireImport = true;
|
||||
CommonStrictFormatter.apply(this, arguments);
|
||||
}
|
||||
|
||||
util.inherits(CommonStandardFormatter, CommonStrictFormatter);
|
||||
@@ -1,3 +0,0 @@
|
||||
"use strict";
|
||||
|
||||
module.exports = require("./_strict")(require("./common"));
|
||||
@@ -1,104 +0,0 @@
|
||||
"use strict";
|
||||
|
||||
module.exports = CommonJSFormatter;
|
||||
|
||||
var DefaultFormatter = require("./_default");
|
||||
var includes = require("lodash/collection/includes");
|
||||
var util = require("../../util");
|
||||
var t = require("../../types");
|
||||
|
||||
function CommonJSFormatter() {
|
||||
DefaultFormatter.apply(this, arguments);
|
||||
}
|
||||
|
||||
util.inherits(CommonJSFormatter, DefaultFormatter);
|
||||
|
||||
CommonJSFormatter.prototype.init = function () {
|
||||
var file = this.file;
|
||||
var scope = file.scope;
|
||||
|
||||
scope.rename("module");
|
||||
|
||||
if (!this.noInteropRequireImport && this.hasNonDefaultExports) {
|
||||
file.ast.program.body.push(util.template("exports-module-declaration", true));
|
||||
}
|
||||
};
|
||||
|
||||
CommonJSFormatter.prototype.importSpecifier = function (specifier, node, nodes) {
|
||||
var variableName = t.getSpecifierName(specifier);
|
||||
|
||||
var ref = this.getExternalReference(node, nodes);
|
||||
|
||||
// import foo from "foo";
|
||||
if (t.isSpecifierDefault(specifier)) {
|
||||
if (!includes(this.file.dynamicImported, node)) {
|
||||
if (this.noInteropRequireImport) {
|
||||
ref = t.memberExpression(ref, t.identifier("default"));
|
||||
} else {
|
||||
ref = t.callExpression(this.file.addHelper("interop-require"), [ref]);
|
||||
}
|
||||
}
|
||||
nodes.push(t.variableDeclaration("var", [t.variableDeclarator(variableName, ref)]));
|
||||
} else {
|
||||
if (specifier.type === "ImportBatchSpecifier") {
|
||||
|
||||
if (!this.noInteropRequireImport) {
|
||||
ref = t.callExpression(this.file.addHelper("interop-require-wildcard"), [ref]);
|
||||
}
|
||||
|
||||
// import * as bar from "foo";
|
||||
nodes.push(t.variableDeclaration("var", [
|
||||
t.variableDeclarator(variableName, ref)
|
||||
]));
|
||||
} else {
|
||||
// import { foo } from "foo";
|
||||
nodes.push(t.variableDeclaration("var", [
|
||||
t.variableDeclarator(
|
||||
variableName,
|
||||
t.memberExpression(ref, t.getSpecifierId(specifier))
|
||||
)
|
||||
]));
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
CommonJSFormatter.prototype.importDeclaration = function (node, nodes) {
|
||||
// import "foo";
|
||||
nodes.push(util.template("require", {
|
||||
MODULE_NAME: node.source
|
||||
}, true));
|
||||
};
|
||||
|
||||
CommonJSFormatter.prototype.exportDeclaration = function (node, nodes) {
|
||||
if (this.doDefaultExportInterop(node)) {
|
||||
var declar = node.declaration;
|
||||
var assign = util.template("exports-default-assign", {
|
||||
VALUE: this._pushStatement(declar, nodes)
|
||||
}, true);
|
||||
|
||||
if (t.isFunctionDeclaration(declar)) {
|
||||
// we can hoist this assignment to the top of the file
|
||||
assign._blockHoist = 3;
|
||||
}
|
||||
|
||||
nodes.push(assign);
|
||||
return;
|
||||
}
|
||||
|
||||
DefaultFormatter.prototype.exportDeclaration.apply(this, arguments);
|
||||
};
|
||||
|
||||
CommonJSFormatter.prototype._getExternalReference = function (node, nodes) {
|
||||
var source = node.source.value;
|
||||
var call = t.callExpression(t.identifier("require"), [node.source]);
|
||||
|
||||
if (this.localImportOccurences[source] > 1) {
|
||||
var uid = this.scope.generateUidIdentifier(source);
|
||||
nodes.push(t.variableDeclaration("var", [
|
||||
t.variableDeclarator(uid, call)
|
||||
]));
|
||||
return uid;
|
||||
} else {
|
||||
return call;
|
||||
}
|
||||
};
|
||||
@@ -1,20 +0,0 @@
|
||||
"use strict";
|
||||
|
||||
module.exports = IgnoreFormatter;
|
||||
|
||||
var t = require("../../types");
|
||||
|
||||
function IgnoreFormatter() {
|
||||
|
||||
}
|
||||
|
||||
IgnoreFormatter.prototype.exportDeclaration = function (node, nodes) {
|
||||
var declar = t.toStatement(node.declaration, true);
|
||||
if (declar) nodes.push(t.inherits(declar, node));
|
||||
};
|
||||
|
||||
IgnoreFormatter.prototype.importDeclaration =
|
||||
IgnoreFormatter.prototype.importSpecifier =
|
||||
IgnoreFormatter.prototype.exportSpecifier = function () {
|
||||
|
||||
};
|
||||
@@ -1,11 +0,0 @@
|
||||
module.exports = {
|
||||
commonStandard: require("./common-standard"),
|
||||
commonStrict: require("./common-strict"),
|
||||
amdStrict: require("./amd-strict"),
|
||||
umdStrict: require("./umd-strict"),
|
||||
common: require("./common"),
|
||||
system: require("./system"),
|
||||
ignore: require("./ignore"),
|
||||
amd: require("./amd"),
|
||||
umd: require("./umd")
|
||||
};
|
||||
@@ -1,201 +0,0 @@
|
||||
"use strict";
|
||||
|
||||
module.exports = SystemFormatter;
|
||||
|
||||
var DefaultFormatter = require("./_default");
|
||||
var AMDFormatter = require("./amd");
|
||||
var useStrict = require("../helpers/use-strict");
|
||||
var util = require("../../util");
|
||||
var t = require("../../types");
|
||||
var last = require("lodash/array/last");
|
||||
var each = require("lodash/collection/each");
|
||||
var map = require("lodash/collection/map");
|
||||
|
||||
function SystemFormatter(file) {
|
||||
this.exportIdentifier = file.scope.generateUidIdentifier("export");
|
||||
this.noInteropRequireExport = true;
|
||||
this.noInteropRequireImport = true;
|
||||
|
||||
DefaultFormatter.apply(this, arguments);
|
||||
}
|
||||
|
||||
util.inherits(SystemFormatter, AMDFormatter);
|
||||
|
||||
SystemFormatter.prototype.init = function () {};
|
||||
|
||||
SystemFormatter.prototype._addImportSource = function (node, exportNode) {
|
||||
node._importSource = exportNode.source && exportNode.source.value;
|
||||
return node;
|
||||
};
|
||||
|
||||
SystemFormatter.prototype.buildExportsWildcard = function (objectIdentifier, node) {
|
||||
var leftIdentifier = this.scope.generateUidIdentifier("key");
|
||||
var valIdentifier = t.memberExpression(objectIdentifier, leftIdentifier, true);
|
||||
|
||||
var left = t.variableDeclaration("var", [
|
||||
t.variableDeclarator(leftIdentifier)
|
||||
]);
|
||||
|
||||
var right = objectIdentifier;
|
||||
|
||||
var block = t.blockStatement([
|
||||
t.expressionStatement(this.buildExportCall(leftIdentifier, valIdentifier))
|
||||
]);
|
||||
|
||||
return this._addImportSource(t.forInStatement(left, right, block), node);
|
||||
};
|
||||
|
||||
SystemFormatter.prototype.buildExportsAssignment = function (id, init, node) {
|
||||
var call = this.buildExportCall(t.literal(id.name), init, true);
|
||||
return this._addImportSource(call, node);
|
||||
};
|
||||
|
||||
SystemFormatter.prototype.remapExportAssignment = function (node) {
|
||||
return this.buildExportCall(t.literal(node.left.name), node);
|
||||
};
|
||||
|
||||
SystemFormatter.prototype.buildExportCall = function (id, init, isStatement) {
|
||||
var call = t.callExpression(this.exportIdentifier, [id, init]);
|
||||
if (isStatement) {
|
||||
return t.expressionStatement(call);
|
||||
} else {
|
||||
return call;
|
||||
}
|
||||
};
|
||||
|
||||
SystemFormatter.prototype.importSpecifier = function (specifier, node, nodes) {
|
||||
AMDFormatter.prototype.importSpecifier.apply(this, arguments);
|
||||
this._addImportSource(last(nodes), node);
|
||||
};
|
||||
|
||||
var runnerSettersVisitor = {
|
||||
enter: function (node, parent, scope, state) {
|
||||
if (node._importSource === state.source) {
|
||||
if (t.isVariableDeclaration(node)) {
|
||||
each(node.declarations, function (declar) {
|
||||
state.hoistDeclarators.push(t.variableDeclarator(declar.id));
|
||||
state.nodes.push(t.expressionStatement(
|
||||
t.assignmentExpression("=", declar.id, declar.init)
|
||||
));
|
||||
});
|
||||
} else {
|
||||
state.nodes.push(node);
|
||||
}
|
||||
|
||||
this.remove();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
SystemFormatter.prototype.buildRunnerSetters = function (block, hoistDeclarators) {
|
||||
var scope = this.file.scope;
|
||||
|
||||
return t.arrayExpression(map(this.ids, function (uid, source) {
|
||||
var state = {
|
||||
source: source,
|
||||
nodes: [],
|
||||
hoistDeclarators: hoistDeclarators
|
||||
};
|
||||
|
||||
scope.traverse(block, runnerSettersVisitor, state);
|
||||
|
||||
return t.functionExpression(null, [uid], t.blockStatement(state.nodes));
|
||||
}));
|
||||
};
|
||||
|
||||
var hoistVariablesVisitor = {
|
||||
enter: function (node, parent, scope, hoistDeclarators) {
|
||||
if (t.isFunction(node)) {
|
||||
// nothing inside is accessible
|
||||
return this.skip();
|
||||
}
|
||||
|
||||
if (t.isVariableDeclaration(node)) {
|
||||
if (node.kind !== "var" && !t.isProgram(parent)) { // let, const
|
||||
// can't be accessed
|
||||
return;
|
||||
}
|
||||
|
||||
// ignore block hoisted nodes as these can be left in
|
||||
if (node._blockHoist) return;
|
||||
|
||||
var nodes = [];
|
||||
|
||||
for (var i = 0; i < node.declarations.length; i++) {
|
||||
var declar = node.declarations[i];
|
||||
hoistDeclarators.push(t.variableDeclarator(declar.id));
|
||||
if (declar.init) {
|
||||
// no initializer so we can just hoist it as-is
|
||||
var assign = t.expressionStatement(t.assignmentExpression("=", declar.id, declar.init));
|
||||
nodes.push(assign);
|
||||
}
|
||||
}
|
||||
|
||||
// for (var i in test)
|
||||
// for (var i = 0;;)
|
||||
if (t.isFor(parent)) {
|
||||
if (parent.left === node) {
|
||||
return node.declarations[0].id;
|
||||
}
|
||||
|
||||
if (parent.init === node) {
|
||||
return t.toSequenceExpression(nodes, scope);
|
||||
}
|
||||
}
|
||||
|
||||
return nodes;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
var hoistFunctionsVisitor = {
|
||||
enter: function (node, parent, scope, handlerBody) {
|
||||
if (t.isFunction(node)) this.skip();
|
||||
|
||||
if (t.isFunctionDeclaration(node) || node._blockHoist) {
|
||||
handlerBody.push(node);
|
||||
this.remove();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
SystemFormatter.prototype.transform = function (program) {
|
||||
var hoistDeclarators = [];
|
||||
var moduleName = this.getModuleName();
|
||||
var moduleNameLiteral = t.literal(moduleName);
|
||||
|
||||
var block = t.blockStatement(program.body);
|
||||
|
||||
var runner = util.template("system", {
|
||||
MODULE_NAME: moduleNameLiteral,
|
||||
MODULE_DEPENDENCIES: t.arrayExpression(this.buildDependencyLiterals()),
|
||||
EXPORT_IDENTIFIER: this.exportIdentifier,
|
||||
SETTERS: this.buildRunnerSetters(block, hoistDeclarators),
|
||||
EXECUTE: t.functionExpression(null, [], block)
|
||||
}, true);
|
||||
|
||||
var handlerBody = runner.expression.arguments[2].body.body;
|
||||
if (!moduleName) runner.expression.arguments.shift();
|
||||
|
||||
var returnStatement = handlerBody.pop();
|
||||
|
||||
// hoist up all variable declarations
|
||||
this.file.scope.traverse(block, hoistVariablesVisitor, hoistDeclarators);
|
||||
|
||||
if (hoistDeclarators.length) {
|
||||
var hoistDeclar = t.variableDeclaration("var", hoistDeclarators);
|
||||
hoistDeclar._blockHoist = true;
|
||||
handlerBody.unshift(hoistDeclar);
|
||||
}
|
||||
|
||||
// hoist up function declarations for circular references
|
||||
this.file.scope.traverse(block, hoistFunctionsVisitor, handlerBody);
|
||||
|
||||
handlerBody.push(returnStatement);
|
||||
|
||||
if (useStrict.has(block)) {
|
||||
handlerBody.unshift(block.body.shift());
|
||||
}
|
||||
|
||||
program.body = [runner];
|
||||
};
|
||||
@@ -1,3 +0,0 @@
|
||||
"use strict";
|
||||
|
||||
module.exports = require("./_strict")(require("./umd"));
|
||||
@@ -1,73 +0,0 @@
|
||||
"use strict";
|
||||
|
||||
module.exports = UMDFormatter;
|
||||
|
||||
var AMDFormatter = require("./amd");
|
||||
var util = require("../../util");
|
||||
var t = require("../../types");
|
||||
var values = require("lodash/object/values");
|
||||
|
||||
function UMDFormatter() {
|
||||
AMDFormatter.apply(this, arguments);
|
||||
}
|
||||
|
||||
util.inherits(UMDFormatter, AMDFormatter);
|
||||
|
||||
UMDFormatter.prototype.transform = function (program) {
|
||||
var body = program.body;
|
||||
|
||||
// build an array of module names
|
||||
|
||||
var names = [];
|
||||
for (var name in this.ids) {
|
||||
names.push(t.literal(name));
|
||||
}
|
||||
|
||||
// factory
|
||||
|
||||
var ids = values(this.ids);
|
||||
var args = [t.identifier("exports")];
|
||||
if (this.passModuleArg) args.push(t.identifier("module"));
|
||||
args = args.concat(ids);
|
||||
|
||||
var factory = t.functionExpression(null, args, t.blockStatement(body));
|
||||
|
||||
// amd
|
||||
|
||||
var defineArgs = [t.literal("exports")];
|
||||
if (this.passModuleArg) defineArgs.push(t.literal("module"));
|
||||
defineArgs = defineArgs.concat(names);
|
||||
defineArgs = [t.arrayExpression(defineArgs)];
|
||||
|
||||
// common
|
||||
|
||||
var testExports = util.template("test-exports");
|
||||
var testModule = util.template("test-module");
|
||||
var commonTests = this.passModuleArg ? t.logicalExpression("&&", testExports, testModule) : testExports;
|
||||
|
||||
var commonArgs = [t.identifier("exports")];
|
||||
if (this.passModuleArg) commonArgs.push(t.identifier("module"));
|
||||
commonArgs = commonArgs.concat(names.map(function (name) {
|
||||
return t.callExpression(t.identifier("require"), [name]);
|
||||
}));
|
||||
|
||||
// globals
|
||||
|
||||
//var umdArgs = [];
|
||||
|
||||
//
|
||||
|
||||
var moduleName = this.getModuleName();
|
||||
if (moduleName) defineArgs.unshift(t.literal(moduleName));
|
||||
|
||||
var runner = util.template("umd-runner-body", {
|
||||
AMD_ARGUMENTS: defineArgs,
|
||||
COMMON_TEST: commonTests,
|
||||
COMMON_ARGUMENTS: commonArgs
|
||||
});
|
||||
|
||||
//
|
||||
|
||||
var call = t.callExpression(runner, [factory]);
|
||||
program.body = [t.expressionStatement(call)];
|
||||
};
|
||||
@@ -1,3 +0,0 @@
|
||||
{
|
||||
"blacklist": ["useStrict"]
|
||||
}
|
||||
@@ -1,5 +0,0 @@
|
||||
(function (Constructor, args) {
|
||||
var instance = Object.create(Constructor.prototype);
|
||||
var result = Constructor.apply(instance, args);
|
||||
return result != null && (typeof result == "object" || typeof result == "function") ? result : instance;
|
||||
});
|
||||
@@ -1 +0,0 @@
|
||||
CORE_ID.$for.isIterable(VALUE);
|
||||
@@ -1 +0,0 @@
|
||||
CORE_ID.$for.getIterator(VALUE);
|
||||
@@ -1,3 +0,0 @@
|
||||
for (var ITERATOR_KEY = OBJECT[Symbol.iterator](), STEP_KEY; !(STEP_KEY = ITERATOR_KEY.next()).done; ) {
|
||||
|
||||
}
|
||||
@@ -1,4 +0,0 @@
|
||||
(function (child, staticProps, instanceProps) {
|
||||
if (staticProps) Object.defineProperties(child, staticProps);
|
||||
if (instanceProps) Object.defineProperties(child.prototype, instanceProps);
|
||||
})
|
||||
@@ -1,3 +0,0 @@
|
||||
{
|
||||
FUNCTION_ID:while (true) BLOCK
|
||||
}
|
||||
@@ -1,23 +0,0 @@
|
||||
(function () {
|
||||
function Tail(func, args, context) {
|
||||
this.func = func;
|
||||
this.args = args;
|
||||
this.context = context;
|
||||
}
|
||||
|
||||
Tail.prototype._isTailDescriptor = true;
|
||||
|
||||
var isRunning = false;
|
||||
|
||||
return function (func, args, context) {
|
||||
var result = new Tail(func, args, context);
|
||||
if (!isRunning) {
|
||||
isRunning = true;
|
||||
do {
|
||||
result = result.func.apply(result.context, result.args);
|
||||
} while (result instanceof Tail || (result && result._isTailDescriptor));
|
||||
isRunning = false;
|
||||
}
|
||||
return result;
|
||||
};
|
||||
})()
|
||||
@@ -1,63 +0,0 @@
|
||||
module.exports = TransformerPass;
|
||||
|
||||
var includes = require("lodash/collection/includes");
|
||||
|
||||
/**
|
||||
* 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.shouldRun = !transformer.check;
|
||||
this.handlers = transformer.handlers;
|
||||
this.file = file;
|
||||
}
|
||||
|
||||
TransformerPass.prototype.canRun = function () {
|
||||
var transformer = this.transformer;
|
||||
|
||||
var opts = this.file.opts;
|
||||
var key = transformer.key;
|
||||
|
||||
// internal
|
||||
if (key[0] === "_") return true;
|
||||
|
||||
// blacklist
|
||||
var blacklist = opts.blacklist;
|
||||
if (blacklist.length && includes(blacklist, key)) return false;
|
||||
|
||||
// whitelist
|
||||
var whitelist = opts.whitelist;
|
||||
if (whitelist.length) return includes(whitelist, key);
|
||||
|
||||
// optional
|
||||
if (transformer.optional && !includes(opts.optional, key)) return false;
|
||||
|
||||
// experimental
|
||||
if (transformer.experimental && !opts.experimental) return false;
|
||||
|
||||
// playground
|
||||
if (transformer.playground && !opts.playground) return false;
|
||||
|
||||
return true;
|
||||
};
|
||||
|
||||
TransformerPass.prototype.checkNode = function (node) {
|
||||
var check = this.transformer.check;
|
||||
if (check) {
|
||||
return this.shouldRun = check(node);
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
TransformerPass.prototype.transform = function () {
|
||||
if (!this.shouldRun) return;
|
||||
|
||||
var file = this.file;
|
||||
|
||||
file.debug("Running transformer " + this.transformer.key);
|
||||
|
||||
file.scope.traverse(file.ast, this.handlers, file);
|
||||
};
|
||||
@@ -1,73 +0,0 @@
|
||||
"use strict";
|
||||
|
||||
module.exports = Transformer;
|
||||
|
||||
var TransformerPass = require("./transformer-pass");
|
||||
var isFunction = require("lodash/lang/isFunction");
|
||||
var traverse = require("../traversal");
|
||||
var isObject = require("lodash/lang/isObject");
|
||||
var clone = require("../helpers/clone");
|
||||
var each = require("lodash/collection/each");
|
||||
|
||||
/**
|
||||
* 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) {
|
||||
transformer = clone(transformer);
|
||||
|
||||
var take = function (key) {
|
||||
var val = transformer[key];
|
||||
delete transformer[key];
|
||||
return val;
|
||||
};
|
||||
|
||||
this.manipulateOptions = take("manipulateOptions");
|
||||
this.check = take("check");
|
||||
this.post = take("post");
|
||||
this.pre = take("pre");
|
||||
|
||||
this.experimental = !!take("experimental");
|
||||
this.playground = !!take("playground");
|
||||
this.secondPass = !!take("secondPass");
|
||||
this.optional = !!take("optional");
|
||||
|
||||
this.handlers = this.normalize(transformer);
|
||||
this.opts = opts || {};
|
||||
this.key = key;
|
||||
}
|
||||
|
||||
Transformer.prototype.normalize = function (transformer) {
|
||||
var self = this;
|
||||
|
||||
if (isFunction(transformer)) {
|
||||
transformer = { ast: transformer };
|
||||
}
|
||||
|
||||
traverse.explode(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 = function () { };
|
||||
if (!fns.exit) fns.exit = function () { };
|
||||
|
||||
transformer[type] = fns;
|
||||
});
|
||||
|
||||
return transformer;
|
||||
};
|
||||
|
||||
Transformer.prototype.buildPass = function (file) {
|
||||
return new TransformerPass(file, this);
|
||||
};
|
||||
@@ -1,41 +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.objectRestSpread",
|
||||
"es7.objectSpread": "es7.objectRestSpread",
|
||||
"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": "es3.propertyLiterals",
|
||||
"specMemberExpressionLiterals": "es3.memberExpressionLiterals",
|
||||
"minification.propertyLiterals": "es3.propertyLiterals",
|
||||
"minification.memberExpressionLiterals": "es3.memberExpressionLiterals"
|
||||
}
|
||||
@@ -1,15 +0,0 @@
|
||||
"use strict";
|
||||
|
||||
var t = require("../../../types");
|
||||
|
||||
exports.check = t.isArrowFunctionExpression;
|
||||
|
||||
exports.ArrowFunctionExpression = function (node) {
|
||||
t.ensureBlock(node);
|
||||
|
||||
node._aliasFunction = "arrow";
|
||||
node.expression = false;
|
||||
node.type = "FunctionExpression";
|
||||
|
||||
return node;
|
||||
};
|
||||
@@ -1,540 +0,0 @@
|
||||
"use strict";
|
||||
|
||||
var traverse = require("../../../traversal");
|
||||
var object = require("../../../helpers/object");
|
||||
var util = require("../../../util");
|
||||
var t = require("../../../types");
|
||||
var values = require("lodash/object/values");
|
||||
var extend = require("lodash/object/extend");
|
||||
|
||||
exports.check = function (node) {
|
||||
return t.isVariableDeclaration(node) && (node.kind === "let" || node.kind === "const");
|
||||
};
|
||||
|
||||
var isLet = function (node, parent) {
|
||||
if (!t.isVariableDeclaration(node)) return false;
|
||||
if (node._let) return true;
|
||||
if (node.kind !== "let") return false;
|
||||
|
||||
// https://github.com/6to5/6to5/issues/255
|
||||
if (isLetInitable(node, parent)) {
|
||||
for (var i = 0; i < node.declarations.length; i++) {
|
||||
var declar = node.declarations[i];
|
||||
declar.init = declar.init || t.identifier("undefined");
|
||||
}
|
||||
}
|
||||
|
||||
node._let = true;
|
||||
node.kind = "var";
|
||||
return true;
|
||||
};
|
||||
|
||||
var isLetInitable = function (node, parent) {
|
||||
return !t.isFor(parent) || t.isFor(parent) && parent.left !== node;
|
||||
};
|
||||
|
||||
var isVar = function (node, parent) {
|
||||
return t.isVariableDeclaration(node, { kind: "var" }) && !isLet(node, parent);
|
||||
};
|
||||
|
||||
var standardizeLets = function (declars) {
|
||||
for (var i = 0; i < declars.length; i++) {
|
||||
delete declars[i]._let;
|
||||
}
|
||||
};
|
||||
|
||||
exports.VariableDeclaration = function (node, parent, scope, file) {
|
||||
if (!isLet(node, parent)) return;
|
||||
|
||||
if (isLetInitable(node) && file.transformers["es6.blockScopingTDZ"].canRun()) {
|
||||
var nodes = [node];
|
||||
|
||||
for (var i = 0; i < node.declarations.length; i++) {
|
||||
var decl = node.declarations[i];
|
||||
if (decl.init) {
|
||||
var assign = t.assignmentExpression("=", decl.id, decl.init);
|
||||
assign._ignoreBlockScopingTDZ = true;
|
||||
nodes.push(t.expressionStatement(assign));
|
||||
}
|
||||
decl.init = file.addHelper("temporal-undefined");
|
||||
}
|
||||
|
||||
node._blockHoist = 2;
|
||||
|
||||
return nodes;
|
||||
}
|
||||
};
|
||||
|
||||
exports.Loop = function (node, parent, scope, file) {
|
||||
var init = node.left || node.init;
|
||||
if (isLet(init, node)) {
|
||||
t.ensureBlock(node);
|
||||
node.body._letDeclarators = [init];
|
||||
}
|
||||
var blockScoping = new BlockScoping(node, node.body, parent, scope, file);
|
||||
blockScoping.run();
|
||||
};
|
||||
|
||||
exports.Program =
|
||||
exports.BlockStatement = function (block, parent, scope, file) {
|
||||
if (!t.isLoop(parent)) {
|
||||
var blockScoping = new BlockScoping(false, block, parent, scope, file);
|
||||
blockScoping.run();
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Description
|
||||
*
|
||||
* @param {Boolean|Node} loopParent
|
||||
* @param {Node} block
|
||||
* @param {Node} parent
|
||||
* @param {Scope} scope
|
||||
* @param {File} file
|
||||
*/
|
||||
|
||||
function BlockScoping(loopParent, block, parent, scope, file) {
|
||||
this.loopParent = loopParent;
|
||||
this.parent = parent;
|
||||
this.scope = scope;
|
||||
this.block = block;
|
||||
this.file = file;
|
||||
|
||||
this.outsideLetReferences = object();
|
||||
this.hasLetReferences = false;
|
||||
this.letReferences = block._letReferences = object();
|
||||
this.body = [];
|
||||
}
|
||||
|
||||
/**
|
||||
* Start the ball rolling.
|
||||
*/
|
||||
|
||||
BlockScoping.prototype.run = function () {
|
||||
var block = this.block;
|
||||
if (block._letDone) return;
|
||||
block._letDone = true;
|
||||
|
||||
var needsClosure = this.getLetReferences();
|
||||
|
||||
// this is a block within a `Function/Program` so we can safely leave it be
|
||||
if (t.isFunction(this.parent) || t.isProgram(this.block)) return;
|
||||
|
||||
// we can skip everything
|
||||
if (!this.hasLetReferences) return;
|
||||
|
||||
if (needsClosure) {
|
||||
this.needsClosure();
|
||||
} else {
|
||||
this.remap();
|
||||
}
|
||||
};
|
||||
|
||||
function replace(node, parent, scope, remaps) {
|
||||
if (!t.isReferencedIdentifier(node, parent)) return;
|
||||
|
||||
var remap = remaps[node.name];
|
||||
if (!remap) return;
|
||||
|
||||
var ownBinding = scope.getBindingIdentifier(node.name);
|
||||
if (ownBinding === remap.binding) {
|
||||
node.name = remap.uid;
|
||||
} else {
|
||||
// scope already has it's own binding that doesn't
|
||||
// match the one we have a stored replacement for
|
||||
if (this) this.skip();
|
||||
}
|
||||
}
|
||||
|
||||
var replaceVisitor = {
|
||||
enter: replace
|
||||
};
|
||||
|
||||
function traverseReplace(node, parent, scope, remaps) {
|
||||
replace(node, parent, scope, remaps);
|
||||
scope.traverse(node, replaceVisitor, remaps);
|
||||
}
|
||||
|
||||
/**
|
||||
* Description
|
||||
*/
|
||||
|
||||
BlockScoping.prototype.remap = function () {
|
||||
var hasRemaps = false;
|
||||
var letRefs = this.letReferences;
|
||||
var scope = this.scope;
|
||||
|
||||
// alright, so since we aren't wrapping this block in a closure
|
||||
// we have to check if any of our let variables collide with
|
||||
// those in upper scopes and then if they do, generate a uid
|
||||
// for them and replace all references with it
|
||||
var remaps = object();
|
||||
|
||||
for (var key in letRefs) {
|
||||
// just an Identifier node we collected in `getLetReferences`
|
||||
// this is the defining identifier of a declaration
|
||||
var ref = letRefs[key];
|
||||
|
||||
if (scope.parentHasBinding(key) || scope.hasGlobal(key)) {
|
||||
var uid = scope.generateUidIdentifier(ref.name).name;
|
||||
ref.name = uid;
|
||||
|
||||
hasRemaps = true;
|
||||
remaps[key] = remaps[uid] = {
|
||||
binding: ref,
|
||||
uid: uid
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
if (!hasRemaps) return;
|
||||
|
||||
//
|
||||
|
||||
var loopParent = this.loopParent;
|
||||
if (loopParent) {
|
||||
traverseReplace(loopParent.right, loopParent, scope, remaps);
|
||||
traverseReplace(loopParent.test, loopParent, scope, remaps);
|
||||
traverseReplace(loopParent.update, loopParent, scope, remaps);
|
||||
}
|
||||
|
||||
scope.traverse(this.block, replaceVisitor, remaps);
|
||||
};
|
||||
|
||||
/**
|
||||
* Description
|
||||
*/
|
||||
|
||||
BlockScoping.prototype.needsClosure = function () {
|
||||
var block = this.block;
|
||||
|
||||
// if we're inside of a for loop then we search to see if there are any
|
||||
// `break`s, `continue`s, `return`s etc
|
||||
this.has = this.checkLoop();
|
||||
|
||||
// hoist var references to retain scope
|
||||
this.hoistVarDeclarations();
|
||||
|
||||
// turn outsideLetReferences into an array
|
||||
var params = values(this.outsideLetReferences);
|
||||
|
||||
// build the closure that we're going to wrap the block with
|
||||
var fn = t.functionExpression(null, params, t.blockStatement(block.body));
|
||||
fn._aliasFunction = true;
|
||||
|
||||
// replace the current block body with the one we're going to build
|
||||
block.body = this.body;
|
||||
|
||||
// build a call and a unique id that we can assign the return value to
|
||||
var call = t.callExpression(fn, params);
|
||||
var ret = this.scope.generateUidIdentifier("ret");
|
||||
|
||||
// handle generators
|
||||
var hasYield = traverse.hasType(fn.body, this.scope, "YieldExpression", t.FUNCTION_TYPES);
|
||||
if (hasYield) {
|
||||
fn.generator = true;
|
||||
call = t.yieldExpression(call, true);
|
||||
}
|
||||
|
||||
// handlers async functions
|
||||
var hasAsync = traverse.hasType(fn.body, this.scope, "AwaitExpression", t.FUNCTION_TYPES);
|
||||
if (hasAsync) {
|
||||
fn.async = true;
|
||||
call = t.awaitExpression(call, true);
|
||||
}
|
||||
|
||||
this.build(ret, call);
|
||||
};
|
||||
|
||||
var letReferenceFunctionVisitor = {
|
||||
enter: function (node, parent, scope, state) {
|
||||
// not a direct reference
|
||||
if (!t.isReferencedIdentifier(node, parent)) return;
|
||||
|
||||
// this scope has a variable with the same name so it couldn't belong
|
||||
// to our let scope
|
||||
if (scope.hasOwnBinding(node.name)) return;
|
||||
|
||||
// not a part of our scope
|
||||
if (!state.letReferences[node.name]) return;
|
||||
|
||||
state.closurify = true;
|
||||
}
|
||||
};
|
||||
|
||||
var letReferenceBlockVisitor = {
|
||||
enter: function (node, parent, scope, state) {
|
||||
if (t.isFunction(node)) {
|
||||
scope.traverse(node, letReferenceFunctionVisitor, state);
|
||||
return this.skip();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Description
|
||||
*/
|
||||
|
||||
BlockScoping.prototype.getLetReferences = function () {
|
||||
var block = this.block;
|
||||
|
||||
var declarators = block._letDeclarators || [];
|
||||
var declar;
|
||||
|
||||
//
|
||||
for (var i = 0; i < declarators.length; i++) {
|
||||
declar = declarators[i];
|
||||
extend(this.outsideLetReferences, t.getBindingIdentifiers(declar));
|
||||
}
|
||||
|
||||
//
|
||||
if (block.body) {
|
||||
for (i = 0; i < block.body.length; i++) {
|
||||
declar = block.body[i];
|
||||
if (isLet(declar, block)) {
|
||||
declarators = declarators.concat(declar.declarations);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
for (i = 0; i < declarators.length; i++) {
|
||||
declar = declarators[i];
|
||||
var keys = t.getBindingIdentifiers(declar);
|
||||
extend(this.letReferences, keys);
|
||||
this.hasLetReferences = true;
|
||||
}
|
||||
|
||||
// no let references so we can just quit
|
||||
if (!this.hasLetReferences) return;
|
||||
|
||||
// set let references to plain var references
|
||||
standardizeLets(declarators);
|
||||
|
||||
var state = {
|
||||
letReferences: this.letReferences,
|
||||
closurify: false
|
||||
};
|
||||
|
||||
// traverse through this block, stopping on functions and checking if they
|
||||
// contain any local let references
|
||||
this.scope.traverse(this.block, letReferenceBlockVisitor, state);
|
||||
|
||||
return state.closurify;
|
||||
};
|
||||
|
||||
var loopNodeTo = function (node) {
|
||||
if (t.isBreakStatement(node)) {
|
||||
return "break";
|
||||
} else if (t.isContinueStatement(node)) {
|
||||
return "continue";
|
||||
}
|
||||
};
|
||||
|
||||
var loopVisitor = {
|
||||
enter: function (node, parent, scope, state) {
|
||||
var replace;
|
||||
|
||||
if (t.isLoop(node)) {
|
||||
state.ignoreLabeless = true;
|
||||
scope.traverse(node, loopVisitor, state);
|
||||
state.ignoreLabeless = false;
|
||||
}
|
||||
|
||||
if (t.isFunction(node) || t.isLoop(node)) {
|
||||
return this.skip();
|
||||
}
|
||||
|
||||
var loopText = loopNodeTo(node);
|
||||
|
||||
if (loopText) {
|
||||
if (node.label) {
|
||||
// we shouldn't be transforming this because it exists somewhere inside
|
||||
if (state.innerLabels.indexOf(node.label.name) >= 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
loopText = loopText + "|" + node.label.name;
|
||||
} else {
|
||||
// we shouldn't be transforming these statements because
|
||||
// they don't refer to the actual loop we're scopifying
|
||||
if (state.ignoreLabeless) return;
|
||||
|
||||
// break statements mean something different in this context
|
||||
if (t.isBreakStatement(node) && t.isSwitchCase(parent)) return;
|
||||
}
|
||||
|
||||
state.hasBreakContinue = true;
|
||||
state.map[loopText] = node;
|
||||
replace = t.literal(loopText);
|
||||
}
|
||||
|
||||
if (t.isReturnStatement(node)) {
|
||||
state.hasReturn = true;
|
||||
replace = t.objectExpression([
|
||||
t.property("init", t.identifier("v"), node.argument || t.identifier("undefined"))
|
||||
]);
|
||||
}
|
||||
|
||||
if (replace) {
|
||||
replace = t.returnStatement(replace);
|
||||
return t.inherits(replace, node);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
var loopLabelVisitor = {
|
||||
enter: function (node, parent, scope, state) {
|
||||
if (t.isLabeledStatement(node)) {
|
||||
state.innerLabels.push(node.label.name);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* If we're inside of a loop then traverse it and check if it has one of
|
||||
* the following node types `ReturnStatement`, `BreakStatement`,
|
||||
* `ContinueStatement` and replace it with a return value that we can track
|
||||
* later on.
|
||||
*
|
||||
* @returns {Object}
|
||||
*/
|
||||
|
||||
BlockScoping.prototype.checkLoop = function () {
|
||||
var state = {
|
||||
hasBreakContinue: false,
|
||||
ignoreLabeless: false,
|
||||
innerLabels: [],
|
||||
hasReturn: false,
|
||||
isLoop: !!this.loopParent,
|
||||
map: {}
|
||||
};
|
||||
|
||||
this.scope.traverse(this.block, loopLabelVisitor, state);
|
||||
this.scope.traverse(this.block, loopVisitor, state);
|
||||
|
||||
return state;
|
||||
};
|
||||
|
||||
var hoistVarDeclarationsVisitor = {
|
||||
enter: function (node, parent, scope, self) {
|
||||
if (t.isForStatement(node)) {
|
||||
if (isVar(node.init, node)) {
|
||||
node.init = t.sequenceExpression(self.pushDeclar(node.init));
|
||||
}
|
||||
} else if (t.isFor(node)) {
|
||||
if (isVar(node.left, node)) {
|
||||
node.left = node.left.declarations[0].id;
|
||||
}
|
||||
} else if (isVar(node, parent)) {
|
||||
return self.pushDeclar(node).map(t.expressionStatement);
|
||||
} else if (t.isFunction(node)) {
|
||||
return this.skip();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Hoist all var declarations in this block to before it so they retain scope
|
||||
* once we wrap everything in a closure.
|
||||
*/
|
||||
|
||||
BlockScoping.prototype.hoistVarDeclarations = function () {
|
||||
traverse(this.block, hoistVarDeclarationsVisitor, this.scope, this);
|
||||
};
|
||||
|
||||
/**
|
||||
* Turn a `VariableDeclaration` into an array of `AssignmentExpressions` with
|
||||
* their declarations hoisted to before the closure wrapper.
|
||||
*
|
||||
* @param {Node} node VariableDeclaration
|
||||
* @returns {Array}
|
||||
*/
|
||||
|
||||
BlockScoping.prototype.pushDeclar = function (node) {
|
||||
this.body.push(t.variableDeclaration(node.kind, node.declarations.map(function (declar) {
|
||||
return t.variableDeclarator(declar.id);
|
||||
})));
|
||||
|
||||
var replace = [];
|
||||
|
||||
for (var i = 0; i < node.declarations.length; i++) {
|
||||
var declar = node.declarations[i];
|
||||
if (!declar.init) continue;
|
||||
|
||||
var expr = t.assignmentExpression("=", declar.id, declar.init);
|
||||
replace.push(t.inherits(expr, declar));
|
||||
}
|
||||
|
||||
return replace;
|
||||
};
|
||||
|
||||
/**
|
||||
* Push the closure to the body.
|
||||
*
|
||||
* @param {Node} ret Identifier
|
||||
* @param {Node} call CallExpression
|
||||
*/
|
||||
|
||||
BlockScoping.prototype.build = function (ret, call) {
|
||||
var has = this.has;
|
||||
if (has.hasReturn || has.hasBreakContinue) {
|
||||
this.buildHas(ret, call);
|
||||
} else {
|
||||
this.body.push(t.expressionStatement(call));
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Description
|
||||
*
|
||||
* @param {Node} ret Identifier
|
||||
* @param {Node} call CallExpression
|
||||
*/
|
||||
|
||||
BlockScoping.prototype.buildHas = function (ret, call) {
|
||||
var body = this.body;
|
||||
|
||||
body.push(t.variableDeclaration("var", [
|
||||
t.variableDeclarator(ret, call)
|
||||
]));
|
||||
|
||||
var loopParent = this.loopParent;
|
||||
var retCheck;
|
||||
var has = this.has;
|
||||
var cases = [];
|
||||
|
||||
if (has.hasReturn) {
|
||||
// typeof ret === "object"
|
||||
retCheck = util.template("let-scoping-return", {
|
||||
RETURN: ret
|
||||
});
|
||||
}
|
||||
|
||||
if (has.hasBreakContinue) {
|
||||
if (!loopParent) {
|
||||
throw new Error("Has no loop parent but we're trying to reassign breaks " +
|
||||
"and continues, something is going wrong here.");
|
||||
}
|
||||
|
||||
for (var key in has.map) {
|
||||
cases.push(t.switchCase(t.literal(key), [has.map[key]]));
|
||||
}
|
||||
|
||||
if (has.hasReturn) {
|
||||
cases.push(t.switchCase(null, [retCheck]));
|
||||
}
|
||||
|
||||
if (cases.length === 1) {
|
||||
var single = cases[0];
|
||||
body.push(t.ifStatement(
|
||||
t.binaryExpression("===", ret, single.test),
|
||||
single.consequent[0]
|
||||
));
|
||||
} else {
|
||||
body.push(t.switchStatement(ret, cases));
|
||||
}
|
||||
} else {
|
||||
if (has.hasReturn) body.push(retCheck);
|
||||
}
|
||||
};
|
||||
@@ -1,296 +0,0 @@
|
||||
"use strict";
|
||||
|
||||
var ReplaceSupers = require("../../helpers/replace-supers");
|
||||
var nameMethod = require("../../helpers/name-method");
|
||||
var defineMap = require("../../helpers/define-map");
|
||||
var messages = require("../../../messages");
|
||||
var util = require("../../../util");
|
||||
var t = require("../../../types");
|
||||
|
||||
exports.check = t.isClass;
|
||||
|
||||
exports.ClassDeclaration = function (node, parent, scope, file) {
|
||||
return new ClassTransformer(node, file, scope, true).run();
|
||||
};
|
||||
|
||||
exports.ClassExpression = function (node, parent, scope, file) {
|
||||
if (!node.id) {
|
||||
if (t.isProperty(parent) && parent.value === node && !parent.computed && t.isIdentifier(parent.key)) {
|
||||
// var o = { foo: class {} };
|
||||
node.id = parent.key;
|
||||
}
|
||||
|
||||
if (t.isVariableDeclarator(parent) && t.isIdentifier(parent.id)) {
|
||||
// var foo = class {};
|
||||
node.id = parent.id;
|
||||
}
|
||||
}
|
||||
|
||||
return new ClassTransformer(node, file, scope, false).run();
|
||||
};
|
||||
|
||||
/**
|
||||
* Description
|
||||
*
|
||||
* @param {Node} node
|
||||
* @param {File} file
|
||||
* @param {Scope} scope
|
||||
* @param {Boolean} isStatement
|
||||
*/
|
||||
|
||||
function ClassTransformer(node, file, scope, isStatement) {
|
||||
this.isStatement = isStatement;
|
||||
this.scope = scope;
|
||||
this.node = node;
|
||||
this.file = file;
|
||||
|
||||
this.hasInstanceMutators = false;
|
||||
this.hasStaticMutators = false;
|
||||
|
||||
this.instanceMutatorMap = {};
|
||||
this.staticMutatorMap = {};
|
||||
this.hasConstructor = false;
|
||||
this.className = node.id || scope.generateUidIdentifier("class");
|
||||
this.superName = node.superClass || t.identifier("Function");
|
||||
this.hasSuper = !!node.superClass;
|
||||
this.isLoose = file.isLoose("es6.classes");
|
||||
}
|
||||
|
||||
/**
|
||||
* Description
|
||||
*
|
||||
* @returns {Array}
|
||||
*/
|
||||
|
||||
ClassTransformer.prototype.run = function () {
|
||||
var superName = this.superName;
|
||||
var className = this.className;
|
||||
var file = this.file;
|
||||
|
||||
//
|
||||
|
||||
var body = this.body = [];
|
||||
|
||||
var constructorBody = t.blockStatement([
|
||||
t.expressionStatement(t.callExpression(file.addHelper("class-call-check"), [
|
||||
t.thisExpression(),
|
||||
className
|
||||
]))
|
||||
]);
|
||||
var constructor;
|
||||
|
||||
if (this.node.id) {
|
||||
constructor = t.functionDeclaration(className, [], constructorBody);
|
||||
body.push(constructor);
|
||||
} else {
|
||||
constructor = t.functionExpression(null, [], constructorBody);
|
||||
body.push(t.variableDeclaration("var", [
|
||||
t.variableDeclarator(className, constructor)
|
||||
]));
|
||||
}
|
||||
this.constructor = constructor;
|
||||
|
||||
var closureParams = [];
|
||||
var closureArgs = [];
|
||||
|
||||
//
|
||||
|
||||
if (this.hasSuper) {
|
||||
closureArgs.push(superName);
|
||||
|
||||
if (!t.isIdentifier(superName)) {
|
||||
superName = this.scope.generateUidBasedOnNode(superName, this.file);
|
||||
}
|
||||
|
||||
closureParams.push(superName);
|
||||
|
||||
this.superName = superName;
|
||||
body.push(t.expressionStatement(t.callExpression(file.addHelper("inherits"), [className, superName])));
|
||||
}
|
||||
|
||||
this.buildBody();
|
||||
|
||||
t.inheritsComments(body[0], this.node);
|
||||
|
||||
var init;
|
||||
|
||||
if (body.length === 1) {
|
||||
// only a constructor so no need for a closure container
|
||||
init = t.toExpression(constructor);
|
||||
} else {
|
||||
body.push(t.returnStatement(className));
|
||||
init = t.callExpression(
|
||||
t.functionExpression(null, closureParams, t.blockStatement(body)),
|
||||
closureArgs
|
||||
);
|
||||
}
|
||||
|
||||
if (this.isStatement) {
|
||||
return t.variableDeclaration("let", [
|
||||
t.variableDeclarator(className, init)
|
||||
]);
|
||||
} else {
|
||||
return init;
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Description
|
||||
*/
|
||||
|
||||
ClassTransformer.prototype.buildBody = function () {
|
||||
var constructor = this.constructor;
|
||||
var className = this.className;
|
||||
var superName = this.superName;
|
||||
var classBody = this.node.body.body;
|
||||
var body = this.body;
|
||||
|
||||
for (var i = 0; i < classBody.length; i++) {
|
||||
var node = classBody[i];
|
||||
if (t.isMethodDefinition(node)) {
|
||||
var replaceSupers = new ReplaceSupers({
|
||||
methodNode: node,
|
||||
className: this.className,
|
||||
superName: this.superName,
|
||||
isStatic: node.static,
|
||||
isLoose: this.isLoose,
|
||||
scope: this.scope,
|
||||
file: this.file
|
||||
}, true);
|
||||
replaceSupers.replace();
|
||||
|
||||
if (node.key.name === "constructor") {
|
||||
this.pushConstructor(node);
|
||||
} else {
|
||||
this.pushMethod(node);
|
||||
}
|
||||
} else if (t.isPrivateDeclaration(node)) {
|
||||
this.closure = true;
|
||||
body.unshift(node);
|
||||
} else if (t.isClassProperty(node)) {
|
||||
this.pushProperty(node);
|
||||
}
|
||||
}
|
||||
|
||||
// we have no constructor, we have a super, and the super doesn't appear to be falsy
|
||||
if (!this.hasConstructor && this.hasSuper && !t.isFalsyExpression(superName)) {
|
||||
var helperName = "class-super-constructor-call";
|
||||
if (this.isLoose) helperName += "-loose";
|
||||
constructor.body.body.push(util.template(helperName, {
|
||||
CLASS_NAME: className,
|
||||
SUPER_NAME: this.superName
|
||||
}, true));
|
||||
}
|
||||
|
||||
var instanceProps;
|
||||
var staticProps;
|
||||
|
||||
if (this.hasInstanceMutators) {
|
||||
instanceProps = defineMap.build(this.instanceMutatorMap);
|
||||
}
|
||||
|
||||
if (this.hasStaticMutators) {
|
||||
staticProps = defineMap.build(this.staticMutatorMap);
|
||||
}
|
||||
|
||||
if (instanceProps || staticProps) {
|
||||
staticProps = staticProps || t.literal(null);
|
||||
|
||||
var args = [className, staticProps];
|
||||
if (instanceProps) args.push(instanceProps);
|
||||
|
||||
body.push(t.expressionStatement(
|
||||
t.callExpression(this.file.addHelper("prototype-properties"), args)
|
||||
));
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Push a method to its respective mutatorMap.
|
||||
*
|
||||
* @param {Node} node MethodDefinition
|
||||
*/
|
||||
|
||||
ClassTransformer.prototype.pushMethod = function (node) {
|
||||
var methodName = node.key;
|
||||
|
||||
var kind = node.kind;
|
||||
|
||||
if (kind === "") {
|
||||
nameMethod.property(node, this.file, this.scope);
|
||||
|
||||
if (this.isLoose) {
|
||||
// use assignments instead of define properties for loose classes
|
||||
|
||||
var className = this.className;
|
||||
if (!node.static) className = t.memberExpression(className, t.identifier("prototype"));
|
||||
methodName = t.memberExpression(className, methodName, node.computed);
|
||||
|
||||
var expr = t.expressionStatement(t.assignmentExpression("=", methodName, node.value));
|
||||
t.inheritsComments(expr, node);
|
||||
this.body.push(expr);
|
||||
return;
|
||||
}
|
||||
|
||||
kind = "value";
|
||||
}
|
||||
|
||||
var mutatorMap = this.instanceMutatorMap;
|
||||
if (node.static) {
|
||||
this.hasStaticMutators = true;
|
||||
mutatorMap = this.staticMutatorMap;
|
||||
} else {
|
||||
this.hasInstanceMutators = true;
|
||||
}
|
||||
|
||||
defineMap.push(mutatorMap, methodName, kind, node.computed, node);
|
||||
defineMap.push(mutatorMap, methodName, "enumerable", node.computed, false);
|
||||
};
|
||||
|
||||
/**
|
||||
* Description
|
||||
*
|
||||
* @param {Node} node
|
||||
*/
|
||||
|
||||
ClassTransformer.prototype.pushProperty = function (node) {
|
||||
if (!node.value) return;
|
||||
|
||||
var key;
|
||||
|
||||
if (node.static) {
|
||||
key = t.memberExpression(this.className, node.key);
|
||||
this.body.push(
|
||||
t.expressionStatement(t.assignmentExpression("=", key, node.value))
|
||||
);
|
||||
} else {
|
||||
key = t.memberExpression(t.thisExpression(), node.key);
|
||||
this.constructor.body.body.unshift(
|
||||
t.expressionStatement(t.assignmentExpression("=", key, node.value))
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Replace the constructor body of our class.
|
||||
*
|
||||
* @param {Node} method MethodDefinition
|
||||
*/
|
||||
|
||||
ClassTransformer.prototype.pushConstructor = function (method) {
|
||||
if (method.kind) {
|
||||
throw this.file.errorWithNode(method, messages.get("classesIllegalConstructorKind"));
|
||||
}
|
||||
|
||||
var construct = this.constructor;
|
||||
var fn = method.value;
|
||||
|
||||
this.hasConstructor = true;
|
||||
|
||||
t.inherits(construct, fn);
|
||||
t.inheritsComments(construct, method);
|
||||
|
||||
construct._ignoreUserWhitespace = true;
|
||||
construct.params = fn.params;
|
||||
construct.body.body = construct.body.body.concat(fn.body.body);
|
||||
};
|
||||
@@ -1,403 +0,0 @@
|
||||
"use strict";
|
||||
|
||||
var messages = require("../../../messages");
|
||||
var t = require("../../../types");
|
||||
|
||||
exports.check = t.isPattern;
|
||||
|
||||
function DestructuringTransformer(opts) {
|
||||
this.blockHoist = opts.blockHoist;
|
||||
this.operator = opts.operator;
|
||||
this.nodes = opts.nodes;
|
||||
this.scope = opts.scope;
|
||||
this.file = opts.file;
|
||||
this.kind = opts.kind;
|
||||
}
|
||||
|
||||
DestructuringTransformer.prototype.buildVariableAssignment = function (id, init) {
|
||||
var op = this.operator;
|
||||
if (t.isMemberExpression(id)) op = "=";
|
||||
|
||||
var node;
|
||||
|
||||
if (op) {
|
||||
node = t.expressionStatement(t.assignmentExpression(op, id, init));
|
||||
} else {
|
||||
node = t.variableDeclaration(this.kind, [
|
||||
t.variableDeclarator(id, init)
|
||||
]);
|
||||
}
|
||||
|
||||
node._blockHoist = this.blockHoist;
|
||||
|
||||
return node;
|
||||
};
|
||||
|
||||
DestructuringTransformer.prototype.buildVariableDeclaration = function (id, init) {
|
||||
var declar = t.variableDeclaration("var", [
|
||||
t.variableDeclarator(id, init)
|
||||
]);
|
||||
declar._blockHoist = this.blockHoist;
|
||||
return declar;
|
||||
};
|
||||
|
||||
DestructuringTransformer.prototype.push = function (elem, parentId) {
|
||||
if (t.isObjectPattern(elem)) {
|
||||
this.pushObjectPattern(elem, parentId);
|
||||
} else if (t.isArrayPattern(elem)) {
|
||||
this.pushArrayPattern(elem, parentId);
|
||||
} else if (t.isAssignmentPattern(elem)) {
|
||||
this.pushAssignmentPattern(elem, parentId);
|
||||
} else {
|
||||
this.nodes.push(this.buildVariableAssignment(elem, parentId));
|
||||
}
|
||||
};
|
||||
|
||||
DestructuringTransformer.prototype.pushAssignmentPattern = function (pattern, parentId) {
|
||||
var tempParentId = this.scope.generateUidBasedOnNode(parentId);
|
||||
|
||||
var declar = t.variableDeclaration("var", [
|
||||
t.variableDeclarator(tempParentId, parentId)
|
||||
]);
|
||||
declar._blockHoist = this.blockHoist;
|
||||
this.nodes.push(declar);
|
||||
|
||||
this.nodes.push(this.buildVariableAssignment(
|
||||
pattern.left,
|
||||
t.conditionalExpression(
|
||||
t.binaryExpression("===", tempParentId, t.identifier("undefined")),
|
||||
pattern.right,
|
||||
tempParentId
|
||||
)
|
||||
));
|
||||
};
|
||||
|
||||
DestructuringTransformer.prototype.pushObjectSpread = function (pattern, parentId, prop, i) {
|
||||
// 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(this.file.addHelper("object-without-properties"), [parentId, keys]);
|
||||
this.nodes.push(this.buildVariableAssignment(prop.argument, value));
|
||||
};
|
||||
|
||||
DestructuringTransformer.prototype.pushObjectProperty = function (prop, parentId) {
|
||||
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)) {
|
||||
this.push(pattern2, patternId2);
|
||||
} else {
|
||||
this.nodes.push(this.buildVariableAssignment(pattern2, patternId2));
|
||||
}
|
||||
};
|
||||
|
||||
DestructuringTransformer.prototype.pushObjectPattern = function (pattern, parentId) {
|
||||
if (!pattern.properties.length) {
|
||||
this.nodes.push(t.expressionStatement(
|
||||
t.callExpression(this.file.addHelper("object-destructuring-empty"), [parentId])
|
||||
));
|
||||
}
|
||||
|
||||
if (pattern.properties.length > 1 && t.isMemberExpression(parentId)) {
|
||||
var temp = this.scope.generateUidBasedOnNode(parentId, this.file);
|
||||
this.nodes.push(this.buildVariableDeclaration(temp, parentId));
|
||||
parentId = temp;
|
||||
}
|
||||
|
||||
for (var i = 0; i < pattern.properties.length; i++) {
|
||||
var prop = pattern.properties[i];
|
||||
if (t.isSpreadProperty(prop)) {
|
||||
this.pushObjectSpread(pattern, parentId, prop, i);
|
||||
} else {
|
||||
this.pushObjectProperty(prop, parentId);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
var hasRest = function (pattern) {
|
||||
for (var i = 0; i < pattern.elements.length; i++) {
|
||||
if (t.isRestElement(pattern.elements[i])) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
};
|
||||
|
||||
DestructuringTransformer.prototype.pushArrayPattern = function (pattern, parentId) {
|
||||
if (!pattern.elements) return;
|
||||
|
||||
// if we have a rest then we need all the elements
|
||||
var count = !hasRest(pattern) && pattern.elements.length;
|
||||
|
||||
var toArray = this.scope.toArray(parentId, count);
|
||||
|
||||
var _parentId = this.scope.generateUidBasedOnNode(parentId);
|
||||
this.nodes.push(this.buildVariableDeclaration(_parentId, toArray));
|
||||
parentId = _parentId;
|
||||
|
||||
this.scope.assignTypeGeneric(parentId.name, "Array");
|
||||
|
||||
for (var i = 0; i < pattern.elements.length; i++) {
|
||||
var elem = pattern.elements[i];
|
||||
|
||||
// hole
|
||||
if (!elem) continue;
|
||||
|
||||
var newPatternId;
|
||||
|
||||
if (t.isRestElement(elem)) {
|
||||
newPatternId = this.scope.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);
|
||||
}
|
||||
|
||||
this.push(elem, newPatternId);
|
||||
}
|
||||
};
|
||||
|
||||
DestructuringTransformer.prototype.init = function (pattern, parentId) {
|
||||
if (!t.isArrayExpression(parentId) && !t.isMemberExpression(parentId) && !t.isIdentifier(parentId)) {
|
||||
var key = this.scope.generateUidBasedOnNode(parentId);
|
||||
this.nodes.push(this.buildVariableDeclaration(key, parentId));
|
||||
parentId = key;
|
||||
}
|
||||
|
||||
this.push(pattern, parentId);
|
||||
};
|
||||
|
||||
exports.ForInStatement =
|
||||
exports.ForOfStatement = function (node, parent, scope, file) {
|
||||
var left = node.left;
|
||||
|
||||
if (t.isPattern(left)) {
|
||||
// for ({ length: k } in { abc: 3 });
|
||||
|
||||
var temp = scope.generateUidIdentifier("ref");
|
||||
|
||||
node.left = t.variableDeclaration("var", [
|
||||
t.variableDeclarator(temp)
|
||||
]);
|
||||
|
||||
t.ensureBlock(node);
|
||||
|
||||
node.body.body.unshift(t.variableDeclaration("var", [
|
||||
t.variableDeclarator(left, temp)
|
||||
]));
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (!t.isVariableDeclaration(left)) return;
|
||||
|
||||
var pattern = left.declarations[0].id;
|
||||
if (!t.isPattern(pattern)) return;
|
||||
|
||||
var key = scope.generateUidIdentifier("ref");
|
||||
node.left = t.variableDeclaration(left.kind, [
|
||||
t.variableDeclarator(key, null)
|
||||
]);
|
||||
|
||||
var nodes = [];
|
||||
|
||||
var destructuring = new DestructuringTransformer({
|
||||
kind: left.kind,
|
||||
file: file,
|
||||
scope: scope,
|
||||
nodes: nodes
|
||||
});
|
||||
|
||||
destructuring.init(pattern, key);
|
||||
|
||||
t.ensureBlock(node);
|
||||
|
||||
var block = node.body;
|
||||
block.body = nodes.concat(block.body);
|
||||
};
|
||||
|
||||
exports.Function = function (node, parent, scope, file) {
|
||||
var nodes = [];
|
||||
|
||||
var hasDestructuringTransformer = false;
|
||||
|
||||
node.params = node.params.map(function (pattern, i) {
|
||||
if (!t.isPattern(pattern)) return pattern;
|
||||
|
||||
hasDestructuringTransformer = true;
|
||||
var parentId = scope.generateUidIdentifier("ref");
|
||||
|
||||
var destructuring = new DestructuringTransformer({
|
||||
blockHoist: node.params.length - i,
|
||||
nodes: nodes,
|
||||
scope: scope,
|
||||
file: file,
|
||||
kind: "var",
|
||||
});
|
||||
destructuring.init(pattern, parentId);
|
||||
|
||||
return parentId;
|
||||
});
|
||||
|
||||
if (!hasDestructuringTransformer) return;
|
||||
|
||||
t.ensureBlock(node);
|
||||
|
||||
var block = node.body;
|
||||
block.body = nodes.concat(block.body);
|
||||
};
|
||||
|
||||
exports.CatchClause = function (node, parent, scope, file) {
|
||||
var pattern = node.param;
|
||||
if (!t.isPattern(pattern)) return;
|
||||
|
||||
var ref = scope.generateUidIdentifier("ref");
|
||||
node.param = ref;
|
||||
|
||||
var nodes = [];
|
||||
|
||||
var destructuring = new DestructuringTransformer({
|
||||
kind: "let",
|
||||
file: file,
|
||||
scope: scope,
|
||||
nodes: nodes
|
||||
});
|
||||
destructuring.init(pattern, ref);
|
||||
|
||||
node.body.body = nodes.concat(node.body.body);
|
||||
|
||||
return node;
|
||||
};
|
||||
|
||||
exports.ExpressionStatement = function (node, parent, scope, 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)
|
||||
]));
|
||||
|
||||
var destructuring = new DestructuringTransformer({
|
||||
operator: expr.operator,
|
||||
file: file,
|
||||
scope: scope,
|
||||
nodes: nodes
|
||||
});
|
||||
destructuring.init(expr.left, ref);
|
||||
|
||||
return nodes;
|
||||
};
|
||||
|
||||
exports.AssignmentExpression = function (node, parent, scope, 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));
|
||||
|
||||
var destructuring = new DestructuringTransformer({
|
||||
operator: node.operator,
|
||||
file: file,
|
||||
scope: scope,
|
||||
nodes: nodes
|
||||
});
|
||||
destructuring.init(node.left, ref);
|
||||
|
||||
nodes.push(ref);
|
||||
|
||||
return t.toSequenceExpression(nodes, scope);
|
||||
};
|
||||
|
||||
var variableDeclarationhasPattern = function (node) {
|
||||
for (var i = 0; i < node.declarations.length; i++) {
|
||||
if (t.isPattern(node.declarations[i].id)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
};
|
||||
|
||||
exports.VariableDeclaration = function (node, parent, scope, file) {
|
||||
if (t.isForInStatement(parent) || t.isForOfStatement(parent)) return;
|
||||
if (!variableDeclarationhasPattern(node)) return;
|
||||
|
||||
var nodes = [];
|
||||
var declar;
|
||||
|
||||
for (var i = 0; i < node.declarations.length; i++) {
|
||||
declar = node.declarations[i];
|
||||
|
||||
var patternId = declar.init;
|
||||
var pattern = declar.id;
|
||||
|
||||
var destructuring = new DestructuringTransformer({
|
||||
nodes: nodes,
|
||||
scope: scope,
|
||||
kind: node.kind,
|
||||
file: file
|
||||
});
|
||||
|
||||
if (t.isPattern(pattern) && patternId) {
|
||||
destructuring.init(pattern, patternId);
|
||||
|
||||
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(destructuring.buildVariableAssignment(declar.id, declar.init), declar));
|
||||
}
|
||||
}
|
||||
|
||||
if (!t.isProgram(parent) && !t.isBlockStatement(parent)) {
|
||||
// https://github.com/6to5/6to5/issues/113
|
||||
// for (let [x] = [0]; false;) {}
|
||||
|
||||
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, messages.get("invalidParentForThisNode"));
|
||||
}
|
||||
|
||||
declar.declarations = declar.declarations.concat(node.declarations);
|
||||
}
|
||||
|
||||
return declar;
|
||||
}
|
||||
|
||||
return nodes;
|
||||
};
|
||||
@@ -1,106 +0,0 @@
|
||||
"use strict";
|
||||
|
||||
var messages = require("../../../messages");
|
||||
var util = require("../../../util");
|
||||
var t = require("../../../types");
|
||||
|
||||
exports.check = t.isForOfStatement;
|
||||
|
||||
exports.ForOfStatement = function (node, parent, scope, file) {
|
||||
var callback = spec;
|
||||
if (file.isLoose("es6.forOf")) callback = loose;
|
||||
|
||||
var build = callback(node, parent, scope, 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 its statements
|
||||
t.ensureBlock(node);
|
||||
|
||||
// add the value declaration to the new loop body
|
||||
if (declar) {
|
||||
block.body.push(declar);
|
||||
}
|
||||
|
||||
// push the rest of the original loop body onto our new body
|
||||
block.body = block.body.concat(node.body.body);
|
||||
|
||||
t.inherits(loop, node);
|
||||
|
||||
// todo: find out why this is necessary? #538
|
||||
loop._scopeInfo = node._scopeInfo;
|
||||
|
||||
return loop;
|
||||
};
|
||||
|
||||
var loose = function (node, parent, scope, 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 = scope.generateUidIdentifier("ref");
|
||||
declar = t.variableDeclaration(left.kind, [
|
||||
t.variableDeclarator(left.declarations[0].id, id)
|
||||
]);
|
||||
} else {
|
||||
throw file.errorWithNode(left, messages.get("unknownForHead", left.type));
|
||||
}
|
||||
|
||||
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
|
||||
});
|
||||
|
||||
if (!declar) {
|
||||
// no declaration so we need to remove the variable declaration at the top of
|
||||
// the for-of-loose template
|
||||
loop.body.body.shift();
|
||||
}
|
||||
|
||||
return {
|
||||
declar: declar,
|
||||
loop: loop
|
||||
};
|
||||
};
|
||||
|
||||
var spec = function (node, parent, scope, 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, messages.get("unknownForHead", left.type));
|
||||
}
|
||||
|
||||
var loop = util.template("for-of", {
|
||||
ITERATOR_KEY: scope.generateUidIdentifier("iterator"),
|
||||
STEP_KEY: stepKey,
|
||||
OBJECT: node.right
|
||||
});
|
||||
|
||||
return {
|
||||
declar: declar,
|
||||
loop: loop
|
||||
};
|
||||
};
|
||||
@@ -1,34 +0,0 @@
|
||||
"use strict";
|
||||
|
||||
var ReplaceSupers = require("../../helpers/replace-supers");
|
||||
var t = require("../../../types");
|
||||
|
||||
exports.check = function (node) {
|
||||
return t.isIdentifier(node, { name: "super" });
|
||||
};
|
||||
|
||||
exports.Property = function (node, parent, scope, file) {
|
||||
if (!node.method) return;
|
||||
|
||||
var value = node.value;
|
||||
var thisExpr = scope.generateUidIdentifier("this");
|
||||
|
||||
var replaceSupers = new ReplaceSupers({
|
||||
topLevelThisReference: thisExpr,
|
||||
methodNode: node,
|
||||
className: thisExpr,
|
||||
isStatic: true,
|
||||
scope: scope,
|
||||
file: file
|
||||
});
|
||||
|
||||
replaceSupers.replace();
|
||||
|
||||
if (replaceSupers.hasSuper) {
|
||||
value.body.body.unshift(
|
||||
t.variableDeclaration("var", [
|
||||
t.variableDeclarator(thisExpr, t.thisExpression())
|
||||
])
|
||||
);
|
||||
}
|
||||
};
|
||||
@@ -1,76 +0,0 @@
|
||||
"use strict";
|
||||
|
||||
var util = require("../../../util");
|
||||
var t = require("../../../types");
|
||||
|
||||
exports.check = t.isRestElement;
|
||||
|
||||
var hasRest = function (node) {
|
||||
return t.isRestElement(node.params[node.params.length - 1]);
|
||||
};
|
||||
|
||||
exports.Function = function (node, parent, scope) {
|
||||
if (!hasRest(node)) return;
|
||||
|
||||
var rest = node.params.pop().argument;
|
||||
|
||||
var argsId = t.identifier("arguments");
|
||||
|
||||
// otherwise `arguments` will be remapped in arrow functions
|
||||
argsId._ignoreAliasFunctions = true;
|
||||
|
||||
var start = t.literal(node.params.length);
|
||||
var key = scope.generateUidIdentifier("key");
|
||||
var len = scope.generateUidIdentifier("len");
|
||||
|
||||
var arrKey = key;
|
||||
var arrLen = len;
|
||||
if (node.params.length) {
|
||||
// this method has additional params, so we need to subtract
|
||||
// the index of the current argument position from the
|
||||
// position in the array that we want to populate
|
||||
arrKey = t.binaryExpression("-", key, start);
|
||||
|
||||
// we need to work out the size of the array that we're
|
||||
// going to store all the rest parameters
|
||||
//
|
||||
// we need to add a check to avoid constructing the array
|
||||
// with <0 if there are less arguments than params as it'll
|
||||
// cause an error
|
||||
arrLen = t.conditionalExpression(
|
||||
t.binaryExpression(">", len, start),
|
||||
t.binaryExpression("-", len, start),
|
||||
t.literal(0)
|
||||
);
|
||||
}
|
||||
|
||||
// support patterns
|
||||
if (t.isPattern(rest)) {
|
||||
var pattern = rest;
|
||||
rest = scope.generateUidIdentifier("ref");
|
||||
|
||||
// let the destructuring transformer handle this
|
||||
var restDeclar = t.variableDeclaration("var", [
|
||||
t.variableDeclarator(pattern, rest)
|
||||
]);
|
||||
|
||||
// retain evaluation position
|
||||
restDeclar._blockHoist = node.params.length + 1;
|
||||
|
||||
node.body.body.unshift(restDeclar);
|
||||
}
|
||||
|
||||
scope.assignTypeGeneric(rest.name, "Array");
|
||||
|
||||
var loop = util.template("rest", {
|
||||
ARGUMENTS: argsId,
|
||||
ARRAY_KEY: arrKey,
|
||||
ARRAY_LEN: arrLen,
|
||||
START: start,
|
||||
ARRAY: rest,
|
||||
KEY: key,
|
||||
LEN: len,
|
||||
});
|
||||
loop._blockHoist = node.params.length + 1;
|
||||
node.body.body.unshift(loop);
|
||||
};
|
||||
@@ -1,21 +0,0 @@
|
||||
"use strict";
|
||||
|
||||
var nameMethod = require("../../helpers/name-method");
|
||||
var t = require("../../../types");
|
||||
var clone = require("lodash/lang/clone");
|
||||
|
||||
exports.check = function (node) {
|
||||
return t.isProperty(node) && (node.method || node.shorthand);
|
||||
};
|
||||
|
||||
exports.Property = function (node, parent, scope, 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,359 +0,0 @@
|
||||
"use strict";
|
||||
|
||||
var reduceRight = require("lodash/collection/reduceRight");
|
||||
var messages = require("../../../messages");
|
||||
var flatten = require("lodash/array/flatten");
|
||||
var util = require("../../../util");
|
||||
var map = require("lodash/collection/map");
|
||||
var t = require("../../../types");
|
||||
|
||||
function returnBlock(expr) {
|
||||
return t.blockStatement([t.returnStatement(expr)]);
|
||||
}
|
||||
|
||||
function TailCallTransformer(node, scope, file) {
|
||||
this.hasTailRecursion = false;
|
||||
this.needsArguments = false;
|
||||
this.setsArguments = false;
|
||||
this.needsThis = false;
|
||||
this.ownerId = node.id;
|
||||
this.vars = [];
|
||||
|
||||
this.scope = scope;
|
||||
this.file = file;
|
||||
this.node = node;
|
||||
}
|
||||
|
||||
TailCallTransformer.prototype.getArgumentsId = function () {
|
||||
return this.argumentsId = this.argumentsId || this.scope.generateUidIdentifier("arguments");
|
||||
};
|
||||
|
||||
TailCallTransformer.prototype.getThisId = function () {
|
||||
return this.thisId = this.thisId || this.scope.generateUidIdentifier("this");
|
||||
};
|
||||
|
||||
TailCallTransformer.prototype.getLeftId = function () {
|
||||
return this.leftId = this.leftId || this.scope.generateUidIdentifier("left");
|
||||
};
|
||||
|
||||
TailCallTransformer.prototype.getFunctionId = function () {
|
||||
return this.functionId = this.functionId || this.scope.generateUidIdentifier("function");
|
||||
};
|
||||
|
||||
TailCallTransformer.prototype.getParams = function () {
|
||||
var params = this.params;
|
||||
|
||||
if (!params) {
|
||||
params = this.node.params;
|
||||
this.paramDecls = [];
|
||||
|
||||
for (var i = 0; i < params.length; i++) {
|
||||
var param = params[i];
|
||||
if (!param._isDefaultPlaceholder) {
|
||||
this.paramDecls.push(t.variableDeclarator(
|
||||
param,
|
||||
params[i] = this.scope.generateUidIdentifier("x")
|
||||
));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return this.params = params;
|
||||
};
|
||||
|
||||
TailCallTransformer.prototype.hasDeopt = function () {
|
||||
// check if the ownerId has been reassigned, if it has then it's not safe to
|
||||
// perform optimisations
|
||||
var ownerIdInfo = this.scope.getBindingInfo(this.ownerId.name);
|
||||
return ownerIdInfo && ownerIdInfo.reassigned;
|
||||
};
|
||||
|
||||
TailCallTransformer.prototype.run = function () {
|
||||
var scope = this.scope;
|
||||
var node = this.node;
|
||||
|
||||
// only tail recursion can be optimized as for now, so we can skip anonymous
|
||||
// functions entirely
|
||||
var ownerId = this.ownerId;
|
||||
if (!ownerId) return;
|
||||
|
||||
// traverse the function and look for tail recursion
|
||||
scope.traverse(node, firstPass, this);
|
||||
|
||||
if (!this.hasTailRecursion) return;
|
||||
|
||||
if (this.hasDeopt()) {
|
||||
this.file.logDeopt(node, messages.get("tailCallReassignmentDeopt"));
|
||||
return;
|
||||
}
|
||||
|
||||
//
|
||||
|
||||
scope.traverse(node, secondPass, this);
|
||||
|
||||
if (!this.needsThis || !this.needsArguments) {
|
||||
scope.traverse(node, thirdPass, this);
|
||||
}
|
||||
|
||||
var body = t.ensureBlock(node).body;
|
||||
|
||||
if (this.vars.length > 0) {
|
||||
var declarations = flatten(map(this.vars, function (decl) {
|
||||
return decl.declarations;
|
||||
}, this));
|
||||
var statement = reduceRight(declarations, function (expr, decl) {
|
||||
return t.assignmentExpression("=", decl.id, expr);
|
||||
}, t.identifier("undefined"));
|
||||
body.unshift(t.expressionStatement(statement));
|
||||
}
|
||||
|
||||
var paramDecls = this.paramDecls;
|
||||
if (paramDecls.length > 0) {
|
||||
body.unshift(t.variableDeclaration("var", paramDecls));
|
||||
}
|
||||
|
||||
node.body = util.template("tail-call-body", {
|
||||
THIS_ID: this.thisId,
|
||||
ARGUMENTS_ID: this.argumentsId,
|
||||
FUNCTION_ID: this.getFunctionId(),
|
||||
BLOCK: node.body
|
||||
});
|
||||
|
||||
var topVars = [];
|
||||
|
||||
if (this.needsThis) {
|
||||
topVars.push(t.variableDeclarator(this.getThisId(), t.thisExpression()));
|
||||
}
|
||||
|
||||
if (this.needsArguments || this.setsArguments) {
|
||||
var decl = t.variableDeclarator(this.getArgumentsId());
|
||||
if (this.needsArguments) {
|
||||
decl.init = t.identifier("arguments");
|
||||
}
|
||||
topVars.push(decl);
|
||||
}
|
||||
|
||||
var leftId = this.leftId;
|
||||
if (leftId) {
|
||||
topVars.push(t.variableDeclarator(leftId));
|
||||
}
|
||||
|
||||
if (topVars.length > 0) {
|
||||
node.body.body.unshift(t.variableDeclaration("var", topVars));
|
||||
}
|
||||
};
|
||||
|
||||
TailCallTransformer.prototype.subTransform = function (node) {
|
||||
if (!node) return;
|
||||
|
||||
var handler = this["subTransform" + node.type];
|
||||
if (handler) return handler.call(this, node);
|
||||
};
|
||||
|
||||
TailCallTransformer.prototype.subTransformConditionalExpression = function (node) {
|
||||
var callConsequent = this.subTransform(node.consequent);
|
||||
var callAlternate = this.subTransform(node.alternate);
|
||||
if (!callConsequent && !callAlternate) {
|
||||
return;
|
||||
}
|
||||
|
||||
// if ternary operator had tail recursion in value, convert to optimized if-statement
|
||||
node.type = "IfStatement";
|
||||
node.consequent = callConsequent ? t.toBlock(callConsequent) : returnBlock(node.consequent);
|
||||
|
||||
if (callAlternate) {
|
||||
node.alternate = t.isIfStatement(callAlternate) ? callAlternate : t.toBlock(callAlternate);
|
||||
} else {
|
||||
node.alternate = returnBlock(node.alternate);
|
||||
}
|
||||
|
||||
return [node];
|
||||
};
|
||||
|
||||
TailCallTransformer.prototype.subTransformLogicalExpression = function (node) {
|
||||
// only call in right-value of can be optimized
|
||||
var callRight = this.subTransform(node.right);
|
||||
if (!callRight) return;
|
||||
|
||||
// cache left value as it might have side-effects
|
||||
var leftId = this.getLeftId();
|
||||
var testExpr = t.assignmentExpression(
|
||||
"=",
|
||||
leftId,
|
||||
node.left
|
||||
);
|
||||
|
||||
if (node.operator === "&&") {
|
||||
testExpr = t.unaryExpression("!", testExpr);
|
||||
}
|
||||
|
||||
return [t.ifStatement(testExpr, returnBlock(leftId))].concat(callRight);
|
||||
};
|
||||
|
||||
TailCallTransformer.prototype.subTransformSequenceExpression = function (node) {
|
||||
var seq = node.expressions;
|
||||
|
||||
// only last element can be optimized
|
||||
var lastCall = this.subTransform(seq[seq.length - 1]);
|
||||
if (!lastCall) {
|
||||
return;
|
||||
}
|
||||
|
||||
// remove converted expression from sequence
|
||||
// and convert to regular expression if needed
|
||||
if (--seq.length === 1) {
|
||||
node = seq[0];
|
||||
}
|
||||
|
||||
return [t.expressionStatement(node)].concat(lastCall);
|
||||
};
|
||||
|
||||
TailCallTransformer.prototype.subTransformCallExpression = function (node) {
|
||||
var callee = node.callee, thisBinding, args;
|
||||
|
||||
if (t.isMemberExpression(callee, { computed: false }) && t.isIdentifier(callee.property)) {
|
||||
switch (callee.property.name) {
|
||||
case "call":
|
||||
args = t.arrayExpression(node.arguments.slice(1));
|
||||
break;
|
||||
|
||||
case "apply":
|
||||
args = node.arguments[1] || t.identifier("undefined");
|
||||
break;
|
||||
|
||||
default:
|
||||
return;
|
||||
}
|
||||
|
||||
thisBinding = node.arguments[0];
|
||||
callee = callee.object;
|
||||
}
|
||||
|
||||
// only tail recursion can be optimized as for now
|
||||
if (!t.isIdentifier(callee) || !this.scope.bindingIdentifierEquals(callee.name, this.ownerId)) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.hasTailRecursion = true;
|
||||
|
||||
if (this.hasDeopt()) return;
|
||||
|
||||
var body = [];
|
||||
|
||||
if (!t.isThisExpression(thisBinding)) {
|
||||
body.push(t.expressionStatement(t.assignmentExpression(
|
||||
"=",
|
||||
this.getThisId(),
|
||||
thisBinding || t.identifier("undefined")
|
||||
)));
|
||||
}
|
||||
|
||||
if (!args) {
|
||||
args = t.arrayExpression(node.arguments);
|
||||
}
|
||||
|
||||
var argumentsId = this.getArgumentsId();
|
||||
var params = this.getParams();
|
||||
|
||||
body.push(t.expressionStatement(t.assignmentExpression(
|
||||
"=",
|
||||
argumentsId,
|
||||
args
|
||||
)));
|
||||
|
||||
var i, param;
|
||||
|
||||
if (t.isArrayExpression(args)) {
|
||||
var elems = args.elements;
|
||||
for (i = 0; i < elems.length && i < params.length; i++) {
|
||||
param = params[i];
|
||||
var elem = elems[i] || (elems[i] = t.identifier("undefined"));
|
||||
if (!param._isDefaultPlaceholder) {
|
||||
elems[i] = t.assignmentExpression("=", param, elem);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
this.setsArguments = true;
|
||||
for (i = 0; i < params.length; i++) {
|
||||
param = params[i];
|
||||
if (!param._isDefaultPlaceholder) {
|
||||
body.push(t.expressionStatement(t.assignmentExpression(
|
||||
"=",
|
||||
param,
|
||||
t.memberExpression(argumentsId, t.literal(i), true)
|
||||
)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
body.push(t.continueStatement(this.getFunctionId()));
|
||||
|
||||
return body;
|
||||
};
|
||||
|
||||
// looks for and replaces tail recursion calls
|
||||
var firstPass = {
|
||||
enter: function (node, parent, scope, state) {
|
||||
if (t.isReturnStatement(node)) {
|
||||
this.skip();
|
||||
return state.subTransform(node.argument);
|
||||
} else if (t.isTryStatement(parent)) {
|
||||
if (node === parent.block) {
|
||||
this.skip();
|
||||
} else if (parent.finalizer && node !== parent.finalizer) {
|
||||
this.skip();
|
||||
}
|
||||
} else if (t.isFunction(node)) {
|
||||
this.skip();
|
||||
} else if (t.isVariableDeclaration(node)) {
|
||||
this.skip();
|
||||
state.vars.push(node);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
// hoists up function declarations, replaces `this` and `arguments` and marks
|
||||
// them as needed
|
||||
var secondPass = {
|
||||
enter: function (node, parent, scope, state) {
|
||||
if (t.isThisExpression(node)) {
|
||||
state.needsThis = true;
|
||||
return state.getThisId();
|
||||
} else if (t.isReferencedIdentifier(node, parent, { name: "arguments" })) {
|
||||
state.needsArguments = true;
|
||||
return state.getArgumentsId();
|
||||
} else if (t.isFunction(node)) {
|
||||
this.skip();
|
||||
if (t.isFunctionDeclaration(node)) {
|
||||
node = t.variableDeclaration("var", [
|
||||
t.variableDeclarator(node.id, t.toExpression(node))
|
||||
]);
|
||||
node._blockHoist = 2;
|
||||
return node;
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
// optimizes recursion by removing `this` and `arguments` if they aren't used
|
||||
var thirdPass = {
|
||||
enter: function (node, parent, scope, state) {
|
||||
if (!t.isExpressionStatement(node)) return;
|
||||
|
||||
var expr = node.expression;
|
||||
if (!t.isAssignmentExpression(expr)) return;
|
||||
|
||||
if (!state.needsThis && expr.left === state.getThisId()) {
|
||||
this.remove();
|
||||
} else if (!state.needsArguments && expr.left === state.getArgumentsId() && t.isArrayExpression(expr.right)) {
|
||||
return map(expr.right.elements, function (elem) {
|
||||
return t.expressionStatement(elem);
|
||||
});
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
exports.Function = function (node, parent, scope, file) {
|
||||
var tailCall = new TailCallTransformer(node, scope, file);
|
||||
tailCall.run();
|
||||
};
|
||||
@@ -1,21 +0,0 @@
|
||||
"use strict";
|
||||
|
||||
var rewritePattern = require("regexpu/rewrite-pattern");
|
||||
var pull = require("lodash/array/pull");
|
||||
var t = require("../../../types");
|
||||
|
||||
exports.check = function (node) {
|
||||
return t.isLiteral(node) && node.regex && node.regex.flags.indexOf("u") >= 0;
|
||||
};
|
||||
|
||||
exports.Literal = function (node) {
|
||||
var regex = node.regex;
|
||||
if (!regex) return;
|
||||
|
||||
var flags = regex.flags.split("");
|
||||
if (regex.flags.indexOf("u") < 0) return;
|
||||
pull(flags, "u");
|
||||
|
||||
regex.pattern = rewritePattern(regex.pattern, regex.flags);
|
||||
regex.flags = flags.join("");
|
||||
};
|
||||
@@ -1,113 +0,0 @@
|
||||
"use strict";
|
||||
|
||||
// https://github.com/zenparsing/es-abstract-refs
|
||||
|
||||
var util = require("../../../util");
|
||||
var t = require("../../../types");
|
||||
|
||||
exports.experimental = true;
|
||||
|
||||
var container = function (parent, call, ret, file) {
|
||||
if (t.isExpressionStatement(parent) && !file.isConsequenceExpressionStatement(parent)) {
|
||||
// we don't need to worry about return values
|
||||
return call;
|
||||
} else {
|
||||
var exprs = [];
|
||||
if (t.isSequenceExpression(call)) {
|
||||
exprs = call.expressions;
|
||||
} else {
|
||||
exprs.push(call);
|
||||
}
|
||||
exprs.push(ret);
|
||||
return t.sequenceExpression(exprs);
|
||||
}
|
||||
};
|
||||
|
||||
exports.AssignmentExpression = function (node, parent, scope, file) {
|
||||
var left = node.left;
|
||||
if (!t.isVirtualPropertyExpression(left)) return;
|
||||
|
||||
var value = node.right;
|
||||
var temp;
|
||||
|
||||
// we need to return `node.right`
|
||||
if (!t.isExpressionStatement(parent)) {
|
||||
temp = scope.generateTempBasedOnNode(node.right);
|
||||
if (temp) value = temp;
|
||||
}
|
||||
|
||||
if (node.operator !== "=") {
|
||||
value = t.binaryExpression(
|
||||
node.operator[0],
|
||||
util.template("abstract-expression-get", {
|
||||
PROPERTY: node.property,
|
||||
OBJECT: node.object
|
||||
}),
|
||||
value
|
||||
);
|
||||
}
|
||||
|
||||
var call = util.template("abstract-expression-set", {
|
||||
PROPERTY: left.property,
|
||||
OBJECT: left.object,
|
||||
VALUE: value
|
||||
});
|
||||
|
||||
if (temp) {
|
||||
call = t.sequenceExpression([
|
||||
t.assignmentExpression("=", temp, node.right),
|
||||
call
|
||||
]);
|
||||
}
|
||||
|
||||
return container(parent, call, value, file);
|
||||
};
|
||||
|
||||
exports.UnaryExpression = function (node, parent, scope, file) {
|
||||
var arg = node.argument;
|
||||
if (!t.isVirtualPropertyExpression(arg)) return;
|
||||
if (node.operator !== "delete") return;
|
||||
|
||||
var call = util.template("abstract-expression-delete", {
|
||||
PROPERTY: arg.property,
|
||||
OBJECT: arg.object
|
||||
});
|
||||
|
||||
return container(parent, call, t.literal(true), file);
|
||||
};
|
||||
|
||||
exports.CallExpression = function (node, parent, scope) {
|
||||
var callee = node.callee;
|
||||
if (!t.isVirtualPropertyExpression(callee)) return;
|
||||
|
||||
var temp = scope.generateTempBasedOnNode(callee.object);
|
||||
|
||||
var call = util.template("abstract-expression-call", {
|
||||
PROPERTY: callee.property,
|
||||
OBJECT: temp || callee.object
|
||||
});
|
||||
|
||||
call.arguments = call.arguments.concat(node.arguments);
|
||||
|
||||
if (temp) {
|
||||
return t.sequenceExpression([
|
||||
t.assignmentExpression("=", temp, callee.object),
|
||||
call
|
||||
]);
|
||||
} else {
|
||||
return call;
|
||||
}
|
||||
};
|
||||
|
||||
exports.VirtualPropertyExpression = function (node) {
|
||||
return util.template("abstract-expression-get", {
|
||||
PROPERTY: node.property,
|
||||
OBJECT: node.object
|
||||
});
|
||||
};
|
||||
|
||||
exports.PrivateDeclaration = function (node) {
|
||||
return t.variableDeclaration("const", node.declarations.map(function (id) {
|
||||
return t.variableDeclarator(id, t.newExpression(t.identifier("WeakMap"), []));
|
||||
}));
|
||||
};
|
||||
@@ -1,36 +0,0 @@
|
||||
"use strict";
|
||||
|
||||
var useStrict = require("../../helpers/use-strict");
|
||||
var groupBy = require("lodash/collection/groupBy");
|
||||
var flatten = require("lodash/array/flatten");
|
||||
var values = require("lodash/object/values");
|
||||
|
||||
// Priority:
|
||||
//
|
||||
// - 0 We want this to be at the **very** bottom
|
||||
// - 1 Default node position
|
||||
// - 2 Priority over normal nodes
|
||||
// - 3 We want this to be at the **very** top
|
||||
|
||||
exports.BlockStatement =
|
||||
exports.Program = {
|
||||
exit: function (node) {
|
||||
var hasChange = false;
|
||||
for (var i = 0; i < node.body.length; i++) {
|
||||
var bodyNode = node.body[i];
|
||||
if (bodyNode && bodyNode._blockHoist != null) hasChange = true;
|
||||
}
|
||||
if (!hasChange) return;
|
||||
|
||||
useStrict.wrap(node, function () {
|
||||
var nodePriorities = groupBy(node.body, function (bodyNode) {
|
||||
var priority = bodyNode._blockHoist;
|
||||
if (priority == null) priority = 1;
|
||||
if (priority === true) priority = 2;
|
||||
return priority;
|
||||
});
|
||||
|
||||
node.body = flatten(values(nodePriorities).reverse());
|
||||
});
|
||||
}
|
||||
};
|
||||
@@ -1,5 +0,0 @@
|
||||
exports.SequenceExpression = function (node) {
|
||||
if (node.expressions.length === 1) {
|
||||
return node.expressions[0];
|
||||
}
|
||||
};
|
||||
@@ -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.post = function (file) {
|
||||
if (!file.transformers["es6.modules"].canRun()) return;
|
||||
|
||||
var program = file.ast.program;
|
||||
|
||||
useStrict.wrap(program, function () {
|
||||
program.body = file.dynamicImports.concat(program.body);
|
||||
});
|
||||
|
||||
if (file.moduleFormatter.transform) {
|
||||
file.moduleFormatter.transform(program);
|
||||
}
|
||||
};
|
||||
@@ -1,53 +0,0 @@
|
||||
"use strict";
|
||||
|
||||
// in this transformer we have to split up classes and function declarations
|
||||
// from their exports. why? because sometimes we need to replace classes with
|
||||
// nodes that aren't allowed in the same contexts. also, if you're exporting
|
||||
// a generator function as a default then regenerator will destroy the export
|
||||
// declaration and leave a variable declaration in it's place... yeah, handy.
|
||||
|
||||
var t = require("../../../types");
|
||||
|
||||
var resolveModuleSource = function (node, parent, scope, file) {
|
||||
var resolveModuleSource = file.opts.resolveModuleSource;
|
||||
if (node.source && resolveModuleSource) {
|
||||
node.source.value = resolveModuleSource(node.source.value);
|
||||
}
|
||||
};
|
||||
|
||||
exports.check = function (node) {
|
||||
return t.isImportDeclaration(node) || t.isExportDeclaration(node);
|
||||
};
|
||||
|
||||
exports.ImportDeclaration = resolveModuleSource;
|
||||
|
||||
exports.ExportDeclaration = function (node, parent, scope) {
|
||||
resolveModuleSource.apply(null, arguments);
|
||||
|
||||
var declar = node.declaration;
|
||||
|
||||
if (node.default) {
|
||||
if (t.isClassDeclaration(declar)) {
|
||||
node.declaration = declar.id;
|
||||
return [declar, node];
|
||||
} else if (t.isClassExpression(declar)) {
|
||||
var temp = scope.generateUidIdentifier("default");
|
||||
declar = t.variableDeclaration("var", [
|
||||
t.variableDeclarator(temp, declar)
|
||||
]);
|
||||
node.declaration = temp;
|
||||
return [declar, node];
|
||||
} else if (t.isFunctionDeclaration(declar)) {
|
||||
node._blockHoist = 2;
|
||||
node.declaration = declar.id;
|
||||
return [declar, node];
|
||||
}
|
||||
} else {
|
||||
if (t.isFunctionDeclaration(declar)) {
|
||||
node.specifiers = [t.importSpecifier(declar.id, declar.id)];
|
||||
node.declaration = null;
|
||||
node._blockHoist = 2;
|
||||
return [declar, node];
|
||||
}
|
||||
}
|
||||
};
|
||||
@@ -1,17 +0,0 @@
|
||||
"use strict";
|
||||
|
||||
var t = require("../../../types");
|
||||
|
||||
var isConsole = t.buildMatchMemberExpression("console", true);
|
||||
|
||||
exports.optional = true;
|
||||
|
||||
exports.CallExpression = function (node, parent) {
|
||||
if (isConsole(node.callee)) {
|
||||
if (t.isExpressionStatement(parent)) {
|
||||
this.parentPath.remove();
|
||||
} else {
|
||||
this.remove();
|
||||
}
|
||||
}
|
||||
};
|
||||
@@ -1,9 +0,0 @@
|
||||
var t = require("../../../types");
|
||||
|
||||
exports.optional = true;
|
||||
|
||||
exports.ExpressionStatement = function (node) {
|
||||
if (t.isIdentifier(node.expression, { name: "debugger" })) {
|
||||
this.remove();
|
||||
}
|
||||
};
|
||||
@@ -1,9 +0,0 @@
|
||||
//var t = require("../../../types");
|
||||
|
||||
exports.optional = true;
|
||||
|
||||
exports.Scopable = function () {
|
||||
//for (var name in scope.bindings) {
|
||||
// scope.rename(name, scope.generateUidIdentifier("a").name);
|
||||
//}
|
||||
};
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user