Skip to content

Commit f8a4656

Browse files
committed
1 parent 55f0eb2 commit f8a4656

File tree

52 files changed

+163
-140
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+163
-140
lines changed

src/compiler/compile/render_dom/Block.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import Renderer from './Renderer';
22
import Wrapper from './wrappers/shared/Wrapper';
33
import { b, x } from 'code-red';
4-
import { Node, Identifier } from 'estree';
4+
import { Node, Identifier, ArrayPattern } from 'estree';
55
import { is_head } from './wrappers/shared/is_head';
66

77
export interface BlockOptions {
@@ -301,7 +301,12 @@ export default class Block {
301301
} else {
302302
const ctx = this.maintain_context ? x`#new_ctx` : x`#ctx`;
303303

304-
properties.update = x`function #update(${ctx}, #dirty) {
304+
let dirty: Identifier | ArrayPattern = { type: 'Identifier', name: '#dirty' };
305+
if (!this.renderer.context_overflow && !this.parent) {
306+
dirty = { type: 'ArrayPattern', elements: [dirty] };
307+
}
308+
309+
properties.update = x`function #update(${ctx}, ${dirty}) {
305310
${this.maintain_context && b`#ctx = ${ctx};`}
306311
${this.chunks.update}
307312
}`;

src/compiler/compile/render_dom/Renderer.ts

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ export default class Renderer {
2626

2727
context: ContextMember[] = [];
2828
context_lookup: Map<string, ContextMember> = new Map();
29+
context_overflow: boolean;
2930
blocks: Array<Block | Node | Node[]> = [];
3031
readonly: Set<string> = new Set();
3132
meta_bindings: Array<Node | Node[]> = []; // initial values for e.g. window.innerWidth, if there's a <svelte:window> meta tag
@@ -96,6 +97,8 @@ export default class Renderer {
9697

9798
this.fragment.render(this.block, null, x`#nodes` as Identifier);
9899

100+
this.context_overflow = this.context.length > 31;
101+
99102
this.context.forEach(member => {
100103
const { variable } = member;
101104
if (variable) {
@@ -237,11 +240,15 @@ export default class Renderer {
237240
return x`${dirty} & /*${names.join(', ')}*/ 0` as BinaryExpression;
238241
}
239242

240-
return bitmask
241-
.map((b, i) => ({ b, i }))
242-
.filter(({ b }) => b)
243-
.map(({ b, i }) => x`${dirty}[${i}] & /*${b.names.join(', ')}*/ ${b.n}`)
244-
.reduce((lhs, rhs) => x`${lhs} | ${rhs}`);
243+
if (renderer.context_overflow) {
244+
return bitmask
245+
.map((b, i) => ({ b, i }))
246+
.filter(({ b }) => b)
247+
.map(({ b, i }) => x`${dirty}[${i}] & /*${b.names.join(', ')}*/ ${b.n}`)
248+
.reduce((lhs, rhs) => x`${lhs} | ${rhs}`);
249+
}
250+
251+
return x`${dirty} & /*${names.join(', ')}*/ ${bitmask[0].n}` as BinaryExpression;
245252
}
246253
} as any;
247254
}

src/compiler/compile/render_dom/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -429,7 +429,7 @@ export default function dom(
429429
}` as ObjectExpression;
430430

431431
let dirty;
432-
if (renderer.context.length > 31) {
432+
if (renderer.context_overflow) {
433433
dirty = x`[]`;
434434
for (let i = 0; i < renderer.context.length; i += 31) {
435435
dirty.elements.push(x`-1`);

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

Lines changed: 28 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import Let from '../../../nodes/Let';
22
import { x, p } from 'code-red';
33
import Block from '../../Block';
44
import TemplateScope from '../../../nodes/shared/TemplateScope';
5+
import { BinaryExpression } from 'estree';
56

67
export function get_slot_definition(block: Block, scope: TemplateScope, lets: Let[]) {
78
if (lets.length === 0) return { block, scope };
@@ -35,30 +36,39 @@ export function get_slot_definition(block: Block, scope: TemplateScope, lets: Le
3536
const changes = {
3637
type: 'ParenthesizedExpression',
3738
get expression() {
38-
const grouped = [];
39+
if (block.renderer.context_overflow) {
40+
const grouped = [];
3941

40-
Array.from(names).forEach(name => {
41-
const i = context_lookup.get(name).index.value as number;
42-
const g = Math.floor(i / 31);
42+
Array.from(names).forEach(name => {
43+
const i = context_lookup.get(name).index.value as number;
44+
const g = Math.floor(i / 31);
4345

44-
if (!grouped[g]) grouped[g] = [];
45-
grouped[g].push({ name, n: i % 31 });
46-
});
46+
if (!grouped[g]) grouped[g] = [];
47+
grouped[g].push({ name, n: i % 31 });
48+
});
4749

48-
const elements = [];
50+
const elements = [];
4951

50-
for (let g = 0; g < grouped.length; g += 1) {
51-
elements[g] = grouped[g]
52-
? grouped[g]
53-
.map(({ name, n }) => x`${name} ? ${1 << n} : 0`)
54-
.reduce((lhs, rhs) => x`${lhs} | ${rhs}`)
55-
: x`0`;
52+
for (let g = 0; g < grouped.length; g += 1) {
53+
elements[g] = grouped[g]
54+
? grouped[g]
55+
.map(({ name, n }) => x`${name} ? ${1 << n} : 0`)
56+
.reduce((lhs, rhs) => x`${lhs} | ${rhs}`)
57+
: x`0`;
58+
}
59+
60+
return {
61+
type: 'ArrayExpression',
62+
elements
63+
};
5664
}
5765

58-
return {
59-
type: 'ArrayExpression',
60-
elements
61-
};
66+
return Array.from(names)
67+
.map(name => {
68+
const i = context_lookup.get(name).index.value as number;
69+
return x`${name} ? ${1 << i} : 0`;
70+
})
71+
.reduce((lhs, rhs) => x`${lhs} | ${rhs}`) as BinaryExpression;
6272
}
6373
};
6474

src/runtime/internal/utils.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,16 +80,17 @@ export function get_slot_changes(definition, $$scope, dirty, fn) {
8080
if (definition[2] && fn) {
8181
const lets = definition[2](fn(dirty));
8282

83-
if ($$scope.dirty) {
83+
if (typeof $$scope.dirty === 'object') {
8484
const merged = [];
8585
const len = Math.max($$scope.dirty.length, lets.length);
8686
for (let i = 0; i < len; i += 1) {
8787
merged[i] = $$scope.dirty[i] | lets[i];
8888
}
89+
8990
return merged;
9091
}
9192

92-
return lets;
93+
return $$scope.dirty | lets;
9394
}
9495

9596
return $$scope.dirty;

test/js/samples/action-custom-event-handler/expected.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ function create_fragment(ctx) {
2323
insert(target, button, anchor);
2424
foo_action = foo.call(null, button, /*foo_function*/ ctx[1]) || ({});
2525
},
26-
p(ctx, dirty) {
27-
if (is_function(foo_action.update) && dirty[0] & /*bar*/ 1) foo_action.update.call(null, /*foo_function*/ ctx[1]);
26+
p(ctx, [dirty]) {
27+
if (is_function(foo_action.update) && dirty & /*bar*/ 1) foo_action.update.call(null, /*foo_function*/ ctx[1]);
2828
},
2929
i: noop,
3030
o: noop,

test/js/samples/bind-open/expected.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ function create_fragment(ctx) {
2727
insert(target, details, anchor);
2828
details.open = /*open*/ ctx[0];
2929
},
30-
p(ctx, dirty) {
31-
if (dirty[0] & /*open*/ 1) {
30+
p(ctx, [dirty]) {
31+
if (dirty & /*open*/ 1) {
3232
details.open = /*open*/ ctx[0];
3333
}
3434
},

test/js/samples/capture-inject-dev-only/expected.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,10 @@ function create_fragment(ctx) {
3737
insert(target, input, anchor);
3838
set_input_value(input, /*foo*/ ctx[0]);
3939
},
40-
p(ctx, dirty) {
41-
if (dirty[0] & /*foo*/ 1) set_data(t0, /*foo*/ ctx[0]);
40+
p(ctx, [dirty]) {
41+
if (dirty & /*foo*/ 1) set_data(t0, /*foo*/ ctx[0]);
4242

43-
if (dirty[0] & /*foo*/ 1 && input.value !== /*foo*/ ctx[0]) {
43+
if (dirty & /*foo*/ 1 && input.value !== /*foo*/ ctx[0]) {
4444
set_input_value(input, /*foo*/ ctx[0]);
4545
}
4646
},

test/js/samples/collapses-text-around-comments/expected.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ function create_fragment(ctx) {
3434
insert(target, p, anchor);
3535
append(p, t);
3636
},
37-
p(ctx, dirty) {
38-
if (dirty[0] & /*foo*/ 1) set_data(t, /*foo*/ ctx[0]);
37+
p(ctx, [dirty]) {
38+
if (dirty & /*foo*/ 1) set_data(t, /*foo*/ ctx[0]);
3939
},
4040
i: noop,
4141
o: noop,

test/js/samples/component-static-var/expected.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,12 +46,12 @@ function create_fragment(ctx) {
4646
set_input_value(input, /*z*/ ctx[0]);
4747
current = true;
4848
},
49-
p(ctx, dirty) {
49+
p(ctx, [dirty]) {
5050
const bar_changes = {};
51-
if (dirty[0] & /*z*/ 1) bar_changes.x = /*z*/ ctx[0];
51+
if (dirty & /*z*/ 1) bar_changes.x = /*z*/ ctx[0];
5252
bar.$set(bar_changes);
5353

54-
if (dirty[0] & /*z*/ 1 && input.value !== /*z*/ ctx[0]) {
54+
if (dirty & /*z*/ 1 && input.value !== /*z*/ ctx[0]) {
5555
set_input_value(input, /*z*/ ctx[0]);
5656
}
5757
},

test/js/samples/component-store-access-invalidate/expected.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ function create_fragment(ctx) {
2828
insert(target, h1, anchor);
2929
append(h1, t);
3030
},
31-
p(ctx, dirty) {
32-
if (dirty[0] & /*$foo*/ 1) set_data(t, /*$foo*/ ctx[0]);
31+
p(ctx, [dirty]) {
32+
if (dirty & /*$foo*/ 1) set_data(t, /*$foo*/ ctx[0]);
3333
},
3434
i: noop,
3535
o: noop,

test/js/samples/component-store-reassign-invalidate/expected.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@ function create_fragment(ctx) {
3939
insert(target, t1, anchor);
4040
insert(target, button, anchor);
4141
},
42-
p(ctx, dirty) {
43-
if (dirty[0] & /*$foo*/ 2) set_data(t0, /*$foo*/ ctx[1]);
42+
p(ctx, [dirty]) {
43+
if (dirty & /*$foo*/ 2) set_data(t0, /*$foo*/ ctx[1]);
4444
},
4545
i: noop,
4646
o: noop,

test/js/samples/data-attribute/expected.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ function create_fragment(ctx) {
2929
insert(target, t, anchor);
3030
insert(target, div1, anchor);
3131
},
32-
p(ctx, dirty) {
33-
if (dirty[0] & /*bar*/ 1) {
32+
p(ctx, [dirty]) {
33+
if (dirty & /*bar*/ 1) {
3434
attr(div1, "data-foo", /*bar*/ ctx[0]);
3535
}
3636
},

test/js/samples/debug-empty/expected.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,8 @@ function create_fragment(ctx) {
4444
append_dev(h1, t2);
4545
insert_dev(target, t3, anchor);
4646
},
47-
p: function update(ctx, dirty) {
48-
if (dirty[0] & /*name*/ 1) set_data_dev(t1, /*name*/ ctx[0]);
47+
p: function update(ctx, [dirty]) {
48+
if (dirty & /*name*/ 1) set_data_dev(t1, /*name*/ ctx[0]);
4949
debugger;
5050
},
5151
i: noop,

test/js/samples/debug-foo-bar-baz-things/expected.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,9 @@ function create_each_block(ctx) {
5454
insert_dev(target, t1, anchor);
5555
},
5656
p: function update(ctx, dirty) {
57-
if (dirty[0] & /*things*/ 1 && t0_value !== (t0_value = /*thing*/ ctx[4].name + "")) set_data_dev(t0, t0_value);
57+
if (dirty & /*things*/ 1 && t0_value !== (t0_value = /*thing*/ ctx[4].name + "")) set_data_dev(t0, t0_value);
5858

59-
if (dirty[0] & /*foo, bar, baz, things*/ 15) {
59+
if (dirty & /*foo, bar, baz, things*/ 15) {
6060
const foo = /*foo*/ ctx[1];
6161
const bar = /*bar*/ ctx[2];
6262
const baz = /*baz*/ ctx[3];
@@ -119,8 +119,8 @@ function create_fragment(ctx) {
119119
append_dev(p, t1);
120120
append_dev(p, t2);
121121
},
122-
p: function update(ctx, dirty) {
123-
if (dirty[0] & /*things*/ 1) {
122+
p: function update(ctx, [dirty]) {
123+
if (dirty & /*things*/ 1) {
124124
each_value = /*things*/ ctx[0];
125125
let i;
126126

@@ -143,7 +143,7 @@ function create_fragment(ctx) {
143143
each_blocks.length = each_value.length;
144144
}
145145

146-
if (dirty[0] & /*foo*/ 2) set_data_dev(t2, /*foo*/ ctx[1]);
146+
if (dirty & /*foo*/ 2) set_data_dev(t2, /*foo*/ ctx[1]);
147147
},
148148
i: noop,
149149
o: noop,

test/js/samples/debug-foo/expected.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,9 @@ function create_each_block(ctx) {
5151
insert_dev(target, t1, anchor);
5252
},
5353
p: function update(ctx, dirty) {
54-
if (dirty[0] & /*things*/ 1 && t0_value !== (t0_value = /*thing*/ ctx[2].name + "")) set_data_dev(t0, t0_value);
54+
if (dirty & /*things*/ 1 && t0_value !== (t0_value = /*thing*/ ctx[2].name + "")) set_data_dev(t0, t0_value);
5555

56-
if (dirty[0] & /*foo*/ 2) {
56+
if (dirty & /*foo*/ 2) {
5757
const foo = /*foo*/ ctx[1];
5858
console.log({ foo });
5959
debugger;
@@ -113,8 +113,8 @@ function create_fragment(ctx) {
113113
append_dev(p, t1);
114114
append_dev(p, t2);
115115
},
116-
p: function update(ctx, dirty) {
117-
if (dirty[0] & /*things*/ 1) {
116+
p: function update(ctx, [dirty]) {
117+
if (dirty & /*things*/ 1) {
118118
each_value = /*things*/ ctx[0];
119119
let i;
120120

@@ -137,7 +137,7 @@ function create_fragment(ctx) {
137137
each_blocks.length = each_value.length;
138138
}
139139

140-
if (dirty[0] & /*foo*/ 2) set_data_dev(t2, /*foo*/ ctx[1]);
140+
if (dirty & /*foo*/ 2) set_data_dev(t2, /*foo*/ ctx[1]);
141141
},
142142
i: noop,
143143
o: noop,

test/js/samples/debug-hoisted/expected.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ function create_fragment(ctx) {
2323
throw new Error("options.hydrate only works if the component was compiled with the `hydratable: true` option");
2424
},
2525
m: noop,
26-
p: function update(ctx, dirty) {
27-
if (dirty[0] & /*obj, kobzol*/ 3) {
26+
p: function update(ctx, [dirty]) {
27+
if (dirty & /*obj, kobzol*/ 3) {
2828
const obj = /*obj*/ ctx[0];
2929
const kobzol = /*kobzol*/ ctx[1];
3030
console.log({ obj, kobzol });

test/js/samples/debug-no-dependencies/expected.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ function create_fragment(ctx) {
8888

8989
insert_dev(target, each_1_anchor, anchor);
9090
},
91-
p: function update(ctx, dirty) {
91+
p: function update(ctx, [dirty]) {
9292
if (dirty & /*things*/ 0) {
9393
each_value = things;
9494
let i;

test/js/samples/deconflict-builtins/expected.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ function create_each_block(ctx) {
3636
append(span, t);
3737
},
3838
p(ctx, dirty) {
39-
if (dirty[0] & /*createElement*/ 1 && t_value !== (t_value = /*node*/ ctx[1] + "")) set_data(t, t_value);
39+
if (dirty & /*createElement*/ 1 && t_value !== (t_value = /*node*/ ctx[1] + "")) set_data(t, t_value);
4040
},
4141
d(detaching) {
4242
if (detaching) detach(span);
@@ -68,8 +68,8 @@ function create_fragment(ctx) {
6868

6969
insert(target, each_1_anchor, anchor);
7070
},
71-
p(ctx, dirty) {
72-
if (dirty[0] & /*createElement*/ 1) {
71+
p(ctx, [dirty]) {
72+
if (dirty & /*createElement*/ 1) {
7373
each_value = /*createElement*/ ctx[0];
7474
let i;
7575

test/js/samples/dev-warning-missing-data-computed/expected.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,9 @@ function create_fragment(ctx) {
4141
append_dev(p, t1);
4242
append_dev(p, t2);
4343
},
44-
p: function update(ctx, dirty) {
45-
if (dirty[0] & /*foo*/ 1 && t0_value !== (t0_value = Math.max(0, /*foo*/ ctx[0]) + "")) set_data_dev(t0, t0_value);
46-
if (dirty[0] & /*bar*/ 2) set_data_dev(t2, /*bar*/ ctx[1]);
44+
p: function update(ctx, [dirty]) {
45+
if (dirty & /*foo*/ 1 && t0_value !== (t0_value = Math.max(0, /*foo*/ ctx[0]) + "")) set_data_dev(t0, t0_value);
46+
if (dirty & /*bar*/ 2) set_data_dev(t2, /*bar*/ ctx[1]);
4747
},
4848
i: noop,
4949
o: noop,
@@ -86,7 +86,7 @@ function instance($$self, $$props, $$invalidate) {
8686
};
8787

8888
$$self.$$.update = () => {
89-
if ($$self.$$.dirty[0] & /*foo*/ 1) {
89+
if ($$self.$$.dirty & /*foo*/ 1) {
9090
$: $$invalidate(1, bar = foo * 2);
9191
}
9292
};

0 commit comments

Comments
 (0)