Skip to content

Commit f105e48

Browse files
committed
chore: remove node.parent and node.prev
1 parent 732da83 commit f105e48

File tree

10 files changed

+13
-61
lines changed

10 files changed

+13
-61
lines changed

packages/svelte/src/compiler/index.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,6 @@ function to_public_ast(source, ast, modern) {
120120
if (modern) {
121121
const clean = (/** @type {any} */ node) => {
122122
delete node.metadata;
123-
delete node.parent;
124123
};
125124

126125
ast.options?.attributes.forEach((attribute) => {

packages/svelte/src/compiler/legacy.js

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,6 @@ export function convert(source, ast) {
4545
return /** @type {Legacy.LegacyRoot} */ (
4646
walk(root, null, {
4747
_(node, { next }) {
48-
// @ts-ignore
49-
delete node.parent;
5048
// @ts-ignore
5149
delete node.metadata;
5250
next();
@@ -62,8 +60,6 @@ export function convert(source, ast) {
6260
idx = node.fragment.nodes.length;
6361
}
6462

65-
// @ts-ignore
66-
delete options.__raw__.parent;
6763
node.fragment.nodes.splice(idx, 0, /** @type {any} */ (options).__raw__);
6864
}
6965

@@ -85,15 +81,11 @@ export function convert(source, ast) {
8581
}
8682

8783
if (instance) {
88-
// @ts-ignore
89-
delete instance.parent;
9084
// @ts-ignore
9185
delete instance.attributes;
9286
}
9387

9488
if (module) {
95-
// @ts-ignore
96-
delete module.parent;
9789
// @ts-ignore
9890
delete module.attributes;
9991
}

packages/svelte/src/compiler/phases/1-parse/index.js

Lines changed: 3 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -262,30 +262,12 @@ export class Parser {
262262
}
263263

264264
/**
265-
* @template T
266-
* @param {Omit<T, 'prev' | 'parent'>} node
265+
* @template {AST.Fragment['nodes'][number]} T
266+
* @param {T} node
267267
* @returns {T}
268268
*/
269269
append(node) {
270-
const current = this.current();
271-
const fragment = this.fragments.at(-1);
272-
273-
Object.defineProperties(node, {
274-
prev: {
275-
enumerable: false,
276-
value: fragment?.nodes.at(-1) ?? null
277-
},
278-
parent: {
279-
enumerable: false,
280-
configurable: true,
281-
value: current
282-
}
283-
});
284-
285-
// @ts-expect-error
286-
fragment.nodes.push(node);
287-
288-
// @ts-expect-error
270+
this.fragments.at(-1)?.nodes.push(node);
289271
return node;
290272
}
291273
}

packages/svelte/src/compiler/phases/1-parse/read/script.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,6 @@ export function read_script(parser, start, attributes) {
8484
end: parser.index,
8585
context,
8686
content: ast,
87-
parent: null,
8887
// @ts-ignore
8988
attributes
9089
};

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

Lines changed: 9 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -153,8 +153,7 @@ export default function element(parser) {
153153
scoped: false,
154154
has_spread: false,
155155
path: []
156-
},
157-
parent: null
156+
}
158157
}
159158
: /** @type {ElementLike} */ ({
160159
type,
@@ -163,7 +162,6 @@ export default function element(parser) {
163162
name,
164163
attributes: [],
165164
fragment: create_fragment(true),
166-
parent: null,
167165
metadata: {
168166
// unpopulated at first, differs between types
169167
}
@@ -348,8 +346,7 @@ export default function element(parser) {
348346
end,
349347
type: 'Text',
350348
data,
351-
raw: data,
352-
parent: null
349+
raw: data
353350
};
354351

355352
element.fragment.nodes.push(node);
@@ -422,8 +419,7 @@ function read_static_attribute(parser) {
422419
end: quoted ? parser.index - 1 : parser.index,
423420
type: 'Text',
424421
raw: raw,
425-
data: decode_character_references(raw, true),
426-
parent: null
422+
data: decode_character_references(raw, true)
427423
}
428424
];
429425
}
@@ -457,7 +453,6 @@ function read_attribute(parser) {
457453
start,
458454
end: parser.index,
459455
expression,
460-
parent: null,
461456
metadata: {
462457
expression: create_expression_metadata()
463458
}
@@ -486,7 +481,6 @@ function read_attribute(parser) {
486481
type: 'Identifier',
487482
name
488483
},
489-
parent: null,
490484
metadata: {
491485
expression: create_expression_metadata()
492486
}
@@ -531,7 +525,6 @@ function read_attribute(parser) {
531525
name: directive_name,
532526
modifiers: /** @type {Array<'important'>} */ (modifiers),
533527
value,
534-
parent: null,
535528
metadata: {
536529
expression: create_expression_metadata()
537530
}
@@ -556,19 +549,20 @@ function read_attribute(parser) {
556549
}
557550

558551
/** @type {Directive} */
559-
// @ts-expect-error TODO can't figure out this error
560552
const directive = {
561553
start,
562554
end,
563555
type,
564556
name: directive_name,
565-
modifiers,
566557
expression,
567558
metadata: {
568559
expression: create_expression_metadata()
569560
}
570561
};
571562

563+
// @ts-expect-error we do this separately from the declaration to avoid upsetting typescript
564+
directive.modifiers = modifiers;
565+
572566
if (directive.type === 'TransitionDirective') {
573567
const direction = name.slice(0, colon_index);
574568
directive.intro = direction === 'in' || direction === 'transition';
@@ -623,8 +617,7 @@ function read_attribute_value(parser) {
623617
end: parser.index - 1,
624618
type: 'Text',
625619
raw: '',
626-
data: '',
627-
parent: null
620+
data: ''
628621
}
629622
];
630623
}
@@ -681,8 +674,7 @@ function read_sequence(parser, done, location) {
681674
end: -1,
682675
type: 'Text',
683676
raw: '',
684-
data: '',
685-
parent: null
677+
data: ''
686678
};
687679

688680
/** @type {Array<AST.Text | AST.ExpressionTag>} */
@@ -729,7 +721,6 @@ function read_sequence(parser, done, location) {
729721
start: index,
730722
end: parser.index,
731723
expression,
732-
parent: null,
733724
metadata: {
734725
expression: create_expression_metadata()
735726
}
@@ -742,8 +733,7 @@ function read_sequence(parser, done, location) {
742733
end: -1,
743734
type: 'Text',
744735
raw: '',
745-
data: '',
746-
parent: null
736+
data: ''
747737
};
748738
} else {
749739
current_chunk.raw += parser.template[parser.index++];

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

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -758,8 +758,7 @@ export function analyze_component(root, source, options) {
758758
data: ` ${analysis.css.hash}`,
759759
raw: ` ${analysis.css.hash}`,
760760
start: -1,
761-
end: -1,
762-
parent: null
761+
end: -1
763762
};
764763

765764
if (Array.isArray(class_attribute.value)) {
@@ -775,7 +774,6 @@ export function analyze_component(root, source, options) {
775774
type: 'Text',
776775
data: analysis.css.hash,
777776
raw: analysis.css.hash,
778-
parent: null,
779777
start: -1,
780778
end: -1
781779
}

packages/svelte/src/compiler/phases/3-transform/server/visitors/shared/element.js

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,6 @@ export function build_element_attributes(node, context) {
135135
type: 'ExpressionTag',
136136
start: -1,
137137
end: -1,
138-
parent: attribute,
139138
expression: is_checkbox
140139
? b.call(
141140
b.member(attribute.expression, 'includes'),
@@ -159,7 +158,6 @@ export function build_element_attributes(node, context) {
159158
type: 'ExpressionTag',
160159
start: -1,
161160
end: -1,
162-
parent: attribute,
163161
expression: attribute.expression,
164162
metadata: {
165163
expression: create_expression_metadata()
@@ -376,7 +374,6 @@ function build_class_directives(class_directives, class_attribute) {
376374
type: 'Text',
377375
start: -1,
378376
end: -1,
379-
parent: class_attribute,
380377
data: ' ',
381378
raw: ' '
382379
});
@@ -386,7 +383,6 @@ function build_class_directives(class_directives, class_attribute) {
386383
type: 'ExpressionTag',
387384
start: -1,
388385
end: -1,
389-
parent: class_attribute,
390386
expression: b.call(
391387
b.member(b.call(b.member(b.array(expressions), 'filter'), b.id('Boolean')), b.id('join')),
392388
b.literal(' ')

packages/svelte/src/compiler/phases/3-transform/utils.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,6 @@ export function clean_nodes(
277277
trimmed.push({
278278
type: 'Comment',
279279
data: '',
280-
parent: first.parent,
281280
start: -1,
282281
end: -1
283282
});

packages/svelte/src/compiler/phases/nodes.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ export function create_attribute(name, start, end, value) {
4343
end,
4444
name,
4545
value,
46-
parent: null,
4746
metadata: {
4847
expression: create_expression_metadata(),
4948
delegated: null

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,6 @@ export namespace AST {
3737
type: string;
3838
start: number;
3939
end: number;
40-
/** @internal This is set during parsing on elements/components/expressions/text (but not attributes etc) */
41-
parent: SvelteNode | null;
4240
}
4341

4442
export interface Fragment {

0 commit comments

Comments
 (0)