add traversal node aliases to be dry
This commit is contained in:
parent
737c349775
commit
a6ffde6e9b
@ -84,7 +84,14 @@ File.prototype.runTransformer = function (name, transformer) {
|
||||
|
||||
var build = function (exit) {
|
||||
return function (node, parent) {
|
||||
var fns = transformer[node.type] || transformer.all;
|
||||
var types = [node.type].concat(traverse.aliases[node.type] || []);
|
||||
|
||||
var fns = transformer.all;
|
||||
|
||||
_.each(types, function (type) {
|
||||
fns = transformer[type] || fns;
|
||||
});
|
||||
|
||||
if (!fns) return;
|
||||
|
||||
var fn = fns.enter || fns;
|
||||
|
||||
@ -1,9 +1,7 @@
|
||||
var util = require("../util");
|
||||
var _ = require("lodash");
|
||||
|
||||
exports.ArrowFunctionExpression =
|
||||
exports.FunctionDeclaration =
|
||||
exports.FunctionExpression = function (node) {
|
||||
exports.Function = function (node) {
|
||||
if (!node.defaults.length) return;
|
||||
util.ensureBlock(node);
|
||||
|
||||
|
||||
@ -85,9 +85,7 @@ exports.ForOfStatement = function (node, parent, file) {
|
||||
block.body = nodes.concat(block.body);
|
||||
};
|
||||
|
||||
exports.ArrowFunctionExpression =
|
||||
exports.FunctionDeclaration =
|
||||
exports.FunctionExpression = function (node, parent, file) {
|
||||
exports.Function = function (node, parent, file) {
|
||||
var block = node.body;
|
||||
var nodes = [];
|
||||
|
||||
|
||||
@ -1,9 +1,7 @@
|
||||
var util = require("../util");
|
||||
var b = require("ast-types").builders;
|
||||
|
||||
exports.ArrowFunctionExpression =
|
||||
exports.FunctionDeclaration =
|
||||
exports.FunctionExpression = function (node) {
|
||||
exports.Function = function (node) {
|
||||
if (!node.rest) return;
|
||||
|
||||
var rest = node.rest;
|
||||
|
||||
@ -69,6 +69,16 @@ var traverse = module.exports = function (parent, callbacks, blacklistTypes) {
|
||||
|
||||
traverse.FUNCTION_TYPES = ["ArrowFunctionExpression", "FunctionDeclaration", "FunctionExpression"];
|
||||
|
||||
traverse.aliases = {
|
||||
ArrowFunctionExpression: ["Function"],
|
||||
FunctionDeclaration: ["Function"],
|
||||
FunctionExpression: ["Function"]
|
||||
};
|
||||
|
||||
traverse.isFunction = function (node) {
|
||||
return _.contains(traverse.FUNCTION_TYPES, node.type);
|
||||
};
|
||||
|
||||
traverse.Delete = {};
|
||||
|
||||
traverse.hasType = function (tree, type, blacklistTypes) {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user