Skip to content

Commit dcbd0f7

Browse files
authored
Merge pull request glayzzle#702 from czosel/php-promoted-props-v2
feat(php8): promoted params v2
2 parents 0b7781f + dfd2abf commit dcbd0f7

18 files changed

+254
-134
lines changed

src/ast/parameter.js

+10
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,13 @@
88
const Declaration = require("./declaration");
99
const KIND = "parameter";
1010

11+
// eslint-disable-next-line no-unused-vars
12+
const MODIFIER_PUBLIC = 1;
13+
// eslint-disable-next-line no-unused-vars
14+
const MODIFIER_PROTECTED = 2;
15+
// eslint-disable-next-line no-unused-vars
16+
const MODIFIER_PRIVATE = 4;
17+
1118
/**
1219
* Defines a function parameter
1320
* @constructor Parameter
@@ -17,6 +24,7 @@ const KIND = "parameter";
1724
* @property {boolean} byref
1825
* @property {boolean} variadic
1926
* @property {boolean} nullable
27+
* @property {MODIFIER_PUBLIC|MODIFIER_PROTECTED|MODIFIER_PRIVATE} flags
2028
*/
2129
module.exports = Declaration.extends(KIND, function Parameter(
2230
name,
@@ -25,6 +33,7 @@ module.exports = Declaration.extends(KIND, function Parameter(
2533
isRef,
2634
isVariadic,
2735
nullable,
36+
flags,
2837
docs,
2938
location
3039
) {
@@ -34,4 +43,5 @@ module.exports = Declaration.extends(KIND, function Parameter(
3443
this.byref = isRef;
3544
this.variadic = isVariadic;
3645
this.nullable = nullable;
46+
this.flags = flags || 0;
3747
});

src/parser/function.js

+26-1
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,7 @@ module.exports = {
208208
this.next();
209209
nullable = true;
210210
}
211+
const flags = this.read_promoted();
211212
types = this.read_types();
212213
if (nullable && !types) {
213214
this.raiseError(
@@ -225,7 +226,15 @@ module.exports = {
225226
if (this.token == "=") {
226227
value = this.next().read_expr();
227228
}
228-
return node(parameterName, types, value, isRef, isVariadic, nullable);
229+
return node(
230+
parameterName,
231+
types,
232+
value,
233+
isRef,
234+
isVariadic,
235+
nullable,
236+
flags
237+
);
229238
},
230239
read_types() {
231240
const types = [];
@@ -244,6 +253,22 @@ module.exports = {
244253
return unionType(types);
245254
}
246255
},
256+
read_promoted() {
257+
const MODIFIER_PUBLIC = 1;
258+
const MODIFIER_PROTECTED = 2;
259+
const MODIFIER_PRIVATE = 4;
260+
if (this.token === this.tok.T_PUBLIC) {
261+
this.next();
262+
return MODIFIER_PUBLIC;
263+
} else if (this.token === this.tok.T_PROTECTED) {
264+
this.next();
265+
return MODIFIER_PROTECTED;
266+
} else if (this.token === this.tok.T_PRIVATE) {
267+
this.next();
268+
return MODIFIER_PRIVATE;
269+
}
270+
return 0;
271+
},
247272
/**
248273
* Reads a list of arguments
249274
* ```ebnf

test/snapshot/__snapshots__/acid.test.js.snap

+2
Original file line numberDiff line numberDiff line change
@@ -2153,6 +2153,7 @@ Program {
21532153
"arguments": Array [
21542154
Parameter {
21552155
"byref": false,
2156+
"flags": 0,
21562157
"kind": "parameter",
21572158
"loc": Location {
21582159
"end": Position {
@@ -4107,6 +4108,7 @@ next:
41074108
"arguments": Array [
41084109
Parameter {
41094110
"byref": false,
4111+
"flags": 0,
41104112
"kind": "parameter",
41114113
"loc": Location {
41124114
"end": Position {

test/snapshot/__snapshots__/arrowfunc.test.js.snap

+8
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ Program {
1616
"arguments": Array [
1717
Parameter {
1818
"byref": false,
19+
"flags": 0,
1920
"kind": "parameter",
2021
"name": Identifier {
2122
"kind": "identifier",
@@ -65,6 +66,7 @@ Program {
6566
"arguments": Array [
6667
Parameter {
6768
"byref": true,
69+
"flags": 0,
6870
"kind": "parameter",
6971
"name": Identifier {
7072
"kind": "identifier",
@@ -114,6 +116,7 @@ Program {
114116
"arguments": Array [
115117
Parameter {
116118
"byref": false,
119+
"flags": 0,
117120
"kind": "parameter",
118121
"name": Identifier {
119122
"kind": "identifier",
@@ -126,6 +129,7 @@ Program {
126129
},
127130
Parameter {
128131
"byref": false,
132+
"flags": 0,
129133
"kind": "parameter",
130134
"name": Identifier {
131135
"kind": "identifier",
@@ -138,6 +142,7 @@ Program {
138142
},
139143
Parameter {
140144
"byref": false,
145+
"flags": 0,
141146
"kind": "parameter",
142147
"name": Identifier {
143148
"kind": "identifier",
@@ -216,6 +221,7 @@ Program {
216221
"arguments": Array [
217222
Parameter {
218223
"byref": false,
224+
"flags": 0,
219225
"kind": "parameter",
220226
"name": Identifier {
221227
"kind": "identifier",
@@ -270,6 +276,7 @@ Program {
270276
"arguments": Array [
271277
Parameter {
272278
"byref": false,
279+
"flags": 0,
273280
"kind": "parameter",
274281
"name": Identifier {
275282
"kind": "identifier",
@@ -319,6 +326,7 @@ Program {
319326
"arguments": Array [
320327
Parameter {
321328
"byref": false,
329+
"flags": 0,
322330
"kind": "parameter",
323331
"name": Identifier {
324332
"kind": "identifier",

test/snapshot/__snapshots__/byref.test.js.snap

+2
Original file line numberDiff line numberDiff line change
@@ -405,6 +405,7 @@ Program {
405405
"arguments": Array [
406406
Parameter {
407407
"byref": true,
408+
"flags": 0,
408409
"kind": "parameter",
409410
"name": Identifier {
410411
"kind": "identifier",
@@ -897,6 +898,7 @@ Program {
897898
"arguments": Array [
898899
Parameter {
899900
"byref": true,
901+
"flags": 0,
900902
"kind": "parameter",
901903
"name": Identifier {
902904
"kind": "identifier",

0 commit comments

Comments
 (0)