]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/gofmt, go/format: sync internal.go
authorDmitri Shuralyov <dmitshur@golang.org>
Fri, 28 Feb 2020 03:53:18 +0000 (22:53 -0500)
committerDmitri Shuralyov <dmitshur@golang.org>
Fri, 28 Feb 2020 14:23:08 +0000 (14:23 +0000)
Apply CL 40930 to src/cmd/gofmt/internal.go to bring
it into sync with src/go/format/internal.go.

Also revert '\n' back to "\n\n" in one of the comments,
because the previous text was more accurate.
Gofmt replaces the "; " part of "package p; func _() {"
input with two newline characters, not one.

Updates #11844

Change-Id: I6bb8155a931b793311991d3cd8e006a2931b167a
Reviewed-on: https://go-review.googlesource.com/c/go/+/221497
Reviewed-by: Robert Griesemer <gri@golang.org>
src/cmd/gofmt/internal.go
src/go/format/internal.go

index cbc6983b6126c2561caf98467e773f6af11959bc..058158ad4032d4290e751abf19006a6deeedee80 100644 (file)
@@ -37,14 +37,14 @@ func parse(fset *token.FileSet, filename string, src []byte, fragmentOk bool) (
 
        // If this is a declaration list, make it a source file
        // by inserting a package clause.
-       // Insert using a ;, not a newline, so that the line numbers
+       // Insert using a ';', not a newline, so that the line numbers
        // in psrc match the ones in src.
        psrc := append([]byte("package p;"), src...)
        file, err = parser.ParseFile(fset, filename, psrc, parserMode)
        if err == nil {
                sourceAdj = func(src []byte, indent int) []byte {
                        // Remove the package clause.
-                       // Gofmt has turned the ; into a \n.
+                       // Gofmt has turned the ';' into a '\n'.
                        src = src[indent+len("package p\n"):]
                        return bytes.TrimSpace(src)
                }
@@ -60,7 +60,7 @@ func parse(fset *token.FileSet, filename string, src []byte, fragmentOk bool) (
        // If this is a statement list, make it a source file
        // by inserting a package clause and turning the list
        // into a function body. This handles expressions too.
-       // Insert using a ;, not a newline, so that the line numbers
+       // Insert using a ';', not a newline, so that the line numbers
        // in fsrc match the ones in src. Add an extra '\n' before the '}'
        // to make sure comments are flushed before the '}'.
        fsrc := append(append([]byte("package p; func _() {"), src...), '\n', '\n', '}')
@@ -72,7 +72,7 @@ func parse(fset *token.FileSet, filename string, src []byte, fragmentOk bool) (
                                indent = 0
                        }
                        // Remove the wrapping.
-                       // Gofmt has turned the ; into a \n\n.
+                       // Gofmt has turned the "; " into a "\n\n".
                        // There will be two non-blank lines with indent, hence 2*indent.
                        src = src[2*indent+len("package p\n\nfunc _() {"):]
                        // Remove only the "}\n" suffix: remaining whitespaces will be trimmed anyway
index 4918681de57c217505644cfbc6161f2f03557b76..2f3b0e43bac297a3cf4312dad958d2bd4eaa1d63 100644 (file)
@@ -72,7 +72,7 @@ func parse(fset *token.FileSet, filename string, src []byte, fragmentOk bool) (
                                indent = 0
                        }
                        // Remove the wrapping.
-                       // Gofmt has turned the ';' into a '\n'.
+                       // Gofmt has turned the "; " into a "\n\n".
                        // There will be two non-blank lines with indent, hence 2*indent.
                        src = src[2*indent+len("package p\n\nfunc _() {"):]
                        // Remove only the "}\n" suffix: remaining whitespaces will be trimmed anyway