mirror of
https://github.com/marko-js/marko.git
synced 2025-12-08 19:26:05 +00:00
Fixes #226 - Allow placeholders in tag name
This commit is contained in:
parent
7d536a7c3c
commit
0c1babd588
@ -225,8 +225,6 @@ class CompileContext {
|
||||
throw new Error('Invalid attributes');
|
||||
}
|
||||
|
||||
ok(typeof tagName === 'string', 'Invalid "tagName"');
|
||||
|
||||
var node;
|
||||
var elNode = builder.htmlElement(elDef);
|
||||
var taglibLookup = this.taglibLookup;
|
||||
|
||||
@ -93,6 +93,7 @@ class Parser {
|
||||
var builder = context.builder;
|
||||
|
||||
var tagName = el.tagName;
|
||||
var tagNameExpression = el.tagNameExpression;
|
||||
var attributes = el.attributes;
|
||||
var argument = el.argument; // e.g. For <for(color in colors)>, argument will be "color in colors"
|
||||
|
||||
@ -100,7 +101,9 @@ class Parser {
|
||||
argument = argument.value;
|
||||
}
|
||||
|
||||
if (tagName === 'compiler-options') {
|
||||
if (tagNameExpression) {
|
||||
tagName = builder.parseExpression(tagNameExpression);
|
||||
} else if (tagName === 'compiler-options') {
|
||||
attributes.forEach(function (attr) {
|
||||
let attrName = attr.name;
|
||||
let handler = COMPILER_ATTRIBUTE_HANDLERS[attrName];
|
||||
|
||||
@ -1,14 +0,0 @@
|
||||
'use strict';
|
||||
|
||||
module.exports = function(elNode, codegen) {
|
||||
var tagName = elNode.argument;
|
||||
if (!tagName) {
|
||||
codegen.addError('Invalid <html-element> tag. Expected: <html-element(<tag-name-expression>) ... >');
|
||||
return;
|
||||
}
|
||||
|
||||
tagName = codegen.builder.parseExpression(tagName, { escapeXml: false });
|
||||
|
||||
elNode.setTagName(tagName);
|
||||
return elNode;
|
||||
};
|
||||
@ -2,8 +2,5 @@
|
||||
"taglib-id": "marko-html",
|
||||
"<html-comment>": {
|
||||
"renderer": "./html-comment-tag.js"
|
||||
},
|
||||
"<html-element>": {
|
||||
"code-generator": "./html-element-tag.js"
|
||||
}
|
||||
}
|
||||
3
test/fixtures/render/autotest/dynamic-tag-name/template.marko
vendored
Normal file
3
test/fixtures/render/autotest/dynamic-tag-name/template.marko
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
<hello-${data.myTagName} class="my-class" foo="bar">
|
||||
My nested content
|
||||
</>
|
||||
@ -1,3 +0,0 @@
|
||||
<html-element("hello-${data.myTagName}") class="my-class" foo="bar">
|
||||
My nested content
|
||||
</html-element>
|
||||
Loading…
x
Reference in New Issue
Block a user