diff options
author | Daniel Jasper <djasper@google.com> | 2015-03-15 13:55:54 +0000 |
---|---|---|
committer | Daniel Jasper <djasper@google.com> | 2015-03-15 13:55:54 +0000 |
commit | 60948b12bb91dc38750d3a75c81d79edb86eda86 (patch) | |
tree | a289a37b8e5d9c227e2dda9126261b5587973c1b /clang/lib/Format | |
parent | 482284a8853c56ebd61dc9a7906be0fbd02b255d (diff) | |
download | bcm5719-llvm-60948b12bb91dc38750d3a75c81d79edb86eda86.tar.gz bcm5719-llvm-60948b12bb91dc38750d3a75c81d79edb86eda86.zip |
clang-format: [JS] more precisely detect enums.
The current enum detection is overly aggressive. As NestingLevel only
applies per line (?) it classifies many if not most object literals as
enum declarations and adds superfluous line breaks into them. This
change narrows the heuristic by requiring an assignment just before the
open brace and requiring the line to start with an identifier.
Patch by Martin Probst. Thank you.
llvm-svn: 232320
Diffstat (limited to 'clang/lib/Format')
-rw-r--r-- | clang/lib/Format/TokenAnnotator.cpp | 8 |
1 files changed, 7 insertions, 1 deletions
diff --git a/clang/lib/Format/TokenAnnotator.cpp b/clang/lib/Format/TokenAnnotator.cpp index caca6458df4..c6c81a48912 100644 --- a/clang/lib/Format/TokenAnnotator.cpp +++ b/clang/lib/Format/TokenAnnotator.cpp @@ -1952,7 +1952,13 @@ bool TokenAnnotator::mustBreakBefore(const AnnotatedLine &Line, Left.Previous->is(tok::char_constant)) return true; if (Left.is(TT_DictLiteral) && Left.is(tok::l_brace) && - Left.NestingLevel == 0) + Left.NestingLevel == 0 && Left.Previous && + Left.Previous->is(tok::equal) && + Line.First->isOneOf(tok::identifier, Keywords.kw_import, + tok::kw_export) && + // kw_var is a pseudo-token that's a tok::identifier, so matches above. + !Line.First->is(Keywords.kw_var)) + // Enum style object literal. return true; } else if (Style.Language == FormatStyle::LK_Java) { if (Right.is(tok::plus) && Left.is(tok::string_literal) && Right.Next && |