Source code
Revision control
Copy as Markdown
Other Tools
Test Info: Warnings
- This test has a WPT meta file that expects 9 subtest issues.
- This WPT test may be referenced by the following Test IDs:
- /css/css-mixins/mixins/mixin-locals.html - WPT Dashboard Interop Dashboard
<!DOCTYPE html>
<html>
<head>
<title>CSS Mixins: Private variables</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
</head>
<body>
<style>
@mixin --m1() {
@private { --my-color: green; }
font-size: 200px;
color: var(--my-color);
}
#e1 {
color: red;
@apply --m1;
}
</style>
<div><div id="e1">This text should be green.</div></div>
<script>
test(() => {
let e1 = document.getElementById('e1');
assert_equals(getComputedStyle(e1).color, 'rgb(0, 128, 0)');
assert_equals(getComputedStyle(e1).fontSize, '200px');
}, 'Private variables and ordinary declarations in a mixin body');
</script>
<style>
@mixin --m1b() {
@private { --my-color: blue; }
color: var(--my-color);
}
#e1b {
color: red;
@apply --m1b;
}
</style>
<div><div id="e1b">This text should be blue (not green).</div></div>
<script>
test(() => {
let e1b = document.getElementById('e1b');
assert_equals(getComputedStyle(e1b).color, 'rgb(0, 0, 255)');
}, 'Mixin is not cached if private variables are different');
</script>
<style>
@mixin --m2() {
@private { --my-color: var(--real-color); }
@private { --real-color: green; }
color: var(--my-color);
}
#e2 {
color: red;
@apply --m2;
}
</style>
<div><div id="e2">This text should be green.</div></div>
<script>
test(() => {
let e2 = document.getElementById('e2');
assert_equals(getComputedStyle(e2).color, 'rgb(0, 128, 0)');
}, 'Private variables resolve against each other');
</script>
<style>
@mixin --m3(--real-color) {
@private { --my-color: var(--real-color); }
color: var(--my-color);
}
#e3 {
color: red;
@apply --m3(green);
}
</style>
<div><div id="e3">This text should be green.</div></div>
<script>
test(() => {
let e3 = document.getElementById('e3');
assert_equals(getComputedStyle(e3).color, 'rgb(0, 128, 0)');
}, 'Private variables resolve against parameters');
</script>
<style>
@mixin --m4(--should-fail: var(--parameter-does-not-see-inner)) {
@private { --parameter-does-not-see-inner: red; }
color: var(--should-fail);
}
#e4 {
--parameter-does-not-see-inner: green;
@apply --m4;
}
#e4-private-default {
@private { --parameter-does-not-see-inner: green; }
@apply --m4;
}
#e4-private-explicit {
@private { --parameter-does-not-see-inner: green; }
@apply --m4(var(--parameter-does-not-see-inner));
}
</style>
<div><div id="e4">This text should be green.</div></div>
<div id="e4-private-default"></div>
<div id="e4-private-explicit"></div>
<script>
test(() => {
let e4 = document.getElementById('e4');
assert_equals(getComputedStyle(e4).color, 'rgb(0, 128, 0)');
}, 'Parameters do not resolve against the mixin body private variables');
test(() => {
for (const id of ['e4-private-default', 'e4-private-explicit']) {
assert_equals(getComputedStyle(document.getElementById(id)).color,
'rgb(0, 128, 0)', id);
}
}, 'Arguments and defaults use the applying rule private scope');
</script>
<style>
@mixin --m5() {
@private { --declared-before-use: unused; }
color: var(--declared-after-use);
@private { --declared-after-use: green; }
}
#e5 {
@apply --m5;
}
</style>
<div><div id="e5">This text should be green.</div></div>
<script>
test(() => {
let e5 = document.getElementById('e5');
assert_equals(getComputedStyle(e5).color, 'rgb(0, 128, 0)');
}, 'Private declarations after their references are seen');
</script>
<style>
@mixin --m6() {
@private { --my-color: green; }
@private { --my-color: red !important; }
color: var(--my-color);
}
#e6 {
@apply --m6;
}
</style>
<div><div id="e6">This text should be green.</div></div>
<script>
test(() => {
let e6 = document.getElementById('e6');
assert_equals(getComputedStyle(e6).color, 'rgb(0, 128, 0)');
}, '!important invalidates a mixin local declaration');
</script>
<style>
@mixin --m7() {
@private { --my-color: red !important; }
color: var(--my-color, green);
}
#e7 {
@apply --m7;
}
</style>
<div><div id="e7">This text should be green.</div></div>
<script>
test(() => {
let e7 = document.getElementById('e7');
assert_equals(getComputedStyle(e7).color, 'rgb(0, 128, 0)');
}, 'An invalid !important local does not define the variable');
</script>
</body>
</html>