KEMBAR78
Code Generation with TypeScript | PDF
Code
Generation with
TypeScript
1
Hello,
2
I am Benny.
TypeScript enthusiast and
creator of vote4code.com
You can follow me on Twitter
@bennycode
Berlin.JS!
3
I am Florian.
TypeScript enthusiast and
creator of sortjson.com
You can follow me on GitHub
@ffflorian
4
5
Frontend Backend
6
https://petstore.swagger.io/
7
Generated with Swaxios
8
Code Generation
A mechanism to produce [ … ]
computer programs [ … ] in
some automatic manner.“ wikipedia.org
9
Iteration I
10
Iteration I Trainee
Requires onboarding
Requires reviews
Requires park walks
Doesn’t check syntax
11
Iteration II
12
Iteration II Handlebars
Requires dependency
Requires helpers
Requires IDE plugin
Doesn’t check syntax
13
Iteration III
14
Compiler API
Ships with TypeScript
Uses AST format
Checks syntax
Generates valid output
15
Architectural Overview
https://github.com/microsoft/TypeScript/wiki/Architectural-Overview
Compiler
Phases
Code
Token
Stream
16
Scanner Parser AST
https://basarat.gitbook.io/typescript/overview/scanner
17
https://ts-ast-viewer.com/
Code
Generation
Nodes (AST)
A program is
basically a
sequence of
statements.
All expressions
and statements
can be
represented as
nodes and
subtrees.
Printer
Prints a node
and its subtree
as-is, without
any emit
transformations.
The result is a
stringified
version of the
source code.
Source File
A destination file
that provides
context for the
node.
Can be written
with a wrapper
method like
ts.sys.write
File.
18
19
Thanks!
Any questions?
Create an issue in
our demo repository.
20

Code Generation with TypeScript