Skip to content

Commit 266448d

Browse files
committed
fix(esm): escape external requests in star reexports
1 parent 3ca6196 commit 266448d

6 files changed

Lines changed: 60 additions & 1 deletion

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+
Escape external module requests in ESM library star reexports.

‎lib/library/ModuleLibraryPlugin.js‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -474,7 +474,7 @@ class ModuleLibraryPlugin extends AbstractLibraryPlugin {
474474
resolveDynamicStarReexport(module, false);
475475

476476
for (const request of moduleRequests) {
477-
result.add(`export * from "${request}";\n`);
477+
result.add(`export * from ${JSON.stringify(request)};\n`);
478478
}
479479

480480
for (const [origin, used] of unknownProvidedExports) {
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import * as library from "./library.mjs";
2+
3+
it("should preserve escaped external requests in native star reexports", () => {
4+
expect(library.quoted).toBe(1);
5+
expect(library.backslash).toBe(2);
6+
expect(library.newline).toBe(3);
7+
expect(library.plain).toBe(4);
8+
});
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
export * from 'quoted"module';
2+
export * from "backslash\\module";
3+
export * from "line\nmodule";
4+
export * from "plain-module";
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
"use strict";
2+
3+
module.exports = {
4+
/**
5+
* @param {number} index configuration index
6+
* @returns {string} emitted test bundle
7+
*/
8+
findBundle(index) {
9+
return `main${index}.mjs`;
10+
},
11+
modules: {
12+
'quoted"module': { quoted: 1 },
13+
"backslash\\module": { backslash: 2 },
14+
"line\nmodule": { newline: 3 },
15+
"plain-module": { plain: 4 }
16+
}
17+
};
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
"use strict";
2+
3+
/** @type {import("../../../../").Configuration[]} */
4+
module.exports = [
5+
{ type: "module", minimize: false },
6+
{ type: "module", minimize: true },
7+
{ type: "modern-module", minimize: false },
8+
{ type: "modern-module", minimize: true }
9+
].map(({ type, minimize }, index) => ({
10+
mode: minimize ? "production" : "development",
11+
entry: {
12+
main: "./index.js",
13+
library: { import: "./library.js", library: { type } }
14+
},
15+
output: { module: true, filename: `[name]${index}.mjs` },
16+
externalsType: "module",
17+
externals: [
18+
{ "./library.mjs": `./library${index}.mjs` },
19+
'quoted"module',
20+
"backslash\\module",
21+
"line\nmodule",
22+
"plain-module"
23+
],
24+
optimization: { minimize }
25+
}));

0 commit comments

Comments
 (0)