Fails when a default is on last parameter of function
mattdawson opened this issue · 1 comments
mattdawson commented
function (a,b,c=1) {
.. code here ...
}
returns a,b, ...first line of code...
This is because the following regexp doesn't end on a bracket....
const DEFAULT_PARAMS = /=[^,]+/mg;
Changing it to: /=[^,)]+/ fixes this.
(Note, this won't capture funky defaults which contain commas, or brackets)
Also maybe consider changing:
var code = fn.toString()
to
const code = fn.prototype.constructor.toString()
This will prevent the whole function being converted to string.
Unless this is for parsing functions that are already strings?
CaptEmulation commented
This is fixed in @captemulation/get-parameter-names
which is a re-write of this library. See https://github.com/CaptEmulation/get-parameter-names