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

Function dedupeDefs

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

Source from the content-addressed store, hash-verified

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

Callers 2

normalizeAstFunction · 0.85

Calls 3

setMethod · 0.65
getMethod · 0.65
hasMethod · 0.45

Tested by

no test coverage detected