Compare commits
497 Commits
v7.0.0-bet
...
v7.0.0-bet
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e6d198eef5 | ||
|
|
86aacad2bc | ||
|
|
6eab6f5863 | ||
|
|
555ee80f43 | ||
|
|
a94cbf760a | ||
|
|
7489f8da7b | ||
|
|
dccaec7691 | ||
|
|
c992f5b61e | ||
|
|
5cd1276a27 | ||
|
|
2af7a33c4e | ||
|
|
ffe04d9195 | ||
|
|
b33823e7f8 | ||
|
|
007bfb6565 | ||
|
|
c8faa34848 | ||
|
|
5bcca0123a | ||
|
|
1d987fb655 | ||
|
|
06e5c46c8d | ||
|
|
52b800decb | ||
|
|
01d969a182 | ||
|
|
7d99a96f9f | ||
|
|
ad1de09b5f | ||
|
|
6b91d6434d | ||
|
|
18796173ab | ||
|
|
eb3334a14e | ||
|
|
5e00c96368 | ||
|
|
b4d18f4764 | ||
|
|
981bff08e4 | ||
|
|
7d641d2e74 | ||
|
|
f2882d570a | ||
|
|
cc5aeb3b50 | ||
|
|
d164f820e6 | ||
|
|
43aa61d6be | ||
|
|
ca1c98b255 | ||
|
|
0963dbddea | ||
|
|
2058e0686e | ||
|
|
c0013264b7 | ||
|
|
442ead701c | ||
|
|
5fb3696955 | ||
|
|
69cca412eb | ||
|
|
3bee37b14d | ||
|
|
bc757c8b75 | ||
|
|
c558dedd7b | ||
|
|
0879a6d608 | ||
|
|
51eef099b3 | ||
|
|
daf0ca8680 | ||
|
|
0200a3e510 | ||
|
|
27c39c512d | ||
|
|
70eb206c03 | ||
|
|
229179b8aa | ||
|
|
6baa36cdc5 | ||
|
|
a40f54f847 | ||
|
|
6226c52f43 | ||
|
|
25153359f7 | ||
|
|
2351a638b5 | ||
|
|
bc6f0f989d | ||
|
|
af7ab71486 | ||
|
|
ac13c302f7 | ||
|
|
b396cdcbe5 | ||
|
|
8dcfabd0d7 | ||
|
|
e45d5c3b65 | ||
|
|
8ff675ad69 | ||
|
|
a955efa3e3 | ||
|
|
51db3e9a5d | ||
|
|
41ca312545 | ||
|
|
a192f8beb4 | ||
|
|
f03adbadf4 | ||
|
|
97145ad01e | ||
|
|
25810d2609 | ||
|
|
5f58117790 | ||
|
|
dca2631ef0 | ||
|
|
ba11d9fa7c | ||
|
|
e06cf20d2e | ||
|
|
df1afa3160 | ||
|
|
cec93c01ce | ||
|
|
0a8367c979 | ||
|
|
ac5d2ba984 | ||
|
|
040ba2bf53 | ||
|
|
98f0808a22 | ||
|
|
bdcfb697a6 | ||
|
|
0341d299c8 | ||
|
|
1a7765712e | ||
|
|
b87c43d894 | ||
|
|
02c4a28608 | ||
|
|
4260ffd7ec | ||
|
|
25c3f0d689 | ||
|
|
21b03c35d3 | ||
|
|
ee1ee0e7ae | ||
|
|
73f8059ea0 | ||
|
|
70e3454d7a | ||
|
|
9dab691302 | ||
|
|
95fc38cecf | ||
|
|
84e76e2d49 | ||
|
|
0d9eef4750 | ||
|
|
d2ed7bbc8d | ||
|
|
5b5ac1f366 | ||
|
|
fa1547d8f8 | ||
|
|
b42b21f25c | ||
|
|
6dca0ff9bf | ||
|
|
3e9b59c0f1 | ||
|
|
3f6c475aae | ||
|
|
5c31e501d7 | ||
|
|
ed6b4e0e40 | ||
|
|
8615b6fe57 | ||
|
|
95fa5a66b1 | ||
|
|
c94355c1c9 | ||
|
|
839bf68d1f | ||
|
|
8198b1b334 | ||
|
|
d608535719 | ||
|
|
0353ce9ed5 | ||
|
|
65ca968f8b | ||
|
|
77445cb044 | ||
|
|
7c4509e280 | ||
|
|
87ae286bc3 | ||
|
|
9c1b3e8dc1 | ||
|
|
39d07638cf | ||
|
|
e887eecda4 | ||
|
|
a3e622ad15 | ||
|
|
494a56df5f | ||
|
|
8060ae5dae | ||
|
|
bd4ebc11c1 | ||
|
|
80cefaff2f | ||
|
|
e9d5073af1 | ||
|
|
c8fb48ffd6 | ||
|
|
55ef39eb87 | ||
|
|
91e1e1728c | ||
|
|
acf509bab5 | ||
|
|
4f312f5739 | ||
|
|
696f84468e | ||
|
|
71fd37067e | ||
|
|
7142a79eb9 | ||
|
|
1a6855eff2 | ||
|
|
1de36948ac | ||
|
|
b28ffedead | ||
|
|
a5edab7393 | ||
|
|
725e6a01c0 | ||
|
|
224ce38882 | ||
|
|
8c46fd159f | ||
|
|
47201db61e | ||
|
|
138d60922c | ||
|
|
cfb386ff03 | ||
|
|
9e7fe0ab49 | ||
|
|
e31e907d5f | ||
|
|
4da4728bf5 | ||
|
|
0112479ba9 | ||
|
|
408124438a | ||
|
|
eab4c0e93e | ||
|
|
d06bf993db | ||
|
|
1076018c4c | ||
|
|
07ff8f30f5 | ||
|
|
e6ba0ab82c | ||
|
|
2afe9404fe | ||
|
|
037fee8ffb | ||
|
|
3a2aa9b862 | ||
|
|
c8b57f777a | ||
|
|
b414387bb1 | ||
|
|
0bb71caad3 | ||
|
|
d6dcbdad48 | ||
|
|
8606b76438 | ||
|
|
34d73ebef0 | ||
|
|
890a45216f | ||
|
|
0a257e8972 | ||
|
|
3616137864 | ||
|
|
f8ab9466d3 | ||
|
|
8f24f91166 | ||
|
|
dbdce0e4e4 | ||
|
|
4595c7fdfd | ||
|
|
1f97b91655 | ||
|
|
b0e1e84471 | ||
|
|
f7c26bf2bf | ||
|
|
a67eb25547 | ||
|
|
485e37fcb0 | ||
|
|
f013dab5fb | ||
|
|
e45b58dcb1 | ||
|
|
339dfddca5 | ||
|
|
0cd868a5f2 | ||
|
|
29db23ed87 | ||
|
|
2679d6775c | ||
|
|
96316dcf88 | ||
|
|
42244123e1 | ||
|
|
4b97e837ea | ||
|
|
3299086955 | ||
|
|
2bded404f3 | ||
|
|
21c7ff3f37 | ||
|
|
341bdab90c | ||
|
|
81149a5cc9 | ||
|
|
5166eef103 | ||
|
|
0ee9a4e612 | ||
|
|
858a2c74e7 | ||
|
|
668358c4d0 | ||
|
|
39b05598a0 | ||
|
|
29eafbbf44 | ||
|
|
7a106025ea | ||
|
|
4f1473da3d | ||
|
|
c62b202e6a | ||
|
|
a084339a15 | ||
|
|
d7987fbbd2 | ||
|
|
8a31eabf5e | ||
|
|
80428dec47 | ||
|
|
61ec5ce957 | ||
|
|
1e41f613bb | ||
|
|
a86d14de61 | ||
|
|
a62cfe9045 | ||
|
|
f797454a18 | ||
|
|
ec882be44d | ||
|
|
ecbf0dd53c | ||
|
|
af3d6526e7 | ||
|
|
95894397eb | ||
|
|
b1c9af3f05 | ||
|
|
ec3722b3f9 | ||
|
|
7ae724f553 | ||
|
|
6597a472b3 | ||
|
|
fdd0789936 | ||
|
|
5b1332457c | ||
|
|
3177f05904 | ||
|
|
9dc178df9a | ||
|
|
75bc9422b8 | ||
|
|
bd98041321 | ||
|
|
6a8c4ab433 | ||
|
|
637bfe76b1 | ||
|
|
3f72f1d637 | ||
|
|
20de23f895 | ||
|
|
d17adf40df | ||
|
|
450a1678f2 | ||
|
|
e9ed0f5f21 | ||
|
|
29d249e3b7 | ||
|
|
6f9b0546ef | ||
|
|
fa2c6c5164 | ||
|
|
43040a4181 | ||
|
|
01f4c2368e | ||
|
|
56cb4baf46 | ||
|
|
b051243a63 | ||
|
|
e808b63c15 | ||
|
|
a6df92f245 | ||
|
|
f4b81ab101 | ||
|
|
360b632881 | ||
|
|
bdfeeb38c6 | ||
|
|
47ada5ab3a | ||
|
|
59ba3959dc | ||
|
|
0200e6256a | ||
|
|
9a26c2b07a | ||
|
|
901571d72f | ||
|
|
b09c729675 | ||
|
|
a36525be45 | ||
|
|
a10c91790f | ||
|
|
ab7d1231ad | ||
|
|
a5df709bc3 | ||
|
|
1dbed5f458 | ||
|
|
40e38646e4 | ||
|
|
9e4dd861ee | ||
|
|
a7bddc02ba | ||
|
|
023f8bd1cb | ||
|
|
c9b99af5a6 | ||
|
|
c8d82d6483 | ||
|
|
db42a5d70f | ||
|
|
0856f89882 | ||
|
|
921702ef8c | ||
|
|
8b57a3e3b9 | ||
|
|
21309cc8d4 | ||
|
|
19708e0154 | ||
|
|
f98dff9189 | ||
|
|
840ba187a7 | ||
|
|
de00d939f0 | ||
|
|
e80488f1d5 | ||
|
|
81c1b49f6a | ||
|
|
55bf55398a | ||
|
|
f0d681a238 | ||
|
|
6d6fe844fd | ||
|
|
edb0a70e14 | ||
|
|
669f6b97b2 | ||
|
|
e2c5f25e97 | ||
|
|
8eee435cd6 | ||
|
|
d260bfaec4 | ||
|
|
c662c2ada2 | ||
|
|
b6e54800b4 | ||
|
|
ae210a46d1 | ||
|
|
017d0e7078 | ||
|
|
b8d1d221f8 | ||
|
|
fed530f6bf | ||
|
|
29d44193cd | ||
|
|
82994ce087 | ||
|
|
586d3b5929 | ||
|
|
d682e32529 | ||
|
|
07ab02f6b2 | ||
|
|
91a114f74a | ||
|
|
6d9887fc0f | ||
|
|
d2a3a8151e | ||
|
|
270ea17fed | ||
|
|
da2aea31f5 | ||
|
|
1d69cd41ca | ||
|
|
a7ec312cfe | ||
|
|
6ff91cfdae | ||
|
|
dfb3795a97 | ||
|
|
353d3199c2 | ||
|
|
bdd70c37e0 | ||
|
|
9d2d499760 | ||
|
|
29807837bb | ||
|
|
c14a6a7735 | ||
|
|
3a7881379a | ||
|
|
f3f0197890 | ||
|
|
8e030e28b3 | ||
|
|
3c8e9acd4a | ||
|
|
958551fd89 | ||
|
|
b5e6536f26 | ||
|
|
0389035e15 | ||
|
|
4f4dd3d4a6 | ||
|
|
4da3f3bc64 | ||
|
|
7901e7d1b9 | ||
|
|
4b6c7ac0f6 | ||
|
|
24a07fc790 | ||
|
|
1c9b0ff49e | ||
|
|
828e9a8538 | ||
|
|
f97d4313c9 | ||
|
|
2a0071028d | ||
|
|
2c0d492674 | ||
|
|
e42cbb40a4 | ||
|
|
74ab2798e2 | ||
|
|
fef5c7e523 | ||
|
|
53825f8152 | ||
|
|
40819f112c | ||
|
|
2d36549541 | ||
|
|
7e423de911 | ||
|
|
8317f8ab14 | ||
|
|
65dcc4eabe | ||
|
|
c8992e4155 | ||
|
|
50b9fbb570 | ||
|
|
5d615dd198 | ||
|
|
eb2a0b0fcd | ||
|
|
eaa31b6ec3 | ||
|
|
4d76d5dddc | ||
|
|
a86d311986 | ||
|
|
a340a2614f | ||
|
|
f9857ca6ba | ||
|
|
f43bf7fcd5 | ||
|
|
653318b7e4 | ||
|
|
d187c26748 | ||
|
|
fc64ab5725 | ||
|
|
5cd8b5b7f0 | ||
|
|
a328b6ad1a | ||
|
|
15a80f0df8 | ||
|
|
a4795408b4 | ||
|
|
5f6e3122a0 | ||
|
|
7f8f4e86dc | ||
|
|
5c3092d86f | ||
|
|
7cc00cce0d | ||
|
|
beb99dfda1 | ||
|
|
5f9539e9cc | ||
|
|
aa669ef902 | ||
|
|
c92e8be612 | ||
|
|
ab1e295c74 | ||
|
|
ae0df86340 | ||
|
|
41bf66bca2 | ||
|
|
212058148c | ||
|
|
785131d8e6 | ||
|
|
81532103da | ||
|
|
cc6e739f15 | ||
|
|
3e95830646 | ||
|
|
53208d6998 | ||
|
|
fdfbd9a6f7 | ||
|
|
007f8d19b3 | ||
|
|
586ba35950 | ||
|
|
1a454f666c | ||
|
|
a07f96ce3f | ||
|
|
2c3eb3096f | ||
|
|
148e6dfc26 | ||
|
|
ddd40bf5c7 | ||
|
|
bf8b25289b | ||
|
|
b19b7fd2cf | ||
|
|
f004972625 | ||
|
|
5459c75d64 | ||
|
|
8e3e6e0a88 | ||
|
|
d4a8c7672c | ||
|
|
600106b9cb | ||
|
|
dffcef785a | ||
|
|
cb4f4f4d5f | ||
|
|
7ff4a73916 | ||
|
|
8823e4247e | ||
|
|
6f3be3a543 | ||
|
|
6f6c8dabba | ||
|
|
960fa66c9e | ||
|
|
df50cddd63 | ||
|
|
455c04e60a | ||
|
|
182fe7b04e | ||
|
|
959865b48d | ||
|
|
62c1046249 | ||
|
|
70627ac92c | ||
|
|
a99e9614a6 | ||
|
|
cfb830b5bd | ||
|
|
84de90e572 | ||
|
|
d283324f8a | ||
|
|
d75a6b8468 | ||
|
|
dad05ed503 | ||
|
|
7e90d56024 | ||
|
|
3d49766f6b | ||
|
|
4d17a96d50 | ||
|
|
6cbc585cf4 | ||
|
|
ee6dfd1580 | ||
|
|
e732ee0c5b | ||
|
|
128fc6864e | ||
|
|
6aed8e944f | ||
|
|
4d164bd8e6 | ||
|
|
ea3f2d9299 | ||
|
|
88a0f52230 | ||
|
|
4a2e1dbbc3 | ||
|
|
2979dd99ac | ||
|
|
534ee4734c | ||
|
|
a01007a3d3 | ||
|
|
493996e02a | ||
|
|
c03a34e509 | ||
|
|
92580e750d | ||
|
|
213805f21e | ||
|
|
28d13cb09b | ||
|
|
9a8ba76e1f | ||
|
|
d88173b9f8 | ||
|
|
85174b6ce1 | ||
|
|
ec2e0b664a | ||
|
|
a3ad518ce1 | ||
|
|
dd0337cc85 | ||
|
|
4887d81929 | ||
|
|
22555cd15d | ||
|
|
593c1a0861 | ||
|
|
7234442fde | ||
|
|
5ea1bfe780 | ||
|
|
2254ed45d2 | ||
|
|
278cd5e572 | ||
|
|
96c0415c86 | ||
|
|
ed98d2491e | ||
|
|
eb38ea2b10 | ||
|
|
f19d559ff3 | ||
|
|
73e64c6cb0 | ||
|
|
3deb246c7d | ||
|
|
1ebc229fa5 | ||
|
|
cc4913699b | ||
|
|
82b6ee734b | ||
|
|
22c8f6376c | ||
|
|
023550c87b | ||
|
|
8e0d247e8c | ||
|
|
65ae4ff15b | ||
|
|
2185256589 | ||
|
|
3316a554bf | ||
|
|
252ea5a966 | ||
|
|
912bcc186d | ||
|
|
63ae923987 | ||
|
|
dde9274986 | ||
|
|
ba111c13b5 | ||
|
|
967414d926 | ||
|
|
92fc26d399 | ||
|
|
fa5eb4f605 | ||
|
|
d6a782b09c | ||
|
|
567d25cfa5 | ||
|
|
1da831baa4 | ||
|
|
b0d8c62d1c | ||
|
|
0e570eceb2 | ||
|
|
ca18ea5e79 | ||
|
|
63d9998aa4 | ||
|
|
88e550c733 | ||
|
|
b96fdf8780 | ||
|
|
180eda3211 | ||
|
|
b3969d35fa | ||
|
|
dccfed3601 | ||
|
|
5759c33b4c | ||
|
|
193bccc93c | ||
|
|
5ce54799ff | ||
|
|
064c17e03f | ||
|
|
f9804e6beb | ||
|
|
47ce7e71c9 | ||
|
|
5ac8ba19a4 | ||
|
|
b5d20ab171 | ||
|
|
539009a980 | ||
|
|
c3654d83c8 | ||
|
|
667f5815c1 | ||
|
|
4f39e6ea4a | ||
|
|
64dfb7574e | ||
|
|
d36b142e30 | ||
|
|
3c8d831fe4 | ||
|
|
0a517b51cd | ||
|
|
79c84f2f9b | ||
|
|
ca86648726 | ||
|
|
2d05487293 | ||
|
|
c3352ad2e0 | ||
|
|
26e4911eb2 | ||
|
|
aa888e666a | ||
|
|
8659e1a88c | ||
|
|
9e384f3915 | ||
|
|
f694b5d034 | ||
|
|
d765573c0b | ||
|
|
64161fa0b5 | ||
|
|
52f22e9e1e | ||
|
|
3e5fce07e4 | ||
|
|
0f42accb87 | ||
|
|
07e69c009b | ||
|
|
ce420ba51c | ||
|
|
9fe30b98a1 | ||
|
|
0a9f136d5f | ||
|
|
e9ed687666 | ||
|
|
63157159ab | ||
|
|
74682f33bc | ||
|
|
b1bf7798ab |
@@ -1,5 +0,0 @@
|
||||
# Ensure babel-register won't compile fixtures, or try to recompile compiled code.
|
||||
packages/*/test/fixtures
|
||||
packages/*/lib
|
||||
packages/babel-standalone/babel.js
|
||||
packages/babel-preset-env-standalone/babel-preset-env.js
|
||||
63
.babelrc.js
63
.babelrc.js
@@ -1,63 +0,0 @@
|
||||
"use strict";
|
||||
|
||||
// Blame Logan for this.
|
||||
// This works around https://github.com/istanbuljs/istanbuljs/issues/92 until
|
||||
// we have a version of Istanbul that actually works with 7.x.
|
||||
function istanbulHacks() {
|
||||
return {
|
||||
inherits: require("babel-plugin-istanbul").default,
|
||||
visitor: {
|
||||
Program: {
|
||||
exit: function(path) {
|
||||
if (!this.__dv__) return
|
||||
|
||||
const node = path.node.body[0];
|
||||
if (
|
||||
node.type !== "VariableDeclaration" ||
|
||||
node.declarations[0].id.type !== "Identifier" ||
|
||||
!node.declarations[0].id.name.match(/cov_/) ||
|
||||
node._blockHoist !== 3
|
||||
) {
|
||||
throw new Error("Something has gone wrong in Logan's hacks.");
|
||||
}
|
||||
|
||||
// Gross hacks to put the code coverage block above all compiled
|
||||
// import statement output.
|
||||
node._blockHoist = 5;
|
||||
},
|
||||
},
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
let envOpts = {
|
||||
loose: true,
|
||||
};
|
||||
|
||||
const config = {
|
||||
comments: false,
|
||||
presets: [
|
||||
["@babel/env", envOpts],
|
||||
"@babel/flow"
|
||||
],
|
||||
plugins: [
|
||||
["@babel/proposal-class-properties", { loose: true }],
|
||||
"@babel/proposal-export-namespace-from",
|
||||
"@babel/proposal-numeric-separator",
|
||||
["@babel/proposal-object-rest-spread", { useBuiltIns: true }],
|
||||
]
|
||||
};
|
||||
|
||||
if (process.env.BABEL_ENV === "cov") {
|
||||
config.auxiliaryCommentBefore = "istanbul ignore next";
|
||||
config.plugins.push(istanbulHacks);
|
||||
}
|
||||
|
||||
if (process.env.BABEL_ENV === "development") {
|
||||
envOpts.targets = {
|
||||
node: "current"
|
||||
};
|
||||
envOpts.debug = true;
|
||||
}
|
||||
|
||||
module.exports = config;
|
||||
56
.circleci/config.yml
Normal file
56
.circleci/config.yml
Normal file
@@ -0,0 +1,56 @@
|
||||
version: 2
|
||||
aliases:
|
||||
- &restore-node-modules-cache
|
||||
keys:
|
||||
- v1-yarn-deps-{{ checksum "yarn.lock" }}
|
||||
|
||||
- &restore-yarn-cache
|
||||
keys:
|
||||
- v1-yarn-cache
|
||||
|
||||
- &save-node-modules-cache
|
||||
paths:
|
||||
- node_modules
|
||||
key: v1-yarn-deps-{{ checksum "yarn.lock" }}
|
||||
|
||||
- &save-yarn-cache
|
||||
paths:
|
||||
- ~/.yarn-cache
|
||||
key: v1-yarn-cache
|
||||
|
||||
- &artifact_babel
|
||||
path: ~/babel/packages/babel-standalone/babel.js
|
||||
|
||||
- &artifact_babel_min
|
||||
path: ~/babel/packages/babel-standalone/babel.min.js
|
||||
|
||||
- &artifact_env
|
||||
path: ~/babel/packages/babel-preset-env-standalone/babel-preset-env.js
|
||||
|
||||
- &artifact_env_min
|
||||
path: ~/babel/packages/babel-preset-env-standalone/babel-preset-env.min.js
|
||||
|
||||
jobs:
|
||||
build:
|
||||
working_directory: ~/babel
|
||||
docker:
|
||||
- image: circleci/node:9
|
||||
steps:
|
||||
- checkout
|
||||
- restore-cache: *restore-yarn-cache
|
||||
- restore-cache: *restore-node-modules-cache
|
||||
- run: yarn --version
|
||||
- run: make test-ci-coverage
|
||||
# Builds babel-standalone with the regular Babel config
|
||||
- run: make build
|
||||
# test-ci-coverage doesn't test babel-standalone, as trying to gather coverage
|
||||
# data for a JS file that's several megabytes large is bound to fail. Here,
|
||||
# we just run the babel-standalone test separately.
|
||||
- run: ./node_modules/.bin/jest packages/babel-standalone/test/
|
||||
- run: ./node_modules/.bin/jest packages/babel-preset-env-standalone/test/
|
||||
- store_artifacts: *artifact_babel
|
||||
- store_artifacts: *artifact_babel_min
|
||||
- store_artifacts: *artifact_env
|
||||
- store_artifacts: *artifact_env_min
|
||||
- save_cache: *save-node-modules-cache
|
||||
- save_cache: *save-yarn-cache
|
||||
@@ -1,4 +1,8 @@
|
||||
/lib
|
||||
/build
|
||||
/.git
|
||||
package.json
|
||||
lerna.json
|
||||
packages/babel-runtime
|
||||
!packages/babel-runtime/scripts
|
||||
!packages/babel-runtime/core-js.js
|
||||
@@ -18,5 +22,4 @@ packages/babel-preset-env-standalone/babel-preset-env.js
|
||||
packages/babel-preset-env-standalone/babel-preset-env.min.js
|
||||
packages/babel-standalone/babel.js
|
||||
packages/babel-standalone/babel.min.js
|
||||
packages/babylon/build
|
||||
packages/babylon/test/expressions
|
||||
packages/babel-parser/test/expressions
|
||||
|
||||
35
.eslintrc
35
.eslintrc
@@ -1,35 +0,0 @@
|
||||
{
|
||||
"extends": "babel",
|
||||
"plugins": [
|
||||
"prettier"
|
||||
],
|
||||
"rules": {
|
||||
"curly": ["error", "multi-line"],
|
||||
"prettier/prettier": "error",
|
||||
"no-case-declarations": "error"
|
||||
},
|
||||
"env": {
|
||||
"node": true
|
||||
},
|
||||
"overrides": [
|
||||
{
|
||||
"files": [
|
||||
"packages/*/src/**/*.js",
|
||||
"codemods/*/src/**/*.js"
|
||||
],
|
||||
"rules": {
|
||||
"no-undefined-identifier": "error"
|
||||
}
|
||||
},
|
||||
{
|
||||
"files": [
|
||||
"packages/*/test/**/*.js",
|
||||
"codemods/*/test/**/*.js",
|
||||
"test/**/*.js"
|
||||
],
|
||||
"env": {
|
||||
"mocha": true
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
33
.eslintrc.json
Normal file
33
.eslintrc.json
Normal file
@@ -0,0 +1,33 @@
|
||||
{
|
||||
"root": true,
|
||||
"extends": "babel",
|
||||
"plugins": ["prettier"],
|
||||
"rules": {
|
||||
"curly": ["error", "multi-line"],
|
||||
"prettier/prettier": "error",
|
||||
"no-case-declarations": "error"
|
||||
},
|
||||
"env": {
|
||||
"node": true
|
||||
},
|
||||
"overrides": [
|
||||
{
|
||||
"files": ["packages/*/src/**/*.js", "codemods/*/src/**/*.js"],
|
||||
"rules": {
|
||||
"no-undefined-identifier": "error",
|
||||
"no-deprecated-clone": "error"
|
||||
}
|
||||
},
|
||||
{
|
||||
"files": [
|
||||
"packages/*/test/**/*.js",
|
||||
"codemods/*/test/**/*.js",
|
||||
"packages/babel-helper-transform-fixture-test-runner/src/helpers.js",
|
||||
"test/**/*.js"
|
||||
],
|
||||
"env": {
|
||||
"jest": true
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -13,8 +13,8 @@ codemods/*/src
|
||||
[libs]
|
||||
lib/file.js
|
||||
lib/parser.js
|
||||
lib/types.js
|
||||
lib/third-party-libs.js.flow
|
||||
packages/babel-types/lib/index.js.flow
|
||||
|
||||
[options]
|
||||
include_warnings=true
|
||||
|
||||
59
.github/ISSUE_TEMPLATE.md
vendored
59
.github/ISSUE_TEMPLATE.md
vendored
@@ -1,63 +1,6 @@
|
||||
<!---
|
||||
Thanks for filing an issue 😄 ! Before you submit, please read the following:
|
||||
|
||||
Check the other issue templates if you are trying to submit a bug report, feature request, or question
|
||||
Search open/closed issues before submitting since someone might have asked the same thing before!
|
||||
|
||||
If you have a support request or question please submit them to one of this resources:
|
||||
|
||||
* Slack Community: https://slack.babeljs.io/
|
||||
* StackOverflow: http://stackoverflow.com/questions/tagged/babeljs using the tag `babeljs`
|
||||
* Also have a look at the readme for more information on how to get support:
|
||||
https://github.com/babel/babel/blob/master/README.md
|
||||
|
||||
Issues on GitHub are only related to problems of Babel itself and we cannot answer
|
||||
support questions here.
|
||||
-->
|
||||
|
||||
Choose one: is this a bug report or feature request?
|
||||
|
||||
<!--- Provide a general summary of the issue in the title above -->
|
||||
|
||||
### Input Code
|
||||
<!--- If you're describing a bug, please let us know which sample code reproduces your problem -->
|
||||
<!--- If you have link to our REPL or a standalone repo please link that! -->
|
||||
|
||||
```js
|
||||
var your => (code) => here;
|
||||
```
|
||||
|
||||
### Babel/Babylon Configuration (.babelrc, package.json, cli command)
|
||||
<!--- If describing a bug, tell us what your babel configuration looks like -->
|
||||
|
||||
```js
|
||||
{
|
||||
"your": { "config": "here" }
|
||||
}
|
||||
```
|
||||
|
||||
### Expected Behavior
|
||||
<!--- If you're describing a bug, tell us what should happen -->
|
||||
<!--- If you're suggesting a change/improvement, tell us how it should work -->
|
||||
|
||||
### Current Behavior
|
||||
<!--- If describing a bug, tell us what happens instead of the expected behavior -->
|
||||
<!--- If suggesting a change/improvement, explain the difference from current behavior -->
|
||||
|
||||
### Possible Solution
|
||||
<!--- Not obligatory, but suggest a fix/reason for the bug, -->
|
||||
<!--- or ideas how to implement the addition or change -->
|
||||
|
||||
### Context
|
||||
<!--- How has this issue affected you? What are you trying to accomplish? -->
|
||||
<!--- Providing context helps us come up with a solution that is most useful in the real world -->
|
||||
|
||||
### Your Environment
|
||||
<!--- Include as many relevant details about the environment you experienced the bug in -->
|
||||
|
||||
| software | version(s)
|
||||
| ---------------- | -------
|
||||
| Babel |
|
||||
| Babylon | <!-- This is only needed if you are using Babylon directly -->
|
||||
| node |
|
||||
| npm |
|
||||
| Operating System |
|
||||
|
||||
41
.github/ISSUE_TEMPLATE/Bug_report.md
vendored
Normal file
41
.github/ISSUE_TEMPLATE/Bug_report.md
vendored
Normal file
@@ -0,0 +1,41 @@
|
||||
---
|
||||
name: 🐛 Bug Report
|
||||
about: If something isn't working as expected 🤔.
|
||||
|
||||
---
|
||||
|
||||
## Bug Report
|
||||
|
||||
**Current Behavior**
|
||||
A clear and concise description of the behavior.
|
||||
|
||||
**Input Code**
|
||||
- REPL or Repo link if applicable:
|
||||
|
||||
```js
|
||||
var your => (code) => here;
|
||||
```
|
||||
|
||||
**Expected behavior/code**
|
||||
A clear and concise description of what you expected to happen (or code).
|
||||
|
||||
**Babel Configuration (.babelrc, package.json, cli command)**
|
||||
|
||||
```js
|
||||
{
|
||||
"your": { "config": "here" }
|
||||
}
|
||||
```
|
||||
|
||||
**Environment**
|
||||
- Babel version(s): [e.g. v6.0.0, v7.0.0-beta.34]
|
||||
- Node/npm version: [e.g. Node 8/npm 5]
|
||||
- OS: [e.g. OSX 10.13.4, Windows 10]
|
||||
- Monorepo [e.g. yes/no/Lerna]
|
||||
- How you are using Babel: [e.g. `cli`, `register`, `loader`]
|
||||
|
||||
**Possible Solution**
|
||||
<!--- Only if you have suggestions on a fix for the bug -->
|
||||
|
||||
**Additional context/Screenshots**
|
||||
Add any other context about the problem here. If applicable, add screenshots to help explain.
|
||||
20
.github/ISSUE_TEMPLATE/Feature_request.md
vendored
Normal file
20
.github/ISSUE_TEMPLATE/Feature_request.md
vendored
Normal file
@@ -0,0 +1,20 @@
|
||||
---
|
||||
name: 🚀 Feature Request
|
||||
about: I have a suggestion (and may want to implement it 🙂)!
|
||||
|
||||
---
|
||||
|
||||
## Feature Request
|
||||
|
||||
**Is your feature request related to a problem? Please describe.**
|
||||
A clear and concise description of what the problem is. Ex. I have an issue when [...]
|
||||
|
||||
**Describe the solution you'd like**
|
||||
A clear and concise description of what you want to happen. Add any considered drawbacks.
|
||||
|
||||
**Describe alternatives you've considered**
|
||||
A clear and concise description of any alternative solutions or features you've considered.
|
||||
|
||||
**Teachability, Documentation, Adoption, Migration Strategy**
|
||||
If you can, explain how users will be able to use this and possibly write out a version the docs.
|
||||
Maybe a screenshot or design?
|
||||
41
.github/ISSUE_TEMPLATE/Regression-v7.md
vendored
Normal file
41
.github/ISSUE_TEMPLATE/Regression-v7.md
vendored
Normal file
@@ -0,0 +1,41 @@
|
||||
---
|
||||
name: 💥 v7 Regression
|
||||
about: Report an unexpected behavior in v7 from v6 (Check the upgrade guide first ✌️)
|
||||
|
||||
---
|
||||
|
||||
# v7 Regression
|
||||
|
||||
> First check out: https://new.babeljs.io/docs/en/next/v7-migration.html
|
||||
> Also a partial upgrade tool: https://github.com/babel/babel-upgrade
|
||||
|
||||
**Potential Commit/PR that introduced the regression**
|
||||
If you have time to investigate, what PR/date introduced this issue.
|
||||
|
||||
**Describe the regression**
|
||||
A clear and concise description of what the regression is.
|
||||
|
||||
**Input Code**
|
||||
<!--- If you have link to our REPL or a standalone repo please link that! -->
|
||||
|
||||
```js
|
||||
var your => (code) => here;
|
||||
```
|
||||
|
||||
**Babel Configuration (.babelrc, package.json, cli command)**
|
||||
|
||||
```js
|
||||
{
|
||||
"your": { "config": "here" }
|
||||
}
|
||||
```
|
||||
|
||||
**Expected behavior/code**
|
||||
A clear and concise description of what you expected to happen (or code).
|
||||
|
||||
**Environment**
|
||||
- Babel version(s): [e.g. v6.0.0, v7.0.0-beta.34]
|
||||
- Node/npm version: [e.g. Node 8/npm 5]
|
||||
- OS: [e.g. OSX 10.13.4, Windows 10]
|
||||
- Monorepo [e.g. yes/no/Lerna]
|
||||
- How you are using Babel: [e.g. `cli`, `register`, `loader`]
|
||||
16
.github/ISSUE_TEMPLATE/Support_question.md
vendored
Normal file
16
.github/ISSUE_TEMPLATE/Support_question.md
vendored
Normal file
@@ -0,0 +1,16 @@
|
||||
---
|
||||
name: 🤗 Support Question
|
||||
about: If you have a question 💬, please check out our Slack or StackOverflow!
|
||||
|
||||
---
|
||||
|
||||
--------------^ Click "Preview" for a nicer view!
|
||||
We primarily use GitHub as an issue tracker; for usage and support questions, please check out these resources below. Thanks! 😁.
|
||||
|
||||
---
|
||||
|
||||
* Slack Community Chat: https://babeljs.slack.com (you can sign-up at https://slack.babeljs.io/ for an invite)
|
||||
* StackOverflow: https://stackoverflow.com/questions/tagged/babeljs using the tag `babeljs`
|
||||
* Twitter: If it's just a quick question you can ping our Twitter: https://twitter.com/babeljs
|
||||
* Also have a look at the readme for more information on how to get support:
|
||||
https://github.com/babel/babel/blob/master/README.md
|
||||
24
.github/ISSUE_TEMPLATE/Support_us.md
vendored
Normal file
24
.github/ISSUE_TEMPLATE/Support_us.md
vendored
Normal file
@@ -0,0 +1,24 @@
|
||||
---
|
||||
name: 🤝 Support us on Babel
|
||||
about: If you would like to support our efforts in maintaining this community-driven project 🙌!
|
||||
|
||||
---
|
||||
|
||||
--------------^ Click "Preview" for a nicer view!
|
||||
> Open Collective: https://opencollective.com/babel
|
||||
> Henry's Patreon: https://www.patreon.com/henryzhu
|
||||
|
||||
Help support Babel!
|
||||
|
||||
Babel has always been a community project, not really backed or owned by any single (or group) of companies. While some maintainers used to work at Facebook (and Henry at Adobe) no one was working on it full time and there certainly isn't a huge company or team anywhere doing all this work.
|
||||
|
||||
---
|
||||
|
||||
As a group of volunteers you can help us in a few ways
|
||||
|
||||
- Giving developer time on the project. (Message us on [Twitter](https://twitter.com/babeljs) or [Slack](https://slack.babeljs.io/) for guidance). Companies should be paying their employees to contribute back to the open source projects they use everyday.
|
||||
- Giving funds by becoming one of our sponsors/donators!
|
||||
|
||||
If you'd like to sustain the future of the project as a whole, we have an [Open Collective](https://opencollective.com/babel) that you can donate to. This is a way for funds to be allocated to the core team.
|
||||
|
||||
You can also support [Henry](https://github.com/hzoo) directly since I [left my job to work on Babel and Open Source full time](https://twitter.com/left_pad/status/969793227862790144) at my [Patreon](https://www.patreon.com/henryzhu).
|
||||
12
.github/lock.yml
vendored
Normal file
12
.github/lock.yml
vendored
Normal file
@@ -0,0 +1,12 @@
|
||||
# Configuration for lock-threads - https://github.com/dessant/lock-threads
|
||||
|
||||
# Number of days of inactivity before a closed issue or pull request is locked
|
||||
daysUntilLock: 91
|
||||
# Comment to post before locking. Set to `false` to disable
|
||||
lockComment: false
|
||||
only: issues
|
||||
lockLabel: 'outdated'
|
||||
|
||||
# Issues or pull requests with these labels will not be locked
|
||||
# exemptLabels:
|
||||
# - no-locking
|
||||
7
.gitignore
vendored
7
.gitignore
vendored
@@ -16,15 +16,19 @@ package-lock.json
|
||||
!/packages/babel-runtime/core-js/map.js
|
||||
/packages/babel-runtime/helpers/*.js
|
||||
!/packages/babel-runtime/helpers/toArray.js
|
||||
!/packages/babel-runtime/helpers/iterableToArray.js
|
||||
!/packages/babel-runtime/helpers/temporalRef.js
|
||||
/packages/babel-runtime/helpers/builtin/*.js
|
||||
!/packages/babel-runtime/helpers/builtin/toArray.js
|
||||
!/packages/babel-runtime/helpers/builtin/iterableToArray.js
|
||||
!/packages/babel-runtime/helpers/builtin/temporalRef.js
|
||||
/packages/babel-runtime/helpers/builtin/es6/*.js
|
||||
!/packages/babel-runtime/helpers/builtin/es6/toArray.js
|
||||
!/packages/babel-runtime/helpers/builtin/es6/iterableToArray.js
|
||||
!/packages/babel-runtime/helpers/builtin/es6/temporalRef.js
|
||||
/packages/babel-runtime/helpers/es6/*.js
|
||||
!/packages/babel-runtime/helpers/es6/toArray.js
|
||||
!/packages/babel-runtime/helpers/es6/iterableToArray.js
|
||||
!/packages/babel-runtime/helpers/es6/temporalRef.js
|
||||
/packages/babel-register/test/.babel
|
||||
/packages/babel-cli/test/tmp
|
||||
@@ -38,5 +42,6 @@ packages/babel-preset-env-standalone/babel-preset-env.js
|
||||
packages/babel-preset-env-standalone/babel-preset-env.min.js
|
||||
/codemods/*/lib
|
||||
/codemods/*/node_modules
|
||||
/packages/babylon/build
|
||||
/packages/babel-parser/build
|
||||
.idea/
|
||||
/.changelog
|
||||
|
||||
2
.prettierignore
Normal file
2
.prettierignore
Normal file
@@ -0,0 +1,2 @@
|
||||
package.json
|
||||
packages/babel-preset-env/data
|
||||
@@ -1,5 +1,14 @@
|
||||
{
|
||||
"arrowParens": "avoid",
|
||||
"trailingComma": "es5",
|
||||
"useTabs": false,
|
||||
"semi": true,
|
||||
"singleQuote": false,
|
||||
"bracketSpacing": true,
|
||||
"jsxBracketSameLine": false,
|
||||
"tabWidth": 2,
|
||||
"parser": "babylon",
|
||||
"printWidth": 80,
|
||||
"overrides": [{
|
||||
"files": [
|
||||
"**/codemods/*/src/**/*.js",
|
||||
|
||||
18
.travis.yml
18
.travis.yml
@@ -5,11 +5,11 @@ language: node_js
|
||||
cache:
|
||||
yarn: true
|
||||
directories:
|
||||
- node_modules
|
||||
- node_modules
|
||||
node_js:
|
||||
# We test the latest version on circleci
|
||||
- '8'
|
||||
- '6'
|
||||
- '4'
|
||||
|
||||
env:
|
||||
global:
|
||||
@@ -19,15 +19,17 @@ env:
|
||||
before_install:
|
||||
- curl -o- -L https://yarnpkg.com/install.sh | bash
|
||||
|
||||
install: yarn --ignore-engines
|
||||
|
||||
before_script:
|
||||
- 'if [ "$JOB" = "babylon-flow-tests" ]; then make bootstrap-flow; fi'
|
||||
- 'if [ "$JOB" = "babylon-test262-tests" ]; then make bootstrap-test262; fi'
|
||||
- 'if [ "$JOB" = "babel-parser-flow-tests" ]; then make bootstrap-flow; fi'
|
||||
- 'if [ "$JOB" = "babel-parser-test262-tests" ]; then make bootstrap-test262; fi'
|
||||
|
||||
script:
|
||||
- 'if [ "$JOB" = "test" ]; then make test-ci; fi'
|
||||
- 'if [ "$JOB" = "lint" ]; then make lint && make flow; fi'
|
||||
- 'if [ "$JOB" = "babylon-flow-tests" ]; then make test-flow-ci; fi'
|
||||
- 'if [ "$JOB" = "babylon-test262-tests" ]; then make test-test262-ci; fi'
|
||||
- 'if [ "$JOB" = "babel-parser-flow-tests" ]; then make test-flow-ci; fi'
|
||||
- 'if [ "$JOB" = "babel-parser-test262-tests" ]; then make test-test262-ci; fi'
|
||||
|
||||
matrix:
|
||||
fast_finish: true
|
||||
@@ -35,9 +37,9 @@ matrix:
|
||||
- node_js: "node"
|
||||
env: JOB=lint
|
||||
- node_js: "node"
|
||||
env: JOB=babylon-flow-tests
|
||||
env: JOB=babel-parser-flow-tests
|
||||
- node_js: "node"
|
||||
env: JOB=babylon-test262-tests
|
||||
env: JOB=babel-parser-test262-tests
|
||||
|
||||
notifications:
|
||||
slack:
|
||||
|
||||
@@ -24,23 +24,24 @@ contributing, please read the
|
||||
## Not sure where to start?
|
||||
|
||||
- If you aren't just making a documentation change, you'll probably want to learn a bit about a few topics.
|
||||
- [ASTs](https://en.wikipedia.org/wiki/Abstract_syntax_tree) (Abstract Syntax Tree): The Babel AST [spec](https://github.com/babel/babel/blob/master/packages/babylon/ast/spec.md) is a bit different from [ESTree](https://github.com/estree/estree). The differences are listed [here](https://github.com/babel/babel/tree/master/packages/babylon#output).
|
||||
- [ASTs](https://en.wikipedia.org/wiki/Abstract_syntax_tree) (Abstract Syntax Tree): The Babel AST [spec](https://github.com/babel/babel/blob/master/packages/babel-parser/ast/spec.md) is a bit different from [ESTree](https://github.com/estree/estree). The differences are listed [here](https://github.com/babel/babel/tree/master/packages/babel-parser#output).
|
||||
- Check out [`/doc`](https://github.com/babel/babel/tree/master/doc) for information about Babel's internals
|
||||
- Check out [the Babel Plugin Handbook](https://github.com/thejameskyle/babel-handbook/blob/master/translations/en/plugin-handbook.md#babel-plugin-handbook) - core plugins are written the same way as any other plugin!
|
||||
- Check out [AST Explorer](http://astexplorer.net/#/scUfOmVOG5) to learn more about ASTs or make your own plugin in the browser
|
||||
- When you feel ready to jump into the Babel source code, a good place to start is to look for issues tagged with [help wanted](https://github.com/babel/babel/labels/help%20wanted) and/or [good first issue](https://github.com/babel/babel/labels/good%20first%20issue).
|
||||
- Follow along with what we are working on by joining our Slack, following our announcements on [Twitter](https://twitter.com/babeljs), and reading (or participating!) in our [meeting notes](https://github.com/babel/notes).
|
||||
- Follow along with what we are working on by joining our [Slack](https://babeljs.slack.com) (you can sign-up [here](https://slack.babeljs.io/)
|
||||
for an invite), following our announcements on [Twitter](https://twitter.com/babeljs), and reading (or participating!) in our [meeting notes](https://github.com/babel/notes).
|
||||
- Check out our [website](http://babeljs.io/) and the [repo](https://github.com/babel/website)
|
||||
|
||||
## Chat
|
||||
|
||||
Feel free to check out the `#discussion`/`#development` channels on our [Slack](https://slack.babeljs.io). Some of us are always online to chat!
|
||||
Feel free to check out the `#discussion`/`#development` channels on our [Slack](https://slack.babeljs.io) (you can sign-up [here](https://slack.babeljs.io/) for an invite). Some of us are always online to chat!
|
||||
|
||||
## Developing
|
||||
|
||||
**Note:** Versions `< 5.1.10` can't be built.
|
||||
|
||||
Babel is built for Node 4 and up but we develop using Node 8 and yarn. You can check this with `node -v`.
|
||||
Babel is built for Node 6 and up but we develop using Node 8 and yarn. You can check this with `node -v`.
|
||||
|
||||
Make sure that Yarn is installed with version >= `0.28.0`.
|
||||
Installation instructions can be found here: https://yarnpkg.com/en/docs/install.
|
||||
@@ -116,7 +117,7 @@ $ TEST_ONLY=babel-cli make test
|
||||
|
||||
```sh
|
||||
# Run tests for the @babel/plugin-transform-classes package.
|
||||
$ TEST_ONLY=es2015-class make test
|
||||
$ TEST_ONLY=babel-plugin-transform-classes make test
|
||||
```
|
||||
|
||||
Use the `TEST_GREP` variable to run a subset of tests by name:
|
||||
@@ -139,6 +140,12 @@ $ TEST_DEBUG=true make test
|
||||
|
||||
You can combine `TEST_DEBUG` with `TEST_GREP` or `TEST_ONLY` to debug a subset of tests. If you plan to stay long in the debugger (which you'll likely do!), you may increase the test timeout by editing [test/mocha.opts](https://github.com/babel/babel/blob/master/test/mocha.opts).
|
||||
|
||||
To overwrite any test fixtures when fixing a bug or anything, add the env variable `OVERWRITE=true`
|
||||
|
||||
```sh
|
||||
$ OVERWRITE=true TEST_ONLY=babel-plugin-transform-classes make test-only
|
||||
```
|
||||
|
||||
To test the code coverage, use:
|
||||
|
||||
```sh
|
||||
@@ -175,29 +182,29 @@ For example, in [`@babel/plugin-transform-exponentiation-operator/test`](https:/
|
||||
|
||||
- In each subfolder, you can organize your directory structure by categories of tests. (Example: these folders can be named after the feature you are testing or can reference the issue number they fix)
|
||||
- Generally, there are two kinds of tests for plugins
|
||||
- The first is a simple test of the input and output produced by running Babel on some code. We do this by creating an [`actual.js`](https://github.com/babel/babel/blob/master/packages/babel-plugin-transform-exponentiation-operator/test/fixtures/exponentian-operator/binary/actual.js) file and an [`expected.js`](https://github.com/babel/babel/blob/master/packages/babel-plugin-transform-exponentiation-operator/test/fixtures/exponentian-operator/binary/expected.js) file.
|
||||
- If you need to expect an error, you can ignore creating the `expected.js` file and pass a new `throws` key to the `options.json` that contains the error string that is created.
|
||||
- The first is a simple test of the input and output produced by running Babel on some code. We do this by creating an [`input.js`](https://github.com/babel/babel/blob/master/packages/babel-plugin-transform-exponentiation-operator/test/fixtures/exponentian-operator/binary/input.js) file and an [`output.js`](https://github.com/babel/babel/blob/master/packages/babel-plugin-transform-exponentiation-operator/test/fixtures/exponentian-operator/binary/output.js) file. This kind of test only works in sub-subdirectories of `/fixtures`, i.e. `/fixtures/exponentian-operator/binary/input.js` and **not** `/fixtures/exponentian-operator/input.js`.
|
||||
- If you need to expect an error, you can ignore creating the `output.js` file and pass a new `throws` key to the `options.json` that contains the error string that is created.
|
||||
- The second and preferred type is a test that actually evaluates the produced code and asserts that certain properties are true or false. We do this by creating an [`exec.js`](https://github.com/babel/babel/blob/master/packages/babel-plugin-transform-exponentiation-operator/test/fixtures/exponentian-operator/comprehensive/exec.js) file.
|
||||
|
||||
In an actual/expected test, you simply write out the code you want transformed in `actual.js`.
|
||||
In a fixture test, you simply write out the code you want transformed in `input.js`.
|
||||
|
||||
```js
|
||||
// actual.js
|
||||
// input.js
|
||||
2 ** 2;
|
||||
```
|
||||
|
||||
and the expected output after transforming it with your `options.json` in `expected.js`.
|
||||
and the expected output after transforming it with your `options.json` in `output.js`.
|
||||
|
||||
```js
|
||||
// expected.js
|
||||
// output.js
|
||||
Math.pow(2, 2);
|
||||
```
|
||||
In an `exec.js` test, we run or check that the code actually does what it's supposed to do rather than just check the static output.
|
||||
|
||||
```js
|
||||
// exec.js
|
||||
assert.equal(8, 2 ** 3);
|
||||
assert.equal(24, 3 * 2 ** 3);
|
||||
expect(2 ** 3).toBe(8);
|
||||
expect(3 * 2 ** 3).toBe(24);
|
||||
```
|
||||
|
||||
If you need to check for an error that is thrown you can add to the `options.json`
|
||||
@@ -219,45 +226,45 @@ If the test requires a minimum Node version, you can add `minNodeVersion` (must
|
||||
}
|
||||
```
|
||||
|
||||
#### `babylon`
|
||||
#### `@babel/parser` (babylon)
|
||||
|
||||
Writing tests for Babylon is very
|
||||
Writing tests for the babel parser is very
|
||||
similar to the other packages.
|
||||
Inside the `packages/babylon/tests/fixtures` folder are categories/groupings of test fixtures (es2015, flow,
|
||||
Inside the `packages/babel-parser/tests/fixtures` folder are categories/groupings of test fixtures (es2015, flow,
|
||||
etc.). To add a test, create a folder under one of these groupings (or create a new one) with a
|
||||
descriptive name, and add the following:
|
||||
|
||||
* Create an `actual.js` file that contains the code you want Babylon to parse.
|
||||
* Create an `input.js` file that contains the code you want the babel parser to parse.
|
||||
|
||||
* Add an `expected.json` file with the expected parser output. For added convenience, if there is no `expected.json` present, the test runner will generate one for you.
|
||||
* Add an `output.json` file with the expected parser output. For added convenience, if there is no `output.json` present, the test runner will generate one for you.
|
||||
|
||||
After writing tests for babylon, just build it by running:
|
||||
After writing tests for @babel/parser, just build it by running:
|
||||
|
||||
```sh
|
||||
$ make build-babylon
|
||||
$ make build
|
||||
```
|
||||
|
||||
Then, to run the tests, use:
|
||||
|
||||
```sh
|
||||
$ TEST_ONLY=babylon make test-only
|
||||
$ TEST_ONLY=babel-parser make test-only
|
||||
```
|
||||
|
||||
#### Bootstrapping expected output
|
||||
|
||||
For both `@babel/plugin-x` and `babylon`, you can easily generate an `expected.js`/`expected.json` automatically by just providing `actual.js` and running the tests as you usually would.
|
||||
For both `@babel/plugin-x` and `@babel/parser`, you can easily generate an `output.js`/`output.json` automatically by just providing `input.js` and running the tests as you usually would.
|
||||
|
||||
```
|
||||
// Example
|
||||
- packages
|
||||
- babylon
|
||||
- babel-parser
|
||||
- test
|
||||
- fixtures
|
||||
- comments
|
||||
- basic
|
||||
- block-trailing-comment
|
||||
- actual.js
|
||||
- expected.json (will be generated if not created)
|
||||
- input.js
|
||||
- output.json (will be generated if not created)
|
||||
```
|
||||
|
||||
### Debugging code
|
||||
@@ -302,14 +309,14 @@ Note that the code shown in Chrome DevTools is compiled code and therefore diffe
|
||||
|
||||
- Create a new issue that describes the proposal (ex: [#538](https://github.com/babel/babylon/issues/538)). Include any relevant information like proposal repo/author, examples, parsing approaches, meeting notes, presentation slides, and more.
|
||||
- The pull request should include:
|
||||
- [ ] An update to the [plugins](https://github.com/babel/babel/tree/master/packages/babylon#plugins) part of the readme. Add a new entry to that list for the new plugin flag (and link to the proposal)
|
||||
- [ ] If any new nodes or modifications need to be added to the AST, update [ast/spec.md](https://github.com/babel/babel/bloc/master/packages/babylon/ast/spec.md)
|
||||
- [ ] Make sure you use the `this.hasPlugin("plugin-name-here")` check in Babylon so that your new plugin code only runs when that flag is turned on (not default behavior)
|
||||
- [ ] An update to the [plugins](https://github.com/babel/babel/tree/master/packages/babel-parser#plugins) part of the readme. Add a new entry to that list for the new plugin flag (and link to the proposal)
|
||||
- [ ] If any new nodes or modifications need to be added to the AST, update [ast/spec.md](https://github.com/babel/babel/bloc/master/packages/babel-parser/ast/spec.md)
|
||||
- [ ] Make sure you use the `this.hasPlugin("plugin-name-here")` check in the babel parser so that your new plugin code only runs when that flag is turned on (not default behavior)
|
||||
- [ ] Add failing/passing tests according to spec behavior
|
||||
- Start working about the Babel transform itself!
|
||||
|
||||
## Internals
|
||||
- AST spec ([babylon/ast/spec.md](https://github.com/babel/babel/blob/master/packages/babylon/ast/spec.md))
|
||||
- AST spec ([babel-parser/ast/spec.md](https://github.com/babel/babel/blob/master/packages/babel-parser/ast/spec.md))
|
||||
- Versioning ([doc/design/versioning.md](https://github.com/babel/babel/blob/master/doc/design/versioning.md))
|
||||
- Monorepo ([doc/design/monorepo.md](https://github.com/babel/babel/blob/master/doc/design/monorepo.md))
|
||||
- Compiler environment support ([doc/design/compiler-environment-support.md](https://github.com/babel/babel/blob/master/doc/design/compiler-environment-support.md))
|
||||
|
||||
130
Gulpfile.js
130
Gulpfile.js
@@ -5,13 +5,18 @@ const through = require("through2");
|
||||
const chalk = require("chalk");
|
||||
const newer = require("gulp-newer");
|
||||
const babel = require("gulp-babel");
|
||||
const watch = require("gulp-watch");
|
||||
const gulpWatch = require("gulp-watch");
|
||||
const gutil = require("gulp-util");
|
||||
const filter = require("gulp-filter");
|
||||
const gulp = require("gulp");
|
||||
const path = require("path");
|
||||
const webpack = require("webpack");
|
||||
const merge = require("merge-stream");
|
||||
const rollup = require("rollup-stream");
|
||||
const source = require("vinyl-source-stream");
|
||||
const buffer = require("vinyl-buffer");
|
||||
const rollupBabel = require("rollup-plugin-babel");
|
||||
const rollupNodeResolve = require("rollup-plugin-node-resolve");
|
||||
const registerStandalonePackageTask = require("./scripts/gulp-tasks")
|
||||
.registerStandalonePackageTask;
|
||||
|
||||
@@ -27,55 +32,106 @@ function getGlobFromSource(source) {
|
||||
return `./${source}/*/src/**/*.js`;
|
||||
}
|
||||
|
||||
gulp.task("default", ["build"]);
|
||||
function getIndexFromPackage(name) {
|
||||
return `${name}/src/index.js`;
|
||||
}
|
||||
|
||||
gulp.task("build", function() {
|
||||
function compilationLogger(rollup) {
|
||||
return through.obj(function(file, enc, callback) {
|
||||
gutil.log(
|
||||
`Compiling '${chalk.cyan(file.relative)}'${
|
||||
rollup ? " with rollup " : ""
|
||||
}...`
|
||||
);
|
||||
callback(null, file);
|
||||
});
|
||||
}
|
||||
|
||||
function errorsLogger() {
|
||||
return plumber({
|
||||
errorHandler(err) {
|
||||
gutil.log(err.stack);
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
function rename(fn) {
|
||||
return through.obj(function(file, enc, callback) {
|
||||
file.path = fn(file);
|
||||
callback(null, file);
|
||||
});
|
||||
}
|
||||
|
||||
function buildBabel(exclude) {
|
||||
return merge(
|
||||
sources.map(source => {
|
||||
const base = path.join(__dirname, source);
|
||||
const f = filter(["**", "!**/packages/babylon/**"]);
|
||||
|
||||
return gulp
|
||||
.src(getGlobFromSource(source), { base: base })
|
||||
.pipe(f)
|
||||
.pipe(
|
||||
plumber({
|
||||
errorHandler: function(err) {
|
||||
gutil.log(err.stack);
|
||||
},
|
||||
})
|
||||
)
|
||||
.pipe(
|
||||
newer({
|
||||
dest: base,
|
||||
map: swapSrcWithLib,
|
||||
})
|
||||
)
|
||||
.pipe(
|
||||
through.obj(function(file, enc, callback) {
|
||||
gutil.log("Compiling", "'" + chalk.cyan(file.relative) + "'...");
|
||||
callback(null, file);
|
||||
})
|
||||
)
|
||||
let stream = gulp.src(getGlobFromSource(source), { base: base });
|
||||
|
||||
if (exclude) {
|
||||
const filters = exclude.map(p => `!**/${p}/**`);
|
||||
filters.unshift("**");
|
||||
stream = stream.pipe(filter(filters));
|
||||
}
|
||||
|
||||
return stream
|
||||
.pipe(errorsLogger())
|
||||
.pipe(newer({ dest: base, map: swapSrcWithLib }))
|
||||
.pipe(compilationLogger())
|
||||
.pipe(babel())
|
||||
.pipe(
|
||||
through.obj(function(file, enc, callback) {
|
||||
// Passing 'file.relative' because newer() above uses a relative
|
||||
// path and this keeps it consistent.
|
||||
file.path = path.resolve(file.base, swapSrcWithLib(file.relative));
|
||||
callback(null, file);
|
||||
})
|
||||
// Passing 'file.relative' because newer() above uses a relative
|
||||
// path and this keeps it consistent.
|
||||
rename(file => path.resolve(file.base, swapSrcWithLib(file.relative)))
|
||||
)
|
||||
.pipe(gulp.dest(base));
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
function buildRollup(packages) {
|
||||
return merge(
|
||||
packages.map(pkg => {
|
||||
return rollup({
|
||||
input: getIndexFromPackage(pkg),
|
||||
format: "cjs",
|
||||
plugins: [
|
||||
rollupBabel({
|
||||
envName: "babel-parser",
|
||||
}),
|
||||
rollupNodeResolve(),
|
||||
],
|
||||
})
|
||||
.pipe(source("index.js"))
|
||||
.pipe(buffer())
|
||||
.pipe(errorsLogger())
|
||||
.pipe(compilationLogger(/* rollup */ true))
|
||||
.pipe(gulp.dest(path.join(pkg, "lib")));
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
gulp.task("build", function() {
|
||||
const bundles = ["packages/babel-parser"];
|
||||
|
||||
return merge([buildBabel(/* exclude */ bundles), buildRollup(bundles)]);
|
||||
});
|
||||
|
||||
gulp.task("watch", ["build"], function() {
|
||||
watch(sources.map(getGlobFromSource), { debounceDelay: 200 }, function() {
|
||||
gulp.start("build");
|
||||
});
|
||||
});
|
||||
gulp.task("default", gulp.series("build"));
|
||||
|
||||
gulp.task("build-no-bundle", () => buildBabel());
|
||||
|
||||
gulp.task(
|
||||
"watch",
|
||||
gulp.series("build-no-bundle", function watch() {
|
||||
gulpWatch(
|
||||
sources.map(getGlobFromSource),
|
||||
{ debounceDelay: 200 },
|
||||
gulp.task("build-no-bundle")
|
||||
);
|
||||
})
|
||||
);
|
||||
|
||||
registerStandalonePackageTask(
|
||||
gulp,
|
||||
|
||||
76
Makefile
76
Makefile
@@ -1,8 +1,6 @@
|
||||
MAKEFLAGS = -j1
|
||||
FLOW_COMMIT = 622bbc4f07acb77eb1109830c70815f827401d90
|
||||
TEST262_COMMIT = 1282e842febf418ca27df13fa4b32f7e5021b470
|
||||
|
||||
export NODE_ENV = test
|
||||
FLOW_COMMIT = 395e045c18d537fcbbc552a96ef2cdcd70b4ab52
|
||||
TEST262_COMMIT = 40883f4c6ae17e073dfd03e34f73a6bf8c855595
|
||||
|
||||
# Fix color output until TravisCI fixes https://github.com/travis-ci/travis-ci/issues/7967
|
||||
export FORCE_COLOR = true
|
||||
@@ -11,23 +9,21 @@ SOURCES = packages codemods
|
||||
|
||||
.PHONY: build build-dist watch lint fix clean test-clean test-only test test-ci publish bootstrap
|
||||
|
||||
build: clean
|
||||
make clean-lib
|
||||
# Build babylon before building all other projects
|
||||
make build-babylon
|
||||
build: clean clean-lib
|
||||
./node_modules/.bin/gulp build
|
||||
node ./packages/babel-types/scripts/generateTypeHelpers.js
|
||||
# call build again as the generated files might need to be compiled again.
|
||||
./node_modules/.bin/gulp build
|
||||
ifneq ("$(BABEL_ENV)", "cov")
|
||||
# generate flow and typescript typings
|
||||
node scripts/generators/flow.js > ./packages/babel-types/lib/index.js.flow
|
||||
node scripts/generators/typescript.js > ./packages/babel-types/lib/index.d.ts
|
||||
# generate docs
|
||||
node scripts/generators/docs.js > ./packages/babel-types/README.md
|
||||
ifneq ("$(BABEL_COVERAGE)", "true")
|
||||
make build-standalone
|
||||
make build-preset-env-standalone
|
||||
endif
|
||||
|
||||
build-babylon:
|
||||
cd packages/babylon; \
|
||||
./node_modules/.bin/rollup -c
|
||||
|
||||
build-standalone:
|
||||
./node_modules/.bin/gulp build-babel-standalone
|
||||
|
||||
@@ -39,24 +35,26 @@ build-dist: build
|
||||
scripts/build-dist.sh
|
||||
cd packages/babel-runtime; \
|
||||
node scripts/build-dist.js
|
||||
node scripts/generate-babel-types-docs.js
|
||||
|
||||
watch: clean
|
||||
make clean-lib
|
||||
watch: clean clean-lib
|
||||
|
||||
# Ensure that build artifacts for types are created during local
|
||||
# development too.
|
||||
BABEL_ENV=development ./node_modules/.bin/gulp build-no-bundle
|
||||
node ./packages/babel-types/scripts/generateTypeHelpers.js
|
||||
node scripts/generators/flow.js > ./packages/babel-types/lib/index.js.flow
|
||||
BABEL_ENV=development ./node_modules/.bin/gulp watch
|
||||
|
||||
watch-babylon:
|
||||
cd packages/babylon; \
|
||||
./node_modules/.bin/rollup -c -w
|
||||
|
||||
flow:
|
||||
./node_modules/.bin/flow check --strip-root
|
||||
|
||||
lint:
|
||||
./node_modules/.bin/eslint scripts $(SOURCES) *.js --format=codeframe --rulesdir="./scripts/eslint_rules"
|
||||
./node_modules/.bin/eslint scripts $(SOURCES) '*.js' '**/.*.js' --format=codeframe --rulesdir="./scripts/eslint_rules"
|
||||
|
||||
fix:
|
||||
./node_modules/.bin/eslint scripts $(SOURCES) *.js --format=codeframe --fix --rulesdir="./scripts/eslint_rules"
|
||||
# The config is hardcoded because otherwise prettier searches for it and also picks up some broken package.json files from tests
|
||||
./node_modules/.bin/prettier --config .prettierrc --write --ignore-path .eslintignore '**/*.json'
|
||||
./node_modules/.bin/eslint scripts $(SOURCES) '*.js' '**/.*.js' --format=codeframe --fix --rulesdir="./scripts/eslint_rules"
|
||||
|
||||
clean: test-clean
|
||||
rm -rf packages/babel-polyfill/browser*
|
||||
@@ -69,19 +67,17 @@ test-clean:
|
||||
$(call clean-source-test, $(source)))
|
||||
|
||||
test-only:
|
||||
./scripts/test.sh
|
||||
BABEL_ENV=test ./scripts/test.sh
|
||||
make test-clean
|
||||
|
||||
test: lint test-only
|
||||
|
||||
test-ci:
|
||||
make bootstrap
|
||||
make test-only
|
||||
test-ci: bootstrap test-only
|
||||
|
||||
test-ci-coverage: SHELL:=/bin/bash
|
||||
test-ci-coverage:
|
||||
BABEL_ENV=cov make bootstrap
|
||||
./scripts/test-cov.sh
|
||||
BABEL_COVERAGE=true BABEL_ENV=test make bootstrap
|
||||
BABEL_ENV=test TEST_TYPE=cov ./scripts/test-cov.sh
|
||||
bash <(curl -s https://codecov.io/bash) -f coverage/coverage-final.json
|
||||
|
||||
bootstrap-flow:
|
||||
@@ -91,14 +87,12 @@ bootstrap-flow:
|
||||
cd build/flow && git checkout $(FLOW_COMMIT)
|
||||
|
||||
test-flow:
|
||||
node scripts/tests/flow/run_babylon_flow_tests.js
|
||||
node scripts/tests/flow/run_babel_parser_flow_tests.js
|
||||
|
||||
test-flow-ci:
|
||||
make bootstrap
|
||||
make test-flow
|
||||
test-flow-ci: bootstrap test-flow
|
||||
|
||||
test-flow-update-whitelist:
|
||||
node scripts/tests/flow/run_babylon_flow_tests.js --update-whitelist
|
||||
node scripts/tests/flow/run_babel_parser_flow_tests.js --update-whitelist
|
||||
|
||||
bootstrap-test262:
|
||||
rm -rf ./build/test262
|
||||
@@ -107,14 +101,12 @@ bootstrap-test262:
|
||||
cd build/test262 && git checkout $(TEST262_COMMIT)
|
||||
|
||||
test-test262:
|
||||
node scripts/tests/test262/run_babylon_test262.js
|
||||
node scripts/tests/test262/run_babel_parser_test262.js
|
||||
|
||||
test-test262-ci:
|
||||
make bootstrap
|
||||
make test-test262
|
||||
test-test262-ci: bootstrap test-test262
|
||||
|
||||
test-test262-update-whitelist:
|
||||
node scripts/tests/test262/run_babylon_test262.js --update-whitelist
|
||||
node scripts/tests/test262/run_babel_parser_test262.js --update-whitelist
|
||||
|
||||
publish:
|
||||
git pull --rebase
|
||||
@@ -128,10 +120,9 @@ publish:
|
||||
./node_modules/.bin/lerna publish --force-publish=* --exact --skip-temp-tag
|
||||
make clean
|
||||
|
||||
bootstrap:
|
||||
make clean-all
|
||||
yarn
|
||||
./node_modules/.bin/lerna bootstrap
|
||||
bootstrap: clean-all
|
||||
yarn --ignore-engines
|
||||
./node_modules/.bin/lerna bootstrap -- --ignore-engines
|
||||
make build
|
||||
cd packages/babel-runtime; \
|
||||
node scripts/build-dist.js
|
||||
@@ -143,6 +134,7 @@ clean-lib:
|
||||
clean-all:
|
||||
rm -rf node_modules
|
||||
rm -rf package-lock.json
|
||||
rm -rf .changelog
|
||||
|
||||
$(foreach source, $(SOURCES), \
|
||||
$(call clean-source-all, $(source)))
|
||||
|
||||
170
README.md
170
README.md
@@ -24,108 +24,12 @@
|
||||
<a href="https://medium.com/friendship-dot-js/i-peeked-into-my-node-modules-directory-and-you-wont-believe-what-happened-next-b89f63d21558"><img alt="Business Strategy Status" src="https://img.shields.io/badge/business%20model-flavortown-green.svg"></a>
|
||||
</p>
|
||||
|
||||
Babel is community-driven and thus mostly maintained by a group of [volunteers](https://babeljs.io/team). It has a lot of [companies and projects](https://babeljs.io/users) using it but almost no sponsors/people funded to work on it. If you'd like to help maintain the future of the project, please consider:
|
||||
Babel is a community-driven project used by many companies and projects, and is maintained by a group of [volunteers](https://babeljs.io/team). If you'd like to help support the future of the project, please consider:
|
||||
|
||||
- Giving developer time on the project. (Message us on [Twitter](https://twitter.com/babeljs) or [Slack](https://slack.babeljs.io/))
|
||||
- [Giving funds by becoming a backer/sponsor on OpenCollective](https://opencollective.com/babel)
|
||||
- Giving developer time on the project. (Message us on [Twitter](https://twitter.com/babeljs) or [Slack](https://slack.babeljs.io/) for guidance!)
|
||||
- Giving funds by becoming a sponsor (see below)!
|
||||
|
||||
## Intro
|
||||
|
||||
Babel is a tool that helps you write code in the latest version of JavaScript. When your supported environments don't support certain features natively, Babel will help you compile those features down to a supported version.
|
||||
|
||||
**In**
|
||||
|
||||
```js
|
||||
// ES2015 arrow function
|
||||
[1, 2, 3].map((n) => n + 1);
|
||||
```
|
||||
|
||||
**Out**
|
||||
|
||||
```js
|
||||
[1, 2, 3].map(function(n) {
|
||||
return n + 1;
|
||||
});
|
||||
```
|
||||
|
||||
Try it out at our [REPL](https://babeljs.io/repl/build/master#?code_lz=NoRgNATGDMC6B0BbAhgBwBQDsAEBeAfNjgNTYgCUA3EA&lineWrap=true&presets=es2015%2Ces2016%2Ces2017&version=7.0.0-beta.2).
|
||||
|
||||
- [FAQ](#faq)
|
||||
- [Backers](#backers)
|
||||
- [Sponsors](#sponsors)
|
||||
- [License](#license)
|
||||
|
||||
## FAQ
|
||||
|
||||
### Who maintains Babel?
|
||||
|
||||
Mostly a handful of volunteers! Please check out our [team page](https://babeljs.io/team)!
|
||||
|
||||
### Looking for support?
|
||||
|
||||
For questions and support please visit join our [Slack Community](https://slack.babeljs.io/), ask a question on [Stack Overflow](https://stackoverflow.com/questions/tagged/babeljs), or ping us on [Twitter](https://twitter.com/babeljs).
|
||||
|
||||
### Is there a Babel song?
|
||||
|
||||
I'm so glad you asked: [Hallelujah —— In Praise of Babel](SONG.md) by [@angus-c](https://github.com/angus-c). Tweet us your recordings!
|
||||
|
||||
### Where are the docs?
|
||||
|
||||
Check out our website: [babeljs.io](https://babeljs.io/), and report issues/features at [babel/website](https://github.com/babel/website/issues).
|
||||
|
||||
### Want to report a bug or request a feature?
|
||||
|
||||
Please read through our [CONTRIBUTING.md](CONTRIBUTING.md) and fill out the issue template at [babel/issues](https://github.com/babel/babel/issues)!
|
||||
|
||||
### Want to contribute to Babel?
|
||||
|
||||
Check out our [CONTRIBUTING.md](CONTRIBUTING.md) to get started with setting up the repo.
|
||||
|
||||
- If you have already joined Slack, join our [#development](https://babeljs.slack.com/messages/development) channel and say hi!
|
||||
- Check out the issues with the [good first issue](https://github.com/babel/babel/labels/good%20first%20issue) and [help wanted](https://github.com/babel/babel/labels/help%20wanted) label. We suggest also looking at the closed ones to get a sense of the kinds of issues you can tackle.
|
||||
- Our discussions/notes/roadmap: [babel/notes](https://github.com/babel/notes)
|
||||
- Our progress on TC39 proposals: [babel/proposals](https://github.com/babel/proposals)
|
||||
|
||||
### How is the repo structured?
|
||||
|
||||
The Babel repo is managed as a [monorepo](doc/design/monorepo.md) that is composed of many [npm packages](packages/README.md).
|
||||
|
||||
## Backers
|
||||
|
||||
Support us with a monthly donation and help us continue our activities. [[Become a backer](https://opencollective.com/babel#backer)]
|
||||
|
||||
<a href="https://opencollective.com/babel/backer/0/website" target="_blank"><img src="https://opencollective.com/babel/backer/0/avatar.svg"></a>
|
||||
<a href="https://opencollective.com/babel/backer/1/website" target="_blank"><img src="https://opencollective.com/babel/backer/1/avatar.svg"></a>
|
||||
<a href="https://opencollective.com/babel/backer/2/website" target="_blank"><img src="https://opencollective.com/babel/backer/2/avatar.svg"></a>
|
||||
<a href="https://opencollective.com/babel/backer/3/website" target="_blank"><img src="https://opencollective.com/babel/backer/3/avatar.svg"></a>
|
||||
<a href="https://opencollective.com/babel/backer/4/website" target="_blank"><img src="https://opencollective.com/babel/backer/4/avatar.svg"></a>
|
||||
<a href="https://opencollective.com/babel/backer/5/website" target="_blank"><img src="https://opencollective.com/babel/backer/5/avatar.svg"></a>
|
||||
<a href="https://opencollective.com/babel/backer/6/website" target="_blank"><img src="https://opencollective.com/babel/backer/6/avatar.svg"></a>
|
||||
<a href="https://opencollective.com/babel/backer/7/website" target="_blank"><img src="https://opencollective.com/babel/backer/7/avatar.svg"></a>
|
||||
<a href="https://opencollective.com/babel/backer/8/website" target="_blank"><img src="https://opencollective.com/babel/backer/8/avatar.svg"></a>
|
||||
<a href="https://opencollective.com/babel/backer/9/website" target="_blank"><img src="https://opencollective.com/babel/backer/9/avatar.svg"></a>
|
||||
<a href="https://opencollective.com/babel/backer/10/website" target="_blank"><img src="https://opencollective.com/babel/backer/10/avatar.svg"></a>
|
||||
<a href="https://opencollective.com/babel/backer/11/website" target="_blank"><img src="https://opencollective.com/babel/backer/11/avatar.svg"></a>
|
||||
<a href="https://opencollective.com/babel/backer/12/website" target="_blank"><img src="https://opencollective.com/babel/backer/12/avatar.svg"></a>
|
||||
<a href="https://opencollective.com/babel/backer/13/website" target="_blank"><img src="https://opencollective.com/babel/backer/13/avatar.svg"></a>
|
||||
<a href="https://opencollective.com/babel/backer/14/website" target="_blank"><img src="https://opencollective.com/babel/backer/14/avatar.svg"></a>
|
||||
<a href="https://opencollective.com/babel/backer/15/website" target="_blank"><img src="https://opencollective.com/babel/backer/15/avatar.svg"></a>
|
||||
<a href="https://opencollective.com/babel/backer/16/website" target="_blank"><img src="https://opencollective.com/babel/backer/16/avatar.svg"></a>
|
||||
<a href="https://opencollective.com/babel/backer/17/website" target="_blank"><img src="https://opencollective.com/babel/backer/17/avatar.svg"></a>
|
||||
<a href="https://opencollective.com/babel/backer/18/website" target="_blank"><img src="https://opencollective.com/babel/backer/18/avatar.svg"></a>
|
||||
<a href="https://opencollective.com/babel/backer/19/website" target="_blank"><img src="https://opencollective.com/babel/backer/19/avatar.svg"></a>
|
||||
<a href="https://opencollective.com/babel/backer/20/website" target="_blank"><img src="https://opencollective.com/babel/backer/20/avatar.svg"></a>
|
||||
<a href="https://opencollective.com/babel/backer/21/website" target="_blank"><img src="https://opencollective.com/babel/backer/21/avatar.svg"></a>
|
||||
<a href="https://opencollective.com/babel/backer/22/website" target="_blank"><img src="https://opencollective.com/babel/backer/22/avatar.svg"></a>
|
||||
<a href="https://opencollective.com/babel/backer/23/website" target="_blank"><img src="https://opencollective.com/babel/backer/23/avatar.svg"></a>
|
||||
<a href="https://opencollective.com/babel/backer/24/website" target="_blank"><img src="https://opencollective.com/babel/backer/24/avatar.svg"></a>
|
||||
<a href="https://opencollective.com/babel/backer/25/website" target="_blank"><img src="https://opencollective.com/babel/backer/25/avatar.svg"></a>
|
||||
<a href="https://opencollective.com/babel/backer/26/website" target="_blank"><img src="https://opencollective.com/babel/backer/26/avatar.svg"></a>
|
||||
<a href="https://opencollective.com/babel/backer/27/website" target="_blank"><img src="https://opencollective.com/babel/backer/27/avatar.svg"></a>
|
||||
<a href="https://opencollective.com/babel/backer/28/website" target="_blank"><img src="https://opencollective.com/babel/backer/28/avatar.svg"></a>
|
||||
<a href="https://opencollective.com/babel/backer/29/website" target="_blank"><img src="https://opencollective.com/babel/backer/29/avatar.svg"></a>
|
||||
|
||||
## Sponsors
|
||||
## Open Collective Sponsors
|
||||
|
||||
Become a sponsor and get your logo on our README on Github with a link to your site. [[Become a sponsor](https://opencollective.com/babel#sponsor)]
|
||||
|
||||
@@ -160,6 +64,72 @@ Become a sponsor and get your logo on our README on Github with a link to your s
|
||||
<a href="https://opencollective.com/babel/sponsor/28/website" target="_blank"><img src="https://opencollective.com/babel/sponsor/28/avatar.svg"></a>
|
||||
<a href="https://opencollective.com/babel/sponsor/29/website" target="_blank"><img src="https://opencollective.com/babel/sponsor/29/avatar.svg"></a>
|
||||
|
||||
## Patreon Sponsors
|
||||
|
||||
Become a sponsor and get your logo on our README on Github with a link to your site. [[Become a sponsor](https://www.patreon.com/henryzhu)]
|
||||
|
||||
## Bronze
|
||||
|
||||
<a href="http://teamextension.io/" target="_blank"><img src="https://teamextension.io/dist/img/logo/te-logo-compact.png" height="64"></a>
|
||||
<a href="https://webflow.com/" target="_blank"><img src="https://opencollective.com/proxy/images/?src=https%3A%2F%2Fopencollective-production.s3-us-west-1.amazonaws.com%2F4a5024b0-8cf2-11e7-b1a2-b30b1de1463c.png&height=64"></a>
|
||||
<p><a href="https://twitter.com/mikesherov">Mike Sherov</a></p>
|
||||
|
||||
## Intro
|
||||
|
||||
Babel is a tool that helps you write code in the latest version of JavaScript. When your supported environments don't support certain features natively, Babel will help you compile those features down to a supported version.
|
||||
|
||||
**In**
|
||||
|
||||
```js
|
||||
// ES2015 arrow function
|
||||
[1, 2, 3].map((n) => n + 1);
|
||||
```
|
||||
|
||||
**Out**
|
||||
|
||||
```js
|
||||
[1, 2, 3].map(function(n) {
|
||||
return n + 1;
|
||||
});
|
||||
```
|
||||
|
||||
Try it out at our [REPL](https://babeljs.io/repl/build/master#?code_lz=NoRgNATGDMC6B0BbAhgBwBQDsAEBeAfNjgNTYgCUA3EA&lineWrap=true&presets=es2015%2Ces2016%2Ces2017&version=7.0.0-beta.2).
|
||||
|
||||
## FAQ
|
||||
|
||||
### Who maintains Babel?
|
||||
|
||||
Mostly a handful of volunteers! Please check out our [team page](https://babeljs.io/team)!
|
||||
|
||||
### Looking for support?
|
||||
|
||||
For questions and support please visit join our [Slack Community](https://slack.babeljs.io/) (you can sign-up [here](https://slack.babeljs.io/) for an invite), ask a question on [Stack Overflow](https://stackoverflow.com/questions/tagged/babeljs), or ping us on [Twitter](https://twitter.com/babeljs).
|
||||
|
||||
### Is there a Babel song?
|
||||
|
||||
I'm so glad you asked: [Hallelujah —— In Praise of Babel](SONG.md) by [@angus-c](https://github.com/angus-c). Tweet us your recordings!
|
||||
|
||||
### Where are the docs?
|
||||
|
||||
Check out our website: [babeljs.io](https://babeljs.io/), and report issues/features at [babel/website](https://github.com/babel/website/issues).
|
||||
|
||||
### Want to report a bug or request a feature?
|
||||
|
||||
Please read through our [CONTRIBUTING.md](CONTRIBUTING.md) and fill out the issue template at [babel/issues](https://github.com/babel/babel/issues)!
|
||||
|
||||
### Want to contribute to Babel?
|
||||
|
||||
Check out our [CONTRIBUTING.md](CONTRIBUTING.md) to get started with setting up the repo.
|
||||
|
||||
- If you have already joined Slack, join our [#development](https://babeljs.slack.com/messages/development) channel and say hi!
|
||||
- Check out the issues with the [good first issue](https://github.com/babel/babel/labels/good%20first%20issue) and [help wanted](https://github.com/babel/babel/labels/help%20wanted) label. We suggest also looking at the closed ones to get a sense of the kinds of issues you can tackle.
|
||||
- Our discussions/notes/roadmap: [babel/notes](https://github.com/babel/notes)
|
||||
- Our progress on TC39 proposals: [babel/proposals](https://github.com/babel/proposals)
|
||||
|
||||
### How is the repo structured?
|
||||
|
||||
The Babel repo is managed as a [monorepo](doc/design/monorepo.md) that is composed of many [npm packages](packages/README.md).
|
||||
|
||||
## License
|
||||
|
||||
[MIT](LICENSE)
|
||||
|
||||
97
babel.config.js
Normal file
97
babel.config.js
Normal file
@@ -0,0 +1,97 @@
|
||||
"use strict";
|
||||
|
||||
module.exports = function(api) {
|
||||
const env = api.env();
|
||||
|
||||
const includeCoverage = process.env.BABEL_COVERAGE === "true";
|
||||
|
||||
const envOpts = {
|
||||
loose: true,
|
||||
modules: false,
|
||||
exclude: ["transform-typeof-symbol"],
|
||||
};
|
||||
|
||||
let convertESM = true;
|
||||
let ignoreLib = true;
|
||||
|
||||
switch (env) {
|
||||
// Configs used during bundling builds.
|
||||
case "babel-parser":
|
||||
case "standalone":
|
||||
convertESM = false;
|
||||
ignoreLib = false;
|
||||
break;
|
||||
case "production":
|
||||
// Config during builds before publish.
|
||||
envOpts.targets = {
|
||||
node: "6.9",
|
||||
};
|
||||
break;
|
||||
case "development":
|
||||
envOpts.debug = true;
|
||||
envOpts.targets = {
|
||||
node: "current",
|
||||
};
|
||||
break;
|
||||
case "test":
|
||||
envOpts.targets = {
|
||||
node: "current",
|
||||
};
|
||||
break;
|
||||
}
|
||||
|
||||
const config = {
|
||||
comments: false,
|
||||
ignore: [
|
||||
// These may not be strictly necessary with the newly-limited scope of
|
||||
// babelrc searching, but including them for now because we had them
|
||||
// in our .babelignore before.
|
||||
"packages/*/test/fixtures",
|
||||
ignoreLib ? "packages/*/lib" : null,
|
||||
"packages/babel-standalone/babel.js",
|
||||
"packages/babel-preset-env-standalone/babel-preset-env.js",
|
||||
].filter(Boolean),
|
||||
presets: [["@babel/env", envOpts]],
|
||||
plugins: [
|
||||
// TODO: Use @babel/preset-flow when
|
||||
// https://github.com/babel/babel/issues/7233 is fixed
|
||||
"@babel/plugin-transform-flow-strip-types",
|
||||
["@babel/proposal-class-properties", { loose: true }],
|
||||
"@babel/proposal-export-namespace-from",
|
||||
"@babel/proposal-numeric-separator",
|
||||
[
|
||||
"@babel/proposal-object-rest-spread",
|
||||
{ useBuiltIns: true, loose: true },
|
||||
],
|
||||
|
||||
// Explicitly use the lazy version of CommonJS modules.
|
||||
convertESM ? ["@babel/transform-modules-commonjs", { lazy: true }] : null,
|
||||
].filter(Boolean),
|
||||
overrides: [
|
||||
{
|
||||
test: "packages/babel-parser",
|
||||
plugins: [
|
||||
"babel-plugin-transform-charcodes",
|
||||
["@babel/transform-for-of", { assumeArray: true }],
|
||||
],
|
||||
},
|
||||
{
|
||||
test: "./packages/babel-register",
|
||||
plugins: [
|
||||
// Override the root options to disable lazy imports for babel-register
|
||||
// because otherwise the require hook will try to lazy-import things
|
||||
// leading to dependency cycles.
|
||||
convertESM ? "@babel/transform-modules-commonjs" : null,
|
||||
].filter(Boolean),
|
||||
},
|
||||
],
|
||||
};
|
||||
|
||||
// we need to do this as long as we do not test everything from source
|
||||
if (includeCoverage) {
|
||||
config.auxiliaryCommentBefore = "istanbul ignore next";
|
||||
config.plugins.push("babel-plugin-istanbul");
|
||||
}
|
||||
|
||||
return config;
|
||||
};
|
||||
30
circle.yml
30
circle.yml
@@ -1,30 +0,0 @@
|
||||
general:
|
||||
artifacts:
|
||||
- "packages/babel-standalone/babel.js"
|
||||
- "packages/babel-standalone/babel.min.js"
|
||||
- "packages/babel-preset-env-standalone/babel-preset-env.js"
|
||||
- "packages/babel-preset-env-standalone/babel-preset-env.min.js"
|
||||
|
||||
machine:
|
||||
node:
|
||||
version:
|
||||
8
|
||||
|
||||
dependencies:
|
||||
pre:
|
||||
- curl -o- -L https://yarnpkg.com/install.sh | bash
|
||||
cache_directories:
|
||||
- ~/.yarn-cache
|
||||
override:
|
||||
- yarn
|
||||
|
||||
test:
|
||||
override:
|
||||
- make test-ci-coverage
|
||||
# Builds babel-standalone with the regular Babel config
|
||||
- make build
|
||||
# test-ci-coverage doesn't test babel-standalone, as trying to gather coverage
|
||||
# data for a JS file that's several megabytes large is bound to fail. Here,
|
||||
# we just run the babel-standalone test separately.
|
||||
- ./node_modules/mocha/bin/_mocha packages/babel-standalone/test/ --opts test/mocha.opts
|
||||
- ./node_modules/mocha/bin/_mocha packages/babel-preset-env-standalone/test/ --opts test/mocha.opts
|
||||
@@ -0,0 +1,57 @@
|
||||
# @babel/plugin-codemod-object-assign-to-object-spread
|
||||
|
||||
Transforms old code that uses `Object.assign` with an Object Literal as
|
||||
the first param to use Object Spread syntax.
|
||||
|
||||
## Examples
|
||||
|
||||
```js
|
||||
const obj = Object.assign({
|
||||
test1: 1,
|
||||
}, other, {
|
||||
test2: 2,
|
||||
}, other2);
|
||||
```
|
||||
|
||||
Is transformed to:
|
||||
|
||||
```js
|
||||
const obj = {
|
||||
test1: 1,
|
||||
...other,
|
||||
test2: 2,
|
||||
...other2,
|
||||
};
|
||||
```
|
||||
|
||||
## Installation
|
||||
|
||||
```sh
|
||||
npm install --save-dev @babel/plugin-codemod-object-assign-to-object-spread
|
||||
```
|
||||
|
||||
## Usage
|
||||
|
||||
### Via `.babelrc` (Recommended)
|
||||
|
||||
**.babelrc**
|
||||
|
||||
```json
|
||||
{
|
||||
"plugins": ["@babel/plugin-codemod-object-assign-to-object-spread"]
|
||||
}
|
||||
```
|
||||
|
||||
### Via CLI
|
||||
|
||||
```sh
|
||||
babel --plugins @babel/plugin-codemod-object-assign-to-object-spread script.js
|
||||
```
|
||||
|
||||
### Via Node API
|
||||
|
||||
```javascript
|
||||
require("@babel/core").transform("code", {
|
||||
plugins: ["@babel/plugin-codemod-object-assign-to-object-spread"]
|
||||
});
|
||||
```
|
||||
@@ -0,0 +1,25 @@
|
||||
{
|
||||
"name": "@babel/plugin-codemod-object-assign-to-object-spread",
|
||||
"version": "7.0.0-beta.48",
|
||||
"description": "Transforms Object.assign into object spread syntax",
|
||||
"repository": "https://github.com/babel/babel/tree/master/codemods/babel-plugin-codemod-object-assign-to-object-spread",
|
||||
"license": "MIT",
|
||||
"main": "lib/index.js",
|
||||
"keywords": [
|
||||
"@babel/codemod",
|
||||
"@babel/plugin"
|
||||
],
|
||||
"dependencies": {
|
||||
"@babel/plugin-syntax-object-rest-spread": "7.0.0-beta.48"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"@babel/core": "7.0.0-beta.48"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@babel/core": "7.0.0-beta.48",
|
||||
"@babel/helper-plugin-test-runner": "7.0.0-beta.48"
|
||||
},
|
||||
"publishConfig": {
|
||||
"access": "public"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
import syntaxObjectRestSpread from "@babel/plugin-syntax-object-rest-spread";
|
||||
|
||||
export default function({ types: t }) {
|
||||
return {
|
||||
inherits: syntaxObjectRestSpread,
|
||||
|
||||
visitor: {
|
||||
CallExpression(path) {
|
||||
if (!path.get("callee").matchesPattern("Object.assign")) return;
|
||||
|
||||
const args = path.get("arguments");
|
||||
if (args.length === 0) return;
|
||||
|
||||
const [objPath] = args;
|
||||
if (!objPath.isObjectExpression()) return;
|
||||
|
||||
const obj = objPath.node;
|
||||
const { properties } = obj;
|
||||
|
||||
for (let i = 1; i < args.length; i++) {
|
||||
const arg = args[i];
|
||||
const { node } = arg;
|
||||
|
||||
if (arg.isObjectExpression()) {
|
||||
properties.push(...node.properties);
|
||||
} else {
|
||||
properties.push(t.spreadElement(node));
|
||||
}
|
||||
}
|
||||
|
||||
path.replaceWith(obj);
|
||||
},
|
||||
},
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
Object.assign({test: 1}, {test: 2});
|
||||
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"plugins": ["../../../../lib"]
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
({
|
||||
test: 1,
|
||||
test: 2
|
||||
});
|
||||
@@ -0,0 +1 @@
|
||||
Object.assign({test: 1}, test2, {test: 2}, test3);
|
||||
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"plugins": ["../../../../lib"]
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
({
|
||||
test: 1,
|
||||
...test2,
|
||||
test: 2,
|
||||
...test3
|
||||
});
|
||||
@@ -0,0 +1 @@
|
||||
Object.assign(test);
|
||||
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"plugins": ["../../../../lib"]
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
Object.assign(test);
|
||||
@@ -0,0 +1 @@
|
||||
Object.assign({test: 1});
|
||||
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"plugins": ["../../../../lib"]
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
({
|
||||
test: 1
|
||||
});
|
||||
@@ -1,21 +1,22 @@
|
||||
{
|
||||
"name": "@babel/plugin-codemod-optional-catch-binding",
|
||||
"version": "7.0.0-beta.37",
|
||||
"version": "7.0.0-beta.48",
|
||||
"description": "Remove unused catch bindings",
|
||||
"repository": "https://github.com/babel/babel/tree/master/packages/babel-plugin-transform-remove-unused-catch-binding",
|
||||
"repository": "https://github.com/babel/babel/tree/master/codemods/babel-plugin-codemod-remove-unused-catch-binding",
|
||||
"license": "MIT",
|
||||
"main": "lib/index.js",
|
||||
"keywords": [
|
||||
"@babel/codemod",
|
||||
"@babel/plugin"
|
||||
],
|
||||
"dependencies": {
|
||||
"@babel/plugin-syntax-optional-catch-binding": "7.0.0-beta.37"
|
||||
"@babel/plugin-syntax-optional-catch-binding": "7.0.0-beta.48"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"@babel/core": "7.0.0-beta.37"
|
||||
"@babel/core": "7.0.0-beta.48"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@babel/core": "7.0.0-beta.37",
|
||||
"@babel/helper-plugin-test-runner": "7.0.0-beta.37"
|
||||
"@babel/core": "7.0.0-beta.48",
|
||||
"@babel/helper-plugin-test-runner": "7.0.0-beta.48"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
import syntaxOptionalCatchBinding from "@babel/plugin-syntax-optional-catch-binding";
|
||||
import { types as t } from "@babel/core";
|
||||
|
||||
export default function() {
|
||||
export default function({ types: t }) {
|
||||
return {
|
||||
inherits: syntaxOptionalCatchBinding,
|
||||
|
||||
|
||||
@@ -1 +1 @@
|
||||
The [AST specification](https://github.com/babel/babel/blob/master/packages/babylon/ast/spec.md) has been moved to the Babylon package, `packages/babylon`.
|
||||
The [AST specification](https://github.com/babel/babel/blob/master/packages/babel-parser/ast/spec.md) has been moved to the babel parser package, `packages/babel-parser`.
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
The Babel compiler is **only** supported in these environments:
|
||||
|
||||
- Modern browsers such as Chrome, Firefox, Safari, Edge etc.
|
||||
- Node.js 4 and upper versions
|
||||
- Node.js 6 and newer versions
|
||||
|
||||
## Unsupported environments
|
||||
|
||||
|
||||
@@ -15,7 +15,7 @@ This is quite taboo but let's look at the pros and cons:
|
||||
* Easy to coordinate changes across modules.
|
||||
* Single place to report issues.
|
||||
* Easier to setup a development environment.
|
||||
* Tests across modules are ran together which finds bugs that touch multiple modules easier.
|
||||
* Tests across modules are run together which finds bugs that touch multiple modules easier.
|
||||
|
||||
**Cons:**
|
||||
|
||||
|
||||
18
lerna.json
18
lerna.json
@@ -1,19 +1,19 @@
|
||||
{
|
||||
"lerna": "2.0.0-rc.4",
|
||||
"version": "7.0.0-beta.37",
|
||||
"version": "7.0.0-beta.48",
|
||||
"changelog": {
|
||||
"repo": "babel/babel",
|
||||
"cacheDir": ".changelog",
|
||||
"labels": {
|
||||
"PR: Spec Compliancy": ":eyeglasses: Spec Compliancy",
|
||||
"PR: Breaking Change": ":boom: Breaking Change",
|
||||
"PR: New Feature": ":rocket: New Feature",
|
||||
"PR: Bug Fix": ":bug: Bug Fix",
|
||||
"PR: Polish": ":nail_care: Polish",
|
||||
"PR: Docs": ":memo: Documentation",
|
||||
"PR: Internal": ":house: Internal"
|
||||
"PR: Spec Compliancy :eyeglasses:": ":eyeglasses: Spec Compliancy",
|
||||
"PR: Breaking Change :boom:": ":boom: Breaking Change",
|
||||
"PR: New Feature :rocket:": ":rocket: New Feature",
|
||||
"PR: Bug Fix :bug:": ":bug: Bug Fix",
|
||||
"PR: Polish :nail_care:": ":nail_care: Polish",
|
||||
"PR: Docs :memo:": ":memo: Documentation",
|
||||
"PR: Internal :house:": ":house: Internal"
|
||||
}
|
||||
},
|
||||
"cacheDir": ".changelog",
|
||||
"commands": {
|
||||
"publish": {
|
||||
"ignore": [
|
||||
|
||||
@@ -3,9 +3,9 @@
|
||||
*/
|
||||
|
||||
declare module "micromatch" {
|
||||
declare function exports(Array<string>, Array<string>, ?{
|
||||
nocase: boolean,
|
||||
}): Array<string>;
|
||||
declare module.exports: {
|
||||
(Array<string>, Array<string>, ?{ nocase: boolean }): Array<string>,
|
||||
};
|
||||
}
|
||||
|
||||
declare module "resolve" {
|
||||
@@ -26,22 +26,124 @@ declare module "lodash/defaults" {
|
||||
|
||||
declare module "lodash/clone" {
|
||||
declare export default <T>(obj: T) => T;
|
||||
}
|
||||
}
|
||||
|
||||
declare module "lodash/merge" {
|
||||
declare export default <T: Object>(T, Object) => T;
|
||||
}
|
||||
|
||||
declare module "convert-source-map" {
|
||||
declare module "source-map" {
|
||||
declare export type SourceMap = {
|
||||
version: 3,
|
||||
file: ?string,
|
||||
sourceRoot: ?string,
|
||||
sources: [?string],
|
||||
sourcesContent: [?string],
|
||||
names: [?string],
|
||||
mappings: string,
|
||||
};
|
||||
|
||||
declare module.exports: {
|
||||
SourceMapConsumer: typeof SourceMapConsumer,
|
||||
SourceMapGenerator: typeof SourceMapGenerator,
|
||||
}
|
||||
|
||||
declare class SourceMapConsumer {
|
||||
static GENERATED_ORDER: 1;
|
||||
static ORIGINAL_ORDER: 2;
|
||||
|
||||
file: string | null;
|
||||
sourceRoot: string | null;
|
||||
sources: Array<string>;
|
||||
|
||||
constructor(?SourceMap): this;
|
||||
|
||||
computeColumnSpans(): string;
|
||||
originalPositionFor({
|
||||
line: number,
|
||||
column: number,
|
||||
}): {|
|
||||
source: string,
|
||||
line: number,
|
||||
column: number,
|
||||
name: string | null
|
||||
|} | {|
|
||||
source: null,
|
||||
line: null,
|
||||
column: null,
|
||||
name: null
|
||||
|};
|
||||
|
||||
generatedPositionFor({
|
||||
source: string,
|
||||
line: number,
|
||||
column: number,
|
||||
}): {|
|
||||
line: number,
|
||||
column: number,
|
||||
lastColumn: number | null | void,
|
||||
|} | {|
|
||||
line: null,
|
||||
column: null,
|
||||
lastColumn: null | void,
|
||||
|};
|
||||
|
||||
allGeneratedPositionsFor({
|
||||
source: string,
|
||||
line: number,
|
||||
column: number,
|
||||
}): Array<{|
|
||||
line: number,
|
||||
column: number,
|
||||
lastColumn: number,
|
||||
|}>;
|
||||
|
||||
sourceContentFor(string, boolean | void): string | null;
|
||||
|
||||
eachMapping(
|
||||
({|
|
||||
generatedLine: number,
|
||||
generatedColumn: number,
|
||||
source: string,
|
||||
originalLine: number,
|
||||
originalColumn: number,
|
||||
name: string | null,
|
||||
|} | {|
|
||||
generatedLine: number,
|
||||
generatedColumn: number,
|
||||
source: null,
|
||||
originalLine: null,
|
||||
originalColumn: null,
|
||||
name: null,
|
||||
|}) => mixed,
|
||||
context: mixed,
|
||||
order: ?(1 | 2),
|
||||
): void;
|
||||
}
|
||||
|
||||
declare class SourceMapGenerator {
|
||||
constructor(?{
|
||||
file?: string | null,
|
||||
sourceRoot?: string | null,
|
||||
skipValidation?: boolean | null,
|
||||
}): this;
|
||||
|
||||
addMapping({
|
||||
generated: {
|
||||
line: number,
|
||||
column: number,
|
||||
}
|
||||
}): void;
|
||||
|
||||
setSourceContent(string, string): void;
|
||||
|
||||
toJSON(): SourceMap;
|
||||
}
|
||||
}
|
||||
|
||||
declare module "convert-source-map" {
|
||||
import type { SourceMap } from "source-map";
|
||||
|
||||
declare class Converter {
|
||||
toJSON(): string;
|
||||
toBase64(): string;
|
||||
|
||||
1769
lib/types.js
1769
lib/types.js
File diff suppressed because it is too large
Load Diff
112
package.json
112
package.json
@@ -10,77 +10,113 @@
|
||||
"test": "make test"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@babel/cli": "7.0.0-beta.33",
|
||||
"@babel/core": "7.0.0-beta.33",
|
||||
"@babel/plugin-proposal-export-namespace-from": "7.0.0-beta.33",
|
||||
"@babel/preset-env": "7.0.0-beta.33",
|
||||
"@babel/preset-flow": "7.0.0-beta.33",
|
||||
"@babel/preset-stage-0": "7.0.0-beta.33",
|
||||
"@babel/register": "7.0.0-beta.33",
|
||||
"async": "^1.5.0",
|
||||
"@babel/cli": "7.0.0-beta.46",
|
||||
"@babel/core": "7.0.0-beta.46",
|
||||
"@babel/plugin-transform-modules-commonjs": "7.0.0-beta.46",
|
||||
"@babel/preset-env": "7.0.0-beta.46",
|
||||
"@babel/preset-flow": "7.0.0-beta.46",
|
||||
"@babel/preset-stage-0": "7.0.0-beta.46",
|
||||
"@babel/register": "7.0.0-beta.46",
|
||||
"babel-core": "^7.0.0-0",
|
||||
"babel-eslint": "^8.0.1",
|
||||
"babel-jest": "^22.4.1",
|
||||
"babel-loader": "8.0.0-beta.0",
|
||||
"babel-plugin-istanbul": "^4.1.4",
|
||||
"babylon": "7.0.0-beta.33",
|
||||
"babel-plugin-transform-charcodes": "^0.1.0",
|
||||
"babylon": "7.0.0-beta.46",
|
||||
"browserify": "^13.1.1",
|
||||
"bundle-collapser": "^1.2.1",
|
||||
"chai": "^4.1.0",
|
||||
"chalk": "^2.0.0",
|
||||
"chalk": "^2.3.2",
|
||||
"charcodes": "^0.1.0",
|
||||
"derequire": "^2.0.2",
|
||||
"eslint": "^4.5.0",
|
||||
"enhanced-resolve": "^3.0.0",
|
||||
"eslint": "^4.18.2",
|
||||
"eslint-config-babel": "^7.0.2",
|
||||
"eslint-plugin-flowtype": "^2.20.0",
|
||||
"eslint-plugin-prettier": "^2.2.0",
|
||||
"flow-bin": "^0.59.0",
|
||||
"eslint-plugin-prettier": "^2.5.0",
|
||||
"flow-bin": "^0.66.0",
|
||||
"graceful-fs": "^4.1.11",
|
||||
"gulp": "^3.9.0",
|
||||
"gulp-babel": "^8.0.0-beta.0",
|
||||
"gulp-filter": "^5.0.1",
|
||||
"gulp": "^4.0.0",
|
||||
"gulp-babel": "^8.0.0-beta.2",
|
||||
"gulp-filter": "^5.1.0",
|
||||
"gulp-newer": "^1.0.0",
|
||||
"gulp-plumber": "^1.0.1",
|
||||
"gulp-rename": "^1.2.2",
|
||||
"gulp-uglify": "^3.0.0",
|
||||
"gulp-util": "^3.0.7",
|
||||
"gulp-watch": "^4.3.5",
|
||||
"gulp-watch": "^5.0.0",
|
||||
"husky": "^0.14.3",
|
||||
"jest": "^22.4.2",
|
||||
"lerna": "2.0.0",
|
||||
"lerna-changelog": "^0.5.0",
|
||||
"lint-staged": "^4.2.3",
|
||||
"lodash": "^4.2.0",
|
||||
"lint-staged": "^6.0.1",
|
||||
"lodash": "^4.17.5",
|
||||
"merge-stream": "^1.0.1",
|
||||
"mocha": "^3.0.0",
|
||||
"nyc": "^11.0.3",
|
||||
"output-file-sync": "^2.0.0",
|
||||
"prettier": "1.9.1",
|
||||
"prettier": "1.11.1",
|
||||
"pump": "^1.0.2",
|
||||
"rimraf": "^2.4.3",
|
||||
"semver": "^5.0.0",
|
||||
"rollup-plugin-babel": "^4.0.0-beta.0",
|
||||
"rollup-plugin-node-resolve": "^3.0.2",
|
||||
"rollup-stream": "^1.24.1",
|
||||
"test262-stream": "^1.1.0",
|
||||
"through2": "^2.0.0",
|
||||
"uglify-js": "^2.4.16",
|
||||
"util.promisify": "^1.0.0",
|
||||
"vinyl-buffer": "^1.0.1",
|
||||
"vinyl-source-stream": "^2.0.0",
|
||||
"webpack": "^3.4.1",
|
||||
"webpack-dependency-suite": "^2.4.4",
|
||||
"webpack-stream": "^4.0.0"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">= 4.x <= 9.x",
|
||||
"node": ">= 6.9.0 <= 11.0.0-0",
|
||||
"npm": ">= 2.x <= 5.x",
|
||||
"yarn": ">=0.27.5 || >=1.0.0-20170811"
|
||||
},
|
||||
"nyc": {
|
||||
"all": true,
|
||||
"exclude": [
|
||||
"scripts/*.js",
|
||||
"packages/*/test/**",
|
||||
"packages/babel-standalone/**",
|
||||
"codemods/*/test/**"
|
||||
],
|
||||
"sourceMap": false,
|
||||
"instrument": false
|
||||
},
|
||||
"lint-staged": {
|
||||
"*.js": [
|
||||
"eslint --format=codeframe --rulesdir='./scripts/eslint_rules'"
|
||||
]
|
||||
},
|
||||
"jest": {
|
||||
"collectCoverageFrom": [
|
||||
"packages/*/src/**/*.mjs",
|
||||
"packages/*/src/**/*.js",
|
||||
"codemods/*/src/**/*.mjs",
|
||||
"codemods/*/src/**/*.js"
|
||||
],
|
||||
"testRegex": "./(packages|codemods)/[^/]+/test/.+\\.m?js$",
|
||||
"testPathIgnorePatterns": [
|
||||
"/node_modules/",
|
||||
"/test/fixtures/",
|
||||
"/test/debug-fixtures/",
|
||||
"/babel-parser/test/expressions/",
|
||||
"/test/tmp/",
|
||||
"/test/__data__/",
|
||||
"/test/helpers/",
|
||||
"<rootDir>/test/warning\\.js",
|
||||
"<rootDir>/build/",
|
||||
"_browser\\.js"
|
||||
],
|
||||
"testEnvironment": "node",
|
||||
"setupTestFrameworkScriptFile": "<rootDir>/test/testSetupFile.js",
|
||||
"transformIgnorePatterns": [
|
||||
"/node_modules/",
|
||||
"<rootDir>/packages/babel-standalone/babel(\\.min)?\\.js",
|
||||
"<rootDir>/packages/babel-preset-env-standalone/babel-preset-env(\\.min)?\\.js",
|
||||
"/test/(fixtures|tmp|__data__)/",
|
||||
"<rootDir>/(packages|codemods)/[^/]+/lib/"
|
||||
],
|
||||
"coveragePathIgnorePatterns": [
|
||||
"/node_modules/",
|
||||
"<rootDir>/packages/babel-standalone/babel(\\.min)?\\.js",
|
||||
"<rootDir>/packages/babel-preset-env-standalone/babel-preset-env(\\.min)?\\.js",
|
||||
"/test/(fixtures|tmp|__data__)/"
|
||||
],
|
||||
"modulePathIgnorePatterns": [
|
||||
"/test/fixtures/",
|
||||
"/test/tmp/",
|
||||
"/test/__data__/",
|
||||
"<rootDir>/build/"
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,22 +13,22 @@ A monorepo, muhahahahahaha. See the [monorepo design doc](/doc/design/monorepo.m
|
||||
|
||||
| Package | Version | Dependencies |
|
||||
|--------|-------|------------|
|
||||
| [`@babel/core`](/packages/babel-core) | [](https://www.npmjs.com/package/babel-core) | [](https://david-dm.org/babel/babel?path=packages/babel-core) |
|
||||
| [`babylon`](https://github.com/babel/babel/tree/master/packages/babylon) | [](https://www.npmjs.com/package/babylon) | [](https://david-dm.org/babel/babylon) |
|
||||
| [`@babel/traverse`](/packages/babel-traverse) | [](https://www.npmjs.com/package/babel-traverse) | [](https://david-dm.org/babel/babel?path=packages/babel-traverse) |
|
||||
| [`@babel/generator`](/packages/babel-generator) | [](https://www.npmjs.com/package/babel-generator) | [](https://david-dm.org/babel/babel?path=packages/babel-generator) |
|
||||
| [`@babel/core`](/packages/babel-core) | [](https://www.npmjs.com/package/@babel/core) | [](https://david-dm.org/babel/babel?path=packages/babel-core) |
|
||||
| [`@babel/parser`](/packages/@babel/parser) | [](https://www.npmjs.com/package/@babel/parser) | [](https://david-dm.org/babel/babel?path=packages/babel-parser) |
|
||||
| [`@babel/traverse`](/packages/babel-traverse) | [](https://www.npmjs.com/package/@babel/traverse) | [](https://david-dm.org/babel/babel?path=packages/babel-traverse) |
|
||||
| [`@babel/generator`](/packages/babel-generator) | [](https://www.npmjs.com/package/@babel/generator) | [](https://david-dm.org/babel/babel?path=packages/babel-generator) |
|
||||
|
||||
[`@babel/core`](/packages/babel-core) is the Babel compiler itself; it exposes the `babel.transform` method, where `transformedCode = transform(src).code`.
|
||||
|
||||
The compiler can be broken down into 3 parts:
|
||||
- The parser: [`babylon`](https://github.com/babel/babel/tree/master/packages/babylon)
|
||||
- The parser: [`@babel/parser`](/packages/babel-parser)
|
||||
- The transformer[s]: All the plugins/presets
|
||||
- These all use [`@babel/traverse`](/packages/babel-traverse) to traverse through the AST
|
||||
- The generator: [`@babel/generator`](/packages/babel-generator)
|
||||
|
||||
The flow goes like this:
|
||||
|
||||
input string -> `babylon` parser -> `AST` -> transformer[s] -> `AST` -> `@babel/generator` -> output string
|
||||
input string -> `@babel/parser` parser -> `AST` -> transformer[s] -> `AST` -> `@babel/generator` -> output string
|
||||
|
||||
Check out the [`babel-handbook`](https://github.com/thejameskyle/babel-handbook/blob/master/translations/en/plugin-handbook.md#introduction) for more information on this.
|
||||
|
||||
@@ -36,18 +36,18 @@ Check out the [`babel-handbook`](https://github.com/thejameskyle/babel-handbook/
|
||||
|
||||
| Package | Version | Dependencies |
|
||||
|--------|-------|------------|
|
||||
| [`@babel/cli`](/packages/babel-cli) | [](https://www.npmjs.com/package/babel-cli) | [](https://david-dm.org/babel/babel?path=packages/babel-cli) |
|
||||
| [`@babel/types`](/packages/babel-types) | [](https://www.npmjs.com/package/babel-types) | [](https://david-dm.org/babel/babel?path=packages/babel-types) |
|
||||
| [`@babel/polyfill`](/packages/babel-polyfill) | [](https://www.npmjs.com/package/babel-polyfill) | [](https://david-dm.org/babel/babel?path=packages/babel-polyfill) |
|
||||
| [`@babel/runtime`](/packages/babel-runtime) | [](https://www.npmjs.com/package/babel-runtime) | [](https://david-dm.org/babel/babel?path=packages/babel-runtime) |
|
||||
| [`@babel/register`](/packages/babel-register) | [](https://www.npmjs.com/package/babel-register) | [](https://david-dm.org/babel/babel?path=packages/babel-register) |
|
||||
| [`@babel/template`](/packages/babel-template) | [](https://www.npmjs.com/package/babel-template) | [](https://david-dm.org/babel/babel?path=packages/babel-template) |
|
||||
| [`@babel/helpers`](/packages/babel-helpers) | [](https://www.npmjs.com/package/babel-helpers) | [](https://david-dm.org/babel/babel?path=packages/babel-helpers) |
|
||||
| [`@babel/code-frame`](/packages/babel-code-frame) | [](https://www.npmjs.com/package/babel-code-frame) | [](https://david-dm.org/babel/babel?path=packages/babel-code-frame) |
|
||||
| [`@babel/cli`](/packages/babel-cli) | [](https://www.npmjs.com/package/@babel/cli) | [](https://david-dm.org/babel/babel?path=packages/babel-cli) |
|
||||
| [`@babel/types`](/packages/babel-types) | [](https://www.npmjs.com/package/@babel/types) | [](https://david-dm.org/babel/babel?path=packages/babel-types) |
|
||||
| [`@babel/polyfill`](/packages/babel-polyfill) | [](https://www.npmjs.com/package/@babel/polyfill) | [](https://david-dm.org/babel/babel?path=packages/babel-polyfill) |
|
||||
| [`@babel/runtime`](/packages/babel-runtime) | [](https://www.npmjs.com/package/@babel/runtime) | [](https://david-dm.org/babel/babel?path=packages/babel-runtime) |
|
||||
| [`@babel/register`](/packages/babel-register) | [](https://www.npmjs.com/package/@babel/register) | [](https://david-dm.org/babel/babel?path=packages/babel-register) |
|
||||
| [`@babel/template`](/packages/babel-template) | [](https://www.npmjs.com/package/@babel/template) | [](https://david-dm.org/babel/babel?path=packages/babel-template) |
|
||||
| [`@babel/helpers`](/packages/babel-helpers) | [](https://www.npmjs.com/package/@babel/helpers) | [](https://david-dm.org/babel/babel?path=packages/babel-helpers) |
|
||||
| [`@babel/code-frame`](/packages/babel-code-frame) | [](https://www.npmjs.com/package/@babel/code-frame) | [](https://david-dm.org/babel/babel?path=packages/babel-code-frame) |
|
||||
|
||||
- [`@babel/cli`](/packages/babel-cli) is the CLI tool that runs `@babel/core` and helps with outputting to a directory, a file, stdout and more (also includes `@babel/node` cli). Check out the [docs](https://babeljs.io/docs/usage/cli/).
|
||||
- [`@babel/types`](/packages/babel-types) is used to validate, build and change AST nodes.
|
||||
- [`@babel/polyfill`](/packages/babel-polyfill) is [literally a wrapper](https://github.com/babel/babel/blob/master/packages/babel-polyfill/src/index.js) around [`core-js`](https://github.com/zloirock/core-js) and [regenerator-runtime](https://github.com/facebook/regenerator/tree/master/packages/regenerator-runtime). Check out the [docs](https://babeljs.io/docs/usage/polyfill/).
|
||||
- [`@babel/polyfill`](/packages/babel-polyfill) is [literally a wrapper](/packages/babel-polyfill/src/index.js) around [`core-js`](https://github.com/zloirock/core-js) and [regenerator-runtime](https://github.com/facebook/regenerator/tree/master/packages/regenerator-runtime). Check out the [docs](https://babeljs.io/docs/usage/polyfill/).
|
||||
- [`@babel/runtime`](/packages/babel-runtime) is similar to the polyfill except that it doesn't modify the global scope and is to be used with [`@babel/plugin-transform-runtime`](/packages/babel-plugin-transform-runtime) (usually in library/plugin code). Check out the [docs](https://babeljs.io/docs/plugins/transform-runtime/).
|
||||
- [`@babel/register`](/packages/babel-register) is a way to automatically compile files with Babel on the fly by binding to Node.js `require`. Check out the [docs](http://babeljs.io/docs/usage/require/).
|
||||
- [`@babel/template`](/packages/babel-template) is a helper function that allows constructing AST nodes from a string presentation of the code; this eliminates the tedium of using `@babel/types` for building AST nodes.
|
||||
@@ -62,7 +62,7 @@ The transformer[s] used in Babel are the independent pieces of code that transfo
|
||||
|
||||
| Package | Version | Dependencies | Description |
|
||||
|--------|-------|------------|---|
|
||||
| [`@babel/preset-env`](https://github.com/babel/babel-preset-env) | [](https://www.npmjs.com/package/babel-preset-env) | [](https://david-dm.org/babel/babel-preset-env) | automatically determines plugins and polyfills you need based on your supported environments |
|
||||
| [`@babel/preset-env`](/packages/babel-preset-env) | [](https://www.npmjs.com/package/@babel/preset-env) | [](https://david-dm.org/babel/babel?path=packages/babel-preset-env) | automatically determines plugins and polyfills you need based on your supported environments |
|
||||
|
||||
> You can find community maintained presets on [npm](https://www.npmjs.com/search?q=babel-preset)
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@babel/cli",
|
||||
"version": "7.0.0-beta.37",
|
||||
"version": "7.0.0-beta.48",
|
||||
"description": "Babel command line.",
|
||||
"author": "Sebastian McKenzie <sebmck@gmail.com>",
|
||||
"homepage": "https://babeljs.io/",
|
||||
@@ -20,20 +20,20 @@
|
||||
"convert-source-map": "^1.1.0",
|
||||
"fs-readdir-recursive": "^1.0.0",
|
||||
"glob": "^7.0.0",
|
||||
"lodash": "^4.2.0",
|
||||
"lodash": "^4.17.5",
|
||||
"output-file-sync": "^2.0.0",
|
||||
"slash": "^1.0.0",
|
||||
"source-map": "^0.5.0"
|
||||
},
|
||||
"optionalDependencies": {
|
||||
"chokidar": "^1.6.1"
|
||||
"chokidar": "^2.0.3"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"@babel/core": "7.0.0-beta.37"
|
||||
"@babel/core": "7.0.0-beta.48"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@babel/core": "7.0.0-beta.37",
|
||||
"@babel/helper-fixtures": "7.0.0-beta.37"
|
||||
"@babel/core": "7.0.0-beta.48",
|
||||
"@babel/helper-fixtures": "7.0.0-beta.48"
|
||||
},
|
||||
"bin": {
|
||||
"babel": "./bin/babel.js",
|
||||
|
||||
@@ -6,92 +6,141 @@ import fs from "fs";
|
||||
|
||||
import * as util from "./util";
|
||||
|
||||
export default function(commander, filenames, opts) {
|
||||
function write(src, relative, base) {
|
||||
if (!util.isCompilableExtension(relative, commander.extensions)) {
|
||||
export default async function({ cliOptions, babelOptions }) {
|
||||
const filenames = cliOptions.filenames;
|
||||
|
||||
async function write(src, base) {
|
||||
let relative = path.relative(base, src);
|
||||
|
||||
if (!util.isCompilableExtension(relative, cliOptions.extensions)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// remove extension and then append back on .js
|
||||
relative = util.adjustRelative(relative, commander.keepFileExtension);
|
||||
relative = util.adjustRelative(relative, cliOptions.keepFileExtension);
|
||||
|
||||
const dest = getDest(commander, relative, base);
|
||||
const dest = getDest(relative, base);
|
||||
|
||||
const data = util.compile(
|
||||
src,
|
||||
defaults(
|
||||
{
|
||||
sourceFileName: slash(path.relative(dest + "/..", src)),
|
||||
sourceMapTarget: path.basename(relative),
|
||||
},
|
||||
opts,
|
||||
),
|
||||
);
|
||||
try {
|
||||
const res = await util.compile(
|
||||
src,
|
||||
defaults(
|
||||
{
|
||||
sourceFileName: slash(path.relative(dest + "/..", src)),
|
||||
},
|
||||
babelOptions,
|
||||
),
|
||||
);
|
||||
|
||||
if (!data) return false;
|
||||
if (!res) return false;
|
||||
|
||||
// we've requested explicit sourcemaps to be written to disk
|
||||
if (data.map && commander.sourceMaps && commander.sourceMaps !== "inline") {
|
||||
const mapLoc = dest + ".map";
|
||||
data.code = util.addSourceMappingUrl(data.code, mapLoc);
|
||||
outputFileSync(mapLoc, JSON.stringify(data.map));
|
||||
// we've requested explicit sourcemaps to be written to disk
|
||||
if (
|
||||
res.map &&
|
||||
babelOptions.sourceMaps &&
|
||||
babelOptions.sourceMaps !== "inline"
|
||||
) {
|
||||
const mapLoc = dest + ".map";
|
||||
res.code = util.addSourceMappingUrl(res.code, mapLoc);
|
||||
res.map.file = path.basename(relative);
|
||||
outputFileSync(mapLoc, JSON.stringify(res.map));
|
||||
}
|
||||
|
||||
outputFileSync(dest, res.code);
|
||||
util.chmod(src, dest);
|
||||
|
||||
if (cliOptions.verbose) {
|
||||
console.log(src + " -> " + dest);
|
||||
}
|
||||
|
||||
return true;
|
||||
} catch (err) {
|
||||
if (cliOptions.watch) {
|
||||
console.error(err);
|
||||
return false;
|
||||
}
|
||||
|
||||
throw err;
|
||||
}
|
||||
|
||||
outputFileSync(dest, data.code);
|
||||
util.chmod(src, dest);
|
||||
|
||||
util.log(src + " -> " + dest);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
function getDest(commander, filename, base) {
|
||||
if (commander.relative) return path.join(base, commander.outDir, filename);
|
||||
return path.join(commander.outDir, filename);
|
||||
function getDest(filename, base) {
|
||||
if (cliOptions.relative) {
|
||||
return path.join(base, cliOptions.outDir, filename);
|
||||
}
|
||||
return path.join(cliOptions.outDir, filename);
|
||||
}
|
||||
|
||||
function handleFile(src, filename, base) {
|
||||
const didWrite = write(src, filename, base);
|
||||
function outputDestFolder(outDir) {
|
||||
const outDirPath = path.resolve(outDir);
|
||||
if (!fs.existsSync(outDirPath)) {
|
||||
fs.mkdirSync(outDirPath);
|
||||
}
|
||||
}
|
||||
|
||||
if (!didWrite && commander.copyFiles) {
|
||||
const dest = getDest(commander, filename, base);
|
||||
async function handleFile(src, base) {
|
||||
const written = await write(src, base);
|
||||
|
||||
if (!written && cliOptions.copyFiles) {
|
||||
const filename = path.relative(base, src);
|
||||
const dest = getDest(filename, base);
|
||||
outputFileSync(dest, fs.readFileSync(src));
|
||||
util.chmod(src, dest);
|
||||
}
|
||||
return written;
|
||||
}
|
||||
|
||||
function handle(filename) {
|
||||
if (!fs.existsSync(filename)) return;
|
||||
async function handle(filenameOrDir) {
|
||||
if (!fs.existsSync(filenameOrDir)) return 0;
|
||||
|
||||
const stat = fs.statSync(filename);
|
||||
const stat = fs.statSync(filenameOrDir);
|
||||
|
||||
if (stat.isDirectory(filename)) {
|
||||
const dirname = filename;
|
||||
if (stat.isDirectory(filenameOrDir)) {
|
||||
const dirname = filenameOrDir;
|
||||
|
||||
if (commander.deleteDirOnStart) {
|
||||
util.deleteDir(commander.outDir);
|
||||
let count = 0;
|
||||
|
||||
const files = util.readdir(dirname, cliOptions.includeDotfiles);
|
||||
for (const filename of files) {
|
||||
const src = path.join(dirname, filename);
|
||||
|
||||
const written = await handleFile(src, dirname);
|
||||
if (written) count += 1;
|
||||
}
|
||||
|
||||
util
|
||||
.readdir(dirname, commander.includeDotfiles)
|
||||
.forEach(function(filename) {
|
||||
const src = path.join(dirname, filename);
|
||||
handleFile(src, filename, dirname);
|
||||
});
|
||||
return count;
|
||||
} else {
|
||||
write(filename, path.basename(filename), path.dirname(filename));
|
||||
const filename = filenameOrDir;
|
||||
const written = await handleFile(filename, path.dirname(filename));
|
||||
|
||||
return written ? 1 : 0;
|
||||
}
|
||||
}
|
||||
|
||||
if (!commander.skipInitialBuild) {
|
||||
filenames.forEach(handle);
|
||||
if (!cliOptions.skipInitialBuild) {
|
||||
if (cliOptions.deleteDirOnStart) {
|
||||
util.deleteDir(cliOptions.outDir);
|
||||
}
|
||||
|
||||
outputDestFolder(cliOptions.outDir);
|
||||
|
||||
let compiledFiles = 0;
|
||||
for (const filename of cliOptions.filenames) {
|
||||
compiledFiles += await handle(filename);
|
||||
}
|
||||
|
||||
console.log(
|
||||
`🎉 Successfully compiled ${compiledFiles} ${
|
||||
compiledFiles !== 1 ? "files" : "file"
|
||||
} with Babel.`,
|
||||
);
|
||||
}
|
||||
|
||||
if (commander.watch) {
|
||||
if (cliOptions.watch) {
|
||||
const chokidar = util.requireChokidar();
|
||||
|
||||
filenames.forEach(function(dirname) {
|
||||
const watcher = chokidar.watch(dirname, {
|
||||
filenames.forEach(function(filenameOrDir) {
|
||||
const watcher = chokidar.watch(filenameOrDir, {
|
||||
persistent: true,
|
||||
ignoreInitial: true,
|
||||
awaitWriteFinish: {
|
||||
@@ -102,12 +151,14 @@ export default function(commander, filenames, opts) {
|
||||
|
||||
["add", "change"].forEach(function(type) {
|
||||
watcher.on(type, function(filename) {
|
||||
const relative = path.relative(dirname, filename) || filename;
|
||||
try {
|
||||
handleFile(filename, relative);
|
||||
} catch (err) {
|
||||
console.error(err.stack);
|
||||
}
|
||||
handleFile(
|
||||
filename,
|
||||
filename === filenameOrDir
|
||||
? path.dirname(filenameOrDir)
|
||||
: filenameOrDir,
|
||||
).catch(err => {
|
||||
console.error(err);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -7,23 +7,22 @@ import fs from "fs";
|
||||
|
||||
import * as util from "./util";
|
||||
|
||||
export default function(commander, filenames, opts) {
|
||||
if (commander.sourceMaps === "inline") {
|
||||
opts.sourceMaps = true;
|
||||
}
|
||||
|
||||
let results = [];
|
||||
|
||||
const buildResult = function() {
|
||||
export default async function({ cliOptions, babelOptions }) {
|
||||
function buildResult(fileResults) {
|
||||
const map = new sourceMap.SourceMapGenerator({
|
||||
file: path.basename(commander.outFile || "") || "stdout",
|
||||
sourceRoot: opts.sourceRoot,
|
||||
file:
|
||||
cliOptions.sourceMapTarget ||
|
||||
path.basename(cliOptions.outFile || "") ||
|
||||
"stdout",
|
||||
sourceRoot: babelOptions.sourceRoot,
|
||||
});
|
||||
|
||||
let code = "";
|
||||
let offset = 0;
|
||||
|
||||
results.forEach(function(result) {
|
||||
for (const result of fileResults) {
|
||||
if (!result) continue;
|
||||
|
||||
code += result.code + "\n";
|
||||
|
||||
if (result.map) {
|
||||
@@ -58,13 +57,13 @@ export default function(commander, filenames, opts) {
|
||||
|
||||
offset = code.split("\n").length - 1;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// add the inline sourcemap comment if we've either explicitly asked for inline source
|
||||
// maps, or we've requested them without any output file
|
||||
if (
|
||||
commander.sourceMaps === "inline" ||
|
||||
(!commander.outFile && commander.sourceMaps)
|
||||
babelOptions.sourceMaps === "inline" ||
|
||||
(!cliOptions.outFile && babelOptions.sourceMaps)
|
||||
) {
|
||||
code += "\n" + convertSourceMap.fromObject(map).toComment();
|
||||
}
|
||||
@@ -73,55 +72,62 @@ export default function(commander, filenames, opts) {
|
||||
map: map,
|
||||
code: code,
|
||||
};
|
||||
};
|
||||
}
|
||||
|
||||
const output = function() {
|
||||
const result = buildResult();
|
||||
function output(fileResults) {
|
||||
const result = buildResult(fileResults);
|
||||
|
||||
if (commander.outFile) {
|
||||
if (cliOptions.outFile) {
|
||||
// we've requested for a sourcemap to be written to disk
|
||||
if (commander.sourceMaps && commander.sourceMaps !== "inline") {
|
||||
const mapLoc = commander.outFile + ".map";
|
||||
if (babelOptions.sourceMaps && babelOptions.sourceMaps !== "inline") {
|
||||
const mapLoc = cliOptions.outFile + ".map";
|
||||
result.code = util.addSourceMappingUrl(result.code, mapLoc);
|
||||
fs.writeFileSync(mapLoc, JSON.stringify(result.map));
|
||||
}
|
||||
|
||||
fs.writeFileSync(commander.outFile, result.code);
|
||||
fs.writeFileSync(cliOptions.outFile, result.code);
|
||||
} else {
|
||||
process.stdout.write(result.code + "\n");
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
const stdin = function() {
|
||||
let code = "";
|
||||
function readStdin() {
|
||||
return new Promise((resolve, reject) => {
|
||||
let code = "";
|
||||
|
||||
process.stdin.setEncoding("utf8");
|
||||
process.stdin.setEncoding("utf8");
|
||||
|
||||
process.stdin.on("readable", function() {
|
||||
const chunk = process.stdin.read();
|
||||
if (chunk !== null) code += chunk;
|
||||
process.stdin.on("readable", function() {
|
||||
const chunk = process.stdin.read();
|
||||
if (chunk !== null) code += chunk;
|
||||
});
|
||||
|
||||
process.stdin.on("end", function() {
|
||||
resolve(code);
|
||||
});
|
||||
process.stdin.on("error", reject);
|
||||
});
|
||||
}
|
||||
|
||||
process.stdin.on("end", function() {
|
||||
results.push(
|
||||
util.transform(
|
||||
commander.filename,
|
||||
code,
|
||||
defaults(
|
||||
{
|
||||
sourceFileName: "stdin",
|
||||
},
|
||||
opts,
|
||||
),
|
||||
),
|
||||
);
|
||||
output();
|
||||
});
|
||||
};
|
||||
async function stdin() {
|
||||
const code = await readStdin();
|
||||
|
||||
const walk = function() {
|
||||
const res = await util.transform(
|
||||
cliOptions.filename,
|
||||
code,
|
||||
defaults(
|
||||
{
|
||||
sourceFileName: "stdin",
|
||||
},
|
||||
babelOptions,
|
||||
),
|
||||
);
|
||||
|
||||
output([res]);
|
||||
}
|
||||
|
||||
async function walk(filenames) {
|
||||
const _filenames = [];
|
||||
results = [];
|
||||
|
||||
filenames.forEach(function(filename) {
|
||||
if (!fs.existsSync(filename)) return;
|
||||
@@ -131,7 +137,7 @@ export default function(commander, filenames, opts) {
|
||||
const dirname = filename;
|
||||
|
||||
util
|
||||
.readdirForCompilable(filename, commander.includeDotfiles)
|
||||
.readdirForCompilable(filename, cliOptions.includeDotfiles)
|
||||
.forEach(function(filename) {
|
||||
_filenames.push(path.join(dirname, filename));
|
||||
});
|
||||
@@ -140,40 +146,54 @@ export default function(commander, filenames, opts) {
|
||||
}
|
||||
});
|
||||
|
||||
_filenames.forEach(function(filename) {
|
||||
let sourceFilename = filename;
|
||||
if (commander.outFile) {
|
||||
sourceFilename = path.relative(
|
||||
path.dirname(commander.outFile),
|
||||
sourceFilename,
|
||||
);
|
||||
}
|
||||
sourceFilename = slash(sourceFilename);
|
||||
const results = await Promise.all(
|
||||
_filenames.map(async function(filename) {
|
||||
let sourceFilename = filename;
|
||||
if (cliOptions.outFile) {
|
||||
sourceFilename = path.relative(
|
||||
path.dirname(cliOptions.outFile),
|
||||
sourceFilename,
|
||||
);
|
||||
}
|
||||
sourceFilename = slash(sourceFilename);
|
||||
|
||||
const data = util.compile(
|
||||
filename,
|
||||
defaults(
|
||||
{
|
||||
sourceFileName: sourceFilename,
|
||||
},
|
||||
opts,
|
||||
),
|
||||
);
|
||||
try {
|
||||
return await util.compile(
|
||||
filename,
|
||||
defaults(
|
||||
{
|
||||
sourceFileName: sourceFilename,
|
||||
// Since we're compiling everything to be merged together,
|
||||
// "inline" applies to the final output file, but to the individual
|
||||
// files being concatenated.
|
||||
sourceMaps:
|
||||
babelOptions.sourceMaps === "inline"
|
||||
? true
|
||||
: babelOptions.sourceMaps,
|
||||
},
|
||||
babelOptions,
|
||||
),
|
||||
);
|
||||
} catch (err) {
|
||||
if (!cliOptions.watch) {
|
||||
throw err;
|
||||
}
|
||||
|
||||
if (!data) return;
|
||||
console.error(err);
|
||||
return null;
|
||||
}
|
||||
}),
|
||||
);
|
||||
|
||||
results.push(data);
|
||||
});
|
||||
output(results);
|
||||
}
|
||||
|
||||
output();
|
||||
};
|
||||
|
||||
const files = function() {
|
||||
if (!commander.skipInitialBuild) {
|
||||
walk();
|
||||
async function files(filenames) {
|
||||
if (!cliOptions.skipInitialBuild) {
|
||||
await walk(filenames);
|
||||
}
|
||||
|
||||
if (commander.watch) {
|
||||
if (cliOptions.watch) {
|
||||
const chokidar = util.requireChokidar();
|
||||
chokidar
|
||||
.watch(filenames, {
|
||||
@@ -185,25 +205,26 @@ export default function(commander, filenames, opts) {
|
||||
},
|
||||
})
|
||||
.on("all", function(type, filename) {
|
||||
if (!util.isCompilableExtension(filename, commander.extensions)) {
|
||||
if (!util.isCompilableExtension(filename, cliOptions.extensions)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (type === "add" || type === "change") {
|
||||
util.log(type + " " + filename);
|
||||
try {
|
||||
walk();
|
||||
} catch (err) {
|
||||
console.error(err.stack);
|
||||
if (cliOptions.verbose) {
|
||||
console.log(type + " " + filename);
|
||||
}
|
||||
|
||||
walk(filenames).catch(err => {
|
||||
console.error(err);
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
if (filenames.length) {
|
||||
files();
|
||||
if (cliOptions.filenames.length) {
|
||||
await files(cliOptions.filenames);
|
||||
} else {
|
||||
stdin();
|
||||
await stdin();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,259 +1,13 @@
|
||||
#!/usr/bin/env node
|
||||
|
||||
import fs from "fs";
|
||||
import commander from "commander";
|
||||
import { version } from "@babel/core";
|
||||
import uniq from "lodash/uniq";
|
||||
import glob from "glob";
|
||||
|
||||
import parseArgv from "./options";
|
||||
import dirCommand from "./dir";
|
||||
import fileCommand from "./file";
|
||||
|
||||
import pkg from "../../package.json";
|
||||
const opts = parseArgv(process.argv);
|
||||
|
||||
function booleanify(val: any): boolean | any {
|
||||
if (val === "true" || val == 1) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (val === "false" || val == 0 || !val) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return val;
|
||||
}
|
||||
|
||||
function collect(value, previousValue): Array<string> {
|
||||
// If the user passed the option with no value, like "babel file.js --presets", do nothing.
|
||||
if (typeof value !== "string") return previousValue;
|
||||
|
||||
const values = value.split(",");
|
||||
|
||||
return previousValue ? previousValue.concat(values) : values;
|
||||
}
|
||||
|
||||
/* eslint-disable max-len */
|
||||
// Standard Babel input configs.
|
||||
commander.option(
|
||||
"-f, --filename [filename]",
|
||||
"filename to use when reading from stdin - this will be used in source-maps, errors etc",
|
||||
);
|
||||
commander.option(
|
||||
"--presets [list]",
|
||||
"comma-separated list of preset names",
|
||||
collect,
|
||||
);
|
||||
commander.option(
|
||||
"--plugins [list]",
|
||||
"comma-separated list of plugin names",
|
||||
collect,
|
||||
);
|
||||
commander.option("--config-file [path]", "Path a to .babelrc file to use");
|
||||
commander.option(
|
||||
"--env-name [name]",
|
||||
"The name of the 'env' to use when loading configs and plugins. " +
|
||||
"Defaults to the value of BABEL_ENV, or else NODE_ENV, or else 'development'.",
|
||||
);
|
||||
|
||||
// Basic file input configuration.
|
||||
commander.option("--source-type [script|module]", "");
|
||||
commander.option(
|
||||
"--no-babelrc",
|
||||
"Whether or not to look up .babelrc and .babelignore files",
|
||||
);
|
||||
commander.option(
|
||||
"--ignore [list]",
|
||||
"list of glob paths to **not** compile",
|
||||
collect,
|
||||
);
|
||||
commander.option(
|
||||
"--only [list]",
|
||||
"list of glob paths to **only** compile",
|
||||
collect,
|
||||
);
|
||||
|
||||
// Misc babel config.
|
||||
commander.option(
|
||||
"--no-highlight-code",
|
||||
"enable/disable ANSI syntax highlighting of code frames (on by default)",
|
||||
);
|
||||
|
||||
// General output formatting.
|
||||
commander.option(
|
||||
"--no-comments",
|
||||
"write comments to generated output (true by default)",
|
||||
);
|
||||
commander.option(
|
||||
"--retain-lines",
|
||||
"retain line numbers - will result in really ugly code",
|
||||
);
|
||||
commander.option(
|
||||
"--compact [true|false|auto]",
|
||||
"do not include superfluous whitespace characters and line terminators",
|
||||
booleanify,
|
||||
);
|
||||
commander.option("--minified", "save as much bytes when printing [true|false]");
|
||||
commander.option(
|
||||
"--auxiliary-comment-before [string]",
|
||||
"print a comment before any injected non-user code",
|
||||
);
|
||||
commander.option(
|
||||
"--auxiliary-comment-after [string]",
|
||||
"print a comment after any injected non-user code",
|
||||
);
|
||||
|
||||
// General soucemap formatting.
|
||||
commander.option("-s, --source-maps [true|false|inline|both]", "", booleanify);
|
||||
commander.option(
|
||||
"--source-map-target [string]",
|
||||
"set `file` on returned source map",
|
||||
);
|
||||
commander.option(
|
||||
"--source-file-name [string]",
|
||||
"set `sources[0]` on returned source map",
|
||||
);
|
||||
commander.option(
|
||||
"--source-root [filename]",
|
||||
"the root from which all sources are relative",
|
||||
);
|
||||
|
||||
// Config params for certain module output formats.
|
||||
commander.option(
|
||||
"--module-root [filename]",
|
||||
"optional prefix for the AMD module formatter that will be prepend to the filename on module definitions",
|
||||
);
|
||||
commander.option("-M, --module-ids", "insert an explicit id for modules");
|
||||
commander.option(
|
||||
"--module-id [string]",
|
||||
"specify a custom name for module ids",
|
||||
);
|
||||
|
||||
// "babel" command specific arguments that are not passed to @babel/core.
|
||||
commander.option(
|
||||
"-x, --extensions [extensions]",
|
||||
"List of extensions to compile when a directory has been input [.es6,.js,.es,.jsx,.mjs]",
|
||||
collect,
|
||||
);
|
||||
commander.option(
|
||||
"--keep-file-extension",
|
||||
"Preserve the file extensions of the input files",
|
||||
);
|
||||
commander.option("-w, --watch", "Recompile files on changes");
|
||||
commander.option(
|
||||
"--skip-initial-build",
|
||||
"Do not compile files before watching",
|
||||
);
|
||||
commander.option(
|
||||
"-o, --out-file [out]",
|
||||
"Compile all input files into a single file",
|
||||
);
|
||||
commander.option(
|
||||
"-d, --out-dir [out]",
|
||||
"Compile an input directory of modules into an output directory",
|
||||
);
|
||||
commander.option(
|
||||
"--relative",
|
||||
"Compile into an output directory relative to input directory or file. Requires --out-dir [out]",
|
||||
);
|
||||
commander.option(
|
||||
"-D, --copy-files",
|
||||
"When compiling a directory copy over non-compilable files",
|
||||
);
|
||||
commander.option(
|
||||
"--include-dotfiles",
|
||||
"Include dotfiles when compiling and copying non-compilable files",
|
||||
);
|
||||
commander.option("-q, --quiet", "Don't log anything");
|
||||
commander.option(
|
||||
"--delete-dir-on-start",
|
||||
"Delete the out directory before compilation",
|
||||
);
|
||||
/* eslint-enable max-len */
|
||||
|
||||
commander.version(pkg.version + " (@babel/core " + version + ")");
|
||||
commander.usage("[options] <files ...>");
|
||||
commander.parse(process.argv);
|
||||
|
||||
//
|
||||
|
||||
const errors = [];
|
||||
|
||||
let filenames = commander.args.reduce(function(globbed, input) {
|
||||
let files = glob.sync(input);
|
||||
if (!files.length) files = [input];
|
||||
return globbed.concat(files);
|
||||
}, []);
|
||||
|
||||
filenames = uniq(filenames);
|
||||
|
||||
filenames.forEach(function(filename) {
|
||||
if (!fs.existsSync(filename)) {
|
||||
errors.push(filename + " doesn't exist");
|
||||
}
|
||||
const fn = opts.cliOptions.outDir ? dirCommand : fileCommand;
|
||||
fn(opts).catch(err => {
|
||||
console.error(err);
|
||||
process.exit(1);
|
||||
});
|
||||
|
||||
if (commander.outDir && !filenames.length) {
|
||||
errors.push("filenames required for --out-dir");
|
||||
}
|
||||
|
||||
if (commander.outFile && commander.outDir) {
|
||||
errors.push("cannot have --out-file and --out-dir");
|
||||
}
|
||||
|
||||
if (commander.relative && !commander.outDir) {
|
||||
errors.push("output directory required for --relative");
|
||||
}
|
||||
|
||||
if (commander.watch) {
|
||||
if (!commander.outFile && !commander.outDir) {
|
||||
errors.push("--watch requires --out-file or --out-dir");
|
||||
}
|
||||
|
||||
if (!filenames.length) {
|
||||
errors.push("--watch requires filenames");
|
||||
}
|
||||
}
|
||||
|
||||
if (commander.skipInitialBuild && !commander.watch) {
|
||||
errors.push("--skip-initial-build requires --watch");
|
||||
}
|
||||
if (commander.deleteDirOnStart && !commander.outDir) {
|
||||
errors.push("--delete-dir-on-start requires --out-dir");
|
||||
}
|
||||
|
||||
if (errors.length) {
|
||||
console.error(errors.join(". "));
|
||||
process.exit(2);
|
||||
}
|
||||
|
||||
//
|
||||
|
||||
const opts = commander.opts();
|
||||
//the configFile CLI option maps to the extends option in the node API
|
||||
if (opts.configFile) {
|
||||
opts.extends = opts.configFile;
|
||||
}
|
||||
|
||||
// Delete options that are specific to @babel/cli and shouldn't be passed to @babel/core.
|
||||
delete opts.version;
|
||||
delete opts.extensions;
|
||||
delete opts.watch;
|
||||
delete opts.skipInitialBuild;
|
||||
delete opts.outFile;
|
||||
delete opts.outDir;
|
||||
delete opts.copyFiles;
|
||||
delete opts.includeDotfiles;
|
||||
delete opts.quiet;
|
||||
delete opts.configFile;
|
||||
delete opts.deleteDirOnStart;
|
||||
delete opts.keepFileExtension;
|
||||
delete opts.relative;
|
||||
|
||||
// Commander will default the "--no-" arguments to true, but we want to leave them undefined so that
|
||||
// @babel/core can handle the default-assignment logic on its own.
|
||||
if (opts.babelrc === true) opts.babelrc = undefined;
|
||||
if (opts.comments === true) opts.comments = undefined;
|
||||
if (opts.highlightCode === true) opts.highlightCode = undefined;
|
||||
|
||||
const fn = commander.outDir ? dirCommand : fileCommand;
|
||||
fn(commander, filenames, opts);
|
||||
|
||||
283
packages/babel-cli/src/babel/options.js
Normal file
283
packages/babel-cli/src/babel/options.js
Normal file
@@ -0,0 +1,283 @@
|
||||
import fs from "fs";
|
||||
|
||||
import commander from "commander";
|
||||
import { version } from "@babel/core";
|
||||
import uniq from "lodash/uniq";
|
||||
import glob from "glob";
|
||||
|
||||
import pkg from "../../package.json";
|
||||
|
||||
// Standard Babel input configs.
|
||||
commander.option(
|
||||
"-f, --filename [filename]",
|
||||
"filename to use when reading from stdin - this will be used in source-maps, errors etc",
|
||||
);
|
||||
commander.option(
|
||||
"--presets [list]",
|
||||
"comma-separated list of preset names",
|
||||
collect,
|
||||
);
|
||||
commander.option(
|
||||
"--plugins [list]",
|
||||
"comma-separated list of plugin names",
|
||||
collect,
|
||||
);
|
||||
commander.option("--config-file [path]", "Path a to .babelrc file to use");
|
||||
commander.option(
|
||||
"--env-name [name]",
|
||||
"The name of the 'env' to use when loading configs and plugins. " +
|
||||
"Defaults to the value of BABEL_ENV, or else NODE_ENV, or else 'development'.",
|
||||
);
|
||||
|
||||
// Basic file input configuration.
|
||||
commander.option("--source-type [script|module]", "");
|
||||
commander.option(
|
||||
"--no-babelrc",
|
||||
"Whether or not to look up .babelrc and .babelignore files",
|
||||
);
|
||||
commander.option(
|
||||
"--ignore [list]",
|
||||
"list of glob paths to **not** compile",
|
||||
collect,
|
||||
);
|
||||
commander.option(
|
||||
"--only [list]",
|
||||
"list of glob paths to **only** compile",
|
||||
collect,
|
||||
);
|
||||
|
||||
// Misc babel config.
|
||||
commander.option(
|
||||
"--no-highlight-code",
|
||||
"enable/disable ANSI syntax highlighting of code frames (on by default)",
|
||||
);
|
||||
|
||||
// General output formatting.
|
||||
commander.option(
|
||||
"--no-comments",
|
||||
"write comments to generated output (true by default)",
|
||||
);
|
||||
commander.option(
|
||||
"--retain-lines",
|
||||
"retain line numbers - will result in really ugly code",
|
||||
);
|
||||
commander.option(
|
||||
"--compact [true|false|auto]",
|
||||
"do not include superfluous whitespace characters and line terminators",
|
||||
booleanify,
|
||||
);
|
||||
commander.option("--minified", "save as much bytes when printing [true|false]");
|
||||
commander.option(
|
||||
"--auxiliary-comment-before [string]",
|
||||
"print a comment before any injected non-user code",
|
||||
);
|
||||
commander.option(
|
||||
"--auxiliary-comment-after [string]",
|
||||
"print a comment after any injected non-user code",
|
||||
);
|
||||
|
||||
// General soucemap formatting.
|
||||
commander.option("-s, --source-maps [true|false|inline|both]", "", booleanify);
|
||||
commander.option(
|
||||
"--source-map-target [string]",
|
||||
"set `file` on returned source map",
|
||||
);
|
||||
commander.option(
|
||||
"--source-file-name [string]",
|
||||
"set `sources[0]` on returned source map",
|
||||
);
|
||||
commander.option(
|
||||
"--source-root [filename]",
|
||||
"the root from which all sources are relative",
|
||||
);
|
||||
|
||||
// Config params for certain module output formats.
|
||||
commander.option(
|
||||
"--module-root [filename]",
|
||||
"optional prefix for the AMD module formatter that will be prepend to the filename on module definitions",
|
||||
);
|
||||
commander.option("-M, --module-ids", "insert an explicit id for modules");
|
||||
commander.option(
|
||||
"--module-id [string]",
|
||||
"specify a custom name for module ids",
|
||||
);
|
||||
|
||||
// "babel" command specific arguments that are not passed to @babel/core.
|
||||
commander.option(
|
||||
"-x, --extensions [extensions]",
|
||||
"List of extensions to compile when a directory has been input [.es6,.js,.es,.jsx,.mjs]",
|
||||
collect,
|
||||
);
|
||||
commander.option(
|
||||
"--keep-file-extension",
|
||||
"Preserve the file extensions of the input files",
|
||||
);
|
||||
commander.option("-w, --watch", "Recompile files on changes");
|
||||
commander.option(
|
||||
"--skip-initial-build",
|
||||
"Do not compile files before watching",
|
||||
);
|
||||
commander.option(
|
||||
"-o, --out-file [out]",
|
||||
"Compile all input files into a single file",
|
||||
);
|
||||
commander.option(
|
||||
"-d, --out-dir [out]",
|
||||
"Compile an input directory of modules into an output directory",
|
||||
);
|
||||
commander.option(
|
||||
"--relative",
|
||||
"Compile into an output directory relative to input directory or file. Requires --out-dir [out]",
|
||||
);
|
||||
commander.option(
|
||||
"-D, --copy-files",
|
||||
"When compiling a directory copy over non-compilable files",
|
||||
);
|
||||
commander.option(
|
||||
"--include-dotfiles",
|
||||
"Include dotfiles when compiling and copying non-compilable files",
|
||||
);
|
||||
commander.option("--verbose", "Log everything");
|
||||
commander.option(
|
||||
"--delete-dir-on-start",
|
||||
"Delete the out directory before compilation",
|
||||
);
|
||||
|
||||
commander.version(pkg.version + " (@babel/core " + version + ")");
|
||||
commander.usage("[options] <files ...>");
|
||||
|
||||
export default function parseArgv(args: Array<string>) {
|
||||
//
|
||||
commander.parse(args);
|
||||
|
||||
const errors = [];
|
||||
|
||||
let filenames = commander.args.reduce(function(globbed, input) {
|
||||
let files = glob.sync(input);
|
||||
if (!files.length) files = [input];
|
||||
return globbed.concat(files);
|
||||
}, []);
|
||||
|
||||
filenames = uniq(filenames);
|
||||
|
||||
filenames.forEach(function(filename) {
|
||||
if (!fs.existsSync(filename)) {
|
||||
errors.push(filename + " doesn't exist");
|
||||
}
|
||||
});
|
||||
|
||||
if (commander.outDir && !filenames.length) {
|
||||
errors.push("filenames required for --out-dir");
|
||||
}
|
||||
|
||||
if (commander.outFile && commander.outDir) {
|
||||
errors.push("cannot have --out-file and --out-dir");
|
||||
}
|
||||
|
||||
if (commander.relative && !commander.outDir) {
|
||||
errors.push("output directory required for --relative");
|
||||
}
|
||||
|
||||
if (commander.watch) {
|
||||
if (!commander.outFile && !commander.outDir) {
|
||||
errors.push("--watch requires --out-file or --out-dir");
|
||||
}
|
||||
|
||||
if (!filenames.length) {
|
||||
errors.push("--watch requires filenames");
|
||||
}
|
||||
}
|
||||
|
||||
if (commander.skipInitialBuild && !commander.watch) {
|
||||
errors.push("--skip-initial-build requires --watch");
|
||||
}
|
||||
if (commander.deleteDirOnStart && !commander.outDir) {
|
||||
errors.push("--delete-dir-on-start requires --out-dir");
|
||||
}
|
||||
|
||||
if (
|
||||
!commander.outDir &&
|
||||
filenames.length === 0 &&
|
||||
typeof commander.filename !== "string" &&
|
||||
commander.babelrc !== false
|
||||
) {
|
||||
errors.push(
|
||||
"stdin compilation requires either -f/--filename [filename] or --no-babelrc",
|
||||
);
|
||||
}
|
||||
|
||||
if (errors.length) {
|
||||
console.error(errors.join(". "));
|
||||
process.exit(2);
|
||||
}
|
||||
|
||||
const opts = commander.opts();
|
||||
|
||||
return {
|
||||
babelOptions: {
|
||||
presets: opts.presets,
|
||||
plugins: opts.plugins,
|
||||
configFile: opts.configFile,
|
||||
envName: opts.envName,
|
||||
sourceType: opts.sourceType,
|
||||
ignore: opts.ignore,
|
||||
only: opts.only,
|
||||
retainLines: opts.retainLines,
|
||||
compact: opts.compact,
|
||||
minified: opts.minified,
|
||||
auxiliaryCommentBefore: opts.auxiliaryCommentBefore,
|
||||
auxiliaryCommentAfter: opts.auxiliaryCommentAfter,
|
||||
sourceMaps: opts.sourceMaps,
|
||||
sourceFileName: opts.sourceFileName,
|
||||
sourceRoot: opts.sourceRoot,
|
||||
moduleRoot: opts.moduleRoot,
|
||||
moduleIds: opts.moduleIds,
|
||||
moduleId: opts.moduleId,
|
||||
|
||||
// Commander will default the "--no-" arguments to true, but we want to
|
||||
// leave them undefined so that @babel/core can handle the
|
||||
// default-assignment logic on its own.
|
||||
babelrc: opts.babelrc === true ? undefined : opts.babelrc,
|
||||
highlightCode:
|
||||
opts.highlightCode === true ? undefined : opts.highlightCode,
|
||||
comments: opts.comments === true ? undefined : opts.comments,
|
||||
},
|
||||
cliOptions: {
|
||||
filename: opts.filename,
|
||||
filenames,
|
||||
extensions: opts.extensions,
|
||||
keepFileExtension: opts.keepFileExtension,
|
||||
watch: opts.watch,
|
||||
skipInitialBuild: opts.skipInitialBuild,
|
||||
outFile: opts.outFile,
|
||||
outDir: opts.outDir,
|
||||
relative: opts.relative,
|
||||
copyFiles: opts.copyFiles,
|
||||
includeDotfiles: opts.includeDotfiles,
|
||||
verbose: opts.verbose,
|
||||
deleteDirOnStart: opts.deleteDirOnStart,
|
||||
sourceMapTarget: opts.sourceMapTarget,
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
function booleanify(val: any): boolean | any {
|
||||
if (val === "true" || val == 1) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (val === "false" || val == 0 || !val) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return val;
|
||||
}
|
||||
|
||||
function collect(value, previousValue): Array<string> {
|
||||
// If the user passed the option with no value, like "babel file.js --presets", do nothing.
|
||||
if (typeof value !== "string") return previousValue;
|
||||
|
||||
const values = value.split(",");
|
||||
|
||||
return previousValue ? previousValue.concat(values) : values;
|
||||
}
|
||||
@@ -1,4 +1,3 @@
|
||||
import commander from "commander";
|
||||
import readdirRecursive from "fs-readdir-recursive";
|
||||
import * as babel from "@babel/core";
|
||||
import includes from "lodash/includes";
|
||||
@@ -46,29 +45,27 @@ export function addSourceMappingUrl(code, loc) {
|
||||
return code + "\n//# sourceMappingURL=" + path.basename(loc);
|
||||
}
|
||||
|
||||
export function log(msg) {
|
||||
if (!commander.quiet) console.log(msg);
|
||||
}
|
||||
|
||||
export function transform(filename, code, opts) {
|
||||
opts = Object.assign({}, opts, {
|
||||
opts = {
|
||||
...opts,
|
||||
filename,
|
||||
});
|
||||
};
|
||||
|
||||
return babel.transform(code, opts);
|
||||
return new Promise((resolve, reject) => {
|
||||
babel.transform(code, opts, (err, result) => {
|
||||
if (err) reject(err);
|
||||
else resolve(result);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
export function compile(filename, opts) {
|
||||
try {
|
||||
return babel.transformFileSync(filename, opts);
|
||||
} catch (err) {
|
||||
if (commander.watch) {
|
||||
console.error(err);
|
||||
return { ignored: true };
|
||||
} else {
|
||||
throw err;
|
||||
}
|
||||
}
|
||||
return new Promise((resolve, reject) => {
|
||||
babel.transformFile(filename, opts, (err, result) => {
|
||||
if (err) reject(err);
|
||||
else resolve(result);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
export function deleteDir(path) {
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
{
|
||||
"args": ["--config-file", "../.othername_babelrc"]
|
||||
}
|
||||
"args": ["--config-file", "../.othername_babelrc", "-f", "file.js"]
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
"--out-dir", "lib",
|
||||
"--copy-files",
|
||||
"--include-dotfiles",
|
||||
"--ignore", "src/foo"
|
||||
"--ignore", "src/foo",
|
||||
"--verbose"
|
||||
]
|
||||
}
|
||||
|
||||
@@ -1 +1,2 @@
|
||||
src/index.js -> lib/index.js
|
||||
🎉 Successfully compiled 1 file with Babel.
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
"--out-dir", "lib",
|
||||
"--copy-files",
|
||||
"--include-dotfiles",
|
||||
"--only", "src/foo"
|
||||
"--only", "src/foo",
|
||||
"--verbose"
|
||||
]
|
||||
}
|
||||
|
||||
@@ -1,2 +1,3 @@
|
||||
src/foo/.foo.js -> lib/foo/.foo.js
|
||||
src/foo/bar.js -> lib/foo/bar.js
|
||||
🎉 Successfully compiled 2 files with Babel.
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
{
|
||||
"args": ["src", "--out-dir", "lib", "--copy-files", "--include-dotfiles"]
|
||||
"args": ["src", "--out-dir", "lib", "--copy-files", "--include-dotfiles", "--verbose"]
|
||||
}
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
src/.foo.js -> lib/.foo.js
|
||||
src/bar/index.js -> lib/bar/index.js
|
||||
src/foo/foo.js -> lib/foo/foo.js
|
||||
🎉 Successfully compiled 3 files with Babel.
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
"src",
|
||||
"--out-dir", "lib",
|
||||
"--copy-files",
|
||||
"--ignore", "src/foo/*"
|
||||
"--ignore", "src/foo/*",
|
||||
"--verbose"
|
||||
]
|
||||
}
|
||||
|
||||
@@ -1 +1,2 @@
|
||||
src/index.js -> lib/index.js
|
||||
🎉 Successfully compiled 1 file with Babel.
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
"src",
|
||||
"--out-dir", "lib",
|
||||
"--copy-files",
|
||||
"--only", "src/foo/*"
|
||||
"--only", "src/foo/*",
|
||||
"--verbose"
|
||||
]
|
||||
}
|
||||
|
||||
@@ -1 +1,2 @@
|
||||
src/foo/bar.js -> lib/foo/bar.js
|
||||
🎉 Successfully compiled 1 file with Babel.
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
{
|
||||
"args": ["src", "--out-dir", "lib", "--copy-files"]
|
||||
"args": ["src", "--out-dir", "lib", "--copy-files", "--verbose"]
|
||||
}
|
||||
|
||||
@@ -1,2 +1,3 @@
|
||||
src/bar/index.js -> lib/bar/index.js
|
||||
src/foo/foo.js -> lib/foo/foo.js
|
||||
🎉 Successfully compiled 2 files with Babel.
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
{
|
||||
"args": ["src", "--out-dir", "lib", "--ignore", "src/bar"]
|
||||
"args": ["src", "--out-dir", "lib", "--ignore", "src/bar", "--verbose"]
|
||||
}
|
||||
|
||||
@@ -1 +1,2 @@
|
||||
src/foobar/foo.js -> lib/foobar/foo.js
|
||||
🎉 Successfully compiled 1 file with Babel.
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
{
|
||||
"args": ["src", "--out-dir", "lib", "--ignore", "**/*.foo.js"]
|
||||
"args": ["src", "--out-dir", "lib", "--ignore", "**/*.foo.js", "--verbose"]
|
||||
}
|
||||
|
||||
@@ -2,3 +2,4 @@ src/a.js -> lib/a.js
|
||||
src/b.js -> lib/b.js
|
||||
src/baz/c.js -> lib/baz/c.js
|
||||
src/foo.js -> lib/foo.js
|
||||
🎉 Successfully compiled 4 files with Babel.
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
{
|
||||
"args": ["src", "--out-dir", "lib", "--ignore", "src/foo/*"]
|
||||
"args": ["src", "--out-dir", "lib", "--ignore", "src/foo/*", "--verbose"]
|
||||
}
|
||||
|
||||
@@ -1 +1,2 @@
|
||||
src/bar/index.js -> lib/bar/index.js
|
||||
🎉 Successfully compiled 1 file with Babel.
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
{
|
||||
"args": ["src", "--out-dir", "lib", "--only", "**/*.foo.js"]
|
||||
"args": ["src", "--out-dir", "lib", "--only", "**/*.foo.js", "--verbose"]
|
||||
}
|
||||
|
||||
@@ -1,2 +1,3 @@
|
||||
src/a.foo.js -> lib/a.foo.js
|
||||
src/baz/b.foo.js -> lib/baz/b.foo.js
|
||||
🎉 Successfully compiled 2 files with Babel.
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
{
|
||||
"args": ["src", "--out-dir", "lib", "--only", "src/bar/*"]
|
||||
"args": ["src", "--out-dir", "lib", "--only", "src/bar/*", "--verbose"]
|
||||
}
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user