Merge remote-tracking branch 'origin/master' into merge-master

This commit is contained in:
Henry Zhu 2017-02-23 18:54:15 -05:00
commit d33d023594
18 changed files with 113 additions and 18 deletions

View File

@ -9,6 +9,8 @@
| |
<strong><a href="#writing-tests">Writing tests</a></strong> <strong><a href="#writing-tests">Writing tests</a></strong>
| |
<strong><a href="#debugging-code">Debugging code</a></strong>
|
<strong><a href="#internals">Internals</a></strong> <strong><a href="#internals">Internals</a></strong>
</p> </p>
@ -127,7 +129,8 @@ $ TEST_DEBUG=true make test
To test the code coverage, use: To test the code coverage, use:
```sh ```sh
$ make test-cov $ BABEL_ENV=cov make build
$ ./scripts/test-cov.sh
``` ```
#### Writing tests #### Writing tests
@ -199,9 +202,46 @@ For both `babel-plugin-x` and `babylon`, you can easily generate an `expected.js
- expected.json (will be generated if not created) - expected.json (will be generated if not created)
``` ```
#### Debugging code
A common approach to debugging JavaScript code is to walk through the code using the [Chrome DevTools](https://developers.google.com/web/tools/chrome-devtools/) debugger.
For illustration purposes, we are going to assume that we need to get a better understanding of [`Generator.generate()`](https://github.com/babel/babel/blob/b5246994b57f06af871be6a63dcc4c6fd41d94d6/packages/babel-generator/src/index.js#L32), which is responsible for generating code for a given AST.
To get a better understanding of what is actually going on for this particular piece of code, we are going to make use of breakpoints.
```diff
generate() {
+ debugger; // breakpoint
return super.generate(this.ast);
}
```
To include the changes, we have to make sure to build Babel:
```bash
$ make build
```
Next, we need to execute `Generator.generate()`, which can be achieved by running a test case in the `babel-generator` package.
For example, we can run the test case that tests the generation of class declarations:
```bash
$ TEST_DEBUG=true TEST_GREP=ClassDeclaration make test-only
./scripts/test.sh
Debugger listening on port 9229.
Warning: This is an experimental feature and could change at any time.
To start debugging, open the following URL in Chrome:
chrome-devtools://devtools/remote/serve_file/@60cd6e859b9f557d2312f5bf532f6aec5f284980/inspector.html?experiments=true&v8only=true&ws=127.0.0.1:9229/3cdaebd2-be88-4e7b-a94b-432950ab72d0
```
To start the debugging in Chrome DevTools, open the given URL.
The debugger starts at the first executed line of code, which is Mocha's first line by default.
Click _Resume script execution_ <img src="https://i.imgur.com/TmYBn9d.png" alt="Resume script execution button." width="16"> to jump to the set breakpoint.
Note that the code shown in Chrome DevTools is compiled code and therefore differs.
#### Internals #### Internals
- AST spec ([babylon/ast/spec.md](https://github.com/babel/babylon/blob/master/ast/spec.md)) - AST spec ([babylon/ast/spec.md](https://github.com/babel/babylon/blob/master/ast/spec.md))
- Versionning ([doc/design/versioning.md](./doc/design/versioning.md)) - Versioning ([doc/design/versioning.md](./doc/design/versioning.md))
- Monorepo ([doc/design/monorepo.md](./doc/design/monorepo.md)) - Monorepo ([doc/design/monorepo.md](./doc/design/monorepo.md))
- Compiler environment support ([doc/design/compiler-environment-support.md](./doc/design/compiler-environment-support.md)) - Compiler environment support ([doc/design/compiler-environment-support.md](./doc/design/compiler-environment-support.md))
- Compiler assumptions ([doc/design/compiler-assumptions.md](./doc/design/compiler-assumptions.md)) - Compiler assumptions ([doc/design/compiler-assumptions.md](./doc/design/compiler-assumptions.md))

View File

@ -49,11 +49,11 @@ test-only:
test: lint test-only test: lint test-only
test-ci: test-ci:
NODE_ENV=test make bootstrap make bootstrap
make test-only make test-only
test-ci-coverage: test-ci-coverage:
NODE_ENV=test BABEL_ENV=cov make bootstrap BABEL_ENV=cov make bootstrap
./scripts/test-cov.sh ./scripts/test-cov.sh
./node_modules/.bin/codecov -f coverage/coverage-final.json ./node_modules/.bin/codecov -f coverage/coverage-final.json

View File

@ -203,6 +203,14 @@ Babel | Daniel Tschinder | Logan Smyth | Henry Zhu |
| [@kangax](https://github.com/kangax) | [@kaicataldo](https://github.com/kaicataldo) | [@motiz88](https://github.com/motiz88) | [@xtuc](https://github.com/xtuc) | | [@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) | | [@kangax](https://twitter.com/kangax) | [@kai_cataldo](https://twitter.com/kai_cataldo) | [@motiz88](https://twitter.com/motiz88) | [@svensauleau](https://twitter.com/svensauleau) |
### Non-Human Members
[<img src="https://github.com/babel/babel-bot/raw/master/babel-bot.png" height="64">](https://github.com/babel-bot) |
|---|
| Babel Bot |
| [@babel-bot](https://github.com/babel-bot) |
| [@babeljs](https://twitter.com/babeljs) |
### Inactive members ### Inactive members
[![Amjad Masad](https://avatars.githubusercontent.com/u/587518?s=64)](https://github.com/amasad) | [![James Kyle](https://avatars.githubusercontent.com/u/952783?s=64)](https://github.com/thejameskyle) | [![Jesse McCarthy](https://avatars.githubusercontent.com/u/129203?s=64)](https://github.com/jmm) | [![Sebastian McKenzie](https://avatars.githubusercontent.com/u/853712?s=64)](https://github.com/kittens) (Creator) | [![Amjad Masad](https://avatars.githubusercontent.com/u/587518?s=64)](https://github.com/amasad) | [![James Kyle](https://avatars.githubusercontent.com/u/952783?s=64)](https://github.com/thejameskyle) | [![Jesse McCarthy](https://avatars.githubusercontent.com/u/129203?s=64)](https://github.com/jmm) | [![Sebastian McKenzie](https://avatars.githubusercontent.com/u/853712?s=64)](https://github.com/kittens) (Creator) |

4
codecov.yml Normal file
View File

@ -0,0 +1,4 @@
coverage:
parsers:
javascript:
enable_partials: yes

View File

@ -1,4 +1,5 @@
{ {
"name": "babel",
"private": true, "private": true,
"license": "MIT", "license": "MIT",
"scripts": { "scripts": {
@ -44,6 +45,10 @@
"through2": "^2.0.0", "through2": "^2.0.0",
"uglify-js": "^2.4.16" "uglify-js": "^2.4.16"
}, },
"devEngines": {
"node": ">= 0.10 <= 7.x",
"npm": "2.x || 3.x || 4.x"
},
"babel": { "babel": {
"comments": false, "comments": false,
"presets": [ "presets": [

View File

@ -0,0 +1 @@
console.log(process.argv[2]);

View File

@ -0,0 +1,4 @@
{
"args": ["bar", "foo"],
"stdout": "foo"
}

View File

@ -270,7 +270,7 @@ export default class OptionManager {
} }
const presetFactory = this.getPresetFactoryForPreset(presetLoc || preset); const presetFactory = this.getPresetFactoryForPreset(presetLoc || preset);
preset = presetFactory(context, options); preset = presetFactory(context, options, { dirname });
if (onResolve) onResolve(preset, presetLoc); if (onResolve) onResolve(preset, presetLoc);
} catch (e) { } catch (e) {

View File

@ -1,7 +1,10 @@
module.exports = function () { module.exports = function (context, options, fileContext) {
return { if (/resolve-addons-relative-to-file$/.test(fileContext.dirname)) {
plugins: [plugin], return {
plugins: [plugin],
};
} }
return {};
}; };
function plugin () { function plugin () {

View File

@ -89,7 +89,6 @@ const buildForXStatement = function (op) {
this.space(); this.space();
} }
this.token("("); this.token("(");
this.print(node.left, node); this.print(node.left, node);
this.space(); this.space();
this.word(op); this.word(op);

View File

@ -46,6 +46,10 @@ export function ObjectExpression(node: Object, parent: Object, printStack: Array
return isFirstInStatement(printStack, { considerArrow: true }); return isFirstInStatement(printStack, { considerArrow: true });
} }
export function DoExpression(node: Object, parent: Object, printStack: Array<Object>): boolean {
return isFirstInStatement(printStack);
}
export function Binary(node: Object, parent: Object): boolean { export function Binary(node: Object, parent: Object): boolean {
if ((t.isCallExpression(parent) || t.isNewExpression(parent)) && parent.callee === node) { if ((t.isCallExpression(parent) || t.isNewExpression(parent)) && parent.callee === node) {
return true; return true;

View File

@ -0,0 +1,3 @@
(do {
foo;
});

View File

@ -0,0 +1,3 @@
(do {
foo;
});

View File

@ -13,7 +13,7 @@ var o = { a, b, c };
**Out** **Out**
```js ```js
var o = { a: a, b: b, c:c }; var o = { a: a, b: b, c: c };
``` ```
**In** **In**

View File

@ -11,7 +11,7 @@ var a = ['a', 'b', 'c'];
var b = [...a, 'foo']; var b = [...a, 'foo'];
var c = { foo: 'bar', baz: 42 }; var c = { foo: 'bar', baz: 42 };
var d = {...o, a: 2}; var d = {...c, a: 2};
``` ```
**Out** **Out**
@ -33,7 +33,7 @@ var a = [ 'a', 'b', 'c' ];
var b = [].concat(a, [ 'foo' ]); var b = [].concat(a, [ 'foo' ]);
var c = { foo: 'bar', baz: 42 }; var c = { foo: 'bar', baz: 42 };
var d = _extends({}, o, { a: 2 }); var d = _extends({}, c, { a: 2 });
``` ```
## Installation ## Installation

View File

@ -6,7 +6,7 @@
**In** **In**
```js ```jsx
const Hr = () => { const Hr = () => {
return <hr className="hr" />; return <hr className="hr" />;
}; };
@ -14,7 +14,7 @@ const Hr = () => {
**Out** **Out**
```js ```jsx
const _ref = <hr className="hr" />; const _ref = <hr className="hr" />;
const Hr = () => { const Hr = () => {
@ -26,13 +26,13 @@ const Hr = () => {
- **Spread Operator** - **Spread Operator**
```js ```jsx
<div {...foobar} /> <div {...foobar} />
``` ```
- **Refs** - **Refs**
```js ```jsx
<div ref="foobar" /> <div ref="foobar" />
<div ref={node => this.node = node} /> <div ref={node => this.node = node} />
``` ```

View File

@ -1,6 +1,6 @@
{ {
"name": "babel-runtime", "name": "babel-runtime",
"version": "6.22.0", "version": "6.23.0",
"description": "babel selfContained runtime", "description": "babel selfContained runtime",
"license": "MIT", "license": "MIT",
"repository": "https://github.com/babel/babel/tree/master/packages/babel-runtime", "repository": "https://github.com/babel/babel/tree/master/packages/babel-runtime",
@ -11,6 +11,6 @@
}, },
"devDependencies": { "devDependencies": {
"babel-helpers": "^6.22.0", "babel-helpers": "^6.22.0",
"babel-plugin-transform-runtime": "^6.22.0" "babel-plugin-transform-runtime": "^6.23.0"
} }
} }

View File

@ -14,6 +14,19 @@ function getPath(code) {
return path; return path;
} }
function getIdentifierPath(code) {
const ast = parse(code);
let nodePath;
traverse(ast, {
Identifier: function(path) {
nodePath = path;
path.stop();
}
});
return nodePath;
}
describe("scope", function () { describe("scope", function () {
describe("binding paths", function () { describe("binding paths", function () {
it("function declaration id", function () { it("function declaration id", function () {
@ -67,5 +80,13 @@ describe("scope", function () {
_foo2: { } _foo2: { }
`).scope.generateUid("foo"), "_foo3"); `).scope.generateUid("foo"), "_foo3");
}); });
it("reference paths", function() {
const path = getIdentifierPath("function square(n) { return n * n}");
const referencePaths = path.context.scope.bindings.n.referencePaths;
assert.equal(referencePaths.length, 2);
assert.deepEqual(referencePaths[0].node.loc.start, { line: 1, column:28 });
assert.deepEqual(referencePaths[1].node.loc.start, { line: 1, column:32 });
});
}); });
}); });