Skip to content
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

feat(ast)!: remove JSXMemberExpressionObject::Identifier variant #5358

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
1 change: 0 additions & 1 deletion crates/oxc_ast/src/ast/jsx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,6 @@ pub struct JSXMemberExpression<'a> {
#[cfg_attr(feature = "serialize", derive(Serialize, Tsify))]
#[serde(untagged)]
pub enum JSXMemberExpressionObject<'a> {
Identifier(Box<'a, JSXIdentifier<'a>>) = 0,
IdentifierReference(Box<'a, IdentifierReference<'a>>) = 1,
MemberExpression(Box<'a, JSXMemberExpression<'a>>) = 2,
}
Expand Down
1 change: 0 additions & 1 deletion crates/oxc_ast/src/ast_impl/jsx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ impl<'a> fmt::Display for JSXMemberExpression<'a> {
impl<'a> fmt::Display for JSXMemberExpressionObject<'a> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Self::Identifier(id) => id.fmt(f),
Self::IdentifierReference(id) => id.fmt(f),
Self::MemberExpression(expr) => expr.fmt(f),
}
Expand Down
31 changes: 0 additions & 31 deletions crates/oxc_ast/src/generated/ast_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12971,37 +12971,6 @@ impl<'a> AstBuilder<'a> {
Box::new_in(self.jsx_member_expression(span, object, property), self.allocator)
}

/// Build a [`JSXMemberExpressionObject::Identifier`]
///
/// This node contains a [`JSXIdentifier`] that will be stored in the memory arena.
///
/// ## Parameters
/// - span: The [`Span`] covering this node
/// - name: The name of the identifier.
#[inline]
pub fn jsx_member_expression_object_jsx_identifier<A>(
self,
span: Span,
name: A,
) -> JSXMemberExpressionObject<'a>
where
A: IntoIn<'a, Atom<'a>>,
{
JSXMemberExpressionObject::Identifier(self.alloc(self.jsx_identifier(span, name)))
}

/// Convert a [`JSXIdentifier`] into a [`JSXMemberExpressionObject::Identifier`]
#[inline]
pub fn jsx_member_expression_object_from_jsx_identifier<T>(
self,
inner: T,
) -> JSXMemberExpressionObject<'a>
where
T: IntoIn<'a, Box<'a, JSXIdentifier<'a>>>,
{
JSXMemberExpressionObject::Identifier(inner.into_in(self.allocator))
}

