Skip to content

Commit 73a745b

Browse files
authored
Merge pull request #3147 from sveltejs/gh-2693
distinguish between lazy and non-lazy expressions
2 parents 1427206 + 7a11b75 commit 73a745b

File tree

8 files changed

+26
-9
lines changed

8 files changed

+26
-9
lines changed

src/compiler/compile/nodes/Animation.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ export default class Animation extends Node {
3434
block.has_animation = true;
3535

3636
this.expression = info.expression
37-
? new Expression(component, this, scope, info.expression)
37+
? new Expression(component, this, scope, info.expression, true)
3838
: null;
3939
}
4040
}

src/compiler/compile/nodes/EventHandler.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ export default class EventHandler extends Node {
2121
this.modifiers = new Set(info.modifiers);
2222

2323
if (info.expression) {
24-
this.expression = new Expression(component, this, template_scope, info.expression);
24+
this.expression = new Expression(component, this, template_scope, info.expression, true);
2525
this.uses_context = this.expression.uses_context;
2626

2727
if (/FunctionExpression/.test(info.expression.type) && info.expression.params.length === 0) {

src/compiler/compile/nodes/Transition.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ export default class Transition extends Node {
3434
}
3535

3636
this.expression = info.expression
37-
? new Expression(component, this, scope, info.expression)
37+
? new Expression(component, this, scope, info.expression, true)
3838
: null;
3939
}
4040
}

src/compiler/compile/nodes/shared/Expression.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ export default class Expression {
8686
rendered: string;
8787

8888
// todo: owner type
89-
constructor(component: Component, owner: Owner, template_scope: TemplateScope, info) {
89+
constructor(component: Component, owner: Owner, template_scope: TemplateScope, info, lazy?: boolean) {
9090
// TODO revert to direct property access in prod?
9191
Object.defineProperties(this, {
9292
component: {
@@ -146,11 +146,11 @@ export default class Expression {
146146

147147
contextual_dependencies.add(name);
148148

149-
if (!function_expression) {
149+
if (!lazy) {
150150
template_scope.dependencies_for_name.get(name).forEach(name => dependencies.add(name));
151151
}
152152
} else {
153-
if (!function_expression) {
153+
if (!lazy) {
154154
dependencies.add(name);
155155
}
156156

test/js/samples/action-custom-event-handler/expected.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,12 @@ function create_fragment(ctx) {
2323
foo_action = foo.call(null, button, ctx.foo_function) || {};
2424
},
2525

26-
p: noop,
26+
p(changed, ctx) {
27+
if (typeof foo_action.update === 'function' && changed.bar) {
28+
foo_action.update.call(null, ctx.foo_function);
29+
}
30+
},
31+
2732
i: noop,
2833
o: noop,
2934

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
export default {
2+
html: '<p>0</p>',
3+
4+
test({ assert, component, target }) {
5+
component.selected = 3;
6+
assert.htmlEqual(target.innerHTML, '<p>3</p>');
7+
}
8+
};
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<script>
2+
let list = [0, 1, 2, 3, 4];
3+
export let selected = 0;
4+
</script>
5+
6+
<p>{list.filter(x => x === selected)}</p>

test/runtime/samples/reactive-function/_config.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,8 @@ export default {
22
html: '<p>50</p>',
33

44
test({ assert, component, target }) {
5-
console.group('range [50,100]');
65
component.range = [50, 100];
76
assert.htmlEqual(target.innerHTML, '<p>75</p>');
8-
console.groupEnd();
97

108
component.range = [50, 60];
119
assert.htmlEqual(target.innerHTML, '<p>55</p>');

0 commit comments

Comments
 (0)