Do not allow freshness to move errors out of the current file, ensure json documents are deeply unfreshened and fully widened (#35048)

This commit is contained in:
Wesley Wigham
2019-11-12 13:30:27 -08:00
committed by GitHub
parent f3344767dd
commit aa39080ac7
6 changed files with 158 additions and 8 deletions

View File

@@ -7310,11 +7310,7 @@ namespace ts {
if (!declaration.statements.length) {
return emptyObjectType;
}
const type = getWidenedLiteralType(checkExpression(declaration.statements[0].expression));
if (type.flags & TypeFlags.Object) {
return getRegularTypeOfObjectLiteral(type);
}
return type;
return getWidenedType(getWidenedLiteralType(checkExpression(declaration.statements[0].expression)));
}
// Handle variable, parameter or property
@@ -14807,7 +14803,7 @@ namespace 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)
if (prop.valueDeclaration && isJsxAttribute(prop.valueDeclaration)) {
if (prop.valueDeclaration && isJsxAttribute(prop.valueDeclaration) && getSourceFileOfNode(errorNode) === getSourceFileOfNode(prop.valueDeclaration.name)) {
// Note that extraneous children (as in `<NoChild>extra</NoChild>`) don't pass this check,
// since `children` is a SyntaxKind.PropertySignature instead of a SyntaxKind.JsxAttribute.
errorNode = prop.valueDeclaration.name;
@@ -14818,7 +14814,7 @@ namespace ts {
// use the property's value declaration if the property is assigned inside the literal itself
const objectLiteralDeclaration = source.symbol && firstOrUndefined(source.symbol.declarations);
let suggestion;
if (prop.valueDeclaration && findAncestor(prop.valueDeclaration, d => d === objectLiteralDeclaration)) {
if (prop.valueDeclaration && findAncestor(prop.valueDeclaration, d => d === objectLiteralDeclaration) && getSourceFileOfNode(objectLiteralDeclaration) === getSourceFileOfNode(errorNode)) {
const propDeclaration = prop.valueDeclaration as ObjectLiteralElementLike;
Debug.assertNode(propDeclaration, isObjectLiteralElementLike);