Fix trailing line comment classified as enclosed in validators#227
Conversation
A `//` line comment that runs to the end of a validated expression (no
terminating newline) consumes everything that would follow it on the
line, so the value is not safe to emit verbatim as an attribute value.
`isValid` only downgraded `enclosed` -> `valid` when it saw a literal
newline byte, so a value ending in a trailing line comment (e.g.
`"hello" // note`) was wrongly reported as `enclosed`, regressing
prettier-plugin-marko which then emitted the value bare and commented
out the tag close.
Flag the enclosing expression as having an unguarded newline when a line
comment reaches EOF while no group is open, mirroring the existing
unguarded-newline handling. This is done in EXPRESSION.return so it only
affects line comments whose parent is a JS expression. A comment guarded
by a group (`("hello" // c\n)`) or a self-closing block comment stays
`enclosed`.
🦋 Changeset detectedLatest commit: 4b97e68 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #227 +/- ##
=======================================
Coverage 99.95% 99.95%
=======================================
Files 34 34
Lines 4261 4270 +9
Branches 792 793 +1
=======================================
+ Hits 4259 4268 +9
Misses 2 2 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (3)
WalkthroughThis change fixes validation logic for inline JavaScript-in-HTML values ending with a trailing Changes
Sequence Diagram(s)sequenceDiagram
participant Parser
participant EXPRESSION
participant Expression
Parser->>EXPRESSION: return(child, expression) for JS_COMMENT_LINE
EXPRESSION->>EXPRESSION: check pos === maxPos and no groupStack
EXPRESSION->>Expression: set hadUnguardedNewline = true
Estimated code review effort: Low Related PRs: None identified Suggested labels: patch, bug fix Suggested reviewers: None identified 🐰 A comment that trails off at the end, 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Comment |
Description
Fixes
isValidAttrValue(andisValidStatement/isValidScriptlet) reportingenclosedfor a value that ends in a trailing//line comment, e.g."hello" // note.isValidonly downgradedenclosed→validwhen it scanned a literal newline byte. A line comment that runs to EOF contains no newline, sohadUnguardedNewlinenever tripped and the value stayedenclosed. But a trailing line comment consumes everything that would follow it on the line, so the value is not safe to emit verbatim.The fix flags the enclosing expression as having an unguarded newline when a line comment reaches EOF while no group is open — mirroring the existing unguarded-newline handling. It lives in
EXPRESSION.return, so it only affects line comments whose parent is a JS expression (not the same state entered from tag/HTML contexts)."hello" // cenclosedvalidfoo // cenclosedvalid1 + 2 // cenclosedvalid"hello" /* c */ // denclosedvalid"hello" /* c */enclosedenclosed(block comment self-closes)("hello" // c\n)enclosedenclosed(guarded by parens)"hello"\n// cvalidvalidMotivation and Context
Regression introduced in 5.11.0 (last good: 5.10.2).
enclosedpromises consumers "safe to emit verbatim, no wrapping needed" — soprettier-plugin-markoemitted such values bare, ejecting the comment and commenting out the tag close:Checklist:
Generated by Claude Code