Skip to content

Align sourceFilename across core, parser, and generator#17869

Draft
nicolo-ribaudo wants to merge 1 commit intobabel:mainfrom
nicolo-ribaudo:fix-filenames-handling
Draft

Align sourceFilename across core, parser, and generator#17869
nicolo-ribaudo wants to merge 1 commit intobabel:mainfrom
nicolo-ribaudo:fix-filenames-handling

Conversation

@nicolo-ribaudo
Copy link
Copy Markdown
Member

@nicolo-ribaudo nicolo-ribaudo commented Mar 12, 2026

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

Closes #15917 and closes #15911.

Marking as draft because I want to add getters for the old spelling for legacy compatibility.

@nicolo-ribaudo nicolo-ribaudo added the PR: Breaking Change 💥 A type of pull request used for our changelog categories for next major release label Mar 12, 2026
Comment on lines +32 to +44
// The source filename used in the source map's "sources" array.
// This is the "normalized" version: if sourceRoot is set, it's
// relative to sourceRoot; if the path is absolute with no sourceRoot,
// it's reduced to its basename. Relative paths are kept as-is.
#sourceFilename: string | undefined;

// The original absolute filename (opts.filename, or opts.sourceFilename
// as a fallback), converted to a POSIX path.
// This is used in #resolveSourceFilename to detect when a node's
// loc.filename refers to the main source file, so we can map it back
// to the normalized #sourceFilename instead of creating a duplicate
// source entry.
#rawSourceFilename: string | undefined;
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.

This is a mess, but I was trying to minimize disruption 😅

The problem is that right now we are very inconsistent about how we use relative paths, absolute paths, and basenames. @babel/generator needs to accept a mix of those to put the right things in the source map.

@babel-bot
Copy link
Copy Markdown
Collaborator

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

@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new bot commented Mar 12, 2026

Open in StackBlitz

commit: 37b605b

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

PR: Breaking Change 💥 A type of pull request used for our changelog categories for next major release

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Handling of filenames in Babel

2 participants