From f0a996e6fb9747a97ba1cbafb08e9fd101b28f92 Mon Sep 17 00:00:00 2001 From: Yui Date: Thu, 7 Apr 2016 11:17:43 -0700 Subject: [PATCH] Fix rwc (#7895) * Fix RWC * Fix RWC * Addres PR --- src/compiler/program.ts | 9 --------- src/compiler/utilities.ts | 9 +++++++++ src/harness/fourslash.ts | 4 ++-- src/harness/harness.ts | 15 +++++++-------- src/harness/projectsRunner.ts | 2 +- src/harness/rwcRunner.ts | 4 ++-- 6 files changed, 21 insertions(+), 22 deletions(-) diff --git a/src/compiler/program.ts b/src/compiler/program.ts index 70c421f9d2b..bbe5505b0a0 100644 --- a/src/compiler/program.ts +++ b/src/compiler/program.ts @@ -44,15 +44,6 @@ namespace ts { return compilerOptions.traceModuleResolution && host.trace !== undefined; } - function startsWith(str: string, prefix: string): boolean { - return str.lastIndexOf(prefix, 0) === 0; - } - - function endsWith(str: string, suffix: string): boolean { - const expectedPos = str.length - suffix.length; - return str.indexOf(suffix, expectedPos) === expectedPos; - } - function hasZeroOrOneAsteriskCharacter(str: string): boolean { let seenAsterisk = false; for (let i = 0; i < str.length; i++) { diff --git a/src/compiler/utilities.ts b/src/compiler/utilities.ts index 8f15891fcf7..780a6d615ef 100644 --- a/src/compiler/utilities.ts +++ b/src/compiler/utilities.ts @@ -2927,4 +2927,13 @@ namespace ts { export function isParameterPropertyDeclaration(node: ParameterDeclaration): boolean { return node.flags & NodeFlags.AccessibilityModifier && node.parent.kind === SyntaxKind.Constructor && isClassLike(node.parent.parent); } + + export function startsWith(str: string, prefix: string): boolean { + return str.lastIndexOf(prefix, 0) === 0; + } + + export function endsWith(str: string, suffix: string): boolean { + const expectedPos = str.length - suffix.length; + return str.indexOf(suffix, expectedPos) === expectedPos; + } } diff --git a/src/harness/fourslash.ts b/src/harness/fourslash.ts index 2abcee8c6d5..44057cad327 100644 --- a/src/harness/fourslash.ts +++ b/src/harness/fourslash.ts @@ -221,7 +221,7 @@ namespace FourSlash { function tryAdd(path: string) { const inputFile = inputFiles[path]; - if (inputFile && !Harness.isLibraryFile(path)) { + if (inputFile && !Harness.isDefaultLibraryFile(path)) { languageServiceAdapterHost.addScript(path, inputFile); return true; } @@ -298,7 +298,7 @@ namespace FourSlash { else { // resolveReference file-option is not specified then do not resolve any files and include all inputFiles ts.forEachKey(this.inputFiles, fileName => { - if (!Harness.isLibraryFile(fileName)) { + if (!Harness.isDefaultLibraryFile(fileName)) { this.languageServiceAdapterHost.addScript(fileName, this.inputFiles[fileName]); } }); diff --git a/src/harness/harness.ts b/src/harness/harness.ts index f21167eeeba..d5191566413 100644 --- a/src/harness/harness.ts +++ b/src/harness/harness.ts @@ -816,8 +816,7 @@ namespace Harness { }; export function getDefaultLibrarySourceFile(fileName = defaultLibFileName): ts.SourceFile { - if (!isLibraryFile(fileName)) { - assert(!isLibraryFile(fileName), "Expected library fileName"); + if (!isDefaultLibraryFile(fileName)) { return undefined; } @@ -1157,7 +1156,7 @@ namespace Harness { // then they will be added twice thus triggering 'total errors' assertion with condition // 'totalErrorsReportedInNonLibraryFiles + numLibraryDiagnostics + numTest262HarnessDiagnostics, diagnostics.length - if (!error.file || !isLibraryFile(error.file.fileName)) { + if (!error.file || !isDefaultLibraryFile(error.file.fileName)) { totalErrorsReportedInNonLibraryFiles++; } } @@ -1236,7 +1235,7 @@ namespace Harness { }); const numLibraryDiagnostics = ts.countWhere(diagnostics, diagnostic => { - return diagnostic.file && (isLibraryFile(diagnostic.file.fileName) || isBuiltFile(diagnostic.file.fileName)); + return diagnostic.file && (isDefaultLibraryFile(diagnostic.file.fileName) || isBuiltFile(diagnostic.file.fileName)); }); const numTest262HarnessDiagnostics = ts.countWhere(diagnostics, diagnostic => { @@ -1623,10 +1622,10 @@ namespace Harness { } } - // Regex for check if the give filePath is a library file - const libRegex = /lib(\.\S+)*\.d\.ts/; - export function isLibraryFile(filePath: string): boolean { - return !!libRegex.exec(Path.getFileName(filePath)); + export function isDefaultLibraryFile(filePath: string): boolean { + // We need to make sure that the filePath is prefixed with "lib." not just containing "lib." and end with ".d.ts" + const fileName = Path.getFileName(filePath); + return ts.startsWith(fileName, "lib.") && ts.endsWith(fileName, ".d.ts"); } export function isBuiltFile(filePath: string): boolean { diff --git a/src/harness/projectsRunner.ts b/src/harness/projectsRunner.ts index 6db745bd7a0..3385d0218c3 100644 --- a/src/harness/projectsRunner.ts +++ b/src/harness/projectsRunner.ts @@ -412,7 +412,7 @@ class ProjectRunner extends RunnerBase { function getErrorsBaseline(compilerResult: CompileProjectFilesResult) { const inputFiles = compilerResult.program ? ts.map(ts.filter(compilerResult.program.getSourceFiles(), - sourceFile => !Harness.isLibraryFile(sourceFile.fileName)), + sourceFile => !Harness.isDefaultLibraryFile(sourceFile.fileName)), sourceFile => { return { unitName: ts.isRootedDiskPath(sourceFile.fileName) ? diff --git a/src/harness/rwcRunner.ts b/src/harness/rwcRunner.ts index 11ed5e7a680..c7127e52834 100644 --- a/src/harness/rwcRunner.ts +++ b/src/harness/rwcRunner.ts @@ -95,13 +95,13 @@ namespace RWC { continue; } - if (!Harness.isLibraryFile(fileRead.path)) { + if (!Harness.isDefaultLibraryFile(fileRead.path)) { if (inInputList) { continue; } otherFiles.push(getHarnessCompilerInputUnit(fileRead.path)); } - else if (!opts.options.noLib && Harness.isLibraryFile(fileRead.path)) { + else if (!opts.options.noLib && Harness.isDefaultLibraryFile(fileRead.path)) { if (!inInputList) { // If useCustomLibraryFile is true, we will use lib.d.ts from json object // otherwise use the lib.d.ts from built/local