goatslacker / get-parameter-names

Retrieves the argument names of a function
46 stars 13 forks source link

Fails with variable definitions #6

Open maxgherman opened 8 years ago

maxgherman commented 8 years ago

Input:

c => { let test2 = c.resolve(); return new Test3(test2); } Expected output:

['c']

Output:

[ 'c', 'let', 'test2' ]

Input:

c => { var test2 = c.resolve(); return new Test3(test2); } Expected output:

['c']

Output:

[ 'c', 'var', 'test2' ]

$ node -v v4.2.1

jfromaniello commented 8 years ago

I think the problem is when you use a fat-arrow function with 1 argument and the argument is not defined with parenthesis.

benbotto commented 8 years ago

Use my scoped package: https://www.npmjs.com/package/@avejidah/get-parameter-names There are other issues that are fixed there as well.

troywweber7 commented 7 years ago

With function definition:

function test(arg1=3, /*arg2,*/ arg3='duh') { console.log(arguments); }

getParameterNames(test) returns ["arg1", "arg"].

Here is another test:

function test(arg1=3, /*arg2,*/ arg345='duh') { console.log(arguments); }

getParameterNames(test) returns ["arg1", "arg34"].

It seems that it works really well EXCEPT for the very last argument, on which it strips the last character for some reason. Hope this helps. Oh, and the tests were run in the chrome browser console window.

benbotto commented 7 years ago

@troywweber7 These tests pass correctly in my fork, and my fork has a number of other issues corrected. Use my scoped module, as described in my comment above (npm install @avejidah/get-parameter-names).