Skip to content

Commit fa2ab0e

Browse files
Traverse await expression blocks in Svelte (#118)
* Traverse await expression blocks in Svelte * Update changelog
1 parent 4949f79 commit fa2ab0e

File tree

3 files changed

+18
-1
lines changed

3 files changed

+18
-1
lines changed

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## [Unreleased]
99

10-
- Nothing yet!
10+
- Add prettier plugins to peer dependencies ([#114](https://github.com/tailwindlabs/prettier-plugin-tailwindcss/pull/114))
11+
- Traverse await expression blocks in Svelte ([#118](https://github.com/tailwindlabs/prettier-plugin-tailwindcss/pull/118))
1112

1213
## [0.2.1] - 2022-12-08
1314

src/index.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -746,6 +746,14 @@ function transformSvelte(ast, { env, changes }) {
746746
transformSvelte(child, { env, changes })
747747
}
748748
}
749+
750+
if (ast.type === "AwaitBlock") {
751+
let nodes = [ast.pending, ast.then, ast.catch];
752+
753+
for (let child of nodes) {
754+
transformSvelte(child, { env, changes });
755+
}
756+
}
749757
}
750758

751759
// https://lihautan.com/manipulating-ast-with-javascript/

tests/test.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,14 @@ let tests = {
225225
`<div class="p-0 sm:p-0 {someVar}sm:block flex md:inline" />`,
226226
],
227227
['<div class={`sm:p-0\np-0`} />', '<div\n class={`p-0\nsm:p-0`}\n/>'],
228+
[
229+
`{#await promise()} <div class="sm:p-0 p-0"></div> {:then} <div class="sm:p-0 p-0"></div> {/await}`,
230+
`{#await promise()} <div class="p-0 sm:p-0" /> {:then} <div class="p-0 sm:p-0" /> {/await}`,
231+
],
232+
[
233+
`{#await promise() then} <div class="sm:p-0 p-0"></div> {/await}`,
234+
`{#await promise() then} <div class="p-0 sm:p-0" /> {/await}`,
235+
],
228236
],
229237
astro: [
230238
...html,

0 commit comments

Comments
 (0)