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
//! Contains logic that makes viewing and transform parts of AST trivial through the visitor pattern

use source_map::SourceId;

use crate::{
	ArrayDestructuringField, Expression, 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::{
		BlockItem, BlockItemMut, Chain, Expression, ImmutableVariableOrProperty,
		MutableVariableOrProperty, VisitorMutReceiver, VisitorReceiver,
	};

	/// Options for behavior when visiting AST.
	/// Customizable behavior is important for analysis
	pub struct VisitOptions {
		/// Visits statements in reverse,
		/// e.g
		/// ```ts
		/// const x = 2;
		/// const y = 3;
		/// ```
		/// If `reverse_statements` is true, `const y = 3` will be visited before `const x = 2`
		pub reverse_statements: bool,
		/// Will not visit anything under nested blocks, functions etc
		pub visit_nested_blocks: bool,
	}

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

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

	/// Yielded during visiting AST. Might not be 1:1 with AST and include a wrapping type
	pub trait SelfVisitable {}

	/// Yielded during visiting AST. Might not be 1:1 with AST and include a wrapping type
	pub trait SelfVisitableMut {}

	mark_items! {
		impl SelfVisitable for Expression, BlockItem<'_>, BlockLike<'_>, ImmutableVariableOrProperty<'_>
	}

	mark_items! {
		impl SelfVisitableMut for Expression, BlockLikeMut<'_>, BlockItemMut<'_>, MutableVariableOrProperty<'_>
	}

	/// 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,
			options: &VisitOptions,
			chain: &mut Annex<Chain>,
		);

		fn visit_mut<TData>(
			&mut self,
			visitors: &mut (impl VisitorMutReceiver<TData> + ?Sized),
			data: &mut TData,
			options: &VisitOptions,
			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: &VisitOptions,
			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: &VisitOptions,
			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: &VisitOptions,
			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: &VisitOptions,
			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: &VisitOptions,
			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: &VisitOptions,
			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: &VisitOptions,
			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: &VisitOptions,
			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,
                        _options: &VisitOptions,
                        _chain: &mut Annex<Chain>,
                    ) {}

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

	// A bunch of blank implementations for data types that do not have
	// any AST nested / aren't important for visiting.
	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::declarations::ImportExportName,
		crate::declarations::ImportLocation,
		crate::functions::FunctionHeader,
		crate::functions::MethodHeader
	];
}

/// Data used when visiting AST
mod structures {
	use crate::{
		property_key::{AlwaysPublic, PublicOrPrivate},
		Statement, VariableFieldInSourceCode, VariableIdentifier,
	};

	use super::{
		ArrayDestructuringField, ObjectDestructuringField, PropertyKey, SourceId,
		StatementOrDeclaration, WithComment,
	};
	use source_map::Span;
	use temporary_annex::{Annex, Annexable};

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

	/// Contains [`ChainVariable`]s which signal the position in the AST
	#[derive(Debug, Clone)]
	pub struct Chain(Vec<ChainVariable>);

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

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

		#[must_use]
		pub fn len(&self) -> usize {
			self.0.len()
		}

		#[must_use]
		pub fn is_empty(&self) -> bool {
			self.0.is_empty()
		}

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

