Skip to content

Commit

Permalink
fix: JSON/infinity tests
Browse files Browse the repository at this point in the history
  • Loading branch information
j4k0xb committed Dec 2, 2023
1 parent c969fb9 commit 95eb5fc
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 5 deletions.
5 changes: 4 additions & 1 deletion packages/unminify/src/transforms/json-parse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@ export default {
return {
CallExpression: {
exit(path) {
if (matcher.match(path.node) && !path.scope.hasBinding("JSON")) {
if (
matcher.match(path.node) &&
!path.scope.hasBinding("JSON", { noGlobals: true })
) {
try {
JSON.parse(string.current!);
const parsed = parseExpression(string.current!);
Expand Down
4 changes: 2 additions & 2 deletions packages/unminify/test/infinity.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ import { infinity } from "../src/transforms";

const expectJS = testTransform(infinity);

test("infinity", () => expectJS("1/0").toMatchInlineSnapshot('Infinity;'));
test("infinity", () => expectJS("1/0").toMatchInlineSnapshot("Infinity;"));

test("negative infinity", () =>
expectJS("-1/0").toMatchInlineSnapshot('-Infinity;'));
expectJS("-1/0").toMatchInlineSnapshot("-Infinity;"));

test("ignore when Infinity is declared in scope", () =>
expectJS("let Infinity = 1; 1/0").toMatchInlineSnapshot(`
Expand Down
4 changes: 2 additions & 2 deletions packages/unminify/test/json-parse.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ import { jsonParse } from "../src/transforms";
const expectJS = testTransform(jsonParse);

test("array", () =>
expectJS('JSON.parse("[1,2,3]")').toMatchInlineSnapshot('JSON.parse("[1,2,3]");'));
expectJS('JSON.parse("[1,2,3]")').toMatchInlineSnapshot("[1, 2, 3];"));

test("large literal", () =>
expectJS('JSON.parse("1000000000000000000000")').toMatchInlineSnapshot(
'JSON.parse("1000000000000000000000");',
"1000000000000000000000;",
));

test("ignore invalid json", () =>
Expand Down

0 comments on commit 95eb5fc

Please sign in to comment.