Skip to content

Commit 90e31ad

Browse files
author
unknown
committed
Raise error if mixing tsconfig.json and directives.
1 parent 450112d commit 90e31ad

1 file changed

Lines changed: 39 additions & 0 deletions

File tree

src/harness/fourslash.ts

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2476,6 +2476,17 @@ module FourSlash {
24762476
}
24772477
}
24782478

2479+
// @Filename is the only directive that can be used in a test that contains tsconfig.json file.
2480+
if (containTSConfigJson(files)) {
2481+
let directive = getNonFileNameOptionInFileList(files);
2482+
if (directive == null) {
2483+
directive = getNonFileNameOptionInObject(globalOptions);
2484+
}
2485+
if (directive !== null) {
2486+
throw Error("It is not allowed to use tsconfig.json along with directive '" + directive + "'");
2487+
}
2488+
}
2489+
24792490
return {
24802491
markerPositions,
24812492
markers,
@@ -2485,6 +2496,34 @@ module FourSlash {
24852496
};
24862497
}
24872498

2499+
function containTSConfigJson(files: FourSlashFile[]): boolean {
2500+
for (let i = 0; i < files.length; ++i) {
2501+
if (files[i].fileOptions['Filename'] === 'tsconfig.json') {
2502+
return true;
2503+
}
2504+
}
2505+
return false;
2506+
}
2507+
2508+
function getNonFileNameOptionInFileList(files: FourSlashFile[]): string {
2509+
for (let i = 0; i < files.length; ++i) {
2510+
let option = getNonFileNameOptionInObject(files[i].fileOptions);
2511+
if (option !== null) {
2512+
return option;
2513+
}
2514+
}
2515+
return null;
2516+
}
2517+
2518+
function getNonFileNameOptionInObject(optionObject: { [s: string]: string }): string {
2519+
for (let option in optionObject) {
2520+
if (option !== metadataOptionNames.fileName) {
2521+
return option;
2522+
}
2523+
}
2524+
return null;
2525+
}
2526+
24882527
const enum State {
24892528
none,
24902529
inSlashStarMarker,

0 commit comments

Comments
 (0)