is-arrow-function icon indicating copy to clipboard operation
is-arrow-function copied to clipboard

More robust logic for various edge cases

Open lionel-rowe opened this issue 1 year ago • 4 comments

Fixes https://github.com/inspect-js/is-arrow-function/issues/26 Fixes https://github.com/inspect-js/is-arrow-function/issues/15

Started out with some tweaks but turned into a rewrite.

  • is-callable dependency is no longer needed, as "callable" strictly means functions plus the single special case of document.all. typeof document.all isn't function so it returns false anyway.
  • Checking is now significantly more robust, e.g. lots of cases with misleading => or function.
  • All the old tests are retained, but rewritten somewhat.
  • I inlined the make-arrow-function, make-async-function, and make-generator-function test deps.
  • Added new test groups, e.g. one each for the 2 GitHub issues, plus async generator functions, object properties, object methods, classes, and various combinations.

lionel-rowe avatar May 09 '24 10:05 lionel-rowe

Removed dependencies detected. Learn more about Socket for GitHub ↗︎

🚮 Removed packages: npm/[email protected], npm/[email protected], npm/[email protected]

View full report↗︎

socket-security[bot] avatar May 09 '24 10:05 socket-security[bot]

as "callable" strictly means functions plus the single special case

this is incorrect; there’s older engines in which regexes are callable.

inlined

why? That makes them not reusable. If the deps need improvement let’s improve them rather than inlining.

ljharb avatar May 09 '24 14:05 ljharb

as "callable" strictly means functions plus the single special case

this is incorrect; there’s older engines in which regexes are callable.

Whoah, that's pretty freaky. Would an instanceof check fix it? Also, what's the purpose of supporting ES3 given that arrow functions can't syntactically exist in ES3 (or ES5 for that matter)?

inlined

why? That makes them not reusable. If the deps need improvement let’s improve them rather than inlining.

It makes the tests hard to follow if they depend on 3 separate external NPM packages that just export variables; even more so given that the exported arrays were being sliced arbitrarily within the test code without explanation.

lionel-rowe avatar May 09 '24 14:05 lionel-rowe

The explanation is in the git log :-) with the full list, the checks fail, and the needed fix is to have the tests pass largely unchanged, with the full list. In this case, the abstraction is worth the readability hit.

instanceof is never reliable for builtins and should be avoided. while certainly in an env that doesn’t have arrow syntax, this predicate will always return false, the predicate may need to run in an env so that code doesn’t need to check syntax support and branch.

ljharb avatar May 09 '24 14:05 ljharb