@@ -143,6 +143,7 @@ namespace ts {
143
143
144
144
const anySignature = createSignature(undefined, undefined, undefined, emptyArray, anyType, /*typePredicate*/ undefined, 0, /*hasRestParameter*/ false, /*hasLiteralTypes*/ false);
145
145
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);
146
147
147
148
const enumNumberIndexInfo = createIndexInfo(stringType, /*isReadonly*/ true);
148
149
@@ -1024,8 +1025,8 @@ namespace ts {
1024
1025
}
1025
1026
}
1026
1027
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);
1029
1030
}
1030
1031
1031
1032
function getTargetOfImportEqualsDeclaration(node: ImportEqualsDeclaration): Symbol {
@@ -1192,6 +1193,7 @@ namespace ts {
1192
1193
if (!links.target) {
1193
1194
links.target = resolvingSymbol;
1194
1195
const node = getDeclarationOfAliasSymbol(symbol);
1196
+ Debug.assert(!!node);
1195
1197
const target = getTargetOfAliasDeclaration(node);
1196
1198
if (links.target === resolvingSymbol) {
1197
1199
links.target = target || unknownSymbol;
@@ -1227,6 +1229,7 @@ namespace ts {
1227
1229
if (!links.referenced) {
1228
1230
links.referenced = true;
1229
1231
const node = getDeclarationOfAliasSymbol(symbol);
1232
+ Debug.assert(!!node);
1230
1233
if (node.kind === SyntaxKind.ExportAssignment) {
1231
1234
// export default <symbol>
1232
1235
checkExpressionCached((<ExportAssignment>node).expression);
@@ -3348,7 +3351,13 @@ namespace ts {
3348
3351
// Otherwise, fall back to 'any'.
3349
3352
else {
3350
3353
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
+ }
3352
3361
}
3353
3362
type = anyType;
3354
3363
}
@@ -5374,7 +5383,7 @@ namespace ts {
5374
5383
while (i > 0) {
5375
5384
i--;
5376
5385
if (isSubtypeOfAny(types[i], types)) {
5377
- types.splice(i, 1 );
5386
+ orderedRemoveItemAt(types, i );
5378
5387
}
5379
5388
}
5380
5389
}
@@ -8758,7 +8767,7 @@ namespace ts {
8758
8767
// The location isn't a reference to the given symbol, meaning we're being asked
8759
8768
// a hypothetical question of what type the symbol would have if there was a reference
8760
8769
// 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
8762
8771
// binder), we simply return the declared type of the symbol.
8763
8772
return getTypeOfSymbol(symbol);
8764
8773
}
@@ -11993,18 +12002,12 @@ namespace ts {
11993
12002
// Function interface, since they have none by default. This is a bit of a leap of faith
11994
12003
// that the user will not add any.
11995
12004
const callSignatures = getSignaturesOfType(apparentType, SignatureKind.Call);
11996
-
11997
12005
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
12002
12009
// 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)) {
12008
12011
// The unknownType indicates that an error already occurred (and was reported). No
12009
12012
// need to report another error in this case.
12010
12013
if (funcType !== unknownType && node.typeArguments) {
@@ -12027,6 +12030,29 @@ namespace ts {
12027
12030
return resolveCall(node, callSignatures, candidatesOutArray);
12028
12031
}
12029
12032
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
+
12030
12056
function resolveNewExpression(node: NewExpression, candidatesOutArray: Signature[]): Signature {
12031
12057
if (node.arguments && languageVersion < ScriptTarget.ES5) {
12032
12058
const spreadIndex = getSpreadArgumentIndex(node.arguments);
@@ -12152,8 +12178,9 @@ namespace ts {
12152
12178
}
12153
12179
12154
12180
const callSignatures = getSignaturesOfType(apparentType, SignatureKind.Call);
12181
+ const constructSignatures = getSignaturesOfType(apparentType, SignatureKind.Construct);
12155
12182
12156
- if (isTypeAny (tagType) || (! callSignatures.length && !(tagType.flags & TypeFlags.Union) && isTypeAssignableTo(tagType, globalFunctionType) )) {
12183
+ if (isUntypedFunctionCall (tagType, apparentType, callSignatures.length, constructSignatures.length )) {
12157
12184
return resolveUntypedCall(node);
12158
12185
}
12159
12186
@@ -12198,7 +12225,8 @@ namespace ts {
12198
12225
}
12199
12226
12200
12227
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)) {
12202
12230
return resolveUntypedCall(node);
12203
12231
}
12204
12232
@@ -12237,10 +12265,10 @@ namespace ts {
12237
12265
// or that a different candidatesOutArray was passed in. Therefore, we need to redo the work
12238
12266
// to correctly fill the candidatesOutArray.
12239
12267
const cached = links.resolvedSignature;
12240
- if (cached && cached !== anySignature && !candidatesOutArray) {
12268
+ if (cached && cached !== resolvingSignature && !candidatesOutArray) {
12241
12269
return cached;
12242
12270
}
12243
- links.resolvedSignature = anySignature ;
12271
+ links.resolvedSignature = resolvingSignature ;
12244
12272
const result = resolveSignature(node, candidatesOutArray);
12245
12273
// If signature resolution originated in control flow type analysis (for example to compute the
12246
12274
// 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 {
12252
12280
function getResolvedOrAnySignature(node: CallLikeExpression) {
12253
12281
// If we're already in the process of resolving the given signature, don't resolve again as
12254
12282
// 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);
12256
12284
}
12257
12285
12258
12286
function getInferredClassType(symbol: Symbol) {
@@ -18885,7 +18913,13 @@ namespace ts {
18885
18913
(augmentations || (augmentations = [])).push(file.moduleAugmentations);
18886
18914
}
18887
18915
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
+ }
18889
18923
}
18890
18924
if ((compilerOptions.isolatedModules || isExternalModule(file)) && !file.isDeclarationFile) {
18891
18925
const fileRequestedExternalEmitHelpers = file.flags & NodeFlags.EmitHelperFlags;
0 commit comments