marko-widgets
Version:
<h1 align="center"> <!-- Logo --> <br/> marko-widgets@8 <br/>
80 lines (79 loc) • 3.27 kB
JavaScript
;
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 w_body_directive_exports = {};
__export(w_body_directive_exports, {
default: () => w_body_directive_default
});
module.exports = __toCommonJS(w_body_directive_exports);
var import_compiler = require("@marko/compiler");
var import_babel_utils = require("@marko/babel-utils");
var import_compat_utils = require("@marko/compat-utils");
var w_body_directive_default = {
MarkoAttribute(attr) {
const { node } = attr;
if (node.name !== "w-body") return;
(0, import_babel_utils.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 ((0, import_compat_utils.isSourceBooleanAttribute)(node)) {
bodyValue = import_compiler.types.memberExpression(
import_compiler.types.identifier("input"),
import_compiler.types.identifier("renderBody")
);
needsGuard = true;
} else if (!(bodyValue.type === "MemberExpression" && bodyValue.property.type === "Identifier" && bodyValue.property.name === "renderBody")) {
needsGuard = true;
}
if (needsGuard) {
tag.set(
"body",
import_compiler.types.markoTagBody([
import_compiler.types.markoTag(
import_compiler.types.stringLiteral("if"),
[],
import_compiler.types.markoTagBody([import_compiler.types.markoPlaceholder(bodyValue)]),
[
import_compiler.types.binaryExpression(
"===",
import_compiler.types.unaryExpression("typeof", bodyValue),
import_compiler.types.stringLiteral("string")
)
]
),
import_compiler.types.markoTag(
import_compiler.types.stringLiteral("else"),
[],
import_compiler.types.markoTagBody([import_compiler.types.markoTag(bodyValue, [], tag.node.body)])
)
])
);
} else {
tag.set(
"body",
import_compiler.types.markoTagBody([import_compiler.types.markoTag(bodyValue, [], tag.node.body)])
);
}
}
});
}
};