branch: externals/js2-mode commit 394b85e0eb5b0a474c49c8ae24eff8ba912466d7 Author: babenhauserheide <arne.babenhauserhe...@disy.net> Commit: babenhauserheide <arne.babenhauserhe...@disy.net>
Add node creation and basic syntax tests --- js2-mode.el | 19 ++++++++++++++----- tests/parser.el | 19 +++++++++++++++++++ 2 files changed, 33 insertions(+), 5 deletions(-) diff --git a/js2-mode.el b/js2-mode.el index 304303e..341f01b 100644 --- a/js2-mode.el +++ b/js2-mode.el @@ -6096,10 +6096,10 @@ its relevant fields and puts it into `js2-ti-tokens'." (?, (throw 'return js2-COMMA)) (?? - (if (js2-match-char ?.) - (throw 'return js2-OPTIONAL-CHAINING) - (if (js2-match-char ??) - (throw 'return js2-NULLISH-COALESCING) + (if (js2-match-char ??) + (throw 'return js2-NULLISH-COALESCING) + (if (js2-match-char ?.) + (throw 'return js2-OPTIONAL-CHAINING) (throw 'return js2-HOOK)))) (?: (if (js2-match-char ?:) @@ -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-or-expr)) + (pn (js2-parse-nullish-coalescing-expr)) test-expr if-true if-false @@ -10023,6 +10023,15 @@ FIXME: The latter option is unused?" 'js2-parse-eq-expr))) pn)) + +(defun js2-parse-nullish-coalescing-expr () + (let ((pn (js2-parse-or-expr))) + (when (js2-match-token js2-NULLISH-COALESCING) + (setq pn (js2-make-binary js2-NULLISH-COALESCING + 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 d890549..094ca29 100644 --- a/tests/parser.el +++ b/tests/parser.el @@ -17,6 +17,10 @@ ;; You should have received a copy of the GNU General Public License ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. +;;; Commentary: + +;; run tests with M-x ert-run-tests-interactively + ;;; Code: (require 'ert) @@ -1012,6 +1016,21 @@ the test." (should node) (should (string= (js2-node-text node) "99")))) +;; nullish coalescing, via https://github.com/tc39/proposal-nullish-coalescing +(js2-deftest nullish-coalescing-operator-null-variable + "var a = null; a ?? b;" + (js2-mode--and-parse) + (let ((node (js2-find-node js2-mode-ast 'js2-name-node-p))) + (should node) + (should (string= (js2-node-text node) "b")))) + +(js2-deftest nullish-coalescing-operator-null-value + "null ?? b;" + (js2-mode--and-parse) + (let ((node (js2-find-node js2-mode-ast 'js2-name-node-p))) + (should node) + (should (string= (js2-node-text node) "b")))) + (js2-deftest unary-void-node-start "var c = void 0" (js2-mode--and-parse)