]> granicus.if.org Git - clang/commitdiff
clang-format: [JS] space between pseudo keywords and template literals.
authorMartin Probst <martin@probst.io>
Mon, 3 Jul 2017 14:29:13 +0000 (14:29 +0000)
committerMartin Probst <martin@probst.io>
Mon, 3 Jul 2017 14:29:13 +0000 (14:29 +0000)
Summary:
Before:
    yield`foo`;

After:
    yield `foo`;

Reviewers: djasper

Subscribers: klimek

Differential Revision: https://reviews.llvm.org/D34938

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

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

index d78a37532fe8811068da8c0a77ad7ab5086dccae..471f7e13585275020f100eab73b034c65a16fd9e 100644 (file)
@@ -2300,7 +2300,11 @@ bool TokenAnnotator::spaceRequiredBefore(const AnnotatedLine &Line,
     if ((Left.is(TT_TemplateString) && Left.TokenText.endswith("${")) ||
         (Right.is(TT_TemplateString) && Right.TokenText.startswith("}")))
       return false;
-    if (Left.is(tok::identifier) && Right.is(TT_TemplateString))
+    // In tagged template literals ("html`bar baz`"), there is no space between
+    // the tag identifier and the template string. getIdentifierInfo makes sure
+    // that the identifier is not a pseudo keyword like `yield`, either.
+    if (Left.is(tok::identifier) && Left.Tok.getIdentifierInfo() == nullptr &&
+        Right.is(TT_TemplateString))
       return false;
     if (Right.is(tok::star) &&
         Left.isOneOf(Keywords.kw_function, Keywords.kw_yield))
index e84f470687ec60a10c80b9a908d60d4784884ec6..db23902ef3eb8bd47fb4332845c44d92582f8fdc 100644 (file)
@@ -1564,6 +1564,7 @@ TEST_F(FormatTestJS, TemplateStrings) {
                "                               aaaaa(  //\n"
                "                                   aaaaa)\n"
                "                             })`);");
+  verifyFormat("yield `hello`;");
 }
 
 TEST_F(FormatTestJS, TemplateStringMultiLineExpression) {