Skip to content

Commit

Permalink
fix(javascript): regression for hasOwnProperty (#4603)
Browse files Browse the repository at this point in the history
  • Loading branch information
ikatyang authored May 30, 2018
1 parent dc5de05 commit 8abbc5d
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 14 deletions.
29 changes: 15 additions & 14 deletions src/language-js/printer-estree.js
Original file line number Diff line number Diff line change
Expand Up @@ -3418,30 +3418,31 @@ function shouldGroupFirstArg(args) {
);
}

const functionCompositionFunctionNames = {
pipe: true, // RxJS, Ramda
pipeP: true, // Ramda
pipeK: true, // Ramda
compose: true, // Ramda, Redux
composeFlipped: true, // Not from any library, but common in Haskell, so supported
composeP: true, // Ramda
composeK: true, // Ramda
flow: true, // Lodash
flowRight: true, // Lodash
connect: true // Redux
};
const functionCompositionFunctionNames = new Set([
"pipe", // RxJS, Ramda
"pipeP", // Ramda
"pipeK", // Ramda
"compose", // Ramda, Redux
"composeFlipped", // Not from any library, but common in Haskell, so supported
"composeP", // Ramda
"composeK", // Ramda
"flow", // Lodash
"flowRight", // Lodash
"connect" // Redux
]);

function isFunctionCompositionFunction(node) {
switch (node.type) {
case "OptionalMemberExpression":
case "MemberExpression": {
return isFunctionCompositionFunction(node.property);
}
case "Identifier": {
return functionCompositionFunctionNames[node.name];
return functionCompositionFunctionNames.has(node.name);
}
case "StringLiteral":
case "Literal": {
return functionCompositionFunctionNames[node.value];
return functionCompositionFunctionNames.has(node.value);
}
}
}
Expand Down
6 changes: 6 additions & 0 deletions tests/functional_composition/__snapshots__/jsfmt.spec.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ somelib.composeFlipped(
flatten,
map(x => [x, x*2])
);
// no regression (#4602)
const hasValue = hasOwnProperty(a, b);
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
compose(
sortBy(x => x),
Expand All @@ -49,6 +52,9 @@ somelib.composeFlipped(
map(x => [x, x * 2])
);
// no regression (#4602)
const hasValue = hasOwnProperty(a, b);
`;

exports[`lodash_flow.js 1`] = `
Expand Down
3 changes: 3 additions & 0 deletions tests/functional_composition/functional_compose.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,6 @@ somelib.composeFlipped(
flatten,
map(x => [x, x*2])
);

// no regression (#4602)
const hasValue = hasOwnProperty(a, b);

0 comments on commit 8abbc5d

Please sign in to comment.