clang-format: [JS] space between pseudo keywords and template literals.

Summary:
Before:
    yield`foo`;

After:
    yield `foo`;

Reviewers: djasper

Subscribers: klimek

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

llvm-svn: 307023
This commit is contained in:
Martin Probst 2017-07-03 14:29:13 +00:00
parent 448095c19b
commit bd1eb12d31
2 changed files with 6 additions and 1 deletions

View 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))

View File

@ -1564,6 +1564,7 @@ TEST_F(FormatTestJS, TemplateStrings) {
" aaaaa( //\n"
" aaaaa)\n"
" })`);");
verifyFormat("yield `hello`;");
}
TEST_F(FormatTestJS, TemplateStringMultiLineExpression) {