From: Adam Niederer <adam.niederer@gmail.com>
To: Dmitry Gutov <dgutov@yandex.ru>, emacs-devel@gnu.org
Subject: Re: [PATCH] Update js-mode function heading regexes
Date: Mon, 19 Jun 2017 03:04:59 -0400 [thread overview]
Message-ID: <365dbefc-1dee-c7c6-e9d5-c5a3b6fd0a9d@gmail.com> (raw)
In-Reply-To: <b377e066-067b-a681-e858-2b32c1a561a3@yandex.ru>
> These are manual tests, right? 'make check' doesn't sound relevant.
> But we have some automated tests for js.el too. Check out
> test/lisp/progmodes/js-tests.el. Maybe these scenarios would be better
> coded with ERT.
The file I included was primarily for visual evaluation of the changes.
Adding some automated tests is a good idea, though, so I've included an
updated patchset below. This also makes js--function-heading-2-re work
on async functions.
> Not much. Patch submissions via the bug tracker have higher odds of
> not being forgotten is they're not applied right away, though.
>
> Thanks for the patch.
Would reposting these changes to bug-gnu-emacs be a good idea?
Thanks a lot,
-Adam
--- a/lisp/progmodes/js.el
+++ b/lisp/progmodes/js.el
@@ -250,20 +250,20 @@ js--available-frameworks
(defconst js--function-heading-1-re
(concat
- "^\\s-*function\\(?:\\s-\\|\\*\\)+\\(" js--name-re "\\)")
+ "^\\s-*\\(?:async\\s-+\\)?function\\(?:\\s-\\|\\*\\)+\\("
js--name-re "\\)")
"Regexp matching the start of a JavaScript function header.
Match group 1 is the name of the function.")
(defconst js--function-heading-2-re
(concat
- "^\\s-*\\(" js--name-re "\\)\\s-*:\\s-*function\\_>")
+ "^.*?\\(" js--name-re "\\)\\s-*:\\s-*\\(?:async\\s-+\\)?function\\_>")
"Regexp matching the start of a function entry in an associative array.
Match group 1 is the name of the function.")
(defconst js--function-heading-3-re
(concat
- "^\\s-*\\(?:var\\s-+\\)?\\(" js--dotted-name-re "\\)"
- "\\s-*=\\s-*function\\_>")
+ "^\\s-*\\(?:\\(?:var\\|let\\|const\\)\\s-+\\)?\\("
js--dotted-name-re "\\)"
+ "\\s-*=\\s-*\\(?:async\\s-+\\)?function\\_>")
"Regexp matching a line in the JavaScript form \"var MUMBLE = function\".
Match group 1 is MUMBLE.")
diff --git a/test/lisp/progmodes/js-tests.el
b/test/lisp/progmodes/js-tests.el
index 8e1bac10cd..313e2e2e52 100644
--- a/test/lisp/progmodes/js-tests.el
+++ b/test/lisp/progmodes/js-tests.el
@@ -177,6 +177,44 @@
;; The bug was a hang.
(should t)))
+(ert-deftest js-mode-highlight-function-names ()
+ "Ensure js--function-heading-1-re and js--function-heading-2-re match all
+possible function declarations and highlight the function names
accordingly."
+ (with-temp-buffer
+ (js-mode)
+ (insert "function foo() {}\n"
+ "async function bar() {}\n"
+ "let x = [{ baz: function() {}\n"
+ " quux: function() {}\n"
+ " kek: async function() {}\n"
+ "/**/ bur: async function() {} }]\n")
+ (font-lock-ensure)
+ (dolist (name '("foo" "bar" "baz" "quux" "kek" "bur"))
+ (save-excursion
+ (search-backward name)
+ (should (equal (face-at-point) font-lock-function-name-face))))))
+
+(ert-deftest js-mode-accept-function-bindings ()
+ "Ensure js--function-heading-3-re matches all function declarations
of the
+form (var|let|const) foo = (async)? function."
+ (with-temp-buffer
+ (js-mode)
+ (insert "var foo = async function() {}\n"
+ "const bar = async function() {}\n"
+ "let baz = async function() {}\n"
+ "var quux = function() {}\n"
+ "const kek = function() {}\n"
+ "let bur = function() {}\n")
+ (dolist (name '("foo" "bar" "baz" "quux" "kek" "bur"))
+ ;; re-search-backward will throw if one the strings doesn't match.
+ (re-search-backward js--function-heading-3-re))
+ ;; Ensure we have exactly six matches
+ (should-error (re-search-backward js--function-heading-3-re))))
+
(provide 'js-tests)
;;; js-tests.el ends here
next prev parent reply other threads:[~2017-06-19 7:04 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-06-17 7:30 [PATCH] Update js-mode function heading regexes Adam Niederer
2017-06-18 23:59 ` Dmitry Gutov
2017-06-19 7:04 ` Adam Niederer [this message]
2017-09-28 21:02 ` Dmitry Gutov
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=365dbefc-1dee-c7c6-e9d5-c5a3b6fd0a9d@gmail.com \
--to=adam.niederer@gmail.com \
--cc=dgutov@yandex.ru \
--cc=emacs-devel@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).