Compare commits
1148 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a813341433 | ||
|
|
4968de9803 | ||
|
|
0de2d33e8d | ||
|
|
6f81ddd0d5 | ||
|
|
6b83055b12 | ||
|
|
080c23d5ed | ||
|
|
293bec58d7 | ||
|
|
93ceafc732 | ||
|
|
b2bac04b72 | ||
|
|
e549c37ca1 | ||
|
|
02512da38d | ||
|
|
abe9c4fd30 | ||
|
|
af21c52cc6 | ||
|
|
706626f79a | ||
|
|
b8dd421073 | ||
|
|
5453c466d6 | ||
|
|
0cfb2e76b8 | ||
|
|
ba67f57c1e | ||
|
|
f1a178f8f9 | ||
|
|
b1d1909c64 | ||
|
|
9529f93690 | ||
|
|
925b1f7600 | ||
|
|
40f8bc0a65 | ||
|
|
3a0dbabf5a | ||
|
|
383912c11b | ||
|
|
470c8fced0 | ||
|
|
e3dc2355e8 | ||
|
|
9733cb58c9 | ||
|
|
edd5a3878a | ||
|
|
78d2c4fa8d | ||
|
|
e268dc6138 | ||
|
|
5b6c0fcacd | ||
|
|
777f2be14e | ||
|
|
41d60a85e9 | ||
|
|
800c350db6 | ||
|
|
7b5b8ab6ed | ||
|
|
c7a02ca289 | ||
|
|
52e23473ed | ||
|
|
af412cae28 | ||
|
|
4c2c96366f | ||
|
|
de427936a6 | ||
|
|
9d6850d576 | ||
|
|
20a0280a52 | ||
|
|
64b7d6fa93 | ||
|
|
d7ca7ebbb9 | ||
|
|
9680730e24 | ||
|
|
07667d80ff | ||
|
|
9a633ebd9c | ||
|
|
fac4a61245 | ||
|
|
0ebc073762 | ||
|
|
860432cdfd | ||
|
|
c408432445 | ||
|
|
27e9f9d616 | ||
|
|
94a11cd602 | ||
|
|
ab6e424cac | ||
|
|
9ee7b07cbf | ||
|
|
31fff092b6 | ||
|
|
e847ac11af | ||
|
|
aee1ca45b0 | ||
|
|
46632e1a97 | ||
|
|
961e0b9b6b | ||
|
|
afdde8b3a7 | ||
|
|
918ddb4124 | ||
|
|
18739ad78b | ||
|
|
74a84e2473 | ||
|
|
52ffc65a06 | ||
|
|
d4fbfbbe47 | ||
|
|
781467d423 | ||
|
|
44f5b7d013 | ||
|
|
dcf7f0b70b | ||
|
|
03efd69998 | ||
|
|
213003a007 | ||
|
|
b0503f2efe | ||
|
|
c8cf7ff286 | ||
|
|
ceb32816d7 | ||
|
|
32b94899a6 | ||
|
|
d951082b09 | ||
|
|
b49f6e33d6 | ||
|
|
c5fa6425a5 | ||
|
|
70d896d609 | ||
|
|
e00fa8c9b1 | ||
|
|
13933bc9b8 | ||
|
|
295bab544b | ||
|
|
cfe05ca10d | ||
|
|
da72182219 | ||
|
|
005f5b2174 | ||
|
|
8551c94fa0 | ||
|
|
c509d06bc2 | ||
|
|
f21743012b | ||
|
|
22dc33f93c | ||
|
|
6df6652629 | ||
|
|
4942ba6dd7 | ||
|
|
b63bd8cba0 | ||
|
|
cd1eb11171 | ||
|
|
6e1c12fd78 | ||
|
|
a4ea71b85d | ||
|
|
1df69bdbeb | ||
|
|
84c2766756 | ||
|
|
1f000ac83d | ||
|
|
322aa246b8 | ||
|
|
601bbb86cd | ||
|
|
5c39685650 | ||
|
|
e6ac5eccd0 | ||
|
|
c4c9f7984f | ||
|
|
8d472a14be | ||
|
|
4fd007948c | ||
|
|
f4e516e8ce | ||
|
|
7fcd8ea642 | ||
|
|
add0a7d5fe | ||
|
|
e9445c9277 | ||
|
|
df66fa0a7f | ||
|
|
0a85211e8e | ||
|
|
ac8fc24fdb | ||
|
|
71c4a29a78 | ||
|
|
08dde22939 | ||
|
|
d3ea0fe84f | ||
|
|
22851cd1ac | ||
|
|
987dc0692f | ||
|
|
560d60e3e7 | ||
|
|
e96d02c972 | ||
|
|
13a2d469a3 | ||
|
|
0b232ed228 | ||
|
|
9053e0dedf | ||
|
|
873e820210 | ||
|
|
27bb08eadf | ||
|
|
bea903c69f | ||
|
|
198a9c6ead | ||
|
|
9c92679053 | ||
|
|
87d2bdadeb | ||
|
|
fa71f2a7f9 | ||
|
|
66e7134335 | ||
|
|
99a1cf08f9 | ||
|
|
5de9c22452 | ||
|
|
694a8dc456 | ||
|
|
2df1ca3971 | ||
|
|
6c7cdc9b7c | ||
|
|
52b1d055ac | ||
|
|
2a316bf362 | ||
|
|
26ce0b8c8b | ||
|
|
275c4cc34e | ||
|
|
bc914e6f23 | ||
|
|
4ea425ac7b | ||
|
|
bd255257f1 | ||
|
|
41f072d112 | ||
|
|
2a4c8e8423 | ||
|
|
122705bdaf | ||
|
|
f84e0ba640 | ||
|
|
64216ec384 | ||
|
|
a948928973 | ||
|
|
5ab891b39d | ||
|
|
2a742b5fac | ||
|
|
cd6b678b51 | ||
|
|
c290a008b2 | ||
|
|
e8f0c8e8a4 | ||
|
|
22eb8edf41 | ||
|
|
a3eb8900a9 | ||
|
|
bf74f5a634 | ||
|
|
98e9a45f63 | ||
|
|
1d91a758b4 | ||
|
|
b94b4b335b | ||
|
|
104b1f4c9b | ||
|
|
00c95f6a94 | ||
|
|
f14dc60934 | ||
|
|
2fc8010034 | ||
|
|
882ed48438 | ||
|
|
49578fe223 | ||
|
|
01bdb7efdc | ||
|
|
fc7fc384c9 | ||
|
|
bd78e3ed4d | ||
|
|
1f990f4030 | ||
|
|
d8e4a4a776 | ||
|
|
473b6d6a91 | ||
|
|
3d975da530 | ||
|
|
1a4110e0a1 | ||
|
|
a03d491ac6 | ||
|
|
e01e010577 | ||
|
|
132ac00ec7 | ||
|
|
1673f78ab5 | ||
|
|
76b8a06e90 | ||
|
|
711f84c826 | ||
|
|
4b4ff007e9 | ||
|
|
e31e68cae3 | ||
|
|
778b4e3a27 | ||
|
|
6011db7ae1 | ||
|
|
363b1631f5 | ||
|
|
01286ebd5b | ||
|
|
fe918a3535 | ||
|
|
2fb6c7820c | ||
|
|
e7cbbefc11 | ||
|
|
f4fdc3adc6 | ||
|
|
2cd49b08ec | ||
|
|
1b16ff3a0b | ||
|
|
b7c298a0ee | ||
|
|
5da4397392 | ||
|
|
ea5954121e | ||
|
|
37b2e747d5 | ||
|
|
3dd6eb1202 | ||
|
|
319ed09407 | ||
|
|
77f9596682 | ||
|
|
00cb90541a | ||
|
|
d26f441a5c | ||
|
|
11fc7cd0ce | ||
|
|
c38428c536 | ||
|
|
bf40849e35 | ||
|
|
194fb77b9c | ||
|
|
ceb8e812b6 | ||
|
|
3a261a5e05 | ||
|
|
4c1ad04b2c | ||
|
|
0d9e6aca67 | ||
|
|
aac6303696 | ||
|
|
833a4900da | ||
|
|
525169460a | ||
|
|
13785bddb0 | ||
|
|
84332da399 | ||
|
|
aae7d8190b | ||
|
|
03dcc335d8 | ||
|
|
9ca05b1971 | ||
|
|
2a27b7c16c | ||
|
|
c92fd6f0bb | ||
|
|
2267344471 | ||
|
|
593e4ca670 | ||
|
|
e563783a1e | ||
|
|
615425c808 | ||
|
|
55e2010311 | ||
|
|
74f40c2824 | ||
|
|
c26ce1c114 | ||
|
|
2537768772 | ||
|
|
8af05634fa | ||
|
|
74614e712e | ||
|
|
ad923cf8fa | ||
|
|
c7d69b2f92 | ||
|
|
2a0b63f3bb | ||
|
|
01934b6960 | ||
|
|
8ffd2e843f | ||
|
|
6d68b3da4d | ||
|
|
79b4207b44 | ||
|
|
30a90d2554 | ||
|
|
bac8758369 | ||
|
|
d00faf4a72 | ||
|
|
b986a4e482 | ||
|
|
f11f364d2c | ||
|
|
c4a0f62eef | ||
|
|
072fff0f4c | ||
|
|
59b81b389a | ||
|
|
4a439857d2 | ||
|
|
187f7ba01e | ||
|
|
e6da342e8b | ||
|
|
1c22c608a9 | ||
|
|
8e96130bc0 | ||
|
|
0f47814b41 | ||
|
|
b32d56a168 | ||
|
|
5f26a0c5cc | ||
|
|
2245bbc6c4 | ||
|
|
b8d61f1528 | ||
|
|
e97e916b5c | ||
|
|
b688154aee | ||
|
|
ccb56fe33f | ||
|
|
5e67dfbd9e | ||
|
|
6f6d9bd5a8 | ||
|
|
61b9c28ce6 | ||
|
|
d11d0d3216 | ||
|
|
bd876f7a4d | ||
|
|
f9f48620de | ||
|
|
ce9a82c194 | ||
|
|
24f6dfa8e2 | ||
|
|
f592f95a68 | ||
|
|
2e0cd0f349 | ||
|
|
e17d5bdb13 | ||
|
|
c1c22ed5f7 | ||
|
|
bf07f54e57 | ||
|
|
eef0344cb2 | ||
|
|
88a85c0ca8 | ||
|
|
302e6f4caa | ||
|
|
36c16a0227 | ||
|
|
0ee4a15d01 | ||
|
|
fbdaedc4f8 | ||
|
|
75c8d73d35 | ||
|
|
21599d3a9a | ||
|
|
9fbbabc7e4 | ||
|
|
8c1fe49b2e | ||
|
|
763b4caf32 | ||
|
|
c0248cf04c | ||
|
|
a7a6ee80f2 | ||
|
|
aa298b1e0a | ||
|
|
9c0a8e22d2 | ||
|
|
7c1a924ef6 | ||
|
|
1d975a2635 | ||
|
|
67cfdbd447 | ||
|
|
ab02231d39 | ||
|
|
40a2d14c7c | ||
|
|
573283f260 | ||
|
|
0497860462 | ||
|
|
a173775fec | ||
|
|
c5214ffe70 | ||
|
|
3d62af004d | ||
|
|
d7af8c6261 | ||
|
|
680c6b166a | ||
|
|
5bad458b09 | ||
|
|
055f894a88 | ||
|
|
da8edecc09 | ||
|
|
cd6dea6480 | ||
|
|
69d7ac0e0c | ||
|
|
dae46bfbfa | ||
|
|
b5b175c45a | ||
|
|
569c681c4f | ||
|
|
ed1e4a7820 | ||
|
|
b55f941dae | ||
|
|
a0219ef278 | ||
|
|
b9266b0c4c | ||
|
|
a1239e5f5a | ||
|
|
2f279de7d1 | ||
|
|
c70b3586fb | ||
|
|
3928384c27 | ||
|
|
e469f7f589 | ||
|
|
988ab0e823 | ||
|
|
e708394408 | ||
|
|
7c3ab8bc3c | ||
|
|
2b11a45117 | ||
|
|
d5666912d4 | ||
|
|
2eab56c38b | ||
|
|
888ab5473a | ||
|
|
5fe1c07d9a | ||
|
|
758a873894 | ||
|
|
e91926d094 | ||
|
|
5085b96753 | ||
|
|
66f67b92ce | ||
|
|
3c9fa13a1f | ||
|
|
5f21fc2f17 | ||
|
|
4bd4e4cdbe | ||
|
|
3c7b2d7872 | ||
|
|
5db757354a | ||
|
|
063b379d4f | ||
|
|
af42fe3d30 | ||
|
|
3c808fcef2 | ||
|
|
a29505f75d | ||
|
|
05942d17bf | ||
|
|
be0d4b344b | ||
|
|
f1a2401681 | ||
|
|
2d61672cdb | ||
|
|
1b00ba21a1 | ||
|
|
f8ea386f3c | ||
|
|
2527fffbad | ||
|
|
86498ad990 | ||
|
|
27c8804214 | ||
|
|
2b6f0ee780 | ||
|
|
c7c9660c79 | ||
|
|
ff025e63ec | ||
|
|
9fb6681ad3 | ||
|
|
301887f88d | ||
|
|
b519bb6a68 | ||
|
|
b6e366ad94 | ||
|
|
ba2204156c | ||
|
|
2545292bce | ||
|
|
c763cf364c | ||
|
|
1db7247d9a | ||
|
|
1a1e6bc3ba | ||
|
|
d184bc93b9 | ||
|
|
e12cca974a | ||
|
|
b17bc95b4f | ||
|
|
a71f260377 | ||
|
|
8cbc1f7f06 | ||
|
|
34335018e9 | ||
|
|
136bddab33 | ||
|
|
b2951c5462 | ||
|
|
07de6f5f4a | ||
|
|
99ea00ca18 | ||
|
|
ab5c6a38eb | ||
|
|
52cee84625 | ||
|
|
20dc8b05c9 | ||
|
|
ba5992621d | ||
|
|
cdae98f653 | ||
|
|
81434bb557 | ||
|
|
3af0fc6fb7 | ||
|
|
3f60062ab6 | ||
|
|
76499bb26e | ||
|
|
44f2f701e1 | ||
|
|
032bc0af5e | ||
|
|
0e822a7e54 | ||
|
|
51e521f0e0 | ||
|
|
e5ce69d6af | ||
|
|
e3b8fa93e2 | ||
|
|
f4ce3a23ad | ||
|
|
39f4696ac7 | ||
|
|
4a9918ec6b | ||
|
|
c87e14f6a9 | ||
|
|
680771c81b | ||
|
|
cad3f63723 | ||
|
|
eceda64528 | ||
|
|
b8ec87e058 | ||
|
|
04bd023787 | ||
|
|
f1759dc419 | ||
|
|
2985f1b40b | ||
|
|
14d1b6701e | ||
|
|
eb3cc9ff07 | ||
|
|
b97a2bd61d | ||
|
|
49e7e3b998 | ||
|
|
11ac6ff084 | ||
|
|
54e7e495ac | ||
|
|
fafdb1a18a | ||
|
|
b599e2c794 | ||
|
|
7f57d3d6a2 | ||
|
|
a2b0ee6809 | ||
|
|
83e8c4bddd | ||
|
|
57aca3c77f | ||
|
|
f80527832c | ||
|
|
2ecceaac45 | ||
|
|
32f8f9e663 | ||
|
|
3447204d97 | ||
|
|
c500532469 | ||
|
|
3396cc84f1 | ||
|
|
1de4893a69 | ||
|
|
abba930f36 | ||
|
|
c84097cf57 | ||
|
|
790b81938c | ||
|
|
187bbca731 | ||
|
|
4ccc12b04d | ||
|
|
9a5f97d85b | ||
|
|
4ed77e136b | ||
|
|
0339d21c33 | ||
|
|
4502aee988 | ||
|
|
55150853b4 | ||
|
|
b9da4f988c | ||
|
|
bf0ca10253 | ||
|
|
fcc4734a1f | ||
|
|
d1c5c773fa | ||
|
|
01ce38c5ac | ||
|
|
cc6d440f0e | ||
|
|
2b21f4b571 | ||
|
|
24d9833170 | ||
|
|
20f21987de | ||
|
|
fad0be8a45 | ||
|
|
02c42b94f5 | ||
|
|
4808689795 | ||
|
|
6231dceb1c | ||
|
|
1753afa782 | ||
|
|
4097da09bd | ||
|
|
c7965df42d | ||
|
|
1027f8a5a4 | ||
|
|
cbd6be30bf | ||
|
|
7e299470fd | ||
|
|
c794c2aede | ||
|
|
1a58087460 | ||
|
|
44f6fc67f8 | ||
|
|
e4a3d222d6 | ||
|
|
5a96c2e015 | ||
|
|
43390c0d1f | ||
|
|
d166656149 | ||
|
|
acc4d289e4 | ||
|
|
717e6df407 | ||
|
|
286404c6f2 | ||
|
|
f191fd7883 | ||
|
|
74f36cfaa0 | ||
|
|
71aed8b269 | ||
|
|
9e6b0b45b3 | ||
|
|
7bbb3725d4 | ||
|
|
1210c92405 | ||
|
|
714ca9fbc8 | ||
|
|
60713f0e5f | ||
|
|
f1f5f8bb27 | ||
|
|
a69f095720 | ||
|
|
d50d4972a7 | ||
|
|
bd91bbee71 | ||
|
|
8b46cce466 | ||
|
|
defa9108bd | ||
|
|
6b1d9b49b7 | ||
|
|
4e333cf357 | ||
|
|
ddcd7ab28d | ||
|
|
4b8a4492ba | ||
|
|
4256a9960c | ||
|
|
ecb695c30c | ||
|
|
db97f665ed | ||
|
|
931b68dc5d | ||
|
|
b5feaf7c2f | ||
|
|
d82683f598 | ||
|
|
6772f5a74f | ||
|
|
a90f133918 | ||
|
|
71ad511322 | ||
|
|
ff6677a4b7 | ||
|
|
ac5e0ad392 | ||
|
|
0a25618c34 | ||
|
|
984c048591 | ||
|
|
5867e24886 | ||
|
|
02d7cdc701 | ||
|
|
d3b3febfeb | ||
|
|
7fccf98c10 | ||
|
|
4a1c393bdb | ||
|
|
afaf3fb0c0 | ||
|
|
2152ae9b17 | ||
|
|
b8f5693b5e | ||
|
|
638143700b | ||
|
|
aa7eb9c1c9 | ||
|
|
27ca532896 | ||
|
|
913fbdbd87 | ||
|
|
fb39df71eb | ||
|
|
102a566b1d | ||
|
|
b924e3deb5 | ||
|
|
ef21724a9c | ||
|
|
fdad51b53b | ||
|
|
df0e4f6431 | ||
|
|
a37f2093bc | ||
|
|
32b32329b2 | ||
|
|
d4379d52a7 | ||
|
|
5c5d811647 | ||
|
|
8feb17dd23 | ||
|
|
55b3f84a2f | ||
|
|
50dee1a754 | ||
|
|
f80f860bbc | ||
|
|
7fc2fe41af | ||
|
|
a884a26402 | ||
|
|
81ec1e1f42 | ||
|
|
1a27970376 | ||
|
|
6822c854d4 | ||
|
|
8f4c4be821 | ||
|
|
5fca095149 | ||
|
|
34599a21cb | ||
|
|
d9d84c60b5 | ||
|
|
221d78d2e2 | ||
|
|
fa46f60655 | ||
|
|
03ce52fb7c | ||
|
|
0df0c696a9 | ||
|
|
21b7f4120e | ||
|
|
f43a3dec4b | ||
|
|
cacee5c625 | ||
|
|
553c90ae75 | ||
|
|
bc3502d695 | ||
|
|
6ae03a5dce | ||
|
|
9895711bf4 | ||
|
|
d2724554cc | ||
|
|
8db466c698 | ||
|
|
68ef2d545e | ||
|
|
861b9e68d3 | ||
|
|
a0eb108cd4 | ||
|
|
756aef6adc | ||
|
|
7b74c1c8ec | ||
|
|
8e115ef3ed | ||
|
|
b9a6cf35b7 | ||
|
|
2e22de71b4 | ||
|
|
a077c75c8c | ||
|
|
c0b03e8126 | ||
|
|
a3a4a7645c | ||
|
|
7bd1337ee8 | ||
|
|
c54f530b10 | ||
|
|
9d3a3a57f2 | ||
|
|
e1474c2f5f | ||
|
|
8a9a205122 | ||
|
|
885d65f9de | ||
|
|
43d1435c97 | ||
|
|
247c14c5ab | ||
|
|
0e2b12c134 | ||
|
|
59c5abe188 | ||
|
|
e1cc1dcb4b | ||
|
|
d091793077 | ||
|
|
e6baac1003 | ||
|
|
c41608edc3 | ||
|
|
3815913537 | ||
|
|
e5c18749f0 | ||
|
|
b7458f949c | ||
|
|
69302b314f | ||
|
|
0c57a00fdb | ||
|
|
3bec8b0311 | ||
|
|
6a88e05362 | ||
|
|
e3bd2dff8d | ||
|
|
ef82171254 | ||
|
|
00d94fd810 | ||
|
|
d929d3c5eb | ||
|
|
5c1ee86b97 | ||
|
|
5409691a3a | ||
|
|
24964ac454 | ||
|
|
faa81ab85b | ||
|
|
d4bc082bb9 | ||
|
|
3777af6bbd | ||
|
|
1f258e9e9c | ||
|
|
50333c879c | ||
|
|
105e6ac379 | ||
|
|
dadab64e39 | ||
|
|
2b82f2bcc2 | ||
|
|
f1183505b1 | ||
|
|
fa3b24e5b4 | ||
|
|
5789447068 | ||
|
|
f1f7321590 | ||
|
|
9ff4df6dae | ||
|
|
0dbb24c922 | ||
|
|
a027d2b9cf | ||
|
|
e290990371 | ||
|
|
d0a2bd170e | ||
|
|
69db46f96b | ||
|
|
27ba4b2bba | ||
|
|
b337c1ab06 | ||
|
|
a1895b4bb4 | ||
|
|
00483917f0 | ||
|
|
d09bafaf8c | ||
|
|
a7ef02c781 | ||
|
|
94cd45c269 | ||
|
|
424bab97d0 | ||
|
|
a1bdd804e2 | ||
|
|
10c051890b | ||
|
|
ac49d0a335 | ||
|
|
b56f1800e5 | ||
|
|
49ef92c586 | ||
|
|
542fe89123 | ||
|
|
5b118c0c3f | ||
|
|
8503916799 | ||
|
|
206c828a56 | ||
|
|
7a261a1db1 | ||
|
|
c9d9a085f1 | ||
|
|
6d1953d9c3 | ||
|
|
92621d71c7 | ||
|
|
dc01731c25 | ||
|
|
9fb8a80f60 | ||
|
|
85c2de57e4 | ||
|
|
58fac2e2be | ||
|
|
682806f1ca | ||
|
|
47c6f74251 | ||
|
|
37f360c72d | ||
|
|
e5a8c95b62 | ||
|
|
921d459f13 | ||
|
|
58898932e6 | ||
|
|
c7b45116c4 | ||
|
|
32ddd638ba | ||
|
|
0eb3cda2d4 | ||
|
|
2acb24d43d | ||
|
|
fdd1451d53 | ||
|
|
43e2f121a6 | ||
|
|
297e55ba63 | ||
|
|
38396dadd5 | ||
|
|
f75f045026 | ||
|
|
740193b1e2 | ||
|
|
b9fe1475c2 | ||
|
|
6065220f9b | ||
|
|
715884662e | ||
|
|
11780c28ff | ||
|
|
215c2da7cb | ||
|
|
c7c41d6548 | ||
|
|
695571b435 | ||
|
|
f845633cc1 | ||
|
|
72c9b1d6c9 | ||
|
|
edd3363e48 | ||
|
|
114b5ef9ec | ||
|
|
2f4e0c3361 | ||
|
|
3ee51dae1a | ||
|
|
20263c1151 | ||
|
|
eaac564f11 | ||
|
|
63a47ef7bb | ||
|
|
6963cc1e40 | ||
|
|
5eb2462e29 | ||
|
|
9e285cdc20 | ||
|
|
01ade47af9 | ||
|
|
b1fe449b0d | ||
|
|
2b458ec2d4 | ||
|
|
d5f47f4f4d | ||
|
|
d4deb18975 | ||
|
|
5a794db73b | ||
|
|
dc131f05a8 | ||
|
|
1d4f79790a | ||
|
|
6bcbaf6df1 | ||
|
|
bc199ef0c9 | ||
|
|
f5fed99c81 | ||
|
|
66a6d3cffe | ||
|
|
39227486a6 | ||
|
|
caafa31df1 | ||
|
|
4c41c904f5 | ||
|
|
0917a6a5b1 | ||
|
|
349eba33ce | ||
|
|
8ff21b407d | ||
|
|
751ea7a12c | ||
|
|
b30cd227cc | ||
|
|
18dc7b8143 | ||
|
|
1c628bbec1 | ||
|
|
d4c3dde02a | ||
|
|
a587106a6b | ||
|
|
9c1b60e451 | ||
|
|
0c7e0b65b9 | ||
|
|
5c17091db4 | ||
|
|
7fa5ba88df | ||
|
|
2fae245cd5 | ||
|
|
297f103ddb | ||
|
|
fd63650d6a | ||
|
|
e13ed39567 | ||
|
|
bb00f641b7 | ||
|
|
25b466a627 | ||
|
|
ac231f2987 | ||
|
|
458e3d48f6 | ||
|
|
c235780611 | ||
|
|
56b858ccb1 | ||
|
|
d42351bb02 | ||
|
|
ed7378cc2d | ||
|
|
a47a7dc347 | ||
|
|
2c82b5a4b0 | ||
|
|
3578135b90 | ||
|
|
5f3408b2a2 | ||
|
|
9e3f9fda6b | ||
|
|
7f425d2c6e | ||
|
|
311a8e042b | ||
|
|
27d30329fd | ||
|
|
12c5a3e73b | ||
|
|
2a166a6ed1 | ||
|
|
896929378e | ||
|
|
ae439d27b9 | ||
|
|
e22798261a | ||
|
|
d0af8b8d0a | ||
|
|
beaa2fa540 | ||
|
|
b8cac9787e | ||
|
|
64f6e4a0c5 | ||
|
|
c4a7ac5a8b | ||
|
|
1ed682fa76 | ||
|
|
9987e7fe0e | ||
|
|
e74c7cb0b7 | ||
|
|
2f01e5c3af | ||
|
|
6847211971 | ||
|
|
965e246259 | ||
|
|
af59eb7d6a | ||
|
|
def4319058 | ||
|
|
d90383b1ba | ||
|
|
1ac40ee834 | ||
|
|
3d5d170eff | ||
|
|
b5bdba46f1 | ||
|
|
c4e162b8e5 | ||
|
|
98bc750b05 | ||
|
|
84002ed1ce | ||
|
|
aaab2db0ec | ||
|
|
7f3959444c | ||
|
|
0ba9216d6f | ||
|
|
6dfe66bce3 | ||
|
|
9e08a6f084 | ||
|
|
b9f3f1e2a9 | ||
|
|
4f18ed406c | ||
|
|
4d8e5f728a | ||
|
|
54857ceac7 | ||
|
|
5b961ea3e7 | ||
|
|
35b28cf722 | ||
|
|
c5bfbf37f0 | ||
|
|
cfee68aa67 | ||
|
|
7d0dae129c | ||
|
|
f9d14fa2ed | ||
|
|
11d55e661e | ||
|
|
0544e98fb1 | ||
|
|
59d918ea67 | ||
|
|
b4232699d2 | ||
|
|
6bd67ca660 | ||
|
|
4722c0ce56 | ||
|
|
25a5caa0fc | ||
|
|
6f05466cf5 | ||
|
|
1ad9edb57c | ||
|
|
c6ae33c5a2 | ||
|
|
e0d620b1d5 | ||
|
|
5588bf56eb | ||
|
|
a0e500de6c | ||
|
|
bf8d9801ce | ||
|
|
68b99a7004 | ||
|
|
5ae4f8eec7 | ||
|
|
d9a3eadad7 | ||
|
|
b1cc5419a4 | ||
|
|
c6a7a9c401 | ||
|
|
608df54b02 | ||
|
|
2ac83ec95b | ||
|
|
e4596f638d | ||
|
|
1425af9b2a | ||
|
|
9351c6470f | ||
|
|
7b8a50509a | ||
|
|
1400dee0c1 | ||
|
|
9e2fc6db9c | ||
|
|
aef5b89492 | ||
|
|
e0bf6f698e | ||
|
|
1ac459a05d | ||
|
|
1b49835b27 | ||
|
|
db7b6a4972 | ||
|
|
79045e15c5 | ||
|
|
b7e6d8f998 | ||
|
|
88c6ce4e48 | ||
|
|
8c97f1d92e | ||
|
|
833e8b091b | ||
|
|
23ebb23944 | ||
|
|
778cab33d5 | ||
|
|
5849c6af17 | ||
|
|
bb0655d8f6 | ||
|
|
9977a5f614 | ||
|
|
9318d63b5c | ||
|
|
b2ab0dbedc | ||
|
|
e0d3e18865 | ||
|
|
3a3ad4775b | ||
|
|
40fdd2a828 | ||
|
|
12f66e852a | ||
|
|
c61c9aab56 | ||
|
|
7adc919bb6 | ||
|
|
9989b89b92 | ||
|
|
361ef02a88 | ||
|
|
72369c90a2 | ||
|
|
fa26174d3f | ||
|
|
227d51a556 | ||
|
|
a5f00aa3f6 | ||
|
|
a47723c66c | ||
|
|
ab2f652bdf | ||
|
|
5aff7709f7 | ||
|
|
06ba731452 | ||
|
|
f4c81531ad | ||
|
|
19b115c76b | ||
|
|
96b08bf7df | ||
|
|
8f435d59da | ||
|
|
6df03c00a8 | ||
|
|
4ec134814e | ||
|
|
4fb50cfe20 | ||
|
|
bac952e036 | ||
|
|
9844540bb0 | ||
|
|
1a9a60e010 | ||
|
|
e26812e622 | ||
|
|
7f306388e4 | ||
|
|
b217453d49 | ||
|
|
463165e0c8 | ||
|
|
85d7da9a7c | ||
|
|
48f6c5c649 | ||
|
|
d1187dde82 | ||
|
|
f21a6b36ac | ||
|
|
407bb9278f | ||
|
|
70b3d88455 | ||
|
|
98df094e60 | ||
|
|
4bae820a5a | ||
|
|
4e8afa18da | ||
|
|
fbf0c25bbe | ||
|
|
a90da9908c | ||
|
|
bd51215316 | ||
|
|
e3c6ee5c88 | ||
|
|
8c40db5658 | ||
|
|
4d59976d82 | ||
|
|
83286cccd2 | ||
|
|
de7edcaeb0 | ||
|
|
6c8db61b23 | ||
|
|
e3d2748970 | ||
|
|
fa8c570e77 | ||
|
|
677f9805c6 | ||
|
|
eff5efaf10 | ||
|
|
a909a6febd | ||
|
|
61ee0ef6f6 | ||
|
|
07c15f02e6 | ||
|
|
3f4068ae00 | ||
|
|
dce41bb989 | ||
|
|
896663056d | ||
|
|
dfe4ce86e0 | ||
|
|
24f0120e01 | ||
|
|
0108562e88 | ||
|
|
e4e4ae5b1d | ||
|
|
ba04377ed8 | ||
|
|
cd9e289dee | ||
|
|
0b86a2fef8 | ||
|
|
b84cb1828b | ||
|
|
aedc013ab8 | ||
|
|
ab9cd4e630 | ||
|
|
8ef5148870 | ||
|
|
4cb90cb1e0 | ||
|
|
d0a33ab933 | ||
|
|
9ea4431ba3 | ||
|
|
08580edda8 | ||
|
|
5c6d57c51b | ||
|
|
744d1af485 | ||
|
|
591b78b159 | ||
|
|
49ea641314 | ||
|
|
37a7c92500 | ||
|
|
35b7b140da | ||
|
|
159f5217e3 | ||
|
|
795e38e4f4 | ||
|
|
2a9af21e93 | ||
|
|
e327e041ab | ||
|
|
f8e8cd3979 | ||
|
|
b3206d94a6 | ||
|
|
fcbd315bc1 | ||
|
|
71646f4ade | ||
|
|
56ac964e54 | ||
|
|
e5f1eb64b6 | ||
|
|
6145f0a03b | ||
|
|
54f901f131 | ||
|
|
df70be4ebb | ||
|
|
99ba77bb0b | ||
|
|
346f72be05 | ||
|
|
c0e6cda071 | ||
|
|
c054ff7bbb | ||
|
|
771d3dc8a0 | ||
|
|
e8d4806b45 | ||
|
|
469a522300 | ||
|
|
4068a8bf68 | ||
|
|
a04513a3c7 | ||
|
|
6f0ca947a7 | ||
|
|
dd62244e10 | ||
|
|
12f68b05c3 | ||
|
|
62fe128132 | ||
|
|
bf632ca20b | ||
|
|
26428cde41 | ||
|
|
9bb8a16d93 | ||
|
|
44cd044586 | ||
|
|
765899a521 | ||
|
|
1d40cac52f | ||
|
|
fb0325a4d8 | ||
|
|
1df25a633c | ||
|
|
cfbaae456b | ||
|
|
95ace3220d | ||
|
|
2e0f3de72c | ||
|
|
732c21d42a | ||
|
|
a535007a35 | ||
|
|
5ff6f445b2 | ||
|
|
d7ae3b506a | ||
|
|
287cbbb6a1 | ||
|
|
d1088583ba | ||
|
|
c967cded78 | ||
|
|
71d87f5b97 | ||
|
|
56271efada | ||
|
|
89fbb06658 | ||
|
|
43ee3b77f3 | ||
|
|
9ef826b53e | ||
|
|
6519ceaa63 | ||
|
|
d28496006e | ||
|
|
5f9710e61f | ||
|
|
c4cadd8a64 | ||
|
|
d3c5b8ef0b | ||
|
|
120df2c611 | ||
|
|
719d23eb3b | ||
|
|
364abf60ea | ||
|
|
0f5a141c91 | ||
|
|
fca3a0c56f | ||
|
|
e88505aba6 | ||
|
|
500a0bdfb6 | ||
|
|
2a0efceef5 | ||
|
|
225754ae12 | ||
|
|
6f230de01c | ||
|
|
3c3746b21f | ||
|
|
f49f057b33 | ||
|
|
e3b9a0dd38 | ||
|
|
f540c3f4b7 | ||
|
|
6e5917e537 | ||
|
|
816c1d304b | ||
|
|
5deeae1aa2 | ||
|
|
718e342e86 | ||
|
|
cb98605520 | ||
|
|
600513bcab | ||
|
|
620e5791af | ||
|
|
47ee2cc99f | ||
|
|
6cc70f7465 | ||
|
|
20484c66c5 | ||
|
|
171bcad870 | ||
|
|
c963c30107 | ||
|
|
795183569d | ||
|
|
9a3c973280 | ||
|
|
95f3ca6348 | ||
|
|
c17878913b | ||
|
|
c8139317ee | ||
|
|
6d6039aeb6 | ||
|
|
74f11dfddf | ||
|
|
4c63b4ea1e | ||
|
|
6332e725fe | ||
|
|
f3d371869d | ||
|
|
89ecd46b77 | ||
|
|
9f8e8d96a8 | ||
|
|
a7bbd1dd3e | ||
|
|
6d961c1857 | ||
|
|
e13a650d05 | ||
|
|
3cd7ed69a3 | ||
|
|
93c6d69e21 | ||
|
|
57d3c836bd | ||
|
|
115282d57b | ||
|
|
72d924d85b | ||
|
|
6838062279 | ||
|
|
bc79cec15a | ||
|
|
85f0f6fb14 | ||
|
|
bf61c1e85d | ||
|
|
bd2e3d784f | ||
|
|
7e8c5cd20f | ||
|
|
ddbb522392 | ||
|
|
288cfd1f00 | ||
|
|
435b9434ea | ||
|
|
2409b017db | ||
|
|
99f2864048 | ||
|
|
5351057557 | ||
|
|
1a5ee7d5da | ||
|
|
ebea86c527 | ||
|
|
bf58004947 | ||
|
|
f0c78102ca | ||
|
|
da1512eeb0 | ||
|
|
43ea593677 | ||
|
|
629cea497f | ||
|
|
9475dc681f | ||
|
|
6e41309ede | ||
|
|
42322e1ce7 | ||
|
|
400fa8ed97 | ||
|
|
07e2842226 | ||
|
|
7d46b7c465 | ||
|
|
fcf6c9e066 | ||
|
|
a5523664fc | ||
|
|
1841f5c8a0 | ||
|
|
33f8988313 | ||
|
|
1d3544eadc | ||
|
|
646bdfd04c | ||
|
|
aba9bba7db | ||
|
|
e77382582f | ||
|
|
af997b9945 | ||
|
|
a2332f08bc | ||
|
|
bbffde374e | ||
|
|
115dca56b6 | ||
|
|
251e4d01c8 | ||
|
|
0fbf0e2a77 | ||
|
|
e8628ea1a7 | ||
|
|
a5a8f08bb8 | ||
|
|
d376bd3c0e | ||
|
|
20818b086c | ||
|
|
f9ef1723a6 | ||
|
|
6e7b8a14fe | ||
|
|
622bb2e962 | ||
|
|
5c5348537d | ||
|
|
0def62b918 | ||
|
|
530ad78428 | ||
|
|
daced12baa | ||
|
|
51f18a152e | ||
|
|
51f72ace57 | ||
|
|
2fa36b30d5 | ||
|
|
11270e0803 | ||
|
|
6f8cbf0ad1 | ||
|
|
6696d5fcf4 | ||
|
|
591f123670 | ||
|
|
1f7270720f | ||
|
|
ec3a3cbbc9 | ||
|
|
8a1ea82e97 | ||
|
|
6953b6e8b6 | ||
|
|
378832d31b | ||
|
|
85703eb5b8 | ||
|
|
d0fdd3bf41 | ||
|
|
a7385bdf1b | ||
|
|
9c7c385ee8 | ||
|
|
7c84af2ba8 | ||
|
|
009d063790 | ||
|
|
5483c4ef6f | ||
|
|
5558f61518 | ||
|
|
96bc95d6d9 | ||
|
|
11dd13b7e0 | ||
|
|
976e6782a2 | ||
|
|
febc3062cc | ||
|
|
efff5e5aab | ||
|
|
eefab7f80f | ||
|
|
1a3d306949 | ||
|
|
e5ae2f8eaf | ||
|
|
e797be518f | ||
|
|
45cb755845 | ||
|
|
3b9a339c79 | ||
|
|
ea7ac4cd2d | ||
|
|
e141a8b875 | ||
|
|
6768fc3800 | ||
|
|
0af5e00b5f | ||
|
|
ecedc23892 | ||
|
|
163c68dd6a | ||
|
|
4dc6147348 | ||
|
|
4b3ebc62b1 | ||
|
|
cc094efe1b | ||
|
|
8f4a3f77a0 | ||
|
|
b31f3666c8 | ||
|
|
b1495832d7 | ||
|
|
fa6e50ea28 | ||
|
|
a72c839a73 | ||
|
|
32b5edb711 | ||
|
|
8cbb121e3f | ||
|
|
75ece96475 | ||
|
|
b016fda8af | ||
|
|
2cffad61fa | ||
|
|
4e248c0a16 | ||
|
|
4f5026101b | ||
|
|
4ce38eab37 | ||
|
|
0a7ce115ff | ||
|
|
21ed438fd8 | ||
|
|
5f9e954d21 | ||
|
|
a03fd0f43a | ||
|
|
dcc5eaa95e | ||
|
|
3b7ce5aaa1 | ||
|
|
6811f071a9 | ||
|
|
9abda34e59 | ||
|
|
417ba2bd92 | ||
|
|
e23f8e92ba | ||
|
|
ef2638eb89 | ||
|
|
a7d860aab4 | ||
|
|
0e3498d785 | ||
|
|
45fe1d0d47 | ||
|
|
d5c2647701 | ||
|
|
af4d8a27aa | ||
|
|
8136b4c40b | ||
|
|
65ba4d35e7 | ||
|
|
e09312f127 | ||
|
|
1b0e42ad03 | ||
|
|
e21a0d0a8b | ||
|
|
ce170f7646 | ||
|
|
5f8420f23e | ||
|
|
ce4220644d | ||
|
|
aa50a450bd | ||
|
|
1e6b8d80bb | ||
|
|
035829e726 | ||
|
|
2b70df4141 | ||
|
|
1e7b7b3e0c | ||
|
|
b8b670e607 | ||
|
|
3467d509f7 | ||
|
|
66cc6bea08 | ||
|
|
dba935c63d | ||
|
|
73f65ae634 | ||
|
|
e263757509 | ||
|
|
b8a80364df | ||
|
|
19ba55410b | ||
|
|
c65197f006 | ||
|
|
98a04a070f | ||
|
|
2bda223001 | ||
|
|
ddefc09510 | ||
|
|
489547b77b | ||
|
|
a16685d36d | ||
|
|
891bbba375 | ||
|
|
7f2335974b | ||
|
|
ca597a2306 | ||
|
|
45bab5709f | ||
|
|
0683591c6c | ||
|
|
44966849f9 | ||
|
|
e76462303e | ||
|
|
fceff4b52f | ||
|
|
209093a3f0 | ||
|
|
7013e970d8 | ||
|
|
42a7973a9d | ||
|
|
a75248d2d2 | ||
|
|
1f274a3b95 | ||
|
|
5bc4dfc14c | ||
|
|
4241227dbe | ||
|
|
a1adca6b65 | ||
|
|
4f15bfcf1d | ||
|
|
a405d6d3d5 | ||
|
|
9c784436f0 | ||
|
|
88856e040d | ||
|
|
9f493b23ab | ||
|
|
cc84b5e1a4 | ||
|
|
2be2e4e1ae | ||
|
|
435cd98480 | ||
|
|
d3b088cc6d | ||
|
|
234d9997c8 | ||
|
|
dcaea68240 | ||
|
|
6c48e6cd66 | ||
|
|
8e2abad41c | ||
|
|
f06901ac05 | ||
|
|
531ea91a07 | ||
|
|
0188556b36 | ||
|
|
aeac003dc8 | ||
|
|
41ab47dde8 | ||
|
|
112932f9ee | ||
|
|
0efeed3d5e | ||
|
|
55fdf11555 | ||
|
|
d801c95f6e | ||
|
|
138d714589 | ||
|
|
123de49d9c | ||
|
|
7cd574d7bc | ||
|
|
45c8c29cdf | ||
|
|
5b08924c02 | ||
|
|
c2930c9650 | ||
|
|
5db127e622 |
4
.gitignore
vendored
4
.gitignore
vendored
@@ -4,5 +4,9 @@ test/tmp
|
||||
*.log
|
||||
*.cache
|
||||
/templates.json
|
||||
/tests.json
|
||||
/browser.js
|
||||
/browser-polyfill.js
|
||||
/runtime.js
|
||||
coverage
|
||||
dist
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
node_modules
|
||||
test
|
||||
lib/6to5/templates
|
||||
lib/6to5/transformation/templates
|
||||
|
||||
10
.jshintrc
10
.jshintrc
@@ -17,5 +17,13 @@
|
||||
"loopfunc": true,
|
||||
"white": true,
|
||||
"maxparams": 5,
|
||||
"maxdepth": 4
|
||||
"maxdepth": 4,
|
||||
|
||||
"globals": {
|
||||
"window": true,
|
||||
"suite": true,
|
||||
"set": true,
|
||||
"before": true,
|
||||
"bench": true
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,10 +1,11 @@
|
||||
node_modules
|
||||
*.log
|
||||
*.cache
|
||||
lib/6to5/templates
|
||||
lib/6to5/transformation/templates
|
||||
test
|
||||
benchmark
|
||||
Makefile
|
||||
.*
|
||||
dist
|
||||
!README.md
|
||||
tests.json
|
||||
CHANGELOG.md
|
||||
|
||||
15
.travis.yml
15
.travis.yml
@@ -3,10 +3,17 @@ node_js:
|
||||
- "0.10"
|
||||
- "0.11"
|
||||
|
||||
branches:
|
||||
except:
|
||||
- experimental
|
||||
|
||||
before_script: "npm install -g codeclimate-test-reporter"
|
||||
script: "make test-travis"
|
||||
|
||||
addons:
|
||||
code_climate:
|
||||
repo_token:
|
||||
secure: "PfP9sDUJzSznDb+ZEPO2cignXabSTXJxEVm5ESRPgEcFr+/4b0pt3hI8R9b+9mLtBEwtw3DLUq48MOeqEKnq29csQmpjPVcN6gT4uR2DdNa1JpVgDuwxT05NB3fBea9U2reM73iV8ylCgPHExr2uGR9/87JzR2beY/56EUL5NjY="
|
||||
notifications:
|
||||
webhooks:
|
||||
urls:
|
||||
- https://webhooks.gitter.im/e/acf1870e9d223c65e8d5
|
||||
on_success: always
|
||||
on_failure: always
|
||||
on_start: false
|
||||
|
||||
386
CHANGELOG.md
Normal file
386
CHANGELOG.md
Normal file
@@ -0,0 +1,386 @@
|
||||
# Changelog
|
||||
|
||||
Gaps between patch versions are faulty/broken releases.
|
||||
|
||||
## 2.4.2
|
||||
|
||||
* Upgrade `acorn-6to5`.
|
||||
* Better uids generated for various transformers based on parent node.
|
||||
* Alias flat references in `coreAliasing` transformer.
|
||||
|
||||
## 2.4.1
|
||||
|
||||
* Better whitespace handling of parenthesized expressions due to trailing comments.
|
||||
* Fix `yield` inside of comprehensions.
|
||||
|
||||
## 2.4.0
|
||||
|
||||
* Use a closure always for classes with a super.
|
||||
* Always use native loops for array comprehensions.
|
||||
* Allow `yield` inside of comprehensions.
|
||||
* Add optional `bluebirdCoroutine` transformer.
|
||||
* Add optional `asyncToGenerator` transformer.
|
||||
* Move `useStrict` transformer to before `_moduleFormatter` causing `"use strict";` to always be placed the very top.
|
||||
|
||||
## 2.3.2
|
||||
|
||||
* Add parens on expressions with trailing comments.
|
||||
|
||||
## 2.3.1
|
||||
|
||||
* Add `undefinedToVoid` optional transformer.
|
||||
* Use `Object.defineProperty` for computed properties.
|
||||
|
||||
## 2.3.0
|
||||
|
||||
* Upgrade `acorn-6to5`.
|
||||
* Support circular references and hoist variable declarations in `system` module formatter.
|
||||
* Add optional transformers, including a new `coreAliasing` transformer that aliases native ES6 static properties to their `core-js` equivalent.
|
||||
|
||||
## 2.2.0
|
||||
|
||||
* Make `system` module formatter modules anonymous by default.
|
||||
* Fix duplicate comments being output, breaking code.
|
||||
|
||||
## 2.1.0
|
||||
|
||||
* Add `cache` option to register hook.
|
||||
* Update `core-js`.
|
||||
* Fix starting newline not being added on case statements.
|
||||
* Fix destructuring `VariableDeclaration`s not inside `BlockStatement`s and `Program`.
|
||||
|
||||
## 2.0.4
|
||||
|
||||
* Avoid being greedy when destructuring array iterables.
|
||||
|
||||
## 2.0.3
|
||||
|
||||
* Hoist function declarations in system module formatter for circular references.
|
||||
* Hoist default function declarations in umd and amd module formatters for circular references.
|
||||
|
||||
## 2.0.2
|
||||
|
||||
* Inherit comments in `for-of` transformer.
|
||||
* Remove `interopRequire` from `system` module formatter.
|
||||
|
||||
## 2.0.1
|
||||
|
||||
* Remap `UpdateExpression` module export binding.
|
||||
* Fix automatic closure on `PrivateDeclaration` in classes.
|
||||
|
||||
## 2.0.0
|
||||
|
||||
* Make string literal generation only escapes unicode that it has to.
|
||||
* Internal code generation format options have been exposed.
|
||||
* Change playground method binding operator from `:` to `#` removing ambiguous syntax with terns.
|
||||
* Fix rest parameters in async and generator functions.
|
||||
* Export/import declarations replace by the modules transformer now inherit comments.
|
||||
* Added playground flag to `6to5-node`.
|
||||
* `6to5-node` now behaves the same as `node`.
|
||||
* `6to5-node` now uses `kexec` to become the forked process to correctly propagate signals on unix.
|
||||
* Constants are now block scoped.
|
||||
* Exposed ast transformer.
|
||||
* Merged `commonInterop` and `common` module formatters.
|
||||
* Fix generator comprehensions not inheriting `arguments`, `this` etc.
|
||||
* Object and class mutator shorthand are now enumerable.
|
||||
* Remove regenerator `Generator has already finished` error which isn't spec-compliant.
|
||||
* Expose internal `spec` transformers that nicen up code output.
|
||||
* Add export variable declaration default initializers.
|
||||
* Propagate export declaration reassignments.
|
||||
* Add initializer default to block scoped variable declarations within a loop.
|
||||
* Flow type support.
|
||||
* Make async/await contextual keywords.
|
||||
* Allow `yield`ing of non-objects.
|
||||
* Class declarations now lack an IIFE.
|
||||
* Support falsy and `null` super classes.
|
||||
* Add support for experimental abstract references `private` declarations.
|
||||
* Leave out IIFE for class declarations.
|
||||
* Switched to [core-js](https://github.com/zloirock/core-js) from [es6-symbol](https://github.com/medikoo/es6-symbol) and [es6-shim](https://github.com/paulmillr/es6-shim/) for built-in polyfill.
|
||||
* `amd` and `umd` module formatters now behave the same as `common` with `interopRequire`.
|
||||
* Micro-optimizations to boost performance by 200%.
|
||||
* Rename module formatter methods `import` to `importDeclaration` and `export` to `exportDeclaration`.
|
||||
* Support multiple declarators in export variable declarations.
|
||||
* Freeze tagged template literal object.
|
||||
* Remove inlined `regenerator` fork.
|
||||
* Remove `ParenthesizedExpression`.
|
||||
* Rename `object-spread` helper to `object-without-properties`.
|
||||
* Rename `class-props` helper to `prototype-properties`.
|
||||
* Rename `extends` helper to `inherits`.
|
||||
* Completely rewritten `system` module formatter.
|
||||
|
||||
## 1.15.0
|
||||
|
||||
* Don't alias `GeneratorFunction` and check the name which causes minifiers to remove the name and throw an error later on when we check if it's set.
|
||||
|
||||
## 1.14.18
|
||||
|
||||
* Fix files only containg comments not being output.
|
||||
* Fix duplicate comments on property key shorthands.
|
||||
|
||||
## 1.14.17
|
||||
|
||||
* Add default initializer to let variables within loop bodies.
|
||||
* Fix excessive `break` replacement inside of switches in let scoping.
|
||||
|
||||
## 1.14.16
|
||||
|
||||
* Add object getter memos and this shorthand to playground.
|
||||
* Fix while loops in let scoping.
|
||||
* Upgrade `acorn-6to5`.
|
||||
|
||||
## 1.14.14
|
||||
|
||||
* Fix template literals escaping.
|
||||
|
||||
## 1.14.13
|
||||
|
||||
* Fix let scoping of `while` loops.
|
||||
* Make class methods enumerable.
|
||||
|
||||
## 1.14.12
|
||||
|
||||
* Fix duplicate dynamic expressions in call spread.
|
||||
|
||||
## 1.14.10
|
||||
|
||||
* Fix let scoping unneccesary override.
|
||||
|
||||
## 1.14.6
|
||||
|
||||
* Avoid ensuring a block on non-array node replacements.
|
||||
|
||||
## 1.14.5
|
||||
|
||||
* Upgrade `acorn-6to5`.
|
||||
* Fix JSON recursion error for unknown code generator node types.
|
||||
* Ensure that a statement is a block on block/statement types when replacing them with multiple nodes.
|
||||
|
||||
## 1.14.4
|
||||
|
||||
* Merge pretzel maps and method binding.
|
||||
|
||||
## 1.14.3
|
||||
|
||||
* Add playground pretzel maps.
|
||||
|
||||
## 1.14.2
|
||||
|
||||
* Fix `commonInterop` default export handling.
|
||||
* Fix keyworded property key identifiers being turned into computed property key literals.
|
||||
|
||||
## 1.14.1
|
||||
|
||||
* Inherit comments from `ClassDeclaration`.
|
||||
|
||||
## 1.14.0
|
||||
|
||||
* Add [playground](https://6to5.github.io/playground.html).
|
||||
|
||||
## 1.13.13
|
||||
|
||||
* Fix `--debug` in `bin/6to5-node`. Thanks [@timoxley](https://github.com/timoxley).
|
||||
|
||||
## 1.13.12
|
||||
|
||||
* Ignore `XJSEmptyExpression`s in `react` transformer output.
|
||||
|
||||
## 1.13.11
|
||||
|
||||
* Fix `util.regexify` on falsy values.
|
||||
* Fix `_aliasFunction` with rest parameters.
|
||||
* Export as `module.exports` instead of `exports.default` if there are no other `ExportDeclaration`s in `commonInterop` module formatter.
|
||||
* Add `system` module formatter. Thanks [@douglasduteil](https://github.com/douglasduteil).
|
||||
|
||||
## 1.13.10
|
||||
|
||||
* Add support for `AssignmentExpression` destructuring outside of `ExpressionStatement`.
|
||||
|
||||
## 1.13.9
|
||||
|
||||
* Fix `VirtualPropertyExpression` visitor keys.
|
||||
|
||||
## 1.13.8
|
||||
|
||||
* Only use a single reference in abstract references.
|
||||
|
||||
## 1.13.7
|
||||
|
||||
* Upgrade `acorn-6to5`.
|
||||
* Add experimental exponentiation operator support.
|
||||
|
||||
## 1.13.6
|
||||
|
||||
* Fix experimental object spread/rest helper.
|
||||
|
||||
## 1.13.5
|
||||
|
||||
* Upgrade `acorn-6to5`.
|
||||
* Add experimental support for object spread/rest.
|
||||
* Change `arguments` to array to an additional helper method.
|
||||
|
||||
## 1.13.4
|
||||
|
||||
* Fix single spread element returning itself.
|
||||
|
||||
## 1.13.3
|
||||
|
||||
* Upgrade `acorn-6to5`.
|
||||
* Add experimental support for abstract references.
|
||||
|
||||
## 1.13.2
|
||||
|
||||
* Optimise `Array.from` usage by adding a helper method.
|
||||
* Upgrade `acorn-6to5`.
|
||||
|
||||
## 1.13.1
|
||||
|
||||
* Fix constructor spread optimisation. Thanks [@zloirock](https://github.com/zloirock).
|
||||
|
||||
## 1.13.0
|
||||
|
||||
* Put experimental ES7 features behind a flag `--experimental` and `experimental` option.
|
||||
* Constructor spread performance increase. Thanks [@RReverser](https://github.com/RReverser).
|
||||
* Use `self` instead of `window` in the optional 6to5 runtime. Thanks [@RReverser](https://github.com/RReverser).
|
||||
|
||||
## 1.12.26
|
||||
|
||||
* Support computed property destructuring.
|
||||
|
||||
## 1.12.25
|
||||
|
||||
* Update `acorn-6to5`, `ast-types`, `es6-shim`, `chokidar`, `estraverse` and `private`.
|
||||
|
||||
## 1.12.24
|
||||
|
||||
* Collect references that haven't been declared in scope.
|
||||
|
||||
## 1.12.23
|
||||
|
||||
* Fix generator function export hoisting.
|
||||
|
||||
## 1.12.22
|
||||
|
||||
* Update `fs-readdir-recursive` and `chokidar`.
|
||||
* Support array destructuring on iterables.
|
||||
* Make amd module id optional. Thanks [@webpro](https://github.com/webpro).
|
||||
|
||||
## 1.12.21
|
||||
|
||||
* Fix unneccesary let scoping replacement.
|
||||
* Add `commonInterop` module formatter. Thanks [@Naddiseo](https://github.com/Naddiseo).
|
||||
* Fix `return` outside of function body bug. Thanks [@brentburg](https://github.com/brentburg).
|
||||
* Add more flexible option types.
|
||||
|
||||
## 1.12.20
|
||||
|
||||
* Append `sourceMappingURL` when using `bin/6to5` and output sourcemaps.
|
||||
|
||||
## 1.12.19
|
||||
|
||||
* Add `comments` option and `--remove-comments` flag. Thanks [@webpro](htps://github.com/webpro).
|
||||
* Embed `regenerator`.
|
||||
|
||||
## 1.12.18
|
||||
|
||||
* Use `global` reference instead of `window`.
|
||||
|
||||
## 1.12.17
|
||||
|
||||
* Add `moduleName`, `sourceRoot` and `filenameRelative` options. Thanks [@darvelo](https://github.com/darvelo).
|
||||
* Traversal optimisations.
|
||||
|
||||
## 1.12.16
|
||||
|
||||
* Fix comments not being retained from `MethodDefinition` in classes.
|
||||
* Add temporal dead zone in default parameters.
|
||||
|
||||
## 1.12.15
|
||||
|
||||
* Update `acorn-6to5`.
|
||||
|
||||
## 1.12.14
|
||||
|
||||
* Fix duplicate let scoping in functions.
|
||||
* Make JSX whitespace more React-compliant.
|
||||
* Add `_memberExpressionKeywords` transformer that turns keyword identifiers to computed literals.
|
||||
* Upgrade `regenerator-6to5`.
|
||||
|
||||
## 1.12.13
|
||||
|
||||
* Support duplicate constants within different block scopes.
|
||||
* Fix for-head duplication testing and replacement.
|
||||
* Support `raw` property on tagged template literals.
|
||||
|
||||
## 1.12.12
|
||||
|
||||
* Make scope tracker more reliable to handle all edgecases.
|
||||
|
||||
## 1.12.11
|
||||
|
||||
* Block scope classes.
|
||||
* Fix generation of integer `Literal`s in `MemberExpression`.
|
||||
|
||||
## 1.12.10
|
||||
|
||||
* Fix let scoping var hoisting.
|
||||
|
||||
## 1.12.9
|
||||
|
||||
* Escape unicode characters when generating string `Literal`s.
|
||||
* Fix semicolons being output for statements in `ExportDeclaration`.
|
||||
* Fix `WithStatement` missing parenthesis.
|
||||
|
||||
## 1.12.8
|
||||
|
||||
* Temporarily forbid `AssignmentExpression` destructuring outside of `ExpressionStatement`.
|
||||
|
||||
## 1.12.7
|
||||
|
||||
* Update to latest `acorn-6to5`.
|
||||
|
||||
## 1.12.6
|
||||
|
||||
* Update to latest `acorn-6to5`.
|
||||
|
||||
## 1.12.5
|
||||
|
||||
* Fix excessive whitespace trimming resulting in innaccurate sourcemap line.
|
||||
|
||||
## 1.12.4
|
||||
|
||||
* Add `doc` folder for documentation.
|
||||
|
||||
## 1.12.3
|
||||
|
||||
* Support generator comprehensions.
|
||||
* Use `Array.from` instead of `Array.prototype.slice` in spread transformer.
|
||||
* Support spread in `NewExpression`s.
|
||||
|
||||
## 1.12.2
|
||||
|
||||
* Upgrade `matcha` to `0.6.0` and `browserify` to `6.3.2`.
|
||||
* Add own `trimRight` helper instead of relying on the string instance method.
|
||||
* Support JSX spreads that aren't the first.
|
||||
|
||||
## 1.12.1
|
||||
|
||||
* Fix `this` and `arguments` mapping in the `_aliasFunctions` transformer.
|
||||
|
||||
## 1.12.0
|
||||
|
||||
* Combine `jsx` and `react` transformers to `react`.
|
||||
* Update `react` syntax output to React v0.12.
|
||||
|
||||
## 1.11.15
|
||||
|
||||
* Fix JSX literal whitespace generation.
|
||||
|
||||
## 1.11.14
|
||||
|
||||
* Avoid using a switch for let-scoping continue and break statements and use an if statement instead.
|
||||
* Remove excess whitespace and newlines from JSX literals.
|
||||
|
||||
## 1.11.13
|
||||
|
||||
* Update regenerator-6to5
|
||||
* Add support for most escodegen formatting options
|
||||
30
CONTRIBUTING.md
Normal file
30
CONTRIBUTING.md
Normal file
@@ -0,0 +1,30 @@
|
||||
# Contributing
|
||||
|
||||
* **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
|
||||
162
FEATURES.md
162
FEATURES.md
@@ -1,162 +0,0 @@
|
||||
# Features
|
||||
|
||||
## Array comprehension
|
||||
|
||||
```javascript
|
||||
[for (i of [1, 2, 3]) i * i]; // [1, 4, 9]
|
||||
```
|
||||
|
||||
## Arrow functions
|
||||
|
||||
```javascript
|
||||
arr.map(x => x * x);
|
||||
```
|
||||
|
||||
## Let scoping
|
||||
|
||||
```javascript
|
||||
for (let i in arr) {
|
||||
let v = arr[i];
|
||||
}
|
||||
```
|
||||
|
||||
## Classes
|
||||
|
||||
```javascript
|
||||
class Foo extends Bar {
|
||||
constructor() { }
|
||||
|
||||
foo() { }
|
||||
|
||||
get bar() { }
|
||||
|
||||
set bar() { }
|
||||
}
|
||||
```
|
||||
|
||||
## Computed property names
|
||||
|
||||
```javascript
|
||||
var foo = "foo";
|
||||
var bar = "bar";
|
||||
var obj = {
|
||||
["foo" + bar]: "heh",
|
||||
["bar" + foo]: "noo",
|
||||
foo: "foo",
|
||||
bar: "bar"
|
||||
};
|
||||
```
|
||||
|
||||
## Constants
|
||||
|
||||
```javascript
|
||||
const MULTIPLIER = 5;
|
||||
console.log(2 * MULTIPLIER);
|
||||
|
||||
MULTIPLIER = 6; // error
|
||||
var MULTIPLIER; // error
|
||||
```
|
||||
|
||||
## Default parameters
|
||||
|
||||
```javascript
|
||||
function foo(bar = "foo") {
|
||||
return bar + "bar";
|
||||
}
|
||||
```
|
||||
|
||||
## Destructuring
|
||||
|
||||
```javascript
|
||||
var [a, [b], c, d] = ["hello", [", ", "junk"], ["world"]];
|
||||
console.log(a + b + c); // hello, world
|
||||
```
|
||||
|
||||
## For-of
|
||||
|
||||
```javascript
|
||||
for (var i of [1, 2, 3]) {
|
||||
console.log(i * i);
|
||||
}
|
||||
```
|
||||
|
||||
## Generators
|
||||
|
||||
```javascript
|
||||
```
|
||||
|
||||
## Modules
|
||||
|
||||
```javascript
|
||||
```
|
||||
|
||||
## Numeric literals
|
||||
|
||||
```javascript
|
||||
0b111110111 === 503; // true
|
||||
0o767 === 503; // true
|
||||
```
|
||||
|
||||
## Property method assignment
|
||||
|
||||
```javascript
|
||||
var obj = {
|
||||
foo() {
|
||||
return "foobar";
|
||||
},
|
||||
|
||||
get bar() {
|
||||
return this._bar;
|
||||
},
|
||||
|
||||
set bar(val) {
|
||||
this._bar = val;
|
||||
}
|
||||
};
|
||||
```
|
||||
|
||||
## Property name shorthand
|
||||
|
||||
```javascript
|
||||
function f(x, y) {
|
||||
return { x, y };
|
||||
}
|
||||
```
|
||||
|
||||
## Rest parameters
|
||||
|
||||
```javascript
|
||||
function printList(name, ...items) {
|
||||
console.log("list %s has the following items", name);
|
||||
items.forEach(function (item) {
|
||||
console.log(item);
|
||||
});
|
||||
}
|
||||
```
|
||||
|
||||
## Spread
|
||||
|
||||
```javascript
|
||||
function add(x, y) {
|
||||
return x + y;
|
||||
}
|
||||
|
||||
var numbers = [5, 10];
|
||||
add(...numbers); // 15
|
||||
```
|
||||
|
||||
## Template literals
|
||||
|
||||
```javascript
|
||||
var x = 5;
|
||||
var y = 10;
|
||||
console.log(`${x} + ${y} = ${x + y}`); // "5 + 10 = 15"
|
||||
```
|
||||
|
||||
## Unicode regex
|
||||
|
||||
```javascript
|
||||
var string = 'foo💩bar';
|
||||
var match = string.match(/foo(.)bar/u);
|
||||
console.log(match[1]);
|
||||
```
|
||||
2
LICENSE
2
LICENSE
@@ -1,4 +1,4 @@
|
||||
Copyright (c) 2014 Sebastian McKenzie
|
||||
Copyright (c) 2014-2015 Sebastian McKenzie
|
||||
|
||||
MIT License
|
||||
|
||||
|
||||
45
Makefile
45
Makefile
@@ -1,32 +1,48 @@
|
||||
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
|
||||
JSHINT_CMD = node_modules/jshint/bin/jshint
|
||||
MOCHA_CMD = node_modules/mocha/bin/_mocha
|
||||
|
||||
export NODE_ENV = test
|
||||
|
||||
.PHONY: clean test test-cov test-travis test-browser publish bench build
|
||||
.PHONY: clean test test-cov test-clean lint test-travis test-spec test-browser publish bench build
|
||||
|
||||
clean:
|
||||
rm -rf coverage templates.json test/tmp dist
|
||||
|
||||
bench:
|
||||
npm install es6-transpiler traceur esnext es6now jstransform
|
||||
node node_modules/matcha/bin/_matcha
|
||||
|
||||
test:
|
||||
$(JSHINT_CMD) lib
|
||||
lint:
|
||||
$(JSHINT_CMD) --reporter node_modules/jshint-stylish/stylish.js lib bin benchmark/index.js
|
||||
|
||||
test-clean:
|
||||
rm -rf test/tmp
|
||||
|
||||
test: lint
|
||||
$(MOCHA_CMD)
|
||||
make test-clean
|
||||
|
||||
test-cov:
|
||||
rm -rf coverage
|
||||
node $(ISTANBUL_CMD) $(MOCHA_CMD) --
|
||||
|
||||
test-travis:
|
||||
test-spec:
|
||||
node $(ISTANBUL_CMD) $(MOCHA_CMD) -- --reporter spec
|
||||
|
||||
test-travis: test-spec
|
||||
if test -n "$$CODECLIMATE_REPO_TOKEN"; then codeclimate < coverage/lcov.info; fi
|
||||
|
||||
test-browser:
|
||||
make build
|
||||
node bin/generate-browser-test >dist/6to5-test.js
|
||||
mkdir -p dist
|
||||
|
||||
node bin/cache-templates
|
||||
node bin/cache-tests
|
||||
node $(BROWSERIFY_CMD) -e test/_browser.js >dist/6to5-test.js
|
||||
rm -rf templates.json tests.json
|
||||
|
||||
test -n "`which open`" && open test/browser.html
|
||||
|
||||
build:
|
||||
@@ -34,8 +50,14 @@ build:
|
||||
|
||||
node bin/cache-templates
|
||||
|
||||
browserify lib/6to5/transform.js -s to5 >dist/6to5.js
|
||||
uglifyjs dist/6to5.js >dist/6to5.min.js
|
||||
node $(BROWSERIFY_CMD) -e lib/6to5/polyfill.js >dist/polyfill.js
|
||||
node $(UGLIFY_CMD) dist/polyfill.js >dist/polyfill.min.js
|
||||
|
||||
node $(BROWSERIFY_CMD) lib/6to5/browser.js -s to5 >dist/6to5.js
|
||||
node $(UGLIFY_CMD) dist/6to5.js >dist/6to5.min.js
|
||||
|
||||
node bin/6to5-runtime >dist/runtime.js
|
||||
node $(UGLIFY_CMD) dist/runtime.js >dist/runtime.min.js
|
||||
|
||||
rm -rf templates.json
|
||||
|
||||
@@ -44,6 +66,11 @@ publish:
|
||||
|
||||
make test
|
||||
|
||||
make build
|
||||
cp dist/6to5.min.js browser.js
|
||||
cp dist/polyfill.min.js browser-polyfill.js
|
||||
cp dist/runtime.min.js runtime.js
|
||||
|
||||
node bin/cache-templates
|
||||
test -f templates.json
|
||||
|
||||
@@ -53,4 +80,4 @@ publish:
|
||||
|
||||
git push --follow-tags
|
||||
|
||||
rm -rf templates.json
|
||||
rm -rf templates.json browser.js runtime.js browser-polyfill.js
|
||||
|
||||
394
README.md
394
README.md
@@ -1,386 +1,34 @@
|
||||
<p align="center">
|
||||
<img alt="6to5" src="http://i.imgur.com/hVl9KRw.png">
|
||||
<img alt="6to5" src="https://raw.githubusercontent.com/6to5/logo/master/logo.png" width="546">
|
||||
</p>
|
||||
|
||||
<p align="center">
|
||||
<a href="https://travis-ci.org/sebmck/6to5">
|
||||
<img alt="Travis Status" src="http://img.shields.io/travis/sebmck/6to5.svg?style=flat&label=travis">
|
||||
<a href="https://gratipay.com/sebmck">
|
||||
<img alt="Gratipay" src="https://img.shields.io/gratipay/sebmck.svg?style=flat">
|
||||
</a>
|
||||
|
||||
<a href="https://codeclimate.com/github/sebmck/6to5">
|
||||
<img alt="Code Climate Score" src="http://img.shields.io/codeclimate/github/sebmck/6to5.svg?style=flat">
|
||||
<a href="https://travis-ci.org/6to5/6to5">
|
||||
<img alt="Travis Status" src="http://img.shields.io/travis/6to5/6to5/master.svg?style=flat&label=travis">
|
||||
</a>
|
||||
|
||||
<a href="https://codeclimate.com/github/sebmck/6to5">
|
||||
<img alt="Coverage" src="http://img.shields.io/codeclimate/coverage/github/sebmck/6to5.svg?style=flat">
|
||||
<a href="https://codeclimate.com/github/6to5/6to5">
|
||||
<img alt="Code Climate Score" src="http://img.shields.io/codeclimate/github/6to5/6to5.svg?style=flat">
|
||||
</a>
|
||||
|
||||
<a href="https://david-dm.org/sebmck/6to5">
|
||||
<img alt="Dependency Status" src="http://img.shields.io/david/sebmck/6to5.svg?style=flat">
|
||||
<a href="https://codeclimate.com/github/6to5/6to5">
|
||||
<img alt="Coverage" src="http://img.shields.io/codeclimate/coverage/github/6to5/6to5.svg?style=flat">
|
||||
</a>
|
||||
|
||||
<a href="https://david-dm.org/6to5/6to5">
|
||||
<img alt="Dependency Status" src="http://img.shields.io/david/6to5/6to5.svg?style=flat">
|
||||
</a>
|
||||
</p>
|
||||
|
||||
**6to5** turns ES6 code into vanilla ES5, so you can use ES6 features **today.**
|
||||
|
||||
- **Readable** - formatting is retained if possible so your generated code is as similar as possible.
|
||||
- **Extensible** - with a large range of [plugins](#plugins) and **browser support**.
|
||||
- **Lossless** - **source map support** so you can debug your compiled code with ease.
|
||||
- **Compact** - maps directly to the equivalent ES5 with **no runtime**[\*](#generators).
|
||||
|
||||
## Installation
|
||||
|
||||
It's as easy as:
|
||||
|
||||
$ npm install -g 6to5
|
||||
|
||||
## Table of Contents
|
||||
|
||||
- [Features](#features)
|
||||
- [Usage](#usage)
|
||||
- [Plugins](#plugins)
|
||||
- [CLI](#cli)
|
||||
- [Node](#node-1)
|
||||
- [Browser](#browser)
|
||||
- [Modules](#modules)
|
||||
- [Caveats](#caveats)
|
||||
- [Differences](#differences)
|
||||
|
||||
## [Features](FEATURES.md)
|
||||
|
||||
- [Array comprehension](FEATURES.md#array-comprehension)
|
||||
- [Arrow functions](FEATURES.md#arrow-functions)
|
||||
- [Classes](FEATURES.md#classes)
|
||||
- [Computed property names](FEATURES.md#computed-property-names)
|
||||
- [Constants](FEATURES.md#constants)
|
||||
- [Default parameters](FEATURES.md#default-parameters)
|
||||
- [Destructuring](FEATURES.md#destructuring)
|
||||
- [For-of](FEATURES.md#for-of)
|
||||
- [Generators](FEATURES.md#generators) via [regenerator](https://github.com/facebook/regenerator)
|
||||
- [Let scoping](FEATURES.md#let-scoping)
|
||||
- [Modules](FEATURES.md#modules)
|
||||
- [Numeric literals](FEATURES.md#numeric-literals)
|
||||
- [Property method assignment](FEATURES.md#property-method-assignment)
|
||||
- [Property name shorthand](FEATURES.md#property-name-shorthand)
|
||||
- [Rest parameters](FEATURES.md#rest-parameters)
|
||||
- [Spread](FEATURES.md#spread)
|
||||
- [Template literals](FEATURES.md#template-literals)
|
||||
- [Unicode regex](FEATURES.md#unicode-regex)
|
||||
|
||||
## Usage
|
||||
|
||||
### Plugins
|
||||
|
||||
- [Broccoli](https://github.com/very-geek/broccoli-6to5-transpiler)
|
||||
- [Browserify](https://github.com/sebmck/6to5-browserify)
|
||||
- [Brunch](https://github.com/es128/6to5-brunch)
|
||||
- [Connect](https://github.com/sebmck/6to5-connect)
|
||||
- [Gulp](https://github.com/sindresorhus/gulp-6to5)
|
||||
- [Grunt](https://github.com/sindresorhus/grunt-6to5)
|
||||
- [Jade](https://github.com/Apoxx/jade-6to5)
|
||||
- [webpack](https://github.com/Couto/6to5-loader)
|
||||
|
||||
### CLI
|
||||
|
||||
Compile the file `script.js` and output it to stdout.
|
||||
|
||||
$ 6to5 script.js
|
||||
|
||||
Compile the file `script.js` and output it to `script-compiled.js`.
|
||||
|
||||
$ 6to5 script.js --out-file script-compiled.js
|
||||
|
||||
Compile the file `script.js` and output it to `script-compiled.js` and save a
|
||||
source map to `script-compiled.js.map`.
|
||||
|
||||
$ 6to5 script.js --source-maps --out-file script-compiled.js
|
||||
|
||||
Compile the file `script.js` and output it to `script-compiled.js` with a source
|
||||
map embedded in a comment at the bottom.
|
||||
|
||||
$ 6to5 script.js --source-maps-inline --out-file script-compiled.js
|
||||
|
||||
Compile the entire `src` directory and output it to the `lib` directory.
|
||||
|
||||
$ 6to5 src --out-dir lib
|
||||
|
||||
Pipe a file in via stdin and output it to `script-compiled.js`
|
||||
|
||||
$ 6to5 --out-file script-compiled.js < script.js
|
||||
|
||||
#### Node
|
||||
|
||||
Launch a repl.
|
||||
|
||||
$ 6to5-node
|
||||
|
||||
Evaluate code.
|
||||
|
||||
$ 6to5-node -e "class Test { }"
|
||||
|
||||
Compile and run `test.js`.
|
||||
|
||||
$ 6to5-node test
|
||||
|
||||
### Node
|
||||
|
||||
```javascript
|
||||
var to5 = require("6to5");
|
||||
|
||||
var result = to5.transform("code();", options);
|
||||
result.code;
|
||||
result.map;
|
||||
result.ast;
|
||||
|
||||
to5.transformFileSync("filename.js", options).code;
|
||||
|
||||
to5.transformFile("filename.js", options, function (err, result) {
|
||||
|
||||
});
|
||||
```
|
||||
|
||||
##### Options
|
||||
|
||||
```javascript
|
||||
{
|
||||
// Filename for use in errors etc.
|
||||
// Default: "unknown"
|
||||
filename: "filename",
|
||||
|
||||
// List of transformers to EXCLUDE.
|
||||
// Run `6to5 --help` to see a full list of transformers.
|
||||
blacklist: [],
|
||||
|
||||
// List of transformers to ONLY use.
|
||||
// Run `6to5 --help` to see a full list of transformers.
|
||||
whitelist: [],
|
||||
|
||||
// If truthy, adds a `map` property to returned output.
|
||||
// If set to "inline", a comment with a sourceMappingURL directive is added to
|
||||
// the bottom of the returned code.
|
||||
// Default: false
|
||||
sourceMap: true,
|
||||
|
||||
// Set `file` on returned source map.
|
||||
// Default: `filename` option.
|
||||
sourceMapName: "filename",
|
||||
|
||||
// Set `sources[0]` on returned source map.
|
||||
// Default: `filename` option.
|
||||
sourceFileName: "filename"
|
||||
}
|
||||
```
|
||||
|
||||
#### Require hook
|
||||
|
||||
All subsequent files required by node will be transformed by 6to5. The polyfill
|
||||
specified in [Polyfill](#polyfill) is also required.
|
||||
|
||||
```javascript
|
||||
require("6to5/register");
|
||||
```
|
||||
|
||||
**NOTE:** By default all requires to `node_modules` will be ignored. You can
|
||||
override this by passing an ignore regex via:
|
||||
|
||||
```javascript
|
||||
require("6to5/register")(/regex/)
|
||||
```
|
||||
|
||||
### Browser
|
||||
|
||||
You can build a browser version of the compiler by running the following in the
|
||||
6to5 directory:
|
||||
|
||||
$ make build
|
||||
|
||||
This will output the files `dist/6to5.js` and `dist/6to5.min.js`.
|
||||
|
||||
Just include one of those in the browser and access the transform method via the
|
||||
global `to5`.
|
||||
|
||||
```javascript
|
||||
to5("class Test {}").code;
|
||||
```
|
||||
|
||||
#### Test
|
||||
|
||||
To test 6to5 in your browser run:
|
||||
|
||||
$ make test-browser
|
||||
|
||||
And open `test/browser.html` in your browser if it doesn't open automatically.
|
||||
|
||||
## Modules
|
||||
|
||||
6to5 modules compile straight to CommonJS, because of this various liberties are
|
||||
taken into account to make their usage easier.
|
||||
|
||||
```javascript
|
||||
import "foo"; // require("foo");
|
||||
|
||||
import foo from "foo"; // var foo = require("foo").default;
|
||||
import * as foo from "foo"; // var foo = require("foo");
|
||||
|
||||
import {bar} from "foo"; // var bar = require("foo").bar;
|
||||
import {foo as bar} from "foo"; // var bar = require("foo").foo;
|
||||
|
||||
export {test}; // exports.test = test;
|
||||
export var test = 5; // var test = 5; exports.test = test;
|
||||
|
||||
export default test; // exports.default = test;
|
||||
```
|
||||
|
||||
If you'd like to disable this behaviour and use the more ES6-like
|
||||
[es6-module-transpiler](https://github.com/esnext/es6-module-transpiler) you can
|
||||
use the following:
|
||||
|
||||
$ 6to5 script.js -o script-compiled.js --blacklist modules
|
||||
$ compile-modules convert script-compiled.js -o script-compiled.js
|
||||
|
||||
## Caveats
|
||||
|
||||
### Polyfill
|
||||
|
||||
6to5 does not include a runtime nor polyfill and it's up to the developer to
|
||||
include one in compiled browser code.
|
||||
|
||||
#### Node
|
||||
|
||||
A polyfill is included with the 6to5 module that can be included in node like
|
||||
so:
|
||||
|
||||
```javascript
|
||||
require("6to5/polyfill");
|
||||
```
|
||||
|
||||
This is simply a wrapper around the
|
||||
[regenerator runtime](https://github.com/facebook/regenerator/blob/master/runtime.js) and the
|
||||
[es6-shim](https://github.com/paulmillr/es6-shim) and
|
||||
[es6-symbol](https://github.com/medikoo/es6-symbol) polyfills.
|
||||
|
||||
#### Browser
|
||||
|
||||
If you're planning on using 6to5 output in the browser then it's up to you
|
||||
to include polyfills. [es6-symbol](https://github.com/medikoo/es6-symbol#browser)
|
||||
and [es6-shim](https://raw.githubusercontent.com/paulmillr/es6-shim/master/es6-shim.js)
|
||||
fill the vast majority of polyfill concerns.
|
||||
|
||||
### For-of
|
||||
|
||||
A polyfill is required for for-of functionality that implements `Symbol` and
|
||||
adds `prototype[Symbol.iterator]` behaviour to built-ins. Using the polyfills
|
||||
specified in [polyfill](#polyfill) suffices.
|
||||
|
||||
### Classes
|
||||
|
||||
Built-in classes such as `Date`, `Array` and `DOM` cannot be subclassed due to
|
||||
limitations in ES5 implementations.
|
||||
|
||||
If you're inheriting from a class then static properties are inherited from it
|
||||
via [\_\_proto\_\_](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/proto),
|
||||
this is widely supported but you may run into problems with much older browsers.
|
||||
|
||||
### Generators
|
||||
|
||||
The [regenerator runtime](https://github.com/facebook/regenerator/blob/master/runtime.js)
|
||||
and an [ES6 polyfill](#polyfill) are required in order for generators to work.
|
||||
|
||||
## Differences
|
||||
|
||||
### Philosophy
|
||||
|
||||
The fundamental concept behind 6to5 is that the generated code must be close as
|
||||
possible to the original, retaining all the same formatting and readability.
|
||||
|
||||
Many other transpilers are just concerned with making the code work while 6to5
|
||||
is concerned with making sure it works **and** is readable at the same time.
|
||||
|
||||
For example, given the following array comprehension:
|
||||
|
||||
```javascript
|
||||
var seattlers = [for (c of customers) if (c.city == "Seattle") { name: c.name, age: c.age }];
|
||||
```
|
||||
|
||||
is generated to the following with 6to5:
|
||||
|
||||
```javascript
|
||||
var seattlers = customers.filter(function (c) {
|
||||
return c.city == "Seattle";
|
||||
}).map(function (c) {
|
||||
return {
|
||||
name: c.name,
|
||||
age: c.age
|
||||
};
|
||||
});
|
||||
```
|
||||
|
||||
The following is what Traceur generates:
|
||||
|
||||
```javascript
|
||||
var seattlers = (function() {
|
||||
var c;
|
||||
var $__20 = 0,
|
||||
$__21 = [];
|
||||
for (var $__22 = customers[$traceurRuntime.toProperty(Symbol.iterator)](),
|
||||
$__23; !($__23 = $__22.next()).done; ) {
|
||||
c = $__23.value;
|
||||
if (c.city == "Seattle")
|
||||
$traceurRuntime.setProperty($__21, $__20++, {
|
||||
name: c.name,
|
||||
age: c.age
|
||||
});
|
||||
}
|
||||
return $__21;
|
||||
}());
|
||||
```
|
||||
|
||||
As you can tell, it's not very pretty, unreadable even. Instead of mapping
|
||||
directly to a runtime, like other transpilers, 6to5 maps directly to the
|
||||
equivalent ES5.
|
||||
|
||||
I'm not saying 6to5 is for everyone or even suited for everything. Traceur is
|
||||
better suited if you'd like a full ES6 environment with polyfills and all.
|
||||
|
||||
### Comparison to other transpilers
|
||||
|
||||
| | 6to5 | Traceur | esnext | es6now | es6-transpiler | jstransform |
|
||||
| ---------------------------- | ---- | ------- | ------ | ------ | -------------- | ----------- |
|
||||
| No runtime | ✓ | | | | ✓ | ✓ |
|
||||
| Source maps | ✓ | ✓ | ✓ | | ✓ | ✓ |
|
||||
| No compiler global pollution | ✓ | | ✓ | | ✓ | ✓ |
|
||||
| Arrow functions | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
|
||||
| Classes | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
|
||||
| Computed property names | ✓ | ✓ | ✓ | ✓ | ✓ | |
|
||||
| Constants | ✓ | ✓ | | | ✓ | |
|
||||
| Default parameters | ✓ | ✓ | ✓ | ✓ | ✓ | |
|
||||
| Destructuring | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
|
||||
| For-of | ✓ | ✓ | ✓ | ✓ | ✓ | |
|
||||
| Generators | ✓ | ✓ | ✓ | | | |
|
||||
| Let scoping | ✓ | ✓ | | | ✓ | |
|
||||
| Modules | ✓ | ✓ | | ✓ | | |
|
||||
| Property method assignment | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
|
||||
| Property name shorthand | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
|
||||
| Rest parameters | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
|
||||
| Spread | ✓ | ✓ | ✓ | ✓ | ✓ | |
|
||||
| Template literals | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
|
||||
| Unicode regex | ✓ | ✓ | | | ✓ | |
|
||||
|
||||
#### [Traceur](https://github.com/google/traceur-compiler)
|
||||
|
||||
Traceur requires quite a bulky runtime (~75KB) and produces quite verbose code.
|
||||
While this can be trimmed down by selectively building the runtime, it's an
|
||||
unneccesary step when a runtime can be eliminated entirely.
|
||||
|
||||
#### [es6now](https://github.com/zenparsing/es6now)
|
||||
|
||||
es6now doesn't output sourcemaps. This is cited as a positive as line-to-line
|
||||
mapping is the goal. This however obviously doesn't retain column mapping
|
||||
resulting in the output code not being very pleasant.
|
||||
|
||||
#### [es6-transpiler](https://github.com/termi/es6-transpiler)
|
||||
|
||||
The es6-transpiler compiler requires shims to operate which pollutes the global
|
||||
scope resulting in possible collisions.
|
||||
|
||||
es6-transpiler maps line-by-line, just like es6now, this results in the same
|
||||
issues such as lack of column information and unpleasant code output.
|
||||
<p align="center">
|
||||
<strong>6to5</strong> turns ES6+ code into vanilla ES5, so you can use next generation features <strong>today.</strong>
|
||||
</p>
|
||||
|
||||
<p align="center">
|
||||
For more information view the <a href="https://6to5.github.io">documentation</a>. For
|
||||
support visit the <a href="https://gitter.im/6to5/6to5">gitter room</a>.
|
||||
</p>
|
||||
|
||||
17
appveyor.yml
Normal file
17
appveyor.yml
Normal file
@@ -0,0 +1,17 @@
|
||||
environment:
|
||||
matrix:
|
||||
- nodejs_version: "0.10"
|
||||
- nodejs_version: "0.11"
|
||||
|
||||
install:
|
||||
- "npm install"
|
||||
- "cinst make"
|
||||
|
||||
test_script:
|
||||
- "node --version"
|
||||
- "npm --version"
|
||||
- "make test-spec"
|
||||
|
||||
build: "off"
|
||||
|
||||
version: "{build}"
|
||||
@@ -2,22 +2,24 @@ Error.stackTraceLimit = Infinity;
|
||||
|
||||
var jsTrans = require("jstransform");
|
||||
var traceur = require("traceur");
|
||||
var es6tr = require("es6-transpiler");
|
||||
//var es6tr = require("es6-transpiler");
|
||||
var es6now = require("es6now");
|
||||
var esnext = require("esnext");
|
||||
//var esnext = require("esnext");
|
||||
var to5 = require("../lib/6to5");
|
||||
|
||||
var uglify = require("uglify-js");
|
||||
//var uglify = require("uglify-js");
|
||||
var matcha = require("matcha");
|
||||
var stream = require("stream");
|
||||
var path = require("path");
|
||||
var zlib = require("zlib");
|
||||
var fs = require("fs");
|
||||
var vm = require("vm");
|
||||
var _ = require("lodash");
|
||||
|
||||
var readResolve = function (filename) {
|
||||
return fs.readFileSync(require.resolve(filename), "utf8");
|
||||
try {
|
||||
filename = require.resolve(filename);
|
||||
} catch (err) {
|
||||
return null;
|
||||
}
|
||||
return fs.readFileSync(filename, "utf8");
|
||||
};
|
||||
|
||||
var getVersion = function (name) {
|
||||
@@ -38,6 +40,7 @@ _.each([
|
||||
|
||||
var compilers = {
|
||||
"6to5": {
|
||||
version: getVersion(".."),
|
||||
compile: function (code, filename) {
|
||||
return to5.transform(code, { filename: filename }).code;
|
||||
}
|
||||
@@ -45,7 +48,7 @@ var compilers = {
|
||||
|
||||
traceur: {
|
||||
runtime: readResolve("traceur/bin/traceur-runtime.js"),
|
||||
compile: function (code, filename) {
|
||||
compile: function (code) {
|
||||
return traceur.compile(code, {
|
||||
modules: "commonjs",
|
||||
experimental: true
|
||||
@@ -53,30 +56,30 @@ var compilers = {
|
||||
}
|
||||
},
|
||||
|
||||
esnext: {
|
||||
runtime: readResolve("esnext/node_modules/regenerator/runtime.js"),
|
||||
compile: function (code, filename) {
|
||||
/*esnext: {
|
||||
runtime: readResolve("esnext/node_modules/regenerator/runtime.js") || readResolve("regenerator/runtime.js"),
|
||||
compile: function (code) {
|
||||
return esnext.compile(code).code;
|
||||
}
|
||||
},
|
||||
},*/
|
||||
|
||||
es6now: {
|
||||
runtime: readResolve("es6now/runtime/ES6.js"),
|
||||
compile: function (code, filename) {
|
||||
compile: function (code) {
|
||||
return es6now.translate(code);
|
||||
}
|
||||
},
|
||||
|
||||
"es6-transpiler": {
|
||||
compile: function (code, filename) {
|
||||
/*"es6-transpiler": {
|
||||
compile: function (code) {
|
||||
var result = es6tr.run({ src: code });
|
||||
if (result.errors.length) throw new Error(result.join("; "));
|
||||
return result.src;
|
||||
}
|
||||
},
|
||||
},*/
|
||||
|
||||
jstransform: {
|
||||
compile: function (code, filename) {
|
||||
compile: function (code) {
|
||||
return jsTrans.transform(jsTransVisitors, code).code;
|
||||
}
|
||||
}
|
||||
@@ -84,10 +87,10 @@ var compilers = {
|
||||
|
||||
// versions
|
||||
|
||||
var uglifyTitle = "uglify v" + getVersion("uglify-js");
|
||||
//var uglifyTitle = "uglify v" + getVersion("uglify-js");
|
||||
|
||||
_.each(compilers, function (compiler, name) {
|
||||
compiler.title = name + " v" + getVersion(name);
|
||||
compiler.title = name + " v" + (compiler.version || getVersion(name));
|
||||
});
|
||||
|
||||
//
|
||||
@@ -96,14 +99,13 @@ var sizeBenchmark = function (code, loc, name, compiler) {
|
||||
var log = function (output, title) {
|
||||
title = [compiler.title].concat(title || []).join(" + ");
|
||||
|
||||
var kilo = (output.length / 1024).toFixed(2);
|
||||
|
||||
var text;
|
||||
var color;
|
||||
if (output === false) {
|
||||
if (output.stack) {
|
||||
text = "error";
|
||||
color = "red";
|
||||
} else {
|
||||
var kilo = (output.length / 1024).toFixed(2);
|
||||
text = kilo + "KB";
|
||||
color = "cyan";
|
||||
}
|
||||
@@ -111,6 +113,10 @@ var sizeBenchmark = function (code, loc, name, compiler) {
|
||||
text = matcha.utils.color(matcha.utils.padBefore(text, 22), color);
|
||||
|
||||
console.log(text, matcha.utils.color("» " + title, "gray"));
|
||||
|
||||
if (output.stack) {
|
||||
console.error(output.stack);
|
||||
}
|
||||
};
|
||||
|
||||
var go = function (getOutput, title) {
|
||||
@@ -118,7 +124,7 @@ var sizeBenchmark = function (code, loc, name, compiler) {
|
||||
try {
|
||||
code = getOutput();
|
||||
} catch (err) {
|
||||
log(false, title);
|
||||
log(err, title);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -127,13 +133,13 @@ var sizeBenchmark = function (code, loc, name, compiler) {
|
||||
|
||||
var output;
|
||||
go(function () {
|
||||
return output = output || compiler.compile(code, loc);
|
||||
return output = compiler.compile(code, loc);
|
||||
});
|
||||
if (!output) return;
|
||||
|
||||
go(function () {
|
||||
return uglify.minify(output, { fromString: true }).code;
|
||||
}, uglifyTitle);
|
||||
//go(function () {
|
||||
// return uglify.minify(output, { fromString: true }).code;
|
||||
//}, uglifyTitle);
|
||||
};
|
||||
|
||||
//
|
||||
@@ -153,7 +159,7 @@ _.each(fs.readdirSync(__dirname + "/fixtures"), function (name) {
|
||||
});
|
||||
});
|
||||
|
||||
_.each(compilers, function (compiler, name) {
|
||||
_.each(compilers, function (compiler) {
|
||||
bench(compiler.title, function () {
|
||||
compiler.compile(code, loc);
|
||||
});
|
||||
|
||||
111
bin/6to5-node
111
bin/6to5-node
@@ -1,71 +1,68 @@
|
||||
#!/usr/bin/env node
|
||||
|
||||
var commander = require("commander");
|
||||
var Module = require("module");
|
||||
var path = require("path");
|
||||
var util = require("../lib/6to5/util");
|
||||
var path = require("path");
|
||||
var repl = require("repl");
|
||||
var to5 = require("../lib/6to5");
|
||||
var vm = require("vm");
|
||||
var _ = require("lodash");
|
||||
/**
|
||||
* This tiny wrapper file checks for known node flags and appends them
|
||||
* when found, before invoking the "real" _6to5-node(1) executable.
|
||||
*/
|
||||
|
||||
commander.option("-e, --eval [script]", "evaluate script");
|
||||
commander.option("-p, --print", "evaluate script and print result");
|
||||
var args = ["--harmony", __dirname + "/_6to5-node"];
|
||||
|
||||
var pkg = require("../package.json");
|
||||
commander.version(pkg.version);
|
||||
commander.usage("[options] [ -e script | script.js ] [arguments]");
|
||||
commander.parse(process.argv);
|
||||
process.argv.slice(2).forEach(function(arg){
|
||||
var flag = arg.split("=")[0];
|
||||
|
||||
to5.register();
|
||||
switch (flag) {
|
||||
case "-d":
|
||||
args.unshift("--debug");
|
||||
break;
|
||||
|
||||
var _eval = function (code, filename) {
|
||||
code = to5.transform(code, { filename: filename }).code;
|
||||
return vm.runInThisContext(code, filename);
|
||||
};
|
||||
case "debug":
|
||||
case "--debug":
|
||||
case "--debug-brk":
|
||||
args.unshift(arg);
|
||||
break;
|
||||
|
||||
if (commander.eval) {
|
||||
var code = to5.transform(commander.eval, { filename: "eval" }).code;
|
||||
case "-gc":
|
||||
case "--expose-gc":
|
||||
args.unshift("--expose-gc");
|
||||
break;
|
||||
|
||||
var result = _eval(code, "eval");
|
||||
if (commander.print) console.log(result);
|
||||
} else {
|
||||
var filenames = commander.args;
|
||||
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":
|
||||
args.unshift(arg);
|
||||
break;
|
||||
|
||||
if (filenames.length) {
|
||||
_.each(filenames, function (filename) {
|
||||
if (!util.isAbsolute(filename)) {
|
||||
filename = path.join(process.cwd(), filename);
|
||||
default:
|
||||
if (arg.indexOf("--trace") === 0) {
|
||||
args.unshift(arg);
|
||||
} else {
|
||||
args.push(arg);
|
||||
}
|
||||
|
||||
require(require.resolve(filename));
|
||||
});
|
||||
} else {
|
||||
replStart();
|
||||
break;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
function replStart() {
|
||||
repl.start({
|
||||
prompt: "> ",
|
||||
input: process.stdin,
|
||||
output: process.stdout,
|
||||
eval: replEval,
|
||||
useGlobal: true
|
||||
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);
|
||||
}
|
||||
})
|
||||
});
|
||||
}
|
||||
|
||||
function replEval(code, context, filename, callback) {
|
||||
var err;
|
||||
var result;
|
||||
|
||||
try {
|
||||
code = code.slice(1, -2); // remove "(" and "\n)"
|
||||
result = _eval(code, filename);
|
||||
} catch (e) {
|
||||
err = e;
|
||||
}
|
||||
|
||||
callback(err, result);
|
||||
}
|
||||
|
||||
4
bin/6to5-runtime
Executable file
4
bin/6to5-runtime
Executable file
@@ -0,0 +1,4 @@
|
||||
#!/usr/bin/env node
|
||||
|
||||
var runtime = require("../lib/6to5/runtime-generator");
|
||||
console.log(runtime(process.argv[2]));
|
||||
@@ -13,13 +13,15 @@ module.exports = function (commander, filenames, opts) {
|
||||
var write = function (src, relative) {
|
||||
var dest = path.join(commander.outDir, relative);
|
||||
|
||||
var data = util.compile(src, dest);
|
||||
var data = util.compile(src, { sourceMapName: dest });
|
||||
|
||||
var up = path.normalize(dest + "/..");
|
||||
mkdirp.sync(up);
|
||||
|
||||
if (commander.sourceMaps) {
|
||||
fs.writeFileSync(dest + ".map", JSON.stringify(data.map));
|
||||
var mapLoc = dest + ".map";
|
||||
data.code = util.addSourceMappingUrl(data.code, mapLoc);
|
||||
fs.writeFileSync(mapLoc, JSON.stringify(data.map));
|
||||
}
|
||||
|
||||
fs.writeFileSync(dest, data.code);
|
||||
|
||||
@@ -6,7 +6,7 @@ var util = require("./util");
|
||||
var fs = require("fs");
|
||||
var _ = require("lodash");
|
||||
|
||||
module.exports = function (commander, filenames, opts) {
|
||||
module.exports = function (commander, filenames) {
|
||||
var results = [];
|
||||
|
||||
var buildResult = function () {
|
||||
@@ -48,7 +48,7 @@ module.exports = function (commander, filenames, opts) {
|
||||
return {
|
||||
map: map,
|
||||
code: code
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
var output = function () {
|
||||
@@ -56,7 +56,9 @@ module.exports = function (commander, filenames, opts) {
|
||||
|
||||
if (commander.outFile) {
|
||||
if (commander.sourceMaps) {
|
||||
fs.writeFileSync(commander.outFile + ".map", JSON.stringify(result.map));
|
||||
var mapLoc = commander.outFile + ".map";
|
||||
result.code = util.addSourceMappingUrl(result.code, mapLoc);
|
||||
fs.writeFileSync(mapLoc, JSON.stringify(result.map));
|
||||
}
|
||||
|
||||
fs.writeFileSync(commander.outFile, result.code);
|
||||
@@ -111,16 +113,14 @@ module.exports = function (commander, filenames, opts) {
|
||||
walk();
|
||||
|
||||
if (commander.watch) {
|
||||
var watcher = chokidar.watch(filenames, {
|
||||
chokidar.watch(filenames, {
|
||||
persistent: true,
|
||||
ignoreInitial: true
|
||||
});
|
||||
|
||||
_.each(["add", "change", "unlink"], function (type) {
|
||||
watcher.on(type, function (filename) {
|
||||
}).on("all", function (type, filename) {
|
||||
if (type === "add" || type === "change" || type === "unlink" ) {
|
||||
console.log(type, filename);
|
||||
walk();
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
@@ -1,11 +1,8 @@
|
||||
#!/usr/bin/env node
|
||||
|
||||
var commander = require("commander");
|
||||
var sourceMap = require("source-map");
|
||||
var transform = require("../../lib/6to5/transform");
|
||||
var chokidar = require("chokidar");
|
||||
var mkdirp = require("mkdirp");
|
||||
var path = require("path");
|
||||
var transform = require("../../lib/6to5/transformation/transform");
|
||||
var util = require("../../lib/6to5/util");
|
||||
var fs = require("fs");
|
||||
var _ = require("lodash");
|
||||
|
||||
@@ -13,24 +10,43 @@ commander.option("-t, --source-maps-inline", "Append sourceMappingURL comment to
|
||||
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");
|
||||
|
||||
var list = function (val) {
|
||||
return val ? val.split(",") : [];
|
||||
};
|
||||
|
||||
commander.option("-w, --whitelist [whitelist]", "Whitelist of transformers to ONLY use", list);
|
||||
commander.option("-b, --blacklist [blacklist]", "Blacklist of transformers to NOT use", list);
|
||||
commander.option("-m, --modules [modules]", "Module formatter type to use [common]", "common");
|
||||
commander.option("-w, --whitelist [whitelist]", "Whitelist of transformers to ONLY use", util.list);
|
||||
commander.option("-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("-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("-a, --amd-module-ids", "Insert module id in AMD modules", false); // todo: remove in 3.0.0
|
||||
commander.option("-m, --module-ids", "Insert module id in modules", false);
|
||||
|
||||
commander.on("--help", function(){
|
||||
console.log(" Transformers:");
|
||||
console.log();
|
||||
_.each(_.keys(transform.transformers).sort(), function (key) {
|
||||
if (key[0] === "_") return;
|
||||
console.log(" - " + key);
|
||||
});
|
||||
console.log();
|
||||
var outKeys = function (title, obj) {
|
||||
console.log(" " + title + ":");
|
||||
console.log();
|
||||
|
||||
var hasOptional = true;
|
||||
|
||||
_.each(_.keys(obj).sort(), function (key) {
|
||||
if (key[0] === "_") return;
|
||||
|
||||
if (obj[key].optional) {
|
||||
hasOptional = true;
|
||||
key = "[" + key + "]";
|
||||
}
|
||||
|
||||
console.log(" - " + key);
|
||||
});
|
||||
|
||||
console.log();
|
||||
};
|
||||
|
||||
outKeys("Transformers", transform.transformers);
|
||||
outKeys("Module formatters", transform.moduleFormatters);
|
||||
});
|
||||
|
||||
var pkg = require("../../package.json");
|
||||
@@ -83,9 +99,16 @@ if (errors.length) {
|
||||
|
||||
exports.opts = {
|
||||
sourceMapName: commander.outFile,
|
||||
experimental: commander.experimental,
|
||||
playground: commander.playground,
|
||||
moduleIds: commander.amdModuleIds || commander.moduleIds,
|
||||
blacklist: commander.blacklist,
|
||||
whitelist: commander.whitelist,
|
||||
sourceMap: commander.sourceMaps || commander.sourceMapsInline
|
||||
sourceMap: commander.sourceMaps || commander.sourceMapsInline,
|
||||
optional: commander.optional,
|
||||
comments: !commander.removeComments,
|
||||
runtime: commander.runtime,
|
||||
modules: commander.modules
|
||||
};
|
||||
|
||||
var fn;
|
||||
|
||||
@@ -1,17 +1,24 @@
|
||||
var readdir = require("fs-readdir-recursive");
|
||||
var index = require("./index");
|
||||
var util = require("../../lib/6to5/util");
|
||||
var path = require("path");
|
||||
var to5 = require("../../lib/6to5");
|
||||
var fs = require("fs");
|
||||
var _ = require("lodash");
|
||||
|
||||
exports.readdirFilter = function (filename) {
|
||||
return readdir(filename).filter(util.canCompile);
|
||||
return readdir(filename).filter(function (filename) {
|
||||
return util.canCompile(filename);
|
||||
});
|
||||
};
|
||||
|
||||
exports.transform = function (filename, code, to) {
|
||||
var opts = _.extend({ filename: filename }, index.opts);
|
||||
if (to) opts.sourceMapName = to;
|
||||
exports.addSourceMappingUrl = function (code, loc) {
|
||||
return code + "\n//# sourceMappingURL=" + path.basename(loc);
|
||||
};
|
||||
|
||||
exports.transform = function (filename, code, opts) {
|
||||
opts = _.extend(opts || {}, index.opts);
|
||||
opts.filename = filename;
|
||||
|
||||
var result = to5.transform(code, opts);
|
||||
result.filename = filename;
|
||||
@@ -19,7 +26,7 @@ exports.transform = function (filename, code, to) {
|
||||
return result;
|
||||
};
|
||||
|
||||
exports.compile = function (filename, to) {
|
||||
exports.compile = function (filename, opts) {
|
||||
var code = fs.readFileSync(filename, "utf8");
|
||||
return exports.transform(filename, code, to);
|
||||
return exports.transform(filename, code, opts);
|
||||
};
|
||||
|
||||
107
bin/_6to5-node
Normal file
107
bin/_6to5-node
Normal file
@@ -0,0 +1,107 @@
|
||||
#!/usr/bin/env node
|
||||
|
||||
var roadrunner = require("roadrunner");
|
||||
var commander = require("commander");
|
||||
var Module = require("module");
|
||||
var path = require("path");
|
||||
var repl = require("repl");
|
||||
var to5 = require("../lib/6to5");
|
||||
var util = require("../lib/6to5/util");
|
||||
var vm = require("vm");
|
||||
var _ = require("lodash");
|
||||
|
||||
commander.option("-e, --eval [script]", "Evaluate script");
|
||||
commander.option("-p, --print", "Evaluate script and print result");
|
||||
commander.option("-i, --ignore [regex]", "Ignore all files that match this regex when using the require hook");
|
||||
commander.option("-x, --extensions [extensions]", "List of extensions to hook into [.es6,.js]");
|
||||
commander.option("-r, --experimental", "Enable experimental support for proposed ES7 features");
|
||||
commander.option("-g, --playground", "Enable playground support");
|
||||
commander.option("-c, --cache", "Cache compiled files and require paths");
|
||||
|
||||
var pkg = require("../package.json");
|
||||
commander.version(pkg.version);
|
||||
commander.usage("[options] [ -e script | script.js ] [arguments]");
|
||||
commander.parse(process.argv);
|
||||
|
||||
if (commander.cache) roadrunner.load();
|
||||
|
||||
//
|
||||
|
||||
to5.register({
|
||||
experimental: commander.experimental,
|
||||
extensions: commander.extensions,
|
||||
playground: commander.playground,
|
||||
ignore: commander.ignore,
|
||||
cache: commander.cache && roadrunner.get("6to5")
|
||||
});
|
||||
|
||||
//
|
||||
|
||||
var _eval = function (code, filename) {
|
||||
code = to5.transform(code, {
|
||||
filename: filename,
|
||||
blacklist: ["useStrict"],
|
||||
experimental: commander.experimental,
|
||||
playground: commander.playground
|
||||
}).code;
|
||||
return vm.runInThisContext(code, filename);
|
||||
};
|
||||
|
||||
if (commander.eval) {
|
||||
var result = _eval(commander.eval, "eval");
|
||||
if (commander.print) console.log(result);
|
||||
} else {
|
||||
if (commander.args.length) {
|
||||
// slice all arguments up to the first filename since they're 6to5 args that we handle
|
||||
var args = process.argv.slice(2);
|
||||
|
||||
var i = 0;
|
||||
_.each(args, function (arg, i2) {
|
||||
if (arg[0] !== "-") {
|
||||
i = i2;
|
||||
return false;
|
||||
}
|
||||
});
|
||||
args = args.slice(i);
|
||||
|
||||
// make the filename absolute
|
||||
var filename = args[0]
|
||||
if (!util.isAbsolute(filename)) args[0] = path.join(process.cwd(), filename);
|
||||
|
||||
// add back on node and concat the sliced args
|
||||
process.argv = ["node"].concat(args);
|
||||
|
||||
Module.runMain();
|
||||
} else {
|
||||
replStart();
|
||||
}
|
||||
}
|
||||
|
||||
if (commander.cache) roadrunner.save();
|
||||
|
||||
function replStart() {
|
||||
repl.start({
|
||||
prompt: "> ",
|
||||
input: process.stdin,
|
||||
output: process.stdout,
|
||||
eval: replEval,
|
||||
useGlobal: true
|
||||
});
|
||||
}
|
||||
|
||||
function replEval(code, context, filename, callback) {
|
||||
var err;
|
||||
var result;
|
||||
|
||||
try {
|
||||
if (/^\((.*?)\n\)$/.test(code)) {
|
||||
code = code.slice(1, -2); // remove "(" and "\n)"
|
||||
}
|
||||
|
||||
result = _eval(code, filename);
|
||||
} catch (e) {
|
||||
err = e;
|
||||
}
|
||||
|
||||
callback(err, result);
|
||||
}
|
||||
5
bin/cache-tests
Normal file
5
bin/cache-tests
Normal file
@@ -0,0 +1,5 @@
|
||||
#!/usr/bin/env node
|
||||
|
||||
var fs = require("fs");
|
||||
var cache = require("../test/_helper").cache;
|
||||
fs.writeFileSync("tests.json", JSON.stringify(cache));
|
||||
@@ -1,6 +0,0 @@
|
||||
#!/usr/bin/env node
|
||||
|
||||
var helper = require("../test/_helper");
|
||||
var util = require("../lib/6to5/util");
|
||||
|
||||
console.log("(" + helper.run + ")(" + JSON.stringify(helper.getTests()) + ", to5, proclaim)");
|
||||
65
doc/browser.md
Normal file
65
doc/browser.md
Normal file
@@ -0,0 +1,65 @@
|
||||
# Browser
|
||||
|
||||
A browser version of 6to5 is available from `browser.js` inside the 6to5
|
||||
directory in an npm release.
|
||||
|
||||
## Scripts
|
||||
|
||||
While it's not recommended for serious use, when the browser version is included
|
||||
all scripts with the type `text/ecmascript-6` and `text/6to5` are automatically
|
||||
compiled and ran.
|
||||
|
||||
For example:
|
||||
|
||||
```html
|
||||
<script src="node_modules/6to5/browser.js"></script>
|
||||
<script type="text/6to5">
|
||||
class Test {
|
||||
test() {
|
||||
return "test";
|
||||
}
|
||||
}
|
||||
|
||||
var test = new Test;
|
||||
test.test();
|
||||
</script>
|
||||
```
|
||||
|
||||
## Build
|
||||
|
||||
You can build a browser version of the compiler by running the following in the
|
||||
6to5 directory:
|
||||
|
||||
```sh
|
||||
$ make build
|
||||
```
|
||||
|
||||
This will output the files `dist/6to5.js` and `dist/6to5.min.js`.
|
||||
|
||||
## Test
|
||||
|
||||
To test 6to5 in your browser run:
|
||||
|
||||
```sh
|
||||
$ make test-browser
|
||||
```
|
||||
|
||||
And open `test/browser.html` in your browser if it doesn't open automatically.
|
||||
|
||||
## API
|
||||
|
||||
### to5.transform(code, [opts])
|
||||
|
||||
See [options](usage.md#options) for additional documentation.
|
||||
|
||||
```javascript
|
||||
to5.transform("class Test {}").code;
|
||||
```
|
||||
|
||||
### to5.run(code, [opts])
|
||||
|
||||
See [options](usage.md#options) for additional documentation.
|
||||
|
||||
```javascript
|
||||
to5.run("class Test {}");
|
||||
```
|
||||
59
doc/caveats.md
Normal file
59
doc/caveats.md
Normal file
@@ -0,0 +1,59 @@
|
||||
# Caveats
|
||||
|
||||
In order for certain features to work they require certain polyfills. You can
|
||||
satisfy **all** 6to5 feature requirements by using the included
|
||||
[polyfill](polyfill.md).
|
||||
|
||||
You may alternatively selectively include what you need:
|
||||
|
||||
| Feature | Requirements |
|
||||
| --------------------------- | ---------------------------------------------------------------------------------------------------------------------- |
|
||||
| Abstract References | [experimental](experimental.md), `Symbol` |
|
||||
| Array destructuring | `Array.isArray`, `Array.from` |
|
||||
| Async functions, Generators | [experimental](experimental.md), [regenerator runtime](https://github.com/facebook/regenerator/blob/master/runtime.js) |
|
||||
| Comprehensions | [experimental](experimental.md), `Array.isArray`, `Array.from` |
|
||||
| For Of | `Symbol`, `prototype[Symbol.iterator]` |
|
||||
| Object spread/rest | [experimental](experimental.md), `Object.assign` |
|
||||
| Spread | `Array.isArray`, `Array.from` |
|
||||
|
||||
## ES5
|
||||
|
||||
Since 6to5 assumes that your code will be ran in an ES5 environment it uses ES5
|
||||
functions. So if you're using an environment that has limited or no support for
|
||||
ES5 such as lower versions of IE then using the
|
||||
[es5-shim](https://github.com/es-shims/es5-shim) along with the
|
||||
[6to5 polyfill](polyfill.md) will add support for these methods.
|
||||
|
||||
## Internet Explorer
|
||||
|
||||
### Classes (9 and below)
|
||||
|
||||
If you're inheriting from a class then static properties are inherited from it
|
||||
via [\_\_proto\_\_](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/proto),
|
||||
this is widely supported but you may run into problems with much older browsers.
|
||||
|
||||
**NOTE:** `__proto__` is not supported on IE <= 9 so static properties
|
||||
**will not** be inherited. A possible workaround is to use `super();`:
|
||||
|
||||
```javascript
|
||||
class Foo {
|
||||
static foo() {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
class Bar extends Foo {
|
||||
static foo() {
|
||||
super();
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## Getters/setters (8 and below)
|
||||
|
||||
In IE8 `Object.defineProperty` can only be used on DOM objects. This is
|
||||
unfortunate as it's required to set getters and setters. Due to this if
|
||||
you plan on supporting IE8 or below then the user of getters and setters
|
||||
isn't recommended.
|
||||
|
||||
Reference: [MDN](https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/Object/defineProperty#Internet_Explorer_8_specific_notes).
|
||||
138
doc/differences.md
Normal file
138
doc/differences.md
Normal file
@@ -0,0 +1,138 @@
|
||||
# Differences
|
||||
|
||||
There are three main points that separate 6to5 from all other transpilers.
|
||||
|
||||
### Readable code
|
||||
|
||||
The fundamental concept behind 6to5 is that the generated code must be close as
|
||||
possible to the original, retaining all the same formatting and readability.
|
||||
|
||||
Many other transpilers are just concerned with making the code work while 6to5
|
||||
is concerned with making sure it works **and** is readable at the same time.
|
||||
|
||||
For example, given the following array comprehension:
|
||||
|
||||
```javascript
|
||||
var seattlers = [for (c of customers) if (c.city == "Seattle") { name: c.name, age: c.age }];
|
||||
```
|
||||
|
||||
is generated to the following with 6to5:
|
||||
|
||||
```javascript
|
||||
var seattlers = Array.from(customers).filter(function (c) {
|
||||
return c.city == "Seattle";
|
||||
}).map(function (c) {
|
||||
return {
|
||||
name: c.name,
|
||||
age: c.age
|
||||
};
|
||||
});
|
||||
```
|
||||
|
||||
The following is what Traceur generates:
|
||||
|
||||
```javascript
|
||||
var seattlers = (function() {
|
||||
var c;
|
||||
var $__20 = 0,
|
||||
$__21 = [];
|
||||
for (var $__22 = customers[$traceurRuntime.toProperty(Symbol.iterator)](),
|
||||
$__23; !($__23 = $__22.next()).done; ) {
|
||||
c = $__23.value;
|
||||
if (c.city == "Seattle")
|
||||
$traceurRuntime.setProperty($__21, $__20++, {
|
||||
name: c.name,
|
||||
age: c.age
|
||||
});
|
||||
}
|
||||
return $__21;
|
||||
}());
|
||||
```
|
||||
|
||||
As you can tell, it's not very pretty, unreadable even. Instead of mapping
|
||||
directly to a runtime, like other transpilers, 6to5 maps directly to the
|
||||
equivalent ES5.
|
||||
|
||||
Sometimes there are little inline functions that 6to5 needs. These are
|
||||
placed at the top of your file much like coffee-script does. If these
|
||||
are bother you then you can use the [optional runtime](optional-runtime.md).
|
||||
We promise that these inline functions will never be significant and will
|
||||
always be used as little as possible.
|
||||
|
||||
### Static analysis
|
||||
|
||||
6to5 uses a lot of static analysis to simplify code as much as possible.
|
||||
Not many other transpilers do this, and those that do don't do it nearly
|
||||
as much as 6to5. This process is pretty intensive but it leads to higher
|
||||
quality code.
|
||||
|
||||
### Spec compliancy
|
||||
|
||||
6to5 prides itself on
|
||||
[spec compliancy](https://kangax.github.io/compat-table/es6/). We have
|
||||
excellent support for edgecases, something that many other transpilers
|
||||
suffer from, including Traceur. When you use 6to5 you can be confident
|
||||
that when you turn it off and use your code in a full ES6 environment
|
||||
**it'll just work**.
|
||||
|
||||
## Comparison to other transpilers
|
||||
|
||||
### Features
|
||||
|
||||
| | 6to5 | Traceur | es6-transpiler | esnext | es6now | jstransform |
|
||||
| ---------------------------- | ---- | ------- | -------------- | ------ | ------ | ----------- |
|
||||
| Source maps | ✓ | ✓ | ✓ | ✓ | | ✓ |
|
||||
| No compiler global pollution | ✓ | | ✓ | ✓ | | ✓ |
|
||||
| Optional runtime | ✓ | | ✓ | | | ✓ |
|
||||
| Browser compiler | ✓ | ✓ | | ✓ | | |
|
||||
|
||||
### Language Support
|
||||
|
||||
| | 6to5 | Traceur | es6-transpiler | esnext | es6now | jstransform |
|
||||
| ---------------------------- | ---- | ------- | -------------- | ------ | ------ | ----------- |
|
||||
| Abstract references | ✓ | | | | | |
|
||||
| Array comprehension | ✓ | ✓ | ✓ | | | |
|
||||
| Arrow functions | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
|
||||
| Async functions | ✓ | ✓ | | ✓ | | |
|
||||
| Async generator functions | ✓ | ✓ | | | | |
|
||||
| Classes | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
|
||||
| Computed property names | ✓ | ✓ | ✓ | ✓ | ✓ | |
|
||||
| Constants | ✓ | ✓ | ✓ | | | |
|
||||
| Default parameters | ✓ | ✓ | ✓ | ✓ | ✓ | |
|
||||
| Destructuring | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
|
||||
| Exponentiation operator | ✓ | ✓ | | | | |
|
||||
| Flow types | ✓ | | | | | ✓ |
|
||||
| For-of | ✓ | ✓ | ✓ | ✓ | ✓ | |
|
||||
| Generators | ✓ | ✓ | | ✓ | | |
|
||||
| Generator comprehension | ✓ | ✓ | | | | |
|
||||
| JSX | ✓ | | | | | |
|
||||
| Let scoping | ✓ | ✓ | ✓ | | | |
|
||||
| Modules | ✓ | ✓ | | | ✓ | |
|
||||
| Object rest/spread | ✓ | | | | | ✓ |
|
||||
| Property method assignment | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
|
||||
| Property name shorthand | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
|
||||
| Rest parameters | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
|
||||
| React | ✓ | | | | | |
|
||||
| Spread | ✓ | ✓ | ✓ | ✓ | ✓ | |
|
||||
| Template literals | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
|
||||
| Unicode regex | ✓ | ✓ | ✓ | | | |
|
||||
|
||||
### [Traceur](https://github.com/google/traceur-compiler)
|
||||
|
||||
Traceur requires quite a bulky runtime (~75KB) and produces quite verbose code.
|
||||
While this can be trimmed down by selectively building the runtime, it's an
|
||||
unnecessary step when a large runtime can be eliminated entirely.
|
||||
|
||||
### [es6now](https://github.com/zenparsing/es6now)
|
||||
|
||||
es6now doesn't output sourcemaps. This is cited as a positive as line-to-line
|
||||
mapping is the goal. This however obviously doesn't retain column mapping
|
||||
resulting in the output code not being very pleasant.
|
||||
|
||||
### [es6-transpiler](https://github.com/termi/es6-transpiler)
|
||||
|
||||
The es6-transpiler compiler requires shims to operate which pollutes the global
|
||||
scope resulting in possible collisions.
|
||||
|
||||
es6-transpiler maps line-by-line, just like es6now, this results in the same
|
||||
issues such as lack of column information and unpleasant code output.
|
||||
8
doc/experimental.md
Normal file
8
doc/experimental.md
Normal file
@@ -0,0 +1,8 @@
|
||||
## Experimental
|
||||
|
||||
6to5 also has experimental support for ES7 proposals. You can enable this with
|
||||
the `experimental: true` option when using the [Node API](#node) or
|
||||
`--experimental` when using the [CLI](#cli).
|
||||
|
||||
**WARNING:** These proposals are subject to change so use with
|
||||
**extreme caution**.
|
||||
283
doc/features.md
Normal file
283
doc/features.md
Normal file
@@ -0,0 +1,283 @@
|
||||
# Features
|
||||
|
||||
## Abstract references ([experimental](experimental.md)) ([spec](https://github.com/zenparsing/es-abstract-refs))
|
||||
|
||||
```javascript
|
||||
foo::bar;
|
||||
foo::bar = baz;
|
||||
delete foo::bar;
|
||||
```
|
||||
|
||||
## Array comprehensions ([experimental](experimental.md))
|
||||
|
||||
```javascript
|
||||
var results = [for (c of customers) if (c.city == "Seattle") { name: c.name, age: c.age }]
|
||||
```
|
||||
|
||||
## Arrow functions
|
||||
|
||||
```javascript
|
||||
// Expression bodies
|
||||
var odds = evens.map(v => v + 1);
|
||||
var nums = evens.map((v, i) => v + i);
|
||||
|
||||
// Statement bodies
|
||||
nums.forEach(v => {
|
||||
if (v % 5 === 0)
|
||||
fives.push(v);
|
||||
});
|
||||
|
||||
// Lexical this
|
||||
var bob = {
|
||||
_name: "Bob",
|
||||
_friends: [],
|
||||
printFriends() {
|
||||
this._friends.forEach(f => {
|
||||
console.log(this._name + " knows " + f);
|
||||
});
|
||||
}
|
||||
};
|
||||
```
|
||||
|
||||
## Async functions ([experimental](experimental.md)) ([spec](https://github.com/lukehoban/ecmascript-asyncawait))
|
||||
|
||||
```javascript
|
||||
async function chainAnimationsAsync(elem, animations) {
|
||||
for (var anim of animations) {
|
||||
await anim(elem);
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## Async generator functions ([experimental](experimental.md)) ([spec](https://github.com/jhusain/asyncgenerator))
|
||||
|
||||
```javascript
|
||||
|
||||
```
|
||||
|
||||
## Classes
|
||||
|
||||
```javascript
|
||||
class SkinnedMesh extends THREE.Mesh {
|
||||
constructor(geometry, materials) {
|
||||
super(geometry, materials);
|
||||
|
||||
this.idMatrix = SkinnedMesh.defaultMatrix();
|
||||
this.bones = [];
|
||||
this.boneMatrices = [];
|
||||
//...
|
||||
}
|
||||
|
||||
update(camera) {
|
||||
//...
|
||||
super.update();
|
||||
}
|
||||
|
||||
static defaultMatrix() {
|
||||
return new THREE.Matrix4();
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## Computed property names
|
||||
|
||||
```javascript
|
||||
var foo = "foo";
|
||||
var bar = "bar";
|
||||
var obj = {
|
||||
["foo" + bar]: "heh",
|
||||
["bar" + foo]: "noo",
|
||||
foo: "foo",
|
||||
bar: "bar"
|
||||
};
|
||||
```
|
||||
|
||||
## Constants
|
||||
|
||||
```javascript
|
||||
const MULTIPLIER = 5;
|
||||
console.log(2 * MULTIPLIER);
|
||||
|
||||
MULTIPLIER = 6; // error
|
||||
var MULTIPLIER; // error
|
||||
```
|
||||
|
||||
## Default parameters
|
||||
|
||||
```javascript
|
||||
function f(x, y = 12) {
|
||||
// y is 12 if not passed (or passed as undefined)
|
||||
return x + y;
|
||||
}
|
||||
f(3) == 15
|
||||
```
|
||||
|
||||
## Destructuring
|
||||
|
||||
```javascript
|
||||
// list matching
|
||||
var [a, , b] = [1,2,3];
|
||||
|
||||
// object matching
|
||||
var { op: a, lhs: { op: b }, rhs: c } = getASTNode();
|
||||
|
||||
// object matching shorthand
|
||||
// binds `op`, `lhs` and `rhs` in scope
|
||||
var { op, lhs, rhs } = getASTNode();
|
||||
|
||||
// Can be used in parameter position
|
||||
function g({ name: x }) {
|
||||
console.log(x);
|
||||
}
|
||||
g({ name: 5 });
|
||||
|
||||
// Fail-soft destructuring
|
||||
var [a] = [];
|
||||
a === undefined;
|
||||
```
|
||||
|
||||
## Exponentiation operator ([experimental](experimental.md)) ([spec](https://github.com/rwaldron/exponentiation-operator))
|
||||
|
||||
```javascript
|
||||
var a = 2;
|
||||
a **= 2;
|
||||
|
||||
var squared = 2 ** 2;
|
||||
```
|
||||
|
||||
## For-of
|
||||
|
||||
```javascript
|
||||
for (var i of [1, 2, 3]) {
|
||||
console.log(i * i);
|
||||
}
|
||||
```
|
||||
|
||||
## Generators
|
||||
|
||||
```javascript
|
||||
function* fibonacci() {
|
||||
var pre = 0, cur = 1;
|
||||
for (;;) {
|
||||
var temp = pre;
|
||||
pre = cur;
|
||||
cur += temp;
|
||||
yield cur;
|
||||
}
|
||||
}
|
||||
|
||||
for (var n of fibonacci()) {
|
||||
// truncate the sequence at 1000
|
||||
if (n > 1000) break;
|
||||
console.log(n);
|
||||
}
|
||||
```
|
||||
|
||||
## Generator comprehensions ([experimental](experimental.md))
|
||||
|
||||
```javascript
|
||||
var nums = [1, 2, 3, 4, 5, 6];
|
||||
var multiples = (for (i of nums) if (i % 2) i * i);
|
||||
assert.equal(multiples.next().value, 1);
|
||||
assert.equal(multiples.next().value, 9);
|
||||
assert.equal(multiples.next().value, 25);
|
||||
```
|
||||
|
||||
## Let scoping
|
||||
|
||||
```javascript
|
||||
for (let i in arr) {
|
||||
let v = arr[i];
|
||||
}
|
||||
```
|
||||
|
||||
## Modules
|
||||
|
||||
```javascript
|
||||
import "foo";
|
||||
import foo from "foo";
|
||||
import * as foo from "foo";
|
||||
import {bar} from "foo";
|
||||
import {foo as bar} from "foo";
|
||||
|
||||
export { test };
|
||||
export var test = 5;
|
||||
export function test() {}
|
||||
|
||||
export default test;
|
||||
```
|
||||
|
||||
## Numeric literals
|
||||
|
||||
```javascript
|
||||
0b111110111 === 503; // true
|
||||
0o767 === 503; // true
|
||||
```
|
||||
|
||||
## Object spread/rest ([experimental](experimental.md)) ([spec](https://github.com/sebmarkbage/ecmascript-rest-spread))
|
||||
|
||||
```javascript
|
||||
var n = { x, y, ...z };
|
||||
var { x, y, ...z } = { x: 1, y: 2, a: 3, b: 4 };
|
||||
```
|
||||
|
||||
## Property method assignment
|
||||
|
||||
```javascript
|
||||
var obj = {
|
||||
foo() {
|
||||
return "foobar";
|
||||
},
|
||||
|
||||
get bar() {
|
||||
return this._bar;
|
||||
},
|
||||
|
||||
set bar(val) {
|
||||
this._bar = val;
|
||||
}
|
||||
};
|
||||
```
|
||||
|
||||
## Property name shorthand
|
||||
|
||||
```javascript
|
||||
function f(x, y) {
|
||||
return { x, y };
|
||||
}
|
||||
```
|
||||
|
||||
## Rest parameters
|
||||
|
||||
```javascript
|
||||
function f(x, ...y) {
|
||||
// y is an Array
|
||||
return x * y.length;
|
||||
}
|
||||
f(3, "hello", true) == 6
|
||||
```
|
||||
|
||||
## Spread
|
||||
|
||||
```javascript
|
||||
function f(x, y, z) {
|
||||
return x + y + z;
|
||||
}
|
||||
// Pass each elem of array as argument
|
||||
f(...[1,2,3]) == 6
|
||||
```
|
||||
|
||||
## Template literals
|
||||
|
||||
```javascript
|
||||
var x = 5;
|
||||
var y = 10;
|
||||
console.log(`${x} + ${y} = ${x + y}`); // "5 + 10 = 15"
|
||||
```
|
||||
## Unicode regex
|
||||
|
||||
```javascript
|
||||
var string = 'foo💩bar';
|
||||
var match = string.match(/foo(.)bar/u);
|
||||
console.log(match[1]);
|
||||
```
|
||||
62
doc/index.md
Normal file
62
doc/index.md
Normal file
@@ -0,0 +1,62 @@
|
||||
**6to5** turns ES6+ code into vanilla ES5, so you can use next generation features **today.**
|
||||
|
||||
- **Readable** - formatting is retained if possible so your generated code is as similar as possible.
|
||||
- **Extensible** - with a large range of [plugins](plugins.md) and **browser support**.
|
||||
- **Lossless** - **source map support** so you can debug your compiled code with ease.
|
||||
- **Compact** - maps directly to the equivalent ES5 with **no runtime**[\*](caveats.md).
|
||||
|
||||
## Installation
|
||||
|
||||
It's as easy as:
|
||||
|
||||
$ npm install -g 6to5
|
||||
|
||||
## Usage
|
||||
|
||||
Once you've installed 6to5, there are multiple paths you can take depending on
|
||||
how you want to use it.
|
||||
|
||||
6to5 will simply compile your ES6+ script to ES5 if you pass it as an argument
|
||||
to the command-line tool `6to5`:
|
||||
|
||||
```sh
|
||||
$ 6to5 script.js
|
||||
```
|
||||
|
||||
If you have a file written using ES6+ and you just want to run it, `6to5-node`
|
||||
has you covered:
|
||||
|
||||
```sh
|
||||
$ 6to5-node script.js
|
||||
```
|
||||
|
||||
And it doesn't end here! To see all the ways you can use 6to5, check out the
|
||||
[Usage](http://6to5.github.io/usage.html) page.
|
||||
|
||||
## [Features](features.md)
|
||||
|
||||
- [Abstract references](features.md#abstract-references) ([experimental](experimental.md))
|
||||
- [Array comprehension](features.md#array-comprehension) ([experimental](experimental.md))
|
||||
- [Async functions](features.md#async-functions) ([experimental](experimental.md))
|
||||
- [Async generator functions](features.md#async-generator-functions) ([experimental](experimental.md))
|
||||
- [Arrow functions](features.md#arrow-functions)
|
||||
- [Classes](features.md#classes)
|
||||
- [Computed property names](features.md#computed-property-names)
|
||||
- [Constants](features.md#constants)
|
||||
- [Default parameters](features.md#default-parameters)
|
||||
- [Destructuring](features.md#destructuring)
|
||||
- [Exponentiation operator](features.md#exponentiation-operator) ([experimental](experimental.md))
|
||||
- [For-of](features.md#for-of)
|
||||
- [Generators](features.md#generators)
|
||||
- [Generator comprehension](features.md#generator-comprehension) ([experimental](experimental.md))
|
||||
- [Let scoping](features.md#let-scoping)
|
||||
- [Modules](features.md#modules)
|
||||
- [Numeric literals](features.md#numeric-literals)
|
||||
- [Object Rest/Spread](features.md#object-rest-spread) ([experimental](experimental.md))
|
||||
- [Property method assignment](features.md#property-method-assignment)
|
||||
- [Property name shorthand](features.md#property-name-shorthand)
|
||||
- [React/JSX](react.md)
|
||||
- [Rest parameters](features.md#rest-parameters)
|
||||
- [Spread](features.md#spread)
|
||||
- [Template literals](features.md#template-literals)
|
||||
- [Unicode regex](features.md#unicode-regex)
|
||||
257
doc/modules.md
Normal file
257
doc/modules.md
Normal file
@@ -0,0 +1,257 @@
|
||||
# Modules
|
||||
|
||||
## Usage
|
||||
|
||||
### CLI
|
||||
|
||||
```sh
|
||||
$ 6to5 --modules common script.js
|
||||
```
|
||||
|
||||
### Node
|
||||
|
||||
```javascript
|
||||
var to5 = require("6to5");
|
||||
to5.transform('import "foo";', { modules: "common" });
|
||||
```
|
||||
|
||||
## Formats
|
||||
|
||||
* [AMD](#amd)
|
||||
* [Common (Default)](#common-default)
|
||||
* [Ignore](#ignore)
|
||||
* [System](#system)
|
||||
* [UMD](#umd)
|
||||
|
||||
### Common
|
||||
|
||||
```sh
|
||||
$ 6to5 --modules common
|
||||
```
|
||||
|
||||
**In**
|
||||
|
||||
```javascript
|
||||
export default test;
|
||||
|
||||
export {test};
|
||||
export var test = 5;
|
||||
|
||||
import "foo";
|
||||
|
||||
import foo from "foo";
|
||||
import * as foo from "foo";
|
||||
|
||||
import {bar} from "foo";
|
||||
import {foo as bar} from "foo";
|
||||
```
|
||||
|
||||
**Out**
|
||||
|
||||
```javascript
|
||||
"use strict";
|
||||
|
||||
var _interopRequire = function (obj) {
|
||||
return obj && (obj["default"] || obj);
|
||||
};
|
||||
|
||||
exports = module.exports = test;
|
||||
|
||||
exports.test = test;
|
||||
var test = exports.test = 5;
|
||||
|
||||
require("foo");
|
||||
|
||||
var foo = _interopRequire(require("foo"));
|
||||
|
||||
var foo = require("foo");
|
||||
|
||||
var bar = require("foo").bar;
|
||||
var bar = require("foo").foo;
|
||||
```
|
||||
|
||||
### AMD
|
||||
|
||||
```sh
|
||||
$ 6to5 --modules amd
|
||||
```
|
||||
|
||||
**In**
|
||||
|
||||
```javascript
|
||||
import foo from "foo";
|
||||
|
||||
export function bar() {
|
||||
return foo("foobar");
|
||||
}
|
||||
```
|
||||
|
||||
**Out**
|
||||
|
||||
```javascript
|
||||
define(["exports", "foo"], function (exports, _foo) {
|
||||
"use strict";
|
||||
|
||||
var _interopRequire = function (obj) {
|
||||
return obj && (obj["default"] || obj);
|
||||
};
|
||||
|
||||
exports.bar = bar;
|
||||
var foo = _interopRequire(_foo);
|
||||
|
||||
function bar() {
|
||||
return foo("foobar");
|
||||
}
|
||||
});
|
||||
```
|
||||
|
||||
You can optionally specify to include the module id (using the `--amd-module-id` argument):
|
||||
|
||||
```javascript
|
||||
define("filename", ["exports", "foo"], function (exports, _foo) {})
|
||||
```
|
||||
|
||||
### UMD
|
||||
|
||||
```sh
|
||||
$ 6to5 --modules umd
|
||||
```
|
||||
|
||||
**In**
|
||||
|
||||
```javascript
|
||||
import foo from "foo";
|
||||
|
||||
export function bar() {
|
||||
return foo("foobar");
|
||||
}
|
||||
```
|
||||
|
||||
**Out**
|
||||
|
||||
```javascript
|
||||
(function (factory) {
|
||||
if (typeof define === "function" && define.amd) {
|
||||
define(["exports", "foo"], factory);
|
||||
} else if (typeof exports !== "undefined") {
|
||||
factory(exports, require("foo"));
|
||||
}
|
||||
})(function (exports, _foo) {
|
||||
"use strict";
|
||||
|
||||
var _interopRequire = function (obj) {
|
||||
return obj && (obj["default"] || obj);
|
||||
};
|
||||
|
||||
exports.bar = bar;
|
||||
var foo = _interopRequire(_foo);
|
||||
|
||||
function bar() {
|
||||
return foo("foobar");
|
||||
}
|
||||
});
|
||||
```
|
||||
|
||||
### Ignore
|
||||
|
||||
```sh
|
||||
$ 6to5 --modules ignore
|
||||
```
|
||||
|
||||
**In**
|
||||
|
||||
```javascript
|
||||
import foo from "foo";
|
||||
|
||||
export function bar() {
|
||||
return foo("foobar");
|
||||
}
|
||||
```
|
||||
|
||||
**Out**
|
||||
|
||||
```javascript
|
||||
function bar() {
|
||||
return foo("foobar");
|
||||
}
|
||||
```
|
||||
|
||||
### System
|
||||
|
||||
```sh
|
||||
$ 6to5 --modules system
|
||||
```
|
||||
|
||||
**In**
|
||||
|
||||
```javascript
|
||||
import foo from "foo";
|
||||
|
||||
export function bar() {
|
||||
return foo("foobar");
|
||||
}
|
||||
```
|
||||
|
||||
**Out**
|
||||
|
||||
```javascript
|
||||
System.register("bar", ["foo"], function (_export) {
|
||||
"use strict";
|
||||
|
||||
var __moduleName = "bar";
|
||||
|
||||
var foo;
|
||||
function bar() {
|
||||
return foo("foobar");
|
||||
}
|
||||
return {
|
||||
setters: [function (m) {
|
||||
foo = m.default;
|
||||
}],
|
||||
execute: function () {
|
||||
_export("bar", bar);
|
||||
}
|
||||
};
|
||||
});
|
||||
```
|
||||
|
||||
## Custom
|
||||
|
||||
You can alternatively specify module names instead of one of the built-in types.
|
||||
|
||||
```sh
|
||||
$ 6to5 --modules custom-module-formatter
|
||||
```
|
||||
|
||||
**node_modules/custom-module-formatter/index.js**
|
||||
|
||||
```javascript
|
||||
module.exports = ModuleFormatter;
|
||||
|
||||
function ModuleFormatter() {
|
||||
|
||||
}
|
||||
|
||||
ModuleFormatter.prototype.transform = function (ast) {
|
||||
// this is ran after all transformers have had their turn at modifying the ast
|
||||
// feel free to modify this however
|
||||
};
|
||||
|
||||
ModuleFormatter.prototype.importDeclaration = function (node, nodes) {
|
||||
// node is an ImportDeclaration
|
||||
};
|
||||
|
||||
ModuleFormatter.prototype.importSpecifier = function (specifier, node, nodes) {
|
||||
// specifier is an ImportSpecifier
|
||||
// node is an ImportDeclaration
|
||||
};
|
||||
|
||||
ModuleFormatter.prototype.exportDeclaration = function (node, nodes) {
|
||||
// node is an ExportDeclaration
|
||||
};
|
||||
|
||||
ModuleFormatter.prototype.exportSpecifier = function (specifier, node, nodes) {
|
||||
// specifier is an ExportSpecifier
|
||||
// node is an ExportDeclaration
|
||||
};
|
||||
```
|
||||
57
doc/optional-runtime.md
Normal file
57
doc/optional-runtime.md
Normal file
@@ -0,0 +1,57 @@
|
||||
# Optional runtime
|
||||
|
||||
6to5 has a few helper functions that'll be placed at the top of the generated
|
||||
code if needed so it's not inlined multiple times throughout that file. This may
|
||||
become an issue if you have multiple files, especially when you're sending them
|
||||
to the browser. gzip alleviates most of this concern but it's still not ideal.
|
||||
|
||||
You can tell 6to5 to not place any declarations at the top of your files and
|
||||
instead just point them to a reference contained within the runtime.
|
||||
|
||||
Simply use the following option if you're using the [Node API](usage.md#node):
|
||||
|
||||
```javascript
|
||||
{
|
||||
runtime: true
|
||||
}
|
||||
```
|
||||
|
||||
or the following flag if you're using the [CLI](usage.md#cli):
|
||||
|
||||
```ssh
|
||||
$ 6to5 --runtime
|
||||
```
|
||||
|
||||
Then just include the runtime before your generated code.
|
||||
|
||||
## Getting the runtime
|
||||
|
||||
You can get the runtime via either:
|
||||
|
||||
```sh
|
||||
$ 6to5-runtime
|
||||
```
|
||||
|
||||
or
|
||||
|
||||
```javascript
|
||||
require("6to5").runtime();
|
||||
```
|
||||
|
||||
or from an npm release in `runtime.js` from the 6to5 directory.
|
||||
|
||||
## Customising namespace
|
||||
|
||||
You can also customise the runtime namespace by passing an optional namespace
|
||||
argument:
|
||||
|
||||
```javascript
|
||||
require("6to5").runtime("myCustomNamespace");
|
||||
```
|
||||
|
||||
```sh
|
||||
$ 6to5-runtime myCustomNamespace
|
||||
```
|
||||
|
||||
See [Options - runtime](usage.md#options) for documentation on changing the
|
||||
reference in generated code.
|
||||
124
doc/playground.md
Normal file
124
doc/playground.md
Normal file
@@ -0,0 +1,124 @@
|
||||
# Playground
|
||||
|
||||
Playground is a proving ground for **possible** ES7 proposals.
|
||||
|
||||
**NOTE: These features are in no way endorsed by Ecma International and are not a part of ES6. They might become a part of ECMAScript in the future.**
|
||||
|
||||
## Usage
|
||||
|
||||
$ 6to5 --playground
|
||||
|
||||
```javascript
|
||||
to5.transform("code", { playground: true });
|
||||
```
|
||||
|
||||
**NOTE:** Enabling `playground` also enables [experimental support](experimental.md).
|
||||
|
||||
## Features
|
||||
|
||||
* [Memoization operator](#memoization-operator)
|
||||
* [Method binding](#method-binding)
|
||||
* [Object getter memoization](#object-getter-memoization)
|
||||
* [This shorthand](#this-shorthand)
|
||||
|
||||
### Memoization assignment operator
|
||||
|
||||
```javascript
|
||||
var obj = {};
|
||||
obj.x ?= 2;
|
||||
obj.x; // 2
|
||||
|
||||
obj = { x: 1 };
|
||||
obj.x ?= 2;
|
||||
obj.x; // 1
|
||||
|
||||
obj = { x: undefined }
|
||||
obj.x ?= 2;
|
||||
obj.x; // undefined
|
||||
```
|
||||
|
||||
```javascript
|
||||
var obj = {};
|
||||
obj.x ?= 2;
|
||||
```
|
||||
|
||||
equivalent to:
|
||||
|
||||
```javascript
|
||||
var obj = {};
|
||||
if (!Object.prototype.hasOwnProperty.call(obj, "x")) obj.x = 2;
|
||||
```
|
||||
|
||||
### Method binding
|
||||
|
||||
```javascript
|
||||
var fn = obj#method;
|
||||
var fn = obj#method("foob");
|
||||
|
||||
["foo", "bar"].map(#toUpperCase); // ["FOO", "BAR"]
|
||||
[1.1234, 23.53245, 3].map(#toFixed(2)); // ["1.12", "23.53", "3.00"]
|
||||
```
|
||||
|
||||
equivalent to:
|
||||
|
||||
```javascript
|
||||
var fn = obj.method.bind(obj);
|
||||
var fn = obj.method.bind(obj, "foob");
|
||||
|
||||
["foo", "bar"].map(function (val) { return val.toUpperCase(); });
|
||||
[1.1234, 23.53245, 3].map(function (val) { return val.toFixed(2); });
|
||||
```
|
||||
|
||||
### Object getter memoization
|
||||
|
||||
```javascript
|
||||
var foo = {
|
||||
memo bar() {
|
||||
return complex();
|
||||
}
|
||||
};
|
||||
|
||||
class Foo {
|
||||
memo bar() {
|
||||
return complex();
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
equivalent to
|
||||
|
||||
```javascript
|
||||
var foo = {
|
||||
get bar() {
|
||||
return Object.defineProperty(this, "bar", {
|
||||
value: complex(),
|
||||
enumerable: true,
|
||||
configurable: true,
|
||||
writable: true
|
||||
}).bar;
|
||||
}
|
||||
};
|
||||
|
||||
class Foo {
|
||||
get bar() {
|
||||
return Object.defineProperty(this, "bar", {
|
||||
value: complex(),
|
||||
enumerable: true,
|
||||
configurable: true,
|
||||
writable: true
|
||||
}).bar;
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### This shorthand
|
||||
|
||||
```javascript
|
||||
@foo
|
||||
```
|
||||
|
||||
equivalent to
|
||||
|
||||
```javascirpt
|
||||
this.foo
|
||||
```
|
||||
33
doc/plugins.md
Normal file
33
doc/plugins.md
Normal file
@@ -0,0 +1,33 @@
|
||||
# Plugins
|
||||
|
||||
## Build systems
|
||||
|
||||
- [Broccoli](https://github.com/6to5/broccoli-6to5-transpiler)
|
||||
- [Browserify](https://github.com/6to5/6to5ify)
|
||||
- [Brunch](https://github.com/6to5/6to5-brunch)
|
||||
- [Duo](https://github.com/6to5/duo6to5)
|
||||
- [Gobble](https://github.com/6to5/gobble-6to5)
|
||||
- [Gulp](https://github.com/6to5/gulp-6to5)
|
||||
- [Grunt](https://github.com/6to5/grunt-6to5)
|
||||
- [Sprockets](https://github.com/josh/sprockets-es6) or via [Browserify](https://github.com/6to5/6to5-rails)
|
||||
- [webpack](https://github.com/6to5/6to5-loader)
|
||||
|
||||
## Integrations
|
||||
|
||||
- [Isparta](https://github.com/douglasduteil/isparta) - Code coverage with `karma` and `instanbul` using 6to5
|
||||
- [JSXHint](https://github.com/STRML/JSXHint) - A wrapper around JSHint to allow linting of JSX files
|
||||
|
||||
## Bridges
|
||||
|
||||
- [Ruby](https://github.com/6to5/6to5-ruby)
|
||||
|
||||
## Testing
|
||||
|
||||
- [Jest](https://github.com/6to5/6to5-jest)
|
||||
- [Karma](https://github.com/6to5/karma-6to5-preprocessor)
|
||||
- [Mocha](https://github.com/6to5/6to5-mocha)
|
||||
|
||||
## Misc
|
||||
|
||||
- [Connect](https://github.com/6to5/6to5-connect)
|
||||
- [Jade](https://github.com/6to5/jade-6to5)
|
||||
34
doc/polyfill.md
Normal file
34
doc/polyfill.md
Normal file
@@ -0,0 +1,34 @@
|
||||
# Polyfill
|
||||
|
||||
6to5 includes a polyfill that includes a custom
|
||||
[regenerator runtime](https://github.com/facebook/regenerator/blob/master/runtime.js) and
|
||||
[core.js](https://github.com/zloirock/core-js).
|
||||
|
||||
This will emulate a full ES6 environment. This polyfill is automatically loaded
|
||||
when using [6to5-node](usage.md#node) and [6to5/register](usage.md#register-hook).
|
||||
|
||||
## Usage
|
||||
|
||||
### Node/Browserify
|
||||
|
||||
You need to include the polyfill require at the top the **entry point** to your
|
||||
application.
|
||||
|
||||
```javascript
|
||||
require("6to5/polyfill");
|
||||
```
|
||||
|
||||
Fortunately, this is automatically loaded when using:
|
||||
|
||||
```javascript
|
||||
require("6to5/register");
|
||||
```
|
||||
|
||||
### Browser
|
||||
|
||||
Available from the `browser-polyfill.js` file within the 6to5 directory of an
|
||||
npm release. This needs to be included **before** all your compiled 6to5 code.
|
||||
You can either prepend it to your compiled code or include it in a `<script>`
|
||||
before it.
|
||||
|
||||
**NOTE:** Do not `require` this via browserify etc, use `6to5/polyfill`.
|
||||
17
doc/react.md
Normal file
17
doc/react.md
Normal file
@@ -0,0 +1,17 @@
|
||||
# React/JSX
|
||||
|
||||
6to5 has built-in support for React v0.12. Tags are automatically transformed to
|
||||
their equivalent `React.createElement(...)` and `displayName` is automatically
|
||||
inferred and added to all `React.createClass` calls.
|
||||
|
||||
## Blacklist
|
||||
|
||||
To disable this behaviour add `react` to your blacklist:
|
||||
|
||||
```javascript
|
||||
to5.transform("code", { blacklist: ["react"] });
|
||||
```
|
||||
|
||||
```sh
|
||||
$ 6to5 --blacklist react
|
||||
```
|
||||
259
doc/usage.md
Normal file
259
doc/usage.md
Normal file
@@ -0,0 +1,259 @@
|
||||
# Usage
|
||||
|
||||
## CLI
|
||||
|
||||
Compile the file `script.js` and output it to stdout.
|
||||
|
||||
```sh
|
||||
$ 6to5 script.js
|
||||
```
|
||||
|
||||
Compile the file `script.js` and output it to `script-compiled.js`.
|
||||
|
||||
```sh
|
||||
$ 6to5 script.js --out-file script-compiled.js
|
||||
```
|
||||
|
||||
Compile the file `script.js` and output it to `script-compiled.js` and save a
|
||||
source map to `script-compiled.js.map`.
|
||||
|
||||
```sh
|
||||
$ 6to5 script.js --source-maps --out-file script-compiled.js
|
||||
```
|
||||
|
||||
Compile the file `script.js` and output it to `script-compiled.js` with a source
|
||||
map embedded in a comment at the bottom.
|
||||
|
||||
```sh
|
||||
$ 6to5 script.js --source-maps-inline --out-file script-compiled.js
|
||||
```
|
||||
|
||||
Compile the entire `src` directory and output it to the `lib` directory.
|
||||
|
||||
```sh
|
||||
$ 6to5 src --out-dir lib
|
||||
```
|
||||
|
||||
Compile the entire `src` directory and output it to the one concatenated file.
|
||||
|
||||
```sh
|
||||
$ 6to5 src --out-file script-compiled.js
|
||||
```
|
||||
|
||||
Pipe a file in via stdin and output it to `script-compiled.js`
|
||||
|
||||
```sh
|
||||
$ 6to5 --out-file script-compiled.js < script.js
|
||||
```
|
||||
|
||||
### Node
|
||||
|
||||
Launch a repl.
|
||||
|
||||
```sh
|
||||
$ 6to5-node
|
||||
```
|
||||
|
||||
Evaluate code.
|
||||
|
||||
```sh
|
||||
$ 6to5-node -e "class Test { }"
|
||||
```
|
||||
|
||||
Compile and run `test.js`.
|
||||
|
||||
```sh
|
||||
$ 6to5-node test
|
||||
```
|
||||
|
||||
## Node
|
||||
|
||||
```javascript
|
||||
var to5 = require("6to5");
|
||||
```
|
||||
|
||||
### to5.transform(code, [opts]);
|
||||
|
||||
```javascript
|
||||
var result = to5.transform("code();", options);
|
||||
result.code;
|
||||
result.map;
|
||||
result.ast;
|
||||
```
|
||||
|
||||
### to5.transformFileSync(filename, [opts])
|
||||
|
||||
```javascript
|
||||
to5.transformFileSync("filename.js", options).code;
|
||||
```
|
||||
|
||||
### to5.transformFile(filename, [opts], callback)
|
||||
|
||||
```javascript
|
||||
to5.transformFile("filename.js", options, function (err, result) {
|
||||
result.code;
|
||||
});
|
||||
```
|
||||
|
||||
### to5.transform.fromAst(ast, [code], [opts])
|
||||
|
||||
```javascript
|
||||
var result = to5.transform.fromAst(ast, "var a = 2;", opts);
|
||||
result.code;
|
||||
result.map;
|
||||
result.ast;
|
||||
```
|
||||
|
||||
#### Options
|
||||
|
||||
```javascript
|
||||
{
|
||||
// Filename for use in errors etc.
|
||||
// Default: "unknown"
|
||||
filename: "filename",
|
||||
|
||||
// Filename relative to `sourceRoot`
|
||||
// Default: `filename` option.
|
||||
filenameRelative: "",
|
||||
|
||||
// List of transformers to EXCLUDE.
|
||||
// Run `6to5 --help` to see a full list of transformers.
|
||||
blacklist: [],
|
||||
|
||||
// List of transformers to ONLY use.
|
||||
// Run `6to5 --help` to see a full list of transformers.
|
||||
whitelist: [],
|
||||
|
||||
// Module formatter to use
|
||||
// Run `6to5 --help` to see a full list of module formatters.
|
||||
// Default: "common"
|
||||
modules: "common",
|
||||
|
||||
// If truthy, adds a `map` property to returned output.
|
||||
// If set to "inline", a comment with a sourceMappingURL directive is added to
|
||||
// the bottom of the returned code.
|
||||
// Default: false
|
||||
sourceMap: true,
|
||||
|
||||
// Set `file` on returned source map.
|
||||
// Default: `filenameRelative` option.
|
||||
sourceMapName: "filename",
|
||||
|
||||
// Set `sources[0]` on returned source map.
|
||||
// Default: `filenameRelative` option.
|
||||
sourceFileName: "filename",
|
||||
|
||||
// The root from which all sources are relative
|
||||
// Default: `moduleRoot` option.
|
||||
sourceRoot: "assets/scripts",
|
||||
|
||||
// Optional prefix for the AMD module formatter that will be prepend to the
|
||||
// filename on module definitions
|
||||
// Default: `sourceRoot` option.
|
||||
moduleRoot: "my-app",
|
||||
|
||||
// If truthy, insert an explicit id for each defined AMD/System module.
|
||||
// By default, AMD/System modules are anonymous.
|
||||
// Default: false
|
||||
moduleIds: true,
|
||||
|
||||
// Optionally replace all 6to5 helper declarations with a referenece to this
|
||||
// variable. If set to `true` then the default namespace is used "to5Runtime".
|
||||
// Default: false
|
||||
runtime: true,
|
||||
|
||||
// Enable support for experimental ES7 features
|
||||
// Default: false
|
||||
experimental: true,
|
||||
|
||||
// Set this to `false` if you don't want the transformed AST in the returned
|
||||
// result
|
||||
// Default: true
|
||||
ast: true,
|
||||
|
||||
// Set this to `false` if you don't want the transformed code in the returned
|
||||
// result
|
||||
// Default: true
|
||||
code: true,
|
||||
|
||||
format: {
|
||||
// Output comments in generated output
|
||||
// Default: true
|
||||
comments: true,
|
||||
|
||||
// Do not include superfluous whitespace characters and line terminators
|
||||
// Default: false
|
||||
compact: false,
|
||||
|
||||
indent: {
|
||||
// Preserve parentheses in new expressions that have no arguments
|
||||
// Default: true
|
||||
parentheses: true,
|
||||
|
||||
// Adjust the indentation of multiline comments to keep asterisks vertically aligned
|
||||
// Default: true
|
||||
adjustMultilineComment: true,
|
||||
|
||||
// Indent string
|
||||
// Default: " "
|
||||
style: " ",
|
||||
|
||||
// Base indent level
|
||||
// Default: 0
|
||||
base: 0
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### Require hook
|
||||
|
||||
All subsequent files required by node with the extensions `.es6` and `.js` will
|
||||
be transformed by 6to5. The polyfill specified in [Polyfill](polyfill.md) is
|
||||
also required; but this is automatically loaded when using:
|
||||
|
||||
Source maps are automatically configured so if any errors a thrown then line
|
||||
number info is mapped and you'll get the correct source location.
|
||||
|
||||
```javascript
|
||||
require("6to5/register");
|
||||
```
|
||||
|
||||
**NOTE:** By default all requires to `node_modules` will be ignored. You can
|
||||
override this by passing an ignore regex via:
|
||||
|
||||
```javascript
|
||||
require("6to5/register")({
|
||||
// This will override `node_modules` ignoring - you can alternatively pass
|
||||
// a regex
|
||||
ignore: false
|
||||
});
|
||||
```
|
||||
|
||||
**NOTE:** Using 6to5-node or `require("6to5/register")`, 6to5 will check what features are available in the current environment and blacklists them if they're supported.
|
||||
|
||||
#### Options
|
||||
|
||||
```javascript
|
||||
require("6to5/register")({
|
||||
// Optional ignore regex - if any filenames **do** match this regex then they
|
||||
// aren't compiled
|
||||
ignore: /regex/,
|
||||
|
||||
// Optional only regex - if any filenames **don't** match this regex then they
|
||||
// aren't compiled
|
||||
only: /my_es6_folder/,
|
||||
|
||||
// See options above for usage
|
||||
whitelist: [],
|
||||
blacklist: [],
|
||||
|
||||
// This will remove the currently hooked extensions of .es6 and .js so you'll
|
||||
// have to add them back if you want them to be used again.
|
||||
extensions: [".js", ".es6"],
|
||||
|
||||
// Enables `roadrunner` cache that will save to a `.roadrunner.json` file in your cwd
|
||||
// Do not check this into git as it's user-specific
|
||||
cache: true
|
||||
});
|
||||
```
|
||||
80
lib/6to5/browser.js
Normal file
80
lib/6to5/browser.js
Normal file
@@ -0,0 +1,80 @@
|
||||
var transform = module.exports = require("./transformation/transform");
|
||||
|
||||
transform.transform = transform;
|
||||
|
||||
transform.run = function (code, opts) {
|
||||
opts = opts || {};
|
||||
opts.sourceMap = "inline";
|
||||
return new Function(transform(code, opts).code)();
|
||||
};
|
||||
|
||||
transform.load = function (url, callback, opts, hold) {
|
||||
opts = opts || {};
|
||||
opts.filename = opts.filename || url;
|
||||
|
||||
var xhr = global.ActiveXObject ? new global.ActiveXObject("Microsoft.XMLHTTP") : new global.XMLHttpRequest();
|
||||
xhr.open("GET", url, true);
|
||||
if ("overrideMimeType" in xhr) xhr.overrideMimeType("text/plain");
|
||||
|
||||
xhr.onreadystatechange = function () {
|
||||
if (xhr.readyState !== 4) return;
|
||||
|
||||
var status = xhr.status;
|
||||
if (status === 0 || status === 200) {
|
||||
var param = [xhr.responseText, opts];
|
||||
if (!hold) transform.run.apply(transform, param);
|
||||
if (callback) callback(param);
|
||||
} else {
|
||||
throw new Error("Could not load " + url);
|
||||
}
|
||||
};
|
||||
|
||||
xhr.send(null);
|
||||
};
|
||||
|
||||
var runScripts = function () {
|
||||
var scripts = [];
|
||||
var types = ["text/ecmascript-6", "text/6to5"];
|
||||
var index = 0;
|
||||
|
||||
var exec = function () {
|
||||
var param = scripts[index];
|
||||
if (param instanceof Array) {
|
||||
transform.run.apply(transform, param);
|
||||
index++;
|
||||
exec();
|
||||
}
|
||||
};
|
||||
|
||||
var run = function (script, i) {
|
||||
var opts = {};
|
||||
|
||||
if (script.src) {
|
||||
transform.load(script.src, function (param) {
|
||||
scripts[i] = param;
|
||||
exec();
|
||||
}, opts, true);
|
||||
} else {
|
||||
opts.filename = "embedded";
|
||||
scripts[i] = [script.innerHTML, opts];
|
||||
}
|
||||
};
|
||||
|
||||
var _scripts = global.document.getElementsByTagName("script");
|
||||
for (var i in _scripts) {
|
||||
var _script = _scripts[i];
|
||||
if (types.indexOf(_script.type) >= 0) scripts.push(_script);
|
||||
}
|
||||
|
||||
for (i in scripts) {
|
||||
run(scripts[i], i);
|
||||
}
|
||||
|
||||
exec();
|
||||
};
|
||||
|
||||
if (global.addEventListener) {
|
||||
global.addEventListener("DOMContentLoaded", runScripts, false);
|
||||
} else if (global.attachEvent) {
|
||||
global.attachEvent("onload", runScripts);
|
||||
}
|
||||
259
lib/6to5/file.js
259
lib/6to5/file.js
@@ -2,41 +2,145 @@ module.exports = File;
|
||||
|
||||
var SHEBANG_REGEX = /^\#\!.*/;
|
||||
|
||||
var transform = require("./transform");
|
||||
var recast = require("recast");
|
||||
var transform = require("./transformation/transform");
|
||||
var generate = require("./generation/generator");
|
||||
var Scope = require("./traverse/scope");
|
||||
var util = require("./util");
|
||||
var b = require("recast").types.builders;
|
||||
var t = require("./types");
|
||||
var _ = require("lodash");
|
||||
|
||||
function File(opts) {
|
||||
this.declarations = {};
|
||||
this.uids = {};
|
||||
this.opts = File.normaliseOptions(opts);
|
||||
this.transformers = this.getTransformers();
|
||||
this.uids = {};
|
||||
this.ast = {};
|
||||
}
|
||||
|
||||
File.declarations = [
|
||||
"inherits",
|
||||
"prototype-properties",
|
||||
"apply-constructor",
|
||||
"tagged-template-literal",
|
||||
"interop-require",
|
||||
"to-array",
|
||||
"sliced-to-array",
|
||||
"object-without-properties",
|
||||
"has-own",
|
||||
"slice",
|
||||
"define-property",
|
||||
"async-to-generator"
|
||||
];
|
||||
|
||||
File.excludeDeclarationsFromRuntime = [
|
||||
"async-to-generator"
|
||||
];
|
||||
|
||||
File.normaliseOptions = function (opts) {
|
||||
opts = opts || {};
|
||||
opts = _.cloneDeep(opts || {});
|
||||
|
||||
_.defaults(opts, {
|
||||
blacklist: [],
|
||||
whitelist: [],
|
||||
sourceMap: false,
|
||||
filename: "unknown",
|
||||
format: {}
|
||||
experimental: false,
|
||||
playground: false,
|
||||
whitespace: true,
|
||||
moduleIds: opts.amdModuleIds || false,
|
||||
blacklist: [],
|
||||
whitelist: [],
|
||||
sourceMap: false,
|
||||
optional: [],
|
||||
comments: true,
|
||||
filename: "unknown",
|
||||
modules: "common",
|
||||
runtime: false,
|
||||
code: true,
|
||||
ast: true
|
||||
});
|
||||
|
||||
// normalise windows path separators to unix
|
||||
opts.filename = opts.filename.replace(/\\/g, "/");
|
||||
|
||||
opts.blacklist = util.arrayify(opts.blacklist);
|
||||
opts.whitelist = util.arrayify(opts.whitelist);
|
||||
|
||||
_.defaults(opts, {
|
||||
moduleRoot: opts.sourceRoot
|
||||
});
|
||||
|
||||
_.defaults(opts, {
|
||||
sourceFileName: opts.filename,
|
||||
sourceMapName: opts.filename
|
||||
sourceRoot: opts.moduleRoot
|
||||
});
|
||||
|
||||
_.defaults(opts, {
|
||||
filenameRelative: opts.filename
|
||||
});
|
||||
|
||||
_.defaults(opts, {
|
||||
sourceFileName: opts.filenameRelative,
|
||||
sourceMapName: opts.filenameRelative
|
||||
});
|
||||
|
||||
if (opts.runtime === true) {
|
||||
opts.runtime = "to5Runtime";
|
||||
}
|
||||
|
||||
if (opts.playground) {
|
||||
opts.experimental = true;
|
||||
}
|
||||
|
||||
transform._ensureTransformerNames("blacklist", opts.blacklist);
|
||||
transform._ensureTransformerNames("whitelist", opts.whitelist);
|
||||
transform._ensureTransformerNames("optional", opts.optional);
|
||||
|
||||
return opts;
|
||||
};
|
||||
|
||||
File.prototype.getTransformers = function () {
|
||||
var file = this;
|
||||
var transformers = [];
|
||||
|
||||
_.each(transform.transformers, function (transformer) {
|
||||
if (transformer.canRun(file)) {
|
||||
transformers.push(transformer);
|
||||
|
||||
if (transformer.manipulateOptions) {
|
||||
transformer.manipulateOptions(file.opts, file);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
return transformers;
|
||||
};
|
||||
|
||||
File.prototype.toArray = function (node, i) {
|
||||
if (t.isArrayExpression(node)) {
|
||||
return node;
|
||||
} else if (t.isIdentifier(node) && node.name === "arguments") {
|
||||
return t.callExpression(t.memberExpression(this.addDeclaration("slice"), t.identifier("call")), [node]);
|
||||
} else {
|
||||
var declarationName = "to-array";
|
||||
var args = [node];
|
||||
if (i) {
|
||||
args.push(t.literal(i));
|
||||
declarationName = "sliced-to-array";
|
||||
}
|
||||
return t.callExpression(this.addDeclaration(declarationName), args);
|
||||
}
|
||||
};
|
||||
|
||||
File.prototype.getModuleFormatter = function (type) {
|
||||
var ModuleFormatter = _.isFunction(type) ? type : transform.moduleFormatters[type];
|
||||
|
||||
if (!ModuleFormatter) {
|
||||
var loc = util.resolve(type);
|
||||
if (loc) ModuleFormatter = require(loc);
|
||||
}
|
||||
|
||||
if (!ModuleFormatter) {
|
||||
throw new ReferenceError("Unknown module formatter type " + JSON.stringify(type));
|
||||
}
|
||||
|
||||
return new ModuleFormatter(this);
|
||||
};
|
||||
|
||||
File.prototype.parseShebang = function (code) {
|
||||
var shebangMatch = code.match(SHEBANG_REGEX);
|
||||
if (shebangMatch) {
|
||||
@@ -49,77 +153,134 @@ File.prototype.parseShebang = function (code) {
|
||||
return code;
|
||||
};
|
||||
|
||||
File.prototype.addDeclaration = function (name) {
|
||||
var declar = this.declarations[name];
|
||||
if (declar) return declar.uid;
|
||||
File.prototype.addImport = function (id, source) {
|
||||
var specifiers = [t.importSpecifier(t.identifier("default"), id)];
|
||||
var declar = t.importDeclaration(specifiers, t.literal(source));
|
||||
this.ast.program.body.unshift(declar);
|
||||
};
|
||||
|
||||
var uid = b.identifier(this.generateUid(name));
|
||||
this.declarations[name] = {
|
||||
uid: uid,
|
||||
node: util.template(name)
|
||||
};
|
||||
File.prototype.addDeclaration = function (name) {
|
||||
if (!_.contains(File.declarations, name)) {
|
||||
throw new ReferenceError("unknown declaration " + name);
|
||||
}
|
||||
|
||||
var program = this.ast.program;
|
||||
|
||||
var declar = program._declarations && program._declarations[name];
|
||||
if (declar) return declar.id;
|
||||
|
||||
var ref;
|
||||
var runtimeNamespace = this.opts.runtime;
|
||||
if (runtimeNamespace && !_.contains(File.excludeDeclarationsFromRuntime, name)) {
|
||||
name = t.identifier(t.toIdentifier(name));
|
||||
return t.memberExpression(t.identifier(runtimeNamespace), name);
|
||||
} else {
|
||||
ref = util.template(name);
|
||||
}
|
||||
|
||||
var uid = this.generateUidIdentifier(name);
|
||||
this.scope.push({
|
||||
key: name,
|
||||
id: uid,
|
||||
init: ref
|
||||
});
|
||||
return uid;
|
||||
};
|
||||
|
||||
File.prototype.errorWithNode = function (node, msg, Error) {
|
||||
Error = Error || SyntaxError;
|
||||
|
||||
var loc = node.loc.start;
|
||||
var err = new Error("Line " + loc.line + ": " + msg);
|
||||
err.loc = loc;
|
||||
return err;
|
||||
};
|
||||
|
||||
File.prototype.addCode = function (code) {
|
||||
code = (code || "") + "";
|
||||
this.code = code;
|
||||
return this.parseShebang(code);
|
||||
};
|
||||
|
||||
File.prototype.parse = function (code) {
|
||||
var self = this;
|
||||
|
||||
code = this.parseShebang(code);
|
||||
code = this.addCode(code);
|
||||
|
||||
return util.parse(this.opts, code, function (tree) {
|
||||
return self.transform(tree);
|
||||
self.transform(tree);
|
||||
return self.generate();
|
||||
});
|
||||
};
|
||||
|
||||
File.prototype.transform = function (ast) {
|
||||
this.ast = ast;
|
||||
|
||||
var self = this;
|
||||
|
||||
_.each(transform.transformers, function (transformer) {
|
||||
this.ast = ast;
|
||||
this.scope = new Scope(ast.program);
|
||||
this.moduleFormatter = this.getModuleFormatter(this.opts.modules);
|
||||
|
||||
var astRun = function (key) {
|
||||
_.each(self.transformers, function (transformer) {
|
||||
transformer.astRun(self, key);
|
||||
});
|
||||
};
|
||||
|
||||
astRun("enter");
|
||||
|
||||
_.each(this.transformers, function (transformer) {
|
||||
transformer.transform(self);
|
||||
});
|
||||
|
||||
var body = ast.program.body;
|
||||
|
||||
_.each(this.declarations, function (declar) {
|
||||
body.unshift(b.variableDeclaration("var", [
|
||||
b.variableDeclarator(declar.uid, declar.node)
|
||||
]));
|
||||
});
|
||||
|
||||
return this.generate();
|
||||
astRun("exit");
|
||||
};
|
||||
|
||||
File.prototype.generate = function () {
|
||||
var opts = this.opts;
|
||||
var ast = this.ast;
|
||||
|
||||
var printOpts = {};
|
||||
if (opts.sourceMap) {
|
||||
printOpts.sourceMapName = opts.sourceMapName;
|
||||
}
|
||||
var result = {
|
||||
code: "",
|
||||
map: null,
|
||||
ast: null
|
||||
};
|
||||
|
||||
var result = recast.print(ast, printOpts);
|
||||
var code = result.code;
|
||||
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
|
||||
code = this.shebang + code;
|
||||
result.code = this.shebang + "\n" + result.code;
|
||||
}
|
||||
|
||||
if (opts.sourceMap === "inline") {
|
||||
code += "\n" + util.sourceMapToComment(result.map);
|
||||
result.code += "\n" + util.sourceMapToComment(result.map);
|
||||
}
|
||||
|
||||
return {
|
||||
code: code,
|
||||
map: result.map || null,
|
||||
ast: ast
|
||||
};
|
||||
return result;
|
||||
};
|
||||
|
||||
File.prototype.generateUid = function (name) {
|
||||
File.prototype.generateUid = function (name, scope) {
|
||||
name = t.toIdentifier(name);
|
||||
|
||||
scope = scope || this.scope;
|
||||
|
||||
var uid;
|
||||
do {
|
||||
uid = this._generateUid(name);
|
||||
} while (scope.has(uid));
|
||||
return uid;
|
||||
};
|
||||
|
||||
File.prototype.generateUidIdentifier = function (name, scope) {
|
||||
return t.identifier(this.generateUid(name, scope));
|
||||
};
|
||||
|
||||
File.prototype._generateUid = function (name) {
|
||||
var uids = this.uids;
|
||||
var i = uids[name] || 1;
|
||||
|
||||
|
||||
127
lib/6to5/generation/buffer.js
Normal file
127
lib/6to5/generation/buffer.js
Normal file
@@ -0,0 +1,127 @@
|
||||
module.exports = Buffer;
|
||||
|
||||
var util = require("../util");
|
||||
var _ = require("lodash");
|
||||
|
||||
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) {
|
||||
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.push(" ");
|
||||
};
|
||||
|
||||
Buffer.prototype.space = function () {
|
||||
if (this.buf && !this.isLast([" ", "\n"])) {
|
||||
this.push(" ");
|
||||
}
|
||||
};
|
||||
|
||||
Buffer.prototype.removeLast = function (cha) {
|
||||
if (!this.isLast(cha)) return;
|
||||
|
||||
this.buf = this.buf.slice(0, -1);
|
||||
this.position.unshift(cha);
|
||||
};
|
||||
|
||||
Buffer.prototype.newline = function (i, removeLast) {
|
||||
if (this.format.compact) return;
|
||||
|
||||
if (_.isBoolean(i)) {
|
||||
removeLast = i;
|
||||
i = null;
|
||||
}
|
||||
|
||||
if (_.isNumber(i)) {
|
||||
if (this.endsWith("{\n")) i--;
|
||||
if (this.endsWith(util.repeat(i, "\n"))) return;
|
||||
|
||||
var self = this;
|
||||
_.times(i, function () {
|
||||
self.newline(null, removeLast);
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
if (removeLast && this.isLast("\n")) this.removeLast("\n");
|
||||
|
||||
this.removeLast(" ");
|
||||
|
||||
// remove whitespace if last character was a newline
|
||||
this.buf = this.buf.replace(/\n +$/, "\n");
|
||||
|
||||
this._push("\n");
|
||||
};
|
||||
|
||||
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) {
|
||||
return this.buf.slice(-str.length) === str;
|
||||
};
|
||||
|
||||
Buffer.prototype.isLast = function (cha, trimRight) {
|
||||
var buf = this.buf;
|
||||
if (trimRight) buf = util.trimRight(buf);
|
||||
|
||||
var chars = [].concat(cha);
|
||||
return _.contains(chars, _.last(buf));
|
||||
};
|
||||
320
lib/6to5/generation/generator.js
Normal file
320
lib/6to5/generation/generator.js
Normal file
@@ -0,0 +1,320 @@
|
||||
module.exports = function (ast, opts, code) {
|
||||
var gen = new CodeGenerator(ast, opts, code);
|
||||
return gen.generate();
|
||||
};
|
||||
|
||||
module.exports.CodeGenerator = CodeGenerator;
|
||||
|
||||
var Whitespace = require("./whitespace");
|
||||
var SourceMap = require("./source-map");
|
||||
var Position = require("./position");
|
||||
var Buffer = require("./buffer");
|
||||
var util = require("../util");
|
||||
var n = require("./node");
|
||||
var t = require("../types");
|
||||
var _ = require("lodash");
|
||||
|
||||
function CodeGenerator(ast, opts, code) {
|
||||
opts = opts || {};
|
||||
|
||||
this.comments = ast.comments || [];
|
||||
this.tokens = ast.tokens || [];
|
||||
this.format = CodeGenerator.normaliseOptions(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.normaliseOptions = function (opts) {
|
||||
return _.merge({
|
||||
parentheses: true,
|
||||
comments: opts.comments == null || opts.comments,
|
||||
compact: false,
|
||||
indent: {
|
||||
adjustMultilineComment: true,
|
||||
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.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 "";
|
||||
|
||||
var self = this;
|
||||
|
||||
opts = opts || {};
|
||||
|
||||
var newline = function (leading) {
|
||||
if (!opts.statement && !n.isUserWhitespacable(node, parent)) {
|
||||
return;
|
||||
}
|
||||
|
||||
var lines = 0;
|
||||
|
||||
if (node.start != null) {
|
||||
// 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 needsCommentParens = t.isExpression(node) && node.leadingComments && node.leadingComments.length;
|
||||
var needsParens = needsCommentParens || n.needsParens(node, parent);
|
||||
|
||||
if (needsParens) this.push("(");
|
||||
if (needsCommentParens) 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 (needsCommentParens) {
|
||||
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));
|
||||
}
|
||||
};
|
||||
|
||||
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) {
|
||||
// find the original comment in the ast and set it as displayed
|
||||
_.each(self.ast.comments, function (origComment) {
|
||||
if (origComment.start === comment.start) {
|
||||
origComment._displayed = true;
|
||||
return false;
|
||||
}
|
||||
});
|
||||
|
||||
// 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));
|
||||
});
|
||||
};
|
||||
19
lib/6to5/generation/generators/base.js
Normal file
19
lib/6to5/generation/generators/base.js
Normal file
@@ -0,0 +1,19 @@
|
||||
exports.File = function (node, print) {
|
||||
print(node.program);
|
||||
};
|
||||
|
||||
exports.Program = function (node, print) {
|
||||
print.sequence(node.body);
|
||||
};
|
||||
|
||||
exports.BlockStatement = function (node, print) {
|
||||
if (node.body.length === 0) {
|
||||
this.push("{}");
|
||||
} else {
|
||||
this.push("{");
|
||||
this.newline();
|
||||
print.sequence(node.body, { indent: true });
|
||||
this.removeLast("\n");
|
||||
this.rightBrace();
|
||||
}
|
||||
};
|
||||
40
lib/6to5/generation/generators/classes.js
Normal file
40
lib/6to5/generation/generators/classes.js
Normal file
@@ -0,0 +1,40 @@
|
||||
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);
|
||||
};
|
||||
27
lib/6to5/generation/generators/comprehensions.js
Normal file
27
lib/6to5/generation/generators/comprehensions.js
Normal file
@@ -0,0 +1,27 @@
|
||||
exports.ComprehensionBlock = function (node, print) {
|
||||
this.keyword("for");
|
||||
this.push("(");
|
||||
print(node.left);
|
||||
this.push(" of ");
|
||||
print(node.right);
|
||||
this.push(")");
|
||||
};
|
||||
|
||||
exports.ComprehensionExpression = function (node, print) {
|
||||
this.push(node.generator ? "(" : "[");
|
||||
|
||||
print.join(node.blocks, { separator: " " });
|
||||
this.space();
|
||||
|
||||
if (node.filter) {
|
||||
this.keyword("if");
|
||||
this.push("(");
|
||||
print(node.filter);
|
||||
this.push(")");
|
||||
this.space();
|
||||
}
|
||||
|
||||
print(node.body);
|
||||
|
||||
this.push(node.generator ? ")" : "]");
|
||||
};
|
||||
114
lib/6to5/generation/generators/expressions.js
Normal file
114
lib/6to5/generation/generators/expressions.js
Normal file
@@ -0,0 +1,114 @@
|
||||
var util = require("../../util");
|
||||
var t = require("../../types");
|
||||
|
||||
exports.UnaryExpression = function (node, print) {
|
||||
var hasSpace = /[a-z]$/.test(node.operator);
|
||||
var arg = node.argument;
|
||||
|
||||
if (t.isUpdateExpression(arg) || t.isUnaryExpression(arg)) {
|
||||
hasSpace = true;
|
||||
}
|
||||
|
||||
if (t.isUnaryExpression(arg) && arg.operator === "!") {
|
||||
hasSpace = false;
|
||||
}
|
||||
|
||||
this.push(node.operator);
|
||||
if (hasSpace) this.space();
|
||||
print(node.argument);
|
||||
};
|
||||
|
||||
exports.UpdateExpression = function (node, print) {
|
||||
if (node.prefix) {
|
||||
this.push(node.operator);
|
||||
print(node.argument);
|
||||
} else {
|
||||
print(node.argument);
|
||||
this.push(node.operator);
|
||||
}
|
||||
};
|
||||
|
||||
exports.ConditionalExpression = function (node, print) {
|
||||
print(node.test);
|
||||
this.push(" ? ");
|
||||
print(node.consequent);
|
||||
this.push(" : ");
|
||||
print(node.alternate);
|
||||
};
|
||||
|
||||
exports.NewExpression = function (node, print) {
|
||||
this.push("new ");
|
||||
print(node.callee);
|
||||
if (node.arguments.length || this.format.parentheses) {
|
||||
this.push("(");
|
||||
print.join(node.arguments, { separator: ", " });
|
||||
this.push(")");
|
||||
}
|
||||
};
|
||||
|
||||
exports.SequenceExpression = function (node, print) {
|
||||
print.join(node.expressions, { separator: ", " });
|
||||
};
|
||||
|
||||
exports.ThisExpression = function () {
|
||||
this.push("this");
|
||||
};
|
||||
|
||||
exports.CallExpression = function (node, print) {
|
||||
print(node.callee);
|
||||
this.push("(");
|
||||
print.join(node.arguments, { separator: ", " });
|
||||
this.push(")");
|
||||
};
|
||||
|
||||
var buildYieldAwait = function (keyword) {
|
||||
return function (node, print) {
|
||||
this.push(keyword);
|
||||
if (node.delegate) this.push("*");
|
||||
if (node.argument) {
|
||||
this.space();
|
||||
print(node.argument);
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
exports.YieldExpression = buildYieldAwait("yield");
|
||||
exports.AwaitExpression = buildYieldAwait("await");
|
||||
|
||||
exports.EmptyStatement = function () {
|
||||
this.semicolon();
|
||||
};
|
||||
|
||||
exports.ExpressionStatement = function (node, print) {
|
||||
print(node.expression);
|
||||
this.semicolon();
|
||||
};
|
||||
|
||||
exports.BinaryExpression =
|
||||
exports.LogicalExpression =
|
||||
exports.AssignmentExpression = function (node, print) {
|
||||
print(node.left);
|
||||
this.push(" " + node.operator + " ");
|
||||
print(node.right);
|
||||
};
|
||||
|
||||
var SCIENTIFIC_NOTATION = /e/i;
|
||||
|
||||
exports.MemberExpression = function (node, print) {
|
||||
var obj = node.object;
|
||||
print(obj);
|
||||
|
||||
if (node.computed) {
|
||||
this.push("[");
|
||||
print(node.property);
|
||||
this.push("]");
|
||||
} else {
|
||||
// 5..toFixed(2);
|
||||
if (t.isLiteral(obj) && util.isInteger(obj.value) && !SCIENTIFIC_NOTATION.test(obj.value.toString())) {
|
||||
this.push(".");
|
||||
}
|
||||
|
||||
this.push(".");
|
||||
print(node.property);
|
||||
}
|
||||
};
|
||||
3
lib/6to5/generation/generators/flow.js
Normal file
3
lib/6to5/generation/generators/flow.js
Normal file
@@ -0,0 +1,3 @@
|
||||
exports.ClassProperty = function () {
|
||||
throw new Error("not implemented");
|
||||
};
|
||||
78
lib/6to5/generation/generators/jsx.js
Normal file
78
lib/6to5/generation/generators/jsx.js
Normal file
@@ -0,0 +1,78 @@
|
||||
var t = require("../../types");
|
||||
var _ = require("lodash");
|
||||
|
||||
exports.XJSAttribute = function (node, print) {
|
||||
print(node.name);
|
||||
if (node.value) {
|
||||
this.push("=");
|
||||
print(node.value);
|
||||
}
|
||||
};
|
||||
|
||||
exports.XJSIdentifier = function (node) {
|
||||
this.push(node.name);
|
||||
};
|
||||
|
||||
exports.XJSNamespacedName = function (node, print) {
|
||||
print(node.namespace);
|
||||
this.push(":");
|
||||
print(node.name);
|
||||
};
|
||||
|
||||
exports.XJSMemberExpression = function (node, print) {
|
||||
print(node.object);
|
||||
this.push(".");
|
||||
print(node.property);
|
||||
};
|
||||
|
||||
exports.XJSSpreadAttribute = function (node, print) {
|
||||
this.push("{...");
|
||||
print(node.argument);
|
||||
this.push("}");
|
||||
};
|
||||
|
||||
exports.XJSExpressionContainer = function (node, print) {
|
||||
this.push("{");
|
||||
print(node.expression);
|
||||
this.push("}");
|
||||
};
|
||||
|
||||
exports.XJSElement = function (node, print) {
|
||||
var self = this;
|
||||
|
||||
var open = node.openingElement;
|
||||
print(open);
|
||||
if (open.selfClosing) return;
|
||||
|
||||
this.indent();
|
||||
_.each(node.children, function (child) {
|
||||
if (t.isLiteral(child)) {
|
||||
self.push(child.value);
|
||||
} else {
|
||||
print(child);
|
||||
}
|
||||
});
|
||||
this.dedent();
|
||||
|
||||
print(node.closingElement);
|
||||
};
|
||||
|
||||
exports.XJSOpeningElement = function (node, print) {
|
||||
this.push("<");
|
||||
print(node.name);
|
||||
if (node.attributes.length > 0) {
|
||||
this.space();
|
||||
print.join(node.attributes, { separator: " " });
|
||||
}
|
||||
this.push(node.selfClosing ? " />" : ">");
|
||||
};
|
||||
|
||||
exports.XJSClosingElement = function (node, print) {
|
||||
this.push("</");
|
||||
print(node.name);
|
||||
this.push(">");
|
||||
};
|
||||
|
||||
exports.XJSEmptyExpression = function () {
|
||||
|
||||
};
|
||||
82
lib/6to5/generation/generators/methods.js
Normal file
82
lib/6to5/generation/generators/methods.js
Normal file
@@ -0,0 +1,82 @@
|
||||
var t = require("../../types");
|
||||
|
||||
exports._params = function (node, print) {
|
||||
var self = this;
|
||||
|
||||
this.push("(");
|
||||
|
||||
print.join(node.params, {
|
||||
separator: ", ",
|
||||
iterator: function (param, i) {
|
||||
var def = node.defaults && node.defaults[i];
|
||||
if (def) {
|
||||
self.push(" = ");
|
||||
print(def);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
if (node.rest) {
|
||||
if (node.params.length) {
|
||||
this.push(", ");
|
||||
}
|
||||
|
||||
this.push("...");
|
||||
print(node.rest);
|
||||
}
|
||||
|
||||
this.push(")");
|
||||
};
|
||||
|
||||
exports._method = function (node, print) {
|
||||
var value = node.value;
|
||||
var kind = node.kind;
|
||||
var key = node.key;
|
||||
|
||||
if (!kind || kind === "init") {
|
||||
if (value.generator) {
|
||||
this.push("*");
|
||||
}
|
||||
} else {
|
||||
this.push(kind + " ");
|
||||
}
|
||||
|
||||
if (value.async) this.push("async ");
|
||||
|
||||
if (node.computed) {
|
||||
this.push("[");
|
||||
print(key);
|
||||
this.push("]");
|
||||
} else {
|
||||
print(key);
|
||||
}
|
||||
|
||||
this._params(value, print);
|
||||
this.space();
|
||||
print(value.body);
|
||||
};
|
||||
|
||||
exports.FunctionDeclaration =
|
||||
exports.FunctionExpression = function (node, print) {
|
||||
if (node.async) this.push("async ");
|
||||
this.push("function");
|
||||
if (node.generator) this.push("*");
|
||||
this.space();
|
||||
if (node.id) print(node.id);
|
||||
this._params(node, print);
|
||||
this.space();
|
||||
print(node.body);
|
||||
};
|
||||
|
||||
exports.ArrowFunctionExpression = function (node, print) {
|
||||
if (node.async) this.push("async ");
|
||||
|
||||
if (node.params.length === 1 && !node.defaults.length && !node.rest && t.isIdentifier(node.params[0])) {
|
||||
print(node.params[0]);
|
||||
} else {
|
||||
this._params(node, print);
|
||||
}
|
||||
|
||||
this.push(" => ");
|
||||
print(node.body);
|
||||
};
|
||||
96
lib/6to5/generation/generators/modules.js
Normal file
96
lib/6to5/generation/generators/modules.js
Normal file
@@ -0,0 +1,96 @@
|
||||
var t = require("../../types");
|
||||
var _ = require("lodash");
|
||||
|
||||
exports.ImportSpecifier = function (node, print) {
|
||||
if (node.id && node.id.name === "default") {
|
||||
print(node.name);
|
||||
} 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 = spec.id && spec.id.name === "default";
|
||||
|
||||
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);
|
||||
};
|
||||
7
lib/6to5/generation/generators/playground.js
Normal file
7
lib/6to5/generation/generators/playground.js
Normal file
@@ -0,0 +1,7 @@
|
||||
var _ = require("lodash");
|
||||
|
||||
_.each(["BindMemberExpression", "BindFunctionExpression"], function (type) {
|
||||
exports[type] = function () {
|
||||
throw new ReferenceError("Trying to render non-standard playground node " + JSON.stringify(type));
|
||||
};
|
||||
});
|
||||
181
lib/6to5/generation/generators/statements.js
Normal file
181
lib/6to5/generation/generators/statements.js
Normal file
@@ -0,0 +1,181 @@
|
||||
var t = require("../../types");
|
||||
|
||||
exports.WithStatement = function (node, print) {
|
||||
this.keyword("with");
|
||||
this.push("(");
|
||||
print(node.object);
|
||||
this.push(")");
|
||||
print.block(node.body);
|
||||
};
|
||||
|
||||
exports.IfStatement = function (node, print) {
|
||||
this.keyword("if");
|
||||
this.push("(");
|
||||
print(node.test);
|
||||
this.push(") ");
|
||||
|
||||
print.indentOnComments(node.consequent);
|
||||
|
||||
if (node.alternate) {
|
||||
if (this.isLast("}")) this.space();
|
||||
this.keyword("else");
|
||||
print.indentOnComments(node.alternate);
|
||||
}
|
||||
};
|
||||
|
||||
exports.ForStatement = function (node, print) {
|
||||
this.keyword("for");
|
||||
this.push("(");
|
||||
|
||||
print(node.init);
|
||||
this.push(";");
|
||||
|
||||
if (node.test) {
|
||||
this.space();
|
||||
print(node.test);
|
||||
}
|
||||
this.push(";");
|
||||
|
||||
if (node.update) {
|
||||
this.space();
|
||||
print(node.update);
|
||||
}
|
||||
|
||||
this.push(")");
|
||||
print.block(node.body);
|
||||
};
|
||||
|
||||
exports.WhileStatement = function (node, print) {
|
||||
this.keyword("while");
|
||||
this.push("(");
|
||||
print(node.test);
|
||||
this.push(")");
|
||||
print.block(node.body);
|
||||
};
|
||||
|
||||
var buildForXStatement = function (op) {
|
||||
return function (node, print) {
|
||||
this.keyword("for");
|
||||
this.push("(");
|
||||
print(node.left);
|
||||
this.push(" " + op + " ");
|
||||
print(node.right);
|
||||
this.push(")");
|
||||
print.block(node.body);
|
||||
};
|
||||
};
|
||||
|
||||
exports.ForInStatement = buildForXStatement("in");
|
||||
exports.ForOfStatement = buildForXStatement("of");
|
||||
|
||||
exports.DoWhileStatement = function (node, print) {
|
||||
this.keyword("do");
|
||||
print(node.body);
|
||||
this.space();
|
||||
this.keyword("while");
|
||||
this.push("(");
|
||||
print(node.test);
|
||||
this.push(");");
|
||||
};
|
||||
|
||||
var buildLabelStatement = function (prefix, key) {
|
||||
return function (node, print) {
|
||||
this.push(prefix);
|
||||
|
||||
var label = node[key || "label"];
|
||||
if (label) {
|
||||
this.space();
|
||||
print(label);
|
||||
}
|
||||
|
||||
this.semicolon();
|
||||
};
|
||||
};
|
||||
|
||||
exports.ContinueStatement = buildLabelStatement("continue");
|
||||
exports.ReturnStatement = buildLabelStatement("return", "argument");
|
||||
exports.BreakStatement = buildLabelStatement("break");
|
||||
|
||||
exports.LabeledStatement = function (node, print) {
|
||||
print(node.label);
|
||||
this.push(": ");
|
||||
print(node.body);
|
||||
};
|
||||
|
||||
exports.TryStatement = function (node, print) {
|
||||
this.keyword("try");
|
||||
print(node.block);
|
||||
this.space();
|
||||
print(node.handler);
|
||||
if (node.finalizer) {
|
||||
this.space();
|
||||
this.push("finally ");
|
||||
print(node.finalizer);
|
||||
}
|
||||
};
|
||||
|
||||
exports.CatchClause = function (node, print) {
|
||||
this.keyword("catch");
|
||||
this.push("(");
|
||||
print(node.param);
|
||||
this.push(") ");
|
||||
print(node.body);
|
||||
};
|
||||
|
||||
exports.ThrowStatement = function (node, print) {
|
||||
this.push("throw ");
|
||||
print(node.argument);
|
||||
this.semicolon();
|
||||
};
|
||||
|
||||
exports.SwitchStatement = function (node, print) {
|
||||
this.keyword("switch");
|
||||
this.push("(");
|
||||
print(node.discriminant);
|
||||
this.push(") {");
|
||||
print.sequence(node.cases, { indent: true });
|
||||
this.push("}");
|
||||
};
|
||||
|
||||
exports.SwitchCase = function (node, print) {
|
||||
if (node.test) {
|
||||
this.push("case ");
|
||||
print(node.test);
|
||||
this.push(":");
|
||||
} else {
|
||||
this.push("default:");
|
||||
}
|
||||
|
||||
this.newline();
|
||||
print.sequence(node.consequent, { indent: true });
|
||||
};
|
||||
|
||||
exports.DebuggerStatement = function () {
|
||||
this.push("debugger;");
|
||||
};
|
||||
|
||||
exports.VariableDeclaration = function (node, print, parent) {
|
||||
this.push(node.kind + " ");
|
||||
|
||||
print.join(node.declarations, { separator: ", " });
|
||||
|
||||
if (!t.isFor(parent)) {
|
||||
this.semicolon();
|
||||
}
|
||||
};
|
||||
|
||||
exports.PrivateDeclaration = function (node, print) {
|
||||
this.push("private ");
|
||||
print.join(node.declarations, { separator: ", " });
|
||||
this.semicolon();
|
||||
};
|
||||
|
||||
exports.VariableDeclarator = function (node, print) {
|
||||
if (node.init) {
|
||||
print(node.id);
|
||||
this.push(" = ");
|
||||
print(node.init);
|
||||
} else {
|
||||
print(node.id);
|
||||
}
|
||||
};
|
||||
30
lib/6to5/generation/generators/template-literals.js
Normal file
30
lib/6to5/generation/generators/template-literals.js
Normal file
@@ -0,0 +1,30 @@
|
||||
var _ = require("lodash");
|
||||
|
||||
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("`");
|
||||
};
|
||||
100
lib/6to5/generation/generators/types.js
Normal file
100
lib/6to5/generation/generators/types.js
Normal file
@@ -0,0 +1,100 @@
|
||||
var _ = require("lodash");
|
||||
|
||||
exports.Identifier = function (node) {
|
||||
this.push(node.name);
|
||||
};
|
||||
|
||||
exports.SpreadElement =
|
||||
exports.SpreadProperty = function (node, print) {
|
||||
this.push("...");
|
||||
print(node.argument);
|
||||
};
|
||||
|
||||
exports.VirtualPropertyExpression = function (node, print) {
|
||||
print(node.object);
|
||||
this.push("::");
|
||||
print(node.property);
|
||||
};
|
||||
|
||||
exports.ObjectExpression =
|
||||
exports.ObjectPattern = function (node, print) {
|
||||
var props = node.properties;
|
||||
|
||||
if (props.length) {
|
||||
this.push("{");
|
||||
this.space();
|
||||
|
||||
print.join(props, { separator: ", ", indent: true });
|
||||
|
||||
this.space();
|
||||
this.push("}");
|
||||
} else {
|
||||
this.push("{}");
|
||||
}
|
||||
};
|
||||
|
||||
exports.Property = function (node, print) {
|
||||
if (node.method || node.kind === "get" || node.kind === "set") {
|
||||
this._method(node, print);
|
||||
} else {
|
||||
if (node.computed) {
|
||||
this.push("[");
|
||||
print(node.key);
|
||||
this.push("]");
|
||||
} else {
|
||||
print(node.key);
|
||||
if (node.shorthand) return;
|
||||
}
|
||||
|
||||
this.push(": ");
|
||||
print(node.value);
|
||||
}
|
||||
};
|
||||
|
||||
exports.ArrayExpression =
|
||||
exports.ArrayPattern = function (node, print) {
|
||||
var elems = node.elements;
|
||||
var self = this;
|
||||
var len = elems.length;
|
||||
|
||||
this.push("[");
|
||||
|
||||
_.each(elems, function (elem, i) {
|
||||
if (!elem) {
|
||||
// If the array expression ends with a hole, that hole
|
||||
// will be ignored by the interpreter, but if it ends with
|
||||
// two (or more) holes, we need to write out two (or more)
|
||||
// commas so that the resulting code is interpreted with
|
||||
// both (all) of the holes.
|
||||
self.push(",");
|
||||
} else {
|
||||
if (i > 0) self.push(" ");
|
||||
print(elem);
|
||||
if (i < len - 1) self.push(",");
|
||||
}
|
||||
});
|
||||
|
||||
this.push("]");
|
||||
};
|
||||
|
||||
exports.Literal = function (node) {
|
||||
var val = node.value;
|
||||
var type = typeof val;
|
||||
|
||||
if (type === "string") {
|
||||
val = JSON.stringify(val);
|
||||
|
||||
// escape illegal js but valid json unicode characters
|
||||
val = val.replace(/[\u000A\u000D\u2028\u2029]/g, function (c) {
|
||||
return "\\u" + ("0000" + c.charCodeAt(0).toString(16)).slice(-4);
|
||||
});
|
||||
|
||||
this.push(val);
|
||||
} else if (type === "boolean" || type === "number") {
|
||||
this.push(JSON.stringify(val));
|
||||
} else if (node.regex) {
|
||||
this.push("/" + node.regex.pattern + "/" + node.regex.flags);
|
||||
} else if (val === null) {
|
||||
this.push("null");
|
||||
}
|
||||
};
|
||||
79
lib/6to5/generation/node/index.js
Normal file
79
lib/6to5/generation/node/index.js
Normal file
@@ -0,0 +1,79 @@
|
||||
module.exports = Node;
|
||||
|
||||
var whitespace = require("./whitespace");
|
||||
var parens = require("./parentheses");
|
||||
var t = require("../../types");
|
||||
var _ = require("lodash");
|
||||
|
||||
var find = function (obj, node, parent) {
|
||||
var result;
|
||||
|
||||
_.each(obj, function (fn, type) {
|
||||
if (t["is" + type](node)) {
|
||||
result = fn(node, parent);
|
||||
if (result != null) return false;
|
||||
}
|
||||
});
|
||||
|
||||
return result;
|
||||
};
|
||||
|
||||
function Node(node, parent) {
|
||||
this.parent = parent;
|
||||
this.node = node;
|
||||
}
|
||||
|
||||
Node.prototype.isUserWhitespacable = function () {
|
||||
return t.isUserWhitespacable(this.node);
|
||||
};
|
||||
|
||||
Node.prototype.needsWhitespace = function (type) {
|
||||
var parent = this.parent;
|
||||
var node = this.node;
|
||||
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.prototype.needsWhitespaceBefore = function () {
|
||||
return this.needsWhitespace("before");
|
||||
};
|
||||
|
||||
Node.prototype.needsWhitespaceAfter = function () {
|
||||
return this.needsWhitespace("after");
|
||||
};
|
||||
|
||||
Node.prototype.needsParens = function () {
|
||||
var parent = this.parent;
|
||||
var node = this.node;
|
||||
|
||||
if (!parent) return false;
|
||||
|
||||
if (t.isNewExpression(parent) && parent.callee === node) {
|
||||
return t.isCallExpression(node) || _.some(node, function (val) {
|
||||
return t.isCallExpression(val);
|
||||
});
|
||||
}
|
||||
|
||||
return find(parens, node, parent);
|
||||
};
|
||||
|
||||
_.each(Node.prototype, function (fn, key) {
|
||||
Node[key] = function (node, parent) {
|
||||
var n = new Node(node, parent);
|
||||
|
||||
var args = _.toArray(arguments).slice(2);
|
||||
return n[key].apply(n, args);
|
||||
};
|
||||
});
|
||||
143
lib/6to5/generation/node/parentheses.js
Normal file
143
lib/6to5/generation/node/parentheses.js
Normal file
@@ -0,0 +1,143 @@
|
||||
var t = require("../../types");
|
||||
var _ = require("lodash");
|
||||
|
||||
var PRECEDENCE = {};
|
||||
|
||||
_.each([
|
||||
["||"],
|
||||
["&&"],
|
||||
["|"],
|
||||
["^"],
|
||||
["&"],
|
||||
["==", "===", "!=", "!=="],
|
||||
["<", ">", "<=", ">=", "in", "instanceof"],
|
||||
[">>", "<<", ">>>"],
|
||||
["+", "-"],
|
||||
["*", "/", "%"]
|
||||
], function (tier, i) {
|
||||
_.each(tier, function (op) {
|
||||
PRECEDENCE[op] = i;
|
||||
});
|
||||
});
|
||||
|
||||
exports.Binary = function (node, parent) {
|
||||
if (t.isCallExpression(parent) && parent.callee === node) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (t.isUnaryLike(parent)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (t.isMemberExpression(parent) && parent.object === node) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (t.isBinary(parent)) {
|
||||
var parentOp = parent.operator;
|
||||
var parentPos = PRECEDENCE[parentOp];
|
||||
|
||||
var nodeOp = node.operator;
|
||||
var nodePos = PRECEDENCE[nodeOp];
|
||||
|
||||
if (parentPos > nodePos) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (parentPos === nodePos && parent.right === node) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
exports.BinaryExpression = function (node, parent) {
|
||||
if (node.operator === "in") {
|
||||
// var i = (1 in []);
|
||||
if (t.isVariableDeclarator(parent)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// for ((1 in []);;);
|
||||
if (t.isFor(parent)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
exports.SequenceExpression = function (node, parent) {
|
||||
if (t.isForStatement(parent)) {
|
||||
// Although parentheses wouldn't hurt around sequence
|
||||
// expressions in the head of for loops, traditional style
|
||||
// dictates that e.g. i++, j++ should not be wrapped with
|
||||
// parentheses.
|
||||
return false;
|
||||
}
|
||||
|
||||
if (t.isExpressionStatement(parent) && parent.expression === node) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Otherwise err on the side of overparenthesization, adding
|
||||
// explicit exceptions above if this proves overzealous.
|
||||
return true;
|
||||
};
|
||||
|
||||
exports.YieldExpression = function (node, parent) {
|
||||
return t.isBinary(parent) ||
|
||||
t.isUnaryLike(parent) ||
|
||||
t.isCallExpression(parent) ||
|
||||
t.isMemberExpression(parent) ||
|
||||
t.isNewExpression(parent) ||
|
||||
t.isConditionalExpression(parent) ||
|
||||
t.isYieldExpression(parent);
|
||||
};
|
||||
|
||||
exports.ClassExpression = function (node, parent) {
|
||||
return t.isExpressionStatement(parent);
|
||||
};
|
||||
|
||||
exports.UnaryLike = function (node, parent) {
|
||||
return t.isMemberExpression(parent) && parent.object === node;
|
||||
};
|
||||
|
||||
exports.FunctionExpression = function (node, parent) {
|
||||
// function () {};
|
||||
if (t.isExpressionStatement(parent)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// (function test() {}).name;
|
||||
if (t.isMemberExpression(parent) && parent.object === node) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// (function () {})();
|
||||
if (t.isCallExpression(parent) && parent.callee === node) {
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
exports.AssignmentExpression =
|
||||
exports.ConditionalExpression = function (node, parent) {
|
||||
if (t.isUnaryLike(parent)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (t.isBinary(parent)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (t.isCallExpression(parent) && parent.callee === node) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (t.isConditionalExpression(parent) && parent.test === node) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (t.isMemberExpression(parent) && parent.object === node) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
};
|
||||
72
lib/6to5/generation/node/whitespace.js
Normal file
72
lib/6to5/generation/node/whitespace.js
Normal file
@@ -0,0 +1,72 @@
|
||||
var _ = require("lodash");
|
||||
var t = require("../../types");
|
||||
|
||||
exports.before = {
|
||||
nodes: {
|
||||
Property: function (node, parent) {
|
||||
if (parent.properties[0] === node) {
|
||||
return 1;
|
||||
}
|
||||
},
|
||||
|
||||
SpreadProperty: function (node, parent) {
|
||||
return exports.before.nodes.Property(node, parent);
|
||||
},
|
||||
|
||||
SwitchCase: function (node, parent) {
|
||||
if (parent.cases[0] === node) {
|
||||
return 1;
|
||||
}
|
||||
},
|
||||
|
||||
CallExpression: function (node) {
|
||||
if (t.isFunction(node.callee)) {
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
exports.after = {
|
||||
nodes: {
|
||||
AssignmentExpression: function (node) {
|
||||
if (t.isFunction(node.right)) {
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
list: {
|
||||
VariableDeclaration: function (node) {
|
||||
return _.map(node.declarations, "init");
|
||||
},
|
||||
|
||||
ArrayExpression: function (node) {
|
||||
return node.elements;
|
||||
},
|
||||
|
||||
ObjectExpression: function (node) {
|
||||
return node.properties;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
_.each({
|
||||
Function: 1,
|
||||
Class: 1,
|
||||
For: 1,
|
||||
ArrayExpression: { after: 1 },
|
||||
ObjectExpression: { after: 1 },
|
||||
SwitchStatement: 1,
|
||||
IfStatement: { before: 1 },
|
||||
CallExpression: { after: 1 },
|
||||
Literal: { after: 1 }
|
||||
}, function (amounts, type) {
|
||||
if (_.isNumber(amounts)) amounts = { after: amounts, before: amounts };
|
||||
|
||||
_.each(amounts, function (amount, key) {
|
||||
exports[key].nodes[type] = function () {
|
||||
return amount;
|
||||
};
|
||||
});
|
||||
});
|
||||
33
lib/6to5/generation/position.js
Normal file
33
lib/6to5/generation/position.js
Normal file
@@ -0,0 +1,33 @@
|
||||
module.exports = Position;
|
||||
|
||||
var _ = require("lodash");
|
||||
|
||||
function Position() {
|
||||
this.line = 1;
|
||||
this.column = 0;
|
||||
}
|
||||
|
||||
Position.prototype.push = function (str) {
|
||||
var self = this;
|
||||
|
||||
_.each(str, function (cha) {
|
||||
if (cha === "\n") {
|
||||
self.line++;
|
||||
self.column = 0;
|
||||
} else {
|
||||
self.column++;
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
Position.prototype.unshift = function (str) {
|
||||
var self = this;
|
||||
|
||||
_.each(str, function (cha) {
|
||||
if (cha === "\n") {
|
||||
self.line--;
|
||||
} else {
|
||||
self.column--;
|
||||
}
|
||||
});
|
||||
};
|
||||
56
lib/6to5/generation/source-map.js
Normal file
56
lib/6to5/generation/source-map.js
Normal file
@@ -0,0 +1,56 @@
|
||||
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];
|
||||
|
||||
if (generated.line === original.line && generated.column === original.column) return; // nothing to map
|
||||
|
||||
map.addMapping({
|
||||
source: this.opts.sourceFileName,
|
||||
generated: generated,
|
||||
original: original
|
||||
});
|
||||
};
|
||||
62
lib/6to5/generation/whitespace.js
Normal file
62
lib/6to5/generation/whitespace.js
Normal file
@@ -0,0 +1,62 @@
|
||||
module.exports = Whitespace;
|
||||
|
||||
var _ = require("lodash");
|
||||
|
||||
function Whitespace(tokens, comments) {
|
||||
this.tokens = _.sortBy(tokens.concat(comments), "start");
|
||||
this.used = [];
|
||||
}
|
||||
|
||||
Whitespace.prototype.getNewlinesBefore = function (node) {
|
||||
var startToken;
|
||||
var endToken;
|
||||
var tokens = this.tokens;
|
||||
|
||||
_.each(tokens, function (token, i) {
|
||||
// this is the token this node starts with
|
||||
if (node.start === token.start) {
|
||||
startToken = tokens[i - 1];
|
||||
endToken = token;
|
||||
return false;
|
||||
}
|
||||
});
|
||||
|
||||
return this.getNewlinesBetween(startToken, endToken);
|
||||
};
|
||||
|
||||
Whitespace.prototype.getNewlinesAfter = function (node) {
|
||||
var startToken;
|
||||
var endToken;
|
||||
var tokens = this.tokens;
|
||||
|
||||
_.each(tokens, function (token, i) {
|
||||
// this is the token this node ends with
|
||||
if (node.end === token.end) {
|
||||
startToken = token;
|
||||
endToken = tokens[i + 1];
|
||||
return false;
|
||||
}
|
||||
});
|
||||
|
||||
if (endToken.type.type === "eof") {
|
||||
return 1;
|
||||
} else {
|
||||
return this.getNewlinesBetween(startToken, endToken);
|
||||
}
|
||||
};
|
||||
|
||||
Whitespace.prototype.getNewlinesBetween = function (startToken, endToken) {
|
||||
var start = startToken ? startToken.loc.end.line : 1;
|
||||
var end = endToken.loc.start.line;
|
||||
|
||||
var lines = 0;
|
||||
|
||||
for (var line = start; line < end; line++) {
|
||||
if (!_.contains(this.used, line)) {
|
||||
this.used.push(line);
|
||||
lines++;
|
||||
}
|
||||
}
|
||||
|
||||
return lines;
|
||||
};
|
||||
@@ -1,17 +1,27 @@
|
||||
var transform = require("./transform");
|
||||
var transform = require("./transformation/transform");
|
||||
var util = require("./util");
|
||||
var fs = require("fs");
|
||||
var _ = require("lodash");
|
||||
|
||||
exports.util = require("./util");
|
||||
exports.types = require("./types");
|
||||
|
||||
exports.register = function () {
|
||||
return require("./register");
|
||||
exports.runtime = require("./runtime-generator");
|
||||
|
||||
exports.register = function (opts) {
|
||||
var register = require("./register");
|
||||
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) {
|
||||
|
||||
47
lib/6to5/patch.js
Normal file
47
lib/6to5/patch.js
Normal file
@@ -0,0 +1,47 @@
|
||||
var t = require("./types");
|
||||
var _ = require("lodash");
|
||||
|
||||
// estraverse
|
||||
|
||||
var estraverse = require("estraverse");
|
||||
_.extend(estraverse.VisitorKeys, t.VISITOR_KEYS);
|
||||
|
||||
// regenerator/recast/ast-types
|
||||
|
||||
var types = require("ast-types");
|
||||
var def = types.Type.def;
|
||||
var or = types.Type.or;
|
||||
|
||||
// Acorn - Same as ImportNamespaceSpecifier but `id` is `name`
|
||||
def("ImportBatchSpecifier")
|
||||
.bases("Specifier")
|
||||
.build("name")
|
||||
.field("name", def("Identifier"));
|
||||
|
||||
// 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,3 +1,2 @@
|
||||
require("es6-symbol/implement");
|
||||
require("es6-shim");
|
||||
require("regenerator").runtime();
|
||||
require("core-js/shim");
|
||||
require("regenerator/runtime");
|
||||
|
||||
@@ -1,28 +1,148 @@
|
||||
require("./polyfill");
|
||||
|
||||
var maps = {};
|
||||
var to5 = require("./index");
|
||||
var old = require.extensions[".js"];
|
||||
var sourceMapSupport = require("source-map-support");
|
||||
var roadrunner = require("roadrunner");
|
||||
var util = require("./util");
|
||||
var to5 = require("./index");
|
||||
var fs = require("fs");
|
||||
var _ = require("lodash");
|
||||
|
||||
// TODO: source maps - Error.prepareStackTrace override
|
||||
sourceMapSupport.install({
|
||||
retrieveSourceMap: function (source) {
|
||||
var map = maps && maps[source];
|
||||
if (map) {
|
||||
return {
|
||||
url: null,
|
||||
map: map
|
||||
};
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
var ignoreRegex = /node_modules/;
|
||||
//
|
||||
|
||||
require.extensions[".js"] =
|
||||
require.extensions[".es6"] = function (m, filename) {
|
||||
if (ignoreRegex && ignoreRegex.test(filename)) {
|
||||
var blacklist = [];
|
||||
|
||||
var blacklistTest = function (transformer, code) {
|
||||
try {
|
||||
if (_.isFunction(code)) {
|
||||
code();
|
||||
} else {
|
||||
new Function(code);
|
||||
}
|
||||
blacklist.push(transformer);
|
||||
} catch (err) {
|
||||
if (err.name !== "SyntaxError") throw err;
|
||||
}
|
||||
};
|
||||
|
||||
blacklistTest("arrayComprehension", "var foo = [for (foo of bar) foo * foo];");
|
||||
blacklistTest("generatorComprehension", "var foo = (for (foo of bar) foo * foo)");
|
||||
blacklistTest("arrowFunctions", "var foo = x => x * x;");
|
||||
blacklistTest("classes", "class Foo {}");
|
||||
blacklistTest("computedPropertyNames", "var foo = { [foo]: bar };");
|
||||
blacklistTest("constants", function () {
|
||||
try {
|
||||
new Function("const foo = 'foo';\nfoo = 'wow';");
|
||||
} catch (err) {
|
||||
return; // constants are supported
|
||||
}
|
||||
throw new SyntaxError;
|
||||
});
|
||||
blacklistTest("defaultParamaters", "var foo = function (bar = 0) {};");
|
||||
blacklistTest("destructuring", "var { x, y } = { x: 0, y: 0 };");
|
||||
blacklistTest("forOf", "for (var foo of bar) {}");
|
||||
blacklistTest("generators", "function* foo() {}\nasync function bar() {}"); // generators/async functions delegated to same transformer
|
||||
blacklistTest("letScoping", "let foo = 0;");
|
||||
blacklistTest("modules", 'import foo from "from";');
|
||||
blacklistTest("propertyMethodAssignment", "{ get foo() {} }");
|
||||
blacklistTest("propertyNameShorthand", "var foo = { x, y };");
|
||||
blacklistTest("restParameters", "function foo(...bar) {}");
|
||||
blacklistTest("spread", "foo(...bar);");
|
||||
blacklistTest("templateLiterals", "var foo = `foo`;");
|
||||
blacklistTest("unicodeRegex", function () { new RegExp("foo", "u"); });
|
||||
|
||||
//
|
||||
|
||||
var transformOpts = {};
|
||||
var ignoreRegex = /node_modules/;
|
||||
var onlyRegex;
|
||||
var whitelist = [];
|
||||
var cache;
|
||||
var exts = {};
|
||||
var maps = {};
|
||||
var old = require.extensions[".js"];
|
||||
|
||||
var mtime = function (filename) {
|
||||
return +fs.statSync(filename).mtime;
|
||||
};
|
||||
|
||||
var loader = function (m, filename) {
|
||||
if ((ignoreRegex && ignoreRegex.test(filename)) || (onlyRegex && !onlyRegex.test(filename))) {
|
||||
return old.apply(this, arguments);
|
||||
}
|
||||
|
||||
var result = to5.transformFileSync(filename, {
|
||||
sourceMap: true
|
||||
});
|
||||
var result;
|
||||
|
||||
if (cache) {
|
||||
var cached = cache[filename];
|
||||
if (cached && cached.mtime === mtime(filename)) {
|
||||
result = cached;
|
||||
}
|
||||
}
|
||||
|
||||
result = result || to5.transformFileSync(filename, _.extend({
|
||||
whitelist: whitelist,
|
||||
blacklist: blacklist,
|
||||
sourceMap: true,
|
||||
ast: false
|
||||
}, transformOpts));
|
||||
|
||||
if (cache) {
|
||||
result.mtime = mtime(filename);
|
||||
cache[filename] = result;
|
||||
}
|
||||
|
||||
maps[filename] = result.map;
|
||||
|
||||
m._compile(result.code, filename);
|
||||
};
|
||||
|
||||
module.exports = function (_ignoreRegex) {
|
||||
ignoreRegex = _ignoreRegex;
|
||||
var hookExtensions = function (_exts) {
|
||||
_.each(exts, function (old, ext) {
|
||||
require.extensions[ext] = old;
|
||||
});
|
||||
|
||||
exts = {};
|
||||
|
||||
_.each(_exts, function (ext) {
|
||||
exts[ext] = require.extensions[ext];
|
||||
require.extensions[ext] = loader;
|
||||
});
|
||||
};
|
||||
|
||||
hookExtensions([".es6", ".js"]);
|
||||
|
||||
module.exports = function (opts) {
|
||||
// normalise options
|
||||
opts = opts || {};
|
||||
if (_.isRegExp(opts)) opts = { ignore: opts };
|
||||
if (opts.ignoreRegex != null) opts.ignore = opts.ignoreRegex;
|
||||
|
||||
if (opts.only != null) onlyRegex = util.regexify(opts.only);
|
||||
if (opts.ignore != null) ignoreRegex = util.regexify(opts.ignore);
|
||||
|
||||
if (opts.extensions) hookExtensions(util.arrayify(opts.extensions));
|
||||
|
||||
if (opts.cache) cache = opts.cache;
|
||||
if (opts.cache === false) cache = null;
|
||||
if (opts.cache === true) {
|
||||
roadrunner.load();
|
||||
roadrunner.setup();
|
||||
cache = roadrunner.get("6to5");
|
||||
}
|
||||
|
||||
_.extend(transformOpts, opts);
|
||||
};
|
||||
|
||||
33
lib/6to5/runtime-generator.js
Normal file
33
lib/6to5/runtime-generator.js
Normal file
@@ -0,0 +1,33 @@
|
||||
var generator = require("./generation/generator");
|
||||
var util = require("./util");
|
||||
var File = require("./file");
|
||||
var t = require("./types");
|
||||
var _ = require("lodash");
|
||||
|
||||
module.exports = function (namespace) {
|
||||
namespace = t.identifier(t.toIdentifier(namespace || "to5Runtime"));
|
||||
|
||||
var body = [];
|
||||
var container = t.functionExpression(null, [t.identifier("global")], t.blockStatement(body));
|
||||
var tree = t.program([t.expressionStatement(t.callExpression(container, [util.template("self-global")]))]);
|
||||
|
||||
body.push(t.variableDeclaration("var", [
|
||||
t.variableDeclarator(
|
||||
namespace,
|
||||
t.assignmentExpression("=", t.memberExpression(t.identifier("global"), namespace), t.objectExpression([]))
|
||||
)
|
||||
]));
|
||||
|
||||
_.each(File.declarations, function (name) {
|
||||
if (_.contains(File.excludeDeclarationsFromRuntime, name)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
var key = t.identifier(t.toIdentifier(name));
|
||||
body.push(t.expressionStatement(
|
||||
t.assignmentExpression("=", t.memberExpression(namespace, key), util.template(name))
|
||||
));
|
||||
});
|
||||
|
||||
return generator(tree).code;
|
||||
};
|
||||
@@ -1 +0,0 @@
|
||||
var VARIABLE_NAME = SLICE_KEY.call(arguments, SLICE_ARG);
|
||||
@@ -1 +0,0 @@
|
||||
var VARIABLE_NAME = SLICE_KEY.call(arguments);
|
||||
@@ -1 +0,0 @@
|
||||
SLICE_KEY.call(arguments);
|
||||
@@ -1,5 +0,0 @@
|
||||
ARRAY.filter(function (KEY) {
|
||||
return FILTER;
|
||||
}).map(function (KEY) {
|
||||
return STATEMENT;
|
||||
});
|
||||
@@ -1,3 +0,0 @@
|
||||
ARRAY.map(function (KEY) {
|
||||
return STATEMENT;
|
||||
});
|
||||
@@ -1 +0,0 @@
|
||||
[].concat(ARGUMENT);
|
||||
@@ -1 +0,0 @@
|
||||
CLASS_NAME.__proto__ = SUPER_NAME;
|
||||
@@ -1,8 +0,0 @@
|
||||
CLASS_NAME.prototype = Object.create(SUPER_NAME.prototype, {
|
||||
constructor: {
|
||||
value: CLASS_NAME,
|
||||
enumerable: false,
|
||||
writable: true,
|
||||
configurable: true
|
||||
}
|
||||
});
|
||||
@@ -1,2 +0,0 @@
|
||||
SUPER_NAME.apply(this, arguments);
|
||||
|
||||
@@ -1,7 +0,0 @@
|
||||
(function () {
|
||||
var CLASS_NAME = function () {
|
||||
|
||||
};
|
||||
|
||||
return CLASS_NAME;
|
||||
})()
|
||||
@@ -1 +0,0 @@
|
||||
exports.default = VALUE;
|
||||
@@ -1 +0,0 @@
|
||||
exports.VARIABLE_NAME = require(MODULE_NAME).KEY;
|
||||
@@ -1,3 +0,0 @@
|
||||
(function (KEY) {
|
||||
return KEY;
|
||||
})(OBJECT)
|
||||
@@ -1,4 +0,0 @@
|
||||
(function (KEY) {
|
||||
CONTENT;
|
||||
return KEY;
|
||||
})(OBJECT);
|
||||
@@ -1,102 +0,0 @@
|
||||
module.exports = transform;
|
||||
|
||||
var Transformer = require("./transformer");
|
||||
var sourceMap = require("source-map");
|
||||
var recast = require("recast");
|
||||
var File = require("./file");
|
||||
var util = require("./util");
|
||||
var _ = require("lodash");
|
||||
|
||||
function transform(code, opts) {
|
||||
opts = opts || {};
|
||||
code = (code || "") + "";
|
||||
|
||||
var file = new File(opts);
|
||||
return file.parse(code);
|
||||
}
|
||||
|
||||
transform.test = function (task, assert) {
|
||||
var actual = task.actual;
|
||||
var expect = task.expect;
|
||||
var opts = task.options;
|
||||
var exec = task.exec;
|
||||
|
||||
var getOpts = function (filename) {
|
||||
return _.merge({ filename: filename }, opts);
|
||||
};
|
||||
|
||||
var execCode = exec.code.trim();
|
||||
var result;
|
||||
|
||||
if (execCode) {
|
||||
result = transform(execCode, getOpts(exec.filename));
|
||||
execCode = result.code;
|
||||
|
||||
require("./polyfill");
|
||||
var fn = new Function("assert", execCode);
|
||||
fn(assert);
|
||||
} else {
|
||||
var actualCode = actual.code.trim();
|
||||
var expectCode = expect.code.trim();
|
||||
|
||||
result = transform(actualCode, getOpts(actual.filename));
|
||||
actualCode = recast.prettyPrint(result.ast).code;
|
||||
|
||||
var expectAst = util.parse(expect, expectCode);
|
||||
var expectResult = recast.prettyPrint(expectAst);
|
||||
expectCode = expectResult.code;
|
||||
|
||||
assert.equal(actualCode, expectCode);
|
||||
}
|
||||
|
||||
if (task.sourceMap) {
|
||||
assert.deepEqual(task.sourceMap, result.map);
|
||||
}
|
||||
|
||||
if (task.sourceMappings) {
|
||||
var consumer = new sourceMap.SourceMapConsumer(result.map);
|
||||
|
||||
_.each(task.sourceMappings, function (mapping, i) {
|
||||
var generated = mapping.generated;
|
||||
var original = mapping.original;
|
||||
|
||||
var pos = consumer.originalPositionFor(generated);
|
||||
var msg = "source mapping " + i + " - generated: " + generated.line + ":" + generated.column;
|
||||
assert.equal(pos.line + ":" + pos.column, original.line + ":" + original.column, msg);
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
transform._ensureTransformerNames = function (type, keys) {
|
||||
_.each(keys, function (key) {
|
||||
if (key[0] === "_" || !_.has(transform.transformers, key)) {
|
||||
throw new ReferenceError("unknown transformer " + key + " specified in " + type);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
transform.transformers = {
|
||||
modules: require("./transformers/modules"),
|
||||
computedPropertyNames: require("./transformers/computed-property-names"),
|
||||
propertyNameShorthand: require("./transformers/property-name-shorthand"),
|
||||
constants: require("./transformers/constants"),
|
||||
arrayComprehension: require("./transformers/array-comprehension"),
|
||||
arrowFunctions: require("./transformers/arrow-functions"),
|
||||
classes: require("./transformers/classes"),
|
||||
spread: require("./transformers/spread"),
|
||||
templateLiterals: require("./transformers/template-literals"),
|
||||
propertyMethodAssignment: require("./transformers/property-method-assignment"),
|
||||
defaultParameters: require("./transformers/default-parameters"),
|
||||
letScoping: require("./transformers/let-scoping"),
|
||||
restParameters: require("./transformers/rest-parameters"),
|
||||
destructuring: require("./transformers/destructuring"),
|
||||
forOf: require("./transformers/for-of"),
|
||||
unicodeRegex: require("./transformers/unicode-regex"),
|
||||
generators: require("./transformers/generators"),
|
||||
|
||||
_aliasFunctions: require("./transformers/_alias-functions")
|
||||
};
|
||||
|
||||
_.each(transform.transformers, function (transformer, key) {
|
||||
transform.transformers[key] = new Transformer(key, transformer);
|
||||
});
|
||||
205
lib/6to5/transformation/modules/_default.js
Normal file
205
lib/6to5/transformation/modules/_default.js
Normal file
@@ -0,0 +1,205 @@
|
||||
module.exports = DefaultFormatter;
|
||||
|
||||
var traverse = require("../../traverse");
|
||||
var util = require("../../util");
|
||||
var t = require("../../types");
|
||||
var _ = require("lodash");
|
||||
|
||||
function DefaultFormatter(file) {
|
||||
this.file = file;
|
||||
|
||||
this.localExports = this.getLocalExports();
|
||||
this.remapAssignments();
|
||||
}
|
||||
|
||||
DefaultFormatter.prototype.getLocalExports = function () {
|
||||
var localExports = {};
|
||||
|
||||
traverse(this.file.ast, {
|
||||
enter: function (node) {
|
||||
var declar = node && node.declaration;
|
||||
if (t.isExportDeclaration(node) && declar && t.isStatement(declar)) {
|
||||
_.extend(localExports, t.getIds(declar, true));
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
return localExports;
|
||||
};
|
||||
|
||||
DefaultFormatter.prototype.remapExportAssignment = function (node) {
|
||||
return t.assignmentExpression(
|
||||
"=",
|
||||
node.left,
|
||||
t.assignmentExpression(
|
||||
node.operator,
|
||||
t.memberExpression(t.identifier("exports"), node.left),
|
||||
node.right
|
||||
)
|
||||
);
|
||||
};
|
||||
|
||||
DefaultFormatter.prototype.remapAssignments = function () {
|
||||
var localExports = this.localExports;
|
||||
var self = this;
|
||||
|
||||
var isLocalReference = function (node, scope) {
|
||||
var name = node.name;
|
||||
return t.isIdentifier(node) && localExports[name] && localExports[name] === scope.get(name, true);
|
||||
};
|
||||
|
||||
traverse(this.file.ast, {
|
||||
enter: function (node, parent, scope) {
|
||||
if (t.isUpdateExpression(node) && isLocalReference(node.argument, scope)) {
|
||||
this.stop();
|
||||
|
||||
// expand to long file assignment expression
|
||||
var assign = t.assignmentExpression(node.operator[0] + "=", node.argument, t.literal(1));
|
||||
|
||||
// remap this assignment expression
|
||||
var remapped = self.remapExportAssignment(assign);
|
||||
|
||||
// we don't need to change the result
|
||||
if (t.isExpressionStatement(parent) || node.prefix) {
|
||||
return remapped;
|
||||
}
|
||||
|
||||
var nodes = [];
|
||||
nodes.push(remapped);
|
||||
|
||||
var operator;
|
||||
if (node.operator === "--") {
|
||||
operator = "+";
|
||||
} else { // "++"
|
||||
operator = "-";
|
||||
}
|
||||
nodes.push(t.binaryExpression(operator, node.argument, t.literal(1)));
|
||||
|
||||
return t.sequenceExpression(nodes);
|
||||
}
|
||||
|
||||
if (t.isAssignmentExpression(node) && isLocalReference(node.left, scope)) {
|
||||
this.stop();
|
||||
return self.remapExportAssignment(node);
|
||||
}
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
DefaultFormatter.prototype.getModuleName = function () {
|
||||
var opts = this.file.opts;
|
||||
var filenameRelative = opts.filenameRelative;
|
||||
var moduleName = "";
|
||||
|
||||
if (opts.moduleRoot) {
|
||||
moduleName = opts.moduleRoot + "/";
|
||||
}
|
||||
|
||||
if (!opts.filenameRelative) {
|
||||
return moduleName + opts.filename.replace(/^\//, "");
|
||||
}
|
||||
|
||||
if (opts.sourceRoot) {
|
||||
// remove sourceRoot from filename
|
||||
var sourceRootRegEx = new RegExp("^" + opts.sourceRoot + "\/?");
|
||||
filenameRelative = filenameRelative.replace(sourceRootRegEx, "");
|
||||
}
|
||||
|
||||
// remove extension
|
||||
filenameRelative = filenameRelative.replace(/\.(.*?)$/, "");
|
||||
|
||||
moduleName += filenameRelative;
|
||||
|
||||
return moduleName;
|
||||
};
|
||||
|
||||
DefaultFormatter.prototype._pushStatement = function (ref, nodes) {
|
||||
if (t.isClass(ref) || t.isFunction(ref)) {
|
||||
if (ref.id) {
|
||||
nodes.push(t.toStatement(ref));
|
||||
ref = ref.id;
|
||||
}
|
||||
}
|
||||
|
||||
return ref;
|
||||
};
|
||||
|
||||
DefaultFormatter.prototype._hoistExport = function (declar, assign, priority) {
|
||||
if (t.isFunctionDeclaration(declar)) {
|
||||
assign._blockHoist = priority || 2;
|
||||
}
|
||||
|
||||
return assign;
|
||||
};
|
||||
|
||||
DefaultFormatter.prototype._exportSpecifier = function (getRef, specifier, node, nodes) {
|
||||
var inherits = false;
|
||||
if (node.specifiers.length === 1) inherits = node;
|
||||
|
||||
if (node.source) {
|
||||
if (t.isExportBatchSpecifier(specifier)) {
|
||||
// export * from "foo";
|
||||
nodes.push(this._exportsWildcard(getRef(), node));
|
||||
} else {
|
||||
// export { foo } from "test";
|
||||
nodes.push(this._exportsAssign(
|
||||
t.getSpecifierName(specifier),
|
||||
t.memberExpression(getRef(), specifier.id),
|
||||
node
|
||||
));
|
||||
}
|
||||
} else {
|
||||
// export { foo };
|
||||
nodes.push(this._exportsAssign(t.getSpecifierName(specifier), specifier.id, node));
|
||||
}
|
||||
};
|
||||
|
||||
DefaultFormatter.prototype._exportsWildcard = function (objectIdentifier) {
|
||||
return util.template("exports-wildcard", {
|
||||
OBJECT: objectIdentifier
|
||||
}, true);
|
||||
};
|
||||
|
||||
DefaultFormatter.prototype._exportsAssign = function (id, init) {
|
||||
return util.template("exports-assign", {
|
||||
VALUE: init,
|
||||
KEY: id
|
||||
}, true);
|
||||
};
|
||||
|
||||
DefaultFormatter.prototype.exportDeclaration = function (node, nodes) {
|
||||
var declar = node.declaration;
|
||||
|
||||
var id = declar.id;
|
||||
|
||||
if (node.default) {
|
||||
id = t.identifier("default");
|
||||
}
|
||||
|
||||
var assign;
|
||||
|
||||
if (t.isVariableDeclaration(declar)) {
|
||||
for (var i in declar.declarations) {
|
||||
var decl = declar.declarations[i];
|
||||
|
||||
decl.init = this._exportsAssign(decl.id, decl.init, node).expression;
|
||||
|
||||
var newDeclar = t.variableDeclaration(declar.kind, [decl]);
|
||||
if (i === "0") t.inherits(newDeclar, declar);
|
||||
nodes.push(newDeclar);
|
||||
}
|
||||
} else {
|
||||
var ref = declar;
|
||||
|
||||
if (t.isFunctionDeclaration(declar) || t.isClassDeclaration(declar)) {
|
||||
ref = declar.id;
|
||||
nodes.push(declar);
|
||||
}
|
||||
|
||||
assign = this._exportsAssign(id, ref, node);
|
||||
|
||||
nodes.push(assign);
|
||||
|
||||
this._hoistExport(declar, assign);
|
||||
}
|
||||
};
|
||||
104
lib/6to5/transformation/modules/amd.js
Normal file
104
lib/6to5/transformation/modules/amd.js
Normal file
@@ -0,0 +1,104 @@
|
||||
module.exports = AMDFormatter;
|
||||
|
||||
var DefaultFormatter = require("./_default");
|
||||
var util = require("../../util");
|
||||
var t = require("../../types");
|
||||
var _ = require("lodash");
|
||||
|
||||
function AMDFormatter() {
|
||||
DefaultFormatter.apply(this, arguments);
|
||||
this.ids = {};
|
||||
}
|
||||
|
||||
util.inherits(AMDFormatter, DefaultFormatter);
|
||||
|
||||
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 (ast) {
|
||||
var program = ast.program;
|
||||
var body = program.body;
|
||||
|
||||
// build an array of module names
|
||||
|
||||
var names = [t.literal("exports")].concat(this.buildDependencyLiterals());
|
||||
names = t.arrayExpression(names);
|
||||
|
||||
// build up define container
|
||||
|
||||
var params = _.values(this.ids);
|
||||
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._push = function (node) {
|
||||
var id = node.source.value;
|
||||
var ids = this.ids;
|
||||
|
||||
if (ids[id]) {
|
||||
return ids[id];
|
||||
} else {
|
||||
return this.ids[id] = this.file.generateUidIdentifier(id);
|
||||
}
|
||||
};
|
||||
|
||||
AMDFormatter.prototype.importDeclaration = function (node) {
|
||||
this._push(node);
|
||||
};
|
||||
|
||||
AMDFormatter.prototype.importSpecifier = function (specifier, node, nodes) {
|
||||
var key = t.getSpecifierName(specifier);
|
||||
var ref = this._push(node);
|
||||
|
||||
if (t.isImportBatchSpecifier(specifier)) {
|
||||
// import * as bar from "foo";
|
||||
} else if (t.isSpecifierDefault(specifier) && !this.noInteropRequire) {
|
||||
// import foo from "foo";
|
||||
ref = t.callExpression(this.file.addDeclaration("interop-require"), [ref]);
|
||||
} else {
|
||||
// import {foo} from "foo";
|
||||
ref = t.memberExpression(ref, specifier.id, false);
|
||||
}
|
||||
|
||||
nodes.push(t.variableDeclaration("var", [
|
||||
t.variableDeclarator(key, ref)
|
||||
]));
|
||||
};
|
||||
|
||||
AMDFormatter.prototype.exportSpecifier = function (specifier, node, nodes) {
|
||||
var self = this;
|
||||
return this._exportSpecifier(function () {
|
||||
return self._push(node);
|
||||
}, specifier, node, nodes);
|
||||
};
|
||||
97
lib/6to5/transformation/modules/common.js
Normal file
97
lib/6to5/transformation/modules/common.js
Normal file
@@ -0,0 +1,97 @@
|
||||
module.exports = CommonJSFormatter;
|
||||
|
||||
var DefaultFormatter = require("./_default");
|
||||
var traverse = require("../../traverse");
|
||||
var util = require("../../util");
|
||||
var t = require("../../types");
|
||||
|
||||
function CommonJSFormatter(file) {
|
||||
DefaultFormatter.apply(this, arguments);
|
||||
|
||||
var hasNonDefaultExports = false;
|
||||
traverse(file.ast, {
|
||||
enter: function (node) {
|
||||
if (t.isExportDeclaration(node) && !node.default) hasNonDefaultExports = true;
|
||||
}
|
||||
});
|
||||
this.hasNonDefaultExports = hasNonDefaultExports;
|
||||
}
|
||||
|
||||
util.inherits(CommonJSFormatter, DefaultFormatter);
|
||||
|
||||
CommonJSFormatter.prototype.importSpecifier = function (specifier, node, nodes) {
|
||||
var variableName = t.getSpecifierName(specifier);
|
||||
|
||||
// import foo from "foo";
|
||||
if (t.isSpecifierDefault(specifier)) {
|
||||
nodes.push(t.variableDeclaration("var", [
|
||||
t.variableDeclarator(variableName,
|
||||
t.callExpression(this.file.addDeclaration("interop-require"), [util.template("require", {
|
||||
MODULE_NAME: node.source
|
||||
})])
|
||||
)
|
||||
]));
|
||||
} else {
|
||||
// import foo from "foo";
|
||||
|
||||
var templateName = "require-assign";
|
||||
|
||||
// import * as bar from "foo";
|
||||
if (specifier.type !== "ImportBatchSpecifier") templateName += "-key";
|
||||
|
||||
nodes.push(util.template(templateName, {
|
||||
VARIABLE_NAME: variableName,
|
||||
MODULE_NAME: node.source,
|
||||
KEY: specifier.id
|
||||
}));
|
||||
}
|
||||
};
|
||||
|
||||
CommonJSFormatter.prototype.importDeclaration = function (node, nodes) {
|
||||
// import "foo";
|
||||
nodes.push(util.template("require", {
|
||||
MODULE_NAME: node.source
|
||||
}, true));
|
||||
};
|
||||
|
||||
CommonJSFormatter.prototype.exportDeclaration = function (node, nodes) {
|
||||
if (node.default) {
|
||||
var declar = node.declaration;
|
||||
var assign;
|
||||
|
||||
// module.exports = VALUE;
|
||||
var templateName = "exports-default-module";
|
||||
|
||||
// exports = module.exports = VALUE;
|
||||
if (this.hasNonDefaultExports) templateName = "exports-default-module-override";
|
||||
|
||||
if (t.isFunction(declar) || !this.hasNonDefaultExports) {
|
||||
assign = util.template(templateName, {
|
||||
VALUE: this._pushStatement(declar, nodes)
|
||||
}, true);
|
||||
|
||||
// hoist to the top if this default is a function
|
||||
nodes.push(this._hoistExport(declar, assign, 3));
|
||||
return;
|
||||
} else {
|
||||
// this export isn't a function so we can't hoist it to the top so we need to set it
|
||||
// at the very end of the file with something like:
|
||||
//
|
||||
// module.exports = Object.assign(exports["default"], exports)
|
||||
//
|
||||
|
||||
assign = util.template("common-export-default-assign", true);
|
||||
assign._blockHoist = 0;
|
||||
|
||||
nodes.push(assign);
|
||||
}
|
||||
}
|
||||
|
||||
DefaultFormatter.prototype.exportDeclaration.apply(this, arguments);
|
||||
};
|
||||
|
||||
CommonJSFormatter.prototype.exportSpecifier = function (specifier, node, nodes) {
|
||||
this._exportSpecifier(function () {
|
||||
return t.callExpression(t.identifier("require"), [node.source]);
|
||||
}, specifier, node, nodes);
|
||||
};
|
||||
18
lib/6to5/transformation/modules/ignore.js
Normal file
18
lib/6to5/transformation/modules/ignore.js
Normal file
@@ -0,0 +1,18 @@
|
||||
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 () {
|
||||
|
||||
};
|
||||
174
lib/6to5/transformation/modules/system.js
Normal file
174
lib/6to5/transformation/modules/system.js
Normal file
@@ -0,0 +1,174 @@
|
||||
module.exports = SystemFormatter;
|
||||
|
||||
var AMDFormatter = require("./amd");
|
||||
var traverse = require("../../traverse");
|
||||
var util = require("../../util");
|
||||
var t = require("../../types");
|
||||
var _ = require("lodash");
|
||||
|
||||
function SystemFormatter(file) {
|
||||
this.exportIdentifier = file.generateUidIdentifier("export");
|
||||
this.noInteropRequire = true;
|
||||
|
||||
AMDFormatter.apply(this, arguments);
|
||||
}
|
||||
|
||||
util.inherits(SystemFormatter, AMDFormatter);
|
||||
|
||||
SystemFormatter.prototype._addImportSource = function (node, exportNode) {
|
||||
node._importSource = exportNode.source && exportNode.source.value;
|
||||
return node;
|
||||
};
|
||||
|
||||
SystemFormatter.prototype._exportsWildcard = function (objectIdentifier, node) {
|
||||
var leftIdentifier = this.file.generateUidIdentifier("key");
|
||||
var valIdentifier = t.memberExpression(objectIdentifier, leftIdentifier, true);
|
||||
|
||||
var left = t.variableDeclaration("var", [
|
||||
t.variableDeclarator(leftIdentifier)
|
||||
]);
|
||||
|
||||
var right = objectIdentifier;
|
||||
|
||||
var block = t.blockStatement([
|
||||
this.buildExportCall(leftIdentifier, valIdentifier)
|
||||
]);
|
||||
|
||||
return this._addImportSource(t.forInStatement(left, right, block), node);
|
||||
};
|
||||
|
||||
SystemFormatter.prototype._exportsAssign = function (id, init, node) {
|
||||
var call = this.buildExportCall(t.literal(id.name), init, true);
|
||||
return this._addImportSource(call, node);
|
||||
};
|
||||
|
||||
SystemFormatter.prototype.remapExportAssignment = function (node) {
|
||||
return this.buildExportCall(t.literal(node.left.name), node);
|
||||
};
|
||||
|
||||
SystemFormatter.prototype.buildExportCall = function (id, init, isStatement) {
|
||||
var call = t.callExpression(this.exportIdentifier, [id, init]);
|
||||
if (isStatement) {
|
||||
return t.expressionStatement(call);
|
||||
} else {
|
||||
return call;
|
||||
}
|
||||
};
|
||||
|
||||
SystemFormatter.prototype.importSpecifier = function (specifier, node, nodes) {
|
||||
AMDFormatter.prototype.importSpecifier.apply(this, arguments);
|
||||
this._addImportSource(_.last(nodes), node);
|
||||
};
|
||||
|
||||
SystemFormatter.prototype.buildRunnerSetters = function (block, hoistDeclarators) {
|
||||
return t.arrayExpression(_.map(this.ids, function (uid, source) {
|
||||
var nodes = [];
|
||||
|
||||
traverse(block, {
|
||||
enter: function (node) {
|
||||
if (node._importSource === source) {
|
||||
if (t.isVariableDeclaration(node)) {
|
||||
_.each(node.declarations, function (declar) {
|
||||
hoistDeclarators.push(t.variableDeclarator(declar.id));
|
||||
nodes.push(t.expressionStatement(
|
||||
t.assignmentExpression("=", declar.id, declar.init)
|
||||
));
|
||||
});
|
||||
} else {
|
||||
nodes.push(node);
|
||||
}
|
||||
|
||||
this.remove();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
return t.functionExpression(null, [uid], t.blockStatement(nodes));
|
||||
}));
|
||||
};
|
||||
|
||||
SystemFormatter.prototype.transform = function (ast) {
|
||||
var program = ast.program;
|
||||
|
||||
var hoistDeclarators = [];
|
||||
var moduleName = this.getModuleName();
|
||||
var moduleNameLiteral = t.literal(moduleName);
|
||||
|
||||
var block = t.blockStatement(program.body);
|
||||
|
||||
var runner = util.template("system", {
|
||||
MODULE_NAME: moduleNameLiteral,
|
||||
MODULE_DEPENDENCIES: t.arrayExpression(this.buildDependencyLiterals()),
|
||||
EXPORT_IDENTIFIER: this.exportIdentifier,
|
||||
SETTERS: this.buildRunnerSetters(block, hoistDeclarators),
|
||||
EXECUTE: t.functionExpression(null, [], block)
|
||||
}, true);
|
||||
|
||||
var handlerBody = runner.expression.arguments[2].body.body;
|
||||
if (!moduleName) runner.expression.arguments.shift();
|
||||
|
||||
var returnStatement = handlerBody.pop();
|
||||
|
||||
// hoist up all variable declarations
|
||||
traverse(block, {
|
||||
enter: function (node, parent, scope) {
|
||||
if (t.isFunction(node)) {
|
||||
// nothing inside is accessible
|
||||
return this.stop();
|
||||
}
|
||||
|
||||
if (t.isVariableDeclaration(node)) {
|
||||
if (node.kind !== "var" && !t.isProgram(parent)) { // let, const
|
||||
// can't be accessed
|
||||
return;
|
||||
}
|
||||
|
||||
var nodes = [];
|
||||
|
||||
_.each(node.declarations, function (declar) {
|
||||
hoistDeclarators.push(t.variableDeclarator(declar.id));
|
||||
if (declar.init) {
|
||||
// no initializer so we can just hoist it as-is
|
||||
var assign = t.expressionStatement(t.assignmentExpression("=", declar.id, declar.init));
|
||||
nodes.push(assign);
|
||||
}
|
||||
});
|
||||
|
||||
// for (var i in test)
|
||||
// for (var i = 0;;)
|
||||
if (t.isFor(parent)) {
|
||||
if (parent.left === node) {
|
||||
return node.declarations[0].id;
|
||||
}
|
||||
|
||||
if (parent.init === node) {
|
||||
return t.toSequenceExpression(nodes, scope);
|
||||
}
|
||||
}
|
||||
|
||||
return nodes;
|
||||
}
|
||||
}
|
||||
});
|
||||
if (hoistDeclarators.length) {
|
||||
var hoistDeclar = t.variableDeclaration("var", hoistDeclarators);
|
||||
hoistDeclar._blockHoist = true;
|
||||
handlerBody.unshift(hoistDeclar);
|
||||
}
|
||||
|
||||
// hoist up function declarations for circular references
|
||||
traverse(block, {
|
||||
enter: function (node) {
|
||||
if (t.isFunction(node)) this.stop();
|
||||
|
||||
if (t.isFunctionDeclaration(node) || node._blockHoist) {
|
||||
handlerBody.push(node);
|
||||
this.remove();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
handlerBody.push(returnStatement);
|
||||
|
||||
program.body = [runner];
|
||||
};
|
||||
50
lib/6to5/transformation/modules/umd.js
Normal file
50
lib/6to5/transformation/modules/umd.js
Normal file
@@ -0,0 +1,50 @@
|
||||
module.exports = UMDFormatter;
|
||||
|
||||
var AMDFormatter = require("./amd");
|
||||
var util = require("../../util");
|
||||
var t = require("../../types");
|
||||
var _ = require("lodash");
|
||||
|
||||
function UMDFormatter() {
|
||||
AMDFormatter.apply(this, arguments);
|
||||
}
|
||||
|
||||
util.inherits(UMDFormatter, AMDFormatter);
|
||||
|
||||
UMDFormatter.prototype.transform = function (ast) {
|
||||
var program = ast.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")].concat(ids);
|
||||
|
||||
var factory = t.functionExpression(null, args, t.blockStatement(body));
|
||||
|
||||
// runner
|
||||
|
||||
var defineArgs = [t.arrayExpression([t.literal("exports")].concat(names))];
|
||||
var moduleName = this.getModuleName();
|
||||
if (moduleName) defineArgs.unshift(t.literal(moduleName));
|
||||
|
||||
var runner = util.template("umd-runner-body", {
|
||||
AMD_ARGUMENTS: defineArgs,
|
||||
|
||||
COMMON_ARGUMENTS: names.map(function (name) {
|
||||
return t.callExpression(t.identifier("require"), [name]);
|
||||
})
|
||||
});
|
||||
|
||||
//
|
||||
|
||||
var call = t.callExpression(runner, [factory]);
|
||||
program.body = [t.expressionStatement(call)];
|
||||
};
|
||||
@@ -0,0 +1 @@
|
||||
PROPERTY[Symbol.referenceGet](OBJECT).call(OBJECT)
|
||||
@@ -0,0 +1 @@
|
||||
PROPERTY[Symbol.referenceDelete](OBJECT)
|
||||
@@ -0,0 +1 @@
|
||||
PROPERTY[Symbol.referenceGet](OBJECT)
|
||||
@@ -0,0 +1 @@
|
||||
PROPERTY[Symbol.referenceSet](OBJECT, VALUE)
|
||||
5
lib/6to5/transformation/templates/apply-constructor.js
Normal file
5
lib/6to5/transformation/templates/apply-constructor.js
Normal file
@@ -0,0 +1,5 @@
|
||||
(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
lib/6to5/transformation/templates/array-from.js
Normal file
1
lib/6to5/transformation/templates/array-from.js
Normal file
@@ -0,0 +1 @@
|
||||
Array.from(VALUE);
|
||||
37
lib/6to5/transformation/templates/async-to-generator.js
Normal file
37
lib/6to5/transformation/templates/async-to-generator.js
Normal file
@@ -0,0 +1,37 @@
|
||||
(function (fn) {
|
||||
return function () {
|
||||
var gen = fn.apply(this, arguments);
|
||||
|
||||
return new Promise(function (resolve, reject) {
|
||||
function step(getNext) {
|
||||
var next;
|
||||
|
||||
try {
|
||||
next = getNext();
|
||||
} catch(e) {
|
||||
reject(e);
|
||||
return;
|
||||
}
|
||||
|
||||
if (next.done) {
|
||||
resolve(next.value);
|
||||
return;
|
||||
}
|
||||
|
||||
Promise.resolve(next.value).then(function (v) {
|
||||
step(function () {
|
||||
return gen.next(v);
|
||||
});
|
||||
}, function (e) {
|
||||
step(function () {
|
||||
return gen["throw"](e);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
step(function () {
|
||||
return gen.next();
|
||||
});
|
||||
});
|
||||
}
|
||||
})
|
||||
@@ -0,0 +1,3 @@
|
||||
if (SUPER_NAME) {
|
||||
SUPER_NAME.apply(this, arguments);
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
module.exports = Object.assign(exports["default"], exports);
|
||||
1
lib/6to5/transformation/templates/corejs-iterator.js
Normal file
1
lib/6to5/transformation/templates/corejs-iterator.js
Normal file
@@ -0,0 +1 @@
|
||||
CORE_ID.$for.getIterator(VALUE);
|
||||
8
lib/6to5/transformation/templates/define-property.js
Normal file
8
lib/6to5/transformation/templates/define-property.js
Normal file
@@ -0,0 +1,8 @@
|
||||
(function (obj, key, value) {
|
||||
return Object.defineProperty(obj, key, {
|
||||
value: value,
|
||||
enumerable: true,
|
||||
configurable: true,
|
||||
writable: true
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1 @@
|
||||
exports = module.exports = VALUE;
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user