1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
use source_map::SourceId;

use crate::{
	ArrayDestructuringField, Expression, JSXElement, ObjectDestructuringField, PropertyKey,
	StatementOrDeclaration, WithComment,
};

pub use temporary_annex::Annex;

pub use ast::*;
pub use structures::*;
pub use visitors::*;
pub use visitors_mut::*;

mod ast {
	use temporary_annex::Annex;

	use crate::block::{BlockLike, BlockLikeMut};

	use super::*;

	/// Options for behavior when visiting AST.
	/// Customizable behavior is important for analysis
	pub struct VisitSettings {
		/// Visits statements in reverse,
		/// e.g
		/// ```ts
		/// const x = 2;
		/// const y = 3;
		/// ```
		/// If `reverse_statements` is true will visit the `const y = 3` statement first
		pub reverse_statements: bool,
		/// Will not visit parameters and statements in functions. This includes arrow functions
		pub visit_function_bodies: bool,
	}

	impl Default for VisitSettings {
		fn default() -> Self {
			Self { reverse_statements: false, visit_function_bodies: true }
		}
	}

	/// Whether something has visit self
	macro_rules! mark_items {
        (impl $trait:ident for $($t:ty),*) => {
            $(
                impl $trait for $t {}
            )*
        }
    }
	pub trait SelfVisitable {}
	pub trait SelfVisitableMut {}

	mark_items! {
		impl SelfVisitable for Expression, StatementOrDeclarationRef<'_>, BlockLike<'_>, JSXElement, ImmutableVariableOrPropertyPart<'_>
	}

	mark_items! {
		impl SelfVisitableMut for Expression, StatementOrDeclarationMut<'_>, BlockLikeMut<'_>, JSXElement, MutableVariablePart<'_>
	}

	/// For something to visitable it can visit all nested fields.
	pub trait Visitable {
		fn visit<TData>(
			&self,
			visitors: &mut (impl VisitorReceiver<TData> + ?Sized),
			data: &mut TData,
			settings: &VisitSettings,
			chain: &mut Annex<Chain>,
		);

		fn visit_mut<TData>(
			&mut self,
			visitors: &mut (impl VisitorMutReceiver<TData> + ?Sized),
			data: &mut TData,
			settings: &VisitSettings,
			chain: &mut Annex<Chain>,
		);
	}

	// Implementing Visitable to some structures that are commonly used in AST
	impl<T: Visitable> Visitable for Box<T> {
		fn visit<TData>(
			&self,
			v: &mut (impl VisitorReceiver<TData> + ?Sized),
			d: &mut TData,
			s: &VisitSettings,
			c: &mut Annex<Chain>,
		) {
			Visitable::visit(&**self, v, d, s, c)
		}

		fn visit_mut<TData>(
			&mut self,
			v: &mut (impl VisitorMutReceiver<TData> + ?Sized),
			d: &mut TData,
			s: &VisitSettings,
			c: &mut Annex<Chain>,
		) {
			Visitable::visit_mut(&mut **self, v, d, s, c)
		}
	}

	impl<T: Visitable> Visitable for Vec<T> {
		fn visit<TData>(
			&self,
			v: &mut (impl VisitorReceiver<TData> + ?Sized),
			d: &mut TData,
			s: &VisitSettings,
			c: &mut Annex<Chain>,
		) {
			self.iter().for_each(|item| item.visit(v, d, s, c));
		}

		fn visit_mut<TData>(
			&mut self,
			v: &mut (impl VisitorMutReceiver<TData> + ?Sized),
			d: &mut TData,
			s: &VisitSettings,
			c: &mut Annex<Chain>,
		) {
			self.iter_mut().for_each(|item| item.visit_mut(v, d, s, c));
		}
	}

	impl<T: Visitable> Visitable for Option<T> {
		fn visit<TData>(
			&self,
			v: &mut (impl VisitorReceiver<TData> + ?Sized),
			d: &mut TData,
			s: &VisitSettings,
			c: &mut Annex<Chain>,
		) {
			if let Some(item) = self {
				item.visit(v, d, s, c);
			}
		}

		fn visit_mut<TData>(
			&mut self,
			v: &mut (impl VisitorMutReceiver<TData> + ?Sized),
			d: &mut TData,
			s: &VisitSettings,
			c: &mut Annex<Chain>,
		) {
			if let Some(item) = self {
				item.visit_mut(v, d, s, c);
			}
		}
	}

	impl<T: Visitable, U: Visitable> Visitable for (T, U) {
		fn visit<TData>(
			&self,
			v: &mut (impl VisitorReceiver<TData> + ?Sized),
			d: &mut TData,
			s: &VisitSettings,
			c: &mut Annex<Chain>,
		) {
			self.0.visit(v, d, s, c);
			self.1.visit(v, d, s, c);
		}

		fn visit_mut<TData>(
			&mut self,
			v: &mut (impl VisitorMutReceiver<TData> + ?Sized),
			d: &mut TData,
			s: &VisitSettings,
			c: &mut Annex<Chain>,
		) {
			self.0.visit_mut(v, d, s, c);
			self.1.visit_mut(v, d, s, c);
		}
	}

	macro_rules! create_blank_visiting_implementations {
        ($($T:ty),*) => {
            $(
                impl Visitable for $T {
                    fn visit<TData>(
                        &self,
                        _visitors: &mut (impl VisitorReceiver<TData> + ?Sized),
                        _data: &mut TData,
                        _settings: &VisitSettings,
                        _chain: &mut Annex<Chain>,
                    ) {}

                    fn visit_mut<TData>(
                        &mut self,
                        _visitors: &mut (impl VisitorMutReceiver<TData> + ?Sized),
                        _data: &mut TData,
                        _settings: &VisitSettings,
                        _chain: &mut Annex<Chain>,
                    ) {}
                }
            )*
        }
    }

	// Create a bunch of blank implementations for data types that do not have
	// any AST nested / aren't important for visiting.
	// TODO propertyKey should be visited
	create_blank_visiting_implementations![
		(),
		bool,
		isize,
		usize,
		i8,
		u8,
		i16,
		u16,
		i32,
		u32,
		i64,
		u64,
		i128,
		u128,
		f32,
		f64,
		char,
		String,
		Box<str>,
		std::rc::Rc<str>,
		std::path::Path,
		std::path::PathBuf,
		source_map::Span,
		crate::TypeAnnotation,
		crate::NumberRepresentation,
		crate::operators::BinaryOperator,
		crate::operators::BinaryAssignmentOperator,
		crate::operators::UnaryOperator,
		crate::operators::UnaryPrefixAssignmentOperator,
		crate::operators::UnaryPostfixAssignmentOperator,
		crate::types::InterfaceDeclaration,
		crate::types::type_alias::TypeAlias,
		crate::types::declares::DeclareFunctionDeclaration,
		crate::types::declares::DeclareVariableDeclaration,
		crate::VariableIdentifier,
		crate::PropertyReference,
		crate::Quoted,
		crate::PropertyKey<crate::property_key::AlwaysPublic>,
		crate::PropertyKey<crate::property_key::PublicOrPrivate>
	];
}

/// These are structures used when visiting AST
mod structures {
	use crate::{
		property_key::{AlwaysPublic, PublicOrPrivate},
		Declaration, Statement, VariableFieldInSourceCode,
	};

	use super::*;
	use source_map::Span;
	use temporary_annex::{Annex, Annexable};

	#[derive(Debug, Clone)]
	pub enum ChainVariable {
		Module(SourceId),
		Function(Span),
		Block(Span),
	}

	/// The current location in the AST
	#[derive(Debug, Clone)]
	pub struct Chain(Vec<ChainVariable>);

	impl Chain {
		pub fn new() -> Self {
			Self(Vec::with_capacity(10))
		}

		pub fn new_with_initial(initial: ChainVariable) -> Self {
			let mut buf = Vec::with_capacity(10);
			buf.push(initial);
			Self(buf)
		}

		pub fn len(&self) -> usize {
			self.0.len()
		}

		pub fn truncate(&mut self, to_size: usize) {
			self.0.truncate(to_size)
		}

		/// TODO remove
		pub fn get_chain(&self) -> &[ChainVariable] {
			&self.0
		}

		pub fn get_module(&self) -> SourceId {
			if let ChainVariable::Module(source) = self.0.first().unwrap() {
				source.to_owned()
			} else {
				SourceId::NULL
			}
		}

		// TODO get function root. Aka last thing before in top level scope or
	}

	impl Annexable for Chain {
		type NewItem = ChainVariable;

		fn push_annex(&mut self, item: Self::NewItem) -> Annex<Self>
		where
			Self: Sized,
		{
			self.0.push(item);
			Annex::new(self)
		}

		fn revert_annex(&mut self) {
			self.0.pop();
		}
	}

	/// TODO these may go
	#[derive(Debug)]
	pub enum MutableVariablePart<'a> {
		VariableFieldName(&'a mut String),
		// TODO these should maybe only be the spread variables
		ArrayDestructuringMember(&'a mut ArrayDestructuringField<VariableFieldInSourceCode>),
		ObjectDestructuringMember(
			&'a mut WithComment<ObjectDestructuringField<VariableFieldInSourceCode>>,
		),
		ClassName(Option<&'a mut String>),
		FunctionName(&'a mut String),
		ClassPropertyKey(&'a mut WithComment<PropertyKey<PublicOrPrivate>>),
		ObjectPropertyKey(&'a mut WithComment<PropertyKey<AlwaysPublic>>),
	}

	/// TODO these may go
	#[derive(Debug)]
	pub enum ImmutableVariableOrPropertyPart<'a> {
		// TODO maybe WithComment on some of these
		VariableFieldName(&'a str, &'a Span),
		// TODO these should maybe only be the spread variables
		ArrayDestructuringMember(&'a ArrayDestructuringField<VariableFieldInSourceCode>),
		ObjectDestructuringMember(
			&'a WithComment<ObjectDestructuringField<VariableFieldInSourceCode>>,
		),
		ClassName(Option<&'a str>, &'a Span),
		FunctionName(&'a str, &'a Span),
		ClassPropertyKey(&'a WithComment<PropertyKey<PublicOrPrivate>>),
		ObjectPropertyKey(&'a WithComment<PropertyKey<AlwaysPublic>>),
	}

	impl<'a> ImmutableVariableOrPropertyPart<'a> {
		pub fn get_name(&self) -> Option<&'a str> {
			match self {
				ImmutableVariableOrPropertyPart::FunctionName(name, _)
				| ImmutableVariableOrPropertyPart::VariableFieldName(name, _) => Some(name),
				ImmutableVariableOrPropertyPart::ArrayDestructuringMember(_)
				| ImmutableVariableOrPropertyPart::ObjectDestructuringMember(_) => None,
				ImmutableVariableOrPropertyPart::ClassName(name, _) => *name,
				ImmutableVariableOrPropertyPart::ObjectPropertyKey(property) => {
					match property.get_ast_ref() {
						PropertyKey::Ident(ident, _, _) | PropertyKey::StringLiteral(ident, _) => {
							Some(ident.as_str())
						}
						PropertyKey::NumberLiteral(_, _) | PropertyKey::Computed(_, _) => None,
					}
				}
				ImmutableVariableOrPropertyPart::ClassPropertyKey(property) => {
					match property.get_ast_ref() {
						PropertyKey::Ident(ident, _, _) | PropertyKey::StringLiteral(ident, _) => {
							Some(ident.as_str())
						}
						PropertyKey::NumberLiteral(_, _) | PropertyKey::Computed(_, _) => None,
					}
				}
			}
		}

		pub fn get_position(&self) -> &Span {
			use crate::ASTNode;
			match self {
				ImmutableVariableOrPropertyPart::FunctionName(_, pos)
				| ImmutableVariableOrPropertyPart::ClassName(_, pos)
				| ImmutableVariableOrPropertyPart::VariableFieldName(_, pos) => pos,
				ImmutableVariableOrPropertyPart::ArrayDestructuringMember(member) => {
					member.get_position()
				}
				ImmutableVariableOrPropertyPart::ObjectDestructuringMember(member) => {
					member.get_position()
				}
				ImmutableVariableOrPropertyPart::ClassPropertyKey(property_key) => {
					property_key.get_position()
				}
				ImmutableVariableOrPropertyPart::ObjectPropertyKey(property_key) => {
					property_key.get_position()
				}
			}
		}
	}

	pub enum StatementOrDeclarationRef<'a> {
		Statement(&'a crate::Statement),
		Declaration(&'a crate::Declaration),
	}

	impl<'a> From<&'a StatementOrDeclaration> for StatementOrDeclarationRef<'a> {
		fn from(value: &'a StatementOrDeclaration) -> Self {
			match value {
				StatementOrDeclaration::Statement(item) => {
					StatementOrDeclarationRef::Statement(item)
				}
				StatementOrDeclaration::Declaration(item) => {
					StatementOrDeclarationRef::Declaration(item)
				}
			}
		}
	}

	impl<'a> From<&'a Statement> for StatementOrDeclarationRef<'a> {
		fn from(item: &'a Statement) -> Self {
			StatementOrDeclarationRef::Statement(item)
		}
	}

	impl<'a> From<&'a Declaration> for StatementOrDeclarationRef<'a> {
		fn from(item: &'a Declaration) -> Self {
			StatementOrDeclarationRef::Declaration(item)
		}
	}

	pub enum StatementOrDeclarationMut<'a> {
		Statement(&'a mut crate::Statement),
		Declaration(&'a mut crate::Declaration),
	}

	impl<'a> From<&'a mut StatementOrDeclaration> for StatementOrDeclarationMut<'a> {
		fn from(value: &'a mut StatementOrDeclaration) -> Self {
			match value {
				StatementOrDeclaration::Statement(item) => {
					StatementOrDeclarationMut::Statement(item)
				}
				StatementOrDeclaration::Declaration(item) => {
					StatementOrDeclarationMut::Declaration(item)
				}
			}
		}
	}

	impl<'a> From<&'a mut Statement> for StatementOrDeclarationMut<'a> {
		fn from(item: &'a mut Statement) -> Self {
			StatementOrDeclarationMut::Statement(item)
		}
	}

	impl<'a> From<&'a mut Declaration> for StatementOrDeclarationMut<'a> {
		fn from(item: &'a mut Declaration) -> Self {
			StatementOrDeclarationMut::Declaration(item)
		}
	}
}

mod visitors {
	use super::*;
	use crate::{block::BlockLike, TSXKeyword};
	use source_map::Span;

	/// A visitor over something which is hooked/is SelfVisitable with some Data
	pub trait Visitor<Item: SelfVisitable, Data> {
		fn visit(&mut self, item: &Item, data: &mut Data, chain: &Chain);
	}

	/// These are a receiver traits of the visitor
	#[allow(unused_variables)]
	pub trait VisitorReceiver<T> {
		fn visit_expression(&mut self, expression: &Expression, data: &mut T, chain: &Chain) {}

		fn visit_statement(
			&mut self,
			statement: StatementOrDeclarationRef,
			data: &mut T,
			chain: &Chain,
		) {
		}

		fn visit_jsx_element(&mut self, element: &JSXElement, data: &mut T, chain: &Chain) {}

		fn visit_variable(
			&mut self,
			variable: &ImmutableVariableOrPropertyPart,
			data: &mut T,
			chain: &Chain,
		) {
		}

		fn visit_block(&mut self, block: &BlockLike, data: &mut T, chain: &Chain) {}

		fn visit_keyword(&mut self, keyword: &(TSXKeyword, &Span), data: &mut T, chain: &Chain) {}
	}

	impl<T> VisitorReceiver<T> for Visitors<T> {
		fn visit_expression(&mut self, expression: &Expression, data: &mut T, chain: &Chain) {
			self.expression_visitors.iter_mut().for_each(|vis| vis.visit(expression, data, chain));
		}

		fn visit_statement(
			&mut self,
			statement: StatementOrDeclarationRef,
			data: &mut T,
			chain: &Chain,
		) {
			self.statement_visitors.iter_mut().for_each(|vis| vis.visit(&statement, data, chain));
		}

		fn visit_jsx_element(&mut self, jsx_element: &JSXElement, data: &mut T, chain: &Chain) {
			self.jsx_element_visitors
				.iter_mut()
				.for_each(|vis| vis.visit(jsx_element, data, chain));
		}

		fn visit_variable(
			&mut self,
			variable: &ImmutableVariableOrPropertyPart,
			data: &mut T,
			chain: &Chain,
		) {
			self.variable_visitors.iter_mut().for_each(|vis| vis.visit(variable, data, chain))
		}

		fn visit_block(&mut self, block: &BlockLike, data: &mut T, chain: &Chain) {
			self.block_visitors.iter_mut().for_each(|vis| vis.visit(block, data, chain))
		}

		fn visit_keyword(&mut self, _keyword: &(TSXKeyword, &Span), _data: &mut T, _chain: &Chain) {
		}
	}

	#[derive(Default)]
	pub struct Visitors<T> {
		pub expression_visitors: Vec<Box<dyn Visitor<Expression, T>>>,
		pub statement_visitors: Vec<Box<dyn for<'a> Visitor<StatementOrDeclarationRef<'a>, T>>>,
		pub jsx_element_visitors: Vec<Box<dyn Visitor<JSXElement, T>>>,
		pub variable_visitors:
			Vec<Box<dyn for<'a> Visitor<ImmutableVariableOrPropertyPart<'a>, T>>>,
		pub block_visitors: Vec<Box<dyn for<'a> Visitor<BlockLike<'a>, T>>>,
	}

	// impl<T, U> Visitor<Expression, T> for U
	// where
	// 	U: Fn(&Expression, &mut T),
	// {
	// 	fn visit(&mut self, expression: &Expression, data: &mut T, _chain: &Chain) {
	// 		(self)(expression, data)
	// 	}
	// }

	// impl<T, U> Visitor<Statement, T> for U
	// where
	// 	U: Fn(&Statement, &mut T),
	// {
	// 	fn visit(&mut self, statement: &Statement, data: &mut T, _chain: &Chain) {
	// 		(self)(statement, data)
	// 	}
	// }

	// impl<'a, T, U> Visitor<ImmutableVariableOrPropertyPart<'a>, T> for U
	// where
	// 	U: Fn(&ImmutableVariableOrPropertyPart, &mut T),
	// {
	// 	fn visit(
	// 		&mut self,
	// 		variable: &ImmutableVariableOrPropertyPart<'a>,
	// 		data: &mut T,
	// 		_chain: &Chain,
	// 	) {
	// 		(self)(variable, data)
	// 	}
	// }
}

mod visitors_mut {
	use crate::block::BlockLikeMut;

	use super::*;

	/// A visitor over something which is hooked/is SelfVisitable with some Data
	pub trait VisitorMut<Item: SelfVisitableMut, Data> {
		fn visit_mut(&mut self, item: &mut Item, data: &mut Data, chain: &Chain);
	}

	/// These are a receiver traits of the visitor
	#[allow(unused_variables)]
	pub trait VisitorMutReceiver<T> {
		fn visit_expression_mut(
			&mut self,
			expression: &mut Expression,
			data: &mut T,
			chain: &Chain,
		) {
		}

		fn visit_statement_mut(
			&mut self,
			statement: StatementOrDeclarationMut,
			data: &mut T,
			chain: &Chain,
		) {
		}

		fn visit_jsx_element_mut(&mut self, element: &mut JSXElement, data: &mut T, chain: &Chain) {
		}

		fn visit_variable_mut(
			&mut self,
			variable: &mut MutableVariablePart,
			data: &mut T,
			chain: &Chain,
		) {
		}

		fn visit_block_mut(&mut self, block: &mut BlockLikeMut, data: &mut T, chain: &Chain) {}
	}

	pub struct VisitorsMut<T> {
		pub expression_visitors_mut: Vec<Box<dyn VisitorMut<Expression, T>>>,
		pub statement_visitors_mut:
			Vec<Box<dyn for<'a> VisitorMut<StatementOrDeclarationMut<'a>, T>>>,
		pub jsx_element_visitors_mut: Vec<Box<dyn VisitorMut<JSXElement, T>>>,
		pub variable_visitors_mut: Vec<Box<dyn for<'a> VisitorMut<MutableVariablePart<'a>, T>>>,
		pub block_visitors_mut: Vec<Box<dyn for<'a> VisitorMut<BlockLikeMut<'a>, T>>>,
	}

	impl<T> Default for VisitorsMut<T> {
		fn default() -> Self {
			Self {
				expression_visitors_mut: Default::default(),
				statement_visitors_mut: Default::default(),
				jsx_element_visitors_mut: Default::default(),
				variable_visitors_mut: Default::default(),
				block_visitors_mut: Default::default(),
			}
		}
	}

	impl<T> VisitorMutReceiver<T> for VisitorsMut<T> {
		fn visit_expression_mut(
			&mut self,
			expression: &mut Expression,
			data: &mut T,
			chain: &Chain,
		) {
			self.expression_visitors_mut
				.iter_mut()
				.for_each(|vis| vis.visit_mut(expression, data, chain));
		}

		fn visit_statement_mut(
			&mut self,
			mut statement: StatementOrDeclarationMut,
			data: &mut T,
			chain: &Chain,
		) {
			self.statement_visitors_mut
				.iter_mut()
				.for_each(|vis| vis.visit_mut(&mut statement, data, chain));
		}

		fn visit_jsx_element_mut(&mut self, element: &mut JSXElement, data: &mut T, chain: &Chain) {
			self.jsx_element_visitors_mut
				.iter_mut()
				.for_each(|vis| vis.visit_mut(element, data, chain));
		}

		fn visit_variable_mut(
			&mut self,
			variable: &mut MutableVariablePart,
			data: &mut T,
			chain: &Chain,
		) {
			self.variable_visitors_mut
				.iter_mut()
				.for_each(|vis| vis.visit_mut(variable, data, chain));
		}

		fn visit_block_mut(&mut self, block: &mut BlockLikeMut, data: &mut T, chain: &Chain) {
			self.block_visitors_mut.iter_mut().for_each(|vis| vis.visit_mut(block, data, chain));
		}
	}

	// Implementors for functions...
	// impl<T, U> VisitorMut<Expression, T> for U
	// where
	// 	U: Fn(&mut Expression, &mut T),
	// {
	// 	fn visit_mut(&mut self, expression: &mut Expression, data: &mut T, _chain: &Chain) {
	// 		(self)(expression, data)
	// 	}
	// }

	// impl<T, U> VisitorMut<Statement, T> for U
	// where
	// 	U: Fn(&mut Statement, &mut T),
	// {
	// 	fn visit_mut(&mut self, statement: &mut Statement, data: &mut T, _chain: &Chain) {
	// 		(self)(statement, data)
	// 	}
	// }

	// impl<'a, T, U> VisitorMut<MutableVariablePart<'a>, T> for U
	// where
	// 	U: Fn(&mut MutableVariablePart, &mut T),
	// {
	// 	fn visit_mut(&mut self, item: &mut MutableVariablePart, data: &mut T, _chain: &Chain) {
	// 		(self)(item, data)
	// 	}
	// }
}