From 836f3986199378f7646897091afd3f37dc482003 Mon Sep 17 00:00:00 2001 From: Logan Smyth Date: Sun, 6 Mar 2016 03:16:11 -0800 Subject: [PATCH] Re-use central inShadow logic. --- packages/babel-helper-replace-supers/src/index.js | 6 +----- packages/babel-traverse/src/path/ancestry.js | 7 ++++--- 2 files changed, 5 insertions(+), 8 deletions(-) diff --git a/packages/babel-helper-replace-supers/src/index.js b/packages/babel-helper-replace-supers/src/index.js index 76b05d7ad4..7010cb1670 100644 --- a/packages/babel-helper-replace-supers/src/index.js +++ b/packages/babel-helper-replace-supers/src/index.js @@ -20,11 +20,7 @@ function isMemberExpressionSuper(node) { } let visitor = { - "ObjectMethod|ClassMethod"(path) { - path.skip(); - }, - - "FunctionDeclaration|FunctionExpression"(path) { + Function(path) { if (!path.inShadow("this")) { path.skip(); } diff --git a/packages/babel-traverse/src/path/ancestry.js b/packages/babel-traverse/src/path/ancestry.js index 8578f7d3e8..f98934c6b7 100644 --- a/packages/babel-traverse/src/path/ancestry.js +++ b/packages/babel-traverse/src/path/ancestry.js @@ -220,14 +220,15 @@ export function inShadow(key?) { let parentFn = this.isFunction() ? this : this.findParent((p) => p.isFunction()); if (!parentFn) return; - let shadow = parentFn.node.shadow; - if (shadow) { + if (parentFn.isFunctionExpression() || parentFn.isFunctionDeclaration()) { + let shadow = parentFn.node.shadow; + // this is because sometimes we may have a `shadow` value of: // // { this: false } // // we need to catch this case if `inShadow` has been passed a `key` - if (!key || shadow[key] !== false) { + if (shadow && (!key || shadow[key] !== false)) { return parentFn; } } else if (parentFn.isArrowFunctionExpression()) {