![c9f4a0759d7c987b2c03a4945b0adc77.png](https://i-blog.csdnimg.cn/blog_migrate/ac26304397fda2b5a580550f0de72374.png)
ESLint 会对我们的代码进行校验,而 parser 的作用是将我们写的代码转换为 ESTree,ESLint 会对 ESTree 进行校验。
ESTree 只是一个 AST 的某一种规范,ESTree 本质上还是 AST
Espree
ESLint 默认的 parser ,只转换 js,默认支持 ES5 的语法,可以通过制定 parserOptions 给 Espree 传递如下选项。
"parserOptions": {
"ecmaVersion": 6,
"sourceType": "module",
"ecmaFeatures": {
"jsx": true
}
}
- ecmaVersion 可以开启更高 ES 版本的校验(已加入ES标准的语法,不包括实验性的语法),但需要注意的是一些新标准中的语法对 ESLint 的版本也有要求,如果发现ESLint 不支持校验,可能需要升级 ESLint 版本
- sourceType 可以设置为 "script",如果使用 ESModule 可以设置为 "module"<