[Bug]: @tsrx/core's error codes are final: new codes for its errors, and Ripple's own errors have none
[!WARNING] Wait for the
@tsrx/corerelease that includes tsrx-org/tsrx#888. The codes below come with it. Switching the tests to theDIAGNOSTIC_CODESconstants (#1524) can be done now.
Issue Category
Other (upgrading @tsrx/core)
Bug Description
@tsrx/core now gives every error a code (tsrx-org/tsrx#843, merged in tsrx-org/tsrx#888). The TSRX specification lists every code in its appendix B, "Error codes":
- A mistake TypeScript also reports gets TypeScript's own code.
- A mistake only TSRX reports gets a
TSRXcode:TSRX1xxxfor markup,TSRX2xxxfor template rules,TSRX3xxxfor style blocks and CSS, andTSRX4xxxfor everything else.
What that means for Ripple:
1. DIAGNOSTIC_CODES keeps its names; the values change. Ripple's compiler compares with the constant (style-scopes.js#L573), which keeps working. Five tests compare literal strings (#1524):
| Constant | Before | After |
|---|---|---|
STYLE_APPLY_VALUE |
tsrx-style-apply-value |
TSRX3001 |
STYLE_APPLY_TARGET |
tsrx-style-apply-target |
TSRX3002 |
STYLE_APPLY_BEFORE_DECLARATION |
tsrx-style-apply-before-declaration |
TSRX3003 |
STYLE_STANDALONE_OUTSIDE_TEMPLATE |
tsrx-style-standalone-outside-template |
TSRX3008 |
STYLE_STANDALONE_NEEDS_FRAGMENT |
tsrx-style-standalone-needs-fragment |
TSRX3009 |
CSS_GLOBAL_PLACEMENT |
tsrx-css-global-placement |
TSRX3011 |
JSX_EXPRESSION_VALUE is removed, since no error used it; Ripple doesn't use it.
2. Core's errors that had no code now have one. For example:
export function App() @{
@for (let i = 0; i < 3; i++) {
<li />
}
}before code: undefined For loops are not supported in TSRX templates. Use for...of instead.
after code: TSRX2015 For loops are not supported in TSRX templates. Use for...of instead.That error comes from validateTsrxUnsupportedLoopStatement, which Ripple calls. Parser errors now carry TypeScript's code: '}' expected. is TS1005, and a redeclared name is TS2300.
3. Two kinds of parser messages now use TypeScript's wording:
- An
importorexportinside a block: acorn's'import' and 'export' may only appear at the top levelis now TypeScript's error for each kind, such asTS1232(An import declaration can only be used at the top level of a namespace or module.) orTS1184(Modifiers cannot appear here.). usingorawait usingin afor…inhead: nowTS1493andTS1494.
Nothing in Ripple matches these messages today (checked at 83ed5615).
4. Ripple's own errors have no code. Ripple's analyzer raises 36 distinct messages through error(). Core's table gives only one of them a code, await is not allowed inside components (TSRX2021). The other 35 have none. For example:
export function App() @{
<div onClick={} />
}code: undefined attributes must only be assigned a non-empty expressionThe specification says every error a conforming implementation reports carries a code. A suggestion, for Ripple to decide:
- Where Ripple's error duplicates one of core's, use core's message.
error()then gives it core's code with no code argument, and the two report the same mistake the same way. For example, an empty attribute expression is TypeScript'sTS17000(JSX attributes must only be assigned a non-empty 'expression'.). - Give the rules only Ripple has their own codes, such as the
module serverrules,trackoutside a reactive context, and the<head>rules. The prefix and numbering are Ripple's choice (for exampleRIPPLE1001), passed througherror()'scodeargument.
References
- tsrx-org/tsrx#843: the code scheme; tsrx-org/tsrx#888: the change.
- #1524: switch the tests to the constants.
@tsrx/mcpmaps the oldtsrx-*codes to the new ones, so a Ripple release still on the old codes shows the new ones there.
Source: Ripple-TS/ripple