Skip to content

Commit 7bd9e09

Browse files
committed
Make configFile on compiler options as non enumerable
1 parent 16fd947 commit 7bd9e09

13 files changed

+38
-62
lines changed

src/compiler/commandLineParser.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1380,6 +1380,13 @@ namespace ts {
13801380
return parseJsonConfigFileContentWorker(/*json*/ undefined, sourceFile, host, basePath, existingOptions, configFileName, resolutionStack, extraFileExtensions);
13811381
}
13821382

1383+
/*@internal*/
1384+
export function setConfigFileInOptions(options: CompilerOptions, configFile: JsonSourceFile) {
1385+
if (configFile) {
1386+
Object.defineProperty(options, "configFile", { enumerable: false, writable: false, value: configFile });
1387+
}
1388+
}
1389+
13831390
/**
13841391
* Parse the contents of a config file from json or json source file (tsconfig.json).
13851392
* @param json The contents of the config file to parse
@@ -1406,8 +1413,7 @@ namespace ts {
14061413
const { raw } = parsedConfig;
14071414
const options = extend(existingOptions, parsedConfig.options || {});
14081415
options.configFilePath = configFileName;
1409-
options.configFile = sourceFile;
1410-
1416+
setConfigFileInOptions(options, sourceFile);
14111417
const { fileNames, wildcardDirectories } = getFileNames();
14121418
return {
14131419
options,

src/compiler/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3449,7 +3449,7 @@ namespace ts {
34493449
charset?: string;
34503450
checkJs?: boolean;
34513451
/* @internal */ configFilePath?: string;
3452-
/* @internal */ configFile?: JsonSourceFile;
3452+
/* @internal */ readonly configFile?: JsonSourceFile;
34533453
declaration?: boolean;
34543454
declarationDir?: string;
34553455
/* @internal */ diagnostics?: boolean;

src/harness/compilerRunner.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ class CompilerBaselineRunner extends RunnerBase {
8282
if (testCaseContent.tsConfig) {
8383
assert.equal(testCaseContent.tsConfig.fileNames.length, 0, `list of files in tsconfig is not currently supported`);
8484

85-
tsConfigOptions = ts.clone(testCaseContent.tsConfig.options);
85+
tsConfigOptions = ts.cloneCompilerOptions(testCaseContent.tsConfig.options);
8686
tsConfigFiles.push(this.createHarnessTestFile(testCaseContent.tsConfigFileUnitData, rootDir, ts.combinePaths(rootDir, tsConfigOptions.configFilePath)));
8787
}
8888
else {

src/harness/harness.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1123,7 +1123,7 @@ namespace Harness {
11231123
compilerOptions: ts.CompilerOptions,
11241124
// Current directory is needed for rwcRunner to be able to use currentDirectory defined in json file
11251125
currentDirectory: string): CompilationOutput {
1126-
const options: ts.CompilerOptions & HarnessOptions = compilerOptions ? ts.clone(compilerOptions) : { noResolve: false };
1126+
const options: ts.CompilerOptions & HarnessOptions = compilerOptions ? ts.cloneCompilerOptions(compilerOptions) : { noResolve: false };
11271127
options.target = options.target || ts.ScriptTarget.ES3;
11281128
options.newLine = options.newLine || ts.NewLineKind.CarriageReturnLineFeed;
11291129
options.noErrorTruncation = true;

src/harness/rwcRunner.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ namespace RWC {
8787
const configParseResult = ts.parseJsonSourceFileConfigFileContent(parsedTsconfigFileContents, configParseHost, ts.getDirectoryPath(tsconfigFile.path));
8888
fileNames = configParseResult.fileNames;
8989
opts.options = ts.extend(opts.options, configParseResult.options);
90+
ts.setConfigFileInOptions(opts.options, configParseResult.options.configFile);
9091
}
9192

9293
// Load the files
@@ -262,4 +263,4 @@ class RWCRunner extends RunnerBase {
262263
private runTest(jsonFileName: string) {
263264
RWC.runRWCTest(jsonFileName);
264265
}
265-
}
266+
}

src/harness/unittests/cachingInServerLSHost.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ namespace ts {
158158
// setting compiler options discards module resolution cache
159159
fileExistsCalled = false;
160160

161-
const compilerOptions = ts.clone(project.getCompilerOptions());
161+
const compilerOptions = ts.cloneCompilerOptions(project.getCompilerOptions());
162162
compilerOptions.target = ts.ScriptTarget.ES5;
163163
project.setCompilerOptions(compilerOptions);
164164

src/harness/unittests/configurationExtension.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -131,14 +131,15 @@ namespace ts {
131131
it(name, () => {
132132
const parsed = getParseCommandLine(entry);
133133
assert(!parsed.errors.length, flattenDiagnosticMessageText(parsed.errors[0] && parsed.errors[0].messageText, "\n"));
134-
assert.deepEqual(parsed.options, ts.extend(expected, <CompilerOptions>{ configFile: undefined }));
134+
assert.deepEqual(parsed.options, expected);
135135
assert.deepEqual(parsed.fileNames, expectedFiles);
136136
});
137137

138138
it(name + " with jsonSourceFile", () => {
139139
const { parsed, jsonSourceFile } = getParseCommandLineJsonSourceFile(entry);
140140
assert(!parsed.errors.length, flattenDiagnosticMessageText(parsed.errors[0] && parsed.errors[0].messageText, "\n"));
141-
assert.deepEqual(parsed.options, ts.extend(expected, <CompilerOptions>{ configFile: jsonSourceFile }));
141+
assert.deepEqual(parsed.options, expected);
142+
assert.equal(parsed.options.configFile, jsonSourceFile);
142143
assert.deepEqual(parsed.fileNames, expectedFiles);
143144
});
144145
}
@@ -208,4 +209,4 @@ namespace ts {
208209
});
209210
});
210211
});
211-
}
212+
}

