UNPKG

marko-widgets

Version:

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

64 lines (63 loc) 1.74 kB
// packages/marko-widgets/src/components/layout-placeholder/migrate.ts import { types as t } from "@marko/compiler"; import { diagnosticDeprecate, diagnosticError, getStart, withLoc } from "@marko/babel-utils"; import { getAttributeValue } from "@marko/compat-utils"; var migrate_default = { exit(tag) { const { node, hub: { file } } = tag; const name = getAttributeValue(tag, "name"); if (!name || !name.isStringLiteral()) { diagnosticError(tag, { label: "The <layout-placeholder> tag requires a 'name' attribute that is a string literal." }); tag.remove(); return; } if (node.attributes.length > 1) { diagnosticError(tag, { label: "The <layout-placeholder> tag only supports the 'name' attribute." }); tag.remove(); return; } const memberProperty = t.identifier(toCamelCase(name.node.value)); const nameStart = getStart(file, node.name); if (nameStart != null) { withLoc( tag.hub.file, memberProperty, nameStart + 1, nameStart + name.node.value.length ); } diagnosticDeprecate(tag, { label: "The <layout-placeholder> tag is deprecated. Please use the <${dynamic}> tag instead. See: https://github.com/marko-js/marko/wiki/Deprecation:-layout-tag", fix() { tag.replaceWith( t.markoTag( t.memberExpression(t.identifier("input"), memberProperty), [], node.body ) ); } }); } }; function toCamelCase(str) { return str.replace(/-([a-z])/g, matchToUpperCase); } function matchToUpperCase(_, str) { return str.toUpperCase(); } export { migrate_default as default };