From 13a6c696681de0eac6eb1945f41907aceb94887c Mon Sep 17 00:00:00 2001 From: Sebastian McKenzie Date: Thu, 7 May 2015 23:02:40 +0100 Subject: [PATCH] add node existence check to each visitor call --- src/babel/traversal/path/index.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/babel/traversal/path/index.js b/src/babel/traversal/path/index.js index 408726f235..6ac9cc1819 100644 --- a/src/babel/traversal/path/index.js +++ b/src/babel/traversal/path/index.js @@ -696,6 +696,9 @@ export default class TraversalPath { for (var fn of (fns: Array)) { if (!fn) continue; + var node = this.node; + if (!node) return; + // call the function with the params (node, parent, scope, state) var replacement = fn.call(this, node, this.parent, this.scope, this.state); if (replacement) { @@ -703,11 +706,11 @@ export default class TraversalPath { this.replaceWith(replacement, true); if (this.type !== previousType) { this.queueNode(this); - break; + return; } } - if (this.shouldStop || this.removed) break; + if (this.shouldStop || this.removed) return; } }