microsoft / microsoft/TypeScript

`tsc` loses the class name in sourcemap

Open
#55,912 0 comments 4 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Domain: Source Maps Help Wanted Possible Improvement
Dominant language
Go
Stars
111k
Forks
14.3k
Avg merge
1d 19h
Merged PRs (30d)
117

Description

🔎 Search Terms
  • stack trace
  • lose class name
🕗 Version & Regression Information

Now I use TypeScript v5.2.2. This is not a critical bug, so I did not pay attention when it appeared.

💻 Code
// tmp.ts
class MyClass {
  static staticMethod() {
    throw new Error('Error in static method');
  }
}

MyClass.staticMethod();

Enable sourceMap in tsconfig, compile this code with tsc and then run compiled file with --enable-source-maps option:

tsc tmp.ts
node --enable-source-maps dist/tmp.js
🙁 Actual behavior
Error: Error in static method
    at Function.staticMethod

As you can see, the class name is missing from the stack trace. This bug appears only when the error occurs in static methods.

🙂 Expected behavior
Error: Error in static method
    at MyClass.staticMethod

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the issue with tmp.ts, sourceMap enabled in tsconfig, tsc, and Node's --enable-source-maps option. Compare the stack trace from dist/tmp.js with the expected MyClass.staticMethod output, then trace the compiler's source-map handling for static methods. Done means the class name is preserved in the reported stack trace.

Written by the indexing model from the issue text.

Assessment

Tech stack
node.js, typescript
Domain
compilers
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.