Skip to content

Commit

Permalink
Update LKG
Browse files Browse the repository at this point in the history
  • Loading branch information
mhegazy committed Apr 25, 2017
1 parent 9ada915 commit 47e5569
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 94 deletions.
21 changes: 7 additions & 14 deletions lib/tsc.js
Original file line number Diff line number Diff line change
Expand Up @@ -27271,9 +27271,9 @@ var ts;
return checkTypeRelatedTo(source, target, comparableRelation, errorNode, headMessage, containingMessageChain);
}
function isSignatureAssignableTo(source, target, ignoreReturnTypes) {
return compareSignaturesRelated(source, target, false, ignoreReturnTypes, false, undefined, compareTypesAssignable) !== 0;
return compareSignaturesRelated(source, target, ignoreReturnTypes, false, undefined, compareTypesAssignable) !== 0;
}
function compareSignaturesRelated(source, target, checkAsCallback, ignoreReturnTypes, reportErrors, errorReporter, compareTypes) {
function compareSignaturesRelated(source, target, ignoreReturnTypes, reportErrors, errorReporter, compareTypes) {
if (source === target) {
return -1;
}
Expand Down Expand Up @@ -27304,15 +27304,9 @@ var ts;
var sourceParams = source.parameters;
var targetParams = target.parameters;
for (var i = 0; i < checkCount; i++) {
var sourceType = i < sourceMax ? getTypeOfParameter(sourceParams[i]) : getRestTypeOfSignature(source);
var targetType = i < targetMax ? getTypeOfParameter(targetParams[i]) : getRestTypeOfSignature(target);
var sourceSig = getSingleCallSignature(getNonNullableType(sourceType));
var targetSig = getSingleCallSignature(getNonNullableType(targetType));
var callbacks = sourceSig && targetSig && !sourceSig.typePredicate && !targetSig.typePredicate &&
(getFalsyFlags(sourceType) & 6144) === (getFalsyFlags(targetType) & 6144);
var related = callbacks ?
compareSignaturesRelated(targetSig, sourceSig, true, false, reportErrors, errorReporter, compareTypes) :
!checkAsCallback && compareTypes(sourceType, targetType, false) || compareTypes(targetType, sourceType, reportErrors);
var s = i < sourceMax ? getTypeOfParameter(sourceParams[i]) : getRestTypeOfSignature(source);
var t = i < targetMax ? getTypeOfParameter(targetParams[i]) : getRestTypeOfSignature(target);
var related = compareTypes(s, t, false) || compareTypes(t, s, reportErrors);
if (!related) {
if (reportErrors) {
errorReporter(ts.Diagnostics.Types_of_parameters_0_and_1_are_incompatible, sourceParams[i < sourceMax ? i : sourceMax].name, targetParams[i < targetMax ? i : targetMax].name);
Expand All @@ -27339,8 +27333,7 @@ var ts;
}
}
else {
result &= checkAsCallback && compareTypes(targetReturnType, sourceReturnType, false) ||
compareTypes(sourceReturnType, targetReturnType, reportErrors);
result &= compareTypes(sourceReturnType, targetReturnType, reportErrors);
}
}
return result;
Expand Down Expand Up @@ -28155,7 +28148,7 @@ var ts;
return result;
}
function signatureRelatedTo(source, target, reportErrors) {
return compareSignaturesRelated(source, target, false, false, reportErrors, reportError, isRelatedTo);
return compareSignaturesRelated(source, target, false, reportErrors, reportError, isRelatedTo);
}
function signaturesIdenticalTo(source, target, kind) {
var sourceSignatures = getSignaturesOfType(source, kind);
Expand Down
21 changes: 7 additions & 14 deletions lib/tsserver.js
Original file line number Diff line number Diff line change
Expand Up @@ -28433,9 +28433,9 @@ var ts;
return checkTypeRelatedTo(source, target, comparableRelation, errorNode, headMessage, containingMessageChain);
}
function isSignatureAssignableTo(source, target, ignoreReturnTypes) {
return compareSignaturesRelated(source, target, false, ignoreReturnTypes, false, undefined, compareTypesAssignable) !== 0;
return compareSignaturesRelated(source, target, ignoreReturnTypes, false, undefined, compareTypesAssignable) !== 0;
}
function compareSignaturesRelated(source, target, checkAsCallback, ignoreReturnTypes, reportErrors, errorReporter, compareTypes) {
function compareSignaturesRelated(source, target, ignoreReturnTypes, reportErrors, errorReporter, compareTypes) {
if (source === target) {
return -1;
}
Expand Down Expand Up @@ -28466,15 +28466,9 @@ var ts;
var sourceParams = source.parameters;
var targetParams = target.parameters;
for (var i = 0; i < checkCount; i++) {
var sourceType = i < sourceMax ? getTypeOfParameter(sourceParams[i]) : getRestTypeOfSignature(source);
var targetType = i < targetMax ? getTypeOfParameter(targetParams[i]) : getRestTypeOfSignature(target);
var sourceSig = getSingleCallSignature(getNonNullableType(sourceType));
var targetSig = getSingleCallSignature(getNonNullableType(targetType));
var callbacks = sourceSig && targetSig && !sourceSig.typePredicate && !targetSig.typePredicate &&
(getFalsyFlags(sourceType) & 6144) === (getFalsyFlags(targetType) & 6144);
var related = callbacks ?
compareSignaturesRelated(targetSig, sourceSig, true, false, reportErrors, errorReporter, compareTypes) :
!checkAsCallback && compareTypes(sourceType, targetType, false) || compareTypes(targetType, sourceType, reportErrors);
var s = i < sourceMax ? getTypeOfParameter(sourceParams[i]) : getRestTypeOfSignature(source);
var t = i < targetMax ? getTypeOfParameter(targetParams[i]) : getRestTypeOfSignature(target);
var related = compareTypes(s, t, false) || compareTypes(t, s, reportErrors);
if (!related) {
if (reportErrors) {
errorReporter(ts.Diagnostics.Types_of_parameters_0_and_1_are_incompatible, sourceParams[i < sourceMax ? i : sourceMax].name, targetParams[i < targetMax ? i : targetMax].name);
Expand All @@ -28501,8 +28495,7 @@ var ts;
}
}
else {
result &= checkAsCallback && compareTypes(targetReturnType, sourceReturnType, false) ||
compareTypes(sourceReturnType, targetReturnType, reportErrors);
result &= compareTypes(sourceReturnType, targetReturnType, reportErrors);
}
}
return result;
Expand Down Expand Up @@ -29317,7 +29310,7 @@ var ts;
return result;
}
function signatureRelatedTo(source, target, reportErrors) {
return compareSignaturesRelated(source, target, false, false, reportErrors, reportError, isRelatedTo);
return compareSignaturesRelated(source, target, false, reportErrors, reportError, isRelatedTo);
}
function signaturesIdenticalTo(source, target, kind) {
var sourceSignatures = getSignaturesOfType(source, kind);
Expand Down
21 changes: 7 additions & 14 deletions lib/tsserverlibrary.js
Original file line number Diff line number Diff line change
Expand Up @@ -29779,9 +29779,9 @@ var ts;
return checkTypeRelatedTo(source, target, comparableRelation, errorNode, headMessage, containingMessageChain);
}
function isSignatureAssignableTo(source, target, ignoreReturnTypes) {
return compareSignaturesRelated(source, target, false, ignoreReturnTypes, false, undefined, compareTypesAssignable) !== 0;
return compareSignaturesRelated(source, target, ignoreReturnTypes, false, undefined, compareTypesAssignable) !== 0;
}
function compareSignaturesRelated(source, target, checkAsCallback, ignoreReturnTypes, reportErrors, errorReporter, compareTypes) {
function compareSignaturesRelated(source, target, ignoreReturnTypes, reportErrors, errorReporter, compareTypes) {
if (source === target) {
return -1;
}
Expand Down Expand Up @@ -29812,15 +29812,9 @@ var ts;
var sourceParams = source.parameters;
var targetParams = target.parameters;
for (var i = 0; i < checkCount; i++) {
var sourceType = i < sourceMax ? getTypeOfParameter(sourceParams[i]) : getRestTypeOfSignature(source);
var targetType = i < targetMax ? getTypeOfParameter(targetParams[i]) : getRestTypeOfSignature(target);
var sourceSig = getSingleCallSignature(getNonNullableType(sourceType));
var targetSig = getSingleCallSignature(getNonNullableType(targetType));
var callbacks = sourceSig && targetSig && !sourceSig.typePredicate && !targetSig.typePredicate &&
(getFalsyFlags(sourceType) & 6144) === (getFalsyFlags(targetType) & 6144);
var related = callbacks ?
compareSignaturesRelated(targetSig, sourceSig, true, false, reportErrors, errorReporter, compareTypes) :
!checkAsCallback && compareTypes(sourceType, targetType, false) || compareTypes(targetType, sourceType, reportErrors);
var s = i < sourceMax ? getTypeOfParameter(sourceParams[i]) : getRestTypeOfSignature(source);
var t = i < targetMax ? getTypeOfParameter(targetParams[i]) : getRestTypeOfSignature(target);
var related = compareTypes(s, t, false) || compareTypes(t, s, reportErrors);
if (!related) {
if (reportErrors) {
errorReporter(ts.Diagnostics.Types_of_parameters_0_and_1_are_incompatible, sourceParams[i < sourceMax ? i : sourceMax].name, targetParams[i < targetMax ? i : targetMax].name);
Expand All @@ -29847,8 +29841,7 @@ var ts;
}
}
else {
result &= checkAsCallback && compareTypes(targetReturnType, sourceReturnType, false) ||
compareTypes(sourceReturnType, targetReturnType, reportErrors);
result &= compareTypes(sourceReturnType, targetReturnType, reportErrors);
}
}
return result;
Expand Down Expand Up @@ -30663,7 +30656,7 @@ var ts;
return result;
}
function signatureRelatedTo(source, target, reportErrors) {
return compareSignaturesRelated(source, target, false, false, reportErrors, reportError, isRelatedTo);
return compareSignaturesRelated(source, target, false, reportErrors, reportError, isRelatedTo);
}
function signaturesIdenticalTo(source, target, kind) {
var sourceSignatures = getSignaturesOfType(source, kind);
Expand Down
33 changes: 7 additions & 26 deletions lib/typescript.js
Original file line number Diff line number Diff line change
Expand Up @@ -32880,13 +32880,12 @@ var ts;
return checkTypeRelatedTo(source, target, comparableRelation, errorNode, headMessage, containingMessageChain);
}
function isSignatureAssignableTo(source, target, ignoreReturnTypes) {
return compareSignaturesRelated(source, target, /*checkAsCallback*/ false, ignoreReturnTypes, /*reportErrors*/ false,
/*errorReporter*/ undefined, compareTypesAssignable) !== 0 /* False */;
return compareSignaturesRelated(source, target, ignoreReturnTypes, /*reportErrors*/ false, /*errorReporter*/ undefined, compareTypesAssignable) !== 0 /* False */;
}
/**
* See signatureRelatedTo, compareSignaturesIdentical
*/
function compareSignaturesRelated(source, target, checkAsCallback, ignoreReturnTypes, reportErrors, errorReporter, compareTypes) {
function compareSignaturesRelated(source, target, ignoreReturnTypes, reportErrors, errorReporter, compareTypes) {
// TODO (drosen): De-duplicate code between related functions.
if (source === target) {
return -1 /* True */;
Expand Down Expand Up @@ -32921,23 +32920,9 @@ var ts;
var sourceParams = source.parameters;
var targetParams = target.parameters;
for (var i = 0; i < checkCount; i++) {
var sourceType = i < sourceMax ? getTypeOfParameter(sourceParams[i]) : getRestTypeOfSignature(source);
var targetType = i < targetMax ? getTypeOfParameter(targetParams[i]) : getRestTypeOfSignature(target);
var sourceSig = getSingleCallSignature(getNonNullableType(sourceType));
var targetSig = getSingleCallSignature(getNonNullableType(targetType));
// In order to ensure that any generic type Foo<T> is at least co-variant with respect to T no matter
// how Foo uses T, we need to relate parameters bi-variantly (given that parameters are input positions,
// they naturally relate only contra-variantly). However, if the source and target parameters both have
// function types with a single call signature, we known we are relating two callback parameters. In
// that case it is sufficient to only relate the parameters of the signatures co-variantly because,
// similar to return values, callback parameters are output positions. This means that a Promise<T>,
// where T is used only in callback parameter positions, will be co-variant (as opposed to bi-variant)
// with respect to T.
var callbacks = sourceSig && targetSig && !sourceSig.typePredicate && !targetSig.typePredicate &&
(getFalsyFlags(sourceType) & 6144 /* Nullable */) === (getFalsyFlags(targetType) & 6144 /* Nullable */);
var related = callbacks ?
compareSignaturesRelated(targetSig, sourceSig, /*checkAsCallback*/ true, /*ignoreReturnTypes*/ false, reportErrors, errorReporter, compareTypes) :
!checkAsCallback && compareTypes(sourceType, targetType, /*reportErrors*/ false) || compareTypes(targetType, sourceType, reportErrors);
var s = i < sourceMax ? getTypeOfParameter(sourceParams[i]) : getRestTypeOfSignature(source);
var t = i < targetMax ? getTypeOfParameter(targetParams[i]) : getRestTypeOfSignature(target);
var related = compareTypes(s, t, /*reportErrors*/ false) || compareTypes(t, s, reportErrors);
if (!related) {
if (reportErrors) {
errorReporter(ts.Diagnostics.Types_of_parameters_0_and_1_are_incompatible, sourceParams[i < sourceMax ? i : sourceMax].name, targetParams[i < targetMax ? i : targetMax].name);
Expand Down Expand Up @@ -32965,11 +32950,7 @@ var ts;
}
}
else {
// When relating callback signatures, we still need to relate return types bi-variantly as otherwise
// the containing type wouldn't be co-variant. For example, interface Foo<T> { add(cb: () => T): void }
// wouldn't be co-variant for T without this rule.
result &= checkAsCallback && compareTypes(targetReturnType, sourceReturnType, /*reportErrors*/ false) ||
compareTypes(sourceReturnType, targetReturnType, reportErrors);
result &= compareTypes(sourceReturnType, targetReturnType, reportErrors);
}
}
return result;
Expand Down Expand Up @@ -33888,7 +33869,7 @@ var ts;
* See signatureAssignableTo, compareSignaturesIdentical
*/
function signatureRelatedTo(source, target, reportErrors) {
return compareSignaturesRelated(source, target, /*checkAsCallback*/ false, /*ignoreReturnTypes*/ false, reportErrors, reportError, isRelatedTo);
return compareSignaturesRelated(source, target, /*ignoreReturnTypes*/ false, reportErrors, reportError, isRelatedTo);
}
function signaturesIdenticalTo(source, target, kind) {
var sourceSignatures = getSignaturesOfType(source, kind);
Expand Down
Loading

0 comments on commit 47e5569

Please sign in to comment.