{"version":3,"file":"require_function_slots_for_programmatic_components.mjs","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":";AASA,MAAMA,IAAgDC,EAAW;AAAA,EAC/D,MAAM;AAAA,EACN,MAAM;AAAA,IACJ,MAAM;AAAA,IACN,MAAM;AAAA,MACJ,aACE;AAAA,IAAA;AAAA,IAEJ,QAAQ,CAAA;AAAA;AAAA,IACR,UAAU;AAAA,MACR,iBACE;AAAA,IAAA;AAAA,EACJ;AAAA,EAEF,OAAOC,GAAS;AAEd,aAASC,EAAWC,GAAW;AAC7B,aAAOA,MAASA,EAAK,SAAS,6BAA6BA,EAAK,SAAS;AAAA,IAC3E;AAEA,WAAO;AAAA,MACL,eAAeA,GAAM;AAEnB,YAAIA,EAAK,UAAUA,EAAK,OAAO,SAAS,gBAAgBA,EAAK,OAAO,SAAS,KAAK;AAEhF,cAAIA,EAAK,UAAU,SAAS;AAC1B;AAEF,gBAAMC,IAASD,EAAK,UAAU,CAAC,GACzBE,IAAcF,EAAK,UAAU,CAAC;AAQpC,cALIC,EAAO,SAAS,aAAa,OAAOA,EAAO,SAAU,YAKrDF,EAAWG,CAAW;AACxB;AAIF,cAAIA,EAAY,SAAS,oBAAoB;AAC3C,gBAAIC,IAAQ;AACZ,uBAAWC,KAAQF,EAAY,YAAY;AAEzC,kBAAIE,EAAK,SAAS,YAAY;AAC5B,gBAAAD,IAAQ;AACR;AAAA,cACF;AAEA,kBAAI,CAACJ,EAAWK,EAAK,KAAK,GAAG;AAC3B,gBAAAD,IAAQ;AACR;AAAA,cACF;AAAA,YACF;AACA,gBAAIA;AACF;AAAA,UAEJ;AAGA,UAAAL,EAAQ,OAAO;AAAA,YACb,MAAMI;AAAA,YACN,WAAW;AAAA,UAAA,CACZ;AAAA,QACH;AAAA,MACF;AAAA,IAAA;AAAA,EAEJ;AAAA,EACA,gBAAgB,CAAA;AAClB,CAAC;"}