Commit 56e6c7a
committed
test(compat-eslint): bottom-up parity sweep + phantom-types invariant
Hardens the test suite against the bug class fixed earlier in this
PR (JSXAttribute.parent corruption via phantom TSJsxAttributes).
Master's tests had three blind spots:
1. lazy-estree.test's `compare()` walks tree TOP-DOWN through child
getters, where parent is set correctly even on master. Bottom-up
`materialise(tsNode)` (what tsScanTraverse does on selector match)
was never exercised. The function also explicitly skips the
`parent` field — so even top-down parent-chain corruption would
not have failed parity.
2. compat-pipeline's JSXAttribute listener pushed `attr:${n.name}`
events but never read `n.parent`, leaving the listener-API parent
contract unverified.
3. Nothing checked the invariant "no node has a 'TS<KindName>' type
for kinds typescript-estree elides" — the property the
TSJsxAttributes regression directly violated.
Three new test blocks address each:
Bottom-up parity sweep (lazy-estree.test): 9 JSX-attribute fixtures
(self-closing, non-self-closing, spread, sibling attrs, multi-attr
mixed, fragment, nested attr value, deeply nested), each walks every
TS node, runs `lazy.materialise(tsNode, ctx)`, and compares the
resulting type / parent.type / parent.parent.type against eager's
`astMaps.tsNodeToESTreeNodeMap` lookup. Eager parents are stitched
ourselves (typescript-estree's astConverter doesn't set parent —
ESLint's SourceCode does that downstream). 117 type asserts + 108
parent asserts on the fix branch; 7 unique mismatches on master.
Phantom-types invariant (lazy-estree.test): 5 comprehensive fixtures
(jsx-attrs-everything, ts-everything, imports-everything, patterns-
everything, jsx-fragment-mix), each walks via visitor-keys and ALSO
bottom-up materialises every TS node that has an eager counterpart.
Asserts no produced type starts with 'TS' AND isn't in typescript-
estree's published TS-* type list. The published list is hard-coded
inline (~75 entries) so the test fails immediately if a future
PR-added GenericTSNode fallback emits a name not in eager's spec.
JSX listener parent assertion (compat-pipeline): test #7's
JSXAttribute / JSXSpreadAttribute listeners now also assert
`parents[0] === 'JSXOpeningElement'` — the contract any
jsx-a11y / react/jsx-* rule relies on. The contract is correct in
spec; whether each listener path independently fails on master
depends on whether sibling listeners pre-warm the cache top-down,
but the assert still locks the contract from inside the actual
ESLint listener API surface.
Out of scope (real but unrelated impedance with eager that the broad
sweep also surfaces — left as separate follow-ups):
- export wrapper identity (lazy maps the TS node to ExportNamed/
DefaultWrapper, eager maps to the inner declaration)
- chain-expression wrapping for `a?.b?.c`
- destructuring with defaults
- CatchClause param lifted from ts.VariableDeclaration shim
- TSStringKeyword / TSVoidKeyword direct-on-Signature1 parent c1ccffe commit 56e6c7a
2 files changed
Lines changed: 394 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1981 | 1981 | | |
1982 | 1982 | | |
1983 | 1983 | | |
| 1984 | + | |
| 1985 | + | |
| 1986 | + | |
| 1987 | + | |
| 1988 | + | |
| 1989 | + | |
| 1990 | + | |
| 1991 | + | |
| 1992 | + | |
| 1993 | + | |
| 1994 | + | |
| 1995 | + | |
| 1996 | + | |
| 1997 | + | |
| 1998 | + | |
1984 | 1999 | | |
1985 | 2000 | | |
1986 | 2001 | | |
1987 | 2002 | | |
| 2003 | + | |
| 2004 | + | |
| 2005 | + | |
| 2006 | + | |
| 2007 | + | |
| 2008 | + | |
| 2009 | + | |
| 2010 | + | |
| 2011 | + | |
| 2012 | + | |
| 2013 | + | |
1988 | 2014 | | |
1989 | 2015 | | |
1990 | 2016 | | |
| |||
2052 | 2078 | | |
2053 | 2079 | | |
2054 | 2080 | | |
2055 | | - | |
| 2081 | + | |
| 2082 | + | |
| 2083 | + | |
| 2084 | + | |
| 2085 | + | |
| 2086 | + | |
| 2087 | + | |
2056 | 2088 | | |
2057 | 2089 | | |
2058 | 2090 | | |
| |||
2071 | 2103 | | |
2072 | 2104 | | |
2073 | 2105 | | |
2074 | | - | |
| 2106 | + | |
| 2107 | + | |
| 2108 | + | |
| 2109 | + | |
| 2110 | + | |
2075 | 2111 | | |
2076 | 2112 | | |
2077 | 2113 | | |
| |||
0 commit comments