Skip to content

Commit c19199a

Browse files
committed
feat(core): update getCallerInfo()
1 parent ac6a0e8 commit c19199a

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

packages/core/src/lib/callstack/util.ts

+6-2
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,9 @@ export function getCallerInfo(callerDistance = 0): CallerInfo {
147147
enclosingLineNumber: -1,
148148
enclosingColNumber: -1,
149149
}
150+
if (! info.methodName) {
151+
info.methodName = info.funcName
152+
}
150153
return info
151154
}
152155

@@ -167,8 +170,6 @@ export function getCallerInfo(callerDistance = 0): CallerInfo {
167170
const funcName = site.getFunctionName() ?? ''
168171
const methodName = site.getMethodName() ?? ''
169172
const typeName = site.getTypeName() ?? ''
170-
171-
172173
const line = site.toString()
173174

174175
let className = typeName
@@ -197,6 +198,9 @@ export function getCallerInfo(callerDistance = 0): CallerInfo {
197198
enclosingLineNumber,
198199
enclosingColNumber,
199200
}
201+
if (! info.methodName) {
202+
info.methodName = info.funcName
203+
}
200204

201205
return info
202206
}

packages/core/test/callstack/34.util.getCallerStackSimpleInfo.test.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import { _demo, validateInfo } from './34a.config.js'
1010

1111
describe(fileShortPath(import.meta.url), () => {
1212

13-
describe('getCallerStackSimpleInfo() ', () => {
13+
describe('getCallerInfo() ', () => {
1414
it('distance: 0', () => {
1515
const info = getCallerInfo(0)
1616
validateInfo(info, import.meta.url)
@@ -52,7 +52,7 @@ function case22(): void {
5252
assert(info.line === -1, JSON.stringify(info, null, 2))
5353
assert(info.column === -1, JSON.stringify(info, null, 2))
5454
assert(info.funcName === 'case22', JSON.stringify(info, null, 2))
55-
assert(info.methodName === '', JSON.stringify(info, null, 2))
55+
assert(info.methodName === 'case22', JSON.stringify(info, null, 2))
5656
assert(info.className === '', JSON.stringify(info, null, 2))
5757
assert(info.lineNumber === 40, JSON.stringify(info, null, 2))
5858
assert(info.columnNumber === 18, JSON.stringify(info, null, 2))

0 commit comments

Comments
 (0)