Make special case for class property initializers in shadow-functions (#4502)

This commit is contained in:
Moti Zilberman 2016-10-14 22:21:11 +03:00 committed by Henry Zhu
parent fde16f10fa
commit 2827d660fc
4 changed files with 34 additions and 7 deletions

View File

@ -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;

View File

@ -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;
}

View File

@ -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;
}

View File

@ -0,0 +1,3 @@
{
"plugins": ["syntax-class-properties"]
}