Skip to main content

编辑器

语法高亮

¥Syntax Highlighting

Syntax Highlighting

如今,许多流行的编辑器都支持开箱即用的 ES2015+ 语法高亮显示,而有些则需要安装额外的扩展。本指南应该可以帮助你使语法高亮正常工作。

¥These days, many popular editors support ES2015+ syntax highlighting out of the box, while some require installing additional extensions. This guide should help you get the syntax highlighting to work.

如果你正在寻找更高级的集成,你可能需要查看 设置 指南。

¥If you're looking for more advanced integrations, you may want to take a look at the Setup guide.

提示:上面截图中使用的字体是 FiraCode

¥Tip: The font used on the screenshot above is FiraCode.

Atom

安装 language-babel 包,按照 instructions

¥Install language-babel package and follow the instructions.

Emacs

安装可能是 Emacs 可用的最佳 JavaScript 模式的 js2-mode。它使用递归下降解析器进行非常准确的语法高亮,严格识别 Ecma-262 语言标准,支持 1.5 及以上版本的大多数 Rhino 和 SpiderMonkey 扩展,以及动态报告语法错误和严格模式警告。

¥Install the js2-mode that's likely the best JavaScript mode available for Emacs. It has very accurate syntax highlighting using a recursive-descent parser, strict recognition of the Ecma-262 language standard, supports most Rhino and SpiderMonkey extensions from 1.5 and up, and on-the-fly reporting of syntax errors and strict-mode warnings.

除了 js2-mode,你还可以安装另外两个包,添加强大重构功能的 js2-refactor 和可以轻松跳转到函数引用或定义的 xref-js2

¥In adition to js2-mode, you can install two more packages, js2-refactor that adds powerful refactorings, and xref-js2 that makes it easy to jump to function references or definitions.

Sublime Text 3

首先,安装包控制。然后从 Package Control 菜单安装 Babel 包并按照 instructions

¥First, install Package Control. Then install Babel package from the Package Control menu and follow the instructions.

Vim

安装 vim-javascript 插件,它为 Vim 带来了改进的语法高亮和对 JavaScript 的缩进支持。

¥Install the vim-javascript plugin, which brings both improved syntax highlighting and indentation support for JavaScript to Vim.

另一种选择是将 yajs.vimes.next.syntax 一起使用。

¥Another option is to use yajs.vim with es.next.syntax.

Visual Studio Code

安装 vscode-language-babel 扩展并按照说明进行操作。

¥Install the vscode-language-babel extension and follow the instructions.

似乎还有另一种方法可以使语法高亮工作,你可以在 Visual Studio 代码文档 中了解更多信息。

¥There seems to be one other way to get the syntax highlighting working and you can learn more about it in the Visual Studio Code docs.

WebStorm

WebStorm 现在支持 ES2015+,无需安装任何额外的扩展。但是,你可能需要 启用它

¥WebStorm now ships with support for ES2015+ without requiring the installation of any additional extensions. You may, however, need to enable it.

Emacs

安装 js2-mode

¥Install the js2-mode.

另一种选择是使用 web-mode

¥Another option is to use web-mode.