Skip to content

Commit fdce504

Browse files
committed
WIP
1 parent 33026a7 commit fdce504

File tree

4 files changed

+5
-46
lines changed

4 files changed

+5
-46
lines changed

packages/svelte/src/compiler/phases/2-analyze/css/css-prune.js

Lines changed: 4 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import { get_attribute_chunks, is_text_attribute } from '../../../utils/ast.js';
88
/**
99
* @typedef {{
1010
* element: Compiler.AST.RegularElement | Compiler.AST.SvelteElement;
11-
* from_render_tag: boolean;
1211
* }} State
1312
*/
1413
/** @typedef {NODE_PROBABLY_EXISTS | NODE_DEFINITELY_EXISTS} NodeExistsValue */
@@ -53,17 +52,10 @@ const nesting_selector = {
5352
/**
5453
*
5554
* @param {Compiler.Css.StyleSheet} stylesheet
56-
* @param {Compiler.AST.RegularElement | Compiler.AST.SvelteElement | Compiler.AST.RenderTag} element
55+
* @param {Compiler.AST.RegularElement | Compiler.AST.SvelteElement} element
5756
*/
5857
export function prune(stylesheet, element) {
59-
if (element.type === 'RenderTag') {
60-
const parent = get_element_parent(element);
61-
if (!parent) return;
62-
63-
walk(stylesheet, { element: parent, from_render_tag: true }, visitors);
64-
} else {
65-
walk(stylesheet, { element, from_render_tag: false }, visitors);
66-
}
58+
walk(stylesheet, { element }, visitors);
6759
}
6860

6961
/** @type {Visitors<Compiler.Css.Node, State>} */
@@ -77,46 +69,16 @@ const visitors = {
7769
},
7870
ComplexSelector(node, context) {
7971
const selectors = get_relative_selectors(node);
80-
const inner = selectors[selectors.length - 1];
81-
82-
if (context.state.from_render_tag) {
83-
// We're searching for a match that crosses a render tag boundary. That means we have to both traverse up
84-
// the element tree (to see if we find an entry point) but also remove selectors from the end (assuming
85-
// they are part of the render tag we don't see). We do all possible combinations of both until we find a match.
86-
/** @type {Compiler.AST.RegularElement | Compiler.AST.SvelteElement | null} */
87-
let element = context.state.element;
8872

89-
while (element) {
90-
const selectors_to_check = selectors.slice();
91-
92-
while (selectors_to_check.length > 0) {
93-
selectors_to_check.pop();
94-
95-
if (
96-
apply_selector(
97-
selectors_to_check,
98-
/** @type {Compiler.Css.Rule} */ (node.metadata.rule),
99-
element,
100-
context.state
101-
)
102-
) {
103-
mark(inner, element);
104-
node.metadata.used = true;
105-
return;
106-
}
107-
}
108-
109-
element = get_element_parent(element);
110-
}
111-
} else if (
73+
if (
11274
apply_selector(
11375
selectors,
11476
/** @type {Compiler.Css.Rule} */ (node.metadata.rule),
11577
context.state.element,
11678
context.state
11779
)
11880
) {
119-
mark(inner, context.state.element);
81+
mark(selectors[selectors.length - 1], context.state.element);
12082
node.metadata.used = true;
12183
}
12284

packages/svelte/src/compiler/phases/2-analyze/index.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -738,8 +738,6 @@ export function analyze_component(root, source, options) {
738738
}
739739

740740
outer: for (const node of analysis.elements) {
741-
if (node.type === 'RenderTag') continue;
742-
743741
if (node.metadata.scoped) {
744742
// Dynamic elements in dom mode always use spread for attributes and therefore shouldn't have a class attribute added to them
745743
// TODO this happens during the analysis phase, which shouldn't know anything about client vs server

packages/svelte/src/compiler/phases/2-analyze/visitors/RenderTag.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ export function RenderTag(node, context) {
1313
validate_opening_tag(node, context.state, '@');
1414

1515
node.metadata.path = [...context.path];
16-
context.state.analysis.elements.push(node);
1716

1817
const callee = unwrap_optional(node.expression).callee;
1918

packages/svelte/src/compiler/phases/types.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ export interface ComponentAnalysis extends Analysis {
3737
instance: Js;
3838
template: Template;
3939
/** Used for CSS pruning and scoping */
40-
elements: Array<AST.RegularElement | AST.SvelteElement | AST.RenderTag>;
40+
elements: Array<AST.RegularElement | AST.SvelteElement>;
4141
runes: boolean;
4242
exports: Array<{ name: string; alias: string | null }>;
4343
/** Whether the component uses `$$props` */

0 commit comments

Comments
 (0)