is-arrow-function
is-arrow-function copied to clipboard
More robust logic for various edge cases
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-callabledependency is no longer needed, as "callable" strictly means functions plus the single special case ofdocument.all.typeof document.allisn'tfunctionso it returnsfalseanyway.- Checking is now significantly more robust, e.g. lots of cases with misleading
=>orfunction. - All the old tests are retained, but rewritten somewhat.
- I inlined the
make-arrow-function,make-async-function, andmake-generator-functiontest 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.
Removed dependencies detected. Learn more about Socket for GitHub ↗︎
🚮 Removed packages: npm/[email protected], npm/[email protected], npm/[email protected]
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.
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.
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.