add readme entry for for-of assumeArray, use it (#6942)

This commit is contained in:
Henry Zhu 2017-11-30 18:40:23 -05:00 committed by Brian Ng
parent a992d06c41
commit 5761eb0bb4
3 changed files with 14 additions and 4 deletions

View File

@ -59,11 +59,12 @@ Without options:
With options:
```json
```js
{
"plugins": [
["@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
[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
If a basic array is used, Babel will compile the for-of loop down to a regular for loop.

View File

@ -24,7 +24,6 @@
},
"devDependencies": {
"@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",
"charcodes": "0.0.10",
"rollup": "^0.50.0",

View File

@ -24,7 +24,10 @@ export default {
],
"@babel/flow",
],
plugins: ["transform-charcodes", "transform-for-of-as-array"],
plugins: [
"transform-charcodes",
["@babel/transform-for-of", { assumeArray: true }],
],
}),
nodeResolve(),
],