r272330 - clang-format: [JS] recognized named functions in AnnotatingParser.
Martin Probst via cfe-commits
cfe-commits at lists.llvm.org
Thu Jun 9 15:49:04 PDT 2016
Author: mprobst
Date: Thu Jun 9 17:49:04 2016
New Revision: 272330
URL: http://llvm.org/viewvc/llvm-project?rev=272330&view=rev
Log:
clang-format: [JS] recognized named functions in AnnotatingParser.
Summary: This also fixes union type formatting in function parameter types.
Before: function x(path: number| string) {}
After: function x(path: number|string) {}
Reviewers: djasper
Subscribers: klimek, cfe-commits
Differential Revision: http://reviews.llvm.org/D21206
Modified:
cfe/trunk/lib/Format/TokenAnnotator.cpp
cfe/trunk/unittests/Format/FormatTestJS.cpp
Modified: cfe/trunk/lib/Format/TokenAnnotator.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/TokenAnnotator.cpp?rev=272330&r1=272329&r2=272330&view=diff
==============================================================================
--- cfe/trunk/lib/Format/TokenAnnotator.cpp (original)
+++ cfe/trunk/lib/Format/TokenAnnotator.cpp Thu Jun 9 17:49:04 2016
@@ -142,7 +142,10 @@ private:
// 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 &&
Modified: cfe/trunk/unittests/Format/FormatTestJS.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTestJS.cpp?rev=272330&r1=272329&r2=272330&view=diff
==============================================================================
--- cfe/trunk/unittests/Format/FormatTestJS.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTestJS.cpp Thu Jun 9 17:49:04 2016
@@ -903,6 +903,8 @@ TEST_F(FormatTestJS, UnionIntersectionTy
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) {
More information about the cfe-commits
mailing list