Skip to content

Do not emit source map names for identical names#18005

Merged
nicolo-ribaudo merged 2 commits into
babel:mainfrom
nicolo-ribaudo:skip-sm-names
May 21, 2026
Merged

Do not emit source map names for identical names#18005
nicolo-ribaudo merged 2 commits into
babel:mainfrom
nicolo-ribaudo:skip-sm-names

Conversation

@nicolo-ribaudo

@nicolo-ribaudo nicolo-ribaudo commented May 18, 2026

Copy link
Copy Markdown
Member
Q                       A
Fixed Issues? Fixes #1, Fixes #2
Patch: Bug Fix?
Major: Breaking Change?
Minor: New Feature?
Tests Added + Pass? Yes
Documentation PR Link
Any Dependency Changes?
License MIT

I am working on an implementation of range mappings (https://github.com/tc39/ecma426/blob/main/proposals/range-mappings.md). For that to work well, we need to minimize the number of places where we would need to force a mapping not because code is moved around, but because we need to assign a name in it.

Babel emits a name for each identifier, but it's actually only needed when the new name is different from the original one. This also applies to #14907.

Even though this is PR should be safe, I'd avoid backporting it to Babel 7.

@Andarist as you very recently touched this logic, I'd appreciate if you could do a quick review :)

@nicolo-ribaudo nicolo-ribaudo marked this pull request as draft May 18, 2026 20:49

(1:10-12) Test { <-- (4:2-11) function Test
^^ ^^^^^^^^^
(1:10-12) Test { <-- (4:2-19) function Test() {

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Marking as draft until I understand what's going on here.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, this is actually fine. Before we were mapping all of the locations in function Test() { to after class Test, and we were giving name: Test to Test(.

That's not happening anymore (since it's not renamed), so the source map now has a single mapping-to-nowhere-useful for the whole function Test() {

@babel-bot

babel-bot commented May 18, 2026

Copy link
Copy Markdown
Collaborator

Build successful! You can test your changes in the REPL here: https://babeljs.io/repl/build/61580

@pkg-pr-new

pkg-pr-new Bot commented May 18, 2026

Copy link
Copy Markdown

Open in StackBlitz

commit: e678d68

Comment on lines +976 to +977
"e",
"#e",

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The reason we have both e and #e here is that the first one is for the renamed identifier, while the second one is for the name of the function.

The first one is probably not needed, but it's unrelated to this PR.

@nicolo-ribaudo nicolo-ribaudo marked this pull request as ready for review May 18, 2026 21:20
@nicolo-ribaudo nicolo-ribaudo added the PR: Output optimization 🔬 A type of pull request used for our changelog categories label May 18, 2026

@Andarist Andarist left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 😉

@liuxingbaoyu liuxingbaoyu left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The CI failed because toMatchTemplate failed and the error message wasn't reported correctly.
I agree that this PR shouldn't be ported to Babel 7 because it changes some behavior of source-map-support.

@liuxingbaoyu

Copy link
Copy Markdown
Member

I tested the integration of this PR with Jest, and it doesn't seem to have affected the tests.

@nicolo-ribaudo

nicolo-ribaudo commented May 21, 2026

Copy link
Copy Markdown
Member Author

Yeah CI error is related, thanks for skipping it for now! It seems like the new stack trace is actually more correct.

@nicolo-ribaudo nicolo-ribaudo merged commit 0e16971 into babel:main May 21, 2026
56 checks passed
@nicolo-ribaudo nicolo-ribaudo deleted the skip-sm-names branch May 21, 2026 12:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

PR: Output optimization 🔬 A type of pull request used for our changelog categories

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants