Skip to content

Commit

Permalink
Merge branch 'master' of github.com:hulkish/babel
Browse files Browse the repository at this point in the history
* 'master' of github.com:hulkish/babel: (37 commits)
  Increase the code coverage for traverse evaluation (babel#5363)
  Improve options documentation for `babel-plugin-transform-runtime` babel#5401
  [doc] Fix: comments in usage w/ options babel#5400
  document cache option for babel-register babel#5440
  Update coffescript/register reference link address babel#5475
  Update babel-generator's README babel#5517
  Improve example of babel-plugin-transform-es2015-arrow-functions babel#5573
  Remove incorrect docs. babel#5580
  Update transform-es2015-modules-commonjs doc babel#5588
  Fix replacing function declaration in export default (fixes babel#4468) (babel#5456)
  Fix a typo: occurences -> occurrences (babel#5575)
  Fix changelog [skip ci]
  Treat "await" as an invalid identifier (babel#4954)
  Removes unused lodash dependency from babel-helper-builder-react-jsx (babel#5486)
  docs: [skip ci] update documentation
  v6.24.0
  changelog for 6.24.0 [skip ci] (babel#5452)
  Keep parentheses for logical expression when in await expression (fix babel#5428) (babel#5433) (babel#5453)
  Use absolute paths in Babel's CONTRIBUTING.md (babel#5431)
  Fixed broken links in README.md [skip ci] (babel#5449)
  ...
  • Loading branch information
hulkish committed May 2, 2017
2 parents 13b125d + 0284fd4 commit 35e5d76
Show file tree
Hide file tree
Showing 78 changed files with 691 additions and 288 deletions.
101 changes: 101 additions & 0 deletions CHANGELOG.md
Expand Up @@ -13,6 +13,107 @@ _Note: Gaps between patch versions are faulty, broken or test releases._

See [CHANGELOG - 6to5](CHANGELOG-6to5.md) for the pre-4.0.0 version changelog.

## 6.24.0 (2017-03-13)

A quick release for 2 features:

- Thanks to @rwjblue, there is now a `noInterop` option for our `es2015-modules` transform to remove the `interopRequireDefault` and `interopRequireWildcard` helpers.

Input

```js
import foo from "foo";
foo;
```

Regular Output

```js
var _foo = require("foo");
var _foo2 = _interopRequireDefault(_foo);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
_foo2.default;
```

Output with option `noInterop`

```js
"use strict";
var _foo = require("foo");
(0, _foo.default)();
```

> This also helps [ember-cli migrate to Babel 6](https://github.com/ember-cli/ember-cli/pull/6828).

- @izaakschroeder has added `dirname` to the preset constructor which presets can use to resolve things relative to files.

Example usage of `fileContext.dirname` in a preset

```js
module.exports = function preset (context, options, fileContext) {
if (/resolve-addons-relative-to-file$/.test(fileContext.dirname)) {
return {
plugins: ['plugin-here'],
};
}
return {};
};
```

> This will help out with reusing a [`browserslist` file for babel-preset-env](https://github.com/babel/babel-preset-env/issues/26) and for plugins like https://github.com/tleunen/babel-plugin-module-resolver.

#### :rocket: New Feature
* `babel-plugin-transform-es2015-modules-amd`, `babel-plugin-transform-es2015-modules-commonjs`
* [#5427](https://github.com/babel/babel/pull/5427) Backport `noInterop` flag for modules to 6.x. ([@rwjblue](https://github.com/rwjblue))
* `babel-core`
* [#4834](https://github.com/babel/babel/pull/4834) Pass `dirname` as extra metadata to preset constructor. ([@izaakschroeder](https://github.com/izaakschroeder))

#### :bug: Bug Fix
* `babel-generator`
* [#5453](https://github.com/babel/babel/pull/5453) Keep parentheses for logical expression when in await expression. ([@aaronang](https://github.com/aaronang))
* [#5339](https://github.com/babel/babel/pull/5339) Wrap some generated do expressions in parens. ([@zjmiller](https://github.com/zjmiller))
* `babel-generator`, `babel-plugin-transform-object-rest-spread`
* [#5322](https://github.com/babel/babel/pull/5322) Fix for-await printing. ([@danez](https://github.com/danez))

#### :memo: Documentation

* [#5449](https://github.com/babel/babel/pull/5449) Fixed broken links in README.md [skip-ci]. ([@sethbergman](https://github.com/sethbergman))
* [#5409](https://github.com/babel/babel/pull/5409) Fix transform-object-rest-spread README. ([@existentialism](https://github.com/existentialism))
* [#5379](https://github.com/babel/babel/pull/5379) Lint code snippets in READMEs. ([@xtuc](https://github.com/xtuc))
* [#5334](https://github.com/babel/babel/pull/5334) Shorthand properties examples. ([@bhoule](https://github.com/bhoule))
* [#5329](https://github.com/babel/babel/pull/5329) Update CONTRIBUTING.md with respect to coverage check [skip ci]. ([@zjmiller](https://github.com/zjmiller))

#### :house: Internal
* Other
* [#5338](https://github.com/babel/babel/pull/5338) Improve babel-generator's code coverage. ([@alxpy](https://github.com/alxpy))
* [#5336](https://github.com/babel/babel/pull/5336) Enable codecov partial coverage. ([@danez](https://github.com/danez))
* [#5350](https://github.com/babel/babel/pull/5350) Remove redundant NODE_ENV=test in Makefile. ([@aaronang](https://github.com/aaronang))
* [#5312](https://github.com/babel/babel/pull/5312) [skip ci] Add devEngines to package.json. ([@yavorsky](https://github.com/yavorsky))
* `babel-cli`
* [#5342](https://github.com/babel/babel/pull/5342) Add test for passing arguments to babel-node (#5163). ([@outsideris](https://github.com/outsideris))
* `babel-traverse`
* [#5296](https://github.com/babel/babel/pull/5296) Add test for reference paths. ([@jasonLaster](https://github.com/jasonLaster))

#### Committers: 14
- Aaron Ang ([aaronang](https://github.com/aaronang))
- Alex Kuzmenko ([alxpy](https://github.com/alxpy))
- Artem Gurzhii ([artemgurzhii](https://github.com/artemgurzhii))
- Artem Yavorsky ([yavorsky](https://github.com/yavorsky))
- Brendan Houle ([bhoule](https://github.com/bhoule))
- Brian Ng ([existentialism](https://github.com/existentialism))
- Daniel Tschinder ([danez](https://github.com/danez))
- Izaak Schroeder ([izaakschroeder](https://github.com/izaakschroeder))
- Jason Laster ([jasonLaster](https://github.com/jasonLaster))
- JeongHoon Byun (aka Outsider) ([outsideris](https://github.com/outsideris))
- Robert Jackson ([rwjblue](https://github.com/rwjblue))
- Seth Bergman ([sethbergman](https://github.com/sethbergman))
- Sven SAULEAU ([xtuc](https://github.com/xtuc))
- Zachary Miller ([zjmiller](https://github.com/zjmiller))

## 6.23.1 (2017-02-13)

Regression: Revert https://github.com/babel/babel/pull/5306 since it made a backwards-incompatible change.

## 6.23.0 (2017-02-13)

#### :rocket: New Feature
Expand Down
80 changes: 60 additions & 20 deletions CONTRIBUTING.md
Expand Up @@ -2,13 +2,15 @@

----

<p align="center">
<p align="center" class="toc">
<strong><a href="#setup">Setup</a></strong>
|
<strong><a href="#running-lintingtests">Running linting/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>
</p>

Expand All @@ -25,7 +27,7 @@ Contributions are always welcome, no matter how large or small.

- If you aren't just making a documentation change, you'll probably want to learn a bit about a few topics.
- [ASTs](https://en.wikipedia.org/wiki/Abstract_syntax_tree) (Abstract Syntax Tree): The Babel AST [spec](https://github.com/babel/babylon/blob/master/ast/spec.md) is a bit different from [ESTree](https://github.com/estree/estree). The differences are listed [here](https://github.com/babel/babylon#output).
- This repository's [`/doc`](/doc) directory for notes on Babel's internals
- This repository's [`/doc`](https://github.com/babel/babel/tree/master/doc) directory for notes on Babel's internals
- Check out [the Babel Plugin Handbook](https://github.com/thejameskyle/babel-handbook/blob/master/translations/en/plugin-handbook.md#babel-plugin-handbook) - core plugins are written the same way as any other plugin!
- Check out [AST Explorer](http://astexplorer.net/#/scUfOmVOG5) to learn more about ASTs or make your own plugin in the browser
- When you feel ready to finally jump into the babel source code a good start is to look out for issues which are labeled with [help-wanted](https://github.com/babel/babel/issues?q=is%3Aissue+is%3Aopen+label%3A%22help+wanted%22) and/or [beginner-friendly](https://github.com/babel/babel/issues?q=is%3Aissue+is%3Aopen+label%3A%22beginner-friendly%22).
Expand All @@ -42,7 +44,7 @@ Babel is built for node 0.10 and up but we develop using node 6. Make sure you a

You can check this with `node -v` and `npm -v`.

#### Setup
### Setup

```sh
$ git clone https://github.com/babel/babel
Expand Down Expand Up @@ -72,7 +74,7 @@ If you wish to build a copy of Babel for distribution, then run:
$ make build-dist
```

#### Running linting/tests
### Running linting/tests

You can run lint via:

Expand Down Expand Up @@ -103,7 +105,7 @@ $ make test-only

Most likely you'll want to focus in on a specific issue.

To run tests for a specific package in [packages](/packages), you can use the `TEST_ONLY` environment variable:
To run tests for a specific package in [packages](https://github.com/babel/babel/tree/master/packages), you can use the `TEST_ONLY` environment variable:

```sh
$ TEST_ONLY=babel-cli make test
Expand All @@ -124,30 +126,31 @@ $ TEST_DEBUG=true make test
To test the code coverage, use:

```sh
$ BABEL_ENV=cov make build
$ ./scripts/test-cov.sh
```

#### Writing tests
### Writing tests

Most packages in [`/packages`](/packages) have a `test` folder, however some tests might be in other packages or in [`/packages/babel-core`](/packages/babel-core/test/fixtures).
Most packages in [`/packages`](https://github.com/babel/babel/tree/master/packages) have a `test` folder, however some tests might be in other packages or in [`/packages/babel-core`](https://github.com/babel/babel/tree/master/packages/babel-core/test/fixtures).

##### `babel-plugin-x`
#### `babel-plugin-x`

All the Babel plugins (and other packages) that have a `/test/fixtures` are written in a similar way.

For example, in [`babel-plugin-transform-exponentiation-operator/test`](/packages/babel-plugin-transform-exponentiation-operator/test):
For example, in [`babel-plugin-transform-exponentiation-operator/test`](https://github.com/babel/babel/tree/master/packages/babel-plugin-transform-exponentiation-operator/test):

- There is an `index.js` file. It imports our [test helper](/packages/babel-helper-plugin-test-runner). (You don't have to worry about this).
- There can be multiple folders under [`/fixtures`](/packages/babel-plugin-transform-exponentiation-operator/test/fixtures)
- There is an [`options.json`](/packages/babel-plugin-transform-exponentiation-operator/test/fixtures/exponentian-operator/options.json) file whose function is similar to a `.babelrc` file, allowing you to pass in the plugins and settings you need for your tests.
- There is an `index.js` file. It imports our [test helper](https://github.com/babel/babel/tree/master/packages/babel-helper-plugin-test-runner). (You don't have to worry about this).
- There can be multiple folders under [`/fixtures`](https://github.com/babel/babel/tree/master/packages/babel-plugin-transform-exponentiation-operator/test/fixtures)
- There is an [`options.json`](https://github.com/babel/babel/blob/master/packages/babel-plugin-transform-exponentiation-operator/test/fixtures/exponentian-operator/options.json) file whose function is similar to a `.babelrc` file, allowing you to pass in the plugins and settings you need for your tests.
- For this test, we only need the relevant plugin, so it's just `{ "plugins": ["transform-exponentiation-operator"] }`.
- If necessary, you can have an `options.json` with different options in each subfolder.

- In each subfolder, you can organize your directory structure by categories of tests. (Example: these folders can be named after the feature you are testing or can reference the issue number they fix)
- Generally, there are two kinds of tests for plugins
- The first is a simple test of the input and output produced by running Babel on some code. We do this by creating an [`actual.js`](packages/babel-plugin-transform-exponentiation-operator/test/fixtures/exponentian-operator/binary/actual.js) file and an [`expected.js`](/packages/babel-plugin-transform-exponentiation-operator/test/fixtures/exponentian-operator/binary/expected.js) file.
- The first is a simple test of the input and output produced by running Babel on some code. We do this by creating an [`actual.js`](https://github.com/babel/babel/blob/master/packages/babel-plugin-transform-exponentiation-operator/test/fixtures/exponentian-operator/binary/actual.js) file and an [`expected.js`](https://github.com/babel/babel/blob/master/packages/babel-plugin-transform-exponentiation-operator/test/fixtures/exponentian-operator/binary/expected.js) file.
- If you need to expect an error, you can ignore creating the `expected.js` file and pass a new `throws` key to the `options.json` that contains the error string that is created.
- The second and preferred type is a test that actually evaluates the produced code and asserts that certain properties are true or false. We do this by creating an [`exec.js`](/packages/babel-plugin-transform-exponentiation-operator/test/fixtures/exponentian-operator/comprehensive/exec.js) file.
- The second and preferred type is a test that actually evaluates the produced code and asserts that certain properties are true or false. We do this by creating an [`exec.js`](https://github.com/babel/babel/blob/master/packages/babel-plugin-transform-exponentiation-operator/test/fixtures/exponentian-operator/comprehensive/exec.js) file.

In an actual/expected test, you simply write out the code you want transformed in `actual.js`.

Expand Down Expand Up @@ -180,7 +183,7 @@ If you need to check for an error that is thrown you can add to the `options.jso
}
```

##### Bootstrapping expected output
#### Bootstrapping expected output

For both `babel-plugin-x` and `babylon`, you can easily generate an `expected.js`/`expected.json` automatically by just providing `actual.js` and running the tests as you usually would.

Expand All @@ -196,9 +199,46 @@ For both `babel-plugin-x` and `babylon`, you can easily generate an `expected.js
- expected.json (will be generated if not created)
```

#### Internals
### 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
- 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))
- 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 assumptions ([doc/design/compiler-assumptions.md](./doc/design/compiler-assumptions.md))
- Versioning ([doc/design/versioning.md](https://github.com/babel/babel/blob/master/doc/design/versioning.md)
- Monorepo ([doc/design/monorepo.md](https://github.com/babel/babel/blob/master/doc/design/monorepo.md))
- Compiler environment support ([doc/design/compiler-environment-support.md](https://github.com/babel/babel/blob/master/doc/design/compiler-environment-support.md))
- Compiler assumptions ([doc/design/compiler-assumptions.md](https://github.com/babel/babel/blob/master/doc/design/compiler-assumptions.md))
4 changes: 2 additions & 2 deletions Makefile
Expand Up @@ -49,11 +49,11 @@ test-only:
test: lint test-only

test-ci:
NODE_ENV=test make bootstrap
make bootstrap
make test-only

test-ci-coverage:
NODE_ENV=test BABEL_ENV=cov make bootstrap
BABEL_ENV=cov make bootstrap
./scripts/test-cov.sh
./node_modules/.bin/codecov -f coverage/coverage-final.json

Expand Down
12 changes: 10 additions & 2 deletions README.md
Expand Up @@ -25,13 +25,13 @@ When your supported environments don't support certain features natively, it wil

```js
// ES2015 arrow function
[1,2,3].map(n => n + 1);
[1, 2, 3].map((n) => n + 1);
```

**Out**

```js
[1,2,3].map(function(n) {
[1, 2, 3].map(function(n) {
return n + 1;
});
```
Expand Down Expand Up @@ -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://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

[![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) |
Expand Down
4 changes: 4 additions & 0 deletions codecov.yml
@@ -0,0 +1,4 @@
coverage:
parsers:
javascript:
enable_partials: yes
2 changes: 1 addition & 1 deletion lerna.json
@@ -1,6 +1,6 @@
{
"lerna": "2.0.0-beta.23",
"version": "6.23.1",
"version": "6.24.0",
"changelog": {
"repo": "babel/babel",
"labels": {
Expand Down
4 changes: 4 additions & 0 deletions package.json
Expand Up @@ -47,6 +47,10 @@
"through2": "^2.0.0",
"uglify-js": "^2.4.16"
},
"devEngines": {
"node": ">= 0.10 <= 7.x",
"npm": "2.x || 3.x || 4.x"
},
"babel": {
"comments": false,
"presets": [
Expand Down
6 changes: 3 additions & 3 deletions packages/babel-cli/package.json
@@ -1,6 +1,6 @@
{
"name": "babel-cli",
"version": "6.23.0",
"version": "6.24.0",
"description": "Babel command line.",
"author": "Sebastian McKenzie <sebmck@gmail.com>",
"homepage": "https://babeljs.io/",
Expand All @@ -16,8 +16,8 @@
"compiler"
],
"dependencies": {
"babel-core": "^6.23.0",
"babel-register": "^6.23.0",
"babel-core": "^6.24.0",
"babel-register": "^6.24.0",
"babel-polyfill": "^6.23.0",
"babel-runtime": "^6.22.0",
"commander": "^2.8.1",
Expand Down
@@ -0,0 +1 @@
console.log(process.argv[2]);
@@ -0,0 +1,4 @@
{
"args": ["bar", "foo"],
"stdout": "foo"
}

0 comments on commit 35e5d76

Please sign in to comment.