[错误]: @tsrx/core 的错误代码是最终的: 其错误有新的代码,而 Ripple 的自身错误没有任何代码
@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 TSRX code: TSRX1xxx for markup, TSRX2xxx for template rules, TSRX3xxx for style blocks and CSS, and TSRX4xxx for 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: tsrx export function App() @ { @ for (let i = 0; i < 3; i++) { <li /> } } | text | 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 import or export inside a block: acorn's 'import' and 'export' may only appear at the top level is now TypeScript's error for each kind, such as TS1232 (An import declaration can only be used at the top level of a namespace or module.) or TS1184 (Modifiers cannot appear here.). - using or await using in a for…in head: now TS1493 and TS1494. 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: tsrx export function App() @ { <div onClick={} /> } | text | code: undefined | attributes must only be assigned a non-empty expression |
内容来源: Ripple-TS/ripple