diff --git a/src/vermiparous.js b/src/vermiparous.js index ee2f0e5..4cf7e6f 100644 --- a/src/vermiparous.js +++ b/src/vermiparous.js @@ -1,5 +1,6 @@ const KEYWORDS = ["asset", "code"]; const MIN_KW_LENGTH = Math.min(...KEYWORDS.map((x) => x.length)); +const MAX_KW_LENGTH = Math.max(...KEYWORDS.map((x) => x.length)); const SEMICOLON_CHARCODE = ";".charCodeAt(0); function isKeyword(buffer) { @@ -15,7 +16,6 @@ export class Vermiparous { static en(code, assets) { const ret = []; for (const asset of assets) { - console.log(asset); ret.push(...strToBytes("asset")); ret.push(...strToBytes(asset.name.length.toString())); ret.push(...strToBytes(";")); @@ -41,11 +41,10 @@ export class Vermiparous { let idx = 0; while (idx < bytes.length) { buffer.push(bytes[idx]); - if (buffer.length < MIN_KW_LENGTH) { - ++idx; - continue; + if (buffer.length >= MAX_KW_LENGTH) { + throw new Error("unreachable: something went wrong !"); } - if (!isKeyword(buffer)) { + if (buffer.length < MIN_KW_LENGTH || !isKeyword(buffer)) { ++idx; continue; }