Skip to content

Commit

Permalink
simplify toExpression
Browse files Browse the repository at this point in the history
  • Loading branch information
leonid-shutov committed Jan 23, 2025
1 parent 4167db5 commit a1adacd
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions lib/expressions.js
Original file line number Diff line number Diff line change
Expand Up @@ -144,11 +144,12 @@ 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()};`,
);
const consequentExpressions = consequents.map((consequent, i) => {
const consequentExpression = consequent.toExpression();
return i === consequents.length - 1
? `return ${consequentExpression};`
: `${consequentExpression};`;
});
return `${ifExpression} {${consequentExpressions.join(' ')}}`;
});
return ifExpressions.join(' ');
Expand Down

0 comments on commit a1adacd

Please sign in to comment.