Repository navigation
fix(core): report a dynamic tag expression that isn't an identifier, a member access, or a string (#737) - #782
Merged
Merged
Conversation
…a member access, or a string (#737) A dynamic tag expression (`<{expr}>`) must be an identifier, a member access (chains from an identifier or `this`, computed keys that are an identifier, a string or number literal, or a member access), or a string literal. Any other expression parses and is reported as `tsrx-dynamic-tag-expression` at the part that isn't allowed, once per element: thrown in a strict parse, recorded in `collect` and `loose` mode. This replaces the old check, which threw in every mode and let conditionals, `&&`, arrow functions and elements through. @tsrx/prettier-plugin formats a file whose only error is a reported tag. The specification, llms.txt, the features page and the MCP docs list the three forms. Co-Authored-By: Claude Opus 5.5 <[email protected]>
This was referenced Sep 26, 2026
Co-Authored-By: Claude Opus 5.5 <[email protected]>
…e any compile error The old plugin parses strictly and refuses every other error a normal compile reports, so it no longer parses a second time in collect mode for a disallowed dynamic tag. Its code is back to main's, its tests check that it rejects the tag with core's error, and its changeset entry is dropped. tsrx-prettier-plugin still formats such files. Co-Authored-By: Claude Opus 5.5 <[email protected]>
This was referenced Sep 27, 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.
Closes #737
The rule
A dynamic tag expression (
<{expr}>) must be one of three forms, as decided in #737:tag,Comp;props.as,Content.value,this.tag,registry[name],items[0]. Each computed key is an identifier, a string or number literal, or a member access;'section'.Everything else is reported as
tsrx-dynamic-tag-expression: conditionals,||,??and&&; parentheses and type-only wrappers ((tag),tag as any,tag satisfies T,tag!);null,undefined, numbers, booleans, objects, arrays and regular expressions; optional member access; computed keys outside the list (registry[getName()],items[-1]); arrow functions, functions, classes, elements and fragments; calls,new, spreads, concatenation, template literals, assignments, sequences,!tagandawait tag.The message suggests computing the tag first:
The bug
The old check in
plugin.jsthrew "Dynamic element names must be…" in every mode, so one call or concatenation in a tag lost the whole file's AST incollectmode, the mode the editor and both formatters use. It also let through the forms #737 lists: arrow functions, elements inside a conditional or||,nullas a branch,&&anda?.b.The fix
find_invalid_dynamic_tag_partinplugin.jsreturns the first part of the expression that isn't one of the three forms. It follows only the chain of a member access (the object and each computed key), so it never walks the whole expression.jsx_parseOpeningElementAtchecks the name once per element. The closing tag repeats the expression and isn't checked, so an element is reported once.#report_recoverable_error_range: thrown in a strict parse, recorded incollectandloosemode, where parsing goes on. It points at the disallowed part: the whole tag forc ? A : B,getName()inregistry[getName()],(a)in(a).b. The range of a parenthesized part includes its parentheses whenpreserveParensis off (end_after_parentheses, from themetadata.paren_startthe parser already records).<{...a}>and<{}>still throw in every mode, with the new message. They aren't anAssignmentExpression, so they don't fit the grammar at all, and a spread child or an empty expression in the name position would break the printers and transforms that read the name.DIAGNOSTIC_CODES.DYNAMIC_TAG_EXPRESSIONandTSRX_DYNAMIC_TAG_EXPRESSION_ERROR.@tsrx/prettier-pluginparses strictly, like a normal compile, so it refuses a file with a disallowed tag, as it refuses every other error a compile reports. Its code is unchanged; its tests check that it rejects the tag withtsrx-dynamic-tag-expression, and it has no changeset entry.tsrx-prettier-plugincollects errors and formats such files: this error isn't one of itsREJECTED_MISTAKES, since it drops no code.llms.txt, the features page, and the MCP docs (regenerated) list the three forms and show theconst Tag = …pattern.No upstream overrides.
Decisions to check
thisstarts a chain.<{this.tag} />and<{this.#Tag} />are allowed; a bare<{this} />isn't. The rule lists chains without naming their start.thisbehaves like an identifier here, and a source-mapping test for private names already uses<{this.#Tag} />.super.xandimport.meta.xare reported.<{`div`} />) was accepted before and is reported now, since the rule reports template literals. A parser test and an old-formatter test used one; they now use allowed forms.Verification
Every input parsed before and after the change, strict and with
{ collect: true, errors: [], comments: [], preserveParens: true }and{ loose: true }. That's 19,750 inputs: 70 tracked.tsrxfiles, 2,040 Prettier snapshot inputs and 2,040 outputs, and 15,600 distinct string literals from test files. 24 changed, and every change is intended. No AST changed where both versions parse.<{`div`} />,<{`article`} />, and six tests with an element in a conditional tag (<{c ? <b>/* c */</b> : "div"} />,<{c ? <b>{x} …</b> : 'i'} />).<{null} />,<{tagName()} />,<{'hello' + 'by'} />,<{`d${kind}`} />, …).<{...a} />.Existing tests whose inputs are now errors:
<{`article`} />became<{registry[props.kind]} />in the old formatter's test.{x}becomes an expression #693) now expect the strict error and check the tree incollectandloosemode. The compile test for [Bug]: tsrx-core: Character references in an element in a spread argument, or in an unbraced attribute value in a container, compile decoded:{x}becomes an expression #693 moved to the editor's virtual code, where a reported tag still compiles.tsrx-prettier-pluginstill formats those inputs, and its labels now say "reported". The old formatter's case for an element in a tag name is removed; its new rejection test covers that input.New tests:
collect; 49 reported forms, each in strict,collect,collectwithpreserveParensandloosemode, checking the message and range; a file with three reported tags that still parses to the end incollectandloosemode, one error per element; a tag nested in a tag; and a spread or empty container, which still throw.collectrecords the error and still produces code that parses as TSX, and the editor's virtual code keeps and maps the expression.Local runs (
--maxWorkers=4):tsrx-utils(1,314), the five target projects andtsrx-analyze(3,398),prettier-pluginandtsrx-prettier-plugin(4,955),tsrx-mcp(83) andwebsite(47) all pass. The Prettier known-failures list didn't change.pnpm typecheckpasses;tsrx-tscwasn't linked after--ignore-scripts, so its one step (vite-plugin-honotests) ran throughpackages/typescript-plugin/dist/tsc.js.pnpm formatleft no diff.Downstream
Checked against Ripple and Octane at
origin/main, with@tsrx/coreoverridden to this branch in scratch worktrees, and compared with a run onmain's core:83ed5615): one test uses a tag this rule reports,<{flag.value || !flag.value ? Child : null} n={n.value} />inpackages/ripple/tests/client/composite/composite.dynamic-components.test.tsrx, so that file no longer compiles. The otherripple-client,ripple-server,tsrx-rippleandripple-hydrationresults match the run onmain's core. That run has 4 failures in the style-identifier and scoped-styles tests;parser-nestingtimed out once under load and passes on its own. Filed [Bug]: A test's dynamic tagflag.value || !flag.value ? Child : nullstops compiling with the next@tsrx/core(tsrx-org/tsrx#737) Ripple-TS/ripple#1522 with a rewrite that keeps what the test checks (<{children[key.value]} n={n.value} />); all 8 tests in the file pass with it on this branch's core.e813fc0e): none of its 2,963.tsrxfiles or its test strings use a tag this rule reports. Its affected tests (dynamic-tag,ssr-host-string-tags,style-list-scopes,universal-renderer,tests/compiler; 2,768 tests) show no new failures: 5 type-checking tests failed onmain's core, and 1 of those on this branch's. On Node, Octane parses with@tsrx/oxcfirst, so JSX inside a dynamic tag name is left in the compiled output, so the module is not valid JavaScript octanejs/octane#1329's inputs become errors there once@tsrx/oxcfollows this rule. [Bug]: vue-runtime: twomergeRefsresults set on one node clean each other up, so a component's own ref staysnullwhen a parent forwards a merged ref through a spread #1329 already says to wait for [Bug]: tsrx-core: A dynamic tag accepts conditionals, arrow functions, elements and null, where only an identifier, member access or string should be allowed, and a disallowed form fails the whole file in collect mode #737, so there's no new Octane issue.@tsrx/oxc: its native check (crates/oxc_adapter/src/dynamic_tags.rs) implements the old rule, andtsrx-core-compatthrows the old message in every mode. Filed Dynamic tag expressions follow the old rule: conditionals, casts,&&, arrow functions and elements are accepted, and a call fails the whole file incollectmode oxc#115.Both issues start with a box saying to wait for the
@tsrx/corerelease that includes this PR.🤖 Generated with Claude Code
Note
Medium Risk
This is a breaking language change for some previously accepted dynamic tags (e.g. conditionals and template literals in tags), and it touches core parsing used by the editor and formatters; behavior is well-tested but downstream packages may need updates.
Overview
Tightens dynamic tag rules (
<{expr}>) so only an identifier, member access (with allowed computed keys), or a string literal is valid; everything else (conditionals, calls, templates, casts, etc.) istsrx-dynamic-tag-expression, with guidance to hoist viaconst Tag = ….The parser replaces the old deep walk with
find_invalid_dynamic_tag_partand reports on the opening tag only through recoverable errors: strict compile throws,collect/looserecord once per element and keep the AST—fixing cases where invalid tags used to abort the whole file in editor/format paths.@tsrx/prettier-pluginaddsparseTsrx: retry withcollectwhen the sole failure is this diagnostic so Prettier can still format. Spec, site docs, MCP generated docs, and a changeset document the rule; tests cover parser ranges, all compile targets, and formatters.Reviewed by Cursor Bugbot for commit fa9e85d. Bugbot is set up for automated code reviews on this repo. Configure here.