Skip to content

Commit 7566529

Browse files
Respond to CR
1 parent 845f573 commit 7566529

4 files changed

Lines changed: 29 additions & 29 deletions

File tree

src/compiler/checker.ts

Lines changed: 23 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -13473,31 +13473,32 @@ namespace ts {
1347313473
node.parent.openingElement.attributes :
1347413474
undefined; // node.parent is JsxFragment with no attributes
1347513475

13476-
if (jsxAttributes) {
13477-
// When we trying to resolve JsxOpeningLikeElement as a stateless function element, we will already give its attributes a contextual type
13478-
// which is a type of the parameter of the signature we are trying out.
13479-
// If there is no contextual type (e.g. we are trying to resolve stateful component), get attributes type from resolving element's tagName
13480-
const attributesType = getContextualType(jsxAttributes);
13476+
if (!jsxAttributes) {
13477+
return anyType; // don't check children of a fragment
13478+
}
1348113479

13482-
if (!attributesType || isTypeAny(attributesType)) {
13483-
return undefined;
13484-
}
13480+
// When we trying to resolve JsxOpeningLikeElement as a stateless function element, we will already give its attributes a contextual type
13481+
// which is a type of the parameter of the signature we are trying out.
13482+
// If there is no contextual type (e.g. we are trying to resolve stateful component), get attributes type from resolving element's tagName
13483+
const attributesType = getContextualType(jsxAttributes);
1348513484

13486-
if (isJsxAttribute(node.parent)) {
13487-
// JSX expression is in JSX attribute
13488-
return getTypeOfPropertyOfContextualType(attributesType, node.parent.name.escapedText);
13489-
}
13490-
else if (node.parent.kind === SyntaxKind.JsxElement) {
13491-
// JSX expression is in children of JSX Element, we will look for an "children" atttribute (we get the name from JSX.ElementAttributesProperty)
13492-
const jsxChildrenPropertyName = getJsxElementChildrenPropertyname();
13493-
return jsxChildrenPropertyName && jsxChildrenPropertyName !== "" ? getTypeOfPropertyOfContextualType(attributesType, jsxChildrenPropertyName) : anyType;
13494-
}
13495-
else {
13496-
// JSX expression is in JSX spread attribute
13497-
return attributesType;
13498-
}
13485+
if (!attributesType || isTypeAny(attributesType)) {
13486+
return undefined;
13487+
}
13488+
13489+
if (isJsxAttribute(node.parent)) {
13490+
// JSX expression is in JSX attribute
13491+
return getTypeOfPropertyOfContextualType(attributesType, node.parent.name.escapedText);
13492+
}
13493+
else if (node.parent.kind === SyntaxKind.JsxElement) {
13494+
// JSX expression is in children of JSX Element, we will look for an "children" atttribute (we get the name from JSX.ElementAttributesProperty)
13495+
const jsxChildrenPropertyName = getJsxElementChildrenPropertyname();
13496+
return jsxChildrenPropertyName && jsxChildrenPropertyName !== "" ? getTypeOfPropertyOfContextualType(attributesType, jsxChildrenPropertyName) : anyType;
13497+
}
13498+
else {
13499+
// JSX expression is in JSX spread attribute
13500+
return attributesType;
1349913501
}
13500-
return anyType; // don't check children of a fragment
1350113502
}
1350213503

1350313504
function getContextualTypeForJsxAttribute(attribute: JsxAttribute | JsxSpreadAttribute) {

src/compiler/parser.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3987,7 +3987,6 @@ namespace ts {
39873987
else if (opening.kind === SyntaxKind.JsxOpeningFragment) {
39883988
const node = <JsxFragment>createNode(SyntaxKind.JsxFragment, opening.pos);
39893989
node.openingFragment = opening;
3990-
39913990
node.children = parseJsxChildren(node.openingFragment);
39923991
node.closingFragment = parseJsxClosingFragment(inExpressionContext);
39933992

@@ -4058,12 +4057,12 @@ namespace ts {
40584057
else if (token() === SyntaxKind.EndOfFileToken) {
40594058
// If we hit EOF, issue the error at the tag that lacks the closing element
40604059
// rather than at the end of the file (which is useless)
4061-
if (isJsxOpeningElement(openingTag)) {
4062-
const openingTagName = openingTag.tagName;
4063-
parseErrorAtPosition(openingTagName.pos, openingTagName.end - openingTagName.pos, Diagnostics.JSX_element_0_has_no_corresponding_closing_tag, getTextOfNodeFromSourceText(sourceText, openingTagName));
4060+
if (isJsxOpeningFragment(openingTag)) {
4061+
parseErrorAtPosition(openingTag.pos, openingTag.end - openingTag.pos, Diagnostics.JSX_fragment_has_no_corresponding_closing_tag);
40644062
}
40654063
else {
4066-
parseErrorAtPosition(openingTag.pos, openingTag.end - openingTag.pos, Diagnostics.JSX_fragment_has_no_corresponding_closing_tag);
4064+
const openingTagName = openingTag.tagName;
4065+
parseErrorAtPosition(openingTagName.pos, openingTagName.end - openingTagName.pos, Diagnostics.JSX_element_0_has_no_corresponding_closing_tag, getTextOfNodeFromSourceText(sourceText, openingTagName));
40674066
}
40684067
break;
40694068
}

src/compiler/scanner.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ namespace ts {
1313

1414
/* @internal */
1515
export function tokenIsIdentifierOrKeywordOrGreaterThan(token: SyntaxKind): boolean {
16-
return token === SyntaxKind.GreaterThanToken || token >= SyntaxKind.Identifier;
16+
return token === SyntaxKind.GreaterThanToken || tokenIsIdentifierOrKeyword(token);
1717
}
1818

1919
export interface Scanner {

src/compiler/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1621,7 +1621,7 @@ namespace ts {
16211621
closingElement: JsxClosingElement;
16221622
}
16231623

1624-
/// Either the opening tag in a <Tag>...</Tag> pair, the opening tag in a <>...</> pair, or the lone <Tag /> in a self-closing form
1624+
/// Either the opening tag in a <Tag>...</Tag> pair or the lone <Tag /> in a self-closing form
16251625
export type JsxOpeningLikeElement = JsxSelfClosingElement | JsxOpeningElement;
16261626

16271627
export type JsxAttributeLike = JsxAttribute | JsxSpreadAttribute;

0 commit comments

Comments
 (0)