Skip to content

Commit 6801022

Browse files
authored
fix: lose closing brace when exports are unprovided (#19669)
1 parent 5a204dc commit 6801022

File tree

3 files changed

+25
-2
lines changed

3 files changed

+25
-2
lines changed

lib/library/AssignLibraryPlugin.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -344,9 +344,14 @@ class AssignLibraryPlugin extends AbstractLibraryPlugin {
344344
);
345345
}
346346
result.add(
347-
` ${hasProvided ? " " : ""}${webpackExportTarget}[__webpack_i__] = ${exports}[__webpack_i__];\n`
347+
` ${
348+
hasProvided ? " " : ""
349+
}${webpackExportTarget}[__webpack_i__] = ${exports}[__webpack_i__];\n`
348350
);
349-
result.add(hasProvided ? " }\n}\n" : "\n");
351+
if (hasProvided) {
352+
result.add(" }\n");
353+
}
354+
result.add("}\n");
350355
result.add(
351356
`Object.defineProperty(${exportTarget}, "__esModule", { value: true });\n`
352357
);
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
Object.defineProperty(exports, "__esModule", { value: true });
2+
exports.main = main;
3+
function main() {}
4+
5+
// commonjs bailout
6+
if(this){}
7+
8+
it("Should work when exports are unprovided", function() {
9+
expect(true).toBe(true);
10+
});
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
/** @type {import("../../../../").Configuration} */
2+
module.exports = {
3+
output: {
4+
library: {
5+
type: "commonjs-static"
6+
}
7+
}
8+
};

0 commit comments

Comments
 (0)