-
Notifications
You must be signed in to change notification settings - Fork 10
Disallow await
as an IdentifierReference or BindingIdentifier inside of a static block
#27
Comments
I think the cleanest solution would be to pass |
I'm concerned if we do that that if we introduced any new features under |
Isn't that what we'd want? It seems like static blocks should either inherit the outer context's async-ness wholesale or not at all, not piecemeal. (Though I still don't understand why we'd go with "not at all".) |
We're reserving it because there are still questions about what to do here, as we have been discussing in #7. Reserving class C {
static {
let await = 1;
}
} And we can later decide how we want to treat |
Hi folks. I'm very confused about the concept.
I have searched on specification. But there's not section about what exactly is the For example: var await = 1
class C {
static {
class D {
field = await
static staticFields = await
[await] = await
}
}
} Does the There's only two references of But for now. IdentifierReference could crossing the |
That's a good question. A "function boundary" is essentially anywhere code can execute when the function is called, such as the parameter list (initializers), and the body. A class body is not a function boundary, since the heritage clause and computed property names are evaluated in the lexical scope containing the class, not in the class itself. Per the class fields specification, field initializers have an implicit function boundary (each initializer is wrapped in a function and evaluated with an appropriate Consider this: var await = 1;
async function f() {
function g() {
console.log(await);
}
g();
}
f(); // prints 1 Applying that to your example: var await = 1
class C {
static {
class D {
field = await /*1*/
static staticFields = await /*2*/
[await /*3*/] = await /*4*/
}
}
}
So, the only error that should be reported for the above example is the |
Thanks for the explanations. Could we wrote these up into the spec? |
// Currently both Babel and V8 throw
class C { static { (await) => {} } }
// Currently both Babel and V8 throw
class C { static { ({ [await] : x }) => {} } } |
From the perspective of Contains, arrow function parameters do not cross a function boundary, but non-arrow function parameters do. So the answer for your example is "no".
Same thing: no for arrows, yes for non-arrows. |
Its also tricky for paren-less arrow functions. For example, the following is illegal today: async function f() {
(await => {}); error
((await) => {}); error
(function(await) {}); // ok
} In an async function, you parse the cover grammar for the arrow function parameters in the Another way I could handle this is parse the body of |
I still think that's the cleanest solution. |
Big, explicit +1 for this approach after reasoning through the implementation for when to allow |
I agree. I'll spend some time on updates to the spec text next week. |
The proposal currently does not allow a
static {}
block to inherit the[Await]
flag of its surrounding context. We intend to leave open the possibility of supporting this in the future, though not at this time. However, by passing[~Await]
to the statement list, we allow the use ofawait
as an identifier inside of thestatic {}
block, which would make adopting the outer[Await]
context a breaking change.To address this concern, we should disallow
await
as an IdentifierReference or BindingIdentifier directly inside of astatic {}
block (while still allowing it inside of a function nested inside of the block).Note that this is less of an issue with
yield
, asyield
is treated as a reserved word in strict mode, and class bodies are always strict.Related: #7, #24
The text was updated successfully, but these errors were encountered: