JSのASTを触る
JavaScriptでASTを触る
解析の過程
parser
acorn, Babylon
warker, traverser, visitor
estraverse, babel-traverser
unparser
escodegen, babel-generator
jsのastの標準は
ちゃんとした仕様はない(?)
コミュニティ標準
estree/estree/es2015.mdとかにかいてるやつ
acornはもう少し情報が多い
便利ライブラリ
https://github.com/estools/espurify
https://github.com/estools
https://efcl.info/2016/03/06/ast-first-step/
ESTree 仕様
apiが返すオブジェクトの標準化
babylonを使ってASTを生成
code:js
const babylon = require('babylon');
const ast = babylon.parse('1 + 2 * ( 3 + 4 )');
console.log(ast);
参考
『JavaScript AST入門』
JSConfJP2019 day1#5de48b0c1982700000c91530
https://azu.github.io/slide/JSojisan/
https://efcl.info/2016/03/06/ast-first-step/
http://suguru03.hatenablog.com/entry/2019/12/05/070009
https://efcl.info/2019/12/03/dive-to-ast/
/nwtgck/TypeScript Transformerを使って任意の構文木を書き換えるシンプルなWebアプリの例