Skip to content

Commit f0826c6

Browse files
committed
Fix key statement
1 parent 7ec3e10 commit f0826c6

File tree

2 files changed

+24
-4
lines changed

2 files changed

+24
-4
lines changed

src/parsers/template.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,11 @@ const addDynamicVariablesToElements = (
5454
cssVar: CssVariables
5555
): void => {
5656
node.children?.forEach((childNode) => {
57-
// console.log(childNode);
58-
59-
if (childNode.type === 'InlineComponent' || childNode.type === 'EachBlock') {
57+
if (
58+
childNode.type === 'InlineComponent' ||
59+
childNode.type === 'EachBlock' ||
60+
childNode.type === 'KeyBlock'
61+
) {
6062
addDynamicVariablesToElements(processor, childNode, cssVar);
6163
} else if (childNode.type === 'Element') {
6264
const attributesLength = childNode.attributes.length;

test/globalFixtures/bindVariable.test.js

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ describe('Bind variable to CSS', () => {
152152
);
153153
});
154154

155-
test('root elements has `each` statement', async () => {
155+
test('root element has `each` statement', async () => {
156156
const output = await compiler({
157157
source: `${script}` +
158158
`{#await promise}` +
@@ -183,4 +183,22 @@ describe('Bind variable to CSS', () => {
183183
`{/await}<style module>:global(div){color:var(--color-123)}</style>`
184184
);
185185
});
186+
187+
test('root element has `key` statement', async () => {
188+
const output = await compiler({
189+
source: `${script}` +
190+
`{#key value}` +
191+
`<div transition:fade>{value}</div>` +
192+
`{/key}<style module>div{color:bind(color)}</style>`,
193+
}, {
194+
cssVariableHash: '123',
195+
});
196+
197+
expect(output).toBe(
198+
`${script}` +
199+
`{#key value}` +
200+
`<div transition:fade style="--color-123:{color};">{value}</div>` +
201+
`{/key}<style module>:global(div){color:var(--color-123)}</style>`
202+
);
203+
});
186204
});

0 commit comments

Comments
 (0)