Skip to content

Commit a871cad

Browse files
feat: correctly parse and format 8.4 syntax
1 parent 0fc6754 commit a871cad

File tree

3 files changed

+28
-3
lines changed

3 files changed

+28
-3
lines changed

src/parser.mjs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,16 @@ function parse(text, opts) {
1010
// Todo https://github.com/glayzzle/php-parser/issues/170
1111
text = text.replace(/\?>\n<\?/g, "?>\n___PSEUDO_INLINE_PLACEHOLDER___<?");
1212

13+
const parserOpts = Object.assign(
14+
{ extractDoc: true },
15+
// only pass the version if user requested 8.4 syntax; parser is stricter
16+
// about allowed syntax than we are and currenly defaults to support for 8.3
17+
opts && opts.phpVersion === "8.4" ? { version: opts.phpVersion } : {}
18+
);
19+
1320
// initialize a new parser instance
1421
const parser = new engine({
15-
parser: {
16-
extractDoc: true,
17-
},
22+
parser: parserOpts,
1823
ast: {
1924
withPositions: true,
2025
withSource: true,

tests/new84/__snapshots__/jsfmt.spec.mjs.snap

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,24 @@ new Foo->prop;
1313
new Foo->method();
1414
new Foo->$var;
1515
16+
new A()
17+
->b()
18+
->c()
19+
->d();
20+
21+
$asdf =
22+
new A()->b() ->c();
23+
1624
=====================================output=====================================
1725
<?php
1826
1927
new Foo()->prop;
2028
new Foo()->method();
2129
new Foo()->$var;
2230
31+
new A()->b()->c()->d();
32+
33+
$asdf = new A()->b()->c();
34+
2335
================================================================================
2436
`;

tests/new84/new84.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,11 @@
33
new Foo->prop;
44
new Foo->method();
55
new Foo->$var;
6+
7+
new A()
8+
->b()
9+
->c()
10+
->d();
11+
12+
$asdf =
13+
new A()->b() ->c();

0 commit comments

Comments
 (0)