Skip to content

Commit 41a23a1

Browse files
committed
fix bitmask overflow if initial dirty value
1 parent 926a2ae commit 41a23a1

File tree

5 files changed

+105
-4
lines changed

5 files changed

+105
-4
lines changed

src/compiler/compile/render_dom/Renderer.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,7 @@ export default class Renderer {
230230
return bitmask;
231231
};
232232

233+
// TODO: context-overflow make it less gross
233234
return {
234235
// Using a ParenthesizedExpression allows us to create
235236
// the expression lazily. TODO would be better if

src/compiler/compile/render_dom/wrappers/IfBlock.ts

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,7 @@ export default class IfBlockWrapper extends Wrapper {
288288
}
289289

290290
block.chunks.init.push(b`
291-
let ${current_block_type} = ${select_block_type}(#ctx, -1);
291+
let ${current_block_type} = ${select_block_type}(#ctx, ${this.get_initial_dirty_bit()});
292292
let ${name} = ${get_block};
293293
`);
294294

@@ -407,12 +407,12 @@ export default class IfBlockWrapper extends Wrapper {
407407

408408
if (has_else) {
409409
block.chunks.init.push(b`
410-
${current_block_type_index} = ${select_block_type}(#ctx, -1);
410+
${current_block_type_index} = ${select_block_type}(#ctx, ${this.get_initial_dirty_bit()});
411411
${name} = ${if_blocks}[${current_block_type_index}] = ${if_block_creators}[${current_block_type_index}](#ctx);
412412
`);
413413
} else {
414414
block.chunks.init.push(b`
415-
if (~(${current_block_type_index} = ${select_block_type}(#ctx, -1))) {
415+
if (~(${current_block_type_index} = ${select_block_type}(#ctx, ${this.get_initial_dirty_bit()}))) {
416416
${name} = ${if_blocks}[${current_block_type_index}] = ${if_block_creators}[${current_block_type_index}](#ctx);
417417
}
418418
`);
@@ -587,4 +587,18 @@ export default class IfBlockWrapper extends Wrapper {
587587
`);
588588
}
589589
}
590+
591+
get_initial_dirty_bit() {
592+
const _this = this;
593+
// TODO: context-overflow make it less gross
594+
595+
const val = x`-1`;
596+
return {
597+
...val,
598+
elements: [val],
599+
get type() {
600+
return _this.renderer.context_overflow ? 'ArrayExpression' : 'UnaryExpression';
601+
},
602+
};
603+
}
590604
}

src/compiler/compile/render_dom/wrappers/shared/get_slot_definition.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ export function get_slot_definition(block: Block, scope: TemplateScope, lets: Le
6363
const { context_lookup } = block.renderer;
6464

6565
// i am well aware that this code is gross
66-
// TODO make it less gross
66+
// TODO: context-overflow make it less gross
6767
const changes = {
6868
type: 'ParenthesizedExpression',
6969
get expression() {
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
export default {
2+
html: `
3+
012345678910111213141516171819202122232425262728293031323334353637383940
4+
expected: true
5+
if: true
6+
<button></button>
7+
`,
8+
9+
async test({ assert, component, target, window }) {
10+
const button = target.querySelector("button");
11+
await button.dispatchEvent(new window.MouseEvent("click"));
12+
13+
assert.htmlEqual(
14+
target.innerHTML,
15+
`
16+
112345678910111213141516171819202122232425262728293031323334353637383940
17+
expected: false
18+
if: false
19+
<div></div>
20+
<button></button>
21+
`
22+
);
23+
}
24+
};
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
<script>
2+
import { fade } from 'svelte/transition';
3+
export let _a = [];
4+
export let _0 = '0';
5+
export let _1 = '1';
6+
export let _2 = '2';
7+
export let _3 = '3';
8+
export let _4 = '4';
9+
export let _5 = '5';
10+
export let _6 = '6';
11+
export let _7 = '7';
12+
export let _8 = '8';
13+
export let _9 = '9';
14+
export let _10 = '10';
15+
export let _11 = '11';
16+
export let _12 = '12';
17+
export let _13 = '13';
18+
export let _14 = '14';
19+
export let _15 = '15';
20+
export let _16 = '16';
21+
export let _17 = '17';
22+
export let _18 = '18';
23+
export let _19 = '19';
24+
export let _20 = '20';
25+
export let _21 = '21';
26+
export let _22 = '22';
27+
export let _23 = '23';
28+
export let _24 = '24';
29+
export let _25 = '25';
30+
export let _26 = '26';
31+
export let _27 = '27';
32+
export let _28 = '28';
33+
export let _29 = '29';
34+
export let _30 = '30';
35+
export let _31 = '31';
36+
export let _32 = '32';
37+
export let _33 = '33';
38+
export let _34 = '34';
39+
export let _35 = '35';
40+
export let _36 = '36';
41+
export let _37 = '37';
42+
export let _38 = '38';
43+
export let _39 = '39';
44+
export let _40 = '40';
45+
46+
function update() {
47+
_0 = '1';
48+
}
49+
</script>
50+
51+
52+
{_0}{_1}{_2}{_3}{_4}{_5}{_6}{_7}{_8}{_9}{_10}{_11}{_12}{_13}{_14}{_15}{_16}{_17}{_18}{_19}{_20}{_21}{_22}{_23}{_24}{_25}{_26}{_27}{_28}{_29}{_30}{_31}{_32}{_33}{_34}{_35}{_36}{_37}{_38}{_39}{_40}
53+
54+
expected: {_a.indexOf(_0) && _0 === '0' && _1 === '1'}
55+
{#if _a.indexOf(_0) && _0 === '0' && _1 === '1'}
56+
if: true
57+
{:else}
58+
if: false
59+
<div out:fade></div>
60+
{/if}
61+
62+
<button on:click={update}></button>

0 commit comments

Comments
 (0)