Skip to content

Commit cf57486

Browse files
authored
refactor (#13501)
1 parent 09b7f49 commit cf57486

File tree

1 file changed

+6
-12
lines changed
  • packages/react-router-dev/typegen

1 file changed

+6
-12
lines changed

packages/react-router-dev/typegen/index.ts

+6-12
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ import type { Context } from "./context";
1313
import { getTypesDir, getTypesPath } from "./paths";
1414
import * as Params from "./params";
1515
import * as Route from "./route";
16-
import type { RouteManifestEntry } from "../config/routes";
1716

1817
export async function run(rootDirectory: string, { mode }: { mode: string }) {
1918
const ctx = await createContext({ rootDirectory, mode, watch: false });
@@ -109,24 +108,19 @@ function register(ctx: Context) {
109108

110109
const { t } = Babel;
111110

112-
const fullpaths: Record<string, RouteManifestEntry[]> = {};
113-
for (const route of Object.values(ctx.config.routes)) {
114-
// skip pathless (layout) routes
115-
if (route.id !== "root" && !route.path) continue;
116-
111+
const fullpaths = new Set<string>();
112+
Object.values(ctx.config.routes).forEach((route) => {
113+
if (route.id !== "root" && !route.path) return;
117114
const lineage = Route.lineage(ctx.config.routes, route);
118115
const fullpath = Route.fullpath(lineage);
119-
const existing = fullpaths[fullpath];
120-
if (!existing || existing.length < lineage.length) {
121-
fullpaths[fullpath] = lineage;
122-
}
123-
}
116+
fullpaths.add(fullpath);
117+
});
124118

125119
const typeParams = t.tsTypeAliasDeclaration(
126120
t.identifier("Params"),
127121
null,
128122
t.tsTypeLiteral(
129-
Object.keys(fullpaths).map((fullpath) => {
123+
Array.from(fullpaths).map((fullpath) => {
130124
const params = Params.parse(fullpath);
131125
return t.tsPropertySignature(
132126
t.stringLiteral(fullpath),

0 commit comments

Comments
 (0)