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) {
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 ,
Original file line number Diff line number Diff line change @@ -774,11 +774,12 @@ function printBinaryExpression(
774774 parts . push ( print ( "left" ) ) ;
775775 }
776776
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" ) ] ;
782783
783784 // If there's only a single binary expression, we want to create a group
784785 // in order to avoid having a small right part like -1 be on its own line.
@@ -794,6 +795,7 @@ function printBinaryExpression(
794795
795796 const shouldNotHaveWhitespace =
796797 isDocNode ( node . left ) ||
798+ ( node . left . kind === "new" && node . type !== "." ) ||
797799 ( node . left . kind === "bin" && isDocNode ( node . left . right ) ) ;
798800
799801 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