A small collection of AST transformations to refactor typescript code. All transformations are driven by individual needs and are by no means a fully working and supported migration tool. There is no plan to provide a command line runner or to publish the transformers as npm package. To use it checkout the code, run it and make adjustments as you need them. If they are useful too other, open a PR.
This blog post gives a bunch of drawbacks when using default exports. Replacing default exports is a two-step process:
- Replace the default export in the declaring module with a named export
- Update all depending on modules that do a default export to use the new named export
- support for
.tsx
files
To me copyright headers at the top of a file are noise and distraction. If you are allowed to remove them, this should help.
- Implement it
- Implement it
- https://github.com/elliottsj/jscodeshift-typescript-example Contains an example on how to test the code mode in an end-to-end fashion
- https://www.toptal.com/javascript/write-code-to-rewrite-your-code tutorial with exercises
- https://github.com/5to6/5to6-codemod/blob/master/transforms/named-export-generation.js
- https://augustinlf.com/writing-codemods-to-transform-your-codebase/
- https://github.com/cpojer/js-codemod
- https://github.com/awslabs/aws-sdk-js-codemod/tree/main/src/transforms/v2-to-v3
- https://github.com/WolkSoftware/tsmod (abstraction on top of ts.morph)
- only replace default imports if the source is in the project
- https://developer.mozilla.org/en-US/docs/Mozilla/Projects/SpiderMonkey/Parser_API
- https://github.com/facebook/jscodeshift
- https://github.com/benjamn/recast
- https://github.com/benjamn/ast-types
- ast-types wraps every AST node into a path object
- paths contain meta-information and helper methods to process AST nodes
- defines a couple of builder methods, to make creating AST nodes a bit simpler and "safer"
To get a typescript AST like you get with jscodeshift
- change from
acorn
to@babel/parser
- click ⚙️ to open the
@babel/parser
settings - uncheck
flow
- check
typescript
- what is the difference between path.node and path.value?