From 88262dbeb0dfb60af0e27735c10c5a8d9e7b3e27 Mon Sep 17 00:00:00 2001 From: Armando Aguirre Date: Mon, 14 Aug 2017 18:19:43 -0700 Subject: [PATCH] Changed check for default library by first checking hasNoDefaultLib, second library path and third name of file. --- src/compiler/program.ts | 27 ++++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/src/compiler/program.ts b/src/compiler/program.ts index 55edb377373..25a526ddaf4 100644 --- a/src/compiler/program.ts +++ b/src/compiler/program.ts @@ -436,6 +436,7 @@ namespace ts { host = host || createCompilerHost(options); let skipDefaultLib = options.noLib; + const defaultLibraryPath = host.getDefaultLibLocation ? host.getDefaultLibLocation() : getDirectoryPath(host.getDefaultLibFileName(options)); const programDiagnostics = createDiagnosticCollection(); const currentDirectory = host.getCurrentDirectory(); const supportedExtensions = getSupportedExtensions(options); @@ -977,7 +978,15 @@ namespace ts { } function isSourceFileDefaultLibrary(file: SourceFile): boolean { - return file.fileName === host.getDefaultLibFileName(options); + if (file.hasNoDefaultLib) { + return true; + } + + if (defaultLibraryPath !== undefined && defaultLibraryPath.length !== 0) { + return comparePaths(defaultLibraryPath, file.path, currentDirectory, /*ignoreCase*/ true) === Comparison.EqualTo; + } + + return compareStrings(file.fileName, host.getDefaultLibFileName(options), /*ignoreCase*/ true) === Comparison.EqualTo; } function getDiagnosticsProducingTypeChecker() { @@ -1209,7 +1218,7 @@ namespace ts { diagnostics.push(createDiagnosticForNode(node, Diagnostics._0_can_only_be_used_in_a_ts_file, "?")); return; } - // falls through + // falls through case SyntaxKind.MethodDeclaration: case SyntaxKind.MethodSignature: case SyntaxKind.Constructor: @@ -1291,7 +1300,7 @@ namespace ts { diagnostics.push(createDiagnosticForNodeArray(nodes, Diagnostics.type_parameter_declarations_can_only_be_used_in_a_ts_file)); return; } - // falls through + // falls through case SyntaxKind.VariableStatement: // Check modifiers if (nodes === (parent).modifiers) { @@ -1339,8 +1348,8 @@ namespace ts { if (isConstValid) { continue; } - // to report error, - // falls through + // to report error, + // falls through case SyntaxKind.PublicKeyword: case SyntaxKind.PrivateKeyword: case SyntaxKind.ProtectedKeyword: @@ -1556,10 +1565,10 @@ namespace ts { } function getSourceFileFromReferenceWorker( - fileName: string, - getSourceFile: (fileName: string) => SourceFile | undefined, - fail?: (diagnostic: DiagnosticMessage, ...argument: string[]) => void, - refFile?: SourceFile): SourceFile | undefined { + fileName: string, + getSourceFile: (fileName: string) => SourceFile | undefined, + fail?: (diagnostic: DiagnosticMessage, ...argument: string[]) => void, + refFile?: SourceFile): SourceFile | undefined { if (hasExtension(fileName)) { if (!options.allowNonTsExtensions && !forEach(supportedExtensions, extension => fileExtensionIs(host.getCanonicalFileName(fileName), extension))) {