@@ -141,7 +141,7 @@ namespace ts {
141141 getAugmentedPropertiesOfType,
142142 getRootSymbols,
143143 getContextualType: node => {
144- node = getParseTreeNode(node, isExpression)
144+ node = getParseTreeNode(node, isExpression);
145145 return node ? getContextualType(node) : undefined;
146146 },
147147 getFullyQualifiedName,
@@ -197,6 +197,8 @@ namespace ts {
197197 const evolvingArrayTypes: EvolvingArrayType[] = [];
198198
199199 const unknownSymbol = createSymbol(SymbolFlags.Property, "unknown");
200+ const untypedModuleSymbol = createSymbol(SymbolFlags.ValueModule, "<untyped>");
201+ untypedModuleSymbol.exports = createMap<Symbol>();
200202 const resolvingSymbol = createSymbol(0, "__resolving__");
201203
202204 const anyType = createIntrinsicType(TypeFlags.Any, "any");
@@ -1227,7 +1229,7 @@ namespace ts {
12271229
12281230 if (moduleSymbol) {
12291231 let exportDefaultSymbol: Symbol;
1230- if (isShorthandAmbientModuleSymbol (moduleSymbol)) {
1232+ if (isUntypedOrShorthandAmbientModuleSymbol (moduleSymbol)) {
12311233 exportDefaultSymbol = moduleSymbol;
12321234 }
12331235 else {
@@ -1307,7 +1309,7 @@ namespace ts {
13071309 if (targetSymbol) {
13081310 const name = specifier.propertyName || specifier.name;
13091311 if (name.text) {
1310- if (isShorthandAmbientModuleSymbol (moduleSymbol)) {
1312+ if (isUntypedOrShorthandAmbientModuleSymbol (moduleSymbol)) {
13111313 return moduleSymbol;
13121314 }
13131315
@@ -1560,15 +1562,19 @@ namespace ts {
15601562 if (isForAugmentation) {
15611563 const diag = Diagnostics.Invalid_module_name_in_augmentation_Module_0_resolves_to_an_untyped_module_at_1_which_cannot_be_augmented;
15621564 error(errorNode, diag, moduleReference, resolvedModule.resolvedFileName);
1565+ return undefined;
15631566 }
15641567 else if (compilerOptions.noImplicitAny && moduleNotFoundError) {
15651568 error(errorNode,
15661569 Diagnostics.Could_not_find_a_declaration_file_for_module_0_1_implicitly_has_an_any_type,
15671570 moduleReference,
15681571 resolvedModule.resolvedFileName);
1572+ return undefined;
15691573 }
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;
15721578 }
15731579
15741580 if (moduleNotFoundError) {
@@ -3753,7 +3759,7 @@ namespace ts {
37533759 function getTypeOfFuncClassEnumModule(symbol: Symbol): Type {
37543760 const links = getSymbolLinks(symbol);
37553761 if (!links.type) {
3756- if (symbol.flags & SymbolFlags.Module && isShorthandAmbientModuleSymbol (symbol)) {
3762+ if (symbol.flags & SymbolFlags.Module && isUntypedOrShorthandAmbientModuleSymbol (symbol)) {
37573763 links.type = anyType;
37583764 }
37593765 else {
@@ -11578,7 +11584,7 @@ namespace ts {
1157811584 if (isBindingPattern(declaration.parent)) {
1157911585 const parentDeclaration = declaration.parent.parent;
1158011586 const name = declaration.propertyName || declaration.name;
11581- if (isVariableLike( parentDeclaration) &&
11587+ if (parentDeclaration.kind !== SyntaxKind.BindingElement &&
1158211588 parentDeclaration.type &&
1158311589 !isBindingPattern(name)) {
1158411590 const text = getTextOfPropertyName(name);
@@ -16125,7 +16131,7 @@ namespace ts {
1612516131 }
1612616132
1612716133 function checkDeclarationInitializer(declaration: VariableLikeDeclaration) {
16128- const type = checkExpressionCached (declaration.initializer);
16134+ const type = getTypeOfExpression (declaration.initializer, /*cache*/ true );
1612916135 return getCombinedNodeFlags(declaration) & NodeFlags.Const ||
1613016136 getCombinedModifierFlags(declaration) & ModifierFlags.Readonly && !isParameterPropertyDeclaration(declaration) ||
1613116137 isTypeAssertion(declaration.initializer) ? type : getWidenedLiteralType(type);
@@ -16198,10 +16204,12 @@ namespace ts {
1619816204
1619916205 // Returns the type of an expression. Unlike checkExpression, this function is simply concerned
1620016206 // 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) {
1620216210 // Optimize for the common case of a call to a function with a single non-generic call
1620316211 // 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) ) {
1620516213 const funcType = checkNonNullExpression((<CallExpression>node).expression);
1620616214 const signature = getSingleCallSignature(funcType);
1620716215 if (signature && !signature.typeParameters) {
@@ -16211,7 +16219,7 @@ namespace ts {
1621116219 // Otherwise simply call checkExpression. Ideally, the entire family of checkXXX functions
1621216220 // should have a parameter that indicates whether full error checking is required such that
1621316221 // we can perform the optimizations locally.
16214- return checkExpression(node);
16222+ return cache ? checkExpressionCached(node) : checkExpression(node);
1621516223 }
1621616224
1621716225 // Checks an expression and returns its type. The contextualMapper parameter serves two purposes: When
@@ -20668,7 +20676,7 @@ namespace ts {
2066820676 }
2066920677
2067020678 if (potentialNewTargetCollisions.length) {
20671- forEach(potentialNewTargetCollisions, checkIfNewTargetIsCapturedInEnclosingScope)
20679+ forEach(potentialNewTargetCollisions, checkIfNewTargetIsCapturedInEnclosingScope);
2067220680 potentialNewTargetCollisions.length = 0;
2067320681 }
2067420682
@@ -21138,7 +21146,15 @@ namespace ts {
2113821146 }
2113921147
2114021148 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;
2114221158 }
2114321159
2114421160 if (isPartOfExpression(node)) {
@@ -21148,7 +21164,10 @@ namespace ts {
2114821164 if (isExpressionWithTypeArgumentsInClassExtendsClause(node)) {
2114921165 // A SyntaxKind.ExpressionWithTypeArguments is considered a type node, except when it occurs in the
2115021166 // 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);
2115221171 }
2115321172
2115421173 if (isTypeDeclaration(node)) {
@@ -21316,7 +21335,7 @@ namespace ts {
2131621335
2131721336 function moduleExportsSomeValue(moduleReferenceExpression: Expression): boolean {
2131821337 let moduleSymbol = resolveExternalModuleName(moduleReferenceExpression.parent, moduleReferenceExpression);
21319- if (!moduleSymbol || isShorthandAmbientModuleSymbol (moduleSymbol)) {
21338+ if (!moduleSymbol || isUntypedOrShorthandAmbientModuleSymbol (moduleSymbol)) {
2132021339 // If the module is not found or is shorthand, assume that it may export a value.
2132121340 return true;
2132221341 }
0 commit comments