Skip to content

Commit

Permalink
Fixes #386 - Allow regular expression for an HTML attribute value
Browse files Browse the repository at this point in the history
  • Loading branch information
patrick-steele-idem committed Nov 10, 2016
1 parent a35e6bd commit adb7fe1
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 1 deletion.
8 changes: 7 additions & 1 deletion compiler/ast/HtmlAttribute/html/generateCode.js
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,13 @@ module.exports = function generateCode(node, codegen) {
}

if (node.isLiteralValue()) {
return builder.htmlLiteral(attr(name, value.value));
let literalValue = value.value;

if (literalValue instanceof RegExp) {
literalValue = literalValue.source;
}

return builder.htmlLiteral(attr(name, literalValue));
} else if (value != null) {
return generateCodeForExpressionAttr(name, value, escape, codegen);
} else if (argument) {
Expand Down
1 change: 1 addition & 0 deletions test/autotests/render/pattern-attr/expected.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<input type="text" pattern="\w{2,20}">
1 change: 1 addition & 0 deletions test/autotests/render/pattern-attr/template.marko
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<input type="text" pattern=/\w{2,20}/ />
1 change: 1 addition & 0 deletions test/autotests/render/pattern-attr/test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
exports.templateData = {};

0 comments on commit adb7fe1

Please sign in to comment.