UNPKG

marko-widgets

Version:

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

62 lines (60 loc) 2.01 kB
// packages/marko-widgets/src/migrate/w-body-directive.ts import { types as t } from "@marko/compiler"; import { diagnosticDeprecate } from "@marko/babel-utils"; import { isSourceBooleanAttribute } from "@marko/compat-utils"; var w_body_directive_default = { MarkoAttribute(attr) { const { node } = attr; if (node.name !== "w-body") return; diagnosticDeprecate(attr, { label: 'The "w-body" attribute is deprecated. Please use the "<${dynamicTag}/>" tag instead. See: https://github.com/marko-js/marko/wiki/Deprecation:-Widget-body-(w\u2010body)', fix() { const tag = attr.parentPath; let bodyValue = node.value; let needsGuard = false; attr.remove(); if (isSourceBooleanAttribute(node)) { bodyValue = t.memberExpression( t.identifier("input"), t.identifier("renderBody") ); needsGuard = true; } else if (!(bodyValue.type === "MemberExpression" && bodyValue.property.type === "Identifier" && bodyValue.property.name === "renderBody")) { needsGuard = true; } if (needsGuard) { tag.set( "body", t.markoTagBody([ t.markoTag( t.stringLiteral("if"), [], t.markoTagBody([t.markoPlaceholder(bodyValue)]), [ t.binaryExpression( "===", t.unaryExpression("typeof", bodyValue), t.stringLiteral("string") ) ] ), t.markoTag( t.stringLiteral("else"), [], t.markoTagBody([t.markoTag(bodyValue, [], tag.node.body)]) ) ]) ); } else { tag.set( "body", t.markoTagBody([t.markoTag(bodyValue, [], tag.node.body)]) ); } } }); } }; export { w_body_directive_default };