vscode-blade-formatter
vscode-blade-formatter copied to clipboard
[Formatting Bug]: Array to object into optional chaining
Platform
MacOS
Template before formatting
<div>
{{ ($value ?: null)?->someProperty }}
</div>
Template after formatting
<div>
{{ ($value ?: null)?->someProperty }}
</div>
Expected Behaviour
Formatting does not break, but vscode shows an error popup:
Parse Error : syntax error, unexpected '?->' (T_NULLSAFE_OBJECT_OPERATOR), expecting ';' on line 1 > 1 | <?php echo ($value ?: null)?->someProperty ?> | ^
Relevant log output
No response
It seems php parser used in this package can't parse syntax.
$ node
Welcome to Node.js v16.16.0.
Type ".help" for more information.
> const parser = require('php-parser')
undefined
> const target = `($value ?? null)?->someProperty;`;
undefined
> const eval = parser.parseEval(target)
Uncaught:
[SyntaxError: Parse Error : syntax error, unexpected '?->' (T_NULLSAFE_OBJECT_OPERATOR), expecting ';' on line 1
] {
lineNumber: 1,
fileName: 'eval',
columnNumber: 16
}
refs: https://github.com/glayzzle/php-parser/issues/1003
If there is no other work around syntax, please use Blade Formatter > Format: No PHP Syntax Check
option.
It will suppress syntax error.
Configuration file: .bladeformatterrc.json
{
"noPhpSyntaxCheck": true
}
Or using ignore directive will suppress the error.
{{-- blade-formatter-disable --}}
<div>
{{ ($value ?: null)?->someProperty }}
</div>
{{-- blade-formatter-enable --}}
This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 5 days
This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 5 days
This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 5 days
This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 5 days