Skip to content

Conversation

@pepkin88
Copy link
Contributor

Fix for #1019, #1021 and #1023.

This wasn't that hard as I imagined. Did I get it right?
I also noticed a similar behavior is duplicated in Node::compile-closure. Perhaps it could be rewritten to use Call.let inside.
I still don't know how everything works, but more and more I get the hang of it.

Copy link
Collaborator

@rhendric rhendric left a comment

Choose a reason for hiding this comment

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

Nice work! This is almost identical to the solution I found. Fix one minor style quibble and then this is good to go.

switch child.op
| \yield \yieldfrom => has-yield := true
| \await => has-await := true
return true if has-yield and has-await
Copy link
Collaborator

Choose a reason for hiding this comment

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

A function can never legally have both a yield and an await, so this is a little misleading. Could you change this back to something a little closer to the original expression in add-body, where you return as soon as any instance of Yield is found? Instead of returning true you can return child.op, to distinguish between the yield and await cases without mutating a variable in the outer scope.

Copy link
Contributor Author

@pepkin88 pepkin88 Jul 30, 2018

Choose a reason for hiding this comment

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

I left this in intentionally for async generators, as I would imagine they will come to LS eventually. I thought it would be better to future-proof it, in case someone implementing async generators forgets about awaits and yields in let blocks, as it have happened with async functions.

Copy link
Collaborator

Choose a reason for hiding this comment

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

That's a good thought! I wasn't aware that async generators had gotten this far in the standardization process before now; they should be very easy to add to LiveScript, so I agree this is a good precaution.

switch child.op
| \yield \yieldfrom => has-yield := true
| \await => has-await := true
return true if has-yield and has-await
Copy link
Collaborator

Choose a reason for hiding this comment

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

That's a good thought! I wasn't aware that async generators had gotten this far in the standardization process before now; they should be very easy to add to LiveScript, so I agree this is a good precaution.

@rhendric rhendric merged commit 8ac8bb4 into gkz:master Jul 30, 2018
@pepkin88 pepkin88 deleted the yield-and-await-in-let branch July 30, 2018 13:01
@pepkin88 pepkin88 restored the yield-and-await-in-let branch July 30, 2018 17:32
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