This commit is contained in:
Sebastian McKenzie 2015-07-13 16:34:43 +01:00
parent 1948946a4d
commit 2d5d1ceb5c
41 changed files with 45 additions and 299 deletions

View File

@ -26,129 +26,8 @@ contributing, please read the
## Developing ## Developing
> Note: Babel moves fast. Only the latest release is guaranteed to build correctly.
> Older releases are not officially supported. If you attempt to build them, do that at your own risk.
#### Setup #### Setup
```sh
$ git clone https://github.com/babel/babel
$ cd babel
$ make bootstrap
```
Then you can either run:
```sh
$ make build-core
```
to build Babel **once** or:
```sh
$ make watch-core
```
to have Babel build itself then incrementally build files on change.
#### Running tests
You can run tests via:
```sh
$ make test
```
This is mostly overkill and you can limit the tests to a select few by directly
running them with `mocha`:
```sh
$ mocha test/core/transformation.js
```
Use mocha's `--grep` option to run a subset of tests by name:
```sh
$ mocha test/core/transformation.js --grep es7
```
If you don't have `mocha` installed globally, you can still use it from Babel's
dependencies in `node_modules`, but make sure `node_modules/.bin` is added to
your [`$PATH`](http://unix.stackexchange.com/questions/26047/how-to-correctly-add-a-path-to-path) environment variable.
#### Workflow
* Fork the repository
* Clone your fork and change directory to it (`git clone git@github.com:yourUserName/babel.git && cd babel`)
* Install the project dependencies (`make bootstrap`)
* Link your forked clone (`npm link`)
* Develop your changes ensuring you're fetching updates from upstream often
* Ensure the test are passing (`make test`)
* Create new pull request explaining your proposed change or reference an issue in your commit message
#### Dependencies
+ [ast-types](http://ghub.io/ast-types) This is required to monkeypatch regenerators AST definitions. Could be improved in the future.
+ [chalk](http://ghub.io/chalk) This is used for terminal color highlighting for syntax errors.
+ [convert-source-map](http://ghub.io/convert-source-map) Turns a source map object into a comment etc.
+ [core-js](http://ghub.io/core-js) Used for the polyfill.
+ [debug](http://ghub.io/debug) Used to output debugging information when NODE_DEBUG is set to babel.
+ [detect-indent](http://ghub.io/detect-indent) This is used in the code generator so it can infer indentation.
+ [estraverse](http://ghub.io/estraverse) The only method on this is attachComments. I'd like to implement our own comment attachment algorithm eventually though.
+ [esutils](http://ghub.io/esutils) Various ES related utilities. Check whether something is a keyword etc.
+ [fs-readdir-recursive](http://ghub.io/fs-readdir-recursive) Recursively search a directory for.
+ [globals](http://ghub.io/globals) A list of JavaScript global variables. This is used by the scope tracking to check for colliding variables.
+ [is-integer](http://ghub.io/is-integer) Checks if something is an integer.
+ [js-tokens](http://ghub.io/js-tokens) This is used to get tokens for syntax error highlighting.
+ [line-numbers](http://ghub.io/line-numbers) Used to produce the code frames in syntax errors.
+ [lodash](http://ghub.io/lodash) Used for various utilities.
+ [minimatch](http://ghub.io/minimatch) This is used to match glob-style ignore/only filters.
+ [output-file-sync](http://ghub.io/output-file-sync) Synchronously writes a file and create its ancestor directories if needed.
+ [path-is-absolute](http://ghub.io/path-is-absolute) Checks if a path is absolute. C:\foo and \foo are considered absolute.
+ [regenerator](http://ghub.io/regenerator) This is used to transform generators/async functions.
+ [regexpu](http://ghub.io/regexpu) Used to transform unicode regex patterns.
+ [repeating](http://ghub.io/repeating) Repeats a string.
+ [shebang-regex](http://ghub.io/shebang-regex) Literally just a regex that matches shebangs.
+ [slash](http://ghub.io/slash) Normalises path separators.
+ [source-map](http://ghub.io/source-map) Generates sourcemaps.
+ [source-map-support](http://ghub.io/source-map-support) Adds source map support to babel-node/babel/register.
+ [strip-json-comments](http://ghub.io/strip-json-comments) Remove comments from a JSON string. This is used for .babelrc files.
+ [to-fast-properties](http://ghub.io/to-fast-properties) A V8 trick to put an object into fast properties mode.
+ [trim-right](http://ghub.io/trim-right) Trims the rightside whitespace.
+ [path-exists](https://www.npmjs.com/package/path-exists) Checks if a path exists. (replaces the deprecated `fs.exists` methods)
+ [home-or-tmp](https://github.com/sindresorhus/home-or-tmp) Gets the user home directory with fallback to the system temporary directory. This is used to resolve the babel-node/babel/register cache.
+ [resolve](https://www.npmjs.com/package/resolve) Implements the [`require.resolve()` algorithm](http://nodejs.org/docs/v0.12.0/api/all.html#all_require_resolve) such that we can `require.resolve()` on behalf of a file asynchronously and synchronously.
#### Code Standards #### Code Standards
* **General** * **General**
@ -177,4 +56,5 @@ your [`$PATH`](http://unix.stackexchange.com/questions/26047/how-to-correctly-ad
* No pollution of global variables and prototypes * No pollution of global variables and prototypes
#### Internals #### Internals
Please see [`/doc`](/doc) for internals documentation relevant to developing babel. Please see [`/doc`](/doc) for internals documentation relevant to developing babel.

View File

@ -1,69 +1,51 @@
MAKEFLAGS = -j1 MAKEFLAGS = -j1
ISTANBUL_CMD = node_modules/istanbul/lib/cli.js cover
#UGLIFY_CMD = node_modules/uglify-js/bin/uglifyjs --mangle sort
MOCHA_CMD = node_modules/mocha/bin/_mocha
BABEL_CMD = node_modules/babel/bin/babel
export NODE_ENV = test export NODE_ENV = test
.PHONY: clean test test-cov test-clean test-travis test-browser publish build bootstrap publish-core publish-runtime build-website build-core watch-core build-core-test clean-core prepublish .PHONY: clean test test-cov test-clean test-travis test-browser publish build bootstrap publish-core publish-runtime build-website build-core watch-core build-core-test clean-core prepublish
build-core: clean-core build: clean
./scripts/build-core.sh ./scripts/build.sh
watch-core: clean-core build-dist: build
./scripts/build-core.sh --watch cd packages/babel; \
scripts/build-dist.sh
cd packages/babel-runtime; \
node scripts/build-dist.js
clean-core: watch: clean
rm -rf packages/*/lib scripts/build.sh --watch
lint: lint:
eslint packages/*/src eslint packages/*/src
build: build-core clean: test-clean
cd packages/babel; \ rm -rf coverage
scripts/build.sh rm -rf packages/*/dist dist
rm -rf packages/*/lib packages/babel/templates.json
clean:
rm -rf coverage packages/babel/templates.json test/tmp dist lib
test-clean: test-clean:
rm -rf test/tmp rm -rf packages/*/test/tmp
test: test: lint
./scripts/test.sh ./scripts/test.sh
make test-clean make test-clean
test-browser: test-browser:
./scripts/test-browser.sh ./scripts/test-browser.sh
test-cov: test-cov: clean
rm -rf coverage
BABEL_ENV=test; \ BABEL_ENV=test; \
make build-core make build
node $(ISTANBUL_CMD) $(MOCHA_CMD) -- test/core node $(ISTANBUL_CMD) $(MOCHA_CMD) -- test/core
test-travis: bootstrap lint build test test-travis: bootstrap lint build test
publish: lint publish: build-dist
git pull --rebase git pull --rebase
make test make test
read -p "Version: " version; \ node scripts/publish
npm version $$version --message "v%s" ./scripts/build-website.sh
git push --follow-tags
publish-runtime:
cd packages; \
node build-runtime.js; \
cd babel-runtime; \
npm publish
travis-deploy:
@./scripts/travis/publish-cli.sh
make publish-runtime
@./scripts/travis/build-website.sh
@./scripts/travis/comment-issues.sh
bootstrap: bootstrap:
./scripts/bootstrap.sh ./scripts/bootstrap.sh

View File

@ -7,7 +7,6 @@
"chai": "^2.2.0", "chai": "^2.2.0",
"es5-shim": "^4.1.7", "es5-shim": "^4.1.7",
"eslint": "^0.21.2", "eslint": "^0.21.2",
"esvalid": "^1.1.0",
"fs-readdir-recursive": "^0.1.2", "fs-readdir-recursive": "^0.1.2",
"istanbul": "^0.3.5", "istanbul": "^0.3.5",
"matcha": "^0.6.0", "matcha": "^0.6.0",
@ -15,6 +14,7 @@
"output-file-sync": "^1.1.1", "output-file-sync": "^1.1.1",
"path-exists": "^1.0.0", "path-exists": "^1.0.0",
"rimraf": "^2.4.1", "rimraf": "^2.4.1",
"semver": "^5.0.0",
"uglify-js": "^2.4.16" "uglify-js": "^2.4.16"
} }
} }

View File

@ -7,6 +7,7 @@
"repository": "babel/babel", "repository": "babel/babel",
"preferGlobal": true, "preferGlobal": true,
"dependencies": { "dependencies": {
"babel": "*",
"chokidar": "^1.0.0", "chokidar": "^1.0.0",
"commander": "^2.6.0", "commander": "^2.6.0",
"convert-source-map": "^1.1.0", "convert-source-map": "^1.1.0",

View File

@ -1,2 +0,0 @@
--reporter dot
--ui tdd

View File

@ -1,2 +0,0 @@
var bar = () => console.log("bar");
bar();

View File

@ -1,5 +0,0 @@
import "./bar2";
import "./not_node_modules";
var foo = () => console.log("foo");
foo();

View File

@ -1,10 +0,0 @@
/*
The purpose of this file is to test that the node_modules check in the require
hook doesn't mistakenly exclude something like "not_node_modules". To pass, this
file merely needs to be transpiled. The transpiled code won't, and doesn't need
to, execute without error. It won't execute because React will be undefined.
*/
try {
<Some jsx="element" />;
}
catch (e) {}

View File

@ -0,0 +1,2 @@
scripts
node_modules

View File

@ -1,5 +1,3 @@
"use strict";
var outputFile = require("output-file-sync"); var outputFile = require("output-file-sync");
var transform = require("../lib/babel/transformation"); var transform = require("../lib/babel/transformation");
var each = require("lodash/collection/each"); var each = require("lodash/collection/each");
@ -10,7 +8,7 @@ var t = require("../lib/babel/types");
var _ = require("lodash"); var _ = require("lodash");
function relative(filename) { function relative(filename) {
return __dirname + "/babel-runtime/" + filename; return __dirname + "/../" + filename;
} }
function readFile(filename, shouldDefaultify) { function readFile(filename, shouldDefaultify) {
@ -27,16 +25,6 @@ function defaultify(name) {
return 'module.exports = { "default": ' + name + ', __esModule: true };'; return 'module.exports = { "default": ' + name + ', __esModule: true };';
} }
function updatePackage() {
var pkgLoc = relative("package.json");
var pkg = require(pkgLoc);
var mainPkg = require("../package.json");
pkg.version = mainPkg.version;
writeRootFile("package.json", JSON.stringify(pkg, null, 2));
}
function writeRootFile(filename, content) { function writeRootFile(filename, content) {
filename = relative(filename); filename = relative(filename);
console.log(filename); console.log(filename);
@ -92,5 +80,3 @@ each(paths, function (path) {
writeFile("core-js/" + path + ".js", defaultify('require("core-js/library/fn/' + path + '")')); writeFile("core-js/" + path + ".js", defaultify('require("core-js/library/fn/' + path + '")'));
}); });
updatePackage();

View File

@ -3,14 +3,10 @@
.* .*
/lib/transformation/templates /lib/transformation/templates
/test /test
/benchmark
/Makefile
/dist /dist
/tests.json /tests.json
/CHANGELOG.md /CHANGELOG.md
/.package.json /.package.json
/coverage
/vendor
/packages /packages
/src /src
_babel.github.io _babel.github.io

View File

@ -41,6 +41,7 @@
"babel-plugin-runtime": "^1.0.7", "babel-plugin-runtime": "^1.0.7",
"babel-plugin-undeclared-variables-check": "^1.0.2", "babel-plugin-undeclared-variables-check": "^1.0.2",
"babel-plugin-undefined-to-void": "^1.1.6", "babel-plugin-undefined-to-void": "^1.1.6",
"babylon": "*",
"bluebird": "^2.9.33", "bluebird": "^2.9.33",
"chalk": "^1.0.0", "chalk": "^1.0.0",
"convert-source-map": "^1.1.0", "convert-source-map": "^1.1.0",

View File

@ -1,5 +1,4 @@
var pathExists = require("path-exists"); var pathExists = require("path-exists");
var esvalid = require("esvalid");
var util = require("../lib/util"); var util = require("../lib/util");
var path = require("path"); var path = require("path");
var fs = require("fs"); var fs = require("fs");
@ -20,17 +19,6 @@ var readFile = exports.readFile = function (filename) {
} }
}; };
exports.esvalid = function (ast, code, loc) {
var errors = esvalid.errors(ast);
if (errors.length) {
var msg = [];
_.each(errors, function (err) {
msg.push(err.message + " - " + util.inspect(err.node));
});
throw new Error(loc + ": " + msg.join(". ") + "\n" + code);
}
};
exports.assertVendor = function (name) { exports.assertVendor = function (name) {
if (!pathExists.sync(__dirname + "/../../../vendor/" + name)) { if (!pathExists.sync(__dirname + "/../../../vendor/" + name)) {
console.error("No vendor/" + name + " - run `make bootstrap`"); console.error("No vendor/" + name + " - run `make bootstrap`");

View File

@ -44,6 +44,7 @@ chai.assert.throw = function (fn, msg) {
return chai.assert._throw(fn, msg); return chai.assert._throw(fn, msg);
}; };
var run = function (task, done) { var run = function (task, done) {
var actual = task.actual; var actual = task.actual;
var expect = task.expect; var expect = task.expect;
@ -60,14 +61,6 @@ var run = function (task, done) {
var execCode = exec.code; var execCode = exec.code;
var result; var result;
var noCheckAst = opts.noCheckAst;
delete opts.noCheckAst;
var checkAst = function (result, opts) {
if (noCheckAst) return;
helper.esvalid(result.ast.program, result.code, opts.loc);
};
if (execCode) { if (execCode) {
result = transform(execCode, getOpts(exec)); result = transform(execCode, getOpts(exec));
execCode = result.code; execCode = result.code;
@ -90,8 +83,6 @@ var run = function (task, done) {
err.message += codeFrame(execCode); err.message += codeFrame(execCode);
throw err; throw err;
} }
checkAst(result, exec);
} }
var actualCode = actual.code; var actualCode = actual.code;
@ -106,8 +97,6 @@ var run = function (task, done) {
//require("fs").writeFileSync(expect.loc, actualCode); //require("fs").writeFileSync(expect.loc, actualCode);
throw err; throw err;
} }
checkAst(result, actual);
} }
if (task.sourceMap) { if (task.sourceMap) {

View File

@ -1,3 +0,0 @@
{
"noCheckAst": true
}

View File

@ -1,5 +1,4 @@
{ {
"externalHelpers": true, "externalHelpers": true,
"noCheckAst": true,
"optional": ["asyncToGenerator"] "optional": ["asyncToGenerator"]
} }

View File

@ -1,4 +1,3 @@
{ {
"optional": ["bluebirdCoroutines"], "optional": ["bluebirdCoroutines"]
"noCheckAst": true
} }

View File

@ -1,4 +1,3 @@
{ {
"blacklist": ["es6.modules"], "blacklist": ["es6.modules"]
"noCheckAst": true
} }

View File

@ -1,3 +0,0 @@
{
"noCheckAst": true
}

View File

@ -1,5 +1,4 @@
{ {
"noCheckAst": true,
"externalHelpers": true, "externalHelpers": true,
"optional": "es7.exportExtensions" "optional": "es7.exportExtensions"
} }

View File

@ -1,4 +1,3 @@
{ {
"whitelist": ["flow", "es7.asyncFunctions", "es7.classProperties"], "whitelist": ["flow", "es7.asyncFunctions", "es7.classProperties"]
"noCheckAst": true
} }

View File

@ -1,7 +1,6 @@
{ {
"experimental": true, "experimental": true,
"externalHelpers": true, "externalHelpers": true,
"noCheckAst": true,
"blacklist": ["regenerator"], "blacklist": ["regenerator"],
"optional": ["minification.deadCodeElimination"] "optional": ["minification.deadCodeElimination"]
} }

View File

@ -1,4 +1,3 @@
{ {
"blacklist": ["es6.modules"], "blacklist": ["es6.modules"]
"noCheckAst": true
} }

View File

@ -1,5 +1,4 @@
{ {
"noCheckAst": true,
"optional": ["optimisation.react.constantElements"], "optional": ["optimisation.react.constantElements"],
"blacklist": ["react", "react.displayName"] "blacklist": ["react", "react.displayName"]
} }

View File

@ -1,5 +1,4 @@
{ {
"externalHelpers": true, "externalHelpers": true,
"noCheckAst": true,
"optional": ["optimisation.react.inlineElements"] "optional": ["optimisation.react.inlineElements"]
} }

View File

@ -1,4 +1,3 @@
{ {
"noCheckAst": true,
"blacklist": ["es6.modules"] "blacklist": ["es6.modules"]
} }

View File

@ -1,2 +0,0 @@
--reporter dot
--ui tdd

View File

@ -1,2 +0,0 @@
var bar = () => console.log("bar");
bar();

View File

@ -1,5 +0,0 @@
import "./bar2";
import "./not_node_modules";
var foo = () => console.log("foo");
foo();

View File

@ -1,10 +0,0 @@
/*
The purpose of this file is to test that the node_modules check in the require
hook doesn't mistakenly exclude something like "not_node_modules". To pass, this
file merely needs to be transpiled. The transpiled code won't, and doesn't need
to, execute without error. It won't execute because React will be undefined.
*/
try {
<Some jsx="element" />;
}
catch (e) {}

View File

@ -30,6 +30,7 @@ export class Token {
const pp = Parser.prototype; const pp = Parser.prototype;
// Are we running under Rhino? // Are we running under Rhino?
/* global Packages */
const isRhino = typeof Packages === "object" && Object.prototype.toString.call(Packages) === "[object JavaPackage]"; const isRhino = typeof Packages === "object" && Object.prototype.toString.call(Packages) === "[object JavaPackage]";
// Move to the next token // Move to the next token

View File

@ -1,2 +0,0 @@
--reporter dot
--ui tdd

View File

@ -1,11 +0,0 @@
var outputFile = require("output-file-sync");
var pkgLoc = __dirname + "/babel-cli/package.json";
var pkg = require(pkgLoc);
var mainPkg = require("../package.json");
pkg.version = mainPkg.version;
pkg.dependencies["babel-core"] = "^" + mainPkg.version;
outputFile(pkgLoc, JSON.stringify(pkg, null, 2));

View File

@ -12,5 +12,5 @@ if [ ! -d ./_babel ]; then
fi fi
make build make build
git commit -am "${TRAVIS_TAG}" git commit -am "v`babel -V`"
git push "https://${GH_TOKEN}@github.com/babel/babel.github.io" git push

3
scripts/publish.js Normal file
View File

@ -0,0 +1,3 @@
var fs = require("fs");
var packageNames = fs.readDirSync(__filename + "/../packages");

View File

@ -1,15 +1,16 @@
#!/bin/sh #!/bin/sh
set -e set -e
TEST_DIRS=""
for f in packages/*; do for f in packages/*; do
if [ -n "$TEST_ONLY" ] && [ `basename $f` != "$TEST_ONLY" ]; then if [ -n "$TEST_ONLY" ] && [ `basename $f` != "$TEST_ONLY" ]; then
continue continue
fi fi
if [ -d "$f/test" ]; then if [ -d "$f/test" ]; then
echo $f TEST_DIRS="$f/test $TEST_DIRS"
cd $f
node ../../node_modules/mocha/bin/_mocha
cd ../../
fi fi
done done
node node_modules/mocha/bin/_mocha $TEST_DIRS --reporter dot --ui tdd

View File

@ -1,2 +0,0 @@
#!/bin/bash
set -e

View File

@ -1,17 +0,0 @@
#!/bin/bash
set -e
LAST_TAG=$(git describe $(git rev-list --tags --max-count=1))
TAG_DIFF=$(git diff $LAST_TAG -- packages/babel-cli/)
if [ -n "$TAG_DIFF" ]; then
echo "Changes detected to babel-cli since last tag, publishing new version."
cd ../packages
node build-cli.js
cd babel-cli
npm publish
else
echo "No changes detected to babel-cli since last tag"
fi

2
test/warning.js Normal file
View File

@ -0,0 +1,2 @@
console.error("Don't run `mocha` directly. Use `make test`. See CONTRIBUTING.md for usage instructions.");
process.exit(0);