Skip to content

fix(parser): reject v-for and v-slot names with Citry's reserved prefixes - #628

Merged
JuroOravec merged 5 commits into
mainfrom
issue-560-v-for-reserved-aliases
Nov 14, 2026
Merged

JuroOravec merged 5 commits into
mainfrom
issue-560-v-for-reserved-aliases

Conversation

@JuroOravec

@JuroOravec JuroOravec commented Nov 13, 2026 •

Copy link
Copy Markdown
Member

Part of the 0.9.0 release.

Closes #560.

What changes

A v-for alias or a v-slot pattern that uses a name starting with $, _, or citry now makes the template fail to load. That covers the item, key, and index names, the names inside an object or array pattern, #name shorthand, v-slot on a Vue component or <template>, and either directive with a modifier. Before this change such a name loaded, and inside the loop or slot it could hide a value Citry gives the template, such as $i18n, so the template read the wrong value without any error.

The error names the alias and suggests a replacement:

'v-for' on <li> (line 1, column 5) uses the name '$i18n', which starts with a prefix Citry reserves ('$', '_', or 'citry') for the values it gives the template, such as '$i18n'. A name like this could hide one of those values. Rename it, for example to 'i18n'.
  • The suggestion is always a valid JavaScript name. It is never a keyword, a name the directive already binds, or another reserved name. When the name without its prefix doesn't work (for example _ or _if), the suggestion falls back to item, key, or index, depending on the alias's position.
  • In a v-for or a Vue component's v-slot, an object shorthand such as { _id } gets a fix that keeps the property: { _id: id }.
  • The existing <c-fill v-slot> message now suggests a plain rename too. It skips the fill's Python data and fallback names, and it says that no <c-slot> prop can use these prefixes.

citry check and the editor already show load-time errors, so they report this as citry.parse.syntax. Tests cover both.

This is a breaking change: templates that load today can now fail. Hence the 0.9.0 target and the changelog entry under ## Unreleased / ### Changed.

How

  • The rule lives in one function, browser::is_reserved_browser_name (crates/citry_template_parser/src/browser.rs). The <c-slot> prop check, the <c-fill v-slot> check, and the new check all call it.
  • The new check runs in the parser's existing validate_element_vue_directives. That pass already handles HTML elements, Vue component tags, <template>, and <c-element>, and it skips v-pre content, where Vue declares no names.
  • v_for_alias_parts splits the v-for value the way Citry's Vue compiler (vize, third_party/rust/vize_atelier_core/src/steps/v_for.rs) does, because the browser runs vize's output. It splits at the first in/of with whitespace on both sides, removes one pair of outer parentheses (an unmatched one is rejected), splits at top-level commas, keeps alias positions (so the empty piece in (, $i) still leaves $i in place), and uses only the first three pieces.
  • find_reserved_binding walks each pattern with OXC to collect its names and spot shorthands, then picks the suggestion.
  • The grammar, AST, compiler output, LangImpl, and PyO3 surface are unchanged (CLAUDE.md Mechanism 2 does not apply). The new functions are pub(crate).
  • The Python-valued forms (c-v-for, a v-for key in c-bind) were already refused when the page renders, so they cannot carry a reserved alias.

