aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorYuan Fu2024-12-12 21:42:44 -0800
committerYuan Fu2024-12-12 21:45:25 -0800
commit989cdb2c35889476702e4d2bd82d8195fa2e7ec0 (patch)
treea9c1af4c38e1851c1fe1924bf930089144b09556
parent9377ef5c2369202e372774c873af4d6c259cd28f (diff)
downloademacs-989cdb2c35889476702e4d2bd82d8195fa2e7ec0.tar.gz
emacs-989cdb2c35889476702e4d2bd82d8195fa2e7ec0.zip
Apply string syntax only to string in jsx (bug#73978)
The current code applies string syntax to too many things. This patch makes tsx-ts-mode (and friends) only apply string syntax to actual text in tsx/jsx. * lisp/progmodes/typescript-ts-mode.el: (tsx-ts--s-p-query): Only capture jsx_text. (tsx-ts--syntax-propertize-captures): handle the case when the text is one character long.
-rw-r--r--lisp/progmodes/typescript-ts-mode.el17
1 files changed, 10 insertions, 7 deletions
diff --git a/lisp/progmodes/typescript-ts-mode.el b/lisp/progmodes/typescript-ts-mode.el
index 5389d0d64c9..edca89e5c3a 100644
--- a/lisp/progmodes/typescript-ts-mode.el
+++ b/lisp/progmodes/typescript-ts-mode.el
@@ -596,11 +596,7 @@ at least 3 (which is the default value)."
596 (when (treesit-available-p) 596 (when (treesit-available-p)
597 (treesit-query-compile 'tsx 597 (treesit-query-compile 'tsx
598 '(((regex pattern: (regex_pattern) @regexp)) 598 '(((regex pattern: (regex_pattern) @regexp))
599 ((variable_declarator value: (jsx_element) @jsx)) 599 ((jsx_text) @jsx)))))
600 ((assignment_expression right: (jsx_element) @jsx))
601 ((arguments (jsx_element) @jsx))
602 ((parenthesized_expression (jsx_element) @jsx))
603 ((return_statement (jsx_element) @jsx))))))
604 600
605(defun typescript-ts--syntax-propertize (beg end) 601(defun typescript-ts--syntax-propertize (beg end)
606 (let ((captures (treesit-query-capture 'typescript typescript-ts--s-p-query beg end))) 602 (let ((captures (treesit-query-capture 'typescript typescript-ts--s-p-query beg end)))
@@ -621,8 +617,15 @@ at least 3 (which is the default value)."
621 (string-to-syntax "\"/")) 617 (string-to-syntax "\"/"))
622 ('jsx 618 ('jsx
623 (string-to-syntax "|"))))) 619 (string-to-syntax "|")))))
624 (put-text-property ns (1+ ns) 'syntax-table syntax) 620 ;; The string syntax require at least two characters (one for
625 (put-text-property (1- ne) ne 'syntax-table syntax)))) 621 ;; opening fence and one for closing fence). So if the string has
622 ;; only one character, we apply the whitespace syntax. The string
623 ;; has to be in a non-code syntax, lest the string could contain
624 ;; parent or brackets and messes up syntax-ppss.
625 (if (eq ne (1+ ns))
626 (put-text-property ns ne 'syntax-table "-")
627 (put-text-property ns (1+ ns) 'syntax-table syntax)
628 (put-text-property (1- ne) ne 'syntax-table syntax)))))
626 629
627(if (treesit-ready-p 'tsx) 630(if (treesit-ready-p 'tsx)
628 (add-to-list 'auto-mode-alist '("\\.tsx\\'" . tsx-ts-mode))) 631 (add-to-list 'auto-mode-alist '("\\.tsx\\'" . tsx-ts-mode)))