Support for JavaScript === and !== operators.

Reviewers: klimek, djasper

Reviewed By: klimek

CC: cfe-commits, klimek

Differential Revision: http://llvm-reviews.chandlerc.com/D2231

llvm-svn: 195251
This commit is contained in:
Alexander Kornienko 2013-11-20 14:30:26 +00:00
parent 3e29c6bf22
commit 7c9c050769
2 changed files with 15 additions and 0 deletions

View File

@ -1363,6 +1363,10 @@ bool TokenAnnotator::spaceRequiredBefore(const AnnotatedLine &Line,
if (Tok.isOneOf(tok::arrowstar, tok::periodstar) ||
Tok.Previous->isOneOf(tok::arrowstar, tok::periodstar))
return false;
// JavaScript identity operators ===, !==.
if (Tok.Previous->isOneOf(tok::equalequal, tok::exclaimequal) &&
Tok.is(tok::equal))
return false;
if (!Style.SpaceBeforeAssignmentOperators &&
Tok.getPrecedence() == prec::Assignment)
return false;
@ -1452,6 +1456,9 @@ bool TokenAnnotator::canBreakBefore(const AnnotatedLine &Line,
return false;
if (Left.is(tok::equal) && Line.Type == LT_VirtualFunctionDecl)
return false;
// JavaScript identity operators ===, !==.
if (Left.isOneOf(tok::equalequal, tok::exclaimequal) && Right.is(tok::equal))
return false;
if (Left.Previous) {
if (Left.is(tok::l_paren) && Right.is(tok::l_paren) &&
Left.Previous->is(tok::kw___attribute))

View File

@ -7309,5 +7309,13 @@ TEST_F(FormatTest, SpacesInAngles) {
verifyFormat("A<A<int>>();", Spaces);
}
TEST_F(FormatTest, UnderstandsJavaScript) {
verifyFormat("a === b;");
verifyFormat("aaaaaaa === b;", getLLVMStyleWithColumns(10));
verifyFormat("a !== b;");
verifyFormat("aaaaaaa !== b;", getLLVMStyleWithColumns(10));
}
} // end namespace tooling
} // end namespace clang