diff options
author | Daniel Jasper <djasper@google.com> | 2015-06-10 09:21:09 +0000 |
---|---|---|
committer | Daniel Jasper <djasper@google.com> | 2015-06-10 09:21:09 +0000 |
commit | 11ca263994f20678fc30c7f18f4768d13390b5e4 (patch) | |
tree | 1d77055e3ac57cb739550bdbf7b1427a1e187b56 /clang/lib | |
parent | ef40f0bbff6bdded23b2e14326cd4d6ea3187f13 (diff) | |
download | bcm5719-llvm-11ca263994f20678fc30c7f18f4768d13390b5e4.tar.gz bcm5719-llvm-11ca263994f20678fc30c7f18f4768d13390b5e4.zip |
clang-format: [JS] Only special case top level object literal
assignments as enums.
Top level object literals are treated as enums, and their k/v pairs are put on
separate lines:
X.Y = {
A: 1,
B: 2
};
However assignments within blocks should not be affected:
function x() {
y = {a:1, b:2};
}
This change fixes the second case. Patch by Martin Probst.
llvm-svn: 239462
Diffstat (limited to 'clang/lib')
-rw-r--r-- | clang/lib/Format/TokenAnnotator.cpp | 7 |
1 files changed, 4 insertions, 3 deletions
diff --git a/clang/lib/Format/TokenAnnotator.cpp b/clang/lib/Format/TokenAnnotator.cpp index 78e6103bfcd..8f2b608afb3 100644 --- a/clang/lib/Format/TokenAnnotator.cpp +++ b/clang/lib/Format/TokenAnnotator.cpp @@ -2088,13 +2088,14 @@ 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.Previous && + Line.Level == 0 && Left.Previous && Left.Previous->is(tok::equal) && Line.First->isOneOf(tok::identifier, Keywords.kw_import, - tok::kw_export) && + tok::kw_export, tok::kw_const) && // kw_var is a pseudo-token that's a tok::identifier, so matches above. !Line.First->is(Keywords.kw_var)) - // Enum style object literal. + // Object literals on the top level of a file are treated as "enum-style". + // Each key/value pair is put on a separate line, instead of bin-packing. return true; } else if (Style.Language == FormatStyle::LK_Java) { if (Right.is(tok::plus) && Left.is(tok::string_literal) && Right.Next && |