Skip to content

Commit 2abfe12

Browse files
committed
fix mixed attribute node types, ref #1
1 parent 19838a5 commit 2abfe12

2 files changed

Lines changed: 5 additions & 4 deletions

File tree

lib/index.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,9 @@ module.exports = function reshapeEvalCode (_locals = {}) {
1111
if (node.type === 'tag') {
1212
if (!node.attrs) return node
1313
for (let k in node.attrs) {
14-
node.attrs[k].map((n) => {
15-
if (n.type === 'code') { node.attrs[k] = evalNode(n, locals, opts) }
14+
node.attrs[k] = node.attrs[k].map((n) => {
15+
if (n.type !== 'code') return n
16+
return evalNode(n, locals, opts)[0]
1617
})
1718
}
1819
return node

test/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ test('loops', (t) => {
1717

1818
test('evals attribute code nodes', (t) => {
1919
return reshape({ plugins: [expressions(), evalCode({ foo: 'bar' })] })
20-
.process('<p class="{{ foo }}">content</p>')
21-
.then((res) => { t.is(res.output(), '<p class="bar">content</p>') })
20+
.process('<p class="test-{{ foo }}-test2">content</p>')
21+
.then((res) => { t.is(res.output(), '<p class="test-bar-test2">content</p>') })
2222
})
2323

2424
test('merges from reshape options locals', (t) => {

0 commit comments

Comments
 (0)