diff --git a/packages/babel-traverse/src/path/generated/asserts.ts b/packages/babel-traverse/src/path/generated/asserts.ts index 3acc28f3fbb8..a0f0c50093b6 100755 --- a/packages/babel-traverse/src/path/generated/asserts.ts +++ b/packages/babel-traverse/src/path/generated/asserts.ts @@ -328,6 +328,7 @@ export interface NodePathAssetions { ): asserts this is NodePath; assertMetaProperty(opts?: object): asserts this is NodePath; assertMethod(opts?: object): asserts this is NodePath; + assertMiscellaneous(opts?: object): asserts this is NodePath; assertMixedTypeAnnotation( opts?: object, ): asserts this is NodePath; @@ -437,6 +438,7 @@ export interface NodePathAssetions { assertSpreadProperty( opts?: object, ): asserts this is NodePath; + assertStandardized(opts?: object): asserts this is NodePath; assertStatement(opts?: object): asserts this is NodePath; assertStaticBlock(opts?: object): asserts this is NodePath; assertStringLiteral(opts?: object): asserts this is NodePath; @@ -660,6 +662,7 @@ export interface NodePathAssetions { assertTypeParameterInstantiation( opts?: object, ): asserts this is NodePath; + assertTypeScript(opts?: object): asserts this is NodePath; assertTypeofTypeAnnotation( opts?: object, ): asserts this is NodePath; diff --git a/packages/babel-traverse/src/path/generated/validators.ts b/packages/babel-traverse/src/path/generated/validators.ts index 6f6c457e37e5..ab7b614d4454 100755 --- a/packages/babel-traverse/src/path/generated/validators.ts +++ b/packages/babel-traverse/src/path/generated/validators.ts @@ -191,6 +191,7 @@ export interface NodePathValidators { isMemberExpression(opts?: object): this is NodePath; isMetaProperty(opts?: object): this is NodePath; isMethod(opts?: object): this is NodePath; + isMiscellaneous(opts?: object): this is NodePath; isMixedTypeAnnotation(opts?: object): this is NodePath; isModuleDeclaration(opts?: object): this is NodePath; isModuleExpression(opts?: object): this is NodePath; @@ -274,6 +275,7 @@ export interface NodePathValidators { isSequenceExpression(opts?: object): this is NodePath; isSpreadElement(opts?: object): this is NodePath; isSpreadProperty(opts?: object): this is NodePath; + isStandardized(opts?: object): this is NodePath; isStatement(opts?: object): this is NodePath; isStaticBlock(opts?: object): this is NodePath; isStringLiteral(opts?: object): this is NodePath; @@ -399,6 +401,7 @@ export interface NodePathValidators { isTypeParameterInstantiation( opts?: object, ): this is NodePath; + isTypeScript(opts?: object): this is NodePath; isTypeofTypeAnnotation( opts?: object, ): this is NodePath; diff --git a/packages/babel-types/scripts/generators/ast-types.js b/packages/babel-types/scripts/generators/ast-types.js index cd31918a5611..3bf42869f127 100644 --- a/packages/babel-types/scripts/generators/ast-types.js +++ b/packages/babel-types/scripts/generators/ast-types.js @@ -49,7 +49,9 @@ interface BaseNode { export type CommentTypeShorthand = "leading" | "inner" | "trailing"; -export type Node = ${t.TYPES.sort().join(" | ")};\n\n`; +export type Node = ${t.TYPES.filter(k => !t.FLIPPED_ALIAS_KEYS[k]) + .sort() + .join(" | ")};\n\n`; const deprecatedAlias = {}; for (const type in t.DEPRECATED_KEYS) { @@ -115,6 +117,9 @@ export interface ${deprecatedAlias[type]} extends BaseNode { code += ` ${type}: ${type};\n`; } code += "}\n\n"; + code += `export type DeprecatedAliases = ${Object.keys( + t.DEPRECATED_KEYS + ).join(" | ")}\n\n`; return code; } diff --git a/packages/babel-types/scripts/generators/docs.js b/packages/babel-types/scripts/generators/docs.js index f7b82e56d394..e64bb275e98d 100644 --- a/packages/babel-types/scripts/generators/docs.js +++ b/packages/babel-types/scripts/generators/docs.js @@ -217,6 +217,8 @@ const aliasDescriptions = { "A cover of [Literal](https://tc39.es/ecma262/#sec-primary-expression-literals)s, [Regular Expression Literal](https://tc39.es/ecma262/#sec-primary-expression-regular-expression-literals)s and [Template Literal](https://tc39.es/ecma262/#sec-template-literals)s.", Loop: "A cover of loop statements.", Method: "A cover of object methods and class methods.", + Miscellaneous: + "A cover of non-standard AST types that are sometimes useful for development.", ModuleDeclaration: "A cover of ImportDeclaration and [ExportDeclaration](#exportdeclaration)", ModuleSpecifier: @@ -233,12 +235,15 @@ const aliasDescriptions = { "A cover of AST nodes which do not have side-effects. In other words, there is no observable behaviour changes if they are evaluated more than once.", Scopable: "A cover of [FunctionParent](#functionparent) and [BlockParent](#blockparent).", + Standardized: + "A cover of AST nodes which are part of an official ECMAScript specification.", Statement: "A cover of any [Statement](https://tc39.es/ecma262/#prod-Statement)s.", TSBaseType: "A cover of primary TypeScript type annotations.", TSEntityName: "A cover of ts entities.", TSType: "A cover of TypeScript type annotations.", TSTypeElement: "A cover of TypeScript type declarations.", + TypeScript: "A cover of AST nodes defined for TypeScript.", Terminatorless: "A cover of AST nodes whose semantic will change when a line terminator is inserted between the operator and the operand.", UnaryLike: "A cover of UnaryExpression and SpreadElement.", diff --git a/packages/babel-types/src/asserts/generated/index.ts b/packages/babel-types/src/asserts/generated/index.ts index c171b27816cf..5b784c6171e1 100755 --- a/packages/babel-types/src/asserts/generated/index.ts +++ b/packages/babel-types/src/asserts/generated/index.ts @@ -1490,6 +1490,12 @@ export function assertTSTypeParameter( ): asserts node is t.TSTypeParameter { assert("TSTypeParameter", node, opts); } +export function assertStandardized( + node: object | null | undefined, + opts?: object | null, +): asserts node is t.Standardized { + assert("Standardized", node, opts); +} export function assertExpression( node: object | null | undefined, opts?: object | null, @@ -1742,6 +1748,18 @@ export function assertJSX( ): asserts node is t.JSX { assert("JSX", node, opts); } +export function assertMiscellaneous( + node: object | null | undefined, + opts?: object | null, +): asserts node is t.Miscellaneous { + assert("Miscellaneous", node, opts); +} +export function assertTypeScript( + node: object | null | undefined, + opts?: object | null, +): asserts node is t.TypeScript { + assert("TypeScript", node, opts); +} export function assertTSTypeElement( node: object | null | undefined, opts?: object | null, diff --git a/packages/babel-types/src/ast-types/generated/index.ts b/packages/babel-types/src/ast-types/generated/index.ts index f4def136c3c2..cb5483b949bd 100755 --- a/packages/babel-types/src/ast-types/generated/index.ts +++ b/packages/babel-types/src/ast-types/generated/index.ts @@ -56,11 +56,8 @@ export type Node = | AssignmentPattern | AwaitExpression | BigIntLiteral - | Binary | BinaryExpression | BindExpression - | Block - | BlockParent | BlockStatement | BooleanLiteral | BooleanLiteralTypeAnnotation @@ -68,7 +65,6 @@ export type Node = | BreakStatement | CallExpression | CatchClause - | Class | ClassBody | ClassDeclaration | ClassExpression @@ -77,13 +73,10 @@ export type Node = | ClassPrivateMethod | ClassPrivateProperty | ClassProperty - | CompletionStatement - | Conditional | ConditionalExpression | ContinueStatement | DebuggerStatement | DecimalLiteral - | Declaration | DeclareClass | DeclareExportAllDeclaration | DeclareExportDeclaration @@ -102,12 +95,10 @@ export type Node = | DoWhileStatement | EmptyStatement | EmptyTypeAnnotation - | EnumBody | EnumBooleanBody | EnumBooleanMember | EnumDeclaration | EnumDefaultedMember - | EnumMember | EnumNumberBody | EnumNumberMember | EnumStringBody @@ -115,36 +106,23 @@ export type Node = | EnumSymbolBody | ExistsTypeAnnotation | ExportAllDeclaration - | ExportDeclaration | ExportDefaultDeclaration | ExportDefaultSpecifier | ExportNamedDeclaration | ExportNamespaceSpecifier | ExportSpecifier - | Expression | ExpressionStatement - | ExpressionWrapper | File - | Flow - | FlowBaseAnnotation - | FlowDeclaration - | FlowPredicate - | FlowType - | For | ForInStatement | ForOfStatement | ForStatement - | ForXStatement - | Function | FunctionDeclaration | FunctionExpression - | FunctionParent | FunctionTypeAnnotation | FunctionTypeParam | GenericTypeAnnotation | Identifier | IfStatement - | Immutable | Import | ImportAttribute | ImportDeclaration @@ -158,7 +136,6 @@ export type Node = | InterfaceTypeAnnotation | InterpreterDirective | IntersectionTypeAnnotation - | JSX | JSXAttribute | JSXClosingElement | JSXClosingFragment @@ -174,18 +151,12 @@ export type Node = | JSXSpreadAttribute | JSXSpreadChild | JSXText - | LVal | LabeledStatement - | Literal | LogicalExpression - | Loop | MemberExpression | MetaProperty - | Method | MixedTypeAnnotation - | ModuleDeclaration | ModuleExpression - | ModuleSpecifier | NewExpression | Noop | NullLiteral @@ -196,7 +167,6 @@ export type Node = | NumberTypeAnnotation | NumericLiteral | ObjectExpression - | ObjectMember | ObjectMethod | ObjectPattern | ObjectProperty @@ -211,17 +181,12 @@ export type Node = | OptionalIndexedAccessType | OptionalMemberExpression | ParenthesizedExpression - | Pattern - | PatternLike | PipelineBareFunction | PipelinePrimaryTopicReference | PipelineTopicExpression | Placeholder - | Private | PrivateName | Program - | Property - | Pureish | QualifiedTypeIdentifier | RecordExpression | RegExpLiteral @@ -229,11 +194,9 @@ export type Node = | RestElement | RestProperty | ReturnStatement - | Scopable | SequenceExpression | SpreadElement | SpreadProperty - | Statement | StaticBlock | StringLiteral | StringLiteralTypeAnnotation @@ -245,7 +208,6 @@ export type Node = | TSAnyKeyword | TSArrayType | TSAsExpression - | TSBaseType | TSBigIntKeyword | TSBooleanKeyword | TSCallSignatureDeclaration @@ -254,7 +216,6 @@ export type Node = | TSConstructorType | TSDeclareFunction | TSDeclareMethod - | TSEntityName | TSEnumDeclaration | TSEnumMember | TSExportAssignment @@ -292,11 +253,9 @@ export type Node = | TSSymbolKeyword | TSThisType | TSTupleType - | TSType | TSTypeAliasDeclaration | TSTypeAnnotation | TSTypeAssertion - | TSTypeElement | TSTypeLiteral | TSTypeOperator | TSTypeParameter @@ -312,7 +271,6 @@ export type Node = | TaggedTemplateExpression | TemplateElement | TemplateLiteral - | Terminatorless | ThisExpression | ThisTypeAnnotation | ThrowStatement @@ -328,16 +286,13 @@ export type Node = | TypeParameterInstantiation | TypeofTypeAnnotation | UnaryExpression - | UnaryLike | UnionTypeAnnotation | UpdateExpression - | UserWhitespacable | V8IntrinsicIdentifier | VariableDeclaration | VariableDeclarator | Variance | VoidTypeAnnotation - | While | WhileStatement | WithStatement | YieldExpression; @@ -2055,6 +2010,92 @@ export interface TSTypeParameter extends BaseNode { name: string; } +export type Standardized = + | ArrayExpression + | AssignmentExpression + | BinaryExpression + | InterpreterDirective + | Directive + | DirectiveLiteral + | BlockStatement + | BreakStatement + | CallExpression + | CatchClause + | ConditionalExpression + | ContinueStatement + | DebuggerStatement + | DoWhileStatement + | EmptyStatement + | ExpressionStatement + | File + | ForInStatement + | ForStatement + | FunctionDeclaration + | FunctionExpression + | Identifier + | IfStatement + | LabeledStatement + | StringLiteral + | NumericLiteral + | NullLiteral + | BooleanLiteral + | RegExpLiteral + | LogicalExpression + | MemberExpression + | NewExpression + | Program + | ObjectExpression + | ObjectMethod + | ObjectProperty + | RestElement + | ReturnStatement + | SequenceExpression + | ParenthesizedExpression + | SwitchCase + | SwitchStatement + | ThisExpression + | ThrowStatement + | TryStatement + | UnaryExpression + | UpdateExpression + | VariableDeclaration + | VariableDeclarator + | WhileStatement + | WithStatement + | AssignmentPattern + | ArrayPattern + | ArrowFunctionExpression + | ClassBody + | ClassExpression + | ClassDeclaration + | ExportAllDeclaration + | ExportDefaultDeclaration + | ExportNamedDeclaration + | ExportSpecifier + | ForOfStatement + | ImportDeclaration + | ImportDefaultSpecifier + | ImportNamespaceSpecifier + | ImportSpecifier + | MetaProperty + | ClassMethod + | ObjectPattern + | SpreadElement + | Super + | TaggedTemplateExpression + | TemplateElement + | TemplateLiteral + | YieldExpression + | AwaitExpression + | Import + | BigIntLiteral + | ExportNamespaceSpecifier + | OptionalMemberExpression + | OptionalCallExpression + | ClassProperty + | ClassPrivateProperty + | ClassPrivateMethod + | PrivateName; export type Expression = | ArrayExpression | AssignmentExpression @@ -2398,6 +2439,15 @@ export type Flow = | UnionTypeAnnotation | Variance | VoidTypeAnnotation + | EnumDeclaration + | EnumBooleanBody + | EnumNumberBody + | EnumStringBody + | EnumSymbolBody + | EnumBooleanMember + | EnumNumberMember + | EnumStringMember + | EnumDefaultedMember | IndexedAccessType | OptionalIndexedAccessType; export type FlowType = @@ -2479,6 +2529,71 @@ export type JSX = | JSXFragment | JSXOpeningFragment | JSXClosingFragment; +export type Miscellaneous = Noop | Placeholder | V8IntrinsicIdentifier; +export type TypeScript = + | TSParameterProperty + | TSDeclareFunction + | TSDeclareMethod + | TSQualifiedName + | TSCallSignatureDeclaration + | TSConstructSignatureDeclaration + | TSPropertySignature + | TSMethodSignature + | TSIndexSignature + | TSAnyKeyword + | TSBooleanKeyword + | TSBigIntKeyword + | TSIntrinsicKeyword + | TSNeverKeyword + | TSNullKeyword + | TSNumberKeyword + | TSObjectKeyword + | TSStringKeyword + | TSSymbolKeyword + | TSUndefinedKeyword + | TSUnknownKeyword + | TSVoidKeyword + | TSThisType + | TSFunctionType + | TSConstructorType + | TSTypeReference + | TSTypePredicate + | TSTypeQuery + | TSTypeLiteral + | TSArrayType + | TSTupleType + | TSOptionalType + | TSRestType + | TSNamedTupleMember + | TSUnionType + | TSIntersectionType + | TSConditionalType + | TSInferType + | TSParenthesizedType + | TSTypeOperator + | TSIndexedAccessType + | TSMappedType + | TSLiteralType + | TSExpressionWithTypeArguments + | TSInterfaceDeclaration + | TSInterfaceBody + | TSTypeAliasDeclaration + | TSAsExpression + | TSTypeAssertion + | TSEnumDeclaration + | TSEnumMember + | TSModuleDeclaration + | TSModuleBlock + | TSImportType + | TSImportEqualsDeclaration + | TSExternalModuleReference + | TSNonNullExpression + | TSExportAssignment + | TSNamespaceExportDeclaration + | TSTypeAnnotation + | TSTypeParameterInstantiation + | TSTypeParameterDeclaration + | TSTypeParameter; export type TSTypeElement = | TSCallSignatureDeclaration | TSConstructSignatureDeclaration @@ -2539,6 +2654,7 @@ export type TSBaseType = | TSLiteralType; export interface Aliases { + Standardized: Standardized; Expression: Expression; Binary: Binary; Scopable: Scopable; @@ -2581,7 +2697,15 @@ export interface Aliases { EnumBody: EnumBody; EnumMember: EnumMember; JSX: JSX; + Miscellaneous: Miscellaneous; + TypeScript: TypeScript; TSTypeElement: TSTypeElement; TSType: TSType; TSBaseType: TSBaseType; } + +export type DeprecatedAliases = + | NumberLiteral + | RegexLiteral + | RestProperty + | SpreadProperty; diff --git a/packages/babel-types/src/constants/generated/index.ts b/packages/babel-types/src/constants/generated/index.ts index 39342664168f..774d7a8fb4cd 100755 --- a/packages/babel-types/src/constants/generated/index.ts +++ b/packages/babel-types/src/constants/generated/index.ts @@ -4,6 +4,7 @@ */ import { FLIPPED_ALIAS_KEYS } from "../../definitions"; +export const STANDARDIZED_TYPES = FLIPPED_ALIAS_KEYS["Standardized"]; export const EXPRESSION_TYPES = FLIPPED_ALIAS_KEYS["Expression"]; export const BINARY_TYPES = FLIPPED_ALIAS_KEYS["Binary"]; export const SCOPABLE_TYPES = FLIPPED_ALIAS_KEYS["Scopable"]; @@ -48,6 +49,8 @@ export const FLOWPREDICATE_TYPES = FLIPPED_ALIAS_KEYS["FlowPredicate"]; export const ENUMBODY_TYPES = FLIPPED_ALIAS_KEYS["EnumBody"]; export const ENUMMEMBER_TYPES = FLIPPED_ALIAS_KEYS["EnumMember"]; export const JSX_TYPES = FLIPPED_ALIAS_KEYS["JSX"]; +export const MISCELLANEOUS_TYPES = FLIPPED_ALIAS_KEYS["Miscellaneous"]; +export const TYPESCRIPT_TYPES = FLIPPED_ALIAS_KEYS["TypeScript"]; export const TSTYPEELEMENT_TYPES = FLIPPED_ALIAS_KEYS["TSTypeElement"]; export const TSTYPE_TYPES = FLIPPED_ALIAS_KEYS["TSType"]; export const TSBASETYPE_TYPES = FLIPPED_ALIAS_KEYS["TSBaseType"]; diff --git a/packages/babel-types/src/definitions/core.ts b/packages/babel-types/src/definitions/core.ts index 6e275614e2be..4b619edca893 100644 --- a/packages/babel-types/src/definitions/core.ts +++ b/packages/babel-types/src/definitions/core.ts @@ -10,7 +10,8 @@ import { UPDATE_OPERATORS, } from "../constants"; -import defineType, { +import { + defineAliasedType, assertShape, assertOptionalChainStart, assertValueType, @@ -22,6 +23,8 @@ import defineType, { validateOptional, } from "./utils"; +const defineType = defineAliasedType("Standardized"); + defineType("ArrayExpression", { fields: { elements: { diff --git a/packages/babel-types/src/definitions/flow.ts b/packages/babel-types/src/definitions/flow.ts index 2b42c7ffbc96..738f2370dac7 100644 --- a/packages/babel-types/src/definitions/flow.ts +++ b/packages/babel-types/src/definitions/flow.ts @@ -1,4 +1,5 @@ -import defineType, { +import { + defineAliasedType, arrayOfType, assertOneOf, assertValueType, @@ -9,6 +10,8 @@ import defineType, { validateType, } from "./utils"; +const defineType = defineAliasedType("Flow"); + const defineInterfaceishType = ( name: string, typeParameterType: string = "TypeParameterDeclaration", @@ -23,7 +26,7 @@ const defineInterfaceishType = ( "implements", "body", ], - aliases: ["Flow", "FlowDeclaration", "Statement", "Declaration"], + aliases: ["FlowDeclaration", "Statement", "Declaration"], fields: { id: validateType("Identifier"), typeParameters: validateOptionalType(typeParameterType), @@ -36,36 +39,35 @@ const defineInterfaceishType = ( }; defineType("AnyTypeAnnotation", { - aliases: ["Flow", "FlowType", "FlowBaseAnnotation"], + aliases: ["FlowType", "FlowBaseAnnotation"], }); defineType("ArrayTypeAnnotation", { visitor: ["elementType"], - aliases: ["Flow", "FlowType"], + aliases: ["FlowType"], fields: { elementType: validateType("FlowType"), }, }); defineType("BooleanTypeAnnotation", { - aliases: ["Flow", "FlowType", "FlowBaseAnnotation"], + aliases: ["FlowType", "FlowBaseAnnotation"], }); defineType("BooleanLiteralTypeAnnotation", { builder: ["value"], - aliases: ["Flow", "FlowType"], + aliases: ["FlowType"], fields: { value: validate(assertValueType("boolean")), }, }); defineType("NullLiteralTypeAnnotation", { - aliases: ["Flow", "FlowType", "FlowBaseAnnotation"], + aliases: ["FlowType", "FlowBaseAnnotation"], }); defineType("ClassImplements", { visitor: ["id", "typeParameters"], - aliases: ["Flow"], fields: { id: validateType("Identifier"), typeParameters: validateOptionalType("TypeParameterInstantiation"), @@ -76,7 +78,7 @@ defineInterfaceishType("DeclareClass"); defineType("DeclareFunction", { visitor: ["id"], - aliases: ["Flow", "FlowDeclaration", "Statement", "Declaration"], + aliases: ["FlowDeclaration", "Statement", "Declaration"], fields: { id: validateType("Identifier"), predicate: validateOptionalType("DeclaredPredicate"), @@ -88,7 +90,7 @@ defineInterfaceishType("DeclareInterface"); defineType("DeclareModule", { builder: ["id", "body", "kind"], visitor: ["id", "body"], - aliases: ["Flow", "FlowDeclaration", "Statement", "Declaration"], + aliases: ["FlowDeclaration", "Statement", "Declaration"], fields: { id: validateType(["Identifier", "StringLiteral"]), body: validateType("BlockStatement"), @@ -98,7 +100,7 @@ defineType("DeclareModule", { defineType("DeclareModuleExports", { visitor: ["typeAnnotation"], - aliases: ["Flow", "FlowDeclaration", "Statement", "Declaration"], + aliases: ["FlowDeclaration", "Statement", "Declaration"], fields: { typeAnnotation: validateType("TypeAnnotation"), }, @@ -106,7 +108,7 @@ defineType("DeclareModuleExports", { defineType("DeclareTypeAlias", { visitor: ["id", "typeParameters", "right"], - aliases: ["Flow", "FlowDeclaration", "Statement", "Declaration"], + aliases: ["FlowDeclaration", "Statement", "Declaration"], fields: { id: validateType("Identifier"), typeParameters: validateOptionalType("TypeParameterDeclaration"), @@ -116,7 +118,7 @@ defineType("DeclareTypeAlias", { defineType("DeclareOpaqueType", { visitor: ["id", "typeParameters", "supertype"], - aliases: ["Flow", "FlowDeclaration", "Statement", "Declaration"], + aliases: ["FlowDeclaration", "Statement", "Declaration"], fields: { id: validateType("Identifier"), typeParameters: validateOptionalType("TypeParameterDeclaration"), @@ -127,7 +129,7 @@ defineType("DeclareOpaqueType", { defineType("DeclareVariable", { visitor: ["id"], - aliases: ["Flow", "FlowDeclaration", "Statement", "Declaration"], + aliases: ["FlowDeclaration", "Statement", "Declaration"], fields: { id: validateType("Identifier"), }, @@ -135,7 +137,7 @@ defineType("DeclareVariable", { defineType("DeclareExportDeclaration", { visitor: ["declaration", "specifiers", "source"], - aliases: ["Flow", "FlowDeclaration", "Statement", "Declaration"], + aliases: ["FlowDeclaration", "Statement", "Declaration"], fields: { declaration: validateOptionalType("Flow"), specifiers: validateOptional( @@ -148,7 +150,7 @@ defineType("DeclareExportDeclaration", { defineType("DeclareExportAllDeclaration", { visitor: ["source"], - aliases: ["Flow", "FlowDeclaration", "Statement", "Declaration"], + aliases: ["FlowDeclaration", "Statement", "Declaration"], fields: { source: validateType("StringLiteral"), exportKind: validateOptional(assertOneOf("type", "value")), @@ -157,19 +159,19 @@ defineType("DeclareExportAllDeclaration", { defineType("DeclaredPredicate", { visitor: ["value"], - aliases: ["Flow", "FlowPredicate"], + aliases: ["FlowPredicate"], fields: { value: validateType("Flow"), }, }); defineType("ExistsTypeAnnotation", { - aliases: ["Flow", "FlowType"], + aliases: ["FlowType"], }); defineType("FunctionTypeAnnotation", { visitor: ["typeParameters", "params", "rest", "returnType"], - aliases: ["Flow", "FlowType"], + aliases: ["FlowType"], fields: { typeParameters: validateOptionalType("TypeParameterDeclaration"), params: validate(arrayOfType("FunctionTypeParam")), @@ -181,7 +183,6 @@ defineType("FunctionTypeAnnotation", { defineType("FunctionTypeParam", { visitor: ["name", "typeAnnotation"], - aliases: ["Flow"], fields: { name: validateOptionalType("Identifier"), typeAnnotation: validateType("FlowType"), @@ -191,7 +192,7 @@ defineType("FunctionTypeParam", { defineType("GenericTypeAnnotation", { visitor: ["id", "typeParameters"], - aliases: ["Flow", "FlowType"], + aliases: ["FlowType"], fields: { id: validateType(["Identifier", "QualifiedTypeIdentifier"]), typeParameters: validateOptionalType("TypeParameterInstantiation"), @@ -199,12 +200,11 @@ defineType("GenericTypeAnnotation", { }); defineType("InferredPredicate", { - aliases: ["Flow", "FlowPredicate"], + aliases: ["FlowPredicate"], }); defineType("InterfaceExtends", { visitor: ["id", "typeParameters"], - aliases: ["Flow"], fields: { id: validateType(["Identifier", "QualifiedTypeIdentifier"]), typeParameters: validateOptionalType("TypeParameterInstantiation"), @@ -215,7 +215,7 @@ defineInterfaceishType("InterfaceDeclaration"); defineType("InterfaceTypeAnnotation", { visitor: ["extends", "body"], - aliases: ["Flow", "FlowType"], + aliases: ["FlowType"], fields: { extends: validateOptional(arrayOfType("InterfaceExtends")), body: validateType("ObjectTypeAnnotation"), @@ -224,23 +224,23 @@ defineType("InterfaceTypeAnnotation", { defineType("IntersectionTypeAnnotation", { visitor: ["types"], - aliases: ["Flow", "FlowType"], + aliases: ["FlowType"], fields: { types: validate(arrayOfType("FlowType")), }, }); defineType("MixedTypeAnnotation", { - aliases: ["Flow", "FlowType", "FlowBaseAnnotation"], + aliases: ["FlowType", "FlowBaseAnnotation"], }); defineType("EmptyTypeAnnotation", { - aliases: ["Flow", "FlowType", "FlowBaseAnnotation"], + aliases: ["FlowType", "FlowBaseAnnotation"], }); defineType("NullableTypeAnnotation", { visitor: ["typeAnnotation"], - aliases: ["Flow", "FlowType"], + aliases: ["FlowType"], fields: { typeAnnotation: validateType("FlowType"), }, @@ -248,19 +248,19 @@ defineType("NullableTypeAnnotation", { defineType("NumberLiteralTypeAnnotation", { builder: ["value"], - aliases: ["Flow", "FlowType"], + aliases: ["FlowType"], fields: { value: validate(assertValueType("number")), }, }); defineType("NumberTypeAnnotation", { - aliases: ["Flow", "FlowType", "FlowBaseAnnotation"], + aliases: ["FlowType", "FlowBaseAnnotation"], }); defineType("ObjectTypeAnnotation", { visitor: ["properties", "indexers", "callProperties", "internalSlots"], - aliases: ["Flow", "FlowType"], + aliases: ["FlowType"], builder: [ "properties", "indexers", @@ -288,7 +288,7 @@ defineType("ObjectTypeAnnotation", { defineType("ObjectTypeInternalSlot", { visitor: ["id", "value", "optional", "static", "method"], - aliases: ["Flow", "UserWhitespacable"], + aliases: ["UserWhitespacable"], fields: { id: validateType("Identifier"), value: validateType("FlowType"), @@ -300,7 +300,7 @@ defineType("ObjectTypeInternalSlot", { defineType("ObjectTypeCallProperty", { visitor: ["value"], - aliases: ["Flow", "UserWhitespacable"], + aliases: ["UserWhitespacable"], fields: { value: validateType("FlowType"), static: validate(assertValueType("boolean")), @@ -309,7 +309,7 @@ defineType("ObjectTypeCallProperty", { defineType("ObjectTypeIndexer", { visitor: ["id", "key", "value", "variance"], - aliases: ["Flow", "UserWhitespacable"], + aliases: ["UserWhitespacable"], fields: { id: validateOptionalType("Identifier"), key: validateType("FlowType"), @@ -321,7 +321,7 @@ defineType("ObjectTypeIndexer", { defineType("ObjectTypeProperty", { visitor: ["key", "value", "variance"], - aliases: ["Flow", "UserWhitespacable"], + aliases: ["UserWhitespacable"], fields: { key: validateType(["Identifier", "StringLiteral"]), value: validateType("FlowType"), @@ -336,7 +336,7 @@ defineType("ObjectTypeProperty", { defineType("ObjectTypeSpreadProperty", { visitor: ["argument"], - aliases: ["Flow", "UserWhitespacable"], + aliases: ["UserWhitespacable"], fields: { argument: validateType("FlowType"), }, @@ -344,7 +344,7 @@ defineType("ObjectTypeSpreadProperty", { defineType("OpaqueType", { visitor: ["id", "typeParameters", "supertype", "impltype"], - aliases: ["Flow", "FlowDeclaration", "Statement", "Declaration"], + aliases: ["FlowDeclaration", "Statement", "Declaration"], fields: { id: validateType("Identifier"), typeParameters: validateOptionalType("TypeParameterDeclaration"), @@ -355,7 +355,6 @@ defineType("OpaqueType", { defineType("QualifiedTypeIdentifier", { visitor: ["id", "qualification"], - aliases: ["Flow"], fields: { id: validateType("Identifier"), qualification: validateType(["Identifier", "QualifiedTypeIdentifier"]), @@ -364,27 +363,27 @@ defineType("QualifiedTypeIdentifier", { defineType("StringLiteralTypeAnnotation", { builder: ["value"], - aliases: ["Flow", "FlowType"], + aliases: ["FlowType"], fields: { value: validate(assertValueType("string")), }, }); defineType("StringTypeAnnotation", { - aliases: ["Flow", "FlowType", "FlowBaseAnnotation"], + aliases: ["FlowType", "FlowBaseAnnotation"], }); defineType("SymbolTypeAnnotation", { - aliases: ["Flow", "FlowType", "FlowBaseAnnotation"], + aliases: ["FlowType", "FlowBaseAnnotation"], }); defineType("ThisTypeAnnotation", { - aliases: ["Flow", "FlowType", "FlowBaseAnnotation"], + aliases: ["FlowType", "FlowBaseAnnotation"], }); defineType("TupleTypeAnnotation", { visitor: ["types"], - aliases: ["Flow", "FlowType"], + aliases: ["FlowType"], fields: { types: validate(arrayOfType("FlowType")), }, @@ -392,7 +391,7 @@ defineType("TupleTypeAnnotation", { defineType("TypeofTypeAnnotation", { visitor: ["argument"], - aliases: ["Flow", "FlowType"], + aliases: ["FlowType"], fields: { argument: validateType("FlowType"), }, @@ -400,7 +399,7 @@ defineType("TypeofTypeAnnotation", { defineType("TypeAlias", { visitor: ["id", "typeParameters", "right"], - aliases: ["Flow", "FlowDeclaration", "Statement", "Declaration"], + aliases: ["FlowDeclaration", "Statement", "Declaration"], fields: { id: validateType("Identifier"), typeParameters: validateOptionalType("TypeParameterDeclaration"), @@ -409,7 +408,6 @@ defineType("TypeAlias", { }); defineType("TypeAnnotation", { - aliases: ["Flow"], visitor: ["typeAnnotation"], fields: { typeAnnotation: validateType("FlowType"), @@ -418,7 +416,7 @@ defineType("TypeAnnotation", { defineType("TypeCastExpression", { visitor: ["expression", "typeAnnotation"], - aliases: ["Flow", "ExpressionWrapper", "Expression"], + aliases: ["ExpressionWrapper", "Expression"], fields: { expression: validateType("Expression"), typeAnnotation: validateType("TypeAnnotation"), @@ -426,7 +424,6 @@ defineType("TypeCastExpression", { }); defineType("TypeParameter", { - aliases: ["Flow"], visitor: ["bound", "default", "variance"], fields: { name: validate(assertValueType("string")), @@ -437,7 +434,6 @@ defineType("TypeParameter", { }); defineType("TypeParameterDeclaration", { - aliases: ["Flow"], visitor: ["params"], fields: { params: validate(arrayOfType("TypeParameter")), @@ -445,7 +441,6 @@ defineType("TypeParameterDeclaration", { }); defineType("TypeParameterInstantiation", { - aliases: ["Flow"], visitor: ["params"], fields: { params: validate(arrayOfType("FlowType")), @@ -454,14 +449,13 @@ defineType("TypeParameterInstantiation", { defineType("UnionTypeAnnotation", { visitor: ["types"], - aliases: ["Flow", "FlowType"], + aliases: ["FlowType"], fields: { types: validate(arrayOfType("FlowType")), }, }); defineType("Variance", { - aliases: ["Flow"], builder: ["kind"], fields: { kind: validate(assertOneOf("minus", "plus")), @@ -469,7 +463,7 @@ defineType("Variance", { }); defineType("VoidTypeAnnotation", { - aliases: ["Flow", "FlowType", "FlowBaseAnnotation"], + aliases: ["FlowType", "FlowBaseAnnotation"], }); // Enums @@ -563,7 +557,7 @@ defineType("EnumDefaultedMember", { defineType("IndexedAccessType", { visitor: ["objectType", "indexType"], - aliases: ["Flow", "FlowType"], + aliases: ["FlowType"], fields: { objectType: validateType("FlowType"), indexType: validateType("FlowType"), @@ -572,7 +566,7 @@ defineType("IndexedAccessType", { defineType("OptionalIndexedAccessType", { visitor: ["objectType", "indexType"], - aliases: ["Flow", "FlowType"], + aliases: ["FlowType"], fields: { objectType: validateType("FlowType"), indexType: validateType("FlowType"), diff --git a/packages/babel-types/src/definitions/jsx.ts b/packages/babel-types/src/definitions/jsx.ts index 566236031e72..e650008740de 100644 --- a/packages/babel-types/src/definitions/jsx.ts +++ b/packages/babel-types/src/definitions/jsx.ts @@ -1,13 +1,16 @@ -import defineType, { +import { + defineAliasedType, assertNodeType, assertValueType, chain, assertEach, } from "./utils"; +const defineType = defineAliasedType("JSX"); + defineType("JSXAttribute", { visitor: ["name", "value"], - aliases: ["JSX", "Immutable"], + aliases: ["Immutable"], fields: { name: { validate: assertNodeType("JSXIdentifier", "JSXNamespacedName"), @@ -26,7 +29,7 @@ defineType("JSXAttribute", { defineType("JSXClosingElement", { visitor: ["name"], - aliases: ["JSX", "Immutable"], + aliases: ["Immutable"], fields: { name: { validate: assertNodeType( @@ -41,7 +44,7 @@ defineType("JSXClosingElement", { defineType("JSXElement", { builder: ["openingElement", "closingElement", "children", "selfClosing"], visitor: ["openingElement", "children", "closingElement"], - aliases: ["JSX", "Immutable", "Expression"], + aliases: ["Immutable", "Expression"], fields: { openingElement: { validate: assertNodeType("JSXOpeningElement"), @@ -71,13 +74,11 @@ defineType("JSXElement", { }, }); -defineType("JSXEmptyExpression", { - aliases: ["JSX"], -}); +defineType("JSXEmptyExpression", {}); defineType("JSXExpressionContainer", { visitor: ["expression"], - aliases: ["JSX", "Immutable"], + aliases: ["Immutable"], fields: { expression: { validate: assertNodeType("Expression", "JSXEmptyExpression"), @@ -87,7 +88,7 @@ defineType("JSXExpressionContainer", { defineType("JSXSpreadChild", { visitor: ["expression"], - aliases: ["JSX", "Immutable"], + aliases: ["Immutable"], fields: { expression: { validate: assertNodeType("Expression"), @@ -97,7 +98,6 @@ defineType("JSXSpreadChild", { defineType("JSXIdentifier", { builder: ["name"], - aliases: ["JSX"], fields: { name: { validate: assertValueType("string"), @@ -107,7 +107,6 @@ defineType("JSXIdentifier", { defineType("JSXMemberExpression", { visitor: ["object", "property"], - aliases: ["JSX"], fields: { object: { validate: assertNodeType("JSXMemberExpression", "JSXIdentifier"), @@ -120,7 +119,6 @@ defineType("JSXMemberExpression", { defineType("JSXNamespacedName", { visitor: ["namespace", "name"], - aliases: ["JSX"], fields: { namespace: { validate: assertNodeType("JSXIdentifier"), @@ -134,7 +132,7 @@ defineType("JSXNamespacedName", { defineType("JSXOpeningElement", { builder: ["name", "attributes", "selfClosing"], visitor: ["name", "attributes"], - aliases: ["JSX", "Immutable"], + aliases: ["Immutable"], fields: { name: { validate: assertNodeType( @@ -164,7 +162,6 @@ defineType("JSXOpeningElement", { defineType("JSXSpreadAttribute", { visitor: ["argument"], - aliases: ["JSX"], fields: { argument: { validate: assertNodeType("Expression"), @@ -173,7 +170,7 @@ defineType("JSXSpreadAttribute", { }); defineType("JSXText", { - aliases: ["JSX", "Immutable"], + aliases: ["Immutable"], builder: ["value"], fields: { value: { @@ -185,7 +182,7 @@ defineType("JSXText", { defineType("JSXFragment", { builder: ["openingFragment", "closingFragment", "children"], visitor: ["openingFragment", "children", "closingFragment"], - aliases: ["JSX", "Immutable", "Expression"], + aliases: ["Immutable", "Expression"], fields: { openingFragment: { validate: assertNodeType("JSXOpeningFragment"), @@ -211,9 +208,9 @@ defineType("JSXFragment", { }); defineType("JSXOpeningFragment", { - aliases: ["JSX", "Immutable"], + aliases: ["Immutable"], }); defineType("JSXClosingFragment", { - aliases: ["JSX", "Immutable"], + aliases: ["Immutable"], }); diff --git a/packages/babel-types/src/definitions/misc.ts b/packages/babel-types/src/definitions/misc.ts index 7624706cd4e0..228b9b0d523a 100644 --- a/packages/babel-types/src/definitions/misc.ts +++ b/packages/babel-types/src/definitions/misc.ts @@ -1,10 +1,13 @@ -import defineType, { +import { + defineAliasedType, assertNodeType, assertOneOf, assertValueType, } from "./utils"; import { PLACEHOLDERS } from "./placeholders"; +const defineType = defineAliasedType("Miscellaneous"); + if (!process.env.BABEL_8_BREAKING) { defineType("Noop", { visitor: [], diff --git a/packages/babel-types/src/definitions/typescript.ts b/packages/babel-types/src/definitions/typescript.ts index bd70b4467a1f..373f4a6757e0 100644 --- a/packages/babel-types/src/definitions/typescript.ts +++ b/packages/babel-types/src/definitions/typescript.ts @@ -1,4 +1,5 @@ -import defineType, { +import { + defineAliasedType, arrayOfType, assertEach, assertNodeType, @@ -17,6 +18,8 @@ import { } from "./core"; import is from "../validators/is"; +const defineType = defineAliasedType("TypeScript"); + const bool = assertValueType("boolean"); const tSFunctionTypeAnnotationCommon = { diff --git a/packages/babel-types/src/definitions/utils.ts b/packages/babel-types/src/definitions/utils.ts index a93fec055730..6ed5ce96b370 100644 --- a/packages/babel-types/src/definitions/utils.ts +++ b/packages/babel-types/src/definitions/utils.ts @@ -19,6 +19,18 @@ function getType(val) { } } +type DefineTypeOpts = { + fields?: { + [x: string]: FieldOptions; + }; + visitor?: Array; + aliases?: Array; + builder?: Array; + inherits?: string; + deprecatedAlias?: string; + validate?: Validator; +}; + type Validator = ( | { type: string } | { each: Validator } @@ -256,20 +268,22 @@ const validTypeOpts = [ ]; const validFieldKeys = ["default", "optional", "validate"]; -export default function defineType( - type: string, - opts: { - fields?: { - [x: string]: FieldOptions; - }; - visitor?: Array; - aliases?: Array; - builder?: Array; - inherits?: string; - deprecatedAlias?: string; - validate?: Validator; - } = {}, -) { +// Wraps defineType to ensure these aliases are included. +export function defineAliasedType(...aliases: string[]) { + return (type: string, opts: DefineTypeOpts = {}) => { + let defined = opts.aliases; + if (!defined) { + if (opts.inherits) defined = store[opts.inherits].aliases?.slice(); + defined ??= []; + opts.aliases = defined; + } + const additional = aliases.filter(a => !defined.includes(a)); + defined.unshift(...additional); + return defineType(type, opts); + }; +} + +export default function defineType(type: string, opts: DefineTypeOpts = {}) { const inherits = (opts.inherits && store[opts.inherits]) || {}; let fields = opts.fields; diff --git a/packages/babel-types/src/validators/generated/index.ts b/packages/babel-types/src/validators/generated/index.ts index 7a2509842d27..c65613f85ef6 100755 --- a/packages/babel-types/src/validators/generated/index.ts +++ b/packages/babel-types/src/validators/generated/index.ts @@ -4187,6 +4187,114 @@ export function isTSTypeParameter( return false; } +export function isStandardized( + node: object | null | undefined, + opts?: object | null, +): node is t.Standardized { + if (!node) return false; + + const nodeType = (node as t.Node).type; + if ( + "ArrayExpression" === nodeType || + "AssignmentExpression" === nodeType || + "BinaryExpression" === nodeType || + "InterpreterDirective" === nodeType || + "Directive" === nodeType || + "DirectiveLiteral" === nodeType || + "BlockStatement" === nodeType || + "BreakStatement" === nodeType || + "CallExpression" === nodeType || + "CatchClause" === nodeType || + "ConditionalExpression" === nodeType || + "ContinueStatement" === nodeType || + "DebuggerStatement" === nodeType || + "DoWhileStatement" === nodeType || + "EmptyStatement" === nodeType || + "ExpressionStatement" === nodeType || + "File" === nodeType || + "ForInStatement" === nodeType || + "ForStatement" === nodeType || + "FunctionDeclaration" === nodeType || + "FunctionExpression" === nodeType || + "Identifier" === nodeType || + "IfStatement" === nodeType || + "LabeledStatement" === nodeType || + "StringLiteral" === nodeType || + "NumericLiteral" === nodeType || + "NullLiteral" === nodeType || + "BooleanLiteral" === nodeType || + "RegExpLiteral" === nodeType || + "LogicalExpression" === nodeType || + "MemberExpression" === nodeType || + "NewExpression" === nodeType || + "Program" === nodeType || + "ObjectExpression" === nodeType || + "ObjectMethod" === nodeType || + "ObjectProperty" === nodeType || + "RestElement" === nodeType || + "ReturnStatement" === nodeType || + "SequenceExpression" === nodeType || + "ParenthesizedExpression" === nodeType || + "SwitchCase" === nodeType || + "SwitchStatement" === nodeType || + "ThisExpression" === nodeType || + "ThrowStatement" === nodeType || + "TryStatement" === nodeType || + "UnaryExpression" === nodeType || + "UpdateExpression" === nodeType || + "VariableDeclaration" === nodeType || + "VariableDeclarator" === nodeType || + "WhileStatement" === nodeType || + "WithStatement" === nodeType || + "AssignmentPattern" === nodeType || + "ArrayPattern" === nodeType || + "ArrowFunctionExpression" === nodeType || + "ClassBody" === nodeType || + "ClassExpression" === nodeType || + "ClassDeclaration" === nodeType || + "ExportAllDeclaration" === nodeType || + "ExportDefaultDeclaration" === nodeType || + "ExportNamedDeclaration" === nodeType || + "ExportSpecifier" === nodeType || + "ForOfStatement" === nodeType || + "ImportDeclaration" === nodeType || + "ImportDefaultSpecifier" === nodeType || + "ImportNamespaceSpecifier" === nodeType || + "ImportSpecifier" === nodeType || + "MetaProperty" === nodeType || + "ClassMethod" === nodeType || + "ObjectPattern" === nodeType || + "SpreadElement" === nodeType || + "Super" === nodeType || + "TaggedTemplateExpression" === nodeType || + "TemplateElement" === nodeType || + "TemplateLiteral" === nodeType || + "YieldExpression" === nodeType || + "AwaitExpression" === nodeType || + "Import" === nodeType || + "BigIntLiteral" === nodeType || + "ExportNamespaceSpecifier" === nodeType || + "OptionalMemberExpression" === nodeType || + "OptionalCallExpression" === nodeType || + "ClassProperty" === nodeType || + "ClassPrivateProperty" === nodeType || + "ClassPrivateMethod" === nodeType || + "PrivateName" === nodeType || + (nodeType === "Placeholder" && + ("Identifier" === (node as t.Placeholder).expectedNode || + "StringLiteral" === (node as t.Placeholder).expectedNode || + "BlockStatement" === (node as t.Placeholder).expectedNode || + "ClassBody" === (node as t.Placeholder).expectedNode)) + ) { + if (typeof opts === "undefined") { + return true; + } else { + return shallowEqual(node, opts); + } + } + + return false; +} export function isExpression( node: object | null | undefined, opts?: object | null, @@ -5160,6 +5268,15 @@ export function isFlow( "UnionTypeAnnotation" === nodeType || "Variance" === nodeType || "VoidTypeAnnotation" === nodeType || + "EnumDeclaration" === nodeType || + "EnumBooleanBody" === nodeType || + "EnumNumberBody" === nodeType || + "EnumStringBody" === nodeType || + "EnumSymbolBody" === nodeType || + "EnumBooleanMember" === nodeType || + "EnumNumberMember" === nodeType || + "EnumStringMember" === nodeType || + "EnumDefaultedMember" === nodeType || "IndexedAccessType" === nodeType || "OptionalIndexedAccessType" === nodeType ) { @@ -5369,6 +5486,108 @@ export function isJSX( return false; } +export function isMiscellaneous( + node: object | null | undefined, + opts?: object | null, +): node is t.Miscellaneous { + if (!node) return false; + + const nodeType = (node as t.Node).type; + if ( + "Noop" === nodeType || + "Placeholder" === nodeType || + "V8IntrinsicIdentifier" === nodeType + ) { + if (typeof opts === "undefined") { + return true; + } else { + return shallowEqual(node, opts); + } + } + + return false; +} +export function isTypeScript( + node: object | null | undefined, + opts?: object | null, +): node is t.TypeScript { + if (!node) return false; + + const nodeType = (node as t.Node).type; + if ( + "TSParameterProperty" === nodeType || + "TSDeclareFunction" === nodeType || + "TSDeclareMethod" === nodeType || + "TSQualifiedName" === nodeType || + "TSCallSignatureDeclaration" === nodeType || + "TSConstructSignatureDeclaration" === nodeType || + "TSPropertySignature" === nodeType || + "TSMethodSignature" === nodeType || + "TSIndexSignature" === nodeType || + "TSAnyKeyword" === nodeType || + "TSBooleanKeyword" === nodeType || + "TSBigIntKeyword" === nodeType || + "TSIntrinsicKeyword" === nodeType || + "TSNeverKeyword" === nodeType || + "TSNullKeyword" === nodeType || + "TSNumberKeyword" === nodeType || + "TSObjectKeyword" === nodeType || + "TSStringKeyword" === nodeType || + "TSSymbolKeyword" === nodeType || + "TSUndefinedKeyword" === nodeType || + "TSUnknownKeyword" === nodeType || + "TSVoidKeyword" === nodeType || + "TSThisType" === nodeType || + "TSFunctionType" === nodeType || + "TSConstructorType" === nodeType || + "TSTypeReference" === nodeType || + "TSTypePredicate" === nodeType || + "TSTypeQuery" === nodeType || + "TSTypeLiteral" === nodeType || + "TSArrayType" === nodeType || + "TSTupleType" === nodeType || + "TSOptionalType" === nodeType || + "TSRestType" === nodeType || + "TSNamedTupleMember" === nodeType || + "TSUnionType" === nodeType || + "TSIntersectionType" === nodeType || + "TSConditionalType" === nodeType || + "TSInferType" === nodeType || + "TSParenthesizedType" === nodeType || + "TSTypeOperator" === nodeType || + "TSIndexedAccessType" === nodeType || + "TSMappedType" === nodeType || + "TSLiteralType" === nodeType || + "TSExpressionWithTypeArguments" === nodeType || + "TSInterfaceDeclaration" === nodeType || + "TSInterfaceBody" === nodeType || + "TSTypeAliasDeclaration" === nodeType || + "TSAsExpression" === nodeType || + "TSTypeAssertion" === nodeType || + "TSEnumDeclaration" === nodeType || + "TSEnumMember" === nodeType || + "TSModuleDeclaration" === nodeType || + "TSModuleBlock" === nodeType || + "TSImportType" === nodeType || + "TSImportEqualsDeclaration" === nodeType || + "TSExternalModuleReference" === nodeType || + "TSNonNullExpression" === nodeType || + "TSExportAssignment" === nodeType || + "TSNamespaceExportDeclaration" === nodeType || + "TSTypeAnnotation" === nodeType || + "TSTypeParameterInstantiation" === nodeType || + "TSTypeParameterDeclaration" === nodeType || + "TSTypeParameter" === nodeType + ) { + if (typeof opts === "undefined") { + return true; + } else { + return shallowEqual(node, opts); + } + } + + return false; +} export function isTSTypeElement( node: object | null | undefined, opts?: object | null,