diff --git a/clang/lib/Format/FormatToken.h b/clang/lib/Format/FormatToken.h index b683660f350a..980c7be81d6b 100644 --- a/clang/lib/Format/FormatToken.h +++ b/clang/lib/Format/FormatToken.h @@ -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; diff --git a/clang/lib/Format/TokenAnnotator.cpp b/clang/lib/Format/TokenAnnotator.cpp index 9dcda5d3839e..d5d7146aaa41 100644 --- a/clang/lib/Format/TokenAnnotator.cpp +++ b/clang/lib/Format/TokenAnnotator.cpp @@ -2037,7 +2037,7 @@ bool TokenAnnotator::spaceRequiredBefore(const AnnotatedLine &Line, 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)) diff --git a/clang/unittests/Format/FormatTestJS.cpp b/clang/unittests/Format/FormatTestJS.cpp index 7fad83aab12a..e08c876a5c67 100644 --- a/clang/unittests/Format/FormatTestJS.cpp +++ b/clang/unittests/Format/FormatTestJS.cpp @@ -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" "}");