1818 * - a path composed onto the root constant (`` `${STUDIO_ROOT_PATH}/…` ``,
1919 * `STUDIO_ROOT_PATH + '/…'`), the same hand-build one step removed.
2020 *
21+ * A route PATTERN is not an address: `<Route path="/studio">` declares what
22+ * the console serves, and builds no link. It stays a plain literal, because
23+ * the console's route table is read as source text
24+ * (`useConsoleActionRuntime.onSuccessNavigateHost-13379.test.tsx` reads every
25+ * top-level `path="/…"`), so the string initializer of a `<Route>`'s `path`
26+ * attribute is spared. Every other spelling, including a `<Link to="/studio">`
27+ * or a `path` on anything but a `<Route>`, is refused.
28+ *
2129 * `studioAddress.ts` is the one file allowed to spell the root (and the
2230 * mapping table beside it, which spells shapes, not links). The server's
2331 * two review links are held by the same kind of pin in `@objectstack/types`
@@ -93,8 +101,17 @@ function handBuiltStudioAddresses(fileName: string, text: string): string[] {
93101 hits . push ( `${ line + 1 } : ${ node . getText ( source ) . replace ( / \s + / g, ' ' ) . slice ( 0 , 120 ) } ` ) ;
94102 } ;
95103 const isRoot = ( node : ts . Node ) => ts . isIdentifier ( node ) && ROOT_NAMES . has ( node . text ) ;
104+ // `<Route path="/studio">`: a route pattern the console serves, not a link.
105+ const isRoutePattern = ( node : ts . Node ) =>
106+ ts . isStringLiteral ( node ) &&
107+ ts . isJsxAttribute ( node . parent ) &&
108+ node . parent . name . getText ( source ) === 'path' &&
109+ ts . isJsxAttributes ( node . parent . parent ) &&
110+ node . parent . parent . parent . tagName . getText ( source ) === 'Route' ;
96111 const visit = ( node : ts . Node ) : void => {
97- if ( ( ts . isStringLiteral ( node ) || ts . isNoSubstitutionTemplateLiteral ( node ) ) && STUDIO_LITERAL . test ( node . text ) ) {
112+ if ( isRoutePattern ( node ) ) {
113+ // Spared: see the header.
114+ } else if ( ( ts . isStringLiteral ( node ) || ts . isNoSubstitutionTemplateLiteral ( node ) ) && STUDIO_LITERAL . test ( node . text ) ) {
98115 hit ( node ) ;
99116 } else if ( ts . isTemplateExpression ( node ) ) {
100117 if ( STUDIO_LITERAL . test ( node . head . text ) || ( node . head . text === '' && isRoot ( node . templateSpans [ 0 ] . expression ) ) ) {
@@ -115,7 +132,9 @@ describe('no Studio address is built by hand under ui/ (objectstack#36895)', ()
115132 expect ( scan ( "const a = '/studio';" ) ) . toHaveLength ( 1 ) ;
116133 expect ( scan ( 'const b = `/studio/${pkg}/data`;' ) ) . toHaveLength ( 1 ) ;
117134 expect ( scan ( 'const c = "/studio?new=package";' ) ) . toHaveLength ( 1 ) ;
118- expect ( scan ( 'const d = <Route path="/studio" />;' ) ) . toHaveLength ( 1 ) ;
135+ expect ( scan ( 'const d = <Link to="/studio" />;' ) ) . toHaveLength ( 1 ) ;
136+ expect ( scan ( 'const d2 = <Tab path="/studio" />;' ) ) . toHaveLength ( 1 ) ;
137+ expect ( scan ( 'const d3 = <Route path={`/studio/${pkg}`} />;' ) ) . toHaveLength ( 1 ) ;
119138 expect ( scan ( 'const e = `${STUDIO_ROOT_PATH}/${pkg}`;' ) ) . toHaveLength ( 1 ) ;
120139 expect ( scan ( "const f = STUDIO_ROOT_PATH + '/' + pkg;" ) ) . toHaveLength ( 1 ) ;
121140 // Not an address.
@@ -124,6 +143,9 @@ describe('no Studio address is built by hand under ui/ (objectstack#36895)', ()
124143 expect ( scan ( "const i = 'studio:builder';" ) ) . toEqual ( [ ] ) ;
125144 expect ( scan ( '// opens /studio/crm/data\nconst j = 1;' ) ) . toEqual ( [ ] ) ;
126145 expect ( scan ( '/** `/studio/<package>/metadata` */\nconst k = 1;' ) ) . toEqual ( [ ] ) ;
146+ // A route pattern is a declaration, not a link.
147+ expect ( scan ( 'const m = <Route path="/studio" element={<X />} />;' ) ) . toEqual ( [ ] ) ;
148+ expect ( scan ( 'const n = <Route path="/studio/:packageId"><Route index /></Route>;' ) ) . toEqual ( [ ] ) ;
127149 // The builder's output is not a literal.
128150 expect ( scan ( 'const l = studioHomePath(pkg);' ) ) . toEqual ( [ ] ) ;
129151 } ) ;
0 commit comments