Skip to content

Commit 2867cc1

Browse files
committed
WIP
1 parent d2ce0a7 commit 2867cc1

File tree

4 files changed

+32
-2
lines changed

4 files changed

+32
-2
lines changed

packages/svelte/src/compiler/phases/1-parse/state/tag.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -315,7 +315,10 @@ function open(parser) {
315315
name
316316
},
317317
parameters: function_expression.params,
318-
body: create_fragment()
318+
body: create_fragment(),
319+
metadata: {
320+
sites: new Set()
321+
}
319322
});
320323
parser.stack.push(block);
321324
parser.fragments.push(block.body);
@@ -609,7 +612,8 @@ function special(parser) {
609612
expression: expression,
610613
metadata: {
611614
dynamic: false,
612-
args_with_call_expression: new Set()
615+
args_with_call_expression: new Set(),
616+
snippets: []
613617
}
614618
});
615619
}

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ export function RenderTag(node, context) {
2020
node.metadata.dynamic =
2121
callee.type !== 'Identifier' || context.state.scope.get(callee.name)?.kind !== 'normal';
2222

23+
// TODO populate node.metadata.snippets with all the locally-defined snippets that this
24+
// could refer to, and create bidirectional links
25+
2326
context.state.analysis.uses_render_tags = true;
2427

2528
const raw_args = unwrap_optional(node.expression).arguments;

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,11 @@ import { mark_subtree_dynamic } from './fragment.js';
1515
* @param {Context} context
1616
*/
1717
export function visit_component(node, context) {
18+
node.metadata.snippets = [];
19+
20+
// TODO populate node.metadata.snippets with all the locally-defined snippets that this
21+
// could refer to, and create bidirectional links
22+
1823
mark_subtree_dynamic(context.path);
1924

2025
for (const attribute of node.attributes) {

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

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,9 @@ export namespace AST {
168168
dynamic: boolean;
169169
args_with_call_expression: Set<number>;
170170
path: SvelteNode[];
171+
/** The set of locally-defined snippets that this render tag could correspond to,
172+
* used for CSS pruning purposes */
173+
snippets: SnippetBlock[];
171174
};
172175
}
173176

@@ -280,6 +283,9 @@ export namespace AST {
280283
metadata: {
281284
scopes: Record<string, Scope>;
282285
dynamic: boolean;
286+
/** The set of locally-defined snippets that this component tag could render,
287+
* used for CSS pruning purposes */
288+
snippets: SnippetBlock[];
283289
};
284290
}
285291

@@ -320,6 +326,9 @@ export namespace AST {
320326
/** @internal */
321327
metadata: {
322328
scopes: Record<string, Scope>;
329+
/** The set of locally-defined snippets that this component tag could render,
330+
* used for CSS pruning purposes */
331+
snippets: SnippetBlock[];
323332
};
324333
}
325334

@@ -371,6 +380,9 @@ export namespace AST {
371380
/** @internal */
372381
metadata: {
373382
scopes: Record<string, Scope>;
383+
/** The set of locally-defined snippets that this component tag could render,
384+
* used for CSS pruning purposes */
385+
snippets: SnippetBlock[];
374386
};
375387
}
376388

@@ -440,6 +452,12 @@ export namespace AST {
440452
expression: Identifier;
441453
parameters: Pattern[];
442454
body: Fragment;
455+
/** @internal */
456+
metadata: {
457+
/** The set of components/render tags that could render this snippet,
458+
* used for CSS pruning */
459+
sites: Set<Component | SvelteComponent | RenderTag>;
460+
};
443461
}
444462

445463
export interface Attribute extends BaseNode {

0 commit comments

Comments
 (0)