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

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

[nongnu] elpa/typescript-mode 2573266955 086/222: Fix a bug in handling


From: ELPA Syncer
Subject: [nongnu] elpa/typescript-mode 2573266955 086/222: Fix a bug in handling function return type annotations.
Date: Sun, 6 Feb 2022 16:59:20 -0500 (EST)

branch: elpa/typescript-mode
commit 257326695531eb3320403a8624b7179b71fd1103
Author: Louis-Dominique Dubeau <ldd@lddubeau.com>
Commit: Louis-Dominique Dubeau <ldd@lddubeau.com>

    Fix a bug in handling function return type annotations.
    
    The algorithm would work fine indenting the line after the curly brace
    in "function foo(): ((a: X) => void) {" but if the parentheses around
    the return type were missing, the algorithm would go astray. This
    commit fixes the problem.
---
 test-files/indentation-reference-document.ts |  6 ++++++
 typescript-mode.el                           | 11 +++++++++--
 2 files changed, 15 insertions(+), 2 deletions(-)

diff --git a/test-files/indentation-reference-document.ts 
b/test-files/indentation-reference-document.ts
index 16522752b0..12c7d843d0 100644
--- a/test-files/indentation-reference-document.ts
+++ b/test-files/indentation-reference-document.ts
@@ -252,6 +252,12 @@ function moo(x: any,
     return null;
 }
 
+// No parens around return type.
+function moo2(x: any,
+              f: string): (a: number) => void {
+    return null;
+}
+
 // Parens around return type.
 function foo(x: any,
              f: string): ((a: number) => void) {
diff --git a/typescript-mode.el b/typescript-mode.el
index 6497d3b7cd..947d410929 100644
--- a/typescript-mode.el
+++ b/typescript-mode.el
@@ -2060,10 +2060,17 @@ moved on success."
             (loop named search-loop
                   do (progn
                        (cond
-                        ;; Looking at the arrow of an arrow function:
+                        ;; Looking at the arrow of a function definition:
                         ;; move back over the arrow.
                         ((looking-back "=>" (- (point) 2))
-                         (backward-char 2))
+                         (backward-char 2)
+                         (typescript--backward-syntactic-ws)
+                         ;; Immediately handle a parenthesized list of 
arguments. Otherwise, the
+                         ;; algorithm here will go astray.
+                         (when (eq (char-before) ?\))
+                           (condition-case nil
+                               (backward-sexp)
+                             (scan-error nil))))
                         ;; Looking at the end of the parameters list
                         ;; of a generic: move back over the list.
                         ((eq (char-before) ?>)



reply via email to

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