Skip to content

Commit

Permalink
feat(removecalls): handle string and logical expression as argument
Browse files Browse the repository at this point in the history
  • Loading branch information
merceyz committed May 28, 2019
1 parent 0c453b3 commit 2b59da8
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 0 deletions.
21 changes: 21 additions & 0 deletions src/visitors/removeUnnecessaryCalls.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,27 @@ const transforms = [
return arg;
}
},

function stringAndLogicalExpression(args) {
if (args.length !== 2) return;

const [arg1, arg2] = args;
if (
t.isStringLiteral(arg1) &&
t.isLogicalExpression(arg2, { operator: '&&' }) &&
t.isStringLiteral(arg2.right)
) {
return t.binaryExpression(
'+',
arg1,
t.conditionalExpression(
arg2.left,
t.stringLiteral(' ' + arg2.right.value),
t.stringLiteral(''),
),
);
}
},
];

const visitor = {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
const x = clsx(fooVar && 'btn-primary', {
btn: true,
});
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
const x = 'btn' + (fooVar ? ' btn-primary' : '');

0 comments on commit 2b59da8

Please sign in to comment.