File tree Expand file tree Collapse file tree 3 files changed +28
-7
lines changed Expand file tree Collapse file tree 3 files changed +28
-7
lines changed Original file line number Diff line number Diff line change @@ -346,6 +346,14 @@ module.exports = {
346
346
case this . tok . T_UNSET_CAST :
347
347
return this . read_expr_cast ( "unset" ) ;
348
348
349
+ case this . tok . T_THROW : {
350
+ if ( this . version < 800 ) {
351
+ this . raiseError ( "PHP 8+ is required to use throw as an expression" ) ;
352
+ }
353
+ const result = this . node ( "throw" ) ;
354
+ const expr = this . next ( ) . read_expr ( ) ;
355
+ return result ( expr ) ;
356
+ }
349
357
case this . tok . T_EXIT : {
350
358
const useDie = this . lexer . yytext . toLowerCase ( ) === "die" ;
351
359
result = this . node ( "exit" ) ;
Original file line number Diff line number Diff line change @@ -258,12 +258,25 @@ Program {
258
258
" kind" : " matcharm" ,
259
259
},
260
260
MatchArm {
261
- " body" : String {
262
- " isDoubleQuote" : false ,
263
- " kind" : " string" ,
264
- " raw" : " 'Nope!'" ,
265
- " unicode" : false ,
266
- " value" : " Nope!" ,
261
+ " body" : Throw {
262
+ " kind" : " throw" ,
263
+ " what" : New {
264
+ " arguments" : Array [
265
+ String {
266
+ " isDoubleQuote" : false ,
267
+ " kind" : " string" ,
268
+ " raw" : " 'Nope'" ,
269
+ " unicode" : false ,
270
+ " value" : " Nope" ,
271
+ },
272
+ ],
273
+ " kind" : " new" ,
274
+ " what" : Name {
275
+ " kind" : " name" ,
276
+ " name" : " Exception" ,
277
+ " resolution" : " uqn" ,
278
+ },
279
+ },
267
280
},
268
281
" conds" : Array [
269
282
Boolean {
Original file line number Diff line number Diff line change @@ -35,7 +35,7 @@ describe("match", () => {
35
35
const ast = parser . parseEval ( `
36
36
$test = match($test) {
37
37
true, => 'ok',
38
- false => 'Nope!' ,
38
+ false => throw new Exception( 'Nope') ,
39
39
};
40
40
` ) ;
41
41
expect ( ast ) . toMatchSnapshot ( ) ;
You can’t perform that action at this time.
0 commit comments