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

Syntax Error on multilined class constant with comment #1151

Open
shufo opened this issue Jan 12, 2025 · 0 comments · May be fixed by #1152
Open

Syntax Error on multilined class constant with comment #1151

shufo opened this issue Jan 12, 2025 · 0 comments · May be fixed by #1152
Labels

Comments

@shufo
Copy link

shufo commented Jan 12, 2025

/cc @genintho

Context

Problem

e.g.

<?php

$var = new class {
    public
    const
    CONSTANT
    // Comment 3
    =
    'string';
};

How to reproduce

  • create test file

vim test.js

const engine = require(".");

// initialize a new parser instance
const parser = new engine({
  // some options :
  parser: {
    extractDoc: true,
    phpVersion: "8.3",
  },
  ast: {
    withPositions: true,
    withSource: true,
  },
});

const target = `
<?php

$var = new class {
    public
    const
    CONSTANT
    // Comment 3
    =
    'string';
};
`;

// Retrieve the AST from the specified source
parser.parseCode(target);
  • execute
$ node test.js
/home/shuhei/develop/php-parser/src/parser.js:357
    throw err;
    ^

SyntaxError: Parse Error : syntax error, unexpected '=' on line 11
    at Parser.raiseError (/home/shuhei/develop/php-parser/src/parser.js:349:17)
    at Parser.error (/home/shuhei/develop/php-parser/src/parser.js:397:15)
    at Parser.expect (/home/shuhei/develop/php-parser/src/parser.js:577:10)
    at Parser.read_constant_declaration (/home/shuhei/develop/php-parser/src/parser/class.js:262:16)
    at Parser.read_list (/home/shuhei/develop/php-parser/src/parser/utils.js:76:33)
    at Parser.read_constant_list (/home/shuhei/develop/php-parser/src/parser/class.js:234:24)
    at Parser.read_class_body (/home/shuhei/develop/php-parser/src/parser/class.js:117:32)
    at Parser.read_new_expr (/home/shuhei/develop/php-parser/src/parser/expr.js:769:28)
    at Parser.read_expr_item (/home/shuhei/develop/php-parser/src/parser/expr.js:353:21)
    at Parser.read_expr (/home/shuhei/develop/php-parser/src/parser/expr.js:18:19) {
  lineNumber: 11,
  fileName: 'eval',
  columnNumber: 4
}

Node.js v20.12.2
@cseufert cseufert added the bug label Jan 13, 2025
shufo added a commit to shufo/php-parser that referenced this issue Jan 13, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants