Skip to content

Commit

Permalink
fix: unable to get value using NumericLiteral or BooleanLiteral t…
Browse files Browse the repository at this point in the history
…ype keys (#91)
  • Loading branch information
PinkChampagne17 authored Nov 9, 2023
1 parent 320a79f commit 63d540d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/proxy/object.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export function proxifyObject<T extends object>(
(prop.key.type === "StringLiteral" ||
prop.key.type === "NumericLiteral" ||
prop.key.type === "BooleanLiteral") &&
prop.key.value === key
prop.key.value.toString() === key
) {
return (prop.value as any).value;
}
Expand Down
12 changes: 11 additions & 1 deletion test/object.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,25 @@ export default {
foo: {
['a']: 1,
['a-b']: 2,
foo() {}
foo() {},
1: 3,
[true]: 4,
}
}
`.trim(),
);

expect(mod.exports.default.foo.a).toBe(1);
expect(mod.exports.default.foo["a-b"]).toBe(2);
expect(mod.exports.default.foo[1]).toBe(3);
expect(mod.exports.default.foo.true).toBe(4);
expect(Object.keys(mod.exports.default.foo)).toMatchInlineSnapshot(`
[
"a",
"a-b",
"foo",
"1",
"true",
]
`);

Expand All @@ -34,6 +40,8 @@ export default {
"a",
"a-b",
"foo",
"1",
"true",
"a-b-c",
]
`);
Expand All @@ -46,6 +54,8 @@ export default {
[\\"a\\"]: 1,
[\\"a-b\\"]: \\"updated\\",
foo() {},
1: 3,
[true]: 4,
\\"a-b-c\\": 3,
},
};"
Expand Down

0 comments on commit 63d540d

Please sign in to comment.