Open-source project
mooz/js2-mode avatar
mooz/js2-mode

js2-mode gives Emacs a JavaScript syntax tree other packages can use

Improved JavaScript editing mode for GNU Emacs

1,333 stars179 forksEmacs LispGPL-3.0

At a glance

What is it?
js2-mode is an Emacs major mode for JavaScript that goes beyond the built-in js-mode by building a parse tree that third-party packages consume, which is why refactoring and semantic tools exist for it. The stable versions ship through GNU ELPA, and the development version through MELPA.
Who is it for?
Adopt js2-mode if you edit JavaScript in Emacs and want a parse tree that other tools can query, since that is the specific thing it adds over the built-in mode and what packages like js2-refactor and skewer-mode depend on. Do not adopt it if your only need is syntax highlighting, because js-mode in a recent Emacs already covers JSX highlighting and indentation.
Can I use it commercially?
Yes, with conditions. GPL-3.0 is a copyleft licence: if you distribute software that includes it, you must release that software's source code under the same licence. Running it internally without distributing it does not trigger that obligation.
Is it still maintained?
Yes. The repository last received commits 133 days ago.
What is it written in?
Mainly Emacs Lisp, according to GitHub's language statistics.

Answers come from the project's GitHub data, last synced on November 6, 2026, and from our analysis. They are not legal advice.

From daily snapshots

Star history

  • mooz/js2-mode1,333 ★ · +0
Star history
Repository2026-10-202026-11-06
mooz/js2-mode1.3k1.3k

0 Stars in the last 17 days, measured from the daily GitHub snapshot. Compare with other projects

Editorial analysis

The AST is the product, not the highlighting

The mode is described as an improved JavaScript editing mode for GNU Emacs, but the interesting part is stated further down: the See Also section lists third-party modes that use the generated syntax tree, and among them are js2-refactor and skewer-mode. So the value of js2-mode is not that it colours JavaScript better than the built-in mode. It is that it produces a parse tree other Emacs Lisp code can walk, which is what makes refactoring and semantic tooling possible at all. The project's own bug guidance points at the same distinction: indentation problems should be reported with the Emacs bug reporter after trying to reproduce them with `js-mode` first, and the reason given is that starting with Emacs 25, js2-mode delegates indentation to the indentation engine of `js-mode`. In other words, the built-in mode owns the layout and js2-mode owns the tree.

For React and JSX, the built-in mode is the recommendation

The React and JSX section is where the documentation tells you not to use this package, which is a good sign. The currently recommended solution is to install Emacs 27, either built from source or from a PPA snapshot, and use `js-mode` as the major mode. The reason is that `js-mode` in Emacs 27 includes full support for syntax highlighting and indenting of JSX syntax. To make use of the JS2 AST and the packages that integrate with it, the documentation recommends `js2-minor-mode` instead, which is a minor mode layered over the built-in one rather than a replacement for it. The instructions point into the Commentary section of the source file for the details, and an alternative exists in rjsx-mode, which comes with certain trade-offs that the README does not enumerate.

Two package archives, two different things

Installation goes through one of two archives, and the distinction between them matters for what you get. The stable versions are hosted at GNU ELPA and are reachable from the built-in package list with `M-x list-packages`. The latest development version comes from MELPA. For a package that is part of the GNU Emacs ecosystem and subject to the same copyright assignment policy as Emacs itself, the ELPA/MELPA split is the usual one, and it means an ELPA install gives you a version that has gone through the package review process. The requirements are Emacs 24.1 or newer and `cl-lib`, either built in or installed from GNU ELPA, so on an old Emacs there is one more thing to install before this one. The README also links a NEWS.md file for the latest user-visible changes, which is the right place to look for what a new version actually changed.

Byte-compilation issues after an Emacs upgrade

The bug section documents a specific failure mode that will waste your afternoon if you hit it cold. If you see broken syntax highlighting and timer errors, and you recently upgraded Emacs from version 24.2 or earlier, the fix is to reinstall or byte-recompile the package. The reason is not spelled out, but the cause is a known property of the Emacs Lisp loader: a package compiled against an older Emacs can carry stale byte code that does not match the newer runtime, and the symptoms are highlighting and timers misbehaving rather than an error message. The issue tracker link is given for the long form of the explanation. The second bug rule is about indentation problems, which should be reported as Emacs bugs rather than js2-mode bugs, again because js2-mode delegates indentation to js-mode.

