distinguish between lazy and non-lazy expressions - fixes #2693

pull/3147/head
Richard Harris 6 years ago
parent 220515b605
commit 91aabf5f49

@ -17,7 +17,7 @@ export default class Action extends Node {
component.qualify(info.name);
this.expression = info.expression
? new Expression(component, this, scope, info.expression)
? new Expression(component, this, scope, info.expression, true)
: null;
this.uses_context = this.expression && this.expression.uses_context;

@ -34,7 +34,7 @@ export default class Animation extends Node {
block.has_animation = true;
this.expression = info.expression
? new Expression(component, this, scope, info.expression)
? new Expression(component, this, scope, info.expression, true)
: null;
}
}

@ -21,7 +21,7 @@ export default class EventHandler extends Node {
this.modifiers = new Set(info.modifiers);
if (info.expression) {
this.expression = new Expression(component, this, template_scope, info.expression);
this.expression = new Expression(component, this, template_scope, info.expression, true);
this.uses_context = this.expression.uses_context;
if (/FunctionExpression/.test(info.expression.type) && info.expression.params.length === 0) {

@ -34,7 +34,7 @@ export default class Transition extends Node {
}
this.expression = info.expression
? new Expression(component, this, scope, info.expression)
? new Expression(component, this, scope, info.expression, true)
: null;
}
}

@ -86,7 +86,7 @@ export default class Expression {
rendered: string;
// todo: owner type
constructor(component: Component, owner: Owner, template_scope: TemplateScope, info) {
constructor(component: Component, owner: Owner, template_scope: TemplateScope, info, lazy?: boolean) {
// TODO revert to direct property access in prod?
Object.defineProperties(this, {
component: {
@ -146,11 +146,11 @@ export default class Expression {
contextual_dependencies.add(name);
if (!function_expression) {
if (!function_expression || !lazy) {
template_scope.dependencies_for_name.get(name).forEach(name => dependencies.add(name));
}
} else {
if (!function_expression) {
if (!function_expression || !lazy) {
dependencies.add(name);
}

@ -0,0 +1,8 @@
export default {
html: '<p>0</p>',
test({ assert, component, target }) {
component.selected = 3;
assert.htmlEqual(target.innerHTML, '<p>3</p>');
}
};

@ -0,0 +1,6 @@
<script>
let list = [0, 1, 2, 3, 4];
export let selected = 0;
</script>
<p>{list.filter(x => x === selected)}</p>

@ -2,10 +2,8 @@ export default {
html: '<p>50</p>',
test({ assert, component, target }) {
console.group('range [50,100]');
component.range = [50, 100];
assert.htmlEqual(target.innerHTML, '<p>75</p>');
console.groupEnd();
component.range = [50, 60];
assert.htmlEqual(target.innerHTML, '<p>55</p>');

Loading…
Cancel
Save