goccia:ast's comments holds the comments the JSX transformer removes
Date: 2026-12-01
Area: runtime, source pipeline
Supersedes: ADR 0118's consequence that comments the transformer removes are
not reported, and ADR 0163's that comments is unchanged
when they became tokens; their other decisions stand.
Related: #2441,
#2440
Context
With jsx: true, the JSX transformer rewrites the text before the lexer sees it. Two kinds of comment do not survive
the rewrite: one between attributes (<div /* why */ id="b" />, or the // biome-ignore … line above an attribute),
and one in a child container that holds nothing else ({/* note */}). An attribute list becomes one object literal
and an empty container contributes no argument, so neither has a place in the output.
ADR 0118 recorded them as missing from comments. ADR 0163 had the transformer record them as tokens and left
comments as it was. So comments, which docs/built-ins-ast.md describes as every comment, lacked them, and a tool
that needed every comment had to ask for tokens. Across 2,906 TypeScript and TSX files of one codebase, the two lists
differed in 87 files, all .tsx, and asking for tokens cost most of that tool's run (#2440).
Decision
commentsholds every comment of the file. The transformer records the comments it removes, in the file's offsets, through an opt-in sink beside its token sink, when the run asks for comments.goccia:astmerges them with the lexer's comments, mapped back to the file, in source order. Each has its kind, range andloc, as a lexed one does.- The comment tokens are the comments. With
tokens, the line and block comment tokens come from that merged list, so their ranges are the comments' ranges. A hashbang stays a token only, as before. The transformer's token sink holds no comments. - A comment in an attribute's expression counts once. An attribute expression is transformed on its own; the comments its transform removes, such as one between the attributes of an element nested in the expression, are shifted into the file's offsets as its tokens are.
Consequences
- A tool that reads comments needs neither
tokensnor a token filter. - The source pipeline's
Commentsstay in the parsed text's offsets, andJSXCommentsis a second list in the file's offsets. Onlygoccia:astreads either, throughOriginalComments, which merges them. - Without
jsx, or when the transformer rewrote nothing, the list is the lexer's, as before.