Skip to content

Commit

Permalink
consistent return value for class property parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
genintho committed Nov 25, 2024
1 parent d9cb05e commit 1af8906
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 22 deletions.
16 changes: 6 additions & 10 deletions src/parser/class.js
Original file line number Diff line number Diff line change
Expand Up @@ -201,22 +201,18 @@ module.exports = {
const name = this.text().substring(1); // ignore $
this.next();
propName = propName(name);

let value = null;

if (this.token === ";" || this.token === ",") {
return result(propName, null, readonly, nullable, type, attrs || []);
// no-op
} else if (this.token === "=") {
// https://github.com/php/php-src/blob/master/Zend/zend_language_parser.y#L815
return result(
propName,
this.next().read_expr(),
readonly,
nullable,
type,
attrs || [],
);
value = this.next().read_expr();
} else {
this.expect([",", ";", "="]);
return result(propName, null, nullable, type, attrs || []);
}
return result(propName, value, readonly, nullable, type, attrs || []);
},
",",
);
Expand Down
8 changes: 4 additions & 4 deletions test/snapshot/__snapshots__/class.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -1200,19 +1200,19 @@ Program {
"kind": "propertystatement",
"properties": [
Property {
"attrGroups": null,
"attrGroups": [],
"kind": "property",
"name": Identifier {
"kind": "identifier",
"name": "id",
},
"nullable": TypeReference {
"nullable": false,
"readonly": true,
"type": TypeReference {
"kind": "typereference",
"name": "int",
"raw": "int",
},
"readonly": false,
"type": [],
"value": null,
},
],
Expand Down
16 changes: 8 additions & 8 deletions test/snapshot/__snapshots__/graceful.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -300,19 +300,19 @@ Program {
"kind": "propertystatement",
"properties": [
Property {
"attrGroups": null,
"attrGroups": [],
"kind": "property",
"name": Identifier {
"kind": "identifier",
"name": "onst",
},
"nullable": Name {
"nullable": false,
"readonly": false,
"type": Name {
"kind": "name",
"name": "foo",
"resolution": "uqn",
},
"readonly": false,
"type": [],
"value": null,
},
],
Expand Down Expand Up @@ -843,19 +843,19 @@ Program {
"kind": "propertystatement",
"properties": [
Property {
"attrGroups": null,
"attrGroups": [],
"kind": "property",
"name": Identifier {
"kind": "identifier",
"name": "mplement",
},
"nullable": Name {
"nullable": false,
"readonly": false,
"type": Name {
"kind": "name",
"name": "bar",
"resolution": "uqn",
},
"readonly": false,
"type": [],
"value": null,
},
],
Expand Down

0 comments on commit 1af8906

Please sign in to comment.