Skip to content

Commit 1aa7e1a

Browse files
authored
fix: ensure excludeBarrelReExports preserves exports with same name but different kind (#28)
1 parent 505a98a commit 1aa7e1a

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

packages/cli/src/core/parser/source/exclude-barrel-re-exports.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { groupBy } from "es-toolkit";
22
import { ExportDeclaration } from "../../types/parser.types.js";
33

44
export function excludeBarrelReExports(exportDeclarations: ExportDeclaration[]): ExportDeclaration[] {
5-
return Object.values(groupBy(exportDeclarations, exp => exp.symbolName))
5+
return Object.values(groupBy(exportDeclarations, exp => `${exp.symbolName}:${exp.kind}`))
66
.flatMap(declarations => {
77
if (declarations.length === 1) {
88
return declarations;

packages/cli/src/tests/core/parser/source/exclude-barrel-re-exports.spec.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { getExportedDeclarationsBySourceFile } from "../../../../core/parser/sou
44
import { getTsProject } from "../../../../core/get-ts-project.js";
55
import { getTsConfigPath } from "../../../../core/get-ts-config-path.js";
66
import { createE2EWorkspace, E2EWorkspace } from "../../../utils/create-e2e-workspace.js";
7+
import { ExportDeclaration, StandardizedFilePath } from "../../../../core/types/parser.types.js";
78

89
describe("excludeBarrelReExports", () => {
910
let workspace: E2EWorkspace;
@@ -92,4 +93,19 @@ describe("excludeBarrelReExports", () => {
9293
expect(filePaths.some(path => path.includes("math.ts"))).toBe(true);
9394
expect(filePaths.some(path => path.includes("string.ts"))).toBe(true);
9495
});
96+
97+
it("should keep both exports when symbolName is same but kind differs", () => {
98+
const result = excludeBarrelReExports([
99+
mockExport("Foo", "type", "/src/foo.ts"),
100+
mockExport("Foo", "function", "/src/foo.ts"),
101+
]);
102+
103+
expect(result).toHaveLength(2);
104+
expect(result.find(exp => exp.kind === "type")).toBeDefined();
105+
expect(result.find(exp => exp.kind === "function")).toBeDefined();
106+
});
95107
});
108+
109+
function mockExport(symbolName: string, kind: ExportDeclaration["kind"], filePath: string): ExportDeclaration {
110+
return { symbolName, kind, filePath: filePath as StandardizedFilePath } as ExportDeclaration;
111+
}

0 commit comments

Comments
 (0)