Skip to content
Source
Sign inSign up
TanStack/router

feat(router-generator): support higher-order wrappers around createFileRoute #7766

Opendhleong(GitHub profile, opens in a new tab)wants to merge 1 commit intomain fromrefs/pull/7766/headopened

Showing 2 changed files with 75 additions and 26 deletions (loading 1).

x
0 of 2 viewed, 2 left
75 additions and 26 deletionspackages/router-generator/src/transform/transform.tsModified
View file
@@ -218,23 +218,30 @@
continue
​
- const init = getRouteConstructorInit(declarator.init)
- if (!init) {
- if (isDirectRouteConstructorCall(declarator.init)) {
+ // The exported `Route` may be wrapped by one or more higher-order
+ // handlers (e.g. `wrap('x')(createFileRoute('/path')({...}))`), so search
+ // the whole init expression for the `createFileRoute('/path')({...})`
+ // call rather than requiring it to be the top-level init. The wrapper is
+ // opaque to the generator; we only need the inner constructor call.
+ const inits = findRouteConstructorInits(declarator.init)
+ if (inits.length === 0) {
+ if (containsRouteConstructorCall(declarator.init)) {
hasMalformedRouteCall = true
continue
​
- const routeIdArg = init.innerCall.arguments[0]
- if (isSupportedRouteId(routeIdArg)) {
- calls.push({
- callee: init.callee,
- routeIdArg,
- optionsArg: init.outerCall.arguments[0],