]> granicus.if.org Git - clang/commitdiff
clang-format: [JS] detect ASI after closing parens.
authorMartin Probst <martin@probst.io>
Wed, 9 Aug 2017 15:19:16 +0000 (15:19 +0000)
committerMartin Probst <martin@probst.io>
Wed, 9 Aug 2017 15:19:16 +0000 (15:19 +0000)
Summary: A closing parenthesis followed by a declaration or statement should always terminate the current statement.

Reviewers: djasper

Subscribers: klimek, cfe-commits

Differential Revision: https://reviews.llvm.org/D36491

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

lib/Format/UnwrappedLineParser.cpp
unittests/Format/FormatTestJS.cpp

index e6afd1f9887f5f6a24e85a2610a1937dfff25271..fdf98839019565cc1b223a1c5d549de283eb74ec 100644 (file)
@@ -853,7 +853,8 @@ void UnwrappedLineParser::readTokenWithJavaScriptASI() {
        Previous->isOneOf(tok::r_square, tok::r_paren, tok::plusplus,
                          tok::minusminus)))
     return addUnwrappedLine();
-  if (PreviousMustBeValue && isJSDeclOrStmt(Keywords, Next))
+  if ((PreviousMustBeValue || Previous->is(tok::r_paren)) &&
+      isJSDeclOrStmt(Keywords, Next))
     return addUnwrappedLine();
 }
 
index e6827296e1264ffe3ecd35065ebc226069fb0cd5..fb035066d68f3c6e258d712c7dd2b3e760522a22 100644 (file)
@@ -1106,6 +1106,10 @@ TEST_F(FormatTestJS, WrapRespectsAutomaticSemicolonInsertion) {
                "  readonly ratherLongField = 1;\n"
                "}",
                getGoogleJSStyleWithColumns(20));
+  verifyFormat("const x = (5 + 9)\n"
+               "const y = 3\n",
+               "const x = (   5 +    9)\n"
+               "const y = 3\n");
 }
 
 TEST_F(FormatTestJS, AutomaticSemicolonInsertionHeuristic) {