remove function invocation dependency tracking

pull/1839/head
Rich Harris 7 years ago
parent 9ead0e8096
commit 7e72b49b6e

@ -376,62 +376,6 @@ export default class Component {
});
}
findDependenciesForFunctionCall(name) {
const declaration = this.node_for_declaration.get(name);
const dependencies = new Set();
if (!declaration) {
// Global or module-scoped function — can't have
// local state as dependency by definition
return dependencies;
}
let { instance_scope, instance_scope_map: map } = this;
let scope = instance_scope;
const component = this;
let bail = false;
walk(declaration, {
enter(node, parent) {
if (map.has(node)) {
scope = map.get(node);
}
if (isReference(node, parent)) {
const { name } = flattenReference(node);
if (scope.findOwner(name) === instance_scope) {
dependencies.add(name);
}
}
if (node.type === 'CallExpression') {
if (node.callee.type === 'Identifier') {
const call_dependencies = component.findDependenciesForFunctionCall(node.callee.name);
if (!call_dependencies) {
bail = true;
return this.skip();
}
addToSet(dependencies, call_dependencies);
} else {
bail = true;
return this.skip();
}
}
},
leave(node) {
if (map.has(node)) {
scope = map.get(node);
}
}
});
return bail ? null : dependencies;
}
extract_imports_and_exports(content, imports, exports) {
const { code } = this;

@ -142,20 +142,6 @@ export default class Expression {
this.skip();
}
if (node.type === 'CallExpression') {
// TODO remove this? rely on reactive declarations?
if (node.callee.type === 'Identifier') {
const dependencies_for_invocation = component.findDependenciesForFunctionCall(node.callee.name);
if (dependencies_for_invocation) {
addToSet(dependencies, dependencies_for_invocation);
} else {
dependencies.add('$$BAIL$$');
}
} else {
dependencies.add('$$BAIL$$');
}
}
}
});

@ -426,9 +426,6 @@ export default class EachBlockWrapper extends Wrapper {
`);
}
// TODO do this for keyed blocks as well
const bail = allDependencies.has('$$BAIL$$');
const condition = Array.from(allDependencies)
.map(dependency => `changed.${dependency}`)
.join(' || ');
@ -490,15 +487,11 @@ export default class EachBlockWrapper extends Wrapper {
${destroy}
`;
if (bail) {
block.builders.update.addBlock(update);
} else {
block.builders.update.addBlock(deindent`
if (${condition}) {
${update}
}
`);
}
block.builders.update.addBlock(deindent`
if (${condition}) {
${update}
}
`);
}
if (outroBlock) {

@ -168,11 +168,9 @@ export default class AttributeWrapper {
const updateCachedValue = `${last} !== (${last} = ${value})`;
const condition = this.node.dependencies.has('$$BAIL$$')
? updateCachedValue
: shouldCache
? (dependencies.length ? `(${changedCheck}) && ${updateCachedValue}` : updateCachedValue)
: changedCheck;
const condition = shouldCache
? (dependencies.length ? `(${changedCheck}) && ${updateCachedValue}` : updateCachedValue)
: changedCheck;
block.builders.update.addConditional(
condition,

@ -45,22 +45,16 @@ export default class StyleAttributeWrapper extends AttributeWrapper {
.join(' + ');
if (propDependencies.size) {
if (propDependencies.has('$$BAIL$$')) {
block.builders.update.addLine(
`@setStyle(${this.parent.var}, "${prop.key}", ${value});`
);
} else {
const dependencies = Array.from(propDependencies);
const condition = (
(block.hasOutros ? `!#current || ` : '') +
dependencies.map(dependency => `changed.${dependency}`).join(' || ')
);
block.builders.update.addConditional(
condition,
`@setStyle(${this.parent.var}, "${prop.key}", ${value});`
);
}
const dependencies = Array.from(propDependencies);
const condition = (
(block.hasOutros ? `!#current || ` : '') +
dependencies.map(dependency => `changed.${dependency}`).join(' || ')
);
block.builders.update.addConditional(
condition,
`@setStyle(${this.parent.var}, "${prop.key}", ${value});`
);
}
} else {
value = stringify(prop.value[0].data);

@ -557,12 +557,11 @@ export default class ElementWrapper extends Wrapper {
this.node.attributes
.filter(attr => attr.type === 'Attribute' || attr.type === 'Spread')
.forEach(attr => {
const condition = (attr.dependencies.size > 0 && !attr.dependencies.has('$$BAIL$$'))
const condition = attr.dependencies.size > 0
? `(${[...attr.dependencies].map(d => `changed.${d}`).join(' || ')})`
: null;
if (attr.isSpread) {
const { dependencies } = attr.expression;
const snippet = attr.expression.render();
initialProps.push(snippet);

@ -144,8 +144,6 @@ export default class InlineComponentWrapper extends Wrapper {
this.node.attributes.forEach(attr => {
const { name, dependencies } = attr;
// TODO probably need to account for $$BAIL$$ but
// not totally sure how. will come back to it
const condition = dependencies.size > 0 && (dependencies.size !== allDependencies.size)
? `(${[...dependencies].map(d => `changed.${d}`).join(' || ')})`
: null;

@ -34,13 +34,11 @@ export default class Tag extends Wrapper {
const updateCachedValue = `${value} !== (${value} = ${snippet})`;
const condition = dependencies.has('$$BAIL$$')
? updateCachedValue
: this.node.shouldCache
? dependencies.size > 0
? `(${changedCheck}) && ${updateCachedValue}`
: updateCachedValue
: changedCheck;
const condition =this.node.shouldCache
? dependencies.size > 0
? `(${changedCheck}) && ${updateCachedValue}`
: updateCachedValue
: changedCheck;
block.builders.update.addConditional(
condition,

Loading…
Cancel
Save