Skip to content

Commit

Permalink
Fix
Browse files Browse the repository at this point in the history
  • Loading branch information
mischnic committed Jan 1, 2023
1 parent dc990c6 commit 7a69d69
Showing 1 changed file with 18 additions and 15 deletions.
33 changes: 18 additions & 15 deletions packages/transformers/typescript-tsc/src/TSCTransformer.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,10 @@ export default (new Transformer({
},

async transform({asset, config, options}) {
asset.type = 'js';

let code = await asset.getCode();
let [code, originalMap] = await Promise.all([
asset.getCode(),
asset.getMap(),
]);

let transpiled = typescript.transpileModule(
code,
Expand All @@ -30,30 +31,32 @@ export default (new Transformer({
// Don't compile ES `import`s -- scope hoisting prefers them and they will
// otherwise compiled to CJS via babel in the js transformer
module: typescript.ModuleKind.ESNext,
sourceMap: !!asset.env.sourceMap,
sourceMap: Boolean(asset.env.sourceMap),
mapRoot: options.projectRoot,
},
fileName: asset.filePath, // Should be relativePath?
}: TranspileOptions),
);

let map;
let {outputText, sourceMapText} = transpiled;
if (sourceMapText != null) {
map = new SourceMap(options.projectRoot);
map.addVLQMap(JSON.parse(sourceMapText));

if (sourceMapText != null) {
outputText = outputText.substring(
0,
outputText.lastIndexOf('//# sourceMappingURL'),
);

let map = new SourceMap(options.projectRoot);
map.addVLQMap(JSON.parse(sourceMapText));
if (originalMap) {
map.extends(originalMap);
}
asset.setMap(map);
}

return [
{
type: 'js',
content: outputText,
map,
},
];
asset.type = 'js';
asset.setCode(outputText);

return [asset];
},
}): Transformer);

0 comments on commit 7a69d69

Please sign in to comment.