forked from OSchip/llvm-project
clang-format: [JS] Support for (.. of ..) loops.
Before: for (var i of[2, 3]) {} After: for (var i of [2, 3]) {} llvm-svn: 260518
This commit is contained in:
parent
602a727add
commit
b7fda11572
|
@ -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;
|
||||
|
|
|
@ -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))
|
||||
|
|
|
@ -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"
|
||||
"}");
|
||||
|
|
Loading…
Reference in New Issue