Revert this/super blacklist for function composition heuristic (#4936)
parent
308863e061
commit
418a04bf2b
|
@ -3425,27 +3425,11 @@ 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 (
|
||||
!isThisExpression(node.object) &&
|
||||
isFunctionCompositionFunction(node.property)
|
||||
);
|
||||
return isFunctionCompositionFunction(node.property);
|
||||
}
|
||||
case "Identifier": {
|
||||
return functionCompositionFunctionNames.has(node.name);
|
||||
|
|
|
@ -2,43 +2,49 @@
|
|||
|
||||
exports[`functional_compose.js - flow-verify 1`] = `
|
||||
compose(
|
||||
sortBy(x => x),
|
||||
flatten,
|
||||
sortBy(x => x),
|
||||
flatten,
|
||||
map(x => [x, x*2])
|
||||
);
|
||||
|
||||
somelib.compose(
|
||||
sortBy(x => x),
|
||||
flatten,
|
||||
sortBy(x => x),
|
||||
flatten,
|
||||
map(x => [x, x*2])
|
||||
);
|
||||
|
||||
composeFlipped(
|
||||
sortBy(x => x),
|
||||
flatten,
|
||||
sortBy(x => x),
|
||||
flatten,
|
||||
map(x => [x, x*2])
|
||||
);
|
||||
|
||||
somelib.composeFlipped(
|
||||
sortBy(x => x),
|
||||
flatten,
|
||||
sortBy(x => x),
|
||||
flatten,
|
||||
map(x => [x, x*2])
|
||||
);
|
||||
|
||||
// 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);
|
||||
}
|
||||
}
|
||||
|
||||
this.subscriptions.add(
|
||||
this.componentUpdates
|
||||
.pipe(startWith(this.props), distinctUntilChanged(isEqual))
|
||||
.subscribe(props => {
|
||||
|
||||
})
|
||||
)
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
compose(
|
||||
sortBy(x => x),
|
||||
|
@ -67,18 +73,39 @@ 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));
|
||||
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);
|
||||
super.compose(
|
||||
sortBy(x => x),
|
||||
flatten
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
this.subscriptions.add(
|
||||
this.componentUpdates
|
||||
.pipe(
|
||||
startWith(this.props),
|
||||
distinctUntilChanged(isEqual)
|
||||
)
|
||||
.subscribe(props => {})
|
||||
);
|
||||
|
||||
`;
|
||||
|
||||
exports[`lodash_flow.js - flow-verify 1`] = `
|
||||
|
|
|
@ -1,38 +1,44 @@
|
|||
compose(
|
||||
sortBy(x => x),
|
||||
flatten,
|
||||
sortBy(x => x),
|
||||
flatten,
|
||||
map(x => [x, x*2])
|
||||
);
|
||||
|
||||
somelib.compose(
|
||||
sortBy(x => x),
|
||||
flatten,
|
||||
sortBy(x => x),
|
||||
flatten,
|
||||
map(x => [x, x*2])
|
||||
);
|
||||
|
||||
composeFlipped(
|
||||
sortBy(x => x),
|
||||
flatten,
|
||||
sortBy(x => x),
|
||||
flatten,
|
||||
map(x => [x, x*2])
|
||||
);
|
||||
|
||||
somelib.composeFlipped(
|
||||
sortBy(x => x),
|
||||
flatten,
|
||||
sortBy(x => x),
|
||||
flatten,
|
||||
map(x => [x, x*2])
|
||||
);
|
||||
|
||||
// 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);
|
||||
}
|
||||
}
|
||||
|
||||
this.subscriptions.add(
|
||||
this.componentUpdates
|
||||
.pipe(startWith(this.props), distinctUntilChanged(isEqual))
|
||||
.subscribe(props => {
|
||||
|
||||
})
|
||||
)
|
||||
|
|
Loading…
Reference in New Issue