Skip to content
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
5 changes: 1 addition & 4 deletions crates/oxc_transformer/src/es2022/class_properties/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -279,10 +279,7 @@ impl<'a, 'ctx> Traverse<'a> for ClassProperties<'a, 'ctx> {
self.transform_chain_expression(expr, ctx);
}
// `delete object?.#prop.xyz`
Expression::UnaryExpression(unary)
if unary.operator == UnaryOperator::Delete
&& matches!(unary.argument, Expression::ChainExpression(_)) =>
{
Expression::UnaryExpression(_) => {
self.transform_unary_expression(expr, ctx);
}
// "object.#prop`xyz`"
Expand Down
19 changes: 18 additions & 1 deletion crates/oxc_transformer/src/es2022/class_properties/private.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1357,14 +1357,31 @@ impl<'a, 'ctx> ClassProperties<'a, 'ctx> {
/// * `delete object?.#prop?.xyz;`
/// -> `delete (object === null || object === void 0 ? void 0 : _assertClassBrand(Foo, object, _prop)._)?.xyz;`
//
// `#[inline]` so that compiler sees that `expr` is an `Expression::UnaryExpression`.
// `#[inline]` so that compiler sees that `expr` is an `Expression::UnaryExpression`,
// and make bailing out if is not `delete <chain expression>` (it rarely will be) a fast path without
// cost of a function call.
#[inline]
pub(super) fn transform_unary_expression(
&mut self,
expr: &mut Expression<'a>,
ctx: &mut TraverseCtx<'a>,
) {
let Expression::UnaryExpression(unary_expr) = expr else { unreachable!() };

if unary_expr.operator == UnaryOperator::Delete
&& matches!(unary_expr.argument, Expression::ChainExpression(_))
{
self.transform_unary_expression_impl(expr, ctx);
}
}

fn transform_unary_expression_impl(
&mut self,
expr: &mut Expression<'a>,
ctx: &mut TraverseCtx<'a>,
) {
let Expression::UnaryExpression(unary_expr) = expr else { unreachable!() };

if let Some((result, chain_expr)) =
self.transform_chain_expression_impl(&mut unary_expr.argument, ctx)
{
Expand Down