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?
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?