You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
21 lines
382 B
JavaScript
21 lines
382 B
JavaScript
'use strict';
|
|
|
|
module.exports = function createAddParentProcessor() {
|
|
let currentLevel = 0;
|
|
let lastKnownNodes = [];
|
|
|
|
return {
|
|
onEnter: function onEnter(node) {
|
|
if (currentLevel > 0) {
|
|
node._parent = lastKnownNodes[currentLevel - 1];
|
|
}
|
|
|
|
lastKnownNodes[currentLevel] = node;
|
|
currentLevel += 1;
|
|
},
|
|
onExit: function onExit() {
|
|
currentLevel -= 1;
|
|
}
|
|
};
|
|
};
|