Compare commits
937 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
8e530afd78 | ||
|
|
6c66a82b37 | ||
|
|
737abca3a9 | ||
|
|
9db43ca7a9 | ||
|
|
25b0683316 | ||
|
|
a096f6b1c5 | ||
|
|
e41ab2ab0c | ||
|
|
6a6764fa7b | ||
|
|
a2358d6863 | ||
|
|
612ef79d35 | ||
|
|
2dfa6ddf36 | ||
|
|
2910d4f82c | ||
|
|
4b6c954f5e | ||
|
|
b7e23e3410 | ||
|
|
a19f10e124 | ||
|
|
8e1f134635 | ||
|
|
aa151016f5 | ||
|
|
ce3c6289a2 | ||
|
|
0364519869 | ||
|
|
58cda35831 | ||
|
|
ebaa06f4a2 | ||
|
|
4b0f624fb3 | ||
|
|
aa0f3ac5d0 | ||
|
|
725906a7dc | ||
|
|
13d5c94b8b | ||
|
|
85308a1e8c | ||
|
|
83bcaba1a5 | ||
|
|
185648cb2c | ||
|
|
be355fc1c6 | ||
|
|
7795e11d58 | ||
|
|
8f74e8068c | ||
|
|
4f08a77230 | ||
|
|
4ac33d62af | ||
|
|
2710a914e8 | ||
|
|
8934e7f9da | ||
|
|
b4f18e05fa | ||
|
|
c07540a2c4 | ||
|
|
c409f63bbe | ||
|
|
d3c30b669f | ||
|
|
d10856d16c | ||
|
|
fb08a519c8 | ||
|
|
6a8ecf2507 | ||
|
|
100317e0c8 | ||
|
|
a32f744341 | ||
|
|
c4feff3cb7 | ||
|
|
498297ce6b | ||
|
|
2412c1d502 | ||
|
|
d92e1a4fb8 | ||
|
|
1d0d050413 | ||
|
|
a607ac0077 | ||
|
|
41f5e7c077 | ||
|
|
99604362ed | ||
|
|
2c8e374eaf | ||
|
|
238c68f829 | ||
|
|
09b334ad21 | ||
|
|
d647ede94b | ||
|
|
6386b60b9a | ||
|
|
25749a9933 | ||
|
|
fd4c0dae95 | ||
|
|
80d362c534 | ||
|
|
59820b9a84 | ||
|
|
f6ff366edf | ||
|
|
c7cac7aaba | ||
|
|
0647d374a3 | ||
|
|
25c2816a85 | ||
|
|
b57a80ecae | ||
|
|
574d47a571 | ||
|
|
7c5d2b19b7 | ||
|
|
c7669f44c1 | ||
|
|
0ed5c5f480 | ||
|
|
94c34e0132 | ||
|
|
92c4bbd003 | ||
|
|
ec8e840841 | ||
|
|
1c3c64c12c | ||
|
|
cae80d6e9b | ||
|
|
aaf29ddd82 | ||
|
|
fb485567b9 | ||
|
|
050bcec617 | ||
|
|
6231015557 | ||
|
|
822eb47ee7 | ||
|
|
91161ae9a1 | ||
|
|
4c1b4b6490 | ||
|
|
e792256087 | ||
|
|
19ad22f6e8 | ||
|
|
01818a50fa | ||
|
|
3247851019 | ||
|
|
939c00d33c | ||
|
|
8b096ac705 | ||
|
|
30c4a0cf06 | ||
|
|
e08d400b36 | ||
|
|
7e080aa9d2 | ||
|
|
c0e5059634 | ||
|
|
f8f5684faa | ||
|
|
2c3e9fbc07 | ||
|
|
b9d066d953 | ||
|
|
94e15b0750 | ||
|
|
3256c1d120 | ||
|
|
eba9f0ffbd | ||
|
|
52c3c143f9 | ||
|
|
b0f797205b | ||
|
|
dd52c6a687 | ||
|
|
3cf773b528 | ||
|
|
98424f80af | ||
|
|
708879ff1b | ||
|
|
70042bb0a8 | ||
|
|
0f7711a202 | ||
|
|
27f039488e | ||
|
|
e3ce82e12f | ||
|
|
4934ea56a0 | ||
|
|
ce03457b19 | ||
|
|
1298c67949 | ||
|
|
668274edcb | ||
|
|
0694a7dd06 | ||
|
|
20d19735fc | ||
|
|
b5b6bf4ad5 | ||
|
|
844c10cac0 | ||
|
|
43583e4e9d | ||
|
|
f5b921cda9 | ||
|
|
763892aa79 | ||
|
|
3e6eae4d1a | ||
|
|
7c090c8580 | ||
|
|
a5f6c1c389 | ||
|
|
c159f2d982 | ||
|
|
9205f10244 | ||
|
|
4cd7bcad59 | ||
|
|
7e9660efd3 | ||
|
|
2d66ce5224 | ||
|
|
1257b2cf40 | ||
|
|
f21d935de5 | ||
|
|
2e20364793 | ||
|
|
e47e8a187a | ||
|
|
26924d5944 | ||
|
|
5eb1850a55 | ||
|
|
333e287226 | ||
|
|
80a77bd6a2 | ||
|
|
c9286a1de1 | ||
|
|
52f614dcdf | ||
|
|
600367ae25 | ||
|
|
b761cba135 | ||
|
|
947d3e262d | ||
|
|
4061bea528 | ||
|
|
de195e5bfc | ||
|
|
3bcef86973 | ||
|
|
fa670ac71e | ||
|
|
572261f9ce | ||
|
|
8a320d53a5 | ||
|
|
0650eedeb6 | ||
|
|
2282d066a2 | ||
|
|
f4d7cc55c1 | ||
|
|
eaaa279aa5 | ||
|
|
0595e06e29 | ||
|
|
9b27a170ae | ||
|
|
1db232da9e | ||
|
|
4cc844f410 | ||
|
|
024ae670cb | ||
|
|
429edda9c0 | ||
|
|
05b13b9ea3 | ||
|
|
b7320ce400 | ||
|
|
0c37b7b973 | ||
|
|
bb36dbd8d9 | ||
|
|
2dd8c40618 | ||
|
|
33128b0ccf | ||
|
|
cf25424295 | ||
|
|
7492074794 | ||
|
|
c4a491123e | ||
|
|
55ad88fe4e | ||
|
|
7170dbced8 | ||
|
|
b0971412a2 | ||
|
|
a6b374a681 | ||
|
|
2d0355b3b9 | ||
|
|
7fade101be | ||
|
|
0918da8569 | ||
|
|
917db622c4 | ||
|
|
f7ee6fbd20 | ||
|
|
5899e9a0be | ||
|
|
d41cb11545 | ||
|
|
3ad909a4ae | ||
|
|
4bafdf733c | ||
|
|
b825998c63 | ||
|
|
6b02ca47c3 | ||
|
|
ea1b85bffa | ||
|
|
3cffe47eea | ||
|
|
e5d5a9fb27 | ||
|
|
ca97fa63a9 | ||
|
|
f4cc27bc0e | ||
|
|
8cea575e2e | ||
|
|
c91baee4d5 | ||
|
|
8055ce29f7 | ||
|
|
4596ae48b8 | ||
|
|
6c268cdf21 | ||
|
|
fce977f1d7 | ||
|
|
a298075949 | ||
|
|
66599c3779 | ||
|
|
60340244b1 | ||
|
|
eb72ea3e5a | ||
|
|
ede6237b6f | ||
|
|
e91e10aae6 | ||
|
|
9c3cca0d25 | ||
|
|
8eee5367f3 | ||
|
|
40d55a3d44 | ||
|
|
75330304dc | ||
|
|
776c508418 | ||
|
|
e804741632 | ||
|
|
3d3cb4be4f | ||
|
|
64f4209119 | ||
|
|
2ede226ef9 | ||
|
|
f5cf641c0a | ||
|
|
1abd3419f6 | ||
|
|
75699db716 | ||
|
|
7c3572f08c | ||
|
|
9dacde6d07 | ||
|
|
8c3aab9a26 | ||
|
|
ba4550c953 | ||
|
|
d0ac65a934 | ||
|
|
a4c70bb029 | ||
|
|
795cf0c0b1 | ||
|
|
e64b90e322 | ||
|
|
d69b0973e1 | ||
|
|
6296f49653 | ||
|
|
9f2b739046 | ||
|
|
da1d5e5577 | ||
|
|
7333b4e392 | ||
|
|
b0442d0784 | ||
|
|
295e69f8f8 | ||
|
|
cfe844fa39 | ||
|
|
0f4ea2d2a6 | ||
|
|
4b85b05839 | ||
|
|
2539d08dce | ||
|
|
c26fd7a819 | ||
|
|
2053610429 | ||
|
|
cd4f83b299 | ||
|
|
ec29ba19a9 | ||
|
|
9dc03e0978 | ||
|
|
bc4258eca9 | ||
|
|
b0e58f9770 | ||
|
|
a1e2641c91 | ||
|
|
9108422f99 | ||
|
|
9e8f4b25ca | ||
|
|
1cecd24823 | ||
|
|
97f6e1469b | ||
|
|
ec46eaf224 | ||
|
|
a102692103 | ||
|
|
0376ec8ff0 | ||
|
|
5932a07610 | ||
|
|
6110b0c0b3 | ||
|
|
365e221d95 | ||
|
|
acbc4859c0 | ||
|
|
55750e05e7 | ||
|
|
ba9c4db673 | ||
|
|
ba8a63a69e | ||
|
|
25581981b5 | ||
|
|
02a6feed73 | ||
|
|
f3acedbf08 | ||
|
|
35ab4ffaab | ||
|
|
ddfb7f2c11 | ||
|
|
e2ca03f92d | ||
|
|
c75a3c68e5 | ||
|
|
5d617ea99b | ||
|
|
58059a2c48 | ||
|
|
4c2936773a | ||
|
|
c7c16ad9c1 | ||
|
|
7b676d608b | ||
|
|
48ecec1e2e | ||
|
|
9dc72e71d4 | ||
|
|
4a7a02b9af | ||
|
|
7cb460d2f3 | ||
|
|
0a7dac8744 | ||
|
|
667d595a73 | ||
|
|
2d2d957be5 | ||
|
|
5aef7afade | ||
|
|
d5e7b5616c | ||
|
|
9aa17a6cc2 | ||
|
|
0f13097f59 | ||
|
|
355ffbdaf8 | ||
|
|
45b0d63d72 | ||
|
|
c515271fbd | ||
|
|
6f3501876a | ||
|
|
f8afc5fa17 | ||
|
|
4ecda93147 | ||
|
|
41847162b1 | ||
|
|
0f7e010e3e | ||
|
|
8201ea0aa2 | ||
|
|
a7848c1822 | ||
|
|
d4abaeeecf | ||
|
|
871a82df0a | ||
|
|
ffbf5b0b47 | ||
|
|
9dcceaeb40 | ||
|
|
556e58a4ab | ||
|
|
b6c35743e6 | ||
|
|
0abd34f7e6 | ||
|
|
cafd7f8e39 | ||
|
|
43c0a0e65f | ||
|
|
7b359f46fd | ||
|
|
880827f6ce | ||
|
|
0c300058a3 | ||
|
|
d35be22f7d | ||
|
|
ff8d90061f | ||
|
|
e66109f9d0 | ||
|
|
1934c16f0f | ||
|
|
012ac7d9ec | ||
|
|
efb3b04225 | ||
|
|
1488d88c81 | ||
|
|
80a7f13460 | ||
|
|
8919fc22b1 | ||
|
|
b1273cb774 | ||
|
|
0843b8355e | ||
|
|
6457677fb4 | ||
|
|
f8a860bf21 | ||
|
|
f2bed33db8 | ||
|
|
7d2c6525d8 | ||
|
|
de652dc747 | ||
|
|
9f1053212b | ||
|
|
76690a3deb | ||
|
|
50f2f2fc98 | ||
|
|
5c27234d19 | ||
|
|
6f5d16f397 | ||
|
|
e42a43e3d1 | ||
|
|
bfd307cd57 | ||
|
|
beb5ee1333 | ||
|
|
cde871555d | ||
|
|
51b0ffa7bf | ||
|
|
255c819727 | ||
|
|
152ccb2ce8 | ||
|
|
bdb3adfeea | ||
|
|
236086bee5 | ||
|
|
1436753e6d | ||
|
|
eadf8ef799 | ||
|
|
f1e20cf6ff | ||
|
|
82a0851526 | ||
|
|
07a992e6d3 | ||
|
|
f642c2baa8 | ||
|
|
2f7743cafb | ||
|
|
44112f2d87 | ||
|
|
99c4810770 | ||
|
|
9f2ac15695 | ||
|
|
19c1ee157f | ||
|
|
973270772b | ||
|
|
7334326042 | ||
|
|
4043e8e8b9 | ||
|
|
7fd403998c | ||
|
|
1f7fcc2985 | ||
|
|
ba19bd36a4 | ||
|
|
e119681b1f | ||
|
|
fbe22e53a9 | ||
|
|
79e826fcc8 | ||
|
|
cf940268b9 | ||
|
|
96bb572307 | ||
|
|
5dafe0b66a | ||
|
|
29e24a4cbe | ||
|
|
f979d55b71 | ||
|
|
164b2116a3 | ||
|
|
55e623a099 | ||
|
|
a60b4b1302 | ||
|
|
bf23e59bbf | ||
|
|
eb4cee89c5 | ||
|
|
fb94a87a4d | ||
|
|
9613c7fdb6 | ||
|
|
d8c97fba15 | ||
|
|
0f663560d4 | ||
|
|
4901075960 | ||
|
|
4aec242979 | ||
|
|
d1d95e0e49 | ||
|
|
d3c643b004 | ||
|
|
98eb30c482 | ||
|
|
2d43ffb5b4 | ||
|
|
a195701de2 | ||
|
|
f639f4bea7 | ||
|
|
334cbb06c6 | ||
|
|
f4a3b2f01a | ||
|
|
dbe6f1b9a9 | ||
|
|
73ada57a17 | ||
|
|
8e2b743f7e | ||
|
|
a533042503 | ||
|
|
49953e3464 | ||
|
|
0bf95d6aea | ||
|
|
7d88a1ca0b | ||
|
|
ec74eb41cf | ||
|
|
3139482358 | ||
|
|
32f19aff99 | ||
|
|
23bead9226 | ||
|
|
bd3812c255 | ||
|
|
e498185a76 | ||
|
|
167eda4750 | ||
|
|
3b52ddce6d | ||
|
|
0e771c5d38 | ||
|
|
2ec1544f2d | ||
|
|
049ef430b2 | ||
|
|
34eb2babdb | ||
|
|
8706754550 | ||
|
|
c7b507e119 | ||
|
|
221c632c05 | ||
|
|
7dbde208ef | ||
|
|
52a2e3e17c | ||
|
|
fa22d7dca0 | ||
|
|
9fcdebde08 | ||
|
|
92157161f0 | ||
|
|
82b5479436 | ||
|
|
91a037af55 | ||
|
|
067fccc2c9 | ||
|
|
348c0d2542 | ||
|
|
f2f6bbb02c | ||
|
|
16f7b967b5 | ||
|
|
270a8be68d | ||
|
|
82254d9d9b | ||
|
|
759a265fb0 | ||
|
|
ee46f45c90 | ||
|
|
c45ce61550 | ||
|
|
b36cf11ac8 | ||
|
|
dca0f72e4d | ||
|
|
68a99ed1e9 | ||
|
|
af4feb4d88 | ||
|
|
de1e965fec | ||
|
|
430c5df0e7 | ||
|
|
9b12f799f7 | ||
|
|
f3a9c6ee5d | ||
|
|
e0aceeafef | ||
|
|
7643d86047 | ||
|
|
98af01a73c | ||
|
|
e280a810c3 | ||
|
|
7a59575d1e | ||
|
|
b01d8448a0 | ||
|
|
9b3c8569f7 | ||
|
|
12104f822f | ||
|
|
b4cd2df745 | ||
|
|
887ffed84c | ||
|
|
9be3d9c8e1 | ||
|
|
9d3dff3b7a | ||
|
|
55114ec631 | ||
|
|
9c3d00d3c3 | ||
|
|
90b8826e73 | ||
|
|
65f39bbf6f | ||
|
|
e9eced846f | ||
|
|
a0befe349d | ||
|
|
04992effb3 | ||
|
|
9ae54d2a50 | ||
|
|
fe72a40159 | ||
|
|
ea510d09d0 | ||
|
|
375689a1ff | ||
|
|
9908e331b7 | ||
|
|
cd8655708d | ||
|
|
62b94f297a | ||
|
|
01d399ee3c | ||
|
|
30e3908484 | ||
|
|
ff12046009 | ||
|
|
1a058b4a6e | ||
|
|
02dfd18023 | ||
|
|
9ab7df5f47 | ||
|
|
7a5b140f92 | ||
|
|
6f83111c55 | ||
|
|
f3f60368da | ||
|
|
7a09640b20 | ||
|
|
2916d1262b | ||
|
|
741abb73d2 | ||
|
|
2e46755260 | ||
|
|
2cff9519e1 | ||
|
|
f9c2c6e988 | ||
|
|
5ae3dc01f1 | ||
|
|
af4fd69dd0 | ||
|
|
4d4493f325 | ||
|
|
e70d474b39 | ||
|
|
1b45f64858 | ||
|
|
b89cf6768f | ||
|
|
36ad1108b4 | ||
|
|
4c04371ea4 | ||
|
|
d3e385c554 | ||
|
|
6afcef9805 | ||
|
|
ed861e230b | ||
|
|
e15ced2922 | ||
|
|
93052e532f | ||
|
|
198d51ddaa | ||
|
|
8730b24def | ||
|
|
f09c0d5998 | ||
|
|
21e4481ab7 | ||
|
|
2f61754a24 | ||
|
|
3910d18bc9 | ||
|
|
583111ebfb | ||
|
|
1b15481460 | ||
|
|
fd9c98ff86 | ||
|
|
41b5607ef3 | ||
|
|
ae77ea807f | ||
|
|
ad44190c6b | ||
|
|
024e4454a1 | ||
|
|
14dddcda36 | ||
|
|
d4fb924b6a | ||
|
|
b02c97af60 | ||
|
|
cc611cb71c | ||
|
|
b8a01a9919 | ||
|
|
55c99661be | ||
|
|
1563b216df | ||
|
|
a9d4b485d9 | ||
|
|
360daa6267 | ||
|
|
724bf52929 | ||
|
|
7407b37bd9 | ||
|
|
da765cc4c1 | ||
|
|
4f862eee6e | ||
|
|
e05d7cf49a | ||
|
|
fd8e94a90f | ||
|
|
a6cf28c5b5 | ||
|
|
6b07b13a8e | ||
|
|
561c4dcc25 | ||
|
|
b516ea596a | ||
|
|
248758eee3 | ||
|
|
a808602ae0 | ||
|
|
40e3436e95 | ||
|
|
f704770b26 | ||
|
|
330665f150 | ||
|
|
af41899d74 | ||
|
|
d12f4d0bc8 | ||
|
|
97680e9dfd | ||
|
|
51341ca6c3 | ||
|
|
ab54bfa50e | ||
|
|
60aa933fb6 | ||
|
|
1a299b2bcc | ||
|
|
37f662d790 | ||
|
|
b0317f9bab | ||
|
|
be2dfaf081 | ||
|
|
2c8437ae92 | ||
|
|
2a0bcfd086 | ||
|
|
2cf41afac3 | ||
|
|
e318f5f3be | ||
|
|
939decb86c | ||
|
|
1baa0df948 | ||
|
|
e8956a8c44 | ||
|
|
2f0fdbbc26 | ||
|
|
5f931525bc | ||
|
|
b86545a320 | ||
|
|
06e75c42bf | ||
|
|
05dd65244d | ||
|
|
c4ebfeb0fa | ||
|
|
1aa0bbfac9 | ||
|
|
58f1e6cbc6 | ||
|
|
83e0be3038 | ||
|
|
5fc242e4ec | ||
|
|
dc101adad3 | ||
|
|
faade72787 | ||
|
|
2a78ae9889 | ||
|
|
9840639843 | ||
|
|
82c21a901e | ||
|
|
e1c83144c1 | ||
|
|
ef2ac73215 | ||
|
|
735d8955bf | ||
|
|
3abee0a4fa | ||
|
|
b6f18b4f2b | ||
|
|
85cd0465fa | ||
|
|
0452e0fdd2 | ||
|
|
462ff572b3 | ||
|
|
d11099bb2b | ||
|
|
f5c4684d3e | ||
|
|
876a22578b | ||
|
|
9f5e8b296b | ||
|
|
d9deb02edc | ||
|
|
a402d0cdeb | ||
|
|
683fb62505 | ||
|
|
941474983d | ||
|
|
2b42773e01 | ||
|
|
8277a532f4 | ||
|
|
539784b640 | ||
|
|
f373f8f003 | ||
|
|
8605e835eb | ||
|
|
b4ace2043a | ||
|
|
444a64e934 | ||
|
|
8ea2ae924d | ||
|
|
4ceb1d6f5e | ||
|
|
3c81899ca7 | ||
|
|
ab59fd08e5 | ||
|
|
19b05b5e61 | ||
|
|
65a44a1e13 | ||
|
|
d38f18af40 | ||
|
|
2744b9f31f | ||
|
|
4deed35212 | ||
|
|
bc9ae5ea8b | ||
|
|
87d879e236 | ||
|
|
f657598c72 | ||
|
|
2a5cb9d21b | ||
|
|
cf7d6b655e | ||
|
|
6d2723eec5 | ||
|
|
6834cc5b46 | ||
|
|
9b949e574f | ||
|
|
a75af0a5d2 | ||
|
|
080b26769c | ||
|
|
e037ae7bc9 | ||
|
|
c60ad89937 | ||
|
|
4194857086 | ||
|
|
1179c44c5b | ||
|
|
f6d9b270c9 | ||
|
|
1be0159b01 | ||
|
|
61ba8ad997 | ||
|
|
89e31085d2 | ||
|
|
920c84a1f2 | ||
|
|
ed56fecd04 | ||
|
|
f0bfdfb699 | ||
|
|
b02a1112bc | ||
|
|
590a165776 | ||
|
|
2fd1b2a484 | ||
|
|
8f9d02d689 | ||
|
|
b376b6b33b | ||
|
|
8292d6d8ad | ||
|
|
d6a5c39079 | ||
|
|
2a9a59f784 | ||
|
|
abf4a5495a | ||
|
|
f8b8723bef | ||
|
|
6b9686f2dd | ||
|
|
4a439d8c8e | ||
|
|
c526a3eb04 | ||
|
|
ba516901af | ||
|
|
8f52229a86 | ||
|
|
5b793f8882 | ||
|
|
b31c14c52a | ||
|
|
78b72512cb | ||
|
|
2fbb3cad9f | ||
|
|
2621081a13 | ||
|
|
8daf95bf59 | ||
|
|
6e8ab16b25 | ||
|
|
a5cda5caa7 | ||
|
|
13a6c69668 | ||
|
|
380293d030 | ||
|
|
0b15a97013 | ||
|
|
11af066956 | ||
|
|
d7b4d342c3 | ||
|
|
77aeebe2a8 | ||
|
|
c3a08d413f | ||
|
|
23ac2319af | ||
|
|
a1bc0704ab | ||
|
|
0bbfd427af | ||
|
|
f17b268a71 | ||
|
|
9ffc265bea | ||
|
|
6f664ca64e | ||
|
|
8a4a76000d | ||
|
|
e83daf87d4 | ||
|
|
8ed90d3af2 | ||
|
|
0bb311f8ce | ||
|
|
53f0f0302b | ||
|
|
c25a5d2480 | ||
|
|
fc8540d88a | ||
|
|
31a4195c81 | ||
|
|
bf0e4ede00 | ||
|
|
3757bc6b9a | ||
|
|
2e01f220da | ||
|
|
8ae4e1fdf2 | ||
|
|
f6219ec15a | ||
|
|
6a82eb5a5c | ||
|
|
a241300ff1 | ||
|
|
d5548a6ff9 | ||
|
|
ba6cb112c3 | ||
|
|
8f1bb84930 | ||
|
|
235726eee6 | ||
|
|
08183ef490 | ||
|
|
dc6fc3b30a | ||
|
|
76f2eb5684 | ||
|
|
4f33687957 | ||
|
|
74f37fe0a3 | ||
|
|
cc5e4bce52 | ||
|
|
f441a7cae8 | ||
|
|
fc2be81c43 | ||
|
|
1277a8f67f | ||
|
|
86c6d4e769 | ||
|
|
bf2d527cfe | ||
|
|
6b59ea8eac | ||
|
|
72e3cb9243 | ||
|
|
5e5ede6058 | ||
|
|
d25944ea1f | ||
|
|
fce2aa8fa3 | ||
|
|
0112c63779 | ||
|
|
6a4e93bf0f | ||
|
|
4328e920d2 | ||
|
|
bbbf0a895d | ||
|
|
3289b33806 | ||
|
|
f4b9faa6b3 | ||
|
|
239b77816f | ||
|
|
8565e2b4e5 | ||
|
|
4317a46a3e | ||
|
|
81ca29adc3 | ||
|
|
c1a6ff7f44 | ||
|
|
7e6e5d4746 | ||
|
|
12d650e195 | ||
|
|
8fb58492df | ||
|
|
2c0c2f12df | ||
|
|
01e5354fd9 | ||
|
|
0b100c4273 | ||
|
|
340e75eb59 | ||
|
|
53808a6d45 | ||
|
|
e6326332b6 | ||
|
|
9e0cf84505 | ||
|
|
b7eea7b08c | ||
|
|
92dd67856e | ||
|
|
a2bb587e24 | ||
|
|
0c570cb599 | ||
|
|
db6fab2c8f | ||
|
|
d92deb52b6 | ||
|
|
b8b70f2f4a | ||
|
|
a8a3f6d34d | ||
|
|
9847d226e1 | ||
|
|
3d48a16305 | ||
|
|
3d24cc9ae5 | ||
|
|
5acc58dd68 | ||
|
|
34f02f06a6 | ||
|
|
6d3fe5b85c | ||
|
|
3878bd812c | ||
|
|
0717eaddce | ||
|
|
102cbbe493 | ||
|
|
d981b30194 | ||
|
|
0fc02f2cf0 | ||
|
|
f24b5164d4 | ||
|
|
4be27ee72c | ||
|
|
f0070e4828 | ||
|
|
ce8beec22c | ||
|
|
b30bdf2294 | ||
|
|
63b44a3e6e | ||
|
|
74aaf848ed | ||
|
|
95de5400e6 | ||
|
|
fe7079802b | ||
|
|
61ddb14e25 | ||
|
|
ca7a93cd64 | ||
|
|
90a1c81d30 | ||
|
|
5e9089d104 | ||
|
|
1a716943bc | ||
|
|
c28415c38a | ||
|
|
e1491de6b8 | ||
|
|
253ea8cd18 | ||
|
|
d37bad3149 | ||
|
|
a2b912bc77 | ||
|
|
f1bfbe44e2 | ||
|
|
dbdd07d0b8 | ||
|
|
166909998e | ||
|
|
a8ec4c965c | ||
|
|
d2aff67c6c | ||
|
|
3353de225d | ||
|
|
203ebeef20 | ||
|
|
032cf990c3 | ||
|
|
16cdb43c67 | ||
|
|
6f622033c5 | ||
|
|
531d4f1937 | ||
|
|
f155bc249c | ||
|
|
452d0ef30e | ||
|
|
005754ba98 | ||
|
|
c3c4cf17e3 | ||
|
|
0866e5a403 | ||
|
|
15f5e658fc | ||
|
|
574e6da132 | ||
|
|
da6d27ed16 | ||
|
|
4e87809ff9 | ||
|
|
f4267aaab0 | ||
|
|
4f255d103a | ||
|
|
502cc13aed | ||
|
|
0a1154e6fd | ||
|
|
f5b3d72730 | ||
|
|
e9bcccffbd | ||
|
|
aaf4cbf06f | ||
|
|
5080534974 | ||
|
|
02cb397873 | ||
|
|
d9169a87ad | ||
|
|
f3b6f2fc61 | ||
|
|
04cc24ee82 | ||
|
|
f32079ef42 | ||
|
|
d1b69656ae | ||
|
|
09453a490b | ||
|
|
e2e7627f0f | ||
|
|
4fe24a9a3b | ||
|
|
d26e7ad577 | ||
|
|
571cb4928f | ||
|
|
c12e8122f8 | ||
|
|
92e7a01d14 | ||
|
|
b9ca9d42dc | ||
|
|
479c3e477a | ||
|
|
2c3d3d8105 | ||
|
|
ea03f67505 | ||
|
|
ee0c88a070 | ||
|
|
98206df864 | ||
|
|
1066a42fb2 | ||
|
|
062175586c | ||
|
|
0dc6b582a6 | ||
|
|
d8d70ba137 | ||
|
|
f23c916520 | ||
|
|
8ae4601177 | ||
|
|
9a466d3ef9 | ||
|
|
713845d14c | ||
|
|
471d60e5cd | ||
|
|
43864e0686 | ||
|
|
4c2ae5dd19 | ||
|
|
a540cbe801 | ||
|
|
34cc577fa2 | ||
|
|
c855b55133 | ||
|
|
16c86c25b7 | ||
|
|
4345f7945b | ||
|
|
f44c93add2 | ||
|
|
09e45c51a4 | ||
|
|
1a42b72b15 | ||
|
|
d30415d74a | ||
|
|
616ef8d840 | ||
|
|
56437f94bc | ||
|
|
881fa6430b | ||
|
|
b7971690f3 | ||
|
|
c01d0abbd3 | ||
|
|
7043119346 | ||
|
|
b5325df57f | ||
|
|
0fc958e0fc | ||
|
|
9cb16711dd | ||
|
|
04766b13f5 | ||
|
|
433d704739 | ||
|
|
30204d2ee6 | ||
|
|
374b7cca2c | ||
|
|
152ae388f0 | ||
|
|
04344026bb | ||
|
|
cfffaf6cdb | ||
|
|
2952d94e60 | ||
|
|
0276c3ae81 | ||
|
|
c00f8dce3f | ||
|
|
4e24ae39cf | ||
|
|
12bd6494b7 | ||
|
|
e35c7550fe | ||
|
|
e7046abe72 | ||
|
|
affa7f0c6f | ||
|
|
be650ffc61 | ||
|
|
3078d48178 | ||
|
|
0be93563dd | ||
|
|
3e55980145 | ||
|
|
470ebf3a46 | ||
|
|
b695369126 | ||
|
|
f4611469b4 | ||
|
|
68bfafe745 | ||
|
|
f72782b71c | ||
|
|
0f1f5e3565 | ||
|
|
dfe126f3d4 | ||
|
|
4c9cb957a9 | ||
|
|
8f997f8825 | ||
|
|
d789a6e7aa | ||
|
|
4007148d9f | ||
|
|
998f1d544e | ||
|
|
deed48a3db | ||
|
|
00c0a958db | ||
|
|
1511dcbd73 | ||
|
|
12fef25803 | ||
|
|
fd30eb1839 | ||
|
|
63344eb0a4 | ||
|
|
6e4e11a365 | ||
|
|
e330efe058 | ||
|
|
ce86eca8b0 | ||
|
|
03dbaa3e0e | ||
|
|
2bd35fac6e | ||
|
|
cdca4e50d9 | ||
|
|
bb041c1bd6 | ||
|
|
a36c1b4a92 | ||
|
|
b760daca21 | ||
|
|
ff63d8f60c | ||
|
|
74f04ed6a1 | ||
|
|
74d880bf18 | ||
|
|
5ce38cacaa | ||
|
|
829f642ad8 | ||
|
|
80a4b95da4 | ||
|
|
dc2a20dbcd | ||
|
|
f6278e43ce | ||
|
|
30bc80000b | ||
|
|
ef56042c93 | ||
|
|
b6498103db | ||
|
|
7af4302d07 | ||
|
|
543770960c | ||
|
|
a2975a72cc | ||
|
|
beb3fd51d8 | ||
|
|
9360860601 | ||
|
|
7d4ecea8fb | ||
|
|
a44831b3fa | ||
|
|
8357f3900f | ||
|
|
6b1c5bc358 | ||
|
|
3564309a77 | ||
|
|
c9518bb60d | ||
|
|
0f1215e33e | ||
|
|
d7b0b5bec0 | ||
|
|
3e5af404ab | ||
|
|
1818094577 | ||
|
|
6d712b3d14 | ||
|
|
11389fe165 | ||
|
|
0ee9531db3 | ||
|
|
1622d2498d | ||
|
|
b76e6f8e5b | ||
|
|
beac006832 | ||
|
|
20d7603c0b | ||
|
|
24b13c5e49 | ||
|
|
9e21074e88 | ||
|
|
9a825bced7 | ||
|
|
fcb78436c6 | ||
|
|
bb30a64f8d | ||
|
|
b483c16fe2 | ||
|
|
569f046045 | ||
|
|
4e969d3d92 | ||
|
|
0bca1de285 | ||
|
|
3a5bd06a7e | ||
|
|
66a908aaa7 | ||
|
|
cd0ed08237 | ||
|
|
dd84b554e6 | ||
|
|
b51411f090 | ||
|
|
4cc843ded3 | ||
|
|
47d253c732 | ||
|
|
09901274ab | ||
|
|
35196e20c7 | ||
|
|
35af771a29 | ||
|
|
dee80caa09 | ||
|
|
46b7cc0a72 | ||
|
|
3b189e22b7 | ||
|
|
6ca565d7fb | ||
|
|
64f5480f96 | ||
|
|
828fdc8769 | ||
|
|
6763c4415e | ||
|
|
fb30e79e03 | ||
|
|
85fb4304b0 | ||
|
|
c2da77d7ec | ||
|
|
c54c3d3c15 | ||
|
|
2a7c954155 | ||
|
|
3fb7f7c7cc | ||
|
|
c4b2818336 | ||
|
|
061561bfd8 | ||
|
|
d4944d606b | ||
|
|
736b689c3b | ||
|
|
e12b377014 | ||
|
|
5fd5b815ab | ||
|
|
92db8312f6 | ||
|
|
1f2f4ce4f3 | ||
|
|
e080fe547d | ||
|
|
b967ecf063 | ||
|
|
365b7285d2 | ||
|
|
a40d532b0e | ||
|
|
0487bf911d | ||
|
|
57c72d1cd0 | ||
|
|
335bdffec2 | ||
|
|
e1d76a1dfe | ||
|
|
a4845323a2 | ||
|
|
792951b489 | ||
|
|
5adda836af | ||
|
|
4c2c3098c3 | ||
|
|
087c714098 | ||
|
|
5a33e4fe05 | ||
|
|
5f8667eaa7 | ||
|
|
31b4468514 | ||
|
|
2be9678bbe | ||
|
|
b5210877cf | ||
|
|
a8702be756 | ||
|
|
0995cc3f4e | ||
|
|
6491018c21 |
8
.babelrc
8
.babelrc
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"experimental": true,
|
||||
"playground": true,
|
||||
"loose": true,
|
||||
"blacklist": ["es6.tailCall"]
|
||||
"stage": 0,
|
||||
"loose": ["all"],
|
||||
"blacklist": ["es6.tailCall"],
|
||||
"optional": ["optimisation.flow.forOf"]
|
||||
}
|
||||
|
||||
10
.eslintrc
10
.eslintrc
@@ -3,18 +3,22 @@
|
||||
"rules": {
|
||||
"strict": 0,
|
||||
"no-underscore-dangle": 0,
|
||||
"no-unused-vars": 0,
|
||||
"curly": 0,
|
||||
"no-multi-spaces": 0,
|
||||
"key-spacing": 0,
|
||||
"no-return-assign": 0,
|
||||
"consistent-return": 0,
|
||||
"no-shadow": 0,
|
||||
"no-comma-dangle": 0,
|
||||
"comma-dangle": 0,
|
||||
"no-use-before-define": 0,
|
||||
"no-empty": 0,
|
||||
"new-parens": 0,
|
||||
"no-cond-assign": 0
|
||||
"no-cond-assign": 0,
|
||||
"no-fallthrough": 0,
|
||||
"new-cap": 0,
|
||||
"no-loop-func": 0,
|
||||
"no-unreachable": 0,
|
||||
"no-labels": 0
|
||||
},
|
||||
"env": {
|
||||
"node": true
|
||||
|
||||
14
.gitignore
vendored
14
.gitignore
vendored
@@ -8,10 +8,10 @@ test/core/tmp
|
||||
/browser.js
|
||||
/browser-polyfill.js
|
||||
/runtime.js
|
||||
coverage
|
||||
dist
|
||||
.package.json
|
||||
packages/babel-runtime/core-js
|
||||
packages/babel-runtime/helpers/*.js
|
||||
packages/babel-runtime/regenerator/*.js
|
||||
lib
|
||||
/coverage
|
||||
/dist
|
||||
/.package.json
|
||||
/packages/babel-runtime/core-js
|
||||
/packages/babel-runtime/helpers/*.js
|
||||
/packages/babel-runtime/regenerator/*.js
|
||||
/lib
|
||||
|
||||
9
.gitmodules
vendored
9
.gitmodules
vendored
@@ -1,12 +1,3 @@
|
||||
[submodule "vendor/traceur"]
|
||||
path = vendor/traceur
|
||||
url = https://github.com/google/traceur-compiler
|
||||
[submodule "vendor/regenerator"]
|
||||
path = vendor/regenerator
|
||||
url = https://github.com/babel/regenerator-babel
|
||||
[submodule "vendor/test262"]
|
||||
path = vendor/test262
|
||||
url = https://github.com/tc39/test262
|
||||
[submodule "vendor/compat-table"]
|
||||
path = vendor/compat-table
|
||||
url = https://github.com/kangax/compat-table
|
||||
|
||||
12
.travis.yml
12
.travis.yml
@@ -1,5 +1,8 @@
|
||||
sudo: false
|
||||
#sudo: false
|
||||
language: node_js
|
||||
cache:
|
||||
directories:
|
||||
- node_modules
|
||||
node_js:
|
||||
- "0.12"
|
||||
- "iojs"
|
||||
@@ -8,9 +11,4 @@ before_script: "npm install -g codeclimate-test-reporter"
|
||||
script: "make test-travis"
|
||||
|
||||
notifications:
|
||||
webhooks:
|
||||
urls:
|
||||
- https://webhooks.gitter.im/e/acf1870e9d223c65e8d5
|
||||
on_success: always
|
||||
on_failure: always
|
||||
on_start: false
|
||||
slack: babeljs:5Wy4QX13KVkGy9CnU0rmvgeK
|
||||
|
||||
450
CHANGELOG.md
450
CHANGELOG.md
@@ -13,6 +13,456 @@ _Note: Gaps between patch versions are faulty/broken releases._
|
||||
|
||||
See [CHANGELOG - 6to5](CHANGELOG-6to5.md) for the pre-4.0.0 version changelog.
|
||||
|
||||
## 5.6.4
|
||||
|
||||
* **Internal**
|
||||
* Add `ParenthesizedExpression` node type.
|
||||
|
||||
## 5.6.3
|
||||
|
||||
* **Bug Fix**
|
||||
* Fix rest parameter array allocation loop being incorrectly aliased.
|
||||
|
||||
## 5.6.2
|
||||
|
||||
* **Bug Fix**
|
||||
* Fix method key literals not turning into computed member expression in loose mode.
|
||||
* Elect rest parameters in spread element position as candidates instead of replacing them in place.
|
||||
|
||||
## 5.6.0
|
||||
|
||||
* **Bug Fix**
|
||||
* Fix istanbul interop for register hook when registering for non-existence extension.
|
||||
* Fix super class constructor call differing for no constructor in derived classes.
|
||||
* Disable module import receiver when in loose mode.
|
||||
* Fix duplicate filenames when using `babel` CLI when passing multiple matching patterns.
|
||||
* Register labels as bindings to fix undeclared variable checks.
|
||||
* **Polish**
|
||||
* Remove unnecessary string binary expressions when transforming template literals.
|
||||
* Support module live bindings in arbitary positions not in Program statement position.
|
||||
* Throw error when attemping to replace a `Program` root node with another node not of type `Program`.
|
||||
* Optimise rest parameters in spread element position and allocate rest array at the earliest common ancestor of all references.
|
||||
* Generate original number representation when value was not changed.
|
||||
* Check for invalid binding identifiers when generating inferred method names.
|
||||
* Don't terminate CLI when watching files fail compilation on init.
|
||||
* **New Feature**
|
||||
* Add new plugin API.
|
||||
* **Internal**
|
||||
* Split react displayName addition into a plugin.
|
||||
* Add check for `JSXMemberExpression` to `t.isReferenced`.
|
||||
* Move `validation.undeclaredVariableCheck` transformer up.
|
||||
* Start great core-to-plugin exodus.
|
||||
* Add `BindingIdentifier` virtual type.
|
||||
* Hidden class optimisations.
|
||||
* Array allocation optimisations.
|
||||
* Update `regenerator`.
|
||||
* Update `js-tokens`.
|
||||
* Sync with upstream Acorn.
|
||||
|
||||
## 5.5.8
|
||||
|
||||
* **Internal**
|
||||
* Remove extremely unprofessional and harsh error message for those hotlinking to `resolve-rc`.
|
||||
|
||||
## 5.5.7
|
||||
|
||||
* **Bug Fix**
|
||||
* Push newline after decorators when doing code gen.
|
||||
* Rewriting error handling to normalise options before merging them.
|
||||
* Remove duplicate keys in `alias-keys.json` causing errors in strict mode.
|
||||
* Fix `$ babel --help` not showing optional transformers as such.
|
||||
* **New Feature**
|
||||
* Add `auxiliaryCommentBefore` and `auxiliaryCommentAfter` options.
|
||||
|
||||
## 5.5.6
|
||||
|
||||
* **Bug Fix**
|
||||
* Fix `let` binding collision in loop head not properly replacing `AssignmentExpression`s.
|
||||
|
||||
## 5.5.5
|
||||
|
||||
* **Bug Fix**
|
||||
* Fix `file.opts` not being set before `file.log.deprecate` was called causing a `ReferenceError` as it was checking for a property on it.
|
||||
|
||||
## 5.5.4
|
||||
|
||||
* **Bug Fix**
|
||||
* Add back missing `shouldIgnore` check.
|
||||
* Log message on deprecated options rather than throw an error.
|
||||
* Fix name of `auxiliaryComment` option when attempting Istanbul interop in `babel/register`.
|
||||
|
||||
## 5.5.3
|
||||
|
||||
* **Bug Fix**
|
||||
* Fix weird state bug when traversing overa `node` `ClassProperty` instead of `path` in the `es6.classes` transformer.
|
||||
|
||||
## 5.5.2
|
||||
|
||||
* **Bug Fix**
|
||||
* Fix `NodePath#isPure` on `Property` nodes.
|
||||
* Use cwd instead of entry file directory when working out relative directory for `babel/register`.
|
||||
* **Internal**
|
||||
* Add scary warning for those few who choose to use the WIP experimental transformers.
|
||||
|
||||
## 5.5.1
|
||||
|
||||
* **Bug Fix**
|
||||
* Remove `ClassProperty` nodes always in the `Flow` transformer. This is fine now since class properties aren't supported in any engine that supports classes but the `es7.classProperties` transformer will need to be updated in the future to desugar to ES6 classes instead of relying on the `es6.classes` transformer from being ran.
|
||||
|
||||
## 5.5.0
|
||||
|
||||
* **Bug Fix**
|
||||
* Allow pushing declarations to `SwitchStatement`s.
|
||||
* Fix `minification.removeDebugger` to remove `DebuggerStatement`s rather than `ExpressionStatement`s with an identifier of `debugger`.
|
||||
* Check LHS in `ForInStatement` and `ForOfStatement` for constant violations.
|
||||
* Register function `id` as a reference when naming methods to avoid collisions.
|
||||
* Support key literals when checking for the existence of `displayName` property when attempting to add it for `React.createClass`.
|
||||
* Remove `ExportDefaultSpecifier` check from `t.isDefaultSpecifier`.
|
||||
* Don't consider `JSXIdentifier` HTML tag identifiers to be references.
|
||||
* **Polish**
|
||||
* Update `minification.deadCodeElimination` transformer to remove all statements after completion statements.
|
||||
* Update `minification.deadCodeElimination` transformer to not inline single used bindings that exist in different scopes.
|
||||
* When performing Istanbul interop in `babel/register`, add the auxiliary comment `"istanbul ignore text"` to get more accurate coverage.
|
||||
* Add `--nolazy` argument to `babel-node`.
|
||||
* Add support for `cluster` forking.
|
||||
* Perform scope tracking in a single pass instead of multiple.
|
||||
* Smarten up type inferrence and resolution to support the whole array of language constructs.
|
||||
* Optimise module metadata retrieval into a single pass.
|
||||
* Ignore trailing commas when inferring newlines.
|
||||
* Rename `minification.inlineExpressions` transformer to `minification.constantFolding`.
|
||||
* Check path relative to entry file when checking to see if we're inside `node_modules` when using `babel/register`.
|
||||
* Upgrade `regenerator`.
|
||||
|
||||
## 5.4.7
|
||||
|
||||
* **Bug Fix**
|
||||
* Don't consider `JSXAttribute` `names` to be valid `ReferencedIdentifier`s.
|
||||
|
||||
## 5.4.6
|
||||
|
||||
* **Bug Fix**
|
||||
* Fix `spec.functionName` transformer incorrectly attempting to rename a binding that doesn't exist as it's a global.
|
||||
* **Internal**
|
||||
* Deprecate custom module formatters.
|
||||
|
||||
## 5.4.5
|
||||
|
||||
* **Bug Fix**
|
||||
* Add `JSXIdentifier` as a valid `ReferencedIdentifier` visitor virtual type.
|
||||
* Ignore `CallExpression` `_prettyCall` when the `retainLines` option is enabled.
|
||||
* Inherit comments to new declaration node when exploding module declarations.
|
||||
* Fix `es6.tailCall` transformer failing on calls that exceed the max parameters of the function.
|
||||
|
||||
## 5.4.4
|
||||
|
||||
* **Bug Fix**
|
||||
* Fix bug where replacing variable declarations in the head of a `for` loop would turn them into `ExpressionStatement`s.
|
||||
* Fix renaming of assignment expressions that were non-identifiers ie. patterns.
|
||||
* Force space before `class` `id` to avoid breaking named classes when using `compact` mode.
|
||||
* Add assignment pattern explosion to avoid initial duplicate nodes.
|
||||
* Ignore this and arguments when performing TCO on shadowed functions.
|
||||
* **Polish**
|
||||
* Rename `sourceMapName` option to `sourceMapTarget`. Thanks [@getify](https://github.com/getify)!
|
||||
* Better detection of completion records, ignore those in `Function`s.
|
||||
* Clarified descriptions of the options that are enabled by default.
|
||||
* Resolve `\`babel-plugin-${name}\`` plugin names **before** just checking the `name`. Thanks [@jquense](https://github.com/jquense)!
|
||||
* Update AMD module formatter to add import default remapping.
|
||||
|
||||
## 5.4.3
|
||||
|
||||
* **Bug Fix**
|
||||
* Fix `module` being incorrectly rewritten when used as in an export declaration.
|
||||
* When performing single-reference inlining, ensure that the single reference isn't a child of the binding itself.
|
||||
* Fix a bug in `minification.deadCodeElimination` where a new binding instance was being created for local class bindings instead of just inheriting the parent one.
|
||||
* Fix bug with paren printing in `compact` and `retainLines` mode where a left paren was already printed before catching up.
|
||||
* **Internal**
|
||||
* Handle contexts for paths much better. This will ensure that the path node location info is in sync.
|
||||
|
||||
## 5.4.2
|
||||
|
||||
* **Polish**
|
||||
* `ignore` and `only` patterns are now **very** liberal. The pattern can now exist anywhere in the path.
|
||||
|
||||
## 5.4.1
|
||||
|
||||
* **Bug Fix**
|
||||
* Add missing `slash` dependency. Thanks [@browncolyn](https://github.com/browncolyn)!
|
||||
* **Polish**
|
||||
* Clean up `shouldIgnore` algorithm to work how you'd expect rather than being a hacky piece of shit. It now crawls the entire path, checking each section of it against the input ignore/only patterns. This means that the pattern `foo` will ignore the paths `foo/bar.js`, `bar/foo` etc.
|
||||
|
||||
## 5.4.0
|
||||
|
||||
* **New Feature**
|
||||
* Added [function bind syntax](https://github.com/zenparsing/es-function-bind) behind stage 0. Thanks [@RReverser](https://github.com/rreverser)!
|
||||
* Added `env` option. Especially handy when using the `.babelrc`.
|
||||
* **Bug Fix**
|
||||
* Fix files not properly being ignored when `babel.transform` ignores them when using `$ babel`.
|
||||
* Fix scope tracking registering loop head bindings to their `VariableDeclaration` instead of `VariableDeclarator`.
|
||||
* **Polish**
|
||||
* Normalise path separators for souce map paths when using `$ babel`.
|
||||
* Rework `PathHoister` to ignore global references and to not deopt on reassignments to referenced bindings, instead it tries to hoist to the highest scope.
|
||||
* Added missing exponential operator inlining. Thanks [@nkt](https://github.com/nkt)!
|
||||
* Optimise `regenerator` transformer. Thanks [@benjamn](https://github.com/benjamn)!
|
||||
|
||||
## 5.3.3
|
||||
|
||||
* **Bug Fix**
|
||||
* Fix `minification.deadCodeElimination` transformer incorrectly trying to inline import declarations.
|
||||
* Fix `minification.inlineExpression` transformer getting into an infinite loop.
|
||||
|
||||
## 5.3.2
|
||||
|
||||
* **Bug Fix**
|
||||
* Fix patterns not being considered when hoisting variables in the `es6.blockScoping` transformer.
|
||||
|
||||
## 5.3.1
|
||||
|
||||
* **Bug Fix**
|
||||
* Fix unique export specifiers not being cloned when exploding class and function exports,
|
||||
* **Polish**
|
||||
* Turn import remaps to sequence expressions to remove their context and improve performance.
|
||||
|
||||
## 5.3.0
|
||||
|
||||
**Speeeeeeed**
|
||||
|
||||

|
||||
|
||||
* **Spec Compliancy**
|
||||
* Allow trailing param commas for methods when using the `es7.trailingCommas` transformer.
|
||||
* **Bug Fix**
|
||||
* Fix `es6.blockScoping` transformer not properly ignoring `break` in `SwitchCase`.
|
||||
* Fix lookahead context saving to avoid weird tokenizer state.
|
||||
* Explode duplicate identifiers in export/import specifiers and property shorthand to create unique objects.
|
||||
* Skip loose mode for class methods when they have decorators.
|
||||
* When removing nodes, share their comments with their siblings.
|
||||
* Properly hoist temp param declarations when doing TCO.
|
||||
* **Internal**
|
||||
* Add `--harmony_generators` flag to `$ babel-node`.
|
||||
* Internal AST traversals have been minimised **drastically**. Transformers have been grouped together which means entire tree traversals are much fewer. Visiting nodes is now also skipped if the traversal context can detect that the handler is a noop. This sames precious cycles as it avoids constructing traversal paths and creating a new traversal context. See issues [#1472](https://github.com/babel/babel/issues/1472) and [#1486](https://github.com/babel/babel/issues/1486) for related discussion.
|
||||
* **Polish**
|
||||
* Move many `utility` transformers to `minification`.
|
||||
|
||||
## 5.2.17
|
||||
|
||||
* **Bug Fix**
|
||||
* Fix auxiliary comments not properly being attached to function declaration helpers.
|
||||
* Add `Super` node type to `ast-types` patch.
|
||||
* Ignore parameter bindings when attempting to inline them in the `minification.deadCodeElimination` transformer.
|
||||
* Correct `extensions` arguments when using the Babel CLI.
|
||||
|
||||
## 5.2.16
|
||||
|
||||
* **Bug Fix**
|
||||
* Fix plugins being disabled when using the whitelist.
|
||||
* Fix correct function scope being passed to `nameMethod.property` when inferring the function name for class methods.
|
||||
* Fix incorrect extensions reference causing weird issues when using the Babel CLI.
|
||||
* Fix destructuring param reference replacements not inheriting from their original param.
|
||||
* **Spec Compliancy**
|
||||
* Fix order that method decorators are ran in.
|
||||
|
||||
## 5.2.15
|
||||
|
||||
* **Bug Fix**
|
||||
* Fix initializer descriptor add attempt if it doesn't exist.
|
||||
|
||||
## 5.2.14
|
||||
|
||||
* **Bug Fix**
|
||||
* Fix bug with initializer decorators where the descriptors weren't being defined if there was no `initializer` property.
|
||||
* **Internal**
|
||||
* Expose `retainLines` option to CLI.
|
||||
* Fix `retainLines` option not being taken into consideration when doing multiple variable declaration declarators generation.
|
||||
* Expose minified and unminified copies of dist scripts.
|
||||
|
||||
## 5.2.13
|
||||
|
||||
* **Bug Fix**
|
||||
* Fix `ExportDeclaration`s being incorrectly removed when using the `utility.deadCodeElimination` transformer.
|
||||
* Fix position of `utility` transformers.
|
||||
* **New Feature**
|
||||
* Add built-in `esquery` support.
|
||||
* **Internal**
|
||||
* Consolidate notion of "virtual types".
|
||||
|
||||
## 5.2.12
|
||||
|
||||
* **Polish**
|
||||
* Make UID generation based on module declarations **much** nicer.
|
||||
* **Internal**
|
||||
* Remove internal check for traversal path replacement of self. This is a pattern that **could** come up in the wild and it could lead to pretty nasty code and may lead to internal regressions as the test coverage isn't 100% :( Instead, just put it in the fast path.
|
||||
|
||||
## 5.2.11
|
||||
|
||||
* **Internal**
|
||||
* Rename `getModuleName` option to `getModuleId`, doh.
|
||||
|
||||
## 5.2.10
|
||||
|
||||
* **Bug Fix**
|
||||
* Fix numerous issues in `replaceWithSourceString`. Thanks [@pangratz](https://github.com/pangratz)!
|
||||
* **New Feature**
|
||||
* Add `getModuleName` option. Thanks [@jayphelps](https://github.com/jayphelps)!
|
||||
|
||||
## 5.2.9
|
||||
|
||||
* **Bug Fix**
|
||||
* Fix `_blockHoist` transformer incorrectly sorting nodes on shitty environments that aren't spec compliant in their key order.
|
||||
* Fix broken `parse` API method reference to an undeclared import.
|
||||
|
||||
## 5.2.7
|
||||
|
||||
* **Bug Fix**
|
||||
* Move `utility.deadCodeElimination` transformer up to avoid race conditions.
|
||||
* Fix shorthand property scope binding renaming.
|
||||
* **Polish**
|
||||
* Turn helper variable declarations into function declarations if possible.
|
||||
* **Internal**
|
||||
* Removed native inheritance support from classes.
|
||||
* Added `replaceWithSourceString` path API.
|
||||
* Split up `es3.propertyLiterals` and `es3.memberExpressionLiterals` transformers to `minfication.propertyLiterals` and `es3.memberExpressionLiterals`.
|
||||
|
||||
## 5.2.6
|
||||
|
||||
* **Internal**
|
||||
* Fix transformer aliases being accidently set as deprecated ones.
|
||||
* Expose `Pipeline` as `TransformerPipeline` instead.
|
||||
|
||||
## 5.2.5
|
||||
|
||||
* **Bug Fix**
|
||||
* Fix `parse` API not adding all the correct pipeline transformers.
|
||||
|
||||
## 5.2.4
|
||||
|
||||
* **Bug Fix**
|
||||
* Fix race condition with the Node API being loaded awkwardly and not being able to initialise itself when used in the browser.
|
||||
* **Internal**
|
||||
* Expose `transform.pipeline`.
|
||||
|
||||
## 5.2.3
|
||||
|
||||
* **Bug Fix**
|
||||
* Fix plugin containers being called with an undefined import. Thanks [@timbur](https://github.com/timbur)!
|
||||
* Allow Flow object separators to be commas. Thanks [@monsanto](https://github.com/monsanto)!
|
||||
* Add missing `Statement` and `Declaration` node aliases to flow types.
|
||||
|
||||
## 5.2.2
|
||||
|
||||
* **Internal**
|
||||
* Allow `util.arrayify` to take arbitrary types and coerce it into an array.
|
||||
|
||||
## 5.2.1
|
||||
|
||||
* **Bug Fix**
|
||||
* Fix regression in `node/register` that caused `node_modules` to not be ignored.
|
||||
|
||||
## 5.2.0
|
||||
|
||||
* **Bug Fix**
|
||||
* Fix plugin strings splitting arbitrarily on `:` which caused full paths on Windows to fail as they include `:` after the drive letter.
|
||||
* Call class property `initializer`s with their target instead of their descriptor.
|
||||
* Fix `ignore` and `only` not properly working on Windows path separators. Thanks [@stagas](https://github.com/stagas)!
|
||||
* Fix `resolveRc` running on files twice causing issues. Thanks [@lukescott](https://github.com/lukescott)!
|
||||
* Fix shorthand properties not correctly being target for `isReferenced` checks. Thanks [@monsanto](https://github.com/monsanto)!
|
||||
* **Polish**
|
||||
* Allow passing an array of globs to `babel/register` `only` and `ignore` options. Thanks [@Mark-Simulacrum](https://github.com/Mark-Simulacrum)!
|
||||
* When inferring function names that collide with upper bindings, instead of doing the wrapper, instead rename them.
|
||||
* Consider constant-like variable declaration functions to always refer to themselves so TOC can be performed.
|
||||
* Process globs manually when using `$ babel` as some shells such as Windows don't explode them. Thanks [@jden](https://github.com/jden)!
|
||||
* Add alternative way to execute plugins via a closure that's called with the current Babel instance.
|
||||
* **Internal**
|
||||
* Remove multiple internal transformers in favor of directly doing things when we need to. Previously, declarations such as `_ref` that we needed to create in specific scopes were done at the very end via the `_declarations` transformer. Now, they're done and added to the scope **right** when they're needed. This gets rid of the crappy `_declarations` property on scope nodes and fixes the crappy regenerator bug where it was creating a new `BlockStatement` so the declarations were being lost.
|
||||
* Rework transformer traversal optimisation. Turns out that calling a `check` function for **every single node** in the AST is ridiculously expensive. 300,000 nodes timesed by ~30 transformers meant that it took tens of seconds to perform while it's quicker to just do the unnecessary traversal. Seems obvious in hindsight.
|
||||
* **New Feature**
|
||||
* Add `jscript` transformer that turns named function expressions into function declarations to get around [JScript's horribly broken function expression semantics](https://kangax.github.io/nfe/#jscript-bugs). Thanks [@kondi](https://github.com/kondi)!
|
||||
* Add `@@hasInstance` support to objects when using the `es6.spec.symbols` transformer.
|
||||
* Add `retainLines` option that retains the line (but not the columns!) of the input code.
|
||||
|
||||
## 5.1.13
|
||||
|
||||
* **Polish**
|
||||
* Remove symbol check from `defineProperty` helper.
|
||||
|
||||
## 5.1.12
|
||||
|
||||
* **Bug Fix**
|
||||
* Fix `resolveModuleSource` not being ran on `ExportAllDeclaration`s.
|
||||
* Fix `.babelrc` being resolved multiple times when using the require hook.
|
||||
* Fix parse error on spread properties in assignment position.
|
||||
* Fix `externalHelpers` option being incorrectly listed as type `string`.
|
||||
* **Internal**
|
||||
* Upgrade `core-js` to `0.9.0`.
|
||||
* **Spec Compliancy**
|
||||
* Fix object decorators not using the `initializer` pattern.
|
||||
* Remove property initializer descriptor reflection.
|
||||
|
||||
## 5.1.11
|
||||
|
||||
* **Bug Fix**
|
||||
* Memoise and bind member expression decorators.
|
||||
* Move JSX children cleaning to opening element visitor. Fixes elements not being cleaned in certain scenarios.
|
||||
* Consider `SwitchStatement`s to be `Scopable`.
|
||||
* Fix `bluebirdCoroutines` calling `interopRequireWildcard` before it's defined.
|
||||
* Add space to `do...while` code generation.
|
||||
* Validate `super` use before `this` on `super` exit rather than entrance.
|
||||
* **Polish**
|
||||
* Add Babel name to logger.
|
||||
|
||||
## 5.1.10
|
||||
|
||||
* **Bug Fix**
|
||||
* Remove `makePredicate` from acorn in favor of an `indexOf`.
|
||||
* Remove statements to expression explosion when inserting a block statement.
|
||||
* **Internal**
|
||||
* Remove runtime compatibility check.
|
||||
|
||||
## 5.1.9
|
||||
|
||||
* **Bug Fix**
|
||||
* Fix class property initializers with `undefined` values not being correctly writable.
|
||||
* Fix self inferring generators incorrectly causing a stack error.
|
||||
* Fix default export specifiers not triggering AMD `module` argument inclusion.
|
||||
* Fix assignments not having their module references properly remapped.
|
||||
* **Internal**
|
||||
* Upgrade to latest `acorn`.
|
||||
* **Polish**
|
||||
* Make invalid LHS pattern error messages nicer.
|
||||
|
||||
## 5.1.8
|
||||
|
||||
* **Bug Fix**
|
||||
* Only make parenthesized object pattern LHS illegal.
|
||||
|
||||
## 5.1.7
|
||||
|
||||
* **Internal**
|
||||
* Add `parse` node API.
|
||||
|
||||
## 5.1.6
|
||||
|
||||
* **Bug Fix**
|
||||
* Fix `runtime` built-in catchall not properly checking for local variables.
|
||||
|
||||
## 5.1.5
|
||||
|
||||
* **Internal**
|
||||
* Bump `core-js` version.
|
||||
|
||||
## 5.1.4
|
||||
|
||||
* **Polish**
|
||||
* Add missing `Reflect` methods to runtime transformer.
|
||||
|
||||
## 5.1.3
|
||||
|
||||
* **Internal**
|
||||
* Switch entirely to vanilla regenerator.
|
||||
* Clean up and make the parsing of decorators stateless.
|
||||
* **Bug Fix**
|
||||
* Don't do TCO on generators and async functions.
|
||||
* Add missing `core-js` runtime definitions.
|
||||
|
||||
## 5.1.2
|
||||
|
||||
* **Bug Fix**
|
||||
|
||||
108
CONTRIBUTING.md
108
CONTRIBUTING.md
@@ -1,3 +1,23 @@
|
||||
# NOTE: BEFORE OPENING AN ISSUE PLEASE SEE THE [README](https://github.com/babel/babel#readme).
|
||||
|
||||
----
|
||||
|
||||
<p align="center">
|
||||
<strong><a href="#setup">Setup</a></strong>
|
||||
|
|
||||
<strong><a href="#running-tests">Running tests</a></strong>
|
||||
|
|
||||
<strong><a href="#workflow">Workflow</a></strong>
|
||||
|
|
||||
<strong><a href="#dependencies">Dependencies</a></strong>
|
||||
|
|
||||
<strong><a href="#code-standards">Code Standards</a></strong>
|
||||
|
|
||||
<strong><a href="#internals">Internals</a></strong>
|
||||
</p>
|
||||
|
||||
----
|
||||
|
||||
# Contributing
|
||||
|
||||
Contributions are always welcome, no matter how large or small. Before
|
||||
@@ -6,6 +26,9 @@ contributing, please read the
|
||||
|
||||
## Developing
|
||||
|
||||
> Note: Babel moves fast. Only the latest release is guaranteed to build correctly.
|
||||
> Older releases are not officially supported. If you attempt to build them, do that at your own risk.
|
||||
|
||||
#### Setup
|
||||
|
||||
```sh
|
||||
@@ -14,14 +37,19 @@ $ cd babel
|
||||
$ make bootstrap
|
||||
```
|
||||
|
||||
Then you need to run:
|
||||
Then you can either run:
|
||||
|
||||
```sh
|
||||
$ make build-core
|
||||
```
|
||||
|
||||
to build Babel **once** or:
|
||||
|
||||
```sh
|
||||
$ make watch-core
|
||||
```
|
||||
|
||||
This will compile Babel and then sit in the background and on file modification
|
||||
recompile the necessary files.
|
||||
to have Babel build itself then incrementally build files on change.
|
||||
|
||||
#### Running tests
|
||||
|
||||
@@ -44,6 +72,11 @@ Use mocha's `--grep` option to run a subset of tests by name:
|
||||
$ mocha test/core/transformation.js --grep es7
|
||||
```
|
||||
|
||||
If you don't have `mocha` installed globally, you can still use it from Babel's
|
||||
dependencies in `node_modules`, but make sure `node_modules/.bin` is added to
|
||||
your [`$PATH`](http://unix.stackexchange.com/questions/26047/how-to-correctly-add-a-path-to-path) environment variable.
|
||||
|
||||
|
||||
#### Workflow
|
||||
|
||||
* Fork the repository
|
||||
@@ -54,24 +87,93 @@ $ mocha test/core/transformation.js --grep es7
|
||||
* Ensure the test are passing (`make test`)
|
||||
* Create new pull request explaining your proposed change or reference an issue in your commit message
|
||||
|
||||
#### Dependencies
|
||||
|
||||
+ [ast-types](http://ghub.io/ast-types) This is required to monkeypatch regenerators AST definitions. Could be improved in the future.
|
||||
|
||||
+ [chalk](http://ghub.io/chalk) This is used for terminal color highlighting for syntax errors.
|
||||
|
||||
+ [convert-source-map](http://ghub.io/convert-source-map) Turns a source map object into a comment etc.
|
||||
|
||||
+ [core-js](http://ghub.io/core-js) Used for the polyfill.
|
||||
|
||||
+ [debug](http://ghub.io/debug) Used to output debugging information when NODE_DEBUG is set to babel.
|
||||
|
||||
+ [detect-indent](http://ghub.io/detect-indent) This is used in the code generator so it can infer indentation.
|
||||
|
||||
+ [estraverse](http://ghub.io/estraverse) The only method on this is attachComments. I'd like to implement our own comment attachment algorithm eventually though.
|
||||
|
||||
+ [esutils](http://ghub.io/esutils) Various ES related utilities. Check whether something is a keyword etc.
|
||||
|
||||
+ [fs-readdir-recursive](http://ghub.io/fs-readdir-recursive) Recursively search a directory for.
|
||||
|
||||
+ [globals](http://ghub.io/globals) A list of JavaScript global variables. This is used by the scope tracking to check for colliding variables.
|
||||
|
||||
+ [is-integer](http://ghub.io/is-integer) Checks if something is an integer.
|
||||
|
||||
+ [js-tokens](http://ghub.io/js-tokens) This is used to get tokens for syntax error highlighting.
|
||||
|
||||
+ [leven](http://ghub.io/leven) A levenstein algorithm to determine how close a word is to another. This is used to offer suggestions when using the utility.undeclaredVariableCheck transformer.
|
||||
|
||||
+ [line-numbers](http://ghub.io/line-numbers) Used to produce the code frames in syntax errors.
|
||||
|
||||
+ [lodash](http://ghub.io/lodash) Used for various utilities.
|
||||
|
||||
+ [minimatch](http://ghub.io/minimatch) This is used to match glob-style ignore/only filters.
|
||||
|
||||
+ [output-file-sync](http://ghub.io/output-file-sync) Synchronously writes a file and create its ancestor directories if needed.
|
||||
|
||||
+ [path-is-absolute](http://ghub.io/path-is-absolute) Checks if a path is absolute. C:\foo and \foo are considered absolute.
|
||||
|
||||
+ [regenerator](http://ghub.io/regenerator) This is used to transform generators/async functions.
|
||||
|
||||
+ [regexpu](http://ghub.io/regexpu) Used to transform unicode regex patterns.
|
||||
|
||||
+ [repeating](http://ghub.io/repeating) Repeats a string.
|
||||
|
||||
+ [shebang-regex](http://ghub.io/shebang-regex) Literally just a regex that matches shebangs.
|
||||
|
||||
+ [slash](http://ghub.io/slash) Normalises path separators.
|
||||
|
||||
+ [source-map](http://ghub.io/source-map) Generates sourcemaps.
|
||||
|
||||
+ [source-map-support](http://ghub.io/source-map-support) Adds source map support to babel-node/babel/register.
|
||||
|
||||
+ [strip-json-comments](http://ghub.io/strip-json-comments) Remove comments from a JSON string. This is used for .babelrc files.
|
||||
|
||||
+ [to-fast-properties](http://ghub.io/to-fast-properties) A V8 trick to put an object into fast properties mode.
|
||||
|
||||
+ [trim-right](http://ghub.io/trim-right) Trims the rightside whitespace.
|
||||
|
||||
+ [user-home](http://ghub.io/user-home) Gets the users home directory. This is used to resolve the babel-node/babel/register cache.
|
||||
|
||||
|
||||
#### Code Standards
|
||||
|
||||
* **General**
|
||||
* 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
|
||||
|
||||
#### Internals
|
||||
Please see [`/doc`](/doc) for internals documentation relevant to developing babel.
|
||||
|
||||
45
Makefile
45
Makefile
@@ -3,23 +3,29 @@ BROWSERIFY_CMD = node_modules/browserify/bin/cmd.js
|
||||
ISTANBUL_CMD = node_modules/istanbul/lib/cli.js cover
|
||||
UGLIFY_CMD = node_modules/uglify-js/bin/uglifyjs
|
||||
#UGLIFY_CMD = node_modules/uglify-js/bin/uglifyjs --mangle sort
|
||||
JSHINT_CMD = node_modules/jshint/bin/jshint
|
||||
MOCHA_CMD = node_modules/mocha/bin/_mocha
|
||||
BABEL_CMD = node_modules/babel/bin/babel
|
||||
BROWSERIFY_IGNORE = -i esprima-fb
|
||||
|
||||
export NODE_ENV = test
|
||||
|
||||
.PHONY: clean test test-cov test-clean test-travis test-simple test-all test-browser test-parser publish build bootstrap publish-core publish-runtime build-core watch-core build-core-test
|
||||
.PHONY: clean test test-cov test-clean test-travis test-simple test-all test-browser test-parser publish build bootstrap publish-core publish-runtime build-core watch-core build-core-test clean-core
|
||||
|
||||
build-core:
|
||||
build-core: clean-core
|
||||
node $(BABEL_CMD) src --out-dir lib --copy-files
|
||||
|
||||
build-core-test:
|
||||
node $(BABEL_CMD) src --out-dir lib --copy-files --auxiliary-comment "istanbul ignore next"
|
||||
build-core-test: clean-core
|
||||
node $(BABEL_CMD) src --out-dir lib --copy-files --auxiliary-comment-before "istanbul ignore next"
|
||||
|
||||
watch-core:
|
||||
watch-core: clean-core
|
||||
node $(BABEL_CMD) src --out-dir lib --watch --copy-files
|
||||
|
||||
clean-core:
|
||||
rm -rf lib
|
||||
|
||||
lint:
|
||||
eslint src/babel
|
||||
|
||||
build:
|
||||
mkdir -p dist
|
||||
make build-core
|
||||
@@ -29,8 +35,10 @@ build:
|
||||
node $(BROWSERIFY_CMD) -e lib/babel/polyfill.js >dist/polyfill.js
|
||||
node $(UGLIFY_CMD) dist/polyfill.js >dist/polyfill.min.js
|
||||
|
||||
node $(BROWSERIFY_CMD) lib/babel/api/browser.js -s babel >dist/babel.js
|
||||
node $(UGLIFY_CMD) dist/babel.js >dist/babel.min.js
|
||||
node $(BROWSERIFY_CMD) lib/babel/api/browser.js -s babel $(BROWSERIFY_IGNORE) >dist/browser.js
|
||||
node $(UGLIFY_CMD) dist/browser.js >dist/browser.min.js
|
||||
|
||||
node $(BROWSERIFY_CMD) lib/babel/api/node.js --node $(BROWSERIFY_IGNORE) >dist/node.js
|
||||
|
||||
node packages/babel-cli/bin/babel-external-helpers >dist/external-helpers.js
|
||||
node $(UGLIFY_CMD) dist/external-helpers.js >dist/external-helpers.min.js
|
||||
@@ -59,7 +67,7 @@ test-cov:
|
||||
test-parser:
|
||||
node test/acorn/run.js
|
||||
|
||||
test-travis: bootstrap build test
|
||||
test-travis: bootstrap lint build test
|
||||
|
||||
test-browser:
|
||||
mkdir -p dist
|
||||
@@ -71,7 +79,7 @@ test-browser:
|
||||
|
||||
test -n "`which open`" && open test/browser.html
|
||||
|
||||
publish:
|
||||
publish: lint
|
||||
git pull --rebase
|
||||
|
||||
make test
|
||||
@@ -80,9 +88,15 @@ publish:
|
||||
npm version $$version --message "v%s"
|
||||
|
||||
make build
|
||||
cp dist/babel.min.js browser.js
|
||||
cp dist/polyfill.min.js browser-polyfill.js
|
||||
cp dist/external-helpers.min.js external-helpers.js
|
||||
|
||||
cp dist/browser.js browser.js
|
||||
cp dist/browser.min.js browser.min.js
|
||||
|
||||
cp dist/polyfill.js browser-polyfill.js
|
||||
cp dist/polyfill.min.js browser-polyfill.min.js
|
||||
|
||||
cp dist/external-helpers.js external-helpers.js
|
||||
cp dist/external-helpers.min.js external-helpers.min.js
|
||||
|
||||
node tools/cache-templates
|
||||
test -f templates.json
|
||||
@@ -94,7 +108,7 @@ publish:
|
||||
make publish-cli
|
||||
make publish-runtime
|
||||
|
||||
rm -rf templates.json browser.js browser-polyfill.js external-helpers.js
|
||||
rm -rf templates.json browser.js browser.min.js browser-polyfill.js browser-polyfill.min.js external-helpers.js external-helpers.min.js
|
||||
|
||||
publish-runtime:
|
||||
cd packages; \
|
||||
@@ -114,5 +128,4 @@ bootstrap:
|
||||
npm link
|
||||
cd packages/babel-cli && npm install && npm link && npm link babel-core
|
||||
git submodule update --init
|
||||
cd vendor/regenerator && npm install
|
||||
cd vendor/compat-table && npm install object-assign
|
||||
make build
|
||||
|
||||
@@ -9,7 +9,11 @@
|
||||
</p>
|
||||
|
||||
<p align="center">
|
||||
For questions and support please visit the <a href="https://gitter.im/babel/babel">gitter room</a> or <a href="http://stackoverflow.com/questions/tagged/babeljs">StackOverflow</a>. The Babel issue tracker is <strong>exclusively</strong> for bug reports and feature requests.
|
||||
For questions and support please visit the <a href="https://babel-slack.herokuapp.com">slack channel</a> or <a href="http://stackoverflow.com/questions/tagged/babeljs">StackOverflow</a>. The Babel issue tracker is <strong>exclusively</strong> for bug reports and feature requests.
|
||||
</p>
|
||||
|
||||
<p align="center">
|
||||
Issues without instructions to reproduce <strong>will be immediately closed<strong>.
|
||||
</p>
|
||||
|
||||
<p align="center">
|
||||
|
||||
4
doc/index.md
Normal file
4
doc/index.md
Normal file
@@ -0,0 +1,4 @@
|
||||
This is a collection of documentation about babel internals, for use in development of babel.
|
||||
|
||||
# [Properties of nodes](/doc/node-props.md)
|
||||
These are properties babel stores in AST node objects for internal use, as opposed to properties that are part of the AST spec (ESTree at the time of this writing).
|
||||
11
doc/node-props.md
Normal file
11
doc/node-props.md
Normal file
@@ -0,0 +1,11 @@
|
||||
# Properties of nodes
|
||||
These are properties babel stores in AST node objects for internal use, as opposed to properties that are part of the AST spec (ESTree at the time of this writing).
|
||||
|
||||
## `_blockHoist`
|
||||
`node._blockHoist != null` triggers the [block-hoist transformer](/src/babel/transformation/transformers/internal/block-hoist.js). Value should be `true` or an integer in the range `0..3`. `true` is equivalent to `2`. The value indicates whether the node should be hoisted and to what degree. See the source code for more detailed information.
|
||||
|
||||
## `_paths`
|
||||
Stores a representation of a node's position in the tree and relationship to other nodes.
|
||||
|
||||
## `shadow`
|
||||
A truthy value on a function node triggers the [shadow-functions transformer](/src/babel/transformation/transformers/internal/shadow-functions.js), which transforms the node so that it references (or inherits) `arguments` and `this` from the parent scope. It is invoked for arrow functions, for example.
|
||||
42
package.json
42
package.json
@@ -1,9 +1,10 @@
|
||||
{
|
||||
"name": "babel-core",
|
||||
"description": "Turn ES6 code into readable vanilla ES5 with source maps",
|
||||
"version": "5.1.2",
|
||||
"description": "A compiler for writing next generation JavaScript",
|
||||
"version": "5.6.5",
|
||||
"author": "Sebastian McKenzie <sebmck@gmail.com>",
|
||||
"homepage": "https://babeljs.io/",
|
||||
"license": "MIT",
|
||||
"repository": "babel/babel",
|
||||
"main": "lib/babel/api/node.js",
|
||||
"browser": {
|
||||
@@ -27,18 +28,35 @@
|
||||
"test": "make test"
|
||||
},
|
||||
"dependencies": {
|
||||
"acorn-jsx": "^1.0.0",
|
||||
"ast-types": "~0.7.0",
|
||||
"babel-plugin-constant-folding": "^1.0.1",
|
||||
"babel-plugin-dead-code-elimination": "^1.0.1",
|
||||
"babel-plugin-eval": "^1.0.1",
|
||||
"babel-plugin-inline-environment-variables": "^1.0.1",
|
||||
"babel-plugin-jscript": "^1.0.1",
|
||||
"babel-plugin-member-expression-literals": "^1.0.1",
|
||||
"babel-plugin-property-literals": "^1.0.1",
|
||||
"babel-plugin-proto-to-assign": "^1.0.3",
|
||||
"babel-plugin-react-constant-elements": "^1.0.3",
|
||||
"babel-plugin-react-display-name": "^1.0.3",
|
||||
"babel-plugin-remove-console": "^1.0.1",
|
||||
"babel-plugin-remove-debugger": "^1.0.1",
|
||||
"babel-plugin-runtime": "^1.0.7",
|
||||
"babel-plugin-undeclared-variables-check": "^1.0.2",
|
||||
"babel-plugin-undefined-to-void": "^1.1.6",
|
||||
"chalk": "^1.0.0",
|
||||
"convert-source-map": "^1.0.0",
|
||||
"core-js": "^0.8.1",
|
||||
"convert-source-map": "^1.1.0",
|
||||
"core-js": "^0.9.0",
|
||||
"debug": "^2.1.1",
|
||||
"detect-indent": "^3.0.0",
|
||||
"estraverse": "^3.0.0",
|
||||
"estraverse": "^4.0.0",
|
||||
"esutils": "^2.0.0",
|
||||
"fs-readdir-recursive": "^0.1.0",
|
||||
"globals": "^6.4.0",
|
||||
"home-or-tmp": "^1.0.0",
|
||||
"is-integer": "^1.0.4",
|
||||
"js-tokens": "1.0.0",
|
||||
"js-tokens": "1.0.1",
|
||||
"leven": "^1.0.1",
|
||||
"line-numbers": "0.2.0",
|
||||
"lodash": "^3.6.0",
|
||||
@@ -46,24 +64,24 @@
|
||||
"output-file-sync": "^1.1.0",
|
||||
"path-is-absolute": "^1.0.0",
|
||||
"private": "^0.1.6",
|
||||
"regenerator": "https://github.com/sebmck/regenerator/archive/block-hoist.tar.gz",
|
||||
"regenerator": "0.8.31",
|
||||
"regexpu": "^1.1.2",
|
||||
"repeating": "^1.1.2",
|
||||
"resolve": "^1.1.6",
|
||||
"shebang-regex": "^1.0.0",
|
||||
"slash": "^1.0.0",
|
||||
"source-map": "^0.4.0",
|
||||
"source-map-support": "^0.2.10",
|
||||
"strip-json-comments": "^1.0.2",
|
||||
"to-fast-properties": "^1.0.0",
|
||||
"trim-right": "^1.0.0",
|
||||
"user-home": "^1.1.1"
|
||||
"trim-right": "^1.0.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"babel": "4.7.13",
|
||||
"babel": "5.5.7",
|
||||
"browserify": "^9.0.8",
|
||||
"chai": "^2.2.0",
|
||||
"eslint": "^0.18.0",
|
||||
"babel-eslint": "^2.0.0",
|
||||
"eslint": "^0.21.2",
|
||||
"babel-eslint": "^3.1.9",
|
||||
"esvalid": "^1.1.0",
|
||||
"istanbul": "^0.3.5",
|
||||
"matcha": "^0.6.0",
|
||||
|
||||
@@ -107,6 +107,7 @@ if (program.eval || program.print) {
|
||||
|
||||
// add back on node and concat the sliced args
|
||||
process.argv = ["node"].concat(args);
|
||||
process.execArgv.unshift(__filename);
|
||||
|
||||
Module.runMain();
|
||||
} else {
|
||||
|
||||
@@ -55,6 +55,8 @@ babelArgs.forEach(function(arg){
|
||||
case "--harmony_classes":
|
||||
case "--harmony_object_literals":
|
||||
case "--harmony_templates":
|
||||
case "--harmony_rest_parameters":
|
||||
case "--harmony_generators":
|
||||
case "--compiled_keyed_generic_loads":
|
||||
case "--pretenuring_call_new":
|
||||
case "--allocation_site_pretenuring":
|
||||
@@ -410,6 +412,7 @@ babelArgs.forEach(function(arg){
|
||||
case "--prof_auto":
|
||||
case "--prof_lazy":
|
||||
case "--sliding_state_window":
|
||||
case "--nolazy":
|
||||
args.unshift(arg);
|
||||
break;
|
||||
|
||||
|
||||
140
packages/babel-cli/bin/babel-plugin/index.js
Executable file
140
packages/babel-cli/bin/babel-plugin/index.js
Executable file
@@ -0,0 +1,140 @@
|
||||
#!/usr/bin/env node
|
||||
|
||||
var readline = require("readline");
|
||||
var child = require("child_process");
|
||||
var path = require("path");
|
||||
var fs = require("fs");
|
||||
|
||||
function spawn(cmd, args, callback) {
|
||||
console.log(">", cmd, args);
|
||||
|
||||
var spawn = child.spawn(cmd, args, { stdio: "inherit" });
|
||||
|
||||
spawn.on("exit", function (code) {
|
||||
if (code === 0) {
|
||||
if (callback) callback();
|
||||
} else {
|
||||
console.log("Killing...");
|
||||
process.exit(1);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function spawnMultiple(cmds) {
|
||||
function next() {
|
||||
var cmd = cmds.shift();
|
||||
if (cmd) {
|
||||
spawn(cmd.command, cmd.args, next);
|
||||
} else {
|
||||
process.exit();
|
||||
}
|
||||
}
|
||||
|
||||
next();
|
||||
}
|
||||
|
||||
function template(name, data) {
|
||||
var source = fs.readFileSync(__dirname + "/templates/" + name, "utf8");
|
||||
source = source.replace(/[A-Z_]+/g, function (key) {
|
||||
return data[key] === undefined ? key : data[key];
|
||||
});
|
||||
return source;
|
||||
}
|
||||
|
||||
function write(filename, content) {
|
||||
console.log(filename);
|
||||
fs.writeFileSync(filename, content);
|
||||
}
|
||||
|
||||
var rl = readline.createInterface({
|
||||
input: process.stdin,
|
||||
output: process.stdout
|
||||
});
|
||||
|
||||
var BABEL_PLUGIN_PREFIX = "babel-plugin-";
|
||||
|
||||
var cmds = {
|
||||
init: function () {
|
||||
var name = path.basename(process.cwd());
|
||||
|
||||
if (name.indexOf(BABEL_PLUGIN_PREFIX) === 0) {
|
||||
name = name.slice(BABEL_PLUGIN_PREFIX.length);
|
||||
}
|
||||
|
||||
rl.question("Description (optional): ", function (description) {
|
||||
rl.question("GitHub Repository (eg. sebmck/babel-plugin-foobar) (optional): ", function (repo) {
|
||||
rl.close();
|
||||
|
||||
var templateData = {
|
||||
DESCRIPTION: description,
|
||||
FULL_NAME: BABEL_PLUGIN_PREFIX + name,
|
||||
NAME: name
|
||||
};
|
||||
|
||||
write("package.json", JSON.stringify({
|
||||
name: templateData.FULL_NAME,
|
||||
version: "1.0.0",
|
||||
description: templateData.DESCRIPTION,
|
||||
repository: repo || undefined,
|
||||
license: "MIT",
|
||||
main: "lib/index.js",
|
||||
|
||||
devDependencies: {
|
||||
babel: "^5.6.0"
|
||||
},
|
||||
|
||||
scripts: {
|
||||
build: "babel-plugin build",
|
||||
push: "babel-plugin publish",
|
||||
test: "babel-plugin test"
|
||||
},
|
||||
|
||||
keywords: ["babel-plugin"]
|
||||
}, null, " ") + "\n");
|
||||
|
||||
write(".npmignore", "node_modules\n*.log\nsrc\n");
|
||||
|
||||
write(".gitignore", "node_modules\n*.log\nlib\n");
|
||||
|
||||
write("README.md", template("README.md", templateData));
|
||||
|
||||
if (!fs.existsSync("src")) {
|
||||
fs.mkdirSync("src");
|
||||
write("src/index.js", template("index.js", templateData));
|
||||
}
|
||||
});
|
||||
});
|
||||
},
|
||||
|
||||
build: function () {
|
||||
spawn("babel", ["src", "--out-dir", "lib", "--copy-files"]);
|
||||
},
|
||||
|
||||
publish: function () {
|
||||
var pkg = require(process.cwd() + "/package.json");
|
||||
console.log("Current verison:", pkg.version);
|
||||
|
||||
rl.question("New version (enter nothing for patch): ", function (newVersion) {
|
||||
rl.close();
|
||||
|
||||
newVersion = newVersion || "patch";
|
||||
|
||||
spawnMultiple([
|
||||
{ command: "git", args: ["pull"] },
|
||||
{ command: "git", args: ["push"] },
|
||||
{ command: "babel-plugin", args: ["build"] },
|
||||
{ command: "npm", args: ["version", newVersion] },
|
||||
{ command: "npm", args: ["publish"] },
|
||||
{ command: "git", args: ["push", "--follow-tags"] }
|
||||
]);
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
var cmd = cmds[process.argv[2]];
|
||||
if (cmd) {
|
||||
cmd();
|
||||
} else {
|
||||
console.error("Unknown command:", cmd);
|
||||
process.exit(1);
|
||||
}
|
||||
35
packages/babel-cli/bin/babel-plugin/templates/README.md
Normal file
35
packages/babel-cli/bin/babel-plugin/templates/README.md
Normal file
@@ -0,0 +1,35 @@
|
||||
# FULL_NAME
|
||||
|
||||
DESCRIPTION
|
||||
|
||||
## Installation
|
||||
|
||||
```sh
|
||||
$ npm install FULL_NAME
|
||||
```
|
||||
|
||||
## Usage
|
||||
|
||||
### Via `.babelrc` (Recommended)
|
||||
|
||||
**.babelrc**
|
||||
|
||||
```json
|
||||
{
|
||||
"plugins": ["NAME"]
|
||||
}
|
||||
```
|
||||
|
||||
### Via CLI
|
||||
|
||||
```sh
|
||||
$ babel --plugins NAME script.js
|
||||
```
|
||||
|
||||
### Via Node API
|
||||
|
||||
```javascript
|
||||
require("babel-core").transform("code", {
|
||||
plugins: ["NAME"]
|
||||
});
|
||||
```
|
||||
7
packages/babel-cli/bin/babel-plugin/templates/index.js
Normal file
7
packages/babel-cli/bin/babel-plugin/templates/index.js
Normal file
@@ -0,0 +1,7 @@
|
||||
export default function ({ Plugin, types: t }) {
|
||||
return new Plugin("NAME", {
|
||||
visitor: {
|
||||
// your visitor methods go here
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
var outputFileSync = require("output-file-sync");
|
||||
var chokidar = require("chokidar");
|
||||
var slash = require("slash");
|
||||
var path = require("path");
|
||||
var util = require("./util");
|
||||
var fs = require("fs");
|
||||
@@ -13,8 +14,10 @@ module.exports = function (commander, filenames, opts) {
|
||||
var dest = path.join(commander.outDir, relative);
|
||||
|
||||
var data = util.compile(src, {
|
||||
sourceFileName: path.relative(dest + "/..", src)
|
||||
sourceFileName: slash(path.relative(dest + "/..", src)),
|
||||
sourceMapTarget: path.basename(relative)
|
||||
});
|
||||
if (data.ignored) return;
|
||||
|
||||
if (commander.sourceMaps && commander.sourceMaps !== "inline") {
|
||||
var mapLoc = dest + ".map";
|
||||
@@ -30,7 +33,7 @@ module.exports = function (commander, filenames, opts) {
|
||||
var handleFile = function (src, filename) {
|
||||
if (util.shouldIgnore(src)) return;
|
||||
|
||||
if (util.canCompile(filename)) {
|
||||
if (util.canCompile(filename, commander.extensions)) {
|
||||
write(src, filename);
|
||||
} else if (commander.copyFiles) {
|
||||
outputFileSync(path.join(commander.outDir, filename), fs.readFileSync(src));
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
var convertSourceMap = require("convert-source-map");
|
||||
var sourceMap = require("source-map");
|
||||
var chokidar = require("chokidar");
|
||||
var slash = require("slash");
|
||||
var path = require("path");
|
||||
var util = require("./util");
|
||||
var fs = require("fs");
|
||||
@@ -15,7 +16,8 @@ module.exports = function (commander, filenames, opts) {
|
||||
|
||||
var buildResult = function () {
|
||||
var map = new sourceMap.SourceMapGenerator({
|
||||
file: commander.outFile || "stdout"
|
||||
file: path.basename(commander.outFile) || "stdout",
|
||||
sourceRoot: opts.sourceRoot
|
||||
});
|
||||
|
||||
var code = "";
|
||||
@@ -28,8 +30,14 @@ module.exports = function (commander, filenames, opts) {
|
||||
if (result.map) {
|
||||
var consumer = new sourceMap.SourceMapConsumer(result.map);
|
||||
|
||||
map._sources.add(filename);
|
||||
map.setSourceContent(filename, result.actual);
|
||||
var sourceFilename = filename;
|
||||
if (commander.outFile) {
|
||||
sourceFilename = path.relative(path.dirname(commander.outFile), sourceFilename);
|
||||
}
|
||||
sourceFilename = slash(sourceFilename);
|
||||
|
||||
map._sources.add(sourceFilename);
|
||||
map.setSourceContent(sourceFilename, result.actual);
|
||||
|
||||
consumer.eachMapping(function (mapping) {
|
||||
map._mappings.add({
|
||||
@@ -37,7 +45,7 @@ module.exports = function (commander, filenames, opts) {
|
||||
generatedColumn: mapping.generatedColumn,
|
||||
originalLine: mapping.originalLine,
|
||||
originalColumn: mapping.originalColumn,
|
||||
source: filename
|
||||
source: sourceFilename
|
||||
});
|
||||
});
|
||||
|
||||
@@ -109,7 +117,9 @@ module.exports = function (commander, filenames, opts) {
|
||||
_.each(_filenames, function (filename) {
|
||||
if (util.shouldIgnore(filename)) return;
|
||||
|
||||
results.push(util.compile(filename));
|
||||
var data = util.compile(filename);
|
||||
if (data.ignored) return;
|
||||
results.push(data);
|
||||
});
|
||||
|
||||
output();
|
||||
|
||||
@@ -1,13 +1,16 @@
|
||||
#!/usr/bin/env node
|
||||
|
||||
var commander = require("commander");
|
||||
var transform = require("babel-core").transform;
|
||||
var kebabCase = require("lodash/string/kebabCase");
|
||||
var options = require("babel-core").options;
|
||||
var util = require("babel-core").util;
|
||||
var each = require("lodash/collection/each");
|
||||
var keys = require("lodash/object/keys");
|
||||
var fs = require("fs");
|
||||
var moduleFormatters = require("babel-core/lib/babel/transformation/modules");
|
||||
var commander = require("commander");
|
||||
var transform = require("babel-core").transform;
|
||||
var kebabCase = require("lodash/string/kebabCase");
|
||||
var options = require("babel-core").options;
|
||||
var util = require("babel-core").util;
|
||||
var uniq = require("lodash/array/uniq");
|
||||
var each = require("lodash/collection/each");
|
||||
var keys = require("lodash/object/keys");
|
||||
var fs = require("fs");
|
||||
var glob = require("glob");
|
||||
|
||||
each(options, function (option, key) {
|
||||
if (option.hidden) return;
|
||||
@@ -33,8 +36,9 @@ each(options, function (option, key) {
|
||||
if (option.description) desc.push(option.description);
|
||||
|
||||
commander.option(arg, desc.join(" "));
|
||||
})
|
||||
});
|
||||
|
||||
commander.option("-x, --extensions [extensions]", "List of extensions to compile when a directory has been input [.es6,.js,.es,.jsx]");
|
||||
commander.option("-w, --watch", "Recompile files on changes");
|
||||
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");
|
||||
@@ -48,7 +52,7 @@ commander.on("--help", function () {
|
||||
each(keys(obj).sort(), function (key) {
|
||||
if (key[0] === "_") return;
|
||||
|
||||
if (obj[key].optional) key = "[" + key + "]";
|
||||
if (obj[key].metadata && obj[key].metadata.optional) key = "[" + key + "]";
|
||||
|
||||
console.log(" - " + key);
|
||||
});
|
||||
@@ -56,8 +60,8 @@ commander.on("--help", function () {
|
||||
console.log();
|
||||
};
|
||||
|
||||
outKeys("Transformers", transform.transformers);
|
||||
outKeys("Module formatters", transform.moduleFormatters);
|
||||
outKeys("Transformers", transform.pipeline.transformers);
|
||||
outKeys("Module formatters", moduleFormatters);
|
||||
});
|
||||
|
||||
var pkg = require("../../package.json");
|
||||
@@ -67,9 +71,21 @@ commander.parse(process.argv);
|
||||
|
||||
//
|
||||
|
||||
if (commander.extensions) {
|
||||
commander.extensions = util.arrayify(commander.extensions);
|
||||
}
|
||||
|
||||
//
|
||||
|
||||
var errors = [];
|
||||
|
||||
var filenames = commander.args;
|
||||
var filenames = commander.args.reduce(function (globbed, input) {
|
||||
var files = glob.sync(input);
|
||||
if (!files.length) files = [input];
|
||||
return globbed.concat(files);
|
||||
}, []);
|
||||
|
||||
filenames = uniq(filenames);
|
||||
|
||||
each(filenames, function (filename) {
|
||||
if (!fs.existsSync(filename)) {
|
||||
@@ -105,11 +121,16 @@ if (errors.length) {
|
||||
var opts = exports.opts = {};
|
||||
|
||||
each(options, function (opt, key) {
|
||||
opts[key] = commander[key];
|
||||
if (commander[key] !== undefined) {
|
||||
opts[key] = commander[key];
|
||||
}
|
||||
});
|
||||
|
||||
opts.ignore = util.arrayify(opts.ignore, util.regexify);
|
||||
opts.only = util.arrayify(opts.only, util.regexify);
|
||||
|
||||
if (opts.only) {
|
||||
opts.only = util.arrayify(opts.only, util.regexify);
|
||||
}
|
||||
|
||||
var fn;
|
||||
|
||||
|
||||
@@ -1,10 +1,11 @@
|
||||
var readdir = require("fs-readdir-recursive");
|
||||
var index = require("./index");
|
||||
var babel = require("babel-core");
|
||||
var util = require("babel-core").util;
|
||||
var path = require("path");
|
||||
var fs = require("fs");
|
||||
var _ = require("lodash");
|
||||
var commander = require("commander");
|
||||
var readdir = require("fs-readdir-recursive");
|
||||
var index = require("./index");
|
||||
var babel = require("babel-core");
|
||||
var util = require("babel-core").util;
|
||||
var path = require("path");
|
||||
var fs = require("fs");
|
||||
var _ = require("lodash");
|
||||
|
||||
exports.readdirFilter = function (filename) {
|
||||
return readdir(filename).filter(function (filename) {
|
||||
@@ -37,6 +38,15 @@ exports.transform = function (filename, code, opts) {
|
||||
};
|
||||
|
||||
exports.compile = function (filename, opts) {
|
||||
var code = fs.readFileSync(filename, "utf8");
|
||||
return exports.transform(filename, code, opts);
|
||||
try {
|
||||
var code = fs.readFileSync(filename, "utf8");
|
||||
return exports.transform(filename, code, opts);
|
||||
} catch (err) {
|
||||
if (commander.watch) {
|
||||
console.error(err.stack);
|
||||
return { ignored: true };
|
||||
} else {
|
||||
throw err;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@@ -1,25 +1,29 @@
|
||||
{
|
||||
"name": "babel",
|
||||
"description": "Turn ES6 code into readable vanilla ES5 with source maps",
|
||||
"version": "5.1.1",
|
||||
"version": "5.6.4",
|
||||
"author": "Sebastian McKenzie <sebmck@gmail.com>",
|
||||
"homepage": "https://babeljs.io/",
|
||||
"license": "MIT",
|
||||
"repository": "babel/babel",
|
||||
"preferGlobal": true,
|
||||
"dependencies": {
|
||||
"babel-core": "^5.1.1",
|
||||
"babel-core": "^5.6.4",
|
||||
"chokidar": "^1.0.0",
|
||||
"commander": "^2.6.0",
|
||||
"convert-source-map": "^1.1.0",
|
||||
"fs-readdir-recursive": "^0.1.0",
|
||||
"output-file-sync": "^1.1.0",
|
||||
"glob": "^5.0.5",
|
||||
"lodash": "^3.2.0",
|
||||
"convert-source-map": "^0.5.0",
|
||||
"output-file-sync": "^1.1.0",
|
||||
"path-is-absolute": "^1.0.0",
|
||||
"source-map": "^0.4.0",
|
||||
"path-is-absolute": "^1.0.0"
|
||||
"slash": "^1.0.0"
|
||||
},
|
||||
"bin": {
|
||||
"babel": "./bin/babel/index.js",
|
||||
"babel-node": "./bin/babel-node",
|
||||
"babel-external-helpers": "./bin/babel-external-helpers"
|
||||
"babel-external-helpers": "./bin/babel-external-helpers",
|
||||
"babel-plugin": "./bin/babel-plugin/index.js"
|
||||
}
|
||||
}
|
||||
1
packages/babel-cli/register-without-polyfill.js
Normal file
1
packages/babel-cli/register-without-polyfill.js
Normal file
@@ -0,0 +1 @@
|
||||
module.exports = require("babel-core/register-without-polyfill");
|
||||
@@ -1,10 +1,11 @@
|
||||
{
|
||||
"name": "babel-runtime",
|
||||
"description": "babel selfContained runtime",
|
||||
"version": "5.1.1",
|
||||
"version": "5.6.4",
|
||||
"license": "MIT",
|
||||
"repository": "babel/babel",
|
||||
"author": "Sebastian McKenzie <sebmck@gmail.com>",
|
||||
"dependencies": {
|
||||
"core-js": "^0.8.0"
|
||||
"core-js": "^0.9.0"
|
||||
}
|
||||
}
|
||||
@@ -70,12 +70,12 @@ each(File.helpers, function (helperName) {
|
||||
writeFile("helpers/" + helperName + ".js", buildHelper(helperName));
|
||||
});
|
||||
|
||||
writeFile("regenerator/index.js", readFile("regenerator-babel/runtime-module", true));
|
||||
writeFile("regenerator/runtime.js", selfContainify(readFile("regenerator-babel/runtime")));
|
||||
writeFile("regenerator/index.js", readFile("regenerator/runtime-module", true));
|
||||
writeFile("regenerator/runtime.js", selfContainify(readFile("regenerator/runtime")));
|
||||
|
||||
//
|
||||
|
||||
var coreDefinitions = require("../lib/babel/transformation/transformers/other/runtime/definitions");
|
||||
var coreDefinitions = require("babel-plugin-runtime/lib/definitions");
|
||||
|
||||
var paths = ["is-iterable", "get-iterator"];
|
||||
|
||||
|
||||
1
register-without-polyfill.js
Normal file
1
register-without-polyfill.js
Normal file
@@ -0,0 +1 @@
|
||||
module.exports = require("./lib/babel/api/register/node");
|
||||
@@ -1 +1 @@
|
||||
module.exports = require("./lib/babel/api/register/node");
|
||||
module.exports = require("./lib/babel/api/register/node-polyfill");
|
||||
|
||||
48
sebmck-bjs.nfo
Normal file
48
sebmck-bjs.nfo
Normal file
@@ -0,0 +1,48 @@
|
||||
|
||||
====== ==========M=
|
||||
============= == ======O= ======= MM ==
|
||||
M==+=== ==M === ==== == === ==
|
||||
=D === === ====MM ==M ==M ==M ===
|
||||
===M ====M ==== =D ===M === === ==
|
||||
==7 ====M ==M == ======== =========M ==M
|
||||
=========== ======M ===MMM === ==M ==
|
||||
=======MM==========MM== ==M ==M=== ==
|
||||
==M === M== ==M == === === =D =
|
||||
==M ===+ == == == ==$M =========== ============M
|
||||
=== ====M == ==M ===M== ====?MMMM M M
|
||||
== ===== ==M == ==MM M
|
||||
==M===M=M =M =MM M M
|
||||
==MM=M ==
|
||||
MMM =M
|
||||
M
|
||||
|
||||
> ú B ú A ú B ú E ú L ú <
|
||||
ÕÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÑÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ͸
|
||||
³ SOFTWARE .. : JavaScript Compiler ³ COMPANY ... : N/A ³
|
||||
³ SUPPLIER .. : N/A ³ CRACKER ... : Sebastian McKenzie ³
|
||||
³ RATING .... : depends.. ³ PACKAGER .. : Sebastian McKenzie ³
|
||||
³ ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ ³
|
||||
³ GRAFIX .... : - ³ SOUND ..... : - ³
|
||||
ÔÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÏÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ;
|
||||
|
||||
Babel is a JavaScript compiler and transformation platform for writing NeXt
|
||||
GeNeRaTiOn JavaScript.
|
||||
|
||||
ÆÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÏÍÍÍÍÍÍÍÍÍÍÍÍÍÍÏÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÏÍÍÍÍÍÍÍÏÍÍÍÍÍÍÍÍÍÍÍ͵
|
||||
³ :: Greets :: ³
|
||||
³ ³
|
||||
³ sebmck, thejameskyle, RReverser, zloirock, monsanto, gaearon, zertosh, ³
|
||||
³ stefanpenner, eventualbuddha, AluisioASG, Apoxx, Couto, dominicbarnes, ³
|
||||
³ es128, gordonkristan, hkjels, jmeas, josh, loganfsmyth, nightire, ³
|
||||
³ Rich-Harris, shinnn, shuhei, sindresorhus, tricknotes ³
|
||||
³ ³
|
||||
ÔÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ;
|
||||
|
||||
-*- JavaScripts for all , All for JavaScripts ! -*-
|
||||
|
||||
ÕÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ͸
|
||||
³ If you want to Contact us, call 555-720-4228, Use the Handle "BABEL" w/ ³
|
||||
³ password : VISITOR and leave a mail to Sebastian or James. ³
|
||||
ÔÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ;
|
||||
|
||||
-=- We LoVe fun Too! -=-
|
||||
6
src/acorn/index.js
Normal file
6
src/acorn/index.js
Normal file
@@ -0,0 +1,6 @@
|
||||
export * from "./src/index";
|
||||
import "./plugins/flow";
|
||||
|
||||
import inject from "acorn-jsx/inject";
|
||||
import * as acorn from "./src/index";
|
||||
inject(acorn);
|
||||
@@ -2,7 +2,7 @@
|
||||
"name": "acorn",
|
||||
"description": "ECMAScript parser",
|
||||
"homepage": "https://github.com/marijnh/acorn",
|
||||
"main": "src/index.js",
|
||||
"main": "index.js",
|
||||
"version": "1.0.0",
|
||||
"engines": {
|
||||
"node": ">=0.4.0"
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
var acorn = require("..")
|
||||
var acorn = require("../src/index")
|
||||
|
||||
var pp = acorn.Parser.prototype
|
||||
var tt = acorn.tokTypes
|
||||
@@ -153,10 +153,15 @@ pp.flow_parseTypeAlias = function (node) {
|
||||
node.typeParameters = null
|
||||
}
|
||||
|
||||
var oldInType = this.inType;
|
||||
this.inType = true;
|
||||
|
||||
this.expect(tt.eq)
|
||||
|
||||
node.right = this.flow_parseType()
|
||||
|
||||
this.inType = oldInType;
|
||||
|
||||
this.semicolon()
|
||||
|
||||
return this.finishNode(node, "TypeAlias")
|
||||
@@ -322,7 +327,7 @@ pp.flow_parseObjectType = function (allowStatic) {
|
||||
}
|
||||
|
||||
pp.flow_objectTypeSemicolon = function () {
|
||||
if (!this.eat(tt.semi) && this.type !== tt.braceR) {
|
||||
if (!this.eat(tt.semi) && !this.eat(tt.comma) && this.type !== tt.braceR) {
|
||||
this.unexpected()
|
||||
}
|
||||
}
|
||||
@@ -410,6 +415,9 @@ pp.flow_identToTypeAnnotation = function (start, node, id) {
|
||||
case "boolean":
|
||||
return this.finishNode(node, "BooleanTypeAnnotation")
|
||||
|
||||
case "mixed":
|
||||
return this.finishNode(node, "MixedTypeAnnotation")
|
||||
|
||||
case "number":
|
||||
return this.finishNode(node, "NumberTypeAnnotation")
|
||||
|
||||
|
||||
@@ -1,658 +0,0 @@
|
||||
var acorn = require("..")
|
||||
|
||||
var tt = acorn.tokTypes;
|
||||
var tc = acorn.tokContexts;
|
||||
|
||||
tc.j_oTag = new acorn.TokContext("<tag", false);
|
||||
tc.j_cTag = new acorn.TokContext("</tag", false);
|
||||
tc.j_expr = new acorn.TokContext("<tag>...</tag>", true, true);
|
||||
|
||||
tt.jsxName = new acorn.TokenType("jsxName");
|
||||
tt.jsxText = new acorn.TokenType("jsxText", {beforeExpr: true});
|
||||
tt.jsxTagStart = new acorn.TokenType("jsxTagStart");
|
||||
tt.jsxTagEnd = new acorn.TokenType("jsxTagEnd");
|
||||
|
||||
tt.jsxTagStart.updateContext = function() {
|
||||
this.context.push(tc.j_expr); // treat as beginning of JSX expression
|
||||
this.context.push(tc.j_oTag); // start opening tag context
|
||||
this.exprAllowed = false;
|
||||
};
|
||||
tt.jsxTagEnd.updateContext = function(prevType) {
|
||||
var out = this.context.pop();
|
||||
if (out === tc.j_oTag && prevType === tt.slash || out === tc.j_cTag) {
|
||||
this.context.pop();
|
||||
this.exprAllowed = this.curContext() === tc.j_expr;
|
||||
} else {
|
||||
this.exprAllowed = true;
|
||||
}
|
||||
};
|
||||
|
||||
var pp = acorn.Parser.prototype;
|
||||
|
||||
// Reads inline JSX contents token.
|
||||
|
||||
pp.jsx_readToken = function() {
|
||||
var out = "", chunkStart = this.pos;
|
||||
for (;;) {
|
||||
if (this.pos >= this.input.length)
|
||||
this.raise(this.start, "Unterminated JSX contents");
|
||||
var ch = this.input.charCodeAt(this.pos);
|
||||
|
||||
switch (ch) {
|
||||
case 60: // '<'
|
||||
case 123: // '{'
|
||||
if (this.pos === this.start) {
|
||||
if (ch === 60 && this.exprAllowed) {
|
||||
++this.pos;
|
||||
return this.finishToken(tt.jsxTagStart);
|
||||
}
|
||||
return this.getTokenFromCode(ch);
|
||||
}
|
||||
out += this.input.slice(chunkStart, this.pos);
|
||||
return this.finishToken(tt.jsxText, out);
|
||||
|
||||
case 38: // '&'
|
||||
out += this.input.slice(chunkStart, this.pos);
|
||||
out += this.jsx_readEntity();
|
||||
chunkStart = this.pos;
|
||||
break;
|
||||
|
||||
default:
|
||||
if (acorn.isNewLine(ch)) {
|
||||
out += this.input.slice(chunkStart, this.pos);
|
||||
++this.pos;
|
||||
if (ch === 13 && this.input.charCodeAt(this.pos) === 10) {
|
||||
++this.pos;
|
||||
out += "\n";
|
||||
} else {
|
||||
out += String.fromCharCode(ch);
|
||||
}
|
||||
if (this.options.locations) {
|
||||
++this.curLine;
|
||||
this.lineStart = this.pos;
|
||||
}
|
||||
chunkStart = this.pos;
|
||||
} else {
|
||||
++this.pos;
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
pp.jsx_readString = function(quote) {
|
||||
var out = "", chunkStart = ++this.pos;
|
||||
for (;;) {
|
||||
if (this.pos >= this.input.length)
|
||||
this.raise(this.start, "Unterminated string constant");
|
||||
var ch = this.input.charCodeAt(this.pos);
|
||||
if (ch === quote) break;
|
||||
if (ch === 38) { // '&'
|
||||
out += this.input.slice(chunkStart, this.pos);
|
||||
out += this.jsx_readEntity();
|
||||
chunkStart = this.pos;
|
||||
} else {
|
||||
++this.pos;
|
||||
}
|
||||
}
|
||||
out += this.input.slice(chunkStart, this.pos++);
|
||||
return this.finishToken(tt.string, out);
|
||||
};
|
||||
|
||||
var XHTMLEntities = {
|
||||
quot: '\u0022',
|
||||
amp: '&',
|
||||
apos: '\u0027',
|
||||
lt: '<',
|
||||
gt: '>',
|
||||
nbsp: '\u00A0',
|
||||
iexcl: '\u00A1',
|
||||
cent: '\u00A2',
|
||||
pound: '\u00A3',
|
||||
curren: '\u00A4',
|
||||
yen: '\u00A5',
|
||||
brvbar: '\u00A6',
|
||||
sect: '\u00A7',
|
||||
uml: '\u00A8',
|
||||
copy: '\u00A9',
|
||||
ordf: '\u00AA',
|
||||
laquo: '\u00AB',
|
||||
not: '\u00AC',
|
||||
shy: '\u00AD',
|
||||
reg: '\u00AE',
|
||||
macr: '\u00AF',
|
||||
deg: '\u00B0',
|
||||
plusmn: '\u00B1',
|
||||
sup2: '\u00B2',
|
||||
sup3: '\u00B3',
|
||||
acute: '\u00B4',
|
||||
micro: '\u00B5',
|
||||
para: '\u00B6',
|
||||
middot: '\u00B7',
|
||||
cedil: '\u00B8',
|
||||
sup1: '\u00B9',
|
||||
ordm: '\u00BA',
|
||||
raquo: '\u00BB',
|
||||
frac14: '\u00BC',
|
||||
frac12: '\u00BD',
|
||||
frac34: '\u00BE',
|
||||
iquest: '\u00BF',
|
||||
Agrave: '\u00C0',
|
||||
Aacute: '\u00C1',
|
||||
Acirc: '\u00C2',
|
||||
Atilde: '\u00C3',
|
||||
Auml: '\u00C4',
|
||||
Aring: '\u00C5',
|
||||
AElig: '\u00C6',
|
||||
Ccedil: '\u00C7',
|
||||
Egrave: '\u00C8',
|
||||
Eacute: '\u00C9',
|
||||
Ecirc: '\u00CA',
|
||||
Euml: '\u00CB',
|
||||
Igrave: '\u00CC',
|
||||
Iacute: '\u00CD',
|
||||
Icirc: '\u00CE',
|
||||
Iuml: '\u00CF',
|
||||
ETH: '\u00D0',
|
||||
Ntilde: '\u00D1',
|
||||
Ograve: '\u00D2',
|
||||
Oacute: '\u00D3',
|
||||
Ocirc: '\u00D4',
|
||||
Otilde: '\u00D5',
|
||||
Ouml: '\u00D6',
|
||||
times: '\u00D7',
|
||||
Oslash: '\u00D8',
|
||||
Ugrave: '\u00D9',
|
||||
Uacute: '\u00DA',
|
||||
Ucirc: '\u00DB',
|
||||
Uuml: '\u00DC',
|
||||
Yacute: '\u00DD',
|
||||
THORN: '\u00DE',
|
||||
szlig: '\u00DF',
|
||||
agrave: '\u00E0',
|
||||
aacute: '\u00E1',
|
||||
acirc: '\u00E2',
|
||||
atilde: '\u00E3',
|
||||
auml: '\u00E4',
|
||||
aring: '\u00E5',
|
||||
aelig: '\u00E6',
|
||||
ccedil: '\u00E7',
|
||||
egrave: '\u00E8',
|
||||
eacute: '\u00E9',
|
||||
ecirc: '\u00EA',
|
||||
euml: '\u00EB',
|
||||
igrave: '\u00EC',
|
||||
iacute: '\u00ED',
|
||||
icirc: '\u00EE',
|
||||
iuml: '\u00EF',
|
||||
eth: '\u00F0',
|
||||
ntilde: '\u00F1',
|
||||
ograve: '\u00F2',
|
||||
oacute: '\u00F3',
|
||||
ocirc: '\u00F4',
|
||||
otilde: '\u00F5',
|
||||
ouml: '\u00F6',
|
||||
divide: '\u00F7',
|
||||
oslash: '\u00F8',
|
||||
ugrave: '\u00F9',
|
||||
uacute: '\u00FA',
|
||||
ucirc: '\u00FB',
|
||||
uuml: '\u00FC',
|
||||
yacute: '\u00FD',
|
||||
thorn: '\u00FE',
|
||||
yuml: '\u00FF',
|
||||
OElig: '\u0152',
|
||||
oelig: '\u0153',
|
||||
Scaron: '\u0160',
|
||||
scaron: '\u0161',
|
||||
Yuml: '\u0178',
|
||||
fnof: '\u0192',
|
||||
circ: '\u02C6',
|
||||
tilde: '\u02DC',
|
||||
Alpha: '\u0391',
|
||||
Beta: '\u0392',
|
||||
Gamma: '\u0393',
|
||||
Delta: '\u0394',
|
||||
Epsilon: '\u0395',
|
||||
Zeta: '\u0396',
|
||||
Eta: '\u0397',
|
||||
Theta: '\u0398',
|
||||
Iota: '\u0399',
|
||||
Kappa: '\u039A',
|
||||
Lambda: '\u039B',
|
||||
Mu: '\u039C',
|
||||
Nu: '\u039D',
|
||||
Xi: '\u039E',
|
||||
Omicron: '\u039F',
|
||||
Pi: '\u03A0',
|
||||
Rho: '\u03A1',
|
||||
Sigma: '\u03A3',
|
||||
Tau: '\u03A4',
|
||||
Upsilon: '\u03A5',
|
||||
Phi: '\u03A6',
|
||||
Chi: '\u03A7',
|
||||
Psi: '\u03A8',
|
||||
Omega: '\u03A9',
|
||||
alpha: '\u03B1',
|
||||
beta: '\u03B2',
|
||||
gamma: '\u03B3',
|
||||
delta: '\u03B4',
|
||||
epsilon: '\u03B5',
|
||||
zeta: '\u03B6',
|
||||
eta: '\u03B7',
|
||||
theta: '\u03B8',
|
||||
iota: '\u03B9',
|
||||
kappa: '\u03BA',
|
||||
lambda: '\u03BB',
|
||||
mu: '\u03BC',
|
||||
nu: '\u03BD',
|
||||
xi: '\u03BE',
|
||||
omicron: '\u03BF',
|
||||
pi: '\u03C0',
|
||||
rho: '\u03C1',
|
||||
sigmaf: '\u03C2',
|
||||
sigma: '\u03C3',
|
||||
tau: '\u03C4',
|
||||
upsilon: '\u03C5',
|
||||
phi: '\u03C6',
|
||||
chi: '\u03C7',
|
||||
psi: '\u03C8',
|
||||
omega: '\u03C9',
|
||||
thetasym: '\u03D1',
|
||||
upsih: '\u03D2',
|
||||
piv: '\u03D6',
|
||||
ensp: '\u2002',
|
||||
emsp: '\u2003',
|
||||
thinsp: '\u2009',
|
||||
zwnj: '\u200C',
|
||||
zwj: '\u200D',
|
||||
lrm: '\u200E',
|
||||
rlm: '\u200F',
|
||||
ndash: '\u2013',
|
||||
mdash: '\u2014',
|
||||
lsquo: '\u2018',
|
||||
rsquo: '\u2019',
|
||||
sbquo: '\u201A',
|
||||
ldquo: '\u201C',
|
||||
rdquo: '\u201D',
|
||||
bdquo: '\u201E',
|
||||
dagger: '\u2020',
|
||||
Dagger: '\u2021',
|
||||
bull: '\u2022',
|
||||
hellip: '\u2026',
|
||||
permil: '\u2030',
|
||||
prime: '\u2032',
|
||||
Prime: '\u2033',
|
||||
lsaquo: '\u2039',
|
||||
rsaquo: '\u203A',
|
||||
oline: '\u203E',
|
||||
frasl: '\u2044',
|
||||
euro: '\u20AC',
|
||||
image: '\u2111',
|
||||
weierp: '\u2118',
|
||||
real: '\u211C',
|
||||
trade: '\u2122',
|
||||
alefsym: '\u2135',
|
||||
larr: '\u2190',
|
||||
uarr: '\u2191',
|
||||
rarr: '\u2192',
|
||||
darr: '\u2193',
|
||||
harr: '\u2194',
|
||||
crarr: '\u21B5',
|
||||
lArr: '\u21D0',
|
||||
uArr: '\u21D1',
|
||||
rArr: '\u21D2',
|
||||
dArr: '\u21D3',
|
||||
hArr: '\u21D4',
|
||||
forall: '\u2200',
|
||||
part: '\u2202',
|
||||
exist: '\u2203',
|
||||
empty: '\u2205',
|
||||
nabla: '\u2207',
|
||||
isin: '\u2208',
|
||||
notin: '\u2209',
|
||||
ni: '\u220B',
|
||||
prod: '\u220F',
|
||||
sum: '\u2211',
|
||||
minus: '\u2212',
|
||||
lowast: '\u2217',
|
||||
radic: '\u221A',
|
||||
prop: '\u221D',
|
||||
infin: '\u221E',
|
||||
ang: '\u2220',
|
||||
and: '\u2227',
|
||||
or: '\u2228',
|
||||
cap: '\u2229',
|
||||
cup: '\u222A',
|
||||
'int': '\u222B',
|
||||
there4: '\u2234',
|
||||
sim: '\u223C',
|
||||
cong: '\u2245',
|
||||
asymp: '\u2248',
|
||||
ne: '\u2260',
|
||||
equiv: '\u2261',
|
||||
le: '\u2264',
|
||||
ge: '\u2265',
|
||||
sub: '\u2282',
|
||||
sup: '\u2283',
|
||||
nsub: '\u2284',
|
||||
sube: '\u2286',
|
||||
supe: '\u2287',
|
||||
oplus: '\u2295',
|
||||
otimes: '\u2297',
|
||||
perp: '\u22A5',
|
||||
sdot: '\u22C5',
|
||||
lceil: '\u2308',
|
||||
rceil: '\u2309',
|
||||
lfloor: '\u230A',
|
||||
rfloor: '\u230B',
|
||||
lang: '\u2329',
|
||||
rang: '\u232A',
|
||||
loz: '\u25CA',
|
||||
spades: '\u2660',
|
||||
clubs: '\u2663',
|
||||
hearts: '\u2665',
|
||||
diams: '\u2666'
|
||||
};
|
||||
|
||||
var hexNumber = /^[\da-fA-F]+$/;
|
||||
var decimalNumber = /^\d+$/;
|
||||
|
||||
pp.jsx_readEntity = function() {
|
||||
var str = "", count = 0, entity;
|
||||
var ch = this.input[this.pos];
|
||||
if (ch !== "&")
|
||||
this.raise(this.pos, "Entity must start with an ampersand");
|
||||
var startPos = ++this.pos;
|
||||
while (this.pos < this.input.length && count++ < 10) {
|
||||
ch = this.input[this.pos++];
|
||||
if (ch === ";") {
|
||||
if (str[0] === "#") {
|
||||
if (str[1] === "x") {
|
||||
str = str.substr(2);
|
||||
if (hexNumber.test(str))
|
||||
entity = String.fromCharCode(parseInt(str, 16));
|
||||
} else {
|
||||
str = str.substr(1);
|
||||
if (decimalNumber.test(str))
|
||||
entity = String.fromCharCode(parseInt(str, 10));
|
||||
}
|
||||
} else {
|
||||
entity = XHTMLEntities[str];
|
||||
}
|
||||
break;
|
||||
}
|
||||
str += ch;
|
||||
}
|
||||
if (!entity) {
|
||||
this.pos = startPos;
|
||||
return "&";
|
||||
}
|
||||
return entity;
|
||||
};
|
||||
|
||||
|
||||
// Read a JSX identifier (valid tag or attribute name).
|
||||
//
|
||||
// Optimized version since JSX identifiers can't contain
|
||||
// escape characters and so can be read as single slice.
|
||||
// Also assumes that first character was already checked
|
||||
// by isIdentifierStart in readToken.
|
||||
|
||||
pp.jsx_readWord = function() {
|
||||
var ch, start = this.pos;
|
||||
do {
|
||||
ch = this.input.charCodeAt(++this.pos);
|
||||
} while (acorn.isIdentifierChar(ch) || ch === 45); // '-'
|
||||
return this.finishToken(tt.jsxName, this.input.slice(start, this.pos));
|
||||
};
|
||||
|
||||
// Transforms JSX element name to string.
|
||||
|
||||
function getQualifiedJSXName(object) {
|
||||
if (object.type === "JSXIdentifier")
|
||||
return object.name;
|
||||
|
||||
if (object.type === "JSXNamespacedName")
|
||||
return object.namespace.name + ':' + object.name.name;
|
||||
|
||||
if (object.type === "JSXMemberExpression")
|
||||
return getQualifiedJSXName(object.object) + '.' +
|
||||
getQualifiedJSXName(object.property);
|
||||
}
|
||||
|
||||
// Parse next token as JSX identifier
|
||||
|
||||
pp.jsx_parseIdentifier = function() {
|
||||
var node = this.startNode();
|
||||
if (this.type === tt.jsxName)
|
||||
node.name = this.value;
|
||||
else if (this.type.keyword)
|
||||
node.name = this.type.keyword;
|
||||
else
|
||||
this.unexpected();
|
||||
this.next();
|
||||
return this.finishNode(node, "JSXIdentifier");
|
||||
};
|
||||
|
||||
// Parse namespaced identifier.
|
||||
|
||||
pp.jsx_parseNamespacedName = function() {
|
||||
var start = this.markPosition();
|
||||
var name = this.jsx_parseIdentifier();
|
||||
if (!this.eat(tt.colon)) return name;
|
||||
var node = this.startNodeAt(start);
|
||||
node.namespace = name;
|
||||
node.name = this.jsx_parseIdentifier();
|
||||
return this.finishNode(node, "JSXNamespacedName");
|
||||
};
|
||||
|
||||
// Parses element name in any form - namespaced, member
|
||||
// or single identifier.
|
||||
|
||||
pp.jsx_parseElementName = function() {
|
||||
var start = this.markPosition();
|
||||
var node = this.jsx_parseNamespacedName();
|
||||
while (this.eat(tt.dot)) {
|
||||
var newNode = this.startNodeAt(start);
|
||||
newNode.object = node;
|
||||
newNode.property = this.jsx_parseIdentifier();
|
||||
node = this.finishNode(newNode, "JSXMemberExpression");
|
||||
}
|
||||
return node;
|
||||
};
|
||||
|
||||
// Parses any type of JSX attribute value.
|
||||
|
||||
pp.jsx_parseAttributeValue = function() {
|
||||
switch (this.type) {
|
||||
case tt.braceL:
|
||||
var node = this.jsx_parseExpressionContainer();
|
||||
if (node.expression.type === "JSXEmptyExpression")
|
||||
this.raise(node.start, "JSX attributes must only be assigned a non-empty expression");
|
||||
return node;
|
||||
|
||||
case tt.jsxTagStart:
|
||||
case tt.string:
|
||||
return this.parseExprAtom();
|
||||
|
||||
default:
|
||||
this.raise(this.start, "JSX value should be either an expression or a quoted JSX text");
|
||||
}
|
||||
};
|
||||
|
||||
// JSXEmptyExpression is unique type since it doesn't actually parse anything,
|
||||
// and so it should start at the end of last read token (left brace) and finish
|
||||
// at the beginning of the next one (right brace).
|
||||
|
||||
pp.jsx_parseEmptyExpression = function() {
|
||||
var tmp = this.start;
|
||||
this.start = this.lastTokEnd;
|
||||
this.lastTokEnd = tmp;
|
||||
|
||||
tmp = this.startLoc;
|
||||
this.startLoc = this.lastTokEndLoc;
|
||||
this.lastTokEndLoc = tmp;
|
||||
|
||||
return this.finishNode(this.startNode(), "JSXEmptyExpression");
|
||||
};
|
||||
|
||||
// Parses JSX expression enclosed into curly brackets.
|
||||
|
||||
|
||||
pp.jsx_parseExpressionContainer = function() {
|
||||
var node = this.startNode();
|
||||
this.next();
|
||||
node.expression = this.type === tt.braceR
|
||||
? this.jsx_parseEmptyExpression()
|
||||
: this.parseExpression();
|
||||
this.expect(tt.braceR);
|
||||
return this.finishNode(node, "JSXExpressionContainer");
|
||||
};
|
||||
|
||||
// Parses following JSX attribute name-value pair.
|
||||
|
||||
pp.jsx_parseAttribute = function() {
|
||||
var node = this.startNode();
|
||||
if (this.eat(tt.braceL)) {
|
||||
this.expect(tt.ellipsis);
|
||||
node.argument = this.parseMaybeAssign();
|
||||
this.expect(tt.braceR);
|
||||
return this.finishNode(node, "JSXSpreadAttribute");
|
||||
}
|
||||
node.name = this.jsx_parseNamespacedName();
|
||||
node.value = this.eat(tt.eq) ? this.jsx_parseAttributeValue() : null;
|
||||
return this.finishNode(node, "JSXAttribute");
|
||||
};
|
||||
|
||||
// Parses JSX opening tag starting after '<'.
|
||||
|
||||
pp.jsx_parseOpeningElementAt = function(start) {
|
||||
var node = this.startNodeAt(start);
|
||||
node.attributes = [];
|
||||
node.name = this.jsx_parseElementName();
|
||||
while (this.type !== tt.slash && this.type !== tt.jsxTagEnd)
|
||||
node.attributes.push(this.jsx_parseAttribute());
|
||||
node.selfClosing = this.eat(tt.slash);
|
||||
this.expect(tt.jsxTagEnd);
|
||||
return this.finishNode(node, "JSXOpeningElement");
|
||||
};
|
||||
|
||||
// Parses JSX closing tag starting after '</'.
|
||||
|
||||
pp.jsx_parseClosingElementAt = function(start) {
|
||||
var node = this.startNodeAt(start);
|
||||
node.name = this.jsx_parseElementName();
|
||||
this.expect(tt.jsxTagEnd);
|
||||
return this.finishNode(node, "JSXClosingElement");
|
||||
};
|
||||
|
||||
// Parses entire JSX element, including it's opening tag
|
||||
// (starting after '<'), attributes, contents and closing tag.
|
||||
|
||||
pp.jsx_parseElementAt = function(start) {
|
||||
var node = this.startNodeAt(start);
|
||||
var children = [];
|
||||
var openingElement = this.jsx_parseOpeningElementAt(start);
|
||||
var closingElement = null;
|
||||
|
||||
if (!openingElement.selfClosing) {
|
||||
contents: for (;;) {
|
||||
switch (this.type) {
|
||||
case tt.jsxTagStart:
|
||||
start = this.markPosition();
|
||||
this.next();
|
||||
if (this.eat(tt.slash)) {
|
||||
closingElement = this.jsx_parseClosingElementAt(start);
|
||||
break contents;
|
||||
}
|
||||
children.push(this.jsx_parseElementAt(start));
|
||||
break;
|
||||
|
||||
case tt.jsxText:
|
||||
children.push(this.parseExprAtom());
|
||||
break;
|
||||
|
||||
case tt.braceL:
|
||||
children.push(this.jsx_parseExpressionContainer());
|
||||
break;
|
||||
|
||||
default:
|
||||
this.unexpected();
|
||||
}
|
||||
}
|
||||
if (getQualifiedJSXName(closingElement.name) !== getQualifiedJSXName(openingElement.name))
|
||||
this.raise(
|
||||
closingElement.start,
|
||||
"Expected corresponding JSX closing tag for <" + getQualifiedJSXName(openingElement.name) + ">");
|
||||
}
|
||||
|
||||
node.openingElement = openingElement;
|
||||
node.closingElement = closingElement;
|
||||
node.children = children;
|
||||
return this.finishNode(node, "JSXElement");
|
||||
};
|
||||
|
||||
// Parses entire JSX element from current position.
|
||||
|
||||
pp.jsx_parseElement = function() {
|
||||
var start = this.markPosition();
|
||||
this.next();
|
||||
return this.jsx_parseElementAt(start);
|
||||
};
|
||||
|
||||
acorn.plugins.jsx = function(instance) {
|
||||
instance.extend("parseExprAtom", function(inner) {
|
||||
return function(refShortHandDefaultPos) {
|
||||
if (this.type === tt.jsxText)
|
||||
return this.parseLiteral(this.value);
|
||||
else if (this.type === tt.jsxTagStart)
|
||||
return this.jsx_parseElement();
|
||||
else
|
||||
return inner.call(this, refShortHandDefaultPos);
|
||||
};
|
||||
});
|
||||
|
||||
instance.extend("readToken", function(inner) {
|
||||
return function(code) {
|
||||
var context = this.curContext();
|
||||
|
||||
if (context === tc.j_expr) return this.jsx_readToken();
|
||||
|
||||
if (context === tc.j_oTag || context === tc.j_cTag) {
|
||||
if (acorn.isIdentifierStart(code)) return this.jsx_readWord();
|
||||
|
||||
if (code == 62) {
|
||||
++this.pos;
|
||||
return this.finishToken(tt.jsxTagEnd);
|
||||
}
|
||||
|
||||
if ((code === 34 || code === 39) && context == tc.j_oTag)
|
||||
return this.jsx_readString(code);
|
||||
}
|
||||
|
||||
if (code === 60 && this.exprAllowed) {
|
||||
++this.pos;
|
||||
return this.finishToken(tt.jsxTagStart);
|
||||
}
|
||||
return inner.call(this, code);
|
||||
};
|
||||
});
|
||||
|
||||
instance.extend("updateContext", function(inner) {
|
||||
return function(prevType) {
|
||||
if (this.type == tt.braceL) {
|
||||
var curContext = this.curContext();
|
||||
if (curContext == tc.j_oTag) this.context.push(tc.b_expr);
|
||||
else if (curContext == tc.j_expr) this.context.push(tc.b_tmpl);
|
||||
else inner.call(this, prevType);
|
||||
this.exprAllowed = true;
|
||||
} else if (this.type === tt.slash && prevType === tt.jsxTagStart) {
|
||||
this.context.length -= 2; // do not consider JSX expr -> JSX open tag -> ... anymore
|
||||
this.context.push(tc.j_cTag); // reconsider as closing tag context
|
||||
this.exprAllowed = false;
|
||||
} else {
|
||||
return inner.call(this, prevType);
|
||||
}
|
||||
};
|
||||
});
|
||||
}
|
||||
@@ -29,14 +29,23 @@ const pp = Parser.prototype
|
||||
// strict mode, init properties are also not allowed to be repeated.
|
||||
|
||||
pp.checkPropClash = function(prop, propHash) {
|
||||
if (this.options.ecmaVersion >= 6) return
|
||||
if (this.options.ecmaVersion >= 6 && (prop.computed || prop.method || prop.shorthand))
|
||||
return
|
||||
let key = prop.key, name
|
||||
switch (key.type) {
|
||||
case "Identifier": name = key.name; break
|
||||
case "Literal": name = String(key.value); break
|
||||
default: return
|
||||
}
|
||||
let kind = prop.kind || "init", other
|
||||
let kind = prop.kind
|
||||
if (this.options.ecmaVersion >= 6) {
|
||||
if (name === "__proto__" && kind === "init") {
|
||||
if (propHash.proto) this.raise(key.start, "Redefinition of __proto__ property");
|
||||
propHash.proto = true
|
||||
}
|
||||
return
|
||||
}
|
||||
let other
|
||||
if (has(propHash, name)) {
|
||||
other = propHash[name]
|
||||
let isGetSet = kind !== "init"
|
||||
@@ -104,10 +113,14 @@ pp.parseMaybeAssign = function(noIn, refShorthandDefaultPos, afterLeftParse) {
|
||||
refShorthandDefaultPos.start = 0 // reset because shorthand default was used correctly
|
||||
this.checkLVal(left)
|
||||
if (left.parenthesizedExpression) {
|
||||
let errorMsg
|
||||
if (left.type === "ObjectPattern") {
|
||||
this.raise(left.start, "You're trying to assign to a parenthesized expression, instead of `({ foo }) = {}` use `({ foo } = {})`");
|
||||
} else {
|
||||
this.raise(left.start, "Parenthesized left hand expressions are illegal");
|
||||
errorMsg = "`({a}) = 0` use `({a} = 0)`"
|
||||
} else if (left.type === "ArrayPattern") {
|
||||
errorMsg = "`([a]) = 0` use `([a] = 0)`"
|
||||
}
|
||||
if (errorMsg) {
|
||||
this.raise(left.start, `You're trying to assign to a parenthesized expression, eg. instead of ${errorMsg}`)
|
||||
}
|
||||
}
|
||||
this.next()
|
||||
@@ -210,7 +223,12 @@ pp.parseExprSubscripts = function(refShorthandDefaultPos) {
|
||||
}
|
||||
|
||||
pp.parseSubscripts = function(base, start, noCalls) {
|
||||
if (this.eat(tt.dot)) {
|
||||
if (!noCalls && this.eat(tt.doubleColon)) {
|
||||
let node = this.startNodeAt(start)
|
||||
node.object = base
|
||||
node.callee = this.parseNoCallExpr()
|
||||
return this.parseSubscripts(this.finishNode(node, "BindExpression"), start, noCalls)
|
||||
} else if (this.eat(tt.dot)) {
|
||||
let node = this.startNodeAt(start)
|
||||
node.object = base
|
||||
node.property = this.parseIdent(true)
|
||||
@@ -236,6 +254,13 @@ pp.parseSubscripts = function(base, start, noCalls) {
|
||||
} return base
|
||||
}
|
||||
|
||||
// Parse a no-call expression (like argument of `new` or `::` operators).
|
||||
|
||||
pp.parseNoCallExpr = function() {
|
||||
let start = this.markPosition()
|
||||
return this.parseSubscripts(this.parseExprAtom(), start, true)
|
||||
}
|
||||
|
||||
// Parse an atomic expression — either a single token that is an
|
||||
// expression, an expression started by a keyword like `function` or
|
||||
// `new`, or an expression wrapped in punctuation like `()`, `[]`,
|
||||
@@ -244,8 +269,10 @@ pp.parseSubscripts = function(base, start, noCalls) {
|
||||
pp.parseExprAtom = function(refShorthandDefaultPos) {
|
||||
let node, canBeArrow = this.potentialArrowAt == this.start
|
||||
switch (this.type) {
|
||||
case tt._this:
|
||||
case tt._super:
|
||||
if (!this.inFunction)
|
||||
this.raise(this.start, "'super' outside of function or class")
|
||||
case tt._this:
|
||||
let type = this.type === tt._this ? "ThisExpression" : "Super"
|
||||
node = this.startNode()
|
||||
this.next()
|
||||
@@ -258,7 +285,13 @@ pp.parseExprAtom = function(refShorthandDefaultPos) {
|
||||
if (this.options.features["es7.doExpressions"]) {
|
||||
let node = this.startNode()
|
||||
this.next()
|
||||
var oldInFunction = this.inFunction
|
||||
var oldLabels = this.labels
|
||||
this.labels = []
|
||||
this.inFunction = false
|
||||
node.body = this.parseBlock()
|
||||
this.inFunction = oldInFunction
|
||||
this.labels = oldLabels
|
||||
return this.finishNode(node, "DoExpression")
|
||||
}
|
||||
|
||||
@@ -270,7 +303,7 @@ pp.parseExprAtom = function(refShorthandDefaultPos) {
|
||||
//
|
||||
if (this.options.features["es7.asyncFunctions"]) {
|
||||
// async functions!
|
||||
if (id.name === "async") {
|
||||
if (id.name === "async" && !this.canInsertSemicolon()) {
|
||||
// arrow functions
|
||||
if (this.type === tt.parenL) {
|
||||
let expr = this.parseParenAndDistinguishExpression(start, true, true)
|
||||
@@ -359,6 +392,15 @@ pp.parseExprAtom = function(refShorthandDefaultPos) {
|
||||
case tt.backQuote:
|
||||
return this.parseTemplate()
|
||||
|
||||
case tt.doubleColon:
|
||||
node = this.startNode()
|
||||
this.next()
|
||||
node.object = null
|
||||
let callee = node.callee = this.parseNoCallExpr()
|
||||
if (callee.type !== "MemberExpression")
|
||||
this.raise(callee.start, "Binding should be performed on object property.")
|
||||
return this.finishNode(node, "BindExpression")
|
||||
|
||||
default:
|
||||
this.unexpected()
|
||||
}
|
||||
@@ -468,9 +510,11 @@ pp.parseNew = function() {
|
||||
this.raise(node.property.start, "The only valid meta property for new is new.target")
|
||||
return this.finishNode(node, "MetaProperty")
|
||||
}
|
||||
let start = this.markPosition()
|
||||
node.callee = this.parseSubscripts(this.parseExprAtom(), start, true)
|
||||
if (this.eat(tt.parenL)) node.arguments = this.parseExprList(tt.parenR, false)
|
||||
node.callee = this.parseNoCallExpr()
|
||||
if (this.eat(tt.parenL)) node.arguments = this.parseExprList(
|
||||
tt.parenR,
|
||||
this.options.features["es7.trailingFunctionCommas"]
|
||||
)
|
||||
else node.arguments = empty
|
||||
return this.finishNode(node, "NewExpression")
|
||||
}
|
||||
@@ -480,7 +524,7 @@ pp.parseNew = function() {
|
||||
pp.parseTemplateElement = function() {
|
||||
let elem = this.startNode()
|
||||
elem.value = {
|
||||
raw: this.input.slice(this.start, this.end),
|
||||
raw: this.input.slice(this.start, this.end).replace(/\r\n?/g, '\n'),
|
||||
cooked: this.value
|
||||
}
|
||||
this.next()
|
||||
@@ -509,22 +553,24 @@ pp.parseTemplate = function() {
|
||||
pp.parseObj = function(isPattern, refShorthandDefaultPos) {
|
||||
let node = this.startNode(), first = true, propHash = {}
|
||||
node.properties = []
|
||||
let decorators = []
|
||||
this.next()
|
||||
while (!this.eat(tt.braceR)) {
|
||||
if (!first) {
|
||||
this.expect(tt.comma)
|
||||
if (this.afterTrailingComma(tt.braceR)) break
|
||||
} else first = false
|
||||
|
||||
while (this.type === tt.at) {
|
||||
this.decorators.push(this.parseDecorator())
|
||||
decorators.push(this.parseDecorator())
|
||||
}
|
||||
|
||||
let prop = this.startNode(), isGenerator = false, isAsync = false, start
|
||||
if (decorators.length) {
|
||||
prop.decorators = decorators
|
||||
decorators = []
|
||||
}
|
||||
if (this.options.features["es7.objectRestSpread"] && this.type === tt.ellipsis) {
|
||||
prop = this.parseSpread()
|
||||
prop.type = "SpreadProperty"
|
||||
this.takeDecorators(prop)
|
||||
node.properties.push(prop)
|
||||
continue
|
||||
}
|
||||
@@ -550,10 +596,9 @@ pp.parseObj = function(isPattern, refShorthandDefaultPos) {
|
||||
}
|
||||
this.parseObjPropValue(prop, start, isGenerator, isAsync, isPattern, refShorthandDefaultPos);
|
||||
this.checkPropClash(prop, propHash)
|
||||
this.takeDecorators(prop)
|
||||
node.properties.push(this.finishNode(prop, "Property"))
|
||||
}
|
||||
if (this.decorators.length) {
|
||||
if (decorators.length) {
|
||||
this.raise(this.start, "You have trailing decorators with no property");
|
||||
}
|
||||
return this.finishNode(node, isPattern ? "ObjectPattern" : "ObjectExpression")
|
||||
@@ -575,6 +620,14 @@ pp.parseObjPropValue = function (prop, start, isGenerator, isAsync, isPattern, r
|
||||
prop.kind = prop.key.name
|
||||
this.parsePropertyName(prop)
|
||||
prop.value = this.parseMethod(false)
|
||||
let paramCount = prop.kind === "get" ? 0 : 1
|
||||
if (prop.value.params.length !== paramCount) {
|
||||
let start = prop.value.start
|
||||
if (prop.kind === "get")
|
||||
this.raise(start, "getter should have no params");
|
||||
else
|
||||
this.raise(start, "setter should have exactly one param")
|
||||
}
|
||||
} else if (this.options.ecmaVersion >= 6 && !prop.computed && prop.key.type === "Identifier") {
|
||||
prop.kind = "init"
|
||||
if (isPattern) {
|
||||
@@ -600,12 +653,12 @@ pp.parsePropertyName = function(prop) {
|
||||
prop.computed = true
|
||||
prop.key = this.parseMaybeAssign()
|
||||
this.expect(tt.bracketR)
|
||||
return
|
||||
return prop.key
|
||||
} else {
|
||||
prop.computed = false
|
||||
}
|
||||
}
|
||||
prop.key = (this.type === tt.num || this.type === tt.string) ? this.parseExprAtom() : this.parseIdent(true)
|
||||
return prop.key = (this.type === tt.num || this.type === tt.string) ? this.parseExprAtom() : this.parseIdent(true)
|
||||
}
|
||||
|
||||
// Initialize empty function node.
|
||||
@@ -627,7 +680,7 @@ pp.parseMethod = function(isGenerator, isAsync) {
|
||||
let node = this.startNode()
|
||||
this.initFunction(node, isAsync)
|
||||
this.expect(tt.parenL)
|
||||
node.params = this.parseBindingList(tt.parenR, false, false)
|
||||
node.params = this.parseBindingList(tt.parenR, false, this.options.features["es7.trailingFunctionCommas"])
|
||||
if (this.options.ecmaVersion >= 6) {
|
||||
node.generator = isGenerator
|
||||
}
|
||||
|
||||
@@ -9,41 +9,9 @@
|
||||
|
||||
function makePredicate(words) {
|
||||
words = words.split(" ")
|
||||
let f = "", cats = []
|
||||
out: for (let i = 0; i < words.length; ++i) {
|
||||
for (let j = 0; j < cats.length; ++j)
|
||||
if (cats[j][0].length == words[i].length) {
|
||||
cats[j].push(words[i])
|
||||
continue out
|
||||
}
|
||||
cats.push([words[i]])
|
||||
return function(str) {
|
||||
return words.indexOf(str) >= 0
|
||||
}
|
||||
function compareTo(arr) {
|
||||
if (arr.length == 1) return f += "return str === " + JSON.stringify(arr[0]) + ";"
|
||||
f += "switch(str){"
|
||||
for (let i = 0; i < arr.length; ++i) f += "case " + JSON.stringify(arr[i]) + ":"
|
||||
f += "return true}return false;"
|
||||
}
|
||||
|
||||
// When there are more than three length categories, an outer
|
||||
// switch first dispatches on the lengths, to save on comparisons.
|
||||
|
||||
if (cats.length > 3) {
|
||||
cats.sort((a, b) => b.length - a.length)
|
||||
f += "switch(str.length){"
|
||||
for (let i = 0; i < cats.length; ++i) {
|
||||
let cat = cats[i]
|
||||
f += "case " + cat[0].length + ":"
|
||||
compareTo(cat)
|
||||
}
|
||||
f += "}"
|
||||
|
||||
// Otherwise, simply generate a flat `switch` statement.
|
||||
|
||||
} else {
|
||||
compareTo(words)
|
||||
}
|
||||
return new Function("str", f)
|
||||
}
|
||||
|
||||
// Reserved word lists for various dialects of the language
|
||||
|
||||
@@ -38,9 +38,6 @@ export {isIdentifierChar, isIdentifierStart} from "./identifier"
|
||||
export {Token} from "./tokenize"
|
||||
export {isNewLine, lineBreak, lineBreakG} from "./whitespace"
|
||||
|
||||
import "../plugins/flow";
|
||||
import "../plugins/jsx";
|
||||
|
||||
export const version = "1.0.0"
|
||||
|
||||
// The main exported interface (under `self.acorn` when in the
|
||||
|
||||
@@ -9,12 +9,17 @@ var STATE_KEYS = [
|
||||
"lastTokEnd",
|
||||
"lineStart",
|
||||
"startLoc",
|
||||
"curLine",
|
||||
"endLoc",
|
||||
"start",
|
||||
"pos",
|
||||
"end",
|
||||
"type",
|
||||
"value"
|
||||
"value",
|
||||
"exprAllowed",
|
||||
"potentialArrowAt",
|
||||
"currLine",
|
||||
"input"
|
||||
];
|
||||
|
||||
pp.getState = function () {
|
||||
@@ -23,6 +28,7 @@ pp.getState = function () {
|
||||
var key = STATE_KEYS[i]
|
||||
state[key] = this[key]
|
||||
}
|
||||
state.context = this.context.slice()
|
||||
return state
|
||||
};
|
||||
|
||||
|
||||
@@ -21,6 +21,7 @@ pp.toAssignable = function(node, isBinding) {
|
||||
node.type = "ObjectPattern"
|
||||
for (let i = 0; i < node.properties.length; i++) {
|
||||
let prop = node.properties[i]
|
||||
if (prop.type === "SpreadProperty") continue;
|
||||
if (prop.kind !== "init") this.raise(prop.key.start, "Object pattern can't contain getter or setter")
|
||||
this.toAssignable(prop.value, isBinding)
|
||||
}
|
||||
@@ -34,6 +35,7 @@ pp.toAssignable = function(node, isBinding) {
|
||||
case "AssignmentExpression":
|
||||
if (node.operator === "=") {
|
||||
node.type = "AssignmentPattern"
|
||||
delete node.operator
|
||||
} else {
|
||||
this.raise(node.left.end, "Only '=' operator can be used for specifying default value.")
|
||||
}
|
||||
@@ -170,7 +172,7 @@ pp.checkLVal = function(expr, isBinding, checkClashes) {
|
||||
break
|
||||
|
||||
case "ObjectPattern":
|
||||
for (let i = 0; i < expr.properties.length; i++) {
|
||||
for (let i = 0; i < expr.properties.length; i++) {
|
||||
var prop = expr.properties[i];
|
||||
if (prop.type === "Property") prop = prop.value;
|
||||
this.checkLVal(prop, isBinding, checkClashes)
|
||||
@@ -193,6 +195,10 @@ pp.checkLVal = function(expr, isBinding, checkClashes) {
|
||||
this.checkLVal(expr.argument, isBinding, checkClashes)
|
||||
break
|
||||
|
||||
case "ParenthesizedExpression":
|
||||
this.checkLVal(expr.expression, isBinding, checkClashes)
|
||||
break
|
||||
|
||||
default:
|
||||
this.raise(expr.start, (isBinding ? "Binding" : "Assigning to") + " rvalue")
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import {reservedWords, keywords} from "./identifier"
|
||||
import {types as tt, lineBreak} from "./tokentype"
|
||||
import {types as tt} from "./tokentype"
|
||||
import {lineBreak} from "./whitespace"
|
||||
|
||||
export function Parser(options, input, startPos) {
|
||||
this.options = options
|
||||
|
||||
@@ -83,10 +83,13 @@ pp.parseStatement = function(declaration, topLevel) {
|
||||
return starttype === tt._import ? this.parseImport(node) : this.parseExport(node)
|
||||
|
||||
case tt.name:
|
||||
if (this.options.features["es7.asyncFunctions"] && this.value === "async" && this.lookahead().type === tt._function) {
|
||||
this.next();
|
||||
this.expect(tt._function);
|
||||
return this.parseFunction(node, true, false, true);
|
||||
if (this.options.features["es7.asyncFunctions"] && this.value === "async") {
|
||||
var lookahead = this.lookahead();
|
||||
if (lookahead.type === tt._function && !this.canInsertSemicolon.call(lookahead)) {
|
||||
this.next();
|
||||
this.expect(tt._function);
|
||||
return this.parseFunction(node, true, false, true);
|
||||
}
|
||||
}
|
||||
|
||||
// If the statement does not start with a statement keyword or a
|
||||
@@ -168,12 +171,6 @@ pp.parseDoStatement = function(node) {
|
||||
this.labels.push(loopLabel)
|
||||
node.body = this.parseStatement(false)
|
||||
this.labels.pop()
|
||||
if (this.options.features["es7.doExpressions"] && this.type !== tt._while) {
|
||||
let container = this.startNodeAt(start)
|
||||
container.expression = this.finishNode(node, "DoExpression")
|
||||
this.semicolon()
|
||||
return this.finishNode(container, "ExpressionStatement")
|
||||
}
|
||||
this.expect(tt._while)
|
||||
node.test = this.parseParenExpression()
|
||||
if (this.options.ecmaVersion >= 6)
|
||||
@@ -350,7 +347,14 @@ pp.parseLabeledStatement = function(node, maybeName, expr) {
|
||||
for (let i = 0; i < this.labels.length; ++i)
|
||||
if (this.labels[i].name === maybeName) this.raise(expr.start, "Label '" + maybeName + "' is already declared")
|
||||
let kind = this.type.isLoop ? "loop" : this.type === tt._switch ? "switch" : null
|
||||
this.labels.push({name: maybeName, kind: kind})
|
||||
for (let i = this.labels.length - 1; i >= 0; i--) {
|
||||
let label = this.labels[i]
|
||||
if (label.statementStart == node.start) {
|
||||
label.statementStart = this.start;
|
||||
label.kind = kind;
|
||||
} else break;
|
||||
}
|
||||
this.labels.push({name: maybeName, kind: kind, statementStart: this.start})
|
||||
node.body = this.parseStatement(true)
|
||||
this.labels.pop()
|
||||
node.label = expr
|
||||
@@ -469,26 +473,29 @@ pp.parseClass = function(node, isStatement) {
|
||||
this.parseClassId(node, isStatement)
|
||||
this.parseClassSuper(node)
|
||||
var classBody = this.startNode()
|
||||
let hadConstructor = false
|
||||
classBody.body = []
|
||||
this.expect(tt.braceL)
|
||||
let decorators = []
|
||||
while (!this.eat(tt.braceR)) {
|
||||
if (this.eat(tt.semi)) continue
|
||||
if (this.type === tt.at) {
|
||||
this.decorators.push(this.parseDecorator())
|
||||
decorators.push(this.parseDecorator())
|
||||
continue
|
||||
}
|
||||
var method = this.startNode()
|
||||
this.takeDecorators(method)
|
||||
if (decorators.length) {
|
||||
method.decorators = decorators
|
||||
decorators = []
|
||||
}
|
||||
let isMaybeStatic = this.type === tt.name && this.value === "static"
|
||||
var isGenerator = this.eat(tt.star), isAsync = false
|
||||
this.parsePropertyName(method)
|
||||
if (this.type !== tt.parenL && !method.computed && method.key.type === "Identifier" &&
|
||||
method.key.name === "static") {
|
||||
method.static = isMaybeStatic && this.type !== tt.parenL
|
||||
if (method.static) {
|
||||
if (isGenerator) this.unexpected()
|
||||
method['static'] = true
|
||||
isGenerator = this.eat(tt.star)
|
||||
this.parsePropertyName(method)
|
||||
} else {
|
||||
method['static'] = false
|
||||
}
|
||||
if (!isGenerator && method.key.type === "Identifier" && !method.computed && this.isClassProperty()) {
|
||||
classBody.body.push(this.parseClassProperty(method))
|
||||
@@ -499,25 +506,41 @@ pp.parseClass = function(node, isStatement) {
|
||||
isAsync = true
|
||||
this.parsePropertyName(method)
|
||||
}
|
||||
let isGetSet = false
|
||||
method.kind = "method"
|
||||
if (!method.computed && !isGenerator) {
|
||||
if (method.key.type === "Identifier") {
|
||||
if (this.type !== tt.parenL && (method.key.name === "get" || method.key.name === "set")) {
|
||||
method.kind = method.key.name
|
||||
this.parsePropertyName(method)
|
||||
} else if (!method['static'] && method.key.name === "constructor") {
|
||||
method.kind = "constructor"
|
||||
}
|
||||
} else if (!method['static'] && method.key.type === "Literal" && method.key.value === "constructor") {
|
||||
if (!method.computed) {
|
||||
let {key} = method
|
||||
if (!isAsync && !isGenerator && key.type === "Identifier" && this.type !== tt.parenL && (key.name === "get" || key.name === "set")) {
|
||||
isGetSet = true
|
||||
method.kind = key.name
|
||||
key = this.parsePropertyName(method)
|
||||
}
|
||||
if (!method.static && (key.type === "Identifier" && key.name === "constructor" ||
|
||||
key.type === "Literal" && key.value === "constructor")) {
|
||||
if (hadConstructor) this.raise(key.start, "Duplicate constructor in the same class")
|
||||
if (isGetSet) this.raise(key.start, "Constructor can't have get/set modifier")
|
||||
if (isGenerator) this.raise(key.start, "Constructor can't be a generator")
|
||||
if (isAsync) this.raise(key.start, "Constructor can't be an async function")
|
||||
method.kind = "constructor"
|
||||
hadConstructor = true
|
||||
}
|
||||
}
|
||||
if (method.kind === "constructor" && method.decorators) {
|
||||
this.raise(method.start, "You can't attach decorators to a class constructor")
|
||||
}
|
||||
this.parseClassMethod(classBody, method, isGenerator, isAsync)
|
||||
if (isGetSet) {
|
||||
let paramCount = method.kind === "get" ? 0 : 1
|
||||
if (method.value.params.length !== paramCount) {
|
||||
let start = method.value.start
|
||||
if (method.kind === "get")
|
||||
this.raise(start, "getter should have no params");
|
||||
else
|
||||
this.raise(start, "setter should have exactly one param")
|
||||
}
|
||||
}
|
||||
}
|
||||
if (this.decorators.length) {
|
||||
if (decorators.length) {
|
||||
this.raise(this.start, "You have trailing decorators with no method");
|
||||
}
|
||||
node.body = this.finishNode(classBody, "ClassBody")
|
||||
@@ -570,7 +593,7 @@ pp.parseExport = function(node) {
|
||||
this.parseExportFrom(node)
|
||||
return this.finishNode(node, "ExportAllDeclaration")
|
||||
}
|
||||
} else if (this.isExportDefaultSpecifier()) {
|
||||
} else if (this.options.features["es7.exportExtensions"] && this.isExportDefaultSpecifier()) {
|
||||
let specifier = this.startNode()
|
||||
specifier.exported = this.parseIdent(true)
|
||||
node.specifiers = [this.finishNode(specifier, "ExportDefaultSpecifier")]
|
||||
@@ -687,7 +710,6 @@ pp.parseImport = function(node) {
|
||||
if (this.type === tt.string) {
|
||||
node.specifiers = empty
|
||||
node.source = this.parseExprAtom()
|
||||
node.kind = ""
|
||||
} else {
|
||||
node.specifiers = []
|
||||
this.parseImportSpecifiers(node)
|
||||
|
||||
@@ -25,6 +25,9 @@ export class Token {
|
||||
|
||||
const pp = Parser.prototype
|
||||
|
||||
// Are we running under Rhino?
|
||||
const isRhino = typeof Packages == "object" && Object.prototype.toString.call(Packages) == "[object JavaPackage]"
|
||||
|
||||
// Move to the next token
|
||||
|
||||
pp.next = function() {
|
||||
@@ -283,7 +286,7 @@ pp.readToken_lt_gt = function(code) { // '<>'
|
||||
}
|
||||
if (next == 33 && code == 60 && this.input.charCodeAt(this.pos + 2) == 45 &&
|
||||
this.input.charCodeAt(this.pos + 3) == 45) {
|
||||
if (this.inModule) unexpected()
|
||||
if (this.inModule) this.unexpected()
|
||||
// `<!--`, an XML-style comment that should be interpreted as a line comment
|
||||
this.skipLineComment(4)
|
||||
this.skipSpace()
|
||||
@@ -320,7 +323,13 @@ pp.getTokenFromCode = function(code) {
|
||||
case 93: ++this.pos; return this.finishToken(tt.bracketR)
|
||||
case 123: ++this.pos; return this.finishToken(tt.braceL)
|
||||
case 125: ++this.pos; return this.finishToken(tt.braceR)
|
||||
case 58: ++this.pos; return this.finishToken(tt.colon)
|
||||
|
||||
case 58:
|
||||
if (this.options.features["es7.functionBind"] && this.input.charCodeAt(this.pos + 1) === 58)
|
||||
return this.finishOp(tt.doubleColon, 2)
|
||||
++this.pos
|
||||
return this.finishToken(tt.colon)
|
||||
|
||||
case 63: ++this.pos; return this.finishToken(tt.question)
|
||||
case 64: ++this.pos; return this.finishToken(tt.at)
|
||||
|
||||
@@ -424,23 +433,30 @@ pp.readRegexp = function() {
|
||||
// negatives in unlikely scenarios. For example, `[\u{61}-b]` is a
|
||||
// perfectly valid pattern that is equivalent to `[a-b]`, but it would
|
||||
// be replaced by `[x-b]` which throws an error.
|
||||
tmp = tmp.replace(/\\u([a-fA-F0-9]{4})|\\u\{([0-9a-fA-F]+)\}|[\uD800-\uDBFF][\uDC00-\uDFFF]/g, "x")
|
||||
tmp = tmp.replace(/\\u\{([0-9a-fA-F]+)\}/g, (match, code, offset) => {
|
||||
code = Number("0x" + code)
|
||||
if (code > 0x10FFFF) this.raise(start + offset + 3, "Code point out of bounds")
|
||||
return "x"
|
||||
});
|
||||
tmp = tmp.replace(/\\u([a-fA-F0-9]{4})|[\uD800-\uDBFF][\uDC00-\uDFFF]/g, "x")
|
||||
}
|
||||
}
|
||||
// Detect invalid regular expressions.
|
||||
try {
|
||||
new RegExp(tmp)
|
||||
} catch (e) {
|
||||
if (e instanceof SyntaxError) this.raise(start, "Error parsing regular expression: " + e.message)
|
||||
this.raise(e)
|
||||
}
|
||||
// Get a regular expression object for this pattern-flag pair, or `null` in
|
||||
// case the current environment doesn't support the flags it uses.
|
||||
let value
|
||||
try {
|
||||
value = new RegExp(content, mods)
|
||||
} catch (err) {
|
||||
value = null
|
||||
let value = null
|
||||
// Rhino's regular expression parser is flaky and throws uncatchable exceptions,
|
||||
// so don't do detection if we are running under Rhino
|
||||
if (!isRhino) {
|
||||
try {
|
||||
new RegExp(tmp)
|
||||
} catch (e) {
|
||||
if (e instanceof SyntaxError) this.raise(start, "Error parsing regular expression: " + e.message)
|
||||
this.raise(e)
|
||||
}
|
||||
// Get a regular expression object for this pattern-flag pair, or `null` in
|
||||
// case the current environment doesn't support the flags it uses.
|
||||
try {
|
||||
value = new RegExp(content, mods)
|
||||
} catch (err) {}
|
||||
}
|
||||
return this.finishToken(tt.regexp, {pattern: content, flags: mods, value: value})
|
||||
}
|
||||
@@ -508,10 +524,10 @@ pp.readCodePoint = function() {
|
||||
|
||||
if (ch === 123) {
|
||||
if (this.options.ecmaVersion < 6) this.unexpected()
|
||||
++this.pos
|
||||
let codePos = ++this.pos
|
||||
code = this.readHexChar(this.input.indexOf('}', this.pos) - this.pos)
|
||||
++this.pos
|
||||
if (code > 0x10FFFF) this.unexpected()
|
||||
if (code > 0x10FFFF) this.raise(codePos, "Code point out of bounds")
|
||||
} else {
|
||||
code = this.readHexChar(4)
|
||||
}
|
||||
@@ -533,7 +549,7 @@ pp.readString = function(quote) {
|
||||
if (ch === quote) break
|
||||
if (ch === 92) { // '\'
|
||||
out += this.input.slice(chunkStart, this.pos)
|
||||
out += this.readEscapedChar()
|
||||
out += this.readEscapedChar(false)
|
||||
chunkStart = this.pos
|
||||
} else {
|
||||
if (isNewLine(ch)) this.raise(this.start, "Unterminated string constant")
|
||||
@@ -566,16 +582,20 @@ pp.readTmplToken = function() {
|
||||
}
|
||||
if (ch === 92) { // '\'
|
||||
out += this.input.slice(chunkStart, this.pos)
|
||||
out += this.readEscapedChar()
|
||||
out += this.readEscapedChar(true)
|
||||
chunkStart = this.pos
|
||||
} else if (isNewLine(ch)) {
|
||||
out += this.input.slice(chunkStart, this.pos)
|
||||
++this.pos
|
||||
if (ch === 13 && this.input.charCodeAt(this.pos) === 10) {
|
||||
++this.pos
|
||||
out += "\n"
|
||||
} else {
|
||||
out += String.fromCharCode(ch)
|
||||
switch (ch) {
|
||||
case 13:
|
||||
if (this.input.charCodeAt(this.pos) === 10) ++this.pos;
|
||||
case 10:
|
||||
out += "\n";
|
||||
break;
|
||||
default:
|
||||
out += String.fromCharCode(ch);
|
||||
break;
|
||||
}
|
||||
if (this.options.locations) {
|
||||
++this.curLine
|
||||
@@ -590,42 +610,46 @@ pp.readTmplToken = function() {
|
||||
|
||||
// Used to read escaped characters
|
||||
|
||||
pp.readEscapedChar = function() {
|
||||
pp.readEscapedChar = function(inTemplate) {
|
||||
let ch = this.input.charCodeAt(++this.pos)
|
||||
let octal = /^[0-7]+/.exec(this.input.slice(this.pos, this.pos + 3))
|
||||
if (octal) octal = octal[0]
|
||||
while (octal && parseInt(octal, 8) > 255) octal = octal.slice(0, -1)
|
||||
if (octal === "0") octal = null
|
||||
++this.pos
|
||||
if (octal) {
|
||||
if (this.strict) this.raise(this.pos - 2, "Octal literal in strict mode")
|
||||
this.pos += octal.length - 1
|
||||
return String.fromCharCode(parseInt(octal, 8))
|
||||
} else {
|
||||
switch (ch) {
|
||||
case 110: return "\n"; // 'n' -> '\n'
|
||||
case 114: return "\r"; // 'r' -> '\r'
|
||||
case 120: return String.fromCharCode(this.readHexChar(2)); // 'x'
|
||||
case 117: return codePointToString(this.readCodePoint()); // 'u'
|
||||
case 116: return "\t"; // 't' -> '\t'
|
||||
case 98: return "\b"; // 'b' -> '\b'
|
||||
case 118: return "\u000b"; // 'v' -> '\u000b'
|
||||
case 102: return "\f"; // 'f' -> '\f'
|
||||
case 48: return "\0"; // 0 -> '\0'
|
||||
case 13: if (this.input.charCodeAt(this.pos) === 10) ++this.pos; // '\r\n'
|
||||
case 10: // ' \n'
|
||||
if (this.options.locations) { this.lineStart = this.pos; ++this.curLine }
|
||||
return ""
|
||||
default: return String.fromCharCode(ch)
|
||||
switch (ch) {
|
||||
case 110: return "\n"; // 'n' -> '\n'
|
||||
case 114: return "\r"; // 'r' -> '\r'
|
||||
case 120: return String.fromCharCode(this.readHexChar(2)); // 'x'
|
||||
case 117: return codePointToString(this.readCodePoint()); // 'u'
|
||||
case 116: return "\t"; // 't' -> '\t'
|
||||
case 98: return "\b"; // 'b' -> '\b'
|
||||
case 118: return "\u000b"; // 'v' -> '\u000b'
|
||||
case 102: return "\f"; // 'f' -> '\f'
|
||||
case 13: if (this.input.charCodeAt(this.pos) === 10) ++this.pos; // '\r\n'
|
||||
case 10: // ' \n'
|
||||
if (this.options.locations) { this.lineStart = this.pos; ++this.curLine }
|
||||
return ""
|
||||
default:
|
||||
if (ch >= 48 && ch <= 55) {
|
||||
let octalStr = this.input.substr(this.pos - 1, 3).match(/^[0-7]+/)[0]
|
||||
let octal = parseInt(octalStr, 8)
|
||||
if (octal > 255) {
|
||||
octalStr = octalStr.slice(0, -1)
|
||||
octal = parseInt(octalStr, 8)
|
||||
}
|
||||
if (octal > 0 && (this.strict || inTemplate)) {
|
||||
this.raise(this.pos - 2, "Octal literal in strict mode")
|
||||
}
|
||||
this.pos += octalStr.length - 1
|
||||
return String.fromCharCode(octal)
|
||||
}
|
||||
return String.fromCharCode(ch)
|
||||
}
|
||||
}
|
||||
|
||||
// Used to read character escape sequences ('\x', '\u', '\U').
|
||||
|
||||
pp.readHexChar = function(len) {
|
||||
let codePos = this.pos
|
||||
let n = this.readInt(16, len)
|
||||
if (n === null) this.raise(this.start, "Bad character escape sequence")
|
||||
if (n === null) this.raise(codePos, "Bad character escape sequence")
|
||||
return n
|
||||
}
|
||||
|
||||
|
||||
@@ -54,6 +54,7 @@ export const types = {
|
||||
comma: new TokenType(",", beforeExpr),
|
||||
semi: new TokenType(";", beforeExpr),
|
||||
colon: new TokenType(":", beforeExpr),
|
||||
doubleColon: new TokenType("::", beforeExpr),
|
||||
dot: new TokenType("."),
|
||||
question: new TokenType("?", beforeExpr),
|
||||
arrow: new TokenType("=>", beforeExpr),
|
||||
@@ -116,7 +117,7 @@ kw("do", {isLoop: true})
|
||||
kw("else", beforeExpr)
|
||||
kw("finally")
|
||||
kw("for", {isLoop: true})
|
||||
kw("function")
|
||||
kw("function", startsExpr)
|
||||
kw("if")
|
||||
kw("return", beforeExpr)
|
||||
kw("switch")
|
||||
|
||||
@@ -1,3 +1,6 @@
|
||||
/* eslint no-new-func: 0 */
|
||||
|
||||
require("./node");
|
||||
var transform = module.exports = require("../transformation");
|
||||
|
||||
transform.options = require("../transformation/file/options");
|
||||
@@ -11,7 +14,7 @@ transform.run = function (code, opts = {}) {
|
||||
};
|
||||
|
||||
transform.load = function (url, callback, opts = {}, hold) {
|
||||
opts.filename ||= url;
|
||||
opts.filename = opts.filename || url;
|
||||
|
||||
var xhr = global.ActiveXObject ? new global.ActiveXObject("Microsoft.XMLHTTP") : new global.XMLHttpRequest();
|
||||
xhr.open("GET", url, true);
|
||||
|
||||
@@ -4,12 +4,14 @@ import * as acorn from "../../acorn";
|
||||
import * as util from "../util";
|
||||
import fs from "fs";
|
||||
|
||||
export { util, acorn };
|
||||
export { util, acorn, transform };
|
||||
export { pipeline } from "../transformation";
|
||||
export { canCompile } from "../util";
|
||||
|
||||
export { default as options } from "../transformation/file/options";
|
||||
export { default as options } from "../transformation/file/options/config";
|
||||
export { default as Plugin } from "../transformation/plugin";
|
||||
export { default as Transformer } from "../transformation/transformer";
|
||||
export { default as transform } from "../transformation";
|
||||
export { default as Pipeline } from "../transformation/pipeline";
|
||||
export { default as traverse } from "../traversal";
|
||||
export { default as buildExternalHelpers } from "../tools/build-external-helpers";
|
||||
export { version } from "../../../package";
|
||||
@@ -18,7 +20,7 @@ import * as t from "../types";
|
||||
export { t as types };
|
||||
|
||||
export function register(opts?: Object) {
|
||||
var callback = require("./register/node");
|
||||
var callback = require("./register/node-polyfill");
|
||||
if (opts != null) callback(opts);
|
||||
return callback;
|
||||
}
|
||||
@@ -52,5 +54,22 @@ export function transformFile(filename: string, opts?: Object, callback: Functio
|
||||
|
||||
export function transformFileSync(filename: string, opts?: Object = {}) {
|
||||
opts.filename = filename;
|
||||
return transform(fs.readFileSync(filename), opts);
|
||||
return transform(fs.readFileSync(filename, "utf8"), opts);
|
||||
}
|
||||
|
||||
export function parse(code, opts = {}) {
|
||||
opts.allowHashBang = true;
|
||||
opts.sourceType = "module";
|
||||
opts.ecmaVersion = Infinity;
|
||||
opts.plugins = {
|
||||
jsx: true,
|
||||
flow: true
|
||||
};
|
||||
opts.features = {};
|
||||
|
||||
for (var key in transform.pipeline.transformers) {
|
||||
opts.features[key] = true;
|
||||
}
|
||||
|
||||
return acorn.parse(code, opts);
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
// required to safely use babel/register within a browserify codebase
|
||||
|
||||
export default function () {};
|
||||
export default function () {}
|
||||
|
||||
import "../../polyfill";
|
||||
|
||||
@@ -1,9 +1,8 @@
|
||||
import path from "path";
|
||||
import os from "os";
|
||||
import fs from "fs";
|
||||
import userHome from "user-home";
|
||||
import homeOrTmp from "home-or-tmp";
|
||||
|
||||
const FILENAME = process.env.BABEL_CACHE_PATH || path.join(userHome || os.tmpdir(), ".babel.json");
|
||||
const FILENAME = process.env.BABEL_CACHE_PATH || path.join(homeOrTmp, ".babel.json");
|
||||
var data = {};
|
||||
|
||||
export function save() {
|
||||
|
||||
2
src/babel/api/register/node-polyfill.js
Normal file
2
src/babel/api/register/node-polyfill.js
Normal file
@@ -0,0 +1,2 @@
|
||||
import "../../polyfill";
|
||||
export { default } from "./node";
|
||||
@@ -1,12 +1,12 @@
|
||||
import "../../polyfill";
|
||||
import sourceMapSupport from "source-map-support";
|
||||
import * as registerCache from "./cache";
|
||||
import resolveRc from "../../tools/resolve-rc";
|
||||
import resolveRc from "../../transformation/file/options/resolve-rc";
|
||||
import extend from "lodash/object/extend";
|
||||
import * as babel from "../node";
|
||||
import each from "lodash/collection/each";
|
||||
import * as util from "../../util";
|
||||
import fs from "fs";
|
||||
import path from "path";
|
||||
|
||||
sourceMapSupport.install({
|
||||
handleUncaughtExceptions: false,
|
||||
@@ -31,19 +31,27 @@ var cache = registerCache.get();
|
||||
//
|
||||
|
||||
var transformOpts = {};
|
||||
var ignoreRegex = /node_modules/;
|
||||
var onlyRegex;
|
||||
|
||||
var ignore;
|
||||
var only;
|
||||
|
||||
var oldHandlers = {};
|
||||
var maps = {};
|
||||
|
||||
var cwd = process.cwd();
|
||||
|
||||
var getRelativePath = function (filename){
|
||||
return path.relative(cwd, filename);
|
||||
};
|
||||
|
||||
var mtime = function (filename) {
|
||||
return +fs.statSync(filename).mtime;
|
||||
};
|
||||
|
||||
var compile = function (filename) {
|
||||
var compile = function (filename, opts = {}) {
|
||||
var result;
|
||||
|
||||
var opts = extend({}, transformOpts);
|
||||
opts = extend(opts, transformOpts);
|
||||
|
||||
// this will be done when the file is transformed anyway but we need all
|
||||
// the options so we can generate the cache key
|
||||
@@ -51,6 +59,9 @@ var compile = function (filename) {
|
||||
|
||||
var cacheKey = `${filename}:${JSON.stringify(opts)}:${babel.version}`;
|
||||
|
||||
var env = process.env.BABEL_ENV || process.env.NODE_ENV;
|
||||
if (env) cacheKey += `:${env}`;
|
||||
|
||||
if (cache) {
|
||||
var cached = cache[cacheKey];
|
||||
if (cached && cached.mtime === mtime(filename)) {
|
||||
@@ -76,12 +87,16 @@ var compile = function (filename) {
|
||||
};
|
||||
|
||||
var shouldIgnore = function (filename) {
|
||||
return (ignoreRegex && ignoreRegex.test(filename)) || (onlyRegex && !onlyRegex.test(filename));
|
||||
if (!ignore && !only) {
|
||||
return getRelativePath(filename).split(path.sep).indexOf("node_modules") >= 0;
|
||||
} else {
|
||||
return util.shouldIgnore(filename, ignore || [], only);
|
||||
}
|
||||
};
|
||||
|
||||
var istanbulMonkey = {};
|
||||
|
||||
if (process.env.running_under_istanbul) { // jshint ignore:line
|
||||
if (process.env.running_under_istanbul) {
|
||||
// we need to monkey patch fs.readFileSync so we can hook into
|
||||
// what istanbul gets, it's extremely dirty but it's the only way
|
||||
var _readFileSync = fs.readFileSync;
|
||||
@@ -89,7 +104,9 @@ if (process.env.running_under_istanbul) { // jshint ignore:line
|
||||
fs.readFileSync = function (filename) {
|
||||
if (istanbulMonkey[filename]) {
|
||||
delete istanbulMonkey[filename];
|
||||
var code = compile(filename);
|
||||
var code = compile(filename, {
|
||||
auxiliaryCommentBefore: "istanbul ignore next"
|
||||
});
|
||||
istanbulMonkey[filename] = true;
|
||||
return code;
|
||||
} else {
|
||||
@@ -108,10 +125,10 @@ var normalLoader = function (m, filename) {
|
||||
};
|
||||
|
||||
var registerExtension = function (ext) {
|
||||
var old = oldHandlers[ext] || oldHandlers[".js"];
|
||||
var old = oldHandlers[ext] || oldHandlers[".js"] || require.extensions[".js"];
|
||||
|
||||
var loader = normalLoader;
|
||||
if (process.env.running_under_istanbul) loader = istanbulLoader; // jshint ignore:line
|
||||
if (process.env.running_under_istanbul) loader = istanbulLoader;
|
||||
|
||||
require.extensions[ext] = function (m, filename) {
|
||||
if (shouldIgnore(filename)) {
|
||||
@@ -142,8 +159,8 @@ var hookExtensions = function (_exts) {
|
||||
hookExtensions(util.canCompile.EXTENSIONS);
|
||||
|
||||
export default function (opts = {}) {
|
||||
if (opts.only != null) onlyRegex = util.regexify(opts.only);
|
||||
if (opts.ignore != null) ignoreRegex = util.regexify(opts.ignore);
|
||||
if (opts.only != null) only = util.arrayify(opts.only, util.regexify);
|
||||
if (opts.ignore != null) ignore = util.arrayify(opts.ignore, util.regexify);
|
||||
|
||||
if (opts.extensions) hookExtensions(util.arrayify(opts.extensions));
|
||||
|
||||
@@ -155,17 +172,4 @@ export default function (opts = {}) {
|
||||
delete opts.only;
|
||||
|
||||
extend(transformOpts, opts);
|
||||
};
|
||||
|
||||
//
|
||||
|
||||
try {
|
||||
var runtimePackage = require("babel-runtime/package");
|
||||
var version = require("../../../../package").version;
|
||||
if (runtimePackage.version !== version) {
|
||||
throw new ReferenceError(`The verison of babel-runtime of ${runtimePackage.runtime} that you have installed does not match the babel verison of ${version}`);
|
||||
}
|
||||
} catch (err) {
|
||||
if (err.code !== "MODULE_NOT_FOUND") throw err;
|
||||
}
|
||||
|
||||
|
||||
@@ -70,14 +70,14 @@ export default class Buffer {
|
||||
}
|
||||
|
||||
newline(i, removeLast) {
|
||||
if (this.format.compact) return;
|
||||
if (this.format.compact || this.format.retainLines) return;
|
||||
|
||||
if (this.format.concise) {
|
||||
this.space();
|
||||
return;
|
||||
}
|
||||
|
||||
removeLast ||= false;
|
||||
removeLast = removeLast || false;
|
||||
|
||||
if (isNumber(i)) {
|
||||
i = Math.min(2, i);
|
||||
@@ -117,8 +117,9 @@ export default class Buffer {
|
||||
|
||||
_removeSpacesAfterLastNewline() {
|
||||
var lastNewlineIndex = this.buf.lastIndexOf("\n");
|
||||
if (lastNewlineIndex === -1)
|
||||
if (lastNewlineIndex === -1) {
|
||||
return;
|
||||
}
|
||||
|
||||
var index = this.buf.length - 1;
|
||||
while (index > lastNewlineIndex) {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
export function File(node, print) {
|
||||
print(node.program);
|
||||
print.plain(node.program);
|
||||
}
|
||||
|
||||
export function Program(node, print) {
|
||||
@@ -13,7 +13,11 @@ export function BlockStatement(node, print) {
|
||||
this.push("{");
|
||||
this.newline();
|
||||
print.sequence(node.body, { indent: true });
|
||||
this.removeLast("\n");
|
||||
if (!this.format.retainLines) this.removeLast("\n");
|
||||
this.rightBrace();
|
||||
}
|
||||
}
|
||||
|
||||
export function Noop() {
|
||||
|
||||
}
|
||||
|
||||
@@ -3,16 +3,16 @@ export function ClassDeclaration(node, print) {
|
||||
this.push("class");
|
||||
|
||||
if (node.id) {
|
||||
this.space();
|
||||
print(node.id);
|
||||
this.push(" ");
|
||||
print.plain(node.id);
|
||||
}
|
||||
|
||||
print(node.typeParameters);
|
||||
print.plain(node.typeParameters);
|
||||
|
||||
if (node.superClass) {
|
||||
this.push(" extends ");
|
||||
print(node.superClass);
|
||||
print(node.superTypeParameters);
|
||||
print.plain(node.superClass);
|
||||
print.plain(node.superTypeParameters);
|
||||
}
|
||||
|
||||
if (node.implements) {
|
||||
@@ -21,7 +21,7 @@ export function ClassDeclaration(node, print) {
|
||||
}
|
||||
|
||||
this.space();
|
||||
print(node.body);
|
||||
print.plain(node.body);
|
||||
}
|
||||
|
||||
export { ClassDeclaration as ClassExpression };
|
||||
@@ -46,13 +46,13 @@ export function ClassProperty(node, print) {
|
||||
print.list(node.decorators);
|
||||
|
||||
if (node.static) this.push("static ");
|
||||
print(node.key);
|
||||
print(node.typeAnnotation);
|
||||
print.plain(node.key);
|
||||
print.plain(node.typeAnnotation);
|
||||
if (node.value) {
|
||||
this.space();
|
||||
this.push("=");
|
||||
this.space();
|
||||
print(node.value);
|
||||
print.plain(node.value);
|
||||
}
|
||||
this.semicolon();
|
||||
}
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
export function ComprehensionBlock(node, print) {
|
||||
this.keyword("for");
|
||||
this.push("(");
|
||||
print(node.left);
|
||||
print.plain(node.left);
|
||||
this.push(" of ");
|
||||
print(node.right);
|
||||
print.plain(node.right);
|
||||
this.push(")");
|
||||
}
|
||||
|
||||
@@ -16,12 +16,12 @@ export function ComprehensionExpression(node, print) {
|
||||
if (node.filter) {
|
||||
this.keyword("if");
|
||||
this.push("(");
|
||||
print(node.filter);
|
||||
print.plain(node.filter);
|
||||
this.push(")");
|
||||
this.space();
|
||||
}
|
||||
|
||||
print(node.body);
|
||||
print.plain(node.body);
|
||||
|
||||
this.push(node.generator ? ")" : "]");
|
||||
}
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
import isInteger from "is-integer";
|
||||
import isNumber from "lodash/lang/isNumber";
|
||||
import * as t from "../../types";
|
||||
|
||||
@@ -16,40 +15,46 @@ export function UnaryExpression(node, print) {
|
||||
|
||||
this.push(node.operator);
|
||||
if (hasSpace) this.push(" ");
|
||||
print(node.argument);
|
||||
print.plain(node.argument);
|
||||
}
|
||||
|
||||
export function DoExpression(node, print) {
|
||||
this.push("do");
|
||||
this.space();
|
||||
print(node.body);
|
||||
print.plain(node.body);
|
||||
}
|
||||
|
||||
export function ParenthesizedExpression(node, print) {
|
||||
this.push("(");
|
||||
print.plain(node.expression);
|
||||
this.push(")");
|
||||
}
|
||||
|
||||
export function UpdateExpression(node, print) {
|
||||
if (node.prefix) {
|
||||
this.push(node.operator);
|
||||
print(node.argument);
|
||||
print.plain(node.argument);
|
||||
} else {
|
||||
print(node.argument);
|
||||
print.plain(node.argument);
|
||||
this.push(node.operator);
|
||||
}
|
||||
}
|
||||
|
||||
export function ConditionalExpression(node, print) {
|
||||
print(node.test);
|
||||
print.plain(node.test);
|
||||
this.space();
|
||||
this.push("?");
|
||||
this.space();
|
||||
print(node.consequent);
|
||||
print.plain(node.consequent);
|
||||
this.space();
|
||||
this.push(":");
|
||||
this.space();
|
||||
print(node.alternate);
|
||||
print.plain(node.alternate);
|
||||
}
|
||||
|
||||
export function NewExpression(node, print) {
|
||||
this.push("new ");
|
||||
print(node.callee);
|
||||
print.plain(node.callee);
|
||||
this.push("(");
|
||||
print.list(node.arguments);
|
||||
this.push(")");
|
||||
@@ -69,17 +74,20 @@ export function Super() {
|
||||
|
||||
export function Decorator(node, print) {
|
||||
this.push("@");
|
||||
print(node.expression);
|
||||
print.plain(node.expression);
|
||||
this.newline();
|
||||
}
|
||||
|
||||
export function CallExpression(node, print) {
|
||||
print(node.callee);
|
||||
print.plain(node.callee);
|
||||
|
||||
this.push("(");
|
||||
|
||||
var separator = ",";
|
||||
|
||||
if (node._prettyCall) {
|
||||
var isPrettyCall = node._prettyCall && !this.format.retainLines;
|
||||
|
||||
if (isPrettyCall) {
|
||||
separator += "\n";
|
||||
this.newline();
|
||||
this.indent();
|
||||
@@ -89,7 +97,7 @@ export function CallExpression(node, print) {
|
||||
|
||||
print.list(node.arguments, { separator: separator });
|
||||
|
||||
if (node._prettyCall) {
|
||||
if (isPrettyCall) {
|
||||
this.newline();
|
||||
this.dedent();
|
||||
}
|
||||
@@ -106,8 +114,8 @@ var buildYieldAwait = function (keyword) {
|
||||
}
|
||||
|
||||
if (node.argument) {
|
||||
this.space();
|
||||
print(node.argument);
|
||||
this.push(" ");
|
||||
print.plain(node.argument);
|
||||
}
|
||||
};
|
||||
};
|
||||
@@ -120,30 +128,39 @@ export function EmptyStatement() {
|
||||
}
|
||||
|
||||
export function ExpressionStatement(node, print) {
|
||||
print(node.expression);
|
||||
print.plain(node.expression);
|
||||
this.semicolon();
|
||||
}
|
||||
|
||||
export function AssignmentPattern(node, print) {
|
||||
print.plain(node.left);
|
||||
this.push(" = ");
|
||||
print.plain(node.right);
|
||||
}
|
||||
|
||||
export function AssignmentExpression(node, print) {
|
||||
// todo: add cases where the spaces can be dropped when in compact mode
|
||||
print(node.left);
|
||||
print.plain(node.left);
|
||||
this.push(" ");
|
||||
this.push(node.operator);
|
||||
this.push(" ");
|
||||
print(node.right);
|
||||
print.plain(node.right);
|
||||
}
|
||||
|
||||
export function BindExpression(node, print) {
|
||||
print.plain(node.object);
|
||||
this.push("::");
|
||||
print.plain(node.callee);
|
||||
}
|
||||
|
||||
export {
|
||||
AssignmentExpression as BinaryExpression,
|
||||
AssignmentExpression as LogicalExpression,
|
||||
AssignmentExpression as AssignmentPattern
|
||||
AssignmentExpression as LogicalExpression
|
||||
};
|
||||
|
||||
var SCIENTIFIC_NOTATION = /e/i;
|
||||
|
||||
export function MemberExpression(node, print) {
|
||||
var obj = node.object;
|
||||
print(obj);
|
||||
print.plain(obj);
|
||||
|
||||
if (!node.computed && t.isMemberExpression(node.property)) {
|
||||
throw new TypeError("Got a MemberExpression for MemberExpression property");
|
||||
@@ -156,21 +173,16 @@ export function MemberExpression(node, print) {
|
||||
|
||||
if (computed) {
|
||||
this.push("[");
|
||||
print(node.property);
|
||||
print.plain(node.property);
|
||||
this.push("]");
|
||||
} else {
|
||||
// 5..toFixed(2);
|
||||
if (t.isLiteral(obj) && isInteger(obj.value) && !SCIENTIFIC_NOTATION.test(obj.value.toString())) {
|
||||
this.push(".");
|
||||
}
|
||||
|
||||
this.push(".");
|
||||
print(node.property);
|
||||
print.plain(node.property);
|
||||
}
|
||||
}
|
||||
|
||||
export function MetaProperty(node, print) {
|
||||
print(node.meta);
|
||||
print.plain(node.meta);
|
||||
this.push(".");
|
||||
print(node.property);
|
||||
print.plain(node.property);
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@ export function AnyTypeAnnotation() {
|
||||
}
|
||||
|
||||
export function ArrayTypeAnnotation(node, print) {
|
||||
print(node.elementType);
|
||||
print.plain(node.elementType);
|
||||
this.push("[");
|
||||
this.push("]");
|
||||
}
|
||||
@@ -21,27 +21,27 @@ export function DeclareClass(node, print) {
|
||||
|
||||
export function DeclareFunction(node, print) {
|
||||
this.push("declare function ");
|
||||
print(node.id);
|
||||
print(node.id.typeAnnotation.typeAnnotation);
|
||||
print.plain(node.id);
|
||||
print.plain(node.id.typeAnnotation.typeAnnotation);
|
||||
this.semicolon();
|
||||
}
|
||||
|
||||
export function DeclareModule(node, print) {
|
||||
this.push("declare module ");
|
||||
print(node.id);
|
||||
print.plain(node.id);
|
||||
this.space();
|
||||
print(node.body);
|
||||
print.plain(node.body);
|
||||
}
|
||||
|
||||
export function DeclareVariable(node, print) {
|
||||
this.push("declare var ");
|
||||
print(node.id);
|
||||
print(node.id.typeAnnotation);
|
||||
print.plain(node.id);
|
||||
print.plain(node.id.typeAnnotation);
|
||||
this.semicolon();
|
||||
}
|
||||
|
||||
export function FunctionTypeAnnotation(node, print, parent) {
|
||||
print(node.typeParameters);
|
||||
print.plain(node.typeParameters);
|
||||
this.push("(");
|
||||
print.list(node.params);
|
||||
|
||||
@@ -51,7 +51,7 @@ export function FunctionTypeAnnotation(node, print, parent) {
|
||||
this.space();
|
||||
}
|
||||
this.push("...");
|
||||
print(node.rest);
|
||||
print.plain(node.rest);
|
||||
}
|
||||
|
||||
this.push(")");
|
||||
@@ -65,33 +65,33 @@ export function FunctionTypeAnnotation(node, print, parent) {
|
||||
}
|
||||
|
||||
this.space();
|
||||
print(node.returnType);
|
||||
print.plain(node.returnType);
|
||||
}
|
||||
|
||||
export function FunctionTypeParam(node, print) {
|
||||
print(node.name);
|
||||
print.plain(node.name);
|
||||
if (node.optional) this.push("?");
|
||||
this.push(":");
|
||||
this.space();
|
||||
print(node.typeAnnotation);
|
||||
print.plain(node.typeAnnotation);
|
||||
}
|
||||
|
||||
export function InterfaceExtends(node, print) {
|
||||
print(node.id);
|
||||
print(node.typeParameters);
|
||||
print.plain(node.id);
|
||||
print.plain(node.typeParameters);
|
||||
}
|
||||
|
||||
export { InterfaceExtends as ClassImplements, InterfaceExtends as GenericTypeAnnotation };
|
||||
|
||||
export function _interfaceish(node, print) {
|
||||
print(node.id);
|
||||
print(node.typeParameters);
|
||||
print.plain(node.id);
|
||||
print.plain(node.typeParameters);
|
||||
if (node.extends.length) {
|
||||
this.push(" extends ");
|
||||
print.join(node.extends, { separator: ", " });
|
||||
}
|
||||
this.space();
|
||||
print(node.body);
|
||||
print.plain(node.body);
|
||||
}
|
||||
|
||||
export function InterfaceDeclaration(node, print) {
|
||||
@@ -103,9 +103,13 @@ export function IntersectionTypeAnnotation(node, print) {
|
||||
print.join(node.types, { separator: " & " });
|
||||
}
|
||||
|
||||
export function MixedTypeAnnotation() {
|
||||
this.push("mixed");
|
||||
}
|
||||
|
||||
export function NullableTypeAnnotation(node, print) {
|
||||
this.push("?");
|
||||
print(node.typeAnnotation);
|
||||
print.plain(node.typeAnnotation);
|
||||
}
|
||||
|
||||
export function NumberTypeAnnotation() {
|
||||
@@ -128,17 +132,17 @@ export function TupleTypeAnnotation(node, print) {
|
||||
|
||||
export function TypeofTypeAnnotation(node, print) {
|
||||
this.push("typeof ");
|
||||
print(node.argument);
|
||||
print.plain(node.argument);
|
||||
}
|
||||
|
||||
export function TypeAlias(node, print) {
|
||||
this.push("type ");
|
||||
print(node.id);
|
||||
print(node.typeParameters);
|
||||
print.plain(node.id);
|
||||
print.plain(node.typeParameters);
|
||||
this.space();
|
||||
this.push("=");
|
||||
this.space();
|
||||
print(node.right);
|
||||
print.plain(node.right);
|
||||
this.semicolon();
|
||||
}
|
||||
|
||||
@@ -146,7 +150,7 @@ export function TypeAnnotation(node, print) {
|
||||
this.push(":");
|
||||
this.space();
|
||||
if (node.optional) this.push("?");
|
||||
print(node.typeAnnotation);
|
||||
print.plain(node.typeAnnotation);
|
||||
}
|
||||
|
||||
export function TypeParameterInstantiation(node, print) {
|
||||
@@ -183,37 +187,37 @@ export function ObjectTypeAnnotation(node, print) {
|
||||
|
||||
export function ObjectTypeCallProperty(node, print) {
|
||||
if (node.static) this.push("static ");
|
||||
print(node.value);
|
||||
print.plain(node.value);
|
||||
}
|
||||
|
||||
export function ObjectTypeIndexer(node, print) {
|
||||
if (node.static) this.push("static ");
|
||||
this.push("[");
|
||||
print(node.id);
|
||||
print.plain(node.id);
|
||||
this.push(":");
|
||||
this.space();
|
||||
print(node.key);
|
||||
print.plain(node.key);
|
||||
this.push("]");
|
||||
this.push(":");
|
||||
this.space();
|
||||
print(node.value);
|
||||
print.plain(node.value);
|
||||
}
|
||||
|
||||
export function ObjectTypeProperty(node, print) {
|
||||
if (node.static) this.push("static ");
|
||||
print(node.key);
|
||||
print.plain(node.key);
|
||||
if (node.optional) this.push("?");
|
||||
if (!t.isFunctionTypeAnnotation(node.value)) {
|
||||
this.push(":");
|
||||
this.space();
|
||||
}
|
||||
print(node.value);
|
||||
print.plain(node.value);
|
||||
}
|
||||
|
||||
export function QualifiedTypeIdentifier(node, print) {
|
||||
print(node.qualification);
|
||||
print.plain(node.qualification);
|
||||
this.push(".");
|
||||
print(node.id);
|
||||
print.plain(node.id);
|
||||
}
|
||||
|
||||
export function UnionTypeAnnotation(node, print) {
|
||||
@@ -222,8 +226,8 @@ export function UnionTypeAnnotation(node, print) {
|
||||
|
||||
export function TypeCastExpression(node, print) {
|
||||
this.push("(");
|
||||
print(node.expression);
|
||||
print(node.typeAnnotation);
|
||||
print.plain(node.expression);
|
||||
print.plain(node.typeAnnotation);
|
||||
this.push(")");
|
||||
}
|
||||
|
||||
|
||||
@@ -1,11 +1,10 @@
|
||||
import each from "lodash/collection/each";
|
||||
import * as t from "../../types";
|
||||
|
||||
export function JSXAttribute(node, print) {
|
||||
print(node.name);
|
||||
print.plain(node.name);
|
||||
if (node.value) {
|
||||
this.push("=");
|
||||
print(node.value);
|
||||
print.plain(node.value);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,50 +13,50 @@ export function JSXIdentifier(node) {
|
||||
}
|
||||
|
||||
export function JSXNamespacedName(node, print) {
|
||||
print(node.namespace);
|
||||
print.plain(node.namespace);
|
||||
this.push(":");
|
||||
print(node.name);
|
||||
print.plain(node.name);
|
||||
}
|
||||
|
||||
export function JSXMemberExpression(node, print) {
|
||||
print(node.object);
|
||||
print.plain(node.object);
|
||||
this.push(".");
|
||||
print(node.property);
|
||||
print.plain(node.property);
|
||||
}
|
||||
|
||||
export function JSXSpreadAttribute(node, print) {
|
||||
this.push("{...");
|
||||
print(node.argument);
|
||||
print.plain(node.argument);
|
||||
this.push("}");
|
||||
}
|
||||
|
||||
export function JSXExpressionContainer(node, print) {
|
||||
this.push("{");
|
||||
print(node.expression);
|
||||
print.plain(node.expression);
|
||||
this.push("}");
|
||||
}
|
||||
|
||||
export function JSXElement(node, print) {
|
||||
var open = node.openingElement;
|
||||
print(open);
|
||||
print.plain(open);
|
||||
if (open.selfClosing) return;
|
||||
|
||||
this.indent();
|
||||
each(node.children, (child) => {
|
||||
for (var child of (node.children: Array)) {
|
||||
if (t.isLiteral(child)) {
|
||||
this.push(child.value);
|
||||
this.push(child.value, true);
|
||||
} else {
|
||||
print(child);
|
||||
print.plain(child);
|
||||
}
|
||||
});
|
||||
}
|
||||
this.dedent();
|
||||
|
||||
print(node.closingElement);
|
||||
print.plain(node.closingElement);
|
||||
}
|
||||
|
||||
export function JSXOpeningElement(node, print) {
|
||||
this.push("<");
|
||||
print(node.name);
|
||||
print.plain(node.name);
|
||||
if (node.attributes.length > 0) {
|
||||
this.push(" ");
|
||||
print.join(node.attributes, { separator: " " });
|
||||
@@ -67,7 +66,7 @@ export function JSXOpeningElement(node, print) {
|
||||
|
||||
export function JSXClosingElement(node, print) {
|
||||
this.push("</");
|
||||
print(node.name);
|
||||
print.plain(node.name);
|
||||
this.push(">");
|
||||
}
|
||||
|
||||
|
||||
@@ -1,18 +1,18 @@
|
||||
import * as t from "../../types";
|
||||
|
||||
export function _params(node, print) {
|
||||
print(node.typeParameters);
|
||||
print.plain(node.typeParameters);
|
||||
this.push("(");
|
||||
print.list(node.params, {
|
||||
iterator: (node) =>{
|
||||
if (node.optional) this.push("?");
|
||||
print(node.typeAnnotation);
|
||||
print.plain(node.typeAnnotation);
|
||||
}
|
||||
});
|
||||
this.push(")");
|
||||
|
||||
if (node.returnType) {
|
||||
print(node.returnType);
|
||||
print.plain(node.returnType);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -35,15 +35,15 @@ export function _method(node, print) {
|
||||
|
||||
if (node.computed) {
|
||||
this.push("[");
|
||||
print(key);
|
||||
print.plain(key);
|
||||
this.push("]");
|
||||
} else {
|
||||
print(key);
|
||||
print.plain(key);
|
||||
}
|
||||
|
||||
this._params(value, print);
|
||||
this.push(" ");
|
||||
print(value.body);
|
||||
print.plain(value.body);
|
||||
}
|
||||
|
||||
export function FunctionExpression(node, print) {
|
||||
@@ -53,14 +53,14 @@ export function FunctionExpression(node, print) {
|
||||
|
||||
if (node.id) {
|
||||
this.push(" ");
|
||||
print(node.id);
|
||||
print.plain(node.id);
|
||||
} else {
|
||||
this.space();
|
||||
}
|
||||
|
||||
this._params(node, print);
|
||||
this.space();
|
||||
print(node.body);
|
||||
print.plain(node.body);
|
||||
}
|
||||
|
||||
export { FunctionExpression as FunctionDeclaration };
|
||||
@@ -69,7 +69,7 @@ export function ArrowFunctionExpression(node, print) {
|
||||
if (node.async) this.push("async ");
|
||||
|
||||
if (node.params.length === 1 && t.isIdentifier(node.params[0])) {
|
||||
print(node.params[0]);
|
||||
print.plain(node.params[0]);
|
||||
} else {
|
||||
this._params(node, print);
|
||||
}
|
||||
@@ -82,7 +82,7 @@ export function ArrowFunctionExpression(node, print) {
|
||||
this.push("(");
|
||||
}
|
||||
|
||||
print(node.body);
|
||||
print.plain(node.body);
|
||||
|
||||
if (bodyNeedsParens) {
|
||||
this.push(")");
|
||||
|
||||
@@ -1,43 +1,42 @@
|
||||
import each from "lodash/collection/each";
|
||||
import * as t from "../../types";
|
||||
|
||||
export function ImportSpecifier(node, print) {
|
||||
print(node.imported);
|
||||
if (node.local && node.local !== node.imported) {
|
||||
print.plain(node.imported);
|
||||
if (node.local && node.local.name !== node.imported.name) {
|
||||
this.push(" as ");
|
||||
print(node.local);
|
||||
print.plain(node.local);
|
||||
}
|
||||
}
|
||||
|
||||
export function ImportDefaultSpecifier(node, print) {
|
||||
print(node.local);
|
||||
print.plain(node.local);
|
||||
}
|
||||
|
||||
export function ExportDefaultSpecifier(node, print) {
|
||||
print(node.exported);
|
||||
print.plain(node.exported);
|
||||
}
|
||||
|
||||
export function ExportSpecifier(node, print) {
|
||||
print(node.local);
|
||||
if (node.exported && node.local !== node.exported) {
|
||||
print.plain(node.local);
|
||||
if (node.exported && node.local.name !== node.exported.name) {
|
||||
this.push(" as ");
|
||||
print(node.exported);
|
||||
print.plain(node.exported);
|
||||
}
|
||||
}
|
||||
|
||||
export function ExportNamespaceSpecifier(node, print) {
|
||||
this.push("* as ");
|
||||
print(node.exported);
|
||||
print.plain(node.exported);
|
||||
}
|
||||
|
||||
export function ExportAllDeclaration(node, print) {
|
||||
this.push("export *");
|
||||
if (node.exported) {
|
||||
this.push(" as ");
|
||||
print(node.exported);
|
||||
print.plain(node.exported);
|
||||
}
|
||||
this.push(" from ");
|
||||
print(node.source);
|
||||
print.plain(node.source);
|
||||
this.semicolon();
|
||||
}
|
||||
|
||||
@@ -56,14 +55,14 @@ function ExportDeclaration(node, print) {
|
||||
|
||||
if (node.declaration) {
|
||||
var declar = node.declaration;
|
||||
print(declar);
|
||||
print.plain(declar);
|
||||
if (t.isStatement(declar) || t.isFunction(declar) || t.isClass(declar)) return;
|
||||
} else {
|
||||
var first = specifiers[0];
|
||||
var hasSpecial = false;
|
||||
if (t.isExportDefaultSpecifier(first) || t.isExportNamespaceSpecifier(first)) {
|
||||
hasSpecial = true;
|
||||
print(specifiers.shift());
|
||||
print.plain(specifiers.shift());
|
||||
if (specifiers.length) {
|
||||
this.push(", ");
|
||||
}
|
||||
@@ -81,7 +80,7 @@ function ExportDeclaration(node, print) {
|
||||
|
||||
if (node.source) {
|
||||
this.push(" from ");
|
||||
print(node.source);
|
||||
print.plain(node.source);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -99,7 +98,7 @@ export function ImportDeclaration(node, print) {
|
||||
if (specfiers && specfiers.length) {
|
||||
var first = node.specifiers[0];
|
||||
if (t.isImportDefaultSpecifier(first) || t.isImportNamespaceSpecifier(first)) {
|
||||
print(node.specifiers.shift());
|
||||
print.plain(node.specifiers.shift());
|
||||
if (node.specifiers.length) {
|
||||
this.push(", ");
|
||||
}
|
||||
@@ -107,20 +106,20 @@ export function ImportDeclaration(node, print) {
|
||||
|
||||
if (node.specifiers.length) {
|
||||
this.push("{");
|
||||
this.space()
|
||||
this.space();
|
||||
print.join(node.specifiers, { separator: ", " });
|
||||
this.space()
|
||||
this.space();
|
||||
this.push("}");
|
||||
}
|
||||
|
||||
this.push(" from ");
|
||||
}
|
||||
|
||||
print(node.source);
|
||||
print.plain(node.source);
|
||||
this.semicolon();
|
||||
}
|
||||
|
||||
export function ImportNamespaceSpecifier(node, print) {
|
||||
this.push("* as ");
|
||||
print(node.local);
|
||||
print.plain(node.local);
|
||||
}
|
||||
|
||||
@@ -4,7 +4,7 @@ import * as t from "../../types";
|
||||
export function WithStatement(node, print) {
|
||||
this.keyword("with");
|
||||
this.push("(");
|
||||
print(node.object);
|
||||
print.plain(node.object);
|
||||
this.push(")");
|
||||
print.block(node.body);
|
||||
}
|
||||
@@ -12,7 +12,7 @@ export function WithStatement(node, print) {
|
||||
export function IfStatement(node, print) {
|
||||
this.keyword("if");
|
||||
this.push("(");
|
||||
print(node.test);
|
||||
print.plain(node.test);
|
||||
this.push(")");
|
||||
this.space();
|
||||
|
||||
@@ -29,18 +29,18 @@ export function ForStatement(node, print) {
|
||||
this.keyword("for");
|
||||
this.push("(");
|
||||
|
||||
print(node.init);
|
||||
print.plain(node.init);
|
||||
this.push(";");
|
||||
|
||||
if (node.test) {
|
||||
this.push(" ");
|
||||
print(node.test);
|
||||
this.space();
|
||||
print.plain(node.test);
|
||||
}
|
||||
this.push(";");
|
||||
|
||||
if (node.update) {
|
||||
this.push(" ");
|
||||
print(node.update);
|
||||
this.space();
|
||||
print.plain(node.update);
|
||||
}
|
||||
|
||||
this.push(")");
|
||||
@@ -50,7 +50,7 @@ export function ForStatement(node, print) {
|
||||
export function WhileStatement(node, print) {
|
||||
this.keyword("while");
|
||||
this.push("(");
|
||||
print(node.test);
|
||||
print.plain(node.test);
|
||||
this.push(")");
|
||||
print.block(node.body);
|
||||
}
|
||||
@@ -59,9 +59,9 @@ var buildForXStatement = function (op) {
|
||||
return function (node, print) {
|
||||
this.keyword("for");
|
||||
this.push("(");
|
||||
print(node.left);
|
||||
print.plain(node.left);
|
||||
this.push(` ${op} `);
|
||||
print(node.right);
|
||||
print.plain(node.right);
|
||||
this.push(")");
|
||||
print.block(node.body);
|
||||
};
|
||||
@@ -71,12 +71,12 @@ export var ForInStatement = buildForXStatement("in");
|
||||
export var ForOfStatement = buildForXStatement("of");
|
||||
|
||||
export function DoWhileStatement(node, print) {
|
||||
this.keyword("do");
|
||||
print(node.body);
|
||||
this.push("do ");
|
||||
print.plain(node.body);
|
||||
this.space();
|
||||
this.keyword("while");
|
||||
this.push("(");
|
||||
print(node.test);
|
||||
print.plain(node.test);
|
||||
this.push(");");
|
||||
}
|
||||
|
||||
@@ -87,7 +87,7 @@ var buildLabelStatement = function (prefix, key) {
|
||||
var label = node[key || "label"];
|
||||
if (label) {
|
||||
this.push(" ");
|
||||
print(label);
|
||||
print.plain(label);
|
||||
}
|
||||
|
||||
this.semicolon();
|
||||
@@ -99,50 +99,50 @@ export var ReturnStatement = buildLabelStatement("return", "argument");
|
||||
export var BreakStatement = buildLabelStatement("break");
|
||||
|
||||
export function LabeledStatement(node, print) {
|
||||
print(node.label);
|
||||
print.plain(node.label);
|
||||
this.push(": ");
|
||||
print(node.body);
|
||||
print.plain(node.body);
|
||||
}
|
||||
|
||||
export function TryStatement(node, print) {
|
||||
this.keyword("try");
|
||||
print(node.block);
|
||||
print.plain(node.block);
|
||||
this.space();
|
||||
|
||||
// Esprima bug puts the catch clause in a `handlers` array.
|
||||
// see https://code.google.com/p/esprima/issues/detail?id=433
|
||||
// We run into this from regenerator generated ast.
|
||||
if (node.handlers) {
|
||||
print(node.handlers[0]);
|
||||
print.plain(node.handlers[0]);
|
||||
} else {
|
||||
print(node.handler);
|
||||
print.plain(node.handler);
|
||||
}
|
||||
|
||||
if (node.finalizer) {
|
||||
this.space();
|
||||
this.push("finally ");
|
||||
print(node.finalizer);
|
||||
print.plain(node.finalizer);
|
||||
}
|
||||
}
|
||||
|
||||
export function CatchClause(node, print) {
|
||||
this.keyword("catch");
|
||||
this.push("(");
|
||||
print(node.param);
|
||||
print.plain(node.param);
|
||||
this.push(") ");
|
||||
print(node.body);
|
||||
print.plain(node.body);
|
||||
}
|
||||
|
||||
export function ThrowStatement(node, print) {
|
||||
this.push("throw ");
|
||||
print(node.argument);
|
||||
print.plain(node.argument);
|
||||
this.semicolon();
|
||||
}
|
||||
|
||||
export function SwitchStatement(node, print) {
|
||||
this.keyword("switch");
|
||||
this.push("(");
|
||||
print(node.discriminant);
|
||||
print.plain(node.discriminant);
|
||||
this.push(")");
|
||||
this.space();
|
||||
this.push("{");
|
||||
@@ -160,7 +160,7 @@ export function SwitchStatement(node, print) {
|
||||
export function SwitchCase(node, print) {
|
||||
if (node.test) {
|
||||
this.push("case ");
|
||||
print(node.test);
|
||||
print.plain(node.test);
|
||||
this.push(":");
|
||||
} else {
|
||||
this.push("default:");
|
||||
@@ -182,8 +182,8 @@ export function VariableDeclaration(node, print, parent) {
|
||||
var hasInits = false;
|
||||
// don't add whitespace to loop heads
|
||||
if (!t.isFor(parent)) {
|
||||
for (var i = 0; i < node.declarations.length; i++) {
|
||||
if (node.declarations[i].init) {
|
||||
for (var declar of (node.declarations: Array)) {
|
||||
if (declar.init) {
|
||||
// has an init so let's split it up over multiple lines
|
||||
hasInits = true;
|
||||
}
|
||||
@@ -191,7 +191,7 @@ export function VariableDeclaration(node, print, parent) {
|
||||
}
|
||||
|
||||
var sep = ",";
|
||||
if (!this.format.compact && hasInits) {
|
||||
if (!this.format.compact && !this.format.concise && hasInits && !this.format.retainLines) {
|
||||
sep += `\n${repeating(" ", node.kind.length + 1)}`;
|
||||
} else {
|
||||
sep += " ";
|
||||
@@ -207,12 +207,12 @@ export function VariableDeclaration(node, print, parent) {
|
||||
}
|
||||
|
||||
export function VariableDeclarator(node, print) {
|
||||
print(node.id);
|
||||
print(node.id.typeAnnotation);
|
||||
print.plain(node.id);
|
||||
print.plain(node.id.typeAnnotation);
|
||||
if (node.init) {
|
||||
this.space();
|
||||
this.push("=");
|
||||
this.space();
|
||||
print(node.init);
|
||||
print.plain(node.init);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
import each from "lodash/collection/each";
|
||||
|
||||
export function TaggedTemplateExpression(node, print) {
|
||||
print(node.tag);
|
||||
print(node.quasi);
|
||||
print.plain(node.tag);
|
||||
print.plain(node.quasi);
|
||||
}
|
||||
|
||||
export function TemplateElement(node) {
|
||||
@@ -15,15 +13,15 @@ export function TemplateLiteral(node, print) {
|
||||
var quasis = node.quasis;
|
||||
var len = quasis.length;
|
||||
|
||||
each(quasis, (quasi, i) => {
|
||||
print(quasi);
|
||||
for (var i = 0; i < len; i++) {
|
||||
print.plain(quasis[i]);
|
||||
|
||||
if (i + 1 < len) {
|
||||
this.push("${ ");
|
||||
print(node.expressions[i]);
|
||||
print.plain(node.expressions[i]);
|
||||
this.push(" }");
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
this._push("`");
|
||||
}
|
||||
|
||||
@@ -1,4 +1,7 @@
|
||||
import each from "lodash/collection/each";
|
||||
/* eslint quotes: 0 */
|
||||
|
||||
import isInteger from "is-integer";
|
||||
import * as t from "../../types";
|
||||
|
||||
export function Identifier(node) {
|
||||
this.push(node.name);
|
||||
@@ -6,7 +9,7 @@ export function Identifier(node) {
|
||||
|
||||
export function RestElement(node, print) {
|
||||
this.push("...");
|
||||
print(node.argument);
|
||||
print.plain(node.argument);
|
||||
}
|
||||
|
||||
export { RestElement as SpreadElement, RestElement as SpreadProperty };
|
||||
@@ -35,16 +38,29 @@ export function Property(node, print) {
|
||||
} else {
|
||||
if (node.computed) {
|
||||
this.push("[");
|
||||
print(node.key);
|
||||
print.plain(node.key);
|
||||
this.push("]");
|
||||
} else {
|
||||
print(node.key);
|
||||
if (node.shorthand) return;
|
||||
// print `({ foo: foo = 5 } = {})` as `({ foo = 5 } = {});`
|
||||
if (t.isAssignmentPattern(node.value) && t.isIdentifier(node.key) && node.key.name === node.value.left.name) {
|
||||
print.plain(node.value);
|
||||
return;
|
||||
}
|
||||
|
||||
print.plain(node.key);
|
||||
|
||||
// shorthand!
|
||||
if (node.shorthand &&
|
||||
(t.isIdentifier(node.key) &&
|
||||
t.isIdentifier(node.value) &&
|
||||
node.key.name === node.value.name)) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
this.push(":");
|
||||
this.space();
|
||||
print(node.value);
|
||||
print.plain(node.value);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -54,7 +70,8 @@ export function ArrayExpression(node, print) {
|
||||
|
||||
this.push("[");
|
||||
|
||||
each(elems, (elem, i) => {
|
||||
for (var i = 0; i < elems.length; i++) {
|
||||
var elem = elems[i];
|
||||
if (!elem) {
|
||||
// If the array expression ends with a hole, that hole
|
||||
// will be ignored by the interpreter, but if it ends with
|
||||
@@ -64,24 +81,39 @@ export function ArrayExpression(node, print) {
|
||||
this.push(",");
|
||||
} else {
|
||||
if (i > 0) this.push(" ");
|
||||
print(elem);
|
||||
print.plain(elem);
|
||||
if (i < len - 1) this.push(",");
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
this.push("]");
|
||||
}
|
||||
|
||||
export { ArrayExpression as ArrayPattern };
|
||||
|
||||
export function Literal(node) {
|
||||
const SCIENTIFIC_NOTATION = /e/i;
|
||||
|
||||
export function Literal(node, print, parent) {
|
||||
var val = node.value;
|
||||
var type = typeof val;
|
||||
|
||||
if (type === "string") {
|
||||
this._stringLiteral(val);
|
||||
} else if (type === "number") {
|
||||
this.push(val + "");
|
||||
// check to see if this is the same number as the raw one in the original source as asm.js uses
|
||||
// numbers in the form 5.0 for type hinting
|
||||
var raw = node.raw;
|
||||
if (val === +raw && raw[raw.length - 1] !== "." && !/^0[bo]/i.test(raw)) {
|
||||
val = raw;
|
||||
}
|
||||
|
||||
val = val + "";
|
||||
|
||||
if (isInteger(+val) && t.isMemberExpression(parent, { object: node }) && !SCIENTIFIC_NOTATION.test(val)) {
|
||||
val += ".";
|
||||
}
|
||||
|
||||
this.push(val);
|
||||
} else if (type === "boolean") {
|
||||
this.push(val ? "true" : "false");
|
||||
} else if (node.regex) {
|
||||
@@ -100,9 +132,16 @@ export function _stringLiteral(val) {
|
||||
});
|
||||
|
||||
if (this.format.quotes === "single") {
|
||||
// remove double quotes
|
||||
val = val.slice(1, -1);
|
||||
|
||||
// unescape double quotes
|
||||
val = val.replace(/\\"/g, '"');
|
||||
|
||||
// escape single quotes
|
||||
val = val.replace(/'/g, "\\'");
|
||||
|
||||
// add single quotes
|
||||
val = `'${val}'`;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import detectIndent from "detect-indent";
|
||||
import Whitespace from "./whitespace";
|
||||
import NodePrinter from "./node/printer";
|
||||
import repeating from "repeating";
|
||||
import SourceMap from "./source-map";
|
||||
import Position from "./position";
|
||||
@@ -12,7 +13,7 @@ import * as t from "../types";
|
||||
|
||||
class CodeGenerator {
|
||||
constructor(ast, opts, code) {
|
||||
opts ||= {};
|
||||
opts = opts || {};
|
||||
|
||||
this.comments = ast.comments || [];
|
||||
this.tokens = ast.tokens || [];
|
||||
@@ -20,7 +21,7 @@ class CodeGenerator {
|
||||
this.opts = opts;
|
||||
this.ast = ast;
|
||||
|
||||
this.whitespace = new Whitespace(this.tokens, this.comments, this.format);
|
||||
this.whitespace = new Whitespace(this.tokens);
|
||||
this.position = new Position;
|
||||
this.map = new SourceMap(this.position, opts, code);
|
||||
this.buffer = new Buffer(this.position, this.format);
|
||||
@@ -34,9 +35,10 @@ class CodeGenerator {
|
||||
}
|
||||
|
||||
var format = {
|
||||
retainLines: opts.retainLines,
|
||||
comments: opts.comments == null || opts.comments,
|
||||
compact: opts.compact,
|
||||
quotes: CodeGenerator.findCommonStringDelimeter(code, tokens),
|
||||
quotes: CodeGenerator.findCommonStringDelimiter(code, tokens),
|
||||
indent: {
|
||||
adjustMultilineComment: true,
|
||||
style: style,
|
||||
@@ -48,14 +50,14 @@ class CodeGenerator {
|
||||
format.compact = code.length > 100000; // 100KB
|
||||
|
||||
if (format.compact) {
|
||||
console.error(messages.get("codeGeneratorDeopt", opts.filename, "100KB"));
|
||||
console.error("[BABEL] " + messages.get("codeGeneratorDeopt", opts.filename, "100KB"));
|
||||
}
|
||||
}
|
||||
|
||||
return format;
|
||||
}
|
||||
|
||||
static findCommonStringDelimeter(code, tokens) {
|
||||
static findCommonStringDelimiter(code, tokens) {
|
||||
var occurences = {
|
||||
single: 0,
|
||||
double: 0
|
||||
@@ -66,7 +68,6 @@ class CodeGenerator {
|
||||
for (var i = 0; i < tokens.length; i++) {
|
||||
var token = tokens[i];
|
||||
if (token.type.label !== "string") continue;
|
||||
if (checked >= 3) continue;
|
||||
|
||||
var raw = code.slice(token.start, token.end);
|
||||
if (raw[0] === "'") {
|
||||
@@ -76,6 +77,7 @@ class CodeGenerator {
|
||||
}
|
||||
|
||||
checked++;
|
||||
if (checked >= 3) break;
|
||||
}
|
||||
|
||||
if (occurences.single > occurences.double) {
|
||||
@@ -104,11 +106,13 @@ class CodeGenerator {
|
||||
|
||||
this.print(ast);
|
||||
|
||||
var comments = [];
|
||||
each(ast.comments, function (comment) {
|
||||
if (!comment._displayed) comments.push(comment);
|
||||
});
|
||||
this._printComments(comments);
|
||||
if (ast.comments) {
|
||||
var comments = [];
|
||||
for (var comment of (ast.comments: Array)) {
|
||||
if (!comment._displayed) comments.push(comment);
|
||||
}
|
||||
this._printComments(comments);
|
||||
}
|
||||
|
||||
return {
|
||||
map: this.map.get(),
|
||||
@@ -117,33 +121,54 @@ class CodeGenerator {
|
||||
}
|
||||
|
||||
buildPrint(parent) {
|
||||
var print = (node, opts) => {
|
||||
return this.print(node, parent, opts);
|
||||
};
|
||||
return new NodePrinter(this, parent);
|
||||
}
|
||||
|
||||
print.sequence = (nodes, opts = {}) => {
|
||||
opts.statement = true;
|
||||
return this.printJoin(print, nodes, opts);
|
||||
};
|
||||
catchUp(node, parent, leftParenPrinted) {
|
||||
// catch up to this nodes newline if we're behind
|
||||
if (node.loc && this.format.retainLines && this.buffer.buf) {
|
||||
var needsParens = false;
|
||||
if (!leftParenPrinted && parent &&
|
||||
this.position.line < node.loc.start.line && t.isTerminatorless(parent)) {
|
||||
needsParens = true;
|
||||
this._push("(");
|
||||
}
|
||||
while (this.position.line < node.loc.start.line) {
|
||||
this._push("\n");
|
||||
}
|
||||
return needsParens;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
print.join = (nodes, opts) => {
|
||||
return this.printJoin(print, nodes, opts);
|
||||
};
|
||||
_printNewline(leading, node, parent, opts) {
|
||||
if (!opts.statement && !n.isUserWhitespacable(node, parent)) {
|
||||
return;
|
||||
}
|
||||
|
||||
print.list = function (items, opts = {}) {
|
||||
if (opts.separator == null) opts.separator = ", ";
|
||||
print.join(items, opts);
|
||||
};
|
||||
var lines = 0;
|
||||
|
||||
print.block = (node) => {
|
||||
return this.printBlock(print, node);
|
||||
};
|
||||
if (node.start != null && !node._ignoreUserWhitespace) {
|
||||
// user node
|
||||
if (leading) {
|
||||
lines = this.whitespace.getNewlinesBefore(node);
|
||||
} else {
|
||||
lines = this.whitespace.getNewlinesAfter(node);
|
||||
}
|
||||
} else {
|
||||
// generated node
|
||||
if (!leading) lines++; // always include at least a single line after
|
||||
if (opts.addNewlines) lines += opts.addNewlines(leading, node) || 0;
|
||||
|
||||
print.indentOnComments = (node) => {
|
||||
return this.printAndIndentOnComments(print, node);
|
||||
};
|
||||
var needs = n.needsWhitespaceAfter;
|
||||
if (leading) needs = n.needsWhitespaceBefore;
|
||||
if (needs(node, parent)) lines++;
|
||||
|
||||
return print;
|
||||
// generated nodes can't add starting file whitespace
|
||||
if (!this.buffer.buf) lines = 0;
|
||||
}
|
||||
|
||||
this.newline(lines);
|
||||
}
|
||||
|
||||
print(node, parent, opts = {}) {
|
||||
@@ -158,36 +183,6 @@ class CodeGenerator {
|
||||
this.format.concise = true;
|
||||
}
|
||||
|
||||
var newline = (leading) => {
|
||||
if (!opts.statement && !n.isUserWhitespacable(node, parent)) {
|
||||
return;
|
||||
}
|
||||
|
||||
var lines = 0;
|
||||
|
||||
if (node.start != null && !node._ignoreUserWhitespace) {
|
||||
// user node
|
||||
if (leading) {
|
||||
lines = this.whitespace.getNewlinesBefore(node);
|
||||
} else {
|
||||
lines = this.whitespace.getNewlinesAfter(node);
|
||||
}
|
||||
} else {
|
||||
// generated node
|
||||
if (!leading) lines++; // always include at least a single line after
|
||||
if (opts.addNewlines) lines += opts.addNewlines(leading, node) || 0;
|
||||
|
||||
var needs = n.needsWhitespaceAfter;
|
||||
if (leading) needs = n.needsWhitespaceBefore;
|
||||
if (needs(node, parent)) lines++;
|
||||
|
||||
// generated nodes can't add starting file whitespace
|
||||
if (!this.buffer.buf) lines = 0;
|
||||
}
|
||||
|
||||
this.newline(lines);
|
||||
};
|
||||
|
||||
if (this[node.type]) {
|
||||
var needsNoLineTermParens = n.needsParensNoLineTerminator(node, parent);
|
||||
var needsParens = needsNoLineTermParens || n.needsParens(node, parent);
|
||||
@@ -197,7 +192,9 @@ class CodeGenerator {
|
||||
|
||||
this.printLeadingComments(node, parent);
|
||||
|
||||
newline(true);
|
||||
var needsParensFromCatchup = this.catchUp(node, parent, needsParens);
|
||||
|
||||
this._printNewline(true, node, parent, opts);
|
||||
|
||||
if (opts.before) opts.before();
|
||||
this.map.mark(node, "start");
|
||||
@@ -208,19 +205,19 @@ class CodeGenerator {
|
||||
this.newline();
|
||||
this.dedent();
|
||||
}
|
||||
if (needsParens) this.push(")");
|
||||
if (needsParens || needsParensFromCatchup) this.push(")");
|
||||
|
||||
this.map.mark(node, "end");
|
||||
if (opts.after) opts.after();
|
||||
|
||||
newline(false);
|
||||
this.format.concise = oldConcise;
|
||||
|
||||
this._printNewline(false, node, parent, opts);
|
||||
|
||||
this.printTrailingComments(node, parent);
|
||||
} else {
|
||||
throw new ReferenceError(`unknown node of type ${JSON.stringify(node.type)} with constructor ${JSON.stringify(node && node.constructor.name)}`);
|
||||
}
|
||||
|
||||
this.format.concise = oldConcise;
|
||||
}
|
||||
|
||||
printJoin(print, nodes, opts = {}) {
|
||||
@@ -230,21 +227,24 @@ class CodeGenerator {
|
||||
|
||||
if (opts.indent) this.indent();
|
||||
|
||||
each(nodes, (node, i) => {
|
||||
print(node, {
|
||||
statement: opts.statement,
|
||||
addNewlines: opts.addNewlines,
|
||||
after: () => {
|
||||
if (opts.iterator) {
|
||||
opts.iterator(node, i);
|
||||
}
|
||||
|
||||
if (opts.separator && i < len - 1) {
|
||||
this.push(opts.separator);
|
||||
}
|
||||
var printOpts = {
|
||||
statement: opts.statement,
|
||||
addNewlines: opts.addNewlines,
|
||||
after: () => {
|
||||
if (opts.iterator) {
|
||||
opts.iterator(node, i);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
if (opts.separator && i < len - 1) {
|
||||
this.push(opts.separator);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
for (var i = 0; i < nodes.length; i++) {
|
||||
var node = nodes[i];
|
||||
print.plain(node, printOpts);
|
||||
}
|
||||
|
||||
if (opts.indent) this.dedent();
|
||||
}
|
||||
@@ -252,7 +252,7 @@ class CodeGenerator {
|
||||
printAndIndentOnComments(print, node) {
|
||||
var indent = !!node.leadingComments;
|
||||
if (indent) this.indent();
|
||||
print(node);
|
||||
print.plain(node);
|
||||
if (indent) this.dedent();
|
||||
}
|
||||
|
||||
@@ -261,13 +261,13 @@ class CodeGenerator {
|
||||
this.semicolon();
|
||||
} else {
|
||||
this.push(" ");
|
||||
print(node);
|
||||
print.plain(node);
|
||||
}
|
||||
}
|
||||
|
||||
generateComment(comment) {
|
||||
var val = comment.value;
|
||||
if (comment.type === "Line") {
|
||||
if (comment.type === "CommentLine") {
|
||||
val = `//${val}`;
|
||||
} else {
|
||||
val = `/*${val}*/`;
|
||||
@@ -295,9 +295,9 @@ class CodeGenerator {
|
||||
nodes.push(node.argument);
|
||||
}
|
||||
|
||||
each(nodes, (node) => {
|
||||
for (let node of (nodes: Array)) {
|
||||
comments = comments.concat(this._getComments(key, node));
|
||||
});
|
||||
}
|
||||
|
||||
return comments;
|
||||
}
|
||||
@@ -308,26 +308,29 @@ class CodeGenerator {
|
||||
|
||||
_printComments(comments) {
|
||||
if (this.format.compact) return;
|
||||
|
||||
if (!this.format.comments) return;
|
||||
if (!comments || !comments.length) return;
|
||||
|
||||
each(comments, (comment) => {
|
||||
for (var comment of (comments: Array)) {
|
||||
var skip = false;
|
||||
|
||||
// find the original comment in the ast and set it as displayed
|
||||
each(this.ast.comments, function (origComment) {
|
||||
if (origComment.start === comment.start) {
|
||||
// comment has already been output
|
||||
if (origComment._displayed) skip = true;
|
||||
if (this.ast.comments) {
|
||||
// find the original comment in the ast and set it as displayed
|
||||
for (var origComment of (this.ast.comments: Array)) {
|
||||
if (origComment.start === comment.start) {
|
||||
// comment has already been output
|
||||
if (origComment._displayed) skip = true;
|
||||
|
||||
origComment._displayed = true;
|
||||
return false;
|
||||
origComment._displayed = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
if (skip) return;
|
||||
|
||||
this.catchUp(comment);
|
||||
|
||||
// whitespace before
|
||||
this.newline(this.whitespace.getNewlinesBefore(comment));
|
||||
|
||||
@@ -340,9 +343,8 @@ class CodeGenerator {
|
||||
}
|
||||
|
||||
//
|
||||
|
||||
if (comment.type === "Block" && this.format.indent.adjustMultilineComment) {
|
||||
var offset = comment.loc.start.column;
|
||||
if (comment.type === "CommentBlock" && this.format.indent.adjustMultilineComment) {
|
||||
var offset = comment.loc && comment.loc.start.column;
|
||||
if (offset) {
|
||||
var newlineRegex = new RegExp("\\n\\s{1," + offset + "}", "g");
|
||||
val = val.replace(newlineRegex, "\n");
|
||||
@@ -356,13 +358,18 @@ class CodeGenerator {
|
||||
val = this.getIndent() + val;
|
||||
}
|
||||
|
||||
//
|
||||
// force a newline for line comments when retainLines is set in case the next printed node
|
||||
// doesn't catch up
|
||||
if (this.format.retainLines && comment.type === "CommentLine") {
|
||||
val += "\n";
|
||||
}
|
||||
|
||||
//
|
||||
this._push(val);
|
||||
|
||||
// whitespace after
|
||||
this.newline(this.whitespace.getNewlinesAfter(comment));
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -85,16 +85,7 @@ export default class Node {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (t.isYieldExpression(parent) || t.isAwaitExpression(parent)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (t.isContinueStatement(parent) || t.isBreakStatement(parent) ||
|
||||
t.isReturnStatement(parent) || t.isThrowStatement(parent)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
return t.isTerminatorless(parent);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -171,4 +171,10 @@ export function ConditionalExpression(node, parent) {
|
||||
return false;
|
||||
}
|
||||
|
||||
export { ConditionalExpression as AssignmentExpression };
|
||||
export function AssignmentExpression(node) {
|
||||
if (t.isObjectPattern(node.left)) {
|
||||
return true;
|
||||
} else {
|
||||
return ConditionalExpression(...arguments);
|
||||
}
|
||||
}
|
||||
|
||||
32
src/babel/generation/node/printer.js
Normal file
32
src/babel/generation/node/printer.js
Normal file
@@ -0,0 +1,32 @@
|
||||
export default class NodePrinter {
|
||||
constructor(generator, parent) {
|
||||
this.generator = generator;
|
||||
this.parent = parent;
|
||||
}
|
||||
|
||||
plain(node, opts) {
|
||||
return this.generator.print(node, this.parent, opts);
|
||||
}
|
||||
|
||||
sequence(nodes, opts = {}) {
|
||||
opts.statement = true;
|
||||
return this.generator.printJoin(this, nodes, opts);
|
||||
}
|
||||
|
||||
join(nodes, opts) {
|
||||
return this.generator.printJoin(this, nodes, opts);
|
||||
}
|
||||
|
||||
list(items, opts = {}) {
|
||||
if (opts.separator == null) opts.separator = ", ";
|
||||
return this.join(items, opts);
|
||||
}
|
||||
|
||||
block(node) {
|
||||
return this.generator.printBlock(this, node);
|
||||
}
|
||||
|
||||
indentOnComments(node) {
|
||||
return this.generator.printAndIndentOnComments(this, node);
|
||||
}
|
||||
}
|
||||
@@ -16,7 +16,7 @@ function crawl(node, state = {}) {
|
||||
} else if (t.isFunction(node)) {
|
||||
state.hasFunction = true;
|
||||
} else if (t.isIdentifier(node)) {
|
||||
state.hasHelper ||= isHelper(node.callee);
|
||||
state.hasHelper = state.hasHelper || isHelper(node.callee);
|
||||
}
|
||||
|
||||
return state;
|
||||
|
||||
@@ -8,7 +8,7 @@ export default class SourceMap {
|
||||
|
||||
if (opts.sourceMaps) {
|
||||
this.map = new sourceMap.SourceMapGenerator({
|
||||
file: opts.sourceMapName,
|
||||
file: opts.sourceMapTarget,
|
||||
sourceRoot: opts.sourceRoot
|
||||
});
|
||||
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
import sortBy from "lodash/collection/sortBy";
|
||||
|
||||
/**
|
||||
* Returns `i`th number from `base`, continuing from 0 when `max` is reached.
|
||||
* Useful for shifting `for` loop by a fixed number but going over all items.
|
||||
@@ -21,8 +19,8 @@ function getLookupIndex(i, base, max) {
|
||||
}
|
||||
|
||||
export default class Whitespace {
|
||||
constructor(tokens, comments) {
|
||||
this.tokens = sortBy(tokens.concat(comments), "start");
|
||||
constructor(tokens) {
|
||||
this.tokens = tokens;
|
||||
this.used = {};
|
||||
|
||||
// Profiling this code shows that while generator passes over it, indexes
|
||||
@@ -40,12 +38,11 @@ export default class Whitespace {
|
||||
var startToken;
|
||||
var endToken;
|
||||
var tokens = this.tokens;
|
||||
var token;
|
||||
|
||||
for (var j = 0; j < tokens.length; j++) {
|
||||
// optimize for forward traversal by shifting for loop index
|
||||
var i = getLookupIndex(j, this._lastFoundIndex, this.tokens.length);
|
||||
token = tokens[i];
|
||||
var token = tokens[i];
|
||||
|
||||
// this is the token this node starts with
|
||||
if (node.start === token.start) {
|
||||
@@ -64,17 +61,17 @@ export default class Whitespace {
|
||||
var startToken;
|
||||
var endToken;
|
||||
var tokens = this.tokens;
|
||||
var token;
|
||||
|
||||
for (var j = 0; j < tokens.length; j++) {
|
||||
// optimize for forward traversal by shifting for loop index
|
||||
var i = getLookupIndex(j, this._lastFoundIndex, this.tokens.length);
|
||||
token = tokens[i];
|
||||
var token = tokens[i];
|
||||
|
||||
// this is the token this node ends with
|
||||
if (node.end === token.end) {
|
||||
startToken = token;
|
||||
endToken = tokens[i + 1];
|
||||
if (endToken.type.label === ",") endToken = tokens[i + 2];
|
||||
|
||||
this._lastFoundIndex = i;
|
||||
break;
|
||||
@@ -85,7 +82,7 @@ export default class Whitespace {
|
||||
return 1;
|
||||
} else {
|
||||
var lines = this.getNewlinesBetween(startToken, endToken);
|
||||
if (node.type === "Line" && !lines) {
|
||||
if (node.type === "CommentLine" && !lines) {
|
||||
// line comment
|
||||
return 1;
|
||||
} else {
|
||||
|
||||
@@ -79,10 +79,12 @@ export default function (lines: number, lineNumber: number, colNumber: number, o
|
||||
if (params.number !== lineNumber) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (colNumber) {
|
||||
params.line += `\n${params.before}${repeating(" ", params.width)}${params.after}${repeating(" ", colNumber - 1)}^`;
|
||||
}
|
||||
|
||||
params.before = params.before.replace(/^./, ">");
|
||||
}
|
||||
}).join("\n");
|
||||
};
|
||||
}
|
||||
|
||||
17
src/babel/helpers/merge.js
Normal file
17
src/babel/helpers/merge.js
Normal file
@@ -0,0 +1,17 @@
|
||||
import merge from "lodash/object/merge";
|
||||
|
||||
export default function (dest, src) {
|
||||
if (!dest || !src) return;
|
||||
|
||||
return merge(dest, src, function(a, b) {
|
||||
if (Array.isArray(a)) {
|
||||
var c = a.slice(0);
|
||||
for (var v of b) {
|
||||
if (a.indexOf(v) < 0) {
|
||||
c.push(v);
|
||||
}
|
||||
}
|
||||
return c;
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -6,4 +6,4 @@ export default function (ast, comments, tokens) {
|
||||
} else {
|
||||
throw new Error("Not a valid ast?");
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
export default function () {
|
||||
return Object.create(null);
|
||||
};
|
||||
}
|
||||
|
||||
@@ -1,65 +1,52 @@
|
||||
import normalizeAst from "./normalize-ast";
|
||||
import estraverse from "estraverse";
|
||||
import codeFrame from "./code-frame";
|
||||
import * as acorn from "../../acorn";
|
||||
|
||||
export default function (opts, code, callback) {
|
||||
try {
|
||||
var comments = [];
|
||||
var tokens = [];
|
||||
export default function (code, opts = {}) {
|
||||
var commentsAndTokens = [];
|
||||
var comments = [];
|
||||
var tokens = [];
|
||||
|
||||
var parseOpts = {
|
||||
allowImportExportEverywhere: opts.looseModules,
|
||||
allowReturnOutsideFunction: opts.looseModules,
|
||||
ecmaVersion: 6,
|
||||
strictMode: opts.strictMode,
|
||||
sourceType: opts.sourceType,
|
||||
onComment: comments,
|
||||
locations: true,
|
||||
features: opts.features || {},
|
||||
plugins: opts.plugins || {},
|
||||
onToken: tokens,
|
||||
ranges: true
|
||||
var parseOpts = {
|
||||
allowImportExportEverywhere: opts.looseModules,
|
||||
allowReturnOutsideFunction: opts.looseModules,
|
||||
allowHashBang: true,
|
||||
ecmaVersion: 6,
|
||||
strictMode: opts.strictMode,
|
||||
sourceType: opts.sourceType,
|
||||
locations: true,
|
||||
features: opts.features || {},
|
||||
plugins: opts.plugins || {},
|
||||
onToken: tokens,
|
||||
ranges: true
|
||||
};
|
||||
|
||||
parseOpts.onToken = function (token) {
|
||||
tokens.push(token);
|
||||
commentsAndTokens.push(token);
|
||||
};
|
||||
|
||||
parseOpts.onComment = function (block, text, start, end, startLoc, endLoc) {
|
||||
var comment = {
|
||||
type: block ? "CommentBlock" : "CommentLine",
|
||||
value: text,
|
||||
start: start,
|
||||
end: end,
|
||||
loc: new acorn.SourceLocation(this, startLoc, endLoc),
|
||||
range: [start, end]
|
||||
};
|
||||
|
||||
if (opts.nonStandard) {
|
||||
parseOpts.plugins.jsx = true;
|
||||
parseOpts.plugins.flow = true;
|
||||
}
|
||||
commentsAndTokens.push(comment);
|
||||
comments.push(comment);
|
||||
};
|
||||
|
||||
var ast = acorn.parse(code, parseOpts);
|
||||
|
||||
estraverse.attachComments(ast, comments, tokens);
|
||||
|
||||
ast = normalizeAst(ast, comments, tokens);
|
||||
|
||||
if (callback) {
|
||||
return callback(ast);
|
||||
} else {
|
||||
return ast;
|
||||
}
|
||||
} catch (err) {
|
||||
if (!err._babel) {
|
||||
err._babel = true;
|
||||
|
||||
var message = err.message = `${opts.filename}: ${err.message}`;
|
||||
|
||||
var loc = err.loc;
|
||||
if (loc) {
|
||||
err.codeFrame = codeFrame(code, loc.line, loc.column + 1, opts);
|
||||
message += "\n" + err.codeFrame;
|
||||
}
|
||||
|
||||
if (err.stack) {
|
||||
var newStack = err.stack.replace(err.message, message);
|
||||
try {
|
||||
err.stack = newStack;
|
||||
} catch (e) {
|
||||
// `err.stack` may be a readonly property in some environments
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
throw err;
|
||||
if (opts.nonStandard) {
|
||||
parseOpts.plugins.jsx = true;
|
||||
parseOpts.plugins.flow = true;
|
||||
}
|
||||
};
|
||||
|
||||
var ast = acorn.parse(code, parseOpts);
|
||||
estraverse.attachComments(ast, comments, tokens);
|
||||
ast = normalizeAst(ast, comments, commentsAndTokens);
|
||||
return ast;
|
||||
}
|
||||
|
||||
@@ -5,24 +5,39 @@ export const MESSAGES = {
|
||||
JSXNamespacedTags: "Namespace tags are not supported. ReactJSX is not XML.",
|
||||
classesIllegalBareSuper: "Illegal use of bare super",
|
||||
classesIllegalSuperCall: "Direct super call is illegal in non-constructor, use super.$1() instead",
|
||||
classesIllegalConstructorKind: "Illegal kind for constructor method",
|
||||
scopeDuplicateDeclaration: "Duplicate declaration $1",
|
||||
undeclaredVariable: "Reference to undeclared variable $1",
|
||||
undeclaredVariableSuggestion: "Reference to undeclared variable $1 - did you mean $2?",
|
||||
settersInvalidParamLength: "Setters must have exactly one parameter",
|
||||
settersNoRest: "Setters aren't allowed to have a rest",
|
||||
noAssignmentsInForHead: "No assignments allowed in for-in/of head",
|
||||
expectedMemberExpressionOrIdentifier: "Expected type MemeberExpression or Identifier",
|
||||
expectedMemberExpressionOrIdentifier: "Expected type MemberExpression or Identifier",
|
||||
invalidParentForThisNode: "We don't know how to handle this node within the current parent - please open an issue",
|
||||
readOnly: "$1 is read-only",
|
||||
modulesIllegalExportName: "Illegal export $1",
|
||||
unknownForHead: "Unknown node type $1 in ForStatement",
|
||||
didYouMean: "Did you mean $1?",
|
||||
evalInStrictMode: "eval is not allowed in strict mode",
|
||||
codeGeneratorDeopt: "Note: The code generator has deoptimised the styling of $1 as it exceeds the max of $2.",
|
||||
missingTemplatesDirectory: "no templates directory - this is most likely the result of a broken `npm publish`. Please report to https://github.com/babel/babel/issues",
|
||||
unsupportedOutputType: "Unsupported output type $1",
|
||||
illegalMethodName: "Illegal method name $1"
|
||||
illegalMethodName: "Illegal method name $1",
|
||||
lostTrackNodePath: "We lost track of this nodes position, likely because the AST was directly manipulated",
|
||||
|
||||
modulesIllegalExportName: "Illegal export $1",
|
||||
modulesDuplicateDeclarations: "Duplicate module declarations with the same source but in different scopes",
|
||||
|
||||
undeclaredVariable: "Reference to undeclared variable $1",
|
||||
undeclaredVariableType: "Referencing a type alias outside of a type annotation",
|
||||
undeclaredVariableSuggestion: "Reference to undeclared variable $1 - did you mean $2?",
|
||||
|
||||
traverseNeedsParent: "Must pass a scope and parentPath unless traversing a Program/File got a $1 node",
|
||||
traverseVerifyRootFunction: "You passed `traverse()` a function when it expected a visitor object, are you sure you didn't mean `{ enter: Function }`?",
|
||||
traverseVerifyVisitorProperty: "You passed `traverse()` a visitor object with the property $1 that has the invalid property $2",
|
||||
traverseVerifyNodeType: "You gave us a visitor for the node type $1 but it's not a valid type",
|
||||
|
||||
pluginIllegalKind: "Illegal kind $1 for plugin $2",
|
||||
pluginIllegalPosition: "Illegal position $1 for plugin $2",
|
||||
pluginKeyCollision: "The plugin $1 collides with another of the same name",
|
||||
pluginNotTransformer: "The plugin $1 didn't export a Plugin instance",
|
||||
pluginUnknown: "Unknown plugin $1",
|
||||
|
||||
pluginNotFile: "Plugin $1 is resolving to a different Babel version to what is doing the actual transformation..."
|
||||
};
|
||||
|
||||
export function get(key: String, ...args) {
|
||||
|
||||
@@ -17,6 +17,8 @@ var or = types.Type.or;
|
||||
// .build("program")
|
||||
// .field("program", def("Program"));
|
||||
|
||||
def("Noop");
|
||||
|
||||
def("AssignmentPattern")
|
||||
.bases("Pattern")
|
||||
.build("left", "right")
|
||||
@@ -33,6 +35,9 @@ def("DoExpression")
|
||||
.build("body")
|
||||
.field("body", [def("Statement")]);
|
||||
|
||||
def("Super")
|
||||
.bases("Expression");
|
||||
|
||||
def("ExportDefaultDeclaration")
|
||||
.bases("Declaration")
|
||||
.build("declaration")
|
||||
@@ -55,4 +60,24 @@ def("ExportNamedDeclaration")
|
||||
)])
|
||||
.field("source", or(def("ModuleSpecifier"), null));
|
||||
|
||||
def("ExportNamespaceSpecifier")
|
||||
.bases("Specifier")
|
||||
.field("exported", def("Identifier"));
|
||||
|
||||
def("ExportDefaultSpecifier")
|
||||
.bases("Specifier")
|
||||
.field("exported", def("Identifier"));
|
||||
|
||||
def("ExportAllDeclaration")
|
||||
.bases("Declaration")
|
||||
.build("exported", "source")
|
||||
.field("exported", def("Identifier"))
|
||||
.field("source", def("Literal"));
|
||||
|
||||
def("BindExpression")
|
||||
.bases("Expression")
|
||||
.build("object", "callee")
|
||||
.field("object", or(def("Expression"), null))
|
||||
.field("callee", def("Expression"));
|
||||
|
||||
types.finalize();
|
||||
|
||||
@@ -83,4 +83,4 @@ export default function (whitelist, outputType = "global") {
|
||||
}
|
||||
|
||||
return generator(tree).code;
|
||||
};
|
||||
}
|
||||
|
||||
@@ -1,56 +1,62 @@
|
||||
import { validateOption, normaliseOptions, config as optionsConfig } from "./options";
|
||||
import convertSourceMap from "convert-source-map";
|
||||
import * as optionParsers from "./option-parsers";
|
||||
import moduleFormatters from "../modules";
|
||||
import PluginManager from "./plugin-manager";
|
||||
import shebangRegex from "shebang-regex";
|
||||
import TraversalPath from "../../traversal/path";
|
||||
import NodePath from "../../traversal/path";
|
||||
import isFunction from "lodash/lang/isFunction";
|
||||
import isAbsolute from "path-is-absolute";
|
||||
import resolveRc from "../../tools/resolve-rc";
|
||||
import resolveRc from "./options/resolve-rc";
|
||||
import sourceMap from "source-map";
|
||||
import transform from "./../index";
|
||||
import generate from "../../generation";
|
||||
import codeFrame from "../../helpers/code-frame";
|
||||
import defaults from "lodash/object/defaults";
|
||||
import includes from "lodash/collection/includes";
|
||||
import traverse from "../../traversal";
|
||||
import assign from "lodash/object/assign";
|
||||
import Logger from "./logger";
|
||||
import Plugin from "../plugin";
|
||||
import parse from "../../helpers/parse";
|
||||
import Scope from "../../traversal/scope";
|
||||
import merge from "../../helpers/merge";
|
||||
import slash from "slash";
|
||||
import clone from "lodash/lang/clone";
|
||||
import Hub from "../../traversal/hub";
|
||||
import * as util from "../../util";
|
||||
import path from "path";
|
||||
import each from "lodash/collection/each";
|
||||
import * as t from "../../types";
|
||||
|
||||
var checkTransformerVisitor = {
|
||||
enter(node, parent, scope, state) {
|
||||
checkNode(state.stack, node, scope);
|
||||
}
|
||||
};
|
||||
|
||||
function checkNode(stack, node, scope) {
|
||||
each(stack, function (pass) {
|
||||
if (pass.shouldRun || pass.ran) return;
|
||||
pass.checkNode(node, scope);
|
||||
});
|
||||
}
|
||||
|
||||
export default class File {
|
||||
constructor(opts = {}) {
|
||||
this.dynamicImportAbsoluteDefaults = [];
|
||||
this.dynamicImportIds = {};
|
||||
this.dynamicImports = [];
|
||||
constructor(opts = {}, pipeline) {
|
||||
this.transformerDependencies = {};
|
||||
|
||||
this.usedHelpers = {};
|
||||
this.dynamicData = {};
|
||||
this.data = {};
|
||||
this.uids = {};
|
||||
this.dynamicImportTypes = {};
|
||||
this.dynamicImportIds = {};
|
||||
this.dynamicImports = [];
|
||||
|
||||
this.lastStatements = [];
|
||||
this.log = new Logger(this, opts.filename || "unknown");
|
||||
this.opts = this.normalizeOptions(opts);
|
||||
this.ast = {};
|
||||
this.declarations = {};
|
||||
this.usedHelpers = {};
|
||||
this.dynamicData = {};
|
||||
this.data = {};
|
||||
|
||||
this.metadata = {
|
||||
modules: {
|
||||
imports: [],
|
||||
exports: {
|
||||
exported: [],
|
||||
specifiers: []
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
this.pipeline = pipeline;
|
||||
this.log = new Logger(this, opts.filename || "unknown");
|
||||
this.ast = {};
|
||||
|
||||
this.normaliseOptions(opts);
|
||||
|
||||
this.buildTransformers();
|
||||
|
||||
this.hub = new Hub(this);
|
||||
}
|
||||
|
||||
static helpers = [
|
||||
@@ -59,9 +65,9 @@ export default class File {
|
||||
"create-class",
|
||||
"create-decorated-class",
|
||||
"create-decorated-object",
|
||||
"define-decorated-property-descriptor",
|
||||
"tagged-template-literal",
|
||||
"tagged-template-literal-loose",
|
||||
"interop-require",
|
||||
"to-array",
|
||||
"to-consumable-array",
|
||||
"sliced-to-array",
|
||||
@@ -73,6 +79,7 @@ export default class File {
|
||||
"define-property",
|
||||
"async-to-generator",
|
||||
"interop-require-wildcard",
|
||||
"interop-require-default",
|
||||
"typeof",
|
||||
"extends",
|
||||
"get",
|
||||
@@ -82,24 +89,28 @@ export default class File {
|
||||
"temporal-undefined",
|
||||
"temporal-assert-defined",
|
||||
"self-global",
|
||||
"default-props"
|
||||
"default-props",
|
||||
"instanceof",
|
||||
|
||||
// legacy
|
||||
"interop-require",
|
||||
];
|
||||
|
||||
static soloHelpers = [];
|
||||
|
||||
static options = require("./options");
|
||||
static options = optionsConfig;
|
||||
|
||||
normalizeOptions(opts: Object) {
|
||||
opts = assign({}, opts);
|
||||
normaliseOptions(opts: Object) {
|
||||
opts = this.opts = normaliseOptions(assign({}, opts));
|
||||
|
||||
// resolve babelrc
|
||||
if (opts.filename) {
|
||||
var rcFilename = opts.filename;
|
||||
if (!isAbsolute(rcFilename)) rcFilename = path.join(process.cwd(), rcFilename);
|
||||
opts = resolveRc(rcFilename, opts);
|
||||
}
|
||||
|
||||
//
|
||||
|
||||
// check for unknown options
|
||||
for (let key in opts) {
|
||||
if (key[0] === "_") continue;
|
||||
|
||||
@@ -107,23 +118,32 @@ export default class File {
|
||||
if (!option) this.log.error(`Unknown option: ${key}`, ReferenceError);
|
||||
}
|
||||
|
||||
// merge in environment options
|
||||
var envKey = process.env.BABEL_ENV || process.env.NODE_ENV || "development";
|
||||
if (opts.env) merge(opts, normaliseOptions(opts.env[envKey]));
|
||||
|
||||
// normalise options
|
||||
for (let key in File.options) {
|
||||
let option = File.options[key];
|
||||
var val = opts[key];
|
||||
|
||||
var val = opts[key];
|
||||
// optional
|
||||
if (!val && option.optional) continue;
|
||||
|
||||
// deprecated
|
||||
if (val && option.deprecated) {
|
||||
throw new Error("Deprecated option " + key + ": " + option.deprecated);
|
||||
this.log.deprecate("Deprecated option " + key + ": " + option.deprecated);
|
||||
}
|
||||
|
||||
if (val == null) val = option.default || val;
|
||||
// default
|
||||
if (val == null) val = clone(option.default);
|
||||
|
||||
var optionParser = optionParsers[option.type];
|
||||
if (optionParser) val = optionParser(key, val);
|
||||
// validate
|
||||
if (val) val = validateOption(key, val, this.pipeline);
|
||||
|
||||
// aaliases
|
||||
if (option.alias) {
|
||||
opts[option.alias] ||= val;
|
||||
opts[option.alias] = opts[option.alias] || val;
|
||||
} else {
|
||||
opts[key] = val;
|
||||
}
|
||||
@@ -146,7 +166,10 @@ export default class File {
|
||||
opts.basename = path.basename(opts.filename, path.extname(opts.filename));
|
||||
|
||||
opts.ignore = util.arrayify(opts.ignore, util.regexify);
|
||||
opts.only = util.arrayify(opts.only, util.regexify);
|
||||
|
||||
if (opts.only) {
|
||||
opts.only = util.arrayify(opts.only, util.regexify);
|
||||
}
|
||||
|
||||
defaults(opts, {
|
||||
moduleRoot: opts.sourceRoot
|
||||
@@ -162,7 +185,7 @@ export default class File {
|
||||
|
||||
defaults(opts, {
|
||||
sourceFileName: opts.filenameRelative,
|
||||
sourceMapName: opts.filenameRelative
|
||||
sourceMapTarget: opts.filenameRelative
|
||||
});
|
||||
|
||||
//
|
||||
@@ -187,8 +210,9 @@ export default class File {
|
||||
var stack = [];
|
||||
|
||||
// build internal transformers
|
||||
each(transform.transformers, function (transformer, key) {
|
||||
var pass = transformers[key] = transformer.buildPass(file);
|
||||
for (var key in this.pipeline.transformers) {
|
||||
var transformer = this.pipeline.transformers[key];
|
||||
let pass = transformers[key] = transformer.buildPass(file);
|
||||
|
||||
if (pass.canTransform()) {
|
||||
stack.push(pass);
|
||||
@@ -201,111 +225,70 @@ export default class File {
|
||||
transformer.manipulateOptions(file.opts, file);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// init plugins!
|
||||
var beforePlugins = [];
|
||||
var afterPlugins = [];
|
||||
var pluginManager = new PluginManager({
|
||||
file: this,
|
||||
transformers: this.transformers,
|
||||
before: beforePlugins,
|
||||
after: afterPlugins
|
||||
});
|
||||
for (var i = 0; i < file.opts.plugins.length; i++) {
|
||||
this.addPlugin(file.opts.plugins[i], beforePlugins, afterPlugins);
|
||||
pluginManager.add(file.opts.plugins[i]);
|
||||
}
|
||||
stack = beforePlugins.concat(stack, afterPlugins);
|
||||
|
||||
// register
|
||||
this.transformerStack = stack.concat(secondaryStack);
|
||||
}
|
||||
// build transformer stack
|
||||
this.uncollapsedTransformerStack = stack = stack.concat(secondaryStack);
|
||||
|
||||
getModuleFormatter(type: string) {
|
||||
var ModuleFormatter = isFunction(type) ? type : transform.moduleFormatters[type];
|
||||
|
||||
if (!ModuleFormatter) {
|
||||
var loc = util.resolveRelative(type);
|
||||
if (loc) ModuleFormatter = require(loc);
|
||||
// build dependency graph
|
||||
for (let pass of (stack: Array)) {
|
||||
for (var dep of (pass.plugin.dependencies: Array)) {
|
||||
this.transformerDependencies[dep] = pass.key;
|
||||
}
|
||||
}
|
||||
|
||||
if (!ModuleFormatter) {
|
||||
throw new ReferenceError(`Unknown module formatter type ${JSON.stringify(type)}`);
|
||||
}
|
||||
|
||||
return new ModuleFormatter(this);
|
||||
// collapse stack categories
|
||||
this.transformerStack = this.collapseStack(stack);
|
||||
}
|
||||
|
||||
addPlugin(name, before, after) {
|
||||
var position = "before";
|
||||
var plugin;
|
||||
collapseStack(_stack) {
|
||||
var stack = [];
|
||||
var ignore = [];
|
||||
|
||||
if (name) {
|
||||
if (typeof name === "string") {
|
||||
// this is a plugin in the form of "foobar" or "foobar:after"
|
||||
// where the optional colon is the delimiter for plugin position in the transformer stack
|
||||
for (let pass of (_stack: Array)) {
|
||||
// been merged
|
||||
if (ignore.indexOf(pass) >= 0) continue;
|
||||
|
||||
[name, position = "before"] = name.split(":");
|
||||
var group = pass.plugin.metadata.group;
|
||||
|
||||
var loc = util.resolveRelative(name) || util.resolveRelative(`babel-plugin-${name}`);
|
||||
if (loc) {
|
||||
plugin = require(loc)
|
||||
} else {
|
||||
throw new ReferenceError(`Unknown plugin ${JSON.stringify(name)}`);
|
||||
// can't merge
|
||||
if (!pass.canTransform() || !group) {
|
||||
stack.push(pass);
|
||||
continue;
|
||||
}
|
||||
|
||||
var mergeStack = [];
|
||||
for (let pass of (_stack: Array)) {
|
||||
if (pass.plugin.metadata.group === group) {
|
||||
mergeStack.push(pass);
|
||||
ignore.push(pass);
|
||||
}
|
||||
} else {
|
||||
// not a string so we'll just assume that it's a direct Transformer instance, if not then
|
||||
// the checks later on will complain
|
||||
plugin = name;
|
||||
}
|
||||
} else {
|
||||
throw new TypeError(`Ilegal kind ${typeof name} for plugin name ${JSON.stringify(name)}`);
|
||||
}
|
||||
|
||||
// validate position
|
||||
if (position !== "before" && position !== "after") {
|
||||
throw new TypeError(`Plugin ${JSON.stringify(name)} has an illegal position of ${JSON.stringify(position)}`);
|
||||
}
|
||||
|
||||
// validate transformer key
|
||||
var key = plugin.key;
|
||||
if (this.transformers[key]) {
|
||||
throw new ReferenceError(`The key for plugin ${JSON.stringify(name)} of ${key} collides with an existing plugin`);
|
||||
}
|
||||
|
||||
// validate Transformer instance
|
||||
if (!plugin.buildPass || plugin.constructor.name !== "Transformer") {
|
||||
throw new TypeError(`Plugin ${JSON.stringify(name)} didn't export a default Transformer instance`);
|
||||
}
|
||||
|
||||
// build!
|
||||
var pass = this.transformers[key] = plugin.buildPass(this);
|
||||
if (pass.canTransform()) {
|
||||
var stack = before;
|
||||
if (position === "after") stack = after;
|
||||
stack.push(pass);
|
||||
}
|
||||
}
|
||||
|
||||
parseInputSourceMap(code: string) {
|
||||
var opts = this.opts;
|
||||
|
||||
if (opts.inputSourceMap !== false) {
|
||||
var inputMap = convertSourceMap.fromSource(code);
|
||||
if (inputMap) {
|
||||
opts.inputSourceMap = inputMap.toObject();
|
||||
code = convertSourceMap.removeComments(code);
|
||||
var visitors = [];
|
||||
for (let pass of (mergeStack: Array)) {
|
||||
visitors.push(pass.plugin.visitor);
|
||||
}
|
||||
var visitor = traverse.visitors.merge(visitors);
|
||||
var mergePlugin = new Plugin(group, { visitor });
|
||||
stack.push(mergePlugin.buildPass(this));
|
||||
}
|
||||
|
||||
return code;
|
||||
}
|
||||
|
||||
parseShebang(code: string) {
|
||||
var shebangMatch = shebangRegex.exec(code);
|
||||
|
||||
if (shebangMatch) {
|
||||
this.shebang = shebangMatch[0];
|
||||
|
||||
// remove shebang
|
||||
code = code.replace(shebangRegex, "");
|
||||
}
|
||||
|
||||
return code;
|
||||
return stack;
|
||||
}
|
||||
|
||||
set(key: string, val): any {
|
||||
@@ -334,8 +317,8 @@ export default class File {
|
||||
return source;
|
||||
}
|
||||
|
||||
addImport(source: string, name?: string, absoluteDefault?: boolean): Object {
|
||||
name ||= source;
|
||||
addImport(source: string, name?: string, type?: string): Object {
|
||||
name = name || source;
|
||||
var id = this.dynamicImportIds[name];
|
||||
|
||||
if (!id) {
|
||||
@@ -345,10 +328,14 @@ export default class File {
|
||||
var specifiers = [t.importDefaultSpecifier(id)];
|
||||
var declar = t.importDeclaration(specifiers, t.literal(source));
|
||||
declar._blockHoist = 3;
|
||||
if (absoluteDefault) this.dynamicImportAbsoluteDefaults.push(declar);
|
||||
|
||||
if (type) {
|
||||
var modules = this.dynamicImportTypes[type] = this.dynamicImportTypes[type] || [];
|
||||
modules.push(declar);
|
||||
}
|
||||
|
||||
if (this.transformers["es6.modules"].canTransform()) {
|
||||
this.moduleFormatter.importSpecifier(specifiers[0], declar, this.dynamicImports);
|
||||
this.moduleFormatter.importSpecifier(specifiers[0], declar, this.dynamicImports, this.scope);
|
||||
this.moduleFormatter.hasLocalImports = true;
|
||||
} else {
|
||||
this.dynamicImports.push(declar);
|
||||
@@ -358,19 +345,25 @@ export default class File {
|
||||
return id;
|
||||
}
|
||||
|
||||
isConsequenceExpressionStatement(node: Object): boolean {
|
||||
return t.isExpressionStatement(node) && this.lastStatements.indexOf(node) >= 0;
|
||||
}
|
||||
|
||||
attachAuxiliaryComment(node: Object): Object {
|
||||
var comment = this.opts.auxiliaryComment;
|
||||
if (comment) {
|
||||
node.leadingComments ||= [];
|
||||
var beforeComment = this.opts.auxiliaryCommentBefore;
|
||||
if (beforeComment) {
|
||||
node.leadingComments = node.leadingComments || [];
|
||||
node.leadingComments.push({
|
||||
type: "Line",
|
||||
value: " " + comment
|
||||
type: "CommentLine",
|
||||
value: " " + beforeComment
|
||||
});
|
||||
}
|
||||
|
||||
var afterComment = this.opts.auxiliaryCommentAfter;
|
||||
if (afterComment) {
|
||||
node.trailingComments = node.trailingComments || [];
|
||||
node.trailingComments.push({
|
||||
type: "CommentLine",
|
||||
value: " " + afterComment
|
||||
});
|
||||
}
|
||||
|
||||
return node;
|
||||
}
|
||||
|
||||
@@ -381,10 +374,8 @@ export default class File {
|
||||
throw new ReferenceError(`Unknown helper ${name}`);
|
||||
}
|
||||
|
||||
var program = this.ast.program;
|
||||
|
||||
var declar = program._declarations && program._declarations[name];
|
||||
if (declar) return declar.id;
|
||||
var declar = this.declarations[name];
|
||||
if (declar) return declar;
|
||||
|
||||
this.usedHelpers[name] = true;
|
||||
|
||||
@@ -400,47 +391,84 @@ export default class File {
|
||||
}
|
||||
|
||||
var ref = util.template("helper-" + name);
|
||||
ref._compact = true;
|
||||
var uid = this.scope.generateUidIdentifier(name);
|
||||
this.scope.push({
|
||||
key: name,
|
||||
id: uid,
|
||||
init: ref
|
||||
});
|
||||
|
||||
var uid = this.declarations[name] = this.scope.generateUidIdentifier(name);
|
||||
|
||||
if (t.isFunctionExpression(ref) && !ref.id) {
|
||||
ref.body._compact = true;
|
||||
ref._generated = true;
|
||||
ref.id = uid;
|
||||
ref.type = "FunctionDeclaration";
|
||||
this.attachAuxiliaryComment(ref);
|
||||
this.path.unshiftContainer("body", ref);
|
||||
} else {
|
||||
ref._compact = true;
|
||||
this.scope.push({
|
||||
id: uid,
|
||||
init: ref,
|
||||
unique: true
|
||||
});
|
||||
}
|
||||
|
||||
return uid;
|
||||
}
|
||||
|
||||
errorWithNode(node, msg, Error = SyntaxError) {
|
||||
var loc = node.loc.start;
|
||||
var err = new Error(`Line ${loc.line}: ${msg}`);
|
||||
err.loc = loc;
|
||||
var err;
|
||||
if (node && node.loc) {
|
||||
var loc = node.loc.start;
|
||||
err = new Error(`Line ${loc.line}: ${msg}`);
|
||||
err.loc = loc;
|
||||
} else {
|
||||
// todo: find errors with nodes inside to at least point to something
|
||||
err = new Error("There's been an error on a dynamic node. This is almost certainly an internal error. Please report it.");
|
||||
}
|
||||
return err;
|
||||
}
|
||||
|
||||
addCode(code: string) {
|
||||
code = (code || "") + "";
|
||||
code = this.parseInputSourceMap(code);
|
||||
this.code = code;
|
||||
return this.parseShebang(code);
|
||||
mergeSourceMap(map: Object) {
|
||||
var opts = this.opts;
|
||||
|
||||
var inputMap = opts.inputSourceMap;
|
||||
|
||||
if (inputMap) {
|
||||
map.sources[0] = inputMap.file;
|
||||
|
||||
var inputMapConsumer = new sourceMap.SourceMapConsumer(inputMap);
|
||||
var outputMapConsumer = new sourceMap.SourceMapConsumer(map);
|
||||
var outputMapGenerator = sourceMap.SourceMapGenerator.fromSourceMap(outputMapConsumer);
|
||||
outputMapGenerator.applySourceMap(inputMapConsumer);
|
||||
|
||||
var mergedMap = outputMapGenerator.toJSON();
|
||||
mergedMap.sources = inputMap.sources;
|
||||
mergedMap.file = inputMap.file;
|
||||
return mergedMap;
|
||||
}
|
||||
|
||||
return map;
|
||||
}
|
||||
|
||||
shouldIgnore() {
|
||||
var opts = this.opts;
|
||||
return util.shouldIgnore(opts.filename, opts.ignore, opts.only);
|
||||
|
||||
getModuleFormatter(type: string) {
|
||||
if (isFunction(type) || !moduleFormatters[type]) {
|
||||
this.log.deprecate("Custom module formatters are deprecated and will be removed in the next major. Please use Babel plugins instead.");
|
||||
}
|
||||
|
||||
var ModuleFormatter = isFunction(type) ? type : moduleFormatters[type];
|
||||
|
||||
if (!ModuleFormatter) {
|
||||
var loc = util.resolveRelative(type);
|
||||
if (loc) ModuleFormatter = require(loc);
|
||||
}
|
||||
|
||||
if (!ModuleFormatter) {
|
||||
throw new ReferenceError(`Unknown module formatter type ${JSON.stringify(type)}`);
|
||||
}
|
||||
|
||||
return new ModuleFormatter(this);
|
||||
}
|
||||
|
||||
parse(code: string) {
|
||||
if (this.shouldIgnore()) {
|
||||
return {
|
||||
metadata: {},
|
||||
code: code,
|
||||
map: null,
|
||||
ast: null
|
||||
};
|
||||
}
|
||||
|
||||
code = this.addCode(code);
|
||||
|
||||
var opts = this.opts;
|
||||
|
||||
//
|
||||
@@ -462,129 +490,169 @@ export default class File {
|
||||
parseOpts.strictMode = features.strict;
|
||||
parseOpts.sourceType = "module";
|
||||
|
||||
//
|
||||
|
||||
return parse(parseOpts, code, (tree) => {
|
||||
this.transform(tree);
|
||||
return this.generate();
|
||||
});
|
||||
this.log.debug("Parse start");
|
||||
var tree = parse(code, parseOpts);
|
||||
this.log.debug("Parse stop");
|
||||
return tree;
|
||||
}
|
||||
|
||||
setAst(ast) {
|
||||
this.path = TraversalPath.get(null, null, ast, ast, "program", this);
|
||||
_addAst(ast) {
|
||||
this.path = NodePath.get({
|
||||
hub: this.hub,
|
||||
parentPath: null,
|
||||
parent: ast,
|
||||
container: ast,
|
||||
key: "program"
|
||||
}).setContext();
|
||||
this.scope = this.path.scope;
|
||||
this.ast = ast;
|
||||
|
||||
this.path.traverse({
|
||||
enter(node, parent, scope) {
|
||||
if (this.isScope()) {
|
||||
for (var key in scope.bindings) {
|
||||
scope.bindings[key].setTypeAnnotation();
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
transform(ast) {
|
||||
this.log.debug();
|
||||
|
||||
this.setAst(ast);
|
||||
|
||||
this.lastStatements = t.getLastStatements(ast.program);
|
||||
addAst(ast) {
|
||||
this.log.debug("Start set AST");
|
||||
this._addAst(ast);
|
||||
this.log.debug("End set AST");
|
||||
|
||||
this.log.debug("Start module formatter init");
|
||||
var modFormatter = this.moduleFormatter = this.getModuleFormatter(this.opts.modules);
|
||||
if (modFormatter.init && this.transformers["es6.modules"].canTransform()) {
|
||||
modFormatter.init();
|
||||
}
|
||||
this.log.debug("End module formatter init");
|
||||
}
|
||||
|
||||
this.checkNode(ast);
|
||||
|
||||
transform() {
|
||||
this.call("pre");
|
||||
|
||||
each(this.transformerStack, function (pass) {
|
||||
for (var pass of (this.transformerStack: Array)) {
|
||||
pass.transform();
|
||||
});
|
||||
|
||||
}
|
||||
this.call("post");
|
||||
|
||||
return this.generate();
|
||||
}
|
||||
|
||||
wrap(code, callback) {
|
||||
code = code + "";
|
||||
|
||||
try {
|
||||
if (this.shouldIgnore()) {
|
||||
return this.makeResult({ code, ignored: true });
|
||||
} else {
|
||||
return callback();
|
||||
}
|
||||
} catch (err) {
|
||||
if (err._babel) {
|
||||
throw err;
|
||||
} else {
|
||||
err._babel = true;
|
||||
}
|
||||
|
||||
var message = err.message = `${this.opts.filename}: ${err.message}`;
|
||||
|
||||
var loc = err.loc;
|
||||
if (loc) {
|
||||
err.codeFrame = codeFrame(code, loc.line, loc.column + 1, this.opts);
|
||||
message += "\n" + err.codeFrame;
|
||||
}
|
||||
|
||||
if (err.stack) {
|
||||
var newStack = err.stack.replace(err.message, message);
|
||||
try {
|
||||
err.stack = newStack;
|
||||
} catch (e) {
|
||||
// `err.stack` may be a readonly property in some environments
|
||||
}
|
||||
}
|
||||
|
||||
throw err;
|
||||
}
|
||||
}
|
||||
|
||||
addCode(code: string) {
|
||||
code = (code || "") + "";
|
||||
code = this.parseInputSourceMap(code);
|
||||
this.code = code;
|
||||
}
|
||||
|
||||
parseCode() {
|
||||
this.parseShebang();
|
||||
this.addAst(this.parse(this.code));
|
||||
}
|
||||
|
||||
shouldIgnore() {
|
||||
var opts = this.opts;
|
||||
return util.shouldIgnore(opts.filename, opts.ignore, opts.only);
|
||||
}
|
||||
|
||||
call(key: string) {
|
||||
var stack = this.transformerStack;
|
||||
for (var i = 0; i < stack.length; i++) {
|
||||
var transformer = stack[i].transformer;
|
||||
var fn = transformer[key];
|
||||
for (var pass of (this.uncollapsedTransformerStack: Array)) {
|
||||
var fn = pass.plugin[key];
|
||||
if (fn) fn(this);
|
||||
}
|
||||
}
|
||||
|
||||
checkNode(node, scope) {
|
||||
if (Array.isArray(node)) {
|
||||
for (var i = 0; i < node.length; i++) {
|
||||
this.checkNode(node[i], scope);
|
||||
parseInputSourceMap(code: string) {
|
||||
var opts = this.opts;
|
||||
|
||||
if (opts.inputSourceMap !== false) {
|
||||
var inputMap = convertSourceMap.fromSource(code);
|
||||
if (inputMap) {
|
||||
opts.inputSourceMap = inputMap.toObject();
|
||||
code = convertSourceMap.removeComments(code);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
var stack = this.transformerStack;
|
||||
scope ||= this.scope;
|
||||
|
||||
checkNode(stack, node, scope);
|
||||
|
||||
scope.traverse(node, checkTransformerVisitor, {
|
||||
stack: stack
|
||||
});
|
||||
return code;
|
||||
}
|
||||
|
||||
mergeSourceMap(map: Object) {
|
||||
var opts = this.opts;
|
||||
|
||||
var inputMap = opts.inputSourceMap;
|
||||
|
||||
if (inputMap) {
|
||||
map.sources[0] = inputMap.file;
|
||||
|
||||
var inputMapConsumer = new sourceMap.SourceMapConsumer(inputMap);
|
||||
var outputMapConsumer = new sourceMap.SourceMapConsumer(map);
|
||||
var outputMapGenerator = sourceMap.SourceMapGenerator.fromSourceMap(outputMapConsumer);
|
||||
outputMapGenerator.applySourceMap(inputMapConsumer);
|
||||
|
||||
var mergedMap = outputMapGenerator.toJSON();
|
||||
mergedMap.sources = inputMap.sources
|
||||
mergedMap.file = inputMap.file;
|
||||
return mergedMap;
|
||||
parseShebang() {
|
||||
var shebangMatch = shebangRegex.exec(this.code);
|
||||
if (shebangMatch) {
|
||||
this.shebang = shebangMatch[0];
|
||||
this.code = this.code.replace(shebangRegex, "");
|
||||
}
|
||||
|
||||
return map;
|
||||
}
|
||||
|
||||
generate(): {
|
||||
usedHelpers?: Array<string>;
|
||||
code: string;
|
||||
map?: Object;
|
||||
ast?: Object;
|
||||
} {
|
||||
var opts = this.opts;
|
||||
var ast = this.ast;
|
||||
|
||||
makeResult({ code, map = null, ast, ignored }) {
|
||||
var result = {
|
||||
metadata: {},
|
||||
code: "",
|
||||
map: null,
|
||||
ast: null
|
||||
metadata: null,
|
||||
ignored: !!ignored,
|
||||
code: null,
|
||||
ast: null,
|
||||
map: map
|
||||
};
|
||||
|
||||
if (this.opts.metadataUsedHelpers) {
|
||||
if (this.opts.code) {
|
||||
result.code = code;
|
||||
}
|
||||
|
||||
if (this.opts.ast) {
|
||||
result.ast = ast;
|
||||
}
|
||||
|
||||
if (this.opts.metadata) {
|
||||
result.metadata = this.metadata;
|
||||
result.metadata.usedHelpers = Object.keys(this.usedHelpers);
|
||||
}
|
||||
|
||||
if (opts.ast) result.ast = ast;
|
||||
if (!opts.code) return result;
|
||||
return result;
|
||||
}
|
||||
|
||||
generate() {
|
||||
var opts = this.opts;
|
||||
var ast = this.ast;
|
||||
|
||||
var result = { ast };
|
||||
if (!opts.code) return this.makeResult(result);
|
||||
|
||||
this.log.debug("Generation start");
|
||||
|
||||
var _result = generate(ast, opts, this.code);
|
||||
result.code = _result.code;
|
||||
result.map = _result.map;
|
||||
|
||||
this.log.debug("Generation end");
|
||||
|
||||
if (this.shebang) {
|
||||
// add back shebang
|
||||
result.code = `${this.shebang}\n${result.code}`;
|
||||
@@ -602,6 +670,6 @@ export default class File {
|
||||
result.map = null;
|
||||
}
|
||||
|
||||
return result;
|
||||
return this.makeResult(result);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,8 @@
|
||||
import * as util from "../../util";
|
||||
import type File from "./index";
|
||||
import buildDebug from "debug/node";
|
||||
|
||||
var verboseDebug = buildDebug("babel:verbose");
|
||||
var generalDebug = buildDebug("babel");
|
||||
|
||||
export default class Logger {
|
||||
constructor(file: File, filename: string) {
|
||||
@@ -7,26 +11,34 @@ export default class Logger {
|
||||
}
|
||||
|
||||
_buildMessage(msg: string): string {
|
||||
var parts = this.filename;
|
||||
var parts = `[BABEL] ${this.filename}`;
|
||||
if (msg) parts += `: ${msg}`;
|
||||
return parts;
|
||||
}
|
||||
|
||||
warn(msg) {
|
||||
console.warn(this._buildMessage(msg));
|
||||
}
|
||||
|
||||
error(msg: string, Constructor = Error) {
|
||||
throw new Constructor(this._buildMessage(msg));
|
||||
}
|
||||
|
||||
deprecate(msg) {
|
||||
if (!this.file.opts.suppressDeprecationMessages) {
|
||||
console.error(msg);
|
||||
console.error(this._buildMessage(msg));
|
||||
}
|
||||
}
|
||||
|
||||
verbose(msg: string) {
|
||||
if (verboseDebug.enabled) verboseDebug(this._buildMessage(msg));
|
||||
}
|
||||
|
||||
debug(msg: string) {
|
||||
util.debug(this._buildMessage(msg));
|
||||
if (generalDebug.enabled) generalDebug(this._buildMessage(msg));
|
||||
}
|
||||
|
||||
deopt(node: Object, msg: string) {
|
||||
util.debug(this._buildMessage(msg));
|
||||
this.debug(msg);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,28 +0,0 @@
|
||||
import transform from "./../index";
|
||||
import * as util from "../../util";
|
||||
|
||||
export function transformerList(key, val) {
|
||||
val = util.arrayify(val);
|
||||
|
||||
if (val.indexOf("all") >= 0 || val.indexOf(true) >= 0) {
|
||||
val = Object.keys(transform.transformers);
|
||||
}
|
||||
|
||||
return transform._ensureTransformerNames(key, val);
|
||||
}
|
||||
|
||||
export function number(key, val) {
|
||||
return +val;
|
||||
}
|
||||
|
||||
export function boolean(key, val) {
|
||||
return !!val;
|
||||
}
|
||||
|
||||
export function booleanString(key, val) {
|
||||
return util.booleanify(val);
|
||||
}
|
||||
|
||||
export function list(key, val) {
|
||||
return util.list(val);
|
||||
}
|
||||
@@ -15,23 +15,45 @@
|
||||
"hidden": true
|
||||
},
|
||||
|
||||
"extra": {
|
||||
"hidden": true,
|
||||
"default": {}
|
||||
},
|
||||
|
||||
"env": {
|
||||
"hidden": true,
|
||||
"default": {}
|
||||
},
|
||||
|
||||
"moduleId": {
|
||||
"description": "specify a custom name for module ids",
|
||||
"type": "string"
|
||||
},
|
||||
|
||||
"getModuleId": {
|
||||
"hidden": true
|
||||
},
|
||||
|
||||
"retainLines": {
|
||||
"type": "boolean",
|
||||
"default": false,
|
||||
"description": "retain line numbers - will result in really ugly code"
|
||||
},
|
||||
|
||||
"nonStandard": {
|
||||
"type": "boolean",
|
||||
"default": true,
|
||||
"description": "enable support for JSX and Flow"
|
||||
"description": "enable/disable support for JSX and Flow (on by default)"
|
||||
},
|
||||
|
||||
"experimental": {
|
||||
"deprecated": "use `--stage 0`/`{ stage: 0 }` instead"
|
||||
"type": "boolean",
|
||||
"description": "allow use of experimental transformers",
|
||||
"default": false
|
||||
},
|
||||
|
||||
"highlightCode": {
|
||||
"description": "ANSI syntax highlight code frames",
|
||||
"description": "enable/disable ANSI syntax highlighting of code frames (on by default)",
|
||||
"type": "boolean",
|
||||
"default": true
|
||||
},
|
||||
@@ -56,7 +78,8 @@
|
||||
"blacklist": {
|
||||
"type": "transformerList",
|
||||
"description": "blacklist of transformers to NOT use",
|
||||
"shorthand": "b"
|
||||
"shorthand": "b",
|
||||
"default": []
|
||||
},
|
||||
|
||||
"whitelist": {
|
||||
@@ -68,7 +91,8 @@
|
||||
|
||||
"optional": {
|
||||
"type": "transformerList",
|
||||
"description": "list of optional transformers to enable"
|
||||
"description": "list of optional transformers to enable",
|
||||
"default": []
|
||||
},
|
||||
|
||||
"modules": {
|
||||
@@ -100,12 +124,14 @@
|
||||
|
||||
"plugins": {
|
||||
"type": "list",
|
||||
"description": ""
|
||||
"description": "",
|
||||
"default": []
|
||||
},
|
||||
|
||||
"ignore": {
|
||||
"type": "list",
|
||||
"description": "list of glob paths to **not** compile"
|
||||
"description": "list of glob paths to **not** compile",
|
||||
"default": []
|
||||
},
|
||||
|
||||
"only": {
|
||||
@@ -119,6 +145,12 @@
|
||||
"type": "boolean"
|
||||
},
|
||||
|
||||
"metadata": {
|
||||
"hidden": true,
|
||||
"default": true,
|
||||
"type": "boolean"
|
||||
},
|
||||
|
||||
"ast": {
|
||||
"hidden": true,
|
||||
"default": true,
|
||||
@@ -128,7 +160,7 @@
|
||||
"comments": {
|
||||
"type": "boolean",
|
||||
"default": true,
|
||||
"description": "output comments in generated output"
|
||||
"description": "strip/output comments in generated output (on by default)"
|
||||
},
|
||||
|
||||
"compact": {
|
||||
@@ -145,20 +177,32 @@
|
||||
},
|
||||
|
||||
"auxiliaryComment": {
|
||||
"deprecated": "renamed to auxiliaryCommentBefore",
|
||||
"shorthand": "a",
|
||||
"alias": "auxiliaryCommentBefore"
|
||||
},
|
||||
|
||||
"auxiliaryCommentBefore": {
|
||||
"type": "string",
|
||||
"default": "",
|
||||
"shorthand": "a",
|
||||
"description": "attach a comment before all helper declarations and auxiliary code"
|
||||
},
|
||||
|
||||
"externalHelpers": {
|
||||
"auxiliaryCommentAfter": {
|
||||
"type": "string",
|
||||
"default": "",
|
||||
"description": "attach a comment after all helper declarations and auxiliary code"
|
||||
},
|
||||
|
||||
"externalHelpers": {
|
||||
"type": "boolean",
|
||||
"default": false,
|
||||
"shorthand": "r",
|
||||
"description": "uses a reference to `babelHelpers` instead of placing helpers at the top of your code."
|
||||
},
|
||||
|
||||
"metadataUsedHelpers": {
|
||||
"deprecated": "Not required anymore as this is enabled by default",
|
||||
"type": "boolean",
|
||||
"default": false,
|
||||
"hidden": true
|
||||
@@ -177,6 +221,11 @@
|
||||
},
|
||||
|
||||
"sourceMapName": {
|
||||
"alias": "sourceMapTarget",
|
||||
"description": "DEPRECATED - Please use sourceMapTarget"
|
||||
},
|
||||
|
||||
"sourceMapTarget": {
|
||||
"type": "string",
|
||||
"description": "set `file` on returned source map"
|
||||
},
|
||||
@@ -201,6 +250,10 @@
|
||||
"default": false,
|
||||
"hidden": true,
|
||||
"description": "stop trying to load .babelrc files"
|
||||
}
|
||||
},
|
||||
|
||||
"babelrc": {
|
||||
"hidden": true,
|
||||
"description": "do not load the same .babelrc file twice"
|
||||
}
|
||||
}
|
||||
31
src/babel/transformation/file/options/index.js
Normal file
31
src/babel/transformation/file/options/index.js
Normal file
@@ -0,0 +1,31 @@
|
||||
import * as parsers from "./parsers";
|
||||
import config from "./config";
|
||||
|
||||
export { config };
|
||||
|
||||
export function validateOption(key, val, pipeline) {
|
||||
var opt = config[key];
|
||||
var parser = opt && parsers[opt.type];
|
||||
if (parser && parser.validate) {
|
||||
return parser.validate(key, val, pipeline);
|
||||
} else {
|
||||
return val;
|
||||
}
|
||||
}
|
||||
|
||||
export function normaliseOptions(options = {}) {
|
||||
for (var key in options) {
|
||||
var val = options[key];
|
||||
if (val == null) continue;
|
||||
|
||||
var opt = config[key];
|
||||
if (!opt) continue;
|
||||
|
||||
var parser = parsers[opt.type];
|
||||
if (parser) val = parser(val);
|
||||
|
||||
options[key] = val;
|
||||
}
|
||||
|
||||
return options;
|
||||
}
|
||||
29
src/babel/transformation/file/options/parsers.js
Normal file
29
src/babel/transformation/file/options/parsers.js
Normal file
@@ -0,0 +1,29 @@
|
||||
import * as util from "../../../util";
|
||||
|
||||
export function transformerList(val) {
|
||||
return util.arrayify(val);
|
||||
}
|
||||
|
||||
transformerList.validate = function (key, val, pipeline) {
|
||||
if (val.indexOf("all") >= 0 || val.indexOf(true) >= 0) {
|
||||
val = Object.keys(pipeline.transformers);
|
||||
}
|
||||
|
||||
return pipeline._ensureTransformerNames(key, val);
|
||||
};
|
||||
|
||||
export function number(val) {
|
||||
return +val;
|
||||
}
|
||||
|
||||
export function boolean(val) {
|
||||
return !!val;
|
||||
}
|
||||
|
||||
export function booleanString(val) {
|
||||
return util.booleanify(val);
|
||||
}
|
||||
|
||||
export function list(val) {
|
||||
return util.list(val);
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
import stripJsonComments from "strip-json-comments";
|
||||
import merge from "lodash/object/merge";
|
||||
import { normaliseOptions } from "./index";
|
||||
import merge from "../../../helpers/merge";
|
||||
import path from "path";
|
||||
import fs from "fs";
|
||||
|
||||
@@ -17,26 +18,34 @@ function exists(filename) {
|
||||
export default function (loc, opts = {}) {
|
||||
var rel = ".babelrc";
|
||||
|
||||
if (!opts.babelrc) {
|
||||
opts.babelrc = [];
|
||||
}
|
||||
|
||||
function find(start, rel) {
|
||||
var file = path.join(start, rel);
|
||||
|
||||
if (opts.babelrc.indexOf(file) >= 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (exists(file)) {
|
||||
var content = fs.readFileSync(file, "utf8");
|
||||
var json;
|
||||
|
||||
try {
|
||||
json = jsons[content] ||= JSON.parse(stripJsonComments(content));
|
||||
json = jsons[content] = jsons[content] || JSON.parse(stripJsonComments(content));
|
||||
normaliseOptions(json);
|
||||
} catch (err) {
|
||||
err.message = `${file}: ${err.message}`;
|
||||
throw err;
|
||||
}
|
||||
|
||||
opts.babelrc.push(file);
|
||||
|
||||
if (json.breakConfig) return;
|
||||
merge(opts, json, function(a, b) {
|
||||
if (Array.isArray(a)) {
|
||||
return a.concat(b);
|
||||
}
|
||||
});
|
||||
|
||||
merge(opts, json);
|
||||
}
|
||||
|
||||
var up = path.dirname(start);
|
||||
@@ -44,11 +53,10 @@ export default function (loc, opts = {}) {
|
||||
find(up, rel);
|
||||
}
|
||||
}
|
||||
|
||||
if (opts.breakConfig !== true) {
|
||||
|
||||
if (opts.babelrc.indexOf(loc) < 0 && opts.breakConfig !== true) {
|
||||
find(loc, rel);
|
||||
}
|
||||
|
||||
|
||||
return opts;
|
||||
};
|
||||
}
|
||||
123
src/babel/transformation/file/plugin-manager.js
Normal file
123
src/babel/transformation/file/plugin-manager.js
Normal file
@@ -0,0 +1,123 @@
|
||||
import Transformer from "../transformer";
|
||||
import Plugin from "../plugin";
|
||||
import * as types from "../../types";
|
||||
import * as messages from "../../messages";
|
||||
import traverse from "../../types";
|
||||
import parse from "../../helpers/parse";
|
||||
|
||||
var context = {
|
||||
messages,
|
||||
Transformer,
|
||||
Plugin,
|
||||
types,
|
||||
parse,
|
||||
traverse
|
||||
};
|
||||
|
||||
import * as util from "../../util";
|
||||
|
||||
export default class PluginManager {
|
||||
static memoisedPlugins = [];
|
||||
|
||||
static memoisePluginContainer(fn) {
|
||||
for (var i = 0; i < PluginManager.memoisedPlugins.length; i++) {
|
||||
var plugin = PluginManager.memoisedPlugins[i];
|
||||
if (plugin.container === fn) return plugin.transformer;
|
||||
}
|
||||
|
||||
var transformer = fn(context);
|
||||
PluginManager.memoisedPlugins.push({
|
||||
container: fn,
|
||||
transformer: transformer
|
||||
});
|
||||
return transformer;
|
||||
}
|
||||
|
||||
static positions = ["before", "after"];
|
||||
|
||||
constructor({ file, transformers, before, after } = { transformers: {}, before: [], after: [] }) {
|
||||
this.transformers = transformers;
|
||||
this.file = file;
|
||||
this.before = before;
|
||||
this.after = after;
|
||||
}
|
||||
|
||||
subnormaliseString(name, position) {
|
||||
// this is a plugin in the form of "foobar" or "foobar:after"
|
||||
// where the optional colon is the delimiter for plugin position in the transformer stack
|
||||
|
||||
var match = name.match(/^(.*?):(after|before)$/);
|
||||
if (match) [, name, position] = match;
|
||||
|
||||
var loc = util.resolveRelative(`babel-plugin-${name}`) || util.resolveRelative(name);
|
||||
if (loc) {
|
||||
var plugin = require(loc);
|
||||
return {
|
||||
position: position,
|
||||
plugin: plugin.default || plugin
|
||||
};
|
||||
} else {
|
||||
throw new ReferenceError(messages.get("pluginUnknown", name));
|
||||
}
|
||||
}
|
||||
|
||||
validate(name, plugin) {
|
||||
// validate transformer key
|
||||
var key = plugin.key;
|
||||
if (this.transformers[key]) {
|
||||
throw new ReferenceError(messages.get("pluginKeyCollision", key));
|
||||
}
|
||||
|
||||
// validate Transformer instance
|
||||
if (!plugin.buildPass || plugin.constructor.name !== "Plugin") {
|
||||
throw new TypeError(messages.get("pluginNotTransformer", name));
|
||||
}
|
||||
|
||||
// register as a plugin
|
||||
plugin.metadata.plugin = true;
|
||||
}
|
||||
|
||||
add(name) {
|
||||
var position;
|
||||
var plugin;
|
||||
|
||||
if (name) {
|
||||
if (typeof name === "object" && name.transformer) {
|
||||
({ transformer: plugin, position } = name);
|
||||
} else if (typeof name !== "string") {
|
||||
// not a string so we'll just assume that it's a direct Transformer instance, if not then
|
||||
// the checks later on will complain
|
||||
plugin = name;
|
||||
}
|
||||
|
||||
if (typeof name === "string") {
|
||||
({ plugin, position } = this.subnormaliseString(name, position));
|
||||
}
|
||||
} else {
|
||||
throw new TypeError(messages.get("pluginIllegalKind", typeof name, name));
|
||||
}
|
||||
|
||||
// default position
|
||||
position = position || "before";
|
||||
|
||||
// validate position
|
||||
if (PluginManager.positions.indexOf(position) < 0) {
|
||||
throw new TypeError(messages.get("pluginIllegalPosition", position, name));
|
||||
}
|
||||
|
||||
// allow plugin containers to be specified so they don't have to manually require
|
||||
if (typeof plugin === "function") {
|
||||
plugin = PluginManager.memoisePluginContainer(plugin);
|
||||
}
|
||||
|
||||
//
|
||||
this.validate(name, plugin);
|
||||
|
||||
// build!
|
||||
var pass = this.transformers[plugin.key] = plugin.buildPass(this.file);
|
||||
if (pass.canTransform()) {
|
||||
var stack = position === "before" ? this.before : this.after;
|
||||
stack.push(pass);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,9 @@
|
||||
import explode from "./explode-assignable-expression";
|
||||
import * as t from "../../types";
|
||||
|
||||
export default function (exports, opts) {
|
||||
export default function (opts) {
|
||||
var exports = {};
|
||||
|
||||
var isAssignment = function (node) {
|
||||
return node.operator === opts.operator + "=";
|
||||
};
|
||||
@@ -12,7 +14,7 @@ export default function (exports, opts) {
|
||||
|
||||
exports.ExpressionStatement = function (node, parent, scope, file) {
|
||||
// hit the `AssignmentExpression` one below
|
||||
if (file.isConsequenceExpressionStatement(node)) return;
|
||||
if (this.isCompletionRecord()) return;
|
||||
|
||||
var expr = node.expression;
|
||||
if (!isAssignment(expr)) return;
|
||||
@@ -40,4 +42,6 @@ export default function (exports, opts) {
|
||||
if (node.operator !== opts.operator) return;
|
||||
return opts.build(node.left, node.right);
|
||||
};
|
||||
};
|
||||
|
||||
return exports;
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@ export default function (exports, opts) {
|
||||
|
||||
exports.ExpressionStatement = function (node, parent, scope, file) {
|
||||
// hit the `AssignmentExpression` one below
|
||||
if (file.isConsequenceExpressionStatement(node)) return;
|
||||
if (this.isCompletionRecord()) return;
|
||||
|
||||
var expr = node.expression;
|
||||
if (!opts.is(expr, file)) return;
|
||||
@@ -42,4 +42,4 @@ export default function (exports, opts) {
|
||||
|
||||
return nodes;
|
||||
};
|
||||
};
|
||||
}
|
||||
|
||||
@@ -9,15 +9,11 @@ import esutils from "esutils";
|
||||
import * as react from "./react";
|
||||
import * as t from "../../types";
|
||||
|
||||
export default function (exports, opts) {
|
||||
exports.check = function (node) {
|
||||
if (t.isJSX(node)) return true;
|
||||
if (react.isCreateClass(node)) return true;
|
||||
return false;
|
||||
};
|
||||
export default function (opts) {
|
||||
var visitor = {};
|
||||
|
||||
exports.JSXIdentifier = function (node, parent) {
|
||||
if (node.name === "this" && t.isReferenced(node, parent)) {
|
||||
visitor.JSXIdentifier = function (node) {
|
||||
if (node.name === "this" && this.isReferenced()) {
|
||||
return t.thisExpression();
|
||||
} else if (esutils.keyword.isIdentifierNameES6(node.name)) {
|
||||
node.type = "Identifier";
|
||||
@@ -26,22 +22,22 @@ export default function (exports, opts) {
|
||||
}
|
||||
};
|
||||
|
||||
exports.JSXNamespacedName = function (node, parent, scope, file) {
|
||||
visitor.JSXNamespacedName = function () {
|
||||
throw this.errorWithNode(messages.get("JSXNamespacedTags"));
|
||||
};
|
||||
|
||||
exports.JSXMemberExpression = {
|
||||
visitor.JSXMemberExpression = {
|
||||
exit(node) {
|
||||
node.computed = t.isLiteral(node.property);
|
||||
node.type = "MemberExpression";
|
||||
}
|
||||
};
|
||||
|
||||
exports.JSXExpressionContainer = function (node) {
|
||||
visitor.JSXExpressionContainer = function (node) {
|
||||
return node.expression;
|
||||
};
|
||||
|
||||
exports.JSXAttribute = {
|
||||
visitor.JSXAttribute = {
|
||||
enter(node) {
|
||||
var value = node.value;
|
||||
if (t.isLiteral(value) && isString(value.value)) {
|
||||
@@ -55,8 +51,10 @@ export default function (exports, opts) {
|
||||
}
|
||||
};
|
||||
|
||||
exports.JSXOpeningElement = {
|
||||
visitor.JSXOpeningElement = {
|
||||
exit(node, parent, scope, file) {
|
||||
parent.children = react.buildChildren(parent);
|
||||
|
||||
var tagExpr = node.name;
|
||||
var args = [];
|
||||
|
||||
@@ -143,11 +141,7 @@ export default function (exports, opts) {
|
||||
return attribs;
|
||||
};
|
||||
|
||||
exports.JSXElement = {
|
||||
enter(node) {
|
||||
node.children = react.buildChildren(node);
|
||||
},
|
||||
|
||||
visitor.JSXElement = {
|
||||
exit(node) {
|
||||
var callExpr = node.openingElement;
|
||||
|
||||
@@ -161,53 +155,5 @@ export default function (exports, opts) {
|
||||
}
|
||||
};
|
||||
|
||||
// display names
|
||||
|
||||
var addDisplayName = function (id, call) {
|
||||
var props = call.arguments[0].properties;
|
||||
var safe = true;
|
||||
|
||||
for (var i = 0; i < props.length; i++) {
|
||||
var prop = props[i];
|
||||
if (t.isIdentifier(prop.key, { name: "displayName" })) {
|
||||
safe = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (safe) {
|
||||
props.unshift(t.property("init", t.identifier("displayName"), t.literal(id)));
|
||||
}
|
||||
};
|
||||
|
||||
exports.ExportDefaultDeclaration = function (node, parent, scope, file) {
|
||||
if (react.isCreateClass(node.declaration)) {
|
||||
addDisplayName(file.opts.basename, node.declaration);
|
||||
}
|
||||
};
|
||||
|
||||
exports.AssignmentExpression =
|
||||
exports.Property =
|
||||
exports.VariableDeclarator = function (node) {
|
||||
var left, right;
|
||||
|
||||
if (t.isAssignmentExpression(node)) {
|
||||
left = node.left;
|
||||
right = node.right;
|
||||
} else if (t.isProperty(node)) {
|
||||
left = node.key;
|
||||
right = node.value;
|
||||
} else if (t.isVariableDeclarator(node)) {
|
||||
left = node.id;
|
||||
right = node.init;
|
||||
}
|
||||
|
||||
if (t.isMemberExpression(left)) {
|
||||
left = left.property;
|
||||
}
|
||||
|
||||
if (t.isIdentifier(left) && react.isCreateClass(right)) {
|
||||
addDisplayName(left.name, right);
|
||||
}
|
||||
};
|
||||
};
|
||||
return visitor;
|
||||
}
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
import traverse from "../../traversal";
|
||||
import * as t from "../../types";
|
||||
|
||||
var visitor = {
|
||||
@@ -7,10 +6,10 @@ var visitor = {
|
||||
state.found = true;
|
||||
this.stop();
|
||||
}
|
||||
},
|
||||
|
||||
if (this.isFunction()) {
|
||||
this.skip();
|
||||
}
|
||||
Function() {
|
||||
this.skip();
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
import cloneDeep from "lodash/lang/cloneDeep";
|
||||
import traverse from "../../traversal";
|
||||
import each from "lodash/collection/each";
|
||||
import has from "lodash/object/has";
|
||||
import * as t from "../../types";
|
||||
@@ -15,7 +13,7 @@ export function push(mutatorMap, node, kind, file) {
|
||||
|
||||
//
|
||||
|
||||
map._inherits ||= [];
|
||||
map._inherits = map._inherits || [];
|
||||
map._inherits.push(node);
|
||||
|
||||
map._key = node.key;
|
||||
@@ -25,8 +23,8 @@ export function push(mutatorMap, node, kind, file) {
|
||||
}
|
||||
|
||||
if (node.decorators) {
|
||||
var decorators = map.decorators ||= t.arrayExpression([]);
|
||||
decorators.elements = decorators.elements.concat(node.decorators.map(dec => dec.expression));
|
||||
var decorators = map.decorators = map.decorators || t.arrayExpression([]);
|
||||
decorators.elements = decorators.elements.concat(node.decorators.map(dec => dec.expression).reverse());
|
||||
}
|
||||
|
||||
if (map.value || map.initializer) {
|
||||
|
||||
@@ -26,7 +26,7 @@ var getObjRef = function (node, nodes, file, scope) {
|
||||
throw new Error(`We can't explode this node type ${node.type}`);
|
||||
}
|
||||
|
||||
var temp = scope.generateUidBasedOnNode(ref);
|
||||
var temp = scope.generateUidIdentifierBasedOnNode(ref);
|
||||
nodes.push(t.variableDeclaration("var", [
|
||||
t.variableDeclarator(temp, ref)
|
||||
]));
|
||||
@@ -38,7 +38,7 @@ var getPropRef = function (node, nodes, file, scope) {
|
||||
var key = t.toComputedKey(node, prop);
|
||||
if (t.isLiteral(key)) return key;
|
||||
|
||||
var temp = scope.generateUidBasedOnNode(prop);
|
||||
var temp = scope.generateUidIdentifierBasedOnNode(prop);
|
||||
nodes.push(t.variableDeclaration("var", [
|
||||
t.variableDeclarator(temp, prop)
|
||||
]));
|
||||
@@ -68,4 +68,4 @@ export default function (node, nodes, file, scope, allowedSingleIdent) {
|
||||
uid: uid,
|
||||
ref: ref
|
||||
};
|
||||
};
|
||||
}
|
||||
|
||||
@@ -3,7 +3,10 @@ import * as t from "../../types";
|
||||
export default function (node) {
|
||||
var lastNonDefault = 0;
|
||||
for (var i = 0; i < node.params.length; i++) {
|
||||
if (!t.isAssignmentPattern(node.params[i])) lastNonDefault = i + 1;
|
||||
var param = node.params[i];
|
||||
if (!t.isAssignmentPattern(param) && !t.isRestElement(param)) {
|
||||
lastNonDefault = i + 1;
|
||||
}
|
||||
}
|
||||
return lastNonDefault;
|
||||
};
|
||||
}
|
||||
|
||||
37
src/babel/transformation/helpers/memoise-decorators.js
Normal file
37
src/babel/transformation/helpers/memoise-decorators.js
Normal file
@@ -0,0 +1,37 @@
|
||||
import * as t from "../../types";
|
||||
|
||||
export default function (decorators, scope) {
|
||||
for (var i = 0; i < decorators.length; i++) {
|
||||
var decorator = decorators[i];
|
||||
var expression = decorator.expression;
|
||||
if (!t.isMemberExpression(expression)) continue;
|
||||
|
||||
var temp = scope.maybeGenerateMemoised(expression.object);
|
||||
var ref;
|
||||
|
||||
var nodes = [];
|
||||
|
||||
if (temp) {
|
||||
ref = temp;
|
||||
nodes.push(t.assignmentExpression("=", temp, expression.object));
|
||||
} else {
|
||||
ref = expression.object;
|
||||
}
|
||||
|
||||
nodes.push(t.callExpression(
|
||||
t.memberExpression(
|
||||
t.memberExpression(ref, expression.property, expression.computed),
|
||||
t.identifier("bind")
|
||||
),
|
||||
[ref]
|
||||
));
|
||||
|
||||
if (nodes.length === 1) {
|
||||
decorator.expression = nodes[0];
|
||||
} else {
|
||||
decorator.expression = t.sequenceExpression(nodes);
|
||||
}
|
||||
}
|
||||
|
||||
return decorators;
|
||||
}
|
||||
@@ -2,45 +2,58 @@ import getFunctionArity from "./get-function-arity";
|
||||
import * as util from "../../util";
|
||||
import * as t from "../../types";
|
||||
|
||||
function visitIdentifier(context, node, scope, state) {
|
||||
// check if this node matches our function id
|
||||
if (node.name !== state.name) return;
|
||||
|
||||
// check that we don't have a local variable declared as that removes the need
|
||||
// for the wrapper
|
||||
var localDeclar = scope.getBindingIdentifier(state.name);
|
||||
if (localDeclar !== state.outerDeclar) return;
|
||||
|
||||
state.selfReference = true;
|
||||
context.stop();
|
||||
}
|
||||
|
||||
var visitor = {
|
||||
enter(node, parent, scope, state) {
|
||||
// check if this node is a referenced identifier that matches the same as our
|
||||
// function id
|
||||
if (!this.isReferencedIdentifier({ name: state.name })) return;
|
||||
ReferencedIdentifier(node, parent, scope, state) {
|
||||
visitIdentifier(this, node, scope, state);
|
||||
},
|
||||
|
||||
// check that we don't have a local variable declared as that removes the need
|
||||
// for the wrapper
|
||||
var localDeclar = scope.getBindingIdentifier(state.name);
|
||||
if (localDeclar !== state.outerDeclar) return;
|
||||
|
||||
state.selfReference = true;
|
||||
this.stop();
|
||||
BindingIdentifier(node, parent, scope, state) {
|
||||
visitIdentifier(this, node, scope, state);
|
||||
}
|
||||
};
|
||||
|
||||
var wrap = function (state, method, id, scope) {
|
||||
if (state.selfReference) {
|
||||
var templateName = "property-method-assignment-wrapper";
|
||||
if (method.generator) templateName += "-generator";
|
||||
var template = util.template(templateName, {
|
||||
FUNCTION: method,
|
||||
FUNCTION_ID: id,
|
||||
FUNCTION_KEY: scope.generateUidIdentifier(id.name)
|
||||
});
|
||||
template.callee._skipModulesRemap = true;
|
||||
if (scope.hasBinding(id.name) && !scope.hasGlobal(id.name)) {
|
||||
// we can just munge the local binding
|
||||
scope.rename(id.name);
|
||||
} else {
|
||||
// need to add a wrapper since we can't change the references
|
||||
var templateName = "property-method-assignment-wrapper";
|
||||
if (method.generator) templateName += "-generator";
|
||||
var template = util.template(templateName, {
|
||||
FUNCTION: method,
|
||||
FUNCTION_ID: id,
|
||||
FUNCTION_KEY: scope.generateUidIdentifier(id.name)
|
||||
});
|
||||
template.callee._skipModulesRemap = true;
|
||||
|
||||
// shim in dummy params to retain function arity, if you try to read the
|
||||
// source then you'll get the original since it's proxied so it's all good
|
||||
var params = template.callee.body.body[0].params;
|
||||
for (var i = 0, len = getFunctionArity(method); i < len; i++) {
|
||||
params.push(scope.generateUidIdentifier("x"));
|
||||
// shim in dummy params to retain function arity, if you try to read the
|
||||
// source then you'll get the original since it's proxied so it's all good
|
||||
var params = template.callee.body.body[0].params;
|
||||
for (var i = 0, len = getFunctionArity(method); i < len; i++) {
|
||||
params.push(scope.generateUidIdentifier("x"));
|
||||
}
|
||||
|
||||
return template;
|
||||
}
|
||||
|
||||
return template;
|
||||
} else {
|
||||
method.id = id;
|
||||
return method;
|
||||
}
|
||||
|
||||
method.id = id;
|
||||
scope.getProgramParent().references[id.name] = true;
|
||||
};
|
||||
|
||||
var visit = function (node, name, scope) {
|
||||
@@ -55,10 +68,10 @@ var visit = function (node, name, scope) {
|
||||
// check to see if we have a local binding of the id we're setting inside of
|
||||
// the function, this is important as there are caveats associated
|
||||
|
||||
var bindingInfo = scope.getOwnBindingInfo(name);
|
||||
var binding = scope.getOwnBinding(name);
|
||||
|
||||
if (bindingInfo) {
|
||||
if (bindingInfo.kind === "param") {
|
||||
if (binding) {
|
||||
if (binding.kind === "param") {
|
||||
// safari will blow up in strict mode with code like:
|
||||
//
|
||||
// var t = function t(t) {};
|
||||
@@ -82,7 +95,7 @@ var visit = function (node, name, scope) {
|
||||
// so we can safely just set the id and move along as it shadows the
|
||||
// bound function id
|
||||
}
|
||||
} else {
|
||||
} else if (state.outerDeclar || scope.hasGlobal(name)) {
|
||||
scope.traverse(node, visitor, state);
|
||||
}
|
||||
|
||||
@@ -96,20 +109,19 @@ export function custom(node, id, scope) {
|
||||
|
||||
export function property(node, file, scope) {
|
||||
var key = t.toComputedKey(node, node.key);
|
||||
if (!t.isLiteral(key)) return node; // we can't set a function id with this
|
||||
if (!t.isLiteral(key)) return; // we can't set a function id with this
|
||||
|
||||
var name = t.toIdentifier(key.value);
|
||||
if (name === "eval" || name === "arguments") name = "_" + name;
|
||||
var name = t.toBindingIdentifierName(key.value);
|
||||
var id = t.identifier(name);
|
||||
|
||||
var method = node.value;
|
||||
var state = visit(method, name, scope);
|
||||
node.value = wrap(state, method, id, scope);
|
||||
node.value = wrap(state, method, id, scope) || method;
|
||||
}
|
||||
|
||||
export function bare(node, parent, scope) {
|
||||
// has an `id` so we don't need to infer one
|
||||
if (node.id) return node;
|
||||
if (node.id) return;
|
||||
|
||||
var id;
|
||||
if (t.isProperty(parent) && parent.kind === "init" && (!parent.computed || t.isLiteral(parent.key))) {
|
||||
@@ -118,8 +130,17 @@ export function bare(node, parent, scope) {
|
||||
} else if (t.isVariableDeclarator(parent)) {
|
||||
// var foo = function () {};
|
||||
id = parent.id;
|
||||
|
||||
if (t.isIdentifier(id)) {
|
||||
var binding = scope.parent.getBinding(id.name);
|
||||
if (binding && binding.constant && scope.getBinding(id.name) === binding) {
|
||||
// always going to reference this method
|
||||
node.id = id;
|
||||
return;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
return node;
|
||||
return;
|
||||
}
|
||||
|
||||
var name;
|
||||
@@ -131,7 +152,7 @@ export function bare(node, parent, scope) {
|
||||
return;
|
||||
}
|
||||
|
||||
name = t.toIdentifier(name);
|
||||
name = t.toBindingIdentifierName(name);
|
||||
id = t.identifier(name);
|
||||
|
||||
var state = visit(node, name, scope);
|
||||
|
||||
29
src/babel/transformation/helpers/react.js
vendored
29
src/babel/transformation/helpers/react.js
vendored
@@ -1,42 +1,17 @@
|
||||
import isString from "lodash/lang/isString";
|
||||
import * as t from "../../types";
|
||||
|
||||
var isCreateClassCallExpression = t.buildMatchMemberExpression("React.createClass");
|
||||
|
||||
export function isCreateClass(node) {
|
||||
if (!node || !t.isCallExpression(node)) return false;
|
||||
|
||||
// not React.createClass call member object
|
||||
if (!isCreateClassCallExpression(node.callee)) return false;
|
||||
|
||||
// no call arguments
|
||||
var args = node.arguments;
|
||||
if (args.length !== 1) return false;
|
||||
|
||||
// first node arg is not an object
|
||||
var first = args[0];
|
||||
if (!t.isObjectExpression(first)) return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
export var isReactComponent = t.buildMatchMemberExpression("React.Component");
|
||||
|
||||
export function isCompatTag(tagName) {
|
||||
return tagName && /^[a-z]|\-/.test(tagName);
|
||||
}
|
||||
|
||||
function isStringLiteral(node) {
|
||||
return t.isLiteral(node) && isString(node.value);
|
||||
}
|
||||
|
||||
function cleanJSXElementLiteralChild(child, args) {
|
||||
var lines = child.value.split(/\r\n|\n|\r/);
|
||||
|
||||
var lastNonEmptyLine = 0;
|
||||
var i;
|
||||
|
||||
for (i = 0; i < lines.length; i++) {
|
||||
for (let i = 0; i < lines.length; i++) {
|
||||
if (lines[i].match(/[^ \t]/)) {
|
||||
lastNonEmptyLine = i;
|
||||
}
|
||||
@@ -44,7 +19,7 @@ function cleanJSXElementLiteralChild(child, args) {
|
||||
|
||||
var str = "";
|
||||
|
||||
for (i = 0; i < lines.length; i++) {
|
||||
for (let i = 0; i < lines.length; i++) {
|
||||
var line = lines[i];
|
||||
|
||||
var isFirstLine = i === 0;
|
||||
|
||||
@@ -1,35 +1,37 @@
|
||||
import * as t from "../../types";
|
||||
|
||||
var awaitVisitor = {
|
||||
enter(node, parent, scope, state) {
|
||||
if (t.isFunction(node)) this.skip();
|
||||
Function() {
|
||||
this.skip();
|
||||
},
|
||||
|
||||
if (t.isAwaitExpression(node)) {
|
||||
node.type = "YieldExpression";
|
||||
AwaitExpression(node) {
|
||||
node.type = "YieldExpression";
|
||||
|
||||
if (node.all) {
|
||||
// await* foo; -> yield Promise.all(foo);
|
||||
node.all = false;
|
||||
node.argument = t.callExpression(t.memberExpression(t.identifier("Promise"), t.identifier("all")), [node.argument]);
|
||||
}
|
||||
if (node.all) {
|
||||
// await* foo; -> yield Promise.all(foo);
|
||||
node.all = false;
|
||||
node.argument = t.callExpression(t.memberExpression(t.identifier("Promise"), t.identifier("all")), [node.argument]);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
var referenceVisitor = {
|
||||
enter(node, parent, scope, state) {
|
||||
ReferencedIdentifier(node, parent, scope, state) {
|
||||
var name = state.id.name;
|
||||
if (t.isReferencedIdentifier(node, parent, { name: name }) && scope.bindingIdentifierEquals(name, state.id)) {
|
||||
return state.ref ||= scope.generateUidIdentifier(name);
|
||||
if (node.name === name && scope.bindingIdentifierEquals(name, state.id)) {
|
||||
return state.ref = state.ref || scope.generateUidIdentifier(name);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
export default function (node, callId, scope) {
|
||||
export default function (path, callId) {
|
||||
var node = path.node;
|
||||
|
||||
node.async = false;
|
||||
node.generator = true;
|
||||
|
||||
scope.traverse(node, awaitVisitor, state);
|
||||
path.traverse(awaitVisitor, state);
|
||||
|
||||
var call = t.callExpression(callId, [node]);
|
||||
|
||||
@@ -44,15 +46,15 @@ export default function (node, callId, scope) {
|
||||
return declar;
|
||||
} else {
|
||||
if (id) {
|
||||
var state = { id: id };
|
||||
scope.traverse(node, referenceVisitor, state);
|
||||
var state = { id };
|
||||
path.traverse(referenceVisitor, state);
|
||||
|
||||
if (state.ref) {
|
||||
scope.parent.push({ id: state.ref });
|
||||
path.scope.parent.push({ id: state.ref });
|
||||
return t.assignmentExpression("=", state.ref, call);
|
||||
}
|
||||
}
|
||||
|
||||
return call;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import type NodePath from "../../traversal/path";
|
||||
import * as messages from "../../messages";
|
||||
import * as t from "../../types";
|
||||
|
||||
@@ -130,7 +131,7 @@ export default class ReplaceSupers {
|
||||
* Description
|
||||
*/
|
||||
|
||||
traverseLevel(path: TraversalPath, topLevel: boolean) {
|
||||
traverseLevel(path: NodePath, topLevel: boolean) {
|
||||
var state = { self: this, topLevel: topLevel };
|
||||
path.traverse(visitor, state);
|
||||
}
|
||||
@@ -168,7 +169,13 @@ export default class ReplaceSupers {
|
||||
|
||||
if (methodName.name === "constructor") {
|
||||
// constructor() { super(); }
|
||||
return t.memberExpression(superRef, t.identifier("call"));
|
||||
if (parent.arguments.length === 2 && t.isSpreadElement(parent.arguments[1]) && t.isIdentifier(parent.arguments[1].argument, { name: "arguments" })) {
|
||||
// special case single arguments spread
|
||||
parent.arguments[1] = parent.arguments[1].argument;
|
||||
return t.memberExpression(superRef, t.identifier("apply"));
|
||||
} else {
|
||||
return t.memberExpression(superRef, t.identifier("call"));
|
||||
}
|
||||
} else {
|
||||
id = superRef;
|
||||
|
||||
@@ -192,7 +199,7 @@ export default class ReplaceSupers {
|
||||
* Description
|
||||
*/
|
||||
|
||||
looseHandle(path: TraversalPath, getThisReference: Function) {
|
||||
looseHandle(path: NodePath, getThisReference: Function) {
|
||||
var node = path.node;
|
||||
if (path.isSuper()) {
|
||||
return this.getLooseSuperProperty(node, path.parent);
|
||||
@@ -218,7 +225,7 @@ export default class ReplaceSupers {
|
||||
return this.setSuperProperty(node.left.property, node.right, node.left.computed, getThisReference());
|
||||
} else {
|
||||
// super.age += 2; -> var _ref = super.age; super.age = _ref + 2;
|
||||
ref ||= path.scope.generateUidIdentifier("ref");
|
||||
ref = ref || path.scope.generateUidIdentifier("ref");
|
||||
return [
|
||||
t.variableDeclaration("var", [
|
||||
t.variableDeclarator(ref, node.left)
|
||||
@@ -234,7 +241,7 @@ export default class ReplaceSupers {
|
||||
* Description
|
||||
*/
|
||||
|
||||
specHandle(path: TraversalPath, getThisReference: Function) {
|
||||
specHandle(path: NodePath, getThisReference: Function) {
|
||||
var methodNode = this.methodNode;
|
||||
var property;
|
||||
var computed;
|
||||
@@ -274,7 +281,7 @@ export default class ReplaceSupers {
|
||||
property = node.property;
|
||||
computed = node.computed;
|
||||
} else if (t.isUpdateExpression(node) && isMemberExpressionSuper(node.argument)) {
|
||||
var binary = t.binaryExpression(node.operator[0], node.argument, t.literal(1))
|
||||
var binary = t.binaryExpression(node.operator[0], node.argument, t.literal(1));
|
||||
if (node.prefix) {
|
||||
// ++super.foo; -> super.foo += 1;
|
||||
return this.specHandleAssignmentExpression(null, path, binary, getThisReference);
|
||||
|
||||
@@ -1,19 +0,0 @@
|
||||
import * as t from "../../types";
|
||||
|
||||
export function has(node) {
|
||||
var first = node.body[0];
|
||||
return t.isExpressionStatement(first) && t.isLiteral(first.expression, { value: "use strict" });
|
||||
}
|
||||
|
||||
export function wrap(node, callback) {
|
||||
var useStrictNode;
|
||||
if (has(node)) {
|
||||
useStrictNode = node.body.shift();
|
||||
}
|
||||
|
||||
callback();
|
||||
|
||||
if (useStrictNode) {
|
||||
node.body.unshift(useStrictNode);
|
||||
}
|
||||
}
|
||||
@@ -1,68 +1,44 @@
|
||||
import normalizeAst from "../helpers/normalize-ast";
|
||||
import Transformer from "./transformer";
|
||||
import object from "../helpers/object";
|
||||
import File from "./file";
|
||||
import each from "lodash/collection/each";
|
||||
import Pipeline from "./pipeline";
|
||||
|
||||
export default function transform(code: string, opts?: Object) {
|
||||
var file = new File(opts);
|
||||
return file.parse(code);
|
||||
var pipeline = new Pipeline;
|
||||
|
||||
//
|
||||
|
||||
import transformers from "./transformers";
|
||||
|
||||
for (var key in transformers) {
|
||||
var transformer = transformers[key];
|
||||
|
||||
if (typeof transformer === "object") {
|
||||
var metadata = transformer.metadata = transformer.metadata || {};
|
||||
metadata.group = metadata.group || "builtin-basic";
|
||||
}
|
||||
}
|
||||
|
||||
transform.fromAst = function (ast, code, opts) {
|
||||
ast = normalizeAst(ast);
|
||||
pipeline.addTransformers(transformers);
|
||||
|
||||
var file = new File(opts);
|
||||
file.addCode(code);
|
||||
file.transform(ast);
|
||||
return file.generate();
|
||||
};
|
||||
//
|
||||
|
||||
transform._ensureTransformerNames = function (type: string, rawKeys: Array<string>) {
|
||||
var keys = [];
|
||||
import deprecated from "./transformers/deprecated";
|
||||
pipeline.addDeprecated(deprecated);
|
||||
|
||||
for (var i = 0; i < rawKeys.length; i++) {
|
||||
var key = rawKeys[i];
|
||||
//
|
||||
|
||||
var deprecatedKey = transform.deprecatedTransformerMap[key];
|
||||
var aliasKey = transform.aliasTransformerMap[key];
|
||||
if (aliasKey) {
|
||||
keys.push(aliasKey);
|
||||
} else if (deprecatedKey) {
|
||||
// deprecated key, remap it to the new one
|
||||
console.error(`The transformer ${key} has been renamed to ${deprecatedKey}`);
|
||||
rawKeys.push(deprecatedKey);
|
||||
} else if (transform.transformers[key]) {
|
||||
// valid key
|
||||
keys.push(key);
|
||||
} else if (transform.namespaces[key]) {
|
||||
// namespace, append all transformers within this namespace
|
||||
keys = keys.concat(transform.namespaces[key]);
|
||||
} else {
|
||||
// invalid key
|
||||
throw new ReferenceError(`Unknown transformer ${key} specified in ${type}`);
|
||||
}
|
||||
}
|
||||
import aliases from "./transformers/aliases";
|
||||
pipeline.addAliases(aliases);
|
||||
|
||||
return keys;
|
||||
};
|
||||
//
|
||||
|
||||
transform.transformerNamespaces = object();
|
||||
transform.transformers = object();
|
||||
transform.namespaces = object();
|
||||
import * as filters from "./transformers/filters";
|
||||
pipeline.addFilter(filters.internal);
|
||||
pipeline.addFilter(filters.blacklist);
|
||||
pipeline.addFilter(filters.whitelist);
|
||||
pipeline.addFilter(filters.stage);
|
||||
pipeline.addFilter(filters.optional);
|
||||
|
||||
transform.deprecatedTransformerMap = require("./transformers/deprecated");
|
||||
transform.aliasTransformerMap = require("./transformers/aliases");
|
||||
transform.moduleFormatters = require("./modules");
|
||||
//
|
||||
|
||||
import rawTransformers from "./transformers";
|
||||
|
||||
each(rawTransformers, function (transformer, key) {
|
||||
var namespace = key.split(".")[0];
|
||||
|
||||
transform.namespaces[namespace] ||= [];
|
||||
transform.namespaces[namespace].push(key);
|
||||
transform.transformerNamespaces[key] = namespace;
|
||||
|
||||
transform.transformers[key] = new Transformer(key, transformer);
|
||||
});
|
||||
var transform = pipeline.transform.bind(pipeline);
|
||||
transform.fromAst = pipeline.transformFromAst.bind(pipeline);
|
||||
transform.pipeline = pipeline;
|
||||
export default transform;
|
||||
|
||||
@@ -1,115 +1,182 @@
|
||||
import * as messages from "../../messages";
|
||||
import traverse from "../../traversal";
|
||||
import Remaps from "./lib/remaps";
|
||||
import extend from "lodash/object/extend";
|
||||
import object from "../../helpers/object";
|
||||
import * as util from "../../util";
|
||||
import * as t from "../../types";
|
||||
|
||||
var remapVisitor = {
|
||||
enter(node, parent, scope, formatter) {
|
||||
var remap = formatter.internalRemap[node.name];
|
||||
if (this.isReferencedIdentifier() && remap) {
|
||||
if (!scope.hasBinding(node.name) || scope.bindingIdentifierEquals(node.name, formatter.localImports[node.name])) {
|
||||
return remap;
|
||||
var metadataVisitor = {
|
||||
ModuleDeclaration: {
|
||||
enter(node, parent, scope, formatter) {
|
||||
if (node.source) {
|
||||
node.source.value = formatter.file.resolveModuleSource(node.source.value);
|
||||
formatter.addScope(this);
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
if (t.isUpdateExpression(node)) {
|
||||
var exported = formatter.getExport(node.argument, scope);
|
||||
|
||||
if (exported) {
|
||||
this.skip();
|
||||
|
||||
// expand to long file assignment expression
|
||||
var assign = t.assignmentExpression(node.operator[0] + "=", node.argument, t.literal(1));
|
||||
|
||||
// remap this assignment expression
|
||||
var remapped = formatter.remapExportAssignment(assign, exported);
|
||||
|
||||
// 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 (node._skipModulesRemap) {
|
||||
return this.skip();
|
||||
}
|
||||
|
||||
if (t.isAssignmentExpression(node) && !node._ignoreModulesRemap) {
|
||||
var exported = formatter.getExport(node.left, scope);
|
||||
if (exported) {
|
||||
this.skip();
|
||||
return formatter.remapExportAssignment(node, exported);
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
var importsVisitor = {
|
||||
ImportDeclaration: {
|
||||
enter(node, parent, scope, formatter) {
|
||||
exit(node, parent, scope, formatter) {
|
||||
formatter.hasLocalImports = true;
|
||||
extend(formatter.localImports, this.getBindingIdentifiers());
|
||||
|
||||
var specifiers = [];
|
||||
var imported = [];
|
||||
formatter.metadata.imports.push({
|
||||
source: node.source.value,
|
||||
imported,
|
||||
specifiers
|
||||
});
|
||||
|
||||
for (var specifier of (this.get("specifiers"): Array)) {
|
||||
var ids = specifier.getBindingIdentifiers();
|
||||
extend(formatter.localImports, ids);
|
||||
|
||||
var local = specifier.node.local.name;
|
||||
|
||||
if (specifier.isImportDefaultSpecifier()) {
|
||||
imported.push("default");
|
||||
specifiers.push({
|
||||
kind: "named",
|
||||
imported: "default",
|
||||
local
|
||||
});
|
||||
}
|
||||
|
||||
if (specifier.isImportSpecifier()) {
|
||||
var importedName = specifier.node.imported.name;
|
||||
imported.push(importedName);
|
||||
specifiers.push({
|
||||
kind: "named",
|
||||
imported: importedName,
|
||||
local
|
||||
});
|
||||
}
|
||||
|
||||
if (specifier.isImportNamespaceSpecifier()) {
|
||||
imported.push("*");
|
||||
specifiers.push({
|
||||
kind: "namespace",
|
||||
local
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
ExportDeclaration(node, parent, scope, formatter) {
|
||||
formatter.hasLocalExports = true;
|
||||
|
||||
var source = node.source ? node.source.value : null;
|
||||
var exports = formatter.metadata.exports;
|
||||
|
||||
// export function foo() {}
|
||||
// export var foo = "bar";
|
||||
var declar = this.get("declaration");
|
||||
if (declar.isStatement()) {
|
||||
var bindings = declar.getBindingIdentifiers();
|
||||
|
||||
for (var name in bindings) {
|
||||
var binding = bindings[name];
|
||||
formatter._addExport(name, binding);
|
||||
|
||||
exports.exported.push(name);
|
||||
exports.specifiers.push({
|
||||
kind: "local",
|
||||
local: name,
|
||||
exported: this.isExportDefaultDeclaration() ? "default" : name
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
if (this.isExportNamedDeclaration() && node.specifiers) {
|
||||
for (var specifier of (node.specifiers: Array)) {
|
||||
var exported = specifier.exported.name;
|
||||
exports.exported.push(exported);
|
||||
|
||||
// export foo from "bar";
|
||||
if (t.isExportDefaultSpecifier(specifier)) {
|
||||
exports.specifiers.push({
|
||||
kind: "external",
|
||||
local: exported,
|
||||
exported,
|
||||
source
|
||||
});
|
||||
}
|
||||
|
||||
// export * as foo from "bar";
|
||||
if (t.isExportNamespaceSpecifier(specifier)) {
|
||||
exports.specifiers.push({
|
||||
kind: "external-namespace",
|
||||
exported,
|
||||
source
|
||||
});
|
||||
}
|
||||
|
||||
var local = specifier.local;
|
||||
if (!local) continue;
|
||||
|
||||
formatter._addExport(local.name, specifier.exported);
|
||||
|
||||
// export { foo } from "bar";
|
||||
// export { foo as bar } from "bar";
|
||||
if (source) {
|
||||
exports.specifiers.push({
|
||||
kind: "external",
|
||||
local: local.name,
|
||||
exported,
|
||||
source
|
||||
});
|
||||
}
|
||||
|
||||
// export { foo };
|
||||
// export { foo as bar };
|
||||
if (!source) {
|
||||
exports.specifiers.push({
|
||||
kind: "local",
|
||||
local: local.name,
|
||||
exported
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// export * from "bar";
|
||||
if (this.isExportAllDeclaration()) {
|
||||
exports.specifiers.push({
|
||||
kind: "external-all",
|
||||
source
|
||||
});
|
||||
}
|
||||
|
||||
if (!t.isExportDefaultDeclaration(node) && !declar.isTypeAlias()) {
|
||||
var onlyDefault = node.specifiers && node.specifiers.length === 1 && t.isSpecifierDefault(node.specifiers[0]);
|
||||
if (!onlyDefault) {
|
||||
formatter.hasNonDefaultExports = true;
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
Scope(node, parent, scope, formatter) {
|
||||
if (!formatter.isLoose()) {
|
||||
this.skip();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
var exportsVisitor = traverse.explode({
|
||||
ExportDeclaration: {
|
||||
enter(node, parent, scope, formatter) {
|
||||
formatter.hasLocalExports = true;
|
||||
|
||||
var declar = this.get("declaration");
|
||||
if (declar.isStatement()) {
|
||||
var bindings = declar.getBindingIdentifiers()
|
||||
for (var name in bindings) {
|
||||
var binding = bindings[name];
|
||||
formatter._addExport(name, binding);
|
||||
}
|
||||
}
|
||||
|
||||
if (this.isExportNamedDeclaration() && node.specifiers) {
|
||||
for (var i = 0; i < node.specifiers.length; i++) {
|
||||
var specifier = node.specifiers[i];
|
||||
var local = specifier.local;
|
||||
if (!local) continue;
|
||||
|
||||
formatter._addExport(local.name, specifier.exported);
|
||||
}
|
||||
}
|
||||
|
||||
if (!t.isExportDefaultDeclaration(node)) {
|
||||
var onlyDefault = node.specifiers && node.specifiers.length === 1 && t.isSpecifierDefault(node.specifiers[0]);
|
||||
if (!onlyDefault) {
|
||||
formatter.hasNonDefaultExports = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
export default class DefaultFormatter {
|
||||
constructor(file) {
|
||||
this.internalRemap = object();
|
||||
this.defaultIds = object();
|
||||
this.scope = file.scope;
|
||||
this.file = file;
|
||||
this.ids = object();
|
||||
// object containg all module sources with the scope that they're contained in
|
||||
this.sourceScopes = object();
|
||||
|
||||
// ids for use in module ids
|
||||
this.defaultIds = object();
|
||||
this.ids = object();
|
||||
|
||||
// contains reference aliases for live bindings
|
||||
this.remaps = new Remaps(file, this);
|
||||
|
||||
this.scope = file.scope;
|
||||
this.file = file;
|
||||
|
||||
this.hasNonDefaultExports = false;
|
||||
|
||||
@@ -119,8 +186,25 @@ export default class DefaultFormatter {
|
||||
this.localExports = object();
|
||||
this.localImports = object();
|
||||
|
||||
this.getLocalExports();
|
||||
this.getLocalImports();
|
||||
this.metadata = file.metadata.modules;
|
||||
this.getMetadata();
|
||||
}
|
||||
|
||||
addScope(path) {
|
||||
var source = path.node.source && path.node.source.value;
|
||||
if (!source) return;
|
||||
|
||||
var existingScope = this.sourceScopes[source];
|
||||
if (existingScope && existingScope !== path.scope) {
|
||||
throw path.errorWithNode(messages.get("modulesDuplicateDeclarations"));
|
||||
}
|
||||
|
||||
this.sourceScopes[source] = path.scope;
|
||||
}
|
||||
|
||||
isModuleType(node, type) {
|
||||
var modules = this.file.dynamicImportTypes[type];
|
||||
return modules && modules.indexOf(node) >= 0;
|
||||
}
|
||||
|
||||
transform() {
|
||||
@@ -131,17 +215,22 @@ export default class DefaultFormatter {
|
||||
return (t.isExportDefaultDeclaration(node) || t.isSpecifierDefault(node)) && !this.noInteropRequireExport && !this.hasNonDefaultExports;
|
||||
}
|
||||
|
||||
getLocalExports() {
|
||||
this.file.path.traverse(exportsVisitor, this);
|
||||
}
|
||||
|
||||
getLocalImports() {
|
||||
this.file.path.traverse(importsVisitor, this);
|
||||
getMetadata() {
|
||||
var has = false;
|
||||
for (var node of (this.file.ast.program.body: Array)) {
|
||||
if (t.isModuleDeclaration(node)) {
|
||||
has = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (has || this.isLoose()) {
|
||||
this.file.path.traverse(metadataVisitor, this);
|
||||
}
|
||||
}
|
||||
|
||||
remapAssignments() {
|
||||
if (this.hasLocalExports || this.hasLocalImports) {
|
||||
this.file.path.traverse(remapVisitor, this);
|
||||
this.remaps.run();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -160,7 +249,7 @@ export default class DefaultFormatter {
|
||||
}
|
||||
|
||||
_addExport(name, exported) {
|
||||
var info = this.localExports[name] ||= {
|
||||
var info = this.localExports[name] = this.localExports[name] || {
|
||||
binding: this.scope.getBindingIdentifier(name),
|
||||
exported: []
|
||||
};
|
||||
@@ -178,7 +267,10 @@ export default class DefaultFormatter {
|
||||
|
||||
getModuleName() {
|
||||
var opts = this.file.opts;
|
||||
if (opts.moduleId) return opts.moduleId;
|
||||
// moduleId is n/a if a `getModuleId()` is provided
|
||||
if (opts.moduleId && !opts.getModuleId) {
|
||||
return opts.moduleId;
|
||||
}
|
||||
|
||||
var filenameRelative = opts.filenameRelative;
|
||||
var moduleName = "";
|
||||
@@ -207,7 +299,12 @@ export default class DefaultFormatter {
|
||||
// normalize path separators
|
||||
moduleName = moduleName.replace(/\\/g, "/");
|
||||
|
||||
return moduleName;
|
||||
if (opts.getModuleId) {
|
||||
// If return is falsy, assume they want us to use our generated default name
|
||||
return opts.getModuleId(moduleName) || moduleName;
|
||||
} else {
|
||||
return moduleName;
|
||||
}
|
||||
}
|
||||
|
||||
_pushStatement(ref, nodes) {
|
||||
|
||||
@@ -10,4 +10,4 @@ export default function (Parent) {
|
||||
util.inherits(Constructor, Parent);
|
||||
|
||||
return Constructor;
|
||||
};
|
||||
}
|
||||
|
||||
@@ -6,8 +6,8 @@ import * as util from "../../util";
|
||||
import * as t from "../../types";
|
||||
|
||||
export default class AMDFormatter extends DefaultFormatter {
|
||||
init() {
|
||||
CommonFormatter.prototype._init.call(this, this.hasNonDefaultExports);
|
||||
setup() {
|
||||
CommonFormatter.prototype._setup.call(this, this.hasNonDefaultExports);
|
||||
}
|
||||
|
||||
buildDependencyLiterals() {
|
||||
@@ -23,7 +23,7 @@ export default class AMDFormatter extends DefaultFormatter {
|
||||
*/
|
||||
|
||||
transform(program) {
|
||||
DefaultFormatter.prototype.transform.apply(this, arguments);
|
||||
CommonFormatter.prototype.transform.apply(this, arguments);
|
||||
|
||||
var body = program.body;
|
||||
|
||||
@@ -72,7 +72,7 @@ export default class AMDFormatter extends DefaultFormatter {
|
||||
this.getExternalReference(node);
|
||||
}
|
||||
|
||||
importSpecifier(specifier, node, nodes) {
|
||||
importSpecifier(specifier, node, nodes, scope) {
|
||||
var key = node.source.value;
|
||||
var ref = this.getExternalReference(node);
|
||||
|
||||
@@ -80,7 +80,9 @@ export default class AMDFormatter extends DefaultFormatter {
|
||||
this.defaultIds[key] = specifier.local;
|
||||
}
|
||||
|
||||
if (includes(this.file.dynamicImportAbsoluteDefaults, node)) {
|
||||
if (this.isModuleType(node, "absolute")) {
|
||||
// absolute module reference
|
||||
} else if (this.isModuleType(node, "absoluteDefault")) {
|
||||
// prevent unnecessary renaming of dynamic imports
|
||||
this.ids[node.source.value] = ref;
|
||||
ref = t.memberExpression(ref, t.identifier("default"));
|
||||
@@ -88,11 +90,11 @@ export default class AMDFormatter extends DefaultFormatter {
|
||||
// import * as bar from "foo";
|
||||
} else if (!includes(this.file.dynamicImported, node) && t.isSpecifierDefault(specifier) && !this.noInteropRequireImport) {
|
||||
// import foo from "foo";
|
||||
var uid = this.scope.generateUidIdentifier(specifier.local.name);
|
||||
var uid = scope.generateUidIdentifier(specifier.local.name);
|
||||
nodes.push(t.variableDeclaration("var", [
|
||||
t.variableDeclarator(uid, t.callExpression(this.file.addHelper("interop-require"), [ref]))
|
||||
t.variableDeclarator(uid, t.callExpression(this.file.addHelper("interop-require-default"), [ref]))
|
||||
]));
|
||||
ref = uid;
|
||||
ref = t.memberExpression(uid, t.identifier("default"));
|
||||
} else {
|
||||
// import { foo } from "foo";
|
||||
var imported = specifier.imported;
|
||||
@@ -100,17 +102,22 @@ export default class AMDFormatter extends DefaultFormatter {
|
||||
ref = t.memberExpression(ref, imported);
|
||||
}
|
||||
|
||||
this.internalRemap[specifier.local.name] = ref;
|
||||
this.remaps.add(scope, specifier.local.name, ref);
|
||||
}
|
||||
|
||||
exportSpecifier(specifier, node, nodes) {
|
||||
if (this.doDefaultExportInterop(specifier)) {
|
||||
nodes.push(util.template("exports-default-assign", {
|
||||
VALUE: specifier.local
|
||||
}, true));
|
||||
} else {
|
||||
CommonFormatter.prototype.exportSpecifier.apply(this, arguments);
|
||||
this.passModuleArg = true;
|
||||
|
||||
if (specifier.exported !== specifier.local && !node.source) {
|
||||
nodes.push(util.template("exports-default-assign", {
|
||||
VALUE: specifier.local
|
||||
}, true));
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
CommonFormatter.prototype.exportSpecifier.apply(this, arguments);
|
||||
}
|
||||
|
||||
exportDeclaration(node, nodes) {
|
||||
|
||||
@@ -1,14 +1,13 @@
|
||||
import DefaultFormatter from "./_default";
|
||||
import includes from "lodash/collection/includes";
|
||||
import * as util from "../../util";
|
||||
import * as t from "../../types";
|
||||
|
||||
export default class CommonJSFormatter extends DefaultFormatter {
|
||||
init() {
|
||||
this._init(this.hasLocalExports);
|
||||
setup() {
|
||||
this._setup(this.hasLocalExports);
|
||||
}
|
||||
|
||||
_init(conditional) {
|
||||
_setup(conditional) {
|
||||
var file = this.file;
|
||||
var scope = file.scope;
|
||||
|
||||
@@ -20,7 +19,7 @@ export default class CommonJSFormatter extends DefaultFormatter {
|
||||
if (this.file.isLoose("es6.modules")) templateName += "-loose";
|
||||
var declar = util.template(templateName, true);
|
||||
declar._blockHoist = 3;
|
||||
file.ast.program.body.unshift(declar);
|
||||
file.path.unshiftContainer("body", [declar]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -38,25 +37,27 @@ export default class CommonJSFormatter extends DefaultFormatter {
|
||||
}
|
||||
}
|
||||
|
||||
importSpecifier(specifier, node, nodes) {
|
||||
importSpecifier(specifier, node, nodes, scope) {
|
||||
var variableName = specifier.local;
|
||||
|
||||
var ref = this.getExternalReference(node, nodes);
|
||||
|
||||
// import foo from "foo";
|
||||
if (t.isSpecifierDefault(specifier)) {
|
||||
if (includes(this.file.dynamicImportAbsoluteDefaults, node)) {
|
||||
this.internalRemap[variableName.name] = ref;
|
||||
if (this.isModuleType(node, "absolute")) {
|
||||
// absolute module reference
|
||||
} else if (this.isModuleType(node, "absoluteDefault")) {
|
||||
this.remaps.add(scope, variableName.name, ref);
|
||||
} else if (this.noInteropRequireImport) {
|
||||
this.internalRemap[variableName.name] = t.memberExpression(ref, t.identifier("default"));
|
||||
this.remaps.add(scope, variableName.name, t.memberExpression(ref, t.identifier("default")));
|
||||
} else {
|
||||
var uid = this.scope.generateUidBasedOnNode(node, "import");
|
||||
var uid = this.scope.generateUidIdentifierBasedOnNode(node, "import");
|
||||
|
||||
nodes.push(t.variableDeclaration("var", [
|
||||
t.variableDeclarator(uid, t.callExpression(this.file.addHelper("interop-require-wildcard"), [ref]))
|
||||
t.variableDeclarator(uid, t.callExpression(this.file.addHelper("interop-require-default"), [ref]))
|
||||
]));
|
||||
|
||||
this.internalRemap[variableName.name] = t.memberExpression(uid, t.identifier("default"));
|
||||
this.remaps.add(scope, variableName.name, t.memberExpression(uid, t.identifier("default")));
|
||||
}
|
||||
} else {
|
||||
if (t.isImportNamespaceSpecifier(specifier)) {
|
||||
@@ -70,7 +71,7 @@ export default class CommonJSFormatter extends DefaultFormatter {
|
||||
]));
|
||||
} else {
|
||||
// import { foo } from "foo";
|
||||
this.internalRemap[variableName.name] = t.memberExpression(ref, specifier.imported);
|
||||
this.remaps.add(scope, variableName.name, t.memberExpression(ref, specifier.imported));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -82,7 +83,7 @@ export default class CommonJSFormatter extends DefaultFormatter {
|
||||
}, true));
|
||||
}
|
||||
|
||||
exportSpecifier(specifier, node, nodes) {
|
||||
exportSpecifier(specifier) {
|
||||
if (this.doDefaultExportInterop(specifier)) {
|
||||
this.hasDefaultOnlyExport = true;
|
||||
}
|
||||
@@ -90,7 +91,7 @@ export default class CommonJSFormatter extends DefaultFormatter {
|
||||
DefaultFormatter.prototype.exportSpecifier.apply(this, arguments);
|
||||
}
|
||||
|
||||
exportDeclaration(node, nodes) {
|
||||
exportDeclaration(node) {
|
||||
if (this.doDefaultExportInterop(node)) {
|
||||
this.hasDefaultOnlyExport = true;
|
||||
}
|
||||
@@ -99,18 +100,19 @@ export default class CommonJSFormatter extends DefaultFormatter {
|
||||
}
|
||||
|
||||
_getExternalReference(node, nodes) {
|
||||
var source = node.source.value;
|
||||
|
||||
var call = t.callExpression(t.identifier("require"), [node.source]);
|
||||
var uid;
|
||||
|
||||
if (includes(this.file.dynamicImportAbsoluteDefaults, node)) {
|
||||
if (this.isModuleType(node, "absolute")) {
|
||||
// absolute module reference
|
||||
} else if (this.isModuleType(node, "absoluteDefault")) {
|
||||
call = t.memberExpression(call, t.identifier("default"));
|
||||
uid = node.specifiers[0].local;
|
||||
} else {
|
||||
uid = this.scope.generateUidBasedOnNode(node, "import");
|
||||
uid = this.scope.generateUidIdentifierBasedOnNode(node, "import");
|
||||
}
|
||||
|
||||
uid = uid || node.specifiers[0].local;
|
||||
|
||||
var declar = t.variableDeclaration("var", [
|
||||
t.variableDeclarator(uid, call)
|
||||
]);
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user