Author: mprobst Date: Mon Jul 3 07:29:13 2017 New Revision: 307023 URL: http://llvm.org/viewvc/llvm-project?rev=307023&view=rev Log: 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 Modified: cfe/trunk/lib/Format/TokenAnnotator.cpp cfe/trunk/unittests/Format/FormatTestJS.cpp Modified: cfe/trunk/lib/Format/TokenAnnotator.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/TokenAnnotator.cpp?rev=307023&r1=307022&r2=307023&view=diff ============================================================================== --- cfe/trunk/lib/Format/TokenAnnotator.cpp (original) +++ cfe/trunk/lib/Format/TokenAnnotator.cpp Mon Jul 3 07:29:13 2017 @@ -2300,7 +2300,11 @@ bool TokenAnnotator::spaceRequiredBefore 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)) Modified: cfe/trunk/unittests/Format/FormatTestJS.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTestJS.cpp?rev=307023&r1=307022&r2=307023&view=diff ============================================================================== --- cfe/trunk/unittests/Format/FormatTestJS.cpp (original) +++ cfe/trunk/unittests/Format/FormatTestJS.cpp Mon Jul 3 07:29:13 2017 @@ -1564,6 +1564,7 @@ TEST_F(FormatTestJS, TemplateStrings) { " aaaaa( //\n" " aaaaa)\n" " })`);"); + verifyFormat("yield `hello`;"); } TEST_F(FormatTestJS, TemplateStringMultiLineExpression) { _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits