Skip to content

Commit 2efd21b

Browse files
authored
fix(re-exports): reexports runtime calculation should not accessing __WEBPACK_IMPORT_KEY__ decl with var (#20249)
1 parent c510070 commit 2efd21b

File tree

5 files changed

+35
-3
lines changed

5 files changed

+35
-3
lines changed

.changeset/clean-mugs-rescue.md

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+
Reexports runtime calculation should not accessing **WEBPACK_IMPORT_KEY** decl with var.

lib/dependencies/HarmonyExportImportedSpecifierDependency.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1251,9 +1251,11 @@ HarmonyExportImportedSpecifierDependency.Template = class HarmonyExportImportedS
12511251
}
12521252

12531253
content += "__WEBPACK_REEXPORT_OBJECT__[__WEBPACK_IMPORT_KEY__] = ";
1254-
content += runtimeTemplate.supportsArrowFunction()
1255-
? `() => ${importVar}[__WEBPACK_IMPORT_KEY__]`
1256-
: `function(key) { return ${importVar}[key]; }.bind(0, __WEBPACK_IMPORT_KEY__)`;
1254+
content +=
1255+
runtimeTemplate.supportsArrowFunction() &&
1256+
runtimeTemplate.supportsConst()
1257+
? `() => ${importVar}[__WEBPACK_IMPORT_KEY__]`
1258+
: `function(key) { return ${importVar}[key]; }.bind(0, __WEBPACK_IMPORT_KEY__)`;
12571259

12581260
runtimeRequirements.add(RuntimeGlobals.exports);
12591261
runtimeRequirements.add(RuntimeGlobals.definePropertyGetters);
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import * as ns from './lib'
2+
3+
it('should have correect reexport', () => {
4+
expect(ns).toHaveProperty('readFile');
5+
expect(ns).toHaveProperty('resolve');
6+
7+
8+
expect(typeof ns.sep).toBe('string');
9+
})
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
// 2 external modules, the external module exportsType is unkown
2+
// so the exports of current module can only be known at runtime
3+
export * from 'path'
4+
5+
export * from 'fs'
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
"use strict";
2+
3+
module.exports = {
4+
target: ["node"],
5+
output: {
6+
environment: {
7+
arrowFunction: true,
8+
const: false
9+
}
10+
}
11+
};

0 commit comments

Comments
 (0)