goatslacker / goatslacker/get-parameter-names
Fails when a default is on last parameter of function
Open
- Dominant language
- JavaScript
- Stars
- 45
- Forks
- 12
- PR merge metrics
- No merged PRs in 30d
Description
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?
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.