Skip to content

Commit

Permalink
A few unimportant code-style consistency changes (#1137)
Browse files Browse the repository at this point in the history
* Use consistent declaration format for function exports.

Change "read_types() {" to "read_types: function () {"
Change "read_promoted() {" to "read_promoted: function () {"

* parser/class.js -- tiny simplification
Set nullable directly and use result for comparison.

* Use strict equality tests for consistency
  • Loading branch information
mreiden authored Nov 6, 2024
1 parent 7a82704 commit 8334fea
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 10 deletions.
15 changes: 7 additions & 8 deletions src/parser/class.js
Original file line number Diff line number Diff line change
Expand Up @@ -312,11 +312,11 @@ module.exports = {
break;
}
if (asInterface) {
if (idx == 0 && val == 2) {
if (idx === 0 && val === 2) {
// an interface can't be private
this.expect([this.tok.T_PUBLIC, this.tok.T_PROTECTED]);
val = -1;
} else if (idx == 2 && val == 1) {
} else if (idx === 2 && val === 1) {
// an interface cant be abstract
this.error();
val = -1;
Expand All @@ -331,8 +331,8 @@ module.exports = {
} while (this.next().is("T_MEMBER_FLAGS"));
}

if (result[1] == -1) result[1] = 0;
if (result[2] == -1) result[2] = 0;
if (result[1] === -1) result[1] = 0;
if (result[2] === -1) result[2] = 0;
return result;
},

Expand Down Expand Up @@ -360,9 +360,8 @@ module.exports = {
* ;
*/
read_optional_type: function () {
let nullable = false;
if (this.token === "?") {
nullable = true;
const nullable = this.token === "?";
if (nullable) {
this.next();
}
let type = this.read_types();
Expand Down Expand Up @@ -440,7 +439,7 @@ module.exports = {
const flags = this.read_member_flags(true);

// check constant
if (this.token == this.tok.T_CONST) {
if (this.token === this.tok.T_CONST) {
const constants = this.read_constant_list(flags, attrs);
if (this.expect(";")) {
this.next();
Expand Down
4 changes: 2 additions & 2 deletions src/parser/function.js
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,7 @@ module.exports = {
if (attrs) result.attrGroups = attrs;
return result;
},
read_types() {
read_types: function () {
const MODE_UNSET = "unset";
const MODE_UNION = "union";
const MODE_INTERSECTION = "intersection";
Expand Down Expand Up @@ -374,7 +374,7 @@ module.exports = {
: this.node("uniontype")(types);
}
},
read_promoted() {
read_promoted: function () {
const MODIFIER_PUBLIC = 1;
const MODIFIER_PROTECTED = 2;
const MODIFIER_PRIVATE = 4;
Expand Down

0 comments on commit 8334fea

Please sign in to comment.