File tree Expand file tree Collapse file tree 3 files changed +132
-0
lines changed Expand file tree Collapse file tree 3 files changed +132
-0
lines changed Original file line number Diff line number Diff line change @@ -745,6 +745,16 @@ module.exports = {
745
745
const result = this . node ( "new" ) ;
746
746
this . expect ( this . tok . T_NEW ) && this . next ( ) ;
747
747
let args = [ ] ;
748
+ if ( this . token === "(" ) {
749
+ this . next ( ) ;
750
+ const newExp = this . read_expr ( ) ;
751
+ this . expect ( ")" ) ;
752
+ this . next ( ) ;
753
+ if ( this . token === "(" ) {
754
+ args = this . read_argument_list ( ) ;
755
+ }
756
+ return result ( newExp , args ) ;
757
+ }
748
758
const attrs = this . read_attr_list ( ) ;
749
759
if ( this . token === this . tok . T_CLASS ) {
750
760
const what = this . node ( "class" ) ;
Original file line number Diff line number Diff line change @@ -338,6 +338,122 @@ Program {
338
338
}
339
339
` ;
340
340
341
+ exports [` new result from function 1` ] = `
342
+ Program {
343
+ " children" : [
344
+ ExpressionStatement {
345
+ " expression" : Assign {
346
+ " kind" : " assign" ,
347
+ " left" : Variable {
348
+ " curly" : false ,
349
+ " kind" : " variable" ,
350
+ " name" : " a" ,
351
+ },
352
+ " operator" : " =" ,
353
+ " right" : New {
354
+ " arguments" : [],
355
+ " kind" : " new" ,
356
+ " what" : Call {
357
+ " arguments" : [
358
+ String {
359
+ " isDoubleQuote" : false ,
360
+ " kind" : " string" ,
361
+ " raw" : " 'd'" ,
362
+ " unicode" : false ,
363
+ " value" : " d" ,
364
+ },
365
+ ],
366
+ " kind" : " call" ,
367
+ " what" : Call {
368
+ " arguments" : [
369
+ String {
370
+ " isDoubleQuote" : false ,
371
+ " kind" : " string" ,
372
+ " raw" : " 'c'" ,
373
+ " unicode" : false ,
374
+ " value" : " c" ,
375
+ },
376
+ ],
377
+ " kind" : " call" ,
378
+ " what" : Name {
379
+ " kind" : " name" ,
380
+ " name" : " b" ,
381
+ " resolution" : " uqn" ,
382
+ },
383
+ },
384
+ },
385
+ },
386
+ },
387
+ " kind" : " expressionstatement" ,
388
+ },
389
+ ],
390
+ " errors" : [],
391
+ " kind" : " program" ,
392
+ }
393
+ ` ;
394
+
395
+ exports [` new result from function with arguments 1` ] = `
396
+ Program {
397
+ " children" : [
398
+ ExpressionStatement {
399
+ " expression" : Assign {
400
+ " kind" : " assign" ,
401
+ " left" : Variable {
402
+ " curly" : false ,
403
+ " kind" : " variable" ,
404
+ " name" : " a" ,
405
+ },
406
+ " operator" : " =" ,
407
+ " right" : New {
408
+ " arguments" : [
409
+ String {
410
+ " isDoubleQuote" : false ,
411
+ " kind" : " string" ,
412
+ " raw" : " 'e'" ,
413
+ " unicode" : false ,
414
+ " value" : " e" ,
415
+ },
416
+ ],
417
+ " kind" : " new" ,
418
+ " what" : Call {
419
+ " arguments" : [
420
+ String {
421
+ " isDoubleQuote" : false ,
422
+ " kind" : " string" ,
423
+ " raw" : " 'd'" ,
424
+ " unicode" : false ,
425
+ " value" : " d" ,
426
+ },
427
+ ],
428
+ " kind" : " call" ,
429
+ " what" : Call {
430
+ " arguments" : [
431
+ String {
432
+ " isDoubleQuote" : false ,
433
+ " kind" : " string" ,
434
+ " raw" : " 'c'" ,
435
+ " unicode" : false ,
436
+ " value" : " c" ,
437
+ },
438
+ ],
439
+ " kind" : " call" ,
440
+ " what" : Name {
441
+ " kind" : " name" ,
442
+ " name" : " b" ,
443
+ " resolution" : " uqn" ,
444
+ },
445
+ },
446
+ },
447
+ },
448
+ },
449
+ " kind" : " expressionstatement" ,
450
+ },
451
+ ],
452
+ " errors" : [],
453
+ " kind" : " program" ,
454
+ }
455
+ ` ;
456
+
341
457
exports [` new self 1` ] = `
342
458
Program {
343
459
" children" : [
Original file line number Diff line number Diff line change @@ -79,4 +79,10 @@ describe("new", function () {
79
79
)
80
80
) . toMatchSnapshot ( ) ;
81
81
} ) ;
82
+ it ( "result from function" , function ( ) {
83
+ expect ( parser . parseEval ( "$a = new (b('c')('d'));" ) ) . toMatchSnapshot ( ) ;
84
+ } ) ;
85
+ it ( "result from function with arguments" , function ( ) {
86
+ expect ( parser . parseEval ( "$a = new (b('c')('d'))('e');" ) ) . toMatchSnapshot ( ) ;
87
+ } ) ;
82
88
} ) ;
You can’t perform that action at this time.
0 commit comments