Repository: a-h/templ (Go)

Issue:
Raw go errors if block ends with a comment
**Describe the bug**
Comments in the middle of a raw code block is fine, but a comment at the end will cause an error when generating templates

**To Reproduce**
```templ
// example.templ

package bingo

templ innerDataPatient() {
    {{
        one := "one"
        two := "two"
        // fine
        four := "four"
        // breaks
    }}
    <div></div>
}
```
Then run:
```bash
$ TEMPL_EXPERIMENT=rawgo templ generate
(✗) Error generating code [ file=input.templ error=input.templ parsing error: go code: missing close braces: line 8, col 8 ]
(✗) Event handler failed [ error=failed to generate code for "input.templ": input.templ parsing error: go code: missing close braces: line 8, col 8 ]
(✗) Error [ error=failed to generate code for "input.templ": input.templ parsing error: go code: missing close braces: line 8, col 8 ]
```
**Expected behavior**
A comment at the end of a raw go code block should not cause an error

**Desktop (please complete the following information):**
 - OS: MacOS
 - templ CLI version: v0.2.7.47
- Go version: 1.22.5 darwin/arm64

**Additional context**
I suspect it's a simple parser error


Discussion:

Patch:
diff --git a/.version b/.version
index 5cc385c97..1148158d1 100644
--- a/.version
+++ b/.version
@@ -1,1 +1,1 @@
-0.2.759
\ No newline at end of file
+0.2.763
\ No newline at end of file
diff --git a/parser/v2/goexpression/parse.go b/parser/v2/goexpression/parse.go
index 77c413cc9..22e2db106 100644
--- a/parser/v2/goexpression/parse.go
+++ b/parser/v2/goexpression/parse.go
@@ -112,7 +112,7 @@ func TemplExpression(src string) (start, end int, err error) {
 	errorHandler := func(pos token.Position, msg string) {
 		err = fmt.Errorf("error parsing expression: %v", msg)
 	}
-	s.Init(file, []byte(src), errorHandler, 0)
+	s.Init(file, []byte(src), errorHandler, scanner.ScanComments)
 
 	// Read chains of identifiers, e.g.:
 	// components.Variable
@@ -140,7 +140,7 @@ func Expression(src string) (start, end int, err error) {
 	errorHandler := func(pos token.Position, msg string) {
 		err = fmt.Errorf("error parsing expression: %v", msg)
 	}
-	s.Init(file, []byte(src), errorHandler, 0)
+	s.Init(file, []byte(src), errorHandler, scanner.ScanComments)
 
 	// Read chains of identifiers and constants up until RBRACE, e.g.:
 	// true
@@ -183,6 +183,8 @@ loop:
 			end = int(pos) + len(lit) - 1
 		case token.SEMICOLON:
 			continue
+		case token.COMMENT:
+			end = int(pos) + len(lit) - 1
 		case token.ILLEGAL:
 			return 0, 0, fmt.Errorf("illegal token: %v", lit)
 		default:


Test patch:
diff --git a/parser/v2/gocodeparser_test.go b/parser/v2/gocodeparser_test.go
index dff14430f..19fada80e 100644
--- a/parser/v2/gocodeparser_test.go
+++ b/parser/v2/gocodeparser_test.go
@@ -91,6 +91,32 @@ func TestGoCodeParser(t *testing.T) {
 				Multiline: true,
 			},
 		},
+		{
+			name: "comments in expression",
+			input: `{{
+	one := "one"
+	two := "two"
+	// Comment in middle of expression.
+	four := "four"
+	// Comment at end of expression.
+}}`,
+			expected: GoCode{
+				Expression: Expression{
+					Value: `
+	one := "one"
+	two := "two"
+	// Comment in middle of expression.
+	four := "four"
+	// Comment at end of expression.`,
+					Range: Range{
+						From: Position{Index: 2, Line: 0, Col: 2},
+						To:   Position{Index: 117, Line: 5, Col: 33},
+					},
+				},
+				TrailingSpace: SpaceNone,
+				Multiline:     true,
+			},
+		},
 	}
 	for _, tt := range tests {
 		tt := tt