Skip to content

Commit 4fc5b21

Browse files
committed
fix: Ignore methods in Object.value() calls
1 parent 85ea6a5 commit 4fc5b21

File tree

3 files changed

+20
-1
lines changed

3 files changed

+20
-1
lines changed

src/utils/__tests__/__snapshots__/resolveObjectValuesToArray-test.ts.snap

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,13 @@ Array [
3838
]
3939
`;
4040

41+
exports[`resolveObjectValuesToArray resolves Object.values when using methods 1`] = `
42+
Array [
43+
"1",
44+
"2",
45+
]
46+
`;
47+
4148
exports[`resolveObjectValuesToArray resolves Object.values when using resolvable spread 1`] = `
4249
Array [
4350
"1",

src/utils/__tests__/resolveObjectValuesToArray-test.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,16 @@ describe('resolveObjectValuesToArray', () => {
104104
expect(resolveObjectValuesToArray(path, noopImporter)).toMatchSnapshot();
105105
});
106106

107+
it('resolves Object.values when using methods', () => {
108+
const path = expressionLast(
109+
['var foo = { boo: 1, foo: 2, bar(e) {} };', 'Object.values(foo);'].join(
110+
'\n',
111+
),
112+
);
113+
114+
expect(resolveObjectValuesToArray(path, noopImporter)).toMatchSnapshot();
115+
});
116+
107117
it('resolves Object.values but ignores duplicates', () => {
108118
const path = expressionLast(
109119
[

src/utils/resolveObjectValuesToArray.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,9 @@ export function resolveObjectToPropMap(
6161
if (error) return;
6262
const prop = propPath.value;
6363

64-
if (prop.kind === 'get' || prop.kind === 'set') return;
64+
if (prop.kind === 'get' || prop.kind === 'set' || prop.method === true) {
65+
return;
66+
}
6567

6668
if (
6769
t.Property.check(prop) ||

0 commit comments

Comments
 (0)