fix: do not duplicate modules with import attributes and reexport (#19290)

This commit is contained in:
Alexander Akait 2025-03-06 23:02:09 +03:00 committed by GitHub
parent 98221f239b
commit 59ede3c64a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
7 changed files with 36 additions and 1 deletions

View File

@ -149,6 +149,7 @@ module.exports = class HarmonyExportDependencyParserPlugin {
parser.state.harmonyNamedExports || new Set());
harmonyNamedExports.add(name);
InnerGraph.addVariableUsage(parser, id, name);
console.log(settings);
const dep = settings
? new HarmonyExportImportedSpecifierDependency(
settings.source,
@ -189,6 +190,7 @@ module.exports = class HarmonyExportDependencyParserPlugin {
harmonyStarExports = parser.state.harmonyStarExports =
parser.state.harmonyStarExports || new HarmonyStarExportsList();
}
const attributes = getImportAttributes(statement);
const dep = new HarmonyExportImportedSpecifierDependency(
/** @type {string} */ (source),
parser.state.lastHarmonyImportOrder,
@ -197,7 +199,8 @@ module.exports = class HarmonyExportDependencyParserPlugin {
harmonyNamedExports,
harmonyStarExports && harmonyStarExports.slice(),
exportPresenceMode,
harmonyStarExports
harmonyStarExports,
attributes
);
if (harmonyStarExports) {
harmonyStarExports.push(dep);

View File

@ -0,0 +1 @@
export {b} from "./b" with {type: "RANDOM"}

View File

@ -0,0 +1,5 @@
import { c } from "./c.js";
export function b() {
return "b" + c();
}

View File

@ -0,0 +1,3 @@
export function c() {
return "c";
}

View File

@ -0,0 +1,9 @@
import { b } from "./a.js";
function foo() {
return "a" + b();
}
it("should not duplicate modules", function() {
expect(foo()).toEqual("ab");
});

View File

@ -0,0 +1,3 @@
module.exports = function loader() {
return "export function b() { return 'b'; }";
};

View File

@ -0,0 +1,11 @@
/** @type {import("../../../../").Configuration} */
module.exports = {
module: {
rules: [
{
with: { type: "RANDOM" },
use: require.resolve("./test-loader")
}
]
}
};