Skip to content

Determining when parsing is complete.聽#13

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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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