oxc_css_parser/config.rs
1#[cfg(feature = "config_serde")]
2use serde::{Deserialize, Serialize};
3
4/// Supported syntax.
5#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
6#[cfg_attr(feature = "config_serde", derive(Serialize, Deserialize))]
7#[cfg_attr(feature = "config_serde", serde(rename_all = "camelCase"))]
8pub enum Syntax {
9 #[default]
10 Css,
11 Scss,
12 /// Indented Sass Syntax
13 Sass,
14 Less,
15}
16
17/// Configuration for a backtick-delimited template placeholder.
18///
19/// A placeholder has the shape `` `<prefix><decimal index>` `` (e.g. with
20/// `prefix = "PLACEHOLDER-"`: `` `PLACEHOLDER-0` ``). The opening and closing
21/// backticks are fixed; only `prefix` is supplied by the downstream consumer, so
22/// oxc-css-parser stays agnostic to its content and only uses it to recognize and index
23/// the token.
24///
25/// Backtick is not valid CSS/SCSS/Sass syntax (it is only Less's inline-JS
26/// delimiter), so this is intended for SCSS parsing only; see
27/// [`ParserOptions::template_placeholder`].
28#[derive(Clone, Copy, Debug, PartialEq, Eq)]
29pub struct TemplatePlaceholder {
30 /// Text after the opening backtick that marks the start of a placeholder,
31 /// before its decimal index (e.g. `"PLACEHOLDER-"`).
32 pub prefix: &'static str,
33}
34
35/// Parser options for customizing parser behaviors.
36#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
37#[cfg_attr(feature = "config_serde", derive(Serialize, Deserialize))]
38#[cfg_attr(feature = "config_serde", serde(rename_all = "camelCase"))]
39pub struct ParserOptions {
40 /// Enabling this will make parser attempt to parse
41 /// custom property value as normal declaration value instead of tokens.
42 /// It will fallback to parse as tokens if there're syntax errors
43 /// when parsing as values.
44 pub try_parsing_value_in_custom_property: bool,
45
46 /// If enabled, trailing semicolon of each statement will be treated
47 /// as recoverable errors, instead of raising a syntax error.
48 pub tolerate_semicolon_in_sass: bool,
49
50 /// If set, a backtick-delimited token of the shape `` `<prefix><decimal index>` ``
51 /// (see [`TemplatePlaceholder`]) is tokenized as an atomic
52 /// [`Token::Placeholder`](crate::token::Token) carrying the parsed index.
53 /// The token terminates at the closing backtick, so an immediately following
54 /// identifier (e.g. `` `PLACEHOLDER-0`px ``) is lexed as a separate suffix.
55 ///
56 /// This is designed for downstream formatters that substitute template
57 /// interpolations (e.g. CSS-in-JS `${expr}`) with such placeholders
58 /// before parsing, then re-substitute them in the output.
59 ///
60 /// Backtick is not valid CSS/SCSS/Sass syntax, so this MUST be used with
61 /// [`Syntax::Scss`] (the parser builder asserts this); in Less, backtick is
62 /// the inline-JS delimiter and would conflict.
63 ///
64 /// Not serialized: the affix is a `&'static str` supplied programmatically,
65 /// not loadable from a config file.
66 #[cfg_attr(feature = "config_serde", serde(skip))]
67 pub template_placeholder: Option<TemplatePlaceholder>,
68}