Skip to content

Commit

Permalink
Revert this/super blacklist for function composition heuristic (#4936)
Browse files Browse the repository at this point in the history
  • Loading branch information
suchipi committed Aug 8, 2018
1 parent 308863e commit 418a04b
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 43 deletions.
18 changes: 1 addition & 17 deletions src/language-js/printer-estree.js
Expand Up @@ -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);
Expand Down
59 changes: 43 additions & 16 deletions tests/functional_composition/__snapshots__/jsfmt.spec.js.snap
Expand Up @@ -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),
Expand Down Expand Up @@ -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`] = `
Expand Down
26 changes: 16 additions & 10 deletions tests/functional_composition/functional_compose.js
@@ -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 => {

})
)

0 comments on commit 418a04b

Please sign in to comment.