branch: master commit bc61ce03600bc3a00e0922ca3546ec7098a7abf5 Author: Jackson Ray Hamilton <jack...@jacksonrayhamilton.com> Commit: Jackson Ray Hamilton <jack...@jacksonrayhamilton.com>
Fix off-by-one error for comment node length --- js2-mode.el | 7 +++++-- tests/parser.el | 12 ++++++++++++ 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/js2-mode.el b/js2-mode.el index 5424ff0..46ef97d 100644 --- a/js2-mode.el +++ b/js2-mode.el @@ -6163,8 +6163,11 @@ its relevant fields and puts it into `js2-ti-tokens'." (setf (js2-token-beg token) (- js2-ts-cursor 2)) (js2-skip-line) (setf (js2-token-comment-type token) 'line) - ;; include newline so highlighting goes to end of window - (cl-incf (js2-token-end token)) + ;; include newline so highlighting goes to end of + ;; window, if there actually is a newline; if we + ;; hit eof, then implicitly there isn't + (unless js2-ts-hit-eof + (cl-incf (js2-token-end token))) (throw 'return js2-COMMENT)) ;; is it a /* comment? (when (js2-match-char ?*) diff --git a/tests/parser.el b/tests/parser.el index d791d3f..0dd1502 100644 --- a/tests/parser.el +++ b/tests/parser.el @@ -793,3 +793,15 @@ the test." (js2-deftest function-without-parens-error "function b {}" ;; Should finish the parse. (js2-mode)) + +;;; Comments + +(js2-deftest comment-node-length "//" + (js2-mode) + (let ((node (js2-node-at-point (point-min)))) + (should (= (js2-node-len node) 2)))) + +(js2-deftest comment-node-length-newline "//\n" + (js2-mode) + (let ((node (js2-node-at-point (point-min)))) + (should (= (js2-node-len node) 3))))