Skip to content

Parse error with object destructuring inside for loop initializer. #164

@Luni-4

Description

@Luni-4

When I tried to parse this code:

async function *fn() {
  for await (var { w: { x, y, z } = { x: 4, y: 5, z: 6 } } of asyncIter) {
    assert.sameValue(x, 4);
    assert.sameValue(y, 5);
    assert.sameValue(z, 6);

    assert.throws(ReferenceError, function() {
      w;
    });

    iterCount += 1;
  }
}

fn().next()
  .then(() => assert.sameValue(iterCount, 1, 'iteration occurred as expected'), $DONE)
  .then($DONE, $DONE);

I got the following AST:

(program [0, 0] - [13, 0]
  (ERROR [0, 0] - [12, 1]
    (identifier [0, 16] - [0, 18])
    (formal_parameters [0, 18] - [0, 20])
    (ERROR [1, 19] - [1, 35]
      (pair_pattern [1, 19] - [1, 33]
        key: (property_identifier [1, 19] - [1, 20])
        value: (object_pattern [1, 22] - [1, 33]
          (shorthand_property_identifier_pattern [1, 24] - [1, 25])
          (shorthand_property_identifier_pattern [1, 27] - [1, 28])
          (shorthand_property_identifier_pattern [1, 30] - [1, 31]))))
    (object_pattern [1, 36] - [12, 1]
      (ERROR [1, 38] - [11, 3]
        (property_identifier [1, 38] - [1, 39])
        (number [1, 41] - [1, 42])
        (ERROR [1, 44] - [1, 48]
          (property_identifier [1, 44] - [1, 45])
          (number [1, 47] - [1, 48]))
        (pair_pattern [1, 50] - [1, 71]
          key: (property_identifier [1, 50] - [1, 51])
          (ERROR [1, 53] - [1, 61]
            (number [1, 53] - [1, 54]))
          value: (identifier [1, 62] - [1, 71]))
        (object_pattern [1, 73] - [11, 3]
          (ERROR [2, 4] - [2, 21]
            (identifier [2, 4] - [2, 10])
            (identifier [2, 11] - [2, 20]))
          (shorthand_property_identifier_pattern [2, 21] - [2, 22])
          (ERROR [2, 24] - [3, 21]
            (number [2, 24] - [2, 25])
            (identifier [3, 4] - [3, 10])
            (identifier [3, 11] - [3, 20]))
          (shorthand_property_identifier_pattern [3, 21] - [3, 22])
          (ERROR [3, 24] - [4, 21]
            (number [3, 24] - [3, 25])
            (identifier [4, 4] - [4, 10])
            (identifier [4, 11] - [4, 20]))
          (shorthand_property_identifier_pattern [4, 21] - [4, 22])
          (ERROR [4, 24] - [6, 18]
            (number [4, 24] - [4, 25])
            (identifier [6, 4] - [6, 10])
            (identifier [6, 11] - [6, 17]))
          (shorthand_property_identifier_pattern [6, 18] - [6, 32])
          (ERROR [6, 34] - [10, 19]
            (identifier [6, 34] - [6, 42])
            (object_pattern [6, 45] - [8, 5]
              (shorthand_property_identifier_pattern [7, 6] - [7, 7])
              (ERROR [7, 7] - [7, 8]))
            (identifier [10, 4] - [10, 13])
            (number [10, 17] - [10, 18])))))))

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugpriority:mediummedium-priority task, typically with broad demand but not blocking

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions