fix(javascript): skip .connect() method when composing fun (#5739)

master
makepost 2019-01-10 21:20:15 +02:00 committed by Lily Scott
parent a8d423b18c
commit 94eab666c4
4 changed files with 76 additions and 1 deletions

View File

@ -3852,12 +3852,18 @@ const functionCompositionFunctionNames = new Set([
"connect", // Redux
"createSelector" // Reselect
]);
const ordinaryMethodNames = new Set([
"connect" // GObject, MongoDB
]);
function isFunctionCompositionFunction(node) {
switch (node.type) {
case "OptionalMemberExpression":
case "MemberExpression": {
return isFunctionCompositionFunction(node.property);
return (
isFunctionCompositionFunction(node.property) &&
!ordinaryMethodNames.has(node.property.name)
);
}
case "Identifier": {
return functionCompositionFunctionNames.has(node.name);

View File

@ -115,6 +115,34 @@ this.subscriptions.add(
================================================================================
`;
exports[`gobject_connect.js 1`] = `
====================================options=====================================
parsers: ["flow", "babel", "typescript"]
printWidth: 80
| printWidth
=====================================input======================================
button.connect(
"clicked",
() => doSomething()
);
app.connect(
"activate",
async () => {
await data.load();
win.show_all();
}
);
=====================================output=====================================
button.connect("clicked", () => doSomething());
app.connect("activate", async () => {
await data.load();
win.show_all();
});
================================================================================
`;
exports[`lodash_flow.js 1`] = `
====================================options=====================================
parsers: ["flow", "babel", "typescript"]
@ -215,6 +243,29 @@ foo(6);
================================================================================
`;
exports[`mongo_connect.js 1`] = `
====================================options=====================================
parsers: ["flow", "babel", "typescript"]
printWidth: 80
| printWidth
=====================================input======================================
MongoClient.connect(
"mongodb://localhost:27017/posts",
(err, db) => {
assert.equal(null, err);
db.close();
}
);
=====================================output=====================================
MongoClient.connect("mongodb://localhost:27017/posts", (err, db) => {
assert.equal(null, err);
db.close();
});
================================================================================
`;
exports[`ramda_compose.js 1`] = `
====================================options=====================================
parsers: ["flow", "babel", "typescript"]

View File

@ -0,0 +1,11 @@
button.connect(
"clicked",
() => doSomething()
);
app.connect(
"activate",
async () => {
await data.load();
win.show_all();
}
);

View File

@ -0,0 +1,7 @@
MongoClient.connect(
"mongodb://localhost:27017/posts",
(err, db) => {
assert.equal(null, err);
db.close();
}
);