Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Abstract Syntax Tree in Javascript
Search
Taketoshi Aono(青野健利 a.k.a brn)
January 24, 2018
Programming
0
180
Abstract Syntax Tree in Javascript
JavascriptのASTについて
Taketoshi Aono(青野健利 a.k.a brn)
January 24, 2018
Tweet
Share
More Decks by Taketoshi Aono(青野健利 a.k.a brn)
See All by Taketoshi Aono(青野健利 a.k.a brn)
document.write再考
brn
6
3.1k
Parsing Javascript
brn
14
9.3k
JSON & Object Tips
brn
1
510
CA 1Day Youth Bootcamp for Frontend LT
brn
0
990
Modern TypeScript
brn
2
830
javascript - behind the scene
brn
3
760
tc39 proposals
brn
0
900
プロダクト開発とTypeScript
brn
8
2.9k
React-Springでリッチなアニメーション
brn
1
720
Other Decks in Programming
See All in Programming
AkarengaLT vol.38
hashimoto_kei
1
130
CSC305 Lecture 12
javiergs
PRO
0
240
CSC509 Lecture 07
javiergs
PRO
0
250
AsyncSequenceとAsyncStreamのプロポーザルを全部読む!!
s_shimotori
1
160
CSC305 Lecture 10
javiergs
PRO
0
320
コードとあなたと私の距離 / The Distance Between Code, You, and I
hiro_y
0
210
ネストしたdata classの面倒な更新にさようなら!Lensを作って理解するArrowのOpticsの世界
shiita0903
1
180
Dive into Triton Internals
appleparan
0
310
alien-signals と自作 OSS で実現する フレームワーク非依存な ロジック共通化の探求 / Exploring Framework-Agnostic Logic Sharing with alien-signals and Custom OSS
aoseyuu
3
2.5k
Leading Effective Engineering Teams in the AI Era
addyosmani
7
680
One Enishi After Another
snoozer05
PRO
0
170
マイベストのシンプルなデータ基盤の話 - Googleスイートとのつき合い方 / mybest-simple-data-architecture-google-nized
snhryt
0
110
Featured
See All Featured
How To Stay Up To Date on Web Technology
chriscoyier
791
250k
Why Our Code Smells
bkeepers
PRO
340
57k
Facilitating Awesome Meetings
lara
57
6.6k
Intergalactic Javascript Robots from Outer Space
tanoku
273
27k
ReactJS: Keep Simple. Everything can be a component!
pedronauck
666
130k
Imperfection Machines: The Place of Print at Facebook
scottboms
269
13k
Agile that works and the tools we love
rasmusluckow
331
21k
The Web Performance Landscape in 2024 [PerfNow 2024]
tammyeverts
10
900
[RailsConf 2023 Opening Keynote] The Magic of Rails
eileencodes
31
9.7k
I Don’t Have Time: Getting Over the Fear to Launch Your Podcast
jcasabona
34
2.5k
Measuring & Analyzing Core Web Vitals
bluesmoon
9
650
Raft: Consensus for Rubyists
vanstee
140
7.2k
Transcript
Abstract Syntax Tree in Javascript
Name @brn (ꫬꅿ⨳ⵃ) Occupation ؿٗٝزؒٝسؒٝآص،٥ط؎ذ؍ـؒٝآص، Company Cyberagent ،سذؙأةآؔ AI Messenger
OSS Contributor of V8 Blog http://abcdef.gets.b6n.ch/ Twitter https://twitter.com/brn227 GitHub https://github.com/brn
What is AST? ASTהכJavascriptךفؚٗٓيػ٦أ׃穠卓欰䧭ׁ 圓俑邌植׃加圓鸡ךֿה
if (x) { x = 100 }
IF CONDITION THEN BLOCK EXPRESSION STATEMENT ASSIGN VAR PROXY (X)
LITERAL (100) if (x) { x = 100
Why need it? فؚٗٓيך㶵ךתת⢪ֲךכꨇ׃ְկ javascript㹋遤ׅחכ圫ղזؿؑ٦ؤָ֮կ غ؎ز؝٦س欰䧭ծCFG欰䧭ծIR欰䧭ծ剑黝⻉ծetc…
How do I create it? فؚٗٓىؚٝ鎉铂חכ㛇劤涸חכ俑岀ָ㶷㖈ׅկ JavascriptכEcmaInternationalָ➬圫תהגⰕ׃גְկ
None
Grammars ך⚥ח俑岀ָ㹀纏ׁגְل٦آָ֮ךדֿ撑ֿׅ הדػ٦؟٦剅ֻֿהָדֹկ
None
But… ֿך俑岀㹀纏כ㛇劤涸חךתת⢪ֲךכꨇ׃ְկ
Javascript become too complex Javascriptך俑岀כַז醱꧟חזגֹגֶծ秪磏חךתת ػ٦أֿׅהַָזꨇ׃ְկ
var a = /aaa|bbb/! b / 2 = 0;! !
// Is it easy?! b = / 2 = 0 /! ת׆כ剣せז姻鋉邌植ַ
var a = (x, y) => x + y;! var
a = (x, y);! ! var a = x => x;! var a = x;! ،ٗ٦ꟼ侧
None
var {a: b, b: c} = {b: 1, c: 2};!
({a: b, b: c});! ! [a, b, c] = [0, 1, 2];! [a, b, c];! ⴓⶴ➿Ⰵ
Parser has many state 穠㽷Parserכ㣐ꆀך朐䡾⥂䭯׃זָ갹䓸גػ٦أׅ׃ַז ְկ
AST Usage 蕱⸤׃ג⡲♳־ASTכוֲ⢪גְךַ
In V8 ASTַScope欰䧭׃ׅ ׁח剑穄涸חBytecode欰䧭׃ג㹋遤ׅ YieldװAsync٥Awaitך圓俑JavascriptךStateMachineח㢌䳔ׅ 
In Babel AST㢌䳔׃ג剑倜ךJavascriptַ植㖈ךJavascriptפ㢌䳔ׅ
In istanbul AST㢌䳔׃גぐ؝٦سח鸐麓׃⽩➰ֽ؝٦س㙵鴥
Try and play AST Esprima⢪ֲֿהד知⽃חAST欰䧭ֿׅהָדֹ ת https://github.com/estools חػ٦أ׃ASTQuery׃ׅخ٦ָٕ尶㿊֮ךד鑐׃ גה葺ְ
Summary AST鍗ה鸐䌢ךفؚٗٓيדכꨇ׃ַֿהָ葿ղדֹ״ ֲחז 嚂׃ְךד僽ꬊ♧㔐ְֻכ鑐׃גהְְה䙼ֲ