Compare commits
203 Commits
v6.26.0
...
v7.0.0-alp
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c732f5e1d0 | ||
|
|
9acbcccff8 | ||
|
|
ae0681aa3f | ||
|
|
beae0ff9ba | ||
|
|
8f848b4b32 | ||
|
|
d39400c9d5 | ||
|
|
9155c613cb | ||
|
|
b2ced1d6bd | ||
|
|
7ad697cd86 | ||
|
|
348cc5eeff | ||
|
|
5576a8942b | ||
|
|
878a7c5fdb | ||
|
|
d3497348b8 | ||
|
|
4bf8e4d08d | ||
|
|
0c2ac9d907 | ||
|
|
899daafcf4 | ||
|
|
fa23b662c2 | ||
|
|
3d74dc044f | ||
|
|
67253c5d27 | ||
|
|
7935dd6642 | ||
|
|
f3ef03abfd | ||
|
|
75328ccc60 | ||
|
|
dea509377c | ||
|
|
7262ad631f | ||
|
|
1f2f63ccdf | ||
|
|
1ada981077 | ||
|
|
18bbaa0253 | ||
|
|
4278ede41f | ||
|
|
7a1ccf076c | ||
|
|
cff1c8db39 | ||
|
|
b8cf7b89f2 | ||
|
|
0eb898d95b | ||
|
|
d0b6db1901 | ||
|
|
d7a77f4161 | ||
|
|
287869dcc2 | ||
|
|
a498371005 | ||
|
|
ab68800e06 | ||
|
|
f438a4e6b6 | ||
|
|
c687b703ae | ||
|
|
c9a851a218 | ||
|
|
299e51298c | ||
|
|
0cd541b7d8 | ||
|
|
796d497ea1 | ||
|
|
640515b3f6 | ||
|
|
e155859b12 | ||
|
|
c0779fdb71 | ||
|
|
60b5409183 | ||
|
|
26b9f9ed15 | ||
|
|
483958b24d | ||
|
|
b75d80386c | ||
|
|
f20da57317 | ||
|
|
b2c977a1b0 | ||
|
|
7e25dccc6e | ||
|
|
c4ebc8553b | ||
|
|
b638c8b3eb | ||
|
|
492ee95f27 | ||
|
|
2b774f46fb | ||
|
|
a55f38b127 | ||
|
|
ceb68f5bb7 | ||
|
|
7d37017a5f | ||
|
|
7551a8e666 | ||
|
|
4901f33423 | ||
|
|
95c905c5d2 | ||
|
|
94024961ba | ||
|
|
ae8728c146 | ||
|
|
baafe486b3 | ||
|
|
534f621183 | ||
|
|
a15de19888 | ||
|
|
3c63431c7e | ||
|
|
f3f907bdb3 | ||
|
|
7b5d4fe069 | ||
|
|
b71569ff6c | ||
|
|
3e2d731d50 | ||
|
|
12a2124d16 | ||
|
|
6c4810cea5 | ||
|
|
05ee30c9f7 | ||
|
|
38720ae309 | ||
|
|
bf13ed4da0 | ||
|
|
344f0a68c9 | ||
|
|
62def8da19 | ||
|
|
39c862c195 | ||
|
|
b6194a8533 | ||
|
|
612cce399a | ||
|
|
4e96a2da5e | ||
|
|
edf2c76d63 | ||
|
|
bf1b6ace53 | ||
|
|
2c0907acdc | ||
|
|
dd1bc3b183 | ||
|
|
bf4664b430 | ||
|
|
dcb0f91f38 | ||
|
|
738bd54bfb | ||
|
|
83356abd92 | ||
|
|
c1be6a36c4 | ||
|
|
188fe105c2 | ||
|
|
540f9b2ad6 | ||
|
|
2642c2c2df | ||
|
|
8c1cd177b2 | ||
|
|
0bc802cf1b | ||
|
|
5b50b73d8b | ||
|
|
4f72232ca9 | ||
|
|
2c564a6973 | ||
|
|
0c0f090a98 | ||
|
|
523a41b25e | ||
|
|
c00ffb83be | ||
|
|
d328af0aec | ||
|
|
8744303f06 | ||
|
|
752788f22f | ||
|
|
01b250a8fa | ||
|
|
5287e13817 | ||
|
|
911b71f2c6 | ||
|
|
25212445ed | ||
|
|
8dc2176a04 | ||
|
|
cf5ab16ff9 | ||
|
|
ca71c74696 | ||
|
|
305165eda4 | ||
|
|
12eb25c06c | ||
|
|
7c8825f6b2 | ||
|
|
3d987ed6c0 | ||
|
|
230712e091 | ||
|
|
0553d7761d | ||
|
|
02473a72c1 | ||
|
|
d054cd0ea8 | ||
|
|
0336cab757 | ||
|
|
6888a2c51b | ||
|
|
39eca84642 | ||
|
|
836dd95c44 | ||
|
|
23de276718 | ||
|
|
0d1edb9811 | ||
|
|
8a82cc060a | ||
|
|
990d22a8d4 | ||
|
|
f7e2d88f6c | ||
|
|
11e54a6bd3 | ||
|
|
22a5ce43f1 | ||
|
|
67ed224df0 | ||
|
|
c86f922dc7 | ||
|
|
b4b03d48fa | ||
|
|
0847ae055d | ||
|
|
4ad0caaa66 | ||
|
|
b9c0f364c4 | ||
|
|
65f23b8212 | ||
|
|
b363e7b199 | ||
|
|
2b9c3735fd | ||
|
|
3ff77a61e4 | ||
|
|
6d6cdf6baf | ||
|
|
9acae54a29 | ||
|
|
696e63c58b | ||
|
|
6529cb5f01 | ||
|
|
f3e92010c5 | ||
|
|
d33d023594 | ||
|
|
87ca6150ae | ||
|
|
45087b258b | ||
|
|
724c949244 | ||
|
|
c1f7d67bae | ||
|
|
4ee385e96c | ||
|
|
d9f01cbce6 | ||
|
|
7e540cdcc9 | ||
|
|
7c62278dcd | ||
|
|
1ba3269ece | ||
|
|
ca78da6501 | ||
|
|
fa2a373acd | ||
|
|
9188be9ed5 | ||
|
|
bc8f476d33 | ||
|
|
b3e208fcd0 | ||
|
|
c3098d2437 | ||
|
|
6c03cb0783 | ||
|
|
dde70c0a04 | ||
|
|
870a37834c | ||
|
|
982cdb2a3a | ||
|
|
ad91c6d186 | ||
|
|
9083bd6283 | ||
|
|
6fa6f5924d | ||
|
|
ba0df23365 | ||
|
|
e530e3c025 | ||
|
|
e09ea222c9 | ||
|
|
e5aa501327 | ||
|
|
3f95a767f2 | ||
|
|
0766f29591 | ||
|
|
398b0326a3 | ||
|
|
2ee3a017f0 | ||
|
|
728072f47b | ||
|
|
20a5249dea | ||
|
|
661102c7ea | ||
|
|
e9d87ed55c | ||
|
|
090f7abda4 | ||
|
|
1aa7a2a1a3 | ||
|
|
d0b42d4313 | ||
|
|
12886ea495 | ||
|
|
b978996ba4 | ||
|
|
1742035a98 | ||
|
|
e4ba28c294 | ||
|
|
81c3578adc | ||
|
|
d710e6dd5b | ||
|
|
3a5ce620c8 | ||
|
|
c468b15a15 | ||
|
|
ef3ab66847 | ||
|
|
e2c5a513f6 | ||
|
|
2471d5ebf3 | ||
|
|
d67b55e88f | ||
|
|
90279f102f | ||
|
|
8b25e21520 | ||
|
|
1672982873 | ||
|
|
868c9ecc11 | ||
|
|
7135751750 |
3
.babelignore
Normal file
3
.babelignore
Normal file
@@ -0,0 +1,3 @@
|
||||
# Ensure babel-register won't compile fixtures, or try to recompile compiled code.
|
||||
packages/*/test/fixtures
|
||||
packages/*/lib
|
||||
29
.babelrc.js
Normal file
29
.babelrc.js
Normal file
@@ -0,0 +1,29 @@
|
||||
"use strict";
|
||||
|
||||
let envOpts = {
|
||||
loose: true
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
comments: false,
|
||||
presets: [
|
||||
[
|
||||
"env", envOpts
|
||||
],
|
||||
"stage-0",
|
||||
"flow",
|
||||
],
|
||||
env: {
|
||||
cov: {
|
||||
auxiliaryCommentBefore: "istanbul ignore next",
|
||||
plugins: ["istanbul"]
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
if (process.env.BABEL_ENV === 'development') {
|
||||
envOpts.targets = {
|
||||
node: "current"
|
||||
};
|
||||
envOpts.debug = true;
|
||||
};
|
||||
@@ -1,11 +1,9 @@
|
||||
/lib
|
||||
scripts
|
||||
packages/babel-core/src/transformation/templates
|
||||
packages/babel-runtime
|
||||
!packages/babel-runtime/scripts
|
||||
!packages/babel-runtime/core-js.js
|
||||
packages/*/node_modules
|
||||
packages/*/lib
|
||||
packages/*/dist
|
||||
packages/*/test/fixtures
|
||||
vendor
|
||||
_babel.github.io
|
||||
Gulpfile.js
|
||||
packages/*/test/tmp
|
||||
|
||||
@@ -1,6 +1,11 @@
|
||||
{
|
||||
"extends": "babel",
|
||||
"rules": {
|
||||
"comma-dangle": ["error", "always-multiline"],
|
||||
"curly": ["error", "multi-line"],
|
||||
"func-call-spacing": "error",
|
||||
"key-spacing": "error",
|
||||
"no-multi-spaces": "error"
|
||||
},
|
||||
"env": {
|
||||
"node": true,
|
||||
|
||||
15
.github/ISSUE_TEMPLATE.md
vendored
15
.github/ISSUE_TEMPLATE.md
vendored
@@ -1,20 +1,21 @@
|
||||
<!---
|
||||
BEFORE YOU SUBMIT please read the following:
|
||||
Thanks for filing an issue 😄 ! Before you submit, please read the following:
|
||||
|
||||
Please search open/closed issues before submitting since someone might have asked the same thing before!
|
||||
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:
|
||||
|
||||
* Discussion Forum: https://discuss.babeljs.io/
|
||||
* Slack Community: https://slack.babeljs.io/
|
||||
* StackOverflow: http://stackoverflow.com/questions/tagged/babeljs using the tag `babeljs`
|
||||
* Slack community: https://slack.babeljs.io/
|
||||
* Also have a look at the Readme for more information on how to get support:
|
||||
* 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
|
||||
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
|
||||
@@ -53,7 +54,7 @@ var your => (code) => here;
|
||||
### Your Environment
|
||||
<!--- Include as many relevant details about the environment you experienced the bug in -->
|
||||
|
||||
| software | version
|
||||
| software | version(s)
|
||||
| ---------------- | -------
|
||||
| Babel |
|
||||
| node |
|
||||
|
||||
15
.gitignore
vendored
15
.gitignore
vendored
@@ -1,22 +1,25 @@
|
||||
.DS_Store
|
||||
node_modules
|
||||
test/tmp
|
||||
*.log
|
||||
*.cache
|
||||
/.eslintcache
|
||||
/templates.json
|
||||
/tests.json
|
||||
/browser.js
|
||||
/browser-polyfill.js
|
||||
/runtime.js
|
||||
/coverage
|
||||
dist
|
||||
/.package.json
|
||||
/packages/babel-runtime/core-js
|
||||
/packages/babel-runtime/core-js/**/*.js
|
||||
!/packages/babel-runtime/core-js/map.js
|
||||
/packages/babel-runtime/helpers/*.js
|
||||
!/packages/babel-runtime/helpers/toArray.js
|
||||
/packages/babel-runtime/helpers/builtin/*.js
|
||||
!/packages/babel-runtime/helpers/builtin/toArray.js
|
||||
/packages/babel-runtime/helpers/builtin/es6/*.js
|
||||
!/packages/babel-runtime/helpers/builtin/es6/toArray.js
|
||||
/packages/babel-runtime/helpers/es6/*.js
|
||||
!/packages/babel-runtime/helpers/es6/toArray.js
|
||||
/packages/babel-register/test/.babel
|
||||
/packages/*/lib
|
||||
_babel.github.io
|
||||
/tests/.browser-build.js
|
||||
.nyc_output
|
||||
/babel.sublime-workspace
|
||||
|
||||
@@ -3,27 +3,24 @@ git:
|
||||
sudo: false
|
||||
language: node_js
|
||||
cache:
|
||||
yarn: true
|
||||
directories:
|
||||
- node_modules
|
||||
node_js:
|
||||
- '7'
|
||||
- '6'
|
||||
- '5'
|
||||
- '4'
|
||||
- '0.12'
|
||||
|
||||
env:
|
||||
- JOB=test
|
||||
|
||||
script:
|
||||
- 'if [ "$JOB" = "test" ]; then make test-ci; fi'
|
||||
- 'if [ "$JOB" = "test-coverage" ]; then make test-ci-coverage; fi'
|
||||
- 'if [ "$JOB" = "lint" ]; then make lint && make flow; fi'
|
||||
|
||||
matrix:
|
||||
fast_finish: true
|
||||
include:
|
||||
- node_js: "7"
|
||||
env: JOB=test-coverage
|
||||
- node_js: "node"
|
||||
env: JOB=lint
|
||||
|
||||
|
||||
@@ -40,10 +40,13 @@ Feel free to check out the `#discussion`/`#development` channels on our [slack](
|
||||
|
||||
**Note:** Versions `< 5.1.10` can't be built.
|
||||
|
||||
Babel is built for node 0.10 and up but we develop using node 6. Make sure you are on npm 3.
|
||||
Babel is built for node 4 and up but we develop using node 6. Make sure you are on npm 3.
|
||||
|
||||
You can check this with `node -v` and `npm -v`.
|
||||
|
||||
In addition, make sure that Yarn is installed.
|
||||
Installation instructions can be found here: https://yarnpkg.com/en/docs/install.
|
||||
|
||||
### Setup
|
||||
|
||||
```sh
|
||||
|
||||
83
Gulpfile.js
83
Gulpfile.js
@@ -1,77 +1,52 @@
|
||||
var plumber = require("gulp-plumber");
|
||||
var through = require("through2");
|
||||
var chalk = require("chalk");
|
||||
var newer = require("gulp-newer");
|
||||
var babel = require("gulp-babel");
|
||||
var watch = require("gulp-watch");
|
||||
var gutil = require("gulp-util");
|
||||
var gulp = require("gulp");
|
||||
var path = require("path");
|
||||
"use strict";
|
||||
|
||||
var scripts = "./packages/*/src/**/*.js";
|
||||
const plumber = require("gulp-plumber");
|
||||
const through = require("through2");
|
||||
const chalk = require("chalk");
|
||||
const newer = require("gulp-newer");
|
||||
const babel = require("gulp-babel");
|
||||
const watch = require("gulp-watch");
|
||||
const gutil = require("gulp-util");
|
||||
const gulp = require("gulp");
|
||||
const path = require("path");
|
||||
|
||||
var srcEx, libFragment;
|
||||
const base = path.join(__dirname, "packages");
|
||||
const scripts = "./packages/*/src/**/*.js";
|
||||
|
||||
if (path.win32 === path) {
|
||||
srcEx = /(packages\\[^\\]+)\\src\\/;
|
||||
libFragment = "$1\\lib\\";
|
||||
} else {
|
||||
srcEx = new RegExp("(packages/[^/]+)/src/");
|
||||
libFragment = "$1/lib/";
|
||||
function swapSrcWithLib(srcPath) {
|
||||
const parts = srcPath.split(path.sep);
|
||||
parts[1] = "lib";
|
||||
return parts.join(path.sep);
|
||||
}
|
||||
|
||||
var mapToDest = function (path) { return path.replace(srcEx, libFragment); };
|
||||
var dest = "packages";
|
||||
|
||||
gulp.task("default", ["build"]);
|
||||
|
||||
gulp.task("build", function () {
|
||||
return gulp.src(scripts)
|
||||
return gulp.src(scripts, { base: base })
|
||||
.pipe(plumber({
|
||||
errorHandler: function (err) {
|
||||
gutil.log(err.stack);
|
||||
}
|
||||
},
|
||||
}))
|
||||
.pipe(newer({
|
||||
dest: base,
|
||||
map: swapSrcWithLib,
|
||||
}))
|
||||
.pipe(newer({map: mapToDest}))
|
||||
.pipe(through.obj(function (file, enc, callback) {
|
||||
gutil.log("Compiling", "'" + chalk.cyan(file.path) + "'...");
|
||||
gutil.log("Compiling", "'" + chalk.cyan(file.relative) + "'...");
|
||||
callback(null, file);
|
||||
}))
|
||||
.pipe(babel())
|
||||
.pipe(through.obj(function (file, enc, callback) {
|
||||
file._path = file.path;
|
||||
file.path = mapToDest(file.path);
|
||||
// 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);
|
||||
}))
|
||||
.pipe(gulp.dest(dest));
|
||||
.pipe(gulp.dest(base));
|
||||
});
|
||||
|
||||
// TODO: remove this section
|
||||
// temporarily just copying the old code since watch isn't working
|
||||
var dest = "packages";
|
||||
gulp.task("build-watch", function () {
|
||||
return gulp.src(scripts)
|
||||
.pipe(plumber({
|
||||
errorHandler: function (err) {
|
||||
gutil.log(err.stack);
|
||||
}
|
||||
}))
|
||||
.pipe(through.obj(function (file, enc, callback) {
|
||||
file._path = file.path;
|
||||
file.path = file.path.replace(srcEx, libFragment);
|
||||
callback(null, file);
|
||||
}))
|
||||
.pipe(newer(dest))
|
||||
.pipe(through.obj(function (file, enc, callback) {
|
||||
gutil.log("Compiling", "'" + chalk.cyan(file._path) + "'...");
|
||||
callback(null, file);
|
||||
}))
|
||||
.pipe(babel())
|
||||
.pipe(gulp.dest(dest));
|
||||
});
|
||||
|
||||
gulp.task("watch", ["build-watch"], function (callback) {
|
||||
watch(scripts, {debounceDelay: 200}, function () {
|
||||
gulp.start("build-watch");
|
||||
gulp.task("watch", ["build"], function () {
|
||||
watch(scripts, { debounceDelay: 200 }, function () {
|
||||
gulp.start("build");
|
||||
});
|
||||
});
|
||||
|
||||
14
Makefile
14
Makefile
@@ -16,20 +16,22 @@ build-dist: build
|
||||
|
||||
watch: clean
|
||||
rm -rf packages/*/lib
|
||||
./node_modules/.bin/gulp watch
|
||||
BABEL_ENV=development ./node_modules/.bin/gulp watch
|
||||
|
||||
lint:
|
||||
./node_modules/.bin/eslint packages/ --format=codeframe
|
||||
./node_modules/.bin/eslint scripts packages *.js --format=codeframe
|
||||
|
||||
flow:
|
||||
./node_modules/.bin/flow check
|
||||
|
||||
fix:
|
||||
./node_modules/.bin/eslint packages/ --format=codeframe --fix
|
||||
./node_modules/.bin/eslint scripts packages *.js --format=codeframe --fix
|
||||
|
||||
clean: test-clean
|
||||
rm -rf packages/babel-polyfill/browser*
|
||||
rm -rf packages/babel-polyfill/dist
|
||||
# rm -rf packages/babel-runtime/helpers
|
||||
# rm -rf packages/babel-runtime/core-js
|
||||
rm -rf coverage
|
||||
rm -rf packages/*/npm-debug*
|
||||
|
||||
@@ -63,14 +65,14 @@ publish:
|
||||
BABEL_ENV=production make build-dist
|
||||
make test
|
||||
# not using lerna independent mode atm, so only update packages that have changed since we use ^
|
||||
./node_modules/.bin/lerna publish --only-explicit-updates
|
||||
# --only-explicit-updates
|
||||
./node_modules/.bin/lerna publish --npm-tag=next --exact --skip-temp-tag
|
||||
make clean
|
||||
|
||||
bootstrap:
|
||||
make clean-all
|
||||
npm install
|
||||
yarn
|
||||
./node_modules/.bin/lerna bootstrap
|
||||
make build
|
||||
cd packages/babel-runtime; \
|
||||
npm install; \
|
||||
node scripts/build-dist.js
|
||||
|
||||
47
README.md
47
README.md
@@ -137,27 +137,9 @@ After Babel 6, the default transforms were removed; if you don't specify any plu
|
||||
|
||||
The transformer[s] used in Babel are the independent pieces of code that transform specific things. For example: the [`es2015-arrow-functions`](/packages/babel-plugin-transform-es2015-arrow-functions) transform specifically changes arrow functions into a regular function. Presets are just simply an array of plugins that make it easier to run a whole a set of transforms without specifying each one manually.
|
||||
|
||||
There are a few presets that we maintain officially.
|
||||
|
||||
| Package | Version | Dependencies |
|
||||
|--------|-------|------------|
|
||||
| [`babel-preset-es2015`](/packages/babel-preset-es2015) | [](https://www.npmjs.com/package/babel-preset-es2015) | [](https://david-dm.org/babel/babel?path=packages/babel-preset-es2015) |
|
||||
| [`babel-preset-es2016`](/packages/babel-preset-es2016) | [](https://www.npmjs.com/package/babel-preset-es2016) | [](https://david-dm.org/babel/babel?path=packages/babel-preset-es2016) |
|
||||
| [`babel-preset-es2017`](/packages/babel-preset-es2017) | [](https://www.npmjs.com/package/babel-preset-es2017) | [](https://david-dm.org/babel/babel?path=packages/babel-preset-es2017) |
|
||||
| [`babel-preset-latest`](/packages/babel-preset-latest) | [](https://www.npmjs.com/package/babel-preset-latest) | [](https://david-dm.org/babel/babel?path=packages/babel-preset-latest) |
|
||||
| [`babel-preset-stage-0`](/packages/babel-preset-stage-0) | [](https://www.npmjs.com/package/babel-preset-stage-0) | [](https://david-dm.org/babel/babel?path=packages/babel-preset-stage-0) |
|
||||
| [`babel-preset-stage-1`](/packages/babel-preset-stage-1) | [](https://www.npmjs.com/package/babel-preset-stage-1) | [](https://david-dm.org/babel/babel?path=packages/babel-preset-stage-1) |
|
||||
| [`babel-preset-stage-2`](/packages/babel-preset-stage-2) | [](https://www.npmjs.com/package/babel-preset-stage-2) | [](https://david-dm.org/babel/babel?path=packages/babel-preset-stage-2) |
|
||||
| [`babel-preset-stage-3`](/packages/babel-preset-stage-3) | [](https://www.npmjs.com/package/babel-preset-stage-3) | [](https://david-dm.org/babel/babel?path=packages/babel-preset-stage-3) |
|
||||
| [`babel-preset-react`](/packages/babel-preset-react) | [](https://www.npmjs.com/package/babel-preset-react) | [](https://david-dm.org/babel/babel?path=packages/babel-preset-react) |
|
||||
| [`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) |
|
||||
|
||||
We maintain:
|
||||
|
||||
- a preset for each yearly release of ECMAScript (Javascript) starting from ES6/ES2015.
|
||||
- a preset for react (JSX/Flow).
|
||||
- a preset for each [stage (0-3)](http://babeljs.io/docs/plugins/#stage-x-experimental-presets) of the [TC-39 Process](https://tc39.github.io/process-document/) for ECMAScript proposals.
|
||||
- a preset that can automatically determine plugins and polyfills you need based on your supported environments.
|
||||
| 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 |
|
||||
|
||||
> You can find community maintained presets on [npm](https://www.npmjs.com/search?q=babel-preset)
|
||||
|
||||
@@ -184,24 +166,24 @@ These are mostly for internal use in various plugins: `babel-helper-x`.
|
||||
### Core members
|
||||
|
||||
[](https://github.com/babel) | [](https://github.com/danez) | [](https://github.com/loganfsmyth) | [](https://github.com/hzoo) |
|
||||
|---|---|---|---|---|
|
||||
|---|---|---|---|
|
||||
Babel | Daniel Tschinder | Logan Smyth | Henry Zhu |
|
||||
:octocat: [@babel](https://github.com/babel) | [@danez](https://github.com/danez) | [@loganfsmyth](https://github.com/loganfsmyth) | [@hzoo](https://github.com/hzoo) |
|
||||
:bird: [@babeljs](https://twitter.com/babeljs) | [@TschinderDaniel](https://twitter.com/TschinderDaniel) | [@loganfsmyth](https://twitter.com/loganfsmyth) | [@left_pad](https://twitter.com/left_pad) |
|
||||
|
||||
### Members
|
||||
|
||||
[](https://github.com/drewml) | [](https://github.com/boopathi) | [](https://github.com/existentialism) | [](https://github.com/danharper) | [](https://github.com/kovensky) |
|
||||
|---|---|---|---|---|---|---|---|---|
|
||||
| Andrew Levine | Boopathi Rajaa | Brian Ng | Dan Harper | Diogo Franco |
|
||||
| [@drewml](https://github.com/drewml) | [@boopathi](https://github.com/boopathi) | [@existentialism](https://github.com/existentialism) | [@danharper](https://github.com/danharper) | [@kovensky](https://github.com/kovensky) |
|
||||
| [@drewml](https://twitter.com/drewml) | [@heisenbugger](https://twitter.com/heisenbugger) | [@existentialism](https://twitter.com/existentialism) | [@DanHarper7](https://twitter.com/DanHarper7) | [@kovnsk](https://twitter.com/kovnsk) |
|
||||
[](https://github.com/drewml) | [](https://github.com/boopathi) | [](https://github.com/existentialism) | [](https://github.com/danharper) | [](https://github.com/kovensky) | [](https://github.com/aaronang) | [](https://github.com/yavorsky) |
|
||||
|---|---|---|---|---|---|---|
|
||||
| Andrew Levine | Boopathi Rajaa | Brian Ng | Dan Harper | Diogo Franco | Aaron Ang | Artem Yavorsky |
|
||||
| [@drewml](https://github.com/drewml) | [@boopathi](https://github.com/boopathi) | [@existentialism](https://github.com/existentialism) | [@danharper](https://github.com/danharper) | [@kovensky](https://github.com/kovensky) | [@aaronang](https://github.com/aaronang) | [@yavorsky](https://github.com/yavorsky) |
|
||||
| [@drewml](https://twitter.com/drewml) | [@heisenbugger](https://twitter.com/heisenbugger) | [@existentialism](https://twitter.com/existentialism) | [@DanHarper7](https://twitter.com/DanHarper7) | [@kovnsk](https://twitter.com/kovnsk) | [@_aaronang](https://twitter.com/_aaronang) | [@yavorsky_](https://twitter.com/yavorsky_) |
|
||||
|
||||
[](https://github.com/kangax) | [](https://github.com/kaicataldo) | [](https://github.com/motiz88) | [](https://github.com/xtuc) |
|
||||
|---|---|---|---|---|---|---|---|---|
|
||||
| Juriy Zaytsev | Kai Cataldo | Moti Zilberman | Sven Sauleau |
|
||||
| [@kangax](https://github.com/kangax) | [@kaicataldo](https://github.com/kaicataldo) | [@motiz88](https://github.com/motiz88) | [@xtuc](https://github.com/xtuc) |
|
||||
| [@kangax](https://twitter.com/kangax) | [@kai_cataldo](https://twitter.com/kai_cataldo) | [@motiz88](https://twitter.com/motiz88) | [@svensauleau](https://twitter.com/svensauleau) |
|
||||
[](https://github.com/kangax) | [](https://github.com/kaicataldo) | [](https://github.com/motiz88) | [](https://github.com/xtuc) | [](https://github.com/STRML) | [](https://github.com/chicoxyzzy) |
|
||||
|---|---|---|---|---|---|
|
||||
| Juriy Zaytsev | Kai Cataldo | Moti Zilberman | Sven Sauleau | Samuel Reed | Sergey Rubanov |
|
||||
| [@kangax](https://github.com/kangax) | [@kaicataldo](https://github.com/kaicataldo) | [@motiz88](https://github.com/motiz88) | [@xtuc](https://github.com/xtuc) | [@STRML](https://github.com/STRML) | [@chicoxyzzy](https://github.com/chicoxyzzy) |
|
||||
| [@kangax](https://twitter.com/kangax) | [@kai_cataldo](https://twitter.com/kai_cataldo) | [@motiz88](https://twitter.com/motiz88) | [@svensauleau](https://twitter.com/svensauleau) | [@STRML_](https://twitter.com/STRML_) | [@chicoxyzzy](https://twitter.com/chicoxyzzy) |
|
||||
|
||||
### Non-Human Members
|
||||
|
||||
@@ -222,3 +204,4 @@ Amjad Masad | James Kyle | Jesse McCarthy | Sebastian McKenzie |
|
||||
## License
|
||||
|
||||
[MIT](https://github.com/babel/babel/blob/master/LICENSE)
|
||||
|
||||
|
||||
12
circle.yml
12
circle.yml
@@ -1,8 +1,16 @@
|
||||
machine:
|
||||
node:
|
||||
version:
|
||||
0.10.46
|
||||
6
|
||||
|
||||
dependencies:
|
||||
pre:
|
||||
- curl -o- -L https://yarnpkg.com/install.sh | bash
|
||||
cache_directories:
|
||||
- ~/.yarn-cache
|
||||
override:
|
||||
- yarn
|
||||
|
||||
test:
|
||||
override:
|
||||
- make test-ci
|
||||
- make test-ci-coverage
|
||||
|
||||
@@ -2,12 +2,12 @@
|
||||
|
||||
**NOTE:** Compiler support does not dictate the runtime requirements of compiled code.
|
||||
|
||||
## Supported environments
|
||||
## Officially supported environments
|
||||
|
||||
The Babel compiler is **only** supported in these environments:
|
||||
|
||||
- Modern browsers such as Chrome, Firefox, Safari, Edge etc.
|
||||
- Node 0.10+
|
||||
- Node.js 4 and upper versions
|
||||
|
||||
## Unsupported environments
|
||||
|
||||
@@ -17,7 +17,6 @@ to:
|
||||
- Rhino
|
||||
- Nashorn
|
||||
- Internet Explorer
|
||||
- ...
|
||||
|
||||
**NOTE:** If Babel works in any of the unsupported environments, it is purely
|
||||
coincidental and has no bearing on future compatibility. Use at your own risk.
|
||||
|
||||
20
lerna.json
20
lerna.json
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"lerna": "2.0.0-beta.23",
|
||||
"version": "6.24.0",
|
||||
"lerna": "2.0.0-beta.38",
|
||||
"version": "7.0.0-alpha.7",
|
||||
"changelog": {
|
||||
"repo": "babel/babel",
|
||||
"labels": {
|
||||
@@ -13,13 +13,13 @@
|
||||
"tag: internal": ":house: Internal"
|
||||
}
|
||||
},
|
||||
"bootstrapConfig": {
|
||||
"ignore": "babel-runtime"
|
||||
},
|
||||
"publishConfig": {
|
||||
"ignore": [
|
||||
"*.md",
|
||||
"test/**"
|
||||
]
|
||||
"cacheDir": ".changelog",
|
||||
"commands": {
|
||||
"publish": {
|
||||
"ignore": [
|
||||
"*.md",
|
||||
"test/**"
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
18
lib/types.js
18
lib/types.js
@@ -581,8 +581,8 @@ declare class BabelNodeDeclareVariable extends BabelNode {
|
||||
id: any;
|
||||
}
|
||||
|
||||
declare class BabelNodeExistentialTypeParam extends BabelNode {
|
||||
type: "ExistentialTypeParam";
|
||||
declare class BabelNodeExistsTypeAnnotation extends BabelNode {
|
||||
type: "ExistsTypeAnnotation";
|
||||
}
|
||||
|
||||
declare class BabelNodeFunctionTypeAnnotation extends BabelNode {
|
||||
@@ -632,8 +632,8 @@ declare class BabelNodeNullableTypeAnnotation extends BabelNode {
|
||||
typeAnnotation: any;
|
||||
}
|
||||
|
||||
declare class BabelNodeNumericLiteralTypeAnnotation extends BabelNode {
|
||||
type: "NumericLiteralTypeAnnotation";
|
||||
declare class BabelNodeNumberLiteralTypeAnnotation extends BabelNode {
|
||||
type: "NumberLiteralTypeAnnotation";
|
||||
}
|
||||
|
||||
declare class BabelNodeNumberTypeAnnotation extends BabelNode {
|
||||
@@ -873,7 +873,7 @@ type BabelNodeClass = BabelNodeClassDeclaration | BabelNodeClassExpression;
|
||||
type BabelNodeModuleDeclaration = BabelNodeExportAllDeclaration | BabelNodeExportDefaultDeclaration | BabelNodeExportNamedDeclaration | BabelNodeImportDeclaration;
|
||||
type BabelNodeExportDeclaration = BabelNodeExportAllDeclaration | BabelNodeExportDefaultDeclaration | BabelNodeExportNamedDeclaration;
|
||||
type BabelNodeModuleSpecifier = BabelNodeExportSpecifier | BabelNodeImportDefaultSpecifier | BabelNodeImportNamespaceSpecifier | BabelNodeImportSpecifier | BabelNodeExportDefaultSpecifier | BabelNodeExportNamespaceSpecifier;
|
||||
type BabelNodeFlow = BabelNodeAnyTypeAnnotation | BabelNodeArrayTypeAnnotation | BabelNodeBooleanTypeAnnotation | BabelNodeBooleanLiteralTypeAnnotation | BabelNodeNullLiteralTypeAnnotation | BabelNodeClassImplements | BabelNodeClassProperty | BabelNodeDeclareClass | BabelNodeDeclareFunction | BabelNodeDeclareInterface | BabelNodeDeclareModule | BabelNodeDeclareModuleExports | BabelNodeDeclareTypeAlias | BabelNodeDeclareVariable | BabelNodeExistentialTypeParam | BabelNodeFunctionTypeAnnotation | BabelNodeFunctionTypeParam | BabelNodeGenericTypeAnnotation | BabelNodeInterfaceExtends | BabelNodeInterfaceDeclaration | BabelNodeIntersectionTypeAnnotation | BabelNodeMixedTypeAnnotation | BabelNodeNullableTypeAnnotation | BabelNodeNumericLiteralTypeAnnotation | BabelNodeNumberTypeAnnotation | BabelNodeStringLiteralTypeAnnotation | BabelNodeStringTypeAnnotation | BabelNodeThisTypeAnnotation | BabelNodeTupleTypeAnnotation | BabelNodeTypeofTypeAnnotation | BabelNodeTypeAlias | BabelNodeTypeAnnotation | BabelNodeTypeCastExpression | BabelNodeTypeParameterDeclaration | BabelNodeTypeParameterInstantiation | BabelNodeObjectTypeAnnotation | BabelNodeObjectTypeCallProperty | BabelNodeObjectTypeIndexer | BabelNodeObjectTypeProperty | BabelNodeQualifiedTypeIdentifier | BabelNodeUnionTypeAnnotation | BabelNodeVoidTypeAnnotation;
|
||||
type BabelNodeFlow = BabelNodeAnyTypeAnnotation | BabelNodeArrayTypeAnnotation | BabelNodeBooleanTypeAnnotation | BabelNodeBooleanLiteralTypeAnnotation | BabelNodeNullLiteralTypeAnnotation | BabelNodeClassImplements | BabelNodeClassProperty | BabelNodeDeclareClass | BabelNodeDeclareFunction | BabelNodeDeclareInterface | BabelNodeDeclareModule | BabelNodeDeclareModuleExports | BabelNodeDeclareTypeAlias | BabelNodeDeclareVariable | BabelNodeExistsTypeAnnotation | BabelNodeFunctionTypeAnnotation | BabelNodeFunctionTypeParam | BabelNodeGenericTypeAnnotation | BabelNodeInterfaceExtends | BabelNodeInterfaceDeclaration | BabelNodeIntersectionTypeAnnotation | BabelNodeMixedTypeAnnotation | BabelNodeNullableTypeAnnotation | BabelNodeNumberLiteralTypeAnnotation | BabelNodeNumberTypeAnnotation | BabelNodeStringLiteralTypeAnnotation | BabelNodeStringTypeAnnotation | BabelNodeThisTypeAnnotation | BabelNodeTupleTypeAnnotation | BabelNodeTypeofTypeAnnotation | BabelNodeTypeAlias | BabelNodeTypeAnnotation | BabelNodeTypeCastExpression | BabelNodeTypeParameterDeclaration | BabelNodeTypeParameterInstantiation | BabelNodeObjectTypeAnnotation | BabelNodeObjectTypeCallProperty | BabelNodeObjectTypeIndexer | BabelNodeObjectTypeProperty | BabelNodeQualifiedTypeIdentifier | BabelNodeUnionTypeAnnotation | BabelNodeVoidTypeAnnotation;
|
||||
type BabelNodeFlowBaseAnnotation = BabelNodeAnyTypeAnnotation | BabelNodeBooleanTypeAnnotation | BabelNodeNullLiteralTypeAnnotation | BabelNodeMixedTypeAnnotation | BabelNodeNumberTypeAnnotation | BabelNodeStringTypeAnnotation | BabelNodeThisTypeAnnotation | BabelNodeVoidTypeAnnotation;
|
||||
type BabelNodeFlowDeclaration = BabelNodeDeclareClass | BabelNodeDeclareFunction | BabelNodeDeclareInterface | BabelNodeDeclareModule | BabelNodeDeclareModuleExports | BabelNodeDeclareTypeAlias | BabelNodeDeclareVariable | BabelNodeInterfaceDeclaration | BabelNodeTypeAlias;
|
||||
type BabelNodeJSX = BabelNodeJSXAttribute | BabelNodeJSXClosingElement | BabelNodeJSXElement | BabelNodeJSXEmptyExpression | BabelNodeJSXExpressionContainer | BabelNodeJSXIdentifier | BabelNodeJSXMemberExpression | BabelNodeJSXNamespacedName | BabelNodeJSXOpeningElement | BabelNodeJSXSpreadAttribute | BabelNodeJSXText;
|
||||
@@ -965,7 +965,7 @@ declare module "babel-types" {
|
||||
declare function declareModuleExports(typeAnnotation: any): BabelNodeDeclareModuleExports;
|
||||
declare function declareTypeAlias(id: any, typeParameters: any, right: any): BabelNodeDeclareTypeAlias;
|
||||
declare function declareVariable(id: any): BabelNodeDeclareVariable;
|
||||
declare function existentialTypeParam(): BabelNodeExistentialTypeParam;
|
||||
declare function existsTypeAnnotation(): BabelNodeExistsTypeAnnotation;
|
||||
declare function functionTypeAnnotation(typeParameters: any, params: any, rest: any, returnType: any): BabelNodeFunctionTypeAnnotation;
|
||||
declare function functionTypeParam(name: any, typeAnnotation: any): BabelNodeFunctionTypeParam;
|
||||
declare function genericTypeAnnotation(id: any, typeParameters: any): BabelNodeGenericTypeAnnotation;
|
||||
@@ -974,7 +974,7 @@ declare module "babel-types" {
|
||||
declare function intersectionTypeAnnotation(types: any): BabelNodeIntersectionTypeAnnotation;
|
||||
declare function mixedTypeAnnotation(): BabelNodeMixedTypeAnnotation;
|
||||
declare function nullableTypeAnnotation(typeAnnotation: any): BabelNodeNullableTypeAnnotation;
|
||||
declare function numericLiteralTypeAnnotation(): BabelNodeNumericLiteralTypeAnnotation;
|
||||
declare function numberLiteralTypeAnnotation(): BabelNodeNumberLiteralTypeAnnotation;
|
||||
declare function numberTypeAnnotation(): BabelNodeNumberTypeAnnotation;
|
||||
declare function stringLiteralTypeAnnotation(): BabelNodeStringLiteralTypeAnnotation;
|
||||
declare function stringTypeAnnotation(): BabelNodeStringTypeAnnotation;
|
||||
@@ -1101,7 +1101,7 @@ declare module "babel-types" {
|
||||
declare function isDeclareModuleExports(node: Object, opts?: Object): boolean;
|
||||
declare function isDeclareTypeAlias(node: Object, opts?: Object): boolean;
|
||||
declare function isDeclareVariable(node: Object, opts?: Object): boolean;
|
||||
declare function isExistentialTypeParam(node: Object, opts?: Object): boolean;
|
||||
declare function isExistsTypeAnnotation(node: Object, opts?: Object): boolean;
|
||||
declare function isFunctionTypeAnnotation(node: Object, opts?: Object): boolean;
|
||||
declare function isFunctionTypeParam(node: Object, opts?: Object): boolean;
|
||||
declare function isGenericTypeAnnotation(node: Object, opts?: Object): boolean;
|
||||
@@ -1110,7 +1110,7 @@ declare module "babel-types" {
|
||||
declare function isIntersectionTypeAnnotation(node: Object, opts?: Object): boolean;
|
||||
declare function isMixedTypeAnnotation(node: Object, opts?: Object): boolean;
|
||||
declare function isNullableTypeAnnotation(node: Object, opts?: Object): boolean;
|
||||
declare function isNumericLiteralTypeAnnotation(node: Object, opts?: Object): boolean;
|
||||
declare function isNumberLiteralTypeAnnotation(node: Object, opts?: Object): boolean;
|
||||
declare function isNumberTypeAnnotation(node: Object, opts?: Object): boolean;
|
||||
declare function isStringLiteralTypeAnnotation(node: Object, opts?: Object): boolean;
|
||||
declare function isStringTypeAnnotation(node: Object, opts?: Object): boolean;
|
||||
|
||||
47
package.json
47
package.json
@@ -10,16 +10,13 @@
|
||||
},
|
||||
"devDependencies": {
|
||||
"async": "^1.5.0",
|
||||
"babel-core": "^6.13.2",
|
||||
"babel-core": "^7.0.0-alpha.6",
|
||||
"babel-eslint": "^7.0.0",
|
||||
"babel-plugin-istanbul": "^2.0.1",
|
||||
"babel-plugin-transform-class-properties": "^6.6.0",
|
||||
"babel-plugin-transform-flow-strip-types": "^6.3.13",
|
||||
"babel-plugin-transform-runtime": "^6.3.13",
|
||||
"babel-preset-es2015": "^6.13.2",
|
||||
"babel-preset-stage-0": "^6.0.0",
|
||||
"babel-register": "^6.14.0",
|
||||
"babel-runtime": "^6.0.0",
|
||||
"babel-preset-env": "^2.0.0-alpha.3",
|
||||
"babel-preset-flow": "^7.0.0-alpha.3",
|
||||
"babel-preset-stage-0": "^7.0.0-alpha.3",
|
||||
"babel-register": "^7.0.0-alpha.6",
|
||||
"browserify": "^13.1.1",
|
||||
"bundle-collapser": "^1.2.1",
|
||||
"chai": "^3.5.0",
|
||||
@@ -29,14 +26,14 @@
|
||||
"eslint": "^3.9.0",
|
||||
"eslint-config-babel": "^6.0.0",
|
||||
"eslint-plugin-flowtype": "^2.20.0",
|
||||
"flow-bin": "^0.34.0",
|
||||
"flow-bin": "^0.41.0",
|
||||
"gulp": "^3.9.0",
|
||||
"gulp-babel": "^6.0.0",
|
||||
"gulp-babel": "babel/gulp-babel#b7-alpha",
|
||||
"gulp-newer": "^1.0.0",
|
||||
"gulp-plumber": "^1.0.1",
|
||||
"gulp-util": "^3.0.7",
|
||||
"gulp-watch": "^4.3.5",
|
||||
"lerna": "2.0.0-beta.23",
|
||||
"lerna": "^2.0.0-beta.38",
|
||||
"lerna-changelog": "^0.2.0",
|
||||
"lodash": "^4.2.0",
|
||||
"mocha": "^3.0.0",
|
||||
@@ -48,35 +45,9 @@
|
||||
"uglify-js": "^2.4.16"
|
||||
},
|
||||
"devEngines": {
|
||||
"node": ">= 0.10 <= 7.x",
|
||||
"node": ">= 4.x <= 7.x",
|
||||
"npm": "2.x || 3.x || 4.x"
|
||||
},
|
||||
"babel": {
|
||||
"comments": false,
|
||||
"presets": [
|
||||
[
|
||||
"es2015",
|
||||
{
|
||||
"loose": true
|
||||
}
|
||||
],
|
||||
"stage-0"
|
||||
],
|
||||
"plugins": [
|
||||
"./scripts/add-module-exports",
|
||||
"transform-runtime",
|
||||
"transform-class-properties",
|
||||
"transform-flow-strip-types"
|
||||
],
|
||||
"env": {
|
||||
"cov": {
|
||||
"auxiliaryCommentBefore": "istanbul ignore next",
|
||||
"plugins": [
|
||||
"istanbul"
|
||||
]
|
||||
}
|
||||
}
|
||||
},
|
||||
"nyc": {
|
||||
"all": true,
|
||||
"exclude": [
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
src
|
||||
test
|
||||
node_modules
|
||||
*.log
|
||||
|
||||
@@ -1 +1 @@
|
||||
throw new Error("Use the `babel-core` package not `babel`.");
|
||||
throw new Error("Use the `babel-core` package instead of `babel-cli`.");
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "babel-cli",
|
||||
"version": "6.24.0",
|
||||
"version": "7.0.0-alpha.7",
|
||||
"description": "Babel command line.",
|
||||
"author": "Sebastian McKenzie <sebmck@gmail.com>",
|
||||
"homepage": "https://babeljs.io/",
|
||||
@@ -16,17 +16,15 @@
|
||||
"compiler"
|
||||
],
|
||||
"dependencies": {
|
||||
"babel-core": "^6.24.0",
|
||||
"babel-register": "^6.24.0",
|
||||
"babel-polyfill": "^6.23.0",
|
||||
"babel-runtime": "^6.22.0",
|
||||
"babel-core": "7.0.0-alpha.7",
|
||||
"babel-register": "7.0.0-alpha.7",
|
||||
"babel-polyfill": "7.0.0-alpha.7",
|
||||
"commander": "^2.8.1",
|
||||
"convert-source-map": "^1.1.0",
|
||||
"fs-readdir-recursive": "^1.0.0",
|
||||
"glob": "^7.0.0",
|
||||
"lodash": "^4.2.0",
|
||||
"output-file-sync": "^1.1.0",
|
||||
"path-is-absolute": "^1.0.0",
|
||||
"slash": "^1.0.0",
|
||||
"source-map": "^0.5.0",
|
||||
"v8flags": "^2.0.10"
|
||||
@@ -35,7 +33,7 @@
|
||||
"chokidar": "^1.6.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"babel-helper-fixtures": "^6.22.0"
|
||||
"babel-helper-fixtures": "^7.0.0-alpha.3"
|
||||
},
|
||||
"bin": {
|
||||
"babel-doctor": "./bin/babel-doctor.js",
|
||||
|
||||
@@ -1,3 +0,0 @@
|
||||
#!/bin/sh
|
||||
set -e
|
||||
npm link babel-core
|
||||
@@ -1,26 +1,36 @@
|
||||
import pathIsAbsolute from "path-is-absolute";
|
||||
import commander from "commander";
|
||||
import Module from "module";
|
||||
import { inspect } from "util";
|
||||
import path from "path";
|
||||
import repl from "repl";
|
||||
import { util } from "babel-core";
|
||||
import * as babel from "babel-core";
|
||||
import vm from "vm";
|
||||
import "babel-polyfill";
|
||||
import register from "babel-register";
|
||||
|
||||
import pkg from "../package.json";
|
||||
|
||||
const program = new commander.Command("babel-node");
|
||||
|
||||
function collect(value, previousValue): Array<string> {
|
||||
// If the user passed the option with no value, like "babel-node 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 */
|
||||
program.option("-e, --eval [script]", "Evaluate script");
|
||||
program.option("-p, --print [code]", "Evaluate script and print result");
|
||||
program.option("-o, --only [globs]", "");
|
||||
program.option("-i, --ignore [globs]", "");
|
||||
program.option("-x, --extensions [extensions]", "List of extensions to hook into [.es6,.js,.es,.jsx]");
|
||||
program.option("-w, --plugins [string]", "", util.list);
|
||||
program.option("-b, --presets [string]", "", util.list);
|
||||
program.option("-o, --only [globs]", "A comma-separated list of glob patterns to compile", collect);
|
||||
program.option("-i, --ignore [globs]", "A comma-separated list of glob patterns to skip compiling", collect);
|
||||
program.option("-x, --extensions [extensions]", "List of extensions to hook into [.es6,.js,.es,.jsx]", collect);
|
||||
program.option("-w, --plugins [string]", "", collect);
|
||||
program.option("-b, --presets [string]", "", collect);
|
||||
/* eslint-enable max-len */
|
||||
|
||||
const pkg = require("../package.json");
|
||||
program.version(pkg.version);
|
||||
program.usage("[options] [ -e script | script.js ] [arguments]");
|
||||
program.parse(process.argv);
|
||||
@@ -29,10 +39,10 @@ program.parse(process.argv);
|
||||
|
||||
register({
|
||||
extensions: program.extensions,
|
||||
ignore: program.ignore,
|
||||
only: program.only,
|
||||
plugins: program.plugins,
|
||||
presets: program.presets,
|
||||
ignore: program.ignore,
|
||||
only: program.only,
|
||||
plugins: program.plugins,
|
||||
presets: program.presets,
|
||||
});
|
||||
|
||||
//
|
||||
@@ -55,8 +65,8 @@ const replPlugin = ({ types: t }) => ({
|
||||
// If the executed code doesn't evaluate to a value,
|
||||
// prevent implicit strict mode from printing 'use strict'.
|
||||
path.pushContainer("body", t.expressionStatement(t.identifier("undefined")));
|
||||
}
|
||||
}
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
//
|
||||
@@ -68,11 +78,11 @@ const _eval = function (code, filename) {
|
||||
code = babel.transform(code, {
|
||||
filename: filename,
|
||||
presets: program.presets,
|
||||
plugins: (program.plugins || []).concat([replPlugin])
|
||||
plugins: (program.plugins || []).concat([replPlugin]),
|
||||
}).code;
|
||||
|
||||
return vm.runInThisContext(code, {
|
||||
filename: filename
|
||||
filename: filename,
|
||||
});
|
||||
};
|
||||
|
||||
@@ -85,10 +95,10 @@ if (program.eval || program.print) {
|
||||
|
||||
const module = new Module(global.__filename);
|
||||
module.filename = global.__filename;
|
||||
module.paths = Module._nodeModulePaths(global.__dirname);
|
||||
module.paths = Module._nodeModulePaths(global.__dirname);
|
||||
|
||||
global.exports = module.exports;
|
||||
global.module = module;
|
||||
global.module = module;
|
||||
global.require = module.require.bind(module);
|
||||
|
||||
const result = _eval(code, global.__filename);
|
||||
@@ -123,7 +133,7 @@ if (program.eval || program.print) {
|
||||
|
||||
// make the filename absolute
|
||||
const filename = args[0];
|
||||
if (!pathIsAbsolute(filename)) args[0] = path.join(process.cwd(), filename);
|
||||
if (!path.isAbsolute(filename)) args[0] = path.join(process.cwd(), filename);
|
||||
|
||||
// add back on node and concat the sliced args
|
||||
process.argv = ["node"].concat(args);
|
||||
@@ -141,7 +151,7 @@ function replStart() {
|
||||
input: process.stdin,
|
||||
output: process.stdout,
|
||||
eval: replEval,
|
||||
useGlobal: true
|
||||
useGlobal: true,
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -1,7 +1,16 @@
|
||||
import commander from "commander";
|
||||
import { util, buildExternalHelpers } from "babel-core";
|
||||
import { buildExternalHelpers } from "babel-core";
|
||||
|
||||
commander.option("-l, --whitelist [whitelist]", "Whitelist of helpers to ONLY include", util.list);
|
||||
function collect(value, previousValue): Array<string> {
|
||||
// If the user passed the option with no value, like "babel-external-helpers --whitelist", do nothing.
|
||||
if (typeof value !== "string") return previousValue;
|
||||
|
||||
const values = value.split(",");
|
||||
|
||||
return previousValue ? previousValue.concat(values) : values;
|
||||
}
|
||||
|
||||
commander.option("-l, --whitelist [whitelist]", "Whitelist of helpers to ONLY include", collect);
|
||||
commander.option("-t, --output-type [type]", "Type of output (global|umd|var)", "global");
|
||||
|
||||
commander.usage("[options]");
|
||||
|
||||
@@ -3,8 +3,8 @@
|
||||
* when found, before invoking the "real" _babel-node(1) executable.
|
||||
*/
|
||||
|
||||
const getV8Flags = require("v8flags");
|
||||
const path = require("path");
|
||||
import getV8Flags from "v8flags";
|
||||
import path from "path";
|
||||
|
||||
let args = [path.join(__dirname, "_babel-node")];
|
||||
|
||||
@@ -14,7 +14,7 @@ let userArgs;
|
||||
// separate node arguments from script arguments
|
||||
const argSeparator = babelArgs.indexOf("--");
|
||||
if (argSeparator > -1) {
|
||||
userArgs = babelArgs.slice(argSeparator); // including the --
|
||||
userArgs = babelArgs.slice(argSeparator); // including the --
|
||||
babelArgs = babelArgs.slice(0, argSeparator);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,21 +1,26 @@
|
||||
const outputFileSync = require("output-file-sync");
|
||||
const slash = require("slash");
|
||||
const path = require("path");
|
||||
const util = require("./util");
|
||||
const fs = require("fs");
|
||||
import defaults from "lodash/defaults";
|
||||
import outputFileSync from "output-file-sync";
|
||||
import slash from "slash";
|
||||
import path from "path";
|
||||
import fs from "fs";
|
||||
|
||||
module.exports = function (commander, filenames) {
|
||||
import * as util from "./util";
|
||||
|
||||
export default function (commander, filenames, opts) {
|
||||
function write(src, relative) {
|
||||
if (!util.isCompilableExtension(relative, commander.extensions)) return false;
|
||||
|
||||
// remove extension and then append back on .js
|
||||
relative = relative.replace(/\.(\w*?)$/, "") + ".js";
|
||||
|
||||
const dest = path.join(commander.outDir, relative);
|
||||
|
||||
const data = util.compile(src, {
|
||||
const data = util.compile(src, defaults({
|
||||
sourceFileName: slash(path.relative(dest + "/..", src)),
|
||||
sourceMapTarget: path.basename(relative)
|
||||
});
|
||||
if (!commander.copyFiles && data.ignored) return;
|
||||
sourceMapTarget: path.basename(relative),
|
||||
}, opts));
|
||||
|
||||
if (!data) return false;
|
||||
|
||||
// we've requested explicit sourcemaps to be written to disk
|
||||
if (data.map && commander.sourceMaps && commander.sourceMaps !== "inline") {
|
||||
@@ -28,14 +33,14 @@ module.exports = function (commander, filenames) {
|
||||
util.chmod(src, dest);
|
||||
|
||||
util.log(src + " -> " + dest);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
function handleFile(src, filename) {
|
||||
if (util.shouldIgnore(src)) return;
|
||||
const didWrite = write(src, filename);
|
||||
|
||||
if (util.canCompile(filename, commander.extensions)) {
|
||||
write(src, filename);
|
||||
} else if (commander.copyFiles) {
|
||||
if (!didWrite && commander.copyFiles) {
|
||||
const dest = path.join(commander.outDir, filename);
|
||||
outputFileSync(dest, fs.readFileSync(src));
|
||||
util.chmod(src, dest);
|
||||
@@ -73,7 +78,7 @@ module.exports = function (commander, filenames) {
|
||||
awaitWriteFinish: {
|
||||
stabilityThreshold: 50,
|
||||
pollInterval: 10,
|
||||
}
|
||||
},
|
||||
});
|
||||
|
||||
["add", "change"].forEach(function (type) {
|
||||
@@ -88,4 +93,4 @@ module.exports = function (commander, filenames) {
|
||||
});
|
||||
});
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@@ -1,11 +1,13 @@
|
||||
const convertSourceMap = require("convert-source-map");
|
||||
const sourceMap = require("source-map");
|
||||
const slash = require("slash");
|
||||
const path = require("path");
|
||||
const util = require("./util");
|
||||
const fs = require("fs");
|
||||
import convertSourceMap from "convert-source-map";
|
||||
import defaults from "lodash/defaults";
|
||||
import sourceMap from "source-map";
|
||||
import slash from "slash";
|
||||
import path from "path";
|
||||
import fs from "fs";
|
||||
|
||||
module.exports = function (commander, filenames, opts) {
|
||||
import * as util from "./util";
|
||||
|
||||
export default function (commander, filenames, opts) {
|
||||
if (commander.sourceMaps === "inline") {
|
||||
opts.sourceMaps = true;
|
||||
}
|
||||
@@ -15,7 +17,7 @@ module.exports = function (commander, filenames, opts) {
|
||||
const buildResult = function () {
|
||||
const map = new sourceMap.SourceMapGenerator({
|
||||
file: path.basename(commander.outFile || "") || "stdout",
|
||||
sourceRoot: opts.sourceRoot
|
||||
sourceRoot: opts.sourceRoot,
|
||||
});
|
||||
|
||||
let code = "";
|
||||
@@ -63,7 +65,7 @@ module.exports = function (commander, filenames, opts) {
|
||||
|
||||
return {
|
||||
map: map,
|
||||
code: code
|
||||
code: code,
|
||||
};
|
||||
};
|
||||
|
||||
@@ -95,9 +97,9 @@ module.exports = function (commander, filenames, opts) {
|
||||
});
|
||||
|
||||
process.stdin.on("end", function () {
|
||||
results.push(util.transform(commander.filename, code, {
|
||||
results.push(util.transform(commander.filename, code, defaults({
|
||||
sourceFileName: "stdin",
|
||||
}));
|
||||
}, opts)));
|
||||
output();
|
||||
});
|
||||
};
|
||||
@@ -122,19 +124,18 @@ module.exports = function (commander, filenames, opts) {
|
||||
});
|
||||
|
||||
_filenames.forEach(function (filename) {
|
||||
if (util.shouldIgnore(filename)) return;
|
||||
|
||||
let sourceFilename = filename;
|
||||
if (commander.outFile) {
|
||||
sourceFilename = path.relative(path.dirname(commander.outFile), sourceFilename);
|
||||
}
|
||||
sourceFilename = slash(sourceFilename);
|
||||
|
||||
const data = util.compile(filename, {
|
||||
const data = util.compile(filename, defaults({
|
||||
sourceFileName: sourceFilename,
|
||||
});
|
||||
}, opts));
|
||||
|
||||
if (!data) return;
|
||||
|
||||
if (data.ignored) return;
|
||||
results.push(data);
|
||||
});
|
||||
|
||||
@@ -155,9 +156,9 @@ module.exports = function (commander, filenames, opts) {
|
||||
awaitWriteFinish: {
|
||||
stabilityThreshold: 50,
|
||||
pollInterval: 10,
|
||||
}
|
||||
},
|
||||
}).on("all", function (type, filename) {
|
||||
if (util.shouldIgnore(filename) || !util.canCompile(filename, commander.extensions)) return;
|
||||
if (!util.isCompilableExtension(filename, commander.extensions)) return;
|
||||
|
||||
if (type === "add" || type === "change") {
|
||||
util.log(type + " " + filename);
|
||||
@@ -176,4 +177,4 @@ module.exports = function (commander, filenames, opts) {
|
||||
} else {
|
||||
stdin();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@@ -1,42 +1,73 @@
|
||||
#!/usr/bin/env node
|
||||
|
||||
const fs = require("fs");
|
||||
const commander = require("commander");
|
||||
const kebabCase = require("lodash/kebabCase");
|
||||
const options = require("babel-core").options;
|
||||
const util = require("babel-core").util;
|
||||
const uniq = require("lodash/uniq");
|
||||
const glob = require("glob");
|
||||
import fs from "fs";
|
||||
import commander from "commander";
|
||||
import { version } from "babel-core";
|
||||
import uniq from "lodash/uniq";
|
||||
import glob from "glob";
|
||||
|
||||
Object.keys(options).forEach(function (key) {
|
||||
const option = options[key];
|
||||
if (option.hidden) return;
|
||||
import dirCommand from "./dir";
|
||||
import fileCommand from "./file";
|
||||
|
||||
let arg = kebabCase(key);
|
||||
import pkg from "../../package.json";
|
||||
|
||||
if (option.type !== "boolean") {
|
||||
arg += " [" + (option.type || "string") + "]";
|
||||
function booleanify(val: any): boolean | any {
|
||||
if (val === "true" || val == 1) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (option.type === "boolean" && option.default === true) {
|
||||
arg = "no-" + arg;
|
||||
if (val === "false" || val == 0 || !val) {
|
||||
return false;
|
||||
}
|
||||
|
||||
arg = "--" + arg;
|
||||
return val;
|
||||
}
|
||||
|
||||
if (option.shorthand) {
|
||||
arg = "-" + option.shorthand + ", " + arg;
|
||||
}
|
||||
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 desc = [];
|
||||
if (option.deprecated) desc.push("[DEPRECATED] " + option.deprecated);
|
||||
if (option.description) desc.push(option.description);
|
||||
const values = value.split(",");
|
||||
|
||||
commander.option(arg, desc.join(" "));
|
||||
});
|
||||
return previousValue ? previousValue.concat(values) : values;
|
||||
}
|
||||
|
||||
/* eslint-disable max-len */
|
||||
commander.option("-x, --extensions [extensions]", "List of extensions to compile when a directory has been input [.es6,.js,.es,.jsx]");
|
||||
// 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);
|
||||
|
||||
// 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]", collect);
|
||||
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");
|
||||
@@ -45,19 +76,12 @@ commander.option("-D, --copy-files", "When compiling a directory copy over non-c
|
||||
commander.option("-q, --quiet", "Don't log anything");
|
||||
/* eslint-enable max-len */
|
||||
|
||||
const pkg = require("../../package.json");
|
||||
commander.version(pkg.version + " (babel-core " + require("babel-core").version + ")");
|
||||
commander.version(pkg.version + " (babel-core " + version + ")");
|
||||
commander.usage("[options] <files ...>");
|
||||
commander.parse(process.argv);
|
||||
|
||||
//
|
||||
|
||||
if (commander.extensions) {
|
||||
commander.extensions = util.arrayify(commander.extensions);
|
||||
}
|
||||
|
||||
//
|
||||
|
||||
const errors = [];
|
||||
|
||||
let filenames = commander.args.reduce(function (globbed, input) {
|
||||
@@ -103,27 +127,23 @@ if (errors.length) {
|
||||
|
||||
//
|
||||
|
||||
const opts = exports.opts = {};
|
||||
const opts = commander.opts();
|
||||
|
||||
Object.keys(options).forEach(function (key) {
|
||||
const opt = options[key];
|
||||
if (commander[key] !== undefined && commander[key] !== opt.default) {
|
||||
opts[key] = commander[key];
|
||||
}
|
||||
});
|
||||
// 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.quiet;
|
||||
|
||||
opts.ignore = util.arrayify(opts.ignore, util.regexify);
|
||||
// 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;
|
||||
|
||||
if (opts.only) {
|
||||
opts.only = util.arrayify(opts.only, util.regexify);
|
||||
}
|
||||
|
||||
let fn;
|
||||
|
||||
if (commander.outDir) {
|
||||
fn = require("./dir");
|
||||
} else {
|
||||
fn = require("./file");
|
||||
}
|
||||
|
||||
fn(commander, filenames, exports.opts);
|
||||
const fn = commander.outDir ? dirCommand : fileCommand;
|
||||
fn(commander, filenames, opts);
|
||||
|
||||
@@ -1,11 +1,9 @@
|
||||
const commander = require("commander");
|
||||
const defaults = require("lodash/defaults");
|
||||
const readdir = require("fs-readdir-recursive");
|
||||
const index = require("./index");
|
||||
const babel = require("babel-core");
|
||||
const util = require("babel-core").util;
|
||||
const path = require("path");
|
||||
const fs = require("fs");
|
||||
import commander from "commander";
|
||||
import readdir from "fs-readdir-recursive";
|
||||
import * as babel from "babel-core";
|
||||
import includes from "lodash/includes";
|
||||
import path from "path";
|
||||
import fs from "fs";
|
||||
|
||||
export function chmod(src, dest) {
|
||||
fs.chmodSync(dest, fs.statSync(src).mode);
|
||||
@@ -13,16 +11,19 @@ export function chmod(src, dest) {
|
||||
|
||||
export function readdirFilter(filename) {
|
||||
return readdir(filename).filter(function (filename) {
|
||||
return util.canCompile(filename);
|
||||
return babel.util.isCompilableExtension(filename);
|
||||
});
|
||||
}
|
||||
|
||||
export { readdir };
|
||||
|
||||
export const canCompile = util.canCompile;
|
||||
|
||||
export function shouldIgnore(loc) {
|
||||
return util.shouldIgnore(loc, index.opts.ignore, index.opts.only);
|
||||
/**
|
||||
* Test if a filename ends with a compilable extension.
|
||||
*/
|
||||
export function isCompilableExtension(filename: string, altExts?: Array<string>): boolean {
|
||||
const exts = altExts || babel.DEFAULT_EXTENSIONS;
|
||||
const ext = path.extname(filename);
|
||||
return includes(exts, ext);
|
||||
}
|
||||
|
||||
export function addSourceMappingUrl(code, loc) {
|
||||
@@ -34,19 +35,16 @@ export function log(msg) {
|
||||
}
|
||||
|
||||
export function transform(filename, code, opts) {
|
||||
opts = defaults(opts || {}, index.opts);
|
||||
opts.filename = filename;
|
||||
opts = Object.assign({}, opts, {
|
||||
filename,
|
||||
});
|
||||
|
||||
const result = babel.transform(code, opts);
|
||||
result.filename = filename;
|
||||
result.actual = code;
|
||||
return result;
|
||||
return babel.transform(code, opts);
|
||||
}
|
||||
|
||||
export function compile(filename, opts) {
|
||||
try {
|
||||
const code = fs.readFileSync(filename, "utf8");
|
||||
return transform(filename, code, opts);
|
||||
return babel.transformFileSync(filename, opts);
|
||||
} catch (err) {
|
||||
if (commander.watch) {
|
||||
console.error(toErrorStack(err));
|
||||
|
||||
0
packages/babel-cli/test/fixtures/babel/--copy-files with ignore/in-files/src/README.md
vendored
Normal file
0
packages/babel-cli/test/fixtures/babel/--copy-files with ignore/in-files/src/README.md
vendored
Normal file
1
packages/babel-cli/test/fixtures/babel/--copy-files with ignore/in-files/src/foo/bar.js
vendored
Normal file
1
packages/babel-cli/test/fixtures/babel/--copy-files with ignore/in-files/src/foo/bar.js
vendored
Normal file
@@ -0,0 +1 @@
|
||||
bar;
|
||||
1
packages/babel-cli/test/fixtures/babel/--copy-files with ignore/in-files/src/index.js
vendored
Normal file
1
packages/babel-cli/test/fixtures/babel/--copy-files with ignore/in-files/src/index.js
vendored
Normal file
@@ -0,0 +1 @@
|
||||
index;
|
||||
8
packages/babel-cli/test/fixtures/babel/--copy-files with ignore/options.json
vendored
Normal file
8
packages/babel-cli/test/fixtures/babel/--copy-files with ignore/options.json
vendored
Normal file
@@ -0,0 +1,8 @@
|
||||
{
|
||||
"args": [
|
||||
"src",
|
||||
"--out-dir", "lib",
|
||||
"--copy-files",
|
||||
"--ignore", "src/foo/*"
|
||||
]
|
||||
}
|
||||
0
packages/babel-cli/test/fixtures/babel/--copy-files with ignore/out-files/lib/README.md
vendored
Normal file
0
packages/babel-cli/test/fixtures/babel/--copy-files with ignore/out-files/lib/README.md
vendored
Normal file
1
packages/babel-cli/test/fixtures/babel/--copy-files with ignore/out-files/lib/foo/bar.js
vendored
Normal file
1
packages/babel-cli/test/fixtures/babel/--copy-files with ignore/out-files/lib/foo/bar.js
vendored
Normal file
@@ -0,0 +1 @@
|
||||
bar;
|
||||
3
packages/babel-cli/test/fixtures/babel/--copy-files with ignore/out-files/lib/index.js
vendored
Normal file
3
packages/babel-cli/test/fixtures/babel/--copy-files with ignore/out-files/lib/index.js
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
"use strict";
|
||||
|
||||
index;
|
||||
1
packages/babel-cli/test/fixtures/babel/--copy-files with ignore/stdout.txt
vendored
Normal file
1
packages/babel-cli/test/fixtures/babel/--copy-files with ignore/stdout.txt
vendored
Normal file
@@ -0,0 +1 @@
|
||||
src/index.js -> lib/index.js
|
||||
0
packages/babel-cli/test/fixtures/babel/--copy-files with only/in-files/src/README.md
vendored
Normal file
0
packages/babel-cli/test/fixtures/babel/--copy-files with only/in-files/src/README.md
vendored
Normal file
1
packages/babel-cli/test/fixtures/babel/--copy-files with only/in-files/src/foo/bar.js
vendored
Normal file
1
packages/babel-cli/test/fixtures/babel/--copy-files with only/in-files/src/foo/bar.js
vendored
Normal file
@@ -0,0 +1 @@
|
||||
bar;
|
||||
1
packages/babel-cli/test/fixtures/babel/--copy-files with only/in-files/src/index.js
vendored
Normal file
1
packages/babel-cli/test/fixtures/babel/--copy-files with only/in-files/src/index.js
vendored
Normal file
@@ -0,0 +1 @@
|
||||
index;
|
||||
8
packages/babel-cli/test/fixtures/babel/--copy-files with only/options.json
vendored
Normal file
8
packages/babel-cli/test/fixtures/babel/--copy-files with only/options.json
vendored
Normal file
@@ -0,0 +1,8 @@
|
||||
{
|
||||
"args": [
|
||||
"src",
|
||||
"--out-dir", "lib",
|
||||
"--copy-files",
|
||||
"--only", "src/foo/*"
|
||||
]
|
||||
}
|
||||
0
packages/babel-cli/test/fixtures/babel/--copy-files with only/out-files/lib/README.md
vendored
Normal file
0
packages/babel-cli/test/fixtures/babel/--copy-files with only/out-files/lib/README.md
vendored
Normal file
3
packages/babel-cli/test/fixtures/babel/--copy-files with only/out-files/lib/foo/bar.js
vendored
Normal file
3
packages/babel-cli/test/fixtures/babel/--copy-files with only/out-files/lib/foo/bar.js
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
"use strict";
|
||||
|
||||
bar;
|
||||
1
packages/babel-cli/test/fixtures/babel/--copy-files with only/out-files/lib/index.js
vendored
Normal file
1
packages/babel-cli/test/fixtures/babel/--copy-files with only/out-files/lib/index.js
vendored
Normal file
@@ -0,0 +1 @@
|
||||
index;
|
||||
1
packages/babel-cli/test/fixtures/babel/--copy-files with only/stdout.txt
vendored
Normal file
1
packages/babel-cli/test/fixtures/babel/--copy-files with only/stdout.txt
vendored
Normal file
@@ -0,0 +1 @@
|
||||
src/foo/bar.js -> lib/foo/bar.js
|
||||
0
packages/babel-cli/test/fixtures/babel/--copy-files/in-files/src/.foorc
vendored
Normal file
0
packages/babel-cli/test/fixtures/babel/--copy-files/in-files/src/.foorc
vendored
Normal file
0
packages/babel-cli/test/fixtures/babel/--copy-files/in-files/src/README.md
vendored
Normal file
0
packages/babel-cli/test/fixtures/babel/--copy-files/in-files/src/README.md
vendored
Normal file
1
packages/babel-cli/test/fixtures/babel/--copy-files/in-files/src/bar/index.js
vendored
Normal file
1
packages/babel-cli/test/fixtures/babel/--copy-files/in-files/src/bar/index.js
vendored
Normal file
@@ -0,0 +1 @@
|
||||
bar;
|
||||
0
packages/babel-cli/test/fixtures/babel/--copy-files/in-files/src/foo/foo.js
vendored
Normal file
0
packages/babel-cli/test/fixtures/babel/--copy-files/in-files/src/foo/foo.js
vendored
Normal file
3
packages/babel-cli/test/fixtures/babel/--copy-files/options.json
vendored
Normal file
3
packages/babel-cli/test/fixtures/babel/--copy-files/options.json
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"args": ["src", "--out-dir", "lib", "--copy-files"]
|
||||
}
|
||||
0
packages/babel-cli/test/fixtures/babel/--copy-files/out-files/lib/README.md
vendored
Normal file
0
packages/babel-cli/test/fixtures/babel/--copy-files/out-files/lib/README.md
vendored
Normal file
3
packages/babel-cli/test/fixtures/babel/--copy-files/out-files/lib/bar/index.js
vendored
Normal file
3
packages/babel-cli/test/fixtures/babel/--copy-files/out-files/lib/bar/index.js
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
"use strict";
|
||||
|
||||
bar;
|
||||
1
packages/babel-cli/test/fixtures/babel/--copy-files/out-files/lib/foo/foo.js
vendored
Normal file
1
packages/babel-cli/test/fixtures/babel/--copy-files/out-files/lib/foo/foo.js
vendored
Normal file
@@ -0,0 +1 @@
|
||||
"use strict";
|
||||
2
packages/babel-cli/test/fixtures/babel/--copy-files/stdout.txt
vendored
Normal file
2
packages/babel-cli/test/fixtures/babel/--copy-files/stdout.txt
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
src/bar/index.js -> lib/bar/index.js
|
||||
src/foo/foo.js -> lib/foo/foo.js
|
||||
@@ -1,3 +1,3 @@
|
||||
{
|
||||
"args": ["src", "--out-dir", "lib", "--ignore", "/bar/*"]
|
||||
"args": ["src", "--out-dir", "lib", "--ignore", "src/bar"]
|
||||
}
|
||||
|
||||
1
packages/babel-cli/test/fixtures/babel/--ignore glob/in-files/src/a.foo.js
vendored
Normal file
1
packages/babel-cli/test/fixtures/babel/--ignore glob/in-files/src/a.foo.js
vendored
Normal file
@@ -0,0 +1 @@
|
||||
a.foo;
|
||||
1
packages/babel-cli/test/fixtures/babel/--ignore glob/in-files/src/a.js
vendored
Normal file
1
packages/babel-cli/test/fixtures/babel/--ignore glob/in-files/src/a.js
vendored
Normal file
@@ -0,0 +1 @@
|
||||
a;
|
||||
1
packages/babel-cli/test/fixtures/babel/--ignore glob/in-files/src/b.js
vendored
Normal file
1
packages/babel-cli/test/fixtures/babel/--ignore glob/in-files/src/b.js
vendored
Normal file
@@ -0,0 +1 @@
|
||||
b;
|
||||
1
packages/babel-cli/test/fixtures/babel/--ignore glob/in-files/src/baz/b.foo.js
vendored
Normal file
1
packages/babel-cli/test/fixtures/babel/--ignore glob/in-files/src/baz/b.foo.js
vendored
Normal file
@@ -0,0 +1 @@
|
||||
b.foo;
|
||||
1
packages/babel-cli/test/fixtures/babel/--ignore glob/in-files/src/baz/c.js
vendored
Normal file
1
packages/babel-cli/test/fixtures/babel/--ignore glob/in-files/src/baz/c.js
vendored
Normal file
@@ -0,0 +1 @@
|
||||
c;
|
||||
1
packages/babel-cli/test/fixtures/babel/--ignore glob/in-files/src/foo.js
vendored
Normal file
1
packages/babel-cli/test/fixtures/babel/--ignore glob/in-files/src/foo.js
vendored
Normal file
@@ -0,0 +1 @@
|
||||
foo;
|
||||
3
packages/babel-cli/test/fixtures/babel/--ignore glob/options.json
vendored
Normal file
3
packages/babel-cli/test/fixtures/babel/--ignore glob/options.json
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"args": ["src", "--out-dir", "lib", "--ignore", "**/*.foo.js"]
|
||||
}
|
||||
3
packages/babel-cli/test/fixtures/babel/--ignore glob/out-files/lib/a.js
vendored
Normal file
3
packages/babel-cli/test/fixtures/babel/--ignore glob/out-files/lib/a.js
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
"use strict";
|
||||
|
||||
a;
|
||||
3
packages/babel-cli/test/fixtures/babel/--ignore glob/out-files/lib/b.js
vendored
Normal file
3
packages/babel-cli/test/fixtures/babel/--ignore glob/out-files/lib/b.js
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
"use strict";
|
||||
|
||||
b;
|
||||
3
packages/babel-cli/test/fixtures/babel/--ignore glob/out-files/lib/baz/c.js
vendored
Normal file
3
packages/babel-cli/test/fixtures/babel/--ignore glob/out-files/lib/baz/c.js
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
"use strict";
|
||||
|
||||
c;
|
||||
3
packages/babel-cli/test/fixtures/babel/--ignore glob/out-files/lib/foo.js
vendored
Normal file
3
packages/babel-cli/test/fixtures/babel/--ignore glob/out-files/lib/foo.js
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
"use strict";
|
||||
|
||||
foo;
|
||||
4
packages/babel-cli/test/fixtures/babel/--ignore glob/stdout.txt
vendored
Normal file
4
packages/babel-cli/test/fixtures/babel/--ignore glob/stdout.txt
vendored
Normal file
@@ -0,0 +1,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
|
||||
1
packages/babel-cli/test/fixtures/babel/--only glob/in-files/src/a.foo.js
vendored
Normal file
1
packages/babel-cli/test/fixtures/babel/--only glob/in-files/src/a.foo.js
vendored
Normal file
@@ -0,0 +1 @@
|
||||
a.foo;
|
||||
1
packages/babel-cli/test/fixtures/babel/--only glob/in-files/src/a.js
vendored
Normal file
1
packages/babel-cli/test/fixtures/babel/--only glob/in-files/src/a.js
vendored
Normal file
@@ -0,0 +1 @@
|
||||
a;
|
||||
1
packages/babel-cli/test/fixtures/babel/--only glob/in-files/src/b.js
vendored
Normal file
1
packages/babel-cli/test/fixtures/babel/--only glob/in-files/src/b.js
vendored
Normal file
@@ -0,0 +1 @@
|
||||
b;
|
||||
1
packages/babel-cli/test/fixtures/babel/--only glob/in-files/src/baz/b.foo.js
vendored
Normal file
1
packages/babel-cli/test/fixtures/babel/--only glob/in-files/src/baz/b.foo.js
vendored
Normal file
@@ -0,0 +1 @@
|
||||
b.foo;
|
||||
1
packages/babel-cli/test/fixtures/babel/--only glob/in-files/src/baz/c.js
vendored
Normal file
1
packages/babel-cli/test/fixtures/babel/--only glob/in-files/src/baz/c.js
vendored
Normal file
@@ -0,0 +1 @@
|
||||
c;
|
||||
1
packages/babel-cli/test/fixtures/babel/--only glob/in-files/src/foo.js
vendored
Normal file
1
packages/babel-cli/test/fixtures/babel/--only glob/in-files/src/foo.js
vendored
Normal file
@@ -0,0 +1 @@
|
||||
foo;
|
||||
3
packages/babel-cli/test/fixtures/babel/--only glob/options.json
vendored
Normal file
3
packages/babel-cli/test/fixtures/babel/--only glob/options.json
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"args": ["src", "--out-dir", "lib", "--only", "**/*.foo.js"]
|
||||
}
|
||||
3
packages/babel-cli/test/fixtures/babel/--only glob/out-files/lib/a.foo.js
vendored
Normal file
3
packages/babel-cli/test/fixtures/babel/--only glob/out-files/lib/a.foo.js
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
"use strict";
|
||||
|
||||
a.foo;
|
||||
3
packages/babel-cli/test/fixtures/babel/--only glob/out-files/lib/baz/b.foo.js
vendored
Normal file
3
packages/babel-cli/test/fixtures/babel/--only glob/out-files/lib/baz/b.foo.js
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
"use strict";
|
||||
|
||||
b.foo;
|
||||
2
packages/babel-cli/test/fixtures/babel/--only glob/stdout.txt
vendored
Normal file
2
packages/babel-cli/test/fixtures/babel/--only glob/stdout.txt
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
src/a.foo.js -> lib/a.foo.js
|
||||
src/baz/b.foo.js -> lib/baz/b.foo.js
|
||||
@@ -5,4 +5,4 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Cons
|
||||
var Test = function Test() {
|
||||
_classCallCheck(this, Test);
|
||||
};
|
||||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy9iYXIvYmFyLmpzIl0sIm5hbWVzIjpbIlRlc3QiXSwibWFwcGluZ3MiOiI7Ozs7SUFBTUEsSSIsImZpbGUiOiJiYXIuanMiLCJzb3VyY2VzQ29udGVudCI6WyJjbGFzcyBUZXN0IHtcblxufSJdfQ==
|
||||
//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy9iYXIvYmFyLmpzIl0sIm5hbWVzIjpbIlRlc3QiXSwibWFwcGluZ3MiOiI7Ozs7SUFBTUEsSSIsImZpbGUiOiJiYXIuanMiLCJzb3VyY2VzQ29udGVudCI6WyJjbGFzcyBUZXN0IHtcblxufSJdfQ==
|
||||
|
||||
@@ -3,4 +3,4 @@
|
||||
arr.map(function (x) {
|
||||
return x * MULTIPLIER;
|
||||
});
|
||||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIi4uL3NyYy9mb28uanMiXSwibmFtZXMiOlsiYXJyIiwibWFwIiwieCIsIk1VTFRJUExJRVIiXSwibWFwcGluZ3MiOiI7O0FBQUFBLElBQUlDLEdBQUosQ0FBUTtBQUFBLFNBQUtDLElBQUlDLFVBQVQ7QUFBQSxDQUFSIiwiZmlsZSI6ImZvby5qcyIsInNvdXJjZXNDb250ZW50IjpbImFyci5tYXAoeCA9PiB4ICogTVVMVElQTElFUik7Il19
|
||||
//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIi4uL3NyYy9mb28uanMiXSwibmFtZXMiOlsiYXJyIiwibWFwIiwieCIsIk1VTFRJUExJRVIiXSwibWFwcGluZ3MiOiI7O0FBQUFBLElBQUlDLEdBQUosQ0FBUTtBQUFBLFNBQUtDLElBQUlDLFVBQVQ7QUFBQSxDQUFSIiwiZmlsZSI6ImZvby5qcyIsInNvdXJjZXNDb250ZW50IjpbImFyci5tYXAoeCA9PiB4ICogTVVMVElQTElFUik7Il19
|
||||
|
||||
@@ -4,4 +4,4 @@ arr.map(function (x) {
|
||||
return x * MULTIPLIER;
|
||||
});
|
||||
|
||||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbInNjcmlwdC5qcyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOztBQUFBLElBQUksR0FBSixDQUFRO0FBQUEsU0FBSyxJQUFJLFVBQVQ7QUFBQSxDQUFSIiwiZmlsZSI6InNjcmlwdDIuanMiLCJzb3VyY2VzQ29udGVudCI6WyJhcnIubWFwKHggPT4geCAqIE1VTFRJUExJRVIpOyJdfQ==
|
||||
//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbInNjcmlwdC5qcyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOztBQUFBLElBQUksR0FBSixDQUFRO0FBQUEsU0FBSyxJQUFJLFVBQVQ7QUFBQSxDQUFSIiwiZmlsZSI6InNjcmlwdDIuanMiLCJzb3VyY2VzQ29udGVudCI6WyJhcnIubWFwKHggPT4geCAqIE1VTFRJUExJRVIpOyJdfQ==
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
{
|
||||
"inlineSourceMap": true
|
||||
"sourceMap": "inline"
|
||||
}
|
||||
|
||||
@@ -4,4 +4,4 @@ var foo = function foo() {
|
||||
return 4;
|
||||
};
|
||||
|
||||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIm9yaWdpbmFsLmpzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7O0FBQUEsVUFBVSxlO1MsQUFBTTtBQUFDIiwiZmlsZSI6InNjcmlwdDIuanMiLCJzb3VyY2VzQ29udGVudCI6WyJ2YXIgZm9vID0gKCkgPT4gNDsiXX0=
|
||||
//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIm9yaWdpbmFsLmpzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7O0FBQUEsVUFBVSxlO1MsQUFBTTtBQUFDIiwiZmlsZSI6InNjcmlwdDIuanMiLCJzb3VyY2VzQ29udGVudCI6WyJ2YXIgZm9vID0gKCkgPT4gNDsiXX0=
|
||||
|
||||
@@ -11,4 +11,4 @@ arr.map(function (x) {
|
||||
return x * MULTIPLIER;
|
||||
});
|
||||
|
||||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbInNjcmlwdC5qcyIsInNjcmlwdDIuanMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6Ijs7OztJQUFNLEk7Ozs7O0FDQU4sSUFBSSxHQUFKLENBQVE7QUFBQSxTQUFLLElBQUksVUFBVDtBQUFBLENBQVIiLCJmaWxlIjoic2NyaXB0My5qcyIsInNvdXJjZXNDb250ZW50IjpbImNsYXNzIFRlc3Qge1xuXG59IiwiYXJyLm1hcCh4ID0+IHggKiBNVUxUSVBMSUVSKTsiXX0=
|
||||
//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbInNjcmlwdC5qcyIsInNjcmlwdDIuanMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6Ijs7OztJQUFNLEk7Ozs7O0FDQU4sSUFBSSxHQUFKLENBQVE7QUFBQSxTQUFLLElBQUksVUFBVDtBQUFBLENBQVIiLCJmaWxlIjoic2NyaXB0My5qcyIsInNvdXJjZXNDb250ZW50IjpbImNsYXNzIFRlc3Qge1xuXG59IiwiYXJyLm1hcCh4ID0+IHggKiBNVUxUSVBMSUVSKTsiXX0=
|
||||
|
||||
@@ -1,21 +1,25 @@
|
||||
const includes = require("lodash/includes");
|
||||
const readdir = require("fs-readdir-recursive");
|
||||
const helper = require("babel-helper-fixtures");
|
||||
const assert = require("assert");
|
||||
const rimraf = require("rimraf");
|
||||
const includes = require("lodash/includes");
|
||||
const readdir = require("fs-readdir-recursive");
|
||||
const helper = require("babel-helper-fixtures");
|
||||
const assert = require("assert");
|
||||
const rimraf = require("rimraf");
|
||||
const outputFileSync = require("output-file-sync");
|
||||
const child = require("child_process");
|
||||
const merge = require("lodash/merge");
|
||||
const path = require("path");
|
||||
const chai = require("chai");
|
||||
const fs = require("fs");
|
||||
const child = require("child_process");
|
||||
const merge = require("lodash/merge");
|
||||
const path = require("path");
|
||||
const chai = require("chai");
|
||||
const fs = require("fs");
|
||||
|
||||
const fixtureLoc = path.join(__dirname, "fixtures");
|
||||
const tmpLoc = path.join(__dirname, "tmp");
|
||||
|
||||
const fileFilter = function(x) {
|
||||
return x !== ".DS_Store";
|
||||
};
|
||||
|
||||
const presetLocs = [
|
||||
path.join(__dirname, "../../babel-preset-es2015"),
|
||||
path.join(__dirname, "../../babel-preset-react")
|
||||
path.join(__dirname, "../../babel-preset-react"),
|
||||
].join(",");
|
||||
|
||||
const pluginLocs = [
|
||||
@@ -23,10 +27,10 @@ const pluginLocs = [
|
||||
path.join(__dirname, "/../../babel-plugin-transform-es2015-modules-commonjs"),
|
||||
].join(",");
|
||||
|
||||
const readDir = function (loc) {
|
||||
const readDir = function (loc, filter) {
|
||||
const files = {};
|
||||
if (fs.existsSync(loc)) {
|
||||
readdir(loc).forEach(function (filename) {
|
||||
readdir(loc, filter).forEach(function (filename) {
|
||||
files[filename] = helper.readFile(path.join(loc, filename));
|
||||
});
|
||||
}
|
||||
@@ -34,6 +38,9 @@ const readDir = function (loc) {
|
||||
};
|
||||
|
||||
const saveInFiles = function (files) {
|
||||
// Place an empty .babelrc in each test so tests won't unexpectedly get to repo-level config.
|
||||
outputFileSync(".babelrc", "{}");
|
||||
|
||||
Object.keys(files).forEach(function (filename) {
|
||||
const content = files[filename];
|
||||
outputFileSync(filename, content);
|
||||
@@ -70,11 +77,27 @@ const assertTest = function (stdout, stderr, opts) {
|
||||
throw new Error("stdout:\n" + stdout);
|
||||
}
|
||||
|
||||
Object.keys(opts.outFiles, function (filename) {
|
||||
const expect = opts.outFiles[filename];
|
||||
const actual = helper.readFile(filename);
|
||||
chai.expect(actual).to.equal(expect, "out-file " + filename);
|
||||
});
|
||||
if (opts.outFiles) {
|
||||
const actualFiles = readDir(path.join(tmpLoc));
|
||||
|
||||
Object.keys(actualFiles).forEach(function (filename) {
|
||||
if (!opts.inFiles.hasOwnProperty(filename)) {
|
||||
const expect = opts.outFiles[filename];
|
||||
const actual = actualFiles[filename];
|
||||
|
||||
chai.expect(expect, "Output is missing: " + filename).to.not.be.undefined;
|
||||
|
||||
if (expect) {
|
||||
chai.expect(actual).to.equal(expect, "Compiled output does not match: " + filename);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
Object.keys(opts.outFiles).forEach(function(filename) {
|
||||
chai.expect(actualFiles, "Extraneous file in output: " + filename)
|
||||
.to.contain.key(filename);
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
const buildTest = function (binName, testName, opts) {
|
||||
@@ -91,7 +114,7 @@ const buildTest = function (binName, testName, opts) {
|
||||
}
|
||||
|
||||
if (binName === "babel-node") {
|
||||
args.push("--only", "packages/*/test");
|
||||
args.push("--only", "../../../../packages/*/test");
|
||||
}
|
||||
|
||||
args = args.concat(opts.args);
|
||||
@@ -119,7 +142,7 @@ const buildTest = function (binName, testName, opts) {
|
||||
}
|
||||
|
||||
if (err) {
|
||||
err.message = args.join(" ") + ": " + err.message;
|
||||
err.message = args.map((arg) => `"${ arg }"`).join(" ") + ": " + err.message;
|
||||
}
|
||||
|
||||
callback(err);
|
||||
@@ -150,7 +173,7 @@ fs.readdirSync(fixtureLoc).forEach(function (binName) {
|
||||
const testLoc = path.join(suiteLoc, testName);
|
||||
|
||||
const opts = {
|
||||
args: []
|
||||
args: [],
|
||||
};
|
||||
|
||||
const optionsLoc = path.join(testLoc, "options.json");
|
||||
@@ -165,8 +188,8 @@ fs.readdirSync(fixtureLoc).forEach(function (binName) {
|
||||
}
|
||||
});
|
||||
|
||||
opts.outFiles = readDir(path.join(testLoc, "out-files"));
|
||||
opts.inFiles = readDir(path.join(testLoc, "in-files"));
|
||||
opts.outFiles = readDir(path.join(testLoc, "out-files"), fileFilter);
|
||||
opts.inFiles = readDir(path.join(testLoc, "in-files"), fileFilter);
|
||||
|
||||
const babelrcLoc = path.join(testLoc, ".babelrc");
|
||||
if (fs.existsSync(babelrcLoc)) {
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
src
|
||||
test
|
||||
node_modules
|
||||
*.log
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "babel-code-frame",
|
||||
"version": "6.22.0",
|
||||
"version": "7.0.0-alpha.3",
|
||||
"description": "Generate errors that contain a code frame that point to source locations.",
|
||||
"author": "Sebastian McKenzie <sebmck@gmail.com>",
|
||||
"homepage": "https://babeljs.io/",
|
||||
|
||||
@@ -8,18 +8,18 @@ import Chalk from "chalk";
|
||||
|
||||
function getDefs(chalk) {
|
||||
return {
|
||||
keyword: chalk.cyan,
|
||||
keyword: chalk.cyan,
|
||||
capitalized: chalk.yellow,
|
||||
jsx_tag: chalk.yellow,
|
||||
punctuator: chalk.yellow,
|
||||
jsx_tag: chalk.yellow,
|
||||
punctuator: chalk.yellow,
|
||||
// bracket: intentionally omitted.
|
||||
number: chalk.magenta,
|
||||
string: chalk.green,
|
||||
regex: chalk.magenta,
|
||||
comment: chalk.grey,
|
||||
invalid: chalk.white.bgRed.bold,
|
||||
gutter: chalk.grey,
|
||||
marker: chalk.red.bold,
|
||||
number: chalk.magenta,
|
||||
string: chalk.green,
|
||||
regex: chalk.magenta,
|
||||
comment: chalk.grey,
|
||||
invalid: chalk.white.bgRed.bold,
|
||||
gutter: chalk.grey,
|
||||
marker: chalk.red.bold,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -117,7 +117,7 @@ export default function (
|
||||
|
||||
const lines = rawLines.split(NEWLINE);
|
||||
let start = Math.max(lineNumber - (linesAbove + 1), 0);
|
||||
let end = Math.min(lines.length, lineNumber + linesBelow);
|
||||
let end = Math.min(lines.length, lineNumber + linesBelow);
|
||||
|
||||
if (!lineNumber && !colNumber) {
|
||||
start = 0;
|
||||
@@ -138,14 +138,14 @@ export default function (
|
||||
"\n ",
|
||||
maybeHighlight(defs.gutter, gutter.replace(/\d/g, " ")),
|
||||
markerSpacing,
|
||||
maybeHighlight(defs.marker, "^")
|
||||
maybeHighlight(defs.marker, "^"),
|
||||
].join("");
|
||||
}
|
||||
return [
|
||||
maybeHighlight(defs.marker, ">"),
|
||||
maybeHighlight(defs.gutter, gutter),
|
||||
line,
|
||||
markerLine
|
||||
markerLine,
|
||||
].join("");
|
||||
} else {
|
||||
return ` ${maybeHighlight(defs.gutter, gutter)}${line}`;
|
||||
|
||||
@@ -55,7 +55,7 @@ describe("babel-code-frame", function () {
|
||||
"",
|
||||
"function sum(a, b) {",
|
||||
" return a + b",
|
||||
"}"
|
||||
"}",
|
||||
].join("\n");
|
||||
assert.equal(codeFrame(rawLines, 7, 2), [
|
||||
" 5 | * @param b Number",
|
||||
@@ -80,7 +80,7 @@ describe("babel-code-frame", function () {
|
||||
"",
|
||||
"function sum(a, b) {",
|
||||
" return a + b",
|
||||
"}"
|
||||
"}",
|
||||
].join("\n");
|
||||
assert.equal(codeFrame(rawLines, 6, 2), [
|
||||
" 4 | * @param a Number",
|
||||
@@ -130,7 +130,7 @@ describe("babel-code-frame", function () {
|
||||
"",
|
||||
"function sum(a, b) {",
|
||||
" return a + b",
|
||||
"}"
|
||||
"}",
|
||||
].join("\n");
|
||||
assert.equal(codeFrame(rawLines, 7, 2, { linesAbove: 1 }), [
|
||||
" 6 | * @returns Number",
|
||||
@@ -154,14 +154,14 @@ describe("babel-code-frame", function () {
|
||||
"",
|
||||
"function sum(a, b) {",
|
||||
" return a + b",
|
||||
"}"
|
||||
"}",
|
||||
].join("\n");
|
||||
assert.equal(codeFrame(rawLines, 7, 2, { linesBelow: 1 }), [
|
||||
" 5 | * @param b Number",
|
||||
" 6 | * @returns Number",
|
||||
"> 7 | */",
|
||||
" | ^",
|
||||
" 8 | "
|
||||
" 8 | ",
|
||||
].join("\n"));
|
||||
});
|
||||
|
||||
@@ -177,13 +177,13 @@ describe("babel-code-frame", function () {
|
||||
"",
|
||||
"function sum(a, b) {",
|
||||
" return a + b",
|
||||
"}"
|
||||
"}",
|
||||
].join("\n");
|
||||
assert.equal(codeFrame(rawLines, 7, 2, { linesAbove: 1, linesBelow: 1 }), [
|
||||
" 6 | * @returns Number",
|
||||
"> 7 | */",
|
||||
" | ^",
|
||||
" 8 | "
|
||||
" 8 | ",
|
||||
].join("\n"));
|
||||
});
|
||||
|
||||
@@ -195,13 +195,13 @@ describe("babel-code-frame", function () {
|
||||
"",
|
||||
"",
|
||||
"",
|
||||
""
|
||||
"",
|
||||
].join("\n");
|
||||
assert.equal(codeFrame(rawLines, 3, null, { linesAbove: 1, linesBelow: 1, forceColor: true }),
|
||||
chalk.reset([
|
||||
" " + gutter(" 2 | "),
|
||||
marker(">") + gutter(" 3 | "),
|
||||
" " + gutter(" 4 | ")
|
||||
" " + gutter(" 4 | "),
|
||||
].join("\n"))
|
||||
);
|
||||
});
|
||||
|
||||
@@ -1,13 +1,3 @@
|
||||
src
|
||||
test
|
||||
*.log
|
||||
*.cache
|
||||
.*
|
||||
/lib/transformation/templates
|
||||
/test
|
||||
/dist
|
||||
/tests.json
|
||||
/CHANGELOG.md
|
||||
/.package.json
|
||||
/packages
|
||||
/scripts
|
||||
/src
|
||||
_babel.github.io
|
||||
|
||||
@@ -1 +1 @@
|
||||
module.exports = require("./lib/api/node.js");
|
||||
module.exports = require("./lib/index.js");
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "babel-core",
|
||||
"version": "6.24.0",
|
||||
"version": "7.0.0-alpha.7",
|
||||
"description": "Babel compiler core.",
|
||||
"author": "Sebastian McKenzie <sebmck@gmail.com>",
|
||||
"homepage": "https://babeljs.io/",
|
||||
@@ -21,34 +21,32 @@
|
||||
"babel-core",
|
||||
"compiler"
|
||||
],
|
||||
"scripts": {
|
||||
"bench": "make bench",
|
||||
"test": "make test"
|
||||
"browser": {
|
||||
"./lib/config/loading/files/index.js": "./lib/config/loading/files/index-browser.js"
|
||||
},
|
||||
"dependencies": {
|
||||
"babel-code-frame": "^6.22.0",
|
||||
"babel-generator": "^6.24.0",
|
||||
"babel-helpers": "^6.23.0",
|
||||
"babel-messages": "^6.23.0",
|
||||
"babel-template": "^6.23.0",
|
||||
"babel-runtime": "^6.22.0",
|
||||
"babel-register": "^6.24.0",
|
||||
"babel-traverse": "^6.23.1",
|
||||
"babel-types": "^6.23.0",
|
||||
"babylon": "^6.11.0",
|
||||
"babel-code-frame": "7.0.0-alpha.3",
|
||||
"babel-generator": "7.0.0-alpha.7",
|
||||
"babel-helpers": "7.0.0-alpha.7",
|
||||
"babel-messages": "7.0.0-alpha.3",
|
||||
"babel-template": "7.0.0-alpha.7",
|
||||
"babel-traverse": "7.0.0-alpha.7",
|
||||
"babel-types": "7.0.0-alpha.7",
|
||||
"babylon": "7.0.0-beta.8",
|
||||
"convert-source-map": "^1.1.0",
|
||||
"debug": "^2.1.1",
|
||||
"json5": "^0.5.0",
|
||||
"lodash": "^4.2.0",
|
||||
"minimatch": "^3.0.2",
|
||||
"path-is-absolute": "^1.0.0",
|
||||
"micromatch": "^2.3.11",
|
||||
"private": "^0.1.6",
|
||||
"resolve": "^1.3.2",
|
||||
"slash": "^1.0.0",
|
||||
"source-map": "^0.5.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"babel-helper-fixtures": "^6.22.0",
|
||||
"babel-helper-transform-fixture-test-runner": "^6.24.0",
|
||||
"babel-polyfill": "^6.23.0"
|
||||
"babel-helper-fixtures": "^7.0.0-alpha.3",
|
||||
"babel-helper-transform-fixture-test-runner": "7.0.0-alpha.7",
|
||||
"babel-polyfill": "7.0.0-alpha.7",
|
||||
"babel-register": "7.0.0-alpha.7"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,3 +1 @@
|
||||
/* eslint max-len: 0 */
|
||||
// TODO: eventually deprecate this console.trace("use the `babel-register` package instead of `babel-core/register`");
|
||||
module.exports = require("babel-register");
|
||||
throw new Error("`babel-core/register` has been moved to `babel-register`.");
|
||||
|
||||
@@ -1,112 +0,0 @@
|
||||
/* eslint max-len: 0 */
|
||||
/* eslint no-new-func: 0 */
|
||||
|
||||
import { transform } from "./node";
|
||||
export {
|
||||
File,
|
||||
options,
|
||||
buildExternalHelpers,
|
||||
template,
|
||||
version,
|
||||
util,
|
||||
messages,
|
||||
types,
|
||||
traverse,
|
||||
OptionManager,
|
||||
Plugin,
|
||||
Pipeline,
|
||||
analyse,
|
||||
transform,
|
||||
transformFromAst,
|
||||
transformFile,
|
||||
transformFileSync
|
||||
} from "./node";
|
||||
|
||||
export function run(code: string, opts: Object = {}): any {
|
||||
return new Function(transform(code, opts).code)();
|
||||
}
|
||||
|
||||
export function load(url: string, callback: Function, opts: Object = {}, hold?: boolean) {
|
||||
opts.filename = opts.filename || url;
|
||||
|
||||
const xhr = global.ActiveXObject ? new global.ActiveXObject("Microsoft.XMLHTTP") : new global.XMLHttpRequest();
|
||||
xhr.open("GET", url, true);
|
||||
if ("overrideMimeType" in xhr) xhr.overrideMimeType("text/plain");
|
||||
|
||||
xhr.onreadystatechange = function () {
|
||||
if (xhr.readyState !== 4) return;
|
||||
|
||||
const status = xhr.status;
|
||||
if (status === 0 || status === 200) {
|
||||
const param = [xhr.responseText, opts];
|
||||
if (!hold) run(param);
|
||||
if (callback) callback(param);
|
||||
} else {
|
||||
throw new Error(`Could not load ${url}`);
|
||||
}
|
||||
};
|
||||
|
||||
xhr.send(null);
|
||||
}
|
||||
|
||||
function runScripts() {
|
||||
const scripts: Array<Array<any> | Object> = [];
|
||||
const types = ["text/ecmascript-6", "text/6to5", "text/babel", "module"];
|
||||
let index = 0;
|
||||
|
||||
/**
|
||||
* Transform and execute script. Ensures correct load order.
|
||||
*/
|
||||
|
||||
function exec() {
|
||||
const param = scripts[index];
|
||||
if (param instanceof Array) {
|
||||
run(param, index);
|
||||
index++;
|
||||
exec();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Load, transform, and execute all scripts.
|
||||
*/
|
||||
|
||||
function run(script: Object, i: number) {
|
||||
const opts = {};
|
||||
|
||||
if (script.src) {
|
||||
load(script.src, function (param) {
|
||||
scripts[i] = param;
|
||||
exec();
|
||||
}, opts, true);
|
||||
} else {
|
||||
opts.filename = "embedded";
|
||||
scripts[i] = [script.innerHTML, opts];
|
||||
}
|
||||
}
|
||||
|
||||
// Collect scripts with Babel `types`.
|
||||
|
||||
const _scripts = global.document.getElementsByTagName("script");
|
||||
|
||||
for (let i = 0; i < _scripts.length; ++i) {
|
||||
const _script = _scripts[i];
|
||||
if (types.indexOf(_script.type) >= 0) scripts.push(_script);
|
||||
}
|
||||
|
||||
for (let i = 0; i < scripts.length; i++) {
|
||||
run(scripts[i], i);
|
||||
}
|
||||
|
||||
exec();
|
||||
}
|
||||
|
||||
/**
|
||||
* Register load event to transform and execute scripts.
|
||||
*/
|
||||
|
||||
if (global.addEventListener) {
|
||||
global.addEventListener("DOMContentLoaded", runScripts, false);
|
||||
} else if (global.attachEvent) {
|
||||
global.attachEvent("onload", runScripts);
|
||||
}
|
||||
@@ -1,68 +0,0 @@
|
||||
import fs from "fs";
|
||||
|
||||
export { default as File } from "../transformation/file";
|
||||
export { default as options } from "../transformation/file/options/config";
|
||||
export { default as buildExternalHelpers } from "../tools/build-external-helpers";
|
||||
export { default as template } from "babel-template";
|
||||
export { default as resolvePlugin } from "../helpers/resolve-plugin";
|
||||
export { default as resolvePreset } from "../helpers/resolve-preset";
|
||||
export { version } from "../../package";
|
||||
|
||||
import * as util from "../util";
|
||||
export { util };
|
||||
|
||||
import * as messages from "babel-messages";
|
||||
export { messages };
|
||||
|
||||
import * as t from "babel-types";
|
||||
export { t as types };
|
||||
|
||||
import traverse from "babel-traverse";
|
||||
export { traverse };
|
||||
|
||||
import OptionManager from "../transformation/file/options/option-manager";
|
||||
export { OptionManager };
|
||||
|
||||
export function Plugin(alias) {
|
||||
throw new Error(`The (${alias}) Babel 5 plugin is being run with Babel 6.`);
|
||||
}
|
||||
|
||||
import Pipeline from "../transformation/pipeline";
|
||||
export { Pipeline };
|
||||
|
||||
const pipeline = new Pipeline;
|
||||
export const analyse = pipeline.analyse.bind(pipeline);
|
||||
export const transform = pipeline.transform.bind(pipeline);
|
||||
export const transformFromAst = pipeline.transformFromAst.bind(pipeline);
|
||||
|
||||
export function transformFile(filename: string, opts?: Object, callback: Function) {
|
||||
if (typeof opts === "function") {
|
||||
callback = opts;
|
||||
opts = {};
|
||||
}
|
||||
|
||||
opts.filename = filename;
|
||||
|
||||
fs.readFile(filename, function (err, code) {
|
||||
let result;
|
||||
|
||||
if (!err) {
|
||||
try {
|
||||
result = transform(code, opts);
|
||||
} catch (_err) {
|
||||
err = _err;
|
||||
}
|
||||
}
|
||||
|
||||
if (err) {
|
||||
callback(err);
|
||||
} else {
|
||||
callback(null, result);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
export function transformFileSync(filename: string, opts?: Object = {}): string {
|
||||
opts.filename = filename;
|
||||
return transform(fs.readFileSync(filename, "utf8"), opts);
|
||||
}
|
||||
187
packages/babel-core/src/config/build-config-chain.js
Normal file
187
packages/babel-core/src/config/build-config-chain.js
Normal file
@@ -0,0 +1,187 @@
|
||||
import * as babel from "../index";
|
||||
import path from "path";
|
||||
import micromatch from "micromatch";
|
||||
|
||||
import { findConfigs, loadConfig } from "./loading/files";
|
||||
|
||||
export default function buildConfigChain(opts: Object = {}) {
|
||||
const filename = opts.filename ? path.resolve(opts.filename) : null;
|
||||
const builder = new ConfigChainBuilder(filename);
|
||||
|
||||
try {
|
||||
builder.mergeConfig({
|
||||
type: "arguments",
|
||||
options: opts,
|
||||
alias: "base",
|
||||
dirname: process.cwd(),
|
||||
});
|
||||
|
||||
// resolve all .babelrc files
|
||||
if (opts.babelrc !== false) {
|
||||
builder.findConfigs(filename);
|
||||
}
|
||||
} catch (e) {
|
||||
if (e.code !== "BABEL_IGNORED_FILE") throw e;
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
return builder.configs.reverse();
|
||||
}
|
||||
|
||||
class ConfigChainBuilder {
|
||||
constructor(filename) {
|
||||
this.configs = [];
|
||||
this.filename = filename;
|
||||
this.possibleDirs = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests if a filename should be ignored based on "ignore" and "only" options.
|
||||
*/
|
||||
shouldIgnore(
|
||||
ignore: Array<string | RegExp | Function>,
|
||||
only?: Array<string | RegExp | Function>,
|
||||
dirname: string,
|
||||
): boolean {
|
||||
if (!this.filename) return false;
|
||||
|
||||
if (ignore) {
|
||||
if (!Array.isArray(ignore)) {
|
||||
throw new Error(`.ignore should be an array, was ${JSON.stringify(ignore)}`);
|
||||
}
|
||||
|
||||
for (const pattern of ignore) {
|
||||
if (this.matchesPattern(pattern, dirname)) return true;
|
||||
}
|
||||
}
|
||||
|
||||
if (only) {
|
||||
if (!Array.isArray(only)) {
|
||||
throw new Error(`.only should be an array, was ${JSON.stringify(only)}`);
|
||||
}
|
||||
|
||||
for (const pattern of only) {
|
||||
if (this.matchesPattern(pattern, dirname)) return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns result of calling function with filename if pattern is a function.
|
||||
* Otherwise returns result of matching pattern Regex with filename.
|
||||
*/
|
||||
matchesPattern(pattern: string | Function | RegExp, dirname: string) {
|
||||
if (typeof pattern === "string") {
|
||||
// Lazy-init so we don't initialize this for files that have no glob patterns.
|
||||
if (!this.possibleDirs) {
|
||||
this.possibleDirs = [];
|
||||
|
||||
if (this.filename) {
|
||||
this.possibleDirs.push(this.filename);
|
||||
|
||||
let current = this.filename;
|
||||
while (true) {
|
||||
const previous = current;
|
||||
current = path.dirname(current);
|
||||
if (previous === current) break;
|
||||
|
||||
this.possibleDirs.push(current);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return this.possibleDirs.some(micromatch.filter(path.resolve(dirname, pattern), {
|
||||
nocase: true,
|
||||
nonegate: true,
|
||||
}));
|
||||
} else if (typeof pattern === "function") {
|
||||
return pattern(this.filename);
|
||||
} else {
|
||||
return pattern.test(this.filename);
|
||||
}
|
||||
}
|
||||
|
||||
findConfigs(loc: string) {
|
||||
if (!loc) return;
|
||||
|
||||
if (!path.isAbsolute(loc)) {
|
||||
loc = path.join(process.cwd(), loc);
|
||||
}
|
||||
|
||||
findConfigs(path.dirname(loc)).forEach(({ filepath, dirname, options }) => {
|
||||
this.mergeConfig({
|
||||
type: "options",
|
||||
options,
|
||||
alias: filepath,
|
||||
dirname,
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
mergeConfig({
|
||||
type,
|
||||
options,
|
||||
alias,
|
||||
loc,
|
||||
dirname,
|
||||
}) {
|
||||
if (!options) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Bail out ASAP if this file is ignored so that we run as little logic as possible on ignored files.
|
||||
if (this.filename && this.shouldIgnore(options.ignore, options.only, dirname)) {
|
||||
// TODO(logan): This is a really cross way to bail out. Avoid this in rewrite.
|
||||
throw Object.assign(new Error("This file has been ignored."), { code: "BABEL_IGNORED_FILE" });
|
||||
}
|
||||
|
||||
options = Object.assign({}, options);
|
||||
|
||||
loc = loc || alias;
|
||||
|
||||
// env
|
||||
const envKey = babel.getEnv();
|
||||
if (options.env) {
|
||||
const envOpts = options.env[envKey];
|
||||
delete options.env;
|
||||
|
||||
this.mergeConfig({
|
||||
type,
|
||||
options: envOpts,
|
||||
alias: `${alias}.env.${envKey}`,
|
||||
dirname: dirname,
|
||||
});
|
||||
}
|
||||
|
||||
this.configs.push({
|
||||
type,
|
||||
options,
|
||||
alias,
|
||||
loc,
|
||||
dirname,
|
||||
});
|
||||
|
||||
// add extends clause
|
||||
if (options.extends) {
|
||||
const extendsConfig = loadConfig(options.extends, dirname);
|
||||
|
||||
const existingConfig = this.configs.some((config) => {
|
||||
return config.alias === extendsConfig.filepath;
|
||||
});
|
||||
if (!existingConfig) {
|
||||
this.mergeConfig({
|
||||
type: "options",
|
||||
alias: extendsConfig.filepath,
|
||||
options: extendsConfig.options,
|
||||
dirname: extendsConfig.dirname,
|
||||
});
|
||||
}
|
||||
delete options.extends;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
6
packages/babel-core/src/config/helpers/environment.js
Normal file
6
packages/babel-core/src/config/helpers/environment.js
Normal file
@@ -0,0 +1,6 @@
|
||||
export function getEnv(defaultValue = "development") {
|
||||
|
||||
return process.env.BABEL_ENV
|
||||
|| process.env.NODE_ENV
|
||||
|| defaultValue;
|
||||
}
|
||||
30
packages/babel-core/src/config/index.js
Normal file
30
packages/babel-core/src/config/index.js
Normal file
@@ -0,0 +1,30 @@
|
||||
import type Plugin from "./plugin";
|
||||
import OptionManager from "./option-manager";
|
||||
|
||||
export type ResolvedConfig = {
|
||||
options: Object,
|
||||
passes: Array<Array<Plugin>>,
|
||||
};
|
||||
|
||||
/**
|
||||
* Standard API for loading Babel configuration data. Not for public consumption.
|
||||
*/
|
||||
export default function loadConfig(opts: Object): ResolvedConfig|null {
|
||||
const mergedOpts = new OptionManager().init(opts);
|
||||
if (!mergedOpts) return null;
|
||||
|
||||
let passes = [];
|
||||
if (mergedOpts.plugins) {
|
||||
passes.push(mergedOpts.plugins);
|
||||
}
|
||||
|
||||
// With "passPerPreset" enabled there may still be presets in the options.
|
||||
if (mergedOpts.presets) {
|
||||
passes = passes.concat(mergedOpts.presets.map((preset) => preset.plugins).filter(Boolean));
|
||||
}
|
||||
|
||||
return {
|
||||
options: mergedOpts,
|
||||
passes,
|
||||
};
|
||||
}
|
||||
175
packages/babel-core/src/config/loading/files/configuration.js
Normal file
175
packages/babel-core/src/config/loading/files/configuration.js
Normal file
@@ -0,0 +1,175 @@
|
||||
// @flow
|
||||
|
||||
import path from "path";
|
||||
import fs from "fs";
|
||||
import json5 from "json5";
|
||||
import resolve from "resolve";
|
||||
|
||||
type ConfigFile = {
|
||||
filepath: string,
|
||||
dirname: string,
|
||||
options: Object,
|
||||
};
|
||||
|
||||
const existsCache = {};
|
||||
const jsonCache = {};
|
||||
|
||||
const BABELRC_FILENAME = ".babelrc";
|
||||
const BABELRC_JS_FILENAME = ".babelrc.js";
|
||||
const PACKAGE_FILENAME = "package.json";
|
||||
const BABELIGNORE_FILENAME = ".babelignore";
|
||||
|
||||
function exists(filename) {
|
||||
const cached = existsCache[filename];
|
||||
if (cached == null) {
|
||||
return existsCache[filename] = fs.existsSync(filename);
|
||||
} else {
|
||||
return cached;
|
||||
}
|
||||
}
|
||||
|
||||
export function findConfigs(dirname: string): Array<ConfigFile> {
|
||||
let foundConfig = false;
|
||||
let foundIgnore = false;
|
||||
|
||||
const confs = [];
|
||||
|
||||
let loc = dirname;
|
||||
while (true) {
|
||||
if (!foundIgnore) {
|
||||
const ignoreLoc = path.join(loc, BABELIGNORE_FILENAME);
|
||||
const ignore = readIgnoreConfig(ignoreLoc);
|
||||
|
||||
if (ignore) {
|
||||
confs.push(ignore);
|
||||
foundIgnore = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (!foundConfig) {
|
||||
const conf = [
|
||||
BABELRC_FILENAME,
|
||||
BABELRC_JS_FILENAME,
|
||||
PACKAGE_FILENAME,
|
||||
].reduce((previousConfig: ConfigFile|null, name) => {
|
||||
const filepath = path.join(loc, name);
|
||||
const config = readConfig(filepath);
|
||||
|
||||
if (config && previousConfig) {
|
||||
throw new Error(`Multiple configuration files found. Please remove one:\n- ${
|
||||
path.basename(previousConfig.filepath)}\n- ${name}\nfrom ${loc}`);
|
||||
}
|
||||
|
||||
return config || previousConfig;
|
||||
}, null);
|
||||
|
||||
if (conf) {
|
||||
confs.push(conf);
|
||||
foundConfig = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (foundIgnore && foundConfig) break;
|
||||
|
||||
if (loc === path.dirname(loc)) break;
|
||||
|
||||
loc = path.dirname(loc);
|
||||
}
|
||||
|
||||
return confs;
|
||||
}
|
||||
|
||||
export function loadConfig(name: string, dirname: string): ConfigFile {
|
||||
const filepath = resolve.sync(name, { basedir: dirname });
|
||||
|
||||
const conf = readConfig(filepath);
|
||||
if (!conf) throw new Error(`Config file ${filepath} contains no configuration data`);
|
||||
|
||||
return conf;
|
||||
}
|
||||
|
||||
/**
|
||||
* Read the given config file, returning the result. Returns null if no config was found, but will
|
||||
* throw if there are parsing errors while loading a config.
|
||||
*/
|
||||
function readConfig(filepath) {
|
||||
return (path.extname(filepath) === ".js") ? readConfigJS(filepath) : readConfigFile(filepath);
|
||||
}
|
||||
|
||||
function readIgnoreConfig(filepath) {
|
||||
if (!exists(filepath)) return null;
|
||||
|
||||
const file = fs.readFileSync(filepath, "utf8");
|
||||
let lines = file.split("\n");
|
||||
|
||||
lines = lines
|
||||
.map((line) => line.replace(/#(.*?)$/, "").trim())
|
||||
.filter((line) => !!line);
|
||||
|
||||
return {
|
||||
filepath,
|
||||
dirname: path.dirname(filepath),
|
||||
options: { ignore: lines },
|
||||
};
|
||||
}
|
||||
|
||||
function readConfigJS(filepath) {
|
||||
if (!exists(filepath)) return null;
|
||||
|
||||
let options;
|
||||
try {
|
||||
// $FlowIssue
|
||||
const configModule = (require(filepath): mixed);
|
||||
options = configModule && configModule.__esModule ? (configModule.default || undefined) : configModule;
|
||||
} catch (err) {
|
||||
err.message = `${filepath}: Error while loading config - ${err.message}`;
|
||||
throw err;
|
||||
}
|
||||
|
||||
if (!options || typeof options !== "object" || Array.isArray(options)) {
|
||||
throw new Error(`${filepath}: Configuration should be an exported JavaScript object.`);
|
||||
}
|
||||
|
||||
return {
|
||||
filepath,
|
||||
dirname: path.dirname(filepath),
|
||||
options,
|
||||
};
|
||||
}
|
||||
|
||||
function readConfigFile(filepath) {
|
||||
if (!exists(filepath)) return null;
|
||||
|
||||
const content = fs.readFileSync(filepath, "utf8");
|
||||
|
||||
let options;
|
||||
if (path.basename(filepath) === PACKAGE_FILENAME) {
|
||||
try {
|
||||
const json = jsonCache[content] = jsonCache[content] || JSON.parse(content);
|
||||
|
||||
options = json.babel;
|
||||
} catch (err) {
|
||||
err.message = `${filepath}: Error while parsing JSON - ${err.message}`;
|
||||
throw err;
|
||||
}
|
||||
if (!options) return null;
|
||||
} else {
|
||||
try {
|
||||
options = jsonCache[content] = jsonCache[content] || json5.parse(content);
|
||||
} catch (err) {
|
||||
err.message = `${filepath}: Error while parsing config - ${err.message}`;
|
||||
throw err;
|
||||
}
|
||||
|
||||
if (!options) throw new Error(`${filepath}: No config detected`);
|
||||
}
|
||||
|
||||
if (typeof options !== "object") throw new Error(`${filepath}: Config returned typeof ${typeof options}`);
|
||||
if (Array.isArray(options)) throw new Error(`${filepath}: Expected config object but found array`);
|
||||
|
||||
return {
|
||||
filepath,
|
||||
dirname: path.dirname(filepath),
|
||||
options,
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
// @flow
|
||||
|
||||
type ConfigFile = {
|
||||
filepath: string,
|
||||
dirname: string,
|
||||
options: Object,
|
||||
};
|
||||
|
||||
// eslint-disable-next-line no-unused-vars
|
||||
export function findConfigs(dirname: string): Array<ConfigFile> {
|
||||
return [];
|
||||
}
|
||||
|
||||
export function loadConfig(name: string, dirname: string): ConfigFile {
|
||||
throw new Error(`Cannot load ${name} relative to ${dirname} in a browser`);
|
||||
}
|
||||
|
||||
// eslint-disable-next-line no-unused-vars
|
||||
export function resolvePlugin(name: string, dirname: string): string|null {
|
||||
return null;
|
||||
}
|
||||
|
||||
// eslint-disable-next-line no-unused-vars
|
||||
export function resolvePreset(name: string, dirname: string): string|null {
|
||||
return null;
|
||||
}
|
||||
|
||||
export function loadPlugin(name: string, dirname: string): { filepath: string, plugin: mixed } {
|
||||
throw new Error(`Cannot load plugin ${name} relative to ${dirname} in a browser`);
|
||||
}
|
||||
|
||||
export function loadPreset(name: string, dirname: string): { filepath: string, preset: mixed } {
|
||||
throw new Error(`Cannot load preset ${name} relative to ${dirname} in a browser`);
|
||||
}
|
||||
|
||||
export function loadParser(name: string, dirname: string): { filepath: string, parser: Function } {
|
||||
throw new Error(`Cannot load parser ${name} relative to ${dirname} in a browser`);
|
||||
}
|
||||
|
||||
export function loadGenerator(name: string, dirname: string): { filepath: string, generator: Function } {
|
||||
throw new Error(`Cannot load generator ${name} relative to ${dirname} in a browser`);
|
||||
}
|
||||
11
packages/babel-core/src/config/loading/files/index.js
Normal file
11
packages/babel-core/src/config/loading/files/index.js
Normal file
@@ -0,0 +1,11 @@
|
||||
// @flow
|
||||
|
||||
import typeof * as indexBrowserType from "./index-browser";
|
||||
import typeof * as indexType from "./index";
|
||||
|
||||
// Kind of gross, but essentially asserting that the exports of this module are the same as the
|
||||
// exports of index-browser, since this file may be replaced at bundle time with index-browser.
|
||||
((({}: any) : $Exact<indexBrowserType>): $Exact<indexType>);
|
||||
|
||||
export * from "./configuration";
|
||||
export * from "./plugins";
|
||||
111
packages/babel-core/src/config/loading/files/plugins.js
Normal file
111
packages/babel-core/src/config/loading/files/plugins.js
Normal file
@@ -0,0 +1,111 @@
|
||||
// @flow
|
||||
|
||||
/**
|
||||
* This file handles all logic for converting string-based configuration references into loaded objects.
|
||||
*/
|
||||
|
||||
import resolve from "resolve";
|
||||
|
||||
export function resolvePlugin(pluginName: string, dirname: string): string|null {
|
||||
const possibleNames = [`babel-plugin-${pluginName}`, pluginName];
|
||||
|
||||
return resolveFromPossibleNames(possibleNames, dirname);
|
||||
}
|
||||
|
||||
export function resolvePreset(presetName: string, dirname: string): string|null {
|
||||
const possibleNames = [`babel-preset-${presetName}`, presetName];
|
||||
|
||||
// trying to resolve @organization shortcat
|
||||
// @foo/es2015 -> @foo/babel-preset-es2015
|
||||
const matches = presetName.match(/^(@[^/]+)\/(.+)$/);
|
||||
if (matches) {
|
||||
const [, orgName, presetPath] = matches;
|
||||
possibleNames.push(`${orgName}/babel-preset-${presetPath}`);
|
||||
}
|
||||
|
||||
return resolveFromPossibleNames(possibleNames, dirname);
|
||||
}
|
||||
|
||||
export function loadPlugin(name: string, dirname: string): { filepath: string, plugin: mixed } {
|
||||
const filepath = resolvePlugin(name, dirname);
|
||||
if (!filepath) throw new Error(`Plugin ${name} not found relative to ${dirname}`);
|
||||
|
||||
return {
|
||||
filepath,
|
||||
plugin: requireModule(filepath),
|
||||
};
|
||||
}
|
||||
|
||||
export function loadPreset(name: string, dirname: string): { filepath: string, preset: mixed } {
|
||||
const filepath = resolvePreset(name, dirname);
|
||||
if (!filepath) throw new Error(`Preset ${name} not found relative to ${dirname}`);
|
||||
|
||||
return {
|
||||
filepath,
|
||||
preset: requireModule(filepath),
|
||||
};
|
||||
}
|
||||
|
||||
export function loadParser(name: string, dirname: string): { filepath: string, parser: Function } {
|
||||
const filepath = resolveQuiet(name, dirname);
|
||||
if (!filepath) throw new Error(`Parser ${name} not found relative to ${dirname}`);
|
||||
|
||||
const mod = requireModule(filepath);
|
||||
|
||||
if (!mod) {
|
||||
throw new Error(`Parser ${name} relative to ${dirname} does not export an object`);
|
||||
}
|
||||
if (typeof mod.parse !== "function") {
|
||||
throw new Error(`Parser ${name} relative to ${dirname} does not export a .parse function`);
|
||||
}
|
||||
|
||||
return {
|
||||
filepath,
|
||||
parser: mod.parse,
|
||||
};
|
||||
}
|
||||
|
||||
export function loadGenerator(name: string, dirname: string): { filepath: string, generator: Function } {
|
||||
const filepath = resolveQuiet(name, dirname);
|
||||
if (!filepath) throw new Error(`Generator ${name} not found relative to ${dirname}`);
|
||||
|
||||
const mod = requireModule(filepath);
|
||||
|
||||
if (!mod) {
|
||||
throw new Error(`Generator ${name} relative to ${dirname} does not export an object`);
|
||||
}
|
||||
if (typeof mod.print !== "function") {
|
||||
throw new Error(`Generator ${name} relative to ${dirname} does not export a .print function`);
|
||||
}
|
||||
|
||||
return {
|
||||
filepath,
|
||||
generator: mod.print,
|
||||
};
|
||||
}
|
||||
|
||||
function resolveQuiet(name: string, dirname: string): string|null {
|
||||
try {
|
||||
return resolve.sync(name, { basedir: dirname });
|
||||
} catch (e) {
|
||||
// The 'resolve' module can currently throw ENOTDIR
|
||||
// https://github.com/substack/node-resolve/issues/121
|
||||
if (e.code !== "MODULE_NOT_FOUND" && e.code !== "ENOTDIR") throw e;
|
||||
|
||||
// Silently fail and move to the next item.
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
function resolveFromPossibleNames(possibleNames: Array<string>, dirname: string): string|null {
|
||||
for (const name of possibleNames) {
|
||||
const result = resolveQuiet(name, dirname);
|
||||
if (result !== null) return result;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
function requireModule(name: string): mixed {
|
||||
// $FlowIssue
|
||||
return require(name);
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user