-
-
Notifications
You must be signed in to change notification settings - Fork 159
Add iterator for ASTNodeArray #8
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
Changes from 4 commits
ce97d35
3febdf8
8577018
e287eb3
27a2ec0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -74,7 +74,11 @@ declare module "tree-sitter" { | |
|
|
||
| type ArrayCallback<TItem, TArray, TReturn> = (node: TItem, index?: number, array?: TArray) => TReturn | ||
|
|
||
| export interface AstNodeArray extends ArrayLike<AstNode> { | ||
| export interface AstNodeArray extends ArrayLike<AstNode>, Iterable<AstNode> { | ||
| // Getters | ||
| isNamed: boolean; | ||
|
||
|
|
||
| // Methods | ||
| map<T>(callback: ArrayCallback<AstNode, AstNodeArray, void>, thisArg?: any): T[]; | ||
| every(callback: ArrayCallback<AstNode, AstNodeArray, void>, thisArg?: any): void; | ||
| filter(callback: ArrayCallback<AstNode, AstNodeArray, boolean>, thisArg?: any): AstNode[]; | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Even though it will mean more duplication, I'd prefer to have one conditional check at the beginning of the loop, rather than a closure with a conditional on each iteration. Something like:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can do this, but I wanted to mention that the way it's currently implemented doesn't use a closure and the
this.isNamedis only evaluated once. The only difference this change would make would be removing the stack frame of the lambda on lines 31/32.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, thanks for pointing that out; I misread your code.