Skip to content

Commit a1d4371

Browse files
committed
Fixed usage of any
1 parent c91d416 commit a1d4371

File tree

2 files changed

+26
-12
lines changed

2 files changed

+26
-12
lines changed

src/utils/common.ts

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
import { SimpleIdentifierListContext } from "../generated";
2-
import { VariableContext, VariableContextWithNull } from "../types";
2+
import {
3+
CircomValueType,
4+
VariableContext,
5+
VariableContextWithNull,
6+
} from "../types";
37

48
export function parseSimpleIdentifierList(
59
ctx: SimpleIdentifierListContext,
@@ -19,7 +23,7 @@ export function parseSimpleIdentifierList(
1923

2024
export function buildVariableContext(
2125
names: string[],
22-
values: any[],
26+
values: CircomValueType[],
2327
): VariableContext {
2428
if (names.length !== values.length) {
2529
throw new Error("Names and values must have the same length");
@@ -44,7 +48,7 @@ export function buildVariableContext(
4448
return context;
4549
}
4650

47-
export function getArrayDimensions(value: any): number[] {
51+
export function getArrayDimensions(value: CircomValueType): number[] {
4852
if (Array.isArray(value)) {
4953
return [value.length, ...getArrayDimensions(value[0])];
5054
}
@@ -55,7 +59,7 @@ export function getArrayDimensions(value: any): number[] {
5559
export function bindVariableContext(
5660
variableName: string,
5761
dimensions: number[],
58-
values: any,
62+
values: CircomValueType,
5963
): VariableContextWithNull {
6064
const context: VariableContextWithNull = {};
6165
const resolved = resolveDimensions(variableName, dimensions);
@@ -82,7 +86,10 @@ export function resolveDimensions(
8286
}
8387

8488
// reference MUST be similar to [0][1]
85-
function parseVariable(value: any, reference: string): bigint {
89+
function parseVariable(
90+
value: CircomValueType,
91+
reference: string,
92+
): CircomValueType {
8693
const parts = reference
8794
.split("[")
8895
.map((part) => part.replace("]", ""))
@@ -92,9 +99,16 @@ function parseVariable(value: any, reference: string): bigint {
9299
return getReferenceValueInternal(value, parts);
93100
}
94101

95-
function getReferenceValueInternal(value: any, reference: number[]): bigint {
102+
function getReferenceValueInternal(
103+
value: CircomValueType,
104+
reference: number[],
105+
): CircomValueType {
96106
if (reference.length === 0) {
97-
return BigInt(value);
107+
return value;
108+
}
109+
110+
if (!Array.isArray(value)) {
111+
throw new Error("INTERNAL ERROR! Reference is invalid");
98112
}
99113

100114
return getReferenceValueInternal(value[reference[0]], reference.slice(1));

test/utils.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { bindVariableContext } from "../src";
55
describe("utils", () => {
66
describe("resolve dimensions", () => {
77
it("should resolve the case: [1, 2], when value: [[3, 5]]", () => {
8-
expect(bindVariableContext("a", [1, 2], [[3, 5]])).to.deep.equal({
8+
expect(bindVariableContext("a", [1, 2], [[3n, 5n]])).to.deep.equal({
99
"a[0][0]": 3n,
1010
"a[0][1]": 5n,
1111
});
@@ -19,13 +19,13 @@ describe("utils", () => {
1919
});
2020

2121
it("should resolve the case: [], when value: 1", () => {
22-
expect(bindVariableContext("a", [], 1)).to.deep.equal({
22+
expect(bindVariableContext("a", [], 1n)).to.deep.equal({
2323
a: 1n,
2424
});
2525
});
2626

2727
it("should resolve the case: [1], when value: 1", () => {
28-
expect(bindVariableContext("a", [1], 1)).to.deep.equal({
28+
expect(bindVariableContext("a", [1], 1n)).to.deep.equal({
2929
"a[0]": null,
3030
});
3131
});
@@ -36,8 +36,8 @@ describe("utils", () => {
3636
"a",
3737
[2, 2],
3838
[
39-
[1, 2],
40-
[3, 4],
39+
[1n, 2n],
40+
[3n, 4n],
4141
],
4242
),
4343
).to.deep.equal({

0 commit comments

Comments
 (0)