Skip to content

Commit c340c88

Browse files
committed
Bringing back excludes error and fixing faulty test
1 parent db85643 commit c340c88

4 files changed

Lines changed: 41 additions & 61 deletions

File tree

src/compiler/commandLineParser.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -713,6 +713,9 @@ namespace ts {
713713
errors.push(createCompilerDiagnostic(Diagnostics.Compiler_option_0_requires_a_value_of_type_1, "exclude", "Array"));
714714
}
715715
}
716+
else if (hasProperty(json, "excludes")) {
717+
errors.push(createCompilerDiagnostic(Diagnostics.Unknown_option_excludes_Did_you_mean_exclude));
718+
}
716719
else {
717720
// By default, exclude common package folders
718721
excludeSpecs = ["node_modules", "bower_components", "jspm_packages"];

src/harness/virtualFileSystem.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
/// <reference path="harness.ts" />
2+
/// <reference path="..\compiler\commandLineParser.ts"/>
23
namespace Utils {
34
export class VirtualFileSystemEntry {
45
fileSystem: VirtualFileSystem;
@@ -157,4 +158,29 @@ namespace Utils {
157158
return directory;
158159
}
159160
}
161+
162+
export class MockParseConfigHost extends VirtualFileSystem implements ts.ParseConfigHost {
163+
constructor(currentDirectory: string, ignoreCase: boolean, files: string[]) {
164+
super(currentDirectory, ignoreCase);
165+
for (const file of files) {
166+
this.addFile(file);
167+
}
168+
}
169+
170+
readDirectory(path: string, extensions: string[], excludes: string[], includes: string[]) {
171+
return ts.matchFiles(path, extensions, excludes, includes, this.useCaseSensitiveFileNames, this.currentDirectory, (path: string) => this.getAccessibleFileSystemEntries(path));
172+
}
173+
174+
getAccessibleFileSystemEntries(path: string) {
175+
const entry = this.traversePath(path);
176+
if (entry && entry.isDirectory()) {
177+
const directory = <VirtualDirectory>entry;
178+
return {
179+
files: ts.map(directory.getFiles(), f => f.name),
180+
directories: ts.map(directory.getDirectories(), d => d.name)
181+
};
182+
}
183+
return { files: [], directories: [] };
184+
}
185+
}
160186
}

tests/cases/unittests/matchFiles.ts

Lines changed: 3 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -3,33 +3,8 @@
33
/// <reference path="..\..\..\src\harness\virtualFileSystem.ts" />
44

55
namespace ts {
6-
class MockParseConfigHost extends Utils.VirtualFileSystem implements ParseConfigHost {
7-
constructor(currentDirectory: string, ignoreCase: boolean, files: string[]) {
8-
super(currentDirectory, ignoreCase);
9-
for (const file of files) {
10-
this.addFile(file);
11-
}
12-
}
13-
14-
readDirectory(path: string, extensions: string[], excludes: string[], includes: string[]) {
15-
return matchFiles(path, extensions, excludes, includes, this.useCaseSensitiveFileNames, this.currentDirectory, (path: string) => this.getAccessibleFileSystemEntries(path));
16-
}
17-
18-
getAccessibleFileSystemEntries(path: string) {
19-
const entry = this.traversePath(path);
20-
if (entry && entry.isDirectory()) {
21-
const directory = <Utils.VirtualDirectory>entry;
22-
return {
23-
files: map(directory.getFiles(), f => f.name),
24-
directories: map(directory.getDirectories(), d => d.name)
25-
};
26-
}
27-
return { files: [], directories: [] };
28-
}
29-
}
30-
316
const caseInsensitiveBasePath = "c:/dev/";
32-
const caseInsensitiveHost = new MockParseConfigHost(caseInsensitiveBasePath, /*useCaseSensitiveFileNames*/ false, [
7+
const caseInsensitiveHost = new Utils.MockParseConfigHost(caseInsensitiveBasePath, /*useCaseSensitiveFileNames*/ false, [
338
"c:/dev/a.ts",
349
"c:/dev/a.d.ts",
3510
"c:/dev/a.js",
@@ -53,7 +28,7 @@ namespace ts {
5328
]);
5429

5530
const caseSensitiveBasePath = "/dev/";
56-
const caseSensitiveHost = new MockParseConfigHost(caseSensitiveBasePath, /*useCaseSensitiveFileNames*/ true, [
31+
const caseSensitiveHost = new Utils.MockParseConfigHost(caseSensitiveBasePath, /*useCaseSensitiveFileNames*/ true, [
5732
"/dev/a.ts",
5833
"/dev/a.d.ts",
5934
"/dev/a.js",
@@ -76,7 +51,7 @@ namespace ts {
7651
"/dev/js/b.js",
7752
]);
7853

79-
const caseInsensitiveMixedExtensionHost = new MockParseConfigHost(caseInsensitiveBasePath, /*useCaseSensitiveFileNames*/ false, [
54+
const caseInsensitiveMixedExtensionHost = new Utils.MockParseConfigHost(caseInsensitiveBasePath, /*useCaseSensitiveFileNames*/ false, [
8055
"c:/dev/a.ts",
8156
"c:/dev/a.d.ts",
8257
"c:/dev/a.js",

tests/cases/unittests/tsconfigParsing.ts

Lines changed: 9 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -2,31 +2,6 @@
22
/// <reference path="..\..\..\src\compiler\commandLineParser.ts" />
33

44
namespace ts {
5-
class MockParseConfigHost extends Utils.VirtualFileSystem implements ParseConfigHost {
6-
constructor(currentDirectory: string, ignoreCase: boolean, files: string[]) {
7-
super(currentDirectory, ignoreCase);
8-
for (const file of files) {
9-
this.addFile(file);
10-
}
11-
}
12-
13-
readDirectory(path: string, extensions: string[], excludes: string[], includes: string[]) {
14-
return matchFiles(path, extensions, excludes, includes, this.useCaseSensitiveFileNames, this.currentDirectory, (path: string) => this.getAccessibleFileSystemEntries(path));
15-
}
16-
17-
getAccessibleFileSystemEntries(path: string) {
18-
const entry = this.traversePath(path);
19-
if (entry && entry.isDirectory()) {
20-
const directory = <Utils.VirtualDirectory>entry;
21-
return {
22-
files: map(directory.getFiles(), f => f.name),
23-
directories: map(directory.getDirectories(), d => d.name)
24-
};
25-
}
26-
return { files: [], directories: [] };
27-
}
28-
}
29-
305
describe('parseConfigFileTextToJson', () => {
316
function assertParseResult(jsonText: string, expectedConfigObject: { config?: any; error?: Diagnostic }) {
327
let parsed = ts.parseConfigFileTextToJson("/apath/tsconfig.json", jsonText);
@@ -41,13 +16,14 @@ namespace ts {
4116

4217
function assertParseErrorWithExcludesKeyword(jsonText: string) {
4318
let parsed = ts.parseConfigFileTextToJson("/apath/tsconfig.json", jsonText);
44-
let parsedCommand = ts.parseJsonConfigFileContent(parsed, ts.sys, "tests/cases/unittests");
45-
assert.isTrue(undefined !== parsedCommand.errors);
19+
let parsedCommand = ts.parseJsonConfigFileContent(parsed.config, ts.sys, "tests/cases/unittests");
20+
assert.isTrue(parsedCommand.errors && parsedCommand.errors.length === 1 &&
21+
parsedCommand.errors[0].code === ts.Diagnostics.Unknown_option_excludes_Did_you_mean_exclude.code);
4622
}
4723

4824
function assertParseFileList(jsonText: string, configFileName: string, basePath: string, allFileList: string[], expectedFileList: string[]) {
4925
const json = JSON.parse(jsonText);
50-
const host: ParseConfigHost = new MockParseConfigHost(basePath, true, allFileList);
26+
const host: ParseConfigHost = new Utils.MockParseConfigHost(basePath, true, allFileList);
5127
const parsed = ts.parseJsonConfigFileContent(json, host, basePath, /*existingOptions*/ undefined, configFileName);
5228
assert.isTrue(arrayIsEqualTo(parsed.fileNames.sort(), expectedFileList.sort()));
5329
}
@@ -125,27 +101,27 @@ namespace ts {
125101
assertParseResult(
126102
`{
127103
"compilerOptions": {
128-
"lib": "es5"
104+
"lib": ["es5"]
129105
}
130106
}`, {
131-
config: { compilerOptions: { lib: "es5" } }
107+
config: { compilerOptions: { lib: ["es5"] } }
132108
});
133109

134110
assertParseResult(
135111
`{
136112
"compilerOptions": {
137-
"lib": "es5,es6"
113+
"lib": ["es5", "es6"]
138114
}
139115
}`, {
140-
config: { compilerOptions: { lib: "es5,es6" } }
116+
config: { compilerOptions: { lib: ["es5", "es6"] } }
141117
});
142118
});
143119

144120
it("returns error when tsconfig have excludes", () => {
145121
assertParseErrorWithExcludesKeyword(
146122
`{
147123
"compilerOptions": {
148-
"lib": "es5"
124+
"lib": ["es5"]
149125
},
150126
"excludes": [
151127
"foge.ts"

0 commit comments

Comments
 (0)