From 4242a8c0106ca77424c86a95232402db6e244d82 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Buscht=C3=B6ns?= Date: Thu, 5 Oct 2017 09:27:40 +0200 Subject: [PATCH] feat: allow html-attributes in addition to attributes --- lib/component-attributes-transform.js | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/lib/component-attributes-transform.js b/lib/component-attributes-transform.js index 1ebd4dd..fec8b1d 100644 --- a/lib/component-attributes-transform.js +++ b/lib/component-attributes-transform.js @@ -3,12 +3,14 @@ /* ```hbs + {{my-component (html-attributes data-qux="quax" class="horse" id="pony")}} {{my-component (attributes data-foo="bar" class="cat" id="dog")}} ``` becomes ```hbs + {{my-component class="horse" id="pony" __HTML_ATTRIBUTES__=(hash data-qux="quax") }} {{my-component class="cat" id="dog" __HTML_ATTRIBUTES__=(hash data-foo="bar") }} ``` */ @@ -30,7 +32,7 @@ AttributesExpressionTransform.prototype.transform = function(ast) { }); function transform(curly) { - if (hasAttributesExpression(curly)) { + if (hasHTMLAttributesExpression(curly)) { let attributes = curly.params.pop(); let pairs = attributes.hash.pairs; @@ -65,10 +67,13 @@ AttributesExpressionTransform.prototype.transform = function(ast) { } } - function hasAttributesExpression(curly) { + function hasHTMLAttributesExpression(curly) { if (curly.params.length > 0) { let last = curly.params[curly.params.length - 1]; - if (last.type === "SubExpression" && last.path.original === "attributes") { + if ( + last.type === "SubExpression" && + (last.path.original === "html-attributes" || last.path.original === "attributes") + ) { return true; } }