@@ -143,6 +143,7 @@ namespace ts {
143143
144144 const anySignature = createSignature(undefined, undefined, undefined, emptyArray, anyType, /*typePredicate*/ undefined, 0, /*hasRestParameter*/ false, /*hasLiteralTypes*/ false);
145145 const unknownSignature = createSignature(undefined, undefined, undefined, emptyArray, unknownType, /*typePredicate*/ undefined, 0, /*hasRestParameter*/ false, /*hasLiteralTypes*/ false);
146+ const resolvingSignature = createSignature(undefined, undefined, undefined, emptyArray, anyType, /*typePredicate*/ undefined, 0, /*hasRestParameter*/ false, /*hasLiteralTypes*/ false);
146147
147148 const enumNumberIndexInfo = createIndexInfo(stringType, /*isReadonly*/ true);
148149
@@ -1024,8 +1025,8 @@ namespace ts {
10241025 }
10251026 }
10261027
1027- function getDeclarationOfAliasSymbol(symbol: Symbol): Declaration {
1028- return findMap (symbol.declarations, d => isAliasSymbolDeclaration(d) ? d : undefined);
1028+ function getDeclarationOfAliasSymbol(symbol: Symbol): Declaration | undefined {
1029+ return forEach (symbol.declarations, d => isAliasSymbolDeclaration(d) ? d : undefined);
10291030 }
10301031
10311032 function getTargetOfImportEqualsDeclaration(node: ImportEqualsDeclaration): Symbol {
@@ -1192,6 +1193,7 @@ namespace ts {
11921193 if (!links.target) {
11931194 links.target = resolvingSymbol;
11941195 const node = getDeclarationOfAliasSymbol(symbol);
1196+ Debug.assert(!!node);
11951197 const target = getTargetOfAliasDeclaration(node);
11961198 if (links.target === resolvingSymbol) {
11971199 links.target = target || unknownSymbol;
@@ -1227,6 +1229,7 @@ namespace ts {
12271229 if (!links.referenced) {
12281230 links.referenced = true;
12291231 const node = getDeclarationOfAliasSymbol(symbol);
1232+ Debug.assert(!!node);
12301233 if (node.kind === SyntaxKind.ExportAssignment) {
12311234 // export default <symbol>
12321235 checkExpressionCached((<ExportAssignment>node).expression);
@@ -3348,7 +3351,13 @@ namespace ts {
33483351 // Otherwise, fall back to 'any'.
33493352 else {
33503353 if (compilerOptions.noImplicitAny) {
3351- error(setter, Diagnostics.Property_0_implicitly_has_type_any_because_its_set_accessor_lacks_a_type_annotation, symbolToString(symbol));
3354+ if (setter) {
3355+ error(setter, Diagnostics.Property_0_implicitly_has_type_any_because_its_set_accessor_lacks_a_parameter_type_annotation, symbolToString(symbol));
3356+ }
3357+ else {
3358+ Debug.assert(!!getter, "there must existed getter as we are current checking either setter or getter in this function");
3359+ error(getter, Diagnostics.Property_0_implicitly_has_type_any_because_its_get_accessor_lacks_a_return_type_annotation, symbolToString(symbol));
3360+ }
33523361 }
33533362 type = anyType;
33543363 }
@@ -5374,7 +5383,7 @@ namespace ts {
53745383 while (i > 0) {
53755384 i--;
53765385 if (isSubtypeOfAny(types[i], types)) {
5377- types.splice(i, 1 );
5386+ orderedRemoveItemAt(types, i );
53785387 }
53795388 }
53805389 }
@@ -8758,7 +8767,7 @@ namespace ts {
87588767 // The location isn't a reference to the given symbol, meaning we're being asked
87598768 // a hypothetical question of what type the symbol would have if there was a reference
87608769 // to it at the given location. Since we have no control flow information for the
8761- // hypotherical reference (control flow information is created and attached by the
8770+ // hypothetical reference (control flow information is created and attached by the
87628771 // binder), we simply return the declared type of the symbol.
87638772 return getTypeOfSymbol(symbol);
87648773 }
@@ -11993,18 +12002,12 @@ namespace ts {
1199312002 // Function interface, since they have none by default. This is a bit of a leap of faith
1199412003 // that the user will not add any.
1199512004 const callSignatures = getSignaturesOfType(apparentType, SignatureKind.Call);
11996-
1199712005 const constructSignatures = getSignaturesOfType(apparentType, SignatureKind.Construct);
11998- // TS 1.0 spec: 4.12
11999- // If FuncExpr is of type Any, or of an object type that has no call or construct signatures
12000- // but is a subtype of the Function interface, the call is an untyped function call. In an
12001- // untyped function call no TypeArgs are permitted, Args can be any argument list, no contextual
12006+
12007+ // TS 1.0 Spec: 4.12
12008+ // In an untyped function call no TypeArgs are permitted, Args can be any argument list, no contextual
1200212009 // types are provided for the argument expressions, and the result is always of type Any.
12003- // We exclude union types because we may have a union of function types that happen to have
12004- // no common signatures.
12005- if (isTypeAny(funcType) ||
12006- (isTypeAny(apparentType) && funcType.flags & TypeFlags.TypeParameter) ||
12007- (!callSignatures.length && !constructSignatures.length && !(funcType.flags & TypeFlags.Union) && isTypeAssignableTo(funcType, globalFunctionType))) {
12010+ if (isUntypedFunctionCall(funcType, apparentType, callSignatures.length, constructSignatures.length)) {
1200812011 // The unknownType indicates that an error already occurred (and was reported). No
1200912012 // need to report another error in this case.
1201012013 if (funcType !== unknownType && node.typeArguments) {
@@ -12027,6 +12030,29 @@ namespace ts {
1202712030 return resolveCall(node, callSignatures, candidatesOutArray);
1202812031 }
1202912032
12033+ /**
12034+ * TS 1.0 spec: 4.12
12035+ * If FuncExpr is of type Any, or of an object type that has no call or construct signatures
12036+ * but is a subtype of the Function interface, the call is an untyped function call.
12037+ */
12038+ function isUntypedFunctionCall(funcType: Type, apparentFuncType: Type, numCallSignatures: number, numConstructSignatures: number) {
12039+ if (isTypeAny(funcType)) {
12040+ return true;
12041+ }
12042+ if (isTypeAny(apparentFuncType) && funcType.flags & TypeFlags.TypeParameter) {
12043+ return true;
12044+ }
12045+ if (!numCallSignatures && !numConstructSignatures) {
12046+ // We exclude union types because we may have a union of function types that happen to have
12047+ // no common signatures.
12048+ if (funcType.flags & TypeFlags.Union) {
12049+ return false;
12050+ }
12051+ return isTypeAssignableTo(funcType, globalFunctionType);
12052+ }
12053+ return false;
12054+ }
12055+
1203012056 function resolveNewExpression(node: NewExpression, candidatesOutArray: Signature[]): Signature {
1203112057 if (node.arguments && languageVersion < ScriptTarget.ES5) {
1203212058 const spreadIndex = getSpreadArgumentIndex(node.arguments);
@@ -12152,8 +12178,9 @@ namespace ts {
1215212178 }
1215312179
1215412180 const callSignatures = getSignaturesOfType(apparentType, SignatureKind.Call);
12181+ const constructSignatures = getSignaturesOfType(apparentType, SignatureKind.Construct);
1215512182
12156- if (isTypeAny (tagType) || (! callSignatures.length && !(tagType.flags & TypeFlags.Union) && isTypeAssignableTo(tagType, globalFunctionType) )) {
12183+ if (isUntypedFunctionCall (tagType, apparentType, callSignatures.length, constructSignatures.length )) {
1215712184 return resolveUntypedCall(node);
1215812185 }
1215912186
@@ -12198,7 +12225,8 @@ namespace ts {
1219812225 }
1219912226
1220012227 const callSignatures = getSignaturesOfType(apparentType, SignatureKind.Call);
12201- if (funcType === anyType || (!callSignatures.length && !(funcType.flags & TypeFlags.Union) && isTypeAssignableTo(funcType, globalFunctionType))) {
12228+ const constructSignatures = getSignaturesOfType(apparentType, SignatureKind.Construct);
12229+ if (isUntypedFunctionCall(funcType, apparentType, callSignatures.length, constructSignatures.length)) {
1220212230 return resolveUntypedCall(node);
1220312231 }
1220412232
@@ -12237,10 +12265,10 @@ namespace ts {
1223712265 // or that a different candidatesOutArray was passed in. Therefore, we need to redo the work
1223812266 // to correctly fill the candidatesOutArray.
1223912267 const cached = links.resolvedSignature;
12240- if (cached && cached !== anySignature && !candidatesOutArray) {
12268+ if (cached && cached !== resolvingSignature && !candidatesOutArray) {
1224112269 return cached;
1224212270 }
12243- links.resolvedSignature = anySignature ;
12271+ links.resolvedSignature = resolvingSignature ;
1224412272 const result = resolveSignature(node, candidatesOutArray);
1224512273 // If signature resolution originated in control flow type analysis (for example to compute the
1224612274 // assigned type in a flow assignment) we don't cache the result as it may be based on temporary
@@ -12252,7 +12280,7 @@ namespace ts {
1225212280 function getResolvedOrAnySignature(node: CallLikeExpression) {
1225312281 // If we're already in the process of resolving the given signature, don't resolve again as
1225412282 // that could cause infinite recursion. Instead, return anySignature.
12255- return getNodeLinks(node).resolvedSignature === anySignature ? anySignature : getResolvedSignature(node);
12283+ return getNodeLinks(node).resolvedSignature === resolvingSignature ? resolvingSignature : getResolvedSignature(node);
1225612284 }
1225712285
1225812286 function getInferredClassType(symbol: Symbol) {
@@ -18885,7 +18913,13 @@ namespace ts {
1888518913 (augmentations || (augmentations = [])).push(file.moduleAugmentations);
1888618914 }
1888718915 if (file.symbol && file.symbol.globalExports) {
18888- mergeSymbolTable(globals, file.symbol.globalExports);
18916+ // Merge in UMD exports with first-in-wins semantics (see #9771)
18917+ const source = file.symbol.globalExports;
18918+ for (const id in source) {
18919+ if (!(id in globals)) {
18920+ globals[id] = source[id];
18921+ }
18922+ }
1888918923 }
1889018924 if ((compilerOptions.isolatedModules || isExternalModule(file)) && !file.isDeclarationFile) {
1889118925 const fileRequestedExternalEmitHelpers = file.flags & NodeFlags.EmitHelperFlags;
0 commit comments