Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not fail when generating hashes for tree-shaken dynamic imports #2638

Merged
merged 1 commit into from Jan 5, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 3 additions & 2 deletions src/Chunk.ts
Expand Up @@ -132,7 +132,7 @@ export default class Chunk {
} = undefined;
private renderedHash: string = undefined;
private renderedModuleSources: MagicString[] = undefined;
private renderedSource: MagicStringBundle = undefined;
private renderedSource: MagicStringBundle | null = null;
private renderedSourceLength: number = undefined;

constructor(graph: Graph, orderedModules: Module[], inlineDynamicImports: boolean) {
Expand Down Expand Up @@ -662,8 +662,9 @@ export default class Chunk {
return exports;
}

getRenderedHash() {
getRenderedHash(): string {
if (this.renderedHash) return this.renderedHash;
if (!this.renderedSource) return '';
const hash = sha256();
hash.update(this.renderedSource.toString());
return (this.renderedHash = hash.digest('hex'));
Expand Down
10 changes: 10 additions & 0 deletions test/chunking-form/samples/tree-shaken-dynamic-hash/_config.js
@@ -0,0 +1,10 @@
module.exports = {
description:
'Does not fail when calculating the hash of a file containing a tree-shaken dynamic import',
options: {
input: ['main.js'],
output: {
entryFileNames: '[hash].js'
}
}
};
@@ -0,0 +1,7 @@
define(function () { 'use strict';

var main = null;

return main;

});
@@ -0,0 +1,5 @@
'use strict';

var main = null;

module.exports = main;
@@ -0,0 +1,3 @@
var main = null;

export default main;
@@ -0,0 +1,10 @@
System.register([], function (exports, module) {
'use strict';
return {
execute: function () {

var main = exports('default', null);

}
};
});
1 change: 1 addition & 0 deletions test/chunking-form/samples/tree-shaken-dynamic-hash/foo.js
@@ -0,0 +1 @@
export default 42;
3 changes: 3 additions & 0 deletions test/chunking-form/samples/tree-shaken-dynamic-hash/main.js
@@ -0,0 +1,3 @@
export default false
? import('./foo.js')
: null;