use std::path::PathBuf;
use oxc_data_structures::code_buffer::{DEFAULT_INDENT_WIDTH, IndentChar};
#[derive(Debug, Clone)]
pub struct CodegenOptions {
pub single_quote: bool,
pub minify: bool,
pub comments: CommentOptions,
pub source_map_path: Option<PathBuf>,
pub indent_char: IndentChar,
pub indent_width: usize,
pub initial_indent: u32,
}
impl Default for CodegenOptions {
fn default() -> Self {
Self {
single_quote: false,
minify: false,
comments: CommentOptions::default(),
source_map_path: None,
indent_char: IndentChar::default(),
indent_width: DEFAULT_INDENT_WIDTH,
initial_indent: 0,
}
}
}
impl CodegenOptions {
pub fn minify() -> Self {
Self {
single_quote: false,
minify: true,
comments: CommentOptions::disabled(),
source_map_path: None,
indent_char: IndentChar::default(),
indent_width: DEFAULT_INDENT_WIDTH,
initial_indent: 0,
}
}
#[inline]
pub(crate) fn print_normal_comment(&self) -> bool {
self.comments.normal
}
#[inline]
pub(crate) fn print_legal_comment(&self) -> bool {
self.comments.legal.is_inline()
}
#[inline]
pub(crate) fn print_jsdoc_comment(&self) -> bool {
self.comments.jsdoc
}
#[inline]
pub(crate) fn print_annotation_comment(&self) -> bool {
self.comments.annotation
}
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct CommentOptions {
pub normal: bool,
pub jsdoc: bool,
pub annotation: bool,
pub legal: LegalComment,
}
impl Default for CommentOptions {
fn default() -> Self {
Self { normal: true, jsdoc: true, annotation: true, legal: LegalComment::default() }
}
}
impl CommentOptions {
pub fn disabled() -> Self {
Self { normal: false, jsdoc: false, annotation: false, legal: LegalComment::None }
}
}
#[derive(Debug, Clone, Eq, PartialEq, Default)]
pub enum LegalComment {
None,
#[default]
Inline,
Eof,
Linked(String),
External,
}
impl LegalComment {
pub fn is_none(&self) -> bool {
*self == Self::None
}
pub fn is_inline(&self) -> bool {
*self == Self::Inline
}
pub fn is_eof(&self) -> bool {
*self == Self::Eof
}
}