From cf5a39a36127e8df70ac34b9895771fb41d474a6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bartek=20Iwa=C5=84czuk?= Date: Tue, 5 May 2020 18:23:15 +0200 Subject: refactor(ts): remove op_cache (#5071) This PR removes op_cache and refactors how Deno interacts with TS compiler. Ultimate goal is to completely sandbox TS compiler worker; it should operate on simple request -> response basis. With this commit TS compiler no longer caches compiled sources as they are generated but rather collects all sources and sends them back to Rust when compilation is done. Additionally "Diagnostic" and its children got refactored to use "Deserialize" trait instead of manually implementing JSON deserialization. --- cli/js/compiler/host.ts | 31 ++++++++++++++++--------------- 1 file changed, 16 insertions(+), 15 deletions(-) (limited to 'cli/js/compiler/host.ts') diff --git a/cli/js/compiler/host.ts b/cli/js/compiler/host.ts index de2eacfa9..64b5e0245 100644 --- a/cli/js/compiler/host.ts +++ b/cli/js/compiler/host.ts @@ -255,16 +255,12 @@ export class Host implements ts.CompilerHost { assert(sourceFile != null); if (!sourceFile.tsSourceFile) { assert(sourceFile.sourceCode != null); - // even though we assert the extension for JSON modules to the compiler - // is TypeScript, TypeScript internally analyses the filename for its - // extension and tries to parse it as JSON instead of TS. We have to - // change the filename to the TypeScript file. + const tsSourceFileName = fileName.startsWith(ASSETS) + ? sourceFile.filename + : fileName; + sourceFile.tsSourceFile = ts.createSourceFile( - fileName.startsWith(ASSETS) - ? sourceFile.filename - : fileName.toLowerCase().endsWith(".json") - ? `${fileName}.ts` - : fileName, + tsSourceFileName, sourceFile.sourceCode, languageVersion ); @@ -294,15 +290,20 @@ export class Host implements ts.CompilerHost { containingFile, }); return moduleNames.map((specifier) => { - const url = SourceFile.getUrl(specifier, containingFile); - const sourceFile = specifier.startsWith(ASSETS) - ? getAssetInternal(specifier) - : url - ? SourceFile.get(url) - : undefined; + const maybeUrl = SourceFile.getUrl(specifier, containingFile); + + let sourceFile: SourceFile | undefined = undefined; + + if (specifier.startsWith(ASSETS)) { + sourceFile = getAssetInternal(specifier); + } else if (typeof maybeUrl !== "undefined") { + sourceFile = SourceFile.get(maybeUrl); + } + if (!sourceFile) { return undefined; } + return { resolvedFileName: sourceFile.url, isExternalLibraryImport: specifier.startsWith(ASSETS), -- cgit v1.2.3