From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Adam Niederer Newsgroups: gmane.emacs.devel Subject: Re: [PATCH] Update js-mode function heading regexes Date: Mon, 19 Jun 2017 03:04:59 -0400 Message-ID: <365dbefc-1dee-c7c6-e9d5-c5a3b6fd0a9d@gmail.com> References: <7ad22b11-406f-1193-c948-faaf01268710@gmail.com> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-Trace: blaine.gmane.org 1497881358 28188 195.159.176.226 (19 Jun 2017 14:09:18 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Mon, 19 Jun 2017 14:09:18 +0000 (UTC) User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.2.0 To: Dmitry Gutov , emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Mon Jun 19 16:09:10 2017 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dMxMZ-0006q9-TI for ged-emacs-devel@m.gmane.org; Mon, 19 Jun 2017 16:09:08 +0200 Original-Received: from localhost ([::1]:42852 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dMxMe-00069Z-WC for ged-emacs-devel@m.gmane.org; Mon, 19 Jun 2017 10:09:13 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:51475) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dMqkF-0005EL-JX for emacs-devel@gnu.org; Mon, 19 Jun 2017 03:05:08 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dMqkA-0001nC-K9 for emacs-devel@gnu.org; Mon, 19 Jun 2017 03:05:07 -0400 Original-Received: from mail-qt0-x235.google.com ([2607:f8b0:400d:c0d::235]:33959) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1dMqkA-0001ms-Fk for emacs-devel@gnu.org; Mon, 19 Jun 2017 03:05:02 -0400 Original-Received: by mail-qt0-x235.google.com with SMTP id c10so104157827qtd.1 for ; Mon, 19 Jun 2017 00:05:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=subject:to:references:from:message-id:date:user-agent:mime-version :in-reply-to:content-transfer-encoding:content-language; bh=owm+NzfmpiefjQqh+wK+ZGxrfQXU6kY0bkb2vNiPqME=; b=PqTV37qDsI9482td8LVgsJcJ3YB+evDA3OEVY3+0gHdtW8enIVs3fawjLOyv/uBgKf VoMz93X5QfF8y4l0PfQ16Bbr5GAE/gdaw2SZAasfZnav1dmwKPRX7NfCveP8VjUgYVli y/UwTZCKfVwUd9AjHGBU7XoXXi2EQyrAaENNAZi6b6TcJGzd+LXMvrFO3YI9JoHVT2Df VHtEk45oXyGA3FIPW26RZ64Lv0xpxbR5eN9jl+9pu/fTEWL8a+85/O34OLb9zngEI+3W +b/1D2qJGKrImKeAYmhTQ47QsPoQsGksekJDl7vpS8AMx7poGVs6HwghtJdFUwyItpKM /AoA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-transfer-encoding :content-language; bh=owm+NzfmpiefjQqh+wK+ZGxrfQXU6kY0bkb2vNiPqME=; b=IPytgDCFYauCWlgiIRDVL/MNYDAsbWONcAP0DiRcTW4lD1c19fi59Q9lI73Ue5FG9Q OXHeFDE2dKSYcPbjTUTZ89InZXHXqBTCfSvympbT5+hKkkvDJ2DRqor757qyy7d+Bkv8 PWZm0dHQNppkxVHEGASxRaxCMSJu/MWVNeUoTxDEPPZ38zBzRRPUvNGTbE1BSTGAais4 Owph1LpXxILgu4oBQB8Q4duexpeq/ZQVwY6StOcY2QC+QOu+0RfoP1gw2blbtqC8GTqd QdQLZKqaNnb+1aE2nERDYwYr+pPHtVk5fpNzpTp0yRMHpcaZxVVFDxxsI7FpZ2lf1lDP bpRw== X-Gm-Message-State: AKS2vOw7vfHhxpGw9vnMoFxoHSZzPueX9LZRT2/nyH1O2SI98Sepl/0f 32J0w+A5UhE9R/M3oBU= X-Received: by 10.200.38.142 with SMTP id 14mr26948201qto.237.1497855901288; Mon, 19 Jun 2017 00:05:01 -0700 (PDT) Original-Received: from [192.168.1.5] (pool-173-59-6-166.phlapa.fios.verizon.net. [173.59.6.166]) by smtp.gmail.com with ESMTPSA id u9sm6571446qtb.29.2017.06.19.00.05.00 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 19 Jun 2017 00:05:00 -0700 (PDT) In-Reply-To: Content-Language: en-US X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:400d:c0d::235 X-Mailman-Approved-At: Mon, 19 Jun 2017 10:08:59 -0400 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Original-Sender: "Emacs-devel" Xref: news.gmane.org gmane.emacs.devel:215777 Archived-At: > 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