various fixes

pull/1839/head
Rich Harris 7 years ago
parent b82ca07c45
commit 5b7dc63504

@ -764,6 +764,8 @@ export default class Component {
if (this.hoistable_names.has(name)) return name; if (this.hoistable_names.has(name)) return name;
if (this.imported_declarations.has(name)) return name; if (this.imported_declarations.has(name)) return name;
if (this.declarations.indexOf(name) === -1) return name; if (this.declarations.indexOf(name) === -1) return name;
this.template_references.add(name); // TODO we can probably remove most other occurrences of this
return `ctx.${name}`; return `ctx.${name}`;
} }

@ -8,15 +8,7 @@ export default class EventHandler extends Node {
modifiers: Set<string>; modifiers: Set<string>;
expression: Expression; expression: Expression;
handler_name: string; handler_name: string;
usesComponent: boolean;
usesContext: boolean; usesContext: boolean;
usesEventObject: boolean;
isCustomEvent: boolean;
insertionPoint: number;
args: Expression[];
snippet: string;
constructor(component: Component, parent, template_scope, info) { constructor(component: Component, parent, template_scope, info) {
super(component, parent, template_scope, info); super(component, parent, template_scope, info);
@ -42,8 +34,9 @@ export default class EventHandler extends Node {
} }
render() { render() {
return this.expression if (this.expression) return this.expression.render();
? this.expression.render()
: `ctx.${this.handler_name}`; this.component.template_references.add(this.handler_name);
return `ctx.${this.handler_name}`;
} }
} }

@ -219,7 +219,7 @@ export default class Expression {
dependencies.add(name); dependencies.add(name);
component.template_references.add(name); component.template_references.add(name);
} }
} else if (!is_synthetic && !component.hoistable_names.has(name)) { } else if (!is_synthetic && !component.hoistable_names.has(name) && !component.imported_declarations.has(name)) {
code.prependRight(node.start, key === 'key' && parent.shorthand code.prependRight(node.start, key === 'key' && parent.shorthand
? `${name}: ctx.` ? `${name}: ctx.`
: 'ctx.'); : 'ctx.');

@ -621,9 +621,10 @@ export default class ElementWrapper extends Wrapper {
block: Block block: Block
) { ) {
const { intro, outro } = this.node; const { intro, outro } = this.node;
if (!intro && !outro) return; if (!intro && !outro) return;
const { component } = this.renderer;
if (intro === outro) { if (intro === outro) {
const name = block.getUniqueName(`${this.var}_transition`); const name = block.getUniqueName(`${this.var}_transition`);
const snippet = intro.expression const snippet = intro.expression
@ -632,7 +633,7 @@ export default class ElementWrapper extends Wrapper {
block.addVariable(name); block.addVariable(name);
const fn = `ctx.${intro.name}`; const fn = component.qualify(intro.name);
block.builders.intro.addConditional(`@intro.enabled`, deindent` block.builders.intro.addConditional(`@intro.enabled`, deindent`
if (${name}) ${name}.invalidate(); if (${name}) ${name}.invalidate();
@ -662,7 +663,7 @@ export default class ElementWrapper extends Wrapper {
? intro.expression.render() ? intro.expression.render()
: '{}'; : '{}';
const fn = `ctx.${intro.name}`; // TODO add built-in transitions? const fn = component.qualify(intro.name); // TODO add built-in transitions?
if (outro) { if (outro) {
block.builders.intro.addBlock(deindent` block.builders.intro.addBlock(deindent`
@ -685,7 +686,7 @@ export default class ElementWrapper extends Wrapper {
? outro.expression.render() ? outro.expression.render()
: '{}'; : '{}';
const fn = `ctx.${outro.name}`; const fn = component.qualify(outro.name);
block.builders.intro.addBlock(deindent` block.builders.intro.addBlock(deindent`
if (${outroName}) ${outroName}.abort(1); if (${outroName}) ${outroName}.abort(1);

@ -202,6 +202,7 @@ export default class InlineComponentWrapper extends Wrapper {
const name = component.getUniqueName(`${this.var}_${binding.name}_binding`); const name = component.getUniqueName(`${this.var}_${binding.name}_binding`);
component.declarations.push(name); component.declarations.push(name);
component.template_references.add(name);
const updating = block.getUniqueName(`updating_${binding.name}`); const updating = block.getUniqueName(`updating_${binding.name}`);
block.addVariable(updating); block.addVariable(updating);
@ -293,7 +294,7 @@ export default class InlineComponentWrapper extends Wrapper {
function ${switch_props}(ctx) { function ${switch_props}(ctx) {
${(this.node.attributes.length || this.node.bindings.length) && deindent` ${(this.node.attributes.length || this.node.bindings.length) && deindent`
${props && `const ${props} = ${attributeObject};`}`} ${props && `let ${props} = ${attributeObject};`}`}
${statements} ${statements}
return ${stringifyProps(component_opts)}; return ${stringifyProps(component_opts)};
} }
@ -385,7 +386,7 @@ export default class InlineComponentWrapper extends Wrapper {
block.builders.init.addBlock(deindent` block.builders.init.addBlock(deindent`
${(this.node.attributes.length || this.node.bindings.length) && deindent` ${(this.node.attributes.length || this.node.bindings.length) && deindent`
${props && `const ${props} = ${attributeObject};`}`} ${props && `let ${props} = ${attributeObject};`}`}
${statements} ${statements}
var ${name} = new ${expression}(${stringifyProps(component_opts)}); var ${name} = new ${expression}(${stringifyProps(component_opts)});

@ -30,6 +30,8 @@ export default function addActions(
? action.name ? action.name
: `ctx.${action.name}`; : `ctx.${action.name}`;
component.template_references.add(action.name);
block.builders.mount.addLine( block.builders.mount.addLine(
`${name} = ${fn}.call(null, ${target}${snippet ? `, ${snippet}` : ''}) || {};` `${name} = ${fn}.call(null, ${target}${snippet ? `, ${snippet}` : ''}) || {};`
); );

@ -34,7 +34,7 @@ export function exclude(src, prop) {
} }
export function run(fn) { export function run(fn) {
fn(); return fn();
} }
export function blankObject() { export function blankObject() {

Loading…
Cancel
Save