UNPKG

@builder.io/mitosis

Version:

Write components once, run everywhere. Compiles to Vue, React, Solid, and Liquid. Import code from Figma and Builder.io

39 lines (38 loc) 1.71 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.checkIfIsClientComponent = void 0; const event_handlers_1 = require("../../helpers/event-handlers"); const is_mitosis_node_1 = require("../../helpers/is-mitosis-node"); const legacy_1 = __importDefault(require("neotraverse/legacy")); const checkIsNodeAMitosisComponent = (node) => node.name[0] === node.name[0].toUpperCase(); const checkIfIsClientComponent = (json) => { var _a, _b; if (json.hooks.onMount.length) return true; if ((_a = json.hooks.onUnMount) === null || _a === void 0 ? void 0 : _a.code) return true; if ((_b = json.hooks.onUpdate) === null || _b === void 0 ? void 0 : _b.length) return true; if (Object.keys(json.refs).length) return true; if (Object.keys(json.context.set).length) return true; if (Object.keys(json.context.get).length) return true; if (Object.values(json.state).filter((s) => (s === null || s === void 0 ? void 0 : s.type) === 'property').length) return true; let foundEventListener = false; (0, legacy_1.default)(json).forEach(function (node) { if ((0, is_mitosis_node_1.isMitosisNode)(node) && !checkIsNodeAMitosisComponent(node)) { if (Object.keys(node.bindings).filter((item) => (0, event_handlers_1.checkIsEvent)(item)).length) { foundEventListener = true; this.stop(); } } }); return foundEventListener; }; exports.checkIfIsClientComponent = checkIfIsClientComponent;