Socket
Socket
Sign inDemoInstall

@babel/plugin-transform-for-of

Package Overview
Dependencies
Maintainers
4
Versions
86
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@babel/plugin-transform-for-of - npm Package Compare versions

Comparing version 7.0.0-beta.32 to 7.0.0-beta.33

47

lib/index.js

@@ -9,3 +9,48 @@ "use strict";

function _default(api, options) {
var loose = options.loose;
var loose = options.loose,
assumeArray = options.assumeArray;
if (loose === true && assumeArray === true) {
throw new Error("The loose and assumeArray options cannot be used together in @babel/plugin-transform-for-of");
}
if (assumeArray) {
return {
visitor: {
ForOfStatement: function ForOfStatement(path) {
var scope = path.scope;
var _path$node = path.node,
left = _path$node.left,
right = _path$node.right,
body = _path$node.body;
var i = scope.generateUidIdentifier("i");
var array = scope.maybeGenerateMemoised(right, true);
var inits = [_core.types.variableDeclarator(i, _core.types.numericLiteral(0))];
if (array) {
inits.push(_core.types.variableDeclarator(array, right));
} else {
array = right;
}
var item = _core.types.memberExpression(array, _core.types.clone(i), true);
var assignment;
if (_core.types.isVariableDeclaration(left)) {
assignment = left;
assignment.declarations[0].init = item;
} else {
assignment = _core.types.expressionStatement(_core.types.assignmentExpression("=", left, item));
}
var block = _core.types.toBlock(body);
block.body.unshift(assignment);
path.replaceWith(_core.types.forStatement(_core.types.variableDeclaration("let", inits), _core.types.binaryExpression("<", _core.types.clone(i), _core.types.memberExpression(_core.types.clone(array), _core.types.identifier("length"))), _core.types.updateExpression("++", _core.types.clone(i)), block));
}
}
};
}
var pushComputedProps = loose ? pushComputedPropsLoose : pushComputedPropsSpec;

@@ -12,0 +57,0 @@ var buildForOfArray = (0, _core.template)("\n for (var KEY = 0; KEY < ARR.length; KEY++) BODY;\n ");

8

package.json
{
"name": "@babel/plugin-transform-for-of",
"version": "7.0.0-beta.32",
"version": "7.0.0-beta.33",
"description": "Compile ES2015 for...of to ES5",

@@ -12,8 +12,8 @@ "repository": "https://github.com/babel/babel/tree/master/packages/babel-plugin-transform-for-of",

"peerDependencies": {
"@babel/core": "7.0.0-beta.32"
"@babel/core": "7.0.0-beta.33"
},
"devDependencies": {
"@babel/core": "7.0.0-beta.32",
"@babel/helper-plugin-test-runner": "7.0.0-beta.32"
"@babel/core": "7.0.0-beta.33",
"@babel/helper-plugin-test-runner": "7.0.0-beta.33"
}
}

@@ -56,3 +56,3 @@ # @babel/plugin-transform-for-of

{
"plugins": ["@babel/transform-for-of"]
"plugins": ["@babel/plugin-transform-for-of"]
}

@@ -63,7 +63,8 @@ ```

```json
```js
{
"plugins": [
["@babel/transform-for-of", {
"loose": true
["@babel/plugin-transform-for-of", {
"loose": true, // defaults to false
"assumeArray": true // defaults to false
}]

@@ -77,3 +78,3 @@ ]

```sh
babel --plugins @babel/transform-for-of script.js
babel --plugins @babel/plugin-transform-for-of script.js
```

@@ -85,3 +86,3 @@

require("@babel/core").transform("code", {
plugins: ["@babel/transform-for-of"]
plugins: ["@babel/plugin-transform-for-of"]
});

@@ -133,2 +134,9 @@ ```

### `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

@@ -135,0 +143,0 @@

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc