UNPKG

marko-widgets

Version:

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

47 lines (46 loc) 1.53 kB
// packages/marko-widgets/src/components/layout-use/migrate.ts import { types as t } from "@marko/compiler"; import { diagnosticDeprecate, diagnosticError } from "@marko/babel-utils"; import { exprToAttrs, getTagNameForTemplatePath } from "@marko/compat-utils"; var migrate_default = { exit(tag) { const { node } = tag; const args = node.arguments; if (!args || args.length < 1 || args.length > 2 || !isOnlyExpressions(args)) { diagnosticError(tag, { label: "Invalid <layout-use> tag. Expected: <layout-use(template[, data]) ...>" }); tag.remove(); return; } const [target] = args; const tagNameExpression = target.type === "StringLiteral" ? getTagNameForTemplatePath(tag, target.value) : target; const attributes = args.length === 2 ? [...exprToAttrs(args[1]), ...node.attributes] : node.attributes; diagnosticDeprecate(tag, { label: "The <layout-use> tag is deprecated. Please use a combination of the <${dynamic}> tag and imports instead. See: https://github.com/marko-js/marko/wiki/Deprecation:-layout-tag", fix() { tag.replaceWith( t.markoTag( tagNameExpression, attributes, node.body, void 0, void 0, node.attributeTags ) ); } }); } }; function isOnlyExpressions(args) { for (const arg of args) { if (arg.type === "SpreadElement") { return false; } } return true; } export { migrate_default as default };