question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[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:closed
  • Created 2 years ago
  • Comments:13 (10 by maintainers)

github_iconTop GitHub Comments

2reactions
The-x-Theoristcommented, Nov 2, 2021

@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.

2reactions
JLHwungcommented, Oct 26, 2021

@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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found