move flattenable keys to types

This commit is contained in:
Sebastian McKenzie 2015-03-09 16:55:00 +11:00
parent 5f2df40f6d
commit c4da0253c5
2 changed files with 3 additions and 1 deletions

View File

@ -1,6 +1,7 @@
import TraversalPath from "./path";
import flatten from "lodash/array/flatten";
import compact from "lodash/array/compact";
import t from "../types";
export default class TraversalContext {
constructor(scope, opts, state, parentPath) {
@ -42,7 +43,7 @@ export default class TraversalContext {
if (this.shouldFlatten) {
node[key] = flatten(node[key]);
if (key === "body" || key === "expressions") {
if (t.FLATTENABLE_KEYS.indexOf(key) >= 0) {
// we can safely compact this
node[key] = compact(node[key]);
}

View File

@ -36,6 +36,7 @@ function registerType(type, skipAliasCheck) {
t.STATEMENT_OR_BLOCK_KEYS = ["consequent", "body", "alternate"];
t.NATIVE_TYPE_NAMES = ["Array", "Object", "Number", "Boolean", "Date", "Array", "String"];
t.FLATTENABLE_KEYS = ["body", "expressions"];
t.FOR_INIT_KEYS = ["left", "init"];
t.VISITOR_KEYS = require("./visitor-keys");