Add aliases for Standardized, TypeScript, and Flow (#13666)

* 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<t.Node, t.TypeScript | t.Flow>;
```

* Lint

* Export deprecated alias types

* Add docs descriptions for new aliases

* Add Standardized alias

* Fix inherits aliases

* Filter aliases from node types

* Remove Proposal alias
This commit is contained in:
Justin Ridgewell 2021-10-28 14:14:32 -04:00 committed by GitHub
parent 248aa9d302
commit b1793656e6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
14 changed files with 530 additions and 136 deletions

View File

@ -328,6 +328,7 @@ export interface NodePathAssetions {
): asserts this is NodePath<t.MemberExpression>; ): asserts this is NodePath<t.MemberExpression>;
assertMetaProperty(opts?: object): asserts this is NodePath<t.MetaProperty>; assertMetaProperty(opts?: object): asserts this is NodePath<t.MetaProperty>;
assertMethod(opts?: object): asserts this is NodePath<t.Method>; assertMethod(opts?: object): asserts this is NodePath<t.Method>;
assertMiscellaneous(opts?: object): asserts this is NodePath<t.Miscellaneous>;
assertMixedTypeAnnotation( assertMixedTypeAnnotation(
opts?: object, opts?: object,
): asserts this is NodePath<t.MixedTypeAnnotation>; ): asserts this is NodePath<t.MixedTypeAnnotation>;
@ -437,6 +438,7 @@ export interface NodePathAssetions {
assertSpreadProperty( assertSpreadProperty(
opts?: object, opts?: object,
): asserts this is NodePath<t.SpreadProperty>; ): asserts this is NodePath<t.SpreadProperty>;
assertStandardized(opts?: object): asserts this is NodePath<t.Standardized>;
assertStatement(opts?: object): asserts this is NodePath<t.Statement>; assertStatement(opts?: object): asserts this is NodePath<t.Statement>;
assertStaticBlock(opts?: object): asserts this is NodePath<t.StaticBlock>; assertStaticBlock(opts?: object): asserts this is NodePath<t.StaticBlock>;
assertStringLiteral(opts?: object): asserts this is NodePath<t.StringLiteral>; assertStringLiteral(opts?: object): asserts this is NodePath<t.StringLiteral>;
@ -660,6 +662,7 @@ export interface NodePathAssetions {
assertTypeParameterInstantiation( assertTypeParameterInstantiation(
opts?: object, opts?: object,
): asserts this is NodePath<t.TypeParameterInstantiation>; ): asserts this is NodePath<t.TypeParameterInstantiation>;
assertTypeScript(opts?: object): asserts this is NodePath<t.TypeScript>;
assertTypeofTypeAnnotation( assertTypeofTypeAnnotation(
opts?: object, opts?: object,
): asserts this is NodePath<t.TypeofTypeAnnotation>; ): asserts this is NodePath<t.TypeofTypeAnnotation>;

View File

@ -191,6 +191,7 @@ export interface NodePathValidators {
isMemberExpression(opts?: object): this is NodePath<t.MemberExpression>; isMemberExpression(opts?: object): this is NodePath<t.MemberExpression>;
isMetaProperty(opts?: object): this is NodePath<t.MetaProperty>; isMetaProperty(opts?: object): this is NodePath<t.MetaProperty>;
isMethod(opts?: object): this is NodePath<t.Method>; isMethod(opts?: object): this is NodePath<t.Method>;
isMiscellaneous(opts?: object): this is NodePath<t.Miscellaneous>;
isMixedTypeAnnotation(opts?: object): this is NodePath<t.MixedTypeAnnotation>; isMixedTypeAnnotation(opts?: object): this is NodePath<t.MixedTypeAnnotation>;
isModuleDeclaration(opts?: object): this is NodePath<t.ModuleDeclaration>; isModuleDeclaration(opts?: object): this is NodePath<t.ModuleDeclaration>;
isModuleExpression(opts?: object): this is NodePath<t.ModuleExpression>; isModuleExpression(opts?: object): this is NodePath<t.ModuleExpression>;
@ -274,6 +275,7 @@ export interface NodePathValidators {
isSequenceExpression(opts?: object): this is NodePath<t.SequenceExpression>; isSequenceExpression(opts?: object): this is NodePath<t.SequenceExpression>;
isSpreadElement(opts?: object): this is NodePath<t.SpreadElement>; isSpreadElement(opts?: object): this is NodePath<t.SpreadElement>;
isSpreadProperty(opts?: object): this is NodePath<t.SpreadProperty>; isSpreadProperty(opts?: object): this is NodePath<t.SpreadProperty>;
isStandardized(opts?: object): this is NodePath<t.Standardized>;
isStatement(opts?: object): this is NodePath<t.Statement>; isStatement(opts?: object): this is NodePath<t.Statement>;
isStaticBlock(opts?: object): this is NodePath<t.StaticBlock>; isStaticBlock(opts?: object): this is NodePath<t.StaticBlock>;
isStringLiteral(opts?: object): this is NodePath<t.StringLiteral>; isStringLiteral(opts?: object): this is NodePath<t.StringLiteral>;
@ -399,6 +401,7 @@ export interface NodePathValidators {
isTypeParameterInstantiation( isTypeParameterInstantiation(
opts?: object, opts?: object,
): this is NodePath<t.TypeParameterInstantiation>; ): this is NodePath<t.TypeParameterInstantiation>;
isTypeScript(opts?: object): this is NodePath<t.TypeScript>;
isTypeofTypeAnnotation( isTypeofTypeAnnotation(
opts?: object, opts?: object,
): this is NodePath<t.TypeofTypeAnnotation>; ): this is NodePath<t.TypeofTypeAnnotation>;

View File

@ -49,7 +49,9 @@ interface BaseNode {
export type CommentTypeShorthand = "leading" | "inner" | "trailing"; 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 = {}; const deprecatedAlias = {};
for (const type in t.DEPRECATED_KEYS) { for (const type in t.DEPRECATED_KEYS) {
@ -115,6 +117,9 @@ export interface ${deprecatedAlias[type]} extends BaseNode {
code += ` ${type}: ${type};\n`; code += ` ${type}: ${type};\n`;
} }
code += "}\n\n"; code += "}\n\n";
code += `export type DeprecatedAliases = ${Object.keys(
t.DEPRECATED_KEYS
).join(" | ")}\n\n`;
return code; return code;
} }

View File

@ -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.", "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.", Loop: "A cover of loop statements.",
Method: "A cover of object methods and class methods.", Method: "A cover of object methods and class methods.",
Miscellaneous:
"A cover of non-standard AST types that are sometimes useful for development.",
ModuleDeclaration: ModuleDeclaration:
"A cover of ImportDeclaration and [ExportDeclaration](#exportdeclaration)", "A cover of ImportDeclaration and [ExportDeclaration](#exportdeclaration)",
ModuleSpecifier: ModuleSpecifier:
@ -233,12 +235,15 @@ const aliasDescriptions = {
"A cover of AST nodes which do not have side-effects. In other words, there is no observable behaviour changes if they are evaluated more than once.", "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: Scopable:
"A cover of [FunctionParent](#functionparent) and [BlockParent](#blockparent).", "A cover of [FunctionParent](#functionparent) and [BlockParent](#blockparent).",
Standardized:
"A cover of AST nodes which are part of an official ECMAScript specification.",
Statement: Statement:
"A cover of any [Statement](https://tc39.es/ecma262/#prod-Statement)s.", "A cover of any [Statement](https://tc39.es/ecma262/#prod-Statement)s.",
TSBaseType: "A cover of primary TypeScript type annotations.", TSBaseType: "A cover of primary TypeScript type annotations.",
TSEntityName: "A cover of ts entities.", TSEntityName: "A cover of ts entities.",
TSType: "A cover of TypeScript type annotations.", TSType: "A cover of TypeScript type annotations.",
TSTypeElement: "A cover of TypeScript type declarations.", TSTypeElement: "A cover of TypeScript type declarations.",
TypeScript: "A cover of AST nodes defined for TypeScript.",
Terminatorless: Terminatorless:
"A cover of AST nodes whose semantic will change when a line terminator is inserted between the operator and the operand.", "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.", UnaryLike: "A cover of UnaryExpression and SpreadElement.",

View File

@ -1490,6 +1490,12 @@ export function assertTSTypeParameter(
): asserts node is t.TSTypeParameter { ): asserts node is t.TSTypeParameter {
assert("TSTypeParameter", node, opts); assert("TSTypeParameter", node, opts);
} }
export function assertStandardized(
node: object | null | undefined,
opts?: object | null,
): asserts node is t.Standardized {
assert("Standardized", node, opts);
}
export function assertExpression( export function assertExpression(
node: object | null | undefined, node: object | null | undefined,
opts?: object | null, opts?: object | null,
@ -1742,6 +1748,18 @@ export function assertJSX(
): asserts node is t.JSX { ): asserts node is t.JSX {
assert("JSX", node, opts); 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( export function assertTSTypeElement(
node: object | null | undefined, node: object | null | undefined,
opts?: object | null, opts?: object | null,

View File

@ -56,11 +56,8 @@ export type Node =
| AssignmentPattern | AssignmentPattern
| AwaitExpression | AwaitExpression
| BigIntLiteral | BigIntLiteral
| Binary
| BinaryExpression | BinaryExpression
| BindExpression | BindExpression
| Block
| BlockParent
| BlockStatement | BlockStatement
| BooleanLiteral | BooleanLiteral
| BooleanLiteralTypeAnnotation | BooleanLiteralTypeAnnotation
@ -68,7 +65,6 @@ export type Node =
| BreakStatement | BreakStatement
| CallExpression | CallExpression
| CatchClause | CatchClause
| Class
| ClassBody | ClassBody
| ClassDeclaration | ClassDeclaration
| ClassExpression | ClassExpression
@ -77,13 +73,10 @@ export type Node =
| ClassPrivateMethod | ClassPrivateMethod
| ClassPrivateProperty | ClassPrivateProperty
| ClassProperty | ClassProperty
| CompletionStatement
| Conditional
| ConditionalExpression | ConditionalExpression
| ContinueStatement | ContinueStatement
| DebuggerStatement | DebuggerStatement
| DecimalLiteral | DecimalLiteral
| Declaration
| DeclareClass | DeclareClass
| DeclareExportAllDeclaration | DeclareExportAllDeclaration
| DeclareExportDeclaration | DeclareExportDeclaration
@ -102,12 +95,10 @@ export type Node =
| DoWhileStatement | DoWhileStatement
| EmptyStatement | EmptyStatement
| EmptyTypeAnnotation | EmptyTypeAnnotation
| EnumBody
| EnumBooleanBody | EnumBooleanBody
| EnumBooleanMember | EnumBooleanMember
| EnumDeclaration | EnumDeclaration
| EnumDefaultedMember | EnumDefaultedMember
| EnumMember
| EnumNumberBody | EnumNumberBody
| EnumNumberMember | EnumNumberMember
| EnumStringBody | EnumStringBody
@ -115,36 +106,23 @@ export type Node =
| EnumSymbolBody | EnumSymbolBody
| ExistsTypeAnnotation | ExistsTypeAnnotation
| ExportAllDeclaration | ExportAllDeclaration
| ExportDeclaration
| ExportDefaultDeclaration | ExportDefaultDeclaration
| ExportDefaultSpecifier | ExportDefaultSpecifier
| ExportNamedDeclaration | ExportNamedDeclaration
| ExportNamespaceSpecifier | ExportNamespaceSpecifier
| ExportSpecifier | ExportSpecifier
| Expression
| ExpressionStatement | ExpressionStatement
| ExpressionWrapper
| File | File
| Flow
| FlowBaseAnnotation
| FlowDeclaration
| FlowPredicate
| FlowType
| For
| ForInStatement | ForInStatement
| ForOfStatement | ForOfStatement
| ForStatement | ForStatement
| ForXStatement
| Function
| FunctionDeclaration | FunctionDeclaration
| FunctionExpression | FunctionExpression
| FunctionParent
| FunctionTypeAnnotation | FunctionTypeAnnotation
| FunctionTypeParam | FunctionTypeParam
| GenericTypeAnnotation | GenericTypeAnnotation
| Identifier | Identifier
| IfStatement | IfStatement
| Immutable
| Import | Import
| ImportAttribute | ImportAttribute
| ImportDeclaration | ImportDeclaration
@ -158,7 +136,6 @@ export type Node =
| InterfaceTypeAnnotation | InterfaceTypeAnnotation
| InterpreterDirective | InterpreterDirective
| IntersectionTypeAnnotation | IntersectionTypeAnnotation
| JSX
| JSXAttribute | JSXAttribute
| JSXClosingElement | JSXClosingElement
| JSXClosingFragment | JSXClosingFragment
@ -174,18 +151,12 @@ export type Node =
| JSXSpreadAttribute | JSXSpreadAttribute
| JSXSpreadChild | JSXSpreadChild
| JSXText | JSXText
| LVal
| LabeledStatement | LabeledStatement
| Literal
| LogicalExpression | LogicalExpression
| Loop
| MemberExpression | MemberExpression
| MetaProperty | MetaProperty
| Method
| MixedTypeAnnotation | MixedTypeAnnotation
| ModuleDeclaration
| ModuleExpression | ModuleExpression
| ModuleSpecifier
| NewExpression | NewExpression
| Noop | Noop
| NullLiteral | NullLiteral
@ -196,7 +167,6 @@ export type Node =
| NumberTypeAnnotation | NumberTypeAnnotation
| NumericLiteral | NumericLiteral
| ObjectExpression | ObjectExpression
| ObjectMember
| ObjectMethod | ObjectMethod
| ObjectPattern | ObjectPattern
| ObjectProperty | ObjectProperty
@ -211,17 +181,12 @@ export type Node =
| OptionalIndexedAccessType | OptionalIndexedAccessType
| OptionalMemberExpression | OptionalMemberExpression
| ParenthesizedExpression | ParenthesizedExpression
| Pattern
| PatternLike
| PipelineBareFunction | PipelineBareFunction
| PipelinePrimaryTopicReference | PipelinePrimaryTopicReference
| PipelineTopicExpression | PipelineTopicExpression
| Placeholder | Placeholder
| Private
| PrivateName | PrivateName
| Program | Program
| Property
| Pureish
| QualifiedTypeIdentifier | QualifiedTypeIdentifier
| RecordExpression | RecordExpression
| RegExpLiteral | RegExpLiteral
@ -229,11 +194,9 @@ export type Node =
| RestElement | RestElement
| RestProperty | RestProperty
| ReturnStatement | ReturnStatement
| Scopable
| SequenceExpression | SequenceExpression
| SpreadElement | SpreadElement
| SpreadProperty | SpreadProperty
| Statement
| StaticBlock | StaticBlock
| StringLiteral | StringLiteral
| StringLiteralTypeAnnotation | StringLiteralTypeAnnotation
@ -245,7 +208,6 @@ export type Node =
| TSAnyKeyword | TSAnyKeyword
| TSArrayType | TSArrayType
| TSAsExpression | TSAsExpression
| TSBaseType
| TSBigIntKeyword | TSBigIntKeyword
| TSBooleanKeyword | TSBooleanKeyword
| TSCallSignatureDeclaration | TSCallSignatureDeclaration
@ -254,7 +216,6 @@ export type Node =
| TSConstructorType | TSConstructorType
| TSDeclareFunction | TSDeclareFunction
| TSDeclareMethod | TSDeclareMethod
| TSEntityName
| TSEnumDeclaration | TSEnumDeclaration
| TSEnumMember | TSEnumMember
| TSExportAssignment | TSExportAssignment
@ -292,11 +253,9 @@ export type Node =
| TSSymbolKeyword | TSSymbolKeyword
| TSThisType | TSThisType
| TSTupleType | TSTupleType
| TSType
| TSTypeAliasDeclaration | TSTypeAliasDeclaration
| TSTypeAnnotation | TSTypeAnnotation
| TSTypeAssertion | TSTypeAssertion
| TSTypeElement
| TSTypeLiteral | TSTypeLiteral
| TSTypeOperator | TSTypeOperator
| TSTypeParameter | TSTypeParameter
@ -312,7 +271,6 @@ export type Node =
| TaggedTemplateExpression | TaggedTemplateExpression
| TemplateElement | TemplateElement
| TemplateLiteral | TemplateLiteral
| Terminatorless
| ThisExpression | ThisExpression
| ThisTypeAnnotation | ThisTypeAnnotation
| ThrowStatement | ThrowStatement
@ -328,16 +286,13 @@ export type Node =
| TypeParameterInstantiation | TypeParameterInstantiation
| TypeofTypeAnnotation | TypeofTypeAnnotation
| UnaryExpression | UnaryExpression
| UnaryLike
| UnionTypeAnnotation | UnionTypeAnnotation
| UpdateExpression | UpdateExpression
| UserWhitespacable
| V8IntrinsicIdentifier | V8IntrinsicIdentifier
| VariableDeclaration | VariableDeclaration
| VariableDeclarator | VariableDeclarator
| Variance | Variance
| VoidTypeAnnotation | VoidTypeAnnotation
| While
| WhileStatement | WhileStatement
| WithStatement | WithStatement
| YieldExpression; | YieldExpression;
@ -2055,6 +2010,92 @@ export interface TSTypeParameter extends BaseNode {
name: string; name: string;
} }
export type Standardized =
| ArrayExpression
| AssignmentExpression
| BinaryExpression
| InterpreterDirective
| Directive
| DirectiveLiteral
| BlockStatement
| BreakStatement
| CallExpression
| CatchClause
| ConditionalExpression
| ContinueStatement
| DebuggerStatement
| DoWhileStatement
| EmptyStatement
| ExpressionStatement
| File
| ForInStatement
| ForStatement
| FunctionDeclaration
| FunctionExpression
| Identifier
| IfStatement
| LabeledStatement
| StringLiteral
| NumericLiteral
| NullLiteral
| BooleanLiteral
| RegExpLiteral
| LogicalExpression
| MemberExpression
| NewExpression
| Program
| ObjectExpression
| ObjectMethod
| ObjectProperty
| RestElement
| ReturnStatement
| SequenceExpression
| ParenthesizedExpression
| SwitchCase
| SwitchStatement
| ThisExpression
| ThrowStatement
| TryStatement
| UnaryExpression
| UpdateExpression
| VariableDeclaration
| VariableDeclarator
| WhileStatement
| WithStatement
| AssignmentPattern
| ArrayPattern
| ArrowFunctionExpression
| ClassBody
| ClassExpression
| ClassDeclaration
| ExportAllDeclaration
| ExportDefaultDeclaration
| ExportNamedDeclaration
| ExportSpecifier
| ForOfStatement
| ImportDeclaration
| ImportDefaultSpecifier
| ImportNamespaceSpecifier
| ImportSpecifier
| MetaProperty
| ClassMethod
| ObjectPattern
| SpreadElement
| Super
| TaggedTemplateExpression
| TemplateElement
| TemplateLiteral
| YieldExpression
| AwaitExpression
| Import
| BigIntLiteral
| ExportNamespaceSpecifier
| OptionalMemberExpression
| OptionalCallExpression
| ClassProperty
| ClassPrivateProperty
| ClassPrivateMethod
| PrivateName;
export type Expression = export type Expression =
| ArrayExpression | ArrayExpression
| AssignmentExpression | AssignmentExpression
@ -2399,6 +2440,15 @@ export type Flow =
| UnionTypeAnnotation | UnionTypeAnnotation
| Variance | Variance
| VoidTypeAnnotation | VoidTypeAnnotation
| EnumDeclaration
| EnumBooleanBody
| EnumNumberBody
| EnumStringBody
| EnumSymbolBody
| EnumBooleanMember
| EnumNumberMember
| EnumStringMember
| EnumDefaultedMember
| IndexedAccessType | IndexedAccessType
| OptionalIndexedAccessType; | OptionalIndexedAccessType;
export type FlowType = export type FlowType =
@ -2480,6 +2530,71 @@ export type JSX =
| JSXFragment | JSXFragment
| JSXOpeningFragment | JSXOpeningFragment
| JSXClosingFragment; | 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 = export type TSTypeElement =
| TSCallSignatureDeclaration | TSCallSignatureDeclaration
| TSConstructSignatureDeclaration | TSConstructSignatureDeclaration
@ -2540,6 +2655,7 @@ export type TSBaseType =
| TSLiteralType; | TSLiteralType;
export interface Aliases { export interface Aliases {
Standardized: Standardized;
Expression: Expression; Expression: Expression;
Binary: Binary; Binary: Binary;
Scopable: Scopable; Scopable: Scopable;
@ -2582,7 +2698,15 @@ export interface Aliases {
EnumBody: EnumBody; EnumBody: EnumBody;
EnumMember: EnumMember; EnumMember: EnumMember;
JSX: JSX; JSX: JSX;
Miscellaneous: Miscellaneous;
TypeScript: TypeScript;
TSTypeElement: TSTypeElement; TSTypeElement: TSTypeElement;
TSType: TSType; TSType: TSType;
TSBaseType: TSBaseType; TSBaseType: TSBaseType;
} }
export type DeprecatedAliases =
| NumberLiteral
| RegexLiteral
| RestProperty
| SpreadProperty;

View File

@ -4,6 +4,7 @@
*/ */
import { FLIPPED_ALIAS_KEYS } from "../../definitions"; import { FLIPPED_ALIAS_KEYS } from "../../definitions";
export const STANDARDIZED_TYPES = FLIPPED_ALIAS_KEYS["Standardized"];
export const EXPRESSION_TYPES = FLIPPED_ALIAS_KEYS["Expression"]; export const EXPRESSION_TYPES = FLIPPED_ALIAS_KEYS["Expression"];
export const BINARY_TYPES = FLIPPED_ALIAS_KEYS["Binary"]; export const BINARY_TYPES = FLIPPED_ALIAS_KEYS["Binary"];
export const SCOPABLE_TYPES = FLIPPED_ALIAS_KEYS["Scopable"]; export const SCOPABLE_TYPES = FLIPPED_ALIAS_KEYS["Scopable"];
@ -48,6 +49,8 @@ export const FLOWPREDICATE_TYPES = FLIPPED_ALIAS_KEYS["FlowPredicate"];
export const ENUMBODY_TYPES = FLIPPED_ALIAS_KEYS["EnumBody"]; export const ENUMBODY_TYPES = FLIPPED_ALIAS_KEYS["EnumBody"];
export const ENUMMEMBER_TYPES = FLIPPED_ALIAS_KEYS["EnumMember"]; export const ENUMMEMBER_TYPES = FLIPPED_ALIAS_KEYS["EnumMember"];
export const JSX_TYPES = FLIPPED_ALIAS_KEYS["JSX"]; 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 TSTYPEELEMENT_TYPES = FLIPPED_ALIAS_KEYS["TSTypeElement"];
export const TSTYPE_TYPES = FLIPPED_ALIAS_KEYS["TSType"]; export const TSTYPE_TYPES = FLIPPED_ALIAS_KEYS["TSType"];
export const TSBASETYPE_TYPES = FLIPPED_ALIAS_KEYS["TSBaseType"]; export const TSBASETYPE_TYPES = FLIPPED_ALIAS_KEYS["TSBaseType"];

View File

@ -10,7 +10,8 @@ import {
UPDATE_OPERATORS, UPDATE_OPERATORS,
} from "../constants"; } from "../constants";
import defineType, { import {
defineAliasedType,
assertShape, assertShape,
assertOptionalChainStart, assertOptionalChainStart,
assertValueType, assertValueType,
@ -22,6 +23,8 @@ import defineType, {
validateOptional, validateOptional,
} from "./utils"; } from "./utils";
const defineType = defineAliasedType("Standardized");
defineType("ArrayExpression", { defineType("ArrayExpression", {
fields: { fields: {
elements: { elements: {

View File

@ -1,4 +1,5 @@
import defineType, { import {
defineAliasedType,
arrayOfType, arrayOfType,
assertOneOf, assertOneOf,
assertValueType, assertValueType,
@ -9,6 +10,8 @@ import defineType, {
validateType, validateType,
} from "./utils"; } from "./utils";
const defineType = defineAliasedType("Flow");
const defineInterfaceishType = ( const defineInterfaceishType = (
name: string, name: string,
typeParameterType: string = "TypeParameterDeclaration", typeParameterType: string = "TypeParameterDeclaration",
@ -23,7 +26,7 @@ const defineInterfaceishType = (
"implements", "implements",
"body", "body",
], ],
aliases: ["Flow", "FlowDeclaration", "Statement", "Declaration"], aliases: ["FlowDeclaration", "Statement", "Declaration"],
fields: { fields: {
id: validateType("Identifier"), id: validateType("Identifier"),
typeParameters: validateOptionalType(typeParameterType), typeParameters: validateOptionalType(typeParameterType),
@ -36,36 +39,35 @@ const defineInterfaceishType = (
}; };
defineType("AnyTypeAnnotation", { defineType("AnyTypeAnnotation", {
aliases: ["Flow", "FlowType", "FlowBaseAnnotation"], aliases: ["FlowType", "FlowBaseAnnotation"],
}); });
defineType("ArrayTypeAnnotation", { defineType("ArrayTypeAnnotation", {
visitor: ["elementType"], visitor: ["elementType"],
aliases: ["Flow", "FlowType"], aliases: ["FlowType"],
fields: { fields: {
elementType: validateType("FlowType"), elementType: validateType("FlowType"),
}, },
}); });
defineType("BooleanTypeAnnotation", { defineType("BooleanTypeAnnotation", {
aliases: ["Flow", "FlowType", "FlowBaseAnnotation"], aliases: ["FlowType", "FlowBaseAnnotation"],
}); });
defineType("BooleanLiteralTypeAnnotation", { defineType("BooleanLiteralTypeAnnotation", {
builder: ["value"], builder: ["value"],
aliases: ["Flow", "FlowType"], aliases: ["FlowType"],
fields: { fields: {
value: validate(assertValueType("boolean")), value: validate(assertValueType("boolean")),
}, },
}); });
defineType("NullLiteralTypeAnnotation", { defineType("NullLiteralTypeAnnotation", {
aliases: ["Flow", "FlowType", "FlowBaseAnnotation"], aliases: ["FlowType", "FlowBaseAnnotation"],
}); });
defineType("ClassImplements", { defineType("ClassImplements", {
visitor: ["id", "typeParameters"], visitor: ["id", "typeParameters"],
aliases: ["Flow"],
fields: { fields: {
id: validateType("Identifier"), id: validateType("Identifier"),
typeParameters: validateOptionalType("TypeParameterInstantiation"), typeParameters: validateOptionalType("TypeParameterInstantiation"),
@ -76,7 +78,7 @@ defineInterfaceishType("DeclareClass");
defineType("DeclareFunction", { defineType("DeclareFunction", {
visitor: ["id"], visitor: ["id"],
aliases: ["Flow", "FlowDeclaration", "Statement", "Declaration"], aliases: ["FlowDeclaration", "Statement", "Declaration"],
fields: { fields: {
id: validateType("Identifier"), id: validateType("Identifier"),
predicate: validateOptionalType("DeclaredPredicate"), predicate: validateOptionalType("DeclaredPredicate"),
@ -88,7 +90,7 @@ defineInterfaceishType("DeclareInterface");
defineType("DeclareModule", { defineType("DeclareModule", {
builder: ["id", "body", "kind"], builder: ["id", "body", "kind"],
visitor: ["id", "body"], visitor: ["id", "body"],
aliases: ["Flow", "FlowDeclaration", "Statement", "Declaration"], aliases: ["FlowDeclaration", "Statement", "Declaration"],
fields: { fields: {
id: validateType(["Identifier", "StringLiteral"]), id: validateType(["Identifier", "StringLiteral"]),
body: validateType("BlockStatement"), body: validateType("BlockStatement"),
@ -98,7 +100,7 @@ defineType("DeclareModule", {
defineType("DeclareModuleExports", { defineType("DeclareModuleExports", {
visitor: ["typeAnnotation"], visitor: ["typeAnnotation"],
aliases: ["Flow", "FlowDeclaration", "Statement", "Declaration"], aliases: ["FlowDeclaration", "Statement", "Declaration"],
fields: { fields: {
typeAnnotation: validateType("TypeAnnotation"), typeAnnotation: validateType("TypeAnnotation"),
}, },
@ -106,7 +108,7 @@ defineType("DeclareModuleExports", {
defineType("DeclareTypeAlias", { defineType("DeclareTypeAlias", {
visitor: ["id", "typeParameters", "right"], visitor: ["id", "typeParameters", "right"],
aliases: ["Flow", "FlowDeclaration", "Statement", "Declaration"], aliases: ["FlowDeclaration", "Statement", "Declaration"],
fields: { fields: {
id: validateType("Identifier"), id: validateType("Identifier"),
typeParameters: validateOptionalType("TypeParameterDeclaration"), typeParameters: validateOptionalType("TypeParameterDeclaration"),
@ -116,7 +118,7 @@ defineType("DeclareTypeAlias", {
defineType("DeclareOpaqueType", { defineType("DeclareOpaqueType", {
visitor: ["id", "typeParameters", "supertype"], visitor: ["id", "typeParameters", "supertype"],
aliases: ["Flow", "FlowDeclaration", "Statement", "Declaration"], aliases: ["FlowDeclaration", "Statement", "Declaration"],
fields: { fields: {
id: validateType("Identifier"), id: validateType("Identifier"),
typeParameters: validateOptionalType("TypeParameterDeclaration"), typeParameters: validateOptionalType("TypeParameterDeclaration"),
@ -127,7 +129,7 @@ defineType("DeclareOpaqueType", {
defineType("DeclareVariable", { defineType("DeclareVariable", {
visitor: ["id"], visitor: ["id"],
aliases: ["Flow", "FlowDeclaration", "Statement", "Declaration"], aliases: ["FlowDeclaration", "Statement", "Declaration"],
fields: { fields: {
id: validateType("Identifier"), id: validateType("Identifier"),
}, },
@ -135,7 +137,7 @@ defineType("DeclareVariable", {
defineType("DeclareExportDeclaration", { defineType("DeclareExportDeclaration", {
visitor: ["declaration", "specifiers", "source"], visitor: ["declaration", "specifiers", "source"],
aliases: ["Flow", "FlowDeclaration", "Statement", "Declaration"], aliases: ["FlowDeclaration", "Statement", "Declaration"],
fields: { fields: {
declaration: validateOptionalType("Flow"), declaration: validateOptionalType("Flow"),
specifiers: validateOptional( specifiers: validateOptional(
@ -148,7 +150,7 @@ defineType("DeclareExportDeclaration", {
defineType("DeclareExportAllDeclaration", { defineType("DeclareExportAllDeclaration", {
visitor: ["source"], visitor: ["source"],
aliases: ["Flow", "FlowDeclaration", "Statement", "Declaration"], aliases: ["FlowDeclaration", "Statement", "Declaration"],
fields: { fields: {
source: validateType("StringLiteral"), source: validateType("StringLiteral"),
exportKind: validateOptional(assertOneOf("type", "value")), exportKind: validateOptional(assertOneOf("type", "value")),
@ -157,19 +159,19 @@ defineType("DeclareExportAllDeclaration", {
defineType("DeclaredPredicate", { defineType("DeclaredPredicate", {
visitor: ["value"], visitor: ["value"],
aliases: ["Flow", "FlowPredicate"], aliases: ["FlowPredicate"],
fields: { fields: {
value: validateType("Flow"), value: validateType("Flow"),
}, },
}); });
defineType("ExistsTypeAnnotation", { defineType("ExistsTypeAnnotation", {
aliases: ["Flow", "FlowType"], aliases: ["FlowType"],
}); });
defineType("FunctionTypeAnnotation", { defineType("FunctionTypeAnnotation", {
visitor: ["typeParameters", "params", "rest", "returnType"], visitor: ["typeParameters", "params", "rest", "returnType"],
aliases: ["Flow", "FlowType"], aliases: ["FlowType"],
fields: { fields: {
typeParameters: validateOptionalType("TypeParameterDeclaration"), typeParameters: validateOptionalType("TypeParameterDeclaration"),
params: validate(arrayOfType("FunctionTypeParam")), params: validate(arrayOfType("FunctionTypeParam")),
@ -181,7 +183,6 @@ defineType("FunctionTypeAnnotation", {
defineType("FunctionTypeParam", { defineType("FunctionTypeParam", {
visitor: ["name", "typeAnnotation"], visitor: ["name", "typeAnnotation"],
aliases: ["Flow"],
fields: { fields: {
name: validateOptionalType("Identifier"), name: validateOptionalType("Identifier"),
typeAnnotation: validateType("FlowType"), typeAnnotation: validateType("FlowType"),
@ -191,7 +192,7 @@ defineType("FunctionTypeParam", {
defineType("GenericTypeAnnotation", { defineType("GenericTypeAnnotation", {
visitor: ["id", "typeParameters"], visitor: ["id", "typeParameters"],
aliases: ["Flow", "FlowType"], aliases: ["FlowType"],
fields: { fields: {
id: validateType(["Identifier", "QualifiedTypeIdentifier"]), id: validateType(["Identifier", "QualifiedTypeIdentifier"]),
typeParameters: validateOptionalType("TypeParameterInstantiation"), typeParameters: validateOptionalType("TypeParameterInstantiation"),
@ -199,12 +200,11 @@ defineType("GenericTypeAnnotation", {
}); });
defineType("InferredPredicate", { defineType("InferredPredicate", {
aliases: ["Flow", "FlowPredicate"], aliases: ["FlowPredicate"],
}); });
defineType("InterfaceExtends", { defineType("InterfaceExtends", {
visitor: ["id", "typeParameters"], visitor: ["id", "typeParameters"],
aliases: ["Flow"],
fields: { fields: {
id: validateType(["Identifier", "QualifiedTypeIdentifier"]), id: validateType(["Identifier", "QualifiedTypeIdentifier"]),
typeParameters: validateOptionalType("TypeParameterInstantiation"), typeParameters: validateOptionalType("TypeParameterInstantiation"),
@ -215,7 +215,7 @@ defineInterfaceishType("InterfaceDeclaration");
defineType("InterfaceTypeAnnotation", { defineType("InterfaceTypeAnnotation", {
visitor: ["extends", "body"], visitor: ["extends", "body"],
aliases: ["Flow", "FlowType"], aliases: ["FlowType"],
fields: { fields: {
extends: validateOptional(arrayOfType("InterfaceExtends")), extends: validateOptional(arrayOfType("InterfaceExtends")),
body: validateType("ObjectTypeAnnotation"), body: validateType("ObjectTypeAnnotation"),
@ -224,23 +224,23 @@ defineType("InterfaceTypeAnnotation", {
defineType("IntersectionTypeAnnotation", { defineType("IntersectionTypeAnnotation", {
visitor: ["types"], visitor: ["types"],
aliases: ["Flow", "FlowType"], aliases: ["FlowType"],
fields: { fields: {
types: validate(arrayOfType("FlowType")), types: validate(arrayOfType("FlowType")),
}, },
}); });
defineType("MixedTypeAnnotation", { defineType("MixedTypeAnnotation", {
aliases: ["Flow", "FlowType", "FlowBaseAnnotation"], aliases: ["FlowType", "FlowBaseAnnotation"],
}); });
defineType("EmptyTypeAnnotation", { defineType("EmptyTypeAnnotation", {
aliases: ["Flow", "FlowType", "FlowBaseAnnotation"], aliases: ["FlowType", "FlowBaseAnnotation"],
}); });
defineType("NullableTypeAnnotation", { defineType("NullableTypeAnnotation", {
visitor: ["typeAnnotation"], visitor: ["typeAnnotation"],
aliases: ["Flow", "FlowType"], aliases: ["FlowType"],
fields: { fields: {
typeAnnotation: validateType("FlowType"), typeAnnotation: validateType("FlowType"),
}, },
@ -248,19 +248,19 @@ defineType("NullableTypeAnnotation", {
defineType("NumberLiteralTypeAnnotation", { defineType("NumberLiteralTypeAnnotation", {
builder: ["value"], builder: ["value"],
aliases: ["Flow", "FlowType"], aliases: ["FlowType"],
fields: { fields: {
value: validate(assertValueType("number")), value: validate(assertValueType("number")),
}, },
}); });
defineType("NumberTypeAnnotation", { defineType("NumberTypeAnnotation", {
aliases: ["Flow", "FlowType", "FlowBaseAnnotation"], aliases: ["FlowType", "FlowBaseAnnotation"],
}); });
defineType("ObjectTypeAnnotation", { defineType("ObjectTypeAnnotation", {
visitor: ["properties", "indexers", "callProperties", "internalSlots"], visitor: ["properties", "indexers", "callProperties", "internalSlots"],
aliases: ["Flow", "FlowType"], aliases: ["FlowType"],
builder: [ builder: [
"properties", "properties",
"indexers", "indexers",
@ -288,7 +288,7 @@ defineType("ObjectTypeAnnotation", {
defineType("ObjectTypeInternalSlot", { defineType("ObjectTypeInternalSlot", {
visitor: ["id", "value", "optional", "static", "method"], visitor: ["id", "value", "optional", "static", "method"],
aliases: ["Flow", "UserWhitespacable"], aliases: ["UserWhitespacable"],
fields: { fields: {
id: validateType("Identifier"), id: validateType("Identifier"),
value: validateType("FlowType"), value: validateType("FlowType"),
@ -300,7 +300,7 @@ defineType("ObjectTypeInternalSlot", {
defineType("ObjectTypeCallProperty", { defineType("ObjectTypeCallProperty", {
visitor: ["value"], visitor: ["value"],
aliases: ["Flow", "UserWhitespacable"], aliases: ["UserWhitespacable"],
fields: { fields: {
value: validateType("FlowType"), value: validateType("FlowType"),
static: validate(assertValueType("boolean")), static: validate(assertValueType("boolean")),
@ -309,7 +309,7 @@ defineType("ObjectTypeCallProperty", {
defineType("ObjectTypeIndexer", { defineType("ObjectTypeIndexer", {
visitor: ["id", "key", "value", "variance"], visitor: ["id", "key", "value", "variance"],
aliases: ["Flow", "UserWhitespacable"], aliases: ["UserWhitespacable"],
fields: { fields: {
id: validateOptionalType("Identifier"), id: validateOptionalType("Identifier"),
key: validateType("FlowType"), key: validateType("FlowType"),
@ -321,7 +321,7 @@ defineType("ObjectTypeIndexer", {
defineType("ObjectTypeProperty", { defineType("ObjectTypeProperty", {
visitor: ["key", "value", "variance"], visitor: ["key", "value", "variance"],
aliases: ["Flow", "UserWhitespacable"], aliases: ["UserWhitespacable"],
fields: { fields: {
key: validateType(["Identifier", "StringLiteral"]), key: validateType(["Identifier", "StringLiteral"]),
value: validateType("FlowType"), value: validateType("FlowType"),
@ -336,7 +336,7 @@ defineType("ObjectTypeProperty", {
defineType("ObjectTypeSpreadProperty", { defineType("ObjectTypeSpreadProperty", {
visitor: ["argument"], visitor: ["argument"],
aliases: ["Flow", "UserWhitespacable"], aliases: ["UserWhitespacable"],
fields: { fields: {
argument: validateType("FlowType"), argument: validateType("FlowType"),
}, },
@ -344,7 +344,7 @@ defineType("ObjectTypeSpreadProperty", {
defineType("OpaqueType", { defineType("OpaqueType", {
visitor: ["id", "typeParameters", "supertype", "impltype"], visitor: ["id", "typeParameters", "supertype", "impltype"],
aliases: ["Flow", "FlowDeclaration", "Statement", "Declaration"], aliases: ["FlowDeclaration", "Statement", "Declaration"],
fields: { fields: {
id: validateType("Identifier"), id: validateType("Identifier"),
typeParameters: validateOptionalType("TypeParameterDeclaration"), typeParameters: validateOptionalType("TypeParameterDeclaration"),
@ -355,7 +355,6 @@ defineType("OpaqueType", {
defineType("QualifiedTypeIdentifier", { defineType("QualifiedTypeIdentifier", {
visitor: ["id", "qualification"], visitor: ["id", "qualification"],
aliases: ["Flow"],
fields: { fields: {
id: validateType("Identifier"), id: validateType("Identifier"),
qualification: validateType(["Identifier", "QualifiedTypeIdentifier"]), qualification: validateType(["Identifier", "QualifiedTypeIdentifier"]),
@ -364,27 +363,27 @@ defineType("QualifiedTypeIdentifier", {
defineType("StringLiteralTypeAnnotation", { defineType("StringLiteralTypeAnnotation", {
builder: ["value"], builder: ["value"],
aliases: ["Flow", "FlowType"], aliases: ["FlowType"],
fields: { fields: {
value: validate(assertValueType("string")), value: validate(assertValueType("string")),
}, },
}); });
defineType("StringTypeAnnotation", { defineType("StringTypeAnnotation", {
aliases: ["Flow", "FlowType", "FlowBaseAnnotation"], aliases: ["FlowType", "FlowBaseAnnotation"],
}); });
defineType("SymbolTypeAnnotation", { defineType("SymbolTypeAnnotation", {
aliases: ["Flow", "FlowType", "FlowBaseAnnotation"], aliases: ["FlowType", "FlowBaseAnnotation"],
}); });
defineType("ThisTypeAnnotation", { defineType("ThisTypeAnnotation", {
aliases: ["Flow", "FlowType", "FlowBaseAnnotation"], aliases: ["FlowType", "FlowBaseAnnotation"],
}); });
defineType("TupleTypeAnnotation", { defineType("TupleTypeAnnotation", {
visitor: ["types"], visitor: ["types"],
aliases: ["Flow", "FlowType"], aliases: ["FlowType"],
fields: { fields: {
types: validate(arrayOfType("FlowType")), types: validate(arrayOfType("FlowType")),
}, },
@ -392,7 +391,7 @@ defineType("TupleTypeAnnotation", {
defineType("TypeofTypeAnnotation", { defineType("TypeofTypeAnnotation", {
visitor: ["argument"], visitor: ["argument"],
aliases: ["Flow", "FlowType"], aliases: ["FlowType"],
fields: { fields: {
argument: validateType("FlowType"), argument: validateType("FlowType"),
}, },
@ -400,7 +399,7 @@ defineType("TypeofTypeAnnotation", {
defineType("TypeAlias", { defineType("TypeAlias", {
visitor: ["id", "typeParameters", "right"], visitor: ["id", "typeParameters", "right"],
aliases: ["Flow", "FlowDeclaration", "Statement", "Declaration"], aliases: ["FlowDeclaration", "Statement", "Declaration"],
fields: { fields: {
id: validateType("Identifier"), id: validateType("Identifier"),
typeParameters: validateOptionalType("TypeParameterDeclaration"), typeParameters: validateOptionalType("TypeParameterDeclaration"),
@ -409,7 +408,6 @@ defineType("TypeAlias", {
}); });
defineType("TypeAnnotation", { defineType("TypeAnnotation", {
aliases: ["Flow"],
visitor: ["typeAnnotation"], visitor: ["typeAnnotation"],
fields: { fields: {
typeAnnotation: validateType("FlowType"), typeAnnotation: validateType("FlowType"),
@ -418,7 +416,7 @@ defineType("TypeAnnotation", {
defineType("TypeCastExpression", { defineType("TypeCastExpression", {
visitor: ["expression", "typeAnnotation"], visitor: ["expression", "typeAnnotation"],
aliases: ["Flow", "ExpressionWrapper", "Expression"], aliases: ["ExpressionWrapper", "Expression"],
fields: { fields: {
expression: validateType("Expression"), expression: validateType("Expression"),
typeAnnotation: validateType("TypeAnnotation"), typeAnnotation: validateType("TypeAnnotation"),
@ -426,7 +424,6 @@ defineType("TypeCastExpression", {
}); });
defineType("TypeParameter", { defineType("TypeParameter", {
aliases: ["Flow"],
visitor: ["bound", "default", "variance"], visitor: ["bound", "default", "variance"],
fields: { fields: {
name: validate(assertValueType("string")), name: validate(assertValueType("string")),
@ -437,7 +434,6 @@ defineType("TypeParameter", {
}); });
defineType("TypeParameterDeclaration", { defineType("TypeParameterDeclaration", {
aliases: ["Flow"],
visitor: ["params"], visitor: ["params"],
fields: { fields: {
params: validate(arrayOfType("TypeParameter")), params: validate(arrayOfType("TypeParameter")),
@ -445,7 +441,6 @@ defineType("TypeParameterDeclaration", {
}); });
defineType("TypeParameterInstantiation", { defineType("TypeParameterInstantiation", {
aliases: ["Flow"],
visitor: ["params"], visitor: ["params"],
fields: { fields: {
params: validate(arrayOfType("FlowType")), params: validate(arrayOfType("FlowType")),
@ -454,14 +449,13 @@ defineType("TypeParameterInstantiation", {
defineType("UnionTypeAnnotation", { defineType("UnionTypeAnnotation", {
visitor: ["types"], visitor: ["types"],
aliases: ["Flow", "FlowType"], aliases: ["FlowType"],
fields: { fields: {
types: validate(arrayOfType("FlowType")), types: validate(arrayOfType("FlowType")),
}, },
}); });
defineType("Variance", { defineType("Variance", {
aliases: ["Flow"],
builder: ["kind"], builder: ["kind"],
fields: { fields: {
kind: validate(assertOneOf("minus", "plus")), kind: validate(assertOneOf("minus", "plus")),
@ -469,7 +463,7 @@ defineType("Variance", {
}); });
defineType("VoidTypeAnnotation", { defineType("VoidTypeAnnotation", {
aliases: ["Flow", "FlowType", "FlowBaseAnnotation"], aliases: ["FlowType", "FlowBaseAnnotation"],
}); });
// Enums // Enums
@ -563,7 +557,7 @@ defineType("EnumDefaultedMember", {
defineType("IndexedAccessType", { defineType("IndexedAccessType", {
visitor: ["objectType", "indexType"], visitor: ["objectType", "indexType"],
aliases: ["Flow", "FlowType"], aliases: ["FlowType"],
fields: { fields: {
objectType: validateType("FlowType"), objectType: validateType("FlowType"),
indexType: validateType("FlowType"), indexType: validateType("FlowType"),
@ -572,7 +566,7 @@ defineType("IndexedAccessType", {
defineType("OptionalIndexedAccessType", { defineType("OptionalIndexedAccessType", {
visitor: ["objectType", "indexType"], visitor: ["objectType", "indexType"],
aliases: ["Flow", "FlowType"], aliases: ["FlowType"],
fields: { fields: {
objectType: validateType("FlowType"), objectType: validateType("FlowType"),
indexType: validateType("FlowType"), indexType: validateType("FlowType"),

View File

@ -1,13 +1,16 @@
import defineType, { import {
defineAliasedType,
assertNodeType, assertNodeType,
assertValueType, assertValueType,
chain, chain,
assertEach, assertEach,
} from "./utils"; } from "./utils";
const defineType = defineAliasedType("JSX");
defineType("JSXAttribute", { defineType("JSXAttribute", {
visitor: ["name", "value"], visitor: ["name", "value"],
aliases: ["JSX", "Immutable"], aliases: ["Immutable"],
fields: { fields: {
name: { name: {
validate: assertNodeType("JSXIdentifier", "JSXNamespacedName"), validate: assertNodeType("JSXIdentifier", "JSXNamespacedName"),
@ -26,7 +29,7 @@ defineType("JSXAttribute", {
defineType("JSXClosingElement", { defineType("JSXClosingElement", {
visitor: ["name"], visitor: ["name"],
aliases: ["JSX", "Immutable"], aliases: ["Immutable"],
fields: { fields: {
name: { name: {
validate: assertNodeType( validate: assertNodeType(
@ -41,7 +44,7 @@ defineType("JSXClosingElement", {
defineType("JSXElement", { defineType("JSXElement", {
builder: ["openingElement", "closingElement", "children", "selfClosing"], builder: ["openingElement", "closingElement", "children", "selfClosing"],
visitor: ["openingElement", "children", "closingElement"], visitor: ["openingElement", "children", "closingElement"],
aliases: ["JSX", "Immutable", "Expression"], aliases: ["Immutable", "Expression"],
fields: { fields: {
openingElement: { openingElement: {
validate: assertNodeType("JSXOpeningElement"), validate: assertNodeType("JSXOpeningElement"),
@ -71,13 +74,11 @@ defineType("JSXElement", {
}, },
}); });
defineType("JSXEmptyExpression", { defineType("JSXEmptyExpression", {});
aliases: ["JSX"],
});
defineType("JSXExpressionContainer", { defineType("JSXExpressionContainer", {
visitor: ["expression"], visitor: ["expression"],
aliases: ["JSX", "Immutable"], aliases: ["Immutable"],
fields: { fields: {
expression: { expression: {
validate: assertNodeType("Expression", "JSXEmptyExpression"), validate: assertNodeType("Expression", "JSXEmptyExpression"),
@ -87,7 +88,7 @@ defineType("JSXExpressionContainer", {
defineType("JSXSpreadChild", { defineType("JSXSpreadChild", {
visitor: ["expression"], visitor: ["expression"],
aliases: ["JSX", "Immutable"], aliases: ["Immutable"],
fields: { fields: {
expression: { expression: {
validate: assertNodeType("Expression"), validate: assertNodeType("Expression"),
@ -97,7 +98,6 @@ defineType("JSXSpreadChild", {
defineType("JSXIdentifier", { defineType("JSXIdentifier", {
builder: ["name"], builder: ["name"],
aliases: ["JSX"],
fields: { fields: {
name: { name: {
validate: assertValueType("string"), validate: assertValueType("string"),
@ -107,7 +107,6 @@ defineType("JSXIdentifier", {
defineType("JSXMemberExpression", { defineType("JSXMemberExpression", {
visitor: ["object", "property"], visitor: ["object", "property"],
aliases: ["JSX"],
fields: { fields: {
object: { object: {
validate: assertNodeType("JSXMemberExpression", "JSXIdentifier"), validate: assertNodeType("JSXMemberExpression", "JSXIdentifier"),
@ -120,7 +119,6 @@ defineType("JSXMemberExpression", {
defineType("JSXNamespacedName", { defineType("JSXNamespacedName", {
visitor: ["namespace", "name"], visitor: ["namespace", "name"],
aliases: ["JSX"],
fields: { fields: {
namespace: { namespace: {
validate: assertNodeType("JSXIdentifier"), validate: assertNodeType("JSXIdentifier"),
@ -134,7 +132,7 @@ defineType("JSXNamespacedName", {
defineType("JSXOpeningElement", { defineType("JSXOpeningElement", {
builder: ["name", "attributes", "selfClosing"], builder: ["name", "attributes", "selfClosing"],
visitor: ["name", "attributes"], visitor: ["name", "attributes"],
aliases: ["JSX", "Immutable"], aliases: ["Immutable"],
fields: { fields: {
name: { name: {
validate: assertNodeType( validate: assertNodeType(
@ -164,7 +162,6 @@ defineType("JSXOpeningElement", {
defineType("JSXSpreadAttribute", { defineType("JSXSpreadAttribute", {
visitor: ["argument"], visitor: ["argument"],
aliases: ["JSX"],
fields: { fields: {
argument: { argument: {
validate: assertNodeType("Expression"), validate: assertNodeType("Expression"),
@ -173,7 +170,7 @@ defineType("JSXSpreadAttribute", {
}); });
defineType("JSXText", { defineType("JSXText", {
aliases: ["JSX", "Immutable"], aliases: ["Immutable"],
builder: ["value"], builder: ["value"],
fields: { fields: {
value: { value: {
@ -185,7 +182,7 @@ defineType("JSXText", {
defineType("JSXFragment", { defineType("JSXFragment", {
builder: ["openingFragment", "closingFragment", "children"], builder: ["openingFragment", "closingFragment", "children"],
visitor: ["openingFragment", "children", "closingFragment"], visitor: ["openingFragment", "children", "closingFragment"],
aliases: ["JSX", "Immutable", "Expression"], aliases: ["Immutable", "Expression"],
fields: { fields: {
openingFragment: { openingFragment: {
validate: assertNodeType("JSXOpeningFragment"), validate: assertNodeType("JSXOpeningFragment"),
@ -211,9 +208,9 @@ defineType("JSXFragment", {
}); });
defineType("JSXOpeningFragment", { defineType("JSXOpeningFragment", {
aliases: ["JSX", "Immutable"], aliases: ["Immutable"],
}); });
defineType("JSXClosingFragment", { defineType("JSXClosingFragment", {
aliases: ["JSX", "Immutable"], aliases: ["Immutable"],
}); });

View File

@ -1,10 +1,13 @@
import defineType, { import {
defineAliasedType,
assertNodeType, assertNodeType,
assertOneOf, assertOneOf,
assertValueType, assertValueType,
} from "./utils"; } from "./utils";
import { PLACEHOLDERS } from "./placeholders"; import { PLACEHOLDERS } from "./placeholders";
const defineType = defineAliasedType("Miscellaneous");
if (!process.env.BABEL_8_BREAKING) { if (!process.env.BABEL_8_BREAKING) {
defineType("Noop", { defineType("Noop", {
visitor: [], visitor: [],

View File

@ -1,4 +1,5 @@
import defineType, { import {
defineAliasedType,
arrayOfType, arrayOfType,
assertEach, assertEach,
assertNodeType, assertNodeType,
@ -17,6 +18,8 @@ import {
} from "./core"; } from "./core";
import is from "../validators/is"; import is from "../validators/is";
const defineType = defineAliasedType("TypeScript");
const bool = assertValueType("boolean"); const bool = assertValueType("boolean");
const tSFunctionTypeAnnotationCommon = { const tSFunctionTypeAnnotationCommon = {

View File

@ -19,6 +19,18 @@ function getType(val) {
} }
} }
type DefineTypeOpts = {
fields?: {
[x: string]: FieldOptions;
};
visitor?: Array<string>;
aliases?: Array<string>;
builder?: Array<string>;
inherits?: string;
deprecatedAlias?: string;
validate?: Validator;
};
type Validator = ( type Validator = (
| { type: string } | { type: string }
| { each: Validator } | { each: Validator }
@ -256,20 +268,22 @@ const validTypeOpts = [
]; ];
const validFieldKeys = ["default", "optional", "validate"]; const validFieldKeys = ["default", "optional", "validate"];
export default function defineType( // Wraps defineType to ensure these aliases are included.
type: string, export function defineAliasedType(...aliases: string[]) {
opts: { return (type: string, opts: DefineTypeOpts = {}) => {
fields?: { let defined = opts.aliases;
[x: string]: FieldOptions; if (!defined) {
}; if (opts.inherits) defined = store[opts.inherits].aliases?.slice();
visitor?: Array<string>; defined ??= [];
aliases?: Array<string>; opts.aliases = defined;
builder?: Array<string>; }
inherits?: string; const additional = aliases.filter(a => !defined.includes(a));
deprecatedAlias?: string; defined.unshift(...additional);
validate?: Validator; return defineType(type, opts);
} = {}, };
) { }
export default function defineType(type: string, opts: DefineTypeOpts = {}) {
const inherits = (opts.inherits && store[opts.inherits]) || {}; const inherits = (opts.inherits && store[opts.inherits]) || {};
let fields = opts.fields; let fields = opts.fields;

View File

@ -4187,6 +4187,114 @@ export function isTSTypeParameter(
return false; return false;
} }
export function isStandardized(
node: object | null | undefined,
opts?: object | null,
): node is t.Standardized {
if (!node) return false;
const nodeType = (node as t.Node).type;
if (
"ArrayExpression" === nodeType ||
"AssignmentExpression" === nodeType ||
"BinaryExpression" === nodeType ||
"InterpreterDirective" === nodeType ||
"Directive" === nodeType ||
"DirectiveLiteral" === nodeType ||
"BlockStatement" === nodeType ||
"BreakStatement" === nodeType ||
"CallExpression" === nodeType ||
"CatchClause" === nodeType ||
"ConditionalExpression" === nodeType ||
"ContinueStatement" === nodeType ||
"DebuggerStatement" === nodeType ||
"DoWhileStatement" === nodeType ||
"EmptyStatement" === nodeType ||
"ExpressionStatement" === nodeType ||
"File" === nodeType ||
"ForInStatement" === nodeType ||
"ForStatement" === nodeType ||
"FunctionDeclaration" === nodeType ||
"FunctionExpression" === nodeType ||
"Identifier" === nodeType ||
"IfStatement" === nodeType ||
"LabeledStatement" === nodeType ||
"StringLiteral" === nodeType ||
"NumericLiteral" === nodeType ||
"NullLiteral" === nodeType ||
"BooleanLiteral" === nodeType ||
"RegExpLiteral" === nodeType ||
"LogicalExpression" === nodeType ||
"MemberExpression" === nodeType ||
"NewExpression" === nodeType ||
"Program" === nodeType ||
"ObjectExpression" === nodeType ||
"ObjectMethod" === nodeType ||
"ObjectProperty" === nodeType ||
"RestElement" === nodeType ||
"ReturnStatement" === nodeType ||
"SequenceExpression" === nodeType ||
"ParenthesizedExpression" === nodeType ||
"SwitchCase" === nodeType ||
"SwitchStatement" === nodeType ||
"ThisExpression" === nodeType ||
"ThrowStatement" === nodeType ||
"TryStatement" === nodeType ||
"UnaryExpression" === nodeType ||
"UpdateExpression" === nodeType ||
"VariableDeclaration" === nodeType ||
"VariableDeclarator" === nodeType ||
"WhileStatement" === nodeType ||
"WithStatement" === nodeType ||
"AssignmentPattern" === nodeType ||
"ArrayPattern" === nodeType ||
"ArrowFunctionExpression" === nodeType ||
"ClassBody" === nodeType ||
"ClassExpression" === nodeType ||
"ClassDeclaration" === nodeType ||
"ExportAllDeclaration" === nodeType ||
"ExportDefaultDeclaration" === nodeType ||
"ExportNamedDeclaration" === nodeType ||
"ExportSpecifier" === nodeType ||
"ForOfStatement" === nodeType ||
"ImportDeclaration" === nodeType ||
"ImportDefaultSpecifier" === nodeType ||
"ImportNamespaceSpecifier" === nodeType ||
"ImportSpecifier" === nodeType ||
"MetaProperty" === nodeType ||
"ClassMethod" === nodeType ||
"ObjectPattern" === nodeType ||
"SpreadElement" === nodeType ||
"Super" === nodeType ||
"TaggedTemplateExpression" === nodeType ||
"TemplateElement" === nodeType ||
"TemplateLiteral" === nodeType ||
"YieldExpression" === nodeType ||
"AwaitExpression" === nodeType ||
"Import" === nodeType ||
"BigIntLiteral" === nodeType ||
"ExportNamespaceSpecifier" === nodeType ||
"OptionalMemberExpression" === nodeType ||
"OptionalCallExpression" === nodeType ||
"ClassProperty" === nodeType ||
"ClassPrivateProperty" === nodeType ||
"ClassPrivateMethod" === nodeType ||
"PrivateName" === nodeType ||
(nodeType === "Placeholder" &&
("Identifier" === (node as t.Placeholder).expectedNode ||
"StringLiteral" === (node as t.Placeholder).expectedNode ||
"BlockStatement" === (node as t.Placeholder).expectedNode ||
"ClassBody" === (node as t.Placeholder).expectedNode))
) {
if (typeof opts === "undefined") {
return true;
} else {
return shallowEqual(node, opts);
}
}
return false;
}
export function isExpression( export function isExpression(
node: object | null | undefined, node: object | null | undefined,
opts?: object | null, opts?: object | null,
@ -5161,6 +5269,15 @@ export function isFlow(
"UnionTypeAnnotation" === nodeType || "UnionTypeAnnotation" === nodeType ||
"Variance" === nodeType || "Variance" === nodeType ||
"VoidTypeAnnotation" === nodeType || "VoidTypeAnnotation" === nodeType ||
"EnumDeclaration" === nodeType ||
"EnumBooleanBody" === nodeType ||
"EnumNumberBody" === nodeType ||
"EnumStringBody" === nodeType ||
"EnumSymbolBody" === nodeType ||
"EnumBooleanMember" === nodeType ||
"EnumNumberMember" === nodeType ||
"EnumStringMember" === nodeType ||
"EnumDefaultedMember" === nodeType ||
"IndexedAccessType" === nodeType || "IndexedAccessType" === nodeType ||
"OptionalIndexedAccessType" === nodeType "OptionalIndexedAccessType" === nodeType
) { ) {
@ -5370,6 +5487,108 @@ export function isJSX(
return false; 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( export function isTSTypeElement(
node: object | null | undefined, node: object | null | undefined,
opts?: object | null, opts?: object | null,