From 24f5ef50b041a8659c904f0e8bdf88d5d0d77448 Mon Sep 17 00:00:00 2001 From: Sebastian McKenzie Date: Mon, 2 Nov 2015 06:36:07 +0000 Subject: [PATCH] when we encounter a different NodePath instance, ignore it and create a new one. this is going to thrash the tree and memory but npm and node module resolution is atrociously bad --- packages/babel-traverse/src/path/index.js | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/packages/babel-traverse/src/path/index.js b/packages/babel-traverse/src/path/index.js index 1469becd39..39a0e26348 100644 --- a/packages/babel-traverse/src/path/index.js +++ b/packages/babel-traverse/src/path/index.js @@ -77,15 +77,23 @@ export default class NodePath { } } + if (!(path instanceof NodePath)) { + if (path.constructor.name === "NodePath") { + // we're going to absolutley thrash the tree and allocate way too many node paths + // than is necessary but there's no way around this as the node module resolution + // algorithm is ridiculous + path = null; + } else { + // badly deserialised probably + throw new Error("We found a path that isn't a NodePath instance. Possiblly due to bad serialisation."); + } + } + if (!path) { path = new NodePath(hub, parent); paths.push(path); } - if (!(path instanceof NodePath)) { - throw new Error("We found a path that isn't a NodePath instance"); - } - path.setup(parentPath, container, listKey, key); return path;