From 190d122e6f43d04dcc519171502303f931907598 Mon Sep 17 00:00:00 2001 From: Chris Thielen Date: Mon, 19 Sep 2016 01:49:23 -0500 Subject: [PATCH] fix(trace): Show function definition during logging of trace.enable('HOOK') --- src/common/strings.ts | 8 +++++++- src/common/trace.ts | 9 ++++----- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/src/common/strings.ts b/src/common/strings.ts index 2c85da7d2..883ade7d4 100644 --- a/src/common/strings.ts +++ b/src/common/strings.ts @@ -57,7 +57,13 @@ function promiseToString(p: Promise) { export function functionToString(fn: Function) { let fnStr = fnToString(fn); let namedFunctionMatch = fnStr.match(/^(function [^ ]+\([^)]*\))/); - return namedFunctionMatch ? namedFunctionMatch[1] : fnStr; + let toStr = namedFunctionMatch ? namedFunctionMatch[1] : fnStr; + + let fnName = fn['name'] || ""; + if (fnName && toStr.match(/function \(/)) { + return 'function ' + fnName + toStr.substr(9); + } + return toStr; } export function fnToString(fn: IInjectable) { diff --git a/src/common/trace.ts b/src/common/trace.ts index 6fbf512a8..b29bea4f1 100644 --- a/src/common/trace.ts +++ b/src/common/trace.ts @@ -162,18 +162,17 @@ export class Trace { digest = this.approximateDigests, event = parse("traceData.hookType")(options) || "internal", context = parse("traceData.context.state.name")(options) || parse("traceData.context")(options) || "unknown", - name = functionToString((step as any).hookFn); + name = functionToString((step as any).eventHook.callback); console.log(`Transition #${tid} Digest #${digest}: Hook -> ${event} context: ${context}, ${maxLength(200, name)}`); } /** called by ui-router code */ - traceHookResult(hookResult: HookResult, transitionResult: Promise, transitionOptions: any) { + traceHookResult(hookResult: HookResult, transitionOptions: any) { if (!this.enabled(Category.HOOK)) return; let tid = parse("transition.$id")(transitionOptions), digest = this.approximateDigests, - hookResultStr = stringify(hookResult), - transitionResultStr = stringify(transitionResult); - console.log(`Transition #${tid} Digest #${digest}: <- Hook returned: ${maxLength(200, hookResultStr)}, transition result: ${maxLength(200, transitionResultStr)}`); + hookResultStr = stringify(hookResult); + console.log(`Transition #${tid} Digest #${digest}: <- Hook returned: ${maxLength(200, hookResultStr)}`); } /** called by ui-router code */