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.
This commit is contained in:
Jackson Ray Hamilton 2019-09-22 12:55:44 -07:00
parent ee89c1cdb5
commit 9aacc443d9
No known key found for this signature in database
GPG key ID: B4771664B476B290
2 changed files with 21 additions and 1 deletions

View 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

View file

@ -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