r260518 - clang-format: [JS] Support for (.. of ..) loops.
Daniel Jasper via cfe-commits
cfe-commits at lists.llvm.org
Thu Feb 11 05:24:15 PST 2016
Author: djasper
Date: Thu Feb 11 07:24:15 2016
New Revision: 260518
URL: http://llvm.org/viewvc/llvm-project?rev=260518&view=rev
Log:
clang-format: [JS] Support for (.. of ..) loops.
Before:
for (var i of[2, 3]) {}
After:
for (var i of [2, 3]) {}
Modified:
cfe/trunk/lib/Format/FormatToken.h
cfe/trunk/lib/Format/TokenAnnotator.cpp
cfe/trunk/unittests/Format/FormatTestJS.cpp
Modified: cfe/trunk/lib/Format/FormatToken.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/FormatToken.h?rev=260518&r1=260517&r2=260518&view=diff
==============================================================================
--- cfe/trunk/lib/Format/FormatToken.h (original)
+++ cfe/trunk/lib/Format/FormatToken.h Thu Feb 11 07:24:15 2016
@@ -528,6 +528,7 @@ struct AdditionalKeywords {
kw_final = &IdentTable.get("final");
kw_override = &IdentTable.get("override");
kw_in = &IdentTable.get("in");
+ kw_of = &IdentTable.get("of");
kw_CF_ENUM = &IdentTable.get("CF_ENUM");
kw_CF_OPTIONS = &IdentTable.get("CF_OPTIONS");
kw_NS_ENUM = &IdentTable.get("NS_ENUM");
@@ -571,6 +572,7 @@ struct AdditionalKeywords {
IdentifierInfo *kw_final;
IdentifierInfo *kw_override;
IdentifierInfo *kw_in;
+ IdentifierInfo *kw_of;
IdentifierInfo *kw_CF_ENUM;
IdentifierInfo *kw_CF_OPTIONS;
IdentifierInfo *kw_NS_ENUM;
Modified: cfe/trunk/lib/Format/TokenAnnotator.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/TokenAnnotator.cpp?rev=260518&r1=260517&r2=260518&view=diff
==============================================================================
--- cfe/trunk/lib/Format/TokenAnnotator.cpp (original)
+++ cfe/trunk/lib/Format/TokenAnnotator.cpp Thu Feb 11 07:24:15 2016
@@ -2037,7 +2037,7 @@ bool TokenAnnotator::spaceRequiredBefore
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_in, Keywords.kw_of))
return true;
if (Left.is(tok::kw_default) && Left.Previous &&
Left.Previous->is(tok::kw_export))
Modified: cfe/trunk/unittests/Format/FormatTestJS.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTestJS.cpp?rev=260518&r1=260517&r2=260518&view=diff
==============================================================================
--- cfe/trunk/unittests/Format/FormatTestJS.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTestJS.cpp Thu Feb 11 07:24:15 2016
@@ -595,6 +595,8 @@ TEST_F(FormatTestJS, ReturnStatements) {
TEST_F(FormatTestJS, ForLoops) {
verifyFormat("for (var i in [2, 3]) {\n"
"}");
+ verifyFormat("for (var i of [2, 3]) {\n"
+ "}");
}
TEST_F(FormatTestJS, AutomaticSemicolonInsertion) {
@@ -758,6 +760,7 @@ TEST_F(FormatTestJS, TypeAnnotations) {
verifyFormat("function x(): {x: string} {\n return {x: 'x'};\n}");
verifyFormat("function x(y: string): string {\n return 'x';\n}");
verifyFormat("for (var y: string in x) {\n x();\n}");
+ verifyFormat("for (var y: string of x) {\n x();\n}");
verifyFormat("function x(y: {a?: number;} = {}): number {\n"
" return 12;\n"
"}");
More information about the cfe-commits
mailing list