UNPKG

marko-widgets

Version:

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

83 lines (82 loc) 3.44 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 migrate_default = { exit(tag) { if (!tag.node.attributes.length) { (0, import_babel_utils.diagnosticError)(tag, { label: "The <assign> tag requires a value.", fix() { tag.remove(); } }); return; } (0, import_babel_utils.diagnosticDeprecate)(tag, { label: 'The "<assign>" tag is deprecated. Please use "$ <js_code>" for JavaScript in the template. See: https://github.com/marko-js/marko/wiki/Deprecation:-var,-assign,-invoke-tags', fix() { var _a; const { file } = tag.hub; const statements = []; let condition; for (const attr of tag.get("attributes")) { const { node } = attr; if (import_compiler.types.isMarkoSpreadAttribute(node)) { (0, import_babel_utils.diagnosticError)(attr, { label: "Spread attributes are not supported in <assign> tags.", fix() { attr.remove(); } }); continue; } const { name, value } = node; if (name === "if" && ((_a = node.arguments) == null ? void 0 : _a.length)) { condition = node.arguments.length === 1 ? node.arguments[0] : import_compiler.types.sequenceExpression(node.arguments); continue; } const nodeStart = (0, import_babel_utils.getStart)(file, node); const nodeEnd = (0, import_babel_utils.getEnd)(file, node); statements.push( import_compiler.types.expressionStatement( import_compiler.types.isBooleanLiteral(value) && value.value === true && /^[+-]{2,}|[+-]{2,}$/.test(name) ? nodeStart != null && nodeEnd != null ? (0, import_babel_utils.parseExpression)(file, name, nodeStart, nodeEnd) : (0, import_babel_utils.parseExpression)(file, name) : import_compiler.types.assignmentExpression("=", import_compiler.types.identifier(name), value) ) ); } if (condition) { tag.replaceWith( import_compiler.types.markoScriptlet([ import_compiler.types.ifStatement(condition, import_compiler.types.blockStatement(statements)) ]) ); } else { tag.replaceWithMultiple( statements.map((it) => import_compiler.types.markoScriptlet([it])) ); } } }); } };