Repository navigation
feat(core): give every error a TypeScript or TSRX code (#843) - #888
Merged
Merged
Conversation
A mistake TypeScript also reports carries TypeScript's code; a mistake only TSRX reports carries a TSRX1xxx (markup), TSRX2xxx (template rules), TSRX3xxx (style/CSS) or TSRX4xxx (other) code. Every code is listed in the specification's appendix B. An import or export inside a block is reported with TypeScript's error for its kind. tsrx-prettier-plugin rejects by code the mistakes Prettier's typescript parser rejects. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Contributor
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.
Bugbot Autofix prepared a fix for the issue found in the latest run.
- ✅ Fixed: Message table assigns wrong TS codes
- MESSAGE_CODES now maps import-attribute values to TS2858, matches only an exact Unexpected token for TS1012 so raw JSX > and } reach TS1382, and limits the .mts/.cts pattern to the trailing-comma form so an as assertion reaches TS7059.
Or push these changes by commenting:
@cursor push bb4102bd5c
Preview (bb4102bd5c)
diff --git a/packages/tsrx/src/diagnostics.js b/packages/tsrx/src/diagnostics.js
--- a/packages/tsrx/src/diagnostics.js
+++ b/packages/tsrx/src/diagnostics.js
@@ -276,7 +276,10 @@
['A rest parameter cannot have an initializer.', 'TS1048'],
['A rest parameter cannot be optional.', 'TS1047'],
['A binding pattern parameter cannot be optional in an implementation signature.', 'TS2463'],
- [/^This syntax is reserved in files with the \.mts or \.cts extension\. /, 'TS7060'],
+ [
+ /^This syntax is reserved in files with the \.mts or \.cts extension\. Add a trailing comma/,
+ 'TS7060',
+ ],
["'readonly' type modifier is only permitted on array and tuple literal types.", 'TS1354'],
["'abstract' modifier can only appear on a class, method, or property declaration.", 'TS1242'],
[
@@ -301,10 +304,10 @@
['for-of loop variable declaration may not have an initializer', 'TS1190'],
['Missing catch or finally clause', 'TS1472'],
['Multiple default clauses', 'TS1113'],
- ['Only string is supported as an attribute value', 'TS1145'],
+ ['Only string is supported as an attribute value', 'TS2858'],
['value should be either an expression or a quoted text', 'TS1145'],
['Unterminated JSX contents', 'TS17008'],
- [/^Unexpected token\b/, 'TS1012'],
+ [/^Unexpected token$/, 'TS1012'],
];
/**You can send follow-ups to the cloud agent here.
Reviewed by Cursor Bugbot for commit 197811a. Configure here.
…es (#843) Broad patterns in MESSAGE_CODES caught acorn-typescript messages before their exact entries: an import attribute value got TS1145 instead of TS2858, the .mts/.cts `as` message TS7060 instead of TS7059, and the JSX `>`/`}` hint TS1012 instead of TS1382/TS1381. Regenerate the RuleSync outputs, which CI found out of date. Co-Authored-By: Claude Opus 5.5 <[email protected]>
This was referenced Sep 27, 2026
This was referenced Sep 27, 2026
thejackshelton
added a commit
to tsrx-org/yuku
that referenced
this pull request
Sep 27, 2026
…gives them Errors now carry @tsrx/core's codes (tsrx-org/tsrx#888): TSRX1001, TSRX1004 and TSRX2014 replace tsrx-unclosed-tag, tsrx-script-end-tag-in-body and tsrx-dynamic-tag-expression, and a mistake TypeScript also reports gets TypeScript's code (TS2300, TS2304, TS1005, ...), from one message table in core-compat.js that parse(), analyze() and the site's wasm host share. A thrown unclosed tag and a spread or empty dynamic tag carry their code, as core's now do.
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 #843.
Every error
@tsrx/corereports now has a code:TSRXcode in four ranges:TSRX1xxxfor markup,TSRX2xxxfor template rules,TSRX3xxxfor style blocks and CSS, andTSRX4xxxfor everything else.The specification's new appendix B lists them all: B.1 has the 52 TSRX codes with an example each, and B.2 has the 175 TypeScript codes with TypeScript's message for each.
What changes
if (a) {'}' expected.TS1005let a = 1; let a = 2;Identifier 'a' has already been declaredTS2300const a = <div></span>;Expected closing tag to match opening tag. …tsrx-mismatched-closing-tagTSRX1002<div>@if (x) <b /></div>Expected `{` after JSX control-flow directive.TSRX1008@{ <a /> <b /> }A code block renders a single node; …TSRX2011<style apply={a} />,anot a style block'a' is not a style block. …tsrx-style-apply-targetTSRX3002<style>p { color: red; </style>Expected }TSRX3013DIAGNOSTIC_CODES: every name keeps its name and gets the new value.JSX_EXPRESSION_VALUEis gone, since no error used it.get_error_codeindiagnostics.js):MESSAGE_CODEScovers TSRX's own messages and core's TypeScript-worded ones.PARSER_MESSAGE_CODEScovers all 204 acorn and acorn-typescript messages. 140 of them map to TypeScript's code. The 6 that TypeScript accepts, such as a duplicate import attribute key, map toTSRX4003.errors.jserror()or the parser'sraise, both of which set the code.Expected `for` after `@`.andExpected `@if`, `@for`, `@switch`, or `@try`.) could not be reached, because the parser reads a directive only after checking the word. The codes after it moved down by one. None of them had been released.validateTsrxUnsupportedLoopStatement(used by Ripple) raised four messages with no code. They are nowTSRX2015, the same mistake asTSRX `@for` currently supports `for...of` loops.tryerrors pass their codes.An import or export inside a block
acorn reports all of these with one message,
'import' and 'export' may only appear at the top level. TypeScript uses a separate error for each kind. Core now reports TypeScript's error, with the same code and position as TypeScript:import a from 'a',import a = require('a'),export import a = bTS1232An import declaration can only be used at the top level of a namespace or module.export { f },export * from 'a',export type { a }TS1233An export declaration can only be used at the top level of a namespace or module.export = fTS1231An export assignment must be at the top level of a file or module declaration.export as namespace ATS1316Global module exports may only appear at top level.export default 1TS1258A default export must be at the top level of a file or module declaration.export namespace N {},export declare module M {}TS1235A namespace declaration is only allowed at the top level of a namespace or module.export const a = 1,export default class {}TS1184Modifiers cannot appear here.Also,
usingandawait usingin afor…inhead use TypeScript's messages, TS1493 and TS1494.tsrx-prettier-plugin: rejects exactly what Prettier rejects
Important
This part changes what the formatter accepts. Please review it.
REJECTED_MISTAKES(16 message patterns) is nowREJECTED_CODES, a set of codes. The old list used a different rule: refuse any input whose tree drops something, even where Prettier formats it. Several codes cover inputs on both sides of that rule, so a code set can't express it:declare declare class(rejected before) andreadonly readonly a(formatted before).public classin a block (rejected before) andexport constin a block (formatted before).So the set follows the 2026-09-27 direction to match Prettier exactly: it is the codes of the recorded mistakes that Prettier's
typescriptparser rejects. I ran every recorded mistake through Prettier to build it.Formatted now as Prettier formats them (rejected before). Prettier's tree has no place for these either, so both leave them out:
function f(...a = []) {}function f(...a) {}declare declare class A {}declare class A {}function f() { public class A {} }function f() { class A {} }declare import x from "m";import x from "m";Rejected now as Prettier rejects them (formatted before):
class A { @dec constructor() {} }Decorators can't be used with a constructor. …function f(private a) {},type F = (public x: number) => voidA parameter property is only allowed in a constructor implementation.class A { constructor(public [a]: number[]) {} }A parameter property may not be declared using a binding pattern.import.source("x")The only valid meta property for import is 'import.meta'One exception: TS1039, an initializer in an ambient context, stays out of the set. Prettier rejects
declare let x = 1but formatsdeclare class A { x = 1 }, and both have the same code. The plugin formats both, as it did before.Downstream
The code values change, so Ripple, Octane and oxc need to know. I'll update Ripple-TS/ripple#1524, octanejs/octane#1337 and tsrx-org/oxc#117 with the final codes once this PR is reviewed.
@tsrx/mcpmaps the oldtsrx-*codes a target might still report (Ripple today) to the new ones.Side issues filed
.tsfile gets the.mts/.ctserror (TS7060) when collecting.import type a, { b }is accepted (TypeScript's TS1363) #881:import type a, { b }is accepted (TS1363).a?.<T>c`` throws "Unexpected token (1:NaN)" #884:a?.<T>`c`throwsUnexpected token (1:NaN)."use server"allows top-levelawait, but nothing checks for the directive.Verification
error()and atparseModule's exit across the full suite (11,553 tests), and none was left. An earlier pass found acorn's recoverable errors, such asPrivate field '#x' must be declared in an enclosing class, thrown without a code; the second commit fixes that.MESSAGE_CODESpatterns catching acorn-typescript messages before their exact entries. The third commit removes them: an import attribute value now gets TS2858, the.mts/.ctsasmessage TS7059, and the JSX hint TS1382 for>and TS1381 for}. A test checks them.packages/tsrx/tests/utils/error-codes.test.jscovers the parser and analysis codes, a set of TypeScript codes, and that every code is listed in the specification.packages/tsrx-react/tests/error-codes.test.jscovers the codes only a target's transform reports.typescriptparser. Four still differ, all tracked in [Bug]: tsrx-core: A modifier before a class static block throws, and a decorator before one is accepted #885 and [Bug]: tsrx-core: TS2369 isn't reported for a parameter property on a method, setter or constructor overload #886.pnpm test(11,553 passed),pnpm typecheckandpnpm formatpass.🤖 Generated with Claude Code
Note
Medium Risk
Public diagnostic code values change across the ecosystem (editors, MCP, formatters), and prettier-plugin acceptance rules shift for some syntax errors; core/parser error mapping is broad and affects all compile paths.
Overview
Assigns a stable diagnostic code to every compile error: TypeScript
TS####codes when the mistake matches TypeScript (including acorn/acorn-typescript wording), andTSRX1xxx–TSRX4xxxfor TSRX-only issues, replacing the oldtsrx-*string codes.DIAGNOSTIC_CODESkeeps the same keys with new values;JSX_EXPRESSION_VALUEis removed.Core adds
get_error_codevia largeMESSAGE_CODES/PARSER_MESSAGE_CODEStables, auto-attaches codes inerror()and parserraise, maps nested import/export in blocks to TypeScript’s per-kind errors (not acorn’s generic top-level message), uses TS1493/TS1494 forusinginfor…in, and tags CSS parse failures asTSRX3013. Solid passes codes for its two templatetryerrors.@tsrx/mcpnormalizes legacytsrx-*codes from older compilers; docs, spec appendix B, and agent rules reference the new codes.tsrx-prettier-pluginswitches from message-pattern rejection to a TypeScript code set aligned with what Prettier’stypescriptparser rejects (behavior change for some modifier/decorator cases). Newerror-codestests assert codes end-to-end and that every code appears in the specification.Reviewed by Cursor Bugbot for commit e48e1a2. Bugbot is set up for automated code reviews on this repo. Configure here.