Skip to content

Commit

Permalink
Make special case for class property initializers in `shadow-function…
Browse files Browse the repository at this point in the history
…s` (babel#4502)
  • Loading branch information
motiz88 authored and chrisprice committed Oct 18, 2016
1 parent 4776e78 commit 119079a
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 7 deletions.
Expand Up @@ -49,21 +49,25 @@ function remap(path, key) {
let currentFunction;
let passedShadowFunction = false;

let fnPath = path.findParent(function (path) {
if (path.isProgram() || path.isFunction()) {
let fnPath = path.find(function (innerPath) {
if (innerPath.parentPath && innerPath.parentPath.isClassProperty() && innerPath.key === "value") {
return true;
}
if (path === innerPath) return false;
if (innerPath.isProgram() || innerPath.isFunction()) {
// catch current function in case this is the shadowed one and we can ignore it
currentFunction = currentFunction || path;
currentFunction = currentFunction || innerPath;
}

if (path.isProgram()) {
if (innerPath.isProgram()) {
passedShadowFunction = true;

return true;
} else if (path.isFunction() && !path.isArrowFunctionExpression()) {
} else if (innerPath.isFunction() && !innerPath.isArrowFunctionExpression()) {
if (shadowFunction) {
if (path === shadowFunction || path.node === shadowFunction.node) return true;
if (innerPath === shadowFunction || innerPath.node === shadowFunction.node) return true;
} else {
if (!path.is("shadow")) return true;
if (!innerPath.is("shadow")) return true;
}

passedShadowFunction = true;
Expand Down
@@ -0,0 +1,10 @@
class A {
prop1 = () => this;
static prop2 = () => this;
prop3 = () => arguments;
static prop4 = () => arguments;
prop5 = this;
static prop6 = this;
prop7 = arguments;
static prop8 = arguments;
}
@@ -0,0 +1,10 @@
class A {
prop1 = () => this;
static prop2 = () => this;
prop3 = () => arguments;
static prop4 = () => arguments;
prop5 = this;
static prop6 = this;
prop7 = arguments;
static prop8 = arguments;
}
@@ -0,0 +1,3 @@
{
"plugins": ["syntax-class-properties"]
}

0 comments on commit 119079a

Please sign in to comment.