mirror of
https://github.com/lexmount/moli.git
synced 2026-11-21 00:03:15 +00:00
fix(typed-om): reify single scoped identifiers without splitting lists
This commit is contained in:
Generated
+11
-11
@@ -5690,7 +5690,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "selectors"
|
||||
version = "0.41.0"
|
||||
source = "git+https://github.com/lexmount/stylo?rev=d2fa17d143cc01ef6e04da1079f2e0f3eed8b834#d2fa17d143cc01ef6e04da1079f2e0f3eed8b834"
|
||||
source = "git+https://github.com/lexmount/stylo?rev=5837d15463a0cfd34fbe1ac5a8cdf42f3bd4301e#5837d15463a0cfd34fbe1ac5a8cdf42f3bd4301e"
|
||||
dependencies = [
|
||||
"bitflags",
|
||||
"cssparser",
|
||||
@@ -5820,7 +5820,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "servo_arc"
|
||||
version = "0.5.0"
|
||||
source = "git+https://github.com/lexmount/stylo?rev=d2fa17d143cc01ef6e04da1079f2e0f3eed8b834#d2fa17d143cc01ef6e04da1079f2e0f3eed8b834"
|
||||
source = "git+https://github.com/lexmount/stylo?rev=5837d15463a0cfd34fbe1ac5a8cdf42f3bd4301e#5837d15463a0cfd34fbe1ac5a8cdf42f3bd4301e"
|
||||
dependencies = [
|
||||
"serde",
|
||||
"stable_deref_trait",
|
||||
@@ -6191,7 +6191,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "stylo"
|
||||
version = "0.22.0"
|
||||
source = "git+https://github.com/lexmount/stylo?rev=d2fa17d143cc01ef6e04da1079f2e0f3eed8b834#d2fa17d143cc01ef6e04da1079f2e0f3eed8b834"
|
||||
source = "git+https://github.com/lexmount/stylo?rev=5837d15463a0cfd34fbe1ac5a8cdf42f3bd4301e#5837d15463a0cfd34fbe1ac5a8cdf42f3bd4301e"
|
||||
dependencies = [
|
||||
"app_units",
|
||||
"arrayvec",
|
||||
@@ -6247,7 +6247,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "stylo_atoms"
|
||||
version = "0.22.0"
|
||||
source = "git+https://github.com/lexmount/stylo?rev=d2fa17d143cc01ef6e04da1079f2e0f3eed8b834#d2fa17d143cc01ef6e04da1079f2e0f3eed8b834"
|
||||
source = "git+https://github.com/lexmount/stylo?rev=5837d15463a0cfd34fbe1ac5a8cdf42f3bd4301e#5837d15463a0cfd34fbe1ac5a8cdf42f3bd4301e"
|
||||
dependencies = [
|
||||
"string_cache 0.11.0",
|
||||
"string_cache_codegen 0.11.2",
|
||||
@@ -6256,7 +6256,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "stylo_derive"
|
||||
version = "0.22.0"
|
||||
source = "git+https://github.com/lexmount/stylo?rev=d2fa17d143cc01ef6e04da1079f2e0f3eed8b834#d2fa17d143cc01ef6e04da1079f2e0f3eed8b834"
|
||||
source = "git+https://github.com/lexmount/stylo?rev=5837d15463a0cfd34fbe1ac5a8cdf42f3bd4301e#5837d15463a0cfd34fbe1ac5a8cdf42f3bd4301e"
|
||||
dependencies = [
|
||||
"darling",
|
||||
"proc-macro2",
|
||||
@@ -6268,7 +6268,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "stylo_dom"
|
||||
version = "0.22.0"
|
||||
source = "git+https://github.com/lexmount/stylo?rev=d2fa17d143cc01ef6e04da1079f2e0f3eed8b834#d2fa17d143cc01ef6e04da1079f2e0f3eed8b834"
|
||||
source = "git+https://github.com/lexmount/stylo?rev=5837d15463a0cfd34fbe1ac5a8cdf42f3bd4301e#5837d15463a0cfd34fbe1ac5a8cdf42f3bd4301e"
|
||||
dependencies = [
|
||||
"bitflags",
|
||||
"stylo_malloc_size_of",
|
||||
@@ -6277,7 +6277,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "stylo_malloc_size_of"
|
||||
version = "0.22.0"
|
||||
source = "git+https://github.com/lexmount/stylo?rev=d2fa17d143cc01ef6e04da1079f2e0f3eed8b834#d2fa17d143cc01ef6e04da1079f2e0f3eed8b834"
|
||||
source = "git+https://github.com/lexmount/stylo?rev=5837d15463a0cfd34fbe1ac5a8cdf42f3bd4301e#5837d15463a0cfd34fbe1ac5a8cdf42f3bd4301e"
|
||||
dependencies = [
|
||||
"app_units",
|
||||
"cssparser",
|
||||
@@ -6295,7 +6295,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "stylo_static_prefs"
|
||||
version = "0.22.0"
|
||||
source = "git+https://github.com/lexmount/stylo?rev=d2fa17d143cc01ef6e04da1079f2e0f3eed8b834#d2fa17d143cc01ef6e04da1079f2e0f3eed8b834"
|
||||
source = "git+https://github.com/lexmount/stylo?rev=5837d15463a0cfd34fbe1ac5a8cdf42f3bd4301e#5837d15463a0cfd34fbe1ac5a8cdf42f3bd4301e"
|
||||
dependencies = [
|
||||
"toml",
|
||||
]
|
||||
@@ -6314,7 +6314,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "stylo_traits"
|
||||
version = "0.22.0"
|
||||
source = "git+https://github.com/lexmount/stylo?rev=d2fa17d143cc01ef6e04da1079f2e0f3eed8b834#d2fa17d143cc01ef6e04da1079f2e0f3eed8b834"
|
||||
source = "git+https://github.com/lexmount/stylo?rev=5837d15463a0cfd34fbe1ac5a8cdf42f3bd4301e#5837d15463a0cfd34fbe1ac5a8cdf42f3bd4301e"
|
||||
dependencies = [
|
||||
"app_units",
|
||||
"bitflags",
|
||||
@@ -6624,7 +6624,7 @@ checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20"
|
||||
[[package]]
|
||||
name = "to_shmem"
|
||||
version = "0.6.0"
|
||||
source = "git+https://github.com/lexmount/stylo?rev=d2fa17d143cc01ef6e04da1079f2e0f3eed8b834#d2fa17d143cc01ef6e04da1079f2e0f3eed8b834"
|
||||
source = "git+https://github.com/lexmount/stylo?rev=5837d15463a0cfd34fbe1ac5a8cdf42f3bd4301e#5837d15463a0cfd34fbe1ac5a8cdf42f3bd4301e"
|
||||
dependencies = [
|
||||
"cssparser",
|
||||
"servo_arc",
|
||||
@@ -6637,7 +6637,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "to_shmem_derive"
|
||||
version = "0.2.0"
|
||||
source = "git+https://github.com/lexmount/stylo?rev=d2fa17d143cc01ef6e04da1079f2e0f3eed8b834#d2fa17d143cc01ef6e04da1079f2e0f3eed8b834"
|
||||
source = "git+https://github.com/lexmount/stylo?rev=5837d15463a0cfd34fbe1ac5a8cdf42f3bd4301e#5837d15463a0cfd34fbe1ac5a8cdf42f3bd4301e"
|
||||
dependencies = [
|
||||
"darling",
|
||||
"proc-macro2",
|
||||
|
||||
+7
-7
@@ -143,13 +143,13 @@ curl-sys = { path = "vendor/curl-sys-0.4.91" }
|
||||
cookie = { git = "https://github.com/ldm0/cookie-rs", branch = "priority" }
|
||||
v8 = { path = "vendor/v8-152.2.0" }
|
||||
deno_v8 = { path = "vendor/deno_v8-0.3.0" }
|
||||
selectors = { git = "https://github.com/lexmount/stylo", rev = "d2fa17d143cc01ef6e04da1079f2e0f3eed8b834" }
|
||||
servo_arc = { git = "https://github.com/lexmount/stylo", rev = "d2fa17d143cc01ef6e04da1079f2e0f3eed8b834" }
|
||||
stylo = { git = "https://github.com/lexmount/stylo", rev = "d2fa17d143cc01ef6e04da1079f2e0f3eed8b834" }
|
||||
stylo_atoms = { git = "https://github.com/lexmount/stylo", rev = "d2fa17d143cc01ef6e04da1079f2e0f3eed8b834" }
|
||||
stylo_dom = { git = "https://github.com/lexmount/stylo", rev = "d2fa17d143cc01ef6e04da1079f2e0f3eed8b834" }
|
||||
stylo_static_prefs = { git = "https://github.com/lexmount/stylo", rev = "d2fa17d143cc01ef6e04da1079f2e0f3eed8b834" }
|
||||
stylo_traits = { git = "https://github.com/lexmount/stylo", rev = "d2fa17d143cc01ef6e04da1079f2e0f3eed8b834" }
|
||||
selectors = { git = "https://github.com/lexmount/stylo", rev = "5837d15463a0cfd34fbe1ac5a8cdf42f3bd4301e" }
|
||||
servo_arc = { git = "https://github.com/lexmount/stylo", rev = "5837d15463a0cfd34fbe1ac5a8cdf42f3bd4301e" }
|
||||
stylo = { git = "https://github.com/lexmount/stylo", rev = "5837d15463a0cfd34fbe1ac5a8cdf42f3bd4301e" }
|
||||
stylo_atoms = { git = "https://github.com/lexmount/stylo", rev = "5837d15463a0cfd34fbe1ac5a8cdf42f3bd4301e" }
|
||||
stylo_dom = { git = "https://github.com/lexmount/stylo", rev = "5837d15463a0cfd34fbe1ac5a8cdf42f3bd4301e" }
|
||||
stylo_static_prefs = { git = "https://github.com/lexmount/stylo", rev = "5837d15463a0cfd34fbe1ac5a8cdf42f3bd4301e" }
|
||||
stylo_traits = { git = "https://github.com/lexmount/stylo", rev = "5837d15463a0cfd34fbe1ac5a8cdf42f3bd4301e" }
|
||||
svgtypes = { git = "https://github.com/lexmount/svgtypes", rev = "520374d714d69f8e2dc93c81a9d6be559ecde3ff" }
|
||||
# Preserve original SVG selector inputs and collect unclipped source geometry.
|
||||
usvg = { git = "https://github.com/lexmount/resvg", rev = "a137793a5749c27862b724eef60c4734526b14a0" }
|
||||
|
||||
@@ -1,5 +1,47 @@
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn native_scoped_names_preserve_decoded_identifiers_and_opaque_lists() {
|
||||
use moli_css_parse::parse_typed_style_value;
|
||||
use style::typed_om::TypedValue;
|
||||
|
||||
crate::style_engine::ensure_stylo_browser_compat_prefs();
|
||||
for property in ["anchor-scope", "timeline-scope"] {
|
||||
for (source, expected) in [
|
||||
("none", "none"),
|
||||
("ALL", "all"),
|
||||
("--a", "--a"),
|
||||
("--A", "--A"),
|
||||
("--é", "--é"),
|
||||
("--foo\\2e bar", "--foo.bar"),
|
||||
("--foo\\20 bar", "--foo bar"),
|
||||
("--foo\\5c bar", "--foo\\bar"),
|
||||
] {
|
||||
let parsed = parse_typed_style_value(property, source, None).unwrap();
|
||||
assert!(matches!(
|
||||
parsed.values.unwrap().native().unwrap().values.as_slice(),
|
||||
[TypedValue::Keyword(value)] if value.0 == expected
|
||||
));
|
||||
}
|
||||
for source in ["--a, --b", "--a, --a", "--A, --a", "--foo\\2e bar, --é"] {
|
||||
let parsed = parse_typed_style_value(property, source, None).unwrap();
|
||||
assert!(parsed.values.is_none(), "{property}: {source}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn css_style_property_maps_reify_scoped_names_without_splitting_lists() {
|
||||
let mut vm = new_parsed_test_vm(
|
||||
"https://css-scoped-names.test/",
|
||||
"<!doctype html><html><head></head><body></body></html>",
|
||||
);
|
||||
let result = vm.eval(include_str!("css_typed_scoped_names.js")).unwrap();
|
||||
let result: serde_json::Value = serde_json::from_str(&result).unwrap();
|
||||
assert_eq!(result["failures"], serde_json::json!([]), "{result}");
|
||||
assert_eq!(result["cases"].as_array().map(Vec::len), Some(600));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn native_font_alternates_reify_keywords_without_exposing_function_arguments() {
|
||||
use moli_css_parse::parse_typed_style_value;
|
||||
|
||||
+140
@@ -0,0 +1,140 @@
|
||||
JSON.stringify((() => {
|
||||
const failures = [];
|
||||
const cases = [];
|
||||
let checks = 0;
|
||||
const check = (condition, label) => {
|
||||
checks++;
|
||||
if (!condition) failures.push(label);
|
||||
};
|
||||
const attempt = (label, callback) => {
|
||||
try { callback(); } catch (error) { failures.push(label + ': ' + error); }
|
||||
};
|
||||
const keyword = (values, expected, label) => check(values.length === 1 &&
|
||||
values[0] instanceof CSSKeywordValue && values[0].value === expected &&
|
||||
String(values[0]) === CSS.escape(expected), label + ': keyword ' + values.map(String));
|
||||
const opaque = (values, label) => check(values.length === 1 &&
|
||||
Object.prototype.toString.call(values[0]) === '[object CSSStyleValue]', label + ': opaque ' + values.map(String));
|
||||
const throws = (callback, label) => {
|
||||
let error;
|
||||
try { callback(); } catch (caught) { error = caught; }
|
||||
check(error instanceof TypeError, label + ': ' + error);
|
||||
};
|
||||
const connected = document.createElement('div'); document.body.append(connected);
|
||||
const detached = document.createElement('div');
|
||||
const svg = document.createElementNS('http://www.w3.org/2000/svg', 'svg'); document.body.append(svg);
|
||||
const owner = document.createElement('style'); owner.textContent = '.scoped-names {}'; document.head.append(owner);
|
||||
const sheet = new CSSStyleSheet(); sheet.replaceSync('.scoped-names {}');
|
||||
const owners = [
|
||||
['connected', connected.style, connected.attributeStyleMap],
|
||||
['detached', detached.style, detached.attributeStyleMap],
|
||||
['svg', svg.style, svg.attributeStyleMap],
|
||||
['style-rule', owner.sheet.cssRules[0].style, owner.sheet.cssRules[0].styleMap],
|
||||
['constructed-rule', sheet.cssRules[0].style, sheet.cssRules[0].styleMap]
|
||||
];
|
||||
for (const property of ['anchor-scope', 'timeline-scope']) {
|
||||
for (const [source, expected] of [
|
||||
['none', 'none'], ['NONE', 'none'], ['n\\6f ne', 'none'],
|
||||
['all', 'all'], ['ALL', 'all'], ['\\61ll', 'all'],
|
||||
['--a', '--a'], ['--A', '--A'], ['--é', '--é'],
|
||||
['--foo\\2e bar', '--foo.bar'], ['--foo\\20 bar', '--foo bar'],
|
||||
['--foo\\5c bar', '--foo\\bar']
|
||||
]) {
|
||||
const prefix = property + ': ' + source;
|
||||
attempt(prefix + ': parsing', () => {
|
||||
keyword([CSSStyleValue.parse(property, source)], expected, prefix + ': parse');
|
||||
keyword(CSSStyleValue.parseAll(property, source), expected, prefix + ': parseAll');
|
||||
});
|
||||
for (const [kind, style, map] of owners) {
|
||||
for (const write of ['string', 'keyword', 'parsed', 'cssom', 'cssText']) {
|
||||
const label = [property, source, kind, write].join(': ');
|
||||
attempt(label, () => {
|
||||
style.cssText = 'color: red';
|
||||
if (write === 'string') map.set(property, source);
|
||||
if (write === 'keyword') map.set(property, new CSSKeywordValue(expected));
|
||||
if (write === 'parsed') map.set(property, CSSStyleValue.parse(property, source));
|
||||
if (write === 'cssom') style.setProperty(property, source);
|
||||
if (write === 'cssText') style.cssText = property + ': ' + source;
|
||||
keyword(map.getAll(property), expected, label + ': getAll');
|
||||
keyword([map.get(property)], expected, label + ': get');
|
||||
keyword(Array.from(map).find(([name]) => name === property)[1], expected, label + ': iteration');
|
||||
style.setProperty('opacity', '0.5');
|
||||
keyword(map.getAll(property), expected, label + ': unrelated write');
|
||||
check(style.getPropertyValue(property) === CSS.escape(expected), label + ': CSSOM escapes exactly once');
|
||||
if (kind === 'style-rule' || kind === 'constructed-rule') {
|
||||
const rule = kind === 'style-rule' ? owner.sheet.cssRules[0] : sheet.cssRules[0];
|
||||
keyword(rule.styleMap.getAll(property), expected, label + ': reacquired rule');
|
||||
}
|
||||
cases.push(label);
|
||||
});
|
||||
}
|
||||
}
|
||||
attempt(prefix + ': computed', () => {
|
||||
connected.style.cssText = property + ': ' + source;
|
||||
keyword(connected.computedStyleMap().getAll(property), expected, prefix + ': computed');
|
||||
});
|
||||
}
|
||||
for (const source of ['--a, --b', '--a, --a', '--A, --a', '--foo\\2e bar, --é']) {
|
||||
const prefix = property + ': ' + source;
|
||||
attempt(prefix + ': parsing', () => opaque(CSSStyleValue.parseAll(property, source), prefix));
|
||||
for (const [kind, style, map] of owners) attempt(prefix + ': ' + kind, () => {
|
||||
const parsed = CSSStyleValue.parse(property, source);
|
||||
style.cssText = 'color: red'; map.set(property, parsed);
|
||||
opaque(map.getAll(property), prefix + ': ' + kind);
|
||||
const text = style.getPropertyValue(property);
|
||||
check(text.includes(','), prefix + ': comma retained');
|
||||
style.setProperty('opacity', '0.25');
|
||||
opaque(map.getAll(property), prefix + ': after mutation');
|
||||
check(String(map.get(property)) === text, prefix + ': entire list retained');
|
||||
map.set(property, new CSSKeywordValue(source));
|
||||
keyword(map.getAll(property), source, prefix + ': punctuation in one identifier is escaped');
|
||||
map.set(property, parsed);
|
||||
check(style.getPropertyValue(property) === text, prefix + ': opaque list restored after escaped identifier');
|
||||
check(style.getPropertyValue('color') === 'red' && style.getPropertyValue('opacity') === '0.25', prefix + ': unrelated properties retained');
|
||||
const before = style.cssText;
|
||||
throws(() => map.set(property, new CSSKeywordValue('--a'), new CSSKeywordValue('--b')), prefix + ': list cannot be typed arguments');
|
||||
throws(() => map.append(property, new CSSKeywordValue('--c')), prefix + ': list cannot be appended');
|
||||
check(style.cssText === before, prefix + ': atomic rejection');
|
||||
const other = property === 'anchor-scope' ? 'timeline-scope' : 'anchor-scope';
|
||||
throws(() => map.set(other, parsed), prefix + ': opaque association');
|
||||
map.set(property, new CSSKeywordValue('--A'));
|
||||
keyword(map.getAll(property), '--A', prefix + ': restore keyword');
|
||||
});
|
||||
attempt(prefix + ': computed', () => {
|
||||
connected.style.cssText = property + ': ' + source;
|
||||
opaque(connected.computedStyleMap().getAll(property), prefix + ': computed opaque list');
|
||||
});
|
||||
}
|
||||
for (const [kind, style, map] of owners) attempt(property + ': ' + kind + ': validation', () => {
|
||||
map.set(property, '--A');
|
||||
const saved = map.get(property);
|
||||
for (const invalid of ['foo', 'all, --a', 'none, --a', '--a --b', '--a,', 'var()']) {
|
||||
const before = style.cssText;
|
||||
throws(() => map.set(property, invalid), property + ': invalid ' + invalid);
|
||||
check(style.cssText === before, property + ': invalid write is atomic');
|
||||
}
|
||||
map.set(property, new CSSUnparsedValue(['var(--scope)']));
|
||||
check(map.get(property) instanceof CSSUnparsedValue, property + ': variable stays unparsed');
|
||||
map.set(property, new CSSKeywordValue('inherit'));
|
||||
keyword(map.getAll(property), 'inherit', property + ': CSS-wide keyword');
|
||||
map.set(property, saved);
|
||||
keyword(map.getAll(property), '--A', property + ': immutable saved value');
|
||||
});
|
||||
attempt(property + ': cascade and variables', () => {
|
||||
const child = document.createElement('span'); connected.append(child);
|
||||
connected.style.cssText = property + ': --parent';
|
||||
keyword(child.computedStyleMap().getAll(property), 'none', property + ': non-inherited default');
|
||||
child.style.cssText = property + ': inherit';
|
||||
keyword(child.computedStyleMap().getAll(property), '--parent', property + ': explicit inheritance');
|
||||
child.style.cssText = '--scope: --A; ' + property + ': var(--scope)';
|
||||
check(child.attributeStyleMap.get(property) instanceof CSSUnparsedValue, property + ': declared variable');
|
||||
keyword(child.computedStyleMap().getAll(property), '--A', property + ': computed variable');
|
||||
child.style.setProperty('--scope', '--a, --b');
|
||||
opaque(child.computedStyleMap().getAll(property), property + ': computed list variable');
|
||||
child.style.setProperty('--scope', '--a');
|
||||
keyword(child.computedStyleMap().getAll(property), '--a', property + ': variable invalidation');
|
||||
child.remove();
|
||||
});
|
||||
}
|
||||
owner.remove(); connected.remove(); svg.remove();
|
||||
return {checks, cases, failures};
|
||||
})())
|
||||
Reference in New Issue
Block a user