Skip to content

Commit 72a2c96

Browse files
committed
Add support for callable template literals
1 parent d586b21 commit 72a2c96

File tree

3 files changed

+42
-0
lines changed

3 files changed

+42
-0
lines changed

src/index.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -596,6 +596,19 @@ function isSortableTemplateExpression(
596596
}
597597
}
598598

599+
if (node.tag.type === 'CallExpression') {
600+
let func = node.tag.callee
601+
602+
// If the tag is a CallExpression we should traverse all CallExpression's until we find the leading Identifier
603+
while (func.type === 'CallExpression') {
604+
func = func.callee
605+
}
606+
607+
if (func.type === 'Identifier') {
608+
return functions.has(func.name)
609+
}
610+
}
611+
599612
return false
600613
}
601614

@@ -626,6 +639,19 @@ function isSortableCallExpression(
626639
}
627640
}
628641

642+
if (node.callee.type === 'CallExpression') {
643+
let func = node.callee.callee
644+
645+
// If the tag is a CallExpression we should traverse all CallExpression's until we find the leading Identifier
646+
while (func.type === 'CallExpression') {
647+
func = func.callee
648+
}
649+
650+
if (func.type === 'Identifier') {
651+
return functions.has(func.name)
652+
}
653+
}
654+
629655
return false
630656
}
631657

tests/fixtures/custom-jsx/index.jsx

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,14 @@ const k = tw.foo('sm:p-1 p-2');
1414
const l = tw.foo.bar('sm:p-1 p-2');
1515
const m = no.foo('sm:p-1 p-2');
1616
const n = no.tw('sm:p-1 p-2');
17+
const o = tw(Foo)`sm:p-1 p-2`;
18+
const p = tw(Foo)(Bar)`sm:p-1 p-2`;
19+
const q = no(Foo)`sm:p-1 p-2`;
20+
const r = no.tw(Foo)`sm:p-1 p-2`;
21+
const s = tw(Foo)('sm:p-1 p-2');
22+
const t = tw(Foo)(Bar)('sm:p-1 p-2');
23+
const u = no(Foo)('sm:p-1 p-2');
24+
const v = no.tw(Foo)('sm:p-1 p-2');
1725

1826
const A = (props) => <div className={props.sortMe} />;
1927
const B = () => <A sortMe="sm:p-1 p-2" dontSort="sm:p-1 p-2" />;

tests/fixtures/custom-jsx/output.jsx

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,14 @@ const k = tw.foo("p-2 sm:p-1");
1414
const l = tw.foo.bar("p-2 sm:p-1");
1515
const m = no.foo("sm:p-1 p-2");
1616
const n = no.tw("sm:p-1 p-2");
17+
const o = tw(Foo)`p-2 sm:p-1`;
18+
const p = tw(Foo)(Bar)`p-2 sm:p-1`;
19+
const q = no(Foo)`sm:p-1 p-2`;
20+
const r = no.tw(Foo)`sm:p-1 p-2`;
21+
const s = tw(Foo)("p-2 sm:p-1");
22+
const t = tw(Foo)(Bar)("p-2 sm:p-1");
23+
const u = no(Foo)("sm:p-1 p-2");
24+
const v = no.tw(Foo)("sm:p-1 p-2");
1725

1826
const A = (props) => <div className={props.sortMe} />;
1927
const B = () => <A sortMe="p-2 sm:p-1" dontSort="sm:p-1 p-2" />;

0 commit comments

Comments
 (0)