-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
31 lines (27 loc) · 882 Bytes
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
/**
* escallmatch:
* ECMAScript CallExpression matcher made from function/method signature
*
* https://github.com/twada/escallmatch
*
* Copyright (c) 2014-2016 Takuto Wada
* Licensed under the MIT license.
* https://github.com/twada/escallmatch/blob/master/LICENSE
*/
'use strict';
/* jshint -W024 */
var esprima = require('esprima');
var CallMatcher = require('call-matcher');
var notCallExprMessage = 'Argument should be in the form of CallExpression';
function createMatcher (signatureStr, options) {
var ast = extractExpressionFrom(esprima.parse(signatureStr));
return new CallMatcher(ast, options || {});
}
function extractExpressionFrom (tree) {
var statement = tree.body[0];
if (statement.type !== 'ExpressionStatement') {
throw new Error(notCallExprMessage);
}
return statement.expression;
}
module.exports = createMatcher;