Computer, refactor my code!
summary
Demonstrates writing codemods that parse JavaScript into an AST, traverse and transform nodes, then regenerate code; one example runs over 300 automated edits in a real codebase and another rewrites a chained SDK API across ~30 apps into single-object calls. Uses jscodeshift, built on recast, and debugs transforms with AST Explorer. Typical nontrivial transform takes a few hours to reach 90% correctness; replacements are deterministic and preserve nested function arguments.
AI-written summary · about
chapters (11)
- 0:00Introduction to code refactoring
- 3:03Case study and motivation
- 9:59Understanding AST basics
- 15:24Introducing code mods
- 17:33Tools for AST traversal
- 22:57Building your first transform
- 24:47Demo: Simple identifier replacement
- 28:05Demo: Targeted node replacement
- 33:47Demo: Complex AST construction
- 39:18Summary and encouragement
- 40:02Q&A session
related talks
40mRefactoring large JavaScript codebases
43mMachine Powered Refactoring: Leverage AST's to Push Your Legacy Code (& the Web) Forward
21mAutomating Front-End Refactoring
34mCodemods and Transforming JavaScript Code
20mThey see me refactorin'. They hatin'
25mManage large refactors with JSCodeShift
28mMaster the art of the AST and take control of your JS
36mTransformers - codemods in disguise