Contributions come with a copyright assignment form

The contributing section is where the project explains itself in a way that very few README files do. js2-mode is subject to the same copyright assignment policy as Emacs itself, org-mode, CEDET and other packages in GNU ELPA. The practical consequence is stated plainly: any legally significant contributions can only be accepted after the author has completed their paperwork, and you have to ask for the request form, which will be sent to you. That is the GNU convention for a package that will live in ELPA, where the copyright needs to be held in a way that survives a maintainer change. It also tells you something about the project's status: it is not a casual weekend package but one intended to be a long term part of the Emacs distribution, and the barrier to contributing is deliberate.

The repository is small and builds with a plain Makefile

The top level is three Emacs Lisp source files and a test directory, plus the usual metadata: `js2-mode.el` is the mode itself, `js2-imenu-extras.el` adds to the imenu, and `js2-old-indent.el` is the older indentation implementation kept around. There is a `tests/` directory, a `Makefile`, a `NEWS.md` for the user-visible changes, a `.dir-locals.el` and a `.elpaignore`. The Makefile compiles the sources non-interactively with a clean environment, using batch flags of `-batch -Q`, and the test target runs the ERT test suite in batch mode:

bash
test: all
	${EMACS} $(BATCHFLAGS) -L . \
	  $(addprefix -l ,$(OBJS)) \
	  -f ert-run-tests-batch-and-exit

The `-Q` flag is the one that matters, since it starts Emacs without loading your personal configuration, so the tests see the package as a user would see it rather than as your own setup makes it. There is a GitHub Actions workflow for the test suite, and the licence is GPL 3.0. The last push to the master branch was on 2026-06-27.

Editorial conclusion

Adopt js2-mode if you edit JavaScript in Emacs and want a parse tree that other tools can query, since that is the specific thing it adds over the built-in mode and what packages like js2-refactor and skewer-mode depend on. Do not adopt it if your only need is syntax highlighting, because js-mode in a recent Emacs already covers JSX highlighting and indentation. Verify first which major mode you actually want, since the documentation recommends the built-in js-mode for most work and js2-minor-mode only when you need the AST, and note that the copyright assignment policy means a substantial contribution comes with paperwork.

Frequently asked questions

What does js2-mode add to Emacs's built-in js-mode?

It generates a parse tree that third-party packages can use, which is what enables tools like js2-refactor and skewer-mode. Starting with Emacs 25, js2-mode delegates indentation to the indentation engine of js-mode.

How do I install js2-mode?

The stable versions are hosted at GNU ELPA and are reachable with `M-x list-packages`. The latest development version is available from MELPA. The requirements are Emacs 24.1 or newer and cl-lib, either built in or installed from GNU ELPA.

Should I use js2-mode for React and JSX?

The documentation recommends Emacs 27 and the built-in `js-mode` instead, because it includes full support for syntax highlighting and indenting of JSX. If you need the JS2 AST and the packages built on it, use `js2-minor-mode` instead.

What should I do if syntax highlighting breaks after upgrading Emacs?

If you recently upgraded from Emacs 24.2 or earlier, reinstall or byte-recompile the package. Stale byte code from the older Emacs is the usual cause of broken highlighting and timer errors in that situation.

What is the contribution policy for js2-mode?

The project follows the same copyright assignment policy as Emacs itself, org-mode and CEDET. Legally significant contributions are only accepted after the author completes the paperwork, and you have to request the form.

Official sources

  1. Issues
  2. License: GPL-3.0
  3. mooz/js2-mode on GitHub
  4. README
Add this badge to your README

If you maintain this project, the badge below links readers to this analysis and shows its maintenance status from the daily GitHub snapshot. Paste the markdown into your README; add ?metric=license or ?metric=stars to the image URL for a different field.

Add this badge to your README

markdown
[![Hysen Labs](https://hysenlabs.com/badge/mooz-js2-mode.svg)](https://hysenlabs.com/projects/mooz-js2-mode)

Star history chart for your README

markdown
[![Star history](https://hysenlabs.com/chart/mooz-js2-mode.svg)](https://hysenlabs.com/projects/mooz-js2-mode)

Was this useful?