Skip to content

Commit

Permalink
issue #254 - fibers esprima transform passes all unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
bjouhier committed Mar 5, 2015
1 parent a50716d commit bda0bf1
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
20 changes: 10 additions & 10 deletions lib/fibers/transform-esprima.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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;
}
Expand Down Expand Up @@ -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]);
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion lib/fibers/walker-esprima.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down

0 comments on commit bda0bf1

Please sign in to comment.