plotnik_compiler/typegen/typescript/
config.rs

1//! Configuration types for TypeScript emission.
2
3use plotnik_core::Colors;
4
5/// How to represent the void type in TypeScript.
6#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
7pub enum VoidType {
8    /// `undefined` - the absence of a value
9    #[default]
10    Undefined,
11    /// `null` - explicit null value
12    Null,
13}
14
15/// Configuration for TypeScript emission.
16#[derive(Clone, Debug)]
17pub struct Config {
18    /// Whether to export types
19    pub(crate) export: bool,
20    /// Whether to emit the Node type definition
21    pub(crate) emit_node_type: bool,
22    /// Use verbose node representation (with kind, text, etc.)
23    pub(crate) verbose_nodes: bool,
24    /// How to represent the void type
25    pub(crate) void_type: VoidType,
26    /// Color configuration for output
27    pub(crate) colors: Colors,
28}
29
30impl Default for Config {
31    fn default() -> Self {
32        Self {
33            export: true,
34            emit_node_type: true,
35            verbose_nodes: false,
36            void_type: VoidType::default(),
37            colors: Colors::OFF,
38        }
39    }
40}
41
42impl Config {
43    /// Create a new Config with default values.
44    pub fn new() -> Self {
45        Self::default()
46    }
47
48    /// Set whether to export types.
49    pub fn export(mut self, value: bool) -> Self {
50        self.export = value;
51        self
52    }
53
54    /// Set whether to emit the Node type definition.
55    pub fn emit_node_type(mut self, value: bool) -> Self {
56        self.emit_node_type = value;
57        self
58    }
59
60    /// Set whether to use verbose node representation.
61    pub fn verbose_nodes(mut self, value: bool) -> Self {
62        self.verbose_nodes = value;
63        self
64    }
65
66    /// Set the void type representation.
67    pub fn void_type(mut self, value: VoidType) -> Self {
68        self.void_type = value;
69        self
70    }
71
72    /// Set whether to use colored output.
73    pub fn colored(mut self, enabled: bool) -> Self {
74        self.colors = Colors::new(enabled);
75        self
76    }
77}