Merge remote-tracking branch 'origin/master' into pathMappingModuleResolution

This commit is contained in:
vladima
2016-01-04 21:50:44 -08:00
30 changed files with 542 additions and 120 deletions

View File

@@ -7362,6 +7362,12 @@ namespace ts {
}
return type;
}
else if (operator === SyntaxKind.AmpersandAmpersandToken || operator === SyntaxKind.CommaToken) {
if (node === binaryExpression.right) {
return getContextualType(binaryExpression);
}
}
return undefined;
}
@@ -7474,24 +7480,22 @@ namespace ts {
return node === conditional.whenTrue || node === conditional.whenFalse ? getContextualType(conditional) : undefined;
}
function getContextualTypeForJsxExpression(expr: JsxExpression | JsxSpreadAttribute): Type {
// Contextual type only applies to JSX expressions that are in attribute assignments (not in 'Children' positions)
if (expr.parent.kind === SyntaxKind.JsxAttribute) {
const attrib = <JsxAttribute>expr.parent;
const attrsType = getJsxElementAttributesType(<JsxOpeningLikeElement>attrib.parent);
function getContextualTypeForJsxAttribute(attribute: JsxAttribute | JsxSpreadAttribute) {
const kind = attribute.kind;
const jsxElement = attribute.parent as JsxOpeningLikeElement;
const attrsType = getJsxElementAttributesType(jsxElement);
if (attribute.kind === SyntaxKind.JsxAttribute) {
if (!attrsType || isTypeAny(attrsType)) {
return undefined;
}
else {
return getTypeOfPropertyOfType(attrsType, attrib.name.text);
}
return getTypeOfPropertyOfType(attrsType, (attribute as JsxAttribute).name.text);
}
else if (attribute.kind === SyntaxKind.JsxSpreadAttribute) {
return attrsType;
}
if (expr.kind === SyntaxKind.JsxSpreadAttribute) {
return getJsxElementAttributesType(<JsxOpeningLikeElement>expr.parent);
}
return undefined;
Debug.fail(`Expected JsxAttribute or JsxSpreadAttribute, got ts.SyntaxKind[${kind}]`);
}
// Return the contextual type for a given expression node. During overload resolution, a contextual type may temporarily
@@ -7559,8 +7563,10 @@ namespace ts {
case SyntaxKind.ParenthesizedExpression:
return getContextualType(<ParenthesizedExpression>parent);
case SyntaxKind.JsxExpression:
return getContextualType(<JsxExpression>parent);
case SyntaxKind.JsxAttribute:
case SyntaxKind.JsxSpreadAttribute:
return getContextualTypeForJsxExpression(<JsxExpression>parent);
return getContextualTypeForJsxAttribute(<JsxAttribute | JsxSpreadAttribute>parent);
}
return undefined;
}