Comparing version 0.2.3 to 0.3.0
194
lib/index.js
@@ -15,4 +15,2 @@ var esprima = require('esprima'); | ||
function visitForOfStatement(node) { | ||
var arrayIterator = injectArrayIterator(this.scope.getGlobalScope()); | ||
var getIterator = injectGetIterator(this.scope.getGlobalScope(), arrayIterator); | ||
var iterator = util.uniqueIdentifier(this.scope); | ||
@@ -62,5 +60,5 @@ var item = util.uniqueIdentifier(this.scope); | ||
iterator, | ||
b.callExpression( | ||
getIterator, | ||
[node.right] | ||
util.callGetIterator( | ||
this.scope.getGlobalScope(), | ||
node.right | ||
) | ||
@@ -99,188 +97,2 @@ ), | ||
function injectArrayIterator(scope) { | ||
return util.injectShared(scope, 'arrayIterator', b.functionExpression( | ||
null, | ||
[b.identifier('array')], | ||
b.blockStatement([ | ||
b.variableDeclaration( | ||
'var', | ||
[b.variableDeclarator( | ||
b.identifier('index'), | ||
b.literal(0) | ||
)] | ||
), | ||
b.returnStatement( | ||
b.objectExpression([ | ||
b.property( | ||
'init', | ||
b.identifier('next'), | ||
b.functionExpression( | ||
null, | ||
[], | ||
b.blockStatement([ | ||
b.ifStatement( | ||
b.binaryExpression( | ||
'>=', | ||
b.identifier('index'), | ||
b.memberExpression( | ||
b.identifier('array'), | ||
b.identifier('length'), | ||
false | ||
) | ||
), | ||
b.blockStatement([ | ||
b.returnStatement( | ||
b.objectExpression([ | ||
b.property( | ||
'init', | ||
b.identifier('done'), | ||
b.literal(true) | ||
), | ||
b.property( | ||
'init', | ||
b.identifier('value'), | ||
b.unaryExpression( | ||
'void', | ||
b.literal(0), | ||
true | ||
) | ||
) | ||
]) | ||
) | ||
]), | ||
b.blockStatement([ | ||
b.returnStatement( | ||
b.objectExpression([ | ||
b.property( | ||
'init', | ||
b.identifier('done'), | ||
b.literal(false) | ||
), | ||
b.property( | ||
'init', | ||
b.identifier('value'), | ||
b.memberExpression( | ||
b.identifier('array'), | ||
b.updateExpression( | ||
'++', | ||
b.identifier('index'), | ||
false | ||
), | ||
true | ||
) | ||
) | ||
]) | ||
) | ||
]) | ||
) | ||
]) | ||
) | ||
) | ||
]) | ||
) | ||
]) | ||
)); | ||
} | ||
function injectGetIterator(scope, arrayIterator) { | ||
return util.injectShared(scope, 'getIterator', b.functionExpression( | ||
null, | ||
[b.identifier('iterable')], | ||
b.blockStatement([ | ||
b.variableDeclaration( | ||
'var', | ||
[b.variableDeclarator( | ||
b.identifier('sym'), | ||
b.logicalExpression( | ||
'||', | ||
b.logicalExpression( | ||
'&&', | ||
b.binaryExpression( | ||
'===', | ||
b.unaryExpression( | ||
'typeof', | ||
b.identifier('Symbol'), | ||
true | ||
), | ||
b.literal('function') | ||
), | ||
b.memberExpression( | ||
b.identifier('Symbol'), | ||
b.identifier('iterator'), | ||
false | ||
) | ||
), | ||
b.literal('@@iterator') | ||
) | ||
)] | ||
), | ||
b.ifStatement( | ||
b.binaryExpression( | ||
'===', | ||
b.unaryExpression( | ||
'typeof', | ||
b.memberExpression( | ||
b.identifier('iterable'), | ||
b.identifier('sym'), | ||
true | ||
), | ||
true | ||
), | ||
b.literal('function') | ||
), | ||
b.blockStatement([ | ||
b.returnStatement( | ||
b.callExpression( | ||
b.memberExpression( | ||
b.identifier('iterable'), | ||
b.identifier('sym'), | ||
true | ||
), | ||
[] | ||
) | ||
) | ||
]), | ||
b.ifStatement( | ||
b.binaryExpression( | ||
'===', | ||
b.callExpression( | ||
b.memberExpression( | ||
b.memberExpression( | ||
b.memberExpression( | ||
b.identifier('Object'), | ||
b.identifier('prototype'), | ||
false | ||
), | ||
b.identifier('toString'), | ||
false | ||
), | ||
b.identifier('call'), | ||
false | ||
), | ||
[b.identifier('iterable')] | ||
), | ||
b.literal('[object Array]') | ||
), | ||
b.blockStatement([ | ||
b.returnStatement( | ||
b.callExpression( | ||
arrayIterator, | ||
[b.identifier('iterable')] | ||
) | ||
) | ||
]), | ||
b.blockStatement([ | ||
b.throwStatement( | ||
b.newExpression( | ||
b.identifier('TypeError'), | ||
[] | ||
) | ||
) | ||
]) | ||
) | ||
) | ||
]) | ||
)); | ||
} | ||
function transform(ast) { | ||
@@ -287,0 +99,0 @@ recast.types.traverse(ast, visitNode); |
{ | ||
"name": "es6-for-of", | ||
"version": "0.2.3", | ||
"version": "0.3.0", | ||
"main": "lib/index.js", | ||
@@ -12,3 +12,3 @@ "scripts": { | ||
"esprima": "git+https://github.com/ariya/esprima.git#harmony", | ||
"ast-util": "^0.0" | ||
"ast-util": "^0.1" | ||
}, | ||
@@ -15,0 +15,0 @@ "devDependencies": { |
@@ -27,3 +27,3 @@ var expect = require('chai').expect; | ||
' return iterable[sym]();', | ||
' } else if (Object.prototype.toString.call(iterable) === "[object Array]") {', | ||
' } else if (typeof iterable === "object" || typeof iterable === "function") {', | ||
' return $__arrayIterator(iterable);', | ||
@@ -40,11 +40,11 @@ ' } else {', | ||
' next: function() {', | ||
' if (index >= array.length) {', | ||
' if (index < array.length) {', | ||
' return {', | ||
' done: true,', | ||
' value: void 0', | ||
' done: false,', | ||
' value: array[index++]', | ||
' };', | ||
' } else {', | ||
' return {', | ||
' done: false,', | ||
' value: array[index++]', | ||
' done: true,', | ||
' value: void 0', | ||
' };', | ||
@@ -105,5 +105,5 @@ ' }', | ||
var d = []; | ||
vm.runInNewContext(result, { a: a, d: d, c: null }); | ||
vm.runInNewContext(result, {a: a, d: d, c: null}); | ||
expect(d).to.eql([1, 2, 3, 4, 5, 6]); | ||
}); | ||
}); |
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
7898
210
+ Addedast-util@0.1.2(transitive)
- Removedast-util@0.0.6(transitive)
Updatedast-util@^0.1