Skip to content

Commit

Permalink
feat: add template literals support
Browse files Browse the repository at this point in the history
  • Loading branch information
daviderenger authored and kinday committed Jul 19, 2022
1 parent 06ff357 commit 06c414d
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
4 changes: 4 additions & 0 deletions src/classnames.macro.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,10 @@ export default createMacro(({ babel, references: { default: paths } }) => {
)
}

if (babel.types.isTemplateLiteral(node)) {
return babel.types.binaryExpression("+", babel.types.stringLiteral(getPrefix()), node);
}

// TODO: This probably does not belong here
if (babel.types.isStringLiteral(node)) {
if (node.value.indexOf(" ") !== 0) {
Expand Down
2 changes: 1 addition & 1 deletion tests/classnames.macro.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ test("computed properties (template string)", (t) => {
});
`

const expected = 'const CLASS_NAMES = "baz" + (props.bar ? " " +`bar--${bar}` : "");';
const expected = 'const CLASS_NAMES = "baz" + (props.bar ? " " + `bar--${bar}` : "");';

const output = run(input)
t.is(output, expected)
Expand Down

0 comments on commit 06c414d

Please sign in to comment.