mirror of https://github.com/sveltejs/svelte
pull/8569/head
parent
fda41da2a4
commit
bcfff0da52
@ -1,6 +1,7 @@
|
|||||||
import { Node } from 'estree';
|
/**
|
||||||
|
* @param {import("estree").Node} node
|
||||||
export function is_head(node: Node) {
|
*/
|
||||||
|
export function is_head(node) {
|
||||||
return (
|
return (
|
||||||
node &&
|
node &&
|
||||||
node.type === 'MemberExpression' &&
|
node.type === 'MemberExpression' &&
|
||||||
@ -1,34 +1,35 @@
|
|||||||
import EachBlock from '../../../nodes/EachBlock';
|
/**
|
||||||
import InlineComponentWrapper from '../InlineComponent';
|
* @param {import('../Element.js').default | import('../InlineComponent.js').default} parent
|
||||||
import ElementWrapper from '../Element';
|
* @param {import('../../../nodes/Binding.js').default} binding
|
||||||
import Binding from '../../../nodes/Binding';
|
*/
|
||||||
|
export default function mark_each_block_bindings(parent, binding) {
|
||||||
|
// we need to ensure that the each block creates a context including
|
||||||
|
// the list and the index, if they're not otherwise referenced
|
||||||
|
binding.expression.references.forEach((name) => {
|
||||||
|
const each_block = parent.node.scope.get_owner(name);
|
||||||
|
if (each_block) {
|
||||||
|
( /** @type {import('../../../nodes/EachBlock.js').default} */(each_block)).has_binding = true;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
if (binding.name === 'group') {
|
||||||
|
|
||||||
export default function mark_each_block_bindings(
|
/** @param {string} name */
|
||||||
parent: ElementWrapper | InlineComponentWrapper,
|
const add_index_binding = (name) => {
|
||||||
binding: Binding
|
const each_block = parent.node.scope.get_owner(name);
|
||||||
) {
|
if (each_block.type === 'EachBlock') {
|
||||||
// we need to ensure that the each block creates a context including
|
each_block.has_index_binding = true;
|
||||||
// the list and the index, if they're not otherwise referenced
|
for (const dep of each_block.expression.contextual_dependencies) {
|
||||||
binding.expression.references.forEach((name) => {
|
add_index_binding(dep);
|
||||||
const each_block = parent.node.scope.get_owner(name);
|
}
|
||||||
if (each_block) {
|
}
|
||||||
(each_block as EachBlock).has_binding = true;
|
};
|
||||||
}
|
// for `<input bind:group={} >`, we make sure that all the each blocks creates context with `index`
|
||||||
});
|
for (const name of binding.expression.contextual_dependencies) {
|
||||||
|
add_index_binding(name);
|
||||||
if (binding.name === 'group') {
|
}
|
||||||
const add_index_binding = (name: string) => {
|
}
|
||||||
const each_block = parent.node.scope.get_owner(name);
|
|
||||||
if (each_block.type === 'EachBlock') {
|
|
||||||
each_block.has_index_binding = true;
|
|
||||||
for (const dep of each_block.expression.contextual_dependencies) {
|
|
||||||
add_index_binding(dep);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
// for `<input bind:group={} >`, we make sure that all the each blocks creates context with `index`
|
|
||||||
for (const name of binding.expression.contextual_dependencies) {
|
|
||||||
add_index_binding(name);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in new issue