From 252fdd7fb6875dd6af83312040a70992f281bbd1 Mon Sep 17 00:00:00 2001 From: Ivan Seidel Date: Thu, 23 Jun 2016 15:19:57 -0300 Subject: Consider non-explicit parameters in validation --- lib/autoInject.js | 7 ++++++- mocha_test/autoInject.js | 14 ++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/lib/autoInject.js b/lib/autoInject.js index 5e9bda6..89b76d6 100644 --- a/lib/autoInject.js +++ b/lib/autoInject.js @@ -13,7 +13,7 @@ var STRIP_COMMENTS = /((\/\/.*$)|(\/\*[\s\S]*?\*\/))/mg; function parseParams(func) { func = func.toString().replace(STRIP_COMMENTS, ''); func = func.match(FN_ARGS)[2].replace(' ', ''); - func = func.split(FN_ARG_SPLIT); + func = func ? func.split(FN_ARG_SPLIT) : []; func = func.map(function (arg){ return trim(arg.replace(FN_ARG, '')); }); @@ -122,6 +122,11 @@ export default function autoInject(tasks, callback) { newTasks[key] = taskFn; } else { params = parseParams(taskFn); + if (taskFn.length === 0 && params.length === 0) { + throw new Error("autoInject task functions require explicit parameters."); + } + console.log(taskFn.length, params) + params.pop(); newTasks[key] = params.concat(newTask); diff --git a/mocha_test/autoInject.js b/mocha_test/autoInject.js index e658167..9c2d1fb 100644 --- a/mocha_test/autoInject.js +++ b/mocha_test/autoInject.js @@ -85,6 +85,20 @@ describe('autoInject', function () { }, done); }); + it('should throw error for function without explicit parameters', function (done) { + try { + async.autoInject({ + a: function (){} + }); + } catch (e) { + // It's ok. It detected a void function + return done(); + } + + // If didn't catch error, then it's a failed test + done(true) + }); + var arrowSupport = true; try { new Function('x => x'); -- cgit v1.2.1