Skip to content

feat: add expr validator helpers#204

Merged
DylanPiercey merged 1 commit intomainfrom
expose-expr-validators
Feb 9, 2026
Merged

feat: add expr validator helpers#204
DylanPiercey merged 1 commit intomainfrom
expose-expr-validators

Conversation

@DylanPiercey
Copy link
Contributor

Expose helpers for validating if statements and attribute values can be completely parsed by the parser.

This will be used in prettier-plugin-marko in order to determine when expressions and blocks should be wrapped with brackets.

@changeset-bot
Copy link

changeset-bot bot commented Feb 9, 2026

🦋 Changeset detected

Latest commit: 1fe3aa7

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
htmljs-parser Minor

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

@DylanPiercey DylanPiercey merged commit 9a637a3 into main Feb 9, 2026
9 checks passed
@github-actions github-actions bot mentioned this pull request Feb 9, 2026
@coderabbitai
Copy link

coderabbitai bot commented Feb 9, 2026

Walkthrough

The pull request introduces expression validation helper functions for the htmljs-parser package. A new src/util/validators.ts module provides isValidStatement and isValidAttrValue functions that validate code-like strings using the Parser. These validators are exported through the public API via index.ts. Additionally, two helper functions (shouldTerminateHtmlAttrValue and shouldTerminateConciseAttrValue) in src/states/ATTRIBUTE.ts are exported. New test coverage is added via src/tests/validate.test.ts to validate the behavior of both validators. A changeset file documents this as a minor version release.

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title 'feat: add expr validator helpers' directly describes the main change: adding new validator helper functions. It clearly reflects the changeset which introduces isValidStatement and isValidAttrValue validators.
Description check ✅ Passed The description explains the purpose of the new validators (validating statement and attribute value parsing) and their intended usage in prettier-plugin-marko for determining when to wrap expressions with brackets, which aligns with the changeset.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch expose-expr-validators

No actionable comments were generated in the recent review. 🎉

🧹 Recent nitpick comments
src/states/ATTRIBUTE.ts (1)

326-345: Verify this binding when shouldTerminateHtmlAttrValue is used externally.

This function uses this: STATE.ExpressionMeta to access this.start on line 341 for the => special case. When assigned directly in validators.ts (line 50), the function is passed to expr.shouldTerminate without explicit binding. This works because the EXPRESSION state calls shouldTerminate with the expression as this context.

However, the asymmetry between this function (needs this) and shouldTerminateConciseAttrValue (plain function) could be a source of subtle bugs if consumers misuse the API.

Consider documenting this requirement or making the API more consistent.

src/util/validators.ts (1)

24-29: Type cast for parent is acceptable but could use a comment.

The undefined as unknown as Meta cast on line 26 works because ROOT_STATE handlers are all no-ops and never access parent. A brief inline comment would clarify this intentional design for future maintainers.

📝 Suggested documentation
 const ROOT_RANGE = {
   state: ROOT_STATE,
+  // Safe to cast as undefined since ROOT_STATE handlers never access parent
   parent: undefined as unknown as Meta,
   start: 0,
   end: 0,
 };

Comment @coderabbitai help to get the list of available commands and usage tips.

@DylanPiercey DylanPiercey deleted the expose-expr-validators branch February 9, 2026 20:53
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.

1 participant