UNPKG

746 BJavaScriptView Raw
1'use strict';
2const concordance = require('concordance');
3const dotProp = require('dot-prop');
4const generate = require('@babel/generator').default;
5const concordanceOptions = require('./concordance-options').default;
6
7const computeStatement = node => generate(node).code;
8const getNode = (ast, path) => dotProp.get(ast, path.replace(/\//g, '.'));
9
10const 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
23module.exports.formatter = formatter;