Skip to content

Commit 7ec3e10

Browse files
committed
Fix await statement
1 parent ed44b0f commit 7ec3e10

File tree

2 files changed

+36
-0
lines changed

2 files changed

+36
-0
lines changed

src/parsers/template.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,10 @@ const addDynamicVariablesToElements = (
7777
} else if (childNode.type === 'IfBlock') {
7878
addDynamicVariablesToElements(processor, childNode, cssVar);
7979
addDynamicVariablesToElements(processor, childNode.else, cssVar);
80+
} else if (childNode.type === 'AwaitBlock') {
81+
addDynamicVariablesToElements(processor, childNode.pending, cssVar);
82+
addDynamicVariablesToElements(processor, childNode.then, cssVar);
83+
addDynamicVariablesToElements(processor, childNode.catch, cssVar);
8084
}
8185
});
8286
};

test/globalFixtures/bindVariable.test.js

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,4 +151,36 @@ describe('Bind variable to CSS', () => {
151151
`{/each}<style module>:global(div){color:var(--color-123)}</style>`
152152
);
153153
});
154+
155+
test('root elements has `each` statement', async () => {
156+
const output = await compiler({
157+
source: `${script}` +
158+
`{#await promise}` +
159+
`<p>...waiting</p>` +
160+
`{:then number}` +
161+
`<p>The number is {number}</p>` +
162+
`{:catch error}` +
163+
`<p>{error.message}</p>` +
164+
`{/await}` +
165+
`{#await promise then value}` +
166+
`<p>the value is {value}</p>` +
167+
`{/await}<style module>div{color:bind(color)}</style>`,
168+
}, {
169+
cssVariableHash: '123',
170+
});
171+
172+
expect(output).toBe(
173+
`${script}` +
174+
`{#await promise}` +
175+
`<p style="--color-123:{color};">...waiting</p>` +
176+
`{:then number}` +
177+
`<p style="--color-123:{color};">The number is {number}</p>` +
178+
`{:catch error}` +
179+
`<p style="--color-123:{color};">{error.message}</p>` +
180+
`{/await}` +
181+
`{#await promise then value}` +
182+
`<p style="--color-123:{color};">the value is {value}</p>` +
183+
`{/await}<style module>:global(div){color:var(--color-123)}</style>`
184+
);
185+
});
154186
});

0 commit comments

Comments
 (0)