Skip to content

Commit d2d6a9e

Browse files
committed
patch to fix empty node handling within expressions
1 parent 3a89525 commit d2d6a9e

4 files changed

Lines changed: 110 additions & 124 deletions

File tree

lib/index.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@ module.exports = function reshapeEvalCode (_locals = {}) {
2424
}
2525

2626
function evalNode (node, locals, opts) {
27-
const newNode = parse(gen.call({ runtime: opts.runtime }, node, opts)(locals))
28-
if (node.location) { newNode.location = node.location }
27+
let newNode = parse(gen.call({ runtime: opts.runtime }, node, opts)(locals))
28+
if (newNode.length === 0) { newNode = [{ type: 'text', content: '' }] }
29+
if (node.location) { newNode[0].location = node.location }
2930
return newNode
3031
}

package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,13 @@
1313
"reshape-plugin-util": "^0.2.1"
1414
},
1515
"devDependencies": {
16-
"ava": "^0.20.0",
17-
"codecov": "^2.2.0",
18-
"nyc": "^11.0.3",
16+
"ava": "^0.22.0",
17+
"codecov": "^2.3.0",
18+
"nyc": "^11.1.0",
1919
"reshape": "^0.4.1",
2020
"reshape-expressions": "^0.1.5",
2121
"snazzy": "^7.0.0",
22-
"standard": "^10.0.2"
22+
"standard": "^10.0.3"
2323
},
2424
"engines": {
2525
"node": ">= 6"

test/index.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,9 @@ test('merges from reshape options locals', (t) => {
2626
.process('<p>{{ foo }}</p>')
2727
.then((res) => { t.is(res.output(), '<p>bar</p>') })
2828
})
29+
30+
test('correctly handles empty nodes', (t) => {
31+
return reshape({ plugins: [expressions(), evalCode()], locals: { foo: 'bar' } })
32+
.process('<p class="{{ true ? \'\' : \'\' }}"></p>')
33+
.then((res) => { t.is(res.output(), '<p class></p>') })
34+
})

0 commit comments

Comments
 (0)