Skip to content

Commit

Permalink
feat(transformer): add proposal-decorators (#2868)
Browse files Browse the repository at this point in the history
  • Loading branch information
Boshen committed Mar 30, 2024
1 parent ffadcb0 commit 7034bcc
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 4 deletions.
19 changes: 19 additions & 0 deletions crates/oxc_transformer/src/decorators/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
use serde::Deserialize;

/// 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)
#[derive(Debug, Default)]
pub struct Decorators {
#[allow(unused)]
options: DecoratorsOptions,
}

impl Decorators {
pub fn new(options: DecoratorsOptions) -> Self {
Self { options }
}
}
6 changes: 6 additions & 0 deletions crates/oxc_transformer/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
//! * <https://github.com/microsoft/TypeScript/blob/main/src/compiler/transformer.ts>

// Plugins: <https://babeljs.io/docs/plugins-list>
mod decorators;
mod react_display_name;
mod react_jsx;
mod react_jsx_self;
Expand All @@ -19,6 +20,7 @@ use oxc_semantic::Semantic;
use oxc_span::SourceType;

pub use crate::{
decorators::{Decorators, DecoratorsOptions},
react_display_name::{ReactDisplayName, ReactDisplayNameOptions},
react_jsx::{ReactJsx, ReactJsxOptions},
react_jsx_self::{ReactJsxSelf, ReactJsxSelfOptions},
Expand All @@ -29,6 +31,7 @@ pub use crate::{
#[allow(unused)]
#[derive(Debug, Default, Clone)]
pub struct TransformOptions {
pub decorators: DecoratorsOptions,
pub typescript: TypeScriptOptions,
pub react_jsx: ReactJsxOptions,
pub react_display_name: ReactDisplayNameOptions,
Expand All @@ -43,6 +46,8 @@ pub struct Transformer<'a> {
semantic: Semantic<'a>,
options: TransformOptions,

// Stage 3
decorators: Decorators,
// [preset-typescript](https://babeljs.io/docs/babel-preset-typescript)
typescript: TypeScript,
// [preset-react](https://babeljs.io/docs/babel-preset-react)
Expand All @@ -64,6 +69,7 @@ impl<'a> Transformer<'a> {
source_type,
semantic,
options,
decorators: Decorators::default(),
typescript: TypeScript::default(),
react_display_name: ReactDisplayName::default(),
react_jsx: ReactJsx::default(),
Expand Down
13 changes: 9 additions & 4 deletions tasks/transform_conformance/src/test_case.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ use std::{
path::{Path, PathBuf},
};

use serde::de::DeserializeOwned;
use serde_json::Value;

use oxc_allocator::Allocator;
use oxc_codegen::{Codegen, CodegenOptions};
use oxc_diagnostics::Error;
Expand All @@ -11,11 +14,9 @@ use oxc_semantic::SemanticBuilder;
use oxc_span::{SourceType, VALID_EXTENSIONS};
use oxc_tasks_common::{normalize_path, print_diff_in_terminal, BabelOptions};
use oxc_transformer::{
ReactDisplayNameOptions, ReactJsxOptions, ReactJsxSelfOptions, ReactJsxSourceOptions,
TransformOptions, Transformer, TypeScriptOptions,
DecoratorsOptions, ReactDisplayNameOptions, ReactJsxOptions, ReactJsxSelfOptions,
ReactJsxSourceOptions, TransformOptions, Transformer, TypeScriptOptions,
};
use serde::de::DeserializeOwned;
use serde_json::Value;

use crate::{fixture_root, root, TestRunnerEnv};

Expand Down Expand Up @@ -86,6 +87,10 @@ pub trait TestCase {
}
let options = self.options();
TransformOptions {
decorators: options
.get_plugin("proposal-decorators")
.map(get_options::<DecoratorsOptions>)
.unwrap_or_default(),
typescript: options
.get_plugin("transform-typescript")
.map(get_options::<TypeScriptOptions>)
Expand Down

0 comments on commit 7034bcc

Please sign in to comment.