Skip to content

Commit

Permalink
improve static considertaion for contextual variable
Browse files Browse the repository at this point in the history
  • Loading branch information
tanhauhau committed Apr 16, 2022
1 parent 563fc88 commit cd46954
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
9 changes: 9 additions & 0 deletions src/compiler/compile/nodes/shared/Expression.ts
Expand Up @@ -175,6 +175,15 @@ export default class Expression {
});
}

dynamic_contextual_dependencies() {
return Array.from(this.contextual_dependencies).filter(name => {
return Array.from(this.template_scope.dependencies_for_name.get(name)).some(variable_name => {
const variable = this.component.var_lookup.get(variable_name);
return is_dynamic(variable);
});
});
}

// TODO move this into a render-dom wrapper?
manipulate(block?: Block, ctx?: string | void) {
// TODO ideally we wouldn't end up calling this method
Expand Down
2 changes: 1 addition & 1 deletion src/compiler/compile/nodes/shared/Tag.ts
Expand Up @@ -19,7 +19,7 @@ export default class Tag extends Node {
);
}
is_dependencies_static() {
return this.expression.contextual_dependencies.size === 0 && this.expression.dynamic_dependencies().length === 0;
return this.expression.dynamic_contextual_dependencies().length === 0 && this.expression.dynamic_dependencies().length === 0;
}
check_if_content_dynamic() {
if (!this.is_dependencies_static()) {
Expand Down

0 comments on commit cd46954

Please sign in to comment.