]> granicus.if.org Git - clang/commit
clang-format: [JS] improve calculateBraceType heuristic
authorMartin Probst <martin@probst.io>
Wed, 31 May 2017 09:29:40 +0000 (09:29 +0000)
committerMartin Probst <martin@probst.io>
Wed, 31 May 2017 09:29:40 +0000 (09:29 +0000)
commite22ee5cb65b1b69f0e48e949ab108fb467a20f97
tree57786487760d12961a7cbae5449ba33b57fcbc27
parenta7fae60ad9bddc322191668b3ddb0cb31e45b338
clang-format: [JS] improve calculateBraceType heuristic

Summary:

calculateBraceTypes decides for braced init for empty brace pairs ({}).
In context of a function declaration, this incorrectly classifies empty
function or method bodies as braced inits, leading to missing wraps:

    class C {
      foo() {}[bar]() {}
    }

Where code should have wrapped after "}", before "[". This change adds
another piece of contextual information in that braces following closing
parentheses must always be the opening braces of function blocks. This
fixes brace detection for methods immediately followed by brackets
(computed property declarations), but also curlies.

Reviewers: djasper

Subscribers: klimek, cfe-commits

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

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@304290 91177308-0d34-0410-b5e6-96231b3b80d8
lib/Format/UnwrappedLineParser.cpp
unittests/Format/FormatTestJS.cpp