mirror of
https://github.com/microsoft/vscode.git
synced 2025-12-25 04:36:23 +00:00
Use real maps for monaco-api/treeshaking
Working on understanding this code and trying to modernize it a little
This commit is contained in:
@@ -652,10 +652,10 @@ export class DeclarationResolver {
|
||||
);
|
||||
}
|
||||
const fileContents = this._fsProvider.readFileSync(moduleId, fileName).toString();
|
||||
const fileMap: IFileMap = {
|
||||
'file.ts': fileContents
|
||||
};
|
||||
const service = this.ts.createLanguageService(new TypeScriptLanguageServiceHost(this.ts, {}, fileMap, {}));
|
||||
const fileMap: IFileMap = new Map([
|
||||
['file.ts', fileContents]
|
||||
]);
|
||||
const service = this.ts.createLanguageService(new TypeScriptLanguageServiceHost(this.ts, new Map(), fileMap, {}));
|
||||
const text = service.getEmitOutput('file.ts', true, true).outputFiles[0].text;
|
||||
return new CacheEntry(
|
||||
this.ts.createSourceFile(fileName, text, this.ts.ScriptTarget.ES5),
|
||||
@@ -670,10 +670,8 @@ export function run3(resolver: DeclarationResolver): IMonacoDeclarationResult |
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
interface ILibMap { [libName: string]: string }
|
||||
interface IFileMap { [fileName: string]: string }
|
||||
type ILibMap = Map</*libName*/ string, string>;
|
||||
type IFileMap = Map</*fileName*/ string, string>;
|
||||
|
||||
class TypeScriptLanguageServiceHost implements ts.LanguageServiceHost {
|
||||
|
||||
@@ -695,11 +693,10 @@ class TypeScriptLanguageServiceHost implements ts.LanguageServiceHost {
|
||||
return this._compilerOptions;
|
||||
}
|
||||
getScriptFileNames(): string[] {
|
||||
return (
|
||||
([] as string[])
|
||||
.concat(Object.keys(this._libs))
|
||||
.concat(Object.keys(this._files))
|
||||
);
|
||||
return [
|
||||
...this._libs.keys(),
|
||||
...this._files.keys(),
|
||||
];
|
||||
}
|
||||
getScriptVersion(_fileName: string): string {
|
||||
return '1';
|
||||
@@ -708,10 +705,10 @@ class TypeScriptLanguageServiceHost implements ts.LanguageServiceHost {
|
||||
return '1';
|
||||
}
|
||||
getScriptSnapshot(fileName: string): ts.IScriptSnapshot {
|
||||
if (this._files.hasOwnProperty(fileName)) {
|
||||
return this._ts.ScriptSnapshot.fromString(this._files[fileName]);
|
||||
} else if (this._libs.hasOwnProperty(fileName)) {
|
||||
return this._ts.ScriptSnapshot.fromString(this._libs[fileName]);
|
||||
if (this._files.has(fileName)) {
|
||||
return this._ts.ScriptSnapshot.fromString(this._files.get(fileName)!);
|
||||
} else if (this._libs.has(fileName)) {
|
||||
return this._ts.ScriptSnapshot.fromString(this._libs.get(fileName)!);
|
||||
} else {
|
||||
return this._ts.ScriptSnapshot.fromString('');
|
||||
}
|
||||
@@ -729,10 +726,10 @@ class TypeScriptLanguageServiceHost implements ts.LanguageServiceHost {
|
||||
return fileName === this.getDefaultLibFileName(this._compilerOptions);
|
||||
}
|
||||
readFile(path: string, _encoding?: string): string | undefined {
|
||||
return this._files[path] || this._libs[path];
|
||||
return this._files.get(path) || this._libs.get(path);
|
||||
}
|
||||
fileExists(path: string): boolean {
|
||||
return path in this._files || path in this._libs;
|
||||
return this._files.has(path) || this._libs.has(path);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user