r208093 - clang-format: [JS] Keep space after closure style comments.

Daniel Jasper djasper at google.com
Tue May 6 07:41:30 PDT 2014


Author: djasper
Date: Tue May  6 09:41:29 2014
New Revision: 208093

URL: http://llvm.org/viewvc/llvm-project?rev=208093&view=rev
Log:
clang-format: [JS] Keep space after closure style comments.

Before:
  var x = /** @type {foo} */ (bar);

After:
  var x = /** @type {foo} */(bar);

Modified:
    cfe/trunk/lib/Format/TokenAnnotator.cpp
    cfe/trunk/unittests/Format/FormatTestJS.cpp

Modified: cfe/trunk/lib/Format/TokenAnnotator.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/TokenAnnotator.cpp?rev=208093&r1=208092&r2=208093&view=diff
==============================================================================
--- cfe/trunk/lib/Format/TokenAnnotator.cpp (original)
+++ cfe/trunk/lib/Format/TokenAnnotator.cpp Tue May  6 09:41:29 2014
@@ -1457,6 +1457,8 @@ bool TokenAnnotator::spaceRequiredBetwee
     return false;
   if (Left.is(tok::colon))
     return Left.Type != TT_ObjCMethodExpr;
+  if (Left.Type == TT_BlockComment)
+    return !Left.TokenText.endswith("=*/");
   if (Right.is(tok::l_paren)) {
     if (Left.is(tok::r_paren) && Left.Type == TT_AttributeParen)
       return true;
@@ -1478,8 +1480,6 @@ bool TokenAnnotator::spaceRequiredBetwee
       (Right.is(tok::r_brace) && Right.MatchingParen &&
        Right.MatchingParen->BlockKind != BK_Block))
     return !Style.Cpp11BracedListStyle;
-  if (Left.Type == TT_BlockComment && Left.TokenText.endswith("=*/"))
-    return false;
   if (Right.Type == TT_UnaryOperator)
     return !Left.isOneOf(tok::l_paren, tok::l_square, tok::at) &&
            (Left.isNot(tok::colon) || Left.Type != TT_ObjCMethodExpr);

Modified: cfe/trunk/unittests/Format/FormatTestJS.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTestJS.cpp?rev=208093&r1=208092&r2=208093&view=diff
==============================================================================
--- cfe/trunk/unittests/Format/FormatTestJS.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTestJS.cpp Tue May  6 09:41:29 2014
@@ -102,5 +102,9 @@ TEST_F(FormatTestJS, ReturnStatements) {
   verifyFormat("function() { return [hello, world]; }");
 }
 
+TEST_F(FormatTestJS, ClosureStyleComments) {
+  verifyFormat("var x = /** @type {foo} */ (bar);");
+}
+
 } // end namespace tooling
 } // end namespace clang





More information about the cfe-commits mailing list