Skip to content

fix: parse union type annotations on tag variables#230

Closed
DylanPiercey wants to merge 0 commit into
mainfrom
dpiercey-ws-agents-feedback-i8bbdl
Closed

fix: parse union type annotations on tag variables#230
DylanPiercey wants to merge 0 commit into
mainfrom
dpiercey-ws-agents-feedback-i8bbdl

Conversation

@DylanPiercey

Copy link
Copy Markdown
Contributor

Problem

A union type annotation on a tag variable fails to parse:

<let/value: string | null = null/>

The | prematurely terminates the tag variable at value: string, and the trailing | null = null cascades into EOF reached while parsing expression. This blocks the two most common TS unions (T | null, T | undefined). The equivalent already works for generics (Array<string>) and intersections (A & B), and a parenthesized union (string | null) also works — only the bare union | was broken.

Fix

shouldTerminateConciseTagVar / shouldTerminateHtmlTagVar treated CODE.PIPE as an unconditional terminator, while CODE.OPEN_ANGLE_BRACKET returns !expression.inType (so < only terminates outside a type) and & is absent entirely. Make | mirror <: return !expression.inType. This only changes behavior inside a type annotation — outside a type, !inType is still true, so | terminates exactly as before.

Tests

New fixture tag-var-type-union covering bare unions in both concise and HTML tag-var forms (string | null, A | B | C, number | undefined) — each captures the full union as tagVar.value with the initializer kept separate. Full suite passes with no existing snapshot changes; tsc clean.

This is the root-cause fix for the union-type-annotation issue tracked in the marko repo (where it surfaces as the EOF reached while parsing expression cascade on <let/d: string | null = null>).

@changeset-bot

changeset-bot Bot commented Jul 21, 2026

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: 93850d2

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@coderabbitai

coderabbitai Bot commented Jul 21, 2026

Copy link
Copy Markdown

Warning

Review limit reached

You’ve reached a temporary PR review limit under our Fair Usage Limits Policy.

Your recent review volume is higher than typical usage, so adaptive limits are currently applied.

Next review available in: 39 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 92f8e0c6-aa04-445d-a92f-5f425a8341b0

📥 Commits

Reviewing files that changed from the base of the PR and between 93850d2 and 3538b79.

⛔ Files ignored due to path filters (1)
  • src/__tests__/fixtures/tag-var-type-union/__snapshots__/tag-var-type-union.expected.txt is excluded by !**/__snapshots__/** and included by **
📒 Files selected for processing (3)
  • .changeset/tag-var-union-type-annotations.md
  • src/__tests__/fixtures/tag-var-type-union/input.marko
  • src/states/OPEN_TAG.ts
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch dpiercey-ws-agents-feedback-i8bbdl

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

@codecov

codecov Bot commented Jul 21, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 99.95%. Comparing base (93850d2) to head (3538b79).

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #230   +/-   ##
=======================================
  Coverage   99.95%   99.95%           
=======================================
  Files          34       34           
  Lines        4270     4270           
  Branches      793      793           
=======================================
  Hits         4268     4268           
  Misses          2        2           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@DylanPiercey
DylanPiercey force-pushed the dpiercey-ws-agents-feedback-i8bbdl branch from df8ebc1 to 3538b79 Compare July 21, 2026 21:01
@DylanPiercey
DylanPiercey force-pushed the dpiercey-ws-agents-feedback-i8bbdl branch from 3538b79 to 93850d2 Compare July 21, 2026 21:07
@DylanPiercey

Copy link
Copy Markdown
Contributor Author

Closed: this change is unsound. | is overloaded as both the TS union separator and the tag-body-parameters delimiter, so making | non-terminating inside a tag-variable type annotation breaks a valid pattern — a typed tag variable followed by body params, e.g. <my-list/ref: Api|item, index|> (parses as tagVar ref: Api + params item, index before the change; the |item, index| is swallowed into the type after). Requiring (string | null) is intentional disambiguation. Better path for the original issue: a diagnostic suggesting parentheses.

DylanPiercey added a commit that referenced this pull request Jul 21, 2026
| is overloaded as the TS union separator and the tag-body-parameters
delimiter, so — unlike < — it must not be made type-aware: a typed tag
variable can be followed by |params| (<tag/v: T|a,b|>), and a union type
annotation must be parenthesized (A | B). Records the decision at the site
so the parenthesization requirement is not re-filed as a bug (see the
closed union-type PR #230).
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