-
Notifications
You must be signed in to change notification settings - Fork 902
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
Add rest/spread properties #658
Conversation
Thanks! @adrianheine Since you have experience with this, as you've also written a plugin for this, do you want to review? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tests for destructuring assignments and exports are missing.
// Rest Properties | ||
//------------------------------------------------------------------------------ | ||
|
||
test("({...obj} = foo)", { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This and below are destructuring assignments.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, I didn't mean assignments, I meant declarations.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, I see. I will add it.
@adrianheine would you teach me about tests for exports? I'm not sure if rest/spread properties are related to ES modules. |
You have to check for duplicate exports. I think for example this test would currently fail with your PR. |
Thank you! |
Thank you for the good catch. I updated this PR. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! Another thing: Could you remove object-spread
and object-rest
from unsupportedFeatures
in bin/run_test262.js
?
This looks significantly different than the equiv plugins. |
src/expression.js
Outdated
@@ -565,6 +567,30 @@ pp.parseObj = function(isPattern, refDestructuringErrors) { | |||
|
|||
pp.parseProperty = function(isPattern, refDestructuringErrors) { | |||
let prop = this.startNode(), isGenerator, isAsync, startPos, startLoc | |||
if (this.options.ecmaVersion >= 9 && this.eat(tt.ellipsis)) { | |||
// To disallow parenthesized identifier via `this.toAssignable()`. | |||
if (this.type === tt.parenL && refDestructuringErrors) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👆 just to clarify the check above
To disallow parenthesized identifier via
this.toAssignable()
Is that the default param value guard? Or something else (does it have a test).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the guard for the parenthesized identifier in RestElement. E.g. ({...(obj)} = foo)
. Yes, there are tests.
@jdalton What is the equiv plugins? |
I updated this PR.
|
Please see the acorn readme for the list, specifically the acorn-5 one by @adrianheine (on mobile or would get links). |
@mysticatea What @jdalton meant is ›the equivalent plugins‹, i. e. https://github.com/adrianheine/acorn5-object-spread and https://github.com/victor-homyakov/acorn-object-rest-spread. |
Thank you for the explanation. I wrote this PR from scratch. I check the difference.
|
Rock! 🎉 |
Great! Merged as 5aa2e73 |
Rest/Spread Properties arrived at Stage 4.
This PR implements it into Acorn.