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

Martin Probst martinprobst at google.com
Wed Feb 18 08:29:01 PST 2015


================
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)) {
----------------
djasper wrote:
> Maybe
> 
>   Tok->Type = Style.Language == FormatStyle::LK_JavaScript
>       ? TT_JsTypeColon
>       : TT_RangeBasedForLoopColon;
> 
> ?
Done.

================
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 &&
----------------
djasper wrote:
> Here, too?
I don't think a double nested ternary is very readable here (note this is three cases).

================
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;
+        }
----------------
djasper wrote:
> Here, too?
Done.

http://reviews.llvm.org/D7721

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






More information about the cfe-commits mailing list