Open syg opened 1 month ago
The maximally consistent interpretation is to say that initializer RHSes are basically new function bodies and therefore should unset the yield
/await
flags, but we could also just unconditionally ban them. We do that for await
in static blocks (by unconditionally setting the flags and then having an early error for "contains await
").
The maximally consistent interpretation is to say that initializer RHSes are basically new function bodies and therefore should unset the yield/await flags, but we could also just unconditionally ban them. We do that for await in static blocks (by unconditionally setting the flags and then having an early error for "contains await").
Agreed. I think these should all be [~Yield, +Await, ~Return] with Early Error ban for await
, like static
blocks.
While we're at it... can we also ban syntactically
class C {
#secrets;
[this.#secrets] = 42;
static [this.#secrets] = 42;
};
or
class C {
static #secrets;
[this.#secrets] = 42;
static [this.#secrets] = 42;
};
Maybe this should be in a different issue though. Right now I think they're all a runtime error (Although, until recently it was a crash in JSC).
@kmiller68 Babel relies on it being syntactically valid to compile decorators, and banning it would break it:
FieldDefinition passes along [?Yield, ?Await], which means the RHS of field initializers inside async functions and generators allow
yield
andawait
expressions to be parsed.Suspending in the middle of construction of a class instance is super cursed!
It is arguably sensible for
static
initializers, but even that seems gross.Behavior diverges among browser implementations. JSC parses both
yield
andawait
expressions in initializers, and SpiderMonkey and V8 rejectyield
andawait
expressions.