1 #[cfg(feature = "luau")]
2 use full_moon::ast::types::{
3 IndexedTypeInfo, TypeAssertion, TypeField, TypeFieldKey, TypeInfo, TypeSpecifier,
4 };
5 use full_moon::ast::{
6 punctuated::Punctuated, span::ContainedSpan, BinOp, Call, Expression, FunctionArgs,
7 FunctionBody, FunctionCall, FunctionName, Index, MethodCall, Parameter, Prefix, Suffix,
8 TableConstructor, UnOp, Value, Var, VarExpression,
9 };
10 use full_moon::tokenizer::{Token, TokenReference};
11
12 /// Enum to determine how trivia should be added when using trivia formatter functions
13 #[derive(Clone, Debug)]
14 pub enum FormatTriviaType {
15 /// Trivia will be added to the end of the current trivia
16 Append(Vec<Token>),
17 /// The current trivia will be replaced with the new trivia
18 Replace(Vec<Token>),
19 /// Trivia will not be changed
20 NoChange,
21 }
22
23 /// Strips all leading and trailing trivia from a specific node.
24 /// This is useful if we need to use the node to calculate sizing, whilst we do not want trivia included
strip_trivia<T>(item: &T) -> T where T: UpdateLeadingTrivia + UpdateTrailingTrivia,25 pub fn strip_trivia<T>(item: &T) -> T
26 where
27 T: UpdateLeadingTrivia + UpdateTrailingTrivia,
28 {
29 item.update_leading_trivia(FormatTriviaType::Replace(vec![]))
30 .update_trailing_trivia(FormatTriviaType::Replace(vec![]))
31 }
32
strip_leading_trivia<T>(item: &T) -> T where T: UpdateLeadingTrivia,33 pub fn strip_leading_trivia<T>(item: &T) -> T
34 where
35 T: UpdateLeadingTrivia,
36 {
37 item.update_leading_trivia(FormatTriviaType::Replace(vec![]))
38 }
39
strip_trailing_trivia<T>(item: &T) -> T where T: UpdateTrailingTrivia,40 pub fn strip_trailing_trivia<T>(item: &T) -> T
41 where
42 T: UpdateTrailingTrivia,
43 {
44 item.update_trailing_trivia(FormatTriviaType::Replace(vec![]))
45 }
46
47 pub trait UpdateLeadingTrivia {
update_leading_trivia(&self, leading_trivia: FormatTriviaType) -> Self48 fn update_leading_trivia(&self, leading_trivia: FormatTriviaType) -> Self;
49 }
50
51 pub trait UpdateTrailingTrivia {
update_trailing_trivia(&self, trailing_trivia: FormatTriviaType) -> Self52 fn update_trailing_trivia(&self, trailing_trivia: FormatTriviaType) -> Self;
53 }
54
55 pub trait UpdateTrivia {
update_trivia( &self, leading_trivia: FormatTriviaType, trailing_trivia: FormatTriviaType, ) -> Self56 fn update_trivia(
57 &self,
58 leading_trivia: FormatTriviaType,
59 trailing_trivia: FormatTriviaType,
60 ) -> Self;
61 }
62
63 impl<T> UpdateLeadingTrivia for T
64 where
65 T: UpdateTrivia,
66 {
update_leading_trivia(&self, leading_trivia: FormatTriviaType) -> Self where Self: std::marker::Sized,67 fn update_leading_trivia(&self, leading_trivia: FormatTriviaType) -> Self
68 where
69 Self: std::marker::Sized,
70 {
71 self.update_trivia(leading_trivia, FormatTriviaType::NoChange)
72 }
73 }
74
75 impl<T> UpdateTrailingTrivia for T
76 where
77 T: UpdateTrivia,
78 {
update_trailing_trivia(&self, trailing_trivia: FormatTriviaType) -> Self where Self: std::marker::Sized,79 fn update_trailing_trivia(&self, trailing_trivia: FormatTriviaType) -> Self
80 where
81 Self: std::marker::Sized,
82 {
83 self.update_trivia(FormatTriviaType::NoChange, trailing_trivia)
84 }
85 }
86
87 impl UpdateTrivia for TokenReference {
update_trivia( &self, leading_trivia: FormatTriviaType, trailing_trivia: FormatTriviaType, ) -> Self88 fn update_trivia(
89 &self,
90 leading_trivia: FormatTriviaType,
91 trailing_trivia: FormatTriviaType,
92 ) -> Self {
93 let added_leading_trivia = match leading_trivia {
94 FormatTriviaType::Append(trivia) => {
95 let mut current: Vec<Token> = self.leading_trivia().map(|x| x.to_owned()).collect();
96 current.extend(trivia);
97 current
98 }
99 FormatTriviaType::Replace(trivia) => trivia,
100 FormatTriviaType::NoChange => self.leading_trivia().map(|x| x.to_owned()).collect(),
101 };
102 let added_trailing_trivia = match trailing_trivia {
103 FormatTriviaType::Append(trivia) => {
104 let mut current: Vec<Token> =
105 self.trailing_trivia().map(|x| x.to_owned()).collect();
106 current.extend(trivia);
107 current
108 }
109 FormatTriviaType::Replace(trivia) => trivia,
110 FormatTriviaType::NoChange => self.trailing_trivia().map(|x| x.to_owned()).collect(),
111 };
112 TokenReference::new(
113 added_leading_trivia,
114 self.token().to_owned(),
115 added_trailing_trivia,
116 )
117 }
118 }
119
120 macro_rules! define_update_trivia {
121 ($node:ident, |$self:ident, $leading_trivia:ident, $trailing_trivia:ident| $body:expr) => {
122 define_update_trivia! {$node, |$self:&$node, $leading_trivia: FormatTriviaType, $trailing_trivia: FormatTriviaType| $body}
123 };
124 ($node:ident, $body:expr) => {
125 impl UpdateTrivia for $node {
126 fn update_trivia(&self, leading_trivia: FormatTriviaType, trailing_trivia: FormatTriviaType) -> Self {
127 $body(&self, leading_trivia, trailing_trivia)
128 }
129 }
130 };
131 }
132
133 macro_rules! define_update_leading_trivia {
134 ($node:ident, |$self:ident, $leading_trivia:ident| $body:expr) => {
135 define_update_leading_trivia! {$node, |$self:&$node, $leading_trivia: FormatTriviaType| $body}
136 };
137 ($node:ident, $body:expr) => {
138 impl UpdateLeadingTrivia for $node {
139 fn update_leading_trivia(&self, leading_trivia: FormatTriviaType) -> Self {
140 $body(&self, leading_trivia)
141 }
142 }
143 };
144 }
145
146 macro_rules! define_update_trailing_trivia {
147 ($node:ident, |$self:ident, $trailing_trivia:ident| $body:expr) => {
148 define_update_trailing_trivia! {$node, |$self:&$node, $trailing_trivia: FormatTriviaType| $body}
149 };
150 ($node:ident, $body:expr) => {
151 impl UpdateTrailingTrivia for $node {
152 fn update_trailing_trivia(&self, trailing_trivia: FormatTriviaType) -> Self {
153 $body(&self, trailing_trivia)
154 }
155 }
156 };
157 }
158
159 macro_rules! binop_trivia {
160 ($enum:ident, $value:ident, $leading_trivia:ident, $trailing_trivia:ident, { $($operator:ident,)+ }) => {
161 match $value {
162 $(
163 $enum::$operator(token) => $enum::$operator(token.update_trivia($leading_trivia, $trailing_trivia)),
164 )+
165 other => panic!("unknown node {:?}", other),
166 }
167 };
168 }
169
170 define_update_trivia!(BinOp, |this, leading, trailing| {
171 binop_trivia!(BinOp, this, leading, trailing, {
172 And,
173 Caret,
174 GreaterThan,
175 GreaterThanEqual,
176 LessThan,
177 LessThanEqual,
178 Minus,
179 Or,
180 Percent,
181 Plus,
182 Slash,
183 Star,
184 TildeEqual,
185 TwoDots,
186 TwoEqual,
187 })
188 });
189
190 define_update_trivia!(ContainedSpan, |this, leading, trailing| {
191 let (start_token, end_token) = this.tokens();
192 ContainedSpan::new(
193 start_token.update_leading_trivia(leading),
194 end_token.update_trailing_trivia(trailing),
195 )
196 });
197
198 define_update_trivia!(Call, |this, leading, trailing| {
199 match this {
200 Call::AnonymousCall(function_args) => {
201 Call::AnonymousCall(function_args.update_trivia(leading, trailing))
202 }
203 Call::MethodCall(method_call) => {
204 Call::MethodCall(method_call.update_trivia(leading, trailing))
205 }
206 other => panic!("unknown node {:?}", other),
207 }
208 });
209
210 define_update_leading_trivia!(Expression, |this, leading| {
211 match this {
212 Expression::Parentheses {
213 contained,
214 expression,
215 } => Expression::Parentheses {
216 contained: contained.update_leading_trivia(leading),
217 expression: expression.to_owned(),
218 },
219 Expression::UnaryOperator { unop, expression } => Expression::UnaryOperator {
220 unop: unop.update_leading_trivia(leading),
221 expression: expression.to_owned(),
222 },
223 Expression::BinaryOperator { lhs, binop, rhs } => Expression::BinaryOperator {
224 lhs: Box::new(lhs.update_leading_trivia(leading)),
225 binop: binop.to_owned(),
226 rhs: rhs.to_owned(),
227 },
228 Expression::Value {
229 value,
230 #[cfg(feature = "luau")]
231 type_assertion,
232 } => Expression::Value {
233 value: Box::new(value.update_leading_trivia(leading)),
234 #[cfg(feature = "luau")]
235 type_assertion: type_assertion.to_owned(),
236 },
237 other => panic!("unknown node {:?}", other),
238 }
239 });
240
241 define_update_trailing_trivia!(Expression, |this, trailing| {
242 match this {
243 Expression::Value {
244 value,
245 #[cfg(feature = "luau")]
246 type_assertion,
247 } => {
248 #[cfg(feature = "luau")]
249 if let Some(as_assertion) = type_assertion {
250 return Expression::Value {
251 value: value.to_owned(),
252 type_assertion: Some(as_assertion.update_trailing_trivia(trailing)),
253 };
254 }
255
256 Expression::Value {
257 value: Box::new(value.update_trailing_trivia(trailing)),
258 #[cfg(feature = "luau")]
259 type_assertion: type_assertion.to_owned(),
260 }
261 }
262
263 // Add trailing trivia to the end of parentheses
264 Expression::Parentheses {
265 contained,
266 expression,
267 } => Expression::Parentheses {
268 contained: contained.update_trailing_trivia(trailing),
269 expression: expression.to_owned(),
270 },
271
272 // Keep recursing down until we find an Expression::Value
273 Expression::UnaryOperator { unop, expression } => Expression::UnaryOperator {
274 unop: unop.to_owned(),
275 expression: Box::new(expression.update_trailing_trivia(trailing)),
276 },
277
278 Expression::BinaryOperator { lhs, binop, rhs } => Expression::BinaryOperator {
279 lhs: lhs.to_owned(),
280 binop: binop.to_owned(),
281 rhs: Box::new(rhs.update_trailing_trivia(trailing)),
282 },
283 other => panic!("unknown node {:?}", other),
284 }
285 });
286
287 define_update_trivia!(FunctionArgs, |this, leading, trailing| {
288 match this {
289 FunctionArgs::Parentheses {
290 parentheses,
291 arguments,
292 } => FunctionArgs::Parentheses {
293 parentheses: parentheses.update_trivia(leading, trailing),
294 arguments: arguments.to_owned(),
295 },
296 FunctionArgs::String(token_reference) => {
297 FunctionArgs::String(token_reference.update_trivia(leading, trailing))
298 }
299 FunctionArgs::TableConstructor(table_constructor) => {
300 FunctionArgs::TableConstructor(table_constructor.update_trivia(leading, trailing))
301 }
302 other => panic!("unknown node {:?}", other),
303 }
304 });
305
306 define_update_trailing_trivia!(FunctionBody, |this, trailing| {
307 this.to_owned()
308 .with_end_token(this.end_token().update_trailing_trivia(trailing))
309 });
310
311 define_update_trivia!(FunctionCall, |this, leading, trailing| {
312 let prefix = match leading {
313 FormatTriviaType::NoChange => this.prefix().to_owned(),
314 _ => this.prefix().update_leading_trivia(leading),
315 };
316
317 let mut suffixes: Vec<Suffix> = this.suffixes().map(|x| x.to_owned()).collect();
318 match trailing {
319 FormatTriviaType::NoChange => (),
320 _ => {
321 if let Some(suffix) = suffixes.pop() {
322 suffixes.push(suffix.update_trailing_trivia(trailing))
323 }
324 }
325 };
326
327 this.to_owned().with_prefix(prefix).with_suffixes(suffixes)
328 });
329
330 define_update_trivia!(FunctionName, |this, leading, trailing| {
331 if let Some(method_name) = this.method_name() {
332 let names = this.names().update_leading_trivia(leading);
333 let method_name = method_name.update_trailing_trivia(trailing);
334 this.to_owned()
335 .with_names(names)
336 .with_method(Some((this.method_colon().unwrap().to_owned(), method_name)))
337 } else {
338 let names = this
339 .names()
340 .update_leading_trivia(leading)
341 .update_trailing_trivia(trailing);
342 this.to_owned().with_names(names)
343 }
344 });
345
346 define_update_trivia!(Index, |this, leading, trailing| {
347 match this {
348 Index::Brackets {
349 brackets,
350 expression,
351 } => Index::Brackets {
352 brackets: brackets.update_trivia(leading, trailing),
353 expression: expression.to_owned(),
354 },
355 Index::Dot { dot, name } => Index::Dot {
356 dot: dot.update_leading_trivia(leading),
357 name: name.update_trailing_trivia(trailing),
358 },
359 other => panic!("unknown node {:?}", other),
360 }
361 });
362
363 define_update_trivia!(MethodCall, |this, leading, trailing| {
364 this.to_owned()
365 .with_colon_token(this.colon_token().update_leading_trivia(leading))
366 .with_args(this.args().update_trailing_trivia(trailing))
367 });
368
369 define_update_trivia!(Parameter, |this, leading, trailing| {
370 match this {
371 Parameter::Ellipse(token) => Parameter::Ellipse(token.update_trivia(leading, trailing)),
372 Parameter::Name(token) => Parameter::Name(token.update_trivia(leading, trailing)),
373 other => panic!("unknown node {:?}", other),
374 }
375 });
376
377 define_update_leading_trivia!(Prefix, |this, leading| {
378 match this {
379 Prefix::Name(token_reference) => {
380 Prefix::Name(token_reference.update_leading_trivia(leading))
381 }
382 Prefix::Expression(expression) => {
383 Prefix::Expression(expression.update_leading_trivia(leading))
384 }
385 other => panic!("unknown node {:?}", other),
386 }
387 });
388
389 impl<T> UpdateLeadingTrivia for Punctuated<T>
390 where
391 T: UpdateLeadingTrivia + Clone,
392 {
update_leading_trivia(&self, leading: FormatTriviaType) -> Self393 fn update_leading_trivia(&self, leading: FormatTriviaType) -> Self {
394 let mut punctuated = Punctuated::new();
395 let mut pairs = self.to_owned().into_pairs();
396
397 // Retrieve first item and add leading trivia
398 if let Some(first_pair) = pairs.next() {
399 let updated_pair = first_pair.map(|value| value.update_leading_trivia(leading));
400 punctuated.push(updated_pair);
401 };
402
403 // Add back the rest of the values
404 for pair in pairs {
405 punctuated.push(full_moon::ast::punctuated::Pair::new(
406 pair.value().clone(),
407 pair.punctuation().map(|x| x.to_owned()),
408 ))
409 }
410
411 punctuated
412 }
413 }
414
415 impl<T> UpdateTrailingTrivia for Punctuated<T>
416 where
417 T: UpdateTrailingTrivia + Clone,
418 {
update_trailing_trivia(&self, trailing: FormatTriviaType) -> Self419 fn update_trailing_trivia(&self, trailing: FormatTriviaType) -> Self {
420 let mut punctuated = self.to_owned();
421
422 // Add any trailing trivia to the end of the punctuated list
423 if let Some(pair) = punctuated.pop() {
424 let pair = pair.map(|value| value.update_trailing_trivia(trailing));
425 punctuated.push(pair);
426 }
427
428 punctuated
429 }
430 }
431
432 define_update_trivia!(Suffix, |this, leading, trailing| {
433 match this {
434 Suffix::Call(call) => Suffix::Call(call.update_trivia(leading, trailing)),
435 Suffix::Index(index) => Suffix::Index(index.update_trivia(leading, trailing)),
436 other => panic!("unknown node {:?}", other),
437 }
438 });
439
440 define_update_trivia!(TableConstructor, |this, leading, trailing| {
441 this.to_owned()
442 .with_braces(this.braces().update_trivia(leading, trailing))
443 });
444
445 define_update_leading_trivia!(UnOp, |this, leading| {
446 match this {
447 UnOp::Hash(token_reference) => UnOp::Hash(token_reference.update_leading_trivia(leading)),
448 UnOp::Minus(token_reference) => UnOp::Minus(token_reference.update_leading_trivia(leading)),
449 UnOp::Not(token_reference) => UnOp::Not(token_reference.update_leading_trivia(leading)),
450 other => panic!("unknown node {:?}", other),
451 }
452 });
453
454 define_update_leading_trivia!(Value, |this, leading| {
455 match this {
456 Value::Function((token, function_body)) => Value::Function((
457 token.update_leading_trivia(leading),
458 function_body.to_owned(),
459 )),
460 Value::FunctionCall(function_call) => {
461 Value::FunctionCall(function_call.update_leading_trivia(leading))
462 }
463 Value::Number(token_reference) => {
464 Value::Number(token_reference.update_leading_trivia(leading))
465 }
466 Value::ParenthesesExpression(expression) => {
467 Value::ParenthesesExpression(expression.update_leading_trivia(leading))
468 }
469 Value::String(token_reference) => {
470 Value::String(token_reference.update_leading_trivia(leading))
471 }
472 Value::Symbol(token_reference) => {
473 Value::Symbol(token_reference.update_leading_trivia(leading))
474 }
475 Value::TableConstructor(table_constructor) => {
476 Value::TableConstructor(table_constructor.update_leading_trivia(leading))
477 }
478 Value::Var(var) => Value::Var(var.update_leading_trivia(leading)),
479 other => panic!("unknown node {:?}", other),
480 }
481 });
482
483 define_update_trailing_trivia!(Value, |this, trailing| {
484 match this {
485 Value::Function((token, function_body)) => Value::Function((
486 token.to_owned(),
487 function_body.update_trailing_trivia(trailing),
488 )),
489 Value::FunctionCall(function_call) => {
490 Value::FunctionCall(function_call.update_trailing_trivia(trailing))
491 }
492 Value::Number(token_reference) => {
493 Value::Number(token_reference.update_trailing_trivia(trailing))
494 }
495 Value::ParenthesesExpression(expression) => {
496 Value::ParenthesesExpression(expression.update_trailing_trivia(trailing))
497 }
498 Value::String(token_reference) => {
499 Value::String(token_reference.update_trailing_trivia(trailing))
500 }
501 Value::Symbol(token_reference) => {
502 Value::Symbol(token_reference.update_trailing_trivia(trailing))
503 }
504 Value::TableConstructor(table_constructor) => {
505 Value::TableConstructor(table_constructor.update_trailing_trivia(trailing))
506 }
507 Value::Var(var) => Value::Var(var.update_trailing_trivia(trailing)),
508 other => panic!("unknown node {:?}", other),
509 }
510 });
511
512 define_update_leading_trivia!(Var, |this, leading| {
513 match this {
514 Var::Name(token_reference) => Var::Name(token_reference.update_leading_trivia(leading)),
515 Var::Expression(var_expresion) => {
516 Var::Expression(var_expresion.update_leading_trivia(leading))
517 }
518 other => panic!("unknown node {:?}", other),
519 }
520 });
521
522 define_update_trailing_trivia!(Var, |this, trailing| {
523 match this {
524 Var::Name(token_reference) => Var::Name(token_reference.update_trailing_trivia(trailing)),
525 Var::Expression(var_expression) => {
526 Var::Expression(var_expression.update_trailing_trivia(trailing))
527 }
528 other => panic!("unknown node {:?}", other),
529 }
530 });
531
532 define_update_trivia!(VarExpression, |this, leading, trailing| {
533 let prefix = match leading {
534 FormatTriviaType::NoChange => this.prefix().to_owned(),
535 _ => this.prefix().update_leading_trivia(leading),
536 };
537
538 let mut suffixes: Vec<Suffix> = this.suffixes().map(|x| x.to_owned()).collect();
539 match trailing {
540 FormatTriviaType::NoChange => (),
541 _ => {
542 if let Some(suffix) = suffixes.pop() {
543 suffixes.push(suffix.update_trailing_trivia(trailing))
544 }
545 }
546 };
547
548 this.to_owned().with_prefix(prefix).with_suffixes(suffixes)
549 });
550
551 #[cfg(feature = "luau")]
552 define_update_trailing_trivia!(TypeInfo, |this, trailing| {
553 match this {
554 TypeInfo::Array { braces, type_info } => TypeInfo::Array {
555 braces: braces.update_trailing_trivia(trailing),
556 type_info: type_info.to_owned(),
557 },
558 TypeInfo::Basic(token_reference) => {
559 TypeInfo::Basic(token_reference.update_trailing_trivia(trailing))
560 }
561 TypeInfo::Callback {
562 parentheses,
563 arguments,
564 arrow,
565 return_type,
566 } => TypeInfo::Callback {
567 parentheses: parentheses.to_owned(),
568 arguments: arguments.to_owned(),
569 arrow: arrow.to_owned(),
570 return_type: Box::new(return_type.update_trailing_trivia(trailing)),
571 },
572 TypeInfo::Generic {
573 base,
574 arrows,
575 generics,
576 } => TypeInfo::Generic {
577 base: base.to_owned(),
578 arrows: arrows.update_trailing_trivia(trailing),
579 generics: generics.to_owned(),
580 },
581
582 TypeInfo::Intersection {
583 left,
584 ampersand,
585 right,
586 } => TypeInfo::Intersection {
587 left: left.to_owned(),
588 ampersand: ampersand.to_owned(),
589 right: Box::new(right.update_trailing_trivia(trailing)),
590 },
591
592 TypeInfo::Module {
593 module,
594 punctuation,
595 type_info,
596 } => TypeInfo::Module {
597 module: module.to_owned(),
598 punctuation: punctuation.to_owned(),
599 type_info: Box::new(type_info.update_trailing_trivia(trailing)),
600 },
601
602 TypeInfo::Optional {
603 base,
604 question_mark,
605 } => TypeInfo::Optional {
606 base: base.to_owned(),
607 question_mark: question_mark.update_trailing_trivia(trailing),
608 },
609
610 TypeInfo::Table { braces, fields } => TypeInfo::Table {
611 braces: braces.update_trailing_trivia(trailing),
612 fields: fields.to_owned(),
613 },
614
615 TypeInfo::Typeof {
616 typeof_token,
617 parentheses,
618 inner,
619 } => TypeInfo::Typeof {
620 typeof_token: typeof_token.to_owned(),
621 parentheses: parentheses.update_trailing_trivia(trailing),
622 inner: inner.to_owned(),
623 },
624
625 TypeInfo::Tuple { parentheses, types } => TypeInfo::Tuple {
626 parentheses: parentheses.update_trailing_trivia(trailing),
627 types: types.to_owned(),
628 },
629
630 TypeInfo::Union { left, pipe, right } => TypeInfo::Union {
631 left: left.to_owned(),
632 pipe: pipe.to_owned(),
633 right: Box::new(right.update_trailing_trivia(trailing)),
634 },
635
636 TypeInfo::Variadic { ellipse, type_info } => TypeInfo::Variadic {
637 ellipse: ellipse.to_owned(),
638 type_info: Box::new(type_info.update_trailing_trivia(trailing)),
639 },
640
641 other => panic!("unknown node {:?}", other),
642 }
643 });
644
645 #[cfg(feature = "luau")]
646 define_update_trailing_trivia!(IndexedTypeInfo, |this, trailing| {
647 match this {
648 IndexedTypeInfo::Basic(token_reference) => {
649 IndexedTypeInfo::Basic(token_reference.update_trailing_trivia(trailing))
650 }
651 IndexedTypeInfo::Generic {
652 base,
653 arrows,
654 generics,
655 } => IndexedTypeInfo::Generic {
656 base: base.to_owned(),
657 arrows: arrows.update_trailing_trivia(trailing),
658 generics: generics.to_owned(),
659 },
660
661 other => panic!("unknown node {:?}", other),
662 }
663 });
664
665 #[cfg(feature = "luau")]
666 define_update_trailing_trivia!(TypeAssertion, |this, trailing| {
667 this.to_owned()
668 .with_cast_to(this.cast_to().update_trailing_trivia(trailing))
669 });
670
671 #[cfg(feature = "luau")]
672 define_update_leading_trivia!(TypeField, |this, leading| {
673 this.to_owned()
674 .with_key(this.key().update_leading_trivia(leading))
675 });
676
677 #[cfg(feature = "luau")]
678 define_update_trailing_trivia!(TypeField, |this, trailing| {
679 this.to_owned()
680 .with_value(this.value().update_trailing_trivia(trailing))
681 });
682
683 #[cfg(feature = "luau")]
684 define_update_leading_trivia!(TypeFieldKey, |this, leading| {
685 match this {
686 TypeFieldKey::Name(token) => TypeFieldKey::Name(token.update_leading_trivia(leading)),
687 TypeFieldKey::IndexSignature { brackets, inner } => TypeFieldKey::IndexSignature {
688 brackets: brackets.update_leading_trivia(leading),
689 inner: inner.to_owned(),
690 },
691 other => panic!("unknown node {:?}", other),
692 }
693 });
694
695 #[cfg(feature = "luau")]
696 define_update_trailing_trivia!(TypeSpecifier, |this, trailing| {
697 this.to_owned()
698 .with_type_info(this.type_info().update_trailing_trivia(trailing))
699 });
700