|
| 1 | +/** |
| 2 | + * Copyright (c) Facebook, Inc. and its affiliates. |
| 3 | + * |
| 4 | + * This source code is licensed under the MIT license found in the |
| 5 | + * LICENSE file in the root directory of this source tree. |
| 6 | + * |
| 7 | + * @format |
| 8 | + */ |
| 9 | + |
| 10 | +/** |
| 11 | + * Alias AST defintions |
| 12 | + * |
| 13 | + * Aliases are used to allow users to match a group of AST nodes at once. Aliases are used internally |
| 14 | + * by the `is` validator as well as getting specific matches codegenned. |
| 15 | + * e.g. The definition `ArrayExpression: ['Expression']` means that to match an ArrayExpression both |
| 16 | + * the specific `t.ArrayExpression(node)` matcher could be used as well as the general |
| 17 | + * `t.Expression(node)` matcher (even though `Expression` is not an AST node). |
| 18 | + * |
| 19 | + * TODO: |
| 20 | + * - Remove TS support. |
| 21 | + * - Rename "Property" alias, ESTree has a "Property" AST node. |
| 22 | + */ |
| 23 | +module.exports = { |
| 24 | + ArrayExpression: ['Expression'], |
| 25 | + AssignmentExpression: ['Expression'], |
| 26 | + BinaryExpression: ['Binary', 'Expression'], |
| 27 | + BlockStatement: ['Scopable', 'BlockParent', 'Block', 'Statement'], |
| 28 | + BreakStatement: ['Statement', 'Terminatorless', 'CompletionStatement'], |
| 29 | + CallExpression: ['Expression'], |
| 30 | + CatchClause: ['Scopable', 'BlockParent'], |
| 31 | + ConditionalExpression: ['Expression', 'Conditional'], |
| 32 | + ContinueStatement: ['Statement', 'Terminatorless', 'CompletionStatement'], |
| 33 | + DebuggerStatement: ['Statement'], |
| 34 | + DoWhileStatement: ['Statement', 'BlockParent', 'Loop', 'While', 'Scopable'], |
| 35 | + EmptyStatement: ['Statement'], |
| 36 | + ExpressionStatement: ['Statement', 'ExpressionWrapper'], |
| 37 | + ForInStatement: [ |
| 38 | + 'Scopable', |
| 39 | + 'Statement', |
| 40 | + 'For', |
| 41 | + 'BlockParent', |
| 42 | + 'Loop', |
| 43 | + 'ForXStatement', |
| 44 | + ], |
| 45 | + ForStatement: ['Scopable', 'Statement', 'For', 'BlockParent', 'Loop'], |
| 46 | + FunctionDeclaration: [ |
| 47 | + 'Scopable', |
| 48 | + 'Function', |
| 49 | + 'BlockParent', |
| 50 | + 'FunctionParent', |
| 51 | + 'Statement', |
| 52 | + 'Pureish', |
| 53 | + 'Declaration', |
| 54 | + ], |
| 55 | + FunctionExpression: [ |
| 56 | + 'Scopable', |
| 57 | + 'Function', |
| 58 | + 'BlockParent', |
| 59 | + 'FunctionParent', |
| 60 | + 'Expression', |
| 61 | + 'Pureish', |
| 62 | + ], |
| 63 | + Identifier: ['Expression', 'PatternLike', 'LVal', 'TSEntityName'], |
| 64 | + IfStatement: ['Statement', 'Conditional'], |
| 65 | + LabeledStatement: ['Statement'], |
| 66 | + StringLiteral: ['Expression', 'Pureish', 'Literal', 'Immutable'], |
| 67 | + NumericLiteral: ['Expression', 'Pureish', 'Literal', 'Immutable'], |
| 68 | + NullLiteral: ['Expression', 'Pureish', 'Literal', 'Immutable'], |
| 69 | + BooleanLiteral: ['Expression', 'Pureish', 'Literal', 'Immutable'], |
| 70 | + RegExpLiteral: ['Expression', 'Pureish', 'Literal'], |
| 71 | + LogicalExpression: ['Binary', 'Expression'], |
| 72 | + MemberExpression: ['Expression', 'LVal'], |
| 73 | + NewExpression: ['Expression'], |
| 74 | + Program: ['Scopable', 'BlockParent', 'Block'], |
| 75 | + ObjectExpression: ['Expression'], |
| 76 | + ObjectMethod: [ |
| 77 | + 'UserWhitespacable', |
| 78 | + 'Function', |
| 79 | + 'Scopable', |
| 80 | + 'BlockParent', |
| 81 | + 'FunctionParent', |
| 82 | + 'Method', |
| 83 | + 'ObjectMember', |
| 84 | + ], |
| 85 | + ObjectProperty: [ |
| 86 | + 'UserWhitespacable', |
| 87 | + // "Property", |
| 88 | + 'ObjectMember', |
| 89 | + ], |
| 90 | + RestElement: ['LVal', 'PatternLike'], |
| 91 | + ReturnStatement: ['Statement', 'Terminatorless', 'CompletionStatement'], |
| 92 | + SequenceExpression: ['Expression'], |
| 93 | + ParenthesizedExpression: ['Expression', 'ExpressionWrapper'], |
| 94 | + SwitchStatement: ['Statement', 'BlockParent', 'Scopable'], |
| 95 | + ThisExpression: ['Expression'], |
| 96 | + ThrowStatement: ['Statement', 'Terminatorless', 'CompletionStatement'], |
| 97 | + TryStatement: ['Statement'], |
| 98 | + UnaryExpression: ['UnaryLike', 'Expression'], |
| 99 | + UpdateExpression: ['Expression'], |
| 100 | + VariableDeclaration: ['Statement', 'Declaration'], |
| 101 | + WhileStatement: ['Statement', 'BlockParent', 'Loop', 'While', 'Scopable'], |
| 102 | + WithStatement: ['Statement'], |
| 103 | + AssignmentPattern: ['Pattern', 'PatternLike', 'LVal'], |
| 104 | + ArrayPattern: ['Pattern', 'PatternLike', 'LVal'], |
| 105 | + ArrowFunctionExpression: [ |
| 106 | + 'Scopable', |
| 107 | + 'Function', |
| 108 | + 'BlockParent', |
| 109 | + 'FunctionParent', |
| 110 | + 'Expression', |
| 111 | + 'Pureish', |
| 112 | + ], |
| 113 | + ClassExpression: ['Scopable', 'Class', 'Expression'], |
| 114 | + ClassDeclaration: ['Scopable', 'Class', 'Statement', 'Declaration'], |
| 115 | + ExportAllDeclaration: [ |
| 116 | + 'Statement', |
| 117 | + 'Declaration', |
| 118 | + 'ModuleDeclaration', |
| 119 | + 'ExportDeclaration', |
| 120 | + ], |
| 121 | + ExportDefaultDeclaration: [ |
| 122 | + 'Statement', |
| 123 | + 'Declaration', |
| 124 | + 'ModuleDeclaration', |
| 125 | + 'ExportDeclaration', |
| 126 | + ], |
| 127 | + ExportNamedDeclaration: [ |
| 128 | + 'Statement', |
| 129 | + 'Declaration', |
| 130 | + 'ModuleDeclaration', |
| 131 | + 'ExportDeclaration', |
| 132 | + ], |
| 133 | + ExportSpecifier: ['ModuleSpecifier'], |
| 134 | + ForOfStatement: [ |
| 135 | + 'Scopable', |
| 136 | + 'Statement', |
| 137 | + 'For', |
| 138 | + 'BlockParent', |
| 139 | + 'Loop', |
| 140 | + 'ForXStatement', |
| 141 | + ], |
| 142 | + ImportDeclaration: ['Statement', 'Declaration', 'ModuleDeclaration'], |
| 143 | + ImportDefaultSpecifier: ['ModuleSpecifier'], |
| 144 | + ImportNamespaceSpecifier: ['ModuleSpecifier'], |
| 145 | + ImportSpecifier: ['ModuleSpecifier'], |
| 146 | + MetaProperty: ['Expression'], |
| 147 | + ClassMethod: [ |
| 148 | + 'Function', |
| 149 | + 'Scopable', |
| 150 | + 'BlockParent', |
| 151 | + 'FunctionParent', |
| 152 | + 'Method', |
| 153 | + ], |
| 154 | + ObjectPattern: ['Pattern', 'PatternLike', 'LVal'], |
| 155 | + SpreadElement: ['UnaryLike'], |
| 156 | + Super: ['Expression'], |
| 157 | + TaggedTemplateExpression: ['Expression'], |
| 158 | + TemplateLiteral: ['Expression', 'Literal'], |
| 159 | + YieldExpression: ['Expression', 'Terminatorless'], |
| 160 | + AwaitExpression: ['Expression', 'Terminatorless'], |
| 161 | + Import: ['Expression'], |
| 162 | + BigIntLiteral: ['Expression', 'Pureish', 'Literal', 'Immutable'], |
| 163 | + ExportNamespaceSpecifier: ['ModuleSpecifier'], |
| 164 | + OptionalMemberExpression: ['Expression'], |
| 165 | + OptionalCallExpression: ['Expression'], |
| 166 | + ClassProperty: [ |
| 167 | + // "Property" |
| 168 | + ], |
| 169 | + ClassPrivateProperty: [ |
| 170 | + // "Property", |
| 171 | + 'Private', |
| 172 | + ], |
| 173 | + ClassPrivateMethod: [ |
| 174 | + 'Function', |
| 175 | + 'Scopable', |
| 176 | + 'BlockParent', |
| 177 | + 'FunctionParent', |
| 178 | + 'Method', |
| 179 | + 'Private', |
| 180 | + ], |
| 181 | + PrivateName: ['Private'], |
| 182 | + AnyTypeAnnotation: ['Flow', 'FlowType', 'FlowBaseAnnotation'], |
| 183 | + ArrayTypeAnnotation: ['Flow', 'FlowType'], |
| 184 | + BooleanTypeAnnotation: ['Flow', 'FlowType', 'FlowBaseAnnotation'], |
| 185 | + BooleanLiteralTypeAnnotation: ['Flow', 'FlowType'], |
| 186 | + NullLiteralTypeAnnotation: ['Flow', 'FlowType', 'FlowBaseAnnotation'], |
| 187 | + ClassImplements: ['Flow'], |
| 188 | + DeclareClass: ['Flow', 'FlowDeclaration', 'Statement', 'Declaration'], |
| 189 | + DeclareFunction: ['Flow', 'FlowDeclaration', 'Statement', 'Declaration'], |
| 190 | + DeclareInterface: ['Flow', 'FlowDeclaration', 'Statement', 'Declaration'], |
| 191 | + DeclareModule: ['Flow', 'FlowDeclaration', 'Statement', 'Declaration'], |
| 192 | + DeclareModuleExports: ['Flow', 'FlowDeclaration', 'Statement', 'Declaration'], |
| 193 | + DeclareTypeAlias: ['Flow', 'FlowDeclaration', 'Statement', 'Declaration'], |
| 194 | + DeclareOpaqueType: ['Flow', 'FlowDeclaration', 'Statement', 'Declaration'], |
| 195 | + DeclareVariable: ['Flow', 'FlowDeclaration', 'Statement', 'Declaration'], |
| 196 | + DeclareExportDeclaration: [ |
| 197 | + 'Flow', |
| 198 | + 'FlowDeclaration', |
| 199 | + 'Statement', |
| 200 | + 'Declaration', |
| 201 | + ], |
| 202 | + DeclareExportAllDeclaration: [ |
| 203 | + 'Flow', |
| 204 | + 'FlowDeclaration', |
| 205 | + 'Statement', |
| 206 | + 'Declaration', |
| 207 | + ], |
| 208 | + DeclaredPredicate: ['Flow', 'FlowPredicate'], |
| 209 | + ExistsTypeAnnotation: ['Flow', 'FlowType'], |
| 210 | + FunctionTypeAnnotation: ['Flow', 'FlowType'], |
| 211 | + FunctionTypeParam: ['Flow'], |
| 212 | + GenericTypeAnnotation: ['Flow', 'FlowType'], |
| 213 | + InferredPredicate: ['Flow', 'FlowPredicate'], |
| 214 | + InterfaceExtends: ['Flow'], |
| 215 | + InterfaceDeclaration: ['Flow', 'FlowDeclaration', 'Statement', 'Declaration'], |
| 216 | + InterfaceTypeAnnotation: ['Flow', 'FlowType'], |
| 217 | + IntersectionTypeAnnotation: ['Flow', 'FlowType'], |
| 218 | + MixedTypeAnnotation: ['Flow', 'FlowType', 'FlowBaseAnnotation'], |
| 219 | + EmptyTypeAnnotation: ['Flow', 'FlowType', 'FlowBaseAnnotation'], |
| 220 | + NullableTypeAnnotation: ['Flow', 'FlowType'], |
| 221 | + NumberLiteralTypeAnnotation: ['Flow', 'FlowType'], |
| 222 | + NumberTypeAnnotation: ['Flow', 'FlowType', 'FlowBaseAnnotation'], |
| 223 | + ObjectTypeAnnotation: ['Flow', 'FlowType'], |
| 224 | + ObjectTypeInternalSlot: ['Flow', 'UserWhitespacable'], |
| 225 | + ObjectTypeCallProperty: ['Flow', 'UserWhitespacable'], |
| 226 | + ObjectTypeIndexer: ['Flow', 'UserWhitespacable'], |
| 227 | + ObjectTypeProperty: ['Flow', 'UserWhitespacable'], |
| 228 | + ObjectTypeSpreadProperty: ['Flow', 'UserWhitespacable'], |
| 229 | + OpaqueType: ['Flow', 'FlowDeclaration', 'Statement', 'Declaration'], |
| 230 | + QualifiedTypeIdentifier: ['Flow'], |
| 231 | + StringLiteralTypeAnnotation: ['Flow', 'FlowType'], |
| 232 | + StringTypeAnnotation: ['Flow', 'FlowType', 'FlowBaseAnnotation'], |
| 233 | + SymbolTypeAnnotation: ['Flow', 'FlowType', 'FlowBaseAnnotation'], |
| 234 | + ThisTypeAnnotation: ['Flow', 'FlowType', 'FlowBaseAnnotation'], |
| 235 | + TupleTypeAnnotation: ['Flow', 'FlowType'], |
| 236 | + TypeofTypeAnnotation: ['Flow', 'FlowType'], |
| 237 | + TypeAlias: ['Flow', 'FlowDeclaration', 'Statement', 'Declaration'], |
| 238 | + TypeAnnotation: ['Flow'], |
| 239 | + TypeCastExpression: ['Flow', 'ExpressionWrapper', 'Expression'], |
| 240 | + TypeParameter: ['Flow'], |
| 241 | + TypeParameterDeclaration: ['Flow'], |
| 242 | + TypeParameterInstantiation: ['Flow'], |
| 243 | + UnionTypeAnnotation: ['Flow', 'FlowType'], |
| 244 | + Variance: ['Flow'], |
| 245 | + VoidTypeAnnotation: ['Flow', 'FlowType', 'FlowBaseAnnotation'], |
| 246 | + EnumDeclaration: ['Statement', 'Declaration'], |
| 247 | + EnumBooleanBody: ['EnumBody'], |
| 248 | + EnumNumberBody: ['EnumBody'], |
| 249 | + EnumStringBody: ['EnumBody'], |
| 250 | + EnumSymbolBody: ['EnumBody'], |
| 251 | + EnumBooleanMember: ['EnumMember'], |
| 252 | + EnumNumberMember: ['EnumMember'], |
| 253 | + EnumStringMember: ['EnumMember'], |
| 254 | + EnumDefaultedMember: ['EnumMember'], |
| 255 | + IndexedAccessType: ['Flow', 'FlowType'], |
| 256 | + OptionalIndexedAccessType: ['Flow', 'FlowType'], |
| 257 | + JSXAttribute: ['JSX', 'Immutable'], |
| 258 | + JSXClosingElement: ['JSX', 'Immutable'], |
| 259 | + JSXElement: ['JSX', 'Immutable', 'Expression'], |
| 260 | + JSXEmptyExpression: ['JSX'], |
| 261 | + JSXExpressionContainer: ['JSX', 'Immutable'], |
| 262 | + JSXSpreadChild: ['JSX', 'Immutable'], |
| 263 | + JSXIdentifier: ['JSX'], |
| 264 | + JSXMemberExpression: ['JSX'], |
| 265 | + JSXNamespacedName: ['JSX'], |
| 266 | + JSXOpeningElement: ['JSX', 'Immutable'], |
| 267 | + JSXSpreadAttribute: ['JSX'], |
| 268 | + JSXText: ['JSX', 'Immutable'], |
| 269 | + JSXFragment: ['JSX', 'Immutable', 'Expression'], |
| 270 | + JSXOpeningFragment: ['JSX', 'Immutable'], |
| 271 | + JSXClosingFragment: ['JSX', 'Immutable'], |
| 272 | + BindExpression: ['Expression'], |
| 273 | + DoExpression: ['Expression'], |
| 274 | + ExportDefaultSpecifier: ['ModuleSpecifier'], |
| 275 | + RecordExpression: ['Expression'], |
| 276 | + TupleExpression: ['Expression'], |
| 277 | + DecimalLiteral: ['Expression', 'Pureish', 'Literal', 'Immutable'], |
| 278 | + StaticBlock: ['Scopable', 'BlockParent'], |
| 279 | + ModuleExpression: ['Expression'], |
| 280 | + TopicReference: ['Expression'], |
| 281 | + PipelineTopicExpression: ['Expression'], |
| 282 | + PipelineBareFunction: ['Expression'], |
| 283 | + PipelinePrimaryTopicReference: ['Expression'], |
| 284 | + TSParameterProperty: ['LVal'], |
| 285 | + TSDeclareFunction: ['Statement', 'Declaration'], |
| 286 | + TSQualifiedName: ['TSEntityName'], |
| 287 | + TSCallSignatureDeclaration: ['TSTypeElement'], |
| 288 | + TSConstructSignatureDeclaration: ['TSTypeElement'], |
| 289 | + TSPropertySignature: ['TSTypeElement'], |
| 290 | + TSMethodSignature: ['TSTypeElement'], |
| 291 | + TSIndexSignature: ['TSTypeElement'], |
| 292 | + TSAnyKeyword: ['TSType', 'TSBaseType'], |
| 293 | + TSBooleanKeyword: ['TSType', 'TSBaseType'], |
| 294 | + TSBigIntKeyword: ['TSType', 'TSBaseType'], |
| 295 | + TSIntrinsicKeyword: ['TSType', 'TSBaseType'], |
| 296 | + TSNeverKeyword: ['TSType', 'TSBaseType'], |
| 297 | + TSNullKeyword: ['TSType', 'TSBaseType'], |
| 298 | + TSNumberKeyword: ['TSType', 'TSBaseType'], |
| 299 | + TSObjectKeyword: ['TSType', 'TSBaseType'], |
| 300 | + TSStringKeyword: ['TSType', 'TSBaseType'], |
| 301 | + TSSymbolKeyword: ['TSType', 'TSBaseType'], |
| 302 | + TSUndefinedKeyword: ['TSType', 'TSBaseType'], |
| 303 | + TSUnknownKeyword: ['TSType', 'TSBaseType'], |
| 304 | + TSVoidKeyword: ['TSType', 'TSBaseType'], |
| 305 | + TSThisType: ['TSType', 'TSBaseType'], |
| 306 | + TSFunctionType: ['TSType'], |
| 307 | + TSConstructorType: ['TSType'], |
| 308 | + TSTypeReference: ['TSType'], |
| 309 | + TSTypePredicate: ['TSType'], |
| 310 | + TSTypeQuery: ['TSType'], |
| 311 | + TSTypeLiteral: ['TSType'], |
| 312 | + TSArrayType: ['TSType'], |
| 313 | + TSTupleType: ['TSType'], |
| 314 | + TSOptionalType: ['TSType'], |
| 315 | + TSRestType: ['TSType'], |
| 316 | + TSUnionType: ['TSType'], |
| 317 | + TSIntersectionType: ['TSType'], |
| 318 | + TSConditionalType: ['TSType'], |
| 319 | + TSInferType: ['TSType'], |
| 320 | + TSParenthesizedType: ['TSType'], |
| 321 | + TSTypeOperator: ['TSType'], |
| 322 | + TSIndexedAccessType: ['TSType'], |
| 323 | + TSMappedType: ['TSType'], |
| 324 | + TSLiteralType: ['TSType', 'TSBaseType'], |
| 325 | + TSExpressionWithTypeArguments: ['TSType'], |
| 326 | + TSInterfaceDeclaration: ['Statement', 'Declaration'], |
| 327 | + TSTypeAliasDeclaration: ['Statement', 'Declaration'], |
| 328 | + TSAsExpression: ['Expression'], |
| 329 | + TSTypeAssertion: ['Expression'], |
| 330 | + TSEnumDeclaration: ['Statement', 'Declaration'], |
| 331 | + TSModuleDeclaration: ['Statement', 'Declaration'], |
| 332 | + TSModuleBlock: ['Scopable', 'Block', 'BlockParent'], |
| 333 | + TSImportType: ['TSType'], |
| 334 | + TSImportEqualsDeclaration: ['Statement'], |
| 335 | + TSNonNullExpression: ['Expression'], |
| 336 | + TSExportAssignment: ['Statement'], |
| 337 | + TSNamespaceExportDeclaration: ['Statement'], |
| 338 | +}; |
0 commit comments