mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-02-11 10:00:13 -06:00
Merge pull request #2086 from Microsoft/ofKeywordClassification
Of keyword classification
This commit is contained in:
commit
791e91351c
@ -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,
|
||||
|
||||
@ -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;
|
||||
}
|
||||
|
||||
@ -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]);
|
||||
|
||||
@ -285,7 +285,7 @@ declare module "typescript" {
|
||||
FirstPunctuation = 14,
|
||||
LastPunctuation = 63,
|
||||
FirstToken = 0,
|
||||
LastToken = 121,
|
||||
LastToken = 122,
|
||||
FirstTriviaToken = 2,
|
||||
LastTriviaToken = 6,
|
||||
FirstLiteralToken = 7,
|
||||
|
||||
@ -871,7 +871,7 @@ declare module "typescript" {
|
||||
FirstToken = 0,
|
||||
>FirstToken : SyntaxKind
|
||||
|
||||
LastToken = 121,
|
||||
LastToken = 122,
|
||||
>LastToken : SyntaxKind
|
||||
|
||||
FirstTriviaToken = 2,
|
||||
|
||||
@ -316,7 +316,7 @@ declare module "typescript" {
|
||||
FirstPunctuation = 14,
|
||||
LastPunctuation = 63,
|
||||
FirstToken = 0,
|
||||
LastToken = 121,
|
||||
LastToken = 122,
|
||||
FirstTriviaToken = 2,
|
||||
LastTriviaToken = 6,
|
||||
FirstLiteralToken = 7,
|
||||
|
||||
@ -1015,7 +1015,7 @@ declare module "typescript" {
|
||||
FirstToken = 0,
|
||||
>FirstToken : SyntaxKind
|
||||
|
||||
LastToken = 121,
|
||||
LastToken = 122,
|
||||
>LastToken : SyntaxKind
|
||||
|
||||
FirstTriviaToken = 2,
|
||||
|
||||
@ -317,7 +317,7 @@ declare module "typescript" {
|
||||
FirstPunctuation = 14,
|
||||
LastPunctuation = 63,
|
||||
FirstToken = 0,
|
||||
LastToken = 121,
|
||||
LastToken = 122,
|
||||
FirstTriviaToken = 2,
|
||||
LastTriviaToken = 6,
|
||||
FirstLiteralToken = 7,
|
||||
|
||||
@ -967,7 +967,7 @@ declare module "typescript" {
|
||||
FirstToken = 0,
|
||||
>FirstToken : SyntaxKind
|
||||
|
||||
LastToken = 121,
|
||||
LastToken = 122,
|
||||
>LastToken : SyntaxKind
|
||||
|
||||
FirstTriviaToken = 2,
|
||||
|
||||
@ -354,7 +354,7 @@ declare module "typescript" {
|
||||
FirstPunctuation = 14,
|
||||
LastPunctuation = 63,
|
||||
FirstToken = 0,
|
||||
LastToken = 121,
|
||||
LastToken = 122,
|
||||
FirstTriviaToken = 2,
|
||||
LastTriviaToken = 6,
|
||||
FirstLiteralToken = 7,
|
||||
|
||||
@ -1140,7 +1140,7 @@ declare module "typescript" {
|
||||
FirstToken = 0,
|
||||
>FirstToken : SyntaxKind
|
||||
|
||||
LastToken = 121,
|
||||
LastToken = 122,
|
||||
>LastToken : SyntaxKind
|
||||
|
||||
FirstTriviaToken = 2,
|
||||
|
||||
8
tests/cases/fourslash/formattingForOfKeyword.ts
Normal file
8
tests/cases/fourslash/formattingForOfKeyword.ts
Normal file
@ -0,0 +1,8 @@
|
||||
/// <reference path='fourslash.ts' />
|
||||
|
||||
/////**/for ([]of[]) { }
|
||||
|
||||
|
||||
format.document();
|
||||
goTo.marker();
|
||||
verify.currentLineContentIs('for ([] of []) { }');
|
||||
@ -0,0 +1,16 @@
|
||||
/// <reference path="fourslash.ts"/>
|
||||
|
||||
//// 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("}")
|
||||
);
|
||||
@ -0,0 +1,16 @@
|
||||
/// <reference path="fourslash.ts"/>
|
||||
|
||||
//// 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("}")
|
||||
);
|
||||
@ -0,0 +1,18 @@
|
||||
/// <reference path="fourslash.ts"/>
|
||||
|
||||
//// 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("}")
|
||||
);
|
||||
@ -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));
|
||||
});
|
||||
});
|
||||
});
|
||||
Loading…
x
Reference in New Issue
Block a user