From 256f876e9d7115082e2cd400bfbe425a794a3b31 Mon Sep 17 00:00:00 2001 From: Bruno Jouhier Date: Sat, 7 Mar 2015 20:55:28 +0100 Subject: [PATCH] issue #254 - fixed some glitches in generators-fast transform and unit tests --- lib/generators-fast/flows.js | 6 +++--- lib/generators-fast/transform.js | 6 ++++-- test/common/flows-test._js | 6 +++--- 3 files changed, 10 insertions(+), 8 deletions(-) diff --git a/lib/generators-fast/flows.js b/lib/generators-fast/flows.js index 98c921e8..262e121f 100644 --- a/lib/generators-fast/flows.js +++ b/lib/generators-fast/flows.js @@ -109,7 +109,7 @@ function() { var funnel = exports.funnel(max); this.collect = function*(_, count, trim) { - return (yield galaxy.invoke((function(callback) { + return (yield galaxy.invoke(function(callback) { if (typeof(callback) != "function") throw new Error("invalid call to collect: no callback"); var results = trim ? [] : new Array(fns.length); count = count < 0 ? fns.length : Math.min(count, fns.length); @@ -125,7 +125,7 @@ } , fns[i]); })(i); } - }, "call", [this, _], 1)); + }, "call", [this , _], 1)); }; this.collectOne = function*(_) { var result = (yield this.collect(_, 1, true)); @@ -334,7 +334,7 @@ /// * `flows.sleep(_, millis)` /// Sleeps `millis` ms. exports.sleep = function*(_, millis) { - return (yield galaxy.invoke(null, setTimeout, [_, millis], 0)); + return (yield galaxy.invoke(null, setTimeout, [_ , millis], 0)); }; exports.eventHandler = function(fn) { diff --git a/lib/generators-fast/transform.js b/lib/generators-fast/transform.js index d990d345..405a73a0 100644 --- a/lib/generators-fast/transform.js +++ b/lib/generators-fast/transform.js @@ -169,6 +169,7 @@ function transform(source, options) { skipTo(expr.range[0]); buffer += '(yield galaxy.invoke('; if (expr.type === 'MemberExpression') { + skipTo(expr.object.range[0]); if (!expr.computed) { // Method call: foo.bar(_) walk(expr.object); @@ -191,9 +192,9 @@ function transform(source, options) { } // Render arguments buffer += ', ['; - skipTo(args[0].range[0]); for (var ii = 0; ii < args.length; ++ii) { - catchup(args[ii].range[0]); + skipTo(args[ii].range[0]); + if (ii > 0) buffer += ', '; if (ii !== idx) { walk(args[ii]); catchup(args[ii].range[1]); @@ -271,6 +272,7 @@ function transform(source, options) { var isPromise = args[idx].operator === "void"; catchup(this.range[0]); buffer += 'galaxy.' + (isPromise ? 'promise' : 'spin') + '.call(this, '; + skipTo(expr.range[0]); walk(expr); catchup(expr.range[1]); if (isPromise) buffer += ', ['; diff --git a/test/common/flows-test._js b/test/common/flows-test._js index 8d8adc47..2e3f369a 100644 --- a/test/common/flows-test._js +++ b/test/common/flows-test._js @@ -336,7 +336,7 @@ asyncTest("collectAll", 4, function(_) { return function(_) { count++; peak = Math.max(count, peak); - setTimeout(_, 10); + setTimeout(~_, 10); total = delay(_, i) + total; count--; return 2 * i; @@ -359,7 +359,7 @@ asyncTest("collectOne", 4, function(_) { return function(_) { count++; peak = Math.max(count, peak); - setTimeout(_, 10); + setTimeout(~_, 10); total = delay(_, i) + total; count--; return 2 * i; @@ -382,7 +382,7 @@ asyncTest("collectAll with limit", 1, function(_) { return function(_) { count++; peak = Math.max(count, peak); - setTimeout(_, 10); + setTimeout(~_, 10); total = delay(_, i) + total; count--; return 2 * i;