From 6354e3c3368d99fad755d4dbd7c872ce1280f005 Mon Sep 17 00:00:00 2001 From: Dmitry Gutov Date: Thu, 13 Apr 2017 03:50:41 +0300 Subject: [PATCH] Handle indentation of nested ternary operators in JS * lisp/progmodes/js.el (js--looking-at-operator-p): Handle nested ternary operators. --- lisp/progmodes/js.el | 2 ++ test/manual/indent/js.js | 7 +++++++ 2 files changed, 9 insertions(+) diff --git a/lisp/progmodes/js.el b/lisp/progmodes/js.el index c220353e9b7..bae9e52bf0f 100644 --- a/lisp/progmodes/js.el +++ b/lisp/progmodes/js.el @@ -1788,6 +1788,8 @@ This performs fontification according to `js--class-styles'." (and (looking-at js--indent-operator-re) (or (not (eq (char-after) ?:)) (save-excursion + (js--backward-syntactic-ws) + (when (= (char-before) ?\)) (backward-list)) (and (js--re-search-backward "[?:{]\\|\\_" nil t) (eq (char-after) ??)))) (not (and diff --git a/test/manual/indent/js.js b/test/manual/indent/js.js index 846c3a1a5c2..1ad76a83e18 100644 --- a/test/manual/indent/js.js +++ b/test/manual/indent/js.js @@ -128,6 +128,13 @@ if (x > 72 && let x = svg.mumble() .zzz; +// https://github.com/mooz/js2-mode/issues/405 +if (1) { + isSet + ? (isEmpty ? 2 : 3) + : 4 +} + // Local Variables: // indent-tabs-mode: nil // js-indent-level: 2