From 580bb4f258f97e90164676204ba0ca0d8200e674 Mon Sep 17 00:00:00 2001 From: Alexander Kornienko Date: Wed, 20 Nov 2013 14:30:26 +0000 Subject: [PATCH] Support for JavaScript === and !== operators. Reviewers: klimek, djasper Reviewed By: klimek CC: cfe-commits, klimek Differential Revision: http://llvm-reviews.chandlerc.com/D2231 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@195251 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Format/TokenAnnotator.cpp | 7 +++++++ unittests/Format/FormatTest.cpp | 8 ++++++++ 2 files changed, 15 insertions(+) diff --git a/lib/Format/TokenAnnotator.cpp b/lib/Format/TokenAnnotator.cpp index 074e1d7845..3aee3a0394 100644 --- a/lib/Format/TokenAnnotator.cpp +++ b/lib/Format/TokenAnnotator.cpp @@ -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)) diff --git a/unittests/Format/FormatTest.cpp b/unittests/Format/FormatTest.cpp index d9ca12996f..433f3f70c8 100644 --- a/unittests/Format/FormatTest.cpp +++ b/unittests/Format/FormatTest.cpp @@ -7309,5 +7309,13 @@ TEST_F(FormatTest, SpacesInAngles) { verifyFormat("A>();", 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 -- 2.40.0