Skip to content

Add experimental support for range mappings in source maps - #18006

Merged
nicolo-ribaudo merged 6 commits into
babel:mainfrom
nicolo-ribaudo:range-mappings
Oct 30, 2026
Merged

nicolo-ribaudo merged 6 commits into
babel:mainfrom
nicolo-ribaudo:range-mappings

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 babel/website#3237
Any Dependency Changes?
License MIT

This PR implements the range mappings proposal for source maps. WebKit devtools just merged support for it.

The proposal is at stage 3, meaning that while there might be changes it's expected to be quite stable and changes would be due to implementation feedback. Given that we are in close coordination with all the tools implementing it (we have monthly calls in TC39-TG4), we can safely coordinate changes if they will happen.

Given this test case:

let input = `let x, y, z, w;
x + y + z +   w;`

const plugins = [
  ({ types: t }) => ({
    visitor: {
      Program(path) {
        path.scope.rename("z", "a");
      },
    },
  }),
];

const outWithoutRanges = transformSync(input, {
  configFile: false,
  plugins,
  sourceMaps: true,
  generatorOpts: {
    sourceMapRanges: false,
  },
});

without range mappings we generate

{
  version: 3,
  file: undefined,
  names: [ 'z' ],
  sourceRoot: undefined,
  sources: [ 'unknown' ],
  sourcesContent: [ 'let x, y, z, w;\nx + y + z +   w;' ],
  mappings: 'AAAA,IAAI,CAAC,EAAE,CAAC,EAAEA,CAAC,EAAE,CAAC;AACd,CAAC,GAAG,CAAC,GAAGA,CAAC,GAAK,CAAC',
  ignoreList: undefined,
  rangeMappings: undefined
}

while with range mappings it becomes

{
  version: 3,
  file: undefined,
  names: [ 'z' ],
  sourceRoot: undefined,
  sources: [ 'unknown' ],
  sourcesContent: [ 'let x, y, z, w;\nx + y + z +   w;' ],
  mappings: 'AAAA,QAAQ,EAAEA,CAAC;KACN,GAAGA,CAAC,GAAK,CAAC',
  ignoreList: undefined,
  rangeMappings: 'AD;D'
}

@nicolo-ribaudo nicolo-ribaudo added the PR: New Feature 🚀 A type of pull request used for our changelog categories label May 18, 2026
@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/62608

@pkg-pr-new

pkg-pr-new Bot commented May 21, 2026 •

Copy link
Copy Markdown

Open in StackBlitz

commit: 2da443c

@nicolo-ribaudo nicolo-ribaudo added this to the v8.1.0 milestone Jul 14, 2026
@nicolo-ribaudo nicolo-ribaudo changed the title Add support for range mappings Add experimental support for range mappings in source maps. Jul 15, 2026
@nicolo-ribaudo
nicolo-ribaudo marked this pull request as ready for review July 15, 2026 16:15
@nicolo-ribaudo

Copy link
Copy Markdown
Member Author

As the source maps libraries do not support yet merging source maps that use range mappings, we should automatically want and disable ranges when an inputSourceMap is provided (either inline, from disk, or as an object).

@babel-bot

babel-bot commented Oct 26, 2026 •

Copy link
Copy Markdown
Collaborator

test262 results

As of 2da443c, this PR does not change any test262 results compared to main (tc39/test262@d53ebc8).

@nicolo-ribaudo nicolo-ribaudo changed the title Add experimental support for range mappings in source maps. Add experimental support for range mappings in source maps Oct 26, 2026
@nicolo-ribaudo

Copy link
Copy Markdown
Member Author

All review comments addressed

@JLHwung JLHwung left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Could you add a test for babel-cli? Currently babel --out-file is not aware of the rangeMappings right?

@nicolo-ribaudo

Copy link
Copy Markdown
Member Author

Good catch, I made it throw an error. Unfortunately the source map libraries that we use do not support composition/concatenation yet with range mappins.

@codspeed

This comment was marked as outdated.

if (opts.inputSourceMap) {
if (this.#allowRangeMappings) {
this.#allowRangeMappings = false;
console.warn(

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This comment is from Claude Code:

This warning will be printed per-file if users have enabled sourceMapRanges and the input source contains //# sourceMappingURL comments. Consider warning once per process, or only when inputSourceMap was passed explicitly, would avoid flooding build output.

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 other warnings we have are per-file (e.g. discarding unknown file input sourcemap when the sourceMappingURLs point to source maps that are not actually included together with the input code).

This warning specifically could be for some files and not others, because some files might link to a source map and others may not, so there is value in having the filename there and warning per-file.

Also, there is an easy workaround for users to not see the warning: just disable the option that is a no-op for them.

@nicolo-ribaudo nicolo-ribaudo added PR: Ready to be Merged A pull request with already two approvals, but waiting for the next minor release and removed PR: Needs Review A pull request awaiting more approvals labels Oct 28, 2026
@nicolo-ribaudo
nicolo-ribaudo added this pull request to the merge queue Oct 30, 2026
Merged via the queue into babel:main with commit a40290f Oct 30, 2026
64 of 65 checks passed
@nicolo-ribaudo
nicolo-ribaudo deleted the range-mappings branch October 30, 2026 13:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pkg: generator PR: New Feature 🚀 A type of pull request used for our changelog categories PR: Ready to be Merged A pull request with already two approvals, but waiting for the next minor release

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants