mirror of https://github.com/sveltejs/svelte
feat: implement `:global {...}` CSS blocks (#11276)
* feat: implement `:global {...}` CSS blocks * tests for compiler errors * regenerate types * lintpull/11260/head
parent
11c7cd5495
commit
9721d5641b
@ -0,0 +1,5 @@
|
||||
---
|
||||
'svelte': patch
|
||||
---
|
||||
|
||||
feat: implement `:global {...}` CSS blocks
|
@ -0,0 +1,9 @@
|
||||
import { test } from '../../test';
|
||||
|
||||
export default test({
|
||||
error: {
|
||||
code: 'invalid-css-global-block-combinator',
|
||||
message: 'A :global {...} block cannot follow a > combinator',
|
||||
position: [12, 21]
|
||||
}
|
||||
});
|
@ -1,3 +1,3 @@
|
||||
<style>
|
||||
:global {}
|
||||
.x > :global {}
|
||||
</style>
|
@ -0,0 +1,9 @@
|
||||
import { test } from '../../test';
|
||||
|
||||
export default test({
|
||||
error: {
|
||||
code: 'invalid-css-global-block-declaration',
|
||||
message: 'A :global {...} block can only contain rules, not declarations',
|
||||
position: [24, 34]
|
||||
}
|
||||
});
|
@ -0,0 +1,5 @@
|
||||
<style>
|
||||
.x :global {
|
||||
color: red;
|
||||
}
|
||||
</style>
|
@ -0,0 +1,9 @@
|
||||
import { test } from '../../test';
|
||||
|
||||
export default test({
|
||||
error: {
|
||||
code: 'invalid-css-global-block-modifier',
|
||||
message: 'A :global {...} block cannot modify an existing selector',
|
||||
position: [14, 21]
|
||||
}
|
||||
});
|
@ -0,0 +1,3 @@
|
||||
<style>
|
||||
.x .y:global {}
|
||||
</style>
|
@ -0,0 +1,9 @@
|
||||
import { test } from '../../test';
|
||||
|
||||
export default test({
|
||||
error: {
|
||||
code: 'invalid-css-global-block-list',
|
||||
message: 'A :global {...} block cannot be part of a selector list with more than one item',
|
||||
position: [9, 31]
|
||||
}
|
||||
});
|
@ -0,0 +1,3 @@
|
||||
<style>
|
||||
.x :global, .y :global {}
|
||||
</style>
|
@ -1,9 +0,0 @@
|
||||
import { test } from '../../test';
|
||||
|
||||
export default test({
|
||||
error: {
|
||||
code: 'invalid-css-global-selector',
|
||||
message: ':global(...) must contain exactly one selector',
|
||||
position: [16, 16]
|
||||
}
|
||||
});
|
@ -0,0 +1,21 @@
|
||||
import { test } from '../../test';
|
||||
|
||||
export default test({
|
||||
warnings: [
|
||||
{
|
||||
filename: 'SvelteComponent.svelte',
|
||||
code: 'css-unused-selector',
|
||||
message: 'Unused CSS selector ".unused :global"',
|
||||
start: {
|
||||
line: 16,
|
||||
column: 1,
|
||||
character: 128
|
||||
},
|
||||
end: {
|
||||
line: 16,
|
||||
column: 16,
|
||||
character: 143
|
||||
}
|
||||
}
|
||||
]
|
||||
});
|
@ -0,0 +1,17 @@
|
||||
/* :global {*/
|
||||
.x {
|
||||
color: green;
|
||||
}
|
||||
/*}*/
|
||||
|
||||
div.svelte-xyz {
|
||||
.y {
|
||||
color: green;
|
||||
}
|
||||
}
|
||||
|
||||
/* (unused) .unused :global {
|
||||
.z {
|
||||
color: red;
|
||||
}
|
||||
}*/
|
@ -0,0 +1,21 @@
|
||||
<div>{@html whatever}</div>
|
||||
|
||||
<style>
|
||||
:global {
|
||||
.x {
|
||||
color: green;
|
||||
}
|
||||
}
|
||||
|
||||
div :global {
|
||||
.y {
|
||||
color: green;
|
||||
}
|
||||
}
|
||||
|
||||
.unused :global {
|
||||
.z {
|
||||
color: red;
|
||||
}
|
||||
}
|
||||
</style>
|
Loading…
Reference in new issue