gopatch icon indicating copy to clipboard operation
gopatch copied to clipboard

Multiple top-level declarations

Open abhinav opened this issue 3 years ago • 0 comments

It's currently impossible to have a patch that introduces a new top-level declaration while modifying another one.

For example, given,

func foo() {
  re := regexp.MustCompile("foo")
  // ...
}

We cannot build a patch that would turn it into the following.

var re = regexp.MustCompile("foo")

func foo() {
  // ...
}

That's because we don't yet support patches with multiple top-level declarations in them so the following will fail to parse.

@@
var f, re identifier
var regex expression
@@
+var re = regexp.MustCompile(regex)

 func f() {
-  re := regexp.MustCompile(regex)
   ...
 }

See also #3, #4

abhinav avatar Jun 08 '21 23:06 abhinav