Skip to content

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

Open
nicolo-ribaudo wants to merge 1 commit into
babel:mainfrom
nicolo-ribaudo:range-mappings
Open

Add experimental support for range mappings in source maps.#18006
nicolo-ribaudo wants to merge 1 commit 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
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/61926

@pkg-pr-new

pkg-pr-new Bot commented May 21, 2026

Copy link
Copy Markdown

Open in StackBlitz

commit: 3f4b6ca

@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).

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

Labels

pkg: generator PR: Needs Docs PR: New Feature 🚀 A type of pull request used for our changelog categories

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants