Skip to content

Commit

Permalink
Flow types for match AST nodes, generated JS changes
Browse files Browse the repository at this point in the history
Summary: Adds the generated output from running `yarn build` and the type annotations requried for match expressions/statements/patterns.

Reviewed By: SamChou19815

Differential Revision: D66062801

fbshipit-source-id: 23472978b207d7d757eb25eb40eb1f7670f3338b
  • Loading branch information
gkz authored and facebook-github-bot committed Dec 7, 2024
1 parent e72f400 commit eff47d8
Show file tree
Hide file tree
Showing 6 changed files with 760 additions and 1 deletion.
96 changes: 96 additions & 0 deletions tools/hermes-parser/js/hermes-estree/src/generated/predicates.js
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,22 @@ import type {
KeyofTypeAnnotation,
LabeledStatement,
LogicalExpression,
MatchArrayPattern,
MatchAsPattern,
MatchBindingPattern,
MatchExpression,
MatchExpressionCase,
MatchIdentifierPattern,
MatchLiteralPattern,
MatchMemberPattern,
MatchObjectPattern,
MatchObjectPatternProperty,
MatchOrPattern,
MatchRestPattern,
MatchStatement,
MatchStatementCase,
MatchUnaryPattern,
MatchWildcardPattern,
MemberExpression,
MetaProperty,
MethodDefinition,
Expand Down Expand Up @@ -766,6 +782,86 @@ export function isLogicalExpression(node /*: ESNode | Token */) /*: implies node
}


export function isMatchArrayPattern(node /*: ESNode | Token */) /*: implies node is MatchArrayPattern */ {
return node.type === 'MatchArrayPattern';
}


export function isMatchAsPattern(node /*: ESNode | Token */) /*: implies node is MatchAsPattern */ {
return node.type === 'MatchAsPattern';
}


export function isMatchBindingPattern(node /*: ESNode | Token */) /*: implies node is MatchBindingPattern */ {
return node.type === 'MatchBindingPattern';
}


export function isMatchExpression(node /*: ESNode | Token */) /*: implies node is MatchExpression */ {
return node.type === 'MatchExpression';
}


export function isMatchExpressionCase(node /*: ESNode | Token */) /*: implies node is MatchExpressionCase */ {
return node.type === 'MatchExpressionCase';
}


export function isMatchIdentifierPattern(node /*: ESNode | Token */) /*: implies node is MatchIdentifierPattern */ {
return node.type === 'MatchIdentifierPattern';
}


export function isMatchLiteralPattern(node /*: ESNode | Token */) /*: implies node is MatchLiteralPattern */ {
return node.type === 'MatchLiteralPattern';
}


export function isMatchMemberPattern(node /*: ESNode | Token */) /*: implies node is MatchMemberPattern */ {
return node.type === 'MatchMemberPattern';
}


export function isMatchObjectPattern(node /*: ESNode | Token */) /*: implies node is MatchObjectPattern */ {
return node.type === 'MatchObjectPattern';
}


export function isMatchObjectPatternProperty(node /*: ESNode | Token */) /*: implies node is MatchObjectPatternProperty */ {
return node.type === 'MatchObjectPatternProperty';
}


export function isMatchOrPattern(node /*: ESNode | Token */) /*: implies node is MatchOrPattern */ {
return node.type === 'MatchOrPattern';
}


export function isMatchRestPattern(node /*: ESNode | Token */) /*: implies node is MatchRestPattern */ {
return node.type === 'MatchRestPattern';
}


export function isMatchStatement(node /*: ESNode | Token */) /*: implies node is MatchStatement */ {
return node.type === 'MatchStatement';
}


export function isMatchStatementCase(node /*: ESNode | Token */) /*: implies node is MatchStatementCase */ {
return node.type === 'MatchStatementCase';
}


export function isMatchUnaryPattern(node /*: ESNode | Token */) /*: implies node is MatchUnaryPattern */ {
return node.type === 'MatchUnaryPattern';
}


export function isMatchWildcardPattern(node /*: ESNode | Token */) /*: implies node is MatchWildcardPattern */ {
return node.type === 'MatchWildcardPattern';
}


