File tree Expand file tree Collapse file tree 4 files changed +64
-25
lines changed Expand file tree Collapse file tree 4 files changed +64
-25
lines changed Original file line number Diff line number Diff line change @@ -386,7 +386,7 @@ module.exports = {
386386 return [ nullable , type ] ;
387387 } ,
388388
389- peekSkipComments : function ( ) {
389+ peekSkipComments ( ) {
390390 const lexerState = this . lexer . getState ( ) ;
391391 let nextToken ;
392392
Original file line number Diff line number Diff line change @@ -97,14 +97,6 @@ module.exports = {
9797 if ( this . token === this . tok . T_SPACESHIP ) {
9898 return result ( "bin" , "<=>" , expr , this . next ( ) . read_expr ( ) ) ;
9999 }
100- if ( this . token === this . tok . T_OBJECT_OPERATOR ) {
101- if ( this . version < 804 ) {
102- this . raiseError (
103- "New without parenthesis is not allowed before PHP 8.4" ,
104- ) ;
105- }
106- return result ( "bin" , "->" , expr , this . next ( ) . read_expr ( ) ) ;
107- }
108100
109101 if ( this . token === this . tok . T_INSTANCEOF ) {
110102 expr = result (
@@ -359,7 +351,13 @@ module.exports = {
359351 return this . node ( "pre" ) ( "-" , this . next ( ) . read_variable ( false , false ) ) ;
360352
361353 case this . tok . T_NEW :
362- return this . read_new_expr ( ) ;
354+ expr = this . read_new_expr ( ) ;
355+ if ( this . token === this . tok . T_OBJECT_OPERATOR && this . version < 804 ) {
356+ this . raiseError (
357+ "New without parenthesis is not allowed before PHP 8.4" ,
358+ ) ;
359+ }
360+ return this . handleDereferencable ( expr ) ;
363361
364362 case this . tok . T_ISSET :
365363 case this . tok . T_EMPTY :
Original file line number Diff line number Diff line change 1- // Jest Snapshot v1, https://goo.gl/fbAQLP
1+ // Jest Snapshot v1, https://jestjs.io/docs/snapshot-testing
22
33exports [` Test classes 8.4 allow new without parenthesis 1` ] = `
44Program {
55 " children" : [
66 ExpressionStatement {
7- " expression" : Bin {
8- " kind" : " bin" ,
9- " left" : New {
10- " arguments" : [],
11- " kind" : " new" ,
12- " what" : Name {
13- " kind" : " name" ,
14- " name" : " People" ,
15- " resolution" : " uqn" ,
7+ " expression" : Call {
8+ " arguments" : [],
9+ " kind" : " call" ,
10+ " what" : PropertyLookup {
11+ " kind" : " propertylookup" ,
12+ " offset" : Identifier {
13+ " kind" : " identifier" ,
14+ " name" : " name" ,
1615 },
16+ " what" : New {
17+ " arguments" : [],
18+ " kind" : " new" ,
19+ " what" : Name {
20+ " kind" : " name" ,
21+ " name" : " People" ,
22+ " resolution" : " uqn" ,
23+ },
24+ },
25+ },
26+ },
27+ " kind" : " expressionstatement" ,
28+ },
29+ ],
30+ " errors" : [],
31+ " kind" : " program" ,
32+ }
33+ ` ;
34+
35+ exports [` Test classes 8.4 new without parenthesis with array lookup 1` ] = `
36+ Program {
37+ " children" : [
38+ ExpressionStatement {
39+ " expression" : OffsetLookup {
40+ " kind" : " offsetlookup" ,
41+ " offset" : Number {
42+ " kind" : " number" ,
43+ " value" : " 0" ,
1744 },
18- " right " : Call {
45+ " what " : New {
1946 " arguments" : [],
20- " kind" : " call " ,
47+ " kind" : " new " ,
2148 " what" : Name {
2249 " kind" : " name" ,
23- " name" : " name " ,
50+ " name" : " People " ,
2451 " resolution" : " uqn" ,
2552 },
2653 },
27- " type" : " ->" ,
2854 },
2955 " kind" : " expressionstatement" ,
3056 },
Original file line number Diff line number Diff line change @@ -266,10 +266,25 @@ describe("Test classes", function () {
266266 expect ( test_parser . parseEval ( code ) ) . toMatchSnapshot ( ) ;
267267 } ) ;
268268
269+ it ( "8.4 new without parenthesis with array lookup" , ( ) => {
270+ const code = `new People()[0];` ;
271+ const test_parser = parser . create ( {
272+ parser : {
273+ version : "8.4" ,
274+ } ,
275+ } ) ;
276+ expect ( test_parser . parseEval ( code ) ) . toMatchSnapshot ( ) ;
277+ } ) ;
278+
269279 it ( "new without parenthesis throw errors in PHP < 8.4" , ( ) => {
270280 const code = `new People()->name();` ;
281+ const test_parser = parser . create ( {
282+ parser : {
283+ version : "8.3" ,
284+ } ,
285+ } ) ;
271286 expect ( ( ) => {
272- parser . parseEval ( code ) ;
287+ test_parser . parseEval ( code ) ;
273288 } ) . toThrowErrorMatchingSnapshot ( ) ;
274289 } ) ;
275290
You can’t perform that action at this time.
0 commit comments