archives

« Bugzilla Issues Index

#2506 — 12.1.5, 14.2: Tweak grammar to allow CoverInitialisedName and duplicate PropertyNames in ArrowParameters?


As far as I can see, the following examples are not allowed due to the early errors semantics in 12.1.5.1:
---
// Duplicate property name "x" in object literal in strict mode
"use strict"; ({x: a, x: b}) => {}

// Missing ':' after property name "x" in object literal
({x = 0}) => {}
({x = 0}, {y = 0}) => {}
---

Whereas this code is allowed, because the object parameter is first parsed as an destructuring assignment pattern:
---
"use strict"; ({x: a, x: b} = {}) => {}

({x = 0} = {}) => {}
({x = 0} = {}, {y = 0} = {}) => {}
---

It may make sense to change the grammar to allow the first examples, but I'm not really sure right now how much effort this requires...


Fixed in rev23 editor's draft.

Added clarifying text in 12.1.5.1:

In addition to describing an actual object initializer the ObjectLiteral productions are also used as a cover grammar for ObjectAssignmentPattern (12.13.5). and may be recognized as part of a CoverParenthesisedExpressionAndArrowParameterList. When ObjectLiteral appears in a context where ObjectAssignmentPattern is required the following Early Error rules are not applied. In addition, they are not applied when initially parsing a CoverParenthesisedExpressionAndArrowParameterList.

Does that work?


(In reply to comment #1)
> Does that work?

Yes, I think so. It's now more clear that the early error restrictions apply if and only if the production is used to describe an object initialiser.


fixed in rev23 draft