From 60e92068601b8bf90397f54da221841595e118a8 Mon Sep 17 00:00:00 2001 From: Daniel Jasper Date: Thu, 17 Mar 2016 12:17:59 +0000 Subject: [PATCH] clang-format: [JS] Fix incorrect spacing around contextual keywords. Before: x.of (); After: x.of(); git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@263710 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Format/TokenAnnotator.cpp | 7 +++++-- unittests/Format/FormatTestJS.cpp | 4 ++++ 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/lib/Format/TokenAnnotator.cpp b/lib/Format/TokenAnnotator.cpp index f7cfe9fa58..96b1df82e5 100644 --- a/lib/Format/TokenAnnotator.cpp +++ b/lib/Format/TokenAnnotator.cpp @@ -2038,8 +2038,11 @@ bool TokenAnnotator::spaceRequiredBefore(const AnnotatedLine &Line, Left.isOneOf(Keywords.kw_returns, Keywords.kw_option)) return true; } else if (Style.Language == FormatStyle::LK_JavaScript) { - if (Left.isOneOf(Keywords.kw_let, Keywords.kw_var, TT_JsFatArrow, - Keywords.kw_in, Keywords.kw_of)) + if (Left.is(TT_JsFatArrow)) + return true; + if (Left.isOneOf(Keywords.kw_let, Keywords.kw_var, Keywords.kw_in, + Keywords.kw_of) && + (!Left.Previous || !Left.Previous->is(tok::period))) return true; if (Left.is(tok::kw_default) && Left.Previous && Left.Previous->is(tok::kw_export)) diff --git a/unittests/Format/FormatTestJS.cpp b/unittests/Format/FormatTestJS.cpp index 8d03964fe1..822d572b94 100644 --- a/unittests/Format/FormatTestJS.cpp +++ b/unittests/Format/FormatTestJS.cpp @@ -125,6 +125,10 @@ TEST_F(FormatTestJS, ReservedWords) { verifyFormat("x.class.struct = 1;"); verifyFormat("x.case = 1;"); verifyFormat("x.interface = 1;"); + verifyFormat("x.of() = 1;"); + verifyFormat("x.in() = 1;"); + verifyFormat("x.let() = 1;"); + verifyFormat("x.var() = 1;"); verifyFormat("x = {\n" " a: 12,\n" " interface: 1,\n" -- 2.40.0