From: Daniel Jasper Date: Tue, 6 May 2014 14:41:29 +0000 (+0000) Subject: clang-format: [JS] Keep space after closure style comments. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=56b2dd0e6f00d52647dee2c3f1389265a99f9424;p=clang clang-format: [JS] Keep space after closure style comments. Before: var x = /** @type {foo} */ (bar); After: var x = /** @type {foo} */(bar); git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@208093 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Format/TokenAnnotator.cpp b/lib/Format/TokenAnnotator.cpp index e873e98460..8becd00897 100644 --- a/lib/Format/TokenAnnotator.cpp +++ b/lib/Format/TokenAnnotator.cpp @@ -1457,6 +1457,8 @@ bool TokenAnnotator::spaceRequiredBetween(const AnnotatedLine &Line, 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::spaceRequiredBetween(const AnnotatedLine &Line, (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); diff --git a/unittests/Format/FormatTestJS.cpp b/unittests/Format/FormatTestJS.cpp index 153b07535e..ee49912522 100644 --- a/unittests/Format/FormatTestJS.cpp +++ b/unittests/Format/FormatTestJS.cpp @@ -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