MCPcopy Create free account
hub / github.com/arktypeio/arktype / appendSpreadBranch

Function appendSpreadBranch

ark/type/parser/tupleLiteral.ts:189–215  ·  view source on GitHub ↗
(
	base: mutableInnerOfKind<"sequence">,
	branch: BaseRoot
)

Source from the content-addressed store, hash-verified

187}
188
189const appendSpreadBranch = (
190 base: mutableInnerOfKind<"sequence">,
191 branch: BaseRoot
192): mutableInnerOfKind<"sequence"> => {
193 const spread = branch.select({ method: "find", kind: "sequence" })
194 if (!spread) {
195 // an array with no sequence reference is the empty tuple, which adds no
196 // elements, or unknown[]
197 return branch.select({ method: "find", kind: "exactLength" })?.rule === 0 ?
198 base
199 : appendVariadicElement(base, $ark.kw.unknown)
200 }
201
202 if (spread.prefix)
203 for (const node of spread.prefix) appendRequiredElement(base, node)
204 if (spread.defaultables) {
205 for (const [node, def] of spread.defaultables)
206 appendDefaultableElement(base, node, def)
207 }
208 if (spread.optionals)
209 for (const node of spread.optionals) appendOptionalElement(base, node)
210 if (spread.variadic) appendVariadicElement(base, spread.variadic)
211 if (spread.postfix)
212 for (const node of spread.postfix) appendRequiredElement(base, node)
213
214 return base
215}
216
217type SequencePhase = satisfy<
218 keyof Sequence.Inner,

Callers 1

parseTupleLiteralFunction · 0.85

Calls 4

appendVariadicElementFunction · 0.85
appendRequiredElementFunction · 0.85
appendDefaultableElementFunction · 0.85
appendOptionalElementFunction · 0.85

Tested by

no test coverage detected