( s: RootedRuntimeState )
| 78 | export type ParsedDefaultableProperty = readonly [BaseRoot, "=", unknown] |
| 79 | |
| 80 | export const parseDefault = ( |
| 81 | s: RootedRuntimeState |
| 82 | ): ParsedDefaultableProperty => { |
| 83 | // store the node that will be bounded |
| 84 | const baseNode = s.unsetRoot() |
| 85 | // collection literals are not unit literals, so they must be short-circuited |
| 86 | // here and represented as thunks to keep each traversal's default distinct |
| 87 | s.sc.skipSpace() |
| 88 | if (s.sc.unscanned.startsWith("{}")) { |
| 89 | s.sc.jumpForward(2) |
| 90 | return [baseNode, "=", emptyCollectionDefaults["{}"]] |
| 91 | } |
| 92 | if (s.sc.peek === "[") return [baseNode, "=", parseDefaultArray(s)] |
| 93 | const start = s.sc.location |
| 94 | s.parseOperand() |
| 95 | const defaultNode = s.unsetRoot() |
| 96 | // ( and keyof are operands that don't set a root |
| 97 | if (!defaultNode?.is("unit")) { |
| 98 | return s.error( |
| 99 | writeNonLiteralDefaultMessage( |
| 100 | defaultNode?.expression ?? s.sc.sliceChars(start).trim() |
| 101 | ) |
| 102 | ) |
| 103 | } |
| 104 | const defaultValue = |
| 105 | defaultNode.unit instanceof Date ? |
| 106 | () => new Date(defaultNode.unit as Date) |
| 107 | : defaultNode.unit |
| 108 | return [baseNode, "=", defaultValue] |
| 109 | } |
| 110 | |
| 111 | const parseDefaultArray = (s: RootedRuntimeState): (() => unknown[]) => { |
| 112 | const arrayStart = s.sc.location |
no test coverage detected