[ToDo] Clarify in documentation that `.parent` is an internal property and not reliable on the node API
I'm Writing a ThemeColor Plugin, use Visitor.
In fn:visitColor , node.parent sometimes is null (box-shadow:0 0 0 1px #999 inset). I can't find the parent Declaration Node of Color Node.
so I want to less.js/lib/less/visitors/visitor.js Visitor.prototype.visit, funcOut.call(impl, node); => funcOut.call(impl, node, visitArgs);.
And my Code will be like this.
class ThemeVisitor {
visitDeclaration(node, visitArgs) {
node.isColorDeclaration = false;
visitArgs.isColorDeclaration = false;
return node;
}
visitColor(node, visitArgs) {
visitArgs.isColorDeclaration = true;
return node;
}
visitDeclarationOut(node, visitArgs) {
if (visitArgs.isColorDeclaration) {
node.isColorDeclaration = true;
}
return node;
}
visitRulesetOut(node) {
node.rules = node.rules.filter((item) => {
if (item instanceof Declaration) {
return item.isColorDeclaration;
}
if (item instanceof Ruleset) {
return !!item.rules.length;
}
});
return node;
}
}
@legu2009
node.parent sometimes is null
The parent property of nodes is somewhat unreliable, as it doesn't currently have accompanying tests to verify that all nodes
a) have a parent property set,
b) retain that property as nodes are evaluated.
I've updated this issue to reflect that the API needs to be hardened with tests.
@legu2009 I've taken a dive into the .parent property while doing a conversion of Less.js into TypeScript. It really looks like this property was not well-thought-out (which could very well be my fault), and unfortunately there's too much node mutation of the AST during evaluation that it can't really be reliably used. I'm going to recommend deprecating / removing as a property.
can i take up this issue??
@A-tiwarii Absolutely!
How do I access the docs file. I am interested in solving this issue.
Is anyone working on this issue? I am a beginner in open source and would love to take up this issue.