From edd7d8e9b0fe9d7fcdc31c32596b17fd13d47663 Mon Sep 17 00:00:00 2001 From: Michael Rawlings Date: Thu, 3 Jan 2019 09:55:07 -0800 Subject: [PATCH] w-id migration key only for components (#1217) * only add id:scoped for html/dynamic tags --- src/taglibs/migrate/all-tags/w-id.js | 5 ++++- test/compiler/fixtures-html/invoke/expected.js | 3 +-- .../widget-getWidget/components/app-foo/marko-tag.json | 3 +++ test/migrate/fixtures/w-id/components/test.marko | 0 test/migrate/fixtures/w-id/snapshot-expected.marko | 2 ++ test/migrate/fixtures/w-id/template.marko | 4 +++- 6 files changed, 13 insertions(+), 4 deletions(-) create mode 100644 test/components-browser/fixtures-deprecated/widget-getWidget/components/app-foo/marko-tag.json create mode 100644 test/migrate/fixtures/w-id/components/test.marko diff --git a/src/taglibs/migrate/all-tags/w-id.js b/src/taglibs/migrate/all-tags/w-id.js index 4bb0570e3..49cd35e27 100644 --- a/src/taglibs/migrate/all-tags/w-id.js +++ b/src/taglibs/migrate/all-tags/w-id.js @@ -9,6 +9,9 @@ module.exports = function migrate(el, context) { ); el.setAttributeValue("key", attr.value); - if (!el.hasAttribute("id")) el.setAttributeValue("id:scoped", attr.value); + const isHTML = el.tagDef && el.tagDef.html; + const isDynamic = Boolean(el.rawTagNameExpression); + if (!el.hasAttribute("id") && (isHTML || isDynamic)) + el.setAttributeValue("id:scoped", attr.value); el.removeAttribute(attr.name); }; diff --git a/test/compiler/fixtures-html/invoke/expected.js b/test/compiler/fixtures-html/invoke/expected.js index 0af45f1cb..1eb706589 100644 --- a/test/compiler/fixtures-html/invoke/expected.js +++ b/test/compiler/fixtures-html/invoke/expected.js @@ -12,8 +12,7 @@ function render(input, out, __component, component, state) { var data = input; marko_dynamicTag(input, { - x: 1, - id: __component.elId("hi") + x: 1 }, out, __component, "hi"); } diff --git a/test/components-browser/fixtures-deprecated/widget-getWidget/components/app-foo/marko-tag.json b/test/components-browser/fixtures-deprecated/widget-getWidget/components/app-foo/marko-tag.json new file mode 100644 index 000000000..7b40a332a --- /dev/null +++ b/test/components-browser/fixtures-deprecated/widget-getWidget/components/app-foo/marko-tag.json @@ -0,0 +1,3 @@ +{ + "@foo": "string" +} diff --git a/test/migrate/fixtures/w-id/components/test.marko b/test/migrate/fixtures/w-id/components/test.marko new file mode 100644 index 000000000..e69de29bb diff --git a/test/migrate/fixtures/w-id/snapshot-expected.marko b/test/migrate/fixtures/w-id/snapshot-expected.marko index 0af1825e3..7c5e3c9a9 100644 --- a/test/migrate/fixtures/w-id/snapshot-expected.marko +++ b/test/migrate/fixtures/w-id/snapshot-expected.marko @@ -2,3 +2,5 @@
+ +<${tag} key="d" id:scoped="d"/> \ No newline at end of file diff --git a/test/migrate/fixtures/w-id/template.marko b/test/migrate/fixtures/w-id/template.marko index a528c03f5..97553b513 100644 --- a/test/migrate/fixtures/w-id/template.marko +++ b/test/migrate/fixtures/w-id/template.marko @@ -1,2 +1,4 @@
-
\ No newline at end of file +
+ +<${tag} w-id="d"/> \ No newline at end of file