From 57012ba9f87abfec99f061196fb955da4ccfa384 Mon Sep 17 00:00:00 2001 From: Simon H <5968653+dummdidumm@users.noreply.github.com> Date: Thu, 16 Dec 2021 17:10:24 +0100 Subject: [PATCH] fix: generate high resolution source map (#443) 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). --- src/transformers/typescript.ts | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/src/transformers/typescript.ts b/src/transformers/typescript.ts index 8123fdd3..ad1ec836 100644 --- a/src/transformers/typescript.ts +++ b/src/transformers/typescript.ts @@ -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; @@ -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;