Fix ERB expression compilation when code contains a heredoc#78
Open
pinzonjulian wants to merge 1 commit intomarcoroth:mainfrom
Open
Fix ERB expression compilation when code contains a heredoc#78pinzonjulian wants to merge 1 commit intomarcoroth:mainfrom
pinzonjulian wants to merge 1 commit intomarcoroth:mainfrom
Conversation
marcoroth
reviewed
Feb 19, 2026
Comment on lines
+69
to
+71
| @src << "(" << code | ||
| @src << "\n" if code.match?(/<<[~-]?\s*['"`]?\w/) | ||
| @src << ")" |
Owner
There was a problem hiding this comment.
I wonder if we could just assume to always add a newline, no matter what:
Suggested change
| @src << "(" << code | |
| @src << "\n" if code.match?(/<<[~-]?\s*['"`]?\w/) | |
| @src << ")" | |
| @src << "(" << code << "\n)" |
Author
There was a problem hiding this comment.
Let me try it in CI in our own patch; I'll report back
marcoroth
reviewed
Feb 19, 2026
marcoroth
reviewed
Feb 19, 2026
Owner
marcoroth
left a comment
There was a problem hiding this comment.
Thanks @pinzonjulian for opening this!
Once we have this merged here, I'd also love to bring over the same document/test to the Herb test suite, just to make sure we also handle that correctly in Herb itself and "lock in" the behavior using a snapshot test.
1276bad to
fb4e8cd
Compare
marcoroth
pushed a commit
to marcoroth/herb
that referenced
this pull request
Feb 19, 2026
…1206) When an ERB output tag contains a heredoc (e.g. `<%= method_call <<~GRAPHQL, variables %>`), the closing parenthesis in the compiled Ruby must appear on its own line after the heredoc terminator. Without this, the compiled Ruby is syntactically invalid. This is a sibling commit to the one introduced in marcoroth/reactionview#78
When an ERB output tag wraps code in parentheses and that code contains a heredoc (e.g. `method_call <<~GRAPHQL, variables`), the closing parenthesis must appear on its own line after the heredoc terminator. Without this, the compiled Ruby is syntactically invalid. Always insert a newline before the closing parenthesis unconditionally, since Ruby ignores trailing newlines in expressions. Includes a snapshot test for the compiled output. Co-authored-by: Amp <amp@ampcode.com> Amp-Thread-ID: https://ampcode.com/threads/T-019c7333-8beb-715a-9183-8434cd5fb15a
fb4e8cd to
ad04e49
Compare
marcoroth
added a commit
to marcoroth/herb
that referenced
this pull request
Feb 19, 2026
Inspired by marcoroth/reactionview#78 (comment) This pull request updates our `assert_compiled_snapshot` assertion helper to make sure the compiled snapshot is valid Ruby by passing the engine output to Prism and checking for syntax errors. Co-authored-by: Julián Pinzón Eslava <julian@buildkite.com>
marcoroth
added a commit
that referenced
this pull request
Feb 19, 2026
Inspired by #78 (comment) Follow up on marcoroth/herb#1207 Follow up on marcoroth/herb#1209
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.
I attempted to use Reactionview in Buildkite's Rails monolith and found a blocking issue related to Heredocs.
When an ERB output tag wraps code in parentheses and that code contains a heredoc:
the closing parenthesis must appear on its own line after the heredoc terminator. Without this, the compiled Ruby is syntactically invalid.
This is my first time diving into herb and reactionview so I relied quite a bit on AI for this as I get more comfortable. However, I reviewed the code thoroughly and tested it in CI in Buildkite where I was able to reduce failed specs from ~700 to ~60.
This is a sibling commit of marcoroth/herb#1206