add readme entry for for-of assumeArray, use it (#6942)
This commit is contained in:
parent
a992d06c41
commit
5761eb0bb4
@ -59,11 +59,12 @@ Without options:
|
|||||||
|
|
||||||
With options:
|
With options:
|
||||||
|
|
||||||
```json
|
```js
|
||||||
{
|
{
|
||||||
"plugins": [
|
"plugins": [
|
||||||
["@babel/plugin-transform-for-of", {
|
["@babel/plugin-transform-for-of", {
|
||||||
"loose": true
|
"loose": true, // defaults to false
|
||||||
|
"assumeArray": true // defaults to false
|
||||||
}]
|
}]
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
@ -126,6 +127,13 @@ In loose mode an iterator's `return` method will not be called on abrupt complet
|
|||||||
Please see [google/traceur-compiler#1773](https://github.com/google/traceur-compiler/issues/1773) and
|
Please see [google/traceur-compiler#1773](https://github.com/google/traceur-compiler/issues/1773) and
|
||||||
[babel/babel#838](https://github.com/babel/babel/issues/838) for more information.
|
[babel/babel#838](https://github.com/babel/babel/issues/838) for more information.
|
||||||
|
|
||||||
|
### `assumeArray`
|
||||||
|
`boolean`, defaults to `false`
|
||||||
|
|
||||||
|
This will apply the optimization shown below to all for-of loops by assuming that _all_ loops are arrays.
|
||||||
|
|
||||||
|
Can be useful when you just want a for-of loop to represent a basic for loop over an array.
|
||||||
|
|
||||||
### Optimization
|
### Optimization
|
||||||
|
|
||||||
If a basic array is used, Babel will compile the for-of loop down to a regular for loop.
|
If a basic array is used, Babel will compile the for-of loop down to a regular for loop.
|
||||||
|
|||||||
@ -24,7 +24,6 @@
|
|||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@babel/helper-fixtures": "7.0.0-beta.32",
|
"@babel/helper-fixtures": "7.0.0-beta.32",
|
||||||
"babel-plugin-transform-for-of-as-array": "1.0.4",
|
|
||||||
"babel-plugin-transform-charcodes": "0.0.10",
|
"babel-plugin-transform-charcodes": "0.0.10",
|
||||||
"charcodes": "0.0.10",
|
"charcodes": "0.0.10",
|
||||||
"rollup": "^0.50.0",
|
"rollup": "^0.50.0",
|
||||||
|
|||||||
@ -24,7 +24,10 @@ export default {
|
|||||||
],
|
],
|
||||||
"@babel/flow",
|
"@babel/flow",
|
||||||
],
|
],
|
||||||
plugins: ["transform-charcodes", "transform-for-of-as-array"],
|
plugins: [
|
||||||
|
"transform-charcodes",
|
||||||
|
["@babel/transform-for-of", { assumeArray: true }],
|
||||||
|
],
|
||||||
}),
|
}),
|
||||||
nodeResolve(),
|
nodeResolve(),
|
||||||
],
|
],
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user