Skip to content

Commit c6d2cdd

Browse files
authored
Merge pull request #1940 from sveltejs/remove-component-references
Remove component references
2 parents b87f930 + 179d083 commit c6d2cdd

File tree

59 files changed

+119
-123
lines changed

Some content is hidden

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

59 files changed

+119
-123
lines changed

src/compile/render-dom/Block.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -104,9 +104,7 @@ export default class Block {
104104
this.getUniqueName = this.renderer.component.getUniqueNameMaker();
105105
this.variables = new Map();
106106

107-
this.aliases = new Map()
108-
.set('component', this.getUniqueName('component'))
109-
.set('ctx', this.getUniqueName('ctx'));
107+
this.aliases = new Map().set('ctx', this.getUniqueName('ctx'));
110108
if (this.key) this.aliases.set('key', this.getUniqueName('key'));
111109

112110
this.hasUpdateMethod = false; // determined later
@@ -410,7 +408,7 @@ export default class Block {
410408

411409
return deindent`
412410
${this.comment && `// ${this.comment}`}
413-
function ${this.name}(${this.alias('component')}, ${this.key ? `${localKey}, ` : ''}ctx) {
411+
function ${this.name}($$, ${this.key ? `${localKey}, ` : ''}ctx) {
414412
${this.getContents(localKey)}
415413
}
416414
`;

src/compile/render-dom/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ export default function dom(
238238
if (component.props.length > 0 || component.has_reactive_assignments) args.push('$$props', '$$invalidate');
239239

240240
builder.addBlock(deindent`
241-
function create_fragment(${component.alias('component')}, ctx) {
241+
function create_fragment($$, ctx) {
242242
${block.getContents()}
243243
}
244244

src/compile/render-dom/wrappers/AwaitBlock.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ export default class AwaitBlockWrapper extends Wrapper {
135135
block.maintainContext = true;
136136

137137
const infoProps = [
138-
block.alias('component') === 'component' ? 'component' : `component: #component`,
138+
'$$',
139139
'ctx',
140140
'current: null',
141141
this.pending.block.name && `pending: ${this.pending.block.name}`,

src/compile/render-dom/wrappers/EachBlock.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ export default class EachBlockWrapper extends Wrapper {
216216
// TODO neaten this up... will end up with an empty line in the block
217217
block.builders.init.addBlock(deindent`
218218
if (!${this.vars.each_block_value}.${this.vars.length}) {
219-
${each_block_else} = ${this.else.block.name}(#component, ctx);
219+
${each_block_else} = ${this.else.block.name}($$, ctx);
220220
${each_block_else}.c();
221221
}
222222
`);
@@ -234,7 +234,7 @@ export default class EachBlockWrapper extends Wrapper {
234234
if (!${this.vars.each_block_value}.${this.vars.length} && ${each_block_else}) {
235235
${each_block_else}.p(changed, ctx);
236236
} else if (!${this.vars.each_block_value}.${this.vars.length}) {
237-
${each_block_else} = ${this.else.block.name}(#component, ctx);
237+
${each_block_else} = ${this.else.block.name}($$, ctx);
238238
${each_block_else}.c();
239239
${each_block_else}.${mountOrIntro}(${initialMountNode}, ${this.vars.anchor});
240240
} else if (${each_block_else}) {
@@ -250,7 +250,7 @@ export default class EachBlockWrapper extends Wrapper {
250250
${each_block_else} = null;
251251
}
252252
} else if (!${each_block_else}) {
253-
${each_block_else} = ${this.else.block.name}(#component, ctx);
253+
${each_block_else} = ${this.else.block.name}($$, ctx);
254254
${each_block_else}.c();
255255
${each_block_else}.${mountOrIntro}(${initialMountNode}, ${this.vars.anchor});
256256
}
@@ -307,7 +307,7 @@ export default class EachBlockWrapper extends Wrapper {
307307
for (var #i = 0; #i < ${this.vars.each_block_value}.${length}; #i += 1) {
308308
let child_ctx = ${this.vars.get_each_context}(ctx, ${this.vars.each_block_value}, #i);
309309
let key = ${get_key}(child_ctx);
310-
${blocks}[#i] = ${lookup}[key] = ${create_each_block}(#component, key, child_ctx);
310+
${blocks}[#i] = ${lookup}[key] = ${create_each_block}($$, key, child_ctx);
311311
}
312312
`);
313313

@@ -343,7 +343,7 @@ export default class EachBlockWrapper extends Wrapper {
343343
344344
${this.block.hasOutros && `@group_outros();`}
345345
${this.node.hasAnimation && `for (let #i = 0; #i < ${blocks}.length; #i += 1) ${blocks}[#i].r();`}
346-
${blocks} = @updateKeyedEach(${blocks}, #component, changed, ${get_key}, ${dynamic ? '1' : '0'}, ctx, ${this.vars.each_block_value}, ${lookup}, ${updateMountNode}, ${destroy}, ${create_each_block}, "${mountOrIntro}", ${anchor}, ${this.vars.get_each_context});
346+
${blocks} = @updateKeyedEach(${blocks}, $$, changed, ${get_key}, ${dynamic ? '1' : '0'}, ctx, ${this.vars.each_block_value}, ${lookup}, ${updateMountNode}, ${destroy}, ${create_each_block}, "${mountOrIntro}", ${anchor}, ${this.vars.get_each_context});
347347
${this.node.hasAnimation && `for (let #i = 0; #i < ${blocks}.length; #i += 1) ${blocks}[#i].a();`}
348348
`);
349349

@@ -378,7 +378,7 @@ export default class EachBlockWrapper extends Wrapper {
378378
var ${iterations} = [];
379379
380380
for (var #i = 0; #i < ${this.vars.each_block_value}.${length}; #i += 1) {
381-
${iterations}[#i] = ${create_each_block}(#component, ${this.vars.get_each_context}(ctx, ${this.vars.each_block_value}, #i));
381+
${iterations}[#i] = ${create_each_block}($$, ${this.vars.get_each_context}(ctx, ${this.vars.each_block_value}, #i));
382382
}
383383
`);
384384

@@ -440,7 +440,7 @@ export default class EachBlockWrapper extends Wrapper {
440440
if (${iterations}[#i]) {
441441
${iterations}[#i].p(changed, child_ctx);
442442
} else {
443-
${iterations}[#i] = ${create_each_block}(#component, child_ctx);
443+
${iterations}[#i] = ${create_each_block}($$, child_ctx);
444444
${iterations}[#i].c();
445445
}
446446
${iterations}[#i].i(${updateMountNode}, ${anchor});
@@ -449,13 +449,13 @@ export default class EachBlockWrapper extends Wrapper {
449449
if (${iterations}[#i]) {
450450
${iterations}[#i].p(changed, child_ctx);
451451
} else {
452-
${iterations}[#i] = ${create_each_block}(#component, child_ctx);
452+
${iterations}[#i] = ${create_each_block}($$, child_ctx);
453453
${iterations}[#i].c();
454454
${iterations}[#i].m(${updateMountNode}, ${anchor});
455455
}
456456
`
457457
: deindent`
458-
${iterations}[#i] = ${create_each_block}(#component, child_ctx);
458+
${iterations}[#i] = ${create_each_block}($$, child_ctx);
459459
${iterations}[#i].c();
460460
${iterations}[#i].${mountOrIntro}(${updateMountNode}, ${anchor});
461461
`;

src/compile/render-dom/wrappers/Element/Binding.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,11 +123,11 @@ export default class BindingWrapper {
123123
const bindingGroup = getBindingGroup(parent.renderer, this.node.expression.node);
124124

125125
block.builders.hydrate.addLine(
126-
`(#component.$$.binding_groups[${bindingGroup}] || (#component.$$.binding_groups[${bindingGroup}] = [])).push(${parent.var});`
126+
`($$.binding_groups[${bindingGroup}] || ($$.binding_groups[${bindingGroup}] = [])).push(${parent.var});`
127127
);
128128

129129
block.builders.destroy.addLine(
130-
`#component.$$.binding_groups[${bindingGroup}].splice(#component.$$.binding_groups[${bindingGroup}].indexOf(${parent.var}), 1);`
130+
`$$.binding_groups[${bindingGroup}].splice($$.binding_groups[${bindingGroup}].indexOf(${parent.var}), 1);`
131131
);
132132
break;
133133

src/compile/render-dom/wrappers/IfBlock.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ export default class IfBlockWrapper extends Wrapper {
222222

223223
block.builders.init.addBlock(deindent`
224224
var ${current_block_type} = ${select_block_type}(ctx);
225-
var ${name} = ${current_block_type_and}${current_block_type}(#component, ctx);
225+
var ${name} = ${current_block_type_and}${current_block_type}($$, ctx);
226226
`);
227227

228228
const mountOrIntro = this.branches[0].block.hasIntroMethod ? 'i' : 'm';
@@ -237,7 +237,7 @@ export default class IfBlockWrapper extends Wrapper {
237237

238238
const changeBlock = deindent`
239239
${if_name}${name}.d(1);
240-
${name} = ${current_block_type_and}${current_block_type}(#component, ctx);
240+
${name} = ${current_block_type_and}${current_block_type}($$, ctx);
241241
${if_name}${name}.c();
242242
${if_name}${name}.${mountOrIntro}(${updateMountNode}, ${anchor});
243243
`;
@@ -301,12 +301,12 @@ export default class IfBlockWrapper extends Wrapper {
301301
if (hasElse) {
302302
block.builders.init.addBlock(deindent`
303303
${current_block_type_index} = ${select_block_type}(ctx);
304-
${name} = ${if_blocks}[${current_block_type_index}] = ${if_block_creators}[${current_block_type_index}](#component, ctx);
304+
${name} = ${if_blocks}[${current_block_type_index}] = ${if_block_creators}[${current_block_type_index}]($$, ctx);
305305
`);
306306
} else {
307307
block.builders.init.addBlock(deindent`
308308
if (~(${current_block_type_index} = ${select_block_type}(ctx))) {
309-
${name} = ${if_blocks}[${current_block_type_index}] = ${if_block_creators}[${current_block_type_index}](#component, ctx);
309+
${name} = ${if_blocks}[${current_block_type_index}] = ${if_block_creators}[${current_block_type_index}]($$, ctx);
310310
}
311311
`);
312312
}
@@ -332,7 +332,7 @@ export default class IfBlockWrapper extends Wrapper {
332332
const createNewBlock = deindent`
333333
${name} = ${if_blocks}[${current_block_type_index}];
334334
if (!${name}) {
335-
${name} = ${if_blocks}[${current_block_type_index}] = ${if_block_creators}[${current_block_type_index}](#component, ctx);
335+
${name} = ${if_blocks}[${current_block_type_index}] = ${if_block_creators}[${current_block_type_index}]($$, ctx);
336336
${name}.c();
337337
}
338338
${name}.${mountOrIntro}(${updateMountNode}, ${anchor});
@@ -391,7 +391,7 @@ export default class IfBlockWrapper extends Wrapper {
391391
const branch = this.branches[0];
392392

393393
block.builders.init.addBlock(deindent`
394-
var ${name} = (${branch.condition}) && ${branch.block.name}(#component, ctx);
394+
var ${name} = (${branch.condition}) && ${branch.block.name}($$, ctx);
395395
`);
396396

397397
const mountOrIntro = branch.block.hasIntroMethod ? 'i' : 'm';
@@ -410,7 +410,7 @@ export default class IfBlockWrapper extends Wrapper {
410410
if (${name}) {
411411
${name}.p(changed, ctx);
412412
} else {
413-
${name} = ${branch.block.name}(#component, ctx);
413+
${name} = ${branch.block.name}($$, ctx);
414414
if (${name}) ${name}.c();
415415
}
416416
@@ -420,22 +420,22 @@ export default class IfBlockWrapper extends Wrapper {
420420
if (${name}) {
421421
${name}.p(changed, ctx);
422422
} else {
423-
${name} = ${branch.block.name}(#component, ctx);
423+
${name} = ${branch.block.name}($$, ctx);
424424
${name}.c();
425425
${name}.m(${updateMountNode}, ${anchor});
426426
}
427427
`
428428
: (branch.block.hasIntroMethod || branch.block.hasOutroMethod)
429429
? deindent`
430430
if (!${name}) {
431-
${name} = ${branch.block.name}(#component, ctx);
431+
${name} = ${branch.block.name}($$, ctx);
432432
${name}.c();
433433
}
434434
${name}.i(${updateMountNode}, ${anchor});
435435
`
436436
: deindent`
437437
if (!${name}) {
438-
${name} = ${branch.block.name}(#component, ctx);
438+
${name} = ${branch.block.name}($$, ctx);
439439
${name}.c();
440440
${name}.m(${updateMountNode}, ${anchor});
441441
}

src/compile/render-dom/wrappers/Slot.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ export default class SlotWrapper extends Wrapper {
4646

4747
const content_name = block.getUniqueName(`slot_content_${sanitize(slotName)}`);
4848
const prop = quotePropIfNecessary(slotName);
49-
block.addVariable(content_name, `#component.$$.slotted${prop}`);
49+
block.addVariable(content_name, `$$.slotted${prop}`);
5050

5151
// TODO can we use isDomNode instead of type === 'Element'?
5252
const needsAnchorBefore = this.prev ? this.prev.node.type !== 'Element' : !parentNode;

src/internal/Component.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ export function init(component, options, instance, create_fragment, not_equal) {
9898
$$.update();
9999
ready = true;
100100
run_all($$.before_render);
101-
$$.fragment = create_fragment(component, $$.ctx);
101+
$$.fragment = create_fragment($$, $$.ctx);
102102

103103
if (options.target) {
104104
intros.enabled = !!options.intro;

src/internal/await-block.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { assign, run_all, isPromise } from './utils.js';
1+
import { assign, isPromise } from './utils.js';
22
import { group_outros } from './transitions.js';
33
import { flush } from '../internal/scheduler.js';
44

@@ -11,7 +11,7 @@ export function handlePromise(promise, info) {
1111
info.resolved = key && { [key]: value };
1212

1313
const child_ctx = assign(assign({}, info.ctx), info.resolved);
14-
const block = type && (info.current = type)(info.component, child_ctx);
14+
const block = type && (info.current = type)(info.$$, child_ctx);
1515

1616
if (info.block) {
1717
if (info.blocks) {
@@ -31,8 +31,6 @@ export function handlePromise(promise, info) {
3131
block.c();
3232
block[block.i ? 'i' : 'm'](info.mount(), info.anchor);
3333

34-
// TODO is some of this redundant?
35-
run_all(info.component.$$.after_render);
3634
flush();
3735
}
3836

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/* generated by Svelte vX.Y.Z */
22
import { SvelteComponent as SvelteComponent_1, createElement, detachNode, flush, init, insert, noop, run, safe_not_equal } from "svelte/internal";
33

4-
function create_fragment(component, ctx) {
4+
function create_fragment($$, ctx) {
55
var button, foo_action, current;
66

77
return {

test/js/samples/action/expected.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/* generated by Svelte vX.Y.Z */
22
import { SvelteComponent as SvelteComponent_1, createElement, detachNode, identity, init, insert, noop, run, safe_not_equal } from "svelte/internal";
33

4-
function create_fragment(component, ctx) {
4+
function create_fragment($$, ctx) {
55
var a, link_action, current;
66

77
return {

test/js/samples/bind-width-height/expected.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/* generated by Svelte vX.Y.Z */
22
import { SvelteComponent as SvelteComponent_1, addResizeListener, add_render_callback, createElement, detachNode, flush, init, insert, noop, run, safe_not_equal } from "svelte/internal";
33

4-
function create_fragment(component, ctx) {
4+
function create_fragment($$, ctx) {
55
var div, div_resize_listener, current;
66

77
return {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ function add_css() {
88
append(document.head, style);
99
}
1010

11-
function create_fragment(component, ctx) {
11+
function create_fragment($$, ctx) {
1212
var p, text, current;
1313

1414
return {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/* generated by Svelte vX.Y.Z */
22
import { SvelteComponent as SvelteComponent_1, init, mount_component, noop, safe_not_equal } from "svelte/internal";
33

4-
function create_fragment(component, ctx) {
4+
function create_fragment($$, ctx) {
55
var current;
66

77
var nested = new ctx.Nested({ props: { foo: [1, 2, 3] } });

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/* generated by Svelte vX.Y.Z */
22
import { SvelteComponent as SvelteComponent_1, init, mount_component, noop, not_equal } from "svelte/internal";
33

4-
function create_fragment(component, ctx) {
4+
function create_fragment($$, ctx) {
55
var current;
66

77
var nested = new ctx.Nested({ props: { foo: "bar" } });

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/* generated by Svelte vX.Y.Z */
22
import { SvelteComponent as SvelteComponent_1, init, mount_component, noop, not_equal } from "svelte/internal";
33

4-
function create_fragment(component, ctx) {
4+
function create_fragment($$, ctx) {
55
var current;
66

77
var nested = new ctx.Nested({ props: { foo: "bar" } });

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/* generated by Svelte vX.Y.Z */
22
import { SvelteComponent as SvelteComponent_1, init, mount_component, noop, safe_not_equal } from "svelte/internal";
33

4-
function create_fragment(component, ctx) {
4+
function create_fragment($$, ctx) {
55
var current;
66

77
var nested = new ctx.Nested({ props: { foo: "bar" } });

test/js/samples/computed-collapsed-if/expected.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/* generated by Svelte vX.Y.Z */
22
import { SvelteComponent as SvelteComponent_1, flush, init, noop, run, safe_not_equal } from "svelte/internal";
33

4-
function create_fragment(component, ctx) {
4+
function create_fragment($$, ctx) {
55
var current;
66

77
return {

test/js/samples/css-media-query/expected.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ function add_css() {
88
append(document.head, style);
99
}
1010

11-
function create_fragment(component, ctx) {
11+
function create_fragment($$, ctx) {
1212
var div, current;
1313

1414
return {

test/js/samples/css-shadow-dom-keyframes/expected.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/* generated by Svelte vX.Y.Z */
22
import { SvelteElement, createElement, detachNode, identity, init, insert, noop, run, safe_not_equal } from "svelte/internal";
33

4-
function create_fragment(component, ctx) {
4+
function create_fragment($$, ctx) {
55
var div, current;
66

77
return {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { SvelteComponentDev, addLoc, append, createElement, createText, detachNo
33

44
const file = undefined;
55

6-
function create_fragment(component, ctx) {
6+
function create_fragment($$, ctx) {
77
var h1, text0, text1, text2, text3, current;
88

99
return {

0 commit comments

Comments
 (0)