-
Notifications
You must be signed in to change notification settings - Fork 505
Node -> Tokens navigation, token list navigation #551
Conversation
|
/cc @mikesherov @markelog |
|
@mikesherov Can you take a look please, so I can continue to work on 2.0? |
|
as discussed, i would add tests for new methods, we probably could start using some coverage tool for it too :-) |
|
Agreed with @markelog, if we're going to land these new methods, tests and an actual implementation in at least one rule would be nice. Other than that I have a few comments I'll leave. |
lib/js-file.js
Outdated
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.
findPrevToken
That is the idea |
d8dcd44 to
55e2a45
Compare
|
|
👍 from me. This looks good to land for 2.0 |
|
Same here |
55e2a45 to
ba562c4
Compare
|
I wonder if we can merge this to master branch, it seems we could already start using it |
|
Well, we can. |
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.
So if that returns undefined, than customer of that method should check for it before using? So i can't just do if (getTokenByRangeStart(...).value === '['), i would need to do something like this:
var token = getTokenByRangeStart(...);
if (token && token.value === "["){
...
}Maybe, for convenience sake, it could return some fake token instead of undefined, like
{
type: '',
value: '',
range: [ -1, -1 ],
loc: { start: { line: -1, column: -0 }, end: { line: -1, column: -1 } },
_tokenIndex: -1
}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.
type: 'fake' :-) agreed with fake token, but probably we should be more concrete on this.
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.
This token isn't there, so it's not really fake, such situations might exist if current token is first or last token in the tree
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.
For now I'm not sure there can be situation with no token (if you pass real node range).
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.
@mdevils that is mostly for the getNextToken/getPrevToken, here, just for the consistency
|
Also, how about Has a downside, since it will reflect on performance. |
This is a the start of 2.x work. We can significantly simplify new rules using this kind of navigation.