(at: number, routeList = false)
| 1144 | else if (source[next] === '(') sites.push({ name: { name: id[0], call: true, at: argAt }, at: open }); |
| 1145 | }; |
| 1146 | function unit(at: number, routeList = false): number { |
| 1147 | const ch = source[at]; |
| 1148 | if (ch === '"' || ch === "'" || ch === '`') { |
| 1149 | let i = at + 1; |
| 1150 | while (i < source.length) { |
| 1151 | if (source[i] === '\\') { i += 2; continue; } |
| 1152 | if (source[i] === ch) return i + 1; |
| 1153 | if (ch === '`' && source.startsWith('${', i)) { i = unit(i + 1); continue; } |
| 1154 | i++; |
| 1155 | } |
| 1156 | return i; |
| 1157 | } |
| 1158 | // A regex can contain braces or JSX-looking text without ending an expression. |
| 1159 | if (ch === '/') { |
| 1160 | const before = tokenBefore(at); |
| 1161 | if (!before || /[=(:,[!&|?{};]$/.test(before) || /\b(?:return|throw|case|yield)\s*$/.test(before)) { |
| 1162 | let inClass = false; |
| 1163 | for (let i = at + 1; i < source.length && source[i] !== '\n'; i++) { |
| 1164 | if (source[i] === '\\') { i++; continue; } |
| 1165 | if (source[i] === '[') inClass = true; |
| 1166 | else if (source[i] === ']') inClass = false; |
| 1167 | else if (source[i] === '/' && !inClass) { |
| 1168 | i++; |
| 1169 | while (/[a-z]/i.test(source[i] ?? '') && i < source.length) i++; |
| 1170 | return i; |
| 1171 | } |
| 1172 | } |
| 1173 | } |
| 1174 | } |
| 1175 | if (allowJsx && ch === '<' && /^<(?:[A-Za-z][\w.:-]*|>)/.test(source.slice(at))) { |
| 1176 | const before = tokenBefore(at); |
| 1177 | // `count<limit` and `factory<Type>()` are not JSX opening tags. |
| 1178 | if (!/[\w$)\]'"]$/.test(before) || /\breturn$/.test(before)) return jsx(at); |
| 1179 | } |
| 1180 | const close = ch === '{' ? '}' : ch === '[' ? ']' : ch === '(' ? ')' : undefined; |
| 1181 | if (!close) return at + 1; |
| 1182 | const call = ch === '(' ? routerCall(at) : null; |
| 1183 | const router = ch === '(' && routesFromElements(at); |
| 1184 | let i = at + 1; |
| 1185 | const fields = new Map<string, { value: string; at: number }>(); |
| 1186 | while ((i = trivia(i)) < source.length && source[i] !== close) { |
| 1187 | // A property must start at an object entry, never inside its value. |
| 1188 | const key = ch === '{' ? /^(?:([A-Za-z_$][\w$]*)|["']([^"']+)["'])\s*:/.exec(source.slice(i)) : null; |
| 1189 | if (key) { |
| 1190 | const name = key[1] ?? key[2]!; |
| 1191 | const start = i; |
| 1192 | const valueAt = trivia(i + key[0].length); |
| 1193 | // A route's children are more routes, written in place or named. |
| 1194 | const children = objects && name === 'children'; |
| 1195 | i = valueAt; |
| 1196 | let valueEnd = i; |
| 1197 | while ((i = trivia(i)) < source.length && source[i] !== ',' && source[i] !== close) { |
| 1198 | i = unit(i, children); |
| 1199 | valueEnd = i; |
| 1200 | } |
| 1201 | const value = source.slice(valueAt, valueEnd).trim(); |
| 1202 | fields.set(name, { value, at: start }); |
| 1203 | if (children && /^[A-Za-z_$][\w$]*$/.test(value)) names.push({ name: value, call: false, at: valueAt }); |
no test coverage detected