use syntax::ast::Expression;
use crate::utils::observable_after_mutation;
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub(crate) enum CapturePolicy {
Never,
IfLaterSetup,
}
pub(crate) struct EmittedExpression {
pub setup: String,
pub value: String,
pub capture: CapturePolicy,
}
impl EmittedExpression {
pub(crate) fn new(setup: String, value: String, expression: &Expression) -> Self {
let capture = if setup.is_empty() && observable_after_mutation(expression) {
CapturePolicy::IfLaterSetup
} else {
CapturePolicy::Never
};
Self {
setup,
value,
capture,
}
}
#[allow(dead_code)]
pub(crate) fn inline(value: String) -> Self {
Self {
setup: String::new(),
value,
capture: CapturePolicy::Never,
}
}
#[allow(dead_code)]
pub(crate) fn with_setup(setup: String, value: String) -> Self {
Self {
setup,
value,
capture: CapturePolicy::Never,
}
}
#[allow(dead_code)]
pub(crate) fn write_setup_into(self, output: &mut String) -> String {
output.push_str(&self.setup);
self.value
}
}