|
|
|
|
@ -254,33 +254,17 @@ export default class Expression {
|
|
|
|
|
const declaration = b`const ${id} = ${node}`;
|
|
|
|
|
|
|
|
|
|
if (owner.type === 'ConstTag') {
|
|
|
|
|
const param_names_stack: string[][] = [];
|
|
|
|
|
const is_base_function = (node: BaseNode): node is BaseFunction => 'params' in node;
|
|
|
|
|
const is_member_expression = (node: BaseNode): node is MemberExpression => 'computed' in node;
|
|
|
|
|
const push_params = (params: Pattern[]) => {
|
|
|
|
|
const param_names: string[] = [];
|
|
|
|
|
params.forEach((param => {
|
|
|
|
|
walk(param, {
|
|
|
|
|
enter(node: Node) {
|
|
|
|
|
if (node.type === 'Identifier') param_names.push(node.name);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}));
|
|
|
|
|
param_names_stack.push(param_names);
|
|
|
|
|
};
|
|
|
|
|
const is_context = (node: Identifier, parent: Node, key: string): boolean => {
|
|
|
|
|
if (key === 'params' || (key === 'property' && is_member_expression(parent) && !parent.computed)) return false;
|
|
|
|
|
return !param_names_stack.some((param_names) => param_names.includes(node.name));
|
|
|
|
|
};
|
|
|
|
|
let child_scope = scope;
|
|
|
|
|
walk(node, {
|
|
|
|
|
enter(node: Node, parent: Node, key: string) {
|
|
|
|
|
if (is_base_function(node)) push_params(node.params);
|
|
|
|
|
if (node.type === 'Identifier' && is_context(node, parent, key)) {
|
|
|
|
|
enter(node: Node, parent: any) {
|
|
|
|
|
if (map.has(node)) child_scope = map.get(node);
|
|
|
|
|
if (node.type === 'Identifier' && is_reference(node, parent)) {
|
|
|
|
|
if (child_scope.has(node.name)) return;
|
|
|
|
|
this.replace(block.renderer.reference(node, ctx));
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
leave(node: Node) {
|
|
|
|
|
if (is_base_function(node)) param_names_stack.pop();
|
|
|
|
|
if (map.has(node)) child_scope = child_scope.parent;
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
} else if (dependencies.size === 0 && contextual_dependencies.size === 0) {
|
|
|
|
|
|