2zH / articles-collection

Chuunibyou is good!
1 stars 0 forks source link

[source code] facebook/jscodeshift #16

Open 2zH opened 6 years ago

2zH commented 6 years ago

jscodeshift is a toolkit for running codemods over multiple JS files. It provides:

  • A runner, which executes the provided transform for each file passed to it. It also outputs a summary of how many files have (not) been transformed.
  • A wrapper around recast, providing a different API. Recast is an AST-to-AST transform tool and also tries to preserve the style of original code as much as possible.

Directory Structure:

main of dependencies:

recipes: https://github.com/facebook/jscodeshift/blob/master/recipes/retain-first-comment.md

2zH commented 6 years ago

Collection:

const astTypes = recast.types;
var types = astTypes.namedTypes;
const NodePath = astTypes.NodePath;
const Node = types.Node;
class Collection { ... }
function _inferTypes(paths) { ... }
function _toTypeArray(value) { ... }
function fromPaths(paths, parent, type) { ... }
function fromNodes(nodes, parent, type) { ... }
const CPt = Collection.prototype;
function registerMethods(methods, type) { ... }
function installTypedMethod(methodName) { ... }
function hasConflictingRegistration(methodName, type) { ... }
var _defaultType = []
function setDefaultCollectionType(type) { ... }

exports.fromPaths = fromPaths;
exports.fromNodes = fromNodes;
exports.registerMethods = registerMethods;
exports.hasConflictingRegistration = hasConflictingRegistration;
exports.setDefaultCollectionType = setDefaultCollectionType;

class Collection:

class Collection {
    constructor(paths, parent, types)
    filter(callback) 
    some(callback)
    every(callback)
    map(callback, type)
    size()
    get length()
    nodes()
    paths()
    getAST()
    toSource(options)
    at(index)
    get()
    getTypes()
    isOfType(type)
}

fromPaths:

Creates a new collection from an array of node paths.

registerMethods:

This function adds the provided methods to the prototype of the corresponding typed collection.

2zH commented 6 years ago

collections

Node

traversalMethods:

mutationMethods:

VariableDeclarator

globalMethods:

filterMethods:

transformMethods:

JSXElement

globalMethods:

filterMethods:

traversalMethods:

mappingMethods:

2zH commented 6 years ago

https://github.com/2zH/emiya/blob/master/scripts/fetch-startkit-for-jscodeshift.js