Skip to content

Commit

Permalink
fix: Ignore methods in Object.value() calls
Browse files Browse the repository at this point in the history
  • Loading branch information
danez committed May 28, 2022
1 parent 85ea6a5 commit 4fc5b21
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,13 @@ Array [
]
`;

exports[`resolveObjectValuesToArray resolves Object.values when using methods 1`] = `
Array [
"1",
"2",
]
`;

exports[`resolveObjectValuesToArray resolves Object.values when using resolvable spread 1`] = `
Array [
"1",
Expand Down
10 changes: 10 additions & 0 deletions src/utils/__tests__/resolveObjectValuesToArray-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,16 @@ describe('resolveObjectValuesToArray', () => {
expect(resolveObjectValuesToArray(path, noopImporter)).toMatchSnapshot();
});

it('resolves Object.values when using methods', () => {
const path = expressionLast(
['var foo = { boo: 1, foo: 2, bar(e) {} };', 'Object.values(foo);'].join(
'\n',
),
);

expect(resolveObjectValuesToArray(path, noopImporter)).toMatchSnapshot();
});

it('resolves Object.values but ignores duplicates', () => {
const path = expressionLast(
[
Expand Down
4 changes: 3 additions & 1 deletion src/utils/resolveObjectValuesToArray.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,9 @@ export function resolveObjectToPropMap(
if (error) return;
const prop = propPath.value;

if (prop.kind === 'get' || prop.kind === 'set') return;
if (prop.kind === 'get' || prop.kind === 'set' || prop.method === true) {
return;
}

if (
t.Property.check(prop) ||
Expand Down

0 comments on commit 4fc5b21

Please sign in to comment.