12. Build Example Code Model
• Traverse the example code AST
• Matchers extract code into our code model
• Result is an in memory model of the example code
20. React Stale Closures
• useCallback needs dependencies listed in array
• We need to identify the function dependencies
• Can we use the AST to automate this?
YES!
26. Validation
• Run generated code through Typescript with strict mode enabled
• - load every example variation
• - snapshot major visual features
• Git Di
ff
the generated output in a standalone repo
27. The Result
• Update all examples for a framework variation via a single converter
• e.g support for Typescript in React, 500+ examples in a day
• Add a new framework, just create a new converter
• Happy devs with more time to work on grid features!
• Happy users with code examples in their framework!
28. Take aways
• Use Abstract Syntax Trees to reason / generate code
• astexplorer.net to visualise / interact with AST
• Understand / Contribute to Code Linters
Don’t manually maintain code you can generate!
29. Let me know what you build!
Stephen Cooper
@SCooperDev