regenerator
Advanced tools
Comparing version 0.2.0 to 0.2.1
@@ -17,2 +17,3 @@ /** | ||
var meta = require("./meta"); | ||
var hasOwn = Object.prototype.hasOwnProperty; | ||
@@ -106,2 +107,32 @@ function Emitter(contextId) { | ||
var volatileContextPropertyNames = { | ||
next: true, | ||
sent: true, | ||
rval: true, | ||
thrown: true | ||
}; | ||
// A "volatile" context property is a MemberExpression like context.sent | ||
// that should probably be stored in a temporary variable when there's a | ||
// possibility the property will get overwritten. | ||
Ep.isVolatileContextProperty = function(expr) { | ||
if (n.MemberExpression.check(expr)) { | ||
if (expr.computed) { | ||
// If it's a computed property such as context[couldBeAnything], | ||
// assume the worst in terms of volatility. | ||
return true; | ||
} | ||
if (n.Identifier.check(expr.object) && | ||
n.Identifier.check(expr.property) && | ||
expr.object.name === this.contextId.name && | ||
hasOwn.call(volatileContextPropertyNames, | ||
expr.property.name)) { | ||
return true; | ||
} | ||
} | ||
return false; | ||
}; | ||
// Shorthand for setting context.rval and jumping to `context.stop()`. | ||
@@ -297,3 +328,3 @@ Ep.stop = function(rval) { | ||
} | ||
} | ||
}; | ||
@@ -357,3 +388,3 @@ function getDeclError(node) { | ||
new leap.LoopEntry(after, before, labelId), | ||
function() { self.explodeStatement(path.get("body")) } | ||
function() { self.explodeStatement(path.get("body")); } | ||
); | ||
@@ -373,3 +404,3 @@ self.jump(before); | ||
new leap.LoopEntry(after, test, labelId), | ||
function() { self.explode(path.get("body")) } | ||
function() { self.explode(path.get("body")); } | ||
); | ||
@@ -403,3 +434,3 @@ self.mark(test); | ||
new leap.LoopEntry(after, update, labelId), | ||
function() { self.explodeStatement(path.get("body")) } | ||
function() { self.explodeStatement(path.get("body")); } | ||
); | ||
@@ -462,3 +493,3 @@ | ||
new leap.LoopEntry(after, head, labelId), | ||
function() { self.explodeStatement(path.get("body")) } | ||
function() { self.explodeStatement(path.get("body")); } | ||
); | ||
@@ -806,3 +837,4 @@ | ||
} else if (tempVar || (hasLeapingChildren && | ||
meta.hasSideEffects(result))) { | ||
(self.isVolatileContextProperty(result) || | ||
meta.hasSideEffects(result)))) { | ||
// If tempVar was provided, then the result will always be assigned | ||
@@ -814,4 +846,5 @@ // to it, even if the result does not otherwise need to be assigned | ||
// when some other child contains a leap and the child in question | ||
// has side effects that need to occur in proper sequence relative | ||
// to the leap. | ||
// is a context property like $ctx.sent that might get overwritten | ||
// or an expression with side effects that need to occur in proper | ||
// sequence relative to the leap. | ||
result = self.emitAssign( | ||
@@ -843,6 +876,3 @@ tempVar || self.makeTempVar(), | ||
path.get("arguments").map(function(argPath) { | ||
return explodeViaTempVar( | ||
hasLeapingChildren ? self.makeTempVar() : null, | ||
argPath | ||
); | ||
return explodeViaTempVar(null, argPath); | ||
}) | ||
@@ -857,6 +887,3 @@ )); | ||
propPath.value.key, | ||
explodeViaTempVar( | ||
hasLeapingChildren ? self.makeTempVar() : null, | ||
propPath.get("value") | ||
) | ||
explodeViaTempVar(null, propPath.get("value")) | ||
); | ||
@@ -869,6 +896,3 @@ }) | ||
path.get("elements").map(function(elemPath) { | ||
return explodeViaTempVar( | ||
hasLeapingChildren ? self.makeTempVar() : null, | ||
elemPath | ||
); | ||
return explodeViaTempVar(null, elemPath); | ||
}) | ||
@@ -875,0 +899,0 @@ )); |
@@ -19,3 +19,3 @@ { | ||
], | ||
"version": "0.2.0", | ||
"version": "0.2.1", | ||
"homepage": "http://github.com/facebook/regenerator", | ||
@@ -32,2 +32,3 @@ "repository": { | ||
"dependencies": { | ||
"commander": "~2.0.0", | ||
"esprima": "git://github.com/ariya/esprima.git#harmony", | ||
@@ -34,0 +35,0 @@ "ast-types": "~0.3.5", |
@@ -6,3 +6,3 @@ regenerator [![Build Status](https://travis-ci.org/facebook/regenerator.png?branch=master)](https://travis-ci.org/facebook/regenerator) | ||
takes the proposed syntax for generators/`yield` from future versions of | ||
JS (ECMAScript6 or ES6, experimentally implemented in Node.js v0.11) and | ||
JS ([ECMAScript6 or ES6](http://wiki.ecmascript.org/doku.php?id=harmony:specification_drafts), experimentally implemented in Node.js v0.11) and | ||
spits out efficient JS-of-today (ES5) that behaves the same way. | ||
@@ -19,3 +19,3 @@ | ||
```sh | ||
npm install regenerator | ||
npm install -g regenerator | ||
``` | ||
@@ -39,3 +39,4 @@ | ||
```sh | ||
path/to/node_modules/regenerator/bin/regenerator es6.js > es5.js | ||
regenerator es6.js > es5.js # Just the transform. | ||
regenerator --include-runtime es6.js > es5.js # Add the runtime too. | ||
``` | ||
@@ -66,4 +67,3 @@ | ||
[fork](https://github.com/facebook/regenerator/fork) the repository, | ||
create some failing tests cases in [test/tests.es6.js]( | ||
https://github.com/facebook/regenerator/blob/master/test/tests.es6.js), | ||
create some failing tests cases in [test/tests.es6.js](test/tests.es6.js), | ||
and send pull requests for me to fix. | ||
@@ -70,0 +70,0 @@ |
@@ -53,2 +53,10 @@ /** | ||
}); | ||
it("should support multiple yields in expression", function() { | ||
function *gen() { return (yield 0) + (yield 0); } | ||
var itr = gen(); | ||
itr.next(); | ||
itr.next(1); | ||
assert.equal(itr.next(2).value, 3); | ||
}); | ||
}); | ||
@@ -55,0 +63,0 @@ |
Sorry, the diff of this file is not supported yet
79062
2339
8
+ Addedcommander@~2.0.0
+ Addedcommander@2.0.0(transitive)