-
Notifications
You must be signed in to change notification settings - Fork 38
feat(acrorn-parser): adding support for binary expression #26
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
feat(acrorn-parser): adding support for binary expression #26
Conversation
vault-developer
left a comment
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.
Hey @raj-kumar-s-dev thank you for the PR.
Could you check comments please?
| code: `console.log(1); | ||
| setTimeout(() => console.log(2), 0); | ||
| queueMicrotask(() => console.log(3)); | ||
| console.log(2-1); |
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.
🎯 suggestion:
Adding 5 additional binary expression examples to the "microtasks" example may create confusion as they are not related to microtasks.
What do you think about adding some of them to "everything" instead?
| const operator = binaryExpression.operator; | ||
| switch (operator) { | ||
| case '+': | ||
| return left + right; |
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.
|
|
||
| serialize = () => { | ||
| // eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
| const binaryExpression = this.node as any; |
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.
| const binaryExpression = this.node as any; | |
| import {BinaryExpression} from "acorn"; | |
| const binaryExpression = this.node as BinaryExpression; |
| const left = binaryExpression.left.value; | ||
| const right = binaryExpression.right.value; | ||
| const operator = binaryExpression.operator; | ||
| switch (operator) { |
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.
🎯 suggestion:
I suggest to handle all possible operators, you can check types in acorn:
export type BinaryOperator = "==" | "!=" | "===" | "!==" | "<" | "<=" | ">" | ">=" | "<<" | ">>" | ">>>" | "+" | "-" | "*" | "/" | "%" | "|" | "^" | "&" | "in" | "instanceof" | "**"
| } | ||
| }; | ||
|
|
||
| traverse = () => {}; |
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.
🎯 suggestion(blocking):
I suggest to traverse binaryExpression members further.
Otherwise, they won't be properly managed by the event loop.
Example:
console.log(1 + console.log(1));
|
I'm closing the PR since there have been no updates for more than 1 month. |

@vault-developer
I know i disabled the eslint rule in BinaryExpression.ts
It wasn't my intention to do so.
I tried casting the type to BinaryExpression.
But it didn't work and led to more eslint errors.
If you know of a better approach, please let me know.