-
-
Notifications
You must be signed in to change notification settings - Fork 26
feat: add support for getLocFromIndex
and getIndexFromLoc
#212
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
base: main
Are you sure you want to change the base?
feat: add support for getLocFromIndex
and getIndexFromLoc
#212
Conversation
…c' of https://github.com/eslint/rewrite into feat-add-support-for-getlocfromindex-and-getindexfromloc
this.#columnStart = columnStart; | ||
|
||
let match; | ||
while ((match = lineEndingPattern.exec(text))) { |
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 think we should do this lazily. It doesn't make sense to go through this process until we know someone needs this information.
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.
Thanks for taking a look at this. I left some comments throughout.
Overall, I'd like to think more about how to lazily generate the data needed. For instance, if someone calls getLocFromIndex(5)
, we should only generate the line endings up to index 5. If someone then calls getLocFromIndex(22)
, we can go on to generate line endings up to index 22.
That way, we're saving calculations until we really need them.
Prerequisites checklist
What is the purpose of this pull request?
Hello,
In this PR, I've completed implemention of
getLocFromIndex()
andgetIndexFromLoc()
.I based the implementation on the current JavaScript
SourceCode
class and incorporated the fast lookup algorithm discussed in eslint/eslint#19782.The logic of
getLocFromIndex()
andgetIndexFromLoc()
is nearly identical to that in the JavaScriptSourceCode
class, with the key difference being that it accounts for thelineStart
andcolumnStart
values initialized in the constructor.lineStart
andcolumnStart
TextSourceCodeBase
should acceptlineStart
andcolumnStart
, as these can vary depending on the language, and bothgetLocFromIndex()
andgetIndexFromLoc()
rely on them for accurate calculations. Here are some examples:What changes did you make? (Give an overview)
I've completed implemention of
getLocFromIndex()
andgetIndexFromLoc()
.Related Issues
fixes: #166
refs: eslint/markdown#376, eslint/css#167, eslint/json#109, eslint/eslint#19782
Is there anything you'd like reviewers to focus on?
Prerequisites
getLocFromIndex
eslint#19782