diff --git a/packages/less/src/less/tree/ruleset.js b/packages/less/src/less/tree/ruleset.js index a3324cf07..e453e08e4 100644 --- a/packages/less/src/less/tree/ruleset.js +++ b/packages/less/src/less/tree/ruleset.js @@ -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(); + } } } diff --git a/packages/less/test/index.js b/packages/less/test/index.js index 5ace868ed..31475301f 100644 --- a/packages/less/test/index.js +++ b/packages/less/test/index.js @@ -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) diff --git a/packages/test-data/css/define-var/define-var.css b/packages/test-data/css/define-var/define-var.css new file mode 100644 index 000000000..86bb6a5c5 --- /dev/null +++ b/packages/test-data/css/define-var/define-var.css @@ -0,0 +1,4 @@ +div { + height: 1px; + width: 33px; +} diff --git a/packages/test-data/less/define-var/define-var.less b/packages/test-data/less/define-var/define-var.less new file mode 100644 index 000000000..e7b5e2d17 --- /dev/null +++ b/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; +} \ No newline at end of file diff --git a/packages/test-data/plugin/plugin-define-var.js b/packages/test-data/plugin/plugin-define-var.js new file mode 100644 index 000000000..356a3b9e6 --- /dev/null +++ b/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) => {}); + } +};