File tree Expand file tree Collapse file tree 5 files changed +45
-8
lines changed Expand file tree Collapse file tree 5 files changed +45
-8
lines changed Original file line number Diff line number Diff line change @@ -10,11 +10,16 @@ function parse(text, opts) {
10
10
// Todo https://github.com/glayzzle/php-parser/issues/170
11
11
text = text . replace ( / \? > \n < \? / g, "?>\n___PSEUDO_INLINE_PLACEHOLDER___<?" ) ;
12
12
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
+
13
20
// initialize a new parser instance
14
21
const parser = new engine ( {
15
- parser : {
16
- extractDoc : true ,
17
- } ,
22
+ parser : parserOpts ,
18
23
ast : {
19
24
withPositions : true ,
20
25
withSource : true ,
Original file line number Diff line number Diff line change @@ -774,11 +774,12 @@ function printBinaryExpression(
774
774
parts . push ( print ( "left" ) ) ;
775
775
}
776
776
777
- const shouldInline = shouldInlineLogicalExpression ( node ) ;
778
-
779
- const right = shouldInline
780
- ? [ node . type , " " , print ( "right" ) ]
781
- : [ node . type , line , print ( "right" ) ] ;
777
+ const right =
778
+ node . left . kind === "new" && node . type !== "."
779
+ ? [ node . type , print ( "right" ) ]
780
+ : shouldInlineLogicalExpression ( node )
781
+ ? [ node . type , " " , print ( "right" ) ]
782
+ : [ node . type , line , print ( "right" ) ] ;
782
783
783
784
// If there's only a single binary expression, we want to create a group
784
785
// in order to avoid having a small right part like -1 be on its own line.
@@ -794,6 +795,7 @@ function printBinaryExpression(
794
795
795
796
const shouldNotHaveWhitespace =
796
797
isDocNode ( node . left ) ||
798
+ ( node . left . kind === "new" && node . type !== "." ) ||
797
799
( node . left . kind === "bin" && isDocNode ( node . left . right ) ) ;
798
800
799
801
parts . push (
Original file line number Diff line number Diff line change
1
+ // Jest Snapshot v1, https://goo.gl/fbAQLP
2
+
3
+ exports [` new84.php 1` ] = `
4
+ ====================================options=====================================
5
+ parsers: ["php"]
6
+ phpVersion: "8.4"
7
+ printWidth: 80
8
+ | printWidth
9
+ =====================================input======================================
10
+ <?php
11
+
12
+ new Foo->prop;
13
+ new Foo->method();
14
+ new Foo->$var;
15
+
16
+ =====================================output=====================================
17
+ <?php
18
+
19
+ new Foo()->prop;
20
+ new Foo()->method();
21
+ new Foo()->$var;
22
+
23
+ ================================================================================
24
+ ` ;
Original file line number Diff line number Diff line change
1
+ run_spec ( import . meta, [ "php" ] , { phpVersion : "8.4" } ) ;
Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ new Foo ->prop;
4
+ new Foo ->method ();
5
+ new Foo ->$ var ;
You can’t perform that action at this time.
0 commit comments