Skip to content

Commit

Permalink
fix: generate high resolution source map (#443)
Browse files Browse the repository at this point in the history
When using the advanced import preprocessor, make sure to use a high resolution source map.
Else the mappings won't be that good anymore (line mappings at best).
  • Loading branch information
dummdidumm committed Dec 16, 2021
1 parent 85a86c8 commit 57012ba
Showing 1 changed file with 8 additions and 11 deletions.
19 changes: 8 additions & 11 deletions src/transformers/typescript.ts
Expand Up @@ -167,15 +167,13 @@ function injectVarsToCode({
: `${sep}${getScriptContent(markup, true)}\n${injectedVars}`;

if (sourceMapChain) {
const s = new MagicString(content);

s.append(injectedCode);

const ms = new MagicString(content).append(injectedCode);
const fname = `${filename}.injected.ts`;
const code = s.toString();
const map = s.generateMap({
const code = ms.toString();
const map = ms.generateMap({
source: filename,
file: fname,
hires: true,
});

sourceMapChain.content[fname] = code;
Expand Down Expand Up @@ -203,15 +201,14 @@ function stripInjectedCode({
const injectedCodeStart = transpiledCode.indexOf(injectedCodeSeparator);

if (sourceMapChain) {
const s = new MagicString(transpiledCode);
const st = s.snip(0, injectedCodeStart);

const ms = new MagicString(transpiledCode).snip(0, injectedCodeStart);
const source = `${filename}.transpiled.js`;
const file = `${filename}.js`;
const code = st.toString();
const map = st.generateMap({
const code = ms.toString();
const map = ms.generateMap({
source,
file,
hires: true,
});

sourceMapChain.content[file] = code;
Expand Down

0 comments on commit 57012ba

Please sign in to comment.