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