From 9aacc443d9465793b96cb844469056ae80e6d91b Mon Sep 17 00:00:00 2001 From: Jackson Ray Hamilton Date: Sun, 22 Sep 2019 12:55:44 -0700 Subject: 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. --- lisp/progmodes/js.el | 6 +++++- test/manual/indent/jsx-comment-string.jsx | 16 ++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) create mode 100644 test/manual/indent/jsx-comment-string.jsx 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. + +// +void 0 + +"" +void 0 -- cgit v1.2.1