(defvar js--treesit-indent-rules
(let ((switch-case (rx "switch_" (or "case" "default"))))
`((javascript
+ ((parent-is "program") parent-bol 0)
(no-node (js--treesit-backward-up-list) ,js-indent-level)
((node-is "}") parent-bol 0)
((node-is ")") parent-bol 0)
((node-is "]") parent-bol 0)
((node-is ">") parent-bol 0)
- ((node-is "\\.") parent-bol ,js-indent-level)
+ ((parent-is "ternary_expression") parent-bol ,js-indent-level)
+ ((parent-is "member_expression") parent-bol ,js-indent-level)
((node-is ,switch-case) parent-bol 0)
;; "{" on the newline.
((node-is "statement_block") parent-bol ,js-indent-level)
(defvar ts-mode--indent-rules
`((tsx
+ ((parent-is "program") parent-bol 0)
((node-is "}") parent-bol 0)
((node-is ")") parent-bol 0)
((node-is "]") parent-bol 0)
parent-bol ,ts-mode-indent-offset)
((parent-is "ternary_expression")
parent-bol ,ts-mode-indent-offset)
+ ((parent-is "member_expression")
+ parent-bol ,ts-mode-indent-offset)
((parent-is "named_imports")
parent-bol ,ts-mode-indent-offset)
((parent-is "statement_block")
:syntax-table ts-mode--syntax-table
(cond
+ ;; `ts-mode' requires tree-sitter to work, so we don't check if
+ ;; user enables tree-sitter for it.
((treesit-ready-p nil 'tsx)
;; Tree-sitter.
+ (treesit-parser-create 'tsx)
;; Comments.
(setq-local comment-start "// ")
(setq-local comment-start-skip "\\(?://+\\|/\\*+\\)\\s *")