do not try to resolve modules that has '!' in the name, put .tsx extension to the end of the list

This commit is contained in:
Vladimir Matveev 2015-07-29 16:24:16 -07:00
parent 9332f7e1e3
commit d7661ecf8a
2 changed files with 14 additions and 4 deletions

View file

@ -709,7 +709,7 @@ namespace ts {
/**
* List of supported extensions in order of file resolution precedence.
*/
export const supportedExtensions = [".tsx", ".ts", ".d.ts"];
export const supportedExtensions = [".ts", ".d.ts", ".tsx"];
const extensionsToRemove = [".d.ts", ".ts", ".js", ".tsx", ".jsx"];
export function removeFileExtension(path: string): string {
@ -805,4 +805,4 @@ namespace ts {
Debug.assert(false, message);
}
}
}
}

View file

@ -40,7 +40,12 @@ namespace ts {
}
function resolveModuleName(moduleName: string, containingFile: string, compilerOptions: CompilerOptions, host: ModuleResolutionHost): ResolvedModule {
// module names that contain '!' are used to reference resources and are not resolved to actual files on disk
if (moduleName.indexOf('!') != -1) {
return { resolvedFileName: undefined, failedLookupLocations: [] };
}
let searchPath = getDirectoryPath(containingFile);
let searchName: string;
@ -50,8 +55,13 @@ namespace ts {
while (true) {
searchName = normalizePath(combinePaths(searchPath, moduleName));
referencedSourceFile = forEach(supportedExtensions, extension => {
if (extension === ".tsx" && !compilerOptions.jsx) {
// resolve .tsx files only if jsx support is enabled
// 'logical not' handles both undefined and None cases
return undefined;
}
let candidate = searchName + extension;
let ok = host.fileExists(candidate) ? candidate : undefined;
if (host.fileExists(candidate)) {
return candidate;
}