-
-
Notifications
You must be signed in to change notification settings - Fork 931
test(linter/plugins): add types test for VisitorObject
#20066
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
Merged
graphite-app
merged 1 commit into
main
from
om/03-06-test_linter_plugins_add_types_test_for_visitorobject_
Mar 6, 2026
+77
−0
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,68 @@ | ||
| import type { ExpectExtends, ExpectTrue, ExpectFalse } from "@type-challenges/utils"; | ||
| import type { VisitorObject } from "./generated/visitor.d.ts"; | ||
| import type { Node, CallExpression } from "./generated/types.d.ts"; | ||
|
|
||
| // Empty visitor object is allowed | ||
| const emptyVisitor = {}; | ||
| export type _Empty = ExpectTrue<ExpectExtends<VisitorObject, typeof emptyVisitor>>; | ||
|
|
||
| // Specific node visitors have a stricter type for the parameter | ||
| const callExpressionVisitor = { | ||
| CallExpression: (_node: CallExpression) => {}, | ||
| }; | ||
| export type _CallExpr = ExpectTrue<ExpectExtends<VisitorObject, typeof callExpressionVisitor>>; | ||
|
|
||
| const callExpressionExitVisitor = { | ||
| "CallExpression:exit": (_node: CallExpression) => {}, | ||
| }; | ||
| export type _CallExprExit = ExpectTrue< | ||
| ExpectExtends<VisitorObject, typeof callExpressionExitVisitor> | ||
| >; | ||
|
|
||
| const debuggerStatementWrongTypeVisitor = { | ||
| DebuggerStatement: (_node: CallExpression) => {}, | ||
| }; | ||
| export type _DebuggerStmtWrongType = ExpectFalse< | ||
| ExpectExtends<VisitorObject, typeof debuggerStatementWrongTypeVisitor> | ||
| >; | ||
|
|
||
| // Node selectors have generic `Node` type for the parameter | ||
| const selectorsVisitor = { | ||
| "FunctionExpression > Identifier": (_node: Node) => {}, | ||
| ":matches(FunctionExpression, FunctionDeclaration)": (_node: Node) => {}, | ||
| }; | ||
| export type _Selectors = ExpectTrue<ExpectExtends<VisitorObject, typeof selectorsVisitor>>; | ||
|
|
||
| // Visitor functions can omit the node parameter | ||
| const callExpressionNoParamVisitor = { | ||
| CallExpression: () => {}, | ||
| }; | ||
| export type _CallExprNoParam = ExpectTrue< | ||
| ExpectExtends<VisitorObject, typeof callExpressionNoParamVisitor> | ||
| >; | ||
|
|
||
| // Properties of visitor object can be `undefined`. | ||
| // Ideally we'd disallow this, but it's not possible without `exactOptionalPropertyTypes: true` in `tsconfig.json`. | ||
| // Obviously we can't force that on users. | ||
| const callExpressionUndefinedVisitor = { | ||
| CallExpression: undefined, | ||
| }; | ||
| export type _CallExprUndefined = ExpectTrue< | ||
| ExpectExtends<VisitorObject, typeof callExpressionUndefinedVisitor> | ||
| >; | ||
|
|
||
| // Other types are not allowed | ||
| const invalidNullVisitor = { | ||
| CallExpression: null, | ||
| }; | ||
| export type _InvalidNull = ExpectFalse<ExpectExtends<VisitorObject, typeof invalidNullVisitor>>; | ||
|
|
||
| const invalidObjectVisitor = { | ||
| CallExpression: {}, | ||
| }; | ||
| export type _InvalidObject = ExpectFalse<ExpectExtends<VisitorObject, typeof invalidObjectVisitor>>; | ||
|
|
||
| const invalidStringVisitor = { | ||
| CallExpression: "oh dear", | ||
| }; | ||
| export type _InvalidString = ExpectFalse<ExpectExtends<VisitorObject, typeof invalidStringVisitor>>; |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.