mirror of
https://github.com/marko-js/marko.git
synced 2025-12-08 19:26:05 +00:00
Fix widget el id migration (#1198)
This commit is contained in:
parent
00ae73e7ad
commit
0cf4af2885
@ -1,18 +1,23 @@
|
||||
module.exports = function migrate(el, context) {
|
||||
el.forEachAttribute(attr => {
|
||||
let name = attr.name;
|
||||
const value = attr.value ? attr.value.toString() : undefined;
|
||||
if (!value || !value.startsWith("widget.elId")) {
|
||||
const value = attr.value;
|
||||
|
||||
if (
|
||||
!value ||
|
||||
value.type !== "FunctionCall" ||
|
||||
value.callee.type !== "MemberExpression" ||
|
||||
(value.callee.object.name !== "widget" &&
|
||||
value.callee.object.name !== "component") ||
|
||||
value.callee.property.name !== "elId"
|
||||
) {
|
||||
return;
|
||||
}
|
||||
|
||||
const argument = attr.argument;
|
||||
context.deprecate(
|
||||
`The "*=widget.elId("someId")" is deprecated. Please use "*:scoped="someId"" modifier instead. See: https://github.com/marko-js/marko/wiki/Deprecation:-w-*-Atrributes`
|
||||
);
|
||||
|
||||
name = `${attr.name}:scoped`;
|
||||
el.setAttributeValue(name, argument);
|
||||
el.removeAttribute(attr.name);
|
||||
attr.name += ":scoped";
|
||||
attr.value = value.args[0];
|
||||
});
|
||||
};
|
||||
|
||||
@ -0,0 +1,4 @@
|
||||
<!-- test/migrate/fixtures/widget-el-id-scoped/template.marko -->
|
||||
|
||||
<label for:scoped="thing"/>
|
||||
<input key="thing" id:scoped="thing"/>
|
||||
2
test/migrate/fixtures/widget-el-id-scoped/template.marko
Normal file
2
test/migrate/fixtures/widget-el-id-scoped/template.marko
Normal file
@ -0,0 +1,2 @@
|
||||
<label for=widget.elId('thing')/>
|
||||
<input w-id="thing"/>
|
||||
Loading…
x
Reference in New Issue
Block a user