mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-02-11 10:00:13 -06:00
Allow singleline string writer to be recursively used (#18297)
* Allow singleline string writer to be recursively used * Add unit test exposing issue * Fix lints
This commit is contained in:
parent
697c4d3353
commit
5c779b1edb
@ -143,6 +143,7 @@ var harnessSources = harnessCoreSources.concat([
|
||||
"customTransforms.ts",
|
||||
"programMissingFiles.ts",
|
||||
"symbolWalker.ts",
|
||||
"languageService.ts",
|
||||
].map(function (f) {
|
||||
return path.join(unittestsDirectory, f);
|
||||
})).concat([
|
||||
|
||||
@ -32,7 +32,6 @@ namespace ts {
|
||||
}
|
||||
|
||||
const stringWriter = createSingleLineStringWriter();
|
||||
let stringWriterAcquired = false;
|
||||
|
||||
function createSingleLineStringWriter(): StringSymbolWriter {
|
||||
let str = "";
|
||||
@ -62,15 +61,14 @@ namespace ts {
|
||||
}
|
||||
|
||||
export function usingSingleLineStringWriter(action: (writer: StringSymbolWriter) => void): string {
|
||||
const oldString = stringWriter.string();
|
||||
try {
|
||||
Debug.assert(!stringWriterAcquired);
|
||||
stringWriterAcquired = true;
|
||||
action(stringWriter);
|
||||
return stringWriter.string();
|
||||
}
|
||||
finally {
|
||||
stringWriter.clear();
|
||||
stringWriterAcquired = false;
|
||||
stringWriter.writeKeyword(oldString);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -128,6 +128,7 @@
|
||||
"./unittests/extractMethods.ts",
|
||||
"./unittests/textChanges.ts",
|
||||
"./unittests/telemetry.ts",
|
||||
"./unittests/languageService.ts",
|
||||
"./unittests/programMissingFiles.ts"
|
||||
]
|
||||
}
|
||||
|
||||
49
src/harness/unittests/languageService.ts
Normal file
49
src/harness/unittests/languageService.ts
Normal file
@ -0,0 +1,49 @@
|
||||
/// <reference path="..\harness.ts" />
|
||||
|
||||
namespace ts {
|
||||
describe("languageService", () => {
|
||||
const files: {[index: string]: string} = {
|
||||
"foo.ts": `import Vue from "./vue";
|
||||
import Component from "./vue-class-component";
|
||||
import { vueTemplateHtml } from "./variables";
|
||||
|
||||
@Component({
|
||||
template: vueTemplateHtml,
|
||||
})
|
||||
class Carousel<T> extends Vue {
|
||||
}`,
|
||||
"variables.ts": `export const vueTemplateHtml = \`<div></div>\`;`,
|
||||
"vue.d.ts": `export namespace Vue { export type Config = { template: string }; }`,
|
||||
"vue-class-component.d.ts": `import Vue from "./vue";
|
||||
export function Component(x: Config): any;`
|
||||
};
|
||||
it("should be able to create a language service which can respond to deinition requests without throwing", () => {
|
||||
const languageService = ts.createLanguageService({
|
||||
getCompilationSettings() {
|
||||
return {};
|
||||
},
|
||||
getScriptFileNames() {
|
||||
return ["foo.ts", "variables.ts", "vue.d.ts", "vue-class-component.d.ts"];
|
||||
},
|
||||
getScriptVersion(_fileName) {
|
||||
return "";
|
||||
},
|
||||
getScriptSnapshot(fileName) {
|
||||
if (fileName === ".ts") {
|
||||
return ts.ScriptSnapshot.fromString("");
|
||||
}
|
||||
return ts.ScriptSnapshot.fromString(files[fileName] || "");
|
||||
},
|
||||
getCurrentDirectory: () => ".",
|
||||
getDefaultLibFileName(options) {
|
||||
return ts.getDefaultLibFilePath(options);
|
||||
},
|
||||
fileExists: noop as any,
|
||||
readFile: noop as any,
|
||||
readDirectory: noop as any,
|
||||
});
|
||||
const definitions = languageService.getDefinitionAtPosition("foo.ts", 160); // 160 is the latter `vueTemplateHtml` position
|
||||
expect(definitions).to.exist;
|
||||
});
|
||||
});
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user