Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit e6fa4e4

Browse filesBrowse files
authored
Merge pull request microsoft#23043 from alan-agius4/feature/compiler-host-falsy-file
fix: `CompilerHost.getSourceFile` is being called for odd filenames
2 parents 955542d + 7e482b2 commit e6fa4e4
Copy full SHA for e6fa4e4

4 files changed

+43-3Lines changed: 43 additions & 3 deletions

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎Jakefile.js‎

Copy file name to clipboardExpand all lines: Jakefile.js
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,7 @@ var harnessSources = harnessCoreSources.concat([
154154
"transform.ts",
155155
"customTransforms.ts",
156156
"programMissingFiles.ts",
157+
"programNoParseFalsyFileNames.ts",
157158
"symbolWalker.ts",
158159
"languageService.ts",
159160
"publicApi.ts",
Collapse file

‎src/compiler/program.ts‎

Copy file name to clipboardExpand all lines: src/compiler/program.ts
+4-3Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -611,8 +611,9 @@ namespace ts {
611611
if (!skipDefaultLib) {
612612
// If '--lib' is not specified, include default library file according to '--target'
613613
// otherwise, using options specified in '--lib' instead of '--target' default library file
614-
if (!options.lib) {
615-
processRootFile(getDefaultLibraryFileName(), /*isDefaultLib*/ true);
614+
const defaultLibraryFileName = getDefaultLibraryFileName();
615+
if (!options.lib && defaultLibraryFileName) {
616+
processRootFile(defaultLibraryFileName, /*isDefaultLib*/ true);
616617
}
617618
else {
618619
forEach(options.lib, libFileName => {
@@ -1117,7 +1118,7 @@ namespace ts {
11171118
// otherwise, using options specified in '--lib' instead of '--target' default library file
11181119
const equalityComparer = host.useCaseSensitiveFileNames() ? equateStringsCaseSensitive : equateStringsCaseInsensitive;
11191120
if (!options.lib) {
1120-
return equalityComparer(file.fileName, getDefaultLibraryFileName());
1121+
return equalityComparer(file.fileName, getDefaultLibraryFileName());
11211122
}
11221123
else {
11231124
return forEach(options.lib, libFileName => equalityComparer(file.fileName, combinePaths(defaultLibraryPath, libFileName)));
Collapse file

‎src/harness/tsconfig.json‎

Copy file name to clipboardExpand all lines: src/harness/tsconfig.json
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,7 @@
135135
"./unittests/telemetry.ts",
136136
"./unittests/languageService.ts",
137137
"./unittests/programMissingFiles.ts",
138+
"./unittests/programNoParseFalsyFileNames.ts",
138139
"./unittests/publicApi.ts",
139140
"./unittests/hostNewLineSupport.ts"
140141
]
Collapse file
+37Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/// <reference path="..\harness.ts" />
2+
namespace ts {
3+
describe("programNoParseFalsyFileNames", () => {
4+
let program: Program;
5+
6+
beforeEach(() => {
7+
const testSource = `
8+
class Foo extends HTMLElement {
9+
bar: string = 'baz';
10+
}`;
11+
12+
const host: CompilerHost = {
13+
getSourceFile: (fileName: string, languageVersion: ScriptTarget, _onError?: (message: string) => void) => {
14+
return fileName === "test.ts" ? createSourceFile(fileName, testSource, languageVersion) : undefined;
15+
},
16+
getDefaultLibFileName: () => "",
17+
writeFile: (_fileName, _content) => { throw new Error("unsupported"); },
18+
getCurrentDirectory: () => sys.getCurrentDirectory(),
19+
getCanonicalFileName: fileName => sys.useCaseSensitiveFileNames ? fileName : fileName.toLowerCase(),
20+
getNewLine: () => sys.newLine,
21+
useCaseSensitiveFileNames: () => sys.useCaseSensitiveFileNames,
22+
fileExists: fileName => fileName === "test.ts",
23+
readFile: fileName => fileName === "test.ts" ? testSource : undefined,
24+
resolveModuleNames: (_moduleNames: string[], _containingFile: string) => { throw new Error("unsupported"); },
25+
getDirectories: _path => { throw new Error("unsupported"); },
26+
};
27+
28+
program = createProgram(["test.ts"], { module: ModuleKind.ES2015 }, host);
29+
});
30+
31+
it("should not have missing file paths", () => {
32+
assert(program.getSourceFiles().length === 1, "expected 'getSourceFiles' length to be 1");
33+
assert(program.getMissingFilePaths().length === 0, "expected 'getMissingFilePaths' length to be 0");
34+
assert(program.getFileProcessingDiagnostics().getDiagnostics().length === 0, "expected 'getFileProcessingDiagnostics' length to be 0");
35+
});
36+
});
37+
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.