From 1f3bb7c5ab9839619e8e52ec7dd15edd37736835 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}; } }; git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@285569 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Format/TokenAnnotator.cpp | 3 +++ unittests/Format/FormatTestJS.cpp | 2 ++ 2 files changed, 5 insertions(+) diff --git a/lib/Format/TokenAnnotator.cpp b/lib/Format/TokenAnnotator.cpp index abf7ff6b3b..9237fc6ec5 100644 --- a/lib/Format/TokenAnnotator.cpp +++ b/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/unittests/Format/FormatTestJS.cpp b/unittests/Format/FormatTestJS.cpp index 66d72534e2..8c4bced24c 100644 --- a/unittests/Format/FormatTestJS.cpp +++ b/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.40.0