Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unexpected syntax error when nullsafe object operator used with parentheses #1127

Open
shufo opened this issue Jul 21, 2023 · 0 comments
Open

Comments

@shufo
Copy link

shufo commented Jul 21, 2023

Context

Problems

When php code like ($value ?: null)?->someProperty; passed to parser, it throws unexpected Syntax exception.

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

But its syntax is valid in php.

 $  php -v
PHP 8.1.2-1ubuntu2.10 (cli) (built: Jan 16 2023 15:19:49) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.1.2, Copyright (c) Zend Technologies
    with Zend OPcache v8.1.2-1ubuntu2.10, Copyright (c), by Zend Technologies

 $  cat test.php
<?php
echo ($value ?: null)?->someProperty;

 $  php --syntax-check test.php
No syntax errors detected in test.php

Repro:

test.js

const parser = require(".");
const target = `($value ?: null)?->someProperty;`;
const eval = parser.parseEval(target);
$ node test.js
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant