From 3c70b89ffcb1a6d93cc9e17597dba5a720711f09 Mon Sep 17 00:00:00 2001 From: Justin Ridgewell Date: Sun, 15 Aug 2021 21:01:38 -0400 Subject: [PATCH] Fix inherits aliases --- .../src/path/generated/asserts.ts | 3 + .../src/path/generated/validators.ts | 1 + .../src/asserts/generated/index.ts | 42 ++++--- .../src/ast-types/generated/index.ts | 52 +++++--- .../src/builders/generated/index.ts | 29 +++-- .../src/builders/generated/uppercase.js | 7 +- packages/babel-types/src/definitions/utils.ts | 7 +- .../src/validators/generated/index.ts | 111 +++++++++++------- 8 files changed, 159 insertions(+), 93 deletions(-) diff --git a/packages/babel-traverse/src/path/generated/asserts.ts b/packages/babel-traverse/src/path/generated/asserts.ts index 02668f2699f8..871f209663cb 100755 --- a/packages/babel-traverse/src/path/generated/asserts.ts +++ b/packages/babel-traverse/src/path/generated/asserts.ts @@ -642,6 +642,9 @@ export interface NodePathAssetions { assertThrowStatement( opts?: object, ): asserts this is NodePath; + assertTopicReference( + opts?: object, + ): asserts this is NodePath; assertTryStatement(opts?: object): asserts this is NodePath; assertTupleExpression( opts?: object, diff --git a/packages/babel-traverse/src/path/generated/validators.ts b/packages/babel-traverse/src/path/generated/validators.ts index 030aeb629fa7..9e7781917e94 100755 --- a/packages/babel-traverse/src/path/generated/validators.ts +++ b/packages/babel-traverse/src/path/generated/validators.ts @@ -391,6 +391,7 @@ export interface NodePathValidators { isThisExpression(opts?: object): this is NodePath; isThisTypeAnnotation(opts?: object): this is NodePath; isThrowStatement(opts?: object): this is NodePath; + isTopicReference(opts?: object): this is NodePath; isTryStatement(opts?: object): this is NodePath; isTupleExpression(opts?: object): this is NodePath; isTupleTypeAnnotation(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 805d7aa40f43..b4d8e3747faa 100755 --- a/packages/babel-types/src/asserts/generated/index.ts +++ b/packages/babel-types/src/asserts/generated/index.ts @@ -1034,24 +1034,6 @@ export function assertBindExpression( ): asserts node is t.BindExpression { assert("BindExpression", node, opts); } -export function assertPipelineTopicExpression( - node: object | null | undefined, - opts?: object | null, -): asserts node is t.PipelineTopicExpression { - assert("PipelineTopicExpression", node, opts); -} -export function assertPipelineBareFunction( - node: object | null | undefined, - opts?: object | null, -): asserts node is t.PipelineBareFunction { - assert("PipelineBareFunction", node, opts); -} -export function assertPipelinePrimaryTopicReference( - node: object | null | undefined, - opts?: object | null, -): asserts node is t.PipelinePrimaryTopicReference { - assert("PipelinePrimaryTopicReference", node, opts); -} export function assertImportAttribute( node: object | null | undefined, opts?: object | null, @@ -1106,6 +1088,30 @@ export function assertModuleExpression( ): asserts node is t.ModuleExpression { assert("ModuleExpression", node, opts); } +export function assertTopicReference( + node: object | null | undefined, + opts?: object | null, +): asserts node is t.TopicReference { + assert("TopicReference", node, opts); +} +export function assertPipelineTopicExpression( + node: object | null | undefined, + opts?: object | null, +): asserts node is t.PipelineTopicExpression { + assert("PipelineTopicExpression", node, opts); +} +export function assertPipelineBareFunction( + node: object | null | undefined, + opts?: object | null, +): asserts node is t.PipelineBareFunction { + assert("PipelineBareFunction", node, opts); +} +export function assertPipelinePrimaryTopicReference( + node: object | null | undefined, + opts?: object | null, +): asserts node is t.PipelinePrimaryTopicReference { + assert("PipelinePrimaryTopicReference", node, opts); +} export function assertTSParameterProperty( 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 e041e85bb029..86d3f69ef0dc 100755 --- a/packages/babel-types/src/ast-types/generated/index.ts +++ b/packages/babel-types/src/ast-types/generated/index.ts @@ -320,6 +320,7 @@ export type Node = | ThisExpression | ThisTypeAnnotation | ThrowStatement + | TopicReference | TryStatement | TupleExpression | TupleTypeAnnotation @@ -648,6 +649,7 @@ export interface RestElement extends BaseNode { type: "RestElement"; argument: LVal; decorators?: Array | null; + optional?: boolean | null; typeAnnotation?: TypeAnnotation | TSTypeAnnotation | Noop | null; } @@ -658,6 +660,7 @@ export interface RestProperty extends BaseNode { type: "RestProperty"; argument: LVal; decorators?: Array | null; + optional?: boolean | null; typeAnnotation?: TypeAnnotation | TSTypeAnnotation | Noop | null; } @@ -756,6 +759,7 @@ export interface ArrayPattern extends BaseNode { type: "ArrayPattern"; elements: Array; decorators?: Array | null; + optional?: boolean | null; typeAnnotation?: TypeAnnotation | TSTypeAnnotation | Noop | null; } @@ -840,6 +844,7 @@ export interface ExportDefaultDeclaration extends BaseNode { | TSDeclareFunction | ClassDeclaration | Expression; + exportKind?: "value" | null; } export interface ExportNamedDeclaration extends BaseNode { @@ -1029,6 +1034,7 @@ export interface ClassProperty extends BaseNode { optional?: boolean | null; override?: boolean; readonly?: boolean | null; + variance?: Variance | null; } export interface ClassPrivateProperty extends BaseNode { @@ -1037,7 +1043,10 @@ export interface ClassPrivateProperty extends BaseNode { value?: Expression | null; decorators?: Array | null; static: any; + definite?: boolean | null; + readonly?: boolean | null; typeAnnotation?: TypeAnnotation | TSTypeAnnotation | Noop | null; + variance?: Variance | null; } export interface ClassPrivateMethod extends BaseNode { @@ -1147,6 +1156,7 @@ export interface DeclareOpaqueType extends BaseNode { id: Identifier; typeParameters?: TypeParameterDeclaration | null; supertype?: FlowType | null; + impltype?: FlowType | null; } export interface DeclareVariable extends BaseNode { @@ -1591,20 +1601,6 @@ export interface BindExpression extends BaseNode { callee: Expression; } -export interface PipelineTopicExpression extends BaseNode { - type: "PipelineTopicExpression"; - expression: Expression; -} - -export interface PipelineBareFunction extends BaseNode { - type: "PipelineBareFunction"; - callee: Expression; -} - -export interface PipelinePrimaryTopicReference extends BaseNode { - type: "PipelinePrimaryTopicReference"; -} - export interface ImportAttribute extends BaseNode { type: "ImportAttribute"; key: Identifier | StringLiteral; @@ -1652,10 +1648,30 @@ export interface ModuleExpression extends BaseNode { body: Program; } +export interface TopicReference extends BaseNode { + type: "TopicReference"; +} + +export interface PipelineTopicExpression extends BaseNode { + type: "PipelineTopicExpression"; + expression: Expression; +} + +export interface PipelineBareFunction extends BaseNode { + type: "PipelineBareFunction"; + callee: Expression; +} + +export interface PipelinePrimaryTopicReference extends BaseNode { + type: "PipelinePrimaryTopicReference"; +} + export interface TSParameterProperty extends BaseNode { type: "TSParameterProperty"; parameter: Identifier | AssignmentPattern; accessibility?: "public" | "private" | "protected" | null; + decorators?: Array | null; + override?: boolean | null; readonly?: boolean | null; } @@ -1715,6 +1731,7 @@ export interface TSPropertySignature extends BaseNode { typeAnnotation?: TSTypeAnnotation | null; initializer?: Expression | null; computed?: boolean | null; + kind: "get" | "set"; optional?: boolean | null; readonly?: boolean | null; } @@ -1997,6 +2014,7 @@ export interface TSImportEqualsDeclaration extends BaseNode { type: "TSImportEqualsDeclaration"; id: Identifier; moduleReference: TSEntityName | TSExternalModuleReference; + importKind?: "type" | "value" | null; isExport: boolean; } @@ -2133,13 +2151,16 @@ export type Expression = | MemberExpression | MetaProperty | ModuleExpression + | NewExpression | NullLiteral | NumericLiteral | ObjectExpression | OptionalCallExpression | OptionalMemberExpression | ParenthesizedExpression + | PipelineBareFunction | PipelinePrimaryTopicReference + | PipelineTopicExpression | RecordExpression | RegExpLiteral | SequenceExpression @@ -2151,6 +2172,7 @@ export type Expression = | TaggedTemplateExpression | TemplateLiteral | ThisExpression + | TopicReference | TupleExpression | TypeCastExpression | UnaryExpression @@ -2389,6 +2411,7 @@ export type Proposal = | PipelineTopicExpression | RecordExpression | StaticBlock + | TopicReference | TupleExpression; export type Pureish = | ArrowFunctionExpression @@ -2598,6 +2621,7 @@ export type StandardizedOrProposal = | TemplateLiteral | ThisExpression | ThrowStatement + | TopicReference | TryStatement | TupleExpression | UnaryExpression diff --git a/packages/babel-types/src/builders/generated/index.ts b/packages/babel-types/src/builders/generated/index.ts index 658a503298ba..aa5591c88bbd 100755 --- a/packages/babel-types/src/builders/generated/index.ts +++ b/packages/babel-types/src/builders/generated/index.ts @@ -1024,19 +1024,6 @@ export function bindExpression( ): t.BindExpression { return builder("BindExpression", ...arguments); } -export function pipelineTopicExpression( - expression: t.Expression, -): t.PipelineTopicExpression { - return builder("PipelineTopicExpression", ...arguments); -} -export function pipelineBareFunction( - callee: t.Expression, -): t.PipelineBareFunction { - return builder("PipelineBareFunction", ...arguments); -} -export function pipelinePrimaryTopicReference(): t.PipelinePrimaryTopicReference { - return builder("PipelinePrimaryTopicReference", ...arguments); -} export function importAttribute( key: t.Identifier | t.StringLiteral, value: t.StringLiteral, @@ -1076,6 +1063,22 @@ export function staticBlock(body: Array): t.StaticBlock { export function moduleExpression(body: t.Program): t.ModuleExpression { return builder("ModuleExpression", ...arguments); } +export function topicReference(): t.TopicReference { + return builder("TopicReference", ...arguments); +} +export function pipelineTopicExpression( + expression: t.Expression, +): t.PipelineTopicExpression { + return builder("PipelineTopicExpression", ...arguments); +} +export function pipelineBareFunction( + callee: t.Expression, +): t.PipelineBareFunction { + return builder("PipelineBareFunction", ...arguments); +} +export function pipelinePrimaryTopicReference(): t.PipelinePrimaryTopicReference { + return builder("PipelinePrimaryTopicReference", ...arguments); +} export function tsParameterProperty( parameter: t.Identifier | t.AssignmentPattern, ): t.TSParameterProperty { diff --git a/packages/babel-types/src/builders/generated/uppercase.js b/packages/babel-types/src/builders/generated/uppercase.js index c56295e657f4..73d60dbb6ff8 100755 --- a/packages/babel-types/src/builders/generated/uppercase.js +++ b/packages/babel-types/src/builders/generated/uppercase.js @@ -179,9 +179,6 @@ export { v8IntrinsicIdentifier as V8IntrinsicIdentifier, argumentPlaceholder as ArgumentPlaceholder, bindExpression as BindExpression, - pipelineTopicExpression as PipelineTopicExpression, - pipelineBareFunction as PipelineBareFunction, - pipelinePrimaryTopicReference as PipelinePrimaryTopicReference, importAttribute as ImportAttribute, decorator as Decorator, doExpression as DoExpression, @@ -191,6 +188,10 @@ export { decimalLiteral as DecimalLiteral, staticBlock as StaticBlock, moduleExpression as ModuleExpression, + topicReference as TopicReference, + pipelineTopicExpression as PipelineTopicExpression, + pipelineBareFunction as PipelineBareFunction, + pipelinePrimaryTopicReference as PipelinePrimaryTopicReference, tsParameterProperty as TSParameterProperty, tsDeclareFunction as TSDeclareFunction, tsDeclareMethod as TSDeclareMethod, 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 e7114ffbfa6f..1bdef6bb60a2 100755 --- a/packages/babel-types/src/validators/generated/index.ts +++ b/packages/babel-types/src/validators/generated/index.ts @@ -2895,14 +2895,14 @@ export function isBindExpression( return false; } -export function isPipelineTopicExpression( +export function isImportAttribute( node: object | null | undefined, opts?: object | null, -): node is t.PipelineTopicExpression { +): node is t.ImportAttribute { if (!node) return false; const nodeType = (node as t.Node).type; - if (nodeType === "PipelineTopicExpression") { + if (nodeType === "ImportAttribute") { if (typeof opts === "undefined") { return true; } else { @@ -2912,14 +2912,14 @@ export function isPipelineTopicExpression( return false; } -export function isPipelineBareFunction( +export function isDecorator( node: object | null | undefined, opts?: object | null, -): node is t.PipelineBareFunction { +): node is t.Decorator { if (!node) return false; const nodeType = (node as t.Node).type; - if (nodeType === "PipelineBareFunction") { + if (nodeType === "Decorator") { if (typeof opts === "undefined") { return true; } else { @@ -2929,14 +2929,14 @@ export function isPipelineBareFunction( return false; } -export function isPipelinePrimaryTopicReference( +export function isDoExpression( node: object | null | undefined, opts?: object | null, -): node is t.PipelinePrimaryTopicReference { +): node is t.DoExpression { if (!node) return false; const nodeType = (node as t.Node).type; - if (nodeType === "PipelinePrimaryTopicReference") { + if (nodeType === "DoExpression") { if (typeof opts === "undefined") { return true; } else { @@ -2946,14 +2946,14 @@ export function isPipelinePrimaryTopicReference( return false; } -export function isImportAttribute( +export function isExportDefaultSpecifier( node: object | null | undefined, opts?: object | null, -): node is t.ImportAttribute { +): node is t.ExportDefaultSpecifier { if (!node) return false; const nodeType = (node as t.Node).type; - if (nodeType === "ImportAttribute") { + if (nodeType === "ExportDefaultSpecifier") { if (typeof opts === "undefined") { return true; } else { @@ -2963,14 +2963,14 @@ export function isImportAttribute( return false; } -export function isDecorator( +export function isRecordExpression( node: object | null | undefined, opts?: object | null, -): node is t.Decorator { +): node is t.RecordExpression { if (!node) return false; const nodeType = (node as t.Node).type; - if (nodeType === "Decorator") { + if (nodeType === "RecordExpression") { if (typeof opts === "undefined") { return true; } else { @@ -2980,14 +2980,14 @@ export function isDecorator( return false; } -export function isDoExpression( +export function isTupleExpression( node: object | null | undefined, opts?: object | null, -): node is t.DoExpression { +): node is t.TupleExpression { if (!node) return false; const nodeType = (node as t.Node).type; - if (nodeType === "DoExpression") { + if (nodeType === "TupleExpression") { if (typeof opts === "undefined") { return true; } else { @@ -2997,14 +2997,14 @@ export function isDoExpression( return false; } -export function isExportDefaultSpecifier( +export function isDecimalLiteral( node: object | null | undefined, opts?: object | null, -): node is t.ExportDefaultSpecifier { +): node is t.DecimalLiteral { if (!node) return false; const nodeType = (node as t.Node).type; - if (nodeType === "ExportDefaultSpecifier") { + if (nodeType === "DecimalLiteral") { if (typeof opts === "undefined") { return true; } else { @@ -3014,14 +3014,14 @@ export function isExportDefaultSpecifier( return false; } -export function isRecordExpression( +export function isStaticBlock( node: object | null | undefined, opts?: object | null, -): node is t.RecordExpression { +): node is t.StaticBlock { if (!node) return false; const nodeType = (node as t.Node).type; - if (nodeType === "RecordExpression") { + if (nodeType === "StaticBlock") { if (typeof opts === "undefined") { return true; } else { @@ -3031,14 +3031,14 @@ export function isRecordExpression( return false; } -export function isTupleExpression( +export function isModuleExpression( node: object | null | undefined, opts?: object | null, -): node is t.TupleExpression { +): node is t.ModuleExpression { if (!node) return false; const nodeType = (node as t.Node).type; - if (nodeType === "TupleExpression") { + if (nodeType === "ModuleExpression") { if (typeof opts === "undefined") { return true; } else { @@ -3048,14 +3048,14 @@ export function isTupleExpression( return false; } -export function isDecimalLiteral( +export function isTopicReference( node: object | null | undefined, opts?: object | null, -): node is t.DecimalLiteral { +): node is t.TopicReference { if (!node) return false; const nodeType = (node as t.Node).type; - if (nodeType === "DecimalLiteral") { + if (nodeType === "TopicReference") { if (typeof opts === "undefined") { return true; } else { @@ -3065,14 +3065,14 @@ export function isDecimalLiteral( return false; } -export function isStaticBlock( +export function isPipelineTopicExpression( node: object | null | undefined, opts?: object | null, -): node is t.StaticBlock { +): node is t.PipelineTopicExpression { if (!node) return false; const nodeType = (node as t.Node).type; - if (nodeType === "StaticBlock") { + if (nodeType === "PipelineTopicExpression") { if (typeof opts === "undefined") { return true; } else { @@ -3082,14 +3082,31 @@ export function isStaticBlock( return false; } -export function isModuleExpression( +export function isPipelineBareFunction( node: object | null | undefined, opts?: object | null, -): node is t.ModuleExpression { +): node is t.PipelineBareFunction { if (!node) return false; const nodeType = (node as t.Node).type; - if (nodeType === "ModuleExpression") { + if (nodeType === "PipelineBareFunction") { + if (typeof opts === "undefined") { + return true; + } else { + return shallowEqual(node, opts); + } + } + + return false; +} +export function isPipelinePrimaryTopicReference( + node: object | null | undefined, + opts?: object | null, +): node is t.PipelinePrimaryTopicReference { + if (!node) return false; + + const nodeType = (node as t.Node).type; + if (nodeType === "PipelinePrimaryTopicReference") { if (typeof opts === "undefined") { return true; } else { @@ -4373,9 +4390,6 @@ export function isStandardizedOrProposal( "PrivateName" === nodeType || "ArgumentPlaceholder" === nodeType || "BindExpression" === nodeType || - "PipelineTopicExpression" === nodeType || - "PipelineBareFunction" === nodeType || - "PipelinePrimaryTopicReference" === nodeType || "ImportAttribute" === nodeType || "Decorator" === nodeType || "DoExpression" === nodeType || @@ -4385,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 || @@ -4422,6 +4440,7 @@ export function isExpression( "RegExpLiteral" === nodeType || "LogicalExpression" === nodeType || "MemberExpression" === nodeType || + "NewExpression" === nodeType || "ObjectExpression" === nodeType || "SequenceExpression" === nodeType || "ParenthesizedExpression" === nodeType || @@ -4444,12 +4463,15 @@ export function isExpression( "JSXElement" === nodeType || "JSXFragment" === nodeType || "BindExpression" === nodeType || - "PipelinePrimaryTopicReference" === nodeType || "DoExpression" === nodeType || "RecordExpression" === nodeType || "TupleExpression" === nodeType || "DecimalLiteral" === nodeType || "ModuleExpression" === nodeType || + "TopicReference" === nodeType || + "PipelineTopicExpression" === nodeType || + "PipelineBareFunction" === nodeType || + "PipelinePrimaryTopicReference" === nodeType || "TSAsExpression" === nodeType || "TSTypeAssertion" === nodeType || "TSNonNullExpression" === nodeType || @@ -5618,9 +5640,6 @@ export function isProposal( if ( "ArgumentPlaceholder" === nodeType || "BindExpression" === nodeType || - "PipelineTopicExpression" === nodeType || - "PipelineBareFunction" === nodeType || - "PipelinePrimaryTopicReference" === nodeType || "ImportAttribute" === nodeType || "Decorator" === nodeType || "DoExpression" === nodeType || @@ -5629,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;