
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.
esprima-selector
Advanced tools
ask whether a particular esprima node matches a CSS-like selector
Use CSS-like selectors to match nodes in an esprima abstract syntax tree (AST).
var eselector = require('esprima-selector');
If you're using a library like falafel, then you have a callback function that takes an AST node as its argument. Well, eselector.tester()
accepts an array of such functions, each with a CSS-like selector for the nodes it should be called for. Example:
var eselector = require('esprima-selector');
var src = falafel(fs.readFileSync('test.js', 'utf8'), eselector.tester([
{
selector: '*',
callback: function(node) {
// Gets called for every node in the AST.
console.log('node', node.name, node.classes);
},
},
{
selector: 'program',
callback: function(node) {
// Gets called for the outmost node in the AST.
node.update(
'var indent = []; function start() { console.log(indent.join(\'\') + \'*\'); indent.push(\'\t\') } function end() { indent.pop() }' +
node.source());
},
},
{
selector: 'program declaration.function > block',
callback: function(node) {
// Gets called for every code block that's the body of a function
// declaration.
node.update('start();' + node.source() + 'end();');
},
},
]));
You select these as if they were CSS tags (ex: block > statement
):
program
(the outermost node)expression
(e.g. variable references, math expressions, initializers)statement
(e.g. return
, if(...) {...}
, debugger
)clause
(e.g. catch(e) {...}
)block
(e.g. {...}
)declaration
(e.g. var x = ...
)declarator
(e.g. the x = ...
part of var x = ...
)property
(e.g. the a:
part of {a: 42}
)switch-case
(e.g. case 42: ...
)You select these as if they were CSS classes (ex: .function
or declaration.function
):
42
or "foo"
)a()
)-i
)i++
)a + b
)a.b
)a && b
)a ? b : c
)a, b
)foo:
){...}
of if (...) {...}
)if
statement)else
branch of an if
statement)FAQs
ask whether a particular esprima node matches a CSS-like selector
We found that esprima-selector 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.