(candidate: T)
| 219 | } |
| 220 | |
| 221 | export function cloneCandidate<T extends Candidate>(candidate: T): T { |
| 222 | switch (candidate.kind) { |
| 223 | case 'arbitrary': |
| 224 | return { |
| 225 | kind: candidate.kind, |
| 226 | property: candidate.property, |
| 227 | value: candidate.value, |
| 228 | modifier: candidate.modifier |
| 229 | ? { kind: candidate.modifier.kind, value: candidate.modifier.value } |
| 230 | : null, |
| 231 | variants: candidate.variants.map(cloneVariant), |
| 232 | important: candidate.important, |
| 233 | raw: candidate.raw, |
| 234 | } satisfies Extract<Candidate, { kind: 'arbitrary' }> as T |
| 235 | |
| 236 | case 'static': |
| 237 | return { |
| 238 | kind: candidate.kind, |
| 239 | root: candidate.root, |
| 240 | variants: candidate.variants.map(cloneVariant), |
| 241 | important: candidate.important, |
| 242 | raw: candidate.raw, |
| 243 | } satisfies Extract<Candidate, { kind: 'static' }> as T |
| 244 | |
| 245 | case 'functional': |
| 246 | return { |
| 247 | kind: candidate.kind, |
| 248 | root: candidate.root, |
| 249 | value: candidate.value |
| 250 | ? candidate.value.kind === 'arbitrary' |
| 251 | ? { |
| 252 | kind: candidate.value.kind, |
| 253 | dataType: candidate.value.dataType, |
| 254 | value: candidate.value.value, |
| 255 | } |
| 256 | : { |
| 257 | kind: candidate.value.kind, |
| 258 | value: candidate.value.value, |
| 259 | fraction: candidate.value.fraction, |
| 260 | } |
| 261 | : null, |
| 262 | modifier: candidate.modifier |
| 263 | ? { kind: candidate.modifier.kind, value: candidate.modifier.value } |
| 264 | : null, |
| 265 | variants: candidate.variants.map(cloneVariant), |
| 266 | important: candidate.important, |
| 267 | raw: candidate.raw, |
| 268 | } satisfies Extract<Candidate, { kind: 'functional' }> as T |
| 269 | |
| 270 | default: |
| 271 | candidate satisfies never |
| 272 | throw new Error('Unknown candidate kind') |
| 273 | } |
| 274 | } |
| 275 | |
| 276 | export function cloneVariant<T extends Variant>(variant: T): T { |
| 277 | switch (variant.kind) { |
no outgoing calls
no test coverage detected