fix some let stuff

pull/2011/head
Richard Harris 7 years ago
parent c3e0f3fd31
commit fe275cc568

@ -92,7 +92,6 @@ export default class Element extends Node {
constructor(component, parent, scope, info: any) {
super(component, parent, scope, info);
this.name = info.name;
this.scope = scope;
const parentElement = parent.findNearest(/^Element/);
this.namespace = this.name === 'svg' ?
@ -196,7 +195,7 @@ export default class Element extends Node {
const dependencies = new Set([l.name]);
l.names.forEach(name => {
this.scope.add(name, dependencies);
this.scope.add(name, dependencies, this);
});
});
} else {

@ -124,7 +124,11 @@ export default class Expression {
if (scope.has(name)) return;
if (globalWhitelist.has(name) && component.declarations.indexOf(name) === -1) return;
if (template_scope.names.has(name)) {
if (template_scope.is_let(name)) {
if (!function_expression) {
dependencies.add(name);
}
} else if (template_scope.names.has(name)) {
expression.usesContext = true;
contextual_dependencies.add(name);
@ -188,9 +192,7 @@ export default class Expression {
dynamic_dependencies() {
return Array.from(this.dependencies).filter(name => {
const owner = this.template_scope.getOwner(name);
const is_let = owner && (owner.type === 'InlineComponent' || owner.type === 'Element');
if (is_let) return true;
if (this.template_scope.is_let(name)) return true;
const variable = this.component.var_lookup.get(name);
return variable.mutated;

@ -37,4 +37,9 @@ export default class TemplateScope {
getOwner(name: string): NodeWithScope {
return this.owners.get(name) || (this.parent && this.parent.getOwner(name));
}
is_let(name: string) {
const owner = this.getOwner(name);
return owner && (owner.type === 'Element' || owner.type === 'InlineComponent');
}
}

@ -141,6 +141,7 @@ export default class ElementWrapper extends Wrapper {
(owner as InlineComponentWrapper).slots.set(name, {
block: child_block,
scope: this.node.scope,
fn
});
this.renderer.blocks.push(child_block);

@ -15,10 +15,11 @@ import createDebuggingComment from '../../../../utils/createDebuggingComment';
import sanitize from '../../../../utils/sanitize';
import { get_context_merger } from '../shared/get_context_merger';
import EachBlock from '../../../nodes/EachBlock';
import TemplateScope from '../../../nodes/shared/TemplateScope';
export default class InlineComponentWrapper extends Wrapper {
var: string;
slots: Map<string, { block: Block, fn?: string }> = new Map();
slots: Map<string, { block: Block, scope: TemplateScope, fn?: string }> = new Map();
node: InlineComponent;
fragment: FragmentWrapper;
@ -79,6 +80,7 @@ export default class InlineComponentWrapper extends Wrapper {
this.slots.set('default', {
block: default_slot,
scope: this.node.scope,
fn
});
this.fragment = new FragmentWrapper(renderer, default_slot, node.children, this, stripWhitespace, nextSibling);
@ -145,9 +147,9 @@ export default class InlineComponentWrapper extends Wrapper {
}
const fragment_dependencies = new Set();
this.slots.forEach(slot => {
this.slots.forEach((slot, name) => {
slot.block.dependencies.forEach(name => {
const is_let = this.node.lets.some(l => l.names.indexOf(name) !== -1);
const is_let = slot.scope.is_let(name);
const variable = renderer.component.var_lookup.get(name);
if (is_let || variable.mutated) {

Loading…
Cancel
Save