-
-
Notifications
You must be signed in to change notification settings - Fork 4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: implement
:global {...}
CSS blocks (#11276)
* feat: implement `:global {...}` CSS blocks * tests for compiler errors * regenerate types * lint
- Loading branch information
1 parent
11c7cd5
commit 9721d56
Showing
21 changed files
with
208 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'svelte': patch | ||
--- | ||
|
||
feat: implement `:global {...}` CSS blocks |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 9 additions & 0 deletions
9
packages/svelte/tests/compiler-errors/samples/css-global-block-combinator/_config.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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] | ||
} | ||
}); |
2 changes: 1 addition & 1 deletion
2
...s/css-global-without-selector/main.svelte → ...s/css-global-block-combinator/main.svelte
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
<style> | ||
:global {} | ||
.x > :global {} | ||
</style> |
9 changes: 9 additions & 0 deletions
9
packages/svelte/tests/compiler-errors/samples/css-global-block-declaration/_config.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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] | ||
} | ||
}); |
5 changes: 5 additions & 0 deletions
5
packages/svelte/tests/compiler-errors/samples/css-global-block-declaration/main.svelte
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<style> | ||
.x :global { | ||
color: red; | ||
} | ||
</style> |
9 changes: 9 additions & 0 deletions
9
packages/svelte/tests/compiler-errors/samples/css-global-block-modifier/_config.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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] | ||
} | ||
}); |
3 changes: 3 additions & 0 deletions
3
packages/svelte/tests/compiler-errors/samples/css-global-block-modifier/main.svelte
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
<style> | ||
.x .y:global {} | ||
</style> |
9 changes: 9 additions & 0 deletions
9
packages/svelte/tests/compiler-errors/samples/css-global-block-multiple/_config.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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] | ||
} | ||
}); |
3 changes: 3 additions & 0 deletions
3
packages/svelte/tests/compiler-errors/samples/css-global-block-multiple/main.svelte
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
<style> | ||
.x :global, .y :global {} | ||
</style> |
9 changes: 0 additions & 9 deletions
9
packages/svelte/tests/compiler-errors/samples/css-global-without-selector/_config.js
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
} | ||
} | ||
] | ||
}); |
17 changes: 17 additions & 0 deletions
17
packages/svelte/tests/css/samples/global-block/expected.css
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
/* :global {*/ | ||
.x { | ||
color: green; | ||
} | ||
/*}*/ | ||
|
||
div.svelte-xyz { | ||
.y { | ||
color: green; | ||
} | ||
} | ||
|
||
/* (unused) .unused :global { | ||
.z { | ||
color: red; | ||
} | ||
}*/ |
21 changes: 21 additions & 0 deletions
21
packages/svelte/tests/css/samples/global-block/input.svelte
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<div>{@html whatever}</div> | ||
|
||
<style> | ||
:global { | ||
.x { | ||
color: green; | ||
} | ||
} | ||
div :global { | ||
.y { | ||
color: green; | ||
} | ||
} | ||
.unused :global { | ||
.z { | ||
color: red; | ||
} | ||
} | ||
</style> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters