| 330 | } |
| 331 | |
| 332 | const collectNamed = ( |
| 333 | node: NamedNode, |
| 334 | code: string, |
| 335 | named: (Token | Span)[] |
| 336 | ): void => { |
| 337 | const { start, end } = node |
| 338 | if (node.type === "Literal" && typeof node.value === "string") { |
| 339 | // by its value, as one transform quotes it otherwise than another |
| 340 | named.push({ start, end, text: JSON.stringify(node.value) }) |
| 341 | } else if ( |
| 342 | (node.type === "Literal" && node.regex) || |
| 343 | node.type === "TemplateElement" || |
| 344 | node.type === "JSXText" |
| 345 | ) |
| 346 | named.push({ start, end, text: code.slice(start, end) }) |
| 347 | for (const key in node) { |
| 348 | if (key === "parent") continue |
| 349 | const child = (node as never as Record<string, unknown>)[key] |
| 350 | if (Array.isArray(child)) { |
| 351 | for (const item of child) |
| 352 | if (isNode(item)) collectNamed(item, code, named) |
| 353 | } else if (isNode(child)) collectNamed(child, code, named) |
| 354 | } |
| 355 | } |
| 356 | |
| 357 | const isNode = (value: unknown): value is NamedNode => |
| 358 | typeof value === "object" && |