@@ -254,6 +254,7 @@ namespace ts {
254
254
return resolveName(location, escapeLeadingUnderscores(name), meaning, /*nameNotFoundMessage*/ undefined, /*nameArg*/ undefined, /*isUse*/ false);
255
255
},
256
256
getJsxNamespace: () => unescapeLeadingUnderscores(getJsxNamespace()),
257
+ getAccessibleSymbolChain,
257
258
};
258
259
259
260
const tupleTypes: GenericType[] = [];
@@ -738,10 +739,6 @@ namespace ts {
738
739
return nodeLinks[nodeId] || (nodeLinks[nodeId] = { flags: 0 });
739
740
}
740
741
741
- function getObjectFlags(type: Type): ObjectFlags {
742
- return type.flags & TypeFlags.Object ? (<ObjectType>type).objectFlags : 0;
743
- }
744
-
745
742
function isGlobalSourceFile(node: Node) {
746
743
return node.kind === SyntaxKind.SourceFile && !isExternalOrCommonJsModule(<SourceFile>node);
747
744
}
@@ -10146,20 +10143,6 @@ namespace ts {
10146
10143
!hasBaseType(checkClass, getDeclaringClass(p)) : false) ? undefined : checkClass;
10147
10144
}
10148
10145
10149
- // Return true if the given type is the constructor type for an abstract class
10150
- function isAbstractConstructorType(type: Type) {
10151
- if (getObjectFlags(type) & ObjectFlags.Anonymous) {
10152
- const symbol = type.symbol;
10153
- if (symbol && symbol.flags & SymbolFlags.Class) {
10154
- const declaration = getClassLikeDeclarationOfSymbol(symbol);
10155
- if (declaration && hasModifier(declaration, ModifierFlags.Abstract)) {
10156
- return true;
10157
- }
10158
- }
10159
- }
10160
- return false;
10161
- }
10162
-
10163
10146
// Return true if the given type is deeply nested. We consider this to be the case when structural type comparisons
10164
10147
// for 5 or more occurrences or instantiations of the type have been recorded on the given stack. It is possible,
10165
10148
// though highly unlikely, for this test to be true in a situation where a chain of instantiations is not infinitely
@@ -13409,7 +13392,7 @@ namespace ts {
13409
13392
// the contextual type of an initializer expression is the type annotation of the containing declaration, if present.
13410
13393
function getContextualTypeForInitializerExpression(node: Expression): Type {
13411
13394
const declaration = <VariableLikeDeclaration>node.parent;
13412
- if (node === declaration.initializer) {
13395
+ if (node === declaration.initializer || node.kind === SyntaxKind.EqualsToken ) {
13413
13396
const typeNode = getEffectiveTypeAnnotationNode(declaration);
13414
13397
if (typeNode) {
13415
13398
return getTypeFromTypeNode(typeNode);
@@ -13529,7 +13512,8 @@ namespace ts {
13529
13512
13530
13513
function getContextualTypeForBinaryOperand(node: Expression): Type {
13531
13514
const binaryExpression = <BinaryExpression>node.parent;
13532
- const operator = binaryExpression.operatorToken.kind;
13515
+ const { operatorToken } = binaryExpression;
13516
+ const operator = operatorToken.kind;
13533
13517
if (isAssignmentOperator(operator)) {
13534
13518
if (node === binaryExpression.right) {
13535
13519
// Don't do this for special property assignments to avoid circularity
@@ -13567,10 +13551,26 @@ namespace ts {
13567
13551
return getContextualType(binaryExpression);
13568
13552
}
13569
13553
}
13554
+ else if (node === operatorToken && isEquationOperator(operator)) {
13555
+ // For completions after `x === `
13556
+ return getTypeOfExpression(binaryExpression.left);
13557
+ }
13570
13558
13571
13559
return undefined;
13572
13560
}
13573
13561
13562
+ function isEquationOperator(operator: SyntaxKind) {
13563
+ switch (operator) {
13564
+ case SyntaxKind.EqualsEqualsEqualsToken:
13565
+ case SyntaxKind.EqualsEqualsToken:
13566
+ case SyntaxKind.ExclamationEqualsEqualsToken:
13567
+ case SyntaxKind.ExclamationEqualsToken:
13568
+ return true;
13569
+ default:
13570
+ return false;
13571
+ }
13572
+ }
13573
+
13574
13574
function getTypeOfPropertyOfContextualType(type: Type, name: __String) {
13575
13575
return mapType(type, t => {
13576
13576
const prop = t.flags & TypeFlags.StructuredType ? getPropertyOfType(t, name) : undefined;
@@ -13761,9 +13761,13 @@ namespace ts {
13761
13761
return getContextualTypeForReturnExpression(node);
13762
13762
case SyntaxKind.YieldExpression:
13763
13763
return getContextualTypeForYieldOperand(<YieldExpression>parent);
13764
- case SyntaxKind.CallExpression:
13765
13764
case SyntaxKind.NewExpression:
13766
- return getContextualTypeForArgument(<CallExpression>parent, node);
13765
+ if (node.kind === SyntaxKind.NewKeyword) { // for completions after `new `
13766
+ return getContextualType(parent as NewExpression);
13767
+ }
13768
+ // falls through
13769
+ case SyntaxKind.CallExpression:
13770
+ return getContextualTypeForArgument(<CallExpression | NewExpression>parent, node);
13767
13771
case SyntaxKind.TypeAssertionExpression:
13768
13772
case SyntaxKind.AsExpression:
13769
13773
return getTypeFromTypeNode((<AssertionExpression>parent).type);
@@ -13797,6 +13801,12 @@ namespace ts {
13797
13801
case SyntaxKind.JsxOpeningElement:
13798
13802
case SyntaxKind.JsxSelfClosingElement:
13799
13803
return getAttributesTypeFromJsxOpeningLikeElement(<JsxOpeningLikeElement>parent);
13804
+ case SyntaxKind.CaseClause: {
13805
+ if (node.kind === SyntaxKind.CaseKeyword) { // for completions after `case `
13806
+ const switchStatement = (parent as CaseClause).parent.parent;
13807
+ return getTypeOfExpression(switchStatement.expression);
13808
+ }
13809
+ }
13800
13810
}
13801
13811
return undefined;
13802
13812
}
@@ -22117,10 +22127,6 @@ namespace ts {
22117
22127
return getCheckFlags(s) & CheckFlags.Instantiated ? (<TransientSymbol>s).target : s;
22118
22128
}
22119
22129
22120
- function getClassLikeDeclarationOfSymbol(symbol: Symbol): Declaration {
22121
- return forEach(symbol.declarations, d => isClassLike(d) ? d : undefined);
22122
- }
22123
-
22124
22130
function getClassOrInterfaceDeclarationsOfSymbol(symbol: Symbol) {
22125
22131
return filter(symbol.declarations, (d: Declaration): d is ClassDeclaration | InterfaceDeclaration =>
22126
22132
d.kind === SyntaxKind.ClassDeclaration || d.kind === SyntaxKind.InterfaceDeclaration);
0 commit comments