Skip to content

Commit 29ba8f3

Browse files
authored
Do not include lib in extract symbol tests unless required (microsoft#19361)
1 parent 8a292e3 commit 29ba8f3

2 files changed

Lines changed: 10 additions & 10 deletions

File tree

src/harness/unittests/extractFunctions.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -195,12 +195,12 @@ namespace ts {
195195
function G<U extends T[]>(t2: U) {
196196
[#|t2.toString();|]
197197
}
198-
}`);
198+
}`, /*includeLib*/ true);
199199
// Confirm that the contextual type of an extracted expression counts as a use.
200200
testExtractFunction("extractFunction16",
201201
`function F<T>() {
202202
const array: T[] = [#|[]|];
203-
}`);
203+
}`, /*includeLib*/ true);
204204
// Class type parameter
205205
testExtractFunction("extractFunction17",
206206
`class C<T1, T2> {
@@ -219,7 +219,7 @@ namespace ts {
219219
testExtractFunction("extractFunction19",
220220
`function F<T, U extends T[], V extends U[]>(v: V) {
221221
[#|v.toString()|];
222-
}`);
222+
}`, /*includeLib*/ true);
223223

224224
testExtractFunction("extractFunction20",
225225
`const _ = class {
@@ -542,7 +542,7 @@ var q = /*b*/ //c
542542
/*m*/; /*n*/ //o`);
543543
});
544544

545-
function testExtractFunction(caption: string, text: string) {
546-
testExtractSymbol(caption, text, "extractFunction", Diagnostics.Extract_function);
545+
function testExtractFunction(caption: string, text: string, includeLib?: boolean) {
546+
testExtractSymbol(caption, text, "extractFunction", Diagnostics.Extract_function, includeLib);
547547
}
548548
}

src/harness/unittests/extractTestHelpers.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ namespace ts {
106106
getCurrentDirectory: notImplemented,
107107
};
108108

109-
export function testExtractSymbol(caption: string, text: string, baselineFolder: string, description: DiagnosticMessage) {
109+
export function testExtractSymbol(caption: string, text: string, baselineFolder: string, description: DiagnosticMessage, includeLib?: boolean) {
110110
const t = extractTest(text);
111111
const selectionRange = t.ranges.get("selection");
112112
if (!selectionRange) {
@@ -118,7 +118,7 @@ namespace ts {
118118

119119
function runBaseline(extension: Extension) {
120120
const path = "/a" + extension;
121-
const program = makeProgram({ path, content: t.source });
121+
const program = makeProgram({ path, content: t.source }, includeLib);
122122

123123
if (hasSyntacticDiagnostics(program)) {
124124
// Don't bother generating JS baselines for inputs that aren't valid JS.
@@ -154,15 +154,15 @@ namespace ts {
154154
const newTextWithRename = newText.slice(0, renameLocation) + "/*RENAME*/" + newText.slice(renameLocation);
155155
data.push(newTextWithRename);
156156

157-
const diagProgram = makeProgram({ path, content: newText });
157+
const diagProgram = makeProgram({ path, content: newText }, includeLib);
158158
assert.isFalse(hasSyntacticDiagnostics(diagProgram));
159159
}
160160
return data.join(newLineCharacter);
161161
});
162162
}
163163

164-
function makeProgram(f: {path: string, content: string }) {
165-
const host = projectSystem.createServerHost([f, projectSystem.libFile]);
164+
function makeProgram(f: {path: string, content: string }, includeLib?: boolean) {
165+
const host = projectSystem.createServerHost(includeLib ? [f, projectSystem.libFile] : [f]); // libFile is expensive to parse repeatedly - only test when required
166166
const projectService = projectSystem.createProjectService(host);
167167
projectService.openClientFile(f.path);
168168
const program = projectService.inferredProjects[0].getLanguageService().getProgram();

0 commit comments

Comments
 (0)