inspect-js / inspect-js/is-arrow-function

False negative for arrow function with closing parenthesis in parameter list

Open
#15 6 comments 0 reactions 0 assignees View on GitHub
Dominant language
JavaScript
Stars
24
Forks
4
PR merge metrics
No merged PRs in 30d

Description

For instance, if a default parameter value uses a function:
```js
const isArrow = require("is-arrow-function");
const arrow = (a = Math.random(10)) => {};
console.log(isArrow(arrow)); // false, should be true
```

There are lots of ways to include a `)` in the parameter list. For instance, `(a, b = (a)) => {}` (but who would write that? ... you know someone would :-) ).

Sadly, I think the only way to deal with this would be to fire up a full parser, since a default can be anything, including a function definition with arbitrary code in it:
```js
const isArrow = require("is-arrow-function");
const arrow = (a = function() {
if (Math.random() < 0.5) {
return 42;
}
return "something else";
}) => a();
console.log(isArrow(arrow)); // false, should be true
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.