333
schangxiang@126.com
2025-09-19 18966e02fb573c7e2bb0c6426ed792b38b910940
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;