File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -1005,6 +1005,32 @@ Program {
10051005}
10061006` ;
10071007
1008+ exports [` Parse Attributes doesnt parse attributes for assignments 1` ] = `
1009+ Program {
1010+ " children" : Array [
1011+ ExpressionStatement {
1012+ " expression" : Assign {
1013+ " kind" : " assign" ,
1014+ " left" : Variable {
1015+ " curly" : false ,
1016+ " kind" : " variable" ,
1017+ " name" : " a" ,
1018+ },
1019+ " operator" : " =" ,
1020+ " right" : Number {
1021+ " kind" : " number" ,
1022+ " value" : " 1" ,
1023+ },
1024+ },
1025+ " kind" : " expressionstatement" ,
1026+ },
1027+ ],
1028+ " comments" : Array [],
1029+ " errors" : Array [],
1030+ " kind" : " program" ,
1031+ }
1032+ ` ;
1033+
10081034exports [` Parse Attributes doesnt repeat attributes from previous function 1` ] = `
10091035Program {
10101036 " children" : Array [
Original file line number Diff line number Diff line change @@ -86,6 +86,20 @@ describe("Parse Attributes", () => {
8686 ` )
8787 ) . toMatchSnapshot ( ) ;
8888 } ) ;
89+ it ( "can't parse anonymous function attributes in PHP < 8" , ( ) => {
90+ expect ( ( ) =>
91+ parser . parseEval (
92+ `
93+ $a = #[Pure] fn() => true;
94+ ` ,
95+ {
96+ parser : {
97+ version : "7.4" ,
98+ } ,
99+ }
100+ )
101+ ) . toThrow ( SyntaxError ) ;
102+ } ) ;
89103 it ( "can parse class property attributes" , ( ) => {
90104 expect (
91105 parser . parseEval ( `
@@ -113,6 +127,15 @@ describe("Parse Attributes", () => {
113127 it ( "can parse anon-class attributes" , ( ) => {
114128 expect ( parser . parseEval ( `$a = new #[T] class {};` ) ) . toMatchSnapshot ( ) ;
115129 } ) ;
130+ it ( "can't parse anon-class attributes in PHP < 8" , ( ) => {
131+ expect ( ( ) =>
132+ parser . parseEval ( `$a = new #[T] class {};` , {
133+ parser : {
134+ version : "7.4" ,
135+ } ,
136+ } )
137+ ) . toThrow ( SyntaxError ) ;
138+ } ) ;
116139 it ( "can parse interface attributes" , ( ) => {
117140 expect (
118141 parser . parseEval ( `
@@ -132,7 +155,7 @@ describe("Parse Attributes", () => {
132155 namespace A {
133156 function b() {
134157 return #[C] fn() => #[Pure] function() {};
135- }
158+ }
136159 }` )
137160 ) . toMatchSnapshot ( ) ;
138161 } ) ;
@@ -167,15 +190,26 @@ describe("Parse Attributes", () => {
167190 #[Att2]
168191 function b(){}
169192 }
170- ` ,
193+ ` ,
171194 {
172195 parser : {
173196 version : "7.4" ,
174-
175197 extractDoc : true ,
176198 } ,
177199 }
178200 )
179201 ) . toMatchSnapshot ( ) ;
180202 } ) ;
203+
204+ it ( "doesnt parse attributes for assignments" , ( ) => {
205+ expect (
206+ parser . parseEval (
207+ `
208+ #[Att1]
209+ $a = 1;
210+ ` ,
211+ { parser : { extractDoc : true } }
212+ )
213+ ) . toMatchSnapshot ( ) ;
214+ } ) ;
181215} ) ;
You can’t perform that action at this time.
0 commit comments