		#[must_use]
		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();
		}
	}

	#[derive(Debug)]
	pub enum ImmutableVariableOrProperty<'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 VariableIdentifier>),
		FunctionName(Option<&'a VariableIdentifier>),
		ClassPropertyKey(&'a PropertyKey<PublicOrPrivate>),
		ObjectPropertyKey(&'a PropertyKey<AlwaysPublic>),
	}

	#[derive(Debug)]
	pub enum MutableVariableOrProperty<'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 VariableIdentifier>),
		FunctionName(Option<&'a mut VariableIdentifier>),
		ClassPropertyKey(&'a mut PropertyKey<PublicOrPrivate>),
		ObjectPropertyKey(&'a mut PropertyKey<AlwaysPublic>),
	}

	impl<'a> ImmutableVariableOrProperty<'a> {
		#[must_use]
		pub fn get_variable_name(&self) -> Option<&'a str> {
			match self {
				ImmutableVariableOrProperty::VariableFieldName(name, _) => Some(name),
				ImmutableVariableOrProperty::ArrayDestructuringMember(a) => match a {
					ArrayDestructuringField::Spread(_, a) => Some(a.as_str()),
					ArrayDestructuringField::Name(_, _) | ArrayDestructuringField::None => None,
				},
				ImmutableVariableOrProperty::ObjectDestructuringMember(o) => {
					match o.get_ast_ref() {
						ObjectDestructuringField::Spread(name, _)
						| ObjectDestructuringField::Name(name, _, _) => Some(name.as_str()),
						ObjectDestructuringField::Map { .. } => None,
					}
				}
				ImmutableVariableOrProperty::FunctionName(name)
				| ImmutableVariableOrProperty::ClassName(name) => {
					name.map(crate::variable_fields::VariableIdentifier::as_str)
				}
				ImmutableVariableOrProperty::ObjectPropertyKey(_property) => {
					// Just want variable names
					None
					// match property.get_ast_ref() {
					// 	PropertyKey::Ident(ident, _, _)
					// 	| PropertyKey::StringLiteral(ident, _, _) => Some(ident.as_str()),
					// 	PropertyKey::NumberLiteral(_, _) | PropertyKey::Computed(_, _) => None,
					// }
				}
				ImmutableVariableOrProperty::ClassPropertyKey(_property) => {
					// Just want variable names
					None
					// match property.get_ast_ref() {
					// 	PropertyKey::Ident(ident, _, _)
					// 	| PropertyKey::StringLiteral(ident, _, _) => Some(ident.as_str()),
					// 	PropertyKey::NumberLiteral(_, _) | PropertyKey::Computed(_, _) => None,
					// }
				}
			}
		}

		#[must_use]
		pub fn get_position(&self) -> &Span {
			use crate::ASTNode;
			match self {
				ImmutableVariableOrProperty::FunctionName(pos)
				| ImmutableVariableOrProperty::ClassName(pos) => match pos {
					Some(p) => p.get_position(),
					None => &Span::NULL_SPAN,
				},
				ImmutableVariableOrProperty::VariableFieldName(_, pos) => pos,
				ImmutableVariableOrProperty::ArrayDestructuringMember(m) => m.get_position(),
				ImmutableVariableOrProperty::ObjectDestructuringMember(m) => m.get_position(),
				ImmutableVariableOrProperty::ClassPropertyKey(k) => k.get_position(),
				ImmutableVariableOrProperty::ObjectPropertyKey(k) => k.get_position(),
			}
		}
	}

	/// Wrapper type for [`StatementOrDeclaration`]. Needed because [`crate::Statement`] doesn't
	/// come under [`StatementOrDeclaration`] in the case of [`crate::BlockOrSingleStatement`]
	pub enum BlockItem<'a> {
		StatementOrDeclaration(&'a crate::StatementOrDeclaration),
		SingleStatement(&'a crate::Statement),
	}

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

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

	/// Wrapper type for [`StatementOrDeclaration`]. Needed because [`crate::Statement`] doesn't
	/// come under [`StatementOrDeclaration`] in the case of [`crate::BlockOrSingleStatement`]
	pub enum BlockItemMut<'a> {
		StatementOrDeclaration(&'a mut crate::StatementOrDeclaration),
		SingleStatement(&'a mut crate::Statement),
	}

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

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

mod visitors {
	use super::{BlockItem, Chain, Expression, ImmutableVariableOrProperty, SelfVisitable};
	use crate::{block::BlockLike, TSXKeyword};
	use source_map::Span;

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

	/// Something which has a bunch of callbacks for AST
	#[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: BlockItem, data: &mut T, chain: &Chain) {}

		fn visit_variable(
			&mut self,
			variable: &ImmutableVariableOrProperty,
			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: BlockItem, data: &mut T, chain: &Chain) {
			self.statement_visitors.iter_mut().for_each(|vis| vis.visit(&statement, data, chain));
		}

		fn visit_variable(
			&mut self,
			variable: &ImmutableVariableOrProperty,
			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) {
		}
	}

	type ExpressionVisitor<T> = Box<dyn Visitor<Expression, T>>;
	type StatementVisitor<T> = Box<dyn for<'a> Visitor<BlockItem<'a>, T>>;
	type VariableVisitor<T> = Box<dyn for<'a> Visitor<ImmutableVariableOrProperty<'a>, T>>;
	type BlockVisitor<T> = Box<dyn for<'a> Visitor<BlockLike<'a>, T>>;

	/// A utility type which implements [`VisitorReceiver`]. Use for running a bunch of different **immutable**
	/// visitors over a **immutable** AST. Used for simple analysis
	#[derive(Default)]
	pub struct Visitors<T> {
		pub expression_visitors: Vec<ExpressionVisitor<T>>,
		pub statement_visitors: Vec<StatementVisitor<T>>,
		pub variable_visitors: Vec<VariableVisitor<T>>,
		pub block_visitors: Vec<BlockVisitor<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::{BlockItemMut, Chain, Expression, MutableVariableOrProperty, SelfVisitableMut};

	/// A visitor over something which is hooked/is [`SelfVisitableMut`] 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: BlockItemMut, data: &mut T, chain: &Chain) {}

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

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

	type StatementVisitor<T> = Box<dyn for<'a> VisitorMut<BlockItemMut<'a>, T>>;
	type VariableVisitor<T> = Box<dyn for<'a> VisitorMut<MutableVariableOrProperty<'a>, T>>;
	type BlockVisitor<T> = Box<dyn for<'a> VisitorMut<BlockLikeMut<'a>, T>>;

	/// A utility type which implements [`VisitorMutReceiver`]. Use for running a bunch of different **mutable**
	/// visitors over a **mutable** AST. Therefore can remove, add or change AST
	pub struct VisitorsMut<T> {
		pub expression_visitors_mut: Vec<Box<dyn VisitorMut<Expression, T>>>,
		pub statement_visitors_mut: Vec<StatementVisitor<T>>,
		pub variable_visitors_mut: Vec<VariableVisitor<T>>,
		pub block_visitors_mut: Vec<BlockVisitor<T>>,
	}

	impl<T> Default for VisitorsMut<T> {
		fn default() -> Self {
			Self {
				expression_visitors_mut: Default::default(),
				statement_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 item: BlockItemMut, data: &mut T, chain: &Chain) {
			self.statement_visitors_mut
				.iter_mut()
				.for_each(|vis| vis.visit_mut(&mut item, data, chain));
		}

		fn visit_variable_mut(
			&mut self,
			variable: &mut MutableVariableOrProperty,
			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)
	// 	}
	// }
}