regenerator
Advanced tools
Comparing version 0.3.3 to 0.3.4
@@ -21,6 +21,7 @@ /** | ||
// declarations. | ||
exports.hoist = function(fun) { | ||
n.Function.assert(fun); | ||
exports.hoist = function(funPath) { | ||
assert.ok(funPath instanceof types.NodePath); | ||
n.Function.assert(funPath.value); | ||
var vars = {}; | ||
var funDeclsToRaise = []; | ||
@@ -52,3 +53,3 @@ function varDeclToExpr(vdec, includeIdentifiers) { | ||
types.traverse(fun.body, function(node) { | ||
types.traverse(funPath.get("body"), function(node) { | ||
if (n.VariableDeclaration.check(node)) { | ||
@@ -99,12 +100,20 @@ var expr = varDeclToExpr(node, false); | ||
if (n.BlockStatement.check(this.parent.node)) { | ||
funDeclsToRaise.push({ | ||
block: this.parent.node, | ||
assignment: assignment | ||
}); | ||
// Note that the function declaration we want to remove might be | ||
// the same node that firstStmtPath refers to, in case the | ||
// function declaration was already the first statement in the | ||
// enclosing block statement. | ||
var firstStmtPath = this.parent.get("body", 0); | ||
// Remove the function declaration for now, but reinsert the assignment | ||
// form later, at the top of the enclosing BlockStatement. | ||
// Insert the assignment form before the first statement in the | ||
// enclosing block. | ||
firstStmtPath.replace(assignment, firstStmtPath.value); | ||
// Remove the function declaration now that we've inserted the | ||
// equivalent assignment form at the beginning of the block. | ||
this.replace(); | ||
} else { | ||
// If the parent node is not a block statement, then we can just | ||
// replace the declaration with the equivalent assignment form | ||
// without worrying about hoisting it. | ||
this.replace(assignment); | ||
@@ -122,8 +131,5 @@ } | ||
funDeclsToRaise.forEach(function(entry) { | ||
entry.block.body.unshift(entry.assignment); | ||
}); | ||
var paramNames = {}; | ||
fun.params.forEach(function(param) { | ||
funPath.get("params").each(function(paramPath) { | ||
var param = paramPath.value; | ||
if (n.Identifier.check(param)) { | ||
@@ -130,0 +136,0 @@ paramNames[param.name] = param; |
@@ -44,4 +44,4 @@ /** | ||
var wrapGeneratorId = b.identifier("wrapGenerator"); | ||
var shouldAliasArguments = renameArguments(node, argsId); | ||
var vars = hoist(node); | ||
var shouldAliasArguments = renameArguments(this, argsId); | ||
var vars = hoist(this); | ||
@@ -56,4 +56,3 @@ if (shouldAliasArguments) { | ||
var emitter = new Emitter(contextId); | ||
var path = new types.NodePath(node); | ||
emitter.explode(path.get("body")); | ||
emitter.explode(this.get("body")); | ||
@@ -103,7 +102,9 @@ var outerBody = []; | ||
function renameArguments(func, argsId) { | ||
function renameArguments(funcPath, argsId) { | ||
assert.ok(funcPath instanceof types.NodePath); | ||
var func = funcPath.value; | ||
var didReplaceArguments = false; | ||
var hasImplicitArguments = false; | ||
types.traverse(func, function(node) { | ||
types.traverse(funcPath, function(node) { | ||
if (node === func) { | ||
@@ -110,0 +111,0 @@ hasImplicitArguments = !this.scope.lookup("arguments"); |
13
main.js
@@ -59,8 +59,7 @@ /** | ||
var recastAst = recast.parse(source, recastOptions); | ||
var ast = recastAst.program; | ||
var ast = recast.parse(source, recastOptions); | ||
// Transpile let/const into var declarations. | ||
if (supportBlockBinding) { | ||
var defsResult = require("defs")(ast, { | ||
var defsResult = require("defs")(ast.program, { | ||
ast: true, | ||
@@ -78,12 +77,14 @@ disallowUnknownReferences: false, | ||
recastAst.program = transform(ast); | ||
var path = new recast.types.NodePath(ast); | ||
transform(path.get("program")); | ||
// Include the runtime by modifying the AST rather than by concatenating | ||
// strings. This technique will allow for more accurate source mapping. | ||
if (options.includeRuntime) { | ||
var body = recastAst.program.body; | ||
var body = ast.program.body; | ||
body.unshift.apply(body, runtimeBody); | ||
} | ||
return recast.print(recastAst, recastOptions).code; | ||
return recast.print(path, recastOptions).code; | ||
} | ||
@@ -90,0 +91,0 @@ |
@@ -19,3 +19,3 @@ { | ||
], | ||
"version": "0.3.3", | ||
"version": "0.3.4", | ||
"homepage": "http://github.com/facebook/regenerator", | ||
@@ -34,4 +34,4 @@ "repository": { | ||
"esprima": "git://github.com/ariya/esprima.git#harmony", | ||
"ast-types": ">= 0.3.13", | ||
"recast": "~0.5.2", | ||
"ast-types": "~0.3.15", | ||
"recast": "~0.5.7", | ||
"private": "~0.1.0", | ||
@@ -38,0 +38,0 @@ "defs": "~0.6.2" |
95670
2768
- Removedast-types@0.16.1(transitive)
- Removedtslib@2.8.1(transitive)
Updatedast-types@~0.3.15
Updatedrecast@~0.5.7