omena-scss-eval 0.3.0

Oracle-first SCSS and Less value evaluator rail for Omena CSS
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
use std::collections::{BTreeMap, BTreeSet};

use omena_abstract_value::AbstractCssValueV0;
use omena_parser::StyleDialect;
use serde::Serialize;

#[derive(Debug, Clone, PartialEq, Eq, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct OmenaScssEvalStaticStylesheetEvaluationV0 {
    pub schema_version: &'static str,
    pub product: &'static str,
    pub evaluator: &'static str,
    pub dialect: &'static str,
    pub product_output_source: &'static str,
    pub legacy_output_retained_as_oracle: bool,
    pub legacy_output_consumed_until_cutover: bool,
    pub evaluated_css: String,
    pub native_edit_output: String,
    pub replacement_count: usize,
    pub native_replacement_legacy_reflection_count: usize,
    pub native_replacement_legacy_unreflected_count: usize,
    pub native_edit_count: usize,
    pub native_value_edit_count: usize,
    pub native_structural_edit_count: usize,
    pub preserved_dynamic_branch_count: usize,
    pub preserved_dynamic_loop_count: usize,
    pub preserved_raw_call_count: usize,
    pub preserved_raw_include_count: usize,
    pub preserved_dynamic_interpolation_count: usize,
    pub scss_control_flow_value_truthiness_count: usize,
    pub scss_control_flow_contextual_truthiness_fallback_count: usize,
    pub scss_control_flow_contextual_truthiness_conflict_count: usize,
    pub native_edit_output_matches_evaluated_css: bool,
    pub resolved_replacements: Vec<OmenaScssEvalResolvedReplacementV0>,
    pub native_edits: Vec<OmenaScssEvalStaticStylesheetNativeEditV0>,
    pub value_resolution: OmenaScssEvalStaticValueResolutionReportV0,
    pub oracle: crate::OmenaScssEvalOracleReportV0,
}

#[derive(Debug, Clone, PartialEq, Eq, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct OmenaScssEvalResolvedReplacementV0 {
    pub name: String,
    pub start: usize,
    pub end: usize,
    pub text: String,
    pub rendered_value: Option<String>,
    pub abstract_value: AbstractCssValueV0,
    pub abstract_value_kind: &'static str,
}

#[derive(Debug, Clone, PartialEq, Eq, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct OmenaScssEvalStaticStylesheetNativeEditV0 {
    pub start: usize,
    pub end: usize,
    pub replacement: String,
    pub edit_kind: &'static str,
    pub abstract_value: Option<AbstractCssValueV0>,
    pub abstract_value_kind: Option<&'static str>,
}

#[derive(Debug, Clone, PartialEq, Eq, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct OmenaScssEvalStaticValueResolutionReportV0 {
    pub schema_version: &'static str,
    pub product: &'static str,
    pub mode: &'static str,
    pub dialect: &'static str,
    pub fuel_limit: usize,
    pub reference_count: usize,
    pub resolved_count: usize,
    pub raw_count: usize,
    pub top_count: usize,
    pub cycle_count: usize,
    pub fuel_exhausted_count: usize,
    pub unresolved_reference_count: usize,
    pub unsupported_dynamic_count: usize,
    pub values: Vec<OmenaScssEvalStaticValueResolutionV0>,
}

#[derive(Debug, Clone, PartialEq, Eq, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct OmenaScssEvalStaticValueResolutionV0 {
    pub name: String,
    pub start: usize,
    pub end: usize,
    pub source_text: String,
    pub rendered_value: Option<String>,
    pub abstract_value: AbstractCssValueV0,
    pub abstract_value_kind: &'static str,
    pub outcome: &'static str,
    pub reason: &'static str,
}

#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub(super) enum StaticStylesheetVariableKind {
    Scss,
    Less,
}

impl StaticStylesheetVariableKind {
    pub(super) fn for_dialect(dialect: StyleDialect) -> Option<Self> {
        match dialect {
            StyleDialect::Scss | StyleDialect::Sass => Some(Self::Scss),
            StyleDialect::Less => Some(Self::Less),
            StyleDialect::Css => None,
        }
    }

    pub(super) fn evaluator_label(self) -> &'static str {
        match self {
            Self::Scss => "omena-query-static-scss-variable-evaluator",
            Self::Less => "omena-query-static-less-variable-evaluator",
        }
    }

    pub(super) fn reference_prefix(self) -> char {
        match self {
            Self::Scss => '$',
            Self::Less => '@',
        }
    }
}

#[derive(Debug, Clone)]
pub(super) struct StaticStylesheetVariableDeclaration {
    pub(super) value: String,
    pub(super) span_start: usize,
    pub(super) span_end: usize,
    pub(super) removal_spans: Vec<(usize, usize)>,
    pub(super) is_default: bool,
    pub(super) is_global: bool,
}

#[derive(Debug, Clone)]
pub(super) struct StaticStylesheetScopedVariableDeclaration {
    pub(super) name: String,
    pub(super) scope_id: usize,
    pub(super) declaration: StaticStylesheetVariableDeclaration,
    pub(super) removal_spans: Vec<(usize, usize)>,
}

#[derive(Debug, Clone)]
pub(super) struct StaticStylesheetEvaluationEdit {
    pub(super) start: usize,
    pub(super) end: usize,
    pub(super) replacement: String,
}

#[derive(Debug, Clone, Copy, Default, PartialEq, Eq)]
pub(super) struct StaticStylesheetPreservedEvaluationCounts {
    pub(super) dynamic_branch_count: usize,
    pub(super) dynamic_loop_count: usize,
    pub(super) raw_call_count: usize,
    pub(super) raw_include_count: usize,
    pub(super) dynamic_interpolation_count: usize,
}

impl StaticStylesheetPreservedEvaluationCounts {
    pub(super) fn total(self) -> usize {
        self.dynamic_branch_count
            + self.dynamic_loop_count
            + self.raw_call_count
            + self.raw_include_count
            + self.dynamic_interpolation_count
    }
}

#[derive(Debug, Clone, Copy, Default, PartialEq, Eq)]
pub(super) struct StaticScssControlFlowPruneEvidenceCounts {
    pub(super) value_truthiness_count: usize,
    pub(super) contextual_truthiness_fallback_count: usize,
    pub(super) contextual_truthiness_conflict_count: usize,
}

impl StaticScssControlFlowPruneEvidenceCounts {
    pub(super) fn add_assign(&mut self, other: Self) {
        self.value_truthiness_count += other.value_truthiness_count;
        self.contextual_truthiness_fallback_count += other.contextual_truthiness_fallback_count;
        self.contextual_truthiness_conflict_count += other.contextual_truthiness_conflict_count;
    }
}

pub(super) struct StaticScssMixinEvaluationEdits {
    pub(super) edits: Vec<StaticStylesheetEvaluationEdit>,
    pub(super) preserved_raw_include_count: usize,
    pub(super) prune_evidence_counts: StaticScssControlFlowPruneEvidenceCounts,
}

pub(super) struct StaticScssFunctionEvaluationEdits {
    pub(super) edits: Vec<StaticStylesheetEvaluationEdit>,
    pub(super) replacements: Vec<OmenaScssEvalResolvedReplacementV0>,
    pub(super) preserved_raw_call_count: usize,
}

pub(super) struct StaticLessMixinEvaluationEdits {
    pub(super) edits: Vec<StaticStylesheetEvaluationEdit>,
    pub(super) preserved_non_rendering_call_count: usize,
    // Canonical mixin names statically CONSUMED by this pass (rendered/known-no-output).
    pub(super) used_mixin_names: BTreeSet<String>,
    // Canonical mixin names a non-resolving (preserved) reference in this pass still needs;
    // the orchestrator must NOT delete declarations for these (avoids dropping live CSS for a
    // sibling overload the preserved call still references).
    pub(super) preserved_mixin_names: BTreeSet<String>,
}

pub(super) struct StaticLessDetachedRulesetEvaluationEdits {
    pub(super) edits: Vec<StaticStylesheetEvaluationEdit>,
    pub(super) preserved_raw_call_count: usize,
    pub(super) used_mixin_names: BTreeSet<String>,
    pub(super) preserved_mixin_names: BTreeSet<String>,
}

pub(super) struct StaticLessDetachedRulesetAccessorEvaluationEdits {
    pub(super) edits: Vec<StaticStylesheetEvaluationEdit>,
    pub(super) preserved_raw_accessor_count: usize,
    pub(super) preserved_declaration_keys: BTreeSet<(usize, String)>,
}

pub(super) struct StaticLessMixinAccessorEvaluationEdits {
    pub(super) edits: Vec<StaticStylesheetEvaluationEdit>,
    pub(super) preserved_raw_accessor_count: usize,
    pub(super) used_mixin_names: BTreeSet<String>,
    pub(super) preserved_mixin_names: BTreeSet<String>,
}

pub(super) enum StaticLessBodyPropertyValueOutcome {
    Resolved(String),
    MemberNotFound,
}

#[derive(Debug, Clone, PartialEq, Eq)]
pub(super) struct StaticLessResolvedValue {
    pub(super) text: String,
    pub(super) escaped: bool,
}

#[derive(Debug, Clone)]
pub(super) struct StaticStylesheetPropertyDeclaration {
    pub(super) value: String,
}

#[derive(Debug, Clone)]
pub(super) struct StaticScssFunctionDeclaration {
    pub(super) name: String,
    pub(super) parameters: Vec<StaticScssFunctionParameter>,
    pub(super) local_variables: Vec<StaticScssFunctionLocalVariable>,
    pub(super) return_clauses: Vec<StaticScssFunctionReturnClause>,
    pub(super) span_start: usize,
    pub(super) span_end: usize,
    pub(super) body_start: usize,
    pub(super) body_end: usize,
}

#[derive(Debug, Clone)]
pub(super) struct StaticScssMixinDeclaration {
    pub(super) name: String,
    pub(super) parameters: Vec<StaticScssFunctionParameter>,
    pub(super) span_start: usize,
    pub(super) span_end: usize,
    pub(super) body_start: usize,
    pub(super) body_end: usize,
}

#[derive(Debug, Clone, PartialEq, Eq)]
pub(super) struct StaticScssFunctionLocalVariable {
    pub(super) name: String,
    pub(super) value: String,
    pub(super) span_start: usize,
    pub(super) scope_start: usize,
    pub(super) scope_end: usize,
}

#[derive(Debug, Clone, PartialEq, Eq)]
pub(super) struct StaticScssFunctionReturnClause {
    pub(super) condition: Option<String>,
    pub(super) value: String,
    pub(super) span_start: usize,
    pub(super) loop_headers: Vec<StaticScssLoopHeader>,
}

#[derive(Debug, Clone, PartialEq, Eq)]
pub(super) struct StaticScssLoopHeader {
    pub(super) text: String,
    pub(super) span_start: usize,
    pub(super) body_start: usize,
    pub(super) body_end: usize,
}

#[derive(Debug, Clone, PartialEq, Eq)]
pub(super) struct StaticScssFunctionParameter {
    pub(super) name: String,
    pub(super) default_value: Option<String>,
    pub(super) variadic: bool,
    pub(super) pattern_value: Option<String>,
}

#[derive(Debug, Clone)]
pub(super) struct StaticScssFunctionCall {
    pub(super) name: String,
    pub(super) start: usize,
    pub(super) end: usize,
    pub(super) arguments: Vec<StaticScssFunctionArgument>,
}

#[derive(Debug, Clone)]
pub(super) struct StaticScssMixinIncludeCall {
    pub(super) name: String,
    pub(super) start: usize,
    pub(super) end: usize,
    pub(super) arguments: Vec<StaticScssFunctionArgument>,
    pub(super) content_body: Option<String>,
    pub(super) content_parameters: Vec<String>,
    pub(super) content_parameter_range: Option<(usize, usize)>,
    pub(super) content_body_range: Option<(usize, usize)>,
}

#[derive(Debug, Clone)]
pub(super) struct StaticScssMixinRenderResult {
    pub(super) body: String,
    pub(super) used_mixin_declaration_names: BTreeSet<String>,
    pub(super) used_function_declaration_names: BTreeSet<String>,
    pub(super) prune_evidence_counts: StaticScssControlFlowPruneEvidenceCounts,
}

#[derive(Debug, Clone)]
pub(super) struct StaticScssMixinBodyLocalDeclaration {
    pub(super) name: String,
    pub(super) declaration: StaticStylesheetVariableDeclaration,
}

#[derive(Debug, Clone)]
pub(super) struct StaticLessMixinDeclaration {
    pub(super) name: String,
    pub(super) parameters: Vec<StaticScssFunctionParameter>,
    pub(super) guard: Option<String>,
    pub(super) span_start: usize,
    pub(super) span_end: usize,
    pub(super) body_start: usize,
    pub(super) body_end: usize,
}

#[derive(Debug, Clone)]
pub(super) struct StaticLessMixinCall {
    pub(super) namespace: Option<String>,
    pub(super) namespace_arguments: Vec<StaticScssFunctionArgument>,
    pub(super) name: String,
    pub(super) start: usize,
    pub(super) end: usize,
    pub(super) important: bool,
    pub(super) arguments: Vec<StaticScssFunctionArgument>,
}

#[derive(Debug, Clone)]
pub(super) struct StaticLessMixinAccessor {
    pub(super) name: String,
    pub(super) member: String,
    pub(super) start: usize,
    pub(super) end: usize,
    pub(super) arguments: Vec<StaticScssFunctionArgument>,
}

#[derive(Debug, Clone)]
pub(super) struct StaticLessDetachedRulesetDeclaration {
    pub(super) name: String,
    pub(super) scope_id: usize,
    pub(super) span_start: usize,
    pub(super) span_end: usize,
    pub(super) body_start: usize,
    pub(super) body_end: usize,
}

#[derive(Debug, Clone)]
pub(super) struct StaticLessDetachedRulesetCall {
    pub(super) name: String,
    pub(super) start: usize,
    pub(super) end: usize,
}

pub(super) enum StaticLessDetachedRulesetCallRenderOutcome {
    Rendered(StaticLessMixinRenderResult),
    PreservedRaw,
}

#[derive(Debug, Clone)]
pub(super) struct StaticLessDetachedRulesetAccessor {
    pub(super) name: String,
    pub(super) member: String,
    pub(super) start: usize,
    pub(super) end: usize,
}

pub(super) enum StaticLessDetachedRulesetAccessorRenderOutcome {
    Rendered(String),
    PreservedRaw,
}

#[derive(Debug, Clone)]
pub(super) struct StaticLessMixinBodyLocalDeclaration {
    pub(super) name: String,
    pub(super) declaration: StaticStylesheetVariableDeclaration,
}

#[derive(Debug, Clone)]
pub(super) struct StaticLessMixinRenderResult {
    pub(super) body: String,
    pub(super) used_declaration_names: BTreeSet<String>,
}

pub(super) enum StaticLessMixinCallRenderOutcome {
    Rendered(StaticLessMixinRenderResult),
    KnownNoOutput {
        used_declaration_names: BTreeSet<String>,
    },
    PreservedNoOutput,
}

pub(super) enum StaticLessMixinRenderOutcome {
    Rendered(StaticLessMixinRenderResult),
    GuardNotMatched,
    GuardUnknown,
}

#[derive(Debug, Clone)]
pub(super) struct StaticLessMixinAccessorRenderResult {
    pub(super) value: String,
    pub(super) used_declaration_name: String,
}

pub(super) enum StaticLessMixinAccessorCallRenderOutcome {
    Rendered(StaticLessMixinAccessorRenderResult),
    PreservedRaw,
}

pub(super) enum StaticLessMixinAccessorRenderOutcome {
    Rendered(StaticLessMixinAccessorRenderResult),
    GuardNotMatched,
    GuardUnknown,
    MemberNotFound,
}

#[derive(Debug, Clone, Copy)]
pub(super) struct StaticLessMixinRenderContext<'a> {
    pub(super) source: &'a str,
    pub(super) declarations: &'a [StaticLessMixinDeclaration],
    pub(super) detached_ruleset_declarations: &'a [StaticLessDetachedRulesetDeclaration],
    pub(super) scopes: &'a [StaticStylesheetScope],
    pub(super) variable_declarations:
        &'a BTreeMap<(usize, String), StaticStylesheetVariableDeclaration>,
    pub(super) property_declarations:
        &'a BTreeMap<(usize, String), StaticStylesheetPropertyDeclaration>,
    pub(super) captured_values: &'a BTreeMap<String, String>,
}

pub(super) type StaticScssTruthinessEvaluator = fn(&str) -> Option<bool>;

#[derive(Debug, Clone, Copy)]
pub(super) struct StaticScssFunctionResolutionContext<'a> {
    pub(super) dialect: StyleDialect,
    pub(super) declarations: &'a [StaticScssFunctionDeclaration],
    pub(super) mixin_declarations: &'a [StaticScssMixinDeclaration],
    pub(super) scopes: &'a [StaticStylesheetScope],
    pub(super) variable_declarations: &'a [StaticStylesheetScopedVariableDeclaration],
    pub(super) active_functions: &'a BTreeSet<String>,
    pub(super) truthiness_evaluator: StaticScssTruthinessEvaluator,
}

#[derive(Debug, Clone, PartialEq, Eq)]
pub(super) struct StaticScssFunctionArgument {
    pub(super) name: Option<String>,
    pub(super) value: String,
}

#[derive(Debug, Clone, PartialEq, Eq)]
pub(super) struct StaticScssFunctionLocalScope {
    pub(super) end_index: usize,
    pub(super) span_start: usize,
    pub(super) span_end: usize,
}

#[derive(Debug, Clone, PartialEq, Eq)]
pub(super) struct StaticStylesheetScope {
    pub(super) parent_id: Option<usize>,
    pub(super) body_start: usize,
    pub(super) end: usize,
}