Address CR feedback
This commit is contained in:
parent
2c36249ed6
commit
21528748c6
3 changed files with 24 additions and 16 deletions
|
@ -1281,7 +1281,8 @@ namespace ts {
|
||||||
|
|
||||||
function isDottedName(node: Expression): boolean {
|
function isDottedName(node: Expression): boolean {
|
||||||
return node.kind === SyntaxKind.Identifier || node.kind === SyntaxKind.ThisKeyword ||
|
return node.kind === SyntaxKind.Identifier || node.kind === SyntaxKind.ThisKeyword ||
|
||||||
node.kind === SyntaxKind.PropertyAccessExpression && isDottedName((<PropertyAccessExpression>node).expression);
|
node.kind === SyntaxKind.PropertyAccessExpression && isDottedName((<PropertyAccessExpression>node).expression) ||
|
||||||
|
node.kind === SyntaxKind.ParenthesizedExpression && isDottedName((<ParenthesizedExpression>node).expression);
|
||||||
}
|
}
|
||||||
|
|
||||||
function bindExpressionStatement(node: ExpressionStatement): void {
|
function bindExpressionStatement(node: ExpressionStatement): void {
|
||||||
|
|
|
@ -16852,7 +16852,7 @@ namespace ts {
|
||||||
return !!(declaration && (
|
return !!(declaration && (
|
||||||
declaration.kind === SyntaxKind.VariableDeclaration || declaration.kind === SyntaxKind.Parameter ||
|
declaration.kind === SyntaxKind.VariableDeclaration || declaration.kind === SyntaxKind.Parameter ||
|
||||||
declaration.kind === SyntaxKind.PropertyDeclaration || declaration.kind === SyntaxKind.PropertySignature) &&
|
declaration.kind === SyntaxKind.PropertyDeclaration || declaration.kind === SyntaxKind.PropertySignature) &&
|
||||||
(declaration as VariableDeclaration | ParameterDeclaration | PropertyDeclaration | PropertySignature).type);
|
getEffectiveTypeAnnotationNode(declaration as VariableDeclaration | ParameterDeclaration | PropertyDeclaration | PropertySignature));
|
||||||
}
|
}
|
||||||
|
|
||||||
function getExplicitTypeOfSymbol(symbol: Symbol) {
|
function getExplicitTypeOfSymbol(symbol: Symbol) {
|
||||||
|
@ -16861,11 +16861,11 @@ namespace ts {
|
||||||
getTypeOfSymbol(symbol) : undefined;
|
getTypeOfSymbol(symbol) : undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
function getTypeOfDottedName(node: Expression) {
|
// We require the dotted function name in an assertion expression to be comprised of identifiers
|
||||||
// We require the dotted function name in an assertion expression to be comprised of identifiers
|
// that reference function, method, class or value module symbols; or variable, property or
|
||||||
// that reference function, method, class or value module symbols; or variable, property or
|
// parameter symbols with declarations that have explicit type annotations. Such references are
|
||||||
// parameter symbols with declarations that have explicit type annotations. Such references are
|
// resolvable with no possibility of triggering circularities in control flow analysis.
|
||||||
// resolvable with no possibility of triggering circularities in control flow analysis.
|
function getTypeOfDottedName(node: Expression): Type | undefined {
|
||||||
switch (node.kind) {
|
switch (node.kind) {
|
||||||
case SyntaxKind.Identifier:
|
case SyntaxKind.Identifier:
|
||||||
const symbol = getResolvedSymbol(<Identifier>node);
|
const symbol = getResolvedSymbol(<Identifier>node);
|
||||||
|
@ -16874,10 +16874,10 @@ namespace ts {
|
||||||
return checkThisExpression(node);
|
return checkThisExpression(node);
|
||||||
case SyntaxKind.PropertyAccessExpression:
|
case SyntaxKind.PropertyAccessExpression:
|
||||||
const type = getTypeOfDottedName((<PropertyAccessExpression>node).expression);
|
const type = getTypeOfDottedName((<PropertyAccessExpression>node).expression);
|
||||||
if (type) {
|
const prop = type && getPropertyOfType(type, (<PropertyAccessExpression>node).name.escapedText);
|
||||||
const prop = getPropertyOfType(type, (<PropertyAccessExpression>node).name.escapedText);
|
return prop && getExplicitTypeOfSymbol(prop);
|
||||||
return prop && getExplicitTypeOfSymbol(prop);
|
case SyntaxKind.ParenthesizedExpression:
|
||||||
}
|
return getTypeOfDottedName((<ParenthesizedExpression>node).expression);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -16886,7 +16886,9 @@ namespace ts {
|
||||||
let signature = links.effectsSignature;
|
let signature = links.effectsSignature;
|
||||||
if (signature === undefined) {
|
if (signature === undefined) {
|
||||||
// A call expression parented by an expression statement is a potential assertion. Other call
|
// A call expression parented by an expression statement is a potential assertion. Other call
|
||||||
// expressions are potential type predicate function calls.
|
// expressions are potential type predicate function calls. In order to avoid triggering
|
||||||
|
// circularities in control flow analysis, we use getTypeOfDottedName when resolving the call
|
||||||
|
// target expression of an assertion.
|
||||||
const funcType = node.parent.kind === SyntaxKind.ExpressionStatement ? getTypeOfDottedName(node.expression) :
|
const funcType = node.parent.kind === SyntaxKind.ExpressionStatement ? getTypeOfDottedName(node.expression) :
|
||||||
node.expression.kind !== SyntaxKind.SuperKeyword ? checkNonNullExpression(node.expression) :
|
node.expression.kind !== SyntaxKind.SuperKeyword ? checkNonNullExpression(node.expression) :
|
||||||
undefined;
|
undefined;
|
||||||
|
|
|
@ -3518,28 +3518,33 @@ namespace ts {
|
||||||
AssertsIdentifier
|
AssertsIdentifier
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface ThisTypePredicate {
|
export interface TypePredicateBase {
|
||||||
|
kind: TypePredicateKind;
|
||||||
|
type: Type | undefined;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface ThisTypePredicate extends TypePredicateBase {
|
||||||
kind: TypePredicateKind.This;
|
kind: TypePredicateKind.This;
|
||||||
parameterName: undefined;
|
parameterName: undefined;
|
||||||
parameterIndex: undefined;
|
parameterIndex: undefined;
|
||||||
type: Type;
|
type: Type;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface IdentifierTypePredicate {
|
export interface IdentifierTypePredicate extends TypePredicateBase {
|
||||||
kind: TypePredicateKind.Identifier;
|
kind: TypePredicateKind.Identifier;
|
||||||
parameterName: string;
|
parameterName: string;
|
||||||
parameterIndex: number;
|
parameterIndex: number;
|
||||||
type: Type;
|
type: Type;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface AssertsThisTypePredicate {
|
export interface AssertsThisTypePredicate extends TypePredicateBase {
|
||||||
kind: TypePredicateKind.AssertsThis;
|
kind: TypePredicateKind.AssertsThis;
|
||||||
parameterName: undefined;
|
parameterName: undefined;
|
||||||
parameterIndex: undefined;
|
parameterIndex: undefined;
|
||||||
type: Type | undefined;
|
type: Type | undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface AssertsIdentifierTypePredicate {
|
export interface AssertsIdentifierTypePredicate extends TypePredicateBase {
|
||||||
kind: TypePredicateKind.AssertsIdentifier;
|
kind: TypePredicateKind.AssertsIdentifier;
|
||||||
parameterName: string;
|
parameterName: string;
|
||||||
parameterIndex: number;
|
parameterIndex: number;
|
||||||
|
|
Loading…
Reference in a new issue