diff --git a/src/harness/unittests/extractMethods.ts b/src/harness/unittests/extractMethods.ts index a7cc73b5b51..43984fc21b8 100644 --- a/src/harness/unittests/extractMethods.ts +++ b/src/harness/unittests/extractMethods.ts @@ -574,6 +574,13 @@ namespace A { [#|t1.toString(); t2.toString();|] } +}`); + // Confirm that the constraint is preserved. + testExtractMethod("extractMethod15", + `function F(t1: T) { + function F(t2: U) { + [#|t2.toString();|] + } }`); }); @@ -590,7 +597,7 @@ namespace A { path: "/a.ts", content: t.source }; - const host = projectSystem.createServerHost([f]); + const host = projectSystem.createServerHost([f, projectSystem.libFile]); const projectService = projectSystem.createProjectService(host); projectService.openClientFile(f.path); const program = projectService.inferredProjects[0].getLanguageService().getProgram(); diff --git a/tests/baselines/reference/extractMethod/extractMethod15.ts b/tests/baselines/reference/extractMethod/extractMethod15.ts new file mode 100644 index 00000000000..ba5b9b3ad01 --- /dev/null +++ b/tests/baselines/reference/extractMethod/extractMethod15.ts @@ -0,0 +1,35 @@ +// ==ORIGINAL== +function F(t1: T) { + function F(t2: U) { + t2.toString(); + } +} +// ==SCOPE::function 'F'== +function F(t1: T) { + function F(t2: U) { + newFunction(); + + function newFunction() { + t2.toString(); + } + } +} +// ==SCOPE::function 'F'== +function F(t1: T) { + function F(t2: U) { + newFunction(t2); + } + + function newFunction(t2: U) { + t2.toString(); + } +} +// ==SCOPE::global scope== +function F(t1: T) { + function F(t2: U) { + newFunction(t2); + } +} +function newFunction(t2: U) { + t2.toString(); +}