@@ -1024,8 +1024,8 @@ namespace ts {
10241024 }
10251025 }
10261026
1027- function getDeclarationOfAliasSymbol(symbol: Symbol): Declaration {
1028- return findMap (symbol.declarations, d => isAliasSymbolDeclaration(d) ? d : undefined);
1027+ function getDeclarationOfAliasSymbol(symbol: Symbol): Declaration | undefined {
1028+ return forEach (symbol.declarations, d => isAliasSymbolDeclaration(d) ? d : undefined);
10291029 }
10301030
10311031 function getTargetOfImportEqualsDeclaration(node: ImportEqualsDeclaration): Symbol {
@@ -1192,6 +1192,7 @@ namespace ts {
11921192 if (!links.target) {
11931193 links.target = resolvingSymbol;
11941194 const node = getDeclarationOfAliasSymbol(symbol);
1195+ Debug.assert(!!node);
11951196 const target = getTargetOfAliasDeclaration(node);
11961197 if (links.target === resolvingSymbol) {
11971198 links.target = target || unknownSymbol;
@@ -1227,6 +1228,7 @@ namespace ts {
12271228 if (!links.referenced) {
12281229 links.referenced = true;
12291230 const node = getDeclarationOfAliasSymbol(symbol);
1231+ Debug.assert(!!node);
12301232 if (node.kind === SyntaxKind.ExportAssignment) {
12311233 // export default <symbol>
12321234 checkExpressionCached((<ExportAssignment>node).expression);
@@ -3348,7 +3350,13 @@ namespace ts {
33483350 // Otherwise, fall back to 'any'.
33493351 else {
33503352 if (compilerOptions.noImplicitAny) {
3351- error(setter, Diagnostics.Property_0_implicitly_has_type_any_because_its_set_accessor_lacks_a_type_annotation, symbolToString(symbol));
3353+ if (setter) {
3354+ error(setter, Diagnostics.Property_0_implicitly_has_type_any_because_its_set_accessor_lacks_a_parameter_type_annotation, symbolToString(symbol));
3355+ }
3356+ else {
3357+ Debug.assert(!!getter, "there must existed getter as we are current checking either setter or getter in this function");
3358+ error(getter, Diagnostics.Property_0_implicitly_has_type_any_because_its_get_accessor_lacks_a_return_type_annotation, symbolToString(symbol));
3359+ }
33523360 }
33533361 type = anyType;
33543362 }
@@ -5374,7 +5382,7 @@ namespace ts {
53745382 while (i > 0) {
53755383 i--;
53765384 if (isSubtypeOfAny(types[i], types)) {
5377- types.splice(i, 1 );
5385+ orderedRemoveItemAt(types, i );
53785386 }
53795387 }
53805388 }
@@ -8758,7 +8766,7 @@ namespace ts {
87588766 // The location isn't a reference to the given symbol, meaning we're being asked
87598767 // a hypothetical question of what type the symbol would have if there was a reference
87608768 // 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
8769+ // hypothetical reference (control flow information is created and attached by the
87628770 // binder), we simply return the declared type of the symbol.
87638771 return getTypeOfSymbol(symbol);
87648772 }
@@ -11993,18 +12001,12 @@ namespace ts {
1199312001 // Function interface, since they have none by default. This is a bit of a leap of faith
1199412002 // that the user will not add any.
1199512003 const callSignatures = getSignaturesOfType(apparentType, SignatureKind.Call);
11996-
1199712004 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
12005+
12006+ // TS 1.0 Spec: 4.12
12007+ // In an untyped function call no TypeArgs are permitted, Args can be any argument list, no contextual
1200212008 // 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))) {
12009+ if (isUntypedFunctionCall(funcType, apparentType, callSignatures.length, constructSignatures.length)) {
1200812010 // The unknownType indicates that an error already occurred (and was reported). No
1200912011 // need to report another error in this case.
1201012012 if (funcType !== unknownType && node.typeArguments) {
@@ -12027,6 +12029,29 @@ namespace ts {
1202712029 return resolveCall(node, callSignatures, candidatesOutArray);
1202812030 }
1202912031
12032+ /**
12033+ * TS 1.0 spec: 4.12
12034+ * If FuncExpr is of type Any, or of an object type that has no call or construct signatures
12035+ * but is a subtype of the Function interface, the call is an untyped function call.
12036+ */
12037+ function isUntypedFunctionCall(funcType: Type, apparentFuncType: Type, numCallSignatures: number, numConstructSignatures: number) {
12038+ if (isTypeAny(funcType)) {
12039+ return true;
12040+ }
12041+ if (isTypeAny(apparentFuncType) && funcType.flags & TypeFlags.TypeParameter) {
12042+ return true;
12043+ }
12044+ if (!numCallSignatures && !numConstructSignatures) {
12045+ // We exclude union types because we may have a union of function types that happen to have
12046+ // no common signatures.
12047+ if (funcType.flags & TypeFlags.Union) {
12048+ return false;
12049+ }
12050+ return isTypeAssignableTo(funcType, globalFunctionType);
12051+ }
12052+ return false;
12053+ }
12054+
1203012055 function resolveNewExpression(node: NewExpression, candidatesOutArray: Signature[]): Signature {
1203112056 if (node.arguments && languageVersion < ScriptTarget.ES5) {
1203212057 const spreadIndex = getSpreadArgumentIndex(node.arguments);
@@ -12152,8 +12177,9 @@ namespace ts {
1215212177 }
1215312178
1215412179 const callSignatures = getSignaturesOfType(apparentType, SignatureKind.Call);
12180+ const constructSignatures = getSignaturesOfType(apparentType, SignatureKind.Construct);
1215512181
12156- if (isTypeAny (tagType) || (! callSignatures.length && !(tagType.flags & TypeFlags.Union) && isTypeAssignableTo(tagType, globalFunctionType) )) {
12182+ if (isUntypedFunctionCall (tagType, apparentType, callSignatures.length, constructSignatures.length )) {
1215712183 return resolveUntypedCall(node);
1215812184 }
1215912185
@@ -12198,7 +12224,8 @@ namespace ts {
1219812224 }
1219912225
1220012226 const callSignatures = getSignaturesOfType(apparentType, SignatureKind.Call);
12201- if (funcType === anyType || (!callSignatures.length && !(funcType.flags & TypeFlags.Union) && isTypeAssignableTo(funcType, globalFunctionType))) {
12227+ const constructSignatures = getSignaturesOfType(apparentType, SignatureKind.Construct);
12228+ if (isUntypedFunctionCall(funcType, apparentType, callSignatures.length, constructSignatures.length)) {
1220212229 return resolveUntypedCall(node);
1220312230 }
1220412231
@@ -18885,7 +18912,13 @@ namespace ts {
1888518912 (augmentations || (augmentations = [])).push(file.moduleAugmentations);
1888618913 }
1888718914 if (file.symbol && file.symbol.globalExports) {
18888- mergeSymbolTable(globals, file.symbol.globalExports);
18915+ // Merge in UMD exports with first-in-wins semantics (see #9771)
18916+ const source = file.symbol.globalExports;
18917+ for (const id in source) {
18918+ if (!(id in globals)) {
18919+ globals[id] = source[id];
18920+ }
18921+ }
1888918922 }
1889018923 if ((compilerOptions.isolatedModules || isExternalModule(file)) && !file.isDeclarationFile) {
1889118924 const fileRequestedExternalEmitHelpers = file.flags & NodeFlags.EmitHelperFlags;
0 commit comments