Skip to content

Commit d45fb77

Browse files
Renamed certain functions in the parser to more accurately reflect behavior.
1 parent 8786d30 commit d45fb77

File tree

1 file changed

+24
-24
lines changed

1 file changed

+24
-24
lines changed

src/compiler/parser.ts

+24-24
Original file line numberDiff line numberDiff line change
@@ -1161,7 +1161,7 @@ module ts {
11611161
case ParsingContext.SwitchClauses:
11621162
return token === SyntaxKind.CaseKeyword || token === SyntaxKind.DefaultKeyword;
11631163
case ParsingContext.TypeMembers:
1164-
return isTypeMember();
1164+
return isStartOfTypeMember();
11651165
case ParsingContext.ClassMembers:
11661166
return lookAhead(isClassMemberStart);
11671167
case ParsingContext.EnumMembers:
@@ -1173,14 +1173,14 @@ module ts {
11731173
case ParsingContext.TypeParameters:
11741174
return isIdentifier();
11751175
case ParsingContext.ArgumentExpressions:
1176-
return token === SyntaxKind.CommaToken || isExpression();
1176+
return token === SyntaxKind.CommaToken || isStartOfExpression();
11771177
case ParsingContext.ArrayLiteralMembers:
1178-
return token === SyntaxKind.CommaToken || isExpression();
1178+
return token === SyntaxKind.CommaToken || isStartOfExpression();
11791179
case ParsingContext.Parameters:
1180-
return isParameter();
1180+
return isStartOfParameter();
11811181
case ParsingContext.TypeArguments:
11821182
case ParsingContext.TupleElementTypes:
1183-
return token === SyntaxKind.CommaToken || isType();
1183+
return token === SyntaxKind.CommaToken || isStartOfType();
11841184
}
11851185

11861186
Debug.fail("Non-exhaustive case in 'isListElement'.");
@@ -1505,7 +1505,7 @@ module ts {
15051505
// user writes a constraint that is an expression and not an actual type, then parse
15061506
// it out as an expression (so we can recover well), but report that a type is needed
15071507
// instead.
1508-
if (isType() || !isExpression()) {
1508+
if (isStartOfType() || !isStartOfExpression()) {
15091509
node.constraint = parseType();
15101510
}
15111511
else {
@@ -1541,7 +1541,7 @@ module ts {
15411541
return parseOptional(SyntaxKind.ColonToken) ? token === SyntaxKind.StringLiteral ? parseStringLiteral() : parseType() : undefined;
15421542
}
15431543

1544-
function isParameter(): boolean {
1544+
function isStartOfParameter(): boolean {
15451545
return token === SyntaxKind.DotDotDotToken || isIdentifier() || isModifier(token);
15461546
}
15471547

@@ -1749,7 +1749,7 @@ module ts {
17491749
return finishNode(node);
17501750
}
17511751

1752-
function isTypeMember(): boolean {
1752+
function isStartOfTypeMember(): boolean {
17531753
switch (token) {
17541754
case SyntaxKind.OpenParenToken:
17551755
case SyntaxKind.LessThanToken:
@@ -1856,7 +1856,7 @@ module ts {
18561856
return <TypeNode>createMissingNode();
18571857
}
18581858

1859-
function isType(): boolean {
1859+
function isStartOfType(): boolean {
18601860
switch (token) {
18611861
case SyntaxKind.AnyKeyword:
18621862
case SyntaxKind.StringKeyword:
@@ -1874,7 +1874,7 @@ module ts {
18741874
// or something that starts a type. We don't want to consider things like '(1)' a type.
18751875
return lookAhead(() => {
18761876
nextToken();
1877-
return token === SyntaxKind.CloseParenToken || isParameter() || isType();
1877+
return token === SyntaxKind.CloseParenToken || isStartOfParameter() || isStartOfType();
18781878
});
18791879
default:
18801880
return isIdentifier();
@@ -1908,7 +1908,7 @@ module ts {
19081908
return type;
19091909
}
19101910

1911-
function isFunctionType(): boolean {
1911+
function isStartOfFunctionType(): boolean {
19121912
return token === SyntaxKind.LessThanToken || token === SyntaxKind.OpenParenToken && lookAhead(() => {
19131913
nextToken();
19141914
if (token === SyntaxKind.CloseParenToken || token === SyntaxKind.DotDotDotToken) {
@@ -1941,7 +1941,7 @@ module ts {
19411941
}
19421942

19431943
function parseType(): TypeNode {
1944-
if (isFunctionType()) {
1944+
if (isStartOfFunctionType()) {
19451945
return parseFunctionType(SyntaxKind.CallSignature);
19461946
}
19471947
if (token === SyntaxKind.NewKeyword) {
@@ -1956,7 +1956,7 @@ module ts {
19561956

19571957
// EXPRESSIONS
19581958

1959-
function isExpression(): boolean {
1959+
function isStartOfExpression(): boolean {
19601960
switch (token) {
19611961
case SyntaxKind.ThisKeyword:
19621962
case SyntaxKind.SuperKeyword:
@@ -1991,9 +1991,9 @@ module ts {
19911991
}
19921992
}
19931993

1994-
function isExpressionStatement(): boolean {
1994+
function isStartOfExpressionStatement(): boolean {
19951995
// As per the grammar, neither '{' nor 'function' can start an expression statement.
1996-
return token !== SyntaxKind.OpenBraceToken && token !== SyntaxKind.FunctionKeyword && isExpression();
1996+
return token !== SyntaxKind.OpenBraceToken && token !== SyntaxKind.FunctionKeyword && isStartOfExpression();
19971997
}
19981998

19991999
function parseExpression(noIn?: boolean): Expression {
@@ -2014,7 +2014,7 @@ module ts {
20142014
// it's more likely that a { would be a allowed (as an object literal). While this
20152015
// is also allowed for parameters, the risk is that we consume the { as an object
20162016
// literal when it really will be for the block following the parameter.
2017-
if (scanner.hasPrecedingLineBreak() || (inParameter && token === SyntaxKind.OpenBraceToken) || !isExpression()) {
2017+
if (scanner.hasPrecedingLineBreak() || (inParameter && token === SyntaxKind.OpenBraceToken) || !isStartOfExpression()) {
20182018
// preceding line break, open brace in a parameter (likely a function body) or current token is not an expression -
20192019
// do not try to parse initializer
20202020
return undefined;
@@ -2262,7 +2262,7 @@ module ts {
22622262
if (token === SyntaxKind.OpenBraceToken) {
22632263
body = parseBody(/* ignoreMissingOpenBrace */ false);
22642264
}
2265-
else if (isStatement(/* inErrorRecovery */ true) && !isExpressionStatement() && token !== SyntaxKind.FunctionKeyword) {
2265+
else if (isStatement(/* inErrorRecovery */ true) && !isStartOfExpressionStatement() && token !== SyntaxKind.FunctionKeyword) {
22662266
// Check if we got a plain statement (i.e. no expression-statements, no functions expressions/declarations)
22672267
//
22682268
// Here we try to recover from a potential error situation in the case where the
@@ -3267,7 +3267,7 @@ module ts {
32673267
case SyntaxKind.EnumKeyword:
32683268
// When followed by an identifier, these do not start a statement but might
32693269
// instead be following declarations
3270-
if (isDeclaration()) {
3270+
if (isDeclarationStart()) {
32713271
return false;
32723272
}
32733273
case SyntaxKind.PublicKeyword:
@@ -3280,7 +3280,7 @@ module ts {
32803280
return false;
32813281
}
32823282
default:
3283-
return isExpression();
3283+
return isStartOfExpression();
32843284
}
32853285
}
32863286

@@ -3993,7 +3993,7 @@ module ts {
39933993
return finishNode(node);
39943994
}
39953995

3996-
function isDeclaration(): boolean {
3996+
function isDeclarationStart(): boolean {
39973997
switch (token) {
39983998
case SyntaxKind.VarKeyword:
39993999
case SyntaxKind.LetKeyword:
@@ -4011,14 +4011,14 @@ module ts {
40114011
return lookAhead(() => nextToken() >= SyntaxKind.Identifier || token === SyntaxKind.StringLiteral);
40124012
case SyntaxKind.ExportKeyword:
40134013
// Check for export assignment or modifier on source element
4014-
return lookAhead(() => nextToken() === SyntaxKind.EqualsToken || isDeclaration());
4014+
return lookAhead(() => nextToken() === SyntaxKind.EqualsToken || isDeclarationStart());
40154015
case SyntaxKind.DeclareKeyword:
40164016
case SyntaxKind.PublicKeyword:
40174017
case SyntaxKind.PrivateKeyword:
40184018
case SyntaxKind.ProtectedKeyword:
40194019
case SyntaxKind.StaticKeyword:
40204020
// Check for modifier on source element
4021-
return lookAhead(() => { nextToken(); return isDeclaration(); });
4021+
return lookAhead(() => { nextToken(); return isDeclarationStart(); });
40224022
}
40234023
}
40244024

@@ -4079,7 +4079,7 @@ module ts {
40794079
}
40804080

40814081
function isSourceElement(inErrorRecovery: boolean): boolean {
4082-
return isDeclaration() || isStatement(inErrorRecovery);
4082+
return isDeclarationStart() || isStatement(inErrorRecovery);
40834083
}
40844084

40854085
function parseSourceElement() {
@@ -4091,7 +4091,7 @@ module ts {
40914091
}
40924092

40934093
function parseSourceElementOrModuleElement(modifierContext: ModifierContext): Statement {
4094-
if (isDeclaration()) {
4094+
if (isDeclarationStart()) {
40954095
return parseDeclaration(modifierContext);
40964096
}
40974097

0 commit comments

Comments
 (0)