From: Ardis Lu Date: Fri, 23 Feb 2024 05:31:33 +0000 (-0800) Subject: Fix issue where multi-line definitions with the same name but different types were... X-Git-Url: https://git.ardis.lu/?a=commitdiff_plain;h=21ee5477bf55d0b1397d73c9cfbca64755dbb8bf;p=4-byte-gen Fix issue where multi-line definitions with the same name but different types were dropped Occurs because .indexOf(fn) returns the first instance of this line, but there may be multiple instances. Need to track the correct offset to begin the search. --- diff --git a/index.html b/index.html index 186b6f9..ebc86b3 100644 --- a/index.html +++ b/index.html @@ -370,9 +370,14 @@ function setState(code) { state.clear(); + let position = 0; let strict = false; const fns = code.split('\n'); // Assume each function is on its own line for (let fn of fns) { + // Track character index in code block for lookahead + const originalFnLength = fn.length; + position += originalFnLength; + // Clean up empty lines fn = fn.trim(); if (fn === '') { @@ -386,7 +391,7 @@ // Basic lookahead for function definitions that span multiple lines if ((fn.match(/\(/g)?.length ?? 0) > (fn.match(/\)/g)?.length ?? 0)) { - const start = code.indexOf(fn); + const start = code.indexOf(fn, position - originalFnLength - 1); const end = code.indexOf(')', start); fn = code.substring(start, end + 1).replaceAll('\n', ''); }