Merge branch 'master' into parse-jsdoc-with-ts-type-parser

This commit is contained in:
Nathan Shively-Sanders
2017-07-14 15:04:06 -07:00
15 changed files with 95 additions and 87 deletions

View File

@@ -1580,10 +1580,21 @@ namespace ts {
return path && !isRootedDiskPath(path) && path.indexOf("://") !== -1;
}
/* @internal */
export function pathIsRelative(path: string): boolean {
return /^\.\.?($|[\\/])/.test(path);
}
export function isExternalModuleNameRelative(moduleName: string): boolean {
// TypeScript 1.0 spec (April 2014): 11.2.1
// An external module name is "relative" if the first term is "." or "..".
return /^\.\.?($|[\\/])/.test(moduleName);
// Update: We also consider a path like `C:\foo.ts` "relative" because we do not search for it in `node_modules` or treat it as an ambient module.
return pathIsRelative(moduleName) || isRootedDiskPath(moduleName);
}
/** @deprecated Use `!isExternalModuleNameRelative(moduleName)` instead. */
export function moduleHasNonRelativeName(moduleName: string): boolean {
return !isExternalModuleNameRelative(moduleName);
}
export function getEmitScriptTarget(compilerOptions: CompilerOptions) {

View File

@@ -54,10 +54,6 @@ namespace ts {
};
}
export function moduleHasNonRelativeName(moduleName: string): boolean {
return !(isRootedDiskPath(moduleName) || isExternalModuleNameRelative(moduleName));
}
interface ModuleResolutionState {
host: ModuleResolutionHost;
compilerOptions: CompilerOptions;
@@ -318,7 +314,7 @@ namespace ts {
}
function getOrCreateCacheForModuleName(nonRelativeModuleName: string) {
if (!moduleHasNonRelativeName(nonRelativeModuleName)) {
if (isExternalModuleNameRelative(nonRelativeModuleName)) {
return undefined;
}
let perModuleNameCache = moduleNameToDirectoryMap.get(nonRelativeModuleName);
@@ -535,7 +531,7 @@ namespace ts {
function tryLoadModuleUsingOptionalResolutionSettings(extensions: Extensions, moduleName: string, containingDirectory: string, loader: ResolutionKindSpecificLoader,
failedLookupLocations: Push<string>, state: ModuleResolutionState): Resolved | undefined {
if (moduleHasNonRelativeName(moduleName)) {
if (!isExternalModuleNameRelative(moduleName)) {
return tryLoadModuleUsingBaseUrl(extensions, moduleName, loader, failedLookupLocations, state);
}
else {
@@ -711,7 +707,7 @@ namespace ts {
return toSearchResult({ resolved, isExternalLibraryImport: false });
}
if (moduleHasNonRelativeName(moduleName)) {
if (!isExternalModuleNameRelative(moduleName)) {
if (traceEnabled) {
trace(host, Diagnostics.Loading_module_0_from_node_modules_folder_target_file_type_1, moduleName, Extensions[extensions]);
}
@@ -1024,7 +1020,7 @@ namespace ts {
}
const perModuleNameCache = cache && cache.getOrCreateCacheForModuleName(moduleName);
if (moduleHasNonRelativeName(moduleName)) {
if (!isExternalModuleNameRelative(moduleName)) {
// Climb up parent directories looking for a module.
const resolved = forEachAncestorDirectory(containingDirectory, directory => {
const resolutionFromCache = tryFindNonRelativeModuleNameInCache(perModuleNameCache, moduleName, directory, traceEnabled, host);

View File

@@ -332,6 +332,7 @@ namespace ts {
const categoryColor = getCategoryFormat(diagnostic.category);
const category = DiagnosticCategory[diagnostic.category].toLowerCase();
output += `${ formatAndReset(category, categoryColor) } TS${ diagnostic.code }: ${ flattenDiagnosticMessageText(diagnostic.messageText, sys.newLine) }`;
output += sys.newLine;
}
return output;
}

View File

@@ -61,7 +61,7 @@ namespace ts {
}
function reportDiagnosticWithColorAndContext(diagnostic: Diagnostic, host: FormatDiagnosticsHost): void {
sys.write(ts.formatDiagnosticsWithColorAndContext([diagnostic], host) + sys.newLine + sys.newLine);
sys.write(ts.formatDiagnosticsWithColorAndContext([diagnostic], host) + sys.newLine);
}
function reportWatchDiagnostic(diagnostic: Diagnostic) {