-
Notifications
You must be signed in to change notification settings - Fork 393
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: relax static id validation in iterations (#2830)
- Loading branch information
Showing
5 changed files
with
152 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
...wc/template-compiler/src/__tests__/fixtures/regression/static-id-in-iteration/actual.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<template> | ||
<!-- Inline for each --> | ||
<div for:each={items} for:item="item" key={item.key}> | ||
<span id="a"></span> | ||
</div> | ||
|
||
<!-- Template for each --> | ||
<template for:each={items} for:item="item"> | ||
<span key={item.key} id="b"></span> | ||
</template> | ||
|
||
<!-- Inline iterator --> | ||
<div iterator:item={items} key={item.key}> | ||
<span id="c"></span> | ||
</div> | ||
|
||
<!-- Template iterator --> | ||
<template iterator:item={items}> | ||
<span key={item.key} id="d"></span> | ||
</template> | ||
</template> |
81 changes: 81 additions & 0 deletions
81
...wc/template-compiler/src/__tests__/fixtures/regression/static-id-in-iteration/expected.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
import { registerTemplate } from "lwc"; | ||
function tmpl($api, $cmp, $slotset, $ctx) { | ||
const { | ||
k: api_key, | ||
gid: api_scoped_id, | ||
h: api_element, | ||
i: api_iterator, | ||
f: api_flatten, | ||
} = $api; | ||
return api_flatten([ | ||
api_iterator($cmp.items, function (item) { | ||
return api_element( | ||
"div", | ||
{ | ||
key: api_key(0, item.key), | ||
}, | ||
[ | ||
api_element("span", { | ||
attrs: { | ||
id: api_scoped_id("a"), | ||
}, | ||
key: 1, | ||
}), | ||
] | ||
); | ||
}), | ||
api_iterator($cmp.items, function (item) { | ||
return api_element("span", { | ||
attrs: { | ||
id: api_scoped_id("b"), | ||
}, | ||
key: api_key(2, item.key), | ||
}); | ||
}), | ||
api_iterator( | ||
$cmp.items, | ||
function (itemValue, itemIndex, itemFirst, itemLast) { | ||
const item = { | ||
value: itemValue, | ||
index: itemIndex, | ||
first: itemFirst, | ||
last: itemLast, | ||
}; | ||
return api_element( | ||
"div", | ||
{ | ||
key: api_key(3, item.key), | ||
}, | ||
[ | ||
api_element("span", { | ||
attrs: { | ||
id: api_scoped_id("c"), | ||
}, | ||
key: 4, | ||
}), | ||
] | ||
); | ||
} | ||
), | ||
api_iterator( | ||
$cmp.items, | ||
function (itemValue, itemIndex, itemFirst, itemLast) { | ||
const item = { | ||
value: itemValue, | ||
index: itemIndex, | ||
first: itemFirst, | ||
last: itemLast, | ||
}; | ||
return api_element("span", { | ||
attrs: { | ||
id: api_scoped_id("d"), | ||
}, | ||
key: api_key(5, item.key), | ||
}); | ||
} | ||
), | ||
]); | ||
/*LWC compiler vX.X.X*/ | ||
} | ||
export default registerTemplate(tmpl); | ||
tmpl.stylesheets = []; |
48 changes: 48 additions & 0 deletions
48
.../template-compiler/src/__tests__/fixtures/regression/static-id-in-iteration/metadata.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
{ | ||
"warnings": [ | ||
{ | ||
"code": 1041, | ||
"message": "LWC1041: Static id values are not allowed in iterators. Id values must be unique within a template and must therefore be computed with an expression.", | ||
"level": 2, | ||
"location": { | ||
"line": 4, | ||
"column": 15, | ||
"start": 112, | ||
"length": 6 | ||
} | ||
}, | ||
{ | ||
"code": 1041, | ||
"message": "LWC1041: Static id values are not allowed in iterators. Id values must be unique within a template and must therefore be computed with an expression.", | ||
"level": 2, | ||
"location": { | ||
"line": 9, | ||
"column": 30, | ||
"start": 247, | ||
"length": 6 | ||
} | ||
}, | ||
{ | ||
"code": 1041, | ||
"message": "LWC1041: Static id values are not allowed in iterators. Id values must be unique within a template and must therefore be computed with an expression.", | ||
"level": 2, | ||
"location": { | ||
"line": 14, | ||
"column": 15, | ||
"start": 369, | ||
"length": 6 | ||
} | ||
}, | ||
{ | ||
"code": 1041, | ||
"message": "LWC1041: Static id values are not allowed in iterators. Id values must be unique within a template and must therefore be computed with an expression.", | ||
"level": 2, | ||
"location": { | ||
"line": 19, | ||
"column": 30, | ||
"start": 493, | ||
"length": 6 | ||
} | ||
} | ||
] | ||
} |