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.
Astify generates Abstract Syntax Trees from objects in live JS (as well as from source). Want to convert the entire global object to source? `global.toAST().toSource()`. Beyond adding `toAST`, astify also makes build AST (which is then convertable to code
Astify generates Abstract Syntax Trees from objects in live JS (as well as from source). Want to convert the entire global object to source? global.toAST().toSource()
. Beyond adding toAST
, astify also makes build AST (which is then convertable to code using toSource
) super simple to do. Frankenstein different pieces of objects and functions together to make new ones.
This is still experimental and unfinished.
This is a fork of the original astify, with the dependancies included and uploaded to npm.
It is currently set up for use in Node.js (will be combining for a browser build soon).
var astify = require('astify');
astify.install(global); //the toAST functions must be explicitly installed on a global object
console.log(global.toAST().toSource()); // anything can be converted to AST
toAST
prototype functions on a given global object, defaulting to the main global.toAST
methods. showHidden includes non-enumerable properties. identity labels an object which doesn't have a discernable name. By default a gensym is provided.To select nodes you can use css-like syntax (work in progress) using node.find(selector). Some examples:
function function function var
- descending selectors, this would filter to vars that are inside 3 nested functions.function > id
- child selector requires nodes to be direct childrenvar.declarations
- select specific propertiesfunction.params.id
- select multiple propertiesfunction:scope
- select all the nodes in the current scopemethod[kind = ""][key != "constructor"].value
- selects methods (es6) with no kind (normal) where key is notEqual to constructor, then selectos its value property (a function expression).method[key = "constructor"].value:first
- selects the first method with the name "constructor" and returns its value (function expr)ident:first-child
- selects all identifiers that are first-childrenreturn:last-child
- select all return statements which are last childrencall[callee = "super"]
- select functions calls where the function name is "super"member[object=super]
- selects expressions that look like "super.prop"An intro example to manually assembling nodes
var _ = astify.createNode;
// intermix explicit AST node definitions with regular functions, objects, and literals
var myAST = _('object', {
a: 50,
b: _('function').declare({
somevar: 5,
another: _('iife').append([
_('return', _('function', 'another'))
])
}),
c: function hi(){
return 'stuff';
},
get d(){ return this.b.name }
});
Which produces
console.log(myAST.toSource());
// -->
var myAST = {
a: 50,
b: function () {
var somevar = 5,
another = function () {
return function another() {
};
}();
},
c: function hi() {
return 'stuff';
},
get d() {
return this.b.name;
}
};
And the AST:
{ type: 'ObjectExpression',
properties:
[ { type: 'Property',
key: { type: 'Identifier', name: 'a' },
value: { type: 'Literal', value: 50 },
kind: 'init' },
{ type: 'Property',
key: { type: 'Identifier', name: 'b' },
value:
{ type: 'FunctionExpression',
params: [],
id: null,
body:
{ type: 'BlockStatement',
body:
[ { type: 'VariableDeclaration',
kind: 'var',
declarations:
[ { type: 'VariableDeclarator',
id: { type: 'Identifier', name: 'somevar' },
init: { type: 'Literal', value: 5 } },
{ type: 'VariableDeclarator',
id: { type: 'Identifier', name: 'another' },
init:
{ type: 'CallExpression',
callee:
{ type: 'FunctionExpression',
params: [],
id: null,
body:
{ type: 'BlockStatement',
body:
[ { type: 'ReturnStatement',
argument:
{ type: 'FunctionExpression',
params: [],
id: { type: 'Identifier', name: 'another' },
body: { type: 'BlockStatement', body: [] } } } ] } },
arguments: [] } } ] } ] } },
kind: 'init' },
{ type: 'Property',
key: { type: 'Identifier', name: 'c' },
value:
{ type: 'FunctionExpression',
id: { type: 'Identifier', name: 'hi' },
params: [],
body:
{ type: 'BlockStatement',
body:
[ { type: 'ReturnStatement',
argument: { type: 'Literal', value: 'stuff' } } ] } },
kind: 'init' },
{ type: 'Property',
key: { type: 'Identifier', name: 'd' },
value:
{ type: 'FunctionExpression',
id: { type: 'Identifier', name: 'd' },
params: [],
body:
{ type: 'BlockStatement',
body:
[ { type: 'ReturnStatement',
argument:
{ type: 'MemberExpression',
computed: false,
object:
{ type: 'MemberExpression',
computed: false,
object: { type: 'Identifier', name: 'this' },
property: { type: 'Identifier', name: 'b' } },
property: { type: 'Identifier', name: 'name' } } } ] } },
kind: 'get' } ] }
The short name can be used to identify the when using astify.createNode
. Optional arguments are in [brackets].
FAQs
Astify generates Abstract Syntax Trees from objects in live JS (as well as from source). Want to convert the entire global object to source? `global.toAST().toSource()`. Beyond adding `toAST`, astify also makes build AST (which is then convertable to code
The npm package astify receives a total of 12 weekly downloads. As such, astify popularity was classified as not popular.
We found that astify 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.