How to skip child nodes
See original GitHub issueCode:
var traverse = require("@babel/traverse").default;
var parser = require("@babel/parser");
var generate = require("@babel/generator").default;
var types = require("@babel/types");
var ast = parser.parse('{"abc";"123";}');
traverse(ast, {
BlockStatement(path) {
var p = path.get("body")[0];
console.log("before", p.shouldSkip);
p.skip();
console.log("after", p.shouldSkip, path.get("body")[0].shouldSkip);
},
ExpressionStatement(path) {
console.log(generate(path.node).code);
}
});
return;
Output:
before false
after true false
"abc";
"123";
Issue Analytics
- State:
- Created 4 years ago
- Reactions:1
- Comments:6 (3 by maintainers)
Top Results From Across the Web
How to skip child node within parent node(Xpath)
I need to extract below text from parent tag div node excluding its child nodes: Software Quality Assurance & Testing Stack Exchange is...
Read more >XmlReader.Skip skips the children of the current node. : XML ...
Skip skips the children of the current node. using System; using System.Xml; public class Sample { public static void Main() { using (XmlReader...
Read more >Skip Child Element | Cypress examples (v9.7.0)
Remove child elements by selector We need to get the "div#make" element's text, but without the text of the child element "span. picked"....
Read more >first-child - CSS: Cascading Style Sheets - MDN Web Docs
The :first-child CSS pseudo-class represents the first element among a group of sibling elements. Try it. CSS Demo: :first-child. Reset.
Read more >XmlReader.ReadToDescendant Method (System.Xml)
The namespace URI of the element you wish to move to. Returns. Boolean. true if a matching descendant element is found; otherwise false...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
This is definitely a bug. If you try to run this code in the monorepo:
It will log
after 1 true
,after 1 false
, butshouldSkip
shouldn’t change fromafter 1
toafter2
.Skipping just does not work in general. Flags always get wiped before a
visit
, even without callingpath.get
in between:Order of events
p
gets visited, I callp.skip()
. That in turn setsNodePath._traverseFlags
p
gets visited,setContext
is called. Stacktrace looks like so:_traverseFlags
Thus
skip
will not work.The only situation where
skip
can work is a partial skip; that is if you skip the node itself during its ownenter
call. In that case,enter
was called butexit
will not be called.At this point I would like to ask point that it has been quite a while. Is there any news on this?
NodePath.skip
being straight-up broken looks quite bad. I know there are workarounds, but this is just a pretty obvious bug that requires fixing, if not at least acknowledgement.