diff --git a/src/compiler/core.ts b/src/compiler/core.ts index 932acdc632..ba81ee7d10 100644 --- a/src/compiler/core.ts +++ b/src/compiler/core.ts @@ -861,13 +861,6 @@ namespace ts { return fileExtensionIs(path, extension) ? path.substring(0, path.length - extension.length) : undefined; } - export function getFileExtension(path: string): string { - const dot = path.lastIndexOf("."); - if (dot !== -1) { - return path.substring(dot); - } - } - export interface ObjectAllocator { getNodeConstructor(): new (kind: SyntaxKind, pos?: number, end?: number) => Node; getSourceFileConstructor(): new (kind: SyntaxKind, pos?: number, end?: number) => SourceFile; diff --git a/src/compiler/program.ts b/src/compiler/program.ts index c7b2cd66ca..dd3102410e 100644 --- a/src/compiler/program.ts +++ b/src/compiler/program.ts @@ -620,9 +620,9 @@ namespace ts { */ function loadModuleFromFile(candidate: string, extensions: string[], failedLookupLocation: string[], onlyRecordFailures: boolean, state: ModuleResolutionState): string { // First try to keep/add an extension: importing "./foo.ts" can be matched by a file "./foo.ts", and "./foo" by "./foo.d.ts" - const keepOrAddExtension = loadModuleFromFileWorker(candidate, extensions, failedLookupLocation, onlyRecordFailures, state); - if (keepOrAddExtension) { - return keepOrAddExtension; + const resolvedByAddingOrKeepingExtension = loadModuleFromFileWorker(candidate, extensions, failedLookupLocation, onlyRecordFailures, state); + if (resolvedByAddingOrKeepingExtension) { + return resolvedByAddingOrKeepingExtension; } // Then try stripping a ".js" or ".jsx" extension and replacing it with a TypeScript one, e.g. "./foo.js" can be matched by "./foo.ts" or "./foo.d.ts" if (hasJavaScriptFileExtension(candidate)) { @@ -634,9 +634,10 @@ namespace ts { return loadModuleFromFileWorker(extensionless, extensions, failedLookupLocation, onlyRecordFailures, state); } } + function loadModuleFromFileWorker(candidate: string, extensions: string[], failedLookupLocation: string[], onlyRecordFailures: boolean, state: ModuleResolutionState): string { if (!onlyRecordFailures) { - // check if containig folder exists - if it doesn't then just record failures for all supported extensions without disk probing + // check if containing folder exists - if it doesn't then just record failures for all supported extensions without disk probing const directory = getDirectoryPath(candidate); if (directory) { onlyRecordFailures = !directoryProbablyExists(directory, state.host);