Fixes #198 - Marko v3: Replace <div attrs(myAttrs)> with <div ${myAttrs}>

This commit is contained in:
Patrick Steele-Idem 2016-02-01 16:31:12 -07:00
parent f47bfe9da3
commit 9dbb77870f
5 changed files with 21 additions and 11 deletions

View File

@ -213,6 +213,10 @@ class CompileContext {
// Validate the attributes
attributes.forEach((attr) => {
let attrName = attr.name;
if (!attrName) {
// Attribute will be name for placeholder attributes. For example: <div ${data.myAttrs}>
return;
}
let attrDef = taglibLookup.getAttribute(tagName, attrName);
if (!attrDef) {
if (tagDef) {

View File

@ -149,6 +149,10 @@ class HtmlAttribute extends Node {
let value = this.value;
let argument = this.argument;
if (!name) {
return;
}
if (this.isLiteralValue()) {
var literalValue = value.value;
if (typeof literalValue === 'boolean' || literalValue === '') {

View File

@ -31,7 +31,10 @@ class HtmlAttributeCollection {
}
}
this.lookup[name.toLowerCase()] = newAttr;
if (name) {
this.lookup[name.toLowerCase()] = newAttr;
}
this.all.push(newAttr);
}

View File

@ -69,15 +69,6 @@ var coreAttrHandlers = [
el.setBodyOnlyIf(condition);
}
],
[
'attrs', function(attr, node) {
if (!node.addDynamicAttributes) {
node.addError('Node does not support the "attrs" attribute');
} else {
node.addDynamicAttributes(attr.value);
}
}
],
[
'marko-preserve-whitespace', function(attr, node) {
node.setPreserveWhitespace(true);
@ -116,6 +107,14 @@ module.exports = function transform(el, context) {
el.forEachAttribute((attr) => {
let attrName = attr.name;
if (!attrName) {
if (!node.addDynamicAttributes) {
node.addError('Node does not support the "attrs" attribute');
} else {
node.addDynamicAttributes(attr.value);
}
return;
}
var attrTransformerFunc = attributeTransformers[attrName];
if (attrTransformerFunc) {
if (!attributeTransfomer) {

View File

@ -1,3 +1,3 @@
<div attrs=data.myAttrs data-encoding='"hello"'>
<div ${data.myAttrs} data-encoding='"hello"'>
Hello World!
</div>