export function isMemberExpression(node /*: ESNode | Token */) /*: implies node is MemberExpression */ {
return node.type === 'MemberExpression';
}
Expand Down
110 changes: 109 additions & 1 deletion tools/hermes-parser/js/hermes-estree/src/types.js
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,12 @@ export type ESNode =
| EnumSymbolBody
| DeclaredNode
| ObjectTypeInternalSlot
// Match
| MatchPattern
| MatchRestPattern
| MatchObjectPatternProperty
| MatchExpressionCase
| MatchStatementCase
// JSX
| JSXNode;

Expand Down Expand Up @@ -269,7 +275,8 @@ export type Statement =
| TypeAlias
| VariableDeclaration
| WhileStatement
| WithStatement;
| WithStatement
| MatchStatement;

// nodes that can be the direct parent of a statement
export type StatementParentSingle =
Expand Down Expand Up @@ -478,6 +485,7 @@ export type Expression =
| TypeCastExpression
| AsExpression
| AsConstExpression
| MatchExpression
| JSXFragment
| JSXElement;

Expand Down Expand Up @@ -2001,6 +2009,106 @@ export interface JSXSpreadChild extends BaseNode {
+expression: Expression;
}

/************************************
* Match expressions and statements *
************************************/

export interface MatchExpression extends BaseNode {
+type: 'MatchExpression';
+argument: Expression;
+cases: $ReadOnlyArray<MatchExpressionCase>;
}
export interface MatchExpressionCase extends BaseNode {
+type: 'MatchExpressionCase';
+pattern: MatchPattern;
+body: Expression;
+guard: Expression | null;
}

export interface MatchStatement extends BaseNode {
+type: 'MatchStatement';
+argument: Expression;
+cases: $ReadOnlyArray<MatchStatementCase>;
}
export interface MatchStatementCase extends BaseNode {
+type: 'MatchStatementCase';
+pattern: MatchPattern;
+body: BlockStatement;
+guard: Expression | null;
}

/******************
* Match patterns *
******************/

export type MatchPattern =
| MatchOrPattern
| MatchAsPattern
| MatchWildcardPattern
| MatchLiteralPattern
| MatchUnaryPattern
| MatchIdentifierPattern
| MatchMemberPattern
| MatchBindingPattern
| MatchObjectPattern
| MatchArrayPattern;

export interface MatchOrPattern extends BaseNode {
+type: 'MatchOrPattern';
+patterns: $ReadOnlyArray<MatchPattern>;
}
export interface MatchAsPattern extends BaseNode {
+type: 'MatchAsPattern';
+pattern: MatchPattern;
+target: Identifier | MatchBindingPattern;
}
export interface MatchWildcardPattern extends BaseNode {
+type: 'MatchWildcardPattern';
}
export interface MatchLiteralPattern extends BaseNode {
+type: 'MatchLiteralPattern';
+literal: Literal;
}
export interface MatchUnaryPattern extends BaseNode {
+type: 'MatchUnaryPattern';
+argument: Literal;
+operator: '-' | '+';
}
export interface MatchIdentifierPattern extends BaseNode {
+type: 'MatchIdentifierPattern';
+id: Identifier;
}
export interface MatchMemberPattern extends BaseNode {
+type: 'MatchMemberPattern';
+base: MatchIdentifierPattern | MatchMemberPattern;
+property: Identifier | StringLiteral | NumericLiteral | BigIntLiteral;
}
export interface MatchBindingPattern extends BaseNode {
+type: 'MatchBindingPattern';
+id: Identifier;
+kind: 'let' | 'const' | 'var';
}
export interface MatchObjectPattern extends BaseNode {
+type: 'MatchObjectPattern';
+properties: $ReadOnlyArray<MatchObjectPatternProperty>;
+rest: MatchRestPattern | null;
}
export interface MatchObjectPatternProperty extends BaseNode {
+type: 'MatchObjectPatternProperty';
+key: Identifier | StringLiteral | NumericLiteral | BigIntLiteral;
+pattern: MatchPattern;
+shorthand: boolean;
}
export interface MatchArrayPattern extends BaseNode {
+type: 'MatchArrayPattern';
+elements: $ReadOnlyArray<MatchPattern>;
+rest: MatchRestPattern | null;
}
export interface MatchRestPattern extends BaseNode {
+type: 'MatchRestPattern';
+argument: MatchBindingPattern | null;
}

/******************************************************
* Deprecated spec nodes awaiting migration by Hermes *
******************************************************/
Expand Down
Loading

0 comments on commit eff47d8

Please sign in to comment.