Skip to content

Commit c9bad17

Browse files
committed
Fix webpack#5806, TypeError on ExternalModule hash.update
undefined must be coerced to `false`
1 parent 551ea76 commit c9bad17

File tree

2 files changed

+29
-1
lines changed

2 files changed

+29
-1
lines changed

lib/ExternalModule.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ class ExternalModule extends Module {
120120
updateHash(hash) {
121121
hash.update(this.type);
122122
hash.update(JSON.stringify(this.request));
123-
hash.update(JSON.stringify(this.optional));
123+
hash.update(JSON.stringify(Boolean(this.optional)));
124124
super.updateHash(hash);
125125
}
126126
}

test/ExternalModule.test.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -340,4 +340,32 @@ module.exports = some/request;`;
340340
hashedText.should.containEql("12345678");
341341
});
342342
});
343+
344+
describe("#updateHash without optional", function() {
345+
let hashedText;
346+
let hash;
347+
beforeEach(function() {
348+
hashedText = "";
349+
hash = {
350+
update: (text) => {
351+
hashedText += text;
352+
}
353+
};
354+
// Note no set of `externalModule.optional`, which crashed externals in 3.7.0
355+
externalModule.id = 12345678;
356+
externalModule.updateHash(hash);
357+
});
358+
it("updates hash with request", function() {
359+
hashedText.should.containEql("some/request");
360+
});
361+
it("updates hash with type", function() {
362+
hashedText.should.containEql("some-type");
363+
});
364+
it("updates hash with optional flag", function() {
365+
hashedText.should.containEql("false");
366+
});
367+
it("updates hash with module id", function() {
368+
hashedText.should.containEql("12345678");
369+
});
370+
});
343371
});

0 commit comments

Comments
 (0)