Skip to content

Commit

Permalink
fix(combine): don't create an arrayExpression with just one item
Browse files Browse the repository at this point in the history
  • Loading branch information
merceyz committed May 11, 2019
1 parent b344735 commit 699d6f5
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
9 changes: 7 additions & 2 deletions src/transformers/combineArguments.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,13 @@ module.exports = path => {
const result = [];

if (node.child.type === 'rootNode') {
const arr = t.arrayExpression(convertToAST(node.child));
result.push(t.logicalExpression('&&', node.node, arr));
let right = convertToAST(node.child);
if (right.length === 1) {
right = right[0];
} else {
right = t.arrayExpression(right);
}
result.push(t.logicalExpression('&&', node.node, right));
} else {
result.push(t.logicalExpression('&&', node.node, node.child));
}
Expand Down
2 changes: 1 addition & 1 deletion test/fixtures/combine-arguments/nested-match/output.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
clsx(
color === 'primary' && [text && [classes.text, classes.textPrimary]],
color === 'primary' && text && [classes.text, classes.textPrimary],
text && [classes.text, color === 'secondary' && classes.textSecondary],
);

0 comments on commit 699d6f5

Please sign in to comment.