镜像站点 · 本页由第三方 GitHub 只读镜像提供,非 GitHub 官方站点,不接受任何登录或凭据输入。前往 github.com
Skip to content

Need control over trivia when replacing nodes #18626

Description

@amcasey

Consider the following code:

// a
var q = /*b*/ //c
    /*d*/ 1 /*e*/ //f
    /*g*/ + /*h*/ //i
    /*j*/ 2 /*k*/ //l
    /*m*/; /*n*/ //o

Suppose we extract the range from 1 to 2 (inclusive) into a separate function. We would like comments e-j to move to the new function and the others to remain where they are:

// a
var q = /*b*/ //c
    /*d*/ newFunction() /*k*/ //l
    /*m*/; /*n*/ //o

function newFunction() {
    return 1 /*e*/ //f
    /*g*/ + /*h*/ //i
    /*j*/ 2;
}

Presently, there doesn't seem to be a way to express this. We can cause the leading and trailing trivia to remain at the call site by replacing a range ({pos: expr.getStart(), end: expr.end}), rather than a node (expr), but there doesn't seem to be a way to strip the leading and trailing trivia in the body of the extracted function.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

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

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions