UNPKG

1.34 kBJavaScriptView Raw
1/**
2 * espower - Power Assert feature instrumentor based on the ECMAScript AST.
3 *
4 * https://github.com/power-assert-js/espower
5 *
6 * Copyright (c) 2013-2016 Takuto Wada
7 * Licensed under the MIT license.
8 * https://github.com/power-assert-js/espower/blob/master/MIT-LICENSE.txt
9 */
10'use strict';
11
12var defaultOptions = require('./lib/default-options');
13var Instrumentor = require('./lib/instrumentor');
14var extend = require('xtend');
15
16/**
17 * Instrument power assert feature into code. ECMAScript AST in, ECMAScript AST out.
18 * @param {object} originalAst JavaScript ECMAScript JS AST to instrument (directly modified if destructive option is truthy)
19 * @param {object} options Instrumentation options.
20 * @returns {object} instrumented AST
21 * @throws {EspowerError} if `originalAst` is already instrumented
22 * @throws {EspowerError} if `originalAst` does not contain location information
23 * @throws {EspowerError} if `options` is not valid
24 */
25function espower (originalAst, options) {
26 var instrumentor = new Instrumentor(extend(defaultOptions(), options));
27 return instrumentor.instrument(originalAst);
28}
29
30espower.defaultOptions = defaultOptions;
31espower.Instrumentor = Instrumentor;
32espower.AssertionVisitor = require('./lib/assertion-visitor');
33espower.EspowerError = require('./lib/espower-error');
34module.exports = espower;