From 82e00bc9518f9341693e4d80d8ac4352ee3306a4 Mon Sep 17 00:00:00 2001 From: Boshen Date: Mon, 15 Apr 2024 13:51:09 +0800 Subject: [PATCH] refactor(transformer): remove boilerplate code around decorators to reduce noise (#2991) --- crates/oxc_transformer/src/decorators/mod.rs | 31 -------------------- crates/oxc_transformer/src/lib.rs | 14 ++------- crates/oxc_transformer/src/options.rs | 6 +--- tasks/transform_conformance/src/test_case.rs | 9 +----- 4 files changed, 4 insertions(+), 56 deletions(-) delete mode 100644 crates/oxc_transformer/src/decorators/mod.rs diff --git a/crates/oxc_transformer/src/decorators/mod.rs b/crates/oxc_transformer/src/decorators/mod.rs deleted file mode 100644 index 4b6748938ec4d..0000000000000 --- a/crates/oxc_transformer/src/decorators/mod.rs +++ /dev/null @@ -1,31 +0,0 @@ -use std::rc::Rc; - -use serde::Deserialize; - -use oxc_ast::ast::*; - -use crate::context::Ctx; - -/// Only `"2023-11"` will be implemented because Babel 8 will only support "2023-11" and "legacy". -#[derive(Debug, Default, Clone, Deserialize)] -#[serde(rename_all = "camelCase")] -pub struct DecoratorsOptions; - -/// [proposal-decorators](https://babeljs.io/docs/babel-plugin-proposal-decorators) -#[allow(unused)] -pub struct Decorators<'a> { - options: DecoratorsOptions, - ctx: Ctx<'a>, -} - -impl<'a> Decorators<'a> { - pub fn new(options: DecoratorsOptions, ctx: &Ctx<'a>) -> Self { - Self { options, ctx: Rc::clone(ctx) } - } -} - -// Transformers -impl<'a> Decorators<'a> { - #[allow(clippy::unused_self)] - pub fn transform_statement(&self, _stmt: &mut Statement<'_>) {} -} diff --git a/crates/oxc_transformer/src/lib.rs b/crates/oxc_transformer/src/lib.rs index 5bd3b7478cf28..12a7de14a310e 100644 --- a/crates/oxc_transformer/src/lib.rs +++ b/crates/oxc_transformer/src/lib.rs @@ -12,7 +12,6 @@ mod compiler_assumptions; mod context; mod options; // Presets: -mod decorators; mod react; mod typescript; @@ -27,13 +26,12 @@ use oxc_diagnostics::Error; use oxc_semantic::Semantic; pub use crate::{ - compiler_assumptions::CompilerAssumptions, decorators::DecoratorsOptions, - options::TransformOptions, react::ReactOptions, typescript::TypeScriptOptions, + compiler_assumptions::CompilerAssumptions, options::TransformOptions, react::ReactOptions, + typescript::TypeScriptOptions, }; use crate::{ context::{Ctx, TransformCtx}, - decorators::Decorators, react::React, typescript::TypeScript, }; @@ -43,7 +41,6 @@ pub struct Transformer<'a> { // NOTE: all callbacks must run in order. x0_typescript: TypeScript<'a>, x1_react: React<'a>, - x2_decorators: Decorators<'a>, } impl<'a> Transformer<'a> { @@ -58,7 +55,6 @@ impl<'a> Transformer<'a> { ctx: Rc::clone(&ctx), x0_typescript: TypeScript::new(options.typescript, &ctx), x1_react: React::new(options.react, &ctx), - x2_decorators: Decorators::new(options.decorators, &ctx), } } @@ -191,12 +187,6 @@ impl<'a> VisitMut<'a> for Transformer<'a> { self.x0_typescript.transform_statements_on_exit(stmts); } - fn visit_statement(&mut self, stmt: &mut Statement<'a>) { - self.x2_decorators.transform_statement(stmt); - - walk_mut::walk_statement_mut(self, stmt); - } - fn visit_tagged_template_expression(&mut self, expr: &mut TaggedTemplateExpression<'a>) { self.x0_typescript.transform_tagged_template_expression(expr); diff --git a/crates/oxc_transformer/src/options.rs b/crates/oxc_transformer/src/options.rs index baba01f969a44..276ecccf26eb5 100644 --- a/crates/oxc_transformer/src/options.rs +++ b/crates/oxc_transformer/src/options.rs @@ -1,6 +1,5 @@ use crate::{ - compiler_assumptions::CompilerAssumptions, decorators::DecoratorsOptions, react::ReactOptions, - typescript::TypeScriptOptions, + compiler_assumptions::CompilerAssumptions, react::ReactOptions, typescript::TypeScriptOptions, }; #[derive(Debug, Default, Clone)] @@ -11,9 +10,6 @@ pub struct TransformOptions { pub assumptions: CompilerAssumptions, // Plugins - /// [proposal-decorators](https://babeljs.io/docs/babel-plugin-proposal-decorators) - pub decorators: DecoratorsOptions, - /// [preset-typescript](https://babeljs.io/docs/babel-preset-typescript) pub typescript: TypeScriptOptions, diff --git a/tasks/transform_conformance/src/test_case.rs b/tasks/transform_conformance/src/test_case.rs index b7bb1573f0cfc..685ebfe2dca37 100644 --- a/tasks/transform_conformance/src/test_case.rs +++ b/tasks/transform_conformance/src/test_case.rs @@ -13,9 +13,7 @@ use oxc_parser::Parser; use oxc_semantic::SemanticBuilder; use oxc_span::{SourceType, VALID_EXTENSIONS}; use oxc_tasks_common::{normalize_path, print_diff_in_terminal, BabelOptions}; -use oxc_transformer::{ - DecoratorsOptions, ReactOptions, TransformOptions, Transformer, TypeScriptOptions, -}; +use oxc_transformer::{ReactOptions, TransformOptions, Transformer, TypeScriptOptions}; use crate::{fixture_root, root, TestRunnerEnv, PLUGINS_NOT_SUPPORTED_YET}; @@ -98,11 +96,6 @@ fn transform_options(options: &BabelOptions) -> serde_json::Result) - .transpose()? - .unwrap_or_default(), typescript: options .get_plugin("transform-typescript") .map(get_options::)