mirror of
https://github.com/denoland/deno.git
synced 2024-12-23 07:44:48 -05:00
Integrate ScriptSnapshot into ModuleMetaData
This commit is contained in:
parent
a4b3741b4d
commit
c003df53ab
2 changed files with 22 additions and 21 deletions
|
@ -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 {
|
||||
|
|
|
@ -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() {
|
||||
|
|
Loading…
Reference in a new issue