Lazy-initialize babel-traverse to avoid circular dep. (#3497)
This commit is contained in:
@@ -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<Object>, 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") {
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user