Skip to content
Closed
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
35 changes: 23 additions & 12 deletions crates/oxc_transformer/src/react/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,23 +84,34 @@ impl<'a> React<'a> {
ctx: &TraverseCtx<'a>,
) {
if self.options.is_jsx_self_plugin_enabled() {
let is_constructor = ctx
let can_use_this = ctx
.find_scope(|scope| {
if scope.is_block() || scope.is_arrow() {
return FinderRet::Continue;
}
FinderRet::Found(scope.is_constructor())
if scope.is_top() || scope.is_ts_module_block() {
return FinderRet::Found(false);
}
if scope.is_function()
|| scope.is_set_or_get_accessor()
|| scope.is_class_static_block()
{
return FinderRet::Found(true);
}

// Class constructor
let has_no_super_class = ctx
.find_ancestor(|ancestor| match ancestor {
Ancestor::ClassBody(class) => {
FinderRet::Found(class.super_class().is_none())
}
_ => FinderRet::Continue,
})
.unwrap_or_else(|| unreachable!());
FinderRet::Found(has_no_super_class)
})
.unwrap_or(false);
if !is_constructor
// no super class
|| ctx
.find_ancestor(|ancestor| match ancestor {
Ancestor::ClassBody(class) => FinderRet::Found(class.super_class().is_none()),
_ => FinderRet::Continue,
})
.unwrap_or(true)
{
.unwrap_or_else(|| unreachable!());
if can_use_this {
self.jsx.jsx_self.transform_jsx_opening_element(elem);
}
}
Expand Down