@@ -388,7 +388,7 @@ namespace ts {
388
388
return node1.pos <= node2.pos;
389
389
}
390
390
391
- if (!compilerOptions.out) {
391
+ if (!compilerOptions.outFile && !compilerOptions. out) {
392
392
return true;
393
393
}
394
394
@@ -965,28 +965,19 @@ namespace ts {
965
965
// Escape the name in the "require(...)" clause to ensure we find the right symbol.
966
966
let moduleName = escapeIdentifier(moduleReferenceLiteral.text);
967
967
968
- if (!moduleName) return;
968
+ if (!moduleName) {
969
+ return;
970
+ }
969
971
let isRelative = isExternalModuleNameRelative(moduleName);
970
972
if (!isRelative) {
971
973
let symbol = getSymbol(globals, "\"" + moduleName + "\"", SymbolFlags.ValueModule);
972
974
if (symbol) {
973
975
return symbol;
974
976
}
975
977
}
976
- let fileName: string;
977
- let sourceFile: SourceFile;
978
- while (true) {
979
- fileName = normalizePath(combinePaths(searchPath, moduleName));
980
- sourceFile = forEach(supportedExtensions, extension => host.getSourceFile(fileName + extension));
981
- if (sourceFile || isRelative) {
982
- break;
983
- }
984
- let parentPath = getDirectoryPath(searchPath);
985
- if (parentPath === searchPath) {
986
- break;
987
- }
988
- searchPath = parentPath;
989
- }
978
+
979
+ let fileName = getResolvedModuleFileName(getSourceFile(location), moduleReferenceLiteral.text);
980
+ let sourceFile = fileName && host.getSourceFile(fileName);
990
981
if (sourceFile) {
991
982
if (sourceFile.symbol) {
992
983
return sourceFile.symbol;
@@ -2175,10 +2166,13 @@ namespace ts {
2175
2166
function collectLinkedAliases(node: Identifier): Node[] {
2176
2167
let exportSymbol: Symbol;
2177
2168
if (node.parent && node.parent.kind === SyntaxKind.ExportAssignment) {
2178
- exportSymbol = resolveName(node.parent, node.text, SymbolFlags.Value | SymbolFlags.Type | SymbolFlags.Namespace, Diagnostics.Cannot_find_name_0, node);
2169
+ exportSymbol = resolveName(node.parent, node.text, SymbolFlags.Value | SymbolFlags.Type | SymbolFlags.Namespace | SymbolFlags.Alias , Diagnostics.Cannot_find_name_0, node);
2179
2170
}
2180
2171
else if (node.parent.kind === SyntaxKind.ExportSpecifier) {
2181
- exportSymbol = getTargetOfExportSpecifier(<ExportSpecifier>node.parent);
2172
+ let exportSpecifier = <ExportSpecifier>node.parent;
2173
+ exportSymbol = (<ExportDeclaration>exportSpecifier.parent.parent).moduleSpecifier ?
2174
+ getExternalModuleMember(<ExportDeclaration>exportSpecifier.parent.parent, exportSpecifier) :
2175
+ resolveEntityName(exportSpecifier.propertyName || exportSpecifier.name, SymbolFlags.Value | SymbolFlags.Type | SymbolFlags.Namespace | SymbolFlags.Alias);
2182
2176
}
2183
2177
let result: Node[] = [];
2184
2178
if (exportSymbol) {
@@ -3131,52 +3125,66 @@ namespace ts {
3131
3125
setObjectTypeMembers(type, members, arrayType.callSignatures, arrayType.constructSignatures, arrayType.stringIndexType, arrayType.numberIndexType);
3132
3126
}
3133
3127
3134
- function findMatchingSignature(signature: Signature, signatureList: Signature[]): Signature {
3135
- for (let s of signatureList) {
3136
- // Only signatures with no type parameters may differ in return types
3137
- if (compareSignatures(signature, s, /*compareReturnTypes*/ !!signature.typeParameters, compareTypes)) {
3128
+ function findMatchingSignature(signatureList: Signature[], signature: Signature, partialMatch: boolean, ignoreReturnTypes: boolean): Signature {
3129
+ for (let s of signatureList) {
3130
+ if (compareSignatures(s, signature, partialMatch, ignoreReturnTypes, compareTypes)) {
3138
3131
return s;
3139
3132
}
3140
3133
}
3141
3134
}
3142
3135
3143
- function findMatchingSignatures(signature: Signature, signatureLists: Signature[][]): Signature[] {
3136
+ function findMatchingSignatures(signatureLists: Signature[][], signature: Signature, listIndex: number): Signature[] {
3137
+ if (signature.typeParameters) {
3138
+ // We require an exact match for generic signatures, so we only return signatures from the first
3139
+ // signature list and only if they have exact matches in the other signature lists.
3140
+ if (listIndex > 0) {
3141
+ return undefined;
3142
+ }
3143
+ for (let i = 1; i < signatureLists.length; i++) {
3144
+ if (!findMatchingSignature(signatureLists[i], signature, /*partialMatch*/ false, /*ignoreReturnTypes*/ false)) {
3145
+ return undefined;
3146
+ }
3147
+ }
3148
+ return [signature];
3149
+ }
3144
3150
let result: Signature[] = undefined;
3145
- for (let i = 1; i < signatureLists.length; i++) {
3146
- let match = findMatchingSignature(signature, signatureLists[i]);
3151
+ for (let i = 0; i < signatureLists.length; i++) {
3152
+ // Allow matching non-generic signatures to have excess parameters and different return types
3153
+ let match = i === listIndex ? signature : findMatchingSignature(signatureLists[i], signature, /*partialMatch*/ true, /*ignoreReturnTypes*/ true);
3147
3154
if (!match) {
3148
3155
return undefined;
3149
3156
}
3150
- if (!result) {
3151
- result = [signature];
3152
- }
3153
- if (match !== signature) {
3154
- result.push(match);
3157
+ if (!contains(result, match)) {
3158
+ (result || (result = [])).push(match);
3155
3159
}
3156
3160
}
3157
3161
return result;
3158
3162
}
3159
3163
3160
- // The signatures of a union type are those signatures that are present and identical in each of the
3161
- // constituent types, except that non-generic signatures may differ in return types. When signatures
3162
- // differ in return types, the resulting return type is the union of the constituent return types.
3164
+ // The signatures of a union type are those signatures that are present in each of the constituent types.
3165
+ // Generic signatures must match exactly, but non-generic signatures are allowed to have extra optional
3166
+ // parameters and may differ in return types. When signatures differ in return types, the resulting return
3167
+ // type is the union of the constituent return types.
3163
3168
function getUnionSignatures(types: Type[], kind: SignatureKind): Signature[] {
3164
3169
let signatureLists = map(types, t => getSignaturesOfType(t, kind));
3165
3170
let result: Signature[] = undefined;
3166
- for (let source of signatureLists[0]) {
3167
- let unionSignatures = findMatchingSignatures(source, signatureLists);
3168
- if (unionSignatures) {
3169
- let signature: Signature = undefined;
3170
- if (unionSignatures.length === 1 || source.typeParameters) {
3171
- signature = source;
3172
- }
3173
- else {
3174
- signature = cloneSignature(source);
3175
- // Clear resolved return type we possibly got from cloneSignature
3176
- signature.resolvedReturnType = undefined;
3177
- signature.unionSignatures = unionSignatures;
3171
+ for (let i = 0; i < signatureLists.length; i++) {
3172
+ for (let signature of signatureLists[i]) {
3173
+ // Only process signatures with parameter lists that aren't already in the result list
3174
+ if (!result || !findMatchingSignature(result, signature, /*partialMatch*/ false, /*ignoreReturnTypes*/ true)) {
3175
+ let unionSignatures = findMatchingSignatures(signatureLists, signature, i);
3176
+ if (unionSignatures) {
3177
+ let s = signature;
3178
+ // Union the result types when more than one signature matches
3179
+ if (unionSignatures.length > 1) {
3180
+ s = cloneSignature(signature);
3181
+ // Clear resolved return type we possibly got from cloneSignature
3182
+ s.resolvedReturnType = undefined;
3183
+ s.unionSignatures = unionSignatures;
3184
+ }
3185
+ (result || (result = [])).push(s);
3186
+ }
3178
3187
}
3179
- (result || (result = [])).push(signature);
3180
3188
}
3181
3189
}
3182
3190
return result || emptyArray;
@@ -5272,7 +5280,7 @@ namespace ts {
5272
5280
}
5273
5281
let result = Ternary.True;
5274
5282
for (let i = 0, len = sourceSignatures.length; i < len; ++i) {
5275
- let related = compareSignatures(sourceSignatures[i], targetSignatures[i], /*compareReturnTypes */ true , isRelatedTo);
5283
+ let related = compareSignatures(sourceSignatures[i], targetSignatures[i], /*partialMatch */ false, /*ignoreReturnTypes*/ false , isRelatedTo);
5276
5284
if (!related) {
5277
5285
return Ternary.False;
5278
5286
}
@@ -5402,14 +5410,18 @@ namespace ts {
5402
5410
return compareTypes(getTypeOfSymbol(sourceProp), getTypeOfSymbol(targetProp));
5403
5411
}
5404
5412
5405
- function compareSignatures(source: Signature, target: Signature, compareReturnTypes : boolean, compareTypes: (s: Type, t: Type) => Ternary): Ternary {
5413
+ function compareSignatures(source: Signature, target: Signature, partialMatch: boolean, ignoreReturnTypes : boolean, compareTypes: (s: Type, t: Type) => Ternary): Ternary {
5406
5414
if (source === target) {
5407
5415
return Ternary.True;
5408
5416
}
5409
5417
if (source.parameters.length !== target.parameters.length ||
5410
5418
source.minArgumentCount !== target.minArgumentCount ||
5411
5419
source.hasRestParameter !== target.hasRestParameter) {
5412
- return Ternary.False;
5420
+ if (!partialMatch ||
5421
+ source.parameters.length < target.parameters.length && !source.hasRestParameter ||
5422
+ source.minArgumentCount > target.minArgumentCount) {
5423
+ return Ternary.False;
5424
+ }
5413
5425
}
5414
5426
let result = Ternary.True;
5415
5427
if (source.typeParameters && target.typeParameters) {
@@ -5431,16 +5443,18 @@ namespace ts {
5431
5443
// M and N (the signatures) are instantiated using type Any as the type argument for all type parameters declared by M and N
5432
5444
source = getErasedSignature(source);
5433
5445
target = getErasedSignature(target);
5434
- for (let i = 0, len = source.parameters.length; i < len; i++) {
5435
- let s = source.hasRestParameter && i === len - 1 ? getRestTypeOfSignature(source) : getTypeOfSymbol(source.parameters[i]);
5436
- let t = target.hasRestParameter && i === len - 1 ? getRestTypeOfSignature(target) : getTypeOfSymbol(target.parameters[i]);
5446
+ let sourceLen = source.parameters.length;
5447
+ let targetLen = target.parameters.length;
5448
+ for (let i = 0; i < targetLen; i++) {
5449
+ let s = source.hasRestParameter && i === sourceLen - 1 ? getRestTypeOfSignature(source) : getTypeOfSymbol(source.parameters[i]);
5450
+ let t = target.hasRestParameter && i === targetLen - 1 ? getRestTypeOfSignature(target) : getTypeOfSymbol(target.parameters[i]);
5437
5451
let related = compareTypes(s, t);
5438
5452
if (!related) {
5439
5453
return Ternary.False;
5440
5454
}
5441
5455
result &= related;
5442
5456
}
5443
- if (compareReturnTypes ) {
5457
+ if (!ignoreReturnTypes ) {
5444
5458
result &= compareTypes(getReturnTypeOfSignature(source), getReturnTypeOfSignature(target));
5445
5459
}
5446
5460
return result;
@@ -6954,20 +6968,13 @@ namespace ts {
6954
6968
let signatureList: Signature[];
6955
6969
let types = (<UnionType>type).types;
6956
6970
for (let current of types) {
6957
- // The signature set of all constituent type with call signatures should match
6958
- // So number of signatures allowed is either 0 or 1
6959
- if (signatureList &&
6960
- getSignaturesOfStructuredType(current, SignatureKind.Call).length > 1) {
6961
- return undefined;
6962
- }
6963
-
6964
6971
let signature = getNonGenericSignature(current);
6965
6972
if (signature) {
6966
6973
if (!signatureList) {
6967
6974
// This signature will contribute to contextual union signature
6968
6975
signatureList = [signature];
6969
6976
}
6970
- else if (!compareSignatures(signatureList[0], signature, /*compareReturnTypes */ false, compareTypes)) {
6977
+ else if (!compareSignatures(signatureList[0], signature, /*partialMatch */ false, /*ignoreReturnTypes*/ true , compareTypes)) {
6971
6978
// Signatures aren't identical, do not use
6972
6979
return undefined;
6973
6980
}
@@ -13315,7 +13322,7 @@ namespace ts {
13315
13322
}
13316
13323
}
13317
13324
else {
13318
- if (languageVersion >= ScriptTarget.ES6) {
13325
+ if (languageVersion >= ScriptTarget.ES6 && !isInAmbientContext(node) ) {
13319
13326
// Import equals declaration is deprecated in es6 or above
13320
13327
grammarErrorOnNode(node, Diagnostics.Import_assignment_cannot_be_used_when_targeting_ECMAScript_6_or_higher_Consider_using_import_Asterisk_as_ns_from_mod_import_a_from_mod_or_import_d_from_mod_instead);
13321
13328
}
@@ -13838,7 +13845,11 @@ namespace ts {
13838
13845
}
13839
13846
break;
13840
13847
}
13841
-
13848
+
13849
+ if (introducesArgumentsExoticObject(location)) {
13850
+ copySymbol(argumentsSymbol, meaning);
13851
+ }
13852
+
13842
13853
memberFlags = location.flags;
13843
13854
location = location.parent;
13844
13855
}
0 commit comments