[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Emacs-diffs] feature/jsx 79118f8 16/19: Fix counting of nested self-clo
From: |
Marcin Borkowski |
Subject: |
[Emacs-diffs] feature/jsx 79118f8 16/19: Fix counting of nested self-closing JSXOpeningElements |
Date: |
Wed, 27 Mar 2019 05:35:02 -0400 (EDT) |
branch: feature/jsx
commit 79118f8c70e7404aedd7e2d62e846921898c6274
Author: Jackson Ray Hamilton <address@hidden>
Commit: Marcin Borkowski <address@hidden>
Fix counting of nested self-closing JSXOpeningElements
* lisp/progmodes/js.el (js-jsx--matching-close-tag-pos): Fix bug where
self-closing JSXOpeningElements might be missed if one was nested
within another.
* test/manual/indent/jsx-self-closing.jsx: Add test for bug concerning
self-closing JSXOpeningElement counting.
---
lisp/progmodes/js.el | 39 ++++++++++++---------------------
test/manual/indent/jsx-self-closing.jsx | 13 +++++++++++
2 files changed, 27 insertions(+), 25 deletions(-)
diff --git a/lisp/progmodes/js.el b/lisp/progmodes/js.el
index f8dd72c..f22c68c 100644
--- a/lisp/progmodes/js.el
+++ b/lisp/progmodes/js.el
@@ -1934,40 +1934,29 @@ Assuming a JSXOpeningElement or a JSXOpeningFragment is
immediately before point, find a matching JSXClosingElement or
JSXClosingFragment, skipping over any nested JSXElements to find
the match. Return nil if a match can’t be found."
- (let ((tag-stack 1) self-closing-pos type)
+ (let ((tag-stack 1) type tag-pos last-pos pos)
(catch 'stop
(while (re-search-forward js-jsx--tag-re nil t)
- (setq type (js-jsx--matched-tag-type))
- ;; Balance the total of self-closing tags that we subtract
- ;; from the stack, ignoring those tags which are never added
- ;; to the stack (see below).
- (unless (eq type 'self-closing)
- (when (and self-closing-pos (> (point) self-closing-pos))
+ (setq type (js-jsx--matched-tag-type)
+ tag-pos (match-beginning 0))
+ ;; Clear the stack of any JSXOpeningElements which turned out
+ ;; to be self-closing.
+ (when last-pos
+ (setq pos (point))
+ (goto-char last-pos)
+ (while (re-search-forward js-jsx--self-closing-re pos 'move)
(setq tag-stack (1- tag-stack))))
(if (eq type 'close)
(progn
(setq tag-stack (1- tag-stack))
(when (= tag-stack 0)
- (throw 'stop (match-beginning 0))))
- ;; Tags that we know are self-closing aren’t added to the
- ;; stack at all, because we only close the ones that we have
- ;; anticipated after moving past those anticipated tags’
- ;; ends, and if a self-closing tag is the first tag we
- ;; encounter in this loop, then it will never be anticipated
- ;; (due to an optimization where we sometimes can avoid
- ;; looking for self-closing tags).
+ (throw 'stop tag-pos)))
+ ;; JSXOpeningElements that we know are self-closing aren’t
+ ;; added to the stack at all (since re-search-forward moves
+ ;; point after their self-closing syntax).
(unless (eq type 'self-closing)
(setq tag-stack (1+ tag-stack))))
- ;; Don’t needlessly recalculate.
- (unless (and self-closing-pos (<= (point) self-closing-pos))
- (setq self-closing-pos nil) ; Reset if recalculating.
- (save-excursion
- ;; Anticipate a self-closing tag that we should make sure
- ;; to subtract from the tag stack once we move past its
- ;; end; we might might miss the end otherwise, due to the
- ;; regexp-matching method we use to detect tags.
- (when (re-search-forward js-jsx--self-closing-re nil t)
- (setq self-closing-pos (match-beginning 0)))))))))
+ (setq last-pos (point))))))
(defun js-jsx--enclosing-curly-pos ()
"Return position of enclosing “{” in a “{/}” pair about point."
diff --git a/test/manual/indent/jsx-self-closing.jsx
b/test/manual/indent/jsx-self-closing.jsx
new file mode 100644
index 0000000..f8ea7a1
--- /dev/null
+++ b/test/manual/indent/jsx-self-closing.jsx
@@ -0,0 +1,13 @@
+// Local Variables:
+// indent-tabs-mode: nil
+// js-indent-level: 2
+// End:
+
+// The following test goes below any comments to avoid including
+// misindented comments among the erroring lines.
+
+// Properly parse/indent code with a self-closing tag inside the
+// attribute of another self-closing tag.
+<div>
+ <div attr={() => <div attr="" />} />
+</div>
- [Emacs-diffs] feature/jsx 754f826 01/19: Add failing tests for JSX indentation bugs, (continued)
- [Emacs-diffs] feature/jsx 754f826 01/19: Add failing tests for JSX indentation bugs, Marcin Borkowski, 2019/03/27
- [Emacs-diffs] feature/jsx 91c29fb 09/19: Update expectations for JSX indentation in JSXAttribute space, Marcin Borkowski, 2019/03/27
- [Emacs-diffs] feature/jsx 539191c 07/19: Font-lock JSX while editing it by extending regions, Marcin Borkowski, 2019/03/27
- [Emacs-diffs] feature/jsx 79954c6 05/19: Use js-jsx- prefix for functions and variables, Marcin Borkowski, 2019/03/27
- [Emacs-diffs] feature/jsx acab35c 19/19: Add tests for miscellaneous JSX parsing feats, Marcin Borkowski, 2019/03/27
- [Emacs-diffs] feature/jsx e196207 15/19: Indent broken arrow function bodies as an N+1th arg, Marcin Borkowski, 2019/03/27
- [Emacs-diffs] feature/jsx 071c134 06/19: Add basic JSX font-locking, Marcin Borkowski, 2019/03/27
- [Emacs-diffs] feature/jsx ec144e9 12/19: Automatically detect JSX in JavaScript files, Marcin Borkowski, 2019/03/27
- [Emacs-diffs] feature/jsx c66bfa6 10/19: Indent JSX as parsed in a JS context, Marcin Borkowski, 2019/03/27
- [Emacs-diffs] feature/jsx f7ac5e4 11/19: Finish replacing SGML-based JSX detection with js-mode’s parsing, Marcin Borkowski, 2019/03/27
- [Emacs-diffs] feature/jsx 79118f8 16/19: Fix counting of nested self-closing JSXOpeningElements,
Marcin Borkowski <=
- [Emacs-diffs] feature/jsx 4337acd 14/19: Rename tests to use the “.jsx” file extension, Marcin Borkowski, 2019/03/27
- [Emacs-diffs] feature/jsx 66433fd 13/19: Improve JSX syntax propertization, Marcin Borkowski, 2019/03/27
- [Emacs-diffs] feature/jsx ae0ee9b 18/19: Split JSX indentation calculation into several functions, Marcin Borkowski, 2019/03/27
- [Emacs-diffs] feature/jsx 2b4cc70 17/19: Indent expressions in JSXAttributes relative to the attribute’s name, Marcin Borkowski, 2019/03/27
- [Emacs-diffs] feature/jsx d5dae48 02/19: Refactor JSX indentation code to improve enclosing JSX discovery, Marcin Borkowski, 2019/03/27
- [Emacs-diffs] feature/jsx 7166bd2 08/19: Propertize and font-lock JSXText and JSXExpressionContainers, Marcin Borkowski, 2019/03/27
- [Emacs-diffs] feature/jsx 85fccaf 04/19: js-syntax-propertize: Disambiguate JS from JSX, fixing some indents, Marcin Borkowski, 2019/03/27