eslint-plugin-unicorn
eslint-plugin-unicorn copied to clipboard
prefer-top-level-await flags code that can't be top-level-awaited
In class definitions top-level-await is not available but this rule still marks the code as wrong
The rule: unicorn/prefer-top-level-await
class Example {
property = Promise // Can't await here
.resolve(1)
.then(i => i+1); // Error here <- Prefer top-level await over using a promise chain.
}
I'm confused, I can't find anything forbid TLA in class member, the spec, acorn PR, MDN.
But Node.js/browsers/parsers all(except @typescript-eslint/parser
which can't be trust) failed to pase class A {foo = await 1}
.
So the real question is where the TLA expression can be?
Because when parsing class member, the parser enters a non-async function? Need more time to learn the spec.
Maybe the Initializer which runs for ClassFields is a part of the constructor which doesn't allow async?