a-h / templ

A language for writing HTML user interfaces in Go.
https://templ.guide/
MIT License
8.04k stars 264 forks source link

fix: advance past comments in raw go expressions #871

Closed knudtty closed 1 month ago

knudtty commented 2 months ago

Fixes #870

When looking into the internal go/scanner package, I found the final comments are skipped. It works by scanning til the end of a comment, then a goto to the beginning of the Scan function if the mode is not set to ScanComments. If the scanner encounters the final closing brace, the position returned has not advanced.

I implemented a solution that scans comments and advances the length of the token literal. While writing this description I realized the end variable in the go expression extractor probably just needs to be updated properly. Essentially I have implemented 2 fixes. Please review both (small) commits, in case one is a better solution than the other.

a-h commented 1 month ago

Did you run the tests? I'm getting an error with this PR. There's also no test case to check the new behaviour.

a-h commented 1 month ago

I've updated the PR to the test case you provided in the issue, and the first commit in this PR.

Thanks!