From eb886635d9d5b81edadc61a3db38d119791d7c9c Mon Sep 17 00:00:00 2001 From: Daniel Jasper Date: Mon, 31 Oct 2016 13:18:25 +0000 Subject: [PATCH] clang-format: [JS] Fix missing space after 'yield'. 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 | 3 +++ clang/unittests/Format/FormatTestJS.cpp | 2 ++ 2 files changed, 5 insertions(+) diff --git a/clang/lib/Format/TokenAnnotator.cpp b/clang/lib/Format/TokenAnnotator.cpp index abf7ff6..9237fc6 100644 --- a/clang/lib/Format/TokenAnnotator.cpp +++ b/clang/lib/Format/TokenAnnotator.cpp @@ -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()) diff --git a/clang/unittests/Format/FormatTestJS.cpp b/clang/unittests/Format/FormatTestJS.cpp index 66d7253..8c4bced 100644 --- a/clang/unittests/Format/FormatTestJS.cpp +++ b/clang/unittests/Format/FormatTestJS.cpp @@ -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" -- 2.7.4