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

ES6 feature: Destructuring: Tracking Issue #1045

Closed
3 tasks done
ariya opened this issue Feb 16, 2015 · 0 comments
Closed
3 tasks done

ES6 feature: Destructuring: Tracking Issue #1045

ariya opened this issue Feb 16, 2015 · 0 comments
Labels
Milestone

Comments

@ariya
Copy link
Contributor

ariya commented Feb 16, 2015

12.14.5 Destructuring Assignment

They are used in the left hand side of an assignment expression when = is the assignment operator, or at the LeftHandSideExpression position of a for-in or a for-of loop.

Referred to by:

  • 12.14.1 Static Semantics: Early Errors
  • 13.6.4.1 Static Semantics: Early Errors

Syntax:

AssignmentPattern[Yield] :
  ObjectAssignmentPattern[?Yield]
  ArrayAssignmentPattern[?Yield]

ObjectAssignmentPattern[Yield] :
  { }
  { AssignmentPropertyList[?Yield] }
  { AssignmentPropertyList[?Yield] , }

ArrayAssignmentPattern[Yield] :
  [ Elisionopt AssignmentRestElement[?Yield]opt ]
  [ AssignmentElementList[?Yield] ]
  [ AssignmentElementList[?Yield] , Elisionopt AssignmentRestElement[?Yield]opt ]

AssignmentPropertyList[Yield] :
  AssignmentProperty[?Yield]
  AssignmentPropertyList[?Yield] , AssignmentProperty[?Yield]

AssignmentElementList[Yield] :
  AssignmentElisionElement[?Yield]
  AssignmentElementList[?Yield] , AssignmentElisionElement[?Yield]

AssignmentElisionElement[Yield] :
  Elisionopt AssignmentElement[?Yield]

AssignmentProperty[Yield] :
  IdentifierReference[?Yield] Initializer[In,?Yield]opt
  PropertyName : AssignmentElement[?Yield]

AssignmentElement[Yield] :
  DestructuringAssignmentTarget[?Yield] Initializer[In,?Yield]opt

AssignmentRestElement[Yield] :
  ... DestructuringAssignmentTarget[?Yield]

DestructuringAssignmentTarget[Yield] :
  LeftHandSideExpression[?Yield]

Spec:

Destructuring Assignment: https://people.mozilla.org/~jorendorff/es6-draft.html#sec-destructuring-assignment

Relevant AST interfaces (from https://github.com/estree/estree): (TBD)

Early Errors:

AssignmentProperty : IdentifierReference Initializeropt
  • It is a Syntax Error if IsValidSimpleAssignmentTarget of IdentifierReference is false.
DestructuringAssignmentTarget : LeftHandSideExpression
  • It is a Syntax Error if LeftHandSideExpression is either an ObjectLiteral or an ArrayLiteral and if the lexical token sequence matched by LeftHandSideExpression cannot be parsed with no tokens left over using AssignmentPattern as the goal symbol.
  • It is a Syntax Error if LeftHandSideExpression is neither an ObjectLiteral nor an ArrayLiteral and IsValidSimpleAssignmentTarget(LeftHandSideExpression) is false.

13.2.3 Destructuring Binding Patterns

BindingPatterns are used in LexicalBindings, VariableDeclarations, ForBindings and CatchParameters. BindingElement is also used in FormalParameters. A BindingElement is either a BindingPattern or a BindingIdentifier, optionally followed by a Initializer.

Syntax

BindingPattern[Yield,GeneratorParameter] :
  ObjectBindingPattern[?Yield,?GeneratorParameter]
  ArrayBindingPattern[?Yield,?GeneratorParameter]

ObjectBindingPattern[Yield,GeneratorParameter] :
  { }
  { BindingPropertyList[?Yield,?GeneratorParameter] }
  { BindingPropertyList[?Yield,?GeneratorParameter] , }

ArrayBindingPattern[Yield,GeneratorParameter] :
  [ Elisionopt BindingRestElement[?Yield, ?GeneratorParameter]opt ]
  [ BindingElementList[?Yield, ?GeneratorParameter] ]
  [ BindingElementList[?Yield, ?GeneratorParameter] , Elisionopt BindingRestElement[?Yield, ?GeneratorParameter]opt ]

BindingPropertyList[Yield,GeneratorParameter] :
  BindingProperty[?Yield, ?GeneratorParameter]
  BindingPropertyList[?Yield, ?GeneratorParameter] , BindingProperty[?Yield, ?GeneratorParameter]

BindingElementList[Yield,GeneratorParameter] :
  BindingElisionElement[?Yield, ?GeneratorParameter]
  BindingElementList[?Yield, ?GeneratorParameter] , BindingElisionElement[?Yield, ?GeneratorParameter]

BindingElisionElement[Yield,GeneratorParameter] :
  Elisionopt BindingElement[?Yield, ?GeneratorParameter]

BindingProperty[Yield,GeneratorParameter] :
  SingleNameBinding[?Yield, ?GeneratorParameter]
  PropertyName[?Yield, ?GeneratorParameter] : BindingElement[?Yield, ?GeneratorParameter]

BindingElement[Yield,GeneratorParameter] :
  SingleNameBinding[?Yield, ?GeneratorParameter]
  [+GeneratorParameter] BindingPattern[?Yield,GeneratorParameter] Initializer[In]opt
  [~GeneratorParameter] BindingPattern[?Yield] Initializer[In, ?Yield]opt

SingleNameBinding [Yield, GeneratorParameter] :
  [+GeneratorParameter] BindingIdentifier[Yield] Initializer[In]opt
  [~GeneratorParameter] BindingIdentifier[?Yield] Initializer[In, ?Yield]opt

BindingRestElement[Yield, GeneratorParameter] :
  [+GeneratorParameter] ... BindingIdentifier[Yield]
  [~GeneratorParameter] ... BindingIdentifier[?Yield]

Spec

Destructuring Binding Patterns: https://people.mozilla.org/~jorendorff/es6-draft.html#sec-destructuring-binding-patterns

Relevant AST interfaces (from https://github.com/estree/estree): (TBD)

SpiderMonkey AST

interface ObjectPattern <: Pattern {
    type: "ObjectPattern";
    properties: [ { key: Literal | Identifier, value: Pattern } ];
}

interface ArrayPattern <: Pattern {
    type: "ArrayPattern";
    elements: [ Pattern | null ];
}

Shift AST

typedef (ObjectBinding or ArrayBinding or BindingIdentifier or MemberExpression) Binding;


interface BindingWithDefault : Node {
  attribute (ObjectBinding or ArrayBinding or BindingIdentifier) binding;
  attribute Expression init;
};

interface BindingIdentifier : Node {
  attribute Identifier identifier;
};

interface ArrayBinding : Node {
  attribute (Binding or BindingWithDefault)?[] elements;
  attribute BindingIdentifier? restElement;
};

interface ObjectBinding : Node {
  attribute BindingProperty[] properties;
};

interface BindingProperty : Node { };

interface BindingPropertyIdentifier : BindingProperty {
  attribute BindingIdentifier identifier;
  attribute Expression? init;
};

interface BindingPropertyProperty : BindingProperty {
  attribute PropertyName name;
  attribute (Binding or BindingWithDefault) binding;
};


interface PropertyName : Node { };

interface ComputedPropertyName : PropertyName {
  attribute Expression value;
};

interface StaticPropertyName : PropertyName {
  attribute string value;
};

Related Tasks:

@mikesherov mikesherov changed the title ES6 feature: Destructuring ES6 feature: Destructuring: Tracking Issue Mar 7, 2015
@mikesherov mikesherov mentioned this issue Mar 7, 2015
25 tasks
@mikesherov mikesherov added this to the 2.2 milestone Mar 15, 2015
ikarienator added a commit to ikarienator/esprima that referenced this issue Mar 18, 2015
ikarienator added a commit to ikarienator/esprima that referenced this issue Mar 18, 2015
ikarienator added a commit to ikarienator/esprima that referenced this issue Mar 18, 2015
ikarienator added a commit to ikarienator/esprima that referenced this issue Mar 18, 2015
ikarienator added a commit to ikarienator/esprima that referenced this issue Mar 18, 2015
ikarienator added a commit to ikarienator/esprima that referenced this issue Mar 19, 2015
ariya added a commit to ariya/esprima that referenced this issue Dec 15, 2015
This is not necessary anymore once the cover grammar was properly
supported (part of jquery#1045).
ariya added a commit that referenced this issue Dec 17, 2015
This is not necessary anymore once the cover grammar was properly
supported (part of #1045).

Closes gh-1432
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

Successfully merging a pull request may close this issue.

3 participants