mirror of
https://github.com/marko-js/marko.git
synced 2025-12-08 19:26:05 +00:00
Fixes #654 - Bug: components implementing a key attribute break in Marko v4
This commit is contained in:
parent
8019774911
commit
56382307b7
@ -134,6 +134,11 @@ class Tag{
|
||||
|
||||
return attribute;
|
||||
}
|
||||
|
||||
hasAttribute(attrName) {
|
||||
return this.attributes.hasOwnProperty(attrName);
|
||||
}
|
||||
|
||||
addNestedVariable(nestedVariable) {
|
||||
if (!this.nestedVariables) {
|
||||
this.nestedVariables = {
|
||||
@ -232,4 +237,4 @@ class Tag{
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = Tag;
|
||||
module.exports = Tag;
|
||||
|
||||
@ -1,7 +1,6 @@
|
||||
'use strict';
|
||||
|
||||
module.exports = function assignComponentId(isRepeated) {
|
||||
|
||||
// First check if we have already assigned an ID to thie element
|
||||
var componentIdInfo = this.componentIdInfo;
|
||||
|
||||
|
||||
@ -1,6 +1,19 @@
|
||||
'use strict';
|
||||
var getTransformHelper = require('./util/getTransformHelper');
|
||||
|
||||
|
||||
function tagDefinitionHasOverridingKeyAttribute(el, context) {
|
||||
if (!el.hasAttribute('key')) {
|
||||
return false;
|
||||
}
|
||||
|
||||
var tagDef = el.tagDef;
|
||||
if (tagDef && tagDef.hasAttribute('key')) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
module.exports = function transform(el, context) {
|
||||
var transformHelper = getTransformHelper(el, context);
|
||||
|
||||
@ -61,7 +74,9 @@ module.exports = function transform(el, context) {
|
||||
}
|
||||
|
||||
if (el.hasAttribute('key') || el.hasAttribute('ref') || el.hasAttribute('w-id')) {
|
||||
transformHelper.assignComponentId();
|
||||
if (!tagDefinitionHasOverridingKeyAttribute(el, context)) {
|
||||
transformHelper.assignComponentId();
|
||||
}
|
||||
}
|
||||
|
||||
if (el.hasAttribute('for-key') || el.hasAttribute('for-ref') || el.hasAttribute('w-for')) {
|
||||
|
||||
@ -0,0 +1 @@
|
||||
<div>Key: ${input.key}</div>
|
||||
@ -0,0 +1,3 @@
|
||||
{
|
||||
"@key": "string"
|
||||
}
|
||||
1
test/autotests/render/custom-tag-key-attr/expected.html
Normal file
1
test/autotests/render/custom-tag-key-attr/expected.html
Normal file
@ -0,0 +1 @@
|
||||
<div>Key: 123</div>
|
||||
1
test/autotests/render/custom-tag-key-attr/template.marko
Normal file
1
test/autotests/render/custom-tag-key-attr/template.marko
Normal file
@ -0,0 +1 @@
|
||||
<foo key="123"/>
|
||||
Loading…
x
Reference in New Issue
Block a user