Skip to content

Commit

Permalink
Merge pull request #1377 from marko-js/w-id-repeated
Browse files Browse the repository at this point in the history
no id:scoped for repeated w-id
  • Loading branch information
mlrawlings committed Jul 3, 2019
2 parents 535daf9 + a80ad07 commit 676a6b7
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 3 deletions.
4 changes: 3 additions & 1 deletion src/core-tags/migrate/all-tags/w-id.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ module.exports = function migrate(el, context) {
el.setAttributeValue("key", attr.value);
const isHTML = el.tagDef && el.tagDef.html;
const isDynamic = Boolean(el.rawTagNameExpression);
if (!el.hasAttribute("id") && (isHTML || isDynamic))
const isRepeated =
attr.value.type === "Literal" && /\[\]$/.test(attr.value.value);
if (!el.hasAttribute("id") && !isRepeated && (isHTML || isDynamic))
el.setAttributeValue("id:scoped", attr.value);
el.removeAttribute(attr.name);
};
4 changes: 3 additions & 1 deletion test/migrate/fixtures/w-id/snapshot-expected.marko
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,6 @@
<div key="a" id:scoped="a"/>
<div key="b" id:scoped="b"/>
<test key="c"/>
<${tag} key="d" id:scoped="d"/>
<${tag} key="d" id:scoped="d"/>
<div key="e[]"/>
<div key="e[]"/>
4 changes: 3 additions & 1 deletion test/migrate/fixtures/w-id/template.marko
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<div w-id="a"/>
<div w-id="b"/>
<test w-id="c"/>
<${tag} w-id="d"/>
<${tag} w-id="d"/>
<div w-id="e[]"/>
<div w-id="e[]"/>

0 comments on commit 676a6b7

Please sign in to comment.