Fixes #339 - Tag transformers are not being applied to tags with a dynamic tag name

This commit is contained in:
Patrick Steele-Idem 2016-07-18 15:48:38 -06:00
parent 29de5d5a09
commit b85b59d594
6 changed files with 21 additions and 4 deletions

View File

@ -290,7 +290,7 @@ class TaglibLookup {
/*
* Based on the type of node we have to choose how to transform it
*/
if (node.tagName) {
if (node.tagName || node.tagNameExpression) {
this.forEachTagTransformer(node, callback, thisObj);
} else if (node instanceof Text) {
this.forEachTextTransformer(callback, thisObj);
@ -327,10 +327,12 @@ class TaglibLookup {
*/
if (this.merged.tags) {
if (this.merged.tags[tagName]) {
this.merged.tags[tagName].forEachTransformer(addTransformer);
if (tagName) {
if (this.merged.tags[tagName]) {
this.merged.tags[tagName].forEachTransformer(addTransformer);
}
}
if (this.merged.tags['*']) {
this.merged.tags['*'].forEachTransformer(addTransformer);
}

View File

@ -0,0 +1 @@
<p bar="hello">Dynamic tag name</p>

View File

@ -0,0 +1,6 @@
{
"<*>": {
"@foo": "string",
"transformer": "./transformer.js"
}
}

View File

@ -0,0 +1 @@
<${data.tagName} foo="abc">Dynamic tag name</>

View File

@ -0,0 +1,3 @@
exports.templateData = {
tagName: 'p'
};

View File

@ -0,0 +1,4 @@
module.exports = function transform(el, context) {
el.removeAttribute('foo');
el.setAttributeValue('bar', context.builder.literal('hello'));
};