UNPKG

1.26 kBJavaScriptView Raw
1(function (root, factory) {
2 'use strict';
3
4 var dependencies = [
5 'espower',
6 'esprima',
7 'escodegen'
8 ];
9
10 if (typeof define === 'function' && define.amd) {
11 define(dependencies, factory);
12 } else if (typeof exports === 'object') {
13 module.exports = factory.apply(root, dependencies.map(function (path) { return require(path); }));
14 } else {
15 root.testHelper = factory.apply(root, dependencies.map(function (path) {
16 var tokens = path.split('/');
17 return root[tokens[tokens.length - 1]];
18 }));
19 }
20}(this, function (
21 espower,
22 esprima,
23 escodegen
24) {
25 // see: https://github.com/Constellation/escodegen/issues/115
26 if (typeof define === 'function' && define.amd) {
27 escodegen = window.escodegen;
28 }
29
30function applyEspower (line, options) {
31 options = options || {destructive: false, source: line, path: '/path/to/some_test.js', powerAssertVariableName: 'assert'};
32 var tree = esprima.parse(line, {tolerant: true, loc: true, tokens: true});
33 return espower(tree, options);
34}
35
36function weave (line, options) {
37 return escodegen.generate(applyEspower(line, options), {format: {compact: true}});
38}
39
40return {
41 weave: weave
42};
43
44}));