diff --git a/src/compile/render-dom/Block.ts b/src/compile/render-dom/Block.ts index 5a192b55a3..bee2072ef1 100644 --- a/src/compile/render-dom/Block.ts +++ b/src/compile/render-dom/Block.ts @@ -104,9 +104,7 @@ export default class Block { this.getUniqueName = this.renderer.component.getUniqueNameMaker(); this.variables = new Map(); - this.aliases = new Map() - .set('component', this.getUniqueName('component')) - .set('ctx', this.getUniqueName('ctx')); + this.aliases = new Map().set('ctx', this.getUniqueName('ctx')); if (this.key) this.aliases.set('key', this.getUniqueName('key')); this.hasUpdateMethod = false; // determined later @@ -410,7 +408,7 @@ export default class Block { return deindent` ${this.comment && `// ${this.comment}`} - function ${this.name}(${this.alias('component')}, ${this.key ? `${localKey}, ` : ''}ctx) { + function ${this.name}($$, ${this.key ? `${localKey}, ` : ''}ctx) { ${this.getContents(localKey)} } `; diff --git a/src/compile/render-dom/index.ts b/src/compile/render-dom/index.ts index aee924f0cf..50b0a35206 100644 --- a/src/compile/render-dom/index.ts +++ b/src/compile/render-dom/index.ts @@ -238,7 +238,7 @@ export default function dom( if (component.props.length > 0 || component.has_reactive_assignments) args.push('$$props', '$$invalidate'); builder.addBlock(deindent` - function create_fragment(${component.alias('component')}, ctx) { + function create_fragment($$, ctx) { ${block.getContents()} } diff --git a/src/compile/render-dom/wrappers/AwaitBlock.ts b/src/compile/render-dom/wrappers/AwaitBlock.ts index c0b719f140..c37bb4b1cf 100644 --- a/src/compile/render-dom/wrappers/AwaitBlock.ts +++ b/src/compile/render-dom/wrappers/AwaitBlock.ts @@ -135,7 +135,7 @@ export default class AwaitBlockWrapper extends Wrapper { block.maintainContext = true; const infoProps = [ - block.alias('component') === 'component' ? 'component' : `component: #component`, + '$$', 'ctx', 'current: null', this.pending.block.name && `pending: ${this.pending.block.name}`, diff --git a/src/compile/render-dom/wrappers/EachBlock.ts b/src/compile/render-dom/wrappers/EachBlock.ts index 397a5629a7..2b3bd44a01 100644 --- a/src/compile/render-dom/wrappers/EachBlock.ts +++ b/src/compile/render-dom/wrappers/EachBlock.ts @@ -216,7 +216,7 @@ export default class EachBlockWrapper extends Wrapper { // TODO neaten this up... will end up with an empty line in the block block.builders.init.addBlock(deindent` if (!${this.vars.each_block_value}.${this.vars.length}) { - ${each_block_else} = ${this.else.block.name}(#component, ctx); + ${each_block_else} = ${this.else.block.name}($$, ctx); ${each_block_else}.c(); } `); @@ -234,7 +234,7 @@ export default class EachBlockWrapper extends Wrapper { if (!${this.vars.each_block_value}.${this.vars.length} && ${each_block_else}) { ${each_block_else}.p(changed, ctx); } else if (!${this.vars.each_block_value}.${this.vars.length}) { - ${each_block_else} = ${this.else.block.name}(#component, ctx); + ${each_block_else} = ${this.else.block.name}($$, ctx); ${each_block_else}.c(); ${each_block_else}.${mountOrIntro}(${initialMountNode}, ${this.vars.anchor}); } else if (${each_block_else}) { @@ -250,7 +250,7 @@ export default class EachBlockWrapper extends Wrapper { ${each_block_else} = null; } } else if (!${each_block_else}) { - ${each_block_else} = ${this.else.block.name}(#component, ctx); + ${each_block_else} = ${this.else.block.name}($$, ctx); ${each_block_else}.c(); ${each_block_else}.${mountOrIntro}(${initialMountNode}, ${this.vars.anchor}); } @@ -307,7 +307,7 @@ export default class EachBlockWrapper extends Wrapper { for (var #i = 0; #i < ${this.vars.each_block_value}.${length}; #i += 1) { let child_ctx = ${this.vars.get_each_context}(ctx, ${this.vars.each_block_value}, #i); let key = ${get_key}(child_ctx); - ${blocks}[#i] = ${lookup}[key] = ${create_each_block}(#component, key, child_ctx); + ${blocks}[#i] = ${lookup}[key] = ${create_each_block}($$, key, child_ctx); } `); @@ -343,7 +343,7 @@ export default class EachBlockWrapper extends Wrapper { ${this.block.hasOutros && `@group_outros();`} ${this.node.hasAnimation && `for (let #i = 0; #i < ${blocks}.length; #i += 1) ${blocks}[#i].r();`} - ${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}); + ${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}); ${this.node.hasAnimation && `for (let #i = 0; #i < ${blocks}.length; #i += 1) ${blocks}[#i].a();`} `); @@ -378,7 +378,7 @@ export default class EachBlockWrapper extends Wrapper { var ${iterations} = []; for (var #i = 0; #i < ${this.vars.each_block_value}.${length}; #i += 1) { - ${iterations}[#i] = ${create_each_block}(#component, ${this.vars.get_each_context}(ctx, ${this.vars.each_block_value}, #i)); + ${iterations}[#i] = ${create_each_block}($$, ${this.vars.get_each_context}(ctx, ${this.vars.each_block_value}, #i)); } `); @@ -440,7 +440,7 @@ export default class EachBlockWrapper extends Wrapper { if (${iterations}[#i]) { ${iterations}[#i].p(changed, child_ctx); } else { - ${iterations}[#i] = ${create_each_block}(#component, child_ctx); + ${iterations}[#i] = ${create_each_block}($$, child_ctx); ${iterations}[#i].c(); } ${iterations}[#i].i(${updateMountNode}, ${anchor}); @@ -449,13 +449,13 @@ export default class EachBlockWrapper extends Wrapper { if (${iterations}[#i]) { ${iterations}[#i].p(changed, child_ctx); } else { - ${iterations}[#i] = ${create_each_block}(#component, child_ctx); + ${iterations}[#i] = ${create_each_block}($$, child_ctx); ${iterations}[#i].c(); ${iterations}[#i].m(${updateMountNode}, ${anchor}); } ` : deindent` - ${iterations}[#i] = ${create_each_block}(#component, child_ctx); + ${iterations}[#i] = ${create_each_block}($$, child_ctx); ${iterations}[#i].c(); ${iterations}[#i].${mountOrIntro}(${updateMountNode}, ${anchor}); `; diff --git a/src/compile/render-dom/wrappers/Element/Binding.ts b/src/compile/render-dom/wrappers/Element/Binding.ts index 672fb21ab7..4a2df8af70 100644 --- a/src/compile/render-dom/wrappers/Element/Binding.ts +++ b/src/compile/render-dom/wrappers/Element/Binding.ts @@ -123,11 +123,11 @@ export default class BindingWrapper { const bindingGroup = getBindingGroup(parent.renderer, this.node.expression.node); block.builders.hydrate.addLine( - `(#component.$$.binding_groups[${bindingGroup}] || (#component.$$.binding_groups[${bindingGroup}] = [])).push(${parent.var});` + `($$.binding_groups[${bindingGroup}] || ($$.binding_groups[${bindingGroup}] = [])).push(${parent.var});` ); block.builders.destroy.addLine( - `#component.$$.binding_groups[${bindingGroup}].splice(#component.$$.binding_groups[${bindingGroup}].indexOf(${parent.var}), 1);` + `$$.binding_groups[${bindingGroup}].splice($$.binding_groups[${bindingGroup}].indexOf(${parent.var}), 1);` ); break; diff --git a/src/compile/render-dom/wrappers/IfBlock.ts b/src/compile/render-dom/wrappers/IfBlock.ts index 594f811090..0b49412058 100644 --- a/src/compile/render-dom/wrappers/IfBlock.ts +++ b/src/compile/render-dom/wrappers/IfBlock.ts @@ -222,7 +222,7 @@ export default class IfBlockWrapper extends Wrapper { block.builders.init.addBlock(deindent` var ${current_block_type} = ${select_block_type}(ctx); - var ${name} = ${current_block_type_and}${current_block_type}(#component, ctx); + var ${name} = ${current_block_type_and}${current_block_type}($$, ctx); `); const mountOrIntro = this.branches[0].block.hasIntroMethod ? 'i' : 'm'; @@ -237,7 +237,7 @@ export default class IfBlockWrapper extends Wrapper { const changeBlock = deindent` ${if_name}${name}.d(1); - ${name} = ${current_block_type_and}${current_block_type}(#component, ctx); + ${name} = ${current_block_type_and}${current_block_type}($$, ctx); ${if_name}${name}.c(); ${if_name}${name}.${mountOrIntro}(${updateMountNode}, ${anchor}); `; @@ -301,12 +301,12 @@ export default class IfBlockWrapper extends Wrapper { if (hasElse) { block.builders.init.addBlock(deindent` ${current_block_type_index} = ${select_block_type}(ctx); - ${name} = ${if_blocks}[${current_block_type_index}] = ${if_block_creators}[${current_block_type_index}](#component, ctx); + ${name} = ${if_blocks}[${current_block_type_index}] = ${if_block_creators}[${current_block_type_index}]($$, ctx); `); } else { block.builders.init.addBlock(deindent` if (~(${current_block_type_index} = ${select_block_type}(ctx))) { - ${name} = ${if_blocks}[${current_block_type_index}] = ${if_block_creators}[${current_block_type_index}](#component, ctx); + ${name} = ${if_blocks}[${current_block_type_index}] = ${if_block_creators}[${current_block_type_index}]($$, ctx); } `); } @@ -332,7 +332,7 @@ export default class IfBlockWrapper extends Wrapper { const createNewBlock = deindent` ${name} = ${if_blocks}[${current_block_type_index}]; if (!${name}) { - ${name} = ${if_blocks}[${current_block_type_index}] = ${if_block_creators}[${current_block_type_index}](#component, ctx); + ${name} = ${if_blocks}[${current_block_type_index}] = ${if_block_creators}[${current_block_type_index}]($$, ctx); ${name}.c(); } ${name}.${mountOrIntro}(${updateMountNode}, ${anchor}); @@ -391,7 +391,7 @@ export default class IfBlockWrapper extends Wrapper { const branch = this.branches[0]; block.builders.init.addBlock(deindent` - var ${name} = (${branch.condition}) && ${branch.block.name}(#component, ctx); + var ${name} = (${branch.condition}) && ${branch.block.name}($$, ctx); `); const mountOrIntro = branch.block.hasIntroMethod ? 'i' : 'm'; @@ -410,7 +410,7 @@ export default class IfBlockWrapper extends Wrapper { if (${name}) { ${name}.p(changed, ctx); } else { - ${name} = ${branch.block.name}(#component, ctx); + ${name} = ${branch.block.name}($$, ctx); if (${name}) ${name}.c(); } @@ -420,7 +420,7 @@ export default class IfBlockWrapper extends Wrapper { if (${name}) { ${name}.p(changed, ctx); } else { - ${name} = ${branch.block.name}(#component, ctx); + ${name} = ${branch.block.name}($$, ctx); ${name}.c(); ${name}.m(${updateMountNode}, ${anchor}); } @@ -428,14 +428,14 @@ export default class IfBlockWrapper extends Wrapper { : (branch.block.hasIntroMethod || branch.block.hasOutroMethod) ? deindent` if (!${name}) { - ${name} = ${branch.block.name}(#component, ctx); + ${name} = ${branch.block.name}($$, ctx); ${name}.c(); } ${name}.i(${updateMountNode}, ${anchor}); ` : deindent` if (!${name}) { - ${name} = ${branch.block.name}(#component, ctx); + ${name} = ${branch.block.name}($$, ctx); ${name}.c(); ${name}.m(${updateMountNode}, ${anchor}); } diff --git a/src/compile/render-dom/wrappers/Slot.ts b/src/compile/render-dom/wrappers/Slot.ts index 10052f17e0..954c4c56ef 100644 --- a/src/compile/render-dom/wrappers/Slot.ts +++ b/src/compile/render-dom/wrappers/Slot.ts @@ -46,7 +46,7 @@ export default class SlotWrapper extends Wrapper { const content_name = block.getUniqueName(`slot_content_${sanitize(slotName)}`); const prop = quotePropIfNecessary(slotName); - block.addVariable(content_name, `#component.$$.slotted${prop}`); + block.addVariable(content_name, `$$.slotted${prop}`); // TODO can we use isDomNode instead of type === 'Element'? const needsAnchorBefore = this.prev ? this.prev.node.type !== 'Element' : !parentNode; diff --git a/src/internal/Component.js b/src/internal/Component.js index ec8de48d81..a1607f0b30 100644 --- a/src/internal/Component.js +++ b/src/internal/Component.js @@ -98,7 +98,7 @@ export function init(component, options, instance, create_fragment, not_equal) { $$.update(); ready = true; run_all($$.before_render); - $$.fragment = create_fragment(component, $$.ctx); + $$.fragment = create_fragment($$, $$.ctx); if (options.target) { intros.enabled = !!options.intro; diff --git a/src/internal/await-block.js b/src/internal/await-block.js index 5db7c8f1e5..812bf6c860 100644 --- a/src/internal/await-block.js +++ b/src/internal/await-block.js @@ -11,7 +11,7 @@ export function handlePromise(promise, info) { info.resolved = key && { [key]: value }; const child_ctx = assign(assign({}, info.ctx), info.resolved); - const block = type && (info.current = type)(info.component, child_ctx); + const block = type && (info.current = type)(info.$$, child_ctx); if (info.block) { if (info.blocks) { @@ -32,7 +32,7 @@ export function handlePromise(promise, info) { block[block.i ? 'i' : 'm'](info.mount(), info.anchor); // TODO is some of this redundant? - run_all(info.component.$$.after_render); + run_all(info.$$.after_render); flush(); }