-
Notifications
You must be signed in to change notification settings - Fork 591
post CommonJS PR cleanup #824
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
Conversation
1. Move tag reparsing from jsdoc.go to reparser.go 2. Improve a couple of names in the binder and reparser. 3. Restore mistakenly deleted contextual type for export=.
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 cleans up CommonJS-related code with several refactorings that improve tag reparsing, naming consistency, and type resolution. Key changes include:
- Moving tag reparsing from jsdoc.go to reparser.go and updating related function calls.
- Improving naming conventions in binder and reparser by renaming functions such as bindJSDoc to setJSDocParents.
- Restoring the contextual type for export= and removing obsolete TODO comments in nameresolver.
Reviewed Changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated no comments.
Show a summary per file
File | Description |
---|---|
internal/parser/reparser.go | Introduces reparseTags for improved tag reparsing and type alias handling. |
internal/parser/jsdoc.go | Calls reparseTags instead of the removed attachTagsToHost function. |
internal/checker/checker.go | Adds a case for ExportAssignment to improve contextual type resolution. |
internal/binder/nameresolver.go | Removes an outdated TODO comment to clean up the code. |
internal/binder/binder.go | Renames bindJSDoc to setJSDocParents for better clarity regarding jsdoc handling. |
Comments suppressed due to low confidence (5)
internal/binder/binder.go:746
- [nitpick] The renaming from bindJSDoc to setJSDocParents improves clarity; ensure that related documentation is updated to reflect the new naming convention.
b.setJSDocParents(node)
internal/binder/nameresolver.go:307
- [nitpick] The removal of the TODO comment clarifies the code; consider ensuring that any outstanding refactoring plans are tracked elsewhere.
// TODO: Move this to the next == nil block, or move the other up.
internal/parser/reparser.go:112
- [nitpick] The panic message is explicit, but consider whether a more graceful error handling strategy might improve the developer experience during type reparsing.
panic("typedef tag type expression should be a name reference or a type expression" + typeExpression.Kind.String())
internal/parser/jsdoc.go:60
- [nitpick] Replacing attachTagsToHost with reparseTags streamlines tag processing; please verify that all intended side effects are preserved in the new approach.
p.reparseTags(node, jsdoc)
internal/checker/checker.go:27161
- Adding handling for ExportAssignment in getContextualType improves type resolution; please ensure that tryGetTypeFromTypeNode returns the expected type in all cases.
case ast.KindExportAssignment:
@@ -27158,6 +27158,8 @@ func (c *Checker) getContextualType(node *ast.Node, contextFlags ContextFlags) * | |||
return c.getContextualType(parent, contextFlags) | |||
case ast.KindSatisfiesExpression: | |||
return c.getTypeFromTypeNode(parent.AsSatisfiesExpression().Type) | |||
case ast.KindExportAssignment: | |||
return c.tryGetTypeFromTypeNode(parent) |
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 test change?
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.
Nope!
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.
My theory, which I haven't confirmed: in Strada, this code was added by analogy with
/** @type {X} */
exports.x = (x,y,z) => { }
(which is currently broken in Corsa, it's on my list to fix)
But it does nothing because there's no type annotation on export=
.
I tried addressing the TODO and it makes the result more correct but less useful: when a globally declared
module
orexports
overrides the fallback we provide, andexports: { [s: string]: any }
(which I believe is the node definition),exports.x: any
when referred to inside the exporting file. Pro: goto-def works onexports
. Con:exports.x
loses type information it could have had.I considered moving
require
up above the global resolution, but it's not useful to have a good type forrequire
and I'd like to keep goto-def going to types/node if present.