From 46d1fc128c8b2c146e9bdc0c79697f93dbbe6a60 Mon Sep 17 00:00:00 2001 From: Theis Pieter Hollebeek Date: Fri, 10 Oct 2025 21:46:08 +0200 Subject: [PATCH] something's rotten in the state of vermiparous --- src/vermiparous.js | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) 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; }