diff --git a/src/lib/converter/converter.ts b/src/lib/converter/converter.ts index c22680ce6..f011da057 100644 --- a/src/lib/converter/converter.ts +++ b/src/lib/converter/converter.ts @@ -10,6 +10,7 @@ import { ConverterComponent, ConverterNodeComponent, ConverterTypeComponent, Typ import { CompilerHost } from './utils/compiler-host'; import { Component, Option, ChildableComponent, ComponentClass } from '../utils/component'; import { normalizePath } from '../utils/fs'; +import { createMinimatch } from '../utils/paths'; /** * Result structure of the [[Converter.convert]] method. @@ -384,26 +385,33 @@ export class Converter extends ChildableComponent { const program = context.program; - program.getSourceFiles().forEach((sourceFile) => { + const exclude = createMinimatch(this.application.exclude || []); + const isExcluded = (file: ts.SourceFile) => exclude.some(mm => mm.match(file.fileName)); + + const includedSourceFiles = program.getSourceFiles() + .filter(file => !isExcluded(file)); + const isRelevantError = ({ file }: ts.Diagnostic) => !file || includedSourceFiles.includes(file); + + includedSourceFiles.forEach((sourceFile) => { this.convertNode(context, sourceFile); }); - let diagnostics = program.getOptionsDiagnostics(); + let diagnostics = program.getOptionsDiagnostics().filter(isRelevantError); if (diagnostics.length) { return diagnostics; } - diagnostics = program.getSyntacticDiagnostics(); + diagnostics = program.getSyntacticDiagnostics().filter(isRelevantError); if (diagnostics.length) { return diagnostics; } - diagnostics = program.getGlobalDiagnostics(); + diagnostics = program.getGlobalDiagnostics().filter(isRelevantError); if (diagnostics.length) { return diagnostics; } - diagnostics = program.getSemanticDiagnostics(); + diagnostics = program.getSemanticDiagnostics().filter(isRelevantError); if (diagnostics.length) { return diagnostics; } diff --git a/src/test/module/a.ts b/src/test/module/a.ts new file mode 100644 index 000000000..129b9c31a --- /dev/null +++ b/src/test/module/a.ts @@ -0,0 +1,5 @@ +import { multiply } from './b'; + +export function add(a: number, b: number) { + return a + multiply(b, 1); +} diff --git a/src/test/module/b.ts b/src/test/module/b.ts new file mode 100644 index 000000000..f0fc5ed2d --- /dev/null +++ b/src/test/module/b.ts @@ -0,0 +1,3 @@ +export function multiply(a: number, b: number) { + return a * b; +} diff --git a/src/test/typedoc.ts b/src/test/typedoc.ts index 977bf858a..f223c4c1b 100644 --- a/src/test/typedoc.ts +++ b/src/test/typedoc.ts @@ -2,12 +2,13 @@ import { Application } from '..'; import * as Path from 'path'; import Assert = require('assert'); import './.dot'; +import { Converter, Context } from '../lib/converter'; describe('TypeDoc', function() { let application: Application; describe('Application', function() { - it('constructs', function() { + before('constructs', function() { application = new Application(); }); it('expands input directory', function() { @@ -64,5 +65,17 @@ describe('TypeDoc', function() { Assert.equal(expanded.indexOf(Path.join(inputFiles, '.dot', 'index.d.ts')), -1); Assert.equal(expanded.indexOf(inputFiles), -1); }); + it('Honors the exclude option even if a module is imported', () => { + application.options.setValue('exclude', '**/b.d.ts'); + + function handler(context: Context) { + Assert.deepStrictEqual(context.fileNames, [ + Path.resolve(__dirname, 'module', 'a.d.ts').replace(/\\/g, '/') + ]); + } + application.converter.on(Converter.EVENT_END, handler); + application.convert([ Path.join(__dirname, 'module', 'a.d.ts')]); + application.converter.off(Converter.EVENT_END, handler); + }); }); }); diff --git a/tsconfig.json b/tsconfig.json index 2195896e8..ded73fcfa 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -6,7 +6,8 @@ "es5", "es2015.core", "es2015.collection", - "es2015.iterable" + "es2015.iterable", + "es2016.array.include" // Supported by Node 6+ ], "target": "es2015", "noImplicitAny": false,