Skip to content

Determining when parsing is complete. #13

@brentrager

Description

@brentrager

Hi! 👋

Firstly, thanks for your work on this project! 🙂

Today I used patch-package to patch barhandles@0.5.4 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions