@@ -4910,6 +4910,8 @@ bool TokenAnnotator::spaceRequiredBefore(const AnnotatedLine &Line,
4910
4910
if (Left.is (tok::star) && Right.is (tok::comment))
4911
4911
return true ;
4912
4912
4913
+ const auto *BeforeLeft = Left.Previous ;
4914
+
4913
4915
if (IsCpp) {
4914
4916
if (Left.is (TT_OverloadedOperator) &&
4915
4917
Right.isOneOf (TT_TemplateOpener, TT_TemplateCloser)) {
@@ -4962,7 +4964,7 @@ bool TokenAnnotator::spaceRequiredBefore(const AnnotatedLine &Line,
4962
4964
if (Left.Tok .getIdentifierInfo () && Right.Tok .isLiteral ())
4963
4965
return true ;
4964
4966
} else if (Style .isProto ()) {
4965
- if (Right.is (tok::period) &&
4967
+ if (Right.is (tok::period) && !(BeforeLeft && BeforeLeft-> is (tok::period)) &&
4966
4968
Left.isOneOf (Keywords.kw_optional , Keywords.kw_required ,
4967
4969
Keywords.kw_repeated , Keywords.kw_extend )) {
4968
4970
return true ;
@@ -5070,8 +5072,8 @@ bool TokenAnnotator::spaceRequiredBefore(const AnnotatedLine &Line,
5070
5072
if (Left.is (TT_FatArrow))
5071
5073
return true ;
5072
5074
// for await ( ...
5073
- if (Right.is (tok::l_paren) && Left.is (Keywords.kw_await ) && Left. Previous &&
5074
- Left. Previous ->is (tok::kw_for)) {
5075
+ if (Right.is (tok::l_paren) && Left.is (Keywords.kw_await ) && BeforeLeft &&
5076
+ BeforeLeft ->is (tok::kw_for)) {
5075
5077
return true ;
5076
5078
}
5077
5079
if (Left.is (Keywords.kw_async ) && Right.is (tok::l_paren) &&
@@ -5108,7 +5110,7 @@ bool TokenAnnotator::spaceRequiredBefore(const AnnotatedLine &Line,
5108
5110
return false ;
5109
5111
// Valid JS method names can include keywords, e.g. `foo.delete()` or
5110
5112
// `bar.instanceof()`. Recognize call positions by preceding period.
5111
- if (Left. Previous && Left. Previous ->is (tok::period) &&
5113
+ if (BeforeLeft && BeforeLeft ->is (tok::period) &&
5112
5114
Left.Tok .getIdentifierInfo ()) {
5113
5115
return false ;
5114
5116
}
@@ -5126,22 +5128,22 @@ bool TokenAnnotator::spaceRequiredBefore(const AnnotatedLine &Line,
5126
5128
// "of" is only a keyword if it appears after another identifier
5127
5129
// (e.g. as "const x of y" in a for loop), or after a destructuring
5128
5130
// operation (const [x, y] of z, const {a, b} of c).
5129
- (Left.is (Keywords.kw_of ) && Left. Previous &&
5130
- (Left. Previous ->is (tok::identifier) ||
5131
- Left. Previous ->isOneOf (tok::r_square, tok::r_brace)))) &&
5132
- (!Left. Previous || Left. Previous ->isNot (tok::period))) {
5131
+ (Left.is (Keywords.kw_of ) && BeforeLeft &&
5132
+ (BeforeLeft ->is (tok::identifier) ||
5133
+ BeforeLeft ->isOneOf (tok::r_square, tok::r_brace)))) &&
5134
+ (!BeforeLeft || BeforeLeft ->isNot (tok::period))) {
5133
5135
return true ;
5134
5136
}
5135
- if (Left.isOneOf (tok::kw_for, Keywords.kw_as ) && Left. Previous &&
5136
- Left. Previous ->is (tok::period) && Right.is (tok::l_paren)) {
5137
+ if (Left.isOneOf (tok::kw_for, Keywords.kw_as ) && BeforeLeft &&
5138
+ BeforeLeft ->is (tok::period) && Right.is (tok::l_paren)) {
5137
5139
return false ;
5138
5140
}
5139
5141
if (Left.is (Keywords.kw_as ) &&
5140
5142
Right.isOneOf (tok::l_square, tok::l_brace, tok::l_paren)) {
5141
5143
return true ;
5142
5144
}
5143
- if (Left.is (tok::kw_default) && Left. Previous &&
5144
- Left. Previous ->is (tok::kw_export)) {
5145
+ if (Left.is (tok::kw_default) && BeforeLeft &&
5146
+ BeforeLeft ->is (tok::kw_export)) {
5145
5147
return true ;
5146
5148
}
5147
5149
if (Left.is (Keywords.kw_is ) && Right.is (tok::l_brace))
0 commit comments