Skip to content

Commit 27f9cdb

Browse files
authored
Explicitly avoid canonicalizing paths during configuration handling (#18316)
* Explicitly avoid canonicalizing paths during configuration handling * Extract usage of identity in commandLineParser into single function, use identity in checker
1 parent 2e02778 commit 27f9cdb

File tree

3 files changed

+13
-7
lines changed

3 files changed

+13
-7
lines changed

src/compiler/checker.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ namespace ts {
5858
let symbolInstantiationDepth = 0;
5959

6060
const emptySymbols = createSymbolTable();
61+
const identityMapper: (type: Type) => Type = identity;
6162

6263
const compilerOptions = host.getCompilerOptions();
6364
const languageVersion = getEmitScriptTarget(compilerOptions);
@@ -8119,10 +8120,6 @@ namespace ts {
81198120
mapper;
81208121
}
81218122

8122-
function identityMapper(type: Type): Type {
8123-
return type;
8124-
}
8125-
81268123
function combineTypeMappers(mapper1: TypeMapper, mapper2: TypeMapper): TypeMapper {
81278124
return t => instantiateType(mapper1(t), mapper2);
81288125
}

src/compiler/commandLineParser.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1385,6 +1385,12 @@ namespace ts {
13851385
return x === undefined || x === null;
13861386
}
13871387

1388+
function directoryOfCombinedPath(fileName: string, basePath: string) {
1389+
// Use the `identity` function to avoid canonicalizing the path, as it must remain noncanonical
1390+
// until consistient casing errors are reported
1391+
return getDirectoryPath(toPath(fileName, basePath, identity));
1392+
}
1393+
13881394
/**
13891395
* Parse the contents of a config file from json or json source file (tsconfig.json).
13901396
* @param json The contents of the config file to parse
@@ -1467,7 +1473,7 @@ namespace ts {
14671473
includeSpecs = ["**/*"];
14681474
}
14691475

1470-
const result = matchFileNames(fileNames, includeSpecs, excludeSpecs, configFileName ? getDirectoryPath(toPath(configFileName, basePath, createGetCanonicalFileName(host.useCaseSensitiveFileNames))) : basePath, options, host, errors, extraFileExtensions, sourceFile);
1476+
const result = matchFileNames(fileNames, includeSpecs, excludeSpecs, configFileName ? directoryOfCombinedPath(configFileName, basePath) : basePath, options, host, errors, extraFileExtensions, sourceFile);
14711477

14721478
if (result.fileNames.length === 0 && !hasProperty(raw, "files") && resolutionStack.length === 0) {
14731479
errors.push(
@@ -1577,7 +1583,7 @@ namespace ts {
15771583
errors.push(createCompilerDiagnostic(Diagnostics.Compiler_option_0_requires_a_value_of_type_1, "extends", "string"));
15781584
}
15791585
else {
1580-
const newBase = configFileName ? getDirectoryPath(toPath(configFileName, basePath, getCanonicalFileName)) : basePath;
1586+
const newBase = configFileName ? directoryOfCombinedPath(configFileName, basePath) : basePath;
15811587
extendedConfigPath = getExtendsConfigPath(json.extends, host, newBase, getCanonicalFileName, errors, createCompilerDiagnostic);
15821588
}
15831589
}
@@ -1610,7 +1616,7 @@ namespace ts {
16101616
onSetValidOptionKeyValueInRoot(key: string, _keyNode: PropertyName, value: CompilerOptionsValue, valueNode: Expression) {
16111617
switch (key) {
16121618
case "extends":
1613-
const newBase = configFileName ? getDirectoryPath(toPath(configFileName, basePath, getCanonicalFileName)) : basePath;
1619+
const newBase = configFileName ? directoryOfCombinedPath(configFileName, basePath) : basePath;
16141620
extendedConfigPath = getExtendsConfigPath(
16151621
<string>value,
16161622
host,

src/compiler/core.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1228,6 +1228,9 @@ namespace ts {
12281228
/** Does nothing. */
12291229
export function noop(): void {}
12301230

1231+
/** Returns its argument. */
1232+
export function identity<T>(x: T) { return x; }
1233+
12311234
/** Throws an error because a function is not implemented. */
12321235
export function notImplemented(): never {
12331236
throw new Error("Not implemented");

0 commit comments

Comments
 (0)