From bcfff0da521db71a5a37a48c6e845887013f8761 Mon Sep 17 00:00:00 2001 From: Simon Holthausen Date: Fri, 12 May 2023 15:00:59 +0200 Subject: [PATCH] Convert src/compiler/compile/render_dom/wrappers/shared/mark_each_block_bindings.ts to JavaScript --- .../shared/{is_head.ts => is_head.js} | 7 +- .../shared/mark_each_block_bindings.ts | 65 ++++++++++--------- 2 files changed, 37 insertions(+), 35 deletions(-) rename src/compiler/compile/render_dom/wrappers/shared/{is_head.ts => is_head.js} (64%) diff --git a/src/compiler/compile/render_dom/wrappers/shared/is_head.ts b/src/compiler/compile/render_dom/wrappers/shared/is_head.js similarity index 64% rename from src/compiler/compile/render_dom/wrappers/shared/is_head.ts rename to src/compiler/compile/render_dom/wrappers/shared/is_head.js index b5037ad433..52b0f348f1 100644 --- a/src/compiler/compile/render_dom/wrappers/shared/is_head.ts +++ b/src/compiler/compile/render_dom/wrappers/shared/is_head.js @@ -1,6 +1,7 @@ -import { Node } from 'estree'; - -export function is_head(node: Node) { +/** + * @param {import("estree").Node} node + */ +export function is_head(node) { return ( node && node.type === 'MemberExpression' && diff --git a/src/compiler/compile/render_dom/wrappers/shared/mark_each_block_bindings.ts b/src/compiler/compile/render_dom/wrappers/shared/mark_each_block_bindings.ts index 2ecc647954..4ef5a03f1d 100644 --- a/src/compiler/compile/render_dom/wrappers/shared/mark_each_block_bindings.ts +++ b/src/compiler/compile/render_dom/wrappers/shared/mark_each_block_bindings.ts @@ -1,34 +1,35 @@ -import EachBlock from '../../../nodes/EachBlock'; -import InlineComponentWrapper from '../InlineComponent'; -import ElementWrapper from '../Element'; -import Binding from '../../../nodes/Binding'; +/** + * @param {import('../Element.js').default | import('../InlineComponent.js').default} parent + * @param {import('../../../nodes/Binding.js').default} 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( - parent: ElementWrapper | InlineComponentWrapper, - binding: 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) { - (each_block as EachBlock).has_binding = true; - } - }); - - 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 ``, we make sure that all the each blocks creates context with `index` - for (const name of binding.expression.contextual_dependencies) { - add_index_binding(name); - } - } + /** @param {string} name */ + const add_index_binding = (name) => { + 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 ``, we make sure that all the each blocks creates context with `index` + for (const name of binding.expression.contextual_dependencies) { + add_index_binding(name); + } + } } + + + +