(ast)
| 528 | * @returns {object[]} A new AST array with duplicate-named defs collapsed. |
| 529 | */ |
| 530 | export function dedupeDefs(ast) { |
| 531 | const indexByName = new Map() |
| 532 | const out = [] |
| 533 | for (const def of ast) { |
| 534 | const name = def && typeof def === 'object' && typeof def.Name === 'string' ? def.Name : null |
| 535 | if (name === null || !indexByName.has(name)) { |
| 536 | if (name !== null) indexByName.set(name, out.length) |
| 537 | out.push(def) |
| 538 | continue |
| 539 | } |
| 540 | if (!def.IsChoiceAddition) continue // plain duplicate: first wins |
| 541 | const i = indexByName.get(name) |
| 542 | const base = out[i] |
| 543 | const merged = { ...base } |
| 544 | if (base.Properties || def.Properties) merged.Properties = [...(base.Properties ?? []), ...(def.Properties ?? [])] |
| 545 | if (base.PropertyType || def.PropertyType) |
| 546 | merged.PropertyType = [...(base.PropertyType ?? []), ...(def.PropertyType ?? [])] |
| 547 | out[i] = merged |
| 548 | } |
| 549 | return out |
| 550 | } |
| 551 | |
| 552 | /** |
| 553 | * Apply all normalizations to a raw BiDi AST. Pure — does not mutate `ast`. |
no test coverage detected