{"version":3,"file":"require_function_slots_for_programmatic_components.cjs","sources":["../../src/rules/require_function_slots_for_programmatic_components.ts"],"sourcesContent":["/**\n * @module @nhtio/eslint-config/rules/require_function_slots_for_programmatic_components\n */\n\nimport { createRule } from './common'\n\n/**\n * An ESLint rule that enforces the use of function slots for components rendered using Vue's h function.\n */\nconst requireFunctionSlotsForProgrammaticComponents = createRule({\n  name: 'requireFunctionSlotsForProgrammaticComponents',\n  meta: {\n    type: 'problem',\n    docs: {\n      description:\n        \"Require function slots for components rendered using Vue's h function. For non-string tags (i.e. components), children must be a function or an object with function properties.\",\n    },\n    schema: [], // no options\n    messages: {\n      invalidChildren:\n        'Slots for components must be provided as a function or an object with function properties.',\n    },\n  },\n  create(context) {\n    // helper to check if a node is a function\n    function isFunction(node: any) {\n      return node && (node.type === 'ArrowFunctionExpression' || node.type === 'FunctionExpression')\n    }\n\n    return {\n      CallExpression(node) {\n        // Check if this is a call to \"h\"\n        if (node.callee && node.callee.type === 'Identifier' && node.callee.name === 'h') {\n          // Ensure that there are at least three arguments: h(tag, props, children)\n          if (node.arguments.length < 3) {\n            return // nothing to enforce if children are not provided\n          }\n          const tagArg = node.arguments[0]\n          const childrenArg = node.arguments[2]\n\n          // Allow native elements (string literal tag) to use non-function children.\n          if (tagArg.type === 'Literal' && typeof tagArg.value === 'string') {\n            return\n          }\n\n          // For components, children must be a function.\n          if (isFunction(childrenArg)) {\n            return\n          }\n\n          // Alternatively, if children is an object, then every property must be a function.\n          if (childrenArg.type === 'ObjectExpression') {\n            let valid = true\n            for (const prop of childrenArg.properties) {\n              // Only consider normal object properties; if there’s any spread or unexpected structure, mark invalid.\n              if (prop.type !== 'Property') {\n                valid = false\n                break\n              }\n              // For a valid slot, the value must be a function.\n              if (!isFunction(prop.value)) {\n                valid = false\n                break\n              }\n            }\n            if (valid) {\n              return\n            }\n          }\n\n          // Otherwise, report an error.\n          context.report({\n            node: childrenArg,\n            messageId: 'invalidChildren',\n          })\n        }\n      },\n    }\n  },\n  defaultOptions: [],\n})\n\nexport default requireFunctionSlotsForProgrammaticComponents\n"],"names":["requireFunctionSlotsForProgrammaticComponents","createRule","context","isFunction","node","tagArg","childrenArg","valid","prop"],"mappings":"qJASMA,EAAgDC,EAAAA,WAAW,CAC/D,KAAM,gDACN,KAAM,CACJ,KAAM,UACN,KAAM,CACJ,YACE,kLAAA,EAEJ,OAAQ,CAAA,EACR,SAAU,CACR,gBACE,4FAAA,CACJ,EAEF,OAAOC,EAAS,CAEd,SAASC,EAAWC,EAAW,CAC7B,OAAOA,IAASA,EAAK,OAAS,2BAA6BA,EAAK,OAAS,qBAC3E,CAEA,MAAO,CACL,eAAeA,EAAM,CAEnB,GAAIA,EAAK,QAAUA,EAAK,OAAO,OAAS,cAAgBA,EAAK,OAAO,OAAS,IAAK,CAEhF,GAAIA,EAAK,UAAU,OAAS,EAC1B,OAEF,MAAMC,EAASD,EAAK,UAAU,CAAC,EACzBE,EAAcF,EAAK,UAAU,CAAC,EAQpC,GALIC,EAAO,OAAS,WAAa,OAAOA,EAAO,OAAU,UAKrDF,EAAWG,CAAW,EACxB,OAIF,GAAIA,EAAY,OAAS,mBAAoB,CAC3C,IAAIC,EAAQ,GACZ,UAAWC,KAAQF,EAAY,WAAY,CAEzC,GAAIE,EAAK,OAAS,WAAY,CAC5BD,EAAQ,GACR,KACF,CAEA,GAAI,CAACJ,EAAWK,EAAK,KAAK,EAAG,CAC3BD,EAAQ,GACR,KACF,CACF,CACA,GAAIA,EACF,MAEJ,CAGAL,EAAQ,OAAO,CACb,KAAMI,EACN,UAAW,iBAAA,CACZ,CACH,CACF,CAAA,CAEJ,EACA,eAAgB,CAAA,CAClB,CAAC"}