UNPKG

marko-widgets

Version:

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

104 lines (103 loc) 3.82 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 w_preserve_directives_exports = {}; __export(w_preserve_directives_exports, { default: () => w_preserve_directives_default }); module.exports = __toCommonJS(w_preserve_directives_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_preserve_directives_default = { MarkoAttribute(attr) { switch (attr.node.name) { case "w-preserve": renameAttribute(attr, "no-update"); break; case "w-preserve-if": renameAttribute(attr, "no-update-if"); break; case "w-preserve-body": renameAttribute(attr, "no-update-body"); break; case "w-preserve-body-if": renameAttribute(attr, "no-update-body-if"); break; case "w-preserve-attrs": { const value = attr.node.value; if (value.type !== "StringLiteral") { (0, import_babel_utils.diagnosticError)(attr, { label: `The "w-preserve-attrs" attribute must have a string literal value.` }); attr.remove(); return; } (0, import_babel_utils.diagnosticDeprecate)(attr, { label: `The "w-preserve-attrs" attribute is deprecated. Please use ":no-update" modifier instead. See: https://github.com/marko-js/marko/wiki/Deprecation:-w\u2010*-Attributes`, fix() { const tag = attr.parentPath; const seen = /* @__PURE__ */ new Set(); const preserveAttrs = value.value.split(/\s*,\s*/); attr.remove(); for (const name of preserveAttrs) { if (seen.has(name)) continue; seen.add(name); const existing = (0, import_compat_utils.getAttribute)(tag, name); if (existing) { existing.replaceWith( import_compiler.types.markoAttribute( name, existing.node.value, "no-update", existing.node.arguments, existing.node.default, existing.node.bound ) ); } else { tag.node.attributes.unshift( import_compiler.types.markoAttribute(name, import_compiler.types.nullLiteral(), "no-update") ); } } } }); break; } } } }; function renameAttribute(attr, name) { const { node } = attr; (0, import_babel_utils.diagnosticDeprecate)(attr, { label: `The "${node.name}" attribute is deprecated. Please use "${name}" attribute instead. See: https://github.com/marko-js/marko/wiki/Deprecation:-w\u2010*-Attributes`, fix() { attr.replaceWith( import_compiler.types.markoAttribute( name, node.value, node.modifier, node.arguments, node.default, node.bound ) ); } }); }