Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revert this/super blacklist for function composition heuristic #4936

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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,
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, my editor did this

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 => {

})
)