diff options
| -rw-r--r-- | clang/lib/Format/TokenAnnotator.cpp | 7 | ||||
| -rw-r--r-- | clang/unittests/Format/FormatTestJS.cpp | 4 |
2 files changed, 9 insertions, 2 deletions
diff --git a/clang/lib/Format/TokenAnnotator.cpp b/clang/lib/Format/TokenAnnotator.cpp index f7cfe9fa583..96b1df82e56 100644 --- a/clang/lib/Format/TokenAnnotator.cpp +++ b/clang/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/clang/unittests/Format/FormatTestJS.cpp b/clang/unittests/Format/FormatTestJS.cpp index 8d03964fe16..822d572b944 100644 --- a/clang/unittests/Format/FormatTestJS.cpp +++ b/clang/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" |

