Skip to content

Commit

Permalink
Fix inherits aliases
Browse files Browse the repository at this point in the history
  • Loading branch information
jridgewell committed Aug 16, 2021
1 parent ef6b64a commit 3c70b89
Show file tree
Hide file tree
Showing 8 changed files with 159 additions and 93 deletions.
3 changes: 3 additions & 0 deletions packages/babel-traverse/src/path/generated/asserts.ts
Expand Up @@ -642,6 +642,9 @@ export interface NodePathAssetions {
assertThrowStatement(
opts?: object,
): asserts this is NodePath<t.ThrowStatement>;
assertTopicReference(
opts?: object,
): asserts this is NodePath<t.TopicReference>;
assertTryStatement(opts?: object): asserts this is NodePath<t.TryStatement>;
assertTupleExpression(
opts?: object,
Expand Down
1 change: 1 addition & 0 deletions packages/babel-traverse/src/path/generated/validators.ts
Expand Up @@ -391,6 +391,7 @@ export interface NodePathValidators {
isThisExpression(opts?: object): this is NodePath<t.ThisExpression>;
isThisTypeAnnotation(opts?: object): this is NodePath<t.ThisTypeAnnotation>;
isThrowStatement(opts?: object): this is NodePath<t.ThrowStatement>;
isTopicReference(opts?: object): this is NodePath<t.TopicReference>;
isTryStatement(opts?: object): this is NodePath<t.TryStatement>;
isTupleExpression(opts?: object): this is NodePath<t.TupleExpression>;
isTupleTypeAnnotation(opts?: object): this is NodePath<t.TupleTypeAnnotation>;
Expand Down
42 changes: 24 additions & 18 deletions packages/babel-types/src/asserts/generated/index.ts
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
52 changes: 38 additions & 14 deletions packages/babel-types/src/ast-types/generated/index.ts
Expand Up @@ -320,6 +320,7 @@ export type Node =
| ThisExpression
| ThisTypeAnnotation
| ThrowStatement
| TopicReference
| TryStatement
| TupleExpression
| TupleTypeAnnotation
Expand Down Expand Up @@ -648,6 +649,7 @@ export interface RestElement extends BaseNode {
type: "RestElement";
argument: LVal;
decorators?: Array<Decorator> | null;
optional?: boolean | null;
typeAnnotation?: TypeAnnotation | TSTypeAnnotation | Noop | null;
}

Expand All @@ -658,6 +660,7 @@ export interface RestProperty extends BaseNode {
type: "RestProperty";
argument: LVal;
decorators?: Array<Decorator> | null;
optional?: boolean | null;
typeAnnotation?: TypeAnnotation | TSTypeAnnotation | Noop | null;
}

Expand Down Expand Up @@ -756,6 +759,7 @@ export interface ArrayPattern extends BaseNode {
type: "ArrayPattern";
elements: Array<null | PatternLike>;
decorators?: Array<Decorator> | null;
optional?: boolean | null;
typeAnnotation?: TypeAnnotation | TSTypeAnnotation | Noop | null;
}

Expand Down Expand Up @@ -840,6 +844,7 @@ export interface ExportDefaultDeclaration extends BaseNode {
| TSDeclareFunction
| ClassDeclaration
| Expression;
exportKind?: "value" | null;
}

export interface ExportNamedDeclaration extends BaseNode {
Expand Down Expand Up @@ -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 {
Expand All @@ -1037,7 +1043,10 @@ export interface ClassPrivateProperty extends BaseNode {
value?: Expression | null;
decorators?: Array<Decorator> | null;
static: any;
definite?: boolean | null;
readonly?: boolean | null;
typeAnnotation?: TypeAnnotation | TSTypeAnnotation | Noop | null;
variance?: Variance | null;
}

export interface ClassPrivateMethod extends BaseNode {
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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<Decorator> | null;
override?: boolean | null;
readonly?: boolean | null;
}

Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -1997,6 +2014,7 @@ export interface TSImportEqualsDeclaration extends BaseNode {
type: "TSImportEqualsDeclaration";
id: Identifier;
moduleReference: TSEntityName | TSExternalModuleReference;
importKind?: "type" | "value" | null;
isExport: boolean;
}

Expand Down Expand Up @@ -2133,13 +2151,16 @@ export type Expression =
| MemberExpression
| MetaProperty
| ModuleExpression
| NewExpression
| NullLiteral
| NumericLiteral
| ObjectExpression
| OptionalCallExpression
| OptionalMemberExpression
| ParenthesizedExpression
| PipelineBareFunction
| PipelinePrimaryTopicReference
| PipelineTopicExpression
| RecordExpression
| RegExpLiteral
| SequenceExpression
Expand All @@ -2151,6 +2172,7 @@ export type Expression =
| TaggedTemplateExpression
| TemplateLiteral
| ThisExpression
| TopicReference
| TupleExpression
| TypeCastExpression
| UnaryExpression
Expand Down Expand Up @@ -2389,6 +2411,7 @@ export type Proposal =
| PipelineTopicExpression
| RecordExpression
| StaticBlock
| TopicReference
| TupleExpression;
export type Pureish =
| ArrowFunctionExpression
Expand Down Expand Up @@ -2598,6 +2621,7 @@ export type StandardizedOrProposal =
| TemplateLiteral
| ThisExpression
| ThrowStatement
| TopicReference
| TryStatement
| TupleExpression
| UnaryExpression
Expand Down
29 changes: 16 additions & 13 deletions packages/babel-types/src/builders/generated/index.ts
Expand Up @@ -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,
Expand Down Expand Up @@ -1076,6 +1063,22 @@ export function staticBlock(body: Array<t.Statement>): 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 {
Expand Down
7 changes: 4 additions & 3 deletions packages/babel-types/src/builders/generated/uppercase.js
Expand Up @@ -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,
Expand All @@ -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,
Expand Down
7 changes: 6 additions & 1 deletion packages/babel-types/src/definitions/utils.ts
Expand Up @@ -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);
Expand Down

0 comments on commit 3c70b89

Please sign in to comment.