Skip to content

fix(core): handle Unicode line terminators in templates - #1034

Merged
leonidaz merged 4 commits into
tsrx-org:mainfrom
everton-dgn:fix/unicode-line-terminators
Oct 4, 2026
Merged

leonidaz merged 4 commits into
tsrx-org:mainfrom
everton-dgn:fix/unicode-line-terminators

Conversation

@everton-dgn

@everton-dgn everton-dgn commented Oct 4, 2026 •

Copy link
Copy Markdown
Contributor

U+2028 and U+2029 were not treated as line terminators at several setup/markup boundaries and in directive and template comments. Template line comments could consume following markup. JSX text also left the parser's line state behind, shifting the locations of later tokens after CR, U+2028, or U+2029.

Use Acorn's newline classification in the affected scans and restore parser line state from the end location already computed for text. Preserve authored offsets and values, including the existing JSX whitespace and CRLF behavior.

Validation:

  • Regression coverage includes template comments, setup/markup boundaries, JSXText, raw style/script content, and Unicode. Node and comment locations are checked against Acorn's line information.
  • CI passed on Node 22, 24, and 26, including lint, typecheck, grammar checks, and changeset validation.
  • Cursor Bugbot completed without findings.

Includes a patch changeset for @tsrx/core. A backport for 0.1.63 is available separately. Its parser, return-keyword, and location suites pass 339 tests, including repeated parses with LF and CRLF layout whitespace. Another 61 compatibility cases pass. It preserves the older grammar, including rejection of comments between @if and ( and of unclosed raw-text elements.

Compiling Solid with the local parser backports accepted all 108 valid cases across DOM, SSR, and universal output and rejected all 13 invalid controls in both compilers. Solid still uses its published dependencies; adoption needs an accepted maintenance revision or release.

Use Acorn's line-terminator classification in template boundaries,
directive trivia and line comments. Keep authored text, offsets and
HTML whitespace rules unchanged.

Cover static and dynamic tags, comments, source locations, literal
values, JSX text and expression continuations across all newline forms.
@everton-dgn everton-dgn changed the title fix(core): recognize Unicode line terminators before markup fix(core): handle Unicode line terminators in templates Oct 4, 2026
leonidaz and others added 2 commits October 4, 2026 11:26
Write template-line-locations.test.js like the other test files: vitest
describe/it.each blocks and expect, not node:assert and top-level test().
Location checks compare every node's line and column in one toEqual, so
a failure shows all the wrong positions together.

Each check is the same as before, except for the raw-text case: it
checked script children only when there were any, and a <script>
element never has children (content is its only body), so it now
expects no children for <script> and one StyleSheet for <style>.

Against the parsers from main and from the first commit, the converted
file fails the same 17 tests as before (9 comment, 6 JSX text, 2
separator tests).

Also add blank lines between the it.each blocks in parser.test.js and
write the template literal with a plain backtick.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The tests for this fix were in a new describe block at the end of
parser.test.js and in a separate template-line-locations.test.js. The
test files already have a section for each of them, so put each test
there and delete the new file:

- comment after a directive keyword (tsrx-org#477) in tokenizer-context.test.js:
  a line comment after `@if` ends at any line terminator
- comments between template children: a template line comment ends at
  any line terminator, and the children after it read as usual
- the location tests, next to the shorthand attribute test across every
  JavaScript line terminator: JSXText, U+2028/U+2029 as text, and raw
  <style> and <script> content
- next to the setup-to-render `<` disambiguation tests: setup and render
  across every line terminator, and literals and `<` after U+2028/U+2029

Locations are checked as the existing location tests check them: every
node from allNodes against acorn.getLineInfo, in an expectLocations
helper that also covers comments and skips the StyleSheet (its offsets
are relative to the style body).

Against the parsers from main and from the first commit, the moved
tests fail where the old ones failed.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

@leonidaz leonidaz left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thank you!

@leonidaz
leonidaz merged commit 87dda2d into tsrx-org:main Oct 4, 2026
8 checks passed
@github-actions github-actions Bot mentioned this pull request Oct 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants