From: Daniel Jasper Date: Thu, 27 Nov 2014 14:55:17 +0000 (+0000) Subject: clang-format: [JS] new and delete are valid function names. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=ea63da2783aeede9328a805dd2f932c6a92572e2;p=clang clang-format: [JS] new and delete are valid function names. Before: someObject.new (); someObject.delete (); After: someObject.new(); someObject.delete(); git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@222890 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Format/TokenAnnotator.cpp b/lib/Format/TokenAnnotator.cpp index 97bba6f1f9..d6c823e39b 100644 --- a/lib/Format/TokenAnnotator.cpp +++ b/lib/Format/TokenAnnotator.cpp @@ -1671,12 +1671,11 @@ bool TokenAnnotator::spaceRequiredBetween(const AnnotatedLine &Line, if (Right.is(tok::l_paren)) { if (Left.is(tok::r_paren) && Left.is(TT_AttributeParen)) return true; - return Line.Type == LT_ObjCDecl || - Left.isOneOf(tok::kw_new, tok::kw_delete, tok::semi) || + return Line.Type == LT_ObjCDecl || Left.is(tok::semi) || (Style.SpaceBeforeParens != FormatStyle::SBPO_Never && (Left.isOneOf(tok::kw_if, tok::kw_for, tok::kw_while, tok::kw_switch, tok::kw_case) || - (Left.is(tok::kw_catch) && + (Left.isOneOf(tok::kw_catch, tok::kw_new, tok::kw_delete) && (!Left.Previous || Left.Previous->isNot(tok::period))) || Left.IsForEachMacro)) || (Style.SpaceBeforeParens == FormatStyle::SBPO_Always && diff --git a/unittests/Format/FormatTestJS.cpp b/unittests/Format/FormatTestJS.cpp index 3e781c94d0..6c8fd2962a 100644 --- a/unittests/Format/FormatTestJS.cpp +++ b/unittests/Format/FormatTestJS.cpp @@ -361,6 +361,8 @@ TEST_F(FormatTestJS, TryCatch) { // But, of course, "catch" is a perfectly fine function name in JavaScript. verifyFormat("someObject.catch();"); + verifyFormat("someObject.new();"); + verifyFormat("someObject.delete();"); } TEST_F(FormatTestJS, StringLiteralConcatenation) {