Skip to content

Commit

Permalink
Do not fail when generating hashes for tree-shaken dynamic imports
Browse files Browse the repository at this point in the history
  • Loading branch information
lukastaegert committed Jan 5, 2019
1 parent 29b8c64 commit 8e2d73e
Show file tree
Hide file tree
Showing 8 changed files with 42 additions and 2 deletions.
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;

0 comments on commit 8e2d73e

Please sign in to comment.