1 | 'use strict';
|
2 | const concordance = require('concordance');
|
3 | const dotProp = require('dot-prop');
|
4 | const generate = require('@babel/generator').default;
|
5 | const concordanceOptions = require('./concordance-options').default;
|
6 |
|
7 | const computeStatement = node => generate(node).code;
|
8 | const getNode = (ast, path) => dotProp.get(ast, path.replace(/\//g, '.'));
|
9 |
|
10 | const formatter = context => {
|
11 | const ast = JSON.parse(context.source.ast);
|
12 | const args = context.args[0].events;
|
13 | return args
|
14 | .map(arg => {
|
15 | const node = getNode(ast, arg.espath);
|
16 | const statement = computeStatement(node);
|
17 | const formatted = concordance.format(arg.value, concordanceOptions);
|
18 | return [statement, formatted];
|
19 | })
|
20 | .reverse();
|
21 | };
|
22 |
|
23 | module.exports.formatter = formatter;
|