emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[elpa] externals/js2-mode db17df4 53/61: Fix nullish coalescing in cond


From: Dmitry Gutov
Subject: [elpa] externals/js2-mode db17df4 53/61: Fix nullish coalescing in cond exprs and add test with ternary op
Date: Sun, 20 Dec 2020 12:20:11 -0500 (EST)

branch: externals/js2-mode
commit db17df4670355c6b27dfed13959d8da442a154ed
Author: Jonathan Ming <jming422@gmail.com>
Commit: Jonathan Ming <jming422@gmail.com>

    Fix nullish coalescing in cond exprs and add test with ternary op
---
 js2-mode.el     | 10 +++++-----
 tests/parser.el | 13 +++++++------
 2 files changed, 12 insertions(+), 11 deletions(-)

diff --git a/js2-mode.el b/js2-mode.el
index 341f01b..fae3b5f 100644
--- a/js2-mode.el
+++ b/js2-mode.el
@@ -9938,7 +9938,7 @@ If NODE is non-nil, it is the AST node associated with 
the symbol."
 
 (defun js2-parse-cond-expr ()
   (let ((pos (js2-current-token-beg))
-        (pn (js2-parse-nullish-coalescing-expr))
+        (pn (js2-parse-or-expr))
         test-expr
         if-true
         if-false
@@ -10016,7 +10016,7 @@ FIXME: The latter option is unused?"
     pn))
 
 (defun js2-parse-bit-and-expr ()
-  (let ((pn (js2-parse-eq-expr)))
+  (let ((pn (js2-parse-nullish-coalescing-expr)))
     (while (js2-match-token js2-BITAND)
       (setq pn (js2-make-binary js2-BITAND
                                 pn
@@ -10025,12 +10025,12 @@ FIXME: The latter option is unused?"
 
 
 (defun js2-parse-nullish-coalescing-expr ()
-  (let ((pn (js2-parse-or-expr)))
+  (let ((pn (js2-parse-eq-expr)))
     (when (js2-match-token js2-NULLISH-COALESCING)
       (setq pn (js2-make-binary js2-NULLISH-COALESCING
                                 pn
-                                'js2-parse-nullish-coalescing-expr)))
-    pn))
+                                'js2-parse-nullish-coalescing-expr))
+      pn)))
 
 (defconst js2-parse-eq-ops
   (list js2-EQ js2-NE js2-SHEQ js2-SHNE))
diff --git a/tests/parser.el b/tests/parser.el
index 4fa1950..952aa35 100644
--- a/tests/parser.el
+++ b/tests/parser.el
@@ -997,18 +997,19 @@ the test."
 
 ;; nullish coalescing, via https://github.com/tc39/proposal-nullish-coalescing
 (js2-deftest-parse nullish-coalescing-operator-null-variable
-  "var a = null; a ?? 1;")
+  "var a = null;\na ?? 1;")
 
 (js2-deftest-parse nullish-coalescing-operator-inexisting-field
-  "var a = {}; a.nonexistant ?? 1;")
+  "var a = {};\na.nonexistant ?? 1;")
 
 (js2-deftest-parse nullish-coalescing-operator-null-value
-  "var b = 1; null ?? b;")
+  "var b = 1;\nnull ?? b;")
 
 (js2-deftest-parse nullish-coalescing-operator-in-if
-  "if (null ?? b) {
-    return null;
-}")
+  "if (null ?? true) {\n  a = 2;\n}")
+
+(js2-deftest-parse nullish-coalescing-operator-in-ternary
+  "var c = null ?? true ? 1 : 2;")
 
 
 (js2-deftest optional-chaining-operator-on-property-access



reply via email to

[Prev in Thread] Current Thread [Next in Thread]