Skip to content

Commit e811fec

Browse files
committed
Merge pull request microsoft#5275 from Microsoft/fixCasingAndPathFormat
use absolute path as key to store files, correctly handle scenarios w…
2 parents 6e78b9c + f5d4aa7 commit e811fec

7 files changed

Lines changed: 269 additions & 124 deletions

File tree

src/compiler/commandLineParser.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,12 @@ namespace ts {
247247
},
248248
description: Diagnostics.Specifies_module_resolution_strategy_Colon_node_Node_js_or_classic_TypeScript_pre_1_6,
249249
error: Diagnostics.Argument_for_moduleResolution_option_must_be_node_or_classic,
250-
}
250+
},
251+
{
252+
name: "forceConsistentCasingInFileNames",
253+
type: "boolean",
254+
description: Diagnostics.Disallow_inconsistently_cased_references_to_the_same_file
255+
},
251256
];
252257

253258
/* @internal */

src/compiler/diagnosticMessages.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2290,7 +2290,10 @@
22902290
"category": "Message",
22912291
"code": 6072
22922292
},
2293-
2293+
"Disallow inconsistently-cased references to the same file.": {
2294+
"category": "Message",
2295+
"code": 6073
2296+
},
22942297
"Variable '{0}' implicitly has an '{1}' type.": {
22952298
"category": "Error",
22962299
"code": 7005

src/compiler/program.ts

Lines changed: 66 additions & 56 deletions
Large diffs are not rendered by default.

src/compiler/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2092,6 +2092,7 @@ namespace ts {
20922092
experimentalDecorators?: boolean;
20932093
emitDecoratorMetadata?: boolean;
20942094
moduleResolution?: ModuleResolutionKind;
2095+
forceConsistentCasingInFileNames?: boolean;
20952096
/* @internal */ stripInternal?: boolean;
20962097

20972098
// Skip checking lib.d.ts to help speed up tests.

src/harness/harness.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -923,7 +923,9 @@ namespace Harness {
923923
function register(file: { unitName: string; content: string; }) {
924924
if (file.content !== undefined) {
925925
let fileName = ts.normalizePath(file.unitName);
926-
filemap[getCanonicalFileName(fileName)] = createSourceFileAndAssertInvariants(fileName, file.content, scriptTarget);
926+
const sourceFile = createSourceFileAndAssertInvariants(fileName, file.content, scriptTarget);
927+
filemap[getCanonicalFileName(fileName)] = sourceFile;
928+
filemap[getCanonicalFileName(ts.getNormalizedAbsolutePath(fileName, getCurrentDirectory()))] = sourceFile;
927929
}
928930
};
929931
inputFiles.forEach(register);

src/harness/projectsRunner.ts

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ class ProjectRunner extends RunnerBase {
127127
}
128128

129129
function compileProjectFiles(moduleKind: ts.ModuleKind, getInputFiles: () => string[],
130-
getSourceFileText: (fileName: string) => string,
130+
getSourceFileTextImpl: (fileName: string) => string,
131131
writeFile: (fileName: string, data: string, writeByteOrderMark: boolean) => void): CompileProjectFilesResult {
132132

133133
let program = ts.createProgram(getInputFiles(), createCompilerOptions(), createCompilerHost());
@@ -170,6 +170,11 @@ class ProjectRunner extends RunnerBase {
170170
};
171171
}
172172

173+
function getSourceFileText(fileName: string): string {
174+
const text = getSourceFileTextImpl(fileName);
175+
return text !== undefined ? text : getSourceFileTextImpl(ts.getNormalizedAbsolutePath(fileName, getCurrentDirectory()));
176+
}
177+
173178
function getSourceFile(fileName: string, languageVersion: ts.ScriptTarget): ts.SourceFile {
174179
let sourceFile: ts.SourceFile = undefined;
175180
if (fileName === Harness.Compiler.defaultLibFileName) {
@@ -194,7 +199,7 @@ class ProjectRunner extends RunnerBase {
194199
getCanonicalFileName: Harness.Compiler.getCanonicalFileName,
195200
useCaseSensitiveFileNames: () => Harness.IO.useCaseSensitiveFileNames(),
196201
getNewLine: () => Harness.IO.newLine(),
197-
fileExists: fileName => getSourceFile(fileName, ts.ScriptTarget.ES5) !== undefined,
202+
fileExists: fileName => fileName === Harness.Compiler.defaultLibFileName || getSourceFileText(fileName) !== undefined,
198203
readFile: fileName => Harness.IO.readFile(fileName)
199204
};
200205
}
@@ -318,7 +323,16 @@ class ProjectRunner extends RunnerBase {
318323
return ts.map(allInputFiles, outputFile => outputFile.emittedFileName);
319324
}
320325
function getSourceFileText(fileName: string): string {
321-
return ts.forEach(allInputFiles, inputFile => inputFile.emittedFileName === fileName ? inputFile.code : undefined);
326+
for (const inputFile of allInputFiles) {
327+
const isMatchingFile = ts.isRootedDiskPath(fileName)
328+
? ts.getNormalizedAbsolutePath(inputFile.emittedFileName, getCurrentDirectory()) === fileName
329+
: inputFile.emittedFileName === fileName;
330+
331+
if (isMatchingFile) {
332+
return inputFile.code;
333+
}
334+
}
335+
return undefined;
322336
}
323337

324338
function writeFile(fileName: string, data: string, writeByteOrderMark: boolean) {

0 commit comments

Comments
 (0)