Skip to content

Commit 6c892fe

Browse files
committed
Full type action
1 parent 3ea57ae commit 6c892fe

File tree

9 files changed

+91
-23
lines changed

9 files changed

+91
-23
lines changed

src/compiler/binder.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2147,7 +2147,7 @@ namespace ts {
21472147
return updateStrictModeStatementList((<Block | ModuleBlock>node).statements);
21482148

21492149
case SyntaxKind.JSDocParameterTag:
2150-
if (node.parent.kind !== SyntaxKind.JSDocTypeLiteral) {
2150+
if ((node as Node).parent.kind !== SyntaxKind.JSDocTypeLiteral) {
21512151
break;
21522152
}
21532153
// falls through
@@ -2562,11 +2562,11 @@ namespace ts {
25622562
// report error on all statements except empty ones
25632563
(isStatementButNotDeclaration(node) && node.kind !== SyntaxKind.EmptyStatement) ||
25642564
// report error on class declarations
2565-
node.kind === SyntaxKind.ClassDeclaration ||
2565+
(node as Declaration).kind === SyntaxKind.ClassDeclaration ||
25662566
// report error on instantiated modules or const-enums only modules if preserveConstEnums is set
2567-
(node.kind === SyntaxKind.ModuleDeclaration && shouldReportErrorOnModuleDeclaration(<ModuleDeclaration>node)) ||
2567+
((node as Declaration).kind === SyntaxKind.ModuleDeclaration && shouldReportErrorOnModuleDeclaration(<ModuleDeclaration>(node as Declaration))) ||
25682568
// report error on regular enums and const enums if preserveConstEnums is set
2569-
(node.kind === SyntaxKind.EnumDeclaration && (!isConstEnumDeclaration(node) || options.preserveConstEnums));
2569+
((node as Declaration).kind === SyntaxKind.EnumDeclaration && (!isConstEnumDeclaration(node) || options.preserveConstEnums));
25702570

25712571
if (reportError) {
25722572
currentFlow = reportedUnreachableFlow;

src/compiler/declarationEmitter.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ namespace ts {
2727
interface SymbolAccessibilityDiagnostic {
2828
errorNode: Node;
2929
diagnosticMessage: DiagnosticMessage;
30-
typeName?: DeclarationName;
30+
typeName?: DeclarationName | QualifiedName;
3131
}
3232

3333
export function getDeclarationDiagnostics(host: EmitHost, resolver: EmitResolver, targetSourceFile: SourceFile): Diagnostic[] {
@@ -64,7 +64,7 @@ namespace ts {
6464
let currentIdentifiers: Map<string>;
6565
let isCurrentFileExternalModule: boolean;
6666
let reportedDeclarationError = false;
67-
let errorNameNode: DeclarationName;
67+
let errorNameNode: DeclarationName | QualifiedName;
6868
const emitJsDocComments = compilerOptions.removeComments ? noop : writeJsDocComments;
6969
const emit = compilerOptions.stripInternal ? stripInternal : emitNode;
7070
let needsDeclare = true;
@@ -1351,7 +1351,7 @@ namespace ts {
13511351
}
13521352
}
13531353

1354-
function emitTypeOfVariableDeclarationFromTypeLiteral(node: VariableLikeDeclaration) {
1354+
function emitTypeOfVariableDeclarationFromTypeLiteral(node: VariableLikeDeclarationBase) {
13551355
// if this is property of type literal,
13561356
// or is parameter of method/call/construct/index signature of type literal
13571357
// emit only if type is specified

src/compiler/factory.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1108,7 +1108,7 @@ namespace ts {
11081108

11091109
export function createBinary(left: Expression, operator: BinaryOperator | BinaryOperatorToken, right: Expression) {
11101110
const node = <BinaryExpression>createSynthesizedNode(SyntaxKind.BinaryExpression);
1111-
const operatorToken = asToken(operator);
1111+
const operatorToken = asToken(operator) as BinaryOperatorToken;
11121112
const operatorKind = operatorToken.kind;
11131113
node.left = parenthesizeBinaryOperand(operatorKind, left, /*isLeftSideOfBinary*/ true, /*leftOperand*/ undefined);
11141114
node.operatorToken = operatorToken;

src/compiler/parser.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ namespace ts {
201201
return visitNode(cbNode, (<PostfixUnaryExpression>node).operand);
202202
case SyntaxKind.BinaryExpression:
203203
return visitNode(cbNode, (<BinaryExpression>node).left) ||
204-
visitNode(cbNode, (<BinaryExpression>node).operatorToken as Node) ||
204+
visitNode(cbNode, (<BinaryExpression>node).operatorToken) ||
205205
visitNode(cbNode, (<BinaryExpression>node).right);
206206
case SyntaxKind.AsExpression:
207207
return visitNode(cbNode, (<AsExpression>node).expression) ||

src/compiler/transformers/es2015.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -342,7 +342,7 @@ namespace ts {
342342
function shouldVisitNode(node: Node): boolean {
343343
return (node.transformFlags & TransformFlags.ContainsES2015) !== 0
344344
|| convertedLoopState !== undefined
345-
|| (hierarchyFacts & HierarchyFacts.ConstructorWithCapturedSuper && (isStatement(node) || (node.kind === SyntaxKind.Block)))
345+
|| (hierarchyFacts & HierarchyFacts.ConstructorWithCapturedSuper && (isStatement(node) || ((node as Node).kind === SyntaxKind.Block)))
346346
|| (isIterationStatement(node, /*lookInLabeledStatements*/ false) && shouldConvertIterationStatementBody(node))
347347
|| (getEmitFlags(node) & EmitFlags.TypeScriptClassWrapper) !== 0;
348348
}

src/compiler/transformers/module/module.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1551,7 +1551,7 @@ namespace ts {
15511551
? setTextRange(
15521552
createBinary(
15531553
node.operand,
1554-
createToken(node.operator === SyntaxKind.PlusPlusToken ? SyntaxKind.PlusEqualsToken : SyntaxKind.MinusEqualsToken),
1554+
node.operator === SyntaxKind.PlusPlusToken ? createToken(SyntaxKind.PlusEqualsToken) : createToken(SyntaxKind.MinusEqualsToken),
15551555
createLiteral(1)
15561556
),
15571557
/*location*/ node)

src/compiler/types.ts

Lines changed: 70 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1250,7 +1250,53 @@ namespace ts {
12501250
| SyntaxKind.CommaToken
12511251
;
12521252

1253-
export type BinaryOperatorToken = Token<BinaryOperator>;
1253+
export type BinaryOperatorToken =
1254+
| Token<SyntaxKind.CommaToken>
1255+
| Token<SyntaxKind.EqualsToken>
1256+
| Token<SyntaxKind.PlusEqualsToken>
1257+
| Token<SyntaxKind.MinusEqualsToken>
1258+
| Token<SyntaxKind.AsteriskAsteriskEqualsToken>
1259+
| Token<SyntaxKind.AsteriskEqualsToken>
1260+
| Token<SyntaxKind.SlashEqualsToken>
1261+
| Token<SyntaxKind.PercentEqualsToken>
1262+
| Token<SyntaxKind.AmpersandEqualsToken>
1263+
| Token<SyntaxKind.BarEqualsToken>
1264+
| Token<SyntaxKind.CaretEqualsToken>
1265+
| Token<SyntaxKind.LessThanLessThanEqualsToken>
1266+
| Token<SyntaxKind.GreaterThanGreaterThanGreaterThanEqualsToken>
1267+
| Token<SyntaxKind.GreaterThanGreaterThanEqualsToken>
1268+
| Token<SyntaxKind.AmpersandAmpersandToken>
1269+
| Token<SyntaxKind.BarBarToken>
1270+
| Token<SyntaxKind.AmpersandToken>
1271+
| Token<SyntaxKind.BarToken>
1272+
| Token<SyntaxKind.CaretToken>
1273+
| Token<SyntaxKind.EqualsEqualsToken>
1274+
| Token<SyntaxKind.EqualsEqualsEqualsToken>
1275+
| Token<SyntaxKind.ExclamationEqualsEqualsToken>
1276+
| Token<SyntaxKind.ExclamationEqualsToken>
1277+
| Token<SyntaxKind.LessThanToken>
1278+
| Token<SyntaxKind.LessThanEqualsToken>
1279+
| Token<SyntaxKind.GreaterThanToken>
1280+
| Token<SyntaxKind.GreaterThanEqualsToken>
1281+
| Token<SyntaxKind.InstanceOfKeyword>
1282+
| Token<SyntaxKind.InKeyword>
1283+
| Token<SyntaxKind.LessThanLessThanToken>
1284+
| Token<SyntaxKind.GreaterThanGreaterThanToken>
1285+
| Token<SyntaxKind.GreaterThanGreaterThanGreaterThanToken>
1286+
| Token<SyntaxKind.PlusToken>
1287+
| Token<SyntaxKind.MinusToken>
1288+
| Token<SyntaxKind.AsteriskToken>
1289+
| Token<SyntaxKind.SlashToken>
1290+
| Token<SyntaxKind.PercentToken>
1291+
| Token<SyntaxKind.AsteriskAsteriskToken>;
1292+
1293+
// Small check to verify in the type system that BinaryOperatorToken["kind"] and BinaryOperator are the same
1294+
if (!!false) {
1295+
let x: BinaryOperatorToken["kind"];
1296+
let y: BinaryOperator;
1297+
x = y;
1298+
y = x;
1299+
}
12541300

12551301
export interface BinaryExpression extends ExpressionBase, DeclarationBase {
12561302
kind: SyntaxKind.BinaryExpression;
@@ -1259,7 +1305,28 @@ namespace ts {
12591305
right: Expression;
12601306
}
12611307

1262-
export type AssignmentOperatorToken = Token<AssignmentOperator>;
1308+
export type AssignmentOperatorToken =
1309+
| Token<SyntaxKind.EqualsToken>
1310+
| Token<SyntaxKind.PlusEqualsToken>
1311+
| Token<SyntaxKind.MinusEqualsToken>
1312+
| Token<SyntaxKind.AsteriskAsteriskEqualsToken>
1313+
| Token<SyntaxKind.AsteriskEqualsToken>
1314+
| Token<SyntaxKind.SlashEqualsToken>
1315+
| Token<SyntaxKind.PercentEqualsToken>
1316+
| Token<SyntaxKind.AmpersandEqualsToken>
1317+
| Token<SyntaxKind.BarEqualsToken>
1318+
| Token<SyntaxKind.CaretEqualsToken>
1319+
| Token<SyntaxKind.LessThanLessThanEqualsToken>
1320+
| Token<SyntaxKind.GreaterThanGreaterThanGreaterThanEqualsToken>
1321+
| Token<SyntaxKind.GreaterThanGreaterThanEqualsToken>;
1322+
1323+
// Small check to verify in the type system that AssignmentOperatorToken["kind"] and AssignmentOperator are the same
1324+
if (!!false) {
1325+
let x: AssignmentOperatorToken["kind"];
1326+
let y: AssignmentOperator;
1327+
x = y;
1328+
y = x;
1329+
}
12631330

12641331
export interface AssignmentExpression<TOperator extends AssignmentOperatorToken> extends BinaryExpression {
12651332
left: LeftHandSideExpression;
@@ -4778,6 +4845,7 @@ namespace ts {
47784845

47794846
export type MemberExpression =
47804847
| PropertyAccessExpression
4848+
| PropertyAccessEntityNameExpression // Included for completeness
47814849
| ElementAccessExpression
47824850
| TaggedTemplateExpression
47834851
| PrimaryExpression;

src/compiler/utilities.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1131,19 +1131,19 @@ namespace ts {
11311131
&& (<PropertyAccessExpression | ElementAccessExpression>node).expression.kind === SyntaxKind.SuperKeyword;
11321132
}
11331133

1134-
export function getEntityNameFromTypeNode(node: TypeNode): EntityNameOrEntityNameExpression {
1134+
export function getEntityNameFromTypeNode(node: TypeNode | Identifier | QualifiedName): EntityNameOrEntityNameExpression {
11351135
switch (node.kind) {
11361136
case SyntaxKind.TypeReference:
1137-
return (<TypeReferenceNode>node).typeName;
1137+
return node.typeName;
11381138

11391139
case SyntaxKind.ExpressionWithTypeArguments:
1140-
return isEntityNameExpression((<ExpressionWithTypeArguments>node).expression)
1141-
? <EntityNameExpression>(<ExpressionWithTypeArguments>node).expression
1140+
return isEntityNameExpression(node.expression)
1141+
? node.expression
11421142
: undefined;
11431143

11441144
case SyntaxKind.Identifier:
11451145
case SyntaxKind.QualifiedName:
1146-
return (<EntityName><Node>node);
1146+
return node;
11471147
}
11481148

11491149
return undefined;

src/compiler/visitor.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1022,11 +1022,11 @@ namespace ts {
10221022
break;
10231023

10241024
case SyntaxKind.SetAccessor:
1025-
result = reduceNodes((<GetAccessorDeclaration>node).decorators, cbNodes, result);
1026-
result = reduceNodes((<GetAccessorDeclaration>node).modifiers, cbNodes, result);
1027-
result = reduceNode((<GetAccessorDeclaration>node).name, cbNode, result);
1028-
result = reduceNodes((<GetAccessorDeclaration>node).parameters, cbNodes, result);
1029-
result = reduceNode((<GetAccessorDeclaration>node).body, cbNode, result);
1025+
result = reduceNodes(node.decorators, cbNodes, result);
1026+
result = reduceNodes(node.modifiers, cbNodes, result);
1027+
result = reduceNode(node.name, cbNode, result);
1028+
result = reduceNodes(node.parameters, cbNodes, result);
1029+
result = reduceNode(node.body, cbNode, result);
10301030
break;
10311031

10321032
// Binding patterns

0 commit comments

Comments
 (0)