/// Build a [`JSXMemberExpressionObject::IdentifierReference`]
///
/// This node contains a [`IdentifierReference`] that will be stored in the memory arena.
Expand Down
1 change: 0 additions & 1 deletion crates/oxc_ast/src/generated/derive_clone_in.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3517,7 +3517,6 @@ impl<'old_alloc, 'new_alloc> CloneIn<'new_alloc> for JSXMemberExpressionObject<'
type Cloned = JSXMemberExpressionObject<'new_alloc>;
fn clone_in(&self, allocator: &'new_alloc Allocator) -> Self::Cloned {
match self {
Self::Identifier(it) => JSXMemberExpressionObject::Identifier(it.clone_in(allocator)),
Self::IdentifierReference(it) => {
JSXMemberExpressionObject::IdentifierReference(it.clone_in(allocator))
}
Expand Down
1 change: 0 additions & 1 deletion crates/oxc_ast/src/generated/derive_get_span.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2054,7 +2054,6 @@ impl<'a> GetSpan for JSXMemberExpression<'a> {
impl<'a> GetSpan for JSXMemberExpressionObject<'a> {
fn span(&self) -> Span {
match self {
Self::Identifier(it) => it.span(),
Self::IdentifierReference(it) => it.span(),
Self::MemberExpression(it) => it.span(),
}
Expand Down
1 change: 0 additions & 1 deletion crates/oxc_ast/src/generated/derive_get_span_mut.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2054,7 +2054,6 @@ impl<'a> GetSpanMut for JSXMemberExpression<'a> {
impl<'a> GetSpanMut for JSXMemberExpressionObject<'a> {
fn span_mut(&mut self) -> &mut Span {
match self {
Self::Identifier(it) => it.span_mut(),
Self::IdentifierReference(it) => it.span_mut(),
Self::MemberExpression(it) => it.span_mut(),
}
Expand Down
1 change: 0 additions & 1 deletion crates/oxc_ast/src/generated/visit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3341,7 +3341,6 @@ pub mod walk {
let kind = AstKind::JSXMemberExpressionObject(visitor.alloc(it));
visitor.enter_node(kind);
match it {
JSXMemberExpressionObject::Identifier(it) => visitor.visit_jsx_identifier(it),
JSXMemberExpressionObject::IdentifierReference(it) => {
visitor.visit_identifier_reference(it)
}
Expand Down
1 change: 0 additions & 1 deletion crates/oxc_ast/src/generated/visit_mut.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3508,7 +3508,6 @@ pub mod walk_mut {
let kind = AstType::JSXMemberExpressionObject;
visitor.enter_node(kind);
match it {
JSXMemberExpressionObject::Identifier(it) => visitor.visit_jsx_identifier(it),
JSXMemberExpressionObject::IdentifierReference(it) => {
visitor.visit_identifier_reference(it)
}
Expand Down
1 change: 0 additions & 1 deletion crates/oxc_codegen/src/gen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2243,7 +2243,6 @@ impl<'a> Gen for JSXIdentifier<'a> {
impl<'a> Gen for JSXMemberExpressionObject<'a> {
fn gen(&self, p: &mut Codegen, ctx: Context) {
match self {
Self::Identifier(ident) => ident.gen(p, ctx),
Self::IdentifierReference(ident) => ident.gen(p, ctx),
Self::MemberExpression(member_expr) => member_expr.gen(p, ctx),
}
Expand Down
1 change: 0 additions & 1 deletion crates/oxc_linter/src/rules/react/jsx_no_undef.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ fn get_resolvable_ident<'a>(node: &'a JSXElementName<'a>) -> Option<&'a Identifi
fn get_member_ident<'a>(mut expr: &'a JSXMemberExpression<'a>) -> Option<&'a IdentifierReference> {
loop {
match &expr.object {
JSXMemberExpressionObject::Identifier(_) => return None,
JSXMemberExpressionObject::IdentifierReference(ident) => return Some(ident),
JSXMemberExpressionObject::MemberExpression(next_expr) => {
expr = next_expr;
Expand Down
4 changes: 0 additions & 4 deletions crates/oxc_parser/src/jsx/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -441,10 +441,6 @@ impl<'a> ParserImpl<'a> {
return false;
}
match (&lhs.object, &rhs.object) {
(
JSXMemberExpressionObject::Identifier(lhs),
JSXMemberExpressionObject::Identifier(rhs),
) => lhs.name == rhs.name,
(
JSXMemberExpressionObject::IdentifierReference(lhs),
JSXMemberExpressionObject::IdentifierReference(rhs),
Expand Down
5 changes: 1 addition & 4 deletions crates/oxc_transformer/src/react/jsx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -782,17 +782,14 @@ impl<'a> ReactJsx<'a> {
ctx: &mut TraverseCtx<'a>,
) -> Expression<'a> {
let object = match &expr.object {
JSXMemberExpressionObject::Identifier(ident) => {
JSXMemberExpressionObject::IdentifierReference(ident) => {
if ident.name == "this" {
self.ast().expression_this(ident.span)
} else {
let ident = get_read_identifier_reference(ident.span, ident.name.clone(), ctx);
self.ast().expression_from_identifier_reference(ident)
}
}
JSXMemberExpressionObject::IdentifierReference(ident) => {
self.ast().expression_from_identifier_reference(ident.as_ref().clone())
}
JSXMemberExpressionObject::MemberExpression(expr) => {
self.transform_jsx_member_expression(expr, ctx)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -485,7 +485,6 @@ impl<'a> GatherNodeParts<'a> for JSXMemberExpression<'a> {
impl<'a> GatherNodeParts<'a> for JSXMemberExpressionObject<'a> {
fn gather<F: FnMut(&str)>(&self, f: &mut F) {
match self {
JSXMemberExpressionObject::Identifier(ident) => ident.gather(f),
JSXMemberExpressionObject::IdentifierReference(ident) => ident.gather(f),
JSXMemberExpressionObject::MemberExpression(expr) => expr.gather(f),
}
Expand Down
3 changes: 0 additions & 3 deletions crates/oxc_traverse/src/generated/walk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3329,9 +3329,6 @@ pub(crate) unsafe fn walk_jsx_member_expression_object<'a, Tr: Traverse<'a>>(
) {
traverser.enter_jsx_member_expression_object(&mut *node, ctx);
match &mut *node {
JSXMemberExpressionObject::Identifier(node) => {
walk_jsx_identifier(traverser, (&mut **node) as *mut _, ctx)
}
JSXMemberExpressionObject::IdentifierReference(node) => {
walk_identifier_reference(traverser, (&mut **node) as *mut _, ctx)
}
Expand Down
31 changes: 21 additions & 10 deletions tasks/coverage/semantic_typescript.snap
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ commit: a709f989

semantic_typescript Summary:
AST Parsed : 6479/6479 (100.00%)
Positive Passed: 3460/6479 (53.40%)
Positive Passed: 3459/6479 (53.39%)
tasks/coverage/typescript/tests/cases/compiler/2dArrays.ts
semantic error: Symbol reference IDs mismatch:
after transform: SymbolId(0): [ReferenceId(1)]
Expand Down Expand Up @@ -35323,10 +35323,10 @@ Reference symbol mismatch:
after transform: ReferenceId(9): Some("Component")
rebuilt : ReferenceId(48): None
Reference symbol mismatch:
after transform: ReferenceId(10): Some("Namespace")
after transform: ReferenceId(76): Some("Namespace")
rebuilt : ReferenceId(51): None
Reference symbol mismatch:
after transform: ReferenceId(11): Some("Namespace")
after transform: ReferenceId(79): Some("Namespace")
rebuilt : ReferenceId(54): None
Reference symbol mismatch:
after transform: ReferenceId(12): Some("Component")
Expand Down Expand Up @@ -35469,20 +35469,28 @@ Symbol reference IDs mismatch:
after transform: SymbolId(3): [ReferenceId(0), ReferenceId(1)]
rebuilt : SymbolId(2): [ReferenceId(2)]

tasks/coverage/typescript/tests/cases/conformance/jsx/tsxDynamicTagName5.tsx
semantic error: Unresolved references mismatch:
after transform: ["this"]
rebuilt : []

tasks/coverage/typescript/tests/cases/conformance/jsx/tsxDynamicTagName6.tsx
semantic error: Bindings mismatch:
after transform: ScopeId(0): ["JSX", "_jsxFileName", "_reactJsxRuntime", "foo", "t"]
rebuilt : ScopeId(0): ["_jsxFileName", "_reactJsxRuntime", "foo", "t"]
Symbol reference IDs mismatch:
after transform: SymbolId(3): [ReferenceId(0), ReferenceId(1)]
rebuilt : SymbolId(2): [ReferenceId(2)]

tasks/coverage/typescript/tests/cases/conformance/jsx/tsxDynamicTagName8.tsx
semantic error: Unresolved reference IDs mismatch for "this":
after transform: [ReferenceId(1), ReferenceId(2)]
rebuilt : [ReferenceId(2)]
semantic error: Unresolved references mismatch:
after transform: ["this"]
rebuilt : []

tasks/coverage/typescript/tests/cases/conformance/jsx/tsxDynamicTagName9.tsx
semantic error: Unresolved reference IDs mismatch for "this":
after transform: [ReferenceId(1), ReferenceId(2)]
rebuilt : [ReferenceId(2)]
semantic error: Unresolved references mismatch:
after transform: ["this"]
rebuilt : []

tasks/coverage/typescript/tests/cases/conformance/jsx/tsxElementResolution.tsx
semantic error: Missing SymbolId: Dotted
Expand All @@ -35507,7 +35515,7 @@ Symbol reference IDs mismatch:
after transform: SymbolId(5): []
rebuilt : SymbolId(6): [ReferenceId(2)]
Reference symbol mismatch:
after transform: ReferenceId(1): Some("Dotted")
after transform: ReferenceId(8): Some("Dotted")
rebuilt : ReferenceId(13): Some("Dotted")

tasks/coverage/typescript/tests/cases/conformance/jsx/tsxElementResolution13.tsx
Expand Down Expand Up @@ -35908,6 +35916,9 @@ tasks/coverage/typescript/tests/cases/conformance/jsx/tsxOpeningClosingNames.tsx
semantic error: Bindings mismatch:
after transform: ScopeId(0): ["A", "JSX", "_jsxFileName", "_reactJsxRuntime"]
rebuilt : ScopeId(0): ["_jsxFileName", "_reactJsxRuntime"]
Reference symbol mismatch:
after transform: ReferenceId(2): Some("A")
rebuilt : ReferenceId(2): None
Unresolved reference IDs mismatch for "A":
after transform: [ReferenceId(0), ReferenceId(1)]
rebuilt : [ReferenceId(2)]
Expand Down
51 changes: 41 additions & 10 deletions tasks/transform_conformance/babel.snap.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
commit: 3bcfee23

Passed: 318/1021
Passed: 314/1021

# All Passed:
* babel-plugin-transform-optional-catch-binding
Expand Down Expand Up @@ -4852,8 +4852,11 @@ TS(18010)



# babel-plugin-transform-react-jsx (119/144)
# babel-plugin-transform-react-jsx (115/144)
* react/arrow-functions/input.js
x Unresolved references mismatch:
| after transform: ["React", "this"]
| rebuilt : ["React"]


* react/dont-coerce-expression-containers/input.js
Expand All @@ -4880,6 +4883,18 @@ TS(18010)
| rebuilt : [ReferenceId(1)]


* react/should-allow-deeper-js-namespacing/input.js
x Unresolved reference IDs mismatch for "Namespace":
| after transform: [ReferenceId(0), ReferenceId(1)]
| rebuilt : [ReferenceId(1)]


* react/should-allow-js-namespacing/input.js
x Unresolved reference IDs mismatch for "Namespace":
| after transform: [ReferenceId(0), ReferenceId(1)]
| rebuilt : [ReferenceId(1)]


* react/should-avoid-wrapping-in-extra-parens-if-not-needed/input.js
x Unresolved reference IDs mismatch for "Composite":
| after transform: [ReferenceId(2), ReferenceId(3), ReferenceId(5),
Expand Down Expand Up @@ -4924,9 +4939,9 @@ TS(18010)


* react/this-tag-name/input.js
x Unresolved reference IDs mismatch for "this":
| after transform: [ReferenceId(0), ReferenceId(1)]
| rebuilt : [ReferenceId(1)]
x Unresolved references mismatch:
| after transform: ["React", "this"]
| rebuilt : ["React"]


* react/weird-symbols/input.js
Expand All @@ -4936,6 +4951,9 @@ TS(18010)


* react-automatic/arrow-functions/input.js
x Unresolved references mismatch:
| after transform: ["this"]
| rebuilt : []


* react-automatic/does-not-add-source-self-automatic/input.mjs
Expand All @@ -4949,10 +4967,23 @@ transform-react-jsx: unknown field `autoImport`, expected one of `runtime`, `dev

* react-automatic/handle-fragments-with-key/input.js
x Symbol reference IDs mismatch:
| after transform: SymbolId(0): [ReferenceId(0), ReferenceId(1)]
| after transform: SymbolId(0): [ReferenceId(0), ReferenceId(1),
| ReferenceId(2)]
| rebuilt : SymbolId(0): [ReferenceId(1)]


* react-automatic/should-allow-deeper-js-namespacing/input.js
x Unresolved reference IDs mismatch for "Namespace":
| after transform: [ReferenceId(0), ReferenceId(1)]
| rebuilt : [ReferenceId(1)]


* react-automatic/should-allow-js-namespacing/input.js
x Unresolved reference IDs mismatch for "Namespace":
| after transform: [ReferenceId(0), ReferenceId(1)]
| rebuilt : [ReferenceId(1)]


* react-automatic/should-avoid-wrapping-in-extra-parens-if-not-needed/input.js
x Unresolved reference IDs mismatch for "Composite":
| after transform: [ReferenceId(2), ReferenceId(3), ReferenceId(5),
Expand Down Expand Up @@ -4997,9 +5028,9 @@ transform-react-jsx: unknown field `autoImport`, expected one of `runtime`, `dev


* react-automatic/this-tag-name/input.js
x Unresolved reference IDs mismatch for "this":
| after transform: [ReferenceId(0), ReferenceId(1)]
| rebuilt : [ReferenceId(1)]
x Unresolved references mismatch:
| after transform: ["this"]
| rebuilt : []


* react-automatic/weird-symbols/input.js
Expand Down Expand Up @@ -5034,7 +5065,7 @@ transform-react-jsx: unknown field `autoImport`, expected one of `runtime`, `dev

* cross-platform/handle-fragments-with-key/input.js
x Unresolved reference IDs mismatch for "React":
| after transform: [ReferenceId(0), ReferenceId(1)]
| after transform: [ReferenceId(0), ReferenceId(1), ReferenceId(2)]
| rebuilt : [ReferenceId(2)]


Expand Down
Loading