[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] 10/46: js2-parse-array-literal: improve trailing comma warning
From: |
Dmitry Gutov |
Subject: |
[elpa] 10/46: js2-parse-array-literal: improve trailing comma warning |
Date: |
Sat, 15 Nov 2014 20:57:58 +0000 |
dgutov pushed a commit to branch master
in repository elpa.
commit bce0ad0962c108dead720937749848f4adda2539
Author: Dmitry Gutov <address@hidden>
Date: Wed May 21 04:02:22 2014 +0300
js2-parse-array-literal: improve trailing comma warning
* Only warn when language version is < 1.7.
* Handle nil elements.
Fixes #142
---
js2-mode.el | 13 ++++++++-----
tests/parser.el | 3 +++
2 files changed, 11 insertions(+), 5 deletions(-)
diff --git a/js2-mode.el b/js2-mode.el
index 2eb3605..f2b9802 100644
--- a/js2-mode.el
+++ b/js2-mode.el
@@ -3477,7 +3477,10 @@ You can tell the quote type by looking at the first
character."
(defun js2-print-array-node (n i)
(insert (js2-make-pad i) "[")
- (js2-print-list (js2-array-node-elems n))
+ (let ((elems (js2-array-node-elems n)))
+ (js2-print-list elems)
+ (when (and elems (null (car (last elems))))
+ (insert ",")))
(insert "]"))
(defstruct (js2-object-node
@@ -9257,14 +9260,14 @@ array-literals, array comprehensions and regular
expressions."
(= tt js2-EOF)) ; prevent infinite loop
(if (= tt js2-EOF)
(js2-report-error "msg.no.bracket.arg" nil pos))
+ (when (and after-comma (< js2-language-version 170))
+ (js2-parse-warn-trailing-comma "msg.array.trailing.comma"
+ pos (remove nil elems) after-comma))
(setq continue nil
pn (make-js2-array-node :pos pos
:len (- js2-ts-cursor pos)
:elems (nreverse elems)))
- (apply #'js2-node-add-children pn (js2-array-node-elems pn))
- (when (and after-comma (not js2-is-in-destructuring))
- (js2-parse-warn-trailing-comma "msg.array.trailing.comma"
- pos elems after-comma)))
+ (apply #'js2-node-add-children pn (js2-array-node-elems pn)))
;; destructuring binding
(js2-is-in-destructuring
(push (if (or (= tt js2-LC)
diff --git a/tests/parser.el b/tests/parser.el
index ee56087..a4e2e82 100644
--- a/tests/parser.el
+++ b/tests/parser.el
@@ -87,6 +87,9 @@ the test."
(js2-deftest-parse empty-array-literal
"c = [];")
+(js2-deftest-parse array-with-missing-elements
+ "var a = [1, 2, ,];")
+
(js2-deftest-parse comma-after-regexp
"d = /eee/, 42;")
- [elpa] branch master updated (46fb875 -> 4e4c53b), Dmitry Gutov, 2014/11/15
- [elpa] 01/46: Add support for React classes in js2-imenu-extras, Dmitry Gutov, 2014/11/15
- [elpa] 02/46: Merge pull request #133 from johnmastro/imenu-react, Dmitry Gutov, 2014/11/15
- [elpa] 06/46: Merge pull request #138 from martinp/fix-electric-indent, Dmitry Gutov, 2014/11/15
- [elpa] 03/46: Reference #72 in the README, Dmitry Gutov, 2014/11/15
- [elpa] 05/46: Fix electric-indent-mode, Dmitry Gutov, 2014/11/15
- [elpa] 08/46: Fix parsing of function statements in blocks, Dmitry Gutov, 2014/11/15
- [elpa] 04/46: Try to improve formatting, Dmitry Gutov, 2014/11/15
- [elpa] 09/46: Rename mention of espresso-mode to js-mode, Dmitry Gutov, 2014/11/15
- [elpa] 10/46: js2-parse-array-literal: improve trailing comma warning,
Dmitry Gutov <=
- [elpa] 07/46: Cut down on reserved words; improve error reporting, Dmitry Gutov, 2014/11/15
- [elpa] 11/46: Support yield*, Dmitry Gutov, 2014/11/15
- [elpa] 16/46: Support Unicode Identifiers, Dmitry Gutov, 2014/11/15
- [elpa] 17/46: Check if buffer is alive before reparsing., Dmitry Gutov, 2014/11/15
- [elpa] 19/46: Better docstrings, Dmitry Gutov, 2014/11/15
- [elpa] 14/46: Support ES6 generator comprehensions, Dmitry Gutov, 2014/11/15
- [elpa] 13/46: Support ES6 array comprehensions, Dmitry Gutov, 2014/11/15
- [elpa] 12/46: Add `.' to electric-indent-chars for method continuations, Dmitry Gutov, 2014/11/15
- [elpa] 15/46: Add Contributing section, Dmitry Gutov, 2014/11/15
- [elpa] 24/46: Small tweak, Dmitry Gutov, 2014/11/15