Skip to content

Commit 8feb85a

Browse files
authored
fix bitmask overflow for slot (#4485)
1 parent cf660bd commit 8feb85a

File tree

11 files changed

+195
-1
lines changed

11 files changed

+195
-1
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
* In `vars` array, correctly indicate whether `module` variables are `mutated` or `reassigned` ([#3215](https://github.com/sveltejs/svelte/issues/3215))
66
* Exclude global variables from `$capture_state` ([#4463](https://github.com/sveltejs/svelte/issues/4463))
7+
* Fix bitmask overflow for slots ([#4481](https://github.com/sveltejs/svelte/issues/4481))
78

89
## 3.19.1
910

src/runtime/internal/utils.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,11 @@ export function get_slot_changes(definition, $$scope, dirty, fn) {
8383
if (definition[2] && fn) {
8484
const lets = definition[2](fn(dirty));
8585

86-
if (typeof $$scope.dirty === 'object') {
86+
if ($$scope.dirty === undefined) {
87+
return lets;
88+
}
89+
90+
if (typeof lets === 'object') {
8791
const merged = [];
8892
const len = Math.max($$scope.dirty.length, lets.length);
8993
for (let i = 0; i < len; i += 1) {
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<script>
2+
let dummy = 0;
3+
function increment () {
4+
dummy = 1;
5+
}
6+
</script>
7+
8+
<slot dummy={dummy}></slot>
9+
<button on:click={increment}></button>
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
export default {
2+
3+
html: `
4+
<p>_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</p>
5+
<p>0</p>
6+
<button></button>
7+
`,
8+
9+
async test({ assert, component, target, window }) {
10+
// change from inside
11+
const button = target.querySelector('button');
12+
await button.dispatchEvent(new window.MouseEvent('click'));
13+
14+
assert.htmlEqual(target.innerHTML, `
15+
<p>_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</p>
16+
<p>1</p>
17+
<button></button>
18+
`);
19+
20+
// change from outside
21+
component._0 = 'a';
22+
component._40 = 'b';
23+
24+
assert.htmlEqual(target.innerHTML, `
25+
<p>a_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_39b</p>
26+
<p>1</p>
27+
<button></button>
28+
`);
29+
}
30+
};
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<script>
2+
import Echo from './Echo.svelte';
3+
4+
export let _0 = '_0', _1 = '_1', _2 = '_2', _3 = '_3', _4 = '_4', _5 = '_5', _6 = '_6', _7 = '_7', _8 = '_8', _9 = '_9', _10 = '_10', _11 = '_11', _12 = '_12', _13 = '_13', _14 = '_14', _15 = '_15', _16 = '_16', _17 = '_17', _18 = '_18', _19 = '_19', _20 = '_20', _21 = '_21', _22 = '_22', _23 = '_23', _24 = '_24', _25 = '_25', _26 = '_26', _27 = '_27', _28 = '_28', _29 = '_29', _30 = '_30', _31 = '_31', _32 = '_32', _33 = '_33', _34 = '_34', _35 = '_35', _36 = '_36', _37 = '_37', _38 = '_38', _39 = '_39', _40 = '_40';
5+
</script>
6+
7+
<Echo let:dummy>
8+
<p>{_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}</p>
9+
<p>{dummy}</p>
10+
</Echo>
11+
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<script>
2+
export let _0 = '_0', _1 = '_1', _2 = '_2', _3 = '_3', _4 = '_4', _5 = '_5', _6 = '_6', _7 = '_7', _8 = '_8', _9 = '_9', _10 = '_10', _11 = '_11', _12 = '_12', _13 = '_13', _14 = '_14', _15 = '_15', _16 = '_16', _17 = '_17', _18 = '_18', _19 = '_19', _20 = '_20', _21 = '_21', _22 = '_22', _23 = '_23', _24 = '_24', _25 = '_25', _26 = '_26', _27 = '_27', _28 = '_28', _29 = '_29', _30 = '_30', _31 = '_31', _32 = '_32', _33 = '_33', _34 = '_34', _35 = '_35', _36 = '_36', _37 = '_37', _38 = '_38', _39 = '_39', _40 = '_40';
3+
let dummy = 0;
4+
function increment () {
5+
dummy = 1;
6+
}
7+
</script>
8+
9+
<p>{_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}</p>
10+
<slot dummy={dummy}></slot>
11+
<button on:click={increment}></button>
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
export default {
2+
html: `
3+
<p>_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</p>
4+
<p>0</p>
5+
<p>0</p>
6+
<button></button>
7+
`,
8+
9+
async test({ assert, component, target, window }) {
10+
// change from inside
11+
const button = target.querySelector('button');
12+
await button.dispatchEvent(new window.MouseEvent('click'));
13+
14+
assert.htmlEqual(target.innerHTML, `
15+
<p>_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</p>
16+
<p>0</p>
17+
<p>1</p>
18+
<button></button>
19+
`);
20+
21+
// change from outside
22+
component._0 = 'a';
23+
24+
assert.htmlEqual(target.innerHTML, `
25+
<p>_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</p>
26+
<p>a</p>
27+
<p>1</p>
28+
<button></button>
29+
`);
30+
31+
// change from outside through props
32+
component._40 = 'b';
33+
34+
assert.htmlEqual(target.innerHTML, `
35+
<p>_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_39b</p>
36+
<p>a</p>
37+
<p>1</p>
38+
<button></button>
39+
`);
40+
}
41+
};
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<script>
2+
import Echo from './Echo.svelte';
3+
4+
export let _0 = 0, _40;
5+
6+
</script>
7+
8+
<Echo _40={_40} let:dummy>
9+
<p>{_0}</p>
10+
<p>{dummy}</p>
11+
</Echo>
12+
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<script>
2+
export let _0 = '_0', _1 = '_1', _2 = '_2', _3 = '_3', _4 = '_4', _5 = '_5', _6 = '_6', _7 = '_7', _8 = '_8', _9 = '_9', _10 = '_10', _11 = '_11', _12 = '_12', _13 = '_13', _14 = '_14', _15 = '_15', _16 = '_16', _17 = '_17', _18 = '_18', _19 = '_19', _20 = '_20', _21 = '_21', _22 = '_22', _23 = '_23', _24 = '_24', _25 = '_25', _26 = '_26', _27 = '_27', _28 = '_28', _29 = '_29', _30 = '_30', _31 = '_31', _32 = '_32', _33 = '_33', _34 = '_34', _35 = '_35', _36 = '_36', _37 = '_37', _38 = '_38', _39 = '_39', _40 = '_40';
3+
export let b = 'b';
4+
let dummy = 0;
5+
function increment () {
6+
dummy = 1;
7+
}
8+
</script>
9+
10+
<p>{_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}</p>
11+
<p>{b}</p>
12+
<slot dummy={dummy}></slot>
13+
<button on:click={increment}></button>
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
export default {
2+
html: `
3+
<p>_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</p>
4+
<p>b</p>
5+
<p>-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</p>
6+
<p>0</p>
7+
<p>0</p>
8+
<button></button>
9+
`,
10+
11+
async test({ assert, component, target, window }) {
12+
// change from inside
13+
const button = target.querySelector('button');
14+
await button.dispatchEvent(new window.MouseEvent('click'));
15+
16+
assert.htmlEqual(target.innerHTML, `
17+
<p>_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</p>
18+
<p>b</p>
19+
<p>-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</p>
20+
<p>0</p>
21+
<p>1</p>
22+
<button></button>
23+
`);
24+
25+
// change from outside
26+
component.a = 'AA';
27+
28+
assert.htmlEqual(target.innerHTML, `
29+
<p>_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</p>
30+
<p>b</p>
31+
<p>-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</p>
32+
<p>AA</p>
33+
<p>1</p>
34+
<button></button>
35+
`);
36+
37+
// change from outside through props
38+
component.b = 'BB';
39+
40+
assert.htmlEqual(target.innerHTML, `
41+
<p>_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</p>
42+
<p>BB</p>
43+
<p>-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</p>
44+
<p>AA</p>
45+
<p>1</p>
46+
<button></button>
47+
`);
48+
}
49+
};
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<script>
2+
import Echo from './Echo.svelte';
3+
export let _0 = '-0', _1 = '-1', _2 = '-2', _3 = '-3', _4 = '-4', _5 = '-5', _6 = '-6', _7 = '-7', _8 = '-8', _9 = '-9', _10 = '-10', _11 = '-11', _12 = '-12', _13 = '-13', _14 = '-14', _15 = '-15', _16 = '-16', _17 = '-17', _18 = '-18', _19 = '-19', _20 = '-20', _21 = '-21', _22 = '-22', _23 = '-23', _24 = '-24', _25 = '-25', _26 = '-26', _27 = '-27', _28 = '-28', _29 = '-29', _30 = '-30', _31 = '-31', _32 = '-32', _33 = '-33', _34 = '-34', _35 = '-35', _36 = '-36', _37 = '-37', _38 = '-38', _39 = '-39', _40 = '-40';
4+
export let a = 0, b;
5+
6+
</script>
7+
8+
<Echo b={b} let:dummy>
9+
<p>{_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}</p>
10+
<p>{a}</p>
11+
<p>{dummy}</p>
12+
</Echo>
13+

0 commit comments

Comments
 (0)