Make special case for class property initializers in shadow-functions (#4502)
This commit is contained in:
parent
fde16f10fa
commit
2827d660fc
@ -49,21 +49,25 @@ function remap(path, key) {
|
|||||||
let currentFunction;
|
let currentFunction;
|
||||||
let passedShadowFunction = false;
|
let passedShadowFunction = false;
|
||||||
|
|
||||||
let fnPath = path.findParent(function (path) {
|
let fnPath = path.find(function (innerPath) {
|
||||||
if (path.isProgram() || path.isFunction()) {
|
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
|
// 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;
|
passedShadowFunction = true;
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
} else if (path.isFunction() && !path.isArrowFunctionExpression()) {
|
} else if (innerPath.isFunction() && !innerPath.isArrowFunctionExpression()) {
|
||||||
if (shadowFunction) {
|
if (shadowFunction) {
|
||||||
if (path === shadowFunction || path.node === shadowFunction.node) return true;
|
if (innerPath === shadowFunction || innerPath.node === shadowFunction.node) return true;
|
||||||
} else {
|
} else {
|
||||||
if (!path.is("shadow")) return true;
|
if (!innerPath.is("shadow")) return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
passedShadowFunction = true;
|
passedShadowFunction = true;
|
||||||
|
|||||||
@ -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"]
|
||||||
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user