Skip to content

Commit

Permalink
make more compact
Browse files Browse the repository at this point in the history
  • Loading branch information
leonid-shutov committed Jan 14, 2025
1 parent a24e48b commit bf687fe
Showing 1 changed file with 2 additions and 15 deletions.
17 changes: 2 additions & 15 deletions lib/expressions.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,16 +71,11 @@ class OperationExpression {

toJavaScript() {
let header = '(';

for (const identifier of this.identifiers) {
if (header.length > 1) {
header += ', ';
}
if (header.length > 1) header += ', ';
header += identifier;
}

header += ')';

return `${header} => ${this.toExpression()}`;
}
}
Expand Down Expand Up @@ -122,31 +117,23 @@ class ConditionExpression {
toExpression() {
const ifExpressions = this.clauses.map(({ condition, consequents }) => {
const ifExpression = `if ${condition.toExpression()}`;

const consequentExpressions = consequents.map((consequent, i) =>
i === consequents.length - 1
? `return ${consequent.toExpression()};`
: `${consequent.toExpression()};`,
);

return `${ifExpression} {${consequentExpressions.join(' ')}}`;
});

return ifExpressions.join(' ');
}

toJavaScript() {
let header = '(';

for (const identifier of this.identifiers) {
if (header.length > 1) {
header += ', ';
}
if (header.length > 1) header += ', ';
header += identifier;
}

header += ')';

return `${header} => {${this.toExpression()}}`;
}
}
Expand Down

0 comments on commit bf687fe

Please # to comment.