Skip to content

Commit c2d3848

Browse files
Merge branch 'main' into refactor/parser-tree-handle-types
# Conflicts: # lib/javascript/syntax-printer.js
2 parents 7c83d25 + 1b98b3e commit c2d3848

18 files changed

Lines changed: 257 additions & 89 deletions

File tree

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"webpack": patch
3+
---
4+
5+
Keep a strict ES module importer's interop for lazily compiled modules.

‎lib/hmr/LazyCompilationPlugin.js‎

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ const getMatchModuleGlobCondition = memoize(
6060
/** @import RequestShortener from "../util/RequestShortener" */
6161
/** @import { ResolverWithOptions } from "../resolve/ResolverFactory" */
6262
/** @import ESMImportDependency from "../dependencies/esm/ESMImportDependency" */
63+
/** @import { JavascriptModuleBuildMeta } from "../javascript/JavascriptModule" */
6364
/** @import Hash from "../util/Hash" */
6465
/** @import { InputFileSystem } from "../fs/fs" */
6566

@@ -235,8 +236,9 @@ class LazyCompilationProxyModule extends Module {
235236
* @param {ModuleResult["client"]} client client
236237
* @param {ModuleResult["data"]} data data
237238
* @param {ModuleResult["active"]} active true when active, otherwise false
239+
* @param {boolean} strict whether its importers are strict ES modules
238240
*/
239-
constructor(context, originalModule, request, client, data, active) {
241+
constructor(context, originalModule, request, client, data, active, strict) {
240242
super(
241243
WEBPACK_MODULE_TYPE_LAZY_COMPILATION_PROXY,
242244
context,
@@ -255,14 +257,16 @@ class LazyCompilationProxyModule extends Module {
255257
this.data = data;
256258
/** @type {boolean} */
257259
this.active = active;
260+
/** @type {boolean} */
261+
this.strict = strict;
258262
}
259263

260264
/**
261265
* Returns the unique identifier used to reference this module.
262266
* @returns {string} a unique identifier of the module
263267
*/
264268
identifier() {
265-
return `${WEBPACK_MODULE_TYPE_LAZY_COMPILATION_PROXY}|${this.originalModule.identifier()}`;
269+
return `${WEBPACK_MODULE_TYPE_LAZY_COMPILATION_PROXY}|${this.originalModule.identifier()}${this.strict ? "|strict" : ""}`;
266270
}
267271

268272
/**
@@ -291,6 +295,7 @@ class LazyCompilationProxyModule extends Module {
291295
this.client = m.client;
292296
this.data = m.data;
293297
this.active = m.active;
298+
this.strict = m.strict;
294299
}
295300

296301
/**
@@ -419,7 +424,7 @@ class LazyCompilationProxyModule extends Module {
419424
module,
420425
request: this.request,
421426
dependency: dep,
422-
strict: false, // TODO this should be inherited from the original module
427+
strict: this.strict,
423428
message: "import()",
424429
runtimeRequirements,
425430
originModule: this
@@ -622,14 +627,26 @@ class LazyCompilationPlugin {
622627
const moduleInfo = backend.module(module);
623628
if (!moduleInfo) return module;
624629
const { client, data, active } = moduleInfo;
630+
// The proxy builds the namespace its importers get, and a strict ES module
631+
// importer needs another shape than a loose one, so each gets its own proxy.
632+
const importer = compilation.moduleGraph.getParentModule(
633+
resolveData.dependencies[0]
634+
);
635+
const strict = Boolean(
636+
importer &&
637+
importer.buildMeta &&
638+
/** @type {JavascriptModuleBuildMeta} */ (importer.buildMeta)
639+
.strictHarmonyModule
640+
);
625641

626642
return new LazyCompilationProxyModule(
627643
compiler.context,
628644
module,
629645
resolveData.request,
630646
client,
631647
data,
632-
active
648+
active,
649+
strict
633650
);
634651
}
635652
);

‎lib/javascript/ScopeAnalyzer.js‎

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1280,8 +1280,7 @@ class MinifierVariable extends Variable {
12801280
/** @type {number} how an `export` naming it keeps its name, as `EXPORT_*` */
12811281
this.export = 0;
12821282
/** @type {string | null} the name mangling gives it */
1283-
// eslint-disable-next-line camelcase -- terser's name, which the printer reads
1284-
this.mangled_name = null;
1283+
this.mangledName = null;
12851284
/** @type {number} how many names read or write it, which the mangler gives the short names by */
12861285
this.referenceCount = 0;
12871286
/** @type {boolean} whether a name writes it, which a `SyntaxTree`'s analysis alone records */
@@ -1306,8 +1305,7 @@ class MinifierLabel {
13061305
/** @type {string} */
13071306
this.name = name;
13081307
/** @type {string | null} the name mangling gives it */
1309-
// eslint-disable-next-line camelcase -- terser's name, which the printer reads
1310-
this.mangled_name = null;
1308+
this.mangledName = null;
13111309
/** @type {MinifierLabel | null} */
13121310
this.parent = parent;
13131311
/** @type {number} where the mangler's label names stood when it named this one */

0 commit comments

Comments
 (0)