-
-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Don't generate code for a non-updating if block
- Loading branch information
Showing
7 changed files
with
169 additions
and
59 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
/* generated by Svelte vX.Y.Z */ | ||
import { | ||
SvelteComponent, | ||
attr, | ||
detach, | ||
element, | ||
empty, | ||
init, | ||
insert, | ||
noop, | ||
safe_not_equal | ||
} from "svelte/internal"; | ||
|
||
// (7:0) {#if (item.divider && item.divider.includes(1))} | ||
function create_if_block(ctx) { | ||
var div; | ||
|
||
return { | ||
c() { | ||
div = element("div"); | ||
attr(div, "class", "divider"); | ||
}, | ||
|
||
m(target, anchor) { | ||
insert(target, div, anchor); | ||
}, | ||
|
||
d(detaching) { | ||
if (detaching) { | ||
detach(div); | ||
} | ||
} | ||
}; | ||
} | ||
|
||
function create_fragment(ctx) { | ||
var show_if = (ctx.item.divider && ctx.item.divider.includes(1)), if_block_anchor; | ||
|
||
var if_block = (show_if) && create_if_block(ctx); | ||
|
||
return { | ||
c() { | ||
if (if_block) if_block.c(); | ||
if_block_anchor = empty(); | ||
}, | ||
|
||
m(target, anchor) { | ||
if (if_block) if_block.m(target, anchor); | ||
insert(target, if_block_anchor, anchor); | ||
}, | ||
|
||
p: noop, | ||
i: noop, | ||
o: noop, | ||
|
||
d(detaching) { | ||
if (if_block) if_block.d(detaching); | ||
|
||
if (detaching) { | ||
detach(if_block_anchor); | ||
} | ||
} | ||
}; | ||
} | ||
|
||
function instance($$self) { | ||
let item = { | ||
divider: [1] | ||
} | ||
|
||
return { item }; | ||
} | ||
|
||
class Component extends SvelteComponent { | ||
constructor(options) { | ||
super(); | ||
init(this, options, instance, create_fragment, safe_not_equal, []); | ||
} | ||
} | ||
|
||
export default Component; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<script> | ||
let item = { | ||
divider: [1] | ||
} | ||
</script> | ||
|
||
{#if (item.divider && item.divider.includes(1))} | ||
<div class="divider"></div> | ||
{/if} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 12 additions & 0 deletions
12
test/runtime/samples/if-block-static-with-dynamic-contents/_config.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
export default { | ||
props: { | ||
foo: 42 | ||
}, | ||
|
||
html: '<p>42</p>', | ||
|
||
test({ assert, component, target }) { | ||
component.foo = 43; | ||
assert.htmlEqual(target.innerHTML, '<p>43</p>'); | ||
} | ||
}; |
9 changes: 9 additions & 0 deletions
9
test/runtime/samples/if-block-static-with-dynamic-contents/main.svelte
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<script> | ||
export let foo; | ||
const show = () => true; | ||
</script> | ||
|
||
{#if show()} | ||
<p>{foo}</p> | ||
{/if} |