summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--js/compiler.ts36
-rw-r--r--js/compiler_test.ts7
2 files changed, 22 insertions, 21 deletions
diff --git a/js/compiler.ts b/js/compiler.ts
index fcbfc7c5e..93cfd34c1 100644
--- a/js/compiler.ts
+++ b/js/compiler.ts
@@ -57,9 +57,8 @@ export interface Ts {
* Named `ModuleMetaData` to clarify it is just a representation of meta data of
* the module, not the actual module instance.
*/
-export class ModuleMetaData {
+export class ModuleMetaData implements ts.IScriptSnapshot {
public readonly exports = {};
- public scriptSnapshot?: ts.IScriptSnapshot;
public scriptVersion = "";
constructor(
@@ -71,6 +70,19 @@ export class ModuleMetaData {
this.scriptVersion = "1";
}
}
+
+ public getText(start: number, end: number): string {
+ return this.sourceCode.substring(start, end);
+ }
+
+ public getLength(): number {
+ return this.sourceCode.length;
+ }
+
+ public getChangeRange(): undefined {
+ // Required `IScriptSnapshot` API, but not implemented/needed in deno
+ return undefined;
+ }
}
/**
@@ -478,25 +490,7 @@ export class DenoCompiler implements ts.LanguageServiceHost {
getScriptSnapshot(fileName: ModuleFileName): ts.IScriptSnapshot | undefined {
this._log("getScriptSnapshot()", fileName);
- const moduleMetaData = this._getModuleMetaData(fileName);
- if (moduleMetaData) {
- return (
- moduleMetaData.scriptSnapshot ||
- (moduleMetaData.scriptSnapshot = {
- getText(start, end) {
- return moduleMetaData.sourceCode.substring(start, end);
- },
- getLength() {
- return moduleMetaData.sourceCode.length;
- },
- getChangeRange() {
- return undefined;
- }
- })
- );
- } else {
- return undefined;
- }
+ return this._getModuleMetaData(fileName);
}
getCurrentDirectory(): string {
diff --git a/js/compiler_test.ts b/js/compiler_test.ts
index cc3cda406..8960112de 100644
--- a/js/compiler_test.ts
+++ b/js/compiler_test.ts
@@ -436,7 +436,14 @@ test(function compilerGetScriptSnapshot() {
"Expected .getText() to equal 'import'"
);
assertEqual(result.getChangeRange(result), undefined);
+ // This is and optional part of the `IScriptSnapshot` API which we don't
+ // define, os checking for the lack of this property.
assert(!("dispose" in result));
+
+ assert(
+ result === moduleMetaData,
+ "result should strictly equal moduleMetaData"
+ );
});
test(function compilerGetCurrentDirectory() {