This revision was automatically updated to reflect the committed changes. Closed by commit rG0734fb21ed5e: clang-format: [JS] Handle more keyword-named methods. (authored by mprobst).
Changed prior to commit: https://reviews.llvm.org/D72827?vs=238442&id=238713#toc Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D72827/new/ https://reviews.llvm.org/D72827 Files: clang/lib/Format/UnwrappedLineParser.cpp clang/unittests/Format/FormatTestJS.cpp Index: clang/unittests/Format/FormatTestJS.cpp =================================================================== --- clang/unittests/Format/FormatTestJS.cpp +++ clang/unittests/Format/FormatTestJS.cpp @@ -358,6 +358,22 @@ " x();\n" " }\n" "}\n"); + verifyFormat("class KeywordNamedMethods {\n" + " do() {\n" + " }\n" + " for() {\n" + " }\n" + " while() {\n" + " }\n" + " if() {\n" + " }\n" + " else() {\n" + " }\n" + " try() {\n" + " }\n" + " catch() {\n" + " }\n" + "}\n"); } TEST_F(FormatTestJS, ReservedWordsParenthesized) { Index: clang/lib/Format/UnwrappedLineParser.cpp =================================================================== --- clang/lib/Format/UnwrappedLineParser.cpp +++ clang/lib/Format/UnwrappedLineParser.cpp @@ -1011,13 +1011,22 @@ parseAccessSpecifier(); return; case tok::kw_if: + if (Style.Language == FormatStyle::LK_JavaScript && Line->MustBeDeclaration) + // field/method declaration. + break; parseIfThenElse(); return; case tok::kw_for: case tok::kw_while: + if (Style.Language == FormatStyle::LK_JavaScript && Line->MustBeDeclaration) + // field/method declaration. + break; parseForOrWhileLoop(); return; case tok::kw_do: + if (Style.Language == FormatStyle::LK_JavaScript && Line->MustBeDeclaration) + // field/method declaration. + break; parseDoWhile(); return; case tok::kw_switch: @@ -1045,6 +1054,9 @@ return; case tok::kw_try: case tok::kw___try: + if (Style.Language == FormatStyle::LK_JavaScript && Line->MustBeDeclaration) + // field/method declaration. + break; parseTryCatch(); return; case tok::kw_extern: @@ -1290,6 +1302,12 @@ // element continues. break; case tok::kw_try: + if (Style.Language == FormatStyle::LK_JavaScript && + Line->MustBeDeclaration) { + // field/method declaration. + nextToken(); + break; + } // We arrive here when parsing function-try blocks. if (Style.BraceWrapping.AfterFunction) addUnwrappedLine();
Index: clang/unittests/Format/FormatTestJS.cpp =================================================================== --- clang/unittests/Format/FormatTestJS.cpp +++ clang/unittests/Format/FormatTestJS.cpp @@ -358,6 +358,22 @@ " x();\n" " }\n" "}\n"); + verifyFormat("class KeywordNamedMethods {\n" + " do() {\n" + " }\n" + " for() {\n" + " }\n" + " while() {\n" + " }\n" + " if() {\n" + " }\n" + " else() {\n" + " }\n" + " try() {\n" + " }\n" + " catch() {\n" + " }\n" + "}\n"); } TEST_F(FormatTestJS, ReservedWordsParenthesized) { Index: clang/lib/Format/UnwrappedLineParser.cpp =================================================================== --- clang/lib/Format/UnwrappedLineParser.cpp +++ clang/lib/Format/UnwrappedLineParser.cpp @@ -1011,13 +1011,22 @@ parseAccessSpecifier(); return; case tok::kw_if: + if (Style.Language == FormatStyle::LK_JavaScript && Line->MustBeDeclaration) + // field/method declaration. + break; parseIfThenElse(); return; case tok::kw_for: case tok::kw_while: + if (Style.Language == FormatStyle::LK_JavaScript && Line->MustBeDeclaration) + // field/method declaration. + break; parseForOrWhileLoop(); return; case tok::kw_do: + if (Style.Language == FormatStyle::LK_JavaScript && Line->MustBeDeclaration) + // field/method declaration. + break; parseDoWhile(); return; case tok::kw_switch: @@ -1045,6 +1054,9 @@ return; case tok::kw_try: case tok::kw___try: + if (Style.Language == FormatStyle::LK_JavaScript && Line->MustBeDeclaration) + // field/method declaration. + break; parseTryCatch(); return; case tok::kw_extern: @@ -1290,6 +1302,12 @@ // element continues. break; case tok::kw_try: + if (Style.Language == FormatStyle::LK_JavaScript && + Line->MustBeDeclaration) { + // field/method declaration. + nextToken(); + break; + } // We arrive here when parsing function-try blocks. if (Style.BraceWrapping.AfterFunction) addUnwrappedLine();
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits