Skip to content

Commit 04339ef

Browse files
committedJul 2, 2019
add pending assignments when leaving assignment expressions, not entering them
1 parent 5c77f2b commit 04339ef

File tree

1 file changed

+35
-35
lines changed

1 file changed

+35
-35
lines changed
 

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

+35-35
Original file line numberDiff line numberDiff line change
@@ -288,41 +288,7 @@ export default class Expression {
288288
this.skip();
289289
}
290290

291-
if (function_expression) {
292-
if (node.type === 'AssignmentExpression') {
293-
const names = node.left.type === 'MemberExpression'
294-
? [get_object(node.left).name]
295-
: extract_names(node.left);
296-
297-
if (node.operator === '=' && nodes_match(node.left, node.right)) {
298-
const dirty = names.filter(name => {
299-
return !scope.declarations.has(name);
300-
});
301-
302-
if (dirty.length) component.has_reactive_assignments = true;
303-
304-
code.overwrite(node.start, node.end, dirty.map(n => component.invalidate(n)).join('; '));
305-
} else {
306-
names.forEach(name => {
307-
if (scope.declarations.has(name)) return;
308-
309-
const variable = component.var_lookup.get(name);
310-
if (variable && variable.hoistable) return;
311-
312-
pending_assignments.add(name);
313-
});
314-
}
315-
} else if (node.type === 'UpdateExpression') {
316-
const { name } = get_object(node.argument);
317-
318-
if (scope.declarations.has(name)) return;
319-
320-
const variable = component.var_lookup.get(name);
321-
if (variable && variable.hoistable) return;
322-
323-
pending_assignments.add(name);
324-
}
325-
} else {
291+
if (!function_expression) {
326292
if (node.type === 'AssignmentExpression') {
327293
// TODO should this be a warning/error? `<p>{foo = 1}</p>`
328294
}
@@ -447,6 +413,40 @@ export default class Expression {
447413
contextual_dependencies = null;
448414
}
449415

416+
if (node.type === 'AssignmentExpression') {
417+
const names = node.left.type === 'MemberExpression'
418+
? [get_object(node.left).name]
419+
: extract_names(node.left);
420+
421+
if (node.operator === '=' && nodes_match(node.left, node.right)) {
422+
const dirty = names.filter(name => {
423+
return !scope.declarations.has(name);
424+
});
425+
426+
if (dirty.length) component.has_reactive_assignments = true;
427+
428+
code.overwrite(node.start, node.end, dirty.map(n => component.invalidate(n)).join('; '));
429+
} else {
430+
names.forEach(name => {
431+
if (scope.declarations.has(name)) return;
432+
433+
const variable = component.var_lookup.get(name);
434+
if (variable && variable.hoistable) return;
435+
436+
pending_assignments.add(name);
437+
});
438+
}
439+
} else if (node.type === 'UpdateExpression') {
440+
const { name } = get_object(node.argument);
441+
442+
if (scope.declarations.has(name)) return;
443+
444+
const variable = component.var_lookup.get(name);
445+
if (variable && variable.hoistable) return;
446+
447+
pending_assignments.add(name);
448+
}
449+
450450
if (/Statement/.test(node.type)) {
451451
if (pending_assignments.size > 0) {
452452
const has_semi = code.original[node.end - 1] === ';';

0 commit comments

Comments
 (0)
Please sign in to comment.