compilerr
Advanced tools
Comparing version 0.1.0 to 0.2.0
@@ -23,3 +23,3 @@ { | ||
}, | ||
"version": "0.1.0" | ||
"version": "0.2.0" | ||
} |
@@ -78,3 +78,3 @@ 'use strict'; | ||
module.exports.compile = function compile(template, parameters) { | ||
module.exports.compile = function compile(template, parameters, cause) { | ||
var code, | ||
@@ -84,2 +84,6 @@ err, | ||
if (arguments.length === 2 && parameters instanceof Error) { | ||
cause = parameters; | ||
} | ||
code = (template.code === undefined) ? undefined : renderString(template.code, parameters); | ||
@@ -90,2 +94,6 @@ message = (template.message === undefined) ? undefined : renderString(template.message, parameters); | ||
if (cause !== undefined) { | ||
err.cause = cause; | ||
} | ||
if (code !== undefined) { | ||
@@ -92,0 +100,0 @@ err.code = code; |
@@ -109,4 +109,30 @@ 'use strict'; | ||
it('should return an error with a given cause as a third argument', function () { | ||
var cause, | ||
err; | ||
cause = new Error('a fake cause'); | ||
err = compilerr.compile({}, {}, cause); | ||
expect(err).to.be.an.instanceOf(Error); | ||
expect(err.cause).to.equal(cause); | ||
}); | ||
it('should return an error with a given cause as a third argument', function () { | ||
var cause, | ||
err; | ||
cause = new Error('a fake cause'); | ||
err = compilerr.compile({}, cause); | ||
expect(err).to.be.an.instanceOf(Error); | ||
expect(err.cause).to.equal(cause); | ||
}); | ||
}); | ||
}); |
10882
373