another one

pull/14474/head
Simon Holthausen 2 years ago
parent 6a4d1bb946
commit a1330c8811

@ -825,9 +825,10 @@ function get_element_parent(node) {
/**
* @param {Compiler.AST.RegularElement | Compiler.AST.SvelteElement | Compiler.AST.RenderTag | Compiler.AST.Component | Compiler.AST.SvelteComponent | Compiler.AST.SvelteSelf} node
* @param {boolean} adjacent_only
* @param {Set<Compiler.AST.SnippetBlock>} seen
* @returns {Map<Compiler.AST.RegularElement | Compiler.AST.SvelteElement | Compiler.AST.SlotElement | Compiler.AST.RenderTag, NodeExistsValue>}
*/
function get_possible_element_siblings(node, adjacent_only) {
function get_possible_element_siblings(node, adjacent_only, seen = new Set()) {
/** @type {Map<Compiler.AST.RegularElement | Compiler.AST.SvelteElement | Compiler.AST.SlotElement | Compiler.AST.RenderTag, NodeExistsValue>} */
const result = new Map();
const path = node.metadata.path;
@ -886,8 +887,11 @@ function get_possible_element_siblings(node, adjacent_only) {
}
if (current.type === 'SnippetBlock') {
if (seen.has(current)) break;
seen.add(current);
for (const site of current.metadata.sites) {
const siblings = get_possible_element_siblings(site, adjacent_only);
const siblings = get_possible_element_siblings(site, adjacent_only, seen);
add_to_map(siblings, result);
if (adjacent_only && current.metadata.sites.size === 1 && has_definite_elements(siblings)) {

@ -0,0 +1,20 @@
import { test } from '../../test';
export default test({
warnings: [
{
code: 'css_unused_selector',
message: 'Unused CSS selector "div + div"',
start: {
line: 19,
column: 1,
character: 185
},
end: {
line: 19,
column: 10,
character: 194
}
}
]
});

@ -1,7 +1,10 @@
div.svelte-xyz div:where(.svelte-xyz) {
div div.svelte-xyz {
color: green;
}
/* (unused) div + div {
color: red; /* this is marked as unused, but only because we've written an infinite loop - worth fixing? *\/
}*/
div.svelte-xyz:has(div:where(.svelte-xyz)) {
color: green;
}

@ -1,10 +1,12 @@
{#snippet a()}
{@render b()}
<div>
{@render b()}
</div>
{/snippet}
{#snippet b()}
{@render a()}
<div>
{@render a()}
</div>
@ -14,6 +16,9 @@
div div {
color: green;
}
div + div {
color: red; /* this is marked as unused, but only because we've written an infinite loop - worth fixing? */
}
div:has(div) {
color: green;
}

Loading…
Cancel
Save