Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a jump-table for visitEachChild #50266

Merged
merged 3 commits into from
Aug 18, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
138 changes: 138 additions & 0 deletions src/compiler/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -885,6 +885,144 @@ namespace ts {
/* @internal */ jsDocCache?: readonly JSDocTag[]; // Cache for getJSDocTags
}

/* @internal */
export type HasChildren =
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I assume that if we need to update this, we'll know because some other code won't be able to compile?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To add a method to visitEachChild (and potentially forEachChild), we'd have to add the node to this union.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What happens if someone adds a new syntax kind and forgets to update this? Seems like their new node might not emit its children?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AFAIK that's what would have happened in the old code too, because it'd hit the default case to just do nothing.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If both this and #50225 use HasChildren, then you wouldn't be able to define a forEachChild branch or visitEachChild branch without adding an entry, and if you add an entry to HasChildren you would have compile time errors if you forget to add branches to forEachChild and visitEachChild.

| Identifier
| QualifiedName
| ComputedPropertyName
| TypeParameterDeclaration
| ParameterDeclaration
| Decorator
| PropertySignature
| PropertyDeclaration
| MethodSignature
| MethodDeclaration
| ConstructorDeclaration
| GetAccessorDeclaration
| SetAccessorDeclaration
| ClassStaticBlockDeclaration
| CallSignatureDeclaration
| ConstructSignatureDeclaration
| IndexSignatureDeclaration
| TypePredicateNode
| TypeReferenceNode
| FunctionTypeNode
| ConstructorTypeNode
| TypeQueryNode
| TypeLiteralNode
| ArrayTypeNode
| TupleTypeNode
| OptionalTypeNode
| RestTypeNode
| UnionTypeNode
| IntersectionTypeNode
| ConditionalTypeNode
| InferTypeNode
| ImportTypeNode
| ImportTypeAssertionContainer
| NamedTupleMember
| ParenthesizedTypeNode
| TypeOperatorNode
| IndexedAccessTypeNode
| MappedTypeNode
| LiteralTypeNode
| TemplateLiteralTypeNode
| TemplateLiteralTypeSpan
| ObjectBindingPattern
| ArrayBindingPattern
| BindingElement
| ArrayLiteralExpression
| ObjectLiteralExpression
| PropertyAccessExpression
| ElementAccessExpression
| CallExpression
| NewExpression
| TaggedTemplateExpression
| TypeAssertion
| ParenthesizedExpression
| FunctionExpression
| ArrowFunction
| DeleteExpression
| TypeOfExpression
| VoidExpression
| AwaitExpression
| PrefixUnaryExpression
| PostfixUnaryExpression
| BinaryExpression
| ConditionalExpression
| TemplateExpression
| YieldExpression
| SpreadElement
| ClassExpression
| ExpressionWithTypeArguments
| AsExpression
| NonNullExpression
| MetaProperty
| TemplateSpan
| Block
| VariableStatement
| ExpressionStatement
| IfStatement
| DoStatement
| WhileStatement
| ForStatement
| ForInStatement
| ForOfStatement
| ContinueStatement
| BreakStatement
| ReturnStatement
| WithStatement
| SwitchStatement
| LabeledStatement
| ThrowStatement
| TryStatement
| VariableDeclaration
| VariableDeclarationList
| FunctionDeclaration
| ClassDeclaration
| InterfaceDeclaration
| TypeAliasDeclaration
| EnumDeclaration
| ModuleDeclaration
| ModuleBlock
| CaseBlock
| NamespaceExportDeclaration
| ImportEqualsDeclaration
| ImportDeclaration
| AssertClause
| AssertEntry
| ImportClause
| NamespaceImport
| NamespaceExport
| NamedImports
| ImportSpecifier
| ExportAssignment
| ExportDeclaration
| NamedExports
| ExportSpecifier
| ExternalModuleReference
| JsxElement
| JsxSelfClosingElement
| JsxOpeningElement
| JsxClosingElement
| JsxFragment
| JsxAttribute
| JsxAttributes
| JsxSpreadAttribute
| JsxExpression
| CaseClause
| DefaultClause
| HeritageClause
| CatchClause
| PropertyAssignment
| ShorthandPropertyAssignment
| SpreadAssignment
| EnumMember
| SourceFile
| PartiallyEmittedExpression
| CommaListExpression
;

export type HasJSDoc =
| ParameterDeclaration
| CallSignatureDeclaration
Expand Down
Loading