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};
    }
  };

llvm-svn: 285569

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

index abf7ff6..9237fc6 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 66d7253..8c4bced 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"