Security News
Fluent Assertions Faces Backlash After Abandoning Open Source Licensing
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.
Tentative to a simple JavaScript AST modification library.
If you've ever worked with AST trying to edit source code, you've probably had a hard time as the syntax is somehow terse and you need to loop and use conditionnals a lot. AST Query try to hide this complexity behind a declarative façade.
Making this choice, AST Query does not try to cover a full AST API, but instead answer common needs.
Install: npm install --save ast-query
First, you always need to create a Tree
which you'll edit
var Tree = require("ast-query");
var tree = new Tree("var a = 'foo'");
To get the source code back after modifying the AST, call the toString
method on the
tree.
// ...
tree.var("a").value("'bar'");
console.log( tree.toString() );
// LOG: var a = 'bar';
Reminder you're editing source code. As so, you'll need to add extra quotes when outputting
strings (e.g.: "'foo'"
).
Also, note that AST Query isn't checking you output valid code; neither does it check for whitespace consistency. You may want to pass each transformed sources in a beautifier if this is important.
new Tree( sourceCode )
tree.var( name )
variable
token. See object methodstree.object()
object
literal token. See object methods.value( value )
.rename( name )
.replaceWith( value )
var <value goes here>;
.insertAfter( value )
.insertBefore( value )
var
keyword.delete()
.assignedTo( name )
var
..passedTo( name )
function
or a method
Example:
var tree = new Tree("grunt.init({ key: 'value' })");
tree.object().passedTo("grunt.init").key("key").value("'foo'");
console.log( tree.toString() );
.key( name )
Property
token. See object methods.value( value )
.rename( name )
.delete()
Style Guide: Please base yourself on Idiomatic.js
style guide with two space indent
Unit test: Unit test are wrote in Mocha. Please add a unit test for every new feature
or bug fix. npm test
to run the test suite.
Documentation: Add documentation for every API change. Feel free to send corrections
or better docs!
Pull Requests: Send fixes PR on the master
branch. Any new features should be send
on the wip
branch.
Copyright (c) 2012 Simon Boudrias (twitter: @vaxilart)
Licensed under the MIT license.
FAQs
Declarative JavaScript AST modification façade
The npm package ast-query receives a total of 3,297 weekly downloads. As such, ast-query popularity was classified as popular.
We found that ast-query 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
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.
Research
Security News
Socket researchers uncover the risks of a malicious Python package targeting Discord developers.
Security News
The UK is proposing a bold ban on ransomware payments by public entities to disrupt cybercrime, protect critical services, and lead global cybersecurity efforts.