Skip to content

Latest commit

 

History

History
30 lines (19 loc) · 624 Bytes

2.3.4 esprima-ECMAScript 解析器 .md

File metadata and controls

30 lines (19 loc) · 624 Bytes

2.3.4 esprima: Esprima 是执行JavaScript程序的词法和句法分析的工具

:ECMAScript 解析器

Esprima是使用ECMAScript(也称为JavaScript)编写的高性能,符合标准的ECMAScript解析器。

install

npm install esprima -S

usage

let esprima = require('esprima')

const esprimaDemo = esprima.parseScript('answer = 42')
console.log(esprimaDemo)

const program = 'const answer = 42';
console.log(esprima.tokenize(program))
console.log(esprima.parseScript(program))

参考