什么是 JavaScript AST,如何使用它?
问题描述:
抽象语法树..我一直听说在 Github 上编译为 SpiderMonkey AST.
那么,这是 JS 语法树的实际标准吗?还有 V8,V8 是否使用相同类型的 AST?
Abstract Syntax Tree.. I always heard that compile to SpiderMonkey AST on Github.
So, is that a actual standard of JS syntax tree? And there's V8, is V8 using the same kind of AST?
我该怎么玩?
答
SpiderMonkey 提供了 parser api一>.这可能是掌握语法对象的最简单方法.
SpiderMonkey offers the parser api. This is probably the easiest way to get your hands on the syntax objects.
还有开放的 js-js 解析器,例如 Esprima(实际上是 ECMAScript,但它就在胡同)
There's also open js-js parsers like Esprima (which is ECMAScript, really, but it's right up the alley)