Update LKG.

This commit is contained in:
Daniel Rosenwasser 2019-03-12 14:47:01 -07:00
parent 98b4eae2f0
commit 559238b36b
9 changed files with 921 additions and 820 deletions

View File

@ -60,7 +60,7 @@ var __makeTemplateObject = (this && this.__makeTemplateObject) || function (cook
var ts;
(function (ts) {
ts.versionMajorMinor = "3.4";
ts.version = ts.versionMajorMinor + ".0-dev";
ts.version = ts.versionMajorMinor + ".0-rc";
})(ts || (ts = {}));
(function (ts) {
ts.emptyArray = [];
@ -2241,8 +2241,11 @@ var ts;
var ts;
(function (ts) {
function generateDjb2Hash(data) {
var chars = data.split("").map(function (str) { return str.charCodeAt(0); });
return "" + chars.reduce(function (prev, curr) { return ((prev << 5) + prev) + curr; }, 5381);
var acc = 5381;
for (var i = 0; i < data.length; i++) {
acc = ((acc << 5) + acc) + data.charCodeAt(i);
}
return acc.toString();
}
ts.generateDjb2Hash = generateDjb2Hash;
function setStackTraceLimit() {
@ -5908,6 +5911,7 @@ var ts;
}
pos++;
}
tokenValue = text.substring(startPos, pos);
return firstNonWhitespace === -1 ? 12 : 11;
}
function scanJsxIdentifier() {
@ -16147,7 +16151,8 @@ var ts;
}
function parseJsxText() {
var node = createNode(11);
node.containsOnlyWhiteSpaces = currentToken === 12;
node.text = scanner.getTokenValue();
node.containsOnlyTriviaWhiteSpaces = currentToken === 12;
currentToken = scanner.scanJsxToken();
return finishNode(node);
}
@ -25601,6 +25606,7 @@ var ts;
getResolvedSignatureForSignatureHelp: function (node, candidatesOutArray, agumentCount) {
return getResolvedSignatureWorker(node, candidatesOutArray, agumentCount, 16);
},
getExpandedParameters: getExpandedParameters,
getConstantValue: function (nodeIn) {
var node = ts.getParseTreeNode(nodeIn, canHaveConstantValue);
return node ? getConstantValue(node) : undefined;
@ -25952,11 +25958,11 @@ var ts;
}
}
function addRelatedInfo(diagnostic) {
var _a;
var relatedInformation = [];
for (var _i = 1; _i < arguments.length; _i++) {
relatedInformation[_i - 1] = arguments[_i];
}
var _a;
if (!diagnostic.relatedInformation) {
diagnostic.relatedInformation = [];
}
@ -30795,7 +30801,17 @@ var ts;
return sig;
}
function cloneSignature(sig) {
return createSignature(sig.declaration, sig.typeParameters, sig.thisParameter, sig.parameters, undefined, undefined, sig.minArgumentCount, sig.hasRestParameter, sig.hasLiteralTypes);
var result = createSignature(sig.declaration, sig.typeParameters, sig.thisParameter, sig.parameters, undefined, undefined, sig.minArgumentCount, sig.hasRestParameter, sig.hasLiteralTypes);
result.target = sig.target;
result.mapper = sig.mapper;
return result;
}
function createUnionSignature(signature, unionSignatures) {
var result = cloneSignature(signature);
result.unionSignatures = unionSignatures;
result.target = undefined;
result.mapper = undefined;
return result;
}
function getExpandedParameters(sig) {
if (sig.hasRestParameter) {
@ -30894,9 +30910,8 @@ var ts;
var thisType = getUnionType(ts.map(unionSignatures, function (sig) { return sig.thisParameter ? getTypeOfSymbol(sig.thisParameter) : anyType; }), 2);
thisParameter = createSymbolWithType(signature.thisParameter, thisType);
}
s = cloneSignature(signature);
s = createUnionSignature(signature, unionSignatures);
s.thisParameter = thisParameter;
s.unionSignatures = unionSignatures;
}
(result || (result = [])).push(s);
}
@ -32132,8 +32147,6 @@ var ts;
if (returnSignature) {
var newReturnSignature = cloneSignature(returnSignature);
newReturnSignature.typeParameters = inferredTypeParameters;
newReturnSignature.target = returnSignature.target;
newReturnSignature.mapper = returnSignature.mapper;
var newInstantiatedSignature = cloneSignature(instantiatedSignature);
newInstantiatedSignature.resolvedReturnType = getOrCreateTypeFromSignature(newReturnSignature);
return newInstantiatedSignature;
@ -33565,7 +33578,7 @@ var ts;
if (!checkTypeInstantiable) {
inferTypes(context.inferences, checkType, extendsType, 32 | 64);
}
combinedMapper = combineTypeMappers(mapper, context);
combinedMapper = combineTypeMappers(mapper, context.mapper);
}
var inferredExtendsType = combinedMapper ? instantiateType(root.extendsType, combinedMapper) : extendsType;
if (!checkTypeInstantiable && !maybeTypeOfKind(inferredExtendsType, 63176704 | 131072)) {
@ -34083,32 +34096,8 @@ var ts;
function createTypeEraser(sources) {
return createTypeMapper(sources, undefined);
}
function createBackreferenceMapper(typeParameters, index) {
return function (t) { return typeParameters.indexOf(t) >= index ? emptyObjectType : t; };
}
function isInferenceContext(mapper) {
return !!mapper.typeParameters;
}
function cloneTypeMapper(mapper, extraFlags) {
if (extraFlags === void 0) { extraFlags = 0; }
return mapper && isInferenceContext(mapper) ?
createInferenceContext(mapper.typeParameters, mapper.signature, mapper.flags | extraFlags, mapper.compareTypes, mapper.inferences) :
mapper;
}
function cloneInferredPartOfContext(context) {
var params = [];
var inferences = [];
for (var i = 0; i < context.typeParameters.length; i++) {
var info = context.inferences[i];
if (info.candidates || info.contraCandidates) {
params.push(context.typeParameters[i]);
inferences.push(info);
}
}
if (!params.length) {
return undefined;
}
return createInferenceContext(params, context.signature, context.flags | 1, context.compareTypes, inferences);
function createBackreferenceMapper(context, index) {
return function (t) { return ts.findIndex(context.inferences, function (info) { return info.typeParameter === t; }) >= index ? emptyObjectType : t; };
}
function combineTypeMappers(mapper1, mapper2) {
if (!mapper1)
@ -34748,7 +34737,7 @@ var ts;
case 270:
return { errorNode: child, innerExpression: child.expression, nameType: nameType };
case 11:
if (child.containsOnlyWhiteSpaces) {
if (child.containsOnlyTriviaWhiteSpaces) {
break;
}
return { errorNode: child, innerExpression: undefined, nameType: nameType, errorMessage: getInvalidTextDiagnostic() };
@ -34769,7 +34758,7 @@ var ts;
var childrenPropName = childPropName === undefined ? "children" : ts.unescapeLeadingUnderscores(childPropName);
var childrenNameType = getLiteralType(childrenPropName);
var childrenTargetType = getIndexedAccessType(target, childrenNameType);
var validChildren = ts.filter(containingElement.children, function (i) { return !ts.isJsxText(i) || !i.containsOnlyWhiteSpaces; });
var validChildren = ts.filter(containingElement.children, function (i) { return !ts.isJsxText(i) || !i.containsOnlyTriviaWhiteSpaces; });
if (!ts.length(validChildren)) {
return result;
}
@ -37013,26 +37002,43 @@ var ts;
callback(getRestTypeAtPosition(source, paramCount), targetRestType);
}
}
function createInferenceContext(typeParameters, signature, flags, compareTypes, baseInferences) {
var inferences = baseInferences ? baseInferences.map(cloneInferenceInfo) : typeParameters.map(createInferenceInfo);
var context = mapper;
context.typeParameters = typeParameters;
context.signature = signature;
context.inferences = inferences;
context.flags = flags;
context.compareTypes = compareTypes || compareTypesAssignable;
function createInferenceContext(typeParameters, signature, flags, compareTypes) {
return createInferenceContextWorker(typeParameters.map(createInferenceInfo), signature, flags, compareTypes || compareTypesAssignable);
}
function cloneInferenceContext(context, extraFlags) {
if (extraFlags === void 0) { extraFlags = 0; }
return context && createInferenceContextWorker(ts.map(context.inferences, cloneInferenceInfo), context.signature, context.flags | extraFlags, context.compareTypes);
}
function cloneInferredPartOfContext(context) {
var inferences = ts.filter(context.inferences, hasInferenceCandidates);
return inferences.length ?
createInferenceContextWorker(ts.map(inferences, cloneInferenceInfo), context.signature, context.flags, context.compareTypes) :
undefined;
}
function createInferenceContextWorker(inferences, signature, flags, compareTypes) {
var context = {
inferences: inferences,
signature: signature,
flags: flags,
compareTypes: compareTypes,
mapper: function (t) { return mapToInferredType(context, t, true); },
nonFixingMapper: function (t) { return mapToInferredType(context, t, false); },
};
return context;
function mapper(t) {
for (var i = 0; i < inferences.length; i++) {
if (t === inferences[i].typeParameter) {
if (!(context.flags & 4)) {
inferences[i].isFixed = true;
}
return getInferredType(context, i);
}
function mapToInferredType(context, t, fix) {
var inferences = context.inferences;
for (var i = 0; i < inferences.length; i++) {
var inference = inferences[i];
if (t === inference.typeParameter) {
if (fix && !inference.isFixed) {
inference.isFixed = true;
inference.inferredType = undefined;
}
return getInferredType(context, i);
}
return t;
}
return t;
}
function createInferenceInfo(typeParameter) {
return {
@ -37056,6 +37062,9 @@ var ts;
isFixed: inference.isFixed
};
}
function getMapperFromContext(context) {
return context && context.mapper;
}
function couldContainTypeVariables(type) {
var objectFlags = ts.getObjectFlags(type);
return !!(type.flags & 63176704 ||
@ -37260,15 +37269,18 @@ var ts;
}
if (priority === inference.priority) {
var candidate = propagationType || source;
if (contravariant && !bivariant) {
inference.contraCandidates = ts.appendIfUnique(inference.contraCandidates, candidate);
if (contravariant && !bivariant && !ts.contains(inference.contraCandidates, candidate)) {
inference.contraCandidates = ts.append(inference.contraCandidates, candidate);
inference.inferredType = undefined;
}
else {
inference.candidates = ts.appendIfUnique(inference.candidates, candidate);
else if (!ts.contains(inference.candidates, candidate)) {
inference.candidates = ts.append(inference.candidates, candidate);
inference.inferredType = undefined;
}
}
if (!(priority & 8) && target.flags & 262144 && !isTypeParameterAtTopLevel(originalTarget, target)) {
if (!(priority & 8) && target.flags & 262144 && inference.topLevel && !isTypeParameterAtTopLevel(originalTarget, target)) {
inference.topLevel = false;
inference.inferredType = undefined;
}
}
return;
@ -37330,7 +37342,7 @@ var ts;
inferFromTypes(getTrueTypeFromConditionalType(source), getTrueTypeFromConditionalType(target));
inferFromTypes(getFalseTypeFromConditionalType(source), getFalseTypeFromConditionalType(target));
}
else if (target.flags & 16777216) {
else if (target.flags & 16777216 && !contravariant) {
inferFromTypes(source, getTrueTypeFromConditionalType(target));
inferFromTypes(source, getFalseTypeFromConditionalType(target));
}
@ -37628,7 +37640,7 @@ var ts;
else {
var defaultType = getDefaultFromTypeParameter(inference.typeParameter);
if (defaultType) {
inferredType = instantiateType(defaultType, combineTypeMappers(createBackreferenceMapper(context.typeParameters, index), context));
inferredType = instantiateType(defaultType, combineTypeMappers(createBackreferenceMapper(context, index), context.nonFixingMapper));
}
else {
inferredType = getDefaultTypeArgumentType(!!(context.flags & 2));
@ -37641,12 +37653,10 @@ var ts;
inference.inferredType = inferredType;
var constraint = getConstraintOfTypeParameter(inference.typeParameter);
if (constraint) {
context.flags |= 4;
var instantiatedConstraint = instantiateType(constraint, context);
var instantiatedConstraint = instantiateType(constraint, context.nonFixingMapper);
if (!context.compareTypes(inferredType, getTypeWithThisArgument(instantiatedConstraint, inferredType))) {
inference.inferredType = inferredType = instantiatedConstraint;
}
context.flags &= ~4;
}
}
return inferredType;
@ -39557,7 +39567,7 @@ var ts;
while (type) {
var thisType = getThisTypeFromContextualType(type);
if (thisType) {
return instantiateType(thisType, getContextualMapper(containingLiteral));
return instantiateType(thisType, getMapperFromContext(getInferenceContext(containingLiteral)));
}
if (literal.parent.kind !== 275) {
break;
@ -39953,9 +39963,9 @@ var ts;
}
function instantiateContextualType(contextualType, node) {
if (contextualType && maybeTypeOfKind(contextualType, 63176704)) {
var returnMapper = getContextualMapper(node).returnMapper;
if (returnMapper) {
return instantiateInstantiableTypes(contextualType, returnMapper);
var inferenceContext = getInferenceContext(node);
if (inferenceContext && inferenceContext.returnMapper) {
return instantiateInstantiableTypes(contextualType, inferenceContext.returnMapper);
}
}
return contextualType;
@ -40032,9 +40042,9 @@ var ts;
}
return undefined;
}
function getContextualMapper(node) {
var ancestor = ts.findAncestor(node, function (n) { return !!n.contextualMapper; });
return ancestor ? ancestor.contextualMapper : identityMapper;
function getInferenceContext(node) {
var ancestor = ts.findAncestor(node, function (n) { return !!n.inferenceContext; });
return ancestor && ancestor.inferenceContext;
}
function getContextualJsxElementAttributesType(node) {
if (ts.isJsxOpeningElement(node) && node.parent.contextualType) {
@ -40207,12 +40217,7 @@ var ts;
}
}
}
var result;
if (signatureList) {
result = cloneSignature(signatureList[0]);
result.unionSignatures = signatureList;
}
return result;
return signatureList && createUnionSignature(signatureList[0], signatureList);
}
function checkSpreadExpression(node, checkMode) {
if (languageVersion < 2 && compilerOptions.downlevelIteration) {
@ -40644,7 +40649,7 @@ var ts;
for (var _i = 0, _a = node.children; _i < _a.length; _i++) {
var child = _a[_i];
if (child.kind === 11) {
if (!child.containsOnlyWhiteSpaces) {
if (!child.containsOnlyTriviaWhiteSpaces) {
childrenTypes.push(stringType);
}
}
@ -41542,15 +41547,15 @@ var ts;
}
return undefined;
}
function instantiateSignatureInContextOf(signature, contextualSignature, contextualMapper, compareTypes) {
function instantiateSignatureInContextOf(signature, contextualSignature, inferenceContext, compareTypes) {
var context = createInferenceContext(signature.typeParameters, signature, 0, compareTypes);
var restType = getEffectiveRestType(contextualSignature);
var mapper = contextualMapper && restType && restType.flags & 262144 ? cloneTypeMapper(contextualMapper) : contextualMapper;
var mapper = inferenceContext && (restType && restType.flags & 262144 ? inferenceContext.nonFixingMapper : inferenceContext.mapper);
var sourceSignature = mapper ? instantiateSignature(contextualSignature, mapper) : contextualSignature;
forEachMatchingParameterType(sourceSignature, signature, function (source, target) {
inferTypes(context.inferences, source, target);
});
if (!contextualMapper) {
if (!inferenceContext) {
inferTypes(context.inferences, getReturnTypeOfSignature(contextualSignature), getReturnTypeOfSignature(signature), 8);
var signaturePredicate = getTypePredicateOfSignature(signature);
var contextualPredicate = getTypePredicateOfSignature(sourceSignature);
@ -41568,26 +41573,21 @@ var ts;
return getInferredTypes(context);
}
function inferTypeArguments(node, signature, args, checkMode, context) {
for (var _i = 0, _a = context.inferences; _i < _a.length; _i++) {
var inference = _a[_i];
if (!inference.isFixed) {
inference.inferredType = undefined;
}
}
if (ts.isJsxOpeningLikeElement(node)) {
return inferJsxTypeArguments(node, signature, checkMode, context);
}
if (node.kind !== 152) {
var contextualType = getContextualType(node);
if (contextualType) {
var instantiatedType = instantiateType(contextualType, cloneTypeMapper(getContextualMapper(node), 1));
var outerMapper = getMapperFromContext(cloneInferenceContext(getInferenceContext(node), 1));
var instantiatedType = instantiateType(contextualType, outerMapper);
var contextualSignature = getSingleCallSignature(instantiatedType);
var inferenceSourceType = contextualSignature && contextualSignature.typeParameters ?
getOrCreateTypeFromSignature(getSignatureInstantiationWithoutFillingInTypeArguments(contextualSignature, contextualSignature.typeParameters)) :
instantiatedType;
var inferenceTargetType = getReturnTypeOfSignature(signature);
inferTypes(context.inferences, inferenceSourceType, inferenceTargetType, 8);
context.returnMapper = cloneInferredPartOfContext(context);
context.returnMapper = getMapperFromContext(cloneInferredPartOfContext(context));
}
}
var thisType = getThisTypeOfSignature(signature);
@ -41980,7 +41980,7 @@ var ts;
else {
inferenceContext = createInferenceContext(candidate.typeParameters, candidate, ts.isInJSFile(node) ? 2 : 0);
typeArgumentTypes = inferTypeArguments(node, candidate, args, argCheckMode | 8, inferenceContext);
argCheckMode |= inferenceContext.flags & 8 ? 8 : 0;
argCheckMode |= inferenceContext.flags & 4 ? 8 : 0;
}
checkCandidate = getSignatureInstantiation(candidate, typeArgumentTypes, ts.isInJSFile(candidate.declaration), inferenceContext && inferenceContext.inferredTypeParameters);
if (getNonArrayRestType(candidate) && !hasCorrectArity(node, args, checkCandidate, signatureHelpTrailingComma)) {
@ -42749,8 +42749,10 @@ var ts;
}
if (signature.hasRestParameter) {
var restType = getTypeOfSymbol(signature.parameters[paramCount]);
var indexType = getLiteralType(pos - paramCount);
return getIndexedAccessType(restType, indexType);
var index = pos - paramCount;
if (!isTupleType(restType) || restType.target.hasRestElement || index < (restType.typeArguments || ts.emptyArray).length) {
return getIndexedAccessType(restType, getLiteralType(index));
}
}
return undefined;
}
@ -42821,23 +42823,23 @@ var ts;
function getTypeOfFirstParameterOfSignatureWithFallback(signature, fallbackType) {
return signature.parameters.length > 0 ? getTypeAtPosition(signature, 0) : fallbackType;
}
function inferFromAnnotatedParameters(signature, context, mapper) {
function inferFromAnnotatedParameters(signature, context, inferenceContext) {
var len = signature.parameters.length - (signature.hasRestParameter ? 1 : 0);
for (var i = 0; i < len; i++) {
var declaration = signature.parameters[i].valueDeclaration;
if (declaration.type) {
var typeNode = ts.getEffectiveTypeAnnotationNode(declaration);
if (typeNode) {
inferTypes(mapper.inferences, getTypeFromTypeNode(typeNode), getTypeAtPosition(context, i));
inferTypes(inferenceContext.inferences, getTypeFromTypeNode(typeNode), getTypeAtPosition(context, i));
}
}
}
var restType = getEffectiveRestType(context);
if (restType && restType.flags & 262144) {
var instantiatedContext = instantiateSignature(context, cloneTypeMapper(mapper));
var instantiatedContext = instantiateSignature(context, inferenceContext.nonFixingMapper);
assignContextualParameterTypes(signature, instantiatedContext);
var restPos = getParameterCount(context) - 1;
inferTypes(mapper.inferences, getRestTypeAtPosition(signature, restPos), restType);
inferTypes(inferenceContext.inferences, getRestTypeAtPosition(signature, restPos), restType);
}
}
function assignContextualParameterTypes(signature, context) {
@ -43175,12 +43177,12 @@ var ts;
if (contextualSignature) {
var signature = getSignaturesOfType(type, 0)[0];
if (isContextSensitive(node)) {
var contextualMapper = getContextualMapper(node);
var inferenceContext = getInferenceContext(node);
if (checkMode && checkMode & 2) {
inferFromAnnotatedParameters(signature, contextualSignature, contextualMapper);
inferFromAnnotatedParameters(signature, contextualSignature, inferenceContext);
}
var instantiatedContextualSignature = contextualMapper === identityMapper ?
contextualSignature : instantiateSignature(contextualSignature, contextualMapper);
var instantiatedContextualSignature = inferenceContext ?
instantiateSignature(contextualSignature, inferenceContext.mapper) : contextualSignature;
assignContextualParameterTypes(signature, instantiatedContextualSignature);
}
if (!getReturnTypeFromAnnotation(node) && !signature.resolvedReturnType) {
@ -44000,17 +44002,17 @@ var ts;
}
return node;
}
function checkExpressionWithContextualType(node, contextualType, contextualMapper, checkMode) {
function checkExpressionWithContextualType(node, contextualType, inferenceContext, checkMode) {
var context = getContextNode(node);
var saveContextualType = context.contextualType;
var saveContextualMapper = context.contextualMapper;
var saveInferenceContext = context.inferenceContext;
context.contextualType = contextualType;
context.contextualMapper = contextualMapper;
var type = checkExpression(node, checkMode | 1 | (contextualMapper ? 2 : 0));
context.inferenceContext = inferenceContext;
var type = checkExpression(node, checkMode | 1 | (inferenceContext ? 2 : 0));
var result = maybeTypeOfKind(type, 2944) && isLiteralOfContextualType(type, instantiateContextualType(contextualType, node)) ?
getRegularTypeOfLiteralType(type) : type;
context.contextualType = saveContextualType;
context.contextualMapper = saveContextualMapper;
context.inferenceContext = saveInferenceContext;
return result;
}
function checkExpressionCached(node, checkMode) {
@ -44109,12 +44111,12 @@ var ts;
if (contextualType) {
var contextualSignature = getSingleCallSignature(getNonNullableType(contextualType));
if (contextualSignature && !contextualSignature.typeParameters) {
var context = getContextualMapper(node);
var context = getInferenceContext(node);
var returnSignature = context.signature && getSingleCallSignature(getReturnTypeOfSignature(context.signature));
if (returnSignature && !returnSignature.typeParameters && !ts.every(context.inferences, hasInferenceCandidates)) {
var uniqueTypeParameters = getUniqueTypeParameters(context, signature.typeParameters);
var strippedType = getOrCreateTypeFromSignature(getSignatureInstantiationWithoutFillingInTypeArguments(signature, uniqueTypeParameters));
var inferences = ts.map(context.typeParameters, createInferenceInfo);
var inferences = ts.map(context.inferences, function (info) { return createInferenceInfo(info.typeParameter); });
inferTypes(inferences, strippedType, contextualType);
if (ts.some(inferences, hasInferenceCandidates) && !hasOverlappingInferences(context.inferences, inferences)) {
mergeInferences(context.inferences, inferences);
@ -44131,8 +44133,8 @@ var ts;
}
function skippedGenericFunction(node, checkMode) {
if (checkMode & 2) {
var context = getContextualMapper(node);
context.flags |= 8;
var context = getInferenceContext(node);
context.flags |= 4;
}
}
function hasInferenceCandidates(info) {
@ -52591,6 +52593,28 @@ var ts;
return node;
}
ts.createJsxFragment = createJsxFragment;
function createJsxText(text, containsOnlyTriviaWhiteSpaces) {
var node = createSynthesizedNode(11);
node.text = text;
node.containsOnlyTriviaWhiteSpaces = !!containsOnlyTriviaWhiteSpaces;
return node;
}
ts.createJsxText = createJsxText;
function updateJsxText(node, text, containsOnlyTriviaWhiteSpaces) {
return node.text !== text
|| node.containsOnlyTriviaWhiteSpaces !== containsOnlyTriviaWhiteSpaces
? updateNode(createJsxText(text, containsOnlyTriviaWhiteSpaces), node)
: node;
}
ts.updateJsxText = updateJsxText;
function createJsxOpeningFragment() {
return createSynthesizedNode(265);
}
ts.createJsxOpeningFragment = createJsxOpeningFragment;
function createJsxJsxClosingFragment() {
return createSynthesizedNode(266);
}
ts.createJsxJsxClosingFragment = createJsxJsxClosingFragment;
function updateJsxFragment(node, openingFragment, children, closingFragment) {
return node.openingFragment !== openingFragment
|| node.children !== children
@ -59608,7 +59632,7 @@ var ts;
}
}
function visitJsxText(node) {
var fixed = fixupWhitespaceAndDecodeEntities(ts.getTextOfNode(node, true));
var fixed = fixupWhitespaceAndDecodeEntities(node.text);
return fixed === undefined ? undefined : ts.createLiteral(fixed);
}
function fixupWhitespaceAndDecodeEntities(text) {
@ -69687,7 +69711,7 @@ var ts;
writePunctuation(">");
}
function emitJsxText(node) {
writer.writeLiteral(getTextOfNode(node, true));
writer.writeLiteral(node.text);
}
function emitJsxClosingElementOrFragment(node) {
writePunctuation("</");
@ -76093,7 +76117,7 @@ var ts;
}
}
ts.createCompilerHostFromProgramHost = createCompilerHostFromProgramHost;
function setCreateSourceFileAsHashVersioned(compilerHost, host) {
function setGetSourceFileAsHashVersioned(compilerHost, host) {
var originalGetSourceFile = compilerHost.getSourceFile;
var computeHash = host.createHash || ts.generateDjb2Hash;
compilerHost.getSourceFile = function () {
@ -76108,7 +76132,7 @@ var ts;
return result;
};
}
ts.setCreateSourceFileAsHashVersioned = setCreateSourceFileAsHashVersioned;
ts.setGetSourceFileAsHashVersioned = setGetSourceFileAsHashVersioned;
function createProgramHost(system, createProgram) {
var getDefaultLibLocation = ts.memoize(function () { return ts.getDirectoryPath(ts.normalizePath(system.getExecutingFilePath())); });
var host = system;
@ -76240,7 +76264,7 @@ var ts;
configFileWatcher = watchFile(host, configFileName, scheduleProgramReload, ts.PollingInterval.High, "Config file");
}
var compilerHost = ts.createCompilerHostFromProgramHost(host, function () { return compilerOptions; }, directoryStructureHost);
ts.setCreateSourceFileAsHashVersioned(compilerHost, host);
ts.setGetSourceFileAsHashVersioned(compilerHost, host);
var getNewSourceFile = compilerHost.getSourceFile;
compilerHost.getSourceFile = function (fileName) {
var args = [];
@ -76757,7 +76781,7 @@ var ts;
var readFileWithCache = function (f) { return host.readFile(f); };
var projectCompilerOptions = baseCompilerOptions;
var compilerHost = ts.createCompilerHostFromProgramHost(host, function () { return projectCompilerOptions; });
ts.setCreateSourceFileAsHashVersioned(compilerHost, host);
ts.setGetSourceFileAsHashVersioned(compilerHost, host);
var buildInfoChecked = createFileMap(toPath);
var builderPrograms = createFileMap(toPath);
var diagnostics = createFileMap(toPath);

View File

@ -85,7 +85,7 @@ var ts;
// If changing the text in this section, be sure to test `configureNightly` too.
ts.versionMajorMinor = "3.4";
/** The version of the TypeScript compiler release */
ts.version = ts.versionMajorMinor + ".0-dev";
ts.version = ts.versionMajorMinor + ".0-rc";
})(ts || (ts = {}));
(function (ts) {
/* @internal */
@ -3585,8 +3585,7 @@ var ts;
InferenceFlags[InferenceFlags["None"] = 0] = "None";
InferenceFlags[InferenceFlags["NoDefault"] = 1] = "NoDefault";
InferenceFlags[InferenceFlags["AnyDefault"] = 2] = "AnyDefault";
InferenceFlags[InferenceFlags["NoFixing"] = 4] = "NoFixing";
InferenceFlags[InferenceFlags["SkippedGenericFunction"] = 8] = "SkippedGenericFunction";
InferenceFlags[InferenceFlags["SkippedGenericFunction"] = 4] = "SkippedGenericFunction";
})(InferenceFlags = ts.InferenceFlags || (ts.InferenceFlags = {}));
/**
* Ternary values are defined such that
@ -4158,8 +4157,11 @@ var ts;
*/
/* @internal */
function generateDjb2Hash(data) {
var chars = data.split("").map(function (str) { return str.charCodeAt(0); });
return "" + chars.reduce(function (prev, curr) { return ((prev << 5) + prev) + curr; }, 5381);
var acc = 5381;
for (var i = 0; i < data.length; i++) {
acc = ((acc << 5) + acc) + data.charCodeAt(i);
}
return acc.toString();
}
ts.generateDjb2Hash = generateDjb2Hash;
/**
@ -8153,6 +8155,7 @@ var ts;
}
pos++;
}
tokenValue = text.substring(startPos, pos);
return firstNonWhitespace === -1 ? 12 /* JsxTextAllWhiteSpaces */ : 11 /* JsxText */;
}
// Scans a JSX identifier; these differ from normal identifiers in that
@ -20272,7 +20275,8 @@ var ts;
}
function parseJsxText() {
var node = createNode(11 /* JsxText */);
node.containsOnlyWhiteSpaces = currentToken === 12 /* JsxTextAllWhiteSpaces */;
node.text = scanner.getTokenValue();
node.containsOnlyTriviaWhiteSpaces = currentToken === 12 /* JsxTextAllWhiteSpaces */;
currentToken = scanner.scanJsxToken();
return finishNode(node);
}
@ -31278,6 +31282,7 @@ var ts;
getResolvedSignatureForSignatureHelp: function (node, candidatesOutArray, agumentCount) {
return getResolvedSignatureWorker(node, candidatesOutArray, agumentCount, 16 /* IsForSignatureHelp */);
},
getExpandedParameters: getExpandedParameters,
getConstantValue: function (nodeIn) {
var node = ts.getParseTreeNode(nodeIn, canHaveConstantValue);
return node ? getConstantValue(node) : undefined;
@ -31774,11 +31779,11 @@ var ts;
}
}
function addRelatedInfo(diagnostic) {
var _a;
var relatedInformation = [];
for (var _i = 1; _i < arguments.length; _i++) {
relatedInformation[_i - 1] = arguments[_i];
}
var _a;
if (!diagnostic.relatedInformation) {
diagnostic.relatedInformation = [];
}
@ -37298,8 +37303,18 @@ var ts;
return sig;
}
function cloneSignature(sig) {
return createSignature(sig.declaration, sig.typeParameters, sig.thisParameter, sig.parameters, /*resolvedReturnType*/ undefined,
var result = createSignature(sig.declaration, sig.typeParameters, sig.thisParameter, sig.parameters, /*resolvedReturnType*/ undefined,
/*resolvedTypePredicate*/ undefined, sig.minArgumentCount, sig.hasRestParameter, sig.hasLiteralTypes);
result.target = sig.target;
result.mapper = sig.mapper;
return result;
}
function createUnionSignature(signature, unionSignatures) {
var result = cloneSignature(signature);
result.unionSignatures = unionSignatures;
result.target = undefined;
result.mapper = undefined;
return result;
}
function getExpandedParameters(sig) {
if (sig.hasRestParameter) {
@ -37408,9 +37423,8 @@ var ts;
var thisType = getUnionType(ts.map(unionSignatures, function (sig) { return sig.thisParameter ? getTypeOfSymbol(sig.thisParameter) : anyType; }), 2 /* Subtype */);
thisParameter = createSymbolWithType(signature.thisParameter, thisType);
}
s = cloneSignature(signature);
s = createUnionSignature(signature, unionSignatures);
s.thisParameter = thisParameter;
s.unionSignatures = unionSignatures;
}
(result || (result = [])).push(s);
}
@ -38807,8 +38821,6 @@ var ts;
if (returnSignature) {
var newReturnSignature = cloneSignature(returnSignature);
newReturnSignature.typeParameters = inferredTypeParameters;
newReturnSignature.target = returnSignature.target;
newReturnSignature.mapper = returnSignature.mapper;
var newInstantiatedSignature = cloneSignature(instantiatedSignature);
newInstantiatedSignature.resolvedReturnType = getOrCreateTypeFromSignature(newReturnSignature);
return newInstantiatedSignature;
@ -40421,7 +40433,7 @@ var ts;
// types rules (i.e. proper contravariance) for inferences.
inferTypes(context.inferences, checkType, extendsType, 32 /* NoConstraints */ | 64 /* AlwaysStrict */);
}
combinedMapper = combineTypeMappers(mapper, context);
combinedMapper = combineTypeMappers(mapper, context.mapper);
}
// Instantiate the extends type including inferences for 'infer T' type parameters
var inferredExtendsType = combinedMapper ? instantiateType(root.extendsType, combinedMapper) : extendsType;
@ -40974,33 +40986,8 @@ var ts;
* Maps forward-references to later types parameters to the empty object type.
* This is used during inference when instantiating type parameter defaults.
*/
function createBackreferenceMapper(typeParameters, index) {
return function (t) { return typeParameters.indexOf(t) >= index ? emptyObjectType : t; };
}
function isInferenceContext(mapper) {
return !!mapper.typeParameters;
}
function cloneTypeMapper(mapper, extraFlags) {
if (extraFlags === void 0) { extraFlags = 0; }
return mapper && isInferenceContext(mapper) ?
createInferenceContext(mapper.typeParameters, mapper.signature, mapper.flags | extraFlags, mapper.compareTypes, mapper.inferences) :
mapper;
}
function cloneInferredPartOfContext(context) {
// Filter context to only those parameters which actually have inference candidates
var params = [];
var inferences = [];
for (var i = 0; i < context.typeParameters.length; i++) {
var info = context.inferences[i];
if (info.candidates || info.contraCandidates) {
params.push(context.typeParameters[i]);
inferences.push(info);
}
}
if (!params.length) {
return undefined;
}
return createInferenceContext(params, context.signature, context.flags | 1 /* NoDefault */, context.compareTypes, inferences);
function createBackreferenceMapper(context, index) {
return function (t) { return ts.findIndex(context.inferences, function (info) { return info.typeParameter === t; }) >= index ? emptyObjectType : t; };
}
function combineTypeMappers(mapper1, mapper2) {
if (!mapper1)
@ -41737,7 +41724,7 @@ var ts;
// child is of the type of the expression
return { errorNode: child, innerExpression: child.expression, nameType: nameType };
case 11 /* JsxText */:
if (child.containsOnlyWhiteSpaces) {
if (child.containsOnlyTriviaWhiteSpaces) {
break; // Whitespace only jsx text isn't real jsx text
}
// child is a string
@ -41760,7 +41747,7 @@ var ts;
var childrenPropName = childPropName === undefined ? "children" : ts.unescapeLeadingUnderscores(childPropName);
var childrenNameType = getLiteralType(childrenPropName);
var childrenTargetType = getIndexedAccessType(target, childrenNameType);
var validChildren = ts.filter(containingElement.children, function (i) { return !ts.isJsxText(i) || !i.containsOnlyWhiteSpaces; });
var validChildren = ts.filter(containingElement.children, function (i) { return !ts.isJsxText(i) || !i.containsOnlyTriviaWhiteSpaces; });
if (!ts.length(validChildren)) {
return result;
}
@ -41927,7 +41914,7 @@ var ts;
}
if (source.typeParameters && source.typeParameters !== target.typeParameters) {
target = getCanonicalSignature(target);
source = instantiateSignatureInContextOf(source, target, /*contextualMapper*/ undefined, compareTypes);
source = instantiateSignatureInContextOf(source, target, /*inferenceContext*/ undefined, compareTypes);
}
var sourceCount = getParameterCount(source);
var sourceRestType = getNonArrayRestType(source);
@ -44336,26 +44323,43 @@ var ts;
callback(getRestTypeAtPosition(source, paramCount), targetRestType);
}
}
function createInferenceContext(typeParameters, signature, flags, compareTypes, baseInferences) {
var inferences = baseInferences ? baseInferences.map(cloneInferenceInfo) : typeParameters.map(createInferenceInfo);
var context = mapper;
context.typeParameters = typeParameters;
context.signature = signature;
context.inferences = inferences;
context.flags = flags;
context.compareTypes = compareTypes || compareTypesAssignable;
function createInferenceContext(typeParameters, signature, flags, compareTypes) {
return createInferenceContextWorker(typeParameters.map(createInferenceInfo), signature, flags, compareTypes || compareTypesAssignable);
}
function cloneInferenceContext(context, extraFlags) {
if (extraFlags === void 0) { extraFlags = 0; }
return context && createInferenceContextWorker(ts.map(context.inferences, cloneInferenceInfo), context.signature, context.flags | extraFlags, context.compareTypes);
}
function cloneInferredPartOfContext(context) {
var inferences = ts.filter(context.inferences, hasInferenceCandidates);
return inferences.length ?
createInferenceContextWorker(ts.map(inferences, cloneInferenceInfo), context.signature, context.flags, context.compareTypes) :
undefined;
}
function createInferenceContextWorker(inferences, signature, flags, compareTypes) {
var context = {
inferences: inferences,
signature: signature,
flags: flags,
compareTypes: compareTypes,
mapper: function (t) { return mapToInferredType(context, t, /*fix*/ true); },
nonFixingMapper: function (t) { return mapToInferredType(context, t, /*fix*/ false); },
};
return context;
function mapper(t) {
for (var i = 0; i < inferences.length; i++) {
if (t === inferences[i].typeParameter) {
if (!(context.flags & 4 /* NoFixing */)) {
inferences[i].isFixed = true;
}
return getInferredType(context, i);
}
function mapToInferredType(context, t, fix) {
var inferences = context.inferences;
for (var i = 0; i < inferences.length; i++) {
var inference = inferences[i];
if (t === inference.typeParameter) {
if (fix && !inference.isFixed) {
inference.isFixed = true;
inference.inferredType = undefined;
}
return getInferredType(context, i);
}
return t;
}
return t;
}
function createInferenceInfo(typeParameter) {
return {
@ -44379,6 +44383,9 @@ var ts;
isFixed: inference.isFixed
};
}
function getMapperFromContext(context) {
return context && context.mapper;
}
// Return true if the given type could possibly reference a type parameter for which
// we perform type inference (i.e. a type parameter of a generic function). We cache
// results for union and intersection types for performance reasons.
@ -44626,15 +44633,18 @@ var ts;
var candidate = propagationType || source;
// We make contravariant inferences only if we are in a pure contravariant position,
// i.e. only if we have not descended into a bivariant position.
if (contravariant && !bivariant) {
inference.contraCandidates = ts.appendIfUnique(inference.contraCandidates, candidate);
if (contravariant && !bivariant && !ts.contains(inference.contraCandidates, candidate)) {
inference.contraCandidates = ts.append(inference.contraCandidates, candidate);
inference.inferredType = undefined;
}
else {
inference.candidates = ts.appendIfUnique(inference.candidates, candidate);
else if (!ts.contains(inference.candidates, candidate)) {
inference.candidates = ts.append(inference.candidates, candidate);
inference.inferredType = undefined;
}
}
if (!(priority & 8 /* ReturnType */) && target.flags & 262144 /* TypeParameter */ && !isTypeParameterAtTopLevel(originalTarget, target)) {
if (!(priority & 8 /* ReturnType */) && target.flags & 262144 /* TypeParameter */ && inference.topLevel && !isTypeParameterAtTopLevel(originalTarget, target)) {
inference.topLevel = false;
inference.inferredType = undefined;
}
}
return;
@ -44700,7 +44710,7 @@ var ts;
inferFromTypes(getTrueTypeFromConditionalType(source), getTrueTypeFromConditionalType(target));
inferFromTypes(getFalseTypeFromConditionalType(source), getFalseTypeFromConditionalType(target));
}
else if (target.flags & 16777216 /* Conditional */) {
else if (target.flags & 16777216 /* Conditional */ && !contravariant) {
inferFromTypes(source, getTrueTypeFromConditionalType(target));
inferFromTypes(source, getFalseTypeFromConditionalType(target));
}
@ -45053,7 +45063,7 @@ var ts;
if (defaultType) {
// Instantiate the default type. Any forward reference to a type
// parameter should be instantiated to the empty object type.
inferredType = instantiateType(defaultType, combineTypeMappers(createBackreferenceMapper(context.typeParameters, index), context));
inferredType = instantiateType(defaultType, combineTypeMappers(createBackreferenceMapper(context, index), context.nonFixingMapper));
}
else {
inferredType = getDefaultTypeArgumentType(!!(context.flags & 2 /* AnyDefault */));
@ -45066,12 +45076,10 @@ var ts;
inference.inferredType = inferredType;
var constraint = getConstraintOfTypeParameter(inference.typeParameter);
if (constraint) {
context.flags |= 4 /* NoFixing */;
var instantiatedConstraint = instantiateType(constraint, context);
var instantiatedConstraint = instantiateType(constraint, context.nonFixingMapper);
if (!context.compareTypes(inferredType, getTypeWithThisArgument(instantiatedConstraint, inferredType))) {
inference.inferredType = inferredType = instantiatedConstraint;
}
context.flags &= ~4 /* NoFixing */;
}
}
return inferredType;
@ -47346,7 +47354,7 @@ var ts;
while (type) {
var thisType = getThisTypeFromContextualType(type);
if (thisType) {
return instantiateType(thisType, getContextualMapper(containingLiteral));
return instantiateType(thisType, getMapperFromContext(getInferenceContext(containingLiteral)));
}
if (literal.parent.kind !== 275 /* PropertyAssignment */) {
break;
@ -47795,9 +47803,9 @@ var ts;
// return type inferences is available, instantiate those types using that mapper.
function instantiateContextualType(contextualType, node) {
if (contextualType && maybeTypeOfKind(contextualType, 63176704 /* Instantiable */)) {
var returnMapper = getContextualMapper(node).returnMapper;
if (returnMapper) {
return instantiateInstantiableTypes(contextualType, returnMapper);
var inferenceContext = getInferenceContext(node);
if (inferenceContext && inferenceContext.returnMapper) {
return instantiateInstantiableTypes(contextualType, inferenceContext.returnMapper);
}
}
return contextualType;
@ -47896,9 +47904,9 @@ var ts;
}
return undefined;
}
function getContextualMapper(node) {
var ancestor = ts.findAncestor(node, function (n) { return !!n.contextualMapper; });
return ancestor ? ancestor.contextualMapper : identityMapper;
function getInferenceContext(node) {
var ancestor = ts.findAncestor(node, function (n) { return !!n.inferenceContext; });
return ancestor && ancestor.inferenceContext;
}
function getContextualJsxElementAttributesType(node) {
if (ts.isJsxOpeningElement(node) && node.parent.contextualType) {
@ -48098,12 +48106,7 @@ var ts;
}
}
// Result is union of signatures collected (return type is union of return types of this signature set)
var result;
if (signatureList) {
result = cloneSignature(signatureList[0]);
result.unionSignatures = signatureList;
}
return result;
return signatureList && createUnionSignature(signatureList[0], signatureList);
}
function checkSpreadExpression(node, checkMode) {
if (languageVersion < 2 /* ES2015 */ && compilerOptions.downlevelIteration) {
@ -48621,7 +48624,7 @@ var ts;
// In React, JSX text that contains only whitespaces will be ignored so we don't want to type-check that
// because then type of children property will have constituent of string type.
if (child.kind === 11 /* JsxText */) {
if (!child.containsOnlyWhiteSpaces) {
if (!child.containsOnlyTriviaWhiteSpaces) {
childrenTypes.push(stringType);
}
}
@ -49707,19 +49710,19 @@ var ts;
return undefined;
}
// Instantiate a generic signature in the context of a non-generic signature (section 3.8.5 in TypeScript spec)
function instantiateSignatureInContextOf(signature, contextualSignature, contextualMapper, compareTypes) {
function instantiateSignatureInContextOf(signature, contextualSignature, inferenceContext, compareTypes) {
var context = createInferenceContext(signature.typeParameters, signature, 0 /* None */, compareTypes);
// We clone the contextualMapper to avoid fixing. For example, when the source signature is <T>(x: T) => T[] and
// We clone the inferenceContext to avoid fixing. For example, when the source signature is <T>(x: T) => T[] and
// the contextual signature is (...args: A) => B, we want to infer the element type of A's constraint (say 'any')
// for T but leave it possible to later infer '[any]' back to A.
var restType = getEffectiveRestType(contextualSignature);
var mapper = contextualMapper && restType && restType.flags & 262144 /* TypeParameter */ ? cloneTypeMapper(contextualMapper) : contextualMapper;
var mapper = inferenceContext && (restType && restType.flags & 262144 /* TypeParameter */ ? inferenceContext.nonFixingMapper : inferenceContext.mapper);
var sourceSignature = mapper ? instantiateSignature(contextualSignature, mapper) : contextualSignature;
forEachMatchingParameterType(sourceSignature, signature, function (source, target) {
// Type parameters from outer context referenced by source type are fixed by instantiation of the source type
inferTypes(context.inferences, source, target);
});
if (!contextualMapper) {
if (!inferenceContext) {
inferTypes(context.inferences, getReturnTypeOfSignature(contextualSignature), getReturnTypeOfSignature(signature), 8 /* ReturnType */);
var signaturePredicate = getTypePredicateOfSignature(signature);
var contextualPredicate = getTypePredicateOfSignature(sourceSignature);
@ -49737,17 +49740,6 @@ var ts;
return getInferredTypes(context);
}
function inferTypeArguments(node, signature, args, checkMode, context) {
// Clear out all the inference results from the last time inferTypeArguments was called on this context
for (var _i = 0, _a = context.inferences; _i < _a.length; _i++) {
var inference = _a[_i];
// As an optimization, we don't have to clear (and later recompute) inferred types
// for type parameters that have already been fixed on the previous call to inferTypeArguments.
// It would be just as correct to reset all of them. But then we'd be repeating the same work
// for the type parameters that were fixed, namely the work done by getInferredType.
if (!inference.isFixed) {
inference.inferredType = undefined;
}
}
if (ts.isJsxOpeningLikeElement(node)) {
return inferJsxTypeArguments(node, signature, checkMode, context);
}
@ -49758,10 +49750,11 @@ var ts;
if (node.kind !== 152 /* Decorator */) {
var contextualType = getContextualType(node);
if (contextualType) {
// We clone the contextual mapper to avoid disturbing a resolution in progress for an
// We clone the inference context to avoid disturbing a resolution in progress for an
// outer call expression. Effectively we just want a snapshot of whatever has been
// inferred for any outer call expression so far.
var instantiatedType = instantiateType(contextualType, cloneTypeMapper(getContextualMapper(node), 1 /* NoDefault */));
var outerMapper = getMapperFromContext(cloneInferenceContext(getInferenceContext(node), 1 /* NoDefault */));
var instantiatedType = instantiateType(contextualType, outerMapper);
// If the contextual type is a generic function type with a single call signature, we
// instantiate the type with its own type parameters and type arguments. This ensures that
// the type parameters are not erased to type any during type inference such that they can
@ -49778,7 +49771,7 @@ var ts;
inferTypes(context.inferences, inferenceSourceType, inferenceTargetType, 8 /* ReturnType */);
// Create a type mapper for instantiating generic contextual types using the inferences made
// from the return type.
context.returnMapper = cloneInferredPartOfContext(context);
context.returnMapper = getMapperFromContext(cloneInferredPartOfContext(context));
}
}
var thisType = getThisTypeOfSignature(signature);
@ -49881,7 +49874,7 @@ var ts;
// However "context" and "updater" are implicit and can't be specify by users. Only the first parameter, props,
// can be specified by users through attributes property.
var paramType = getEffectiveFirstArgumentForJsxSignature(signature, node);
var attributesType = checkExpressionWithContextualType(node.attributes, paramType, /*contextualMapper*/ undefined, checkMode);
var attributesType = checkExpressionWithContextualType(node.attributes, paramType, /*inferenceContext*/ undefined, checkMode);
return checkTypeRelatedToAndOptionallyElaborate(attributesType, paramType, relation, reportErrors ? node.tagName : undefined, node.attributes);
}
function checkApplicableSignature(node, args, signature, relation, checkMode, reportErrors) {
@ -49908,7 +49901,7 @@ var ts;
var arg = args[i];
if (arg.kind !== 210 /* OmittedExpression */) {
var paramType = getTypeAtPosition(signature, i);
var argType = checkExpressionWithContextualType(arg, paramType, /*contextualMapper*/ undefined, checkMode);
var argType = checkExpressionWithContextualType(arg, paramType, /*inferenceContext*/ undefined, checkMode);
// If one or more arguments are still excluded (as indicated by CheckMode.SkipContextSensitive),
// we obtain the regular type of any object literal arguments because we may not have inferred complete
// parameter types yet and therefore excess property checks may yield false positives (see #17041).
@ -50264,7 +50257,7 @@ var ts;
else {
inferenceContext = createInferenceContext(candidate.typeParameters, candidate, /*flags*/ ts.isInJSFile(node) ? 2 /* AnyDefault */ : 0 /* None */);
typeArgumentTypes = inferTypeArguments(node, candidate, args, argCheckMode | 8 /* SkipGenericFunctions */, inferenceContext);
argCheckMode |= inferenceContext.flags & 8 /* SkippedGenericFunction */ ? 8 /* SkipGenericFunctions */ : 0 /* Normal */;
argCheckMode |= inferenceContext.flags & 4 /* SkippedGenericFunction */ ? 8 /* SkipGenericFunctions */ : 0 /* Normal */;
}
checkCandidate = getSignatureInstantiation(candidate, typeArgumentTypes, ts.isInJSFile(candidate.declaration), inferenceContext && inferenceContext.inferredTypeParameters);
// If the original signature has a generic rest type, instantiation may produce a
@ -51178,9 +51171,14 @@ var ts;
return getTypeOfParameter(signature.parameters[pos]);
}
if (signature.hasRestParameter) {
// We want to return the value undefined for an out of bounds parameter position,
// so we need to check bounds here before calling getIndexedAccessType (which
// otherwise would return the type 'undefined').
var restType = getTypeOfSymbol(signature.parameters[paramCount]);
var indexType = getLiteralType(pos - paramCount);
return getIndexedAccessType(restType, indexType);
var index = pos - paramCount;
if (!isTupleType(restType) || restType.target.hasRestElement || index < (restType.typeArguments || ts.emptyArray).length) {
return getIndexedAccessType(restType, getLiteralType(index));
}
}
return undefined;
}
@ -51251,14 +51249,14 @@ var ts;
function getTypeOfFirstParameterOfSignatureWithFallback(signature, fallbackType) {
return signature.parameters.length > 0 ? getTypeAtPosition(signature, 0) : fallbackType;
}
function inferFromAnnotatedParameters(signature, context, mapper) {
function inferFromAnnotatedParameters(signature, context, inferenceContext) {
var len = signature.parameters.length - (signature.hasRestParameter ? 1 : 0);
for (var i = 0; i < len; i++) {
var declaration = signature.parameters[i].valueDeclaration;
if (declaration.type) {
var typeNode = ts.getEffectiveTypeAnnotationNode(declaration);
if (typeNode) {
inferTypes(mapper.inferences, getTypeFromTypeNode(typeNode), getTypeAtPosition(context, i));
inferTypes(inferenceContext.inferences, getTypeFromTypeNode(typeNode), getTypeAtPosition(context, i));
}
}
}
@ -51266,12 +51264,12 @@ var ts;
if (restType && restType.flags & 262144 /* TypeParameter */) {
// The contextual signature has a generic rest parameter. We first instantiate the contextual
// signature (without fixing type parameters) and assign types to contextually typed parameters.
var instantiatedContext = instantiateSignature(context, cloneTypeMapper(mapper));
var instantiatedContext = instantiateSignature(context, inferenceContext.nonFixingMapper);
assignContextualParameterTypes(signature, instantiatedContext);
// We then infer from a tuple type representing the parameters that correspond to the contextual
// rest parameter.
var restPos = getParameterCount(context) - 1;
inferTypes(mapper.inferences, getRestTypeAtPosition(signature, restPos), restType);
inferTypes(inferenceContext.inferences, getRestTypeAtPosition(signature, restPos), restType);
}
}
function assignContextualParameterTypes(signature, context) {
@ -51680,12 +51678,12 @@ var ts;
if (contextualSignature) {
var signature = getSignaturesOfType(type, 0 /* Call */)[0];
if (isContextSensitive(node)) {
var contextualMapper = getContextualMapper(node);
var inferenceContext = getInferenceContext(node);
if (checkMode && checkMode & 2 /* Inferential */) {
inferFromAnnotatedParameters(signature, contextualSignature, contextualMapper);
inferFromAnnotatedParameters(signature, contextualSignature, inferenceContext);
}
var instantiatedContextualSignature = contextualMapper === identityMapper ?
contextualSignature : instantiateSignature(contextualSignature, contextualMapper);
var instantiatedContextualSignature = inferenceContext ?
instantiateSignature(contextualSignature, inferenceContext.mapper) : contextualSignature;
assignContextualParameterTypes(signature, instantiatedContextualSignature);
}
if (!getReturnTypeFromAnnotation(node) && !signature.resolvedReturnType) {
@ -52603,20 +52601,20 @@ var ts;
}
return node;
}
function checkExpressionWithContextualType(node, contextualType, contextualMapper, checkMode) {
function checkExpressionWithContextualType(node, contextualType, inferenceContext, checkMode) {
var context = getContextNode(node);
var saveContextualType = context.contextualType;
var saveContextualMapper = context.contextualMapper;
var saveInferenceContext = context.inferenceContext;
context.contextualType = contextualType;
context.contextualMapper = contextualMapper;
var type = checkExpression(node, checkMode | 1 /* Contextual */ | (contextualMapper ? 2 /* Inferential */ : 0));
context.inferenceContext = inferenceContext;
var type = checkExpression(node, checkMode | 1 /* Contextual */ | (inferenceContext ? 2 /* Inferential */ : 0));
// We strip literal freshness when an appropriate contextual type is present such that contextually typed
// literals always preserve their literal types (otherwise they might widen during type inference). An alternative
// here would be to not mark contextually typed literals as fresh in the first place.
var result = maybeTypeOfKind(type, 2944 /* Literal */) && isLiteralOfContextualType(type, instantiateContextualType(contextualType, node)) ?
getRegularTypeOfLiteralType(type) : type;
context.contextualType = saveContextualType;
context.contextualMapper = saveContextualMapper;
context.inferenceContext = saveInferenceContext;
return result;
}
function checkExpressionCached(node, checkMode) {
@ -52730,7 +52728,7 @@ var ts;
if (contextualType) {
var contextualSignature = getSingleCallSignature(getNonNullableType(contextualType));
if (contextualSignature && !contextualSignature.typeParameters) {
var context = getContextualMapper(node);
var context = getInferenceContext(node);
// We have an expression that is an argument of a generic function for which we are performing
// type argument inference. The expression is of a function type with a single generic call
// signature and a contextual function type with a single non-generic call signature. Now check
@ -52746,7 +52744,7 @@ var ts;
var strippedType = getOrCreateTypeFromSignature(getSignatureInstantiationWithoutFillingInTypeArguments(signature, uniqueTypeParameters));
// Infer from the stripped expression type to the contextual type starting with an empty
// set of inference candidates.
var inferences = ts.map(context.typeParameters, createInferenceInfo);
var inferences = ts.map(context.inferences, function (info) { return createInferenceInfo(info.typeParameter); });
inferTypes(inferences, strippedType, contextualType);
// If we produced some inference candidates and if the type parameters for which we produced
// candidates do not already have existing inferences, we adopt the new inference candidates and
@ -52769,8 +52767,8 @@ var ts;
if (checkMode & 2 /* Inferential */) {
// We have skipped a generic function during inferential typing. Obtain the inference context and
// indicate this has occurred such that we know a second pass of inference is be needed.
var context = getContextualMapper(node);
context.flags |= 8 /* SkippedGenericFunction */;
var context = getInferenceContext(node);
context.flags |= 4 /* SkippedGenericFunction */;
}
}
function hasInferenceCandidates(info) {
@ -52878,13 +52876,6 @@ var ts;
node.contextualType = saveContextualType;
return type;
}
// Checks an expression and returns its type. The contextualMapper parameter serves two purposes: When
// contextualMapper is not undefined and not equal to the identityMapper function object it indicates that the
// expression is being inferentially typed (section 4.15.2 in spec) and provides the type mapper to use in
// conjunction with the generic contextual type. When contextualMapper is equal to the identityMapper function
// object, it serves as an indicator that all contained function and arrow expressions should be considered to
// have the wildcard function type; this form of type check is used during overload resolution to exclude
// contextually typed function and arrow expressions in the initial phase.
function checkExpression(node, checkMode, forceTuple) {
var saveCurrentNode = currentNode;
currentNode = node;
@ -62278,6 +62269,28 @@ var ts;
return node;
}
ts.createJsxFragment = createJsxFragment;
function createJsxText(text, containsOnlyTriviaWhiteSpaces) {
var node = createSynthesizedNode(11 /* JsxText */);
node.text = text;
node.containsOnlyTriviaWhiteSpaces = !!containsOnlyTriviaWhiteSpaces;
return node;
}
ts.createJsxText = createJsxText;
function updateJsxText(node, text, containsOnlyTriviaWhiteSpaces) {
return node.text !== text
|| node.containsOnlyTriviaWhiteSpaces !== containsOnlyTriviaWhiteSpaces
? updateNode(createJsxText(text, containsOnlyTriviaWhiteSpaces), node)
: node;
}
ts.updateJsxText = updateJsxText;
function createJsxOpeningFragment() {
return createSynthesizedNode(265 /* JsxOpeningFragment */);
}
ts.createJsxOpeningFragment = createJsxOpeningFragment;
function createJsxJsxClosingFragment() {
return createSynthesizedNode(266 /* JsxClosingFragment */);
}
ts.createJsxJsxClosingFragment = createJsxJsxClosingFragment;
function updateJsxFragment(node, openingFragment, children, closingFragment) {
return node.openingFragment !== openingFragment
|| node.children !== children
@ -71506,7 +71519,7 @@ var ts;
}
}
function visitJsxText(node) {
var fixed = fixupWhitespaceAndDecodeEntities(ts.getTextOfNode(node, /*includeTrivia*/ true));
var fixed = fixupWhitespaceAndDecodeEntities(node.text);
return fixed === undefined ? undefined : ts.createLiteral(fixed);
}
/**
@ -85365,7 +85378,7 @@ var ts;
writePunctuation(">");
}
function emitJsxText(node) {
writer.writeLiteral(getTextOfNode(node, /*includeTrivia*/ true));
writer.writeLiteral(node.text);
}
function emitJsxClosingElementOrFragment(node) {
writePunctuation("</");
@ -92757,7 +92770,7 @@ var ts;
}
}
ts.createCompilerHostFromProgramHost = createCompilerHostFromProgramHost;
function setCreateSourceFileAsHashVersioned(compilerHost, host) {
function setGetSourceFileAsHashVersioned(compilerHost, host) {
var originalGetSourceFile = compilerHost.getSourceFile;
var computeHash = host.createHash || ts.generateDjb2Hash;
compilerHost.getSourceFile = function () {
@ -92772,7 +92785,7 @@ var ts;
return result;
};
}
ts.setCreateSourceFileAsHashVersioned = setCreateSourceFileAsHashVersioned;
ts.setGetSourceFileAsHashVersioned = setGetSourceFileAsHashVersioned;
/**
* Creates the watch compiler host that can be extended with config file or root file names and options host
*/
@ -92920,7 +92933,7 @@ var ts;
configFileWatcher = watchFile(host, configFileName, scheduleProgramReload, ts.PollingInterval.High, "Config file" /* ConfigFile */);
}
var compilerHost = ts.createCompilerHostFromProgramHost(host, function () { return compilerOptions; }, directoryStructureHost);
ts.setCreateSourceFileAsHashVersioned(compilerHost, host);
ts.setGetSourceFileAsHashVersioned(compilerHost, host);
// Members for CompilerHost
var getNewSourceFile = compilerHost.getSourceFile;
compilerHost.getSourceFile = function (fileName) {
@ -93507,7 +93520,7 @@ var ts;
var readFileWithCache = function (f) { return host.readFile(f); };
var projectCompilerOptions = baseCompilerOptions;
var compilerHost = ts.createCompilerHostFromProgramHost(host, function () { return projectCompilerOptions; });
ts.setCreateSourceFileAsHashVersioned(compilerHost, host);
ts.setGetSourceFileAsHashVersioned(compilerHost, host);
var buildInfoChecked = createFileMap(toPath);
// Watch state
var builderPrograms = createFileMap(toPath);
@ -95703,7 +95716,7 @@ var ts;
}
ts.isInsideJsxElementOrAttribute = isInsideJsxElementOrAttribute;
function isWhiteSpaceOnlyJsxText(node) {
return ts.isJsxText(node) && node.containsOnlyWhiteSpaces;
return ts.isJsxText(node) && node.containsOnlyTriviaWhiteSpaces;
}
function isInTemplateString(sourceFile, position) {
var token = getTokenAtPosition(sourceFile, position);
@ -106433,7 +106446,7 @@ var ts;
var parameters = (typeParameters || ts.emptyArray).map(function (t) { return createSignatureHelpParameterForTypeParameter(t, checker, enclosingDeclaration, sourceFile, printer); });
var parameterParts = ts.mapToDisplayParts(function (writer) {
var thisParameter = candidateSignature.thisParameter ? [checker.symbolToParameterDeclaration(candidateSignature.thisParameter, enclosingDeclaration, signatureHelpNodeBuilderFlags)] : [];
var params = ts.createNodeArray(thisParameter.concat(candidateSignature.parameters.map(function (param) { return checker.symbolToParameterDeclaration(param, enclosingDeclaration, signatureHelpNodeBuilderFlags); })));
var params = ts.createNodeArray(thisParameter.concat(checker.getExpandedParameters(candidateSignature).map(function (param) { return checker.symbolToParameterDeclaration(param, enclosingDeclaration, signatureHelpNodeBuilderFlags); })));
printer.writeList(2576 /* CallExpressionArguments */, params, sourceFile, writer);
});
return { isVariadic: false, parameters: parameters, prefix: [ts.punctuationPart(28 /* LessThanToken */)], suffix: [ts.punctuationPart(30 /* GreaterThanToken */)].concat(parameterParts) };
@ -106447,7 +106460,7 @@ var ts;
printer.writeList(53776 /* TypeParameters */, args, sourceFile, writer);
}
});
var parameters = candidateSignature.parameters.map(function (p) { return createSignatureHelpParameterForParameter(p, checker, enclosingDeclaration, sourceFile, printer); });
var parameters = checker.getExpandedParameters(candidateSignature).map(function (p) { return createSignatureHelpParameterForParameter(p, checker, enclosingDeclaration, sourceFile, printer); });
return { isVariadic: isVariadic, parameters: parameters, prefix: typeParameterParts.concat([ts.punctuationPart(20 /* OpenParenToken */)]), suffix: [ts.punctuationPart(21 /* CloseParenToken */)] };
}
function createSignatureHelpParameterForParameter(parameter, checker, enclosingDeclaration, sourceFile, printer) {
@ -120317,9 +120330,9 @@ var ts;
}());
ts.ThrottledCancellationToken = ThrottledCancellationToken;
function createLanguageService(host, documentRegistry, syntaxOnly) {
var _a;
if (documentRegistry === void 0) { documentRegistry = ts.createDocumentRegistry(host.useCaseSensitiveFileNames && host.useCaseSensitiveFileNames(), host.getCurrentDirectory()); }
if (syntaxOnly === void 0) { syntaxOnly = false; }
var _a;
var syntaxTreeCache = new SyntaxTreeCache(host);
var program;
var lastProjectVersion;
@ -128386,8 +128399,8 @@ var ts;
}
var Session = /** @class */ (function () {
function Session(opts) {
var _a;
var _this = this;
var _a;
this.changeSeq = 0;
this.handlers = ts.createMapFromTemplate((_a = {},
_a[server.CommandNames.Status] = function () {

View File

@ -1203,9 +1203,9 @@ declare namespace ts {
dotDotDotToken?: Token<SyntaxKind.DotDotDotToken>;
expression?: Expression;
}
interface JsxText extends Node {
interface JsxText extends LiteralLikeNode {
kind: SyntaxKind.JsxText;
containsOnlyWhiteSpaces: boolean;
containsOnlyTriviaWhiteSpaces: boolean;
parent: JsxElement;
}
type JsxChild = JsxText | JsxExpression | JsxElement | JsxSelfClosingElement | JsxFragment;
@ -3992,6 +3992,10 @@ declare namespace ts {
function createJsxClosingElement(tagName: JsxTagNameExpression): JsxClosingElement;
function updateJsxClosingElement(node: JsxClosingElement, tagName: JsxTagNameExpression): JsxClosingElement;
function createJsxFragment(openingFragment: JsxOpeningFragment, children: ReadonlyArray<JsxChild>, closingFragment: JsxClosingFragment): JsxFragment;
function createJsxText(text: string, containsOnlyTriviaWhiteSpaces?: boolean): JsxText;
function updateJsxText(node: JsxText, text: string, containsOnlyTriviaWhiteSpaces?: boolean): JsxText;
function createJsxOpeningFragment(): JsxOpeningFragment;
function createJsxJsxClosingFragment(): JsxClosingFragment;
function updateJsxFragment(node: JsxFragment, openingFragment: JsxOpeningFragment, children: ReadonlyArray<JsxChild>, closingFragment: JsxClosingFragment): JsxFragment;
function createJsxAttribute(name: Identifier, initializer: StringLiteral | JsxExpression): JsxAttribute;
function updateJsxAttribute(node: JsxAttribute, name: Identifier, initializer: StringLiteral | JsxExpression): JsxAttribute;

View File

@ -84,7 +84,7 @@ var ts;
// If changing the text in this section, be sure to test `configureNightly` too.
ts.versionMajorMinor = "3.4";
/** The version of the TypeScript compiler release */
ts.version = ts.versionMajorMinor + ".0-dev";
ts.version = ts.versionMajorMinor + ".0-rc";
})(ts || (ts = {}));
(function (ts) {
/* @internal */
@ -3584,8 +3584,7 @@ var ts;
InferenceFlags[InferenceFlags["None"] = 0] = "None";
InferenceFlags[InferenceFlags["NoDefault"] = 1] = "NoDefault";
InferenceFlags[InferenceFlags["AnyDefault"] = 2] = "AnyDefault";
InferenceFlags[InferenceFlags["NoFixing"] = 4] = "NoFixing";
InferenceFlags[InferenceFlags["SkippedGenericFunction"] = 8] = "SkippedGenericFunction";
InferenceFlags[InferenceFlags["SkippedGenericFunction"] = 4] = "SkippedGenericFunction";
})(InferenceFlags = ts.InferenceFlags || (ts.InferenceFlags = {}));
/**
* Ternary values are defined such that
@ -4157,8 +4156,11 @@ var ts;
*/
/* @internal */
function generateDjb2Hash(data) {
var chars = data.split("").map(function (str) { return str.charCodeAt(0); });
return "" + chars.reduce(function (prev, curr) { return ((prev << 5) + prev) + curr; }, 5381);
var acc = 5381;
for (var i = 0; i < data.length; i++) {
acc = ((acc << 5) + acc) + data.charCodeAt(i);
}
return acc.toString();
}
ts.generateDjb2Hash = generateDjb2Hash;
/**
@ -8152,6 +8154,7 @@ var ts;
}
pos++;
}
tokenValue = text.substring(startPos, pos);
return firstNonWhitespace === -1 ? 12 /* JsxTextAllWhiteSpaces */ : 11 /* JsxText */;
}
// Scans a JSX identifier; these differ from normal identifiers in that
@ -20271,7 +20274,8 @@ var ts;
}
function parseJsxText() {
var node = createNode(11 /* JsxText */);
node.containsOnlyWhiteSpaces = currentToken === 12 /* JsxTextAllWhiteSpaces */;
node.text = scanner.getTokenValue();
node.containsOnlyTriviaWhiteSpaces = currentToken === 12 /* JsxTextAllWhiteSpaces */;
currentToken = scanner.scanJsxToken();
return finishNode(node);
}
@ -31277,6 +31281,7 @@ var ts;
getResolvedSignatureForSignatureHelp: function (node, candidatesOutArray, agumentCount) {
return getResolvedSignatureWorker(node, candidatesOutArray, agumentCount, 16 /* IsForSignatureHelp */);
},
getExpandedParameters: getExpandedParameters,
getConstantValue: function (nodeIn) {
var node = ts.getParseTreeNode(nodeIn, canHaveConstantValue);
return node ? getConstantValue(node) : undefined;
@ -31773,11 +31778,11 @@ var ts;
}
}
function addRelatedInfo(diagnostic) {
var _a;
var relatedInformation = [];
for (var _i = 1; _i < arguments.length; _i++) {
relatedInformation[_i - 1] = arguments[_i];
}
var _a;
if (!diagnostic.relatedInformation) {
diagnostic.relatedInformation = [];
}
@ -37297,8 +37302,18 @@ var ts;
return sig;
}
function cloneSignature(sig) {
return createSignature(sig.declaration, sig.typeParameters, sig.thisParameter, sig.parameters, /*resolvedReturnType*/ undefined,
var result = createSignature(sig.declaration, sig.typeParameters, sig.thisParameter, sig.parameters, /*resolvedReturnType*/ undefined,
/*resolvedTypePredicate*/ undefined, sig.minArgumentCount, sig.hasRestParameter, sig.hasLiteralTypes);
result.target = sig.target;
result.mapper = sig.mapper;
return result;
}
function createUnionSignature(signature, unionSignatures) {
var result = cloneSignature(signature);
result.unionSignatures = unionSignatures;
result.target = undefined;
result.mapper = undefined;
return result;
}
function getExpandedParameters(sig) {
if (sig.hasRestParameter) {
@ -37407,9 +37422,8 @@ var ts;
var thisType = getUnionType(ts.map(unionSignatures, function (sig) { return sig.thisParameter ? getTypeOfSymbol(sig.thisParameter) : anyType; }), 2 /* Subtype */);
thisParameter = createSymbolWithType(signature.thisParameter, thisType);
}
s = cloneSignature(signature);
s = createUnionSignature(signature, unionSignatures);
s.thisParameter = thisParameter;
s.unionSignatures = unionSignatures;
}
(result || (result = [])).push(s);
}
@ -38806,8 +38820,6 @@ var ts;
if (returnSignature) {
var newReturnSignature = cloneSignature(returnSignature);
newReturnSignature.typeParameters = inferredTypeParameters;
newReturnSignature.target = returnSignature.target;
newReturnSignature.mapper = returnSignature.mapper;
var newInstantiatedSignature = cloneSignature(instantiatedSignature);
newInstantiatedSignature.resolvedReturnType = getOrCreateTypeFromSignature(newReturnSignature);
return newInstantiatedSignature;
@ -40420,7 +40432,7 @@ var ts;
// types rules (i.e. proper contravariance) for inferences.
inferTypes(context.inferences, checkType, extendsType, 32 /* NoConstraints */ | 64 /* AlwaysStrict */);
}
combinedMapper = combineTypeMappers(mapper, context);
combinedMapper = combineTypeMappers(mapper, context.mapper);
}
// Instantiate the extends type including inferences for 'infer T' type parameters
var inferredExtendsType = combinedMapper ? instantiateType(root.extendsType, combinedMapper) : extendsType;
@ -40973,33 +40985,8 @@ var ts;
* Maps forward-references to later types parameters to the empty object type.
* This is used during inference when instantiating type parameter defaults.
*/
function createBackreferenceMapper(typeParameters, index) {
return function (t) { return typeParameters.indexOf(t) >= index ? emptyObjectType : t; };
}
function isInferenceContext(mapper) {
return !!mapper.typeParameters;
}
function cloneTypeMapper(mapper, extraFlags) {
if (extraFlags === void 0) { extraFlags = 0; }
return mapper && isInferenceContext(mapper) ?
createInferenceContext(mapper.typeParameters, mapper.signature, mapper.flags | extraFlags, mapper.compareTypes, mapper.inferences) :
mapper;
}
function cloneInferredPartOfContext(context) {
// Filter context to only those parameters which actually have inference candidates
var params = [];
var inferences = [];
for (var i = 0; i < context.typeParameters.length; i++) {
var info = context.inferences[i];
if (info.candidates || info.contraCandidates) {
params.push(context.typeParameters[i]);
inferences.push(info);
}
}
if (!params.length) {
return undefined;
}
return createInferenceContext(params, context.signature, context.flags | 1 /* NoDefault */, context.compareTypes, inferences);
function createBackreferenceMapper(context, index) {
return function (t) { return ts.findIndex(context.inferences, function (info) { return info.typeParameter === t; }) >= index ? emptyObjectType : t; };
}
function combineTypeMappers(mapper1, mapper2) {
if (!mapper1)
@ -41736,7 +41723,7 @@ var ts;
// child is of the type of the expression
return { errorNode: child, innerExpression: child.expression, nameType: nameType };
case 11 /* JsxText */:
if (child.containsOnlyWhiteSpaces) {
if (child.containsOnlyTriviaWhiteSpaces) {
break; // Whitespace only jsx text isn't real jsx text
}
// child is a string
@ -41759,7 +41746,7 @@ var ts;
var childrenPropName = childPropName === undefined ? "children" : ts.unescapeLeadingUnderscores(childPropName);
var childrenNameType = getLiteralType(childrenPropName);
var childrenTargetType = getIndexedAccessType(target, childrenNameType);
var validChildren = ts.filter(containingElement.children, function (i) { return !ts.isJsxText(i) || !i.containsOnlyWhiteSpaces; });
var validChildren = ts.filter(containingElement.children, function (i) { return !ts.isJsxText(i) || !i.containsOnlyTriviaWhiteSpaces; });
if (!ts.length(validChildren)) {
return result;
}
@ -41926,7 +41913,7 @@ var ts;
}
if (source.typeParameters && source.typeParameters !== target.typeParameters) {
target = getCanonicalSignature(target);
source = instantiateSignatureInContextOf(source, target, /*contextualMapper*/ undefined, compareTypes);
source = instantiateSignatureInContextOf(source, target, /*inferenceContext*/ undefined, compareTypes);
}
var sourceCount = getParameterCount(source);
var sourceRestType = getNonArrayRestType(source);
@ -44335,26 +44322,43 @@ var ts;
callback(getRestTypeAtPosition(source, paramCount), targetRestType);
}
}
function createInferenceContext(typeParameters, signature, flags, compareTypes, baseInferences) {
var inferences = baseInferences ? baseInferences.map(cloneInferenceInfo) : typeParameters.map(createInferenceInfo);
var context = mapper;
context.typeParameters = typeParameters;
context.signature = signature;
context.inferences = inferences;
context.flags = flags;
context.compareTypes = compareTypes || compareTypesAssignable;
function createInferenceContext(typeParameters, signature, flags, compareTypes) {
return createInferenceContextWorker(typeParameters.map(createInferenceInfo), signature, flags, compareTypes || compareTypesAssignable);
}
function cloneInferenceContext(context, extraFlags) {
if (extraFlags === void 0) { extraFlags = 0; }
return context && createInferenceContextWorker(ts.map(context.inferences, cloneInferenceInfo), context.signature, context.flags | extraFlags, context.compareTypes);
}
function cloneInferredPartOfContext(context) {
var inferences = ts.filter(context.inferences, hasInferenceCandidates);
return inferences.length ?
createInferenceContextWorker(ts.map(inferences, cloneInferenceInfo), context.signature, context.flags, context.compareTypes) :
undefined;
}
function createInferenceContextWorker(inferences, signature, flags, compareTypes) {
var context = {
inferences: inferences,
signature: signature,
flags: flags,
compareTypes: compareTypes,
mapper: function (t) { return mapToInferredType(context, t, /*fix*/ true); },
nonFixingMapper: function (t) { return mapToInferredType(context, t, /*fix*/ false); },
};
return context;
function mapper(t) {
for (var i = 0; i < inferences.length; i++) {
if (t === inferences[i].typeParameter) {
if (!(context.flags & 4 /* NoFixing */)) {
inferences[i].isFixed = true;
}
return getInferredType(context, i);
}
function mapToInferredType(context, t, fix) {
var inferences = context.inferences;
for (var i = 0; i < inferences.length; i++) {
var inference = inferences[i];
if (t === inference.typeParameter) {
if (fix && !inference.isFixed) {
inference.isFixed = true;
inference.inferredType = undefined;
}
return getInferredType(context, i);
}
return t;
}
return t;
}
function createInferenceInfo(typeParameter) {
return {
@ -44378,6 +44382,9 @@ var ts;
isFixed: inference.isFixed
};
}
function getMapperFromContext(context) {
return context && context.mapper;
}
// Return true if the given type could possibly reference a type parameter for which
// we perform type inference (i.e. a type parameter of a generic function). We cache
// results for union and intersection types for performance reasons.
@ -44625,15 +44632,18 @@ var ts;
var candidate = propagationType || source;
// We make contravariant inferences only if we are in a pure contravariant position,
// i.e. only if we have not descended into a bivariant position.
if (contravariant && !bivariant) {
inference.contraCandidates = ts.appendIfUnique(inference.contraCandidates, candidate);
if (contravariant && !bivariant && !ts.contains(inference.contraCandidates, candidate)) {
inference.contraCandidates = ts.append(inference.contraCandidates, candidate);
inference.inferredType = undefined;
}
else {
inference.candidates = ts.appendIfUnique(inference.candidates, candidate);
else if (!ts.contains(inference.candidates, candidate)) {
inference.candidates = ts.append(inference.candidates, candidate);
inference.inferredType = undefined;
}
}
if (!(priority & 8 /* ReturnType */) && target.flags & 262144 /* TypeParameter */ && !isTypeParameterAtTopLevel(originalTarget, target)) {
if (!(priority & 8 /* ReturnType */) && target.flags & 262144 /* TypeParameter */ && inference.topLevel && !isTypeParameterAtTopLevel(originalTarget, target)) {
inference.topLevel = false;
inference.inferredType = undefined;
}
}
return;
@ -44699,7 +44709,7 @@ var ts;
inferFromTypes(getTrueTypeFromConditionalType(source), getTrueTypeFromConditionalType(target));
inferFromTypes(getFalseTypeFromConditionalType(source), getFalseTypeFromConditionalType(target));
}
else if (target.flags & 16777216 /* Conditional */) {
else if (target.flags & 16777216 /* Conditional */ && !contravariant) {
inferFromTypes(source, getTrueTypeFromConditionalType(target));
inferFromTypes(source, getFalseTypeFromConditionalType(target));
}
@ -45052,7 +45062,7 @@ var ts;
if (defaultType) {
// Instantiate the default type. Any forward reference to a type
// parameter should be instantiated to the empty object type.
inferredType = instantiateType(defaultType, combineTypeMappers(createBackreferenceMapper(context.typeParameters, index), context));
inferredType = instantiateType(defaultType, combineTypeMappers(createBackreferenceMapper(context, index), context.nonFixingMapper));
}
else {
inferredType = getDefaultTypeArgumentType(!!(context.flags & 2 /* AnyDefault */));
@ -45065,12 +45075,10 @@ var ts;
inference.inferredType = inferredType;
var constraint = getConstraintOfTypeParameter(inference.typeParameter);
if (constraint) {
context.flags |= 4 /* NoFixing */;
var instantiatedConstraint = instantiateType(constraint, context);
var instantiatedConstraint = instantiateType(constraint, context.nonFixingMapper);
if (!context.compareTypes(inferredType, getTypeWithThisArgument(instantiatedConstraint, inferredType))) {
inference.inferredType = inferredType = instantiatedConstraint;
}
context.flags &= ~4 /* NoFixing */;
}
}
return inferredType;
@ -47345,7 +47353,7 @@ var ts;
while (type) {
var thisType = getThisTypeFromContextualType(type);
if (thisType) {
return instantiateType(thisType, getContextualMapper(containingLiteral));
return instantiateType(thisType, getMapperFromContext(getInferenceContext(containingLiteral)));
}
if (literal.parent.kind !== 275 /* PropertyAssignment */) {
break;
@ -47794,9 +47802,9 @@ var ts;
// return type inferences is available, instantiate those types using that mapper.
function instantiateContextualType(contextualType, node) {
if (contextualType && maybeTypeOfKind(contextualType, 63176704 /* Instantiable */)) {
var returnMapper = getContextualMapper(node).returnMapper;
if (returnMapper) {
return instantiateInstantiableTypes(contextualType, returnMapper);
var inferenceContext = getInferenceContext(node);
if (inferenceContext && inferenceContext.returnMapper) {
return instantiateInstantiableTypes(contextualType, inferenceContext.returnMapper);
}
}
return contextualType;
@ -47895,9 +47903,9 @@ var ts;
}
return undefined;
}
function getContextualMapper(node) {
var ancestor = ts.findAncestor(node, function (n) { return !!n.contextualMapper; });
return ancestor ? ancestor.contextualMapper : identityMapper;
function getInferenceContext(node) {
var ancestor = ts.findAncestor(node, function (n) { return !!n.inferenceContext; });
return ancestor && ancestor.inferenceContext;
}
function getContextualJsxElementAttributesType(node) {
if (ts.isJsxOpeningElement(node) && node.parent.contextualType) {
@ -48097,12 +48105,7 @@ var ts;
}
}
// Result is union of signatures collected (return type is union of return types of this signature set)
var result;
if (signatureList) {
result = cloneSignature(signatureList[0]);
result.unionSignatures = signatureList;
}
return result;
return signatureList && createUnionSignature(signatureList[0], signatureList);
}
function checkSpreadExpression(node, checkMode) {
if (languageVersion < 2 /* ES2015 */ && compilerOptions.downlevelIteration) {
@ -48620,7 +48623,7 @@ var ts;
// In React, JSX text that contains only whitespaces will be ignored so we don't want to type-check that
// because then type of children property will have constituent of string type.
if (child.kind === 11 /* JsxText */) {
if (!child.containsOnlyWhiteSpaces) {
if (!child.containsOnlyTriviaWhiteSpaces) {
childrenTypes.push(stringType);
}
}
@ -49706,19 +49709,19 @@ var ts;
return undefined;
}
// Instantiate a generic signature in the context of a non-generic signature (section 3.8.5 in TypeScript spec)
function instantiateSignatureInContextOf(signature, contextualSignature, contextualMapper, compareTypes) {
function instantiateSignatureInContextOf(signature, contextualSignature, inferenceContext, compareTypes) {
var context = createInferenceContext(signature.typeParameters, signature, 0 /* None */, compareTypes);
// We clone the contextualMapper to avoid fixing. For example, when the source signature is <T>(x: T) => T[] and
// We clone the inferenceContext to avoid fixing. For example, when the source signature is <T>(x: T) => T[] and
// the contextual signature is (...args: A) => B, we want to infer the element type of A's constraint (say 'any')
// for T but leave it possible to later infer '[any]' back to A.
var restType = getEffectiveRestType(contextualSignature);
var mapper = contextualMapper && restType && restType.flags & 262144 /* TypeParameter */ ? cloneTypeMapper(contextualMapper) : contextualMapper;
var mapper = inferenceContext && (restType && restType.flags & 262144 /* TypeParameter */ ? inferenceContext.nonFixingMapper : inferenceContext.mapper);
var sourceSignature = mapper ? instantiateSignature(contextualSignature, mapper) : contextualSignature;
forEachMatchingParameterType(sourceSignature, signature, function (source, target) {
// Type parameters from outer context referenced by source type are fixed by instantiation of the source type
inferTypes(context.inferences, source, target);
});
if (!contextualMapper) {
if (!inferenceContext) {
inferTypes(context.inferences, getReturnTypeOfSignature(contextualSignature), getReturnTypeOfSignature(signature), 8 /* ReturnType */);
var signaturePredicate = getTypePredicateOfSignature(signature);
var contextualPredicate = getTypePredicateOfSignature(sourceSignature);
@ -49736,17 +49739,6 @@ var ts;
return getInferredTypes(context);
}
function inferTypeArguments(node, signature, args, checkMode, context) {
// Clear out all the inference results from the last time inferTypeArguments was called on this context
for (var _i = 0, _a = context.inferences; _i < _a.length; _i++) {
var inference = _a[_i];
// As an optimization, we don't have to clear (and later recompute) inferred types
// for type parameters that have already been fixed on the previous call to inferTypeArguments.
// It would be just as correct to reset all of them. But then we'd be repeating the same work
// for the type parameters that were fixed, namely the work done by getInferredType.
if (!inference.isFixed) {
inference.inferredType = undefined;
}
}
if (ts.isJsxOpeningLikeElement(node)) {
return inferJsxTypeArguments(node, signature, checkMode, context);
}
@ -49757,10 +49749,11 @@ var ts;
if (node.kind !== 152 /* Decorator */) {
var contextualType = getContextualType(node);
if (contextualType) {
// We clone the contextual mapper to avoid disturbing a resolution in progress for an
// We clone the inference context to avoid disturbing a resolution in progress for an
// outer call expression. Effectively we just want a snapshot of whatever has been
// inferred for any outer call expression so far.
var instantiatedType = instantiateType(contextualType, cloneTypeMapper(getContextualMapper(node), 1 /* NoDefault */));
var outerMapper = getMapperFromContext(cloneInferenceContext(getInferenceContext(node), 1 /* NoDefault */));
var instantiatedType = instantiateType(contextualType, outerMapper);
// If the contextual type is a generic function type with a single call signature, we
// instantiate the type with its own type parameters and type arguments. This ensures that
// the type parameters are not erased to type any during type inference such that they can
@ -49777,7 +49770,7 @@ var ts;
inferTypes(context.inferences, inferenceSourceType, inferenceTargetType, 8 /* ReturnType */);
// Create a type mapper for instantiating generic contextual types using the inferences made
// from the return type.
context.returnMapper = cloneInferredPartOfContext(context);
context.returnMapper = getMapperFromContext(cloneInferredPartOfContext(context));
}
}
var thisType = getThisTypeOfSignature(signature);
@ -49880,7 +49873,7 @@ var ts;
// However "context" and "updater" are implicit and can't be specify by users. Only the first parameter, props,
// can be specified by users through attributes property.
var paramType = getEffectiveFirstArgumentForJsxSignature(signature, node);
var attributesType = checkExpressionWithContextualType(node.attributes, paramType, /*contextualMapper*/ undefined, checkMode);
var attributesType = checkExpressionWithContextualType(node.attributes, paramType, /*inferenceContext*/ undefined, checkMode);
return checkTypeRelatedToAndOptionallyElaborate(attributesType, paramType, relation, reportErrors ? node.tagName : undefined, node.attributes);
}
function checkApplicableSignature(node, args, signature, relation, checkMode, reportErrors) {
@ -49907,7 +49900,7 @@ var ts;
var arg = args[i];
if (arg.kind !== 210 /* OmittedExpression */) {
var paramType = getTypeAtPosition(signature, i);
var argType = checkExpressionWithContextualType(arg, paramType, /*contextualMapper*/ undefined, checkMode);
var argType = checkExpressionWithContextualType(arg, paramType, /*inferenceContext*/ undefined, checkMode);
// If one or more arguments are still excluded (as indicated by CheckMode.SkipContextSensitive),
// we obtain the regular type of any object literal arguments because we may not have inferred complete
// parameter types yet and therefore excess property checks may yield false positives (see #17041).
@ -50263,7 +50256,7 @@ var ts;
else {
inferenceContext = createInferenceContext(candidate.typeParameters, candidate, /*flags*/ ts.isInJSFile(node) ? 2 /* AnyDefault */ : 0 /* None */);
typeArgumentTypes = inferTypeArguments(node, candidate, args, argCheckMode | 8 /* SkipGenericFunctions */, inferenceContext);
argCheckMode |= inferenceContext.flags & 8 /* SkippedGenericFunction */ ? 8 /* SkipGenericFunctions */ : 0 /* Normal */;
argCheckMode |= inferenceContext.flags & 4 /* SkippedGenericFunction */ ? 8 /* SkipGenericFunctions */ : 0 /* Normal */;
}
checkCandidate = getSignatureInstantiation(candidate, typeArgumentTypes, ts.isInJSFile(candidate.declaration), inferenceContext && inferenceContext.inferredTypeParameters);
// If the original signature has a generic rest type, instantiation may produce a
@ -51177,9 +51170,14 @@ var ts;
return getTypeOfParameter(signature.parameters[pos]);
}
if (signature.hasRestParameter) {
// We want to return the value undefined for an out of bounds parameter position,
// so we need to check bounds here before calling getIndexedAccessType (which
// otherwise would return the type 'undefined').
var restType = getTypeOfSymbol(signature.parameters[paramCount]);
var indexType = getLiteralType(pos - paramCount);
return getIndexedAccessType(restType, indexType);
var index = pos - paramCount;
if (!isTupleType(restType) || restType.target.hasRestElement || index < (restType.typeArguments || ts.emptyArray).length) {
return getIndexedAccessType(restType, getLiteralType(index));
}
}
return undefined;
}
@ -51250,14 +51248,14 @@ var ts;
function getTypeOfFirstParameterOfSignatureWithFallback(signature, fallbackType) {
return signature.parameters.length > 0 ? getTypeAtPosition(signature, 0) : fallbackType;
}
function inferFromAnnotatedParameters(signature, context, mapper) {
function inferFromAnnotatedParameters(signature, context, inferenceContext) {
var len = signature.parameters.length - (signature.hasRestParameter ? 1 : 0);
for (var i = 0; i < len; i++) {
var declaration = signature.parameters[i].valueDeclaration;
if (declaration.type) {
var typeNode = ts.getEffectiveTypeAnnotationNode(declaration);
if (typeNode) {
inferTypes(mapper.inferences, getTypeFromTypeNode(typeNode), getTypeAtPosition(context, i));
inferTypes(inferenceContext.inferences, getTypeFromTypeNode(typeNode), getTypeAtPosition(context, i));
}
}
}
@ -51265,12 +51263,12 @@ var ts;
if (restType && restType.flags & 262144 /* TypeParameter */) {
// The contextual signature has a generic rest parameter. We first instantiate the contextual
// signature (without fixing type parameters) and assign types to contextually typed parameters.
var instantiatedContext = instantiateSignature(context, cloneTypeMapper(mapper));
var instantiatedContext = instantiateSignature(context, inferenceContext.nonFixingMapper);
assignContextualParameterTypes(signature, instantiatedContext);
// We then infer from a tuple type representing the parameters that correspond to the contextual
// rest parameter.
var restPos = getParameterCount(context) - 1;
inferTypes(mapper.inferences, getRestTypeAtPosition(signature, restPos), restType);
inferTypes(inferenceContext.inferences, getRestTypeAtPosition(signature, restPos), restType);
}
}
function assignContextualParameterTypes(signature, context) {
@ -51679,12 +51677,12 @@ var ts;
if (contextualSignature) {
var signature = getSignaturesOfType(type, 0 /* Call */)[0];
if (isContextSensitive(node)) {
var contextualMapper = getContextualMapper(node);
var inferenceContext = getInferenceContext(node);
if (checkMode && checkMode & 2 /* Inferential */) {
inferFromAnnotatedParameters(signature, contextualSignature, contextualMapper);
inferFromAnnotatedParameters(signature, contextualSignature, inferenceContext);
}
var instantiatedContextualSignature = contextualMapper === identityMapper ?
contextualSignature : instantiateSignature(contextualSignature, contextualMapper);
var instantiatedContextualSignature = inferenceContext ?
instantiateSignature(contextualSignature, inferenceContext.mapper) : contextualSignature;
assignContextualParameterTypes(signature, instantiatedContextualSignature);
}
if (!getReturnTypeFromAnnotation(node) && !signature.resolvedReturnType) {
@ -52602,20 +52600,20 @@ var ts;
}
return node;
}
function checkExpressionWithContextualType(node, contextualType, contextualMapper, checkMode) {
function checkExpressionWithContextualType(node, contextualType, inferenceContext, checkMode) {
var context = getContextNode(node);
var saveContextualType = context.contextualType;
var saveContextualMapper = context.contextualMapper;
var saveInferenceContext = context.inferenceContext;
context.contextualType = contextualType;
context.contextualMapper = contextualMapper;
var type = checkExpression(node, checkMode | 1 /* Contextual */ | (contextualMapper ? 2 /* Inferential */ : 0));
context.inferenceContext = inferenceContext;
var type = checkExpression(node, checkMode | 1 /* Contextual */ | (inferenceContext ? 2 /* Inferential */ : 0));
// We strip literal freshness when an appropriate contextual type is present such that contextually typed
// literals always preserve their literal types (otherwise they might widen during type inference). An alternative
// here would be to not mark contextually typed literals as fresh in the first place.
var result = maybeTypeOfKind(type, 2944 /* Literal */) && isLiteralOfContextualType(type, instantiateContextualType(contextualType, node)) ?
getRegularTypeOfLiteralType(type) : type;
context.contextualType = saveContextualType;
context.contextualMapper = saveContextualMapper;
context.inferenceContext = saveInferenceContext;
return result;
}
function checkExpressionCached(node, checkMode) {
@ -52729,7 +52727,7 @@ var ts;
if (contextualType) {
var contextualSignature = getSingleCallSignature(getNonNullableType(contextualType));
if (contextualSignature && !contextualSignature.typeParameters) {
var context = getContextualMapper(node);
var context = getInferenceContext(node);
// We have an expression that is an argument of a generic function for which we are performing
// type argument inference. The expression is of a function type with a single generic call
// signature and a contextual function type with a single non-generic call signature. Now check
@ -52745,7 +52743,7 @@ var ts;
var strippedType = getOrCreateTypeFromSignature(getSignatureInstantiationWithoutFillingInTypeArguments(signature, uniqueTypeParameters));
// Infer from the stripped expression type to the contextual type starting with an empty
// set of inference candidates.
var inferences = ts.map(context.typeParameters, createInferenceInfo);
var inferences = ts.map(context.inferences, function (info) { return createInferenceInfo(info.typeParameter); });
inferTypes(inferences, strippedType, contextualType);
// If we produced some inference candidates and if the type parameters for which we produced
// candidates do not already have existing inferences, we adopt the new inference candidates and
@ -52768,8 +52766,8 @@ var ts;
if (checkMode & 2 /* Inferential */) {
// We have skipped a generic function during inferential typing. Obtain the inference context and
// indicate this has occurred such that we know a second pass of inference is be needed.
var context = getContextualMapper(node);
context.flags |= 8 /* SkippedGenericFunction */;
var context = getInferenceContext(node);
context.flags |= 4 /* SkippedGenericFunction */;
}
}
function hasInferenceCandidates(info) {
@ -52877,13 +52875,6 @@ var ts;
node.contextualType = saveContextualType;
return type;
}
// Checks an expression and returns its type. The contextualMapper parameter serves two purposes: When
// contextualMapper is not undefined and not equal to the identityMapper function object it indicates that the
// expression is being inferentially typed (section 4.15.2 in spec) and provides the type mapper to use in
// conjunction with the generic contextual type. When contextualMapper is equal to the identityMapper function
// object, it serves as an indicator that all contained function and arrow expressions should be considered to
// have the wildcard function type; this form of type check is used during overload resolution to exclude
// contextually typed function and arrow expressions in the initial phase.
function checkExpression(node, checkMode, forceTuple) {
var saveCurrentNode = currentNode;
currentNode = node;
@ -62277,6 +62268,28 @@ var ts;
return node;
}
ts.createJsxFragment = createJsxFragment;
function createJsxText(text, containsOnlyTriviaWhiteSpaces) {
var node = createSynthesizedNode(11 /* JsxText */);
node.text = text;
node.containsOnlyTriviaWhiteSpaces = !!containsOnlyTriviaWhiteSpaces;
return node;
}
ts.createJsxText = createJsxText;
function updateJsxText(node, text, containsOnlyTriviaWhiteSpaces) {
return node.text !== text
|| node.containsOnlyTriviaWhiteSpaces !== containsOnlyTriviaWhiteSpaces
? updateNode(createJsxText(text, containsOnlyTriviaWhiteSpaces), node)
: node;
}
ts.updateJsxText = updateJsxText;
function createJsxOpeningFragment() {
return createSynthesizedNode(265 /* JsxOpeningFragment */);
}
ts.createJsxOpeningFragment = createJsxOpeningFragment;
function createJsxJsxClosingFragment() {
return createSynthesizedNode(266 /* JsxClosingFragment */);
}
ts.createJsxJsxClosingFragment = createJsxJsxClosingFragment;
function updateJsxFragment(node, openingFragment, children, closingFragment) {
return node.openingFragment !== openingFragment
|| node.children !== children
@ -71505,7 +71518,7 @@ var ts;
}
}
function visitJsxText(node) {
var fixed = fixupWhitespaceAndDecodeEntities(ts.getTextOfNode(node, /*includeTrivia*/ true));
var fixed = fixupWhitespaceAndDecodeEntities(node.text);
return fixed === undefined ? undefined : ts.createLiteral(fixed);
}
/**
@ -85364,7 +85377,7 @@ var ts;
writePunctuation(">");
}
function emitJsxText(node) {
writer.writeLiteral(getTextOfNode(node, /*includeTrivia*/ true));
writer.writeLiteral(node.text);
}
function emitJsxClosingElementOrFragment(node) {
writePunctuation("</");
@ -92756,7 +92769,7 @@ var ts;
}
}
ts.createCompilerHostFromProgramHost = createCompilerHostFromProgramHost;
function setCreateSourceFileAsHashVersioned(compilerHost, host) {
function setGetSourceFileAsHashVersioned(compilerHost, host) {
var originalGetSourceFile = compilerHost.getSourceFile;
var computeHash = host.createHash || ts.generateDjb2Hash;
compilerHost.getSourceFile = function () {
@ -92771,7 +92784,7 @@ var ts;
return result;
};
}
ts.setCreateSourceFileAsHashVersioned = setCreateSourceFileAsHashVersioned;
ts.setGetSourceFileAsHashVersioned = setGetSourceFileAsHashVersioned;
/**
* Creates the watch compiler host that can be extended with config file or root file names and options host
*/
@ -92919,7 +92932,7 @@ var ts;
configFileWatcher = watchFile(host, configFileName, scheduleProgramReload, ts.PollingInterval.High, "Config file" /* ConfigFile */);
}
var compilerHost = ts.createCompilerHostFromProgramHost(host, function () { return compilerOptions; }, directoryStructureHost);
ts.setCreateSourceFileAsHashVersioned(compilerHost, host);
ts.setGetSourceFileAsHashVersioned(compilerHost, host);
// Members for CompilerHost
var getNewSourceFile = compilerHost.getSourceFile;
compilerHost.getSourceFile = function (fileName) {
@ -93506,7 +93519,7 @@ var ts;
var readFileWithCache = function (f) { return host.readFile(f); };
var projectCompilerOptions = baseCompilerOptions;
var compilerHost = ts.createCompilerHostFromProgramHost(host, function () { return projectCompilerOptions; });
ts.setCreateSourceFileAsHashVersioned(compilerHost, host);
ts.setGetSourceFileAsHashVersioned(compilerHost, host);
var buildInfoChecked = createFileMap(toPath);
// Watch state
var builderPrograms = createFileMap(toPath);
@ -96042,7 +96055,7 @@ var ts;
}
ts.isInsideJsxElementOrAttribute = isInsideJsxElementOrAttribute;
function isWhiteSpaceOnlyJsxText(node) {
return ts.isJsxText(node) && node.containsOnlyWhiteSpaces;
return ts.isJsxText(node) && node.containsOnlyTriviaWhiteSpaces;
}
function isInTemplateString(sourceFile, position) {
var token = getTokenAtPosition(sourceFile, position);
@ -106772,7 +106785,7 @@ var ts;
var parameters = (typeParameters || ts.emptyArray).map(function (t) { return createSignatureHelpParameterForTypeParameter(t, checker, enclosingDeclaration, sourceFile, printer); });
var parameterParts = ts.mapToDisplayParts(function (writer) {
var thisParameter = candidateSignature.thisParameter ? [checker.symbolToParameterDeclaration(candidateSignature.thisParameter, enclosingDeclaration, signatureHelpNodeBuilderFlags)] : [];
var params = ts.createNodeArray(thisParameter.concat(candidateSignature.parameters.map(function (param) { return checker.symbolToParameterDeclaration(param, enclosingDeclaration, signatureHelpNodeBuilderFlags); })));
var params = ts.createNodeArray(thisParameter.concat(checker.getExpandedParameters(candidateSignature).map(function (param) { return checker.symbolToParameterDeclaration(param, enclosingDeclaration, signatureHelpNodeBuilderFlags); })));
printer.writeList(2576 /* CallExpressionArguments */, params, sourceFile, writer);
});
return { isVariadic: false, parameters: parameters, prefix: [ts.punctuationPart(28 /* LessThanToken */)], suffix: [ts.punctuationPart(30 /* GreaterThanToken */)].concat(parameterParts) };
@ -106786,7 +106799,7 @@ var ts;
printer.writeList(53776 /* TypeParameters */, args, sourceFile, writer);
}
});
var parameters = candidateSignature.parameters.map(function (p) { return createSignatureHelpParameterForParameter(p, checker, enclosingDeclaration, sourceFile, printer); });
var parameters = checker.getExpandedParameters(candidateSignature).map(function (p) { return createSignatureHelpParameterForParameter(p, checker, enclosingDeclaration, sourceFile, printer); });
return { isVariadic: isVariadic, parameters: parameters, prefix: typeParameterParts.concat([ts.punctuationPart(20 /* OpenParenToken */)]), suffix: [ts.punctuationPart(21 /* CloseParenToken */)] };
}
function createSignatureHelpParameterForParameter(parameter, checker, enclosingDeclaration, sourceFile, printer) {
@ -120656,9 +120669,9 @@ var ts;
}());
ts.ThrottledCancellationToken = ThrottledCancellationToken;
function createLanguageService(host, documentRegistry, syntaxOnly) {
var _a;
if (documentRegistry === void 0) { documentRegistry = ts.createDocumentRegistry(host.useCaseSensitiveFileNames && host.useCaseSensitiveFileNames(), host.getCurrentDirectory()); }
if (syntaxOnly === void 0) { syntaxOnly = false; }
var _a;
var syntaxTreeCache = new SyntaxTreeCache(host);
var program;
var lastProjectVersion;
@ -128385,8 +128398,8 @@ var ts;
}
var Session = /** @class */ (function () {
function Session(opts) {
var _a;
var _this = this;
var _a;
this.changeSeq = 0;
this.handlers = ts.createMapFromTemplate((_a = {},
_a[server.CommandNames.Status] = function () {

8
lib/typescript.d.ts vendored
View File

@ -1203,9 +1203,9 @@ declare namespace ts {
dotDotDotToken?: Token<SyntaxKind.DotDotDotToken>;
expression?: Expression;
}
interface JsxText extends Node {
interface JsxText extends LiteralLikeNode {
kind: SyntaxKind.JsxText;
containsOnlyWhiteSpaces: boolean;
containsOnlyTriviaWhiteSpaces: boolean;
parent: JsxElement;
}
type JsxChild = JsxText | JsxExpression | JsxElement | JsxSelfClosingElement | JsxFragment;
@ -3992,6 +3992,10 @@ declare namespace ts {
function createJsxClosingElement(tagName: JsxTagNameExpression): JsxClosingElement;
function updateJsxClosingElement(node: JsxClosingElement, tagName: JsxTagNameExpression): JsxClosingElement;
function createJsxFragment(openingFragment: JsxOpeningFragment, children: ReadonlyArray<JsxChild>, closingFragment: JsxClosingFragment): JsxFragment;
function createJsxText(text: string, containsOnlyTriviaWhiteSpaces?: boolean): JsxText;
function updateJsxText(node: JsxText, text: string, containsOnlyTriviaWhiteSpaces?: boolean): JsxText;
function createJsxOpeningFragment(): JsxOpeningFragment;
function createJsxJsxClosingFragment(): JsxClosingFragment;
function updateJsxFragment(node: JsxFragment, openingFragment: JsxOpeningFragment, children: ReadonlyArray<JsxChild>, closingFragment: JsxClosingFragment): JsxFragment;
function createJsxAttribute(name: Identifier, initializer: StringLiteral | JsxExpression): JsxAttribute;
function updateJsxAttribute(node: JsxAttribute, name: Identifier, initializer: StringLiteral | JsxExpression): JsxAttribute;

View File

@ -75,7 +75,7 @@ var ts;
// If changing the text in this section, be sure to test `configureNightly` too.
ts.versionMajorMinor = "3.4";
/** The version of the TypeScript compiler release */
ts.version = ts.versionMajorMinor + ".0-dev";
ts.version = ts.versionMajorMinor + ".0-rc";
})(ts || (ts = {}));
(function (ts) {
/* @internal */
@ -3575,8 +3575,7 @@ var ts;
InferenceFlags[InferenceFlags["None"] = 0] = "None";
InferenceFlags[InferenceFlags["NoDefault"] = 1] = "NoDefault";
InferenceFlags[InferenceFlags["AnyDefault"] = 2] = "AnyDefault";
InferenceFlags[InferenceFlags["NoFixing"] = 4] = "NoFixing";
InferenceFlags[InferenceFlags["SkippedGenericFunction"] = 8] = "SkippedGenericFunction";
InferenceFlags[InferenceFlags["SkippedGenericFunction"] = 4] = "SkippedGenericFunction";
})(InferenceFlags = ts.InferenceFlags || (ts.InferenceFlags = {}));
/**
* Ternary values are defined such that
@ -4148,8 +4147,11 @@ var ts;
*/
/* @internal */
function generateDjb2Hash(data) {
var chars = data.split("").map(function (str) { return str.charCodeAt(0); });
return "" + chars.reduce(function (prev, curr) { return ((prev << 5) + prev) + curr; }, 5381);
var acc = 5381;
for (var i = 0; i < data.length; i++) {
acc = ((acc << 5) + acc) + data.charCodeAt(i);
}
return acc.toString();
}
ts.generateDjb2Hash = generateDjb2Hash;
/**
@ -8143,6 +8145,7 @@ var ts;
}
pos++;
}
tokenValue = text.substring(startPos, pos);
return firstNonWhitespace === -1 ? 12 /* JsxTextAllWhiteSpaces */ : 11 /* JsxText */;
}
// Scans a JSX identifier; these differ from normal identifiers in that
@ -20262,7 +20265,8 @@ var ts;
}
function parseJsxText() {
var node = createNode(11 /* JsxText */);
node.containsOnlyWhiteSpaces = currentToken === 12 /* JsxTextAllWhiteSpaces */;
node.text = scanner.getTokenValue();
node.containsOnlyTriviaWhiteSpaces = currentToken === 12 /* JsxTextAllWhiteSpaces */;
currentToken = scanner.scanJsxToken();
return finishNode(node);
}
@ -31268,6 +31272,7 @@ var ts;
getResolvedSignatureForSignatureHelp: function (node, candidatesOutArray, agumentCount) {
return getResolvedSignatureWorker(node, candidatesOutArray, agumentCount, 16 /* IsForSignatureHelp */);
},
getExpandedParameters: getExpandedParameters,
getConstantValue: function (nodeIn) {
var node = ts.getParseTreeNode(nodeIn, canHaveConstantValue);
return node ? getConstantValue(node) : undefined;
@ -31764,11 +31769,11 @@ var ts;
}
}
function addRelatedInfo(diagnostic) {
var _a;
var relatedInformation = [];
for (var _i = 1; _i < arguments.length; _i++) {
relatedInformation[_i - 1] = arguments[_i];
}
var _a;
if (!diagnostic.relatedInformation) {
diagnostic.relatedInformation = [];
}
@ -37288,8 +37293,18 @@ var ts;
return sig;
}
function cloneSignature(sig) {
return createSignature(sig.declaration, sig.typeParameters, sig.thisParameter, sig.parameters, /*resolvedReturnType*/ undefined,
var result = createSignature(sig.declaration, sig.typeParameters, sig.thisParameter, sig.parameters, /*resolvedReturnType*/ undefined,
/*resolvedTypePredicate*/ undefined, sig.minArgumentCount, sig.hasRestParameter, sig.hasLiteralTypes);
result.target = sig.target;
result.mapper = sig.mapper;
return result;
}
function createUnionSignature(signature, unionSignatures) {
var result = cloneSignature(signature);
result.unionSignatures = unionSignatures;
result.target = undefined;
result.mapper = undefined;
return result;
}
function getExpandedParameters(sig) {
if (sig.hasRestParameter) {
@ -37398,9 +37413,8 @@ var ts;
var thisType = getUnionType(ts.map(unionSignatures, function (sig) { return sig.thisParameter ? getTypeOfSymbol(sig.thisParameter) : anyType; }), 2 /* Subtype */);
thisParameter = createSymbolWithType(signature.thisParameter, thisType);
}
s = cloneSignature(signature);
s = createUnionSignature(signature, unionSignatures);
s.thisParameter = thisParameter;
s.unionSignatures = unionSignatures;
}
(result || (result = [])).push(s);
}
@ -38797,8 +38811,6 @@ var ts;
if (returnSignature) {
var newReturnSignature = cloneSignature(returnSignature);
newReturnSignature.typeParameters = inferredTypeParameters;
newReturnSignature.target = returnSignature.target;
newReturnSignature.mapper = returnSignature.mapper;
var newInstantiatedSignature = cloneSignature(instantiatedSignature);
newInstantiatedSignature.resolvedReturnType = getOrCreateTypeFromSignature(newReturnSignature);
return newInstantiatedSignature;
@ -40411,7 +40423,7 @@ var ts;
// types rules (i.e. proper contravariance) for inferences.
inferTypes(context.inferences, checkType, extendsType, 32 /* NoConstraints */ | 64 /* AlwaysStrict */);
}
combinedMapper = combineTypeMappers(mapper, context);
combinedMapper = combineTypeMappers(mapper, context.mapper);
}
// Instantiate the extends type including inferences for 'infer T' type parameters
var inferredExtendsType = combinedMapper ? instantiateType(root.extendsType, combinedMapper) : extendsType;
@ -40964,33 +40976,8 @@ var ts;
* Maps forward-references to later types parameters to the empty object type.
* This is used during inference when instantiating type parameter defaults.
*/
function createBackreferenceMapper(typeParameters, index) {
return function (t) { return typeParameters.indexOf(t) >= index ? emptyObjectType : t; };
}
function isInferenceContext(mapper) {
return !!mapper.typeParameters;
}
function cloneTypeMapper(mapper, extraFlags) {
if (extraFlags === void 0) { extraFlags = 0; }
return mapper && isInferenceContext(mapper) ?
createInferenceContext(mapper.typeParameters, mapper.signature, mapper.flags | extraFlags, mapper.compareTypes, mapper.inferences) :
mapper;
}
function cloneInferredPartOfContext(context) {
// Filter context to only those parameters which actually have inference candidates
var params = [];
var inferences = [];
for (var i = 0; i < context.typeParameters.length; i++) {
var info = context.inferences[i];
if (info.candidates || info.contraCandidates) {
params.push(context.typeParameters[i]);
inferences.push(info);
}
}
if (!params.length) {
return undefined;
}
return createInferenceContext(params, context.signature, context.flags | 1 /* NoDefault */, context.compareTypes, inferences);
function createBackreferenceMapper(context, index) {
return function (t) { return ts.findIndex(context.inferences, function (info) { return info.typeParameter === t; }) >= index ? emptyObjectType : t; };
}
function combineTypeMappers(mapper1, mapper2) {
if (!mapper1)
@ -41727,7 +41714,7 @@ var ts;
// child is of the type of the expression
return { errorNode: child, innerExpression: child.expression, nameType: nameType };
case 11 /* JsxText */:
if (child.containsOnlyWhiteSpaces) {
if (child.containsOnlyTriviaWhiteSpaces) {
break; // Whitespace only jsx text isn't real jsx text
}
// child is a string
@ -41750,7 +41737,7 @@ var ts;
var childrenPropName = childPropName === undefined ? "children" : ts.unescapeLeadingUnderscores(childPropName);
var childrenNameType = getLiteralType(childrenPropName);
var childrenTargetType = getIndexedAccessType(target, childrenNameType);
var validChildren = ts.filter(containingElement.children, function (i) { return !ts.isJsxText(i) || !i.containsOnlyWhiteSpaces; });
var validChildren = ts.filter(containingElement.children, function (i) { return !ts.isJsxText(i) || !i.containsOnlyTriviaWhiteSpaces; });
if (!ts.length(validChildren)) {
return result;
}
@ -41917,7 +41904,7 @@ var ts;
}
if (source.typeParameters && source.typeParameters !== target.typeParameters) {
target = getCanonicalSignature(target);
source = instantiateSignatureInContextOf(source, target, /*contextualMapper*/ undefined, compareTypes);
source = instantiateSignatureInContextOf(source, target, /*inferenceContext*/ undefined, compareTypes);
}
var sourceCount = getParameterCount(source);
var sourceRestType = getNonArrayRestType(source);
@ -44326,26 +44313,43 @@ var ts;
callback(getRestTypeAtPosition(source, paramCount), targetRestType);
}
}
function createInferenceContext(typeParameters, signature, flags, compareTypes, baseInferences) {
var inferences = baseInferences ? baseInferences.map(cloneInferenceInfo) : typeParameters.map(createInferenceInfo);
var context = mapper;
context.typeParameters = typeParameters;
context.signature = signature;
context.inferences = inferences;
context.flags = flags;
context.compareTypes = compareTypes || compareTypesAssignable;
function createInferenceContext(typeParameters, signature, flags, compareTypes) {
return createInferenceContextWorker(typeParameters.map(createInferenceInfo), signature, flags, compareTypes || compareTypesAssignable);
}
function cloneInferenceContext(context, extraFlags) {
if (extraFlags === void 0) { extraFlags = 0; }
return context && createInferenceContextWorker(ts.map(context.inferences, cloneInferenceInfo), context.signature, context.flags | extraFlags, context.compareTypes);
}
function cloneInferredPartOfContext(context) {
var inferences = ts.filter(context.inferences, hasInferenceCandidates);
return inferences.length ?
createInferenceContextWorker(ts.map(inferences, cloneInferenceInfo), context.signature, context.flags, context.compareTypes) :
undefined;
}
function createInferenceContextWorker(inferences, signature, flags, compareTypes) {
var context = {
inferences: inferences,
signature: signature,
flags: flags,
compareTypes: compareTypes,
mapper: function (t) { return mapToInferredType(context, t, /*fix*/ true); },
nonFixingMapper: function (t) { return mapToInferredType(context, t, /*fix*/ false); },
};
return context;
function mapper(t) {
for (var i = 0; i < inferences.length; i++) {
if (t === inferences[i].typeParameter) {
if (!(context.flags & 4 /* NoFixing */)) {
inferences[i].isFixed = true;
}
return getInferredType(context, i);
}
function mapToInferredType(context, t, fix) {
var inferences = context.inferences;
for (var i = 0; i < inferences.length; i++) {
var inference = inferences[i];
if (t === inference.typeParameter) {
if (fix && !inference.isFixed) {
inference.isFixed = true;
inference.inferredType = undefined;
}
return getInferredType(context, i);
}
return t;
}
return t;
}
function createInferenceInfo(typeParameter) {
return {
@ -44369,6 +44373,9 @@ var ts;
isFixed: inference.isFixed
};
}
function getMapperFromContext(context) {
return context && context.mapper;
}
// Return true if the given type could possibly reference a type parameter for which
// we perform type inference (i.e. a type parameter of a generic function). We cache
// results for union and intersection types for performance reasons.
@ -44616,15 +44623,18 @@ var ts;
var candidate = propagationType || source;
// We make contravariant inferences only if we are in a pure contravariant position,
// i.e. only if we have not descended into a bivariant position.
if (contravariant && !bivariant) {
inference.contraCandidates = ts.appendIfUnique(inference.contraCandidates, candidate);
if (contravariant && !bivariant && !ts.contains(inference.contraCandidates, candidate)) {
inference.contraCandidates = ts.append(inference.contraCandidates, candidate);
inference.inferredType = undefined;
}
else {
inference.candidates = ts.appendIfUnique(inference.candidates, candidate);
else if (!ts.contains(inference.candidates, candidate)) {
inference.candidates = ts.append(inference.candidates, candidate);
inference.inferredType = undefined;
}
}
if (!(priority & 8 /* ReturnType */) && target.flags & 262144 /* TypeParameter */ && !isTypeParameterAtTopLevel(originalTarget, target)) {
if (!(priority & 8 /* ReturnType */) && target.flags & 262144 /* TypeParameter */ && inference.topLevel && !isTypeParameterAtTopLevel(originalTarget, target)) {
inference.topLevel = false;
inference.inferredType = undefined;
}
}
return;
@ -44690,7 +44700,7 @@ var ts;
inferFromTypes(getTrueTypeFromConditionalType(source), getTrueTypeFromConditionalType(target));
inferFromTypes(getFalseTypeFromConditionalType(source), getFalseTypeFromConditionalType(target));
}
else if (target.flags & 16777216 /* Conditional */) {
else if (target.flags & 16777216 /* Conditional */ && !contravariant) {
inferFromTypes(source, getTrueTypeFromConditionalType(target));
inferFromTypes(source, getFalseTypeFromConditionalType(target));
}
@ -45043,7 +45053,7 @@ var ts;
if (defaultType) {
// Instantiate the default type. Any forward reference to a type
// parameter should be instantiated to the empty object type.
inferredType = instantiateType(defaultType, combineTypeMappers(createBackreferenceMapper(context.typeParameters, index), context));
inferredType = instantiateType(defaultType, combineTypeMappers(createBackreferenceMapper(context, index), context.nonFixingMapper));
}
else {
inferredType = getDefaultTypeArgumentType(!!(context.flags & 2 /* AnyDefault */));
@ -45056,12 +45066,10 @@ var ts;
inference.inferredType = inferredType;
var constraint = getConstraintOfTypeParameter(inference.typeParameter);
if (constraint) {
context.flags |= 4 /* NoFixing */;
var instantiatedConstraint = instantiateType(constraint, context);
var instantiatedConstraint = instantiateType(constraint, context.nonFixingMapper);
if (!context.compareTypes(inferredType, getTypeWithThisArgument(instantiatedConstraint, inferredType))) {
inference.inferredType = inferredType = instantiatedConstraint;
}
context.flags &= ~4 /* NoFixing */;
}
}
return inferredType;
@ -47336,7 +47344,7 @@ var ts;
while (type) {
var thisType = getThisTypeFromContextualType(type);
if (thisType) {
return instantiateType(thisType, getContextualMapper(containingLiteral));
return instantiateType(thisType, getMapperFromContext(getInferenceContext(containingLiteral)));
}
if (literal.parent.kind !== 275 /* PropertyAssignment */) {
break;
@ -47785,9 +47793,9 @@ var ts;
// return type inferences is available, instantiate those types using that mapper.
function instantiateContextualType(contextualType, node) {
if (contextualType && maybeTypeOfKind(contextualType, 63176704 /* Instantiable */)) {
var returnMapper = getContextualMapper(node).returnMapper;
if (returnMapper) {
return instantiateInstantiableTypes(contextualType, returnMapper);
var inferenceContext = getInferenceContext(node);
if (inferenceContext && inferenceContext.returnMapper) {
return instantiateInstantiableTypes(contextualType, inferenceContext.returnMapper);
}
}
return contextualType;
@ -47886,9 +47894,9 @@ var ts;
}
return undefined;
}
function getContextualMapper(node) {
var ancestor = ts.findAncestor(node, function (n) { return !!n.contextualMapper; });
return ancestor ? ancestor.contextualMapper : identityMapper;
function getInferenceContext(node) {
var ancestor = ts.findAncestor(node, function (n) { return !!n.inferenceContext; });
return ancestor && ancestor.inferenceContext;
}
function getContextualJsxElementAttributesType(node) {
if (ts.isJsxOpeningElement(node) && node.parent.contextualType) {
@ -48088,12 +48096,7 @@ var ts;
}
}
// Result is union of signatures collected (return type is union of return types of this signature set)
var result;
if (signatureList) {
result = cloneSignature(signatureList[0]);
result.unionSignatures = signatureList;
}
return result;
return signatureList && createUnionSignature(signatureList[0], signatureList);
}
function checkSpreadExpression(node, checkMode) {
if (languageVersion < 2 /* ES2015 */ && compilerOptions.downlevelIteration) {
@ -48611,7 +48614,7 @@ var ts;
// In React, JSX text that contains only whitespaces will be ignored so we don't want to type-check that
// because then type of children property will have constituent of string type.
if (child.kind === 11 /* JsxText */) {
if (!child.containsOnlyWhiteSpaces) {
if (!child.containsOnlyTriviaWhiteSpaces) {
childrenTypes.push(stringType);
}
}
@ -49697,19 +49700,19 @@ var ts;
return undefined;
}
// Instantiate a generic signature in the context of a non-generic signature (section 3.8.5 in TypeScript spec)
function instantiateSignatureInContextOf(signature, contextualSignature, contextualMapper, compareTypes) {
function instantiateSignatureInContextOf(signature, contextualSignature, inferenceContext, compareTypes) {
var context = createInferenceContext(signature.typeParameters, signature, 0 /* None */, compareTypes);
// We clone the contextualMapper to avoid fixing. For example, when the source signature is <T>(x: T) => T[] and
// We clone the inferenceContext to avoid fixing. For example, when the source signature is <T>(x: T) => T[] and
// the contextual signature is (...args: A) => B, we want to infer the element type of A's constraint (say 'any')
// for T but leave it possible to later infer '[any]' back to A.
var restType = getEffectiveRestType(contextualSignature);
var mapper = contextualMapper && restType && restType.flags & 262144 /* TypeParameter */ ? cloneTypeMapper(contextualMapper) : contextualMapper;
var mapper = inferenceContext && (restType && restType.flags & 262144 /* TypeParameter */ ? inferenceContext.nonFixingMapper : inferenceContext.mapper);
var sourceSignature = mapper ? instantiateSignature(contextualSignature, mapper) : contextualSignature;
forEachMatchingParameterType(sourceSignature, signature, function (source, target) {
// Type parameters from outer context referenced by source type are fixed by instantiation of the source type
inferTypes(context.inferences, source, target);
});
if (!contextualMapper) {
if (!inferenceContext) {
inferTypes(context.inferences, getReturnTypeOfSignature(contextualSignature), getReturnTypeOfSignature(signature), 8 /* ReturnType */);
var signaturePredicate = getTypePredicateOfSignature(signature);
var contextualPredicate = getTypePredicateOfSignature(sourceSignature);
@ -49727,17 +49730,6 @@ var ts;
return getInferredTypes(context);
}
function inferTypeArguments(node, signature, args, checkMode, context) {
// Clear out all the inference results from the last time inferTypeArguments was called on this context
for (var _i = 0, _a = context.inferences; _i < _a.length; _i++) {
var inference = _a[_i];
// As an optimization, we don't have to clear (and later recompute) inferred types
// for type parameters that have already been fixed on the previous call to inferTypeArguments.
// It would be just as correct to reset all of them. But then we'd be repeating the same work
// for the type parameters that were fixed, namely the work done by getInferredType.
if (!inference.isFixed) {
inference.inferredType = undefined;
}
}
if (ts.isJsxOpeningLikeElement(node)) {
return inferJsxTypeArguments(node, signature, checkMode, context);
}
@ -49748,10 +49740,11 @@ var ts;
if (node.kind !== 152 /* Decorator */) {
var contextualType = getContextualType(node);
if (contextualType) {
// We clone the contextual mapper to avoid disturbing a resolution in progress for an
// We clone the inference context to avoid disturbing a resolution in progress for an
// outer call expression. Effectively we just want a snapshot of whatever has been
// inferred for any outer call expression so far.
var instantiatedType = instantiateType(contextualType, cloneTypeMapper(getContextualMapper(node), 1 /* NoDefault */));
var outerMapper = getMapperFromContext(cloneInferenceContext(getInferenceContext(node), 1 /* NoDefault */));
var instantiatedType = instantiateType(contextualType, outerMapper);
// If the contextual type is a generic function type with a single call signature, we
// instantiate the type with its own type parameters and type arguments. This ensures that
// the type parameters are not erased to type any during type inference such that they can
@ -49768,7 +49761,7 @@ var ts;
inferTypes(context.inferences, inferenceSourceType, inferenceTargetType, 8 /* ReturnType */);
// Create a type mapper for instantiating generic contextual types using the inferences made
// from the return type.
context.returnMapper = cloneInferredPartOfContext(context);
context.returnMapper = getMapperFromContext(cloneInferredPartOfContext(context));
}
}
var thisType = getThisTypeOfSignature(signature);
@ -49871,7 +49864,7 @@ var ts;
// However "context" and "updater" are implicit and can't be specify by users. Only the first parameter, props,
// can be specified by users through attributes property.
var paramType = getEffectiveFirstArgumentForJsxSignature(signature, node);
var attributesType = checkExpressionWithContextualType(node.attributes, paramType, /*contextualMapper*/ undefined, checkMode);
var attributesType = checkExpressionWithContextualType(node.attributes, paramType, /*inferenceContext*/ undefined, checkMode);
return checkTypeRelatedToAndOptionallyElaborate(attributesType, paramType, relation, reportErrors ? node.tagName : undefined, node.attributes);
}
function checkApplicableSignature(node, args, signature, relation, checkMode, reportErrors) {
@ -49898,7 +49891,7 @@ var ts;
var arg = args[i];
if (arg.kind !== 210 /* OmittedExpression */) {
var paramType = getTypeAtPosition(signature, i);
var argType = checkExpressionWithContextualType(arg, paramType, /*contextualMapper*/ undefined, checkMode);
var argType = checkExpressionWithContextualType(arg, paramType, /*inferenceContext*/ undefined, checkMode);
// If one or more arguments are still excluded (as indicated by CheckMode.SkipContextSensitive),
// we obtain the regular type of any object literal arguments because we may not have inferred complete
// parameter types yet and therefore excess property checks may yield false positives (see #17041).
@ -50254,7 +50247,7 @@ var ts;
else {
inferenceContext = createInferenceContext(candidate.typeParameters, candidate, /*flags*/ ts.isInJSFile(node) ? 2 /* AnyDefault */ : 0 /* None */);
typeArgumentTypes = inferTypeArguments(node, candidate, args, argCheckMode | 8 /* SkipGenericFunctions */, inferenceContext);
argCheckMode |= inferenceContext.flags & 8 /* SkippedGenericFunction */ ? 8 /* SkipGenericFunctions */ : 0 /* Normal */;
argCheckMode |= inferenceContext.flags & 4 /* SkippedGenericFunction */ ? 8 /* SkipGenericFunctions */ : 0 /* Normal */;
}
checkCandidate = getSignatureInstantiation(candidate, typeArgumentTypes, ts.isInJSFile(candidate.declaration), inferenceContext && inferenceContext.inferredTypeParameters);
// If the original signature has a generic rest type, instantiation may produce a
@ -51168,9 +51161,14 @@ var ts;
return getTypeOfParameter(signature.parameters[pos]);
}
if (signature.hasRestParameter) {
// We want to return the value undefined for an out of bounds parameter position,
// so we need to check bounds here before calling getIndexedAccessType (which
// otherwise would return the type 'undefined').
var restType = getTypeOfSymbol(signature.parameters[paramCount]);
var indexType = getLiteralType(pos - paramCount);
return getIndexedAccessType(restType, indexType);
var index = pos - paramCount;
if (!isTupleType(restType) || restType.target.hasRestElement || index < (restType.typeArguments || ts.emptyArray).length) {
return getIndexedAccessType(restType, getLiteralType(index));
}
}
return undefined;
}
@ -51241,14 +51239,14 @@ var ts;
function getTypeOfFirstParameterOfSignatureWithFallback(signature, fallbackType) {
return signature.parameters.length > 0 ? getTypeAtPosition(signature, 0) : fallbackType;
}
function inferFromAnnotatedParameters(signature, context, mapper) {
function inferFromAnnotatedParameters(signature, context, inferenceContext) {
var len = signature.parameters.length - (signature.hasRestParameter ? 1 : 0);
for (var i = 0; i < len; i++) {
var declaration = signature.parameters[i].valueDeclaration;
if (declaration.type) {
var typeNode = ts.getEffectiveTypeAnnotationNode(declaration);
if (typeNode) {
inferTypes(mapper.inferences, getTypeFromTypeNode(typeNode), getTypeAtPosition(context, i));
inferTypes(inferenceContext.inferences, getTypeFromTypeNode(typeNode), getTypeAtPosition(context, i));
}
}
}
@ -51256,12 +51254,12 @@ var ts;
if (restType && restType.flags & 262144 /* TypeParameter */) {
// The contextual signature has a generic rest parameter. We first instantiate the contextual
// signature (without fixing type parameters) and assign types to contextually typed parameters.
var instantiatedContext = instantiateSignature(context, cloneTypeMapper(mapper));
var instantiatedContext = instantiateSignature(context, inferenceContext.nonFixingMapper);
assignContextualParameterTypes(signature, instantiatedContext);
// We then infer from a tuple type representing the parameters that correspond to the contextual
// rest parameter.
var restPos = getParameterCount(context) - 1;
inferTypes(mapper.inferences, getRestTypeAtPosition(signature, restPos), restType);
inferTypes(inferenceContext.inferences, getRestTypeAtPosition(signature, restPos), restType);
}
}
function assignContextualParameterTypes(signature, context) {
@ -51670,12 +51668,12 @@ var ts;
if (contextualSignature) {
var signature = getSignaturesOfType(type, 0 /* Call */)[0];
if (isContextSensitive(node)) {
var contextualMapper = getContextualMapper(node);
var inferenceContext = getInferenceContext(node);
if (checkMode && checkMode & 2 /* Inferential */) {
inferFromAnnotatedParameters(signature, contextualSignature, contextualMapper);
inferFromAnnotatedParameters(signature, contextualSignature, inferenceContext);
}
var instantiatedContextualSignature = contextualMapper === identityMapper ?
contextualSignature : instantiateSignature(contextualSignature, contextualMapper);
var instantiatedContextualSignature = inferenceContext ?
instantiateSignature(contextualSignature, inferenceContext.mapper) : contextualSignature;
assignContextualParameterTypes(signature, instantiatedContextualSignature);
}
if (!getReturnTypeFromAnnotation(node) && !signature.resolvedReturnType) {
@ -52593,20 +52591,20 @@ var ts;
}
return node;
}
function checkExpressionWithContextualType(node, contextualType, contextualMapper, checkMode) {
function checkExpressionWithContextualType(node, contextualType, inferenceContext, checkMode) {
var context = getContextNode(node);
var saveContextualType = context.contextualType;
var saveContextualMapper = context.contextualMapper;
var saveInferenceContext = context.inferenceContext;
context.contextualType = contextualType;
context.contextualMapper = contextualMapper;
var type = checkExpression(node, checkMode | 1 /* Contextual */ | (contextualMapper ? 2 /* Inferential */ : 0));
context.inferenceContext = inferenceContext;
var type = checkExpression(node, checkMode | 1 /* Contextual */ | (inferenceContext ? 2 /* Inferential */ : 0));
// We strip literal freshness when an appropriate contextual type is present such that contextually typed
// literals always preserve their literal types (otherwise they might widen during type inference). An alternative
// here would be to not mark contextually typed literals as fresh in the first place.
var result = maybeTypeOfKind(type, 2944 /* Literal */) && isLiteralOfContextualType(type, instantiateContextualType(contextualType, node)) ?
getRegularTypeOfLiteralType(type) : type;
context.contextualType = saveContextualType;
context.contextualMapper = saveContextualMapper;
context.inferenceContext = saveInferenceContext;
return result;
}
function checkExpressionCached(node, checkMode) {
@ -52720,7 +52718,7 @@ var ts;
if (contextualType) {
var contextualSignature = getSingleCallSignature(getNonNullableType(contextualType));
if (contextualSignature && !contextualSignature.typeParameters) {
var context = getContextualMapper(node);
var context = getInferenceContext(node);
// We have an expression that is an argument of a generic function for which we are performing
// type argument inference. The expression is of a function type with a single generic call
// signature and a contextual function type with a single non-generic call signature. Now check
@ -52736,7 +52734,7 @@ var ts;
var strippedType = getOrCreateTypeFromSignature(getSignatureInstantiationWithoutFillingInTypeArguments(signature, uniqueTypeParameters));
// Infer from the stripped expression type to the contextual type starting with an empty
// set of inference candidates.
var inferences = ts.map(context.typeParameters, createInferenceInfo);
var inferences = ts.map(context.inferences, function (info) { return createInferenceInfo(info.typeParameter); });
inferTypes(inferences, strippedType, contextualType);
// If we produced some inference candidates and if the type parameters for which we produced
// candidates do not already have existing inferences, we adopt the new inference candidates and
@ -52759,8 +52757,8 @@ var ts;
if (checkMode & 2 /* Inferential */) {
// We have skipped a generic function during inferential typing. Obtain the inference context and
// indicate this has occurred such that we know a second pass of inference is be needed.
var context = getContextualMapper(node);
context.flags |= 8 /* SkippedGenericFunction */;
var context = getInferenceContext(node);
context.flags |= 4 /* SkippedGenericFunction */;
}
}
function hasInferenceCandidates(info) {
@ -52868,13 +52866,6 @@ var ts;
node.contextualType = saveContextualType;
return type;
}
// Checks an expression and returns its type. The contextualMapper parameter serves two purposes: When
// contextualMapper is not undefined and not equal to the identityMapper function object it indicates that the
// expression is being inferentially typed (section 4.15.2 in spec) and provides the type mapper to use in
// conjunction with the generic contextual type. When contextualMapper is equal to the identityMapper function
// object, it serves as an indicator that all contained function and arrow expressions should be considered to
// have the wildcard function type; this form of type check is used during overload resolution to exclude
// contextually typed function and arrow expressions in the initial phase.
function checkExpression(node, checkMode, forceTuple) {
var saveCurrentNode = currentNode;
currentNode = node;
@ -62268,6 +62259,28 @@ var ts;
return node;
}
ts.createJsxFragment = createJsxFragment;
function createJsxText(text, containsOnlyTriviaWhiteSpaces) {
var node = createSynthesizedNode(11 /* JsxText */);
node.text = text;
node.containsOnlyTriviaWhiteSpaces = !!containsOnlyTriviaWhiteSpaces;
return node;
}
ts.createJsxText = createJsxText;
function updateJsxText(node, text, containsOnlyTriviaWhiteSpaces) {
return node.text !== text
|| node.containsOnlyTriviaWhiteSpaces !== containsOnlyTriviaWhiteSpaces
? updateNode(createJsxText(text, containsOnlyTriviaWhiteSpaces), node)
: node;
}
ts.updateJsxText = updateJsxText;
function createJsxOpeningFragment() {
return createSynthesizedNode(265 /* JsxOpeningFragment */);
}
ts.createJsxOpeningFragment = createJsxOpeningFragment;
function createJsxJsxClosingFragment() {
return createSynthesizedNode(266 /* JsxClosingFragment */);
}
ts.createJsxJsxClosingFragment = createJsxJsxClosingFragment;
function updateJsxFragment(node, openingFragment, children, closingFragment) {
return node.openingFragment !== openingFragment
|| node.children !== children
@ -71496,7 +71509,7 @@ var ts;
}
}
function visitJsxText(node) {
var fixed = fixupWhitespaceAndDecodeEntities(ts.getTextOfNode(node, /*includeTrivia*/ true));
var fixed = fixupWhitespaceAndDecodeEntities(node.text);
return fixed === undefined ? undefined : ts.createLiteral(fixed);
}
/**
@ -85355,7 +85368,7 @@ var ts;
writePunctuation(">");
}
function emitJsxText(node) {
writer.writeLiteral(getTextOfNode(node, /*includeTrivia*/ true));
writer.writeLiteral(node.text);
}
function emitJsxClosingElementOrFragment(node) {
writePunctuation("</");
@ -92747,7 +92760,7 @@ var ts;
}
}
ts.createCompilerHostFromProgramHost = createCompilerHostFromProgramHost;
function setCreateSourceFileAsHashVersioned(compilerHost, host) {
function setGetSourceFileAsHashVersioned(compilerHost, host) {
var originalGetSourceFile = compilerHost.getSourceFile;
var computeHash = host.createHash || ts.generateDjb2Hash;
compilerHost.getSourceFile = function () {
@ -92762,7 +92775,7 @@ var ts;
return result;
};
}
ts.setCreateSourceFileAsHashVersioned = setCreateSourceFileAsHashVersioned;
ts.setGetSourceFileAsHashVersioned = setGetSourceFileAsHashVersioned;
/**
* Creates the watch compiler host that can be extended with config file or root file names and options host
*/
@ -92910,7 +92923,7 @@ var ts;
configFileWatcher = watchFile(host, configFileName, scheduleProgramReload, ts.PollingInterval.High, "Config file" /* ConfigFile */);
}
var compilerHost = ts.createCompilerHostFromProgramHost(host, function () { return compilerOptions; }, directoryStructureHost);
ts.setCreateSourceFileAsHashVersioned(compilerHost, host);
ts.setGetSourceFileAsHashVersioned(compilerHost, host);
// Members for CompilerHost
var getNewSourceFile = compilerHost.getSourceFile;
compilerHost.getSourceFile = function (fileName) {
@ -93497,7 +93510,7 @@ var ts;
var readFileWithCache = function (f) { return host.readFile(f); };
var projectCompilerOptions = baseCompilerOptions;
var compilerHost = ts.createCompilerHostFromProgramHost(host, function () { return projectCompilerOptions; });
ts.setCreateSourceFileAsHashVersioned(compilerHost, host);
ts.setGetSourceFileAsHashVersioned(compilerHost, host);
var buildInfoChecked = createFileMap(toPath);
// Watch state
var builderPrograms = createFileMap(toPath);
@ -96033,7 +96046,7 @@ var ts;
}
ts.isInsideJsxElementOrAttribute = isInsideJsxElementOrAttribute;
function isWhiteSpaceOnlyJsxText(node) {
return ts.isJsxText(node) && node.containsOnlyWhiteSpaces;
return ts.isJsxText(node) && node.containsOnlyTriviaWhiteSpaces;
}
function isInTemplateString(sourceFile, position) {
var token = getTokenAtPosition(sourceFile, position);
@ -106763,7 +106776,7 @@ var ts;
var parameters = (typeParameters || ts.emptyArray).map(function (t) { return createSignatureHelpParameterForTypeParameter(t, checker, enclosingDeclaration, sourceFile, printer); });
var parameterParts = ts.mapToDisplayParts(function (writer) {
var thisParameter = candidateSignature.thisParameter ? [checker.symbolToParameterDeclaration(candidateSignature.thisParameter, enclosingDeclaration, signatureHelpNodeBuilderFlags)] : [];
var params = ts.createNodeArray(thisParameter.concat(candidateSignature.parameters.map(function (param) { return checker.symbolToParameterDeclaration(param, enclosingDeclaration, signatureHelpNodeBuilderFlags); })));
var params = ts.createNodeArray(thisParameter.concat(checker.getExpandedParameters(candidateSignature).map(function (param) { return checker.symbolToParameterDeclaration(param, enclosingDeclaration, signatureHelpNodeBuilderFlags); })));
printer.writeList(2576 /* CallExpressionArguments */, params, sourceFile, writer);
});
return { isVariadic: false, parameters: parameters, prefix: [ts.punctuationPart(28 /* LessThanToken */)], suffix: [ts.punctuationPart(30 /* GreaterThanToken */)].concat(parameterParts) };
@ -106777,7 +106790,7 @@ var ts;
printer.writeList(53776 /* TypeParameters */, args, sourceFile, writer);
}
});
var parameters = candidateSignature.parameters.map(function (p) { return createSignatureHelpParameterForParameter(p, checker, enclosingDeclaration, sourceFile, printer); });
var parameters = checker.getExpandedParameters(candidateSignature).map(function (p) { return createSignatureHelpParameterForParameter(p, checker, enclosingDeclaration, sourceFile, printer); });
return { isVariadic: isVariadic, parameters: parameters, prefix: typeParameterParts.concat([ts.punctuationPart(20 /* OpenParenToken */)]), suffix: [ts.punctuationPart(21 /* CloseParenToken */)] };
}
function createSignatureHelpParameterForParameter(parameter, checker, enclosingDeclaration, sourceFile, printer) {
@ -120647,9 +120660,9 @@ var ts;
}());
ts.ThrottledCancellationToken = ThrottledCancellationToken;
function createLanguageService(host, documentRegistry, syntaxOnly) {
var _a;
if (documentRegistry === void 0) { documentRegistry = ts.createDocumentRegistry(host.useCaseSensitiveFileNames && host.useCaseSensitiveFileNames(), host.getCurrentDirectory()); }
if (syntaxOnly === void 0) { syntaxOnly = false; }
var _a;
var syntaxTreeCache = new SyntaxTreeCache(host);
var program;
var lastProjectVersion;

View File

@ -1203,9 +1203,9 @@ declare namespace ts {
dotDotDotToken?: Token<SyntaxKind.DotDotDotToken>;
expression?: Expression;
}
interface JsxText extends Node {
interface JsxText extends LiteralLikeNode {
kind: SyntaxKind.JsxText;
containsOnlyWhiteSpaces: boolean;
containsOnlyTriviaWhiteSpaces: boolean;
parent: JsxElement;
}
type JsxChild = JsxText | JsxExpression | JsxElement | JsxSelfClosingElement | JsxFragment;
@ -3992,6 +3992,10 @@ declare namespace ts {
function createJsxClosingElement(tagName: JsxTagNameExpression): JsxClosingElement;
function updateJsxClosingElement(node: JsxClosingElement, tagName: JsxTagNameExpression): JsxClosingElement;
function createJsxFragment(openingFragment: JsxOpeningFragment, children: ReadonlyArray<JsxChild>, closingFragment: JsxClosingFragment): JsxFragment;
function createJsxText(text: string, containsOnlyTriviaWhiteSpaces?: boolean): JsxText;
function updateJsxText(node: JsxText, text: string, containsOnlyTriviaWhiteSpaces?: boolean): JsxText;
function createJsxOpeningFragment(): JsxOpeningFragment;
function createJsxJsxClosingFragment(): JsxClosingFragment;
function updateJsxFragment(node: JsxFragment, openingFragment: JsxOpeningFragment, children: ReadonlyArray<JsxChild>, closingFragment: JsxClosingFragment): JsxFragment;
function createJsxAttribute(name: Identifier, initializer: StringLiteral | JsxExpression): JsxAttribute;
function updateJsxAttribute(node: JsxAttribute, name: Identifier, initializer: StringLiteral | JsxExpression): JsxAttribute;

View File

@ -75,7 +75,7 @@ var ts;
// If changing the text in this section, be sure to test `configureNightly` too.
ts.versionMajorMinor = "3.4";
/** The version of the TypeScript compiler release */
ts.version = ts.versionMajorMinor + ".0-dev";
ts.version = ts.versionMajorMinor + ".0-rc";
})(ts || (ts = {}));
(function (ts) {
/* @internal */
@ -3575,8 +3575,7 @@ var ts;
InferenceFlags[InferenceFlags["None"] = 0] = "None";
InferenceFlags[InferenceFlags["NoDefault"] = 1] = "NoDefault";
InferenceFlags[InferenceFlags["AnyDefault"] = 2] = "AnyDefault";
InferenceFlags[InferenceFlags["NoFixing"] = 4] = "NoFixing";
InferenceFlags[InferenceFlags["SkippedGenericFunction"] = 8] = "SkippedGenericFunction";
InferenceFlags[InferenceFlags["SkippedGenericFunction"] = 4] = "SkippedGenericFunction";
})(InferenceFlags = ts.InferenceFlags || (ts.InferenceFlags = {}));
/**
* Ternary values are defined such that
@ -4148,8 +4147,11 @@ var ts;
*/
/* @internal */
function generateDjb2Hash(data) {
var chars = data.split("").map(function (str) { return str.charCodeAt(0); });
return "" + chars.reduce(function (prev, curr) { return ((prev << 5) + prev) + curr; }, 5381);
var acc = 5381;
for (var i = 0; i < data.length; i++) {
acc = ((acc << 5) + acc) + data.charCodeAt(i);
}
return acc.toString();
}
ts.generateDjb2Hash = generateDjb2Hash;
/**
@ -8143,6 +8145,7 @@ var ts;
}
pos++;
}
tokenValue = text.substring(startPos, pos);
return firstNonWhitespace === -1 ? 12 /* JsxTextAllWhiteSpaces */ : 11 /* JsxText */;
}
// Scans a JSX identifier; these differ from normal identifiers in that
@ -20262,7 +20265,8 @@ var ts;
}
function parseJsxText() {
var node = createNode(11 /* JsxText */);
node.containsOnlyWhiteSpaces = currentToken === 12 /* JsxTextAllWhiteSpaces */;
node.text = scanner.getTokenValue();
node.containsOnlyTriviaWhiteSpaces = currentToken === 12 /* JsxTextAllWhiteSpaces */;
currentToken = scanner.scanJsxToken();
return finishNode(node);
}
@ -31268,6 +31272,7 @@ var ts;
getResolvedSignatureForSignatureHelp: function (node, candidatesOutArray, agumentCount) {
return getResolvedSignatureWorker(node, candidatesOutArray, agumentCount, 16 /* IsForSignatureHelp */);
},
getExpandedParameters: getExpandedParameters,
getConstantValue: function (nodeIn) {
var node = ts.getParseTreeNode(nodeIn, canHaveConstantValue);
return node ? getConstantValue(node) : undefined;
@ -31764,11 +31769,11 @@ var ts;
}
}
function addRelatedInfo(diagnostic) {
var _a;
var relatedInformation = [];
for (var _i = 1; _i < arguments.length; _i++) {
relatedInformation[_i - 1] = arguments[_i];
}
var _a;
if (!diagnostic.relatedInformation) {
diagnostic.relatedInformation = [];
}
@ -37288,8 +37293,18 @@ var ts;
return sig;
}
function cloneSignature(sig) {
return createSignature(sig.declaration, sig.typeParameters, sig.thisParameter, sig.parameters, /*resolvedReturnType*/ undefined,
var result = createSignature(sig.declaration, sig.typeParameters, sig.thisParameter, sig.parameters, /*resolvedReturnType*/ undefined,
/*resolvedTypePredicate*/ undefined, sig.minArgumentCount, sig.hasRestParameter, sig.hasLiteralTypes);
result.target = sig.target;
result.mapper = sig.mapper;
return result;
}
function createUnionSignature(signature, unionSignatures) {
var result = cloneSignature(signature);
result.unionSignatures = unionSignatures;
result.target = undefined;
result.mapper = undefined;
return result;
}
function getExpandedParameters(sig) {
if (sig.hasRestParameter) {
@ -37398,9 +37413,8 @@ var ts;
var thisType = getUnionType(ts.map(unionSignatures, function (sig) { return sig.thisParameter ? getTypeOfSymbol(sig.thisParameter) : anyType; }), 2 /* Subtype */);
thisParameter = createSymbolWithType(signature.thisParameter, thisType);
}
s = cloneSignature(signature);
s = createUnionSignature(signature, unionSignatures);
s.thisParameter = thisParameter;
s.unionSignatures = unionSignatures;
}
(result || (result = [])).push(s);
}
@ -38797,8 +38811,6 @@ var ts;
if (returnSignature) {
var newReturnSignature = cloneSignature(returnSignature);
newReturnSignature.typeParameters = inferredTypeParameters;
newReturnSignature.target = returnSignature.target;
newReturnSignature.mapper = returnSignature.mapper;
var newInstantiatedSignature = cloneSignature(instantiatedSignature);
newInstantiatedSignature.resolvedReturnType = getOrCreateTypeFromSignature(newReturnSignature);
return newInstantiatedSignature;
@ -40411,7 +40423,7 @@ var ts;
// types rules (i.e. proper contravariance) for inferences.
inferTypes(context.inferences, checkType, extendsType, 32 /* NoConstraints */ | 64 /* AlwaysStrict */);
}
combinedMapper = combineTypeMappers(mapper, context);
combinedMapper = combineTypeMappers(mapper, context.mapper);
}
// Instantiate the extends type including inferences for 'infer T' type parameters
var inferredExtendsType = combinedMapper ? instantiateType(root.extendsType, combinedMapper) : extendsType;
@ -40964,33 +40976,8 @@ var ts;
* Maps forward-references to later types parameters to the empty object type.
* This is used during inference when instantiating type parameter defaults.
*/
function createBackreferenceMapper(typeParameters, index) {
return function (t) { return typeParameters.indexOf(t) >= index ? emptyObjectType : t; };
}
function isInferenceContext(mapper) {
return !!mapper.typeParameters;
}
function cloneTypeMapper(mapper, extraFlags) {
if (extraFlags === void 0) { extraFlags = 0; }
return mapper && isInferenceContext(mapper) ?
createInferenceContext(mapper.typeParameters, mapper.signature, mapper.flags | extraFlags, mapper.compareTypes, mapper.inferences) :
mapper;
}
function cloneInferredPartOfContext(context) {
// Filter context to only those parameters which actually have inference candidates
var params = [];
var inferences = [];
for (var i = 0; i < context.typeParameters.length; i++) {
var info = context.inferences[i];
if (info.candidates || info.contraCandidates) {
params.push(context.typeParameters[i]);
inferences.push(info);
}
}
if (!params.length) {
return undefined;
}
return createInferenceContext(params, context.signature, context.flags | 1 /* NoDefault */, context.compareTypes, inferences);
function createBackreferenceMapper(context, index) {
return function (t) { return ts.findIndex(context.inferences, function (info) { return info.typeParameter === t; }) >= index ? emptyObjectType : t; };
}
function combineTypeMappers(mapper1, mapper2) {
if (!mapper1)
@ -41727,7 +41714,7 @@ var ts;
// child is of the type of the expression
return { errorNode: child, innerExpression: child.expression, nameType: nameType };
case 11 /* JsxText */:
if (child.containsOnlyWhiteSpaces) {
if (child.containsOnlyTriviaWhiteSpaces) {
break; // Whitespace only jsx text isn't real jsx text
}
// child is a string
@ -41750,7 +41737,7 @@ var ts;
var childrenPropName = childPropName === undefined ? "children" : ts.unescapeLeadingUnderscores(childPropName);
var childrenNameType = getLiteralType(childrenPropName);
var childrenTargetType = getIndexedAccessType(target, childrenNameType);
var validChildren = ts.filter(containingElement.children, function (i) { return !ts.isJsxText(i) || !i.containsOnlyWhiteSpaces; });
var validChildren = ts.filter(containingElement.children, function (i) { return !ts.isJsxText(i) || !i.containsOnlyTriviaWhiteSpaces; });
if (!ts.length(validChildren)) {
return result;
}
@ -41917,7 +41904,7 @@ var ts;
}
if (source.typeParameters && source.typeParameters !== target.typeParameters) {
target = getCanonicalSignature(target);
source = instantiateSignatureInContextOf(source, target, /*contextualMapper*/ undefined, compareTypes);
source = instantiateSignatureInContextOf(source, target, /*inferenceContext*/ undefined, compareTypes);
}
var sourceCount = getParameterCount(source);
var sourceRestType = getNonArrayRestType(source);
@ -44326,26 +44313,43 @@ var ts;
callback(getRestTypeAtPosition(source, paramCount), targetRestType);
}
}
function createInferenceContext(typeParameters, signature, flags, compareTypes, baseInferences) {
var inferences = baseInferences ? baseInferences.map(cloneInferenceInfo) : typeParameters.map(createInferenceInfo);
var context = mapper;
context.typeParameters = typeParameters;
context.signature = signature;
context.inferences = inferences;
context.flags = flags;
context.compareTypes = compareTypes || compareTypesAssignable;
function createInferenceContext(typeParameters, signature, flags, compareTypes) {
return createInferenceContextWorker(typeParameters.map(createInferenceInfo), signature, flags, compareTypes || compareTypesAssignable);
}
function cloneInferenceContext(context, extraFlags) {
if (extraFlags === void 0) { extraFlags = 0; }
return context && createInferenceContextWorker(ts.map(context.inferences, cloneInferenceInfo), context.signature, context.flags | extraFlags, context.compareTypes);
}
function cloneInferredPartOfContext(context) {
var inferences = ts.filter(context.inferences, hasInferenceCandidates);
return inferences.length ?
createInferenceContextWorker(ts.map(inferences, cloneInferenceInfo), context.signature, context.flags, context.compareTypes) :
undefined;
}
function createInferenceContextWorker(inferences, signature, flags, compareTypes) {
var context = {
inferences: inferences,
signature: signature,
flags: flags,
compareTypes: compareTypes,
mapper: function (t) { return mapToInferredType(context, t, /*fix*/ true); },
nonFixingMapper: function (t) { return mapToInferredType(context, t, /*fix*/ false); },
};
return context;
function mapper(t) {
for (var i = 0; i < inferences.length; i++) {
if (t === inferences[i].typeParameter) {
if (!(context.flags & 4 /* NoFixing */)) {
inferences[i].isFixed = true;
}
return getInferredType(context, i);
}
function mapToInferredType(context, t, fix) {
var inferences = context.inferences;
for (var i = 0; i < inferences.length; i++) {
var inference = inferences[i];
if (t === inference.typeParameter) {
if (fix && !inference.isFixed) {
inference.isFixed = true;
inference.inferredType = undefined;
}
return getInferredType(context, i);
}
return t;
}
return t;
}
function createInferenceInfo(typeParameter) {
return {
@ -44369,6 +44373,9 @@ var ts;
isFixed: inference.isFixed
};
}
function getMapperFromContext(context) {
return context && context.mapper;
}
// Return true if the given type could possibly reference a type parameter for which
// we perform type inference (i.e. a type parameter of a generic function). We cache
// results for union and intersection types for performance reasons.
@ -44616,15 +44623,18 @@ var ts;
var candidate = propagationType || source;
// We make contravariant inferences only if we are in a pure contravariant position,
// i.e. only if we have not descended into a bivariant position.
if (contravariant && !bivariant) {
inference.contraCandidates = ts.appendIfUnique(inference.contraCandidates, candidate);
if (contravariant && !bivariant && !ts.contains(inference.contraCandidates, candidate)) {
inference.contraCandidates = ts.append(inference.contraCandidates, candidate);
inference.inferredType = undefined;
}
else {
inference.candidates = ts.appendIfUnique(inference.candidates, candidate);
else if (!ts.contains(inference.candidates, candidate)) {
inference.candidates = ts.append(inference.candidates, candidate);
inference.inferredType = undefined;
}
}
if (!(priority & 8 /* ReturnType */) && target.flags & 262144 /* TypeParameter */ && !isTypeParameterAtTopLevel(originalTarget, target)) {
if (!(priority & 8 /* ReturnType */) && target.flags & 262144 /* TypeParameter */ && inference.topLevel && !isTypeParameterAtTopLevel(originalTarget, target)) {
inference.topLevel = false;
inference.inferredType = undefined;
}
}
return;
@ -44690,7 +44700,7 @@ var ts;
inferFromTypes(getTrueTypeFromConditionalType(source), getTrueTypeFromConditionalType(target));
inferFromTypes(getFalseTypeFromConditionalType(source), getFalseTypeFromConditionalType(target));
}
else if (target.flags & 16777216 /* Conditional */) {
else if (target.flags & 16777216 /* Conditional */ && !contravariant) {
inferFromTypes(source, getTrueTypeFromConditionalType(target));
inferFromTypes(source, getFalseTypeFromConditionalType(target));
}
@ -45043,7 +45053,7 @@ var ts;
if (defaultType) {
// Instantiate the default type. Any forward reference to a type
// parameter should be instantiated to the empty object type.
inferredType = instantiateType(defaultType, combineTypeMappers(createBackreferenceMapper(context.typeParameters, index), context));
inferredType = instantiateType(defaultType, combineTypeMappers(createBackreferenceMapper(context, index), context.nonFixingMapper));
}
else {
inferredType = getDefaultTypeArgumentType(!!(context.flags & 2 /* AnyDefault */));
@ -45056,12 +45066,10 @@ var ts;
inference.inferredType = inferredType;
var constraint = getConstraintOfTypeParameter(inference.typeParameter);
if (constraint) {
context.flags |= 4 /* NoFixing */;
var instantiatedConstraint = instantiateType(constraint, context);
var instantiatedConstraint = instantiateType(constraint, context.nonFixingMapper);
if (!context.compareTypes(inferredType, getTypeWithThisArgument(instantiatedConstraint, inferredType))) {
inference.inferredType = inferredType = instantiatedConstraint;
}
context.flags &= ~4 /* NoFixing */;
}
}
return inferredType;
@ -47336,7 +47344,7 @@ var ts;
while (type) {
var thisType = getThisTypeFromContextualType(type);
if (thisType) {
return instantiateType(thisType, getContextualMapper(containingLiteral));
return instantiateType(thisType, getMapperFromContext(getInferenceContext(containingLiteral)));
}
if (literal.parent.kind !== 275 /* PropertyAssignment */) {
break;
@ -47785,9 +47793,9 @@ var ts;
// return type inferences is available, instantiate those types using that mapper.
function instantiateContextualType(contextualType, node) {
if (contextualType && maybeTypeOfKind(contextualType, 63176704 /* Instantiable */)) {
var returnMapper = getContextualMapper(node).returnMapper;
if (returnMapper) {
return instantiateInstantiableTypes(contextualType, returnMapper);
var inferenceContext = getInferenceContext(node);
if (inferenceContext && inferenceContext.returnMapper) {
return instantiateInstantiableTypes(contextualType, inferenceContext.returnMapper);
}
}
return contextualType;
@ -47886,9 +47894,9 @@ var ts;
}
return undefined;
}
function getContextualMapper(node) {
var ancestor = ts.findAncestor(node, function (n) { return !!n.contextualMapper; });
return ancestor ? ancestor.contextualMapper : identityMapper;
function getInferenceContext(node) {
var ancestor = ts.findAncestor(node, function (n) { return !!n.inferenceContext; });
return ancestor && ancestor.inferenceContext;
}
function getContextualJsxElementAttributesType(node) {
if (ts.isJsxOpeningElement(node) && node.parent.contextualType) {
@ -48088,12 +48096,7 @@ var ts;
}
}
// Result is union of signatures collected (return type is union of return types of this signature set)
var result;
if (signatureList) {
result = cloneSignature(signatureList[0]);
result.unionSignatures = signatureList;
}
return result;
return signatureList && createUnionSignature(signatureList[0], signatureList);
}
function checkSpreadExpression(node, checkMode) {
if (languageVersion < 2 /* ES2015 */ && compilerOptions.downlevelIteration) {
@ -48611,7 +48614,7 @@ var ts;
// In React, JSX text that contains only whitespaces will be ignored so we don't want to type-check that
// because then type of children property will have constituent of string type.
if (child.kind === 11 /* JsxText */) {
if (!child.containsOnlyWhiteSpaces) {
if (!child.containsOnlyTriviaWhiteSpaces) {
childrenTypes.push(stringType);
}
}
@ -49697,19 +49700,19 @@ var ts;
return undefined;
}
// Instantiate a generic signature in the context of a non-generic signature (section 3.8.5 in TypeScript spec)
function instantiateSignatureInContextOf(signature, contextualSignature, contextualMapper, compareTypes) {
function instantiateSignatureInContextOf(signature, contextualSignature, inferenceContext, compareTypes) {
var context = createInferenceContext(signature.typeParameters, signature, 0 /* None */, compareTypes);
// We clone the contextualMapper to avoid fixing. For example, when the source signature is <T>(x: T) => T[] and
// We clone the inferenceContext to avoid fixing. For example, when the source signature is <T>(x: T) => T[] and
// the contextual signature is (...args: A) => B, we want to infer the element type of A's constraint (say 'any')
// for T but leave it possible to later infer '[any]' back to A.
var restType = getEffectiveRestType(contextualSignature);
var mapper = contextualMapper && restType && restType.flags & 262144 /* TypeParameter */ ? cloneTypeMapper(contextualMapper) : contextualMapper;
var mapper = inferenceContext && (restType && restType.flags & 262144 /* TypeParameter */ ? inferenceContext.nonFixingMapper : inferenceContext.mapper);
var sourceSignature = mapper ? instantiateSignature(contextualSignature, mapper) : contextualSignature;
forEachMatchingParameterType(sourceSignature, signature, function (source, target) {
// Type parameters from outer context referenced by source type are fixed by instantiation of the source type
inferTypes(context.inferences, source, target);
});
if (!contextualMapper) {
if (!inferenceContext) {
inferTypes(context.inferences, getReturnTypeOfSignature(contextualSignature), getReturnTypeOfSignature(signature), 8 /* ReturnType */);
var signaturePredicate = getTypePredicateOfSignature(signature);
var contextualPredicate = getTypePredicateOfSignature(sourceSignature);
@ -49727,17 +49730,6 @@ var ts;
return getInferredTypes(context);
}
function inferTypeArguments(node, signature, args, checkMode, context) {
// Clear out all the inference results from the last time inferTypeArguments was called on this context
for (var _i = 0, _a = context.inferences; _i < _a.length; _i++) {
var inference = _a[_i];
// As an optimization, we don't have to clear (and later recompute) inferred types
// for type parameters that have already been fixed on the previous call to inferTypeArguments.
// It would be just as correct to reset all of them. But then we'd be repeating the same work
// for the type parameters that were fixed, namely the work done by getInferredType.
if (!inference.isFixed) {
inference.inferredType = undefined;
}
}
if (ts.isJsxOpeningLikeElement(node)) {
return inferJsxTypeArguments(node, signature, checkMode, context);
}
@ -49748,10 +49740,11 @@ var ts;
if (node.kind !== 152 /* Decorator */) {
var contextualType = getContextualType(node);
if (contextualType) {
// We clone the contextual mapper to avoid disturbing a resolution in progress for an
// We clone the inference context to avoid disturbing a resolution in progress for an
// outer call expression. Effectively we just want a snapshot of whatever has been
// inferred for any outer call expression so far.
var instantiatedType = instantiateType(contextualType, cloneTypeMapper(getContextualMapper(node), 1 /* NoDefault */));
var outerMapper = getMapperFromContext(cloneInferenceContext(getInferenceContext(node), 1 /* NoDefault */));
var instantiatedType = instantiateType(contextualType, outerMapper);
// If the contextual type is a generic function type with a single call signature, we
// instantiate the type with its own type parameters and type arguments. This ensures that
// the type parameters are not erased to type any during type inference such that they can
@ -49768,7 +49761,7 @@ var ts;
inferTypes(context.inferences, inferenceSourceType, inferenceTargetType, 8 /* ReturnType */);
// Create a type mapper for instantiating generic contextual types using the inferences made
// from the return type.
context.returnMapper = cloneInferredPartOfContext(context);
context.returnMapper = getMapperFromContext(cloneInferredPartOfContext(context));
}
}
var thisType = getThisTypeOfSignature(signature);
@ -49871,7 +49864,7 @@ var ts;
// However "context" and "updater" are implicit and can't be specify by users. Only the first parameter, props,
// can be specified by users through attributes property.
var paramType = getEffectiveFirstArgumentForJsxSignature(signature, node);
var attributesType = checkExpressionWithContextualType(node.attributes, paramType, /*contextualMapper*/ undefined, checkMode);
var attributesType = checkExpressionWithContextualType(node.attributes, paramType, /*inferenceContext*/ undefined, checkMode);
return checkTypeRelatedToAndOptionallyElaborate(attributesType, paramType, relation, reportErrors ? node.tagName : undefined, node.attributes);
}
function checkApplicableSignature(node, args, signature, relation, checkMode, reportErrors) {
@ -49898,7 +49891,7 @@ var ts;
var arg = args[i];
if (arg.kind !== 210 /* OmittedExpression */) {
var paramType = getTypeAtPosition(signature, i);
var argType = checkExpressionWithContextualType(arg, paramType, /*contextualMapper*/ undefined, checkMode);
var argType = checkExpressionWithContextualType(arg, paramType, /*inferenceContext*/ undefined, checkMode);
// If one or more arguments are still excluded (as indicated by CheckMode.SkipContextSensitive),
// we obtain the regular type of any object literal arguments because we may not have inferred complete
// parameter types yet and therefore excess property checks may yield false positives (see #17041).
@ -50254,7 +50247,7 @@ var ts;
else {
inferenceContext = createInferenceContext(candidate.typeParameters, candidate, /*flags*/ ts.isInJSFile(node) ? 2 /* AnyDefault */ : 0 /* None */);
typeArgumentTypes = inferTypeArguments(node, candidate, args, argCheckMode | 8 /* SkipGenericFunctions */, inferenceContext);
argCheckMode |= inferenceContext.flags & 8 /* SkippedGenericFunction */ ? 8 /* SkipGenericFunctions */ : 0 /* Normal */;
argCheckMode |= inferenceContext.flags & 4 /* SkippedGenericFunction */ ? 8 /* SkipGenericFunctions */ : 0 /* Normal */;
}
checkCandidate = getSignatureInstantiation(candidate, typeArgumentTypes, ts.isInJSFile(candidate.declaration), inferenceContext && inferenceContext.inferredTypeParameters);
// If the original signature has a generic rest type, instantiation may produce a
@ -51168,9 +51161,14 @@ var ts;
return getTypeOfParameter(signature.parameters[pos]);
}
if (signature.hasRestParameter) {
// We want to return the value undefined for an out of bounds parameter position,
// so we need to check bounds here before calling getIndexedAccessType (which
// otherwise would return the type 'undefined').
var restType = getTypeOfSymbol(signature.parameters[paramCount]);
var indexType = getLiteralType(pos - paramCount);
return getIndexedAccessType(restType, indexType);
var index = pos - paramCount;
if (!isTupleType(restType) || restType.target.hasRestElement || index < (restType.typeArguments || ts.emptyArray).length) {
return getIndexedAccessType(restType, getLiteralType(index));
}
}
return undefined;
}
@ -51241,14 +51239,14 @@ var ts;
function getTypeOfFirstParameterOfSignatureWithFallback(signature, fallbackType) {
return signature.parameters.length > 0 ? getTypeAtPosition(signature, 0) : fallbackType;
}
function inferFromAnnotatedParameters(signature, context, mapper) {
function inferFromAnnotatedParameters(signature, context, inferenceContext) {
var len = signature.parameters.length - (signature.hasRestParameter ? 1 : 0);
for (var i = 0; i < len; i++) {
var declaration = signature.parameters[i].valueDeclaration;
if (declaration.type) {
var typeNode = ts.getEffectiveTypeAnnotationNode(declaration);
if (typeNode) {
inferTypes(mapper.inferences, getTypeFromTypeNode(typeNode), getTypeAtPosition(context, i));
inferTypes(inferenceContext.inferences, getTypeFromTypeNode(typeNode), getTypeAtPosition(context, i));
}
}
}
@ -51256,12 +51254,12 @@ var ts;
if (restType && restType.flags & 262144 /* TypeParameter */) {
// The contextual signature has a generic rest parameter. We first instantiate the contextual
// signature (without fixing type parameters) and assign types to contextually typed parameters.
var instantiatedContext = instantiateSignature(context, cloneTypeMapper(mapper));
var instantiatedContext = instantiateSignature(context, inferenceContext.nonFixingMapper);
assignContextualParameterTypes(signature, instantiatedContext);
// We then infer from a tuple type representing the parameters that correspond to the contextual
// rest parameter.
var restPos = getParameterCount(context) - 1;
inferTypes(mapper.inferences, getRestTypeAtPosition(signature, restPos), restType);
inferTypes(inferenceContext.inferences, getRestTypeAtPosition(signature, restPos), restType);
}
}
function assignContextualParameterTypes(signature, context) {
@ -51670,12 +51668,12 @@ var ts;
if (contextualSignature) {
var signature = getSignaturesOfType(type, 0 /* Call */)[0];
if (isContextSensitive(node)) {
var contextualMapper = getContextualMapper(node);
var inferenceContext = getInferenceContext(node);
if (checkMode && checkMode & 2 /* Inferential */) {
inferFromAnnotatedParameters(signature, contextualSignature, contextualMapper);
inferFromAnnotatedParameters(signature, contextualSignature, inferenceContext);
}
var instantiatedContextualSignature = contextualMapper === identityMapper ?
contextualSignature : instantiateSignature(contextualSignature, contextualMapper);
var instantiatedContextualSignature = inferenceContext ?
instantiateSignature(contextualSignature, inferenceContext.mapper) : contextualSignature;
assignContextualParameterTypes(signature, instantiatedContextualSignature);
}
if (!getReturnTypeFromAnnotation(node) && !signature.resolvedReturnType) {
@ -52593,20 +52591,20 @@ var ts;
}
return node;
}
function checkExpressionWithContextualType(node, contextualType, contextualMapper, checkMode) {
function checkExpressionWithContextualType(node, contextualType, inferenceContext, checkMode) {
var context = getContextNode(node);
var saveContextualType = context.contextualType;
var saveContextualMapper = context.contextualMapper;
var saveInferenceContext = context.inferenceContext;
context.contextualType = contextualType;
context.contextualMapper = contextualMapper;
var type = checkExpression(node, checkMode | 1 /* Contextual */ | (contextualMapper ? 2 /* Inferential */ : 0));
context.inferenceContext = inferenceContext;
var type = checkExpression(node, checkMode | 1 /* Contextual */ | (inferenceContext ? 2 /* Inferential */ : 0));
// We strip literal freshness when an appropriate contextual type is present such that contextually typed
// literals always preserve their literal types (otherwise they might widen during type inference). An alternative
// here would be to not mark contextually typed literals as fresh in the first place.
var result = maybeTypeOfKind(type, 2944 /* Literal */) && isLiteralOfContextualType(type, instantiateContextualType(contextualType, node)) ?
getRegularTypeOfLiteralType(type) : type;
context.contextualType = saveContextualType;
context.contextualMapper = saveContextualMapper;
context.inferenceContext = saveInferenceContext;
return result;
}
function checkExpressionCached(node, checkMode) {
@ -52720,7 +52718,7 @@ var ts;
if (contextualType) {
var contextualSignature = getSingleCallSignature(getNonNullableType(contextualType));
if (contextualSignature && !contextualSignature.typeParameters) {
var context = getContextualMapper(node);
var context = getInferenceContext(node);
// We have an expression that is an argument of a generic function for which we are performing
// type argument inference. The expression is of a function type with a single generic call
// signature and a contextual function type with a single non-generic call signature. Now check
@ -52736,7 +52734,7 @@ var ts;
var strippedType = getOrCreateTypeFromSignature(getSignatureInstantiationWithoutFillingInTypeArguments(signature, uniqueTypeParameters));
// Infer from the stripped expression type to the contextual type starting with an empty
// set of inference candidates.
var inferences = ts.map(context.typeParameters, createInferenceInfo);
var inferences = ts.map(context.inferences, function (info) { return createInferenceInfo(info.typeParameter); });
inferTypes(inferences, strippedType, contextualType);
// If we produced some inference candidates and if the type parameters for which we produced
// candidates do not already have existing inferences, we adopt the new inference candidates and
@ -52759,8 +52757,8 @@ var ts;
if (checkMode & 2 /* Inferential */) {
// We have skipped a generic function during inferential typing. Obtain the inference context and
// indicate this has occurred such that we know a second pass of inference is be needed.
var context = getContextualMapper(node);
context.flags |= 8 /* SkippedGenericFunction */;
var context = getInferenceContext(node);
context.flags |= 4 /* SkippedGenericFunction */;
}
}
function hasInferenceCandidates(info) {
@ -52868,13 +52866,6 @@ var ts;
node.contextualType = saveContextualType;
return type;
}
// Checks an expression and returns its type. The contextualMapper parameter serves two purposes: When
// contextualMapper is not undefined and not equal to the identityMapper function object it indicates that the
// expression is being inferentially typed (section 4.15.2 in spec) and provides the type mapper to use in
// conjunction with the generic contextual type. When contextualMapper is equal to the identityMapper function
// object, it serves as an indicator that all contained function and arrow expressions should be considered to
// have the wildcard function type; this form of type check is used during overload resolution to exclude
// contextually typed function and arrow expressions in the initial phase.
function checkExpression(node, checkMode, forceTuple) {
var saveCurrentNode = currentNode;
currentNode = node;
@ -62268,6 +62259,28 @@ var ts;
return node;
}
ts.createJsxFragment = createJsxFragment;
function createJsxText(text, containsOnlyTriviaWhiteSpaces) {
var node = createSynthesizedNode(11 /* JsxText */);
node.text = text;
node.containsOnlyTriviaWhiteSpaces = !!containsOnlyTriviaWhiteSpaces;
return node;
}
ts.createJsxText = createJsxText;
function updateJsxText(node, text, containsOnlyTriviaWhiteSpaces) {
return node.text !== text
|| node.containsOnlyTriviaWhiteSpaces !== containsOnlyTriviaWhiteSpaces
? updateNode(createJsxText(text, containsOnlyTriviaWhiteSpaces), node)
: node;
}
ts.updateJsxText = updateJsxText;
function createJsxOpeningFragment() {
return createSynthesizedNode(265 /* JsxOpeningFragment */);
}
ts.createJsxOpeningFragment = createJsxOpeningFragment;
function createJsxJsxClosingFragment() {
return createSynthesizedNode(266 /* JsxClosingFragment */);
}
ts.createJsxJsxClosingFragment = createJsxJsxClosingFragment;
function updateJsxFragment(node, openingFragment, children, closingFragment) {
return node.openingFragment !== openingFragment
|| node.children !== children
@ -71496,7 +71509,7 @@ var ts;
}
}
function visitJsxText(node) {
var fixed = fixupWhitespaceAndDecodeEntities(ts.getTextOfNode(node, /*includeTrivia*/ true));
var fixed = fixupWhitespaceAndDecodeEntities(node.text);
return fixed === undefined ? undefined : ts.createLiteral(fixed);
}
/**
@ -85355,7 +85368,7 @@ var ts;
writePunctuation(">");
}
function emitJsxText(node) {
writer.writeLiteral(getTextOfNode(node, /*includeTrivia*/ true));
writer.writeLiteral(node.text);
}
function emitJsxClosingElementOrFragment(node) {
writePunctuation("</");
@ -92747,7 +92760,7 @@ var ts;
}
}
ts.createCompilerHostFromProgramHost = createCompilerHostFromProgramHost;
function setCreateSourceFileAsHashVersioned(compilerHost, host) {
function setGetSourceFileAsHashVersioned(compilerHost, host) {
var originalGetSourceFile = compilerHost.getSourceFile;
var computeHash = host.createHash || ts.generateDjb2Hash;
compilerHost.getSourceFile = function () {
@ -92762,7 +92775,7 @@ var ts;
return result;
};
}
ts.setCreateSourceFileAsHashVersioned = setCreateSourceFileAsHashVersioned;
ts.setGetSourceFileAsHashVersioned = setGetSourceFileAsHashVersioned;
/**
* Creates the watch compiler host that can be extended with config file or root file names and options host
*/
@ -92910,7 +92923,7 @@ var ts;
configFileWatcher = watchFile(host, configFileName, scheduleProgramReload, ts.PollingInterval.High, "Config file" /* ConfigFile */);
}
var compilerHost = ts.createCompilerHostFromProgramHost(host, function () { return compilerOptions; }, directoryStructureHost);
ts.setCreateSourceFileAsHashVersioned(compilerHost, host);
ts.setGetSourceFileAsHashVersioned(compilerHost, host);
// Members for CompilerHost
var getNewSourceFile = compilerHost.getSourceFile;
compilerHost.getSourceFile = function (fileName) {
@ -93497,7 +93510,7 @@ var ts;
var readFileWithCache = function (f) { return host.readFile(f); };
var projectCompilerOptions = baseCompilerOptions;
var compilerHost = ts.createCompilerHostFromProgramHost(host, function () { return projectCompilerOptions; });
ts.setCreateSourceFileAsHashVersioned(compilerHost, host);
ts.setGetSourceFileAsHashVersioned(compilerHost, host);
var buildInfoChecked = createFileMap(toPath);
// Watch state
var builderPrograms = createFileMap(toPath);
@ -96033,7 +96046,7 @@ var ts;
}
ts.isInsideJsxElementOrAttribute = isInsideJsxElementOrAttribute;
function isWhiteSpaceOnlyJsxText(node) {
return ts.isJsxText(node) && node.containsOnlyWhiteSpaces;
return ts.isJsxText(node) && node.containsOnlyTriviaWhiteSpaces;
}
function isInTemplateString(sourceFile, position) {
var token = getTokenAtPosition(sourceFile, position);
@ -106763,7 +106776,7 @@ var ts;
var parameters = (typeParameters || ts.emptyArray).map(function (t) { return createSignatureHelpParameterForTypeParameter(t, checker, enclosingDeclaration, sourceFile, printer); });
var parameterParts = ts.mapToDisplayParts(function (writer) {
var thisParameter = candidateSignature.thisParameter ? [checker.symbolToParameterDeclaration(candidateSignature.thisParameter, enclosingDeclaration, signatureHelpNodeBuilderFlags)] : [];
var params = ts.createNodeArray(thisParameter.concat(candidateSignature.parameters.map(function (param) { return checker.symbolToParameterDeclaration(param, enclosingDeclaration, signatureHelpNodeBuilderFlags); })));
var params = ts.createNodeArray(thisParameter.concat(checker.getExpandedParameters(candidateSignature).map(function (param) { return checker.symbolToParameterDeclaration(param, enclosingDeclaration, signatureHelpNodeBuilderFlags); })));
printer.writeList(2576 /* CallExpressionArguments */, params, sourceFile, writer);
});
return { isVariadic: false, parameters: parameters, prefix: [ts.punctuationPart(28 /* LessThanToken */)], suffix: [ts.punctuationPart(30 /* GreaterThanToken */)].concat(parameterParts) };
@ -106777,7 +106790,7 @@ var ts;
printer.writeList(53776 /* TypeParameters */, args, sourceFile, writer);
}
});
var parameters = candidateSignature.parameters.map(function (p) { return createSignatureHelpParameterForParameter(p, checker, enclosingDeclaration, sourceFile, printer); });
var parameters = checker.getExpandedParameters(candidateSignature).map(function (p) { return createSignatureHelpParameterForParameter(p, checker, enclosingDeclaration, sourceFile, printer); });
return { isVariadic: isVariadic, parameters: parameters, prefix: typeParameterParts.concat([ts.punctuationPart(20 /* OpenParenToken */)]), suffix: [ts.punctuationPart(21 /* CloseParenToken */)] };
}
function createSignatureHelpParameterForParameter(parameter, checker, enclosingDeclaration, sourceFile, printer) {
@ -120647,9 +120660,9 @@ var ts;
}());
ts.ThrottledCancellationToken = ThrottledCancellationToken;
function createLanguageService(host, documentRegistry, syntaxOnly) {
var _a;
if (documentRegistry === void 0) { documentRegistry = ts.createDocumentRegistry(host.useCaseSensitiveFileNames && host.useCaseSensitiveFileNames(), host.getCurrentDirectory()); }
if (syntaxOnly === void 0) { syntaxOnly = false; }
var _a;
var syntaxTreeCache = new SyntaxTreeCache(host);
var program;
var lastProjectVersion;

View File

@ -76,7 +76,7 @@ var ts;
// If changing the text in this section, be sure to test `configureNightly` too.
ts.versionMajorMinor = "3.4";
/** The version of the TypeScript compiler release */
ts.version = ts.versionMajorMinor + ".0-dev";
ts.version = ts.versionMajorMinor + ".0-rc";
})(ts || (ts = {}));
(function (ts) {
/* @internal */
@ -3576,8 +3576,7 @@ var ts;
InferenceFlags[InferenceFlags["None"] = 0] = "None";
InferenceFlags[InferenceFlags["NoDefault"] = 1] = "NoDefault";
InferenceFlags[InferenceFlags["AnyDefault"] = 2] = "AnyDefault";
InferenceFlags[InferenceFlags["NoFixing"] = 4] = "NoFixing";
InferenceFlags[InferenceFlags["SkippedGenericFunction"] = 8] = "SkippedGenericFunction";
InferenceFlags[InferenceFlags["SkippedGenericFunction"] = 4] = "SkippedGenericFunction";
})(InferenceFlags = ts.InferenceFlags || (ts.InferenceFlags = {}));
/**
* Ternary values are defined such that
@ -4149,8 +4148,11 @@ var ts;
*/
/* @internal */
function generateDjb2Hash(data) {
var chars = data.split("").map(function (str) { return str.charCodeAt(0); });
return "" + chars.reduce(function (prev, curr) { return ((prev << 5) + prev) + curr; }, 5381);
var acc = 5381;
for (var i = 0; i < data.length; i++) {
acc = ((acc << 5) + acc) + data.charCodeAt(i);
}
return acc.toString();
}
ts.generateDjb2Hash = generateDjb2Hash;
/**
@ -8144,6 +8146,7 @@ var ts;
}
pos++;
}
tokenValue = text.substring(startPos, pos);
return firstNonWhitespace === -1 ? 12 /* JsxTextAllWhiteSpaces */ : 11 /* JsxText */;
}
// Scans a JSX identifier; these differ from normal identifiers in that
@ -20263,7 +20266,8 @@ var ts;
}
function parseJsxText() {
var node = createNode(11 /* JsxText */);
node.containsOnlyWhiteSpaces = currentToken === 12 /* JsxTextAllWhiteSpaces */;
node.text = scanner.getTokenValue();
node.containsOnlyTriviaWhiteSpaces = currentToken === 12 /* JsxTextAllWhiteSpaces */;
currentToken = scanner.scanJsxToken();
return finishNode(node);
}
@ -31269,6 +31273,7 @@ var ts;
getResolvedSignatureForSignatureHelp: function (node, candidatesOutArray, agumentCount) {
return getResolvedSignatureWorker(node, candidatesOutArray, agumentCount, 16 /* IsForSignatureHelp */);
},
getExpandedParameters: getExpandedParameters,
getConstantValue: function (nodeIn) {
var node = ts.getParseTreeNode(nodeIn, canHaveConstantValue);
return node ? getConstantValue(node) : undefined;
@ -31765,11 +31770,11 @@ var ts;
}
}
function addRelatedInfo(diagnostic) {
var _a;
var relatedInformation = [];
for (var _i = 1; _i < arguments.length; _i++) {
relatedInformation[_i - 1] = arguments[_i];
}
var _a;
if (!diagnostic.relatedInformation) {
diagnostic.relatedInformation = [];
}
@ -37289,8 +37294,18 @@ var ts;
return sig;
}
function cloneSignature(sig) {
return createSignature(sig.declaration, sig.typeParameters, sig.thisParameter, sig.parameters, /*resolvedReturnType*/ undefined,
var result = createSignature(sig.declaration, sig.typeParameters, sig.thisParameter, sig.parameters, /*resolvedReturnType*/ undefined,
/*resolvedTypePredicate*/ undefined, sig.minArgumentCount, sig.hasRestParameter, sig.hasLiteralTypes);
result.target = sig.target;
result.mapper = sig.mapper;
return result;
}
function createUnionSignature(signature, unionSignatures) {
var result = cloneSignature(signature);
result.unionSignatures = unionSignatures;
result.target = undefined;
result.mapper = undefined;
return result;
}
function getExpandedParameters(sig) {
if (sig.hasRestParameter) {
@ -37399,9 +37414,8 @@ var ts;
var thisType = getUnionType(ts.map(unionSignatures, function (sig) { return sig.thisParameter ? getTypeOfSymbol(sig.thisParameter) : anyType; }), 2 /* Subtype */);
thisParameter = createSymbolWithType(signature.thisParameter, thisType);
}
s = cloneSignature(signature);
s = createUnionSignature(signature, unionSignatures);
s.thisParameter = thisParameter;
s.unionSignatures = unionSignatures;
}
(result || (result = [])).push(s);
}
@ -38798,8 +38812,6 @@ var ts;
if (returnSignature) {
var newReturnSignature = cloneSignature(returnSignature);
newReturnSignature.typeParameters = inferredTypeParameters;
newReturnSignature.target = returnSignature.target;
newReturnSignature.mapper = returnSignature.mapper;
var newInstantiatedSignature = cloneSignature(instantiatedSignature);
newInstantiatedSignature.resolvedReturnType = getOrCreateTypeFromSignature(newReturnSignature);
return newInstantiatedSignature;
@ -40412,7 +40424,7 @@ var ts;
// types rules (i.e. proper contravariance) for inferences.
inferTypes(context.inferences, checkType, extendsType, 32 /* NoConstraints */ | 64 /* AlwaysStrict */);
}
combinedMapper = combineTypeMappers(mapper, context);
combinedMapper = combineTypeMappers(mapper, context.mapper);
}
// Instantiate the extends type including inferences for 'infer T' type parameters
var inferredExtendsType = combinedMapper ? instantiateType(root.extendsType, combinedMapper) : extendsType;
@ -40965,33 +40977,8 @@ var ts;
* Maps forward-references to later types parameters to the empty object type.
* This is used during inference when instantiating type parameter defaults.
*/
function createBackreferenceMapper(typeParameters, index) {
return function (t) { return typeParameters.indexOf(t) >= index ? emptyObjectType : t; };
}
function isInferenceContext(mapper) {
return !!mapper.typeParameters;
}
function cloneTypeMapper(mapper, extraFlags) {
if (extraFlags === void 0) { extraFlags = 0; }
return mapper && isInferenceContext(mapper) ?
createInferenceContext(mapper.typeParameters, mapper.signature, mapper.flags | extraFlags, mapper.compareTypes, mapper.inferences) :
mapper;
}
function cloneInferredPartOfContext(context) {
// Filter context to only those parameters which actually have inference candidates
var params = [];
var inferences = [];
for (var i = 0; i < context.typeParameters.length; i++) {
var info = context.inferences[i];
if (info.candidates || info.contraCandidates) {
params.push(context.typeParameters[i]);
inferences.push(info);
}
}
if (!params.length) {
return undefined;
}
return createInferenceContext(params, context.signature, context.flags | 1 /* NoDefault */, context.compareTypes, inferences);
function createBackreferenceMapper(context, index) {
return function (t) { return ts.findIndex(context.inferences, function (info) { return info.typeParameter === t; }) >= index ? emptyObjectType : t; };
}
function combineTypeMappers(mapper1, mapper2) {
if (!mapper1)
@ -41728,7 +41715,7 @@ var ts;
// child is of the type of the expression
return { errorNode: child, innerExpression: child.expression, nameType: nameType };
case 11 /* JsxText */:
if (child.containsOnlyWhiteSpaces) {
if (child.containsOnlyTriviaWhiteSpaces) {
break; // Whitespace only jsx text isn't real jsx text
}
// child is a string
@ -41751,7 +41738,7 @@ var ts;
var childrenPropName = childPropName === undefined ? "children" : ts.unescapeLeadingUnderscores(childPropName);
var childrenNameType = getLiteralType(childrenPropName);
var childrenTargetType = getIndexedAccessType(target, childrenNameType);
var validChildren = ts.filter(containingElement.children, function (i) { return !ts.isJsxText(i) || !i.containsOnlyWhiteSpaces; });
var validChildren = ts.filter(containingElement.children, function (i) { return !ts.isJsxText(i) || !i.containsOnlyTriviaWhiteSpaces; });
if (!ts.length(validChildren)) {
return result;
}
@ -41918,7 +41905,7 @@ var ts;
}
if (source.typeParameters && source.typeParameters !== target.typeParameters) {
target = getCanonicalSignature(target);
source = instantiateSignatureInContextOf(source, target, /*contextualMapper*/ undefined, compareTypes);
source = instantiateSignatureInContextOf(source, target, /*inferenceContext*/ undefined, compareTypes);
}
var sourceCount = getParameterCount(source);
var sourceRestType = getNonArrayRestType(source);
@ -44327,26 +44314,43 @@ var ts;
callback(getRestTypeAtPosition(source, paramCount), targetRestType);
}
}
function createInferenceContext(typeParameters, signature, flags, compareTypes, baseInferences) {
var inferences = baseInferences ? baseInferences.map(cloneInferenceInfo) : typeParameters.map(createInferenceInfo);
var context = mapper;
context.typeParameters = typeParameters;
context.signature = signature;
context.inferences = inferences;
context.flags = flags;
context.compareTypes = compareTypes || compareTypesAssignable;
function createInferenceContext(typeParameters, signature, flags, compareTypes) {
return createInferenceContextWorker(typeParameters.map(createInferenceInfo), signature, flags, compareTypes || compareTypesAssignable);
}
function cloneInferenceContext(context, extraFlags) {
if (extraFlags === void 0) { extraFlags = 0; }
return context && createInferenceContextWorker(ts.map(context.inferences, cloneInferenceInfo), context.signature, context.flags | extraFlags, context.compareTypes);
}
function cloneInferredPartOfContext(context) {
var inferences = ts.filter(context.inferences, hasInferenceCandidates);
return inferences.length ?
createInferenceContextWorker(ts.map(inferences, cloneInferenceInfo), context.signature, context.flags, context.compareTypes) :
undefined;
}
function createInferenceContextWorker(inferences, signature, flags, compareTypes) {
var context = {
inferences: inferences,
signature: signature,
flags: flags,
compareTypes: compareTypes,
mapper: function (t) { return mapToInferredType(context, t, /*fix*/ true); },
nonFixingMapper: function (t) { return mapToInferredType(context, t, /*fix*/ false); },
};
return context;
function mapper(t) {
for (var i = 0; i < inferences.length; i++) {
if (t === inferences[i].typeParameter) {
if (!(context.flags & 4 /* NoFixing */)) {
inferences[i].isFixed = true;
}
return getInferredType(context, i);
}
function mapToInferredType(context, t, fix) {
var inferences = context.inferences;
for (var i = 0; i < inferences.length; i++) {
var inference = inferences[i];
if (t === inference.typeParameter) {
if (fix && !inference.isFixed) {
inference.isFixed = true;
inference.inferredType = undefined;
}
return getInferredType(context, i);
}
return t;
}
return t;
}
function createInferenceInfo(typeParameter) {
return {
@ -44370,6 +44374,9 @@ var ts;
isFixed: inference.isFixed
};
}
function getMapperFromContext(context) {
return context && context.mapper;
}
// Return true if the given type could possibly reference a type parameter for which
// we perform type inference (i.e. a type parameter of a generic function). We cache
// results for union and intersection types for performance reasons.
@ -44617,15 +44624,18 @@ var ts;
var candidate = propagationType || source;
// We make contravariant inferences only if we are in a pure contravariant position,
// i.e. only if we have not descended into a bivariant position.
if (contravariant && !bivariant) {
inference.contraCandidates = ts.appendIfUnique(inference.contraCandidates, candidate);
if (contravariant && !bivariant && !ts.contains(inference.contraCandidates, candidate)) {
inference.contraCandidates = ts.append(inference.contraCandidates, candidate);
inference.inferredType = undefined;
}
else {
inference.candidates = ts.appendIfUnique(inference.candidates, candidate);
else if (!ts.contains(inference.candidates, candidate)) {
inference.candidates = ts.append(inference.candidates, candidate);
inference.inferredType = undefined;
}
}
if (!(priority & 8 /* ReturnType */) && target.flags & 262144 /* TypeParameter */ && !isTypeParameterAtTopLevel(originalTarget, target)) {
if (!(priority & 8 /* ReturnType */) && target.flags & 262144 /* TypeParameter */ && inference.topLevel && !isTypeParameterAtTopLevel(originalTarget, target)) {
inference.topLevel = false;
inference.inferredType = undefined;
}
}
return;
@ -44691,7 +44701,7 @@ var ts;
inferFromTypes(getTrueTypeFromConditionalType(source), getTrueTypeFromConditionalType(target));
inferFromTypes(getFalseTypeFromConditionalType(source), getFalseTypeFromConditionalType(target));
}
else if (target.flags & 16777216 /* Conditional */) {
else if (target.flags & 16777216 /* Conditional */ && !contravariant) {
inferFromTypes(source, getTrueTypeFromConditionalType(target));
inferFromTypes(source, getFalseTypeFromConditionalType(target));
}
@ -45044,7 +45054,7 @@ var ts;
if (defaultType) {
// Instantiate the default type. Any forward reference to a type
// parameter should be instantiated to the empty object type.
inferredType = instantiateType(defaultType, combineTypeMappers(createBackreferenceMapper(context.typeParameters, index), context));
inferredType = instantiateType(defaultType, combineTypeMappers(createBackreferenceMapper(context, index), context.nonFixingMapper));
}
else {
inferredType = getDefaultTypeArgumentType(!!(context.flags & 2 /* AnyDefault */));
@ -45057,12 +45067,10 @@ var ts;
inference.inferredType = inferredType;
var constraint = getConstraintOfTypeParameter(inference.typeParameter);
if (constraint) {
context.flags |= 4 /* NoFixing */;
var instantiatedConstraint = instantiateType(constraint, context);
var instantiatedConstraint = instantiateType(constraint, context.nonFixingMapper);
if (!context.compareTypes(inferredType, getTypeWithThisArgument(instantiatedConstraint, inferredType))) {
inference.inferredType = inferredType = instantiatedConstraint;
}
context.flags &= ~4 /* NoFixing */;
}
}
return inferredType;
@ -47337,7 +47345,7 @@ var ts;
while (type) {
var thisType = getThisTypeFromContextualType(type);
if (thisType) {
return instantiateType(thisType, getContextualMapper(containingLiteral));
return instantiateType(thisType, getMapperFromContext(getInferenceContext(containingLiteral)));
}
if (literal.parent.kind !== 275 /* PropertyAssignment */) {
break;
@ -47786,9 +47794,9 @@ var ts;
// return type inferences is available, instantiate those types using that mapper.
function instantiateContextualType(contextualType, node) {
if (contextualType && maybeTypeOfKind(contextualType, 63176704 /* Instantiable */)) {
var returnMapper = getContextualMapper(node).returnMapper;
if (returnMapper) {
return instantiateInstantiableTypes(contextualType, returnMapper);
var inferenceContext = getInferenceContext(node);
if (inferenceContext && inferenceContext.returnMapper) {
return instantiateInstantiableTypes(contextualType, inferenceContext.returnMapper);
}
}
return contextualType;
@ -47887,9 +47895,9 @@ var ts;
}
return undefined;
}
function getContextualMapper(node) {
var ancestor = ts.findAncestor(node, function (n) { return !!n.contextualMapper; });
return ancestor ? ancestor.contextualMapper : identityMapper;
function getInferenceContext(node) {
var ancestor = ts.findAncestor(node, function (n) { return !!n.inferenceContext; });
return ancestor && ancestor.inferenceContext;
}
function getContextualJsxElementAttributesType(node) {
if (ts.isJsxOpeningElement(node) && node.parent.contextualType) {
@ -48089,12 +48097,7 @@ var ts;
}
}
// Result is union of signatures collected (return type is union of return types of this signature set)
var result;
if (signatureList) {
result = cloneSignature(signatureList[0]);
result.unionSignatures = signatureList;
}
return result;
return signatureList && createUnionSignature(signatureList[0], signatureList);
}
function checkSpreadExpression(node, checkMode) {
if (languageVersion < 2 /* ES2015 */ && compilerOptions.downlevelIteration) {
@ -48612,7 +48615,7 @@ var ts;
// In React, JSX text that contains only whitespaces will be ignored so we don't want to type-check that
// because then type of children property will have constituent of string type.
if (child.kind === 11 /* JsxText */) {
if (!child.containsOnlyWhiteSpaces) {
if (!child.containsOnlyTriviaWhiteSpaces) {
childrenTypes.push(stringType);
}
}
@ -49698,19 +49701,19 @@ var ts;
return undefined;
}
// Instantiate a generic signature in the context of a non-generic signature (section 3.8.5 in TypeScript spec)
function instantiateSignatureInContextOf(signature, contextualSignature, contextualMapper, compareTypes) {
function instantiateSignatureInContextOf(signature, contextualSignature, inferenceContext, compareTypes) {
var context = createInferenceContext(signature.typeParameters, signature, 0 /* None */, compareTypes);
// We clone the contextualMapper to avoid fixing. For example, when the source signature is <T>(x: T) => T[] and
// We clone the inferenceContext to avoid fixing. For example, when the source signature is <T>(x: T) => T[] and
// the contextual signature is (...args: A) => B, we want to infer the element type of A's constraint (say 'any')
// for T but leave it possible to later infer '[any]' back to A.
var restType = getEffectiveRestType(contextualSignature);
var mapper = contextualMapper && restType && restType.flags & 262144 /* TypeParameter */ ? cloneTypeMapper(contextualMapper) : contextualMapper;
var mapper = inferenceContext && (restType && restType.flags & 262144 /* TypeParameter */ ? inferenceContext.nonFixingMapper : inferenceContext.mapper);
var sourceSignature = mapper ? instantiateSignature(contextualSignature, mapper) : contextualSignature;
forEachMatchingParameterType(sourceSignature, signature, function (source, target) {
// Type parameters from outer context referenced by source type are fixed by instantiation of the source type
inferTypes(context.inferences, source, target);
});
if (!contextualMapper) {
if (!inferenceContext) {
inferTypes(context.inferences, getReturnTypeOfSignature(contextualSignature), getReturnTypeOfSignature(signature), 8 /* ReturnType */);
var signaturePredicate = getTypePredicateOfSignature(signature);
var contextualPredicate = getTypePredicateOfSignature(sourceSignature);
@ -49728,17 +49731,6 @@ var ts;
return getInferredTypes(context);
}
function inferTypeArguments(node, signature, args, checkMode, context) {
// Clear out all the inference results from the last time inferTypeArguments was called on this context
for (var _i = 0, _a = context.inferences; _i < _a.length; _i++) {
var inference = _a[_i];
// As an optimization, we don't have to clear (and later recompute) inferred types
// for type parameters that have already been fixed on the previous call to inferTypeArguments.
// It would be just as correct to reset all of them. But then we'd be repeating the same work
// for the type parameters that were fixed, namely the work done by getInferredType.
if (!inference.isFixed) {
inference.inferredType = undefined;
}
}
if (ts.isJsxOpeningLikeElement(node)) {
return inferJsxTypeArguments(node, signature, checkMode, context);
}
@ -49749,10 +49741,11 @@ var ts;
if (node.kind !== 152 /* Decorator */) {
var contextualType = getContextualType(node);
if (contextualType) {
// We clone the contextual mapper to avoid disturbing a resolution in progress for an
// We clone the inference context to avoid disturbing a resolution in progress for an
// outer call expression. Effectively we just want a snapshot of whatever has been
// inferred for any outer call expression so far.
var instantiatedType = instantiateType(contextualType, cloneTypeMapper(getContextualMapper(node), 1 /* NoDefault */));
var outerMapper = getMapperFromContext(cloneInferenceContext(getInferenceContext(node), 1 /* NoDefault */));
var instantiatedType = instantiateType(contextualType, outerMapper);
// If the contextual type is a generic function type with a single call signature, we
// instantiate the type with its own type parameters and type arguments. This ensures that
// the type parameters are not erased to type any during type inference such that they can
@ -49769,7 +49762,7 @@ var ts;
inferTypes(context.inferences, inferenceSourceType, inferenceTargetType, 8 /* ReturnType */);
// Create a type mapper for instantiating generic contextual types using the inferences made
// from the return type.
context.returnMapper = cloneInferredPartOfContext(context);
context.returnMapper = getMapperFromContext(cloneInferredPartOfContext(context));
}
}
var thisType = getThisTypeOfSignature(signature);
@ -49872,7 +49865,7 @@ var ts;
// However "context" and "updater" are implicit and can't be specify by users. Only the first parameter, props,
// can be specified by users through attributes property.
var paramType = getEffectiveFirstArgumentForJsxSignature(signature, node);
var attributesType = checkExpressionWithContextualType(node.attributes, paramType, /*contextualMapper*/ undefined, checkMode);
var attributesType = checkExpressionWithContextualType(node.attributes, paramType, /*inferenceContext*/ undefined, checkMode);
return checkTypeRelatedToAndOptionallyElaborate(attributesType, paramType, relation, reportErrors ? node.tagName : undefined, node.attributes);
}
function checkApplicableSignature(node, args, signature, relation, checkMode, reportErrors) {
@ -49899,7 +49892,7 @@ var ts;
var arg = args[i];
if (arg.kind !== 210 /* OmittedExpression */) {
var paramType = getTypeAtPosition(signature, i);
var argType = checkExpressionWithContextualType(arg, paramType, /*contextualMapper*/ undefined, checkMode);
var argType = checkExpressionWithContextualType(arg, paramType, /*inferenceContext*/ undefined, checkMode);
// If one or more arguments are still excluded (as indicated by CheckMode.SkipContextSensitive),
// we obtain the regular type of any object literal arguments because we may not have inferred complete
// parameter types yet and therefore excess property checks may yield false positives (see #17041).
@ -50255,7 +50248,7 @@ var ts;
else {
inferenceContext = createInferenceContext(candidate.typeParameters, candidate, /*flags*/ ts.isInJSFile(node) ? 2 /* AnyDefault */ : 0 /* None */);
typeArgumentTypes = inferTypeArguments(node, candidate, args, argCheckMode | 8 /* SkipGenericFunctions */, inferenceContext);
argCheckMode |= inferenceContext.flags & 8 /* SkippedGenericFunction */ ? 8 /* SkipGenericFunctions */ : 0 /* Normal */;
argCheckMode |= inferenceContext.flags & 4 /* SkippedGenericFunction */ ? 8 /* SkipGenericFunctions */ : 0 /* Normal */;
}
checkCandidate = getSignatureInstantiation(candidate, typeArgumentTypes, ts.isInJSFile(candidate.declaration), inferenceContext && inferenceContext.inferredTypeParameters);
// If the original signature has a generic rest type, instantiation may produce a
@ -51169,9 +51162,14 @@ var ts;
return getTypeOfParameter(signature.parameters[pos]);
}
if (signature.hasRestParameter) {
// We want to return the value undefined for an out of bounds parameter position,
// so we need to check bounds here before calling getIndexedAccessType (which
// otherwise would return the type 'undefined').
var restType = getTypeOfSymbol(signature.parameters[paramCount]);
var indexType = getLiteralType(pos - paramCount);
return getIndexedAccessType(restType, indexType);
var index = pos - paramCount;
if (!isTupleType(restType) || restType.target.hasRestElement || index < (restType.typeArguments || ts.emptyArray).length) {
return getIndexedAccessType(restType, getLiteralType(index));
}
}
return undefined;
}
@ -51242,14 +51240,14 @@ var ts;
function getTypeOfFirstParameterOfSignatureWithFallback(signature, fallbackType) {
return signature.parameters.length > 0 ? getTypeAtPosition(signature, 0) : fallbackType;
}
function inferFromAnnotatedParameters(signature, context, mapper) {
function inferFromAnnotatedParameters(signature, context, inferenceContext) {
var len = signature.parameters.length - (signature.hasRestParameter ? 1 : 0);
for (var i = 0; i < len; i++) {
var declaration = signature.parameters[i].valueDeclaration;
if (declaration.type) {
var typeNode = ts.getEffectiveTypeAnnotationNode(declaration);
if (typeNode) {
inferTypes(mapper.inferences, getTypeFromTypeNode(typeNode), getTypeAtPosition(context, i));
inferTypes(inferenceContext.inferences, getTypeFromTypeNode(typeNode), getTypeAtPosition(context, i));
}
}
}
@ -51257,12 +51255,12 @@ var ts;
if (restType && restType.flags & 262144 /* TypeParameter */) {
// The contextual signature has a generic rest parameter. We first instantiate the contextual
// signature (without fixing type parameters) and assign types to contextually typed parameters.
var instantiatedContext = instantiateSignature(context, cloneTypeMapper(mapper));
var instantiatedContext = instantiateSignature(context, inferenceContext.nonFixingMapper);
assignContextualParameterTypes(signature, instantiatedContext);
// We then infer from a tuple type representing the parameters that correspond to the contextual
// rest parameter.
var restPos = getParameterCount(context) - 1;
inferTypes(mapper.inferences, getRestTypeAtPosition(signature, restPos), restType);
inferTypes(inferenceContext.inferences, getRestTypeAtPosition(signature, restPos), restType);
}
}
function assignContextualParameterTypes(signature, context) {
@ -51671,12 +51669,12 @@ var ts;
if (contextualSignature) {
var signature = getSignaturesOfType(type, 0 /* Call */)[0];
if (isContextSensitive(node)) {
var contextualMapper = getContextualMapper(node);
var inferenceContext = getInferenceContext(node);
if (checkMode && checkMode & 2 /* Inferential */) {
inferFromAnnotatedParameters(signature, contextualSignature, contextualMapper);
inferFromAnnotatedParameters(signature, contextualSignature, inferenceContext);
}
var instantiatedContextualSignature = contextualMapper === identityMapper ?
contextualSignature : instantiateSignature(contextualSignature, contextualMapper);
var instantiatedContextualSignature = inferenceContext ?
instantiateSignature(contextualSignature, inferenceContext.mapper) : contextualSignature;
assignContextualParameterTypes(signature, instantiatedContextualSignature);
}
if (!getReturnTypeFromAnnotation(node) && !signature.resolvedReturnType) {
@ -52594,20 +52592,20 @@ var ts;
}
return node;
}
function checkExpressionWithContextualType(node, contextualType, contextualMapper, checkMode) {
function checkExpressionWithContextualType(node, contextualType, inferenceContext, checkMode) {
var context = getContextNode(node);
var saveContextualType = context.contextualType;
var saveContextualMapper = context.contextualMapper;
var saveInferenceContext = context.inferenceContext;
context.contextualType = contextualType;
context.contextualMapper = contextualMapper;
var type = checkExpression(node, checkMode | 1 /* Contextual */ | (contextualMapper ? 2 /* Inferential */ : 0));
context.inferenceContext = inferenceContext;
var type = checkExpression(node, checkMode | 1 /* Contextual */ | (inferenceContext ? 2 /* Inferential */ : 0));
// We strip literal freshness when an appropriate contextual type is present such that contextually typed
// literals always preserve their literal types (otherwise they might widen during type inference). An alternative
// here would be to not mark contextually typed literals as fresh in the first place.
var result = maybeTypeOfKind(type, 2944 /* Literal */) && isLiteralOfContextualType(type, instantiateContextualType(contextualType, node)) ?
getRegularTypeOfLiteralType(type) : type;
context.contextualType = saveContextualType;
context.contextualMapper = saveContextualMapper;
context.inferenceContext = saveInferenceContext;
return result;
}
function checkExpressionCached(node, checkMode) {
@ -52721,7 +52719,7 @@ var ts;
if (contextualType) {
var contextualSignature = getSingleCallSignature(getNonNullableType(contextualType));
if (contextualSignature && !contextualSignature.typeParameters) {
var context = getContextualMapper(node);
var context = getInferenceContext(node);
// We have an expression that is an argument of a generic function for which we are performing
// type argument inference. The expression is of a function type with a single generic call
// signature and a contextual function type with a single non-generic call signature. Now check
@ -52737,7 +52735,7 @@ var ts;
var strippedType = getOrCreateTypeFromSignature(getSignatureInstantiationWithoutFillingInTypeArguments(signature, uniqueTypeParameters));
// Infer from the stripped expression type to the contextual type starting with an empty
// set of inference candidates.
var inferences = ts.map(context.typeParameters, createInferenceInfo);
var inferences = ts.map(context.inferences, function (info) { return createInferenceInfo(info.typeParameter); });
inferTypes(inferences, strippedType, contextualType);
// If we produced some inference candidates and if the type parameters for which we produced
// candidates do not already have existing inferences, we adopt the new inference candidates and
@ -52760,8 +52758,8 @@ var ts;
if (checkMode & 2 /* Inferential */) {
// We have skipped a generic function during inferential typing. Obtain the inference context and
// indicate this has occurred such that we know a second pass of inference is be needed.
var context = getContextualMapper(node);
context.flags |= 8 /* SkippedGenericFunction */;
var context = getInferenceContext(node);
context.flags |= 4 /* SkippedGenericFunction */;
}
}
function hasInferenceCandidates(info) {
@ -52869,13 +52867,6 @@ var ts;
node.contextualType = saveContextualType;
return type;
}
// Checks an expression and returns its type. The contextualMapper parameter serves two purposes: When
// contextualMapper is not undefined and not equal to the identityMapper function object it indicates that the
// expression is being inferentially typed (section 4.15.2 in spec) and provides the type mapper to use in
// conjunction with the generic contextual type. When contextualMapper is equal to the identityMapper function
// object, it serves as an indicator that all contained function and arrow expressions should be considered to
// have the wildcard function type; this form of type check is used during overload resolution to exclude
// contextually typed function and arrow expressions in the initial phase.
function checkExpression(node, checkMode, forceTuple) {
var saveCurrentNode = currentNode;
currentNode = node;
@ -62269,6 +62260,28 @@ var ts;
return node;
}
ts.createJsxFragment = createJsxFragment;
function createJsxText(text, containsOnlyTriviaWhiteSpaces) {
var node = createSynthesizedNode(11 /* JsxText */);
node.text = text;
node.containsOnlyTriviaWhiteSpaces = !!containsOnlyTriviaWhiteSpaces;
return node;
}
ts.createJsxText = createJsxText;
function updateJsxText(node, text, containsOnlyTriviaWhiteSpaces) {
return node.text !== text
|| node.containsOnlyTriviaWhiteSpaces !== containsOnlyTriviaWhiteSpaces
? updateNode(createJsxText(text, containsOnlyTriviaWhiteSpaces), node)
: node;
}
ts.updateJsxText = updateJsxText;
function createJsxOpeningFragment() {
return createSynthesizedNode(265 /* JsxOpeningFragment */);
}
ts.createJsxOpeningFragment = createJsxOpeningFragment;
function createJsxJsxClosingFragment() {
return createSynthesizedNode(266 /* JsxClosingFragment */);
}
ts.createJsxJsxClosingFragment = createJsxJsxClosingFragment;
function updateJsxFragment(node, openingFragment, children, closingFragment) {
return node.openingFragment !== openingFragment
|| node.children !== children
@ -71497,7 +71510,7 @@ var ts;
}
}
function visitJsxText(node) {
var fixed = fixupWhitespaceAndDecodeEntities(ts.getTextOfNode(node, /*includeTrivia*/ true));
var fixed = fixupWhitespaceAndDecodeEntities(node.text);
return fixed === undefined ? undefined : ts.createLiteral(fixed);
}
/**
@ -85356,7 +85369,7 @@ var ts;
writePunctuation(">");
}
function emitJsxText(node) {
writer.writeLiteral(getTextOfNode(node, /*includeTrivia*/ true));
writer.writeLiteral(node.text);
}
function emitJsxClosingElementOrFragment(node) {
writePunctuation("</");
@ -92748,7 +92761,7 @@ var ts;
}
}
ts.createCompilerHostFromProgramHost = createCompilerHostFromProgramHost;
function setCreateSourceFileAsHashVersioned(compilerHost, host) {
function setGetSourceFileAsHashVersioned(compilerHost, host) {
var originalGetSourceFile = compilerHost.getSourceFile;
var computeHash = host.createHash || ts.generateDjb2Hash;
compilerHost.getSourceFile = function () {
@ -92763,7 +92776,7 @@ var ts;
return result;
};
}
ts.setCreateSourceFileAsHashVersioned = setCreateSourceFileAsHashVersioned;
ts.setGetSourceFileAsHashVersioned = setGetSourceFileAsHashVersioned;
/**
* Creates the watch compiler host that can be extended with config file or root file names and options host
*/
@ -92911,7 +92924,7 @@ var ts;
configFileWatcher = watchFile(host, configFileName, scheduleProgramReload, ts.PollingInterval.High, "Config file" /* ConfigFile */);
}
var compilerHost = ts.createCompilerHostFromProgramHost(host, function () { return compilerOptions; }, directoryStructureHost);
ts.setCreateSourceFileAsHashVersioned(compilerHost, host);
ts.setGetSourceFileAsHashVersioned(compilerHost, host);
// Members for CompilerHost
var getNewSourceFile = compilerHost.getSourceFile;
compilerHost.getSourceFile = function (fileName) {
@ -93498,7 +93511,7 @@ var ts;
var readFileWithCache = function (f) { return host.readFile(f); };
var projectCompilerOptions = baseCompilerOptions;
var compilerHost = ts.createCompilerHostFromProgramHost(host, function () { return projectCompilerOptions; });
ts.setCreateSourceFileAsHashVersioned(compilerHost, host);
ts.setGetSourceFileAsHashVersioned(compilerHost, host);
var buildInfoChecked = createFileMap(toPath);
// Watch state
var builderPrograms = createFileMap(toPath);