Skip to content

Add ThisExpression variants to JSXElementName and JSXMemberExpressionObject #5352

@overlookmotel

Description

@overlookmotel

#5223 did the bulk of the work of revamping JSXElementName (#3528). Only thing that's missing is to add:

  • JSXElementName::ThisExpression
  • JSXMemberExpressionObject::ThisExpression

A couple of notes:

Arrow functions transform

This code is currently broken:

let ident = match name {
JSXElementName::Identifier(ident) => ident,
JSXElementName::MemberExpression(member_expr) => {
member_expr.get_object_identifier_mut()
}
JSXElementName::IdentifierReference(_) | JSXElementName::NamespacedName(_) => return,
};
if ident.name == "this" {
// We can't produce a proper identifier with a `ReferenceId` because `JSXIdentifier`
// lacks that field. https://github.com/oxc-project/oxc/issues/3528
// So generate a reference and just use its name.
// If JSX transform is enabled, that transform runs before this and will have converted
// this to a proper `ThisExpression`, and this visitor won't run.
// So only a problem if JSX transform is disabled.
let new_ident = self.get_this_name(ctx).create_read_reference(ctx);
ident.name = new_ident.name;
}

We can fix after we have the ThisExpression variants.

Linter

Once this is done, we can remove these lines from linter.

let name = ident.name.as_str();
// TODO: Remove this check once we have `JSXMemberExpressionObject::ThisExpression`
if name == "this" {
return;
}

Metadata

Metadata

Assignees

Labels

A-astArea - AST

Type

No type

Priority

None yet

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions