diff --git a/src/taglibs/migrate/all-tags/widget-elId.js b/src/taglibs/migrate/all-tags/widget-elId.js index 3b1ebc58f..70367ac26 100644 --- a/src/taglibs/migrate/all-tags/widget-elId.js +++ b/src/taglibs/migrate/all-tags/widget-elId.js @@ -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]; }); }; diff --git a/test/migrate/fixtures/widget-el-id-scoped/snapshot-expected.marko b/test/migrate/fixtures/widget-el-id-scoped/snapshot-expected.marko new file mode 100644 index 000000000..b06aba3a9 --- /dev/null +++ b/test/migrate/fixtures/widget-el-id-scoped/snapshot-expected.marko @@ -0,0 +1,4 @@ + + +