-
Notifications
You must be signed in to change notification settings - Fork 486
Membership inference improvements #558
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
var memberof = comment.memberof; | ||
var index = memberof.lastIndexOf('.'); | ||
|
||
if (index !== -1 && memberof.slice(index + 1) === 'prototype') { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
could these index-based checks be expressed more simply with regular expressions? I believe this one would be memberof.match(/\.prototype$/)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't know how important performance is to you. It surely would result in more compact code. But the next line would read comment.memberof = memberof.slice(0, -10);
which looks a little bit to much on the magical side for my taste.
I could also use a capturing regexp: memberof.match(/^(.*).prototype$/)
and use match[1] like this:
var match = memberof.match(/^(.*).prototype$/);
if (match !== null) {
comment.memberof = match[1];
I'm not sure if that's an improvement in the end. But if this works for you:
if (memberof.match(/.prototype$/) !== null) {
comment.memberof = memberof.slice(0, -10);
comment.scope = 'instance';
return comment;
}
I am totally on board.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probably the most compact way to express this would be:
var isPrototype = /.prototype$/;
if (memberof.match(isPrototype)) {
comment.memberof = memberof.replace(isPrototype, '');
comment.scope = 'instance';
return comment;
}
Performance certainly matters, but with tiny strings in this place I don't think even a wasteful implementation could take more than 1% of total time.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
|
||
var last = memberof.length - 1; | ||
|
||
if (memberof[last] === '#') { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
and this check would be memberof.match(/#$/)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
and this is also done.
👍 Thanks Christoph! |
|
Added normalization of
@memberof Foo#
and@memberof Foo.prototype
Added membership inference for
this.foo
inside constructor functions and class members