Skip to content

JsxTagNameExpression can only be Identifier | ThisExpression, not any PrimaryExpression #21555

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
7 commits merged into from
Jun 29, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 1 addition & 10 deletions src/compiler/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion src/compiler/emitter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2451,7 +2451,7 @@ namespace ts {

function emitJsxTagName(node: JsxTagNameExpression) {
if (node.kind === SyntaxKind.Identifier) {
emitExpression(<Identifier>node);
emitExpression(node);
}
else {
emit(node);
Expand Down
6 changes: 3 additions & 3 deletions src/compiler/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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) {
Expand Down
6 changes: 5 additions & 1 deletion src/compiler/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
5 changes: 4 additions & 1 deletion tests/baselines/reference/api/tsserverlibrary.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1713,7 +1713,10 @@ declare namespace ts {
}
type JsxOpeningLikeElement = JsxSelfClosingElement | JsxOpeningElement;
type JsxAttributeLike = JsxAttribute | JsxSpreadAttribute;
type JsxTagNameExpression = PrimaryExpression | PropertyAccessExpression;
type JsxTagNameExpression = Identifier | ThisExpression | JsxTagNamePropertyAccess;
interface JsxTagNamePropertyAccess extends PropertyAccessExpression {
expression: JsxTagNameExpression;
}
interface JsxAttributes extends ObjectLiteralExpressionBase<JsxAttributeLike> {
parent: JsxOpeningLikeElement;
}
Expand Down
5 changes: 4 additions & 1 deletion tests/baselines/reference/api/typescript.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1105,7 +1105,10 @@ declare namespace ts {
}
type JsxOpeningLikeElement = JsxSelfClosingElement | JsxOpeningElement;
type JsxAttributeLike = JsxAttribute | JsxSpreadAttribute;
type JsxTagNameExpression = PrimaryExpression | PropertyAccessExpression;
type JsxTagNameExpression = Identifier | ThisExpression | JsxTagNamePropertyAccess;
interface JsxTagNamePropertyAccess extends PropertyAccessExpression {
expression: JsxTagNameExpression;
}
interface JsxAttributes extends ObjectLiteralExpressionBase<JsxAttributeLike> {
parent: JsxOpeningLikeElement;
}
Expand Down