Repository navigation
feat(core): keep every character between the tags in an element's children - #869
Merged
Merged
Conversation
…ldren
The parser now gives an element's and a fragment's children exactly the
shape TSX's parsers give them: whitespace-only text (layout indentation)
is kept as JSXText, every comment between children is an empty `{}` of
its own with the comment in its JSXEmptyExpression's innerComments, and
the whitespace and comments right after a control-flow block are read as
text and comments too, which fixes a lost space before a comment there.
Adds the `isLayoutWhitespace` export, JSX's rule for text that renders
nothing, and `render_children`, which core's compilers use to read the
children that render, so compiled output is unchanged. The new Prettier
plugin reads the parser's children directly instead of rebuilding them
from the source (rebuildJsxChildren and addJsxText are gone).
Co-Authored-By: Claude Opus 5.5 <[email protected]>
This was referenced Sep 27, 2026
Closed
…ead, keep text before a comment in nested elements
Every comment between an element's children is now in a `{}` child,
so this code no longer does anything:
- the comment metadata the tokenizer attached (`#createCommentMetadata`,
`commentContainerId`, a comment's `context`, `CommentMetaData`, and
onComment's `metadata` argument), which nothing read;
- `elementLeadingComments`, written but never read, and its branch;
- `getEmptyElementInnerCommentTarget` and its four call sites, which
only an element whose text had been dropped could reach;
- the hand-built text node for whitespace before `@{`, now the shared
`#addSkippedTemplateText`.
Fixes the tokenizer for an element in a `{…}` container or an attribute
value: it dropped the text before a comment that ended the run, so
`{x && <span>a /* c */</span>}` rendered an empty `<span>`.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
This was referenced Sep 29, 2026
Closed
This was referenced Sep 30, 2026
This was referenced Oct 26, 2026
This was referenced Nov 9, 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.
What this PR does
Core's parser now gives an element's and a fragment's children exactly the shape TSX's parsers give them. Every character between the tags is in the tree, and each comment is where
{/* … */}would be in TSX:<div><b />,<i />(the whitespace dropped, the comment attached to<i />)"⏎ ",<b />,"⏎ ",{},"⏎ ",<i />,"⏎"TypeScript, Babel, oxc, SWC, typescript-estree and acorn-jsx all keep that whitespace text, and apply JSX's whitespace rule only when compiling. TSRX's parser applied it while parsing, a leftover of Ripple's statement-based templates (Ripple-TS/ripple#1199). So both formatters had to rebuild the text from the source.
What renders doesn't change, with one fix:
This used to render
<b>t</b>two: the parser read what follows the block's}as code, and lost the space before the comment. It now renders<b>t</b> two, as TSX does.Changes
@tsrx/core(minor, ships in 0.5.0 with #858; decision 51–52 in #852):plugin.js:#addTemplateTextgives every comment an empty{}of its own (JSXExpressionContainer+JSXEmptyExpression, spanning exactly the comment, no braces in the source). The comment attachment puts the comment in itsinnerComments, as feat(core, prettier plugins): read // like JavaScript and render comments between children like {/* … */} #858 does.#readSkippedTemplateTextreads what the tokenizer skipped between two children as text and comments: after a control-flow block's}, and a comment where a text run would start (<b />/* c */text). feat(core, prettier plugins): read // like JavaScript and render comments between children like {/* … */} #858's special case for text after a block becomes this general rule.isLayoutWhitespace(node): JSX's rule for text that renders nothing (empty, or only spaces, tabs and line breaks with a line break among them; a non-breaking space is text). It's the one place the rule lives, for core and for Ripple, Octane and the formatters (decision 52 in [PLAN]: tsrx-prettier-plugin: plan, decisions, and the Phase 1 queue #852).utils/ast.jsrender_children(node): the children a compiler renders, without layout whitespace, and without an empty{}that separates nothing. A{}between two texts stays, since it keeps them apart as in TSX, and so does one holding a tooling comment (// @ts-expect-error), with the line breaks around it. Core's JSX transform reads children through it at the five places that did, so compiled output is unchanged. It doesn't change the parsed tree: a compile leaves its input as it is.tsrx-prettier-plugin(private):rebuildJsxChildrenandaddJsxTextare gone (−69 lines, +23). The adapter takes the parser's children as they are and turns each brace-less{}into its comment child (markJsxComments). This is what #841 set out to do.@tsrx/prettier-plugin: no source change. Its tests compare the tree before and after a format, and now leave out layout whitespace there, as Prettier's own check of the tree does.Verification
tsrx-mcp. Typecheck,pnpm format:checkandpnpm changeset:checkpass.{}for each of several comments;isLayoutWhitespacetable;isLayoutWhitespace; the ones about children list it.render_childrencovers both.Downstream
This changes the tree Ripple, Octane and
@tsrx/oxcread, in the same release as #858. Measured with the change simulated (no downstream code changed):is_droppable_template_textat 4–6 places.normalizeAuthoredJsxLiteralsdrops the text (4 lines); then only 2 parser-shape specs change.@tsrx/oxc: drops whitespace like core did, so it has to change with core.Upgrade issues: Ripple-TS/ripple#1526 and octanejs/octane#1353 (with #858's Ripple-TS/ripple#1525 and octanejs/octane#1338), and tsrx-org/oxc#118, rewritten for the final shape.
Closes #841.
🤖 Generated with Claude Code
Note
Medium Risk
Minor AST shape change in the core parser affects formatters and downstream consumers, though compile output is guarded by render_children; parser/comment attachment behavior is complex.
Overview
Aligns @tsrx/core JSX/fragment child lists with TSX parsers: layout whitespace stays as
JSXText, and each inter-child comment becomes its own brace-lessJSXExpressionContainer+JSXEmptyExpression(comment ininnerComments). The parser also recovers tokenizer-skipped gaps after@if/@for/etc. and before the next child via#readSkippedTemplateText, fixing lost spaces/text (e.g.} // cthentwo, and trailinga /* c */inside{…}).Compiled output stays the same via new
isLayoutWhitespace(exported) andrender_children, which the JSX transform uses instead of dropping empty text at parse time. Comment-attachment metadata (CommentMetaData,elementLeadingComments,commentContainerId) is removed.tsrx-prettier-plugin drops source-based
rebuildJsxChildrenin favor ofmarkJsxCommentson the parser tree; formatter tests ignore layout whitespace when comparing AST shape (like Prettier).Reviewed by Cursor Bugbot for commit c070c15. Bugbot is set up for automated code reviews on this repo. Configure here.