Skip to content

"Extract..." refactorings not available on right side of addition/multiplication expression #61630

@DanielRosenwasser

Description

@DanielRosenwasser

Today, you can request "Extract..." refactorings on the left side of a chain of multiplications:

function multiply(a: number, b: number, c: number) {
    return [|a * b|] * c;
}

Most people consider * to be associative (even if it's not for IEEE-754 numbers). Unfortunately we strictly allow you to refactor expressions as-parsed, so the following doesn't work:

function multiply(a: number, b: number, c: number) {
    return a * [|b * c|];
}

Expected: Extract constant/function work on b * c

Actual:

{
    "name": "Extract Symbol",
    "description": "Extract function",
    "actions": [
        {
            "name": "Extract Function",
            "description": "Extract function",
            "kind": "refactor.extract.function",
            "notApplicableReason": "Cannot extract range."
        }
    ]
},
{
    "name": "Extract Symbol",
    "description": "Extract constant",
    "actions": [
        {
            "name": "Extract Constant",
            "description": "Extract constant",
            "kind": "refactor.extract.constant",
            "notApplicableReason": "Cannot extract range."
        }
    ]
},

Metadata

Metadata

Assignees

No one assigned

    Labels

    7.0 LS MigrationBugA bug in TypeScriptDomain: LS: Refactoringse.g. extract to constant or function, rename symbolEffort: ModerateRequires experience with the TypeScript codebase, but feasible. Harder than "Effort: Casual".Help WantedYou can do this

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions