Bug 1894041 - If syntax is universal, convert substitution to universal. r=firefox-style-system-reviewers,emilio

Differential Revision: https://phabricator.services.mozilla.com/D209545
This commit is contained in:
Zach Hoffman 2024-05-06 14:26:21 +00:00
parent c2d7a1eb87
commit 8356aa55c5
2 changed files with 27 additions and 2 deletions

View file

@ -274,6 +274,11 @@ impl ComputedCustomProperties {
name: &Name,
value: ComputedRegisteredValue,
) {
// Broadening the assert to
// registration.syntax.is_universal() ^ value.as_universal().is_none() would require
// rewriting the cascade to not temporarily store unparsed custom properties with references
// as universal in the custom properties map.
debug_assert!(!registration.syntax.is_universal() || value.as_universal().is_some());
self.map_mut(registration).insert(name, value)
}
@ -1925,13 +1930,13 @@ fn do_substitute_chunk<'a>(
computed_context,
references,
)?;
let substitution = substitution.into_universal();
// Optimize the property: var(--...) case to avoid allocating at all.
if reference.start == start && reference.end == end && registration.syntax.is_universal() {
return Ok(substitution);
return Ok(Substitution::Universal(substitution));
}
let substitution = substitution.into_universal();
substituted.push(
&substitution.css,
substitution.first_token_type,

View file

@ -0,0 +1,20 @@
<!doctype html>
<meta charset=utf8>
<style>
@property --my-registered-property {
syntax: "<color>";
inherits: false;
initial-value: #f0f2f5;
}
.outer {
--unregistered-property: var(--my-registered-property);
}
.inner {
--unregistered-property: #c6cfdb;
}
</style>
<div class="outer">
<div class="inner"></div>
</div>