Skip to content

Change actions to the magic-string do not affect the generated map #265

Description

@guypassy

"magic-string": "^0.30.5",

generateMap is not affected by any changes made to the value in the magic string.

import MagicString from 'magic-string'

const s = new MagicString('problems = 99')

s.update(0, 8, 'answer')
console.log(s.toString()) // 'answer = 99'

s.update(11, 13, '42') // character indices always refer to the original string
console.log(s.toString()) // 'answer = 42'

s.prepend('var ').append(';') // most methods are chainable
console.log(s.toString()) // 'var answer = 42;'

const map = s.generateMap({
  source: 'source.js',
  file: 'converted.js.map',
  includeContent: true
}) // generates a v3 sourcemap

console.log(map.toString())

Results in:

answer = 99
answer = 42
var answer = 42;
{"version":3,"file":"converted.js.map","sources":["source.js"],"sourcesContent":["problems = 99"],"names":[],"mappings":"IAAA,MAAQ,GAAG"}

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

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions