[PATCH] D99495: clang-format: [JS] do not collapse - - to --.
Martin Probst via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Tue Mar 30 05:32:38 PDT 2021
This revision was automatically updated to reflect the committed changes.
Closed by commit rG2b30bd2be0a8: clang-format: [JS] do not collapse - - to --. (authored by mprobst).
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D99495/new/
https://reviews.llvm.org/D99495
Files:
clang/lib/Format/TokenAnnotator.cpp
clang/unittests/Format/FormatTestJS.cpp
Index: clang/unittests/Format/FormatTestJS.cpp
===================================================================
--- clang/unittests/Format/FormatTestJS.cpp
+++ clang/unittests/Format/FormatTestJS.cpp
@@ -276,6 +276,12 @@
// ES6 spread operator.
verifyFormat("someFunction(...a);");
verifyFormat("var x = [1, ...a, 2];");
+
+ // "- -1" is legal JS syntax, but must not collapse into "--".
+ verifyFormat("- -1;", " - -1;");
+ verifyFormat("-- -1;", " -- -1;");
+ verifyFormat("+ +1;", " + +1;");
+ verifyFormat("++ +1;", " ++ +1;");
}
TEST_F(FormatTestJS, UnderstandsAmpAmp) {
Index: clang/lib/Format/TokenAnnotator.cpp
===================================================================
--- clang/lib/Format/TokenAnnotator.cpp
+++ clang/lib/Format/TokenAnnotator.cpp
@@ -3370,6 +3370,12 @@
Style.BitFieldColonSpacing == FormatStyle::BFCS_Before;
return true;
}
+ // Do not merge "- -" into "--".
+ if ((Left.isOneOf(tok::minus, tok::minusminus) &&
+ Right.isOneOf(tok::minus, tok::minusminus)) ||
+ (Left.isOneOf(tok::plus, tok::plusplus) &&
+ Right.isOneOf(tok::plus, tok::plusplus)))
+ return true;
if (Left.is(TT_UnaryOperator)) {
if (!Right.is(tok::l_paren)) {
// The alternative operators for ~ and ! are "compl" and "not".
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D99495.334118.patch
Type: text/x-patch
Size: 1309 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20210330/8d256033/attachment.bin>
More information about the cfe-commits
mailing list