Skip to content

Commit c67d1a4

Browse files
committed
Let fourslash tests support extended tsconfig
1 parent 700d724 commit c67d1a4

File tree

1 file changed

+17
-13
lines changed

1 file changed

+17
-13
lines changed

src/harness/fourslash.ts

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -262,23 +262,12 @@ namespace FourSlash {
262262
// Initialize the language service with all the scripts
263263
let startResolveFileRef: FourSlashFile;
264264

265+
let configFileName: string;
265266
ts.forEach(testData.files, file => {
266267
// Create map between fileName and its content for easily looking up when resolveReference flag is specified
267268
this.inputFiles[file.fileName] = file.content;
268-
269269
if (ts.getBaseFileName(file.fileName).toLowerCase() === "tsconfig.json") {
270-
const configJson = ts.parseConfigFileTextToJson(file.fileName, file.content);
271-
assert.isTrue(configJson.config !== undefined);
272-
273-
// Extend our existing compiler options so that we can also support tsconfig only options
274-
if (configJson.config.compilerOptions) {
275-
const baseDirectory = ts.normalizePath(ts.getDirectoryPath(file.fileName));
276-
const tsConfig = ts.convertCompilerOptionsFromJson(configJson.config.compilerOptions, baseDirectory, file.fileName);
277-
278-
if (!tsConfig.errors || !tsConfig.errors.length) {
279-
compilationOptions = ts.extend(compilationOptions, tsConfig.options);
280-
}
281-
}
270+
configFileName = file.fileName;
282271
}
283272

284273
if (!startResolveFileRef && file.fileOptions[metadataOptionNames.resolveReference] === "true") {
@@ -290,6 +279,21 @@ namespace FourSlash {
290279
}
291280
});
292281

282+
if (configFileName) {
283+
const baseDir = ts.normalizePath(ts.getDirectoryPath(configFileName));
284+
const host = new Utils.MockParseConfigHost(baseDir, /*ignoreCase*/ false, this.inputFiles);
285+
286+
const configJsonObj = ts.parseConfigFileTextToJson(configFileName, this.inputFiles[configFileName]);
287+
assert.isTrue(configJsonObj.config !== undefined);
288+
289+
const { options, errors } = ts.parseJsonConfigFileContent(configJsonObj.config, host, baseDir);
290+
291+
// Extend our existing compiler options so that we can also support tsconfig only options
292+
if (!errors || errors.length === 0) {
293+
compilationOptions = ts.extend(compilationOptions, options);
294+
}
295+
}
296+
293297

294298
if (compilationOptions.typeRoots) {
295299
compilationOptions.typeRoots = compilationOptions.typeRoots.map(p => ts.getNormalizedAbsolutePath(p, this.basePath));

0 commit comments

Comments
 (0)