Repository navigation
fix(parser): reject v-for and v-slot names with Citry's reserved prefixes - #628
Merged
Merged
Conversation
JuroOravec
force-pushed
the
issue-560-v-for-reserved-aliases
branch
from
November 14, 2026 13:48
9a8b352 to
7a1bea9
Compare
…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
force-pushed
the
issue-560-v-for-reserved-aliases
branch
from
November 14, 2026 13:48
7a1bea9 to
df0a7e1
Compare
JuroOravec
marked this pull request as ready for review
November 14, 2026 13:48
Member
Author
This was referenced Nov 14, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Part of the 0.9.0 release.
Closes #560.
What changes
A
v-foralias or av-slotpattern that uses a name starting with$,_, orcitrynow makes the template fail to load. That covers the item, key, and index names, the names inside an object or array pattern,#nameshorthand,v-sloton 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:
_or_if), the suggestion falls back toitem,key, orindex, depending on the alias's position.v-foror a Vue component'sv-slot, an object shorthand such as{ _id }gets a fix that keeps the property:{ _id: id }.<c-fill v-slot>message now suggests a plain rename too. It skips the fill's Pythondataandfallbacknames, and it says that no<c-slot>prop can use these prefixes.citry checkand the editor already show load-time errors, so they report this ascitry.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
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.validate_element_vue_directives. That pass already handles HTML elements, Vue component tags,<template>, and<c-element>, and it skipsv-precontent, where Vue declares no names.v_for_alias_partssplits thev-forvalue 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 firstin/ofwith 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$iin place), and uses only the first three pieces.find_reserved_bindingwalks each pattern with OXC to collect its names and spot shorthands, then picks the suggestion.LangImpl, and PyO3 surface are unchanged (CLAUDE.md Mechanism 2 does not apply). The new functions arepub(crate).c-v-for, av-forkey inc-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.mdandpackages/py/citry_core/CHANGELOG.md: one entry each under## Unreleased, for template authors and forparse_template()callers.Checks
cargo test -p citry_template_parser: all pass, including new parser tests intests/tag_parser_client_directives.rsand unit tests inbrowser.rs.cargo fmt --checkandcargo clippy --all-targetsforcitry_template_parser: clean. The only warning is thequick-xmlunused-dependency warning, which was already there.packages/py/citry/tests/test_vue_component_directives.py,packages/py/citry/tests/test_check.py(citry checkreportscitry.parse.syntax), andpackages/py/citry_lsp/tests/test_engine.py(the editor diagnostic and its range).--platform linux: no issues.scripts/check.pygate (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:
v-fororv-slot. For<b v-for="_ in item">inside<li v-for="item in items">, it suggestsitem. The suggestion is only an example, and fixing this means walking up to the ancestors.v-foralias or a Vuev-slotvalue 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-forandv-slotvalues come only from the template author, and data cannot choose av-name. It opens no new way for data to reach the page.🤖 Generated with Claude Code