$ git clone git://github.com/mooz/js2-mode.git
$ cd js2-mode
- $ emacs --batch --eval '(byte-compile-file "js2-mode.el")'
+ $ emacs --batch -f batch-byte-compile js2-mode.el
+
+_NOTE: Emacs may fail to byte compile js2-mode.el in interactive mode (e.g., `M-x byte-compile-file`). Following the above instruction is highly recommended. See https://github.com/mooz/js2-mode/issues/13 for details._
Then, place js2-mode.elc into your site-lisp directory.
Differences between original js2-mode.el
========================================
-Supported more popular indentation style
-----------------------------------------
+Popular indentation style
+-------------------------
-When js2-consistent-level-indent-inner-bracket-p is non-nil
+When `js2-consistent-level-indent-inner-bracket-p` is non-nil
[foo, bar, baz].forEach(function (v) {
if (validate(v))
return validate(v);
});
-When js2-consistent-level-indent-inner-bracket-p is nil
+When `js2-consistent-level-indent-inner-bracket-p` is nil
(Same as original js2-mode's indentation)
[foo, bar, baz].forEach(function (v) {
return validate(v);
});
-Fixed ugly indentation with multi-line variable declaration
------------------------------------------------------------
+Pretty multi-line variable declaration
+--------------------------------------
In original js2-mode.el,
bar = 20,
baz = 30;
-In this js2-mode.el,
+In this js2-mode.el, when the value `js2-pretty-multiline-decl-indentation-p` is non-nil,
var foo = 10,
bar = 20,
baz = 30;
-Support for abbreviated destructuring assignments
--------------------------------------------------
+Abbreviated destructuring assignments
+-------------------------------------
let {a, b} = {a: 10, b: 20}; // Abbreviated (Not supported in original js2-mode.el)
let {a: a, b: b} = {a: 10, b: 20}; // Same as above (Supported in original js2-mode.el)
for (let [k, { name, age }] in Iterator(obj)) // nested
print(k, name, age);
-Support for expression closure in property value
-------------------------------------------------
+Expression closure in property value
+------------------------------------
let worker = {
get age() 20,
fire: function () _fire()
};
-Fixed odd indentation of "else if" with no braces
------------------------------------------------------
+Fix for odd indentation of "else if" with no braces
+---------------------------------------------------
In original js2-mode.el,
Imenu support for function nesting
----------------------------------
-Supports one level of nesting:
-
- function foo() {
- function bar() { // shown as foo.bar
- function baz() {} // hidden
- }
- }
-
-Top-level function can be anonymous wrapper:
+Supports function nesting and anonymous wrappers:
(function() {
- var foo = function() {}; // shown as foo
- })();
+ var foo = function() {
+ function bar() { // shown as foo.bar.<definition-1>
+ function baz() {} // foo.bar.baz
+ var qux = function() {}; // foo.bar.quux
+ }
+ };
+ });
Examples of output:
-* [Underscore.js](https://github.com/documentcloud/underscore/blob/master/underscore.js)
--> <https://gist.github.com/824262>
-* [Backbone.js](https://github.com/documentcloud/backbone/blob/master/backbone.js)
--> <https://gist.github.com/824260>
+* [jQuery 1.5](https://gist.github.com/845449)
+* [Underscore.js](https://gist.github.com/824262)
+* [Backbone.js](https://gist.github.com/824260)
-No support for library-specific extension methods like _.extend.
+No support for library-specific extension methods like $.extend.
Highlights undeclared/external variables
----------------------------------------