Skip to content

Commit

Permalink
fix(directives): theme() breaks @apply (#1025)
Browse files Browse the repository at this point in the history
  • Loading branch information
Dunqing committed May 29, 2022
1 parent e87e422 commit d04ff70
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 3 deletions.
6 changes: 3 additions & 3 deletions packages/transformer-directives/src/index.ts
Expand Up @@ -189,10 +189,10 @@ export async function transformDirectives(
const stack: Promise<void>[] = []

const processNode = async (node: CssNode, _item: ListItem<CssNode>, _list: List<CssNode>) => {
if (hasThemeFn) {
if (hasThemeFn)
handleThemeFn(node)
}
else if (isApply && node.type === 'Rule') {

if (isApply && node.type === 'Rule') {
await Promise.all(
node.block.children.map(async (childNode, _childItem) => {
if (childNode.type === 'Raw')
Expand Down
25 changes: 25 additions & 0 deletions test/transformer-directives.test.ts
Expand Up @@ -452,5 +452,30 @@ describe('transformer-directives', () => {
)).rejects
.toMatchInlineSnapshot('[Error: theme() expect exact one argument, but got 2]')
})

test('with @apply', async () => {
expect(await transform(
`
div {
@apply flex h-full w-full justify-center items-center;
--my-color: theme('colors.red.500');
color: var(--my-color);
}
`,
)).toMatchInlineSnapshot(`
"div {
height: 100%;
width: 100%;
display: flex;
align-items: center;
justify-content: center;
--my-color: theme(\\"colors.red.500\\");
color: var(--my-color);
}
"
`)
})
})
})

0 comments on commit d04ff70

Please sign in to comment.