Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/metal-beers-learn.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'svelte': patch
---

fix: improve pseudo elements parsing
14 changes: 4 additions & 10 deletions packages/svelte/src/compiler/phases/1-parse/read/style.js
Original file line number Diff line number Diff line change
Expand Up @@ -219,28 +219,22 @@ function read_selector(parser, inside_pseudo_class = false) {
start,
end: parser.index
});
} else if (parser.eat('::')) {
children.push({
type: 'PseudoElementSelector',
name: read_identifier(parser),
start,
end: parser.index
});
} else if (parser.eat(':')) {
const psuedo_element = parser.eat(':');

const name = read_identifier(parser);

/** @type {null | import('#compiler').Css.SelectorList} */
let args = null;

if (parser.eat('(')) {
args = read_selector_list(parser, true);
parser.eat(')', true);
} else if (name === 'global') {
} else if (!psuedo_element && name === 'global') {
error(parser.index, 'invalid-css-global-selector');
}

children.push({
type: 'PseudoClassSelector',
type: psuedo_element ? 'PseudoElementSelector' : 'PseudoClassSelector',
name,
args,
start,
Expand Down
1 change: 1 addition & 0 deletions packages/svelte/src/compiler/types/css.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ export interface AttributeSelector extends BaseNode {
export interface PseudoElementSelector extends BaseNode {
type: 'PseudoElementSelector';
name: string;
args: SelectorList | null;
}

export interface PseudoClassSelector extends BaseNode {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<style>
:root::view-transition-old(*) {
animation: 90ms cubic-bezier(0.4, 0, 1, 1) both fade-out, 300ms cubic-bezier(0.4, 0, 0.2, 1) both slide-to-left;
}
</style>
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
{
"css": {
"type": "Style",
"start": 0,
"end": 165,
"attributes": [],
"children": [
{
"type": "Rule",
"prelude": {
"type": "SelectorList",
"start": 9,
"end": 38,
"children": [
{
"type": "Selector",
"start": 9,
"end": 38,
"children": [
{
"type": "PseudoClassSelector",
"name": "root",
"args": null,
"start": 9,
"end": 14
},
{
"type": "PseudoElementSelector",
"name": "view-transition-old",
"args": {
"type": "SelectorList",
"start": 36,
"end": 37,
"children": [
{
"type": "Selector",
"start": 36,
"end": 37,
"children": [
{
"type": "TypeSelector",
"name": "*",
"start": 36,
"end": 37
}
]
}
]
},
"start": 14,
"end": 38
}
]
}
]
},
"block": {
"type": "Block",
"start": 39,
"end": 156,
"children": [
{
"type": "Declaration",
"start": 42,
"end": 153,
"property": "animation",
"value": "90ms cubic-bezier(0.4, 0, 1, 1) both fade-out, 300ms cubic-bezier(0.4, 0, 0.2, 1) both slide-to-left"
}
]
},
"start": 9,
"end": 156
}
],
"content": {
"start": 7,
"end": 157,
"styles": "\n\t:root::view-transition-old(*) {\n\tanimation: 90ms cubic-bezier(0.4, 0, 1, 1) both fade-out, 300ms cubic-bezier(0.4, 0, 0.2, 1) both slide-to-left;\n}\n"
}
},
"js": [],
"start": null,
"end": null,
"type": "Root",
"fragment": {
"type": "Fragment",
"nodes": [],
"transparent": false
},
"options": null
}