Skip to content

Commit

Permalink
remove exclusion of TS 2 options, add lib support
Browse files Browse the repository at this point in the history
* Remove restriction on what compilerOptions can be set
* remove filtering of TS 2.2 compilerOptions
* add support for 'list' option types
* Switch to processed compilerOptions
* add support for `compilerOptions.lib`

This PR removes the restrictions on setting options that aren't explicitly setup as options to allow new compilerOptions
to pass through TypeDoc to TypeScript. It also sets up support for 'list' parameter types, and switches to use the
processed compilerOptions, rather than `raw` so that the `lib` properties are properly parsed.

This should fix TypeStrong#315 and I believe TypeStrong#311.
  • Loading branch information
nicknisi committed Mar 22, 2017
1 parent 4204c20 commit 760ca41
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 17 deletions.
3 changes: 2 additions & 1 deletion src/lib/utils/options/declaration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,12 +95,13 @@ export class OptionDeclaration {
const map = this.map;
if (map !== 'object') {
const key = value ? (value + '').toLowerCase() : '';
const values = Object.keys(map).map(key => map[key]);

if (map instanceof Map && map.has(key)) {
value = map.get(key);
} else if (key in map) {
value = map[key];
} else if (errorCallback) {
} else if (!~values.indexOf(value) && errorCallback) {
if (this.mapError) {
errorCallback(this.mapError);
} else {
Expand Down
4 changes: 2 additions & 2 deletions src/lib/utils/options/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,10 +152,10 @@ export class Options extends ChildableComponent<Application, OptionsComponent> {
const value = obj[key];
const declaration = this.getDeclaration(key);
const shouldValueBeAnObject = declaration && declaration['map'] === 'object';
if (typeof value === 'object' && !shouldValueBeAnObject) {
if (!Array.isArray(value) && typeof value === 'object' && !shouldValueBeAnObject) {
this.setValues(value, prefix + key + '.', errorCallback);
} else {
this.setValue(prefix + key, value, errorCallback);
this.setValue(prefix + key, value);
}
}
}
Expand Down
17 changes: 8 additions & 9 deletions src/lib/utils/options/readers/tsconfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,31 +51,30 @@ export class TSConfigReader extends OptionsComponent {
return;
}

let data = ts.readConfigFile(fileName, ts.sys.readFile).config;
if (data === undefined) {
let { config } = ts.readConfigFile(fileName, ts.sys.readFile);
if (config === undefined) {
event.addError('The tsconfig file %s does not contain valid JSON.', fileName);
return;
}
if (!_.isPlainObject(data)) {
if (!_.isPlainObject(config)) {
event.addError('The tsconfig file %s does not contain a JSON object.', fileName);
return;
}

data = ts.parseJsonConfigFileContent(
data,
const { fileNames, options, raw: { typedocOptions }} = ts.parseJsonConfigFileContent(
config,
ts.sys,
Path.resolve(Path.dirname(fileName)),
{},
Path.resolve(fileName));

event.inputFiles = data.fileNames;
event.inputFiles = fileNames;

const ignored = TypeScriptSource.IGNORED;
let compilerOptions = _.clone(data.raw.compilerOptions);
for (const key of ignored) {
delete compilerOptions[key];
delete options[key];
}

_.defaults(event.data, data.raw.typedocOptions, compilerOptions);
_.defaults(event.data, typedocOptions, options);
}
}
9 changes: 4 additions & 5 deletions src/lib/utils/options/sources/typescript.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,7 @@ export class TypeScriptSource extends OptionsComponent {
static IGNORED: string[] = [
'out', 'version', 'help',
'watch', 'declaration', 'mapRoot',
'sourceMap', 'inlineSources', 'removeComments',
// Ignore new TypeScript 2.0 options until typedoc can't manage it.
'lib', 'noImplicitThis',
'traceResolution', 'noUnusedParameters', 'noUnusedLocals',
'skipLibCheck', 'declarationDir', 'types', 'typeRoots'
'sourceMap', 'inlineSources', 'removeComments'
];

initialize() {
Expand Down Expand Up @@ -59,6 +55,9 @@ export class TypeScriptSource extends OptionsComponent {
case 'string':
param.type = ParameterType.String;
break;
case 'list':
param.type = ParameterType.Array;
break;
default:
param.type = ParameterType.Map;
param.map = option.type;
Expand Down

0 comments on commit 760ca41

Please sign in to comment.