]> granicus.if.org Git - clang/commitdiff
clang-format: [JS] consistenly format enums.
authorMartin Probst <martin@probst.io>
Tue, 1 Aug 2017 17:12:15 +0000 (17:12 +0000)
committerMartin Probst <martin@probst.io>
Tue, 1 Aug 2017 17:12:15 +0000 (17:12 +0000)
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

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@309703 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Format/TokenAnnotator.cpp
unittests/Format/FormatTestJS.cpp

index 318bb259509aafd3e893554ed189aebddd2128aa..e7a50aa4329a8842c76821f08cbfb2e1fac55c4c 100644 (file)
@@ -2517,7 +2517,9 @@ bool TokenAnnotator::mustBreakBefore(const AnnotatedLine &Line,
       return true;
     if (Left.is(tok::l_brace) && Line.Level == 0 &&
         (Line.startsWith(tok::kw_enum) ||
-         Line.startsWith(tok::kw_export, tok::kw_enum)))
+         Line.startsWith(tok::kw_const, tok::kw_enum) ||
+         Line.startsWith(tok::kw_export, tok::kw_enum) ||
+         Line.startsWith(tok::kw_export, tok::kw_const, tok::kw_enum)))
       // JavaScript top-level enum key/value pairs are put on separate lines
       // instead of bin-packing.
       return true;
index d91df54f3da97c023fb81eef708aaf7a8e32ad8f..54e2c8fbe95502d09f1c1500461fc4bf36e31900 100644 (file)
@@ -1425,6 +1425,14 @@ TEST_F(FormatTestJS, EnumDeclarations) {
                "  B\n"
                "}\n"
                "var x = 1;");
+  verifyFormat("const enum Foo {\n"
+               "  A = 1,\n"
+               "  B\n"
+               "}");
+  verifyFormat("export const enum Foo {\n"
+               "  A = 1,\n"
+               "  B\n"
+               "}");
 }
 
 TEST_F(FormatTestJS, MetadataAnnotations) {