The Wayback Machine - https://web.archive.org/web/20250305094308/https://github.com/less/less.js/issues/3570
Skip to content

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

Open
@legu2009

Description

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

}

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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