File tree Expand file tree Collapse file tree 3 files changed +88
-4
lines changed Expand file tree Collapse file tree 3 files changed +88
-4
lines changed Original file line number Diff line number Diff line change @@ -609,7 +609,7 @@ module.exports = {
609
609
const node = this . node ( "match" ) ;
610
610
this . expect ( this . tok . T_MATCH ) && this . next ( ) ;
611
611
if ( this . version < 800 ) {
612
- this . reaseError ( "Match statements are not allowed before PHP 8" ) ;
612
+ this . raiseError ( "Match statements are not allowed before PHP 8" ) ;
613
613
}
614
614
let cond = null ;
615
615
let arms = [ ] ;
Original file line number Diff line number Diff line change @@ -73,6 +73,71 @@ Program {
73
73
}
74
74
` ;
75
75
76
+ exports [` match can have hanging comma 1` ] = `
77
+ Program {
78
+ " children" : Array [
79
+ ExpressionStatement {
80
+ " expression" : Assign {
81
+ " kind" : " assign" ,
82
+ " left" : Variable {
83
+ " curly" : false ,
84
+ " kind" : " variable" ,
85
+ " name" : " test" ,
86
+ },
87
+ " operator" : " =" ,
88
+ " right" : Match {
89
+ " arms" : Array [
90
+ MatchArm {
91
+ " body" : String {
92
+ " isDoubleQuote" : false ,
93
+ " kind" : " string" ,
94
+ " raw" : " 'ok'" ,
95
+ " unicode" : false ,
96
+ " value" : " ok" ,
97
+ },
98
+ " conds" : Array [
99
+ Boolean {
100
+ " kind" : " boolean" ,
101
+ " raw" : " true" ,
102
+ " value" : true ,
103
+ },
104
+ ],
105
+ " kind" : " matcharm" ,
106
+ },
107
+ MatchArm {
108
+ " body" : String {
109
+ " isDoubleQuote" : false ,
110
+ " kind" : " string" ,
111
+ " raw" : " 'Nope!'" ,
112
+ " unicode" : false ,
113
+ " value" : " Nope!" ,
114
+ },
115
+ " conds" : Array [
116
+ Boolean {
117
+ " kind" : " boolean" ,
118
+ " raw" : " false" ,
119
+ " value" : false ,
120
+ },
121
+ ],
122
+ " kind" : " matcharm" ,
123
+ },
124
+ ],
125
+ " cond" : Variable {
126
+ " curly" : false ,
127
+ " kind" : " variable" ,
128
+ " name" : " test" ,
129
+ },
130
+ " kind" : " match" ,
131
+ },
132
+ },
133
+ " kind" : " expressionstatement" ,
134
+ },
135
+ ],
136
+ " errors" : Array [],
137
+ " kind" : " program" ,
138
+ }
139
+ ` ;
140
+
76
141
exports [` match can have lhs, functions 1` ] = `
77
142
Program {
78
143
" children" : Array [
Original file line number Diff line number Diff line change @@ -6,7 +6,7 @@ describe("match", () => {
6
6
$test = match($a) {
7
7
true => 'yes',
8
8
false => 'no',
9
- default => null,
9
+ default => null
10
10
};
11
11
` ) ;
12
12
expect ( ast ) . toMatchSnapshot ( ) ;
@@ -16,7 +16,7 @@ describe("match", () => {
16
16
const ast = parser . parseEval ( `
17
17
$test = match(true) {
18
18
test($a), abc($b) => 'yes',
19
- default => null,
19
+ default => null
20
20
};
21
21
` ) ;
22
22
expect ( ast ) . toMatchSnapshot ( ) ;
@@ -26,9 +26,28 @@ describe("match", () => {
26
26
const ast = parser . parseEval ( `
27
27
$test = match(trye) {
28
28
0,1,2,3 => run(),
29
- default => null,
29
+ default => null
30
30
};
31
31
` ) ;
32
32
expect ( ast ) . toMatchSnapshot ( ) ;
33
33
} ) ;
34
+ it ( "can have hanging comma" , ( ) => {
35
+ const ast = parser . parseEval ( `
36
+ $test = match($test) {
37
+ true => 'ok',
38
+ false => 'Nope!',
39
+ };
40
+ ` ) ;
41
+ expect ( ast ) . toMatchSnapshot ( ) ;
42
+ } ) ;
43
+ it ( "does not support older php than 8" , ( ) => {
44
+ expect ( ( ) => {
45
+ new parser ( { parser : { version : 704 } } ) . parseEval ( `
46
+ $test = match($test) {
47
+ true => 'ok',
48
+ false => 'Nope!',
49
+ };
50
+ ` ) ;
51
+ } ) . toThrow ( SyntaxError ) ;
52
+ } ) ;
34
53
} ) ;
You can’t perform that action at this time.
0 commit comments