Closed Bug 1107711 Opened 11 years ago Closed 10 years ago

What's the deal with yield expressions in formal default initializers?

Categories

(Core :: JavaScript Engine, defect)

defect
Not set
normal

Tracking

()

RESOLVED INVALID

People

(Reporter: shu, Unassigned)

References

(Blocks 1 open bug)

Details

Are they allowed or not in ES6? Seems like they are (see 14.4's passing of [Yield] into the FormalParameters production [1]) we don't correctly support this. http://people.mozilla.org/~jorendorff/es6-draft.html#sec-generator-function-definitions
See Also: → 1073919
No, YieldExpression cannot appear in default initializers. The [GeneratorParameter] production parameter handles this case. A single formal parameter resolves to the BindingElement production (14.1, 13.2.3) FormalParameters -> FormalParameterList -> FormalsList -> FormalParameter -> BindingElement Case A: The formal parameter is not a BindingPattern, then we need to follow BindingElement -> SingleNameBinding. For generator functions the [GeneratorParameter] is present, so the only applicable production rule is: SingleNameBinding[Yield,GeneratorParameter] : [+GeneratorParameter] BindingIdentifier[Yield] Initializer[In]opt The Initializer production does not receiver the [Yield] parameter, so YieldExpression cannot appear within Initializer. Case B: The formal parameter is a BindingPattern, in that case the only applicable rule in BindingElement is: BindingElement[Yield, GeneratorParameter ] : [+GeneratorParameter] BindingPattern[?Yield,GeneratorParameter] Initializer[In]opt And again there's no [Yield] parameter, so YieldExpression cannot appear with Initializer. Well, actually there's also a Case C to check if YieldExpression can appear within computed property names in destructuring patterns. "function* g({[yield]: a}) {}" To check that case we need to follow BindingProperty -> PropertyName (13.2.3, 12.2.5). If [GeneratorParameter] is present the only applicable rule is: PropertyName[Yield,GeneratorParameter] : [+GeneratorParameter] ComputedPropertyName Same reasoning as above, no [Yield] parameter is set for ComputedPropertyName, so YieldExpression cannot appear within ComputedPropertyName.
yield expressions are not allowed in formal parameters, cf. ES2015, 14.4.1 Static Semantics: Early Errors: > It is a Syntax Error if FormalParameters Contains YieldExpression is true.
Status: NEW → RESOLVED
Closed: 10 years ago
Resolution: --- → INVALID
If we ever mis-implemented this, I'd lay decent money on bug 1155472 having fixed it.
You need to log in before you can comment on or make changes to this bug.