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

Function collectUnionMembers

javascript/selenium-webdriver/generate_bidi.mjs:417–463  ·  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

415 * A leaf is a definition that itself has a `method` property (string literal).
416 */
417function collectUnionMembers(rootName, defMap, visited = new Set()) {
418 if (visited.has(rootName)) return new Set()
419 visited.add(rootName)
420
421 const def = defMap.get(rootName)
422 if (!def) return new Set()
423
424 const members = new Set()
425
426 // Flatten Properties — each element is either a choice-array or a property object. A one-member
427 // aggregate (`MozCommand = webExtension.MozListExtensions`) parses as a variable holding a PropertyType.
428 const rawProps = def.Properties ?? (def.Type === 'variable' ? [{ Type: def.PropertyType }] : [])
429 const allChoices = []
430 for (const prop of rawProps) {
431 if (Array.isArray(prop)) {
432 allChoices.push(...prop)
433 } else {
434 allChoices.push(prop)
435 }
436 }
437
438 for (const choice of allChoices) {
439 // choice.Type can be a single object or an array of type alternatives.
440 const typeEntries = Array.isArray(choice.Type) ? choice.Type : [choice.Type]
441
442 for (const entry of typeEntries) {
443 if (entry?.Type !== 'group' || !entry.Value) continue
444 const childName = entry.Value
445 const childDef = defMap.get(childName)
446 if (!childDef) continue
447
448 // A leaf has a `method` property — it is the actual command or event definition.
449 const childProps = childDef.Properties ?? []
450 const flat = childProps.flatMap((p) => (Array.isArray(p) ? p : [p]))
451 if (flat.some((p) => p.Name === 'method')) {
452 members.add(childName)
453 } else {
454 // Intermediate union — recurse.
455 for (const m of collectUnionMembers(childName, defMap, visited)) {
456 members.add(m)
457 }
458 }
459 }
460 }
461
462 return members
463}
464
465/**
466 * Build a name → definition map from the AST (deduplicated — first wins).

Callers 1

collectAllMembersFunction · 0.85

Calls 4

pushMethod · 0.80
addMethod · 0.65
getMethod · 0.65
hasMethod · 0.45

Tested by

no test coverage detected