Skip to content

Commit ed44b0f

Browse files
committed
Fix each statement
1 parent c72dc44 commit ed44b0f

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

src/parsers/template.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ const addDynamicVariablesToElements = (
5656
node.children?.forEach((childNode) => {
5757
// console.log(childNode);
5858

59-
if (childNode.type === 'InlineComponent') {
59+
if (childNode.type === 'InlineComponent' || childNode.type === 'EachBlock') {
6060
addDynamicVariablesToElements(processor, childNode, cssVar);
6161
} else if (childNode.type === 'Element') {
6262
const attributesLength = childNode.attributes.length;

test/globalFixtures/bindVariable.test.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,4 +133,22 @@ describe('Bind variable to CSS', () => {
133133
`{/if}<style module>:global(div){color:var(--color-123)}</style>`
134134
);
135135
});
136+
137+
test('root elements has `each` statement', async () => {
138+
const output = await compiler({
139+
source: `${script}` +
140+
`{#each [0,1,2,3] as number}` +
141+
`<div>{number}</div>` +
142+
`{/each}<style module>div{color:bind(color)}</style>`,
143+
}, {
144+
cssVariableHash: '123',
145+
});
146+
147+
expect(output).toBe(
148+
`${script}` +
149+
`{#each [0,1,2,3] as number}` +
150+
`<div style="--color-123:{color};">{number}</div>` +
151+
`{/each}<style module>:global(div){color:var(--color-123)}</style>`
152+
);
153+
});
136154
});

0 commit comments

Comments
 (0)