Disallow await inside async arrow params#10469
Conversation
| const oldInClassProperty = this.state.inClassProperty; | ||
| const oldYieldPos = this.state.yieldPos; | ||
| const oldAwaitPos = this.state.awaitPos; | ||
| this.state.maybeInArrowParameters = false; |
There was a problem hiding this comment.
This is needed because this test started failing:
async function f() {
(function await() {});
}|
Build successful! You can test your changes in the REPL here: https://babeljs.io/repl/build/11707/ |
| language/expressions/async-arrow-function/early-errors-arrow-await-in-formals-default.js(default) | ||
| language/expressions/async-arrow-function/early-errors-arrow-await-in-formals-default.js(strict mode) | ||
| language/expressions/async-arrow-function/early-errors-arrow-await-in-formals.js(default) | ||
| language/expressions/async-arrow-function/early-errors-arrow-await-in-formals.js(strict mode) |
There was a problem hiding this comment.
interesting.. didn't know so much test were whitelisted. 🤔
| // } | ||
| // | ||
| if (this.isAwaitAllowed() || oldMaybeInArrowParameters) { | ||
| this.state.awaitPos = oldAwaitPos || this.state.awaitPos; |
There was a problem hiding this comment.
Yeah, it's the default value.
There was a problem hiding this comment.
If topLevelAwait is enabled, await could appear at pos 0. It is a bit confusing if we use oldAwaitPos = 0 to represent we haven't met await yet.
There was a problem hiding this comment.
Oh right, Will update it to use -1
There was a problem hiding this comment.
I have also changed it for yieldPos for consistency, even if it's not strictly necessary.
| this.state.yieldPos = oldYieldPos || this.state.yieldPos; | ||
| this.state.awaitPos = oldAwaitPos || this.state.awaitPos; | ||
| // | ||
| // Hi developer of the future :) If you are implementing generator |
| // an async function: | ||
| // | ||
| // async function a() { | ||
| // function b(param = async (await)) { |
| @@ -0,0 +1 @@ | |||
| async (a = ({ await }) => {}) => {}; | |||
There was a problem hiding this comment.
I actually would have read this as a ReferenceError at first but after paying closer attention the early error makes sense 🤔
Follow up to #7727