Skip to content

Commit c55678c

Browse files
authored
fix(typescript): sourcemap generated as null (rollup#276)
* Fix typescript sourcemap generated as null * test(typescript): add inlineSources test
1 parent 6825bf8 commit c55678c

File tree

3 files changed

+21
-2
lines changed

3 files changed

+21
-2
lines changed

packages/typescript/src/options/normalize.ts

+3
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,9 @@ export function normalizeCompilerOptions(
3838
// Default to using source maps.
3939
// If the plugin user sets sourceMap to false we keep that option.
4040
compilerOptions.sourceMap = true;
41+
// Using inlineSources to make sure typescript generate source content
42+
// instead of source path.
43+
compilerOptions.inlineSources = true;
4144
autoSetSourceMap = true;
4245
}
4346

packages/typescript/test/test.js

+16
Original file line numberDiff line numberDiff line change
@@ -662,6 +662,22 @@ test('prevents errors due to conflicting `sourceMap`/`inlineSourceMap` options',
662662
);
663663
});
664664

665+
test('should not emit null sourceContent', async (t) => {
666+
const bundle = await rollup({
667+
input: 'fixtures/basic/main.ts',
668+
plugins: [
669+
typescript({
670+
tsconfig: 'fixtures/basic/tsconfig.json'
671+
})
672+
],
673+
onwarn
674+
});
675+
const output = await getCode(bundle, { format: 'esm', sourcemap: true }, true);
676+
const sourcemap = output[0].map;
677+
// eslint-disable-next-line no-undefined
678+
t.false(sourcemap.sourcesContent.includes(undefined));
679+
});
680+
665681
test('should not fail if source maps are off', async (t) => {
666682
await t.notThrowsAsync(
667683
rollup({

util/test.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ const getCode = async (bundle, outputOptions, allFiles = false) => {
66
const { output } = await bundle.generate(outputOptions || { format: 'cjs' });
77

88
if (allFiles) {
9-
return output.map(({ code, fileName, source }) => {
10-
return { code, fileName, source };
9+
return output.map(({ code, fileName, source, map }) => {
10+
return { code, fileName, source, map };
1111
});
1212
}
1313
const [{ code }] = output;

0 commit comments

Comments
 (0)