Skip to content

Seal heredoc renders so nothing packs onto their terminator - #17

Merged
JPDuchesne merged 1 commit into
mainfrom
jpd/16-heredoc-line-terminal
Aug 3, 2026
Merged

Seal heredoc renders so nothing packs onto their terminator#17
JPDuchesne merged 1 commit into
mainfrom
jpd/16-heredoc-line-terminal

Conversation

@JPDuchesne

Copy link
Copy Markdown
Contributor

Summary

  • Fixes Line-aligned emission places statements after a heredoc terminator, producing invalid Ruby #16: when Unparser falls back to <<-HEREDOC emission (a dstr failing its quoted round-trip — e.g. interpolation-heavy strings carrying newlines), the line-aligned emitter packed displaced statements and container closers onto the terminator line with ; , unterminating the heredoc and swallowing the rest of the file.
  • StatementRenderer#line_terminal? decides whether a render's last line can be extended, by re-parse verification (the same style compress_to_single_line already uses) behind a cheap << textual gate. The probe chomps first: heredoc renders end with a trailing newline, and the question is about the last line, where packing would land.
  • Layout#place accepts the verdict as a seal: property, keeping the layering intact (Layout stays Ruby-free — "this last line is unextendable" is a caller-declared property). A pack onto a sealed line opens a fresh line instead: alignment degrades by one line, validity is preserved. The seal covers exactly one pack; padding to a line ahead is unaffected.
  • Both statement renders and container openers seal (an opener can carry a heredoc argument too). A false-positive seal costs one line of alignment, never correctness.

Test plan

  • End-to-end regression in line_aligned_emitter_test.rb: the Line-aligned emission places statements after a heredoc terminator, producing invalid Ruby #16-shaped source (heredoc-fallback render displacing following statements) now compiles, terminator alone on its line — failed with the issue's exact SyntaxError before the fix
  • Layout seal semantics: sealed pack opens a fresh line, seal covers one pack, padding unaffected
  • StatementRenderer#line_terminal?: heredoc render flagged; plain renders, shovel <<, quoted "<<-EOS", and multi-line quoted strings pass
  • Full suite (112 tests) and rubocop green

Made with Cursor

Unparser legitimately falls back to <<-HEREDOC emission when a dstr fails
its quoted-string round-trip; the line-aligned emitter then treated that
render like any other statement and `;`-packed displaced statements (and
container closers) onto the terminator line, unterminating the heredoc
and producing invalid Ruby (#16).

StatementRenderer#line_terminal? probes whether a render's last line can
be extended (re-parse verification, the same style as
compress_to_single_line, behind a cheap `<<` gate), and Layout#place
accepts the result as a `seal:` property: a pack onto a sealed line opens
a fresh line instead — alignment degrades by one line, validity is
preserved. Statements and container openers both seal; a false-positive
seal costs alignment, never correctness.

Closes #16

Co-authored-by: Cursor <cursoragent@cursor.com>
@codecov

codecov Bot commented Aug 3, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@JPDuchesne
JPDuchesne merged commit 6ab5d2d into main Aug 3, 2026
5 checks passed
@JPDuchesne
JPDuchesne deleted the jpd/16-heredoc-line-terminal branch August 3, 2026 14:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Line-aligned emission places statements after a heredoc terminator, producing invalid Ruby

1 participant