Repository navigation
fix(core): handle Unicode line terminators in templates - #1034
Merged
Merged
Conversation
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.
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]>
Merged
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.
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:
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@ifand(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.