Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Consistent returns for read_variable_declaration #1141

Merged
merged 3 commits into from
Dec 4, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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([",", ";", "="]);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we need to drop the "=" in th eexpect, we already handled that with the previous if condition.

Suggested change
this.expect([",", ";", "="]);
this.expect([",", ";"]);

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"," and ";" are handled by the first if.
I think this line is here to show an error message indicating that we expect one of those 3 things.

I figured this out while working on adding support for property hooks.

return result(propName, null, nullable, type, attrs || []);
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

here, readonly is not passed.

}
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 {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The snapshot show that what was set was incorrect: instead of a boolean value we had some objects.

"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
Loading