]> code.delx.au - gnu-emacs-elpa/commit
Fix array destructuring including triple-dot
authorDavid Greenspan <dgreenspan@alum.mit.edu>
Sun, 8 Nov 2015 19:29:57 +0000 (11:29 -0800)
committerDavid Greenspan <dgreenspan@alum.mit.edu>
Sun, 8 Nov 2015 19:29:57 +0000 (11:29 -0800)
commit7fe716506b3e8536446c1a83a54e4b3c8d39f361
tree47121056d397167f486230c933d560d6343dedf5
parentf9d28d3dc2c8604907ae4ea022b2c59efdab1199
Fix array destructuring including triple-dot

This change enables proper parsing of:
* `let [a, b, ...c] = d;`
* `let [[x,y] = [1,2]] = z;`

The first case is simply the "rest" part of "array rest/spread," which
lacked the appropriate cases in `js2-parse-array-literal` and
`js2-define-destruct-symbols`.  There's also new logic to make sure that
in the destructuring (rest) case, the rest element comes last (while
spread can occur anywhere).

The removal of the `;; destructuring bind` case of
`js2-parse-array-literal` may require some explanation.  It was doing
more harm than good.  For example, it assumed that only identifiers
have defaults.  Also, calling `js2-parse-destruct-primary-expr` is
unnecessary, since `js2-is-in-destructuring` is already true.  Rather
than add the triple-dot logic in two places, it was simpler to stop
distinguishing between destructuring and non-destructuring at this
level, because the grammars are extremely similar.  In addition, wacky
"vars" as in `let [f()] = x` throw an error anyway when they hit
`js2-define-destruct-symbols`.
js2-mode.el
tests/parser.el