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..e85c1de5e5 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 (!lazy) { template_scope.dependencies_for_name.get(name).forEach(name => dependencies.add(name)); } } else { - if (!function_expression) { + if (!lazy) { dependencies.add(name); } diff --git a/test/js/samples/action-custom-event-handler/expected.js b/test/js/samples/action-custom-event-handler/expected.js index 4b758da030..ea55f1629b 100644 --- a/test/js/samples/action-custom-event-handler/expected.js +++ b/test/js/samples/action-custom-event-handler/expected.js @@ -23,7 +23,12 @@ function create_fragment(ctx) { foo_action = foo.call(null, button, ctx.foo_function) || {}; }, - p: noop, + p(changed, ctx) { + if (typeof foo_action.update === 'function' && changed.bar) { + foo_action.update.call(null, ctx.foo_function); + } + }, + i: noop, o: noop, 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
');