Code Modificators

Code modificators are scripts that traverse javascript files and can modify it’s contents programatically.

JSCodeshift

JSCodeShift is a code modificator tool that wraps Recast with a JQuery-like API.

It works by reading the javascript file text as input to turn it into AST (Abstract Syntax Trees)

An identifier to JSCodeShift is like a selector to CSS

Note: pascal case version of node type Identifier is used for checking the type of the node and camel case version of node type identifier is used to create a node of that type.

Reference

To create an abstract tree run app.jscodeshift(file.source)

AST

key Definition
Program Program
ExpressionStatement a function or any expression eg a + b
BinaryExpression is a type of ExpressionStatement that includes only two values
Identifier is used for names of variables, functions, methods, object keys, etc
TemplateLiteral string template
quasis Template elements between ${} expressions

Tools

tutorials