fix: skip parsing of JavaScript regexp literals: /test/#1245
Merged
Conversation
Owner
Author
|
I've updated to add a heuristic for divisions. |
Contributor
There was a problem hiding this comment.
Pull Request Overview
This PR adds support for parsing JavaScript regular expression literals in script elements to fix issue #1243. The change prevents the parser from incorrectly interpreting regex patterns as Go template expressions.
Key changes:
- Adds regex literal parsing capability to the script parser
- Includes comprehensive test coverage for regex patterns and edge cases
- Refactors error handling and control flow in the script parser
Reviewed Changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| parser/v2/scriptparser.go | Implements regex literal parsing with new regexpLiteral parser and integrates it into the main script parsing loop |
| parser/v2/scriptparser_test.go | Adds test cases for regex parsing, refactors existing tests, and improves error handling in test assertions |
| parser/v2/scriptparsertestdata/regexp_literal.txt | Adds test data file demonstrating regex literal parsing behavior |
joerdav
approved these changes
Aug 15, 2025
Collaborator
joerdav
left a comment
There was a problem hiding this comment.
Looks good, it reduces the cases that would error! Definitely would be ideal to squash the double curly pair bug but I think can be a separate pr.
dgrundel
pushed a commit
to dgrundel/templ
that referenced
this pull request
Aug 16, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #1243
But introduces an issue in code like this:
In the current PR,
/ 100, {{ data }}, 1000 /would be collected as a regexp literal, and therefore, the{{ data }}go value wouldn't be interpolated.