MCPcopy Create free account
hub / github.com/SeleniumHQ/selenium / dedupeDefs

Function dedupeDefs

javascript/selenium-webdriver/normalize_bidi_ast.mjs:479–499  ·  view source on GitHub ↗
(ast)

Source from the content-addressed store, hash-verified

477 * @returns {object[]} A new AST array with duplicate-named defs collapsed.
478 */
479export 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`.

Callers 2

normalizeAstFunction · 0.85

Calls 3

setMethod · 0.65
getMethod · 0.65
hasMethod · 0.45

Tested by

no test coverage detected