From d677b60249a18cd600c22858c7c7d567d7ede30a Mon Sep 17 00:00:00 2001 From: Tobias Koppers Date: Fri, 4 Dec 2020 14:14:21 +0100 Subject: [PATCH 1/2] allow to use tapable in browser avoid arrow functions in favor of normal functions --- lib/AsyncParallelBailHook.js | 2 +- lib/HookCodeFactory.js | 40 ++-- .../__snapshots__/HookCodeFactory.js.snap | 208 +++++++++--------- lib/util-browser.js | 16 ++ package.json | 3 + 5 files changed, 146 insertions(+), 123 deletions(-) create mode 100644 lib/util-browser.js diff --git a/lib/AsyncParallelBailHook.js b/lib/AsyncParallelBailHook.js index c2d08e5..45eca33 100644 --- a/lib/AsyncParallelBailHook.js +++ b/lib/AsyncParallelBailHook.js @@ -11,7 +11,7 @@ class AsyncParallelBailHookCodeFactory extends HookCodeFactory { content({ onError, onResult, onDone }) { let code = ""; code += `var _results = new Array(${this.options.taps.length});\n`; - code += "var _checkDone = () => {\n"; + code += "var _checkDone = function() {\n"; code += "for(var i = 0; i < _results.length; i++) {\n"; code += "var item = _results[i];\n"; code += "if(item === undefined) return false;\n"; diff --git a/lib/HookCodeFactory.js b/lib/HookCodeFactory.js index e327a08..ccdbdba 100644 --- a/lib/HookCodeFactory.js +++ b/lib/HookCodeFactory.js @@ -55,17 +55,18 @@ class HookCodeFactory { }); let code = ""; code += '"use strict";\n'; - code += "return new Promise((_resolve, _reject) => {\n"; + code += this.header(); + code += "return new Promise(function(_resolve, _reject) {\n"; if (errorHelperUsed) { code += "var _sync = true;\n"; code += "function _error(_err) {\n"; code += "if(_sync)\n"; - code += "_resolve(Promise.resolve().then(() => { throw _err; }));\n"; + code += + "_resolve(Promise.resolve().then(function() { throw _err; }));\n"; code += "else\n"; code += "_reject(_err);\n"; code += "};\n"; } - code += this.header(); code += content; if (errorHelperUsed) { code += "_sync = false;\n"; @@ -100,7 +101,16 @@ class HookCodeFactory { const onError = options.onError; const onResult = options.onResult; const onDone = options.onDone; - return this.content( + let code = ""; + for (let i = 0; i < this.options.interceptors.length; i++) { + const interceptor = this.options.interceptors[i]; + if (interceptor.call) { + code += `${this.getInterceptor(i)}.call(${this.args({ + before: interceptor.context ? "_context" : undefined + })});\n`; + } + } + code += this.content( Object.assign(options, { onError: onError && @@ -143,6 +153,7 @@ class HookCodeFactory { }) }) ); + return code; } else { return this.content(options); } @@ -160,14 +171,6 @@ class HookCodeFactory { code += "var _taps = this.taps;\n"; code += "var _interceptors = this.interceptors;\n"; } - for (let i = 0; i < this.options.interceptors.length; i++) { - const interceptor = this.options.interceptors[i]; - if (interceptor.call) { - code += `${this.getInterceptor(i)}.call(${this.args({ - before: interceptor.context ? "_context" : undefined - })});\n`; - } - } return code; } @@ -227,8 +230,9 @@ class HookCodeFactory { break; case "async": let cbCode = ""; - if (onResult) cbCode += `(_err${tapIndex}, _result${tapIndex}) => {\n`; - else cbCode += `_err${tapIndex} => {\n`; + if (onResult) + cbCode += `function(_err${tapIndex}, _result${tapIndex}) {\n`; + else cbCode += `function(_err${tapIndex}) {\n`; cbCode += `if(_err${tapIndex}) {\n`; cbCode += onError(`_err${tapIndex}`); cbCode += "} else {\n"; @@ -252,7 +256,7 @@ class HookCodeFactory { })});\n`; code += `if (!_promise${tapIndex} || !_promise${tapIndex}.then)\n`; code += ` throw new Error('Tap function (tapPromise) did not return promise (returned ' + _promise${tapIndex} + ')');\n`; - code += `_promise${tapIndex}.then(_result${tapIndex} => {\n`; + code += `_promise${tapIndex}.then(function(_result${tapIndex}) {\n`; code += `_hasResult${tapIndex} = true;\n`; if (onResult) { code += onResult(`_result${tapIndex}`); @@ -260,7 +264,7 @@ class HookCodeFactory { if (onDone) { code += onDone(); } - code += `}, _err${tapIndex} => {\n`; + code += `}, function(_err${tapIndex}) {\n`; code += `if(_hasResult${tapIndex}) throw _err${tapIndex};\n`; code += onError(`_err${tapIndex}`); code += "});\n"; @@ -322,7 +326,7 @@ class HookCodeFactory { const syncOnly = this.options.taps.every(t => t.type === "sync"); let code = ""; if (!syncOnly) { - code += "var _looper = () => {\n"; + code += "var _looper = function() {\n"; code += "var _loopAsync = false;\n"; } code += "var _loop;\n"; @@ -388,7 +392,7 @@ class HookCodeFactory { code += "do {\n"; code += `var _counter = ${this.options.taps.length};\n`; if (onDone) { - code += "var _done = () => {\n"; + code += "var _done = function() {\n"; code += onDone(); code += "};\n"; } diff --git a/lib/__tests__/__snapshots__/HookCodeFactory.js.snap b/lib/__tests__/__snapshots__/HookCodeFactory.js.snap index 4f68317..5e323e4 100644 --- a/lib/__tests__/__snapshots__/HookCodeFactory.js.snap +++ b/lib/__tests__/__snapshots__/HookCodeFactory.js.snap @@ -2,7 +2,7 @@ exports[`HookCodeFactory callTap (no args, no intercept) async with onResult 1`] = ` "var _fn1 = _x[1]; -_fn1((_err1, _result1) => { +_fn1(function(_err1, _result1) { if(_err1) { onError(_err1); } else { @@ -14,7 +14,7 @@ onResult(_result1); exports[`HookCodeFactory callTap (no args, no intercept) async with onResult 2`] = ` "var _fn1 = _x[1]; -_fn1((_err1, _result1) => { +_fn1(function(_err1, _result1) { if (_err1) { onError(_err1); } else { @@ -26,7 +26,7 @@ _fn1((_err1, _result1) => { exports[`HookCodeFactory callTap (no args, no intercept) async without onResult 1`] = ` "var _fn1 = _x[1]; -_fn1(_err1 => { +_fn1(function(_err1) { if(_err1) { onError(_err1); } else { @@ -38,7 +38,7 @@ onDone(); exports[`HookCodeFactory callTap (no args, no intercept) async without onResult 2`] = ` "var _fn1 = _x[1]; -_fn1(_err1 => { +_fn1(function(_err1) { if (_err1) { onError(_err1); } else { @@ -54,10 +54,10 @@ var _hasResult2 = false; var _promise2 = _fn2(); if (!_promise2 || !_promise2.then) throw new Error('Tap function (tapPromise) did not return promise (returned ' + _promise2 + ')'); -_promise2.then(_result2 => { +_promise2.then(function(_result2) { _hasResult2 = true; onResult(_result2); -}, _err2 => { +}, function(_err2) { if(_hasResult2) throw _err2; onError(_err2); }); @@ -75,11 +75,11 @@ if (!_promise2 || !_promise2.then) \\")\\" ); _promise2.then( - _result2 => { + function(_result2) { _hasResult2 = true; onResult(_result2); }, - _err2 => { + function(_err2) { if (_hasResult2) throw _err2; onError(_err2); } @@ -93,10 +93,10 @@ var _hasResult2 = false; var _promise2 = _fn2(); if (!_promise2 || !_promise2.then) throw new Error('Tap function (tapPromise) did not return promise (returned ' + _promise2 + ')'); -_promise2.then(_result2 => { +_promise2.then(function(_result2) { _hasResult2 = true; onDone(); -}, _err2 => { +}, function(_err2) { if(_hasResult2) throw _err2; onError(_err2); }); @@ -114,11 +114,11 @@ if (!_promise2 || !_promise2.then) \\")\\" ); _promise2.then( - _result2 => { + function(_result2) { _hasResult2 = true; onDone(); }, - _err2 => { + function(_err2) { if (_hasResult2) throw _err2; onError(_err2); } @@ -188,7 +188,7 @@ if (!_hasError0) { exports[`HookCodeFactory callTap (with args, no intercept) async with onResult 1`] = ` "var _fn1 = _x[1]; -_fn1(a, b, c, (_err1, _result1) => { +_fn1(a, b, c, function(_err1, _result1) { if(_err1) { onError(_err1); } else { @@ -200,7 +200,7 @@ onResult(_result1); exports[`HookCodeFactory callTap (with args, no intercept) async with onResult 2`] = ` "var _fn1 = _x[1]; -_fn1(a, b, c, (_err1, _result1) => { +_fn1(a, b, c, function(_err1, _result1) { if (_err1) { onError(_err1); } else { @@ -212,7 +212,7 @@ _fn1(a, b, c, (_err1, _result1) => { exports[`HookCodeFactory callTap (with args, no intercept) async without onResult 1`] = ` "var _fn1 = _x[1]; -_fn1(a, b, c, _err1 => { +_fn1(a, b, c, function(_err1) { if(_err1) { onError(_err1); } else { @@ -224,7 +224,7 @@ onDone(); exports[`HookCodeFactory callTap (with args, no intercept) async without onResult 2`] = ` "var _fn1 = _x[1]; -_fn1(a, b, c, _err1 => { +_fn1(a, b, c, function(_err1) { if (_err1) { onError(_err1); } else { @@ -240,10 +240,10 @@ var _hasResult2 = false; var _promise2 = _fn2(a, b, c); if (!_promise2 || !_promise2.then) throw new Error('Tap function (tapPromise) did not return promise (returned ' + _promise2 + ')'); -_promise2.then(_result2 => { +_promise2.then(function(_result2) { _hasResult2 = true; onResult(_result2); -}, _err2 => { +}, function(_err2) { if(_hasResult2) throw _err2; onError(_err2); }); @@ -261,11 +261,11 @@ if (!_promise2 || !_promise2.then) \\")\\" ); _promise2.then( - _result2 => { + function(_result2) { _hasResult2 = true; onResult(_result2); }, - _err2 => { + function(_err2) { if (_hasResult2) throw _err2; onError(_err2); } @@ -279,10 +279,10 @@ var _hasResult2 = false; var _promise2 = _fn2(a, b, c); if (!_promise2 || !_promise2.then) throw new Error('Tap function (tapPromise) did not return promise (returned ' + _promise2 + ')'); -_promise2.then(_result2 => { +_promise2.then(function(_result2) { _hasResult2 = true; onDone(); -}, _err2 => { +}, function(_err2) { if(_hasResult2) throw _err2; onError(_err2); }); @@ -300,11 +300,11 @@ if (!_promise2 || !_promise2.then) \\")\\" ); _promise2.then( - _result2 => { + function(_result2) { _hasResult2 = true; onDone(); }, - _err2 => { + function(_err2) { if (_hasResult2) throw _err2; onError(_err2); } @@ -377,7 +377,7 @@ exports[`HookCodeFactory callTap (with args, with intercept) async with onResult _interceptors[0].tap(_tap1); _interceptors[1].tap(_tap1); var _fn1 = _x[1]; -_fn1(a, b, c, (_err1, _result1) => { +_fn1(a, b, c, function(_err1, _result1) { if(_err1) { onError(_err1); } else { @@ -392,7 +392,7 @@ exports[`HookCodeFactory callTap (with args, with intercept) async with onResult _interceptors[0].tap(_tap1); _interceptors[1].tap(_tap1); var _fn1 = _x[1]; -_fn1(a, b, c, (_err1, _result1) => { +_fn1(a, b, c, function(_err1, _result1) { if (_err1) { onError(_err1); } else { @@ -407,7 +407,7 @@ exports[`HookCodeFactory callTap (with args, with intercept) async without onRes _interceptors[0].tap(_tap1); _interceptors[1].tap(_tap1); var _fn1 = _x[1]; -_fn1(a, b, c, _err1 => { +_fn1(a, b, c, function(_err1) { if(_err1) { onError(_err1); } else { @@ -422,7 +422,7 @@ exports[`HookCodeFactory callTap (with args, with intercept) async without onRes _interceptors[0].tap(_tap1); _interceptors[1].tap(_tap1); var _fn1 = _x[1]; -_fn1(a, b, c, _err1 => { +_fn1(a, b, c, function(_err1) { if (_err1) { onError(_err1); } else { @@ -441,10 +441,10 @@ var _hasResult2 = false; var _promise2 = _fn2(a, b, c); if (!_promise2 || !_promise2.then) throw new Error('Tap function (tapPromise) did not return promise (returned ' + _promise2 + ')'); -_promise2.then(_result2 => { +_promise2.then(function(_result2) { _hasResult2 = true; onResult(_result2); -}, _err2 => { +}, function(_err2) { if(_hasResult2) throw _err2; onError(_err2); }); @@ -465,11 +465,11 @@ if (!_promise2 || !_promise2.then) \\")\\" ); _promise2.then( - _result2 => { + function(_result2) { _hasResult2 = true; onResult(_result2); }, - _err2 => { + function(_err2) { if (_hasResult2) throw _err2; onError(_err2); } @@ -486,10 +486,10 @@ var _hasResult2 = false; var _promise2 = _fn2(a, b, c); if (!_promise2 || !_promise2.then) throw new Error('Tap function (tapPromise) did not return promise (returned ' + _promise2 + ')'); -_promise2.then(_result2 => { +_promise2.then(function(_result2) { _hasResult2 = true; onDone(); -}, _err2 => { +}, function(_err2) { if(_hasResult2) throw _err2; onError(_err2); }); @@ -510,11 +510,11 @@ if (!_promise2 || !_promise2.then) \\")\\" ); _promise2.then( - _result2 => { + function(_result2) { _hasResult2 = true; onDone(); }, - _err2 => { + function(_err2) { if (_hasResult2) throw _err2; onError(_err2); } @@ -595,7 +595,7 @@ if (!_hasError0) { `; exports[`HookCodeFactory taps (mixed) callTapsLooping 1`] = ` -"var _looper = () => { +"var _looper = function() { var _loopAsync = false; var _loop; do { @@ -606,7 +606,7 @@ var _hasResult2 = false; var _promise2 = _fn2(a, b, c); if (!_promise2 || !_promise2.then) throw new Error('Tap function (tapPromise) did not return promise (returned ' + _promise2 + ')'); -_promise2.then(_result2 => { +_promise2.then(function(_result2) { _hasResult2 = true; if(_result2 !== undefined) { _loop = true; @@ -616,7 +616,7 @@ if(!_loop) { onDone(); } } -}, _err2 => { +}, function(_err2) { if(_hasResult2) throw _err2; onError(2, _err2); }); @@ -635,7 +635,7 @@ _loop = true; if(_loopAsync) _looper(); } else { var _fn1 = _x[1]; -_fn1(a, b, c, (_err1, _result1) => { +_fn1(a, b, c, function(_err1, _result1) { if(_err1) { onError(1, _err1); } else { @@ -657,7 +657,7 @@ _looper(); `; exports[`HookCodeFactory taps (mixed) callTapsLooping 2`] = ` -"var _looper = () => { +"var _looper = function() { var _loopAsync = false; var _loop; do { @@ -673,7 +673,7 @@ exports[`HookCodeFactory taps (mixed) callTapsLooping 2`] = ` \\")\\" ); _promise2.then( - _result2 => { + function(_result2) { _hasResult2 = true; if (_result2 !== undefined) { _loop = true; @@ -684,7 +684,7 @@ exports[`HookCodeFactory taps (mixed) callTapsLooping 2`] = ` } } }, - _err2 => { + function(_err2) { if (_hasResult2) throw _err2; onError(2, _err2); } @@ -704,7 +704,7 @@ exports[`HookCodeFactory taps (mixed) callTapsLooping 2`] = ` if (_loopAsync) _looper(); } else { var _fn1 = _x[1]; - _fn1(a, b, c, (_err1, _result1) => { + _fn1(a, b, c, function(_err1, _result1) { if (_err1) { onError(1, _err1); } else { @@ -728,7 +728,7 @@ _looper(); exports[`HookCodeFactory taps (mixed) callTapsParallel 1`] = ` "do { var _counter = 3; -var _done = () => { +var _done = function() { onDone(); }; if(_counter <= 0) break; @@ -744,7 +744,7 @@ _done(); } if(_counter <= 0) break; var _fn1 = _x[1]; -_fn1(a, b, c, (_err1, _result1) => { +_fn1(a, b, c, function(_err1, _result1) { if(_err1) { if(_counter > 0) { onError(1, _err1); @@ -766,7 +766,7 @@ var _hasResult2 = false; var _promise2 = _fn2(a, b, c); if (!_promise2 || !_promise2.then) throw new Error('Tap function (tapPromise) did not return promise (returned ' + _promise2 + ')'); -_promise2.then(_result2 => { +_promise2.then(function(_result2) { _hasResult2 = true; if(_counter > 0) { onResult(2, _result2, () => { @@ -776,7 +776,7 @@ _counter = 0; _done(); }); } -}, _err2 => { +}, function(_err2) { if(_hasResult2) throw _err2; if(_counter > 0) { onError(2, _err2); @@ -789,7 +789,7 @@ onError(2, _err2); exports[`HookCodeFactory taps (mixed) callTapsParallel 2`] = ` "do { var _counter = 3; - var _done = () => { + var _done = function() { onDone(); }; if (_counter <= 0) break; @@ -810,7 +810,7 @@ exports[`HookCodeFactory taps (mixed) callTapsParallel 2`] = ` } if (_counter <= 0) break; var _fn1 = _x[1]; - _fn1(a, b, c, (_err1, _result1) => { + _fn1(a, b, c, function(_err1, _result1) { if (_err1) { if (_counter > 0) { onError(1, _err1); @@ -842,7 +842,7 @@ exports[`HookCodeFactory taps (mixed) callTapsParallel 2`] = ` \\")\\" ); _promise2.then( - _result2 => { + function(_result2) { _hasResult2 = true; if (_counter > 0) { onResult( @@ -858,7 +858,7 @@ exports[`HookCodeFactory taps (mixed) callTapsParallel 2`] = ` ); } }, - _err2 => { + function(_err2) { if (_hasResult2) throw _err2; if (_counter > 0) { onError(2, _err2); @@ -876,14 +876,14 @@ var _hasResult2 = false; var _promise2 = _fn2(a, b, c); if (!_promise2 || !_promise2.then) throw new Error('Tap function (tapPromise) did not return promise (returned ' + _promise2 + ')'); -_promise2.then(_result2 => { +_promise2.then(function(_result2) { _hasResult2 = true; onResult(2, _result2, () => { onDone(); }, () => { onDone(); }); -}, _err2 => { +}, function(_err2) { if(_hasResult2) throw _err2; onError(2, _err2); }); @@ -892,7 +892,7 @@ var _fn0 = _x[0]; var _result0 = _fn0(a, b, c); onResult(0, _result0, () => { var _fn1 = _x[1]; -_fn1(a, b, c, (_err1, _result1) => { +_fn1(a, b, c, function(_err1, _result1) { if(_err1) { onError(1, _err1); } else { @@ -921,7 +921,7 @@ exports[`HookCodeFactory taps (mixed) callTapsSeries 2`] = ` \\")\\" ); _promise2.then( - _result2 => { + function(_result2) { _hasResult2 = true; onResult( 2, @@ -934,7 +934,7 @@ exports[`HookCodeFactory taps (mixed) callTapsSeries 2`] = ` } ); }, - _err2 => { + function(_err2) { if (_hasResult2) throw _err2; onError(2, _err2); } @@ -947,7 +947,7 @@ onResult( _result0, () => { var _fn1 = _x[1]; - _fn1(a, b, c, (_err1, _result1) => { + _fn1(a, b, c, function(_err1, _result1) { if (_err1) { onError(1, _err1); } else { @@ -972,7 +972,7 @@ onResult( `; exports[`HookCodeFactory taps (mixed2) callTapsLooping 1`] = ` -"var _looper = () => { +"var _looper = function() { var _loopAsync = false; var _loop; do { @@ -1003,7 +1003,7 @@ var _hasResult1 = false; var _promise1 = _fn1(a, b, c); if (!_promise1 || !_promise1.then) throw new Error('Tap function (tapPromise) did not return promise (returned ' + _promise1 + ')'); -_promise1.then(_result1 => { +_promise1.then(function(_result1) { _hasResult1 = true; if(_result1 !== undefined) { _loop = true; @@ -1011,13 +1011,13 @@ if(_loopAsync) _looper(); } else { _next1(); } -}, _err1 => { +}, function(_err1) { if(_hasResult1) throw _err1; onError(1, _err1); }); } var _fn0 = _x[0]; -_fn0(a, b, c, (_err0, _result0) => { +_fn0(a, b, c, function(_err0, _result0) { if(_err0) { onError(0, _err0); } else { @@ -1037,7 +1037,7 @@ _looper(); `; exports[`HookCodeFactory taps (mixed2) callTapsLooping 2`] = ` -"var _looper = () => { +"var _looper = function() { var _loopAsync = false; var _loop; do { @@ -1073,7 +1073,7 @@ exports[`HookCodeFactory taps (mixed2) callTapsLooping 2`] = ` \\")\\" ); _promise1.then( - _result1 => { + function(_result1) { _hasResult1 = true; if (_result1 !== undefined) { _loop = true; @@ -1082,14 +1082,14 @@ exports[`HookCodeFactory taps (mixed2) callTapsLooping 2`] = ` _next1(); } }, - _err1 => { + function(_err1) { if (_hasResult1) throw _err1; onError(1, _err1); } ); } var _fn0 = _x[0]; - _fn0(a, b, c, (_err0, _result0) => { + _fn0(a, b, c, function(_err0, _result0) { if (_err0) { onError(0, _err0); } else { @@ -1111,12 +1111,12 @@ _looper(); exports[`HookCodeFactory taps (mixed2) callTapsParallel 1`] = ` "do { var _counter = 3; -var _done = () => { +var _done = function() { onDone(); }; if(_counter <= 0) break; var _fn0 = _x[0]; -_fn0(a, b, c, (_err0, _result0) => { +_fn0(a, b, c, function(_err0, _result0) { if(_err0) { if(_counter > 0) { onError(0, _err0); @@ -1138,7 +1138,7 @@ var _hasResult1 = false; var _promise1 = _fn1(a, b, c); if (!_promise1 || !_promise1.then) throw new Error('Tap function (tapPromise) did not return promise (returned ' + _promise1 + ')'); -_promise1.then(_result1 => { +_promise1.then(function(_result1) { _hasResult1 = true; if(_counter > 0) { onResult(1, _result1, () => { @@ -1148,7 +1148,7 @@ _counter = 0; _done(); }); } -}, _err1 => { +}, function(_err1) { if(_hasResult1) throw _err1; if(_counter > 0) { onError(1, _err1); @@ -1172,12 +1172,12 @@ _done(); exports[`HookCodeFactory taps (mixed2) callTapsParallel 2`] = ` "do { var _counter = 3; - var _done = () => { + var _done = function() { onDone(); }; if (_counter <= 0) break; var _fn0 = _x[0]; - _fn0(a, b, c, (_err0, _result0) => { + _fn0(a, b, c, function(_err0, _result0) { if (_err0) { if (_counter > 0) { onError(0, _err0); @@ -1209,7 +1209,7 @@ exports[`HookCodeFactory taps (mixed2) callTapsParallel 2`] = ` \\")\\" ); _promise1.then( - _result1 => { + function(_result1) { _hasResult1 = true; if (_counter > 0) { onResult( @@ -1225,7 +1225,7 @@ exports[`HookCodeFactory taps (mixed2) callTapsParallel 2`] = ` ); } }, - _err1 => { + function(_err1) { if (_hasResult1) throw _err1; if (_counter > 0) { onError(1, _err1); @@ -1276,20 +1276,20 @@ var _hasResult1 = false; var _promise1 = _fn1(a, b, c); if (!_promise1 || !_promise1.then) throw new Error('Tap function (tapPromise) did not return promise (returned ' + _promise1 + ')'); -_promise1.then(_result1 => { +_promise1.then(function(_result1) { _hasResult1 = true; onResult(1, _result1, () => { _next1(); }, () => { onDone(); }); -}, _err1 => { +}, function(_err1) { if(_hasResult1) throw _err1; onError(1, _err1); }); } var _fn0 = _x[0]; -_fn0(a, b, c, (_err0, _result0) => { +_fn0(a, b, c, function(_err0, _result0) { if(_err0) { onError(0, _err0); } else { @@ -1337,7 +1337,7 @@ function _next0() { \\")\\" ); _promise1.then( - _result1 => { + function(_result1) { _hasResult1 = true; onResult( 1, @@ -1350,14 +1350,14 @@ function _next0() { } ); }, - _err1 => { + function(_err1) { if (_hasResult1) throw _err1; onError(1, _err1); } ); } var _fn0 = _x[0]; -_fn0(a, b, c, (_err0, _result0) => { +_fn0(a, b, c, function(_err0, _result0) { if (_err0) { onError(0, _err0); } else { @@ -1437,7 +1437,7 @@ do { exports[`HookCodeFactory taps (multiple sync) callTapsParallel 1`] = ` "do { var _counter = 3; -var _done = () => { +var _done = function() { onDone(); }; if(_counter <= 0) break; @@ -1480,7 +1480,7 @@ _done(); exports[`HookCodeFactory taps (multiple sync) callTapsParallel 2`] = ` "do { var _counter = 3; - var _done = () => { + var _done = function() { onDone(); }; if (_counter <= 0) break; @@ -1627,13 +1627,13 @@ exports[`HookCodeFactory taps (none) callTapsSeries 2`] = ` `; exports[`HookCodeFactory taps (single async) callTapsLooping 1`] = ` -"var _looper = () => { +"var _looper = function() { var _loopAsync = false; var _loop; do { _loop = false; var _fn0 = _x[0]; -_fn0(a, b, c, (_err0, _result0) => { +_fn0(a, b, c, function(_err0, _result0) { if(_err0) { onError(0, _err0); } else { @@ -1655,13 +1655,13 @@ _looper(); `; exports[`HookCodeFactory taps (single async) callTapsLooping 2`] = ` -"var _looper = () => { +"var _looper = function() { var _loopAsync = false; var _loop; do { _loop = false; var _fn0 = _x[0]; - _fn0(a, b, c, (_err0, _result0) => { + _fn0(a, b, c, function(_err0, _result0) { if (_err0) { onError(0, _err0); } else { @@ -1684,7 +1684,7 @@ _looper(); exports[`HookCodeFactory taps (single async) callTapsParallel 1`] = ` "var _fn0 = _x[0]; -_fn0(a, b, c, (_err0, _result0) => { +_fn0(a, b, c, function(_err0, _result0) { if(_err0) { onError(0, _err0); } else { @@ -1700,7 +1700,7 @@ onDone(); exports[`HookCodeFactory taps (single async) callTapsParallel 2`] = ` "var _fn0 = _x[0]; -_fn0(a, b, c, (_err0, _result0) => { +_fn0(a, b, c, function(_err0, _result0) { if (_err0) { onError(0, _err0); } else { @@ -1721,7 +1721,7 @@ _fn0(a, b, c, (_err0, _result0) => { exports[`HookCodeFactory taps (single async) callTapsSeries 1`] = ` "var _fn0 = _x[0]; -_fn0(a, b, c, (_err0, _result0) => { +_fn0(a, b, c, function(_err0, _result0) { if(_err0) { onError(0, _err0); } else { @@ -1737,7 +1737,7 @@ onDone(); exports[`HookCodeFactory taps (single async) callTapsSeries 2`] = ` "var _fn0 = _x[0]; -_fn0(a, b, c, (_err0, _result0) => { +_fn0(a, b, c, function(_err0, _result0) { if (_err0) { onError(0, _err0); } else { @@ -1757,7 +1757,7 @@ _fn0(a, b, c, (_err0, _result0) => { `; exports[`HookCodeFactory taps (single promise) callTapsLooping 1`] = ` -"var _looper = () => { +"var _looper = function() { var _loopAsync = false; var _loop; do { @@ -1767,7 +1767,7 @@ var _hasResult0 = false; var _promise0 = _fn0(a, b, c); if (!_promise0 || !_promise0.then) throw new Error('Tap function (tapPromise) did not return promise (returned ' + _promise0 + ')'); -_promise0.then(_result0 => { +_promise0.then(function(_result0) { _hasResult0 = true; if(_result0 !== undefined) { _loop = true; @@ -1777,7 +1777,7 @@ if(!_loop) { onDone(); } } -}, _err0 => { +}, function(_err0) { if(_hasResult0) throw _err0; onError(0, _err0); }); @@ -1789,7 +1789,7 @@ _looper(); `; exports[`HookCodeFactory taps (single promise) callTapsLooping 2`] = ` -"var _looper = () => { +"var _looper = function() { var _loopAsync = false; var _loop; do { @@ -1804,7 +1804,7 @@ exports[`HookCodeFactory taps (single promise) callTapsLooping 2`] = ` \\")\\" ); _promise0.then( - _result0 => { + function(_result0) { _hasResult0 = true; if (_result0 !== undefined) { _loop = true; @@ -1815,7 +1815,7 @@ exports[`HookCodeFactory taps (single promise) callTapsLooping 2`] = ` } } }, - _err0 => { + function(_err0) { if (_hasResult0) throw _err0; onError(0, _err0); } @@ -1833,14 +1833,14 @@ var _hasResult0 = false; var _promise0 = _fn0(a, b, c); if (!_promise0 || !_promise0.then) throw new Error('Tap function (tapPromise) did not return promise (returned ' + _promise0 + ')'); -_promise0.then(_result0 => { +_promise0.then(function(_result0) { _hasResult0 = true; onResult(0, _result0, () => { onDone(); }, () => { onDone(); }); -}, _err0 => { +}, function(_err0) { if(_hasResult0) throw _err0; onError(0, _err0); }); @@ -1858,7 +1858,7 @@ if (!_promise0 || !_promise0.then) \\")\\" ); _promise0.then( - _result0 => { + function(_result0) { _hasResult0 = true; onResult( 0, @@ -1871,7 +1871,7 @@ _promise0.then( } ); }, - _err0 => { + function(_err0) { if (_hasResult0) throw _err0; onError(0, _err0); } @@ -1885,14 +1885,14 @@ var _hasResult0 = false; var _promise0 = _fn0(a, b, c); if (!_promise0 || !_promise0.then) throw new Error('Tap function (tapPromise) did not return promise (returned ' + _promise0 + ')'); -_promise0.then(_result0 => { +_promise0.then(function(_result0) { _hasResult0 = true; onResult(0, _result0, () => { onDone(); }, () => { onDone(); }); -}, _err0 => { +}, function(_err0) { if(_hasResult0) throw _err0; onError(0, _err0); }); @@ -1910,7 +1910,7 @@ if (!_promise0 || !_promise0.then) \\")\\" ); _promise0.then( - _result0 => { + function(_result0) { _hasResult0 = true; onResult( 0, @@ -1923,7 +1923,7 @@ _promise0.then( } ); }, - _err0 => { + function(_err0) { if (_hasResult0) throw _err0; onError(0, _err0); } diff --git a/lib/util-browser.js b/lib/util-browser.js new file mode 100644 index 0000000..ee4fb9a --- /dev/null +++ b/lib/util-browser.js @@ -0,0 +1,16 @@ +/* + MIT License http://www.opensource.org/licenses/mit-license.php + Author Tobias Koppers @sokra +*/ +"use strict"; + +exports.deprecate = (fn, msg) => { + let once = true; + return function() { + if (once) { + console.warn("DeprecationWarning: " + msg); + once = false; + } + return fn.apply(this, arguments); + }; +}; diff --git a/package.json b/package.json index 98098c4..fb71778 100644 --- a/package.json +++ b/package.json @@ -27,6 +27,9 @@ ], "main": "lib/index.js", "types": "./tapable.d.ts", + "browser": { + "util": "./lib/util-browser.js" + }, "scripts": { "test": "jest", "travis": "yarn pretty-lint && jest --coverage && codecov", From eee843a900a9ea62684d7cca09e65a13cb525198 Mon Sep 17 00:00:00 2001 From: Tobias Koppers Date: Fri, 4 Dec 2020 14:19:31 +0100 Subject: [PATCH 2/2] flag function in good path for eager parsing --- lib/HookCodeFactory.js | 24 +-- .../__snapshots__/HookCodeFactory.js.snap | 148 +++++++++--------- 2 files changed, 86 insertions(+), 86 deletions(-) diff --git a/lib/HookCodeFactory.js b/lib/HookCodeFactory.js index ccdbdba..c9f5340 100644 --- a/lib/HookCodeFactory.js +++ b/lib/HookCodeFactory.js @@ -56,13 +56,13 @@ class HookCodeFactory { let code = ""; code += '"use strict";\n'; code += this.header(); - code += "return new Promise(function(_resolve, _reject) {\n"; + code += "return new Promise((function(_resolve, _reject) {\n"; if (errorHelperUsed) { code += "var _sync = true;\n"; code += "function _error(_err) {\n"; code += "if(_sync)\n"; code += - "_resolve(Promise.resolve().then(function() { throw _err; }));\n"; + "_resolve(Promise.resolve().then((function() { throw _err; })));\n"; code += "else\n"; code += "_reject(_err);\n"; code += "};\n"; @@ -71,7 +71,7 @@ class HookCodeFactory { if (errorHelperUsed) { code += "_sync = false;\n"; } - code += "});\n"; + code += "}));\n"; fn = new Function(this.args(), code); break; } @@ -231,8 +231,8 @@ class HookCodeFactory { case "async": let cbCode = ""; if (onResult) - cbCode += `function(_err${tapIndex}, _result${tapIndex}) {\n`; - else cbCode += `function(_err${tapIndex}) {\n`; + cbCode += `(function(_err${tapIndex}, _result${tapIndex}) {\n`; + else cbCode += `(function(_err${tapIndex}) {\n`; cbCode += `if(_err${tapIndex}) {\n`; cbCode += onError(`_err${tapIndex}`); cbCode += "} else {\n"; @@ -243,7 +243,7 @@ class HookCodeFactory { cbCode += onDone(); } cbCode += "}\n"; - cbCode += "}"; + cbCode += "})"; code += `_fn${tapIndex}(${this.args({ before: tap.context ? "_context" : undefined, after: cbCode @@ -256,7 +256,7 @@ class HookCodeFactory { })});\n`; code += `if (!_promise${tapIndex} || !_promise${tapIndex}.then)\n`; code += ` throw new Error('Tap function (tapPromise) did not return promise (returned ' + _promise${tapIndex} + ')');\n`; - code += `_promise${tapIndex}.then(function(_result${tapIndex}) {\n`; + code += `_promise${tapIndex}.then((function(_result${tapIndex}) {\n`; code += `_hasResult${tapIndex} = true;\n`; if (onResult) { code += onResult(`_result${tapIndex}`); @@ -264,7 +264,7 @@ class HookCodeFactory { if (onDone) { code += onDone(); } - code += `}, function(_err${tapIndex}) {\n`; + code += `}), function(_err${tapIndex}) {\n`; code += `if(_hasResult${tapIndex}) throw _err${tapIndex};\n`; code += onError(`_err${tapIndex}`); code += "});\n"; @@ -326,7 +326,7 @@ class HookCodeFactory { const syncOnly = this.options.taps.every(t => t.type === "sync"); let code = ""; if (!syncOnly) { - code += "var _looper = function() {\n"; + code += "var _looper = (function() {\n"; code += "var _loopAsync = false;\n"; } code += "var _loop;\n"; @@ -367,7 +367,7 @@ class HookCodeFactory { code += "} while(_loop);\n"; if (!syncOnly) { code += "_loopAsync = true;\n"; - code += "};\n"; + code += "});\n"; code += "_looper();\n"; } return code; @@ -392,9 +392,9 @@ class HookCodeFactory { code += "do {\n"; code += `var _counter = ${this.options.taps.length};\n`; if (onDone) { - code += "var _done = function() {\n"; + code += "var _done = (function() {\n"; code += onDone(); - code += "};\n"; + code += "});\n"; } for (let i = 0; i < this.options.taps.length; i++) { const done = () => { diff --git a/lib/__tests__/__snapshots__/HookCodeFactory.js.snap b/lib/__tests__/__snapshots__/HookCodeFactory.js.snap index 5e323e4..5f15542 100644 --- a/lib/__tests__/__snapshots__/HookCodeFactory.js.snap +++ b/lib/__tests__/__snapshots__/HookCodeFactory.js.snap @@ -2,13 +2,13 @@ exports[`HookCodeFactory callTap (no args, no intercept) async with onResult 1`] = ` "var _fn1 = _x[1]; -_fn1(function(_err1, _result1) { +_fn1((function(_err1, _result1) { if(_err1) { onError(_err1); } else { onResult(_result1); } -}); +})); " `; @@ -26,13 +26,13 @@ _fn1(function(_err1, _result1) { exports[`HookCodeFactory callTap (no args, no intercept) async without onResult 1`] = ` "var _fn1 = _x[1]; -_fn1(function(_err1) { +_fn1((function(_err1) { if(_err1) { onError(_err1); } else { onDone(); } -}); +})); " `; @@ -54,10 +54,10 @@ var _hasResult2 = false; var _promise2 = _fn2(); if (!_promise2 || !_promise2.then) throw new Error('Tap function (tapPromise) did not return promise (returned ' + _promise2 + ')'); -_promise2.then(function(_result2) { +_promise2.then((function(_result2) { _hasResult2 = true; onResult(_result2); -}, function(_err2) { +}), function(_err2) { if(_hasResult2) throw _err2; onError(_err2); }); @@ -93,10 +93,10 @@ var _hasResult2 = false; var _promise2 = _fn2(); if (!_promise2 || !_promise2.then) throw new Error('Tap function (tapPromise) did not return promise (returned ' + _promise2 + ')'); -_promise2.then(function(_result2) { +_promise2.then((function(_result2) { _hasResult2 = true; onDone(); -}, function(_err2) { +}), function(_err2) { if(_hasResult2) throw _err2; onError(_err2); }); @@ -188,13 +188,13 @@ if (!_hasError0) { exports[`HookCodeFactory callTap (with args, no intercept) async with onResult 1`] = ` "var _fn1 = _x[1]; -_fn1(a, b, c, function(_err1, _result1) { +_fn1(a, b, c, (function(_err1, _result1) { if(_err1) { onError(_err1); } else { onResult(_result1); } -}); +})); " `; @@ -212,13 +212,13 @@ _fn1(a, b, c, function(_err1, _result1) { exports[`HookCodeFactory callTap (with args, no intercept) async without onResult 1`] = ` "var _fn1 = _x[1]; -_fn1(a, b, c, function(_err1) { +_fn1(a, b, c, (function(_err1) { if(_err1) { onError(_err1); } else { onDone(); } -}); +})); " `; @@ -240,10 +240,10 @@ var _hasResult2 = false; var _promise2 = _fn2(a, b, c); if (!_promise2 || !_promise2.then) throw new Error('Tap function (tapPromise) did not return promise (returned ' + _promise2 + ')'); -_promise2.then(function(_result2) { +_promise2.then((function(_result2) { _hasResult2 = true; onResult(_result2); -}, function(_err2) { +}), function(_err2) { if(_hasResult2) throw _err2; onError(_err2); }); @@ -279,10 +279,10 @@ var _hasResult2 = false; var _promise2 = _fn2(a, b, c); if (!_promise2 || !_promise2.then) throw new Error('Tap function (tapPromise) did not return promise (returned ' + _promise2 + ')'); -_promise2.then(function(_result2) { +_promise2.then((function(_result2) { _hasResult2 = true; onDone(); -}, function(_err2) { +}), function(_err2) { if(_hasResult2) throw _err2; onError(_err2); }); @@ -377,13 +377,13 @@ exports[`HookCodeFactory callTap (with args, with intercept) async with onResult _interceptors[0].tap(_tap1); _interceptors[1].tap(_tap1); var _fn1 = _x[1]; -_fn1(a, b, c, function(_err1, _result1) { +_fn1(a, b, c, (function(_err1, _result1) { if(_err1) { onError(_err1); } else { onResult(_result1); } -}); +})); " `; @@ -407,13 +407,13 @@ exports[`HookCodeFactory callTap (with args, with intercept) async without onRes _interceptors[0].tap(_tap1); _interceptors[1].tap(_tap1); var _fn1 = _x[1]; -_fn1(a, b, c, function(_err1) { +_fn1(a, b, c, (function(_err1) { if(_err1) { onError(_err1); } else { onDone(); } -}); +})); " `; @@ -441,10 +441,10 @@ var _hasResult2 = false; var _promise2 = _fn2(a, b, c); if (!_promise2 || !_promise2.then) throw new Error('Tap function (tapPromise) did not return promise (returned ' + _promise2 + ')'); -_promise2.then(function(_result2) { +_promise2.then((function(_result2) { _hasResult2 = true; onResult(_result2); -}, function(_err2) { +}), function(_err2) { if(_hasResult2) throw _err2; onError(_err2); }); @@ -486,10 +486,10 @@ var _hasResult2 = false; var _promise2 = _fn2(a, b, c); if (!_promise2 || !_promise2.then) throw new Error('Tap function (tapPromise) did not return promise (returned ' + _promise2 + ')'); -_promise2.then(function(_result2) { +_promise2.then((function(_result2) { _hasResult2 = true; onDone(); -}, function(_err2) { +}), function(_err2) { if(_hasResult2) throw _err2; onError(_err2); }); @@ -595,7 +595,7 @@ if (!_hasError0) { `; exports[`HookCodeFactory taps (mixed) callTapsLooping 1`] = ` -"var _looper = function() { +"var _looper = (function() { var _loopAsync = false; var _loop; do { @@ -606,7 +606,7 @@ var _hasResult2 = false; var _promise2 = _fn2(a, b, c); if (!_promise2 || !_promise2.then) throw new Error('Tap function (tapPromise) did not return promise (returned ' + _promise2 + ')'); -_promise2.then(function(_result2) { +_promise2.then((function(_result2) { _hasResult2 = true; if(_result2 !== undefined) { _loop = true; @@ -616,7 +616,7 @@ if(!_loop) { onDone(); } } -}, function(_err2) { +}), function(_err2) { if(_hasResult2) throw _err2; onError(2, _err2); }); @@ -635,7 +635,7 @@ _loop = true; if(_loopAsync) _looper(); } else { var _fn1 = _x[1]; -_fn1(a, b, c, function(_err1, _result1) { +_fn1(a, b, c, (function(_err1, _result1) { if(_err1) { onError(1, _err1); } else { @@ -646,12 +646,12 @@ if(_loopAsync) _looper(); _next1(); } } -}); +})); } } } while(_loop); _loopAsync = true; -}; +}); _looper(); " `; @@ -728,9 +728,9 @@ _looper(); exports[`HookCodeFactory taps (mixed) callTapsParallel 1`] = ` "do { var _counter = 3; -var _done = function() { +var _done = (function() { onDone(); -}; +}); if(_counter <= 0) break; var _fn0 = _x[0]; var _result0 = _fn0(a, b, c); @@ -744,7 +744,7 @@ _done(); } if(_counter <= 0) break; var _fn1 = _x[1]; -_fn1(a, b, c, function(_err1, _result1) { +_fn1(a, b, c, (function(_err1, _result1) { if(_err1) { if(_counter > 0) { onError(1, _err1); @@ -759,14 +759,14 @@ _done(); }); } } -}); +})); if(_counter <= 0) break; var _fn2 = _x[2]; var _hasResult2 = false; var _promise2 = _fn2(a, b, c); if (!_promise2 || !_promise2.then) throw new Error('Tap function (tapPromise) did not return promise (returned ' + _promise2 + ')'); -_promise2.then(function(_result2) { +_promise2.then((function(_result2) { _hasResult2 = true; if(_counter > 0) { onResult(2, _result2, () => { @@ -776,7 +776,7 @@ _counter = 0; _done(); }); } -}, function(_err2) { +}), function(_err2) { if(_hasResult2) throw _err2; if(_counter > 0) { onError(2, _err2); @@ -876,14 +876,14 @@ var _hasResult2 = false; var _promise2 = _fn2(a, b, c); if (!_promise2 || !_promise2.then) throw new Error('Tap function (tapPromise) did not return promise (returned ' + _promise2 + ')'); -_promise2.then(function(_result2) { +_promise2.then((function(_result2) { _hasResult2 = true; onResult(2, _result2, () => { onDone(); }, () => { onDone(); }); -}, function(_err2) { +}), function(_err2) { if(_hasResult2) throw _err2; onError(2, _err2); }); @@ -892,7 +892,7 @@ var _fn0 = _x[0]; var _result0 = _fn0(a, b, c); onResult(0, _result0, () => { var _fn1 = _x[1]; -_fn1(a, b, c, function(_err1, _result1) { +_fn1(a, b, c, (function(_err1, _result1) { if(_err1) { onError(1, _err1); } else { @@ -902,7 +902,7 @@ _next1(); onDone(); }); } -}); +})); }, () => { onDone(); }); @@ -972,7 +972,7 @@ onResult( `; exports[`HookCodeFactory taps (mixed2) callTapsLooping 1`] = ` -"var _looper = function() { +"var _looper = (function() { var _loopAsync = false; var _loop; do { @@ -1003,7 +1003,7 @@ var _hasResult1 = false; var _promise1 = _fn1(a, b, c); if (!_promise1 || !_promise1.then) throw new Error('Tap function (tapPromise) did not return promise (returned ' + _promise1 + ')'); -_promise1.then(function(_result1) { +_promise1.then((function(_result1) { _hasResult1 = true; if(_result1 !== undefined) { _loop = true; @@ -1011,13 +1011,13 @@ if(_loopAsync) _looper(); } else { _next1(); } -}, function(_err1) { +}), function(_err1) { if(_hasResult1) throw _err1; onError(1, _err1); }); } var _fn0 = _x[0]; -_fn0(a, b, c, function(_err0, _result0) { +_fn0(a, b, c, (function(_err0, _result0) { if(_err0) { onError(0, _err0); } else { @@ -1028,10 +1028,10 @@ if(_loopAsync) _looper(); _next0(); } } -}); +})); } while(_loop); _loopAsync = true; -}; +}); _looper(); " `; @@ -1111,12 +1111,12 @@ _looper(); exports[`HookCodeFactory taps (mixed2) callTapsParallel 1`] = ` "do { var _counter = 3; -var _done = function() { +var _done = (function() { onDone(); -}; +}); if(_counter <= 0) break; var _fn0 = _x[0]; -_fn0(a, b, c, function(_err0, _result0) { +_fn0(a, b, c, (function(_err0, _result0) { if(_err0) { if(_counter > 0) { onError(0, _err0); @@ -1131,14 +1131,14 @@ _done(); }); } } -}); +})); if(_counter <= 0) break; var _fn1 = _x[1]; var _hasResult1 = false; var _promise1 = _fn1(a, b, c); if (!_promise1 || !_promise1.then) throw new Error('Tap function (tapPromise) did not return promise (returned ' + _promise1 + ')'); -_promise1.then(function(_result1) { +_promise1.then((function(_result1) { _hasResult1 = true; if(_counter > 0) { onResult(1, _result1, () => { @@ -1148,7 +1148,7 @@ _counter = 0; _done(); }); } -}, function(_err1) { +}), function(_err1) { if(_hasResult1) throw _err1; if(_counter > 0) { onError(1, _err1); @@ -1276,20 +1276,20 @@ var _hasResult1 = false; var _promise1 = _fn1(a, b, c); if (!_promise1 || !_promise1.then) throw new Error('Tap function (tapPromise) did not return promise (returned ' + _promise1 + ')'); -_promise1.then(function(_result1) { +_promise1.then((function(_result1) { _hasResult1 = true; onResult(1, _result1, () => { _next1(); }, () => { onDone(); }); -}, function(_err1) { +}), function(_err1) { if(_hasResult1) throw _err1; onError(1, _err1); }); } var _fn0 = _x[0]; -_fn0(a, b, c, function(_err0, _result0) { +_fn0(a, b, c, (function(_err0, _result0) { if(_err0) { onError(0, _err0); } else { @@ -1299,7 +1299,7 @@ _next0(); onDone(); }); } -}); +})); " `; @@ -1437,9 +1437,9 @@ do { exports[`HookCodeFactory taps (multiple sync) callTapsParallel 1`] = ` "do { var _counter = 3; -var _done = function() { +var _done = (function() { onDone(); -}; +}); if(_counter <= 0) break; var _fn0 = _x[0]; var _result0 = _fn0(a, b, c); @@ -1627,13 +1627,13 @@ exports[`HookCodeFactory taps (none) callTapsSeries 2`] = ` `; exports[`HookCodeFactory taps (single async) callTapsLooping 1`] = ` -"var _looper = function() { +"var _looper = (function() { var _loopAsync = false; var _loop; do { _loop = false; var _fn0 = _x[0]; -_fn0(a, b, c, function(_err0, _result0) { +_fn0(a, b, c, (function(_err0, _result0) { if(_err0) { onError(0, _err0); } else { @@ -1646,10 +1646,10 @@ onDone(); } } } -}); +})); } while(_loop); _loopAsync = true; -}; +}); _looper(); " `; @@ -1684,7 +1684,7 @@ _looper(); exports[`HookCodeFactory taps (single async) callTapsParallel 1`] = ` "var _fn0 = _x[0]; -_fn0(a, b, c, function(_err0, _result0) { +_fn0(a, b, c, (function(_err0, _result0) { if(_err0) { onError(0, _err0); } else { @@ -1694,7 +1694,7 @@ onDone(); onDone(); }); } -}); +})); " `; @@ -1721,7 +1721,7 @@ _fn0(a, b, c, function(_err0, _result0) { exports[`HookCodeFactory taps (single async) callTapsSeries 1`] = ` "var _fn0 = _x[0]; -_fn0(a, b, c, function(_err0, _result0) { +_fn0(a, b, c, (function(_err0, _result0) { if(_err0) { onError(0, _err0); } else { @@ -1731,7 +1731,7 @@ onDone(); onDone(); }); } -}); +})); " `; @@ -1757,7 +1757,7 @@ _fn0(a, b, c, function(_err0, _result0) { `; exports[`HookCodeFactory taps (single promise) callTapsLooping 1`] = ` -"var _looper = function() { +"var _looper = (function() { var _loopAsync = false; var _loop; do { @@ -1767,7 +1767,7 @@ var _hasResult0 = false; var _promise0 = _fn0(a, b, c); if (!_promise0 || !_promise0.then) throw new Error('Tap function (tapPromise) did not return promise (returned ' + _promise0 + ')'); -_promise0.then(function(_result0) { +_promise0.then((function(_result0) { _hasResult0 = true; if(_result0 !== undefined) { _loop = true; @@ -1777,13 +1777,13 @@ if(!_loop) { onDone(); } } -}, function(_err0) { +}), function(_err0) { if(_hasResult0) throw _err0; onError(0, _err0); }); } while(_loop); _loopAsync = true; -}; +}); _looper(); " `; @@ -1833,14 +1833,14 @@ var _hasResult0 = false; var _promise0 = _fn0(a, b, c); if (!_promise0 || !_promise0.then) throw new Error('Tap function (tapPromise) did not return promise (returned ' + _promise0 + ')'); -_promise0.then(function(_result0) { +_promise0.then((function(_result0) { _hasResult0 = true; onResult(0, _result0, () => { onDone(); }, () => { onDone(); }); -}, function(_err0) { +}), function(_err0) { if(_hasResult0) throw _err0; onError(0, _err0); }); @@ -1885,14 +1885,14 @@ var _hasResult0 = false; var _promise0 = _fn0(a, b, c); if (!_promise0 || !_promise0.then) throw new Error('Tap function (tapPromise) did not return promise (returned ' + _promise0 + ')'); -_promise0.then(function(_result0) { +_promise0.then((function(_result0) { _hasResult0 = true; onResult(0, _result0, () => { onDone(); }, () => { onDone(); }); -}, function(_err0) { +}), function(_err0) { if(_hasResult0) throw _err0; onError(0, _err0); });