UNPKG

marko-widgets

Version:

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

102 lines (101 loc) 3.78 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) { if (!tag.node.attributes.length) { (0, import_babel_utils.diagnosticError)(tag, { label: "The <var> tag requires a value.", fix() { tag.remove(); } }); return; } (0, import_babel_utils.diagnosticDeprecate)(tag, { label: 'The "<var>" 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 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 <var> tags.", fix() { attr.remove(); } }); continue; } if (node.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; } statements.push( import_compiler.types.variableDeclaration("var", [ import_compiler.types.variableDeclarator( import_compiler.types.identifier(node.name), (0, import_compat_utils.isSourceBooleanAttribute)(node) ? null : node.value ) ]) ); } if (condition) { if (tag.node.body.body.length) { tag.replaceWith( import_compiler.types.markoTag( import_compiler.types.stringLiteral("if"), [], import_compiler.types.markoTagBody( statements.map( (it) => import_compiler.types.markoScriptlet([it]) ).concat(tag.node.body.body) ), [condition] ) ); } else { tag.replaceWith( import_compiler.types.markoScriptlet([ import_compiler.types.ifStatement(condition, import_compiler.types.blockStatement(statements)) ]) ); } } else { let body = statements.map( (it) => import_compiler.types.markoScriptlet([it]) ); if (tag.node.body.body.length) { body = body.concat(tag.node.body.body); } tag.replaceWithMultiple(body); } } }); } };