This revision was automatically updated to reflect the committed changes. Closed by commit rL272330: clang-format: [JS] recognized named functions in AnnotatingParser. (authored by mprobst).
Changed prior to commit: http://reviews.llvm.org/D21206?vs=60254&id=60268#toc Repository: rL LLVM http://reviews.llvm.org/D21206 Files: cfe/trunk/lib/Format/TokenAnnotator.cpp cfe/trunk/unittests/Format/FormatTestJS.cpp Index: cfe/trunk/lib/Format/TokenAnnotator.cpp =================================================================== --- cfe/trunk/lib/Format/TokenAnnotator.cpp +++ cfe/trunk/lib/Format/TokenAnnotator.cpp @@ -142,7 +142,10 @@ // static_assert, if and while usually contain expressions. Contexts.back().IsExpression = true; } else if (Style.Language == FormatStyle::LK_JavaScript && Left->Previous && - Left->Previous->is(Keywords.kw_function)) { + (Left->Previous->is(Keywords.kw_function) || + (Left->Previous->endsSequence(tok::identifier, + Keywords.kw_function)))) { + // function(...) or function f(...) Contexts.back().IsExpression = false; } else if (Left->Previous && Left->Previous->is(tok::r_square) && Left->Previous->MatchingParen && Index: cfe/trunk/unittests/Format/FormatTestJS.cpp =================================================================== --- cfe/trunk/unittests/Format/FormatTestJS.cpp +++ cfe/trunk/unittests/Format/FormatTestJS.cpp @@ -903,6 +903,8 @@ verifyFormat("let x: Foo<A|B> = new Foo<A|B>();"); verifyFormat("function(x: A|B): C&D {}"); verifyFormat("function(x: A|B = A | B): C&D {}"); + verifyFormat("function x(path: number|string) {}"); + verifyFormat("function x(): string|number {}"); } TEST_F(FormatTestJS, ClassDeclarations) {
Index: cfe/trunk/lib/Format/TokenAnnotator.cpp =================================================================== --- cfe/trunk/lib/Format/TokenAnnotator.cpp +++ cfe/trunk/lib/Format/TokenAnnotator.cpp @@ -142,7 +142,10 @@ // static_assert, if and while usually contain expressions. Contexts.back().IsExpression = true; } else if (Style.Language == FormatStyle::LK_JavaScript && Left->Previous && - Left->Previous->is(Keywords.kw_function)) { + (Left->Previous->is(Keywords.kw_function) || + (Left->Previous->endsSequence(tok::identifier, + Keywords.kw_function)))) { + // function(...) or function f(...) Contexts.back().IsExpression = false; } else if (Left->Previous && Left->Previous->is(tok::r_square) && Left->Previous->MatchingParen && Index: cfe/trunk/unittests/Format/FormatTestJS.cpp =================================================================== --- cfe/trunk/unittests/Format/FormatTestJS.cpp +++ cfe/trunk/unittests/Format/FormatTestJS.cpp @@ -903,6 +903,8 @@ verifyFormat("let x: Foo<A|B> = new Foo<A|B>();"); verifyFormat("function(x: A|B): C&D {}"); verifyFormat("function(x: A|B = A | B): C&D {}"); + verifyFormat("function x(path: number|string) {}"); + verifyFormat("function x(): string|number {}"); } TEST_F(FormatTestJS, ClassDeclarations) {
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits