Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix order of html tags when if in key block #5685

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/compiler/compile/render_dom/wrappers/KeyBlock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export default class KeyBlockWrapper extends Wrapper {
renderer,
this.block,
node.children,
parent,
this,
strip_whitespace,
next_sibling
);
Expand Down
21 changes: 21 additions & 0 deletions test/runtime/samples/key-block-static-if/_config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
export default {
html: `
<section>
<div>Second</div>
</section>
<button>Click</button>
`,
async test({ assert, component, target, window }) {
const button = target.querySelector('button');

await button.dispatchEvent(new window.Event('click'));

assert.htmlEqual(target.innerHTML, `
<section>
<div>First</div>
<div>Second</div>
</section>
<button>Click</button>
`);
}
};
17 changes: 17 additions & 0 deletions test/runtime/samples/key-block-static-if/main.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<script>
let slide = 0;
let num = false;

const changeNum = () => num = !num;
</script>

<section>
{#key slide}
{#if num}
<div>First</div>
{/if}
{/key}
<div>Second</div>
</section>

<button on:click={changeNum}>Click</button>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

eslint enforces a new line at the end of files, but it looks like we have only set it up to run against js and ts files (probably because we have some .svelte files in the test with purposefully malformed content for testing)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

eslint-plugin-svelte3 wouldn't complain about this anyway. The linting rules just apply to the parts that are JS (the script tags and the template expressions), and it doesn't extrapolate any of them to the component itself.