Skip to content

Commit c66f9e2

Browse files
fix(index): don't throw on empty tree ()
1 parent 4381164 commit c66f9e2

File tree

2 files changed

+40
-1
lines changed

2 files changed

+40
-1
lines changed

lib/index.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,9 @@ PostHTML.prototype.process = function (tree, options) {
9494
if (options.parser) parser = options.parser
9595
if (options.render) render = options.render
9696

97-
tree = options.skipParse ? tree : parser(tree, options)
97+
tree = options.skipParse
98+
? tree || []
99+
: parser(tree, options)
98100

99101
tree.options = options
100102
tree.processor = this

test/process.js

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
var it = require('mocha').it
2+
var expect = require('chai').expect
3+
var describe = require('mocha').describe
4+
5+
var posthtml = require('../lib')
6+
7+
var html = null
8+
9+
function test (html, done) {
10+
posthtml()
11+
.use(function (tree) {
12+
tree.walk(function (node) { return node })
13+
tree.match(/(.+)/, function (node) { return node })
14+
15+
tree.messages.push({
16+
type: 'warning',
17+
message: 'tree is empty'
18+
})
19+
20+
return tree
21+
})
22+
.process(html, { skipParse: true })
23+
.then(function (result) {
24+
expect('').to.eql(result.html)
25+
26+
done()
27+
})
28+
.catch(function (error) {
29+
done(error)
30+
})
31+
}
32+
33+
describe('Process', function () {
34+
it('should not throw on empty tree', function (done) {
35+
test(html, done)
36+
})
37+
})

0 commit comments

Comments
 (0)