]> granicus.if.org Git - clang/commitdiff
clang-format: [JS] Fix missing space after 'yield'.
authorDaniel Jasper <djasper@google.com>
Mon, 31 Oct 2016 13:18:25 +0000 (13:18 +0000)
committerDaniel Jasper <djasper@google.com>
Mon, 31 Oct 2016 13:18:25 +0000 (13:18 +0000)
Before:
  class X {
    delete(val) {
      return null;
    }
    * gen() {
      yield[1, 2];
    }
    * gen() {
      yield{a: 1};
    }
  };

After:
  class X {
    delete(val) {
      return null;
    }
    * gen() {
      yield [1, 2];
    }
    * gen() {
      yield {a: 1};
    }
  };

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

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

index abf7ff6b3b731ed8098a0ea516530aa68fb7e6b7..9237fc6ec53c38ed784dc6688913cc3e670c4fac 100644 (file)
@@ -2133,6 +2133,9 @@ bool TokenAnnotator::spaceRequiredBefore(const AnnotatedLine &Line,
     if (Right.is(tok::star) &&
         Left.isOneOf(Keywords.kw_function, Keywords.kw_yield))
       return false;
+    if (Right.isOneOf(tok::l_brace, tok::l_square) &&
+        Left.isOneOf(Keywords.kw_function, Keywords.kw_yield))
+      return true;
     // JS methods can use some keywords as names (e.g. `delete()`).
     if (Right.is(tok::l_paren) && Line.MustBeDeclaration &&
         Left.Tok.getIdentifierInfo())
index 66d72534e24de3d74a789389cb54122c693b722e..8c4bced24c7d270e2716e77eafdd526ef886ea90 100644 (file)
@@ -368,6 +368,8 @@ TEST_F(FormatTestJS, GeneratorFunctions) {
                "  let x = 1;\n"
                "  yield x;\n"
                "  yield* something();\n"
+               "  yield [1, 2];\n"
+               "  yield {a: 1};\n"
                "}");
   verifyFormat("function*\n"
                "    f() {\n"