UNPKG

marko-widgets

Version:

<h1 align="center"> <!-- Logo --> <br/> marko-widgets@8 <br/>

84 lines (83 loc) 3.09 kB
"use strict"; var __defProp = Object.defineProperty; var __getOwnPropDesc = Object.getOwnPropertyDescriptor; var __getOwnPropNames = Object.getOwnPropertyNames; var __hasOwnProp = Object.prototype.hasOwnProperty; var __export = (target, all) => { for (var name in all) __defProp(target, name, { get: all[name], enumerable: true }); }; var __copyProps = (to, from, except, desc) => { if (from && typeof from === "object" || typeof from === "function") { for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); } return to; }; var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); var migrate_exports = {}; __export(migrate_exports, { default: () => migrate_default }); module.exports = __toCommonJS(migrate_exports); var import_compiler = require("@marko/compiler"); var import_babel_utils = require("@marko/babel-utils"); var import_compat_utils = require("@marko/compat-utils"); var migrate_default = { exit(tag) { let hasErrors = false; if (!tag.node.attributes.length) { (0, import_babel_utils.diagnosticError)(tag, { label: "The <invoke> tag requires a value." }); hasErrors = true; } const attrs = tag.get("attributes"); const functionAttr = attrs[0]; if (functionAttr && !((0, import_compat_utils.isSourceBooleanAttribute)(functionAttr.node) && functionAttr.node.arguments)) { (0, import_babel_utils.diagnosticError)(functionAttr, { label: "The <invoke> tag requires a function call." }); hasErrors = true; } if (hasErrors) { tag.remove(); return; } const { file } = tag.hub; const start = (0, import_babel_utils.getStart)(file, functionAttr.node); const end = (0, import_babel_utils.getEnd)(file, functionAttr.node); const callIdentifier = start == null ? (0, import_babel_utils.parseExpression)(file, functionAttr.node.name) : (0, import_babel_utils.parseExpression)( file, functionAttr.node.name, start, start + functionAttr.node.name.length ); const callExpression = import_compiler.types.callExpression( callIdentifier, functionAttr.node.arguments ); if (start != null && end !== null) { (0, import_babel_utils.withLoc)(file, callExpression, start, end); } const dynamicTag = (0, import_compat_utils.renderCallToDynamicTag)(callExpression); if (dynamicTag) { for (let i = 1; i < attrs.length; i++) { dynamicTag.attributes.push(attrs[i].node); } tag.replaceWith(dynamicTag); return; } if (attrs.length > 1) { (0, import_babel_utils.diagnosticError)(attrs[1], { label: "The <invoke> tag does not support other attributes." }); tag.remove(); return; } tag.replaceWith( import_compiler.types.markoScriptlet([import_compiler.types.expressionStatement(callExpression)], false) ); } };