@@ -149,8 +149,7 @@ pub fn preprocess(content: &str) -> (String, BladeSourceMap) {
149149 ) {
150150 // These are conditional blocks: if args present, skip them;
151151 // if no args, emit directly.
152- let after_dir: String =
153- rest_str[ directive. len ( ) ..] . chars ( ) . collect ( ) ;
152+ let after_dir: String = rest_str[ directive. len ( ) ..] . chars ( ) . collect ( ) ;
154153 let after_trimmed = after_dir. trim_start ( ) ;
155154 if after_trimmed. starts_with ( '(' ) {
156155 replacement = " if (true) " . to_string ( ) ;
@@ -162,16 +161,13 @@ pub fn preprocess(content: &str) -> (String, BladeSourceMap) {
162161 }
163162 } else if matches ! ( directive, "foreach" | "forelse" ) {
164163 replacement = format ! ( " {} " , translate_directive( directive) ) ;
165- next_mode = Mode :: DirectiveArgs ( ": /** @var object{index: int, iteration: int, remaining: int, count: int, first: bool, last: bool, even: bool, odd: bool, depth: int, parent: ?object} $loop */ $loop = (object)[];" ) ;
164+ next_mode = Mode :: DirectiveArgs (
165+ ": /** @var object{index: int, iteration: int, remaining: int, count: int, first: bool, last: bool, even: bool, odd: bool, depth: int, parent: ?object} $loop */ $loop = (object)[];" ,
166+ ) ;
166167 paren_depth = 0 ;
167168 } else if matches ! (
168169 directive,
169- "if" | "elseif"
170- | "for"
171- | "while"
172- | "switch"
173- | "unless"
174- | "isset"
170+ "if" | "elseif" | "for" | "while" | "switch" | "unless" | "isset"
175171 ) {
176172 replacement = format ! ( " {} " , translate_directive( directive) ) ;
177173 next_mode = Mode :: DirectiveArgs ( ":" ) ; // Directive Args
@@ -450,7 +446,11 @@ mod tests {
450446 fn test_preprocess_foreach_loop_variable ( ) {
451447 let content = "@foreach($items as $item)\n {{ $loop->first }}\n @endforeach\n " ;
452448 let ( php, _) = preprocess ( content) ;
453- assert ! ( php. contains( "$loop" ) , "should inject $loop variable: {}" , php) ;
449+ assert ! (
450+ php. contains( "$loop" ) ,
451+ "should inject $loop variable: {}" ,
452+ php
453+ ) ;
454454 assert ! (
455455 php. contains( "object{index: int" ) ,
456456 "should have typed $loop: {}" ,
@@ -459,14 +459,22 @@ mod tests {
459459 // $loop should be declared before its usage
460460 let loop_decl = php. find ( "$loop = (object)[];" ) . unwrap ( ) ;
461461 let loop_use = php. rfind ( "$loop" ) . unwrap ( ) ;
462- assert ! ( loop_use > loop_decl, "$loop usage after declaration: {}" , php) ;
462+ assert ! (
463+ loop_use > loop_decl,
464+ "$loop usage after declaration: {}" ,
465+ php
466+ ) ;
463467 }
464468
465469 #[ test]
466470 fn test_preprocess_forelse_loop_variable ( ) {
467471 let content = "@forelse($items as $item)\n {{ $loop->index }}\n @empty\n @endforelse\n " ;
468472 let ( php, _) = preprocess ( content) ;
469- assert ! ( php. contains( "$loop = (object)[];" ) , "forelse should also inject $loop: {}" , php) ;
473+ assert ! (
474+ php. contains( "$loop = (object)[];" ) ,
475+ "forelse should also inject $loop: {}" ,
476+ php
477+ ) ;
470478 }
471479
472480 #[ test]
@@ -512,54 +520,104 @@ mod tests {
512520 eprintln ! ( "{:2}: {}" , i, line) ;
513521 }
514522 assert ! ( php. contains( "foreach" ) , "should contain foreach: {}" , php) ;
515- assert ! ( php. contains( "endforeach" ) , "should contain endforeach: {}" , php) ;
516- assert ! ( php. contains( "if (false):" ) , "should contain if (false): {}" , php) ;
523+ assert ! (
524+ php. contains( "endforeach" ) ,
525+ "should contain endforeach: {}" ,
526+ php
527+ ) ;
528+ assert ! (
529+ php. contains( "if (false):" ) ,
530+ "should contain if (false): {}" ,
531+ php
532+ ) ;
517533 assert ! ( php. contains( "endif;" ) , "should contain endif: {}" , php) ;
518534 }
519535
520536 #[ test]
521537 fn test_preprocess_session_directive ( ) {
522538 let content = "@session('key')\n <p>{{ $value }}</p>\n @endsession\n " ;
523539 let ( php, _) = preprocess ( content) ;
524- assert ! ( php. contains( "if (true)" ) , "should contain if (true): {}" , php) ;
525- assert ! ( php. contains( "$value = '';" ) , "should inject $value: {}" , php) ;
540+ assert ! (
541+ php. contains( "if (true)" ) ,
542+ "should contain if (true): {}" ,
543+ php
544+ ) ;
545+ assert ! (
546+ php. contains( "$value = '';" ) ,
547+ "should inject $value: {}" ,
548+ php
549+ ) ;
526550 assert ! ( php. contains( "endif;" ) , "should contain endif: {}" , php) ;
527551 }
528552
529553 #[ test]
530554 fn test_preprocess_verbatim ( ) {
531- let content = "@verbatim\n {{ $name }}\n @if(true)\n @endverbatim\n <p>{{ $real }}</p>\n " ;
555+ let content =
556+ "@verbatim\n {{ $name }}\n @if(true)\n @endverbatim\n <p>{{ $real }}</p>\n " ;
532557 let ( php, _) = preprocess ( content) ;
533558 // The {{ $name }} inside verbatim should NOT produce echo
534- assert ! ( !php. contains( "$name" ) , "verbatim content should be skipped: {}" , php) ;
559+ assert ! (
560+ !php. contains( "$name" ) ,
561+ "verbatim content should be skipped: {}" ,
562+ php
563+ ) ;
535564 // The {{ $real }} after @endverbatim should work normally
536- assert ! ( php. contains( "$real" ) , "content after endverbatim should work: {}" , php) ;
565+ assert ! (
566+ php. contains( "$real" ) ,
567+ "content after endverbatim should work: {}" ,
568+ php
569+ ) ;
537570 }
538571
539572 #[ test]
540573 fn test_preprocess_verbatim_with_comment_syntax ( ) {
541574 // Verbatim blocks may contain */ which would break PHP block comments
542- let content = "@verbatim\n {{ /* js comment */ value }}\n @endverbatim\n <p>{{ $after }}</p>\n " ;
575+ let content =
576+ "@verbatim\n {{ /* js comment */ value }}\n @endverbatim\n <p>{{ $after }}</p>\n " ;
543577 let ( php, _) = preprocess ( content) ;
544- assert ! ( !php. contains( "js comment" ) , "verbatim content should be skipped: {}" , php) ;
545- assert ! ( php. contains( "$after" ) , "content after endverbatim should work: {}" , php) ;
578+ assert ! (
579+ !php. contains( "js comment" ) ,
580+ "verbatim content should be skipped: {}" ,
581+ php
582+ ) ;
583+ assert ! (
584+ php. contains( "$after" ) ,
585+ "content after endverbatim should work: {}" ,
586+ php
587+ ) ;
546588 }
547589
548590 #[ test]
549591 fn test_preprocess_error_directive ( ) {
550592 let content = "@error('email')\n <p>{{ $message }}</p>\n @enderror\n " ;
551593 let ( php, _) = preprocess ( content) ;
552- assert ! ( php. contains( "if (true)" ) , "should contain if (true): {}" , php) ;
553- assert ! ( php. contains( "$message = '';" ) , "should inject $message: {}" , php) ;
594+ assert ! (
595+ php. contains( "if (true)" ) ,
596+ "should contain if (true): {}" ,
597+ php
598+ ) ;
599+ assert ! (
600+ php. contains( "$message = '';" ) ,
601+ "should inject $message: {}" ,
602+ php
603+ ) ;
554604 assert ! ( php. contains( "endif;" ) , "should contain endif: {}" , php) ;
555605 }
556606
557607 #[ test]
558608 fn test_preprocess_context_directive ( ) {
559609 let content = "@context('key')\n <p>{{ $value }}</p>\n @endcontext\n " ;
560610 let ( php, _) = preprocess ( content) ;
561- assert ! ( php. contains( "if (true)" ) , "should contain if (true): {}" , php) ;
562- assert ! ( php. contains( "$value = '';" ) , "should inject $value: {}" , php) ;
611+ assert ! (
612+ php. contains( "if (true)" ) ,
613+ "should contain if (true): {}" ,
614+ php
615+ ) ;
616+ assert ! (
617+ php. contains( "$value = '';" ) ,
618+ "should inject $value: {}" ,
619+ php
620+ ) ;
563621 assert ! ( php. contains( "endif;" ) , "should contain endif: {}" , php) ;
564622 }
565623
@@ -606,46 +664,98 @@ mod tests {
606664 // @auth without args should produce if (true):
607665 let content = "@auth\n <p>logged in</p>\n @endauth\n " ;
608666 let ( php, _) = preprocess ( content) ;
609- assert ! ( php. contains( "if (true):" ) , "@auth should produce if (true):: {}" , php) ;
610- assert ! ( php. contains( "endif;" ) , "@endauth should produce endif;: {}" , php) ;
667+ assert ! (
668+ php. contains( "if (true):" ) ,
669+ "@auth should produce if (true):: {}" ,
670+ php
671+ ) ;
672+ assert ! (
673+ php. contains( "endif;" ) ,
674+ "@endauth should produce endif;: {}" ,
675+ php
676+ ) ;
611677
612678 // @auth with args should also produce if (true):
613679 let content = "@auth('admin')\n <p>admin</p>\n @endauth\n " ;
614680 let ( php, _) = preprocess ( content) ;
615- assert ! ( php. contains( "if (true)" ) , "@auth('admin') should produce if (true): {}" , php) ;
616- assert ! ( php. contains( "endif;" ) , "@endauth should produce endif;: {}" , php) ;
681+ assert ! (
682+ php. contains( "if (true)" ) ,
683+ "@auth('admin') should produce if (true): {}" ,
684+ php
685+ ) ;
686+ assert ! (
687+ php. contains( "endif;" ) ,
688+ "@endauth should produce endif;: {}" ,
689+ php
690+ ) ;
617691
618692 // @guest without args
619693 let content = "@guest\n <p>guest</p>\n @endguest\n " ;
620694 let ( php, _) = preprocess ( content) ;
621- assert ! ( php. contains( "if (true):" ) , "@guest should produce if (true):: {}" , php) ;
622- assert ! ( php. contains( "endif;" ) , "@endguest should produce endif;: {}" , php) ;
695+ assert ! (
696+ php. contains( "if (true):" ) ,
697+ "@guest should produce if (true):: {}" ,
698+ php
699+ ) ;
700+ assert ! (
701+ php. contains( "endif;" ) ,
702+ "@endguest should produce endif;: {}" ,
703+ php
704+ ) ;
623705
624706 // @production (never takes args)
625707 let content = "@production\n <p>prod</p>\n @endproduction\n " ;
626708 let ( php, _) = preprocess ( content) ;
627- assert ! ( php. contains( "if (true):" ) , "@production should produce if (true):: {}" , php) ;
628- assert ! ( php. contains( "endif;" ) , "@endproduction should produce endif;: {}" , php) ;
709+ assert ! (
710+ php. contains( "if (true):" ) ,
711+ "@production should produce if (true):: {}" ,
712+ php
713+ ) ;
714+ assert ! (
715+ php. contains( "endif;" ) ,
716+ "@endproduction should produce endif;: {}" ,
717+ php
718+ ) ;
629719
630720 // @env with args
631721 let content = "@env('local')\n <p>local</p>\n @endenv\n " ;
632722 let ( php, _) = preprocess ( content) ;
633- assert ! ( php. contains( "if (true)" ) , "@env should produce if (true): {}" , php) ;
634- assert ! ( php. contains( "endif;" ) , "@endenv should produce endif;: {}" , php) ;
723+ assert ! (
724+ php. contains( "if (true)" ) ,
725+ "@env should produce if (true): {}" ,
726+ php
727+ ) ;
728+ assert ! (
729+ php. contains( "endif;" ) ,
730+ "@endenv should produce endif;: {}" ,
731+ php
732+ ) ;
635733
636734 // @once without args
637735 let content = "@once\n <script>app.js</script>\n @endonce\n " ;
638736 let ( php, _) = preprocess ( content) ;
639- assert ! ( php. contains( "if (true):" ) , "@once should produce if (true):: {}" , php) ;
640- assert ! ( php. contains( "endif;" ) , "@endonce should produce endif;: {}" , php) ;
737+ assert ! (
738+ php. contains( "if (true):" ) ,
739+ "@once should produce if (true):: {}" ,
740+ php
741+ ) ;
742+ assert ! (
743+ php. contains( "endif;" ) ,
744+ "@endonce should produce endif;: {}" ,
745+ php
746+ ) ;
641747 }
642748
643749 #[ test]
644750 fn test_preprocess_session_value_accessible ( ) {
645751 // $value should be accessible inside @session block
646752 let content = "@session('status')\n {{ $value }}\n @endsession\n " ;
647753 let ( php, _) = preprocess ( content) ;
648- assert ! ( php. contains( "$value = '';" ) , "should declare $value: {}" , php) ;
754+ assert ! (
755+ php. contains( "$value = '';" ) ,
756+ "should declare $value: {}" ,
757+ php
758+ ) ;
649759 // The $value echo should appear after the declaration
650760 let val_decl = php. find ( "$value = '';" ) . unwrap ( ) ;
651761 // Find last occurrence of $value (the echo usage)
@@ -662,7 +772,11 @@ mod tests {
662772 // $message should be accessible inside @error block
663773 let content = "@error('email')\n {{ $message }}\n @enderror\n " ;
664774 let ( php, _) = preprocess ( content) ;
665- assert ! ( php. contains( "$message = '';" ) , "should declare $message: {}" , php) ;
775+ assert ! (
776+ php. contains( "$message = '';" ) ,
777+ "should declare $message: {}" ,
778+ php
779+ ) ;
666780 let msg_decl = php. find ( "$message = '';" ) . unwrap ( ) ;
667781 let msg_echo = php. rfind ( "$message" ) . unwrap ( ) ;
668782 assert ! (
0 commit comments