Skip to content

Commit bdf721c

Browse files
committed
compat-eslint: factory DSL full migration + dogfood-corpus parity sweep
Two related pieces: ## Dogfood-corpus parity sweep (test infrastructure) Extends the existing 15-fixture bottom-up parity sweep to the dogfood corpus β€” every production .ts file in the monorepo, ~67k type asserts + ~67k parent asserts. The broader walk surfaced 10 real drift bugs (fixed below) plus 3 known scaffolding ambiguities documented as accept-skips (ChainExpression per-link, TSInterfaceHeritage missing wrapper, TSAssertClause missing wrapper). DOGFOOD_FILES extracted into a shared module so the sweep and the rule-level dogfood diff stay in lock-step. ## Drift fixes the sweep caught 1. PropertyDeclaration / MethodDeclaration / GetAccessor / TypePredicate missing from TYPE_SLOT_TRIGGERS β€” class field / method type annotations skipped the synthetic TSTypeAnnotation wrapper. 2. AssignmentPatternNode constructor didn't re-parent its inner β€” the binding identifier in `function f(x = 1)` reported parent.type === 'FunctionDeclaration' instead of 'AssignmentPattern'. 3. NamedExports / TemplateSpan missing from SKIP_AS_PARENT β€” the walker built GenericTSNode wrappers (`TSNamedExports` / `TSTemplateSpan`) where eager flattens. 4. MappedType TypeParameter scaffolding β€” typescript-estree exposes the bare iterating identifier on TSMappedType.key; lazy was building a TSTypeParameter wrapper from SHAPES dispatch. 5. ImportType argument LiteralType wrapper β€” eager flattens the `LiteralType { literal: StringLiteral }` to expose the bare StringLiteral on TSImportType.argument. 6. `typeof import('x')` β€” TSTypeQuery wraps an inner TSImportType but claims the cache slot; bottom-up materialise of the import's children needed a WRAPPER_DRILLS entry to drill TSTypeQuery.exprName. ## Factory DSL extension + class migration Extends the SHAPES factory so 88 of 95 hand-written subclasses can be defined declaratively. New DSL features: - `type: KnownEstreeType | ((tsNode) => KnownEstreeType)` β€” kinds with multiple ESTree variants (e.g. PrefixUnaryExpression β†’ UpdateExpression vs UnaryExpression based on operator). - `range: (tsNode, ctx) => [start, end]` β€” classes that customise the default tsNode-derived range (method ranges, parameter ranges, …). - `init: (instance, tsNode) => void` β€” post-construction setup needing the constructed instance: re-parenting wrapped nodes, registering extra cache entries, defining instance-level getters. - `consts(tsNode, instance)` β€” second arg lets consts callbacks read other already-set fields if needed. - `registersInMaps: (tsNode) => boolean` β€” the LazyNode-level predicate on a per-instance basis. Hybrid classes like JSXOpeningElement (real for JsxOpeningElement, synthetic for JsxSelfClosingElement) need this. - `defineShapeRouter(kind, route)` β€” context-aware dispatch. Same TS kind β†’ different ESTree class based on dispatch-time info (parent kind, modifiers, isExportEquals, allowPattern). - 3rd ctor arg `context?: ConvertContext` β€” needed for ProgramNode (root, no parent) and GenericTSNode (materialise's bottom-up fallback). Migrated classes (88 total): - Statement / control-flow: CatchClause, ForIn, ForOf, Switch (+ Case + Default), Break / Continue, Block, EmptyStatement, IfStatement, Return, While, DoWhile, For, Throw, Try, Labeled, Debugger. - Expressions: Identifier, NewExpression, Member (with chain wrap), Call (with chain wrap + import keyword router), Tagged-template, Conditional, Sequence (router), Binary-like (router on operator), Unary-like (multi-type), Spread (pattern router), Shorthand, ObjectExpression / ArrayExpression (pattern routers), Yield, Await, Template, NoSubstitutionTemplate, RegExp, Literal (Numeric / String with JSX-attribute unescape), BoolLiteral (True / False), Null. - Imports / exports (routers): Import, ImportSpecifier, ImportDefaultSpecifier, NamespaceImport, Export* (named / all / default / TS-equals via routers). - Classes: Class (router on Decl / Expr), ClassBody, MethodDefinition, ObjectMethod / ObjectAccessor (routers), PropertyDefinition with abstract / accessor variants. - TS types: TS-keyword (Any / Unknown / Number / …), Union / Intersection, ArrayType, TupleType (+ NamedTupleMember + RestType router), TypeOperator, FunctionType / ConstructorType, ConditionalType, InferType, IndexedAccessType, MappedType, LiteralType (router for null special case), Predicate, ImportType (with TSTypeQuery wrap router), QualifiedName, TypeReference, TypeAssertion / Satisfies / NonNull, Decorator, Template-literal-type, IndexSignature, TypeParameter (in regular dispatch β€” MappedType skips), Enum (+ body), Interface (+ body), TypeAlias, ParameterProperty (kept hand-written), Module*, Property / Method signatures. - JSX: JSXElement (with JsxSelfClosingElement variant), JSXOpeningElement (hybrid synthetic via registersInMaps), JSXClosingElement, JSXOpeningFragment / ClosingFragment, JSXFragment, JSXAttribute, JSXSpreadAttribute, JSXSpreadChild, JSXExpressionContainer (with empty-expression init), JSXText, JSXIdentifier, JSXMemberExpression, JSXNamespacedName. - Bindings: VariableStatement, VariableDeclaration, BindingElement (router for array / object destructure), AssignmentPattern, RestElement, ArrayBindingPattern, BindingAssignmentPattern. - Other: Program (root), TypeKeyword (synthetic helper), GenericTSNode (catch-all fallback). 7 classes remain hand-written by design β€” all are wrapper-with-extras helpers whose constructor signature documents their API: - ChainExpressionWrapping / TSTypeQueryWrapping β€” wrap a pre-built inner expression; the outer claims the TS node's cache slot. - ExportNamedWrapping / ExportDefaultWrapping β€” wrap an inner declaration with the cache re-pointed. - TSParameterProperty β€” wraps a parameter with class-property modifiers. - TSTypeParameterDeclaration / TSTypeParameterInstantiation β€” NodeArray-based, no SK to dispatch from. Net diff: -672 lines. Hand-written subclass count 95 β†’ 7 (93 % migrated). SHAPES table at 134 entries plus 16 context-aware routers. Tested: predicate-coverage / lazy-estree (15-fixture parity sweep + new dogfood-corpus sweep with ~67k asserts) / scope-compat / selector-analysis / ts-ast-scan / compat-pipeline / jsx-react-x / bench / dogfood (107 rules Γ— 30 files clean) β€” all pass. Dify cold lint within noise of master.
1 parent 7a81e2d commit bdf721c

4 files changed

Lines changed: 2204 additions & 2869 deletions

File tree

0 commit comments

Comments
Β (0)