Skip to content

Commit 67d8cf3

Browse files
committed
cleanup
1 parent 185fd51 commit 67d8cf3

File tree

3 files changed

+69
-70
lines changed

3 files changed

+69
-70
lines changed

src/parser/class.js

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ module.exports = {
234234
this.next();
235235
}
236236

237-
const class_constant = this.node("classconstant");
237+
const class_constant_node = this.node("classconstant");
238238
const items = this.read_list(
239239
/*
240240
* Reads a constant declaration
@@ -245,38 +245,33 @@ module.exports = {
245245
* @return {Constant} [:link:](AST.md#constant)
246246
*/
247247
function read_constant_declaration() {
248-
const constant = this.node("constant");
249-
const nullable = false;
248+
const constant_node = this.node("constant");
250249

251-
let type = this.read_types();
252-
let constName = null;
253-
let name = null;
250+
// eslint-disable-next-line prefer-const
251+
let [nullable, type] = this.read_optional_type();
252+
let propName = this.node("identifier");
254253
let value = null;
255254

256255
if (type && type.kind === "name") {
257-
constName = this.node("identifier");
258-
constName = constName(type.name);
256+
propName = propName(type.name);
259257
type = null;
260-
value = this.next().read_expr();
261258
} else {
262-
constName = this.node("identifier");
263-
name = this.text();
264-
constName = constName(name);
259+
propName = propName(this.text());
265260
this.next();
266-
this.expect("=");
267-
value = this.next().read_expr();
268261
}
262+
this.expect("=");
263+
value = this.next().read_expr();
269264

270265
if (this.version < 803 && type !== null) {
271266
this.raiseError(
272267
"Parse Error: Typed Class Constants requires PHP 8.3+",
273268
);
274269
}
275-
return constant(constName, value, nullable, type);
270+
return constant_node(propName, value, nullable, type);
276271
},
277272
",",
278273
);
279-
return class_constant(null, items, flags, attrs || []);
274+
return class_constant_node(null, items, flags, attrs || []);
280275
},
281276
/*
282277
* Read member flags

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

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -426,19 +426,6 @@ Program {
426426
"constants": [
427427
Constant {
428428
"kind": "constant",
429-
"loc": Location {
430-
"end": Position {
431-
"column": 28,
432-
"line": 20,
433-
"offset": 360,
434-
},
435-
"source": "FOOBAR = 'foo & bar'",
436-
"start": Position {
437-
"column": 8,
438-
"line": 20,
439-
"offset": 340,
440-
},
441-
},
442429
"name": Identifier {
443430
"kind": "identifier",
444431
"loc": Location {
@@ -456,6 +443,20 @@ Program {
456443
},
457444
"name": "FOOBAR",
458445
},
446+
"nullable": null,
447+
"type": Location {
448+
"end": Position {
449+
"column": 28,
450+
"line": 20,
451+
"offset": 360,
452+
},
453+
"source": "FOOBAR = 'foo & bar'",
454+
"start": Position {
455+
"column": 8,
456+
"line": 20,
457+
"offset": 340,
458+
},
459+
},
459460
"value": String {
460461
"isDoubleQuote": false,
461462
"kind": "string",
@@ -789,6 +790,8 @@ Program {
789790
},
790791
"name": "FOOBAR",
791792
},
793+
"nullable": false,
794+
"type": null,
792795
"value": String {
793796
"isDoubleQuote": false,
794797
"kind": "string",
@@ -826,8 +829,6 @@ Program {
826829
"offset": 544,
827830
},
828831
},
829-
"nullable": false,
830-
"type": null,
831832
"visibility": "",
832833
},
833834
PropertyStatement {

test/snapshot/__snapshots__/location.test.js.snap

Lines changed: 42 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -3363,19 +3363,6 @@ Program {
33633363
"constants": [
33643364
Constant {
33653365
"kind": "constant",
3366-
"loc": Location {
3367-
"end": Position {
3368-
"column": 31,
3369-
"line": 1,
3370-
"offset": 31,
3371-
},
3372-
"source": "CONSTANT = "Hello world!"",
3373-
"start": Position {
3374-
"column": 6,
3375-
"line": 1,
3376-
"offset": 6,
3377-
},
3378-
},
33793366
"name": Identifier {
33803367
"kind": "identifier",
33813368
"loc": Location {
@@ -3393,6 +3380,20 @@ Program {
33933380
},
33943381
"name": "CONSTANT",
33953382
},
3383+
"nullable": null,
3384+
"type": Location {
3385+
"end": Position {
3386+
"column": 31,
3387+
"line": 1,
3388+
"offset": 31,
3389+
},
3390+
"source": "CONSTANT = "Hello world!"",
3391+
"start": Position {
3392+
"column": 6,
3393+
"line": 1,
3394+
"offset": 6,
3395+
},
3396+
},
33963397
"value": String {
33973398
"isDoubleQuote": true,
33983399
"kind": "string",
@@ -3456,19 +3457,6 @@ Program {
34563457
"constants": [
34573458
Constant {
34583459
"kind": "constant",
3459-
"loc": Location {
3460-
"end": Position {
3461-
"column": 31,
3462-
"line": 1,
3463-
"offset": 31,
3464-
},
3465-
"source": "CONSTANT = "Hello world!"",
3466-
"start": Position {
3467-
"column": 6,
3468-
"line": 1,
3469-
"offset": 6,
3470-
},
3471-
},
34723460
"name": Identifier {
34733461
"kind": "identifier",
34743462
"loc": Location {
@@ -3486,6 +3474,20 @@ Program {
34863474
},
34873475
"name": "CONSTANT",
34883476
},
3477+
"nullable": null,
3478+
"type": Location {
3479+
"end": Position {
3480+
"column": 31,
3481+
"line": 1,
3482+
"offset": 31,
3483+
},
3484+
"source": "CONSTANT = "Hello world!"",
3485+
"start": Position {
3486+
"column": 6,
3487+
"line": 1,
3488+
"offset": 6,
3489+
},
3490+
},
34893491
"value": String {
34903492
"isDoubleQuote": true,
34913493
"kind": "string",
@@ -3509,19 +3511,6 @@ Program {
35093511
},
35103512
Constant {
35113513
"kind": "constant",
3512-
"loc": Location {
3513-
"end": Position {
3514-
"column": 70,
3515-
"line": 1,
3516-
"offset": 70,
3517-
},
3518-
"source": "OTHER_CONSTANT = "Other hello world!"",
3519-
"start": Position {
3520-
"column": 33,
3521-
"line": 1,
3522-
"offset": 33,
3523-
},
3524-
},
35253514
"name": Identifier {
35263515
"kind": "identifier",
35273516
"loc": Location {
@@ -3539,6 +3528,20 @@ Program {
35393528
},
35403529
"name": "OTHER_CONSTANT",
35413530
},
3531+
"nullable": null,
3532+
"type": Location {
3533+
"end": Position {
3534+
"column": 70,
3535+
"line": 1,
3536+
"offset": 70,
3537+
},
3538+
"source": "OTHER_CONSTANT = "Other hello world!"",
3539+
"start": Position {
3540+
"column": 33,
3541+
"line": 1,
3542+
"offset": 33,
3543+
},
3544+
},
35423545
"value": String {
35433546
"isDoubleQuote": true,
35443547
"kind": "string",

0 commit comments

Comments
 (0)