(ast)
| 477 | * @returns {object[]} A new AST array with duplicate-named defs collapsed. |
| 478 | */ |
| 479 | export function dedupeDefs(ast) { |
| 480 | const indexByName = new Map() |
| 481 | const out = [] |
| 482 | for (const def of ast) { |
| 483 | const name = def && typeof def === 'object' && typeof def.Name === 'string' ? def.Name : null |
| 484 | if (name === null || !indexByName.has(name)) { |
| 485 | if (name !== null) indexByName.set(name, out.length) |
| 486 | out.push(def) |
| 487 | continue |
| 488 | } |
| 489 | if (!def.IsChoiceAddition) continue // plain duplicate: first wins |
| 490 | const i = indexByName.get(name) |
| 491 | const base = out[i] |
| 492 | const merged = { ...base } |
| 493 | if (base.Properties || def.Properties) merged.Properties = [...(base.Properties ?? []), ...(def.Properties ?? [])] |
| 494 | if (base.PropertyType || def.PropertyType) |
| 495 | merged.PropertyType = [...(base.PropertyType ?? []), ...(def.PropertyType ?? [])] |
| 496 | out[i] = merged |
| 497 | } |
| 498 | return out |
| 499 | } |
| 500 | |
| 501 | /** |
| 502 | * Apply all normalizations to a raw BiDi AST. Pure — does not mutate `ast`. |
no test coverage detected