-
-
Notifications
You must be signed in to change notification settings - Fork 6
Class methods #15
Comments
Hey, very thanks! I'll look into it, I think we just should look more on acorn ast. |
I'm starting to think it may be acorn.parse(EqualityChecker.prototype.isEqual.toString(), {ecmaVersion: 7}) throws a syntax error. Or maybe this is the reason why |
There are few ways:
Second feels kinda wrong to me and I'm thinking it would mess the things more than it solve them. |
What you think about the fix? edit: Ooops, labels should stay. |
As much as I am bewildered by the choice of substring check mechanism ([0] and [1] - I assume it's for performance reasons), this is exactly the workaround that I did in my code: let functionString = methodFunction.toString();
if (functionString.slice(0, 8) !== 'function') {
functionString = 'function ' + functionString;
} I agree that it is the sane thing to do. Checking for function calls is probably best left alone - there is another npm module for that (extracts call parameters), and it may be wise not to expand into that field. |
Yea.
You can try http://npm.im/function-arguments, it works for regular, generator and arrow functions. If you need support only for regular functions can use Sindre's It would be better choice to use one of them if you only need getting arguments. |
Oh sorry, i forget to publish. I doing it now :) |
Parsing class methods seems to yield empty bodies, anonymous names and empty arg lists.
Example:
Both console.logs will print
{ name: 'anonymous', args: [], params: '', body: '' }
.I suspect it is because
.toString()
on methods returns the exact representation from the code, from the first to the last token, so in our case (tabs originally in the string):The same problem occurs with this compacted ES6 "function-less" notation:
The text was updated successfully, but these errors were encountered: