Variables in detached rulesets not visited by visitor?
See original GitHub issueI have the following plugin foo.js
module.exports = {
install({ tree: { Quoted }, visitors }, manager) {
class Visitor {
constructor() {
this.native = new visitors.Visitor(this);
this.isPreEvalVisitor = true;
this.isReplacing = true;
}
run(root) {
console.log(
root
.rules[2]
.rules[0]
.arguments[0]
.value
.ruleset
.rules[0]
.value
.value[0]
.value[0]
.type,
); // 'Variable'
return this.native.visit(root);
}
visitVariable(node) {
console.log('visited');
return new Quoted(`'`, 'bar', true);
}
}
manager.addVisitor(new Visitor());
},
};
and the following Less code
@plugin './foo';
.foo(@rules: {}) {
:root.foo & {
@rules();
}
}
.foo {
.foo({
--foo: @foo;
});
}
When trying to compile this code using lessc
and/or less-loader
, Less fails with error SyntaxError: variable @foo is undefined
.
Variables in other contexts (in non-detached rulesets, at top level, in named detached rulests) are visited as expected:
@plugin './foo';
@bar: @foo;
.foo {
--foo: @foo;
--bar: @bar;
@baz();
}
@baz: {
--baz: @foo;
};
// ↓↓↓↓
.foo {
--foo: bar;
--bar: bar;
--baz: bar;
}
Maybe other node types also affected, but I didn’t test it.
Less version: 3.0.2.
Issue Analytics
- State:
- Created 5 years ago
- Reactions:1
- Comments:9 (6 by maintainers)
Top Results From Across the Web
Fixes #3205, partial 3.0 math regression #1880 #3228 - GitHub
Fixes Variables in detached rulesets not visited by visitor? #3205 - Mixin args not visited by visitor; Improves permissive parsing quite a bit...
Read more >Is it possible to use interpolation for detached rulesets in LESS?
Rulesets can be stored in mixins not variables : ... "Detached rulesets" is just the wrong tool for what you want.
Read more >Features In-Depth | Less.js
A detached ruleset is a group of css properties, nested rulesets, media declarations or anything else stored in a variable. You can include...
Read more >Predefined variables reference - GitLab Docs
Variable GitLab Runner
CHAT_CHANNEL 10.6 all
CHAT_INPUT 10.6 all
CHAT_USER_ID 14.4 all
Read more >C++ static code analysis: Threads should not be detached
Unique rules to find Bugs, Vulnerabilities, Security Hotspots, and Code Smells in your C++ code · All rules 585 · Vulnerability13 · Bug114...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Okay! I figured out that for some reason,
MixinCall
arguments are not visited. It seems that it’s an array of… objects? instead of nodes? I’ve fixed it, but would like to fix some of the permissive parsing of custom properties to try parsing a value first. Otherwise you’ll get aVariable
today, but aQuoted
after it’s released, and yourvisitVariable
would stop functioning. I’m just now sure how to make the parser “recover” from a bad path. I’m looking to tweak this code that was merged. - See this comment.So if someone can help me understand how the Less parser works and addresses that comment, I’ll do a PR for this fix.
Please review the PR - https://github.com/less/less.js/pull/3228