streamline
Advanced tools
Comparing version 2.0.2 to 2.0.3
@@ -19,2 +19,3 @@ "use strict"; | ||
var dst = fsp.join(__dirname, to); | ||
console.log("building " + dst); | ||
mkdirs(fsp.dirname(dst)); | ||
@@ -21,0 +22,0 @@ browserify(src, { |
@@ -98,3 +98,2 @@ (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){ | ||
// Do not use this one directly, require it through the flows module. | ||
module.exports = function funnel(max) { | ||
@@ -105,32 +104,32 @@ max = max == null ? -1 : max; | ||
var queue = [], | ||
active = 0, | ||
closed = false; | ||
active = 0, | ||
closed = false; | ||
var fun = function (callback, fn) { | ||
if (callback == null) return future(fun, arguments, 0); | ||
//console.log("FUNNEL: active=" + active + ", queued=" + queue.length); | ||
if (max < 0 || max === Infinity) return fn(callback); | ||
var fun = function(callback, fn) { | ||
if (callback == null) return future(fun, arguments, 0); | ||
//console.log("FUNNEL: active=" + active + ", queued=" + queue.length); | ||
if (max < 0 || max === Infinity) return fn(callback); | ||
queue.push({ | ||
fn: fn, | ||
cb: callback | ||
}); | ||
function _doOne() { | ||
var current = queue.splice(0, 1)[0]; | ||
if (!current.cb) return current.fn(); | ||
active++; | ||
current.fn(function (err, result) { | ||
active--; | ||
if (!closed) { | ||
current.cb(err, result); | ||
while (active < max && queue.length > 0) _doOne(); | ||
} | ||
queue.push({ | ||
fn: fn, | ||
cb: callback | ||
}); | ||
} | ||
while (active < max && queue.length > 0) _doOne(); | ||
}; | ||
function _doOne() { | ||
var current = queue.splice(0, 1)[0]; | ||
if (!current.cb) return current.fn(); | ||
active++; | ||
current.fn(function(err, result) { | ||
active--; | ||
if (!closed) { | ||
current.cb(err, result); | ||
while (active < max && queue.length > 0) _doOne(); | ||
} | ||
}); | ||
} | ||
fun.close = function () { | ||
while (active < max && queue.length > 0) _doOne(); | ||
}; | ||
fun.close = function() { | ||
queue = []; | ||
@@ -142,3 +141,2 @@ closed = true; | ||
module.exports.defaultSize = 4; | ||
},{}],3:[function(require,module,exports){ | ||
@@ -149,3 +147,3 @@ "use strict"; | ||
module.exports = function (file, line, object, property, index) { | ||
module.exports = function(file, line, object, property, index) { | ||
var bound = typeof property !== "function"; | ||
@@ -156,8 +154,5 @@ var fn = bound ? object[property] : property; | ||
return function futured() { | ||
var err, | ||
result, | ||
done, | ||
q = []; | ||
var err, result, done, q = []; | ||
var args = Array.prototype.slice.call(arguments); | ||
var callback = function (e, r) { | ||
var callback = function(e, r) { | ||
//if (e) console.error(e); | ||
@@ -167,9 +162,9 @@ err = e; | ||
done = true; | ||
q && q.forEach(function (f) { | ||
q && q.forEach(function(f) { | ||
if (sync) { | ||
setImmediate(function () { | ||
setImmediate(function() { | ||
f.call(self, e, r); | ||
}); | ||
} else { | ||
f.call(self, e, r); | ||
f.call(self, e, r); | ||
} | ||
@@ -179,22 +174,25 @@ }); | ||
}; | ||
args[index] = callback; | ||
args[index] = callback; | ||
var sync = true; | ||
fn.apply(self, args); | ||
sync = false; | ||
var future = function (cb) { | ||
var future = function(cb) { | ||
if (typeof cb !== "function") throw argError(fn.name, index, "function", cb); | ||
if (done) { | ||
cb.call(self, err, result); | ||
} else q.push(cb); | ||
} | ||
else q.push(cb); | ||
}; | ||
// computed property so that we don't allocate promise if we don't need to | ||
Object.defineProperty(future, 'promise', { | ||
get: function () { | ||
return new Promise(function (resolve, reject) { | ||
get: function() { | ||
return new Promise(function(resolve, reject) { | ||
if (done) { | ||
if (err) reject(err);else resolve(result); | ||
if (err) reject(err); | ||
else resolve(result); | ||
} else { | ||
q.push(function (e, r) { | ||
if (e) reject(e);else resolve(r); | ||
}); | ||
q.push(function(e, r) { | ||
if (e) reject(e); | ||
else resolve(r); | ||
}) | ||
} | ||
@@ -206,3 +204,3 @@ }); | ||
}; | ||
}; | ||
} | ||
@@ -269,3 +267,3 @@ },{"./util":6}],4:[function(require,module,exports){ | ||
/// ## Array functions | ||
/// ## Array functions | ||
/// | ||
@@ -276,8 +274,8 @@ /// These functions are asynchronous variants of the EcmaScript 5 Array functions. | ||
/// | ||
/// These variants are postfixed by an underscore. | ||
/// They take the `_` callback as first parameter. | ||
/// They pass the `_` callback as first argument to their `fn` callback. | ||
/// These variants are postfixed by an underscore. | ||
/// They take the `_` callback as first parameter. | ||
/// They pass the `_` callback as first argument to their `fn` callback. | ||
/// Most of them have an optional `options` second parameter which controls the level of | ||
/// parallelism. This `options` parameter may be specified either as `{ parallel: par }` | ||
/// where `par` is an integer, or directly as a `par` integer value. | ||
/// where `par` is an integer, or directly as a `par` integer value. | ||
/// The `par` values are interpreted as follows: | ||
@@ -293,3 +291,3 @@ /// | ||
/// | ||
/// * `array.forEach_(_[, options], fn[, thisObj])` | ||
/// * `array.forEach_(_[, options], fn[, thisObj])` | ||
/// `fn` is called as `fn(_, elt, i, array)`. | ||
@@ -304,6 +302,6 @@ delete Array.prototype.forEach_; | ||
if (typeof options === "function") { | ||
thisObj = fn; | ||
fn = options; | ||
options = 1; | ||
} | ||
thisObj = fn; | ||
fn = options; | ||
options = 1; | ||
} | ||
var par = _parallel(options); | ||
@@ -313,8 +311,8 @@ thisObj = thisObj !== undefined ? thisObj : this; | ||
if (par === 1 || len <= 1) { | ||
for (var i = 0; i < len; i++) { | ||
if (has.call(this, i)) yield _streamline.await(_filename, 95, fn, "call", 1, null, false)(thisObj, true, this[i], i, this); | ||
for (var i = 0; i < len; i++) { | ||
if (has.call(this, i)) yield _streamline.await(_filename, 95, fn, "call", 1, null, false)(thisObj, true, this[i], i, this); | ||
} | ||
} else { | ||
yield _streamline.await(_filename, 98, this, "map_", 0, null, false)(true, par, fn, thisObj); | ||
} | ||
} else { | ||
yield _streamline.await(_filename, 98, this, "map_", 0, null, false)(true, par, fn, thisObj); | ||
} | ||
return this; | ||
@@ -325,3 +323,3 @@ } | ||
Array.prototype.forEach_.version_ = VERSION; | ||
/// * `result = array.map_(_[, options], fn[, thisObj])` | ||
/// * `result = array.map_(_[, options], fn[, thisObj])` | ||
/// `fn` is called as `fn(_, elt, i, array)`. | ||
@@ -336,6 +334,6 @@ delete Array.prototype.map_; | ||
if (typeof options === "function") { | ||
thisObj = fn; | ||
fn = options; | ||
options = 1; | ||
} | ||
thisObj = fn; | ||
fn = options; | ||
options = 1; | ||
} | ||
var par = _parallel(options); | ||
@@ -346,19 +344,19 @@ thisObj = thisObj !== undefined ? thisObj : this; | ||
if (par === 1 || len <= 1) { | ||
result = new Array(len); | ||
for (i = 0; i < len; i++) { | ||
if (has.call(this, i)) result[i] = yield _streamline.await(_filename, 124, fn, "call", 1, null, false)(thisObj, true, this[i], i, this); | ||
result = new Array(len); | ||
for (i = 0; i < len; i++) { | ||
if (has.call(this, i)) result[i] = yield _streamline.await(_filename, 124, fn, "call", 1, null, false)(thisObj, true, this[i], i, this); | ||
} | ||
} else { | ||
var fun = funnel(par); | ||
result = this.map(function (elt, i, arr) { | ||
return _streamline.future(_filename, 129, null, fun, 0, null, false)(false, _streamline.async(function* _$$$$(_) { | ||
{ | ||
return yield _streamline.await(_filename, 130, fn, "call", 1, null, false)(thisObj, true, elt, i, arr); | ||
} | ||
}, 0, 1)); | ||
}); | ||
for (i = 0; i < len; i++) { | ||
if (has.call(this, i)) result[i] = yield _streamline.await(_filename, 134, result, i, 0, null, false)(true); | ||
} | ||
} | ||
} else { | ||
var fun = funnel(par); | ||
result = this.map(function (elt, i, arr) { | ||
return _streamline.future(_filename, 129, null, fun, 0, null, false)(false, _streamline.async(function* _$$$$(_) { | ||
{ | ||
return yield _streamline.await(_filename, 130, fn, "call", 1, null, false)(thisObj, true, elt, i, arr); | ||
} | ||
}, 0, 1)); | ||
}); | ||
for (i = 0; i < len; i++) { | ||
if (has.call(this, i)) result[i] = yield _streamline.await(_filename, 134, result, i, 0, null, false)(true); | ||
} | ||
} | ||
return result; | ||
@@ -368,3 +366,3 @@ } | ||
}); | ||
/// * `result = array.filter_(_[, options], fn[, thisObj])` | ||
/// * `result = array.filter_(_[, options], fn[, thisObj])` | ||
/// `fn` is called as `fn(_, elt, i, array)`. | ||
@@ -379,6 +377,6 @@ delete Array.prototype.filter_; | ||
if (typeof options === "function") { | ||
thisObj = fn; | ||
fn = options; | ||
options = 1; | ||
} | ||
thisObj = fn; | ||
fn = options; | ||
options = 1; | ||
} | ||
var par = _parallel(options); | ||
@@ -389,15 +387,15 @@ thisObj = thisObj !== undefined ? thisObj : this; | ||
if (par === 1 || len <= 1) { | ||
for (var i = 0; i < len; i++) { | ||
if (has.call(this, i)) { | ||
var elt = this[i]; | ||
if (yield _streamline.await(_filename, 161, fn, "call", 1, null, false)(thisObj, true, elt, i, this)) result.push(elt); | ||
for (var i = 0; i < len; i++) { | ||
if (has.call(this, i)) { | ||
var elt = this[i]; | ||
if (yield _streamline.await(_filename, 161, fn, "call", 1, null, false)(thisObj, true, elt, i, this)) result.push(elt); | ||
} | ||
} | ||
} else { | ||
yield _streamline.await(_filename, 165, this, "map_", 0, null, false)(true, par, _streamline.async(function* _$$$$2(_, elt, i, arr) { | ||
{ | ||
if (yield _streamline.await(_filename, 166, fn, "call", 1, null, false)(thisObj, true, elt, i, arr)) result.push(elt); | ||
} | ||
}, 0, 4), thisObj); | ||
} | ||
} else { | ||
yield _streamline.await(_filename, 165, this, "map_", 0, null, false)(true, par, _streamline.async(function* _$$$$2(_, elt, i, arr) { | ||
{ | ||
if (yield _streamline.await(_filename, 166, fn, "call", 1, null, false)(thisObj, true, elt, i, arr)) result.push(elt); | ||
} | ||
}, 0, 4), thisObj); | ||
} | ||
return result; | ||
@@ -407,3 +405,3 @@ } | ||
}); | ||
/// * `bool = array.every_(_[, options], fn[, thisObj])` | ||
/// * `bool = array.every_(_[, options], fn[, thisObj])` | ||
/// `fn` is called as `fn(_, elt, i, array)`. | ||
@@ -418,6 +416,6 @@ delete Array.prototype.every_; | ||
if (typeof options === "function") { | ||
thisObj = fn; | ||
fn = options; | ||
options = 1; | ||
} | ||
thisObj = fn; | ||
fn = options; | ||
options = 1; | ||
} | ||
var par = _parallel(options); | ||
@@ -428,22 +426,22 @@ thisObj = thisObj !== undefined ? thisObj : this; | ||
if (par === 1 || len <= 1) { | ||
for (i = 0; i < len; i++) { | ||
for (i = 0; i < len; i++) { | ||
if (has.call(this, i) && !(yield _streamline.await(_filename, 191, fn, "call", 1, null, false)(thisObj, true, this[i], i, this))) return false; | ||
} | ||
} else { | ||
var fun = funnel(par); | ||
var futures = this.map(function (elt, i, arr) { | ||
return _streamline.future(_filename, 196, null, fun, 0, null, false)(false, _streamline.async(function* _$$$$3(_) { | ||
{ | ||
return yield _streamline.await(_filename, 197, fn, "call", 1, null, false)(thisObj, true, elt, i, arr); | ||
} | ||
}, 0, 1)); | ||
}); | ||
for (i = 0; i < len; i++) { | ||
if (has.call(this, i) && !(yield _streamline.await(_filename, 201, futures, i, 0, null, false)(true))) { | ||
fun.close(); | ||
return false; | ||
if (has.call(this, i) && !(yield _streamline.await(_filename, 191, fn, "call", 1, null, false)(thisObj, true, this[i], i, this))) return false; | ||
} | ||
} else { | ||
var fun = funnel(par); | ||
var futures = this.map(function (elt, i, arr) { | ||
return _streamline.future(_filename, 196, null, fun, 0, null, false)(false, _streamline.async(function* _$$$$3(_) { | ||
{ | ||
return yield _streamline.await(_filename, 197, fn, "call", 1, null, false)(thisObj, true, elt, i, arr); | ||
} | ||
}, 0, 1)); | ||
}); | ||
for (i = 0; i < len; i++) { | ||
if (has.call(this, i) && !(yield _streamline.await(_filename, 201, futures, i, 0, null, false)(true))) { | ||
fun.close(); | ||
return false; | ||
} | ||
} | ||
} | ||
} | ||
return true; | ||
@@ -453,3 +451,3 @@ } | ||
}); | ||
/// * `bool = array.some_(_[, options], fn[, thisObj])` | ||
/// * `bool = array.some_(_[, options], fn[, thisObj])` | ||
/// `fn` is called as `fn(_, elt, i, array)`. | ||
@@ -464,6 +462,6 @@ delete Array.prototype.some_; | ||
if (typeof options === "function") { | ||
thisObj = fn; | ||
fn = options; | ||
options = 1; | ||
} | ||
thisObj = fn; | ||
fn = options; | ||
options = 1; | ||
} | ||
var par = _parallel(options); | ||
@@ -474,21 +472,21 @@ thisObj = thisObj !== undefined ? thisObj : this; | ||
if (par === 1 || len <= 1) { | ||
for (i = 0; i < len; i++) { | ||
if (has.call(this, i) && (yield _streamline.await(_filename, 228, fn, "call", 1, null, false)(thisObj, true, this[i], i, this))) return true; | ||
} | ||
} else { | ||
var fun = funnel(par); | ||
var futures = this.map(function (elt, i, arr) { | ||
return _streamline.future(_filename, 233, null, fun, 0, null, false)(false, _streamline.async(function* _$$$$4(_) { | ||
{ | ||
return yield _streamline.await(_filename, 234, fn, "call", 1, null, false)(thisObj, true, elt, i, arr); | ||
} | ||
}, 0, 1)); | ||
}); | ||
for (i = 0; i < len; i++) { | ||
if (has.call(this, i) && (yield _streamline.await(_filename, 238, futures, i, 0, null, false)(true))) { | ||
fun.close(); | ||
return true; | ||
for (i = 0; i < len; i++) { | ||
if (has.call(this, i) && (yield _streamline.await(_filename, 228, fn, "call", 1, null, false)(thisObj, true, this[i], i, this))) return true; | ||
} | ||
} else { | ||
var fun = funnel(par); | ||
var futures = this.map(function (elt, i, arr) { | ||
return _streamline.future(_filename, 233, null, fun, 0, null, false)(false, _streamline.async(function* _$$$$4(_) { | ||
{ | ||
return yield _streamline.await(_filename, 234, fn, "call", 1, null, false)(thisObj, true, elt, i, arr); | ||
} | ||
}, 0, 1)); | ||
}); | ||
for (i = 0; i < len; i++) { | ||
if (has.call(this, i) && (yield _streamline.await(_filename, 238, futures, i, 0, null, false)(true))) { | ||
fun.close(); | ||
return true; | ||
} | ||
} | ||
} | ||
} | ||
return false; | ||
@@ -498,3 +496,3 @@ } | ||
}); | ||
/// * `result = array.reduce_(_, fn, val[, thisObj])` | ||
/// * `result = array.reduce_(_, fn, val[, thisObj])` | ||
/// `fn` is called as `val = fn(_, val, elt, i, array)`. | ||
@@ -517,3 +515,3 @@ delete Array.prototype.reduce_; | ||
}); | ||
/// * `result = array.reduceRight_(_, fn, val[, thisObj])` | ||
/// * `result = array.reduceRight_(_, fn, val[, thisObj])` | ||
/// `fn` is called as `val = fn(_, val, elt, i, array)`. | ||
@@ -537,4 +535,4 @@ delete Array.prototype.reduceRight_; | ||
/// * `array = array.sort_(_, compare [, beg [, end]])` | ||
/// `compare` is called as `cmp = compare(_, elt1, elt2)`. | ||
/// * `array = array.sort_(_, compare [, beg [, end]])` | ||
/// `compare` is called as `cmp = compare(_, elt1, elt2)`. | ||
/// Note: this function _changes_ the original array (and returns it). | ||
@@ -554,9 +552,9 @@ delete Array.prototype.sort_; | ||
if (end === beg + 1) { | ||
if ((yield _streamline.await(_filename, 298, null, compare, 0, null, false)(true, array[beg], array[end])) > 0) { | ||
tmp = array[beg]; | ||
array[beg] = array[end]; | ||
array[end] = tmp; | ||
if ((yield _streamline.await(_filename, 298, null, compare, 0, null, false)(true, array[beg], array[end])) > 0) { | ||
tmp = array[beg]; | ||
array[beg] = array[end]; | ||
array[end] = tmp; | ||
} | ||
return; | ||
} | ||
return; | ||
} | ||
@@ -573,8 +571,8 @@ var mid = Math.floor((beg + end) / 2); | ||
if (nbeg <= nend) { | ||
tmp = array[nbeg]; | ||
array[nbeg] = array[nend]; | ||
array[nend] = tmp; | ||
nbeg++; | ||
nend--; | ||
} | ||
tmp = array[nbeg]; | ||
array[nbeg] = array[nend]; | ||
array[nend] = tmp; | ||
nbeg++; | ||
nend--; | ||
} | ||
} | ||
@@ -598,6 +596,6 @@ | ||
/// | ||
/// ## Function functions | ||
/// ## Function functions | ||
/// | ||
/// * `result = fn.apply_(_, thisObj, args[, index])` | ||
/// Helper to use `Function.prototype.apply` inside streamlined functions. | ||
/// * `result = fn.apply_(_, thisObj, args[, index])` | ||
/// Helper to use `Function.prototype.apply` inside streamlined functions. | ||
/// Equivalent to `result = fn.apply(thisObj, argsWith_)` where `argsWith_` is | ||
@@ -619,3 +617,2 @@ /// a modified `args` in which the callback has been inserted at `index` | ||
/// | ||
},{"../funnel":2,"streamline-runtime/lib/generators/runtime":5}],5:[function(require,module,exports){ | ||
@@ -627,3 +624,2 @@ "use strict"; | ||
*/ | ||
var util = require('../util'); | ||
@@ -634,3 +630,3 @@ var glob = util.getGlobals('generators'); | ||
slowAwait: 0, | ||
fastAwait: 0 | ||
fastAwait: 0, | ||
}; | ||
@@ -647,3 +643,4 @@ | ||
function isGenerator(val) { | ||
return val && (Object.prototype.toString.call(val) === "[object Generator]" || val.toString() === "[object Generator]"); | ||
return val && ( | ||
Object.prototype.toString.call(val) === "[object Generator]" || val.toString() === "[object Generator]"); | ||
} | ||
@@ -658,5 +655,5 @@ | ||
Object.defineProperty(Frame.prototype, "name", { | ||
get: function () { | ||
get: function() { | ||
var fn = this.fn; | ||
return fn && (fn.__name__ || fn.name) || "unknown"; | ||
return (fn && (fn.__name__ || fn.name)) || "unknown"; | ||
} | ||
@@ -666,3 +663,3 @@ }); | ||
Object.defineProperty(Frame.prototype, "info", { | ||
get: function () { | ||
get: function() { | ||
return this; | ||
@@ -684,5 +681,5 @@ } | ||
var rsm = glob.resume; | ||
var emit = function (ev, g) { | ||
if (glob.emitter) glob.emitter.emit(ev, g.frame); | ||
}; | ||
var emit = function(ev, g) { | ||
if (glob.emitter) glob.emitter.emit(ev, g.frame); | ||
} | ||
@@ -698,3 +695,3 @@ try { | ||
glob.resume = function (err, val) { | ||
glob.resume = function(err, val) { | ||
if (glob.yielded) { | ||
@@ -709,3 +706,4 @@ emit("resume", g); | ||
var send = g.send || g.next; | ||
var v = err ? g.throw(err) : send.call(g, val); | ||
var v = err ? g. | ||
throw (err) : send.call(g, val); | ||
val = v.value; | ||
@@ -731,18 +729,18 @@ err = null; | ||
else if (v.done) { | ||
//g.close(); | ||
popFrame(g); | ||
g = g.prev; | ||
//g.close(); | ||
popFrame(g); | ||
g = g.prev; | ||
} | ||
// else if val is not a generator we have an error. Yield was not applied to a generators | ||
else { | ||
if (!isGenerator(val)) { | ||
throw new Error("invalid value was yielded. Expected a generator, got " + val); | ||
} | ||
// else if val is not a generator we have an error. Yield was not applied to a generators | ||
else { | ||
if (!isGenerator(val)) { | ||
throw new Error("invalid value was yielded. Expected a generator, got " + val); | ||
} | ||
// we got a new generator which means that g called another generator function | ||
// the new generator become current and we loop with g.send(undefined) (equiv to g.next()) | ||
val.prev = g; | ||
g = val; | ||
pushFrame(g); | ||
val = undefined; | ||
} | ||
// we got a new generator which means that g called another generator function | ||
// the new generator become current and we loop with g.send(undefined) (equiv to g.next()) | ||
val.prev = g; | ||
g = val; | ||
pushFrame(g); | ||
val = undefined; | ||
} | ||
} catch (ex) { | ||
@@ -758,6 +756,6 @@ // the send/throw call failed. | ||
} | ||
// we have exhausted the stack of generators. | ||
// we have exhausted the stack of generators. | ||
// return the result or error through the callback. | ||
cb(err, val); | ||
}; | ||
} | ||
@@ -775,3 +773,3 @@ // start the resume loop | ||
if (options.returnArray) return args; | ||
if (options.returnObject) return options.returnObject.reduce(function (res, key, i) { | ||
if (options.returnObject) return options.returnObject.reduce(function(res, key, i) { | ||
res[key] = args[i]; | ||
@@ -789,3 +787,3 @@ return res; | ||
var result = glob.PENDING, | ||
sync = true; | ||
sync = true; | ||
var rsm = glob.resume; | ||
@@ -796,26 +794,26 @@ | ||
var cx = glob.context; | ||
var callback = function (e, r) { | ||
var oldContext = glob.context; | ||
var oldResume = glob.resume; | ||
try { | ||
if (returnArray) r = Array.prototype.slice.call(arguments, 1); | ||
glob.context = cx; | ||
glob.resume = rsm; | ||
if (sync) { | ||
result = [glob.PENDING, e, r]; | ||
} else { | ||
glob.resume(e, r); | ||
var callback = function(e, r) { | ||
var oldContext = glob.context; | ||
var oldResume = glob.resume; | ||
try { | ||
if (returnArray) r = Array.prototype.slice.call(arguments, 1); | ||
glob.context = cx; | ||
glob.resume = rsm; | ||
if (sync) { | ||
result = [glob.PENDING, e, r]; | ||
} else { | ||
glob.resume(e, r); | ||
} | ||
} finally { | ||
glob.context = oldContext; | ||
glob.resume = oldResume; | ||
} | ||
} finally { | ||
glob.context = oldContext; | ||
glob.resume = oldResume; | ||
} | ||
}; | ||
if (index2 != null) { | ||
args[index] = function (r) { | ||
args[index] = function(r) { | ||
callback(null, r); | ||
}; | ||
args[index2] = function (e) { | ||
} | ||
args[index2] = function(e) { | ||
callback(e); | ||
}; | ||
} | ||
} else { | ||
@@ -829,26 +827,28 @@ args[index] = callback; | ||
var star = function (fn, index, index2, returnArray) { | ||
return function* () { | ||
return yield invoke(this, fn, arguments, index, index2, returnArray); | ||
var star = function(fn, index, index2, returnArray) { | ||
return function *() { | ||
return (yield invoke(this, fn, arguments, index, index2, returnArray)); | ||
}; | ||
}; | ||
} | ||
var unstarTemplate = function (fn, options) { | ||
var index = options && typeof options === 'object' ? options.callbackIndex : options; | ||
if (index == null) index = fn.length; | ||
var unstarTemplate = function(fn, options) { | ||
var index = (options && typeof options === 'object') ? options.callbackIndex : options; | ||
if (index == null) index = fn.length; | ||
var F = function F() { | ||
var cb = arguments[index]; | ||
if (typeof cb !== "function") { | ||
if (glob.allowBooleanPlaceholders && typeof cb === 'boolean') { | ||
if (cb) cb = util.defaultCallback;else return exports.future("", 0, null, wrapper.bind(this), index)(arguments); | ||
} else throw util.argError(fn.name, index, "function", typeof cb); | ||
} | ||
var g = fn.apply(this, arguments); | ||
run.call(this, fn, g, cb); | ||
}; | ||
// track the original name for stack frames | ||
F.__name__ = fn.name; | ||
return F; | ||
}; | ||
var F = function F() { | ||
var cb = arguments[index]; | ||
if (typeof cb !== "function") { | ||
if (glob.allowBooleanPlaceholders && typeof cb === 'boolean') { | ||
if (cb) cb = util.defaultCallback; | ||
else return exports.future("", 0, null, wrapper.bind(this), index)(arguments); | ||
} | ||
else throw util.argError(fn.name, index, "function", typeof cb); | ||
} | ||
var g = fn.apply(this, arguments); | ||
run.call(this, fn, g, cb); | ||
}; | ||
// track the original name for stack frames | ||
F.__name__ = fn.name; | ||
return F; | ||
} | ||
@@ -864,3 +864,3 @@ var unstarBody = unstarTemplate.toString(); | ||
function unstar(fn, index, arity) { | ||
var i = arity != null ? arity : index == null ? fn.length + 1 : fn.length; | ||
var i = arity != null ? arity : (index == null ? fn.length + 1 : fn.length); | ||
var unstarror = unstarrors[i] || (unstarrors[i] = makeUnstarror(i)); | ||
@@ -878,3 +878,3 @@ return unstarror(fn, index); | ||
Object.defineProperty(err, 'stack', { | ||
get: function () { | ||
get: function() { | ||
return stackTrace(this); | ||
@@ -908,3 +908,3 @@ } | ||
exports.await = function (file, line, object, property, index1, index2, returnArray) { | ||
exports.await = function(file, line, object, property, index1, index2, returnArray) { | ||
var bound = typeof property !== "function"; | ||
@@ -931,3 +931,3 @@ var fn = bound ? object[property] : property; | ||
exports.async = function (fn, index, arity) { | ||
exports.async = function(fn, index, arity) { | ||
if (typeof fn !== "function") throw util.typeError("cannot wrap function", "function", fn); | ||
@@ -937,9 +937,9 @@ var unstarred = unstar(fn, index, arity); | ||
return unstarred; | ||
}; | ||
} | ||
exports.new = function (file, line, constructor, index) { | ||
exports.new = function(file, line, constructor, index) { | ||
if (typeof constructor !== "function") throw util.typeError("cannot instantiate", "function", constructor); | ||
glob.frame = new Frame(file, line, constructor); | ||
var starred = star(constructor, index); | ||
return function* () { | ||
return function *() { | ||
var that = Object.create(constructor.prototype); | ||
@@ -953,3 +953,2 @@ yield starred.apply(that, arguments); | ||
require('./builtins'); | ||
},{"../future":3,"../util":6,"./builtins":4}],6:[function(require,module,exports){ | ||
@@ -959,8 +958,5 @@ (function (process,global){ | ||
// colors package does not work in browser - fails on reference to node's `process` global | ||
var idem = function (x) { | ||
return x; | ||
}; | ||
var idem = function(x) { return x; }; | ||
var colors; | ||
if (typeof process !== 'undefined' && !process.browser) { | ||
if (typeof(process) !== 'undefined' && !process.browser) { | ||
try { | ||
@@ -972,3 +968,3 @@ colors = require(idem('colors')); | ||
} | ||
if (!colors) colors = ['black', 'red', 'green', 'yellow', 'blue', 'magenta', 'cyan', 'white', 'gray'].reduce(function (r, c) { | ||
if (!colors) colors = ['black', 'red', 'green', 'yellow', 'blue', 'magenta', 'cyan', 'white', 'gray'].reduce(function(r, c) { | ||
r[c] = idem; | ||
@@ -1010,5 +1006,6 @@ return r; | ||
var secret = "_20c7abceb95c4eb88b7ca1895b1170d1"; | ||
var g = glob[secret] = glob[secret] || { context: {} }; | ||
var g = (glob[secret] = (glob[secret] || { context: {} })); | ||
if (runtime && g.runtime !== runtime) { | ||
if (g.runtime) console.warn("[STREAMLINE-RUNTIME] " + runtime + " runtime loaded on top of " + g.runtime);else g.runtime = runtime; | ||
if (g.runtime) console.warn("[STREAMLINE-RUNTIME] " + runtime + " runtime loaded on top of " + g.runtime); | ||
else g.runtime = runtime; | ||
} | ||
@@ -1024,9 +1021,9 @@ return g; | ||
var origPrepareStackTrace = Error.prepareStackTrace; | ||
if (origPrepareStackTrace) Error.prepareStackTrace = function (_, stack) { | ||
// eval stack frames from streamline-runtime fibers are botched: column number is 0, | ||
if (origPrepareStackTrace) Error.prepareStackTrace = function (_, stack) { | ||
// eval stack frames from streamline-runtime fibers are botched: column number is 0, | ||
// which causes an error in source-map-support.js / mapEvalOrigin. | ||
// So we filter them out. | ||
stack = stack.filter(function (frame) { | ||
stack = stack.filter(function(frame) { | ||
var origin = frame.isEval() && frame.getEvalOrigin(); | ||
return !(origin && /\bstreamline-runtime\b/.test(origin)); | ||
return (!(origin && /\bstreamline-runtime\b/.test(origin))); | ||
}); | ||
@@ -1039,7 +1036,4 @@ var result; | ||
} | ||
result = result.replace(/_\$\$(.*)\$\$\d*/g, function (all, x) { | ||
return x; | ||
}).replace(/Function\.(.*) \[as awaitWrapper-0\]/g, function (all, x) { | ||
return x; | ||
}); | ||
result = result.replace(/_\$\$(.*)\$\$\d*/g, function(all, x) { return x; }) | ||
.replace(/Function\.(.*) \[as awaitWrapper-0\]/g, function(all, x) { return x; }); | ||
return result; | ||
@@ -1050,3 +1044,3 @@ }; | ||
var _defRT; | ||
return _defRT || (_defRT = (function () { | ||
return _defRT || (_defRT = (function() { | ||
try { | ||
@@ -1074,3 +1068,3 @@ require(idem('fibers')); | ||
defaultCallback: defaultCallback, | ||
defaultRuntime: defaultRuntime | ||
defaultRuntime: defaultRuntime, | ||
}; | ||
@@ -1077,0 +1071,0 @@ var util = module.exports; |
@@ -40,2 +40,7 @@ "use strict"; | ||
options = util.getOptions(options); | ||
if (options.ignore && path && options.ignore(path)) { | ||
return { | ||
code: fs.readFileSync(path, 'utf8'), | ||
}; | ||
} | ||
return cacheSync.get(path, options, function() { | ||
@@ -42,0 +47,0 @@ options.filename = path; |
{ | ||
"name": "streamline", | ||
"description": "Asynchronous Javascript for dummies", | ||
"version": "2.0.2", | ||
"version": "2.0.3", | ||
"license": "MIT", | ||
@@ -18,4 +18,4 @@ "homepage": "http://github.com/Sage/streamlinejs", | ||
"colors": "^1.1.2", | ||
"babel-core": "^6.3.17", | ||
"babel-plugin-streamline": "^2.0.0", | ||
"babel-core": "^6.3.26", | ||
"babel-plugin-streamline": "^2.0.1", | ||
"babel-preset-es2015": "^6.3.13", | ||
@@ -22,0 +22,0 @@ "source-map-support": "^0.3.2", |
"use strict"; | ||
var babel = require('babel-core'); | ||
var streamline = require('babel-plugin-streamline'); | ||
var es2015 = require('babel-preset-es2015'); | ||
@@ -8,11 +10,12 @@ window.Streamline = { | ||
streamlineOptions.runtime = streamlineOptions.runtime || "callbacks"; | ||
var plugins = [[streamline, streamlineOptions]]; | ||
// remove regenerator plugin (last one in es2015 preset) if generators mode | ||
if (streamlineOptions.runtime === 'generators') es2015.plugins.pop(); | ||
return babel.transform(code, { | ||
plugins: [streamline], | ||
blacklist: streamlineOptions.runtime !== 'callbacks' ? ['regenerator'] : [], | ||
extra: { | ||
streamline: streamlineOptions, | ||
}, | ||
plugins: plugins, | ||
presets: es2015, | ||
}).code; | ||
}, | ||
modules: { | ||
'streamline-runtime/lib/callbacks/regenerator' : require('streamline-runtime/lib/callbacks/regenerator'), | ||
'streamline-runtime/lib/callbacks/runtime': require('streamline-runtime/lib/callbacks/runtime'), | ||
@@ -19,0 +22,0 @@ 'streamline-runtime/lib/callbacks/builtins': require('streamline-runtime/lib/callbacks/builtins'), |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
831411
18705
Updatedbabel-core@^6.3.26