From 7bfc8fd66bf27b2be5976626e089720ad45c05ae Mon Sep 17 00:00:00 2001 From: Justin Ridgewell Date: Wed, 11 Aug 2021 01:43:51 -0400 Subject: [PATCH 1/8] Ensure non-standard types have an appropriate alias This helps with filter out the types. Eg, I'm concerned with just the core JS types, and in I can derive them via: ```typescript type Core = Exclude; ``` --- .../src/path/generated/asserts.ts | 2 + .../src/path/generated/validators.ts | 2 + .../src/asserts/generated/index.ts | 12 ++ .../src/ast-types/generated/index.ts | 78 ++++++++++++ .../src/constants/generated/index.ts | 2 + packages/babel-types/src/definitions/flow.ts | 104 ++++++++-------- packages/babel-types/src/definitions/jsx.ts | 30 +++-- packages/babel-types/src/definitions/misc.ts | 5 +- .../babel-types/src/definitions/typescript.ts | 5 +- packages/babel-types/src/definitions/utils.ts | 37 +++--- .../src/validators/generated/index.ts | 111 ++++++++++++++++++ 11 files changed, 301 insertions(+), 87 deletions(-) diff --git a/packages/babel-traverse/src/path/generated/asserts.ts b/packages/babel-traverse/src/path/generated/asserts.ts index 3acc28f3fbb8..bfb57eb19f30 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; @@ -660,6 +661,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..6214cce51692 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; @@ -399,6 +400,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/src/asserts/generated/index.ts b/packages/babel-types/src/asserts/generated/index.ts index c171b27816cf..f1f8f3445d7f 100755 --- a/packages/babel-types/src/asserts/generated/index.ts +++ b/packages/babel-types/src/asserts/generated/index.ts @@ -1742,6 +1742,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..4e5657eac0aa 100755 --- a/packages/babel-types/src/ast-types/generated/index.ts +++ b/packages/babel-types/src/ast-types/generated/index.ts @@ -182,6 +182,7 @@ export type Node = | MemberExpression | MetaProperty | Method + | Miscellaneous | MixedTypeAnnotation | ModuleDeclaration | ModuleExpression @@ -326,6 +327,7 @@ export type Node = | TypeParameter | TypeParameterDeclaration | TypeParameterInstantiation + | TypeScript | TypeofTypeAnnotation | UnaryExpression | UnaryLike @@ -2398,6 +2400,15 @@ export type Flow = | UnionTypeAnnotation | Variance | VoidTypeAnnotation + | EnumDeclaration + | EnumBooleanBody + | EnumNumberBody + | EnumStringBody + | EnumSymbolBody + | EnumBooleanMember + | EnumNumberMember + | EnumStringMember + | EnumDefaultedMember | IndexedAccessType | OptionalIndexedAccessType; export type FlowType = @@ -2479,6 +2490,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 @@ -2581,6 +2657,8 @@ export interface Aliases { EnumBody: EnumBody; EnumMember: EnumMember; JSX: JSX; + Miscellaneous: Miscellaneous; + TypeScript: TypeScript; TSTypeElement: TSTypeElement; TSType: TSType; TSBaseType: TSBaseType; diff --git a/packages/babel-types/src/constants/generated/index.ts b/packages/babel-types/src/constants/generated/index.ts index 39342664168f..7cb93ed9580e 100755 --- a/packages/babel-types/src/constants/generated/index.ts +++ b/packages/babel-types/src/constants/generated/index.ts @@ -48,6 +48,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/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..61bb29f493a8 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"), @@ -72,12 +75,11 @@ defineType("JSXElement", { }); defineType("JSXEmptyExpression", { - aliases: ["JSX"], }); defineType("JSXExpressionContainer", { visitor: ["expression"], - aliases: ["JSX", "Immutable"], + aliases: ["Immutable"], fields: { expression: { validate: assertNodeType("Expression", "JSXEmptyExpression"), @@ -87,7 +89,7 @@ defineType("JSXExpressionContainer", { defineType("JSXSpreadChild", { visitor: ["expression"], - aliases: ["JSX", "Immutable"], + aliases: ["Immutable"], fields: { expression: { validate: assertNodeType("Expression"), @@ -97,7 +99,6 @@ defineType("JSXSpreadChild", { defineType("JSXIdentifier", { builder: ["name"], - aliases: ["JSX"], fields: { name: { validate: assertValueType("string"), @@ -107,7 +108,6 @@ defineType("JSXIdentifier", { defineType("JSXMemberExpression", { visitor: ["object", "property"], - aliases: ["JSX"], fields: { object: { validate: assertNodeType("JSXMemberExpression", "JSXIdentifier"), @@ -120,7 +120,6 @@ defineType("JSXMemberExpression", { defineType("JSXNamespacedName", { visitor: ["namespace", "name"], - aliases: ["JSX"], fields: { namespace: { validate: assertNodeType("JSXIdentifier"), @@ -134,7 +133,7 @@ defineType("JSXNamespacedName", { defineType("JSXOpeningElement", { builder: ["name", "attributes", "selfClosing"], visitor: ["name", "attributes"], - aliases: ["JSX", "Immutable"], + aliases: ["Immutable"], fields: { name: { validate: assertNodeType( @@ -164,7 +163,6 @@ defineType("JSXOpeningElement", { defineType("JSXSpreadAttribute", { visitor: ["argument"], - aliases: ["JSX"], fields: { argument: { validate: assertNodeType("Expression"), @@ -173,7 +171,7 @@ defineType("JSXSpreadAttribute", { }); defineType("JSXText", { - aliases: ["JSX", "Immutable"], + aliases: ["Immutable"], builder: ["value"], fields: { value: { @@ -185,7 +183,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 +209,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..96564006798f 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..7c3794767d33 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,17 @@ 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 = {}) => { + const defined = (opts.aliases ??= []); + 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..b9251684c2e9 100755 --- a/packages/babel-types/src/validators/generated/index.ts +++ b/packages/babel-types/src/validators/generated/index.ts @@ -5160,6 +5160,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 +5378,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, From ce49936553903097c8de9b70b11d88defe2a30a7 Mon Sep 17 00:00:00 2001 From: Justin Ridgewell Date: Wed, 11 Aug 2021 02:32:37 -0400 Subject: [PATCH 2/8] Lint --- packages/babel-types/src/definitions/jsx.ts | 3 +-- packages/babel-types/src/definitions/misc.ts | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/packages/babel-types/src/definitions/jsx.ts b/packages/babel-types/src/definitions/jsx.ts index 61bb29f493a8..e650008740de 100644 --- a/packages/babel-types/src/definitions/jsx.ts +++ b/packages/babel-types/src/definitions/jsx.ts @@ -74,8 +74,7 @@ defineType("JSXElement", { }, }); -defineType("JSXEmptyExpression", { -}); +defineType("JSXEmptyExpression", {}); defineType("JSXExpressionContainer", { visitor: ["expression"], diff --git a/packages/babel-types/src/definitions/misc.ts b/packages/babel-types/src/definitions/misc.ts index 96564006798f..228b9b0d523a 100644 --- a/packages/babel-types/src/definitions/misc.ts +++ b/packages/babel-types/src/definitions/misc.ts @@ -6,7 +6,7 @@ import { } from "./utils"; import { PLACEHOLDERS } from "./placeholders"; -const defineType = defineAliasedType("Miscellaneous") +const defineType = defineAliasedType("Miscellaneous"); if (!process.env.BABEL_8_BREAKING) { defineType("Noop", { From 9721390164286b0c690af67b3c5095cc0378f44c Mon Sep 17 00:00:00 2001 From: Justin Ridgewell Date: Wed, 11 Aug 2021 03:26:45 -0400 Subject: [PATCH 3/8] Export deprecated alias types --- packages/babel-types/scripts/generators/ast-types.js | 3 +++ packages/babel-types/src/ast-types/generated/index.ts | 6 ++++++ 2 files changed, 9 insertions(+) diff --git a/packages/babel-types/scripts/generators/ast-types.js b/packages/babel-types/scripts/generators/ast-types.js index cd31918a5611..d64a9d81e42a 100644 --- a/packages/babel-types/scripts/generators/ast-types.js +++ b/packages/babel-types/scripts/generators/ast-types.js @@ -115,6 +115,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/src/ast-types/generated/index.ts b/packages/babel-types/src/ast-types/generated/index.ts index 4e5657eac0aa..ebc2110a17c3 100755 --- a/packages/babel-types/src/ast-types/generated/index.ts +++ b/packages/babel-types/src/ast-types/generated/index.ts @@ -2663,3 +2663,9 @@ export interface Aliases { TSType: TSType; TSBaseType: TSBaseType; } + +export type DeprecatedAliases = + | NumberLiteral + | RegexLiteral + | RestProperty + | SpreadProperty; From 1cb6aca0c2fec386d0621cbc861b6aae03129f82 Mon Sep 17 00:00:00 2001 From: Justin Ridgewell Date: Wed, 11 Aug 2021 15:46:10 -0400 Subject: [PATCH 4/8] Add docs descriptions for new aliases --- packages/babel-types/scripts/generators/docs.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/packages/babel-types/scripts/generators/docs.js b/packages/babel-types/scripts/generators/docs.js index f7b82e56d394..4894cdafd283 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: @@ -239,6 +241,7 @@ const aliasDescriptions = { 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.", From b2bd3cd67a5db994bdf191b5db94d553e6912604 Mon Sep 17 00:00:00 2001 From: Justin Ridgewell Date: Sun, 15 Aug 2021 19:37:16 -0400 Subject: [PATCH 5/8] Add Standardized alias --- .../src/path/generated/asserts.ts | 5 + .../src/path/generated/validators.ts | 5 + .../babel-types/scripts/generators/docs.js | 6 + .../src/asserts/generated/index.ts | 18 ++ .../src/ast-types/generated/index.ts | 208 +++++++++++++- .../src/constants/generated/index.ts | 4 + packages/babel-types/src/definitions/core.ts | 5 +- .../src/definitions/experimental.ts | 5 +- .../src/validators/generated/index.ts | 263 +++++++++++++++++- 9 files changed, 515 insertions(+), 4 deletions(-) diff --git a/packages/babel-traverse/src/path/generated/asserts.ts b/packages/babel-traverse/src/path/generated/asserts.ts index bfb57eb19f30..871f209663cb 100755 --- a/packages/babel-traverse/src/path/generated/asserts.ts +++ b/packages/babel-traverse/src/path/generated/asserts.ts @@ -416,6 +416,7 @@ export interface NodePathAssetions { assertPrivateName(opts?: object): asserts this is NodePath; assertProgram(opts?: object): asserts this is NodePath; assertProperty(opts?: object): asserts this is NodePath; + assertProposal(opts?: object): asserts this is NodePath; assertPureish(opts?: object): asserts this is NodePath; assertQualifiedTypeIdentifier( opts?: object, @@ -438,6 +439,10 @@ export interface NodePathAssetions { assertSpreadProperty( opts?: object, ): asserts this is NodePath; + assertStandardized(opts?: object): asserts this is NodePath; + assertStandardizedOrProposal( + 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; diff --git a/packages/babel-traverse/src/path/generated/validators.ts b/packages/babel-traverse/src/path/generated/validators.ts index 6214cce51692..9e7781917e94 100755 --- a/packages/babel-traverse/src/path/generated/validators.ts +++ b/packages/babel-traverse/src/path/generated/validators.ts @@ -261,6 +261,7 @@ export interface NodePathValidators { isPrivateName(opts?: object): this is NodePath; isProgram(opts?: object): this is NodePath; isProperty(opts?: object): this is NodePath; + isProposal(opts?: object): this is NodePath; isPureish(opts?: object): this is NodePath; isQualifiedTypeIdentifier( opts?: object, @@ -275,6 +276,10 @@ 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; + isStandardizedOrProposal( + opts?: object, + ): this is NodePath; isStatement(opts?: object): this is NodePath; isStaticBlock(opts?: object): this is NodePath; isStringLiteral(opts?: object): this is NodePath; diff --git a/packages/babel-types/scripts/generators/docs.js b/packages/babel-types/scripts/generators/docs.js index 4894cdafd283..1ce0a79897d8 100644 --- a/packages/babel-types/scripts/generators/docs.js +++ b/packages/babel-types/scripts/generators/docs.js @@ -231,10 +231,16 @@ const aliasDescriptions = { "A cover of [BindingPattern](https://tc39.es/ecma262/#prod-BindingPattern)s. ", Private: "A cover of private class elements and private identifiers.", Property: "A cover of object properties and class properties.", + Proposal: + "A cover of AST nodes which are proprosed for inclusion in ECMAScript.", Pureish: "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.", + StandardizedOrProposal: + "A cover of AST nodes which are part of an official ECMAScript specification or a proposed for inclusion.", Statement: "A cover of any [Statement](https://tc39.es/ecma262/#prod-Statement)s.", TSBaseType: "A cover of primary TypeScript type annotations.", diff --git a/packages/babel-types/src/asserts/generated/index.ts b/packages/babel-types/src/asserts/generated/index.ts index f1f8f3445d7f..b4d8e3747faa 100755 --- a/packages/babel-types/src/asserts/generated/index.ts +++ b/packages/babel-types/src/asserts/generated/index.ts @@ -1490,6 +1490,18 @@ 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 assertStandardizedOrProposal( + node: object | null | undefined, + opts?: object | null, +): asserts node is t.StandardizedOrProposal { + assert("StandardizedOrProposal", node, opts); +} export function assertExpression( node: object | null | undefined, opts?: object | null, @@ -1748,6 +1760,12 @@ export function assertMiscellaneous( ): asserts node is t.Miscellaneous { assert("Miscellaneous", node, opts); } +export function assertProposal( + node: object | null | undefined, + opts?: object | null, +): asserts node is t.Proposal { + assert("Proposal", node, opts); +} export function assertTypeScript( 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 ebc2110a17c3..f626993c8cf9 100755 --- a/packages/babel-types/src/ast-types/generated/index.ts +++ b/packages/babel-types/src/ast-types/generated/index.ts @@ -222,6 +222,7 @@ export type Node = | PrivateName | Program | Property + | Proposal | Pureish | QualifiedTypeIdentifier | RecordExpression @@ -234,6 +235,8 @@ export type Node = | SequenceExpression | SpreadElement | SpreadProperty + | Standardized + | StandardizedOrProposal | Statement | StaticBlock | StringLiteral @@ -2057,14 +2060,117 @@ export interface TSTypeParameter extends BaseNode { name: string; } -export type Expression = +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 StandardizedOrProposal = | 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 @@ -2073,6 +2179,88 @@ export type Expression = | 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 + | ArgumentPlaceholder + | BindExpression + | PipelineTopicExpression + | PipelineBareFunction + | PipelinePrimaryTopicReference + | ImportAttribute + | Decorator + | DoExpression + | ExportDefaultSpecifier + | RecordExpression + | TupleExpression + | DecimalLiteral + | StaticBlock + | ModuleExpression; +export type Expression = + | ArrayExpression + | AssignmentExpression + | BinaryExpression + | CallExpression + | ConditionalExpression + | FunctionExpression + | Identifier + | StringLiteral + | NumericLiteral + | NullLiteral + | BooleanLiteral + | RegExpLiteral + | LogicalExpression + | MemberExpression | ObjectExpression | SequenceExpression | ParenthesizedExpression @@ -2491,6 +2679,21 @@ export type JSX = | JSXOpeningFragment | JSXClosingFragment; export type Miscellaneous = Noop | Placeholder | V8IntrinsicIdentifier; +export type Proposal = + | ArgumentPlaceholder + | BindExpression + | PipelineTopicExpression + | PipelineBareFunction + | PipelinePrimaryTopicReference + | ImportAttribute + | Decorator + | DoExpression + | ExportDefaultSpecifier + | RecordExpression + | TupleExpression + | DecimalLiteral + | StaticBlock + | ModuleExpression; export type TypeScript = | TSParameterProperty | TSDeclareFunction @@ -2615,6 +2818,8 @@ export type TSBaseType = | TSLiteralType; export interface Aliases { + Standardized: Standardized; + StandardizedOrProposal: StandardizedOrProposal; Expression: Expression; Binary: Binary; Scopable: Scopable; @@ -2658,6 +2863,7 @@ export interface Aliases { EnumMember: EnumMember; JSX: JSX; Miscellaneous: Miscellaneous; + Proposal: Proposal; TypeScript: TypeScript; TSTypeElement: TSTypeElement; TSType: TSType; diff --git a/packages/babel-types/src/constants/generated/index.ts b/packages/babel-types/src/constants/generated/index.ts index 7cb93ed9580e..effa226acc51 100755 --- a/packages/babel-types/src/constants/generated/index.ts +++ b/packages/babel-types/src/constants/generated/index.ts @@ -4,6 +4,9 @@ */ import { FLIPPED_ALIAS_KEYS } from "../../definitions"; +export const STANDARDIZED_TYPES = FLIPPED_ALIAS_KEYS["Standardized"]; +export const STANDARDIZEDORPROPOSAL_TYPES = + FLIPPED_ALIAS_KEYS["StandardizedOrProposal"]; export const EXPRESSION_TYPES = FLIPPED_ALIAS_KEYS["Expression"]; export const BINARY_TYPES = FLIPPED_ALIAS_KEYS["Binary"]; export const SCOPABLE_TYPES = FLIPPED_ALIAS_KEYS["Scopable"]; @@ -49,6 +52,7 @@ 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 PROPOSAL_TYPES = FLIPPED_ALIAS_KEYS["Proposal"]; export const TYPESCRIPT_TYPES = FLIPPED_ALIAS_KEYS["TypeScript"]; export const TSTYPEELEMENT_TYPES = FLIPPED_ALIAS_KEYS["TSTypeElement"]; export const TSTYPE_TYPES = FLIPPED_ALIAS_KEYS["TSType"]; diff --git a/packages/babel-types/src/definitions/core.ts b/packages/babel-types/src/definitions/core.ts index 6e275614e2be..55052ee6d676 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", "StandardizedOrProposal"); + defineType("ArrayExpression", { fields: { elements: { diff --git a/packages/babel-types/src/definitions/experimental.ts b/packages/babel-types/src/definitions/experimental.ts index 064f25e47f26..f478ec80b086 100644 --- a/packages/babel-types/src/definitions/experimental.ts +++ b/packages/babel-types/src/definitions/experimental.ts @@ -1,10 +1,13 @@ -import defineType, { +import { + defineAliasedType, assertEach, assertNodeType, assertValueType, chain, } from "./utils"; +const defineType = defineAliasedType("Proposal", "StandardizedOrProposal"); + defineType("ArgumentPlaceholder", {}); defineType("BindExpression", { diff --git a/packages/babel-types/src/validators/generated/index.ts b/packages/babel-types/src/validators/generated/index.ts index b9251684c2e9..0691b3b81b3f 100755 --- a/packages/babel-types/src/validators/generated/index.ts +++ b/packages/babel-types/src/validators/generated/index.ts @@ -4187,6 +4187,236 @@ 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 isStandardizedOrProposal( + node: object | null | undefined, + opts?: object | null, +): node is t.StandardizedOrProposal { + 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 || + "ArgumentPlaceholder" === nodeType || + "BindExpression" === nodeType || + "PipelineTopicExpression" === nodeType || + "PipelineBareFunction" === nodeType || + "PipelinePrimaryTopicReference" === nodeType || + "ImportAttribute" === nodeType || + "Decorator" === nodeType || + "DoExpression" === nodeType || + "ExportDefaultSpecifier" === nodeType || + "RecordExpression" === nodeType || + "TupleExpression" === nodeType || + "DecimalLiteral" === nodeType || + "StaticBlock" === nodeType || + "ModuleExpression" === 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, @@ -4209,7 +4439,6 @@ export function isExpression( "RegExpLiteral" === nodeType || "LogicalExpression" === nodeType || "MemberExpression" === nodeType || - "NewExpression" === nodeType || "ObjectExpression" === nodeType || "SequenceExpression" === nodeType || "ParenthesizedExpression" === nodeType || @@ -5399,6 +5628,38 @@ export function isMiscellaneous( return false; } +export function isProposal( + node: object | null | undefined, + opts?: object | null, +): node is t.Proposal { + if (!node) return false; + + const nodeType = (node as t.Node).type; + if ( + "ArgumentPlaceholder" === nodeType || + "BindExpression" === nodeType || + "PipelineTopicExpression" === nodeType || + "PipelineBareFunction" === nodeType || + "PipelinePrimaryTopicReference" === nodeType || + "ImportAttribute" === nodeType || + "Decorator" === nodeType || + "DoExpression" === nodeType || + "ExportDefaultSpecifier" === nodeType || + "RecordExpression" === nodeType || + "TupleExpression" === nodeType || + "DecimalLiteral" === nodeType || + "StaticBlock" === nodeType || + "ModuleExpression" === nodeType + ) { + if (typeof opts === "undefined") { + return true; + } else { + return shallowEqual(node, opts); + } + } + + return false; +} export function isTypeScript( node: object | null | undefined, opts?: object | null, From 517edbcc07d0756202101c38ffb6b8f3c107e9fe Mon Sep 17 00:00:00 2001 From: Justin Ridgewell Date: Sun, 15 Aug 2021 21:01:38 -0400 Subject: [PATCH 6/8] Fix inherits aliases --- .../src/ast-types/generated/index.ts | 19 +++++++++++-------- packages/babel-types/src/definitions/utils.ts | 7 ++++++- .../src/validators/generated/index.ts | 17 ++++++++++------- 3 files changed, 27 insertions(+), 16 deletions(-) diff --git a/packages/babel-types/src/ast-types/generated/index.ts b/packages/babel-types/src/ast-types/generated/index.ts index f626993c8cf9..792edbea05ce 100755 --- a/packages/babel-types/src/ast-types/generated/index.ts +++ b/packages/babel-types/src/ast-types/generated/index.ts @@ -2234,9 +2234,6 @@ export type StandardizedOrProposal = | PrivateName | ArgumentPlaceholder | BindExpression - | PipelineTopicExpression - | PipelineBareFunction - | PipelinePrimaryTopicReference | ImportAttribute | Decorator | DoExpression @@ -2245,7 +2242,11 @@ export type StandardizedOrProposal = | TupleExpression | DecimalLiteral | StaticBlock - | ModuleExpression; + | ModuleExpression + | TopicReference + | PipelineTopicExpression + | PipelineBareFunction + | PipelinePrimaryTopicReference; export type Expression = | ArrayExpression | AssignmentExpression @@ -2261,6 +2262,7 @@ export type Expression = | RegExpLiteral | LogicalExpression | MemberExpression + | NewExpression | ObjectExpression | SequenceExpression | ParenthesizedExpression @@ -2682,9 +2684,6 @@ export type Miscellaneous = Noop | Placeholder | V8IntrinsicIdentifier; export type Proposal = | ArgumentPlaceholder | BindExpression - | PipelineTopicExpression - | PipelineBareFunction - | PipelinePrimaryTopicReference | ImportAttribute | Decorator | DoExpression @@ -2693,7 +2692,11 @@ export type Proposal = | TupleExpression | DecimalLiteral | StaticBlock - | ModuleExpression; + | ModuleExpression + | TopicReference + | PipelineTopicExpression + | PipelineBareFunction + | PipelinePrimaryTopicReference; export type TypeScript = | TSParameterProperty | TSDeclareFunction diff --git a/packages/babel-types/src/definitions/utils.ts b/packages/babel-types/src/definitions/utils.ts index 7c3794767d33..6ed5ce96b370 100644 --- a/packages/babel-types/src/definitions/utils.ts +++ b/packages/babel-types/src/definitions/utils.ts @@ -271,7 +271,12 @@ const validFieldKeys = ["default", "optional", "validate"]; // Wraps defineType to ensure these aliases are included. export function defineAliasedType(...aliases: string[]) { return (type: string, opts: DefineTypeOpts = {}) => { - const defined = (opts.aliases ??= []); + 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); diff --git a/packages/babel-types/src/validators/generated/index.ts b/packages/babel-types/src/validators/generated/index.ts index 0691b3b81b3f..1bdef6bb60a2 100755 --- a/packages/babel-types/src/validators/generated/index.ts +++ b/packages/babel-types/src/validators/generated/index.ts @@ -4390,9 +4390,6 @@ export function isStandardizedOrProposal( "PrivateName" === nodeType || "ArgumentPlaceholder" === nodeType || "BindExpression" === nodeType || - "PipelineTopicExpression" === nodeType || - "PipelineBareFunction" === nodeType || - "PipelinePrimaryTopicReference" === nodeType || "ImportAttribute" === nodeType || "Decorator" === nodeType || "DoExpression" === nodeType || @@ -4402,6 +4399,10 @@ export function isStandardizedOrProposal( "DecimalLiteral" === nodeType || "StaticBlock" === nodeType || "ModuleExpression" === nodeType || + "TopicReference" === nodeType || + "PipelineTopicExpression" === nodeType || + "PipelineBareFunction" === nodeType || + "PipelinePrimaryTopicReference" === nodeType || (nodeType === "Placeholder" && ("Identifier" === (node as t.Placeholder).expectedNode || "StringLiteral" === (node as t.Placeholder).expectedNode || @@ -4439,6 +4440,7 @@ export function isExpression( "RegExpLiteral" === nodeType || "LogicalExpression" === nodeType || "MemberExpression" === nodeType || + "NewExpression" === nodeType || "ObjectExpression" === nodeType || "SequenceExpression" === nodeType || "ParenthesizedExpression" === nodeType || @@ -5638,9 +5640,6 @@ export function isProposal( if ( "ArgumentPlaceholder" === nodeType || "BindExpression" === nodeType || - "PipelineTopicExpression" === nodeType || - "PipelineBareFunction" === nodeType || - "PipelinePrimaryTopicReference" === nodeType || "ImportAttribute" === nodeType || "Decorator" === nodeType || "DoExpression" === nodeType || @@ -5649,7 +5648,11 @@ export function isProposal( "TupleExpression" === nodeType || "DecimalLiteral" === nodeType || "StaticBlock" === nodeType || - "ModuleExpression" === nodeType + "ModuleExpression" === nodeType || + "TopicReference" === nodeType || + "PipelineTopicExpression" === nodeType || + "PipelineBareFunction" === nodeType || + "PipelinePrimaryTopicReference" === nodeType ) { if (typeof opts === "undefined") { return true; From a8187597d63ea70177c278c4870c47edd65fd47b Mon Sep 17 00:00:00 2001 From: Justin Ridgewell Date: Sun, 15 Aug 2021 21:02:38 -0400 Subject: [PATCH 7/8] Filter aliases from node types --- .../scripts/generators/ast-types.js | 4 +- .../src/ast-types/generated/index.ts | 50 ------------------- 2 files changed, 3 insertions(+), 51 deletions(-) diff --git a/packages/babel-types/scripts/generators/ast-types.js b/packages/babel-types/scripts/generators/ast-types.js index d64a9d81e42a..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) { diff --git a/packages/babel-types/src/ast-types/generated/index.ts b/packages/babel-types/src/ast-types/generated/index.ts index 792edbea05ce..10257b1985d4 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,19 +151,12 @@ export type Node = | JSXSpreadAttribute | JSXSpreadChild | JSXText - | LVal | LabeledStatement - | Literal | LogicalExpression - | Loop | MemberExpression | MetaProperty - | Method - | Miscellaneous | MixedTypeAnnotation - | ModuleDeclaration | ModuleExpression - | ModuleSpecifier | NewExpression | Noop | NullLiteral @@ -197,7 +167,6 @@ export type Node = | NumberTypeAnnotation | NumericLiteral | ObjectExpression - | ObjectMember | ObjectMethod | ObjectPattern | ObjectProperty @@ -212,18 +181,12 @@ export type Node = | OptionalIndexedAccessType | OptionalMemberExpression | ParenthesizedExpression - | Pattern - | PatternLike | PipelineBareFunction | PipelinePrimaryTopicReference | PipelineTopicExpression | Placeholder - | Private | PrivateName | Program - | Property - | Proposal - | Pureish | QualifiedTypeIdentifier | RecordExpression | RegExpLiteral @@ -231,13 +194,9 @@ export type Node = | RestElement | RestProperty | ReturnStatement - | Scopable | SequenceExpression | SpreadElement | SpreadProperty - | Standardized - | StandardizedOrProposal - | Statement | StaticBlock | StringLiteral | StringLiteralTypeAnnotation @@ -249,7 +208,6 @@ export type Node = | TSAnyKeyword | TSArrayType | TSAsExpression - | TSBaseType | TSBigIntKeyword | TSBooleanKeyword | TSCallSignatureDeclaration @@ -258,7 +216,6 @@ export type Node = | TSConstructorType | TSDeclareFunction | TSDeclareMethod - | TSEntityName | TSEnumDeclaration | TSEnumMember | TSExportAssignment @@ -296,11 +253,9 @@ export type Node = | TSSymbolKeyword | TSThisType | TSTupleType - | TSType | TSTypeAliasDeclaration | TSTypeAnnotation | TSTypeAssertion - | TSTypeElement | TSTypeLiteral | TSTypeOperator | TSTypeParameter @@ -316,7 +271,6 @@ export type Node = | TaggedTemplateExpression | TemplateElement | TemplateLiteral - | Terminatorless | ThisExpression | ThisTypeAnnotation | ThrowStatement @@ -330,19 +284,15 @@ export type Node = | TypeParameter | TypeParameterDeclaration | TypeParameterInstantiation - | TypeScript | TypeofTypeAnnotation | UnaryExpression - | UnaryLike | UnionTypeAnnotation | UpdateExpression - | UserWhitespacable | V8IntrinsicIdentifier | VariableDeclaration | VariableDeclarator | Variance | VoidTypeAnnotation - | While | WhileStatement | WithStatement | YieldExpression; From 9da61e29026480c1447a34bd21736452ffaae148 Mon Sep 17 00:00:00 2001 From: Justin Ridgewell Date: Mon, 16 Aug 2021 15:34:15 -0400 Subject: [PATCH 8/8] Remove Proposal alias --- .../src/path/generated/asserts.ts | 4 - .../src/path/generated/validators.ts | 4 - .../babel-types/scripts/generators/docs.js | 4 - .../src/asserts/generated/index.ts | 12 -- .../src/ast-types/generated/index.ts | 119 ------------- .../src/constants/generated/index.ts | 3 - packages/babel-types/src/definitions/core.ts | 2 +- .../src/definitions/experimental.ts | 5 +- .../src/validators/generated/index.ts | 156 ------------------ 9 files changed, 2 insertions(+), 307 deletions(-) diff --git a/packages/babel-traverse/src/path/generated/asserts.ts b/packages/babel-traverse/src/path/generated/asserts.ts index 871f209663cb..a0f0c50093b6 100755 --- a/packages/babel-traverse/src/path/generated/asserts.ts +++ b/packages/babel-traverse/src/path/generated/asserts.ts @@ -416,7 +416,6 @@ export interface NodePathAssetions { assertPrivateName(opts?: object): asserts this is NodePath; assertProgram(opts?: object): asserts this is NodePath; assertProperty(opts?: object): asserts this is NodePath; - assertProposal(opts?: object): asserts this is NodePath; assertPureish(opts?: object): asserts this is NodePath; assertQualifiedTypeIdentifier( opts?: object, @@ -440,9 +439,6 @@ export interface NodePathAssetions { opts?: object, ): asserts this is NodePath; assertStandardized(opts?: object): asserts this is NodePath; - assertStandardizedOrProposal( - 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; diff --git a/packages/babel-traverse/src/path/generated/validators.ts b/packages/babel-traverse/src/path/generated/validators.ts index 9e7781917e94..ab7b614d4454 100755 --- a/packages/babel-traverse/src/path/generated/validators.ts +++ b/packages/babel-traverse/src/path/generated/validators.ts @@ -261,7 +261,6 @@ export interface NodePathValidators { isPrivateName(opts?: object): this is NodePath; isProgram(opts?: object): this is NodePath; isProperty(opts?: object): this is NodePath; - isProposal(opts?: object): this is NodePath; isPureish(opts?: object): this is NodePath; isQualifiedTypeIdentifier( opts?: object, @@ -277,9 +276,6 @@ export interface NodePathValidators { isSpreadElement(opts?: object): this is NodePath; isSpreadProperty(opts?: object): this is NodePath; isStandardized(opts?: object): this is NodePath; - isStandardizedOrProposal( - opts?: object, - ): this is NodePath; isStatement(opts?: object): this is NodePath; isStaticBlock(opts?: object): this is NodePath; isStringLiteral(opts?: object): this is NodePath; diff --git a/packages/babel-types/scripts/generators/docs.js b/packages/babel-types/scripts/generators/docs.js index 1ce0a79897d8..e64bb275e98d 100644 --- a/packages/babel-types/scripts/generators/docs.js +++ b/packages/babel-types/scripts/generators/docs.js @@ -231,16 +231,12 @@ const aliasDescriptions = { "A cover of [BindingPattern](https://tc39.es/ecma262/#prod-BindingPattern)s. ", Private: "A cover of private class elements and private identifiers.", Property: "A cover of object properties and class properties.", - Proposal: - "A cover of AST nodes which are proprosed for inclusion in ECMAScript.", Pureish: "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.", - StandardizedOrProposal: - "A cover of AST nodes which are part of an official ECMAScript specification or a proposed for inclusion.", Statement: "A cover of any [Statement](https://tc39.es/ecma262/#prod-Statement)s.", TSBaseType: "A cover of primary TypeScript type annotations.", diff --git a/packages/babel-types/src/asserts/generated/index.ts b/packages/babel-types/src/asserts/generated/index.ts index b4d8e3747faa..5b784c6171e1 100755 --- a/packages/babel-types/src/asserts/generated/index.ts +++ b/packages/babel-types/src/asserts/generated/index.ts @@ -1496,12 +1496,6 @@ export function assertStandardized( ): asserts node is t.Standardized { assert("Standardized", node, opts); } -export function assertStandardizedOrProposal( - node: object | null | undefined, - opts?: object | null, -): asserts node is t.StandardizedOrProposal { - assert("StandardizedOrProposal", node, opts); -} export function assertExpression( node: object | null | undefined, opts?: object | null, @@ -1760,12 +1754,6 @@ export function assertMiscellaneous( ): asserts node is t.Miscellaneous { assert("Miscellaneous", node, opts); } -export function assertProposal( - node: object | null | undefined, - opts?: object | null, -): asserts node is t.Proposal { - assert("Proposal", node, opts); -} export function assertTypeScript( 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 10257b1985d4..cb5483b949bd 100755 --- a/packages/babel-types/src/ast-types/generated/index.ts +++ b/packages/babel-types/src/ast-types/generated/index.ts @@ -2096,107 +2096,6 @@ export type Standardized = | ClassPrivateProperty | ClassPrivateMethod | PrivateName; -export type StandardizedOrProposal = - | 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 - | ArgumentPlaceholder - | BindExpression - | ImportAttribute - | Decorator - | DoExpression - | ExportDefaultSpecifier - | RecordExpression - | TupleExpression - | DecimalLiteral - | StaticBlock - | ModuleExpression - | TopicReference - | PipelineTopicExpression - | PipelineBareFunction - | PipelinePrimaryTopicReference; export type Expression = | ArrayExpression | AssignmentExpression @@ -2631,22 +2530,6 @@ export type JSX = | JSXOpeningFragment | JSXClosingFragment; export type Miscellaneous = Noop | Placeholder | V8IntrinsicIdentifier; -export type Proposal = - | ArgumentPlaceholder - | BindExpression - | ImportAttribute - | Decorator - | DoExpression - | ExportDefaultSpecifier - | RecordExpression - | TupleExpression - | DecimalLiteral - | StaticBlock - | ModuleExpression - | TopicReference - | PipelineTopicExpression - | PipelineBareFunction - | PipelinePrimaryTopicReference; export type TypeScript = | TSParameterProperty | TSDeclareFunction @@ -2772,7 +2655,6 @@ export type TSBaseType = export interface Aliases { Standardized: Standardized; - StandardizedOrProposal: StandardizedOrProposal; Expression: Expression; Binary: Binary; Scopable: Scopable; @@ -2816,7 +2698,6 @@ export interface Aliases { EnumMember: EnumMember; JSX: JSX; Miscellaneous: Miscellaneous; - Proposal: Proposal; TypeScript: TypeScript; TSTypeElement: TSTypeElement; TSType: TSType; diff --git a/packages/babel-types/src/constants/generated/index.ts b/packages/babel-types/src/constants/generated/index.ts index effa226acc51..774d7a8fb4cd 100755 --- a/packages/babel-types/src/constants/generated/index.ts +++ b/packages/babel-types/src/constants/generated/index.ts @@ -5,8 +5,6 @@ import { FLIPPED_ALIAS_KEYS } from "../../definitions"; export const STANDARDIZED_TYPES = FLIPPED_ALIAS_KEYS["Standardized"]; -export const STANDARDIZEDORPROPOSAL_TYPES = - FLIPPED_ALIAS_KEYS["StandardizedOrProposal"]; export const EXPRESSION_TYPES = FLIPPED_ALIAS_KEYS["Expression"]; export const BINARY_TYPES = FLIPPED_ALIAS_KEYS["Binary"]; export const SCOPABLE_TYPES = FLIPPED_ALIAS_KEYS["Scopable"]; @@ -52,7 +50,6 @@ 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 PROPOSAL_TYPES = FLIPPED_ALIAS_KEYS["Proposal"]; export const TYPESCRIPT_TYPES = FLIPPED_ALIAS_KEYS["TypeScript"]; export const TSTYPEELEMENT_TYPES = FLIPPED_ALIAS_KEYS["TSTypeElement"]; export const TSTYPE_TYPES = FLIPPED_ALIAS_KEYS["TSType"]; diff --git a/packages/babel-types/src/definitions/core.ts b/packages/babel-types/src/definitions/core.ts index 55052ee6d676..4b619edca893 100644 --- a/packages/babel-types/src/definitions/core.ts +++ b/packages/babel-types/src/definitions/core.ts @@ -23,7 +23,7 @@ import { validateOptional, } from "./utils"; -const defineType = defineAliasedType("Standardized", "StandardizedOrProposal"); +const defineType = defineAliasedType("Standardized"); defineType("ArrayExpression", { fields: { diff --git a/packages/babel-types/src/definitions/experimental.ts b/packages/babel-types/src/definitions/experimental.ts index f478ec80b086..064f25e47f26 100644 --- a/packages/babel-types/src/definitions/experimental.ts +++ b/packages/babel-types/src/definitions/experimental.ts @@ -1,13 +1,10 @@ -import { - defineAliasedType, +import defineType, { assertEach, assertNodeType, assertValueType, chain, } from "./utils"; -const defineType = defineAliasedType("Proposal", "StandardizedOrProposal"); - defineType("ArgumentPlaceholder", {}); defineType("BindExpression", { diff --git a/packages/babel-types/src/validators/generated/index.ts b/packages/babel-types/src/validators/generated/index.ts index 1bdef6bb60a2..c65613f85ef6 100755 --- a/packages/babel-types/src/validators/generated/index.ts +++ b/packages/babel-types/src/validators/generated/index.ts @@ -4295,129 +4295,6 @@ export function isStandardized( return false; } -export function isStandardizedOrProposal( - node: object | null | undefined, - opts?: object | null, -): node is t.StandardizedOrProposal { - 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 || - "ArgumentPlaceholder" === nodeType || - "BindExpression" === nodeType || - "ImportAttribute" === nodeType || - "Decorator" === nodeType || - "DoExpression" === nodeType || - "ExportDefaultSpecifier" === nodeType || - "RecordExpression" === nodeType || - "TupleExpression" === nodeType || - "DecimalLiteral" === nodeType || - "StaticBlock" === nodeType || - "ModuleExpression" === nodeType || - "TopicReference" === nodeType || - "PipelineTopicExpression" === nodeType || - "PipelineBareFunction" === nodeType || - "PipelinePrimaryTopicReference" === 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, @@ -5630,39 +5507,6 @@ export function isMiscellaneous( return false; } -export function isProposal( - node: object | null | undefined, - opts?: object | null, -): node is t.Proposal { - if (!node) return false; - - const nodeType = (node as t.Node).type; - if ( - "ArgumentPlaceholder" === nodeType || - "BindExpression" === nodeType || - "ImportAttribute" === nodeType || - "Decorator" === nodeType || - "DoExpression" === nodeType || - "ExportDefaultSpecifier" === nodeType || - "RecordExpression" === nodeType || - "TupleExpression" === nodeType || - "DecimalLiteral" === nodeType || - "StaticBlock" === nodeType || - "ModuleExpression" === nodeType || - "TopicReference" === nodeType || - "PipelineTopicExpression" === nodeType || - "PipelineBareFunction" === nodeType || - "PipelinePrimaryTopicReference" === nodeType - ) { - if (typeof opts === "undefined") { - return true; - } else { - return shallowEqual(node, opts); - } - } - - return false; -} export function isTypeScript( node: object | null | undefined, opts?: object | null,