(config: Config)
| 131 | * @internal |
| 132 | */ |
| 133 | export const parseConfig = (config: Config): ConfigInternal => { |
| 134 | const orderedParams: Array<Param.Any> = [] |
| 135 | const flags: Array<Param.AnyFlag> = [] |
| 136 | const args: Array<Param.AnyArgument> = [] |
| 137 | |
| 138 | function parse(config: Config): ConfigInternal.Tree { |
| 139 | const tree: ConfigInternal.Tree = Object.create(null) |
| 140 | for (const key of Object.keys(config)) { |
| 141 | tree[key] = parseValue(config[key]) |
| 142 | } |
| 143 | return tree |
| 144 | } |
| 145 | |
| 146 | function parseValue( |
| 147 | value: Param.Any | ReadonlyArray<Param.Any | Config> | Config |
| 148 | ): ConfigInternal.Node { |
| 149 | if (Array.isArray(value)) { |
| 150 | return { |
| 151 | _tag: "Array", |
| 152 | children: (value as Array<any>).map((v) => parseValue(v)) |
| 153 | } |
| 154 | } else if (Param.isParam(value)) { |
| 155 | const index = orderedParams.length |
| 156 | orderedParams.push(value) |
| 157 | |
| 158 | if (value.kind === "argument") { |
| 159 | args.push(value as Param.AnyArgument) |
| 160 | } else { |
| 161 | flags.push(value as Param.AnyFlag) |
| 162 | } |
| 163 | |
| 164 | return { _tag: "Param", index } |
| 165 | } else { |
| 166 | return { |
| 167 | _tag: "Nested", |
| 168 | tree: parse(value as Config) |
| 169 | } |
| 170 | } |
| 171 | } |
| 172 | |
| 173 | return { |
| 174 | [ConfigInternalTypeId]: ConfigInternalTypeId, |
| 175 | flags, |
| 176 | arguments: args, |
| 177 | orderedParams, |
| 178 | tree: parse(config) |
| 179 | } |
| 180 | } |
| 181 | |
| 182 | /** @internal */ |
| 183 | export const emptyConfig: ConfigInternal = parseConfig({}) |
no test coverage detected