Skip to content

Commit

Permalink
Traverse await expression blocks in Svelte (#118)
Browse files Browse the repository at this point in the history
* Traverse await expression blocks in Svelte

* Update changelog
  • Loading branch information
thecrypticace committed Jan 24, 2023
1 parent 4949f79 commit fa2ab0e
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 1 deletion.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Expand Up @@ -7,7 +7,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

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

## [0.2.1] - 2022-12-08

Expand Down
8 changes: 8 additions & 0 deletions src/index.js
Expand Up @@ -746,6 +746,14 @@ function transformSvelte(ast, { env, changes }) {
transformSvelte(child, { env, changes })
}
}

if (ast.type === "AwaitBlock") {
let nodes = [ast.pending, ast.then, ast.catch];

for (let child of nodes) {
transformSvelte(child, { env, changes });
}
}
}

// https://lihautan.com/manipulating-ast-with-javascript/
Expand Down
8 changes: 8 additions & 0 deletions tests/test.js
Expand Up @@ -225,6 +225,14 @@ let tests = {
`<div class="p-0 sm:p-0 {someVar}sm:block flex md:inline" />`,
],
['<div class={`sm:p-0\np-0`} />', '<div\n class={`p-0\nsm:p-0`}\n/>'],
[
`{#await promise()} <div class="sm:p-0 p-0"></div> {:then} <div class="sm:p-0 p-0"></div> {/await}`,
`{#await promise()} <div class="p-0 sm:p-0" /> {:then} <div class="p-0 sm:p-0" /> {/await}`,
],
[
`{#await promise() then} <div class="sm:p-0 p-0"></div> {/await}`,
`{#await promise() then} <div class="p-0 sm:p-0" /> {/await}`,
],
],
astro: [
...html,
Expand Down

0 comments on commit fa2ab0e

Please sign in to comment.