|
| 1 | +/** |
| 2 | + * This file augments the `estree` types to include types that are not built-in to `estree` or `estree-jsx`. |
| 3 | + * This is necessary because the `estree` types are used by ESLint, and ESLint does not natively support |
| 4 | + * TypeScript or Flow types. Since we're not using a ton of them, we can just add them here, rather than |
| 5 | + * installing typescript estree or flow estree types. |
| 6 | + * |
| 7 | + * This also adds support for the AST mutation that the Exhaustive deps rule does to add parent nodes. |
| 8 | + */ |
| 9 | +declare module 'estree' { |
| 10 | + // The Exhaustive deps rule mutates the AST to add parent nodes for efficient traversal. |
| 11 | + // We need to augment the `estree` types to support that. |
| 12 | + interface BaseNode { |
| 13 | + parent?: Node; |
| 14 | + } |
| 15 | + |
| 16 | + // Adding types that aren't built-in to estree or estree-jsx. |
| 17 | + // Namely, the specific TS and Flow types that we're using. |
| 18 | + interface AsExpression extends BaseExpression { |
| 19 | + type: 'AsExpression'; |
| 20 | + expression: Expression | Identifier; |
| 21 | + } |
| 22 | + |
| 23 | + interface OptionalCallExpression extends BaseCallExpression { |
| 24 | + type: 'OptionalCallExpression'; |
| 25 | + } |
| 26 | + |
| 27 | + interface OptionalMemberExpression extends MemberExpression { |
| 28 | + type: 'OptionalMemberExpression'; |
| 29 | + } |
| 30 | + |
| 31 | + interface TSAsExpression extends BaseExpression { |
| 32 | + type: 'TSAsExpression'; |
| 33 | + expression: Expression | Identifier; |
| 34 | + } |
| 35 | + |
| 36 | + interface TSTypeQuery extends BaseNode { |
| 37 | + type: 'TSTypeQuery'; |
| 38 | + exprName: Identifier; |
| 39 | + } |
| 40 | + |
| 41 | + interface TSTypeReference extends BaseNode { |
| 42 | + type: 'TSTypeReference'; |
| 43 | + typeName: Identifier; |
| 44 | + } |
| 45 | + |
| 46 | + interface TypeCastExpression extends BaseExpression { |
| 47 | + type: 'TypeCastExpression'; |
| 48 | + expression: Expression | Identifier; |
| 49 | + } |
| 50 | + |
| 51 | + // Extend the set of known Expression types |
| 52 | + interface ExpressionMap { |
| 53 | + AsExpression: AsExpression; |
| 54 | + OptionalCallExpression: OptionalCallExpression; |
| 55 | + OptionalMemberExpression: OptionalMemberExpression; |
| 56 | + TSAsExpression: TSAsExpression; |
| 57 | + TypeCastExpression: TypeCastExpression; |
| 58 | + } |
| 59 | + |
| 60 | + // Extend the set of known Node types |
| 61 | + interface NodeMap { |
| 62 | + AsExpression: AsExpression; |
| 63 | + OptionalCallExpression: OptionalCallExpression; |
| 64 | + OptionalMemberExpression: OptionalMemberExpression; |
| 65 | + TSAsExpression: TSAsExpression; |
| 66 | + TSTypeQuery: TSTypeQuery; |
| 67 | + TSTypeReference: TSTypeReference; |
| 68 | + TypeCastExpression: TypeCastExpression; |
| 69 | + } |
| 70 | +} |
0 commit comments