File tree Expand file tree Collapse file tree 4 files changed +143
-3
lines changed Expand file tree Collapse file tree 4 files changed +143
-3
lines changed Original file line number Diff line number Diff line change @@ -13,7 +13,7 @@ const KIND = "catch";
13
13
* @constructor Catch
14
14
* @extends {Statement }
15
15
* @property {Identifier[] } what
16
- * @property {Variable } variable
16
+ * @property {Variable|null } variable
17
17
* @property {Statement } body
18
18
* @see http://php.net/manual/en/language.exceptions.php
19
19
*/
Original file line number Diff line number Diff line change @@ -10,7 +10,7 @@ module.exports = {
10
10
* ```ebnf
11
11
* try ::= T_TRY '{' inner_statement* '}'
12
12
* (
13
- * T_CATCH '(' namespace_name variable ')' '{' inner_statement* '}'
13
+ * T_CATCH '(' namespace_name ( variable)? ')' '{' inner_statement* '}'
14
14
* )*
15
15
* (T_FINALLY '{' inner_statement* '}')?
16
16
* ```
@@ -28,7 +28,10 @@ module.exports = {
28
28
const item = this . node ( "catch" ) ;
29
29
this . next ( ) . expect ( "(" ) && this . next ( ) ;
30
30
const what = this . read_list ( this . read_namespace_name , "|" , false ) ;
31
- const variable = this . read_variable ( true , false ) ;
31
+ let variable = null ;
32
+ if ( this . token === this . tok . T_VARIABLE ) {
33
+ variable = this . read_variable ( true , false ) ;
34
+ }
32
35
this . expect ( ")" ) ;
33
36
catches . push ( item ( this . next ( ) . read_statement ( ) , what , variable ) ) ;
34
37
}
Original file line number Diff line number Diff line change @@ -361,6 +361,71 @@ Program {
361
361
}
362
362
` ;
363
363
364
+ exports [` boolean multiple catch without variable 1` ] = `
365
+ Program {
366
+ " children" : Array [
367
+ Try {
368
+ " always" : null ,
369
+ " body" : Block {
370
+ " children" : Array [
371
+ ExpressionStatement {
372
+ " expression" : Call {
373
+ " arguments" : Array [],
374
+ " kind" : " call" ,
375
+ " what" : Name {
376
+ " kind" : " name" ,
377
+ " name" : " call" ,
378
+ " resolution" : " uqn" ,
379
+ },
380
+ },
381
+ " kind" : " expressionstatement" ,
382
+ },
383
+ ],
384
+ " kind" : " block" ,
385
+ },
386
+ " catches" : Array [
387
+ Catch {
388
+ " body" : Block {
389
+ " children" : Array [
390
+ ExpressionStatement {
391
+ " expression" : Call {
392
+ " arguments" : Array [],
393
+ " kind" : " call" ,
394
+ " what" : Name {
395
+ " kind" : " name" ,
396
+ " name" : " do_something" ,
397
+ " resolution" : " uqn" ,
398
+ },
399
+ },
400
+ " kind" : " expressionstatement" ,
401
+ },
402
+ ],
403
+ " kind" : " block" ,
404
+ },
405
+ " kind" : " catch" ,
406
+ " variable" : null ,
407
+ " what" : Array [
408
+ Name {
409
+ " kind" : " name" ,
410
+ " name" : " MyException" ,
411
+ " resolution" : " uqn" ,
412
+ },
413
+ Name {
414
+ " kind" : " name" ,
415
+ " name" : " MyOtherException" ,
416
+ " resolution" : " uqn" ,
417
+ },
418
+ ],
419
+ },
420
+ ],
421
+ " kind" : " try" ,
422
+ },
423
+ ],
424
+ " errors" : Array [],
425
+ " kind" : " program" ,
426
+ }
427
+ ` ;
428
+
364
429
exports [` boolean qualified name 1` ] = `
365
430
Program {
366
431
" children" : Array [
@@ -552,3 +617,63 @@ Program {
552
617
" kind" : " program" ,
553
618
}
554
619
` ;
620
+
621
+ exports [` boolean without variable 1` ] = `
622
+ Program {
623
+ " children" : Array [
624
+ Try {
625
+ " always" : null ,
626
+ " body" : Block {
627
+ " children" : Array [
628
+ ExpressionStatement {
629
+ " expression" : Call {
630
+ " arguments" : Array [],
631
+ " kind" : " call" ,
632
+ " what" : Name {
633
+ " kind" : " name" ,
634
+ " name" : " call" ,
635
+ " resolution" : " uqn" ,
636
+ },
637
+ },
638
+ " kind" : " expressionstatement" ,
639
+ },
640
+ ],
641
+ " kind" : " block" ,
642
+ },
643
+ " catches" : Array [
644
+ Catch {
645
+ " body" : Block {
646
+ " children" : Array [
647
+ ExpressionStatement {
648
+ " expression" : Call {
649
+ " arguments" : Array [],
650
+ " kind" : " call" ,
651
+ " what" : Name {
652
+ " kind" : " name" ,
653
+ " name" : " do_something" ,
654
+ " resolution" : " uqn" ,
655
+ },
656
+ },
657
+ " kind" : " expressionstatement" ,
658
+ },
659
+ ],
660
+ " kind" : " block" ,
661
+ },
662
+ " kind" : " catch" ,
663
+ " variable" : null ,
664
+ " what" : Array [
665
+ Name {
666
+ " kind" : " name" ,
667
+ " name" : " Exception" ,
668
+ " resolution" : " uqn" ,
669
+ },
670
+ ],
671
+ },
672
+ ],
673
+ " kind" : " try" ,
674
+ },
675
+ ],
676
+ " errors" : Array [],
677
+ " kind" : " program" ,
678
+ }
679
+ ` ;
Original file line number Diff line number Diff line change @@ -8,6 +8,11 @@ describe("boolean", () => {
8
8
)
9
9
) . toMatchSnapshot ( ) ;
10
10
} ) ;
11
+ it ( "without variable" , ( ) => {
12
+ expect (
13
+ parser . parseEval ( "try { call(); } catch (Exception) { do_something(); }" )
14
+ ) . toMatchSnapshot ( ) ;
15
+ } ) ;
11
16
it ( "qualified name" , ( ) => {
12
17
expect (
13
18
parser . parseEval (
@@ -51,6 +56,13 @@ describe("boolean", () => {
51
56
)
52
57
) . toMatchSnapshot ( ) ;
53
58
} ) ;
59
+ it ( "multiple catch without variable" , ( ) => {
60
+ expect (
61
+ parser . parseEval (
62
+ "try { call(); } catch (MyException | MyOtherException) { do_something(); }"
63
+ )
64
+ ) . toMatchSnapshot ( ) ;
65
+ } ) ;
54
66
it ( "multiple catch #2" , ( ) => {
55
67
expect (
56
68
parser . parseEval (
You can’t perform that action at this time.
0 commit comments