[all-commits] [llvm/llvm-project] 4c9d69: clang-format: [JS] fix `??` opreator wrapping.

Martin Probst via All-commits all-commits at lists.llvm.org
Mon Jan 20 08:07:23 PST 2020


  Branch: refs/heads/master
  Home:   https://github.com/llvm/llvm-project
  Commit: 4c9d6914453d970b7b8202b7efd7524b2f0a72ac
      https://github.com/llvm/llvm-project/commit/4c9d6914453d970b7b8202b7efd7524b2f0a72ac
  Author: Martin Probst <martin at probst.io>
  Date:   2020-01-20 (Mon, 20 Jan 2020)

  Changed paths:
    M clang/lib/Format/FormatTokenLexer.cpp
    M clang/unittests/Format/FormatTestJS.cpp

  Log Message:
  -----------
  clang-format: [JS] fix `??` opreator wrapping.

Summary:
clang-format currently treats the nullish coalescing operator `??` like
the ternary operator. That causes multiple nullish terms to be each
indented relative to the last `??`, as they would in a ternary.

The `??` operator is often used in chains though, and as such more
similar to other binary operators, such as `||`. So to fix the indent,
set its token type to `||`, so it inherits the same treatment.

This opens up the question of operator precedence. However, `??` is
required to be parenthesized when mixed with `||` and `&&`, so this is
not a problem that can come up in syntactically legal code.

Reviewers: krasimir

Subscribers: cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D73026




More information about the All-commits mailing list