Skip to content

Add support for range mappings#18006

Draft
nicolo-ribaudo wants to merge 6 commits into
babel:mainfrom
nicolo-ribaudo:range-mappings
Draft

Add support for range mappings#18006
nicolo-ribaudo wants to merge 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
Any Dependency Changes?
License MIT

Wip as it depends on an unstable version of the sourcemaps libraries, on #18005, and I still need to add tests.

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/61616

@pkg-pr-new

pkg-pr-new Bot commented May 21, 2026

Copy link
Copy Markdown

Open in StackBlitz

commit: 25134a6

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

Labels

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.

2 participants