From a0546a9310aa18a097fa8edb5276dc0c16fedfc2 Mon Sep 17 00:00:00 2001 From: Andy Hanson Date: Tue, 31 May 2016 10:39:29 -0700 Subject: [PATCH] Improve loadModuleFromFile code --- src/compiler/program.ts | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/src/compiler/program.ts b/src/compiler/program.ts index f9a583da0cc8b..720b99d89008c 100644 --- a/src/compiler/program.ts +++ b/src/compiler/program.ts @@ -628,24 +628,25 @@ namespace ts { } } - if (state.skipTsx) - extensions = filter(extensions, ext => ext !== "tsx"); - // 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 = forEach(extensions, ext => - tryLoad(fileExtensionIs(candidate, ext) ? candidate : candidate + ext)); + const keepOrAddExtension = forEach(extensions, ext => { + if (state.skipTsx && (ext === ".jsx" || ext === ".tsx")) { + return; + } + return tryLoad(fileExtensionIs(candidate, ext) ? candidate : candidate + ext); + }); if (keepOrAddExtension) { return keepOrAddExtension; } - // Then try stripping a ".js" or ".jsx" extension and replacing it with a different one, e.g. "./foo.js" can be matched by "./foo.ts" or "./foo.d.ts" + // 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" return forEach(supportedJavascriptExtensions, jsExt => { + if (state.skipTsx && jsExt === ".jsx") { + return; + } const extensionless = tryRemoveExtension(candidate, jsExt); if (extensionless !== undefined) { - return forEach(supportedTypeScriptExtensions, ext => { - if (ext !== jsExt) - return tryLoad(extensionless + ext); - }); + return forEach(supportedTypeScriptExtensions, tsExt => tryLoad(extensionless + tsExt)); } });