]> git.eshelyaron.com Git - emacs.git/commitdiff
Ignore comments and strings when recognizing JSX
authorJackson Ray Hamilton <jackson@jacksonrayhamilton.com>
Sun, 22 Sep 2019 19:55:44 +0000 (12:55 -0700)
committerJackson Ray Hamilton <jackson@jacksonrayhamilton.com>
Sun, 22 Sep 2019 19:55:44 +0000 (12:55 -0700)
* lisp/progmodes/js.el (js-syntax-propertize): Ignore comments and
strings.
* test/manual/indent/jsx-comment-string.jsx: New test.

lisp/progmodes/js.el
test/manual/indent/jsx-comment-string.jsx [new file with mode: 0644]

index 65a2538c30a87b30a79f80a16fd7f129abe557e2..3050e8f1a76a664df94c600cedbccf25b4249b07 100644 (file)
@@ -2358,7 +2358,11 @@ testing for syntax only valid as JSX."
                               'syntax-table (string-to-syntax "\"/"))
            (js-syntax-propertize-regexp end)))))
     ("\\`\\(#\\)!" (1 "< b"))
-    ("<" (0 (ignore (if js-jsx-syntax (js-jsx--syntax-propertize-tag end))))))
+    ("<" (0 (ignore
+             (when js-jsx-syntax
+               ;; Not inside a comment or string.
+               (unless (nth 8 (save-excursion (syntax-ppss (match-beginning 0))))
+                 (js-jsx--syntax-propertize-tag end)))))))
    (point) end))
 
 (defconst js--prettify-symbols-alist
diff --git a/test/manual/indent/jsx-comment-string.jsx b/test/manual/indent/jsx-comment-string.jsx
new file mode 100644 (file)
index 0000000..37a6c32
--- /dev/null
@@ -0,0 +1,16 @@
+// Local Variables:
+// indent-tabs-mode: nil
+// js-indent-level: 2
+// End:
+
+// The following tests go below any comments to avoid including
+// misindented comments among the erroring lines.
+
+// The JSX-like text in comments/strings should be treated like the enclosing
+// syntax, not like JSX.
+
+// <Foo>
+void 0
+
+"<Bar>"
+void 0