From eda1c7b74a583a567c781fe13e63a80c2d4dcc3d Mon Sep 17 00:00:00 2001 From: Kitson Kelly Date: Tue, 7 Aug 2018 13:15:04 -0700 Subject: [PATCH] Create ASSETS const in runtime.ts --- js/runtime.ts | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/js/runtime.ts b/js/runtime.ts index 4e9cb657de..8b7863b9fb 100644 --- a/js/runtime.ts +++ b/js/runtime.ts @@ -17,6 +17,7 @@ import { window, globalEval } from "./globals"; //import * as deno from "./deno"; const EOL = "\n"; +const ASSETS = "/$asset$/"; // tslint:disable-next-line:no-any export type AmdFactory = (...args: any[]) => undefined | object; @@ -166,13 +167,13 @@ export function resolveModule( util.assert(moduleSpecifier != null && moduleSpecifier.length > 0); let filename: string, sourceCode: string, outputCode: string; if ( - moduleSpecifier.startsWith("/$asset$/") || - containingFile.startsWith("/$asset$/") + moduleSpecifier.startsWith(ASSETS) || + containingFile.startsWith(ASSETS) ) { // Assets are compiled into the runtime javascript bundle. const assetName = moduleSpecifier.split("/").pop(); sourceCode = assetSourceCode[assetName]; - filename = "/$asset$/" + assetName; + filename = ASSETS + assetName; } else { // We query Rust with a CodeFetch message. It will load the sourceCode, and // if there is any outputCode cached, will return that as well. @@ -331,7 +332,7 @@ class TypeScriptHost implements ts.LanguageServiceHost { getDefaultLibFileName(options: ts.CompilerOptions): string { const fn = "lib.deno.d.ts"; // ts.getDefaultLibFileName(options); util.log("getDefaultLibFileName", fn); - const m = resolveModule(fn, "/$asset$/"); + const m = resolveModule(fn, ASSETS); return m.fileName; } @@ -344,9 +345,9 @@ class TypeScriptHost implements ts.LanguageServiceHost { return moduleNames.map((name: string) => { let resolvedFileName; if (name === "deno") { - resolvedFileName = resolveModuleName("deno.d.ts", "/$asset$/"); + resolvedFileName = resolveModuleName("deno.d.ts", ASSETS); } else if (name === "typescript") { - resolvedFileName = resolveModuleName("typescript.d.ts", "/$asset$/"); + resolvedFileName = resolveModuleName("typescript.d.ts", ASSETS); } else { resolvedFileName = resolveModuleName(name, containingFile); if (resolvedFileName == null) {