add support for eslint colons in visitors

This commit is contained in:
Sebastian McKenzie 2015-09-01 05:00:38 +01:00
parent b7c91178a9
commit ac5dcf2884

View File

@ -3,10 +3,6 @@ import * as messages from "babel-messages";
import * as t from "babel-types";
import clone from "lodash/lang/clone";
/**
* [Please add a description.]
*/
export function explode(visitor) {
if (visitor._exploded) return visitor;
visitor._exploded = true;
@ -26,6 +22,22 @@ export function explode(visitor) {
}
}
// normalise colons
for (let nodeType in visitor) {
if (shouldIgnoreKey(nodeType)) continue;
let parts = nodeType.split(":");
if (parts.length === 1) continue;
let fns = visitor[nodeType];
delete visitor[nodeType];
nodeType = parts[0];
visitor[nodeType] = visitor[nodeType] || {};
visitor[nodeType][parts[1]] = fns;
}
// verify data structure
verify(visitor);
@ -100,10 +112,6 @@ export function explode(visitor) {
return visitor;
}
/**
* [Please add a description.]
*/
export function verify(visitor) {
if (visitor._verified) return;
@ -130,10 +138,6 @@ export function verify(visitor) {
visitor._verified = true;
}
/**
* [Please add a description.]
*/
export function merge(visitors) {
var rootVisitor = {};
@ -149,10 +153,6 @@ export function merge(visitors) {
return rootVisitor;
}
/**
* [Please add a description.]
*/
function ensureEntranceObjects(obj) {
for (let key in obj) {
if (shouldIgnoreKey(key)) continue;
@ -164,19 +164,11 @@ function ensureEntranceObjects(obj) {
}
}
/**
* [Please add a description.]
*/
function ensureCallbackArrays(obj){
if (obj.enter && !Array.isArray(obj.enter)) obj.enter = [obj.enter];
if (obj.exit && !Array.isArray(obj.exit)) obj.exit = [obj.exit];
}
/**
* [Please add a description.]
*/
function wrapCheck(wrapper, fn) {
return function () {
if (wrapper.checkPath(this)) {
@ -185,10 +177,6 @@ function wrapCheck(wrapper, fn) {
};
}
/**
* [Please add a description.]
*/
function shouldIgnoreKey(key) {
// internal/hidden key
if (key[0] === "_") return true;
@ -202,10 +190,6 @@ function shouldIgnoreKey(key) {
return false;
}
/**
* [Please add a description.]
*/
function mergePair(dest, src) {
for (var key in src) {
dest[key] = [].concat(dest[key] || [], src[key]);