]> granicus.if.org Git - clang/commitdiff
clang-format: [JS] Fix templated parameter default values.
authorDaniel Jasper <djasper@google.com>
Sat, 2 May 2015 07:54:58 +0000 (07:54 +0000)
committerDaniel Jasper <djasper@google.com>
Sat, 2 May 2015 07:54:58 +0000 (07:54 +0000)
Parameters can have templated types and default values (= ...), which is
another location in which a template closer should be followed by
whitespace.

Patch by Martin Probst, thank you.

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

lib/Format/TokenAnnotator.cpp
unittests/Format/FormatTestJS.cpp

index e52650be07f1e138c088cdef4f91463db4326bf1..00348a2c9f53d8f09f8360dbc13d68121b94aa7c 100644 (file)
@@ -1804,7 +1804,7 @@ bool TokenAnnotator::spaceRequiredBefore(const AnnotatedLine &Line,
         Line.First->isOneOf(Keywords.kw_import, tok::kw_export))
       return false;
     if (Left.is(TT_TemplateCloser) &&
-        !Right.isOneOf(tok::l_brace, tok::comma, tok::l_square,
+        !Right.isOneOf(tok::equal, tok::l_brace, tok::comma, tok::l_square,
                        Keywords.kw_implements, Keywords.kw_extends))
       // Type assertions ('<type>expr') are not followed by whitespace. Other
       // locations that should have whitespace following are identified by the
index 695bad55538eee11efe7fc9d7a83a1c5f2310bbf..e0719ee4fc23de2b6de7e3285e51608d833b7dd9 100644 (file)
@@ -687,6 +687,8 @@ TEST_F(FormatTestJS, TypeArguments) {
   verifyFormat("foo<Y>(a);");
   verifyFormat("var x: X<Y>[];");
   verifyFormat("class C extends D<E> implements F<G>, H<I> {}");
+  verifyFormat("function f(a: List<any> = null) {\n}");
+  verifyFormat("function f(): List<any> {\n}");
 }
 
 TEST_F(FormatTestJS, OptionalTypes) {