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

Function projectEntry

javascript/selenium-webdriver/project_bidi_schema.mjs:224–263  ·  view source on GitHub ↗
(e)

Source from the content-addressed store, hash-verified

222}
223
224function projectEntry(e) {
225 if (typeof e === 'string') return { primitive: PRIMITIVES[e] ?? e }
226 if (!e || typeof e !== 'object') return { primitive: 'unknown' }
227 if (e.Operator) {
228 const { Operator, ...inner } = e
229 return withOperator(projectEntry(inner), Operator)
230 }
231 // A parenthesized type, or an operator's operand, is `{ Type: <innerType> }`: project the inner type.
232 if (e.Type && typeof e.Type === 'object') return projectEntry(e.Type)
233 if (e.Type === 'literal') return { const: e.Value }
234 if (e.Type === 'group' && e.Value) return e.Value in PRELUDE ? { primitive: PRELUDE[e.Value] } : { ref: e.Value }
235 if (e.Type === 'group' && Array.isArray(e.Properties)) {
236 // An inline group that only wraps anonymous ref(s) — e.g. a union arm
237 // `{ DateLocalValue }` — is that ref (or a union of them), not a record.
238 const refs = unionMemberRefs(e)
239 if (refs) return refs.length === 1 ? { ref: refs[0] } : unionNode(refs.map((r) => ({ ref: r })))
240 return {
241 record: e.Properties.flat()
242 .filter((p) => p?.Name)
243 .map(projectField),
244 }
245 }
246 if (e.Type === 'array') return { list: projectRef(e.Values?.[0]?.Type) }
247 if (e.Type === 'map') return { map: projectRef(e.ValueType ?? e.Values?.[0]?.Type), extensible: true }
248 if (e.Type === 'range') {
249 const min = boundValue(e.Value?.Min)
250 const max = boundValue(e.Value?.Max)
251 if (min === undefined || max === undefined) return { primitive: 'unknown' }
252 // A bound written as a float (`1.0`) parses to an integer `Value` carrying an `IsFloat`
253 // marker; consult it so `(0.0..1.0)` is a number range, not — as its integral bounds alone
254 // would read — an integer one. A bound with no marker falls back to its value's integralness.
255 const intBound = (b) => !b.IsFloat && Number.isInteger(b.Value)
256 const intRange = intBound(e.Value.Min) && intBound(e.Value.Max) // e.g. js-uint (0..MAX) vs latitude (-90.0..90.0)
257 const node = { primitive: intRange ? 'integer' : 'number', min, max }
258 // The parser's `Inclusive: false` is the `...` form, which excludes only the upper bound.
259 if (e.Value.Inclusive === false) node.exclusiveMax = true
260 return node
261 }
262 return { primitive: PRIMITIVES[e.Type] ?? 'unknown' }
263}
264
265// A wire key that is already an identifier is kept verbatim, so `namespaceURI` stays
266// wire-faithful; a quoted CDDL key that is not (`prefers-color-scheme`) is camelCased so

Callers 2

projectRefFunction · 0.85
projectTypeFunction · 0.85

Calls 8

withOperatorFunction · 0.85
unionMemberRefsFunction · 0.85
unionNodeFunction · 0.85
projectRefFunction · 0.85
boundValueFunction · 0.85
intBoundFunction · 0.85
filterMethod · 0.80
mapMethod · 0.45

Tested by

no test coverage detected