[all-commits] [llvm/llvm-project] 2b30bd: clang-format: [JS] do not collapse - - to --.

Martin Probst via All-commits all-commits at lists.llvm.org
Tue Mar 30 05:32:37 PDT 2021


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: 2b30bd2be0a898d0e7cb9eb3f2cf0e0efeaa83e9
      https://github.com/llvm/llvm-project/commit/2b30bd2be0a898d0e7cb9eb3f2cf0e0efeaa83e9
  Author: Martin Probst <martin at probst.io>
  Date:   2021-03-30 (Tue, 30 Mar 2021)

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

  Log Message:
  -----------
  clang-format: [JS] do not collapse - - to --.

In JavaScript, `- -1;` is legal syntax, the language allows unary minus.
However the two tokens must not collapse together: `--1` is prefix
decrement, i.e. different syntax.

Before:

    - -1; ==> --1;

After:

    - -1; ==> - -1;

This change makes no attempt to format this "nicely", given by all
likelihood this represents a programming mistake by the user, or odd
generated code.

The check is not guarded by language: this appears to be a problem in
Java as well, and will also be beneficial when formatting syntactically
incorrect C++ (e.g. during editing).

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




More information about the All-commits mailing list