1 | 'use strict';
|
2 |
|
3 | const balancedMatch = require('balanced-match');
|
4 | const styleSearch = require('style-search');
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 |
|
18 |
|
19 |
|
20 | module.exports = function (source, functionName, callback) {
|
21 | styleSearch(
|
22 | {
|
23 | source,
|
24 | target: functionName,
|
25 | functionNames: 'check',
|
26 | },
|
27 | (match) => {
|
28 | if (source[match.endIndex] !== '(') {
|
29 | return;
|
30 | }
|
31 |
|
32 | const parensMatch = balancedMatch('(', ')', source.substr(match.startIndex));
|
33 |
|
34 | if (!parensMatch) {
|
35 | throw new Error(`No parens match: "${source}"`);
|
36 | }
|
37 |
|
38 | callback(parensMatch.body, match.endIndex + 1);
|
39 | },
|
40 | );
|
41 | };
|