2
2
3
3
/* @internal */
4
4
namespace ts {
5
+ const ambientModuleSymbolRegex = /^".+"$/;
6
+
5
7
let nextSymbolId = 1;
6
8
let nextNodeId = 1;
7
9
let nextMergeId = 1;
@@ -100,6 +102,7 @@ namespace ts {
100
102
getAliasedSymbol: resolveAlias,
101
103
getEmitResolver,
102
104
getExportsOfModule: getExportsOfModuleAsArray,
105
+ getAmbientModules,
103
106
104
107
getJsxElementAttributesType,
105
108
getJsxIntrinsicTagNames,
@@ -329,6 +332,7 @@ namespace ts {
329
332
const assignableRelation = createMap<RelationComparisonResult>();
330
333
const comparableRelation = createMap<RelationComparisonResult>();
331
334
const identityRelation = createMap<RelationComparisonResult>();
335
+ const enumRelation = createMap<boolean>();
332
336
333
337
// This is for caching the result of getSymbolDisplayBuilder. Do not access directly.
334
338
let _displayBuilder: SymbolDisplayBuilder;
@@ -3347,7 +3351,13 @@ namespace ts {
3347
3351
// Otherwise, fall back to 'any'.
3348
3352
else {
3349
3353
if (compilerOptions.noImplicitAny) {
3350
- 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
+ }
3351
3361
}
3352
3362
type = anyType;
3353
3363
}
@@ -6186,8 +6196,14 @@ namespace ts {
6186
6196
if (source === target) {
6187
6197
return true;
6188
6198
}
6189
- if (source.symbol.name !== target.symbol.name || !(source.symbol.flags & SymbolFlags.RegularEnum) || !(target.symbol.flags & SymbolFlags.RegularEnum)) {
6190
- return false;
6199
+ const id = source.id + "," + target.id;
6200
+ if (enumRelation[id] !== undefined) {
6201
+ return enumRelation[id];
6202
+ }
6203
+ if (source.symbol.name !== target.symbol.name ||
6204
+ !(source.symbol.flags & SymbolFlags.RegularEnum) || !(target.symbol.flags & SymbolFlags.RegularEnum) ||
6205
+ (source.flags & TypeFlags.Union) !== (target.flags & TypeFlags.Union)) {
6206
+ return enumRelation[id] = false;
6191
6207
}
6192
6208
const targetEnumType = getTypeOfSymbol(target.symbol);
6193
6209
for (const property of getPropertiesOfType(getTypeOfSymbol(source.symbol))) {
@@ -6198,11 +6214,11 @@ namespace ts {
6198
6214
errorReporter(Diagnostics.Property_0_is_missing_in_type_1, property.name,
6199
6215
typeToString(target, /*enclosingDeclaration*/ undefined, TypeFormatFlags.UseFullyQualifiedType));
6200
6216
}
6201
- return false;
6217
+ return enumRelation[id] = false;
6202
6218
}
6203
6219
}
6204
6220
}
6205
- return true;
6221
+ return enumRelation[id] = true;
6206
6222
}
6207
6223
6208
6224
function isSimpleTypeRelatedTo(source: Type, target: Type, relation: Map<RelationComparisonResult>, errorReporter?: ErrorReporter) {
@@ -6217,8 +6233,18 @@ namespace ts {
6217
6233
if (source.flags & TypeFlags.Null && (!strictNullChecks || target.flags & TypeFlags.Null)) return true;
6218
6234
if (relation === assignableRelation || relation === comparableRelation) {
6219
6235
if (source.flags & TypeFlags.Any) return true;
6220
- if (source.flags & (TypeFlags.Number | TypeFlags.NumberLiteral) && target.flags & TypeFlags.Enum) return true;
6221
- if (source.flags & TypeFlags.NumberLiteral && target.flags & TypeFlags.EnumLiteral && (<LiteralType>source).text === (<LiteralType>target).text) return true;
6236
+ if ((source.flags & TypeFlags.Number | source.flags & TypeFlags.NumberLiteral) && target.flags & TypeFlags.EnumLike) return true;
6237
+ if (source.flags & TypeFlags.EnumLiteral &&
6238
+ target.flags & TypeFlags.EnumLiteral &&
6239
+ (<LiteralType>source).text === (<LiteralType>target).text &&
6240
+ isEnumTypeRelatedTo((<EnumLiteralType>source).baseType, (<EnumLiteralType>target).baseType, errorReporter)) {
6241
+ return true;
6242
+ }
6243
+ if (source.flags & TypeFlags.EnumLiteral &&
6244
+ target.flags & TypeFlags.Enum &&
6245
+ isEnumTypeRelatedTo(<EnumType>target, (<EnumLiteralType>source).baseType, errorReporter)) {
6246
+ return true;
6247
+ }
6222
6248
}
6223
6249
return false;
6224
6250
}
@@ -11961,18 +11987,12 @@ namespace ts {
11961
11987
// Function interface, since they have none by default. This is a bit of a leap of faith
11962
11988
// that the user will not add any.
11963
11989
const callSignatures = getSignaturesOfType(apparentType, SignatureKind.Call);
11964
-
11965
11990
const constructSignatures = getSignaturesOfType(apparentType, SignatureKind.Construct);
11966
- // TS 1.0 spec: 4.12
11967
- // If FuncExpr is of type Any, or of an object type that has no call or construct signatures
11968
- // but is a subtype of the Function interface, the call is an untyped function call. In an
11969
- // untyped function call no TypeArgs are permitted, Args can be any argument list, no contextual
11991
+
11992
+ // TS 1.0 Spec: 4.12
11993
+ // In an untyped function call no TypeArgs are permitted, Args can be any argument list, no contextual
11970
11994
// types are provided for the argument expressions, and the result is always of type Any.
11971
- // We exclude union types because we may have a union of function types that happen to have
11972
- // no common signatures.
11973
- if (isTypeAny(funcType) ||
11974
- (isTypeAny(apparentType) && funcType.flags & TypeFlags.TypeParameter) ||
11975
- (!callSignatures.length && !constructSignatures.length && !(funcType.flags & TypeFlags.Union) && isTypeAssignableTo(funcType, globalFunctionType))) {
11995
+ if (isUntypedFunctionCall(funcType, apparentType, callSignatures.length, constructSignatures.length)) {
11976
11996
// The unknownType indicates that an error already occurred (and was reported). No
11977
11997
// need to report another error in this case.
11978
11998
if (funcType !== unknownType && node.typeArguments) {
@@ -11995,6 +12015,29 @@ namespace ts {
11995
12015
return resolveCall(node, callSignatures, candidatesOutArray);
11996
12016
}
11997
12017
12018
+ /**
12019
+ * TS 1.0 spec: 4.12
12020
+ * If FuncExpr is of type Any, or of an object type that has no call or construct signatures
12021
+ * but is a subtype of the Function interface, the call is an untyped function call.
12022
+ */
12023
+ function isUntypedFunctionCall(funcType: Type, apparentFuncType: Type, numCallSignatures: number, numConstructSignatures: number) {
12024
+ if (isTypeAny(funcType)) {
12025
+ return true;
12026
+ }
12027
+ if (isTypeAny(apparentFuncType) && funcType.flags & TypeFlags.TypeParameter) {
12028
+ return true;
12029
+ }
12030
+ if (!numCallSignatures && !numConstructSignatures) {
12031
+ // We exclude union types because we may have a union of function types that happen to have
12032
+ // no common signatures.
12033
+ if (funcType.flags & TypeFlags.Union) {
12034
+ return false;
12035
+ }
12036
+ return isTypeAssignableTo(funcType, globalFunctionType);
12037
+ }
12038
+ return false;
12039
+ }
12040
+
11998
12041
function resolveNewExpression(node: NewExpression, candidatesOutArray: Signature[]): Signature {
11999
12042
if (node.arguments && languageVersion < ScriptTarget.ES5) {
12000
12043
const spreadIndex = getSpreadArgumentIndex(node.arguments);
@@ -12120,8 +12163,9 @@ namespace ts {
12120
12163
}
12121
12164
12122
12165
const callSignatures = getSignaturesOfType(apparentType, SignatureKind.Call);
12166
+ const constructSignatures = getSignaturesOfType(apparentType, SignatureKind.Construct);
12123
12167
12124
- if (isTypeAny (tagType) || (! callSignatures.length && !(tagType.flags & TypeFlags.Union) && isTypeAssignableTo(tagType, globalFunctionType) )) {
12168
+ if (isUntypedFunctionCall (tagType, apparentType, callSignatures.length, constructSignatures.length )) {
12125
12169
return resolveUntypedCall(node);
12126
12170
}
12127
12171
@@ -12166,7 +12210,8 @@ namespace ts {
12166
12210
}
12167
12211
12168
12212
const callSignatures = getSignaturesOfType(apparentType, SignatureKind.Call);
12169
- if (funcType === anyType || (!callSignatures.length && !(funcType.flags & TypeFlags.Union) && isTypeAssignableTo(funcType, globalFunctionType))) {
12213
+ const constructSignatures = getSignaturesOfType(apparentType, SignatureKind.Construct);
12214
+ if (isUntypedFunctionCall(funcType, apparentType, callSignatures.length, constructSignatures.length)) {
12170
12215
return resolveUntypedCall(node);
12171
12216
}
12172
12217
@@ -18767,7 +18812,13 @@ namespace ts {
18767
18812
(augmentations || (augmentations = [])).push(file.moduleAugmentations);
18768
18813
}
18769
18814
if (file.symbol && file.symbol.globalExports) {
18770
- mergeSymbolTable(globals, file.symbol.globalExports);
18815
+ // Merge in UMD exports with first-in-wins semantics (see #9771)
18816
+ const source = file.symbol.globalExports;
18817
+ for (const id in source) {
18818
+ if (!(id in globals)) {
18819
+ globals[id] = source[id];
18820
+ }
18821
+ }
18771
18822
}
18772
18823
});
18773
18824
@@ -19992,5 +20043,15 @@ namespace ts {
19992
20043
return true;
19993
20044
}
19994
20045
}
20046
+
20047
+ function getAmbientModules(): Symbol[] {
20048
+ const result: Symbol[] = [];
20049
+ for (const sym in globals) {
20050
+ if (ambientModuleSymbolRegex.test(sym)) {
20051
+ result.push(globals[sym]);
20052
+ }
20053
+ }
20054
+ return result;
20055
+ }
19995
20056
}
19996
20057
}
0 commit comments