mirror of https://github.com/sveltejs/svelte
fix: correctly add `__svelte_meta` after else-if chains (#17830)
While looking into something else I spotted the fact that we use `false`
to indicate 'else' in an `{#if ...}` block (whether there's an `else`
block to render or not). If we instead use `-1`, and use `<!--[0-->` to
indicate that the first block in an if-elseif chain was rendered...
- instead of `<!--[-->`, we do `<!--[0-->`
- instead of `<!--[!-->`, we do `<!--[-1-->`
- all others stay the same
...we can simplify things a bit — the `key` argument to `update_branch`
is always a number (which probably has some microscopic benefits in
terms of making it monomorphic when `else` is defined, and less
polymorphic when it isn't), and the hydration mismatch code only needs
to consider one type of hydration marker.
In the process, I discovered a bug — the dev-time `add_locations`
function fails on hydration markers like `<!--[1-->`. This PR fixes it.
pull/17842/head
parent
7717ba01b4
commit
86ec210866
@ -0,0 +1,5 @@
|
||||
---
|
||||
'svelte': patch
|
||||
---
|
||||
|
||||
fix: correctly add \_\_svelte_meta after else-if chains
|
||||
@ -0,0 +1,35 @@
|
||||
import { flushSync } from 'svelte';
|
||||
import { test } from '../../test';
|
||||
|
||||
export default test({
|
||||
compileOptions: {
|
||||
dev: true
|
||||
},
|
||||
|
||||
html: `<p>before</p><p>during</p><p>after</p>`,
|
||||
|
||||
async test({ target, assert }) {
|
||||
const ps = target.querySelectorAll('p');
|
||||
|
||||
// @ts-expect-error
|
||||
assert.deepEqual(ps[0].__svelte_meta.loc, {
|
||||
file: 'main.svelte',
|
||||
line: 1,
|
||||
column: 0
|
||||
});
|
||||
|
||||
// @ts-expect-error
|
||||
assert.deepEqual(ps[1].__svelte_meta.loc, {
|
||||
file: 'main.svelte',
|
||||
line: 6,
|
||||
column: 1
|
||||
});
|
||||
|
||||
// @ts-expect-error
|
||||
assert.deepEqual(ps[2].__svelte_meta.loc, {
|
||||
file: 'main.svelte',
|
||||
line: 11,
|
||||
column: 0
|
||||
});
|
||||
}
|
||||
});
|
||||
@ -0,0 +1,11 @@
|
||||
<p>before</p>
|
||||
|
||||
{#if false}
|
||||
<p>during</p>
|
||||
{:else if true}
|
||||
<p>during</p>
|
||||
{:else if false}
|
||||
<p>during</p>
|
||||
{/if}
|
||||
|
||||
<p>after</p>
|
||||
Loading…
Reference in new issue