Sourcemaps for typescript generate inconsistent results compared to tsc
- Dominant language
- Go
- Stars
- 40.1k
- Forks
- 1.3k
- PR merge metrics
- No merged PRs in 30d
Description
1. generate js from typescript using esbuild, w/ sourcemaps enabled
2. load sourcemap with `SourceMapConsumer`
3. call `generatedPositionFor` for a string in the TS file
4. expect returned range to map to original source
5. observe returned start.character == end.character
```
git clone https://github.com/tmm1/esbuild-repros
cd esbuild-repros/sourcemap-issues
nvm use
npm i
npm run compile-esbuild
npm run compile-tsc
npm run compare
```
```
❯ npm run compile-esbuild
> sourcemap-issues@1.0.0 compile-esbuild
> esbuild --target=es2022 --format=esm --sourcemap=external --outdir=out-esbuild src/*.ts
```
```
❯ npm run compile-tsc
> sourcemap-issues@1.0.0 compile-tsc
> tsc src/*.ts --outdir out-tsc --sourceMap true --target es2022 --module es2022 --moduleResolution node
```
```
❯ npm run compare
> sourcemap-issues@1.0.0 compare
> node --experimental-strip-types compare.ts
out-esbuild/ptyHostMain.js.map
{ line: 8, character: 42 } { line: 8, character: 42 }
false
out-tsc/ptyHostMain.js.map
{ line: 9, character: 44 } { line: 9, character: 53 }
true
```
Contributor guide
No contributing guide indexed for this repository
Research direction
Start with the reproduction in esbuild-repros/sourcemap-issues and run npm install, npm run compile-esbuild, npm run compile-tsc, and npm run compare. Read compare.ts to understand the generatedPositionFor comparison and use the esbuild and tsc outputs to trace the sourcemap ranges. Done means esbuild returns a non-empty original range like tsc for the reproduced TypeScript input.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100