diff --git a/src/harness/fourslash.ts b/src/harness/fourslash.ts index 272f4c1c1dd..06ff5d4234b 100644 --- a/src/harness/fourslash.ts +++ b/src/harness/fourslash.ts @@ -2476,6 +2476,17 @@ module FourSlash { } } + // @Filename is the only directive that can be used in a test that contains tsconfig.json file. + if (containTSConfigJson(files)) { + let directive = getNonFileNameOptionInFileList(files); + if (directive == null) { + directive = getNonFileNameOptionInObject(globalOptions); + } + if (directive !== null) { + throw Error("It is not allowed to use tsconfig.json along with directive '" + directive + "'"); + } + } + return { markerPositions, markers, @@ -2485,6 +2496,34 @@ module FourSlash { }; } + function containTSConfigJson(files: FourSlashFile[]): boolean { + for (let i = 0; i < files.length; ++i) { + if (files[i].fileOptions['Filename'] === 'tsconfig.json') { + return true; + } + } + return false; + } + + function getNonFileNameOptionInFileList(files: FourSlashFile[]): string { + for (let i = 0; i < files.length; ++i) { + let option = getNonFileNameOptionInObject(files[i].fileOptions); + if (option !== null) { + return option; + } + } + return null; + } + + function getNonFileNameOptionInObject(optionObject: { [s: string]: string }): string { + for (let option in optionObject) { + if (option !== metadataOptionNames.fileName) { + return option; + } + } + return null; + } + const enum State { none, inSlashStarMarker,