emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[nongnu] elpa/typescript-mode 2c43dd034c 068/222: Merge pull request #46


From: ELPA Syncer
Subject: [nongnu] elpa/typescript-mode 2c43dd034c 068/222: Merge pull request #46 from ananthakumaran/fix/union-type-in-return-annotation
Date: Sun, 6 Feb 2022 16:59:17 -0500 (EST)

branch: elpa/typescript-mode
commit 2c43dd034c156762589f80f7c6163a2bd35b51d0
Merge: 1cea84486f f3140123d6
Author: Louis-Dominique Dubeau <ldd@lddubeau.com>
Commit: GitHub <noreply@github.com>

    Merge pull request #46 from 
ananthakumaran/fix/union-type-in-return-annotation
---
 test-files/indentation-reference-document.ts |  7 +++++++
 typescript-mode.el                           | 31 ++++++++++++++--------------
 2 files changed, 23 insertions(+), 15 deletions(-)

diff --git a/test-files/indentation-reference-document.ts 
b/test-files/indentation-reference-document.ts
index d6e3124f0f..2fdf6ef337 100644
--- a/test-files/indentation-reference-document.ts
+++ b/test-files/indentation-reference-document.ts
@@ -282,6 +282,13 @@ function bif(a: number,
     return "abc):d";
 }
 
+// Generic and union in return type. This case was constructed from
+// a specific bug in the indentation code.
+function bif2(a: number,
+              b: number): Array<number> | number {
+    return 1;
+}
+
 // Comment where the return type would appear.
 function gogo(a: number,
               b: number) /* foo */ {
diff --git a/typescript-mode.el b/typescript-mode.el
index 4b091fa64d..7c9676be87 100644
--- a/typescript-mode.el
+++ b/typescript-mode.el
@@ -1808,18 +1808,24 @@ moved on success."
           (save-excursion
             (loop named search-loop
                   do (progn
-                       (if (eq (char-before) ?>)
-                           (if (looking-back "=>" (- (point) 2))
-                               ;; Move back over the arrow of an arrow 
function.
-                               (backward-char 2)
-                             ;; Otherwise, we are looking at the end of the 
parameters
-                             ;; list of a generic. We need to move back over 
the list.
-                             (backward-char)
-                             
(typescript--backward-over-generic-parameter-list))
-                         ;; General case: we just move back over the current 
sexp.
+                       (cond
+                        ;; Looking at the arrow of an arrow function:
+                        ;; move back over the arrow.
+                        ((looking-back "=>" (- (point) 2))
+                         (backward-char 2))
+                        ;; Looking at the end of the parameters list
+                        ;; of a generic: move back over the list.
+                        ((eq (char-before) ?>)
+                         (backward-char)
+                         (typescript--backward-over-generic-parameter-list))
+                        ;; Looking at a union: skip over the character.
+                        ((eq (char-before) ?|)
+                         (backward-char))
+                        ;; General case: we just move back over the current 
sexp.
+                        (t
                          (condition-case nil
                              (backward-sexp)
-                           (scan-error nil)))
+                           (scan-error nil))))
                        (typescript--backward-syntactic-ws)
                        (let ((before (char-before)))
                          ;; Check whether we are at "):".
@@ -1884,11 +1890,6 @@ moved on success."
                    (when (or (typescript--backward-to-parameter-list)
                              (eq (char-before) ?\)))
                      (backward-list))
-                   ;; If the parameter list is preceded by (, take the
-                   ;; start of the parameter list as our reference.
-                   ;; This allows handling functions in parameter
-                   ;; lists. Otherwise, we want to go back to the
-                   ;; start of function declaration.
                    (back-to-indentation)
                    (cond (same-indent-p
                           (current-column))



reply via email to

[Prev in Thread] Current Thread [Next in Thread]