Restore JSDoc namespace declarations#4073
Open
ahejlsberg wants to merge 10 commits into
Open
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
Completes restoration of JSDoc dotted-name (NS.T) @typedef and @callback support. The parser now produces a JSDocFullName (Identifier | nested ModuleDeclaration) for the names of @typedef/@callback, and the reparser wraps the resulting type alias in a chain of (exported) namespace declarations so that names like NS.MyCallback resolve and participate in declaration emit, find-all-refs, rename, etc.
Changes:
- New
parseJSDocTypeNameWithNamespaceproduces a nestedModuleDeclarationchain for dotted@typedef/@callbacknames;JSDocCallbackTag.FullNameis renamed tonameand typed asJSDocFullName. - Reparser wraps reparsed type aliases in synthetic namespace
ModuleDeclarations (wrapInJSDocNamespace), with inner namespaces explicitly exported and the outer one relying onIsImplicitlyExportedJSDocDeclaration(renamed fromIsImplicitlyExportedJSTypeAlias) for module visibility. EmitResolver.determineIfDeclarationIsVisiblenow handlesKindExportSpecifier(re-export without module specifier) as visible;someSymbolTableInScopelooks up reparsed nodes;declareSourceFileMembernarrows fromIsExternalOrCommonJSModuletoIsExternalModule; CHANGES.md drops the JSDoc-namespace limitation; many submodule baselines updated.
Reviewed changes
Copilot reviewed 55 out of 58 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| internal/parser/jsdoc.go | Parse JSDoc dotted name into nested ModuleDeclaration. |
| internal/parser/reparser.go | Wrap reparsed type alias in namespace chain; export-modifier helper. |
| internal/ast/utilities.go | Rename helper to IsImplicitlyExportedJSDocDeclaration, include reparsed ModuleDeclaration. |
| internal/ast/nodeflags.go | Add NodeFlagsIdentifierIsInJSDocNamespace, NodeFlagsNestedNamespace. |
| internal/ast/ast.go | TypeExpression() now handles JSDocCallbackTag. |
| internal/ast/ast_generated.go | JSDocCallbackTag.FullName → private name *JSDocFullName; JSDocTypedefTag.name retyped. |
| internal/binder/binder.go | Use renamed helper; declareSourceFileMember uses IsExternalModule. |
| internal/checker/symbolaccessibility.go | Resolve via GetReparsedNodeForNode in scope traversal. |
| internal/checker/emitresolver.go | Treat ExportSpecifier re-exports as visible; use new helper. |
| internal/transformers/declarations/transform.go | Use renamed helper for export modifier. |
| internal/ls/importTracker.go | Use renamed helper. |
| internal/api/encoder/* | Regenerated for renamed field. |
| _packages/native-preview/src/... | Regenerated TS bindings for JSDocFullName/renamed field. |
| _scripts/ast.json | AST schema updates. |
| CHANGES.md | Remove JSDoc-namespace limitation note. |
| testdata/tests/cases/compiler/jsDocTypedefTagNamespace.ts | New compiler test. |
| testdata/baselines/reference/... | Updated baselines / removed obsolete diffs. |
| testdata/submoduleAccepted.txt | Drop now-converged callbackTagNamespace.types.diff. |
Files not reviewed (3)
- internal/api/encoder/decoder_generated.go: Language not supported
- internal/api/encoder/encoder_generated.go: Language not supported
- internal/ast/ast_generated.go: Language not supported
| if fullName == nil || !ast.IsModuleDeclaration(fullName) { | ||
| return statement | ||
| } | ||
| // Recursively wrap from outermost to innerpost. Inner namespaces always get an export modifier |
| } | ||
| // Recursively wrap from outermost to innerpost. Inner namespaces always get an export modifier | ||
| // so members are accessible via dotted access from outside. The outermost namespace is treated as | ||
| // exported only in module files via IsImplicitlyExportedJSTypeAlias (in the binder), so it does |
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.
This PR completes work that was started by @jakebailey. Specifically, it simplifies a few functions and adds proper remapping of reparsed nodes such that Quick Info, Find-all-refs, Rename, etc. on namespaced JSDoc names work in the language service.
Fixes #3842.