Skip to content

[ToDo] Clarify in documentation that .parent is an internal property and not reliable on the node API #3570

Open
@legu2009

Description

@legu2009

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;
    }

}

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions