stacktrace-gps icon indicating copy to clipboard operation
stacktrace-gps copied to clipboard

Bug in stacktrace-gps: Method Name Matching Fails in TypeScript with Typed Return Values

Open x842013824 opened this issue 2 years ago • 0 comments

In TypeScript, when using stacktrace-gps, the _findFunctionName method's regular expression fails to match method names if a return type is specified.

Expected Behavior

The method name should be correctly identified in the stack trace, regardless of the presence of a typed return value in TypeScript.

Current Behavior

method name is not correctly identified in the stack trace, , maybe I can get the name of the last method without the return type when lineNum less 20.

Steps to Reproduce (for bugs)

  1. Define a TypeScript method with a specific return type, e.g., methodName(): ReturnType
  2. Generate a stack trace using stacktrace-gps
  3. Observe that the method name is not correctly identified in the stack trace

Context

I can't get the method name anymore, maybe I can get the name of the last method without the return type. My temporary solution is to drop the return type and use Typescript's automatic inference feature. But I would prefer to add a regular expression for this case directly in the _findFunctionName syntaxes

Your Environment

  • Package version: stacktrace-gps@^3.0.4 [email protected]
  • Browser name and version: chrome 120.0.6099.71

Possible Solution

add a regular expression for this case directly in the _findFunctionName syntaxes

x842013824 avatar Dec 14 '23 04:12 x842013824