From dedf5d413b9bcfe69564e59dd3e1f96ee9280c63 Mon Sep 17 00:00:00 2001 From: Mohamed Hegazy Date: Wed, 25 Jul 2018 11:26:10 -0700 Subject: [PATCH] Update LKG --- lib/tsc.js | 97 ++++++++++++++++---------------------- lib/tsserver.js | 98 ++++++++++++++++----------------------- lib/tsserverlibrary.js | 98 ++++++++++++++++----------------------- lib/typescript.js | 98 ++++++++++++++++----------------------- lib/typescriptServices.js | 98 ++++++++++++++++----------------------- lib/typingsInstaller.js | 98 ++++++++++++++++----------------------- 6 files changed, 245 insertions(+), 342 deletions(-) diff --git a/lib/tsc.js b/lib/tsc.js index 33f11a4dcf1..126f5f19bd6 100644 --- a/lib/tsc.js +++ b/lib/tsc.js @@ -23597,7 +23597,7 @@ var ts; })(ts || (ts = {})); var ts; (function (ts) { - function createGetSymbolWalker(getRestTypeOfSignature, getTypePredicateOfSignature, getReturnTypeOfSignature, getBaseTypes, resolveStructuredTypeMembers, getTypeOfSymbol, getResolvedSymbol, getIndexTypeOfStructuredType, getConstraintFromTypeParameter, getFirstIdentifier) { + function createGetSymbolWalker(getRestTypeOfSignature, getTypePredicateOfSignature, getReturnTypeOfSignature, getBaseTypes, resolveStructuredTypeMembers, getTypeOfSymbol, getResolvedSymbol, getIndexTypeOfStructuredType, getConstraintOfTypeParameter, getFirstIdentifier) { return getSymbolWalker; function getSymbolWalker(accept) { if (accept === void 0) { accept = function () { return true; }; } @@ -23670,7 +23670,7 @@ var ts; ts.forEach(type.typeArguments, visitType); } function visitTypeParameter(type) { - visitType(getConstraintFromTypeParameter(type)); + visitType(getConstraintOfTypeParameter(type)); } function visitUnionOrIntersectionType(type) { ts.forEach(type.types, visitType); @@ -23973,7 +23973,7 @@ var ts; getEmitResolver: getEmitResolver, getExportsOfModule: getExportsOfModuleAsArray, getExportsAndPropertiesOfModule: getExportsAndPropertiesOfModule, - getSymbolWalker: ts.createGetSymbolWalker(getRestTypeOfSignature, getTypePredicateOfSignature, getReturnTypeOfSignature, getBaseTypes, resolveStructuredTypeMembers, getTypeOfSymbol, getResolvedSymbol, getIndexTypeOfStructuredType, getConstraintFromTypeParameter, getFirstIdentifier), + getSymbolWalker: ts.createGetSymbolWalker(getRestTypeOfSignature, getTypePredicateOfSignature, getReturnTypeOfSignature, getBaseTypes, resolveStructuredTypeMembers, getTypeOfSymbol, getResolvedSymbol, getIndexTypeOfStructuredType, getConstraintOfTypeParameter, getFirstIdentifier), getAmbientModules: getAmbientModules, getAllAttributesTypeFromJsxOpeningLikeElement: function (nodeIn) { var node = ts.getParseTreeNode(nodeIn, ts.isJsxOpeningLikeElement); @@ -26710,7 +26710,7 @@ var ts; return ts.createTypeParameterDeclaration(name, constraintNode, defaultParameterNode); } function typeParameterToDeclaration(type, context, constraint) { - if (constraint === void 0) { constraint = getConstraintFromTypeParameter(type); } + if (constraint === void 0) { constraint = getConstraintOfTypeParameter(type); } var constraintNode = constraint && typeToTypeNodeHelper(constraint, context); return typeParameterToDeclarationWithConstraint(type, context, constraintNode); } @@ -27225,23 +27225,19 @@ var ts; return -1; } function hasType(target, propertyName) { - if (propertyName === 0) { - return !!getSymbolLinks(target).type; + switch (propertyName) { + case 0: + return !!getSymbolLinks(target).type; + case 2: + return !!getSymbolLinks(target).declaredType; + case 1: + return !!target.resolvedBaseConstructorType; + case 3: + return !!target.resolvedReturnType; + case 4: + return !!target.immediateBaseConstraint; } - if (propertyName === 2) { - return !!getSymbolLinks(target).declaredType; - } - if (propertyName === 1) { - return !!target.resolvedBaseConstructorType; - } - if (propertyName === 3) { - return !!target.resolvedReturnType; - } - if (propertyName === 4) { - var bc = target.immediateBaseConstraint; - return !!bc && bc !== circularConstraintType; - } - return ts.Debug.fail("Unhandled TypeSystemPropertyName " + propertyName); + return ts.Debug.assertNever(propertyName); } function popTypeResolution() { resolutionTargets.pop(); @@ -29299,20 +29295,12 @@ var ts; } return undefined; } - function getBaseConstraintOfInstantiableNonPrimitiveUnionOrIntersection(type) { + function getBaseConstraintOfType(type) { if (type.flags & (14745600 | 786432)) { var constraint = getResolvedBaseConstraint(type); - if (constraint !== noConstraintType && constraint !== circularConstraintType) { - return constraint; - } + return constraint !== noConstraintType && constraint !== circularConstraintType ? constraint : undefined; } - } - function getBaseConstraintOfType(type) { - var constraint = getBaseConstraintOfInstantiableNonPrimitiveUnionOrIntersection(type); - if (!constraint && type.flags & 1048576) { - return keyofConstraintType; - } - return constraint; + return type.flags & 1048576 ? keyofConstraintType : undefined; } function getBaseConstraintOrType(type) { return getBaseConstraintOfType(type) || type; @@ -29321,29 +29309,24 @@ var ts; return getResolvedBaseConstraint(type) !== circularConstraintType; } function getResolvedBaseConstraint(type) { - var circular; - if (!type.resolvedBaseConstraint) { - var constraint = getBaseConstraint(type); - type.resolvedBaseConstraint = circular ? circularConstraintType : getTypeWithThisArgument(constraint || noConstraintType, type); + return type.resolvedBaseConstraint || + (type.resolvedBaseConstraint = getTypeWithThisArgument(getImmediateBaseConstraint(type), type)); + function getImmediateBaseConstraint(t) { + if (!t.immediateBaseConstraint) { + if (!pushTypeResolution(t, 4)) { + return circularConstraintType; + } + var result = computeBaseConstraint(getSimplifiedType(t)); + if (!popTypeResolution()) { + result = circularConstraintType; + } + t.immediateBaseConstraint = result || noConstraintType; + } + return t.immediateBaseConstraint; } - return type.resolvedBaseConstraint; function getBaseConstraint(t) { - if (t.immediateBaseConstraint) { - return t.immediateBaseConstraint === noConstraintType ? undefined : t.immediateBaseConstraint; - } - if (!pushTypeResolution(t, 4)) { - circular = true; - t.immediateBaseConstraint = circularConstraintType; - return undefined; - } - var result = computeBaseConstraint(getSimplifiedType(t)); - if (!popTypeResolution()) { - circular = true; - t.immediateBaseConstraint = circularConstraintType; - return undefined; - } - t.immediateBaseConstraint = !result ? noConstraintType : result; - return result; + var c = getImmediateBaseConstraint(t); + return c !== noConstraintType && c !== circularConstraintType ? c : undefined; } function computeBaseConstraint(t) { if (t.flags & 65536) { @@ -31107,7 +31090,7 @@ var ts; return type.simplified = substituteIndexedMappedType(objectType, type); } if (objectType.flags & 65536) { - var constraint = getConstraintFromTypeParameter(objectType); + var constraint = getConstraintOfTypeParameter(objectType); if (constraint && isGenericMappedType(constraint)) { return type.simplified = substituteIndexedMappedType(constraint, type); } @@ -33569,7 +33552,7 @@ var ts; return false; } function isUnconstrainedTypeParameter(type) { - return type.flags & 65536 && !getConstraintFromTypeParameter(type); + return type.flags & 65536 && !getConstraintOfTypeParameter(type); } function isTypeReferenceWithGenericArguments(type) { return !!(ts.getObjectFlags(type) & 4) && ts.some(type.typeArguments, function (t) { return isUnconstrainedTypeParameter(t) || isTypeReferenceWithGenericArguments(t); }); @@ -37819,7 +37802,7 @@ var ts; return false; } var thisType = getTypeFromTypeNode(thisParameter.type); - enclosingClass = ((thisType.flags & 65536) ? getConstraintFromTypeParameter(thisType) : thisType); + enclosingClass = ((thisType.flags & 65536) ? getConstraintOfTypeParameter(thisType) : thisType); } if (flags & 32) { return true; @@ -38940,7 +38923,7 @@ var ts; typeArguments.pop(); } while (typeArguments.length < typeParameters.length) { - typeArguments.push(getConstraintFromTypeParameter(typeParameters[typeArguments.length]) || getDefaultTypeArgumentType(ts.isInJavaScriptFile(node))); + typeArguments.push(getConstraintOfTypeParameter(typeParameters[typeArguments.length]) || getDefaultTypeArgumentType(ts.isInJavaScriptFile(node))); } var instantiated = createSignatureInstantiation(candidate, typeArguments); candidates[bestIndex] = instantiated; @@ -43382,7 +43365,7 @@ var ts; return false; } var sourceConstraint = source.constraint && getTypeFromTypeNode(source.constraint); - var targetConstraint = getConstraintFromTypeParameter(target); + var targetConstraint = getConstraintOfTypeParameter(target); if (sourceConstraint) { if (!targetConstraint || !isTypeIdenticalTo(sourceConstraint, targetConstraint)) { return false; diff --git a/lib/tsserver.js b/lib/tsserver.js index f038fe37f5d..106825a7e83 100644 --- a/lib/tsserver.js +++ b/lib/tsserver.js @@ -29009,7 +29009,7 @@ var ts; /** @internal */ var ts; (function (ts) { - function createGetSymbolWalker(getRestTypeOfSignature, getTypePredicateOfSignature, getReturnTypeOfSignature, getBaseTypes, resolveStructuredTypeMembers, getTypeOfSymbol, getResolvedSymbol, getIndexTypeOfStructuredType, getConstraintFromTypeParameter, getFirstIdentifier) { + function createGetSymbolWalker(getRestTypeOfSignature, getTypePredicateOfSignature, getReturnTypeOfSignature, getBaseTypes, resolveStructuredTypeMembers, getTypeOfSymbol, getResolvedSymbol, getIndexTypeOfStructuredType, getConstraintOfTypeParameter, getFirstIdentifier) { return getSymbolWalker; function getSymbolWalker(accept) { if (accept === void 0) { accept = function () { return true; }; } @@ -29085,7 +29085,7 @@ var ts; ts.forEach(type.typeArguments, visitType); } function visitTypeParameter(type) { - visitType(getConstraintFromTypeParameter(type)); + visitType(getConstraintOfTypeParameter(type)); } function visitUnionOrIntersectionType(type) { ts.forEach(type.types, visitType); @@ -29411,7 +29411,7 @@ var ts; getEmitResolver: getEmitResolver, getExportsOfModule: getExportsOfModuleAsArray, getExportsAndPropertiesOfModule: getExportsAndPropertiesOfModule, - getSymbolWalker: ts.createGetSymbolWalker(getRestTypeOfSignature, getTypePredicateOfSignature, getReturnTypeOfSignature, getBaseTypes, resolveStructuredTypeMembers, getTypeOfSymbol, getResolvedSymbol, getIndexTypeOfStructuredType, getConstraintFromTypeParameter, getFirstIdentifier), + getSymbolWalker: ts.createGetSymbolWalker(getRestTypeOfSignature, getTypePredicateOfSignature, getReturnTypeOfSignature, getBaseTypes, resolveStructuredTypeMembers, getTypeOfSymbol, getResolvedSymbol, getIndexTypeOfStructuredType, getConstraintOfTypeParameter, getFirstIdentifier), getAmbientModules: getAmbientModules, getAllAttributesTypeFromJsxOpeningLikeElement: function (nodeIn) { var node = ts.getParseTreeNode(nodeIn, ts.isJsxOpeningLikeElement); @@ -32603,7 +32603,7 @@ var ts; return ts.createTypeParameterDeclaration(name, constraintNode, defaultParameterNode); } function typeParameterToDeclaration(type, context, constraint) { - if (constraint === void 0) { constraint = getConstraintFromTypeParameter(type); } + if (constraint === void 0) { constraint = getConstraintOfTypeParameter(type); } var constraintNode = constraint && typeToTypeNodeHelper(constraint, context); return typeParameterToDeclarationWithConstraint(type, context, constraintNode); } @@ -33173,23 +33173,19 @@ var ts; return -1; } function hasType(target, propertyName) { - if (propertyName === 0 /* Type */) { - return !!getSymbolLinks(target).type; + switch (propertyName) { + case 0 /* Type */: + return !!getSymbolLinks(target).type; + case 2 /* DeclaredType */: + return !!getSymbolLinks(target).declaredType; + case 1 /* ResolvedBaseConstructorType */: + return !!target.resolvedBaseConstructorType; + case 3 /* ResolvedReturnType */: + return !!target.resolvedReturnType; + case 4 /* ImmediateBaseConstraint */: + return !!target.immediateBaseConstraint; } - if (propertyName === 2 /* DeclaredType */) { - return !!getSymbolLinks(target).declaredType; - } - if (propertyName === 1 /* ResolvedBaseConstructorType */) { - return !!target.resolvedBaseConstructorType; - } - if (propertyName === 3 /* ResolvedReturnType */) { - return !!target.resolvedReturnType; - } - if (propertyName === 4 /* ImmediateBaseConstraint */) { - var bc = target.immediateBaseConstraint; - return !!bc && bc !== circularConstraintType; - } - return ts.Debug.fail("Unhandled TypeSystemPropertyName " + propertyName); + return ts.Debug.assertNever(propertyName); } // Pop an entry from the type resolution stack and return its associated result value. The result value will // be true if no circularities were detected, or false if a circularity was found. @@ -35580,20 +35576,12 @@ var ts; } return undefined; } - function getBaseConstraintOfInstantiableNonPrimitiveUnionOrIntersection(type) { + function getBaseConstraintOfType(type) { if (type.flags & (14745600 /* InstantiableNonPrimitive */ | 786432 /* UnionOrIntersection */)) { var constraint = getResolvedBaseConstraint(type); - if (constraint !== noConstraintType && constraint !== circularConstraintType) { - return constraint; - } + return constraint !== noConstraintType && constraint !== circularConstraintType ? constraint : undefined; } - } - function getBaseConstraintOfType(type) { - var constraint = getBaseConstraintOfInstantiableNonPrimitiveUnionOrIntersection(type); - if (!constraint && type.flags & 1048576 /* Index */) { - return keyofConstraintType; - } - return constraint; + return type.flags & 1048576 /* Index */ ? keyofConstraintType : undefined; } /** * This is similar to `getBaseConstraintOfType` except it returns the input type if there's no base constraint, instead of `undefined` @@ -35611,29 +35599,24 @@ var ts; * circularly references the type variable. */ function getResolvedBaseConstraint(type) { - var circular; - if (!type.resolvedBaseConstraint) { - var constraint = getBaseConstraint(type); - type.resolvedBaseConstraint = circular ? circularConstraintType : getTypeWithThisArgument(constraint || noConstraintType, type); + return type.resolvedBaseConstraint || + (type.resolvedBaseConstraint = getTypeWithThisArgument(getImmediateBaseConstraint(type), type)); + function getImmediateBaseConstraint(t) { + if (!t.immediateBaseConstraint) { + if (!pushTypeResolution(t, 4 /* ImmediateBaseConstraint */)) { + return circularConstraintType; + } + var result = computeBaseConstraint(getSimplifiedType(t)); + if (!popTypeResolution()) { + result = circularConstraintType; + } + t.immediateBaseConstraint = result || noConstraintType; + } + return t.immediateBaseConstraint; } - return type.resolvedBaseConstraint; function getBaseConstraint(t) { - if (t.immediateBaseConstraint) { - return t.immediateBaseConstraint === noConstraintType ? undefined : t.immediateBaseConstraint; - } - if (!pushTypeResolution(t, 4 /* ImmediateBaseConstraint */)) { - circular = true; - t.immediateBaseConstraint = circularConstraintType; - return undefined; - } - var result = computeBaseConstraint(getSimplifiedType(t)); - if (!popTypeResolution()) { - circular = true; - t.immediateBaseConstraint = circularConstraintType; - return undefined; - } - t.immediateBaseConstraint = !result ? noConstraintType : result; - return result; + var c = getImmediateBaseConstraint(t); + return c !== noConstraintType && c !== circularConstraintType ? c : undefined; } function computeBaseConstraint(t) { if (t.flags & 65536 /* TypeParameter */) { @@ -36437,6 +36420,7 @@ var ts; } return inferences && getIntersectionType(inferences); } + /** This is a worker function. Use getConstraintOfTypeParameter which guards against circular constraints. */ function getConstraintFromTypeParameter(typeParameter) { if (!typeParameter.constraint) { if (typeParameter.target) { @@ -37604,7 +37588,7 @@ var ts; return type.simplified = substituteIndexedMappedType(objectType, type); } if (objectType.flags & 65536 /* TypeParameter */) { - var constraint = getConstraintFromTypeParameter(objectType); + var constraint = getConstraintOfTypeParameter(objectType); if (constraint && isGenericMappedType(constraint)) { return type.simplified = substituteIndexedMappedType(constraint, type); } @@ -40408,7 +40392,7 @@ var ts; return false; } function isUnconstrainedTypeParameter(type) { - return type.flags & 65536 /* TypeParameter */ && !getConstraintFromTypeParameter(type); + return type.flags & 65536 /* TypeParameter */ && !getConstraintOfTypeParameter(type); } function isTypeReferenceWithGenericArguments(type) { return !!(ts.getObjectFlags(type) & 4 /* Reference */) && ts.some(type.typeArguments, function (t) { return isUnconstrainedTypeParameter(t) || isTypeReferenceWithGenericArguments(t); }); @@ -45507,7 +45491,7 @@ var ts; return false; } var thisType = getTypeFromTypeNode(thisParameter.type); - enclosingClass = ((thisType.flags & 65536 /* TypeParameter */) ? getConstraintFromTypeParameter(thisType) : thisType); + enclosingClass = ((thisType.flags & 65536 /* TypeParameter */) ? getConstraintOfTypeParameter(thisType) : thisType); } // No further restrictions for static properties if (flags & 32 /* Static */) { @@ -46974,7 +46958,7 @@ var ts; typeArguments.pop(); } while (typeArguments.length < typeParameters.length) { - typeArguments.push(getConstraintFromTypeParameter(typeParameters[typeArguments.length]) || getDefaultTypeArgumentType(ts.isInJavaScriptFile(node))); + typeArguments.push(getConstraintOfTypeParameter(typeParameters[typeArguments.length]) || getDefaultTypeArgumentType(ts.isInJavaScriptFile(node))); } var instantiated = createSignatureInstantiation(candidate, typeArguments); candidates[bestIndex] = instantiated; @@ -52268,7 +52252,7 @@ var ts; // If the type parameter node does not have an identical constraint as the resolved // type parameter at this position, we report an error. var sourceConstraint = source.constraint && getTypeFromTypeNode(source.constraint); - var targetConstraint = getConstraintFromTypeParameter(target); + var targetConstraint = getConstraintOfTypeParameter(target); if (sourceConstraint) { // relax check if later interface augmentation has no constraint if (!targetConstraint || !isTypeIdenticalTo(sourceConstraint, targetConstraint)) { diff --git a/lib/tsserverlibrary.js b/lib/tsserverlibrary.js index 54449c3d14d..9baa1bf240f 100644 --- a/lib/tsserverlibrary.js +++ b/lib/tsserverlibrary.js @@ -28996,7 +28996,7 @@ var ts; /** @internal */ var ts; (function (ts) { - function createGetSymbolWalker(getRestTypeOfSignature, getTypePredicateOfSignature, getReturnTypeOfSignature, getBaseTypes, resolveStructuredTypeMembers, getTypeOfSymbol, getResolvedSymbol, getIndexTypeOfStructuredType, getConstraintFromTypeParameter, getFirstIdentifier) { + function createGetSymbolWalker(getRestTypeOfSignature, getTypePredicateOfSignature, getReturnTypeOfSignature, getBaseTypes, resolveStructuredTypeMembers, getTypeOfSymbol, getResolvedSymbol, getIndexTypeOfStructuredType, getConstraintOfTypeParameter, getFirstIdentifier) { return getSymbolWalker; function getSymbolWalker(accept) { if (accept === void 0) { accept = function () { return true; }; } @@ -29072,7 +29072,7 @@ var ts; ts.forEach(type.typeArguments, visitType); } function visitTypeParameter(type) { - visitType(getConstraintFromTypeParameter(type)); + visitType(getConstraintOfTypeParameter(type)); } function visitUnionOrIntersectionType(type) { ts.forEach(type.types, visitType); @@ -29398,7 +29398,7 @@ var ts; getEmitResolver: getEmitResolver, getExportsOfModule: getExportsOfModuleAsArray, getExportsAndPropertiesOfModule: getExportsAndPropertiesOfModule, - getSymbolWalker: ts.createGetSymbolWalker(getRestTypeOfSignature, getTypePredicateOfSignature, getReturnTypeOfSignature, getBaseTypes, resolveStructuredTypeMembers, getTypeOfSymbol, getResolvedSymbol, getIndexTypeOfStructuredType, getConstraintFromTypeParameter, getFirstIdentifier), + getSymbolWalker: ts.createGetSymbolWalker(getRestTypeOfSignature, getTypePredicateOfSignature, getReturnTypeOfSignature, getBaseTypes, resolveStructuredTypeMembers, getTypeOfSymbol, getResolvedSymbol, getIndexTypeOfStructuredType, getConstraintOfTypeParameter, getFirstIdentifier), getAmbientModules: getAmbientModules, getAllAttributesTypeFromJsxOpeningLikeElement: function (nodeIn) { var node = ts.getParseTreeNode(nodeIn, ts.isJsxOpeningLikeElement); @@ -32590,7 +32590,7 @@ var ts; return ts.createTypeParameterDeclaration(name, constraintNode, defaultParameterNode); } function typeParameterToDeclaration(type, context, constraint) { - if (constraint === void 0) { constraint = getConstraintFromTypeParameter(type); } + if (constraint === void 0) { constraint = getConstraintOfTypeParameter(type); } var constraintNode = constraint && typeToTypeNodeHelper(constraint, context); return typeParameterToDeclarationWithConstraint(type, context, constraintNode); } @@ -33160,23 +33160,19 @@ var ts; return -1; } function hasType(target, propertyName) { - if (propertyName === 0 /* Type */) { - return !!getSymbolLinks(target).type; + switch (propertyName) { + case 0 /* Type */: + return !!getSymbolLinks(target).type; + case 2 /* DeclaredType */: + return !!getSymbolLinks(target).declaredType; + case 1 /* ResolvedBaseConstructorType */: + return !!target.resolvedBaseConstructorType; + case 3 /* ResolvedReturnType */: + return !!target.resolvedReturnType; + case 4 /* ImmediateBaseConstraint */: + return !!target.immediateBaseConstraint; } - if (propertyName === 2 /* DeclaredType */) { - return !!getSymbolLinks(target).declaredType; - } - if (propertyName === 1 /* ResolvedBaseConstructorType */) { - return !!target.resolvedBaseConstructorType; - } - if (propertyName === 3 /* ResolvedReturnType */) { - return !!target.resolvedReturnType; - } - if (propertyName === 4 /* ImmediateBaseConstraint */) { - var bc = target.immediateBaseConstraint; - return !!bc && bc !== circularConstraintType; - } - return ts.Debug.fail("Unhandled TypeSystemPropertyName " + propertyName); + return ts.Debug.assertNever(propertyName); } // Pop an entry from the type resolution stack and return its associated result value. The result value will // be true if no circularities were detected, or false if a circularity was found. @@ -35567,20 +35563,12 @@ var ts; } return undefined; } - function getBaseConstraintOfInstantiableNonPrimitiveUnionOrIntersection(type) { + function getBaseConstraintOfType(type) { if (type.flags & (14745600 /* InstantiableNonPrimitive */ | 786432 /* UnionOrIntersection */)) { var constraint = getResolvedBaseConstraint(type); - if (constraint !== noConstraintType && constraint !== circularConstraintType) { - return constraint; - } + return constraint !== noConstraintType && constraint !== circularConstraintType ? constraint : undefined; } - } - function getBaseConstraintOfType(type) { - var constraint = getBaseConstraintOfInstantiableNonPrimitiveUnionOrIntersection(type); - if (!constraint && type.flags & 1048576 /* Index */) { - return keyofConstraintType; - } - return constraint; + return type.flags & 1048576 /* Index */ ? keyofConstraintType : undefined; } /** * This is similar to `getBaseConstraintOfType` except it returns the input type if there's no base constraint, instead of `undefined` @@ -35598,29 +35586,24 @@ var ts; * circularly references the type variable. */ function getResolvedBaseConstraint(type) { - var circular; - if (!type.resolvedBaseConstraint) { - var constraint = getBaseConstraint(type); - type.resolvedBaseConstraint = circular ? circularConstraintType : getTypeWithThisArgument(constraint || noConstraintType, type); + return type.resolvedBaseConstraint || + (type.resolvedBaseConstraint = getTypeWithThisArgument(getImmediateBaseConstraint(type), type)); + function getImmediateBaseConstraint(t) { + if (!t.immediateBaseConstraint) { + if (!pushTypeResolution(t, 4 /* ImmediateBaseConstraint */)) { + return circularConstraintType; + } + var result = computeBaseConstraint(getSimplifiedType(t)); + if (!popTypeResolution()) { + result = circularConstraintType; + } + t.immediateBaseConstraint = result || noConstraintType; + } + return t.immediateBaseConstraint; } - return type.resolvedBaseConstraint; function getBaseConstraint(t) { - if (t.immediateBaseConstraint) { - return t.immediateBaseConstraint === noConstraintType ? undefined : t.immediateBaseConstraint; - } - if (!pushTypeResolution(t, 4 /* ImmediateBaseConstraint */)) { - circular = true; - t.immediateBaseConstraint = circularConstraintType; - return undefined; - } - var result = computeBaseConstraint(getSimplifiedType(t)); - if (!popTypeResolution()) { - circular = true; - t.immediateBaseConstraint = circularConstraintType; - return undefined; - } - t.immediateBaseConstraint = !result ? noConstraintType : result; - return result; + var c = getImmediateBaseConstraint(t); + return c !== noConstraintType && c !== circularConstraintType ? c : undefined; } function computeBaseConstraint(t) { if (t.flags & 65536 /* TypeParameter */) { @@ -36424,6 +36407,7 @@ var ts; } return inferences && getIntersectionType(inferences); } + /** This is a worker function. Use getConstraintOfTypeParameter which guards against circular constraints. */ function getConstraintFromTypeParameter(typeParameter) { if (!typeParameter.constraint) { if (typeParameter.target) { @@ -37591,7 +37575,7 @@ var ts; return type.simplified = substituteIndexedMappedType(objectType, type); } if (objectType.flags & 65536 /* TypeParameter */) { - var constraint = getConstraintFromTypeParameter(objectType); + var constraint = getConstraintOfTypeParameter(objectType); if (constraint && isGenericMappedType(constraint)) { return type.simplified = substituteIndexedMappedType(constraint, type); } @@ -40395,7 +40379,7 @@ var ts; return false; } function isUnconstrainedTypeParameter(type) { - return type.flags & 65536 /* TypeParameter */ && !getConstraintFromTypeParameter(type); + return type.flags & 65536 /* TypeParameter */ && !getConstraintOfTypeParameter(type); } function isTypeReferenceWithGenericArguments(type) { return !!(ts.getObjectFlags(type) & 4 /* Reference */) && ts.some(type.typeArguments, function (t) { return isUnconstrainedTypeParameter(t) || isTypeReferenceWithGenericArguments(t); }); @@ -45494,7 +45478,7 @@ var ts; return false; } var thisType = getTypeFromTypeNode(thisParameter.type); - enclosingClass = ((thisType.flags & 65536 /* TypeParameter */) ? getConstraintFromTypeParameter(thisType) : thisType); + enclosingClass = ((thisType.flags & 65536 /* TypeParameter */) ? getConstraintOfTypeParameter(thisType) : thisType); } // No further restrictions for static properties if (flags & 32 /* Static */) { @@ -46961,7 +46945,7 @@ var ts; typeArguments.pop(); } while (typeArguments.length < typeParameters.length) { - typeArguments.push(getConstraintFromTypeParameter(typeParameters[typeArguments.length]) || getDefaultTypeArgumentType(ts.isInJavaScriptFile(node))); + typeArguments.push(getConstraintOfTypeParameter(typeParameters[typeArguments.length]) || getDefaultTypeArgumentType(ts.isInJavaScriptFile(node))); } var instantiated = createSignatureInstantiation(candidate, typeArguments); candidates[bestIndex] = instantiated; @@ -52255,7 +52239,7 @@ var ts; // If the type parameter node does not have an identical constraint as the resolved // type parameter at this position, we report an error. var sourceConstraint = source.constraint && getTypeFromTypeNode(source.constraint); - var targetConstraint = getConstraintFromTypeParameter(target); + var targetConstraint = getConstraintOfTypeParameter(target); if (sourceConstraint) { // relax check if later interface augmentation has no constraint if (!targetConstraint || !isTypeIdenticalTo(sourceConstraint, targetConstraint)) { diff --git a/lib/typescript.js b/lib/typescript.js index 8a691e273c9..b03617a8bf4 100644 --- a/lib/typescript.js +++ b/lib/typescript.js @@ -28996,7 +28996,7 @@ var ts; /** @internal */ var ts; (function (ts) { - function createGetSymbolWalker(getRestTypeOfSignature, getTypePredicateOfSignature, getReturnTypeOfSignature, getBaseTypes, resolveStructuredTypeMembers, getTypeOfSymbol, getResolvedSymbol, getIndexTypeOfStructuredType, getConstraintFromTypeParameter, getFirstIdentifier) { + function createGetSymbolWalker(getRestTypeOfSignature, getTypePredicateOfSignature, getReturnTypeOfSignature, getBaseTypes, resolveStructuredTypeMembers, getTypeOfSymbol, getResolvedSymbol, getIndexTypeOfStructuredType, getConstraintOfTypeParameter, getFirstIdentifier) { return getSymbolWalker; function getSymbolWalker(accept) { if (accept === void 0) { accept = function () { return true; }; } @@ -29072,7 +29072,7 @@ var ts; ts.forEach(type.typeArguments, visitType); } function visitTypeParameter(type) { - visitType(getConstraintFromTypeParameter(type)); + visitType(getConstraintOfTypeParameter(type)); } function visitUnionOrIntersectionType(type) { ts.forEach(type.types, visitType); @@ -29398,7 +29398,7 @@ var ts; getEmitResolver: getEmitResolver, getExportsOfModule: getExportsOfModuleAsArray, getExportsAndPropertiesOfModule: getExportsAndPropertiesOfModule, - getSymbolWalker: ts.createGetSymbolWalker(getRestTypeOfSignature, getTypePredicateOfSignature, getReturnTypeOfSignature, getBaseTypes, resolveStructuredTypeMembers, getTypeOfSymbol, getResolvedSymbol, getIndexTypeOfStructuredType, getConstraintFromTypeParameter, getFirstIdentifier), + getSymbolWalker: ts.createGetSymbolWalker(getRestTypeOfSignature, getTypePredicateOfSignature, getReturnTypeOfSignature, getBaseTypes, resolveStructuredTypeMembers, getTypeOfSymbol, getResolvedSymbol, getIndexTypeOfStructuredType, getConstraintOfTypeParameter, getFirstIdentifier), getAmbientModules: getAmbientModules, getAllAttributesTypeFromJsxOpeningLikeElement: function (nodeIn) { var node = ts.getParseTreeNode(nodeIn, ts.isJsxOpeningLikeElement); @@ -32590,7 +32590,7 @@ var ts; return ts.createTypeParameterDeclaration(name, constraintNode, defaultParameterNode); } function typeParameterToDeclaration(type, context, constraint) { - if (constraint === void 0) { constraint = getConstraintFromTypeParameter(type); } + if (constraint === void 0) { constraint = getConstraintOfTypeParameter(type); } var constraintNode = constraint && typeToTypeNodeHelper(constraint, context); return typeParameterToDeclarationWithConstraint(type, context, constraintNode); } @@ -33160,23 +33160,19 @@ var ts; return -1; } function hasType(target, propertyName) { - if (propertyName === 0 /* Type */) { - return !!getSymbolLinks(target).type; + switch (propertyName) { + case 0 /* Type */: + return !!getSymbolLinks(target).type; + case 2 /* DeclaredType */: + return !!getSymbolLinks(target).declaredType; + case 1 /* ResolvedBaseConstructorType */: + return !!target.resolvedBaseConstructorType; + case 3 /* ResolvedReturnType */: + return !!target.resolvedReturnType; + case 4 /* ImmediateBaseConstraint */: + return !!target.immediateBaseConstraint; } - if (propertyName === 2 /* DeclaredType */) { - return !!getSymbolLinks(target).declaredType; - } - if (propertyName === 1 /* ResolvedBaseConstructorType */) { - return !!target.resolvedBaseConstructorType; - } - if (propertyName === 3 /* ResolvedReturnType */) { - return !!target.resolvedReturnType; - } - if (propertyName === 4 /* ImmediateBaseConstraint */) { - var bc = target.immediateBaseConstraint; - return !!bc && bc !== circularConstraintType; - } - return ts.Debug.fail("Unhandled TypeSystemPropertyName " + propertyName); + return ts.Debug.assertNever(propertyName); } // Pop an entry from the type resolution stack and return its associated result value. The result value will // be true if no circularities were detected, or false if a circularity was found. @@ -35567,20 +35563,12 @@ var ts; } return undefined; } - function getBaseConstraintOfInstantiableNonPrimitiveUnionOrIntersection(type) { + function getBaseConstraintOfType(type) { if (type.flags & (14745600 /* InstantiableNonPrimitive */ | 786432 /* UnionOrIntersection */)) { var constraint = getResolvedBaseConstraint(type); - if (constraint !== noConstraintType && constraint !== circularConstraintType) { - return constraint; - } + return constraint !== noConstraintType && constraint !== circularConstraintType ? constraint : undefined; } - } - function getBaseConstraintOfType(type) { - var constraint = getBaseConstraintOfInstantiableNonPrimitiveUnionOrIntersection(type); - if (!constraint && type.flags & 1048576 /* Index */) { - return keyofConstraintType; - } - return constraint; + return type.flags & 1048576 /* Index */ ? keyofConstraintType : undefined; } /** * This is similar to `getBaseConstraintOfType` except it returns the input type if there's no base constraint, instead of `undefined` @@ -35598,29 +35586,24 @@ var ts; * circularly references the type variable. */ function getResolvedBaseConstraint(type) { - var circular; - if (!type.resolvedBaseConstraint) { - var constraint = getBaseConstraint(type); - type.resolvedBaseConstraint = circular ? circularConstraintType : getTypeWithThisArgument(constraint || noConstraintType, type); + return type.resolvedBaseConstraint || + (type.resolvedBaseConstraint = getTypeWithThisArgument(getImmediateBaseConstraint(type), type)); + function getImmediateBaseConstraint(t) { + if (!t.immediateBaseConstraint) { + if (!pushTypeResolution(t, 4 /* ImmediateBaseConstraint */)) { + return circularConstraintType; + } + var result = computeBaseConstraint(getSimplifiedType(t)); + if (!popTypeResolution()) { + result = circularConstraintType; + } + t.immediateBaseConstraint = result || noConstraintType; + } + return t.immediateBaseConstraint; } - return type.resolvedBaseConstraint; function getBaseConstraint(t) { - if (t.immediateBaseConstraint) { - return t.immediateBaseConstraint === noConstraintType ? undefined : t.immediateBaseConstraint; - } - if (!pushTypeResolution(t, 4 /* ImmediateBaseConstraint */)) { - circular = true; - t.immediateBaseConstraint = circularConstraintType; - return undefined; - } - var result = computeBaseConstraint(getSimplifiedType(t)); - if (!popTypeResolution()) { - circular = true; - t.immediateBaseConstraint = circularConstraintType; - return undefined; - } - t.immediateBaseConstraint = !result ? noConstraintType : result; - return result; + var c = getImmediateBaseConstraint(t); + return c !== noConstraintType && c !== circularConstraintType ? c : undefined; } function computeBaseConstraint(t) { if (t.flags & 65536 /* TypeParameter */) { @@ -36424,6 +36407,7 @@ var ts; } return inferences && getIntersectionType(inferences); } + /** This is a worker function. Use getConstraintOfTypeParameter which guards against circular constraints. */ function getConstraintFromTypeParameter(typeParameter) { if (!typeParameter.constraint) { if (typeParameter.target) { @@ -37591,7 +37575,7 @@ var ts; return type.simplified = substituteIndexedMappedType(objectType, type); } if (objectType.flags & 65536 /* TypeParameter */) { - var constraint = getConstraintFromTypeParameter(objectType); + var constraint = getConstraintOfTypeParameter(objectType); if (constraint && isGenericMappedType(constraint)) { return type.simplified = substituteIndexedMappedType(constraint, type); } @@ -40395,7 +40379,7 @@ var ts; return false; } function isUnconstrainedTypeParameter(type) { - return type.flags & 65536 /* TypeParameter */ && !getConstraintFromTypeParameter(type); + return type.flags & 65536 /* TypeParameter */ && !getConstraintOfTypeParameter(type); } function isTypeReferenceWithGenericArguments(type) { return !!(ts.getObjectFlags(type) & 4 /* Reference */) && ts.some(type.typeArguments, function (t) { return isUnconstrainedTypeParameter(t) || isTypeReferenceWithGenericArguments(t); }); @@ -45494,7 +45478,7 @@ var ts; return false; } var thisType = getTypeFromTypeNode(thisParameter.type); - enclosingClass = ((thisType.flags & 65536 /* TypeParameter */) ? getConstraintFromTypeParameter(thisType) : thisType); + enclosingClass = ((thisType.flags & 65536 /* TypeParameter */) ? getConstraintOfTypeParameter(thisType) : thisType); } // No further restrictions for static properties if (flags & 32 /* Static */) { @@ -46961,7 +46945,7 @@ var ts; typeArguments.pop(); } while (typeArguments.length < typeParameters.length) { - typeArguments.push(getConstraintFromTypeParameter(typeParameters[typeArguments.length]) || getDefaultTypeArgumentType(ts.isInJavaScriptFile(node))); + typeArguments.push(getConstraintOfTypeParameter(typeParameters[typeArguments.length]) || getDefaultTypeArgumentType(ts.isInJavaScriptFile(node))); } var instantiated = createSignatureInstantiation(candidate, typeArguments); candidates[bestIndex] = instantiated; @@ -52255,7 +52239,7 @@ var ts; // If the type parameter node does not have an identical constraint as the resolved // type parameter at this position, we report an error. var sourceConstraint = source.constraint && getTypeFromTypeNode(source.constraint); - var targetConstraint = getConstraintFromTypeParameter(target); + var targetConstraint = getConstraintOfTypeParameter(target); if (sourceConstraint) { // relax check if later interface augmentation has no constraint if (!targetConstraint || !isTypeIdenticalTo(sourceConstraint, targetConstraint)) { diff --git a/lib/typescriptServices.js b/lib/typescriptServices.js index 8a691e273c9..b03617a8bf4 100644 --- a/lib/typescriptServices.js +++ b/lib/typescriptServices.js @@ -28996,7 +28996,7 @@ var ts; /** @internal */ var ts; (function (ts) { - function createGetSymbolWalker(getRestTypeOfSignature, getTypePredicateOfSignature, getReturnTypeOfSignature, getBaseTypes, resolveStructuredTypeMembers, getTypeOfSymbol, getResolvedSymbol, getIndexTypeOfStructuredType, getConstraintFromTypeParameter, getFirstIdentifier) { + function createGetSymbolWalker(getRestTypeOfSignature, getTypePredicateOfSignature, getReturnTypeOfSignature, getBaseTypes, resolveStructuredTypeMembers, getTypeOfSymbol, getResolvedSymbol, getIndexTypeOfStructuredType, getConstraintOfTypeParameter, getFirstIdentifier) { return getSymbolWalker; function getSymbolWalker(accept) { if (accept === void 0) { accept = function () { return true; }; } @@ -29072,7 +29072,7 @@ var ts; ts.forEach(type.typeArguments, visitType); } function visitTypeParameter(type) { - visitType(getConstraintFromTypeParameter(type)); + visitType(getConstraintOfTypeParameter(type)); } function visitUnionOrIntersectionType(type) { ts.forEach(type.types, visitType); @@ -29398,7 +29398,7 @@ var ts; getEmitResolver: getEmitResolver, getExportsOfModule: getExportsOfModuleAsArray, getExportsAndPropertiesOfModule: getExportsAndPropertiesOfModule, - getSymbolWalker: ts.createGetSymbolWalker(getRestTypeOfSignature, getTypePredicateOfSignature, getReturnTypeOfSignature, getBaseTypes, resolveStructuredTypeMembers, getTypeOfSymbol, getResolvedSymbol, getIndexTypeOfStructuredType, getConstraintFromTypeParameter, getFirstIdentifier), + getSymbolWalker: ts.createGetSymbolWalker(getRestTypeOfSignature, getTypePredicateOfSignature, getReturnTypeOfSignature, getBaseTypes, resolveStructuredTypeMembers, getTypeOfSymbol, getResolvedSymbol, getIndexTypeOfStructuredType, getConstraintOfTypeParameter, getFirstIdentifier), getAmbientModules: getAmbientModules, getAllAttributesTypeFromJsxOpeningLikeElement: function (nodeIn) { var node = ts.getParseTreeNode(nodeIn, ts.isJsxOpeningLikeElement); @@ -32590,7 +32590,7 @@ var ts; return ts.createTypeParameterDeclaration(name, constraintNode, defaultParameterNode); } function typeParameterToDeclaration(type, context, constraint) { - if (constraint === void 0) { constraint = getConstraintFromTypeParameter(type); } + if (constraint === void 0) { constraint = getConstraintOfTypeParameter(type); } var constraintNode = constraint && typeToTypeNodeHelper(constraint, context); return typeParameterToDeclarationWithConstraint(type, context, constraintNode); } @@ -33160,23 +33160,19 @@ var ts; return -1; } function hasType(target, propertyName) { - if (propertyName === 0 /* Type */) { - return !!getSymbolLinks(target).type; + switch (propertyName) { + case 0 /* Type */: + return !!getSymbolLinks(target).type; + case 2 /* DeclaredType */: + return !!getSymbolLinks(target).declaredType; + case 1 /* ResolvedBaseConstructorType */: + return !!target.resolvedBaseConstructorType; + case 3 /* ResolvedReturnType */: + return !!target.resolvedReturnType; + case 4 /* ImmediateBaseConstraint */: + return !!target.immediateBaseConstraint; } - if (propertyName === 2 /* DeclaredType */) { - return !!getSymbolLinks(target).declaredType; - } - if (propertyName === 1 /* ResolvedBaseConstructorType */) { - return !!target.resolvedBaseConstructorType; - } - if (propertyName === 3 /* ResolvedReturnType */) { - return !!target.resolvedReturnType; - } - if (propertyName === 4 /* ImmediateBaseConstraint */) { - var bc = target.immediateBaseConstraint; - return !!bc && bc !== circularConstraintType; - } - return ts.Debug.fail("Unhandled TypeSystemPropertyName " + propertyName); + return ts.Debug.assertNever(propertyName); } // Pop an entry from the type resolution stack and return its associated result value. The result value will // be true if no circularities were detected, or false if a circularity was found. @@ -35567,20 +35563,12 @@ var ts; } return undefined; } - function getBaseConstraintOfInstantiableNonPrimitiveUnionOrIntersection(type) { + function getBaseConstraintOfType(type) { if (type.flags & (14745600 /* InstantiableNonPrimitive */ | 786432 /* UnionOrIntersection */)) { var constraint = getResolvedBaseConstraint(type); - if (constraint !== noConstraintType && constraint !== circularConstraintType) { - return constraint; - } + return constraint !== noConstraintType && constraint !== circularConstraintType ? constraint : undefined; } - } - function getBaseConstraintOfType(type) { - var constraint = getBaseConstraintOfInstantiableNonPrimitiveUnionOrIntersection(type); - if (!constraint && type.flags & 1048576 /* Index */) { - return keyofConstraintType; - } - return constraint; + return type.flags & 1048576 /* Index */ ? keyofConstraintType : undefined; } /** * This is similar to `getBaseConstraintOfType` except it returns the input type if there's no base constraint, instead of `undefined` @@ -35598,29 +35586,24 @@ var ts; * circularly references the type variable. */ function getResolvedBaseConstraint(type) { - var circular; - if (!type.resolvedBaseConstraint) { - var constraint = getBaseConstraint(type); - type.resolvedBaseConstraint = circular ? circularConstraintType : getTypeWithThisArgument(constraint || noConstraintType, type); + return type.resolvedBaseConstraint || + (type.resolvedBaseConstraint = getTypeWithThisArgument(getImmediateBaseConstraint(type), type)); + function getImmediateBaseConstraint(t) { + if (!t.immediateBaseConstraint) { + if (!pushTypeResolution(t, 4 /* ImmediateBaseConstraint */)) { + return circularConstraintType; + } + var result = computeBaseConstraint(getSimplifiedType(t)); + if (!popTypeResolution()) { + result = circularConstraintType; + } + t.immediateBaseConstraint = result || noConstraintType; + } + return t.immediateBaseConstraint; } - return type.resolvedBaseConstraint; function getBaseConstraint(t) { - if (t.immediateBaseConstraint) { - return t.immediateBaseConstraint === noConstraintType ? undefined : t.immediateBaseConstraint; - } - if (!pushTypeResolution(t, 4 /* ImmediateBaseConstraint */)) { - circular = true; - t.immediateBaseConstraint = circularConstraintType; - return undefined; - } - var result = computeBaseConstraint(getSimplifiedType(t)); - if (!popTypeResolution()) { - circular = true; - t.immediateBaseConstraint = circularConstraintType; - return undefined; - } - t.immediateBaseConstraint = !result ? noConstraintType : result; - return result; + var c = getImmediateBaseConstraint(t); + return c !== noConstraintType && c !== circularConstraintType ? c : undefined; } function computeBaseConstraint(t) { if (t.flags & 65536 /* TypeParameter */) { @@ -36424,6 +36407,7 @@ var ts; } return inferences && getIntersectionType(inferences); } + /** This is a worker function. Use getConstraintOfTypeParameter which guards against circular constraints. */ function getConstraintFromTypeParameter(typeParameter) { if (!typeParameter.constraint) { if (typeParameter.target) { @@ -37591,7 +37575,7 @@ var ts; return type.simplified = substituteIndexedMappedType(objectType, type); } if (objectType.flags & 65536 /* TypeParameter */) { - var constraint = getConstraintFromTypeParameter(objectType); + var constraint = getConstraintOfTypeParameter(objectType); if (constraint && isGenericMappedType(constraint)) { return type.simplified = substituteIndexedMappedType(constraint, type); } @@ -40395,7 +40379,7 @@ var ts; return false; } function isUnconstrainedTypeParameter(type) { - return type.flags & 65536 /* TypeParameter */ && !getConstraintFromTypeParameter(type); + return type.flags & 65536 /* TypeParameter */ && !getConstraintOfTypeParameter(type); } function isTypeReferenceWithGenericArguments(type) { return !!(ts.getObjectFlags(type) & 4 /* Reference */) && ts.some(type.typeArguments, function (t) { return isUnconstrainedTypeParameter(t) || isTypeReferenceWithGenericArguments(t); }); @@ -45494,7 +45478,7 @@ var ts; return false; } var thisType = getTypeFromTypeNode(thisParameter.type); - enclosingClass = ((thisType.flags & 65536 /* TypeParameter */) ? getConstraintFromTypeParameter(thisType) : thisType); + enclosingClass = ((thisType.flags & 65536 /* TypeParameter */) ? getConstraintOfTypeParameter(thisType) : thisType); } // No further restrictions for static properties if (flags & 32 /* Static */) { @@ -46961,7 +46945,7 @@ var ts; typeArguments.pop(); } while (typeArguments.length < typeParameters.length) { - typeArguments.push(getConstraintFromTypeParameter(typeParameters[typeArguments.length]) || getDefaultTypeArgumentType(ts.isInJavaScriptFile(node))); + typeArguments.push(getConstraintOfTypeParameter(typeParameters[typeArguments.length]) || getDefaultTypeArgumentType(ts.isInJavaScriptFile(node))); } var instantiated = createSignatureInstantiation(candidate, typeArguments); candidates[bestIndex] = instantiated; @@ -52255,7 +52239,7 @@ var ts; // If the type parameter node does not have an identical constraint as the resolved // type parameter at this position, we report an error. var sourceConstraint = source.constraint && getTypeFromTypeNode(source.constraint); - var targetConstraint = getConstraintFromTypeParameter(target); + var targetConstraint = getConstraintOfTypeParameter(target); if (sourceConstraint) { // relax check if later interface augmentation has no constraint if (!targetConstraint || !isTypeIdenticalTo(sourceConstraint, targetConstraint)) { diff --git a/lib/typingsInstaller.js b/lib/typingsInstaller.js index 3ff8dc1ecbb..a6c148813da 100644 --- a/lib/typingsInstaller.js +++ b/lib/typingsInstaller.js @@ -29009,7 +29009,7 @@ var ts; /** @internal */ var ts; (function (ts) { - function createGetSymbolWalker(getRestTypeOfSignature, getTypePredicateOfSignature, getReturnTypeOfSignature, getBaseTypes, resolveStructuredTypeMembers, getTypeOfSymbol, getResolvedSymbol, getIndexTypeOfStructuredType, getConstraintFromTypeParameter, getFirstIdentifier) { + function createGetSymbolWalker(getRestTypeOfSignature, getTypePredicateOfSignature, getReturnTypeOfSignature, getBaseTypes, resolveStructuredTypeMembers, getTypeOfSymbol, getResolvedSymbol, getIndexTypeOfStructuredType, getConstraintOfTypeParameter, getFirstIdentifier) { return getSymbolWalker; function getSymbolWalker(accept) { if (accept === void 0) { accept = function () { return true; }; } @@ -29085,7 +29085,7 @@ var ts; ts.forEach(type.typeArguments, visitType); } function visitTypeParameter(type) { - visitType(getConstraintFromTypeParameter(type)); + visitType(getConstraintOfTypeParameter(type)); } function visitUnionOrIntersectionType(type) { ts.forEach(type.types, visitType); @@ -29411,7 +29411,7 @@ var ts; getEmitResolver: getEmitResolver, getExportsOfModule: getExportsOfModuleAsArray, getExportsAndPropertiesOfModule: getExportsAndPropertiesOfModule, - getSymbolWalker: ts.createGetSymbolWalker(getRestTypeOfSignature, getTypePredicateOfSignature, getReturnTypeOfSignature, getBaseTypes, resolveStructuredTypeMembers, getTypeOfSymbol, getResolvedSymbol, getIndexTypeOfStructuredType, getConstraintFromTypeParameter, getFirstIdentifier), + getSymbolWalker: ts.createGetSymbolWalker(getRestTypeOfSignature, getTypePredicateOfSignature, getReturnTypeOfSignature, getBaseTypes, resolveStructuredTypeMembers, getTypeOfSymbol, getResolvedSymbol, getIndexTypeOfStructuredType, getConstraintOfTypeParameter, getFirstIdentifier), getAmbientModules: getAmbientModules, getAllAttributesTypeFromJsxOpeningLikeElement: function (nodeIn) { var node = ts.getParseTreeNode(nodeIn, ts.isJsxOpeningLikeElement); @@ -32603,7 +32603,7 @@ var ts; return ts.createTypeParameterDeclaration(name, constraintNode, defaultParameterNode); } function typeParameterToDeclaration(type, context, constraint) { - if (constraint === void 0) { constraint = getConstraintFromTypeParameter(type); } + if (constraint === void 0) { constraint = getConstraintOfTypeParameter(type); } var constraintNode = constraint && typeToTypeNodeHelper(constraint, context); return typeParameterToDeclarationWithConstraint(type, context, constraintNode); } @@ -33173,23 +33173,19 @@ var ts; return -1; } function hasType(target, propertyName) { - if (propertyName === 0 /* Type */) { - return !!getSymbolLinks(target).type; + switch (propertyName) { + case 0 /* Type */: + return !!getSymbolLinks(target).type; + case 2 /* DeclaredType */: + return !!getSymbolLinks(target).declaredType; + case 1 /* ResolvedBaseConstructorType */: + return !!target.resolvedBaseConstructorType; + case 3 /* ResolvedReturnType */: + return !!target.resolvedReturnType; + case 4 /* ImmediateBaseConstraint */: + return !!target.immediateBaseConstraint; } - if (propertyName === 2 /* DeclaredType */) { - return !!getSymbolLinks(target).declaredType; - } - if (propertyName === 1 /* ResolvedBaseConstructorType */) { - return !!target.resolvedBaseConstructorType; - } - if (propertyName === 3 /* ResolvedReturnType */) { - return !!target.resolvedReturnType; - } - if (propertyName === 4 /* ImmediateBaseConstraint */) { - var bc = target.immediateBaseConstraint; - return !!bc && bc !== circularConstraintType; - } - return ts.Debug.fail("Unhandled TypeSystemPropertyName " + propertyName); + return ts.Debug.assertNever(propertyName); } // Pop an entry from the type resolution stack and return its associated result value. The result value will // be true if no circularities were detected, or false if a circularity was found. @@ -35580,20 +35576,12 @@ var ts; } return undefined; } - function getBaseConstraintOfInstantiableNonPrimitiveUnionOrIntersection(type) { + function getBaseConstraintOfType(type) { if (type.flags & (14745600 /* InstantiableNonPrimitive */ | 786432 /* UnionOrIntersection */)) { var constraint = getResolvedBaseConstraint(type); - if (constraint !== noConstraintType && constraint !== circularConstraintType) { - return constraint; - } + return constraint !== noConstraintType && constraint !== circularConstraintType ? constraint : undefined; } - } - function getBaseConstraintOfType(type) { - var constraint = getBaseConstraintOfInstantiableNonPrimitiveUnionOrIntersection(type); - if (!constraint && type.flags & 1048576 /* Index */) { - return keyofConstraintType; - } - return constraint; + return type.flags & 1048576 /* Index */ ? keyofConstraintType : undefined; } /** * This is similar to `getBaseConstraintOfType` except it returns the input type if there's no base constraint, instead of `undefined` @@ -35611,29 +35599,24 @@ var ts; * circularly references the type variable. */ function getResolvedBaseConstraint(type) { - var circular; - if (!type.resolvedBaseConstraint) { - var constraint = getBaseConstraint(type); - type.resolvedBaseConstraint = circular ? circularConstraintType : getTypeWithThisArgument(constraint || noConstraintType, type); + return type.resolvedBaseConstraint || + (type.resolvedBaseConstraint = getTypeWithThisArgument(getImmediateBaseConstraint(type), type)); + function getImmediateBaseConstraint(t) { + if (!t.immediateBaseConstraint) { + if (!pushTypeResolution(t, 4 /* ImmediateBaseConstraint */)) { + return circularConstraintType; + } + var result = computeBaseConstraint(getSimplifiedType(t)); + if (!popTypeResolution()) { + result = circularConstraintType; + } + t.immediateBaseConstraint = result || noConstraintType; + } + return t.immediateBaseConstraint; } - return type.resolvedBaseConstraint; function getBaseConstraint(t) { - if (t.immediateBaseConstraint) { - return t.immediateBaseConstraint === noConstraintType ? undefined : t.immediateBaseConstraint; - } - if (!pushTypeResolution(t, 4 /* ImmediateBaseConstraint */)) { - circular = true; - t.immediateBaseConstraint = circularConstraintType; - return undefined; - } - var result = computeBaseConstraint(getSimplifiedType(t)); - if (!popTypeResolution()) { - circular = true; - t.immediateBaseConstraint = circularConstraintType; - return undefined; - } - t.immediateBaseConstraint = !result ? noConstraintType : result; - return result; + var c = getImmediateBaseConstraint(t); + return c !== noConstraintType && c !== circularConstraintType ? c : undefined; } function computeBaseConstraint(t) { if (t.flags & 65536 /* TypeParameter */) { @@ -36437,6 +36420,7 @@ var ts; } return inferences && getIntersectionType(inferences); } + /** This is a worker function. Use getConstraintOfTypeParameter which guards against circular constraints. */ function getConstraintFromTypeParameter(typeParameter) { if (!typeParameter.constraint) { if (typeParameter.target) { @@ -37604,7 +37588,7 @@ var ts; return type.simplified = substituteIndexedMappedType(objectType, type); } if (objectType.flags & 65536 /* TypeParameter */) { - var constraint = getConstraintFromTypeParameter(objectType); + var constraint = getConstraintOfTypeParameter(objectType); if (constraint && isGenericMappedType(constraint)) { return type.simplified = substituteIndexedMappedType(constraint, type); } @@ -40408,7 +40392,7 @@ var ts; return false; } function isUnconstrainedTypeParameter(type) { - return type.flags & 65536 /* TypeParameter */ && !getConstraintFromTypeParameter(type); + return type.flags & 65536 /* TypeParameter */ && !getConstraintOfTypeParameter(type); } function isTypeReferenceWithGenericArguments(type) { return !!(ts.getObjectFlags(type) & 4 /* Reference */) && ts.some(type.typeArguments, function (t) { return isUnconstrainedTypeParameter(t) || isTypeReferenceWithGenericArguments(t); }); @@ -45507,7 +45491,7 @@ var ts; return false; } var thisType = getTypeFromTypeNode(thisParameter.type); - enclosingClass = ((thisType.flags & 65536 /* TypeParameter */) ? getConstraintFromTypeParameter(thisType) : thisType); + enclosingClass = ((thisType.flags & 65536 /* TypeParameter */) ? getConstraintOfTypeParameter(thisType) : thisType); } // No further restrictions for static properties if (flags & 32 /* Static */) { @@ -46974,7 +46958,7 @@ var ts; typeArguments.pop(); } while (typeArguments.length < typeParameters.length) { - typeArguments.push(getConstraintFromTypeParameter(typeParameters[typeArguments.length]) || getDefaultTypeArgumentType(ts.isInJavaScriptFile(node))); + typeArguments.push(getConstraintOfTypeParameter(typeParameters[typeArguments.length]) || getDefaultTypeArgumentType(ts.isInJavaScriptFile(node))); } var instantiated = createSignatureInstantiation(candidate, typeArguments); candidates[bestIndex] = instantiated; @@ -52268,7 +52252,7 @@ var ts; // If the type parameter node does not have an identical constraint as the resolved // type parameter at this position, we report an error. var sourceConstraint = source.constraint && getTypeFromTypeNode(source.constraint); - var targetConstraint = getConstraintFromTypeParameter(target); + var targetConstraint = getConstraintOfTypeParameter(target); if (sourceConstraint) { // relax check if later interface augmentation has no constraint if (!targetConstraint || !isTypeIdenticalTo(sourceConstraint, targetConstraint)) {