Allow colons in jsx template tag/prop names (attr:, prop:, XML namespaces) - #377
Merged
Conversation
The jsx tagged template's parser regexes excluded `:` from tag-name and prop-name character classes, so attr:/prop: prefixes and other XML namespace prefixes (xlink:href, xmlns:xlink, namespaced tags like svg:circle) threw a parse error even though the DOM and HTML renderers already understood them. Widen PROPS_RE and CHILDREN_RE to accept `:`, and validate that it isn't leading, trailing, or repeated so `:foo`, `foo:`, and `a:b:c` remain parse errors instead of being silently accepted. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
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.
Summary
jsxtagged template's parser (src/jsx-tag.ts) excluded:from its tag-name and prop-name character classes, soattr:/prop:prefixes and other XML namespace prefixes threwUnexpected text \:`even though the DOM and HTML renderers already handle them (src/dom.ts,src/html.ts`).PROPS_REandCHILDREN_REto accept:in names, and added avalidateNamecheck so a leading, trailing, or repeated colon (:foo,foo:,a:b:c) is still a parse error — this is a deliberate choice, since none of those forms are meaningful namespaced names, and a loud parse error is more useful than silently accepting garbage.All six previously-failing forms now parse to the same element shape as compiled JSX:
Verified colons elsewhere are unaffected: text children (
<p>ratio 3:1</p>), quoted attribute values (style="color: red",href="https://x"), the<//>/<//Component>closing forms, and comments.Test plan
npx playwright-test test/jsx-tag.ts --runner uvu— 29/29 passed (25 baseline + 4 new tests; confirmed the count moved, since this file is excluded fromnpm run test:core)npm run test:core— 577/577 passed (unchanged from main, no regressions)npx tsc --noEmit— cleannpx eslint --resolve-plugins-relative-to . src/jsx-tag.ts test/jsx-tag.ts --ext .ts,.tsx— clean## [Unreleased](public-facing capability)docs/guides/11-jsx-template-tag.mdanddocs/SKILL.md(+ regeneratedskills/vianpm run skill)🤖 Generated with Claude Code