|
1 | 1 | import * as _ from 'lodash';
|
2 | 2 | import * as ts from 'typescript';
|
3 | 3 |
|
4 |
| -import { DeclarationOption, ParameterScope, convert, TypeDocOptions, KeyToDeclaration, TypeDocAndTSOptions, TypeDocOptionMap } from './declaration'; |
| 4 | +import { DeclarationOption, ParameterScope, ParameterType, convert, TypeDocOptions, KeyToDeclaration, TypeDocAndTSOptions, TypeDocOptionMap } from './declaration'; |
5 | 5 | import { Logger } from '../loggers';
|
6 | 6 | import { Result, Ok, Err } from '../result';
|
7 | 7 | import { insertPrioritySorted } from '../array';
|
@@ -109,10 +109,7 @@ export class Options {
|
109 | 109 | */
|
110 | 110 | reset() {
|
111 | 111 | for (const declaration of this._declarations.values()) {
|
112 |
| - if (declaration.scope !== ParameterScope.TypeScript) { |
113 |
| - this._values[declaration.name] = convert(declaration.defaultValue, declaration) |
114 |
| - .expect(`Failed to validate default value for ${declaration.name}`); |
115 |
| - } |
| 112 | + this.setOptionValueToDefault(declaration); |
116 | 113 | }
|
117 | 114 | this._compilerOptions = {};
|
118 | 115 | }
|
@@ -169,10 +166,7 @@ export class Options {
|
169 | 166 | }
|
170 | 167 | }
|
171 | 168 |
|
172 |
| - if (declaration.scope !== ParameterScope.TypeScript) { |
173 |
| - this._values[declaration.name] = convert(declaration.defaultValue, declaration) |
174 |
| - .expect(`Failed to validate default value for ${declaration.name}`); |
175 |
| - } |
| 169 | + this.setOptionValueToDefault(declaration); |
176 | 170 | }
|
177 | 171 |
|
178 | 172 | /**
|
@@ -320,6 +314,22 @@ export class Options {
|
320 | 314 | }
|
321 | 315 | return errors.length ? Err(errors) : Ok(void 0);
|
322 | 316 | }
|
| 317 | + |
| 318 | + /** |
| 319 | + * Sets the value of a given option to its default value. |
| 320 | + * @param declaration The option whoes value should be reset. |
| 321 | + */ |
| 322 | + private setOptionValueToDefault(declaration: Readonly<DeclarationOption>): void { |
| 323 | + if (declaration.scope !== ParameterScope.TypeScript) { |
| 324 | + // No nead to convert the defaultValue for a map type as it has to be of a specific type |
| 325 | + if (declaration.type === ParameterType.Map) { |
| 326 | + this._values[declaration.name] = declaration.defaultValue; |
| 327 | + } else { |
| 328 | + this._values[declaration.name] = convert(declaration.defaultValue, declaration) |
| 329 | + .expect(`Failed to validate default value for ${declaration.name}`); |
| 330 | + } |
| 331 | + } |
| 332 | + } |
323 | 333 | }
|
324 | 334 |
|
325 | 335 | /**
|
|
0 commit comments