Skip to content

Commit 5be4026

Browse files
authored
Merge pull request webpack#7015 from webpack/refactor/source_map_deopt
Avoid deopt when cache is set in EvalSourceMapDevToolModuleTemplatePlugin
2 parents e320290 + 6e154f6 commit 5be4026

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

lib/EvalDevToolModuleTemplatePlugin.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
const { RawSource } = require("webpack-sources");
88
const ModuleFilenameHelpers = require("./ModuleFilenameHelpers");
9+
910
const cache = new WeakMap();
1011

1112
class EvalDevToolModuleTemplatePlugin {

lib/EvalSourceMapDevToolModuleTemplatePlugin.js

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
const { RawSource } = require("webpack-sources");
88
const ModuleFilenameHelpers = require("./ModuleFilenameHelpers");
99

10+
const cache = new WeakMap();
11+
1012
class EvalSourceMapDevToolModuleTemplatePlugin {
1113
constructor(compilation, options) {
1214
this.compilation = compilation;
@@ -29,8 +31,11 @@ class EvalSourceMapDevToolModuleTemplatePlugin {
2931
moduleTemplate.hooks.module.tap(
3032
"EvalSourceMapDevToolModuleTemplatePlugin",
3133
(source, module) => {
32-
if (source.__EvalSourceMapDevToolData)
33-
return source.__EvalSourceMapDevToolData;
34+
const cachedSource = cache.get(source);
35+
if (cachedSource !== undefined) {
36+
return cachedSource;
37+
}
38+
3439
if (!matchModule(module.resource)) {
3540
return source;
3641
}
@@ -87,10 +92,14 @@ class EvalSourceMapDevToolModuleTemplatePlugin {
8792
"utf8"
8893
).toString("base64")}`
8994
) + `\n//# sourceURL=webpack-internal:///${module.id}\n`; // workaround for chrome bug
90-
source.__EvalSourceMapDevToolData = new RawSource(
95+
96+
const evalSource = new RawSource(
9197
`eval(${JSON.stringify(content + footer)});`
9298
);
93-
return source.__EvalSourceMapDevToolData;
99+
100+
cache.set(source, evalSource);
101+
102+
return evalSource;
94103
}
95104
);
96105
moduleTemplate.hooks.hash.tap(

0 commit comments

Comments
 (0)