Could it really be that a traverse only visits the given node's children, not the node itself?
This commit is contained in:
parent
73e5ee0944
commit
2aee34d201
|
@ -199,21 +199,37 @@ function compilePattern(state, patternPath) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function instantiatePatternToPattern(state, patternPath) {
|
function instantiatePatternToPattern(state, patternPath) {
|
||||||
|
|
||||||
|
function visitCallExpression(path) {
|
||||||
|
if (!isCaptureIdentifier(path.node.callee)) return true;
|
||||||
|
path.replaceWith(t.identifier(path.node.callee.name.slice(1)));
|
||||||
|
path.skip();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
function visitIdentifier(path) {
|
||||||
|
if (!isCaptureIdentifier(path.node)) return true;
|
||||||
|
path.replaceWith(t.identifier(path.node.name.slice(1)));
|
||||||
|
path.skip();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
patternPath.node = cloneDeep(patternPath.node);
|
patternPath.node = cloneDeep(patternPath.node);
|
||||||
patternPath.traverse({
|
// OK I must have misunderstood something, because could it really
|
||||||
CallExpression(path) {
|
// be the case that traverse recursively visits all the CHILDREN of
|
||||||
if (isCaptureIdentifier(path.node.callee)) {
|
// the given node but NOT THE GIVEN NODE ITSELF???
|
||||||
path.replaceWith(t.identifier(path.node.callee.name.slice(1)));
|
let doTraverse = true;
|
||||||
path.skip();
|
if (doTraverse && (patternPath.node.type === 'CallExpression')) {
|
||||||
}
|
doTraverse = visitCallExpression(patternPath);
|
||||||
},
|
}
|
||||||
Identifier(path) {
|
if (doTraverse && (patternPath.node.type === 'Identifier')) {
|
||||||
if (isCaptureIdentifier(path.node)) {
|
doTraverse = visitIdentifier(patternPath);
|
||||||
path.replaceWith(t.identifier(path.node.name.slice(1)));
|
}
|
||||||
path.skip();
|
if (doTraverse) {
|
||||||
}
|
patternPath.traverse({
|
||||||
},
|
CallExpression(path) { visitCallExpression(path) },
|
||||||
});
|
Identifier(path) { visitIdentifier(path) },
|
||||||
|
});
|
||||||
|
}
|
||||||
return patternPath.node;
|
return patternPath.node;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue