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

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/silver-bobcats-lie.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'svelte': patch
---

fix: add more css selectors to `print()`
24 changes: 24 additions & 0 deletions packages/svelte/src/compiler/print/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,18 @@ const css_visitors = {
}
},

AttributeSelector(node, context) {
context.write(`[${node.name}`);
if (node.matcher) {
context.write(node.matcher);
context.write(`"${node.value}"`);
if (node.flags) {
context.write(` ${node.flags}`);
}
}
context.write(']');
},

Block(node, context) {
context.write('{');

Expand Down Expand Up @@ -221,10 +233,22 @@ const css_visitors = {
context.write(`${node.property}: ${node.value};`);
},

IdSelector(node, context) {
context.write(`#${node.name}`);
},

NestingSelector(node, context) {
context.write('&');
},

Nth(node, context) {
context.write(node.value);
},

Percentage(node, context) {
context.write(`${node.value}%`);
},

PseudoClassSelector(node, context) {
context.write(`:${node.name}`);

Expand Down
11 changes: 11 additions & 0 deletions packages/svelte/tests/print/samples/style/input.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

@keyframes fade {
from { opacity: 0; }
50% { opacity: 0.5; }
to { opacity: 1; }
}

Expand All @@ -40,4 +41,14 @@
.container .item, nav > ul.menu {
color: red;
}
#id-selector { color: red; }
[data-attribute] { color: red; }
[data-attribute="value"] { color: red; }

.card {
background: white;
&:hover {
background: gray;
}
}
</style>
22 changes: 22 additions & 0 deletions packages/svelte/tests/print/samples/style/output.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@
from {
opacity: 0;
}
50%% {
opacity: 0.5;
}
to {
opacity: 1;
}
Expand Down Expand Up @@ -66,4 +69,23 @@
nav > ul.menu {
color: red;
}
#id-selector {
color: red;
}
[data-attribute] {
color: red;
}
[data-attribute="value"] {
color: red;
}
.card {
background: white;
&:hover {
background: gray;
}
}
</style>
Loading