Skip to content

Commit

Permalink
refactor(transformer): remove boilerplate code around decorators to r…
Browse files Browse the repository at this point in the history
…educe noise (#2991)
  • Loading branch information
Boshen authored Apr 15, 2024
1 parent b4bfa2f commit 82e00bc
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 56 deletions.
31 changes: 0 additions & 31 deletions crates/oxc_transformer/src/decorators/mod.rs

This file was deleted.

14 changes: 2 additions & 12 deletions crates/oxc_transformer/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ mod compiler_assumptions;
mod context;
mod options;
// Presets: <https://babel.dev/docs/presets>
mod decorators;
mod react;
mod typescript;

Expand All @@ -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,
};
Expand All @@ -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> {
Expand All @@ -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),
}
}

Expand Down Expand Up @@ -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);

Expand Down
6 changes: 1 addition & 5 deletions crates/oxc_transformer/src/options.rs
Original file line number Diff line number Diff line change
@@ -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)]
Expand All @@ -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,

Expand Down
9 changes: 1 addition & 8 deletions tasks/transform_conformance/src/test_case.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};

Expand Down Expand Up @@ -98,11 +96,6 @@ fn transform_options(options: &BabelOptions) -> serde_json::Result<TransformOpti

Ok(TransformOptions {
assumptions: serde_json::from_value(options.assumptions.clone()).unwrap_or_default(),
decorators: options
.get_plugin("proposal-decorators")
.map(get_options::<DecoratorsOptions>)
.transpose()?
.unwrap_or_default(),
typescript: options
.get_plugin("transform-typescript")
.map(get_options::<TypeScriptOptions>)
Expand Down

0 comments on commit 82e00bc

Please sign in to comment.