Skip to content

Commit f0a996e

Browse files
committed
Fix rwc (#7895)
* Fix RWC * Fix RWC * Addres PR
1 parent 3704ad7 commit f0a996e

File tree

6 files changed

+21
-22
lines changed

6 files changed

+21
-22
lines changed

src/compiler/program.ts

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -44,15 +44,6 @@ namespace ts {
4444
return compilerOptions.traceModuleResolution && host.trace !== undefined;
4545
}
4646

47-
function startsWith(str: string, prefix: string): boolean {
48-
return str.lastIndexOf(prefix, 0) === 0;
49-
}
50-
51-
function endsWith(str: string, suffix: string): boolean {
52-
const expectedPos = str.length - suffix.length;
53-
return str.indexOf(suffix, expectedPos) === expectedPos;
54-
}
55-
5647
function hasZeroOrOneAsteriskCharacter(str: string): boolean {
5748
let seenAsterisk = false;
5849
for (let i = 0; i < str.length; i++) {

src/compiler/utilities.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2927,4 +2927,13 @@ namespace ts {
29272927
export function isParameterPropertyDeclaration(node: ParameterDeclaration): boolean {
29282928
return node.flags & NodeFlags.AccessibilityModifier && node.parent.kind === SyntaxKind.Constructor && isClassLike(node.parent.parent);
29292929
}
2930+
2931+
export function startsWith(str: string, prefix: string): boolean {
2932+
return str.lastIndexOf(prefix, 0) === 0;
2933+
}
2934+
2935+
export function endsWith(str: string, suffix: string): boolean {
2936+
const expectedPos = str.length - suffix.length;
2937+
return str.indexOf(suffix, expectedPos) === expectedPos;
2938+
}
29302939
}

src/harness/fourslash.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ namespace FourSlash {
221221

222222
function tryAdd(path: string) {
223223
const inputFile = inputFiles[path];
224-
if (inputFile && !Harness.isLibraryFile(path)) {
224+
if (inputFile && !Harness.isDefaultLibraryFile(path)) {
225225
languageServiceAdapterHost.addScript(path, inputFile);
226226
return true;
227227
}
@@ -298,7 +298,7 @@ namespace FourSlash {
298298
else {
299299
// resolveReference file-option is not specified then do not resolve any files and include all inputFiles
300300
ts.forEachKey(this.inputFiles, fileName => {
301-
if (!Harness.isLibraryFile(fileName)) {
301+
if (!Harness.isDefaultLibraryFile(fileName)) {
302302
this.languageServiceAdapterHost.addScript(fileName, this.inputFiles[fileName]);
303303
}
304304
});

src/harness/harness.ts

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -816,8 +816,7 @@ namespace Harness {
816816
};
817817

818818
export function getDefaultLibrarySourceFile(fileName = defaultLibFileName): ts.SourceFile {
819-
if (!isLibraryFile(fileName)) {
820-
assert(!isLibraryFile(fileName), "Expected library fileName");
819+
if (!isDefaultLibraryFile(fileName)) {
821820
return undefined;
822821
}
823822

@@ -1157,7 +1156,7 @@ namespace Harness {
11571156
// then they will be added twice thus triggering 'total errors' assertion with condition
11581157
// 'totalErrorsReportedInNonLibraryFiles + numLibraryDiagnostics + numTest262HarnessDiagnostics, diagnostics.length
11591158

1160-
if (!error.file || !isLibraryFile(error.file.fileName)) {
1159+
if (!error.file || !isDefaultLibraryFile(error.file.fileName)) {
11611160
totalErrorsReportedInNonLibraryFiles++;
11621161
}
11631162
}
@@ -1236,7 +1235,7 @@ namespace Harness {
12361235
});
12371236

12381237
const numLibraryDiagnostics = ts.countWhere(diagnostics, diagnostic => {
1239-
return diagnostic.file && (isLibraryFile(diagnostic.file.fileName) || isBuiltFile(diagnostic.file.fileName));
1238+
return diagnostic.file && (isDefaultLibraryFile(diagnostic.file.fileName) || isBuiltFile(diagnostic.file.fileName));
12401239
});
12411240

12421241
const numTest262HarnessDiagnostics = ts.countWhere(diagnostics, diagnostic => {
@@ -1623,10 +1622,10 @@ namespace Harness {
16231622
}
16241623
}
16251624

1626-
// Regex for check if the give filePath is a library file
1627-
const libRegex = /lib(\.\S+)*\.d\.ts/;
1628-
export function isLibraryFile(filePath: string): boolean {
1629-
return !!libRegex.exec(Path.getFileName(filePath));
1625+
export function isDefaultLibraryFile(filePath: string): boolean {
1626+
// We need to make sure that the filePath is prefixed with "lib." not just containing "lib." and end with ".d.ts"
1627+
const fileName = Path.getFileName(filePath);
1628+
return ts.startsWith(fileName, "lib.") && ts.endsWith(fileName, ".d.ts");
16301629
}
16311630

16321631
export function isBuiltFile(filePath: string): boolean {

src/harness/projectsRunner.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -412,7 +412,7 @@ class ProjectRunner extends RunnerBase {
412412

413413
function getErrorsBaseline(compilerResult: CompileProjectFilesResult) {
414414
const inputFiles = compilerResult.program ? ts.map(ts.filter(compilerResult.program.getSourceFiles(),
415-
sourceFile => !Harness.isLibraryFile(sourceFile.fileName)),
415+
sourceFile => !Harness.isDefaultLibraryFile(sourceFile.fileName)),
416416
sourceFile => {
417417
return {
418418
unitName: ts.isRootedDiskPath(sourceFile.fileName) ?

src/harness/rwcRunner.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,13 +95,13 @@ namespace RWC {
9595
continue;
9696
}
9797

98-
if (!Harness.isLibraryFile(fileRead.path)) {
98+
if (!Harness.isDefaultLibraryFile(fileRead.path)) {
9999
if (inInputList) {
100100
continue;
101101
}
102102
otherFiles.push(getHarnessCompilerInputUnit(fileRead.path));
103103
}
104-
else if (!opts.options.noLib && Harness.isLibraryFile(fileRead.path)) {
104+
else if (!opts.options.noLib && Harness.isDefaultLibraryFile(fileRead.path)) {
105105
if (!inInputList) {
106106
// If useCustomLibraryFile is true, we will use lib.d.ts from json object
107107
// otherwise use the lib.d.ts from built/local

0 commit comments

Comments
 (0)