From bda0bf1f8c255c86c43e79d555775fbdbb66c715 Mon Sep 17 00:00:00 2001 From: Bruno Jouhier Date: Thu, 5 Mar 2015 22:36:49 +0100 Subject: [PATCH] issue #254 - fibers esprima transform passes all unit tests --- lib/fibers/transform-esprima.js | 20 ++++++++++---------- lib/fibers/walker-esprima.js | 2 +- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/lib/fibers/transform-esprima.js b/lib/fibers/transform-esprima.js index c334be30..3fe5529a 100644 --- a/lib/fibers/transform-esprima.js +++ b/lib/fibers/transform-esprima.js @@ -43,12 +43,13 @@ function getLocals(fn, recurse) { var vars = this.declarations; for (var ii = 0; ii < vars.length; ++ii) { names[vars[ii].id.name] = vars[ii].id.name; + vars[ii].init && walk(vars[ii].init); } } var walk = Walker({ 'Function': function(name, args, body) { if (this.type !== 'FunctionExpression') { - names[this.name] = this.name; + names[this.id.name] = this.id.name; } // Don't walk further by default if (recurse) { @@ -63,8 +64,8 @@ function getLocals(fn, recurse) { for (var ii = 0; ii < fn.params; ++ii) { names[fn.params[ii].name] = fn.params[ii].name; } - if (fn.name && fn.type === 'FunctionExpression') { - names[fn.name] = fn.name; + if (fn.id && fn.type === 'FunctionExpression') { + names[fn.id.name] = fn.id.name; } return names; } @@ -408,7 +409,7 @@ function transform(source, options) { catchup(this.range[0]); skipTo(expr.object.range[0]); buffer.add('fstreamline__.then.call(this,'); - walk(expr.object()); + walk(expr.object); catchup(expr.object.range[1]); buffer.add(', "' + expr.property.name + '", _)'); skipTo(this.range[1]); @@ -514,29 +515,28 @@ function transform(source, options) { if (endsWith(source, this.range[1] - paren, '}).call(this)') // || endsWith(source, this.range[1] - paren, '}).call(_this)') // || endsWith(source, this.range[1] - paren, '}).apply(this, arguments)')) { - expr.callee.forceAsync = async; + expr.object.forceAsync = async; } } walk(expr); args.map(walk); } }, - 'VariableDeclarator': function(name, initializer) { + 'Identifier': function(name) { if (name === callback) { throw error(this.loc.start.line, 'Invalid usage of callback'); } else if (verboten[name]) { throw error(this.loc.start.line, 'Invalid use of indentifier `'+ name+ '`'); } if (scope[name]) { - catchup(this.id.range[0]); + catchup(this.range[0]); buffer.add(scope[name]); - skipTo(this.id.range[1]); + skipTo(this.range[1]); } else { // catchup to end will deal with all sort of oddities, like object initializer keys that are // parsed as identifiers but need to be quoted. - catchup(this.id.range[1]); + catchup(this.range[1]); } - initializer && walk(initializer); }, 'Property': function() { // Dont't walk the property key, because that's an identifier and it will be clobbered, per diff --git a/lib/fibers/walker-esprima.js b/lib/fibers/walker-esprima.js index f3b0efbc..975ec7b4 100644 --- a/lib/fibers/walker-esprima.js +++ b/lib/fibers/walker-esprima.js @@ -259,7 +259,7 @@ function Walker(visitors) { if (visitors[type]) { visitors[type].call(node, node.id.name, node.init); } else { - walk(node.init); + node.init && walk(node.init); } break;