@@ -141,7 +141,7 @@ namespace ts {
141
141
getAugmentedPropertiesOfType,
142
142
getRootSymbols,
143
143
getContextualType: node => {
144
- node = getParseTreeNode(node, isExpression)
144
+ node = getParseTreeNode(node, isExpression);
145
145
return node ? getContextualType(node) : undefined;
146
146
},
147
147
getFullyQualifiedName,
@@ -197,6 +197,8 @@ namespace ts {
197
197
const evolvingArrayTypes: EvolvingArrayType[] = [];
198
198
199
199
const unknownSymbol = createSymbol(SymbolFlags.Property, "unknown");
200
+ const untypedModuleSymbol = createSymbol(SymbolFlags.ValueModule, "<untyped>");
201
+ untypedModuleSymbol.exports = createMap<Symbol>();
200
202
const resolvingSymbol = createSymbol(0, "__resolving__");
201
203
202
204
const anyType = createIntrinsicType(TypeFlags.Any, "any");
@@ -1227,7 +1229,7 @@ namespace ts {
1227
1229
1228
1230
if (moduleSymbol) {
1229
1231
let exportDefaultSymbol: Symbol;
1230
- if (isShorthandAmbientModuleSymbol (moduleSymbol)) {
1232
+ if (isUntypedOrShorthandAmbientModuleSymbol (moduleSymbol)) {
1231
1233
exportDefaultSymbol = moduleSymbol;
1232
1234
}
1233
1235
else {
@@ -1307,7 +1309,7 @@ namespace ts {
1307
1309
if (targetSymbol) {
1308
1310
const name = specifier.propertyName || specifier.name;
1309
1311
if (name.text) {
1310
- if (isShorthandAmbientModuleSymbol (moduleSymbol)) {
1312
+ if (isUntypedOrShorthandAmbientModuleSymbol (moduleSymbol)) {
1311
1313
return moduleSymbol;
1312
1314
}
1313
1315
@@ -1560,15 +1562,19 @@ namespace ts {
1560
1562
if (isForAugmentation) {
1561
1563
const diag = Diagnostics.Invalid_module_name_in_augmentation_Module_0_resolves_to_an_untyped_module_at_1_which_cannot_be_augmented;
1562
1564
error(errorNode, diag, moduleReference, resolvedModule.resolvedFileName);
1565
+ return undefined;
1563
1566
}
1564
1567
else if (compilerOptions.noImplicitAny && moduleNotFoundError) {
1565
1568
error(errorNode,
1566
1569
Diagnostics.Could_not_find_a_declaration_file_for_module_0_1_implicitly_has_an_any_type,
1567
1570
moduleReference,
1568
1571
resolvedModule.resolvedFileName);
1572
+ return undefined;
1569
1573
}
1570
- // Failed imports and untyped modules are both treated in an untyped manner; only difference is whether we give a diagnostic first.
1571
- return undefined;
1574
+ // Unlike a failed import, an untyped module produces a dummy symbol.
1575
+ // This is checked for by `isUntypedOrShorthandAmbientModuleSymbol`.
1576
+ // This must be different than `unknownSymbol` because `getBaseConstructorTypeOfClass` won't fail for `unknownSymbol`.
1577
+ return untypedModuleSymbol;
1572
1578
}
1573
1579
1574
1580
if (moduleNotFoundError) {
@@ -3753,7 +3759,7 @@ namespace ts {
3753
3759
function getTypeOfFuncClassEnumModule(symbol: Symbol): Type {
3754
3760
const links = getSymbolLinks(symbol);
3755
3761
if (!links.type) {
3756
- if (symbol.flags & SymbolFlags.Module && isShorthandAmbientModuleSymbol (symbol)) {
3762
+ if (symbol.flags & SymbolFlags.Module && isUntypedOrShorthandAmbientModuleSymbol (symbol)) {
3757
3763
links.type = anyType;
3758
3764
}
3759
3765
else {
@@ -11578,7 +11584,7 @@ namespace ts {
11578
11584
if (isBindingPattern(declaration.parent)) {
11579
11585
const parentDeclaration = declaration.parent.parent;
11580
11586
const name = declaration.propertyName || declaration.name;
11581
- if (isVariableLike( parentDeclaration) &&
11587
+ if (parentDeclaration.kind !== SyntaxKind.BindingElement &&
11582
11588
parentDeclaration.type &&
11583
11589
!isBindingPattern(name)) {
11584
11590
const text = getTextOfPropertyName(name);
@@ -16125,7 +16131,7 @@ namespace ts {
16125
16131
}
16126
16132
16127
16133
function checkDeclarationInitializer(declaration: VariableLikeDeclaration) {
16128
- const type = checkExpressionCached (declaration.initializer);
16134
+ const type = getTypeOfExpression (declaration.initializer, /*cache*/ true );
16129
16135
return getCombinedNodeFlags(declaration) & NodeFlags.Const ||
16130
16136
getCombinedModifierFlags(declaration) & ModifierFlags.Readonly && !isParameterPropertyDeclaration(declaration) ||
16131
16137
isTypeAssertion(declaration.initializer) ? type : getWidenedLiteralType(type);
@@ -16198,10 +16204,12 @@ namespace ts {
16198
16204
16199
16205
// Returns the type of an expression. Unlike checkExpression, this function is simply concerned
16200
16206
// with computing the type and may not fully check all contained sub-expressions for errors.
16201
- function getTypeOfExpression(node: Expression) {
16207
+ // A cache argument of true indicates that if the function performs a full type check, it is ok
16208
+ // to cache the result.
16209
+ function getTypeOfExpression(node: Expression, cache?: boolean) {
16202
16210
// Optimize for the common case of a call to a function with a single non-generic call
16203
16211
// signature where we can just fetch the return type without checking the arguments.
16204
- if (node.kind === SyntaxKind.CallExpression && (<CallExpression>node).expression.kind !== SyntaxKind.SuperKeyword) {
16212
+ if (node.kind === SyntaxKind.CallExpression && (<CallExpression>node).expression.kind !== SyntaxKind.SuperKeyword && !isRequireCall(node, /*checkArgumentIsStringLiteral*/true) ) {
16205
16213
const funcType = checkNonNullExpression((<CallExpression>node).expression);
16206
16214
const signature = getSingleCallSignature(funcType);
16207
16215
if (signature && !signature.typeParameters) {
@@ -16211,7 +16219,7 @@ namespace ts {
16211
16219
// Otherwise simply call checkExpression. Ideally, the entire family of checkXXX functions
16212
16220
// should have a parameter that indicates whether full error checking is required such that
16213
16221
// we can perform the optimizations locally.
16214
- return checkExpression(node);
16222
+ return cache ? checkExpressionCached(node) : checkExpression(node);
16215
16223
}
16216
16224
16217
16225
// Checks an expression and returns its type. The contextualMapper parameter serves two purposes: When
@@ -20668,7 +20676,7 @@ namespace ts {
20668
20676
}
20669
20677
20670
20678
if (potentialNewTargetCollisions.length) {
20671
- forEach(potentialNewTargetCollisions, checkIfNewTargetIsCapturedInEnclosingScope)
20679
+ forEach(potentialNewTargetCollisions, checkIfNewTargetIsCapturedInEnclosingScope);
20672
20680
potentialNewTargetCollisions.length = 0;
20673
20681
}
20674
20682
@@ -21138,7 +21146,15 @@ namespace ts {
21138
21146
}
21139
21147
21140
21148
if (isPartOfTypeNode(node)) {
21141
- return getTypeFromTypeNode(<TypeNode>node);
21149
+ let typeFromTypeNode = getTypeFromTypeNode(<TypeNode>node);
21150
+
21151
+ if (typeFromTypeNode && isExpressionWithTypeArgumentsInClassImplementsClause(node)) {
21152
+ const containingClass = getContainingClass(node);
21153
+ const classType = getTypeOfNode(containingClass) as InterfaceType;
21154
+ typeFromTypeNode = getTypeWithThisArgument(typeFromTypeNode, classType.thisType);
21155
+ }
21156
+
21157
+ return typeFromTypeNode;
21142
21158
}
21143
21159
21144
21160
if (isPartOfExpression(node)) {
@@ -21148,7 +21164,10 @@ namespace ts {
21148
21164
if (isExpressionWithTypeArgumentsInClassExtendsClause(node)) {
21149
21165
// A SyntaxKind.ExpressionWithTypeArguments is considered a type node, except when it occurs in the
21150
21166
// extends clause of a class. We handle that case here.
21151
- return getBaseTypes(<InterfaceType>getDeclaredTypeOfSymbol(getSymbolOfNode(node.parent.parent)))[0];
21167
+ const classNode = getContainingClass(node);
21168
+ const classType = getDeclaredTypeOfSymbol(getSymbolOfNode(classNode)) as InterfaceType;
21169
+ const baseType = getBaseTypes(classType)[0];
21170
+ return baseType && getTypeWithThisArgument(baseType, classType.thisType);
21152
21171
}
21153
21172
21154
21173
if (isTypeDeclaration(node)) {
@@ -21316,7 +21335,7 @@ namespace ts {
21316
21335
21317
21336
function moduleExportsSomeValue(moduleReferenceExpression: Expression): boolean {
21318
21337
let moduleSymbol = resolveExternalModuleName(moduleReferenceExpression.parent, moduleReferenceExpression);
21319
- if (!moduleSymbol || isShorthandAmbientModuleSymbol (moduleSymbol)) {
21338
+ if (!moduleSymbol || isUntypedOrShorthandAmbientModuleSymbol (moduleSymbol)) {
21320
21339
// If the module is not found or is shorthand, assume that it may export a value.
21321
21340
return true;
21322
21341
}
0 commit comments