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

refactor(vm): Allow nested binding patterns to be simple #401

Merged
merged 2 commits into from
Aug 25, 2024

Conversation

andreubotella
Copy link
Collaborator

Array and object binding patterns can be either simple or complex, where simple patterns are compiled in a way that jumps into a separate execution context where only binding-related bytecode instructions are supported.

Currently, if an array or object binding pattern contains another binding pattern, that automatically makes the outer pattern complex. However, that doesn't need to be the case, as long as none of the nested patterns, no matter how deeply nested, have initializers or computed property keys.

As it turns out, the spec has a syntax-directed operation called ContainsExpression that checks exactly this, and which affects the behavior of FunctionDeclarationInstantiation. Our implementation currently does not use that, since we don't yet support bindings or initializers in function parameters, which is why we don't yet implement it. This patch adds an implementation for that, and uses it to enable nested simple binding patterns.


This PR builds on top of #398, #399 and #400, do not merge before those.

aapoalas
aapoalas previously approved these changes Aug 25, 2024
Array and object binding patterns can be either simple or complex,
where simple patterns are compiled in a way that jumps into a separate
execution context where only binding-related bytecode instructions are
supported.

Currently, if an array or object binding pattern contains another
binding pattern, that automatically makes the outer pattern complex.
However, that doesn't need to be the case, as long as none of the
nested patterns, no matter how deeply nested, have initializers or
computed property keys.

As it turns out, the spec has a syntax-directed operation called
`ContainsExpression` that checks exactly this, and which affects the
behavior of `FunctionDeclarationInstantiation`. Our implementation
currently does not use that, since we don't yet support bindings or
initializers in function parameters, which is why we don't yet
implement it. This patch adds an implementation for that, and uses it
to enable nested simple binding patterns.
aapoalas
aapoalas previously approved these changes Aug 25, 2024
@andreubotella andreubotella merged commit c2f26dd into trynova:main Aug 25, 2024
1 check passed
@andreubotella andreubotella deleted the simple-nested-binding branch August 25, 2024 18:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants