Skip to content

[AST] PatOrExpr #5186

Answered by magic-akari
magic-akari asked this question in Q&A
Jul 12, 2022 · 3 comments · 9 replies
Discussion options

You must be logged in to vote

Concise design from oxc: AssignmentTarget

OXC Playground
SWC AST

https://github.com/web-infra-dev/oxc/blob/09ebe961d2a6b859f627af86f666d57d28b6a9b3/crates/oxc_ast/src/ast/js.rs#L746-L763

In swc, this structure is called PatOrExpr, while in oxc, it is referred to AssignmentTarget.

AssignmentTarget is an enum with two variants: SimpleAssignmentTarget and AssignmentTargetPattern.

SimpleAssignmentTarget wraps an identifier, or member expression (or TypeScript expression).
AssignmentTargetPattern corresponds to Pat in swc.

This design offers the following advantages:

  1. Explicit lhs. By marking the lhs during the parsing phase, we can easily determine whether an expression is an lhs during the t…

Replies: 3 comments 9 replies

Comment options

You must be logged in to vote
5 replies
@kdy1
Comment options

@kdy1
Comment options

@Austaras
Comment options

@magic-akari
Comment options

@Austaras
Comment options

Comment options

You must be logged in to vote
1 reply
@kdy1
Comment options

Comment options

You must be logged in to vote
3 replies
@kdy1
Comment options

@kdy1
Comment options

@magic-akari
Comment options

Answer selected by kdy1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants