[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/typescript-mode 813cf4fef3 069/222: Fix endless loop (hang
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/typescript-mode 813cf4fef3 069/222: Fix endless loop (hang) in indentation-code. |
Date: |
Sun, 6 Feb 2022 16:59:18 -0500 (EST) |
branch: elpa/typescript-mode
commit 813cf4fef30d95d055268c06afaf61b4b4f49878
Author: Jostein Kjønigsen <jostein@kjonigsen.net>
Commit: Jostein Kjønigsen <jostein@kjonigsen.net>
Fix endless loop (hang) in indentation-code.
Tests.
This closes https://github.com/ananthakumaran/typescript.el/issues/20.
---
typescript-mode-tests.el | 35 +++++++++++++++++++++++++++++++++++
typescript-mode.el | 29 ++++++++++++-----------------
2 files changed, 47 insertions(+), 17 deletions(-)
diff --git a/typescript-mode-tests.el b/typescript-mode-tests.el
index 000e9b3484..ad69c1736e 100644
--- a/typescript-mode-tests.el
+++ b/typescript-mode-tests.el
@@ -130,6 +130,41 @@ a severity set to WARNING, no rule name."
(forward-char 1)
(should (= 8 (current-column)))))
+(ert-deftest indentation-does-not-hang-on-multiline-string ()
+ "Testcase for https://github.com/ananthakumaran/typescript.el/issues/20"
+
+ (with-temp-buffer
+ (typescript-mode)
+
+ (insert "let multiLineString = \"line 1")
+ (newline-and-indent)
+ (insert "// and so we continue")
+ (newline-and-indent)
+ ;; completing and not locking up is test-success!
+ ))
+
+(defun test-re-search (searchee contents offset)
+ (with-temp-buffer
+ (typescript-mode)
+
+ (insert contents)
+ (goto-char (- (point-max) offset))
+
+ (should (= 5 (typescript--re-search-backward-inner searchee nil 1)))))
+
+(ert-deftest re-search-backwards-skips-single-line-strings ()
+ (test-re-search "token" "let token = \"token in string-thing\";" 2))
+
+(ert-deftest re-search-backwards-skips-multi-line-strings ()
+ (test-re-search "token" "let token = \"token in\n multi-line token
string\";" 2))
+
+(ert-deftest re-search-backwards-skips-single-line-comments ()
+ (test-re-search "token" "let token; // token in comment" 0))
+
+(ert-deftest re-search-backwards-skips-multi-line-comments ()
+ (test-re-search "token" "let token; /* token in \nmulti-line token comment"
0))
+
+
(provide 'typescript-mode-tests)
;;; typescript-mode-tests.el ends here
diff --git a/typescript-mode.el b/typescript-mode.el
index 7c9676be87..7a7b57fc2c 100644
--- a/typescript-mode.el
+++ b/typescript-mode.el
@@ -691,7 +691,6 @@ macro as normal text."
(defun typescript--re-search-backward-inner (regexp &optional bound count)
"Auxiliary function for `typescript--re-search-backward'."
(let ((parse)
- str-terminator
(orig-macro-start
(save-excursion
(and (typescript--beginning-of-macro)
@@ -702,22 +701,18 @@ macro as normal text."
(save-excursion (backward-char) (looking-at "/[/*]")))
(forward-char))
(setq parse (syntax-ppss))
- (cond ((setq str-terminator (nth 3 parse))
- (when (eq str-terminator t)
- (setq str-terminator ?/))
- (re-search-backward
- (concat "\\([^\\]\\|^\\)" (string str-terminator))
- (save-excursion (beginning-of-line) (point)) t))
- ((nth 7 parse)
- (goto-char (nth 8 parse)))
- ((or (nth 4 parse)
- (and (eq (char-before) ?/) (eq (char-after) ?*)))
- (re-search-backward "/\\*"))
- ((and (not (and orig-macro-start
- (>= (point) orig-macro-start)))
- (typescript--beginning-of-macro)))
- (t
- (setq count (1- count))))))
+ (cond
+ ;; If we are in a comment or a string, jump back to the start
+ ;; of the comment or string.
+ ((nth 8 parse)
+ (goto-char (nth 8 parse)))
+ ((and (eq (char-before) ?/) (eq (char-after) ?*))
+ (re-search-backward "/\\*"))
+ ((and (not (and orig-macro-start
+ (>= (point) orig-macro-start)))
+ (typescript--beginning-of-macro)))
+ (t
+ (setq count (1- count))))))
(point))
- [nongnu] elpa/typescript-mode 7d80174b23 216/222: Skip past ? and ! in typescript--compute-member-expression-indent, (continued)
- [nongnu] elpa/typescript-mode 7d80174b23 216/222: Skip past ? and ! in typescript--compute-member-expression-indent, ELPA Syncer, 2022/02/06
- [nongnu] elpa/typescript-mode 6918f3f6d7 212/222: Merge pull request #154 from emacs-typescript/feature/build-tasks, ELPA Syncer, 2022/02/06
- [nongnu] elpa/typescript-mode 13e6da6c57 219/222: Merge pull request #157 from rsimoes/patch-1, ELPA Syncer, 2022/02/06
- [nongnu] elpa/typescript-mode a6e0eac105 029/222: Fix wrong cursor position in `typescript-indent-line`, ELPA Syncer, 2022/02/06
- [nongnu] elpa/typescript-mode 0f41709e15 074/222: Fontify @type properly and allow jsdoc one-liners., ELPA Syncer, 2022/02/06
- [nongnu] elpa/typescript-mode 90d9758cfb 035/222: Revert "Fix wrong cursor position in `typescript-indent-line`", ELPA Syncer, 2022/02/06
- [nongnu] elpa/typescript-mode 1cea84486f 064/222: Merge pull request #35 from lddubeau/feature/indent-return-annotations, ELPA Syncer, 2022/02/06
- [nongnu] elpa/typescript-mode 9ad892fb22 061/222: Add keyword 'object', ELPA Syncer, 2022/02/06
- [nongnu] elpa/typescript-mode e3d2fee6de 004/222: unnecessary for single package file, ELPA Syncer, 2022/02/06
- [nongnu] elpa/typescript-mode 7e8b9641ae 096/222: Mark typescript indent variables as safe for file local customizations, ELPA Syncer, 2022/02/06
- [nongnu] elpa/typescript-mode 813cf4fef3 069/222: Fix endless loop (hang) in indentation-code.,
ELPA Syncer <=
- [nongnu] elpa/typescript-mode cebfe5952b 114/222: Rename the regexp matching pretty error messages., ELPA Syncer, 2022/02/06
- [nongnu] elpa/typescript-mode 5d5c611e2d 119/222: Add tags in js2-mode, ELPA Syncer, 2022/02/06
- [nongnu] elpa/typescript-mode e608305ade 137/222: checkdoc fixes, ELPA Syncer, 2022/02/06
- [nongnu] elpa/typescript-mode 85504ce34b 138/222: Update build-badge URL., ELPA Syncer, 2022/02/06
- [nongnu] elpa/typescript-mode f6330f420e 144/222: Add a test for #107., ELPA Syncer, 2022/02/06
- [nongnu] elpa/typescript-mode c1aa1b2e7d 149/222: add better generics highlighting, ELPA Syncer, 2022/02/06
- [nongnu] elpa/typescript-mode 1bafd279cf 148/222: Enable more colors (#110), ELPA Syncer, 2022/02/06
- [nongnu] elpa/typescript-mode 607897d583 151/222: Update Emacs Git to Xenial-build, ELPA Syncer, 2022/02/06
- [nongnu] elpa/typescript-mode 42b366e669 153/222: Merge pull request #111 from tam5/master, ELPA Syncer, 2022/02/06
- [nongnu] elpa/typescript-mode 2405090403 152/222: Handle CI-failures correctly., ELPA Syncer, 2022/02/06