[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/typescript-mode 330c887241 095/222: Fix indentation of fun
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/typescript-mode 330c887241 095/222: Fix indentation of functions with numbers in return type. |
Date: |
Sun, 6 Feb 2022 16:59:21 -0500 (EST) |
branch: elpa/typescript-mode
commit 330c887241cf585aa4e2e3f3e9d851f28b92b08e
Author: Louis-Dominique Dubeau <ldd@lddubeau.com>
Commit: Louis-Dominique Dubeau <ldd@lddubeau.com>
Fix indentation of functions with numbers in return type.
Prior to this commit, a function with a return type consisting of
numbers would not be indented properly. This commit fixes the issue.
---
typescript-mode-tests.el | 17 +++++++++++++++++
typescript-mode.el | 20 ++++++++++++++++++++
2 files changed, 37 insertions(+)
diff --git a/typescript-mode-tests.el b/typescript-mode-tests.el
index 45c43a0a83..da8f9a3aa8 100644
--- a/typescript-mode-tests.el
+++ b/typescript-mode-tests.el
@@ -99,6 +99,23 @@ a severity set to WARNING, no rule name."
(should (string-equal (nth 4 matches) "1"))
(should (string-equal (nth 5 matches) "83"))))
+(ert-deftest typescript--number-literal-re-matches-numbers ()
+ "`typescript--number-literal-re' matches numbers."
+ (dolist (to-match '("NaN" "Infinity" "-Infinity" "-1" "1" "0.1" ".1" "-.1"
"8e23"
+ "9E-2" ".1e23" "0b1" "-0B1" "0o7" "-0O13" "0xaf"
"-0XAF"))
+ (should (string-match typescript--number-literal-re to-match))
+ ;; The regular expression does not begin with ^ and end with $ so
+ ;; we need to check ourselves that the whole string is matched.
+ (should (string-equal (match-string 0 to-match) to-match))))
+
+(ert-deftest typescript--number-literal-re-does-not-match-non-numbers ()
+ "`typescript--number-literal-re' does not match non-numbers."
+ (dolist (to-match '("NaNa" "Inf" "1." "." "0xPQ" "e" "2.3e2.4"))
+ ;; For the same reason as for the positive test above, what we want is
either no match
+ ;; or a match that fails to match the whole string.
+ (should-not (and (string-match typescript--number-literal-re to-match)
+ (string-equal (match-string 0 to-match) to-match)))))
+
(ert-deftest correctly-indents-lines-with-wide-chars ()
"Otsuka Ai and other multi-char users should be a happy to write typescript."
diff --git a/typescript-mode.el b/typescript-mode.el
index 880aafba6e..e342e3e7bf 100644
--- a/typescript-mode.el
+++ b/typescript-mode.el
@@ -1963,6 +1963,21 @@ This performs fontification according to
`typescript--class-styles'."
(concat "[-+*/%<>=&^|?:.]\\([^-+*/]\\|$\\)\\|" typescript--indent-keyword-re)
"Regexp matching operators that affect indentation of continued
expressions.")
+;;
+;; We purposely do not allow the plus symbol as a prefix here, as this
+;; regex is used to check number literal in type annotations, and TS
+;; does not allow to use a plus symbol to prefix numbers there: you
+;; can use 1, but not +1 in a type annotation.
+;;
+;; This is meant to match NaN, floats, decimals, the two infinities
+;; and numbers recorded in binary, octal and hex.
+;;
+;; This regular expression was derived from:
+;; https://stackoverflow.com/a/30987109/
+;;
+(defconst typescript--number-literal-re
+
"\\(?:NaN\\|-?\\(?:0[Bb][01]+\\|0[Oo][0-7]+\\|0[Xx][0-9a-fA-F]+\\|Infinity\\|\\(?:[[:digit:]]*\\.[[:digit:]]+\\|[[:digit:]]+\\)\\(?:[Ee][+-]?[[:digit:]]+\\)?\\)\\)"
+ "Regexp that matches number literals.")
(defun typescript--looking-at-operator-p ()
"Return non-nil if point is on a typescript operator, other than a comma."
@@ -2159,6 +2174,11 @@ moved on success."
(condition-case nil
(backward-sexp)
(scan-error nil)))
+ ((looking-back typescript--number-literal-re
+ ;; We limit the search back to the previous
space or end of line (if possible)
+ ;; to prevent the search from going over the
whole buffer.
+ (save-excursion (re-search-backward
"\\(?:\\s-\\|\n\\)" nil t)) t)
+ (goto-char (match-beginning 0)))
;; Otherwise, we failed to find a location.
(t
(cl-return-from search-loop nil)))))
- [nongnu] elpa/typescript-mode 588d5f3d63 027/222: Update README.md, (continued)
- [nongnu] elpa/typescript-mode 588d5f3d63 027/222: Update README.md, ELPA Syncer, 2022/02/06
- [nongnu] elpa/typescript-mode f72826e564 036/222: Merge pull request #25 from ananthakumaran/revert-24-wrong-cursor-position, ELPA Syncer, 2022/02/06
- [nongnu] elpa/typescript-mode d5c4fb27c8 034/222: Merge pull request #24 from hekt/wrong-cursor-position, ELPA Syncer, 2022/02/06
- [nongnu] elpa/typescript-mode 447cfbc078 030/222: Improve compilation-mode support., ELPA Syncer, 2022/02/06
- [nongnu] elpa/typescript-mode b502d8453d 041/222: On second thought, lets NOT support Emacs 24.1 and 24.2., ELPA Syncer, 2022/02/06
- [nongnu] elpa/typescript-mode f25f4751fe 052/222: Merge pull request #31 from lddubeau/fix/spread-syntax, ELPA Syncer, 2022/02/06
- [nongnu] elpa/typescript-mode 2587e92851 047/222: Don't interpret class members as keywords., ELPA Syncer, 2022/02/06
- [nongnu] elpa/typescript-mode face381789 083/222: Implement clean make-target to assist local development., ELPA Syncer, 2022/02/06
- [nongnu] elpa/typescript-mode 20af0fec5f 077/222: Extend function prefix font-lock test to check arguments are correct., ELPA Syncer, 2022/02/06
- [nongnu] elpa/typescript-mode 5e2165d4b6 038/222: We need a Gitignore-file., ELPA Syncer, 2022/02/06
- [nongnu] elpa/typescript-mode 330c887241 095/222: Fix indentation of functions with numbers in return type.,
ELPA Syncer <=
- [nongnu] elpa/typescript-mode b7074c5dea 106/222: Remove redundant code, ELPA Syncer, 2022/02/06
- [nongnu] elpa/typescript-mode bf9a4155cc 043/222: Revise Emacs versions tested a little more., ELPA Syncer, 2022/02/06
- [nongnu] elpa/typescript-mode a3c91282bc 039/222: Add test-case and indentation-reference document., ELPA Syncer, 2022/02/06
- [nongnu] elpa/typescript-mode d29f31c791 045/222: Fix indentation of methods that are generators., ELPA Syncer, 2022/02/06
- [nongnu] elpa/typescript-mode e780858a86 050/222: Don't interpret spread syntax as a continuation., ELPA Syncer, 2022/02/06
- [nongnu] elpa/typescript-mode f3140123d6 067/222: Remove a leftover comment., ELPA Syncer, 2022/02/06
- [nongnu] elpa/typescript-mode aae70b59e6 023/222: Merge pull request #16 from wingyplus/add-as-and-from-keywords, ELPA Syncer, 2022/02/06
- [nongnu] elpa/typescript-mode 3766e37f24 026/222: Add README, ELPA Syncer, 2022/02/06
- [nongnu] elpa/typescript-mode f6907e8ae3 031/222: Fix error in compilation-mode alist registration., ELPA Syncer, 2022/02/06
- [nongnu] elpa/typescript-mode 316b018d27 040/222: Add CI-config and test-runner., ELPA Syncer, 2022/02/06