Skip to content

fix: report a CSS syntax error and a thrown parse error at their position (#1306, #1308) - #1344

Merged
jonkwheeler merged 3 commits into
tsrx-org:mainfrom
jonkwheeler:w13/e-1306-1308-error-positions
Nov 14, 2026
Merged

jonkwheeler merged 3 commits into
tsrx-org:mainfrom
jonkwheeler:w13/e-1306-1308-error-positions

Conversation

@jonkwheeler

@jonkwheeler jonkwheeler commented Nov 14, 2026 •

Copy link
Copy Markdown
Contributor

Summary

A syntax error the TSRX parser throws now reaches every tool at its line and column.

  • CSS in a <style> block ([Bug]: tsrx-core: a CSS syntax error in a <style> block has no position, and the editor doesn't report it #1306). A CSS syntax error (TSRX3013) was a plain Error with no position, and the loose compile the editor runs dropped it. The CSS parser now records where it stopped, parseStyle gives the error pos (and loc for a sheet with a body origin, which every sheet parseModule makes has), and the parser throws it there, in a strict and a collecting parse. A loose parse records it and keeps the rules before it, as it already kept them; an unclosed <style>, whose body is still being typed, gets its TSRX1001 alone.
  • ESLint ([Bug]: eslint-parser: a syntax error the TSRX parser throws is reported at 0:0, with its position only in the message #1308). @tsrx/eslint-parser gave ESLint a line and column only for a recorded unclosed or mismatched tag, read from loc.start. An error the parser throws has acorn's flat loc { line, column }, so it was wrapped as Failed to parse TSRX file: … and ESLint showed it at 0:0. to_eslint_parse_error now reads both shapes (and pos when there is no loc), drops acorn's (line:column) from the message, and sets index from pos, which TSRX errors carry, instead of start. An error with no position at all keeps the Failed to parse TSRX file: wrapper.

The two issues share their CSS row: #1308 lists the stray } in a <style> body, which has no position until #1306's change, and #1306's ESLint row needs #1308's change.

Before / after

<style> body with a stray } (.a { color: red; } then } on its own line, line 5, column 3) in a template, @tsrx/react:

Path main (8d2b839) This PR
compile Error: Expected identifier, code: 'TSRX3013', no loc or pos SyntaxError: Expected identifier (5:3), code: 'TSRX3013', loc { line: 5, column: 3 }, pos: 67
compile with collect: true the same, no position the same, at 5:3
compile with loose: true, compile_to_volar_mappings loose no error TSRX3013 Expected identifier at 5:3 (pos 67, end 68)
Language server (compileErrorDiagnosticPlugin) nothing TSRX3013 on the opening tag's > (the editor's code has no <style> body, so an error on a body line with no code shows on the nearest code before it); on the } itself for a one-line <style> (export const a = <style>.a { color: red; } }</style>;)
TypeScript 7 (@tsrx/content-mapper on the native language server) nothing TSRX3013 on the } itself
Prettier Expected identifier, no location Expected identifier (5:4), loc { start: 5:4 }
ESLint 10.3.0 0:0 Parsing error: Failed to parse TSRX file: Expected identifier 5:4 Parsing error: Expected identifier

A missing } (.a { color: red; then </style>) is reported the same way at the end of the rule, Expected } (4:19) (ESLint and Prettier 4:20).

ESLint 10.3.0, the rows of #1308:

Source main This PR
const a = ; 0:0 … Failed to parse TSRX file: Unexpected token (2:11) 2:12 Parsing error: Unexpected token
return (\n<div>\n); 0:0 … Unexpected token (5:0) 5:1 Parsing error: Unexpected token
return <div>{props.x ? <b> : null}</div>; 0:0 … Unexpected token (2:34) 2:35 Parsing error: Unexpected token
return [<div>]; 0:0 … Unexpected token (3:0) 3:1 Parsing error: Unexpected token
<style> body with a stray } 0:0 … Failed to parse TSRX file: Expected identifier 5:4 Parsing error: Expected identifier
return <div>{<b>}</div>; (recorded TSRX1001) 2:16 Parsing error: Unclosed tag '<b>'. … the same

