( parent: Namespaces | undefined, attributes: Readonly<Record<string, string>> )
| 2328 | |
| 2329 | // Declarations are copied, as they can outlive the chunk of their tag |
| 2330 | const declare = ( |
| 2331 | parent: Namespaces | undefined, |
| 2332 | attributes: Readonly<Record<string, string>> |
| 2333 | ): Namespaces | undefined => { |
| 2334 | let declarations: Record<string, string> | undefined |
| 2335 | for (const name in attributes) { |
| 2336 | if (!Object.hasOwn(attributes, name)) continue |
| 2337 | const prefix = name === "xmlns" ? "" : name.startsWith("xmlns:") ? name.slice(6) : undefined |
| 2338 | // Omit the reserved xml and xmlns prefixes |
| 2339 | if (prefix === undefined || prefix === "xml" || prefix === "xmlns") continue |
| 2340 | declarations ??= new Attributes() |
| 2341 | declarations[copyString(prefix)] = copyString(attributes[name]) |
| 2342 | } |
| 2343 | return declarations === undefined ? parent : { declarations, parent } |
| 2344 | } |
| 2345 | |
| 2346 | // `string` is "*" or a literal name; `namespace: undefined` matches any namespace |
| 2347 | type Segment = string | { readonly namespace: string | undefined; readonly localName: string } |
no test coverage detected