diff --git a/src/compiler/types.ts b/src/compiler/types.ts
index b396a0673aa..0133c83c422 100644
--- a/src/compiler/types.ts
+++ b/src/compiler/types.ts
@@ -142,7 +142,7 @@ module ts {
StringKeyword,
SymbolKeyword,
TypeKeyword,
- OfKeyword,
+ OfKeyword, // LastKeyword and LastToken
// Parse tree nodes
// Names
@@ -269,7 +269,7 @@ module ts {
FirstPunctuation = OpenBraceToken,
LastPunctuation = CaretEqualsToken,
FirstToken = Unknown,
- LastToken = TypeKeyword,
+ LastToken = OfKeyword,
FirstTriviaToken = SingleLineCommentTrivia,
LastTriviaToken = ConflictMarkerTrivia,
FirstLiteralToken = NumericLiteral,
diff --git a/src/services/formatting/rules.ts b/src/services/formatting/rules.ts
index bf7e3f3988a..b5470579787 100644
--- a/src/services/formatting/rules.ts
+++ b/src/services/formatting/rules.ts
@@ -464,6 +464,9 @@ module ts.formatting {
// "in" keyword in for (var x in []) { }
case SyntaxKind.ForInStatement:
return context.currentTokenSpan.kind === SyntaxKind.InKeyword || context.nextTokenSpan.kind === SyntaxKind.InKeyword;
+ // Technically, "of" is not a binary operator, but format it the same way as "in"
+ case SyntaxKind.ForOfStatement:
+ return context.currentTokenSpan.kind === SyntaxKind.OfKeyword || context.nextTokenSpan.kind === SyntaxKind.OfKeyword;
}
return false;
}
diff --git a/src/services/formatting/tokenRange.ts b/src/services/formatting/tokenRange.ts
index 6dace543eab..ff9cb91ce68 100644
--- a/src/services/formatting/tokenRange.ts
+++ b/src/services/formatting/tokenRange.ts
@@ -126,7 +126,7 @@ module ts.formatting {
static AnyIncludingMultilineComments = TokenRange.FromTokens(TokenRange.Any.GetTokens().concat([SyntaxKind.MultiLineCommentTrivia]));
static Keywords = TokenRange.FromRange(SyntaxKind.FirstKeyword, SyntaxKind.LastKeyword);
static BinaryOperators = TokenRange.FromRange(SyntaxKind.FirstBinaryOperator, SyntaxKind.LastBinaryOperator);
- static BinaryKeywordOperators = TokenRange.FromTokens([SyntaxKind.InKeyword, SyntaxKind.InstanceOfKeyword]);
+ static BinaryKeywordOperators = TokenRange.FromTokens([SyntaxKind.InKeyword, SyntaxKind.InstanceOfKeyword, SyntaxKind.OfKeyword]);
static UnaryPrefixOperators = TokenRange.FromTokens([SyntaxKind.PlusPlusToken, SyntaxKind.MinusMinusToken, SyntaxKind.TildeToken, SyntaxKind.ExclamationToken]);
static UnaryPrefixExpressions = TokenRange.FromTokens([SyntaxKind.NumericLiteral, SyntaxKind.Identifier, SyntaxKind.OpenParenToken, SyntaxKind.OpenBracketToken, SyntaxKind.OpenBraceToken, SyntaxKind.ThisKeyword, SyntaxKind.NewKeyword]);
static UnaryPreincrementExpressions = TokenRange.FromTokens([SyntaxKind.Identifier, SyntaxKind.OpenParenToken, SyntaxKind.ThisKeyword, SyntaxKind.NewKeyword]);
diff --git a/tests/baselines/reference/APISample_compile.js b/tests/baselines/reference/APISample_compile.js
index a1d695f5105..f951a955b29 100644
--- a/tests/baselines/reference/APISample_compile.js
+++ b/tests/baselines/reference/APISample_compile.js
@@ -285,7 +285,7 @@ declare module "typescript" {
FirstPunctuation = 14,
LastPunctuation = 63,
FirstToken = 0,
- LastToken = 121,
+ LastToken = 122,
FirstTriviaToken = 2,
LastTriviaToken = 6,
FirstLiteralToken = 7,
diff --git a/tests/baselines/reference/APISample_compile.types b/tests/baselines/reference/APISample_compile.types
index e2e75843311..7a1a306b989 100644
--- a/tests/baselines/reference/APISample_compile.types
+++ b/tests/baselines/reference/APISample_compile.types
@@ -871,7 +871,7 @@ declare module "typescript" {
FirstToken = 0,
>FirstToken : SyntaxKind
- LastToken = 121,
+ LastToken = 122,
>LastToken : SyntaxKind
FirstTriviaToken = 2,
diff --git a/tests/baselines/reference/APISample_linter.js b/tests/baselines/reference/APISample_linter.js
index f7c81601bc8..9631a755165 100644
--- a/tests/baselines/reference/APISample_linter.js
+++ b/tests/baselines/reference/APISample_linter.js
@@ -316,7 +316,7 @@ declare module "typescript" {
FirstPunctuation = 14,
LastPunctuation = 63,
FirstToken = 0,
- LastToken = 121,
+ LastToken = 122,
FirstTriviaToken = 2,
LastTriviaToken = 6,
FirstLiteralToken = 7,
diff --git a/tests/baselines/reference/APISample_linter.types b/tests/baselines/reference/APISample_linter.types
index 722fa806346..8caa6855e84 100644
--- a/tests/baselines/reference/APISample_linter.types
+++ b/tests/baselines/reference/APISample_linter.types
@@ -1015,7 +1015,7 @@ declare module "typescript" {
FirstToken = 0,
>FirstToken : SyntaxKind
- LastToken = 121,
+ LastToken = 122,
>LastToken : SyntaxKind
FirstTriviaToken = 2,
diff --git a/tests/baselines/reference/APISample_transform.js b/tests/baselines/reference/APISample_transform.js
index daa00de9cb3..2ccf48a5e6c 100644
--- a/tests/baselines/reference/APISample_transform.js
+++ b/tests/baselines/reference/APISample_transform.js
@@ -317,7 +317,7 @@ declare module "typescript" {
FirstPunctuation = 14,
LastPunctuation = 63,
FirstToken = 0,
- LastToken = 121,
+ LastToken = 122,
FirstTriviaToken = 2,
LastTriviaToken = 6,
FirstLiteralToken = 7,
diff --git a/tests/baselines/reference/APISample_transform.types b/tests/baselines/reference/APISample_transform.types
index 157691c6818..60ebae5472d 100644
--- a/tests/baselines/reference/APISample_transform.types
+++ b/tests/baselines/reference/APISample_transform.types
@@ -967,7 +967,7 @@ declare module "typescript" {
FirstToken = 0,
>FirstToken : SyntaxKind
- LastToken = 121,
+ LastToken = 122,
>LastToken : SyntaxKind
FirstTriviaToken = 2,
diff --git a/tests/baselines/reference/APISample_watcher.js b/tests/baselines/reference/APISample_watcher.js
index 177f08f381f..530f081c77a 100644
--- a/tests/baselines/reference/APISample_watcher.js
+++ b/tests/baselines/reference/APISample_watcher.js
@@ -354,7 +354,7 @@ declare module "typescript" {
FirstPunctuation = 14,
LastPunctuation = 63,
FirstToken = 0,
- LastToken = 121,
+ LastToken = 122,
FirstTriviaToken = 2,
LastTriviaToken = 6,
FirstLiteralToken = 7,
diff --git a/tests/baselines/reference/APISample_watcher.types b/tests/baselines/reference/APISample_watcher.types
index 1c153bfac39..ec48d879968 100644
--- a/tests/baselines/reference/APISample_watcher.types
+++ b/tests/baselines/reference/APISample_watcher.types
@@ -1140,7 +1140,7 @@ declare module "typescript" {
FirstToken = 0,
>FirstToken : SyntaxKind
- LastToken = 121,
+ LastToken = 122,
>LastToken : SyntaxKind
FirstTriviaToken = 2,
diff --git a/tests/cases/fourslash/formattingForOfKeyword.ts b/tests/cases/fourslash/formattingForOfKeyword.ts
new file mode 100644
index 00000000000..33b3d83c00f
--- /dev/null
+++ b/tests/cases/fourslash/formattingForOfKeyword.ts
@@ -0,0 +1,8 @@
+///
+
+/////**/for ([]of[]) { }
+
+
+format.document();
+goTo.marker();
+verify.currentLineContentIs('for ([] of []) { }');
\ No newline at end of file
diff --git a/tests/cases/fourslash/syntacticClassificationsForOfKeyword.ts b/tests/cases/fourslash/syntacticClassificationsForOfKeyword.ts
new file mode 100644
index 00000000000..a7a8c704ce6
--- /dev/null
+++ b/tests/cases/fourslash/syntacticClassificationsForOfKeyword.ts
@@ -0,0 +1,16 @@
+///
+
+//// for (var of of of) { }
+
+var c = classification;
+verify.syntacticClassificationsAre(
+ c.keyword("for"),
+ c.punctuation("("),
+ c.keyword("var"),
+ c.text("of"),
+ c.keyword("of"),
+ c.text("of"),
+ c.punctuation(")"),
+ c.punctuation("{"),
+ c.punctuation("}")
+ );
\ No newline at end of file
diff --git a/tests/cases/fourslash/syntacticClassificationsForOfKeyword2.ts b/tests/cases/fourslash/syntacticClassificationsForOfKeyword2.ts
new file mode 100644
index 00000000000..30cfaea51e0
--- /dev/null
+++ b/tests/cases/fourslash/syntacticClassificationsForOfKeyword2.ts
@@ -0,0 +1,16 @@
+///
+
+//// for (var of in of) { }
+
+var c = classification;
+verify.syntacticClassificationsAre(
+ c.keyword("for"),
+ c.punctuation("("),
+ c.keyword("var"),
+ c.text("of"),
+ c.keyword("in"),
+ c.text("of"),
+ c.punctuation(")"),
+ c.punctuation("{"),
+ c.punctuation("}")
+ );
\ No newline at end of file
diff --git a/tests/cases/fourslash/syntacticClassificationsForOfKeyword3.ts b/tests/cases/fourslash/syntacticClassificationsForOfKeyword3.ts
new file mode 100644
index 00000000000..3af4733f3b2
--- /dev/null
+++ b/tests/cases/fourslash/syntacticClassificationsForOfKeyword3.ts
@@ -0,0 +1,18 @@
+///
+
+//// for (var of; of; of) { }
+
+var c = classification;
+verify.syntacticClassificationsAre(
+ c.keyword("for"),
+ c.punctuation("("),
+ c.keyword("var"),
+ c.text("of"),
+ c.punctuation(";"),
+ c.text("of"),
+ c.punctuation(";"),
+ c.text("of"),
+ c.punctuation(")"),
+ c.punctuation("{"),
+ c.punctuation("}")
+ );
\ No newline at end of file
diff --git a/tests/cases/unittests/services/colorization.ts b/tests/cases/unittests/services/colorization.ts
index 890ced3b891..6c685cdb174 100644
--- a/tests/cases/unittests/services/colorization.ts
+++ b/tests/cases/unittests/services/colorization.ts
@@ -430,5 +430,20 @@ class D { }\r\n\
comment(">>>>>>> Branch - a"),
finalEndOfLineState(ts.EndOfLineState.Start));
});
+
+ it("'of' keyword", function () {
+ testLexicalClassification("for (var of of of) { }",
+ ts.EndOfLineState.Start,
+ keyword("for"),
+ punctuation("("),
+ keyword("var"),
+ keyword("of"),
+ keyword("of"),
+ keyword("of"),
+ punctuation(")"),
+ punctuation("{"),
+ punctuation("}"),
+ finalEndOfLineState(ts.EndOfLineState.Start));
+ });
});
});
\ No newline at end of file