Skip to content

Commit

Permalink
fix: can not find the variable that be created in plugin.
Browse files Browse the repository at this point in the history
  • Loading branch information
bestlyg committed Oct 29, 2023
1 parent 13864a6 commit 5fa1dcd
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 1 deletion.
3 changes: 3 additions & 0 deletions packages/less/src/less/tree/ruleset.js
Expand Up @@ -189,6 +189,9 @@ Ruleset.prototype = Object.assign(new Node(), {
for (i = 0; (rule = rsRules[i]); i++) {
if (!rule.evalFirst) {
rsRules[i] = rule = rule.eval ? rule.eval(context) : rule;
if (rule instanceof Declaration) {
ruleset.resetCache();
}
}
}

Expand Down
3 changes: 2 additions & 1 deletion packages/less/test/index.js
Expand Up @@ -81,7 +81,8 @@ var testMap = [
[{plugin: 'test/plugins/visitor/'}, 'visitorPlugin/'],
[{plugin: 'test/plugins/filemanager/'}, 'filemanagerPlugin/'],
[{math: 0}, '3rd-party/'],
[{ processImports: false }, 'process-imports/']
[{ processImports: false }, 'process-imports/'],
[{}, 'define-var/']
];
testMap.forEach(function(args) {
lessTester.runTestSet.apply(lessTester, args)
Expand Down
4 changes: 4 additions & 0 deletions packages/test-data/css/define-var/define-var.css
@@ -0,0 +1,4 @@
div {
height: 1px;
width: 33px;
}
9 changes: 9 additions & 0 deletions packages/test-data/less/define-var/define-var.less
@@ -0,0 +1,9 @@
@plugin "../../plugin/plugin-define-var.js";

@a: 1px;

div {
height: @a;
x();
width: @x;
}
11 changes: 11 additions & 0 deletions packages/test-data/plugin/plugin-define-var.js
@@ -0,0 +1,11 @@
module.exports = class LessPluginBestMixin {
install(less, pluginManager, functions) {
functions.add("x", () => {
return new less.tree.Declaration(
"@x",
new less.tree.Value(new less.tree.Keyword("33px"))
);
});
functions.add("define_var", (key) => {});
}
};

0 comments on commit 5fa1dcd

Please sign in to comment.