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 416eb63
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions packages/schema/bind/src/bindings/golang/functions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -320,15 +320,14 @@ const toWasmMap = (type: string, optional: boolean): string => {

const 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 416eb63

Please sign in to comment.