summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJackson Ray Hamilton <jackson@jacksonrayhamilton.com>2019-09-22 12:55:44 -0700
committerJackson Ray Hamilton <jackson@jacksonrayhamilton.com>2019-09-22 12:55:44 -0700
commit9aacc443d9465793b96cb844469056ae80e6d91b (patch)
tree7c529b8beb8b1714768a43356bdfaf6ab37f4a33
parentee89c1cdb5a3bb7b69b763a59a20b34508ddf3ae (diff)
downloademacs-9aacc443d9465793b96cb844469056ae80e6d91b.tar.gz
Ignore comments and strings when recognizing JSX
* lisp/progmodes/js.el (js-syntax-propertize): Ignore comments and strings. * test/manual/indent/jsx-comment-string.jsx: New test.
-rw-r--r--lisp/progmodes/js.el6
-rw-r--r--test/manual/indent/jsx-comment-string.jsx16
2 files changed, 21 insertions, 1 deletions
diff --git a/lisp/progmodes/js.el b/lisp/progmodes/js.el
index 65a2538c30a..3050e8f1a76 100644
--- a/lisp/progmodes/js.el
+++ b/lisp/progmodes/js.el
@@ -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
index 00000000000..37a6c3233d8
--- /dev/null
+++ b/test/manual/indent/jsx-comment-string.jsx
@@ -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