emacs-diffs
[Top][All Lists]
Advanced

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

master 8e1c553 3/3: Ignore comments and strings when matching JSX


From: Jackson Ray Hamilton
Subject: master 8e1c553 3/3: Ignore comments and strings when matching JSX
Date: Sat, 7 Dec 2019 16:23:10 -0500 (EST)

branch: master
commit 8e1c553260b04ce692986d428472490230b0a807
Author: Jackson Ray Hamilton <address@hidden>
Commit: Jackson Ray Hamilton <address@hidden>

    Ignore comments and strings when matching JSX
    
    * 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                      | 38 ++++++++++++++++---------------
 test/manual/indent/jsx-comment-string.jsx |  7 ++++++
 2 files changed, 27 insertions(+), 18 deletions(-)

diff --git a/lisp/progmodes/js.el b/lisp/progmodes/js.el
index 2de7777..c73c479 100644
--- a/lisp/progmodes/js.el
+++ b/lisp/progmodes/js.el
@@ -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.
diff --git a/test/manual/indent/jsx-comment-string.jsx 
b/test/manual/indent/jsx-comment-string.jsx
index 37a6c32..cae023e 100644
--- a/test/manual/indent/jsx-comment-string.jsx
+++ b/test/manual/indent/jsx-comment-string.jsx
@@ -14,3 +14,10 @@ void 0
 
 "<Bar>"
 void 0
+
+<Chicken>
+  {/* <Pork> */}
+  <Beef attr="<Turkey>">
+    Yum!
+  </Beef>
+</Chicken>



reply via email to

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