diff --git a/packages/babel-plugin-transform-for-of/README.md b/packages/babel-plugin-transform-for-of/README.md index 0241c8722a..4a8c5263fe 100644 --- a/packages/babel-plugin-transform-for-of/README.md +++ b/packages/babel-plugin-transform-for-of/README.md @@ -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. diff --git a/packages/babylon/package.json b/packages/babylon/package.json index 07856635c1..cd2188b488 100644 --- a/packages/babylon/package.json +++ b/packages/babylon/package.json @@ -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", diff --git a/packages/babylon/rollup.config.js b/packages/babylon/rollup.config.js index f627c6a860..2c8f7d757c 100644 --- a/packages/babylon/rollup.config.js +++ b/packages/babylon/rollup.config.js @@ -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(), ],