get-parameter-names icon indicating copy to clipboard operation
get-parameter-names copied to clipboard

Fails when a default is on last parameter of function

Open mattdawson opened this issue 7 years ago • 1 comments

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?

mattdawson avatar May 29 '17 01:05 mattdawson

This is fixed in @captemulation/get-parameter-names which is a re-write of this library. See https://github.com/CaptEmulation/get-parameter-names

CaptEmulation avatar Jun 17 '17 03:06 CaptEmulation