Skip to content

Commit

Permalink
fix logic of function toWasmMap
Browse files Browse the repository at this point in the history
  • Loading branch information
n0cte committed Sep 6, 2022
1 parent 9c5b9d3 commit 2a8f37c
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions packages/schema/bind/src/bindings/golang/functions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -318,17 +318,16 @@ const toWasmMap = (type: string, optional: boolean): string => {
throw new Error(`Invalid Map: ${type}`);
}

const keyValTypes = type
let keyValTypes = type
.substring(firstOpenBracketIdx + 1, lastCloseBracketIdx)
.split(",")
.map((x) => x.trim());
.split(",");

if (keyValTypes.length !== 2 || !keyValTypes[0] || !keyValTypes[1]) {
if (keyValTypes.length < 2) {
throw new Error(`Invalid Map: ${type}`);
}

const keyType = toWasm()(keyValTypes[0], (str) => str);
const valType = toWasm()(keyValTypes[1], (str) => str);
const keyType = toWasm()(keyValTypes[0].trim(), (str) => str);
const valType = toWasm()(keyValTypes.slice(1).join(",").trim(), (str) => str);

return applyOptional(`map[${keyType}]${valType}`, optional, false);
};
Expand Down

0 comments on commit 2a8f37c

Please sign in to comment.