mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-05-25 16:07:52 -05:00
JsxTagNameExpression can only be Identifier | ThisExpression, not any PrimaryExpression (#21555)
* JsxTagNameExpression can only be Identifier | ThisExpression, not any PrimaryExpression * Use a type similar to PropertyAccessEntityNameExpression * Fix lint errors
This commit is contained in:
@@ -16434,16 +16434,7 @@ namespace ts {
|
||||
* Returns true iff React would emit this tag name as a string rather than an identifier or qualified name
|
||||
*/
|
||||
function isJsxIntrinsicIdentifier(tagName: JsxTagNameExpression): boolean {
|
||||
// TODO (yuisu): comment
|
||||
switch (tagName.kind) {
|
||||
case SyntaxKind.PropertyAccessExpression:
|
||||
case SyntaxKind.ThisKeyword:
|
||||
return false;
|
||||
case SyntaxKind.Identifier:
|
||||
return isIntrinsicJsxName((<Identifier>tagName).escapedText);
|
||||
default:
|
||||
return Debug.fail();
|
||||
}
|
||||
return tagName.kind === SyntaxKind.Identifier && isIntrinsicJsxName(tagName.escapedText);
|
||||
}
|
||||
|
||||
function checkJsxAttribute(node: JsxAttribute, checkMode?: CheckMode) {
|
||||
|
||||
@@ -2451,7 +2451,7 @@ namespace ts {
|
||||
|
||||
function emitJsxTagName(node: JsxTagNameExpression) {
|
||||
if (node.kind === SyntaxKind.Identifier) {
|
||||
emitExpression(<Identifier>node);
|
||||
emitExpression(node);
|
||||
}
|
||||
else {
|
||||
emit(node);
|
||||
|
||||
@@ -4314,9 +4314,9 @@ namespace ts {
|
||||
// We can't just simply use parseLeftHandSideExpressionOrHigher because then we will start consider class,function etc as a keyword
|
||||
// We only want to consider "this" as a primaryExpression
|
||||
let expression: JsxTagNameExpression = token() === SyntaxKind.ThisKeyword ?
|
||||
parseTokenNode<PrimaryExpression>() : parseIdentifierName();
|
||||
parseTokenNode<ThisExpression>() : parseIdentifierName();
|
||||
while (parseOptional(SyntaxKind.DotToken)) {
|
||||
const propertyAccess: PropertyAccessExpression = <PropertyAccessExpression>createNode(SyntaxKind.PropertyAccessExpression, expression.pos);
|
||||
const propertyAccess: JsxTagNamePropertyAccess = <JsxTagNamePropertyAccess>createNode(SyntaxKind.PropertyAccessExpression, expression.pos);
|
||||
propertyAccess.expression = expression;
|
||||
propertyAccess.name = parseRightSideOfDot(/*allowIdentifierNames*/ true);
|
||||
expression = finishNode(propertyAccess);
|
||||
@@ -7886,7 +7886,7 @@ namespace ts {
|
||||
}
|
||||
|
||||
if (lhs.kind === SyntaxKind.Identifier) {
|
||||
return (<Identifier>lhs).escapedText === (<Identifier>rhs).escapedText;
|
||||
return lhs.escapedText === (<Identifier>rhs).escapedText;
|
||||
}
|
||||
|
||||
if (lhs.kind === SyntaxKind.ThisKeyword) {
|
||||
|
||||
@@ -1761,7 +1761,11 @@ namespace ts {
|
||||
|
||||
export type JsxAttributeLike = JsxAttribute | JsxSpreadAttribute;
|
||||
|
||||
export type JsxTagNameExpression = PrimaryExpression | PropertyAccessExpression;
|
||||
export type JsxTagNameExpression = Identifier | ThisExpression | JsxTagNamePropertyAccess;
|
||||
|
||||
export interface JsxTagNamePropertyAccess extends PropertyAccessExpression {
|
||||
expression: JsxTagNameExpression;
|
||||
}
|
||||
|
||||
export interface JsxAttributes extends ObjectLiteralExpressionBase<JsxAttributeLike> {
|
||||
parent: JsxOpeningLikeElement;
|
||||
|
||||
Reference in New Issue
Block a user