-
-
Notifications
You must be signed in to change notification settings - Fork 14
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
feat!: Add getLoc/getRange to SourceCode interface #89
Conversation
* Represents a location coordinate inside the source. | ||
* Represents the start and end coordinates of a node inside the source with an offset. | ||
*/ | ||
export interface SourceLocationWithOffset { |
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.
Keeping this as it seems like it would still be helpful for developers.
/** | ||
* Represents a location coordinate inside the source with an offset. | ||
*/ | ||
export interface PositionWithOffset extends Position { |
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.
Same here
node: object, | ||
ancestry: Array<object>, |
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.
Using object
instead of Object
to enforce that this cannot be a primitive value.
@@ -222,7 +242,7 @@ export interface File { | |||
/** | |||
* Represents the successful result of parsing a file. | |||
*/ | |||
export interface OkParseResult { | |||
export interface OkParseResult<T extends object = object> { |
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.
Making this generic allows devs to specify the type of the ast
property to get intellisense completions.
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.
LGTM, thanks! Node 22 CI is currently broken so holding off merging until that's fixed.
@mdjermanovic just a reminder: when it looks like a PR is ready to merge, please move to "Merge Candidates" |
This is blocking me currently, so going to merge to get moving again. |
Prerequisites checklist
What is the purpose of this pull request?
Updates the
SourceCode
interface withgetLoc()
andgetRange()
methods.What changes did you make? (Give an overview)
getLoc()
method toSourceCode
interfacegetRange()
method toSourceCode
interfaceSourceRange
interfaceSyntaxElement
type to be a union of several popular AST-location formatsoffset
property toPosition
, as many ASTs support thatRelated Issues
Refs eslint/eslint#18695
Is there anything you'd like reviewers to focus on?
I marked this as breaking as existing implementations of
SourceCode
would now be invalid.Also, I thought that including different formats of
SyntaxElement
would provide the best developer experience. Otherwise, I'd need to setSourceCode.ast
toObject
, so there would effectively be no type checking or intellisense available. I'm not sure if that makes the most sense.