fix(javascript): skip .connect() method when composing fun (#5739)
parent
a8d423b18c
commit
94eab666c4
|
@ -3852,12 +3852,18 @@ const functionCompositionFunctionNames = new Set([
|
||||||
"connect", // Redux
|
"connect", // Redux
|
||||||
"createSelector" // Reselect
|
"createSelector" // Reselect
|
||||||
]);
|
]);
|
||||||
|
const ordinaryMethodNames = new Set([
|
||||||
|
"connect" // GObject, MongoDB
|
||||||
|
]);
|
||||||
|
|
||||||
function isFunctionCompositionFunction(node) {
|
function isFunctionCompositionFunction(node) {
|
||||||
switch (node.type) {
|
switch (node.type) {
|
||||||
case "OptionalMemberExpression":
|
case "OptionalMemberExpression":
|
||||||
case "MemberExpression": {
|
case "MemberExpression": {
|
||||||
return isFunctionCompositionFunction(node.property);
|
return (
|
||||||
|
isFunctionCompositionFunction(node.property) &&
|
||||||
|
!ordinaryMethodNames.has(node.property.name)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
case "Identifier": {
|
case "Identifier": {
|
||||||
return functionCompositionFunctionNames.has(node.name);
|
return functionCompositionFunctionNames.has(node.name);
|
||||||
|
|
|
@ -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`] = `
|
exports[`lodash_flow.js 1`] = `
|
||||||
====================================options=====================================
|
====================================options=====================================
|
||||||
parsers: ["flow", "babel", "typescript"]
|
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`] = `
|
exports[`ramda_compose.js 1`] = `
|
||||||
====================================options=====================================
|
====================================options=====================================
|
||||||
parsers: ["flow", "babel", "typescript"]
|
parsers: ["flow", "babel", "typescript"]
|
||||||
|
|
|
@ -0,0 +1,11 @@
|
||||||
|
button.connect(
|
||||||
|
"clicked",
|
||||||
|
() => doSomething()
|
||||||
|
);
|
||||||
|
app.connect(
|
||||||
|
"activate",
|
||||||
|
async () => {
|
||||||
|
await data.load();
|
||||||
|
win.show_all();
|
||||||
|
}
|
||||||
|
);
|
|
@ -0,0 +1,7 @@
|
||||||
|
MongoClient.connect(
|
||||||
|
"mongodb://localhost:27017/posts",
|
||||||
|
(err, db) => {
|
||||||
|
assert.equal(null, err);
|
||||||
|
db.close();
|
||||||
|
}
|
||||||
|
);
|
Loading…
Reference in New Issue