Skip to content

Commit 20347ad

Browse files
committed
Merge pull request #5597 from Microsoft/typesCleanup
Types cleanup
2 parents 13bc120 + 5ac4b78 commit 20347ad

File tree

5 files changed

+368
-122
lines changed

5 files changed

+368
-122
lines changed

src/compiler/checker.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -9879,7 +9879,7 @@ namespace ts {
98799879
return type;
98809880
}
98819881

9882-
function checkFunctionExpressionOrObjectLiteralMethodBody(node: FunctionExpression | MethodDeclaration) {
9882+
function checkFunctionExpressionOrObjectLiteralMethodBody(node: ArrowFunction | FunctionExpression | MethodDeclaration) {
98839883
Debug.assert(node.kind !== SyntaxKind.MethodDeclaration || isObjectLiteralMethod(node));
98849884

98859885
const isAsync = isAsyncFunctionLike(node);

src/compiler/parser.ts

+26-26
Original file line numberDiff line numberDiff line change
@@ -1157,7 +1157,7 @@ namespace ts {
11571157
}
11581158

11591159
function parseAnyContextualModifier(): boolean {
1160-
return isModifier(token) && tryParse(nextTokenCanFollowModifier);
1160+
return isModifierKind(token) && tryParse(nextTokenCanFollowModifier);
11611161
}
11621162

11631163
function canFollowModifier(): boolean {
@@ -2004,7 +2004,7 @@ namespace ts {
20042004
}
20052005

20062006
function isStartOfParameter(): boolean {
2007-
return token === SyntaxKind.DotDotDotToken || isIdentifierOrPattern() || isModifier(token) || token === SyntaxKind.AtToken;
2007+
return token === SyntaxKind.DotDotDotToken || isIdentifierOrPattern() || isModifierKind(token) || token === SyntaxKind.AtToken;
20082008
}
20092009

20102010
function setModifiers(node: Node, modifiers: ModifiersArray) {
@@ -2025,7 +2025,7 @@ namespace ts {
20252025

20262026
node.name = parseIdentifierOrPattern();
20272027

2028-
if (getFullWidth(node.name) === 0 && node.flags === 0 && isModifier(token)) {
2028+
if (getFullWidth(node.name) === 0 && node.flags === 0 && isModifierKind(token)) {
20292029
// in cases like
20302030
// 'use strict'
20312031
// function foo(static)
@@ -2132,8 +2132,8 @@ namespace ts {
21322132
parseSemicolon();
21332133
}
21342134

2135-
function parseSignatureMember(kind: SyntaxKind): SignatureDeclaration {
2136-
const node = <SignatureDeclaration>createNode(kind);
2135+
function parseSignatureMember(kind: SyntaxKind): CallSignatureDeclaration | ConstructSignatureDeclaration {
2136+
const node = <CallSignatureDeclaration | ConstructSignatureDeclaration>createNode(kind);
21372137
if (kind === SyntaxKind.ConstructSignature) {
21382138
parseExpected(SyntaxKind.NewKeyword);
21392139
}
@@ -2172,7 +2172,7 @@ namespace ts {
21722172
return true;
21732173
}
21742174

2175-
if (isModifier(token)) {
2175+
if (isModifierKind(token)) {
21762176
nextToken();
21772177
if (isIdentifier()) {
21782178
return true;
@@ -2215,13 +2215,13 @@ namespace ts {
22152215
return finishNode(node);
22162216
}
22172217

2218-
function parsePropertyOrMethodSignature(): Declaration {
2218+
function parsePropertyOrMethodSignature(): PropertySignature | MethodSignature {
22192219
const fullStart = scanner.getStartPos();
22202220
const name = parsePropertyName();
22212221
const questionToken = parseOptionalToken(SyntaxKind.QuestionToken);
22222222

22232223
if (token === SyntaxKind.OpenParenToken || token === SyntaxKind.LessThanToken) {
2224-
const method = <MethodDeclaration>createNode(SyntaxKind.MethodSignature, fullStart);
2224+
const method = <MethodSignature>createNode(SyntaxKind.MethodSignature, fullStart);
22252225
method.name = name;
22262226
method.questionToken = questionToken;
22272227

@@ -2232,7 +2232,7 @@ namespace ts {
22322232
return finishNode(method);
22332233
}
22342234
else {
2235-
const property = <PropertyDeclaration>createNode(SyntaxKind.PropertySignature, fullStart);
2235+
const property = <PropertySignature>createNode(SyntaxKind.PropertySignature, fullStart);
22362236
property.name = name;
22372237
property.questionToken = questionToken;
22382238
property.type = parseTypeAnnotation();
@@ -2248,7 +2248,7 @@ namespace ts {
22482248
case SyntaxKind.OpenBracketToken: // Both for indexers and computed properties
22492249
return true;
22502250
default:
2251-
if (isModifier(token)) {
2251+
if (isModifierKind(token)) {
22522252
const result = lookAhead(isStartOfIndexSignatureDeclaration);
22532253
if (result) {
22542254
return result;
@@ -2260,7 +2260,7 @@ namespace ts {
22602260
}
22612261

22622262
function isStartOfIndexSignatureDeclaration() {
2263-
while (isModifier(token)) {
2263+
while (isModifierKind(token)) {
22642264
nextToken();
22652265
}
22662266

@@ -2276,7 +2276,7 @@ namespace ts {
22762276
canParseSemicolon();
22772277
}
22782278

2279-
function parseTypeMember(): Declaration {
2279+
function parseTypeMember(): TypeElement {
22802280
switch (token) {
22812281
case SyntaxKind.OpenParenToken:
22822282
case SyntaxKind.LessThanToken:
@@ -2301,7 +2301,7 @@ namespace ts {
23012301
// when incrementally parsing as the parser will produce the Index declaration
23022302
// if it has the same text regardless of whether it is inside a class or an
23032303
// object type.
2304-
if (isModifier(token)) {
2304+
if (isModifierKind(token)) {
23052305
const result = tryParse(parseIndexSignatureWithModifiers);
23062306
if (result) {
23072307
return result;
@@ -2334,14 +2334,14 @@ namespace ts {
23342334
return finishNode(node);
23352335
}
23362336

2337-
function parseObjectTypeMembers(): NodeArray<Declaration> {
2338-
let members: NodeArray<Declaration>;
2337+
function parseObjectTypeMembers(): NodeArray<TypeElement> {
2338+
let members: NodeArray<TypeElement>;
23392339
if (parseExpected(SyntaxKind.OpenBraceToken)) {
23402340
members = parseList(ParsingContext.TypeMembers, parseTypeMember);
23412341
parseExpected(SyntaxKind.CloseBraceToken);
23422342
}
23432343
else {
2344-
members = createMissingList<Declaration>();
2344+
members = createMissingList<TypeElement>();
23452345
}
23462346

23472347
return members;
@@ -2483,11 +2483,11 @@ namespace ts {
24832483
// ( ...
24842484
return true;
24852485
}
2486-
if (isIdentifier() || isModifier(token)) {
2486+
if (isIdentifier() || isModifierKind(token)) {
24872487
nextToken();
24882488
if (token === SyntaxKind.ColonToken || token === SyntaxKind.CommaToken ||
24892489
token === SyntaxKind.QuestionToken || token === SyntaxKind.EqualsToken ||
2490-
isIdentifier() || isModifier(token)) {
2490+
isIdentifier() || isModifierKind(token)) {
24912491
// ( id :
24922492
// ( id ,
24932493
// ( id ?
@@ -2894,7 +2894,7 @@ namespace ts {
28942894
}
28952895

28962896
// This *could* be a parenthesized arrow function.
2897-
// Return Unknown to const the caller know.
2897+
// Return Unknown to let the caller know.
28982898
return Tristate.Unknown;
28992899
}
29002900
else {
@@ -2993,7 +2993,7 @@ namespace ts {
29932993
// user meant to supply a block. For example, if the user wrote:
29942994
//
29952995
// a =>
2996-
// const v = 0;
2996+
// let v = 0;
29972997
// }
29982998
//
29992999
// they may be missing an open brace. Check to see if that's the case so we can
@@ -3220,7 +3220,7 @@ namespace ts {
32203220

32213221
/**
32223222
* Parse ES7 unary expression and await expression
3223-
*
3223+
*
32243224
* ES7 UnaryExpression:
32253225
* 1) SimpleUnaryExpression[?yield]
32263226
* 2) IncrementExpression[?yield] ** UnaryExpression[?yield]
@@ -4720,7 +4720,7 @@ namespace ts {
47204720
return finishNode(node);
47214721
}
47224722

4723-
function parseMethodDeclaration(fullStart: number, decorators: NodeArray<Decorator>, modifiers: ModifiersArray, asteriskToken: Node, name: DeclarationName, questionToken: Node, diagnosticMessage?: DiagnosticMessage): MethodDeclaration {
4723+
function parseMethodDeclaration(fullStart: number, decorators: NodeArray<Decorator>, modifiers: ModifiersArray, asteriskToken: Node, name: PropertyName, questionToken: Node, diagnosticMessage?: DiagnosticMessage): MethodDeclaration {
47244724
const method = <MethodDeclaration>createNode(SyntaxKind.MethodDeclaration, fullStart);
47254725
method.decorators = decorators;
47264726
setModifiers(method, modifiers);
@@ -4734,7 +4734,7 @@ namespace ts {
47344734
return finishNode(method);
47354735
}
47364736

4737-
function parsePropertyDeclaration(fullStart: number, decorators: NodeArray<Decorator>, modifiers: ModifiersArray, name: DeclarationName, questionToken: Node): ClassElement {
4737+
function parsePropertyDeclaration(fullStart: number, decorators: NodeArray<Decorator>, modifiers: ModifiersArray, name: PropertyName, questionToken: Node): ClassElement {
47384738
const property = <PropertyDeclaration>createNode(SyntaxKind.PropertyDeclaration, fullStart);
47394739
property.decorators = decorators;
47404740
setModifiers(property, modifiers);
@@ -4808,7 +4808,7 @@ namespace ts {
48084808
}
48094809

48104810
// Eat up all modifiers, but hold on to the last one in case it is actually an identifier.
4811-
while (isModifier(token)) {
4811+
while (isModifierKind(token)) {
48124812
idToken = token;
48134813
// If the idToken is a class modifier (protected, private, public, and static), it is
48144814
// certain that we are starting to parse class member. This allows better error recovery
@@ -5018,8 +5018,8 @@ namespace ts {
50185018
// implements is a future reserved word so
50195019
// 'class implements' might mean either
50205020
// - class expression with omitted name, 'implements' starts heritage clause
5021-
// - class with name 'implements'
5022-
// 'isImplementsClause' helps to disambiguate between these two cases
5021+
// - class with name 'implements'
5022+
// 'isImplementsClause' helps to disambiguate between these two cases
50235023
return isIdentifier() && !isImplementsClause()
50245024
? parseIdentifier()
50255025
: undefined;

0 commit comments

Comments
 (0)