This commit is contained in:
Dirk Baeumer 2020-06-26 21:01:13 +02:00
Родитель b417f4c9fb
Коммит 5839e367be
3 изменённых файлов: 83 добавлений и 0 удалений

6
tsc/.mocharc.json Normal file
Просмотреть файл

@ -0,0 +1,6 @@
{
"spec": ["lib/test"],
"extension": ["js"],
"recursive": true,
"ui": "tdd"
}

52
tsc/src/test/hosts.ts Normal file
Просмотреть файл

@ -0,0 +1,52 @@
/* --------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
* ------------------------------------------------------------------------------------------ */
import * as ts from 'typescript';
export class InMemoryLanguageServiceHost implements ts.LanguageServiceHost {
private scriptSnapshots: Map<string, ts.IScriptSnapshot>;
constructor(private cwd: string, private scripts: Map<string, string>, private options: ts.CompilerOptions) {
this.scriptSnapshots = new Map();
}
public getScriptFileNames(): string[] {
return Array.from(this.scripts.keys());
}
public getCompilationSettings(): ts.CompilerOptions {
return this.options;
}
public getScriptVersion(fileName: string): string {
return '0';
}
public getProjectVersion(): string {
return '0';
}
public getScriptSnapshot(fileName: string): ts.IScriptSnapshot | undefined {
let result: ts.IScriptSnapshot | undefined = this.scriptSnapshots.get(fileName);
if (result === undefined) {
const content = this.scripts.get(fileName);
if (content === undefined) {
return undefined;
}
result = ts.ScriptSnapshot.fromString(content);
this.scriptSnapshots.set(fileName, result);
}
return result;
}
public getCurrentDirectory(): string {
return this.cwd;
}
public getDefaultLibFileName(options: ts.CompilerOptions): string {
return ts.getDefaultLibFilePath(options);
}
}

Просмотреть файл

@ -0,0 +1,25 @@
/* --------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
* ------------------------------------------------------------------------------------------ */
import * as ts from 'typescript';
import { InMemoryLanguageServiceHost } from './hosts';
import { Builder } from '../graph';
import { lsif } from '../lsif';
suite('Simple Tests', () => {
test('xxx', () => {
const host = new InMemoryLanguageServiceHost('/test', new Map([
['/test/a.ts', 'export const x = 10;']
]), { });
const languageService = ts.createLanguageService(host);
let counter = 1;
const generator = (): number => {
return counter++;
};
const builder = new Builder({ idGenerator: generator, emitSource: false });
});
});