({ filePath, project }: { project: Project; filePath: string })
| 9 | ]; |
| 10 | |
| 11 | export const findSignals = ({ filePath, project }: { project: Project; filePath: string }) => { |
| 12 | const ast = project.getSourceFileOrThrow(filePath); |
| 13 | |
| 14 | if (ast === undefined) { |
| 15 | throw new Error('Could not find AST. Please provide a correct `filePath`.'); |
| 16 | } |
| 17 | |
| 18 | const reactiveValues = { |
| 19 | props: new Set<string>(), |
| 20 | state: new Set<string>(), |
| 21 | context: new Set<string>(), |
| 22 | }; |
| 23 | |
| 24 | const propsSymbol = getPropsSymbol(ast); |
| 25 | |
| 26 | const contextSymbols = getContextSymbols(ast); |
| 27 | |
| 28 | const checkIsSignalSymbol = (type: Type<ts.Type>) => { |
| 29 | const symbol = type.getTargetType()?.getAliasSymbol(); |
| 30 | |
| 31 | if (!symbol || symbol.getName() !== 'Signal') return false; |
| 32 | |
| 33 | const compilerSymbol = symbol?.compilerSymbol; |
| 34 | const parent: ts.Symbol | undefined = (compilerSymbol as any).parent; |
| 35 | |
| 36 | if (!parent) return false; |
| 37 | |
| 38 | if (MITOSIS_IMPORT_PATHS.some((path) => parent.getName().includes(path))) { |
| 39 | return true; |
| 40 | } |
| 41 | |
| 42 | return false; |
| 43 | }; |
| 44 | |
| 45 | const checkIsOptionalSignal = (node: Node) => { |
| 46 | let hasUndefined = false; |
| 47 | let hasSignal = false; |
| 48 | |
| 49 | const perfectMatch = node |
| 50 | .getType() |
| 51 | .getUnionTypes() |
| 52 | .every((type) => { |
| 53 | if (type.isUndefined()) { |
| 54 | hasUndefined = true; |
| 55 | return true; |
| 56 | } else if (checkIsSignalSymbol(type)) { |
| 57 | hasSignal = true; |
| 58 | return true; |
| 59 | } |
| 60 | |
| 61 | return false; |
| 62 | }); |
| 63 | |
| 64 | return perfectMatch && hasUndefined && hasSignal; |
| 65 | }; |
| 66 | |
| 67 | ast.forEachDescendant((parentNode) => { |
| 68 | if (Node.isPropertyAccessExpression(parentNode)) { |
no test coverage detected