less/less.js

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

Open

#3,570 创建于 2020年11月26日

在 GitHub 查看
 (6 评论) (0 反应) (0 负责人)JavaScript (16,977 star) (3,517 fork)batch import
good first issuemedium priority

描述

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

}

贡献者指南

[ToDo] Clarify in documentation that `.parent` is an internal property and not reliable on the node API · less/less.js#3570 | Good First Issue