UNPKG

marko-widgets

Version:

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

79 lines (78 loc) 3.02 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) { const { node, hub: { file } } = tag; const into = (0, import_compat_utils.getAttributeValue)(tag, "into"); if (!into || !into.isStringLiteral()) { (0, import_babel_utils.diagnosticError)(tag, { label: "The <layout-put> tag requires an 'into' attribute that is a string literal." }); tag.remove(); return; } const value = (0, import_compat_utils.getAttributeValue)(tag, "value"); if (node.attributes.length > (value ? 2 : 1)) { (0, import_babel_utils.diagnosticError)(tag, { label: "The <layout-put> tag only supports the 'into' and 'value' attributes." }); tag.remove(); return; } let children = node.body.body; if (value) { if (children.length) { (0, import_babel_utils.diagnosticError)(tag, { label: "The <layout-put> tag does not support children when using the 'value' attribute." }); tag.remove(); return; } children = [import_compiler.types.markoPlaceholder(value.node)]; } const newName = import_compiler.types.stringLiteral(`@${toCamelCase(into.node.value)}`); const nameStart = (0, import_babel_utils.getStart)(file, node.name); if (nameStart != null) { (0, import_babel_utils.withLoc)(file, newName, nameStart, nameStart + into.node.value.length); } (0, import_babel_utils.diagnosticDeprecate)(tag, { label: 'The "<layout-put>" tag is deprecated and replaced by `<@attribute>` tags tag. See: https://github.com/marko-js/marko/wiki/Deprecation:-layout-tag', fix() { tag.replaceWith(import_compiler.types.markoTag(newName, [], import_compiler.types.markoTagBody(children))); } }); } }; function toCamelCase(str) { return str.replace(/-([a-z])/g, matchToUpperCase); } function matchToUpperCase(_, str) { return str.toUpperCase(); }