From 1eae327c1aeaed58b725cf6df8fbf94fc1bd7bb0 Mon Sep 17 00:00:00 2001 From: magic-akari Date: Fri, 23 Aug 2024 19:27:50 +0800 Subject: [PATCH] fix: optional plugin --- crates/oxc_transformer/src/es2018/mod.rs | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/crates/oxc_transformer/src/es2018/mod.rs b/crates/oxc_transformer/src/es2018/mod.rs index 97f7983f6de2ac..6f12be237dceae 100644 --- a/crates/oxc_transformer/src/es2018/mod.rs +++ b/crates/oxc_transformer/src/es2018/mod.rs @@ -17,16 +17,15 @@ pub struct ES2018<'a> { options: ES2018Options, // Plugins - object_rest_spread: ObjectRestSpread<'a>, + object_rest_spread: Option>, } impl<'a> ES2018<'a> { pub fn new(options: ES2018Options, ctx: Ctx<'a>) -> Self { Self { - object_rest_spread: ObjectRestSpread::new( - options.object_rest_spread.unwrap_or_default(), - Rc::clone(&ctx), - ), + object_rest_spread: options + .object_rest_spread + .map(|options| ObjectRestSpread::new(options, Rc::clone(&ctx))), ctx, options, } @@ -35,6 +34,8 @@ impl<'a> ES2018<'a> { impl<'a> Traverse<'a> for ES2018<'a> { fn enter_expression(&mut self, expr: &mut Expression<'a>, ctx: &mut TraverseCtx<'a>) { - self.object_rest_spread.enter_expression(expr, ctx); + if let Some(object_rest_spread) = &mut self.object_rest_spread { + object_rest_spread.enter_expression(expr, ctx); + } } }