[Bug]: incorrectly rejects `await` when following a function with an arrow in default parameters
See original GitHub issue💻
- Would you like to work on a fix?
How are you using Babel?
Programmatic API (babel.transform
, babel.parse
)
Input code
(async function () {
function f(_=()=>null) {}
await null;
});
or
(function* () {
function f(_=()=>null) {}
yield;
});
Configuration file name
package.json
Configuration
No response
Current and expected behavior
These are both valid programs but are rejected with
SyntaxError: ‘await’ is not allowed in async function parameters.
and
Yield expression is not allowed in formal parameters.
respectively
Environment
This is with @babel/parser: 7.15.8
Possible solution
No response
Additional context
I found this with a fuzzer, not in real code, so prioritize accordingly. That said, these do actually seem more plausible than many fuzzer-derived bugs.
Issue Analytics
- State:
- Created 2 years ago
- Comments:13 (10 by maintainers)
Top Results From Across the Web
eslint - async arrow function return value error - Stack Overflow
and eslint(consistent-return) is telling me: Async arrow function expected no return value. but then I am getting eslint's: Expected to return ...
Read more >Async/Await Error Handling - Beginner JavaScript - Wes Bos
We will talk about error handling strategies for async await in this lesson. ... new Promise(function (resolve, reject) { // reject if people...
Read more >SyntaxError: Malformed formal parameter - JavaScript | MDN
The JavaScript exception "malformed formal parameter" occurs when the argument list of a Function() constructor call is invalid somehow.
Read more >5. Async functions - Exploring JS
async function asyncFunc () { throw new Error ( 'Problem! ... If the Promise is rejected, await throws the rejection value. Handling a...
Read more >Assert | Node.js v19.3.0 Documentation
If asyncFn is a function and it throws an error synchronously, assert.doesNotReject() will return a rejected Promise with that error. If the function...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@azeez1776 I’m currently working on this give me some time please, If I won’t be able to take it forward I’ll let you know.
@The-x-Theorist If it is the first time you contribute to Babel, see Nicolò’s comment above on setting up the project.
This issue is on babel parser. If you are not familiar with the topic, which is absolutely okay, you can start by trying out https://astexplorer.net/ (Select JavaScript then
@babel/parser
) or reading tutorials about parsing and AST.If you already had some experience on developing a parser, you can start by https://github.com/babel/babel/blob/fb7ddf4d389d3c9eff52567080f54995ba182031/packages/babel-parser/src/parser/expression.js#L2304 and scrutinize how
ExpressionScope
is handled when Babel is parsing arrow expression – because the OP’s error is thrown when an ExpressionScope is validated. For the definition of Expression Scope, see here.For more questions, you can ask team members on Slack.