Skip to content

Commit 67b2c8c

Browse files
committed
use node.metadata.path
1 parent 86fdfe0 commit 67b2c8c

File tree

6 files changed

+12
-16
lines changed

6 files changed

+12
-16
lines changed

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -709,8 +709,8 @@ export function analyze_component(root, source, options) {
709709
analyze_css(analysis.css.ast, analysis);
710710

711711
// mark nodes as scoped/unused/empty etc
712-
for (const element of analysis.elements) {
713-
prune(analysis.css.ast, element.node);
712+
for (const node of analysis.elements) {
713+
prune(analysis.css.ast, node);
714714
}
715715

716716
const { comment } = analysis.css.ast.content;
@@ -724,7 +724,7 @@ export function analyze_component(root, source, options) {
724724
warn_unused(analysis.css.ast);
725725
}
726726

727-
outer: for (const { node } of analysis.elements) {
727+
outer: for (const node of analysis.elements) {
728728
if (node.type === 'RenderTag') continue;
729729

730730
if (node.metadata.scoped) {

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

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,10 @@ import { mark_subtree_dynamic } from './shared/fragment.js';
1919
*/
2020
export function RegularElement(node, context) {
2121
validate_element(node, context);
22-
2322
check_element(node, context);
2423

2524
node.metadata.path = [...context.path];
26-
27-
context.state.analysis.elements.push({ node, path: context.path });
25+
context.state.analysis.elements.push(node);
2826

2927
// Special case: Move the children of <textarea> into a value attribute if they are dynamic
3028
if (node.name === 'textarea' && node.fragment.nodes.length > 0) {

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ import { mark_subtree_dynamic } from './shared/fragment.js';
1212
export function RenderTag(node, context) {
1313
validate_opening_tag(node, context.state, '@');
1414

15-
context.state.analysis.elements.push({ node, path: context.path });
15+
node.metadata.path = [...context.path];
16+
context.state.analysis.elements.push(node);
1617

1718
const callee = unwrap_optional(node.expression).callee;
1819

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@ import { mark_subtree_dynamic } from './shared/fragment.js';
1212
*/
1313
export function SvelteElement(node, context) {
1414
validate_element(node, context);
15-
1615
check_element(node, context);
1716

18-
context.state.analysis.elements.push({ node, path: context.path });
17+
node.metadata.path = [...context.path];
18+
context.state.analysis.elements.push(node);
1919

2020
const xmlns = /** @type {AST.Attribute & { value: [AST.Text] } | undefined} */ (
2121
node.attributes.find(

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { AST, Binding, Css, ElementWithPath, SvelteNode } from '#compiler';
1+
import type { AST, Binding, Css, SvelteNode } from '#compiler';
22
import type { Identifier, LabeledStatement, Program, VariableDeclaration } from 'estree';
33
import type { Scope, ScopeRoot } from './scope.js';
44

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

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

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,7 @@ export namespace AST {
167167
metadata: {
168168
dynamic: boolean;
169169
args_with_call_expression: Set<number>;
170+
path: SvelteNode[];
170171
};
171172
}
172173

@@ -344,6 +345,7 @@ export namespace AST {
344345
*/
345346
mathml: boolean;
346347
scoped: boolean;
348+
path: SvelteNode[];
347349
};
348350
}
349351

@@ -514,11 +516,6 @@ export type TemplateNode =
514516

515517
export type SvelteNode = Node | TemplateNode | AST.Fragment | Css.Node;
516518

517-
export interface ElementWithPath {
518-
node: AST.RegularElement | AST.SvelteElement | AST.RenderTag;
519-
path: SvelteNode[];
520-
}
521-
522519
declare module 'estree' {
523520
export interface BaseNode {
524521
/** Added by the Svelte parser */

0 commit comments

Comments
 (0)