[PATCH] clang-format: [js] Support type annotations

Daniel Jasper djasper at google.com
Wed Feb 18 08:23:49 PST 2015


I'd use ternary expressions, what do you think? Otherwise looks good, I can submit this for you.


================
Comment at: lib/Format/TokenAnnotator.cpp:424-428
@@ -426,3 +423,7 @@
       } else if (Contexts.back().ColonIsForRangeExpr) {
-        Tok->Type = TT_RangeBasedForLoopColon;
+        if (Style.Language == FormatStyle::LK_JavaScript) {
+          Tok->Type = TT_JsTypeColon;
+        } else {
+          Tok->Type = TT_RangeBasedForLoopColon;
+        }
       } else if (CurrentToken && CurrentToken->is(tok::numeric_constant)) {
----------------
Maybe

  Tok->Type = Style.Language == FormatStyle::LK_JavaScript
      ? TT_JsTypeColon
      : TT_RangeBasedForLoopColon;

?

================
Comment at: lib/Format/TokenAnnotator.cpp:435-438
@@ -433,1 +434,6 @@
+          Tok->Type = TT_JsTypeColon;
+        else if (Tok->Previous->is(tok::r_paren))
+          Tok->Type = TT_CtorInitializerColon;
+        else
+          Tok->Type = TT_InheritanceColon;
       } else if (Tok->Previous->is(tok::identifier) && Tok->Next &&
----------------
Here, too?

================
Comment at: lib/Format/TokenAnnotator.cpp:445-448
@@ -438,2 +444,6 @@
       } else if (Contexts.back().ContextKind == tok::l_paren) {
-        Tok->Type = TT_InlineASMColon;
+        if (Style.Language == FormatStyle::LK_JavaScript) {
+          Tok->Type = TT_JsTypeColon;
+        } else {
+          Tok->Type = TT_InlineASMColon;
+        }
----------------
Here, too?

http://reviews.llvm.org/D7721

EMAIL PREFERENCES
  http://reviews.llvm.org/settings/panel/emailpreferences/






More information about the cfe-commits mailing list