Security News
GitHub Removes Malicious Pull Requests Targeting Open Source Repositories
GitHub removed 27 malicious pull requests attempting to inject harmful code across multiple open source repositories, in another round of low-effort attacks.
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
GitHub removed 27 malicious pull requests attempting to inject harmful code across multiple open source repositories, in another round of low-effort attacks.
Security News
RubyGems.org has added a new "maintainer" role that allows for publishing new versions of gems. This new permission type is aimed at improving security for gem owners and the service overall.
Security News
Node.js will be enforcing stricter semver-major PR policies a month before major releases to enhance stability and ensure reliable release candidates.