Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
guypassy opened this issue Dec 5, 2023 · 1 comment
Open

Comments

@guypassy
Copy link

guypassy commented Dec 5, 2023

"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"}
@heyqbnk
Copy link

heyqbnk commented May 22, 2024

For those, who is still looking for the answer to this issue. This behaviour is intended and seems correct, as long as a sourcemap is a document, helping developers to map one statement in source code to another in the generated one.

So, if this (generateMap) function would return a generated code, you wouldn't know what was the source one.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants