Fix widget el id migration (#1198)

This commit is contained in:
Dylan Piercey 2018-12-14 17:12:08 -08:00 committed by GitHub
parent 00ae73e7ad
commit 0cf4af2885
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 18 additions and 7 deletions

View File

@ -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];
});
};

View File

@ -0,0 +1,4 @@
<!-- test/migrate/fixtures/widget-el-id-scoped/template.marko -->
<label for:scoped="thing"/>
<input key="thing" id:scoped="thing"/>

View File

@ -0,0 +1,2 @@
<label for=widget.elId('thing')/>
<input w-id="thing"/>