]> git.ardis.lu - event-hashes/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:27:41 +0000 (21:27 -0800)
committerArdis Lu <ardisglu@gmail.com>
Fri, 23 Feb 2024 05:27:41 +0000 (21:27 -0800)
Occurs because .indexOf(line) 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 e52a15be55fc1df181f032159ec7b7a30e7eb7a1..f364fdd2b61fce5ac827464b76beb2357ca89df2 100644 (file)
 
     function getEvents(code) {
       const events = new Set();
+      let position = 0;
       let strict = false;
       for (let line of code.split('\n')) {
+        const originalLineLength = line.length;
+        position += originalLineLength;
         line = line.trim();
         if (line === '') {
           continue;
         }
         // Basic lookahead for event definitions that span multiple lines
         if ((line.match(/\(/g)?.length ?? 0) > (line.match(/\)/g)?.length ?? 0)) {
-          const start = code.indexOf(line);
+          const start = code.indexOf(line, position - originalLineLength - 1);
           const end = code.indexOf(')', start);
           const lookaheadLine = code.substring(start, end + 1).replaceAll('\n', '');
           try {
This page took 0.03454 seconds and 4 git commands to generate.