Revert this/super blacklist for function composition heuristic (#4936)

master
Suchipi 2018-08-08 09:18:46 -06:00 committed by GitHub
parent 308863e061
commit 418a04bf2b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 60 additions and 43 deletions

View File

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

View File

@ -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`] = `

View File

@ -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 => {
})
)