From 91aabf5f493de2c13527dfed9daea1af12ae6185 Mon Sep 17 00:00:00 2001 From: Richard Harris Date: Mon, 1 Jul 2019 09:19:28 -0400 Subject: [PATCH] distinguish between lazy and non-lazy expressions - fixes #2693 --- src/compiler/compile/nodes/Action.ts | 2 +- src/compiler/compile/nodes/Animation.ts | 2 +- src/compiler/compile/nodes/EventHandler.ts | 2 +- src/compiler/compile/nodes/Transition.ts | 2 +- src/compiler/compile/nodes/shared/Expression.ts | 6 +++--- test/runtime/samples/reactive-function-inline/_config.js | 8 ++++++++ test/runtime/samples/reactive-function-inline/main.svelte | 6 ++++++ test/runtime/samples/reactive-function/_config.js | 2 -- 8 files changed, 21 insertions(+), 9 deletions(-) create mode 100644 test/runtime/samples/reactive-function-inline/_config.js create mode 100644 test/runtime/samples/reactive-function-inline/main.svelte diff --git a/src/compiler/compile/nodes/Action.ts b/src/compiler/compile/nodes/Action.ts index 77b9e3c846..9f1df86c18 100644 --- a/src/compiler/compile/nodes/Action.ts +++ b/src/compiler/compile/nodes/Action.ts @@ -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; diff --git a/src/compiler/compile/nodes/Animation.ts b/src/compiler/compile/nodes/Animation.ts index 6ccdbb0803..ef48b4d745 100644 --- a/src/compiler/compile/nodes/Animation.ts +++ b/src/compiler/compile/nodes/Animation.ts @@ -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; } } \ No newline at end of file diff --git a/src/compiler/compile/nodes/EventHandler.ts b/src/compiler/compile/nodes/EventHandler.ts index f2c48c3169..0c65e463ba 100644 --- a/src/compiler/compile/nodes/EventHandler.ts +++ b/src/compiler/compile/nodes/EventHandler.ts @@ -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) { diff --git a/src/compiler/compile/nodes/Transition.ts b/src/compiler/compile/nodes/Transition.ts index 82eb578f0f..ceb5880e64 100644 --- a/src/compiler/compile/nodes/Transition.ts +++ b/src/compiler/compile/nodes/Transition.ts @@ -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; } } diff --git a/src/compiler/compile/nodes/shared/Expression.ts b/src/compiler/compile/nodes/shared/Expression.ts index f8bb92e0e0..96dbdb226d 100644 --- a/src/compiler/compile/nodes/shared/Expression.ts +++ b/src/compiler/compile/nodes/shared/Expression.ts @@ -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); } diff --git a/test/runtime/samples/reactive-function-inline/_config.js b/test/runtime/samples/reactive-function-inline/_config.js new file mode 100644 index 0000000000..45afe8929f --- /dev/null +++ b/test/runtime/samples/reactive-function-inline/_config.js @@ -0,0 +1,8 @@ +export default { + html: '

0

', + + test({ assert, component, target }) { + component.selected = 3; + assert.htmlEqual(target.innerHTML, '

3

'); + } +}; diff --git a/test/runtime/samples/reactive-function-inline/main.svelte b/test/runtime/samples/reactive-function-inline/main.svelte new file mode 100644 index 0000000000..2a129c4a5d --- /dev/null +++ b/test/runtime/samples/reactive-function-inline/main.svelte @@ -0,0 +1,6 @@ + + +

{list.filter(x => x === selected)}

\ No newline at end of file diff --git a/test/runtime/samples/reactive-function/_config.js b/test/runtime/samples/reactive-function/_config.js index a29c022b5f..b3c6a65dbb 100644 --- a/test/runtime/samples/reactive-function/_config.js +++ b/test/runtime/samples/reactive-function/_config.js @@ -2,10 +2,8 @@ export default { html: '

50

', test({ assert, component, target }) { - console.group('range [50,100]'); component.range = [50, 100]; assert.htmlEqual(target.innerHTML, '

75

'); - console.groupEnd(); component.range = [50, 60]; assert.htmlEqual(target.innerHTML, '

55

');