Skip to content
This repository has been archived by the owner on Dec 1, 2019. It is now read-only.

Commit

Permalink
feat(*): update module resolution logic according to microsoft/TypeSc…
Browse files Browse the repository at this point in the history
  • Loading branch information
s-panferov authored and Stanislav Panferov committed Sep 17, 2015
1 parent 69fd40d commit 59ff7f7
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 21 deletions.
11 changes: 5 additions & 6 deletions src/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export interface IInitPayload {

export interface ICompilePayload {
files: {[fileName: string]: IFile};
resolutionCache: {[fileName: string]: string};
resolutionCache: {[fileName: string]: ts.ResolvedModule};
}

export interface IEnv {
Expand All @@ -28,7 +28,7 @@ export interface IEnv {
compilerInfo?: ICompilerInfo;
host?: Host;
files?: {[fileName: string]: IFile};
resolutionCache?: {[fileName: string]: string};
resolutionCache?: {[fileName: string]: ts.ResolvedModule};
program?: ts.Program;
service?: ts.LanguageService;
}
Expand Down Expand Up @@ -67,15 +67,15 @@ export class Host implements ts.LanguageServiceHost {
}

resolveModuleNames(moduleNames: string[], containingFile: string) {
let resolvedFileNames: string[] = [];
let resolvedModules: ts.ResolvedModule[] = [];

for (let moduleName of moduleNames) {
resolvedFileNames.push(
resolvedModules.push(
env.resolutionCache[`${containingFile}::${moduleName}`]
);
}

return resolvedFileNames;
return resolvedModules;
}

getDefaultLibFileName(options) {
Expand All @@ -87,7 +87,6 @@ export class Host implements ts.LanguageServiceHost {
log(message) {
//console.log(message);
}

}

function processInit(payload: IInitPayload) {
Expand Down
33 changes: 18 additions & 15 deletions src/host.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ export interface IEmitOutput extends ts.EmitOutput {

export class ModuleResolutionHost implements ts.ModuleResolutionHost {
servicesHost: Host;
resolutionCache: {[fileName: string]: string} = {};
resolutionCache: {[fileName: string]: ts.ResolvedModuleWithFailedLookupLocations} = {};

constructor(servicesHost: Host) {
this.servicesHost = servicesHost;
Expand Down Expand Up @@ -120,30 +120,33 @@ export class Host implements ts.LanguageServiceHost {
}

resolveModuleNames(moduleNames: string[], containingFile: string) {
let resolvedFileNames: string[] = [];
let resolvedModules: ts.ResolvedModule[] = [];

for (let moduleName of moduleNames) {
let resolvedFileName: string;
let resolvedModule: ts.ResolvedModuleWithFailedLookupLocations;
try {
resolvedFileName = this.state.resolver(containingFile, moduleName)
if (!resolvedFileName.match(/\.tsx?$/)) resolvedFileName = null;
if (!resolvedFileName.match(/\.tsx?$/)) {
resolvedFileName = null;
}
}
catch (e) { resolvedFileName = null }

if (!resolvedFileName) {
resolvedFileName = this.state.ts.resolveModuleName(
moduleName,
containingFile,
this.state.options,
this.moduleResolutionHost
).resolvedFileName
catch (e) {
resolvedFileName = null
}

this.moduleResolutionHost.resolutionCache[`${containingFile}::${moduleName}`] = resolvedFileName;
resolvedFileNames.push(resolvedFileName);
resolvedModule = this.state.ts.resolveModuleName(
resolvedFileName || moduleName,
containingFile,
this.state.options,
this.moduleResolutionHost
);

this.moduleResolutionHost.resolutionCache[`${containingFile}::${moduleName}`] = resolvedModule;
resolvedModules.push(resolvedModule.resolvedModule);
}

return resolvedFileNames;
return resolvedModules;
}

log(message) {
Expand Down

0 comments on commit 59ff7f7

Please sign in to comment.