Compare commits
538 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
aefd69d31e | ||
|
|
e328031b19 | ||
|
|
571b6a4cd7 | ||
|
|
41cf942391 | ||
|
|
98f28b8e89 | ||
|
|
8f88afc037 | ||
|
|
6359675a4f | ||
|
|
a265c3f25c | ||
|
|
29eb99ee93 | ||
|
|
0c5c1ff989 | ||
|
|
499951123a | ||
|
|
c0fd4c1f9e | ||
|
|
579e6fecee | ||
|
|
bb3665a3b6 | ||
|
|
e6de688234 | ||
|
|
4c233e88ff | ||
|
|
ae2ba0b5a3 | ||
|
|
e34d950793 | ||
|
|
e4083fbbd7 | ||
|
|
59ed7977ef | ||
|
|
dc441e9a8f | ||
|
|
2e21795f57 | ||
|
|
5c988f7fc8 | ||
|
|
493826973e | ||
|
|
1acc71aa4e | ||
|
|
bbab5f72ec | ||
|
|
58ff9e387a | ||
|
|
5a0d099984 | ||
|
|
05c95e04f7 | ||
|
|
88430b4be2 | ||
|
|
19adcfae4d | ||
|
|
7c4fe984ce | ||
|
|
4476e8311c | ||
|
|
2a3142273d | ||
|
|
bbcb889a49 | ||
|
|
c87f85815b | ||
|
|
48d0df17d0 | ||
|
|
01b243347f | ||
|
|
45a5cbf72f | ||
|
|
05efae1c58 | ||
|
|
c08fff4b44 | ||
|
|
13e910ea83 | ||
|
|
b308602098 | ||
|
|
560a044d8f | ||
|
|
619fbe4c3b | ||
|
|
1d83ad6cce | ||
|
|
5353ccd773 | ||
|
|
a8e23d2eb9 | ||
|
|
95d830fde0 | ||
|
|
c8a5d7d970 | ||
|
|
43481eb2cc | ||
|
|
b8bb665691 | ||
|
|
e6846b2730 | ||
|
|
31c1286a3c | ||
|
|
489f9e92b5 | ||
|
|
073809efac | ||
|
|
c9b8e2f3ce | ||
|
|
c6cb871355 | ||
|
|
1b0e5b3ed1 | ||
|
|
0f70c76312 | ||
|
|
e8c672bf4f | ||
|
|
7083ac61ff | ||
|
|
d256809120 | ||
|
|
26a19f82d2 | ||
|
|
128d3b5c91 | ||
|
|
c1a080d0ca | ||
|
|
0b1ce6c9a4 | ||
|
|
a6f04055c0 | ||
|
|
c3219e8b88 | ||
|
|
a35c863341 | ||
|
|
6f862a4c45 | ||
|
|
cf38210fd2 | ||
|
|
5c9d564339 | ||
|
|
031a61515b | ||
|
|
d3884fd53b | ||
|
|
c6eef3080e | ||
|
|
25be0a974d | ||
|
|
7ccd135e83 | ||
|
|
4fc1bbeb60 | ||
|
|
32a4d7172b | ||
|
|
aa25903c05 | ||
|
|
23ec1a455e | ||
|
|
e6ac2d049b | ||
|
|
084ae31816 | ||
|
|
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 |
3
.babelrc
3
.babelrc
@@ -2,5 +2,6 @@
|
|||||||
"stage": 0,
|
"stage": 0,
|
||||||
"loose": ["all"],
|
"loose": ["all"],
|
||||||
"blacklist": ["es6.tailCall"],
|
"blacklist": ["es6.tailCall"],
|
||||||
"optional": ["optimisation.flow.forOf"]
|
"optional": ["optimisation.flow.forOf"],
|
||||||
|
"plugins": ["./tools/build-plugins/protect"]
|
||||||
}
|
}
|
||||||
|
|||||||
11
.eslintrc
11
.eslintrc
@@ -3,18 +3,23 @@
|
|||||||
"rules": {
|
"rules": {
|
||||||
"strict": 0,
|
"strict": 0,
|
||||||
"no-underscore-dangle": 0,
|
"no-underscore-dangle": 0,
|
||||||
"no-unused-vars": 0,
|
|
||||||
"curly": 0,
|
"curly": 0,
|
||||||
"no-multi-spaces": 0,
|
"no-multi-spaces": 0,
|
||||||
"key-spacing": 0,
|
"key-spacing": 0,
|
||||||
"no-return-assign": 0,
|
"no-return-assign": 0,
|
||||||
"consistent-return": 0,
|
"consistent-return": 0,
|
||||||
"no-shadow": 0,
|
"no-shadow": 0,
|
||||||
"no-comma-dangle": 0,
|
"comma-dangle": 0,
|
||||||
"no-use-before-define": 0,
|
"no-use-before-define": 0,
|
||||||
"no-empty": 0,
|
"no-empty": 0,
|
||||||
"new-parens": 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,
|
||||||
|
"no-process-exit": 0
|
||||||
},
|
},
|
||||||
"env": {
|
"env": {
|
||||||
"node": true
|
"node": true
|
||||||
|
|||||||
14
.gitignore
vendored
14
.gitignore
vendored
@@ -8,10 +8,10 @@ test/core/tmp
|
|||||||
/browser.js
|
/browser.js
|
||||||
/browser-polyfill.js
|
/browser-polyfill.js
|
||||||
/runtime.js
|
/runtime.js
|
||||||
coverage
|
/coverage
|
||||||
dist
|
/dist
|
||||||
.package.json
|
/.package.json
|
||||||
packages/babel-runtime/core-js
|
/packages/babel-runtime/core-js
|
||||||
packages/babel-runtime/helpers/*.js
|
/packages/babel-runtime/helpers/*.js
|
||||||
packages/babel-runtime/regenerator/*.js
|
/packages/babel-runtime/regenerator/*.js
|
||||||
lib
|
/lib
|
||||||
|
|||||||
@@ -11,9 +11,4 @@ before_script: "npm install -g codeclimate-test-reporter"
|
|||||||
script: "make test-travis"
|
script: "make test-travis"
|
||||||
|
|
||||||
notifications:
|
notifications:
|
||||||
webhooks:
|
slack: babeljs:5Wy4QX13KVkGy9CnU0rmvgeK
|
||||||
urls:
|
|
||||||
- https://webhooks.gitter.im/e/acf1870e9d223c65e8d5
|
|
||||||
on_success: always
|
|
||||||
on_failure: always
|
|
||||||
on_start: false
|
|
||||||
|
|||||||
209
CHANGELOG.md
209
CHANGELOG.md
@@ -13,6 +13,215 @@ _Note: Gaps between patch versions are faulty/broken releases._
|
|||||||
|
|
||||||
See [CHANGELOG - 6to5](CHANGELOG-6to5.md) for the pre-4.0.0 version changelog.
|
See [CHANGELOG - 6to5](CHANGELOG-6to5.md) for the pre-4.0.0 version changelog.
|
||||||
|
|
||||||
|
## 5.6.12
|
||||||
|
|
||||||
|
* **Bug Fix**
|
||||||
|
* Fix finding parent for top-level shadowed functions.
|
||||||
|
|
||||||
|
## 5.6.11
|
||||||
|
|
||||||
|
** **Internal**
|
||||||
|
* Merge `es6.parameters.rest` and `es6.parameters.default` transformers. See commit [c0fd4c1f9e0b18231f585c4fa793e4cb0e01aed1](https://github.com/babel/babel/commit/c0fd4c1f9e0b18231f585c4fa793e4cb0e01aed1) for more info.
|
||||||
|
|
||||||
|
## 5.6.10
|
||||||
|
|
||||||
|
* **Bug Fix**
|
||||||
|
* Fix faulty internal require check.
|
||||||
|
* **Polish**
|
||||||
|
* Add support for trailing commas in arrow function parameter lists.
|
||||||
|
|
||||||
|
## 5.6.8
|
||||||
|
|
||||||
|
* **Bug Fix**
|
||||||
|
* Fix binary expressions colliding with unary expression operators in compact mode.
|
||||||
|
* Fix node properties being set to `null` when using computed properties.
|
||||||
|
|
||||||
|
## 5.6.7
|
||||||
|
|
||||||
|
* **Bug Fix**
|
||||||
|
* Fix hoisting of `ForXStatement` `left` `var`s when inserting a block scoping IIFE.
|
||||||
|
* **Polish**
|
||||||
|
* Combine all leading computed property initialisers into the root object in loose mode.
|
||||||
|
* **Internal**
|
||||||
|
* Deprecate returning of replacement strings from visitor methods.
|
||||||
|
|
||||||
|
## 5.6.6
|
||||||
|
|
||||||
|
* **Bug Fix**
|
||||||
|
* Fix weird parser bug where `void` type annotations were being parsed as keywords causing the tokeniser to lose track of context.
|
||||||
|
|
||||||
|
## 5.6.5
|
||||||
|
|
||||||
|
* **Bug Fix**
|
||||||
|
* Fix nested functions causing rest parameter optimisation to not properly detect when it should deopt on a reference.
|
||||||
|
* **Internal**
|
||||||
|
* Update Regenerator `0.8.31`.
|
||||||
|
|
||||||
|
## 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
|
## 5.4.2
|
||||||
|
|
||||||
* **Polish**
|
* **Polish**
|
||||||
|
|||||||
@@ -1,3 +1,7 @@
|
|||||||
|
# NOTE: BEFORE OPENING AN ISSUE PLEASE SEE THE [README](https://github.com/babel/babel#readme).
|
||||||
|
|
||||||
|
----
|
||||||
|
|
||||||
<p align="center">
|
<p align="center">
|
||||||
<strong><a href="#setup">Setup</a></strong>
|
<strong><a href="#setup">Setup</a></strong>
|
||||||
|
|
|
|
||||||
@@ -8,6 +12,8 @@
|
|||||||
<strong><a href="#dependencies">Dependencies</a></strong>
|
<strong><a href="#dependencies">Dependencies</a></strong>
|
||||||
|
|
|
|
||||||
<strong><a href="#code-standards">Code Standards</a></strong>
|
<strong><a href="#code-standards">Code Standards</a></strong>
|
||||||
|
|
|
||||||
|
<strong><a href="#internals">Internals</a></strong>
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
----
|
----
|
||||||
@@ -18,9 +24,11 @@ Contributions are always welcome, no matter how large or small. Before
|
|||||||
contributing, please read the
|
contributing, please read the
|
||||||
[code of conduct](https://github.com/babel/babel/blob/master/CODE_OF_CONDUCT.md).
|
[code of conduct](https://github.com/babel/babel/blob/master/CODE_OF_CONDUCT.md).
|
||||||
|
|
||||||
|
|
||||||
## Developing
|
## 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
|
#### Setup
|
||||||
|
|
||||||
```sh
|
```sh
|
||||||
@@ -79,7 +87,6 @@ your [`$PATH`](http://unix.stackexchange.com/questions/26047/how-to-correctly-ad
|
|||||||
* Ensure the test are passing (`make test`)
|
* Ensure the test are passing (`make test`)
|
||||||
* Create new pull request explaining your proposed change or reference an issue in your commit message
|
* Create new pull request explaining your proposed change or reference an issue in your commit message
|
||||||
|
|
||||||
|
|
||||||
#### Dependencies
|
#### Dependencies
|
||||||
|
|
||||||
+ [ast-types](http://ghub.io/ast-types) This is required to monkeypatch regenerators AST definitions. Could be improved in the future.
|
+ [ast-types](http://ghub.io/ast-types) This is required to monkeypatch regenerators AST definitions. Could be improved in the future.
|
||||||
@@ -106,8 +113,6 @@ your [`$PATH`](http://unix.stackexchange.com/questions/26047/how-to-correctly-ad
|
|||||||
|
|
||||||
+ [js-tokens](http://ghub.io/js-tokens) This is used to get tokens for syntax error highlighting.
|
+ [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.
|
+ [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.
|
+ [lodash](http://ghub.io/lodash) Used for various utilities.
|
||||||
@@ -167,3 +172,6 @@ your [`$PATH`](http://unix.stackexchange.com/questions/26047/how-to-correctly-ad
|
|||||||
* **Declaration**
|
* **Declaration**
|
||||||
* No unused variables
|
* No unused variables
|
||||||
* No pollution of global variables and prototypes
|
* No pollution of global variables and prototypes
|
||||||
|
|
||||||
|
#### Internals
|
||||||
|
Please see [`/doc`](/doc) for internals documentation relevant to developing babel.
|
||||||
|
|||||||
20
Makefile
20
Makefile
@@ -5,6 +5,7 @@ UGLIFY_CMD = node_modules/uglify-js/bin/uglifyjs
|
|||||||
#UGLIFY_CMD = node_modules/uglify-js/bin/uglifyjs --mangle sort
|
#UGLIFY_CMD = node_modules/uglify-js/bin/uglifyjs --mangle sort
|
||||||
MOCHA_CMD = node_modules/mocha/bin/_mocha
|
MOCHA_CMD = node_modules/mocha/bin/_mocha
|
||||||
BABEL_CMD = node_modules/babel/bin/babel
|
BABEL_CMD = node_modules/babel/bin/babel
|
||||||
|
BROWSERIFY_IGNORE = -i esprima-fb
|
||||||
|
|
||||||
export NODE_ENV = test
|
export NODE_ENV = test
|
||||||
|
|
||||||
@@ -14,7 +15,7 @@ build-core: clean-core
|
|||||||
node $(BABEL_CMD) src --out-dir lib --copy-files
|
node $(BABEL_CMD) src --out-dir lib --copy-files
|
||||||
|
|
||||||
build-core-test: clean-core
|
build-core-test: clean-core
|
||||||
node $(BABEL_CMD) src --out-dir lib --copy-files --auxiliary-comment "istanbul ignore next"
|
node $(BABEL_CMD) src --out-dir lib --copy-files --auxiliary-comment-before "istanbul ignore next"
|
||||||
|
|
||||||
watch-core: clean-core
|
watch-core: clean-core
|
||||||
node $(BABEL_CMD) src --out-dir lib --watch --copy-files
|
node $(BABEL_CMD) src --out-dir lib --watch --copy-files
|
||||||
@@ -22,6 +23,9 @@ watch-core: clean-core
|
|||||||
clean-core:
|
clean-core:
|
||||||
rm -rf lib
|
rm -rf lib
|
||||||
|
|
||||||
|
lint:
|
||||||
|
eslint src/babel packages/babel-cli/bin
|
||||||
|
|
||||||
build:
|
build:
|
||||||
mkdir -p dist
|
mkdir -p dist
|
||||||
make build-core
|
make build-core
|
||||||
@@ -31,8 +35,10 @@ build:
|
|||||||
node $(BROWSERIFY_CMD) -e lib/babel/polyfill.js >dist/polyfill.js
|
node $(BROWSERIFY_CMD) -e lib/babel/polyfill.js >dist/polyfill.js
|
||||||
node $(UGLIFY_CMD) dist/polyfill.js >dist/polyfill.min.js
|
node $(UGLIFY_CMD) dist/polyfill.js >dist/polyfill.min.js
|
||||||
|
|
||||||
node $(BROWSERIFY_CMD) lib/babel/api/browser.js -s babel >dist/babel.js
|
node $(BROWSERIFY_CMD) lib/babel/api/browser.js -s babel $(BROWSERIFY_IGNORE) >dist/browser.js
|
||||||
node $(UGLIFY_CMD) dist/babel.js >dist/babel.min.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 packages/babel-cli/bin/babel-external-helpers >dist/external-helpers.js
|
||||||
node $(UGLIFY_CMD) dist/external-helpers.js >dist/external-helpers.min.js
|
node $(UGLIFY_CMD) dist/external-helpers.js >dist/external-helpers.min.js
|
||||||
@@ -61,7 +67,7 @@ test-cov:
|
|||||||
test-parser:
|
test-parser:
|
||||||
node test/acorn/run.js
|
node test/acorn/run.js
|
||||||
|
|
||||||
test-travis: bootstrap build test
|
test-travis: bootstrap lint build test
|
||||||
|
|
||||||
test-browser:
|
test-browser:
|
||||||
mkdir -p dist
|
mkdir -p dist
|
||||||
@@ -73,7 +79,7 @@ test-browser:
|
|||||||
|
|
||||||
test -n "`which open`" && open test/browser.html
|
test -n "`which open`" && open test/browser.html
|
||||||
|
|
||||||
publish:
|
publish: lint
|
||||||
git pull --rebase
|
git pull --rebase
|
||||||
|
|
||||||
make test
|
make test
|
||||||
@@ -83,8 +89,8 @@ publish:
|
|||||||
|
|
||||||
make build
|
make build
|
||||||
|
|
||||||
cp dist/babel.js browser.js
|
cp dist/browser.js browser.js
|
||||||
cp dist/babel.min.js browser.min.js
|
cp dist/browser.min.js browser.min.js
|
||||||
|
|
||||||
cp dist/polyfill.js browser-polyfill.js
|
cp dist/polyfill.js browser-polyfill.js
|
||||||
cp dist/polyfill.min.js browser-polyfill.min.js
|
cp dist/polyfill.min.js browser-polyfill.min.js
|
||||||
|
|||||||
@@ -9,7 +9,11 @@
|
|||||||
</p>
|
</p>
|
||||||
|
|
||||||
<p align="center">
|
<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>
|
||||||
|
|
||||||
<p align="center">
|
<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.
|
||||||
38
package.json
38
package.json
@@ -1,12 +1,11 @@
|
|||||||
{
|
{
|
||||||
"name": "babel-core",
|
"name": "babel-core",
|
||||||
"description": "Turn ES6 code into readable vanilla ES5 with source maps",
|
"description": "A compiler for writing next generation JavaScript",
|
||||||
"version": "5.4.2",
|
"version": "5.6.12",
|
||||||
"author": "Sebastian McKenzie <sebmck@gmail.com>",
|
"author": "Sebastian McKenzie <sebmck@gmail.com>",
|
||||||
"homepage": "https://babeljs.io/",
|
"homepage": "https://babeljs.io/",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"repository": "babel/babel",
|
"repository": "babel/babel",
|
||||||
"main": "lib/babel/api/node.js",
|
|
||||||
"browser": {
|
"browser": {
|
||||||
"./lib/babel/api/register/node.js": "./lib/babel/api/register/browser.js"
|
"./lib/babel/api/register/node.js": "./lib/babel/api/register/browser.js"
|
||||||
},
|
},
|
||||||
@@ -30,27 +29,41 @@
|
|||||||
"dependencies": {
|
"dependencies": {
|
||||||
"acorn-jsx": "^1.0.0",
|
"acorn-jsx": "^1.0.0",
|
||||||
"ast-types": "~0.7.0",
|
"ast-types": "~0.7.0",
|
||||||
"bluebird": "^2.9.25",
|
"babel-plugin-constant-folding": "^1.0.1",
|
||||||
|
"babel-plugin-dead-code-elimination": "^1.0.2",
|
||||||
|
"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",
|
"chalk": "^1.0.0",
|
||||||
"convert-source-map": "^1.1.0",
|
"convert-source-map": "^1.1.0",
|
||||||
"core-js": "^0.9.0",
|
"core-js": "^0.9.0",
|
||||||
"debug": "^2.1.1",
|
"debug": "^2.1.1",
|
||||||
"detect-indent": "^3.0.0",
|
"detect-indent": "^3.0.0",
|
||||||
"esquery": "^0.4.0",
|
|
||||||
"estraverse": "^4.0.0",
|
"estraverse": "^4.0.0",
|
||||||
"esutils": "^2.0.0",
|
"esutils": "^2.0.0",
|
||||||
"fs-readdir-recursive": "^0.1.0",
|
"fs-readdir-recursive": "^0.1.0",
|
||||||
"globals": "^6.4.0",
|
"globals": "^6.4.0",
|
||||||
|
"home-or-tmp": "^1.0.0",
|
||||||
"is-integer": "^1.0.4",
|
"is-integer": "^1.0.4",
|
||||||
"js-tokens": "1.0.0",
|
"js-tokens": "1.0.1",
|
||||||
"leven": "^1.0.1",
|
|
||||||
"line-numbers": "0.2.0",
|
"line-numbers": "0.2.0",
|
||||||
"lodash": "^3.6.0",
|
"lodash": "^3.6.0",
|
||||||
"minimatch": "^2.0.3",
|
"minimatch": "^2.0.3",
|
||||||
"output-file-sync": "^1.1.0",
|
"output-file-sync": "^1.1.0",
|
||||||
|
"path-exists": "^1.0.0",
|
||||||
"path-is-absolute": "^1.0.0",
|
"path-is-absolute": "^1.0.0",
|
||||||
"private": "^0.1.6",
|
"private": "^0.1.6",
|
||||||
"regenerator": "^0.8.20",
|
"regenerator": "0.8.31",
|
||||||
"regexpu": "^1.1.2",
|
"regexpu": "^1.1.2",
|
||||||
"repeating": "^1.1.2",
|
"repeating": "^1.1.2",
|
||||||
"resolve": "^1.1.6",
|
"resolve": "^1.1.6",
|
||||||
@@ -60,15 +73,14 @@
|
|||||||
"source-map-support": "^0.2.10",
|
"source-map-support": "^0.2.10",
|
||||||
"strip-json-comments": "^1.0.2",
|
"strip-json-comments": "^1.0.2",
|
||||||
"to-fast-properties": "^1.0.0",
|
"to-fast-properties": "^1.0.0",
|
||||||
"trim-right": "^1.0.0",
|
"trim-right": "^1.0.0"
|
||||||
"user-home": "^1.1.1"
|
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"babel": "5.3.1",
|
"babel": "5.6.10",
|
||||||
"browserify": "^9.0.8",
|
"browserify": "^9.0.8",
|
||||||
"chai": "^2.2.0",
|
"chai": "^2.2.0",
|
||||||
"eslint": "^0.18.0",
|
"eslint": "^0.21.2",
|
||||||
"babel-eslint": "^2.0.0",
|
"babel-eslint": "^3.1.9",
|
||||||
"esvalid": "^1.1.0",
|
"esvalid": "^1.1.0",
|
||||||
"istanbul": "^0.3.5",
|
"istanbul": "^0.3.5",
|
||||||
"matcha": "^0.6.0",
|
"matcha": "^0.6.0",
|
||||||
|
|||||||
@@ -107,6 +107,7 @@ if (program.eval || program.print) {
|
|||||||
|
|
||||||
// add back on node and concat the sliced args
|
// add back on node and concat the sliced args
|
||||||
process.argv = ["node"].concat(args);
|
process.argv = ["node"].concat(args);
|
||||||
|
process.execArgv.unshift(__filename);
|
||||||
|
|
||||||
Module.runMain();
|
Module.runMain();
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -412,6 +412,7 @@ babelArgs.forEach(function(arg){
|
|||||||
case "--prof_auto":
|
case "--prof_auto":
|
||||||
case "--prof_lazy":
|
case "--prof_lazy":
|
||||||
case "--sliding_state_window":
|
case "--sliding_state_window":
|
||||||
|
case "--nolazy":
|
||||||
args.unshift(arg);
|
args.unshift(arg);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
|||||||
141
packages/babel-cli/bin/babel-plugin/index.js
Executable file
141
packages/babel-cli/bin/babel-plugin/index.js
Executable file
@@ -0,0 +1,141 @@
|
|||||||
|
#!/usr/bin/env node
|
||||||
|
|
||||||
|
var pathExists = require("path-exists");
|
||||||
|
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(path.join(__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 (!pathExists.sync("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,4 +1,5 @@
|
|||||||
var outputFileSync = require("output-file-sync");
|
var outputFileSync = require("output-file-sync");
|
||||||
|
var pathExists = require("path-exists");
|
||||||
var chokidar = require("chokidar");
|
var chokidar = require("chokidar");
|
||||||
var slash = require("slash");
|
var slash = require("slash");
|
||||||
var path = require("path");
|
var path = require("path");
|
||||||
@@ -6,7 +7,7 @@ var util = require("./util");
|
|||||||
var fs = require("fs");
|
var fs = require("fs");
|
||||||
var _ = require("lodash");
|
var _ = require("lodash");
|
||||||
|
|
||||||
module.exports = function (commander, filenames, opts) {
|
module.exports = function (commander, filenames) {
|
||||||
var write = function (src, relative) {
|
var write = function (src, relative) {
|
||||||
// remove extension and then append back on .js
|
// remove extension and then append back on .js
|
||||||
relative = relative.replace(/\.(\w*?)$/, "") + ".js";
|
relative = relative.replace(/\.(\w*?)$/, "") + ".js";
|
||||||
@@ -14,7 +15,8 @@ module.exports = function (commander, filenames, opts) {
|
|||||||
var dest = path.join(commander.outDir, relative);
|
var dest = path.join(commander.outDir, relative);
|
||||||
|
|
||||||
var data = util.compile(src, {
|
var data = util.compile(src, {
|
||||||
sourceFileName: slash(path.relative(dest + "/..", src))
|
sourceFileName: slash(path.relative(dest + "/..", src)),
|
||||||
|
sourceMapTarget: path.basename(relative)
|
||||||
});
|
});
|
||||||
if (data.ignored) return;
|
if (data.ignored) return;
|
||||||
|
|
||||||
@@ -40,7 +42,7 @@ module.exports = function (commander, filenames, opts) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
var handle = function (filename) {
|
var handle = function (filename) {
|
||||||
if (!fs.existsSync(filename)) return;
|
if (!pathExists.sync(filename)) return;
|
||||||
|
|
||||||
var stat = fs.statSync(filename);
|
var stat = fs.statSync(filename);
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
var convertSourceMap = require("convert-source-map");
|
var convertSourceMap = require("convert-source-map");
|
||||||
|
var pathExists = require("path-exists");
|
||||||
var sourceMap = require("source-map");
|
var sourceMap = require("source-map");
|
||||||
var chokidar = require("chokidar");
|
var chokidar = require("chokidar");
|
||||||
var slash = require("slash");
|
var slash = require("slash");
|
||||||
@@ -16,7 +17,8 @@ module.exports = function (commander, filenames, opts) {
|
|||||||
|
|
||||||
var buildResult = function () {
|
var buildResult = function () {
|
||||||
var map = new sourceMap.SourceMapGenerator({
|
var map = new sourceMap.SourceMapGenerator({
|
||||||
file: slash(commander.outFile || "stdout")
|
file: path.basename(commander.outFile) || "stdout",
|
||||||
|
sourceRoot: opts.sourceRoot
|
||||||
});
|
});
|
||||||
|
|
||||||
var code = "";
|
var code = "";
|
||||||
@@ -99,7 +101,7 @@ module.exports = function (commander, filenames, opts) {
|
|||||||
results = [];
|
results = [];
|
||||||
|
|
||||||
_.each(filenames, function (filename) {
|
_.each(filenames, function (filename) {
|
||||||
if (!fs.existsSync(filename)) return;
|
if (!pathExists.sync(filename)) return;
|
||||||
|
|
||||||
var stat = fs.statSync(filename);
|
var stat = fs.statSync(filename);
|
||||||
if (stat.isDirectory()) {
|
if (stat.isDirectory()) {
|
||||||
|
|||||||
@@ -1,14 +1,17 @@
|
|||||||
#!/usr/bin/env node
|
#!/usr/bin/env node
|
||||||
|
|
||||||
|
require("babel-core");
|
||||||
|
|
||||||
var moduleFormatters = require("babel-core/lib/babel/transformation/modules");
|
var moduleFormatters = require("babel-core/lib/babel/transformation/modules");
|
||||||
|
var pathExists = require("path-exists");
|
||||||
var commander = require("commander");
|
var commander = require("commander");
|
||||||
var transform = require("babel-core").transform;
|
var transform = require("babel-core").transform;
|
||||||
var kebabCase = require("lodash/string/kebabCase");
|
var kebabCase = require("lodash/string/kebabCase");
|
||||||
var options = require("babel-core").options;
|
var options = require("babel-core").options;
|
||||||
var util = require("babel-core").util;
|
var util = require("babel-core").util;
|
||||||
|
var uniq = require("lodash/array/uniq");
|
||||||
var each = require("lodash/collection/each");
|
var each = require("lodash/collection/each");
|
||||||
var keys = require("lodash/object/keys");
|
var keys = require("lodash/object/keys");
|
||||||
var fs = require("fs");
|
|
||||||
var glob = require("glob");
|
var glob = require("glob");
|
||||||
|
|
||||||
each(options, function (option, key) {
|
each(options, function (option, key) {
|
||||||
@@ -35,7 +38,7 @@ each(options, function (option, key) {
|
|||||||
if (option.description) desc.push(option.description);
|
if (option.description) desc.push(option.description);
|
||||||
|
|
||||||
commander.option(arg, desc.join(" "));
|
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("-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("-w, --watch", "Recompile files on changes");
|
||||||
@@ -51,7 +54,7 @@ commander.on("--help", function () {
|
|||||||
each(keys(obj).sort(), function (key) {
|
each(keys(obj).sort(), function (key) {
|
||||||
if (key[0] === "_") return;
|
if (key[0] === "_") return;
|
||||||
|
|
||||||
if (obj[key].optional) key = "[" + key + "]";
|
if (obj[key].metadata && obj[key].metadata.optional) key = "[" + key + "]";
|
||||||
|
|
||||||
console.log(" - " + key);
|
console.log(" - " + key);
|
||||||
});
|
});
|
||||||
@@ -79,11 +82,15 @@ if (commander.extensions) {
|
|||||||
var errors = [];
|
var errors = [];
|
||||||
|
|
||||||
var filenames = commander.args.reduce(function (globbed, input) {
|
var filenames = commander.args.reduce(function (globbed, input) {
|
||||||
return globbed.concat(glob.sync(input));
|
var files = glob.sync(input);
|
||||||
|
if (!files.length) files = [input];
|
||||||
|
return globbed.concat(files);
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
|
filenames = uniq(filenames);
|
||||||
|
|
||||||
each(filenames, function (filename) {
|
each(filenames, function (filename) {
|
||||||
if (!fs.existsSync(filename)) {
|
if (!pathExists.sync(filename)) {
|
||||||
errors.push(filename + " doesn't exist");
|
errors.push(filename + " doesn't exist");
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -116,11 +123,16 @@ if (errors.length) {
|
|||||||
var opts = exports.opts = {};
|
var opts = exports.opts = {};
|
||||||
|
|
||||||
each(options, function (opt, key) {
|
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.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;
|
var fn;
|
||||||
|
|
||||||
|
|||||||
@@ -1,10 +1,11 @@
|
|||||||
var readdir = require("fs-readdir-recursive");
|
var commander = require("commander");
|
||||||
var index = require("./index");
|
var readdir = require("fs-readdir-recursive");
|
||||||
var babel = require("babel-core");
|
var index = require("./index");
|
||||||
var util = require("babel-core").util;
|
var babel = require("babel-core");
|
||||||
var path = require("path");
|
var util = require("babel-core").util;
|
||||||
var fs = require("fs");
|
var path = require("path");
|
||||||
var _ = require("lodash");
|
var fs = require("fs");
|
||||||
|
var _ = require("lodash");
|
||||||
|
|
||||||
exports.readdirFilter = function (filename) {
|
exports.readdirFilter = function (filename) {
|
||||||
return readdir(filename).filter(function (filename) {
|
return readdir(filename).filter(function (filename) {
|
||||||
@@ -37,6 +38,15 @@ exports.transform = function (filename, code, opts) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
exports.compile = function (filename, opts) {
|
exports.compile = function (filename, opts) {
|
||||||
var code = fs.readFileSync(filename, "utf8");
|
try {
|
||||||
return exports.transform(filename, code, opts);
|
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,14 +1,14 @@
|
|||||||
{
|
{
|
||||||
"name": "babel",
|
"name": "babel",
|
||||||
"description": "Turn ES6 code into readable vanilla ES5 with source maps",
|
"description": "Turn ES6 code into readable vanilla ES5 with source maps",
|
||||||
"version": "5.4.1",
|
"version": "5.6.11",
|
||||||
"author": "Sebastian McKenzie <sebmck@gmail.com>",
|
"author": "Sebastian McKenzie <sebmck@gmail.com>",
|
||||||
"homepage": "https://babeljs.io/",
|
"homepage": "https://babeljs.io/",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"repository": "babel/babel",
|
"repository": "babel/babel",
|
||||||
"preferGlobal": true,
|
"preferGlobal": true,
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"babel-core": "^5.4.1",
|
"babel-core": "^5.6.11",
|
||||||
"chokidar": "^1.0.0",
|
"chokidar": "^1.0.0",
|
||||||
"commander": "^2.6.0",
|
"commander": "^2.6.0",
|
||||||
"convert-source-map": "^1.1.0",
|
"convert-source-map": "^1.1.0",
|
||||||
@@ -16,6 +16,7 @@
|
|||||||
"glob": "^5.0.5",
|
"glob": "^5.0.5",
|
||||||
"lodash": "^3.2.0",
|
"lodash": "^3.2.0",
|
||||||
"output-file-sync": "^1.1.0",
|
"output-file-sync": "^1.1.0",
|
||||||
|
"path-exists": "^1.0.0",
|
||||||
"path-is-absolute": "^1.0.0",
|
"path-is-absolute": "^1.0.0",
|
||||||
"source-map": "^0.4.0",
|
"source-map": "^0.4.0",
|
||||||
"slash": "^1.0.0"
|
"slash": "^1.0.0"
|
||||||
@@ -23,6 +24,7 @@
|
|||||||
"bin": {
|
"bin": {
|
||||||
"babel": "./bin/babel/index.js",
|
"babel": "./bin/babel/index.js",
|
||||||
"babel-node": "./bin/babel-node",
|
"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,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"name": "babel-runtime",
|
"name": "babel-runtime",
|
||||||
"description": "babel selfContained runtime",
|
"description": "babel selfContained runtime",
|
||||||
"version": "5.4.1",
|
"version": "5.6.11",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"repository": "babel/babel",
|
"repository": "babel/babel",
|
||||||
"author": "Sebastian McKenzie <sebmck@gmail.com>",
|
"author": "Sebastian McKenzie <sebmck@gmail.com>",
|
||||||
|
|||||||
@@ -75,7 +75,7 @@ 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"];
|
var paths = ["is-iterable", "get-iterator"];
|
||||||
|
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
Error.stackTraceLimit = Infinity;
|
||||||
var acorn = require("../src/index")
|
var acorn = require("../src/index")
|
||||||
|
|
||||||
var pp = acorn.Parser.prototype
|
var pp = acorn.Parser.prototype
|
||||||
@@ -41,8 +42,11 @@ pp.flow_parseDeclareFunction = function (node) {
|
|||||||
typeNode.rest = tmp.rest
|
typeNode.rest = tmp.rest
|
||||||
this.expect(tt.parenR)
|
this.expect(tt.parenR)
|
||||||
|
|
||||||
|
var oldInType = this.inType
|
||||||
|
this.inType = true
|
||||||
this.expect(tt.colon)
|
this.expect(tt.colon)
|
||||||
typeNode.returnType = this.flow_parseType()
|
typeNode.returnType = this.flow_parseType()
|
||||||
|
this.inType = oldInType
|
||||||
|
|
||||||
typeContainer.typeAnnotation = this.finishNode(typeNode, "FunctionTypeAnnotation")
|
typeContainer.typeAnnotation = this.finishNode(typeNode, "FunctionTypeAnnotation")
|
||||||
id.typeAnnotation = this.finishNode(typeContainer, "TypeAnnotation")
|
id.typeAnnotation = this.finishNode(typeContainer, "TypeAnnotation")
|
||||||
@@ -352,12 +356,6 @@ pp.flow_parseGenericType = function (start, id) {
|
|||||||
return this.finishNode(node, "GenericTypeAnnotation")
|
return this.finishNode(node, "GenericTypeAnnotation")
|
||||||
}
|
}
|
||||||
|
|
||||||
pp.flow_parseVoidType = function () {
|
|
||||||
var node = this.startNode()
|
|
||||||
this.expect(tt._void)
|
|
||||||
return this.finishNode(node, "VoidTypeAnnotation")
|
|
||||||
}
|
|
||||||
|
|
||||||
pp.flow_parseTypeofType = function () {
|
pp.flow_parseTypeofType = function () {
|
||||||
var node = this.startNode()
|
var node = this.startNode()
|
||||||
this.expect(tt._typeof)
|
this.expect(tt._typeof)
|
||||||
@@ -411,10 +409,16 @@ pp.flow_identToTypeAnnotation = function (start, node, id) {
|
|||||||
case "any":
|
case "any":
|
||||||
return this.finishNode(node, "AnyTypeAnnotation")
|
return this.finishNode(node, "AnyTypeAnnotation")
|
||||||
|
|
||||||
|
case "void":
|
||||||
|
return this.finishNode(node, "VoidTypeAnnotation")
|
||||||
|
|
||||||
case "bool":
|
case "bool":
|
||||||
case "boolean":
|
case "boolean":
|
||||||
return this.finishNode(node, "BooleanTypeAnnotation")
|
return this.finishNode(node, "BooleanTypeAnnotation")
|
||||||
|
|
||||||
|
case "mixed":
|
||||||
|
return this.finishNode(node, "MixedTypeAnnotation")
|
||||||
|
|
||||||
case "number":
|
case "number":
|
||||||
return this.finishNode(node, "NumberTypeAnnotation")
|
return this.finishNode(node, "NumberTypeAnnotation")
|
||||||
|
|
||||||
@@ -521,14 +525,8 @@ pp.flow_parsePrimaryType = function () {
|
|||||||
return this.finishNode(node, "StringLiteralTypeAnnotation")
|
return this.finishNode(node, "StringLiteralTypeAnnotation")
|
||||||
|
|
||||||
default:
|
default:
|
||||||
if (this.type.keyword) {
|
if (this.type.keyword === "typeof") {
|
||||||
switch (this.type.keyword) {
|
return this.flow_parseTypeofType()
|
||||||
case "void":
|
|
||||||
return this.flow_parseVoidType()
|
|
||||||
|
|
||||||
case "typeof":
|
|
||||||
return this.flow_parseTypeofType()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -691,6 +689,18 @@ acorn.plugins.flow = function (instance) {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
// don't consider `void` to be a keyword as then it'll use the void token type
|
||||||
|
// and set startExpr
|
||||||
|
instance.extend("isKeyword", function (inner) {
|
||||||
|
return function(name) {
|
||||||
|
if (this.inType && name === "void") {
|
||||||
|
return false
|
||||||
|
} else {
|
||||||
|
return inner.call(this, name)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
instance.extend("readToken", function (inner) {
|
instance.extend("readToken", function (inner) {
|
||||||
return function(code) {
|
return function(code) {
|
||||||
if (this.inType && (code === 62 || code === 60)) {
|
if (this.inType && (code === 62 || code === 60)) {
|
||||||
|
|||||||
@@ -29,14 +29,23 @@ const pp = Parser.prototype
|
|||||||
// strict mode, init properties are also not allowed to be repeated.
|
// strict mode, init properties are also not allowed to be repeated.
|
||||||
|
|
||||||
pp.checkPropClash = function(prop, propHash) {
|
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
|
let key = prop.key, name
|
||||||
switch (key.type) {
|
switch (key.type) {
|
||||||
case "Identifier": name = key.name; break
|
case "Identifier": name = key.name; break
|
||||||
case "Literal": name = String(key.value); break
|
case "Literal": name = String(key.value); break
|
||||||
default: return
|
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)) {
|
if (has(propHash, name)) {
|
||||||
other = propHash[name]
|
other = propHash[name]
|
||||||
let isGetSet = kind !== "init"
|
let isGetSet = kind !== "init"
|
||||||
@@ -260,8 +269,10 @@ pp.parseNoCallExpr = function() {
|
|||||||
pp.parseExprAtom = function(refShorthandDefaultPos) {
|
pp.parseExprAtom = function(refShorthandDefaultPos) {
|
||||||
let node, canBeArrow = this.potentialArrowAt == this.start
|
let node, canBeArrow = this.potentialArrowAt == this.start
|
||||||
switch (this.type) {
|
switch (this.type) {
|
||||||
case tt._this:
|
|
||||||
case tt._super:
|
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"
|
let type = this.type === tt._this ? "ThisExpression" : "Super"
|
||||||
node = this.startNode()
|
node = this.startNode()
|
||||||
this.next()
|
this.next()
|
||||||
@@ -274,7 +285,13 @@ pp.parseExprAtom = function(refShorthandDefaultPos) {
|
|||||||
if (this.options.features["es7.doExpressions"]) {
|
if (this.options.features["es7.doExpressions"]) {
|
||||||
let node = this.startNode()
|
let node = this.startNode()
|
||||||
this.next()
|
this.next()
|
||||||
|
var oldInFunction = this.inFunction
|
||||||
|
var oldLabels = this.labels
|
||||||
|
this.labels = []
|
||||||
|
this.inFunction = false
|
||||||
node.body = this.parseBlock()
|
node.body = this.parseBlock()
|
||||||
|
this.inFunction = oldInFunction
|
||||||
|
this.labels = oldLabels
|
||||||
return this.finishNode(node, "DoExpression")
|
return this.finishNode(node, "DoExpression")
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -286,7 +303,7 @@ pp.parseExprAtom = function(refShorthandDefaultPos) {
|
|||||||
//
|
//
|
||||||
if (this.options.features["es7.asyncFunctions"]) {
|
if (this.options.features["es7.asyncFunctions"]) {
|
||||||
// async functions!
|
// async functions!
|
||||||
if (id.name === "async") {
|
if (id.name === "async" && !this.canInsertSemicolon()) {
|
||||||
// arrow functions
|
// arrow functions
|
||||||
if (this.type === tt.parenL) {
|
if (this.type === tt.parenL) {
|
||||||
let expr = this.parseParenAndDistinguishExpression(start, true, true)
|
let expr = this.parseParenAndDistinguishExpression(start, true, true)
|
||||||
@@ -415,9 +432,18 @@ pp.parseParenAndDistinguishExpression = function(start, isAsync, canBeArrow) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
let innerStart = this.markPosition(), exprList = [], first = true
|
let innerStart = this.markPosition(), exprList = [], first = true
|
||||||
let refShorthandDefaultPos = {start: 0}, spreadStart, innerParenStart
|
let refShorthandDefaultPos = {start: 0}, spreadStart, innerParenStart, optionalCommaStart
|
||||||
while (this.type !== tt.parenR) {
|
while (this.type !== tt.parenR) {
|
||||||
first ? first = false : this.expect(tt.comma)
|
if (first) {
|
||||||
|
first = false;
|
||||||
|
} else {
|
||||||
|
this.expect(tt.comma)
|
||||||
|
if (this.type === tt.parenR && this.options.features["es7.trailingFunctionCommas"]) {
|
||||||
|
optionalCommaStart = this.start
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (this.type === tt.ellipsis) {
|
if (this.type === tt.ellipsis) {
|
||||||
let spreadNodeStart = this.markPosition()
|
let spreadNodeStart = this.markPosition()
|
||||||
spreadStart = this.start
|
spreadStart = this.start
|
||||||
@@ -445,6 +471,7 @@ pp.parseParenAndDistinguishExpression = function(start, isAsync, canBeArrow) {
|
|||||||
this.unexpected(this.lastTokStart)
|
this.unexpected(this.lastTokStart)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (optionalCommaStart) this.unexpected(optionalCommaStart)
|
||||||
if (spreadStart) this.unexpected(spreadStart)
|
if (spreadStart) this.unexpected(spreadStart)
|
||||||
if (refShorthandDefaultPos.start) this.unexpected(refShorthandDefaultPos.start)
|
if (refShorthandDefaultPos.start) this.unexpected(refShorthandDefaultPos.start)
|
||||||
|
|
||||||
@@ -507,7 +534,7 @@ pp.parseNew = function() {
|
|||||||
pp.parseTemplateElement = function() {
|
pp.parseTemplateElement = function() {
|
||||||
let elem = this.startNode()
|
let elem = this.startNode()
|
||||||
elem.value = {
|
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
|
cooked: this.value
|
||||||
}
|
}
|
||||||
this.next()
|
this.next()
|
||||||
@@ -603,6 +630,14 @@ pp.parseObjPropValue = function (prop, start, isGenerator, isAsync, isPattern, r
|
|||||||
prop.kind = prop.key.name
|
prop.kind = prop.key.name
|
||||||
this.parsePropertyName(prop)
|
this.parsePropertyName(prop)
|
||||||
prop.value = this.parseMethod(false)
|
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") {
|
} else if (this.options.ecmaVersion >= 6 && !prop.computed && prop.key.type === "Identifier") {
|
||||||
prop.kind = "init"
|
prop.kind = "init"
|
||||||
if (isPattern) {
|
if (isPattern) {
|
||||||
@@ -628,12 +663,12 @@ pp.parsePropertyName = function(prop) {
|
|||||||
prop.computed = true
|
prop.computed = true
|
||||||
prop.key = this.parseMaybeAssign()
|
prop.key = this.parseMaybeAssign()
|
||||||
this.expect(tt.bracketR)
|
this.expect(tt.bracketR)
|
||||||
return
|
return prop.key
|
||||||
} else {
|
} else {
|
||||||
prop.computed = false
|
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.
|
// Initialize empty function node.
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ var STATE_KEYS = [
|
|||||||
"lastTokEnd",
|
"lastTokEnd",
|
||||||
"lineStart",
|
"lineStart",
|
||||||
"startLoc",
|
"startLoc",
|
||||||
|
"curLine",
|
||||||
"endLoc",
|
"endLoc",
|
||||||
"start",
|
"start",
|
||||||
"pos",
|
"pos",
|
||||||
@@ -18,7 +19,11 @@ var STATE_KEYS = [
|
|||||||
"exprAllowed",
|
"exprAllowed",
|
||||||
"potentialArrowAt",
|
"potentialArrowAt",
|
||||||
"currLine",
|
"currLine",
|
||||||
"input"
|
"input",
|
||||||
|
"inType",
|
||||||
|
"inFunction",
|
||||||
|
"inGenerator",
|
||||||
|
"labels"
|
||||||
];
|
];
|
||||||
|
|
||||||
pp.getState = function () {
|
pp.getState = function () {
|
||||||
@@ -28,6 +33,7 @@ pp.getState = function () {
|
|||||||
state[key] = this[key]
|
state[key] = this[key]
|
||||||
}
|
}
|
||||||
state.context = this.context.slice()
|
state.context = this.context.slice()
|
||||||
|
state.labels = this.labels.slice()
|
||||||
return state
|
return state
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -35,6 +35,7 @@ pp.toAssignable = function(node, isBinding) {
|
|||||||
case "AssignmentExpression":
|
case "AssignmentExpression":
|
||||||
if (node.operator === "=") {
|
if (node.operator === "=") {
|
||||||
node.type = "AssignmentPattern"
|
node.type = "AssignmentPattern"
|
||||||
|
delete node.operator
|
||||||
} else {
|
} else {
|
||||||
this.raise(node.left.end, "Only '=' operator can be used for specifying default value.")
|
this.raise(node.left.end, "Only '=' operator can be used for specifying default value.")
|
||||||
}
|
}
|
||||||
@@ -171,7 +172,7 @@ pp.checkLVal = function(expr, isBinding, checkClashes) {
|
|||||||
break
|
break
|
||||||
|
|
||||||
case "ObjectPattern":
|
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];
|
var prop = expr.properties[i];
|
||||||
if (prop.type === "Property") prop = prop.value;
|
if (prop.type === "Property") prop = prop.value;
|
||||||
this.checkLVal(prop, isBinding, checkClashes)
|
this.checkLVal(prop, isBinding, checkClashes)
|
||||||
@@ -194,6 +195,10 @@ pp.checkLVal = function(expr, isBinding, checkClashes) {
|
|||||||
this.checkLVal(expr.argument, isBinding, checkClashes)
|
this.checkLVal(expr.argument, isBinding, checkClashes)
|
||||||
break
|
break
|
||||||
|
|
||||||
|
case "ParenthesizedExpression":
|
||||||
|
this.checkLVal(expr.expression, isBinding, checkClashes)
|
||||||
|
break
|
||||||
|
|
||||||
default:
|
default:
|
||||||
this.raise(expr.start, (isBinding ? "Binding" : "Assigning to") + " rvalue")
|
this.raise(expr.start, (isBinding ? "Binding" : "Assigning to") + " rvalue")
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,13 +1,14 @@
|
|||||||
import {reservedWords, keywords} from "./identifier"
|
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) {
|
export function Parser(options, input, startPos) {
|
||||||
this.options = options
|
this.options = options
|
||||||
this.loadPlugins(this.options.plugins)
|
|
||||||
this.sourceFile = this.options.sourceFile || null
|
this.sourceFile = this.options.sourceFile || null
|
||||||
this.isKeyword = keywords[this.options.ecmaVersion >= 6 ? 6 : 5]
|
this.isKeyword = keywords[this.options.ecmaVersion >= 6 ? 6 : 5]
|
||||||
this.isReservedWord = reservedWords[this.options.ecmaVersion]
|
this.isReservedWord = reservedWords[this.options.ecmaVersion]
|
||||||
this.input = input
|
this.input = input
|
||||||
|
this.loadPlugins(this.options.plugins)
|
||||||
|
|
||||||
// Set up token state
|
// Set up token state
|
||||||
|
|
||||||
|
|||||||
@@ -83,10 +83,13 @@ pp.parseStatement = function(declaration, topLevel) {
|
|||||||
return starttype === tt._import ? this.parseImport(node) : this.parseExport(node)
|
return starttype === tt._import ? this.parseImport(node) : this.parseExport(node)
|
||||||
|
|
||||||
case tt.name:
|
case tt.name:
|
||||||
if (this.options.features["es7.asyncFunctions"] && this.value === "async" && this.lookahead().type === tt._function) {
|
if (this.options.features["es7.asyncFunctions"] && this.value === "async") {
|
||||||
this.next();
|
var lookahead = this.lookahead();
|
||||||
this.expect(tt._function);
|
if (lookahead.type === tt._function && !this.canInsertSemicolon.call(lookahead)) {
|
||||||
return this.parseFunction(node, true, false, true);
|
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
|
// If the statement does not start with a statement keyword or a
|
||||||
@@ -168,12 +171,6 @@ pp.parseDoStatement = function(node) {
|
|||||||
this.labels.push(loopLabel)
|
this.labels.push(loopLabel)
|
||||||
node.body = this.parseStatement(false)
|
node.body = this.parseStatement(false)
|
||||||
this.labels.pop()
|
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)
|
this.expect(tt._while)
|
||||||
node.test = this.parseParenExpression()
|
node.test = this.parseParenExpression()
|
||||||
if (this.options.ecmaVersion >= 6)
|
if (this.options.ecmaVersion >= 6)
|
||||||
@@ -350,7 +347,14 @@ pp.parseLabeledStatement = function(node, maybeName, expr) {
|
|||||||
for (let i = 0; i < this.labels.length; ++i)
|
for (let i = 0; i < this.labels.length; ++i)
|
||||||
if (this.labels[i].name === maybeName) this.raise(expr.start, "Label '" + maybeName + "' is already declared")
|
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
|
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)
|
node.body = this.parseStatement(true)
|
||||||
this.labels.pop()
|
this.labels.pop()
|
||||||
node.label = expr
|
node.label = expr
|
||||||
@@ -469,6 +473,7 @@ pp.parseClass = function(node, isStatement) {
|
|||||||
this.parseClassId(node, isStatement)
|
this.parseClassId(node, isStatement)
|
||||||
this.parseClassSuper(node)
|
this.parseClassSuper(node)
|
||||||
var classBody = this.startNode()
|
var classBody = this.startNode()
|
||||||
|
let hadConstructor = false
|
||||||
classBody.body = []
|
classBody.body = []
|
||||||
this.expect(tt.braceL)
|
this.expect(tt.braceL)
|
||||||
let decorators = []
|
let decorators = []
|
||||||
@@ -483,16 +488,14 @@ pp.parseClass = function(node, isStatement) {
|
|||||||
method.decorators = decorators
|
method.decorators = decorators
|
||||||
decorators = []
|
decorators = []
|
||||||
}
|
}
|
||||||
|
let isMaybeStatic = this.type === tt.name && this.value === "static"
|
||||||
var isGenerator = this.eat(tt.star), isAsync = false
|
var isGenerator = this.eat(tt.star), isAsync = false
|
||||||
this.parsePropertyName(method)
|
this.parsePropertyName(method)
|
||||||
if (this.type !== tt.parenL && !method.computed && method.key.type === "Identifier" &&
|
method.static = isMaybeStatic && this.type !== tt.parenL
|
||||||
method.key.name === "static") {
|
if (method.static) {
|
||||||
if (isGenerator) this.unexpected()
|
if (isGenerator) this.unexpected()
|
||||||
method['static'] = true
|
|
||||||
isGenerator = this.eat(tt.star)
|
isGenerator = this.eat(tt.star)
|
||||||
this.parsePropertyName(method)
|
this.parsePropertyName(method)
|
||||||
} else {
|
|
||||||
method['static'] = false
|
|
||||||
}
|
}
|
||||||
if (!isGenerator && method.key.type === "Identifier" && !method.computed && this.isClassProperty()) {
|
if (!isGenerator && method.key.type === "Identifier" && !method.computed && this.isClassProperty()) {
|
||||||
classBody.body.push(this.parseClassProperty(method))
|
classBody.body.push(this.parseClassProperty(method))
|
||||||
@@ -503,23 +506,39 @@ pp.parseClass = function(node, isStatement) {
|
|||||||
isAsync = true
|
isAsync = true
|
||||||
this.parsePropertyName(method)
|
this.parsePropertyName(method)
|
||||||
}
|
}
|
||||||
|
let isGetSet = false
|
||||||
method.kind = "method"
|
method.kind = "method"
|
||||||
if (!method.computed && !isGenerator && !isAsync) {
|
if (!method.computed) {
|
||||||
if (method.key.type === "Identifier") {
|
let {key} = method
|
||||||
if (this.type !== tt.parenL && (method.key.name === "get" || method.key.name === "set")) {
|
if (!isAsync && !isGenerator && key.type === "Identifier" && this.type !== tt.parenL && (key.name === "get" || key.name === "set")) {
|
||||||
method.kind = method.key.name
|
isGetSet = true
|
||||||
this.parsePropertyName(method)
|
method.kind = key.name
|
||||||
} else if (!method['static'] && method.key.name === "constructor") {
|
key = this.parsePropertyName(method)
|
||||||
method.kind = "constructor"
|
}
|
||||||
}
|
if (!method.static && (key.type === "Identifier" && key.name === "constructor" ||
|
||||||
} else if (!method['static'] && method.key.type === "Literal" && method.key.value === "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"
|
method.kind = "constructor"
|
||||||
|
hadConstructor = true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (method.kind === "constructor" && method.decorators) {
|
if (method.kind === "constructor" && method.decorators) {
|
||||||
this.raise(method.start, "You can't attach decorators to a class constructor")
|
this.raise(method.start, "You can't attach decorators to a class constructor")
|
||||||
}
|
}
|
||||||
this.parseClassMethod(classBody, method, isGenerator, isAsync)
|
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 (decorators.length) {
|
if (decorators.length) {
|
||||||
this.raise(this.start, "You have trailing decorators with no method");
|
this.raise(this.start, "You have trailing decorators with no method");
|
||||||
@@ -574,7 +593,7 @@ pp.parseExport = function(node) {
|
|||||||
this.parseExportFrom(node)
|
this.parseExportFrom(node)
|
||||||
return this.finishNode(node, "ExportAllDeclaration")
|
return this.finishNode(node, "ExportAllDeclaration")
|
||||||
}
|
}
|
||||||
} else if (this.isExportDefaultSpecifier()) {
|
} else if (this.options.features["es7.exportExtensions"] && this.isExportDefaultSpecifier()) {
|
||||||
let specifier = this.startNode()
|
let specifier = this.startNode()
|
||||||
specifier.exported = this.parseIdent(true)
|
specifier.exported = this.parseIdent(true)
|
||||||
node.specifiers = [this.finishNode(specifier, "ExportDefaultSpecifier")]
|
node.specifiers = [this.finishNode(specifier, "ExportDefaultSpecifier")]
|
||||||
|
|||||||
@@ -25,6 +25,9 @@ export class Token {
|
|||||||
|
|
||||||
const pp = Parser.prototype
|
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
|
// Move to the next token
|
||||||
|
|
||||||
pp.next = function() {
|
pp.next = function() {
|
||||||
@@ -430,23 +433,30 @@ pp.readRegexp = function() {
|
|||||||
// negatives in unlikely scenarios. For example, `[\u{61}-b]` is a
|
// negatives in unlikely scenarios. For example, `[\u{61}-b]` is a
|
||||||
// perfectly valid pattern that is equivalent to `[a-b]`, but it would
|
// perfectly valid pattern that is equivalent to `[a-b]`, but it would
|
||||||
// be replaced by `[x-b]` which throws an error.
|
// 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.
|
// Detect invalid regular expressions.
|
||||||
try {
|
let value = null
|
||||||
new RegExp(tmp)
|
// Rhino's regular expression parser is flaky and throws uncatchable exceptions,
|
||||||
} catch (e) {
|
// so don't do detection if we are running under Rhino
|
||||||
if (e instanceof SyntaxError) this.raise(start, "Error parsing regular expression: " + e.message)
|
if (!isRhino) {
|
||||||
this.raise(e)
|
try {
|
||||||
}
|
new RegExp(tmp)
|
||||||
// Get a regular expression object for this pattern-flag pair, or `null` in
|
} catch (e) {
|
||||||
// case the current environment doesn't support the flags it uses.
|
if (e instanceof SyntaxError) this.raise(start, "Error parsing regular expression: " + e.message)
|
||||||
let value
|
this.raise(e)
|
||||||
try {
|
}
|
||||||
value = new RegExp(content, mods)
|
// Get a regular expression object for this pattern-flag pair, or `null` in
|
||||||
} catch (err) {
|
// case the current environment doesn't support the flags it uses.
|
||||||
value = null
|
try {
|
||||||
|
value = new RegExp(content, mods)
|
||||||
|
} catch (err) {}
|
||||||
}
|
}
|
||||||
return this.finishToken(tt.regexp, {pattern: content, flags: mods, value: value})
|
return this.finishToken(tt.regexp, {pattern: content, flags: mods, value: value})
|
||||||
}
|
}
|
||||||
@@ -514,10 +524,10 @@ pp.readCodePoint = function() {
|
|||||||
|
|
||||||
if (ch === 123) {
|
if (ch === 123) {
|
||||||
if (this.options.ecmaVersion < 6) this.unexpected()
|
if (this.options.ecmaVersion < 6) this.unexpected()
|
||||||
++this.pos
|
let codePos = ++this.pos
|
||||||
code = this.readHexChar(this.input.indexOf('}', this.pos) - this.pos)
|
code = this.readHexChar(this.input.indexOf('}', this.pos) - this.pos)
|
||||||
++this.pos
|
++this.pos
|
||||||
if (code > 0x10FFFF) this.unexpected()
|
if (code > 0x10FFFF) this.raise(codePos, "Code point out of bounds")
|
||||||
} else {
|
} else {
|
||||||
code = this.readHexChar(4)
|
code = this.readHexChar(4)
|
||||||
}
|
}
|
||||||
@@ -539,7 +549,7 @@ pp.readString = function(quote) {
|
|||||||
if (ch === quote) break
|
if (ch === quote) break
|
||||||
if (ch === 92) { // '\'
|
if (ch === 92) { // '\'
|
||||||
out += this.input.slice(chunkStart, this.pos)
|
out += this.input.slice(chunkStart, this.pos)
|
||||||
out += this.readEscapedChar()
|
out += this.readEscapedChar(false)
|
||||||
chunkStart = this.pos
|
chunkStart = this.pos
|
||||||
} else {
|
} else {
|
||||||
if (isNewLine(ch)) this.raise(this.start, "Unterminated string constant")
|
if (isNewLine(ch)) this.raise(this.start, "Unterminated string constant")
|
||||||
@@ -572,16 +582,20 @@ pp.readTmplToken = function() {
|
|||||||
}
|
}
|
||||||
if (ch === 92) { // '\'
|
if (ch === 92) { // '\'
|
||||||
out += this.input.slice(chunkStart, this.pos)
|
out += this.input.slice(chunkStart, this.pos)
|
||||||
out += this.readEscapedChar()
|
out += this.readEscapedChar(true)
|
||||||
chunkStart = this.pos
|
chunkStart = this.pos
|
||||||
} else if (isNewLine(ch)) {
|
} else if (isNewLine(ch)) {
|
||||||
out += this.input.slice(chunkStart, this.pos)
|
out += this.input.slice(chunkStart, this.pos)
|
||||||
++this.pos
|
++this.pos
|
||||||
if (ch === 13 && this.input.charCodeAt(this.pos) === 10) {
|
switch (ch) {
|
||||||
++this.pos
|
case 13:
|
||||||
out += "\n"
|
if (this.input.charCodeAt(this.pos) === 10) ++this.pos;
|
||||||
} else {
|
case 10:
|
||||||
out += String.fromCharCode(ch)
|
out += "\n";
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
out += String.fromCharCode(ch);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
if (this.options.locations) {
|
if (this.options.locations) {
|
||||||
++this.curLine
|
++this.curLine
|
||||||
@@ -596,42 +610,46 @@ pp.readTmplToken = function() {
|
|||||||
|
|
||||||
// Used to read escaped characters
|
// Used to read escaped characters
|
||||||
|
|
||||||
pp.readEscapedChar = function() {
|
pp.readEscapedChar = function(inTemplate) {
|
||||||
let ch = this.input.charCodeAt(++this.pos)
|
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
|
++this.pos
|
||||||
if (octal) {
|
switch (ch) {
|
||||||
if (this.strict) this.raise(this.pos - 2, "Octal literal in strict mode")
|
case 110: return "\n"; // 'n' -> '\n'
|
||||||
this.pos += octal.length - 1
|
case 114: return "\r"; // 'r' -> '\r'
|
||||||
return String.fromCharCode(parseInt(octal, 8))
|
case 120: return String.fromCharCode(this.readHexChar(2)); // 'x'
|
||||||
} else {
|
case 117: return codePointToString(this.readCodePoint()); // 'u'
|
||||||
switch (ch) {
|
case 116: return "\t"; // 't' -> '\t'
|
||||||
case 110: return "\n"; // 'n' -> '\n'
|
case 98: return "\b"; // 'b' -> '\b'
|
||||||
case 114: return "\r"; // 'r' -> '\r'
|
case 118: return "\u000b"; // 'v' -> '\u000b'
|
||||||
case 120: return String.fromCharCode(this.readHexChar(2)); // 'x'
|
case 102: return "\f"; // 'f' -> '\f'
|
||||||
case 117: return codePointToString(this.readCodePoint()); // 'u'
|
case 13: if (this.input.charCodeAt(this.pos) === 10) ++this.pos; // '\r\n'
|
||||||
case 116: return "\t"; // 't' -> '\t'
|
case 10: // ' \n'
|
||||||
case 98: return "\b"; // 'b' -> '\b'
|
if (this.options.locations) { this.lineStart = this.pos; ++this.curLine }
|
||||||
case 118: return "\u000b"; // 'v' -> '\u000b'
|
return ""
|
||||||
case 102: return "\f"; // 'f' -> '\f'
|
default:
|
||||||
case 48: return "\0"; // 0 -> '\0'
|
if (ch >= 48 && ch <= 55) {
|
||||||
case 13: if (this.input.charCodeAt(this.pos) === 10) ++this.pos; // '\r\n'
|
let octalStr = this.input.substr(this.pos - 1, 3).match(/^[0-7]+/)[0]
|
||||||
case 10: // ' \n'
|
let octal = parseInt(octalStr, 8)
|
||||||
if (this.options.locations) { this.lineStart = this.pos; ++this.curLine }
|
if (octal > 255) {
|
||||||
return ""
|
octalStr = octalStr.slice(0, -1)
|
||||||
default: return String.fromCharCode(ch)
|
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').
|
// Used to read character escape sequences ('\x', '\u', '\U').
|
||||||
|
|
||||||
pp.readHexChar = function(len) {
|
pp.readHexChar = function(len) {
|
||||||
|
let codePos = this.pos
|
||||||
let n = this.readInt(16, len)
|
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
|
return n
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -112,7 +112,7 @@ kw("case", beforeExpr)
|
|||||||
kw("catch")
|
kw("catch")
|
||||||
kw("continue")
|
kw("continue")
|
||||||
kw("debugger")
|
kw("debugger")
|
||||||
kw("default")
|
kw("default", beforeExpr)
|
||||||
kw("do", {isLoop: true})
|
kw("do", {isLoop: true})
|
||||||
kw("else", beforeExpr)
|
kw("else", beforeExpr)
|
||||||
kw("finally")
|
kw("finally")
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
|
/* eslint no-new-func: 0 */
|
||||||
|
|
||||||
require("./node");
|
require("./node");
|
||||||
var transform = module.exports = require("../transformation");
|
var transform = module.exports = require("../transformation");
|
||||||
|
|
||||||
|
|||||||
@@ -8,9 +8,10 @@ export { util, acorn, transform };
|
|||||||
export { pipeline } from "../transformation";
|
export { pipeline } from "../transformation";
|
||||||
export { canCompile } from "../util";
|
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 Transformer } from "../transformation/transformer";
|
||||||
export { default as TransformerPipeline } from "../transformation/transformer-pipeline";
|
export { default as Pipeline } from "../transformation/pipeline";
|
||||||
export { default as traverse } from "../traversal";
|
export { default as traverse } from "../traversal";
|
||||||
export { default as buildExternalHelpers } from "../tools/build-external-helpers";
|
export { default as buildExternalHelpers } from "../tools/build-external-helpers";
|
||||||
export { version } from "../../../package";
|
export { version } from "../../../package";
|
||||||
@@ -61,8 +62,8 @@ export function parse(code, opts = {}) {
|
|||||||
opts.sourceType = "module";
|
opts.sourceType = "module";
|
||||||
opts.ecmaVersion = Infinity;
|
opts.ecmaVersion = Infinity;
|
||||||
opts.plugins = {
|
opts.plugins = {
|
||||||
flow: true,
|
jsx: true,
|
||||||
jsx: true
|
flow: true
|
||||||
};
|
};
|
||||||
opts.features = {};
|
opts.features = {};
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
// required to safely use babel/register within a browserify codebase
|
// required to safely use babel/register within a browserify codebase
|
||||||
|
|
||||||
export default function () {};
|
export default function () {}
|
||||||
|
|
||||||
import "../../polyfill";
|
import "../../polyfill";
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
import path from "path";
|
import path from "path";
|
||||||
import os from "os";
|
|
||||||
import fs from "fs";
|
import fs from "fs";
|
||||||
import userHome from "user-home";
|
import homeOrTmp from "home-or-tmp";
|
||||||
|
import pathExists from "path-exists";
|
||||||
|
|
||||||
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 = {};
|
var data = {};
|
||||||
|
|
||||||
export function save() {
|
export function save() {
|
||||||
@@ -16,7 +16,7 @@ export function load() {
|
|||||||
process.on("exit", save);
|
process.on("exit", save);
|
||||||
process.nextTick(save);
|
process.nextTick(save);
|
||||||
|
|
||||||
if (!fs.existsSync(FILENAME)) return;
|
if (!pathExists.sync(FILENAME)) return;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
data = JSON.parse(fs.readFileSync(FILENAME));
|
data = JSON.parse(fs.readFileSync(FILENAME));
|
||||||
|
|||||||
@@ -1,12 +1,12 @@
|
|||||||
import sourceMapSupport from "source-map-support";
|
import sourceMapSupport from "source-map-support";
|
||||||
import * as registerCache from "./cache";
|
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 extend from "lodash/object/extend";
|
||||||
import * as babel from "../node";
|
import * as babel from "../node";
|
||||||
import each from "lodash/collection/each";
|
import each from "lodash/collection/each";
|
||||||
import * as util from "../../util";
|
import * as util from "../../util";
|
||||||
import fs from "fs";
|
import fs from "fs";
|
||||||
import slash from "slash";
|
import path from "path";
|
||||||
|
|
||||||
sourceMapSupport.install({
|
sourceMapSupport.install({
|
||||||
handleUncaughtExceptions: false,
|
handleUncaughtExceptions: false,
|
||||||
@@ -38,14 +38,20 @@ var only;
|
|||||||
var oldHandlers = {};
|
var oldHandlers = {};
|
||||||
var maps = {};
|
var maps = {};
|
||||||
|
|
||||||
|
var cwd = process.cwd();
|
||||||
|
|
||||||
|
var getRelativePath = function (filename){
|
||||||
|
return path.relative(cwd, filename);
|
||||||
|
};
|
||||||
|
|
||||||
var mtime = function (filename) {
|
var mtime = function (filename) {
|
||||||
return +fs.statSync(filename).mtime;
|
return +fs.statSync(filename).mtime;
|
||||||
};
|
};
|
||||||
|
|
||||||
var compile = function (filename) {
|
var compile = function (filename, opts = {}) {
|
||||||
var result;
|
var result;
|
||||||
|
|
||||||
var opts = extend({}, transformOpts);
|
opts = extend(opts, transformOpts);
|
||||||
|
|
||||||
// this will be done when the file is transformed anyway but we need all
|
// this will be done when the file is transformed anyway but we need all
|
||||||
// the options so we can generate the cache key
|
// the options so we can generate the cache key
|
||||||
@@ -53,6 +59,9 @@ var compile = function (filename) {
|
|||||||
|
|
||||||
var cacheKey = `${filename}:${JSON.stringify(opts)}:${babel.version}`;
|
var cacheKey = `${filename}:${JSON.stringify(opts)}:${babel.version}`;
|
||||||
|
|
||||||
|
var env = process.env.BABEL_ENV || process.env.NODE_ENV;
|
||||||
|
if (env) cacheKey += `:${env}`;
|
||||||
|
|
||||||
if (cache) {
|
if (cache) {
|
||||||
var cached = cache[cacheKey];
|
var cached = cache[cacheKey];
|
||||||
if (cached && cached.mtime === mtime(filename)) {
|
if (cached && cached.mtime === mtime(filename)) {
|
||||||
@@ -79,9 +88,9 @@ var compile = function (filename) {
|
|||||||
|
|
||||||
var shouldIgnore = function (filename) {
|
var shouldIgnore = function (filename) {
|
||||||
if (!ignore && !only) {
|
if (!ignore && !only) {
|
||||||
return /node_modules/.test(filename);
|
return getRelativePath(filename).split(path.sep).indexOf("node_modules") >= 0;
|
||||||
} else {
|
} else {
|
||||||
return util.shouldIgnore(filename, ignore || [], only || []);
|
return util.shouldIgnore(filename, ignore || [], only);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -95,7 +104,9 @@ if (process.env.running_under_istanbul) {
|
|||||||
fs.readFileSync = function (filename) {
|
fs.readFileSync = function (filename) {
|
||||||
if (istanbulMonkey[filename]) {
|
if (istanbulMonkey[filename]) {
|
||||||
delete istanbulMonkey[filename];
|
delete istanbulMonkey[filename];
|
||||||
var code = compile(filename);
|
var code = compile(filename, {
|
||||||
|
auxiliaryCommentBefore: "istanbul ignore next"
|
||||||
|
});
|
||||||
istanbulMonkey[filename] = true;
|
istanbulMonkey[filename] = true;
|
||||||
return code;
|
return code;
|
||||||
} else {
|
} else {
|
||||||
@@ -114,7 +125,7 @@ var normalLoader = function (m, filename) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
var registerExtension = function (ext) {
|
var registerExtension = function (ext) {
|
||||||
var old = oldHandlers[ext] || oldHandlers[".js"];
|
var old = oldHandlers[ext] || oldHandlers[".js"] || require.extensions[".js"];
|
||||||
|
|
||||||
var loader = normalLoader;
|
var loader = normalLoader;
|
||||||
if (process.env.running_under_istanbul) loader = istanbulLoader;
|
if (process.env.running_under_istanbul) loader = istanbulLoader;
|
||||||
@@ -161,4 +172,4 @@ export default function (opts = {}) {
|
|||||||
delete opts.only;
|
delete opts.only;
|
||||||
|
|
||||||
extend(transformOpts, opts);
|
extend(transformOpts, opts);
|
||||||
};
|
}
|
||||||
|
|||||||
@@ -54,9 +54,10 @@ export default class Buffer {
|
|||||||
this.space();
|
this.space();
|
||||||
}
|
}
|
||||||
|
|
||||||
space() {
|
space(force?) {
|
||||||
if (this.format.compact) return;
|
if (!force && this.format.compact) return;
|
||||||
if (this.buf && !this.isLast(" ") && !this.isLast("\n")) {
|
|
||||||
|
if (force || this.buf && !this.isLast(" ") && !this.isLast("\n")) {
|
||||||
this.push(" ");
|
this.push(" ");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -117,8 +118,9 @@ export default class Buffer {
|
|||||||
|
|
||||||
_removeSpacesAfterLastNewline() {
|
_removeSpacesAfterLastNewline() {
|
||||||
var lastNewlineIndex = this.buf.lastIndexOf("\n");
|
var lastNewlineIndex = this.buf.lastIndexOf("\n");
|
||||||
if (lastNewlineIndex === -1)
|
if (lastNewlineIndex === -1) {
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
var index = this.buf.length - 1;
|
var index = this.buf.length - 1;
|
||||||
while (index > lastNewlineIndex) {
|
while (index > lastNewlineIndex) {
|
||||||
@@ -154,8 +156,12 @@ export default class Buffer {
|
|||||||
this.buf += str;
|
this.buf += str;
|
||||||
}
|
}
|
||||||
|
|
||||||
endsWith(str) {
|
endsWith(str, buf = this.buf) {
|
||||||
return this.buf.slice(-str.length) === str;
|
if (str.length === 1) {
|
||||||
|
return buf[buf.length - 1] === str;
|
||||||
|
} else {
|
||||||
|
return buf.slice(-str.length) === str;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
isLast(cha) {
|
isLast(cha) {
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
export function File(node, print) {
|
export function File(node, print) {
|
||||||
print(node.program);
|
print.plain(node.program);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function Program(node, print) {
|
export function Program(node, print) {
|
||||||
@@ -17,3 +17,7 @@ export function BlockStatement(node, print) {
|
|||||||
this.rightBrace();
|
this.rightBrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function Noop() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,18 +1,18 @@
|
|||||||
export function ClassDeclaration(node, print) {
|
export function ClassDeclaration(node, print) {
|
||||||
print.list(node.decorators);
|
print.list(node.decorators, { separator: "" });
|
||||||
this.push("class");
|
this.push("class");
|
||||||
|
|
||||||
if (node.id) {
|
if (node.id) {
|
||||||
this.space();
|
this.push(" ");
|
||||||
print(node.id);
|
print.plain(node.id);
|
||||||
}
|
}
|
||||||
|
|
||||||
print(node.typeParameters);
|
print.plain(node.typeParameters);
|
||||||
|
|
||||||
if (node.superClass) {
|
if (node.superClass) {
|
||||||
this.push(" extends ");
|
this.push(" extends ");
|
||||||
print(node.superClass);
|
print.plain(node.superClass);
|
||||||
print(node.superTypeParameters);
|
print.plain(node.superTypeParameters);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (node.implements) {
|
if (node.implements) {
|
||||||
@@ -21,7 +21,7 @@ export function ClassDeclaration(node, print) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
this.space();
|
this.space();
|
||||||
print(node.body);
|
print.plain(node.body);
|
||||||
}
|
}
|
||||||
|
|
||||||
export { ClassDeclaration as ClassExpression };
|
export { ClassDeclaration as ClassExpression };
|
||||||
@@ -43,22 +43,22 @@ export function ClassBody(node, print) {
|
|||||||
|
|
||||||
|
|
||||||
export function ClassProperty(node, print) {
|
export function ClassProperty(node, print) {
|
||||||
print.list(node.decorators);
|
print.list(node.decorators, { separator: "" });
|
||||||
|
|
||||||
if (node.static) this.push("static ");
|
if (node.static) this.push("static ");
|
||||||
print(node.key);
|
print.plain(node.key);
|
||||||
print(node.typeAnnotation);
|
print.plain(node.typeAnnotation);
|
||||||
if (node.value) {
|
if (node.value) {
|
||||||
this.space();
|
this.space();
|
||||||
this.push("=");
|
this.push("=");
|
||||||
this.space();
|
this.space();
|
||||||
print(node.value);
|
print.plain(node.value);
|
||||||
}
|
}
|
||||||
this.semicolon();
|
this.semicolon();
|
||||||
}
|
}
|
||||||
|
|
||||||
export function MethodDefinition(node, print) {
|
export function MethodDefinition(node, print) {
|
||||||
print.list(node.decorators);
|
print.list(node.decorators, { separator: "" });
|
||||||
|
|
||||||
if (node.static) {
|
if (node.static) {
|
||||||
this.push("static ");
|
this.push("static ");
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
export function ComprehensionBlock(node, print) {
|
export function ComprehensionBlock(node, print) {
|
||||||
this.keyword("for");
|
this.keyword("for");
|
||||||
this.push("(");
|
this.push("(");
|
||||||
print(node.left);
|
print.plain(node.left);
|
||||||
this.push(" of ");
|
this.push(" of ");
|
||||||
print(node.right);
|
print.plain(node.right);
|
||||||
this.push(")");
|
this.push(")");
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -16,12 +16,12 @@ export function ComprehensionExpression(node, print) {
|
|||||||
if (node.filter) {
|
if (node.filter) {
|
||||||
this.keyword("if");
|
this.keyword("if");
|
||||||
this.push("(");
|
this.push("(");
|
||||||
print(node.filter);
|
print.plain(node.filter);
|
||||||
this.push(")");
|
this.push(")");
|
||||||
this.space();
|
this.space();
|
||||||
}
|
}
|
||||||
|
|
||||||
print(node.body);
|
print.plain(node.body);
|
||||||
|
|
||||||
this.push(node.generator ? ")" : "]");
|
this.push(node.generator ? ")" : "]");
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,55 +1,60 @@
|
|||||||
import isInteger from "is-integer";
|
|
||||||
import isNumber from "lodash/lang/isNumber";
|
import isNumber from "lodash/lang/isNumber";
|
||||||
import * as t from "../../types";
|
import * as t from "../../types";
|
||||||
|
|
||||||
export function UnaryExpression(node, print) {
|
export function UnaryExpression(node, print) {
|
||||||
var hasSpace = /[a-z]$/.test(node.operator);
|
var needsSpace = /[a-z]$/.test(node.operator);
|
||||||
var arg = node.argument;
|
var arg = node.argument;
|
||||||
|
|
||||||
if (t.isUpdateExpression(arg) || t.isUnaryExpression(arg)) {
|
if (t.isUpdateExpression(arg) || t.isUnaryExpression(arg)) {
|
||||||
hasSpace = true;
|
needsSpace = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (t.isUnaryExpression(arg) && arg.operator === "!") {
|
if (t.isUnaryExpression(arg) && arg.operator === "!") {
|
||||||
hasSpace = false;
|
needsSpace = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
this.push(node.operator);
|
this.push(node.operator);
|
||||||
if (hasSpace) this.push(" ");
|
if (needsSpace) this.push(" ");
|
||||||
print(node.argument);
|
print.plain(node.argument);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function DoExpression(node, print) {
|
export function DoExpression(node, print) {
|
||||||
this.push("do");
|
this.push("do");
|
||||||
this.space();
|
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) {
|
export function UpdateExpression(node, print) {
|
||||||
if (node.prefix) {
|
if (node.prefix) {
|
||||||
this.push(node.operator);
|
this.push(node.operator);
|
||||||
print(node.argument);
|
print.plain(node.argument);
|
||||||
} else {
|
} else {
|
||||||
print(node.argument);
|
print.plain(node.argument);
|
||||||
this.push(node.operator);
|
this.push(node.operator);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export function ConditionalExpression(node, print) {
|
export function ConditionalExpression(node, print) {
|
||||||
print(node.test);
|
print.plain(node.test);
|
||||||
this.space();
|
this.space();
|
||||||
this.push("?");
|
this.push("?");
|
||||||
this.space();
|
this.space();
|
||||||
print(node.consequent);
|
print.plain(node.consequent);
|
||||||
this.space();
|
this.space();
|
||||||
this.push(":");
|
this.push(":");
|
||||||
this.space();
|
this.space();
|
||||||
print(node.alternate);
|
print.plain(node.alternate);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function NewExpression(node, print) {
|
export function NewExpression(node, print) {
|
||||||
this.push("new ");
|
this.push("new ");
|
||||||
print(node.callee);
|
print.plain(node.callee);
|
||||||
this.push("(");
|
this.push("(");
|
||||||
print.list(node.arguments);
|
print.list(node.arguments);
|
||||||
this.push(")");
|
this.push(")");
|
||||||
@@ -69,27 +74,27 @@ export function Super() {
|
|||||||
|
|
||||||
export function Decorator(node, print) {
|
export function Decorator(node, print) {
|
||||||
this.push("@");
|
this.push("@");
|
||||||
print(node.expression);
|
print.plain(node.expression);
|
||||||
|
this.newline();
|
||||||
}
|
}
|
||||||
|
|
||||||
export function CallExpression(node, print) {
|
export function CallExpression(node, print) {
|
||||||
print(node.callee);
|
print.plain(node.callee);
|
||||||
|
|
||||||
this.push("(");
|
this.push("(");
|
||||||
|
|
||||||
var separator = ",";
|
var isPrettyCall = node._prettyCall && !this.format.retainLines && !this.format.compact;
|
||||||
|
|
||||||
if (node._prettyCall) {
|
var separator;
|
||||||
separator += "\n";
|
if (isPrettyCall) {
|
||||||
|
separator = ",\n";
|
||||||
this.newline();
|
this.newline();
|
||||||
this.indent();
|
this.indent();
|
||||||
} else {
|
|
||||||
separator += " ";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
print.list(node.arguments, { separator: separator });
|
print.list(node.arguments, { separator });
|
||||||
|
|
||||||
if (node._prettyCall) {
|
if (isPrettyCall) {
|
||||||
this.newline();
|
this.newline();
|
||||||
this.dedent();
|
this.dedent();
|
||||||
}
|
}
|
||||||
@@ -106,8 +111,8 @@ var buildYieldAwait = function (keyword) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (node.argument) {
|
if (node.argument) {
|
||||||
this.space();
|
this.push(" ");
|
||||||
print(node.argument);
|
print.plain(node.argument);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
@@ -120,36 +125,53 @@ export function EmptyStatement() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function ExpressionStatement(node, print) {
|
export function ExpressionStatement(node, print) {
|
||||||
print(node.expression);
|
print.plain(node.expression);
|
||||||
this.semicolon();
|
this.semicolon();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function AssignmentPattern(node, print) {
|
||||||
|
print.plain(node.left);
|
||||||
|
this.push(" = ");
|
||||||
|
print.plain(node.right);
|
||||||
|
}
|
||||||
|
|
||||||
export function AssignmentExpression(node, print) {
|
export function AssignmentExpression(node, print) {
|
||||||
// todo: add cases where the spaces can be dropped when in compact mode
|
// todo: add cases where the spaces can be dropped when in compact mode
|
||||||
print(node.left);
|
print.plain(node.left);
|
||||||
this.push(" ");
|
|
||||||
|
var spaces = node.operator === "in" || node.operator === "instanceof";
|
||||||
|
spaces = true; // todo: https://github.com/babel/babel/issues/1835
|
||||||
|
this.space(spaces);
|
||||||
|
|
||||||
this.push(node.operator);
|
this.push(node.operator);
|
||||||
this.push(" ");
|
|
||||||
print(node.right);
|
if (!spaces) {
|
||||||
|
// space is mandatory to avoid outputting <!--
|
||||||
|
// http://javascript.spec.whatwg.org/#comment-syntax
|
||||||
|
spaces = node.operator === "<" &&
|
||||||
|
t.isUnaryExpression(node.right, { prefix: true, operator: "!" }) &&
|
||||||
|
t.isUnaryExpression(node.right.argument, { prefix: true, operator: "--" });
|
||||||
|
}
|
||||||
|
|
||||||
|
this.space(spaces);
|
||||||
|
|
||||||
|
print.plain(node.right);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function BindExpression(node, print) {
|
export function BindExpression(node, print) {
|
||||||
print(node.object);
|
print.plain(node.object);
|
||||||
this.push("::");
|
this.push("::");
|
||||||
print(node.callee);
|
print.plain(node.callee);
|
||||||
}
|
}
|
||||||
|
|
||||||
export {
|
export {
|
||||||
AssignmentExpression as BinaryExpression,
|
AssignmentExpression as BinaryExpression,
|
||||||
AssignmentExpression as LogicalExpression,
|
AssignmentExpression as LogicalExpression
|
||||||
AssignmentExpression as AssignmentPattern
|
|
||||||
};
|
};
|
||||||
|
|
||||||
var SCIENTIFIC_NOTATION = /e/i;
|
|
||||||
|
|
||||||
export function MemberExpression(node, print) {
|
export function MemberExpression(node, print) {
|
||||||
var obj = node.object;
|
var obj = node.object;
|
||||||
print(obj);
|
print.plain(obj);
|
||||||
|
|
||||||
if (!node.computed && t.isMemberExpression(node.property)) {
|
if (!node.computed && t.isMemberExpression(node.property)) {
|
||||||
throw new TypeError("Got a MemberExpression for MemberExpression property");
|
throw new TypeError("Got a MemberExpression for MemberExpression property");
|
||||||
@@ -162,21 +184,16 @@ export function MemberExpression(node, print) {
|
|||||||
|
|
||||||
if (computed) {
|
if (computed) {
|
||||||
this.push("[");
|
this.push("[");
|
||||||
print(node.property);
|
print.plain(node.property);
|
||||||
this.push("]");
|
this.push("]");
|
||||||
} else {
|
} else {
|
||||||
// 5..toFixed(2);
|
|
||||||
if (t.isLiteral(obj) && isInteger(obj.value) && !SCIENTIFIC_NOTATION.test(obj.value.toString())) {
|
|
||||||
this.push(".");
|
|
||||||
}
|
|
||||||
|
|
||||||
this.push(".");
|
this.push(".");
|
||||||
print(node.property);
|
print.plain(node.property);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export function MetaProperty(node, print) {
|
export function MetaProperty(node, print) {
|
||||||
print(node.meta);
|
print.plain(node.meta);
|
||||||
this.push(".");
|
this.push(".");
|
||||||
print(node.property);
|
print.plain(node.property);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ export function AnyTypeAnnotation() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function ArrayTypeAnnotation(node, print) {
|
export function ArrayTypeAnnotation(node, print) {
|
||||||
print(node.elementType);
|
print.plain(node.elementType);
|
||||||
this.push("[");
|
this.push("[");
|
||||||
this.push("]");
|
this.push("]");
|
||||||
}
|
}
|
||||||
@@ -21,27 +21,27 @@ export function DeclareClass(node, print) {
|
|||||||
|
|
||||||
export function DeclareFunction(node, print) {
|
export function DeclareFunction(node, print) {
|
||||||
this.push("declare function ");
|
this.push("declare function ");
|
||||||
print(node.id);
|
print.plain(node.id);
|
||||||
print(node.id.typeAnnotation.typeAnnotation);
|
print.plain(node.id.typeAnnotation.typeAnnotation);
|
||||||
this.semicolon();
|
this.semicolon();
|
||||||
}
|
}
|
||||||
|
|
||||||
export function DeclareModule(node, print) {
|
export function DeclareModule(node, print) {
|
||||||
this.push("declare module ");
|
this.push("declare module ");
|
||||||
print(node.id);
|
print.plain(node.id);
|
||||||
this.space();
|
this.space();
|
||||||
print(node.body);
|
print.plain(node.body);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function DeclareVariable(node, print) {
|
export function DeclareVariable(node, print) {
|
||||||
this.push("declare var ");
|
this.push("declare var ");
|
||||||
print(node.id);
|
print.plain(node.id);
|
||||||
print(node.id.typeAnnotation);
|
print.plain(node.id.typeAnnotation);
|
||||||
this.semicolon();
|
this.semicolon();
|
||||||
}
|
}
|
||||||
|
|
||||||
export function FunctionTypeAnnotation(node, print, parent) {
|
export function FunctionTypeAnnotation(node, print, parent) {
|
||||||
print(node.typeParameters);
|
print.plain(node.typeParameters);
|
||||||
this.push("(");
|
this.push("(");
|
||||||
print.list(node.params);
|
print.list(node.params);
|
||||||
|
|
||||||
@@ -51,7 +51,7 @@ export function FunctionTypeAnnotation(node, print, parent) {
|
|||||||
this.space();
|
this.space();
|
||||||
}
|
}
|
||||||
this.push("...");
|
this.push("...");
|
||||||
print(node.rest);
|
print.plain(node.rest);
|
||||||
}
|
}
|
||||||
|
|
||||||
this.push(")");
|
this.push(")");
|
||||||
@@ -65,33 +65,33 @@ export function FunctionTypeAnnotation(node, print, parent) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
this.space();
|
this.space();
|
||||||
print(node.returnType);
|
print.plain(node.returnType);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function FunctionTypeParam(node, print) {
|
export function FunctionTypeParam(node, print) {
|
||||||
print(node.name);
|
print.plain(node.name);
|
||||||
if (node.optional) this.push("?");
|
if (node.optional) this.push("?");
|
||||||
this.push(":");
|
this.push(":");
|
||||||
this.space();
|
this.space();
|
||||||
print(node.typeAnnotation);
|
print.plain(node.typeAnnotation);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function InterfaceExtends(node, print) {
|
export function InterfaceExtends(node, print) {
|
||||||
print(node.id);
|
print.plain(node.id);
|
||||||
print(node.typeParameters);
|
print.plain(node.typeParameters);
|
||||||
}
|
}
|
||||||
|
|
||||||
export { InterfaceExtends as ClassImplements, InterfaceExtends as GenericTypeAnnotation };
|
export { InterfaceExtends as ClassImplements, InterfaceExtends as GenericTypeAnnotation };
|
||||||
|
|
||||||
export function _interfaceish(node, print) {
|
export function _interfaceish(node, print) {
|
||||||
print(node.id);
|
print.plain(node.id);
|
||||||
print(node.typeParameters);
|
print.plain(node.typeParameters);
|
||||||
if (node.extends.length) {
|
if (node.extends.length) {
|
||||||
this.push(" extends ");
|
this.push(" extends ");
|
||||||
print.join(node.extends, { separator: ", " });
|
print.join(node.extends, { separator: ", " });
|
||||||
}
|
}
|
||||||
this.space();
|
this.space();
|
||||||
print(node.body);
|
print.plain(node.body);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function InterfaceDeclaration(node, print) {
|
export function InterfaceDeclaration(node, print) {
|
||||||
@@ -103,9 +103,13 @@ export function IntersectionTypeAnnotation(node, print) {
|
|||||||
print.join(node.types, { separator: " & " });
|
print.join(node.types, { separator: " & " });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function MixedTypeAnnotation() {
|
||||||
|
this.push("mixed");
|
||||||
|
}
|
||||||
|
|
||||||
export function NullableTypeAnnotation(node, print) {
|
export function NullableTypeAnnotation(node, print) {
|
||||||
this.push("?");
|
this.push("?");
|
||||||
print(node.typeAnnotation);
|
print.plain(node.typeAnnotation);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function NumberTypeAnnotation() {
|
export function NumberTypeAnnotation() {
|
||||||
@@ -128,17 +132,17 @@ export function TupleTypeAnnotation(node, print) {
|
|||||||
|
|
||||||
export function TypeofTypeAnnotation(node, print) {
|
export function TypeofTypeAnnotation(node, print) {
|
||||||
this.push("typeof ");
|
this.push("typeof ");
|
||||||
print(node.argument);
|
print.plain(node.argument);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function TypeAlias(node, print) {
|
export function TypeAlias(node, print) {
|
||||||
this.push("type ");
|
this.push("type ");
|
||||||
print(node.id);
|
print.plain(node.id);
|
||||||
print(node.typeParameters);
|
print.plain(node.typeParameters);
|
||||||
this.space();
|
this.space();
|
||||||
this.push("=");
|
this.push("=");
|
||||||
this.space();
|
this.space();
|
||||||
print(node.right);
|
print.plain(node.right);
|
||||||
this.semicolon();
|
this.semicolon();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -146,7 +150,7 @@ export function TypeAnnotation(node, print) {
|
|||||||
this.push(":");
|
this.push(":");
|
||||||
this.space();
|
this.space();
|
||||||
if (node.optional) this.push("?");
|
if (node.optional) this.push("?");
|
||||||
print(node.typeAnnotation);
|
print.plain(node.typeAnnotation);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function TypeParameterInstantiation(node, print) {
|
export function TypeParameterInstantiation(node, print) {
|
||||||
@@ -183,37 +187,37 @@ export function ObjectTypeAnnotation(node, print) {
|
|||||||
|
|
||||||
export function ObjectTypeCallProperty(node, print) {
|
export function ObjectTypeCallProperty(node, print) {
|
||||||
if (node.static) this.push("static ");
|
if (node.static) this.push("static ");
|
||||||
print(node.value);
|
print.plain(node.value);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function ObjectTypeIndexer(node, print) {
|
export function ObjectTypeIndexer(node, print) {
|
||||||
if (node.static) this.push("static ");
|
if (node.static) this.push("static ");
|
||||||
this.push("[");
|
this.push("[");
|
||||||
print(node.id);
|
print.plain(node.id);
|
||||||
this.push(":");
|
this.push(":");
|
||||||
this.space();
|
this.space();
|
||||||
print(node.key);
|
print.plain(node.key);
|
||||||
this.push("]");
|
this.push("]");
|
||||||
this.push(":");
|
this.push(":");
|
||||||
this.space();
|
this.space();
|
||||||
print(node.value);
|
print.plain(node.value);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function ObjectTypeProperty(node, print) {
|
export function ObjectTypeProperty(node, print) {
|
||||||
if (node.static) this.push("static ");
|
if (node.static) this.push("static ");
|
||||||
print(node.key);
|
print.plain(node.key);
|
||||||
if (node.optional) this.push("?");
|
if (node.optional) this.push("?");
|
||||||
if (!t.isFunctionTypeAnnotation(node.value)) {
|
if (!t.isFunctionTypeAnnotation(node.value)) {
|
||||||
this.push(":");
|
this.push(":");
|
||||||
this.space();
|
this.space();
|
||||||
}
|
}
|
||||||
print(node.value);
|
print.plain(node.value);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function QualifiedTypeIdentifier(node, print) {
|
export function QualifiedTypeIdentifier(node, print) {
|
||||||
print(node.qualification);
|
print.plain(node.qualification);
|
||||||
this.push(".");
|
this.push(".");
|
||||||
print(node.id);
|
print.plain(node.id);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function UnionTypeAnnotation(node, print) {
|
export function UnionTypeAnnotation(node, print) {
|
||||||
@@ -222,8 +226,8 @@ export function UnionTypeAnnotation(node, print) {
|
|||||||
|
|
||||||
export function TypeCastExpression(node, print) {
|
export function TypeCastExpression(node, print) {
|
||||||
this.push("(");
|
this.push("(");
|
||||||
print(node.expression);
|
print.plain(node.expression);
|
||||||
print(node.typeAnnotation);
|
print.plain(node.typeAnnotation);
|
||||||
this.push(")");
|
this.push(")");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,11 +1,10 @@
|
|||||||
import each from "lodash/collection/each";
|
|
||||||
import * as t from "../../types";
|
import * as t from "../../types";
|
||||||
|
|
||||||
export function JSXAttribute(node, print) {
|
export function JSXAttribute(node, print) {
|
||||||
print(node.name);
|
print.plain(node.name);
|
||||||
if (node.value) {
|
if (node.value) {
|
||||||
this.push("=");
|
this.push("=");
|
||||||
print(node.value);
|
print.plain(node.value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -14,32 +13,32 @@ export function JSXIdentifier(node) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function JSXNamespacedName(node, print) {
|
export function JSXNamespacedName(node, print) {
|
||||||
print(node.namespace);
|
print.plain(node.namespace);
|
||||||
this.push(":");
|
this.push(":");
|
||||||
print(node.name);
|
print.plain(node.name);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function JSXMemberExpression(node, print) {
|
export function JSXMemberExpression(node, print) {
|
||||||
print(node.object);
|
print.plain(node.object);
|
||||||
this.push(".");
|
this.push(".");
|
||||||
print(node.property);
|
print.plain(node.property);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function JSXSpreadAttribute(node, print) {
|
export function JSXSpreadAttribute(node, print) {
|
||||||
this.push("{...");
|
this.push("{...");
|
||||||
print(node.argument);
|
print.plain(node.argument);
|
||||||
this.push("}");
|
this.push("}");
|
||||||
}
|
}
|
||||||
|
|
||||||
export function JSXExpressionContainer(node, print) {
|
export function JSXExpressionContainer(node, print) {
|
||||||
this.push("{");
|
this.push("{");
|
||||||
print(node.expression);
|
print.plain(node.expression);
|
||||||
this.push("}");
|
this.push("}");
|
||||||
}
|
}
|
||||||
|
|
||||||
export function JSXElement(node, print) {
|
export function JSXElement(node, print) {
|
||||||
var open = node.openingElement;
|
var open = node.openingElement;
|
||||||
print(open);
|
print.plain(open);
|
||||||
if (open.selfClosing) return;
|
if (open.selfClosing) return;
|
||||||
|
|
||||||
this.indent();
|
this.indent();
|
||||||
@@ -47,17 +46,17 @@ export function JSXElement(node, print) {
|
|||||||
if (t.isLiteral(child)) {
|
if (t.isLiteral(child)) {
|
||||||
this.push(child.value, true);
|
this.push(child.value, true);
|
||||||
} else {
|
} else {
|
||||||
print(child);
|
print.plain(child);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
this.dedent();
|
this.dedent();
|
||||||
|
|
||||||
print(node.closingElement);
|
print.plain(node.closingElement);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function JSXOpeningElement(node, print) {
|
export function JSXOpeningElement(node, print) {
|
||||||
this.push("<");
|
this.push("<");
|
||||||
print(node.name);
|
print.plain(node.name);
|
||||||
if (node.attributes.length > 0) {
|
if (node.attributes.length > 0) {
|
||||||
this.push(" ");
|
this.push(" ");
|
||||||
print.join(node.attributes, { separator: " " });
|
print.join(node.attributes, { separator: " " });
|
||||||
@@ -67,7 +66,7 @@ export function JSXOpeningElement(node, print) {
|
|||||||
|
|
||||||
export function JSXClosingElement(node, print) {
|
export function JSXClosingElement(node, print) {
|
||||||
this.push("</");
|
this.push("</");
|
||||||
print(node.name);
|
print.plain(node.name);
|
||||||
this.push(">");
|
this.push(">");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,18 +1,18 @@
|
|||||||
import * as t from "../../types";
|
import * as t from "../../types";
|
||||||
|
|
||||||
export function _params(node, print) {
|
export function _params(node, print) {
|
||||||
print(node.typeParameters);
|
print.plain(node.typeParameters);
|
||||||
this.push("(");
|
this.push("(");
|
||||||
print.list(node.params, {
|
print.list(node.params, {
|
||||||
iterator: (node) =>{
|
iterator: (node) =>{
|
||||||
if (node.optional) this.push("?");
|
if (node.optional) this.push("?");
|
||||||
print(node.typeAnnotation);
|
print.plain(node.typeAnnotation);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
this.push(")");
|
this.push(")");
|
||||||
|
|
||||||
if (node.returnType) {
|
if (node.returnType) {
|
||||||
print(node.returnType);
|
print.plain(node.returnType);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -35,15 +35,15 @@ export function _method(node, print) {
|
|||||||
|
|
||||||
if (node.computed) {
|
if (node.computed) {
|
||||||
this.push("[");
|
this.push("[");
|
||||||
print(key);
|
print.plain(key);
|
||||||
this.push("]");
|
this.push("]");
|
||||||
} else {
|
} else {
|
||||||
print(key);
|
print.plain(key);
|
||||||
}
|
}
|
||||||
|
|
||||||
this._params(value, print);
|
this._params(value, print);
|
||||||
this.push(" ");
|
this.space();
|
||||||
print(value.body);
|
print.plain(value.body);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function FunctionExpression(node, print) {
|
export function FunctionExpression(node, print) {
|
||||||
@@ -53,14 +53,14 @@ export function FunctionExpression(node, print) {
|
|||||||
|
|
||||||
if (node.id) {
|
if (node.id) {
|
||||||
this.push(" ");
|
this.push(" ");
|
||||||
print(node.id);
|
print.plain(node.id);
|
||||||
} else {
|
} else {
|
||||||
this.space();
|
this.space();
|
||||||
}
|
}
|
||||||
|
|
||||||
this._params(node, print);
|
this._params(node, print);
|
||||||
this.space();
|
this.space();
|
||||||
print(node.body);
|
print.plain(node.body);
|
||||||
}
|
}
|
||||||
|
|
||||||
export { FunctionExpression as FunctionDeclaration };
|
export { FunctionExpression as FunctionDeclaration };
|
||||||
@@ -69,7 +69,7 @@ export function ArrowFunctionExpression(node, print) {
|
|||||||
if (node.async) this.push("async ");
|
if (node.async) this.push("async ");
|
||||||
|
|
||||||
if (node.params.length === 1 && t.isIdentifier(node.params[0])) {
|
if (node.params.length === 1 && t.isIdentifier(node.params[0])) {
|
||||||
print(node.params[0]);
|
print.plain(node.params[0]);
|
||||||
} else {
|
} else {
|
||||||
this._params(node, print);
|
this._params(node, print);
|
||||||
}
|
}
|
||||||
@@ -82,7 +82,7 @@ export function ArrowFunctionExpression(node, print) {
|
|||||||
this.push("(");
|
this.push("(");
|
||||||
}
|
}
|
||||||
|
|
||||||
print(node.body);
|
print.plain(node.body);
|
||||||
|
|
||||||
if (bodyNeedsParens) {
|
if (bodyNeedsParens) {
|
||||||
this.push(")");
|
this.push(")");
|
||||||
|
|||||||
@@ -1,43 +1,42 @@
|
|||||||
import each from "lodash/collection/each";
|
|
||||||
import * as t from "../../types";
|
import * as t from "../../types";
|
||||||
|
|
||||||
export function ImportSpecifier(node, print) {
|
export function ImportSpecifier(node, print) {
|
||||||
print(node.imported);
|
print.plain(node.imported);
|
||||||
if (node.local && node.local.name !== node.imported.name) {
|
if (node.local && node.local.name !== node.imported.name) {
|
||||||
this.push(" as ");
|
this.push(" as ");
|
||||||
print(node.local);
|
print.plain(node.local);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export function ImportDefaultSpecifier(node, print) {
|
export function ImportDefaultSpecifier(node, print) {
|
||||||
print(node.local);
|
print.plain(node.local);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function ExportDefaultSpecifier(node, print) {
|
export function ExportDefaultSpecifier(node, print) {
|
||||||
print(node.exported);
|
print.plain(node.exported);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function ExportSpecifier(node, print) {
|
export function ExportSpecifier(node, print) {
|
||||||
print(node.local);
|
print.plain(node.local);
|
||||||
if (node.exported && node.local.name !== node.exported.name) {
|
if (node.exported && node.local.name !== node.exported.name) {
|
||||||
this.push(" as ");
|
this.push(" as ");
|
||||||
print(node.exported);
|
print.plain(node.exported);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export function ExportNamespaceSpecifier(node, print) {
|
export function ExportNamespaceSpecifier(node, print) {
|
||||||
this.push("* as ");
|
this.push("* as ");
|
||||||
print(node.exported);
|
print.plain(node.exported);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function ExportAllDeclaration(node, print) {
|
export function ExportAllDeclaration(node, print) {
|
||||||
this.push("export *");
|
this.push("export *");
|
||||||
if (node.exported) {
|
if (node.exported) {
|
||||||
this.push(" as ");
|
this.push(" as ");
|
||||||
print(node.exported);
|
print.plain(node.exported);
|
||||||
}
|
}
|
||||||
this.push(" from ");
|
this.push(" from ");
|
||||||
print(node.source);
|
print.plain(node.source);
|
||||||
this.semicolon();
|
this.semicolon();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -56,14 +55,14 @@ function ExportDeclaration(node, print) {
|
|||||||
|
|
||||||
if (node.declaration) {
|
if (node.declaration) {
|
||||||
var declar = node.declaration;
|
var declar = node.declaration;
|
||||||
print(declar);
|
print.plain(declar);
|
||||||
if (t.isStatement(declar) || t.isFunction(declar) || t.isClass(declar)) return;
|
if (t.isStatement(declar) || t.isFunction(declar) || t.isClass(declar)) return;
|
||||||
} else {
|
} else {
|
||||||
var first = specifiers[0];
|
var first = specifiers[0];
|
||||||
var hasSpecial = false;
|
var hasSpecial = false;
|
||||||
if (t.isExportDefaultSpecifier(first) || t.isExportNamespaceSpecifier(first)) {
|
if (t.isExportDefaultSpecifier(first) || t.isExportNamespaceSpecifier(first)) {
|
||||||
hasSpecial = true;
|
hasSpecial = true;
|
||||||
print(specifiers.shift());
|
print.plain(specifiers.shift());
|
||||||
if (specifiers.length) {
|
if (specifiers.length) {
|
||||||
this.push(", ");
|
this.push(", ");
|
||||||
}
|
}
|
||||||
@@ -81,7 +80,7 @@ function ExportDeclaration(node, print) {
|
|||||||
|
|
||||||
if (node.source) {
|
if (node.source) {
|
||||||
this.push(" from ");
|
this.push(" from ");
|
||||||
print(node.source);
|
print.plain(node.source);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -99,7 +98,7 @@ export function ImportDeclaration(node, print) {
|
|||||||
if (specfiers && specfiers.length) {
|
if (specfiers && specfiers.length) {
|
||||||
var first = node.specifiers[0];
|
var first = node.specifiers[0];
|
||||||
if (t.isImportDefaultSpecifier(first) || t.isImportNamespaceSpecifier(first)) {
|
if (t.isImportDefaultSpecifier(first) || t.isImportNamespaceSpecifier(first)) {
|
||||||
print(node.specifiers.shift());
|
print.plain(node.specifiers.shift());
|
||||||
if (node.specifiers.length) {
|
if (node.specifiers.length) {
|
||||||
this.push(", ");
|
this.push(", ");
|
||||||
}
|
}
|
||||||
@@ -107,20 +106,20 @@ export function ImportDeclaration(node, print) {
|
|||||||
|
|
||||||
if (node.specifiers.length) {
|
if (node.specifiers.length) {
|
||||||
this.push("{");
|
this.push("{");
|
||||||
this.space()
|
this.space();
|
||||||
print.join(node.specifiers, { separator: ", " });
|
print.join(node.specifiers, { separator: ", " });
|
||||||
this.space()
|
this.space();
|
||||||
this.push("}");
|
this.push("}");
|
||||||
}
|
}
|
||||||
|
|
||||||
this.push(" from ");
|
this.push(" from ");
|
||||||
}
|
}
|
||||||
|
|
||||||
print(node.source);
|
print.plain(node.source);
|
||||||
this.semicolon();
|
this.semicolon();
|
||||||
}
|
}
|
||||||
|
|
||||||
export function ImportNamespaceSpecifier(node, print) {
|
export function ImportNamespaceSpecifier(node, print) {
|
||||||
this.push("* as ");
|
this.push("* as ");
|
||||||
print(node.local);
|
print.plain(node.local);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ import * as t from "../../types";
|
|||||||
export function WithStatement(node, print) {
|
export function WithStatement(node, print) {
|
||||||
this.keyword("with");
|
this.keyword("with");
|
||||||
this.push("(");
|
this.push("(");
|
||||||
print(node.object);
|
print.plain(node.object);
|
||||||
this.push(")");
|
this.push(")");
|
||||||
print.block(node.body);
|
print.block(node.body);
|
||||||
}
|
}
|
||||||
@@ -12,7 +12,7 @@ export function WithStatement(node, print) {
|
|||||||
export function IfStatement(node, print) {
|
export function IfStatement(node, print) {
|
||||||
this.keyword("if");
|
this.keyword("if");
|
||||||
this.push("(");
|
this.push("(");
|
||||||
print(node.test);
|
print.plain(node.test);
|
||||||
this.push(")");
|
this.push(")");
|
||||||
this.space();
|
this.space();
|
||||||
|
|
||||||
@@ -29,18 +29,18 @@ export function ForStatement(node, print) {
|
|||||||
this.keyword("for");
|
this.keyword("for");
|
||||||
this.push("(");
|
this.push("(");
|
||||||
|
|
||||||
print(node.init);
|
print.plain(node.init);
|
||||||
this.push(";");
|
this.push(";");
|
||||||
|
|
||||||
if (node.test) {
|
if (node.test) {
|
||||||
this.push(" ");
|
this.space();
|
||||||
print(node.test);
|
print.plain(node.test);
|
||||||
}
|
}
|
||||||
this.push(";");
|
this.push(";");
|
||||||
|
|
||||||
if (node.update) {
|
if (node.update) {
|
||||||
this.push(" ");
|
this.space();
|
||||||
print(node.update);
|
print.plain(node.update);
|
||||||
}
|
}
|
||||||
|
|
||||||
this.push(")");
|
this.push(")");
|
||||||
@@ -50,7 +50,7 @@ export function ForStatement(node, print) {
|
|||||||
export function WhileStatement(node, print) {
|
export function WhileStatement(node, print) {
|
||||||
this.keyword("while");
|
this.keyword("while");
|
||||||
this.push("(");
|
this.push("(");
|
||||||
print(node.test);
|
print.plain(node.test);
|
||||||
this.push(")");
|
this.push(")");
|
||||||
print.block(node.body);
|
print.block(node.body);
|
||||||
}
|
}
|
||||||
@@ -59,9 +59,9 @@ var buildForXStatement = function (op) {
|
|||||||
return function (node, print) {
|
return function (node, print) {
|
||||||
this.keyword("for");
|
this.keyword("for");
|
||||||
this.push("(");
|
this.push("(");
|
||||||
print(node.left);
|
print.plain(node.left);
|
||||||
this.push(` ${op} `);
|
this.push(` ${op} `);
|
||||||
print(node.right);
|
print.plain(node.right);
|
||||||
this.push(")");
|
this.push(")");
|
||||||
print.block(node.body);
|
print.block(node.body);
|
||||||
};
|
};
|
||||||
@@ -72,11 +72,11 @@ export var ForOfStatement = buildForXStatement("of");
|
|||||||
|
|
||||||
export function DoWhileStatement(node, print) {
|
export function DoWhileStatement(node, print) {
|
||||||
this.push("do ");
|
this.push("do ");
|
||||||
print(node.body);
|
print.plain(node.body);
|
||||||
this.space();
|
this.space();
|
||||||
this.keyword("while");
|
this.keyword("while");
|
||||||
this.push("(");
|
this.push("(");
|
||||||
print(node.test);
|
print.plain(node.test);
|
||||||
this.push(");");
|
this.push(");");
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -87,7 +87,7 @@ var buildLabelStatement = function (prefix, key) {
|
|||||||
var label = node[key || "label"];
|
var label = node[key || "label"];
|
||||||
if (label) {
|
if (label) {
|
||||||
this.push(" ");
|
this.push(" ");
|
||||||
print(label);
|
print.plain(label);
|
||||||
}
|
}
|
||||||
|
|
||||||
this.semicolon();
|
this.semicolon();
|
||||||
@@ -99,50 +99,50 @@ export var ReturnStatement = buildLabelStatement("return", "argument");
|
|||||||
export var BreakStatement = buildLabelStatement("break");
|
export var BreakStatement = buildLabelStatement("break");
|
||||||
|
|
||||||
export function LabeledStatement(node, print) {
|
export function LabeledStatement(node, print) {
|
||||||
print(node.label);
|
print.plain(node.label);
|
||||||
this.push(": ");
|
this.push(": ");
|
||||||
print(node.body);
|
print.plain(node.body);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function TryStatement(node, print) {
|
export function TryStatement(node, print) {
|
||||||
this.keyword("try");
|
this.keyword("try");
|
||||||
print(node.block);
|
print.plain(node.block);
|
||||||
this.space();
|
this.space();
|
||||||
|
|
||||||
// Esprima bug puts the catch clause in a `handlers` array.
|
// Esprima bug puts the catch clause in a `handlers` array.
|
||||||
// see https://code.google.com/p/esprima/issues/detail?id=433
|
// see https://code.google.com/p/esprima/issues/detail?id=433
|
||||||
// We run into this from regenerator generated ast.
|
// We run into this from regenerator generated ast.
|
||||||
if (node.handlers) {
|
if (node.handlers) {
|
||||||
print(node.handlers[0]);
|
print.plain(node.handlers[0]);
|
||||||
} else {
|
} else {
|
||||||
print(node.handler);
|
print.plain(node.handler);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (node.finalizer) {
|
if (node.finalizer) {
|
||||||
this.space();
|
this.space();
|
||||||
this.push("finally ");
|
this.push("finally ");
|
||||||
print(node.finalizer);
|
print.plain(node.finalizer);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export function CatchClause(node, print) {
|
export function CatchClause(node, print) {
|
||||||
this.keyword("catch");
|
this.keyword("catch");
|
||||||
this.push("(");
|
this.push("(");
|
||||||
print(node.param);
|
print.plain(node.param);
|
||||||
this.push(") ");
|
this.push(") ");
|
||||||
print(node.body);
|
print.plain(node.body);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function ThrowStatement(node, print) {
|
export function ThrowStatement(node, print) {
|
||||||
this.push("throw ");
|
this.push("throw ");
|
||||||
print(node.argument);
|
print.plain(node.argument);
|
||||||
this.semicolon();
|
this.semicolon();
|
||||||
}
|
}
|
||||||
|
|
||||||
export function SwitchStatement(node, print) {
|
export function SwitchStatement(node, print) {
|
||||||
this.keyword("switch");
|
this.keyword("switch");
|
||||||
this.push("(");
|
this.push("(");
|
||||||
print(node.discriminant);
|
print.plain(node.discriminant);
|
||||||
this.push(")");
|
this.push(")");
|
||||||
this.space();
|
this.space();
|
||||||
this.push("{");
|
this.push("{");
|
||||||
@@ -160,7 +160,7 @@ export function SwitchStatement(node, print) {
|
|||||||
export function SwitchCase(node, print) {
|
export function SwitchCase(node, print) {
|
||||||
if (node.test) {
|
if (node.test) {
|
||||||
this.push("case ");
|
this.push("case ");
|
||||||
print(node.test);
|
print.plain(node.test);
|
||||||
this.push(":");
|
this.push(":");
|
||||||
} else {
|
} else {
|
||||||
this.push("default:");
|
this.push("default:");
|
||||||
@@ -190,16 +190,29 @@ export function VariableDeclaration(node, print, parent) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var sep = ",";
|
//
|
||||||
|
// use a pretty separator when we aren't in compact mode, have initializers and don't have retainLines on
|
||||||
|
// this will format declarations like:
|
||||||
|
//
|
||||||
|
// var foo = "bar", bar = "foo";
|
||||||
|
//
|
||||||
|
// into
|
||||||
|
//
|
||||||
|
// var foo = "bar",
|
||||||
|
// bar = "foo";
|
||||||
|
//
|
||||||
|
|
||||||
|
var sep;
|
||||||
if (!this.format.compact && !this.format.concise && hasInits && !this.format.retainLines) {
|
if (!this.format.compact && !this.format.concise && hasInits && !this.format.retainLines) {
|
||||||
sep += `\n${repeating(" ", node.kind.length + 1)}`;
|
sep = `,\n${repeating(" ", node.kind.length + 1)}`;
|
||||||
} else {
|
|
||||||
sep += " ";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
|
||||||
print.list(node.declarations, { separator: sep });
|
print.list(node.declarations, { separator: sep });
|
||||||
|
|
||||||
if (t.isFor(parent)) {
|
if (t.isFor(parent)) {
|
||||||
|
// don't give semicolons to these nodes since they'll be inserted in the parent generator
|
||||||
if (parent.left === node || parent.init === node) return;
|
if (parent.left === node || parent.init === node) return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -207,12 +220,12 @@ export function VariableDeclaration(node, print, parent) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function VariableDeclarator(node, print) {
|
export function VariableDeclarator(node, print) {
|
||||||
print(node.id);
|
print.plain(node.id);
|
||||||
print(node.id.typeAnnotation);
|
print.plain(node.id.typeAnnotation);
|
||||||
if (node.init) {
|
if (node.init) {
|
||||||
this.space();
|
this.space();
|
||||||
this.push("=");
|
this.push("=");
|
||||||
this.space();
|
this.space();
|
||||||
print(node.init);
|
print.plain(node.init);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,8 +1,6 @@
|
|||||||
import each from "lodash/collection/each";
|
|
||||||
|
|
||||||
export function TaggedTemplateExpression(node, print) {
|
export function TaggedTemplateExpression(node, print) {
|
||||||
print(node.tag);
|
print.plain(node.tag);
|
||||||
print(node.quasi);
|
print.plain(node.quasi);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function TemplateElement(node) {
|
export function TemplateElement(node) {
|
||||||
@@ -16,11 +14,11 @@ export function TemplateLiteral(node, print) {
|
|||||||
var len = quasis.length;
|
var len = quasis.length;
|
||||||
|
|
||||||
for (var i = 0; i < len; i++) {
|
for (var i = 0; i < len; i++) {
|
||||||
print(quasis[i]);
|
print.plain(quasis[i]);
|
||||||
|
|
||||||
if (i + 1 < len) {
|
if (i + 1 < len) {
|
||||||
this.push("${ ");
|
this.push("${ ");
|
||||||
print(node.expressions[i]);
|
print.plain(node.expressions[i]);
|
||||||
this.push(" }");
|
this.push(" }");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,6 @@
|
|||||||
import each from "lodash/collection/each";
|
/* eslint quotes: 0 */
|
||||||
|
|
||||||
|
import isInteger from "is-integer";
|
||||||
import * as t from "../../types";
|
import * as t from "../../types";
|
||||||
|
|
||||||
export function Identifier(node) {
|
export function Identifier(node) {
|
||||||
@@ -7,7 +9,7 @@ export function Identifier(node) {
|
|||||||
|
|
||||||
export function RestElement(node, print) {
|
export function RestElement(node, print) {
|
||||||
this.push("...");
|
this.push("...");
|
||||||
print(node.argument);
|
print.plain(node.argument);
|
||||||
}
|
}
|
||||||
|
|
||||||
export { RestElement as SpreadElement, RestElement as SpreadProperty };
|
export { RestElement as SpreadElement, RestElement as SpreadProperty };
|
||||||
@@ -31,15 +33,23 @@ export function ObjectExpression(node, print) {
|
|||||||
export { ObjectExpression as ObjectPattern };
|
export { ObjectExpression as ObjectPattern };
|
||||||
|
|
||||||
export function Property(node, print) {
|
export function Property(node, print) {
|
||||||
|
print.list(node.decorators, { separator: "" });
|
||||||
|
|
||||||
if (node.method || node.kind === "get" || node.kind === "set") {
|
if (node.method || node.kind === "get" || node.kind === "set") {
|
||||||
this._method(node, print);
|
this._method(node, print);
|
||||||
} else {
|
} else {
|
||||||
if (node.computed) {
|
if (node.computed) {
|
||||||
this.push("[");
|
this.push("[");
|
||||||
print(node.key);
|
print.plain(node.key);
|
||||||
this.push("]");
|
this.push("]");
|
||||||
} else {
|
} else {
|
||||||
print(node.key);
|
// 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!
|
// shorthand!
|
||||||
if (node.shorthand &&
|
if (node.shorthand &&
|
||||||
@@ -52,7 +62,7 @@ export function Property(node, print) {
|
|||||||
|
|
||||||
this.push(":");
|
this.push(":");
|
||||||
this.space();
|
this.space();
|
||||||
print(node.value);
|
print.plain(node.value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -72,8 +82,8 @@ export function ArrayExpression(node, print) {
|
|||||||
// both (all) of the holes.
|
// both (all) of the holes.
|
||||||
this.push(",");
|
this.push(",");
|
||||||
} else {
|
} else {
|
||||||
if (i > 0) this.push(" ");
|
if (i > 0) this.space();
|
||||||
print(elem);
|
print.plain(elem);
|
||||||
if (i < len - 1) this.push(",");
|
if (i < len - 1) this.push(",");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -83,14 +93,29 @@ export function ArrayExpression(node, print) {
|
|||||||
|
|
||||||
export { ArrayExpression as ArrayPattern };
|
export { ArrayExpression as ArrayPattern };
|
||||||
|
|
||||||
export function Literal(node) {
|
const SCIENTIFIC_NOTATION = /e/i;
|
||||||
|
|
||||||
|
export function Literal(node, print, parent) {
|
||||||
var val = node.value;
|
var val = node.value;
|
||||||
var type = typeof val;
|
var type = typeof val;
|
||||||
|
|
||||||
if (type === "string") {
|
if (type === "string") {
|
||||||
this._stringLiteral(val);
|
this._stringLiteral(val);
|
||||||
} else if (type === "number") {
|
} 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") {
|
} else if (type === "boolean") {
|
||||||
this.push(val ? "true" : "false");
|
this.push(val ? "true" : "false");
|
||||||
} else if (node.regex) {
|
} else if (node.regex) {
|
||||||
@@ -109,9 +134,16 @@ export function _stringLiteral(val) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
if (this.format.quotes === "single") {
|
if (this.format.quotes === "single") {
|
||||||
|
// remove double quotes
|
||||||
val = val.slice(1, -1);
|
val = val.slice(1, -1);
|
||||||
|
|
||||||
|
// unescape double quotes
|
||||||
val = val.replace(/\\"/g, '"');
|
val = val.replace(/\\"/g, '"');
|
||||||
|
|
||||||
|
// escape single quotes
|
||||||
val = val.replace(/'/g, "\\'");
|
val = val.replace(/'/g, "\\'");
|
||||||
|
|
||||||
|
// add single quotes
|
||||||
val = `'${val}'`;
|
val = `'${val}'`;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
import detectIndent from "detect-indent";
|
import detectIndent from "detect-indent";
|
||||||
import Whitespace from "./whitespace";
|
import Whitespace from "./whitespace";
|
||||||
|
import NodePrinter from "./node/printer";
|
||||||
import repeating from "repeating";
|
import repeating from "repeating";
|
||||||
import SourceMap from "./source-map";
|
import SourceMap from "./source-map";
|
||||||
import Position from "./position";
|
import Position from "./position";
|
||||||
@@ -20,7 +21,7 @@ class CodeGenerator {
|
|||||||
this.opts = opts;
|
this.opts = opts;
|
||||||
this.ast = ast;
|
this.ast = ast;
|
||||||
|
|
||||||
this.whitespace = new Whitespace(this.tokens, this.comments, this.format);
|
this.whitespace = new Whitespace(this.tokens);
|
||||||
this.position = new Position;
|
this.position = new Position;
|
||||||
this.map = new SourceMap(this.position, opts, code);
|
this.map = new SourceMap(this.position, opts, code);
|
||||||
this.buffer = new Buffer(this.position, this.format);
|
this.buffer = new Buffer(this.position, this.format);
|
||||||
@@ -67,7 +68,6 @@ class CodeGenerator {
|
|||||||
for (var i = 0; i < tokens.length; i++) {
|
for (var i = 0; i < tokens.length; i++) {
|
||||||
var token = tokens[i];
|
var token = tokens[i];
|
||||||
if (token.type.label !== "string") continue;
|
if (token.type.label !== "string") continue;
|
||||||
if (checked >= 3) continue;
|
|
||||||
|
|
||||||
var raw = code.slice(token.start, token.end);
|
var raw = code.slice(token.start, token.end);
|
||||||
if (raw[0] === "'") {
|
if (raw[0] === "'") {
|
||||||
@@ -77,6 +77,7 @@ class CodeGenerator {
|
|||||||
}
|
}
|
||||||
|
|
||||||
checked++;
|
checked++;
|
||||||
|
if (checked >= 3) break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (occurences.single > occurences.double) {
|
if (occurences.single > occurences.double) {
|
||||||
@@ -120,40 +121,14 @@ class CodeGenerator {
|
|||||||
}
|
}
|
||||||
|
|
||||||
buildPrint(parent) {
|
buildPrint(parent) {
|
||||||
var print = (node, opts) => {
|
return new NodePrinter(this, parent);
|
||||||
return this.print(node, parent, opts);
|
|
||||||
};
|
|
||||||
|
|
||||||
print.sequence = (nodes, opts = {}) => {
|
|
||||||
opts.statement = true;
|
|
||||||
return this.printJoin(print, nodes, opts);
|
|
||||||
};
|
|
||||||
|
|
||||||
print.join = (nodes, opts) => {
|
|
||||||
return this.printJoin(print, nodes, opts);
|
|
||||||
};
|
|
||||||
|
|
||||||
print.list = function (items, opts = {}) {
|
|
||||||
if (opts.separator == null) opts.separator = ", ";
|
|
||||||
print.join(items, opts);
|
|
||||||
};
|
|
||||||
|
|
||||||
print.block = (node) => {
|
|
||||||
return this.printBlock(print, node);
|
|
||||||
};
|
|
||||||
|
|
||||||
print.indentOnComments = (node) => {
|
|
||||||
return this.printAndIndentOnComments(print, node);
|
|
||||||
};
|
|
||||||
|
|
||||||
return print;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
catchUp(node, parent) {
|
catchUp(node, parent, leftParenPrinted) {
|
||||||
// catch up to this nodes newline if we're behind
|
// catch up to this nodes newline if we're behind
|
||||||
if (node.loc && this.format.retainLines && this.buffer.buf) {
|
if (node.loc && this.format.retainLines && this.buffer.buf) {
|
||||||
var needsParens = false;
|
var needsParens = false;
|
||||||
if (parent && this.position.line < node.loc.start.line && t.isTerminatorless(parent)) {
|
if (!leftParenPrinted && parent && this.position.line < node.loc.start.line && t.isTerminatorless(parent)) {
|
||||||
needsParens = true;
|
needsParens = true;
|
||||||
this._push("(");
|
this._push("(");
|
||||||
}
|
}
|
||||||
@@ -165,6 +140,36 @@ class CodeGenerator {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_printNewline(leading, node, parent, opts) {
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
print(node, parent, opts = {}) {
|
print(node, parent, opts = {}) {
|
||||||
if (!node) return;
|
if (!node) return;
|
||||||
|
|
||||||
@@ -177,36 +182,6 @@ class CodeGenerator {
|
|||||||
this.format.concise = true;
|
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]) {
|
if (this[node.type]) {
|
||||||
var needsNoLineTermParens = n.needsParensNoLineTerminator(node, parent);
|
var needsNoLineTermParens = n.needsParensNoLineTerminator(node, parent);
|
||||||
var needsParens = needsNoLineTermParens || n.needsParens(node, parent);
|
var needsParens = needsNoLineTermParens || n.needsParens(node, parent);
|
||||||
@@ -216,9 +191,9 @@ class CodeGenerator {
|
|||||||
|
|
||||||
this.printLeadingComments(node, parent);
|
this.printLeadingComments(node, parent);
|
||||||
|
|
||||||
var needsParensFromCatchup = this.catchUp(node, parent);
|
var needsParensFromCatchup = this.catchUp(node, parent, needsParens);
|
||||||
|
|
||||||
newline(true);
|
this._printNewline(true, node, parent, opts);
|
||||||
|
|
||||||
if (opts.before) opts.before();
|
if (opts.before) opts.before();
|
||||||
this.map.mark(node, "start");
|
this.map.mark(node, "start");
|
||||||
@@ -236,7 +211,7 @@ class CodeGenerator {
|
|||||||
|
|
||||||
this.format.concise = oldConcise;
|
this.format.concise = oldConcise;
|
||||||
|
|
||||||
newline(false);
|
this._printNewline(false, node, parent, opts);
|
||||||
|
|
||||||
this.printTrailingComments(node, parent);
|
this.printTrailingComments(node, parent);
|
||||||
} else {
|
} else {
|
||||||
@@ -251,21 +226,23 @@ class CodeGenerator {
|
|||||||
|
|
||||||
if (opts.indent) this.indent();
|
if (opts.indent) this.indent();
|
||||||
|
|
||||||
|
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++) {
|
for (var i = 0; i < nodes.length; i++) {
|
||||||
var node = nodes[i];
|
var node = nodes[i];
|
||||||
print(node, {
|
print.plain(node, 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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (opts.indent) this.dedent();
|
if (opts.indent) this.dedent();
|
||||||
@@ -274,7 +251,7 @@ class CodeGenerator {
|
|||||||
printAndIndentOnComments(print, node) {
|
printAndIndentOnComments(print, node) {
|
||||||
var indent = !!node.leadingComments;
|
var indent = !!node.leadingComments;
|
||||||
if (indent) this.indent();
|
if (indent) this.indent();
|
||||||
print(node);
|
print.plain(node);
|
||||||
if (indent) this.dedent();
|
if (indent) this.dedent();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -283,13 +260,13 @@ class CodeGenerator {
|
|||||||
this.semicolon();
|
this.semicolon();
|
||||||
} else {
|
} else {
|
||||||
this.push(" ");
|
this.push(" ");
|
||||||
print(node);
|
print.plain(node);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
generateComment(comment) {
|
generateComment(comment) {
|
||||||
var val = comment.value;
|
var val = comment.value;
|
||||||
if (comment.type === "Line") {
|
if (comment.type === "CommentLine") {
|
||||||
val = `//${val}`;
|
val = `//${val}`;
|
||||||
} else {
|
} else {
|
||||||
val = `/*${val}*/`;
|
val = `/*${val}*/`;
|
||||||
@@ -317,7 +294,7 @@ class CodeGenerator {
|
|||||||
nodes.push(node.argument);
|
nodes.push(node.argument);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (var node of (nodes: Array)) {
|
for (let node of (nodes: Array)) {
|
||||||
comments = comments.concat(this._getComments(key, node));
|
comments = comments.concat(this._getComments(key, node));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -330,7 +307,6 @@ class CodeGenerator {
|
|||||||
|
|
||||||
_printComments(comments) {
|
_printComments(comments) {
|
||||||
if (this.format.compact) return;
|
if (this.format.compact) return;
|
||||||
|
|
||||||
if (!this.format.comments) return;
|
if (!this.format.comments) return;
|
||||||
if (!comments || !comments.length) return;
|
if (!comments || !comments.length) return;
|
||||||
|
|
||||||
@@ -366,8 +342,8 @@ class CodeGenerator {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
if (comment.type === "Block" && this.format.indent.adjustMultilineComment) {
|
if (comment.type === "CommentBlock" && this.format.indent.adjustMultilineComment) {
|
||||||
var offset = comment.loc.start.column;
|
var offset = comment.loc && comment.loc.start.column;
|
||||||
if (offset) {
|
if (offset) {
|
||||||
var newlineRegex = new RegExp("\\n\\s{1," + offset + "}", "g");
|
var newlineRegex = new RegExp("\\n\\s{1," + offset + "}", "g");
|
||||||
val = val.replace(newlineRegex, "\n");
|
val = val.replace(newlineRegex, "\n");
|
||||||
@@ -383,7 +359,7 @@ class CodeGenerator {
|
|||||||
|
|
||||||
// force a newline for line comments when retainLines is set in case the next printed node
|
// force a newline for line comments when retainLines is set in case the next printed node
|
||||||
// doesn't catch up
|
// doesn't catch up
|
||||||
if (this.format.retainLines && comment.type === "Line") {
|
if (this.format.retainLines && comment.type === "CommentLine") {
|
||||||
val += "\n";
|
val += "\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
36
src/babel/generation/node/printer.js
Normal file
36
src/babel/generation/node/printer.js
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
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 = ",";
|
||||||
|
if (!this.generator.format.compact) opts.separator += " ";
|
||||||
|
}
|
||||||
|
|
||||||
|
return this.join(items, opts);
|
||||||
|
}
|
||||||
|
|
||||||
|
block(node) {
|
||||||
|
return this.generator.printBlock(this, node);
|
||||||
|
}
|
||||||
|
|
||||||
|
indentOnComments(node) {
|
||||||
|
return this.generator.printAndIndentOnComments(this, node);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -8,7 +8,7 @@ export default class SourceMap {
|
|||||||
|
|
||||||
if (opts.sourceMaps) {
|
if (opts.sourceMaps) {
|
||||||
this.map = new sourceMap.SourceMapGenerator({
|
this.map = new sourceMap.SourceMapGenerator({
|
||||||
file: opts.sourceMapName,
|
file: opts.sourceMapTarget,
|
||||||
sourceRoot: opts.sourceRoot
|
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.
|
* 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.
|
* 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 {
|
export default class Whitespace {
|
||||||
constructor(tokens, comments) {
|
constructor(tokens) {
|
||||||
this.tokens = sortBy(tokens.concat(comments), "start");
|
this.tokens = tokens;
|
||||||
this.used = {};
|
this.used = {};
|
||||||
|
|
||||||
// Profiling this code shows that while generator passes over it, indexes
|
// Profiling this code shows that while generator passes over it, indexes
|
||||||
@@ -40,12 +38,11 @@ export default class Whitespace {
|
|||||||
var startToken;
|
var startToken;
|
||||||
var endToken;
|
var endToken;
|
||||||
var tokens = this.tokens;
|
var tokens = this.tokens;
|
||||||
var token;
|
|
||||||
|
|
||||||
for (var j = 0; j < tokens.length; j++) {
|
for (var j = 0; j < tokens.length; j++) {
|
||||||
// optimize for forward traversal by shifting for loop index
|
// optimize for forward traversal by shifting for loop index
|
||||||
var i = getLookupIndex(j, this._lastFoundIndex, this.tokens.length);
|
var i = getLookupIndex(j, this._lastFoundIndex, this.tokens.length);
|
||||||
token = tokens[i];
|
var token = tokens[i];
|
||||||
|
|
||||||
// this is the token this node starts with
|
// this is the token this node starts with
|
||||||
if (node.start === token.start) {
|
if (node.start === token.start) {
|
||||||
@@ -64,17 +61,17 @@ export default class Whitespace {
|
|||||||
var startToken;
|
var startToken;
|
||||||
var endToken;
|
var endToken;
|
||||||
var tokens = this.tokens;
|
var tokens = this.tokens;
|
||||||
var token;
|
|
||||||
|
|
||||||
for (var j = 0; j < tokens.length; j++) {
|
for (var j = 0; j < tokens.length; j++) {
|
||||||
// optimize for forward traversal by shifting for loop index
|
// optimize for forward traversal by shifting for loop index
|
||||||
var i = getLookupIndex(j, this._lastFoundIndex, this.tokens.length);
|
var i = getLookupIndex(j, this._lastFoundIndex, this.tokens.length);
|
||||||
token = tokens[i];
|
var token = tokens[i];
|
||||||
|
|
||||||
// this is the token this node ends with
|
// this is the token this node ends with
|
||||||
if (node.end === token.end) {
|
if (node.end === token.end) {
|
||||||
startToken = token;
|
startToken = token;
|
||||||
endToken = tokens[i + 1];
|
endToken = tokens[i + 1];
|
||||||
|
if (endToken.type.label === ",") endToken = tokens[i + 2];
|
||||||
|
|
||||||
this._lastFoundIndex = i;
|
this._lastFoundIndex = i;
|
||||||
break;
|
break;
|
||||||
@@ -85,7 +82,7 @@ export default class Whitespace {
|
|||||||
return 1;
|
return 1;
|
||||||
} else {
|
} else {
|
||||||
var lines = this.getNewlinesBetween(startToken, endToken);
|
var lines = this.getNewlinesBetween(startToken, endToken);
|
||||||
if (node.type === "Line" && !lines) {
|
if (node.type === "CommentLine" && !lines) {
|
||||||
// line comment
|
// line comment
|
||||||
return 1;
|
return 1;
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -79,10 +79,12 @@ export default function (lines: number, lineNumber: number, colNumber: number, o
|
|||||||
if (params.number !== lineNumber) {
|
if (params.number !== lineNumber) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (colNumber) {
|
if (colNumber) {
|
||||||
params.line += `\n${params.before}${repeating(" ", params.width)}${params.after}${repeating(" ", colNumber - 1)}^`;
|
params.line += `\n${params.before}${repeating(" ", params.width)}${params.after}${repeating(" ", colNumber - 1)}^`;
|
||||||
}
|
}
|
||||||
|
|
||||||
params.before = params.before.replace(/^./, ">");
|
params.before = params.before.replace(/^./, ">");
|
||||||
}
|
}
|
||||||
}).join("\n");
|
}).join("\n");
|
||||||
};
|
}
|
||||||
|
|||||||
@@ -6,4 +6,4 @@ export default function (ast, comments, tokens) {
|
|||||||
} else {
|
} else {
|
||||||
throw new Error("Not a valid ast?");
|
throw new Error("Not a valid ast?");
|
||||||
}
|
}
|
||||||
};
|
}
|
||||||
|
|||||||
@@ -1,3 +1,3 @@
|
|||||||
export default function () {
|
export default function () {
|
||||||
return Object.create(null);
|
return Object.create(null);
|
||||||
};
|
}
|
||||||
|
|||||||
@@ -3,8 +3,9 @@ import estraverse from "estraverse";
|
|||||||
import * as acorn from "../../acorn";
|
import * as acorn from "../../acorn";
|
||||||
|
|
||||||
export default function (code, opts = {}) {
|
export default function (code, opts = {}) {
|
||||||
var comments = [];
|
var commentsAndTokens = [];
|
||||||
var tokens = [];
|
var comments = [];
|
||||||
|
var tokens = [];
|
||||||
|
|
||||||
var parseOpts = {
|
var parseOpts = {
|
||||||
allowImportExportEverywhere: opts.looseModules,
|
allowImportExportEverywhere: opts.looseModules,
|
||||||
@@ -14,21 +15,38 @@ export default function (code, opts = {}) {
|
|||||||
strictMode: opts.strictMode,
|
strictMode: opts.strictMode,
|
||||||
sourceType: opts.sourceType,
|
sourceType: opts.sourceType,
|
||||||
locations: true,
|
locations: true,
|
||||||
onComment: comments,
|
|
||||||
features: opts.features || {},
|
features: opts.features || {},
|
||||||
plugins: opts.plugins || {},
|
plugins: opts.plugins || {},
|
||||||
onToken: tokens,
|
onToken: tokens,
|
||||||
ranges: true
|
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]
|
||||||
|
};
|
||||||
|
|
||||||
|
commentsAndTokens.push(comment);
|
||||||
|
comments.push(comment);
|
||||||
|
};
|
||||||
|
|
||||||
if (opts.nonStandard) {
|
if (opts.nonStandard) {
|
||||||
parseOpts.plugins.jsx = true;
|
parseOpts.plugins.jsx = true;
|
||||||
parseOpts.plugins.flow = true;
|
parseOpts.plugins.flow = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
var ast = acorn.parse(code, parseOpts);
|
var ast = acorn.parse(code, parseOpts);
|
||||||
|
|
||||||
estraverse.attachComments(ast, comments, tokens);
|
estraverse.attachComments(ast, comments, tokens);
|
||||||
ast = normalizeAst(ast, comments, tokens);
|
ast = normalizeAst(ast, comments, commentsAndTokens);
|
||||||
return ast;
|
return ast;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,23 +5,26 @@ export const MESSAGES = {
|
|||||||
JSXNamespacedTags: "Namespace tags are not supported. ReactJSX is not XML.",
|
JSXNamespacedTags: "Namespace tags are not supported. ReactJSX is not XML.",
|
||||||
classesIllegalBareSuper: "Illegal use of bare super",
|
classesIllegalBareSuper: "Illegal use of bare super",
|
||||||
classesIllegalSuperCall: "Direct super call is illegal in non-constructor, use super.$1() instead",
|
classesIllegalSuperCall: "Direct super call is illegal in non-constructor, use super.$1() instead",
|
||||||
classesIllegalConstructorKind: "Illegal kind for constructor method",
|
|
||||||
scopeDuplicateDeclaration: "Duplicate declaration $1",
|
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",
|
settersNoRest: "Setters aren't allowed to have a rest",
|
||||||
noAssignmentsInForHead: "No assignments allowed in for-in/of head",
|
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",
|
invalidParentForThisNode: "We don't know how to handle this node within the current parent - please open an issue",
|
||||||
readOnly: "$1 is read-only",
|
readOnly: "$1 is read-only",
|
||||||
modulesIllegalExportName: "Illegal export $1",
|
|
||||||
unknownForHead: "Unknown node type $1 in ForStatement",
|
unknownForHead: "Unknown node type $1 in ForStatement",
|
||||||
didYouMean: "Did you mean $1?",
|
didYouMean: "Did you mean $1?",
|
||||||
codeGeneratorDeopt: "Note: The code generator has deoptimised the styling of $1 as it exceeds the max of $2.",
|
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",
|
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",
|
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",
|
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 }`?",
|
traverseVerifyRootFunction: "You passed `traverse()` a function when it expected a visitor object, are you sure you didn't mean `{ enter: Function }`?",
|
||||||
@@ -31,10 +34,10 @@ export const MESSAGES = {
|
|||||||
pluginIllegalKind: "Illegal kind $1 for plugin $2",
|
pluginIllegalKind: "Illegal kind $1 for plugin $2",
|
||||||
pluginIllegalPosition: "Illegal position $1 for plugin $2",
|
pluginIllegalPosition: "Illegal position $1 for plugin $2",
|
||||||
pluginKeyCollision: "The plugin $1 collides with another of the same name",
|
pluginKeyCollision: "The plugin $1 collides with another of the same name",
|
||||||
pluginNotTransformer: "The plugin $1 didn't export a Transformer instance",
|
pluginNotTransformer: "The plugin $1 didn't export a Plugin instance",
|
||||||
pluginUnknown: "Unknown plugin $1",
|
pluginUnknown: "Unknown plugin $1",
|
||||||
|
|
||||||
transformerNotFile: "Transformer $1 is resolving to a different Babel version to what is doing the actual transformation..."
|
pluginNotFile: "Plugin $1 is resolving to a different Babel version to what is doing the actual transformation..."
|
||||||
};
|
};
|
||||||
|
|
||||||
export function get(key: String, ...args) {
|
export function get(key: String, ...args) {
|
||||||
|
|||||||
@@ -17,6 +17,8 @@ var or = types.Type.or;
|
|||||||
// .build("program")
|
// .build("program")
|
||||||
// .field("program", def("Program"));
|
// .field("program", def("Program"));
|
||||||
|
|
||||||
|
def("Noop");
|
||||||
|
|
||||||
def("AssignmentPattern")
|
def("AssignmentPattern")
|
||||||
.bases("Pattern")
|
.bases("Pattern")
|
||||||
.build("left", "right")
|
.build("left", "right")
|
||||||
|
|||||||
@@ -83,4 +83,4 @@ export default function (whitelist, outputType = "global") {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return generator(tree).code;
|
return generator(tree).code;
|
||||||
};
|
}
|
||||||
|
|||||||
9
src/babel/tools/protect.js
Normal file
9
src/babel/tools/protect.js
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
import path from "path";
|
||||||
|
|
||||||
|
var root = path.resolve(__dirname, "../../../");
|
||||||
|
|
||||||
|
export default function (module) {
|
||||||
|
if (module.parent && module.parent.filename.indexOf(root) !== 0) {
|
||||||
|
throw new Error("Don't hotlink internal Babel files.");
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,15 +1,13 @@
|
|||||||
|
import { validateOption, normaliseOptions, config as optionsConfig } from "./options";
|
||||||
import convertSourceMap from "convert-source-map";
|
import convertSourceMap from "convert-source-map";
|
||||||
import * as optionParsers from "./option-parsers";
|
|
||||||
import moduleFormatters from "../modules";
|
import moduleFormatters from "../modules";
|
||||||
import PluginManager from "./plugin-manager";
|
import PluginManager from "./plugin-manager";
|
||||||
import shebangRegex from "shebang-regex";
|
import shebangRegex from "shebang-regex";
|
||||||
import TraversalPath from "../../traversal/path";
|
import NodePath from "../../traversal/path";
|
||||||
import Transformer from "../transformer";
|
|
||||||
import isFunction from "lodash/lang/isFunction";
|
import isFunction from "lodash/lang/isFunction";
|
||||||
import isAbsolute from "path-is-absolute";
|
import isAbsolute from "path-is-absolute";
|
||||||
import resolveRc from "../../tools/resolve-rc";
|
import resolveRc from "./options/resolve-rc";
|
||||||
import sourceMap from "source-map";
|
import sourceMap from "source-map";
|
||||||
import transform from "./../index";
|
|
||||||
import generate from "../../generation";
|
import generate from "../../generation";
|
||||||
import codeFrame from "../../helpers/code-frame";
|
import codeFrame from "../../helpers/code-frame";
|
||||||
import defaults from "lodash/object/defaults";
|
import defaults from "lodash/object/defaults";
|
||||||
@@ -17,13 +15,13 @@ import includes from "lodash/collection/includes";
|
|||||||
import traverse from "../../traversal";
|
import traverse from "../../traversal";
|
||||||
import assign from "lodash/object/assign";
|
import assign from "lodash/object/assign";
|
||||||
import Logger from "./logger";
|
import Logger from "./logger";
|
||||||
|
import Plugin from "../plugin";
|
||||||
import parse from "../../helpers/parse";
|
import parse from "../../helpers/parse";
|
||||||
import Scope from "../../traversal/scope";
|
|
||||||
import merge from "../../helpers/merge";
|
import merge from "../../helpers/merge";
|
||||||
import slash from "slash";
|
import slash from "slash";
|
||||||
import clone from "lodash/lang/clone";
|
import clone from "lodash/lang/clone";
|
||||||
|
import Hub from "../../traversal/hub";
|
||||||
import * as util from "../../util";
|
import * as util from "../../util";
|
||||||
import * as api from "../../api/node";
|
|
||||||
import path from "path";
|
import path from "path";
|
||||||
import * as t from "../../types";
|
import * as t from "../../types";
|
||||||
|
|
||||||
@@ -38,15 +36,27 @@ export default class File {
|
|||||||
this.declarations = {};
|
this.declarations = {};
|
||||||
this.usedHelpers = {};
|
this.usedHelpers = {};
|
||||||
this.dynamicData = {};
|
this.dynamicData = {};
|
||||||
this.metadata = {};
|
|
||||||
this.data = {};
|
this.data = {};
|
||||||
|
|
||||||
|
this.metadata = {
|
||||||
|
modules: {
|
||||||
|
imports: [],
|
||||||
|
exports: {
|
||||||
|
exported: [],
|
||||||
|
specifiers: []
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
this.pipeline = pipeline;
|
this.pipeline = pipeline;
|
||||||
this.log = new Logger(this, opts.filename || "unknown");
|
this.log = new Logger(this, opts.filename || "unknown");
|
||||||
this.opts = this.normalizeOptions(opts);
|
|
||||||
this.ast = {};
|
this.ast = {};
|
||||||
|
|
||||||
|
this.normaliseOptions(opts);
|
||||||
|
|
||||||
this.buildTransformers();
|
this.buildTransformers();
|
||||||
|
|
||||||
|
this.hub = new Hub(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
static helpers = [
|
static helpers = [
|
||||||
@@ -88,19 +98,19 @@ export default class File {
|
|||||||
|
|
||||||
static soloHelpers = [];
|
static soloHelpers = [];
|
||||||
|
|
||||||
static options = require("./options");
|
static options = optionsConfig;
|
||||||
|
|
||||||
normalizeOptions(opts: Object) {
|
normaliseOptions(opts: Object) {
|
||||||
opts = assign({}, opts);
|
opts = this.opts = normaliseOptions(assign({}, opts));
|
||||||
|
|
||||||
|
// resolve babelrc
|
||||||
if (opts.filename) {
|
if (opts.filename) {
|
||||||
var rcFilename = opts.filename;
|
var rcFilename = opts.filename;
|
||||||
if (!isAbsolute(rcFilename)) rcFilename = path.join(process.cwd(), rcFilename);
|
if (!isAbsolute(rcFilename)) rcFilename = path.join(process.cwd(), rcFilename);
|
||||||
opts = resolveRc(rcFilename, opts);
|
opts = resolveRc(rcFilename, opts);
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
// check for unknown options
|
||||||
|
|
||||||
for (let key in opts) {
|
for (let key in opts) {
|
||||||
if (key[0] === "_") continue;
|
if (key[0] === "_") continue;
|
||||||
|
|
||||||
@@ -108,26 +118,30 @@ export default class File {
|
|||||||
if (!option) this.log.error(`Unknown option: ${key}`, ReferenceError);
|
if (!option) this.log.error(`Unknown option: ${key}`, ReferenceError);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// merge in environment options
|
||||||
var envKey = process.env.BABEL_ENV || process.env.NODE_ENV || "development";
|
var envKey = process.env.BABEL_ENV || process.env.NODE_ENV || "development";
|
||||||
if (opts.env) merge(opts, opts.env[envKey]);
|
if (opts.env) merge(opts, normaliseOptions(opts.env[envKey]));
|
||||||
|
|
||||||
|
// normalise options
|
||||||
for (let key in File.options) {
|
for (let key in File.options) {
|
||||||
let option = File.options[key];
|
let option = File.options[key];
|
||||||
|
var val = opts[key];
|
||||||
|
|
||||||
var val = opts[key];
|
// optional
|
||||||
if (!val && option.optional) continue;
|
if (!val && option.optional) continue;
|
||||||
|
|
||||||
|
// deprecated
|
||||||
if (val && option.deprecated) {
|
if (val && option.deprecated) {
|
||||||
throw new Error("Deprecated option " + key + ": " + option.deprecated);
|
this.log.deprecate("Deprecated option " + key + ": " + option.deprecated);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (val == null) {
|
// default
|
||||||
val = clone(option.default);
|
if (val == null) val = clone(option.default);
|
||||||
}
|
|
||||||
|
|
||||||
var optionParser = optionParsers[option.type];
|
// validate
|
||||||
if (optionParser) val = optionParser(key, val, this.pipeline);
|
if (val) val = validateOption(key, val, this.pipeline);
|
||||||
|
|
||||||
|
// aaliases
|
||||||
if (option.alias) {
|
if (option.alias) {
|
||||||
opts[option.alias] = opts[option.alias] || val;
|
opts[option.alias] = opts[option.alias] || val;
|
||||||
} else {
|
} else {
|
||||||
@@ -152,7 +166,10 @@ export default class File {
|
|||||||
opts.basename = path.basename(opts.filename, path.extname(opts.filename));
|
opts.basename = path.basename(opts.filename, path.extname(opts.filename));
|
||||||
|
|
||||||
opts.ignore = util.arrayify(opts.ignore, util.regexify);
|
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, {
|
defaults(opts, {
|
||||||
moduleRoot: opts.sourceRoot
|
moduleRoot: opts.sourceRoot
|
||||||
@@ -168,7 +185,7 @@ export default class File {
|
|||||||
|
|
||||||
defaults(opts, {
|
defaults(opts, {
|
||||||
sourceFileName: opts.filenameRelative,
|
sourceFileName: opts.filenameRelative,
|
||||||
sourceMapName: opts.filenameRelative
|
sourceMapTarget: opts.filenameRelative
|
||||||
});
|
});
|
||||||
|
|
||||||
//
|
//
|
||||||
@@ -195,7 +212,7 @@ export default class File {
|
|||||||
// build internal transformers
|
// build internal transformers
|
||||||
for (var key in this.pipeline.transformers) {
|
for (var key in this.pipeline.transformers) {
|
||||||
var transformer = this.pipeline.transformers[key];
|
var transformer = this.pipeline.transformers[key];
|
||||||
var pass = transformers[key] = transformer.buildPass(file);
|
let pass = transformers[key] = transformer.buildPass(file);
|
||||||
|
|
||||||
if (pass.canTransform()) {
|
if (pass.canTransform()) {
|
||||||
stack.push(pass);
|
stack.push(pass);
|
||||||
@@ -228,8 +245,8 @@ export default class File {
|
|||||||
this.uncollapsedTransformerStack = stack = stack.concat(secondaryStack);
|
this.uncollapsedTransformerStack = stack = stack.concat(secondaryStack);
|
||||||
|
|
||||||
// build dependency graph
|
// build dependency graph
|
||||||
for (var pass of (stack: Array)) {
|
for (let pass of (stack: Array)) {
|
||||||
for (var dep of (pass.transformer.dependencies: Array)) {
|
for (var dep of (pass.plugin.dependencies: Array)) {
|
||||||
this.transformerDependencies[dep] = pass.key;
|
this.transformerDependencies[dep] = pass.key;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -246,7 +263,7 @@ export default class File {
|
|||||||
// been merged
|
// been merged
|
||||||
if (ignore.indexOf(pass) >= 0) continue;
|
if (ignore.indexOf(pass) >= 0) continue;
|
||||||
|
|
||||||
var group = pass.transformer.metadata.group;
|
var group = pass.plugin.metadata.group;
|
||||||
|
|
||||||
// can't merge
|
// can't merge
|
||||||
if (!pass.canTransform() || !group) {
|
if (!pass.canTransform() || !group) {
|
||||||
@@ -256,7 +273,7 @@ export default class File {
|
|||||||
|
|
||||||
var mergeStack = [];
|
var mergeStack = [];
|
||||||
for (let pass of (_stack: Array)) {
|
for (let pass of (_stack: Array)) {
|
||||||
if (pass.transformer.metadata.group === group) {
|
if (pass.plugin.metadata.group === group) {
|
||||||
mergeStack.push(pass);
|
mergeStack.push(pass);
|
||||||
ignore.push(pass);
|
ignore.push(pass);
|
||||||
}
|
}
|
||||||
@@ -264,12 +281,11 @@ export default class File {
|
|||||||
|
|
||||||
var visitors = [];
|
var visitors = [];
|
||||||
for (let pass of (mergeStack: Array)) {
|
for (let pass of (mergeStack: Array)) {
|
||||||
visitors.push(pass.handlers);
|
visitors.push(pass.plugin.visitor);
|
||||||
}
|
}
|
||||||
var visitor = traverse.visitors.merge(visitors);
|
var visitor = traverse.visitors.merge(visitors);
|
||||||
var mergeTransformer = new Transformer(group, visitor);
|
var mergePlugin = new Plugin(group, { visitor });
|
||||||
//console.log(mergeTransformer);
|
stack.push(mergePlugin.buildPass(this));
|
||||||
stack.push(mergeTransformer.buildPass(this));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return stack;
|
return stack;
|
||||||
@@ -319,7 +335,7 @@ export default class File {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (this.transformers["es6.modules"].canTransform()) {
|
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;
|
this.moduleFormatter.hasLocalImports = true;
|
||||||
} else {
|
} else {
|
||||||
this.dynamicImports.push(declar);
|
this.dynamicImports.push(declar);
|
||||||
@@ -330,14 +346,24 @@ export default class File {
|
|||||||
}
|
}
|
||||||
|
|
||||||
attachAuxiliaryComment(node: Object): Object {
|
attachAuxiliaryComment(node: Object): Object {
|
||||||
var comment = this.opts.auxiliaryComment;
|
var beforeComment = this.opts.auxiliaryCommentBefore;
|
||||||
if (comment) {
|
if (beforeComment) {
|
||||||
node.leadingComments = node.leadingComments || [];
|
node.leadingComments = node.leadingComments || [];
|
||||||
node.leadingComments.push({
|
node.leadingComments.push({
|
||||||
type: "Line",
|
type: "CommentLine",
|
||||||
value: " " + comment
|
value: " " + beforeComment
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var afterComment = this.opts.auxiliaryCommentAfter;
|
||||||
|
if (afterComment) {
|
||||||
|
node.trailingComments = node.trailingComments || [];
|
||||||
|
node.trailingComments.push({
|
||||||
|
type: "CommentLine",
|
||||||
|
value: " " + afterComment
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
return node;
|
return node;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -348,8 +374,6 @@ export default class File {
|
|||||||
throw new ReferenceError(`Unknown helper ${name}`);
|
throw new ReferenceError(`Unknown helper ${name}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
var program = this.ast.program;
|
|
||||||
|
|
||||||
var declar = this.declarations[name];
|
var declar = this.declarations[name];
|
||||||
if (declar) return declar;
|
if (declar) return declar;
|
||||||
|
|
||||||
@@ -390,9 +414,15 @@ export default class File {
|
|||||||
}
|
}
|
||||||
|
|
||||||
errorWithNode(node, msg, Error = SyntaxError) {
|
errorWithNode(node, msg, Error = SyntaxError) {
|
||||||
var loc = node.loc.start;
|
var err;
|
||||||
var err = new Error(`Line ${loc.line}: ${msg}`);
|
if (node && node.loc) {
|
||||||
err.loc = 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;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -410,7 +440,7 @@ export default class File {
|
|||||||
outputMapGenerator.applySourceMap(inputMapConsumer);
|
outputMapGenerator.applySourceMap(inputMapConsumer);
|
||||||
|
|
||||||
var mergedMap = outputMapGenerator.toJSON();
|
var mergedMap = outputMapGenerator.toJSON();
|
||||||
mergedMap.sources = inputMap.sources
|
mergedMap.sources = inputMap.sources;
|
||||||
mergedMap.file = inputMap.file;
|
mergedMap.file = inputMap.file;
|
||||||
return mergedMap;
|
return mergedMap;
|
||||||
}
|
}
|
||||||
@@ -420,6 +450,10 @@ export default class File {
|
|||||||
|
|
||||||
|
|
||||||
getModuleFormatter(type: string) {
|
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];
|
var ModuleFormatter = isFunction(type) ? type : moduleFormatters[type];
|
||||||
|
|
||||||
if (!ModuleFormatter) {
|
if (!ModuleFormatter) {
|
||||||
@@ -463,7 +497,13 @@ export default class File {
|
|||||||
}
|
}
|
||||||
|
|
||||||
_addAst(ast) {
|
_addAst(ast) {
|
||||||
this.path = TraversalPath.get(null, null, ast, ast, "program", this);
|
this.path = NodePath.get({
|
||||||
|
hub: this.hub,
|
||||||
|
parentPath: null,
|
||||||
|
parent: ast,
|
||||||
|
container: ast,
|
||||||
|
key: "program"
|
||||||
|
}).setContext();
|
||||||
this.scope = this.path.scope;
|
this.scope = this.path.scope;
|
||||||
this.ast = ast;
|
this.ast = ast;
|
||||||
}
|
}
|
||||||
@@ -479,12 +519,16 @@ export default class File {
|
|||||||
modFormatter.init();
|
modFormatter.init();
|
||||||
}
|
}
|
||||||
this.log.debug("End module formatter init");
|
this.log.debug("End module formatter init");
|
||||||
|
}
|
||||||
|
|
||||||
|
transform() {
|
||||||
this.call("pre");
|
this.call("pre");
|
||||||
for (var pass of (this.transformerStack: Array)) {
|
for (var pass of (this.transformerStack: Array)) {
|
||||||
pass.transform();
|
pass.transform();
|
||||||
}
|
}
|
||||||
this.call("post");
|
this.call("post");
|
||||||
|
|
||||||
|
return this.generate();
|
||||||
}
|
}
|
||||||
|
|
||||||
wrap(code, callback) {
|
wrap(code, callback) {
|
||||||
@@ -492,18 +536,10 @@ export default class File {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
if (this.shouldIgnore()) {
|
if (this.shouldIgnore()) {
|
||||||
return {
|
return this.makeResult({ code, ignored: true });
|
||||||
metadata: this.metadata,
|
} else {
|
||||||
ignored: true,
|
return callback();
|
||||||
code: code,
|
|
||||||
map: null,
|
|
||||||
ast: null
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
callback();
|
|
||||||
|
|
||||||
return this.generate();
|
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
if (err._babel) {
|
if (err._babel) {
|
||||||
throw err;
|
throw err;
|
||||||
@@ -532,15 +568,15 @@ export default class File {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
addCode(code: string, parseCode?) {
|
addCode(code: string) {
|
||||||
code = (code || "") + "";
|
code = (code || "") + "";
|
||||||
code = this.parseInputSourceMap(code);
|
code = this.parseInputSourceMap(code);
|
||||||
this.code = code;
|
this.code = code;
|
||||||
|
}
|
||||||
|
|
||||||
if (parseCode) {
|
parseCode() {
|
||||||
this.parseShebang();
|
this.parseShebang();
|
||||||
this.addAst(this.parse(this.code));
|
this.addAst(this.parse(this.code));
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
shouldIgnore() {
|
shouldIgnore() {
|
||||||
@@ -550,7 +586,7 @@ export default class File {
|
|||||||
|
|
||||||
call(key: string) {
|
call(key: string) {
|
||||||
for (var pass of (this.uncollapsedTransformerStack: Array)) {
|
for (var pass of (this.uncollapsedTransformerStack: Array)) {
|
||||||
var fn = pass.transformer[key];
|
var fn = pass.plugin[key];
|
||||||
if (fn) fn(this);
|
if (fn) fn(this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -577,28 +613,37 @@ export default class File {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
generate(): {
|
makeResult({ code, map = null, ast, ignored }) {
|
||||||
usedHelpers?: Array<string>;
|
|
||||||
code: string;
|
|
||||||
map?: Object;
|
|
||||||
ast?: Object;
|
|
||||||
} {
|
|
||||||
var opts = this.opts;
|
|
||||||
var ast = this.ast;
|
|
||||||
|
|
||||||
var result = {
|
var result = {
|
||||||
metadata: this.metadata,
|
metadata: null,
|
||||||
code: "",
|
ignored: !!ignored,
|
||||||
map: null,
|
code: null,
|
||||||
ast: 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);
|
result.metadata.usedHelpers = Object.keys(this.usedHelpers);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (opts.ast) result.ast = ast;
|
return result;
|
||||||
if (!opts.code) 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");
|
this.log.debug("Generation start");
|
||||||
|
|
||||||
@@ -625,6 +670,6 @@ export default class File {
|
|||||||
result.map = null;
|
result.map = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
return this.makeResult(result);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,8 +1,11 @@
|
|||||||
|
import type File from "./index";
|
||||||
import buildDebug from "debug/node";
|
import buildDebug from "debug/node";
|
||||||
|
|
||||||
var verboseDebug = buildDebug("babel:verbose");
|
var verboseDebug = buildDebug("babel:verbose");
|
||||||
var generalDebug = buildDebug("babel");
|
var generalDebug = buildDebug("babel");
|
||||||
|
|
||||||
|
var seenDeprecatedMessages = [];
|
||||||
|
|
||||||
export default class Logger {
|
export default class Logger {
|
||||||
constructor(file: File, filename: string) {
|
constructor(file: File, filename: string) {
|
||||||
this.filename = filename;
|
this.filename = filename;
|
||||||
@@ -15,14 +18,26 @@ export default class Logger {
|
|||||||
return parts;
|
return parts;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
warn(msg) {
|
||||||
|
console.warn(this._buildMessage(msg));
|
||||||
|
}
|
||||||
|
|
||||||
error(msg: string, Constructor = Error) {
|
error(msg: string, Constructor = Error) {
|
||||||
throw new Constructor(this._buildMessage(msg));
|
throw new Constructor(this._buildMessage(msg));
|
||||||
}
|
}
|
||||||
|
|
||||||
deprecate(msg) {
|
deprecate(msg) {
|
||||||
if (!this.file.opts.suppressDeprecationMessages) {
|
if (this.file.opts.suppressDeprecationMessages) return;
|
||||||
console.error(this._buildMessage(msg));
|
|
||||||
}
|
msg = this._buildMessage(msg);
|
||||||
|
|
||||||
|
// already seen this message
|
||||||
|
if (seenDeprecatedMessages.indexOf(msg) >= 0) return;
|
||||||
|
|
||||||
|
// make sure we don't see it again
|
||||||
|
seenDeprecatedMessages.push(msg);
|
||||||
|
|
||||||
|
console.error(msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
verbose(msg: string) {
|
verbose(msg: string) {
|
||||||
|
|||||||
@@ -1,27 +0,0 @@
|
|||||||
import * as util from "../../util";
|
|
||||||
|
|
||||||
export function transformerList(key, val, pipeline) {
|
|
||||||
val = util.arrayify(val);
|
|
||||||
|
|
||||||
if (val.indexOf("all") >= 0 || val.indexOf(true) >= 0) {
|
|
||||||
val = Object.keys(pipeline.transformers);
|
|
||||||
}
|
|
||||||
|
|
||||||
return pipeline._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);
|
|
||||||
}
|
|
||||||
@@ -43,15 +43,17 @@
|
|||||||
"nonStandard": {
|
"nonStandard": {
|
||||||
"type": "boolean",
|
"type": "boolean",
|
||||||
"default": true,
|
"default": true,
|
||||||
"description": "enable support for JSX and Flow"
|
"description": "enable/disable support for JSX and Flow (on by default)"
|
||||||
},
|
},
|
||||||
|
|
||||||
"experimental": {
|
"experimental": {
|
||||||
"deprecated": "use `--stage 0`/`{ stage: 0 }` instead"
|
"type": "boolean",
|
||||||
|
"description": "allow use of experimental transformers",
|
||||||
|
"default": false
|
||||||
},
|
},
|
||||||
|
|
||||||
"highlightCode": {
|
"highlightCode": {
|
||||||
"description": "ANSI syntax highlight code frames",
|
"description": "enable/disable ANSI syntax highlighting of code frames (on by default)",
|
||||||
"type": "boolean",
|
"type": "boolean",
|
||||||
"default": true
|
"default": true
|
||||||
},
|
},
|
||||||
@@ -76,7 +78,8 @@
|
|||||||
"blacklist": {
|
"blacklist": {
|
||||||
"type": "transformerList",
|
"type": "transformerList",
|
||||||
"description": "blacklist of transformers to NOT use",
|
"description": "blacklist of transformers to NOT use",
|
||||||
"shorthand": "b"
|
"shorthand": "b",
|
||||||
|
"default": []
|
||||||
},
|
},
|
||||||
|
|
||||||
"whitelist": {
|
"whitelist": {
|
||||||
@@ -88,7 +91,8 @@
|
|||||||
|
|
||||||
"optional": {
|
"optional": {
|
||||||
"type": "transformerList",
|
"type": "transformerList",
|
||||||
"description": "list of optional transformers to enable"
|
"description": "list of optional transformers to enable",
|
||||||
|
"default": []
|
||||||
},
|
},
|
||||||
|
|
||||||
"modules": {
|
"modules": {
|
||||||
@@ -120,12 +124,14 @@
|
|||||||
|
|
||||||
"plugins": {
|
"plugins": {
|
||||||
"type": "list",
|
"type": "list",
|
||||||
"description": ""
|
"description": "",
|
||||||
|
"default": []
|
||||||
},
|
},
|
||||||
|
|
||||||
"ignore": {
|
"ignore": {
|
||||||
"type": "list",
|
"type": "list",
|
||||||
"description": "list of glob paths to **not** compile"
|
"description": "list of glob paths to **not** compile",
|
||||||
|
"default": []
|
||||||
},
|
},
|
||||||
|
|
||||||
"only": {
|
"only": {
|
||||||
@@ -139,6 +145,12 @@
|
|||||||
"type": "boolean"
|
"type": "boolean"
|
||||||
},
|
},
|
||||||
|
|
||||||
|
"metadata": {
|
||||||
|
"hidden": true,
|
||||||
|
"default": true,
|
||||||
|
"type": "boolean"
|
||||||
|
},
|
||||||
|
|
||||||
"ast": {
|
"ast": {
|
||||||
"hidden": true,
|
"hidden": true,
|
||||||
"default": true,
|
"default": true,
|
||||||
@@ -148,7 +160,7 @@
|
|||||||
"comments": {
|
"comments": {
|
||||||
"type": "boolean",
|
"type": "boolean",
|
||||||
"default": true,
|
"default": true,
|
||||||
"description": "output comments in generated output"
|
"description": "strip/output comments in generated output (on by default)"
|
||||||
},
|
},
|
||||||
|
|
||||||
"compact": {
|
"compact": {
|
||||||
@@ -165,12 +177,23 @@
|
|||||||
},
|
},
|
||||||
|
|
||||||
"auxiliaryComment": {
|
"auxiliaryComment": {
|
||||||
|
"deprecated": "renamed to auxiliaryCommentBefore",
|
||||||
|
"shorthand": "a",
|
||||||
|
"alias": "auxiliaryCommentBefore"
|
||||||
|
},
|
||||||
|
|
||||||
|
"auxiliaryCommentBefore": {
|
||||||
"type": "string",
|
"type": "string",
|
||||||
"default": "",
|
"default": "",
|
||||||
"shorthand": "a",
|
|
||||||
"description": "attach a comment before all helper declarations and auxiliary code"
|
"description": "attach a comment before all helper declarations and auxiliary code"
|
||||||
},
|
},
|
||||||
|
|
||||||
|
"auxiliaryCommentAfter": {
|
||||||
|
"type": "string",
|
||||||
|
"default": "",
|
||||||
|
"description": "attach a comment after all helper declarations and auxiliary code"
|
||||||
|
},
|
||||||
|
|
||||||
"externalHelpers": {
|
"externalHelpers": {
|
||||||
"type": "boolean",
|
"type": "boolean",
|
||||||
"default": false,
|
"default": false,
|
||||||
@@ -179,6 +202,7 @@
|
|||||||
},
|
},
|
||||||
|
|
||||||
"metadataUsedHelpers": {
|
"metadataUsedHelpers": {
|
||||||
|
"deprecated": "Not required anymore as this is enabled by default",
|
||||||
"type": "boolean",
|
"type": "boolean",
|
||||||
"default": false,
|
"default": false,
|
||||||
"hidden": true
|
"hidden": true
|
||||||
@@ -197,6 +221,11 @@
|
|||||||
},
|
},
|
||||||
|
|
||||||
"sourceMapName": {
|
"sourceMapName": {
|
||||||
|
"alias": "sourceMapTarget",
|
||||||
|
"description": "DEPRECATED - Please use sourceMapTarget"
|
||||||
|
},
|
||||||
|
|
||||||
|
"sourceMapTarget": {
|
||||||
"type": "string",
|
"type": "string",
|
||||||
"description": "set `file` on returned source map"
|
"description": "set `file` on returned source map"
|
||||||
},
|
},
|
||||||
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,17 +1,17 @@
|
|||||||
import stripJsonComments from "strip-json-comments";
|
import stripJsonComments from "strip-json-comments";
|
||||||
import merge from "../helpers/merge";
|
import { normaliseOptions } from "./index";
|
||||||
|
import merge from "../../../helpers/merge";
|
||||||
import path from "path";
|
import path from "path";
|
||||||
import fs from "fs";
|
import fs from "fs";
|
||||||
|
import pathExists from "path-exists";
|
||||||
|
|
||||||
var cache = {};
|
var cache = {};
|
||||||
var jsons = {};
|
var jsons = {};
|
||||||
|
|
||||||
function exists(filename) {
|
function exists(filename) {
|
||||||
if (!fs.existsSync) return false;
|
|
||||||
|
|
||||||
var cached = cache[filename];
|
var cached = cache[filename];
|
||||||
if (cached != null) return cached;
|
if (cached != null) return cached;
|
||||||
return cache[filename] = fs.existsSync(filename);
|
return cache[filename] = pathExists.sync(filename);
|
||||||
}
|
}
|
||||||
|
|
||||||
export default function (loc, opts = {}) {
|
export default function (loc, opts = {}) {
|
||||||
@@ -34,6 +34,7 @@ export default function (loc, opts = {}) {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
json = jsons[content] = jsons[content] || JSON.parse(stripJsonComments(content));
|
json = jsons[content] = jsons[content] || JSON.parse(stripJsonComments(content));
|
||||||
|
normaliseOptions(json);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
err.message = `${file}: ${err.message}`;
|
err.message = `${file}: ${err.message}`;
|
||||||
throw err;
|
throw err;
|
||||||
@@ -42,6 +43,7 @@ export default function (loc, opts = {}) {
|
|||||||
opts.babelrc.push(file);
|
opts.babelrc.push(file);
|
||||||
|
|
||||||
if (json.breakConfig) return;
|
if (json.breakConfig) return;
|
||||||
|
|
||||||
merge(opts, json);
|
merge(opts, json);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -56,4 +58,4 @@ export default function (loc, opts = {}) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return opts;
|
return opts;
|
||||||
};
|
}
|
||||||
@@ -1,5 +1,19 @@
|
|||||||
import * as node from "../../api/node";
|
import Transformer from "../transformer";
|
||||||
|
import Plugin from "../plugin";
|
||||||
|
import * as types from "../../types";
|
||||||
import * as messages from "../../messages";
|
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";
|
import * as util from "../../util";
|
||||||
|
|
||||||
export default class PluginManager {
|
export default class PluginManager {
|
||||||
@@ -11,7 +25,7 @@ export default class PluginManager {
|
|||||||
if (plugin.container === fn) return plugin.transformer;
|
if (plugin.container === fn) return plugin.transformer;
|
||||||
}
|
}
|
||||||
|
|
||||||
var transformer = fn(node);
|
var transformer = fn(context);
|
||||||
PluginManager.memoisedPlugins.push({
|
PluginManager.memoisedPlugins.push({
|
||||||
container: fn,
|
container: fn,
|
||||||
transformer: transformer
|
transformer: transformer
|
||||||
@@ -35,11 +49,12 @@ export default class PluginManager {
|
|||||||
var match = name.match(/^(.*?):(after|before)$/);
|
var match = name.match(/^(.*?):(after|before)$/);
|
||||||
if (match) [, name, position] = match;
|
if (match) [, name, position] = match;
|
||||||
|
|
||||||
var loc = util.resolveRelative(name) || util.resolveRelative(`babel-plugin-${name}`);
|
var loc = util.resolveRelative(`babel-plugin-${name}`) || util.resolveRelative(name);
|
||||||
if (loc) {
|
if (loc) {
|
||||||
|
var plugin = require(loc);
|
||||||
return {
|
return {
|
||||||
position: position,
|
position: position,
|
||||||
plugin: require(loc)
|
plugin: plugin.default || plugin
|
||||||
};
|
};
|
||||||
} else {
|
} else {
|
||||||
throw new ReferenceError(messages.get("pluginUnknown", name));
|
throw new ReferenceError(messages.get("pluginUnknown", name));
|
||||||
@@ -54,7 +69,7 @@ export default class PluginManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// validate Transformer instance
|
// validate Transformer instance
|
||||||
if (!plugin.buildPass || plugin.constructor.name !== "Transformer") {
|
if (!plugin.buildPass || plugin.constructor.name !== "Plugin") {
|
||||||
throw new TypeError(messages.get("pluginNotTransformer", name));
|
throw new TypeError(messages.get("pluginNotTransformer", name));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -44,4 +44,4 @@ export default function (opts) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
return exports;
|
return exports;
|
||||||
};
|
}
|
||||||
|
|||||||
@@ -42,4 +42,4 @@ export default function (exports, opts) {
|
|||||||
|
|
||||||
return nodes;
|
return nodes;
|
||||||
};
|
};
|
||||||
};
|
}
|
||||||
|
|||||||
@@ -9,8 +9,10 @@ import esutils from "esutils";
|
|||||||
import * as react from "./react";
|
import * as react from "./react";
|
||||||
import * as t from "../../types";
|
import * as t from "../../types";
|
||||||
|
|
||||||
export default function (exports, opts) {
|
export default function (opts) {
|
||||||
exports.JSXIdentifier = function (node, parent) {
|
var visitor = {};
|
||||||
|
|
||||||
|
visitor.JSXIdentifier = function (node) {
|
||||||
if (node.name === "this" && this.isReferenced()) {
|
if (node.name === "this" && this.isReferenced()) {
|
||||||
return t.thisExpression();
|
return t.thisExpression();
|
||||||
} else if (esutils.keyword.isIdentifierNameES6(node.name)) {
|
} else if (esutils.keyword.isIdentifierNameES6(node.name)) {
|
||||||
@@ -20,22 +22,22 @@ export default function (exports, opts) {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
exports.JSXNamespacedName = function (node, parent, scope, file) {
|
visitor.JSXNamespacedName = function () {
|
||||||
throw this.errorWithNode(messages.get("JSXNamespacedTags"));
|
throw this.errorWithNode(messages.get("JSXNamespacedTags"));
|
||||||
};
|
};
|
||||||
|
|
||||||
exports.JSXMemberExpression = {
|
visitor.JSXMemberExpression = {
|
||||||
exit(node) {
|
exit(node) {
|
||||||
node.computed = t.isLiteral(node.property);
|
node.computed = t.isLiteral(node.property);
|
||||||
node.type = "MemberExpression";
|
node.type = "MemberExpression";
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
exports.JSXExpressionContainer = function (node) {
|
visitor.JSXExpressionContainer = function (node) {
|
||||||
return node.expression;
|
return node.expression;
|
||||||
};
|
};
|
||||||
|
|
||||||
exports.JSXAttribute = {
|
visitor.JSXAttribute = {
|
||||||
enter(node) {
|
enter(node) {
|
||||||
var value = node.value;
|
var value = node.value;
|
||||||
if (t.isLiteral(value) && isString(value.value)) {
|
if (t.isLiteral(value) && isString(value.value)) {
|
||||||
@@ -49,7 +51,7 @@ export default function (exports, opts) {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
exports.JSXOpeningElement = {
|
visitor.JSXOpeningElement = {
|
||||||
exit(node, parent, scope, file) {
|
exit(node, parent, scope, file) {
|
||||||
parent.children = react.buildChildren(parent);
|
parent.children = react.buildChildren(parent);
|
||||||
|
|
||||||
@@ -139,7 +141,7 @@ export default function (exports, opts) {
|
|||||||
return attribs;
|
return attribs;
|
||||||
};
|
};
|
||||||
|
|
||||||
exports.JSXElement = {
|
visitor.JSXElement = {
|
||||||
exit(node) {
|
exit(node) {
|
||||||
var callExpr = node.openingElement;
|
var callExpr = node.openingElement;
|
||||||
|
|
||||||
@@ -153,53 +155,5 @@ export default function (exports, opts) {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// display names
|
return visitor;
|
||||||
|
}
|
||||||
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);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
import traverse from "../../traversal";
|
|
||||||
import * as t from "../../types";
|
import * as t from "../../types";
|
||||||
|
|
||||||
var visitor = {
|
var visitor = {
|
||||||
@@ -7,10 +6,10 @@ var visitor = {
|
|||||||
state.found = true;
|
state.found = true;
|
||||||
this.stop();
|
this.stop();
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
|
||||||
if (this.isFunction()) {
|
Function() {
|
||||||
this.skip();
|
this.skip();
|
||||||
}
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,3 @@
|
|||||||
import cloneDeep from "lodash/lang/cloneDeep";
|
|
||||||
import traverse from "../../traversal";
|
|
||||||
import each from "lodash/collection/each";
|
import each from "lodash/collection/each";
|
||||||
import has from "lodash/object/has";
|
import has from "lodash/object/has";
|
||||||
import * as t from "../../types";
|
import * as t from "../../types";
|
||||||
|
|||||||
@@ -68,4 +68,4 @@ export default function (node, nodes, file, scope, allowedSingleIdent) {
|
|||||||
uid: uid,
|
uid: uid,
|
||||||
ref: ref
|
ref: ref
|
||||||
};
|
};
|
||||||
};
|
}
|
||||||
|
|||||||
@@ -3,7 +3,10 @@ import * as t from "../../types";
|
|||||||
export default function (node) {
|
export default function (node) {
|
||||||
var lastNonDefault = 0;
|
var lastNonDefault = 0;
|
||||||
for (var i = 0; i < node.params.length; i++) {
|
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;
|
return lastNonDefault;
|
||||||
};
|
}
|
||||||
|
|||||||
@@ -2,25 +2,32 @@ import getFunctionArity from "./get-function-arity";
|
|||||||
import * as util from "../../util";
|
import * as util from "../../util";
|
||||||
import * as t from "../../types";
|
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 = {
|
var visitor = {
|
||||||
enter(node, parent, scope, state) {
|
ReferencedIdentifier(node, parent, scope, state) {
|
||||||
// check if this node is a referenced identifier that matches the same as our
|
visitIdentifier(this, node, scope, state);
|
||||||
// function id
|
},
|
||||||
if (!this.isReferencedIdentifier({ name: state.name })) return;
|
|
||||||
|
|
||||||
// check that we don't have a local variable declared as that removes the need
|
BindingIdentifier(node, parent, scope, state) {
|
||||||
// for the wrapper
|
visitIdentifier(this, node, scope, state);
|
||||||
var localDeclar = scope.getBindingIdentifier(state.name);
|
|
||||||
if (localDeclar !== state.outerDeclar) return;
|
|
||||||
|
|
||||||
state.selfReference = true;
|
|
||||||
this.stop();
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
var wrap = function (state, method, id, scope) {
|
var wrap = function (state, method, id, scope) {
|
||||||
if (state.selfReference) {
|
if (state.selfReference) {
|
||||||
if (scope.hasBinding(id.name)) {
|
if (scope.hasBinding(id.name) && !scope.hasGlobal(id.name)) {
|
||||||
// we can just munge the local binding
|
// we can just munge the local binding
|
||||||
scope.rename(id.name);
|
scope.rename(id.name);
|
||||||
} else {
|
} else {
|
||||||
@@ -46,6 +53,7 @@ var wrap = function (state, method, id, scope) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
method.id = id;
|
method.id = id;
|
||||||
|
scope.getProgramParent().references[id.name] = true;
|
||||||
};
|
};
|
||||||
|
|
||||||
var visit = function (node, name, scope) {
|
var visit = function (node, name, scope) {
|
||||||
@@ -60,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
|
// 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
|
// the function, this is important as there are caveats associated
|
||||||
|
|
||||||
var bindingInfo = scope.getOwnBindingInfo(name);
|
var binding = scope.getOwnBinding(name);
|
||||||
|
|
||||||
if (bindingInfo) {
|
if (binding) {
|
||||||
if (bindingInfo.kind === "param") {
|
if (binding.kind === "param") {
|
||||||
// safari will blow up in strict mode with code like:
|
// safari will blow up in strict mode with code like:
|
||||||
//
|
//
|
||||||
// var t = function t(t) {};
|
// var t = function t(t) {};
|
||||||
@@ -103,8 +111,7 @@ export function property(node, file, scope) {
|
|||||||
var key = t.toComputedKey(node, node.key);
|
var key = t.toComputedKey(node, node.key);
|
||||||
if (!t.isLiteral(key)) return; // 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);
|
var name = t.toBindingIdentifierName(key.value);
|
||||||
if (name === "eval" || name === "arguments") name = "_" + name;
|
|
||||||
var id = t.identifier(name);
|
var id = t.identifier(name);
|
||||||
|
|
||||||
var method = node.value;
|
var method = node.value;
|
||||||
@@ -125,8 +132,8 @@ export function bare(node, parent, scope) {
|
|||||||
id = parent.id;
|
id = parent.id;
|
||||||
|
|
||||||
if (t.isIdentifier(id)) {
|
if (t.isIdentifier(id)) {
|
||||||
var bindingInfo = scope.parent.getBinding(id.name);
|
var binding = scope.parent.getBinding(id.name);
|
||||||
if (bindingInfo && bindingInfo.constant && scope.getBinding(id.name) === bindingInfo) {
|
if (binding && binding.constant && scope.getBinding(id.name) === binding) {
|
||||||
// always going to reference this method
|
// always going to reference this method
|
||||||
node.id = id;
|
node.id = id;
|
||||||
return;
|
return;
|
||||||
@@ -145,7 +152,7 @@ export function bare(node, parent, scope) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
name = t.toIdentifier(name);
|
name = t.toBindingIdentifierName(name);
|
||||||
id = t.identifier(name);
|
id = t.identifier(name);
|
||||||
|
|
||||||
var state = visit(node, name, scope);
|
var state = visit(node, name, scope);
|
||||||
|
|||||||
24
src/babel/transformation/helpers/react.js
vendored
24
src/babel/transformation/helpers/react.js
vendored
@@ -1,35 +1,11 @@
|
|||||||
import isString from "lodash/lang/isString";
|
|
||||||
import * as t from "../../types";
|
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 var isReactComponent = t.buildMatchMemberExpression("React.Component");
|
||||||
|
|
||||||
export function isCompatTag(tagName) {
|
export function isCompatTag(tagName) {
|
||||||
return tagName && /^[a-z]|\-/.test(tagName);
|
return tagName && /^[a-z]|\-/.test(tagName);
|
||||||
}
|
}
|
||||||
|
|
||||||
function isStringLiteral(node) {
|
|
||||||
return t.isLiteral(node) && isString(node.value);
|
|
||||||
}
|
|
||||||
|
|
||||||
function cleanJSXElementLiteralChild(child, args) {
|
function cleanJSXElementLiteralChild(child, args) {
|
||||||
var lines = child.value.split(/\r\n|\n|\r/);
|
var lines = child.value.split(/\r\n|\n|\r/);
|
||||||
|
|
||||||
|
|||||||
@@ -1,35 +1,37 @@
|
|||||||
import * as t from "../../types";
|
import * as t from "../../types";
|
||||||
|
|
||||||
var awaitVisitor = {
|
var awaitVisitor = {
|
||||||
enter(node, parent, scope, state) {
|
Function() {
|
||||||
if (t.isFunction(node)) this.skip();
|
this.skip();
|
||||||
|
},
|
||||||
|
|
||||||
if (t.isAwaitExpression(node)) {
|
AwaitExpression(node) {
|
||||||
node.type = "YieldExpression";
|
node.type = "YieldExpression";
|
||||||
|
|
||||||
if (node.all) {
|
if (node.all) {
|
||||||
// await* foo; -> yield Promise.all(foo);
|
// await* foo; -> yield Promise.all(foo);
|
||||||
node.all = false;
|
node.all = false;
|
||||||
node.argument = t.callExpression(t.memberExpression(t.identifier("Promise"), t.identifier("all")), [node.argument]);
|
node.argument = t.callExpression(t.memberExpression(t.identifier("Promise"), t.identifier("all")), [node.argument]);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
var referenceVisitor = {
|
var referenceVisitor = {
|
||||||
enter(node, parent, scope, state) {
|
ReferencedIdentifier(node, parent, scope, state) {
|
||||||
var name = state.id.name;
|
var name = state.id.name;
|
||||||
if (this.isReferencedIdentifier({ name: name }) && scope.bindingIdentifierEquals(name, state.id)) {
|
if (node.name === name && scope.bindingIdentifierEquals(name, state.id)) {
|
||||||
return state.ref = state.ref || scope.generateUidIdentifier(name);
|
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.async = false;
|
||||||
node.generator = true;
|
node.generator = true;
|
||||||
|
|
||||||
scope.traverse(node, awaitVisitor, state);
|
path.traverse(awaitVisitor, state);
|
||||||
|
|
||||||
var call = t.callExpression(callId, [node]);
|
var call = t.callExpression(callId, [node]);
|
||||||
|
|
||||||
@@ -44,15 +46,15 @@ export default function (node, callId, scope) {
|
|||||||
return declar;
|
return declar;
|
||||||
} else {
|
} else {
|
||||||
if (id) {
|
if (id) {
|
||||||
var state = { id: id };
|
var state = { id };
|
||||||
scope.traverse(node, referenceVisitor, state);
|
path.traverse(referenceVisitor, state);
|
||||||
|
|
||||||
if (state.ref) {
|
if (state.ref) {
|
||||||
scope.parent.push({ id: state.ref });
|
path.scope.parent.push({ id: state.ref });
|
||||||
return t.assignmentExpression("=", state.ref, call);
|
return t.assignmentExpression("=", state.ref, call);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return call;
|
return call;
|
||||||
}
|
}
|
||||||
};
|
}
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
import type NodePath from "../../traversal/path";
|
||||||
import * as messages from "../../messages";
|
import * as messages from "../../messages";
|
||||||
import * as t from "../../types";
|
import * as t from "../../types";
|
||||||
|
|
||||||
@@ -130,7 +131,7 @@ export default class ReplaceSupers {
|
|||||||
* Description
|
* Description
|
||||||
*/
|
*/
|
||||||
|
|
||||||
traverseLevel(path: TraversalPath, topLevel: boolean) {
|
traverseLevel(path: NodePath, topLevel: boolean) {
|
||||||
var state = { self: this, topLevel: topLevel };
|
var state = { self: this, topLevel: topLevel };
|
||||||
path.traverse(visitor, state);
|
path.traverse(visitor, state);
|
||||||
}
|
}
|
||||||
@@ -168,7 +169,13 @@ export default class ReplaceSupers {
|
|||||||
|
|
||||||
if (methodName.name === "constructor") {
|
if (methodName.name === "constructor") {
|
||||||
// constructor() { super(); }
|
// 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 {
|
} else {
|
||||||
id = superRef;
|
id = superRef;
|
||||||
|
|
||||||
@@ -192,7 +199,7 @@ export default class ReplaceSupers {
|
|||||||
* Description
|
* Description
|
||||||
*/
|
*/
|
||||||
|
|
||||||
looseHandle(path: TraversalPath, getThisReference: Function) {
|
looseHandle(path: NodePath, getThisReference: Function) {
|
||||||
var node = path.node;
|
var node = path.node;
|
||||||
if (path.isSuper()) {
|
if (path.isSuper()) {
|
||||||
return this.getLooseSuperProperty(node, path.parent);
|
return this.getLooseSuperProperty(node, path.parent);
|
||||||
@@ -234,7 +241,7 @@ export default class ReplaceSupers {
|
|||||||
* Description
|
* Description
|
||||||
*/
|
*/
|
||||||
|
|
||||||
specHandle(path: TraversalPath, getThisReference: Function) {
|
specHandle(path: NodePath, getThisReference: Function) {
|
||||||
var methodNode = this.methodNode;
|
var methodNode = this.methodNode;
|
||||||
var property;
|
var property;
|
||||||
var computed;
|
var computed;
|
||||||
@@ -274,7 +281,7 @@ export default class ReplaceSupers {
|
|||||||
property = node.property;
|
property = node.property;
|
||||||
computed = node.computed;
|
computed = node.computed;
|
||||||
} else if (t.isUpdateExpression(node) && isMemberExpressionSuper(node.argument)) {
|
} 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) {
|
if (node.prefix) {
|
||||||
// ++super.foo; -> super.foo += 1;
|
// ++super.foo; -> super.foo += 1;
|
||||||
return this.specHandleAssignmentExpression(null, path, binary, getThisReference);
|
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,4 +1,4 @@
|
|||||||
import Pipeline from "./transformer-pipeline";
|
import Pipeline from "./pipeline";
|
||||||
|
|
||||||
var pipeline = new Pipeline;
|
var pipeline = new Pipeline;
|
||||||
|
|
||||||
@@ -8,8 +8,11 @@ import transformers from "./transformers";
|
|||||||
|
|
||||||
for (var key in transformers) {
|
for (var key in transformers) {
|
||||||
var transformer = transformers[key];
|
var transformer = transformers[key];
|
||||||
var metadata = transformer.metadata = transformer.metadata || {};
|
|
||||||
metadata.group = metadata.group || "builtin-basic";
|
if (typeof transformer === "object") {
|
||||||
|
var metadata = transformer.metadata = transformer.metadata || {};
|
||||||
|
metadata.group = metadata.group || "builtin-basic";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pipeline.addTransformers(transformers);
|
pipeline.addTransformers(transformers);
|
||||||
|
|||||||
@@ -1,124 +1,182 @@
|
|||||||
import * as messages from "../../messages";
|
import * as messages from "../../messages";
|
||||||
import traverse from "../../traversal";
|
import Remaps from "./lib/remaps";
|
||||||
import extend from "lodash/object/extend";
|
import extend from "lodash/object/extend";
|
||||||
import object from "../../helpers/object";
|
import object from "../../helpers/object";
|
||||||
import * as util from "../../util";
|
import * as util from "../../util";
|
||||||
import * as t from "../../types";
|
import * as t from "../../types";
|
||||||
|
|
||||||
var remapVisitor = {
|
var metadataVisitor = {
|
||||||
enter(node, parent, scope, formatter) {
|
ModuleDeclaration: {
|
||||||
if (node._skipModulesRemap) {
|
enter(node, parent, scope, formatter) {
|
||||||
return this.skip();
|
if (node.source) {
|
||||||
}
|
node.source.value = formatter.file.resolveModuleSource(node.source.value);
|
||||||
},
|
formatter.addScope(this);
|
||||||
|
|
||||||
ReferencedIdentifier(node, parent, scope, formatter) {
|
|
||||||
var remap = formatter.internalRemap[node.name];
|
|
||||||
|
|
||||||
if (remap && node !== remap) {
|
|
||||||
if (!scope.hasBinding(node.name) || scope.bindingIdentifierEquals(node.name, formatter.localImports[node.name])) {
|
|
||||||
if (this.key === "callee" && this.parentPath.isCallExpression()) {
|
|
||||||
return t.sequenceExpression([t.literal(0), remap]);
|
|
||||||
} else {
|
|
||||||
return remap;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
AssignmentExpression: {
|
|
||||||
exit(node, parent, scope, formatter) {
|
|
||||||
if (!node._ignoreModulesRemap) {
|
|
||||||
var exported = formatter.getExport(node.left, scope);
|
|
||||||
if (exported) {
|
|
||||||
return formatter.remapExportAssignment(node, exported);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
|
|
||||||
UpdateExpression(node, parent, scope, formatter) {
|
|
||||||
var exported = formatter.getExport(node.argument, scope);
|
|
||||||
if (!exported) return;
|
|
||||||
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
var importsVisitor = {
|
|
||||||
ImportDeclaration: {
|
ImportDeclaration: {
|
||||||
enter(node, parent, scope, formatter) {
|
exit(node, parent, scope, formatter) {
|
||||||
formatter.hasLocalImports = true;
|
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
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
},
|
||||||
};
|
|
||||||
|
|
||||||
var exportsVisitor = {
|
ExportDeclaration(node, parent, scope, formatter) {
|
||||||
ExportDeclaration: {
|
formatter.hasLocalExports = true;
|
||||||
enter(node, parent, scope, formatter) {
|
|
||||||
formatter.hasLocalExports = true;
|
|
||||||
|
|
||||||
var declar = this.get("declaration");
|
var source = node.source ? node.source.value : null;
|
||||||
if (declar.isStatement()) {
|
var exports = formatter.metadata.exports;
|
||||||
var bindings = declar.getBindingIdentifiers()
|
|
||||||
for (var name in bindings) {
|
// export function foo() {}
|
||||||
var binding = bindings[name];
|
// export var foo = "bar";
|
||||||
formatter._addExport(name, binding);
|
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
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (this.isExportNamedDeclaration() && node.specifiers) {
|
// export * from "bar";
|
||||||
for (var i = 0; i < node.specifiers.length; i++) {
|
if (this.isExportAllDeclaration()) {
|
||||||
var specifier = node.specifiers[i];
|
exports.specifiers.push({
|
||||||
var local = specifier.local;
|
kind: "external-all",
|
||||||
if (!local) continue;
|
source
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
formatter._addExport(local.name, specifier.exported);
|
if (!t.isExportDefaultDeclaration(node) && !declar.isTypeAlias()) {
|
||||||
}
|
var onlyDefault = node.specifiers && node.specifiers.length === 1 && t.isSpecifierDefault(node.specifiers[0]);
|
||||||
|
if (!onlyDefault) {
|
||||||
|
formatter.hasNonDefaultExports = true;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
if (!t.isExportDefaultDeclaration(node)) {
|
Scope(node, parent, scope, formatter) {
|
||||||
var onlyDefault = node.specifiers && node.specifiers.length === 1 && t.isSpecifierDefault(node.specifiers[0]);
|
if (!formatter.isLoose()) {
|
||||||
if (!onlyDefault) {
|
this.skip();
|
||||||
formatter.hasNonDefaultExports = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
export default class DefaultFormatter {
|
export default class DefaultFormatter {
|
||||||
constructor(file) {
|
constructor(file) {
|
||||||
this.internalRemap = object();
|
// object containg all module sources with the scope that they're contained in
|
||||||
this.defaultIds = object();
|
this.sourceScopes = object();
|
||||||
this.scope = file.scope;
|
|
||||||
this.file = file;
|
// ids for use in module ids
|
||||||
this.ids = object();
|
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;
|
this.hasNonDefaultExports = false;
|
||||||
|
|
||||||
@@ -128,8 +186,20 @@ export default class DefaultFormatter {
|
|||||||
this.localExports = object();
|
this.localExports = object();
|
||||||
this.localImports = object();
|
this.localImports = object();
|
||||||
|
|
||||||
this.getLocalExports();
|
this.metadata = file.metadata.modules;
|
||||||
this.getLocalImports();
|
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) {
|
isModuleType(node, type) {
|
||||||
@@ -145,17 +215,22 @@ export default class DefaultFormatter {
|
|||||||
return (t.isExportDefaultDeclaration(node) || t.isSpecifierDefault(node)) && !this.noInteropRequireExport && !this.hasNonDefaultExports;
|
return (t.isExportDefaultDeclaration(node) || t.isSpecifierDefault(node)) && !this.noInteropRequireExport && !this.hasNonDefaultExports;
|
||||||
}
|
}
|
||||||
|
|
||||||
getLocalExports() {
|
getMetadata() {
|
||||||
this.file.path.traverse(exportsVisitor, this);
|
var has = false;
|
||||||
}
|
for (var node of (this.file.ast.program.body: Array)) {
|
||||||
|
if (t.isModuleDeclaration(node)) {
|
||||||
getLocalImports() {
|
has = true;
|
||||||
this.file.path.traverse(importsVisitor, this);
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (has || this.isLoose()) {
|
||||||
|
this.file.path.traverse(metadataVisitor, this);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
remapAssignments() {
|
remapAssignments() {
|
||||||
if (this.hasLocalExports || this.hasLocalImports) {
|
if (this.hasLocalExports || this.hasLocalImports) {
|
||||||
this.file.path.traverse(remapVisitor, this);
|
this.remaps.run();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -10,4 +10,4 @@ export default function (Parent) {
|
|||||||
util.inherits(Constructor, Parent);
|
util.inherits(Constructor, Parent);
|
||||||
|
|
||||||
return Constructor;
|
return Constructor;
|
||||||
};
|
}
|
||||||
|
|||||||
@@ -6,8 +6,8 @@ import * as util from "../../util";
|
|||||||
import * as t from "../../types";
|
import * as t from "../../types";
|
||||||
|
|
||||||
export default class AMDFormatter extends DefaultFormatter {
|
export default class AMDFormatter extends DefaultFormatter {
|
||||||
init() {
|
setup() {
|
||||||
CommonFormatter.prototype._init.call(this, this.hasNonDefaultExports);
|
CommonFormatter.prototype._setup.call(this, this.hasNonDefaultExports);
|
||||||
}
|
}
|
||||||
|
|
||||||
buildDependencyLiterals() {
|
buildDependencyLiterals() {
|
||||||
@@ -72,7 +72,7 @@ export default class AMDFormatter extends DefaultFormatter {
|
|||||||
this.getExternalReference(node);
|
this.getExternalReference(node);
|
||||||
}
|
}
|
||||||
|
|
||||||
importSpecifier(specifier, node, nodes) {
|
importSpecifier(specifier, node, nodes, scope) {
|
||||||
var key = node.source.value;
|
var key = node.source.value;
|
||||||
var ref = this.getExternalReference(node);
|
var ref = this.getExternalReference(node);
|
||||||
|
|
||||||
@@ -90,11 +90,11 @@ export default class AMDFormatter extends DefaultFormatter {
|
|||||||
// import * as bar from "foo";
|
// import * as bar from "foo";
|
||||||
} else if (!includes(this.file.dynamicImported, node) && t.isSpecifierDefault(specifier) && !this.noInteropRequireImport) {
|
} else if (!includes(this.file.dynamicImported, node) && t.isSpecifierDefault(specifier) && !this.noInteropRequireImport) {
|
||||||
// import foo from "foo";
|
// import foo from "foo";
|
||||||
var uid = this.scope.generateUidIdentifier(specifier.local.name);
|
var uid = scope.generateUidIdentifier(specifier.local.name);
|
||||||
nodes.push(t.variableDeclaration("var", [
|
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 {
|
} else {
|
||||||
// import { foo } from "foo";
|
// import { foo } from "foo";
|
||||||
var imported = specifier.imported;
|
var imported = specifier.imported;
|
||||||
@@ -102,7 +102,7 @@ export default class AMDFormatter extends DefaultFormatter {
|
|||||||
ref = t.memberExpression(ref, imported);
|
ref = t.memberExpression(ref, imported);
|
||||||
}
|
}
|
||||||
|
|
||||||
this.internalRemap[specifier.local.name] = ref;
|
this.remaps.add(scope, specifier.local.name, ref);
|
||||||
}
|
}
|
||||||
|
|
||||||
exportSpecifier(specifier, node, nodes) {
|
exportSpecifier(specifier, node, nodes) {
|
||||||
|
|||||||
@@ -1,14 +1,13 @@
|
|||||||
import DefaultFormatter from "./_default";
|
import DefaultFormatter from "./_default";
|
||||||
import includes from "lodash/collection/includes";
|
|
||||||
import * as util from "../../util";
|
import * as util from "../../util";
|
||||||
import * as t from "../../types";
|
import * as t from "../../types";
|
||||||
|
|
||||||
export default class CommonJSFormatter extends DefaultFormatter {
|
export default class CommonJSFormatter extends DefaultFormatter {
|
||||||
init() {
|
setup() {
|
||||||
this._init(this.hasLocalExports);
|
this._setup(this.hasLocalExports);
|
||||||
}
|
}
|
||||||
|
|
||||||
_init(conditional) {
|
_setup(conditional) {
|
||||||
var file = this.file;
|
var file = this.file;
|
||||||
var scope = file.scope;
|
var scope = file.scope;
|
||||||
|
|
||||||
@@ -38,7 +37,7 @@ export default class CommonJSFormatter extends DefaultFormatter {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
importSpecifier(specifier, node, nodes) {
|
importSpecifier(specifier, node, nodes, scope) {
|
||||||
var variableName = specifier.local;
|
var variableName = specifier.local;
|
||||||
|
|
||||||
var ref = this.getExternalReference(node, nodes);
|
var ref = this.getExternalReference(node, nodes);
|
||||||
@@ -48,9 +47,9 @@ export default class CommonJSFormatter extends DefaultFormatter {
|
|||||||
if (this.isModuleType(node, "absolute")) {
|
if (this.isModuleType(node, "absolute")) {
|
||||||
// absolute module reference
|
// absolute module reference
|
||||||
} else if (this.isModuleType(node, "absoluteDefault")) {
|
} else if (this.isModuleType(node, "absoluteDefault")) {
|
||||||
this.internalRemap[variableName.name] = ref;
|
this.remaps.add(scope, variableName.name, ref);
|
||||||
} else if (this.noInteropRequireImport) {
|
} 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 {
|
} else {
|
||||||
var uid = this.scope.generateUidIdentifierBasedOnNode(node, "import");
|
var uid = this.scope.generateUidIdentifierBasedOnNode(node, "import");
|
||||||
|
|
||||||
@@ -58,7 +57,7 @@ export default class CommonJSFormatter extends DefaultFormatter {
|
|||||||
t.variableDeclarator(uid, t.callExpression(this.file.addHelper("interop-require-default"), [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 {
|
} else {
|
||||||
if (t.isImportNamespaceSpecifier(specifier)) {
|
if (t.isImportNamespaceSpecifier(specifier)) {
|
||||||
@@ -72,7 +71,7 @@ export default class CommonJSFormatter extends DefaultFormatter {
|
|||||||
]));
|
]));
|
||||||
} else {
|
} else {
|
||||||
// import { foo } from "foo";
|
// import { foo } from "foo";
|
||||||
this.internalRemap[variableName.name] = t.memberExpression(ref, specifier.imported);
|
this.remaps.add(scope, variableName.name, t.memberExpression(ref, specifier.imported));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -84,7 +83,7 @@ export default class CommonJSFormatter extends DefaultFormatter {
|
|||||||
}, true));
|
}, true));
|
||||||
}
|
}
|
||||||
|
|
||||||
exportSpecifier(specifier, node, nodes) {
|
exportSpecifier(specifier) {
|
||||||
if (this.doDefaultExportInterop(specifier)) {
|
if (this.doDefaultExportInterop(specifier)) {
|
||||||
this.hasDefaultOnlyExport = true;
|
this.hasDefaultOnlyExport = true;
|
||||||
}
|
}
|
||||||
@@ -92,7 +91,7 @@ export default class CommonJSFormatter extends DefaultFormatter {
|
|||||||
DefaultFormatter.prototype.exportSpecifier.apply(this, arguments);
|
DefaultFormatter.prototype.exportSpecifier.apply(this, arguments);
|
||||||
}
|
}
|
||||||
|
|
||||||
exportDeclaration(node, nodes) {
|
exportDeclaration(node) {
|
||||||
if (this.doDefaultExportInterop(node)) {
|
if (this.doDefaultExportInterop(node)) {
|
||||||
this.hasDefaultOnlyExport = true;
|
this.hasDefaultOnlyExport = true;
|
||||||
}
|
}
|
||||||
@@ -101,8 +100,6 @@ export default class CommonJSFormatter extends DefaultFormatter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
_getExternalReference(node, nodes) {
|
_getExternalReference(node, nodes) {
|
||||||
var source = node.source.value;
|
|
||||||
|
|
||||||
var call = t.callExpression(t.identifier("require"), [node.source]);
|
var call = t.callExpression(t.identifier("require"), [node.source]);
|
||||||
var uid;
|
var uid;
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
|
import DefaultFormatter from "./_default";
|
||||||
import * as t from "../../types";
|
import * as t from "../../types";
|
||||||
|
|
||||||
export default class IgnoreFormatter {
|
export default class IgnoreFormatter extends DefaultFormatter {
|
||||||
exportDeclaration(node, nodes) {
|
exportDeclaration(node, nodes) {
|
||||||
var declar = t.toStatement(node.declaration, true);
|
var declar = t.toStatement(node.declaration, true);
|
||||||
if (declar) nodes.push(t.inherits(declar, node));
|
if (declar) nodes.push(t.inherits(declar, node));
|
||||||
@@ -10,4 +11,5 @@ export default class IgnoreFormatter {
|
|||||||
importDeclaration() {}
|
importDeclaration() {}
|
||||||
importSpecifier() {}
|
importSpecifier() {}
|
||||||
exportSpecifier() {}
|
exportSpecifier() {}
|
||||||
|
transform() {}
|
||||||
}
|
}
|
||||||
|
|||||||
121
src/babel/transformation/modules/lib/remaps.js
Normal file
121
src/babel/transformation/modules/lib/remaps.js
Normal file
@@ -0,0 +1,121 @@
|
|||||||
|
import * as t from "../../../types";
|
||||||
|
|
||||||
|
var remapVisitor = {
|
||||||
|
enter(node) {
|
||||||
|
if (node._skipModulesRemap) {
|
||||||
|
return this.skip();
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
ReferencedIdentifier(node, parent, scope, remaps) {
|
||||||
|
var { formatter } = remaps;
|
||||||
|
|
||||||
|
var remap = remaps.get(scope, node.name);
|
||||||
|
if (!remap || node === remap) return;
|
||||||
|
|
||||||
|
if (!scope.hasBinding(node.name) ||
|
||||||
|
scope.bindingIdentifierEquals(node.name, formatter.localImports[node.name])) {
|
||||||
|
if (!formatter.isLoose() && this.key === "callee" && this.parentPath.isCallExpression()) {
|
||||||
|
return t.sequenceExpression([t.literal(0), remap]);
|
||||||
|
} else {
|
||||||
|
return remap;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
AssignmentExpression: {
|
||||||
|
exit(node, parent, scope, { formatter }) {
|
||||||
|
if (!node._ignoreModulesRemap) {
|
||||||
|
var exported = formatter.getExport(node.left, scope);
|
||||||
|
if (exported) {
|
||||||
|
return formatter.remapExportAssignment(node, exported);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
UpdateExpression(node, parent, scope, { formatter }) {
|
||||||
|
var exported = formatter.getExport(node.argument, scope);
|
||||||
|
if (!exported) return;
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
export default class Remaps {
|
||||||
|
constructor(file, formatter) {
|
||||||
|
this.formatter = formatter;
|
||||||
|
this.file = file;
|
||||||
|
}
|
||||||
|
|
||||||
|
run() {
|
||||||
|
this.file.path.traverse(remapVisitor, this);
|
||||||
|
}
|
||||||
|
|
||||||
|
_getKey(name) {
|
||||||
|
return `${name}:moduleRemap`;
|
||||||
|
}
|
||||||
|
|
||||||
|
get(scope, name) {
|
||||||
|
return scope.getData(this._getKey(name));
|
||||||
|
}
|
||||||
|
|
||||||
|
add(scope, name, val) {
|
||||||
|
if (this.all) {
|
||||||
|
this.all.push({
|
||||||
|
name,
|
||||||
|
scope,
|
||||||
|
node: val
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
return scope.setData(this._getKey(name), val);
|
||||||
|
}
|
||||||
|
|
||||||
|
remove(scope, name) {
|
||||||
|
return scope.removeData(this._getKey(name));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* These methods are used by the system module formatter who needs access to all the remaps
|
||||||
|
* so it can process them into it's specific setter method. We don't do this by default since
|
||||||
|
* no other module formatters need access to this.
|
||||||
|
*/
|
||||||
|
|
||||||
|
getAll() {
|
||||||
|
return this.all;
|
||||||
|
}
|
||||||
|
|
||||||
|
clearAll() {
|
||||||
|
if (this.all) {
|
||||||
|
for (var remap of (this.all: Array)) {
|
||||||
|
remap.scope.removeData(this._getKey(remap.name));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
this.all = [];
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,58 +1,56 @@
|
|||||||
import DefaultFormatter from "./_default";
|
import DefaultFormatter from "./_default";
|
||||||
import AMDFormatter from "./amd";
|
import AMDFormatter from "./amd";
|
||||||
import object from "../../helpers/object";
|
|
||||||
import * as util from "../../util";
|
import * as util from "../../util";
|
||||||
import last from "lodash/array/last";
|
import last from "lodash/array/last";
|
||||||
import each from "lodash/collection/each";
|
|
||||||
import map from "lodash/collection/map";
|
import map from "lodash/collection/map";
|
||||||
import * as t from "../../types";
|
import * as t from "../../types";
|
||||||
|
|
||||||
var hoistVariablesVisitor = {
|
var hoistVariablesVisitor = {
|
||||||
enter(node, parent, scope, state) {
|
Function() {
|
||||||
if (t.isFunction(node)) {
|
// nothing inside is accessible
|
||||||
// nothing inside is accessible
|
this.skip();
|
||||||
return this.skip();
|
},
|
||||||
|
|
||||||
|
VariableDeclaration(node, parent, scope, state) {
|
||||||
|
if (node.kind !== "var" && !t.isProgram(parent)) { // let, const
|
||||||
|
// can't be accessed
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (t.isVariableDeclaration(node)) {
|
// ignore block hoisted nodes as these can be left in
|
||||||
if (node.kind !== "var" && !t.isProgram(parent)) { // let, const
|
if (state.formatter._canHoist(node)) return;
|
||||||
// can't be accessed
|
|
||||||
return;
|
var nodes = [];
|
||||||
|
|
||||||
|
for (var i = 0; i < node.declarations.length; i++) {
|
||||||
|
var declar = node.declarations[i];
|
||||||
|
state.hoistDeclarators.push(t.variableDeclarator(declar.id));
|
||||||
|
if (declar.init) {
|
||||||
|
// no initializer so we can just hoist it as-is
|
||||||
|
var assign = t.expressionStatement(t.assignmentExpression("=", declar.id, declar.init));
|
||||||
|
nodes.push(assign);
|
||||||
}
|
}
|
||||||
|
|
||||||
// ignore block hoisted nodes as these can be left in
|
|
||||||
if (state.formatter._canHoist(node)) return;
|
|
||||||
|
|
||||||
var nodes = [];
|
|
||||||
|
|
||||||
for (var i = 0; i < node.declarations.length; i++) {
|
|
||||||
var declar = node.declarations[i];
|
|
||||||
state.hoistDeclarators.push(t.variableDeclarator(declar.id));
|
|
||||||
if (declar.init) {
|
|
||||||
// no initializer so we can just hoist it as-is
|
|
||||||
var assign = t.expressionStatement(t.assignmentExpression("=", declar.id, declar.init));
|
|
||||||
nodes.push(assign);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// for (var i in test)
|
|
||||||
// for (var i = 0;;)
|
|
||||||
if (t.isFor(parent) && parent.left === node) {
|
|
||||||
return node.declarations[0].id;
|
|
||||||
}
|
|
||||||
|
|
||||||
return nodes;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// for (var i in test)
|
||||||
|
// for (var i = 0;;)
|
||||||
|
if (t.isFor(parent) && (parent.left === node || parent.init === node)) {
|
||||||
|
return node.declarations[0].id;
|
||||||
|
}
|
||||||
|
|
||||||
|
return nodes;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
var hoistFunctionsVisitor = {
|
var hoistFunctionsVisitor = {
|
||||||
enter(node, parent, scope, state) {
|
Function() {
|
||||||
if (t.isFunction(node)) this.skip();
|
this.skip();
|
||||||
|
},
|
||||||
|
|
||||||
|
enter(node, parent, scope, state) {
|
||||||
if (t.isFunctionDeclaration(node) || state.formatter._canHoist(node)) {
|
if (t.isFunctionDeclaration(node) || state.formatter._canHoist(node)) {
|
||||||
state.handlerBody.push(node);
|
state.handlerBody.push(node);
|
||||||
this.remove();
|
this.dangerouslyRemove();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@@ -71,7 +69,7 @@ var runnerSettersVisitor = {
|
|||||||
state.nodes.push(node);
|
state.nodes.push(node);
|
||||||
}
|
}
|
||||||
|
|
||||||
this.remove();
|
this.dangerouslyRemove();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@@ -83,6 +81,8 @@ export default class SystemFormatter extends AMDFormatter {
|
|||||||
this.exportIdentifier = file.scope.generateUidIdentifier("export");
|
this.exportIdentifier = file.scope.generateUidIdentifier("export");
|
||||||
this.noInteropRequireExport = true;
|
this.noInteropRequireExport = true;
|
||||||
this.noInteropRequireImport = true;
|
this.noInteropRequireImport = true;
|
||||||
|
|
||||||
|
this.remaps.clearAll();
|
||||||
}
|
}
|
||||||
|
|
||||||
_addImportSource(node, exportNode) {
|
_addImportSource(node, exportNode) {
|
||||||
@@ -138,13 +138,13 @@ export default class SystemFormatter extends AMDFormatter {
|
|||||||
importSpecifier(specifier, node, nodes) {
|
importSpecifier(specifier, node, nodes) {
|
||||||
AMDFormatter.prototype.importSpecifier.apply(this, arguments);
|
AMDFormatter.prototype.importSpecifier.apply(this, arguments);
|
||||||
|
|
||||||
for (var name in this.internalRemap) {
|
for (var remap of (this.remaps.getAll(): Array)) {
|
||||||
nodes.push(t.variableDeclaration("var", [
|
nodes.push(t.variableDeclaration("var", [
|
||||||
t.variableDeclarator(t.identifier(name), this.internalRemap[name])
|
t.variableDeclarator(t.identifier(remap.name), remap.node)
|
||||||
]));
|
]));
|
||||||
}
|
}
|
||||||
|
|
||||||
this.internalRemap = object();
|
this.remaps.clearAll();
|
||||||
|
|
||||||
this._addImportSource(last(nodes), node);
|
this._addImportSource(last(nodes), node);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,10 +1,11 @@
|
|||||||
import Transformer from "./transformer";
|
import PluginManager from "./file/plugin-manager";
|
||||||
import normalizeAst from "../helpers/normalize-ast";
|
import normalizeAst from "../helpers/normalize-ast";
|
||||||
|
import Plugin from "./plugin";
|
||||||
import assign from "lodash/object/assign";
|
import assign from "lodash/object/assign";
|
||||||
import object from "../helpers/object";
|
import object from "../helpers/object";
|
||||||
import File from "./file";
|
import File from "./file";
|
||||||
|
|
||||||
export default class TransformerPipeline {
|
export default class Pipeline {
|
||||||
constructor() {
|
constructor() {
|
||||||
this.transformers = object();
|
this.transformers = object();
|
||||||
this.namespaces = object();
|
this.namespaces = object();
|
||||||
@@ -20,7 +21,7 @@ export default class TransformerPipeline {
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
addTransformer(key, transformer) {
|
addTransformer(key, plugin) {
|
||||||
if (this.transformers[key]) throw new Error(); // todo: error
|
if (this.transformers[key]) throw new Error(); // todo: error
|
||||||
|
|
||||||
var namespace = key.split(".")[0];
|
var namespace = key.split(".")[0];
|
||||||
@@ -28,7 +29,19 @@ export default class TransformerPipeline {
|
|||||||
this.namespaces[namespace].push(key);
|
this.namespaces[namespace].push(key);
|
||||||
this.namespaces[key] = namespace;
|
this.namespaces[key] = namespace;
|
||||||
|
|
||||||
this.transformers[key] = new Transformer(key, transformer);
|
if (typeof plugin === "function") {
|
||||||
|
plugin = PluginManager.memoisePluginContainer(plugin);
|
||||||
|
plugin.key = key;
|
||||||
|
plugin.metadata.optional = true;
|
||||||
|
|
||||||
|
if (key === "react.displayName") {
|
||||||
|
plugin.metadata.optional = false;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
plugin = new Plugin(key, plugin);
|
||||||
|
}
|
||||||
|
|
||||||
|
this.transformers[key] = plugin;
|
||||||
}
|
}
|
||||||
|
|
||||||
addAliases(names) {
|
addAliases(names) {
|
||||||
@@ -46,21 +59,39 @@ export default class TransformerPipeline {
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
canTransform(transformer, fileOpts) {
|
canTransform(plugin, fileOpts) {
|
||||||
if (transformer.metadata.plugin) return true;
|
if (plugin.metadata.plugin) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
for (var filter of (this.filters: Array)) {
|
for (var filter of (this.filters: Array)) {
|
||||||
var result = filter(transformer, fileOpts);
|
var result = filter(plugin, fileOpts);
|
||||||
if (result != null) return result;
|
if (result != null) return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
analyze(code: string, opts?: Object = {}) {
|
||||||
|
opts.code = false;
|
||||||
|
return this.transform(code, opts);
|
||||||
|
}
|
||||||
|
|
||||||
|
pretransform(code: string, opts?: Object) {
|
||||||
|
var file = new File(opts, this);
|
||||||
|
return file.wrap(code, function () {
|
||||||
|
file.addCode(code);
|
||||||
|
file.parseCode(code);
|
||||||
|
return file;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
transform(code: string, opts?: Object) {
|
transform(code: string, opts?: Object) {
|
||||||
var file = new File(opts, this);
|
var file = new File(opts, this);
|
||||||
return file.wrap(code, function () {
|
return file.wrap(code, function () {
|
||||||
file.addCode(code, true);
|
file.addCode(code);
|
||||||
|
file.parseCode(code);
|
||||||
|
return file.transform();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -71,6 +102,7 @@ export default class TransformerPipeline {
|
|||||||
return file.wrap(code, function () {
|
return file.wrap(code, function () {
|
||||||
file.addCode(code);
|
file.addCode(code);
|
||||||
file.addAst(ast);
|
file.addAst(ast);
|
||||||
|
return file.transform();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
34
src/babel/transformation/plugin-pass.js
Normal file
34
src/babel/transformation/plugin-pass.js
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
import type Transformer from "./transformer";
|
||||||
|
import traverse from "../traversal";
|
||||||
|
import type File from "./file";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This class is responsible for traversing over the provided `File`s
|
||||||
|
* AST and running it's parent transformers handlers over it.
|
||||||
|
*/
|
||||||
|
|
||||||
|
export default class PluginPass {
|
||||||
|
constructor(file: File, plugin: Transformer) {
|
||||||
|
this.plugin = plugin;
|
||||||
|
this.file = file;
|
||||||
|
this.key = plugin.key;
|
||||||
|
|
||||||
|
if (this.canTransform() && plugin.metadata.experimental && !file.opts.experimental) {
|
||||||
|
file.log.warn(`THE TRANSFORMER ${this.key} HAS BEEN MARKED AS EXPERIMENTAL AND IS WIP. USE AT YOUR OWN RISK. ` +
|
||||||
|
"THIS WILL HIGHLY LIKELY BREAK YOUR CODE SO USE WITH **EXTREME** CAUTION. ENABLE THE " +
|
||||||
|
"`experimental` OPTION TO IGNORE THIS WARNING.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
canTransform(): boolean {
|
||||||
|
return this.file.transformerDependencies[this.key] ||
|
||||||
|
this.file.pipeline.canTransform(this.plugin, this.file.opts);
|
||||||
|
}
|
||||||
|
|
||||||
|
transform() {
|
||||||
|
var file = this.file;
|
||||||
|
file.log.debug(`Start transformer ${this.key}`);
|
||||||
|
traverse(file.ast, this.plugin.visitor, file.scope, file);
|
||||||
|
file.log.debug(`Finish transformer ${this.key}`);
|
||||||
|
}
|
||||||
|
}
|
||||||
55
src/babel/transformation/plugin.js
Normal file
55
src/babel/transformation/plugin.js
Normal file
@@ -0,0 +1,55 @@
|
|||||||
|
import PluginPass from "./plugin-pass";
|
||||||
|
import * as messages from "../messages";
|
||||||
|
import isFunction from "lodash/lang/isFunction";
|
||||||
|
import traverse from "../traversal";
|
||||||
|
import assign from "lodash/object/assign";
|
||||||
|
import clone from "lodash/lang/clone";
|
||||||
|
import File from "./file";
|
||||||
|
|
||||||
|
export default class Plugin {
|
||||||
|
constructor(key: string, plugin: Object) {
|
||||||
|
plugin = assign({}, plugin);
|
||||||
|
|
||||||
|
var take = function (key) {
|
||||||
|
var val = plugin[key];
|
||||||
|
delete plugin[key];
|
||||||
|
return val;
|
||||||
|
};
|
||||||
|
|
||||||
|
this.manipulateOptions = take("manipulateOptions");
|
||||||
|
this.metadata = take("metadata") || {};
|
||||||
|
this.dependencies = this.metadata.dependencies || [];
|
||||||
|
this.post = take("post");
|
||||||
|
this.pre = take("pre");
|
||||||
|
|
||||||
|
//
|
||||||
|
|
||||||
|
if (this.metadata.stage != null) {
|
||||||
|
this.metadata.optional = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
|
||||||
|
this.visitor = this.normalize(clone(take("visitor")) || {});
|
||||||
|
this.key = key;
|
||||||
|
}
|
||||||
|
|
||||||
|
normalize(visitor: Object): Object {
|
||||||
|
if (isFunction(visitor)) {
|
||||||
|
visitor = { ast: visitor };
|
||||||
|
}
|
||||||
|
|
||||||
|
traverse.explode(visitor);
|
||||||
|
|
||||||
|
return visitor;
|
||||||
|
}
|
||||||
|
|
||||||
|
buildPass(file: File): PluginPass {
|
||||||
|
// validate Transformer instance
|
||||||
|
if (!(file instanceof File)) {
|
||||||
|
throw new TypeError(messages.get("pluginNotFile", this.key));
|
||||||
|
}
|
||||||
|
|
||||||
|
return new PluginPass(file, this);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
(function () {
|
||||||
|
super(...arguments);
|
||||||
|
})
|
||||||
@@ -1,3 +0,0 @@
|
|||||||
if (SUPER_NAME != null) {
|
|
||||||
SUPER_NAME.apply(this, arguments);
|
|
||||||
}
|
|
||||||
@@ -1,3 +0,0 @@
|
|||||||
if (SUPER_NAME != null) {
|
|
||||||
SUPER_NAME.apply(this, arguments);
|
|
||||||
}
|
|
||||||
@@ -1,5 +0,0 @@
|
|||||||
if (SUPER_NAME != null) {
|
|
||||||
var NATIVE_REF = new SUPER_NAME(...arguments);
|
|
||||||
NATIVE_REF.__proto__ = CLASS_NAME.prototype;
|
|
||||||
return NATIVE_REF;
|
|
||||||
}
|
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
if (VARIABLE_NAME === undefined) VARIABLE_NAME = DEFAULT_VALUE;
|
||||||
@@ -1,8 +1,18 @@
|
|||||||
(function (obj, key, value) {
|
(function (obj, key, value) {
|
||||||
return Object.defineProperty(obj, key, {
|
// Shortcircuit the slow defineProperty path when possible.
|
||||||
value: value,
|
// We are trying to avoid issues where setters defined on the
|
||||||
enumerable: true,
|
// prototype cause side effects under the fast path of simple
|
||||||
configurable: true,
|
// assignment. By checking for existence of the property with
|
||||||
writable: true
|
// the in operator, we can optimize most of this overhead away.
|
||||||
});
|
if (key in obj) {
|
||||||
|
Object.defineProperty(obj, key, {
|
||||||
|
value: value,
|
||||||
|
enumerable: true,
|
||||||
|
configurable: true,
|
||||||
|
writable: true
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
obj[key] = value;
|
||||||
|
}
|
||||||
|
return obj;
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,4 +1,6 @@
|
|||||||
(function get(object, property, receiver) {
|
(function get(object, property, receiver) {
|
||||||
|
if (object === null) object = Function.prototype;
|
||||||
|
|
||||||
var desc = Object.getOwnPropertyDescriptor(object, property);
|
var desc = Object.getOwnPropertyDescriptor(object, property);
|
||||||
|
|
||||||
if (desc === undefined) {
|
if (desc === undefined) {
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
(function (arr, i) {
|
(function () {
|
||||||
if (Array.isArray(arr)) {
|
// Broken out into a separate function to avoid deoptimizations due to the try/catch for the
|
||||||
return arr;
|
// array iterator case.
|
||||||
} else if (Symbol.iterator in Object(arr)) {
|
function sliceIterator(arr, i) {
|
||||||
// this is an expanded form of `for...of` that properly supports abrupt completions of
|
// this is an expanded form of `for...of` that properly supports abrupt completions of
|
||||||
// iterators etc. variable names have been minimised to reduce the size of this massive
|
// iterators etc. variable names have been minimised to reduce the size of this massive
|
||||||
// helper. sometimes spec compliancy is annoying :(
|
// helper. sometimes spec compliancy is annoying :(
|
||||||
@@ -32,7 +32,15 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
return _arr;
|
return _arr;
|
||||||
} else {
|
|
||||||
throw new TypeError("Invalid attempt to destructure non-iterable instance");
|
|
||||||
}
|
}
|
||||||
});
|
|
||||||
|
return function (arr, i) {
|
||||||
|
if (Array.isArray(arr)) {
|
||||||
|
return arr;
|
||||||
|
} else if (Symbol.iterator in Object(arr)) {
|
||||||
|
return sliceIterator(arr, i);
|
||||||
|
} else {
|
||||||
|
throw new TypeError("Invalid attempt to destructure non-iterable instance");
|
||||||
|
}
|
||||||
|
};
|
||||||
|
})();
|
||||||
|
|||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user