Skip to content

Commit

Permalink
fix(index): don't throw on empty tree ()
Browse files Browse the repository at this point in the history
  • Loading branch information
michael-ciniawsky committed Dec 21, 2017
1 parent 4381164 commit c66f9e2
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 1 deletion.
4 changes: 3 additions & 1 deletion lib/index.js
Expand Up @@ -94,7 +94,9 @@ PostHTML.prototype.process = function (tree, options) {
if (options.parser) parser = options.parser
if (options.render) render = options.render

tree = options.skipParse ? tree : parser(tree, options)
tree = options.skipParse
? tree || []
: parser(tree, options)

tree.options = options
tree.processor = this
Expand Down
37 changes: 37 additions & 0 deletions test/process.js
@@ -0,0 +1,37 @@
var it = require('mocha').it
var expect = require('chai').expect
var describe = require('mocha').describe

var posthtml = require('../lib')

var html = null

function test (html, done) {
posthtml()
.use(function (tree) {
tree.walk(function (node) { return node })
tree.match(/(.+)/, function (node) { return node })

tree.messages.push({
type: 'warning',
message: 'tree is empty'
})

return tree
})
.process(html, { skipParse: true })
.then(function (result) {
expect('').to.eql(result.html)

done()
})
.catch(function (error) {
done(error)
})
}

describe('Process', function () {
it('should not throw on empty tree', function (done) {
test(html, done)
})
})

0 comments on commit c66f9e2

Please sign in to comment.