From 416eb635593f397312945a4fbf03a1b4f7b1437f Mon Sep 17 00:00:00 2001 From: n0cte Date: Tue, 6 Sep 2022 20:13:15 +0300 Subject: [PATCH] fix logic of function toWasmMap --- packages/schema/bind/src/bindings/golang/functions.ts | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/packages/schema/bind/src/bindings/golang/functions.ts b/packages/schema/bind/src/bindings/golang/functions.ts index 6c5e836981..008da8bf54 100644 --- a/packages/schema/bind/src/bindings/golang/functions.ts +++ b/packages/schema/bind/src/bindings/golang/functions.ts @@ -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); };