Skip to content

Source maps treat only \n as a line break (lone \r, U+2028, U+2029 ignored) #368

Open

Description

@Sheraff

generateMap starts a new mappings line only at \n, so a source containing a lone \r, U+2028 or U+2029 gets a map with too few lines.

import MagicString from 'magic-string'

const map = (code) => new MagicString(code).generateMap({ hires: true }).mappings

console.log(map('a\nb'))      // AAAA;AACA
console.log(map('a\rb'))      // AAAA,CAAC,CAAC  expected AAAA;AACA
console.log(map('a\u2028b'))  // AAAA,CAAC,CAAC  expected AAAA;AACA
console.log(map('a\u2029b'))  // AAAA,CAAC,CAAC  expected AAAA;AACA

Same thing, but executable on stackblitz: https://stackblitz.com/edit/stackblitz-starters-tu3vynsp?file=index.js

magic-string 1.4.4.
ECMAScript ends a line at every LineTerminatorSequence (LF, CR, CRLF, U+2028, U+2029)
V8 stack traces count lines that way, and esbuild and oxc emit AAAA;AACA for all three inputs.

Drafted with an AI assistant. The snippet above was run and its output checked by me, the human.

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions