Blacklist this in functional composition heuristics (#4836)
This commit is contained in:
1 parent
cd16ff27d7
commit
03ee86ea80
3 files changed
+53
-1
No files matched your search
@@ -3440,11 +3440,27 @@ const functionCompositionFunctionNames = new Set([
|
||||
"connect" // Redux
|
||||
]);
|
||||
|
||||
function isThisExpression(node) {
|
||||
switch (node.type) {
|
||||
case "OptionalMemberExpression":
|
||||
case "MemberExpression": {
|
||||
return isThisExpression(node.object);
|
||||
}
|
||||
case "ThisExpression":
|
||||
case "Super": {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function isFunctionCompositionFunction(node) {
|
||||
switch (node.type) {
|
||||
case "OptionalMemberExpression":
|
||||
case "MemberExpression": {
|
||||
return isFunctionCompositionFunction(node.property);
|
||||
return (
|
||||
!isThisExpression(node.object) &&
|
||||
isFunctionCompositionFunction(node.property)
|
||||
);
|
||||
}
|
||||
case "Identifier": {
|
||||
return functionCompositionFunctionNames.has(node.name);
|
||||
|
||||
@@ -27,6 +27,18 @@ somelib.composeFlipped(
|
||||
|
||||
// no regression (#4602)
|
||||
const hasValue = hasOwnProperty(a, b);
|
||||
|
||||
// filter out ThisExpression
|
||||
this.compose(sortBy(x => x), flatten);
|
||||
this.a.b.c.compose(sortBy(x => x), flatten);
|
||||
someObj.someMethod(this.field.compose(a, b));
|
||||
|
||||
// filter out Super
|
||||
class A extends B {
|
||||
compose() {
|
||||
super.compose(sortBy(x => x), flatten);
|
||||
}
|
||||
}
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
compose(
|
||||
sortBy(x => x),
|
||||
@@ -55,6 +67,18 @@ somelib.composeFlipped(
|
||||
// no regression (#4602)
|
||||
const hasValue = hasOwnProperty(a, b);
|
||||
|
||||
// filter out ThisExpression
|
||||
this.compose(sortBy(x => x), flatten);
|
||||
this.a.b.c.compose(sortBy(x => x), flatten);
|
||||
someObj.someMethod(this.field.compose(a, b));
|
||||
|
||||
// filter out Super
|
||||
class A extends B {
|
||||
compose() {
|
||||
super.compose(sortBy(x => x), flatten);
|
||||
}
|
||||
}
|
||||
|
||||
`;
|
||||
|
||||
exports[`lodash_flow.js - flow-verify 1`] = `
|
||||
|
||||
@@ -24,3 +24,15 @@ somelib.composeFlipped(
|
||||
|
||||
// no regression (#4602)
|
||||
const hasValue = hasOwnProperty(a, b);
|
||||
|
||||
// filter out ThisExpression
|
||||
this.compose(sortBy(x => x), flatten);
|
||||
this.a.b.c.compose(sortBy(x => x), flatten);
|
||||
someObj.someMethod(this.field.compose(a, b));
|
||||
|
||||
// filter out Super
|
||||
class A extends B {
|
||||
compose() {
|
||||
super.compose(sortBy(x => x), flatten);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user