Skip to content

Commit

Permalink
add babel types
Browse files Browse the repository at this point in the history
  • Loading branch information
OrionReed committed Dec 2, 2024
1 parent 7bf64b6 commit b1e20bf
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions src/folk-event-propagator.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { css } from './common/tags.ts';
import { FolkRope } from './folk-rope.ts';
import * as parser from '@babel/parser';
import type { Node } from '@babel/types';

const styles = new CSSStyleSheet();
styles.replaceSync(css`
Expand Down Expand Up @@ -220,7 +221,7 @@ function parseAst(functionBody: string) {
const toProps = new Set<string>();
const fromProps = new Set<string>();

function walkAst(node: any) {
function walkAst(node: Node) {
if (!node || typeof node !== 'object') return;

if (node.type === 'MemberExpression' && node.object?.type === 'Identifier') {
Expand All @@ -237,11 +238,12 @@ function parseAst(functionBody: string) {
}

// Recursively walk through all properties
for (const key in node) {
if (Array.isArray(node[key])) {
node[key].forEach(walkAst);
} else if (node[key] && typeof node[key] === 'object') {
walkAst(node[key]);
for (const key of Object.keys(node)) {
const value = (node as any)[key];
if (Array.isArray(value)) {
value.forEach(walkAst);
} else if (value && typeof value === 'object') {
walkAst(value as Node);
}
}
}
Expand Down

0 comments on commit b1e20bf

Please sign in to comment.