From 4a17c076683724d715d61d833365f87bfd68a6df Mon Sep 17 00:00:00 2001 From: Sebastian McKenzie Date: Tue, 4 Aug 2015 13:03:14 +0100 Subject: [PATCH] check if shadow is defined before looking it up - fixes #2152 --- packages/babel/src/traversal/path/ancestry.js | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/packages/babel/src/traversal/path/ancestry.js b/packages/babel/src/traversal/path/ancestry.js index c1e4b6f128..66049e4856 100644 --- a/packages/babel/src/traversal/path/ancestry.js +++ b/packages/babel/src/traversal/path/ancestry.js @@ -183,7 +183,7 @@ export function inType() { export function inShadow(key?) { var path = this; - while (path) { + do { if (path.isFunction()) { var shadow = path.node.shadow; if (shadow || path.isArrowFunctionExpression()) { @@ -192,7 +192,7 @@ export function inShadow(key?) { // { this: false } // // we need to catch this case if `inShadow` has been passed a `key` - if (!key || shadow[key] !== false) { + if (!key || !shadow || shadow[key] !== false) { return path; } } @@ -200,7 +200,6 @@ export function inShadow(key?) { // normal function, we've found our function context return null; } - path = path.parentPath; - } + } while(path = path.parentPath); return null; }