JavaScript language support for the CodeMirror code editor

Usage no npm install needed!

<script type="module">
  import codemirrorLangJavascript from 'https://cdn.skypack.dev/@codemirror/lang-javascript';


@codemirror/lang-javascript NPM version


This package implements JavaScript language support for the CodeMirror code editor.

The project page has more information, a number of examples and the documentation.

This code is released under an MIT license.

We aim to be an inclusive, welcoming community. To make that explicit, we have a code of conduct that applies to communication around the project.

API Reference

javascript(config⁠?: {jsx⁠?: boolean, typescript⁠?: boolean} = {}) → LanguageSupport

JavaScript support. Includes snippet completion.

javascriptLanguage: LezerLanguage

A language provider based on the Lezer JavaScript parser, extended with highlighting and indentation information.

typescriptLanguage: LezerLanguage

A language provider for TypeScript.

jsxLanguage: LezerLanguage

Language provider for JSX.

tsxLanguage: LezerLanguage

Language provider for JSX + TypeScript.

snippets: readonly Completion[]

A collection of JavaScript-related snippets.

esLint(eslint: any, config⁠?: any) → fn(viewEditorView) → Diagnostic[]

Connects an ESLint linter to CodeMirror's lint integration. eslint should be an instance of the Linter class, and config an optional ESLint configuration. The return value of this function can be passed to linter to create a JavaScript linting extension.

Note that ESLint targets node, and is tricky to run in the browser. The eslint4b and eslint4b-prebuilt packages may help with that.