Skip to content

Commit 8bf176a

Browse files
committed
Cleanup and reorganization of node tests
1 parent f8e574f commit 8bf176a

14 files changed

Lines changed: 966 additions & 887 deletions

File tree

src/compiler/binder.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1696,7 +1696,7 @@ namespace ts {
16961696
case Reachability.Unreachable:
16971697
const reportError =
16981698
// report error on all statements except empty ones
1699-
(isStatement(node) && node.kind !== SyntaxKind.EmptyStatement) ||
1699+
(isStatementButNotDeclaration(node) && node.kind !== SyntaxKind.EmptyStatement) ||
17001700
// report error on class declarations
17011701
node.kind === SyntaxKind.ClassDeclaration ||
17021702
// report error on instantiated modules or const-enums only modules if preserveConstEnums is set

src/compiler/checker.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4934,7 +4934,7 @@ namespace ts {
49344934
case SyntaxKind.JSDocRecordType:
49354935
return getTypeFromTypeLiteralOrFunctionOrConstructorTypeNode(node);
49364936
// This function assumes that an identifier or qualified name is a type expression
4937-
// Callers should first ensure this by calling isTypeNode
4937+
// Callers should first ensure this by calling isPartOfTypeNode
49384938
case SyntaxKind.Identifier:
49394939
case SyntaxKind.QualifiedName:
49404940
const symbol = getSymbolAtLocation(node);
@@ -15385,7 +15385,7 @@ namespace ts {
1538515385
(entityName.parent.kind === SyntaxKind.JsxClosingElement)) {
1538615386
return getJsxElementTagSymbol(<JsxOpeningLikeElement>entityName.parent);
1538715387
}
15388-
else if (isExpression(entityName)) {
15388+
else if (isPartOfExpression(entityName)) {
1538915389
if (nodeIsMissing(entityName)) {
1539015390
// Missing entity name.
1539115391
return undefined;
@@ -15468,7 +15468,7 @@ namespace ts {
1546815468

1546915469
case SyntaxKind.ThisKeyword:
1547015470
case SyntaxKind.SuperKeyword:
15471-
const type = isExpression(node) ? checkExpression(<Expression>node) : getTypeFromTypeNode(<TypeNode>node);
15471+
const type = isPartOfExpression(node) ? checkExpression(<Expression>node) : getTypeFromTypeNode(<TypeNode>node);
1547215472
return type.symbol;
1547315473

1547415474
case SyntaxKind.ThisType:
@@ -15529,11 +15529,11 @@ namespace ts {
1552915529
return unknownType;
1553015530
}
1553115531

15532-
if (isTypeNode(node)) {
15532+
if (isPartOfTypeNode(node)) {
1553315533
return getTypeFromTypeNode(<TypeNode>node);
1553415534
}
1553515535

15536-
if (isExpression(node)) {
15536+
if (isPartOfExpression(node)) {
1553715537
return getTypeOfExpression(<Expression>node);
1553815538
}
1553915539

src/compiler/emitter.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1020,7 +1020,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
10201020
return;
10211021
}
10221022

1023-
const emitOuterParens = isExpression(node.parent)
1023+
const emitOuterParens = isPartOfExpression(node.parent)
10241024
&& templateNeedsParens(node, <Expression>node.parent);
10251025

10261026
if (emitOuterParens) {
@@ -5788,7 +5788,7 @@ const _super = (function (geti, seti) {
57885788
/** Serializes a TypeReferenceNode to an appropriate JS constructor value. Used by the __metadata decorator. */
57895789
function emitSerializedTypeReferenceNode(node: TypeReferenceNode) {
57905790
let location: Node = node.parent;
5791-
while (isDeclaration(location) || isTypeNode(location)) {
5791+
while (isDeclaration(location) || isPartOfTypeNode(location)) {
57925792
location = location.parent;
57935793
}
57945794

@@ -7156,7 +7156,7 @@ const _super = (function (geti, seti) {
71567156
}
71577157

71587158
// text should be quoted string
7159-
// for deduplication purposes in key remove leading and trailing quotes so 'a' and "a" will be considered the same
7159+
// for deduplication purposes in key remove leading and trailing quotes so 'a' and "a" will be considered the same
71607160
const key = text.substr(1, text.length - 2);
71617161

71627162
if (hasProperty(groupIndices, key)) {

src/compiler/factory.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,4 +134,5 @@ namespace ts {
134134
block.statements = createNodeArray(statements);
135135
return block;
136136
}
137+
137138
}

src/compiler/program.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1719,7 +1719,7 @@ namespace ts {
17191719
programDiagnostics.add(createCompilerDiagnostic(Diagnostics.Option_0_cannot_be_specified_without_specifying_option_1, "emitDecoratorMetadata", "experimentalDecorators"));
17201720
}
17211721

1722-
if (options.reactNamespace && !isIdentifier(options.reactNamespace, languageVersion)) {
1722+
if (options.reactNamespace && !isIdentifierText(options.reactNamespace, languageVersion)) {
17231723
programDiagnostics.add(createCompilerDiagnostic(Diagnostics.Invalid_value_for_reactNamespace_0_is_not_a_valid_identifier, options.reactNamespace));
17241724
}
17251725

src/compiler/scanner.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -696,7 +696,7 @@ namespace ts {
696696
}
697697

698698
/* @internal */
699-
export function isIdentifier(name: string, languageVersion: ScriptTarget): boolean {
699+
export function isIdentifierText(name: string, languageVersion: ScriptTarget): boolean {
700700
if (!isIdentifierStart(name.charCodeAt(0), languageVersion)) {
701701
return false;
702702
}

src/compiler/types.ts

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -553,10 +553,12 @@ namespace ts {
553553
// @kind(SyntaxKind.ConstructSignature)
554554
export interface ConstructSignatureDeclaration extends SignatureDeclaration, TypeElement { }
555555

556+
export type BindingName = Identifier | ObjectBindingPattern | ArrayBindingPattern;
557+
556558
// @kind(SyntaxKind.VariableDeclaration)
557559
export interface VariableDeclaration extends Declaration {
558560
parent?: VariableDeclarationList;
559-
name: Identifier | BindingPattern; // Declared variable name
561+
name: BindingName; // Declared variable name
560562
type?: TypeNode; // Optional type annotation
561563
initializer?: Expression; // Optional initializer
562564
}
@@ -569,7 +571,7 @@ namespace ts {
569571
// @kind(SyntaxKind.Parameter)
570572
export interface ParameterDeclaration extends Declaration {
571573
dotDotDotToken?: Node; // Present on rest parameter
572-
name: Identifier | BindingPattern; // Declared parameter name
574+
name: BindingName; // Declared parameter name
573575
questionToken?: Node; // Present on optional parameter
574576
type?: TypeNode; // Optional type annotation
575577
initializer?: Expression; // Optional initializer
@@ -579,7 +581,7 @@ namespace ts {
579581
export interface BindingElement extends Declaration {
580582
propertyName?: PropertyName; // Binding property name (in object binding pattern)
581583
dotDotDotToken?: Node; // Present on rest binding element
582-
name: Identifier | BindingPattern; // Declared binding element name
584+
name: BindingName; // Declared binding element name
583585
initializer?: Expression; // Optional initializer
584586
}
585587

@@ -946,6 +948,8 @@ namespace ts {
946948
_templateLiteralFragmentBrand: any;
947949
}
948950

951+
export type Template = TemplateExpression | LiteralExpression;
952+
949953
// @kind(SyntaxKind.TemplateExpression)
950954
export interface TemplateExpression extends PrimaryExpression {
951955
head: TemplateLiteralFragment;
@@ -1017,7 +1021,7 @@ namespace ts {
10171021
// @kind(SyntaxKind.TaggedTemplateExpression)
10181022
export interface TaggedTemplateExpression extends MemberExpression {
10191023
tag: LeftHandSideExpression;
1020-
template: LiteralExpression | TemplateExpression;
1024+
template: Template;
10211025
}
10221026

10231027
export type CallLikeExpression = CallExpression | NewExpression | TaggedTemplateExpression | Decorator;
@@ -1049,7 +1053,7 @@ namespace ts {
10491053
export interface JsxOpeningElement extends Expression {
10501054
_openingElementBrand?: any;
10511055
tagName: EntityName;
1052-
attributes: NodeArray<JsxAttribute | JsxSpreadAttribute>;
1056+
attributes: NodeArray<JsxAttributeLike>;
10531057
}
10541058

10551059
/// A JSX expression of the form <TagName attrs />
@@ -1061,6 +1065,8 @@ namespace ts {
10611065
/// Either the opening tag in a <Tag>...</Tag> pair, or the lone <Tag /> in a self-closing form
10621066
export type JsxOpeningLikeElement = JsxSelfClosingElement | JsxOpeningElement;
10631067

1068+
export type JsxAttributeLike = JsxAttribute | JsxSpreadAttribute;
1069+
10641070
// @kind(SyntaxKind.JsxAttribute)
10651071
export interface JsxAttribute extends Node {
10661072
name: Identifier;
@@ -1143,22 +1149,24 @@ namespace ts {
11431149
expression: Expression;
11441150
}
11451151

1152+
export type ForInitializer = VariableDeclarationList | Expression;
1153+
11461154
// @kind(SyntaxKind.ForStatement)
11471155
export interface ForStatement extends IterationStatement {
1148-
initializer?: VariableDeclarationList | Expression;
1156+
initializer?: ForInitializer;
11491157
condition?: Expression;
11501158
incrementor?: Expression;
11511159
}
11521160

11531161
// @kind(SyntaxKind.ForInStatement)
11541162
export interface ForInStatement extends IterationStatement {
1155-
initializer: VariableDeclarationList | Expression;
1163+
initializer: ForInitializer;
11561164
expression: Expression;
11571165
}
11581166

11591167
// @kind(SyntaxKind.ForOfStatement)
11601168
export interface ForOfStatement extends IterationStatement {
1161-
initializer: VariableDeclarationList | Expression;
1169+
initializer: ForInitializer;
11621170
expression: Expression;
11631171
}
11641172

@@ -1297,9 +1305,11 @@ namespace ts {
12971305

12981306
export type ModuleBody = ModuleBlock | ModuleDeclaration;
12991307

1308+
export type ModuleName = Identifier | StringLiteral;
1309+
13001310
// @kind(SyntaxKind.ModuleDeclaration)
13011311
export interface ModuleDeclaration extends DeclarationStatement {
1302-
name: Identifier | LiteralExpression;
1312+
name: ModuleName;
13031313
body: ModuleBlock | ModuleDeclaration;
13041314
}
13051315

@@ -1334,6 +1344,8 @@ namespace ts {
13341344
moduleSpecifier: Expression;
13351345
}
13361346

1347+
export type NamedImportBindings = NamespaceImport | NamedImports;
1348+
13371349
// In case of:
13381350
// import d from "mod" => name = d, namedBinding = undefined
13391351
// import * as ns from "mod" => name = undefined, namedBinding: NamespaceImport = { name: ns }
@@ -1343,7 +1355,7 @@ namespace ts {
13431355
// @kind(SyntaxKind.ImportClause)
13441356
export interface ImportClause extends Declaration {
13451357
name?: Identifier; // Default binding
1346-
namedBindings?: NamespaceImport | NamedImports;
1358+
namedBindings?: NamedImportBindings;
13471359
}
13481360

13491361
// @kind(SyntaxKind.NamespaceImport)

0 commit comments

Comments
 (0)