branch: elpa/smartparens
commit 04f94b8ce207f9476b39eb397486e87c8507c84e
Author: Matus Goljer <[email protected]>
Commit: Matus Goljer <[email protected]>

    feat(js): add match skip function for js arrow functions
---
 smartparens-javascript.el           | 31 +++++++++++++++++++++----------
 test/smartparens-javascript-test.el | 20 ++++++++++++++++++++
 2 files changed, 41 insertions(+), 10 deletions(-)

diff --git a/smartparens-javascript.el b/smartparens-javascript.el
index 968694ad69..7295435fcf 100644
--- a/smartparens-javascript.el
+++ b/smartparens-javascript.el
@@ -46,19 +46,30 @@
 
 (require 'smartparens)
 
+(defvar sp--javascript-modes '(
+                               js-mode
+                               javascript-mode
+                               js2-mode
+                               typescript-mode
+                               rjsx-mode
+                               js-ts-mode
+                               typescript-ts-mode
+                               tsx-ts-mode
+                               )
+  "List of JavaScript modes.")
+
 ;; (|sys).path.append---the dot should not travel with the closing
 ;; paren
-(--each '(
-          js-mode
-          javascript-mode
-          js2-mode
-          typescript-mode
-          rjsx-mode
-          js-ts-mode
-          typescript-ts-mode
-          tsx-ts-mode
-          )
+(--each sp--javascript-modes
   (add-to-list 'sp-sexp-suffix (list it 'regexp "")))
 
+(defun sp-javascript-skip-match-angle-bracket (ms mb _me)
+  "Non-nil if we should ignore the bracket as valid delimiter."
+  (and (string= ms ">") (= (char-before mb) ?=)))
+
+(sp-with-modes sp--javascript-modes
+  (sp-local-pair "<" ">"
+                 :skip-match 'sp-javascript-skip-match-angle-bracket))
+
 (provide 'smartparens-javascript)
 ;;; smartparens-javascript.el ends here
diff --git a/test/smartparens-javascript-test.el 
b/test/smartparens-javascript-test.el
index 73fcd6dd10..6e27d25476 100644
--- a/test/smartparens-javascript-test.el
+++ b/test/smartparens-javascript-test.el
@@ -43,3 +43,23 @@
   return |<a href=\"/\">Top</a>;
 }
 ")))
+
+(ert-deftest sp-test-javascript-skip-arrow-fn-bracket ()
+  "#872"
+  (sp-test-with-temp-buffer "|const test = () => {
+  console.log('test')
+}M"
+      (sp-test--javascript-mode)
+    (call-interactively 'sp-kill-region)
+    (should (equal (buffer-string) ""))))
+
+(ert-deftest sp-test-javascript-skip-arrow-fn-bracket-region-ok ()
+  "#872 The region should not be OK because it contains unclosed bracket.
+
+Before, the > character caused it to skip into the `console'
+token over the bracket and this made the region appear OK."
+  (sp-test-with-temp-buffer "|const test = () => {M
+  console.log('test')
+}"
+      (sp-test--javascript-mode)
+    (should (not (sp-region-ok-p (region-beginning) (region-end))))))

Reply via email to