~/talk

Codemods: Refactoring JavaScript using JavaScript

Talkat DinosaurJS 2019 · 2019-06-19..06-20· [javascript, testing]
slides:none on file

Explains how to programmatically refactor JavaScript using js-codeshift and recast, converting patterns like React.createClass to ES2015 classes and turning function expressions into safe arrow functions while avoiding uses of this. Describes parsing to ASTs, writing transformers that return modified source, running codemods across code bases, and safety practices: unit tests, small PRs, and no manual edits. Reports real results: modernizes thousands of files and saves hundreds of developer hours in practice.

AI-written summary · about

  1. 0:00Start
  2. 0:59code-what?
  3. 2:05What does running a codemod look like?
  4. 3:30Codemods unblock complex application-wide refactors.
  5. 4:30What are some possible refactors?
  6. 4:56Refactor React components to unblock upgrades after API changes.
  7. 5:34We'll use jscodeshift to run codemod scripts on our files.
  8. 6:50Recast is a tool for parsing JavaScript, manipulating it, and then returning it.
  9. 7:28Recast generates an abstract syntax tree (AST) by parsing our JavaScript.
  10. 8:04Trees are data structures that consist of nodes that are linked to one another.
  11. 8:29The nodes in an abstract syntax tree describe the structure of our
  12. 10:24Writing Codemods
  13. 10:412. Modify the AST as required • Traverse tree for nodes ⚫ Update the nodes
  14. 20:04Tips
  15. 20:29Have safety nets in place before using codemods.
  16. 20:58Don't make additional changes on codemod refactored branches.
  17. 21:34Split up large refactors into multiple pull requests.
  18. 21:52Write documentation for any codemods, and include them in pull requests.
  19. 22:37Treat any coded scripts written internally as actual code.
~/search
type to search 6,249 conferences, 138,987 speakers and 185,172 talks
~/help
cmdctrl k
search every conference, speaker and series
/
focus the filter search
h
home
c
conferences
s
speakers
e
series
t
light / dark — the status bar button does the same
?
this help
esc
close this, then clear every filter — or just the search, while you are typing in it

Ignored while you are typing. Pages without a filter rail have no search to focus.