Skip to content

Commit 2152874

Browse files
committed
Address CR feedback
1 parent 2c36249 commit 2152874

File tree

3 files changed

+24
-16
lines changed

3 files changed

+24
-16
lines changed

src/compiler/binder.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1281,7 +1281,8 @@ namespace ts {
12811281

12821282
function isDottedName(node: Expression): boolean {
12831283
return node.kind === SyntaxKind.Identifier || node.kind === SyntaxKind.ThisKeyword ||
1284-
node.kind === SyntaxKind.PropertyAccessExpression && isDottedName((<PropertyAccessExpression>node).expression);
1284+
node.kind === SyntaxKind.PropertyAccessExpression && isDottedName((<PropertyAccessExpression>node).expression) ||
1285+
node.kind === SyntaxKind.ParenthesizedExpression && isDottedName((<ParenthesizedExpression>node).expression);
12851286
}
12861287

12871288
function bindExpressionStatement(node: ExpressionStatement): void {

src/compiler/checker.ts

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16852,7 +16852,7 @@ namespace ts {
1685216852
return !!(declaration && (
1685316853
declaration.kind === SyntaxKind.VariableDeclaration || declaration.kind === SyntaxKind.Parameter ||
1685416854
declaration.kind === SyntaxKind.PropertyDeclaration || declaration.kind === SyntaxKind.PropertySignature) &&
16855-
(declaration as VariableDeclaration | ParameterDeclaration | PropertyDeclaration | PropertySignature).type);
16855+
getEffectiveTypeAnnotationNode(declaration as VariableDeclaration | ParameterDeclaration | PropertyDeclaration | PropertySignature));
1685616856
}
1685716857

1685816858
function getExplicitTypeOfSymbol(symbol: Symbol) {
@@ -16861,11 +16861,11 @@ namespace ts {
1686116861
getTypeOfSymbol(symbol) : undefined;
1686216862
}
1686316863

16864-
function getTypeOfDottedName(node: Expression) {
16865-
// We require the dotted function name in an assertion expression to be comprised of identifiers
16866-
// that reference function, method, class or value module symbols; or variable, property or
16867-
// parameter symbols with declarations that have explicit type annotations. Such references are
16868-
// resolvable with no possibility of triggering circularities in control flow analysis.
16864+
// We require the dotted function name in an assertion expression to be comprised of identifiers
16865+
// that reference function, method, class or value module symbols; or variable, property or
16866+
// parameter symbols with declarations that have explicit type annotations. Such references are
16867+
// resolvable with no possibility of triggering circularities in control flow analysis.
16868+
function getTypeOfDottedName(node: Expression): Type | undefined {
1686916869
switch (node.kind) {
1687016870
case SyntaxKind.Identifier:
1687116871
const symbol = getResolvedSymbol(<Identifier>node);
@@ -16874,10 +16874,10 @@ namespace ts {
1687416874
return checkThisExpression(node);
1687516875
case SyntaxKind.PropertyAccessExpression:
1687616876
const type = getTypeOfDottedName((<PropertyAccessExpression>node).expression);
16877-
if (type) {
16878-
const prop = getPropertyOfType(type, (<PropertyAccessExpression>node).name.escapedText);
16879-
return prop && getExplicitTypeOfSymbol(prop);
16880-
}
16877+
const prop = type && getPropertyOfType(type, (<PropertyAccessExpression>node).name.escapedText);
16878+
return prop && getExplicitTypeOfSymbol(prop);
16879+
case SyntaxKind.ParenthesizedExpression:
16880+
return getTypeOfDottedName((<ParenthesizedExpression>node).expression);
1688116881
}
1688216882
}
1688316883

@@ -16886,7 +16886,9 @@ namespace ts {
1688616886
let signature = links.effectsSignature;
1688716887
if (signature === undefined) {
1688816888
// A call expression parented by an expression statement is a potential assertion. Other call
16889-
// expressions are potential type predicate function calls.
16889+
// expressions are potential type predicate function calls. In order to avoid triggering
16890+
// circularities in control flow analysis, we use getTypeOfDottedName when resolving the call
16891+
// target expression of an assertion.
1689016892
const funcType = node.parent.kind === SyntaxKind.ExpressionStatement ? getTypeOfDottedName(node.expression) :
1689116893
node.expression.kind !== SyntaxKind.SuperKeyword ? checkNonNullExpression(node.expression) :
1689216894
undefined;

src/compiler/types.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3518,28 +3518,33 @@ namespace ts {
35183518
AssertsIdentifier
35193519
}
35203520

3521-
export interface ThisTypePredicate {
3521+
export interface TypePredicateBase {
3522+
kind: TypePredicateKind;
3523+
type: Type | undefined;
3524+
}
3525+
3526+
export interface ThisTypePredicate extends TypePredicateBase {
35223527
kind: TypePredicateKind.This;
35233528
parameterName: undefined;
35243529
parameterIndex: undefined;
35253530
type: Type;
35263531
}
35273532

3528-
export interface IdentifierTypePredicate {
3533+
export interface IdentifierTypePredicate extends TypePredicateBase {
35293534
kind: TypePredicateKind.Identifier;
35303535
parameterName: string;
35313536
parameterIndex: number;
35323537
type: Type;
35333538
}
35343539

3535-
export interface AssertsThisTypePredicate {
3540+
export interface AssertsThisTypePredicate extends TypePredicateBase {
35363541
kind: TypePredicateKind.AssertsThis;
35373542
parameterName: undefined;
35383543
parameterIndex: undefined;
35393544
type: Type | undefined;
35403545
}
35413546

3542-
export interface AssertsIdentifierTypePredicate {
3547+
export interface AssertsIdentifierTypePredicate extends TypePredicateBase {
35433548
kind: TypePredicateKind.AssertsIdentifier;
35443549
parameterName: string;
35453550
parameterIndex: number;

0 commit comments

Comments
 (0)