@tanstack/devtools-vite 0.2.13 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,1017 @@
1
+ import { describe, expect, it } from 'vitest'
2
+ import { addSourceToJsx } from './inject-source'
3
+
4
+ const removeEmptySpace = (str: string) => {
5
+ return str.replace(/\s/g, '').trim()
6
+ }
7
+
8
+ describe('inject source', () => {
9
+ it("shouldn't augment react fragments", () => {
10
+ const output = removeEmptySpace(
11
+ addSourceToJsx(
12
+ `
13
+ export const Route = createFileRoute("/test")({
14
+ component: function() { return <>Hello World</> },
15
+ })
16
+ `,
17
+ 'test.jsx',
18
+ ).code,
19
+ )
20
+ expect(output).toBe(
21
+ removeEmptySpace(`
22
+ export const Route = createFileRoute("/test")({
23
+ component: function() { return <>Hello World</> },
24
+ })
25
+ `),
26
+ )
27
+ })
28
+
29
+ it("shouldn't augment react fragments if they start with Fragment ", () => {
30
+ const output = removeEmptySpace(
31
+ addSourceToJsx(
32
+ `
33
+ export const Route = createFileRoute("/test")({
34
+ component: function() { return <Fragment>Hello World</Fragment> },
35
+ })
36
+ `,
37
+ 'test.jsx',
38
+ ).code,
39
+ )
40
+ expect(output).toBe(
41
+ removeEmptySpace(`
42
+ export const Route = createFileRoute("/test")({
43
+ component: function() { return <Fragment>Hello World</Fragment> },
44
+ })
45
+ `),
46
+ )
47
+ })
48
+ it("shouldn't augment react fragments if they start with React.Fragment ", () => {
49
+ const output = removeEmptySpace(
50
+ addSourceToJsx(
51
+ `
52
+ export const Route = createFileRoute("/test")({
53
+ component: function() { return <React.Fragment>Hello World</React.Fragment> },
54
+ })
55
+ `,
56
+ 'test.jsx',
57
+ ).code,
58
+ )
59
+ expect(output).toBe(
60
+ removeEmptySpace(`
61
+ export const Route = createFileRoute("/test")({
62
+ component: function() { return <React.Fragment>Hello World</React.Fragment> },
63
+ })
64
+ `),
65
+ )
66
+ })
67
+ describe('FunctionExpression', () => {
68
+ it('should work with deeply nested custom JSX syntax', () => {
69
+ const output = removeEmptySpace(
70
+ addSourceToJsx(
71
+ `
72
+ export const Route = createFileRoute("/test")({
73
+ component: function() { return <div>Hello World</div> },
74
+ })
75
+ `,
76
+ 'test.jsx',
77
+ ).code,
78
+ )
79
+ expect(output).toBe(
80
+ removeEmptySpace(`
81
+ export const Route = createFileRoute("/test")({
82
+ component: function() { return <div data-tsd-source="test.jsx:3:37">Hello World</div>; }
83
+ });
84
+ `),
85
+ )
86
+ })
87
+
88
+ it('should work with props not destructured and spread', () => {
89
+ const output = removeEmptySpace(
90
+ addSourceToJsx(
91
+ `
92
+ export const Route = createFileRoute("/test")({
93
+ component: function(props) { return <div {...props}>Hello World</div> },
94
+ })
95
+ `,
96
+ 'test.jsx',
97
+ ).code,
98
+ )
99
+ expect(output).toBe(
100
+ removeEmptySpace(`
101
+ export const Route = createFileRoute("/test")({
102
+ component: function(props) { return <div {...props}>Hello World</div> },
103
+ })
104
+ `),
105
+ )
106
+ })
107
+
108
+ it('should work with props destructured and spread', () => {
109
+ const output = removeEmptySpace(
110
+ addSourceToJsx(
111
+ `
112
+ export const Route = createFileRoute("/test")({
113
+ component: function({...props}) { return <div {...props}>Hello World</div> },
114
+ })
115
+ `,
116
+ 'test.jsx',
117
+ ).code,
118
+ )
119
+ expect(output).toBe(
120
+ removeEmptySpace(`
121
+ export const Route = createFileRoute("/test")({
122
+ component: function({...props}) { return <div {...props}>Hello World</div> },
123
+ })
124
+ `),
125
+ )
126
+ })
127
+
128
+ it('should work with props destructured and spread with a different name', () => {
129
+ const output = removeEmptySpace(
130
+ addSourceToJsx(
131
+ `
132
+ export const Route = createFileRoute("/test")({
133
+ component: function({...rest}) { return <div {...rest}>Hello World</div> },
134
+ })
135
+ `,
136
+ 'test.jsx',
137
+ ).code,
138
+ )
139
+ expect(output).toBe(
140
+ removeEmptySpace(`
141
+ export const Route = createFileRoute("/test")({
142
+ component: function({...rest}) { return <div {...rest}>Hello World</div> },
143
+ })
144
+ `),
145
+ )
146
+ })
147
+
148
+ it('should work with props spread and other normal elements', () => {
149
+ const output = removeEmptySpace(
150
+ addSourceToJsx(
151
+ `
152
+ export const Route = createFileRoute("/test")({
153
+ component: function({...rest}) { return <div><div {...rest}>Hello World</div></div> }
154
+ })
155
+ `,
156
+ 'test.jsx',
157
+ ).code,
158
+ )
159
+ expect(output).toBe(
160
+ removeEmptySpace(`
161
+ export const Route = createFileRoute("/test")({
162
+ component: function({...rest}) { return <div data-tsd-source="test.jsx:3:46"><div {...rest}>Hello World</div></div>; }
163
+ });
164
+ `),
165
+ )
166
+ })
167
+ })
168
+
169
+ describe('ArrowFunctionExpression', () => {
170
+ it('should work with deeply nested custom JSX syntax', () => {
171
+ const output = removeEmptySpace(
172
+ addSourceToJsx(
173
+ `
174
+ export const Route = createFileRoute("/test")({
175
+ component: () => <div>Hello World</div>,
176
+ })
177
+ `,
178
+ 'test.jsx',
179
+ ).code,
180
+ )
181
+ expect(output).toBe(
182
+ removeEmptySpace(`
183
+ export const Route = createFileRoute("/test")({
184
+ component: () => <div data-tsd-source="test.jsx:3:23">Hello World</div>
185
+ });
186
+ `),
187
+ )
188
+ })
189
+
190
+ it('should work with props not destructured and spread', () => {
191
+ const output = removeEmptySpace(
192
+ addSourceToJsx(
193
+ `
194
+ export const Route = createFileRoute("/test")({
195
+ component: (props) => <div {...props}>Hello World</div>,
196
+ })
197
+ `,
198
+ 'test.jsx',
199
+ ).code,
200
+ )
201
+ expect(output).toBe(
202
+ removeEmptySpace(`
203
+ export const Route = createFileRoute("/test")({
204
+ component: (props) => <div {...props}>Hello World</div>,
205
+ })
206
+ `),
207
+ )
208
+ })
209
+
210
+ it('should work with props destructured and spread', () => {
211
+ const output = removeEmptySpace(
212
+ addSourceToJsx(
213
+ `
214
+ export const Route = createFileRoute("/test")({
215
+ component: ({...props}) => <div {...props}>Hello World</div>,
216
+ })
217
+ `,
218
+ 'test.jsx',
219
+ ).code,
220
+ )
221
+ expect(output).toBe(
222
+ removeEmptySpace(`
223
+ export const Route = createFileRoute("/test")({
224
+ component: ({...props}) => <div {...props}>Hello World</div>,
225
+ })
226
+ `),
227
+ )
228
+ })
229
+
230
+ it('should work with props destructured and spread with a different name', () => {
231
+ const output = removeEmptySpace(
232
+ addSourceToJsx(
233
+ `
234
+ export const Route = createFileRoute("/test")({
235
+ component: ({...rest}) => <div {...rest}>Hello World</div>,
236
+ })
237
+ `,
238
+ 'test.jsx',
239
+ ).code,
240
+ )
241
+ expect(output).toBe(
242
+ removeEmptySpace(`
243
+ export const Route = createFileRoute("/test")({
244
+ component: ({...rest}) => <div {...rest}>Hello World</div>,
245
+ })
246
+ `),
247
+ )
248
+ })
249
+
250
+ it('should work with props spread and other normal elements', () => {
251
+ const output = removeEmptySpace(
252
+ addSourceToJsx(
253
+ `
254
+ export const Route = createFileRoute("/test")({
255
+ component: ({...rest}) => <div><div {...rest}>Hello World</div></div>,
256
+ })
257
+ `,
258
+ 'test.jsx',
259
+ ).code,
260
+ )
261
+ expect(output).toBe(
262
+ removeEmptySpace(`
263
+ export const Route = createFileRoute("/test")({
264
+ component: ({...rest}) => <div data-tsd-source="test.jsx:3:32"><div {...rest}>Hello World</div></div>
265
+ });
266
+ `),
267
+ )
268
+ })
269
+ })
270
+ describe('function declarations', () => {
271
+ it('should not duplicate the same property if there are nested functions', () => {
272
+ const output = removeEmptySpace(
273
+ addSourceToJsx(
274
+ `
275
+ function Parent({ ...props }) {
276
+ function Child({ ...props }) {
277
+ return <div />
278
+ }
279
+ return <Child {...props} />
280
+ }
281
+ `,
282
+ 'test.jsx',
283
+ ).code,
284
+ )
285
+ expect(output).toBe(
286
+ removeEmptySpace(`
287
+ function Parent({ ...props }) {
288
+ function Child({ ...props }) {
289
+ return <div data-tsd-source="test.jsx:4:17" />;
290
+ }
291
+ return <Child {...props} />;
292
+ }
293
+ `),
294
+ )
295
+ })
296
+ it('should apply data-tsd-source from parent props if an external import', () => {
297
+ const output = removeEmptySpace(
298
+ addSourceToJsx(
299
+ `
300
+
301
+ import Custom from "external";
302
+
303
+ function test({...props }) {
304
+ return <Custom children={props.children} />
305
+ }
306
+ `,
307
+ 'test.tsx',
308
+ ).code,
309
+ )
310
+ expect(output).toBe(
311
+ removeEmptySpace(`
312
+ import Custom from "external";
313
+
314
+ function test({...props }) {
315
+ return <Custom children={props.children} data-tsd-source="test.tsx:6:9" />;
316
+ }`),
317
+ )
318
+ })
319
+ it(' props not destructured', () => {
320
+ const output = removeEmptySpace(
321
+ addSourceToJsx(
322
+ `
323
+ function test(props){
324
+ return <button children={props.children} />
325
+ }
326
+ `,
327
+ 'test.jsx',
328
+ ).code,
329
+ )
330
+ expect(output).toBe(
331
+ removeEmptySpace(`
332
+ function test(props) {
333
+ return <button children={props.children} data-tsd-source="test.jsx:3:15" />;
334
+ }
335
+ `),
336
+ )
337
+ })
338
+
339
+ it("doesn't transform when props are spread across the element", () => {
340
+ const output = removeEmptySpace(
341
+ addSourceToJsx(
342
+ `
343
+ function test(props) {
344
+ return <button {...props} />
345
+ }
346
+ `,
347
+ 'test.jsx',
348
+ ).code,
349
+ )
350
+ expect(output).toBe(
351
+ removeEmptySpace(`
352
+ function test(props) {
353
+ return <button {...props} />
354
+ }
355
+ `),
356
+ )
357
+ })
358
+
359
+ it("doesn't transform when props are spread across the element but applies to other elements without any props", () => {
360
+ const output = removeEmptySpace(
361
+ addSourceToJsx(
362
+ `
363
+ function test(props) {
364
+ return (<div>
365
+ <button {...props} />
366
+ </div>)
367
+ }
368
+ `,
369
+ 'test.jsx',
370
+ ).code,
371
+ )
372
+ expect(output).toBe(
373
+ removeEmptySpace(`
374
+ function test(props) {
375
+ return <div data-tsd-source="test.jsx:3:16">
376
+ <button {...props} />
377
+ </div>;
378
+ }
379
+ `),
380
+ )
381
+ })
382
+
383
+ it("doesn't transform when props are spread across the element but applies to other elements without any props even when props are destructured", () => {
384
+ const output = removeEmptySpace(
385
+ addSourceToJsx(
386
+ `
387
+ function test({...props}) {
388
+ return (<div>
389
+ <button {...props} />
390
+ </div>)
391
+ }
392
+ `,
393
+ 'test.jsx',
394
+ ).code,
395
+ )
396
+ expect(output).toBe(
397
+ removeEmptySpace(`
398
+ function test({...props}) {
399
+ return <div data-tsd-source="test.jsx:3:16">
400
+ <button {...props} />
401
+ </div>;
402
+ }
403
+ `),
404
+ )
405
+ })
406
+
407
+ it("doesn't transform when props are spread across the element but applies to other elements without any props even when props are destructured and name is different", () => {
408
+ const output = removeEmptySpace(
409
+ addSourceToJsx(
410
+ `
411
+ function test({...rest}) {
412
+ return (<div>
413
+ <button {...rest} />
414
+ </div>)
415
+ }
416
+ `,
417
+ 'test.jsx',
418
+ ).code,
419
+ )
420
+ expect(output).toBe(
421
+ removeEmptySpace(`
422
+ function test({...rest}) {
423
+ return <div data-tsd-source="test.jsx:3:16">
424
+ <button {...rest} />
425
+ </div>;
426
+ }
427
+ `),
428
+ )
429
+ })
430
+
431
+ it(' props destructured and collected with a different name', () => {
432
+ const output = removeEmptySpace(
433
+ addSourceToJsx(
434
+ `
435
+ function test({ children, ...rest }) {
436
+ return <button children={children} {...rest} />
437
+ }
438
+ `,
439
+ 'test.jsx',
440
+ ).code,
441
+ )
442
+ expect(output).toBe(
443
+ removeEmptySpace(`
444
+ function test({ children, ...rest }) {
445
+ return <button children={children} {...rest} />
446
+ }
447
+ `),
448
+ )
449
+ })
450
+
451
+ it(' props destructured and collected', () => {
452
+ const output = removeEmptySpace(
453
+ addSourceToJsx(
454
+ `
455
+ function test({ ...props }) {
456
+ return <button children={props.children} />
457
+ }
458
+ `,
459
+ 'test.jsx',
460
+ ).code,
461
+ )
462
+ expect(output).toBe(
463
+ removeEmptySpace(`
464
+ function test({ ...props }) {
465
+ return <button children={props.children} data-tsd-source="test.jsx:3:15" />;
466
+ }
467
+ `),
468
+ )
469
+ })
470
+
471
+ it('props destructured and collected with a different name even on custom components', () => {
472
+ const output = removeEmptySpace(
473
+ addSourceToJsx(
474
+ `
475
+ function test({ children, ...rest }) {
476
+ return <CustomButton children={children} {...rest} />
477
+ }
478
+ `,
479
+ 'test.jsx',
480
+ ).code,
481
+ )
482
+ expect(output).toBe(
483
+ removeEmptySpace(`
484
+ function test({ children, ...rest }) {
485
+ return <CustomButton children={children} {...rest} />
486
+ }
487
+ `),
488
+ )
489
+ })
490
+
491
+ it('props destructured and collected even on custom components', () => {
492
+ const output = removeEmptySpace(
493
+ addSourceToJsx(
494
+ `
495
+ function test({ ...props }) {
496
+ return <CustomButton children={props.children} />
497
+ }
498
+ `,
499
+ 'test.jsx',
500
+ ).code,
501
+ )
502
+ expect(output).toBe(
503
+ removeEmptySpace(`
504
+ function test({ ...props }) {
505
+ return <CustomButton children={props.children} data-tsd-source="test.jsx:3:15" />;
506
+ }
507
+ `),
508
+ )
509
+ })
510
+
511
+ it('props destructured and collected with a different name even on custom components even if exported', () => {
512
+ const output = removeEmptySpace(
513
+ addSourceToJsx(
514
+ `
515
+ function test({ children, ...rest }) {
516
+ return <CustomButton children={children} {...rest} />
517
+ }
518
+ `,
519
+ 'test.jsx',
520
+ ).code,
521
+ )
522
+ expect(output).toBe(
523
+ removeEmptySpace(`
524
+ function test({ children, ...rest }) {
525
+ return <CustomButton children={children} {...rest} />
526
+ }
527
+ `),
528
+ )
529
+ })
530
+
531
+ it('props destructured and collected even on custom components even if exported', () => {
532
+ const output = removeEmptySpace(
533
+ addSourceToJsx(
534
+ `
535
+ function test({ ...props }) {
536
+ return <CustomButton children={props.children} />
537
+ }
538
+ `,
539
+ 'test.jsx',
540
+ ).code,
541
+ )
542
+ expect(output).toBe(
543
+ removeEmptySpace(`
544
+ function test({ ...props }) {
545
+ return <CustomButton children={props.children} data-tsd-source="test.jsx:3:15" />;
546
+ }
547
+ `),
548
+ )
549
+ })
550
+ })
551
+ describe('variable declared functions', () => {
552
+ it('works with function and props not destructured', () => {
553
+ const output = removeEmptySpace(
554
+ addSourceToJsx(
555
+ `
556
+ const ButtonWithProps = function test(props){
557
+ return <button children={props.children} />
558
+ }
559
+ `,
560
+ 'test.jsx',
561
+ ).code,
562
+ )
563
+ expect(output).toBe(
564
+ removeEmptySpace(`
565
+ const ButtonWithProps = function test(props) {
566
+ return <button children={props.children} data-tsd-source="test.jsx:3:15" />;
567
+ };
568
+ `),
569
+ )
570
+ })
571
+
572
+ it("doesn't transform when props are spread across the element", () => {
573
+ const output = removeEmptySpace(
574
+ addSourceToJsx(
575
+ `
576
+ const ButtonWithProps = function test(props) {
577
+ return <button {...props} />
578
+ }
579
+ `,
580
+ 'test.jsx',
581
+ ).code,
582
+ )
583
+ expect(output).toBe(
584
+ removeEmptySpace(`
585
+ const ButtonWithProps = function test(props) {
586
+ return <button {...props} />
587
+ }
588
+ `),
589
+ )
590
+ })
591
+
592
+ it("doesn't transform when props are spread across the element but applies to other elements without any props", () => {
593
+ const output = removeEmptySpace(
594
+ addSourceToJsx(
595
+ `
596
+ const ButtonWithProps = function test(props) {
597
+ return (<div>
598
+ <button {...props} />
599
+ </div>)
600
+ }
601
+ `,
602
+ 'test.jsx',
603
+ ).code,
604
+ )
605
+ expect(output).toBe(
606
+ removeEmptySpace(`
607
+ const ButtonWithProps = function test(props) {
608
+ return <div data-tsd-source="test.jsx:3:16">
609
+ <button {...props} />
610
+ </div>;
611
+ };
612
+ `),
613
+ )
614
+ })
615
+
616
+ it("doesn't transform when props are spread across the element but applies to other elements without any props even when props are destructured", () => {
617
+ const output = removeEmptySpace(
618
+ addSourceToJsx(
619
+ `
620
+ const ButtonWithProps = function test({...props}) {
621
+ return (<div>
622
+ <button {...props} />
623
+ </div>)
624
+ }
625
+ `,
626
+ 'test.jsx',
627
+ ).code,
628
+ )
629
+ expect(output).toBe(
630
+ removeEmptySpace(`
631
+ const ButtonWithProps = function test({...props}) {
632
+ return <div data-tsd-source="test.jsx:3:16">
633
+ <button {...props} />
634
+ </div>;
635
+ };
636
+ `),
637
+ )
638
+ })
639
+
640
+ it("doesn't transform when props are spread across the element but applies to other elements without any props even when props are destructured and name is different", () => {
641
+ const output = removeEmptySpace(
642
+ addSourceToJsx(
643
+ `
644
+ const ButtonWithProps = function test({...rest}) {
645
+ return (<div>
646
+ <button {...rest} />
647
+ </div>)
648
+ }
649
+ `,
650
+ 'test.jsx',
651
+ ).code,
652
+ )
653
+ expect(output).toBe(
654
+ removeEmptySpace(`
655
+ const ButtonWithProps = function test({...rest}) {
656
+ return <div data-tsd-source="test.jsx:3:16">
657
+ <button {...rest} />
658
+ </div>;
659
+ };
660
+ `),
661
+ )
662
+ })
663
+
664
+ it(' props destructured and collected with a different name', () => {
665
+ const output = removeEmptySpace(
666
+ addSourceToJsx(
667
+ `
668
+ const ButtonWithProps = function test({ children, ...rest }) {
669
+ return <button children={children} {...rest} />
670
+ }
671
+ `,
672
+ 'test.jsx',
673
+ ).code,
674
+ )
675
+ expect(output).toBe(
676
+ removeEmptySpace(`
677
+ const ButtonWithProps = function test({ children, ...rest }) {
678
+ return <button children={children} {...rest} />
679
+ }
680
+ `),
681
+ )
682
+ })
683
+
684
+ it(' props destructured and collected', () => {
685
+ const output = removeEmptySpace(
686
+ addSourceToJsx(
687
+ `
688
+ const ButtonWithProps = function test({ ...props }) {
689
+ return <button children={props.children} />
690
+ }
691
+ `,
692
+ 'test.jsx',
693
+ ).code,
694
+ )
695
+ expect(output).toBe(
696
+ removeEmptySpace(`
697
+ const ButtonWithProps = function test({ ...props }) {
698
+ return <button children={props.children} data-tsd-source="test.jsx:3:15" />;
699
+ };
700
+ `),
701
+ )
702
+ })
703
+
704
+ it('props destructured and collected with a different name even on custom components', () => {
705
+ const output = removeEmptySpace(
706
+ addSourceToJsx(
707
+ `
708
+ const ButtonWithProps = function test({ children, ...rest }) {
709
+ return <CustomButton children={children} {...rest} />
710
+ }
711
+ `,
712
+ 'test.jsx',
713
+ ).code,
714
+ )
715
+ expect(output).toBe(
716
+ removeEmptySpace(`
717
+ const ButtonWithProps = function test({ children, ...rest }) {
718
+ return <CustomButton children={children} {...rest} />
719
+ }
720
+ `),
721
+ )
722
+ })
723
+
724
+ it('props destructured and collected even on custom components', () => {
725
+ const output = removeEmptySpace(
726
+ addSourceToJsx(
727
+ `
728
+ const ButtonWithProps = function test({ ...props }) {
729
+ return <CustomButton children={props.children} />
730
+ }
731
+ `,
732
+ 'test.jsx',
733
+ ).code,
734
+ )
735
+ expect(output).toBe(
736
+ removeEmptySpace(`
737
+ const ButtonWithProps = function test({ ...props }) {
738
+ return <CustomButton children={props.children} data-tsd-source="test.jsx:3:15" />;
739
+ };
740
+ `),
741
+ )
742
+ })
743
+
744
+ it('props destructured and collected with a different name even on custom components even if exported', () => {
745
+ const output = removeEmptySpace(
746
+ addSourceToJsx(
747
+ `
748
+ export const ButtonWithProps = function test({ children, ...rest }) {
749
+ return <CustomButton children={children} {...rest} />
750
+ }
751
+ `,
752
+ 'test.jsx',
753
+ ).code,
754
+ )
755
+ expect(output).toBe(
756
+ removeEmptySpace(`
757
+ export const ButtonWithProps = function test({ children, ...rest }) {
758
+ return <CustomButton children={children} {...rest} />
759
+ }
760
+ `),
761
+ )
762
+ })
763
+
764
+ it('props destructured and collected even on custom components even if exported', () => {
765
+ const output = removeEmptySpace(
766
+ addSourceToJsx(
767
+ `
768
+ export const ButtonWithProps = function test({ ...props }) {
769
+ return <CustomButton children={props.children} />
770
+ }
771
+ `,
772
+ 'test.jsx',
773
+ ).code,
774
+ )
775
+ expect(output).toBe(
776
+ removeEmptySpace(`
777
+ export const ButtonWithProps = function test({ ...props }) {
778
+ return <CustomButton children={props.children} data-tsd-source="test.jsx:3:15" />;
779
+ };
780
+ `),
781
+ )
782
+ })
783
+ })
784
+ describe('arrow functions', () => {
785
+ it('works with arrow function and props not destructured', () => {
786
+ const output = removeEmptySpace(
787
+ addSourceToJsx(
788
+ `
789
+ const ButtonWithProps = (props) => {
790
+ return <button children={props.children} />
791
+ }
792
+ `,
793
+ 'test.jsx',
794
+ ).code,
795
+ )
796
+ expect(output).toBe(
797
+ removeEmptySpace(`
798
+ const ButtonWithProps = props => {
799
+ return <button children={props.children} data-tsd-source="test.jsx:3:15" />;
800
+ };
801
+ `),
802
+ )
803
+ })
804
+
805
+ it("doesn't transform when props are spread across the element", () => {
806
+ const output = removeEmptySpace(
807
+ addSourceToJsx(
808
+ `
809
+ const ButtonWithProps = (props) => {
810
+ return <button {...props} />
811
+ }
812
+ `,
813
+ 'test.jsx',
814
+ ).code,
815
+ )
816
+ expect(output).toBe(
817
+ removeEmptySpace(`
818
+ const ButtonWithProps = (props) => {
819
+ return <button {...props} />
820
+ }
821
+ `),
822
+ )
823
+ })
824
+
825
+ it("doesn't transform when props are spread across the element but applies to other elements without any props", () => {
826
+ const output = removeEmptySpace(
827
+ addSourceToJsx(
828
+ `
829
+ const ButtonWithProps = (props) => {
830
+ return (<div>
831
+ <button {...props} />
832
+ </div>)
833
+ }
834
+ `,
835
+ 'test.jsx',
836
+ ).code,
837
+ )
838
+ expect(output).toBe(
839
+ removeEmptySpace(`
840
+ const ButtonWithProps = props => {
841
+ return <div data-tsd-source="test.jsx:3:16">
842
+ <button {...props} />
843
+ </div>;
844
+ };
845
+ `),
846
+ )
847
+ })
848
+
849
+ it("doesn't transform when props are spread across the element but applies to other elements without any props even when props are destructured", () => {
850
+ const output = removeEmptySpace(
851
+ addSourceToJsx(
852
+ `
853
+ const ButtonWithProps = ({...props}) => {
854
+ return (<div>
855
+ <button {...props} />
856
+ </div>)
857
+ }
858
+ `,
859
+ 'test.jsx',
860
+ ).code,
861
+ )
862
+ expect(output).toBe(
863
+ removeEmptySpace(`
864
+ const ButtonWithProps = ({...props}) => {
865
+ return <div data-tsd-source="test.jsx:3:16">
866
+ <button {...props} />
867
+ </div>;
868
+ };
869
+ `),
870
+ )
871
+ })
872
+
873
+ it("doesn't transform when props are spread across the element but applies to other elements without any props even when props are destructured and name is different", () => {
874
+ const output = removeEmptySpace(
875
+ addSourceToJsx(
876
+ `
877
+ const ButtonWithProps = ({...rest}) => {
878
+ return (<div>
879
+ <button {...rest} />
880
+ </div>)
881
+ }
882
+ `,
883
+ 'test.jsx',
884
+ ).code,
885
+ )
886
+ expect(output).toBe(
887
+ removeEmptySpace(`
888
+ const ButtonWithProps = ({...rest}) => {
889
+ return <div data-tsd-source= "test.jsx:3:16">
890
+ <button {...rest} />
891
+ </div>;
892
+ };
893
+ `),
894
+ )
895
+ })
896
+
897
+ it('works with arrow function and props destructured and collected with a different name', () => {
898
+ const output = removeEmptySpace(
899
+ addSourceToJsx(
900
+ `
901
+ const ButtonWithProps = ({ children, ...rest }) => {
902
+ return <button children={children} />
903
+ }
904
+ `,
905
+ 'test.jsx',
906
+ ).code,
907
+ )
908
+ expect(output).toBe(
909
+ removeEmptySpace(`
910
+ const ButtonWithProps = ({ children, ...rest }) => {
911
+ return <button children={children} data-tsd-source="test.jsx:3:15" />;
912
+ };
913
+ `),
914
+ )
915
+ })
916
+
917
+ it('works with arrow function and props destructured and collected', () => {
918
+ const output = removeEmptySpace(
919
+ addSourceToJsx(
920
+ `
921
+ const ButtonWithProps = ({ ...props }) => {
922
+ return <button children={props.children} />
923
+ }
924
+ `,
925
+ 'test.jsx',
926
+ ).code,
927
+ )
928
+ expect(output).toBe(
929
+ removeEmptySpace(`
930
+ const ButtonWithProps = ({ ...props }) => {
931
+ return <button children={props.children} data-tsd-source="test.jsx:3:15" />;
932
+ };
933
+ `),
934
+ )
935
+ })
936
+
937
+ it('works with arrow function and props destructured and collected with a different name even on custom components', () => {
938
+ const output = removeEmptySpace(
939
+ addSourceToJsx(
940
+ `
941
+ const ButtonWithProps = ({ children, ...rest }) => {
942
+ return <CustomButton children={children} {...rest} />
943
+ }
944
+ `,
945
+ 'test.jsx',
946
+ ).code,
947
+ )
948
+ expect(output).toBe(
949
+ removeEmptySpace(`
950
+ const ButtonWithProps = ({ children, ...rest }) => {
951
+ return <CustomButton children={children} {...rest} />
952
+ }
953
+ `),
954
+ )
955
+ })
956
+
957
+ it('works with arrow function and props destructured and collected even on custom components', () => {
958
+ const output = removeEmptySpace(
959
+ addSourceToJsx(
960
+ `
961
+ const ButtonWithProps = ({ ...props }) => {
962
+ return <CustomButton children={props.children} />
963
+ }
964
+ `,
965
+ 'test.jsx',
966
+ ).code,
967
+ )
968
+ expect(output).toBe(
969
+ removeEmptySpace(`
970
+ const ButtonWithProps = ({ ...props }) => {
971
+ return <CustomButton children={props.children} data-tsd-source="test.jsx:3:15" />;
972
+ };
973
+ `),
974
+ )
975
+ })
976
+
977
+ it('works with arrow function and props destructured and collected with a different name even on custom components even if exported', () => {
978
+ const output = removeEmptySpace(
979
+ addSourceToJsx(
980
+ `
981
+ export const ButtonWithProps = ({ children, ...rest }) => {
982
+ return <CustomButton children={children} {...rest} />
983
+ }
984
+ `,
985
+ 'test.jsx',
986
+ ).code,
987
+ )
988
+ expect(output).toBe(
989
+ removeEmptySpace(`
990
+ export const ButtonWithProps = ({ children, ...rest }) => {
991
+ return <CustomButton children={children} {...rest} />
992
+ }
993
+ `),
994
+ )
995
+ })
996
+
997
+ it('works with arrow function and props destructured and collected even on custom components even if exported', () => {
998
+ const output = removeEmptySpace(
999
+ addSourceToJsx(
1000
+ `
1001
+ export const ButtonWithProps = ({ ...props }) => {
1002
+ return <CustomButton children={props.children} />
1003
+ }
1004
+ `,
1005
+ 'test.jsx',
1006
+ ).code,
1007
+ )
1008
+ expect(output).toBe(
1009
+ removeEmptySpace(`
1010
+ export const ButtonWithProps = ({ ...props }) => {
1011
+ return <CustomButton children={props.children} data-tsd-source="test.jsx:3:15" />;
1012
+ };
1013
+ `),
1014
+ )
1015
+ })
1016
+ })
1017
+ })