The SETUP function of a Pinia setup store (`defineStore('id', () => {…})`) * — an arrow/function arg with a block body. Returns null for the options form * (`defineStore({…})`) and for any non-defineStore call. The setup body's local * function consts are the store's actions; the generic
(callNode: SyntaxNode)
| 2497 | * function consts are the store's actions; the generic body walk doesn't reach |
| 2498 | * them (nested functions are separate scopes), so they're extracted explicitly. */ |
| 2499 | private findPiniaSetupFn(callNode: SyntaxNode): SyntaxNode | null { |
| 2500 | const callee = getChildByField(callNode, 'function'); |
| 2501 | if (!callee || callee.type !== 'identifier' || getNodeText(callee, this.source) !== 'defineStore') return null; |
| 2502 | const args = getChildByField(callNode, 'arguments'); |
| 2503 | if (!args) return null; |
| 2504 | for (let i = 0; i < args.namedChildCount; i++) { |
| 2505 | const arg = args.namedChild(i); |
| 2506 | if (arg?.type !== 'arrow_function' && arg?.type !== 'function_expression') continue; |
| 2507 | const body = getChildByField(arg, 'body'); |
| 2508 | if (body?.type === 'statement_block') return arg; // block body ⇒ setup form |
| 2509 | } |
| 2510 | return null; |
| 2511 | } |
| 2512 | |
| 2513 | /** Extract a Pinia setup store's actions: the body-local `const foo = () => …` |
| 2514 | * / `function foo(){}` declarations, named by the binding. (State refs and other |
no test coverage detected