mirror of https://github.com/sveltejs/svelte
parent
9d947292a1
commit
12e7b5ecf5
@ -1,67 +1,66 @@
|
|||||||
import Component from '../Component';
|
import Component from '../Component';
|
||||||
import { Node } from '../../interfaces';
|
import { Node } from '../../interfaces';
|
||||||
// import { nodes_match } from '../../utils/nodes_match';
|
import { nodes_match } from '../../utils/nodes_match';
|
||||||
import { Scope } from './scope';
|
import { Scope } from './scope';
|
||||||
|
import { x } from 'code-red';
|
||||||
|
|
||||||
export function invalidate(_component: Component, _scope: Scope, _node: Node, _names: Set<string>) {
|
export function invalidate(component: Component, scope: Scope, node: Node, names: Set<string>) {
|
||||||
// const [head, ...tail] = Array.from(names).filter(name => {
|
const [head, ...tail] = Array.from(names).filter(name => {
|
||||||
// const owner = scope.find_owner(name);
|
const owner = scope.find_owner(name);
|
||||||
// if (owner && owner !== component.instance_scope) return false;
|
if (owner && owner !== component.instance_scope) return false;
|
||||||
|
|
||||||
// const variable = component.var_lookup.get(name);
|
const variable = component.var_lookup.get(name);
|
||||||
|
|
||||||
// return variable && (
|
return variable && (
|
||||||
// !variable.hoistable &&
|
!variable.hoistable &&
|
||||||
// !variable.global &&
|
!variable.global &&
|
||||||
// !variable.module &&
|
!variable.module &&
|
||||||
// (
|
(
|
||||||
// variable.referenced ||
|
variable.referenced ||
|
||||||
// variable.is_reactive_dependency ||
|
variable.is_reactive_dependency ||
|
||||||
// variable.export_name ||
|
variable.export_name ||
|
||||||
// variable.name[0] === '$'
|
variable.name[0] === '$'
|
||||||
// )
|
)
|
||||||
// );
|
);
|
||||||
// });
|
});
|
||||||
|
|
||||||
// TODO
|
if (head) {
|
||||||
|
component.has_reactive_assignments = true;
|
||||||
|
|
||||||
// if (head) {
|
if (node.operator === '=' && nodes_match(node.left, node.right) && tail.length === 0) {
|
||||||
// component.has_reactive_assignments = true;
|
return component.invalidate(head);
|
||||||
|
} else {
|
||||||
|
|
||||||
// if (node.operator === '=' && nodes_match(node.left, node.right) && tail.length === 0) {
|
// TODO stores
|
||||||
// code.overwrite(node.start, node.end, component.invalidate(head));
|
// if (head[0] === '$') {
|
||||||
// } else {
|
// code.prependRight(node.start, `${component.helper('set_store_value')}(${head.slice(1)}, `);
|
||||||
// let suffix = ')';
|
// } else {
|
||||||
|
// let prefix = `$$invalidate`;
|
||||||
|
|
||||||
// if (head[0] === '$') {
|
// const variable = component.var_lookup.get(head);
|
||||||
// code.prependRight(node.start, `${component.helper('set_store_value')}(${head.slice(1)}, `);
|
// if (variable.subscribable && variable.reassigned) {
|
||||||
// } else {
|
// prefix = `$$subscribe_${head}($$invalidate`;
|
||||||
// let prefix = `$$invalidate`;
|
// suffix += `)`;
|
||||||
|
// }
|
||||||
|
|
||||||
// const variable = component.var_lookup.get(head);
|
// code.prependRight(node.start, `${prefix}('${head}', `);
|
||||||
// if (variable.subscribable && variable.reassigned) {
|
// }
|
||||||
// prefix = `$$subscribe_${head}($$invalidate`;
|
|
||||||
// suffix += `)`;
|
|
||||||
// }
|
|
||||||
|
|
||||||
// code.prependRight(node.start, `${prefix}('${head}', `);
|
const extra_args = tail.map(name => component.invalidate(name));
|
||||||
// }
|
|
||||||
|
|
||||||
// const extra_args = tail.map(name => component.invalidate(name));
|
const pass_value = (
|
||||||
|
extra_args.length > 0 ||
|
||||||
|
(node.type === 'AssignmentExpression' && node.left.type !== 'Identifier') ||
|
||||||
|
(node.type === 'UpdateExpression' && !node.prefix)
|
||||||
|
);
|
||||||
|
|
||||||
// const pass_value = (
|
if (pass_value) {
|
||||||
// extra_args.length > 0 ||
|
extra_args.unshift(head);
|
||||||
// (node.type === 'AssignmentExpression' && node.left.type !== 'Identifier') ||
|
}
|
||||||
// (node.type === 'UpdateExpression' && !node.prefix)
|
|
||||||
// );
|
|
||||||
|
|
||||||
// if (pass_value) {
|
return x`$$invalidate("${head}", ${node}, ${extra_args})`;
|
||||||
// extra_args.unshift(head);
|
}
|
||||||
// }
|
}
|
||||||
|
|
||||||
// suffix = `${extra_args.map(arg => `, ${arg}`).join('')}${suffix}`;
|
return node;
|
||||||
|
|
||||||
// code.appendLeft(node.end, suffix);
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
}
|
}
|
@ -1,3 +1,3 @@
|
|||||||
export default {
|
export default {
|
||||||
html: '<h1>1 + 2 = 3</h1>'
|
html: '<p>1 + 2 = 3</p>'
|
||||||
};
|
};
|
Loading…
Reference in new issue