(at: number)
| 1249 | return i < source.length ? i + 1 : i; |
| 1250 | } |
| 1251 | function jsx(at: number): number { |
| 1252 | const tag = /^<([\w.:-]*)/.exec(source.slice(at))!; |
| 1253 | let i = at + tag[0].length; |
| 1254 | const attrs = new Map<string, string>(); |
| 1255 | const spreads: string[] = []; |
| 1256 | while ((i = trivia(i)) < source.length && source[i] !== '>' && !source.startsWith('/>', i)) { |
| 1257 | const attr = /^[\w:-]+/.exec(source.slice(i)); |
| 1258 | if (!attr) { |
| 1259 | const from = i; |
| 1260 | i = unit(i); |
| 1261 | const spread = /^\{\s*\.\.\.\s*([A-Za-z_$][\w$]*)\s*\}$/.exec(source.slice(from, i)); |
| 1262 | if (spread) spreads.push(spread[1]!); |
| 1263 | continue; |
| 1264 | } |
| 1265 | i = trivia(i + attr[0].length); |
| 1266 | // A bare attribute is `true`: `<Route index element={<Home/>}/>`. |
| 1267 | if (source[i] !== '=') { |
| 1268 | attrs.set(attr[0], '{true}'); |
| 1269 | continue; |
| 1270 | } |
| 1271 | i = trivia(i + 1); |
| 1272 | const start = i; |
| 1273 | i = unit(i); |
| 1274 | attrs.set(attr[0], source.slice(start, i)); |
| 1275 | } |
| 1276 | let scope: RouteScope | undefined; |
| 1277 | // A `<Route>` with no address of its own, settled once its children are read. |
| 1278 | let addressless: { scope: RouteScope; tags: number; page: boolean } | undefined; |
| 1279 | // `<BrowserRouter>…</BrowserRouter>`: the routes at its top are at `/`. |
| 1280 | const router = ROUTER_ELEMENT.test(tag[1]!) ? { start: at, end: source.length } : undefined; |
| 1281 | if (router) routers.push(router); |
| 1282 | if (tag[1] === 'Route' && i < source.length) { |
| 1283 | const pathText = attrs.get('path'); |
| 1284 | const expression = (name: string) => attrs.get(name)?.replace(/^\{([\s\S]*)\}$/, '$1'); |
| 1285 | // `path="team"`, or the same string in braces: `path={"team"}`. |
| 1286 | const path = literal(pathText ?? '') ?? literal(expression('path') ?? ''); |
| 1287 | routeTags.push({ at, spreads, path: expression('path')?.trim() }); |
| 1288 | const element = elementPage(expression('element')); |
| 1289 | const component = componentName(expression('component'), false) ?? element; |
| 1290 | const loaded = lazyRouteReference(expression('lazy'), elementTag); |
| 1291 | // A `<Route>` is a route with nothing of its own to render already. |
| 1292 | const lazy = loaded === OUTLET ? undefined : loaded; |
| 1293 | const route: RouteScope = { part: { lit: path ?? '' }, at, start: at, end: source.length, component, lazy, jsx: true }; |
| 1294 | if (path) scope = route; |
| 1295 | else if (pathText === undefined || path === '') { |
| 1296 | // `<Route index element={<Home/>}/>` is the page at its parent's address. |
| 1297 | if (/^\{\s*true\s*\}$/.test(attrs.get('index') ?? '')) { |
| 1298 | if (component || lazy) scope = { ...route, index: true }; |
| 1299 | } else { |
| 1300 | // Otherwise it is a layout at no address of its own when routes sit |
| 1301 | // inside it (`<Route element={<RequireAuth/>}>`), and `path=""` with |
| 1302 | // an `element` and nothing inside is the page at its parent's |
| 1303 | // address. Version 5's `<Route path="" component={NotFound}/>` is a |
| 1304 | // catch-all, which no address names. |
| 1305 | addressless = { scope: route, tags: routeTags.length, page: path === '' && Boolean(element || lazy) }; |
| 1306 | } |
| 1307 | } else { |
| 1308 | // `path={paths.home}`: an address the file does not spell out. |
no test coverage detected