Skip to content
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

Add support for beforeDeclarations #58880

Open
6 tasks done
Danielku15 opened this issue Jun 16, 2024 · 1 comment Β· May be fixed by #58879
Open
6 tasks done

Add support for beforeDeclarations #58880

Danielku15 opened this issue Jun 16, 2024 · 1 comment Β· May be fixed by #58879
Labels
Awaiting More Feedback This means we'd like to hear from more people who would be helped by this feature Suggestion An idea for TypeScript

Comments

@Danielku15
Copy link

πŸ” Search Terms

beforeDeclarations declaration transform transformers afterDeclarations

βœ… Viability Checklist

⭐ Suggestion

The TypeScript compiler API already supports custom transformers in 3 ways:

  1. Before built-in .js transformations
  2. After built-in .js transformations
  3. After built-in .d.ts transformations

But the API is missing a "Before built-in .d.ts transformations" variant.

πŸ“ƒ Motivating Example

To generate type declarations more dynamically, you often need to access AST nodes of your codebase as it is written. The built-in transformers erase already a lot of the AST making this information unavailable. With the help of this new beforeDeclarations you are able to access your full AST and use it to auto-generate your typescript declaration files.

πŸ’» Use Cases

  1. Use information from property initializers to include "default values" your JSDoc comments. (see Preserve property comment and insert @default value, if providedΒ #41486).
  2. Remove declarations using information like visibility modifiers or used functions in your code to not expose implementation details.
@RyanCavanaugh RyanCavanaugh added Suggestion An idea for TypeScript Awaiting More Feedback This means we'd like to hear from more people who would be helped by this feature labels Jun 17, 2024
@Danielku15
Copy link
Author

Danielku15 commented Jun 23, 2024

Referencing some more related issues where a beforeDeclaration hooks would have a benefit:

The afterDeclarations was added in

And another problem:

  • On the afterDeclarations there seems something broken on the AST. parent is unset for ts.PropertyDeclaration nodes and both ts.getJSDocCommentsAndTags and ts.getSyntheticLeadingComments return nothing. The built-in transforms seem to break things using 5.5.2. (see here).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Awaiting More Feedback This means we'd like to hear from more people who would be helped by this feature Suggestion An idea for TypeScript
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants