Skip to content

Commit

Permalink
refactor(span): reduce #[cfg_attr] boilerplate in type defs (#4702)
Browse files Browse the repository at this point in the history
Similar to #4375 and #4698. #4696 added `#[ast]` attribute to types in `oxc_span`, so these types can use `#[serde]` attrs without the `#[cfg_attr(feature = "serialize", ...)]` guard.
  • Loading branch information
overlookmotel committed Aug 6, 2024
1 parent 125c5fd commit e1429e5
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 8 deletions.
10 changes: 5 additions & 5 deletions crates/oxc_span/src/source_type/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use ::{serde::Serialize, tsify::Tsify};
#[ast]
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
#[cfg_attr(feature = "serialize", derive(Serialize, Tsify))]
#[cfg_attr(feature = "serialize", serde(rename_all = "camelCase"))]
#[serde(rename_all = "camelCase")]
pub struct SourceType {
/// JavaScript or TypeScript, default JavaScript
pub(super) language: Language,
Expand All @@ -26,19 +26,19 @@ pub struct SourceType {
#[ast]
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
#[cfg_attr(feature = "serialize", derive(Serialize, Tsify))]
#[cfg_attr(feature = "serialize", serde(rename_all = "lowercase"))]
#[serde(rename_all = "lowercase")]
pub enum Language {
JavaScript = 0,
TypeScript = 1,
#[cfg_attr(feature = "serialize", serde(rename = "typescriptDefinition"))]
#[serde(rename = "typescriptDefinition")]
TypeScriptDefinition = 2,
}

/// Script or Module
#[ast]
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
#[cfg_attr(feature = "serialize", derive(Serialize, Tsify))]
#[cfg_attr(feature = "serialize", serde(rename_all = "camelCase"))]
#[serde(rename_all = "camelCase")]
pub enum ModuleKind {
Script = 0,
Module = 1,
Expand All @@ -48,7 +48,7 @@ pub enum ModuleKind {
#[ast]
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
#[cfg_attr(feature = "serialize", derive(Serialize, Tsify))]
#[cfg_attr(feature = "serialize", serde(rename_all = "camelCase"))]
#[serde(rename_all = "camelCase")]
pub enum LanguageVariant {
Standard = 0,
Jsx = 1,
Expand Down
4 changes: 1 addition & 3 deletions crates/oxc_span/src/span.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@ use std::{

use miette::{LabeledSpan, SourceOffset, SourceSpan};
#[cfg(feature = "serialize")]
use serde::Serialize;
#[cfg(feature = "serialize")]
use tsify::Tsify;
use ::{serde::Serialize, tsify::Tsify};

/// An Empty span useful for creating AST nodes.
pub const SPAN: Span = Span::new(0, 0);
Expand Down

0 comments on commit e1429e5

Please sign in to comment.