fix: don't skip export generation for default reexport (#19463)

This commit is contained in:
Alexander Akait 2025-04-24 20:28:39 +03:00 committed by GitHub
parent 648e026c1e
commit dc33a1e662
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 36 additions and 6 deletions

View File

@ -124,7 +124,7 @@ class ModuleLibraryPlugin extends AbstractLibraryPlugin {
{ options, compilation }
) {
const result = new ConcatSource(source);
const exportsInfos = options.export
const exportsInfo = options.export
? [
moduleGraph.getExportInfo(
module,
@ -151,7 +151,7 @@ class ModuleLibraryPlugin extends AbstractLibraryPlugin {
? "const"
: "var";
for (const exportInfo of exportsInfos) {
for (const exportInfo of exportsInfo) {
if (!exportInfo.provided) continue;
let shouldContinue = false;
@ -164,6 +164,7 @@ class ModuleLibraryPlugin extends AbstractLibraryPlugin {
for (const reexportInfo of exp.orderedExports) {
if (
reexportInfo.provided === false &&
reexportInfo.name !== "default" &&
reexportInfo.name === /** @type {string[]} */ (reexport.export)[0]
) {
shouldContinue = true;

View File

@ -5,7 +5,7 @@ module.exports = {
output: {
module: true,
library: {
type: "modern-module"
type: "module"
},
filename: "[name].js",
chunkFormat: "module"

Binary file not shown.

After

Width:  |  Height:  |  Size: 15 KiB

View File

@ -0,0 +1,4 @@
declare module "*.png" {
const value: string;
export default value;
}

View File

@ -1,7 +1,15 @@
import { value, T } from './re-export'
import logo from './file.png';
export { value, T }
type MyType = string;
export { logo, value, T, MyType }
it("should not reexport type", function () {
expect(value).toBe(1)
});
type OtherMyType = string;
export type { OtherMyType }
export default MyType;

View File

@ -14,7 +14,7 @@ module.exports = {
output: {
module: true,
library: {
type: "modern-module"
type: "module"
},
chunkFormat: "module"
},
@ -35,7 +35,24 @@ module.exports = {
options: {
transpileOnly: true
}
},
{
type: "asset/inline",
test: /\.png$/
}
]
}
},
plugins: [
function () {
const handler = compilation => {
compilation.hooks.afterProcessAssets.tap("testcase", assets => {
const source = assets["bundle0.mjs"].source();
expect(source).toContain(
"export { file_namespaceObject as logo, value };"
);
});
};
this.hooks.compilation.tap("testcase", handler);
}
]
};