vscode-blade-formatter icon indicating copy to clipboard operation
vscode-blade-formatter copied to clipboard

[Formatting Bug]: Array to object into optional chaining

Open stefvw93 opened this issue 1 year ago • 4 comments

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

stefvw93 avatar Jul 20 '23 10:07 stefvw93

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.

image

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 --}}

shufo avatar Jul 20 '23 18:07 shufo

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

github-actions[bot] avatar Sep 19 '23 01:09 github-actions[bot]

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

github-actions[bot] avatar Nov 30 '23 01:11 github-actions[bot]

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

github-actions[bot] avatar Jan 30 '24 01:01 github-actions[bot]

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

github-actions[bot] avatar Apr 04 '24 01:04 github-actions[bot]