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

DRY await destructure and each destructure code #4560

Closed
tanhauhau opened this issue Mar 15, 2020 · 4 comments · Fixed by #4596
Closed

DRY await destructure and each destructure code #4560

tanhauhau opened this issue Mar 15, 2020 · 4 comments · Fixed by #4596

Comments

@tanhauhau
Copy link
Member

Reference: #4548 (comment)

@Conduitry
Copy link
Member

To answer your question on that PR, yeah I'd definitely be in favor of switching each block destructuring over to your new code that can handle default values.

@tanhauhau
Copy link
Member Author

@Conduitry yea i understand about the code part. i will use the each block destructuring code, but how about the behavior? should we have a default value in the destructuring?

@Conduitry
Copy link
Member

Oh I may have misunderstood your other comment. I thought your spread implementation for awaits already supported default values. If it doesn't, I don't think we need to get that in as part of this issue, because it's apparently not a highly demanded feature as it's never come up as far as I know.

@tanhauhau
Copy link
Member Author

oh i think i misunderstood you. the await destructure supports default value, but the each destructure does not. so, i was asking of whether to support default value on each destructure too...

...and i noticed then in the generated code, each destructure will "transpile" to assignment statements:

function get_each_context(ctx) {
   const child_ctx = ctx.slice();
   child_ctx[2] = ctx[1].foo
   child_ctx[3] = ctx[1].bar
   child_ctx[4] = rest(ctx[1], ['foo', 'bar'])
   return child_ctx
}

whereas the await destructure, i was using object destructure:

function get_each_context(ctx) {
   const child_ctx = ctx.slice();
   ({ foo: child_ctx[2], bar: child_ctx[3], ...child_ctx[4] } = ctx[1]);
   return child_ctx
}

is there any concern or preference for either?

according to https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Destructuring_assignment,

array destructuring rest is still not supported for safari, is that why?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants