From 90e31adea85e12d0e6c2004d29c2dbfd31f898fa Mon Sep 17 00:00:00 2001 From: unknown Date: Mon, 27 Jul 2015 21:02:58 -0700 Subject: [PATCH] Raise error if mixing tsconfig.json and directives. --- src/harness/fourslash.ts | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) 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,