Tests

  • packages/tsrx/tests/utils/parser.test.js: three CSS errors (a stray } in a template and outside one, a missing }) throw TSRX3013 at the CSS that fails, with acorn's loc and message suffix, in a strict and a collecting parse; a loose parse records each at its offset and keeps the rules before it; an unclosed <style> with partial CSS records only TSRX1001.
  • packages/tsrx/tests/utils/style-parse.test.js: parseStyle gives pos in the body without a body origin, and pos and loc in the file with one.
  • Shared compile harness: the editor's compile reports the CSS error at its offset on React, Preact, Solid, Vue, Hono and @tsrx/hono/dom.
  • Language server: the CSS error is shown, with the placements in the table.
  • Prettier plugin: both CSS errors are reported at their line and 1-based column.
  • packages/eslint-parser/tests/index.test.ts: four JavaScript syntax errors (const a = ;, let b = 1 +;, a missing comma in an object, if (a {) and the stray } in a <style> body reach Linter#verify at their line and column with the bare message, and a thrown error gets its offset as index. The test doesn't use the three markup rows of [Bug]: eslint-parser: a syntax error the TSRX parser throws is reported at 0:0, with its position only in the message #1308: fix(core): report an unclosed tag without a later error from the code after it #1353 ([Bug]: tsrx-core: for some unclosed tags, the editor, Prettier or ESLint show a later error (Unexpected token, Expected identifier, '}' expected) instead of TSRX1001 #1305) makes a collecting parse record those as TSRX1001 instead of throwing at the code after them, and ESLint already reports a recorded TSRX1001 at its place.
  • Mutation: with the source of both fix commits reverted and the tests kept, 23 of the 24 new tests fail (core parser 8, ESLint parser 6, the editor test on each of the six targets, language server 2, Prettier 1). The one that passes is the unclosed <style> case, which pins what main already does in a loose parse.
  • Full vitest run (225 files, 14,213 passed, 102 skipped), format:check, typecheck and changeset:check pass locally.

Codex (gpt-5.6-sol) reviewed both commits (8812893, acfc947) and found no bugs or regressions. It checked that the strict-then-loose parse gives a loose parse the same sheet for valid CSS, the unclosed <style> case in collect and loose modes, positions at the end of input and with CRLF, a <style> in <head>, the message suffix stripping, and the changesets.

Fixes #1306
Fixes #1308

🤖 Generated with Claude Code

https://claude.ai/code/session_01FRKmwAwuyPbGQ1ejNqiJ46


Note

Medium Risk
Touches the core TSRX parser, <style> compile paths, and ESLint’s fatal parse error contract, so mis-positioned or double-reported errors could affect editor, build, and lint UX.

Overview
TS/CSS and ESLint now surface parser-thrown syntax errors at real line and column instead of silent drops or 0:0.

In parseStyle / <style> handling, CSS failures (TSRX3013) get pos and file loc when the style body origin is known. Strict compiles throw at that offset; the editor’s loose compile records the error and keeps valid rules above it, while an unclosed <style> still only reports TSRX1001.

@tsrx/eslint-parser reworks to_eslint_parse_error so thrown JS/CSS errors map pos/loc (including deriving location from source when needed), set index, strip acorn’s (line:column) suffix from messages, and throw positioned SyntaxErrors instead of the generic Failed to parse TSRX file: at 0:0.

Coverage is extended in core, ESLint, Prettier, language-server, and shared compile tests for both CSS-in-style and typical JS parse mistakes.

Reviewed by Cursor Bugbot for commit dfcbc2c. Bugbot is set up for automated code reviews on this repo. Configure here.

jonkwheeler and others added 3 commits November 13, 2026 17:35
A CSS syntax error (TSRX3013) was a plain `Error` with no position, so a
build, Prettier and ESLint gave it no line or column, and the loose
compile the editor runs dropped it while keeping the rules before it.
The CSS parser now records where it stopped, `parseStyle` gives the error
that position (`pos`, and `loc` with a `body` origin), and the parser
throws it there, collecting too. A loose parse records it and keeps the
rules before it, as it did; an unclosed `<style>`, still being typed,
gets its TSRX1001 alone.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
ESLint reads a parser error's `lineNumber` and `column`, which the parser
set only for a recorded unclosed or mismatched tag, from `loc.start`. A
syntax error the TSRX parser throws has acorn's flat `loc { line, column }`,
so it was wrapped as `Failed to parse TSRX file: …` with no position and
ESLint showed it at 0:0. Read both shapes (and `pos` when there's no
`loc`), drop acorn's `(line:column)` from the message, and set `index`
from `pos`, which TSRX errors carry, not `start`.

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

Three of the sources came from tsrx-org#1308's table: an unclosed `<div>` or `<b>`
that a collecting parse can't recover, so it throws TS1012 at the code
after it. tsrx-org#1305's open fix records those as TSRX1001 instead, which ESLint
already reports at its place, so they wouldn't keep testing a thrown
error. Use JavaScript syntax errors that a collecting parse throws.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01FRKmwAwuyPbGQ1ejNqiJ46
@jonkwheeler
jonkwheeler marked this pull request as ready for review November 14, 2026 13:52
@jonkwheeler
jonkwheeler merged commit 760f9fe into tsrx-org:main Nov 14, 2026
9 checks passed
jonkwheeler added a commit to jonkwheeler/tsrx that referenced this pull request Nov 14, 2026
tsrx-org#1344 on main parses a <style> body strictly and, on a CSS syntax
error, throws it or records it and reparses loosely. This branch parsed
an unclosed <style>'s partial body loosely. Keeps tsrx-org#1344's handling and
treats an unclosed <style> like a loose parse there: it gets its TSRX1001
alone, in every mode. Keeps both sides' new tests in the ESLint parser
and Prettier plugin test files.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01FRKmwAwuyPbGQ1ejNqiJ46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant