Skip to content

Commit

Permalink
Fix crash when returning undefined sourcemaps from renderChunk hook (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
kyle1320 authored and lukastaegert committed Nov 17, 2018
1 parent 3c521ca commit dbd2e47
Show file tree
Hide file tree
Showing 15 changed files with 68 additions and 22 deletions.
44 changes: 22 additions & 22 deletions src/utils/collapseSourcemaps.ts
Expand Up @@ -143,6 +143,26 @@ export default function collapseSourcemaps(
bundleSourcemapChain: RawSourceMap[],
excludeContent: boolean
) {
function linkMap(source: Source, map: any) {
if (map.missing) {
bundle.graph.warn({
code: 'SOURCEMAP_BROKEN',
plugin: map.plugin,
message: `Sourcemap is likely to be incorrect: a plugin${
map.plugin ? ` ('${map.plugin}')` : ``
} was used to transform files, but didn't generate a sourcemap for the transformation. Consult the plugin documentation for help`,
url: `https://rollupjs.org/guide/en#warning-sourcemap-is-likely-to-be-incorrect`
});

map = {
names: [],
mappings: ''
};
}

return <any>new Link(map, [source]);
}

const moduleSources = modules.filter(module => !module.excludeFromSourcemap).map(module => {
let sourcemapChain = module.sourcemapChain;

Expand Down Expand Up @@ -170,34 +190,14 @@ export default function collapseSourcemaps(
}
}

sourcemapChain.forEach((map: any) => {
if (map.missing) {
bundle.graph.warn({
code: 'SOURCEMAP_BROKEN',
plugin: map.plugin,
message: `Sourcemap is likely to be incorrect: a plugin${
map.plugin ? ` ('${map.plugin}')` : ``
} was used to transform files, but didn't generate a sourcemap for the transformation. Consult the plugin documentation for help`,
url: `https://rollupjs.org/guide/en#warning-sourcemap-is-likely-to-be-incorrect`
});

map = {
names: [],
mappings: ''
};
}

source = <any>new Link(map, [source]);
});
source = sourcemapChain.reduce(linkMap, source);

return source;
});

let source = new Link(<any>map, moduleSources);

bundleSourcemapChain.forEach(map => {
source = new Link(<any>map, [<any>source]);
});
source = bundleSourcemapChain.reduce(linkMap, source);

let { sources, sourcesContent, names, mappings } = source.traceMappings();

Expand Down
21 changes: 21 additions & 0 deletions test/form/samples/render-chunk-plugin-sourcemaps/_config.js
@@ -0,0 +1,21 @@
module.exports = {
description:
'supports returning undefined source maps from render chunk hooks, when source maps are enabled',
options: {
output: {
sourcemap: true
},
plugins: [
{
renderChunk(code) {
return '/* first plugin */';
}
},
{
renderChunk(code) {
return code + '\n/* second plugin */';
}
}
]
}
};

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions test/form/samples/render-chunk-plugin-sourcemaps/main.js
@@ -0,0 +1 @@
console.log( 1 + 1 );

0 comments on commit dbd2e47

Please sign in to comment.