Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix emitting real mapping sources when null mapping comes first #4082

Merged
merged 2 commits into from
Mar 9, 2025

Conversation

jridgewell
Copy link
Contributor

@jridgewell jridgewell commented Feb 16, 2025

This fixes an ordering bug when a null mapping and a real mapping share the same sourceIndex. If a null mapping comes first, then we'll assign it a sourceIndexToSourcesIndex but skip recording its source files in the items array because of the isNullEntry check. When we find the real mapping later in results, we'll skip recording its source files because of the map-ok check.

The simplest fix I can think of is flipping the order just a bit. We'll skip assigning sourceIndexToSourcesIndex for null mappings, so that when a real mapping comes up we'll record its sources.

I'm not sure how to generate a unit test case for this, but it resolves the issue found in angular/angular-cli#29465 (comment).

Fixes #4080
Fixes #4107

@meriturva
Copy link

No chance that this PR will be merged?
Thank you!

@evanw evanw added the sourcemap label Mar 9, 2025
@evanw
Copy link
Owner

evanw commented Mar 9, 2025

Thanks for the PR! I'll take care of reducing the repro and adding a test case. The linked Angular issue is very helpful as I'm able to reproduce the problem myself. A minimal repro is pretty complicated and may involve at least four files.

It looks like the issue happens when the same source file emits multiple discontiguous parts in the output file and source maps are skipped for the first part. This can happen when esbuild automatically generates a separate __export(exports, { ... }) part for the file to handle ESM namespace exports, for example.

Looks like this also fixes #4107.

Edit: For my own reference, here is a minimal repro for this bug. Clicking Visualize this source map on the generated file shows that the source map is invalid.

@evanw evanw merged commit 31052bd into evanw:main Mar 9, 2025
8 checks passed
evanw added a commit that referenced this pull request Mar 9, 2025
@jridgewell jridgewell deleted the source-map-null-entries branch March 9, 2025 20:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants