BladeOne icon indicating copy to clipboard operation
BladeOne copied to clipboard

Blade comment between switch & case statement gives error...

Open AzzaAzza69 opened this issue 1 year ago • 2 comments

eg.

@switch($expr)
  {{-- test comment --}}
  @case('value')

renders to:

<?php switch ($expr) {
 <?php /* test comment */ ?>
 case ('value'): ?>

which gives "syntax error, unexpected '<', expecting case (T_CASE) or default (T_DEFAULT) or '}'" for the middle line.

AzzaAzza69 avatar Oct 08 '24 09:10 AzzaAzza69

Technically, it is a problem with the PHP parser. It is impossible to deal with this problem without impacting the performance. And since comments aren't so vital, so I added a new field to determine how to work with the comments.

$blade=new BladeOne(null,null,0,2);  // the last 2 means:
// 0: means comments are converted into PHP code.
// 1: means comments are converted into HTML comments <-- some comment -->
// 2: means that comments are ignored, so it won't crash "try/case" blocks

https://github.com/EFTEC/BladeOne/releases/tag/4.14

jorgecc avatar Oct 08 '24 14:10 jorgecc

It was a conversion of a Laravel project -> BladeOne and it would appear that Laravel just stripped out comments. Thanks for the config setting.

AzzaAzza69 avatar Oct 10 '24 08:10 AzzaAzza69

Can confirm the setting (2) works

AzzaAzza69 avatar Mar 27 '25 10:03 AzzaAzza69