marko-widgets
Version:
<h1 align="center"> <!-- Logo --> <br/> marko-widgets@8 <br/>
35 lines (33 loc) • 1.15 kB
JavaScript
// packages/marko-widgets/src/migrate/w-id-directive.ts
import { types as t } from "@marko/compiler";
import {
diagnosticDeprecate,
isDynamicTag,
isNativeTag
} from "@marko/babel-utils";
import { hasAttribute } from "@marko/compat-utils";
var w_id_directive_default = {
MarkoAttribute(attr) {
var _a;
const { node } = attr;
if (node.name !== "w-id") return;
(_a = attr.hub.file.metadata.marko).widgetBind || (_a.widgetBind = true);
diagnosticDeprecate(attr, {
label: `The "w-id" attribute is deprecated. Please use "key" attribute instead. See: https://github.com/marko-js/marko/wiki/Deprecation:-w\u2010*-Attributes`,
fix() {
const tag = attr.parentPath;
const value = attr.node.value;
if (!hasAttribute(tag, "id") && !(value.type === "StringLiteral" && value.value.endsWith("[]")) && (isNativeTag(tag) || isDynamicTag(tag))) {
tag.unshiftContainer(
"attributes",
t.markoAttribute("id", value, "scoped")
);
}
attr.replaceWith(t.markoAttribute("key", value));
}
});
}
};
export {
w_id_directive_default
};