Skip to content

Commit db51cc5

Browse files
committedAug 1, 2017
clang-format: [JS] consistenly format enums.
Summary: Previously, const enums would get formatted differently because the modifier was not recognized. Reviewers: djasper Subscribers: klimek, cfe-commits Differential Revision: https://reviews.llvm.org/D36144 llvm-svn: 309703
1 parent 2b89c14 commit db51cc5

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed
 

‎clang/lib/Format/TokenAnnotator.cpp

+3-1
Original file line numberDiff line numberDiff line change
@@ -2517,7 +2517,9 @@ bool TokenAnnotator::mustBreakBefore(const AnnotatedLine &Line,
25172517
return true;
25182518
if (Left.is(tok::l_brace) && Line.Level == 0 &&
25192519
(Line.startsWith(tok::kw_enum) ||
2520-
Line.startsWith(tok::kw_export, tok::kw_enum)))
2520+
Line.startsWith(tok::kw_const, tok::kw_enum) ||
2521+
Line.startsWith(tok::kw_export, tok::kw_enum) ||
2522+
Line.startsWith(tok::kw_export, tok::kw_const, tok::kw_enum)))
25212523
// JavaScript top-level enum key/value pairs are put on separate lines
25222524
// instead of bin-packing.
25232525
return true;

‎clang/unittests/Format/FormatTestJS.cpp

+8
Original file line numberDiff line numberDiff line change
@@ -1425,6 +1425,14 @@ TEST_F(FormatTestJS, EnumDeclarations) {
14251425
" B\n"
14261426
"}\n"
14271427
"var x = 1;");
1428+
verifyFormat("const enum Foo {\n"
1429+
" A = 1,\n"
1430+
" B\n"
1431+
"}");
1432+
verifyFormat("export const enum Foo {\n"
1433+
" A = 1,\n"
1434+
" B\n"
1435+
"}");
14281436
}
14291437

14301438
TEST_F(FormatTestJS, MetadataAnnotations) {

0 commit comments

Comments
 (0)
Please sign in to comment.