How should I prepend content at the begining of orginal code then generate right sourcemap
zoeyzhao19 opened this issue · comments
Zoey Zhao commented
I am using prependLeft
to append content at the begining of code, but as shown below, the sourcemap mappings seems does not map to the right column. Is there someting I missed or it's the exact behavior that prependLeft expected, or how should I prepend content at the begining of orginal code with right sourcemap (expect column 0 in the toMatchInlineSnapshot output
)
it('should map correct column', async () => {
const s = new MagicString('function Foo () {}');
s.prependLeft(0, `export `);
const map = s.generateMap({
hires: true,
file: 'output.js',
source: 'input.js',
includeContent: true,
});
const smc = await new SourceMapConsumer(map);
const loc = smc.originalPositionFor({ line: 1, column: 3 });
expect(s.toString()).toMatchInlineSnapshot('"export function Foo () {}"');
expect(loc).toMatchInlineSnapshot(`
{
"column": null,
"line": null,
"name": null,
"source": null,
}
`);
});