Repository navigation
refactor(core): define each error message once, with its code, and raise and test by code - #950
Merged
Merged
Conversation
…ise by entry `diagnostics.js` now defines every message TSRX raises once, with its code: `TSRX_ERRORS` for TSRX's own codes and `TS_ERRORS` for mistakes TypeScript also reports. A message that takes values is a function of them. The parser, the analysis, the transform and the Solid, Vue and Hono targets raise these entries, or pass their code with a target's own message, instead of writing the message out and looking its code up. Only acorn's and acorn-typescript's own messages keep a lookup. Each row names the upstream functions that raise it, and a row for a message TSRX also writes points at its entry. `CHECKER_LEVEL_ERRORS` is a set of entries and lookup rows instead of messages and regular expressions, and the formatter finds a modifier before `export` by its position. The messages and codes don't change. `@tsrx/core` exports `TS_ERRORS` and `TSRX_ERRORS`; its `TSRX_*_ERROR` message exports are now the entries' messages. Refs #947 Co-Authored-By: Claude Opus 5.5 <[email protected]>
… message exports
TypeScript's TS1079 takes the modifier (`A '{0}' modifier cannot be used
with an import declaration.`), so its entry does too. The message is the
same. The `TSRX_*_ERROR` exports stay, for matching an error that has no
code, as `@tsrx/mcp` does for a compiler that reports none.
Refs #947
Co-Authored-By: Claude Opus 5.5 <[email protected]>
The tests name each error by its entry in `diagnostics.js`, or by its code for an acorn or acorn-typescript message that has none, and check its code and position. The worker parse harness gives codes, and the helpers in `tests/shared/errors.js` match a thrown error or a worker outcome by them. The style syntax fixture, which the Rust parser ports, gives plain codes. A test checks each `TS_ERRORS` entry's wording against TypeScript's diagnostic for its code, except those in acorn's, acorn-typescript's or TSRX's own wording, and another that every `TSRX_ERRORS` entry has a TSRX code. So rewording a message changes `diagnostics.js` and no other test. Refs #947 Co-Authored-By: Claude Opus 5.5 <[email protected]>
Refs #947 Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 task done
jonkwheeler
added a commit
that referenced
this pull request
Nov 12, 2026
… channel (#1294) * feat: carry diagnostic severity and codes through collected-error channel CompileError gains an optional severity ('error' | 'warning') so consumer compilers can publish warning-severity diagnostics; error() accepts it as a trailing parameter. tsrx-tsc now prints collected diagnostics in tsc convention — [tsrx-tsc] file(line,col): <error|warning> <code>: message — instead of dropping the code. The language server's compile-diagnostic plugin maps severity 'warning' to real editor warnings. Re-cut from feat/diagnostic-code-propagation (slice T-A, tracked in octanejs/octane#1204; the fatal-stub emit, exit-path, and class-map emit pins land in a follow-up). Generated with [Devin](https://devin.ai) * fix(typescript-plugin): print a parse error's position in tsrx-tsc A parse error acorn throws gives its position as `loc` itself (`{ line, column }`), not as a range with `start`, so tsrx-tsc printed it without one: `[tsrx-tsc] App.tsrx: error TS1005: '}' expected. (3:5)`. Since #888 that error carries TypeScript's code, so with its position the line now reads `App.tsrx(3,6): error TS1005: ...`, as tsc prints it. The content-mapper compatibility matrix described the classic CLI's line for a fatal error as free text without a code; it now gives the code and position. * test: pin severity and tsrx-tsc lines against the compiler's own error entries `error()` takes an error entry with its code since #950; a test checks a warning severity passes through with an entry's code. A test compiles two rest elements with an initializer with the React compiler and checks that tsrx-tsc prints each one at its own position with TS1186 (#957), where it printed one line without a position or code. * fix(core): never throw a warning-severity diagnostic `error()` throws when it has no `errors` array, which is every compile that doesn't collect, such as a Vite build. So a consumer compiler or a core check reporting `error(..., code, 'warning')` the usual way, with `collect ? errors : undefined`, failed the build on a warning. The thrown error was also fatal: the language server showed it as an error coded `tsrx-compile-error`. A warning is now only ever recorded. Without `errors`, `error()` drops it. * fix(typescript-plugin): place a pos-only diagnostic in tsrx-tsc `tsrx-tsc` read a diagnostic's position from `loc` only. A consumer compiler may give only `pos` and `end`, as the language server allows, since it places a diagnostic by `pos`. So a warning the editor showed at its place printed without one: `[tsrx-tsc] App.tsrx: warning ...`. Without `loc`, the position now comes from `pos` in the compiled source, with lines broken where tsc breaks them. * fix(typescript-plugin): print a thrown diagnostic as an error in tsrx-tsc A thrown error stops the compile, and the language server shows it as an error whatever its `severity`. `tsrx-tsc` printed one marked `severity: 'warning'` as `warning`, for a file that failed to compile. It now prints a fatal error as `error`, as the language server does. Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com> Co-Authored-By: Claude Opus 5.5 <[email protected]>
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.
Closes #947.
Each error message TSRX raises is now written once, in
diagnostics.js, together with its code. The places that raise an error use that entry, and tests check the code and the position instead of the message text. No message or code changes.For example, TypeScript's TS1048:
A message that includes a value is a function of that value, and the function has the code too:
What changes
Each point below follows the proposal in #947.
diagnostics.js.TSRX_ERRORSholds the errors with TSRX's own codes.TS_ERRORSholds the mistakes TypeScript also reports, with TypeScript's codes. Messages in acorn's or acorn-typescript's wording that TSRX raises itself, where it parses in their place, are entries too (for exampleUNEXPECTED_TOKENorMISSING_CATCH_OR_FINALLY).error()also takes an entry.plugin.jsno longer defines its own message strings. The copies intransform/jsx/index.jsandtsrx-solidare gone as well.CHECKER_LEVEL_ERRORSis aSetof entries, not of messages and regular expressions. It holds the TSRX entries, plusUPSTREAM_ERRORSfor the acorn and acorn-typescript messages the parser needs to recognize (a redeclaration,Duplicate modifier: …, and so on).// acorn: parseBreakContinueStatement). A row for a message TSRX also writes points to its entry instead of repeating the text.MESSAGE_CODESandget_error_codeare gone.[TS_ERRORS.X, 'a =']). A thrown error is checked byline:columnor offset. Collected errors are compared bycode. Helpers are intests/shared/errors.js, and the worker parse harness now returns codes. A new test inerror-codes.test.jschecks the wording of everyTS_ERRORSentry against TypeScript 5.9's diagnostic message for its code; about 20 entries are listed there as using acorn's, acorn-typescript's or TSRX's own wording. Another test checks that everyTSRX_ERRORSentry has a TSRX code. After this, rewording a message means changing onlydiagnostics.js.The formatter no longer needs
MODIFIER_BEFORE_EXPORT. A modifier placed beforeexportis now recognized as TS1029 raised at theexportkeyword.On the question #947 left open:
@tsrx/corenow exportsTS_ERRORSandTSRX_ERRORS, because the target packages in this repo raise with them.UPSTREAM_ERRORSis not exported. The existingTSRX_*_ERRORmessage exports stay, as the entries' messages.@tsrx/mcpuses them to match errors from compilers that report no code, so it is unchanged.Beyond the files the issue lists, these test files checked TSRX's message text too and were converted:
closing-brace,tokenizer-contextandexport-scope-cache, the formatter'stsrx-migratedtests, one language-server test, and one test each intsrx-reactandtsrx-vue. The style syntax fixture now givescode: 'TSRX2011'instead of the message.oxc-tsrxports that table by hand into its own test, so nothing there reads the field.Checking that nothing changed
error()and in the parser's throw path, I rantsrx-utils,tsrx-analyze,prettier-plugin, the React, Solid, Vue, Hono and Preact targets, andtsrx-mcp, before and after the source change. Both runs produced the same 272 distinct (message, code) pairs.main's lookup with the new one on a message built from each row's upstream wording (230 messages). There are 5 differences, and none can reach an editor or a build:GenericsEndWithComma,LetInLexicalBinding, and'abstract' modifier can only appear on …. TSRX still raises that last message itself, with its entry.Binding let in strict modeandAssigning to let in strict modenow look up to TS2480. Only the first of acorn's errors at a position is recorded, and that one is alwaysThe keyword 'let' is reserved, so these two are never reported.pnpm changeset:checkpasses, and the changed files are formatted.Downstream
`await` is not allowed inside components. …error calls core'serror()without a code, so today it gets TSRX2021 only because core looks the code up from the text. Once Ripple upgrades to a core release that includes this PR, that error has no code until Ripple passesDIAGNOSTIC_CODES.TARGET_AWAIT_UNSUPPORTED. I'll note this on [Bug]: @tsrx/core's error codes are final: new codes for its errors, and Ripple's own errors have none Ripple-TS/ripple#1529, which already covers Ripple giving its own errors codes.Findings
let a; let a;) is TS2300, where TypeScript says TS2451. A private name outside any class (this.#y) is TS1111, where TypeScript says TS18016. The lookup already had rows with TypeScript's codes, but a broader pattern inMESSAGE_CODESmatched first, so those rows never applied. This PR keeps the codes as they were and removes the rows that never applied.How the comparisons were run
The logging was one line in
errors.jsand one in#throwError, and was removed before committing:For the lookup, a script imported
main'sdiagnostics.jsand this branch's, built a message from each// acorn: …or// acorn-typescript: …template inmain's table (plus the messages cut short in those comments), and comparedget_error_code(message)withget_upstream_error(message)?.code.🤖 Generated with Claude Code
Note
Medium Risk
Touches error reporting across parser, transform, and multiple packages; behavior is intended to be unchanged but any missed raise site could lose a diagnostic code.
Overview
Centralizes TSRX compile errors in
@tsrx/coreasTSRX_ERRORS(TSRX codes) andTS_ERRORS(TypeScript-aligned codes), each{ code, message }or a parameterized factory.error()now accepts these entries directly; raise sites across the parser, analysis, transform, scope, and Solid/Vue/Hono targets pass entries (or explicit codes) instead of duplicating strings and relying on message→code lookup.diagnostics.jsreplaces the oldMESSAGE_CODES/get_error_codetables with structured entries,UPSTREAM_ERRORS, andget_upstream_error/upstream_diagnosticfor acorn/acorn-typescript messages only. LegacyTSRX_*_ERRORexports remain as aliases to entry messages for backward compatibility.Tests and tooling assert codes and positions (shared
error_with/expect_reportedhelpers) rather than full message text; the Prettier plugin detects modifier-before-exportvia TS1029 + source position instead of a message regex.Reviewed by Cursor Bugbot for commit c3e4a31. Bugbot is set up for automated code reviews on this repo. Configure here.