Update LKG.

This commit is contained in:
Daniel Rosenwasser
2018-12-10 14:05:01 -08:00
parent 35d26f5f52
commit d63cc5fd6e
6 changed files with 518 additions and 242 deletions
+49 -37
View File
@@ -61,7 +61,7 @@ var __makeTemplateObject = (this && this.__makeTemplateObject) || function (cook
var ts;
(function (ts) {
ts.versionMajorMinor = "3.2";
ts.version = ts.versionMajorMinor + ".2";
ts.version = ts.versionMajorMinor + ".3";
})(ts || (ts = {}));
(function (ts) {
ts.emptyArray = [];
@@ -26268,7 +26268,8 @@ var ts;
}
}
if (result && isInExternalModule && (meaning & 67220415) === 67220415 && !(originalLocation.flags & 2097152)) {
if (ts.some(result.declarations, function (d) { return ts.isNamespaceExportDeclaration(d) || ts.isSourceFile(d) && !!d.symbol.globalExports; })) {
var merged = getMergedSymbol(result);
if (ts.length(merged.declarations) && ts.every(merged.declarations, function (d) { return ts.isNamespaceExportDeclaration(d) || ts.isSourceFile(d) && !!d.symbol.globalExports; })) {
error(errorLocation, ts.Diagnostics._0_refers_to_a_UMD_global_but_the_current_file_is_a_module_Consider_adding_an_import_instead, ts.unescapeLeadingUnderscores(name));
}
}
@@ -29350,12 +29351,11 @@ var ts;
if (ts.isCatchClauseVariableDeclarationOrBindingElement(declaration)) {
return anyType;
}
if (ts.isSourceFile(declaration)) {
var jsonSourceFile = ts.cast(declaration, ts.isJsonSourceFile);
if (!jsonSourceFile.statements.length) {
if (ts.isSourceFile(declaration) && ts.isJsonSourceFile(declaration)) {
if (!declaration.statements.length) {
return emptyObjectType;
}
var type_1 = getWidenedLiteralType(checkExpression(jsonSourceFile.statements[0].expression));
var type_1 = getWidenedLiteralType(checkExpression(declaration.statements[0].expression));
if (type_1.flags & 524288) {
return getRegularTypeOfObjectLiteral(type_1);
}
@@ -29378,7 +29378,8 @@ var ts;
|| ts.isClassDeclaration(declaration)
|| ts.isFunctionDeclaration(declaration)
|| (ts.isMethodDeclaration(declaration) && !ts.isObjectLiteralMethod(declaration))
|| ts.isMethodSignature(declaration)) {
|| ts.isMethodSignature(declaration)
|| ts.isSourceFile(declaration)) {
if (symbol.flags & (16 | 8192 | 32 | 384 | 512)) {
return getTypeOfFuncClassEnumModule(symbol);
}
@@ -32989,23 +32990,23 @@ var ts;
if (checkType === wildcardType || extendsType === wildcardType) {
return wildcardType;
}
var isDeferred = root.isDistributive && maybeTypeOfKind(checkType, 63176704);
var checkTypeInstantiable = maybeTypeOfKind(checkType, 63176704);
var combinedMapper;
if (root.inferTypeParameters) {
var context = createInferenceContext(root.inferTypeParameters, undefined, 0);
if (!isDeferred) {
if (!checkTypeInstantiable) {
inferTypes(context.inferences, checkType, extendsType, 32 | 64);
}
combinedMapper = combineTypeMappers(mapper, context);
}
if (!isDeferred) {
if (extendsType.flags & 3) {
var inferredExtendsType = combinedMapper ? instantiateType(root.extendsType, combinedMapper) : extendsType;
if (!checkTypeInstantiable && !maybeTypeOfKind(inferredExtendsType, 63176704)) {
if (inferredExtendsType.flags & 3) {
return instantiateType(root.trueType, mapper);
}
if (checkType.flags & 1) {
return getUnionType([instantiateType(root.trueType, combinedMapper || mapper), instantiateType(root.falseType, mapper)]);
}
var inferredExtendsType = combinedMapper ? instantiateType(root.extendsType, combinedMapper) : extendsType;
if (!isTypeAssignableTo(getWildcardInstantiation(checkType), getWildcardInstantiation(inferredExtendsType))) {
return instantiateType(root.falseType, mapper);
}
@@ -34694,7 +34695,7 @@ var ts;
if (!noImplicitAny && ts.getObjectFlags(target) & 16384) {
return false;
}
if (maybeTypeOfKind(target, 524288) && !(ts.getObjectFlags(target) & 512)) {
if (isExcessPropertyCheckTarget(target)) {
var isComparingJsxAttributes = !!(ts.getObjectFlags(source) & 4096);
if ((relation === assignableRelation || relation === definitelyAssignableRelation || relation === comparableRelation) &&
(isTypeSubsetOf(globalObjectType, target) || (!isComparingJsxAttributes && isEmptyObjectType(target)))) {
@@ -34706,10 +34707,11 @@ var ts;
var _loop_6 = function (prop) {
if (shouldCheckAsExcessProperty(prop, source.symbol) && !isKnownProperty(target, prop.escapedName, isComparingJsxAttributes)) {
if (reportErrors) {
var errorTarget = filterType(target, isExcessPropertyCheckTarget);
if (!errorNode)
return { value: ts.Debug.fail() };
if (ts.isJsxAttributes(errorNode) || ts.isJsxOpeningLikeElement(errorNode) || ts.isJsxOpeningLikeElement(errorNode.parent)) {
reportError(ts.Diagnostics.Property_0_does_not_exist_on_type_1, symbolToString(prop), typeToString(target));
reportError(ts.Diagnostics.Property_0_does_not_exist_on_type_1, symbolToString(prop), typeToString(errorTarget));
}
else {
var objectLiteralDeclaration_1 = source.symbol && ts.firstOrUndefined(source.symbol.declarations);
@@ -34720,14 +34722,14 @@ var ts;
errorNode = propDeclaration;
var name = propDeclaration.name;
if (ts.isIdentifier(name)) {
suggestion = getSuggestionForNonexistentProperty(name, target);
suggestion = getSuggestionForNonexistentProperty(name, errorTarget);
}
}
if (suggestion !== undefined) {
reportError(ts.Diagnostics.Object_literal_may_only_specify_known_properties_but_0_does_not_exist_in_type_1_Did_you_mean_to_write_2, symbolToString(prop), typeToString(target), suggestion);
reportError(ts.Diagnostics.Object_literal_may_only_specify_known_properties_but_0_does_not_exist_in_type_1_Did_you_mean_to_write_2, symbolToString(prop), typeToString(errorTarget), suggestion);
}
else {
reportError(ts.Diagnostics.Object_literal_may_only_specify_known_properties_and_0_does_not_exist_in_type_1, symbolToString(prop), typeToString(target));
reportError(ts.Diagnostics.Object_literal_may_only_specify_known_properties_and_0_does_not_exist_in_type_1, symbolToString(prop), typeToString(errorTarget));
}
}
}
@@ -37005,17 +37007,15 @@ var ts;
getAccessedPropertyName(source) === getAccessedPropertyName(target) &&
isMatchingReference(source.expression, target.expression);
case 186:
if (target.kind !== 189)
return false;
var t = target;
if (t.name.escapedText !== getBindingElementNameText(source))
return false;
if (source.parent.parent.kind === 186 && isMatchingReference(source.parent.parent, t.expression)) {
return true;
}
if (source.parent.parent.kind === 237) {
var maybeId = source.parent.parent.initializer;
return !!maybeId && isMatchingReference(maybeId, t.expression);
if (target.kind === 189 && target.name.escapedText === getBindingElementNameText(source)) {
var ancestor = source.parent.parent;
if (ancestor.kind === 186) {
return isMatchingReference(ancestor, target.expression);
}
if (ancestor.kind === 237) {
var initializer = ancestor.initializer;
return !!initializer && isMatchingReference(initializer, target.expression);
}
}
}
return false;
@@ -37025,14 +37025,24 @@ var ts;
ts.isStringLiteral(access.argumentExpression) || ts.isNumericLiteral(access.argumentExpression) ? ts.escapeLeadingUnderscores(access.argumentExpression.text) :
undefined;
}
function getReferenceParent(source) {
if (source.kind === 189) {
return source.expression;
}
if (source.kind === 186) {
var ancestor = source.parent.parent;
return ancestor.kind === 237 ? ancestor.initializer : ancestor;
}
return undefined;
}
function containsMatchingReference(source, target) {
while (source.kind === 189) {
source = source.expression;
if (isMatchingReference(source, target)) {
var parent = getReferenceParent(source);
while (parent) {
if (isMatchingReference(parent, target)) {
return true;
}
parent = getReferenceParent(parent);
}
return false;
}
function containsMatchingReferenceDiscriminant(source, target) {
return target.kind === 189 &&
@@ -40059,7 +40069,7 @@ var ts;
return true;
}
}
else if (targetType.flags & 3145728) {
else if (targetType.flags & 3145728 && isExcessPropertyCheckTarget(targetType)) {
for (var _i = 0, _a = targetType.types; _i < _a.length; _i++) {
var t = _a[_i];
if (isKnownProperty(t, name, isComparingJsxAttributes)) {
@@ -40067,12 +40077,14 @@ var ts;
}
}
}
else if (targetType.flags & 16777216) {
return isKnownProperty(targetType.root.trueType, name, isComparingJsxAttributes) ||
isKnownProperty(targetType.root.falseType, name, isComparingJsxAttributes);
}
return false;
}
function isExcessPropertyCheckTarget(type) {
return !!(type.flags & 524288 && !(ts.getObjectFlags(type) & 512) ||
type.flags & 67108864 ||
type.flags & 1048576 && ts.some(type.types, isExcessPropertyCheckTarget) ||
type.flags & 2097152 && ts.every(type.types, isExcessPropertyCheckTarget));
}
function checkJsxExpression(node, checkMode) {
if (node.expression) {
var type = checkExpression(node.expression, checkMode);
+53 -41
View File
@@ -88,7 +88,7 @@ var ts;
// If changing the text in this section, be sure to test `configureNightly` too.
ts.versionMajorMinor = "3.2";
/** The version of the TypeScript compiler release */
ts.version = ts.versionMajorMinor + ".2";
ts.version = ts.versionMajorMinor + ".3";
})(ts || (ts = {}));
(function (ts) {
/* @internal */
@@ -32171,7 +32171,8 @@ var ts;
}
// If we're in an external module, we can't reference value symbols created from UMD export declarations
if (result && isInExternalModule && (meaning & 67220415 /* Value */) === 67220415 /* Value */ && !(originalLocation.flags & 2097152 /* JSDoc */)) {
if (ts.some(result.declarations, function (d) { return ts.isNamespaceExportDeclaration(d) || ts.isSourceFile(d) && !!d.symbol.globalExports; })) {
var merged = getMergedSymbol(result);
if (ts.length(merged.declarations) && ts.every(merged.declarations, function (d) { return ts.isNamespaceExportDeclaration(d) || ts.isSourceFile(d) && !!d.symbol.globalExports; })) {
error(errorLocation, ts.Diagnostics._0_refers_to_a_UMD_global_but_the_current_file_is_a_module_Consider_adding_an_import_instead, ts.unescapeLeadingUnderscores(name)); // TODO: GH#18217
}
}
@@ -35600,12 +35601,11 @@ var ts;
return anyType;
}
// Handle export default expressions
if (ts.isSourceFile(declaration)) {
var jsonSourceFile = ts.cast(declaration, ts.isJsonSourceFile);
if (!jsonSourceFile.statements.length) {
if (ts.isSourceFile(declaration) && ts.isJsonSourceFile(declaration)) {
if (!declaration.statements.length) {
return emptyObjectType;
}
var type_1 = getWidenedLiteralType(checkExpression(jsonSourceFile.statements[0].expression));
var type_1 = getWidenedLiteralType(checkExpression(declaration.statements[0].expression));
if (type_1.flags & 524288 /* Object */) {
return getRegularTypeOfObjectLiteral(type_1);
}
@@ -35629,7 +35629,8 @@ var ts;
|| ts.isClassDeclaration(declaration)
|| ts.isFunctionDeclaration(declaration)
|| (ts.isMethodDeclaration(declaration) && !ts.isObjectLiteralMethod(declaration))
|| ts.isMethodSignature(declaration)) {
|| ts.isMethodSignature(declaration)
|| ts.isSourceFile(declaration)) {
// Symbol is property of some kind that is merged with something - should use `getTypeOfFuncClassEnumModule` and not `getTypeOfVariableOrParameterOrProperty`
if (symbol.flags & (16 /* Function */ | 8192 /* Method */ | 32 /* Class */ | 384 /* Enum */ | 512 /* ValueModule */)) {
return getTypeOfFuncClassEnumModule(symbol);
@@ -39733,14 +39734,11 @@ var ts;
if (checkType === wildcardType || extendsType === wildcardType) {
return wildcardType;
}
// If this is a distributive conditional type and the check type is generic we need to defer
// resolution of the conditional type such that a later instantiation will properly distribute
// over union types.
var isDeferred = root.isDistributive && maybeTypeOfKind(checkType, 63176704 /* Instantiable */);
var checkTypeInstantiable = maybeTypeOfKind(checkType, 63176704 /* Instantiable */);
var combinedMapper;
if (root.inferTypeParameters) {
var context = createInferenceContext(root.inferTypeParameters, /*signature*/ undefined, 0 /* None */);
if (!isDeferred) {
if (!checkTypeInstantiable) {
// We don't want inferences from constraints as they may cause us to eagerly resolve the
// conditional type instead of deferring resolution. Also, we always want strict function
// types rules (i.e. proper contravariance) for inferences.
@@ -39748,16 +39746,17 @@ var ts;
}
combinedMapper = combineTypeMappers(mapper, context);
}
if (!isDeferred) {
if (extendsType.flags & 3 /* AnyOrUnknown */) {
// Instantiate the extends type including inferences for 'infer T' type parameters
var inferredExtendsType = combinedMapper ? instantiateType(root.extendsType, combinedMapper) : extendsType;
// We attempt to resolve the conditional type only when the check and extends types are non-generic
if (!checkTypeInstantiable && !maybeTypeOfKind(inferredExtendsType, 63176704 /* Instantiable */)) {
if (inferredExtendsType.flags & 3 /* AnyOrUnknown */) {
return instantiateType(root.trueType, mapper);
}
// Return union of trueType and falseType for 'any' since it matches anything
if (checkType.flags & 1 /* Any */) {
return getUnionType([instantiateType(root.trueType, combinedMapper || mapper), instantiateType(root.falseType, mapper)]);
}
// Instantiate the extends type including inferences for 'infer T' type parameters
var inferredExtendsType = combinedMapper ? instantiateType(root.extendsType, combinedMapper) : extendsType;
// Return falseType for a definitely false extends check. We check an instantations of the two
// types with type parameters mapped to the wildcard type, the most permissive instantiations
// possible (the wildcard type is assignable to and from all types). If those are not related,
@@ -41663,7 +41662,7 @@ var ts;
if (!noImplicitAny && ts.getObjectFlags(target) & 16384 /* JSLiteral */) {
return false; // Disable excess property checks on JS literals to simulate having an implicit "index signature" - but only outside of noImplicitAny
}
if (maybeTypeOfKind(target, 524288 /* Object */) && !(ts.getObjectFlags(target) & 512 /* ObjectLiteralPatternWithComputedProperties */)) {
if (isExcessPropertyCheckTarget(target)) {
var isComparingJsxAttributes = !!(ts.getObjectFlags(source) & 4096 /* JsxAttributes */);
if ((relation === assignableRelation || relation === definitelyAssignableRelation || relation === comparableRelation) &&
(isTypeSubsetOf(globalObjectType, target) || (!isComparingJsxAttributes && isEmptyObjectType(target)))) {
@@ -41676,6 +41675,9 @@ var ts;
var _loop_6 = function (prop) {
if (shouldCheckAsExcessProperty(prop, source.symbol) && !isKnownProperty(target, prop.escapedName, isComparingJsxAttributes)) {
if (reportErrors) {
// Report error in terms of object types in the target as those are the only ones
// we check in isKnownProperty.
var errorTarget = filterType(target, isExcessPropertyCheckTarget);
// We know *exactly* where things went wrong when comparing the types.
// Use this property as the error node as this will be more helpful in
// reasoning about what went wrong.
@@ -41685,7 +41687,7 @@ var ts;
// JsxAttributes has an object-literal flag and undergo same type-assignablity check as normal object-literal.
// However, using an object-literal error message will be very confusing to the users so we give different a message.
// TODO: Spelling suggestions for excess jsx attributes (needs new diagnostic messages)
reportError(ts.Diagnostics.Property_0_does_not_exist_on_type_1, symbolToString(prop), typeToString(target));
reportError(ts.Diagnostics.Property_0_does_not_exist_on_type_1, symbolToString(prop), typeToString(errorTarget));
}
else {
// use the property's value declaration if the property is assigned inside the literal itself
@@ -41697,14 +41699,14 @@ var ts;
errorNode = propDeclaration;
var name = propDeclaration.name;
if (ts.isIdentifier(name)) {
suggestion = getSuggestionForNonexistentProperty(name, target);
suggestion = getSuggestionForNonexistentProperty(name, errorTarget);
}
}
if (suggestion !== undefined) {
reportError(ts.Diagnostics.Object_literal_may_only_specify_known_properties_but_0_does_not_exist_in_type_1_Did_you_mean_to_write_2, symbolToString(prop), typeToString(target), suggestion);
reportError(ts.Diagnostics.Object_literal_may_only_specify_known_properties_but_0_does_not_exist_in_type_1_Did_you_mean_to_write_2, symbolToString(prop), typeToString(errorTarget), suggestion);
}
else {
reportError(ts.Diagnostics.Object_literal_may_only_specify_known_properties_and_0_does_not_exist_in_type_1, symbolToString(prop), typeToString(target));
reportError(ts.Diagnostics.Object_literal_may_only_specify_known_properties_and_0_does_not_exist_in_type_1, symbolToString(prop), typeToString(errorTarget));
}
}
}
@@ -44311,17 +44313,15 @@ var ts;
getAccessedPropertyName(source) === getAccessedPropertyName(target) &&
isMatchingReference(source.expression, target.expression);
case 186 /* BindingElement */:
if (target.kind !== 189 /* PropertyAccessExpression */)
return false;
var t = target;
if (t.name.escapedText !== getBindingElementNameText(source))
return false;
if (source.parent.parent.kind === 186 /* BindingElement */ && isMatchingReference(source.parent.parent, t.expression)) {
return true;
}
if (source.parent.parent.kind === 237 /* VariableDeclaration */) {
var maybeId = source.parent.parent.initializer;
return !!maybeId && isMatchingReference(maybeId, t.expression);
if (target.kind === 189 /* PropertyAccessExpression */ && target.name.escapedText === getBindingElementNameText(source)) {
var ancestor = source.parent.parent;
if (ancestor.kind === 186 /* BindingElement */) {
return isMatchingReference(ancestor, target.expression);
}
if (ancestor.kind === 237 /* VariableDeclaration */) {
var initializer = ancestor.initializer;
return !!initializer && isMatchingReference(initializer, target.expression);
}
}
}
return false;
@@ -44331,14 +44331,24 @@ var ts;
ts.isStringLiteral(access.argumentExpression) || ts.isNumericLiteral(access.argumentExpression) ? ts.escapeLeadingUnderscores(access.argumentExpression.text) :
undefined;
}
function getReferenceParent(source) {
if (source.kind === 189 /* PropertyAccessExpression */) {
return source.expression;
}
if (source.kind === 186 /* BindingElement */) {
var ancestor = source.parent.parent;
return ancestor.kind === 237 /* VariableDeclaration */ ? ancestor.initializer : ancestor;
}
return undefined;
}
function containsMatchingReference(source, target) {
while (source.kind === 189 /* PropertyAccessExpression */) {
source = source.expression;
if (isMatchingReference(source, target)) {
var parent = getReferenceParent(source);
while (parent) {
if (isMatchingReference(parent, target)) {
return true;
}
parent = getReferenceParent(parent);
}
return false;
}
// Return true if target is a property access xxx.yyy, source is a property access xxx.zzz, the declared
// type of xxx is a union type, and yyy is a property that is possibly a discriminant. We consider a property
@@ -47957,7 +47967,7 @@ var ts;
return true;
}
}
else if (targetType.flags & 3145728 /* UnionOrIntersection */) {
else if (targetType.flags & 3145728 /* UnionOrIntersection */ && isExcessPropertyCheckTarget(targetType)) {
for (var _i = 0, _a = targetType.types; _i < _a.length; _i++) {
var t = _a[_i];
if (isKnownProperty(t, name, isComparingJsxAttributes)) {
@@ -47965,12 +47975,14 @@ var ts;
}
}
}
else if (targetType.flags & 16777216 /* Conditional */) {
return isKnownProperty(targetType.root.trueType, name, isComparingJsxAttributes) ||
isKnownProperty(targetType.root.falseType, name, isComparingJsxAttributes);
}
return false;
}
function isExcessPropertyCheckTarget(type) {
return !!(type.flags & 524288 /* Object */ && !(ts.getObjectFlags(type) & 512 /* ObjectLiteralPatternWithComputedProperties */) ||
type.flags & 67108864 /* NonPrimitive */ ||
type.flags & 1048576 /* Union */ && ts.some(type.types, isExcessPropertyCheckTarget) ||
type.flags & 2097152 /* Intersection */ && ts.every(type.types, isExcessPropertyCheckTarget));
}
function checkJsxExpression(node, checkMode) {
if (node.expression) {
var type = checkExpression(node.expression, checkMode);
+121 -41
View File
@@ -84,7 +84,7 @@ var ts;
// If changing the text in this section, be sure to test `configureNightly` too.
ts.versionMajorMinor = "3.2";
/** The version of the TypeScript compiler release */
ts.version = ts.versionMajorMinor + ".2";
ts.version = ts.versionMajorMinor + ".3";
})(ts || (ts = {}));
(function (ts) {
/* @internal */
@@ -32167,7 +32167,8 @@ var ts;
}
// If we're in an external module, we can't reference value symbols created from UMD export declarations
if (result && isInExternalModule && (meaning & 67220415 /* Value */) === 67220415 /* Value */ && !(originalLocation.flags & 2097152 /* JSDoc */)) {
if (ts.some(result.declarations, function (d) { return ts.isNamespaceExportDeclaration(d) || ts.isSourceFile(d) && !!d.symbol.globalExports; })) {
var merged = getMergedSymbol(result);
if (ts.length(merged.declarations) && ts.every(merged.declarations, function (d) { return ts.isNamespaceExportDeclaration(d) || ts.isSourceFile(d) && !!d.symbol.globalExports; })) {
error(errorLocation, ts.Diagnostics._0_refers_to_a_UMD_global_but_the_current_file_is_a_module_Consider_adding_an_import_instead, ts.unescapeLeadingUnderscores(name)); // TODO: GH#18217
}
}
@@ -35596,12 +35597,11 @@ var ts;
return anyType;
}
// Handle export default expressions
if (ts.isSourceFile(declaration)) {
var jsonSourceFile = ts.cast(declaration, ts.isJsonSourceFile);
if (!jsonSourceFile.statements.length) {
if (ts.isSourceFile(declaration) && ts.isJsonSourceFile(declaration)) {
if (!declaration.statements.length) {
return emptyObjectType;
}
var type_1 = getWidenedLiteralType(checkExpression(jsonSourceFile.statements[0].expression));
var type_1 = getWidenedLiteralType(checkExpression(declaration.statements[0].expression));
if (type_1.flags & 524288 /* Object */) {
return getRegularTypeOfObjectLiteral(type_1);
}
@@ -35625,7 +35625,8 @@ var ts;
|| ts.isClassDeclaration(declaration)
|| ts.isFunctionDeclaration(declaration)
|| (ts.isMethodDeclaration(declaration) && !ts.isObjectLiteralMethod(declaration))
|| ts.isMethodSignature(declaration)) {
|| ts.isMethodSignature(declaration)
|| ts.isSourceFile(declaration)) {
// Symbol is property of some kind that is merged with something - should use `getTypeOfFuncClassEnumModule` and not `getTypeOfVariableOrParameterOrProperty`
if (symbol.flags & (16 /* Function */ | 8192 /* Method */ | 32 /* Class */ | 384 /* Enum */ | 512 /* ValueModule */)) {
return getTypeOfFuncClassEnumModule(symbol);
@@ -39729,14 +39730,11 @@ var ts;
if (checkType === wildcardType || extendsType === wildcardType) {
return wildcardType;
}
// If this is a distributive conditional type and the check type is generic we need to defer
// resolution of the conditional type such that a later instantiation will properly distribute
// over union types.
var isDeferred = root.isDistributive && maybeTypeOfKind(checkType, 63176704 /* Instantiable */);
var checkTypeInstantiable = maybeTypeOfKind(checkType, 63176704 /* Instantiable */);
var combinedMapper;
if (root.inferTypeParameters) {
var context = createInferenceContext(root.inferTypeParameters, /*signature*/ undefined, 0 /* None */);
if (!isDeferred) {
if (!checkTypeInstantiable) {
// We don't want inferences from constraints as they may cause us to eagerly resolve the
// conditional type instead of deferring resolution. Also, we always want strict function
// types rules (i.e. proper contravariance) for inferences.
@@ -39744,16 +39742,17 @@ var ts;
}
combinedMapper = combineTypeMappers(mapper, context);
}
if (!isDeferred) {
if (extendsType.flags & 3 /* AnyOrUnknown */) {
// Instantiate the extends type including inferences for 'infer T' type parameters
var inferredExtendsType = combinedMapper ? instantiateType(root.extendsType, combinedMapper) : extendsType;
// We attempt to resolve the conditional type only when the check and extends types are non-generic
if (!checkTypeInstantiable && !maybeTypeOfKind(inferredExtendsType, 63176704 /* Instantiable */)) {
if (inferredExtendsType.flags & 3 /* AnyOrUnknown */) {
return instantiateType(root.trueType, mapper);
}
// Return union of trueType and falseType for 'any' since it matches anything
if (checkType.flags & 1 /* Any */) {
return getUnionType([instantiateType(root.trueType, combinedMapper || mapper), instantiateType(root.falseType, mapper)]);
}
// Instantiate the extends type including inferences for 'infer T' type parameters
var inferredExtendsType = combinedMapper ? instantiateType(root.extendsType, combinedMapper) : extendsType;
// Return falseType for a definitely false extends check. We check an instantations of the two
// types with type parameters mapped to the wildcard type, the most permissive instantiations
// possible (the wildcard type is assignable to and from all types). If those are not related,
@@ -41659,7 +41658,7 @@ var ts;
if (!noImplicitAny && ts.getObjectFlags(target) & 16384 /* JSLiteral */) {
return false; // Disable excess property checks on JS literals to simulate having an implicit "index signature" - but only outside of noImplicitAny
}
if (maybeTypeOfKind(target, 524288 /* Object */) && !(ts.getObjectFlags(target) & 512 /* ObjectLiteralPatternWithComputedProperties */)) {
if (isExcessPropertyCheckTarget(target)) {
var isComparingJsxAttributes = !!(ts.getObjectFlags(source) & 4096 /* JsxAttributes */);
if ((relation === assignableRelation || relation === definitelyAssignableRelation || relation === comparableRelation) &&
(isTypeSubsetOf(globalObjectType, target) || (!isComparingJsxAttributes && isEmptyObjectType(target)))) {
@@ -41672,6 +41671,9 @@ var ts;
var _loop_6 = function (prop) {
if (shouldCheckAsExcessProperty(prop, source.symbol) && !isKnownProperty(target, prop.escapedName, isComparingJsxAttributes)) {
if (reportErrors) {
// Report error in terms of object types in the target as those are the only ones
// we check in isKnownProperty.
var errorTarget = filterType(target, isExcessPropertyCheckTarget);
// We know *exactly* where things went wrong when comparing the types.
// Use this property as the error node as this will be more helpful in
// reasoning about what went wrong.
@@ -41681,7 +41683,7 @@ var ts;
// JsxAttributes has an object-literal flag and undergo same type-assignablity check as normal object-literal.
// However, using an object-literal error message will be very confusing to the users so we give different a message.
// TODO: Spelling suggestions for excess jsx attributes (needs new diagnostic messages)
reportError(ts.Diagnostics.Property_0_does_not_exist_on_type_1, symbolToString(prop), typeToString(target));
reportError(ts.Diagnostics.Property_0_does_not_exist_on_type_1, symbolToString(prop), typeToString(errorTarget));
}
else {
// use the property's value declaration if the property is assigned inside the literal itself
@@ -41693,14 +41695,14 @@ var ts;
errorNode = propDeclaration;
var name = propDeclaration.name;
if (ts.isIdentifier(name)) {
suggestion = getSuggestionForNonexistentProperty(name, target);
suggestion = getSuggestionForNonexistentProperty(name, errorTarget);
}
}
if (suggestion !== undefined) {
reportError(ts.Diagnostics.Object_literal_may_only_specify_known_properties_but_0_does_not_exist_in_type_1_Did_you_mean_to_write_2, symbolToString(prop), typeToString(target), suggestion);
reportError(ts.Diagnostics.Object_literal_may_only_specify_known_properties_but_0_does_not_exist_in_type_1_Did_you_mean_to_write_2, symbolToString(prop), typeToString(errorTarget), suggestion);
}
else {
reportError(ts.Diagnostics.Object_literal_may_only_specify_known_properties_and_0_does_not_exist_in_type_1, symbolToString(prop), typeToString(target));
reportError(ts.Diagnostics.Object_literal_may_only_specify_known_properties_and_0_does_not_exist_in_type_1, symbolToString(prop), typeToString(errorTarget));
}
}
}
@@ -44307,17 +44309,15 @@ var ts;
getAccessedPropertyName(source) === getAccessedPropertyName(target) &&
isMatchingReference(source.expression, target.expression);
case 186 /* BindingElement */:
if (target.kind !== 189 /* PropertyAccessExpression */)
return false;
var t = target;
if (t.name.escapedText !== getBindingElementNameText(source))
return false;
if (source.parent.parent.kind === 186 /* BindingElement */ && isMatchingReference(source.parent.parent, t.expression)) {
return true;
}
if (source.parent.parent.kind === 237 /* VariableDeclaration */) {
var maybeId = source.parent.parent.initializer;
return !!maybeId && isMatchingReference(maybeId, t.expression);
if (target.kind === 189 /* PropertyAccessExpression */ && target.name.escapedText === getBindingElementNameText(source)) {
var ancestor = source.parent.parent;
if (ancestor.kind === 186 /* BindingElement */) {
return isMatchingReference(ancestor, target.expression);
}
if (ancestor.kind === 237 /* VariableDeclaration */) {
var initializer = ancestor.initializer;
return !!initializer && isMatchingReference(initializer, target.expression);
}
}
}
return false;
@@ -44327,14 +44327,24 @@ var ts;
ts.isStringLiteral(access.argumentExpression) || ts.isNumericLiteral(access.argumentExpression) ? ts.escapeLeadingUnderscores(access.argumentExpression.text) :
undefined;
}
function getReferenceParent(source) {
if (source.kind === 189 /* PropertyAccessExpression */) {
return source.expression;
}
if (source.kind === 186 /* BindingElement */) {
var ancestor = source.parent.parent;
return ancestor.kind === 237 /* VariableDeclaration */ ? ancestor.initializer : ancestor;
}
return undefined;
}
function containsMatchingReference(source, target) {
while (source.kind === 189 /* PropertyAccessExpression */) {
source = source.expression;
if (isMatchingReference(source, target)) {
var parent = getReferenceParent(source);
while (parent) {
if (isMatchingReference(parent, target)) {
return true;
}
parent = getReferenceParent(parent);
}
return false;
}
// Return true if target is a property access xxx.yyy, source is a property access xxx.zzz, the declared
// type of xxx is a union type, and yyy is a property that is possibly a discriminant. We consider a property
@@ -47953,7 +47963,7 @@ var ts;
return true;
}
}
else if (targetType.flags & 3145728 /* UnionOrIntersection */) {
else if (targetType.flags & 3145728 /* UnionOrIntersection */ && isExcessPropertyCheckTarget(targetType)) {
for (var _i = 0, _a = targetType.types; _i < _a.length; _i++) {
var t = _a[_i];
if (isKnownProperty(t, name, isComparingJsxAttributes)) {
@@ -47961,12 +47971,14 @@ var ts;
}
}
}
else if (targetType.flags & 16777216 /* Conditional */) {
return isKnownProperty(targetType.root.trueType, name, isComparingJsxAttributes) ||
isKnownProperty(targetType.root.falseType, name, isComparingJsxAttributes);
}
return false;
}
function isExcessPropertyCheckTarget(type) {
return !!(type.flags & 524288 /* Object */ && !(ts.getObjectFlags(type) & 512 /* ObjectLiteralPatternWithComputedProperties */) ||
type.flags & 67108864 /* NonPrimitive */ ||
type.flags & 1048576 /* Union */ && ts.some(type.types, isExcessPropertyCheckTarget) ||
type.flags & 2097152 /* Intersection */ && ts.every(type.types, isExcessPropertyCheckTarget));
}
function checkJsxExpression(node, checkMode) {
if (node.expression) {
var type = checkExpression(node.expression, checkMode);
@@ -109063,6 +109075,40 @@ var ts;
})(ts || (ts = {}));
/* @internal */
var ts;
(function (ts) {
var codefix;
(function (codefix) {
var fixId = "addNameToNamelessParameter";
var errorCodes = [ts.Diagnostics.Parameter_has_a_name_but_no_type_Did_you_mean_0_Colon_1.code];
codefix.registerCodeFix({
errorCodes: errorCodes,
getCodeActions: function (context) {
var changes = ts.textChanges.ChangeTracker.with(context, function (t) { return makeChange(t, context.sourceFile, context.span.start); });
return [codefix.createCodeFixAction(fixId, changes, ts.Diagnostics.Add_parameter_name, fixId, ts.Diagnostics.Add_names_to_all_parameters_without_names)];
},
fixIds: [fixId],
getAllCodeActions: function (context) { return codefix.codeFixAll(context, errorCodes, function (changes, diag) { return makeChange(changes, diag.file, diag.start); }); },
});
function makeChange(changeTracker, sourceFile, pos) {
var token = ts.getTokenAtPosition(sourceFile, pos);
if (!ts.isIdentifier(token)) {
return ts.Debug.fail("add-name-to-nameless-parameter operates on identifiers, but got a " + ts.formatSyntaxKind(token.kind));
}
var param = token.parent;
if (!ts.isParameter(param)) {
return ts.Debug.fail("Tried to add a parameter name to a non-parameter: " + ts.formatSyntaxKind(token.kind));
}
var i = param.parent.parameters.indexOf(param);
ts.Debug.assert(!param.type, "Tried to add a parameter name to a parameter that already had one.");
ts.Debug.assert(i > -1, "Parameter not found in parent parameter list.");
var replacement = ts.createParameter(
/*decorators*/ undefined, param.modifiers, param.dotDotDotToken, "arg" + i, param.questionToken, ts.createTypeReferenceNode(token, /*typeArguments*/ undefined), param.initializer);
changeTracker.replaceNode(sourceFile, token, replacement);
}
})(codefix = ts.codefix || (ts.codefix = {}));
})(ts || (ts = {}));
/* @internal */
var ts;
(function (ts) {
var codefix;
(function (codefix) {
@@ -112079,6 +112125,40 @@ var ts;
})(ts || (ts = {}));
/* @internal */
var ts;
(function (ts) {
var codefix;
(function (codefix) {
var fixId = "addMissingNewOperator";
var errorCodes = [ts.Diagnostics.Value_of_type_0_is_not_callable_Did_you_mean_to_include_new.code];
codefix.registerCodeFix({
errorCodes: errorCodes,
getCodeActions: function (context) {
var sourceFile = context.sourceFile, span = context.span;
var changes = ts.textChanges.ChangeTracker.with(context, function (t) { return addMissingNewOperator(t, sourceFile, span); });
return [codefix.createCodeFixAction(fixId, changes, ts.Diagnostics.Add_missing_new_operator_to_call, fixId, ts.Diagnostics.Add_missing_new_operator_to_all_calls)];
},
fixIds: [fixId],
getAllCodeActions: function (context) { return codefix.codeFixAll(context, errorCodes, function (changes, diag) {
return addMissingNewOperator(changes, context.sourceFile, diag);
}); },
});
function addMissingNewOperator(changes, sourceFile, span) {
var call = ts.cast(findAncestorMatchingSpan(sourceFile, span), ts.isCallExpression);
var newExpression = ts.createNew(call.expression, call.typeArguments, call.arguments);
changes.replaceNode(sourceFile, call, newExpression);
}
function findAncestorMatchingSpan(sourceFile, span) {
var token = ts.getTokenAtPosition(sourceFile, span.start);
var end = ts.textSpanEnd(span);
while (token.end < end) {
token = token.parent;
}
return token;
}
})(codefix = ts.codefix || (ts.codefix = {}));
})(ts || (ts = {}));
/* @internal */
var ts;
(function (ts) {
var codefix;
(function (codefix) {
+121 -41
View File
@@ -75,7 +75,7 @@ var ts;
// If changing the text in this section, be sure to test `configureNightly` too.
ts.versionMajorMinor = "3.2";
/** The version of the TypeScript compiler release */
ts.version = ts.versionMajorMinor + ".2";
ts.version = ts.versionMajorMinor + ".3";
})(ts || (ts = {}));
(function (ts) {
/* @internal */
@@ -32158,7 +32158,8 @@ var ts;
}
// If we're in an external module, we can't reference value symbols created from UMD export declarations
if (result && isInExternalModule && (meaning & 67220415 /* Value */) === 67220415 /* Value */ && !(originalLocation.flags & 2097152 /* JSDoc */)) {
if (ts.some(result.declarations, function (d) { return ts.isNamespaceExportDeclaration(d) || ts.isSourceFile(d) && !!d.symbol.globalExports; })) {
var merged = getMergedSymbol(result);
if (ts.length(merged.declarations) && ts.every(merged.declarations, function (d) { return ts.isNamespaceExportDeclaration(d) || ts.isSourceFile(d) && !!d.symbol.globalExports; })) {
error(errorLocation, ts.Diagnostics._0_refers_to_a_UMD_global_but_the_current_file_is_a_module_Consider_adding_an_import_instead, ts.unescapeLeadingUnderscores(name)); // TODO: GH#18217
}
}
@@ -35587,12 +35588,11 @@ var ts;
return anyType;
}
// Handle export default expressions
if (ts.isSourceFile(declaration)) {
var jsonSourceFile = ts.cast(declaration, ts.isJsonSourceFile);
if (!jsonSourceFile.statements.length) {
if (ts.isSourceFile(declaration) && ts.isJsonSourceFile(declaration)) {
if (!declaration.statements.length) {
return emptyObjectType;
}
var type_1 = getWidenedLiteralType(checkExpression(jsonSourceFile.statements[0].expression));
var type_1 = getWidenedLiteralType(checkExpression(declaration.statements[0].expression));
if (type_1.flags & 524288 /* Object */) {
return getRegularTypeOfObjectLiteral(type_1);
}
@@ -35616,7 +35616,8 @@ var ts;
|| ts.isClassDeclaration(declaration)
|| ts.isFunctionDeclaration(declaration)
|| (ts.isMethodDeclaration(declaration) && !ts.isObjectLiteralMethod(declaration))
|| ts.isMethodSignature(declaration)) {
|| ts.isMethodSignature(declaration)
|| ts.isSourceFile(declaration)) {
// Symbol is property of some kind that is merged with something - should use `getTypeOfFuncClassEnumModule` and not `getTypeOfVariableOrParameterOrProperty`
if (symbol.flags & (16 /* Function */ | 8192 /* Method */ | 32 /* Class */ | 384 /* Enum */ | 512 /* ValueModule */)) {
return getTypeOfFuncClassEnumModule(symbol);
@@ -39720,14 +39721,11 @@ var ts;
if (checkType === wildcardType || extendsType === wildcardType) {
return wildcardType;
}
// If this is a distributive conditional type and the check type is generic we need to defer
// resolution of the conditional type such that a later instantiation will properly distribute
// over union types.
var isDeferred = root.isDistributive && maybeTypeOfKind(checkType, 63176704 /* Instantiable */);
var checkTypeInstantiable = maybeTypeOfKind(checkType, 63176704 /* Instantiable */);
var combinedMapper;
if (root.inferTypeParameters) {
var context = createInferenceContext(root.inferTypeParameters, /*signature*/ undefined, 0 /* None */);
if (!isDeferred) {
if (!checkTypeInstantiable) {
// We don't want inferences from constraints as they may cause us to eagerly resolve the
// conditional type instead of deferring resolution. Also, we always want strict function
// types rules (i.e. proper contravariance) for inferences.
@@ -39735,16 +39733,17 @@ var ts;
}
combinedMapper = combineTypeMappers(mapper, context);
}
if (!isDeferred) {
if (extendsType.flags & 3 /* AnyOrUnknown */) {
// Instantiate the extends type including inferences for 'infer T' type parameters
var inferredExtendsType = combinedMapper ? instantiateType(root.extendsType, combinedMapper) : extendsType;
// We attempt to resolve the conditional type only when the check and extends types are non-generic
if (!checkTypeInstantiable && !maybeTypeOfKind(inferredExtendsType, 63176704 /* Instantiable */)) {
if (inferredExtendsType.flags & 3 /* AnyOrUnknown */) {
return instantiateType(root.trueType, mapper);
}
// Return union of trueType and falseType for 'any' since it matches anything
if (checkType.flags & 1 /* Any */) {
return getUnionType([instantiateType(root.trueType, combinedMapper || mapper), instantiateType(root.falseType, mapper)]);
}
// Instantiate the extends type including inferences for 'infer T' type parameters
var inferredExtendsType = combinedMapper ? instantiateType(root.extendsType, combinedMapper) : extendsType;
// Return falseType for a definitely false extends check. We check an instantations of the two
// types with type parameters mapped to the wildcard type, the most permissive instantiations
// possible (the wildcard type is assignable to and from all types). If those are not related,
@@ -41650,7 +41649,7 @@ var ts;
if (!noImplicitAny && ts.getObjectFlags(target) & 16384 /* JSLiteral */) {
return false; // Disable excess property checks on JS literals to simulate having an implicit "index signature" - but only outside of noImplicitAny
}
if (maybeTypeOfKind(target, 524288 /* Object */) && !(ts.getObjectFlags(target) & 512 /* ObjectLiteralPatternWithComputedProperties */)) {
if (isExcessPropertyCheckTarget(target)) {
var isComparingJsxAttributes = !!(ts.getObjectFlags(source) & 4096 /* JsxAttributes */);
if ((relation === assignableRelation || relation === definitelyAssignableRelation || relation === comparableRelation) &&
(isTypeSubsetOf(globalObjectType, target) || (!isComparingJsxAttributes && isEmptyObjectType(target)))) {
@@ -41663,6 +41662,9 @@ var ts;
var _loop_6 = function (prop) {
if (shouldCheckAsExcessProperty(prop, source.symbol) && !isKnownProperty(target, prop.escapedName, isComparingJsxAttributes)) {
if (reportErrors) {
// Report error in terms of object types in the target as those are the only ones
// we check in isKnownProperty.
var errorTarget = filterType(target, isExcessPropertyCheckTarget);
// We know *exactly* where things went wrong when comparing the types.
// Use this property as the error node as this will be more helpful in
// reasoning about what went wrong.
@@ -41672,7 +41674,7 @@ var ts;
// JsxAttributes has an object-literal flag and undergo same type-assignablity check as normal object-literal.
// However, using an object-literal error message will be very confusing to the users so we give different a message.
// TODO: Spelling suggestions for excess jsx attributes (needs new diagnostic messages)
reportError(ts.Diagnostics.Property_0_does_not_exist_on_type_1, symbolToString(prop), typeToString(target));
reportError(ts.Diagnostics.Property_0_does_not_exist_on_type_1, symbolToString(prop), typeToString(errorTarget));
}
else {
// use the property's value declaration if the property is assigned inside the literal itself
@@ -41684,14 +41686,14 @@ var ts;
errorNode = propDeclaration;
var name = propDeclaration.name;
if (ts.isIdentifier(name)) {
suggestion = getSuggestionForNonexistentProperty(name, target);
suggestion = getSuggestionForNonexistentProperty(name, errorTarget);
}
}
if (suggestion !== undefined) {
reportError(ts.Diagnostics.Object_literal_may_only_specify_known_properties_but_0_does_not_exist_in_type_1_Did_you_mean_to_write_2, symbolToString(prop), typeToString(target), suggestion);
reportError(ts.Diagnostics.Object_literal_may_only_specify_known_properties_but_0_does_not_exist_in_type_1_Did_you_mean_to_write_2, symbolToString(prop), typeToString(errorTarget), suggestion);
}
else {
reportError(ts.Diagnostics.Object_literal_may_only_specify_known_properties_and_0_does_not_exist_in_type_1, symbolToString(prop), typeToString(target));
reportError(ts.Diagnostics.Object_literal_may_only_specify_known_properties_and_0_does_not_exist_in_type_1, symbolToString(prop), typeToString(errorTarget));
}
}
}
@@ -44298,17 +44300,15 @@ var ts;
getAccessedPropertyName(source) === getAccessedPropertyName(target) &&
isMatchingReference(source.expression, target.expression);
case 186 /* BindingElement */:
if (target.kind !== 189 /* PropertyAccessExpression */)
return false;
var t = target;
if (t.name.escapedText !== getBindingElementNameText(source))
return false;
if (source.parent.parent.kind === 186 /* BindingElement */ && isMatchingReference(source.parent.parent, t.expression)) {
return true;
}
if (source.parent.parent.kind === 237 /* VariableDeclaration */) {
var maybeId = source.parent.parent.initializer;
return !!maybeId && isMatchingReference(maybeId, t.expression);
if (target.kind === 189 /* PropertyAccessExpression */ && target.name.escapedText === getBindingElementNameText(source)) {
var ancestor = source.parent.parent;
if (ancestor.kind === 186 /* BindingElement */) {
return isMatchingReference(ancestor, target.expression);
}
if (ancestor.kind === 237 /* VariableDeclaration */) {
var initializer = ancestor.initializer;
return !!initializer && isMatchingReference(initializer, target.expression);
}
}
}
return false;
@@ -44318,14 +44318,24 @@ var ts;
ts.isStringLiteral(access.argumentExpression) || ts.isNumericLiteral(access.argumentExpression) ? ts.escapeLeadingUnderscores(access.argumentExpression.text) :
undefined;
}
function getReferenceParent(source) {
if (source.kind === 189 /* PropertyAccessExpression */) {
return source.expression;
}
if (source.kind === 186 /* BindingElement */) {
var ancestor = source.parent.parent;
return ancestor.kind === 237 /* VariableDeclaration */ ? ancestor.initializer : ancestor;
}
return undefined;
}
function containsMatchingReference(source, target) {
while (source.kind === 189 /* PropertyAccessExpression */) {
source = source.expression;
if (isMatchingReference(source, target)) {
var parent = getReferenceParent(source);
while (parent) {
if (isMatchingReference(parent, target)) {
return true;
}
parent = getReferenceParent(parent);
}
return false;
}
// Return true if target is a property access xxx.yyy, source is a property access xxx.zzz, the declared
// type of xxx is a union type, and yyy is a property that is possibly a discriminant. We consider a property
@@ -47944,7 +47954,7 @@ var ts;
return true;
}
}
else if (targetType.flags & 3145728 /* UnionOrIntersection */) {
else if (targetType.flags & 3145728 /* UnionOrIntersection */ && isExcessPropertyCheckTarget(targetType)) {
for (var _i = 0, _a = targetType.types; _i < _a.length; _i++) {
var t = _a[_i];
if (isKnownProperty(t, name, isComparingJsxAttributes)) {
@@ -47952,12 +47962,14 @@ var ts;
}
}
}
else if (targetType.flags & 16777216 /* Conditional */) {
return isKnownProperty(targetType.root.trueType, name, isComparingJsxAttributes) ||
isKnownProperty(targetType.root.falseType, name, isComparingJsxAttributes);
}
return false;
}
function isExcessPropertyCheckTarget(type) {
return !!(type.flags & 524288 /* Object */ && !(ts.getObjectFlags(type) & 512 /* ObjectLiteralPatternWithComputedProperties */) ||
type.flags & 67108864 /* NonPrimitive */ ||
type.flags & 1048576 /* Union */ && ts.some(type.types, isExcessPropertyCheckTarget) ||
type.flags & 2097152 /* Intersection */ && ts.every(type.types, isExcessPropertyCheckTarget));
}
function checkJsxExpression(node, checkMode) {
if (node.expression) {
var type = checkExpression(node.expression, checkMode);
@@ -109054,6 +109066,40 @@ var ts;
})(ts || (ts = {}));
/* @internal */
var ts;
(function (ts) {
var codefix;
(function (codefix) {
var fixId = "addNameToNamelessParameter";
var errorCodes = [ts.Diagnostics.Parameter_has_a_name_but_no_type_Did_you_mean_0_Colon_1.code];
codefix.registerCodeFix({
errorCodes: errorCodes,
getCodeActions: function (context) {
var changes = ts.textChanges.ChangeTracker.with(context, function (t) { return makeChange(t, context.sourceFile, context.span.start); });
return [codefix.createCodeFixAction(fixId, changes, ts.Diagnostics.Add_parameter_name, fixId, ts.Diagnostics.Add_names_to_all_parameters_without_names)];
},
fixIds: [fixId],
getAllCodeActions: function (context) { return codefix.codeFixAll(context, errorCodes, function (changes, diag) { return makeChange(changes, diag.file, diag.start); }); },
});
function makeChange(changeTracker, sourceFile, pos) {
var token = ts.getTokenAtPosition(sourceFile, pos);
if (!ts.isIdentifier(token)) {
return ts.Debug.fail("add-name-to-nameless-parameter operates on identifiers, but got a " + ts.formatSyntaxKind(token.kind));
}
var param = token.parent;
if (!ts.isParameter(param)) {
return ts.Debug.fail("Tried to add a parameter name to a non-parameter: " + ts.formatSyntaxKind(token.kind));
}
var i = param.parent.parameters.indexOf(param);
ts.Debug.assert(!param.type, "Tried to add a parameter name to a parameter that already had one.");
ts.Debug.assert(i > -1, "Parameter not found in parent parameter list.");
var replacement = ts.createParameter(
/*decorators*/ undefined, param.modifiers, param.dotDotDotToken, "arg" + i, param.questionToken, ts.createTypeReferenceNode(token, /*typeArguments*/ undefined), param.initializer);
changeTracker.replaceNode(sourceFile, token, replacement);
}
})(codefix = ts.codefix || (ts.codefix = {}));
})(ts || (ts = {}));
/* @internal */
var ts;
(function (ts) {
var codefix;
(function (codefix) {
@@ -112070,6 +112116,40 @@ var ts;
})(ts || (ts = {}));
/* @internal */
var ts;
(function (ts) {
var codefix;
(function (codefix) {
var fixId = "addMissingNewOperator";
var errorCodes = [ts.Diagnostics.Value_of_type_0_is_not_callable_Did_you_mean_to_include_new.code];
codefix.registerCodeFix({
errorCodes: errorCodes,
getCodeActions: function (context) {
var sourceFile = context.sourceFile, span = context.span;
var changes = ts.textChanges.ChangeTracker.with(context, function (t) { return addMissingNewOperator(t, sourceFile, span); });
return [codefix.createCodeFixAction(fixId, changes, ts.Diagnostics.Add_missing_new_operator_to_call, fixId, ts.Diagnostics.Add_missing_new_operator_to_all_calls)];
},
fixIds: [fixId],
getAllCodeActions: function (context) { return codefix.codeFixAll(context, errorCodes, function (changes, diag) {
return addMissingNewOperator(changes, context.sourceFile, diag);
}); },
});
function addMissingNewOperator(changes, sourceFile, span) {
var call = ts.cast(findAncestorMatchingSpan(sourceFile, span), ts.isCallExpression);
var newExpression = ts.createNew(call.expression, call.typeArguments, call.arguments);
changes.replaceNode(sourceFile, call, newExpression);
}
function findAncestorMatchingSpan(sourceFile, span) {
var token = ts.getTokenAtPosition(sourceFile, span.start);
var end = ts.textSpanEnd(span);
while (token.end < end) {
token = token.parent;
}
return token;
}
})(codefix = ts.codefix || (ts.codefix = {}));
})(ts || (ts = {}));
/* @internal */
var ts;
(function (ts) {
var codefix;
(function (codefix) {
+121 -41
View File
@@ -75,7 +75,7 @@ var ts;
// If changing the text in this section, be sure to test `configureNightly` too.
ts.versionMajorMinor = "3.2";
/** The version of the TypeScript compiler release */
ts.version = ts.versionMajorMinor + ".2";
ts.version = ts.versionMajorMinor + ".3";
})(ts || (ts = {}));
(function (ts) {
/* @internal */
@@ -32158,7 +32158,8 @@ var ts;
}
// If we're in an external module, we can't reference value symbols created from UMD export declarations
if (result && isInExternalModule && (meaning & 67220415 /* Value */) === 67220415 /* Value */ && !(originalLocation.flags & 2097152 /* JSDoc */)) {
if (ts.some(result.declarations, function (d) { return ts.isNamespaceExportDeclaration(d) || ts.isSourceFile(d) && !!d.symbol.globalExports; })) {
var merged = getMergedSymbol(result);
if (ts.length(merged.declarations) && ts.every(merged.declarations, function (d) { return ts.isNamespaceExportDeclaration(d) || ts.isSourceFile(d) && !!d.symbol.globalExports; })) {
error(errorLocation, ts.Diagnostics._0_refers_to_a_UMD_global_but_the_current_file_is_a_module_Consider_adding_an_import_instead, ts.unescapeLeadingUnderscores(name)); // TODO: GH#18217
}
}
@@ -35587,12 +35588,11 @@ var ts;
return anyType;
}
// Handle export default expressions
if (ts.isSourceFile(declaration)) {
var jsonSourceFile = ts.cast(declaration, ts.isJsonSourceFile);
if (!jsonSourceFile.statements.length) {
if (ts.isSourceFile(declaration) && ts.isJsonSourceFile(declaration)) {
if (!declaration.statements.length) {
return emptyObjectType;
}
var type_1 = getWidenedLiteralType(checkExpression(jsonSourceFile.statements[0].expression));
var type_1 = getWidenedLiteralType(checkExpression(declaration.statements[0].expression));
if (type_1.flags & 524288 /* Object */) {
return getRegularTypeOfObjectLiteral(type_1);
}
@@ -35616,7 +35616,8 @@ var ts;
|| ts.isClassDeclaration(declaration)
|| ts.isFunctionDeclaration(declaration)
|| (ts.isMethodDeclaration(declaration) && !ts.isObjectLiteralMethod(declaration))
|| ts.isMethodSignature(declaration)) {
|| ts.isMethodSignature(declaration)
|| ts.isSourceFile(declaration)) {
// Symbol is property of some kind that is merged with something - should use `getTypeOfFuncClassEnumModule` and not `getTypeOfVariableOrParameterOrProperty`
if (symbol.flags & (16 /* Function */ | 8192 /* Method */ | 32 /* Class */ | 384 /* Enum */ | 512 /* ValueModule */)) {
return getTypeOfFuncClassEnumModule(symbol);
@@ -39720,14 +39721,11 @@ var ts;
if (checkType === wildcardType || extendsType === wildcardType) {
return wildcardType;
}
// If this is a distributive conditional type and the check type is generic we need to defer
// resolution of the conditional type such that a later instantiation will properly distribute
// over union types.
var isDeferred = root.isDistributive && maybeTypeOfKind(checkType, 63176704 /* Instantiable */);
var checkTypeInstantiable = maybeTypeOfKind(checkType, 63176704 /* Instantiable */);
var combinedMapper;
if (root.inferTypeParameters) {
var context = createInferenceContext(root.inferTypeParameters, /*signature*/ undefined, 0 /* None */);
if (!isDeferred) {
if (!checkTypeInstantiable) {
// We don't want inferences from constraints as they may cause us to eagerly resolve the
// conditional type instead of deferring resolution. Also, we always want strict function
// types rules (i.e. proper contravariance) for inferences.
@@ -39735,16 +39733,17 @@ var ts;
}
combinedMapper = combineTypeMappers(mapper, context);
}
if (!isDeferred) {
if (extendsType.flags & 3 /* AnyOrUnknown */) {
// Instantiate the extends type including inferences for 'infer T' type parameters
var inferredExtendsType = combinedMapper ? instantiateType(root.extendsType, combinedMapper) : extendsType;
// We attempt to resolve the conditional type only when the check and extends types are non-generic
if (!checkTypeInstantiable && !maybeTypeOfKind(inferredExtendsType, 63176704 /* Instantiable */)) {
if (inferredExtendsType.flags & 3 /* AnyOrUnknown */) {
return instantiateType(root.trueType, mapper);
}
// Return union of trueType and falseType for 'any' since it matches anything
if (checkType.flags & 1 /* Any */) {
return getUnionType([instantiateType(root.trueType, combinedMapper || mapper), instantiateType(root.falseType, mapper)]);
}
// Instantiate the extends type including inferences for 'infer T' type parameters
var inferredExtendsType = combinedMapper ? instantiateType(root.extendsType, combinedMapper) : extendsType;
// Return falseType for a definitely false extends check. We check an instantations of the two
// types with type parameters mapped to the wildcard type, the most permissive instantiations
// possible (the wildcard type is assignable to and from all types). If those are not related,
@@ -41650,7 +41649,7 @@ var ts;
if (!noImplicitAny && ts.getObjectFlags(target) & 16384 /* JSLiteral */) {
return false; // Disable excess property checks on JS literals to simulate having an implicit "index signature" - but only outside of noImplicitAny
}
if (maybeTypeOfKind(target, 524288 /* Object */) && !(ts.getObjectFlags(target) & 512 /* ObjectLiteralPatternWithComputedProperties */)) {
if (isExcessPropertyCheckTarget(target)) {
var isComparingJsxAttributes = !!(ts.getObjectFlags(source) & 4096 /* JsxAttributes */);
if ((relation === assignableRelation || relation === definitelyAssignableRelation || relation === comparableRelation) &&
(isTypeSubsetOf(globalObjectType, target) || (!isComparingJsxAttributes && isEmptyObjectType(target)))) {
@@ -41663,6 +41662,9 @@ var ts;
var _loop_6 = function (prop) {
if (shouldCheckAsExcessProperty(prop, source.symbol) && !isKnownProperty(target, prop.escapedName, isComparingJsxAttributes)) {
if (reportErrors) {
// Report error in terms of object types in the target as those are the only ones
// we check in isKnownProperty.
var errorTarget = filterType(target, isExcessPropertyCheckTarget);
// We know *exactly* where things went wrong when comparing the types.
// Use this property as the error node as this will be more helpful in
// reasoning about what went wrong.
@@ -41672,7 +41674,7 @@ var ts;
// JsxAttributes has an object-literal flag and undergo same type-assignablity check as normal object-literal.
// However, using an object-literal error message will be very confusing to the users so we give different a message.
// TODO: Spelling suggestions for excess jsx attributes (needs new diagnostic messages)
reportError(ts.Diagnostics.Property_0_does_not_exist_on_type_1, symbolToString(prop), typeToString(target));
reportError(ts.Diagnostics.Property_0_does_not_exist_on_type_1, symbolToString(prop), typeToString(errorTarget));
}
else {
// use the property's value declaration if the property is assigned inside the literal itself
@@ -41684,14 +41686,14 @@ var ts;
errorNode = propDeclaration;
var name = propDeclaration.name;
if (ts.isIdentifier(name)) {
suggestion = getSuggestionForNonexistentProperty(name, target);
suggestion = getSuggestionForNonexistentProperty(name, errorTarget);
}
}
if (suggestion !== undefined) {
reportError(ts.Diagnostics.Object_literal_may_only_specify_known_properties_but_0_does_not_exist_in_type_1_Did_you_mean_to_write_2, symbolToString(prop), typeToString(target), suggestion);
reportError(ts.Diagnostics.Object_literal_may_only_specify_known_properties_but_0_does_not_exist_in_type_1_Did_you_mean_to_write_2, symbolToString(prop), typeToString(errorTarget), suggestion);
}
else {
reportError(ts.Diagnostics.Object_literal_may_only_specify_known_properties_and_0_does_not_exist_in_type_1, symbolToString(prop), typeToString(target));
reportError(ts.Diagnostics.Object_literal_may_only_specify_known_properties_and_0_does_not_exist_in_type_1, symbolToString(prop), typeToString(errorTarget));
}
}
}
@@ -44298,17 +44300,15 @@ var ts;
getAccessedPropertyName(source) === getAccessedPropertyName(target) &&
isMatchingReference(source.expression, target.expression);
case 186 /* BindingElement */:
if (target.kind !== 189 /* PropertyAccessExpression */)
return false;
var t = target;
if (t.name.escapedText !== getBindingElementNameText(source))
return false;
if (source.parent.parent.kind === 186 /* BindingElement */ && isMatchingReference(source.parent.parent, t.expression)) {
return true;
}
if (source.parent.parent.kind === 237 /* VariableDeclaration */) {
var maybeId = source.parent.parent.initializer;
return !!maybeId && isMatchingReference(maybeId, t.expression);
if (target.kind === 189 /* PropertyAccessExpression */ && target.name.escapedText === getBindingElementNameText(source)) {
var ancestor = source.parent.parent;
if (ancestor.kind === 186 /* BindingElement */) {
return isMatchingReference(ancestor, target.expression);
}
if (ancestor.kind === 237 /* VariableDeclaration */) {
var initializer = ancestor.initializer;
return !!initializer && isMatchingReference(initializer, target.expression);
}
}
}
return false;
@@ -44318,14 +44318,24 @@ var ts;
ts.isStringLiteral(access.argumentExpression) || ts.isNumericLiteral(access.argumentExpression) ? ts.escapeLeadingUnderscores(access.argumentExpression.text) :
undefined;
}
function getReferenceParent(source) {
if (source.kind === 189 /* PropertyAccessExpression */) {
return source.expression;
}
if (source.kind === 186 /* BindingElement */) {
var ancestor = source.parent.parent;
return ancestor.kind === 237 /* VariableDeclaration */ ? ancestor.initializer : ancestor;
}
return undefined;
}
function containsMatchingReference(source, target) {
while (source.kind === 189 /* PropertyAccessExpression */) {
source = source.expression;
if (isMatchingReference(source, target)) {
var parent = getReferenceParent(source);
while (parent) {
if (isMatchingReference(parent, target)) {
return true;
}
parent = getReferenceParent(parent);
}
return false;
}
// Return true if target is a property access xxx.yyy, source is a property access xxx.zzz, the declared
// type of xxx is a union type, and yyy is a property that is possibly a discriminant. We consider a property
@@ -47944,7 +47954,7 @@ var ts;
return true;
}
}
else if (targetType.flags & 3145728 /* UnionOrIntersection */) {
else if (targetType.flags & 3145728 /* UnionOrIntersection */ && isExcessPropertyCheckTarget(targetType)) {
for (var _i = 0, _a = targetType.types; _i < _a.length; _i++) {
var t = _a[_i];
if (isKnownProperty(t, name, isComparingJsxAttributes)) {
@@ -47952,12 +47962,14 @@ var ts;
}
}
}
else if (targetType.flags & 16777216 /* Conditional */) {
return isKnownProperty(targetType.root.trueType, name, isComparingJsxAttributes) ||
isKnownProperty(targetType.root.falseType, name, isComparingJsxAttributes);
}
return false;
}
function isExcessPropertyCheckTarget(type) {
return !!(type.flags & 524288 /* Object */ && !(ts.getObjectFlags(type) & 512 /* ObjectLiteralPatternWithComputedProperties */) ||
type.flags & 67108864 /* NonPrimitive */ ||
type.flags & 1048576 /* Union */ && ts.some(type.types, isExcessPropertyCheckTarget) ||
type.flags & 2097152 /* Intersection */ && ts.every(type.types, isExcessPropertyCheckTarget));
}
function checkJsxExpression(node, checkMode) {
if (node.expression) {
var type = checkExpression(node.expression, checkMode);
@@ -109054,6 +109066,40 @@ var ts;
})(ts || (ts = {}));
/* @internal */
var ts;
(function (ts) {
var codefix;
(function (codefix) {
var fixId = "addNameToNamelessParameter";
var errorCodes = [ts.Diagnostics.Parameter_has_a_name_but_no_type_Did_you_mean_0_Colon_1.code];
codefix.registerCodeFix({
errorCodes: errorCodes,
getCodeActions: function (context) {
var changes = ts.textChanges.ChangeTracker.with(context, function (t) { return makeChange(t, context.sourceFile, context.span.start); });
return [codefix.createCodeFixAction(fixId, changes, ts.Diagnostics.Add_parameter_name, fixId, ts.Diagnostics.Add_names_to_all_parameters_without_names)];
},
fixIds: [fixId],
getAllCodeActions: function (context) { return codefix.codeFixAll(context, errorCodes, function (changes, diag) { return makeChange(changes, diag.file, diag.start); }); },
});
function makeChange(changeTracker, sourceFile, pos) {
var token = ts.getTokenAtPosition(sourceFile, pos);
if (!ts.isIdentifier(token)) {
return ts.Debug.fail("add-name-to-nameless-parameter operates on identifiers, but got a " + ts.formatSyntaxKind(token.kind));
}
var param = token.parent;
if (!ts.isParameter(param)) {
return ts.Debug.fail("Tried to add a parameter name to a non-parameter: " + ts.formatSyntaxKind(token.kind));
}
var i = param.parent.parameters.indexOf(param);
ts.Debug.assert(!param.type, "Tried to add a parameter name to a parameter that already had one.");
ts.Debug.assert(i > -1, "Parameter not found in parent parameter list.");
var replacement = ts.createParameter(
/*decorators*/ undefined, param.modifiers, param.dotDotDotToken, "arg" + i, param.questionToken, ts.createTypeReferenceNode(token, /*typeArguments*/ undefined), param.initializer);
changeTracker.replaceNode(sourceFile, token, replacement);
}
})(codefix = ts.codefix || (ts.codefix = {}));
})(ts || (ts = {}));
/* @internal */
var ts;
(function (ts) {
var codefix;
(function (codefix) {
@@ -112070,6 +112116,40 @@ var ts;
})(ts || (ts = {}));
/* @internal */
var ts;
(function (ts) {
var codefix;
(function (codefix) {
var fixId = "addMissingNewOperator";
var errorCodes = [ts.Diagnostics.Value_of_type_0_is_not_callable_Did_you_mean_to_include_new.code];
codefix.registerCodeFix({
errorCodes: errorCodes,
getCodeActions: function (context) {
var sourceFile = context.sourceFile, span = context.span;
var changes = ts.textChanges.ChangeTracker.with(context, function (t) { return addMissingNewOperator(t, sourceFile, span); });
return [codefix.createCodeFixAction(fixId, changes, ts.Diagnostics.Add_missing_new_operator_to_call, fixId, ts.Diagnostics.Add_missing_new_operator_to_all_calls)];
},
fixIds: [fixId],
getAllCodeActions: function (context) { return codefix.codeFixAll(context, errorCodes, function (changes, diag) {
return addMissingNewOperator(changes, context.sourceFile, diag);
}); },
});
function addMissingNewOperator(changes, sourceFile, span) {
var call = ts.cast(findAncestorMatchingSpan(sourceFile, span), ts.isCallExpression);
var newExpression = ts.createNew(call.expression, call.typeArguments, call.arguments);
changes.replaceNode(sourceFile, call, newExpression);
}
function findAncestorMatchingSpan(sourceFile, span) {
var token = ts.getTokenAtPosition(sourceFile, span.start);
var end = ts.textSpanEnd(span);
while (token.end < end) {
token = token.parent;
}
return token;
}
})(codefix = ts.codefix || (ts.codefix = {}));
})(ts || (ts = {}));
/* @internal */
var ts;
(function (ts) {
var codefix;
(function (codefix) {
+53 -41
View File
@@ -88,7 +88,7 @@ var ts;
// If changing the text in this section, be sure to test `configureNightly` too.
ts.versionMajorMinor = "3.2";
/** The version of the TypeScript compiler release */
ts.version = ts.versionMajorMinor + ".2";
ts.version = ts.versionMajorMinor + ".3";
})(ts || (ts = {}));
(function (ts) {
/* @internal */
@@ -32171,7 +32171,8 @@ var ts;
}
// If we're in an external module, we can't reference value symbols created from UMD export declarations
if (result && isInExternalModule && (meaning & 67220415 /* Value */) === 67220415 /* Value */ && !(originalLocation.flags & 2097152 /* JSDoc */)) {
if (ts.some(result.declarations, function (d) { return ts.isNamespaceExportDeclaration(d) || ts.isSourceFile(d) && !!d.symbol.globalExports; })) {
var merged = getMergedSymbol(result);
if (ts.length(merged.declarations) && ts.every(merged.declarations, function (d) { return ts.isNamespaceExportDeclaration(d) || ts.isSourceFile(d) && !!d.symbol.globalExports; })) {
error(errorLocation, ts.Diagnostics._0_refers_to_a_UMD_global_but_the_current_file_is_a_module_Consider_adding_an_import_instead, ts.unescapeLeadingUnderscores(name)); // TODO: GH#18217
}
}
@@ -35600,12 +35601,11 @@ var ts;
return anyType;
}
// Handle export default expressions
if (ts.isSourceFile(declaration)) {
var jsonSourceFile = ts.cast(declaration, ts.isJsonSourceFile);
if (!jsonSourceFile.statements.length) {
if (ts.isSourceFile(declaration) && ts.isJsonSourceFile(declaration)) {
if (!declaration.statements.length) {
return emptyObjectType;
}
var type_1 = getWidenedLiteralType(checkExpression(jsonSourceFile.statements[0].expression));
var type_1 = getWidenedLiteralType(checkExpression(declaration.statements[0].expression));
if (type_1.flags & 524288 /* Object */) {
return getRegularTypeOfObjectLiteral(type_1);
}
@@ -35629,7 +35629,8 @@ var ts;
|| ts.isClassDeclaration(declaration)
|| ts.isFunctionDeclaration(declaration)
|| (ts.isMethodDeclaration(declaration) && !ts.isObjectLiteralMethod(declaration))
|| ts.isMethodSignature(declaration)) {
|| ts.isMethodSignature(declaration)
|| ts.isSourceFile(declaration)) {
// Symbol is property of some kind that is merged with something - should use `getTypeOfFuncClassEnumModule` and not `getTypeOfVariableOrParameterOrProperty`
if (symbol.flags & (16 /* Function */ | 8192 /* Method */ | 32 /* Class */ | 384 /* Enum */ | 512 /* ValueModule */)) {
return getTypeOfFuncClassEnumModule(symbol);
@@ -39733,14 +39734,11 @@ var ts;
if (checkType === wildcardType || extendsType === wildcardType) {
return wildcardType;
}
// If this is a distributive conditional type and the check type is generic we need to defer
// resolution of the conditional type such that a later instantiation will properly distribute
// over union types.
var isDeferred = root.isDistributive && maybeTypeOfKind(checkType, 63176704 /* Instantiable */);
var checkTypeInstantiable = maybeTypeOfKind(checkType, 63176704 /* Instantiable */);
var combinedMapper;
if (root.inferTypeParameters) {
var context = createInferenceContext(root.inferTypeParameters, /*signature*/ undefined, 0 /* None */);
if (!isDeferred) {
if (!checkTypeInstantiable) {
// We don't want inferences from constraints as they may cause us to eagerly resolve the
// conditional type instead of deferring resolution. Also, we always want strict function
// types rules (i.e. proper contravariance) for inferences.
@@ -39748,16 +39746,17 @@ var ts;
}
combinedMapper = combineTypeMappers(mapper, context);
}
if (!isDeferred) {
if (extendsType.flags & 3 /* AnyOrUnknown */) {
// Instantiate the extends type including inferences for 'infer T' type parameters
var inferredExtendsType = combinedMapper ? instantiateType(root.extendsType, combinedMapper) : extendsType;
// We attempt to resolve the conditional type only when the check and extends types are non-generic
if (!checkTypeInstantiable && !maybeTypeOfKind(inferredExtendsType, 63176704 /* Instantiable */)) {
if (inferredExtendsType.flags & 3 /* AnyOrUnknown */) {
return instantiateType(root.trueType, mapper);
}
// Return union of trueType and falseType for 'any' since it matches anything
if (checkType.flags & 1 /* Any */) {
return getUnionType([instantiateType(root.trueType, combinedMapper || mapper), instantiateType(root.falseType, mapper)]);
}
// Instantiate the extends type including inferences for 'infer T' type parameters
var inferredExtendsType = combinedMapper ? instantiateType(root.extendsType, combinedMapper) : extendsType;
// Return falseType for a definitely false extends check. We check an instantations of the two
// types with type parameters mapped to the wildcard type, the most permissive instantiations
// possible (the wildcard type is assignable to and from all types). If those are not related,
@@ -41663,7 +41662,7 @@ var ts;
if (!noImplicitAny && ts.getObjectFlags(target) & 16384 /* JSLiteral */) {
return false; // Disable excess property checks on JS literals to simulate having an implicit "index signature" - but only outside of noImplicitAny
}
if (maybeTypeOfKind(target, 524288 /* Object */) && !(ts.getObjectFlags(target) & 512 /* ObjectLiteralPatternWithComputedProperties */)) {
if (isExcessPropertyCheckTarget(target)) {
var isComparingJsxAttributes = !!(ts.getObjectFlags(source) & 4096 /* JsxAttributes */);
if ((relation === assignableRelation || relation === definitelyAssignableRelation || relation === comparableRelation) &&
(isTypeSubsetOf(globalObjectType, target) || (!isComparingJsxAttributes && isEmptyObjectType(target)))) {
@@ -41676,6 +41675,9 @@ var ts;
var _loop_6 = function (prop) {
if (shouldCheckAsExcessProperty(prop, source.symbol) && !isKnownProperty(target, prop.escapedName, isComparingJsxAttributes)) {
if (reportErrors) {
// Report error in terms of object types in the target as those are the only ones
// we check in isKnownProperty.
var errorTarget = filterType(target, isExcessPropertyCheckTarget);
// We know *exactly* where things went wrong when comparing the types.
// Use this property as the error node as this will be more helpful in
// reasoning about what went wrong.
@@ -41685,7 +41687,7 @@ var ts;
// JsxAttributes has an object-literal flag and undergo same type-assignablity check as normal object-literal.
// However, using an object-literal error message will be very confusing to the users so we give different a message.
// TODO: Spelling suggestions for excess jsx attributes (needs new diagnostic messages)
reportError(ts.Diagnostics.Property_0_does_not_exist_on_type_1, symbolToString(prop), typeToString(target));
reportError(ts.Diagnostics.Property_0_does_not_exist_on_type_1, symbolToString(prop), typeToString(errorTarget));
}
else {
// use the property's value declaration if the property is assigned inside the literal itself
@@ -41697,14 +41699,14 @@ var ts;
errorNode = propDeclaration;
var name = propDeclaration.name;
if (ts.isIdentifier(name)) {
suggestion = getSuggestionForNonexistentProperty(name, target);
suggestion = getSuggestionForNonexistentProperty(name, errorTarget);
}
}
if (suggestion !== undefined) {
reportError(ts.Diagnostics.Object_literal_may_only_specify_known_properties_but_0_does_not_exist_in_type_1_Did_you_mean_to_write_2, symbolToString(prop), typeToString(target), suggestion);
reportError(ts.Diagnostics.Object_literal_may_only_specify_known_properties_but_0_does_not_exist_in_type_1_Did_you_mean_to_write_2, symbolToString(prop), typeToString(errorTarget), suggestion);
}
else {
reportError(ts.Diagnostics.Object_literal_may_only_specify_known_properties_and_0_does_not_exist_in_type_1, symbolToString(prop), typeToString(target));
reportError(ts.Diagnostics.Object_literal_may_only_specify_known_properties_and_0_does_not_exist_in_type_1, symbolToString(prop), typeToString(errorTarget));
}
}
}
@@ -44311,17 +44313,15 @@ var ts;
getAccessedPropertyName(source) === getAccessedPropertyName(target) &&
isMatchingReference(source.expression, target.expression);
case 186 /* BindingElement */:
if (target.kind !== 189 /* PropertyAccessExpression */)
return false;
var t = target;
if (t.name.escapedText !== getBindingElementNameText(source))
return false;
if (source.parent.parent.kind === 186 /* BindingElement */ && isMatchingReference(source.parent.parent, t.expression)) {
return true;
}
if (source.parent.parent.kind === 237 /* VariableDeclaration */) {
var maybeId = source.parent.parent.initializer;
return !!maybeId && isMatchingReference(maybeId, t.expression);
if (target.kind === 189 /* PropertyAccessExpression */ && target.name.escapedText === getBindingElementNameText(source)) {
var ancestor = source.parent.parent;
if (ancestor.kind === 186 /* BindingElement */) {
return isMatchingReference(ancestor, target.expression);
}
if (ancestor.kind === 237 /* VariableDeclaration */) {
var initializer = ancestor.initializer;
return !!initializer && isMatchingReference(initializer, target.expression);
}
}
}
return false;
@@ -44331,14 +44331,24 @@ var ts;
ts.isStringLiteral(access.argumentExpression) || ts.isNumericLiteral(access.argumentExpression) ? ts.escapeLeadingUnderscores(access.argumentExpression.text) :
undefined;
}
function getReferenceParent(source) {
if (source.kind === 189 /* PropertyAccessExpression */) {
return source.expression;
}
if (source.kind === 186 /* BindingElement */) {
var ancestor = source.parent.parent;
return ancestor.kind === 237 /* VariableDeclaration */ ? ancestor.initializer : ancestor;
}
return undefined;
}
function containsMatchingReference(source, target) {
while (source.kind === 189 /* PropertyAccessExpression */) {
source = source.expression;
if (isMatchingReference(source, target)) {
var parent = getReferenceParent(source);
while (parent) {
if (isMatchingReference(parent, target)) {
return true;
}
parent = getReferenceParent(parent);
}
return false;
}
// Return true if target is a property access xxx.yyy, source is a property access xxx.zzz, the declared
// type of xxx is a union type, and yyy is a property that is possibly a discriminant. We consider a property
@@ -47957,7 +47967,7 @@ var ts;
return true;
}
}
else if (targetType.flags & 3145728 /* UnionOrIntersection */) {
else if (targetType.flags & 3145728 /* UnionOrIntersection */ && isExcessPropertyCheckTarget(targetType)) {
for (var _i = 0, _a = targetType.types; _i < _a.length; _i++) {
var t = _a[_i];
if (isKnownProperty(t, name, isComparingJsxAttributes)) {
@@ -47965,12 +47975,14 @@ var ts;
}
}
}
else if (targetType.flags & 16777216 /* Conditional */) {
return isKnownProperty(targetType.root.trueType, name, isComparingJsxAttributes) ||
isKnownProperty(targetType.root.falseType, name, isComparingJsxAttributes);
}
return false;
}
function isExcessPropertyCheckTarget(type) {
return !!(type.flags & 524288 /* Object */ && !(ts.getObjectFlags(type) & 512 /* ObjectLiteralPatternWithComputedProperties */) ||
type.flags & 67108864 /* NonPrimitive */ ||
type.flags & 1048576 /* Union */ && ts.some(type.types, isExcessPropertyCheckTarget) ||
type.flags & 2097152 /* Intersection */ && ts.every(type.types, isExcessPropertyCheckTarget));
}
function checkJsxExpression(node, checkMode) {
if (node.expression) {
var type = checkExpression(node.expression, checkMode);