es6-spread
Advanced tools
Comparing version 0.0.5 to 0.0.6
{ | ||
"name": "es6-spread", | ||
"version": "0.0.5", | ||
"version": "0.0.6", | ||
"homepage": "https://github.com/square/es6-spread", | ||
@@ -5,0 +5,0 @@ "authors": [ |
@@ -115,5 +115,5 @@ /* jshint node:true, undef:true, unused:true */ | ||
arrays.push( | ||
util.callArraySlice( | ||
accumulateIteratorValues( | ||
scope.getGlobalScope(), | ||
element.argument | ||
util.callGetIterator(scope.getGlobalScope(), element.argument) | ||
) | ||
@@ -149,2 +149,88 @@ ); | ||
/** | ||
* var accumulateIteratorValues = function(iterator) { | ||
* var result = []; | ||
* for (var $__0 = iterator, $__1; !($__1 = $__0.next()).done; ) { | ||
* result.push($__1.value); | ||
* } | ||
* return result; | ||
* }; | ||
* | ||
* @private | ||
* @param {ast-types.Scope} | ||
* @param {ast-types.Expression} | ||
*/ | ||
function accumulateIteratorValues(scope, iterator) { | ||
var accumulate = util.injectShared( | ||
scope, | ||
'accumulateIteratorValues', | ||
function() { | ||
var iteratorId = b.identifier('iterator'); | ||
var nextId = b.identifier('next'); | ||
var resultId = b.identifier('result'); | ||
var itemId = b.identifier('item'); | ||
var doneId = b.identifier('done'); | ||
var valueId = b.identifier('value'); | ||
return b.functionExpression( | ||
null, | ||
[iteratorId], | ||
b.blockStatement([ | ||
b.variableDeclaration( | ||
'var', | ||
[b.variableDeclarator( | ||
resultId, | ||
b.arrayExpression([]) | ||
)] | ||
), | ||
b.forStatement( | ||
b.variableDeclaration( | ||
'var', | ||
[b.variableDeclarator(itemId, null)] | ||
), | ||
b.unaryExpression( | ||
'!', | ||
b.memberExpression( | ||
b.assignmentExpression( | ||
'=', | ||
itemId, | ||
b.callExpression( | ||
b.memberExpression( | ||
iteratorId, | ||
nextId, | ||
false | ||
), | ||
[] | ||
) | ||
), | ||
doneId, | ||
false | ||
) | ||
), | ||
null, | ||
b.expressionStatement(b.callExpression( | ||
b.memberExpression( | ||
resultId, | ||
b.identifier('push'), | ||
false | ||
), | ||
[b.memberExpression( | ||
itemId, | ||
valueId, | ||
false | ||
)] | ||
)) | ||
), | ||
b.returnStatement(resultId) | ||
]) | ||
); | ||
} | ||
); | ||
return b.callExpression( | ||
accumulate, | ||
[iterator] | ||
); | ||
} | ||
/** | ||
* Transform an Esprima AST generated from ES6 by replacing all spread elements | ||
@@ -151,0 +237,0 @@ * with an equivalent approach in ES5. |
{ | ||
"name": "es6-spread", | ||
"version": "0.0.5", | ||
"version": "0.0.6", | ||
"description": "ES6 spread compiled to ES5.", | ||
@@ -18,3 +18,3 @@ "main": "lib/index.js", | ||
"through": "~2.3.4", | ||
"ast-util": "^0.0.5" | ||
"ast-util": "^0.1.0" | ||
}, | ||
@@ -21,0 +21,0 @@ "devDependencies": { |
# es6-spread | ||
Compiles JavaScript written using ES6 spread syntax to use the equivalent ES5 | ||
code. For example, this: | ||
code. For example, this spreads `args` out as positional arguments to `f`: | ||
@@ -12,10 +12,2 @@ ```js | ||
compiles to this: | ||
```js | ||
function f(x, y, z) { } | ||
var args = [0, 1, 2]; | ||
f.apply(null, args); | ||
``` | ||
This project is part of [esnext][esnext], a project to compile the syntax of | ||
@@ -22,0 +14,0 @@ the next version of JavaScript to today's JavaScript environments. |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
15155
16
410
87
+ Addedast-util@0.1.2(transitive)
- Removedast-util@0.0.5(transitive)
Updatedast-util@^0.1.0