barhandles icon indicating copy to clipboard operation
barhandles copied to clipboard

Determining when parsing is complete.

Open brentrager opened this issue 1 year ago • 0 comments

Hi! 👋

Firstly, thanks for your work on this project! 🙂

Today I used patch-package to patch [email protected] for the project I'm working on.

I was looking for a way to know when a call to extract had come to an end.

Here is the diff that solved my problem. This results in a callback with an empty path array to indicate the end has been reached.

diff --git a/node_modules/barhandles/lib/index.js b/node_modules/barhandles/lib/index.js
index 2a63600..3a9caef 100644
--- a/node_modules/barhandles/lib/index.js
+++ b/node_modules/barhandles/lib/index.js
@@ -86,8 +86,11 @@
         return clone;
       }
     };
-    visit = function(emit, path, node, optional) {
+    visit = function(emit, path, node, optional, top) {
       var helper, newPath, ref, replace;
+      if (top === null) {
+        top = false;
+      }
       if (optional == null) {
         optional = false;
       }
@@ -96,6 +99,9 @@
           _.each(node.body, function(child) {
             return visit(emit, path, child, optional);
           });
+          if (top) {
+            emit([], true);
+          }
           break;
         case 'BlockStatement':
           newPath = path;
@@ -128,7 +134,7 @@
           }
       }
     };
-    return visit(emit, [], parsed);
+    return visit(emit, [], parsed, false, true);
   };
 
 

This issue body was partially generated by patch-package.

brentrager avatar Jul 14 '23 03:07 brentrager