From 21ee5477bf55d0b1397d73c9cfbca64755dbb8bf Mon Sep 17 00:00:00 2001 From: Ardis Lu Date: Thu, 22 Feb 2024 21:31:33 -0800 Subject: [PATCH] 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. --- index.html | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) 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', ''); } -- 2.47.3