diff --git a/packages/babel-traverse/src/path/context.js b/packages/babel-traverse/src/path/context.js index 108f0934da..31aef5fdcd 100644 --- a/packages/babel-traverse/src/path/context.js +++ b/packages/babel-traverse/src/path/context.js @@ -194,7 +194,11 @@ export function _resyncRemoved() { export function popContext() { this.contexts.pop(); - this.setContext(this.contexts[this.contexts.length - 1]); + if (this.contexts.length > 0) { + this.setContext(this.contexts[this.contexts.length - 1]); + } else { + this.setContext(undefined); + } } export function pushContext(context) {