MCPcopy Index your code
hub / github.com/SeleniumHQ/selenium / collectUnionMembers

Function collectUnionMembers

javascript/selenium-webdriver/generate_bidi.mjs:451–496  ·  view source on GitHub ↗

* Walk the `CommandData` or `EventData` union type hierarchy and collect all * leaf definition names (the actual command/event group names). * * The CDDL AST represents union groups with Properties that can be: * - An array of choice objects (each with a Type.Value pointing to the next level)

(rootName, defMap, visited = new Set())

Source from the content-addressed store, hash-verified

449 * A leaf is a definition that itself has a `method` property (string literal).
450 */
451function collectUnionMembers(rootName, defMap, visited = new Set()) {
452 if (visited.has(rootName)) return new Set()
453 visited.add(rootName)
454
455 const def = defMap.get(rootName)
456 if (!def) return new Set()
457
458 const members = new Set()
459
460 // Flatten Properties — each element is either a choice-array or a property object.
461 const rawProps = def.Properties ?? []
462 const allChoices = []
463 for (const prop of rawProps) {
464 if (Array.isArray(prop)) {
465 allChoices.push(...prop)
466 } else {
467 allChoices.push(prop)
468 }
469 }
470
471 for (const choice of allChoices) {
472 // choice.Type can be a single object or an array of type alternatives.
473 const typeEntries = Array.isArray(choice.Type) ? choice.Type : [choice.Type]
474
475 for (const entry of typeEntries) {
476 if (entry?.Type !== 'group' || !entry.Value) continue
477 const childName = entry.Value
478 const childDef = defMap.get(childName)
479 if (!childDef) continue
480
481 // A leaf has a `method` property — it is the actual command or event definition.
482 const childProps = childDef.Properties ?? []
483 const flat = childProps.flatMap((p) => (Array.isArray(p) ? p : [p]))
484 if (flat.some((p) => p.Name === 'method')) {
485 members.add(childName)
486 } else {
487 // Intermediate union — recurse.
488 for (const m of collectUnionMembers(childName, defMap, visited)) {
489 members.add(m)
490 }
491 }
492 }
493 }
494
495 return members
496}
497
498/**
499 * Build a name → definition map from the AST (deduplicated — first wins).

Callers 1

collectAllMembersFunction · 0.85

Calls 3

addMethod · 0.65
getMethod · 0.65
hasMethod · 0.45

Tested by

no test coverage detected