
Security News
Deno 2.2 Improves Dependency Management and Expands Node.js Compatibility
Deno 2.2 enhances Node.js compatibility, improves dependency management, adds OpenTelemetry support, and expands linting and task automation for developers.
escallmatch
Advanced tools
ECMAScript CallExpression matcher made from function/method signature
Creating CallExpression matcher for method signature 'assert.equal(actual, expected, [message])'
.
Then match against path/to/some_test.js
.
var escallmatch = require('escallmatch'),
esprima = require('esprima'),
estraverse = require('estraverse'),
fs = require('fs');
var matcher = escallmatch('assert.equal(actual, expected, [message])');
estraverse.traverse(esprima.parse(fs.readFileSync('path/to/some_test.js')), {
enter: function (currentNode, parentNode) {
if (matcher.test(currentNode)) {
// currentNode is a CallExpression that matches to the signature
}
var argMatched = matcher.matchArgument(currentNode, parentNode);
if (argMatched) {
if (argMatched.kind === 'mandatory') {
// mandatory arg (in this case, `actual` or `expected`)
} else if (argMatched.kind === 'optional') {
// optional arg (in this case, `message`)
}
}
}
});
where content of path/to/some_test.js
is:
var assert = require('assert'),
anotherAssert = assert,
equal = assert.equal.bind(assert),
foo = '2',
bar = 2;
assert.equal(foo, bar); // matches
assert.equal(bar, foo); // matches
assert.equal(foo, bar, 'foo shoule be equal to bar'); // matches (with optional arg)
assert.equal(); // does not match (less args)
assert.equal(foo); // does not match (less args)
assert.equal(foo, bar, 'hoge', 'fuga'); // does not match (too much args)
assert.notEqual(foo, bar); // does not match (callee method name differs)
anotherAssert.equal(foo, bar); // does not match (callee object name differs)
equal(foo, bar); // does not match (callee does not match)
Please note that escallmatch
is an alpha version product. Pull-requests, issue reports and patches are always welcomed. escallmatch
is a spin-off product of power-assert project.
Create matcher object for a given function/method signature string.
var matcher = escallmatch('assert.equal(actual, expected, [message])');
Any arguments enclosed in bracket (for example, [message]
) means optional parameters. Without bracket means mandatory parameters.
Returns matcher
object having four methods, test
, matchArgument
, calleeAst
, and argumentSignatures
.
Tests whether node
matches the signature or not.
true
if matched.false
if not matched.node
should be an AST node object defined in Mozilla JavaScript AST spec.
Returns match result object representing whether node
(and its parentNode
) matches some argument of the signature or not.
null
if not matched.{name: 'actual', kind: 'mandatory'}
, whose name
is an argument name in the signature and kind
is 'mandatory'
or 'optional'
.node
and parentNode
should be AST node objects defined in Mozilla JavaScript AST spec.
Returns clone of callee AST object based on signature passed to escallmatch
function. Returned tree is one of AST node objects defined in Mozilla JavaScript AST spec (in most cases, Identifier
or MemberExpression
).
Returns array of argument signature objects based on signature passed to escallmatch
function. Returns array of objects like [{name: 'actual', kind: 'mandatory'}]
, whose name
is an argument name in the signature and kind
is 'mandatory'
or 'optional'
.
Install
$ npm install --save escallmatch
Install
$ bower install --save escallmatch
Then load (escallmatch
function is exported)
<script type="text/javascript" src="./path/to/bower_components/escallmatch/build/escallmatch.js"></script>
See CHANGELOG
Licensed under the MIT license.
FAQs
ECMAScript CallExpression matcher made from function/method signature
The npm package escallmatch receives a total of 19,435 weekly downloads. As such, escallmatch popularity was classified as popular.
We found that escallmatch demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Deno 2.2 enhances Node.js compatibility, improves dependency management, adds OpenTelemetry support, and expands linting and task automation for developers.
Security News
React's CRA deprecation announcement sparked community criticism over framework recommendations, leading to quick updates acknowledging build tools like Vite as valid alternatives.
Security News
Ransomware payment rates hit an all-time low in 2024 as law enforcement crackdowns, stronger defenses, and shifting policies make attacks riskier and less profitable.