Skip to content
This repository has been archived by the owner on May 27, 2020. It is now read-only.

Commit

Permalink
fix: Tsserver crashes in some cases
Browse files Browse the repository at this point in the history
  • Loading branch information
axetroy committed Mar 29, 2020
1 parent cfd9623 commit 11563b4
Showing 1 changed file with 26 additions and 15 deletions.
41 changes: 26 additions & 15 deletions typescript-deno-plugin/src/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,10 @@ export class DenoPlugin implements ts_module.server.PluginModule {
realContainingFile = project.getCurrentDirectory();
}

if (!this.typescript.sys.fileExists(realContainingFile)) {
return [];
}

const importMapsFilepath = this.configurationManager.config.import_map
? path.isAbsolute(this.configurationManager.config.import_map)
? this.configurationManager.config.import_map
Expand All @@ -163,27 +167,34 @@ export class DenoPlugin implements ts_module.server.PluginModule {
importMapsFilepath
);

const resolvedModules = resolver.resolveModules(typeDirectiveNames);
const result: (
| ts_module.ResolvedTypeReferenceDirective
| undefined
)[] = [];

return resolvedModules
.map((v, i) => {
if (!v) {
const [result] = resolveTypeReferenceDirectives(
[typeDirectiveNames[i]],
containingFile,
...rest
);
for (const typeDirectiveName of typeDirectiveNames) {
const [resolvedModule] = resolver.resolveModules([typeDirectiveName]);

return result;
}
if (resolvedModule) {
const target: ts_module.ResolvedTypeReferenceDirective = {
primary: false,
resolvedFileName: v.module,
resolvedFileName: resolvedModule.filepath,
};

return target;
})
.filter((v) => v);
result.push(target);
continue;
}

const [target] = resolveTypeReferenceDirectives(
[typeDirectiveName],
containingFile,
...rest
);

result.push(target);
}

return result;
};
}

Expand Down

0 comments on commit 11563b4

Please sign in to comment.