Docs

  • docs_site/content/syntax/vue.md: new section "Pick loop and slot names" (#reserved-browser-names), with an example and the { _id: id } advice.
  • docs_site/content/vue/slots.md: a link to that section after the slot syntax errors list.
  • docs/design/template_grammar.md: one paragraph recording the rule.
  • CHANGELOG.md and packages/py/citry_core/CHANGELOG.md: one entry each under ## Unreleased, for template authors and for parse_template() callers.

Checks

  • cargo test -p citry_template_parser: all pass, including new parser tests in tests/tag_parser_client_directives.rs and unit tests in browser.rs.
  • cargo fmt --check and cargo clippy --all-targets for citry_template_parser: clean. The only warning is the quick-xml unused-dependency warning, which was already there.
  • pytest, focused: the new and existing slot and reserved-name tests in packages/py/citry/tests/test_vue_component_directives.py, packages/py/citry/tests/test_check.py (citry check reports citry.parse.syntax), and packages/py/citry_lsp/tests/test_engine.py (the editor diagnostic and its range).
  • ruff check and ruff format on the changed Python files: clean.
  • mypy on the gate's package scope, with the default platform and with --platform linux: no issues.
  • I did not run the full scripts/check.py gate (that belongs to the integration owner).

Review

An independent agent reviewed the diff adversarially. It found an empty-piece alias list ((, $i)) and a modifier (v-for.x) that skipped the check, and suggestions that could be keywords or rebuild a prefix. Those are fixed in the second commit. A separate docs cold-read pointed out that a suggestion could repeat another alias, that renaming a shorthand reads a different property, and that the wording claimed more than it should. Those are fixed too. A second review of the fixes found no reserved name that still gets through. Its smaller points (the <c-fill> shorthand advice, keyword suggestions, the fill's Python names) are fixed in the third commit.

Left for follow-up, not in this PR:

  • Enclosing loops. A suggestion avoids names in the same directive and the fill's Python names, but not names bound by an enclosing v-for or v-slot. For <b v-for="_ in item"> inside <li v-for="item in items">, it suggests item. The suggestion is only an example, and fixing this means walking up to the ancestors.
  • Invalid aliases. A v-for alias or a Vue v-slot value that is not valid JavaScript, such as (a), ($b) in items, still loads and then throws in the browser. It does not hide a Citry value. Rejecting it at load time is a separate check.

Security: the change only adds a check that rejects templates when they load. v-for and v-slot values come only from the template author, and data cannot choose a v- name. It opens no new way for data to reach the page.

🤖 Generated with Claude Code

@JuroOravec
JuroOravec force-pushed the issue-560-v-for-reserved-aliases branch from 9a8b352 to 7a1bea9 Compare November 14, 2026 13:48
JuroOravec and others added 4 commits November 14, 2026 14:48
…ixes

A v-for alias (the item, key and index names, including names inside a
destructuring pattern) and a v-slot pattern on a Vue component or
<template> now fail when the template loads if a name starts with $, _
or citry. Such a name hid a value Citry gives the template, such as
$i18n, and the template read the loop or slot value instead.

The <c-fill> and <c-slot> checks and the new check call one function,
browser::is_reserved_browser_name. The error names the alias and
suggests a name without the prefix. citry check and the editor report it
as citry.parse.syntax.

Closes #560.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Read the v-for alias list the way Citry's Vue compiler (vize) does:
split at top-level commas, keep alias positions so an empty piece such
as `(, $i)` is still checked, use the first three pieces, and reject an
unmatched parenthesis. Match the directive name before `:` or `.`, so
`v-for.x` and `v-slot.x` are checked too.

The suggested name now skips JavaScript keywords, names the directive
already binds, and prefixes rebuilt by lowercasing, and falls back to
`item`, `key` or `index` by position. An object shorthand such as
`{ _id }` gets a fix that keeps the property, `{ _id: id }`. The
`<c-fill v-slot>` message suggests a name the same way.

Docs: rewrite the syntax page section with an example, move the slots
page cross-link out of the `<c-slot>`/`<c-fill>` list, reword the
changelog entry, and record the rule in the template grammar design doc.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
A `<c-fill v-slot>` shorthand such as `{ _id }` reads no prop, because
no `<c-slot>` prop can carry a reserved prefix, so its error suggests a
plain rename instead of keeping the property. The suggestion skips the
fill's Python `data` and `fallback` names, and falls back to the
position's plain word (`item`, `key`, `index`, `props`) instead of a
keyword or taken name with a number appended. A suggestion must be a
valid JavaScript name.

Docs: tighten the syntax page wording and the design doc sentence.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ngelog

parse_template() now raises SyntaxError for a v-for alias or a Vue
component v-slot name that starts with $, _ or citry. The citry
changelog already records the change for template authors. citry-core
users who call parse_template() directly read this one.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@JuroOravec

Copy link
Copy Markdown
Member Author

Follow-ups from "Left for follow-up": #649 (suggestion ignores enclosing loop names) and #650 (invalid v-for alias or v-slot value not rejected at load).

@JuroOravec
JuroOravec merged commit 2b60da2 into main Nov 14, 2026
0 of 12 checks passed
@JuroOravec
JuroOravec deleted the issue-560-v-for-reserved-aliases branch November 14, 2026 14:06
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.

v-for aliases accept the $, _ and citry prefixes that v-slot reserves

1 participant