]> git.eshelyaron.com Git - emacs.git/commitdiff
Ignore comments and strings when matching JSX
authorJackson Ray Hamilton <jackson@jacksonrayhamilton.com>
Sat, 7 Dec 2019 21:10:45 +0000 (13:10 -0800)
committerJackson Ray Hamilton <jackson@jacksonrayhamilton.com>
Sat, 7 Dec 2019 21:18:00 +0000 (13:18 -0800)
* lisp/progmodes/js.el (js-jsx--matching-close-tag-pos): Ignore
comments and strings.
* test/manual/indent/jsx-comment-string.jsx: New test.

lisp/progmodes/js.el
test/manual/indent/jsx-comment-string.jsx

index 2de7777af5f4460bb43dab1da0f4b41d26ef786d..c73c4795de3af08243605d0dd153ae075a626c5d 100644 (file)
@@ -2059,24 +2059,26 @@ the match.  Return nil if a match can’t be found."
   (let ((tag-stack 1) tag-pos type last-pos pos)
     (catch 'stop
       (while (and (re-search-forward "<\\s-*" nil t) (not (eobp)))
-        (when (setq tag-pos (match-beginning 0)
-                    type (js-jsx--matched-tag-type))
-          (when last-pos
-            (setq pos (point))
-            (goto-char last-pos)
-            (while (re-search-forward js-jsx--self-closing-re pos 'move)
-              (setq tag-stack (1- tag-stack))))
-          (if (eq type 'close)
-              (progn
-                (setq tag-stack (1- tag-stack))
-                (when (= tag-stack 0)
-                  (throw 'stop tag-pos)))
-            ;; JSXOpeningElements that we know are self-closing aren’t
-            ;; added to the stack at all (because point is already
-            ;; past that syntax).
-            (unless (eq type 'self-closing)
-              (setq tag-stack (1+ tag-stack))))
-          (setq last-pos (point)))))))
+        ;; Not inside a comment or string.
+        (unless (nth 8 (save-excursion (syntax-ppss (match-beginning 0))))
+          (when (setq tag-pos (match-beginning 0)
+                      type (js-jsx--matched-tag-type))
+            (when last-pos
+              (setq pos (point))
+              (goto-char last-pos)
+              (while (re-search-forward js-jsx--self-closing-re pos 'move)
+                (setq tag-stack (1- tag-stack))))
+            (if (eq type 'close)
+                (progn
+                  (setq tag-stack (1- tag-stack))
+                  (when (= tag-stack 0)
+                    (throw 'stop tag-pos)))
+              ;; JSXOpeningElements that we know are self-closing
+              ;; aren’t added to the stack at all (because point is
+              ;; already past that syntax).
+              (unless (eq type 'self-closing)
+                (setq tag-stack (1+ tag-stack))))
+            (setq last-pos (point))))))))
 
 (defun js-jsx--enclosing-tag-pos ()
   "Return beginning and end of a JSXElement about point.
index 37a6c3233d843e149892824fe00a45781c528d4a..cae023e7288dd94a03b997f9d49d12108c26fdab 100644 (file)
@@ -14,3 +14,10 @@ void 0
 
 "<Bar>"
 void 0
+
+<Chicken>
+  {/* <Pork> */}
+  <Beef attr="<Turkey>">
+    Yum!
+  </Beef>
+</Chicken>