Merge pull request #5380 from babel/extra-do + 6.x commits

This commit is contained in:
Henry Zhu
2017-02-25 18:48:27 -05:00
committed by GitHub
19 changed files with 99 additions and 44 deletions

View File

@@ -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;
});
```

View File

@@ -45,12 +45,6 @@ export function ExportAllDeclaration(node: Object) {
this.word("export");
this.space();
this.token("*");
if (node.exported) {
this.space();
this.word("as");
this.space();
this.print(node.exported, node);
}
this.space();
this.word("from");
this.space();

View File

@@ -0,0 +1,9 @@
(do {});
let a = do {
if (x > 10) {
'big';
} else {
'small';
}
};

View File

@@ -0,0 +1,9 @@
(do {});
let a = do {
if (x > 10) {
'big';
} else {
'small';
}
};

View File

@@ -0,0 +1,2 @@
foo ||bar;
(x => x)|| bar;

View File

@@ -0,0 +1,2 @@
foo || bar;
(x => x) || bar;

View File

@@ -34,13 +34,17 @@ npm install --save-dev babel-plugin-transform-async-to-module-method
**.babelrc**
```js
// without options
Without options:
```json
{
"plugins": ["transform-async-to-module-method"]
}
```
// with options
With options:
```json
{
"plugins": [
["transform-async-to-module-method", {

View File

@@ -57,13 +57,17 @@ npm install --save-dev babel-plugin-transform-es2015-computed-properties
**.babelrc**
```js
// without options
Without options:
```json
{
"plugins": ["transform-es2015-computed-properties"]
}
```
// with options
With options:
```json
{
"plugins": [
["transform-es2015-computed-properties", {

View File

@@ -49,13 +49,17 @@ npm install --save-dev babel-plugin-transform-es2015-for-of
**.babelrc**
Without options:
```js
// without options
{
"plugins": ["transform-es2015-for-of"]
}
```
// with options
With options:
```json
{
"plugins": [
["transform-es2015-for-of", {

View File

@@ -35,13 +35,17 @@ npm install --save-dev babel-plugin-transform-es2015-modules-systemjs
**.babelrc**
```javascript
// without options
Without options:
```json
{
"plugins": ["transform-es2015-modules-systemjs"]
}
```
// with options
With options:
```json
{
"plugins": [
["transform-es2015-modules-systemjs", {

View File

@@ -48,13 +48,17 @@ npm install --save-dev babel-plugin-transform-es2015-spread
**.babelrc**
```js
// without options
Without options:
```json
{
"plugins": ["transform-es2015-spread"]
}
```
// with options
With options:
```json
{
"plugins": [
["transform-es2015-spread", {

View File

@@ -28,13 +28,17 @@ npm install --save-dev babel-plugin-transform-es2015-template-literals
**.babelrc**
```js
// without options
Without options:
```json
{
"plugins": ["transform-es2015-template-literals"]
}
```
// with options
With options:
```json
{
"plugins": [
["transform-es2015-template-literals", {

View File

@@ -41,13 +41,15 @@ This plugin will use babel's `extends` helper, which will polyfill `Object.assig
* `useBuiltIns` - Do not use Babel's helper's and just transform to use the built-in method (Disabled by default).
```js
```json
{
"plugins": [
["transform-object-rest-spread", { "useBuiltIns": true }]
]
}
```
```js
// source
z = { x, ...y };
// compiled

View File

@@ -64,12 +64,17 @@ npm install --save-dev babel-plugin-transform-react-jsx
**.babelrc**
```js
// without options
Without options:
```json
{
"plugins": ["transform-react-jsx"]
}
// with options
```
With options:
```json
{
"plugins": [
["transform-react-jsx", {

View File

@@ -40,13 +40,17 @@ The transformation plugin is typically used only in development, but the runtime
Add the following line to your `.babelrc` file:
```js
// without options
Without options:
```json
{
"plugins": ["transform-runtime"]
}
```
// with options
With options:
```json
{
"plugins": [
["transform-runtime", {

View File

@@ -34,13 +34,17 @@ npm install --save-dev babel-plugin-transform-strict-mode
**.babelrc**
```js
// without options
Without options:
```json
{
"plugins": ["transform-strict-mode"]
}
```
// with options
With options:
```json
{
"plugins": [
["transform-strict-mode", {

View File

@@ -42,7 +42,7 @@ require("babel-core").transform("code", {
Toggles including plugins from the [es2015 preset](https://babeljs.io/docs/plugins/preset-es2015/).
```js
```json
{
"presets": [
["latest", {
@@ -54,7 +54,7 @@ Toggles including plugins from the [es2015 preset](https://babeljs.io/docs/plugi
You can also pass options down to the `es2015` preset.
```js
```json
{
"presets": [
["latest", {

View File

@@ -53,7 +53,7 @@ require("babel-register")({
// Ignore can also be specified as a function.
ignore: function(filename) {
if (filename === '/path/to/es6-file.js') {
if (filename === "/path/to/es6-file.js") {
return false;
} else {
return true;

View File

@@ -13,24 +13,24 @@ npm install --save-dev babel-template
## Usage
```js
import template from 'babel-template';
import generate from 'babel-generator';
import * as t from 'babel-types';
import template from "babel-template";
import generate from "babel-generator";
import * as t from "babel-types";
const buildRequire = template(`
var IMPORT_NAME = require(SOURCE);
`);
const ast = buildRequire({
IMPORT_NAME: t.identifier('myModule'),
SOURCE: t.stringLiteral('my-module')
IMPORT_NAME: t.identifier("myModule"),
SOURCE: t.stringLiteral("my-module")
});
console.log(generate(ast).code);
```
```js
var myModule = require('my-module');
const myModule = require("my-module");
```
## API