From bfff83b883fca9f60bc7596c614803d282f87d12 Mon Sep 17 00:00:00 2001 From: Josh Wilson Date: Sun, 18 Jun 2023 10:54:19 -0400 Subject: [PATCH] WIP getReferences --- src/rules/reactivity/rule.ts | 27 ++++++++++++--------------- 1 file changed, 12 insertions(+), 15 deletions(-) diff --git a/src/rules/reactivity/rule.ts b/src/rules/reactivity/rule.ts index 9941dc7..2344738 100644 --- a/src/rules/reactivity/rule.ts +++ b/src/rules/reactivity/rule.ts @@ -123,24 +123,21 @@ export default createRule({ ): Array { node = ignoreTransparentWrappers(node, "up"); const parsedPathOuter = path != null ? parsePath(path) : null; - const eqCount = parsedPathOuter?.reduce((c, segment) => c + +(segment === '='), 0) ?? 0; + const eqCount = parsedPathOuter?.reduce((c, segment) => c + +(segment === "="), 0) ?? 0; if (eqCount > 1) { - throw new Error(`'${path}' must have 0 or 1 '=' characters, has ${eqCount}`) + throw new Error(`'${path}' must have 0 or 1 '=' characters, has ${eqCount}`); } const hasEq = eqCount === 1; - let declarationScope = hasEq ? null : context.getScope(); + const declarationScope = hasEq ? null : context.getScope(); function* recursiveGenerator(node: T.Node, parsedPath: Array | null) { - - - if (!parsedPath) { - yield VirtualReference(node); - } else if (node.parent?.type === "VariableDeclarator" && node.parent.init === node) { - yield getReferences(node.parent.id); - } else if (node.type === "Identifier") { - - } + if (!parsedPath) { + yield VirtualReference(node); + } else if (node.parent?.type === "VariableDeclarator" && node.parent.init === node) { + yield getReferences(node.parent.id); + } else if (node.type === "Identifier") { + } const { id } = node.parent; if (id.type === "Identifier") { const variable = findVariable(context.getScope(), id); @@ -173,9 +170,9 @@ export default createRule({ } else { } } - - - return Array.from(recursiveGenerator(node, parsePath(path))); + + return Array.from(recursiveGenerator(node, parsePath(path))); + } } function distributeReferences(root: ReactivityScope, references: Array) {