-
Notifications
You must be signed in to change notification settings - Fork 645
Add @implements/@extends
tags
#1111
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
Add @implements/@extends
tags
#1111
Conversation
Code basically all written by AI, then cut down to size by me.
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.
Pull Request Overview
This PR enhances the parser to reparse and apply JSDoc @implements
and @augments
tags to class heritage clauses.
- Handle
@implements
tags by creating or appending toimplements
clauses on classes. - Handle
@augments
tags by updating type arguments on existingextends
clauses when names match. - Introduce
hasSamePropertyAccessName
helper to compare nested property access names.
Comments suppressed due to low confidence (1)
internal/parser/reparser.go:211
- There are no tests covering the new @implements reparse logic, including creating new and appending to existing implements clauses. Consider adding unit tests to verify both scenarios.
case ast.KindJSDocImplementsTag:
internal/parser/reparser.go
Outdated
} else if parent.Kind == ast.KindClassExpression { | ||
class = parent.AsClassExpression().ClassLikeData() | ||
} | ||
if class != nil && class.HeritageClauses != nil { |
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.
The @Augments handler skips classes with no existing HeritageClauses, so it won't add an extends clause when none is present. Consider adding logic similar to the @implements case to create a new HeritageClause when one doesn't exist.
Copilot uses AI. Check for mistakes.
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.
wow, same comment as when I was working with copilot to write this code, huh?
Maybe Ii should try adding those grammar checks in this PR after all.
internal/parser/reparser.go
Outdated
if parent.Kind == ast.KindClassDeclaration { | ||
class = parent.AsClassDeclaration().ClassLikeData() | ||
} else if parent.Kind == ast.KindClassExpression { | ||
class = parent.AsClassExpression().ClassLikeData() | ||
} |
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.
[nitpick] The logic to extract the ClassLikeBase from the parent node is duplicated in both the @implements and @Augments handlers. Extract this into a helper function to reduce duplication and improve readability.
if parent.Kind == ast.KindClassDeclaration { | |
class = parent.AsClassDeclaration().ClassLikeData() | |
} else if parent.Kind == ast.KindClassExpression { | |
class = parent.AsClassExpression().ClassLikeData() | |
} | |
class = getClassLikeBase(parent) |
Copilot uses AI. Check for mistakes.
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.
that's the first refactoring suggestion that I have liked. done.
Also address PR comments. Oops.
return | ||
} | ||
} | ||
types := p.nodeSlicePool.NewSlice(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.
At some point it'd be good to pull this "new slice size 1 then assign" pattern into a helper, given we do it a lot. I definitely had this on an old branch but I guess never sent it.
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.
where should it go? I have a followup PR for this one that I can add it to. Maybe core?
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.
Followup, it'd just be a method like NewSingleElementSlice(v T)
or something
+ | ||
+ /** | ||
+ * @template T | ||
+ * @typedef {import('./interface').Encoder<T>} IEncoder |
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.
Hm, wonder why this doesn't work.
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.
no EOF token=no jsdoc parsed on EOF token (we might have an EOF token by now, I need to go check)
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.
we do parse it but dont save it. I could add it to the tree or maybe move its jsdoc up to the sourcefile (but thats kind of hacky)
No description provided.