src/harness/unittests/convertCompilerOptionsFromJson.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,11 @@ namespace ts {
3434
const host: ParseConfigHost = new Utils.MockParseConfigHost("/apath/", true, []);
3535
const { options: actualCompilerOptions, errors: actualParseErrors } = parseJsonSourceFileConfigFileContent(result, host, "/apath/", /*existingOptions*/ undefined, configFileName);
3636
expectedResult.compilerOptions["configFilePath"] = configFileName;
37-
expectedResult.compilerOptions.configFile = result;
3837

3938
const parsedCompilerOptions = JSON.stringify(actualCompilerOptions);
4039
const expectedCompilerOptions = JSON.stringify(expectedResult.compilerOptions);
4140
assert.equal(parsedCompilerOptions, expectedCompilerOptions);
41+
assert.equal(actualCompilerOptions.configFile, result);
4242

4343
const actualErrors = filter(actualParseErrors, error => error.code !== Diagnostics.No_inputs_were_found_in_config_file_0_Specified_include_paths_were_1_and_exclude_paths_were_2.code);
4444
const expectedErrors = expectedResult.errors;

src/server/project.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -789,7 +789,7 @@ namespace ts.server {
789789

790790
setCompilerOptions(options?: CompilerOptions) {
791791
// Avoid manipulating the given options directly
792-
const newOptions = options ? clone(options) : this.getCompilerOptions();
792+
const newOptions = options ? cloneCompilerOptions(options) : this.getCompilerOptions();
793793
if (!newOptions) {
794794
return;
795795
}

src/server/session.ts

Lines changed: 9 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -132,20 +132,6 @@ namespace ts.server {
132132
return `Content-Length: ${1 + len}\r\n\r\n${json}${newLine}`;
133133
}
134134

135-
/**
136-
* Get the compiler options without configFile key
137-
* @param options
138-
*/
139-
function getCompilerOptionsWithoutConfigFile(options: CompilerOptions) {
140-
const result: CompilerOptions = {};
141-
for (const option in options) {
142-
if (option !== "configFile") {
143-
result[option] = options[option];
144-
}
145-
}
146-
return result;
147-
}
148-
149135
/**
150136
* Allows to schedule next step in multistep operation
151137
*/
@@ -1670,39 +1656,19 @@ namespace ts.server {
16701656
},
16711657
[CommandNames.SynchronizeProjectList]: (request: protocol.SynchronizeProjectListRequest) => {
16721658
const result = this.projectService.synchronizeProjectList(request.arguments.knownProjects);
1673-
// Remapping of the result is needed if
1674-
// - there are project errors
1675-
// - options contain configFile - need to remove it from options before serializing
1676-
const shouldRemapProjectFilesWithTSDiagnostics = (p: ProjectFilesWithTSDiagnostics) => (p.projectErrors && !!p.projectErrors.length) || (p.info && !!p.info.options.configFile);
1677-
if (!some(result, shouldRemapProjectFilesWithTSDiagnostics)) {
1659+
if (!result.some(p => p.projectErrors && p.projectErrors.length !== 0)) {
16781660
return this.requiredResponse(result);
16791661
}
16801662
const converted = map(result, p => {
1681-
if (shouldRemapProjectFilesWithTSDiagnostics(p)) {
1682-
// Map the project errors
1683-
const projectErrors = p.projectErrors && p.projectErrors.length ?
1684-
this.convertToDiagnosticsWithLinePosition(p.projectErrors, /*scriptInfo*/ undefined) :
1685-
p.projectErrors;
1686-
1687-
// Remove the configFile in the options before serializing
1688-
const info = p.info && !!p.info.options.configFile ?
1689-
{
1690-
projectName: p.info.projectName,
1691-
isInferred: p.info.isInferred,
1692-
version: p.info.version,
1693-
options: getCompilerOptionsWithoutConfigFile(p.info.options),
1694-
languageServiceDisabled: p.info.languageServiceDisabled
1695-
} : p.info;
1696-
1697-
return {
1698-
info,
1699-
changes: p.changes,
1700-
files: p.files,
1701-
projectErrors
1702-
};
1663+
if (!p.projectErrors || p.projectErrors.length === 0) {
1664+
return p;
17031665
}
1704-
1705-
return p;
1666+
return {
1667+
info: p.info,
1668+
changes: p.changes,
1669+
files: p.files,
1670+
projectErrors: this.convertToDiagnosticsWithLinePosition(p.projectErrors, /*scriptInfo*/ undefined)
1671+
};
17061672
});
17071673
return this.requiredResponse(converted);
17081674
},

0 commit comments

Comments
 (0)