Skip to content
This repository was archived by the owner on Feb 2, 2021. It is now read-only.

Commit 6112394

Browse files
Fix running hooks
We should be able resolve functions with $injector - this is required for hooks execution and generating help content. Get back the old unit tests that were testing this functionality.
1 parent 655160a commit 6112394

File tree

2 files changed

+253
-106
lines changed

2 files changed

+253
-106
lines changed

helpers.ts

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -360,11 +360,12 @@ export function connectEventuallyUntilTimeout(factory: () => net.Socket, timeout
360360
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
361361
//THE SOFTWARE.
362362

363-
let FN_NAME = /class\s+([A-Z].+?)(?:\s+.*?)?\{/;
364-
let FN_ARGS = /constructor\s*([^\(]*)\(\s*([^\)]*)\)/m;
365-
let FN_ARG_SPLIT = /,/;
366-
let FN_ARG = /^\s*(_?)(\S+?)\1\s*$/;
367-
let STRIP_COMMENTS = /((\/\/.*$)|(\/\*[\s\S]*?\*\/))/mg;
363+
const CLASS_NAME = /class\s+([A-Z].+?)(?:\s+.*?)?\{/;
364+
const CONSTRUCTOR_ARGS = /constructor\s*([^\(]*)\(\s*([^\)]*)\)/m;
365+
const FN_NAME_AND_ARGS = /^(?:function)?\s*([^\(]*)\(\s*([^\)]*)\)\s*\{/m;
366+
const FN_ARG_SPLIT = /,/;
367+
const FN_ARG = /^\s*(_?)(\S+?)\1\s*$/;
368+
const STRIP_COMMENTS = /((\/\/.*$)|(\/\*[\s\S]*?\*\/))/mg;
368369

369370
export function annotate(fn: any) {
370371
let $inject: any,
@@ -375,19 +376,27 @@ export function annotate(fn: any) {
375376
if (!($inject = fn.$inject) || $inject.name !== fn.name) {
376377
$inject = { args: [], name: "" };
377378
fnText = fn.toString().replace(STRIP_COMMENTS, '');
378-
argDecl = fnText.match(FN_ARGS);
379379

380-
let nameMatch = fnText.match(FN_NAME);
380+
let nameMatch = fnText.match(CLASS_NAME);
381+
382+
if (nameMatch) {
383+
argDecl = fnText.match(CONSTRUCTOR_ARGS);
384+
} else {
385+
nameMatch = argDecl = fnText.match(FN_NAME_AND_ARGS);
386+
}
387+
381388
$inject.name = nameMatch && nameMatch[1];
382389

383-
if (argDecl && fn.length) {
390+
if (argDecl && fnText.length) {
384391
argDecl[2].split(FN_ARG_SPLIT).forEach((arg) => {
385392
arg.replace(FN_ARG, (all, underscore, name) => $inject.args.push(name));
386393
});
387394
}
395+
388396
fn.$inject = $inject;
389397
}
390398
}
399+
391400
return $inject;
392401
}
393402

0 commit comments

Comments
 (0)