Repository navigation
Resolve JSDoc '#' links to instance members - #65580
Closed
5 (tydavid5) wants to merge 1 commit into
Closed
5 (tydavid5) wants to merge 1 commit into
5 (tydavid5) wants to merge 1 commit into
Conversation
Fixes microsoft#65507 In TypeScript 6, a JSDoc link written as Foo#member resolved to the instance member, while Foo.member resolved to the static member. The Go port lost that distinction: its parser turns both separators into the same QualifiedName, so the checker resolved both links through the static members first. The parser now records a '#' separator with a node flag, and the checker treats a flagged name as an instance member reference, looking it up on the class prototype instead of resolving it as an entity name. Dot links, plain links, and links on interfaces are unchanged, and a '#' link on a namespace still resolves to nothing, as it did in TypeScript 6, since namespaces have no declared type to look the member up on. Tests: a new compiler test case covers the reported code, and new checker tests assert the resolved symbol for the reported case plus instance-only, static-only, interface, method, missing member, plain link, namespace, see tag, namespace-qualified, and chained '#' cases. The new tests fail with the fix reverted and pass with it.
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
JSDoc member resolution remains API-call-order dependent because cached static symbols bypass the guard, and the new flag is missing from generated API enums.
2 open issues
What changed in this PR
This PR addresses #65507 by distinguishing JSDoc Foo#member links from Foo.member, restoring instance-member resolution in the Go compiler.
Changes:
- Add an AST flag and helper to preserve
#separators during parsing. - Route flagged links through instance-member resolution in the checker.
- Add checker regression tests and a conformance case with baselines.
| File | Description |
|---|---|
tsc/testdata/tests/cases/conformance/jsdoc/jsdocLinkTag10.ts |
Adds the reported static-versus-instance example. |
tsc/testdata/baselines/reference/conformance/jsdocLinkTag10.types |
Records expected types. |
tsc/testdata/baselines/reference/conformance/jsdocLinkTag10.symbols |
Records declaration symbols. |
tsc/testdata/baselines/reference/conformance/jsdocLinkTag10.js |
Records JavaScript output. |
tsc/internal/parser/jsdoc.go |
Marks names parsed with #. |
tsc/internal/checker/checker.go |
Adds instance-member resolution for flagged links. |
tsc/internal/checker/checker_test.go |
Tests link targets and edge cases. |
tsc/internal/ast/utilities.go |
Adds the flagged-name predicate. |
tsc/internal/ast/nodeflags.go |
Defines the JSDoc member-name flag. |
Review effort: Balanced
Comment on lines
+32841
to
+32842
| if !(isJSDoc && ast.IsJSDocMemberName(name)) { | ||
| c.checkQualifiedName(name, CheckModeNormal) |
| NodeFlagsPossiblyContainsDeprecatedTag NodeFlags = 1 << 26 // Set during parse if comment text contains '@deprecated'; must confirm via JSDoc lookup | ||
| NodeFlagsUnreachable NodeFlags = 1 << 27 // If node is unreachable according to the binder | ||
| NodeFlagsReparserTransformedLiteral NodeFlags = 1 << 28 // If node was transformed during parsing, making its' naive text source not match the AST | ||
| NodeFlagsJSDocMemberName NodeFlags = 1 << 29 // If a QualifiedName was parsed from a JSDoc link name using the '#' separator (Foo#member), marking it as an instance member reference rather than a static member reference |
Member
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.


Fixes #65507
In TypeScript 6, a JSDoc link written as Foo#member resolved to the instance member, while Foo.member resolved to the static member. The Go port lost that distinction: its parser turns both separators into the same QualifiedName, so the checker resolved both links through the static members first. The parser now records a '#' separator with a node flag, and the checker treats a flagged name as an instance member reference, looking it up on the class prototype instead of resolving it as an entity name. Dot links, plain links, and links on interfaces are unchanged, and a '#' link on a namespace still resolves to nothing, as it did in TypeScript 6, since namespaces have no declared type to look the member up on.
Tests: a new compiler test case covers the reported code, and new checker tests assert the resolved symbol for the reported case plus instance-only, static-only, interface, method, missing member, plain link, namespace, see tag, namespace-qualified, and chained '#' cases. The new tests fail with the fix reverted and pass with it.