Skip to content

Commit

Permalink
Fix sorting in Svelte :else blocks (#79)
Browse files Browse the repository at this point in the history
  • Loading branch information
bradlc committed May 16, 2022
1 parent fabc165 commit 4623589
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/index.js
Expand Up @@ -432,6 +432,12 @@ function transformSvelte(ast, { env, changes }) {
for (let child of ast.children ?? []) {
transformSvelte(child, { env, changes })
}

if (ast.type === 'IfBlock') {
for (let child of ast.else?.children ?? []) {
transformSvelte(child, { env, changes })
}
}
}

// https://lihautan.com/manipulating-ast-with-javascript/
Expand Down
1 change: 1 addition & 0 deletions tests/test.js
Expand Up @@ -165,6 +165,7 @@ let tests = {
t`<div class={\`${no}\${someVar}${no}\`} />`,
t`<div class="${yes} {\`${yes}\`}" />`,
t`<div let:class={clazz} class="${yes} {clazz}" />`,
t`{#if something} <div class="${yes}" /> {:else} <div class="${yes}" /> {/if}`,
[
`<div class="sm:block uppercase flex{someVar}" />`,
`<div class="uppercase sm:block flex{someVar}" />`,
Expand Down

0 comments on commit 4623589

Please sign in to comment.