]> code.delx.au - gnu-emacs-elpa/commitdiff
Merge pull request #220 from jacksonrayhamilton/comment-length
authorDmitry Gutov <dgutov@yandex.ru>
Sun, 1 Mar 2015 10:06:52 +0000 (12:06 +0200)
committerDmitry Gutov <dgutov@yandex.ru>
Sun, 1 Mar 2015 10:06:52 +0000 (12:06 +0200)
Fix off-by-one error for comment node length

js2-mode.el
tests/parser.el

index 5424ff00a961d0905579ed2c21c8247aaecf9d15..46ef97d1d8d33d8755ca2207e9efca0fd8cdfdcb 100644 (file)
@@ -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 ?*)
index d791d3f163edcc031399b10753a6c2d54af15118..0dd1502c29147ca102aa71ffe2bfbc56011f8739 100644 (file)
@@ -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))))