Skip to content

Commit

Permalink
Additional fixes for #386 - Allow regular expression for an HTML attr…
Browse files Browse the repository at this point in the history
…ibute value
  • Loading branch information
patrick-steele-idem committed Nov 10, 2016
1 parent da52209 commit a64044a
Showing 1 changed file with 15 additions and 6 deletions.
21 changes: 15 additions & 6 deletions compiler/ast/HtmlAttribute/vdom/generateCode.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,23 @@ module.exports = function generateCode(node, codegen, vdomUtil) {
// node.name = codegen.generateCode(node.name);
node.value = codegen.generateCode(node.value);
node.isStatic = vdomUtil.isStaticValue(node.value);

var name = node.name;

if (node.value && node.value.type !== 'Literal') {
if (name === 'class') {
node.value = builder.functionCall(context.helper('classAttr'), [node.value]);
} else if (name === 'style') {
node.value = builder.functionCall(context.helper('styleAttr'), [node.value]);
var attrValue = node.value;

if (attrValue) {
if (attrValue.type === 'Literal') {
var literalValue = attrValue.value;

if (literalValue instanceof RegExp) {
node.value = builder.literal(literalValue.source);
}
} else {
if (name === 'class') {
node.value = builder.functionCall(context.helper('classAttr'), [attrValue]);
} else if (name === 'style') {
node.value = builder.functionCall(context.helper('styleAttr'), [attrValue]);
}
}
}

Expand Down

0 comments on commit a64044a

Please sign in to comment.