Skip to content

Extract function doesn't preserve semantic with return statements #18140

Description

@dbaeumer
function foo(i: number) {
	let x = 10;
	for (let i = 0; i < 10; i++) {
		x++;
		return;
	}
}
  • select
		x++;
		return;
  • extract
  • you get
function foo(i: number) {
	let x = 10;
	for (let i = 0; i < 10; i++) {
        x = newFunction(x);
	}
}
function newFunction(x: number) {
    x++;
    return x;
}

which is not sematic preserving.

Metadata

Metadata

Assignees

Labels

BugA bug in TypeScriptDomain: LS: Refactoringse.g. extract to constant or function, rename symbolFixedA PR has been merged for this issue

Type

No type
No fields configured for issues without a type.

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions