mirror of
https://github.com/denoland/deno.git
synced 2024-11-21 15:04:11 -05:00
Handle 404 fetch better.
This commit is contained in:
parent
8edb3390c2
commit
c150c320c6
1 changed files with 17 additions and 6 deletions
23
runtime.ts
23
runtime.ts
|
@ -146,10 +146,14 @@ export function resolveModule(
|
|||
util.assert(moduleSpecifier != null && moduleSpecifier.length > 0);
|
||||
// We ask golang to sourceCodeFetch. It will load the sourceCode and if
|
||||
// there is any outputCode cached, it will return that as well.
|
||||
const { filename, sourceCode, outputCode } = os.codeFetch(
|
||||
moduleSpecifier,
|
||||
containingFile
|
||||
);
|
||||
let fetchResponse;
|
||||
try {
|
||||
fetchResponse = os.codeFetch(moduleSpecifier, containingFile);
|
||||
} catch(e) {
|
||||
// TODO Only catch "no such file or directory" errors. Need error codes.
|
||||
return null;
|
||||
}
|
||||
const { filename, sourceCode, outputCode } = fetchResponse;
|
||||
if (sourceCode.length === 0) {
|
||||
return null;
|
||||
}
|
||||
|
@ -165,9 +169,13 @@ export function resolveModule(
|
|||
function resolveModuleName(
|
||||
moduleSpecifier: string,
|
||||
containingFile: string
|
||||
): string {
|
||||
): string | undefined {
|
||||
const mod = resolveModule(moduleSpecifier, containingFile);
|
||||
return mod.fileName;
|
||||
if (mod) {
|
||||
return mod.fileName;
|
||||
} else {
|
||||
return undefined;
|
||||
}
|
||||
}
|
||||
|
||||
function execute(fileName: string, outputCode: string): void {
|
||||
|
@ -308,6 +316,9 @@ class TypeScriptHost implements ts.LanguageServiceHost {
|
|||
resolvedFileName = resolveModuleName("typescript.d.ts", "/$asset$/");
|
||||
} else {
|
||||
resolvedFileName = resolveModuleName(name, containingFile);
|
||||
if (resolvedFileName == null) {
|
||||
return undefined;
|
||||
}
|
||||
}
|
||||
const isExternalLibraryImport = false;
|
||||
return { resolvedFileName, isExternalLibraryImport };
|
||||
|
|
Loading…
Reference in a new issue