Skip to content

Commit c1bcb99

Browse files
committed
Merge pull request #4154 from Microsoft/reuseAndCache
Revised module resolution
2 parents 2ffc375 + b6b735c commit c1bcb99

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+1823
-251
lines changed

Jakefile.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,9 @@ var harnessSources = harnessCoreSources.concat([
141141
"session.ts",
142142
"versionCache.ts",
143143
"convertToBase64.ts",
144-
"transpile.ts"
144+
"transpile.ts",
145+
"reuseProgramStructure.ts",
146+
"cachingInServerLSHost.ts"
145147
].map(function (f) {
146148
return path.join(unittestsDirectory, f);
147149
})).concat([

src/compiler/checker.ts

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -965,28 +965,19 @@ namespace ts {
965965
// Escape the name in the "require(...)" clause to ensure we find the right symbol.
966966
let moduleName = escapeIdentifier(moduleReferenceLiteral.text);
967967

968-
if (!moduleName) return;
968+
if (!moduleName) {
969+
return;
970+
}
969971
let isRelative = isExternalModuleNameRelative(moduleName);
970972
if (!isRelative) {
971973
let symbol = getSymbol(globals, "\"" + moduleName + "\"", SymbolFlags.ValueModule);
972974
if (symbol) {
973975
return symbol;
974976
}
975977
}
976-
let fileName: string;
977-
let sourceFile: SourceFile;
978-
while (true) {
979-
fileName = normalizePath(combinePaths(searchPath, moduleName));
980-
sourceFile = forEach(supportedExtensions, extension => host.getSourceFile(fileName + extension));
981-
if (sourceFile || isRelative) {
982-
break;
983-
}
984-
let parentPath = getDirectoryPath(searchPath);
985-
if (parentPath === searchPath) {
986-
break;
987-
}
988-
searchPath = parentPath;
989-
}
978+
979+
let fileName = getResolvedModuleFileName(getSourceFile(location), moduleReferenceLiteral.text);
980+
let sourceFile = fileName && host.getSourceFile(fileName);
990981
if (sourceFile) {
991982
if (sourceFile.symbol) {
992983
return sourceFile.symbol;

src/compiler/core.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ namespace ts {
2424
set,
2525
contains,
2626
remove,
27+
clear,
2728
forEachValue: forEachValueInMap
2829
};
2930

@@ -51,6 +52,10 @@ namespace ts {
5152
function normalizeKey(key: string) {
5253
return getCanonicalFileName(normalizeSlashes(key));
5354
}
55+
56+
function clear() {
57+
files = {};
58+
}
5459
}
5560

5661
export const enum Comparison {
@@ -716,7 +721,7 @@ namespace ts {
716721
/**
717722
* List of supported extensions in order of file resolution precedence.
718723
*/
719-
export const supportedExtensions = [".tsx", ".ts", ".d.ts"];
724+
export const supportedExtensions = [".ts", ".tsx", ".d.ts"];
720725

721726
const extensionsToRemove = [".d.ts", ".ts", ".js", ".tsx", ".jsx"];
722727
export function removeFileExtension(path: string): string {

0 commit comments

Comments
 (0)