mozilla / mozilla/source-map

originalPositionFor returns null if sourcemap does not contains the exact line.

Open
#261 6 comments 3 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

needs-triage
Dominant language
JavaScript
Stars
3.7k
Forks
370
PR merge metrics
No merged PRs in 30d

Description

originalPositionFor returns null if sourcemap does not contains the exact line.
It cause the issue with typescript(ts-node) that may not create source map for all the lines,
especially when the source contains multi-line chained function call like below.

let obj:any = null;
obj
.map();

In this case, the error happens on the last line. But, sourcemap does not have information on the line. So, the following code assume the mapping does not found and return null.

https://github.com/mozilla/source-map/blob/75663e0187002920ad98ed1de21e54cb85114609/lib/source-map-consumer.js#L616

It is much better to return the nearest source map position, instead of just return null.

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

Start in lib/source-map-consumer.js around line 616 and reproduce the multiline chained-call example from the issue with a sourcemap that lacks the exact line. Check how originalPositionFor handles missing mappings; done means it returns the nearest source-map position instead of null for this case.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.