summaryrefslogtreecommitdiff
path: root/deno_typescript
diff options
context:
space:
mode:
Diffstat (limited to 'deno_typescript')
-rw-r--r--deno_typescript/compiler_main.js33
1 files changed, 31 insertions, 2 deletions
diff --git a/deno_typescript/compiler_main.js b/deno_typescript/compiler_main.js
index 0d51479d5..c83bbdec3 100644
--- a/deno_typescript/compiler_main.js
+++ b/deno_typescript/compiler_main.js
@@ -110,6 +110,13 @@ const ops = {
};
/**
+ * @type {Map<string, string>}
+ */
+const moduleMap = new Map();
+
+const externalSpecifierRegEx = /^file:\/{3}\S+\/js(\/\S+\.ts)$/;
+
+/**
* This is a minimal implementation of a compiler host to be able to allow the
* creation of runtime bundles. Some of the methods are implemented in a way
* to just appease the TypeScript compiler, not to necessarily be a general
@@ -176,18 +183,34 @@ class Host {
.replace("/index.d.ts", "");
}
+ // This looks up any modules that have been mapped to internal names
+ if (moduleMap.has(fileName)) {
+ fileName = moduleMap.get(fileName);
+ }
+
const { sourceCode, moduleName } = dispatch("readFile", {
fileName,
languageVersion,
shouldCreateNewSourceFile
});
+ // If we match the external specifier regex, we will then create an internal
+ // specifier and then use that when creating the source file
+ let internalModuleName = moduleName;
+ const result = externalSpecifierRegEx.exec(moduleName);
+ if (result) {
+ const [, specifier] = result;
+ const internalSpecifier = `$deno$${specifier}`;
+ moduleMap.set(internalSpecifier, moduleName);
+ internalModuleName = internalSpecifier;
+ }
+
const sourceFile = ts.createSourceFile(
- fileName,
+ internalModuleName,
sourceCode,
languageVersion
);
- sourceFile.moduleName = moduleName;
+ sourceFile.moduleName = internalModuleName;
return sourceFile;
}
@@ -247,11 +270,17 @@ class Host {
* @return {Array<ts.ResolvedModule | undefined>}
*/
resolveModuleNames(moduleNames, containingFile) {
+ // If the containing file is an internal specifier, map it back to the
+ // external specifier
+ containingFile = moduleMap.has(containingFile)
+ ? moduleMap.get(containingFile)
+ : containingFile;
/** @type {string[]} */
const resolvedNames = dispatch("resolveModuleNames", {
moduleNames,
containingFile
});
+ /** @type {ts.ResolvedModule[]} */
const r = resolvedNames.map(resolvedFileName => {
const extension = getExtension(resolvedFileName);
return { resolvedFileName, extension };