Skip to content

Implement Object ...rest Assignment in for of loop #758

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

komyg
Copy link

@komyg komyg commented Jun 14, 2025

Issue: #722

@load1n9 load1n9 self-requested a review June 15, 2025 17:11
Copy link
Member

@load1n9 load1n9 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM but fix the metrics file

@komyg komyg force-pushed the feature/rest-assignment-in-for-of branch from fa15f99 to 4802ac0 Compare June 15, 2025 18:23
@komyg
Copy link
Author

komyg commented Jun 15, 2025

LGTM but fix the metrics file

Hey @load1n9, done!

@komyg komyg requested a review from load1n9 June 15, 2025 18:23
load1n9
load1n9 previously approved these changes Jun 15, 2025
Copy link
Member

@load1n9 load1n9 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Copy link
Member

@aapoalas aapoalas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey, thanks for the patch.

This isn't yet ready for prime time, though. Try eg. this code:

const source = {};
let target;
({ ...target } = source);
if (target === source) {
  throw "impossible";
}

This will throw the "impossible" string: we're not actually creating a new object for b here at all. Furthermore, this code currently does not support property omissions at all, eg.

({ x, ...target } = source);

even if target was a new object, with the code right now this would still create an object with x property copied into target from source.

It seems you'll rather need the CopyDataPropertiesIntoObject instruction. See bytecode_compiler.rs:1872 and especially the branches related to object_pattern.rest in that function.

@komyg komyg force-pushed the feature/rest-assignment-in-for-of branch from 4802ac0 to 697bff0 Compare June 19, 2025 13:03
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.

3 participants