diff --git a/packages/babel-types/src/converters.js b/packages/babel-types/src/converters.js index bcbc7efbe3..c10e38e63d 100644 --- a/packages/babel-types/src/converters.js +++ b/packages/babel-types/src/converters.js @@ -2,7 +2,6 @@ import isPlainObject from "lodash/lang/isPlainObject"; import isNumber from "lodash/lang/isNumber"; import isRegExp from "lodash/lang/isRegExp"; import isString from "lodash/lang/isString"; -import traverse from "babel-traverse"; import type { Scope } from "babel-traverse"; import * as t from "./index"; @@ -99,7 +98,14 @@ export function toSequenceExpression(nodes: Array, scope: Scope): ?Objec } } +// Can't use import because of cyclic dependency between babel-traverse +// and this module (babel-types). This require needs to appear after +// we export the TYPES constant, so we lazy-initialize it before use. +let traverse; + export function toKeyAlias(node: Object, key: Object = node.key): string { + if (!traverse) traverse = require("babel-traverse").default; + let alias; if (node.kind === "method") { diff --git a/packages/babel-types/src/index.js b/packages/babel-types/src/index.js index 913368d9ba..fe968f9f7a 100644 --- a/packages/babel-types/src/index.js +++ b/packages/babel-types/src/index.js @@ -3,7 +3,6 @@ import compact from "lodash/array/compact"; import loClone from "lodash/lang/clone"; import each from "lodash/collection/each"; import uniq from "lodash/array/uniq"; -import traverse from "babel-traverse"; let t = exports; @@ -400,11 +399,18 @@ function _inheritComments(key, child, parent) { } } +// Can't use import because of cyclic dependency between babel-traverse +// and this module (babel-types). This require needs to appear after +// we export the TYPES constant, so we lazy-initialize it before use. +let traverse; + /** * Inherit all contextual properties from `parent` node to `child` node. */ export function inherits(child: Object, parent: Object): Object { + if (!traverse) traverse = require("babel-traverse").default; + if (!child || !parent) return child; // optionally inherit specific properties if not null