Skip to content

False negative for arrow function with closing parenthesis in parameter list #15

Open
@tjcrowder

Description

@tjcrowder

For instance, if a default parameter value uses a function:

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:

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions