|
| 1 | +import type { TSESTree as ES, AST_NODE_TYPES } from "@typescript-eslint/types" |
| 2 | +import type { |
| 3 | + AstroFragment, |
| 4 | + AstroHTMLComment, |
| 5 | + AstroShorthandAttribute, |
| 6 | + AstroTemplateLiteralAttribute, |
| 7 | +} from "./astro" |
| 8 | +import type { BaseNode } from "./base" |
| 9 | + |
| 10 | +export type JSXNode = |
| 11 | + | JSXAttribute |
| 12 | + | JSXClosingElement |
| 13 | + | JSXClosingFragment |
| 14 | + | JSXElement |
| 15 | + | JSXEmptyExpression |
| 16 | + | JSXExpressionContainer |
| 17 | + | JSXFragment |
| 18 | + | JSXIdentifier |
| 19 | + | JSXMemberExpression |
| 20 | + | JSXNamespacedName |
| 21 | + | JSXOpeningElement |
| 22 | + | JSXOpeningFragment |
| 23 | + | JSXSpreadAttribute |
| 24 | + | JSXSpreadChild |
| 25 | + | JSXText |
| 26 | +export type JSXChild = |
| 27 | + | JSXElement |
| 28 | + | JSXFragment |
| 29 | + | JSXExpression |
| 30 | + | JSXText |
| 31 | + | AstroHTMLComment |
| 32 | +export type JSXParentNode = JSXElement | JSXFragment | AstroFragment |
| 33 | +/* --- Tags --- */ |
| 34 | +export interface JSXElement extends BaseNode { |
| 35 | + type: AST_NODE_TYPES.JSXElement |
| 36 | + openingElement: JSXOpeningElement |
| 37 | + closingElement: JSXClosingElement | null |
| 38 | + children: JSXChild[] |
| 39 | + parent?: JSXParentNode |
| 40 | +} |
| 41 | +export interface JSXFragment extends BaseNode { |
| 42 | + type: AST_NODE_TYPES.JSXFragment |
| 43 | + openingFragment: JSXOpeningFragment |
| 44 | + closingFragment: JSXClosingFragment |
| 45 | + children: JSXChild[] |
| 46 | + parent?: JSXParentNode |
| 47 | +} |
| 48 | +export interface JSXOpeningElement extends BaseNode { |
| 49 | + type: AST_NODE_TYPES.JSXOpeningElement |
| 50 | + typeParameters?: ES.TSTypeParameterInstantiation |
| 51 | + selfClosing: boolean |
| 52 | + name: JSXTagNameExpression |
| 53 | + attributes: ( |
| 54 | + | JSXAttribute |
| 55 | + | JSXSpreadAttribute |
| 56 | + | AstroShorthandAttribute |
| 57 | + | AstroTemplateLiteralAttribute |
| 58 | + )[] |
| 59 | + parent?: JSXElement |
| 60 | +} |
| 61 | +export interface JSXClosingElement extends BaseNode { |
| 62 | + type: AST_NODE_TYPES.JSXClosingElement |
| 63 | + name: JSXTagNameExpression |
| 64 | + parent?: JSXElement |
| 65 | +} |
| 66 | +export interface JSXClosingFragment extends BaseNode { |
| 67 | + type: AST_NODE_TYPES.JSXClosingFragment |
| 68 | + parent?: JSXFragment |
| 69 | +} |
| 70 | +export interface JSXOpeningFragment extends BaseNode { |
| 71 | + type: AST_NODE_TYPES.JSXOpeningFragment |
| 72 | + parent?: JSXFragment |
| 73 | +} |
| 74 | + |
| 75 | +/* --- Attributes --- */ |
| 76 | +export interface JSXAttribute extends BaseNode { |
| 77 | + type: AST_NODE_TYPES.JSXAttribute |
| 78 | + name: JSXIdentifier | JSXNamespacedName |
| 79 | + value: JSXExpression | ES.Literal | null |
| 80 | + parent?: JSXOpeningElement |
| 81 | +} |
| 82 | +export interface JSXSpreadAttribute extends BaseNode { |
| 83 | + type: AST_NODE_TYPES.JSXSpreadAttribute |
| 84 | + argument: ES.Expression |
| 85 | + parent?: JSXOpeningElement |
| 86 | +} |
| 87 | + |
| 88 | +/* --- Names --- */ |
| 89 | +export type JSXTagNameExpression = |
| 90 | + | JSXIdentifier |
| 91 | + | JSXMemberExpression |
| 92 | + | JSXNamespacedName |
| 93 | +export interface JSXIdentifier extends BaseNode { |
| 94 | + type: AST_NODE_TYPES.JSXIdentifier |
| 95 | + name: string |
| 96 | + parent?: |
| 97 | + | JSXAttribute |
| 98 | + | AstroShorthandAttribute |
| 99 | + | AstroTemplateLiteralAttribute |
| 100 | + | JSXMemberExpression |
| 101 | + | JSXNamespacedName |
| 102 | + | JSXOpeningElement |
| 103 | + | JSXClosingElement |
| 104 | +} |
| 105 | +export interface JSXMemberExpression extends BaseNode { |
| 106 | + type: AST_NODE_TYPES.JSXMemberExpression |
| 107 | + object: JSXTagNameExpression |
| 108 | + property: JSXIdentifier |
| 109 | + parent?: JSXMemberExpression | JSXOpeningElement | JSXClosingElement |
| 110 | +} |
| 111 | +export interface JSXNamespacedName extends BaseNode { |
| 112 | + type: AST_NODE_TYPES.JSXNamespacedName |
| 113 | + namespace: JSXIdentifier |
| 114 | + name: JSXIdentifier |
| 115 | + parent?: |
| 116 | + | JSXAttribute |
| 117 | + | AstroShorthandAttribute |
| 118 | + | AstroTemplateLiteralAttribute |
| 119 | + | JSXMemberExpression |
| 120 | + | JSXOpeningElement |
| 121 | + | JSXClosingElement |
| 122 | +} |
| 123 | + |
| 124 | +/* --- Expressions --- */ |
| 125 | +export type JSXExpression = JSXExpressionContainer | JSXSpreadChild |
| 126 | +export interface JSXExpressionContainer extends BaseNode { |
| 127 | + type: AST_NODE_TYPES.JSXExpressionContainer |
| 128 | + expression: ES.Expression | JSXEmptyExpression |
| 129 | + parent?: |
| 130 | + | JSXAttribute |
| 131 | + | AstroShorthandAttribute |
| 132 | + | AstroTemplateLiteralAttribute |
| 133 | + | JSXParentNode |
| 134 | +} |
| 135 | +export interface JSXSpreadChild extends BaseNode { |
| 136 | + type: AST_NODE_TYPES.JSXSpreadChild |
| 137 | + expression: ES.Expression |
| 138 | + parent?: JSXAttribute | JSXParentNode |
| 139 | +} |
| 140 | +export interface JSXEmptyExpression extends BaseNode { |
| 141 | + type: AST_NODE_TYPES.JSXEmptyExpression |
| 142 | + parent?: JSXExpressionContainer |
| 143 | +} |
| 144 | + |
| 145 | +/* --- Texts --- */ |
| 146 | +export interface JSXText extends BaseNode { |
| 147 | + type: AST_NODE_TYPES.JSXText |
| 148 | + value: string |
| 149 | + raw: string |
| 150 | + parent?: JSXParentNode |
| 151 | +} |
0 commit comments