]> git.ardis.lu - 4-byte-gen/commitdiff
Fix issue where multi-line definitions with the same name but different types were...
authorArdis Lu <ardisglu@gmail.com>
Fri, 23 Feb 2024 05:31:33 +0000 (21:31 -0800)
committerArdis Lu <ardisglu@gmail.com>
Fri, 23 Feb 2024 05:31:33 +0000 (21:31 -0800)
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

index 186b6f94e2e014e334d533ac8b110d5269528b13..ebc86b360ace009d62b2d73cc6ee2faf0f196d53 100644 (file)
     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 === '') {
 
         // 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', '');
         }
This page took 0.04709 seconds and 4 git commands to generate.