diff --git a/src/compiler/commandLineParser.ts b/src/compiler/commandLineParser.ts index c53e2fcc2e..d08ca9bdae 100644 --- a/src/compiler/commandLineParser.ts +++ b/src/compiler/commandLineParser.ts @@ -652,6 +652,9 @@ namespace ts { return output; } + // Skip over any minified JavaScript files (ending in ".min.js") + // Skip over dotted files and folders as well + const IgnoreFileNamePattern = /(\.min\.js$)|([\\/]\.[\w.])/; /** * Parse the contents of a config file (tsconfig.json). * @param json The contents of the config file to parse @@ -715,8 +718,7 @@ namespace ts { continue; } - // Skip over any minified JavaScript files (ending in ".min.js") - if (/\.min\.js$/.test(fileName)) { + if (IgnoreFileNamePattern.test(fileName)) { continue; } diff --git a/tests/cases/unittests/tsconfigParsing.ts b/tests/cases/unittests/tsconfigParsing.ts index 29283acfe3..7cb72f4723 100644 --- a/tests/cases/unittests/tsconfigParsing.ts +++ b/tests/cases/unittests/tsconfigParsing.ts @@ -13,13 +13,41 @@ namespace ts { assert.isTrue(undefined === parsed.config); assert.isTrue(undefined !== parsed.error); } - + function assertParseErrorWithExcludesKeyword(jsonText: string) { let parsed = ts.parseConfigFileTextToJson("/apath/tsconfig.json", jsonText); let parsedCommand = ts.parseJsonConfigFileContent(parsed, ts.sys, "tests/cases/unittests"); assert.isTrue(undefined !== parsedCommand.errors); } + function assertParseFileList(jsonText: string, configFileName: string, basePath: string, allFileList: string[], expectedFileList: string[]) { + const json = JSON.parse(jsonText); + const host: ParseConfigHost = { readDirectory: mockReadDirectory }; + const parsed = ts.parseJsonConfigFileContent(json, host, basePath, /*existingOptions*/ undefined, configFileName); + assert.isTrue(arrayIsEqualTo(parsed.fileNames.sort(), expectedFileList.sort())); + + function mockReadDirectory(rootDir: string, extension: string, exclude: string[]): string[] { + const result: string[] = []; + const fullExcludeDirectories = ts.map(exclude, directory => combinePaths(rootDir, directory)); + for (const file of allFileList) { + let shouldExclude = false; + for (const fullExcludeDirectorie of fullExcludeDirectories) { + if (file.indexOf(fullExcludeDirectorie) >= 0) { + shouldExclude = true; + break; + } + } + if (shouldExclude) { + continue; + } + if (fileExtensionIs(file, extension)) { + result.push(file); + } + } + return result; + } + } + it("returns empty config for file with only whitespaces", () => { assertParseResult("", { config : {} }); assertParseResult(" ", { config : {} }); @@ -108,7 +136,7 @@ namespace ts { config: { compilerOptions: { lib: "es5,es6" } } }); }); - + it("returns error when tsconfig have excludes", () => { assertParseErrorWithExcludesKeyword( `{ @@ -120,5 +148,15 @@ namespace ts { ] }`); }); + + it("ignore dotted files and folders", () => { + assertParseFileList( + `{}`, + "tsconfig.json", + "/apath", + ["/apath/test.ts", "/apath/.git/a.ts", "/apath/.b.ts", "/apath/..c.ts"], + ["/apath/test.ts"] + ) + }) }); }