Skip to content

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

Merged
merged 3 commits into from
Jun 10, 2025

Conversation

sandersn
Copy link
Member

@sandersn sandersn commented Jun 9, 2025

No description provided.

sandersn added 2 commits June 9, 2025 09:31
Code basically all written by AI, then cut down to size by me.
@Copilot Copilot AI review requested due to automatic review settings June 9, 2025 21:21
Copy link
Contributor

@Copilot Copilot AI left a 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 to implements clauses on classes.
  • Handle @augments tags by updating type arguments on existing extends 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:

} else if parent.Kind == ast.KindClassExpression {
class = parent.AsClassExpression().ClassLikeData()
}
if class != nil && class.HeritageClauses != nil {
Copy link
Preview

Copilot AI Jun 9, 2025

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.

Copy link
Member Author

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.

Comment on lines 213 to 217
if parent.Kind == ast.KindClassDeclaration {
class = parent.AsClassDeclaration().ClassLikeData()
} else if parent.Kind == ast.KindClassExpression {
class = parent.AsClassExpression().ClassLikeData()
}
Copy link
Preview

Copilot AI Jun 9, 2025

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.

Suggested change
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.

Copy link
Member Author

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.

return
}
}
types := p.nodeSlicePool.NewSlice(1)
Copy link
Member

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.

Copy link
Member Author

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?

Copy link
Member

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
Copy link
Member

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.

Copy link
Member Author

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)

Copy link
Member Author

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)

@sandersn sandersn added this pull request to the merge queue Jun 10, 2025
Merged via the queue into microsoft:main with commit c202a92 Jun 10, 2025
23 checks passed
@sandersn sandersn deleted the add-implements-extends-tags branch June 10, 2025 18:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants