Add codemod to propagate JSDoc comments to dual signatures #3697
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.
Type
Description
Problem Statement
At the moment, JSDoc annotations are lost the second that a user actually calls a method from the library.
When just inspecting methods as variables, you see the JSDoc on hover:
But the second you call the method, the JSDoc disappears:
This is because the JSDoc trivia is associated with the parent variable declaration but they are not propagated to the inner call expression nodes.
Solution
This PR introduces a codemod which will traverse public package entrypoints and attempt to propagate JSDoc comments from the root of an export declaration into the dual call signatures.
Effectively this:
becomes this:
NOTE: if the node already contains comments, the codemod will NOT override them.
The codemod is only run in CI to avoid polluting the codebase with unnecessary JSDocs.
In addition, it is run before the build step to ensure that the build output will contain the JSDoc trivia that was added by the codemod.
Related